docling.rs-wasm 0.50.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 +21 -0
- package/README.md +77 -0
- package/bundler/docling_wasm.d.ts +132 -0
- package/bundler/docling_wasm.js +9 -0
- package/bundler/docling_wasm_bg.js +825 -0
- package/bundler/docling_wasm_bg.wasm +0 -0
- package/bundler/docling_wasm_bg.wasm.d.ts +33 -0
- package/package.json +50 -0
- package/web/docling_wasm.d.ts +190 -0
- package/web/docling_wasm.js +926 -0
- package/web/docling_wasm_bg.wasm +0 -0
- package/web/docling_wasm_bg.wasm.d.ts +33 -0
package/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2026 Artem Kustikov
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
package/README.md
ADDED
|
@@ -0,0 +1,77 @@
|
|
|
1
|
+
# docling.rs-wasm
|
|
2
|
+
|
|
3
|
+
[docling.rs](https://github.com/docling-project/docling.rs) compiled to
|
|
4
|
+
WebAssembly: convert **DOCX, HTML, XLSX, PPTX, CSV, AsciiDoc, EPUB, ODF,
|
|
5
|
+
Markdown, WebVTT, Email, MHTML, JATS, USPTO, XBRL, LaTeX, JSON, DocLang — and
|
|
6
|
+
the embedded text layer of PDFs** — to Markdown / docling JSON / DocLang XML
|
|
7
|
+
**entirely in the browser**. No server; the file never leaves the page.
|
|
8
|
+
|
|
9
|
+
~1.9 MB gzipped, no models needed for any of the above. Scanned PDFs and
|
|
10
|
+
images additionally work through the in-browser ML pipeline (RT-DETR layout +
|
|
11
|
+
PP-OCRv3 + TableFormer via [ONNX Runtime Web](https://www.npmjs.com/package/onnxruntime-web))
|
|
12
|
+
once you provide the models — see the
|
|
13
|
+
[full docs](https://github.com/docling-project/docling.rs/tree/master/crates/docling-wasm#readme)
|
|
14
|
+
and the [live demo](https://docling-project.github.io/docling.rs/).
|
|
15
|
+
|
|
16
|
+
## Bundlers (Vite, webpack, …)
|
|
17
|
+
|
|
18
|
+
```js
|
|
19
|
+
import { convert, supported_extensions } from "docling.rs-wasm";
|
|
20
|
+
|
|
21
|
+
const file = input.files[0];
|
|
22
|
+
const bytes = new Uint8Array(await file.arrayBuffer());
|
|
23
|
+
const markdown = convert(bytes, file.name, "md");
|
|
24
|
+
const json = convert(bytes, file.name, "json");
|
|
25
|
+
const withPics = convert(bytes, file.name, "md", "embedded"); // data: URIs
|
|
26
|
+
```
|
|
27
|
+
|
|
28
|
+
(The bundler target loads the wasm as a module import — Vite needs no config;
|
|
29
|
+
webpack 5 needs `experiments.asyncWebAssembly = true`.)
|
|
30
|
+
|
|
31
|
+
## No bundler (plain `<script type="module">`)
|
|
32
|
+
|
|
33
|
+
```js
|
|
34
|
+
import init, { convert } from "docling.rs-wasm/web";
|
|
35
|
+
await init(); // fetches docling_wasm_bg.wasm next to the JS
|
|
36
|
+
|
|
37
|
+
const markdown = convert(bytes, file.name, "md");
|
|
38
|
+
```
|
|
39
|
+
|
|
40
|
+
## API
|
|
41
|
+
|
|
42
|
+
```ts
|
|
43
|
+
convert(
|
|
44
|
+
bytes: Uint8Array,
|
|
45
|
+
filename: string, // extension drives format detection
|
|
46
|
+
to?: "md" | "json" | "doclang", // default "md"
|
|
47
|
+
images?: "placeholder" | "embedded", // default "placeholder", Markdown only
|
|
48
|
+
max_pages?: number, // convert only the first N PDF pages
|
|
49
|
+
): string
|
|
50
|
+
supported_extensions(): string // JSON array, e.g. for <input accept=…>
|
|
51
|
+
version(): string
|
|
52
|
+
```
|
|
53
|
+
|
|
54
|
+
Structured digital-PDF conversion (`DigitalConverter`: headings, lists,
|
|
55
|
+
tables, pictures via the layout model), scanned-document OCR
|
|
56
|
+
(`ScannedConverter`) and TableFormer table structure are exported too — they
|
|
57
|
+
need ONNX Runtime Web sessions on the JS side; the
|
|
58
|
+
[crate README](https://github.com/docling-project/docling.rs/tree/master/crates/docling-wasm#readme)
|
|
59
|
+
has the complete wiring, and the
|
|
60
|
+
[demo page source](https://github.com/docling-project/docling.rs/tree/master/crates/docling-wasm/www)
|
|
61
|
+
is a working reference.
|
|
62
|
+
|
|
63
|
+
## Tauri / Electron
|
|
64
|
+
|
|
65
|
+
The package runs in any webview as-is — but in a Tauri app you usually want
|
|
66
|
+
the **native** pipeline in the Rust backend instead (full OCR, TableFormer,
|
|
67
|
+
GPU, no wasm limits). See
|
|
68
|
+
[“Tauri and other desktop shells”](https://github.com/docling-project/docling.rs/tree/master/crates/docling-wasm#tauri-and-other-desktop-shells)
|
|
69
|
+
in the crate README.
|
|
70
|
+
|
|
71
|
+
## Related packages
|
|
72
|
+
|
|
73
|
+
- [`docling.rs`](https://www.npmjs.com/package/docling.rs) — native Node.js /
|
|
74
|
+
Bun bindings with the full ML pipeline (use this on servers).
|
|
75
|
+
- [`docling.rs-cuda`](https://www.npmjs.com/package/docling.rs-cuda) — the
|
|
76
|
+
same with CUDA execution providers.
|
|
77
|
+
- [`docling-rs`](https://pypi.org/project/docling-rs/) — Python wheel.
|
|
@@ -0,0 +1,132 @@
|
|
|
1
|
+
/* tslint:disable */
|
|
2
|
+
/* eslint-disable */
|
|
3
|
+
|
|
4
|
+
/**
|
|
5
|
+
* A digital PDF being converted page by page. Construct it from the file's
|
|
6
|
+
* bytes (the text layer is parsed once, in Rust), then feed the rasterized
|
|
7
|
+
* pages in order.
|
|
8
|
+
*/
|
|
9
|
+
export class DigitalConverter {
|
|
10
|
+
free(): void;
|
|
11
|
+
[Symbol.dispose](): void;
|
|
12
|
+
/**
|
|
13
|
+
* [`add_page`](Self::add_page) with TableFormer for the table regions whose
|
|
14
|
+
* geometric reconstruction looks unreliable.
|
|
15
|
+
*/
|
|
16
|
+
addPageTf(index: number, rgba: Uint8Array, px_w: number, px_h: number, scale: number, layout: any, tf: any, rec?: any | null): Promise<void>;
|
|
17
|
+
/**
|
|
18
|
+
* Convert page `index` (0-based) given its rendered bitmap: layout
|
|
19
|
+
* detection plus geometric tables. `scale` is the raster's pixels per PDF
|
|
20
|
+
* point (2.0 for pdf.js `{scale: 2}`). With `rec` (and a dictionary at
|
|
21
|
+
* construction), embedded raster pictures that carry no text cells are
|
|
22
|
+
* OCR'd — the text a digital page's images hide from its text layer.
|
|
23
|
+
*/
|
|
24
|
+
add_page(index: number, rgba: Uint8Array, px_w: number, px_h: number, scale: number, layout: any, rec?: any | null): Promise<void>;
|
|
25
|
+
/**
|
|
26
|
+
* Assemble the converted pages into a document and render it as `"md"`
|
|
27
|
+
* (default), `"json"` or `"doclang"`, with `images` picking how pictures
|
|
28
|
+
* render in Markdown. Resets the converter.
|
|
29
|
+
*/
|
|
30
|
+
finish(name: string, to?: string | null, images?: string | null): string;
|
|
31
|
+
/**
|
|
32
|
+
* Parse the PDF's text layer. Fails when there is none — the caller should
|
|
33
|
+
* fall back to the scanned pipeline, exactly as the demo page does.
|
|
34
|
+
* `dict` (optional) is the recognition dictionary text; with it and a
|
|
35
|
+
* `RecSession` on `add_page`, embedded raster pictures get OCR'd too.
|
|
36
|
+
*/
|
|
37
|
+
constructor(bytes: Uint8Array, dict?: string | null);
|
|
38
|
+
/**
|
|
39
|
+
* Pages the text parser found.
|
|
40
|
+
*/
|
|
41
|
+
page_count(): number;
|
|
42
|
+
/**
|
|
43
|
+
* Install the recognition dictionary after construction — the host probes
|
|
44
|
+
* the text layer first (the constructor throws on a scan) and only then
|
|
45
|
+
* fetches the recognition model + dictionary.
|
|
46
|
+
*/
|
|
47
|
+
setDict(dict: string): void;
|
|
48
|
+
}
|
|
49
|
+
|
|
50
|
+
/**
|
|
51
|
+
* Multi-page scanned-document converter (lite profile). Feed pages in
|
|
52
|
+
* order, then [`finish`](Self::finish) — cross-page paragraph continuations
|
|
53
|
+
* merge exactly like the native pipeline.
|
|
54
|
+
*/
|
|
55
|
+
export class ScannedConverter {
|
|
56
|
+
free(): void;
|
|
57
|
+
[Symbol.dispose](): void;
|
|
58
|
+
/**
|
|
59
|
+
* Convert one page with TableFormer (#157 stage 3): table regions get the
|
|
60
|
+
* ONNX table-structure model + docling's cell matcher instead of the
|
|
61
|
+
* geometric reconstruction. `tf` is the JS-side session over the encoder /
|
|
62
|
+
* decoder / bbox graphs.
|
|
63
|
+
*/
|
|
64
|
+
addPageTf(rgba: Uint8Array, px_w: number, px_h: number, scale: number, layout: any, rec: any, tf: any): Promise<void>;
|
|
65
|
+
/**
|
|
66
|
+
* Convert one page (lite profile — geometric tables): `rgba` is the
|
|
67
|
+
* rendered bitmap (canvas ImageData), `scale` its pixels-per-PDF-point
|
|
68
|
+
* (2.0 for pdf.js `{scale: 2}`; 1.0 for a standalone image).
|
|
69
|
+
*/
|
|
70
|
+
add_page(rgba: Uint8Array, px_w: number, px_h: number, scale: number, layout: any, rec: any): Promise<void>;
|
|
71
|
+
/**
|
|
72
|
+
* Assemble the accumulated pages into the final document and render it
|
|
73
|
+
* as `"md"` (default), `"json"` or `"doclang"` — the same three the
|
|
74
|
+
* declarative [`crate::convert`] entry point offers. `images` picks how
|
|
75
|
+
* cropped figures render in Markdown (`"placeholder"` | `"embedded"`),
|
|
76
|
+
* like [`crate::convert`]. Resets the converter.
|
|
77
|
+
*/
|
|
78
|
+
finish(name: string, to?: string | null, images?: string | null): string;
|
|
79
|
+
/**
|
|
80
|
+
* `dict` is the recognition dictionary text (`en_dict.txt` for the
|
|
81
|
+
* default English model).
|
|
82
|
+
*/
|
|
83
|
+
constructor(dict: string);
|
|
84
|
+
/**
|
|
85
|
+
* Number of pages converted so far (progress display).
|
|
86
|
+
*/
|
|
87
|
+
page_count(): number;
|
|
88
|
+
}
|
|
89
|
+
|
|
90
|
+
/**
|
|
91
|
+
* Convert a document (as bytes + filename, the extension drives format
|
|
92
|
+
* detection) to `to`: `"md"` (Markdown, default), `"json"` (docling-core's
|
|
93
|
+
* `DoclingDocument` wire format, schema 1.10.0) or `"doclang"` (docling's
|
|
94
|
+
* DocLang XML serialization).
|
|
95
|
+
*
|
|
96
|
+
* `images` controls how pictures render in Markdown — `"placeholder"`
|
|
97
|
+
* (default) or `"embedded"` (base64 data URIs), the same option
|
|
98
|
+
* docling-serve exposes. `max_pages` converts only a PDF's first N pages
|
|
99
|
+
* (issue #80's window, first pinned to 1); other formats ignore it.
|
|
100
|
+
*/
|
|
101
|
+
export function convert(bytes: Uint8Array, filename: string, to?: string | null, images?: string | null, max_pages?: number | null): string;
|
|
102
|
+
|
|
103
|
+
/**
|
|
104
|
+
* One-shot scanned-image conversion through the full lite profile (layout +
|
|
105
|
+
* OCR + assembly) — the browser counterpart of the native image path
|
|
106
|
+
* (a standalone image is its own page at scale 1).
|
|
107
|
+
*/
|
|
108
|
+
export function convert_scanned_image(bytes: Uint8Array, name: string, dict: string, layout: any, rec: any, to?: string | null, images?: string | null): Promise<string>;
|
|
109
|
+
|
|
110
|
+
/**
|
|
111
|
+
* OCR a scanned image entirely in the browser: `bytes` is the image file
|
|
112
|
+
* (PNG/JPEG/…), `dict` the recognition dictionary text (`en_dict.txt` for
|
|
113
|
+
* the default English model), `session` the JS inference wrapper. Returns
|
|
114
|
+
* Markdown (default) or docling JSON per `to`, one paragraph per recognized
|
|
115
|
+
* line.
|
|
116
|
+
*/
|
|
117
|
+
export function ocr_image(bytes: Uint8Array, dict: string, session: any, to?: string | null): Promise<string>;
|
|
118
|
+
|
|
119
|
+
export function start(): void;
|
|
120
|
+
|
|
121
|
+
/**
|
|
122
|
+
* The file extensions this build can convert, as a JSON string array —
|
|
123
|
+
* handy for an `<input accept=…>` filter. PDF converts via its embedded
|
|
124
|
+
* text layer (`pdf-text`); the remaining ML formats (images, audio, METS)
|
|
125
|
+
* are excluded: they are not compiled into the wasm build.
|
|
126
|
+
*/
|
|
127
|
+
export function supported_extensions(): string;
|
|
128
|
+
|
|
129
|
+
/**
|
|
130
|
+
* The docling.rs version this module was built from.
|
|
131
|
+
*/
|
|
132
|
+
export function version(): string;
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
/* @ts-self-types="./docling_wasm.d.ts" */
|
|
2
|
+
import * as wasm from "./docling_wasm_bg.wasm";
|
|
3
|
+
import { __wbg_set_wasm } from "./docling_wasm_bg.js";
|
|
4
|
+
|
|
5
|
+
__wbg_set_wasm(wasm);
|
|
6
|
+
wasm.__wbindgen_start();
|
|
7
|
+
export {
|
|
8
|
+
DigitalConverter, ScannedConverter, convert, convert_scanned_image, ocr_image, start, supported_extensions, version
|
|
9
|
+
} from "./docling_wasm_bg.js";
|