@repa/document-viewer 0.0.0-stage → 0.1.0-alpha.20
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 +36 -0
- package/README.md +242 -2
- package/dist/index.d.ts +250 -0
- package/dist/index.js +904 -0
- package/dist/react.d.ts +284 -0
- package/dist/react.js +1026 -0
- package/package.json +60 -3
- package/wasm/build-info.json +123 -0
- package/wasm/document_viewer_wasm.d.ts +160 -0
- package/wasm/document_viewer_wasm.js +1216 -0
- package/wasm/document_viewer_wasm_bg.wasm +0 -0
- package/wasm/document_viewer_wasm_bg.wasm.d.ts +42 -0
package/dist/react.d.ts
ADDED
|
@@ -0,0 +1,284 @@
|
|
|
1
|
+
import { CSSProperties, ReactElement } from 'react';
|
|
2
|
+
|
|
3
|
+
interface DocumentFontFileRequirement {
|
|
4
|
+
readonly fileHash: string;
|
|
5
|
+
readonly byteLength: number;
|
|
6
|
+
}
|
|
7
|
+
interface DocumentFontRequestContext {
|
|
8
|
+
readonly packageFingerprint: string;
|
|
9
|
+
readonly signal: AbortSignal;
|
|
10
|
+
}
|
|
11
|
+
type DocumentViewerFontSource = (requirement: DocumentFontFileRequirement, context: DocumentFontRequestContext) => Promise<Uint8Array>;
|
|
12
|
+
interface DocumentPageSnapshot {
|
|
13
|
+
readonly pageIndex: number;
|
|
14
|
+
readonly widthPt: number;
|
|
15
|
+
readonly heightPt: number;
|
|
16
|
+
}
|
|
17
|
+
interface DocumentViewerSnapshot {
|
|
18
|
+
readonly packageFingerprint: string;
|
|
19
|
+
readonly fontClosureSha256: string;
|
|
20
|
+
readonly fontReleaseDigest: string;
|
|
21
|
+
readonly pageCount: number;
|
|
22
|
+
readonly pageWidthPt: number;
|
|
23
|
+
readonly pageHeightPt: number;
|
|
24
|
+
readonly pages: readonly DocumentPageSnapshot[];
|
|
25
|
+
}
|
|
26
|
+
type DocumentCaretAffinity = "Upstream" | "Downstream";
|
|
27
|
+
type DocumentSelectionDirection = "forward" | "backward";
|
|
28
|
+
interface DocumentSemanticRange {
|
|
29
|
+
readonly paragraphId: string;
|
|
30
|
+
readonly storyKind: string;
|
|
31
|
+
readonly layoutOccurrenceId: string;
|
|
32
|
+
readonly startByte: number;
|
|
33
|
+
readonly endByte: number;
|
|
34
|
+
readonly startAffinity: DocumentCaretAffinity;
|
|
35
|
+
readonly endAffinity: DocumentCaretAffinity;
|
|
36
|
+
}
|
|
37
|
+
interface DocumentRect {
|
|
38
|
+
readonly pageIndex: number;
|
|
39
|
+
readonly xPt: number;
|
|
40
|
+
readonly yPt: number;
|
|
41
|
+
readonly widthPt: number;
|
|
42
|
+
readonly heightPt: number;
|
|
43
|
+
}
|
|
44
|
+
interface DocumentSelectionGeometry {
|
|
45
|
+
readonly rects: readonly DocumentRect[];
|
|
46
|
+
readonly caret: DocumentRect | null;
|
|
47
|
+
readonly generation: number;
|
|
48
|
+
}
|
|
49
|
+
interface DocumentSelection {
|
|
50
|
+
readonly packageFingerprint: string;
|
|
51
|
+
readonly ranges: readonly DocumentSemanticRange[];
|
|
52
|
+
readonly direction: DocumentSelectionDirection;
|
|
53
|
+
readonly text: string;
|
|
54
|
+
readonly geometry: DocumentSelectionGeometry;
|
|
55
|
+
}
|
|
56
|
+
/**
|
|
57
|
+
* Canonical application-owned coordinates for programmatic selection. Text
|
|
58
|
+
* and geometry are intentionally recomputed by the exact viewer runtime.
|
|
59
|
+
*/
|
|
60
|
+
interface DocumentSelectionTarget {
|
|
61
|
+
readonly packageFingerprint: string;
|
|
62
|
+
readonly ranges: readonly DocumentSemanticRange[];
|
|
63
|
+
readonly direction?: DocumentSelectionDirection;
|
|
64
|
+
}
|
|
65
|
+
interface DocumentBlockGeometry {
|
|
66
|
+
readonly blockId: string;
|
|
67
|
+
readonly sourceBlockId: string | null;
|
|
68
|
+
readonly sourceTableId: string | null;
|
|
69
|
+
readonly partId: string;
|
|
70
|
+
readonly kind: string;
|
|
71
|
+
readonly order: number;
|
|
72
|
+
readonly layoutOccurrenceId: string;
|
|
73
|
+
readonly rects: readonly DocumentRect[];
|
|
74
|
+
}
|
|
75
|
+
interface DocumentPlaceholderGeometry {
|
|
76
|
+
readonly occurrenceId: string;
|
|
77
|
+
readonly canonicalKey: string;
|
|
78
|
+
readonly partId: string;
|
|
79
|
+
readonly blockId: string | null;
|
|
80
|
+
readonly paragraphId: string | null;
|
|
81
|
+
readonly storyKind: string | null;
|
|
82
|
+
readonly layoutOccurrenceId: string | null;
|
|
83
|
+
readonly rawText: string;
|
|
84
|
+
readonly rects: readonly DocumentRect[];
|
|
85
|
+
}
|
|
86
|
+
interface DocumentRowGeometry {
|
|
87
|
+
readonly rowId: string | null;
|
|
88
|
+
readonly sourceRowIndex: number;
|
|
89
|
+
readonly layoutRowIndex: number;
|
|
90
|
+
readonly layoutOccurrenceId: string;
|
|
91
|
+
readonly repeatedHeaderOrdinal: number | null;
|
|
92
|
+
readonly rect: DocumentRect;
|
|
93
|
+
}
|
|
94
|
+
interface DocumentCellGeometry {
|
|
95
|
+
readonly cellId: string;
|
|
96
|
+
readonly rowId: string | null;
|
|
97
|
+
readonly sourceRowIndex: number;
|
|
98
|
+
readonly startColumnIndex: number;
|
|
99
|
+
readonly endColumnIndex: number;
|
|
100
|
+
readonly layoutOccurrenceId: string;
|
|
101
|
+
readonly repeatedHeaderOrdinal: number | null;
|
|
102
|
+
readonly paragraphIds: readonly string[];
|
|
103
|
+
readonly rect: DocumentRect;
|
|
104
|
+
readonly contentRect: DocumentRect;
|
|
105
|
+
}
|
|
106
|
+
interface DocumentTableOccurrenceGeometry {
|
|
107
|
+
readonly layoutOccurrenceId: string;
|
|
108
|
+
readonly pageIndex: number;
|
|
109
|
+
readonly storyKind: string;
|
|
110
|
+
readonly sourceStartRowIndex: number;
|
|
111
|
+
readonly sourceEndRowIndex: number;
|
|
112
|
+
readonly rect: DocumentRect;
|
|
113
|
+
readonly rows: readonly DocumentRowGeometry[];
|
|
114
|
+
readonly cells: readonly DocumentCellGeometry[];
|
|
115
|
+
}
|
|
116
|
+
interface DocumentTableGeometry {
|
|
117
|
+
readonly tableId: string;
|
|
118
|
+
readonly occurrences: readonly DocumentTableOccurrenceGeometry[];
|
|
119
|
+
}
|
|
120
|
+
interface DocumentStructureIndex {
|
|
121
|
+
readonly packageFingerprint: string;
|
|
122
|
+
readonly blocks: readonly DocumentBlockGeometry[];
|
|
123
|
+
readonly placeholders: readonly DocumentPlaceholderGeometry[];
|
|
124
|
+
readonly tables: readonly DocumentTableGeometry[];
|
|
125
|
+
}
|
|
126
|
+
interface DocumentStructureMatches {
|
|
127
|
+
readonly packageFingerprint: string;
|
|
128
|
+
readonly blocks: readonly DocumentBlockGeometry[];
|
|
129
|
+
readonly placeholders: readonly DocumentPlaceholderGeometry[];
|
|
130
|
+
readonly tables: readonly DocumentTableGeometry[];
|
|
131
|
+
readonly rows: readonly DocumentRowGeometry[];
|
|
132
|
+
readonly cells: readonly DocumentCellGeometry[];
|
|
133
|
+
}
|
|
134
|
+
type DocumentStructureSelectionKind = "block" | "table" | "row" | "cell";
|
|
135
|
+
type DocumentSelectionMode = "text" | DocumentStructureSelectionKind;
|
|
136
|
+
type DocumentStructureSelection = {
|
|
137
|
+
readonly packageFingerprint: string;
|
|
138
|
+
readonly kind: "block";
|
|
139
|
+
readonly target: DocumentBlockGeometry;
|
|
140
|
+
readonly geometry: readonly DocumentRect[];
|
|
141
|
+
} | {
|
|
142
|
+
readonly packageFingerprint: string;
|
|
143
|
+
readonly kind: "table";
|
|
144
|
+
readonly target: DocumentTableGeometry;
|
|
145
|
+
readonly geometry: readonly DocumentRect[];
|
|
146
|
+
} | {
|
|
147
|
+
readonly packageFingerprint: string;
|
|
148
|
+
readonly kind: "row";
|
|
149
|
+
readonly target: DocumentRowGeometry;
|
|
150
|
+
readonly geometry: readonly DocumentRect[];
|
|
151
|
+
} | {
|
|
152
|
+
readonly packageFingerprint: string;
|
|
153
|
+
readonly kind: "cell";
|
|
154
|
+
readonly target: DocumentCellGeometry;
|
|
155
|
+
readonly geometry: readonly DocumentRect[];
|
|
156
|
+
};
|
|
157
|
+
interface DocumentPoint {
|
|
158
|
+
readonly pageIndex: number;
|
|
159
|
+
readonly xPt: number;
|
|
160
|
+
readonly yPt: number;
|
|
161
|
+
}
|
|
162
|
+
type DocumentPointerType = "mouse" | "pen" | "touch" | "unknown";
|
|
163
|
+
interface DocumentPointerInput {
|
|
164
|
+
readonly pointerType: DocumentPointerType;
|
|
165
|
+
readonly isPrimary: boolean;
|
|
166
|
+
readonly buttons: number;
|
|
167
|
+
readonly modifiers: {
|
|
168
|
+
readonly alt: boolean;
|
|
169
|
+
readonly control: boolean;
|
|
170
|
+
readonly meta: boolean;
|
|
171
|
+
readonly shift: boolean;
|
|
172
|
+
};
|
|
173
|
+
}
|
|
174
|
+
type DocumentPointerCursor = "auto" | "default" | "text" | "pointer" | "crosshair" | "cell" | "grab" | "grabbing" | "col-resize" | "row-resize";
|
|
175
|
+
interface DocumentPointerTarget {
|
|
176
|
+
readonly packageFingerprint: string;
|
|
177
|
+
readonly point: DocumentPoint;
|
|
178
|
+
readonly selectableText: boolean;
|
|
179
|
+
readonly structures: DocumentStructureMatches;
|
|
180
|
+
}
|
|
181
|
+
interface DocumentPointerTargetChangeEvent {
|
|
182
|
+
readonly target: DocumentPointerTarget | null;
|
|
183
|
+
readonly input: DocumentPointerInput;
|
|
184
|
+
}
|
|
185
|
+
interface DocumentSelectionChangeEvent {
|
|
186
|
+
readonly selection: DocumentSelection | null;
|
|
187
|
+
readonly structures: DocumentStructureMatches | null;
|
|
188
|
+
readonly input: DocumentPointerInput | null;
|
|
189
|
+
}
|
|
190
|
+
interface DocumentStructureSelectionChangeEvent {
|
|
191
|
+
readonly selection: DocumentStructureSelection | null;
|
|
192
|
+
readonly input: DocumentPointerInput | null;
|
|
193
|
+
}
|
|
194
|
+
interface DocumentViewerOptions {
|
|
195
|
+
readonly container: HTMLElement;
|
|
196
|
+
readonly fontFiles: DocumentViewerFontSource;
|
|
197
|
+
readonly initialZoom?: number;
|
|
198
|
+
readonly minimumZoom?: number;
|
|
199
|
+
readonly maximumZoom?: number;
|
|
200
|
+
readonly devicePixelRatio?: number;
|
|
201
|
+
readonly initialSelectionMode?: DocumentSelectionMode;
|
|
202
|
+
readonly onSelectionChange?: (event: DocumentSelectionChangeEvent) => void;
|
|
203
|
+
readonly onStructureSelectionChange?: (event: DocumentStructureSelectionChangeEvent) => void;
|
|
204
|
+
readonly onPointerTargetChange?: (event: DocumentPointerTargetChangeEvent) => void;
|
|
205
|
+
readonly resolvePointerCursor?: (event: DocumentPointerTargetChangeEvent & {
|
|
206
|
+
readonly target: DocumentPointerTarget;
|
|
207
|
+
}) => DocumentPointerCursor | undefined;
|
|
208
|
+
readonly onError?: (error: DocumentViewerError) => void;
|
|
209
|
+
}
|
|
210
|
+
/**
|
|
211
|
+
* Framework- and capability-neutral semantic surface. Application layers such
|
|
212
|
+
* as a contract manager can consume this interface from either a viewer or a
|
|
213
|
+
* future editor without depending on either concrete runtime.
|
|
214
|
+
*/
|
|
215
|
+
interface DocumentSemanticSurface {
|
|
216
|
+
readonly snapshot: DocumentViewerSnapshot | null;
|
|
217
|
+
selectionMode(): DocumentSelectionMode;
|
|
218
|
+
setSelectionMode(mode: DocumentSelectionMode): void;
|
|
219
|
+
selection(): DocumentSelection | null;
|
|
220
|
+
structureSelection(): DocumentStructureSelection | null;
|
|
221
|
+
selectRanges(target: DocumentSelectionTarget): DocumentSelection;
|
|
222
|
+
restoreSelection(selection: DocumentSelection): DocumentSelection;
|
|
223
|
+
clearSelection(): void;
|
|
224
|
+
structures(): DocumentStructureIndex;
|
|
225
|
+
hitTestPointerTarget(point: DocumentPoint): DocumentPointerTarget;
|
|
226
|
+
hitTestStructures(point: DocumentPoint): DocumentStructureMatches;
|
|
227
|
+
structuresForSelection(): DocumentStructureMatches;
|
|
228
|
+
}
|
|
229
|
+
interface DocumentViewer extends DocumentSemanticSurface {
|
|
230
|
+
load(bytes: Uint8Array): Promise<DocumentViewerSnapshot>;
|
|
231
|
+
zoom(): number;
|
|
232
|
+
setZoom(zoom: number): void;
|
|
233
|
+
setDevicePixelRatio(devicePixelRatio: number): void;
|
|
234
|
+
resize(): void;
|
|
235
|
+
scrollToPage(pageIndex: number): void;
|
|
236
|
+
dispose(): void;
|
|
237
|
+
}
|
|
238
|
+
declare class DocumentViewerError extends Error {
|
|
239
|
+
readonly code: string;
|
|
240
|
+
readonly cause: unknown;
|
|
241
|
+
constructor(code: string, message: string, cause?: unknown);
|
|
242
|
+
}
|
|
243
|
+
|
|
244
|
+
interface UseDocumentViewerOptions {
|
|
245
|
+
readonly container: HTMLElement | null;
|
|
246
|
+
readonly bytes: Uint8Array | null;
|
|
247
|
+
readonly fontFiles: DocumentViewerFontSource;
|
|
248
|
+
readonly zoom?: number;
|
|
249
|
+
readonly minimumZoom?: number;
|
|
250
|
+
readonly maximumZoom?: number;
|
|
251
|
+
readonly devicePixelRatio?: number;
|
|
252
|
+
readonly selectionMode?: DocumentSelectionMode;
|
|
253
|
+
readonly onSelectionChange?: (event: DocumentSelectionChangeEvent) => void;
|
|
254
|
+
readonly onStructureSelectionChange?: (event: DocumentStructureSelectionChangeEvent) => void;
|
|
255
|
+
readonly onPointerTargetChange?: (event: DocumentPointerTargetChangeEvent) => void;
|
|
256
|
+
readonly resolvePointerCursor?: DocumentViewerOptions["resolvePointerCursor"];
|
|
257
|
+
readonly onError?: (error: DocumentViewerError) => void;
|
|
258
|
+
}
|
|
259
|
+
interface UseDocumentViewerResult {
|
|
260
|
+
readonly viewer: DocumentViewer | null;
|
|
261
|
+
readonly snapshot: DocumentViewerSnapshot | null;
|
|
262
|
+
readonly error: DocumentViewerError | null;
|
|
263
|
+
}
|
|
264
|
+
declare function useDocumentViewer(options: UseDocumentViewerOptions): UseDocumentViewerResult;
|
|
265
|
+
interface DocumentViewerCanvasProps {
|
|
266
|
+
readonly bytes: Uint8Array | null;
|
|
267
|
+
readonly fontFiles: DocumentViewerFontSource;
|
|
268
|
+
readonly zoom?: number;
|
|
269
|
+
readonly minimumZoom?: number;
|
|
270
|
+
readonly maximumZoom?: number;
|
|
271
|
+
readonly devicePixelRatio?: number;
|
|
272
|
+
readonly selectionMode?: DocumentSelectionMode;
|
|
273
|
+
readonly className?: string;
|
|
274
|
+
readonly style?: CSSProperties;
|
|
275
|
+
readonly onReady?: (viewer: DocumentViewer, snapshot: DocumentViewerSnapshot) => void;
|
|
276
|
+
readonly onSelectionChange?: (event: DocumentSelectionChangeEvent) => void;
|
|
277
|
+
readonly onStructureSelectionChange?: (event: DocumentStructureSelectionChangeEvent) => void;
|
|
278
|
+
readonly onPointerTargetChange?: (event: DocumentPointerTargetChangeEvent) => void;
|
|
279
|
+
readonly resolvePointerCursor?: DocumentViewerOptions["resolvePointerCursor"];
|
|
280
|
+
readonly onError?: (error: DocumentViewerError) => void;
|
|
281
|
+
}
|
|
282
|
+
declare function DocumentViewerCanvas(props: DocumentViewerCanvasProps): ReactElement;
|
|
283
|
+
|
|
284
|
+
export { DocumentViewerCanvas, type DocumentViewerCanvasProps, type UseDocumentViewerOptions, type UseDocumentViewerResult, useDocumentViewer };
|