@f-office/wasm 0.0.0-stage → 0.2.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 +168 -0
- package/NOTICE +31 -0
- package/README.md +79 -2
- package/dist/index.d.ts +113 -0
- package/dist/index.js +342 -0
- package/dist/source.d.ts +30 -0
- package/dist/source.js +64 -0
- package/dist/types.d.ts +92 -0
- package/dist/types.js +1 -0
- package/dist/wasm/f_office_wasm.d.ts +398 -0
- package/dist/wasm/f_office_wasm.js +1189 -0
- package/dist/wasm/f_office_wasm_bg.wasm +0 -0
- package/dist/wasm/f_office_wasm_bg.wasm.d.ts +60 -0
- package/dist/worker.d.ts +55 -0
- package/dist/worker.js +325 -0
- package/package.json +51 -4
|
@@ -0,0 +1,398 @@
|
|
|
1
|
+
/* tslint:disable */
|
|
2
|
+
/* eslint-disable */
|
|
3
|
+
|
|
4
|
+
/**
|
|
5
|
+
* A document laid out into pages. Page indexes count from 0.
|
|
6
|
+
*/
|
|
7
|
+
export class Document {
|
|
8
|
+
private constructor();
|
|
9
|
+
free(): void;
|
|
10
|
+
[Symbol.dispose](): void;
|
|
11
|
+
/**
|
|
12
|
+
* Returns the fonts that the layout looked for and the renderer lacks, each once, with the
|
|
13
|
+
* families that the target tries for each. This includes fallback fonts looked up for
|
|
14
|
+
* characters that the primary fonts lack.
|
|
15
|
+
*/
|
|
16
|
+
fontNeeds(): FontNeed[];
|
|
17
|
+
/**
|
|
18
|
+
* Returns the headings of the body in the order of the document.
|
|
19
|
+
*/
|
|
20
|
+
outline(): OutlineEntry[];
|
|
21
|
+
/**
|
|
22
|
+
* Returns the number of pages.
|
|
23
|
+
*/
|
|
24
|
+
pageCount(): number;
|
|
25
|
+
/**
|
|
26
|
+
* Returns the height in pixels of the image that `renderPage` draws at `dpi`.
|
|
27
|
+
*
|
|
28
|
+
* # Errors
|
|
29
|
+
*
|
|
30
|
+
* Throws when the page does not exist or cannot be drawn at this resolution.
|
|
31
|
+
*/
|
|
32
|
+
pageHeight(index: number, dpi: number): number;
|
|
33
|
+
/**
|
|
34
|
+
* Returns the width and the height in points of every page, in order: the width of page 0,
|
|
35
|
+
* its height, the width of page 1, and so on.
|
|
36
|
+
*/
|
|
37
|
+
pageSizes(): Float64Array;
|
|
38
|
+
/**
|
|
39
|
+
* Returns the width in pixels of the image that `renderPage` draws at `dpi`.
|
|
40
|
+
*
|
|
41
|
+
* # Errors
|
|
42
|
+
*
|
|
43
|
+
* Throws when the page does not exist or cannot be drawn at this resolution.
|
|
44
|
+
*/
|
|
45
|
+
pageWidth(index: number, dpi: number): number;
|
|
46
|
+
/**
|
|
47
|
+
* Draws one page at `dpi` pixels per inch on a white background. A CSS pixel is 1/96 inch,
|
|
48
|
+
* so a sharp image for the screen uses `96 * devicePixelRatio`.
|
|
49
|
+
*
|
|
50
|
+
* # Errors
|
|
51
|
+
*
|
|
52
|
+
* Throws when the page does not exist, or cannot be drawn at this resolution.
|
|
53
|
+
*/
|
|
54
|
+
renderPage(index: number, dpi: number): PageImage;
|
|
55
|
+
/**
|
|
56
|
+
* Draws only the rectangular pixel tile `(x, y, width, height)` of page `index` at `dpi`
|
|
57
|
+
* pixels per inch on a white background, keeping memory proportional to the tile size.
|
|
58
|
+
*
|
|
59
|
+
* # Errors
|
|
60
|
+
*
|
|
61
|
+
* Throws when the page does not exist or the tile cannot be drawn at this resolution.
|
|
62
|
+
*/
|
|
63
|
+
renderRegion(index: number, x: number, y: number, width: number, height: number, dpi: number): PageImage;
|
|
64
|
+
/**
|
|
65
|
+
* Returns the upright text runs of one page in painting order, for a text layer.
|
|
66
|
+
*
|
|
67
|
+
* # Errors
|
|
68
|
+
*
|
|
69
|
+
* Throws when the page does not exist.
|
|
70
|
+
*/
|
|
71
|
+
textRuns(index: number): TextRun[];
|
|
72
|
+
/**
|
|
73
|
+
* Returns the text of each distinct warning of the layout, such as a font that another font
|
|
74
|
+
* draws or a picture that the file lacks, once each.
|
|
75
|
+
*/
|
|
76
|
+
warnings(): string[];
|
|
77
|
+
/**
|
|
78
|
+
* Streams the laid-out pages as PDF 1.7 chunks into `onChunk(chunk: Uint8Array)` without
|
|
79
|
+
* buffering the complete PDF in WebAssembly linear memory, returning distinct PDF warnings.
|
|
80
|
+
*
|
|
81
|
+
* # Errors
|
|
82
|
+
*
|
|
83
|
+
* Throws when the pages cannot be written as PDF or `onChunk` throws.
|
|
84
|
+
*/
|
|
85
|
+
writePdfTo(on_chunk: Function): string[];
|
|
86
|
+
/**
|
|
87
|
+
* Writes the laid-out pages as a PDF file with the renderer's fonts subset and embedded.
|
|
88
|
+
*
|
|
89
|
+
* # Errors
|
|
90
|
+
*
|
|
91
|
+
* Throws when the pages cannot be written as PDF.
|
|
92
|
+
*/
|
|
93
|
+
writePdf(): Uint8Array;
|
|
94
|
+
}
|
|
95
|
+
|
|
96
|
+
/**
|
|
97
|
+
* A font that a document's text asks for and the families that the target tries for it.
|
|
98
|
+
*/
|
|
99
|
+
export class FontNeed {
|
|
100
|
+
private constructor();
|
|
101
|
+
free(): void;
|
|
102
|
+
[Symbol.dispose](): void;
|
|
103
|
+
/**
|
|
104
|
+
* The family that the text asks for, or `undefined` for text that names no font.
|
|
105
|
+
*/
|
|
106
|
+
readonly family: string | undefined;
|
|
107
|
+
/**
|
|
108
|
+
* The families that the layout tries for the text, in order.
|
|
109
|
+
*/
|
|
110
|
+
readonly tried: string[];
|
|
111
|
+
}
|
|
112
|
+
|
|
113
|
+
/**
|
|
114
|
+
* A heading of the document's outline.
|
|
115
|
+
*/
|
|
116
|
+
export class OutlineEntry {
|
|
117
|
+
private constructor();
|
|
118
|
+
free(): void;
|
|
119
|
+
[Symbol.dispose](): void;
|
|
120
|
+
/**
|
|
121
|
+
* The address of its paragraph in the body, such as `p12`.
|
|
122
|
+
*/
|
|
123
|
+
readonly address: string;
|
|
124
|
+
/**
|
|
125
|
+
* The heading's level, from 0 for the top level to 8: the level that the body's table of
|
|
126
|
+
* contents gives it when the outline follows that table, else its outline level.
|
|
127
|
+
*/
|
|
128
|
+
readonly level: number;
|
|
129
|
+
/**
|
|
130
|
+
* The index of the page of its first line, counted from 0.
|
|
131
|
+
*/
|
|
132
|
+
readonly page: number;
|
|
133
|
+
/**
|
|
134
|
+
* The heading's text on one line.
|
|
135
|
+
*/
|
|
136
|
+
readonly text: string;
|
|
137
|
+
}
|
|
138
|
+
|
|
139
|
+
/**
|
|
140
|
+
* One drawn page: RGBA pixels with their width and height, and the warnings of the drawing.
|
|
141
|
+
*/
|
|
142
|
+
export class PageImage {
|
|
143
|
+
private constructor();
|
|
144
|
+
free(): void;
|
|
145
|
+
[Symbol.dispose](): void;
|
|
146
|
+
/**
|
|
147
|
+
* Returns the text of each distinct warning of the drawing, such as an image that does not
|
|
148
|
+
* decode, once each.
|
|
149
|
+
*/
|
|
150
|
+
warnings(): string[];
|
|
151
|
+
/**
|
|
152
|
+
* The pixels in gray, one byte each, row by row from the top left corner, as a comparison
|
|
153
|
+
* with a gray page image reads them: each pixel's luma, 0.299 red, 0.587 green and 0.114
|
|
154
|
+
* blue, rounded.
|
|
155
|
+
*/
|
|
156
|
+
readonly gray: Uint8Array;
|
|
157
|
+
/**
|
|
158
|
+
* Height in pixels.
|
|
159
|
+
*/
|
|
160
|
+
readonly height: number;
|
|
161
|
+
/**
|
|
162
|
+
* The pixels as RGBA bytes, row by row from the top left corner. Each read copies them
|
|
163
|
+
* once out of WebAssembly memory into a new array, which
|
|
164
|
+
* `new ImageData(pixels, width, height)` takes without another copy. Read it once, then
|
|
165
|
+
* call `free()`.
|
|
166
|
+
*/
|
|
167
|
+
readonly pixels: Uint8ClampedArray;
|
|
168
|
+
/**
|
|
169
|
+
* Width in pixels.
|
|
170
|
+
*/
|
|
171
|
+
readonly width: number;
|
|
172
|
+
}
|
|
173
|
+
|
|
174
|
+
/**
|
|
175
|
+
* Fonts for rendering. Add the fonts first, then open documents.
|
|
176
|
+
*/
|
|
177
|
+
export class Renderer {
|
|
178
|
+
free(): void;
|
|
179
|
+
[Symbol.dispose](): void;
|
|
180
|
+
/**
|
|
181
|
+
* Adds the pictures of the art page borders in a file of their form, and returns how many
|
|
182
|
+
* it added. Without them, a page border's side of an art style, such as `apples`, is not
|
|
183
|
+
* drawn, with a warning. A document that is already open keeps its layout.
|
|
184
|
+
*
|
|
185
|
+
* # Errors
|
|
186
|
+
*
|
|
187
|
+
* Throws when the data does not read as art pictures.
|
|
188
|
+
*/
|
|
189
|
+
addArtPictures(data: Uint8Array | number[]): number;
|
|
190
|
+
/**
|
|
191
|
+
* Adds every face in an OpenType font or font collection (`.ttf`, `.otf`, `.ttc` or
|
|
192
|
+
* `.otc`), and returns the number of faces that it added. A document that is already open
|
|
193
|
+
* keeps its layout.
|
|
194
|
+
*
|
|
195
|
+
* # Errors
|
|
196
|
+
*
|
|
197
|
+
* Throws when the data is not a font that can be loaded.
|
|
198
|
+
*/
|
|
199
|
+
addFont(data: Uint8Array | number[]): number;
|
|
200
|
+
/**
|
|
201
|
+
* Returns the fonts that a DOCX file asks for, reading lazily from a JavaScript random-access
|
|
202
|
+
* byte source (`readAt(offset, length) -> Uint8Array`) without copying the archive into WASM
|
|
203
|
+
* linear memory.
|
|
204
|
+
*
|
|
205
|
+
* # Errors
|
|
206
|
+
*
|
|
207
|
+
* Throws when `byteLength` is invalid, `target` is unknown, or the DOCX file cannot be read.
|
|
208
|
+
*/
|
|
209
|
+
static fontsNeededSource(byte_length: number, read_at: Function, target?: string | null): FontNeed[];
|
|
210
|
+
/**
|
|
211
|
+
* Returns the fonts that the text of a DOCX file asks for, for the target whose ID
|
|
212
|
+
* `target` gives or the base target, each with the families that the target tries for it.
|
|
213
|
+
* It needs no fonts: fetch the first family of each that you can, add it, then open the
|
|
214
|
+
* document.
|
|
215
|
+
*
|
|
216
|
+
* # Errors
|
|
217
|
+
*
|
|
218
|
+
* Throws when no target has the ID, or when the data is not a DOCX file that can be read.
|
|
219
|
+
*/
|
|
220
|
+
static fontsNeeded(docx: Uint8Array | number[], target?: string | null): FontNeed[];
|
|
221
|
+
/**
|
|
222
|
+
* Makes a renderer without fonts.
|
|
223
|
+
*/
|
|
224
|
+
constructor();
|
|
225
|
+
/**
|
|
226
|
+
* Lays out a DOCX file into pages using constrained mobile/browser resource limits
|
|
227
|
+
* (`f_office::Limits::mobile()`) so oversized or hostile files fail cleanly instead of
|
|
228
|
+
* exhausting tab memory.
|
|
229
|
+
*
|
|
230
|
+
* # Errors
|
|
231
|
+
*
|
|
232
|
+
* Throws when no target has the ID, `now` is malformed, or the DOCX file breaks mobile
|
|
233
|
+
* limits or cannot be read.
|
|
234
|
+
*/
|
|
235
|
+
openDocxMobile(docx: Uint8Array | number[], target?: string | null, now?: string | null): Document;
|
|
236
|
+
/**
|
|
237
|
+
* Lays out a DOCX file from a JavaScript random-access byte source (`readAt(offset, length)
|
|
238
|
+
* -> Uint8Array`) without copying the archive into WebAssembly linear memory.
|
|
239
|
+
*
|
|
240
|
+
* # Errors
|
|
241
|
+
*
|
|
242
|
+
* Throws when `byteLength` is invalid, `target`/`now` is invalid, or the DOCX file cannot be
|
|
243
|
+
* read.
|
|
244
|
+
*/
|
|
245
|
+
openDocxSource(byte_length: number, read_at: Function, target?: string | null, now?: string | null, mobile?: boolean | null): Document;
|
|
246
|
+
/**
|
|
247
|
+
* Lays out a DOCX file into pages with the fonts added so far, for the Word product whose
|
|
248
|
+
* pages to reproduce: the target whose ID `target` gives, or the base target without one.
|
|
249
|
+
* `now`, written as `YYYY-MM-DDTHH:MM:SSZ` with the digits of the local clock, is the date
|
|
250
|
+
* and time that date fields show; without it they show the results stored in the file.
|
|
251
|
+
*
|
|
252
|
+
* # Errors
|
|
253
|
+
*
|
|
254
|
+
* Throws when no target has the ID, `now` is not written in that form, or the data is not
|
|
255
|
+
* a DOCX file that can be read.
|
|
256
|
+
*/
|
|
257
|
+
openDocx(docx: Uint8Array | number[], target?: string | null, now?: string | null): Document;
|
|
258
|
+
/**
|
|
259
|
+
* Returns the IDs of the targets that `openDocx` and `fontsNeeded` accept.
|
|
260
|
+
*/
|
|
261
|
+
static targets(): string[];
|
|
262
|
+
}
|
|
263
|
+
|
|
264
|
+
/**
|
|
265
|
+
* A run of upright text on a page, in points from the page's top left corner: the box of its
|
|
266
|
+
* glyphs from its font's ascender to its descender, and its glyphs.
|
|
267
|
+
*/
|
|
268
|
+
export class TextRun {
|
|
269
|
+
private constructor();
|
|
270
|
+
free(): void;
|
|
271
|
+
[Symbol.dispose](): void;
|
|
272
|
+
/**
|
|
273
|
+
* The baseline.
|
|
274
|
+
*/
|
|
275
|
+
readonly baseline: number;
|
|
276
|
+
/**
|
|
277
|
+
* The end of each glyph's text in `text`, counted in UTF-16 code units as JavaScript
|
|
278
|
+
* counts a string's characters.
|
|
279
|
+
*/
|
|
280
|
+
readonly glyphEnds: Uint32Array;
|
|
281
|
+
/**
|
|
282
|
+
* The left edge of each glyph's cell, in the order of the text.
|
|
283
|
+
*/
|
|
284
|
+
readonly glyphLefts: Float64Array;
|
|
285
|
+
/**
|
|
286
|
+
* The advance of each glyph.
|
|
287
|
+
*/
|
|
288
|
+
readonly glyphWidths: Float64Array;
|
|
289
|
+
/**
|
|
290
|
+
* The height of the box.
|
|
291
|
+
*/
|
|
292
|
+
readonly height: number;
|
|
293
|
+
/**
|
|
294
|
+
* The left edge of the box.
|
|
295
|
+
*/
|
|
296
|
+
readonly left: number;
|
|
297
|
+
/**
|
|
298
|
+
* The font size.
|
|
299
|
+
*/
|
|
300
|
+
readonly size: number;
|
|
301
|
+
/**
|
|
302
|
+
* The text that the glyphs show.
|
|
303
|
+
*/
|
|
304
|
+
readonly text: string;
|
|
305
|
+
/**
|
|
306
|
+
* The top edge of the box.
|
|
307
|
+
*/
|
|
308
|
+
readonly top: number;
|
|
309
|
+
/**
|
|
310
|
+
* The width of the box.
|
|
311
|
+
*/
|
|
312
|
+
readonly width: number;
|
|
313
|
+
}
|
|
314
|
+
|
|
315
|
+
export type InitInput = RequestInfo | URL | Response | BufferSource | WebAssembly.Module;
|
|
316
|
+
|
|
317
|
+
export interface InitOutput {
|
|
318
|
+
readonly memory: WebAssembly.Memory;
|
|
319
|
+
readonly __wbg_document_free: (a: number, b: number) => void;
|
|
320
|
+
readonly __wbg_fontneed_free: (a: number, b: number) => void;
|
|
321
|
+
readonly __wbg_outlineentry_free: (a: number, b: number) => void;
|
|
322
|
+
readonly __wbg_pageimage_free: (a: number, b: number) => void;
|
|
323
|
+
readonly __wbg_renderer_free: (a: number, b: number) => void;
|
|
324
|
+
readonly __wbg_textrun_free: (a: number, b: number) => void;
|
|
325
|
+
readonly document_fontNeeds: (a: number) => [number, number];
|
|
326
|
+
readonly document_outline: (a: number) => [number, number];
|
|
327
|
+
readonly document_pageCount: (a: number) => number;
|
|
328
|
+
readonly document_pageHeight: (a: number, b: number, c: number) => [number, number, number];
|
|
329
|
+
readonly document_pageSizes: (a: number) => [number, number];
|
|
330
|
+
readonly document_pageWidth: (a: number, b: number, c: number) => [number, number, number];
|
|
331
|
+
readonly document_renderPage: (a: number, b: number, c: number) => [number, number, number];
|
|
332
|
+
readonly document_renderRegion: (a: number, b: number, c: number, d: number, e: number, f: number, g: number) => [number, number, number];
|
|
333
|
+
readonly document_textRuns: (a: number, b: number) => [number, number, number, number];
|
|
334
|
+
readonly document_warnings: (a: number) => [number, number];
|
|
335
|
+
readonly document_writePdf: (a: number) => [number, number, number, number];
|
|
336
|
+
readonly document_writePdfTo: (a: number, b: any) => [number, number, number, number];
|
|
337
|
+
readonly fontneed_family: (a: number) => [number, number];
|
|
338
|
+
readonly fontneed_tried: (a: number) => [number, number];
|
|
339
|
+
readonly outlineentry_address: (a: number) => [number, number];
|
|
340
|
+
readonly outlineentry_level: (a: number) => number;
|
|
341
|
+
readonly outlineentry_page: (a: number) => number;
|
|
342
|
+
readonly outlineentry_text: (a: number) => [number, number];
|
|
343
|
+
readonly pageimage_gray: (a: number) => [number, number];
|
|
344
|
+
readonly pageimage_height: (a: number) => number;
|
|
345
|
+
readonly pageimage_pixels: (a: number) => any;
|
|
346
|
+
readonly pageimage_warnings: (a: number) => [number, number];
|
|
347
|
+
readonly pageimage_width: (a: number) => number;
|
|
348
|
+
readonly renderer_addArtPictures: (a: number, b: number, c: number) => [number, number, number];
|
|
349
|
+
readonly renderer_addFont: (a: number, b: number, c: number) => [number, number, number];
|
|
350
|
+
readonly renderer_fontsNeeded: (a: number, b: number, c: number, d: number) => [number, number, number, number];
|
|
351
|
+
readonly renderer_fontsNeededSource: (a: number, b: any, c: number, d: number) => [number, number, number, number];
|
|
352
|
+
readonly renderer_new: () => number;
|
|
353
|
+
readonly renderer_openDocx: (a: number, b: number, c: number, d: number, e: number, f: number, g: number) => [number, number, number];
|
|
354
|
+
readonly renderer_openDocxMobile: (a: number, b: number, c: number, d: number, e: number, f: number, g: number) => [number, number, number];
|
|
355
|
+
readonly renderer_openDocxSource: (a: number, b: number, c: any, d: number, e: number, f: number, g: number, h: number) => [number, number, number];
|
|
356
|
+
readonly renderer_targets: () => [number, number];
|
|
357
|
+
readonly textrun_baseline: (a: number) => number;
|
|
358
|
+
readonly textrun_glyphEnds: (a: number) => [number, number];
|
|
359
|
+
readonly textrun_glyphLefts: (a: number) => [number, number];
|
|
360
|
+
readonly textrun_glyphWidths: (a: number) => [number, number];
|
|
361
|
+
readonly textrun_height: (a: number) => number;
|
|
362
|
+
readonly textrun_left: (a: number) => number;
|
|
363
|
+
readonly textrun_size: (a: number) => number;
|
|
364
|
+
readonly textrun_text: (a: number) => [number, number];
|
|
365
|
+
readonly textrun_top: (a: number) => number;
|
|
366
|
+
readonly textrun_width: (a: number) => number;
|
|
367
|
+
readonly __wbindgen_malloc: (a: number, b: number) => number;
|
|
368
|
+
readonly __wbindgen_realloc: (a: number, b: number, c: number, d: number) => number;
|
|
369
|
+
readonly __wbindgen_free: (a: number, b: number, c: number) => void;
|
|
370
|
+
readonly __wbindgen_exn_store: (a: number) => void;
|
|
371
|
+
readonly __externref_table_alloc: () => number;
|
|
372
|
+
readonly __wbindgen_externrefs: WebAssembly.Table;
|
|
373
|
+
readonly __externref_drop_slice: (a: number, b: number) => void;
|
|
374
|
+
readonly __externref_table_dealloc: (a: number) => void;
|
|
375
|
+
readonly __wbindgen_start: () => void;
|
|
376
|
+
}
|
|
377
|
+
|
|
378
|
+
export type SyncInitInput = BufferSource | WebAssembly.Module;
|
|
379
|
+
|
|
380
|
+
/**
|
|
381
|
+
* Instantiates the given `module`, which can either be bytes or
|
|
382
|
+
* a precompiled `WebAssembly.Module`.
|
|
383
|
+
*
|
|
384
|
+
* @param {{ module: SyncInitInput }} module - Passing `SyncInitInput` directly is deprecated.
|
|
385
|
+
*
|
|
386
|
+
* @returns {InitOutput}
|
|
387
|
+
*/
|
|
388
|
+
export function initSync(module: { module: SyncInitInput } | SyncInitInput): InitOutput;
|
|
389
|
+
|
|
390
|
+
/**
|
|
391
|
+
* If `module_or_path` is {RequestInfo} or {URL}, makes a request and
|
|
392
|
+
* for everything else, calls `WebAssembly.instantiate` directly.
|
|
393
|
+
*
|
|
394
|
+
* @param {{ module_or_path: InitInput | Promise<InitInput> }} module_or_path - Passing `InitInput` directly is deprecated.
|
|
395
|
+
*
|
|
396
|
+
* @returns {Promise<InitOutput>}
|
|
397
|
+
*/
|
|
398
|
+
export default function __wbg_init (module_or_path?: { module_or_path: InitInput | Promise<InitInput> } | InitInput | Promise<InitInput>): Promise<InitOutput>;
|