@kreuzberg/wasm 4.0.0-rc.10

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.
@@ -0,0 +1,174 @@
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
+
20
+ // typescript/runtime.ts
21
+ var runtime_exports = {};
22
+ __export(runtime_exports, {
23
+ detectRuntime: () => detectRuntime,
24
+ getRuntimeInfo: () => getRuntimeInfo,
25
+ getRuntimeVersion: () => getRuntimeVersion,
26
+ getWasmCapabilities: () => getWasmCapabilities,
27
+ hasBigInt: () => hasBigInt,
28
+ hasBlob: () => hasBlob,
29
+ hasFileApi: () => hasFileApi,
30
+ hasModuleWorkers: () => hasModuleWorkers,
31
+ hasSharedArrayBuffer: () => hasSharedArrayBuffer,
32
+ hasWasm: () => hasWasm,
33
+ hasWasmStreaming: () => hasWasmStreaming,
34
+ hasWorkers: () => hasWorkers,
35
+ isBrowser: () => isBrowser,
36
+ isBun: () => isBun,
37
+ isDeno: () => isDeno,
38
+ isNode: () => isNode,
39
+ isServerEnvironment: () => isServerEnvironment,
40
+ isWebEnvironment: () => isWebEnvironment
41
+ });
42
+ module.exports = __toCommonJS(runtime_exports);
43
+ function detectRuntime() {
44
+ if (typeof globalThis.Deno !== "undefined") {
45
+ return "deno";
46
+ }
47
+ if (typeof globalThis.Bun !== "undefined") {
48
+ return "bun";
49
+ }
50
+ if (typeof process !== "undefined" && process.versions && process.versions.node) {
51
+ return "node";
52
+ }
53
+ if (typeof window !== "undefined" && typeof document !== "undefined") {
54
+ return "browser";
55
+ }
56
+ return "unknown";
57
+ }
58
+ function isBrowser() {
59
+ return detectRuntime() === "browser";
60
+ }
61
+ function isNode() {
62
+ return detectRuntime() === "node";
63
+ }
64
+ function isDeno() {
65
+ return detectRuntime() === "deno";
66
+ }
67
+ function isBun() {
68
+ return detectRuntime() === "bun";
69
+ }
70
+ function isWebEnvironment() {
71
+ const runtime = detectRuntime();
72
+ return runtime === "browser";
73
+ }
74
+ function isServerEnvironment() {
75
+ const runtime = detectRuntime();
76
+ return runtime === "node" || runtime === "deno" || runtime === "bun";
77
+ }
78
+ function hasFileApi() {
79
+ return typeof window !== "undefined" && typeof File !== "undefined" && typeof Blob !== "undefined";
80
+ }
81
+ function hasBlob() {
82
+ return typeof Blob !== "undefined";
83
+ }
84
+ function hasWorkers() {
85
+ return typeof Worker !== "undefined";
86
+ }
87
+ function hasSharedArrayBuffer() {
88
+ return typeof SharedArrayBuffer !== "undefined";
89
+ }
90
+ function hasModuleWorkers() {
91
+ if (!hasWorkers()) {
92
+ return false;
93
+ }
94
+ try {
95
+ const blob = new Blob(['console.log("test")'], {
96
+ type: "application/javascript"
97
+ });
98
+ const workerUrl = URL.createObjectURL(blob);
99
+ try {
100
+ return true;
101
+ } finally {
102
+ URL.revokeObjectURL(workerUrl);
103
+ }
104
+ } catch {
105
+ return false;
106
+ }
107
+ }
108
+ function hasWasm() {
109
+ return typeof WebAssembly !== "undefined" && WebAssembly.instantiate !== void 0;
110
+ }
111
+ function hasWasmStreaming() {
112
+ return typeof WebAssembly !== "undefined" && WebAssembly.instantiateStreaming !== void 0;
113
+ }
114
+ function hasBigInt() {
115
+ try {
116
+ const test = BigInt("1");
117
+ return typeof test === "bigint";
118
+ } catch {
119
+ return false;
120
+ }
121
+ }
122
+ function getRuntimeVersion() {
123
+ const runtime = detectRuntime();
124
+ switch (runtime) {
125
+ case "node":
126
+ return process.version?.substring(1);
127
+ // Remove 'v' prefix
128
+ case "deno": {
129
+ const deno = globalThis.Deno;
130
+ const version = deno?.version;
131
+ return version?.deno;
132
+ }
133
+ case "bun": {
134
+ const bun = globalThis.Bun;
135
+ return bun?.version;
136
+ }
137
+ default:
138
+ return void 0;
139
+ }
140
+ }
141
+ function getWasmCapabilities() {
142
+ const runtime = detectRuntime();
143
+ const version = getRuntimeVersion();
144
+ const capabilities = {
145
+ runtime,
146
+ hasWasm: hasWasm(),
147
+ hasWasmStreaming: hasWasmStreaming(),
148
+ hasFileApi: hasFileApi(),
149
+ hasBlob: hasBlob(),
150
+ hasWorkers: hasWorkers(),
151
+ hasSharedArrayBuffer: hasSharedArrayBuffer(),
152
+ hasModuleWorkers: hasModuleWorkers(),
153
+ hasBigInt: hasBigInt(),
154
+ ...version !== void 0 ? { runtimeVersion: version } : {}
155
+ };
156
+ return capabilities;
157
+ }
158
+ function getRuntimeInfo() {
159
+ const runtime = detectRuntime();
160
+ const capabilities = getWasmCapabilities();
161
+ return {
162
+ runtime,
163
+ isBrowser: isBrowser(),
164
+ isNode: isNode(),
165
+ isDeno: isDeno(),
166
+ isBun: isBun(),
167
+ isWeb: isWebEnvironment(),
168
+ isServer: isServerEnvironment(),
169
+ runtimeVersion: getRuntimeVersion(),
170
+ userAgent: typeof navigator !== "undefined" ? navigator.userAgent : "N/A",
171
+ capabilities
172
+ };
173
+ }
174
+ //# sourceMappingURL=runtime.cjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../typescript/runtime.ts"],"sourcesContent":["/**\n * Runtime detection and environment-specific utilities\n *\n * This module provides utilities for detecting the JavaScript runtime environment,\n * checking for feature availability, and enabling environment-specific WASM loading strategies.\n *\n * @example Basic Runtime Detection\n * ```typescript\n * import { detectRuntime, isBrowser, isNode } from '@kreuzberg/wasm/runtime';\n *\n * if (isBrowser()) {\n * console.log('Running in browser');\n * } else if (isNode()) {\n * console.log('Running in Node.js');\n * }\n * ```\n *\n * @example Feature Detection\n * ```typescript\n * import { hasFileApi, hasWorkers } from '@kreuzberg/wasm/runtime';\n *\n * if (hasFileApi()) {\n * // Can use File API for browser file uploads\n * }\n *\n * if (hasWorkers()) {\n * // Can use Web Workers for parallel processing\n * }\n * ```\n */\n\nexport type RuntimeType = \"browser\" | \"node\" | \"deno\" | \"bun\" | \"unknown\";\n\n/**\n * WebAssembly capabilities available in the runtime\n */\nexport interface WasmCapabilities {\n\t/** Runtime environment type */\n\truntime: RuntimeType;\n\t/** WebAssembly support available */\n\thasWasm: boolean;\n\t/** Streaming WebAssembly instantiation available */\n\thasWasmStreaming: boolean;\n\t/** File API available (browser) */\n\thasFileApi: boolean;\n\t/** Blob API available */\n\thasBlob: boolean;\n\t/** Worker support available */\n\thasWorkers: boolean;\n\t/** SharedArrayBuffer available (may be restricted) */\n\thasSharedArrayBuffer: boolean;\n\t/** Module Workers available */\n\thasModuleWorkers: boolean;\n\t/** BigInt support */\n\thasBigInt: boolean;\n\t/** Specific runtime version if available */\n\truntimeVersion?: string;\n}\n\n/**\n * Detect the current JavaScript runtime\n *\n * Checks for various global objects and properties to determine\n * which JavaScript runtime environment is currently executing.\n *\n * @returns The detected runtime type\n *\n * @example\n * ```typescript\n * import { detectRuntime } from '@kreuzberg/wasm/runtime';\n *\n * const runtime = detectRuntime();\n * switch (runtime) {\n * case 'browser':\n * console.log('Running in browser');\n * break;\n * case 'node':\n * console.log('Running in Node.js');\n * break;\n * case 'deno':\n * console.log('Running in Deno');\n * break;\n * case 'bun':\n * console.log('Running in Bun');\n * break;\n * }\n * ```\n */\nexport function detectRuntime(): RuntimeType {\n\t// Check for Deno\n\tif (typeof (globalThis as unknown as Record<string, unknown>).Deno !== \"undefined\") {\n\t\treturn \"deno\";\n\t}\n\n\t// Check for Bun\n\tif (typeof (globalThis as unknown as Record<string, unknown>).Bun !== \"undefined\") {\n\t\treturn \"bun\";\n\t}\n\n\t// Check for Node.js\n\tif (typeof process !== \"undefined\" && process.versions && process.versions.node) {\n\t\treturn \"node\";\n\t}\n\n\t// Check for browser\n\tif (typeof window !== \"undefined\" && typeof document !== \"undefined\") {\n\t\treturn \"browser\";\n\t}\n\n\treturn \"unknown\";\n}\n\n/**\n * Check if running in a browser environment\n *\n * @returns True if running in a browser, false otherwise\n */\nexport function isBrowser(): boolean {\n\treturn detectRuntime() === \"browser\";\n}\n\n/**\n * Check if running in Node.js\n *\n * @returns True if running in Node.js, false otherwise\n */\nexport function isNode(): boolean {\n\treturn detectRuntime() === \"node\";\n}\n\n/**\n * Check if running in Deno\n *\n * @returns True if running in Deno, false otherwise\n */\nexport function isDeno(): boolean {\n\treturn detectRuntime() === \"deno\";\n}\n\n/**\n * Check if running in Bun\n *\n * @returns True if running in Bun, false otherwise\n */\nexport function isBun(): boolean {\n\treturn detectRuntime() === \"bun\";\n}\n\n/**\n * Check if running in a web environment (browser or similar)\n *\n * @returns True if running in a web browser, false otherwise\n */\nexport function isWebEnvironment(): boolean {\n\tconst runtime = detectRuntime();\n\treturn runtime === \"browser\";\n}\n\n/**\n * Check if running in a server-like environment (Node.js, Deno, Bun)\n *\n * @returns True if running on a server runtime, false otherwise\n */\nexport function isServerEnvironment(): boolean {\n\tconst runtime = detectRuntime();\n\treturn runtime === \"node\" || runtime === \"deno\" || runtime === \"bun\";\n}\n\n/**\n * Check if File API is available\n *\n * The File API is required for handling browser file uploads.\n *\n * @returns True if File API is available, false otherwise\n *\n * @example\n * ```typescript\n * if (hasFileApi()) {\n * const fileInput = document.getElementById('file');\n * fileInput.addEventListener('change', (e) => {\n * const file = e.target.files?.[0];\n * // Handle file\n * });\n * }\n * ```\n */\nexport function hasFileApi(): boolean {\n\treturn typeof window !== \"undefined\" && typeof File !== \"undefined\" && typeof Blob !== \"undefined\";\n}\n\n/**\n * Check if Blob API is available\n *\n * @returns True if Blob API is available, false otherwise\n */\nexport function hasBlob(): boolean {\n\treturn typeof Blob !== \"undefined\";\n}\n\n/**\n * Check if Web Workers are available\n *\n * @returns True if Web Workers can be created, false otherwise\n */\nexport function hasWorkers(): boolean {\n\treturn typeof Worker !== \"undefined\";\n}\n\n/**\n * Check if SharedArrayBuffer is available\n *\n * Note: SharedArrayBuffer is restricted in some browser contexts\n * due to security considerations (Spectre/Meltdown mitigations).\n *\n * @returns True if SharedArrayBuffer is available, false otherwise\n */\nexport function hasSharedArrayBuffer(): boolean {\n\treturn typeof SharedArrayBuffer !== \"undefined\";\n}\n\n/**\n * Check if module workers are available\n *\n * Module workers allow importing ES modules in worker threads.\n *\n * @returns True if module workers are supported, false otherwise\n */\nexport function hasModuleWorkers(): boolean {\n\tif (!hasWorkers()) {\n\t\treturn false;\n\t}\n\n\ttry {\n\t\t// Try to detect module worker support\n\t\tconst blob = new Blob(['console.log(\"test\")'], {\n\t\t\ttype: \"application/javascript\",\n\t\t});\n\t\tconst workerUrl = URL.createObjectURL(blob);\n\t\ttry {\n\t\t\t// Module workers require type: 'module' option\n\t\t\t// We can't actually instantiate without issues, so we check the API exists\n\t\t\treturn true;\n\t\t} finally {\n\t\t\tURL.revokeObjectURL(workerUrl);\n\t\t}\n\t} catch {\n\t\treturn false;\n\t}\n}\n\n/**\n * Check if WebAssembly is available\n *\n * @returns True if WebAssembly is supported, false otherwise\n */\nexport function hasWasm(): boolean {\n\treturn typeof WebAssembly !== \"undefined\" && WebAssembly.instantiate !== undefined;\n}\n\n/**\n * Check if WebAssembly.instantiateStreaming is available\n *\n * Streaming instantiation is more efficient than buffering the entire WASM module.\n *\n * @returns True if streaming WebAssembly is supported, false otherwise\n */\nexport function hasWasmStreaming(): boolean {\n\treturn typeof WebAssembly !== \"undefined\" && WebAssembly.instantiateStreaming !== undefined;\n}\n\n/**\n * Check if BigInt is available\n *\n * @returns True if BigInt type is supported, false otherwise\n */\nexport function hasBigInt(): boolean {\n\ttry {\n\t\tconst test = BigInt(\"1\");\n\t\treturn typeof test === \"bigint\";\n\t} catch {\n\t\treturn false;\n\t}\n}\n\n/**\n * Get runtime version information\n *\n * @returns Version string if available, undefined otherwise\n *\n * @example\n * ```typescript\n * const version = getRuntimeVersion();\n * console.log(`Running on Node ${version}`); // \"Running on Node 18.12.0\"\n * ```\n */\nexport function getRuntimeVersion(): string | undefined {\n\tconst runtime = detectRuntime();\n\n\tswitch (runtime) {\n\t\tcase \"node\":\n\t\t\treturn process.version?.substring(1); // Remove 'v' prefix\n\t\tcase \"deno\": {\n\t\t\tconst deno = (globalThis as unknown as Record<string, unknown>).Deno as Record<string, unknown> | undefined;\n\t\t\tconst version = deno?.version as Record<string, unknown> | undefined;\n\t\t\treturn version?.deno as string | undefined;\n\t\t}\n\t\tcase \"bun\": {\n\t\t\tconst bun = (globalThis as unknown as Record<string, unknown>).Bun as Record<string, unknown> | undefined;\n\t\t\treturn bun?.version as string | undefined;\n\t\t}\n\t\tdefault:\n\t\t\treturn undefined;\n\t}\n}\n\n/**\n * Get comprehensive WebAssembly capabilities for current runtime\n *\n * Returns detailed information about WASM and related APIs available\n * in the current runtime environment.\n *\n * @returns Object describing available WASM capabilities\n *\n * @example\n * ```typescript\n * import { getWasmCapabilities } from '@kreuzberg/wasm/runtime';\n *\n * const caps = getWasmCapabilities();\n * console.log(`WASM available: ${caps.hasWasm}`);\n * console.log(`Streaming WASM: ${caps.hasWasmStreaming}`);\n * console.log(`Workers available: ${caps.hasWorkers}`);\n *\n * if (caps.hasWasm && caps.hasWorkers) {\n * // Can offload WASM processing to workers\n * }\n * ```\n */\nexport function getWasmCapabilities(): WasmCapabilities {\n\tconst runtime = detectRuntime();\n\tconst version = getRuntimeVersion();\n\tconst capabilities: WasmCapabilities = {\n\t\truntime,\n\t\thasWasm: hasWasm(),\n\t\thasWasmStreaming: hasWasmStreaming(),\n\t\thasFileApi: hasFileApi(),\n\t\thasBlob: hasBlob(),\n\t\thasWorkers: hasWorkers(),\n\t\thasSharedArrayBuffer: hasSharedArrayBuffer(),\n\t\thasModuleWorkers: hasModuleWorkers(),\n\t\thasBigInt: hasBigInt(),\n\t\t...(version !== undefined ? { runtimeVersion: version } : {}),\n\t};\n\treturn capabilities;\n}\n\n/**\n * Get comprehensive runtime information\n *\n * Returns detailed information about the current runtime environment,\n * capabilities, and identifying information.\n *\n * @returns Object with runtime details and capabilities\n *\n * @example\n * ```typescript\n * const info = getRuntimeInfo();\n * console.log(info.runtime); // 'browser' | 'node' | 'deno' | 'bun'\n * console.log(info.isBrowser); // true/false\n * console.log(info.userAgent); // Browser user agent string\n * console.log(info.capabilities); // Detailed capability information\n * ```\n */\nexport function getRuntimeInfo() {\n\tconst runtime = detectRuntime();\n\tconst capabilities = getWasmCapabilities();\n\n\treturn {\n\t\truntime,\n\t\tisBrowser: isBrowser(),\n\t\tisNode: isNode(),\n\t\tisDeno: isDeno(),\n\t\tisBun: isBun(),\n\t\tisWeb: isWebEnvironment(),\n\t\tisServer: isServerEnvironment(),\n\t\truntimeVersion: getRuntimeVersion(),\n\t\tuserAgent: typeof navigator !== \"undefined\" ? navigator.userAgent : \"N/A\",\n\t\tcapabilities,\n\t};\n}\n"],"mappings":"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","names":[]}
@@ -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 };