@f-office/core 0.2.0 → 0.2.2

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.
@@ -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
  *
@@ -93,6 +98,31 @@ export class Document {
93
98
  writePdf(): Uint8Array;
94
99
  }
95
100
 
101
+ /**
102
+ * A drawn page for JavaScript: its width, height and RGBA pixels.
103
+ */
104
+ export class Drawing {
105
+ private constructor();
106
+ free(): void;
107
+ [Symbol.dispose](): void;
108
+ /**
109
+ * Consumes and returns the RGBA pixels without cloning inside WebAssembly.
110
+ */
111
+ takePixels(): Uint8Array;
112
+ /**
113
+ * The height in pixels.
114
+ */
115
+ readonly height: number;
116
+ /**
117
+ * The pixels, four bytes each, row by row from the top, as a new array.
118
+ */
119
+ readonly pixels: Uint8Array;
120
+ /**
121
+ * The width in pixels.
122
+ */
123
+ readonly width: number;
124
+ }
125
+
96
126
  /**
97
127
  * A font that a document's text asks for and the families that the target tries for it.
98
128
  */
@@ -188,8 +218,10 @@ export class Renderer {
188
218
  */
189
219
  addArtPictures(data: Uint8Array | number[]): number;
190
220
  /**
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
221
+ * Adds every face in an OpenType font or font collection (`.ttf`, `.otf`, `.ttc`, `.otc`)
222
+ * or WOFF2 webfont (`.woff2` when built with the `woff2` feature), and returns the number
223
+ * of faces that it added. Full-table WOFF2 preserves exact layout metrics, while
224
+ * web-subsetted WOFF2 may omit glyphs or OpenType tables. A document that is already open
193
225
  * keeps its layout.
194
226
  *
195
227
  * # Errors
@@ -261,6 +293,392 @@ export class Renderer {
261
293
  static targets(): string[];
262
294
  }
263
295
 
296
+ /**
297
+ * One search match returned by `Document.search`.
298
+ */
299
+ export class SearchMatch {
300
+ private constructor();
301
+ free(): void;
302
+ [Symbol.dispose](): void;
303
+ /**
304
+ * Stable paragraph address when present (for example `"p12"`).
305
+ */
306
+ readonly address: string | undefined;
307
+ /**
308
+ * Exclusive end offset in UTF-16 code units within the matched paragraph.
309
+ */
310
+ readonly end: number;
311
+ /**
312
+ * Zero-based page index where the match starts.
313
+ */
314
+ readonly page: number;
315
+ /**
316
+ * Zero-based paragraph index in the matched story.
317
+ */
318
+ readonly paragraph: number;
319
+ /**
320
+ * Flat array of highlight rectangles in points on `page`: `[left, top, width, height, ...]`.
321
+ */
322
+ readonly rects: Float64Array;
323
+ /**
324
+ * Surrounding context excerpt from the matched paragraph.
325
+ */
326
+ readonly snippet: string;
327
+ /**
328
+ * Start offset in UTF-16 code units within the matched paragraph.
329
+ */
330
+ readonly start: number;
331
+ }
332
+
333
+ /**
334
+ * The viewer's session for JavaScript, as [`Session`] says.
335
+ */
336
+ export class Session {
337
+ free(): void;
338
+ [Symbol.dispose](): void;
339
+ /**
340
+ * Takes the ICU4X word dictionaries from an external postcard data blob, for the open
341
+ * document and the ones that it opens later.
342
+ *
343
+ * # Errors
344
+ *
345
+ * Throws when the data holds no word dictionaries.
346
+ */
347
+ addDictionaries(blob: Uint8Array | number[]): void;
348
+ /**
349
+ * Adds the faces of a font file and returns how many it holds.
350
+ *
351
+ * # Errors
352
+ *
353
+ * Throws when the data is no font.
354
+ */
355
+ addFont(data: Uint8Array | number[]): number;
356
+ /**
357
+ * Ends a press because the window lost the focus, and returns what it did, as JSON
358
+ * ([`handled_json`]).
359
+ *
360
+ * # Errors
361
+ *
362
+ * Throws when no document is open.
363
+ */
364
+ blur(): string;
365
+ /**
366
+ * Clears all caller-supplied highlights, or only those matching `kind`.
367
+ *
368
+ * # Errors
369
+ *
370
+ * Throws when no document is open.
371
+ */
372
+ clearHighlights(kind?: string | null): void;
373
+ /**
374
+ * Clears the selection.
375
+ *
376
+ * # Errors
377
+ *
378
+ * Throws when no document is open.
379
+ */
380
+ clearSelection(): void;
381
+ /**
382
+ * Draws a page at a resolution, and counts the drawing as the shell's.
383
+ *
384
+ * # Errors
385
+ *
386
+ * Throws when no document is open, or the page does not exist or cannot be drawn.
387
+ */
388
+ draw(page: number, dpi: number): Drawing;
389
+ /**
390
+ * Ends a zoom gesture, so that the next frame asks for the drawings at its zoom.
391
+ *
392
+ * # Errors
393
+ *
394
+ * Throws when no document is open.
395
+ */
396
+ endGesture(): void;
397
+ /**
398
+ * Makes the next match current when `forward` is set, and the match before it when not.
399
+ *
400
+ * # Errors
401
+ *
402
+ * Throws when no document is open.
403
+ */
404
+ findStep(forward: boolean): void;
405
+ /**
406
+ * Searches the document for `query`, and returns the number of matches.
407
+ *
408
+ * # Errors
409
+ *
410
+ * Throws when no document is open.
411
+ */
412
+ find(query: string): number;
413
+ /**
414
+ * The fonts that a random-access DOCX source asks for on `target`, as JSON, without copying
415
+ * the whole archive into WASM linear memory ([`Session::fonts_needed_source`]).
416
+ *
417
+ * # Errors
418
+ *
419
+ * Throws when `byteLength` is invalid, no target has the ID, or the source cannot be opened.
420
+ */
421
+ static fontsNeededSource(byte_length: number, read_at: Function, target?: string | null): string;
422
+ /**
423
+ * The fonts that `docx` asks for on `target`, as JSON ([`Session::fonts_needed`]).
424
+ *
425
+ * # Errors
426
+ *
427
+ * Throws when no target has the ID or the file cannot be opened.
428
+ */
429
+ static fontsNeeded(docx: Uint8Array | number[], target?: string | null): string;
430
+ /**
431
+ * Forgets the drawings that the worker was asked for and has not drawn.
432
+ *
433
+ * # Errors
434
+ *
435
+ * Throws when no document is open.
436
+ */
437
+ forgetRequests(): void;
438
+ /**
439
+ * What the shell shows now, as JSON ([`frame_json`]).
440
+ *
441
+ * # Errors
442
+ *
443
+ * Throws when no document is open.
444
+ */
445
+ frame(): string;
446
+ /**
447
+ * Zooms to `factor` during a zoom gesture, around the viewport's point at `anchor_x` and
448
+ * `anchor_y`: the frames ask for no drawing until [`Session::end_gesture`].
449
+ *
450
+ * # Errors
451
+ *
452
+ * Throws when no document is open.
453
+ */
454
+ gestureZoom(factor: number, anchor_x?: number | null, anchor_y?: number | null): void;
455
+ /**
456
+ * Scrolls to the line where the bookmark `name` starts, and returns whether it went.
457
+ *
458
+ * # Errors
459
+ *
460
+ * Throws when no document is open.
461
+ */
462
+ goToBookmark(name: string): boolean;
463
+ /**
464
+ * Scrolls to the first line of a heading of the outline, by its index in the outline, and
465
+ * makes it the frame's `currentHeading` until the next scroll.
466
+ *
467
+ * # Errors
468
+ *
469
+ * Throws when no document is open.
470
+ */
471
+ goToHeading(index: number): void;
472
+ /**
473
+ * Scrolls the top of a page, counted from 0, to the top of the viewport.
474
+ *
475
+ * # Errors
476
+ *
477
+ * Throws when no document is open.
478
+ */
479
+ goToPage(page: number): void;
480
+ /**
481
+ * The innermost hyperlink under the viewport's point `x`, `y`, as JSON: its `target`, an
482
+ * `external` `address` or a `bookmark` `name`, and its `tooltip`; null away from a link.
483
+ *
484
+ * # Errors
485
+ *
486
+ * Throws when no document is open.
487
+ */
488
+ linkAt(x: number, y: number): string;
489
+ /**
490
+ * A session with no fonts and no document.
491
+ */
492
+ constructor();
493
+ /**
494
+ * Opens a random-access DOCX source for `target` without copying the full archive into WASM
495
+ * linear memory ([`Session::open_source`]).
496
+ *
497
+ * # Errors
498
+ *
499
+ * Throws when `byteLength` is invalid, no target has the ID, or the source cannot be opened.
500
+ */
501
+ openSource(byte_length: number, read_at: Function, target?: string | null): string;
502
+ /**
503
+ * Opens `docx` for `target`, and returns its page count and outline as JSON
504
+ * ([`Session::open`]).
505
+ *
506
+ * # Errors
507
+ *
508
+ * Throws when no target has the ID or the file cannot be opened.
509
+ */
510
+ open(docx: Uint8Array | number[], target?: string | null): string;
511
+ /**
512
+ * Whether the viewport's point `x`, `y` lies on a line of text.
513
+ *
514
+ * # Errors
515
+ *
516
+ * Throws when no document is open.
517
+ */
518
+ overText(x: number, y: number): boolean;
519
+ /**
520
+ * The hyperlinks of a page, counted from 0, as JSON: in reading order, each with its
521
+ * `target`, `tooltip`, `text` and `boxes`, the boxes as shares of the page's width and
522
+ * height.
523
+ *
524
+ * # Errors
525
+ *
526
+ * Throws when no document is open.
527
+ */
528
+ pageLinks(page: number): string;
529
+ /**
530
+ * Writes the open document's pages as a PDF file, for printing.
531
+ *
532
+ * # Errors
533
+ *
534
+ * Throws when no document is open, or the pages cannot be written as PDF.
535
+ */
536
+ pdf(): Uint8Array;
537
+ /**
538
+ * Ends a press that the platform cancelled or whose capture it lost, and returns what it
539
+ * did, as JSON ([`handled_json`]).
540
+ *
541
+ * # Errors
542
+ *
543
+ * Throws when no document is open.
544
+ */
545
+ pointerCancel(): string;
546
+ /**
547
+ * Takes a press at the viewport's point `x`, `y` at `time` milliseconds: whether of the
548
+ * `primary` button, by a `pointer` of kind `mouse`, `pen` or `touch`, with `shift`, on a
549
+ * `hit` of kind `page`, `gap`, `scroll-bar`, `start-handle` or `end-handle`. Returns what it did, as JSON
550
+ * ([`handled_json`]).
551
+ *
552
+ * # Errors
553
+ *
554
+ * Throws when no document is open or a kind has another name.
555
+ */
556
+ pointerDown(x: number, y: number, primary: boolean, pointer: string, shift: boolean, time: number, hit: string): string;
557
+ /**
558
+ * Moves a press's pointer to the viewport's point `x`, `y` at `time` milliseconds, and
559
+ * returns what it did, as JSON ([`handled_json`]).
560
+ *
561
+ * # Errors
562
+ *
563
+ * Throws when no document is open.
564
+ */
565
+ pointerMove(x: number, y: number, time: number): string;
566
+ /**
567
+ * Ends a press at the viewport's point `x`, `y` at `time` milliseconds, and returns what
568
+ * it did, as JSON ([`handled_json`]).
569
+ *
570
+ * # Errors
571
+ *
572
+ * Throws when no document is open.
573
+ */
574
+ pointerUp(x: number, y: number, time: number): string;
575
+ /**
576
+ * Draws a page at a resolution for the browser's own Print, without counting the
577
+ * drawing as the shell's.
578
+ *
579
+ * # Errors
580
+ *
581
+ * Throws when no document is open, or the page does not exist or cannot be drawn.
582
+ */
583
+ printPage(page: number, dpi: number): Drawing;
584
+ /**
585
+ * The reading text of a page, counted from 0, as JSON: its paragraphs in reading order,
586
+ * each with its `text` and its outline `level` or null.
587
+ *
588
+ * # Errors
589
+ *
590
+ * Throws when no document is open.
591
+ */
592
+ readingText(page: number): string;
593
+ /**
594
+ * Gives the viewer the viewport's size in CSS pixels and the device pixel ratio.
595
+ *
596
+ * # Errors
597
+ *
598
+ * Throws when no document is open.
599
+ */
600
+ resize(width: number, height: number, ratio: number): void;
601
+ /**
602
+ * Scrolls to `page`, optionally focusing a point-space rectangle with `block` placement.
603
+ *
604
+ * # Errors
605
+ *
606
+ * Throws when no document is open.
607
+ */
608
+ scrollToRect(page: number, left?: number | null, top?: number | null, width?: number | null, height?: number | null, block?: string | null): void;
609
+ /**
610
+ * Scrolls the viewport's top left corner to `(left, top)`.
611
+ *
612
+ * # Errors
613
+ *
614
+ * Throws when no document is open.
615
+ */
616
+ scrollTo(left: number, top: number): void;
617
+ /**
618
+ * Selects the whole story of the last press.
619
+ *
620
+ * # Errors
621
+ *
622
+ * Throws when no document is open.
623
+ */
624
+ selectAll(): void;
625
+ /**
626
+ * The selected text, as a copy gives it.
627
+ *
628
+ * # Errors
629
+ *
630
+ * Throws when no document is open.
631
+ */
632
+ selectedText(): string;
633
+ /**
634
+ * Replaces caller-supplied highlights from a JSON array string.
635
+ *
636
+ * # Errors
637
+ *
638
+ * Throws when no document is open or JSON is malformed.
639
+ */
640
+ setHighlights(items_json: string): void;
641
+ /**
642
+ * Enables or disables two-pass progressive drawing (fast 96 DPI draft before `HiDPI`).
643
+ */
644
+ setProgressiveDraft(enabled: boolean): void;
645
+ /**
646
+ * Sets the zoom, `fixed` at `factor`, `fit-width` or `fit-page`, around the anchor or the
647
+ * viewport's middle ([`Session::set_zoom`]).
648
+ *
649
+ * # Errors
650
+ *
651
+ * Throws when no document is open or the kind is no zoom.
652
+ */
653
+ setZoom(kind: string, factor: number, anchor_x?: number | null, anchor_y?: number | null): void;
654
+ /**
655
+ * Scrolls a point in points of a page, counted from 0, to the viewport's top left corner,
656
+ * as the frame's `place` gave it.
657
+ *
658
+ * # Errors
659
+ *
660
+ * Throws when no document is open.
661
+ */
662
+ showPlace(page: number, x: number, y: number): void;
663
+ /**
664
+ * Streams the open document's pages as a PDF to `onChunk(chunk: Uint8Array)` in bounded
665
+ * 64 KiB chunks without allocating the full PDF in WASM linear memory.
666
+ *
667
+ * # Errors
668
+ *
669
+ * Throws when no document is open, or the pages cannot be written as PDF.
670
+ */
671
+ writePdfTo(on_chunk: Function): void;
672
+ /**
673
+ * Zooms one step in or out around the anchor or the viewport's middle.
674
+ *
675
+ * # Errors
676
+ *
677
+ * Throws when no document is open.
678
+ */
679
+ zoomStep(inward: boolean, anchor_x?: number | null, anchor_y?: number | null): void;
680
+ }
681
+
264
682
  /**
265
683
  * A run of upright text on a page, in points from the page's top left corner: the box of its
266
684
  * glyphs from its font's ascender to its descender, and its glyphs.
@@ -317,10 +735,13 @@ export type InitInput = RequestInfo | URL | Response | BufferSource | WebAssembl
317
735
  export interface InitOutput {
318
736
  readonly memory: WebAssembly.Memory;
319
737
  readonly __wbg_document_free: (a: number, b: number) => void;
738
+ readonly __wbg_drawing_free: (a: number, b: number) => void;
320
739
  readonly __wbg_fontneed_free: (a: number, b: number) => void;
321
740
  readonly __wbg_outlineentry_free: (a: number, b: number) => void;
322
741
  readonly __wbg_pageimage_free: (a: number, b: number) => void;
323
742
  readonly __wbg_renderer_free: (a: number, b: number) => void;
743
+ readonly __wbg_searchmatch_free: (a: number, b: number) => void;
744
+ readonly __wbg_session_free: (a: number, b: number) => void;
324
745
  readonly __wbg_textrun_free: (a: number, b: number) => void;
325
746
  readonly document_fontNeeds: (a: number) => [number, number];
326
747
  readonly document_outline: (a: number) => [number, number];
@@ -330,10 +751,15 @@ export interface InitOutput {
330
751
  readonly document_pageWidth: (a: number, b: number, c: number) => [number, number, number];
331
752
  readonly document_renderPage: (a: number, b: number, c: number) => [number, number, number];
332
753
  readonly document_renderRegion: (a: number, b: number, c: number, d: number, e: number, f: number, g: number) => [number, number, number];
754
+ readonly document_search: (a: number, b: number, c: number, d: number, e: number, f: number) => [number, number];
333
755
  readonly document_textRuns: (a: number, b: number) => [number, number, number, number];
334
756
  readonly document_warnings: (a: number) => [number, number];
335
757
  readonly document_writePdf: (a: number) => [number, number, number, number];
336
758
  readonly document_writePdfTo: (a: number, b: any) => [number, number, number, number];
759
+ readonly drawing_height: (a: number) => number;
760
+ readonly drawing_pixels: (a: number) => [number, number];
761
+ readonly drawing_takePixels: (a: number) => [number, number];
762
+ readonly drawing_width: (a: number) => number;
337
763
  readonly fontneed_family: (a: number) => [number, number];
338
764
  readonly fontneed_tried: (a: number) => [number, number];
339
765
  readonly outlineentry_address: (a: number) => [number, number];
@@ -354,6 +780,54 @@ export interface InitOutput {
354
780
  readonly renderer_openDocxMobile: (a: number, b: number, c: number, d: number, e: number, f: number, g: number) => [number, number, number];
355
781
  readonly renderer_openDocxSource: (a: number, b: number, c: any, d: number, e: number, f: number, g: number, h: number) => [number, number, number];
356
782
  readonly renderer_targets: () => [number, number];
783
+ readonly searchmatch_address: (a: number) => [number, number];
784
+ readonly searchmatch_end: (a: number) => number;
785
+ readonly searchmatch_page: (a: number) => number;
786
+ readonly searchmatch_paragraph: (a: number) => number;
787
+ readonly searchmatch_rects: (a: number) => [number, number];
788
+ readonly searchmatch_snippet: (a: number) => [number, number];
789
+ readonly searchmatch_start: (a: number) => number;
790
+ readonly session_addDictionaries: (a: number, b: number, c: number) => [number, number];
791
+ readonly session_addFont: (a: number, b: number, c: number) => [number, number, number];
792
+ readonly session_blur: (a: number) => [number, number, number, number];
793
+ readonly session_clearHighlights: (a: number, b: number, c: number) => [number, number];
794
+ readonly session_clearSelection: (a: number) => [number, number];
795
+ readonly session_draw: (a: number, b: number, c: number) => [number, number, number];
796
+ readonly session_endGesture: (a: number) => [number, number];
797
+ readonly session_find: (a: number, b: number, c: number) => [number, number, number];
798
+ readonly session_findStep: (a: number, b: number) => [number, number];
799
+ readonly session_fontsNeeded: (a: number, b: number, c: number, d: number) => [number, number, number, number];
800
+ readonly session_fontsNeededSource: (a: number, b: any, c: number, d: number) => [number, number, number, number];
801
+ readonly session_forgetRequests: (a: number) => [number, number];
802
+ readonly session_frame: (a: number) => [number, number, number, number];
803
+ readonly session_gestureZoom: (a: number, b: number, c: number, d: number, e: number, f: number) => [number, number];
804
+ readonly session_goToBookmark: (a: number, b: number, c: number) => [number, number, number];
805
+ readonly session_goToHeading: (a: number, b: number) => [number, number];
806
+ readonly session_goToPage: (a: number, b: number) => [number, number];
807
+ readonly session_linkAt: (a: number, b: number, c: number) => [number, number, number, number];
808
+ readonly session_new: () => number;
809
+ readonly session_open: (a: number, b: number, c: number, d: number, e: number) => [number, number, number, number];
810
+ readonly session_openSource: (a: number, b: number, c: any, d: number, e: number) => [number, number, number, number];
811
+ readonly session_overText: (a: number, b: number, c: number) => [number, number, number];
812
+ readonly session_pageLinks: (a: number, b: number) => [number, number, number, number];
813
+ readonly session_pdf: (a: number) => [number, number, number, number];
814
+ readonly session_pointerCancel: (a: number) => [number, number, number, number];
815
+ readonly session_pointerDown: (a: number, b: number, c: number, d: number, e: number, f: number, g: number, h: number, i: number, j: number) => [number, number, number, number];
816
+ readonly session_pointerMove: (a: number, b: number, c: number, d: number) => [number, number, number, number];
817
+ readonly session_pointerUp: (a: number, b: number, c: number, d: number) => [number, number, number, number];
818
+ readonly session_printPage: (a: number, b: number, c: number) => [number, number, number];
819
+ readonly session_readingText: (a: number, b: number) => [number, number, number, number];
820
+ readonly session_resize: (a: number, b: number, c: number, d: number) => [number, number];
821
+ readonly session_scrollTo: (a: number, b: number, c: number) => [number, number];
822
+ readonly session_scrollToRect: (a: number, b: number, c: number, d: number, e: number, f: number, g: number, h: number, i: number, j: number, k: number, l: number) => [number, number];
823
+ readonly session_selectAll: (a: number) => [number, number];
824
+ readonly session_selectedText: (a: number) => [number, number, number, number];
825
+ readonly session_setHighlights: (a: number, b: number, c: number) => [number, number];
826
+ readonly session_setProgressiveDraft: (a: number, b: number) => void;
827
+ readonly session_setZoom: (a: number, b: number, c: number, d: number, e: number, f: number, g: number, h: number) => [number, number];
828
+ readonly session_showPlace: (a: number, b: number, c: number, d: number) => [number, number];
829
+ readonly session_writePdfTo: (a: number, b: any) => [number, number];
830
+ readonly session_zoomStep: (a: number, b: number, c: number, d: number, e: number, f: number) => [number, number];
357
831
  readonly textrun_baseline: (a: number) => number;
358
832
  readonly textrun_glyphEnds: (a: number) => [number, number];
359
833
  readonly textrun_glyphLefts: (a: number) => [number, number];