whitebox-wasm 0.1.0

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/package.json ADDED
@@ -0,0 +1,29 @@
1
+ {
2
+ "name": "whitebox-wasm",
3
+ "type": "module",
4
+ "description": "WebAssembly bindings for the pure-Rust Whitebox GeoTIFF engine",
5
+ "version": "0.1.0",
6
+ "license": "MIT OR Apache-2.0",
7
+ "repository": {
8
+ "type": "git",
9
+ "url": "https://github.com/opengeos/whitebox-wasm"
10
+ },
11
+ "files": [
12
+ "whitebox_wasm_bg.wasm",
13
+ "whitebox_wasm.js",
14
+ "whitebox_wasm.d.ts"
15
+ ],
16
+ "main": "whitebox_wasm.js",
17
+ "homepage": "https://github.com/opengeos/whitebox-wasm",
18
+ "types": "whitebox_wasm.d.ts",
19
+ "sideEffects": [
20
+ "./snippets/*"
21
+ ],
22
+ "keywords": [
23
+ "geotiff",
24
+ "wasm",
25
+ "gis",
26
+ "raster",
27
+ "webassembly"
28
+ ]
29
+ }
@@ -0,0 +1,59 @@
1
+ /* tslint:disable */
2
+ /* eslint-disable */
3
+
4
+ /**
5
+ * Decode a GeoTIFF and return only its georeferencing/shape metadata as JSON:
6
+ * `{"ok":true,"width":W,"height":H,"bands":B,"epsg":E|null,"nodata":V|null}`.
7
+ */
8
+ export function geotiff_info(data: Uint8Array): string;
9
+
10
+ /**
11
+ * Decode a GeoTIFF from raw bytes and return summary statistics as a JSON string.
12
+ *
13
+ * The returned JSON has the shape:
14
+ * `{"ok":true,"width":W,"height":H,"bands":B,"epsg":E|null,"valid":N,
15
+ * "min":..,"max":..,"mean":..}` on success, or
16
+ * `{"ok":false,"error":"..."}` on failure.
17
+ *
18
+ * Statistics are computed over band 0, skipping NaN and the nodata value.
19
+ */
20
+ export function geotiff_stats(data: Uint8Array): string;
21
+
22
+ /**
23
+ * Semantic version of this crate, exposed for runtime feature detection.
24
+ */
25
+ export function version(): string;
26
+
27
+ export type InitInput = RequestInfo | URL | Response | BufferSource | WebAssembly.Module;
28
+
29
+ export interface InitOutput {
30
+ readonly memory: WebAssembly.Memory;
31
+ readonly geotiff_info: (a: number, b: number, c: number) => void;
32
+ readonly geotiff_stats: (a: number, b: number, c: number) => void;
33
+ readonly version: (a: number) => void;
34
+ readonly __wbindgen_add_to_stack_pointer: (a: number) => number;
35
+ readonly __wbindgen_export: (a: number, b: number) => number;
36
+ readonly __wbindgen_export2: (a: number, b: number, c: number) => void;
37
+ }
38
+
39
+ export type SyncInitInput = BufferSource | WebAssembly.Module;
40
+
41
+ /**
42
+ * Instantiates the given `module`, which can either be bytes or
43
+ * a precompiled `WebAssembly.Module`.
44
+ *
45
+ * @param {{ module: SyncInitInput }} module - Passing `SyncInitInput` directly is deprecated.
46
+ *
47
+ * @returns {InitOutput}
48
+ */
49
+ export function initSync(module: { module: SyncInitInput } | SyncInitInput): InitOutput;
50
+
51
+ /**
52
+ * If `module_or_path` is {RequestInfo} or {URL}, makes a request and
53
+ * for everything else, calls `WebAssembly.instantiate` directly.
54
+ *
55
+ * @param {{ module_or_path: InitInput | Promise<InitInput> }} module_or_path - Passing `InitInput` directly is deprecated.
56
+ *
57
+ * @returns {Promise<InitOutput>}
58
+ */
59
+ export default function __wbg_init (module_or_path?: { module_or_path: InitInput | Promise<InitInput> } | InitInput | Promise<InitInput>): Promise<InitOutput>;
@@ -0,0 +1,223 @@
1
+ /* @ts-self-types="./whitebox_wasm.d.ts" */
2
+
3
+ /**
4
+ * Decode a GeoTIFF and return only its georeferencing/shape metadata as JSON:
5
+ * `{"ok":true,"width":W,"height":H,"bands":B,"epsg":E|null,"nodata":V|null}`.
6
+ * @param {Uint8Array} data
7
+ * @returns {string}
8
+ */
9
+ export function geotiff_info(data) {
10
+ let deferred2_0;
11
+ let deferred2_1;
12
+ try {
13
+ const retptr = wasm.__wbindgen_add_to_stack_pointer(-16);
14
+ const ptr0 = passArray8ToWasm0(data, wasm.__wbindgen_export);
15
+ const len0 = WASM_VECTOR_LEN;
16
+ wasm.geotiff_info(retptr, ptr0, len0);
17
+ var r0 = getDataViewMemory0().getInt32(retptr + 4 * 0, true);
18
+ var r1 = getDataViewMemory0().getInt32(retptr + 4 * 1, true);
19
+ deferred2_0 = r0;
20
+ deferred2_1 = r1;
21
+ return getStringFromWasm0(r0, r1);
22
+ } finally {
23
+ wasm.__wbindgen_add_to_stack_pointer(16);
24
+ wasm.__wbindgen_export2(deferred2_0, deferred2_1, 1);
25
+ }
26
+ }
27
+
28
+ /**
29
+ * Decode a GeoTIFF from raw bytes and return summary statistics as a JSON string.
30
+ *
31
+ * The returned JSON has the shape:
32
+ * `{"ok":true,"width":W,"height":H,"bands":B,"epsg":E|null,"valid":N,
33
+ * "min":..,"max":..,"mean":..}` on success, or
34
+ * `{"ok":false,"error":"..."}` on failure.
35
+ *
36
+ * Statistics are computed over band 0, skipping NaN and the nodata value.
37
+ * @param {Uint8Array} data
38
+ * @returns {string}
39
+ */
40
+ export function geotiff_stats(data) {
41
+ let deferred2_0;
42
+ let deferred2_1;
43
+ try {
44
+ const retptr = wasm.__wbindgen_add_to_stack_pointer(-16);
45
+ const ptr0 = passArray8ToWasm0(data, wasm.__wbindgen_export);
46
+ const len0 = WASM_VECTOR_LEN;
47
+ wasm.geotiff_stats(retptr, ptr0, len0);
48
+ var r0 = getDataViewMemory0().getInt32(retptr + 4 * 0, true);
49
+ var r1 = getDataViewMemory0().getInt32(retptr + 4 * 1, true);
50
+ deferred2_0 = r0;
51
+ deferred2_1 = r1;
52
+ return getStringFromWasm0(r0, r1);
53
+ } finally {
54
+ wasm.__wbindgen_add_to_stack_pointer(16);
55
+ wasm.__wbindgen_export2(deferred2_0, deferred2_1, 1);
56
+ }
57
+ }
58
+
59
+ /**
60
+ * Semantic version of this crate, exposed for runtime feature detection.
61
+ * @returns {string}
62
+ */
63
+ export function version() {
64
+ let deferred1_0;
65
+ let deferred1_1;
66
+ try {
67
+ const retptr = wasm.__wbindgen_add_to_stack_pointer(-16);
68
+ wasm.version(retptr);
69
+ var r0 = getDataViewMemory0().getInt32(retptr + 4 * 0, true);
70
+ var r1 = getDataViewMemory0().getInt32(retptr + 4 * 1, true);
71
+ deferred1_0 = r0;
72
+ deferred1_1 = r1;
73
+ return getStringFromWasm0(r0, r1);
74
+ } finally {
75
+ wasm.__wbindgen_add_to_stack_pointer(16);
76
+ wasm.__wbindgen_export2(deferred1_0, deferred1_1, 1);
77
+ }
78
+ }
79
+ function __wbg_get_imports() {
80
+ const import0 = {
81
+ __proto__: null,
82
+ };
83
+ return {
84
+ __proto__: null,
85
+ "./whitebox_wasm_bg.js": import0,
86
+ };
87
+ }
88
+
89
+ let cachedDataViewMemory0 = null;
90
+ function getDataViewMemory0() {
91
+ if (cachedDataViewMemory0 === null || cachedDataViewMemory0.buffer.detached === true || (cachedDataViewMemory0.buffer.detached === undefined && cachedDataViewMemory0.buffer !== wasm.memory.buffer)) {
92
+ cachedDataViewMemory0 = new DataView(wasm.memory.buffer);
93
+ }
94
+ return cachedDataViewMemory0;
95
+ }
96
+
97
+ function getStringFromWasm0(ptr, len) {
98
+ return decodeText(ptr >>> 0, len);
99
+ }
100
+
101
+ let cachedUint8ArrayMemory0 = null;
102
+ function getUint8ArrayMemory0() {
103
+ if (cachedUint8ArrayMemory0 === null || cachedUint8ArrayMemory0.byteLength === 0) {
104
+ cachedUint8ArrayMemory0 = new Uint8Array(wasm.memory.buffer);
105
+ }
106
+ return cachedUint8ArrayMemory0;
107
+ }
108
+
109
+ function passArray8ToWasm0(arg, malloc) {
110
+ const ptr = malloc(arg.length * 1, 1) >>> 0;
111
+ getUint8ArrayMemory0().set(arg, ptr / 1);
112
+ WASM_VECTOR_LEN = arg.length;
113
+ return ptr;
114
+ }
115
+
116
+ let cachedTextDecoder = new TextDecoder('utf-8', { ignoreBOM: true, fatal: true });
117
+ cachedTextDecoder.decode();
118
+ const MAX_SAFARI_DECODE_BYTES = 2146435072;
119
+ let numBytesDecoded = 0;
120
+ function decodeText(ptr, len) {
121
+ numBytesDecoded += len;
122
+ if (numBytesDecoded >= MAX_SAFARI_DECODE_BYTES) {
123
+ cachedTextDecoder = new TextDecoder('utf-8', { ignoreBOM: true, fatal: true });
124
+ cachedTextDecoder.decode();
125
+ numBytesDecoded = len;
126
+ }
127
+ return cachedTextDecoder.decode(getUint8ArrayMemory0().subarray(ptr, ptr + len));
128
+ }
129
+
130
+ let WASM_VECTOR_LEN = 0;
131
+
132
+ let wasmModule, wasmInstance, wasm;
133
+ function __wbg_finalize_init(instance, module) {
134
+ wasmInstance = instance;
135
+ wasm = instance.exports;
136
+ wasmModule = module;
137
+ cachedDataViewMemory0 = null;
138
+ cachedUint8ArrayMemory0 = null;
139
+ return wasm;
140
+ }
141
+
142
+ async function __wbg_load(module, imports) {
143
+ if (typeof Response === 'function' && module instanceof Response) {
144
+ if (typeof WebAssembly.instantiateStreaming === 'function') {
145
+ try {
146
+ return await WebAssembly.instantiateStreaming(module, imports);
147
+ } catch (e) {
148
+ const validResponse = module.ok && expectedResponseType(module.type);
149
+
150
+ if (validResponse && module.headers.get('Content-Type') !== 'application/wasm') {
151
+ console.warn("`WebAssembly.instantiateStreaming` failed because your server does not serve Wasm with `application/wasm` MIME type. Falling back to `WebAssembly.instantiate` which is slower. Original error:\n", e);
152
+
153
+ } else { throw e; }
154
+ }
155
+ }
156
+
157
+ const bytes = await module.arrayBuffer();
158
+ return await WebAssembly.instantiate(bytes, imports);
159
+ } else {
160
+ const instance = await WebAssembly.instantiate(module, imports);
161
+
162
+ if (instance instanceof WebAssembly.Instance) {
163
+ return { instance, module };
164
+ } else {
165
+ return instance;
166
+ }
167
+ }
168
+
169
+ function expectedResponseType(type) {
170
+ switch (type) {
171
+ case 'basic': case 'cors': case 'default': return true;
172
+ }
173
+ return false;
174
+ }
175
+ }
176
+
177
+ function initSync(module) {
178
+ if (wasm !== undefined) return wasm;
179
+
180
+
181
+ if (module !== undefined) {
182
+ if (Object.getPrototypeOf(module) === Object.prototype) {
183
+ ({module} = module)
184
+ } else {
185
+ console.warn('using deprecated parameters for `initSync()`; pass a single object instead')
186
+ }
187
+ }
188
+
189
+ const imports = __wbg_get_imports();
190
+ if (!(module instanceof WebAssembly.Module)) {
191
+ module = new WebAssembly.Module(module);
192
+ }
193
+ const instance = new WebAssembly.Instance(module, imports);
194
+ return __wbg_finalize_init(instance, module);
195
+ }
196
+
197
+ async function __wbg_init(module_or_path) {
198
+ if (wasm !== undefined) return wasm;
199
+
200
+
201
+ if (module_or_path !== undefined) {
202
+ if (Object.getPrototypeOf(module_or_path) === Object.prototype) {
203
+ ({module_or_path} = module_or_path)
204
+ } else {
205
+ console.warn('using deprecated parameters for the initialization function; pass a single object instead')
206
+ }
207
+ }
208
+
209
+ if (module_or_path === undefined) {
210
+ module_or_path = new URL('whitebox_wasm_bg.wasm', import.meta.url);
211
+ }
212
+ const imports = __wbg_get_imports();
213
+
214
+ if (typeof module_or_path === 'string' || (typeof Request === 'function' && module_or_path instanceof Request) || (typeof URL === 'function' && module_or_path instanceof URL)) {
215
+ module_or_path = fetch(module_or_path);
216
+ }
217
+
218
+ const { instance, module } = await __wbg_load(await module_or_path, imports);
219
+
220
+ return __wbg_finalize_init(instance, module);
221
+ }
222
+
223
+ export { initSync, __wbg_init as default };
Binary file