@f-office/core 0.2.0 → 0.2.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/README.md +16 -1
- package/dist/browser.d.ts +7 -0
- package/dist/browser.js +10 -0
- package/dist/core.d.ts +121 -0
- package/dist/core.js +374 -0
- package/dist/index.d.ts +1 -113
- package/dist/index.js +1 -342
- package/dist/node.d.ts +7 -0
- package/dist/node.js +14 -0
- package/dist/types.d.ts +42 -1
- package/dist/wasm/f_office_wasm.d.ts +55 -2
- package/dist/wasm/f_office_wasm.js +123 -2
- package/dist/wasm/f_office_wasm_bg.wasm +0 -0
- package/dist/wasm/f_office_wasm_bg.wasm.d.ts +9 -0
- package/dist/worker.d.ts +3 -1
- package/dist/worker.js +8 -1
- package/package.json +7 -3
package/dist/index.js
CHANGED
|
@@ -1,342 +1 @@
|
|
|
1
|
-
|
|
2
|
-
export { createBlobSource, createMemorySource, createOpfsSource, } from "./source.js";
|
|
3
|
-
const DEFAULT_TARGET = "word-win";
|
|
4
|
-
let initPromise = null;
|
|
5
|
-
let wasmMemory = null;
|
|
6
|
-
function isNodeRuntime() {
|
|
7
|
-
return (typeof process !== "undefined" &&
|
|
8
|
-
typeof process.versions === "object" &&
|
|
9
|
-
typeof process.versions.node === "string");
|
|
10
|
-
}
|
|
11
|
-
/**
|
|
12
|
-
* Returns the current byte length of the WebAssembly linear memory buffer, or `0` before
|
|
13
|
-
* `init()` completes. Useful for monitoring peak memory on mobile browsers.
|
|
14
|
-
*/
|
|
15
|
-
export function wasmMemoryBytes() {
|
|
16
|
-
return wasmMemory ? wasmMemory.buffer.byteLength : 0;
|
|
17
|
-
}
|
|
18
|
-
/**
|
|
19
|
-
* Initializes the F-Office WebAssembly module. Safe to call multiple times;
|
|
20
|
-
* subsequent calls resolve immediately once initialized.
|
|
21
|
-
*/
|
|
22
|
-
export function init(source) {
|
|
23
|
-
if (initPromise !== null && source === undefined) {
|
|
24
|
-
return initPromise;
|
|
25
|
-
}
|
|
26
|
-
const pending = (async () => {
|
|
27
|
-
if (source !== undefined) {
|
|
28
|
-
const output = await wasmInit({ module_or_path: source });
|
|
29
|
-
wasmMemory = output.memory;
|
|
30
|
-
return;
|
|
31
|
-
}
|
|
32
|
-
const wasmUrl = new URL("./wasm/f_office_wasm_bg.wasm", import.meta.url);
|
|
33
|
-
if (isNodeRuntime()) {
|
|
34
|
-
const { readFile } = await import("node:fs/promises");
|
|
35
|
-
const bytes = await readFile(wasmUrl);
|
|
36
|
-
const output = initSync({ module: bytes });
|
|
37
|
-
wasmMemory = output.memory;
|
|
38
|
-
return;
|
|
39
|
-
}
|
|
40
|
-
const output = await wasmInit({ module_or_path: wasmUrl });
|
|
41
|
-
wasmMemory = output.memory;
|
|
42
|
-
})();
|
|
43
|
-
if (source === undefined) {
|
|
44
|
-
initPromise = pending;
|
|
45
|
-
}
|
|
46
|
-
return pending;
|
|
47
|
-
}
|
|
48
|
-
function unwrapFontNeeds(raw) {
|
|
49
|
-
const out = [];
|
|
50
|
-
for (const item of raw) {
|
|
51
|
-
try {
|
|
52
|
-
out.push({
|
|
53
|
-
family: item.family ?? null,
|
|
54
|
-
tried: item.tried,
|
|
55
|
-
});
|
|
56
|
-
}
|
|
57
|
-
finally {
|
|
58
|
-
item.free();
|
|
59
|
-
}
|
|
60
|
-
}
|
|
61
|
-
return out;
|
|
62
|
-
}
|
|
63
|
-
function unwrapOutline(raw) {
|
|
64
|
-
const out = [];
|
|
65
|
-
for (const item of raw) {
|
|
66
|
-
try {
|
|
67
|
-
out.push({
|
|
68
|
-
level: item.level,
|
|
69
|
-
text: item.text,
|
|
70
|
-
page: item.page,
|
|
71
|
-
address: item.address,
|
|
72
|
-
});
|
|
73
|
-
}
|
|
74
|
-
finally {
|
|
75
|
-
item.free();
|
|
76
|
-
}
|
|
77
|
-
}
|
|
78
|
-
return out;
|
|
79
|
-
}
|
|
80
|
-
function unwrapTextRuns(raw) {
|
|
81
|
-
const out = [];
|
|
82
|
-
for (const item of raw) {
|
|
83
|
-
try {
|
|
84
|
-
out.push({
|
|
85
|
-
text: item.text,
|
|
86
|
-
size: item.size,
|
|
87
|
-
left: item.left,
|
|
88
|
-
top: item.top,
|
|
89
|
-
width: item.width,
|
|
90
|
-
height: item.height,
|
|
91
|
-
baseline: item.baseline,
|
|
92
|
-
glyphLefts: item.glyphLefts,
|
|
93
|
-
glyphWidths: item.glyphWidths,
|
|
94
|
-
glyphEnds: item.glyphEnds,
|
|
95
|
-
});
|
|
96
|
-
}
|
|
97
|
-
finally {
|
|
98
|
-
item.free();
|
|
99
|
-
}
|
|
100
|
-
}
|
|
101
|
-
return out;
|
|
102
|
-
}
|
|
103
|
-
/** A rendered page image (RGBA bytes, dimensions, and drawing warnings). */
|
|
104
|
-
export class PageImage {
|
|
105
|
-
#raw;
|
|
106
|
-
#cachedPixels = null;
|
|
107
|
-
constructor(raw) {
|
|
108
|
-
this.#raw = raw;
|
|
109
|
-
}
|
|
110
|
-
/** Width in pixels. */
|
|
111
|
-
get width() {
|
|
112
|
-
return this.#raw.width;
|
|
113
|
-
}
|
|
114
|
-
/** Height in pixels. */
|
|
115
|
-
get height() {
|
|
116
|
-
return this.#raw.height;
|
|
117
|
-
}
|
|
118
|
-
/** Distinct warnings produced while drawing this page. */
|
|
119
|
-
warnings() {
|
|
120
|
-
return this.#raw.warnings();
|
|
121
|
-
}
|
|
122
|
-
/**
|
|
123
|
-
* RGBA pixels copied out of WebAssembly memory, cached on first read so repeated
|
|
124
|
-
* accesses do not copy the buffer again.
|
|
125
|
-
*/
|
|
126
|
-
get pixels() {
|
|
127
|
-
let cached = this.#cachedPixels;
|
|
128
|
-
if (cached === null) {
|
|
129
|
-
cached = this.#raw.pixels;
|
|
130
|
-
this.#cachedPixels = cached;
|
|
131
|
-
}
|
|
132
|
-
return cached;
|
|
133
|
-
}
|
|
134
|
-
/** Builds a browser `ImageData` backed by this page's RGBA pixels. */
|
|
135
|
-
toImageData() {
|
|
136
|
-
const data = new Uint8ClampedArray(this.pixels);
|
|
137
|
-
return new ImageData(data, this.width, this.height);
|
|
138
|
-
}
|
|
139
|
-
/** Releases WebAssembly memory held by this page image. */
|
|
140
|
-
free() {
|
|
141
|
-
this.#raw.free();
|
|
142
|
-
}
|
|
143
|
-
[Symbol.dispose]() {
|
|
144
|
-
this.free();
|
|
145
|
-
}
|
|
146
|
-
}
|
|
147
|
-
/** A laid-out DOCX document. Page indices are zero-based. */
|
|
148
|
-
export class Document {
|
|
149
|
-
#raw;
|
|
150
|
-
constructor(raw) {
|
|
151
|
-
this.#raw = raw;
|
|
152
|
-
}
|
|
153
|
-
/** Distinct layout warnings (such as substituted fonts or missing pictures). */
|
|
154
|
-
warnings() {
|
|
155
|
-
return this.#raw.warnings();
|
|
156
|
-
}
|
|
157
|
-
/**
|
|
158
|
-
* Fonts looked up during layout that were missing from the renderer, including
|
|
159
|
-
* glyph-fallback families discovered after primary fonts were loaded.
|
|
160
|
-
*/
|
|
161
|
-
fontNeeds() {
|
|
162
|
-
return unwrapFontNeeds(this.#raw.fontNeeds());
|
|
163
|
-
}
|
|
164
|
-
/** Number of laid-out pages. */
|
|
165
|
-
pageCount() {
|
|
166
|
-
return this.#raw.pageCount();
|
|
167
|
-
}
|
|
168
|
-
/** Width in pixels of page `index` when rendered at `dpi`. */
|
|
169
|
-
pageWidth(index, dpi) {
|
|
170
|
-
return this.#raw.pageWidth(index, dpi);
|
|
171
|
-
}
|
|
172
|
-
/** Height in pixels of page `index` when rendered at `dpi`. */
|
|
173
|
-
pageHeight(index, dpi) {
|
|
174
|
-
return this.#raw.pageHeight(index, dpi);
|
|
175
|
-
}
|
|
176
|
-
/** Width and height in points of every page in order. */
|
|
177
|
-
pageSizes() {
|
|
178
|
-
const flat = this.#raw.pageSizes();
|
|
179
|
-
const out = [];
|
|
180
|
-
for (let i = 0; i + 1 < flat.length; i += 2) {
|
|
181
|
-
out.push({ width: flat[i], height: flat[i + 1] });
|
|
182
|
-
}
|
|
183
|
-
return out;
|
|
184
|
-
}
|
|
185
|
-
/** Upright text runs of page `index` in painting order. */
|
|
186
|
-
textRuns(index) {
|
|
187
|
-
return unwrapTextRuns(this.#raw.textRuns(index));
|
|
188
|
-
}
|
|
189
|
-
/** Document headings in reading order. */
|
|
190
|
-
outline() {
|
|
191
|
-
return unwrapOutline(this.#raw.outline());
|
|
192
|
-
}
|
|
193
|
-
/** Renders page `index` at `dpi` pixels per inch on a white background. */
|
|
194
|
-
renderPage(index, dpi) {
|
|
195
|
-
return new PageImage(this.#raw.renderPage(index, dpi));
|
|
196
|
-
}
|
|
197
|
-
/**
|
|
198
|
-
* Renders only the rectangular pixel tile `region` of page `index` at `dpi` pixels per inch.
|
|
199
|
-
* Ideal for mobile viewports and high-zoom viewing with constant memory.
|
|
200
|
-
*/
|
|
201
|
-
renderRegion(index, region, dpi) {
|
|
202
|
-
return new PageImage(this.#raw.renderRegion(index, region.x, region.y, region.width, region.height, dpi));
|
|
203
|
-
}
|
|
204
|
-
/** Writes all pages to a PDF file with fonts subset and embedded. */
|
|
205
|
-
writePdf() {
|
|
206
|
-
return this.#raw.writePdf();
|
|
207
|
-
}
|
|
208
|
-
/**
|
|
209
|
-
* Streams all pages as PDF 1.7 chunks into `onChunk` without allocating the full PDF in
|
|
210
|
-
* WebAssembly linear memory. Returns distinct PDF warnings.
|
|
211
|
-
*/
|
|
212
|
-
writePdfTo(onChunk) {
|
|
213
|
-
return this.#raw.writePdfTo(onChunk);
|
|
214
|
-
}
|
|
215
|
-
/** Releases WebAssembly memory held by this document. */
|
|
216
|
-
free() {
|
|
217
|
-
this.#raw.free();
|
|
218
|
-
}
|
|
219
|
-
[Symbol.dispose]() {
|
|
220
|
-
this.free();
|
|
221
|
-
}
|
|
222
|
-
}
|
|
223
|
-
/** Holds loaded fonts and opens DOCX documents into laid-out pages. */
|
|
224
|
-
export class Renderer {
|
|
225
|
-
#raw;
|
|
226
|
-
constructor() {
|
|
227
|
-
this.#raw = new RawRenderer();
|
|
228
|
-
}
|
|
229
|
-
/** Returns the supported Word target IDs. */
|
|
230
|
-
static targets() {
|
|
231
|
-
return RawRenderer.targets();
|
|
232
|
-
}
|
|
233
|
-
/**
|
|
234
|
-
* Lists fonts requested by a DOCX file before any font is added.
|
|
235
|
-
* Defaults to `"word-win"`.
|
|
236
|
-
*/
|
|
237
|
-
static fontsNeeded(docx, target = DEFAULT_TARGET) {
|
|
238
|
-
return unwrapFontNeeds(RawRenderer.fontsNeeded(docx, target));
|
|
239
|
-
}
|
|
240
|
-
/**
|
|
241
|
-
* Lists fonts requested by a DOCX file read lazily from a random-access `ByteSource` without
|
|
242
|
-
* copying the archive into WebAssembly linear memory.
|
|
243
|
-
*/
|
|
244
|
-
static fontsNeededSource(source, target = DEFAULT_TARGET) {
|
|
245
|
-
return unwrapFontNeeds(RawRenderer.fontsNeededSource(source.byteLength, (offset, length) => source.readAt(offset, length), target));
|
|
246
|
-
}
|
|
247
|
-
/** Adds all faces from an OpenType font or collection (`.ttf`, `.otf`, `.ttc`, `.otc`). */
|
|
248
|
-
addFont(data) {
|
|
249
|
-
return this.#raw.addFont(data);
|
|
250
|
-
}
|
|
251
|
-
/** Adds art page border pictures. */
|
|
252
|
-
addArtPictures(data) {
|
|
253
|
-
return this.#raw.addArtPictures(data);
|
|
254
|
-
}
|
|
255
|
-
/** Lays out a DOCX file with the fonts currently added to this renderer. */
|
|
256
|
-
openDocx(docx, options) {
|
|
257
|
-
const target = options?.target ?? DEFAULT_TARGET;
|
|
258
|
-
const now = options?.now;
|
|
259
|
-
const raw = options?.limits === "mobile"
|
|
260
|
-
? this.#raw.openDocxMobile(docx, target, now)
|
|
261
|
-
: this.#raw.openDocx(docx, target, now);
|
|
262
|
-
return new Document(raw);
|
|
263
|
-
}
|
|
264
|
-
/**
|
|
265
|
-
* Lays out a DOCX file read lazily from a random-access `ByteSource` (such as
|
|
266
|
-
* `createBlobSource(file)` or `createOpfsSource(handle)` inside a Web Worker) without copying
|
|
267
|
-
* the full archive into WebAssembly linear memory.
|
|
268
|
-
*/
|
|
269
|
-
openDocxSource(source, options) {
|
|
270
|
-
const target = options?.target ?? DEFAULT_TARGET;
|
|
271
|
-
const now = options?.now;
|
|
272
|
-
const mobile = options?.limits === "mobile";
|
|
273
|
-
const raw = this.#raw.openDocxSource(source.byteLength, (offset, length) => source.readAt(offset, length), target, now, mobile);
|
|
274
|
-
return new Document(raw);
|
|
275
|
-
}
|
|
276
|
-
/** Releases WebAssembly memory held by this renderer. */
|
|
277
|
-
free() {
|
|
278
|
-
this.#raw.free();
|
|
279
|
-
}
|
|
280
|
-
[Symbol.dispose]() {
|
|
281
|
-
this.free();
|
|
282
|
-
}
|
|
283
|
-
}
|
|
284
|
-
/**
|
|
285
|
-
* Discovers the fonts requested by `docx` (including glyph-fallback families),
|
|
286
|
-
* fetches each missing family once via `fetchFont`, and registers them on `renderer`.
|
|
287
|
-
*/
|
|
288
|
-
export async function loadFontsFor(renderer, docx, fetchFont, options) {
|
|
289
|
-
const target = options?.target ?? DEFAULT_TARGET;
|
|
290
|
-
const attempted = new Set();
|
|
291
|
-
const added = [];
|
|
292
|
-
const fetchNeeds = async (needs) => {
|
|
293
|
-
let addedHere = 0;
|
|
294
|
-
for (const need of needs) {
|
|
295
|
-
for (const family of need.tried) {
|
|
296
|
-
const key = family.toLowerCase();
|
|
297
|
-
if (attempted.has(key)) {
|
|
298
|
-
continue;
|
|
299
|
-
}
|
|
300
|
-
attempted.add(key);
|
|
301
|
-
const result = await fetchFont(family);
|
|
302
|
-
if (!result) {
|
|
303
|
-
continue;
|
|
304
|
-
}
|
|
305
|
-
const files = Array.isArray(result) ? result : [result];
|
|
306
|
-
let loaded = false;
|
|
307
|
-
for (const bytes of files) {
|
|
308
|
-
if (bytes.byteLength > 0) {
|
|
309
|
-
renderer.addFont(bytes);
|
|
310
|
-
loaded = true;
|
|
311
|
-
}
|
|
312
|
-
}
|
|
313
|
-
if (loaded) {
|
|
314
|
-
added.push(family);
|
|
315
|
-
addedHere += 1;
|
|
316
|
-
break;
|
|
317
|
-
}
|
|
318
|
-
}
|
|
319
|
-
}
|
|
320
|
-
return addedHere;
|
|
321
|
-
};
|
|
322
|
-
await fetchNeeds(Renderer.fontsNeeded(docx, target));
|
|
323
|
-
// Second pass catches fallback fonts requested for glyphs absent from the primary fonts.
|
|
324
|
-
for (let pass = 0; pass < 3; pass += 1) {
|
|
325
|
-
const doc = renderer.openDocx(docx, options);
|
|
326
|
-
let remaining;
|
|
327
|
-
try {
|
|
328
|
-
remaining = doc.fontNeeds();
|
|
329
|
-
}
|
|
330
|
-
finally {
|
|
331
|
-
doc.free();
|
|
332
|
-
}
|
|
333
|
-
if (remaining.length === 0) {
|
|
334
|
-
break;
|
|
335
|
-
}
|
|
336
|
-
const newlyAdded = await fetchNeeds(remaining);
|
|
337
|
-
if (newlyAdded === 0) {
|
|
338
|
-
break;
|
|
339
|
-
}
|
|
340
|
-
}
|
|
341
|
-
return added;
|
|
342
|
-
}
|
|
1
|
+
export { createBlobSource, createMemorySource, createOpfsSource, Document, init, loadFontsFor, PageImage, Renderer, wasmMemoryBytes, } from "./browser.js";
|
package/dist/node.d.ts
ADDED
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
import type { WasmInitSource } from "./types.js";
|
|
2
|
+
export { createBlobSource, createMemorySource, createOpfsSource, Document, loadFontsFor, PageImage, Renderer, wasmMemoryBytes, type ByteSource, type FontFetcher, type FontNeed, type LimitProfile, type OpenOptions, type OpfsSyncAccessHandle, type OutlineEntry, type PageRect, type PageSizePoints, type PdfChunkCallback, type PixelRegion, type RenderedPageData, type SearchMatch, type SearchOptions, type SearchRange, type TargetId, type TextRun, type WasmInitSource, } from "./core.js";
|
|
3
|
+
/**
|
|
4
|
+
* Initializes the F-Office WebAssembly module in Node.js by reading the bundled `.wasm` binary
|
|
5
|
+
* directly from disk when `source` is omitted.
|
|
6
|
+
*/
|
|
7
|
+
export declare function init(source?: WasmInitSource): Promise<void>;
|
package/dist/node.js
ADDED
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
import { readFile } from "node:fs/promises";
|
|
2
|
+
import { initSync } from "./wasm/f_office_wasm.js";
|
|
3
|
+
import { initWithDefaultLoader } from "./core.js";
|
|
4
|
+
export { createBlobSource, createMemorySource, createOpfsSource, Document, loadFontsFor, PageImage, Renderer, wasmMemoryBytes, } from "./core.js";
|
|
5
|
+
/**
|
|
6
|
+
* Initializes the F-Office WebAssembly module in Node.js by reading the bundled `.wasm` binary
|
|
7
|
+
* directly from disk when `source` is omitted.
|
|
8
|
+
*/
|
|
9
|
+
export function init(source) {
|
|
10
|
+
return initWithDefaultLoader(async (wasmUrl) => {
|
|
11
|
+
const bytes = await readFile(wasmUrl);
|
|
12
|
+
return initSync({ module: bytes });
|
|
13
|
+
}, source);
|
|
14
|
+
}
|
package/dist/types.d.ts
CHANGED
|
@@ -66,7 +66,48 @@ export interface TextRun {
|
|
|
66
66
|
glyphWidths: Float64Array;
|
|
67
67
|
glyphEnds: Uint32Array;
|
|
68
68
|
}
|
|
69
|
-
/**
|
|
69
|
+
/** An axis-aligned rectangle on a page in typographic points (1/72 inch) from top-left. */
|
|
70
|
+
export interface PageRect {
|
|
71
|
+
left: number;
|
|
72
|
+
top: number;
|
|
73
|
+
width: number;
|
|
74
|
+
height: number;
|
|
75
|
+
}
|
|
76
|
+
/** Options for whole-document text search over the compact text map. */
|
|
77
|
+
export interface SearchOptions {
|
|
78
|
+
/** Match exact character case when `true`. Defaults to `false`. */
|
|
79
|
+
caseSensitive?: boolean;
|
|
80
|
+
/** Require word boundaries around each match when `true`. Defaults to `false`. */
|
|
81
|
+
wholeWord?: boolean;
|
|
82
|
+
/** Optional cap on the number of returned matches. */
|
|
83
|
+
maxResults?: number;
|
|
84
|
+
}
|
|
85
|
+
/** Logical UTF-16 character range of a search match within its paragraph. */
|
|
86
|
+
export interface SearchRange {
|
|
87
|
+
/** Zero-based paragraph index within the matched story. */
|
|
88
|
+
paragraph: number;
|
|
89
|
+
/** Start offset in UTF-16 code units within the paragraph text. */
|
|
90
|
+
start: number;
|
|
91
|
+
/** Exclusive end offset in UTF-16 code units within the paragraph text. */
|
|
92
|
+
end: number;
|
|
93
|
+
/** Stable paragraph address when present (for example `"p12"`). */
|
|
94
|
+
address?: string;
|
|
95
|
+
}
|
|
96
|
+
/** One search match returned by `Document.search()` / `WorkerRendererClient.search()`. */
|
|
97
|
+
export interface SearchMatch {
|
|
98
|
+
/** Zero-based page index where the match starts. */
|
|
99
|
+
page: number;
|
|
100
|
+
/** Highlight rectangles on `page` in typographic points (1/72 inch). */
|
|
101
|
+
rects: PageRect[];
|
|
102
|
+
/** Paragraph index, UTF-16 offsets, and optional stable address. */
|
|
103
|
+
range: SearchRange;
|
|
104
|
+
/** Short surrounding context excerpt from the matched paragraph. */
|
|
105
|
+
snippet: string;
|
|
106
|
+
}
|
|
107
|
+
/**
|
|
108
|
+
* Async callback that fetches font file bytes (`.ttf`, `.otf`, `.ttc`, `.otc`, or full-table
|
|
109
|
+
* `.woff2`) for a family.
|
|
110
|
+
*/
|
|
70
111
|
export type FontFetcher = (family: string) => Promise<Uint8Array[] | Uint8Array | null | undefined>;
|
|
71
112
|
/** Optional source override passed to `init()`. */
|
|
72
113
|
export type WasmInitSource = URL | string | Request | Response | BufferSource | WebAssembly.Module;
|
|
@@ -61,6 +61,11 @@ export class Document {
|
|
|
61
61
|
* Throws when the page does not exist or the tile cannot be drawn at this resolution.
|
|
62
62
|
*/
|
|
63
63
|
renderRegion(index: number, x: number, y: number, width: number, height: number, dpi: number): PageImage;
|
|
64
|
+
/**
|
|
65
|
+
* Searches all laid-out stories of the document for `query` over the compact text map
|
|
66
|
+
* without rasterizing offscreen pages.
|
|
67
|
+
*/
|
|
68
|
+
search(query: string, case_sensitive?: boolean | null, whole_word?: boolean | null, max_results?: number | null): SearchMatch[];
|
|
64
69
|
/**
|
|
65
70
|
* Returns the upright text runs of one page in painting order, for a text layer.
|
|
66
71
|
*
|
|
@@ -188,8 +193,10 @@ export class Renderer {
|
|
|
188
193
|
*/
|
|
189
194
|
addArtPictures(data: Uint8Array | number[]): number;
|
|
190
195
|
/**
|
|
191
|
-
* Adds every face in an OpenType font or font collection (`.ttf`, `.otf`, `.ttc`
|
|
192
|
-
*
|
|
196
|
+
* Adds every face in an OpenType font or font collection (`.ttf`, `.otf`, `.ttc`, `.otc`)
|
|
197
|
+
* or WOFF2 webfont (`.woff2` when built with the `woff2` feature), and returns the number
|
|
198
|
+
* of faces that it added. Full-table WOFF2 preserves exact layout metrics, while
|
|
199
|
+
* web-subsetted WOFF2 may omit glyphs or OpenType tables. A document that is already open
|
|
193
200
|
* keeps its layout.
|
|
194
201
|
*
|
|
195
202
|
* # Errors
|
|
@@ -261,6 +268,43 @@ export class Renderer {
|
|
|
261
268
|
static targets(): string[];
|
|
262
269
|
}
|
|
263
270
|
|
|
271
|
+
/**
|
|
272
|
+
* One search match returned by `Document.search`.
|
|
273
|
+
*/
|
|
274
|
+
export class SearchMatch {
|
|
275
|
+
private constructor();
|
|
276
|
+
free(): void;
|
|
277
|
+
[Symbol.dispose](): void;
|
|
278
|
+
/**
|
|
279
|
+
* Stable paragraph address when present (for example `"p12"`).
|
|
280
|
+
*/
|
|
281
|
+
readonly address: string | undefined;
|
|
282
|
+
/**
|
|
283
|
+
* Exclusive end offset in UTF-16 code units within the matched paragraph.
|
|
284
|
+
*/
|
|
285
|
+
readonly end: number;
|
|
286
|
+
/**
|
|
287
|
+
* Zero-based page index where the match starts.
|
|
288
|
+
*/
|
|
289
|
+
readonly page: number;
|
|
290
|
+
/**
|
|
291
|
+
* Zero-based paragraph index in the matched story.
|
|
292
|
+
*/
|
|
293
|
+
readonly paragraph: number;
|
|
294
|
+
/**
|
|
295
|
+
* Flat array of highlight rectangles in points on `page`: `[left, top, width, height, ...]`.
|
|
296
|
+
*/
|
|
297
|
+
readonly rects: Float64Array;
|
|
298
|
+
/**
|
|
299
|
+
* Surrounding context excerpt from the matched paragraph.
|
|
300
|
+
*/
|
|
301
|
+
readonly snippet: string;
|
|
302
|
+
/**
|
|
303
|
+
* Start offset in UTF-16 code units within the matched paragraph.
|
|
304
|
+
*/
|
|
305
|
+
readonly start: number;
|
|
306
|
+
}
|
|
307
|
+
|
|
264
308
|
/**
|
|
265
309
|
* A run of upright text on a page, in points from the page's top left corner: the box of its
|
|
266
310
|
* glyphs from its font's ascender to its descender, and its glyphs.
|
|
@@ -321,6 +365,7 @@ export interface InitOutput {
|
|
|
321
365
|
readonly __wbg_outlineentry_free: (a: number, b: number) => void;
|
|
322
366
|
readonly __wbg_pageimage_free: (a: number, b: number) => void;
|
|
323
367
|
readonly __wbg_renderer_free: (a: number, b: number) => void;
|
|
368
|
+
readonly __wbg_searchmatch_free: (a: number, b: number) => void;
|
|
324
369
|
readonly __wbg_textrun_free: (a: number, b: number) => void;
|
|
325
370
|
readonly document_fontNeeds: (a: number) => [number, number];
|
|
326
371
|
readonly document_outline: (a: number) => [number, number];
|
|
@@ -330,6 +375,7 @@ export interface InitOutput {
|
|
|
330
375
|
readonly document_pageWidth: (a: number, b: number, c: number) => [number, number, number];
|
|
331
376
|
readonly document_renderPage: (a: number, b: number, c: number) => [number, number, number];
|
|
332
377
|
readonly document_renderRegion: (a: number, b: number, c: number, d: number, e: number, f: number, g: number) => [number, number, number];
|
|
378
|
+
readonly document_search: (a: number, b: number, c: number, d: number, e: number, f: number) => [number, number];
|
|
333
379
|
readonly document_textRuns: (a: number, b: number) => [number, number, number, number];
|
|
334
380
|
readonly document_warnings: (a: number) => [number, number];
|
|
335
381
|
readonly document_writePdf: (a: number) => [number, number, number, number];
|
|
@@ -354,6 +400,13 @@ export interface InitOutput {
|
|
|
354
400
|
readonly renderer_openDocxMobile: (a: number, b: number, c: number, d: number, e: number, f: number, g: number) => [number, number, number];
|
|
355
401
|
readonly renderer_openDocxSource: (a: number, b: number, c: any, d: number, e: number, f: number, g: number, h: number) => [number, number, number];
|
|
356
402
|
readonly renderer_targets: () => [number, number];
|
|
403
|
+
readonly searchmatch_address: (a: number) => [number, number];
|
|
404
|
+
readonly searchmatch_end: (a: number) => number;
|
|
405
|
+
readonly searchmatch_page: (a: number) => number;
|
|
406
|
+
readonly searchmatch_paragraph: (a: number) => number;
|
|
407
|
+
readonly searchmatch_rects: (a: number) => [number, number];
|
|
408
|
+
readonly searchmatch_snippet: (a: number) => [number, number];
|
|
409
|
+
readonly searchmatch_start: (a: number) => number;
|
|
357
410
|
readonly textrun_baseline: (a: number) => number;
|
|
358
411
|
readonly textrun_glyphEnds: (a: number) => [number, number];
|
|
359
412
|
readonly textrun_glyphLefts: (a: number) => [number, number];
|
|
@@ -135,6 +135,24 @@ export class Document {
|
|
|
135
135
|
}
|
|
136
136
|
return PageImage.__wrap(ret[0]);
|
|
137
137
|
}
|
|
138
|
+
/**
|
|
139
|
+
* Searches all laid-out stories of the document for `query` over the compact text map
|
|
140
|
+
* without rasterizing offscreen pages.
|
|
141
|
+
* @param {string} query
|
|
142
|
+
* @param {boolean | null} [case_sensitive]
|
|
143
|
+
* @param {boolean | null} [whole_word]
|
|
144
|
+
* @param {number | null} [max_results]
|
|
145
|
+
* @returns {SearchMatch[]}
|
|
146
|
+
*/
|
|
147
|
+
search(query, case_sensitive, whole_word, max_results) {
|
|
148
|
+
const val2 = +(isLikeNone(max_results) ? Number.MAX_SAFE_INTEGER : (max_results) >>> 0);
|
|
149
|
+
const ptr0 = passStringToWasm0(query, wasm.__wbindgen_malloc, wasm.__wbindgen_realloc);
|
|
150
|
+
const len0 = WASM_VECTOR_LEN;
|
|
151
|
+
const ret = wasm.document_search(this.__wbg_ptr, ptr0, len0, isLikeNone(case_sensitive) ? 0xFFFFFF : case_sensitive ? 1 : 0, isLikeNone(whole_word) ? 0xFFFFFF : whole_word ? 1 : 0, val2);
|
|
152
|
+
var v3 = getArrayJsValueFromWasm0(ret[0], ret[1]);
|
|
153
|
+
wasm.__wbindgen_free(ret[0], ret[1] * 4, 4);
|
|
154
|
+
return v3;
|
|
155
|
+
}
|
|
138
156
|
/**
|
|
139
157
|
* Returns the upright text runs of one page in painting order, for a text layer.
|
|
140
158
|
*
|
|
@@ -429,8 +447,10 @@ export class Renderer {
|
|
|
429
447
|
return ret[0] >>> 0;
|
|
430
448
|
}
|
|
431
449
|
/**
|
|
432
|
-
* Adds every face in an OpenType font or font collection (`.ttf`, `.otf`, `.ttc`
|
|
433
|
-
*
|
|
450
|
+
* Adds every face in an OpenType font or font collection (`.ttf`, `.otf`, `.ttc`, `.otc`)
|
|
451
|
+
* or WOFF2 webfont (`.woff2` when built with the `woff2` feature), and returns the number
|
|
452
|
+
* of faces that it added. Full-table WOFF2 preserves exact layout metrics, while
|
|
453
|
+
* web-subsetted WOFF2 may omit glyphs or OpenType tables. A document that is already open
|
|
434
454
|
* keeps its layout.
|
|
435
455
|
*
|
|
436
456
|
* # Errors
|
|
@@ -633,6 +653,100 @@ export class Renderer {
|
|
|
633
653
|
}
|
|
634
654
|
if (Symbol.dispose) Renderer.prototype[Symbol.dispose] = Renderer.prototype.free;
|
|
635
655
|
|
|
656
|
+
/**
|
|
657
|
+
* One search match returned by `Document.search`.
|
|
658
|
+
*/
|
|
659
|
+
export class SearchMatch {
|
|
660
|
+
static __wrap(ptr) {
|
|
661
|
+
const obj = Object.create(SearchMatch.prototype);
|
|
662
|
+
obj.__wbg_ptr = ptr;
|
|
663
|
+
SearchMatchFinalization.register(obj, obj.__wbg_ptr, obj);
|
|
664
|
+
return obj;
|
|
665
|
+
}
|
|
666
|
+
__destroy_into_raw() {
|
|
667
|
+
const ptr = this.__wbg_ptr;
|
|
668
|
+
this.__wbg_ptr = 0;
|
|
669
|
+
SearchMatchFinalization.unregister(this);
|
|
670
|
+
return ptr;
|
|
671
|
+
}
|
|
672
|
+
free() {
|
|
673
|
+
const ptr = this.__destroy_into_raw();
|
|
674
|
+
wasm.__wbg_searchmatch_free(ptr, 0);
|
|
675
|
+
}
|
|
676
|
+
/**
|
|
677
|
+
* Stable paragraph address when present (for example `"p12"`).
|
|
678
|
+
* @returns {string | undefined}
|
|
679
|
+
*/
|
|
680
|
+
get address() {
|
|
681
|
+
const ret = wasm.searchmatch_address(this.__wbg_ptr);
|
|
682
|
+
let v1;
|
|
683
|
+
if (ret[0] !== 0) {
|
|
684
|
+
v1 = getStringFromWasm0(ret[0], ret[1]);
|
|
685
|
+
wasm.__wbindgen_free(ret[0], ret[1] * 1, 1);
|
|
686
|
+
}
|
|
687
|
+
return v1;
|
|
688
|
+
}
|
|
689
|
+
/**
|
|
690
|
+
* Exclusive end offset in UTF-16 code units within the matched paragraph.
|
|
691
|
+
* @returns {number}
|
|
692
|
+
*/
|
|
693
|
+
get end() {
|
|
694
|
+
const ret = wasm.searchmatch_end(this.__wbg_ptr);
|
|
695
|
+
return ret >>> 0;
|
|
696
|
+
}
|
|
697
|
+
/**
|
|
698
|
+
* Zero-based page index where the match starts.
|
|
699
|
+
* @returns {number}
|
|
700
|
+
*/
|
|
701
|
+
get page() {
|
|
702
|
+
const ret = wasm.searchmatch_page(this.__wbg_ptr);
|
|
703
|
+
return ret >>> 0;
|
|
704
|
+
}
|
|
705
|
+
/**
|
|
706
|
+
* Zero-based paragraph index in the matched story.
|
|
707
|
+
* @returns {number}
|
|
708
|
+
*/
|
|
709
|
+
get paragraph() {
|
|
710
|
+
const ret = wasm.searchmatch_paragraph(this.__wbg_ptr);
|
|
711
|
+
return ret >>> 0;
|
|
712
|
+
}
|
|
713
|
+
/**
|
|
714
|
+
* Flat array of highlight rectangles in points on `page`: `[left, top, width, height, ...]`.
|
|
715
|
+
* @returns {Float64Array}
|
|
716
|
+
*/
|
|
717
|
+
get rects() {
|
|
718
|
+
const ret = wasm.searchmatch_rects(this.__wbg_ptr);
|
|
719
|
+
var v1 = getArrayF64FromWasm0(ret[0], ret[1]).slice();
|
|
720
|
+
wasm.__wbindgen_free(ret[0], ret[1] * 8, 8);
|
|
721
|
+
return v1;
|
|
722
|
+
}
|
|
723
|
+
/**
|
|
724
|
+
* Surrounding context excerpt from the matched paragraph.
|
|
725
|
+
* @returns {string}
|
|
726
|
+
*/
|
|
727
|
+
get snippet() {
|
|
728
|
+
let deferred1_0;
|
|
729
|
+
let deferred1_1;
|
|
730
|
+
try {
|
|
731
|
+
const ret = wasm.searchmatch_snippet(this.__wbg_ptr);
|
|
732
|
+
deferred1_0 = ret[0];
|
|
733
|
+
deferred1_1 = ret[1];
|
|
734
|
+
return getStringFromWasm0(ret[0], ret[1]);
|
|
735
|
+
} finally {
|
|
736
|
+
wasm.__wbindgen_free(deferred1_0, deferred1_1, 1);
|
|
737
|
+
}
|
|
738
|
+
}
|
|
739
|
+
/**
|
|
740
|
+
* Start offset in UTF-16 code units within the matched paragraph.
|
|
741
|
+
* @returns {number}
|
|
742
|
+
*/
|
|
743
|
+
get start() {
|
|
744
|
+
const ret = wasm.searchmatch_start(this.__wbg_ptr);
|
|
745
|
+
return ret >>> 0;
|
|
746
|
+
}
|
|
747
|
+
}
|
|
748
|
+
if (Symbol.dispose) SearchMatch.prototype[Symbol.dispose] = SearchMatch.prototype.free;
|
|
749
|
+
|
|
636
750
|
/**
|
|
637
751
|
* A run of upright text on a page, in points from the page's top left corner: the box of its
|
|
638
752
|
* glyphs from its font's ascender to its descender, and its glyphs.
|
|
@@ -809,6 +923,10 @@ function __wbg_get_imports() {
|
|
|
809
923
|
__wbg_prototypesetcall_13162965d1fe7aa3: function(arg0, arg1, arg2) {
|
|
810
924
|
Uint8Array.prototype.set.call(getArrayU8FromWasm0(arg0, arg1), arg2);
|
|
811
925
|
},
|
|
926
|
+
__wbg_searchmatch_new: function(arg0) {
|
|
927
|
+
const ret = SearchMatch.__wrap(arg0);
|
|
928
|
+
return ret;
|
|
929
|
+
},
|
|
812
930
|
__wbg_subarray_58f388a9247ac0bb: function(arg0, arg1, arg2) {
|
|
813
931
|
const ret = arg0.subarray(arg1 >>> 0, arg2 >>> 0);
|
|
814
932
|
return ret;
|
|
@@ -857,6 +975,9 @@ const PageImageFinalization = (typeof FinalizationRegistry === 'undefined')
|
|
|
857
975
|
const RendererFinalization = (typeof FinalizationRegistry === 'undefined')
|
|
858
976
|
? { register: () => {}, unregister: () => {} }
|
|
859
977
|
: new FinalizationRegistry(ptr => wasm.__wbg_renderer_free(ptr, 1));
|
|
978
|
+
const SearchMatchFinalization = (typeof FinalizationRegistry === 'undefined')
|
|
979
|
+
? { register: () => {}, unregister: () => {} }
|
|
980
|
+
: new FinalizationRegistry(ptr => wasm.__wbg_searchmatch_free(ptr, 1));
|
|
860
981
|
const TextRunFinalization = (typeof FinalizationRegistry === 'undefined')
|
|
861
982
|
? { register: () => {}, unregister: () => {} }
|
|
862
983
|
: new FinalizationRegistry(ptr => wasm.__wbg_textrun_free(ptr, 1));
|
|
Binary file
|