@bulkgrid/bulkparse-wasm 0.0.0-stage → 0.1.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/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2026 BulkParse contributors
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 CHANGED
@@ -1,3 +1,57 @@
1
- # Temporary Holding Version
1
+ # BulkParse for browsers
2
2
 
3
- This version is a temporary placeholder for this package. An operational version to replace this has been submitted for review and is awaiting a staged release.
3
+ Install the browser package with:
4
+
5
+ ```sh
6
+ npm install @bulkgrid/bulkparse-wasm
7
+ ```
8
+
9
+ Rust and wasm-pack are only needed to build from source. From this folder:
10
+
11
+ ```sh
12
+ rustup target add wasm32-unknown-unknown
13
+ cargo install wasm-pack --locked
14
+ npm run build
15
+ npm test
16
+ npm run test:package
17
+ python3 -m http.server 8080
18
+ ```
19
+
20
+ Open `http://localhost:8080/example/` for local file conversion in a Web Worker. The sample refuses files over 32 MiB, transfers input bytes to the worker, and displays output as text. It never uploads the chosen file. The main conversion API is synchronous; use a worker for larger inputs and terminate/recreate it to enforce a host timeout.
21
+
22
+ ```js
23
+ import {init, parse} from '@bulkgrid/bulkparse-wasm';
24
+ await init();
25
+ const result = parse(new TextEncoder().encode('# Hello'), {filename: 'hello.md'});
26
+ console.log(result.markdown);
27
+ ```
28
+
29
+ Serve the generated `.wasm` with MIME type `application/wasm`. WASM exports no file-path or network fetching API. The current build enables DOCX and positioned native-text PDF with heuristic column/directional ordering. No OCR engine or learned layout model is included; page-level diagnostics identify image-only OCR candidates. The current release WASM binary is 2,540,071 bytes (923,087 bytes with gzip level 9). Smoke tests and DOCX conversion in the in-app browser pass; broader browser compatibility is not yet established. Byte copies and JSON serialization still consume memory; the parser limits are not a hard memory sandbox.
30
+
31
+ `capabilities()` and output types match the native bindings. Bundlers can import the package wrapper; the generated `pkg` directory must be included with it. Package-level TypeScript declarations describe the same model as Node.
32
+
33
+
34
+ For offline builds, first install a `wasm-bindgen-cli` version matching the resolved `wasm-bindgen` dependency in Cargo.lock (currently `0.2.130`):
35
+
36
+ ```sh
37
+ cargo install wasm-bindgen-cli --version 0.2.130 --locked
38
+ CARGO_NET_OFFLINE=true npm run build
39
+ ```
40
+
41
+ The build script uses a workspace-local tool cache unless `WASM_PACK_CACHE` is set. It keeps WASM target metadata needed by wasm-bindgen. Packaging checks require the generated JS, TypeScript and WASM assets and override wasm-pack's generated ignore rule so npm includes the engine. `npm run test:package` packs the wrapper, installs that tarball in a temporary directory without network access, and converts DOCX through the installed package. No package is published by these commands.
42
+
43
+ CSV supports automatic comma/semicolon/tab/pipe detection and BOM-aware UTF-8/UTF-16 decoding. Without a BOM or explicit encoding, valid UTF-8 is preserved; otherwise legacy Windows-1252 decoding is attempted and reported with a `csv_encoding_inferred` diagnostic. Encoding inference is ambiguous, particularly for mixed-encoding files. Set `csv_encoding` to `utf8` for strict UTF-8, `windows1252` for a known legacy export, or `utf16_le` / `utf16_be` for BOM-less UTF-16. Explicit encodings must agree with any BOM. Undefined Windows-1252 bytes and binary controls are rejected. For delimiter ambiguity, pass `csv_delimiter` (one ASCII character); headers remain explicit through `csv_has_headers`.
44
+
45
+ PDFs support conservative ruled-table reconstruction. Arabic presentation forms and alphabetic ligatures expand by default. Pass `pdf_normalize_unicode: false` (Python: `pdf_normalize_unicode=False`) to retain mapped forms. `ActualText` is always preserved. See the root `docs/pdf-tables.md` for limits and validation.
46
+
47
+ PDF inspection is available without an OCR runtime: `inspectPdf(bytes)`. Conversion results also include `pdf_inspection`. The shared output schema is now 0.8. See [inspection and routing](../../docs/pdf-inspection.md).
48
+
49
+ The standard build enables BulkParse-owned Office/EPUB readers. See [format support and limits](../../docs/office-formats.md).
50
+
51
+ For resource-limited spreadsheets and CSV files, opt in to `partial_on_limit` (Python: `partial_on_limit=True`). Successful normal conversions are unchanged; supported limit failures can return an explicitly partial prefix within the original per-attempt budgets. This is not complete extraction and strict mode never accepts the recovery result. Inspect `status` and `resource_limit_partial` diagnostics. See [bounded large-document handling](../../docs/large-documents.md). Rebuild the binding to use this option.
52
+
53
+ Embedded image bytes are available in `document.assets` (base64 JSON). See [image retention, export and limitations](../../docs/images.md).
54
+
55
+ ## OCR and standalone images
56
+
57
+ See [OCR across language bindings](../../docs/ocr-bindings.md) for the shared evidence API, browser-hosted recognition, image/frame support, scanned-table limits, and examples.
package/index.d.ts ADDED
@@ -0,0 +1,68 @@
1
+ export type PdfPageKind = 'text' | 'image' | 'mixed' | 'vector' | 'blank' | 'unknown';
2
+ export interface PdfPageInspection {
3
+ page: number; kind: PdfPageKind; route: 'native' | 'ocr' | 'skip' | 'review';
4
+ reasons: ('usable_native_text' | 'no_native_text' | 'suspect_text_encoding' | 'undecodable_text' | 'large_image_with_sparse_text' | 'outlined_text_with_sparse_native_text' | 'invisible_text_layer' | 'vector_content' | 'no_painted_content' | 'uncertain_graphics' | 'extraction_failed')[];
5
+ native_characters: number; suspicious_characters: number; text_operations: number;
6
+ invisible_text_operations: number; image_count: number; image_coverage: number | null;
7
+ painted_paths: number;
8
+ ocr_status: 'not_needed' | 'not_requested' | 'applied' | 'empty' | 'failed' | 'budget_exhausted';
9
+ }
10
+ export interface PdfInspection {
11
+ schema_version: string; kind: PdfPageKind; page_count: number;
12
+ pages: PdfPageInspection[]; pages_needing_ocr: number[];
13
+ }
14
+ export type Format = 'image' | 'text' | 'markdown' | 'csv' | 'tsv' | 'notebook' | 'docx' | 'pdf' | 'xlsx' | 'xls' | 'xlsb' | 'pptx' | 'ppt' | 'odt' | 'ods' | 'odp' | 'epub' | 'rtf' | 'doc';
15
+ export interface OcrSource { image_size: [number, number]; quad: [[number, number], [number, number], [number, number], [number, number]]; confidence: number }
16
+ export interface PdfRegionSource { image_size: [number, number]; bbox: [number, number, number, number]; order: number; label: string; confidence?: number }
17
+ export interface Source { pdf_region?: PdfRegionSource; ocr?: OcrSource; page?: number; part?: string; cell?: number; row?: number; byte_range?: [number, number] }
18
+ export interface Diagnostic { code: string; message: string; source: Source; content_loss: boolean; category: 'missing_content' | 'formatting_limitation' | 'informational'; evidence: 'detected' | 'unverified' }
19
+ export interface Limits {
20
+ max_image_bytes?: number; max_images?: number;
21
+ max_input_bytes?: number; max_text_bytes?: number; max_nodes?: number;
22
+ max_depth?: number; max_table_cells?: number; max_pages?: number;
23
+ /** Additional cells generated by row/column repetition. */
24
+ max_cell_repetitions?: number;
25
+ max_archive_entries?: number; max_expanded_bytes?: number;
26
+ /** Native Markdown writer only; includes markup and empty cells. */
27
+ max_markdown_bytes?: number;
28
+ }
29
+ export interface Options { extract_images?: boolean; export_images?: boolean; filename?: string; format?: Format; strict?: boolean; partial_on_limit?: boolean; pdf_normalize_unicode?: boolean; pdf_force_ocr?: boolean; csv_has_headers?: boolean; csv_delimiter?: string; csv_encoding?: 'utf8' | 'utf16_le' | 'utf16_be' | 'windows1252'; limits?: Limits }
30
+ export type Inline = {type: 'text' | 'code'; text: string}
31
+ | {type: 'math'; tex: string; display: boolean} | {type: 'anchor'; id: string}
32
+ | {type: 'strong' | 'emphasis' | 'strike'; children: Inline[]}
33
+ | {type: 'link'; url: string; children: Inline[]}
34
+ | {type: 'image'; url: string; alt: string} | {type: 'break'};
35
+ export interface Cell { blocks: Block[]; col_span: number; row_span: number; source: Source }
36
+ export type Block = {id: string; source: Source} & (
37
+ {type: 'paragraph'; inlines: Inline[]} | {type: 'heading'; level: number; inlines: Inline[]}
38
+ | {type: 'code'; language: string; text: string} | {type: 'quote'; blocks: Block[]}
39
+ | {type: 'list'; start: number | null; items: Block[][]}
40
+ | {type: 'table'; rows: Cell[][]; header_rows: number}
41
+ | {type: 'thematic_break'} | {type: 'raw'; media_type: string; text: string});
42
+ export interface ImageAsset { id: string; media_type: string; source: Source; /** Base64-encoded original image bytes. */ data: string }
43
+ export interface Conversion {
44
+ pdf_inspection?: PdfInspection;
45
+ document: {schema_version: string; format: Format; blocks: Block[]; assets: ImageAsset[]};
46
+ status: 'complete' | 'partial'; diagnostics: Diagnostic[];
47
+ coverage: {source: Source; status: 'complete' | 'partial'}[];
48
+ parser_version: string; markdown: string; render_diagnostics: Diagnostic[];
49
+ }
50
+ export function parse(bytes: Uint8Array, options?: Options): Conversion;
51
+ export function capabilities(): {format: Format; enabled: boolean; level: string; notes: string}[];
52
+ export function init(input?: Parameters<typeof import("./pkg/bulkparse_wasm.js").default>[0]): ReturnType<typeof import("./pkg/bulkparse_wasm.js").default>;
53
+
54
+ export function inspectPdf(bytes: Uint8Array, options?: Options): PdfInspection;
55
+
56
+ export interface OcrBudget { max_pages?: number; max_output_bytes?: number }
57
+ export interface OcrLine { text: string; quad: OcrSource['quad']; confidence: number }
58
+ export interface OcrRegion {
59
+ order: number; bbox: [number, number, number, number]; label: string; confidence?: number;
60
+ content: {type: 'text'; text: string} | {type: 'heading'; level: number; text: string}
61
+ | {type: 'formula'; tex: string} | {type: 'figure'; description: string}
62
+ | {type: 'table'; rows: {text: string; col_span: number; row_span: number}[][]; header_rows: number};
63
+ }
64
+ export type OcrOutput = {type: 'text'; value: string}
65
+ | {type: 'lines'; value: {image_size: [number, number]; lines: OcrLine[]}}
66
+ | {type: 'regions'; value: {image_size: [number, number]; regions: OcrRegion[]}};
67
+ export interface OcrPages { page_count: number; pages: {page: number; output: OcrOutput}[] }
68
+ export function parseWithOcr(bytes: Uint8Array, evidence: OcrPages, options?: Options, budget?: OcrBudget): Conversion;
package/index.js ADDED
@@ -0,0 +1,48 @@
1
+ import init, { parseJson, parseWithOcrJson, inspectPdfJson, capabilitiesJson } from './pkg/bulkparse_wasm.js';
2
+ export { init };
3
+
4
+ export function parse(bytes, options = {}) { return run(bytes, options, false); }
5
+ export function inspectPdf(bytes, options = {}) { return run(bytes, options, true); }
6
+ function run(bytes, options, inspect) {
7
+ if (!(bytes instanceof Uint8Array)) throw new TypeError('bytes must be a Uint8Array');
8
+ const { filename, ...config } = options;
9
+ const cap = config.limits?.max_input_bytes ?? 33554432;
10
+ if (!Number.isSafeInteger(cap) || cap < 0) throw new TypeError('max_input_bytes must be a nonnegative safe integer');
11
+ if (bytes.byteLength > cap) {
12
+ const error = new Error('resource limit exceeded: max_input_bytes');
13
+ error.code = 'resource_limit';
14
+ throw error;
15
+ }
16
+ try { return JSON.parse(inspect ? inspectPdfJson(bytes, JSON.stringify(config)) : parseJson(bytes, filename, JSON.stringify(config))); }
17
+ catch (failure) {
18
+ let detail;
19
+ try { detail = JSON.parse(String(failure)); } catch { throw failure; }
20
+ const error = new Error(detail.message);
21
+ error.name = 'BulkParseError';
22
+ error.code = detail.code;
23
+ throw error;
24
+ }
25
+ }
26
+ export const capabilities = () => JSON.parse(capabilitiesJson());
27
+
28
+ /** Supply bounded OCR evidence produced by a browser/host engine. No inference runtime is bundled. */
29
+ export function parseWithOcr(bytes, evidence, options = {}, budget = {}) {
30
+ if (!(bytes instanceof Uint8Array)) throw new TypeError('bytes must be a Uint8Array');
31
+ const cap = options.limits?.max_input_bytes ?? 33554432;
32
+ if (!Number.isSafeInteger(cap) || cap < 0) throw new TypeError('max_input_bytes must be a nonnegative safe integer');
33
+ if (bytes.byteLength > cap) {
34
+ const error = new Error('resource limit exceeded: max_input_bytes');
35
+ error.code = 'resource_limit';
36
+ throw error;
37
+ }
38
+ const {filename, ...config} = options;
39
+ try { return JSON.parse(parseWithOcrJson(bytes, JSON.stringify(evidence), filename, JSON.stringify(config), JSON.stringify(budget))); }
40
+ catch (failure) {
41
+ let detail;
42
+ try { detail = JSON.parse(String(failure)); } catch { throw failure; }
43
+ const error = new Error(detail.message);
44
+ error.name = 'BulkParseError';
45
+ error.code = detail.code;
46
+ throw error;
47
+ }
48
+ }
package/package.json CHANGED
@@ -1,6 +1,31 @@
1
1
  {
2
2
  "name": "@bulkgrid/bulkparse-wasm",
3
- "version": "0.0.0-stage",
4
- "stub": true,
5
- "description": "Temporary package placeholder for staged publishing"
6
- }
3
+ "version": "0.1.1",
4
+ "type": "module",
5
+ "license": "MIT",
6
+ "exports": "./index.js",
7
+ "files": [
8
+ "index.js",
9
+ "index.d.ts",
10
+ "pkg/*.js",
11
+ "pkg/*.d.ts",
12
+ "pkg/*.wasm",
13
+ "README.md",
14
+ "LICENSE"
15
+ ],
16
+ "scripts": {
17
+ "build": "node scripts/build.mjs",
18
+ "test": "node test/smoke.mjs",
19
+ "prepack": "node scripts/prepare-package.mjs",
20
+ "test:package": "node test/package.mjs"
21
+ },
22
+ "types": "index.d.ts",
23
+ "repository": {
24
+ "type": "git",
25
+ "url": "https://github.com/bulkgrid/bulkparse.git",
26
+ "directory": "bindings/wasm"
27
+ },
28
+ "publishConfig": {
29
+ "access": "public"
30
+ }
31
+ }
package/pkg/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2026 BulkParse contributors
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/pkg/README.md ADDED
@@ -0,0 +1,57 @@
1
+ # BulkParse for browsers
2
+
3
+ Install the browser package with:
4
+
5
+ ```sh
6
+ npm install @bulkgrid/bulkparse-wasm
7
+ ```
8
+
9
+ Rust and wasm-pack are only needed to build from source. From this folder:
10
+
11
+ ```sh
12
+ rustup target add wasm32-unknown-unknown
13
+ cargo install wasm-pack --locked
14
+ npm run build
15
+ npm test
16
+ npm run test:package
17
+ python3 -m http.server 8080
18
+ ```
19
+
20
+ Open `http://localhost:8080/example/` for local file conversion in a Web Worker. The sample refuses files over 32 MiB, transfers input bytes to the worker, and displays output as text. It never uploads the chosen file. The main conversion API is synchronous; use a worker for larger inputs and terminate/recreate it to enforce a host timeout.
21
+
22
+ ```js
23
+ import {init, parse} from '@bulkgrid/bulkparse-wasm';
24
+ await init();
25
+ const result = parse(new TextEncoder().encode('# Hello'), {filename: 'hello.md'});
26
+ console.log(result.markdown);
27
+ ```
28
+
29
+ Serve the generated `.wasm` with MIME type `application/wasm`. WASM exports no file-path or network fetching API. The current build enables DOCX and positioned native-text PDF with heuristic column/directional ordering. No OCR engine or learned layout model is included; page-level diagnostics identify image-only OCR candidates. The current release WASM binary is 2,540,071 bytes (923,087 bytes with gzip level 9). Smoke tests and DOCX conversion in the in-app browser pass; broader browser compatibility is not yet established. Byte copies and JSON serialization still consume memory; the parser limits are not a hard memory sandbox.
30
+
31
+ `capabilities()` and output types match the native bindings. Bundlers can import the package wrapper; the generated `pkg` directory must be included with it. Package-level TypeScript declarations describe the same model as Node.
32
+
33
+
34
+ For offline builds, first install a `wasm-bindgen-cli` version matching the resolved `wasm-bindgen` dependency in Cargo.lock (currently `0.2.130`):
35
+
36
+ ```sh
37
+ cargo install wasm-bindgen-cli --version 0.2.130 --locked
38
+ CARGO_NET_OFFLINE=true npm run build
39
+ ```
40
+
41
+ The build script uses a workspace-local tool cache unless `WASM_PACK_CACHE` is set. It keeps WASM target metadata needed by wasm-bindgen. Packaging checks require the generated JS, TypeScript and WASM assets and override wasm-pack's generated ignore rule so npm includes the engine. `npm run test:package` packs the wrapper, installs that tarball in a temporary directory without network access, and converts DOCX through the installed package. No package is published by these commands.
42
+
43
+ CSV supports automatic comma/semicolon/tab/pipe detection and BOM-aware UTF-8/UTF-16 decoding. Without a BOM or explicit encoding, valid UTF-8 is preserved; otherwise legacy Windows-1252 decoding is attempted and reported with a `csv_encoding_inferred` diagnostic. Encoding inference is ambiguous, particularly for mixed-encoding files. Set `csv_encoding` to `utf8` for strict UTF-8, `windows1252` for a known legacy export, or `utf16_le` / `utf16_be` for BOM-less UTF-16. Explicit encodings must agree with any BOM. Undefined Windows-1252 bytes and binary controls are rejected. For delimiter ambiguity, pass `csv_delimiter` (one ASCII character); headers remain explicit through `csv_has_headers`.
44
+
45
+ PDFs support conservative ruled-table reconstruction. Arabic presentation forms and alphabetic ligatures expand by default. Pass `pdf_normalize_unicode: false` (Python: `pdf_normalize_unicode=False`) to retain mapped forms. `ActualText` is always preserved. See the root `docs/pdf-tables.md` for limits and validation.
46
+
47
+ PDF inspection is available without an OCR runtime: `inspectPdf(bytes)`. Conversion results also include `pdf_inspection`. The shared output schema is now 0.8. See [inspection and routing](../../docs/pdf-inspection.md).
48
+
49
+ The standard build enables BulkParse-owned Office/EPUB readers. See [format support and limits](../../docs/office-formats.md).
50
+
51
+ For resource-limited spreadsheets and CSV files, opt in to `partial_on_limit` (Python: `partial_on_limit=True`). Successful normal conversions are unchanged; supported limit failures can return an explicitly partial prefix within the original per-attempt budgets. This is not complete extraction and strict mode never accepts the recovery result. Inspect `status` and `resource_limit_partial` diagnostics. See [bounded large-document handling](../../docs/large-documents.md). Rebuild the binding to use this option.
52
+
53
+ Embedded image bytes are available in `document.assets` (base64 JSON). See [image retention, export and limitations](../../docs/images.md).
54
+
55
+ ## OCR and standalone images
56
+
57
+ See [OCR across language bindings](../../docs/ocr-bindings.md) for the shared evidence API, browser-hosted recognition, image/frame support, scanned-table limits, and examples.
@@ -0,0 +1,56 @@
1
+ /* tslint:disable */
2
+ /* eslint-disable */
3
+
4
+ export function capabilitiesJson(): string;
5
+
6
+ export function inspectPdfJson(bytes: Uint8Array | number[], options?: string | null): string;
7
+
8
+ /**
9
+ * JSON transport keeps nulls, tagged enums and integer fields identical to native bindings.
10
+ */
11
+ export function parseJson(bytes: Uint8Array | number[], filename?: string | null, options?: string | null): string;
12
+
13
+ /**
14
+ * OCR inference is supplied by the browser host; Rust validates and assembles it.
15
+ */
16
+ export function parseWithOcrJson(bytes: Uint8Array | number[], evidence: string, filename?: string | null, options?: string | null, budget?: string | null): string;
17
+
18
+ export type InitInput = RequestInfo | URL | Response | BufferSource | WebAssembly.Module;
19
+
20
+ export interface InitOutput {
21
+ readonly memory: WebAssembly.Memory;
22
+ readonly capabilitiesJson: () => [number, number];
23
+ readonly inspectPdfJson: (a: number, b: number, c: number, d: number) => [number, number, number, number];
24
+ readonly parseJson: (a: number, b: number, c: number, d: number, e: number, f: number) => [number, number, number, number];
25
+ readonly parseWithOcrJson: (a: number, b: number, c: number, d: number, e: number, f: number, g: number, h: number, i: number, j: number) => [number, number, number, number];
26
+ readonly __wbindgen_exn_store: (a: number) => void;
27
+ readonly __externref_table_alloc: () => number;
28
+ readonly __wbindgen_externrefs: WebAssembly.Table;
29
+ readonly __wbindgen_free: (a: number, b: number, c: number) => void;
30
+ readonly __wbindgen_malloc: (a: number, b: number) => number;
31
+ readonly __wbindgen_realloc: (a: number, b: number, c: number, d: number) => number;
32
+ readonly __externref_table_dealloc: (a: number) => void;
33
+ readonly __wbindgen_start: () => void;
34
+ }
35
+
36
+ export type SyncInitInput = BufferSource | WebAssembly.Module;
37
+
38
+ /**
39
+ * Instantiates the given `module`, which can either be bytes or
40
+ * a precompiled `WebAssembly.Module`.
41
+ *
42
+ * @param {{ module: SyncInitInput }} module - Passing `SyncInitInput` directly is deprecated.
43
+ *
44
+ * @returns {InitOutput}
45
+ */
46
+ export function initSync(module: { module: SyncInitInput } | SyncInitInput): InitOutput;
47
+
48
+ /**
49
+ * If `module_or_path` is {RequestInfo} or {URL}, makes a request and
50
+ * for everything else, calls `WebAssembly.instantiate` directly.
51
+ *
52
+ * @param {{ module_or_path: InitInput | Promise<InitInput> }} module_or_path - Passing `InitInput` directly is deprecated.
53
+ *
54
+ * @returns {Promise<InitOutput>}
55
+ */
56
+ export default function __wbg_init (module_or_path?: { module_or_path: InitInput | Promise<InitInput> } | InitInput | Promise<InitInput>): Promise<InitOutput>;
@@ -0,0 +1,389 @@
1
+ /* @ts-self-types="./bulkparse_wasm.d.ts" */
2
+
3
+ /**
4
+ * @returns {string}
5
+ */
6
+ export function capabilitiesJson() {
7
+ let deferred1_0;
8
+ let deferred1_1;
9
+ try {
10
+ const ret = wasm.capabilitiesJson();
11
+ deferred1_0 = ret[0];
12
+ deferred1_1 = ret[1];
13
+ return getStringFromWasm0(ret[0], ret[1]);
14
+ } finally {
15
+ wasm.__wbindgen_free(deferred1_0, deferred1_1, 1);
16
+ }
17
+ }
18
+
19
+ /**
20
+ * @param {Uint8Array | number[]} bytes
21
+ * @param {string | null} [options]
22
+ * @returns {string}
23
+ */
24
+ export function inspectPdfJson(bytes, options) {
25
+ let deferred4_0;
26
+ let deferred4_1;
27
+ try {
28
+ let ptr0, len0, ptr1, len1;
29
+ try {
30
+ ptr0 = passArray8ToWasm0(bytes, wasm.__wbindgen_malloc);
31
+ len0 = WASM_VECTOR_LEN;
32
+ ptr1 = isLikeNone(options) ? 0 : passStringToWasm0(options, wasm.__wbindgen_malloc, wasm.__wbindgen_realloc);
33
+ len1 = WASM_VECTOR_LEN;
34
+ } catch (e) {
35
+ if (ptr1) { wasm.__wbindgen_free(ptr1, len1 * 1, 1); }
36
+ if (ptr0) { wasm.__wbindgen_free(ptr0, len0 * 1, 1); }
37
+ throw e;
38
+ }
39
+ const ret = wasm.inspectPdfJson(ptr0, len0, ptr1, len1);
40
+ var ptr3 = ret[0];
41
+ var len3 = ret[1];
42
+ if (ret[3]) {
43
+ ptr3 = 0; len3 = 0;
44
+ throw takeFromExternrefTable0(ret[2]);
45
+ }
46
+ deferred4_0 = ptr3;
47
+ deferred4_1 = len3;
48
+ return getStringFromWasm0(ptr3, len3);
49
+ } finally {
50
+ wasm.__wbindgen_free(deferred4_0, deferred4_1, 1);
51
+ }
52
+ }
53
+
54
+ /**
55
+ * JSON transport keeps nulls, tagged enums and integer fields identical to native bindings.
56
+ * @param {Uint8Array | number[]} bytes
57
+ * @param {string | null} [filename]
58
+ * @param {string | null} [options]
59
+ * @returns {string}
60
+ */
61
+ export function parseJson(bytes, filename, options) {
62
+ let deferred5_0;
63
+ let deferred5_1;
64
+ try {
65
+ let ptr0, len0, ptr1, len1, ptr2, len2;
66
+ try {
67
+ ptr0 = passArray8ToWasm0(bytes, wasm.__wbindgen_malloc);
68
+ len0 = WASM_VECTOR_LEN;
69
+ ptr1 = isLikeNone(filename) ? 0 : passStringToWasm0(filename, wasm.__wbindgen_malloc, wasm.__wbindgen_realloc);
70
+ len1 = WASM_VECTOR_LEN;
71
+ ptr2 = isLikeNone(options) ? 0 : passStringToWasm0(options, wasm.__wbindgen_malloc, wasm.__wbindgen_realloc);
72
+ len2 = WASM_VECTOR_LEN;
73
+ } catch (e) {
74
+ if (ptr2) { wasm.__wbindgen_free(ptr2, len2 * 1, 1); }
75
+ if (ptr1) { wasm.__wbindgen_free(ptr1, len1 * 1, 1); }
76
+ if (ptr0) { wasm.__wbindgen_free(ptr0, len0 * 1, 1); }
77
+ throw e;
78
+ }
79
+ const ret = wasm.parseJson(ptr0, len0, ptr1, len1, ptr2, len2);
80
+ var ptr4 = ret[0];
81
+ var len4 = ret[1];
82
+ if (ret[3]) {
83
+ ptr4 = 0; len4 = 0;
84
+ throw takeFromExternrefTable0(ret[2]);
85
+ }
86
+ deferred5_0 = ptr4;
87
+ deferred5_1 = len4;
88
+ return getStringFromWasm0(ptr4, len4);
89
+ } finally {
90
+ wasm.__wbindgen_free(deferred5_0, deferred5_1, 1);
91
+ }
92
+ }
93
+
94
+ /**
95
+ * OCR inference is supplied by the browser host; Rust validates and assembles it.
96
+ * @param {Uint8Array | number[]} bytes
97
+ * @param {string} evidence
98
+ * @param {string | null} [filename]
99
+ * @param {string | null} [options]
100
+ * @param {string | null} [budget]
101
+ * @returns {string}
102
+ */
103
+ export function parseWithOcrJson(bytes, evidence, filename, options, budget) {
104
+ let deferred7_0;
105
+ let deferred7_1;
106
+ try {
107
+ let ptr0, len0, ptr1, len1, ptr2, len2, ptr3, len3, ptr4, len4;
108
+ try {
109
+ ptr0 = passArray8ToWasm0(bytes, wasm.__wbindgen_malloc);
110
+ len0 = WASM_VECTOR_LEN;
111
+ ptr1 = passStringToWasm0(evidence, wasm.__wbindgen_malloc, wasm.__wbindgen_realloc);
112
+ len1 = WASM_VECTOR_LEN;
113
+ ptr2 = isLikeNone(filename) ? 0 : passStringToWasm0(filename, wasm.__wbindgen_malloc, wasm.__wbindgen_realloc);
114
+ len2 = WASM_VECTOR_LEN;
115
+ ptr3 = isLikeNone(options) ? 0 : passStringToWasm0(options, wasm.__wbindgen_malloc, wasm.__wbindgen_realloc);
116
+ len3 = WASM_VECTOR_LEN;
117
+ ptr4 = isLikeNone(budget) ? 0 : passStringToWasm0(budget, wasm.__wbindgen_malloc, wasm.__wbindgen_realloc);
118
+ len4 = WASM_VECTOR_LEN;
119
+ } catch (e) {
120
+ if (ptr4) { wasm.__wbindgen_free(ptr4, len4 * 1, 1); }
121
+ if (ptr3) { wasm.__wbindgen_free(ptr3, len3 * 1, 1); }
122
+ if (ptr2) { wasm.__wbindgen_free(ptr2, len2 * 1, 1); }
123
+ if (ptr1) { wasm.__wbindgen_free(ptr1, len1 * 1, 1); }
124
+ if (ptr0) { wasm.__wbindgen_free(ptr0, len0 * 1, 1); }
125
+ throw e;
126
+ }
127
+ const ret = wasm.parseWithOcrJson(ptr0, len0, ptr1, len1, ptr2, len2, ptr3, len3, ptr4, len4);
128
+ var ptr6 = ret[0];
129
+ var len6 = ret[1];
130
+ if (ret[3]) {
131
+ ptr6 = 0; len6 = 0;
132
+ throw takeFromExternrefTable0(ret[2]);
133
+ }
134
+ deferred7_0 = ptr6;
135
+ deferred7_1 = len6;
136
+ return getStringFromWasm0(ptr6, len6);
137
+ } finally {
138
+ wasm.__wbindgen_free(deferred7_0, deferred7_1, 1);
139
+ }
140
+ }
141
+ function __wbg_get_imports() {
142
+ const import0 = {
143
+ __proto__: null,
144
+ __wbg___wbindgen_throw_4c88d8bf264fd984: function(arg0, arg1) {
145
+ throw new Error(getStringFromWasm0(arg0, arg1));
146
+ },
147
+ __wbg_getRandomValues_8b6f1f663e6f188d: function() { return handleError(function (arg0, arg1) {
148
+ globalThis.crypto.getRandomValues(getArrayU8FromWasm0(arg0, arg1));
149
+ }, arguments); },
150
+ __wbindgen_generic_0000000000000001: function(arg0, arg1) {
151
+ // Cast intrinsic for `Ref(String) -> Externref`.
152
+ const ret = getStringFromWasm0(arg0, arg1);
153
+ return ret;
154
+ },
155
+ __wbindgen_init_externref_table: function() {
156
+ const table = wasm.__wbindgen_externrefs;
157
+ table.set(0, undefined);
158
+ table.set(1024, undefined);
159
+ table.set(1025, null);
160
+ table.set(1026, true);
161
+ table.set(1027, false);
162
+ },
163
+ };
164
+ return {
165
+ __proto__: null,
166
+ "./bulkparse_wasm_bg.js": import0,
167
+ };
168
+ }
169
+
170
+ function addToExternrefTable0(obj) {
171
+ const idx = wasm.__externref_table_alloc();
172
+ wasm.__wbindgen_externrefs.set(idx, obj);
173
+ return idx;
174
+ }
175
+
176
+ function getArrayU8FromWasm0(ptr, len) {
177
+ ptr = ptr >>> 0;
178
+ return getUint8ArrayMemory0().subarray(ptr / 1, ptr / 1 + len);
179
+ }
180
+
181
+ function getStringFromWasm0(ptr, len) {
182
+ ptr = ptr >>> 0;
183
+ return decodeText(getUint8ArrayMemory0().subarray(ptr, ptr + len));
184
+ }
185
+
186
+ let cachedUint8ArrayMemory0 = null;
187
+ function getUint8ArrayMemory0() {
188
+ if (cachedUint8ArrayMemory0 === null || cachedUint8ArrayMemory0.byteLength === 0) {
189
+ cachedUint8ArrayMemory0 = new Uint8Array(wasm.memory.buffer);
190
+ }
191
+ return cachedUint8ArrayMemory0;
192
+ }
193
+
194
+ function handleError(f, args) {
195
+ try {
196
+ return f.apply(this, args);
197
+ } catch (e) {
198
+ const idx = addToExternrefTable0(e);
199
+ wasm.__wbindgen_exn_store(idx);
200
+ }
201
+ }
202
+
203
+ function isLikeNone(x) {
204
+ return x === undefined || x === null;
205
+ }
206
+
207
+ function passArray8ToWasm0(arg, malloc) {
208
+ const ptr = malloc(arg.length * 1, 1) >>> 0;
209
+ getUint8ArrayMemory0().set(arg, ptr / 1);
210
+ WASM_VECTOR_LEN = arg.length;
211
+ return ptr;
212
+ }
213
+
214
+ function passStringToWasm0(arg, malloc, realloc) {
215
+ if (realloc === undefined) {
216
+ const buf = cachedTextEncoder.encode(arg);
217
+ const ptr = malloc(buf.length, 1) >>> 0;
218
+ getUint8ArrayMemory0().subarray(ptr, ptr + buf.length).set(buf);
219
+ WASM_VECTOR_LEN = buf.length;
220
+ return ptr;
221
+ }
222
+
223
+ let len = arg.length;
224
+ let ptr = malloc(len, 1) >>> 0;
225
+
226
+ const mem = getUint8ArrayMemory0();
227
+
228
+ let offset = 0;
229
+
230
+ for (; offset < len; offset++) {
231
+ const code = arg.charCodeAt(offset);
232
+ if (code > 0x7F) break;
233
+ mem[ptr + offset] = code;
234
+ }
235
+ if (offset !== len) {
236
+ if (offset !== 0) {
237
+ arg = arg.slice(offset);
238
+ }
239
+ ptr = realloc(ptr, len, len = offset + arg.length * 3, 1) >>> 0;
240
+ const view = getUint8ArrayMemory0().subarray(ptr + offset, ptr + len);
241
+ const ret = cachedTextEncoder.encodeInto(arg, view);
242
+
243
+ offset += ret.written;
244
+ ptr = realloc(ptr, len, offset, 1) >>> 0;
245
+ }
246
+
247
+ WASM_VECTOR_LEN = offset;
248
+ return ptr;
249
+ }
250
+
251
+ function takeFromExternrefTable0(idx) {
252
+ const value = wasm.__wbindgen_externrefs.get(idx);
253
+ wasm.__externref_table_dealloc(idx);
254
+ return value;
255
+ }
256
+
257
+ let cachedTextDecoder = new TextDecoder('utf-8', { ignoreBOM: true });
258
+ cachedTextDecoder.decode();
259
+ const MAX_SAFARI_DECODE_BYTES = 2146435072;
260
+ let numBytesDecoded = 0;
261
+ function decodeText(bytes) {
262
+ numBytesDecoded += bytes.length;
263
+ if (numBytesDecoded >= MAX_SAFARI_DECODE_BYTES) {
264
+ cachedTextDecoder = new TextDecoder('utf-8', { ignoreBOM: true });
265
+ cachedTextDecoder.decode();
266
+ numBytesDecoded = bytes.length;
267
+ }
268
+ return cachedTextDecoder.decode(bytes);
269
+ }
270
+
271
+ const cachedTextEncoder = new TextEncoder();
272
+
273
+ if (!('encodeInto' in cachedTextEncoder)) {
274
+ cachedTextEncoder.encodeInto = function (arg, view) {
275
+ const buf = cachedTextEncoder.encode(arg);
276
+ view.set(buf);
277
+ return {
278
+ read: arg.length,
279
+ written: buf.length
280
+ };
281
+ };
282
+ }
283
+
284
+ let WASM_VECTOR_LEN = 0;
285
+
286
+ let wasmModule, wasmInstance, wasm;
287
+ function __wbg_finalize_init(instance, module) {
288
+ wasmInstance = instance;
289
+ wasm = instance.exports;
290
+ wasmModule = module;
291
+ cachedUint8ArrayMemory0 = null;
292
+ wasm.__wbindgen_start();
293
+ return wasm;
294
+ }
295
+
296
+ async function __wbg_load(module, imports) {
297
+ if (typeof Response === 'function' && module instanceof Response) {
298
+ if (!module.ok) {
299
+ throw new Error(`failed to fetch Wasm: ${module.status} ${module.statusText} fetching '${module.url}'`);
300
+ }
301
+
302
+ if (typeof WebAssembly.instantiateStreaming === 'function') {
303
+ try {
304
+ return await WebAssembly.instantiateStreaming(module, imports);
305
+ } catch (e) {
306
+ const validResponse = expectedResponseType(module.type);
307
+
308
+ if (validResponse && module.headers.get('Content-Type') !== 'application/wasm') {
309
+ console.warn("`WebAssembly.instantiateStreaming` failed because your server does not serve Wasm with `application/wasm` MIME type. Falling back to `WebAssembly.instantiate` which is slower. Original error:\n", e);
310
+
311
+ } else { throw e; }
312
+ }
313
+ }
314
+
315
+ const bytes = await module.arrayBuffer();
316
+ return await WebAssembly.instantiate(bytes, imports);
317
+ } else {
318
+ const instance = await WebAssembly.instantiate(module, imports);
319
+
320
+ if (instance instanceof WebAssembly.Instance) {
321
+ return { instance, module };
322
+ } else {
323
+ return instance;
324
+ }
325
+ }
326
+
327
+ function expectedResponseType(type) {
328
+ switch (type) {
329
+ case 'basic': case 'cors': case 'default': return true;
330
+ }
331
+ return false;
332
+ }
333
+ }
334
+
335
+ function initSync(module) {
336
+ if (wasm !== undefined) return wasm;
337
+
338
+
339
+ if (module !== undefined) {
340
+ if (Object.getPrototypeOf(module) === Object.prototype) {
341
+ ({module} = module)
342
+ } else {
343
+ console.warn('using deprecated parameters for `initSync()`; pass a single object instead')
344
+ }
345
+ }
346
+
347
+ const imports = __wbg_get_imports();
348
+ if (!(module instanceof WebAssembly.Module)) {
349
+ module = new WebAssembly.Module(module);
350
+ }
351
+ const instance = new WebAssembly.Instance(module, imports);
352
+ return __wbg_finalize_init(instance, module);
353
+ }
354
+
355
+ let __wbg_init_promise;
356
+ async function __wbg_init(module_or_path) {
357
+ if (wasm !== undefined) return wasm;
358
+ if (__wbg_init_promise === undefined) {
359
+ __wbg_init_promise = __wbg_init_once(module_or_path);
360
+ __wbg_init_promise.catch(() => { __wbg_init_promise = undefined; });
361
+ }
362
+ return __wbg_init_promise;
363
+ }
364
+
365
+ async function __wbg_init_once(module_or_path) {
366
+
367
+ if (module_or_path !== undefined) {
368
+ if (Object.getPrototypeOf(module_or_path) === Object.prototype) {
369
+ ({module_or_path} = module_or_path)
370
+ } else {
371
+ console.warn('using deprecated parameters for the initialization function; pass a single object instead')
372
+ }
373
+ }
374
+
375
+ if (module_or_path === undefined) {
376
+ module_or_path = new URL('bulkparse_wasm_bg.wasm', import.meta.url);
377
+ }
378
+ const imports = __wbg_get_imports();
379
+
380
+ if (typeof module_or_path === 'string' || (typeof Request === 'function' && module_or_path instanceof Request) || (typeof URL === 'function' && module_or_path instanceof URL)) {
381
+ module_or_path = fetch(module_or_path);
382
+ }
383
+
384
+ const { instance, module } = await __wbg_load(await module_or_path, imports);
385
+
386
+ return __wbg_finalize_init(instance, module);
387
+ }
388
+
389
+ export { initSync, __wbg_init as default };
Binary file
@@ -0,0 +1,15 @@
1
+ /* tslint:disable */
2
+ /* eslint-disable */
3
+ export const memory: WebAssembly.Memory;
4
+ export const capabilitiesJson: () => [number, number];
5
+ export const inspectPdfJson: (a: number, b: number, c: number, d: number) => [number, number, number, number];
6
+ export const parseJson: (a: number, b: number, c: number, d: number, e: number, f: number) => [number, number, number, number];
7
+ export const parseWithOcrJson: (a: number, b: number, c: number, d: number, e: number, f: number, g: number, h: number, i: number, j: number) => [number, number, number, number];
8
+ export const __wbindgen_exn_store: (a: number) => void;
9
+ export const __externref_table_alloc: () => number;
10
+ export const __wbindgen_externrefs: WebAssembly.Table;
11
+ export const __wbindgen_free: (a: number, b: number, c: number) => void;
12
+ export const __wbindgen_malloc: (a: number, b: number) => number;
13
+ export const __wbindgen_realloc: (a: number, b: number, c: number, d: number) => number;
14
+ export const __externref_table_dealloc: (a: number) => void;
15
+ export const __wbindgen_start: () => void;