@kreuzberg/wasm 4.0.0-rc.6
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 +982 -0
- package/dist/adapters/wasm-adapter.d.mts +121 -0
- package/dist/adapters/wasm-adapter.d.ts +121 -0
- package/dist/adapters/wasm-adapter.js +241 -0
- package/dist/adapters/wasm-adapter.js.map +1 -0
- package/dist/adapters/wasm-adapter.mjs +221 -0
- package/dist/adapters/wasm-adapter.mjs.map +1 -0
- package/dist/index.d.mts +466 -0
- package/dist/index.d.ts +466 -0
- package/dist/index.js +383 -0
- package/dist/index.js.map +1 -0
- package/dist/index.mjs +384 -0
- package/dist/index.mjs.map +1 -0
- package/dist/kreuzberg_wasm.d.mts +758 -0
- package/dist/kreuzberg_wasm.d.ts +758 -0
- package/dist/kreuzberg_wasm.js +1913 -0
- package/dist/kreuzberg_wasm.mjs +48 -0
- package/dist/kreuzberg_wasm_bg.wasm +0 -0
- package/dist/kreuzberg_wasm_bg.wasm.d.ts +54 -0
- package/dist/ocr/registry.d.mts +102 -0
- package/dist/ocr/registry.d.ts +102 -0
- package/dist/ocr/registry.js +90 -0
- package/dist/ocr/registry.js.map +1 -0
- package/dist/ocr/registry.mjs +70 -0
- package/dist/ocr/registry.mjs.map +1 -0
- package/dist/ocr/tesseract-wasm-backend.d.mts +257 -0
- package/dist/ocr/tesseract-wasm-backend.d.ts +257 -0
- package/dist/ocr/tesseract-wasm-backend.js +454 -0
- package/dist/ocr/tesseract-wasm-backend.js.map +1 -0
- package/dist/ocr/tesseract-wasm-backend.mjs +424 -0
- package/dist/ocr/tesseract-wasm-backend.mjs.map +1 -0
- package/dist/runtime.d.mts +256 -0
- package/dist/runtime.d.ts +256 -0
- package/dist/runtime.js +172 -0
- package/dist/runtime.js.map +1 -0
- package/dist/runtime.mjs +152 -0
- package/dist/runtime.mjs.map +1 -0
- package/dist/snippets/wasm-bindgen-rayon-38edf6e439f6d70d/src/workerHelpers.js +107 -0
- package/dist/types-GJVIvbPy.d.mts +221 -0
- package/dist/types-GJVIvbPy.d.ts +221 -0
- package/package.json +138 -0
|
@@ -0,0 +1,424 @@
|
|
|
1
|
+
class TesseractWasmBackend {
|
|
2
|
+
/** Tesseract WASM client instance */
|
|
3
|
+
client = null;
|
|
4
|
+
/** Track which models are currently loaded to avoid redundant loads */
|
|
5
|
+
loadedLanguages = /* @__PURE__ */ new Set();
|
|
6
|
+
/** Cache for language availability validation */
|
|
7
|
+
supportedLangsCache = null;
|
|
8
|
+
/** Progress callback for UI updates */
|
|
9
|
+
progressCallback = null;
|
|
10
|
+
/** Base URL for training data CDN */
|
|
11
|
+
CDN_BASE_URL = "https://cdn.jsdelivr.net/npm/tesseract-wasm@0.11.0/dist";
|
|
12
|
+
/**
|
|
13
|
+
* Return the unique name of this OCR backend
|
|
14
|
+
*
|
|
15
|
+
* @returns Backend identifier "tesseract-wasm"
|
|
16
|
+
*/
|
|
17
|
+
name() {
|
|
18
|
+
return "tesseract-wasm";
|
|
19
|
+
}
|
|
20
|
+
/**
|
|
21
|
+
* Return list of supported language codes
|
|
22
|
+
*
|
|
23
|
+
* Returns a curated list of commonly available Tesseract language models.
|
|
24
|
+
* Tesseract supports many more languages through custom models.
|
|
25
|
+
*
|
|
26
|
+
* @returns Array of ISO 639-1/2/3 language codes
|
|
27
|
+
*/
|
|
28
|
+
supportedLanguages() {
|
|
29
|
+
if (this.supportedLangsCache) {
|
|
30
|
+
return this.supportedLangsCache;
|
|
31
|
+
}
|
|
32
|
+
this.supportedLangsCache = [
|
|
33
|
+
// Major languages
|
|
34
|
+
"eng",
|
|
35
|
+
// English
|
|
36
|
+
"deu",
|
|
37
|
+
// German
|
|
38
|
+
"fra",
|
|
39
|
+
// French
|
|
40
|
+
"spa",
|
|
41
|
+
// Spanish
|
|
42
|
+
"ita",
|
|
43
|
+
// Italian
|
|
44
|
+
"por",
|
|
45
|
+
// Portuguese
|
|
46
|
+
"nld",
|
|
47
|
+
// Dutch
|
|
48
|
+
"rus",
|
|
49
|
+
// Russian
|
|
50
|
+
"jpn",
|
|
51
|
+
// Japanese
|
|
52
|
+
"kor",
|
|
53
|
+
// Korean
|
|
54
|
+
"chi_sim",
|
|
55
|
+
// Chinese (Simplified)
|
|
56
|
+
"chi_tra",
|
|
57
|
+
// Chinese (Traditional)
|
|
58
|
+
// Additional European languages
|
|
59
|
+
"pol",
|
|
60
|
+
// Polish
|
|
61
|
+
"tur",
|
|
62
|
+
// Turkish
|
|
63
|
+
"swe",
|
|
64
|
+
// Swedish
|
|
65
|
+
"dan",
|
|
66
|
+
// Danish
|
|
67
|
+
"fin",
|
|
68
|
+
// Finnish
|
|
69
|
+
"nor",
|
|
70
|
+
// Norwegian
|
|
71
|
+
"ces",
|
|
72
|
+
// Czech
|
|
73
|
+
"slk",
|
|
74
|
+
// Slovak
|
|
75
|
+
"ron",
|
|
76
|
+
// Romanian
|
|
77
|
+
"hun",
|
|
78
|
+
// Hungarian
|
|
79
|
+
"hrv",
|
|
80
|
+
// Croatian
|
|
81
|
+
"srp",
|
|
82
|
+
// Serbian
|
|
83
|
+
"bul",
|
|
84
|
+
// Bulgarian
|
|
85
|
+
"ukr",
|
|
86
|
+
// Ukrainian
|
|
87
|
+
"ell",
|
|
88
|
+
// Greek
|
|
89
|
+
// Asian languages
|
|
90
|
+
"ara",
|
|
91
|
+
// Arabic
|
|
92
|
+
"heb",
|
|
93
|
+
// Hebrew
|
|
94
|
+
"hin",
|
|
95
|
+
// Hindi
|
|
96
|
+
"tha",
|
|
97
|
+
// Thai
|
|
98
|
+
"vie",
|
|
99
|
+
// Vietnamese
|
|
100
|
+
"mkd",
|
|
101
|
+
// Macedonian
|
|
102
|
+
"ben",
|
|
103
|
+
// Bengali
|
|
104
|
+
"tam",
|
|
105
|
+
// Tamil
|
|
106
|
+
"tel",
|
|
107
|
+
// Telugu
|
|
108
|
+
"kan",
|
|
109
|
+
// Kannada
|
|
110
|
+
"mal",
|
|
111
|
+
// Malayalam
|
|
112
|
+
"mya",
|
|
113
|
+
// Burmese
|
|
114
|
+
"khm",
|
|
115
|
+
// Khmer
|
|
116
|
+
"lao",
|
|
117
|
+
// Lao
|
|
118
|
+
"sin"
|
|
119
|
+
// Sinhala
|
|
120
|
+
];
|
|
121
|
+
return this.supportedLangsCache;
|
|
122
|
+
}
|
|
123
|
+
/**
|
|
124
|
+
* Initialize the OCR backend
|
|
125
|
+
*
|
|
126
|
+
* Creates the Tesseract WASM client instance. This is called once when
|
|
127
|
+
* the backend is registered with the extraction pipeline.
|
|
128
|
+
*
|
|
129
|
+
* The actual model loading happens in processImage() on-demand to avoid
|
|
130
|
+
* loading all models upfront.
|
|
131
|
+
*
|
|
132
|
+
* @throws {Error} If tesseract-wasm is not available or initialization fails
|
|
133
|
+
*
|
|
134
|
+
* @example
|
|
135
|
+
* ```typescript
|
|
136
|
+
* const backend = new TesseractWasmBackend();
|
|
137
|
+
* try {
|
|
138
|
+
* await backend.initialize();
|
|
139
|
+
* } catch (error) {
|
|
140
|
+
* console.error('Failed to initialize OCR:', error);
|
|
141
|
+
* }
|
|
142
|
+
* ```
|
|
143
|
+
*/
|
|
144
|
+
async initialize() {
|
|
145
|
+
if (this.client) {
|
|
146
|
+
return;
|
|
147
|
+
}
|
|
148
|
+
try {
|
|
149
|
+
const tesseractModule = await this.loadTesseractWasm();
|
|
150
|
+
if (!tesseractModule || typeof tesseractModule.OCRClient !== "function") {
|
|
151
|
+
throw new Error("tesseract-wasm OCRClient not found. Ensure tesseract-wasm is installed and available.");
|
|
152
|
+
}
|
|
153
|
+
this.client = new tesseractModule.OCRClient();
|
|
154
|
+
this.loadedLanguages.clear();
|
|
155
|
+
} catch (error) {
|
|
156
|
+
const message = error instanceof Error ? error.message : String(error);
|
|
157
|
+
throw new Error(`Failed to initialize TesseractWasmBackend: ${message}`);
|
|
158
|
+
}
|
|
159
|
+
}
|
|
160
|
+
/**
|
|
161
|
+
* Process image bytes and extract text via OCR
|
|
162
|
+
*
|
|
163
|
+
* Handles image loading, model loading, OCR processing, and result formatting.
|
|
164
|
+
* Automatically loads the language model on first use and caches it for subsequent calls.
|
|
165
|
+
*
|
|
166
|
+
* @param imageBytes - Raw image data (Uint8Array) or Base64-encoded string
|
|
167
|
+
* @param language - ISO 639-2/3 language code (e.g., "eng", "deu")
|
|
168
|
+
* @returns Promise resolving to OCR result with content and metadata
|
|
169
|
+
* @throws {Error} If image processing fails, model loading fails, or language is unsupported
|
|
170
|
+
*
|
|
171
|
+
* @example
|
|
172
|
+
* ```typescript
|
|
173
|
+
* const backend = new TesseractWasmBackend();
|
|
174
|
+
* await backend.initialize();
|
|
175
|
+
*
|
|
176
|
+
* const imageBuffer = fs.readFileSync('scanned.png');
|
|
177
|
+
* const result = await backend.processImage(
|
|
178
|
+
* new Uint8Array(imageBuffer),
|
|
179
|
+
* 'eng'
|
|
180
|
+
* );
|
|
181
|
+
*
|
|
182
|
+
* console.log(result.content); // Extracted text
|
|
183
|
+
* console.log(result.metadata.confidence); // OCR confidence score
|
|
184
|
+
* ```
|
|
185
|
+
*/
|
|
186
|
+
async processImage(imageBytes, language) {
|
|
187
|
+
if (!this.client) {
|
|
188
|
+
throw new Error("TesseractWasmBackend not initialized. Call initialize() first.");
|
|
189
|
+
}
|
|
190
|
+
const supported = this.supportedLanguages();
|
|
191
|
+
const normalizedLang = language.toLowerCase();
|
|
192
|
+
const isSupported = supported.some((lang) => lang.toLowerCase() === normalizedLang);
|
|
193
|
+
if (!isSupported) {
|
|
194
|
+
throw new Error(`Language "${language}" is not supported. Supported languages: ${supported.join(", ")}`);
|
|
195
|
+
}
|
|
196
|
+
try {
|
|
197
|
+
if (!this.loadedLanguages.has(normalizedLang)) {
|
|
198
|
+
this.reportProgress(10);
|
|
199
|
+
await this.loadLanguageModel(normalizedLang);
|
|
200
|
+
this.loadedLanguages.add(normalizedLang);
|
|
201
|
+
this.reportProgress(30);
|
|
202
|
+
}
|
|
203
|
+
this.reportProgress(40);
|
|
204
|
+
const imageBitmap = await this.convertToImageBitmap(imageBytes);
|
|
205
|
+
this.reportProgress(50);
|
|
206
|
+
await this.client.loadImage(imageBitmap);
|
|
207
|
+
this.reportProgress(70);
|
|
208
|
+
const text = await this.client.getText();
|
|
209
|
+
const confidence = await this.getConfidenceScore();
|
|
210
|
+
const pageMetadata = await this.getPageMetadata();
|
|
211
|
+
this.reportProgress(90);
|
|
212
|
+
return {
|
|
213
|
+
content: text,
|
|
214
|
+
mime_type: "text/plain",
|
|
215
|
+
metadata: {
|
|
216
|
+
language: normalizedLang,
|
|
217
|
+
confidence,
|
|
218
|
+
...pageMetadata
|
|
219
|
+
},
|
|
220
|
+
tables: []
|
|
221
|
+
// Tesseract-wasm doesn't provide structured table detection
|
|
222
|
+
};
|
|
223
|
+
} catch (error) {
|
|
224
|
+
const message = error instanceof Error ? error.message : String(error);
|
|
225
|
+
throw new Error(`OCR processing failed for language "${language}": ${message}`);
|
|
226
|
+
} finally {
|
|
227
|
+
this.reportProgress(100);
|
|
228
|
+
}
|
|
229
|
+
}
|
|
230
|
+
/**
|
|
231
|
+
* Shutdown the OCR backend and release resources
|
|
232
|
+
*
|
|
233
|
+
* Properly cleans up the Tesseract WASM client, freeing memory and Web Workers.
|
|
234
|
+
* Called when the backend is unregistered or the application shuts down.
|
|
235
|
+
*
|
|
236
|
+
* @throws {Error} If cleanup fails (errors are logged but not critical)
|
|
237
|
+
*
|
|
238
|
+
* @example
|
|
239
|
+
* ```typescript
|
|
240
|
+
* const backend = new TesseractWasmBackend();
|
|
241
|
+
* await backend.initialize();
|
|
242
|
+
* // ... use backend ...
|
|
243
|
+
* await backend.shutdown(); // Clean up resources
|
|
244
|
+
* ```
|
|
245
|
+
*/
|
|
246
|
+
async shutdown() {
|
|
247
|
+
try {
|
|
248
|
+
if (this.client) {
|
|
249
|
+
if (typeof this.client.destroy === "function") {
|
|
250
|
+
this.client.destroy();
|
|
251
|
+
}
|
|
252
|
+
if (typeof this.client.terminate === "function") {
|
|
253
|
+
this.client.terminate();
|
|
254
|
+
}
|
|
255
|
+
this.client = null;
|
|
256
|
+
}
|
|
257
|
+
this.loadedLanguages.clear();
|
|
258
|
+
this.supportedLangsCache = null;
|
|
259
|
+
this.progressCallback = null;
|
|
260
|
+
} catch (error) {
|
|
261
|
+
console.warn(
|
|
262
|
+
`Warning during TesseractWasmBackend shutdown: ${error instanceof Error ? error.message : String(error)}`
|
|
263
|
+
);
|
|
264
|
+
}
|
|
265
|
+
}
|
|
266
|
+
/**
|
|
267
|
+
* Set a progress callback for UI updates
|
|
268
|
+
*
|
|
269
|
+
* Allows the UI to display progress during OCR processing.
|
|
270
|
+
* The callback will be called with values from 0 to 100.
|
|
271
|
+
*
|
|
272
|
+
* @param callback - Function to call with progress percentage
|
|
273
|
+
*
|
|
274
|
+
* @example
|
|
275
|
+
* ```typescript
|
|
276
|
+
* const backend = new TesseractWasmBackend();
|
|
277
|
+
* backend.setProgressCallback((progress) => {
|
|
278
|
+
* console.log(`OCR Progress: ${progress}%`);
|
|
279
|
+
* document.getElementById('progress-bar').style.width = `${progress}%`;
|
|
280
|
+
* });
|
|
281
|
+
* ```
|
|
282
|
+
*/
|
|
283
|
+
setProgressCallback(callback) {
|
|
284
|
+
this.progressCallback = callback;
|
|
285
|
+
}
|
|
286
|
+
/**
|
|
287
|
+
* Load language model from CDN
|
|
288
|
+
*
|
|
289
|
+
* Fetches the training data for a specific language from jsDelivr CDN.
|
|
290
|
+
* This is an MVP approach - models are cached by the browser.
|
|
291
|
+
*
|
|
292
|
+
* @param language - ISO 639-2/3 language code
|
|
293
|
+
* @throws {Error} If model download fails or language is not available
|
|
294
|
+
*
|
|
295
|
+
* @internal
|
|
296
|
+
*/
|
|
297
|
+
async loadLanguageModel(language) {
|
|
298
|
+
if (!this.client) {
|
|
299
|
+
throw new Error("Client not initialized");
|
|
300
|
+
}
|
|
301
|
+
const modelFilename = `${language}.traineddata`;
|
|
302
|
+
const modelUrl = `${this.CDN_BASE_URL}/${modelFilename}`;
|
|
303
|
+
try {
|
|
304
|
+
await this.client.loadModel(modelUrl);
|
|
305
|
+
} catch (error) {
|
|
306
|
+
const message = error instanceof Error ? error.message : String(error);
|
|
307
|
+
throw new Error(`Failed to load model for language "${language}" from ${modelUrl}: ${message}`);
|
|
308
|
+
}
|
|
309
|
+
}
|
|
310
|
+
/**
|
|
311
|
+
* Convert image bytes or Base64 string to ImageBitmap
|
|
312
|
+
*
|
|
313
|
+
* Handles both Uint8Array and Base64-encoded image data, converting to
|
|
314
|
+
* ImageBitmap format required by Tesseract WASM.
|
|
315
|
+
*
|
|
316
|
+
* @param imageBytes - Image data as Uint8Array or Base64 string
|
|
317
|
+
* @returns Promise resolving to ImageBitmap
|
|
318
|
+
* @throws {Error} If conversion fails (browser API not available or invalid image data)
|
|
319
|
+
*
|
|
320
|
+
* @internal
|
|
321
|
+
*/
|
|
322
|
+
async convertToImageBitmap(imageBytes) {
|
|
323
|
+
if (typeof createImageBitmap === "undefined") {
|
|
324
|
+
throw new Error("createImageBitmap is not available. TesseractWasmBackend requires a browser environment.");
|
|
325
|
+
}
|
|
326
|
+
try {
|
|
327
|
+
let bytes = imageBytes;
|
|
328
|
+
if (typeof imageBytes === "string") {
|
|
329
|
+
const binaryString = atob(imageBytes);
|
|
330
|
+
bytes = new Uint8Array(binaryString.length);
|
|
331
|
+
for (let i = 0; i < binaryString.length; i++) {
|
|
332
|
+
bytes[i] = binaryString.charCodeAt(i);
|
|
333
|
+
}
|
|
334
|
+
}
|
|
335
|
+
const blob = new Blob([bytes]);
|
|
336
|
+
const imageBitmap = await createImageBitmap(blob);
|
|
337
|
+
return imageBitmap;
|
|
338
|
+
} catch (error) {
|
|
339
|
+
const message = error instanceof Error ? error.message : String(error);
|
|
340
|
+
throw new Error(`Failed to convert image bytes to ImageBitmap: ${message}`);
|
|
341
|
+
}
|
|
342
|
+
}
|
|
343
|
+
/**
|
|
344
|
+
* Get confidence score from OCR result
|
|
345
|
+
*
|
|
346
|
+
* Attempts to retrieve confidence score from Tesseract.
|
|
347
|
+
* Returns a safe default if unavailable.
|
|
348
|
+
*
|
|
349
|
+
* @returns Confidence score between 0 and 1
|
|
350
|
+
*
|
|
351
|
+
* @internal
|
|
352
|
+
*/
|
|
353
|
+
async getConfidenceScore() {
|
|
354
|
+
try {
|
|
355
|
+
if (this.client && typeof this.client.getConfidence === "function") {
|
|
356
|
+
const confidence = await this.client.getConfidence();
|
|
357
|
+
return confidence > 1 ? confidence / 100 : confidence;
|
|
358
|
+
}
|
|
359
|
+
} catch {
|
|
360
|
+
}
|
|
361
|
+
return 0.9;
|
|
362
|
+
}
|
|
363
|
+
/**
|
|
364
|
+
* Get page metadata from OCR result
|
|
365
|
+
*
|
|
366
|
+
* Retrieves additional metadata like image dimensions and processing info.
|
|
367
|
+
*
|
|
368
|
+
* @returns Metadata object (may be empty if unavailable)
|
|
369
|
+
*
|
|
370
|
+
* @internal
|
|
371
|
+
*/
|
|
372
|
+
async getPageMetadata() {
|
|
373
|
+
try {
|
|
374
|
+
if (this.client && typeof this.client.getPageMetadata === "function") {
|
|
375
|
+
return await this.client.getPageMetadata();
|
|
376
|
+
}
|
|
377
|
+
} catch {
|
|
378
|
+
}
|
|
379
|
+
return {};
|
|
380
|
+
}
|
|
381
|
+
/**
|
|
382
|
+
* Dynamically load tesseract-wasm module
|
|
383
|
+
*
|
|
384
|
+
* Uses dynamic import to load tesseract-wasm only when needed,
|
|
385
|
+
* avoiding hard dependency in browser environments where it may not be bundled.
|
|
386
|
+
*
|
|
387
|
+
* @returns tesseract-wasm module object
|
|
388
|
+
* @throws {Error} If module cannot be imported
|
|
389
|
+
*
|
|
390
|
+
* @internal
|
|
391
|
+
*/
|
|
392
|
+
async loadTesseractWasm() {
|
|
393
|
+
try {
|
|
394
|
+
const module = await import("tesseract-wasm");
|
|
395
|
+
return module;
|
|
396
|
+
} catch (error) {
|
|
397
|
+
const message = error instanceof Error ? error.message : String(error);
|
|
398
|
+
throw new Error(
|
|
399
|
+
`Failed to import tesseract-wasm. Ensure it is installed via: npm install tesseract-wasm. Error: ${message}`
|
|
400
|
+
);
|
|
401
|
+
}
|
|
402
|
+
}
|
|
403
|
+
/**
|
|
404
|
+
* Report progress to progress callback
|
|
405
|
+
*
|
|
406
|
+
* Internal helper for notifying progress updates during OCR processing.
|
|
407
|
+
*
|
|
408
|
+
* @param progress - Progress percentage (0-100)
|
|
409
|
+
*
|
|
410
|
+
* @internal
|
|
411
|
+
*/
|
|
412
|
+
reportProgress(progress) {
|
|
413
|
+
if (this.progressCallback) {
|
|
414
|
+
try {
|
|
415
|
+
this.progressCallback(Math.min(100, Math.max(0, progress)));
|
|
416
|
+
} catch {
|
|
417
|
+
}
|
|
418
|
+
}
|
|
419
|
+
}
|
|
420
|
+
}
|
|
421
|
+
export {
|
|
422
|
+
TesseractWasmBackend
|
|
423
|
+
};
|
|
424
|
+
//# sourceMappingURL=tesseract-wasm-backend.mjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../../typescript/ocr/tesseract-wasm-backend.ts"],"sourcesContent":["/**\n * Tesseract WASM OCR Backend\n *\n * Provides OCR capabilities using tesseract-wasm library for browser environments.\n * Loads training data on-demand from jsDelivr CDN and implements the OcrBackendProtocol.\n *\n * ## Browser-Only Requirement\n *\n * This backend requires browser APIs like createImageBitmap and Web Workers.\n * It will NOT work in Node.js environments without additional canvas polyfills.\n *\n * ## Supported Languages\n *\n * Common ISO 639-1 and ISO 639-2 codes:\n * - English: \"eng\"\n * - German: \"deu\"\n * - French: \"fra\"\n * - Spanish: \"spa\"\n * - Italian: \"ita\"\n * - Portuguese: \"por\"\n * - Dutch: \"nld\"\n * - Russian: \"rus\"\n * - Chinese (Simplified): \"chi_sim\"\n * - Chinese (Traditional): \"chi_tra\"\n * - Japanese: \"jpn\"\n * - Korean: \"kor\"\n * - Arabic: \"ara\"\n * - Hindi: \"hin\"\n *\n * For complete language list, see: https://github.com/naptha/tesseract.js\n *\n * @example Basic Usage\n * ```typescript\n * import { TesseractWasmBackend } from '@kreuzberg/wasm/ocr/tesseract-wasm-backend';\n * import { registerOcrBackend, extractBytes, initWasm } from '@kreuzberg/wasm';\n *\n * // Initialize\n * await initWasm();\n * const backend = new TesseractWasmBackend();\n * await backend.initialize();\n * registerOcrBackend(backend);\n *\n * // Use in extraction\n * const imageBytes = new Uint8Array(buffer);\n * const result = await extractBytes(imageBytes, 'image/png', {\n * ocr: { backend: 'tesseract-wasm', language: 'eng' }\n * });\n * console.log(result.content); // Extracted text\n * ```\n *\n * @example With Language Auto-Detection\n * ```typescript\n * const backend = new TesseractWasmBackend();\n * await backend.initialize();\n * registerOcrBackend(backend);\n *\n * // Extract without specifying language - backend will auto-detect\n * const result = await extractBytes(imageBytes, 'image/png', {\n * ocr: { backend: 'tesseract-wasm' } // language will auto-detect\n * });\n * ```\n */\n\nimport type { OcrBackendProtocol } from \"../types.js\";\n\n/**\n * Tesseract WASM Client interface\n * Type definition for tesseract-wasm's OCRClient class\n */\ninterface TesseractClient {\n\tloadModel(modelPath: string): Promise<void>;\n\tloadImage(image: ImageBitmap | Blob): Promise<void>;\n\tgetText(): Promise<string>;\n\tgetConfidence(): Promise<number>;\n\tgetPageMetadata(): Promise<Record<string, unknown>>;\n\tdestroy(): void;\n\tterminate(): void;\n}\n\n/**\n * TesseractWasmBackend - OCR backend using tesseract-wasm library\n *\n * Implements the OcrBackendProtocol for Kreuzberg document extraction pipeline.\n * Provides comprehensive OCR support with model caching, error handling, and progress reporting.\n */\nexport class TesseractWasmBackend implements OcrBackendProtocol {\n\t/** Tesseract WASM client instance */\n\tprivate client: TesseractClient | null = null;\n\n\t/** Track which models are currently loaded to avoid redundant loads */\n\tprivate loadedLanguages: Set<string> = new Set();\n\n\t/** Cache for language availability validation */\n\tprivate supportedLangsCache: string[] | null = null;\n\n\t/** Progress callback for UI updates */\n\tprivate progressCallback: ((progress: number) => void) | null = null;\n\n\t/** Base URL for training data CDN */\n\tprivate readonly CDN_BASE_URL = \"https://cdn.jsdelivr.net/npm/tesseract-wasm@0.11.0/dist\";\n\n\t/**\n\t * Return the unique name of this OCR backend\n\t *\n\t * @returns Backend identifier \"tesseract-wasm\"\n\t */\n\tname(): string {\n\t\treturn \"tesseract-wasm\";\n\t}\n\n\t/**\n\t * Return list of supported language codes\n\t *\n\t * Returns a curated list of commonly available Tesseract language models.\n\t * Tesseract supports many more languages through custom models.\n\t *\n\t * @returns Array of ISO 639-1/2/3 language codes\n\t */\n\tsupportedLanguages(): string[] {\n\t\t// Return cached list if already computed\n\t\tif (this.supportedLangsCache) {\n\t\t\treturn this.supportedLangsCache;\n\t\t}\n\n\t\t// Comprehensive list of languages supported by tesseract-wasm\n\t\t// Includes both 3-letter (ISO 639-2) and 2-letter (ISO 639-1) codes where applicable\n\t\tthis.supportedLangsCache = [\n\t\t\t// Major languages\n\t\t\t\"eng\", // English\n\t\t\t\"deu\", // German\n\t\t\t\"fra\", // French\n\t\t\t\"spa\", // Spanish\n\t\t\t\"ita\", // Italian\n\t\t\t\"por\", // Portuguese\n\t\t\t\"nld\", // Dutch\n\t\t\t\"rus\", // Russian\n\t\t\t\"jpn\", // Japanese\n\t\t\t\"kor\", // Korean\n\t\t\t\"chi_sim\", // Chinese (Simplified)\n\t\t\t\"chi_tra\", // Chinese (Traditional)\n\n\t\t\t// Additional European languages\n\t\t\t\"pol\", // Polish\n\t\t\t\"tur\", // Turkish\n\t\t\t\"swe\", // Swedish\n\t\t\t\"dan\", // Danish\n\t\t\t\"fin\", // Finnish\n\t\t\t\"nor\", // Norwegian\n\t\t\t\"ces\", // Czech\n\t\t\t\"slk\", // Slovak\n\t\t\t\"ron\", // Romanian\n\t\t\t\"hun\", // Hungarian\n\t\t\t\"hrv\", // Croatian\n\t\t\t\"srp\", // Serbian\n\t\t\t\"bul\", // Bulgarian\n\t\t\t\"ukr\", // Ukrainian\n\t\t\t\"ell\", // Greek\n\n\t\t\t// Asian languages\n\t\t\t\"ara\", // Arabic\n\t\t\t\"heb\", // Hebrew\n\t\t\t\"hin\", // Hindi\n\t\t\t\"tha\", // Thai\n\t\t\t\"vie\", // Vietnamese\n\t\t\t\"mkd\", // Macedonian\n\t\t\t\"ben\", // Bengali\n\t\t\t\"tam\", // Tamil\n\t\t\t\"tel\", // Telugu\n\t\t\t\"kan\", // Kannada\n\t\t\t\"mal\", // Malayalam\n\t\t\t\"mya\", // Burmese\n\t\t\t\"khm\", // Khmer\n\t\t\t\"lao\", // Lao\n\t\t\t\"sin\", // Sinhala\n\t\t];\n\n\t\treturn this.supportedLangsCache;\n\t}\n\n\t/**\n\t * Initialize the OCR backend\n\t *\n\t * Creates the Tesseract WASM client instance. This is called once when\n\t * the backend is registered with the extraction pipeline.\n\t *\n\t * The actual model loading happens in processImage() on-demand to avoid\n\t * loading all models upfront.\n\t *\n\t * @throws {Error} If tesseract-wasm is not available or initialization fails\n\t *\n\t * @example\n\t * ```typescript\n\t * const backend = new TesseractWasmBackend();\n\t * try {\n\t * await backend.initialize();\n\t * } catch (error) {\n\t * console.error('Failed to initialize OCR:', error);\n\t * }\n\t * ```\n\t */\n\tasync initialize(): Promise<void> {\n\t\tif (this.client) {\n\t\t\treturn; // Already initialized\n\t\t}\n\n\t\ttry {\n\t\t\t// Dynamically import tesseract-wasm\n\t\t\tconst tesseractModule = await this.loadTesseractWasm();\n\n\t\t\t// @ts-expect-error - tesseract-wasm types are not fully typed\n\t\t\tif (!tesseractModule || typeof tesseractModule.OCRClient !== \"function\") {\n\t\t\t\tthrow new Error(\"tesseract-wasm OCRClient not found. Ensure tesseract-wasm is installed and available.\");\n\t\t\t}\n\n\t\t\t// Create client instance\n\t\t\t// @ts-expect-error - tesseract-wasm types are not fully typed\n\t\t\tthis.client = new tesseractModule.OCRClient();\n\n\t\t\t// Initialize tracking\n\t\t\tthis.loadedLanguages.clear();\n\t\t} catch (error) {\n\t\t\tconst message = error instanceof Error ? error.message : String(error);\n\t\t\tthrow new Error(`Failed to initialize TesseractWasmBackend: ${message}`);\n\t\t}\n\t}\n\n\t/**\n\t * Process image bytes and extract text via OCR\n\t *\n\t * Handles image loading, model loading, OCR processing, and result formatting.\n\t * Automatically loads the language model on first use and caches it for subsequent calls.\n\t *\n\t * @param imageBytes - Raw image data (Uint8Array) or Base64-encoded string\n\t * @param language - ISO 639-2/3 language code (e.g., \"eng\", \"deu\")\n\t * @returns Promise resolving to OCR result with content and metadata\n\t * @throws {Error} If image processing fails, model loading fails, or language is unsupported\n\t *\n\t * @example\n\t * ```typescript\n\t * const backend = new TesseractWasmBackend();\n\t * await backend.initialize();\n\t *\n\t * const imageBuffer = fs.readFileSync('scanned.png');\n\t * const result = await backend.processImage(\n\t * new Uint8Array(imageBuffer),\n\t * 'eng'\n\t * );\n\t *\n\t * console.log(result.content); // Extracted text\n\t * console.log(result.metadata.confidence); // OCR confidence score\n\t * ```\n\t */\n\tasync processImage(\n\t\timageBytes: Uint8Array | string,\n\t\tlanguage: string,\n\t): Promise<{\n\t\tcontent: string;\n\t\tmime_type: string;\n\t\tmetadata: Record<string, unknown>;\n\t\ttables: unknown[];\n\t}> {\n\t\tif (!this.client) {\n\t\t\tthrow new Error(\"TesseractWasmBackend not initialized. Call initialize() first.\");\n\t\t}\n\n\t\t// Validate language support\n\t\tconst supported = this.supportedLanguages();\n\t\t// Normalize language code for comparison\n\t\tconst normalizedLang = language.toLowerCase();\n\t\tconst isSupported = supported.some((lang) => lang.toLowerCase() === normalizedLang);\n\n\t\tif (!isSupported) {\n\t\t\tthrow new Error(`Language \"${language}\" is not supported. Supported languages: ${supported.join(\", \")}`);\n\t\t}\n\n\t\ttry {\n\t\t\t// Load language model if not already loaded\n\t\t\tif (!this.loadedLanguages.has(normalizedLang)) {\n\t\t\t\tthis.reportProgress(10); // Progress: loading model\n\t\t\t\tawait this.loadLanguageModel(normalizedLang);\n\t\t\t\tthis.loadedLanguages.add(normalizedLang);\n\t\t\t\tthis.reportProgress(30); // Progress: model loaded\n\t\t\t}\n\n\t\t\t// Convert image bytes to ImageBitmap\n\t\t\tthis.reportProgress(40); // Progress: processing image\n\t\t\tconst imageBitmap = await this.convertToImageBitmap(imageBytes);\n\n\t\t\t// Load image into Tesseract\n\t\t\tthis.reportProgress(50); // Progress: loading image\n\t\t\tawait this.client.loadImage(imageBitmap);\n\n\t\t\t// Perform OCR\n\t\t\tthis.reportProgress(70); // Progress: performing OCR\n\t\t\tconst text = await this.client.getText();\n\n\t\t\t// Get confidence and metadata\n\t\t\tconst confidence = await this.getConfidenceScore();\n\t\t\tconst pageMetadata = await this.getPageMetadata();\n\n\t\t\tthis.reportProgress(90); // Progress: nearly complete\n\n\t\t\t// Return result in Kreuzberg format\n\t\t\treturn {\n\t\t\t\tcontent: text,\n\t\t\t\tmime_type: \"text/plain\",\n\t\t\t\tmetadata: {\n\t\t\t\t\tlanguage: normalizedLang,\n\t\t\t\t\tconfidence,\n\t\t\t\t\t...pageMetadata,\n\t\t\t\t},\n\t\t\t\ttables: [], // Tesseract-wasm doesn't provide structured table detection\n\t\t\t};\n\t\t} catch (error) {\n\t\t\tconst message = error instanceof Error ? error.message : String(error);\n\t\t\tthrow new Error(`OCR processing failed for language \"${language}\": ${message}`);\n\t\t} finally {\n\t\t\tthis.reportProgress(100); // Progress: complete\n\t\t}\n\t}\n\n\t/**\n\t * Shutdown the OCR backend and release resources\n\t *\n\t * Properly cleans up the Tesseract WASM client, freeing memory and Web Workers.\n\t * Called when the backend is unregistered or the application shuts down.\n\t *\n\t * @throws {Error} If cleanup fails (errors are logged but not critical)\n\t *\n\t * @example\n\t * ```typescript\n\t * const backend = new TesseractWasmBackend();\n\t * await backend.initialize();\n\t * // ... use backend ...\n\t * await backend.shutdown(); // Clean up resources\n\t * ```\n\t */\n\tasync shutdown(): Promise<void> {\n\t\ttry {\n\t\t\tif (this.client) {\n\t\t\t\t// Try both destroy and terminate for compatibility\n\t\t\t\tif (typeof this.client.destroy === \"function\") {\n\t\t\t\t\tthis.client.destroy();\n\t\t\t\t}\n\t\t\t\tif (typeof this.client.terminate === \"function\") {\n\t\t\t\t\tthis.client.terminate();\n\t\t\t\t}\n\t\t\t\tthis.client = null;\n\t\t\t}\n\n\t\t\t// Clear cached state\n\t\t\tthis.loadedLanguages.clear();\n\t\t\tthis.supportedLangsCache = null;\n\t\t\tthis.progressCallback = null;\n\t\t} catch (error) {\n\t\t\t// Log error but don't throw - shutdown is best-effort\n\t\t\tconsole.warn(\n\t\t\t\t`Warning during TesseractWasmBackend shutdown: ${error instanceof Error ? error.message : String(error)}`,\n\t\t\t);\n\t\t}\n\t}\n\n\t/**\n\t * Set a progress callback for UI updates\n\t *\n\t * Allows the UI to display progress during OCR processing.\n\t * The callback will be called with values from 0 to 100.\n\t *\n\t * @param callback - Function to call with progress percentage\n\t *\n\t * @example\n\t * ```typescript\n\t * const backend = new TesseractWasmBackend();\n\t * backend.setProgressCallback((progress) => {\n\t * console.log(`OCR Progress: ${progress}%`);\n\t * document.getElementById('progress-bar').style.width = `${progress}%`;\n\t * });\n\t * ```\n\t */\n\tsetProgressCallback(callback: (progress: number) => void): void {\n\t\tthis.progressCallback = callback;\n\t}\n\n\t/**\n\t * Load language model from CDN\n\t *\n\t * Fetches the training data for a specific language from jsDelivr CDN.\n\t * This is an MVP approach - models are cached by the browser.\n\t *\n\t * @param language - ISO 639-2/3 language code\n\t * @throws {Error} If model download fails or language is not available\n\t *\n\t * @internal\n\t */\n\tprivate async loadLanguageModel(language: string): Promise<void> {\n\t\tif (!this.client) {\n\t\t\tthrow new Error(\"Client not initialized\");\n\t\t}\n\n\t\t// Construct model URL - models are named with their language code\n\t\tconst modelFilename = `${language}.traineddata`;\n\t\tconst modelUrl = `${this.CDN_BASE_URL}/${modelFilename}`;\n\n\t\ttry {\n\t\t\tawait this.client.loadModel(modelUrl);\n\t\t} catch (error) {\n\t\t\tconst message = error instanceof Error ? error.message : String(error);\n\t\t\tthrow new Error(`Failed to load model for language \"${language}\" from ${modelUrl}: ${message}`);\n\t\t}\n\t}\n\n\t/**\n\t * Convert image bytes or Base64 string to ImageBitmap\n\t *\n\t * Handles both Uint8Array and Base64-encoded image data, converting to\n\t * ImageBitmap format required by Tesseract WASM.\n\t *\n\t * @param imageBytes - Image data as Uint8Array or Base64 string\n\t * @returns Promise resolving to ImageBitmap\n\t * @throws {Error} If conversion fails (browser API not available or invalid image data)\n\t *\n\t * @internal\n\t */\n\tprivate async convertToImageBitmap(imageBytes: Uint8Array | string): Promise<ImageBitmap> {\n\t\t// Check if createImageBitmap is available (browser only)\n\t\tif (typeof createImageBitmap === \"undefined\") {\n\t\t\tthrow new Error(\"createImageBitmap is not available. TesseractWasmBackend requires a browser environment.\");\n\t\t}\n\n\t\ttry {\n\t\t\t// Convert to Uint8Array if string (Base64)\n\t\t\tlet bytes = imageBytes;\n\t\t\tif (typeof imageBytes === \"string\") {\n\t\t\t\t// Decode Base64 to binary\n\t\t\t\tconst binaryString = atob(imageBytes);\n\t\t\t\tbytes = new Uint8Array(binaryString.length);\n\t\t\t\tfor (let i = 0; i < binaryString.length; i++) {\n\t\t\t\t\t(bytes as Uint8Array)[i] = binaryString.charCodeAt(i);\n\t\t\t\t}\n\t\t\t}\n\n\t\t\t// Create Blob from bytes\n\t\t\tconst blob = new Blob([bytes as Uint8Array] as BlobPart[]);\n\n\t\t\t// Convert Blob to ImageBitmap\n\t\t\tconst imageBitmap = await createImageBitmap(blob);\n\t\t\treturn imageBitmap;\n\t\t} catch (error) {\n\t\t\tconst message = error instanceof Error ? error.message : String(error);\n\t\t\tthrow new Error(`Failed to convert image bytes to ImageBitmap: ${message}`);\n\t\t}\n\t}\n\n\t/**\n\t * Get confidence score from OCR result\n\t *\n\t * Attempts to retrieve confidence score from Tesseract.\n\t * Returns a safe default if unavailable.\n\t *\n\t * @returns Confidence score between 0 and 1\n\t *\n\t * @internal\n\t */\n\tprivate async getConfidenceScore(): Promise<number> {\n\t\ttry {\n\t\t\tif (this.client && typeof this.client.getConfidence === \"function\") {\n\t\t\t\tconst confidence = await this.client.getConfidence();\n\t\t\t\t// Normalize to 0-1 range if needed (some versions return 0-100)\n\t\t\t\treturn confidence > 1 ? confidence / 100 : confidence;\n\t\t\t}\n\t\t} catch {\n\t\t\t// Silently fail - confidence is optional\n\t\t}\n\t\treturn 0.9; // Default reasonable confidence\n\t}\n\n\t/**\n\t * Get page metadata from OCR result\n\t *\n\t * Retrieves additional metadata like image dimensions and processing info.\n\t *\n\t * @returns Metadata object (may be empty if unavailable)\n\t *\n\t * @internal\n\t */\n\tprivate async getPageMetadata(): Promise<Record<string, unknown>> {\n\t\ttry {\n\t\t\tif (this.client && typeof this.client.getPageMetadata === \"function\") {\n\t\t\t\treturn await this.client.getPageMetadata();\n\t\t\t}\n\t\t} catch {\n\t\t\t// Silently fail - metadata is optional\n\t\t}\n\t\treturn {};\n\t}\n\n\t/**\n\t * Dynamically load tesseract-wasm module\n\t *\n\t * Uses dynamic import to load tesseract-wasm only when needed,\n\t * avoiding hard dependency in browser environments where it may not be bundled.\n\t *\n\t * @returns tesseract-wasm module object\n\t * @throws {Error} If module cannot be imported\n\t *\n\t * @internal\n\t */\n\tprivate async loadTesseractWasm(): Promise<unknown> {\n\t\ttry {\n\t\t\t// Use dynamic import to handle both ESM and CJS\n\t\t\t// @ts-expect-error - tesseract-wasm has package.json exports issues with TypeScript\n\t\t\tconst module = await import(\"tesseract-wasm\");\n\t\t\treturn module;\n\t\t} catch (error) {\n\t\t\tconst message = error instanceof Error ? error.message : String(error);\n\t\t\tthrow new Error(\n\t\t\t\t`Failed to import tesseract-wasm. Ensure it is installed via: npm install tesseract-wasm. Error: ${message}`,\n\t\t\t);\n\t\t}\n\t}\n\n\t/**\n\t * Report progress to progress callback\n\t *\n\t * Internal helper for notifying progress updates during OCR processing.\n\t *\n\t * @param progress - Progress percentage (0-100)\n\t *\n\t * @internal\n\t */\n\tprivate reportProgress(progress: number): void {\n\t\tif (this.progressCallback) {\n\t\t\ttry {\n\t\t\t\tthis.progressCallback(Math.min(100, Math.max(0, progress)));\n\t\t\t} catch {\n\t\t\t\t// Ignore callback errors to prevent blocking OCR processing\n\t\t\t}\n\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