@p10node/office-engine 0.0.0-stage → 0.1.0
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 -2
- package/dist/DocViewer-Cv4LaMB_.js +9342 -0
- package/dist/DocViewer-Cv4LaMB_.js.map +1 -0
- package/dist/THIRD_PARTY_LICENSES.txt +79 -0
- package/dist/assets/worker-CJfZ05I7.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-B5CGBnic.js +9193 -0
- package/dist/default-worker-B5CGBnic.js.map +1 -0
- package/dist/embed.js +83 -0
- package/dist/embed.js.map +1 -0
- package/dist/index.js +5 -0
- package/dist/office-engine.embed.js +33 -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/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 +9 -0
- package/dist/types/embed.d.ts +30 -0
- package/dist/types/index.d.ts +18 -0
- package/dist/types/react/DocViewer.d.ts +43 -0
- package/dist/types/react/common/ContextMenu.d.ts +21 -0
- package/dist/types/react/common/Dialog.d.ts +27 -0
- package/dist/types/react/common/Slots.d.ts +18 -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 +18 -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 +130 -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/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 +16 -0
- package/dist/types/react/xlsx/axis.d.ts +19 -0
- package/dist/xlsx-ops-CsjNpMI0.js +244 -0
- package/dist/xlsx-ops-CsjNpMI0.js.map +1 -0
- package/package.json +80 -4
|
@@ -0,0 +1,193 @@
|
|
|
1
|
+
export interface SheetInfo {
|
|
2
|
+
name: string;
|
|
3
|
+
index: number;
|
|
4
|
+
path: string;
|
|
5
|
+
hidden: boolean;
|
|
6
|
+
}
|
|
7
|
+
/** CSS-ish props for a cell format (cellXfs entry). Keys are React style keys. */
|
|
8
|
+
export type CellCss = Record<string, string | number>;
|
|
9
|
+
export interface WorkbookMeta {
|
|
10
|
+
sheets: SheetInfo[];
|
|
11
|
+
styles: CellCss[];
|
|
12
|
+
/** number format code per style */
|
|
13
|
+
formats: string[];
|
|
14
|
+
/** CSS for font 0 (grid default) */
|
|
15
|
+
baseFont: CellCss;
|
|
16
|
+
date1904: boolean;
|
|
17
|
+
}
|
|
18
|
+
export interface ColInfo {
|
|
19
|
+
min: number;
|
|
20
|
+
max: number;
|
|
21
|
+
/** px; 0 when hidden */
|
|
22
|
+
w: number;
|
|
23
|
+
/** width before hiding (px) */
|
|
24
|
+
prevW?: number;
|
|
25
|
+
}
|
|
26
|
+
export interface Merge {
|
|
27
|
+
r0: number;
|
|
28
|
+
c0: number;
|
|
29
|
+
r1: number;
|
|
30
|
+
c1: number;
|
|
31
|
+
}
|
|
32
|
+
export interface SheetProgress {
|
|
33
|
+
sheet: number;
|
|
34
|
+
/** number of rows known so far (max row index + 1) */
|
|
35
|
+
rows: number;
|
|
36
|
+
cols: number;
|
|
37
|
+
/** custom row sizes discovered since last progress: [row, px] (0 = hidden) */
|
|
38
|
+
rowSizes: [number, number][];
|
|
39
|
+
done: boolean;
|
|
40
|
+
/** only in the first progress message */
|
|
41
|
+
colInfo?: ColInfo[];
|
|
42
|
+
defaultColW?: number;
|
|
43
|
+
defaultRowH?: number;
|
|
44
|
+
frozen?: {
|
|
45
|
+
rows: number;
|
|
46
|
+
cols: number;
|
|
47
|
+
};
|
|
48
|
+
gridLines?: boolean;
|
|
49
|
+
/** only when done */
|
|
50
|
+
merges?: Merge[];
|
|
51
|
+
error?: string;
|
|
52
|
+
/** formula values were (re)computed: cached rows are stale */
|
|
53
|
+
recalc?: boolean;
|
|
54
|
+
}
|
|
55
|
+
/** [col, text, styleIndex, kind (0 text,1 number,2 center), color?] */
|
|
56
|
+
export type CellOut = [number, string, number, number, string?];
|
|
57
|
+
export interface RowOut {
|
|
58
|
+
r: number;
|
|
59
|
+
cells: CellOut[];
|
|
60
|
+
}
|
|
61
|
+
export interface BlockOut {
|
|
62
|
+
sheet: number;
|
|
63
|
+
r0: number;
|
|
64
|
+
r1: number;
|
|
65
|
+
rows: RowOut[];
|
|
66
|
+
complete: boolean;
|
|
67
|
+
}
|
|
68
|
+
export interface CellDetail {
|
|
69
|
+
value: string;
|
|
70
|
+
formula?: string;
|
|
71
|
+
type: string;
|
|
72
|
+
}
|
|
73
|
+
export interface CellInput {
|
|
74
|
+
r: number;
|
|
75
|
+
c: number;
|
|
76
|
+
/** raw user input ('' clears; '=…' formula) */
|
|
77
|
+
input: string;
|
|
78
|
+
}
|
|
79
|
+
export type BorderKind = 'all' | 'outer' | 'inner' | 'none' | 'top' | 'bottom' | 'left' | 'right';
|
|
80
|
+
export interface FmtPatch {
|
|
81
|
+
border?: BorderKind;
|
|
82
|
+
borderColor?: string;
|
|
83
|
+
b?: boolean;
|
|
84
|
+
i?: boolean;
|
|
85
|
+
u?: boolean;
|
|
86
|
+
strike?: boolean;
|
|
87
|
+
color?: string | null;
|
|
88
|
+
fill?: string | null;
|
|
89
|
+
align?: 'left' | 'center' | 'right' | null;
|
|
90
|
+
valign?: 'top' | 'center' | 'bottom' | null;
|
|
91
|
+
/** text rotation in degrees (-90…90), 255 = vertical stack, null = none */
|
|
92
|
+
rotate?: number | null;
|
|
93
|
+
wrap?: boolean;
|
|
94
|
+
numFmt?: string;
|
|
95
|
+
sz?: number;
|
|
96
|
+
font?: string;
|
|
97
|
+
borderStyle?: 'thin' | 'medium' | 'thick' | 'dashed' | 'dotted' | 'double';
|
|
98
|
+
/** reset to the default style */
|
|
99
|
+
clear?: boolean;
|
|
100
|
+
/** apply this exact style index (paint format) */
|
|
101
|
+
xf?: number;
|
|
102
|
+
}
|
|
103
|
+
export interface Range {
|
|
104
|
+
r0: number;
|
|
105
|
+
c0: number;
|
|
106
|
+
r1: number;
|
|
107
|
+
c1: number;
|
|
108
|
+
}
|
|
109
|
+
export interface XlsxEditResult {
|
|
110
|
+
sheet: number;
|
|
111
|
+
range: Range;
|
|
112
|
+
/** style entries appended to the workbook (index → css/format) */
|
|
113
|
+
styles?: {
|
|
114
|
+
index: number;
|
|
115
|
+
css: CellCss;
|
|
116
|
+
format: string;
|
|
117
|
+
}[];
|
|
118
|
+
/** full layout after structural edits (sizes, merges, frozen panes…) */
|
|
119
|
+
layout?: SheetProgress;
|
|
120
|
+
/** sheet list changed */
|
|
121
|
+
sheets?: SheetInfo[];
|
|
122
|
+
/** sheets whose formula values changed (cached rows are stale) */
|
|
123
|
+
recalc?: number[];
|
|
124
|
+
}
|
|
125
|
+
export type SheetOp = {
|
|
126
|
+
op: 'insertRows' | 'deleteRows' | 'insertCols' | 'deleteCols';
|
|
127
|
+
at: number;
|
|
128
|
+
n: number;
|
|
129
|
+
} | {
|
|
130
|
+
op: 'merge' | 'unmerge';
|
|
131
|
+
range: Range;
|
|
132
|
+
mode?: 'all' | 'across' | 'down';
|
|
133
|
+
} | {
|
|
134
|
+
op: 'hideRows' | 'hideCols';
|
|
135
|
+
a: number;
|
|
136
|
+
b: number;
|
|
137
|
+
hidden: boolean;
|
|
138
|
+
} | {
|
|
139
|
+
op: 'gridlines';
|
|
140
|
+
show: boolean;
|
|
141
|
+
} | {
|
|
142
|
+
op: 'colWidth';
|
|
143
|
+
c0: number;
|
|
144
|
+
c1: number;
|
|
145
|
+
px: number;
|
|
146
|
+
} | {
|
|
147
|
+
op: 'rowHeight';
|
|
148
|
+
r0: number;
|
|
149
|
+
r1: number;
|
|
150
|
+
px: number;
|
|
151
|
+
} | {
|
|
152
|
+
op: 'freeze';
|
|
153
|
+
rows: number;
|
|
154
|
+
cols: number;
|
|
155
|
+
} | {
|
|
156
|
+
op: 'fill';
|
|
157
|
+
range: Range;
|
|
158
|
+
dir: 'down' | 'right';
|
|
159
|
+
} | {
|
|
160
|
+
op: 'sort';
|
|
161
|
+
range: Range;
|
|
162
|
+
col: number;
|
|
163
|
+
desc?: boolean;
|
|
164
|
+
};
|
|
165
|
+
export type BookOp = {
|
|
166
|
+
op: 'add';
|
|
167
|
+
name?: string;
|
|
168
|
+
after?: number;
|
|
169
|
+
} | {
|
|
170
|
+
op: 'rename';
|
|
171
|
+
index: number;
|
|
172
|
+
name: string;
|
|
173
|
+
} | {
|
|
174
|
+
op: 'delete';
|
|
175
|
+
index: number;
|
|
176
|
+
} | {
|
|
177
|
+
op: 'move';
|
|
178
|
+
from: number;
|
|
179
|
+
to: number;
|
|
180
|
+
};
|
|
181
|
+
export interface FindOptions {
|
|
182
|
+
matchCase?: boolean;
|
|
183
|
+
/** whole cell contents */
|
|
184
|
+
whole?: boolean;
|
|
185
|
+
/** search formula text instead of values */
|
|
186
|
+
formulas?: boolean;
|
|
187
|
+
}
|
|
188
|
+
export interface FindMatch {
|
|
189
|
+
r: number;
|
|
190
|
+
c: number;
|
|
191
|
+
/** text the match was found in (value or formula) */
|
|
192
|
+
text: string;
|
|
193
|
+
}
|
|
@@ -0,0 +1,94 @@
|
|
|
1
|
+
import { OpcPackage, type Rels } from '../opc';
|
|
2
|
+
import { type Theme } from '../theme';
|
|
3
|
+
import { Calc } from './calc';
|
|
4
|
+
import { type SheetStyles } from './styles';
|
|
5
|
+
import type { BlockOut, CellDetail, ColInfo, FindMatch, FindOptions, Merge, SheetInfo, SheetProgress, WorkbookMeta } from './types';
|
|
6
|
+
export declare const T_NUM = 0;
|
|
7
|
+
export declare const T_SST = 1;
|
|
8
|
+
export declare const T_STR = 2;
|
|
9
|
+
export declare const T_BOOL = 3;
|
|
10
|
+
export declare const T_ERR = 4;
|
|
11
|
+
export declare const T_DATE = 5;
|
|
12
|
+
export declare const T_EMPTY = 6;
|
|
13
|
+
export declare const MAX_COL = 16384;
|
|
14
|
+
export declare function colIndex(letters: string): number;
|
|
15
|
+
export declare function colName(c: number): string;
|
|
16
|
+
export declare function parseRef(ref: string): [number, number];
|
|
17
|
+
export declare function parseRange(ref: string): Merge | undefined;
|
|
18
|
+
export declare class SheetData {
|
|
19
|
+
/** shared formula groups: si → master cell key + formula text */
|
|
20
|
+
shared: Map<number, {
|
|
21
|
+
master: number;
|
|
22
|
+
text: string;
|
|
23
|
+
}>;
|
|
24
|
+
/** dependent cell key → shared formula si */
|
|
25
|
+
depOf: Map<number, number>;
|
|
26
|
+
/** edited cell keys (r * MAX_COL + c) */
|
|
27
|
+
edited: Set<number>;
|
|
28
|
+
/** row heights in pt / hidden flags (from the file or the editor) */
|
|
29
|
+
rowAttrs: Map<number, {
|
|
30
|
+
ht?: number;
|
|
31
|
+
hidden?: boolean;
|
|
32
|
+
}>;
|
|
33
|
+
/** rows grown to fit a large font (no explicit height in the file): px */
|
|
34
|
+
autoRowH: Map<number, number>;
|
|
35
|
+
/** whole-sheet rewrite needed (rows/cols inserted or deleted) */
|
|
36
|
+
structural: boolean;
|
|
37
|
+
/** sections to regenerate on save */
|
|
38
|
+
dirtyCols: boolean;
|
|
39
|
+
dirtyMerges: boolean;
|
|
40
|
+
dirtyView: boolean;
|
|
41
|
+
/** rows whose height/visibility changed */
|
|
42
|
+
dirtyRows: Set<number>;
|
|
43
|
+
/** formulas rewritten because another sheet changed */
|
|
44
|
+
formulaChanged: boolean;
|
|
45
|
+
/** formula cells stored without a cached value (to compute after load) */
|
|
46
|
+
uncached: number[];
|
|
47
|
+
rows: (unknown[] | undefined)[];
|
|
48
|
+
maxRow: number;
|
|
49
|
+
maxCol: number;
|
|
50
|
+
formulas: Map<number, string>;
|
|
51
|
+
merges: Merge[];
|
|
52
|
+
colInfo: ColInfo[];
|
|
53
|
+
defaultColW: number;
|
|
54
|
+
defaultRowH: number;
|
|
55
|
+
frozen: {
|
|
56
|
+
rows: number;
|
|
57
|
+
cols: number;
|
|
58
|
+
};
|
|
59
|
+
gridLines: boolean;
|
|
60
|
+
done: boolean;
|
|
61
|
+
error?: string;
|
|
62
|
+
loading?: Promise<void>;
|
|
63
|
+
}
|
|
64
|
+
export declare class XlsxWorkbook {
|
|
65
|
+
readonly pkg: OpcPackage;
|
|
66
|
+
readonly mainPath: string;
|
|
67
|
+
readonly rels: Rels;
|
|
68
|
+
readonly sheets: SheetInfo[];
|
|
69
|
+
styles: SheetStyles;
|
|
70
|
+
readonly date1904: boolean;
|
|
71
|
+
readonly theme: Theme;
|
|
72
|
+
sheetsData: Map<number, SheetData>;
|
|
73
|
+
readonly calc: Calc;
|
|
74
|
+
sst: string[];
|
|
75
|
+
private sstLoading?;
|
|
76
|
+
private constructor();
|
|
77
|
+
static open(pkg: OpcPackage, mainPath: string): Promise<XlsxWorkbook>;
|
|
78
|
+
meta(): WorkbookMeta;
|
|
79
|
+
private loadSst;
|
|
80
|
+
/**
|
|
81
|
+
* Streams a sheet into memory, reporting progress so the UI can grow while parsing.
|
|
82
|
+
* Calling again for a loaded/in-flight sheet is a no-op.
|
|
83
|
+
*/
|
|
84
|
+
loadSheet(index: number, emit: (p: SheetProgress) => void, onBytes?: (phase: string, loaded: number, total: number) => void): Promise<void>;
|
|
85
|
+
private snapshot;
|
|
86
|
+
/** Formatted cells for rows [r0, r1). */
|
|
87
|
+
block(sheet: number, r0: number, r1: number): BlockOut;
|
|
88
|
+
/** cells whose shown value (or formula) contains `query`, in row order */
|
|
89
|
+
find(sheet: number, query: string, opts?: FindOptions, limit?: number): FindMatch[];
|
|
90
|
+
cell(sheet: number, r: number, c: number): CellDetail | undefined;
|
|
91
|
+
unload(sheet: number): void;
|
|
92
|
+
}
|
|
93
|
+
/** pixel heights of every non-default row: explicit heights / hidden rows win over font-grown ones */
|
|
94
|
+
export declare function rowSizesOf(d: SheetData): [number, number][];
|
|
@@ -0,0 +1,80 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Minimal streaming XML tokenizer tailored to OOXML (works inside Web Workers,
|
|
3
|
+
* where DOMParser is unavailable). Element names are reduced to local names;
|
|
4
|
+
* attributes too, except relationship-namespace ones which become `r:<local>`.
|
|
5
|
+
*/
|
|
6
|
+
export type Attrs = Record<string, string>;
|
|
7
|
+
export interface SaxHandler {
|
|
8
|
+
/** Return `true` to skip the element's whole subtree (no `close` is emitted then). */
|
|
9
|
+
open(name: string, attrs: Attrs, selfClosing: boolean): boolean | void;
|
|
10
|
+
close(name: string): void;
|
|
11
|
+
text(text: string): void;
|
|
12
|
+
}
|
|
13
|
+
export declare function decodeEntities(s: string): string;
|
|
14
|
+
export declare class SaxParser {
|
|
15
|
+
private h;
|
|
16
|
+
private raw?;
|
|
17
|
+
private buf;
|
|
18
|
+
private depth;
|
|
19
|
+
private skipDepth;
|
|
20
|
+
private relPrefixes;
|
|
21
|
+
/**
|
|
22
|
+
* @param raw optional tap receiving every consumed source segment verbatim (tags, text, comments…),
|
|
23
|
+
* called right before the matching handler event. Used for byte-preserving rewrites.
|
|
24
|
+
*/
|
|
25
|
+
constructor(h: SaxHandler, raw?: ((segment: string) => void) | undefined);
|
|
26
|
+
write(chunk: string): void;
|
|
27
|
+
end(): void;
|
|
28
|
+
private run;
|
|
29
|
+
private onText;
|
|
30
|
+
private onOpen;
|
|
31
|
+
private onClose;
|
|
32
|
+
}
|
|
33
|
+
export declare class AbortedError extends Error {
|
|
34
|
+
constructor();
|
|
35
|
+
}
|
|
36
|
+
export interface StreamParseOptions {
|
|
37
|
+
signal?: AbortSignal;
|
|
38
|
+
/** verbatim source tap, see SaxParser */
|
|
39
|
+
raw?: (segment: string) => void;
|
|
40
|
+
/** Called after each chunk (decompressed byte count); may return a promise to yield. */
|
|
41
|
+
onChunk?: (bytes: number) => void | Promise<void>;
|
|
42
|
+
}
|
|
43
|
+
export declare function parseXmlStream(stream: ReadableStream<Uint8Array>, h: SaxHandler, opts?: StreamParseOptions): Promise<void>;
|
|
44
|
+
export interface XEl {
|
|
45
|
+
n: string;
|
|
46
|
+
a: Attrs;
|
|
47
|
+
c: XEl[];
|
|
48
|
+
t: string;
|
|
49
|
+
}
|
|
50
|
+
export interface TreeBuilderOptions {
|
|
51
|
+
/** When set, elements at this depth are built and emitted one by one; ancestors are not kept. */
|
|
52
|
+
emitDepth?: number;
|
|
53
|
+
onElement?: (el: XEl) => void;
|
|
54
|
+
onShallowOpen?: (name: string, attrs: Attrs, depth: number) => void;
|
|
55
|
+
/** Element local names whose subtree is dropped. */
|
|
56
|
+
skip?: Set<string>;
|
|
57
|
+
}
|
|
58
|
+
/** Builds XEl trees; resolves mc:AlternateContent by taking the first mc:Choice. */
|
|
59
|
+
export declare class TreeBuilder implements SaxHandler {
|
|
60
|
+
private o;
|
|
61
|
+
root: XEl | null;
|
|
62
|
+
private stack;
|
|
63
|
+
private parents;
|
|
64
|
+
private depth;
|
|
65
|
+
private alt;
|
|
66
|
+
constructor(o?: TreeBuilderOptions);
|
|
67
|
+
open(name: string, a: Attrs): boolean | void;
|
|
68
|
+
close(name: string): void;
|
|
69
|
+
text(t: string): void;
|
|
70
|
+
}
|
|
71
|
+
export declare function parseXml(xml: string, skip?: Set<string>): XEl;
|
|
72
|
+
export declare function kid(el: XEl | undefined, name: string): XEl | undefined;
|
|
73
|
+
export declare function kids(el: XEl | undefined, name: string): XEl[];
|
|
74
|
+
export declare function path(el: XEl | undefined, ...names: string[]): XEl | undefined;
|
|
75
|
+
export declare function desc(el: XEl | undefined, name: string): XEl | undefined;
|
|
76
|
+
export declare function descAll(el: XEl | undefined, name: string, out?: XEl[]): XEl[];
|
|
77
|
+
export declare function num(v: string | undefined, def?: number): number | undefined;
|
|
78
|
+
/** OOXML on/off value: absent element → undefined, `<x/>` → true. */
|
|
79
|
+
export declare function onOff(el: XEl | undefined, attr?: string): boolean | undefined;
|
|
80
|
+
export declare function textOf(el: XEl | undefined): string;
|
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
import type { ByteSource } from './source';
|
|
2
|
+
export interface ZipEntry {
|
|
3
|
+
name: string;
|
|
4
|
+
method: number;
|
|
5
|
+
flags: number;
|
|
6
|
+
crc: number;
|
|
7
|
+
time: number;
|
|
8
|
+
date: number;
|
|
9
|
+
compSize: number;
|
|
10
|
+
size: number;
|
|
11
|
+
localOffset: number;
|
|
12
|
+
dataOffset?: number;
|
|
13
|
+
}
|
|
14
|
+
/**
|
|
15
|
+
* Lazy ZIP reader: parses only the central directory, then inflates single
|
|
16
|
+
* entries on demand straight from the byte source (native DecompressionStream).
|
|
17
|
+
*/
|
|
18
|
+
export declare class ZipArchive {
|
|
19
|
+
readonly src: ByteSource;
|
|
20
|
+
private entries;
|
|
21
|
+
private constructor();
|
|
22
|
+
static open(src: ByteSource): Promise<ZipArchive>;
|
|
23
|
+
private readDirectory;
|
|
24
|
+
list(): ZipEntry[];
|
|
25
|
+
get(path: string): ZipEntry | undefined;
|
|
26
|
+
has(path: string): boolean;
|
|
27
|
+
private dataOffset;
|
|
28
|
+
/** Compressed bytes of an entry, as stored (zero-copy Blob slice when the source allows). */
|
|
29
|
+
rawData(e: ZipEntry): Promise<Blob | Uint8Array>;
|
|
30
|
+
/** Decompressed stream of an entry. `onRaw` reports compressed bytes consumed. */
|
|
31
|
+
stream(path: string, onRaw?: (consumed: number, total: number) => void): Promise<ReadableStream<Uint8Array>>;
|
|
32
|
+
bytes(path: string): Promise<Uint8Array>;
|
|
33
|
+
text(path: string): Promise<string>;
|
|
34
|
+
}
|
|
35
|
+
export declare function normalize(path: string): string;
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
import { type ZipArchive } from './zip';
|
|
2
|
+
export declare function crc32(data: Uint8Array, crc?: number): number;
|
|
3
|
+
export type PartData = Uint8Array | string | (() => ReadableStream<Uint8Array>);
|
|
4
|
+
/**
|
|
5
|
+
* Re-packs an archive: unchanged entries are copied as stored (no recompression,
|
|
6
|
+
* zero-copy when the source is a Blob); changed/added entries are deflated.
|
|
7
|
+
* `changes`: path → new data, or null to delete.
|
|
8
|
+
*/
|
|
9
|
+
export declare function rebuildZip(zip: ZipArchive, changes: Map<string, PartData | null>, type?: string): Promise<Blob>;
|
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
import './core/default-worker';
|
|
2
|
+
import { DocViewer, type DocViewerProps } from './react/DocViewer';
|
|
3
|
+
export type MountOptions = Omit<DocViewerProps, 'styleTarget'>;
|
|
4
|
+
export interface MountedViewer {
|
|
5
|
+
update(next: Partial<MountOptions>): void;
|
|
6
|
+
destroy(): void;
|
|
7
|
+
}
|
|
8
|
+
/** Framework-free embedding: renders the viewer into `el`. */
|
|
9
|
+
export declare function mount(el: HTMLElement, options: MountOptions): MountedViewer;
|
|
10
|
+
/**
|
|
11
|
+
* `<office-viewer src="/file.xlsx" style="height:600px"></office-viewer>`
|
|
12
|
+
* Rendered inside a shadow root so host page CSS cannot leak in.
|
|
13
|
+
* Attributes: src, name, editable, toolbar ("false" to hide), thumbnails ("false" to hide);
|
|
14
|
+
* real-time collaboration: collab (hub WebSocket URL), room, user (display name).
|
|
15
|
+
* Property: `file` (File/Blob/ArrayBuffer) for local data.
|
|
16
|
+
*/
|
|
17
|
+
export declare class OfficeViewerElement extends HTMLElement {
|
|
18
|
+
static observedAttributes: string[];
|
|
19
|
+
private viewer?;
|
|
20
|
+
private _file?;
|
|
21
|
+
get file(): Blob | ArrayBuffer | undefined;
|
|
22
|
+
set file(v: Blob | ArrayBuffer | undefined);
|
|
23
|
+
connectedCallback(): void;
|
|
24
|
+
disconnectedCallback(): void;
|
|
25
|
+
attributeChangedCallback(): void;
|
|
26
|
+
private props;
|
|
27
|
+
private sync;
|
|
28
|
+
}
|
|
29
|
+
export declare function defineElement(tag?: string): void;
|
|
30
|
+
export { DocViewer };
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
import './core/default-worker';
|
|
2
|
+
export { DocViewer, type DocViewerProps } from './react/DocViewer';
|
|
3
|
+
export { DocxView, type DocxViewProps } from './react/docx/DocxView';
|
|
4
|
+
export { XlsxView, type XlsxViewProps } from './react/xlsx/XlsxView';
|
|
5
|
+
export { PptxView, type PptxViewProps } from './react/pptx/PptxView';
|
|
6
|
+
export { SlideView } from './react/pptx/Slide';
|
|
7
|
+
export { useDocument, type DocumentState } from './react/useDocument';
|
|
8
|
+
export { injectStyles, stylesText } from './react/injectStyles';
|
|
9
|
+
export type { Zoom } from './react/common/ZoomControl';
|
|
10
|
+
export { DocumentClient, setDefaultWorker, type OpenOptions } from './core/worker/client';
|
|
11
|
+
export type { DocSource } from './core/source';
|
|
12
|
+
export type { DocKind } from './core/opc';
|
|
13
|
+
export type * from './core/docx/types';
|
|
14
|
+
export type * from './core/xlsx/types';
|
|
15
|
+
export type * from './core/pptx/types';
|
|
16
|
+
export { startCollab, CollabHub, CollabSession, MemoryTransport, WebSocketTransport, type Collab, type CollabOptions, type CollabStatus, type Transport } from './collab';
|
|
17
|
+
export type { PeerInfo, UserInfo } from './collab/protocol';
|
|
18
|
+
export { useCollab, CollabBar, PeerOverlay } from './collab/react';
|
|
@@ -0,0 +1,43 @@
|
|
|
1
|
+
import { type CSSProperties, type ReactNode } from 'react';
|
|
2
|
+
import type { DocSource } from '../core/source';
|
|
3
|
+
import type { DocumentClient, OpenOptions } from '../core/worker/client';
|
|
4
|
+
import type { Zoom } from './common/ZoomControl';
|
|
5
|
+
import type { CollabOptions } from '../collab';
|
|
6
|
+
export interface DocViewerProps {
|
|
7
|
+
/** File, Blob, ArrayBuffer, Uint8Array or URL (HTTP Range requests are used when the server supports them). */
|
|
8
|
+
src: DocSource | null | undefined;
|
|
9
|
+
/** Display name (defaults to File.name or the URL's last segment). */
|
|
10
|
+
name?: string;
|
|
11
|
+
className?: string;
|
|
12
|
+
style?: CSSProperties;
|
|
13
|
+
/** Show the top bar (name, status, progress). Default true. */
|
|
14
|
+
toolbar?: boolean;
|
|
15
|
+
/** Extra toolbar content (rendered at the right). */
|
|
16
|
+
toolbarExtra?: ReactNode;
|
|
17
|
+
/** Initial zoom for documents and presentations. Default 'fit'. */
|
|
18
|
+
zoom?: Zoom;
|
|
19
|
+
/** Show slide thumbnails for presentations. Default true. */
|
|
20
|
+
thumbnails?: boolean;
|
|
21
|
+
headers?: Record<string, string>;
|
|
22
|
+
credentials?: RequestCredentials;
|
|
23
|
+
/** Custom worker factory, or false to parse on the main thread. */
|
|
24
|
+
worker?: OpenOptions['worker'];
|
|
25
|
+
/** Where to inject the stylesheet (document or a shadow root). */
|
|
26
|
+
styleTarget?: Document | ShadowRoot;
|
|
27
|
+
onLoad?: (client: DocumentClient) => void;
|
|
28
|
+
onError?: (error: Error) => void;
|
|
29
|
+
/** Start in edit mode. Default false (view). */
|
|
30
|
+
editable?: boolean;
|
|
31
|
+
/** Show the Edit/View toggle. Default true. */
|
|
32
|
+
allowEdit?: boolean;
|
|
33
|
+
/** Receives the saved file instead of downloading it. */
|
|
34
|
+
onSave?: (file: Blob, name: string) => void | Promise<void>;
|
|
35
|
+
/** Called when the document gets / loses unsaved changes. */
|
|
36
|
+
onDirtyChange?: (dirty: boolean) => void;
|
|
37
|
+
/**
|
|
38
|
+
* Real-time collaboration: everyone opening the same base document (`src`) with the same `room`
|
|
39
|
+
* edits it together through the hub at `transport` (see src/collab).
|
|
40
|
+
*/
|
|
41
|
+
collab?: CollabOptions;
|
|
42
|
+
}
|
|
43
|
+
export declare function DocViewer(props: DocViewerProps): import("react").JSX.Element;
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
export interface MenuItem {
|
|
2
|
+
label: string;
|
|
3
|
+
run: () => void;
|
|
4
|
+
disabled?: boolean;
|
|
5
|
+
/** separator above this item */
|
|
6
|
+
sep?: boolean;
|
|
7
|
+
/** shortcut / secondary text */
|
|
8
|
+
hint?: string;
|
|
9
|
+
icon?: string;
|
|
10
|
+
/** small section title above this item */
|
|
11
|
+
head?: string;
|
|
12
|
+
}
|
|
13
|
+
/** Right-click menu at viewport coordinates; never steals focus from the editor. */
|
|
14
|
+
export declare function ContextMenu({ x, y, items, onClose }: {
|
|
15
|
+
x: number;
|
|
16
|
+
y: number;
|
|
17
|
+
items: MenuItem[];
|
|
18
|
+
onClose: () => void;
|
|
19
|
+
}): import("react").JSX.Element;
|
|
20
|
+
/** platform modifier label for shortcut hints */
|
|
21
|
+
export declare const MOD: string;
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
import { type ReactNode } from 'react';
|
|
2
|
+
export interface PromptSpec {
|
|
3
|
+
title: string;
|
|
4
|
+
label?: string;
|
|
5
|
+
initial?: string;
|
|
6
|
+
placeholder?: string;
|
|
7
|
+
ok?: string;
|
|
8
|
+
/** multi-line input */
|
|
9
|
+
area?: boolean;
|
|
10
|
+
onOk: (value: string) => void;
|
|
11
|
+
/** extra button (e.g. "Remove link") */
|
|
12
|
+
extra?: {
|
|
13
|
+
label: string;
|
|
14
|
+
run: () => void;
|
|
15
|
+
};
|
|
16
|
+
note?: ReactNode;
|
|
17
|
+
}
|
|
18
|
+
/** Small modal prompt (no window.prompt: works in sandboxed / embedded pages). */
|
|
19
|
+
export declare function PromptDialog({ spec, onClose }: {
|
|
20
|
+
spec: PromptSpec;
|
|
21
|
+
onClose: () => void;
|
|
22
|
+
}): import("react").JSX.Element;
|
|
23
|
+
/** Short-lived message at the bottom of the viewer. */
|
|
24
|
+
export declare function Toast({ text, onDone }: {
|
|
25
|
+
text: string;
|
|
26
|
+
onDone: () => void;
|
|
27
|
+
}): import("react").JSX.Element;
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
import { type ReactNode } from 'react';
|
|
2
|
+
import type { DocumentClient } from '../../core/worker/client';
|
|
3
|
+
export interface ViewerApi {
|
|
4
|
+
/** editor bar mount point (null when the viewer toolbar is hidden) */
|
|
5
|
+
bar: HTMLElement | null;
|
|
6
|
+
editable: boolean;
|
|
7
|
+
/** report unsaved changes */
|
|
8
|
+
setDirty: (dirty: boolean) => void;
|
|
9
|
+
/** build + hand off the edited file */
|
|
10
|
+
save: () => Promise<void>;
|
|
11
|
+
client: DocumentClient | null;
|
|
12
|
+
}
|
|
13
|
+
export declare const ViewerContext: import("react").Context<ViewerApi>;
|
|
14
|
+
export declare const useViewer: () => ViewerApi;
|
|
15
|
+
/** Renders the editor bar into the viewer's toolbar row. */
|
|
16
|
+
export declare function EditorBar({ children }: {
|
|
17
|
+
children: ReactNode;
|
|
18
|
+
}): import("react").ReactPortal | null;
|
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
/** Toolbar slot provided by DocViewer; views portal their status text into it (no parent re-render). */
|
|
2
|
+
export declare const StatusContext: import("react").Context<HTMLElement | null>;
|
|
3
|
+
export declare function Status({ text, onStatus }: {
|
|
4
|
+
text: string;
|
|
5
|
+
onStatus?: (s: string) => void;
|
|
6
|
+
}): import("react").ReactPortal | null;
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
import { useLayoutEffect } from 'react';
|
|
2
|
+
import type { DocumentClient } from '../../core/worker/client';
|
|
3
|
+
export declare const useIsoLayoutEffect: typeof useLayoutEffect;
|
|
4
|
+
export declare function useForceUpdate(): [number, () => void];
|
|
5
|
+
/** Element size via ResizeObserver. */
|
|
6
|
+
export declare function useSize<T extends HTMLElement>(): [React.RefObject<T | null>, {
|
|
7
|
+
w: number;
|
|
8
|
+
h: number;
|
|
9
|
+
}];
|
|
10
|
+
/** Scroll position of an element, batched to animation frames. */
|
|
11
|
+
export declare function useScroll(ref: React.RefObject<HTMLElement | null>): {
|
|
12
|
+
x: number;
|
|
13
|
+
y: number;
|
|
14
|
+
};
|
|
15
|
+
/** Lazily resolves a package part to an object URL (null while loading / unsupported). */
|
|
16
|
+
export declare function useMediaUrl(client: DocumentClient, path: string | undefined, enabled?: boolean): string | null | 'unsupported';
|
|
17
|
+
/** Binary search: last index i with arr[i] <= v. */
|
|
18
|
+
export declare function lowerIndex(arr: ArrayLike<number>, v: number): number;
|
|
19
|
+
export declare function useLatest<T>(v: T): import("react").RefObject<T>;
|
|
20
|
+
export declare function useStableCallback<A extends unknown[], R>(fn: (...a: A) => R): (...a: A) => R;
|