@kreuzberg/wasm 4.0.0-rc.10 → 4.0.0-rc.13
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 +49 -0
- package/dist/index.cjs +25 -1
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +0 -43
- package/dist/index.d.ts +0 -43
- package/dist/index.js +25 -1
- package/dist/index.js.map +1 -1
- package/package.json +139 -138
package/dist/index.d.cts
CHANGED
|
@@ -101,49 +101,6 @@ export { RuntimeType, WasmCapabilities, detectRuntime, getRuntimeInfo, getRuntim
|
|
|
101
101
|
* ```
|
|
102
102
|
*/
|
|
103
103
|
|
|
104
|
-
/**
|
|
105
|
-
* Initialize the WASM module
|
|
106
|
-
*
|
|
107
|
-
* This function must be called once before using any extraction functions.
|
|
108
|
-
* It loads and initializes the WASM module in the current runtime environment,
|
|
109
|
-
* automatically selecting the appropriate WASM variant for the detected runtime.
|
|
110
|
-
*
|
|
111
|
-
* Multiple calls to initWasm() are safe and will return immediately if already initialized.
|
|
112
|
-
*
|
|
113
|
-
* @throws {Error} If WASM module fails to load or is not supported in the current environment
|
|
114
|
-
*
|
|
115
|
-
* @example Basic Usage
|
|
116
|
-
* ```typescript
|
|
117
|
-
* import { initWasm } from '@kreuzberg/wasm';
|
|
118
|
-
*
|
|
119
|
-
* async function main() {
|
|
120
|
-
* await initWasm();
|
|
121
|
-
* // Now you can use extraction functions
|
|
122
|
-
* }
|
|
123
|
-
*
|
|
124
|
-
* main().catch(console.error);
|
|
125
|
-
* ```
|
|
126
|
-
*
|
|
127
|
-
* @example With Error Handling
|
|
128
|
-
* ```typescript
|
|
129
|
-
* import { initWasm, getWasmCapabilities } from '@kreuzberg/wasm';
|
|
130
|
-
*
|
|
131
|
-
* async function initializeKreuzberg() {
|
|
132
|
-
* const caps = getWasmCapabilities();
|
|
133
|
-
* if (!caps.hasWasm) {
|
|
134
|
-
* throw new Error('WebAssembly is not supported in this environment');
|
|
135
|
-
* }
|
|
136
|
-
*
|
|
137
|
-
* try {
|
|
138
|
-
* await initWasm();
|
|
139
|
-
* console.log('Kreuzberg initialized successfully');
|
|
140
|
-
* } catch (error) {
|
|
141
|
-
* console.error('Failed to initialize Kreuzberg:', error);
|
|
142
|
-
* throw error;
|
|
143
|
-
* }
|
|
144
|
-
* }
|
|
145
|
-
* ```
|
|
146
|
-
*/
|
|
147
104
|
declare function initWasm(): Promise<void>;
|
|
148
105
|
/**
|
|
149
106
|
* Check if WASM module is initialized
|
package/dist/index.d.ts
CHANGED
|
@@ -101,49 +101,6 @@ export { RuntimeType, WasmCapabilities, detectRuntime, getRuntimeInfo, getRuntim
|
|
|
101
101
|
* ```
|
|
102
102
|
*/
|
|
103
103
|
|
|
104
|
-
/**
|
|
105
|
-
* Initialize the WASM module
|
|
106
|
-
*
|
|
107
|
-
* This function must be called once before using any extraction functions.
|
|
108
|
-
* It loads and initializes the WASM module in the current runtime environment,
|
|
109
|
-
* automatically selecting the appropriate WASM variant for the detected runtime.
|
|
110
|
-
*
|
|
111
|
-
* Multiple calls to initWasm() are safe and will return immediately if already initialized.
|
|
112
|
-
*
|
|
113
|
-
* @throws {Error} If WASM module fails to load or is not supported in the current environment
|
|
114
|
-
*
|
|
115
|
-
* @example Basic Usage
|
|
116
|
-
* ```typescript
|
|
117
|
-
* import { initWasm } from '@kreuzberg/wasm';
|
|
118
|
-
*
|
|
119
|
-
* async function main() {
|
|
120
|
-
* await initWasm();
|
|
121
|
-
* // Now you can use extraction functions
|
|
122
|
-
* }
|
|
123
|
-
*
|
|
124
|
-
* main().catch(console.error);
|
|
125
|
-
* ```
|
|
126
|
-
*
|
|
127
|
-
* @example With Error Handling
|
|
128
|
-
* ```typescript
|
|
129
|
-
* import { initWasm, getWasmCapabilities } from '@kreuzberg/wasm';
|
|
130
|
-
*
|
|
131
|
-
* async function initializeKreuzberg() {
|
|
132
|
-
* const caps = getWasmCapabilities();
|
|
133
|
-
* if (!caps.hasWasm) {
|
|
134
|
-
* throw new Error('WebAssembly is not supported in this environment');
|
|
135
|
-
* }
|
|
136
|
-
*
|
|
137
|
-
* try {
|
|
138
|
-
* await initWasm();
|
|
139
|
-
* console.log('Kreuzberg initialized successfully');
|
|
140
|
-
* } catch (error) {
|
|
141
|
-
* console.error('Failed to initialize Kreuzberg:', error);
|
|
142
|
-
* throw error;
|
|
143
|
-
* }
|
|
144
|
-
* }
|
|
145
|
-
* ```
|
|
146
|
-
*/
|
|
147
104
|
declare function initWasm(): Promise<void>;
|
|
148
105
|
/**
|
|
149
106
|
* Check if WASM module is initialized
|
package/dist/index.js
CHANGED
|
@@ -3956,6 +3956,25 @@ var wasm = null;
|
|
|
3956
3956
|
var initialized = false;
|
|
3957
3957
|
var initializationError = null;
|
|
3958
3958
|
var initializationPromise = null;
|
|
3959
|
+
async function initializePdfiumAsync(wasmModule) {
|
|
3960
|
+
if (!wasmModule || typeof wasmModule.initialize_pdfium_render !== "function") {
|
|
3961
|
+
return;
|
|
3962
|
+
}
|
|
3963
|
+
if (!isBrowser()) {
|
|
3964
|
+
console.debug("PDFium initialization skipped (non-browser environment)");
|
|
3965
|
+
return;
|
|
3966
|
+
}
|
|
3967
|
+
try {
|
|
3968
|
+
const pdfiumModule = await import("./pdfium.js");
|
|
3969
|
+
const pdfium = typeof pdfiumModule.default === "function" ? await pdfiumModule.default() : pdfiumModule;
|
|
3970
|
+
const success = wasmModule.initialize_pdfium_render(pdfium, wasmModule, false);
|
|
3971
|
+
if (!success) {
|
|
3972
|
+
console.warn("PDFium initialization returned false");
|
|
3973
|
+
}
|
|
3974
|
+
} catch (error) {
|
|
3975
|
+
console.debug("PDFium initialization error:", error);
|
|
3976
|
+
}
|
|
3977
|
+
}
|
|
3959
3978
|
async function initWasm() {
|
|
3960
3979
|
if (initialized) {
|
|
3961
3980
|
return;
|
|
@@ -3970,7 +3989,7 @@ async function initWasm() {
|
|
|
3970
3989
|
}
|
|
3971
3990
|
let wasmModule;
|
|
3972
3991
|
try {
|
|
3973
|
-
wasmModule = await import("
|
|
3992
|
+
wasmModule = await import("./pkg/kreuzberg_wasm.js");
|
|
3974
3993
|
} catch {
|
|
3975
3994
|
wasmModule = await import("./kreuzberg_wasm.js");
|
|
3976
3995
|
}
|
|
@@ -3978,6 +3997,11 @@ async function initWasm() {
|
|
|
3978
3997
|
if (wasm && typeof wasm.default === "function") {
|
|
3979
3998
|
await wasm.default();
|
|
3980
3999
|
}
|
|
4000
|
+
if (isBrowser() && wasm && typeof wasm.initialize_pdfium_render === "function") {
|
|
4001
|
+
initializePdfiumAsync(wasm).catch((error) => {
|
|
4002
|
+
console.warn("PDFium auto-initialization failed (PDF extraction disabled):", error);
|
|
4003
|
+
});
|
|
4004
|
+
}
|
|
3981
4005
|
initialized = true;
|
|
3982
4006
|
initializationError = null;
|
|
3983
4007
|
} catch (error) {
|