@veripublica/paginaverto-wasm 0.1.2 → 0.1.3

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 CHANGED
@@ -14,10 +14,12 @@ import { read } from "@veripublica/paginaverto-wasm"; // bundler build
14
14
  // or, without a bundler: wasm-pack build --target web, then
15
15
  // import init, { read } from "./pkg/paginaverto_wasm.js"; await init();
16
16
  const book = read(new Uint8Array(await file.arrayBuffer()));
17
- // book.chapters: [{ title, blocks: [{ kind: "paragraph", text } | { kind: "figure", mediaType, ext, data }] }]
18
- // A refusal throws an Error with `kind` (Open, ScanNeedsOcr, UndecodableFonts, NoText, QualityGate, Internal).
17
+ // book: Book = { chapters: [{ title, blocks: [{ kind: "paragraph", text } | { kind: "figure", mediaType, ext, data }] }] }
18
+ // A refusal throws a PaginavertoError: an Error with `kind` (Open, ScanNeedsOcr, UndecodableFonts, NoText, QualityGate, Internal).
19
19
  ```
20
20
 
21
+ - **Typed.** The `.d.ts` declares `Book`, `Chapter`, `Block` (a union you
22
+ narrow on `kind`), `ErrorKind` and `PaginavertoError`.
21
23
  - **Text layers only.** OCR is not built for the browser; a scan throws
22
24
  `ScanNeedsOcr`.
23
25
  - A panic cannot be caught in WebAssembly: it traps the instance. The demo
package/package.json CHANGED
@@ -2,7 +2,7 @@
2
2
  "name": "@veripublica/paginaverto-wasm",
3
3
  "type": "module",
4
4
  "description": "WebAssembly bindings for paginaverto: read a PDF into chapters in the browser, no upload.",
5
- "version": "0.1.2",
5
+ "version": "0.1.3",
6
6
  "license": "AGPL-3.0-only OR LicenseRef-veripublica-Commercial",
7
7
  "repository": {
8
8
  "type": "git",
@@ -1,14 +1,61 @@
1
1
  /* tslint:disable */
2
2
  /* eslint-disable */
3
3
 
4
+ /** One piece of chapter content, in reading order. */
5
+ export type Block =
6
+ | {
7
+ kind: "paragraph";
8
+ /** The paragraph's text, whitespace collapsed to single spaces. */
9
+ text: string;
10
+ }
11
+ | {
12
+ kind: "figure";
13
+ /** A JPEG verbatim, or raw pixels re-encoded as PNG. */
14
+ mediaType: "image/jpeg" | "image/png";
15
+ ext: "jpg" | "png";
16
+ /** The image file's bytes. */
17
+ data: Uint8Array;
18
+ };
19
+
20
+ /** An optional heading and its content. */
21
+ export interface Chapter {
22
+ /** The heading that starts the chapter; `null` before the first heading. */
23
+ title: string | null;
24
+ blocks: Block[];
25
+ }
26
+
27
+ /** What a PDF turned into. `chapters` is never empty. */
28
+ export interface Book {
29
+ chapters: Chapter[];
30
+ }
31
+
32
+ /** Why a PDF could not be read; the `kind` of a thrown `PaginavertoError`. */
33
+ export type ErrorKind =
34
+ | "Open"
35
+ | "ScanNeedsOcr"
36
+ | "LanguageRequired"
37
+ | "Models"
38
+ | "OcrFoundNothing"
39
+ | "UndecodableFonts"
40
+ | "NoText"
41
+ | "QualityGate"
42
+ | "Internal";
43
+
44
+ /** What `read` throws: an `Error` whose `kind` names the reason. */
45
+ export interface PaginavertoError extends Error {
46
+ kind: ErrorKind;
47
+ }
48
+
49
+
50
+
4
51
  /**
5
- * Read a PDF. Returns `{ chapters: [{ title, blocks }] }`, where each block
6
- * is `{ kind: "paragraph", text }` or `{ kind: "figure", mediaType, ext,
7
- * data }`. Throws an `Error` whose `kind` names the reason (`Open`,
52
+ * Read a PDF into a `Book` (chapters of paragraphs and figures). Throws a
53
+ * `PaginavertoError`: an `Error` whose `kind` names the reason (`Open`,
8
54
  * `ScanNeedsOcr`, `UndecodableFonts`, `NoText`, `QualityGate`, `Internal`)
9
- * and whose `message` says it in English.
55
+ * and whose `message` says it in English. Text layers only: a scan throws
56
+ * `ScanNeedsOcr`.
10
57
  */
11
- export function read(pdf: Uint8Array): any;
58
+ export function read(pdf: Uint8Array): Book;
12
59
 
13
60
  /**
14
61
  * The crate version.
@@ -1,11 +1,11 @@
1
1
  /**
2
- * Read a PDF. Returns `{ chapters: [{ title, blocks }] }`, where each block
3
- * is `{ kind: "paragraph", text }` or `{ kind: "figure", mediaType, ext,
4
- * data }`. Throws an `Error` whose `kind` names the reason (`Open`,
2
+ * Read a PDF into a `Book` (chapters of paragraphs and figures). Throws a
3
+ * `PaginavertoError`: an `Error` whose `kind` names the reason (`Open`,
5
4
  * `ScanNeedsOcr`, `UndecodableFonts`, `NoText`, `QualityGate`, `Internal`)
6
- * and whose `message` says it in English.
5
+ * and whose `message` says it in English. Text layers only: a scan throws
6
+ * `ScanNeedsOcr`.
7
7
  * @param {Uint8Array} pdf
8
- * @returns {any}
8
+ * @returns {Book}
9
9
  */
10
10
  export function read(pdf) {
11
11
  const ptr0 = passArray8ToWasm0(pdf, wasm.__wbindgen_malloc);
Binary file