@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,256 @@
|
|
|
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 };
|
|
@@ -0,0 +1,256 @@
|
|
|
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 };
|
package/dist/runtime.js
ADDED
|
@@ -0,0 +1,172 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __defProp = Object.defineProperty;
|
|
3
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
4
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
5
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
6
|
+
var __export = (target, all) => {
|
|
7
|
+
for (var name in all)
|
|
8
|
+
__defProp(target, name, { get: all[name], enumerable: true });
|
|
9
|
+
};
|
|
10
|
+
var __copyProps = (to, from, except, desc) => {
|
|
11
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
|
12
|
+
for (let key of __getOwnPropNames(from))
|
|
13
|
+
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
14
|
+
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
15
|
+
}
|
|
16
|
+
return to;
|
|
17
|
+
};
|
|
18
|
+
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
19
|
+
var runtime_exports = {};
|
|
20
|
+
__export(runtime_exports, {
|
|
21
|
+
detectRuntime: () => detectRuntime,
|
|
22
|
+
getRuntimeInfo: () => getRuntimeInfo,
|
|
23
|
+
getRuntimeVersion: () => getRuntimeVersion,
|
|
24
|
+
getWasmCapabilities: () => getWasmCapabilities,
|
|
25
|
+
hasBigInt: () => hasBigInt,
|
|
26
|
+
hasBlob: () => hasBlob,
|
|
27
|
+
hasFileApi: () => hasFileApi,
|
|
28
|
+
hasModuleWorkers: () => hasModuleWorkers,
|
|
29
|
+
hasSharedArrayBuffer: () => hasSharedArrayBuffer,
|
|
30
|
+
hasWasm: () => hasWasm,
|
|
31
|
+
hasWasmStreaming: () => hasWasmStreaming,
|
|
32
|
+
hasWorkers: () => hasWorkers,
|
|
33
|
+
isBrowser: () => isBrowser,
|
|
34
|
+
isBun: () => isBun,
|
|
35
|
+
isDeno: () => isDeno,
|
|
36
|
+
isNode: () => isNode,
|
|
37
|
+
isServerEnvironment: () => isServerEnvironment,
|
|
38
|
+
isWebEnvironment: () => isWebEnvironment
|
|
39
|
+
});
|
|
40
|
+
module.exports = __toCommonJS(runtime_exports);
|
|
41
|
+
function detectRuntime() {
|
|
42
|
+
if (typeof globalThis.Deno !== "undefined") {
|
|
43
|
+
return "deno";
|
|
44
|
+
}
|
|
45
|
+
if (typeof globalThis.Bun !== "undefined") {
|
|
46
|
+
return "bun";
|
|
47
|
+
}
|
|
48
|
+
if (typeof process !== "undefined" && process.versions && process.versions.node) {
|
|
49
|
+
return "node";
|
|
50
|
+
}
|
|
51
|
+
if (typeof window !== "undefined" && typeof document !== "undefined") {
|
|
52
|
+
return "browser";
|
|
53
|
+
}
|
|
54
|
+
return "unknown";
|
|
55
|
+
}
|
|
56
|
+
function isBrowser() {
|
|
57
|
+
return detectRuntime() === "browser";
|
|
58
|
+
}
|
|
59
|
+
function isNode() {
|
|
60
|
+
return detectRuntime() === "node";
|
|
61
|
+
}
|
|
62
|
+
function isDeno() {
|
|
63
|
+
return detectRuntime() === "deno";
|
|
64
|
+
}
|
|
65
|
+
function isBun() {
|
|
66
|
+
return detectRuntime() === "bun";
|
|
67
|
+
}
|
|
68
|
+
function isWebEnvironment() {
|
|
69
|
+
const runtime = detectRuntime();
|
|
70
|
+
return runtime === "browser";
|
|
71
|
+
}
|
|
72
|
+
function isServerEnvironment() {
|
|
73
|
+
const runtime = detectRuntime();
|
|
74
|
+
return runtime === "node" || runtime === "deno" || runtime === "bun";
|
|
75
|
+
}
|
|
76
|
+
function hasFileApi() {
|
|
77
|
+
return typeof window !== "undefined" && typeof File !== "undefined" && typeof Blob !== "undefined";
|
|
78
|
+
}
|
|
79
|
+
function hasBlob() {
|
|
80
|
+
return typeof Blob !== "undefined";
|
|
81
|
+
}
|
|
82
|
+
function hasWorkers() {
|
|
83
|
+
return typeof Worker !== "undefined";
|
|
84
|
+
}
|
|
85
|
+
function hasSharedArrayBuffer() {
|
|
86
|
+
return typeof SharedArrayBuffer !== "undefined";
|
|
87
|
+
}
|
|
88
|
+
function hasModuleWorkers() {
|
|
89
|
+
if (!hasWorkers()) {
|
|
90
|
+
return false;
|
|
91
|
+
}
|
|
92
|
+
try {
|
|
93
|
+
const blob = new Blob(['console.log("test")'], {
|
|
94
|
+
type: "application/javascript"
|
|
95
|
+
});
|
|
96
|
+
const workerUrl = URL.createObjectURL(blob);
|
|
97
|
+
try {
|
|
98
|
+
return true;
|
|
99
|
+
} finally {
|
|
100
|
+
URL.revokeObjectURL(workerUrl);
|
|
101
|
+
}
|
|
102
|
+
} catch {
|
|
103
|
+
return false;
|
|
104
|
+
}
|
|
105
|
+
}
|
|
106
|
+
function hasWasm() {
|
|
107
|
+
return typeof WebAssembly !== "undefined" && WebAssembly.instantiate !== void 0;
|
|
108
|
+
}
|
|
109
|
+
function hasWasmStreaming() {
|
|
110
|
+
return typeof WebAssembly !== "undefined" && WebAssembly.instantiateStreaming !== void 0;
|
|
111
|
+
}
|
|
112
|
+
function hasBigInt() {
|
|
113
|
+
try {
|
|
114
|
+
const test = BigInt("1");
|
|
115
|
+
return typeof test === "bigint";
|
|
116
|
+
} catch {
|
|
117
|
+
return false;
|
|
118
|
+
}
|
|
119
|
+
}
|
|
120
|
+
function getRuntimeVersion() {
|
|
121
|
+
const runtime = detectRuntime();
|
|
122
|
+
switch (runtime) {
|
|
123
|
+
case "node":
|
|
124
|
+
return process.version?.substring(1);
|
|
125
|
+
// Remove 'v' prefix
|
|
126
|
+
case "deno": {
|
|
127
|
+
const deno = globalThis.Deno;
|
|
128
|
+
const version = deno?.version;
|
|
129
|
+
return version?.deno;
|
|
130
|
+
}
|
|
131
|
+
case "bun": {
|
|
132
|
+
const bun = globalThis.Bun;
|
|
133
|
+
return bun?.version;
|
|
134
|
+
}
|
|
135
|
+
default:
|
|
136
|
+
return void 0;
|
|
137
|
+
}
|
|
138
|
+
}
|
|
139
|
+
function getWasmCapabilities() {
|
|
140
|
+
const runtime = detectRuntime();
|
|
141
|
+
const version = getRuntimeVersion();
|
|
142
|
+
const capabilities = {
|
|
143
|
+
runtime,
|
|
144
|
+
hasWasm: hasWasm(),
|
|
145
|
+
hasWasmStreaming: hasWasmStreaming(),
|
|
146
|
+
hasFileApi: hasFileApi(),
|
|
147
|
+
hasBlob: hasBlob(),
|
|
148
|
+
hasWorkers: hasWorkers(),
|
|
149
|
+
hasSharedArrayBuffer: hasSharedArrayBuffer(),
|
|
150
|
+
hasModuleWorkers: hasModuleWorkers(),
|
|
151
|
+
hasBigInt: hasBigInt(),
|
|
152
|
+
...version !== void 0 ? { runtimeVersion: version } : {}
|
|
153
|
+
};
|
|
154
|
+
return capabilities;
|
|
155
|
+
}
|
|
156
|
+
function getRuntimeInfo() {
|
|
157
|
+
const runtime = detectRuntime();
|
|
158
|
+
const capabilities = getWasmCapabilities();
|
|
159
|
+
return {
|
|
160
|
+
runtime,
|
|
161
|
+
isBrowser: isBrowser(),
|
|
162
|
+
isNode: isNode(),
|
|
163
|
+
isDeno: isDeno(),
|
|
164
|
+
isBun: isBun(),
|
|
165
|
+
isWeb: isWebEnvironment(),
|
|
166
|
+
isServer: isServerEnvironment(),
|
|
167
|
+
runtimeVersion: getRuntimeVersion(),
|
|
168
|
+
userAgent: typeof navigator !== "undefined" ? navigator.userAgent : "N/A",
|
|
169
|
+
capabilities
|
|
170
|
+
};
|
|
171
|
+
}
|
|
172
|
+
//# sourceMappingURL=runtime.js.map
|