@kreuzberg/wasm 4.0.0-rc.21 → 4.0.0-rc.24
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 +520 -837
- package/dist/adapters/wasm-adapter.d.ts +7 -10
- package/dist/adapters/wasm-adapter.d.ts.map +1 -0
- package/dist/adapters/wasm-adapter.js +41 -19
- package/dist/adapters/wasm-adapter.js.map +1 -1
- package/dist/index.d.ts +23 -24
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +240 -67
- package/dist/index.js.map +1 -1
- package/dist/ocr/registry.d.ts +7 -10
- package/dist/ocr/registry.d.ts.map +1 -0
- package/dist/ocr/registry.js.map +1 -1
- package/dist/ocr/tesseract-wasm-backend.d.ts +3 -6
- package/dist/ocr/tesseract-wasm-backend.d.ts.map +1 -0
- package/dist/ocr/tesseract-wasm-backend.js +0 -46
- package/dist/ocr/tesseract-wasm-backend.js.map +1 -1
- package/dist/pdfium.js +0 -5
- package/dist/plugin-registry.d.ts +246 -0
- package/dist/plugin-registry.d.ts.map +1 -0
- package/dist/runtime.d.ts +21 -22
- package/dist/runtime.d.ts.map +1 -0
- package/dist/runtime.js +0 -1
- package/dist/runtime.js.map +1 -1
- package/dist/{types-CKjcIYcX.d.ts → types.d.ts} +91 -22
- package/dist/types.d.ts.map +1 -0
- package/package.json +119 -162
- package/dist/adapters/wasm-adapter.cjs +0 -245
- package/dist/adapters/wasm-adapter.cjs.map +0 -1
- package/dist/adapters/wasm-adapter.d.cts +0 -121
- package/dist/index.cjs +0 -1245
- package/dist/index.cjs.map +0 -1
- package/dist/index.d.cts +0 -423
- package/dist/ocr/registry.cjs +0 -92
- package/dist/ocr/registry.cjs.map +0 -1
- package/dist/ocr/registry.d.cts +0 -102
- package/dist/ocr/tesseract-wasm-backend.cjs +0 -456
- package/dist/ocr/tesseract-wasm-backend.cjs.map +0 -1
- package/dist/ocr/tesseract-wasm-backend.d.cts +0 -257
- package/dist/runtime.cjs +0 -174
- package/dist/runtime.cjs.map +0 -1
- package/dist/runtime.d.cts +0 -256
- package/dist/types-CKjcIYcX.d.cts +0 -294
|
@@ -1,121 +0,0 @@
|
|
|
1
|
-
import { E as ExtractionConfig, a as ExtractionResult } from '../types-CKjcIYcX.cjs';
|
|
2
|
-
|
|
3
|
-
/**
|
|
4
|
-
* WASM Type Adapter
|
|
5
|
-
*
|
|
6
|
-
* This module provides type adapters for converting between JavaScript/TypeScript
|
|
7
|
-
* types and WASM-compatible types, handling File/Blob conversions, config normalization,
|
|
8
|
-
* and result parsing.
|
|
9
|
-
*
|
|
10
|
-
* @example File Conversion
|
|
11
|
-
* ```typescript
|
|
12
|
-
* import { fileToUint8Array } from '@kreuzberg/wasm/adapters/wasm-adapter';
|
|
13
|
-
*
|
|
14
|
-
* const file = event.target.files[0];
|
|
15
|
-
* const bytes = await fileToUint8Array(file);
|
|
16
|
-
* const result = await extractBytes(bytes, file.type);
|
|
17
|
-
* ```
|
|
18
|
-
*
|
|
19
|
-
* @example Config Normalization
|
|
20
|
-
* ```typescript
|
|
21
|
-
* import { configToJS } from '@kreuzberg/wasm/adapters/wasm-adapter';
|
|
22
|
-
*
|
|
23
|
-
* const config = {
|
|
24
|
-
* ocr: { backend: 'tesseract', language: 'eng' },
|
|
25
|
-
* chunking: { maxChars: 1000 }
|
|
26
|
-
* };
|
|
27
|
-
* const normalized = configToJS(config);
|
|
28
|
-
* ```
|
|
29
|
-
*/
|
|
30
|
-
|
|
31
|
-
/**
|
|
32
|
-
* Convert a File or Blob to Uint8Array
|
|
33
|
-
*
|
|
34
|
-
* Handles both browser File API and server-side Blob-like objects,
|
|
35
|
-
* providing a unified interface for reading binary data.
|
|
36
|
-
*
|
|
37
|
-
* @param file - The File or Blob to convert
|
|
38
|
-
* @returns Promise resolving to the byte array
|
|
39
|
-
* @throws {Error} If the file cannot be read or exceeds size limit
|
|
40
|
-
*
|
|
41
|
-
* @example
|
|
42
|
-
* ```typescript
|
|
43
|
-
* const file = document.getElementById('input').files[0];
|
|
44
|
-
* const bytes = await fileToUint8Array(file);
|
|
45
|
-
* const result = await extractBytes(bytes, 'application/pdf');
|
|
46
|
-
* ```
|
|
47
|
-
*/
|
|
48
|
-
declare function fileToUint8Array(file: File | Blob): Promise<Uint8Array>;
|
|
49
|
-
/**
|
|
50
|
-
* Normalize ExtractionConfig for WASM processing
|
|
51
|
-
*
|
|
52
|
-
* Converts TypeScript configuration objects to a WASM-compatible format,
|
|
53
|
-
* handling null values, undefined properties, and nested structures.
|
|
54
|
-
*
|
|
55
|
-
* @param config - The extraction configuration or null
|
|
56
|
-
* @returns Normalized configuration object suitable for WASM
|
|
57
|
-
*
|
|
58
|
-
* @example
|
|
59
|
-
* ```typescript
|
|
60
|
-
* const config: ExtractionConfig = {
|
|
61
|
-
* ocr: { backend: 'tesseract' },
|
|
62
|
-
* chunking: { maxChars: 1000 }
|
|
63
|
-
* };
|
|
64
|
-
* const wasmConfig = configToJS(config);
|
|
65
|
-
* ```
|
|
66
|
-
*/
|
|
67
|
-
declare function configToJS(config: ExtractionConfig | null): Record<string, unknown>;
|
|
68
|
-
/**
|
|
69
|
-
* Parse WASM extraction result and convert to TypeScript type
|
|
70
|
-
*
|
|
71
|
-
* Handles conversion of WASM-returned objects to proper ExtractionResult types,
|
|
72
|
-
* including proper array conversions and type assertions for tables, chunks, and images.
|
|
73
|
-
*
|
|
74
|
-
* @param jsValue - The raw WASM result value
|
|
75
|
-
* @returns Properly typed ExtractionResult
|
|
76
|
-
* @throws {Error} If the result structure is invalid
|
|
77
|
-
*
|
|
78
|
-
* @example
|
|
79
|
-
* ```typescript
|
|
80
|
-
* const wasmResult = await wasmExtract(bytes, mimeType, config);
|
|
81
|
-
* const result = jsToExtractionResult(wasmResult);
|
|
82
|
-
* console.log(result.content);
|
|
83
|
-
* ```
|
|
84
|
-
*/
|
|
85
|
-
declare function jsToExtractionResult(jsValue: unknown): ExtractionResult;
|
|
86
|
-
/**
|
|
87
|
-
* Wrap and format WASM errors with context
|
|
88
|
-
*
|
|
89
|
-
* Converts WASM error messages to JavaScript Error objects with proper context
|
|
90
|
-
* and stack trace information when available.
|
|
91
|
-
*
|
|
92
|
-
* @param error - The error from WASM
|
|
93
|
-
* @param context - Additional context about what operation failed
|
|
94
|
-
* @returns A formatted Error object
|
|
95
|
-
*
|
|
96
|
-
* @internal
|
|
97
|
-
*
|
|
98
|
-
* @example
|
|
99
|
-
* ```typescript
|
|
100
|
-
* try {
|
|
101
|
-
* await wasmExtract(bytes, mimeType);
|
|
102
|
-
* } catch (error) {
|
|
103
|
-
* throw wrapWasmError(error, 'extracting document');
|
|
104
|
-
* }
|
|
105
|
-
* ```
|
|
106
|
-
*/
|
|
107
|
-
declare function wrapWasmError(error: unknown, context: string): Error;
|
|
108
|
-
/**
|
|
109
|
-
* Validate that a WASM-returned value conforms to ExtractionResult structure
|
|
110
|
-
*
|
|
111
|
-
* Performs structural validation without full type checking,
|
|
112
|
-
* useful for runtime validation of WASM output.
|
|
113
|
-
*
|
|
114
|
-
* @param value - The value to validate
|
|
115
|
-
* @returns True if value appears to be a valid ExtractionResult
|
|
116
|
-
*
|
|
117
|
-
* @internal
|
|
118
|
-
*/
|
|
119
|
-
declare function isValidExtractionResult(value: unknown): value is ExtractionResult;
|
|
120
|
-
|
|
121
|
-
export { configToJS, fileToUint8Array, isValidExtractionResult, jsToExtractionResult, wrapWasmError };
|