|
| 1 | + |
| 2 | +let wasm; |
| 3 | + |
| 4 | +const heap = new Array(32).fill(undefined); |
| 5 | + |
| 6 | +heap.push(undefined, null, true, false); |
| 7 | + |
| 8 | +function getObject(idx) { return heap[idx]; } |
| 9 | + |
| 10 | +let heap_next = heap.length; |
| 11 | + |
| 12 | +function dropObject(idx) { |
| 13 | + if (idx < 36) return; |
| 14 | + heap[idx] = heap_next; |
| 15 | + heap_next = idx; |
| 16 | +} |
| 17 | + |
| 18 | +function takeObject(idx) { |
| 19 | + const ret = getObject(idx); |
| 20 | + dropObject(idx); |
| 21 | + return ret; |
| 22 | +} |
| 23 | + |
| 24 | +let cachedTextDecoder = new TextDecoder('utf-8', { ignoreBOM: true, fatal: true }); |
| 25 | + |
| 26 | +cachedTextDecoder.decode(); |
| 27 | + |
| 28 | +let cachegetUint8Memory0 = null; |
| 29 | +function getUint8Memory0() { |
| 30 | + if (cachegetUint8Memory0 === null || cachegetUint8Memory0.buffer !== wasm.memory.buffer) { |
| 31 | + cachegetUint8Memory0 = new Uint8Array(wasm.memory.buffer); |
| 32 | + } |
| 33 | + return cachegetUint8Memory0; |
| 34 | +} |
| 35 | + |
| 36 | +function getStringFromWasm0(ptr, len) { |
| 37 | + return cachedTextDecoder.decode(getUint8Memory0().subarray(ptr, ptr + len)); |
| 38 | +} |
| 39 | +/** |
| 40 | +*/ |
| 41 | +export function greet() { |
| 42 | + wasm.greet(); |
| 43 | +} |
| 44 | + |
| 45 | +let WASM_VECTOR_LEN = 0; |
| 46 | + |
| 47 | +let cachedTextEncoder = new TextEncoder('utf-8'); |
| 48 | + |
| 49 | +const encodeString = (typeof cachedTextEncoder.encodeInto === 'function' |
| 50 | + ? function (arg, view) { |
| 51 | + return cachedTextEncoder.encodeInto(arg, view); |
| 52 | +} |
| 53 | + : function (arg, view) { |
| 54 | + const buf = cachedTextEncoder.encode(arg); |
| 55 | + view.set(buf); |
| 56 | + return { |
| 57 | + read: arg.length, |
| 58 | + written: buf.length |
| 59 | + }; |
| 60 | +}); |
| 61 | + |
| 62 | +function passStringToWasm0(arg, malloc, realloc) { |
| 63 | + |
| 64 | + if (realloc === undefined) { |
| 65 | + const buf = cachedTextEncoder.encode(arg); |
| 66 | + const ptr = malloc(buf.length); |
| 67 | + getUint8Memory0().subarray(ptr, ptr + buf.length).set(buf); |
| 68 | + WASM_VECTOR_LEN = buf.length; |
| 69 | + return ptr; |
| 70 | + } |
| 71 | + |
| 72 | + let len = arg.length; |
| 73 | + let ptr = malloc(len); |
| 74 | + |
| 75 | + const mem = getUint8Memory0(); |
| 76 | + |
| 77 | + let offset = 0; |
| 78 | + |
| 79 | + for (; offset < len; offset++) { |
| 80 | + const code = arg.charCodeAt(offset); |
| 81 | + if (code > 0x7F) break; |
| 82 | + mem[ptr + offset] = code; |
| 83 | + } |
| 84 | + |
| 85 | + if (offset !== len) { |
| 86 | + if (offset !== 0) { |
| 87 | + arg = arg.slice(offset); |
| 88 | + } |
| 89 | + ptr = realloc(ptr, len, len = offset + arg.length * 3); |
| 90 | + const view = getUint8Memory0().subarray(ptr + offset, ptr + len); |
| 91 | + const ret = encodeString(arg, view); |
| 92 | + |
| 93 | + offset += ret.written; |
| 94 | + } |
| 95 | + |
| 96 | + WASM_VECTOR_LEN = offset; |
| 97 | + return ptr; |
| 98 | +} |
| 99 | + |
| 100 | +let cachegetInt32Memory0 = null; |
| 101 | +function getInt32Memory0() { |
| 102 | + if (cachegetInt32Memory0 === null || cachegetInt32Memory0.buffer !== wasm.memory.buffer) { |
| 103 | + cachegetInt32Memory0 = new Int32Array(wasm.memory.buffer); |
| 104 | + } |
| 105 | + return cachegetInt32Memory0; |
| 106 | +} |
| 107 | +/** |
| 108 | +* @param {string} s |
| 109 | +* @returns {string} |
| 110 | +*/ |
| 111 | +export function analyze_gpx(s) { |
| 112 | + try { |
| 113 | + const retptr = wasm.__wbindgen_add_to_stack_pointer(-16); |
| 114 | + var ptr0 = passStringToWasm0(s, wasm.__wbindgen_malloc, wasm.__wbindgen_realloc); |
| 115 | + var len0 = WASM_VECTOR_LEN; |
| 116 | + wasm.analyze_gpx(retptr, ptr0, len0); |
| 117 | + var r0 = getInt32Memory0()[retptr / 4 + 0]; |
| 118 | + var r1 = getInt32Memory0()[retptr / 4 + 1]; |
| 119 | + return getStringFromWasm0(r0, r1); |
| 120 | + } finally { |
| 121 | + wasm.__wbindgen_add_to_stack_pointer(16); |
| 122 | + wasm.__wbindgen_free(r0, r1); |
| 123 | + } |
| 124 | +} |
| 125 | + |
| 126 | +/** |
| 127 | +* @param {string} s |
| 128 | +* @returns {string} |
| 129 | +*/ |
| 130 | +export function analyze_tcx(s) { |
| 131 | + try { |
| 132 | + const retptr = wasm.__wbindgen_add_to_stack_pointer(-16); |
| 133 | + var ptr0 = passStringToWasm0(s, wasm.__wbindgen_malloc, wasm.__wbindgen_realloc); |
| 134 | + var len0 = WASM_VECTOR_LEN; |
| 135 | + wasm.analyze_tcx(retptr, ptr0, len0); |
| 136 | + var r0 = getInt32Memory0()[retptr / 4 + 0]; |
| 137 | + var r1 = getInt32Memory0()[retptr / 4 + 1]; |
| 138 | + return getStringFromWasm0(r0, r1); |
| 139 | + } finally { |
| 140 | + wasm.__wbindgen_add_to_stack_pointer(16); |
| 141 | + wasm.__wbindgen_free(r0, r1); |
| 142 | + } |
| 143 | +} |
| 144 | + |
| 145 | +function addHeapObject(obj) { |
| 146 | + if (heap_next === heap.length) heap.push(heap.length + 1); |
| 147 | + const idx = heap_next; |
| 148 | + heap_next = heap[idx]; |
| 149 | + |
| 150 | + heap[idx] = obj; |
| 151 | + return idx; |
| 152 | +} |
| 153 | + |
| 154 | +async function load(module, imports) { |
| 155 | + if (typeof Response === 'function' && module instanceof Response) { |
| 156 | + if (typeof WebAssembly.instantiateStreaming === 'function') { |
| 157 | + try { |
| 158 | + return await WebAssembly.instantiateStreaming(module, imports); |
| 159 | + |
| 160 | + } catch (e) { |
| 161 | + if (module.headers.get('Content-Type') != 'application/wasm') { |
| 162 | + 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); |
| 163 | + |
| 164 | + } else { |
| 165 | + throw e; |
| 166 | + } |
| 167 | + } |
| 168 | + } |
| 169 | + |
| 170 | + const bytes = await module.arrayBuffer(); |
| 171 | + return await WebAssembly.instantiate(bytes, imports); |
| 172 | + |
| 173 | + } else { |
| 174 | + const instance = await WebAssembly.instantiate(module, imports); |
| 175 | + |
| 176 | + if (instance instanceof WebAssembly.Instance) { |
| 177 | + return { instance, module }; |
| 178 | + |
| 179 | + } else { |
| 180 | + return instance; |
| 181 | + } |
| 182 | + } |
| 183 | +} |
| 184 | + |
| 185 | +async function init(input) { |
| 186 | + if (typeof input === 'undefined') { |
| 187 | + input = new URL('activity_analyzer_bg.wasm', import.meta.url); |
| 188 | + } |
| 189 | + const imports = {}; |
| 190 | + imports.wbg = {}; |
| 191 | + imports.wbg.__wbg_alert_e9e2360dc670aa7a = function(arg0, arg1) { |
| 192 | + alert(getStringFromWasm0(arg0, arg1)); |
| 193 | + }; |
| 194 | + imports.wbg.__wbg_new_59cb74e423758ede = function() { |
| 195 | + var ret = new Error(); |
| 196 | + return addHeapObject(ret); |
| 197 | + }; |
| 198 | + imports.wbg.__wbg_stack_558ba5917b466edd = function(arg0, arg1) { |
| 199 | + var ret = getObject(arg1).stack; |
| 200 | + var ptr0 = passStringToWasm0(ret, wasm.__wbindgen_malloc, wasm.__wbindgen_realloc); |
| 201 | + var len0 = WASM_VECTOR_LEN; |
| 202 | + getInt32Memory0()[arg0 / 4 + 1] = len0; |
| 203 | + getInt32Memory0()[arg0 / 4 + 0] = ptr0; |
| 204 | + }; |
| 205 | + imports.wbg.__wbg_error_4bb6c2a97407129a = function(arg0, arg1) { |
| 206 | + try { |
| 207 | + console.error(getStringFromWasm0(arg0, arg1)); |
| 208 | + } finally { |
| 209 | + wasm.__wbindgen_free(arg0, arg1); |
| 210 | + } |
| 211 | + }; |
| 212 | + imports.wbg.__wbindgen_object_drop_ref = function(arg0) { |
| 213 | + takeObject(arg0); |
| 214 | + }; |
| 215 | + |
| 216 | + if (typeof input === 'string' || (typeof Request === 'function' && input instanceof Request) || (typeof URL === 'function' && input instanceof URL)) { |
| 217 | + input = fetch(input); |
| 218 | + } |
| 219 | + |
| 220 | + |
| 221 | + |
| 222 | + const { instance, module } = await load(await input, imports); |
| 223 | + |
| 224 | + wasm = instance.exports; |
| 225 | + init.__wbindgen_wasm_module = module; |
| 226 | + |
| 227 | + return wasm; |
| 228 | +} |
| 229 | + |
| 230 | +export default init; |
| 231 | + |
0 commit comments