@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.
Files changed (42) hide show
  1. package/README.md +520 -837
  2. package/dist/adapters/wasm-adapter.d.ts +7 -10
  3. package/dist/adapters/wasm-adapter.d.ts.map +1 -0
  4. package/dist/adapters/wasm-adapter.js +41 -19
  5. package/dist/adapters/wasm-adapter.js.map +1 -1
  6. package/dist/index.d.ts +23 -24
  7. package/dist/index.d.ts.map +1 -0
  8. package/dist/index.js +240 -67
  9. package/dist/index.js.map +1 -1
  10. package/dist/ocr/registry.d.ts +7 -10
  11. package/dist/ocr/registry.d.ts.map +1 -0
  12. package/dist/ocr/registry.js.map +1 -1
  13. package/dist/ocr/tesseract-wasm-backend.d.ts +3 -6
  14. package/dist/ocr/tesseract-wasm-backend.d.ts.map +1 -0
  15. package/dist/ocr/tesseract-wasm-backend.js +0 -46
  16. package/dist/ocr/tesseract-wasm-backend.js.map +1 -1
  17. package/dist/pdfium.js +0 -5
  18. package/dist/plugin-registry.d.ts +246 -0
  19. package/dist/plugin-registry.d.ts.map +1 -0
  20. package/dist/runtime.d.ts +21 -22
  21. package/dist/runtime.d.ts.map +1 -0
  22. package/dist/runtime.js +0 -1
  23. package/dist/runtime.js.map +1 -1
  24. package/dist/{types-CKjcIYcX.d.ts → types.d.ts} +91 -22
  25. package/dist/types.d.ts.map +1 -0
  26. package/package.json +119 -162
  27. package/dist/adapters/wasm-adapter.cjs +0 -245
  28. package/dist/adapters/wasm-adapter.cjs.map +0 -1
  29. package/dist/adapters/wasm-adapter.d.cts +0 -121
  30. package/dist/index.cjs +0 -1245
  31. package/dist/index.cjs.map +0 -1
  32. package/dist/index.d.cts +0 -423
  33. package/dist/ocr/registry.cjs +0 -92
  34. package/dist/ocr/registry.cjs.map +0 -1
  35. package/dist/ocr/registry.d.cts +0 -102
  36. package/dist/ocr/tesseract-wasm-backend.cjs +0 -456
  37. package/dist/ocr/tesseract-wasm-backend.cjs.map +0 -1
  38. package/dist/ocr/tesseract-wasm-backend.d.cts +0 -257
  39. package/dist/runtime.cjs +0 -174
  40. package/dist/runtime.cjs.map +0 -1
  41. package/dist/runtime.d.cts +0 -256
  42. package/dist/types-CKjcIYcX.d.cts +0 -294
@@ -1,256 +0,0 @@
1
- /**
2
- * Runtime detection and environment-specific utilities
3
- *
4
- * This module provides utilities for detecting the JavaScript runtime environment,
5
- * checking for feature availability, and enabling environment-specific WASM loading strategies.
6
- *
7
- * @example Basic Runtime Detection
8
- * ```typescript
9
- * import { detectRuntime, isBrowser, isNode } from '@kreuzberg/wasm/runtime';
10
- *
11
- * if (isBrowser()) {
12
- * console.log('Running in browser');
13
- * } else if (isNode()) {
14
- * console.log('Running in Node.js');
15
- * }
16
- * ```
17
- *
18
- * @example Feature Detection
19
- * ```typescript
20
- * import { hasFileApi, hasWorkers } from '@kreuzberg/wasm/runtime';
21
- *
22
- * if (hasFileApi()) {
23
- * // Can use File API for browser file uploads
24
- * }
25
- *
26
- * if (hasWorkers()) {
27
- * // Can use Web Workers for parallel processing
28
- * }
29
- * ```
30
- */
31
- type RuntimeType = "browser" | "node" | "deno" | "bun" | "unknown";
32
- /**
33
- * WebAssembly capabilities available in the runtime
34
- */
35
- interface WasmCapabilities {
36
- /** Runtime environment type */
37
- runtime: RuntimeType;
38
- /** WebAssembly support available */
39
- hasWasm: boolean;
40
- /** Streaming WebAssembly instantiation available */
41
- hasWasmStreaming: boolean;
42
- /** File API available (browser) */
43
- hasFileApi: boolean;
44
- /** Blob API available */
45
- hasBlob: boolean;
46
- /** Worker support available */
47
- hasWorkers: boolean;
48
- /** SharedArrayBuffer available (may be restricted) */
49
- hasSharedArrayBuffer: boolean;
50
- /** Module Workers available */
51
- hasModuleWorkers: boolean;
52
- /** BigInt support */
53
- hasBigInt: boolean;
54
- /** Specific runtime version if available */
55
- runtimeVersion?: string;
56
- }
57
- /**
58
- * Detect the current JavaScript runtime
59
- *
60
- * Checks for various global objects and properties to determine
61
- * which JavaScript runtime environment is currently executing.
62
- *
63
- * @returns The detected runtime type
64
- *
65
- * @example
66
- * ```typescript
67
- * import { detectRuntime } from '@kreuzberg/wasm/runtime';
68
- *
69
- * const runtime = detectRuntime();
70
- * switch (runtime) {
71
- * case 'browser':
72
- * console.log('Running in browser');
73
- * break;
74
- * case 'node':
75
- * console.log('Running in Node.js');
76
- * break;
77
- * case 'deno':
78
- * console.log('Running in Deno');
79
- * break;
80
- * case 'bun':
81
- * console.log('Running in Bun');
82
- * break;
83
- * }
84
- * ```
85
- */
86
- declare function detectRuntime(): RuntimeType;
87
- /**
88
- * Check if running in a browser environment
89
- *
90
- * @returns True if running in a browser, false otherwise
91
- */
92
- declare function isBrowser(): boolean;
93
- /**
94
- * Check if running in Node.js
95
- *
96
- * @returns True if running in Node.js, false otherwise
97
- */
98
- declare function isNode(): boolean;
99
- /**
100
- * Check if running in Deno
101
- *
102
- * @returns True if running in Deno, false otherwise
103
- */
104
- declare function isDeno(): boolean;
105
- /**
106
- * Check if running in Bun
107
- *
108
- * @returns True if running in Bun, false otherwise
109
- */
110
- declare function isBun(): boolean;
111
- /**
112
- * Check if running in a web environment (browser or similar)
113
- *
114
- * @returns True if running in a web browser, false otherwise
115
- */
116
- declare function isWebEnvironment(): boolean;
117
- /**
118
- * Check if running in a server-like environment (Node.js, Deno, Bun)
119
- *
120
- * @returns True if running on a server runtime, false otherwise
121
- */
122
- declare function isServerEnvironment(): boolean;
123
- /**
124
- * Check if File API is available
125
- *
126
- * The File API is required for handling browser file uploads.
127
- *
128
- * @returns True if File API is available, false otherwise
129
- *
130
- * @example
131
- * ```typescript
132
- * if (hasFileApi()) {
133
- * const fileInput = document.getElementById('file');
134
- * fileInput.addEventListener('change', (e) => {
135
- * const file = e.target.files?.[0];
136
- * // Handle file
137
- * });
138
- * }
139
- * ```
140
- */
141
- declare function hasFileApi(): boolean;
142
- /**
143
- * Check if Blob API is available
144
- *
145
- * @returns True if Blob API is available, false otherwise
146
- */
147
- declare function hasBlob(): boolean;
148
- /**
149
- * Check if Web Workers are available
150
- *
151
- * @returns True if Web Workers can be created, false otherwise
152
- */
153
- declare function hasWorkers(): boolean;
154
- /**
155
- * Check if SharedArrayBuffer is available
156
- *
157
- * Note: SharedArrayBuffer is restricted in some browser contexts
158
- * due to security considerations (Spectre/Meltdown mitigations).
159
- *
160
- * @returns True if SharedArrayBuffer is available, false otherwise
161
- */
162
- declare function hasSharedArrayBuffer(): boolean;
163
- /**
164
- * Check if module workers are available
165
- *
166
- * Module workers allow importing ES modules in worker threads.
167
- *
168
- * @returns True if module workers are supported, false otherwise
169
- */
170
- declare function hasModuleWorkers(): boolean;
171
- /**
172
- * Check if WebAssembly is available
173
- *
174
- * @returns True if WebAssembly is supported, false otherwise
175
- */
176
- declare function hasWasm(): boolean;
177
- /**
178
- * Check if WebAssembly.instantiateStreaming is available
179
- *
180
- * Streaming instantiation is more efficient than buffering the entire WASM module.
181
- *
182
- * @returns True if streaming WebAssembly is supported, false otherwise
183
- */
184
- declare function hasWasmStreaming(): boolean;
185
- /**
186
- * Check if BigInt is available
187
- *
188
- * @returns True if BigInt type is supported, false otherwise
189
- */
190
- declare function hasBigInt(): boolean;
191
- /**
192
- * Get runtime version information
193
- *
194
- * @returns Version string if available, undefined otherwise
195
- *
196
- * @example
197
- * ```typescript
198
- * const version = getRuntimeVersion();
199
- * console.log(`Running on Node ${version}`); // "Running on Node 18.12.0"
200
- * ```
201
- */
202
- declare function getRuntimeVersion(): string | undefined;
203
- /**
204
- * Get comprehensive WebAssembly capabilities for current runtime
205
- *
206
- * Returns detailed information about WASM and related APIs available
207
- * in the current runtime environment.
208
- *
209
- * @returns Object describing available WASM capabilities
210
- *
211
- * @example
212
- * ```typescript
213
- * import { getWasmCapabilities } from '@kreuzberg/wasm/runtime';
214
- *
215
- * const caps = getWasmCapabilities();
216
- * console.log(`WASM available: ${caps.hasWasm}`);
217
- * console.log(`Streaming WASM: ${caps.hasWasmStreaming}`);
218
- * console.log(`Workers available: ${caps.hasWorkers}`);
219
- *
220
- * if (caps.hasWasm && caps.hasWorkers) {
221
- * // Can offload WASM processing to workers
222
- * }
223
- * ```
224
- */
225
- declare function getWasmCapabilities(): WasmCapabilities;
226
- /**
227
- * Get comprehensive runtime information
228
- *
229
- * Returns detailed information about the current runtime environment,
230
- * capabilities, and identifying information.
231
- *
232
- * @returns Object with runtime details and capabilities
233
- *
234
- * @example
235
- * ```typescript
236
- * const info = getRuntimeInfo();
237
- * console.log(info.runtime); // 'browser' | 'node' | 'deno' | 'bun'
238
- * console.log(info.isBrowser); // true/false
239
- * console.log(info.userAgent); // Browser user agent string
240
- * console.log(info.capabilities); // Detailed capability information
241
- * ```
242
- */
243
- declare function getRuntimeInfo(): {
244
- runtime: RuntimeType;
245
- isBrowser: boolean;
246
- isNode: boolean;
247
- isDeno: boolean;
248
- isBun: boolean;
249
- isWeb: boolean;
250
- isServer: boolean;
251
- runtimeVersion: string | undefined;
252
- userAgent: string;
253
- capabilities: WasmCapabilities;
254
- };
255
-
256
- export { type RuntimeType, type WasmCapabilities, detectRuntime, getRuntimeInfo, getRuntimeVersion, getWasmCapabilities, hasBigInt, hasBlob, hasFileApi, hasModuleWorkers, hasSharedArrayBuffer, hasWasm, hasWasmStreaming, hasWorkers, isBrowser, isBun, isDeno, isNode, isServerEnvironment, isWebEnvironment };
@@ -1,294 +0,0 @@
1
- /**
2
- * Type definitions for Kreuzberg WASM bindings
3
- *
4
- * These types are generated from the Rust core library and define
5
- * the interface for extraction, configuration, and results.
6
- */
7
- /**
8
- * Token reduction configuration
9
- */
10
- interface TokenReductionConfig {
11
- /** Token reduction mode */
12
- mode?: string;
13
- /** Preserve important words during reduction */
14
- preserveImportantWords?: boolean;
15
- }
16
- /**
17
- * Post-processor configuration
18
- */
19
- interface PostProcessorConfig {
20
- /** Whether post-processing is enabled */
21
- enabled?: boolean;
22
- /** List of enabled processors */
23
- enabledProcessors?: string[];
24
- /** List of disabled processors */
25
- disabledProcessors?: string[];
26
- }
27
- /**
28
- * Configuration for document extraction
29
- */
30
- interface ExtractionConfig {
31
- /** OCR configuration */
32
- ocr?: OcrConfig;
33
- /** Chunking configuration */
34
- chunking?: ChunkingConfig;
35
- /** Image extraction configuration */
36
- images?: ImageExtractionConfig;
37
- /** Page extraction configuration */
38
- pages?: PageExtractionConfig;
39
- /** Language detection configuration */
40
- languageDetection?: LanguageDetectionConfig;
41
- /** PDF extraction options */
42
- pdfOptions?: PdfConfig;
43
- /** Token reduction configuration */
44
- tokenReduction?: TokenReductionConfig;
45
- /** Post-processor configuration */
46
- postprocessor?: PostProcessorConfig;
47
- /** Whether to use caching */
48
- useCache?: boolean;
49
- /** Enable quality processing */
50
- enableQualityProcessing?: boolean;
51
- /** Force OCR even if text is available */
52
- forceOcr?: boolean;
53
- /** Maximum concurrent extractions */
54
- maxConcurrentExtractions?: number;
55
- }
56
- /**
57
- * Tesseract OCR configuration
58
- */
59
- interface TesseractConfig {
60
- /** Tesseract page segmentation mode */
61
- psm?: number;
62
- /** Enable table detection */
63
- enableTableDetection?: boolean;
64
- /** Character whitelist for recognition */
65
- tesseditCharWhitelist?: string;
66
- }
67
- /**
68
- * OCR configuration
69
- */
70
- interface OcrConfig {
71
- /** OCR backend to use */
72
- backend?: string;
73
- /** Language codes (ISO 639) */
74
- languages?: string[];
75
- /** Whether to perform OCR */
76
- enabled?: boolean;
77
- /** Tesseract-specific configuration */
78
- tesseractConfig?: TesseractConfig;
79
- /** Language code for OCR */
80
- language?: string;
81
- }
82
- /**
83
- * Chunking configuration
84
- */
85
- interface ChunkingConfig {
86
- /** Maximum characters per chunk */
87
- maxChars?: number;
88
- /** Overlap between chunks */
89
- maxOverlap?: number;
90
- }
91
- /**
92
- * Image extraction configuration
93
- */
94
- interface ImageExtractionConfig {
95
- /** Whether to extract images */
96
- enabled?: boolean;
97
- /** Target DPI for image extraction */
98
- targetDpi?: number;
99
- /** Maximum image dimension in pixels */
100
- maxImageDimension?: number;
101
- /** Automatically adjust DPI */
102
- autoAdjustDpi?: boolean;
103
- /** Minimum DPI threshold */
104
- minDpi?: number;
105
- /** Maximum DPI threshold */
106
- maxDpi?: number;
107
- }
108
- /**
109
- * PDF extraction configuration
110
- */
111
- interface PdfConfig {
112
- /** Whether to extract images from PDF */
113
- extractImages?: boolean;
114
- /** Passwords for encrypted PDFs */
115
- passwords?: string[];
116
- /** Whether to extract metadata */
117
- extractMetadata?: boolean;
118
- }
119
- /**
120
- * Page extraction configuration
121
- */
122
- interface PageExtractionConfig {
123
- /** Whether to extract per-page content */
124
- enabled?: boolean;
125
- }
126
- /**
127
- * Language detection configuration
128
- */
129
- interface LanguageDetectionConfig {
130
- /** Whether to detect languages */
131
- enabled?: boolean;
132
- }
133
- /**
134
- * Result of document extraction
135
- */
136
- interface ExtractionResult {
137
- /** Extracted text content */
138
- content: string;
139
- /** MIME type of the document */
140
- mimeType: string;
141
- /** Document metadata */
142
- metadata: Metadata;
143
- /** Extracted tables */
144
- tables: Table[];
145
- /** Detected languages (ISO 639 codes) */
146
- detectedLanguages?: string[] | null;
147
- /** Text chunks when chunking is enabled */
148
- chunks?: Chunk[] | null;
149
- /** Extracted images */
150
- images?: ExtractedImage[] | null;
151
- /** Per-page content */
152
- pages?: PageContent[] | null;
153
- }
154
- /**
155
- * Document metadata
156
- */
157
- interface Metadata {
158
- /** Document title */
159
- title?: string;
160
- /** Document subject or description */
161
- subject?: string;
162
- /** Document author(s) */
163
- authors?: string[];
164
- /** Keywords/tags */
165
- keywords?: string[];
166
- /** Primary language (ISO 639 code) */
167
- language?: string;
168
- /** Creation timestamp (ISO 8601 format) */
169
- createdAt?: string;
170
- /** Last modification timestamp (ISO 8601 format) */
171
- modifiedAt?: string;
172
- /** User who created the document */
173
- creator?: string;
174
- /** User who last modified the document */
175
- lastModifiedBy?: string;
176
- /** Number of pages/slides */
177
- pageCount?: number;
178
- /** Format-specific metadata */
179
- formatMetadata?: unknown;
180
- /**
181
- * Additional fields may be added at runtime by postprocessors.
182
- * Use bracket notation to safely access unexpected properties.
183
- */
184
- [key: string]: unknown;
185
- }
186
- /**
187
- * Extracted table
188
- */
189
- interface Table {
190
- /** Table cells/rows */
191
- cells?: string[][];
192
- /** Table markdown representation */
193
- markdown?: string;
194
- /** Page number if available */
195
- pageNumber?: number;
196
- /** Table headers */
197
- headers?: string[];
198
- /** Table rows */
199
- rows?: string[][];
200
- }
201
- /**
202
- * Chunk metadata
203
- */
204
- interface ChunkMetadata {
205
- /** Character start position in original content */
206
- charStart: number;
207
- /** Character end position in original content */
208
- charEnd: number;
209
- /** Token count if available */
210
- tokenCount: number | null;
211
- /** Index of this chunk */
212
- chunkIndex: number;
213
- /** Total number of chunks */
214
- totalChunks: number;
215
- }
216
- /**
217
- * Text chunk from chunked content
218
- */
219
- interface Chunk {
220
- /** Chunk text content */
221
- content: string;
222
- /** Chunk metadata */
223
- metadata?: ChunkMetadata;
224
- /** Character position in original content (legacy) */
225
- charIndex?: number;
226
- /** Token count if available (legacy) */
227
- tokenCount?: number;
228
- /** Embedding vector if computed */
229
- embedding?: number[] | null;
230
- }
231
- /**
232
- * Extracted image from document
233
- */
234
- interface ExtractedImage {
235
- /** Image data as Uint8Array or base64 string */
236
- data: Uint8Array | string;
237
- /** Image format/MIME type */
238
- format?: string;
239
- /** MIME type of the image */
240
- mimeType?: string;
241
- /** Image index in document */
242
- imageIndex?: number;
243
- /** Page number if available */
244
- pageNumber?: number | null;
245
- /** Image width in pixels */
246
- width?: number | null;
247
- /** Image height in pixels */
248
- height?: number | null;
249
- /** Color space of the image */
250
- colorspace?: string | null;
251
- /** Bits per color component */
252
- bitsPerComponent?: number | null;
253
- /** Whether this is a mask image */
254
- isMask?: boolean;
255
- /** Image description */
256
- description?: string | null;
257
- /** Optional OCR result from the image */
258
- ocrResult?: ExtractionResult | string | null;
259
- }
260
- /**
261
- * Per-page content
262
- */
263
- interface PageContent {
264
- /** Page number (1-indexed) */
265
- pageNumber: number;
266
- /** Text content of the page */
267
- content: string;
268
- /** Tables on this page */
269
- tables?: Table[];
270
- /** Images on this page */
271
- images?: ExtractedImage[];
272
- }
273
- /**
274
- * OCR backend protocol/interface
275
- */
276
- interface OcrBackendProtocol {
277
- /** Get the backend name */
278
- name(): string;
279
- /** Get supported language codes */
280
- supportedLanguages?(): string[];
281
- /** Initialize the backend */
282
- initialize(options?: Record<string, unknown>): void | Promise<void>;
283
- /** Shutdown the backend */
284
- shutdown?(): void | Promise<void>;
285
- /** Process an image with OCR */
286
- processImage(imageData: Uint8Array | string, language?: string): Promise<{
287
- content: string;
288
- mime_type: string;
289
- metadata?: Record<string, unknown>;
290
- tables?: unknown[];
291
- } | string>;
292
- }
293
-
294
- export type { Chunk as C, ExtractionConfig as E, ImageExtractionConfig as I, LanguageDetectionConfig as L, Metadata as M, OcrBackendProtocol as O, PageContent as P, Table as T, ExtractionResult as a, ChunkingConfig as b, ChunkMetadata as c, ExtractedImage as d, OcrConfig as e, PageExtractionConfig as f, PdfConfig as g, PostProcessorConfig as h, TesseractConfig as i, TokenReductionConfig as j };