| | @@ -1,17 +1,18 @@ |
| 1 | 1 | |
| 2 | 2 | var initPikchrModule = (() => { |
| 3 | 3 | var _scriptDir = typeof document !== 'undefined' && document.currentScript ? document.currentScript.src : undefined; |
| 4 | 4 | |
| 5 | 5 | return ( |
| 6 | | -function(moduleArg = {}) { |
| 6 | +function(config) { |
| 7 | + var initPikchrModule = config || {}; |
| 7 | 8 | |
| 8 | | -var Module = moduleArg; |
| 9 | +var Module = typeof initPikchrModule != "undefined" ? initPikchrModule : {}; |
| 9 | 10 | |
| 10 | 11 | var readyPromiseResolve, readyPromiseReject; |
| 11 | 12 | |
| 12 | | -Module["ready"] = new Promise((resolve, reject) => { |
| 13 | +Module["ready"] = new Promise(function(resolve, reject) { |
| 13 | 14 | readyPromiseResolve = resolve; |
| 14 | 15 | readyPromiseReject = reject; |
| 15 | 16 | }); |
| 16 | 17 | |
| 17 | 18 | var moduleOverrides = Object.assign({}, Module); |
| | @@ -35,11 +36,11 @@ |
| 35 | 36 | return Module["locateFile"](path, scriptDirectory); |
| 36 | 37 | } |
| 37 | 38 | return scriptDirectory + path; |
| 38 | 39 | } |
| 39 | 40 | |
| 40 | | -var read_, readAsync, readBinary; |
| 41 | +var read_, readAsync, readBinary, setWindowTitle; |
| 41 | 42 | |
| 42 | 43 | if (ENVIRONMENT_IS_WEB || ENVIRONMENT_IS_WORKER) { |
| 43 | 44 | if (ENVIRONMENT_IS_WORKER) { |
| 44 | 45 | scriptDirectory = self.location.href; |
| 45 | 46 | } else if (typeof document != "undefined" && document.currentScript) { |
| | @@ -46,51 +47,52 @@ |
| 46 | 47 | scriptDirectory = document.currentScript.src; |
| 47 | 48 | } |
| 48 | 49 | if (_scriptDir) { |
| 49 | 50 | scriptDirectory = _scriptDir; |
| 50 | 51 | } |
| 51 | | - if (scriptDirectory.startsWith("blob:")) { |
| 52 | | - scriptDirectory = ""; |
| 52 | + if (scriptDirectory.indexOf("blob:") !== 0) { |
| 53 | + scriptDirectory = scriptDirectory.substr(0, scriptDirectory.replace(/[?#].*/, "").lastIndexOf("/") + 1); |
| 53 | 54 | } else { |
| 54 | | - scriptDirectory = scriptDirectory.substr(0, scriptDirectory.replace(/[?#].*/, "").lastIndexOf("/") + 1); |
| 55 | + scriptDirectory = ""; |
| 55 | 56 | } |
| 56 | 57 | { |
| 57 | 58 | read_ = url => { |
| 58 | | - var xhr = new XMLHttpRequest; |
| 59 | + var xhr = new XMLHttpRequest(); |
| 59 | 60 | xhr.open("GET", url, false); |
| 60 | 61 | xhr.send(null); |
| 61 | 62 | return xhr.responseText; |
| 62 | 63 | }; |
| 63 | 64 | if (ENVIRONMENT_IS_WORKER) { |
| 64 | 65 | readBinary = url => { |
| 65 | | - var xhr = new XMLHttpRequest; |
| 66 | + var xhr = new XMLHttpRequest(); |
| 66 | 67 | xhr.open("GET", url, false); |
| 67 | 68 | xhr.responseType = "arraybuffer"; |
| 68 | 69 | xhr.send(null); |
| 69 | | - return new Uint8Array(/** @type{!ArrayBuffer} */ (xhr.response)); |
| 70 | + return new Uint8Array(xhr.response); |
| 70 | 71 | }; |
| 71 | 72 | } |
| 72 | 73 | readAsync = (url, onload, onerror) => { |
| 73 | | - var xhr = new XMLHttpRequest; |
| 74 | + var xhr = new XMLHttpRequest(); |
| 74 | 75 | xhr.open("GET", url, true); |
| 75 | 76 | xhr.responseType = "arraybuffer"; |
| 76 | 77 | xhr.onload = () => { |
| 77 | | - if (xhr.status == 200 || (xhr.status == 0 && xhr.response)) { |
| 78 | + if (xhr.status == 200 || xhr.status == 0 && xhr.response) { |
| 78 | 79 | onload(xhr.response); |
| 79 | 80 | return; |
| 80 | 81 | } |
| 81 | 82 | onerror(); |
| 82 | 83 | }; |
| 83 | 84 | xhr.onerror = onerror; |
| 84 | 85 | xhr.send(null); |
| 85 | 86 | }; |
| 86 | 87 | } |
| 88 | + setWindowTitle = title => document.title = title; |
| 87 | 89 | } else {} |
| 88 | 90 | |
| 89 | 91 | var out = Module["print"] || console.log.bind(console); |
| 90 | 92 | |
| 91 | | -var err = Module["printErr"] || console.error.bind(console); |
| 93 | +var err = Module["printErr"] || console.warn.bind(console); |
| 92 | 94 | |
| 93 | 95 | Object.assign(Module, moduleOverrides); |
| 94 | 96 | |
| 95 | 97 | moduleOverrides = null; |
| 96 | 98 | |
| | @@ -102,10 +104,12 @@ |
| 102 | 104 | |
| 103 | 105 | var wasmBinary; |
| 104 | 106 | |
| 105 | 107 | if (Module["wasmBinary"]) wasmBinary = Module["wasmBinary"]; |
| 106 | 108 | |
| 109 | +var noExitRuntime = Module["noExitRuntime"] || true; |
| 110 | + |
| 107 | 111 | if (typeof WebAssembly != "object") { |
| 108 | 112 | abort("no native wasm support detected"); |
| 109 | 113 | } |
| 110 | 114 | |
| 111 | 115 | var wasmMemory; |
| | @@ -112,31 +116,118 @@ |
| 112 | 116 | |
| 113 | 117 | var ABORT = false; |
| 114 | 118 | |
| 115 | 119 | var EXITSTATUS; |
| 116 | 120 | |
| 117 | | -var /** @type {!Int8Array} */ HEAP8, /** @type {!Uint8Array} */ HEAPU8, /** @type {!Int16Array} */ HEAP16, /** @type {!Uint16Array} */ HEAPU16, /** @type {!Int32Array} */ HEAP32, /** @type {!Uint32Array} */ HEAPU32, /** @type {!Float32Array} */ HEAPF32, /** @type {!Float64Array} */ HEAPF64; |
| 121 | +var UTF8Decoder = typeof TextDecoder != "undefined" ? new TextDecoder("utf8") : undefined; |
| 122 | + |
| 123 | +function UTF8ArrayToString(heapOrArray, idx, maxBytesToRead) { |
| 124 | + var endIdx = idx + maxBytesToRead; |
| 125 | + var endPtr = idx; |
| 126 | + while (heapOrArray[endPtr] && !(endPtr >= endIdx)) ++endPtr; |
| 127 | + if (endPtr - idx > 16 && heapOrArray.buffer && UTF8Decoder) { |
| 128 | + return UTF8Decoder.decode(heapOrArray.subarray(idx, endPtr)); |
| 129 | + } |
| 130 | + var str = ""; |
| 131 | + while (idx < endPtr) { |
| 132 | + var u0 = heapOrArray[idx++]; |
| 133 | + if (!(u0 & 128)) { |
| 134 | + str += String.fromCharCode(u0); |
| 135 | + continue; |
| 136 | + } |
| 137 | + var u1 = heapOrArray[idx++] & 63; |
| 138 | + if ((u0 & 224) == 192) { |
| 139 | + str += String.fromCharCode((u0 & 31) << 6 | u1); |
| 140 | + continue; |
| 141 | + } |
| 142 | + var u2 = heapOrArray[idx++] & 63; |
| 143 | + if ((u0 & 240) == 224) { |
| 144 | + u0 = (u0 & 15) << 12 | u1 << 6 | u2; |
| 145 | + } else { |
| 146 | + u0 = (u0 & 7) << 18 | u1 << 12 | u2 << 6 | heapOrArray[idx++] & 63; |
| 147 | + } |
| 148 | + if (u0 < 65536) { |
| 149 | + str += String.fromCharCode(u0); |
| 150 | + } else { |
| 151 | + var ch = u0 - 65536; |
| 152 | + str += String.fromCharCode(55296 | ch >> 10, 56320 | ch & 1023); |
| 153 | + } |
| 154 | + } |
| 155 | + return str; |
| 156 | +} |
| 157 | + |
| 158 | +function UTF8ToString(ptr, maxBytesToRead) { |
| 159 | + return ptr ? UTF8ArrayToString(HEAPU8, ptr, maxBytesToRead) : ""; |
| 160 | +} |
| 161 | + |
| 162 | +function stringToUTF8Array(str, heap, outIdx, maxBytesToWrite) { |
| 163 | + if (!(maxBytesToWrite > 0)) return 0; |
| 164 | + var startIdx = outIdx; |
| 165 | + var endIdx = outIdx + maxBytesToWrite - 1; |
| 166 | + for (var i = 0; i < str.length; ++i) { |
| 167 | + var u = str.charCodeAt(i); |
| 168 | + if (u >= 55296 && u <= 57343) { |
| 169 | + var u1 = str.charCodeAt(++i); |
| 170 | + u = 65536 + ((u & 1023) << 10) | u1 & 1023; |
| 171 | + } |
| 172 | + if (u <= 127) { |
| 173 | + if (outIdx >= endIdx) break; |
| 174 | + heap[outIdx++] = u; |
| 175 | + } else if (u <= 2047) { |
| 176 | + if (outIdx + 1 >= endIdx) break; |
| 177 | + heap[outIdx++] = 192 | u >> 6; |
| 178 | + heap[outIdx++] = 128 | u & 63; |
| 179 | + } else if (u <= 65535) { |
| 180 | + if (outIdx + 2 >= endIdx) break; |
| 181 | + heap[outIdx++] = 224 | u >> 12; |
| 182 | + heap[outIdx++] = 128 | u >> 6 & 63; |
| 183 | + heap[outIdx++] = 128 | u & 63; |
| 184 | + } else { |
| 185 | + if (outIdx + 3 >= endIdx) break; |
| 186 | + heap[outIdx++] = 240 | u >> 18; |
| 187 | + heap[outIdx++] = 128 | u >> 12 & 63; |
| 188 | + heap[outIdx++] = 128 | u >> 6 & 63; |
| 189 | + heap[outIdx++] = 128 | u & 63; |
| 190 | + } |
| 191 | + } |
| 192 | + heap[outIdx] = 0; |
| 193 | + return outIdx - startIdx; |
| 194 | +} |
| 195 | + |
| 196 | +function stringToUTF8(str, outPtr, maxBytesToWrite) { |
| 197 | + return stringToUTF8Array(str, HEAPU8, outPtr, maxBytesToWrite); |
| 198 | +} |
| 199 | + |
| 200 | +var HEAP8, HEAPU8, HEAP16, HEAPU16, HEAP32, HEAPU32, HEAPF32, HEAPF64; |
| 118 | 201 | |
| 119 | 202 | function updateMemoryViews() { |
| 120 | 203 | var b = wasmMemory.buffer; |
| 121 | 204 | Module["HEAP8"] = HEAP8 = new Int8Array(b); |
| 122 | 205 | Module["HEAP16"] = HEAP16 = new Int16Array(b); |
| 206 | + Module["HEAP32"] = HEAP32 = new Int32Array(b); |
| 123 | 207 | Module["HEAPU8"] = HEAPU8 = new Uint8Array(b); |
| 124 | 208 | Module["HEAPU16"] = HEAPU16 = new Uint16Array(b); |
| 125 | | - Module["HEAP32"] = HEAP32 = new Int32Array(b); |
| 126 | 209 | Module["HEAPU32"] = HEAPU32 = new Uint32Array(b); |
| 127 | 210 | Module["HEAPF32"] = HEAPF32 = new Float32Array(b); |
| 128 | 211 | Module["HEAPF64"] = HEAPF64 = new Float64Array(b); |
| 129 | 212 | } |
| 213 | + |
| 214 | +var INITIAL_MEMORY = Module["INITIAL_MEMORY"] || 16777216; |
| 215 | + |
| 216 | +var wasmTable; |
| 130 | 217 | |
| 131 | 218 | var __ATPRERUN__ = []; |
| 132 | 219 | |
| 133 | 220 | var __ATINIT__ = []; |
| 134 | 221 | |
| 135 | 222 | var __ATPOSTRUN__ = []; |
| 136 | 223 | |
| 137 | 224 | var runtimeInitialized = false; |
| 225 | + |
| 226 | +function keepRuntimeAlive() { |
| 227 | + return noExitRuntime; |
| 228 | +} |
| 138 | 229 | |
| 139 | 230 | function preRun() { |
| 140 | 231 | if (Module["preRun"]) { |
| 141 | 232 | if (typeof Module["preRun"] == "function") Module["preRun"] = [ Module["preRun"] ]; |
| 142 | 233 | while (Module["preRun"].length) { |
| | @@ -179,16 +270,20 @@ |
| 179 | 270 | |
| 180 | 271 | var dependenciesFulfilled = null; |
| 181 | 272 | |
| 182 | 273 | function addRunDependency(id) { |
| 183 | 274 | runDependencies++; |
| 184 | | - Module["monitorRunDependencies"]?.(runDependencies); |
| 275 | + if (Module["monitorRunDependencies"]) { |
| 276 | + Module["monitorRunDependencies"](runDependencies); |
| 277 | + } |
| 185 | 278 | } |
| 186 | 279 | |
| 187 | 280 | function removeRunDependency(id) { |
| 188 | 281 | runDependencies--; |
| 189 | | - Module["monitorRunDependencies"]?.(runDependencies); |
| 282 | + if (Module["monitorRunDependencies"]) { |
| 283 | + Module["monitorRunDependencies"](runDependencies); |
| 284 | + } |
| 190 | 285 | if (runDependencies == 0) { |
| 191 | 286 | if (runDependencyWatcher !== null) { |
| 192 | 287 | clearInterval(runDependencyWatcher); |
| 193 | 288 | runDependencyWatcher = null; |
| 194 | 289 | } |
| | @@ -198,382 +293,278 @@ |
| 198 | 293 | callback(); |
| 199 | 294 | } |
| 200 | 295 | } |
| 201 | 296 | } |
| 202 | 297 | |
| 203 | | -/** @param {string|number=} what */ function abort(what) { |
| 204 | | - Module["onAbort"]?.(what); |
| 298 | +function abort(what) { |
| 299 | + if (Module["onAbort"]) { |
| 300 | + Module["onAbort"](what); |
| 301 | + } |
| 205 | 302 | what = "Aborted(" + what + ")"; |
| 206 | 303 | err(what); |
| 207 | 304 | ABORT = true; |
| 208 | 305 | EXITSTATUS = 1; |
| 209 | 306 | what += ". Build with -sASSERTIONS for more info."; |
| 210 | | - /** @suppress {checkTypes} */ var e = new WebAssembly.RuntimeError(what); |
| 307 | + var e = new WebAssembly.RuntimeError(what); |
| 211 | 308 | readyPromiseReject(e); |
| 212 | 309 | throw e; |
| 213 | 310 | } |
| 214 | 311 | |
| 215 | 312 | var dataURIPrefix = "data:application/octet-stream;base64,"; |
| 216 | 313 | |
| 217 | | -/** |
| 218 | | - * Indicates whether filename is a base64 data URI. |
| 219 | | - * @noinline |
| 220 | | - */ var isDataURI = filename => filename.startsWith(dataURIPrefix); |
| 314 | +function isDataURI(filename) { |
| 315 | + return filename.startsWith(dataURIPrefix); |
| 316 | +} |
| 221 | 317 | |
| 222 | 318 | var wasmBinaryFile; |
| 223 | 319 | |
| 224 | 320 | wasmBinaryFile = "pikchr.wasm"; |
| 225 | 321 | |
| 226 | 322 | if (!isDataURI(wasmBinaryFile)) { |
| 227 | 323 | wasmBinaryFile = locateFile(wasmBinaryFile); |
| 228 | 324 | } |
| 229 | 325 | |
| 230 | | -function getBinarySync(file) { |
| 231 | | - if (file == wasmBinaryFile && wasmBinary) { |
| 232 | | - return new Uint8Array(wasmBinary); |
| 233 | | - } |
| 234 | | - if (readBinary) { |
| 235 | | - return readBinary(file); |
| 236 | | - } |
| 237 | | - throw "both async and sync fetching of the wasm failed"; |
| 238 | | -} |
| 239 | | - |
| 240 | | -function getBinaryPromise(binaryFile) { |
| 241 | | - if (!wasmBinary && (ENVIRONMENT_IS_WEB || ENVIRONMENT_IS_WORKER)) { |
| 242 | | - if (typeof fetch == "function") { |
| 243 | | - return fetch(binaryFile, { |
| 244 | | - credentials: "same-origin" |
| 245 | | - }).then(response => { |
| 246 | | - if (!response["ok"]) { |
| 247 | | - throw `failed to load wasm binary file at '${binaryFile}'`; |
| 248 | | - } |
| 249 | | - return response["arrayBuffer"](); |
| 250 | | - }).catch(() => getBinarySync(binaryFile)); |
| 251 | | - } |
| 252 | | - } |
| 253 | | - return Promise.resolve().then(() => getBinarySync(binaryFile)); |
| 254 | | -} |
| 255 | | - |
| 256 | | -function instantiateArrayBuffer(binaryFile, imports, receiver) { |
| 257 | | - return getBinaryPromise(binaryFile).then(binary => WebAssembly.instantiate(binary, imports)).then(instance => instance).then(receiver, reason => { |
| 258 | | - err(`failed to asynchronously prepare wasm: ${reason}`); |
| 259 | | - abort(reason); |
| 260 | | - }); |
| 261 | | -} |
| 262 | | - |
| 263 | | -function instantiateAsync(binary, binaryFile, imports, callback) { |
| 264 | | - if (!binary && typeof WebAssembly.instantiateStreaming == "function" && !isDataURI(binaryFile) && typeof fetch == "function") { |
| 265 | | - return fetch(binaryFile, { |
| 266 | | - credentials: "same-origin" |
| 267 | | - }).then(response => { |
| 268 | | - /** @suppress {checkTypes} */ var result = WebAssembly.instantiateStreaming(response, imports); |
| 269 | | - return result.then(callback, function(reason) { |
| 270 | | - err(`wasm streaming compile failed: ${reason}`); |
| 271 | | - err("falling back to ArrayBuffer instantiation"); |
| 272 | | - return instantiateArrayBuffer(binaryFile, imports, callback); |
| 273 | | - }); |
| 274 | | - }); |
| 275 | | - } |
| 276 | | - return instantiateArrayBuffer(binaryFile, imports, callback); |
| 326 | +function getBinary(file) { |
| 327 | + try { |
| 328 | + if (file == wasmBinaryFile && wasmBinary) { |
| 329 | + return new Uint8Array(wasmBinary); |
| 330 | + } |
| 331 | + if (readBinary) { |
| 332 | + return readBinary(file); |
| 333 | + } |
| 334 | + throw "both async and sync fetching of the wasm failed"; |
| 335 | + } catch (err) { |
| 336 | + abort(err); |
| 337 | + } |
| 338 | +} |
| 339 | + |
| 340 | +function getBinaryPromise() { |
| 341 | + if (!wasmBinary && (ENVIRONMENT_IS_WEB || ENVIRONMENT_IS_WORKER)) { |
| 342 | + if (typeof fetch == "function") { |
| 343 | + return fetch(wasmBinaryFile, { |
| 344 | + credentials: "same-origin" |
| 345 | + }).then(function(response) { |
| 346 | + if (!response["ok"]) { |
| 347 | + throw "failed to load wasm binary file at '" + wasmBinaryFile + "'"; |
| 348 | + } |
| 349 | + return response["arrayBuffer"](); |
| 350 | + }).catch(function() { |
| 351 | + return getBinary(wasmBinaryFile); |
| 352 | + }); |
| 353 | + } |
| 354 | + } |
| 355 | + return Promise.resolve().then(function() { |
| 356 | + return getBinary(wasmBinaryFile); |
| 357 | + }); |
| 277 | 358 | } |
| 278 | 359 | |
| 279 | 360 | function createWasm() { |
| 280 | 361 | var info = { |
| 281 | | - "a": wasmImports |
| 362 | + "a": asmLibraryArg |
| 282 | 363 | }; |
| 283 | | - /** @param {WebAssembly.Module=} module*/ function receiveInstance(instance, module) { |
| 284 | | - wasmExports = instance.exports; |
| 285 | | - wasmMemory = wasmExports["d"]; |
| 364 | + function receiveInstance(instance, module) { |
| 365 | + var exports = instance.exports; |
| 366 | + Module["asm"] = exports; |
| 367 | + wasmMemory = Module["asm"]["d"]; |
| 286 | 368 | updateMemoryViews(); |
| 287 | | - addOnInit(wasmExports["e"]); |
| 369 | + wasmTable = Module["asm"]["g"]; |
| 370 | + addOnInit(Module["asm"]["e"]); |
| 288 | 371 | removeRunDependency("wasm-instantiate"); |
| 289 | | - return wasmExports; |
| 290 | 372 | } |
| 291 | 373 | addRunDependency("wasm-instantiate"); |
| 292 | 374 | function receiveInstantiationResult(result) { |
| 293 | 375 | receiveInstance(result["instance"]); |
| 294 | 376 | } |
| 295 | | - if (Module["instantiateWasm"]) { |
| 296 | | - try { |
| 297 | | - return Module["instantiateWasm"](info, receiveInstance); |
| 298 | | - } catch (e) { |
| 299 | | - err(`Module.instantiateWasm callback failed with error: ${e}`); |
| 300 | | - readyPromiseReject(e); |
| 301 | | - } |
| 302 | | - } |
| 303 | | - instantiateAsync(wasmBinary, wasmBinaryFile, info, receiveInstantiationResult).catch(readyPromiseReject); |
| 304 | | - return {}; |
| 305 | | -} |
| 306 | | - |
| 307 | | -/** @constructor */ function ExitStatus(status) { |
| 308 | | - this.name = "ExitStatus"; |
| 309 | | - this.message = `Program terminated with exit(${status})`; |
| 310 | | - this.status = status; |
| 311 | | -} |
| 312 | | - |
| 313 | | -var callRuntimeCallbacks = callbacks => { |
| 314 | | - while (callbacks.length > 0) { |
| 315 | | - callbacks.shift()(Module); |
| 316 | | - } |
| 317 | | -}; |
| 318 | | - |
| 319 | | -/** |
| 320 | | - * @param {number} ptr |
| 321 | | - * @param {string} type |
| 322 | | - */ function getValue(ptr, type = "i8") { |
| 323 | | - if (type.endsWith("*")) type = "*"; |
| 324 | | - switch (type) { |
| 325 | | - case "i1": |
| 326 | | - return HEAP8[((ptr) >> 0)]; |
| 327 | | - |
| 328 | | - case "i8": |
| 329 | | - return HEAP8[((ptr) >> 0)]; |
| 330 | | - |
| 331 | | - case "i16": |
| 332 | | - return HEAP16[((ptr) >> 1)]; |
| 333 | | - |
| 334 | | - case "i32": |
| 335 | | - return HEAP32[((ptr) >> 2)]; |
| 336 | | - |
| 337 | | - case "i64": |
| 338 | | - abort("to do getValue(i64) use WASM_BIGINT"); |
| 339 | | - |
| 340 | | - case "float": |
| 341 | | - return HEAPF32[((ptr) >> 2)]; |
| 342 | | - |
| 343 | | - case "double": |
| 344 | | - return HEAPF64[((ptr) >> 3)]; |
| 345 | | - |
| 346 | | - case "*": |
| 347 | | - return HEAPU32[((ptr) >> 2)]; |
| 348 | | - |
| 349 | | - default: |
| 350 | | - abort(`invalid type for getValue: ${type}`); |
| 351 | | - } |
| 352 | | -} |
| 353 | | - |
| 354 | | -var noExitRuntime = Module["noExitRuntime"] || true; |
| 355 | | - |
| 356 | | -/** |
| 357 | | - * @param {number} ptr |
| 358 | | - * @param {number} value |
| 359 | | - * @param {string} type |
| 360 | | - */ function setValue(ptr, value, type = "i8") { |
| 361 | | - if (type.endsWith("*")) type = "*"; |
| 362 | | - switch (type) { |
| 363 | | - case "i1": |
| 364 | | - HEAP8[((ptr) >> 0)] = value; |
| 365 | | - break; |
| 366 | | - |
| 367 | | - case "i8": |
| 368 | | - HEAP8[((ptr) >> 0)] = value; |
| 369 | | - break; |
| 370 | | - |
| 371 | | - case "i16": |
| 372 | | - HEAP16[((ptr) >> 1)] = value; |
| 373 | | - break; |
| 374 | | - |
| 375 | | - case "i32": |
| 376 | | - HEAP32[((ptr) >> 2)] = value; |
| 377 | | - break; |
| 378 | | - |
| 379 | | - case "i64": |
| 380 | | - abort("to do setValue(i64) use WASM_BIGINT"); |
| 381 | | - |
| 382 | | - case "float": |
| 383 | | - HEAPF32[((ptr) >> 2)] = value; |
| 384 | | - break; |
| 385 | | - |
| 386 | | - case "double": |
| 387 | | - HEAPF64[((ptr) >> 3)] = value; |
| 388 | | - break; |
| 389 | | - |
| 390 | | - case "*": |
| 391 | | - HEAPU32[((ptr) >> 2)] = value; |
| 392 | | - break; |
| 393 | | - |
| 394 | | - default: |
| 395 | | - abort(`invalid type for setValue: ${type}`); |
| 396 | | - } |
| 397 | | -} |
| 398 | | - |
| 399 | | -var UTF8Decoder = typeof TextDecoder != "undefined" ? new TextDecoder("utf8") : undefined; |
| 400 | | - |
| 401 | | -/** |
| 402 | | - * Given a pointer 'idx' to a null-terminated UTF8-encoded string in the given |
| 403 | | - * array that contains uint8 values, returns a copy of that string as a |
| 404 | | - * Javascript String object. |
| 405 | | - * heapOrArray is either a regular array, or a JavaScript typed array view. |
| 406 | | - * @param {number} idx |
| 407 | | - * @param {number=} maxBytesToRead |
| 408 | | - * @return {string} |
| 409 | | - */ var UTF8ArrayToString = (heapOrArray, idx, maxBytesToRead) => { |
| 410 | | - var endIdx = idx + maxBytesToRead; |
| 411 | | - var endPtr = idx; |
| 412 | | - while (heapOrArray[endPtr] && !(endPtr >= endIdx)) ++endPtr; |
| 413 | | - if (endPtr - idx > 16 && heapOrArray.buffer && UTF8Decoder) { |
| 414 | | - return UTF8Decoder.decode(heapOrArray.subarray(idx, endPtr)); |
| 415 | | - } |
| 416 | | - var str = ""; |
| 417 | | - while (idx < endPtr) { |
| 418 | | - var u0 = heapOrArray[idx++]; |
| 419 | | - if (!(u0 & 128)) { |
| 420 | | - str += String.fromCharCode(u0); |
| 421 | | - continue; |
| 422 | | - } |
| 423 | | - var u1 = heapOrArray[idx++] & 63; |
| 424 | | - if ((u0 & 224) == 192) { |
| 425 | | - str += String.fromCharCode(((u0 & 31) << 6) | u1); |
| 426 | | - continue; |
| 427 | | - } |
| 428 | | - var u2 = heapOrArray[idx++] & 63; |
| 429 | | - if ((u0 & 240) == 224) { |
| 430 | | - u0 = ((u0 & 15) << 12) | (u1 << 6) | u2; |
| 431 | | - } else { |
| 432 | | - u0 = ((u0 & 7) << 18) | (u1 << 12) | (u2 << 6) | (heapOrArray[idx++] & 63); |
| 433 | | - } |
| 434 | | - if (u0 < 65536) { |
| 435 | | - str += String.fromCharCode(u0); |
| 436 | | - } else { |
| 437 | | - var ch = u0 - 65536; |
| 438 | | - str += String.fromCharCode(55296 | (ch >> 10), 56320 | (ch & 1023)); |
| 439 | | - } |
| 440 | | - } |
| 441 | | - return str; |
| 442 | | -}; |
| 443 | | - |
| 444 | | -/** |
| 445 | | - * Given a pointer 'ptr' to a null-terminated UTF8-encoded string in the |
| 446 | | - * emscripten HEAP, returns a copy of that string as a Javascript String object. |
| 447 | | - * |
| 448 | | - * @param {number} ptr |
| 449 | | - * @param {number=} maxBytesToRead - An optional length that specifies the |
| 450 | | - * maximum number of bytes to read. You can omit this parameter to scan the |
| 451 | | - * string until the first 0 byte. If maxBytesToRead is passed, and the string |
| 452 | | - * at [ptr, ptr+maxBytesToReadr[ contains a null byte in the middle, then the |
| 453 | | - * string will cut short at that byte index (i.e. maxBytesToRead will not |
| 454 | | - * produce a string of exact length [ptr, ptr+maxBytesToRead[) N.B. mixing |
| 455 | | - * frequent uses of UTF8ToString() with and without maxBytesToRead may throw |
| 456 | | - * JS JIT optimizations off, so it is worth to consider consistently using one |
| 457 | | - * @return {string} |
| 458 | | - */ var UTF8ToString = (ptr, maxBytesToRead) => ptr ? UTF8ArrayToString(HEAPU8, ptr, maxBytesToRead) : ""; |
| 459 | | - |
| 460 | | -var ___assert_fail = (condition, filename, line, func) => { |
| 461 | | - abort(`Assertion failed: ${UTF8ToString(condition)}, at: ` + [ filename ? UTF8ToString(filename) : "unknown filename", line, func ? UTF8ToString(func) : "unknown function" ]); |
| 462 | | -}; |
| 463 | | - |
| 464 | | -var abortOnCannotGrowMemory = requestedSize => { |
| 465 | | - abort("OOM"); |
| 466 | | -}; |
| 467 | | - |
| 468 | | -var _emscripten_resize_heap = requestedSize => { |
| 469 | | - var oldSize = HEAPU8.length; |
| 470 | | - requestedSize >>>= 0; |
| 471 | | - abortOnCannotGrowMemory(requestedSize); |
| 472 | | -}; |
| 473 | | - |
| 474 | | -var runtimeKeepaliveCounter = 0; |
| 475 | | - |
| 476 | | -var keepRuntimeAlive = () => noExitRuntime || runtimeKeepaliveCounter > 0; |
| 477 | | - |
| 478 | | -var _proc_exit = code => { |
| 479 | | - EXITSTATUS = code; |
| 480 | | - if (!keepRuntimeAlive()) { |
| 481 | | - Module["onExit"]?.(code); |
| 482 | | - ABORT = true; |
| 483 | | - } |
| 484 | | - quit_(code, new ExitStatus(code)); |
| 485 | | -}; |
| 486 | | - |
| 487 | | -/** @param {boolean|number=} implicit */ var exitJS = (status, implicit) => { |
| 488 | | - EXITSTATUS = status; |
| 489 | | - _proc_exit(status); |
| 490 | | -}; |
| 491 | | - |
| 492 | | -var _exit = exitJS; |
| 493 | | - |
| 494 | | -var getCFunc = ident => { |
| 495 | | - var func = Module["_" + ident]; |
| 496 | | - return func; |
| 497 | | -}; |
| 498 | | - |
| 499 | | -var writeArrayToMemory = (array, buffer) => { |
| 500 | | - HEAP8.set(array, buffer); |
| 501 | | -}; |
| 502 | | - |
| 503 | | -var lengthBytesUTF8 = str => { |
| 504 | | - var len = 0; |
| 505 | | - for (var i = 0; i < str.length; ++i) { |
| 506 | | - var c = str.charCodeAt(i); |
| 507 | | - if (c <= 127) { |
| 508 | | - len++; |
| 509 | | - } else if (c <= 2047) { |
| 510 | | - len += 2; |
| 511 | | - } else if (c >= 55296 && c <= 57343) { |
| 512 | | - len += 4; |
| 513 | | - ++i; |
| 514 | | - } else { |
| 515 | | - len += 3; |
| 516 | | - } |
| 517 | | - } |
| 518 | | - return len; |
| 519 | | -}; |
| 520 | | - |
| 521 | | -var stringToUTF8Array = (str, heap, outIdx, maxBytesToWrite) => { |
| 522 | | - if (!(maxBytesToWrite > 0)) return 0; |
| 523 | | - var startIdx = outIdx; |
| 524 | | - var endIdx = outIdx + maxBytesToWrite - 1; |
| 525 | | - for (var i = 0; i < str.length; ++i) { |
| 526 | | - var u = str.charCodeAt(i); |
| 527 | | - if (u >= 55296 && u <= 57343) { |
| 528 | | - var u1 = str.charCodeAt(++i); |
| 529 | | - u = 65536 + ((u & 1023) << 10) | (u1 & 1023); |
| 530 | | - } |
| 531 | | - if (u <= 127) { |
| 532 | | - if (outIdx >= endIdx) break; |
| 533 | | - heap[outIdx++] = u; |
| 534 | | - } else if (u <= 2047) { |
| 535 | | - if (outIdx + 1 >= endIdx) break; |
| 536 | | - heap[outIdx++] = 192 | (u >> 6); |
| 537 | | - heap[outIdx++] = 128 | (u & 63); |
| 538 | | - } else if (u <= 65535) { |
| 539 | | - if (outIdx + 2 >= endIdx) break; |
| 540 | | - heap[outIdx++] = 224 | (u >> 12); |
| 541 | | - heap[outIdx++] = 128 | ((u >> 6) & 63); |
| 542 | | - heap[outIdx++] = 128 | (u & 63); |
| 543 | | - } else { |
| 544 | | - if (outIdx + 3 >= endIdx) break; |
| 545 | | - heap[outIdx++] = 240 | (u >> 18); |
| 546 | | - heap[outIdx++] = 128 | ((u >> 12) & 63); |
| 547 | | - heap[outIdx++] = 128 | ((u >> 6) & 63); |
| 548 | | - heap[outIdx++] = 128 | (u & 63); |
| 549 | | - } |
| 550 | | - } |
| 551 | | - heap[outIdx] = 0; |
| 552 | | - return outIdx - startIdx; |
| 553 | | -}; |
| 554 | | - |
| 555 | | -var stringToUTF8 = (str, outPtr, maxBytesToWrite) => stringToUTF8Array(str, HEAPU8, outPtr, maxBytesToWrite); |
| 556 | | - |
| 557 | | -var stringToUTF8OnStack = str => { |
| 558 | | - var size = lengthBytesUTF8(str) + 1; |
| 559 | | - var ret = stackAlloc(size); |
| 560 | | - stringToUTF8(str, ret, size); |
| 561 | | - return ret; |
| 562 | | -}; |
| 563 | | - |
| 564 | | -/** |
| 565 | | - * @param {string|null=} returnType |
| 566 | | - * @param {Array=} argTypes |
| 567 | | - * @param {Arguments|Array=} args |
| 568 | | - * @param {Object=} opts |
| 569 | | - */ var ccall = (ident, returnType, argTypes, args, opts) => { |
| 377 | + function instantiateArrayBuffer(receiver) { |
| 378 | + return getBinaryPromise().then(function(binary) { |
| 379 | + return WebAssembly.instantiate(binary, info); |
| 380 | + }).then(function(instance) { |
| 381 | + return instance; |
| 382 | + }).then(receiver, function(reason) { |
| 383 | + err("failed to asynchronously prepare wasm: " + reason); |
| 384 | + abort(reason); |
| 385 | + }); |
| 386 | + } |
| 387 | + function instantiateAsync() { |
| 388 | + if (!wasmBinary && typeof WebAssembly.instantiateStreaming == "function" && !isDataURI(wasmBinaryFile) && typeof fetch == "function") { |
| 389 | + return fetch(wasmBinaryFile, { |
| 390 | + credentials: "same-origin" |
| 391 | + }).then(function(response) { |
| 392 | + var result = WebAssembly.instantiateStreaming(response, info); |
| 393 | + return result.then(receiveInstantiationResult, function(reason) { |
| 394 | + err("wasm streaming compile failed: " + reason); |
| 395 | + err("falling back to ArrayBuffer instantiation"); |
| 396 | + return instantiateArrayBuffer(receiveInstantiationResult); |
| 397 | + }); |
| 398 | + }); |
| 399 | + } else { |
| 400 | + return instantiateArrayBuffer(receiveInstantiationResult); |
| 401 | + } |
| 402 | + } |
| 403 | + if (Module["instantiateWasm"]) { |
| 404 | + try { |
| 405 | + var exports = Module["instantiateWasm"](info, receiveInstance); |
| 406 | + return exports; |
| 407 | + } catch (e) { |
| 408 | + err("Module.instantiateWasm callback failed with error: " + e); |
| 409 | + readyPromiseReject(e); |
| 410 | + } |
| 411 | + } |
| 412 | + instantiateAsync().catch(readyPromiseReject); |
| 413 | + return {}; |
| 414 | +} |
| 415 | + |
| 416 | +var tempDouble; |
| 417 | + |
| 418 | +var tempI64; |
| 419 | + |
| 420 | +function ExitStatus(status) { |
| 421 | + this.name = "ExitStatus"; |
| 422 | + this.message = "Program terminated with exit(" + status + ")"; |
| 423 | + this.status = status; |
| 424 | +} |
| 425 | + |
| 426 | +function callRuntimeCallbacks(callbacks) { |
| 427 | + while (callbacks.length > 0) { |
| 428 | + callbacks.shift()(Module); |
| 429 | + } |
| 430 | +} |
| 431 | + |
| 432 | +function getValue(ptr, type = "i8") { |
| 433 | + if (type.endsWith("*")) type = "*"; |
| 434 | + switch (type) { |
| 435 | + case "i1": |
| 436 | + return HEAP8[ptr >> 0]; |
| 437 | + |
| 438 | + case "i8": |
| 439 | + return HEAP8[ptr >> 0]; |
| 440 | + |
| 441 | + case "i16": |
| 442 | + return HEAP16[ptr >> 1]; |
| 443 | + |
| 444 | + case "i32": |
| 445 | + return HEAP32[ptr >> 2]; |
| 446 | + |
| 447 | + case "i64": |
| 448 | + return HEAP32[ptr >> 2]; |
| 449 | + |
| 450 | + case "float": |
| 451 | + return HEAPF32[ptr >> 2]; |
| 452 | + |
| 453 | + case "double": |
| 454 | + return HEAPF64[ptr >> 3]; |
| 455 | + |
| 456 | + case "*": |
| 457 | + return HEAPU32[ptr >> 2]; |
| 458 | + |
| 459 | + default: |
| 460 | + abort("invalid type for getValue: " + type); |
| 461 | + } |
| 462 | + return null; |
| 463 | +} |
| 464 | + |
| 465 | +function setValue(ptr, value, type = "i8") { |
| 466 | + if (type.endsWith("*")) type = "*"; |
| 467 | + switch (type) { |
| 468 | + case "i1": |
| 469 | + HEAP8[ptr >> 0] = value; |
| 470 | + break; |
| 471 | + |
| 472 | + case "i8": |
| 473 | + HEAP8[ptr >> 0] = value; |
| 474 | + break; |
| 475 | + |
| 476 | + case "i16": |
| 477 | + HEAP16[ptr >> 1] = value; |
| 478 | + break; |
| 479 | + |
| 480 | + case "i32": |
| 481 | + HEAP32[ptr >> 2] = value; |
| 482 | + break; |
| 483 | + |
| 484 | + case "i64": |
| 485 | + tempI64 = [ value >>> 0, (tempDouble = value, +Math.abs(tempDouble) >= 1 ? tempDouble > 0 ? (Math.min(+Math.floor(tempDouble / 4294967296), 4294967295) | 0) >>> 0 : ~~+Math.ceil((tempDouble - +(~~tempDouble >>> 0)) / 4294967296) >>> 0 : 0) ], |
| 486 | + HEAP32[ptr >> 2] = tempI64[0], HEAP32[ptr + 4 >> 2] = tempI64[1]; |
| 487 | + break; |
| 488 | + |
| 489 | + case "float": |
| 490 | + HEAPF32[ptr >> 2] = value; |
| 491 | + break; |
| 492 | + |
| 493 | + case "double": |
| 494 | + HEAPF64[ptr >> 3] = value; |
| 495 | + break; |
| 496 | + |
| 497 | + case "*": |
| 498 | + HEAPU32[ptr >> 2] = value; |
| 499 | + break; |
| 500 | + |
| 501 | + default: |
| 502 | + abort("invalid type for setValue: " + type); |
| 503 | + } |
| 504 | +} |
| 505 | + |
| 506 | +function ___assert_fail(condition, filename, line, func) { |
| 507 | + abort("Assertion failed: " + UTF8ToString(condition) + ", at: " + [ filename ? UTF8ToString(filename) : "unknown filename", line, func ? UTF8ToString(func) : "unknown function" ]); |
| 508 | +} |
| 509 | + |
| 510 | +function abortOnCannotGrowMemory(requestedSize) { |
| 511 | + abort("OOM"); |
| 512 | +} |
| 513 | + |
| 514 | +function _emscripten_resize_heap(requestedSize) { |
| 515 | + var oldSize = HEAPU8.length; |
| 516 | + requestedSize = requestedSize >>> 0; |
| 517 | + abortOnCannotGrowMemory(requestedSize); |
| 518 | +} |
| 519 | + |
| 520 | +var SYSCALLS = { |
| 521 | + varargs: undefined, |
| 522 | + get: function() { |
| 523 | + SYSCALLS.varargs += 4; |
| 524 | + var ret = HEAP32[SYSCALLS.varargs - 4 >> 2]; |
| 525 | + return ret; |
| 526 | + }, |
| 527 | + getStr: function(ptr) { |
| 528 | + var ret = UTF8ToString(ptr); |
| 529 | + return ret; |
| 530 | + } |
| 531 | +}; |
| 532 | + |
| 533 | +function _proc_exit(code) { |
| 534 | + EXITSTATUS = code; |
| 535 | + if (!keepRuntimeAlive()) { |
| 536 | + if (Module["onExit"]) Module["onExit"](code); |
| 537 | + ABORT = true; |
| 538 | + } |
| 539 | + quit_(code, new ExitStatus(code)); |
| 540 | +} |
| 541 | + |
| 542 | +function exitJS(status, implicit) { |
| 543 | + EXITSTATUS = status; |
| 544 | + _proc_exit(status); |
| 545 | +} |
| 546 | + |
| 547 | +var _exit = exitJS; |
| 548 | + |
| 549 | +function getCFunc(ident) { |
| 550 | + var func = Module["_" + ident]; |
| 551 | + return func; |
| 552 | +} |
| 553 | + |
| 554 | +function writeArrayToMemory(array, buffer) { |
| 555 | + HEAP8.set(array, buffer); |
| 556 | +} |
| 557 | + |
| 558 | +function ccall(ident, returnType, argTypes, args, opts) { |
| 570 | 559 | var toC = { |
| 571 | 560 | "string": str => { |
| 572 | 561 | var ret = 0; |
| 573 | 562 | if (str !== null && str !== undefined && str !== 0) { |
| 574 | | - ret = stringToUTF8OnStack(str); |
| 563 | + var len = (str.length << 2) + 1; |
| 564 | + ret = stackAlloc(len); |
| 565 | + stringToUTF8(str, ret, len); |
| 575 | 566 | } |
| 576 | 567 | return ret; |
| 577 | 568 | }, |
| 578 | 569 | "array": arr => { |
| 579 | 570 | var ret = stackAlloc(arr.length); |
| | @@ -607,46 +598,51 @@ |
| 607 | 598 | if (stack !== 0) stackRestore(stack); |
| 608 | 599 | return convertReturnValue(ret); |
| 609 | 600 | } |
| 610 | 601 | ret = onDone(ret); |
| 611 | 602 | return ret; |
| 612 | | -}; |
| 613 | | - |
| 614 | | -/** |
| 615 | | - * @param {string=} returnType |
| 616 | | - * @param {Array=} argTypes |
| 617 | | - * @param {Object=} opts |
| 618 | | - */ var cwrap = (ident, returnType, argTypes, opts) => { |
| 619 | | - var numericArgs = !argTypes || argTypes.every(type => type === "number" || type === "boolean"); |
| 603 | +} |
| 604 | + |
| 605 | +function cwrap(ident, returnType, argTypes, opts) { |
| 606 | + argTypes = argTypes || []; |
| 607 | + var numericArgs = argTypes.every(type => type === "number" || type === "boolean"); |
| 620 | 608 | var numericRet = returnType !== "string"; |
| 621 | 609 | if (numericRet && numericArgs && !opts) { |
| 622 | 610 | return getCFunc(ident); |
| 623 | 611 | } |
| 624 | 612 | return function() { |
| 625 | 613 | return ccall(ident, returnType, argTypes, arguments, opts); |
| 626 | 614 | }; |
| 627 | | -}; |
| 628 | | - |
| 629 | | -var wasmImports = { |
| 630 | | - /** @export */ a: ___assert_fail, |
| 631 | | - /** @export */ b: _emscripten_resize_heap, |
| 632 | | - /** @export */ c: _exit |
| 633 | | -}; |
| 634 | | - |
| 635 | | -var wasmExports = createWasm(); |
| 636 | | - |
| 637 | | -var ___wasm_call_ctors = () => (___wasm_call_ctors = wasmExports["e"])(); |
| 638 | | - |
| 639 | | -var _pikchr = Module["_pikchr"] = (a0, a1, a2, a3, a4) => (_pikchr = Module["_pikchr"] = wasmExports["f"])(a0, a1, a2, a3, a4); |
| 640 | | - |
| 641 | | -var stackSave = () => (stackSave = wasmExports["h"])(); |
| 642 | | - |
| 643 | | -var stackRestore = a0 => (stackRestore = wasmExports["i"])(a0); |
| 644 | | - |
| 645 | | -var stackAlloc = a0 => (stackAlloc = wasmExports["j"])(a0); |
| 646 | | - |
| 647 | | -Module["stackAlloc"] = stackAlloc; |
| 615 | +} |
| 616 | + |
| 617 | +var asmLibraryArg = { |
| 618 | + "a": ___assert_fail, |
| 619 | + "b": _emscripten_resize_heap, |
| 620 | + "c": _exit |
| 621 | +}; |
| 622 | + |
| 623 | +var asm = createWasm(); |
| 624 | + |
| 625 | +var ___wasm_call_ctors = Module["___wasm_call_ctors"] = function() { |
| 626 | + return (___wasm_call_ctors = Module["___wasm_call_ctors"] = Module["asm"]["e"]).apply(null, arguments); |
| 627 | +}; |
| 628 | + |
| 629 | +var _pikchr = Module["_pikchr"] = function() { |
| 630 | + return (_pikchr = Module["_pikchr"] = Module["asm"]["f"]).apply(null, arguments); |
| 631 | +}; |
| 632 | + |
| 633 | +var stackSave = Module["stackSave"] = function() { |
| 634 | + return (stackSave = Module["stackSave"] = Module["asm"]["h"]).apply(null, arguments); |
| 635 | +}; |
| 636 | + |
| 637 | +var stackRestore = Module["stackRestore"] = function() { |
| 638 | + return (stackRestore = Module["stackRestore"] = Module["asm"]["i"]).apply(null, arguments); |
| 639 | +}; |
| 640 | + |
| 641 | +var stackAlloc = Module["stackAlloc"] = function() { |
| 642 | + return (stackAlloc = Module["stackAlloc"] = Module["asm"]["j"]).apply(null, arguments); |
| 643 | +}; |
| 648 | 644 | |
| 649 | 645 | Module["stackSave"] = stackSave; |
| 650 | 646 | |
| 651 | 647 | Module["stackRestore"] = stackRestore; |
| 652 | 648 | |
| | @@ -661,11 +657,12 @@ |
| 661 | 657 | dependenciesFulfilled = function runCaller() { |
| 662 | 658 | if (!calledRun) run(); |
| 663 | 659 | if (!calledRun) dependenciesFulfilled = runCaller; |
| 664 | 660 | }; |
| 665 | 661 | |
| 666 | | -function run() { |
| 662 | +function run(args) { |
| 663 | + args = args || arguments_; |
| 667 | 664 | if (runDependencies > 0) { |
| 668 | 665 | return; |
| 669 | 666 | } |
| 670 | 667 | preRun(); |
| 671 | 668 | if (runDependencies > 0) { |
| | @@ -702,13 +699,15 @@ |
| 702 | 699 | } |
| 703 | 700 | |
| 704 | 701 | run(); |
| 705 | 702 | |
| 706 | 703 | |
| 707 | | - return moduleArg.ready |
| 704 | + return initPikchrModule.ready |
| 708 | 705 | } |
| 709 | 706 | ); |
| 710 | 707 | })(); |
| 711 | 708 | if (typeof exports === 'object' && typeof module === 'object') |
| 712 | 709 | module.exports = initPikchrModule; |
| 713 | 710 | else if (typeof define === 'function' && define['amd']) |
| 714 | | - define([], () => initPikchrModule); |
| 711 | + define([], function() { return initPikchrModule; }); |
| 712 | +else if (typeof exports === 'object') |
| 713 | + exports["initPikchrModule"] = initPikchrModule; |
| 715 | 714 | |