diff --git a/packages/next/server/lib/squoosh/avif/avif_enc.d.ts b/packages/next/server/lib/squoosh/avif/avif_enc.d.ts new file mode 100644 index 0000000000000..d91bbf36e051c --- /dev/null +++ b/packages/next/server/lib/squoosh/avif/avif_enc.d.ts @@ -0,0 +1,32 @@ +// eslint-disable-next-line no-shadow +export const enum AVIFTune { + auto, + psnr, + ssim, +} + +export interface EncodeOptions { + cqLevel: number + denoiseLevel: number + cqAlphaLevel: number + tileRowsLog2: number + tileColsLog2: number + speed: number + subsample: number + chromaDeltaQ: boolean + sharpness: number + tune: AVIFTune +} + +export interface AVIFModule extends EmscriptenWasm.Module { + encode( + data: BufferSource, + width: number, + height: number, + options: EncodeOptions + ): Uint8Array +} + +declare var moduleFactory: EmscriptenWasm.ModuleFactory + +export default moduleFactory diff --git a/packages/next/server/lib/squoosh/avif/avif_node_dec.js b/packages/next/server/lib/squoosh/avif/avif_node_dec.js new file mode 100644 index 0000000000000..c4e2a2f23ecd6 --- /dev/null +++ b/packages/next/server/lib/squoosh/avif/avif_node_dec.js @@ -0,0 +1,1794 @@ +/* eslint-disable */ +var Module = (function () { + return function (Module) { + Module = Module || {} + + var Module = typeof Module !== 'undefined' ? Module : {} + var readyPromiseResolve, readyPromiseReject + Module['ready'] = new Promise(function (resolve, reject) { + readyPromiseResolve = resolve + readyPromiseReject = reject + }) + var moduleOverrides = {} + var key + for (key in Module) { + if (Module.hasOwnProperty(key)) { + moduleOverrides[key] = Module[key] + } + } + var arguments_ = [] + var thisProgram = './this.program' + var quit_ = function (status, toThrow) { + throw toThrow + } + var ENVIRONMENT_IS_WEB = false + var ENVIRONMENT_IS_WORKER = false + var ENVIRONMENT_IS_NODE = true + var scriptDirectory = '' + function locateFile(path) { + if (Module['locateFile']) { + return Module['locateFile'](path, scriptDirectory) + } + return scriptDirectory + path + } + var read_, readBinary + var nodeFS + var nodePath + if (ENVIRONMENT_IS_NODE) { + if (ENVIRONMENT_IS_WORKER) { + scriptDirectory = require('path').dirname(scriptDirectory) + '/' + } else { + scriptDirectory = __dirname + '/' + } + read_ = function shell_read(filename, binary) { + if (!nodeFS) nodeFS = require('fs') + if (!nodePath) nodePath = require('path') + filename = nodePath['normalize'](filename) + return nodeFS['readFileSync'](filename, binary ? null : 'utf8') + } + readBinary = function readBinary(filename) { + var ret = read_(filename, true) + if (!ret.buffer) { + ret = new Uint8Array(ret) + } + assert(ret.buffer) + return ret + } + if (process['argv'].length > 1) { + thisProgram = process['argv'][1].replace(/\\/g, '/') + } + arguments_ = process['argv'].slice(2) + quit_ = function (status) { + process['exit'](status) + } + Module['inspect'] = function () { + return '[Emscripten Module object]' + } + } else { + } + var out = Module['print'] || console.log.bind(console) + var err = Module['printErr'] || console.warn.bind(console) + for (key in moduleOverrides) { + if (moduleOverrides.hasOwnProperty(key)) { + Module[key] = moduleOverrides[key] + } + } + moduleOverrides = null + if (Module['arguments']) arguments_ = Module['arguments'] + if (Module['thisProgram']) thisProgram = Module['thisProgram'] + if (Module['quit']) quit_ = Module['quit'] + var tempRet0 = 0 + var setTempRet0 = function (value) { + tempRet0 = value + } + var getTempRet0 = function () { + return tempRet0 + } + var wasmBinary + if (Module['wasmBinary']) wasmBinary = Module['wasmBinary'] + var noExitRuntime = Module['noExitRuntime'] || true + if (typeof WebAssembly !== 'object') { + abort('no native wasm support detected') + } + var wasmMemory + var ABORT = false + var EXITSTATUS + function assert(condition, text) { + if (!condition) { + abort('Assertion failed: ' + text) + } + } + var UTF8Decoder = new TextDecoder('utf8') + function UTF8ArrayToString(heap, idx, maxBytesToRead) { + var endIdx = idx + maxBytesToRead + var endPtr = idx + while (heap[endPtr] && !(endPtr >= endIdx)) ++endPtr + return UTF8Decoder.decode( + heap.subarray + ? heap.subarray(idx, endPtr) + : new Uint8Array(heap.slice(idx, endPtr)) + ) + } + function UTF8ToString(ptr, maxBytesToRead) { + if (!ptr) return '' + var maxPtr = ptr + maxBytesToRead + for (var end = ptr; !(end >= maxPtr) && HEAPU8[end]; ) ++end + return UTF8Decoder.decode(HEAPU8.subarray(ptr, end)) + } + function stringToUTF8Array(str, heap, outIdx, maxBytesToWrite) { + if (!(maxBytesToWrite > 0)) return 0 + var startIdx = outIdx + var endIdx = outIdx + maxBytesToWrite - 1 + for (var i = 0; i < str.length; ++i) { + var u = str.charCodeAt(i) + if (u >= 55296 && u <= 57343) { + var u1 = str.charCodeAt(++i) + u = (65536 + ((u & 1023) << 10)) | (u1 & 1023) + } + if (u <= 127) { + if (outIdx >= endIdx) break + heap[outIdx++] = u + } else if (u <= 2047) { + if (outIdx + 1 >= endIdx) break + heap[outIdx++] = 192 | (u >> 6) + heap[outIdx++] = 128 | (u & 63) + } else if (u <= 65535) { + if (outIdx + 2 >= endIdx) break + heap[outIdx++] = 224 | (u >> 12) + heap[outIdx++] = 128 | ((u >> 6) & 63) + heap[outIdx++] = 128 | (u & 63) + } else { + if (outIdx + 3 >= endIdx) break + heap[outIdx++] = 240 | (u >> 18) + heap[outIdx++] = 128 | ((u >> 12) & 63) + heap[outIdx++] = 128 | ((u >> 6) & 63) + heap[outIdx++] = 128 | (u & 63) + } + } + heap[outIdx] = 0 + return outIdx - startIdx + } + function stringToUTF8(str, outPtr, maxBytesToWrite) { + return stringToUTF8Array(str, HEAPU8, outPtr, maxBytesToWrite) + } + function lengthBytesUTF8(str) { + var len = 0 + for (var i = 0; i < str.length; ++i) { + var u = str.charCodeAt(i) + if (u >= 55296 && u <= 57343) + u = (65536 + ((u & 1023) << 10)) | (str.charCodeAt(++i) & 1023) + if (u <= 127) ++len + else if (u <= 2047) len += 2 + else if (u <= 65535) len += 3 + else len += 4 + } + return len + } + var UTF16Decoder = new TextDecoder('utf-16le') + function UTF16ToString(ptr, maxBytesToRead) { + var endPtr = ptr + var idx = endPtr >> 1 + var maxIdx = idx + maxBytesToRead / 2 + while (!(idx >= maxIdx) && HEAPU16[idx]) ++idx + endPtr = idx << 1 + return UTF16Decoder.decode(HEAPU8.subarray(ptr, endPtr)) + var str = '' + for (var i = 0; !(i >= maxBytesToRead / 2); ++i) { + var codeUnit = HEAP16[(ptr + i * 2) >> 1] + if (codeUnit == 0) break + str += String.fromCharCode(codeUnit) + } + return str + } + function stringToUTF16(str, outPtr, maxBytesToWrite) { + if (maxBytesToWrite === undefined) { + maxBytesToWrite = 2147483647 + } + if (maxBytesToWrite < 2) return 0 + maxBytesToWrite -= 2 + var startPtr = outPtr + var numCharsToWrite = + maxBytesToWrite < str.length * 2 ? maxBytesToWrite / 2 : str.length + for (var i = 0; i < numCharsToWrite; ++i) { + var codeUnit = str.charCodeAt(i) + HEAP16[outPtr >> 1] = codeUnit + outPtr += 2 + } + HEAP16[outPtr >> 1] = 0 + return outPtr - startPtr + } + function lengthBytesUTF16(str) { + return str.length * 2 + } + function UTF32ToString(ptr, maxBytesToRead) { + var i = 0 + var str = '' + while (!(i >= maxBytesToRead / 4)) { + var utf32 = HEAP32[(ptr + i * 4) >> 2] + if (utf32 == 0) break + ++i + if (utf32 >= 65536) { + var ch = utf32 - 65536 + str += String.fromCharCode(55296 | (ch >> 10), 56320 | (ch & 1023)) + } else { + str += String.fromCharCode(utf32) + } + } + return str + } + function stringToUTF32(str, outPtr, maxBytesToWrite) { + if (maxBytesToWrite === undefined) { + maxBytesToWrite = 2147483647 + } + if (maxBytesToWrite < 4) return 0 + var startPtr = outPtr + var endPtr = startPtr + maxBytesToWrite - 4 + for (var i = 0; i < str.length; ++i) { + var codeUnit = str.charCodeAt(i) + if (codeUnit >= 55296 && codeUnit <= 57343) { + var trailSurrogate = str.charCodeAt(++i) + codeUnit = + (65536 + ((codeUnit & 1023) << 10)) | (trailSurrogate & 1023) + } + HEAP32[outPtr >> 2] = codeUnit + outPtr += 4 + if (outPtr + 4 > endPtr) break + } + HEAP32[outPtr >> 2] = 0 + return outPtr - startPtr + } + function lengthBytesUTF32(str) { + var len = 0 + for (var i = 0; i < str.length; ++i) { + var codeUnit = str.charCodeAt(i) + if (codeUnit >= 55296 && codeUnit <= 57343) ++i + len += 4 + } + return len + } + function alignUp(x, multiple) { + if (x % multiple > 0) { + x += multiple - (x % multiple) + } + return x + } + var buffer, + HEAP8, + HEAPU8, + HEAP16, + HEAPU16, + HEAP32, + HEAPU32, + HEAPF32, + HEAPF64 + function updateGlobalBufferAndViews(buf) { + buffer = buf + Module['HEAP8'] = HEAP8 = new Int8Array(buf) + Module['HEAP16'] = HEAP16 = new Int16Array(buf) + Module['HEAP32'] = HEAP32 = new Int32Array(buf) + Module['HEAPU8'] = HEAPU8 = new Uint8Array(buf) + Module['HEAPU16'] = HEAPU16 = new Uint16Array(buf) + Module['HEAPU32'] = HEAPU32 = new Uint32Array(buf) + Module['HEAPF32'] = HEAPF32 = new Float32Array(buf) + Module['HEAPF64'] = HEAPF64 = new Float64Array(buf) + } + var INITIAL_MEMORY = Module['INITIAL_MEMORY'] || 16777216 + var wasmTable + var __ATPRERUN__ = [] + var __ATINIT__ = [] + var __ATPOSTRUN__ = [] + var runtimeInitialized = false + function preRun() { + if (Module['preRun']) { + if (typeof Module['preRun'] == 'function') + Module['preRun'] = [Module['preRun']] + while (Module['preRun'].length) { + addOnPreRun(Module['preRun'].shift()) + } + } + callRuntimeCallbacks(__ATPRERUN__) + } + function initRuntime() { + runtimeInitialized = true + callRuntimeCallbacks(__ATINIT__) + } + function postRun() { + if (Module['postRun']) { + if (typeof Module['postRun'] == 'function') + Module['postRun'] = [Module['postRun']] + while (Module['postRun'].length) { + addOnPostRun(Module['postRun'].shift()) + } + } + callRuntimeCallbacks(__ATPOSTRUN__) + } + function addOnPreRun(cb) { + __ATPRERUN__.unshift(cb) + } + function addOnInit(cb) { + __ATINIT__.unshift(cb) + } + function addOnPostRun(cb) { + __ATPOSTRUN__.unshift(cb) + } + var runDependencies = 0 + var runDependencyWatcher = null + var dependenciesFulfilled = null + function addRunDependency(id) { + runDependencies++ + if (Module['monitorRunDependencies']) { + Module['monitorRunDependencies'](runDependencies) + } + } + function removeRunDependency(id) { + runDependencies-- + if (Module['monitorRunDependencies']) { + Module['monitorRunDependencies'](runDependencies) + } + if (runDependencies == 0) { + if (runDependencyWatcher !== null) { + clearInterval(runDependencyWatcher) + runDependencyWatcher = null + } + if (dependenciesFulfilled) { + var callback = dependenciesFulfilled + dependenciesFulfilled = null + callback() + } + } + } + Module['preloadedImages'] = {} + Module['preloadedAudios'] = {} + function abort(what) { + if (Module['onAbort']) { + Module['onAbort'](what) + } + what += '' + err(what) + ABORT = true + EXITSTATUS = 1 + what = 'abort(' + what + '). Build with -s ASSERTIONS=1 for more info.' + var e = new WebAssembly.RuntimeError(what) + readyPromiseReject(e) + throw e + } + var dataURIPrefix = 'data:application/octet-stream;base64,' + function isDataURI(filename) { + return filename.startsWith(dataURIPrefix) + } + if (Module['locateFile']) { + var wasmBinaryFile = 'avif_node_dec.wasm' + if (!isDataURI(wasmBinaryFile)) { + wasmBinaryFile = locateFile(wasmBinaryFile) + } + } else { + throw new Error('invariant') + } + function getBinary(file) { + try { + if (file == wasmBinaryFile && wasmBinary) { + return new Uint8Array(wasmBinary) + } + if (readBinary) { + return readBinary(file) + } else { + throw 'both async and sync fetching of the wasm failed' + } + } catch (err) { + abort(err) + } + } + function getBinaryPromise() { + if (!wasmBinary && (ENVIRONMENT_IS_WEB || ENVIRONMENT_IS_WORKER)) { + if (typeof fetch === 'function') { + return fetch(wasmBinaryFile, { credentials: 'same-origin' }) + .then(function (response) { + if (!response['ok']) { + throw ( + "failed to load wasm binary file at '" + wasmBinaryFile + "'" + ) + } + return response['arrayBuffer']() + }) + .catch(function () { + return getBinary(wasmBinaryFile) + }) + } + } + return Promise.resolve().then(function () { + return getBinary(wasmBinaryFile) + }) + } + function createWasm() { + var info = { a: asmLibraryArg } + function receiveInstance(instance, module) { + var exports = instance.exports + Module['asm'] = exports + wasmMemory = Module['asm']['C'] + updateGlobalBufferAndViews(wasmMemory.buffer) + wasmTable = Module['asm']['L'] + addOnInit(Module['asm']['D']) + removeRunDependency('wasm-instantiate') + } + addRunDependency('wasm-instantiate') + function receiveInstantiationResult(result) { + receiveInstance(result['instance']) + } + function instantiateArrayBuffer(receiver) { + return getBinaryPromise() + .then(function (binary) { + var result = WebAssembly.instantiate(binary, info) + return result + }) + .then(receiver, function (reason) { + err('failed to asynchronously prepare wasm: ' + reason) + abort(reason) + }) + } + function instantiateAsync() { + if ( + !wasmBinary && + typeof WebAssembly.instantiateStreaming === 'function' && + !isDataURI(wasmBinaryFile) && + typeof fetch === 'function' + ) { + return fetch(wasmBinaryFile, { credentials: 'same-origin' }).then( + function (response) { + var result = WebAssembly.instantiateStreaming(response, info) + return result.then(receiveInstantiationResult, function (reason) { + err('wasm streaming compile failed: ' + reason) + err('falling back to ArrayBuffer instantiation') + return instantiateArrayBuffer(receiveInstantiationResult) + }) + } + ) + } else { + return instantiateArrayBuffer(receiveInstantiationResult) + } + } + if (Module['instantiateWasm']) { + try { + var exports = Module['instantiateWasm'](info, receiveInstance) + return exports + } catch (e) { + err('Module.instantiateWasm callback failed with error: ' + e) + return false + } + } + instantiateAsync().catch(readyPromiseReject) + return {} + } + function callRuntimeCallbacks(callbacks) { + while (callbacks.length > 0) { + var callback = callbacks.shift() + if (typeof callback == 'function') { + callback(Module) + continue + } + var func = callback.func + if (typeof func === 'number') { + if (callback.arg === undefined) { + wasmTable.get(func)() + } else { + wasmTable.get(func)(callback.arg) + } + } else { + func(callback.arg === undefined ? null : callback.arg) + } + } + } + function _atexit(func, arg) {} + function ___cxa_thread_atexit(a0, a1) { + return _atexit(a0, a1) + } + function __embind_register_bigint( + primitiveType, + name, + size, + minRange, + maxRange + ) {} + function getShiftFromSize(size) { + switch (size) { + case 1: + return 0 + case 2: + return 1 + case 4: + return 2 + case 8: + return 3 + default: + throw new TypeError('Unknown type size: ' + size) + } + } + function embind_init_charCodes() { + var codes = new Array(256) + for (var i = 0; i < 256; ++i) { + codes[i] = String.fromCharCode(i) + } + embind_charCodes = codes + } + var embind_charCodes = undefined + function readLatin1String(ptr) { + var ret = '' + var c = ptr + while (HEAPU8[c]) { + ret += embind_charCodes[HEAPU8[c++]] + } + return ret + } + var awaitingDependencies = {} + var registeredTypes = {} + var typeDependencies = {} + var char_0 = 48 + var char_9 = 57 + function makeLegalFunctionName(name) { + if (undefined === name) { + return '_unknown' + } + name = name.replace(/[^a-zA-Z0-9_]/g, '$') + var f = name.charCodeAt(0) + if (f >= char_0 && f <= char_9) { + return '_' + name + } else { + return name + } + } + function createNamedFunction(name, body) { + name = makeLegalFunctionName(name) + return new Function( + 'body', + 'return function ' + + name + + '() {\n' + + ' "use strict";' + + ' return body.apply(this, arguments);\n' + + '};\n' + )(body) + } + function extendError(baseErrorType, errorName) { + var errorClass = createNamedFunction(errorName, function (message) { + this.name = errorName + this.message = message + var stack = new Error(message).stack + if (stack !== undefined) { + this.stack = + this.toString() + '\n' + stack.replace(/^Error(:[^\n]*)?\n/, '') + } + }) + errorClass.prototype = Object.create(baseErrorType.prototype) + errorClass.prototype.constructor = errorClass + errorClass.prototype.toString = function () { + if (this.message === undefined) { + return this.name + } else { + return this.name + ': ' + this.message + } + } + return errorClass + } + var BindingError = undefined + function throwBindingError(message) { + throw new BindingError(message) + } + var InternalError = undefined + function throwInternalError(message) { + throw new InternalError(message) + } + function whenDependentTypesAreResolved( + myTypes, + dependentTypes, + getTypeConverters + ) { + myTypes.forEach(function (type) { + typeDependencies[type] = dependentTypes + }) + function onComplete(typeConverters) { + var myTypeConverters = getTypeConverters(typeConverters) + if (myTypeConverters.length !== myTypes.length) { + throwInternalError('Mismatched type converter count') + } + for (var i = 0; i < myTypes.length; ++i) { + registerType(myTypes[i], myTypeConverters[i]) + } + } + var typeConverters = new Array(dependentTypes.length) + var unregisteredTypes = [] + var registered = 0 + dependentTypes.forEach(function (dt, i) { + if (registeredTypes.hasOwnProperty(dt)) { + typeConverters[i] = registeredTypes[dt] + } else { + unregisteredTypes.push(dt) + if (!awaitingDependencies.hasOwnProperty(dt)) { + awaitingDependencies[dt] = [] + } + awaitingDependencies[dt].push(function () { + typeConverters[i] = registeredTypes[dt] + ++registered + if (registered === unregisteredTypes.length) { + onComplete(typeConverters) + } + }) + } + }) + if (0 === unregisteredTypes.length) { + onComplete(typeConverters) + } + } + function registerType(rawType, registeredInstance, options) { + options = options || {} + if (!('argPackAdvance' in registeredInstance)) { + throw new TypeError( + 'registerType registeredInstance requires argPackAdvance' + ) + } + var name = registeredInstance.name + if (!rawType) { + throwBindingError( + 'type "' + name + '" must have a positive integer typeid pointer' + ) + } + if (registeredTypes.hasOwnProperty(rawType)) { + if (options.ignoreDuplicateRegistrations) { + return + } else { + throwBindingError("Cannot register type '" + name + "' twice") + } + } + registeredTypes[rawType] = registeredInstance + delete typeDependencies[rawType] + if (awaitingDependencies.hasOwnProperty(rawType)) { + var callbacks = awaitingDependencies[rawType] + delete awaitingDependencies[rawType] + callbacks.forEach(function (cb) { + cb() + }) + } + } + function __embind_register_bool( + rawType, + name, + size, + trueValue, + falseValue + ) { + var shift = getShiftFromSize(size) + name = readLatin1String(name) + registerType(rawType, { + name: name, + fromWireType: function (wt) { + return !!wt + }, + toWireType: function (destructors, o) { + return o ? trueValue : falseValue + }, + argPackAdvance: 8, + readValueFromPointer: function (pointer) { + var heap + if (size === 1) { + heap = HEAP8 + } else if (size === 2) { + heap = HEAP16 + } else if (size === 4) { + heap = HEAP32 + } else { + throw new TypeError('Unknown boolean type size: ' + name) + } + return this['fromWireType'](heap[pointer >> shift]) + }, + destructorFunction: null, + }) + } + var emval_free_list = [] + var emval_handle_array = [ + {}, + { value: undefined }, + { value: null }, + { value: true }, + { value: false }, + ] + function __emval_decref(handle) { + if (handle > 4 && 0 === --emval_handle_array[handle].refcount) { + emval_handle_array[handle] = undefined + emval_free_list.push(handle) + } + } + function count_emval_handles() { + var count = 0 + for (var i = 5; i < emval_handle_array.length; ++i) { + if (emval_handle_array[i] !== undefined) { + ++count + } + } + return count + } + function get_first_emval() { + for (var i = 5; i < emval_handle_array.length; ++i) { + if (emval_handle_array[i] !== undefined) { + return emval_handle_array[i] + } + } + return null + } + function init_emval() { + Module['count_emval_handles'] = count_emval_handles + Module['get_first_emval'] = get_first_emval + } + function __emval_register(value) { + switch (value) { + case undefined: { + return 1 + } + case null: { + return 2 + } + case true: { + return 3 + } + case false: { + return 4 + } + default: { + var handle = emval_free_list.length + ? emval_free_list.pop() + : emval_handle_array.length + emval_handle_array[handle] = { refcount: 1, value: value } + return handle + } + } + } + function simpleReadValueFromPointer(pointer) { + return this['fromWireType'](HEAPU32[pointer >> 2]) + } + function __embind_register_emval(rawType, name) { + name = readLatin1String(name) + registerType(rawType, { + name: name, + fromWireType: function (handle) { + var rv = emval_handle_array[handle].value + __emval_decref(handle) + return rv + }, + toWireType: function (destructors, value) { + return __emval_register(value) + }, + argPackAdvance: 8, + readValueFromPointer: simpleReadValueFromPointer, + destructorFunction: null, + }) + } + function _embind_repr(v) { + if (v === null) { + return 'null' + } + var t = typeof v + if (t === 'object' || t === 'array' || t === 'function') { + return v.toString() + } else { + return '' + v + } + } + function floatReadValueFromPointer(name, shift) { + switch (shift) { + case 2: + return function (pointer) { + return this['fromWireType'](HEAPF32[pointer >> 2]) + } + case 3: + return function (pointer) { + return this['fromWireType'](HEAPF64[pointer >> 3]) + } + default: + throw new TypeError('Unknown float type: ' + name) + } + } + function __embind_register_float(rawType, name, size) { + var shift = getShiftFromSize(size) + name = readLatin1String(name) + registerType(rawType, { + name: name, + fromWireType: function (value) { + return value + }, + toWireType: function (destructors, value) { + if (typeof value !== 'number' && typeof value !== 'boolean') { + throw new TypeError( + 'Cannot convert "' + _embind_repr(value) + '" to ' + this.name + ) + } + return value + }, + argPackAdvance: 8, + readValueFromPointer: floatReadValueFromPointer(name, shift), + destructorFunction: null, + }) + } + function new_(constructor, argumentList) { + if (!(constructor instanceof Function)) { + throw new TypeError( + 'new_ called with constructor type ' + + typeof constructor + + ' which is not a function' + ) + } + var dummy = createNamedFunction( + constructor.name || 'unknownFunctionName', + function () {} + ) + dummy.prototype = constructor.prototype + var obj = new dummy() + var r = constructor.apply(obj, argumentList) + return r instanceof Object ? r : obj + } + function runDestructors(destructors) { + while (destructors.length) { + var ptr = destructors.pop() + var del = destructors.pop() + del(ptr) + } + } + function craftInvokerFunction( + humanName, + argTypes, + classType, + cppInvokerFunc, + cppTargetFunc + ) { + var argCount = argTypes.length + if (argCount < 2) { + throwBindingError( + "argTypes array size mismatch! Must at least get return value and 'this' types!" + ) + } + var isClassMethodFunc = argTypes[1] !== null && classType !== null + var needsDestructorStack = false + for (var i = 1; i < argTypes.length; ++i) { + if ( + argTypes[i] !== null && + argTypes[i].destructorFunction === undefined + ) { + needsDestructorStack = true + break + } + } + var returns = argTypes[0].name !== 'void' + var argsList = '' + var argsListWired = '' + for (var i = 0; i < argCount - 2; ++i) { + argsList += (i !== 0 ? ', ' : '') + 'arg' + i + argsListWired += (i !== 0 ? ', ' : '') + 'arg' + i + 'Wired' + } + var invokerFnBody = + 'return function ' + + makeLegalFunctionName(humanName) + + '(' + + argsList + + ') {\n' + + 'if (arguments.length !== ' + + (argCount - 2) + + ') {\n' + + "throwBindingError('function " + + humanName + + " called with ' + arguments.length + ' arguments, expected " + + (argCount - 2) + + " args!');\n" + + '}\n' + if (needsDestructorStack) { + invokerFnBody += 'var destructors = [];\n' + } + var dtorStack = needsDestructorStack ? 'destructors' : 'null' + var args1 = [ + 'throwBindingError', + 'invoker', + 'fn', + 'runDestructors', + 'retType', + 'classParam', + ] + var args2 = [ + throwBindingError, + cppInvokerFunc, + cppTargetFunc, + runDestructors, + argTypes[0], + argTypes[1], + ] + if (isClassMethodFunc) { + invokerFnBody += + 'var thisWired = classParam.toWireType(' + dtorStack + ', this);\n' + } + for (var i = 0; i < argCount - 2; ++i) { + invokerFnBody += + 'var arg' + + i + + 'Wired = argType' + + i + + '.toWireType(' + + dtorStack + + ', arg' + + i + + '); // ' + + argTypes[i + 2].name + + '\n' + args1.push('argType' + i) + args2.push(argTypes[i + 2]) + } + if (isClassMethodFunc) { + argsListWired = + 'thisWired' + (argsListWired.length > 0 ? ', ' : '') + argsListWired + } + invokerFnBody += + (returns ? 'var rv = ' : '') + + 'invoker(fn' + + (argsListWired.length > 0 ? ', ' : '') + + argsListWired + + ');\n' + if (needsDestructorStack) { + invokerFnBody += 'runDestructors(destructors);\n' + } else { + for (var i = isClassMethodFunc ? 1 : 2; i < argTypes.length; ++i) { + var paramName = i === 1 ? 'thisWired' : 'arg' + (i - 2) + 'Wired' + if (argTypes[i].destructorFunction !== null) { + invokerFnBody += + paramName + + '_dtor(' + + paramName + + '); // ' + + argTypes[i].name + + '\n' + args1.push(paramName + '_dtor') + args2.push(argTypes[i].destructorFunction) + } + } + } + if (returns) { + invokerFnBody += + 'var ret = retType.fromWireType(rv);\n' + 'return ret;\n' + } else { + } + invokerFnBody += '}\n' + args1.push(invokerFnBody) + var invokerFunction = new_(Function, args1).apply(null, args2) + return invokerFunction + } + function ensureOverloadTable(proto, methodName, humanName) { + if (undefined === proto[methodName].overloadTable) { + var prevFunc = proto[methodName] + proto[methodName] = function () { + if ( + !proto[methodName].overloadTable.hasOwnProperty(arguments.length) + ) { + throwBindingError( + "Function '" + + humanName + + "' called with an invalid number of arguments (" + + arguments.length + + ') - expects one of (' + + proto[methodName].overloadTable + + ')!' + ) + } + return proto[methodName].overloadTable[arguments.length].apply( + this, + arguments + ) + } + proto[methodName].overloadTable = [] + proto[methodName].overloadTable[prevFunc.argCount] = prevFunc + } + } + function exposePublicSymbol(name, value, numArguments) { + if (Module.hasOwnProperty(name)) { + if ( + undefined === numArguments || + (undefined !== Module[name].overloadTable && + undefined !== Module[name].overloadTable[numArguments]) + ) { + throwBindingError("Cannot register public name '" + name + "' twice") + } + ensureOverloadTable(Module, name, name) + if (Module.hasOwnProperty(numArguments)) { + throwBindingError( + 'Cannot register multiple overloads of a function with the same number of arguments (' + + numArguments + + ')!' + ) + } + Module[name].overloadTable[numArguments] = value + } else { + Module[name] = value + if (undefined !== numArguments) { + Module[name].numArguments = numArguments + } + } + } + function heap32VectorToArray(count, firstElement) { + var array = [] + for (var i = 0; i < count; i++) { + array.push(HEAP32[(firstElement >> 2) + i]) + } + return array + } + function replacePublicSymbol(name, value, numArguments) { + if (!Module.hasOwnProperty(name)) { + throwInternalError('Replacing nonexistant public symbol') + } + if ( + undefined !== Module[name].overloadTable && + undefined !== numArguments + ) { + Module[name].overloadTable[numArguments] = value + } else { + Module[name] = value + Module[name].argCount = numArguments + } + } + function dynCallLegacy(sig, ptr, args) { + var f = Module['dynCall_' + sig] + return args && args.length + ? f.apply(null, [ptr].concat(args)) + : f.call(null, ptr) + } + function dynCall(sig, ptr, args) { + if (sig.includes('j')) { + return dynCallLegacy(sig, ptr, args) + } + return wasmTable.get(ptr).apply(null, args) + } + function getDynCaller(sig, ptr) { + var argCache = [] + return function () { + argCache.length = arguments.length + for (var i = 0; i < arguments.length; i++) { + argCache[i] = arguments[i] + } + return dynCall(sig, ptr, argCache) + } + } + function embind__requireFunction(signature, rawFunction) { + signature = readLatin1String(signature) + function makeDynCaller() { + if (signature.includes('j')) { + return getDynCaller(signature, rawFunction) + } + return wasmTable.get(rawFunction) + } + var fp = makeDynCaller() + if (typeof fp !== 'function') { + throwBindingError( + 'unknown function pointer with signature ' + + signature + + ': ' + + rawFunction + ) + } + return fp + } + var UnboundTypeError = undefined + function getTypeName(type) { + var ptr = ___getTypeName(type) + var rv = readLatin1String(ptr) + _free(ptr) + return rv + } + function throwUnboundTypeError(message, types) { + var unboundTypes = [] + var seen = {} + function visit(type) { + if (seen[type]) { + return + } + if (registeredTypes[type]) { + return + } + if (typeDependencies[type]) { + typeDependencies[type].forEach(visit) + return + } + unboundTypes.push(type) + seen[type] = true + } + types.forEach(visit) + throw new UnboundTypeError( + message + ': ' + unboundTypes.map(getTypeName).join([', ']) + ) + } + function __embind_register_function( + name, + argCount, + rawArgTypesAddr, + signature, + rawInvoker, + fn + ) { + var argTypes = heap32VectorToArray(argCount, rawArgTypesAddr) + name = readLatin1String(name) + rawInvoker = embind__requireFunction(signature, rawInvoker) + exposePublicSymbol( + name, + function () { + throwUnboundTypeError( + 'Cannot call ' + name + ' due to unbound types', + argTypes + ) + }, + argCount - 1 + ) + whenDependentTypesAreResolved([], argTypes, function (argTypes) { + var invokerArgsArray = [argTypes[0], null].concat(argTypes.slice(1)) + replacePublicSymbol( + name, + craftInvokerFunction(name, invokerArgsArray, null, rawInvoker, fn), + argCount - 1 + ) + return [] + }) + } + function integerReadValueFromPointer(name, shift, signed) { + switch (shift) { + case 0: + return signed + ? function readS8FromPointer(pointer) { + return HEAP8[pointer] + } + : function readU8FromPointer(pointer) { + return HEAPU8[pointer] + } + case 1: + return signed + ? function readS16FromPointer(pointer) { + return HEAP16[pointer >> 1] + } + : function readU16FromPointer(pointer) { + return HEAPU16[pointer >> 1] + } + case 2: + return signed + ? function readS32FromPointer(pointer) { + return HEAP32[pointer >> 2] + } + : function readU32FromPointer(pointer) { + return HEAPU32[pointer >> 2] + } + default: + throw new TypeError('Unknown integer type: ' + name) + } + } + function __embind_register_integer( + primitiveType, + name, + size, + minRange, + maxRange + ) { + name = readLatin1String(name) + if (maxRange === -1) { + maxRange = 4294967295 + } + var shift = getShiftFromSize(size) + var fromWireType = function (value) { + return value + } + if (minRange === 0) { + var bitshift = 32 - 8 * size + fromWireType = function (value) { + return (value << bitshift) >>> bitshift + } + } + var isUnsignedType = name.includes('unsigned') + registerType(primitiveType, { + name: name, + fromWireType: fromWireType, + toWireType: function (destructors, value) { + if (typeof value !== 'number' && typeof value !== 'boolean') { + throw new TypeError( + 'Cannot convert "' + _embind_repr(value) + '" to ' + this.name + ) + } + if (value < minRange || value > maxRange) { + throw new TypeError( + 'Passing a number "' + + _embind_repr(value) + + '" from JS side to C/C++ side to an argument of type "' + + name + + '", which is outside the valid range [' + + minRange + + ', ' + + maxRange + + ']!' + ) + } + return isUnsignedType ? value >>> 0 : value | 0 + }, + argPackAdvance: 8, + readValueFromPointer: integerReadValueFromPointer( + name, + shift, + minRange !== 0 + ), + destructorFunction: null, + }) + } + function __embind_register_memory_view(rawType, dataTypeIndex, name) { + var typeMapping = [ + Int8Array, + Uint8Array, + Int16Array, + Uint16Array, + Int32Array, + Uint32Array, + Float32Array, + Float64Array, + ] + var TA = typeMapping[dataTypeIndex] + function decodeMemoryView(handle) { + handle = handle >> 2 + var heap = HEAPU32 + var size = heap[handle] + var data = heap[handle + 1] + return new TA(buffer, data, size) + } + name = readLatin1String(name) + registerType( + rawType, + { + name: name, + fromWireType: decodeMemoryView, + argPackAdvance: 8, + readValueFromPointer: decodeMemoryView, + }, + { ignoreDuplicateRegistrations: true } + ) + } + function __embind_register_std_string(rawType, name) { + name = readLatin1String(name) + var stdStringIsUTF8 = name === 'std::string' + registerType(rawType, { + name: name, + fromWireType: function (value) { + var length = HEAPU32[value >> 2] + var str + if (stdStringIsUTF8) { + var decodeStartPtr = value + 4 + for (var i = 0; i <= length; ++i) { + var currentBytePtr = value + 4 + i + if (i == length || HEAPU8[currentBytePtr] == 0) { + var maxRead = currentBytePtr - decodeStartPtr + var stringSegment = UTF8ToString(decodeStartPtr, maxRead) + if (str === undefined) { + str = stringSegment + } else { + str += String.fromCharCode(0) + str += stringSegment + } + decodeStartPtr = currentBytePtr + 1 + } + } + } else { + var a = new Array(length) + for (var i = 0; i < length; ++i) { + a[i] = String.fromCharCode(HEAPU8[value + 4 + i]) + } + str = a.join('') + } + _free(value) + return str + }, + toWireType: function (destructors, value) { + if (value instanceof ArrayBuffer) { + value = new Uint8Array(value) + } + var getLength + var valueIsOfTypeString = typeof value === 'string' + if ( + !( + valueIsOfTypeString || + value instanceof Uint8Array || + value instanceof Uint8ClampedArray || + value instanceof Int8Array + ) + ) { + throwBindingError('Cannot pass non-string to std::string') + } + if (stdStringIsUTF8 && valueIsOfTypeString) { + getLength = function () { + return lengthBytesUTF8(value) + } + } else { + getLength = function () { + return value.length + } + } + var length = getLength() + var ptr = _malloc(4 + length + 1) + HEAPU32[ptr >> 2] = length + if (stdStringIsUTF8 && valueIsOfTypeString) { + stringToUTF8(value, ptr + 4, length + 1) + } else { + if (valueIsOfTypeString) { + for (var i = 0; i < length; ++i) { + var charCode = value.charCodeAt(i) + if (charCode > 255) { + _free(ptr) + throwBindingError( + 'String has UTF-16 code units that do not fit in 8 bits' + ) + } + HEAPU8[ptr + 4 + i] = charCode + } + } else { + for (var i = 0; i < length; ++i) { + HEAPU8[ptr + 4 + i] = value[i] + } + } + } + if (destructors !== null) { + destructors.push(_free, ptr) + } + return ptr + }, + argPackAdvance: 8, + readValueFromPointer: simpleReadValueFromPointer, + destructorFunction: function (ptr) { + _free(ptr) + }, + }) + } + function __embind_register_std_wstring(rawType, charSize, name) { + name = readLatin1String(name) + var decodeString, encodeString, getHeap, lengthBytesUTF, shift + if (charSize === 2) { + decodeString = UTF16ToString + encodeString = stringToUTF16 + lengthBytesUTF = lengthBytesUTF16 + getHeap = function () { + return HEAPU16 + } + shift = 1 + } else if (charSize === 4) { + decodeString = UTF32ToString + encodeString = stringToUTF32 + lengthBytesUTF = lengthBytesUTF32 + getHeap = function () { + return HEAPU32 + } + shift = 2 + } + registerType(rawType, { + name: name, + fromWireType: function (value) { + var length = HEAPU32[value >> 2] + var HEAP = getHeap() + var str + var decodeStartPtr = value + 4 + for (var i = 0; i <= length; ++i) { + var currentBytePtr = value + 4 + i * charSize + if (i == length || HEAP[currentBytePtr >> shift] == 0) { + var maxReadBytes = currentBytePtr - decodeStartPtr + var stringSegment = decodeString(decodeStartPtr, maxReadBytes) + if (str === undefined) { + str = stringSegment + } else { + str += String.fromCharCode(0) + str += stringSegment + } + decodeStartPtr = currentBytePtr + charSize + } + } + _free(value) + return str + }, + toWireType: function (destructors, value) { + if (!(typeof value === 'string')) { + throwBindingError( + 'Cannot pass non-string to C++ string type ' + name + ) + } + var length = lengthBytesUTF(value) + var ptr = _malloc(4 + length + charSize) + HEAPU32[ptr >> 2] = length >> shift + encodeString(value, ptr + 4, length + charSize) + if (destructors !== null) { + destructors.push(_free, ptr) + } + return ptr + }, + argPackAdvance: 8, + readValueFromPointer: simpleReadValueFromPointer, + destructorFunction: function (ptr) { + _free(ptr) + }, + }) + } + function __embind_register_void(rawType, name) { + name = readLatin1String(name) + registerType(rawType, { + isVoid: true, + name: name, + argPackAdvance: 0, + fromWireType: function () { + return undefined + }, + toWireType: function (destructors, o) { + return undefined + }, + }) + } + var emval_symbols = {} + function getStringOrSymbol(address) { + var symbol = emval_symbols[address] + if (symbol === undefined) { + return readLatin1String(address) + } else { + return symbol + } + } + function emval_get_global() { + if (typeof globalThis === 'object') { + return globalThis + } + return (function () { + return Function + })()('return this')() + } + function __emval_get_global(name) { + if (name === 0) { + return __emval_register(emval_get_global()) + } else { + name = getStringOrSymbol(name) + return __emval_register(emval_get_global()[name]) + } + } + function __emval_incref(handle) { + if (handle > 4) { + emval_handle_array[handle].refcount += 1 + } + } + function requireRegisteredType(rawType, humanName) { + var impl = registeredTypes[rawType] + if (undefined === impl) { + throwBindingError( + humanName + ' has unknown type ' + getTypeName(rawType) + ) + } + return impl + } + function craftEmvalAllocator(argCount) { + var argsList = '' + for (var i = 0; i < argCount; ++i) { + argsList += (i !== 0 ? ', ' : '') + 'arg' + i + } + var functionBody = + 'return function emval_allocator_' + + argCount + + '(constructor, argTypes, args) {\n' + for (var i = 0; i < argCount; ++i) { + functionBody += + 'var argType' + + i + + " = requireRegisteredType(Module['HEAP32'][(argTypes >>> 2) + " + + i + + '], "parameter ' + + i + + '");\n' + + 'var arg' + + i + + ' = argType' + + i + + '.readValueFromPointer(args);\n' + + 'args += argType' + + i + + "['argPackAdvance'];\n" + } + functionBody += + 'var obj = new constructor(' + + argsList + + ');\n' + + 'return __emval_register(obj);\n' + + '}\n' + return new Function( + 'requireRegisteredType', + 'Module', + '__emval_register', + functionBody + )(requireRegisteredType, Module, __emval_register) + } + var emval_newers = {} + function requireHandle(handle) { + if (!handle) { + throwBindingError('Cannot use deleted val. handle = ' + handle) + } + return emval_handle_array[handle].value + } + function __emval_new(handle, argCount, argTypes, args) { + handle = requireHandle(handle) + var newer = emval_newers[argCount] + if (!newer) { + newer = craftEmvalAllocator(argCount) + emval_newers[argCount] = newer + } + return newer(handle, argTypes, args) + } + function _abort() { + abort() + } + function _longjmp(env, value) { + _setThrew(env, value || 1) + throw 'longjmp' + } + function _emscripten_longjmp(a0, a1) { + return _longjmp(a0, a1) + } + function _emscripten_memcpy_big(dest, src, num) { + HEAPU8.copyWithin(dest, src, src + num) + } + function emscripten_realloc_buffer(size) { + try { + wasmMemory.grow((size - buffer.byteLength + 65535) >>> 16) + updateGlobalBufferAndViews(wasmMemory.buffer) + return 1 + } catch (e) {} + } + function _emscripten_resize_heap(requestedSize) { + var oldSize = HEAPU8.length + requestedSize = requestedSize >>> 0 + var maxHeapSize = 2147483648 + if (requestedSize > maxHeapSize) { + return false + } + for (var cutDown = 1; cutDown <= 4; cutDown *= 2) { + var overGrownHeapSize = oldSize * (1 + 0.2 / cutDown) + overGrownHeapSize = Math.min( + overGrownHeapSize, + requestedSize + 100663296 + ) + var newSize = Math.min( + maxHeapSize, + alignUp(Math.max(requestedSize, overGrownHeapSize), 65536) + ) + var replacement = emscripten_realloc_buffer(newSize) + if (replacement) { + return true + } + } + return false + } + var SYSCALLS = { + mappings: {}, + buffers: [null, [], []], + printChar: function (stream, curr) { + var buffer = SYSCALLS.buffers[stream] + if (curr === 0 || curr === 10) { + ;(stream === 1 ? out : err)(UTF8ArrayToString(buffer, 0)) + buffer.length = 0 + } else { + buffer.push(curr) + } + }, + varargs: undefined, + get: function () { + SYSCALLS.varargs += 4 + var ret = HEAP32[(SYSCALLS.varargs - 4) >> 2] + return ret + }, + getStr: function (ptr) { + var ret = UTF8ToString(ptr) + return ret + }, + get64: function (low, high) { + return low + }, + } + function _fd_close(fd) { + return 0 + } + function _fd_seek(fd, offset_low, offset_high, whence, newOffset) {} + function _fd_write(fd, iov, iovcnt, pnum) { + var num = 0 + for (var i = 0; i < iovcnt; i++) { + var ptr = HEAP32[(iov + i * 8) >> 2] + var len = HEAP32[(iov + (i * 8 + 4)) >> 2] + for (var j = 0; j < len; j++) { + SYSCALLS.printChar(fd, HEAPU8[ptr + j]) + } + num += len + } + HEAP32[pnum >> 2] = num + return 0 + } + function _getTempRet0() { + return getTempRet0() + } + function _setTempRet0(val) { + setTempRet0(val) + } + embind_init_charCodes() + BindingError = Module['BindingError'] = extendError(Error, 'BindingError') + InternalError = Module['InternalError'] = extendError( + Error, + 'InternalError' + ) + init_emval() + UnboundTypeError = Module['UnboundTypeError'] = extendError( + Error, + 'UnboundTypeError' + ) + var asmLibraryArg = { + j: ___cxa_thread_atexit, + v: __embind_register_bigint, + r: __embind_register_bool, + B: __embind_register_emval, + q: __embind_register_float, + t: __embind_register_function, + e: __embind_register_integer, + d: __embind_register_memory_view, + m: __embind_register_std_string, + l: __embind_register_std_wstring, + s: __embind_register_void, + h: __emval_decref, + i: __emval_get_global, + n: __emval_incref, + o: __emval_new, + a: _abort, + g: _emscripten_longjmp, + y: _emscripten_memcpy_big, + k: _emscripten_resize_heap, + A: _fd_close, + u: _fd_seek, + z: _fd_write, + b: _getTempRet0, + f: invoke_iii, + w: invoke_iiiii, + p: invoke_viiii, + x: invoke_viiiiiii, + c: _setTempRet0, + } + var asm = createWasm() + var ___wasm_call_ctors = (Module['___wasm_call_ctors'] = function () { + return (___wasm_call_ctors = Module['___wasm_call_ctors'] = + Module['asm']['D']).apply(null, arguments) + }) + var _malloc = (Module['_malloc'] = function () { + return (_malloc = Module['_malloc'] = Module['asm']['E']).apply( + null, + arguments + ) + }) + var _free = (Module['_free'] = function () { + return (_free = Module['_free'] = Module['asm']['F']).apply( + null, + arguments + ) + }) + var ___getTypeName = (Module['___getTypeName'] = function () { + return (___getTypeName = Module['___getTypeName'] = + Module['asm']['G']).apply(null, arguments) + }) + var ___embind_register_native_and_builtin_types = (Module[ + '___embind_register_native_and_builtin_types' + ] = function () { + return (___embind_register_native_and_builtin_types = Module[ + '___embind_register_native_and_builtin_types' + ] = + Module['asm']['H']).apply(null, arguments) + }) + var stackSave = (Module['stackSave'] = function () { + return (stackSave = Module['stackSave'] = Module['asm']['I']).apply( + null, + arguments + ) + }) + var stackRestore = (Module['stackRestore'] = function () { + return (stackRestore = Module['stackRestore'] = Module['asm']['J']).apply( + null, + arguments + ) + }) + var _setThrew = (Module['_setThrew'] = function () { + return (_setThrew = Module['_setThrew'] = Module['asm']['K']).apply( + null, + arguments + ) + }) + var dynCall_iiijii = (Module['dynCall_iiijii'] = function () { + return (dynCall_iiijii = Module['dynCall_iiijii'] = + Module['asm']['M']).apply(null, arguments) + }) + var dynCall_jiji = (Module['dynCall_jiji'] = function () { + return (dynCall_jiji = Module['dynCall_jiji'] = Module['asm']['N']).apply( + null, + arguments + ) + }) + function invoke_viiiiiii(index, a1, a2, a3, a4, a5, a6, a7) { + var sp = stackSave() + try { + wasmTable.get(index)(a1, a2, a3, a4, a5, a6, a7) + } catch (e) { + stackRestore(sp) + if (e !== e + 0 && e !== 'longjmp') throw e + _setThrew(1, 0) + } + } + function invoke_viiii(index, a1, a2, a3, a4) { + var sp = stackSave() + try { + wasmTable.get(index)(a1, a2, a3, a4) + } catch (e) { + stackRestore(sp) + if (e !== e + 0 && e !== 'longjmp') throw e + _setThrew(1, 0) + } + } + function invoke_iii(index, a1, a2) { + var sp = stackSave() + try { + return wasmTable.get(index)(a1, a2) + } catch (e) { + stackRestore(sp) + if (e !== e + 0 && e !== 'longjmp') throw e + _setThrew(1, 0) + } + } + function invoke_iiiii(index, a1, a2, a3, a4) { + var sp = stackSave() + try { + return wasmTable.get(index)(a1, a2, a3, a4) + } catch (e) { + stackRestore(sp) + if (e !== e + 0 && e !== 'longjmp') throw e + _setThrew(1, 0) + } + } + var calledRun + dependenciesFulfilled = function runCaller() { + if (!calledRun) run() + if (!calledRun) dependenciesFulfilled = runCaller + } + function run(args) { + args = args || arguments_ + if (runDependencies > 0) { + return + } + preRun() + if (runDependencies > 0) { + return + } + function doRun() { + if (calledRun) return + calledRun = true + Module['calledRun'] = true + if (ABORT) return + initRuntime() + readyPromiseResolve(Module) + if (Module['onRuntimeInitialized']) Module['onRuntimeInitialized']() + postRun() + } + if (Module['setStatus']) { + Module['setStatus']('Running...') + setTimeout(function () { + setTimeout(function () { + Module['setStatus']('') + }, 1) + doRun() + }, 1) + } else { + doRun() + } + } + Module['run'] = run + if (Module['preInit']) { + if (typeof Module['preInit'] == 'function') + Module['preInit'] = [Module['preInit']] + while (Module['preInit'].length > 0) { + Module['preInit'].pop()() + } + } + run() + + return Module.ready + } +})() +export default Module diff --git a/packages/next/server/lib/squoosh/avif/avif_node_dec.wasm b/packages/next/server/lib/squoosh/avif/avif_node_dec.wasm new file mode 100755 index 0000000000000..1cd4e1b034e1e Binary files /dev/null and b/packages/next/server/lib/squoosh/avif/avif_node_dec.wasm differ diff --git a/packages/next/server/lib/squoosh/avif/avif_node_enc.js b/packages/next/server/lib/squoosh/avif/avif_node_enc.js new file mode 100644 index 0000000000000..a3205742b4f0c --- /dev/null +++ b/packages/next/server/lib/squoosh/avif/avif_node_enc.js @@ -0,0 +1,2061 @@ +/* eslint-disable */ +var Module = (function () { + return function (Module) { + Module = Module || {} + + var Module = typeof Module !== 'undefined' ? Module : {} + var readyPromiseResolve, readyPromiseReject + Module['ready'] = new Promise(function (resolve, reject) { + readyPromiseResolve = resolve + readyPromiseReject = reject + }) + var moduleOverrides = {} + var key + for (key in Module) { + if (Module.hasOwnProperty(key)) { + moduleOverrides[key] = Module[key] + } + } + var arguments_ = [] + var thisProgram = './this.program' + var quit_ = function (status, toThrow) { + throw toThrow + } + var ENVIRONMENT_IS_WEB = false + var ENVIRONMENT_IS_WORKER = false + var ENVIRONMENT_IS_NODE = true + var scriptDirectory = '' + function locateFile(path) { + if (Module['locateFile']) { + return Module['locateFile'](path, scriptDirectory) + } + return scriptDirectory + path + } + var read_, readBinary + var nodeFS + var nodePath + if (ENVIRONMENT_IS_NODE) { + if (ENVIRONMENT_IS_WORKER) { + scriptDirectory = require('path').dirname(scriptDirectory) + '/' + } else { + scriptDirectory = __dirname + '/' + } + read_ = function shell_read(filename, binary) { + if (!nodeFS) nodeFS = require('fs') + if (!nodePath) nodePath = require('path') + filename = nodePath['normalize'](filename) + return nodeFS['readFileSync'](filename, binary ? null : 'utf8') + } + readBinary = function readBinary(filename) { + var ret = read_(filename, true) + if (!ret.buffer) { + ret = new Uint8Array(ret) + } + assert(ret.buffer) + return ret + } + if (process['argv'].length > 1) { + thisProgram = process['argv'][1].replace(/\\/g, '/') + } + arguments_ = process['argv'].slice(2) + quit_ = function (status) { + process['exit'](status) + } + Module['inspect'] = function () { + return '[Emscripten Module object]' + } + } else { + } + var out = Module['print'] || console.log.bind(console) + var err = Module['printErr'] || console.warn.bind(console) + for (key in moduleOverrides) { + if (moduleOverrides.hasOwnProperty(key)) { + Module[key] = moduleOverrides[key] + } + } + moduleOverrides = null + if (Module['arguments']) arguments_ = Module['arguments'] + if (Module['thisProgram']) thisProgram = Module['thisProgram'] + if (Module['quit']) quit_ = Module['quit'] + var tempRet0 = 0 + var setTempRet0 = function (value) { + tempRet0 = value + } + var getTempRet0 = function () { + return tempRet0 + } + var wasmBinary + if (Module['wasmBinary']) wasmBinary = Module['wasmBinary'] + var noExitRuntime = Module['noExitRuntime'] || true + if (typeof WebAssembly !== 'object') { + abort('no native wasm support detected') + } + var wasmMemory + var ABORT = false + var EXITSTATUS + function assert(condition, text) { + if (!condition) { + abort('Assertion failed: ' + text) + } + } + var UTF8Decoder = new TextDecoder('utf8') + function UTF8ArrayToString(heap, idx, maxBytesToRead) { + var endIdx = idx + maxBytesToRead + var endPtr = idx + while (heap[endPtr] && !(endPtr >= endIdx)) ++endPtr + return UTF8Decoder.decode( + heap.subarray + ? heap.subarray(idx, endPtr) + : new Uint8Array(heap.slice(idx, endPtr)) + ) + } + function UTF8ToString(ptr, maxBytesToRead) { + if (!ptr) return '' + var maxPtr = ptr + maxBytesToRead + for (var end = ptr; !(end >= maxPtr) && HEAPU8[end]; ) ++end + return UTF8Decoder.decode(HEAPU8.subarray(ptr, end)) + } + function stringToUTF8Array(str, heap, outIdx, maxBytesToWrite) { + if (!(maxBytesToWrite > 0)) return 0 + var startIdx = outIdx + var endIdx = outIdx + maxBytesToWrite - 1 + for (var i = 0; i < str.length; ++i) { + var u = str.charCodeAt(i) + if (u >= 55296 && u <= 57343) { + var u1 = str.charCodeAt(++i) + u = (65536 + ((u & 1023) << 10)) | (u1 & 1023) + } + if (u <= 127) { + if (outIdx >= endIdx) break + heap[outIdx++] = u + } else if (u <= 2047) { + if (outIdx + 1 >= endIdx) break + heap[outIdx++] = 192 | (u >> 6) + heap[outIdx++] = 128 | (u & 63) + } else if (u <= 65535) { + if (outIdx + 2 >= endIdx) break + heap[outIdx++] = 224 | (u >> 12) + heap[outIdx++] = 128 | ((u >> 6) & 63) + heap[outIdx++] = 128 | (u & 63) + } else { + if (outIdx + 3 >= endIdx) break + heap[outIdx++] = 240 | (u >> 18) + heap[outIdx++] = 128 | ((u >> 12) & 63) + heap[outIdx++] = 128 | ((u >> 6) & 63) + heap[outIdx++] = 128 | (u & 63) + } + } + heap[outIdx] = 0 + return outIdx - startIdx + } + function stringToUTF8(str, outPtr, maxBytesToWrite) { + return stringToUTF8Array(str, HEAPU8, outPtr, maxBytesToWrite) + } + function lengthBytesUTF8(str) { + var len = 0 + for (var i = 0; i < str.length; ++i) { + var u = str.charCodeAt(i) + if (u >= 55296 && u <= 57343) + u = (65536 + ((u & 1023) << 10)) | (str.charCodeAt(++i) & 1023) + if (u <= 127) ++len + else if (u <= 2047) len += 2 + else if (u <= 65535) len += 3 + else len += 4 + } + return len + } + var UTF16Decoder = new TextDecoder('utf-16le') + function UTF16ToString(ptr, maxBytesToRead) { + var endPtr = ptr + var idx = endPtr >> 1 + var maxIdx = idx + maxBytesToRead / 2 + while (!(idx >= maxIdx) && HEAPU16[idx]) ++idx + endPtr = idx << 1 + return UTF16Decoder.decode(HEAPU8.subarray(ptr, endPtr)) + var str = '' + for (var i = 0; !(i >= maxBytesToRead / 2); ++i) { + var codeUnit = HEAP16[(ptr + i * 2) >> 1] + if (codeUnit == 0) break + str += String.fromCharCode(codeUnit) + } + return str + } + function stringToUTF16(str, outPtr, maxBytesToWrite) { + if (maxBytesToWrite === undefined) { + maxBytesToWrite = 2147483647 + } + if (maxBytesToWrite < 2) return 0 + maxBytesToWrite -= 2 + var startPtr = outPtr + var numCharsToWrite = + maxBytesToWrite < str.length * 2 ? maxBytesToWrite / 2 : str.length + for (var i = 0; i < numCharsToWrite; ++i) { + var codeUnit = str.charCodeAt(i) + HEAP16[outPtr >> 1] = codeUnit + outPtr += 2 + } + HEAP16[outPtr >> 1] = 0 + return outPtr - startPtr + } + function lengthBytesUTF16(str) { + return str.length * 2 + } + function UTF32ToString(ptr, maxBytesToRead) { + var i = 0 + var str = '' + while (!(i >= maxBytesToRead / 4)) { + var utf32 = HEAP32[(ptr + i * 4) >> 2] + if (utf32 == 0) break + ++i + if (utf32 >= 65536) { + var ch = utf32 - 65536 + str += String.fromCharCode(55296 | (ch >> 10), 56320 | (ch & 1023)) + } else { + str += String.fromCharCode(utf32) + } + } + return str + } + function stringToUTF32(str, outPtr, maxBytesToWrite) { + if (maxBytesToWrite === undefined) { + maxBytesToWrite = 2147483647 + } + if (maxBytesToWrite < 4) return 0 + var startPtr = outPtr + var endPtr = startPtr + maxBytesToWrite - 4 + for (var i = 0; i < str.length; ++i) { + var codeUnit = str.charCodeAt(i) + if (codeUnit >= 55296 && codeUnit <= 57343) { + var trailSurrogate = str.charCodeAt(++i) + codeUnit = + (65536 + ((codeUnit & 1023) << 10)) | (trailSurrogate & 1023) + } + HEAP32[outPtr >> 2] = codeUnit + outPtr += 4 + if (outPtr + 4 > endPtr) break + } + HEAP32[outPtr >> 2] = 0 + return outPtr - startPtr + } + function lengthBytesUTF32(str) { + var len = 0 + for (var i = 0; i < str.length; ++i) { + var codeUnit = str.charCodeAt(i) + if (codeUnit >= 55296 && codeUnit <= 57343) ++i + len += 4 + } + return len + } + function alignUp(x, multiple) { + if (x % multiple > 0) { + x += multiple - (x % multiple) + } + return x + } + var buffer, + HEAP8, + HEAPU8, + HEAP16, + HEAPU16, + HEAP32, + HEAPU32, + HEAPF32, + HEAPF64 + function updateGlobalBufferAndViews(buf) { + buffer = buf + Module['HEAP8'] = HEAP8 = new Int8Array(buf) + Module['HEAP16'] = HEAP16 = new Int16Array(buf) + Module['HEAP32'] = HEAP32 = new Int32Array(buf) + Module['HEAPU8'] = HEAPU8 = new Uint8Array(buf) + Module['HEAPU16'] = HEAPU16 = new Uint16Array(buf) + Module['HEAPU32'] = HEAPU32 = new Uint32Array(buf) + Module['HEAPF32'] = HEAPF32 = new Float32Array(buf) + Module['HEAPF64'] = HEAPF64 = new Float64Array(buf) + } + var INITIAL_MEMORY = Module['INITIAL_MEMORY'] || 16777216 + var wasmTable + var __ATPRERUN__ = [] + var __ATINIT__ = [] + var __ATPOSTRUN__ = [] + var runtimeInitialized = false + function preRun() { + if (Module['preRun']) { + if (typeof Module['preRun'] == 'function') + Module['preRun'] = [Module['preRun']] + while (Module['preRun'].length) { + addOnPreRun(Module['preRun'].shift()) + } + } + callRuntimeCallbacks(__ATPRERUN__) + } + function initRuntime() { + runtimeInitialized = true + callRuntimeCallbacks(__ATINIT__) + } + function postRun() { + if (Module['postRun']) { + if (typeof Module['postRun'] == 'function') + Module['postRun'] = [Module['postRun']] + while (Module['postRun'].length) { + addOnPostRun(Module['postRun'].shift()) + } + } + callRuntimeCallbacks(__ATPOSTRUN__) + } + function addOnPreRun(cb) { + __ATPRERUN__.unshift(cb) + } + function addOnInit(cb) { + __ATINIT__.unshift(cb) + } + function addOnPostRun(cb) { + __ATPOSTRUN__.unshift(cb) + } + var runDependencies = 0 + var runDependencyWatcher = null + var dependenciesFulfilled = null + function addRunDependency(id) { + runDependencies++ + if (Module['monitorRunDependencies']) { + Module['monitorRunDependencies'](runDependencies) + } + } + function removeRunDependency(id) { + runDependencies-- + if (Module['monitorRunDependencies']) { + Module['monitorRunDependencies'](runDependencies) + } + if (runDependencies == 0) { + if (runDependencyWatcher !== null) { + clearInterval(runDependencyWatcher) + runDependencyWatcher = null + } + if (dependenciesFulfilled) { + var callback = dependenciesFulfilled + dependenciesFulfilled = null + callback() + } + } + } + Module['preloadedImages'] = {} + Module['preloadedAudios'] = {} + function abort(what) { + if (Module['onAbort']) { + Module['onAbort'](what) + } + what += '' + err(what) + ABORT = true + EXITSTATUS = 1 + what = 'abort(' + what + '). Build with -s ASSERTIONS=1 for more info.' + var e = new WebAssembly.RuntimeError(what) + readyPromiseReject(e) + throw e + } + var dataURIPrefix = 'data:application/octet-stream;base64,' + function isDataURI(filename) { + return filename.startsWith(dataURIPrefix) + } + if (Module['locateFile']) { + var wasmBinaryFile = 'avif_node_enc.wasm' + if (!isDataURI(wasmBinaryFile)) { + wasmBinaryFile = locateFile(wasmBinaryFile) + } + } else { + throw new Error('invariant') + } + function getBinary(file) { + try { + if (file == wasmBinaryFile && wasmBinary) { + return new Uint8Array(wasmBinary) + } + if (readBinary) { + return readBinary(file) + } else { + throw 'both async and sync fetching of the wasm failed' + } + } catch (err) { + abort(err) + } + } + function getBinaryPromise() { + if (!wasmBinary && (ENVIRONMENT_IS_WEB || ENVIRONMENT_IS_WORKER)) { + if (typeof fetch === 'function') { + return fetch(wasmBinaryFile, { credentials: 'same-origin' }) + .then(function (response) { + if (!response['ok']) { + throw ( + "failed to load wasm binary file at '" + wasmBinaryFile + "'" + ) + } + return response['arrayBuffer']() + }) + .catch(function () { + return getBinary(wasmBinaryFile) + }) + } + } + return Promise.resolve().then(function () { + return getBinary(wasmBinaryFile) + }) + } + function createWasm() { + var info = { a: asmLibraryArg } + function receiveInstance(instance, module) { + var exports = instance.exports + Module['asm'] = exports + wasmMemory = Module['asm']['P'] + updateGlobalBufferAndViews(wasmMemory.buffer) + wasmTable = Module['asm']['Y'] + addOnInit(Module['asm']['Q']) + removeRunDependency('wasm-instantiate') + } + addRunDependency('wasm-instantiate') + function receiveInstantiationResult(result) { + receiveInstance(result['instance']) + } + function instantiateArrayBuffer(receiver) { + return getBinaryPromise() + .then(function (binary) { + var result = WebAssembly.instantiate(binary, info) + return result + }) + .then(receiver, function (reason) { + err('failed to asynchronously prepare wasm: ' + reason) + abort(reason) + }) + } + function instantiateAsync() { + if ( + !wasmBinary && + typeof WebAssembly.instantiateStreaming === 'function' && + !isDataURI(wasmBinaryFile) && + typeof fetch === 'function' + ) { + return fetch(wasmBinaryFile, { credentials: 'same-origin' }).then( + function (response) { + var result = WebAssembly.instantiateStreaming(response, info) + return result.then(receiveInstantiationResult, function (reason) { + err('wasm streaming compile failed: ' + reason) + err('falling back to ArrayBuffer instantiation') + return instantiateArrayBuffer(receiveInstantiationResult) + }) + } + ) + } else { + return instantiateArrayBuffer(receiveInstantiationResult) + } + } + if (Module['instantiateWasm']) { + try { + var exports = Module['instantiateWasm'](info, receiveInstance) + return exports + } catch (e) { + err('Module.instantiateWasm callback failed with error: ' + e) + return false + } + } + instantiateAsync().catch(readyPromiseReject) + return {} + } + function callRuntimeCallbacks(callbacks) { + while (callbacks.length > 0) { + var callback = callbacks.shift() + if (typeof callback == 'function') { + callback(Module) + continue + } + var func = callback.func + if (typeof func === 'number') { + if (callback.arg === undefined) { + wasmTable.get(func)() + } else { + wasmTable.get(func)(callback.arg) + } + } else { + func(callback.arg === undefined ? null : callback.arg) + } + } + } + function _atexit(func, arg) {} + function ___cxa_thread_atexit(a0, a1) { + return _atexit(a0, a1) + } + var SYSCALLS = { + mappings: {}, + buffers: [null, [], []], + printChar: function (stream, curr) { + var buffer = SYSCALLS.buffers[stream] + if (curr === 0 || curr === 10) { + ;(stream === 1 ? out : err)(UTF8ArrayToString(buffer, 0)) + buffer.length = 0 + } else { + buffer.push(curr) + } + }, + varargs: undefined, + get: function () { + SYSCALLS.varargs += 4 + var ret = HEAP32[(SYSCALLS.varargs - 4) >> 2] + return ret + }, + getStr: function (ptr) { + var ret = UTF8ToString(ptr) + return ret + }, + get64: function (low, high) { + return low + }, + } + function ___sys_fcntl64(fd, cmd, varargs) { + SYSCALLS.varargs = varargs + return 0 + } + function ___sys_ioctl(fd, op, varargs) { + SYSCALLS.varargs = varargs + return 0 + } + function ___sys_open(path, flags, varargs) { + SYSCALLS.varargs = varargs + } + var structRegistrations = {} + function runDestructors(destructors) { + while (destructors.length) { + var ptr = destructors.pop() + var del = destructors.pop() + del(ptr) + } + } + function simpleReadValueFromPointer(pointer) { + return this['fromWireType'](HEAPU32[pointer >> 2]) + } + var awaitingDependencies = {} + var registeredTypes = {} + var typeDependencies = {} + var char_0 = 48 + var char_9 = 57 + function makeLegalFunctionName(name) { + if (undefined === name) { + return '_unknown' + } + name = name.replace(/[^a-zA-Z0-9_]/g, '$') + var f = name.charCodeAt(0) + if (f >= char_0 && f <= char_9) { + return '_' + name + } else { + return name + } + } + function createNamedFunction(name, body) { + name = makeLegalFunctionName(name) + return new Function( + 'body', + 'return function ' + + name + + '() {\n' + + ' "use strict";' + + ' return body.apply(this, arguments);\n' + + '};\n' + )(body) + } + function extendError(baseErrorType, errorName) { + var errorClass = createNamedFunction(errorName, function (message) { + this.name = errorName + this.message = message + var stack = new Error(message).stack + if (stack !== undefined) { + this.stack = + this.toString() + '\n' + stack.replace(/^Error(:[^\n]*)?\n/, '') + } + }) + errorClass.prototype = Object.create(baseErrorType.prototype) + errorClass.prototype.constructor = errorClass + errorClass.prototype.toString = function () { + if (this.message === undefined) { + return this.name + } else { + return this.name + ': ' + this.message + } + } + return errorClass + } + var InternalError = undefined + function throwInternalError(message) { + throw new InternalError(message) + } + function whenDependentTypesAreResolved( + myTypes, + dependentTypes, + getTypeConverters + ) { + myTypes.forEach(function (type) { + typeDependencies[type] = dependentTypes + }) + function onComplete(typeConverters) { + var myTypeConverters = getTypeConverters(typeConverters) + if (myTypeConverters.length !== myTypes.length) { + throwInternalError('Mismatched type converter count') + } + for (var i = 0; i < myTypes.length; ++i) { + registerType(myTypes[i], myTypeConverters[i]) + } + } + var typeConverters = new Array(dependentTypes.length) + var unregisteredTypes = [] + var registered = 0 + dependentTypes.forEach(function (dt, i) { + if (registeredTypes.hasOwnProperty(dt)) { + typeConverters[i] = registeredTypes[dt] + } else { + unregisteredTypes.push(dt) + if (!awaitingDependencies.hasOwnProperty(dt)) { + awaitingDependencies[dt] = [] + } + awaitingDependencies[dt].push(function () { + typeConverters[i] = registeredTypes[dt] + ++registered + if (registered === unregisteredTypes.length) { + onComplete(typeConverters) + } + }) + } + }) + if (0 === unregisteredTypes.length) { + onComplete(typeConverters) + } + } + function __embind_finalize_value_object(structType) { + var reg = structRegistrations[structType] + delete structRegistrations[structType] + var rawConstructor = reg.rawConstructor + var rawDestructor = reg.rawDestructor + var fieldRecords = reg.fields + var fieldTypes = fieldRecords + .map(function (field) { + return field.getterReturnType + }) + .concat( + fieldRecords.map(function (field) { + return field.setterArgumentType + }) + ) + whenDependentTypesAreResolved( + [structType], + fieldTypes, + function (fieldTypes) { + var fields = {} + fieldRecords.forEach(function (field, i) { + var fieldName = field.fieldName + var getterReturnType = fieldTypes[i] + var getter = field.getter + var getterContext = field.getterContext + var setterArgumentType = fieldTypes[i + fieldRecords.length] + var setter = field.setter + var setterContext = field.setterContext + fields[fieldName] = { + read: function (ptr) { + return getterReturnType['fromWireType']( + getter(getterContext, ptr) + ) + }, + write: function (ptr, o) { + var destructors = [] + setter( + setterContext, + ptr, + setterArgumentType['toWireType'](destructors, o) + ) + runDestructors(destructors) + }, + } + }) + return [ + { + name: reg.name, + fromWireType: function (ptr) { + var rv = {} + for (var i in fields) { + rv[i] = fields[i].read(ptr) + } + rawDestructor(ptr) + return rv + }, + toWireType: function (destructors, o) { + for (var fieldName in fields) { + if (!(fieldName in o)) { + throw new TypeError('Missing field: "' + fieldName + '"') + } + } + var ptr = rawConstructor() + for (fieldName in fields) { + fields[fieldName].write(ptr, o[fieldName]) + } + if (destructors !== null) { + destructors.push(rawDestructor, ptr) + } + return ptr + }, + argPackAdvance: 8, + readValueFromPointer: simpleReadValueFromPointer, + destructorFunction: rawDestructor, + }, + ] + } + ) + } + function __embind_register_bigint( + primitiveType, + name, + size, + minRange, + maxRange + ) {} + function getShiftFromSize(size) { + switch (size) { + case 1: + return 0 + case 2: + return 1 + case 4: + return 2 + case 8: + return 3 + default: + throw new TypeError('Unknown type size: ' + size) + } + } + function embind_init_charCodes() { + var codes = new Array(256) + for (var i = 0; i < 256; ++i) { + codes[i] = String.fromCharCode(i) + } + embind_charCodes = codes + } + var embind_charCodes = undefined + function readLatin1String(ptr) { + var ret = '' + var c = ptr + while (HEAPU8[c]) { + ret += embind_charCodes[HEAPU8[c++]] + } + return ret + } + var BindingError = undefined + function throwBindingError(message) { + throw new BindingError(message) + } + function registerType(rawType, registeredInstance, options) { + options = options || {} + if (!('argPackAdvance' in registeredInstance)) { + throw new TypeError( + 'registerType registeredInstance requires argPackAdvance' + ) + } + var name = registeredInstance.name + if (!rawType) { + throwBindingError( + 'type "' + name + '" must have a positive integer typeid pointer' + ) + } + if (registeredTypes.hasOwnProperty(rawType)) { + if (options.ignoreDuplicateRegistrations) { + return + } else { + throwBindingError("Cannot register type '" + name + "' twice") + } + } + registeredTypes[rawType] = registeredInstance + delete typeDependencies[rawType] + if (awaitingDependencies.hasOwnProperty(rawType)) { + var callbacks = awaitingDependencies[rawType] + delete awaitingDependencies[rawType] + callbacks.forEach(function (cb) { + cb() + }) + } + } + function __embind_register_bool( + rawType, + name, + size, + trueValue, + falseValue + ) { + var shift = getShiftFromSize(size) + name = readLatin1String(name) + registerType(rawType, { + name: name, + fromWireType: function (wt) { + return !!wt + }, + toWireType: function (destructors, o) { + return o ? trueValue : falseValue + }, + argPackAdvance: 8, + readValueFromPointer: function (pointer) { + var heap + if (size === 1) { + heap = HEAP8 + } else if (size === 2) { + heap = HEAP16 + } else if (size === 4) { + heap = HEAP32 + } else { + throw new TypeError('Unknown boolean type size: ' + name) + } + return this['fromWireType'](heap[pointer >> shift]) + }, + destructorFunction: null, + }) + } + var emval_free_list = [] + var emval_handle_array = [ + {}, + { value: undefined }, + { value: null }, + { value: true }, + { value: false }, + ] + function __emval_decref(handle) { + if (handle > 4 && 0 === --emval_handle_array[handle].refcount) { + emval_handle_array[handle] = undefined + emval_free_list.push(handle) + } + } + function count_emval_handles() { + var count = 0 + for (var i = 5; i < emval_handle_array.length; ++i) { + if (emval_handle_array[i] !== undefined) { + ++count + } + } + return count + } + function get_first_emval() { + for (var i = 5; i < emval_handle_array.length; ++i) { + if (emval_handle_array[i] !== undefined) { + return emval_handle_array[i] + } + } + return null + } + function init_emval() { + Module['count_emval_handles'] = count_emval_handles + Module['get_first_emval'] = get_first_emval + } + function __emval_register(value) { + switch (value) { + case undefined: { + return 1 + } + case null: { + return 2 + } + case true: { + return 3 + } + case false: { + return 4 + } + default: { + var handle = emval_free_list.length + ? emval_free_list.pop() + : emval_handle_array.length + emval_handle_array[handle] = { refcount: 1, value: value } + return handle + } + } + } + function __embind_register_emval(rawType, name) { + name = readLatin1String(name) + registerType(rawType, { + name: name, + fromWireType: function (handle) { + var rv = emval_handle_array[handle].value + __emval_decref(handle) + return rv + }, + toWireType: function (destructors, value) { + return __emval_register(value) + }, + argPackAdvance: 8, + readValueFromPointer: simpleReadValueFromPointer, + destructorFunction: null, + }) + } + function _embind_repr(v) { + if (v === null) { + return 'null' + } + var t = typeof v + if (t === 'object' || t === 'array' || t === 'function') { + return v.toString() + } else { + return '' + v + } + } + function floatReadValueFromPointer(name, shift) { + switch (shift) { + case 2: + return function (pointer) { + return this['fromWireType'](HEAPF32[pointer >> 2]) + } + case 3: + return function (pointer) { + return this['fromWireType'](HEAPF64[pointer >> 3]) + } + default: + throw new TypeError('Unknown float type: ' + name) + } + } + function __embind_register_float(rawType, name, size) { + var shift = getShiftFromSize(size) + name = readLatin1String(name) + registerType(rawType, { + name: name, + fromWireType: function (value) { + return value + }, + toWireType: function (destructors, value) { + if (typeof value !== 'number' && typeof value !== 'boolean') { + throw new TypeError( + 'Cannot convert "' + _embind_repr(value) + '" to ' + this.name + ) + } + return value + }, + argPackAdvance: 8, + readValueFromPointer: floatReadValueFromPointer(name, shift), + destructorFunction: null, + }) + } + function new_(constructor, argumentList) { + if (!(constructor instanceof Function)) { + throw new TypeError( + 'new_ called with constructor type ' + + typeof constructor + + ' which is not a function' + ) + } + var dummy = createNamedFunction( + constructor.name || 'unknownFunctionName', + function () {} + ) + dummy.prototype = constructor.prototype + var obj = new dummy() + var r = constructor.apply(obj, argumentList) + return r instanceof Object ? r : obj + } + function craftInvokerFunction( + humanName, + argTypes, + classType, + cppInvokerFunc, + cppTargetFunc + ) { + var argCount = argTypes.length + if (argCount < 2) { + throwBindingError( + "argTypes array size mismatch! Must at least get return value and 'this' types!" + ) + } + var isClassMethodFunc = argTypes[1] !== null && classType !== null + var needsDestructorStack = false + for (var i = 1; i < argTypes.length; ++i) { + if ( + argTypes[i] !== null && + argTypes[i].destructorFunction === undefined + ) { + needsDestructorStack = true + break + } + } + var returns = argTypes[0].name !== 'void' + var argsList = '' + var argsListWired = '' + for (var i = 0; i < argCount - 2; ++i) { + argsList += (i !== 0 ? ', ' : '') + 'arg' + i + argsListWired += (i !== 0 ? ', ' : '') + 'arg' + i + 'Wired' + } + var invokerFnBody = + 'return function ' + + makeLegalFunctionName(humanName) + + '(' + + argsList + + ') {\n' + + 'if (arguments.length !== ' + + (argCount - 2) + + ') {\n' + + "throwBindingError('function " + + humanName + + " called with ' + arguments.length + ' arguments, expected " + + (argCount - 2) + + " args!');\n" + + '}\n' + if (needsDestructorStack) { + invokerFnBody += 'var destructors = [];\n' + } + var dtorStack = needsDestructorStack ? 'destructors' : 'null' + var args1 = [ + 'throwBindingError', + 'invoker', + 'fn', + 'runDestructors', + 'retType', + 'classParam', + ] + var args2 = [ + throwBindingError, + cppInvokerFunc, + cppTargetFunc, + runDestructors, + argTypes[0], + argTypes[1], + ] + if (isClassMethodFunc) { + invokerFnBody += + 'var thisWired = classParam.toWireType(' + dtorStack + ', this);\n' + } + for (var i = 0; i < argCount - 2; ++i) { + invokerFnBody += + 'var arg' + + i + + 'Wired = argType' + + i + + '.toWireType(' + + dtorStack + + ', arg' + + i + + '); // ' + + argTypes[i + 2].name + + '\n' + args1.push('argType' + i) + args2.push(argTypes[i + 2]) + } + if (isClassMethodFunc) { + argsListWired = + 'thisWired' + (argsListWired.length > 0 ? ', ' : '') + argsListWired + } + invokerFnBody += + (returns ? 'var rv = ' : '') + + 'invoker(fn' + + (argsListWired.length > 0 ? ', ' : '') + + argsListWired + + ');\n' + if (needsDestructorStack) { + invokerFnBody += 'runDestructors(destructors);\n' + } else { + for (var i = isClassMethodFunc ? 1 : 2; i < argTypes.length; ++i) { + var paramName = i === 1 ? 'thisWired' : 'arg' + (i - 2) + 'Wired' + if (argTypes[i].destructorFunction !== null) { + invokerFnBody += + paramName + + '_dtor(' + + paramName + + '); // ' + + argTypes[i].name + + '\n' + args1.push(paramName + '_dtor') + args2.push(argTypes[i].destructorFunction) + } + } + } + if (returns) { + invokerFnBody += + 'var ret = retType.fromWireType(rv);\n' + 'return ret;\n' + } else { + } + invokerFnBody += '}\n' + args1.push(invokerFnBody) + var invokerFunction = new_(Function, args1).apply(null, args2) + return invokerFunction + } + function ensureOverloadTable(proto, methodName, humanName) { + if (undefined === proto[methodName].overloadTable) { + var prevFunc = proto[methodName] + proto[methodName] = function () { + if ( + !proto[methodName].overloadTable.hasOwnProperty(arguments.length) + ) { + throwBindingError( + "Function '" + + humanName + + "' called with an invalid number of arguments (" + + arguments.length + + ') - expects one of (' + + proto[methodName].overloadTable + + ')!' + ) + } + return proto[methodName].overloadTable[arguments.length].apply( + this, + arguments + ) + } + proto[methodName].overloadTable = [] + proto[methodName].overloadTable[prevFunc.argCount] = prevFunc + } + } + function exposePublicSymbol(name, value, numArguments) { + if (Module.hasOwnProperty(name)) { + if ( + undefined === numArguments || + (undefined !== Module[name].overloadTable && + undefined !== Module[name].overloadTable[numArguments]) + ) { + throwBindingError("Cannot register public name '" + name + "' twice") + } + ensureOverloadTable(Module, name, name) + if (Module.hasOwnProperty(numArguments)) { + throwBindingError( + 'Cannot register multiple overloads of a function with the same number of arguments (' + + numArguments + + ')!' + ) + } + Module[name].overloadTable[numArguments] = value + } else { + Module[name] = value + if (undefined !== numArguments) { + Module[name].numArguments = numArguments + } + } + } + function heap32VectorToArray(count, firstElement) { + var array = [] + for (var i = 0; i < count; i++) { + array.push(HEAP32[(firstElement >> 2) + i]) + } + return array + } + function replacePublicSymbol(name, value, numArguments) { + if (!Module.hasOwnProperty(name)) { + throwInternalError('Replacing nonexistant public symbol') + } + if ( + undefined !== Module[name].overloadTable && + undefined !== numArguments + ) { + Module[name].overloadTable[numArguments] = value + } else { + Module[name] = value + Module[name].argCount = numArguments + } + } + function dynCallLegacy(sig, ptr, args) { + var f = Module['dynCall_' + sig] + return args && args.length + ? f.apply(null, [ptr].concat(args)) + : f.call(null, ptr) + } + function dynCall(sig, ptr, args) { + if (sig.includes('j')) { + return dynCallLegacy(sig, ptr, args) + } + return wasmTable.get(ptr).apply(null, args) + } + function getDynCaller(sig, ptr) { + var argCache = [] + return function () { + argCache.length = arguments.length + for (var i = 0; i < arguments.length; i++) { + argCache[i] = arguments[i] + } + return dynCall(sig, ptr, argCache) + } + } + function embind__requireFunction(signature, rawFunction) { + signature = readLatin1String(signature) + function makeDynCaller() { + if (signature.includes('j')) { + return getDynCaller(signature, rawFunction) + } + return wasmTable.get(rawFunction) + } + var fp = makeDynCaller() + if (typeof fp !== 'function') { + throwBindingError( + 'unknown function pointer with signature ' + + signature + + ': ' + + rawFunction + ) + } + return fp + } + var UnboundTypeError = undefined + function getTypeName(type) { + var ptr = ___getTypeName(type) + var rv = readLatin1String(ptr) + _free(ptr) + return rv + } + function throwUnboundTypeError(message, types) { + var unboundTypes = [] + var seen = {} + function visit(type) { + if (seen[type]) { + return + } + if (registeredTypes[type]) { + return + } + if (typeDependencies[type]) { + typeDependencies[type].forEach(visit) + return + } + unboundTypes.push(type) + seen[type] = true + } + types.forEach(visit) + throw new UnboundTypeError( + message + ': ' + unboundTypes.map(getTypeName).join([', ']) + ) + } + function __embind_register_function( + name, + argCount, + rawArgTypesAddr, + signature, + rawInvoker, + fn + ) { + var argTypes = heap32VectorToArray(argCount, rawArgTypesAddr) + name = readLatin1String(name) + rawInvoker = embind__requireFunction(signature, rawInvoker) + exposePublicSymbol( + name, + function () { + throwUnboundTypeError( + 'Cannot call ' + name + ' due to unbound types', + argTypes + ) + }, + argCount - 1 + ) + whenDependentTypesAreResolved([], argTypes, function (argTypes) { + var invokerArgsArray = [argTypes[0], null].concat(argTypes.slice(1)) + replacePublicSymbol( + name, + craftInvokerFunction(name, invokerArgsArray, null, rawInvoker, fn), + argCount - 1 + ) + return [] + }) + } + function integerReadValueFromPointer(name, shift, signed) { + switch (shift) { + case 0: + return signed + ? function readS8FromPointer(pointer) { + return HEAP8[pointer] + } + : function readU8FromPointer(pointer) { + return HEAPU8[pointer] + } + case 1: + return signed + ? function readS16FromPointer(pointer) { + return HEAP16[pointer >> 1] + } + : function readU16FromPointer(pointer) { + return HEAPU16[pointer >> 1] + } + case 2: + return signed + ? function readS32FromPointer(pointer) { + return HEAP32[pointer >> 2] + } + : function readU32FromPointer(pointer) { + return HEAPU32[pointer >> 2] + } + default: + throw new TypeError('Unknown integer type: ' + name) + } + } + function __embind_register_integer( + primitiveType, + name, + size, + minRange, + maxRange + ) { + name = readLatin1String(name) + if (maxRange === -1) { + maxRange = 4294967295 + } + var shift = getShiftFromSize(size) + var fromWireType = function (value) { + return value + } + if (minRange === 0) { + var bitshift = 32 - 8 * size + fromWireType = function (value) { + return (value << bitshift) >>> bitshift + } + } + var isUnsignedType = name.includes('unsigned') + registerType(primitiveType, { + name: name, + fromWireType: fromWireType, + toWireType: function (destructors, value) { + if (typeof value !== 'number' && typeof value !== 'boolean') { + throw new TypeError( + 'Cannot convert "' + _embind_repr(value) + '" to ' + this.name + ) + } + if (value < minRange || value > maxRange) { + throw new TypeError( + 'Passing a number "' + + _embind_repr(value) + + '" from JS side to C/C++ side to an argument of type "' + + name + + '", which is outside the valid range [' + + minRange + + ', ' + + maxRange + + ']!' + ) + } + return isUnsignedType ? value >>> 0 : value | 0 + }, + argPackAdvance: 8, + readValueFromPointer: integerReadValueFromPointer( + name, + shift, + minRange !== 0 + ), + destructorFunction: null, + }) + } + function __embind_register_memory_view(rawType, dataTypeIndex, name) { + var typeMapping = [ + Int8Array, + Uint8Array, + Int16Array, + Uint16Array, + Int32Array, + Uint32Array, + Float32Array, + Float64Array, + ] + var TA = typeMapping[dataTypeIndex] + function decodeMemoryView(handle) { + handle = handle >> 2 + var heap = HEAPU32 + var size = heap[handle] + var data = heap[handle + 1] + return new TA(buffer, data, size) + } + name = readLatin1String(name) + registerType( + rawType, + { + name: name, + fromWireType: decodeMemoryView, + argPackAdvance: 8, + readValueFromPointer: decodeMemoryView, + }, + { ignoreDuplicateRegistrations: true } + ) + } + function __embind_register_std_string(rawType, name) { + name = readLatin1String(name) + var stdStringIsUTF8 = name === 'std::string' + registerType(rawType, { + name: name, + fromWireType: function (value) { + var length = HEAPU32[value >> 2] + var str + if (stdStringIsUTF8) { + var decodeStartPtr = value + 4 + for (var i = 0; i <= length; ++i) { + var currentBytePtr = value + 4 + i + if (i == length || HEAPU8[currentBytePtr] == 0) { + var maxRead = currentBytePtr - decodeStartPtr + var stringSegment = UTF8ToString(decodeStartPtr, maxRead) + if (str === undefined) { + str = stringSegment + } else { + str += String.fromCharCode(0) + str += stringSegment + } + decodeStartPtr = currentBytePtr + 1 + } + } + } else { + var a = new Array(length) + for (var i = 0; i < length; ++i) { + a[i] = String.fromCharCode(HEAPU8[value + 4 + i]) + } + str = a.join('') + } + _free(value) + return str + }, + toWireType: function (destructors, value) { + if (value instanceof ArrayBuffer) { + value = new Uint8Array(value) + } + var getLength + var valueIsOfTypeString = typeof value === 'string' + if ( + !( + valueIsOfTypeString || + value instanceof Uint8Array || + value instanceof Uint8ClampedArray || + value instanceof Int8Array + ) + ) { + throwBindingError('Cannot pass non-string to std::string') + } + if (stdStringIsUTF8 && valueIsOfTypeString) { + getLength = function () { + return lengthBytesUTF8(value) + } + } else { + getLength = function () { + return value.length + } + } + var length = getLength() + var ptr = _malloc(4 + length + 1) + HEAPU32[ptr >> 2] = length + if (stdStringIsUTF8 && valueIsOfTypeString) { + stringToUTF8(value, ptr + 4, length + 1) + } else { + if (valueIsOfTypeString) { + for (var i = 0; i < length; ++i) { + var charCode = value.charCodeAt(i) + if (charCode > 255) { + _free(ptr) + throwBindingError( + 'String has UTF-16 code units that do not fit in 8 bits' + ) + } + HEAPU8[ptr + 4 + i] = charCode + } + } else { + for (var i = 0; i < length; ++i) { + HEAPU8[ptr + 4 + i] = value[i] + } + } + } + if (destructors !== null) { + destructors.push(_free, ptr) + } + return ptr + }, + argPackAdvance: 8, + readValueFromPointer: simpleReadValueFromPointer, + destructorFunction: function (ptr) { + _free(ptr) + }, + }) + } + function __embind_register_std_wstring(rawType, charSize, name) { + name = readLatin1String(name) + var decodeString, encodeString, getHeap, lengthBytesUTF, shift + if (charSize === 2) { + decodeString = UTF16ToString + encodeString = stringToUTF16 + lengthBytesUTF = lengthBytesUTF16 + getHeap = function () { + return HEAPU16 + } + shift = 1 + } else if (charSize === 4) { + decodeString = UTF32ToString + encodeString = stringToUTF32 + lengthBytesUTF = lengthBytesUTF32 + getHeap = function () { + return HEAPU32 + } + shift = 2 + } + registerType(rawType, { + name: name, + fromWireType: function (value) { + var length = HEAPU32[value >> 2] + var HEAP = getHeap() + var str + var decodeStartPtr = value + 4 + for (var i = 0; i <= length; ++i) { + var currentBytePtr = value + 4 + i * charSize + if (i == length || HEAP[currentBytePtr >> shift] == 0) { + var maxReadBytes = currentBytePtr - decodeStartPtr + var stringSegment = decodeString(decodeStartPtr, maxReadBytes) + if (str === undefined) { + str = stringSegment + } else { + str += String.fromCharCode(0) + str += stringSegment + } + decodeStartPtr = currentBytePtr + charSize + } + } + _free(value) + return str + }, + toWireType: function (destructors, value) { + if (!(typeof value === 'string')) { + throwBindingError( + 'Cannot pass non-string to C++ string type ' + name + ) + } + var length = lengthBytesUTF(value) + var ptr = _malloc(4 + length + charSize) + HEAPU32[ptr >> 2] = length >> shift + encodeString(value, ptr + 4, length + charSize) + if (destructors !== null) { + destructors.push(_free, ptr) + } + return ptr + }, + argPackAdvance: 8, + readValueFromPointer: simpleReadValueFromPointer, + destructorFunction: function (ptr) { + _free(ptr) + }, + }) + } + function __embind_register_value_object( + rawType, + name, + constructorSignature, + rawConstructor, + destructorSignature, + rawDestructor + ) { + structRegistrations[rawType] = { + name: readLatin1String(name), + rawConstructor: embind__requireFunction( + constructorSignature, + rawConstructor + ), + rawDestructor: embind__requireFunction( + destructorSignature, + rawDestructor + ), + fields: [], + } + } + function __embind_register_value_object_field( + structType, + fieldName, + getterReturnType, + getterSignature, + getter, + getterContext, + setterArgumentType, + setterSignature, + setter, + setterContext + ) { + structRegistrations[structType].fields.push({ + fieldName: readLatin1String(fieldName), + getterReturnType: getterReturnType, + getter: embind__requireFunction(getterSignature, getter), + getterContext: getterContext, + setterArgumentType: setterArgumentType, + setter: embind__requireFunction(setterSignature, setter), + setterContext: setterContext, + }) + } + function __embind_register_void(rawType, name) { + name = readLatin1String(name) + registerType(rawType, { + isVoid: true, + name: name, + argPackAdvance: 0, + fromWireType: function () { + return undefined + }, + toWireType: function (destructors, o) { + return undefined + }, + }) + } + var emval_symbols = {} + function getStringOrSymbol(address) { + var symbol = emval_symbols[address] + if (symbol === undefined) { + return readLatin1String(address) + } else { + return symbol + } + } + function emval_get_global() { + if (typeof globalThis === 'object') { + return globalThis + } + return (function () { + return Function + })()('return this')() + } + function __emval_get_global(name) { + if (name === 0) { + return __emval_register(emval_get_global()) + } else { + name = getStringOrSymbol(name) + return __emval_register(emval_get_global()[name]) + } + } + function __emval_incref(handle) { + if (handle > 4) { + emval_handle_array[handle].refcount += 1 + } + } + function requireRegisteredType(rawType, humanName) { + var impl = registeredTypes[rawType] + if (undefined === impl) { + throwBindingError( + humanName + ' has unknown type ' + getTypeName(rawType) + ) + } + return impl + } + function craftEmvalAllocator(argCount) { + var argsList = '' + for (var i = 0; i < argCount; ++i) { + argsList += (i !== 0 ? ', ' : '') + 'arg' + i + } + var functionBody = + 'return function emval_allocator_' + + argCount + + '(constructor, argTypes, args) {\n' + for (var i = 0; i < argCount; ++i) { + functionBody += + 'var argType' + + i + + " = requireRegisteredType(Module['HEAP32'][(argTypes >>> 2) + " + + i + + '], "parameter ' + + i + + '");\n' + + 'var arg' + + i + + ' = argType' + + i + + '.readValueFromPointer(args);\n' + + 'args += argType' + + i + + "['argPackAdvance'];\n" + } + functionBody += + 'var obj = new constructor(' + + argsList + + ');\n' + + 'return __emval_register(obj);\n' + + '}\n' + return new Function( + 'requireRegisteredType', + 'Module', + '__emval_register', + functionBody + )(requireRegisteredType, Module, __emval_register) + } + var emval_newers = {} + function requireHandle(handle) { + if (!handle) { + throwBindingError('Cannot use deleted val. handle = ' + handle) + } + return emval_handle_array[handle].value + } + function __emval_new(handle, argCount, argTypes, args) { + handle = requireHandle(handle) + var newer = emval_newers[argCount] + if (!newer) { + newer = craftEmvalAllocator(argCount) + emval_newers[argCount] = newer + } + return newer(handle, argTypes, args) + } + function _abort() { + abort() + } + function _longjmp(env, value) { + _setThrew(env, value || 1) + throw 'longjmp' + } + function _emscripten_longjmp(a0, a1) { + return _longjmp(a0, a1) + } + function _emscripten_memcpy_big(dest, src, num) { + HEAPU8.copyWithin(dest, src, src + num) + } + function emscripten_realloc_buffer(size) { + try { + wasmMemory.grow((size - buffer.byteLength + 65535) >>> 16) + updateGlobalBufferAndViews(wasmMemory.buffer) + return 1 + } catch (e) {} + } + function _emscripten_resize_heap(requestedSize) { + var oldSize = HEAPU8.length + requestedSize = requestedSize >>> 0 + var maxHeapSize = 2147483648 + if (requestedSize > maxHeapSize) { + return false + } + for (var cutDown = 1; cutDown <= 4; cutDown *= 2) { + var overGrownHeapSize = oldSize * (1 + 0.2 / cutDown) + overGrownHeapSize = Math.min( + overGrownHeapSize, + requestedSize + 100663296 + ) + var newSize = Math.min( + maxHeapSize, + alignUp(Math.max(requestedSize, overGrownHeapSize), 65536) + ) + var replacement = emscripten_realloc_buffer(newSize) + if (replacement) { + return true + } + } + return false + } + function _fd_close(fd) { + return 0 + } + function _fd_read(fd, iov, iovcnt, pnum) { + var stream = SYSCALLS.getStreamFromFD(fd) + var num = SYSCALLS.doReadv(stream, iov, iovcnt) + HEAP32[pnum >> 2] = num + return 0 + } + function _fd_seek(fd, offset_low, offset_high, whence, newOffset) {} + function _fd_write(fd, iov, iovcnt, pnum) { + var num = 0 + for (var i = 0; i < iovcnt; i++) { + var ptr = HEAP32[(iov + i * 8) >> 2] + var len = HEAP32[(iov + (i * 8 + 4)) >> 2] + for (var j = 0; j < len; j++) { + SYSCALLS.printChar(fd, HEAPU8[ptr + j]) + } + num += len + } + HEAP32[pnum >> 2] = num + return 0 + } + function _getTempRet0() { + return getTempRet0() + } + function _setTempRet0(val) { + setTempRet0(val) + } + function _time(ptr) { + var ret = (Date.now() / 1e3) | 0 + if (ptr) { + HEAP32[ptr >> 2] = ret + } + return ret + } + InternalError = Module['InternalError'] = extendError( + Error, + 'InternalError' + ) + embind_init_charCodes() + BindingError = Module['BindingError'] = extendError(Error, 'BindingError') + init_emval() + UnboundTypeError = Module['UnboundTypeError'] = extendError( + Error, + 'UnboundTypeError' + ) + var asmLibraryArg = { + O: ___cxa_thread_atexit, + r: ___sys_fcntl64, + G: ___sys_ioctl, + H: ___sys_open, + x: __embind_finalize_value_object, + B: __embind_register_bigint, + K: __embind_register_bool, + J: __embind_register_emval, + t: __embind_register_float, + w: __embind_register_function, + i: __embind_register_integer, + e: __embind_register_memory_view, + u: __embind_register_std_string, + o: __embind_register_std_wstring, + z: __embind_register_value_object, + g: __embind_register_value_object_field, + L: __embind_register_void, + j: __emval_decref, + N: __emval_get_global, + v: __emval_incref, + D: __emval_new, + f: _abort, + d: _emscripten_longjmp, + E: _emscripten_memcpy_big, + n: _emscripten_resize_heap, + s: _fd_close, + F: _fd_read, + A: _fd_seek, + I: _fd_write, + b: _getTempRet0, + l: invoke_iiiii, + p: invoke_iiiiiiiii, + q: invoke_iiiiiiiiii, + C: invoke_iiiiiiiiiiii, + y: invoke_ijiii, + m: invoke_vi, + h: invoke_vii, + c: invoke_viiii, + k: invoke_viiiiiiiiii, + a: _setTempRet0, + M: _time, + } + var asm = createWasm() + var ___wasm_call_ctors = (Module['___wasm_call_ctors'] = function () { + return (___wasm_call_ctors = Module['___wasm_call_ctors'] = + Module['asm']['Q']).apply(null, arguments) + }) + var _malloc = (Module['_malloc'] = function () { + return (_malloc = Module['_malloc'] = Module['asm']['R']).apply( + null, + arguments + ) + }) + var _free = (Module['_free'] = function () { + return (_free = Module['_free'] = Module['asm']['S']).apply( + null, + arguments + ) + }) + var ___getTypeName = (Module['___getTypeName'] = function () { + return (___getTypeName = Module['___getTypeName'] = + Module['asm']['T']).apply(null, arguments) + }) + var ___embind_register_native_and_builtin_types = (Module[ + '___embind_register_native_and_builtin_types' + ] = function () { + return (___embind_register_native_and_builtin_types = Module[ + '___embind_register_native_and_builtin_types' + ] = + Module['asm']['U']).apply(null, arguments) + }) + var stackSave = (Module['stackSave'] = function () { + return (stackSave = Module['stackSave'] = Module['asm']['V']).apply( + null, + arguments + ) + }) + var stackRestore = (Module['stackRestore'] = function () { + return (stackRestore = Module['stackRestore'] = Module['asm']['W']).apply( + null, + arguments + ) + }) + var _setThrew = (Module['_setThrew'] = function () { + return (_setThrew = Module['_setThrew'] = Module['asm']['X']).apply( + null, + arguments + ) + }) + var dynCall_jiiiiiiiii = (Module['dynCall_jiiiiiiiii'] = function () { + return (dynCall_jiiiiiiiii = Module['dynCall_jiiiiiiiii'] = + Module['asm']['Z']).apply(null, arguments) + }) + var dynCall_ijiii = (Module['dynCall_ijiii'] = function () { + return (dynCall_ijiii = Module['dynCall_ijiii'] = + Module['asm']['_']).apply(null, arguments) + }) + var dynCall_jiji = (Module['dynCall_jiji'] = function () { + return (dynCall_jiji = Module['dynCall_jiji'] = Module['asm']['$']).apply( + null, + arguments + ) + }) + var dynCall_jiiiiiiii = (Module['dynCall_jiiiiiiii'] = function () { + return (dynCall_jiiiiiiii = Module['dynCall_jiiiiiiii'] = + Module['asm']['aa']).apply(null, arguments) + }) + var dynCall_jiiiiii = (Module['dynCall_jiiiiii'] = function () { + return (dynCall_jiiiiii = Module['dynCall_jiiiiii'] = + Module['asm']['ba']).apply(null, arguments) + }) + var dynCall_jiiiii = (Module['dynCall_jiiiii'] = function () { + return (dynCall_jiiiii = Module['dynCall_jiiiii'] = + Module['asm']['ca']).apply(null, arguments) + }) + var dynCall_iiijii = (Module['dynCall_iiijii'] = function () { + return (dynCall_iiijii = Module['dynCall_iiijii'] = + Module['asm']['da']).apply(null, arguments) + }) + function invoke_vi(index, a1) { + var sp = stackSave() + try { + wasmTable.get(index)(a1) + } catch (e) { + stackRestore(sp) + if (e !== e + 0 && e !== 'longjmp') throw e + _setThrew(1, 0) + } + } + function invoke_viiii(index, a1, a2, a3, a4) { + var sp = stackSave() + try { + wasmTable.get(index)(a1, a2, a3, a4) + } catch (e) { + stackRestore(sp) + if (e !== e + 0 && e !== 'longjmp') throw e + _setThrew(1, 0) + } + } + function invoke_vii(index, a1, a2) { + var sp = stackSave() + try { + wasmTable.get(index)(a1, a2) + } catch (e) { + stackRestore(sp) + if (e !== e + 0 && e !== 'longjmp') throw e + _setThrew(1, 0) + } + } + function invoke_iiiiiiiiii(index, a1, a2, a3, a4, a5, a6, a7, a8, a9) { + var sp = stackSave() + try { + return wasmTable.get(index)(a1, a2, a3, a4, a5, a6, a7, a8, a9) + } catch (e) { + stackRestore(sp) + if (e !== e + 0 && e !== 'longjmp') throw e + _setThrew(1, 0) + } + } + function invoke_iiiiiiiiiiii( + index, + a1, + a2, + a3, + a4, + a5, + a6, + a7, + a8, + a9, + a10, + a11 + ) { + var sp = stackSave() + try { + return wasmTable.get(index)( + a1, + a2, + a3, + a4, + a5, + a6, + a7, + a8, + a9, + a10, + a11 + ) + } catch (e) { + stackRestore(sp) + if (e !== e + 0 && e !== 'longjmp') throw e + _setThrew(1, 0) + } + } + function invoke_iiiii(index, a1, a2, a3, a4) { + var sp = stackSave() + try { + return wasmTable.get(index)(a1, a2, a3, a4) + } catch (e) { + stackRestore(sp) + if (e !== e + 0 && e !== 'longjmp') throw e + _setThrew(1, 0) + } + } + function invoke_viiiiiiiiii( + index, + a1, + a2, + a3, + a4, + a5, + a6, + a7, + a8, + a9, + a10 + ) { + var sp = stackSave() + try { + wasmTable.get(index)(a1, a2, a3, a4, a5, a6, a7, a8, a9, a10) + } catch (e) { + stackRestore(sp) + if (e !== e + 0 && e !== 'longjmp') throw e + _setThrew(1, 0) + } + } + function invoke_iiiiiiiii(index, a1, a2, a3, a4, a5, a6, a7, a8) { + var sp = stackSave() + try { + return wasmTable.get(index)(a1, a2, a3, a4, a5, a6, a7, a8) + } catch (e) { + stackRestore(sp) + if (e !== e + 0 && e !== 'longjmp') throw e + _setThrew(1, 0) + } + } + function invoke_ijiii(index, a1, a2, a3, a4, a5) { + var sp = stackSave() + try { + return dynCall_ijiii(index, a1, a2, a3, a4, a5) + } catch (e) { + stackRestore(sp) + if (e !== e + 0 && e !== 'longjmp') throw e + _setThrew(1, 0) + } + } + var calledRun + dependenciesFulfilled = function runCaller() { + if (!calledRun) run() + if (!calledRun) dependenciesFulfilled = runCaller + } + function run(args) { + args = args || arguments_ + if (runDependencies > 0) { + return + } + preRun() + if (runDependencies > 0) { + return + } + function doRun() { + if (calledRun) return + calledRun = true + Module['calledRun'] = true + if (ABORT) return + initRuntime() + readyPromiseResolve(Module) + if (Module['onRuntimeInitialized']) Module['onRuntimeInitialized']() + postRun() + } + if (Module['setStatus']) { + Module['setStatus']('Running...') + setTimeout(function () { + setTimeout(function () { + Module['setStatus']('') + }, 1) + doRun() + }, 1) + } else { + doRun() + } + } + Module['run'] = run + if (Module['preInit']) { + if (typeof Module['preInit'] == 'function') + Module['preInit'] = [Module['preInit']] + while (Module['preInit'].length > 0) { + Module['preInit'].pop()() + } + } + run() + + return Module.ready + } +})() +export default Module diff --git a/packages/next/server/lib/squoosh/avif/avif_node_enc.wasm b/packages/next/server/lib/squoosh/avif/avif_node_enc.wasm new file mode 100755 index 0000000000000..6a19f18bf0671 Binary files /dev/null and b/packages/next/server/lib/squoosh/avif/avif_node_enc.wasm differ diff --git a/packages/next/server/lib/squoosh/codecs.ts b/packages/next/server/lib/squoosh/codecs.ts index b913fc4d3c455..c8959dab2bba4 100644 --- a/packages/next/server/lib/squoosh/codecs.ts +++ b/packages/next/server/lib/squoosh/codecs.ts @@ -2,7 +2,40 @@ import { promises as fsp } from 'fs' import * as path from 'path' import { instantiateEmscriptenWasm, pathify } from './emscripten-utils.js' +interface DecodeModule extends EmscriptenWasm.Module { + decode: (data: Uint8Array) => ImageData +} + +type DecodeModuleFactory = EmscriptenWasm.ModuleFactory + +interface RotateModuleInstance { + exports: { + memory: WebAssembly.Memory + rotate(width: number, height: number, rotate: number): void + } +} + +interface ResizeWithAspectParams { + input_width: number + input_height: number + target_width?: number + target_height?: number +} + +export interface ResizeOptions { + width?: number + height?: number + method: 'triangle' | 'catrom' | 'mitchell' | 'lanczos3' + premultiply: boolean + linearRGB: boolean +} + +export interface RotateOptions { + numRotations: number +} + // MozJPEG +import type { MozJPEGModule as MozJPEGEncodeModule } from './mozjpeg/mozjpeg_enc' // @ts-ignore import mozEnc from './mozjpeg/mozjpeg_node_enc.js' const mozEncWasm = path.resolve(__dirname, './mozjpeg/mozjpeg_node_enc.wasm') @@ -11,6 +44,7 @@ import mozDec from './mozjpeg/mozjpeg_node_dec.js' const mozDecWasm = path.resolve(__dirname, './mozjpeg/mozjpeg_node_dec.wasm') // WebP +import type { WebPModule as WebPEncodeModule } from './webp/webp_enc' // @ts-ignore import webpEnc from './webp/webp_node_enc.js' const webpEncWasm = path.resolve(__dirname, './webp/webp_node_enc.wasm') @@ -18,6 +52,15 @@ const webpEncWasm = path.resolve(__dirname, './webp/webp_node_enc.wasm') import webpDec from './webp/webp_node_dec.js' const webpDecWasm = path.resolve(__dirname, './webp/webp_node_dec.wasm') +// AVIF +import type { AVIFModule as AVIFEncodeModule } from './avif/avif_enc' +// @ts-ignore +import avifEnc from './avif/avif_node_enc.js' +const avifEncWasm = path.resolve(__dirname, './avif/avif_node_enc.wasm') +// @ts-ignore +import avifDec from './avif/avif_node_dec.js' +const avifDecWasm = path.resolve(__dirname, './avif/avif_node_dec.wasm') + // PNG // @ts-ignore import * as pngEncDec from './png/squoosh_png.js' @@ -40,8 +83,9 @@ const resizeInit = () => resize.default(fsp.readFile(pathify(resizeWasm))) // rotate const rotateWasm = path.resolve(__dirname, './rotate/rotate.wasm') -import ImageData from './image_data.js' -;(global as any).ImageData = ImageData // mandatory for wasm binaries +// Our decoders currently rely on a `ImageData` global. +import ImageData from './image_data' +;(global as any).ImageData = ImageData function resizeNameToIndex( name: 'triangle' | 'catrom' | 'mitchell' | 'lanczos3' @@ -65,31 +109,26 @@ function resizeWithAspect({ input_height, target_width, target_height, -}: { - input_width: number - input_height: number - target_width?: number - target_height?: number -}): { width: number; height: number } { +}: ResizeWithAspectParams): { width: number; height: number } { if (!target_width && !target_height) { throw Error('Need to specify at least width or height when resizing') } + if (target_width && target_height) { return { width: target_width, height: target_height } } + if (!target_width) { return { width: Math.round((input_width / input_height) * target_height!), height: target_height!, } } - if (!target_height) { - return { - width: target_width, - height: Math.round((input_height / input_width) * target_width), - } + + return { + width: target_width, + height: Math.round((input_height / input_width) * target_width), } - throw Error('invariant') } export const preprocessors = { @@ -99,22 +138,10 @@ export const preprocessors = { instantiate: async () => { await resizeInit() return ( - buffer: Buffer | Uint8Array, + buffer: Uint8Array, input_width: number, input_height: number, - { - width, - height, - method, - premultiply, - linearRGB, - }: { - width?: number - height?: number - method: 'triangle' | 'catrom' | 'mitchell' | 'lanczos3' - premultiply: boolean - linearRGB: boolean - } + { width, height, method, premultiply, linearRGB }: ResizeOptions ) => { ;({ width, height } = resizeWithAspect({ input_width, @@ -152,19 +179,18 @@ export const preprocessors = { description: 'Rotate image', instantiate: async () => { return async ( - buffer: Buffer | Uint8Array, + buffer: Uint8Array, width: number, height: number, - { numRotations }: { numRotations: number } + { numRotations }: RotateOptions ) => { const degrees = (numRotations * 90) % 360 const sameDimensions = degrees === 0 || degrees === 180 const size = width * height * 4 - const { instance } = await WebAssembly.instantiate( - await fsp.readFile(pathify(rotateWasm)) - ) - const exports = instance.exports as any - const { memory } = exports + const instance = ( + await WebAssembly.instantiate(await fsp.readFile(pathify(rotateWasm))) + ).instance as RotateModuleInstance + const { memory } = instance.exports const additionalPagesNeeded = Math.ceil( (size * 2 - memory.buffer.byteLength + 8) / (64 * 1024) ) @@ -173,9 +199,9 @@ export const preprocessors = { } const view = new Uint8ClampedArray(memory.buffer) view.set(buffer, 8) - exports.rotate(width, height, degrees) + instance.exports.rotate(width, height, degrees) return new ImageData( - Buffer.from(view.slice(size + 8, size * 2 + 8)), + view.slice(size + 8, size * 2 + 8), sameDimensions ? width : height, sameDimensions ? height : width ) @@ -192,8 +218,13 @@ export const codecs = { name: 'MozJPEG', extension: 'jpg', detectors: [/^\xFF\xD8\xFF/], - dec: () => instantiateEmscriptenWasm(mozDec, mozDecWasm), - enc: () => instantiateEmscriptenWasm(mozEnc, mozEncWasm), + dec: () => + instantiateEmscriptenWasm(mozDec as DecodeModuleFactory, mozDecWasm), + enc: () => + instantiateEmscriptenWasm( + mozEnc as EmscriptenWasm.ModuleFactory, + mozEncWasm + ), defaultEncoderOptions: { quality: 75, baseline: false, @@ -221,9 +252,14 @@ export const codecs = { webp: { name: 'WebP', extension: 'webp', - detectors: [/^RIFF....WEBPVP8[LX ]/], - dec: () => instantiateEmscriptenWasm(webpDec, webpDecWasm), - enc: () => instantiateEmscriptenWasm(webpEnc, webpEncWasm), + detectors: [/^RIFF....WEBPVP8[LX ]/s], + dec: () => + instantiateEmscriptenWasm(webpDec as DecodeModuleFactory, webpDecWasm), + enc: () => + instantiateEmscriptenWasm( + webpEnc as EmscriptenWasm.ModuleFactory, + webpEncWasm + ), defaultEncoderOptions: { quality: 75, target_size: 0, @@ -259,6 +295,37 @@ export const codecs = { max: 100, }, }, + avif: { + name: 'AVIF', + extension: 'avif', + // eslint-disable-next-line no-control-regex + detectors: [/^\x00\x00\x00 ftypavif\x00\x00\x00\x00/], + dec: () => + instantiateEmscriptenWasm(avifDec as DecodeModuleFactory, avifDecWasm), + enc: async () => { + return instantiateEmscriptenWasm( + avifEnc as EmscriptenWasm.ModuleFactory, + avifEncWasm + ) + }, + defaultEncoderOptions: { + cqLevel: 33, + cqAlphaLevel: -1, + denoiseLevel: 0, + tileColsLog2: 0, + tileRowsLog2: 0, + speed: 6, + subsample: 1, + chromaDeltaQ: false, + sharpness: 0, + tune: 0 /* AVIFTune.auto */, + }, + autoOptimize: { + option: 'cqLevel', + min: 62, + max: 0, + }, + }, oxipng: { name: 'OxiPNG', extension: 'png', @@ -267,29 +334,29 @@ export const codecs = { dec: async () => { await pngEncDecInit() return { - decode: (buffer: Buffer | Uint8Array): Buffer => { + decode: (buffer: Buffer | Uint8Array) => { const imageData = pngEncDec.decode(buffer) pngEncDec.cleanup() return imageData }, - } as any + } }, enc: async () => { await pngEncDecInit() await oxipngInit() return { encode: ( - buffer: Buffer | Uint8Array, + buffer: Uint8ClampedArray | ArrayBuffer, width: number, height: number, - opts: any + opts: { level: number } ) => { const simplePng = pngEncDec.encode( new Uint8Array(buffer), width, height ) - const imageData = oxipng.optimise(simplePng, opts.level) + const imageData = oxipng.optimise(simplePng, opts.level, false) oxipng.cleanup() return imageData }, diff --git a/packages/next/server/lib/squoosh/emscripten-types.d.ts b/packages/next/server/lib/squoosh/emscripten-types.d.ts new file mode 100644 index 0000000000000..6397872299c54 --- /dev/null +++ b/packages/next/server/lib/squoosh/emscripten-types.d.ts @@ -0,0 +1,121 @@ +// These types roughly model the object that the JS files generated by Emscripten define. Copied from https://github.com/DefinitelyTyped/DefinitelyTyped/blob/master/types/emscripten/index.d.ts and turned into a type definition rather than a global to support our way of using Emscripten. +declare namespace EmscriptenWasm { + type ModuleFactory = ( + moduleOverrides?: ModuleOpts + ) => Promise + + type EnvironmentType = 'WEB' | 'NODE' | 'SHELL' | 'WORKER' + + // Options object for modularized Emscripten files. Shoe-horned by @surma. + // FIXME: This an incomplete definition! + interface ModuleOpts { + mainScriptUrlOrBlob?: string + noInitialRun?: boolean + locateFile?: (url: string) => string + onRuntimeInitialized?: () => void + } + + interface Module { + print(str: string): void + printErr(str: string): void + arguments: string[] + environment: EnvironmentType + preInit: { (): void }[] + preRun: { (): void }[] + postRun: { (): void }[] + preinitializedWebGLContext: WebGLRenderingContext + noInitialRun: boolean + noExitRuntime: boolean + logReadFiles: boolean + filePackagePrefixURL: string + wasmBinary: ArrayBuffer + + destroy(object: object): void + getPreloadedPackage( + remotePackageName: string, + remotePackageSize: number + ): ArrayBuffer + instantiateWasm( + imports: WebAssembly.Imports, + successCallback: (module: WebAssembly.Module) => void + ): WebAssembly.Exports + locateFile(url: string): string + onCustomMessage(event: MessageEvent): void + + Runtime: any + + ccall( + ident: string, + returnType: string | null, + argTypes: string[], + args: any[] + ): any + cwrap(ident: string, returnType: string | null, argTypes: string[]): any + + setValue(ptr: number, value: any, type: string, noSafe?: boolean): void + getValue(ptr: number, type: string, noSafe?: boolean): number + + ALLOC_NORMAL: number + ALLOC_STACK: number + ALLOC_STATIC: number + ALLOC_DYNAMIC: number + ALLOC_NONE: number + + allocate(slab: any, types: string, allocator: number, ptr: number): number + allocate(slab: any, types: string[], allocator: number, ptr: number): number + + Pointer_stringify(ptr: number, length?: number): string + UTF16ToString(ptr: number): string + stringToUTF16(str: string, outPtr: number): void + UTF32ToString(ptr: number): string + stringToUTF32(str: string, outPtr: number): void + + // USE_TYPED_ARRAYS == 1 + HEAP: Int32Array + IHEAP: Int32Array + FHEAP: Float64Array + + // USE_TYPED_ARRAYS == 2 + HEAP8: Int8Array + HEAP16: Int16Array + HEAP32: Int32Array + HEAPU8: Uint8Array + HEAPU16: Uint16Array + HEAPU32: Uint32Array + HEAPF32: Float32Array + HEAPF64: Float64Array + + TOTAL_STACK: number + TOTAL_MEMORY: number + FAST_MEMORY: number + + addOnPreRun(cb: () => any): void + addOnInit(cb: () => any): void + addOnPreMain(cb: () => any): void + addOnExit(cb: () => any): void + addOnPostRun(cb: () => any): void + + // Tools + intArrayFromString( + stringy: string, + dontAddNull?: boolean, + length?: number + ): number[] + intArrayToString(array: number[]): string + writeStringToMemory(str: string, buffer: number, dontAddNull: boolean): void + writeArrayToMemory(array: number[], buffer: number): void + writeAsciiToMemory(str: string, buffer: number, dontAddNull: boolean): void + + addRunDependency(id: any): void + removeRunDependency(id: any): void + + preloadedImages: any + preloadedAudios: any + + _malloc(size: number): number + _free(ptr: number): void + + // Augmentations below by @surma. + onRuntimeInitialized: () => void | null + } +} diff --git a/packages/next/server/lib/squoosh/emscripten-utils.ts b/packages/next/server/lib/squoosh/emscripten-utils.ts index ac66ef1dbfc4a..0cf95fd0bfedf 100644 --- a/packages/next/server/lib/squoosh/emscripten-utils.ts +++ b/packages/next/server/lib/squoosh/emscripten-utils.ts @@ -1,32 +1,26 @@ import { fileURLToPath } from 'url' -export function pathify(path: string) { +export function pathify(path: string): string { if (path.startsWith('file://')) { path = fileURLToPath(path) } return path } -export function instantiateEmscriptenWasm( - factory: (args: { locateFile: () => string }) => { - decode?: ( - buffer: Buffer | Uint8Array, - width: number, - height: number, - opts: any - ) => Buffer - encode?: ( - buffer: Buffer | Uint8Array, - width: number, - height: number, - opts: any - ) => Buffer - }, - path: string -) { +export function instantiateEmscriptenWasm( + factory: EmscriptenWasm.ModuleFactory, + path: string, + workerJS: string = '' +): Promise { return factory({ - locateFile() { - return pathify(path) + locateFile(requestPath) { + // The glue code generated by emscripten uses the original + // file names of the worker file and the wasm binary. + // These will have changed in the bundling process and + // we need to inject them here. + if (requestPath.endsWith('.wasm')) return pathify(path) + if (requestPath.endsWith('.worker.js')) return pathify(workerJS) + return requestPath }, }) } diff --git a/packages/next/server/lib/squoosh/impl.ts b/packages/next/server/lib/squoosh/impl.ts index 1d924e226c55a..40fe1d3a01a2e 100644 --- a/packages/next/server/lib/squoosh/impl.ts +++ b/packages/next/server/lib/squoosh/impl.ts @@ -2,6 +2,8 @@ import semver from 'next/dist/compiled/semver' import { codecs as supportedFormats, preprocessors } from './codecs' import ImageData from './image_data' +type EncoderKey = keyof typeof supportedFormats + // Fixed in Node.js 16.5.0 and newer. // See https://github.com/nodejs/node/pull/39337 // Eventually, remove this delay when engines is updated. @@ -37,12 +39,14 @@ export async function decodeBuffer( .join('') const key = Object.entries(supportedFormats).find(([, { detectors }]) => detectors.some((detector) => detector.exec(firstChunkString)) - )?.[0] as keyof typeof supportedFormats + )?.[0] as EncoderKey | undefined if (!key) { throw Error(`Buffer has an unsupported format`) } - const d = await supportedFormats[key].dec() - return d.decode(new Uint8Array(buffer)) + const encoder = supportedFormats[key] + const mod = await encoder.dec() + const rgba = mod.decode(new Uint8Array(buffer)) + return rgba } export async function rotate( @@ -82,7 +86,7 @@ export async function encodeJpeg( const e = supportedFormats['mozjpeg'] const m = await e.enc() await maybeDelay() - const r = await m.encode!(image.data, image.width, image.height, { + const r = await m.encode(image.data, image.width, image.height, { ...e.defaultEncoderOptions, quality, }) @@ -98,13 +102,32 @@ export async function encodeWebp( const e = supportedFormats['webp'] const m = await e.enc() await maybeDelay() - const r = await m.encode!(image.data, image.width, image.height, { + const r = await m.encode(image.data, image.width, image.height, { ...e.defaultEncoderOptions, quality, }) return Buffer.from(r) } +export async function encodeAvif( + image: ImageData, + { quality }: { quality: number } +): Promise { + image = ImageData.from(image) + + const e = supportedFormats['avif'] + const m = await e.enc() + await maybeDelay() + const val = e.autoOptimize.min + const r = await m.encode(image.data, image.width, image.height, { + ...e.defaultEncoderOptions, + // Think of cqLevel as the "amount" of quantization (0 to 62), + // so a lower value yields higher quality (0 to 100). + cqLevel: quality === 0 ? val : Math.round(val - (quality / 100) * val), + }) + return Buffer.from(r) +} + export async function encodePng( image: ImageData ): Promise { diff --git a/packages/next/server/lib/squoosh/main.ts b/packages/next/server/lib/squoosh/main.ts index 013571366f7cc..519e57245680a 100644 --- a/packages/next/server/lib/squoosh/main.ts +++ b/packages/next/server/lib/squoosh/main.ts @@ -11,7 +11,7 @@ type ResizeOperation = { type: 'resize' } & ({ width: number; height?: never } | { height: number; width?: never }) export type Operation = RotateOperation | ResizeOperation -export type Encoding = 'jpeg' | 'png' | 'webp' +export type Encoding = 'jpeg' | 'png' | 'webp' | 'avif' const getWorker = execOnce( () => @@ -64,6 +64,8 @@ export async function processBuffer( return Buffer.from(await worker.encodeJpeg(imageData, { quality })) case 'webp': return Buffer.from(await worker.encodeWebp(imageData, { quality })) + case 'avif': + return Buffer.from(await worker.encodeAvif(imageData, { quality })) case 'png': return Buffer.from(await worker.encodePng(imageData)) default: diff --git a/packages/next/server/lib/squoosh/mozjpeg/mozjpeg_enc.d.ts b/packages/next/server/lib/squoosh/mozjpeg/mozjpeg_enc.d.ts new file mode 100644 index 0000000000000..87b697a11a502 --- /dev/null +++ b/packages/next/server/lib/squoosh/mozjpeg/mozjpeg_enc.d.ts @@ -0,0 +1,38 @@ +// eslint-disable-next-line no-shadow +export const enum MozJpegColorSpace { + GRAYSCALE = 1, + RGB, + YCbCr, +} + +export interface EncodeOptions { + quality: number + baseline: boolean + arithmetic: boolean + progressive: boolean + optimize_coding: boolean + smoothing: number + color_space: MozJpegColorSpace + quant_table: number + trellis_multipass: boolean + trellis_opt_zero: boolean + trellis_opt_table: boolean + trellis_loops: number + auto_subsample: boolean + chroma_subsample: number + separate_chroma_quality: boolean + chroma_quality: number +} + +export interface MozJPEGModule extends EmscriptenWasm.Module { + encode( + data: BufferSource, + width: number, + height: number, + options: EncodeOptions + ): Uint8Array +} + +declare var moduleFactory: EmscriptenWasm.ModuleFactory + +export default moduleFactory diff --git a/packages/next/server/lib/squoosh/mozjpeg/mozjpeg_node_dec.js b/packages/next/server/lib/squoosh/mozjpeg/mozjpeg_node_dec.js index 520d6f6174482..21e580fc95f71 100644 --- a/packages/next/server/lib/squoosh/mozjpeg/mozjpeg_node_dec.js +++ b/packages/next/server/lib/squoosh/mozjpeg/mozjpeg_node_dec.js @@ -1,234 +1,506 @@ /* eslint-disable */ -import { TextDecoder } from '../text-decoder' - var Module = (function () { - // var _scriptDir = import.meta.url - return function (Module) { Module = Module || {} - var e - e || (e = typeof Module !== 'undefined' ? Module : {}) - var aa, r - e.ready = new Promise(function (a, b) { - aa = a - r = b + var Module = typeof Module !== 'undefined' ? Module : {} + var readyPromiseResolve, readyPromiseReject + Module['ready'] = new Promise(function (resolve, reject) { + readyPromiseResolve = resolve + readyPromiseReject = reject }) - var t = {}, - u - for (u in e) e.hasOwnProperty(u) && (t[u] = e[u]) - var ba = './this.program' - function ca(a, b) { - throw b - } - var da = '', - ea, - fa, - ha, - ia - da = __dirname + '/' - ea = function (a) { - ha || (ha = require('fs')) - ia || (ia = require('path')) - a = ia.normalize(a) - return ha.readFileSync(a, null) - } - fa = function (a) { - a = ea(a) - a.buffer || (a = new Uint8Array(a)) - a.buffer || v('Assertion failed: undefined') - return a - } - ca = function (a) { - process.exit(a) - } - e.inspect = function () { - return '[Emscripten Module object]' - } - var ka = e.print || console.log.bind(console), - w = e.printErr || console.warn.bind(console) - for (u in t) t.hasOwnProperty(u) && (e[u] = t[u]) - t = null - e.thisProgram && (ba = e.thisProgram) - e.quit && (ca = e.quit) - var y - e.wasmBinary && (y = e.wasmBinary) - var noExitRuntime - e.noExitRuntime && (noExitRuntime = e.noExitRuntime) - 'object' !== typeof WebAssembly && v('no native wasm support detected') - var z, - la = !1, - ma = new TextDecoder('utf8') - function na(a, b, c) { - var d = A - if (0 < c) { - c = b + c - 1 - for (var f = 0; f < a.length; ++f) { - var g = a.charCodeAt(f) - if (55296 <= g && 57343 >= g) { - var l = a.charCodeAt(++f) - g = (65536 + ((g & 1023) << 10)) | (l & 1023) - } - if (127 >= g) { - if (b >= c) break - d[b++] = g - } else { - if (2047 >= g) { - if (b + 1 >= c) break - d[b++] = 192 | (g >> 6) - } else { - if (65535 >= g) { - if (b + 2 >= c) break - d[b++] = 224 | (g >> 12) - } else { - if (b + 3 >= c) break - d[b++] = 240 | (g >> 18) - d[b++] = 128 | ((g >> 12) & 63) - } - d[b++] = 128 | ((g >> 6) & 63) - } - d[b++] = 128 | (g & 63) - } - } - d[b] = 0 - } - } - var oa = new TextDecoder('utf-16le') - function pa(a, b) { - var c = a >> 1 - for (b = c + b / 2; !(c >= b) && C[c]; ) ++c - return oa.decode(A.subarray(a, c << 1)) - } - function qa(a, b, c) { - void 0 === c && (c = 2147483647) - if (2 > c) return 0 - c -= 2 - var d = b - c = c < 2 * a.length ? c / 2 : a.length - for (var f = 0; f < c; ++f) (D[b >> 1] = a.charCodeAt(f)), (b += 2) - D[b >> 1] = 0 - return b - d - } - function ra(a) { - return 2 * a.length - } - function sa(a, b) { - for (var c = 0, d = ''; !(c >= b / 4); ) { - var f = E[(a + 4 * c) >> 2] - if (0 == f) break - ++c - 65536 <= f - ? ((f -= 65536), - (d += String.fromCharCode(55296 | (f >> 10), 56320 | (f & 1023)))) - : (d += String.fromCharCode(f)) - } - return d - } - function ta(a, b, c) { - void 0 === c && (c = 2147483647) - if (4 > c) return 0 - var d = b - c = d + c - 4 - for (var f = 0; f < a.length; ++f) { - var g = a.charCodeAt(f) - if (55296 <= g && 57343 >= g) { - var l = a.charCodeAt(++f) - g = (65536 + ((g & 1023) << 10)) | (l & 1023) + var moduleOverrides = {} + var key + for (key in Module) { + if (Module.hasOwnProperty(key)) { + moduleOverrides[key] = Module[key] + } + } + var arguments_ = [] + var thisProgram = './this.program' + var quit_ = function (status, toThrow) { + throw toThrow + } + var ENVIRONMENT_IS_WEB = false + var ENVIRONMENT_IS_WORKER = false + var ENVIRONMENT_IS_NODE = true + var scriptDirectory = '' + function locateFile(path) { + if (Module['locateFile']) { + return Module['locateFile'](path, scriptDirectory) + } + return scriptDirectory + path + } + var read_, readBinary + var nodeFS + var nodePath + if (ENVIRONMENT_IS_NODE) { + if (ENVIRONMENT_IS_WORKER) { + scriptDirectory = require('path').dirname(scriptDirectory) + '/' + } else { + scriptDirectory = __dirname + '/' + } + read_ = function shell_read(filename, binary) { + if (!nodeFS) nodeFS = require('fs') + if (!nodePath) nodePath = require('path') + filename = nodePath['normalize'](filename) + return nodeFS['readFileSync'](filename, binary ? null : 'utf8') + } + readBinary = function readBinary(filename) { + var ret = read_(filename, true) + if (!ret.buffer) { + ret = new Uint8Array(ret) } - E[b >> 2] = g - b += 4 - if (b + 4 > c) break - } - E[b >> 2] = 0 - return b - d - } - function ua(a) { - for (var b = 0, c = 0; c < a.length; ++c) { - var d = a.charCodeAt(c) - 55296 <= d && 57343 >= d && ++c - b += 4 - } - return b - } - var F, G, A, D, C, E, I, va, wa - function xa(a) { - F = a - e.HEAP8 = G = new Int8Array(a) - e.HEAP16 = D = new Int16Array(a) - e.HEAP32 = E = new Int32Array(a) - e.HEAPU8 = A = new Uint8Array(a) - e.HEAPU16 = C = new Uint16Array(a) - e.HEAPU32 = I = new Uint32Array(a) - e.HEAPF32 = va = new Float32Array(a) - e.HEAPF64 = wa = new Float64Array(a) - } - var ya = e.INITIAL_MEMORY || 16777216 - e.wasmMemory - ? (z = e.wasmMemory) - : (z = new WebAssembly.Memory({ initial: ya / 65536, maximum: 32768 })) - z && (F = z.buffer) - ya = F.byteLength - xa(F) - var J, - za = [], - Aa = [], - Ba = [], - Ca = [] - function Da() { - var a = e.preRun.shift() - za.unshift(a) - } - var K = 0, - Ea = null, - M = null - e.preloadedImages = {} - e.preloadedAudios = {} - function v(a) { - if (e.onAbort) e.onAbort(a) - w(a) - la = !0 - a = new WebAssembly.RuntimeError( - 'abort(' + a + '). Build with -s ASSERTIONS=1 for more info.' + assert(ret.buffer) + return ret + } + if (process['argv'].length > 1) { + thisProgram = process['argv'][1].replace(/\\/g, '/') + } + arguments_ = process['argv'].slice(2) + quit_ = function (status) { + process['exit'](status) + } + Module['inspect'] = function () { + return '[Emscripten Module object]' + } + } else { + } + var out = Module['print'] || console.log.bind(console) + var err = Module['printErr'] || console.warn.bind(console) + for (key in moduleOverrides) { + if (moduleOverrides.hasOwnProperty(key)) { + Module[key] = moduleOverrides[key] + } + } + moduleOverrides = null + if (Module['arguments']) arguments_ = Module['arguments'] + if (Module['thisProgram']) thisProgram = Module['thisProgram'] + if (Module['quit']) quit_ = Module['quit'] + var tempRet0 = 0 + var setTempRet0 = function (value) { + tempRet0 = value + } + var wasmBinary + if (Module['wasmBinary']) wasmBinary = Module['wasmBinary'] + var noExitRuntime = Module['noExitRuntime'] || true + if (typeof WebAssembly !== 'object') { + abort('no native wasm support detected') + } + var wasmMemory + var ABORT = false + var EXITSTATUS + function assert(condition, text) { + if (!condition) { + abort('Assertion failed: ' + text) + } + } + var UTF8Decoder = new TextDecoder('utf8') + function UTF8ArrayToString(heap, idx, maxBytesToRead) { + var endIdx = idx + maxBytesToRead + var endPtr = idx + while (heap[endPtr] && !(endPtr >= endIdx)) ++endPtr + return UTF8Decoder.decode( + heap.subarray + ? heap.subarray(idx, endPtr) + : new Uint8Array(heap.slice(idx, endPtr)) ) - r(a) - throw a } - function Fa() { - var a = N - return String.prototype.startsWith - ? a.startsWith('data:application/octet-stream;base64,') - : 0 === a.indexOf('data:application/octet-stream;base64,') + function UTF8ToString(ptr, maxBytesToRead) { + if (!ptr) return '' + var maxPtr = ptr + maxBytesToRead + for (var end = ptr; !(end >= maxPtr) && HEAPU8[end]; ) ++end + return UTF8Decoder.decode(HEAPU8.subarray(ptr, end)) + } + function stringToUTF8Array(str, heap, outIdx, maxBytesToWrite) { + if (!(maxBytesToWrite > 0)) return 0 + var startIdx = outIdx + var endIdx = outIdx + maxBytesToWrite - 1 + for (var i = 0; i < str.length; ++i) { + var u = str.charCodeAt(i) + if (u >= 55296 && u <= 57343) { + var u1 = str.charCodeAt(++i) + u = (65536 + ((u & 1023) << 10)) | (u1 & 1023) + } + if (u <= 127) { + if (outIdx >= endIdx) break + heap[outIdx++] = u + } else if (u <= 2047) { + if (outIdx + 1 >= endIdx) break + heap[outIdx++] = 192 | (u >> 6) + heap[outIdx++] = 128 | (u & 63) + } else if (u <= 65535) { + if (outIdx + 2 >= endIdx) break + heap[outIdx++] = 224 | (u >> 12) + heap[outIdx++] = 128 | ((u >> 6) & 63) + heap[outIdx++] = 128 | (u & 63) + } else { + if (outIdx + 3 >= endIdx) break + heap[outIdx++] = 240 | (u >> 18) + heap[outIdx++] = 128 | ((u >> 12) & 63) + heap[outIdx++] = 128 | ((u >> 6) & 63) + heap[outIdx++] = 128 | (u & 63) + } + } + heap[outIdx] = 0 + return outIdx - startIdx + } + function stringToUTF8(str, outPtr, maxBytesToWrite) { + return stringToUTF8Array(str, HEAPU8, outPtr, maxBytesToWrite) + } + function lengthBytesUTF8(str) { + var len = 0 + for (var i = 0; i < str.length; ++i) { + var u = str.charCodeAt(i) + if (u >= 55296 && u <= 57343) + u = (65536 + ((u & 1023) << 10)) | (str.charCodeAt(++i) & 1023) + if (u <= 127) ++len + else if (u <= 2047) len += 2 + else if (u <= 65535) len += 3 + else len += 4 + } + return len + } + var UTF16Decoder = new TextDecoder('utf-16le') + function UTF16ToString(ptr, maxBytesToRead) { + var endPtr = ptr + var idx = endPtr >> 1 + var maxIdx = idx + maxBytesToRead / 2 + while (!(idx >= maxIdx) && HEAPU16[idx]) ++idx + endPtr = idx << 1 + return UTF16Decoder.decode(HEAPU8.subarray(ptr, endPtr)) + var str = '' + for (var i = 0; !(i >= maxBytesToRead / 2); ++i) { + var codeUnit = HEAP16[(ptr + i * 2) >> 1] + if (codeUnit == 0) break + str += String.fromCharCode(codeUnit) + } + return str + } + function stringToUTF16(str, outPtr, maxBytesToWrite) { + if (maxBytesToWrite === undefined) { + maxBytesToWrite = 2147483647 + } + if (maxBytesToWrite < 2) return 0 + maxBytesToWrite -= 2 + var startPtr = outPtr + var numCharsToWrite = + maxBytesToWrite < str.length * 2 ? maxBytesToWrite / 2 : str.length + for (var i = 0; i < numCharsToWrite; ++i) { + var codeUnit = str.charCodeAt(i) + HEAP16[outPtr >> 1] = codeUnit + outPtr += 2 + } + HEAP16[outPtr >> 1] = 0 + return outPtr - startPtr + } + function lengthBytesUTF16(str) { + return str.length * 2 + } + function UTF32ToString(ptr, maxBytesToRead) { + var i = 0 + var str = '' + while (!(i >= maxBytesToRead / 4)) { + var utf32 = HEAP32[(ptr + i * 4) >> 2] + if (utf32 == 0) break + ++i + if (utf32 >= 65536) { + var ch = utf32 - 65536 + str += String.fromCharCode(55296 | (ch >> 10), 56320 | (ch & 1023)) + } else { + str += String.fromCharCode(utf32) + } + } + return str + } + function stringToUTF32(str, outPtr, maxBytesToWrite) { + if (maxBytesToWrite === undefined) { + maxBytesToWrite = 2147483647 + } + if (maxBytesToWrite < 4) return 0 + var startPtr = outPtr + var endPtr = startPtr + maxBytesToWrite - 4 + for (var i = 0; i < str.length; ++i) { + var codeUnit = str.charCodeAt(i) + if (codeUnit >= 55296 && codeUnit <= 57343) { + var trailSurrogate = str.charCodeAt(++i) + codeUnit = + (65536 + ((codeUnit & 1023) << 10)) | (trailSurrogate & 1023) + } + HEAP32[outPtr >> 2] = codeUnit + outPtr += 4 + if (outPtr + 4 > endPtr) break + } + HEAP32[outPtr >> 2] = 0 + return outPtr - startPtr + } + function lengthBytesUTF32(str) { + var len = 0 + for (var i = 0; i < str.length; ++i) { + var codeUnit = str.charCodeAt(i) + if (codeUnit >= 55296 && codeUnit <= 57343) ++i + len += 4 + } + return len + } + function writeAsciiToMemory(str, buffer, dontAddNull) { + for (var i = 0; i < str.length; ++i) { + HEAP8[buffer++ >> 0] = str.charCodeAt(i) + } + if (!dontAddNull) HEAP8[buffer >> 0] = 0 + } + function alignUp(x, multiple) { + if (x % multiple > 0) { + x += multiple - (x % multiple) + } + return x + } + var buffer, + HEAP8, + HEAPU8, + HEAP16, + HEAPU16, + HEAP32, + HEAPU32, + HEAPF32, + HEAPF64 + function updateGlobalBufferAndViews(buf) { + buffer = buf + Module['HEAP8'] = HEAP8 = new Int8Array(buf) + Module['HEAP16'] = HEAP16 = new Int16Array(buf) + Module['HEAP32'] = HEAP32 = new Int32Array(buf) + Module['HEAPU8'] = HEAPU8 = new Uint8Array(buf) + Module['HEAPU16'] = HEAPU16 = new Uint16Array(buf) + Module['HEAPU32'] = HEAPU32 = new Uint32Array(buf) + Module['HEAPF32'] = HEAPF32 = new Float32Array(buf) + Module['HEAPF64'] = HEAPF64 = new Float64Array(buf) + } + var INITIAL_MEMORY = Module['INITIAL_MEMORY'] || 16777216 + var wasmTable + var __ATPRERUN__ = [] + var __ATINIT__ = [] + var __ATPOSTRUN__ = [] + var runtimeInitialized = false + var runtimeExited = false + function preRun() { + if (Module['preRun']) { + if (typeof Module['preRun'] == 'function') + Module['preRun'] = [Module['preRun']] + while (Module['preRun'].length) { + addOnPreRun(Module['preRun'].shift()) + } + } + callRuntimeCallbacks(__ATPRERUN__) + } + function initRuntime() { + runtimeInitialized = true + callRuntimeCallbacks(__ATINIT__) + } + function exitRuntime() { + runtimeExited = true + } + function postRun() { + if (Module['postRun']) { + if (typeof Module['postRun'] == 'function') + Module['postRun'] = [Module['postRun']] + while (Module['postRun'].length) { + addOnPostRun(Module['postRun'].shift()) + } + } + callRuntimeCallbacks(__ATPOSTRUN__) + } + function addOnPreRun(cb) { + __ATPRERUN__.unshift(cb) + } + function addOnInit(cb) { + __ATINIT__.unshift(cb) + } + function addOnPostRun(cb) { + __ATPOSTRUN__.unshift(cb) + } + var runDependencies = 0 + var runDependencyWatcher = null + var dependenciesFulfilled = null + function addRunDependency(id) { + runDependencies++ + if (Module['monitorRunDependencies']) { + Module['monitorRunDependencies'](runDependencies) + } + } + function removeRunDependency(id) { + runDependencies-- + if (Module['monitorRunDependencies']) { + Module['monitorRunDependencies'](runDependencies) + } + if (runDependencies == 0) { + if (runDependencyWatcher !== null) { + clearInterval(runDependencyWatcher) + runDependencyWatcher = null + } + if (dependenciesFulfilled) { + var callback = dependenciesFulfilled + dependenciesFulfilled = null + callback() + } + } + } + Module['preloadedImages'] = {} + Module['preloadedAudios'] = {} + function abort(what) { + if (Module['onAbort']) { + Module['onAbort'](what) + } + what += '' + err(what) + ABORT = true + EXITSTATUS = 1 + what = 'abort(' + what + '). Build with -s ASSERTIONS=1 for more info.' + var e = new WebAssembly.RuntimeError(what) + readyPromiseReject(e) + throw e + } + var dataURIPrefix = 'data:application/octet-stream;base64,' + function isDataURI(filename) { + return filename.startsWith(dataURIPrefix) } - var N = 'mozjpeg_node_dec.wasm' - if (!Fa()) { - var Ga = N - N = e.locateFile ? e.locateFile(Ga, da) : da + Ga + if (Module['locateFile']) { + var wasmBinaryFile = 'mozjpeg_node_dec.wasm' + if (!isDataURI(wasmBinaryFile)) { + wasmBinaryFile = locateFile(wasmBinaryFile) + } + } else { + throw new Error('invariant') } - function Ha() { + function getBinary(file) { try { - if (y) return new Uint8Array(y) - if (fa) return fa(N) - throw 'both async and sync fetching of the wasm failed' - } catch (a) { - v(a) - } - } - function O(a) { - for (; 0 < a.length; ) { - var b = a.shift() - if ('function' == typeof b) b(e) - else { - var c = b.L - 'number' === typeof c - ? void 0 === b.I - ? J.get(c)() - : J.get(c)(b.I) - : c(void 0 === b.I ? null : b.I) + if (file == wasmBinaryFile && wasmBinary) { + return new Uint8Array(wasmBinary) } + if (readBinary) { + return readBinary(file) + } else { + throw 'both async and sync fetching of the wasm failed' + } + } catch (err) { + abort(err) } } - function Ia(a) { - switch (a) { + function getBinaryPromise() { + if (!wasmBinary && (ENVIRONMENT_IS_WEB || ENVIRONMENT_IS_WORKER)) { + if (typeof fetch === 'function') { + return fetch(wasmBinaryFile, { credentials: 'same-origin' }) + .then(function (response) { + if (!response['ok']) { + throw ( + "failed to load wasm binary file at '" + wasmBinaryFile + "'" + ) + } + return response['arrayBuffer']() + }) + .catch(function () { + return getBinary(wasmBinaryFile) + }) + } + } + return Promise.resolve().then(function () { + return getBinary(wasmBinaryFile) + }) + } + function createWasm() { + var info = { a: asmLibraryArg } + function receiveInstance(instance, module) { + var exports = instance.exports + Module['asm'] = exports + wasmMemory = Module['asm']['z'] + updateGlobalBufferAndViews(wasmMemory.buffer) + wasmTable = Module['asm']['F'] + addOnInit(Module['asm']['A']) + removeRunDependency('wasm-instantiate') + } + addRunDependency('wasm-instantiate') + function receiveInstantiationResult(result) { + receiveInstance(result['instance']) + } + function instantiateArrayBuffer(receiver) { + return getBinaryPromise() + .then(function (binary) { + var result = WebAssembly.instantiate(binary, info) + return result + }) + .then(receiver, function (reason) { + err('failed to asynchronously prepare wasm: ' + reason) + abort(reason) + }) + } + function instantiateAsync() { + if ( + !wasmBinary && + typeof WebAssembly.instantiateStreaming === 'function' && + !isDataURI(wasmBinaryFile) && + typeof fetch === 'function' + ) { + return fetch(wasmBinaryFile, { credentials: 'same-origin' }).then( + function (response) { + var result = WebAssembly.instantiateStreaming(response, info) + return result.then(receiveInstantiationResult, function (reason) { + err('wasm streaming compile failed: ' + reason) + err('falling back to ArrayBuffer instantiation') + return instantiateArrayBuffer(receiveInstantiationResult) + }) + } + ) + } else { + return instantiateArrayBuffer(receiveInstantiationResult) + } + } + if (Module['instantiateWasm']) { + try { + var exports = Module['instantiateWasm'](info, receiveInstance) + return exports + } catch (e) { + err('Module.instantiateWasm callback failed with error: ' + e) + return false + } + } + instantiateAsync().catch(readyPromiseReject) + return {} + } + function callRuntimeCallbacks(callbacks) { + while (callbacks.length > 0) { + var callback = callbacks.shift() + if (typeof callback == 'function') { + callback(Module) + continue + } + var func = callback.func + if (typeof func === 'number') { + if (callback.arg === undefined) { + wasmTable.get(func)() + } else { + wasmTable.get(func)(callback.arg) + } + } else { + func(callback.arg === undefined ? null : callback.arg) + } + } + } + var runtimeKeepaliveCounter = 0 + function keepRuntimeAlive() { + return noExitRuntime || runtimeKeepaliveCounter > 0 + } + function _atexit(func, arg) {} + function ___cxa_thread_atexit(a0, a1) { + return _atexit(a0, a1) + } + function __embind_register_bigint( + primitiveType, + name, + size, + minRange, + maxRange + ) {} + function getShiftFromSize(size) { + switch (size) { case 1: return 0 case 2: @@ -238,970 +510,1293 @@ var Module = (function () { case 8: return 3 default: - throw new TypeError('Unknown type size: ' + a) + throw new TypeError('Unknown type size: ' + size) } } - var Ja = void 0 - function P(a) { - for (var b = ''; A[a]; ) b += Ja[A[a++]] - return b + function embind_init_charCodes() { + var codes = new Array(256) + for (var i = 0; i < 256; ++i) { + codes[i] = String.fromCharCode(i) + } + embind_charCodes = codes + } + var embind_charCodes = undefined + function readLatin1String(ptr) { + var ret = '' + var c = ptr + while (HEAPU8[c]) { + ret += embind_charCodes[HEAPU8[c++]] + } + return ret } - var Q = {}, - R = {}, - S = {} - function Ka(a) { - if (void 0 === a) return '_unknown' - a = a.replace(/[^a-zA-Z0-9_]/g, '$') - var b = a.charCodeAt(0) - return 48 <= b && 57 >= b ? '_' + a : a + var awaitingDependencies = {} + var registeredTypes = {} + var typeDependencies = {} + var char_0 = 48 + var char_9 = 57 + function makeLegalFunctionName(name) { + if (undefined === name) { + return '_unknown' + } + name = name.replace(/[^a-zA-Z0-9_]/g, '$') + var f = name.charCodeAt(0) + if (f >= char_0 && f <= char_9) { + return '_' + name + } else { + return name + } } - function La(a, b) { - a = Ka(a) + function createNamedFunction(name, body) { + name = makeLegalFunctionName(name) return new Function( 'body', 'return function ' + - a + - '() {\n "use strict"; return body.apply(this, arguments);\n};\n' - )(b) - } - function Ma(a) { - var b = Error, - c = La(a, function (d) { - this.name = a - this.message = d - d = Error(d).stack - void 0 !== d && - (this.stack = - this.toString() + '\n' + d.replace(/^Error(:[^\n]*)?\n/, '')) - }) - c.prototype = Object.create(b.prototype) - c.prototype.constructor = c - c.prototype.toString = function () { - return void 0 === this.message - ? this.name - : this.name + ': ' + this.message - } - return c - } - var Na = void 0 - function T(a) { - throw new Na(a) - } - var Oa = void 0 - function Pa(a, b) { - function c(h) { - h = b(h) - if (h.length !== d.length) - throw new Oa('Mismatched type converter count') - for (var k = 0; k < d.length; ++k) U(d[k], h[k]) - } - var d = [] - d.forEach(function (h) { - S[h] = a + name + + '() {\n' + + ' "use strict";' + + ' return body.apply(this, arguments);\n' + + '};\n' + )(body) + } + function extendError(baseErrorType, errorName) { + var errorClass = createNamedFunction(errorName, function (message) { + this.name = errorName + this.message = message + var stack = new Error(message).stack + if (stack !== undefined) { + this.stack = + this.toString() + '\n' + stack.replace(/^Error(:[^\n]*)?\n/, '') + } + }) + errorClass.prototype = Object.create(baseErrorType.prototype) + errorClass.prototype.constructor = errorClass + errorClass.prototype.toString = function () { + if (this.message === undefined) { + return this.name + } else { + return this.name + ': ' + this.message + } + } + return errorClass + } + var BindingError = undefined + function throwBindingError(message) { + throw new BindingError(message) + } + var InternalError = undefined + function throwInternalError(message) { + throw new InternalError(message) + } + function whenDependentTypesAreResolved( + myTypes, + dependentTypes, + getTypeConverters + ) { + myTypes.forEach(function (type) { + typeDependencies[type] = dependentTypes }) - var f = Array(a.length), - g = [], - l = 0 - a.forEach(function (h, k) { - R.hasOwnProperty(h) - ? (f[k] = R[h]) - : (g.push(h), - Q.hasOwnProperty(h) || (Q[h] = []), - Q[h].push(function () { - f[k] = R[h] - ++l - l === g.length && c(f) - })) + function onComplete(typeConverters) { + var myTypeConverters = getTypeConverters(typeConverters) + if (myTypeConverters.length !== myTypes.length) { + throwInternalError('Mismatched type converter count') + } + for (var i = 0; i < myTypes.length; ++i) { + registerType(myTypes[i], myTypeConverters[i]) + } + } + var typeConverters = new Array(dependentTypes.length) + var unregisteredTypes = [] + var registered = 0 + dependentTypes.forEach(function (dt, i) { + if (registeredTypes.hasOwnProperty(dt)) { + typeConverters[i] = registeredTypes[dt] + } else { + unregisteredTypes.push(dt) + if (!awaitingDependencies.hasOwnProperty(dt)) { + awaitingDependencies[dt] = [] + } + awaitingDependencies[dt].push(function () { + typeConverters[i] = registeredTypes[dt] + ++registered + if (registered === unregisteredTypes.length) { + onComplete(typeConverters) + } + }) + } }) - 0 === g.length && c(f) + if (0 === unregisteredTypes.length) { + onComplete(typeConverters) + } } - function U(a, b, c) { - c = c || {} - if (!('argPackAdvance' in b)) + function registerType(rawType, registeredInstance, options) { + options = options || {} + if (!('argPackAdvance' in registeredInstance)) { throw new TypeError( 'registerType registeredInstance requires argPackAdvance' ) - var d = b.name - a || T('type "' + d + '" must have a positive integer typeid pointer') - if (R.hasOwnProperty(a)) { - if (c.M) return - T("Cannot register type '" + d + "' twice") - } - R[a] = b - delete S[a] - Q.hasOwnProperty(a) && - ((b = Q[a]), - delete Q[a], - b.forEach(function (f) { - f() - })) - } - var Qa = [], - V = [{}, { value: void 0 }, { value: null }, { value: !0 }, { value: !1 }] - function Ra(a) { - 4 < a && 0 === --V[a].J && ((V[a] = void 0), Qa.push(a)) - } - function W(a) { - switch (a) { - case void 0: + } + var name = registeredInstance.name + if (!rawType) { + throwBindingError( + 'type "' + name + '" must have a positive integer typeid pointer' + ) + } + if (registeredTypes.hasOwnProperty(rawType)) { + if (options.ignoreDuplicateRegistrations) { + return + } else { + throwBindingError("Cannot register type '" + name + "' twice") + } + } + registeredTypes[rawType] = registeredInstance + delete typeDependencies[rawType] + if (awaitingDependencies.hasOwnProperty(rawType)) { + var callbacks = awaitingDependencies[rawType] + delete awaitingDependencies[rawType] + callbacks.forEach(function (cb) { + cb() + }) + } + } + function __embind_register_bool( + rawType, + name, + size, + trueValue, + falseValue + ) { + var shift = getShiftFromSize(size) + name = readLatin1String(name) + registerType(rawType, { + name: name, + fromWireType: function (wt) { + return !!wt + }, + toWireType: function (destructors, o) { + return o ? trueValue : falseValue + }, + argPackAdvance: 8, + readValueFromPointer: function (pointer) { + var heap + if (size === 1) { + heap = HEAP8 + } else if (size === 2) { + heap = HEAP16 + } else if (size === 4) { + heap = HEAP32 + } else { + throw new TypeError('Unknown boolean type size: ' + name) + } + return this['fromWireType'](heap[pointer >> shift]) + }, + destructorFunction: null, + }) + } + var emval_free_list = [] + var emval_handle_array = [ + {}, + { value: undefined }, + { value: null }, + { value: true }, + { value: false }, + ] + function __emval_decref(handle) { + if (handle > 4 && 0 === --emval_handle_array[handle].refcount) { + emval_handle_array[handle] = undefined + emval_free_list.push(handle) + } + } + function count_emval_handles() { + var count = 0 + for (var i = 5; i < emval_handle_array.length; ++i) { + if (emval_handle_array[i] !== undefined) { + ++count + } + } + return count + } + function get_first_emval() { + for (var i = 5; i < emval_handle_array.length; ++i) { + if (emval_handle_array[i] !== undefined) { + return emval_handle_array[i] + } + } + return null + } + function init_emval() { + Module['count_emval_handles'] = count_emval_handles + Module['get_first_emval'] = get_first_emval + } + function __emval_register(value) { + switch (value) { + case undefined: { return 1 - case null: + } + case null: { return 2 - case !0: + } + case true: { return 3 - case !1: + } + case false: { return 4 - default: - var b = Qa.length ? Qa.pop() : V.length - V[b] = { J: 1, value: a } - return b + } + default: { + var handle = emval_free_list.length + ? emval_free_list.pop() + : emval_handle_array.length + emval_handle_array[handle] = { refcount: 1, value: value } + return handle + } } } - function Sa(a) { - return this.fromWireType(I[a >> 2]) + function simpleReadValueFromPointer(pointer) { + return this['fromWireType'](HEAPU32[pointer >> 2]) } - function Va(a) { - if (null === a) return 'null' - var b = typeof a - return 'object' === b || 'array' === b || 'function' === b - ? a.toString() - : '' + a + function __embind_register_emval(rawType, name) { + name = readLatin1String(name) + registerType(rawType, { + name: name, + fromWireType: function (handle) { + var rv = emval_handle_array[handle].value + __emval_decref(handle) + return rv + }, + toWireType: function (destructors, value) { + return __emval_register(value) + }, + argPackAdvance: 8, + readValueFromPointer: simpleReadValueFromPointer, + destructorFunction: null, + }) + } + function _embind_repr(v) { + if (v === null) { + return 'null' + } + var t = typeof v + if (t === 'object' || t === 'array' || t === 'function') { + return v.toString() + } else { + return '' + v + } } - function Wa(a, b) { - switch (b) { + function floatReadValueFromPointer(name, shift) { + switch (shift) { case 2: - return function (c) { - return this.fromWireType(va[c >> 2]) + return function (pointer) { + return this['fromWireType'](HEAPF32[pointer >> 2]) } case 3: - return function (c) { - return this.fromWireType(wa[c >> 3]) + return function (pointer) { + return this['fromWireType'](HEAPF64[pointer >> 3]) } default: - throw new TypeError('Unknown float type: ' + a) + throw new TypeError('Unknown float type: ' + name) } } - function Xa(a) { - var b = Function - if (!(b instanceof Function)) + function __embind_register_float(rawType, name, size) { + var shift = getShiftFromSize(size) + name = readLatin1String(name) + registerType(rawType, { + name: name, + fromWireType: function (value) { + return value + }, + toWireType: function (destructors, value) { + if (typeof value !== 'number' && typeof value !== 'boolean') { + throw new TypeError( + 'Cannot convert "' + _embind_repr(value) + '" to ' + this.name + ) + } + return value + }, + argPackAdvance: 8, + readValueFromPointer: floatReadValueFromPointer(name, shift), + destructorFunction: null, + }) + } + function new_(constructor, argumentList) { + if (!(constructor instanceof Function)) { throw new TypeError( 'new_ called with constructor type ' + - typeof b + + typeof constructor + ' which is not a function' ) - var c = La(b.name || 'unknownFunctionName', function () {}) - c.prototype = b.prototype - c = new c() - a = b.apply(c, a) - return a instanceof Object ? a : c - } - function Ya(a) { - for (; a.length; ) { - var b = a.pop() - a.pop()(b) - } - } - function Za(a, b) { - var c = e - if (void 0 === c[a].G) { - var d = c[a] - c[a] = function () { - c[a].G.hasOwnProperty(arguments.length) || - T( + } + var dummy = createNamedFunction( + constructor.name || 'unknownFunctionName', + function () {} + ) + dummy.prototype = constructor.prototype + var obj = new dummy() + var r = constructor.apply(obj, argumentList) + return r instanceof Object ? r : obj + } + function runDestructors(destructors) { + while (destructors.length) { + var ptr = destructors.pop() + var del = destructors.pop() + del(ptr) + } + } + function craftInvokerFunction( + humanName, + argTypes, + classType, + cppInvokerFunc, + cppTargetFunc + ) { + var argCount = argTypes.length + if (argCount < 2) { + throwBindingError( + "argTypes array size mismatch! Must at least get return value and 'this' types!" + ) + } + var isClassMethodFunc = argTypes[1] !== null && classType !== null + var needsDestructorStack = false + for (var i = 1; i < argTypes.length; ++i) { + if ( + argTypes[i] !== null && + argTypes[i].destructorFunction === undefined + ) { + needsDestructorStack = true + break + } + } + var returns = argTypes[0].name !== 'void' + var argsList = '' + var argsListWired = '' + for (var i = 0; i < argCount - 2; ++i) { + argsList += (i !== 0 ? ', ' : '') + 'arg' + i + argsListWired += (i !== 0 ? ', ' : '') + 'arg' + i + 'Wired' + } + var invokerFnBody = + 'return function ' + + makeLegalFunctionName(humanName) + + '(' + + argsList + + ') {\n' + + 'if (arguments.length !== ' + + (argCount - 2) + + ') {\n' + + "throwBindingError('function " + + humanName + + " called with ' + arguments.length + ' arguments, expected " + + (argCount - 2) + + " args!');\n" + + '}\n' + if (needsDestructorStack) { + invokerFnBody += 'var destructors = [];\n' + } + var dtorStack = needsDestructorStack ? 'destructors' : 'null' + var args1 = [ + 'throwBindingError', + 'invoker', + 'fn', + 'runDestructors', + 'retType', + 'classParam', + ] + var args2 = [ + throwBindingError, + cppInvokerFunc, + cppTargetFunc, + runDestructors, + argTypes[0], + argTypes[1], + ] + if (isClassMethodFunc) { + invokerFnBody += + 'var thisWired = classParam.toWireType(' + dtorStack + ', this);\n' + } + for (var i = 0; i < argCount - 2; ++i) { + invokerFnBody += + 'var arg' + + i + + 'Wired = argType' + + i + + '.toWireType(' + + dtorStack + + ', arg' + + i + + '); // ' + + argTypes[i + 2].name + + '\n' + args1.push('argType' + i) + args2.push(argTypes[i + 2]) + } + if (isClassMethodFunc) { + argsListWired = + 'thisWired' + (argsListWired.length > 0 ? ', ' : '') + argsListWired + } + invokerFnBody += + (returns ? 'var rv = ' : '') + + 'invoker(fn' + + (argsListWired.length > 0 ? ', ' : '') + + argsListWired + + ');\n' + if (needsDestructorStack) { + invokerFnBody += 'runDestructors(destructors);\n' + } else { + for (var i = isClassMethodFunc ? 1 : 2; i < argTypes.length; ++i) { + var paramName = i === 1 ? 'thisWired' : 'arg' + (i - 2) + 'Wired' + if (argTypes[i].destructorFunction !== null) { + invokerFnBody += + paramName + + '_dtor(' + + paramName + + '); // ' + + argTypes[i].name + + '\n' + args1.push(paramName + '_dtor') + args2.push(argTypes[i].destructorFunction) + } + } + } + if (returns) { + invokerFnBody += + 'var ret = retType.fromWireType(rv);\n' + 'return ret;\n' + } else { + } + invokerFnBody += '}\n' + args1.push(invokerFnBody) + var invokerFunction = new_(Function, args1).apply(null, args2) + return invokerFunction + } + function ensureOverloadTable(proto, methodName, humanName) { + if (undefined === proto[methodName].overloadTable) { + var prevFunc = proto[methodName] + proto[methodName] = function () { + if ( + !proto[methodName].overloadTable.hasOwnProperty(arguments.length) + ) { + throwBindingError( "Function '" + - b + + humanName + "' called with an invalid number of arguments (" + arguments.length + ') - expects one of (' + - c[a].G + + proto[methodName].overloadTable + ')!' ) - return c[a].G[arguments.length].apply(this, arguments) + } + return proto[methodName].overloadTable[arguments.length].apply( + this, + arguments + ) } - c[a].G = [] - c[a].G[d.K] = d - } - } - function $a(a, b, c) { - e.hasOwnProperty(a) - ? ((void 0 === c || (void 0 !== e[a].G && void 0 !== e[a].G[c])) && - T("Cannot register public name '" + a + "' twice"), - Za(a, a), - e.hasOwnProperty(c) && - T( - 'Cannot register multiple overloads of a function with the same number of arguments (' + - c + - ')!' - ), - (e[a].G[c] = b)) - : ((e[a] = b), void 0 !== c && (e[a].O = c)) - } - function ab(a, b) { - for (var c = [], d = 0; d < a; d++) c.push(E[(b >> 2) + d]) - return c - } - function bb(a, b) { - 0 <= a.indexOf('j') || - v('Assertion failed: getDynCaller should only be called with i64 sigs') - var c = [] + proto[methodName].overloadTable = [] + proto[methodName].overloadTable[prevFunc.argCount] = prevFunc + } + } + function exposePublicSymbol(name, value, numArguments) { + if (Module.hasOwnProperty(name)) { + if ( + undefined === numArguments || + (undefined !== Module[name].overloadTable && + undefined !== Module[name].overloadTable[numArguments]) + ) { + throwBindingError("Cannot register public name '" + name + "' twice") + } + ensureOverloadTable(Module, name, name) + if (Module.hasOwnProperty(numArguments)) { + throwBindingError( + 'Cannot register multiple overloads of a function with the same number of arguments (' + + numArguments + + ')!' + ) + } + Module[name].overloadTable[numArguments] = value + } else { + Module[name] = value + if (undefined !== numArguments) { + Module[name].numArguments = numArguments + } + } + } + function heap32VectorToArray(count, firstElement) { + var array = [] + for (var i = 0; i < count; i++) { + array.push(HEAP32[(firstElement >> 2) + i]) + } + return array + } + function replacePublicSymbol(name, value, numArguments) { + if (!Module.hasOwnProperty(name)) { + throwInternalError('Replacing nonexistant public symbol') + } + if ( + undefined !== Module[name].overloadTable && + undefined !== numArguments + ) { + Module[name].overloadTable[numArguments] = value + } else { + Module[name] = value + Module[name].argCount = numArguments + } + } + function dynCallLegacy(sig, ptr, args) { + var f = Module['dynCall_' + sig] + return args && args.length + ? f.apply(null, [ptr].concat(args)) + : f.call(null, ptr) + } + function dynCall(sig, ptr, args) { + if (sig.includes('j')) { + return dynCallLegacy(sig, ptr, args) + } + return wasmTable.get(ptr).apply(null, args) + } + function getDynCaller(sig, ptr) { + var argCache = [] return function () { - c.length = arguments.length - for (var d = 0; d < arguments.length; d++) c[d] = arguments[d] - var f - ;-1 != a.indexOf('j') - ? (f = - c && c.length - ? e['dynCall_' + a].apply(null, [b].concat(c)) - : e['dynCall_' + a].call(null, b)) - : (f = J.get(b).apply(null, c)) - return f - } - } - function cb(a, b) { - a = P(a) - var c = -1 != a.indexOf('j') ? bb(a, b) : J.get(b) - 'function' !== typeof c && - T('unknown function pointer with signature ' + a + ': ' + b) - return c - } - var db = void 0 - function eb(a) { - a = fb(a) - var b = P(a) - X(a) - return b - } - function gb(a, b) { - function c(g) { - f[g] || R[g] || (S[g] ? S[g].forEach(c) : (d.push(g), (f[g] = !0))) - } - var d = [], - f = {} - b.forEach(c) - throw new db(a + ': ' + d.map(eb).join([', '])) - } - function hb(a, b, c) { - switch (b) { + argCache.length = arguments.length + for (var i = 0; i < arguments.length; i++) { + argCache[i] = arguments[i] + } + return dynCall(sig, ptr, argCache) + } + } + function embind__requireFunction(signature, rawFunction) { + signature = readLatin1String(signature) + function makeDynCaller() { + if (signature.includes('j')) { + return getDynCaller(signature, rawFunction) + } + return wasmTable.get(rawFunction) + } + var fp = makeDynCaller() + if (typeof fp !== 'function') { + throwBindingError( + 'unknown function pointer with signature ' + + signature + + ': ' + + rawFunction + ) + } + return fp + } + var UnboundTypeError = undefined + function getTypeName(type) { + var ptr = ___getTypeName(type) + var rv = readLatin1String(ptr) + _free(ptr) + return rv + } + function throwUnboundTypeError(message, types) { + var unboundTypes = [] + var seen = {} + function visit(type) { + if (seen[type]) { + return + } + if (registeredTypes[type]) { + return + } + if (typeDependencies[type]) { + typeDependencies[type].forEach(visit) + return + } + unboundTypes.push(type) + seen[type] = true + } + types.forEach(visit) + throw new UnboundTypeError( + message + ': ' + unboundTypes.map(getTypeName).join([', ']) + ) + } + function __embind_register_function( + name, + argCount, + rawArgTypesAddr, + signature, + rawInvoker, + fn + ) { + var argTypes = heap32VectorToArray(argCount, rawArgTypesAddr) + name = readLatin1String(name) + rawInvoker = embind__requireFunction(signature, rawInvoker) + exposePublicSymbol( + name, + function () { + throwUnboundTypeError( + 'Cannot call ' + name + ' due to unbound types', + argTypes + ) + }, + argCount - 1 + ) + whenDependentTypesAreResolved([], argTypes, function (argTypes) { + var invokerArgsArray = [argTypes[0], null].concat(argTypes.slice(1)) + replacePublicSymbol( + name, + craftInvokerFunction(name, invokerArgsArray, null, rawInvoker, fn), + argCount - 1 + ) + return [] + }) + } + function integerReadValueFromPointer(name, shift, signed) { + switch (shift) { case 0: - return c - ? function (d) { - return G[d] + return signed + ? function readS8FromPointer(pointer) { + return HEAP8[pointer] } - : function (d) { - return A[d] + : function readU8FromPointer(pointer) { + return HEAPU8[pointer] } case 1: - return c - ? function (d) { - return D[d >> 1] + return signed + ? function readS16FromPointer(pointer) { + return HEAP16[pointer >> 1] } - : function (d) { - return C[d >> 1] + : function readU16FromPointer(pointer) { + return HEAPU16[pointer >> 1] } case 2: - return c - ? function (d) { - return E[d >> 2] + return signed + ? function readS32FromPointer(pointer) { + return HEAP32[pointer >> 2] } - : function (d) { - return I[d >> 2] + : function readU32FromPointer(pointer) { + return HEAPU32[pointer >> 2] } default: - throw new TypeError('Unknown integer type: ' + a) - } - } - var ib = {} - function jb() { - return 'object' === typeof globalThis - ? globalThis - : Function('return this')() - } - function kb(a, b) { - var c = R[a] - void 0 === c && T(b + ' has unknown type ' + eb(a)) - return c - } - var lb = {}, - mb = {} - function nb() { - if (!ob) { - var a = { - USER: 'web_user', - LOGNAME: 'web_user', - PATH: '/', - PWD: '/', - HOME: '/home/web_user', - LANG: - ( - ('object' === typeof navigator && - navigator.languages && - navigator.languages[0]) || - 'C' - ).replace('-', '_') + '.UTF-8', - _: ba || './this.program', - }, - b - for (b in mb) a[b] = mb[b] - var c = [] - for (b in a) c.push(b + '=' + a[b]) - ob = c - } - return ob - } - for (var ob, pb = [null, [], []], qb = Array(256), Y = 0; 256 > Y; ++Y) - qb[Y] = String.fromCharCode(Y) - Ja = qb - Na = e.BindingError = Ma('BindingError') - Oa = e.InternalError = Ma('InternalError') - e.count_emval_handles = function () { - for (var a = 0, b = 5; b < V.length; ++b) void 0 !== V[b] && ++a - return a - } - e.get_first_emval = function () { - for (var a = 5; a < V.length; ++a) if (void 0 !== V[a]) return V[a] - return null + throw new TypeError('Unknown integer type: ' + name) + } } - db = e.UnboundTypeError = Ma('UnboundTypeError') - Aa.push({ - L: function () { - rb() - }, - }) - var tb = { - g: function () {}, - o: function (a, b, c, d, f) { - var g = Ia(c) - b = P(b) - U(a, { - name: b, - fromWireType: function (l) { - return !!l - }, - toWireType: function (l, h) { - return h ? d : f - }, - argPackAdvance: 8, - readValueFromPointer: function (l) { - if (1 === c) var h = G - else if (2 === c) h = D - else if (4 === c) h = E - else throw new TypeError('Unknown boolean type size: ' + b) - return this.fromWireType(h[l >> g]) - }, - H: null, - }) - }, - x: function (a, b) { - b = P(b) - U(a, { - name: b, - fromWireType: function (c) { - var d = V[c].value - Ra(c) - return d - }, - toWireType: function (c, d) { - return W(d) - }, - argPackAdvance: 8, - readValueFromPointer: Sa, - H: null, - }) - }, - n: function (a, b, c) { - c = Ia(c) - b = P(b) - U(a, { - name: b, - fromWireType: function (d) { - return d - }, - toWireType: function (d, f) { - if ('number' !== typeof f && 'boolean' !== typeof f) - throw new TypeError( - 'Cannot convert "' + Va(f) + '" to ' + this.name - ) - return f - }, - argPackAdvance: 8, - readValueFromPointer: Wa(b, c), - H: null, - }) - }, - q: function (a, b, c, d, f, g) { - var l = ab(b, c) - a = P(a) - f = cb(d, f) - $a( - a, - function () { - gb('Cannot call ' + a + ' due to unbound types', l) - }, - b - 1 - ) - Pa(l, function (h) { - var k = [h[0], null].concat(h.slice(1)), - m = (h = a), - n = f, - p = k.length - 2 > p && - T( - "argTypes array size mismatch! Must at least get return value and 'this' types!" + function __embind_register_integer( + primitiveType, + name, + size, + minRange, + maxRange + ) { + name = readLatin1String(name) + if (maxRange === -1) { + maxRange = 4294967295 + } + var shift = getShiftFromSize(size) + var fromWireType = function (value) { + return value + } + if (minRange === 0) { + var bitshift = 32 - 8 * size + fromWireType = function (value) { + return (value << bitshift) >>> bitshift + } + } + var isUnsignedType = name.includes('unsigned') + registerType(primitiveType, { + name: name, + fromWireType: fromWireType, + toWireType: function (destructors, value) { + if (typeof value !== 'number' && typeof value !== 'boolean') { + throw new TypeError( + 'Cannot convert "' + _embind_repr(value) + '" to ' + this.name ) - for (var x = null !== k[1] && !1, B = !1, q = 1; q < k.length; ++q) - if (null !== k[q] && void 0 === k[q].H) { - B = !0 - break - } - var Ta = 'void' !== k[0].name, - H = '', - L = '' - for (q = 0; q < p - 2; ++q) - (H += (0 !== q ? ', ' : '') + 'arg' + q), - (L += (0 !== q ? ', ' : '') + 'arg' + q + 'Wired') - m = - 'return function ' + - Ka(m) + - '(' + - H + - ') {\nif (arguments.length !== ' + - (p - 2) + - ") {\nthrowBindingError('function " + - m + - " called with ' + arguments.length + ' arguments, expected " + - (p - 2) + - " args!');\n}\n" - B && (m += 'var destructors = [];\n') - var Ua = B ? 'destructors' : 'null' - H = - 'throwBindingError invoker fn runDestructors retType classParam'.split( - ' ' + } + if (value < minRange || value > maxRange) { + throw new TypeError( + 'Passing a number "' + + _embind_repr(value) + + '" from JS side to C/C++ side to an argument of type "' + + name + + '", which is outside the valid range [' + + minRange + + ', ' + + maxRange + + ']!' ) - n = [T, n, g, Ya, k[0], k[1]] - x && - (m += 'var thisWired = classParam.toWireType(' + Ua + ', this);\n') - for (q = 0; q < p - 2; ++q) - (m += - 'var arg' + - q + - 'Wired = argType' + - q + - '.toWireType(' + - Ua + - ', arg' + - q + - '); // ' + - k[q + 2].name + - '\n'), - H.push('argType' + q), - n.push(k[q + 2]) - x && (L = 'thisWired' + (0 < L.length ? ', ' : '') + L) - m += - (Ta ? 'var rv = ' : '') + - 'invoker(fn' + - (0 < L.length ? ', ' : '') + - L + - ');\n' - if (B) m += 'runDestructors(destructors);\n' - else - for (q = x ? 1 : 2; q < k.length; ++q) - (p = 1 === q ? 'thisWired' : 'arg' + (q - 2) + 'Wired'), - null !== k[q].H && - ((m += p + '_dtor(' + p + '); // ' + k[q].name + '\n'), - H.push(p + '_dtor'), - n.push(k[q].H)) - Ta && (m += 'var ret = retType.fromWireType(rv);\nreturn ret;\n') - H.push(m + '}\n') - k = Xa(H).apply(null, n) - q = b - 1 - if (!e.hasOwnProperty(h)) - throw new Oa('Replacing nonexistant public symbol') - void 0 !== e[h].G && void 0 !== q - ? (e[h].G[q] = k) - : ((e[h] = k), (e[h].K = q)) - return [] - }) - }, - c: function (a, b, c, d, f) { - function g(m) { - return m - } - b = P(b) - ;-1 === f && (f = 4294967295) - var l = Ia(c) - if (0 === d) { - var h = 32 - 8 * c - g = function (m) { - return (m << h) >>> h } - } - var k = -1 != b.indexOf('unsigned') - U(a, { - name: b, - fromWireType: g, - toWireType: function (m, n) { - if ('number' !== typeof n && 'boolean' !== typeof n) - throw new TypeError( - 'Cannot convert "' + Va(n) + '" to ' + this.name - ) - if (n < d || n > f) - throw new TypeError( - 'Passing a number "' + - Va(n) + - '" from JS side to C/C++ side to an argument of type "' + - b + - '", which is outside the valid range [' + - d + - ', ' + - f + - ']!' - ) - return k ? n >>> 0 : n | 0 - }, + return isUnsignedType ? value >>> 0 : value | 0 + }, + argPackAdvance: 8, + readValueFromPointer: integerReadValueFromPointer( + name, + shift, + minRange !== 0 + ), + destructorFunction: null, + }) + } + function __embind_register_memory_view(rawType, dataTypeIndex, name) { + var typeMapping = [ + Int8Array, + Uint8Array, + Int16Array, + Uint16Array, + Int32Array, + Uint32Array, + Float32Array, + Float64Array, + ] + var TA = typeMapping[dataTypeIndex] + function decodeMemoryView(handle) { + handle = handle >> 2 + var heap = HEAPU32 + var size = heap[handle] + var data = heap[handle + 1] + return new TA(buffer, data, size) + } + name = readLatin1String(name) + registerType( + rawType, + { + name: name, + fromWireType: decodeMemoryView, argPackAdvance: 8, - readValueFromPointer: hb(b, l, 0 !== d), - H: null, - }) - }, - b: function (a, b, c) { - function d(g) { - g >>= 2 - var l = I - return new f(F, l[g + 1], l[g]) - } - var f = [ - Int8Array, - Uint8Array, - Int16Array, - Uint16Array, - Int32Array, - Uint32Array, - Float32Array, - Float64Array, - ][b] - c = P(c) - U( - a, - { - name: c, - fromWireType: d, - argPackAdvance: 8, - readValueFromPointer: d, - }, - { M: !0 } - ) - }, - i: function (a, b) { - b = P(b) - var c = 'std::string' === b - U(a, { - name: b, - fromWireType: function (d) { - var f = I[d >> 2] - if (c) - for (var g = d + 4, l = 0; l <= f; ++l) { - var h = d + 4 + l - if (l == f || 0 == A[h]) { - if (g) { - for (var k = g + (h - g), m = g; !(m >= k) && A[m]; ) ++m - g = ma.decode(A.subarray(g, m)) - } else g = '' - if (void 0 === n) var n = g - else (n += String.fromCharCode(0)), (n += g) - g = h + 1 + readValueFromPointer: decodeMemoryView, + }, + { ignoreDuplicateRegistrations: true } + ) + } + function __embind_register_std_string(rawType, name) { + name = readLatin1String(name) + var stdStringIsUTF8 = name === 'std::string' + registerType(rawType, { + name: name, + fromWireType: function (value) { + var length = HEAPU32[value >> 2] + var str + if (stdStringIsUTF8) { + var decodeStartPtr = value + 4 + for (var i = 0; i <= length; ++i) { + var currentBytePtr = value + 4 + i + if (i == length || HEAPU8[currentBytePtr] == 0) { + var maxRead = currentBytePtr - decodeStartPtr + var stringSegment = UTF8ToString(decodeStartPtr, maxRead) + if (str === undefined) { + str = stringSegment + } else { + str += String.fromCharCode(0) + str += stringSegment } + decodeStartPtr = currentBytePtr + 1 } - else { - n = Array(f) - for (l = 0; l < f; ++l) n[l] = String.fromCharCode(A[d + 4 + l]) - n = n.join('') } - X(d) - return n - }, - toWireType: function (d, f) { - f instanceof ArrayBuffer && (f = new Uint8Array(f)) - var g = 'string' === typeof f - g || - f instanceof Uint8Array || - f instanceof Uint8ClampedArray || - f instanceof Int8Array || - T('Cannot pass non-string to std::string') - var l = ( - c && g - ? function () { - for (var m = 0, n = 0; n < f.length; ++n) { - var p = f.charCodeAt(n) - 55296 <= p && - 57343 >= p && - (p = - (65536 + ((p & 1023) << 10)) | - (f.charCodeAt(++n) & 1023)) - 127 >= p - ? ++m - : (m = 2047 >= p ? m + 2 : 65535 >= p ? m + 3 : m + 4) - } - return m - } - : function () { - return f.length - } - )(), - h = sb(4 + l + 1) - I[h >> 2] = l - if (c && g) na(f, h + 4, l + 1) - else if (g) - for (g = 0; g < l; ++g) { - var k = f.charCodeAt(g) - 255 < k && - (X(h), - T('String has UTF-16 code units that do not fit in 8 bits')) - A[h + 4 + g] = k - } - else for (g = 0; g < l; ++g) A[h + 4 + g] = f[g] - null !== d && d.push(X, h) - return h - }, - argPackAdvance: 8, - readValueFromPointer: Sa, - H: function (d) { - X(d) - }, - }) - }, - h: function (a, b, c) { - c = P(c) - if (2 === b) { - var d = pa - var f = qa - var g = ra - var l = function () { - return C + } else { + var a = new Array(length) + for (var i = 0; i < length; ++i) { + a[i] = String.fromCharCode(HEAPU8[value + 4 + i]) + } + str = a.join('') + } + _free(value) + return str + }, + toWireType: function (destructors, value) { + if (value instanceof ArrayBuffer) { + value = new Uint8Array(value) } - var h = 1 - } else - 4 === b && - ((d = sa), - (f = ta), - (g = ua), - (l = function () { - return I - }), - (h = 2)) - U(a, { - name: c, - fromWireType: function (k) { - for (var m = I[k >> 2], n = l(), p, x = k + 4, B = 0; B <= m; ++B) { - var q = k + 4 + B * b - if (B == m || 0 == n[q >> h]) - (x = d(x, q - x)), - void 0 === p - ? (p = x) - : ((p += String.fromCharCode(0)), (p += x)), - (x = q + b) + var getLength + var valueIsOfTypeString = typeof value === 'string' + if ( + !( + valueIsOfTypeString || + value instanceof Uint8Array || + value instanceof Uint8ClampedArray || + value instanceof Int8Array + ) + ) { + throwBindingError('Cannot pass non-string to std::string') + } + if (stdStringIsUTF8 && valueIsOfTypeString) { + getLength = function () { + return lengthBytesUTF8(value) } - X(k) - return p - }, - toWireType: function (k, m) { - 'string' !== typeof m && - T('Cannot pass non-string to C++ string type ' + c) - var n = g(m), - p = sb(4 + n + b) - I[p >> 2] = n >> h - f(m, p + 4, n + b) - null !== k && k.push(X, p) - return p - }, - argPackAdvance: 8, - readValueFromPointer: Sa, - H: function (k) { - X(k) - }, - }) - }, - p: function (a, b) { - b = P(b) - U(a, { - N: !0, - name: b, - argPackAdvance: 0, - fromWireType: function () {}, - toWireType: function () {}, - }) - }, - e: Ra, - f: function (a) { - if (0 === a) return W(jb()) - var b = ib[a] - a = void 0 === b ? P(a) : b - return W(jb()[a]) - }, - j: function (a) { - 4 < a && (V[a].J += 1) - }, - k: function (a, b, c, d) { - a || T('Cannot use deleted val. handle = ' + a) - a = V[a].value - var f = lb[b] - if (!f) { - f = '' - for (var g = 0; g < b; ++g) f += (0 !== g ? ', ' : '') + 'arg' + g - var l = - 'return function emval_allocator_' + - b + - '(constructor, argTypes, args) {\n' - for (g = 0; g < b; ++g) - l += - 'var argType' + - g + - " = requireRegisteredType(Module['HEAP32'][(argTypes >>> 2) + " + - g + - '], "parameter ' + - g + - '");\nvar arg' + - g + - ' = argType' + - g + - '.readValueFromPointer(args);\nargs += argType' + - g + - "['argPackAdvance'];\n" - f = new Function( - 'requireRegisteredType', - 'Module', - '__emval_register', - l + - ('var obj = new constructor(' + - f + - ');\nreturn __emval_register(obj);\n}\n') - )(kb, e, W) - lb[b] = f + } else { + getLength = function () { + return value.length + } + } + var length = getLength() + var ptr = _malloc(4 + length + 1) + HEAPU32[ptr >> 2] = length + if (stdStringIsUTF8 && valueIsOfTypeString) { + stringToUTF8(value, ptr + 4, length + 1) + } else { + if (valueIsOfTypeString) { + for (var i = 0; i < length; ++i) { + var charCode = value.charCodeAt(i) + if (charCode > 255) { + _free(ptr) + throwBindingError( + 'String has UTF-16 code units that do not fit in 8 bits' + ) + } + HEAPU8[ptr + 4 + i] = charCode + } + } else { + for (var i = 0; i < length; ++i) { + HEAPU8[ptr + 4 + i] = value[i] + } + } + } + if (destructors !== null) { + destructors.push(_free, ptr) + } + return ptr + }, + argPackAdvance: 8, + readValueFromPointer: simpleReadValueFromPointer, + destructorFunction: function (ptr) { + _free(ptr) + }, + }) + } + function __embind_register_std_wstring(rawType, charSize, name) { + name = readLatin1String(name) + var decodeString, encodeString, getHeap, lengthBytesUTF, shift + if (charSize === 2) { + decodeString = UTF16ToString + encodeString = stringToUTF16 + lengthBytesUTF = lengthBytesUTF16 + getHeap = function () { + return HEAPU16 } - return f(a, c, d) - }, - l: function () { - v() - }, - t: function (a, b, c) { - A.copyWithin(a, b, b + c) - }, - d: function (a) { - a >>>= 0 - var b = A.length - if (2147483648 < a) return !1 - for (var c = 1; 4 >= c; c *= 2) { - var d = b * (1 + 0.2 / c) - d = Math.min(d, a + 100663296) - d = Math.max(16777216, a, d) - 0 < d % 65536 && (d += 65536 - (d % 65536)) - a: { - try { - z.grow((Math.min(2147483648, d) - F.byteLength + 65535) >>> 16) - xa(z.buffer) - var f = 1 - break a - } catch (g) {} - f = void 0 + shift = 1 + } else if (charSize === 4) { + decodeString = UTF32ToString + encodeString = stringToUTF32 + lengthBytesUTF = lengthBytesUTF32 + getHeap = function () { + return HEAPU32 + } + shift = 2 + } + registerType(rawType, { + name: name, + fromWireType: function (value) { + var length = HEAPU32[value >> 2] + var HEAP = getHeap() + var str + var decodeStartPtr = value + 4 + for (var i = 0; i <= length; ++i) { + var currentBytePtr = value + 4 + i * charSize + if (i == length || HEAP[currentBytePtr >> shift] == 0) { + var maxReadBytes = currentBytePtr - decodeStartPtr + var stringSegment = decodeString(decodeStartPtr, maxReadBytes) + if (str === undefined) { + str = stringSegment + } else { + str += String.fromCharCode(0) + str += stringSegment + } + decodeStartPtr = currentBytePtr + charSize + } + } + _free(value) + return str + }, + toWireType: function (destructors, value) { + if (!(typeof value === 'string')) { + throwBindingError( + 'Cannot pass non-string to C++ string type ' + name + ) + } + var length = lengthBytesUTF(value) + var ptr = _malloc(4 + length + charSize) + HEAPU32[ptr >> 2] = length >> shift + encodeString(value, ptr + 4, length + charSize) + if (destructors !== null) { + destructors.push(_free, ptr) } - if (f) return !0 + return ptr + }, + argPackAdvance: 8, + readValueFromPointer: simpleReadValueFromPointer, + destructorFunction: function (ptr) { + _free(ptr) + }, + }) + } + function __embind_register_void(rawType, name) { + name = readLatin1String(name) + registerType(rawType, { + isVoid: true, + name: name, + argPackAdvance: 0, + fromWireType: function () { + return undefined + }, + toWireType: function (destructors, o) { + return undefined + }, + }) + } + var emval_symbols = {} + function getStringOrSymbol(address) { + var symbol = emval_symbols[address] + if (symbol === undefined) { + return readLatin1String(address) + } else { + return symbol + } + } + function emval_get_global() { + if (typeof globalThis === 'object') { + return globalThis + } + return (function () { + return Function + })()('return this')() + } + function __emval_get_global(name) { + if (name === 0) { + return __emval_register(emval_get_global()) + } else { + name = getStringOrSymbol(name) + return __emval_register(emval_get_global()[name]) + } + } + function __emval_incref(handle) { + if (handle > 4) { + emval_handle_array[handle].refcount += 1 + } + } + function requireRegisteredType(rawType, humanName) { + var impl = registeredTypes[rawType] + if (undefined === impl) { + throwBindingError( + humanName + ' has unknown type ' + getTypeName(rawType) + ) + } + return impl + } + function craftEmvalAllocator(argCount) { + var argsList = '' + for (var i = 0; i < argCount; ++i) { + argsList += (i !== 0 ? ', ' : '') + 'arg' + i + } + var functionBody = + 'return function emval_allocator_' + + argCount + + '(constructor, argTypes, args) {\n' + for (var i = 0; i < argCount; ++i) { + functionBody += + 'var argType' + + i + + " = requireRegisteredType(Module['HEAP32'][(argTypes >>> 2) + " + + i + + '], "parameter ' + + i + + '");\n' + + 'var arg' + + i + + ' = argType' + + i + + '.readValueFromPointer(args);\n' + + 'args += argType' + + i + + "['argPackAdvance'];\n" + } + functionBody += + 'var obj = new constructor(' + + argsList + + ');\n' + + 'return __emval_register(obj);\n' + + '}\n' + return new Function( + 'requireRegisteredType', + 'Module', + '__emval_register', + functionBody + )(requireRegisteredType, Module, __emval_register) + } + var emval_newers = {} + function requireHandle(handle) { + if (!handle) { + throwBindingError('Cannot use deleted val. handle = ' + handle) + } + return emval_handle_array[handle].value + } + function __emval_new(handle, argCount, argTypes, args) { + handle = requireHandle(handle) + var newer = emval_newers[argCount] + if (!newer) { + newer = craftEmvalAllocator(argCount) + emval_newers[argCount] = newer + } + return newer(handle, argTypes, args) + } + function _abort() { + abort() + } + function _emscripten_memcpy_big(dest, src, num) { + HEAPU8.copyWithin(dest, src, src + num) + } + function emscripten_realloc_buffer(size) { + try { + wasmMemory.grow((size - buffer.byteLength + 65535) >>> 16) + updateGlobalBufferAndViews(wasmMemory.buffer) + return 1 + } catch (e) {} + } + function _emscripten_resize_heap(requestedSize) { + var oldSize = HEAPU8.length + requestedSize = requestedSize >>> 0 + var maxHeapSize = 2147483648 + if (requestedSize > maxHeapSize) { + return false + } + for (var cutDown = 1; cutDown <= 4; cutDown *= 2) { + var overGrownHeapSize = oldSize * (1 + 0.2 / cutDown) + overGrownHeapSize = Math.min( + overGrownHeapSize, + requestedSize + 100663296 + ) + var newSize = Math.min( + maxHeapSize, + alignUp(Math.max(requestedSize, overGrownHeapSize), 65536) + ) + var replacement = emscripten_realloc_buffer(newSize) + if (replacement) { + return true + } + } + return false + } + var ENV = {} + function getExecutableName() { + return thisProgram || './this.program' + } + function getEnvStrings() { + if (!getEnvStrings.strings) { + var lang = + ( + (typeof navigator === 'object' && + navigator.languages && + navigator.languages[0]) || + 'C' + ).replace('-', '_') + '.UTF-8' + var env = { + USER: 'web_user', + LOGNAME: 'web_user', + PATH: '/', + PWD: '/', + HOME: '/home/web_user', + LANG: lang, + _: getExecutableName(), + } + for (var x in ENV) { + env[x] = ENV[x] + } + var strings = [] + for (var x in env) { + strings.push(x + '=' + env[x]) + } + getEnvStrings.strings = strings + } + return getEnvStrings.strings + } + var SYSCALLS = { + mappings: {}, + buffers: [null, [], []], + printChar: function (stream, curr) { + var buffer = SYSCALLS.buffers[stream] + if (curr === 0 || curr === 10) { + ;(stream === 1 ? out : err)(UTF8ArrayToString(buffer, 0)) + buffer.length = 0 + } else { + buffer.push(curr) } - return !1 - }, - u: function (a, b) { - var c = 0 - nb().forEach(function (d, f) { - var g = b + c - f = E[(a + 4 * f) >> 2] = g - for (g = 0; g < d.length; ++g) G[f++ >> 0] = d.charCodeAt(g) - G[f >> 0] = 0 - c += d.length + 1 - }) - return 0 }, - v: function (a, b) { - var c = nb() - E[a >> 2] = c.length - var d = 0 - c.forEach(function (f) { - d += f.length + 1 - }) - E[b >> 2] = d - return 0 + varargs: undefined, + get: function () { + SYSCALLS.varargs += 4 + var ret = HEAP32[(SYSCALLS.varargs - 4) >> 2] + return ret }, - y: function (a) { - if (!noExitRuntime) { - if (e.onExit) e.onExit(a) - la = !0 - } - ca(a, new ja(a)) + getStr: function (ptr) { + var ret = UTF8ToString(ptr) + return ret }, - w: function () { - return 0 + get64: function (low, high) { + return low }, - r: function () {}, - m: function (a, b, c, d) { - for (var f = 0, g = 0; g < c; g++) { - for ( - var l = E[(b + 8 * g) >> 2], h = E[(b + (8 * g + 4)) >> 2], k = 0; - k < h; - k++ - ) { - var m = A[l + k], - n = pb[a] - if (0 === m || 10 === m) { - m = 1 === a ? ka : w - var p - for (p = 0; n[p] && !(NaN <= p); ) ++p - p = ma.decode( - n.subarray ? n.subarray(0, p) : new Uint8Array(n.slice(0, p)) - ) - m(p) - n.length = 0 - } else n.push(m) - } - f += h + } + function _environ_get(__environ, environ_buf) { + var bufSize = 0 + getEnvStrings().forEach(function (string, i) { + var ptr = environ_buf + bufSize + HEAP32[(__environ + i * 4) >> 2] = ptr + writeAsciiToMemory(string, ptr) + bufSize += string.length + 1 + }) + return 0 + } + function _environ_sizes_get(penviron_count, penviron_buf_size) { + var strings = getEnvStrings() + HEAP32[penviron_count >> 2] = strings.length + var bufSize = 0 + strings.forEach(function (string) { + bufSize += string.length + 1 + }) + HEAP32[penviron_buf_size >> 2] = bufSize + return 0 + } + function _exit(status) { + exit(status) + } + function _fd_close(fd) { + return 0 + } + function _fd_seek(fd, offset_low, offset_high, whence, newOffset) {} + function _fd_write(fd, iov, iovcnt, pnum) { + var num = 0 + for (var i = 0; i < iovcnt; i++) { + var ptr = HEAP32[(iov + i * 8) >> 2] + var len = HEAP32[(iov + (i * 8 + 4)) >> 2] + for (var j = 0; j < len; j++) { + SYSCALLS.printChar(fd, HEAPU8[ptr + j]) } - E[d >> 2] = f - return 0 - }, - a: z, - s: function () {}, - } - ;(function () { - function a(f) { - e.asm = f.exports - J = e.asm.z - K-- - e.monitorRunDependencies && e.monitorRunDependencies(K) - 0 == K && - (null !== Ea && (clearInterval(Ea), (Ea = null)), - M && ((f = M), (M = null), f())) - } - function b(f) { - a(f.instance) - } - function c(f) { - return Promise.resolve() - .then(Ha) - .then(function (g) { - return WebAssembly.instantiate(g, d) - }) - .then(f, function (g) { - w('failed to asynchronously prepare wasm: ' + g) - v(g) - }) + num += len } - var d = { a: tb } - K++ - e.monitorRunDependencies && e.monitorRunDependencies(K) - if (e.instantiateWasm) - try { - return e.instantiateWasm(d, a) - } catch (f) { - return ( - w('Module.instantiateWasm callback failed with error: ' + f), !1 - ) - } - ;(function () { - return y || - 'function' !== typeof WebAssembly.instantiateStreaming || - Fa() || - 'function' !== typeof fetch - ? c(b) - : fetch(N, { credentials: 'same-origin' }).then(function (f) { - return WebAssembly.instantiateStreaming(f, d).then( - b, - function (g) { - w('wasm streaming compile failed: ' + g) - w('falling back to ArrayBuffer instantiation') - return c(b) - } - ) - }) - })().catch(r) - return {} - })() - var rb = (e.___wasm_call_ctors = function () { - return (rb = e.___wasm_call_ctors = e.asm.A).apply(null, arguments) - }), - sb = (e._malloc = function () { - return (sb = e._malloc = e.asm.B).apply(null, arguments) - }), - X = (e._free = function () { - return (X = e._free = e.asm.C).apply(null, arguments) - }), - fb = (e.___getTypeName = function () { - return (fb = e.___getTypeName = e.asm.D).apply(null, arguments) - }) - e.___embind_register_native_and_builtin_types = function () { - return (e.___embind_register_native_and_builtin_types = e.asm.E).apply( + HEAP32[pnum >> 2] = num + return 0 + } + function _setTempRet0(val) { + setTempRet0(val) + } + embind_init_charCodes() + BindingError = Module['BindingError'] = extendError(Error, 'BindingError') + InternalError = Module['InternalError'] = extendError( + Error, + 'InternalError' + ) + init_emval() + UnboundTypeError = Module['UnboundTypeError'] = extendError( + Error, + 'UnboundTypeError' + ) + var asmLibraryArg = { + e: ___cxa_thread_atexit, + q: __embind_register_bigint, + m: __embind_register_bool, + x: __embind_register_emval, + l: __embind_register_float, + o: __embind_register_function, + b: __embind_register_integer, + a: __embind_register_memory_view, + h: __embind_register_std_string, + g: __embind_register_std_wstring, + n: __embind_register_void, + c: __emval_decref, + d: __emval_get_global, + i: __emval_incref, + j: __emval_new, + k: _abort, + s: _emscripten_memcpy_big, + f: _emscripten_resize_heap, + t: _environ_get, + u: _environ_sizes_get, + y: _exit, + w: _fd_close, + p: _fd_seek, + v: _fd_write, + r: _setTempRet0, + } + var asm = createWasm() + var ___wasm_call_ctors = (Module['___wasm_call_ctors'] = function () { + return (___wasm_call_ctors = Module['___wasm_call_ctors'] = + Module['asm']['A']).apply(null, arguments) + }) + var _malloc = (Module['_malloc'] = function () { + return (_malloc = Module['_malloc'] = Module['asm']['B']).apply( + null, + arguments + ) + }) + var _free = (Module['_free'] = function () { + return (_free = Module['_free'] = Module['asm']['C']).apply( null, arguments ) + }) + var ___getTypeName = (Module['___getTypeName'] = function () { + return (___getTypeName = Module['___getTypeName'] = + Module['asm']['D']).apply(null, arguments) + }) + var ___embind_register_native_and_builtin_types = (Module[ + '___embind_register_native_and_builtin_types' + ] = function () { + return (___embind_register_native_and_builtin_types = Module[ + '___embind_register_native_and_builtin_types' + ] = + Module['asm']['E']).apply(null, arguments) + }) + var dynCall_jiji = (Module['dynCall_jiji'] = function () { + return (dynCall_jiji = Module['dynCall_jiji'] = Module['asm']['G']).apply( + null, + arguments + ) + }) + var calledRun + function ExitStatus(status) { + this.name = 'ExitStatus' + this.message = 'Program terminated with exit(' + status + ')' + this.status = status } - e.dynCall_jiji = function () { - return (e.dynCall_jiji = e.asm.F).apply(null, arguments) + dependenciesFulfilled = function runCaller() { + if (!calledRun) run() + if (!calledRun) dependenciesFulfilled = runCaller } - var Z - function ja(a) { - this.name = 'ExitStatus' - this.message = 'Program terminated with exit(' + a + ')' - this.status = a - } - M = function ub() { - Z || vb() - Z || (M = ub) - } - function vb() { - function a() { - if (!Z && ((Z = !0), (e.calledRun = !0), !la)) { - O(Aa) - O(Ba) - aa(e) - if (e.onRuntimeInitialized) e.onRuntimeInitialized() - if (e.postRun) - for ( - 'function' == typeof e.postRun && (e.postRun = [e.postRun]); - e.postRun.length; - - ) { - var b = e.postRun.shift() - Ca.unshift(b) - } - O(Ca) - } + function run(args) { + args = args || arguments_ + if (runDependencies > 0) { + return } - if (!(0 < K)) { - if (e.preRun) - for ( - 'function' == typeof e.preRun && (e.preRun = [e.preRun]); - e.preRun.length; - - ) - Da() - O(za) - 0 < K || - (e.setStatus - ? (e.setStatus('Running...'), - setTimeout(function () { - setTimeout(function () { - e.setStatus('') - }, 1) - a() - }, 1)) - : a()) - } - } - e.run = vb - if (e.preInit) - for ( - 'function' == typeof e.preInit && (e.preInit = [e.preInit]); - 0 < e.preInit.length; - - ) - e.preInit.pop()() - noExitRuntime = !0 - vb() + preRun() + if (runDependencies > 0) { + return + } + function doRun() { + if (calledRun) return + calledRun = true + Module['calledRun'] = true + if (ABORT) return + initRuntime() + readyPromiseResolve(Module) + if (Module['onRuntimeInitialized']) Module['onRuntimeInitialized']() + postRun() + } + if (Module['setStatus']) { + Module['setStatus']('Running...') + setTimeout(function () { + setTimeout(function () { + Module['setStatus']('') + }, 1) + doRun() + }, 1) + } else { + doRun() + } + } + Module['run'] = run + function exit(status, implicit) { + EXITSTATUS = status + if (implicit && keepRuntimeAlive() && status === 0) { + return + } + if (keepRuntimeAlive()) { + } else { + exitRuntime() + if (Module['onExit']) Module['onExit'](status) + ABORT = true + } + quit_(status, new ExitStatus(status)) + } + if (Module['preInit']) { + if (typeof Module['preInit'] == 'function') + Module['preInit'] = [Module['preInit']] + while (Module['preInit'].length > 0) { + Module['preInit'].pop()() + } + } + run() return Module.ready } diff --git a/packages/next/server/lib/squoosh/mozjpeg/mozjpeg_node_dec.wasm b/packages/next/server/lib/squoosh/mozjpeg/mozjpeg_node_dec.wasm old mode 100644 new mode 100755 index 0f08ea8deea3a..abf13d75f271a Binary files a/packages/next/server/lib/squoosh/mozjpeg/mozjpeg_node_dec.wasm and b/packages/next/server/lib/squoosh/mozjpeg/mozjpeg_node_dec.wasm differ diff --git a/packages/next/server/lib/squoosh/mozjpeg/mozjpeg_node_enc.js b/packages/next/server/lib/squoosh/mozjpeg/mozjpeg_node_enc.js index d1cabb541f36f..e69b72e4c86b1 100644 --- a/packages/next/server/lib/squoosh/mozjpeg/mozjpeg_node_enc.js +++ b/packages/next/server/lib/squoosh/mozjpeg/mozjpeg_node_enc.js @@ -1,308 +1,691 @@ /* eslint-disable */ -import { TextDecoder } from '../text-decoder' - var Module = (function () { - // var _scriptDir = import.meta.url - return function (Module) { Module = Module || {} - var f - f || (f = typeof Module !== 'undefined' ? Module : {}) - var aa, ba - f.ready = new Promise(function (a, b) { - aa = a - ba = b + var Module = typeof Module !== 'undefined' ? Module : {} + var readyPromiseResolve, readyPromiseReject + Module['ready'] = new Promise(function (resolve, reject) { + readyPromiseResolve = resolve + readyPromiseReject = reject }) - var r = {}, - t - for (t in f) f.hasOwnProperty(t) && (r[t] = f[t]) - var da = './this.program' - function ea(a, b) { - throw b - } - var fa = '', - ha, - ia, - ja, - ka - fa = __dirname + '/' - ha = function (a) { - ja || (ja = require('fs')) - ka || (ka = require('path')) - a = ka.normalize(a) - return ja.readFileSync(a, null) - } - ia = function (a) { - a = ha(a) - a.buffer || (a = new Uint8Array(a)) - a.buffer || u('Assertion failed: undefined') - return a - } - ea = function (a) { - process.exit(a) - } - f.inspect = function () { - return '[Emscripten Module object]' - } - var ma = f.print || console.log.bind(console), - v = f.printErr || console.warn.bind(console) - for (t in r) r.hasOwnProperty(t) && (f[t] = r[t]) - r = null - f.thisProgram && (da = f.thisProgram) - f.quit && (ea = f.quit) - var w - f.wasmBinary && (w = f.wasmBinary) - var noExitRuntime - f.noExitRuntime && (noExitRuntime = f.noExitRuntime) - 'object' !== typeof WebAssembly && u('no native wasm support detected') - var A, - na = !1, - oa = new TextDecoder('utf8') - function pa(a, b, c) { - var d = B - if (0 < c) { - c = b + c - 1 - for (var e = 0; e < a.length; ++e) { - var g = a.charCodeAt(e) - if (55296 <= g && 57343 >= g) { - var m = a.charCodeAt(++e) - g = (65536 + ((g & 1023) << 10)) | (m & 1023) - } - if (127 >= g) { - if (b >= c) break - d[b++] = g - } else { - if (2047 >= g) { - if (b + 1 >= c) break - d[b++] = 192 | (g >> 6) - } else { - if (65535 >= g) { - if (b + 2 >= c) break - d[b++] = 224 | (g >> 12) - } else { - if (b + 3 >= c) break - d[b++] = 240 | (g >> 18) - d[b++] = 128 | ((g >> 12) & 63) - } - d[b++] = 128 | ((g >> 6) & 63) - } - d[b++] = 128 | (g & 63) - } - } - d[b] = 0 - } - } - var qa = new TextDecoder('utf-16le') - function ra(a, b) { - var c = a >> 1 - for (b = c + b / 2; !(c >= b) && C[c]; ) ++c - return qa.decode(B.subarray(a, c << 1)) - } - function sa(a, b, c) { - void 0 === c && (c = 2147483647) - if (2 > c) return 0 - c -= 2 - var d = b - c = c < 2 * a.length ? c / 2 : a.length - for (var e = 0; e < c; ++e) (D[b >> 1] = a.charCodeAt(e)), (b += 2) - D[b >> 1] = 0 - return b - d - } - function ta(a) { - return 2 * a.length - } - function ua(a, b) { - for (var c = 0, d = ''; !(c >= b / 4); ) { - var e = F[(a + 4 * c) >> 2] - if (0 == e) break - ++c - 65536 <= e - ? ((e -= 65536), - (d += String.fromCharCode(55296 | (e >> 10), 56320 | (e & 1023)))) - : (d += String.fromCharCode(e)) - } - return d - } - function va(a, b, c) { - void 0 === c && (c = 2147483647) - if (4 > c) return 0 - var d = b - c = d + c - 4 - for (var e = 0; e < a.length; ++e) { - var g = a.charCodeAt(e) - if (55296 <= g && 57343 >= g) { - var m = a.charCodeAt(++e) - g = (65536 + ((g & 1023) << 10)) | (m & 1023) + var moduleOverrides = {} + var key + for (key in Module) { + if (Module.hasOwnProperty(key)) { + moduleOverrides[key] = Module[key] + } + } + var arguments_ = [] + var thisProgram = './this.program' + var quit_ = function (status, toThrow) { + throw toThrow + } + var ENVIRONMENT_IS_WEB = false + var ENVIRONMENT_IS_WORKER = false + var ENVIRONMENT_IS_NODE = true + var scriptDirectory = '' + function locateFile(path) { + if (Module['locateFile']) { + return Module['locateFile'](path, scriptDirectory) + } + return scriptDirectory + path + } + var read_, readBinary + var nodeFS + var nodePath + if (ENVIRONMENT_IS_NODE) { + if (ENVIRONMENT_IS_WORKER) { + scriptDirectory = require('path').dirname(scriptDirectory) + '/' + } else { + scriptDirectory = __dirname + '/' + } + read_ = function shell_read(filename, binary) { + if (!nodeFS) nodeFS = require('fs') + if (!nodePath) nodePath = require('path') + filename = nodePath['normalize'](filename) + return nodeFS['readFileSync'](filename, binary ? null : 'utf8') + } + readBinary = function readBinary(filename) { + var ret = read_(filename, true) + if (!ret.buffer) { + ret = new Uint8Array(ret) } - F[b >> 2] = g - b += 4 - if (b + 4 > c) break - } - F[b >> 2] = 0 - return b - d - } - function wa(a) { - for (var b = 0, c = 0; c < a.length; ++c) { - var d = a.charCodeAt(c) - 55296 <= d && 57343 >= d && ++c - b += 4 - } - return b - } - var G, H, B, D, C, F, I, xa, ya - function za(a) { - G = a - f.HEAP8 = H = new Int8Array(a) - f.HEAP16 = D = new Int16Array(a) - f.HEAP32 = F = new Int32Array(a) - f.HEAPU8 = B = new Uint8Array(a) - f.HEAPU16 = C = new Uint16Array(a) - f.HEAPU32 = I = new Uint32Array(a) - f.HEAPF32 = xa = new Float32Array(a) - f.HEAPF64 = ya = new Float64Array(a) - } - var Aa = f.INITIAL_MEMORY || 16777216 - f.wasmMemory - ? (A = f.wasmMemory) - : (A = new WebAssembly.Memory({ initial: Aa / 65536, maximum: 32768 })) - A && (G = A.buffer) - Aa = G.byteLength - za(G) - var J, - Ba = [], - Ca = [], - Da = [], - Ea = [] - function Fa() { - var a = f.preRun.shift() - Ba.unshift(a) - } - var K = 0, - Ga = null, - L = null - f.preloadedImages = {} - f.preloadedAudios = {} - function u(a) { - if (f.onAbort) f.onAbort(a) - v(a) - na = !0 - a = new WebAssembly.RuntimeError( - 'abort(' + a + '). Build with -s ASSERTIONS=1 for more info.' + assert(ret.buffer) + return ret + } + if (process['argv'].length > 1) { + thisProgram = process['argv'][1].replace(/\\/g, '/') + } + arguments_ = process['argv'].slice(2) + quit_ = function (status) { + process['exit'](status) + } + Module['inspect'] = function () { + return '[Emscripten Module object]' + } + } else { + } + var out = Module['print'] || console.log.bind(console) + var err = Module['printErr'] || console.warn.bind(console) + for (key in moduleOverrides) { + if (moduleOverrides.hasOwnProperty(key)) { + Module[key] = moduleOverrides[key] + } + } + moduleOverrides = null + if (Module['arguments']) arguments_ = Module['arguments'] + if (Module['thisProgram']) thisProgram = Module['thisProgram'] + if (Module['quit']) quit_ = Module['quit'] + var tempRet0 = 0 + var setTempRet0 = function (value) { + tempRet0 = value + } + var wasmBinary + if (Module['wasmBinary']) wasmBinary = Module['wasmBinary'] + var noExitRuntime = Module['noExitRuntime'] || true + if (typeof WebAssembly !== 'object') { + abort('no native wasm support detected') + } + var wasmMemory + var ABORT = false + var EXITSTATUS + function assert(condition, text) { + if (!condition) { + abort('Assertion failed: ' + text) + } + } + var UTF8Decoder = new TextDecoder('utf8') + function UTF8ArrayToString(heap, idx, maxBytesToRead) { + var endIdx = idx + maxBytesToRead + var endPtr = idx + while (heap[endPtr] && !(endPtr >= endIdx)) ++endPtr + return UTF8Decoder.decode( + heap.subarray + ? heap.subarray(idx, endPtr) + : new Uint8Array(heap.slice(idx, endPtr)) ) - ba(a) - throw a } - function Ha() { - var a = M - return String.prototype.startsWith - ? a.startsWith('data:application/octet-stream;base64,') - : 0 === a.indexOf('data:application/octet-stream;base64,') + function UTF8ToString(ptr, maxBytesToRead) { + if (!ptr) return '' + var maxPtr = ptr + maxBytesToRead + for (var end = ptr; !(end >= maxPtr) && HEAPU8[end]; ) ++end + return UTF8Decoder.decode(HEAPU8.subarray(ptr, end)) + } + function stringToUTF8Array(str, heap, outIdx, maxBytesToWrite) { + if (!(maxBytesToWrite > 0)) return 0 + var startIdx = outIdx + var endIdx = outIdx + maxBytesToWrite - 1 + for (var i = 0; i < str.length; ++i) { + var u = str.charCodeAt(i) + if (u >= 55296 && u <= 57343) { + var u1 = str.charCodeAt(++i) + u = (65536 + ((u & 1023) << 10)) | (u1 & 1023) + } + if (u <= 127) { + if (outIdx >= endIdx) break + heap[outIdx++] = u + } else if (u <= 2047) { + if (outIdx + 1 >= endIdx) break + heap[outIdx++] = 192 | (u >> 6) + heap[outIdx++] = 128 | (u & 63) + } else if (u <= 65535) { + if (outIdx + 2 >= endIdx) break + heap[outIdx++] = 224 | (u >> 12) + heap[outIdx++] = 128 | ((u >> 6) & 63) + heap[outIdx++] = 128 | (u & 63) + } else { + if (outIdx + 3 >= endIdx) break + heap[outIdx++] = 240 | (u >> 18) + heap[outIdx++] = 128 | ((u >> 12) & 63) + heap[outIdx++] = 128 | ((u >> 6) & 63) + heap[outIdx++] = 128 | (u & 63) + } + } + heap[outIdx] = 0 + return outIdx - startIdx + } + function stringToUTF8(str, outPtr, maxBytesToWrite) { + return stringToUTF8Array(str, HEAPU8, outPtr, maxBytesToWrite) + } + function lengthBytesUTF8(str) { + var len = 0 + for (var i = 0; i < str.length; ++i) { + var u = str.charCodeAt(i) + if (u >= 55296 && u <= 57343) + u = (65536 + ((u & 1023) << 10)) | (str.charCodeAt(++i) & 1023) + if (u <= 127) ++len + else if (u <= 2047) len += 2 + else if (u <= 65535) len += 3 + else len += 4 + } + return len + } + var UTF16Decoder = new TextDecoder('utf-16le') + function UTF16ToString(ptr, maxBytesToRead) { + var endPtr = ptr + var idx = endPtr >> 1 + var maxIdx = idx + maxBytesToRead / 2 + while (!(idx >= maxIdx) && HEAPU16[idx]) ++idx + endPtr = idx << 1 + return UTF16Decoder.decode(HEAPU8.subarray(ptr, endPtr)) + var str = '' + for (var i = 0; !(i >= maxBytesToRead / 2); ++i) { + var codeUnit = HEAP16[(ptr + i * 2) >> 1] + if (codeUnit == 0) break + str += String.fromCharCode(codeUnit) + } + return str + } + function stringToUTF16(str, outPtr, maxBytesToWrite) { + if (maxBytesToWrite === undefined) { + maxBytesToWrite = 2147483647 + } + if (maxBytesToWrite < 2) return 0 + maxBytesToWrite -= 2 + var startPtr = outPtr + var numCharsToWrite = + maxBytesToWrite < str.length * 2 ? maxBytesToWrite / 2 : str.length + for (var i = 0; i < numCharsToWrite; ++i) { + var codeUnit = str.charCodeAt(i) + HEAP16[outPtr >> 1] = codeUnit + outPtr += 2 + } + HEAP16[outPtr >> 1] = 0 + return outPtr - startPtr + } + function lengthBytesUTF16(str) { + return str.length * 2 + } + function UTF32ToString(ptr, maxBytesToRead) { + var i = 0 + var str = '' + while (!(i >= maxBytesToRead / 4)) { + var utf32 = HEAP32[(ptr + i * 4) >> 2] + if (utf32 == 0) break + ++i + if (utf32 >= 65536) { + var ch = utf32 - 65536 + str += String.fromCharCode(55296 | (ch >> 10), 56320 | (ch & 1023)) + } else { + str += String.fromCharCode(utf32) + } + } + return str + } + function stringToUTF32(str, outPtr, maxBytesToWrite) { + if (maxBytesToWrite === undefined) { + maxBytesToWrite = 2147483647 + } + if (maxBytesToWrite < 4) return 0 + var startPtr = outPtr + var endPtr = startPtr + maxBytesToWrite - 4 + for (var i = 0; i < str.length; ++i) { + var codeUnit = str.charCodeAt(i) + if (codeUnit >= 55296 && codeUnit <= 57343) { + var trailSurrogate = str.charCodeAt(++i) + codeUnit = + (65536 + ((codeUnit & 1023) << 10)) | (trailSurrogate & 1023) + } + HEAP32[outPtr >> 2] = codeUnit + outPtr += 4 + if (outPtr + 4 > endPtr) break + } + HEAP32[outPtr >> 2] = 0 + return outPtr - startPtr + } + function lengthBytesUTF32(str) { + var len = 0 + for (var i = 0; i < str.length; ++i) { + var codeUnit = str.charCodeAt(i) + if (codeUnit >= 55296 && codeUnit <= 57343) ++i + len += 4 + } + return len + } + function writeAsciiToMemory(str, buffer, dontAddNull) { + for (var i = 0; i < str.length; ++i) { + HEAP8[buffer++ >> 0] = str.charCodeAt(i) + } + if (!dontAddNull) HEAP8[buffer >> 0] = 0 + } + function alignUp(x, multiple) { + if (x % multiple > 0) { + x += multiple - (x % multiple) + } + return x + } + var buffer, + HEAP8, + HEAPU8, + HEAP16, + HEAPU16, + HEAP32, + HEAPU32, + HEAPF32, + HEAPF64 + function updateGlobalBufferAndViews(buf) { + buffer = buf + Module['HEAP8'] = HEAP8 = new Int8Array(buf) + Module['HEAP16'] = HEAP16 = new Int16Array(buf) + Module['HEAP32'] = HEAP32 = new Int32Array(buf) + Module['HEAPU8'] = HEAPU8 = new Uint8Array(buf) + Module['HEAPU16'] = HEAPU16 = new Uint16Array(buf) + Module['HEAPU32'] = HEAPU32 = new Uint32Array(buf) + Module['HEAPF32'] = HEAPF32 = new Float32Array(buf) + Module['HEAPF64'] = HEAPF64 = new Float64Array(buf) } - var M = 'mozjpeg_node_enc.wasm' - if (!Ha()) { - var Ia = M - M = f.locateFile ? f.locateFile(Ia, fa) : fa + Ia + var INITIAL_MEMORY = Module['INITIAL_MEMORY'] || 16777216 + var wasmTable + var __ATPRERUN__ = [] + var __ATINIT__ = [] + var __ATPOSTRUN__ = [] + var runtimeInitialized = false + var runtimeExited = false + function preRun() { + if (Module['preRun']) { + if (typeof Module['preRun'] == 'function') + Module['preRun'] = [Module['preRun']] + while (Module['preRun'].length) { + addOnPreRun(Module['preRun'].shift()) + } + } + callRuntimeCallbacks(__ATPRERUN__) + } + function initRuntime() { + runtimeInitialized = true + callRuntimeCallbacks(__ATINIT__) + } + function exitRuntime() { + runtimeExited = true + } + function postRun() { + if (Module['postRun']) { + if (typeof Module['postRun'] == 'function') + Module['postRun'] = [Module['postRun']] + while (Module['postRun'].length) { + addOnPostRun(Module['postRun'].shift()) + } + } + callRuntimeCallbacks(__ATPOSTRUN__) + } + function addOnPreRun(cb) { + __ATPRERUN__.unshift(cb) + } + function addOnInit(cb) { + __ATINIT__.unshift(cb) + } + function addOnPostRun(cb) { + __ATPOSTRUN__.unshift(cb) + } + var runDependencies = 0 + var runDependencyWatcher = null + var dependenciesFulfilled = null + function addRunDependency(id) { + runDependencies++ + if (Module['monitorRunDependencies']) { + Module['monitorRunDependencies'](runDependencies) + } + } + function removeRunDependency(id) { + runDependencies-- + if (Module['monitorRunDependencies']) { + Module['monitorRunDependencies'](runDependencies) + } + if (runDependencies == 0) { + if (runDependencyWatcher !== null) { + clearInterval(runDependencyWatcher) + runDependencyWatcher = null + } + if (dependenciesFulfilled) { + var callback = dependenciesFulfilled + dependenciesFulfilled = null + callback() + } + } + } + Module['preloadedImages'] = {} + Module['preloadedAudios'] = {} + function abort(what) { + if (Module['onAbort']) { + Module['onAbort'](what) + } + what += '' + err(what) + ABORT = true + EXITSTATUS = 1 + what = 'abort(' + what + '). Build with -s ASSERTIONS=1 for more info.' + var e = new WebAssembly.RuntimeError(what) + readyPromiseReject(e) + throw e + } + var dataURIPrefix = 'data:application/octet-stream;base64,' + function isDataURI(filename) { + return filename.startsWith(dataURIPrefix) + } + if (Module['locateFile']) { + var wasmBinaryFile = 'mozjpeg_node_enc.wasm' + if (!isDataURI(wasmBinaryFile)) { + wasmBinaryFile = locateFile(wasmBinaryFile) + } + } else { + throw new Error('invariant') } - function Ja() { + function getBinary(file) { try { - if (w) return new Uint8Array(w) - if (ia) return ia(M) - throw 'both async and sync fetching of the wasm failed' - } catch (a) { - u(a) - } - } - function N(a) { - for (; 0 < a.length; ) { - var b = a.shift() - if ('function' == typeof b) b(f) - else { - var c = b.R - 'number' === typeof c - ? void 0 === b.L - ? J.get(c)() - : J.get(c)(b.L) - : c(void 0 === b.L ? null : b.L) + if (file == wasmBinaryFile && wasmBinary) { + return new Uint8Array(wasmBinary) + } + if (readBinary) { + return readBinary(file) + } else { + throw 'both async and sync fetching of the wasm failed' } + } catch (err) { + abort(err) } } - var O = {} - function Ka(a) { - for (; a.length; ) { - var b = a.pop() - a.pop()(b) + function getBinaryPromise() { + if (!wasmBinary && (ENVIRONMENT_IS_WEB || ENVIRONMENT_IS_WORKER)) { + if (typeof fetch === 'function') { + return fetch(wasmBinaryFile, { credentials: 'same-origin' }) + .then(function (response) { + if (!response['ok']) { + throw ( + "failed to load wasm binary file at '" + wasmBinaryFile + "'" + ) + } + return response['arrayBuffer']() + }) + .catch(function () { + return getBinary(wasmBinaryFile) + }) + } } + return Promise.resolve().then(function () { + return getBinary(wasmBinaryFile) + }) } - function P(a) { - return this.fromWireType(I[a >> 2]) + function createWasm() { + var info = { a: asmLibraryArg } + function receiveInstance(instance, module) { + var exports = instance.exports + Module['asm'] = exports + wasmMemory = Module['asm']['C'] + updateGlobalBufferAndViews(wasmMemory.buffer) + wasmTable = Module['asm']['I'] + addOnInit(Module['asm']['D']) + removeRunDependency('wasm-instantiate') + } + addRunDependency('wasm-instantiate') + function receiveInstantiationResult(result) { + receiveInstance(result['instance']) + } + function instantiateArrayBuffer(receiver) { + return getBinaryPromise() + .then(function (binary) { + var result = WebAssembly.instantiate(binary, info) + return result + }) + .then(receiver, function (reason) { + err('failed to asynchronously prepare wasm: ' + reason) + abort(reason) + }) + } + function instantiateAsync() { + if ( + !wasmBinary && + typeof WebAssembly.instantiateStreaming === 'function' && + !isDataURI(wasmBinaryFile) && + typeof fetch === 'function' + ) { + return fetch(wasmBinaryFile, { credentials: 'same-origin' }).then( + function (response) { + var result = WebAssembly.instantiateStreaming(response, info) + return result.then(receiveInstantiationResult, function (reason) { + err('wasm streaming compile failed: ' + reason) + err('falling back to ArrayBuffer instantiation') + return instantiateArrayBuffer(receiveInstantiationResult) + }) + } + ) + } else { + return instantiateArrayBuffer(receiveInstantiationResult) + } + } + if (Module['instantiateWasm']) { + try { + var exports = Module['instantiateWasm'](info, receiveInstance) + return exports + } catch (e) { + err('Module.instantiateWasm callback failed with error: ' + e) + return false + } + } + instantiateAsync().catch(readyPromiseReject) + return {} + } + function callRuntimeCallbacks(callbacks) { + while (callbacks.length > 0) { + var callback = callbacks.shift() + if (typeof callback == 'function') { + callback(Module) + continue + } + var func = callback.func + if (typeof func === 'number') { + if (callback.arg === undefined) { + wasmTable.get(func)() + } else { + wasmTable.get(func)(callback.arg) + } + } else { + func(callback.arg === undefined ? null : callback.arg) + } + } } - var Q = {}, - R = {}, - S = {} - function La(a) { - if (void 0 === a) return '_unknown' - a = a.replace(/[^a-zA-Z0-9_]/g, '$') - var b = a.charCodeAt(0) - return 48 <= b && 57 >= b ? '_' + a : a + var runtimeKeepaliveCounter = 0 + function keepRuntimeAlive() { + return noExitRuntime || runtimeKeepaliveCounter > 0 + } + function _atexit(func, arg) {} + function ___cxa_thread_atexit(a0, a1) { + return _atexit(a0, a1) + } + var structRegistrations = {} + function runDestructors(destructors) { + while (destructors.length) { + var ptr = destructors.pop() + var del = destructors.pop() + del(ptr) + } + } + function simpleReadValueFromPointer(pointer) { + return this['fromWireType'](HEAPU32[pointer >> 2]) + } + var awaitingDependencies = {} + var registeredTypes = {} + var typeDependencies = {} + var char_0 = 48 + var char_9 = 57 + function makeLegalFunctionName(name) { + if (undefined === name) { + return '_unknown' + } + name = name.replace(/[^a-zA-Z0-9_]/g, '$') + var f = name.charCodeAt(0) + if (f >= char_0 && f <= char_9) { + return '_' + name + } else { + return name + } } - function Ma(a, b) { - a = La(a) + function createNamedFunction(name, body) { + name = makeLegalFunctionName(name) return new Function( 'body', 'return function ' + - a + - '() {\n "use strict"; return body.apply(this, arguments);\n};\n' - )(b) - } - function Na(a) { - var b = Error, - c = Ma(a, function (d) { - this.name = a - this.message = d - d = Error(d).stack - void 0 !== d && - (this.stack = - this.toString() + '\n' + d.replace(/^Error(:[^\n]*)?\n/, '')) - }) - c.prototype = Object.create(b.prototype) - c.prototype.constructor = c - c.prototype.toString = function () { - return void 0 === this.message - ? this.name - : this.name + ': ' + this.message - } - return c - } - var Oa = void 0 - function Pa(a, b, c) { - function d(h) { - h = c(h) - if (h.length !== a.length) - throw new Oa('Mismatched type converter count') - for (var k = 0; k < a.length; ++k) U(a[k], h[k]) - } - a.forEach(function (h) { - S[h] = b + name + + '() {\n' + + ' "use strict";' + + ' return body.apply(this, arguments);\n' + + '};\n' + )(body) + } + function extendError(baseErrorType, errorName) { + var errorClass = createNamedFunction(errorName, function (message) { + this.name = errorName + this.message = message + var stack = new Error(message).stack + if (stack !== undefined) { + this.stack = + this.toString() + '\n' + stack.replace(/^Error(:[^\n]*)?\n/, '') + } + }) + errorClass.prototype = Object.create(baseErrorType.prototype) + errorClass.prototype.constructor = errorClass + errorClass.prototype.toString = function () { + if (this.message === undefined) { + return this.name + } else { + return this.name + ': ' + this.message + } + } + return errorClass + } + var InternalError = undefined + function throwInternalError(message) { + throw new InternalError(message) + } + function whenDependentTypesAreResolved( + myTypes, + dependentTypes, + getTypeConverters + ) { + myTypes.forEach(function (type) { + typeDependencies[type] = dependentTypes }) - var e = Array(b.length), - g = [], - m = 0 - b.forEach(function (h, k) { - R.hasOwnProperty(h) - ? (e[k] = R[h]) - : (g.push(h), - Q.hasOwnProperty(h) || (Q[h] = []), - Q[h].push(function () { - e[k] = R[h] - ++m - m === g.length && d(e) - })) + function onComplete(typeConverters) { + var myTypeConverters = getTypeConverters(typeConverters) + if (myTypeConverters.length !== myTypes.length) { + throwInternalError('Mismatched type converter count') + } + for (var i = 0; i < myTypes.length; ++i) { + registerType(myTypes[i], myTypeConverters[i]) + } + } + var typeConverters = new Array(dependentTypes.length) + var unregisteredTypes = [] + var registered = 0 + dependentTypes.forEach(function (dt, i) { + if (registeredTypes.hasOwnProperty(dt)) { + typeConverters[i] = registeredTypes[dt] + } else { + unregisteredTypes.push(dt) + if (!awaitingDependencies.hasOwnProperty(dt)) { + awaitingDependencies[dt] = [] + } + awaitingDependencies[dt].push(function () { + typeConverters[i] = registeredTypes[dt] + ++registered + if (registered === unregisteredTypes.length) { + onComplete(typeConverters) + } + }) + } }) - 0 === g.length && d(e) + if (0 === unregisteredTypes.length) { + onComplete(typeConverters) + } } - function Qa(a) { - switch (a) { + function __embind_finalize_value_object(structType) { + var reg = structRegistrations[structType] + delete structRegistrations[structType] + var rawConstructor = reg.rawConstructor + var rawDestructor = reg.rawDestructor + var fieldRecords = reg.fields + var fieldTypes = fieldRecords + .map(function (field) { + return field.getterReturnType + }) + .concat( + fieldRecords.map(function (field) { + return field.setterArgumentType + }) + ) + whenDependentTypesAreResolved( + [structType], + fieldTypes, + function (fieldTypes) { + var fields = {} + fieldRecords.forEach(function (field, i) { + var fieldName = field.fieldName + var getterReturnType = fieldTypes[i] + var getter = field.getter + var getterContext = field.getterContext + var setterArgumentType = fieldTypes[i + fieldRecords.length] + var setter = field.setter + var setterContext = field.setterContext + fields[fieldName] = { + read: function (ptr) { + return getterReturnType['fromWireType']( + getter(getterContext, ptr) + ) + }, + write: function (ptr, o) { + var destructors = [] + setter( + setterContext, + ptr, + setterArgumentType['toWireType'](destructors, o) + ) + runDestructors(destructors) + }, + } + }) + return [ + { + name: reg.name, + fromWireType: function (ptr) { + var rv = {} + for (var i in fields) { + rv[i] = fields[i].read(ptr) + } + rawDestructor(ptr) + return rv + }, + toWireType: function (destructors, o) { + for (var fieldName in fields) { + if (!(fieldName in o)) { + throw new TypeError('Missing field: "' + fieldName + '"') + } + } + var ptr = rawConstructor() + for (fieldName in fields) { + fields[fieldName].write(ptr, o[fieldName]) + } + if (destructors !== null) { + destructors.push(rawDestructor, ptr) + } + return ptr + }, + argPackAdvance: 8, + readValueFromPointer: simpleReadValueFromPointer, + destructorFunction: rawDestructor, + }, + ] + } + ) + } + function __embind_register_bigint( + primitiveType, + name, + size, + minRange, + maxRange + ) {} + function getShiftFromSize(size) { + switch (size) { case 1: return 0 case 2: @@ -312,965 +695,1234 @@ var Module = (function () { case 8: return 3 default: - throw new TypeError('Unknown type size: ' + a) + throw new TypeError('Unknown type size: ' + size) } } - var Ra = void 0 - function V(a) { - for (var b = ''; B[a]; ) b += Ra[B[a++]] - return b + function embind_init_charCodes() { + var codes = new Array(256) + for (var i = 0; i < 256; ++i) { + codes[i] = String.fromCharCode(i) + } + embind_charCodes = codes } - var Sa = void 0 - function W(a) { - throw new Sa(a) + var embind_charCodes = undefined + function readLatin1String(ptr) { + var ret = '' + var c = ptr + while (HEAPU8[c]) { + ret += embind_charCodes[HEAPU8[c++]] + } + return ret + } + var BindingError = undefined + function throwBindingError(message) { + throw new BindingError(message) } - function U(a, b, c) { - c = c || {} - if (!('argPackAdvance' in b)) + function registerType(rawType, registeredInstance, options) { + options = options || {} + if (!('argPackAdvance' in registeredInstance)) { throw new TypeError( 'registerType registeredInstance requires argPackAdvance' ) - var d = b.name - a || W('type "' + d + '" must have a positive integer typeid pointer') - if (R.hasOwnProperty(a)) { - if (c.V) return - W("Cannot register type '" + d + "' twice") - } - R[a] = b - delete S[a] - Q.hasOwnProperty(a) && - ((b = Q[a]), - delete Q[a], - b.forEach(function (e) { - e() - })) - } - var Ta = [], - X = [{}, { value: void 0 }, { value: null }, { value: !0 }, { value: !1 }] - function Ua(a) { - 4 < a && 0 === --X[a].M && ((X[a] = void 0), Ta.push(a)) - } - function Va(a) { - switch (a) { - case void 0: + } + var name = registeredInstance.name + if (!rawType) { + throwBindingError( + 'type "' + name + '" must have a positive integer typeid pointer' + ) + } + if (registeredTypes.hasOwnProperty(rawType)) { + if (options.ignoreDuplicateRegistrations) { + return + } else { + throwBindingError("Cannot register type '" + name + "' twice") + } + } + registeredTypes[rawType] = registeredInstance + delete typeDependencies[rawType] + if (awaitingDependencies.hasOwnProperty(rawType)) { + var callbacks = awaitingDependencies[rawType] + delete awaitingDependencies[rawType] + callbacks.forEach(function (cb) { + cb() + }) + } + } + function __embind_register_bool( + rawType, + name, + size, + trueValue, + falseValue + ) { + var shift = getShiftFromSize(size) + name = readLatin1String(name) + registerType(rawType, { + name: name, + fromWireType: function (wt) { + return !!wt + }, + toWireType: function (destructors, o) { + return o ? trueValue : falseValue + }, + argPackAdvance: 8, + readValueFromPointer: function (pointer) { + var heap + if (size === 1) { + heap = HEAP8 + } else if (size === 2) { + heap = HEAP16 + } else if (size === 4) { + heap = HEAP32 + } else { + throw new TypeError('Unknown boolean type size: ' + name) + } + return this['fromWireType'](heap[pointer >> shift]) + }, + destructorFunction: null, + }) + } + var emval_free_list = [] + var emval_handle_array = [ + {}, + { value: undefined }, + { value: null }, + { value: true }, + { value: false }, + ] + function __emval_decref(handle) { + if (handle > 4 && 0 === --emval_handle_array[handle].refcount) { + emval_handle_array[handle] = undefined + emval_free_list.push(handle) + } + } + function count_emval_handles() { + var count = 0 + for (var i = 5; i < emval_handle_array.length; ++i) { + if (emval_handle_array[i] !== undefined) { + ++count + } + } + return count + } + function get_first_emval() { + for (var i = 5; i < emval_handle_array.length; ++i) { + if (emval_handle_array[i] !== undefined) { + return emval_handle_array[i] + } + } + return null + } + function init_emval() { + Module['count_emval_handles'] = count_emval_handles + Module['get_first_emval'] = get_first_emval + } + function __emval_register(value) { + switch (value) { + case undefined: { return 1 - case null: + } + case null: { return 2 - case !0: + } + case true: { return 3 - case !1: + } + case false: { return 4 - default: - var b = Ta.length ? Ta.pop() : X.length - X[b] = { M: 1, value: a } - return b + } + default: { + var handle = emval_free_list.length + ? emval_free_list.pop() + : emval_handle_array.length + emval_handle_array[handle] = { refcount: 1, value: value } + return handle + } } } - function Wa(a) { - if (null === a) return 'null' - var b = typeof a - return 'object' === b || 'array' === b || 'function' === b - ? a.toString() - : '' + a + function __embind_register_emval(rawType, name) { + name = readLatin1String(name) + registerType(rawType, { + name: name, + fromWireType: function (handle) { + var rv = emval_handle_array[handle].value + __emval_decref(handle) + return rv + }, + toWireType: function (destructors, value) { + return __emval_register(value) + }, + argPackAdvance: 8, + readValueFromPointer: simpleReadValueFromPointer, + destructorFunction: null, + }) + } + function _embind_repr(v) { + if (v === null) { + return 'null' + } + var t = typeof v + if (t === 'object' || t === 'array' || t === 'function') { + return v.toString() + } else { + return '' + v + } } - function Xa(a, b) { - switch (b) { + function floatReadValueFromPointer(name, shift) { + switch (shift) { case 2: - return function (c) { - return this.fromWireType(xa[c >> 2]) + return function (pointer) { + return this['fromWireType'](HEAPF32[pointer >> 2]) } case 3: - return function (c) { - return this.fromWireType(ya[c >> 3]) + return function (pointer) { + return this['fromWireType'](HEAPF64[pointer >> 3]) } default: - throw new TypeError('Unknown float type: ' + a) + throw new TypeError('Unknown float type: ' + name) } } - function Ya(a) { - var b = Function - if (!(b instanceof Function)) + function __embind_register_float(rawType, name, size) { + var shift = getShiftFromSize(size) + name = readLatin1String(name) + registerType(rawType, { + name: name, + fromWireType: function (value) { + return value + }, + toWireType: function (destructors, value) { + if (typeof value !== 'number' && typeof value !== 'boolean') { + throw new TypeError( + 'Cannot convert "' + _embind_repr(value) + '" to ' + this.name + ) + } + return value + }, + argPackAdvance: 8, + readValueFromPointer: floatReadValueFromPointer(name, shift), + destructorFunction: null, + }) + } + function new_(constructor, argumentList) { + if (!(constructor instanceof Function)) { throw new TypeError( 'new_ called with constructor type ' + - typeof b + + typeof constructor + ' which is not a function' ) - var c = Ma(b.name || 'unknownFunctionName', function () {}) - c.prototype = b.prototype - c = new c() - a = b.apply(c, a) - return a instanceof Object ? a : c - } - function Za(a, b) { - var c = f - if (void 0 === c[a].J) { - var d = c[a] - c[a] = function () { - c[a].J.hasOwnProperty(arguments.length) || - W( + } + var dummy = createNamedFunction( + constructor.name || 'unknownFunctionName', + function () {} + ) + dummy.prototype = constructor.prototype + var obj = new dummy() + var r = constructor.apply(obj, argumentList) + return r instanceof Object ? r : obj + } + function craftInvokerFunction( + humanName, + argTypes, + classType, + cppInvokerFunc, + cppTargetFunc + ) { + var argCount = argTypes.length + if (argCount < 2) { + throwBindingError( + "argTypes array size mismatch! Must at least get return value and 'this' types!" + ) + } + var isClassMethodFunc = argTypes[1] !== null && classType !== null + var needsDestructorStack = false + for (var i = 1; i < argTypes.length; ++i) { + if ( + argTypes[i] !== null && + argTypes[i].destructorFunction === undefined + ) { + needsDestructorStack = true + break + } + } + var returns = argTypes[0].name !== 'void' + var argsList = '' + var argsListWired = '' + for (var i = 0; i < argCount - 2; ++i) { + argsList += (i !== 0 ? ', ' : '') + 'arg' + i + argsListWired += (i !== 0 ? ', ' : '') + 'arg' + i + 'Wired' + } + var invokerFnBody = + 'return function ' + + makeLegalFunctionName(humanName) + + '(' + + argsList + + ') {\n' + + 'if (arguments.length !== ' + + (argCount - 2) + + ') {\n' + + "throwBindingError('function " + + humanName + + " called with ' + arguments.length + ' arguments, expected " + + (argCount - 2) + + " args!');\n" + + '}\n' + if (needsDestructorStack) { + invokerFnBody += 'var destructors = [];\n' + } + var dtorStack = needsDestructorStack ? 'destructors' : 'null' + var args1 = [ + 'throwBindingError', + 'invoker', + 'fn', + 'runDestructors', + 'retType', + 'classParam', + ] + var args2 = [ + throwBindingError, + cppInvokerFunc, + cppTargetFunc, + runDestructors, + argTypes[0], + argTypes[1], + ] + if (isClassMethodFunc) { + invokerFnBody += + 'var thisWired = classParam.toWireType(' + dtorStack + ', this);\n' + } + for (var i = 0; i < argCount - 2; ++i) { + invokerFnBody += + 'var arg' + + i + + 'Wired = argType' + + i + + '.toWireType(' + + dtorStack + + ', arg' + + i + + '); // ' + + argTypes[i + 2].name + + '\n' + args1.push('argType' + i) + args2.push(argTypes[i + 2]) + } + if (isClassMethodFunc) { + argsListWired = + 'thisWired' + (argsListWired.length > 0 ? ', ' : '') + argsListWired + } + invokerFnBody += + (returns ? 'var rv = ' : '') + + 'invoker(fn' + + (argsListWired.length > 0 ? ', ' : '') + + argsListWired + + ');\n' + if (needsDestructorStack) { + invokerFnBody += 'runDestructors(destructors);\n' + } else { + for (var i = isClassMethodFunc ? 1 : 2; i < argTypes.length; ++i) { + var paramName = i === 1 ? 'thisWired' : 'arg' + (i - 2) + 'Wired' + if (argTypes[i].destructorFunction !== null) { + invokerFnBody += + paramName + + '_dtor(' + + paramName + + '); // ' + + argTypes[i].name + + '\n' + args1.push(paramName + '_dtor') + args2.push(argTypes[i].destructorFunction) + } + } + } + if (returns) { + invokerFnBody += + 'var ret = retType.fromWireType(rv);\n' + 'return ret;\n' + } else { + } + invokerFnBody += '}\n' + args1.push(invokerFnBody) + var invokerFunction = new_(Function, args1).apply(null, args2) + return invokerFunction + } + function ensureOverloadTable(proto, methodName, humanName) { + if (undefined === proto[methodName].overloadTable) { + var prevFunc = proto[methodName] + proto[methodName] = function () { + if ( + !proto[methodName].overloadTable.hasOwnProperty(arguments.length) + ) { + throwBindingError( "Function '" + - b + + humanName + "' called with an invalid number of arguments (" + arguments.length + ') - expects one of (' + - c[a].J + + proto[methodName].overloadTable + ')!' ) - return c[a].J[arguments.length].apply(this, arguments) + } + return proto[methodName].overloadTable[arguments.length].apply( + this, + arguments + ) } - c[a].J = [] - c[a].J[d.O] = d - } - } - function $a(a, b, c) { - f.hasOwnProperty(a) - ? ((void 0 === c || (void 0 !== f[a].J && void 0 !== f[a].J[c])) && - W("Cannot register public name '" + a + "' twice"), - Za(a, a), - f.hasOwnProperty(c) && - W( - 'Cannot register multiple overloads of a function with the same number of arguments (' + - c + - ')!' - ), - (f[a].J[c] = b)) - : ((f[a] = b), void 0 !== c && (f[a].ba = c)) - } - function ab(a, b) { - for (var c = [], d = 0; d < a; d++) c.push(F[(b >> 2) + d]) - return c - } - function bb(a, b) { - 0 <= a.indexOf('j') || - u('Assertion failed: getDynCaller should only be called with i64 sigs') - var c = [] + proto[methodName].overloadTable = [] + proto[methodName].overloadTable[prevFunc.argCount] = prevFunc + } + } + function exposePublicSymbol(name, value, numArguments) { + if (Module.hasOwnProperty(name)) { + if ( + undefined === numArguments || + (undefined !== Module[name].overloadTable && + undefined !== Module[name].overloadTable[numArguments]) + ) { + throwBindingError("Cannot register public name '" + name + "' twice") + } + ensureOverloadTable(Module, name, name) + if (Module.hasOwnProperty(numArguments)) { + throwBindingError( + 'Cannot register multiple overloads of a function with the same number of arguments (' + + numArguments + + ')!' + ) + } + Module[name].overloadTable[numArguments] = value + } else { + Module[name] = value + if (undefined !== numArguments) { + Module[name].numArguments = numArguments + } + } + } + function heap32VectorToArray(count, firstElement) { + var array = [] + for (var i = 0; i < count; i++) { + array.push(HEAP32[(firstElement >> 2) + i]) + } + return array + } + function replacePublicSymbol(name, value, numArguments) { + if (!Module.hasOwnProperty(name)) { + throwInternalError('Replacing nonexistant public symbol') + } + if ( + undefined !== Module[name].overloadTable && + undefined !== numArguments + ) { + Module[name].overloadTable[numArguments] = value + } else { + Module[name] = value + Module[name].argCount = numArguments + } + } + function dynCallLegacy(sig, ptr, args) { + var f = Module['dynCall_' + sig] + return args && args.length + ? f.apply(null, [ptr].concat(args)) + : f.call(null, ptr) + } + function dynCall(sig, ptr, args) { + if (sig.includes('j')) { + return dynCallLegacy(sig, ptr, args) + } + return wasmTable.get(ptr).apply(null, args) + } + function getDynCaller(sig, ptr) { + var argCache = [] return function () { - c.length = arguments.length - for (var d = 0; d < arguments.length; d++) c[d] = arguments[d] - var e - ;-1 != a.indexOf('j') - ? (e = - c && c.length - ? f['dynCall_' + a].apply(null, [b].concat(c)) - : f['dynCall_' + a].call(null, b)) - : (e = J.get(b).apply(null, c)) - return e - } - } - function Y(a, b) { - a = V(a) - var c = -1 != a.indexOf('j') ? bb(a, b) : J.get(b) - 'function' !== typeof c && - W('unknown function pointer with signature ' + a + ': ' + b) - return c - } - var cb = void 0 - function db(a) { - a = eb(a) - var b = V(a) - Z(a) - return b - } - function fb(a, b) { - function c(g) { - e[g] || R[g] || (S[g] ? S[g].forEach(c) : (d.push(g), (e[g] = !0))) - } - var d = [], - e = {} - b.forEach(c) - throw new cb(a + ': ' + d.map(db).join([', '])) - } - function gb(a, b, c) { - switch (b) { + argCache.length = arguments.length + for (var i = 0; i < arguments.length; i++) { + argCache[i] = arguments[i] + } + return dynCall(sig, ptr, argCache) + } + } + function embind__requireFunction(signature, rawFunction) { + signature = readLatin1String(signature) + function makeDynCaller() { + if (signature.includes('j')) { + return getDynCaller(signature, rawFunction) + } + return wasmTable.get(rawFunction) + } + var fp = makeDynCaller() + if (typeof fp !== 'function') { + throwBindingError( + 'unknown function pointer with signature ' + + signature + + ': ' + + rawFunction + ) + } + return fp + } + var UnboundTypeError = undefined + function getTypeName(type) { + var ptr = ___getTypeName(type) + var rv = readLatin1String(ptr) + _free(ptr) + return rv + } + function throwUnboundTypeError(message, types) { + var unboundTypes = [] + var seen = {} + function visit(type) { + if (seen[type]) { + return + } + if (registeredTypes[type]) { + return + } + if (typeDependencies[type]) { + typeDependencies[type].forEach(visit) + return + } + unboundTypes.push(type) + seen[type] = true + } + types.forEach(visit) + throw new UnboundTypeError( + message + ': ' + unboundTypes.map(getTypeName).join([', ']) + ) + } + function __embind_register_function( + name, + argCount, + rawArgTypesAddr, + signature, + rawInvoker, + fn + ) { + var argTypes = heap32VectorToArray(argCount, rawArgTypesAddr) + name = readLatin1String(name) + rawInvoker = embind__requireFunction(signature, rawInvoker) + exposePublicSymbol( + name, + function () { + throwUnboundTypeError( + 'Cannot call ' + name + ' due to unbound types', + argTypes + ) + }, + argCount - 1 + ) + whenDependentTypesAreResolved([], argTypes, function (argTypes) { + var invokerArgsArray = [argTypes[0], null].concat(argTypes.slice(1)) + replacePublicSymbol( + name, + craftInvokerFunction(name, invokerArgsArray, null, rawInvoker, fn), + argCount - 1 + ) + return [] + }) + } + function integerReadValueFromPointer(name, shift, signed) { + switch (shift) { case 0: - return c - ? function (d) { - return H[d] + return signed + ? function readS8FromPointer(pointer) { + return HEAP8[pointer] } - : function (d) { - return B[d] + : function readU8FromPointer(pointer) { + return HEAPU8[pointer] } case 1: - return c - ? function (d) { - return D[d >> 1] + return signed + ? function readS16FromPointer(pointer) { + return HEAP16[pointer >> 1] } - : function (d) { - return C[d >> 1] + : function readU16FromPointer(pointer) { + return HEAPU16[pointer >> 1] } case 2: - return c - ? function (d) { - return F[d >> 2] + return signed + ? function readS32FromPointer(pointer) { + return HEAP32[pointer >> 2] } - : function (d) { - return I[d >> 2] + : function readU32FromPointer(pointer) { + return HEAPU32[pointer >> 2] } default: - throw new TypeError('Unknown integer type: ' + a) - } - } - var hb = {} - function ib() { - return 'object' === typeof globalThis - ? globalThis - : Function('return this')() - } - function jb(a, b) { - var c = R[a] - void 0 === c && W(b + ' has unknown type ' + db(a)) - return c - } - var kb = {}, - lb = {} - function mb() { - if (!nb) { - var a = { - USER: 'web_user', - LOGNAME: 'web_user', - PATH: '/', - PWD: '/', - HOME: '/home/web_user', - LANG: - ( - ('object' === typeof navigator && - navigator.languages && - navigator.languages[0]) || - 'C' - ).replace('-', '_') + '.UTF-8', - _: da || './this.program', - }, - b - for (b in lb) a[b] = lb[b] - var c = [] - for (b in a) c.push(b + '=' + a[b]) - nb = c - } - return nb - } - var nb, - ob = [null, [], []] - Oa = f.InternalError = Na('InternalError') - for (var pb = Array(256), qb = 0; 256 > qb; ++qb) - pb[qb] = String.fromCharCode(qb) - Ra = pb - Sa = f.BindingError = Na('BindingError') - f.count_emval_handles = function () { - for (var a = 0, b = 5; b < X.length; ++b) void 0 !== X[b] && ++a - return a - } - f.get_first_emval = function () { - for (var a = 5; a < X.length; ++a) if (void 0 !== X[a]) return X[a] - return null + throw new TypeError('Unknown integer type: ' + name) + } } - cb = f.UnboundTypeError = Na('UnboundTypeError') - Ca.push({ - R: function () { - rb() - }, - }) - var tb = { - B: function () {}, - n: function (a) { - var b = O[a] - delete O[a] - var c = b.W, - d = b.X, - e = b.N, - g = e - .map(function (m) { - return m.U - }) - .concat( - e.map(function (m) { - return m.Z - }) - ) - Pa([a], g, function (m) { - var h = {} - e.forEach(function (k, n) { - var l = m[n], - p = k.S, - x = k.T, - y = m[n + e.length], - q = k.Y, - ca = k.$ - h[k.P] = { - read: function (z) { - return l.fromWireType(p(x, z)) - }, - write: function (z, E) { - var T = [] - q(ca, z, y.toWireType(T, E)) - Ka(T) - }, - } - }) - return [ - { - name: b.name, - fromWireType: function (k) { - var n = {}, - l - for (l in h) n[l] = h[l].read(k) - d(k) - return n - }, - toWireType: function (k, n) { - for (var l in h) - if (!(l in n)) - throw new TypeError('Missing field: "' + l + '"') - var p = c() - for (l in h) h[l].write(p, n[l]) - null !== k && k.push(d, p) - return p - }, - argPackAdvance: 8, - readValueFromPointer: P, - K: d, - }, - ] - }) - }, - y: function (a, b, c, d, e) { - var g = Qa(c) - b = V(b) - U(a, { - name: b, - fromWireType: function (m) { - return !!m - }, - toWireType: function (m, h) { - return h ? d : e - }, - argPackAdvance: 8, - readValueFromPointer: function (m) { - if (1 === c) var h = H - else if (2 === c) h = D - else if (4 === c) h = F - else throw new TypeError('Unknown boolean type size: ' + b) - return this.fromWireType(h[m >> g]) - }, - K: null, - }) - }, - x: function (a, b) { - b = V(b) - U(a, { - name: b, - fromWireType: function (c) { - var d = X[c].value - Ua(c) - return d - }, - toWireType: function (c, d) { - return Va(d) - }, - argPackAdvance: 8, - readValueFromPointer: P, - K: null, - }) - }, - k: function (a, b, c) { - c = Qa(c) - b = V(b) - U(a, { - name: b, - fromWireType: function (d) { - return d - }, - toWireType: function (d, e) { - if ('number' !== typeof e && 'boolean' !== typeof e) - throw new TypeError( - 'Cannot convert "' + Wa(e) + '" to ' + this.name - ) - return e - }, - argPackAdvance: 8, - readValueFromPointer: Xa(b, c), - K: null, - }) - }, - g: function (a, b, c, d, e, g) { - var m = ab(b, c) - a = V(a) - e = Y(d, e) - $a( - a, - function () { - fb('Cannot call ' + a + ' due to unbound types', m) - }, - b - 1 - ) - Pa([], m, function (h) { - var k = [h[0], null].concat(h.slice(1)), - n = (h = a), - l = e, - p = k.length - 2 > p && - W( - "argTypes array size mismatch! Must at least get return value and 'this' types!" + function __embind_register_integer( + primitiveType, + name, + size, + minRange, + maxRange + ) { + name = readLatin1String(name) + if (maxRange === -1) { + maxRange = 4294967295 + } + var shift = getShiftFromSize(size) + var fromWireType = function (value) { + return value + } + if (minRange === 0) { + var bitshift = 32 - 8 * size + fromWireType = function (value) { + return (value << bitshift) >>> bitshift + } + } + var isUnsignedType = name.includes('unsigned') + registerType(primitiveType, { + name: name, + fromWireType: fromWireType, + toWireType: function (destructors, value) { + if (typeof value !== 'number' && typeof value !== 'boolean') { + throw new TypeError( + 'Cannot convert "' + _embind_repr(value) + '" to ' + this.name ) - for (var x = null !== k[1] && !1, y = !1, q = 1; q < k.length; ++q) - if (null !== k[q] && void 0 === k[q].K) { - y = !0 - break - } - var ca = 'void' !== k[0].name, - z = '', - E = '' - for (q = 0; q < p - 2; ++q) - (z += (0 !== q ? ', ' : '') + 'arg' + q), - (E += (0 !== q ? ', ' : '') + 'arg' + q + 'Wired') - n = - 'return function ' + - La(n) + - '(' + - z + - ') {\nif (arguments.length !== ' + - (p - 2) + - ") {\nthrowBindingError('function " + - n + - " called with ' + arguments.length + ' arguments, expected " + - (p - 2) + - " args!');\n}\n" - y && (n += 'var destructors = [];\n') - var T = y ? 'destructors' : 'null' - z = - 'throwBindingError invoker fn runDestructors retType classParam'.split( - ' ' + } + if (value < minRange || value > maxRange) { + throw new TypeError( + 'Passing a number "' + + _embind_repr(value) + + '" from JS side to C/C++ side to an argument of type "' + + name + + '", which is outside the valid range [' + + minRange + + ', ' + + maxRange + + ']!' ) - l = [W, l, g, Ka, k[0], k[1]] - x && - (n += 'var thisWired = classParam.toWireType(' + T + ', this);\n') - for (q = 0; q < p - 2; ++q) - (n += - 'var arg' + - q + - 'Wired = argType' + - q + - '.toWireType(' + - T + - ', arg' + - q + - '); // ' + - k[q + 2].name + - '\n'), - z.push('argType' + q), - l.push(k[q + 2]) - x && (E = 'thisWired' + (0 < E.length ? ', ' : '') + E) - n += - (ca ? 'var rv = ' : '') + - 'invoker(fn' + - (0 < E.length ? ', ' : '') + - E + - ');\n' - if (y) n += 'runDestructors(destructors);\n' - else - for (q = x ? 1 : 2; q < k.length; ++q) - (p = 1 === q ? 'thisWired' : 'arg' + (q - 2) + 'Wired'), - null !== k[q].K && - ((n += p + '_dtor(' + p + '); // ' + k[q].name + '\n'), - z.push(p + '_dtor'), - l.push(k[q].K)) - ca && (n += 'var ret = retType.fromWireType(rv);\nreturn ret;\n') - z.push(n + '}\n') - k = Ya(z).apply(null, l) - q = b - 1 - if (!f.hasOwnProperty(h)) - throw new Oa('Replacing nonexistant public symbol') - void 0 !== f[h].J && void 0 !== q - ? (f[h].J[q] = k) - : ((f[h] = k), (f[h].O = q)) - return [] - }) - }, - d: function (a, b, c, d, e) { - function g(n) { - return n - } - b = V(b) - ;-1 === e && (e = 4294967295) - var m = Qa(c) - if (0 === d) { - var h = 32 - 8 * c - g = function (n) { - return (n << h) >>> h } - } - var k = -1 != b.indexOf('unsigned') - U(a, { - name: b, - fromWireType: g, - toWireType: function (n, l) { - if ('number' !== typeof l && 'boolean' !== typeof l) - throw new TypeError( - 'Cannot convert "' + Wa(l) + '" to ' + this.name - ) - if (l < d || l > e) - throw new TypeError( - 'Passing a number "' + - Wa(l) + - '" from JS side to C/C++ side to an argument of type "' + - b + - '", which is outside the valid range [' + - d + - ', ' + - e + - ']!' - ) - return k ? l >>> 0 : l | 0 - }, + return isUnsignedType ? value >>> 0 : value | 0 + }, + argPackAdvance: 8, + readValueFromPointer: integerReadValueFromPointer( + name, + shift, + minRange !== 0 + ), + destructorFunction: null, + }) + } + function __embind_register_memory_view(rawType, dataTypeIndex, name) { + var typeMapping = [ + Int8Array, + Uint8Array, + Int16Array, + Uint16Array, + Int32Array, + Uint32Array, + Float32Array, + Float64Array, + ] + var TA = typeMapping[dataTypeIndex] + function decodeMemoryView(handle) { + handle = handle >> 2 + var heap = HEAPU32 + var size = heap[handle] + var data = heap[handle + 1] + return new TA(buffer, data, size) + } + name = readLatin1String(name) + registerType( + rawType, + { + name: name, + fromWireType: decodeMemoryView, argPackAdvance: 8, - readValueFromPointer: gb(b, m, 0 !== d), - K: null, - }) - }, - c: function (a, b, c) { - function d(g) { - g >>= 2 - var m = I - return new e(G, m[g + 1], m[g]) - } - var e = [ - Int8Array, - Uint8Array, - Int16Array, - Uint16Array, - Int32Array, - Uint32Array, - Float32Array, - Float64Array, - ][b] - c = V(c) - U( - a, - { - name: c, - fromWireType: d, - argPackAdvance: 8, - readValueFromPointer: d, - }, - { V: !0 } - ) - }, - l: function (a, b) { - b = V(b) - var c = 'std::string' === b - U(a, { - name: b, - fromWireType: function (d) { - var e = I[d >> 2] - if (c) - for (var g = d + 4, m = 0; m <= e; ++m) { - var h = d + 4 + m - if (m == e || 0 == B[h]) { - if (g) { - for (var k = g + (h - g), n = g; !(n >= k) && B[n]; ) ++n - g = oa.decode(B.subarray(g, n)) - } else g = '' - if (void 0 === l) var l = g - else (l += String.fromCharCode(0)), (l += g) - g = h + 1 + readValueFromPointer: decodeMemoryView, + }, + { ignoreDuplicateRegistrations: true } + ) + } + function __embind_register_std_string(rawType, name) { + name = readLatin1String(name) + var stdStringIsUTF8 = name === 'std::string' + registerType(rawType, { + name: name, + fromWireType: function (value) { + var length = HEAPU32[value >> 2] + var str + if (stdStringIsUTF8) { + var decodeStartPtr = value + 4 + for (var i = 0; i <= length; ++i) { + var currentBytePtr = value + 4 + i + if (i == length || HEAPU8[currentBytePtr] == 0) { + var maxRead = currentBytePtr - decodeStartPtr + var stringSegment = UTF8ToString(decodeStartPtr, maxRead) + if (str === undefined) { + str = stringSegment + } else { + str += String.fromCharCode(0) + str += stringSegment } + decodeStartPtr = currentBytePtr + 1 } - else { - l = Array(e) - for (m = 0; m < e; ++m) l[m] = String.fromCharCode(B[d + 4 + m]) - l = l.join('') } - Z(d) - return l - }, - toWireType: function (d, e) { - e instanceof ArrayBuffer && (e = new Uint8Array(e)) - var g = 'string' === typeof e - g || - e instanceof Uint8Array || - e instanceof Uint8ClampedArray || - e instanceof Int8Array || - W('Cannot pass non-string to std::string') - var m = ( - c && g - ? function () { - for (var n = 0, l = 0; l < e.length; ++l) { - var p = e.charCodeAt(l) - 55296 <= p && - 57343 >= p && - (p = - (65536 + ((p & 1023) << 10)) | - (e.charCodeAt(++l) & 1023)) - 127 >= p - ? ++n - : (n = 2047 >= p ? n + 2 : 65535 >= p ? n + 3 : n + 4) - } - return n - } - : function () { - return e.length - } - )(), - h = sb(4 + m + 1) - I[h >> 2] = m - if (c && g) pa(e, h + 4, m + 1) - else if (g) - for (g = 0; g < m; ++g) { - var k = e.charCodeAt(g) - 255 < k && - (Z(h), - W('String has UTF-16 code units that do not fit in 8 bits')) - B[h + 4 + g] = k - } - else for (g = 0; g < m; ++g) B[h + 4 + g] = e[g] - null !== d && d.push(Z, h) - return h - }, - argPackAdvance: 8, - readValueFromPointer: P, - K: function (d) { - Z(d) - }, - }) - }, - f: function (a, b, c) { - c = V(c) - if (2 === b) { - var d = ra - var e = sa - var g = ta - var m = function () { - return C + } else { + var a = new Array(length) + for (var i = 0; i < length; ++i) { + a[i] = String.fromCharCode(HEAPU8[value + 4 + i]) + } + str = a.join('') } - var h = 1 - } else - 4 === b && - ((d = ua), - (e = va), - (g = wa), - (m = function () { - return I - }), - (h = 2)) - U(a, { - name: c, - fromWireType: function (k) { - for (var n = I[k >> 2], l = m(), p, x = k + 4, y = 0; y <= n; ++y) { - var q = k + 4 + y * b - if (y == n || 0 == l[q >> h]) - (x = d(x, q - x)), - void 0 === p - ? (p = x) - : ((p += String.fromCharCode(0)), (p += x)), - (x = q + b) + _free(value) + return str + }, + toWireType: function (destructors, value) { + if (value instanceof ArrayBuffer) { + value = new Uint8Array(value) + } + var getLength + var valueIsOfTypeString = typeof value === 'string' + if ( + !( + valueIsOfTypeString || + value instanceof Uint8Array || + value instanceof Uint8ClampedArray || + value instanceof Int8Array + ) + ) { + throwBindingError('Cannot pass non-string to std::string') + } + if (stdStringIsUTF8 && valueIsOfTypeString) { + getLength = function () { + return lengthBytesUTF8(value) } - Z(k) - return p - }, - toWireType: function (k, n) { - 'string' !== typeof n && - W('Cannot pass non-string to C++ string type ' + c) - var l = g(n), - p = sb(4 + l + b) - I[p >> 2] = l >> h - e(n, p + 4, l + b) - null !== k && k.push(Z, p) - return p - }, - argPackAdvance: 8, - readValueFromPointer: P, - K: function (k) { - Z(k) - }, - }) - }, - o: function (a, b, c, d, e, g) { - O[a] = { name: V(b), W: Y(c, d), X: Y(e, g), N: [] } - }, - b: function (a, b, c, d, e, g, m, h, k, n) { - O[a].N.push({ P: V(b), U: c, S: Y(d, e), T: g, Z: m, Y: Y(h, k), $: n }) - }, - z: function (a, b) { - b = V(b) - U(a, { - aa: !0, - name: b, - argPackAdvance: 0, - fromWireType: function () {}, - toWireType: function () {}, - }) - }, - h: Ua, - v: function (a) { - if (0 === a) return Va(ib()) - var b = hb[a] - a = void 0 === b ? V(a) : b - return Va(ib()[a]) - }, - m: function (a) { - 4 < a && (X[a].M += 1) - }, - p: function (a, b, c, d) { - a || W('Cannot use deleted val. handle = ' + a) - a = X[a].value - var e = kb[b] - if (!e) { - e = '' - for (var g = 0; g < b; ++g) e += (0 !== g ? ', ' : '') + 'arg' + g - var m = - 'return function emval_allocator_' + - b + - '(constructor, argTypes, args) {\n' - for (g = 0; g < b; ++g) - m += - 'var argType' + - g + - " = requireRegisteredType(Module['HEAP32'][(argTypes >>> 2) + " + - g + - '], "parameter ' + - g + - '");\nvar arg' + - g + - ' = argType' + - g + - '.readValueFromPointer(args);\nargs += argType' + - g + - "['argPackAdvance'];\n" - e = new Function( - 'requireRegisteredType', - 'Module', - '__emval_register', - m + - ('var obj = new constructor(' + - e + - ');\nreturn __emval_register(obj);\n}\n') - )(jb, f, Va) - kb[b] = e + } else { + getLength = function () { + return value.length + } + } + var length = getLength() + var ptr = _malloc(4 + length + 1) + HEAPU32[ptr >> 2] = length + if (stdStringIsUTF8 && valueIsOfTypeString) { + stringToUTF8(value, ptr + 4, length + 1) + } else { + if (valueIsOfTypeString) { + for (var i = 0; i < length; ++i) { + var charCode = value.charCodeAt(i) + if (charCode > 255) { + _free(ptr) + throwBindingError( + 'String has UTF-16 code units that do not fit in 8 bits' + ) + } + HEAPU8[ptr + 4 + i] = charCode + } + } else { + for (var i = 0; i < length; ++i) { + HEAPU8[ptr + 4 + i] = value[i] + } + } + } + if (destructors !== null) { + destructors.push(_free, ptr) + } + return ptr + }, + argPackAdvance: 8, + readValueFromPointer: simpleReadValueFromPointer, + destructorFunction: function (ptr) { + _free(ptr) + }, + }) + } + function __embind_register_std_wstring(rawType, charSize, name) { + name = readLatin1String(name) + var decodeString, encodeString, getHeap, lengthBytesUTF, shift + if (charSize === 2) { + decodeString = UTF16ToString + encodeString = stringToUTF16 + lengthBytesUTF = lengthBytesUTF16 + getHeap = function () { + return HEAPU16 } - return e(a, c, d) - }, - i: function () { - u() - }, - s: function (a, b, c) { - B.copyWithin(a, b, b + c) - }, - e: function (a) { - a >>>= 0 - var b = B.length - if (2147483648 < a) return !1 - for (var c = 1; 4 >= c; c *= 2) { - var d = b * (1 + 0.2 / c) - d = Math.min(d, a + 100663296) - d = Math.max(16777216, a, d) - 0 < d % 65536 && (d += 65536 - (d % 65536)) - a: { - try { - A.grow((Math.min(2147483648, d) - G.byteLength + 65535) >>> 16) - za(A.buffer) - var e = 1 - break a - } catch (g) {} - e = void 0 + shift = 1 + } else if (charSize === 4) { + decodeString = UTF32ToString + encodeString = stringToUTF32 + lengthBytesUTF = lengthBytesUTF32 + getHeap = function () { + return HEAPU32 + } + shift = 2 + } + registerType(rawType, { + name: name, + fromWireType: function (value) { + var length = HEAPU32[value >> 2] + var HEAP = getHeap() + var str + var decodeStartPtr = value + 4 + for (var i = 0; i <= length; ++i) { + var currentBytePtr = value + 4 + i * charSize + if (i == length || HEAP[currentBytePtr >> shift] == 0) { + var maxReadBytes = currentBytePtr - decodeStartPtr + var stringSegment = decodeString(decodeStartPtr, maxReadBytes) + if (str === undefined) { + str = stringSegment + } else { + str += String.fromCharCode(0) + str += stringSegment + } + decodeStartPtr = currentBytePtr + charSize + } } - if (e) return !0 + _free(value) + return str + }, + toWireType: function (destructors, value) { + if (!(typeof value === 'string')) { + throwBindingError( + 'Cannot pass non-string to C++ string type ' + name + ) + } + var length = lengthBytesUTF(value) + var ptr = _malloc(4 + length + charSize) + HEAPU32[ptr >> 2] = length >> shift + encodeString(value, ptr + 4, length + charSize) + if (destructors !== null) { + destructors.push(_free, ptr) + } + return ptr + }, + argPackAdvance: 8, + readValueFromPointer: simpleReadValueFromPointer, + destructorFunction: function (ptr) { + _free(ptr) + }, + }) + } + function __embind_register_value_object( + rawType, + name, + constructorSignature, + rawConstructor, + destructorSignature, + rawDestructor + ) { + structRegistrations[rawType] = { + name: readLatin1String(name), + rawConstructor: embind__requireFunction( + constructorSignature, + rawConstructor + ), + rawDestructor: embind__requireFunction( + destructorSignature, + rawDestructor + ), + fields: [], + } + } + function __embind_register_value_object_field( + structType, + fieldName, + getterReturnType, + getterSignature, + getter, + getterContext, + setterArgumentType, + setterSignature, + setter, + setterContext + ) { + structRegistrations[structType].fields.push({ + fieldName: readLatin1String(fieldName), + getterReturnType: getterReturnType, + getter: embind__requireFunction(getterSignature, getter), + getterContext: getterContext, + setterArgumentType: setterArgumentType, + setter: embind__requireFunction(setterSignature, setter), + setterContext: setterContext, + }) + } + function __embind_register_void(rawType, name) { + name = readLatin1String(name) + registerType(rawType, { + isVoid: true, + name: name, + argPackAdvance: 0, + fromWireType: function () { + return undefined + }, + toWireType: function (destructors, o) { + return undefined + }, + }) + } + var emval_symbols = {} + function getStringOrSymbol(address) { + var symbol = emval_symbols[address] + if (symbol === undefined) { + return readLatin1String(address) + } else { + return symbol + } + } + function emval_get_global() { + if (typeof globalThis === 'object') { + return globalThis + } + return (function () { + return Function + })()('return this')() + } + function __emval_get_global(name) { + if (name === 0) { + return __emval_register(emval_get_global()) + } else { + name = getStringOrSymbol(name) + return __emval_register(emval_get_global()[name]) + } + } + function __emval_incref(handle) { + if (handle > 4) { + emval_handle_array[handle].refcount += 1 + } + } + function requireRegisteredType(rawType, humanName) { + var impl = registeredTypes[rawType] + if (undefined === impl) { + throwBindingError( + humanName + ' has unknown type ' + getTypeName(rawType) + ) + } + return impl + } + function craftEmvalAllocator(argCount) { + var argsList = '' + for (var i = 0; i < argCount; ++i) { + argsList += (i !== 0 ? ', ' : '') + 'arg' + i + } + var functionBody = + 'return function emval_allocator_' + + argCount + + '(constructor, argTypes, args) {\n' + for (var i = 0; i < argCount; ++i) { + functionBody += + 'var argType' + + i + + " = requireRegisteredType(Module['HEAP32'][(argTypes >>> 2) + " + + i + + '], "parameter ' + + i + + '");\n' + + 'var arg' + + i + + ' = argType' + + i + + '.readValueFromPointer(args);\n' + + 'args += argType' + + i + + "['argPackAdvance'];\n" + } + functionBody += + 'var obj = new constructor(' + + argsList + + ');\n' + + 'return __emval_register(obj);\n' + + '}\n' + return new Function( + 'requireRegisteredType', + 'Module', + '__emval_register', + functionBody + )(requireRegisteredType, Module, __emval_register) + } + var emval_newers = {} + function requireHandle(handle) { + if (!handle) { + throwBindingError('Cannot use deleted val. handle = ' + handle) + } + return emval_handle_array[handle].value + } + function __emval_new(handle, argCount, argTypes, args) { + handle = requireHandle(handle) + var newer = emval_newers[argCount] + if (!newer) { + newer = craftEmvalAllocator(argCount) + emval_newers[argCount] = newer + } + return newer(handle, argTypes, args) + } + function _abort() { + abort() + } + function _emscripten_memcpy_big(dest, src, num) { + HEAPU8.copyWithin(dest, src, src + num) + } + function emscripten_realloc_buffer(size) { + try { + wasmMemory.grow((size - buffer.byteLength + 65535) >>> 16) + updateGlobalBufferAndViews(wasmMemory.buffer) + return 1 + } catch (e) {} + } + function _emscripten_resize_heap(requestedSize) { + var oldSize = HEAPU8.length + requestedSize = requestedSize >>> 0 + var maxHeapSize = 2147483648 + if (requestedSize > maxHeapSize) { + return false + } + for (var cutDown = 1; cutDown <= 4; cutDown *= 2) { + var overGrownHeapSize = oldSize * (1 + 0.2 / cutDown) + overGrownHeapSize = Math.min( + overGrownHeapSize, + requestedSize + 100663296 + ) + var newSize = Math.min( + maxHeapSize, + alignUp(Math.max(requestedSize, overGrownHeapSize), 65536) + ) + var replacement = emscripten_realloc_buffer(newSize) + if (replacement) { + return true + } + } + return false + } + var ENV = {} + function getExecutableName() { + return thisProgram || './this.program' + } + function getEnvStrings() { + if (!getEnvStrings.strings) { + var lang = + ( + (typeof navigator === 'object' && + navigator.languages && + navigator.languages[0]) || + 'C' + ).replace('-', '_') + '.UTF-8' + var env = { + USER: 'web_user', + LOGNAME: 'web_user', + PATH: '/', + PWD: '/', + HOME: '/home/web_user', + LANG: lang, + _: getExecutableName(), + } + for (var x in ENV) { + env[x] = ENV[x] + } + var strings = [] + for (var x in env) { + strings.push(x + '=' + env[x]) + } + getEnvStrings.strings = strings + } + return getEnvStrings.strings + } + var SYSCALLS = { + mappings: {}, + buffers: [null, [], []], + printChar: function (stream, curr) { + var buffer = SYSCALLS.buffers[stream] + if (curr === 0 || curr === 10) { + ;(stream === 1 ? out : err)(UTF8ArrayToString(buffer, 0)) + buffer.length = 0 + } else { + buffer.push(curr) } - return !1 - }, - t: function (a, b) { - var c = 0 - mb().forEach(function (d, e) { - var g = b + c - e = F[(a + 4 * e) >> 2] = g - for (g = 0; g < d.length; ++g) H[e++ >> 0] = d.charCodeAt(g) - H[e >> 0] = 0 - c += d.length + 1 - }) - return 0 }, - u: function (a, b) { - var c = mb() - F[a >> 2] = c.length - var d = 0 - c.forEach(function (e) { - d += e.length + 1 - }) - F[b >> 2] = d - return 0 + varargs: undefined, + get: function () { + SYSCALLS.varargs += 4 + var ret = HEAP32[(SYSCALLS.varargs - 4) >> 2] + return ret }, - A: function (a) { - if (!noExitRuntime) { - if (f.onExit) f.onExit(a) - na = !0 - } - ea(a, new la(a)) + getStr: function (ptr) { + var ret = UTF8ToString(ptr) + return ret }, - w: function () { - return 0 + get64: function (low, high) { + return low }, - q: function () {}, - j: function (a, b, c, d) { - for (var e = 0, g = 0; g < c; g++) { - for ( - var m = F[(b + 8 * g) >> 2], h = F[(b + (8 * g + 4)) >> 2], k = 0; - k < h; - k++ - ) { - var n = B[m + k], - l = ob[a] - if (0 === n || 10 === n) { - n = 1 === a ? ma : v - var p - for (p = 0; l[p] && !(NaN <= p); ) ++p - p = oa.decode( - l.subarray ? l.subarray(0, p) : new Uint8Array(l.slice(0, p)) - ) - n(p) - l.length = 0 - } else l.push(n) - } - e += h + } + function _environ_get(__environ, environ_buf) { + var bufSize = 0 + getEnvStrings().forEach(function (string, i) { + var ptr = environ_buf + bufSize + HEAP32[(__environ + i * 4) >> 2] = ptr + writeAsciiToMemory(string, ptr) + bufSize += string.length + 1 + }) + return 0 + } + function _environ_sizes_get(penviron_count, penviron_buf_size) { + var strings = getEnvStrings() + HEAP32[penviron_count >> 2] = strings.length + var bufSize = 0 + strings.forEach(function (string) { + bufSize += string.length + 1 + }) + HEAP32[penviron_buf_size >> 2] = bufSize + return 0 + } + function _exit(status) { + exit(status) + } + function _fd_close(fd) { + return 0 + } + function _fd_seek(fd, offset_low, offset_high, whence, newOffset) {} + function _fd_write(fd, iov, iovcnt, pnum) { + var num = 0 + for (var i = 0; i < iovcnt; i++) { + var ptr = HEAP32[(iov + i * 8) >> 2] + var len = HEAP32[(iov + (i * 8 + 4)) >> 2] + for (var j = 0; j < len; j++) { + SYSCALLS.printChar(fd, HEAPU8[ptr + j]) } - F[d >> 2] = e - return 0 - }, - a: A, - r: function () {}, - } - ;(function () { - function a(e) { - f.asm = e.exports - J = f.asm.C - K-- - f.monitorRunDependencies && f.monitorRunDependencies(K) - 0 == K && - (null !== Ga && (clearInterval(Ga), (Ga = null)), - L && ((e = L), (L = null), e())) - } - function b(e) { - a(e.instance) - } - function c(e) { - return Promise.resolve() - .then(Ja) - .then(function (g) { - return WebAssembly.instantiate(g, d) - }) - .then(e, function (g) { - v('failed to asynchronously prepare wasm: ' + g) - u(g) - }) + num += len } - var d = { a: tb } - K++ - f.monitorRunDependencies && f.monitorRunDependencies(K) - if (f.instantiateWasm) - try { - return f.instantiateWasm(d, a) - } catch (e) { - return ( - v('Module.instantiateWasm callback failed with error: ' + e), !1 - ) - } - ;(function () { - return w || - 'function' !== typeof WebAssembly.instantiateStreaming || - Ha() || - 'function' !== typeof fetch - ? c(b) - : fetch(M, { credentials: 'same-origin' }).then(function (e) { - return WebAssembly.instantiateStreaming(e, d).then( - b, - function (g) { - v('wasm streaming compile failed: ' + g) - v('falling back to ArrayBuffer instantiation') - return c(b) - } - ) - }) - })().catch(ba) - return {} - })() - var rb = (f.___wasm_call_ctors = function () { - return (rb = f.___wasm_call_ctors = f.asm.D).apply(null, arguments) - }), - sb = (f._malloc = function () { - return (sb = f._malloc = f.asm.E).apply(null, arguments) - }), - Z = (f._free = function () { - return (Z = f._free = f.asm.F).apply(null, arguments) - }), - eb = (f.___getTypeName = function () { - return (eb = f.___getTypeName = f.asm.G).apply(null, arguments) - }) - f.___embind_register_native_and_builtin_types = function () { - return (f.___embind_register_native_and_builtin_types = f.asm.H).apply( + HEAP32[pnum >> 2] = num + return 0 + } + function _setTempRet0(val) { + setTempRet0(val) + } + InternalError = Module['InternalError'] = extendError( + Error, + 'InternalError' + ) + embind_init_charCodes() + BindingError = Module['BindingError'] = extendError(Error, 'BindingError') + init_emval() + UnboundTypeError = Module['UnboundTypeError'] = extendError( + Error, + 'UnboundTypeError' + ) + var asmLibraryArg = { + B: ___cxa_thread_atexit, + l: __embind_finalize_value_object, + p: __embind_register_bigint, + y: __embind_register_bool, + x: __embind_register_emval, + i: __embind_register_float, + f: __embind_register_function, + c: __embind_register_integer, + b: __embind_register_memory_view, + j: __embind_register_std_string, + e: __embind_register_std_wstring, + m: __embind_register_value_object, + a: __embind_register_value_object_field, + z: __embind_register_void, + g: __emval_decref, + u: __emval_get_global, + k: __emval_incref, + n: __emval_new, + h: _abort, + r: _emscripten_memcpy_big, + d: _emscripten_resize_heap, + s: _environ_get, + t: _environ_sizes_get, + A: _exit, + w: _fd_close, + o: _fd_seek, + v: _fd_write, + q: _setTempRet0, + } + var asm = createWasm() + var ___wasm_call_ctors = (Module['___wasm_call_ctors'] = function () { + return (___wasm_call_ctors = Module['___wasm_call_ctors'] = + Module['asm']['D']).apply(null, arguments) + }) + var _malloc = (Module['_malloc'] = function () { + return (_malloc = Module['_malloc'] = Module['asm']['E']).apply( null, arguments ) + }) + var _free = (Module['_free'] = function () { + return (_free = Module['_free'] = Module['asm']['F']).apply( + null, + arguments + ) + }) + var ___getTypeName = (Module['___getTypeName'] = function () { + return (___getTypeName = Module['___getTypeName'] = + Module['asm']['G']).apply(null, arguments) + }) + var ___embind_register_native_and_builtin_types = (Module[ + '___embind_register_native_and_builtin_types' + ] = function () { + return (___embind_register_native_and_builtin_types = Module[ + '___embind_register_native_and_builtin_types' + ] = + Module['asm']['H']).apply(null, arguments) + }) + var dynCall_jiji = (Module['dynCall_jiji'] = function () { + return (dynCall_jiji = Module['dynCall_jiji'] = Module['asm']['J']).apply( + null, + arguments + ) + }) + var calledRun + function ExitStatus(status) { + this.name = 'ExitStatus' + this.message = 'Program terminated with exit(' + status + ')' + this.status = status } - f.dynCall_jiji = function () { - return (f.dynCall_jiji = f.asm.I).apply(null, arguments) + dependenciesFulfilled = function runCaller() { + if (!calledRun) run() + if (!calledRun) dependenciesFulfilled = runCaller } - var ub - function la(a) { - this.name = 'ExitStatus' - this.message = 'Program terminated with exit(' + a + ')' - this.status = a - } - L = function vb() { - ub || wb() - ub || (L = vb) - } - function wb() { - function a() { - if (!ub && ((ub = !0), (f.calledRun = !0), !na)) { - N(Ca) - N(Da) - aa(f) - if (f.onRuntimeInitialized) f.onRuntimeInitialized() - if (f.postRun) - for ( - 'function' == typeof f.postRun && (f.postRun = [f.postRun]); - f.postRun.length; - - ) { - var b = f.postRun.shift() - Ea.unshift(b) - } - N(Ea) - } + function run(args) { + args = args || arguments_ + if (runDependencies > 0) { + return } - if (!(0 < K)) { - if (f.preRun) - for ( - 'function' == typeof f.preRun && (f.preRun = [f.preRun]); - f.preRun.length; - - ) - Fa() - N(Ba) - 0 < K || - (f.setStatus - ? (f.setStatus('Running...'), - setTimeout(function () { - setTimeout(function () { - f.setStatus('') - }, 1) - a() - }, 1)) - : a()) - } - } - f.run = wb - if (f.preInit) - for ( - 'function' == typeof f.preInit && (f.preInit = [f.preInit]); - 0 < f.preInit.length; - - ) - f.preInit.pop()() - noExitRuntime = !0 - wb() + preRun() + if (runDependencies > 0) { + return + } + function doRun() { + if (calledRun) return + calledRun = true + Module['calledRun'] = true + if (ABORT) return + initRuntime() + readyPromiseResolve(Module) + if (Module['onRuntimeInitialized']) Module['onRuntimeInitialized']() + postRun() + } + if (Module['setStatus']) { + Module['setStatus']('Running...') + setTimeout(function () { + setTimeout(function () { + Module['setStatus']('') + }, 1) + doRun() + }, 1) + } else { + doRun() + } + } + Module['run'] = run + function exit(status, implicit) { + EXITSTATUS = status + if (implicit && keepRuntimeAlive() && status === 0) { + return + } + if (keepRuntimeAlive()) { + } else { + exitRuntime() + if (Module['onExit']) Module['onExit'](status) + ABORT = true + } + quit_(status, new ExitStatus(status)) + } + if (Module['preInit']) { + if (typeof Module['preInit'] == 'function') + Module['preInit'] = [Module['preInit']] + while (Module['preInit'].length > 0) { + Module['preInit'].pop()() + } + } + run() return Module.ready } diff --git a/packages/next/server/lib/squoosh/mozjpeg/mozjpeg_node_enc.wasm b/packages/next/server/lib/squoosh/mozjpeg/mozjpeg_node_enc.wasm old mode 100644 new mode 100755 index 6dc8b5b6f0fb0..4dc36264bcfdc Binary files a/packages/next/server/lib/squoosh/mozjpeg/mozjpeg_node_enc.wasm and b/packages/next/server/lib/squoosh/mozjpeg/mozjpeg_node_enc.wasm differ diff --git a/packages/next/server/lib/squoosh/png/squoosh_oxipng.js b/packages/next/server/lib/squoosh/png/squoosh_oxipng.js index f2d8ccb9c99e9..abfb6de7c3572 100644 --- a/packages/next/server/lib/squoosh/png/squoosh_oxipng.js +++ b/packages/next/server/lib/squoosh/png/squoosh_oxipng.js @@ -1,5 +1,3 @@ -import { TextDecoder } from '../text-decoder' - let wasm let cachedTextDecoder = new TextDecoder('utf-8', { @@ -50,40 +48,29 @@ function getArrayU8FromWasm0(ptr, len) { /** * @param {Uint8Array} data * @param {number} level + * @param {boolean} interlace * @returns {Uint8Array} */ -export function optimise(data, level) { +export function optimise(data, level, interlace) { try { - const retptr = wasm.__wbindgen_export_0.value - 16 - wasm.__wbindgen_export_0.value = retptr + const retptr = wasm.__wbindgen_add_to_stack_pointer(-16) var ptr0 = passArray8ToWasm0(data, wasm.__wbindgen_malloc) var len0 = WASM_VECTOR_LEN - wasm.optimise(retptr, ptr0, len0, level) + wasm.optimise(retptr, ptr0, len0, level, interlace) var r0 = getInt32Memory0()[retptr / 4 + 0] var r1 = getInt32Memory0()[retptr / 4 + 1] var v1 = getArrayU8FromWasm0(r0, r1).slice() wasm.__wbindgen_free(r0, r1 * 1) return v1 } finally { - wasm.__wbindgen_export_0.value += 16 + wasm.__wbindgen_add_to_stack_pointer(16) } } async function load(module, imports) { if (typeof Response === 'function' && module instanceof Response) { if (typeof WebAssembly.instantiateStreaming === 'function') { - try { - return await WebAssembly.instantiateStreaming(module, imports) - } catch (e) { - if (module.headers.get('Content-Type') !== 'application/wasm') { - 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 - ) - } else { - throw e - } - } + return await WebAssembly.instantiateStreaming(module, imports) } const bytes = await module.arrayBuffer() @@ -100,10 +87,6 @@ async function load(module, imports) { } async function init(input) { - if (typeof input === 'undefined') { - // input = import.meta.url.replace(/\.js$/, '_bg.wasm') - throw new Error('invariant') - } const imports = {} imports.wbg = {} imports.wbg.__wbindgen_throw = function (arg0, arg1) { diff --git a/packages/next/server/lib/squoosh/png/squoosh_oxipng_bg.wasm b/packages/next/server/lib/squoosh/png/squoosh_oxipng_bg.wasm index 97715f1ad9b9c..92ec1d8960bd1 100644 Binary files a/packages/next/server/lib/squoosh/png/squoosh_oxipng_bg.wasm and b/packages/next/server/lib/squoosh/png/squoosh_oxipng_bg.wasm differ diff --git a/packages/next/server/lib/squoosh/png/squoosh_png.js b/packages/next/server/lib/squoosh/png/squoosh_png.js index 236a005db37ea..4ff8d7b1ab047 100644 --- a/packages/next/server/lib/squoosh/png/squoosh_png.js +++ b/packages/next/server/lib/squoosh/png/squoosh_png.js @@ -1,5 +1,3 @@ -import { TextDecoder } from '../text-decoder' - let wasm let cachedTextDecoder = new TextDecoder('utf-8', { @@ -85,8 +83,7 @@ function getArrayU8FromWasm0(ptr, len) { */ export function encode(data, width, height) { try { - const retptr = wasm.__wbindgen_export_1.value - 16 - wasm.__wbindgen_export_1.value = retptr + const retptr = wasm.__wbindgen_add_to_stack_pointer(-16) var ptr0 = passArray8ToWasm0(data, wasm.__wbindgen_malloc) var len0 = WASM_VECTOR_LEN wasm.encode(retptr, ptr0, len0, width, height) @@ -96,7 +93,7 @@ export function encode(data, width, height) { wasm.__wbindgen_free(r0, r1 * 1) return v1 } finally { - wasm.__wbindgen_export_1.value += 16 + wasm.__wbindgen_add_to_stack_pointer(16) } } @@ -129,18 +126,7 @@ export function decode(data) { async function load(module, imports) { if (typeof Response === 'function' && module instanceof Response) { if (typeof WebAssembly.instantiateStreaming === 'function') { - try { - return await WebAssembly.instantiateStreaming(module, imports) - } catch (e) { - if (module.headers.get('Content-Type') !== 'application/wasm') { - 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 - ) - } else { - throw e - } - } + return await WebAssembly.instantiateStreaming(module, imports) } const bytes = await module.arrayBuffer() @@ -157,10 +143,6 @@ async function load(module, imports) { } async function init(input) { - if (typeof input === 'undefined') { - // input = import.meta.url.replace(/\.js$/, '_bg.wasm') - throw new Error('invariant') - } const imports = {} imports.wbg = {} imports.wbg.__wbg_newwithownedu8clampedarrayandsh_787b2db8ea6bfd62 = @@ -173,6 +155,7 @@ async function init(input) { imports.wbg.__wbindgen_throw = function (arg0, arg1) { throw new Error(getStringFromWasm0(arg0, arg1)) } + if ( typeof input === 'string' || (typeof Request === 'function' && input instanceof Request) || diff --git a/packages/next/server/lib/squoosh/png/squoosh_png_bg.wasm b/packages/next/server/lib/squoosh/png/squoosh_png_bg.wasm index ef074fafe8b10..cc5cf3660e097 100644 Binary files a/packages/next/server/lib/squoosh/png/squoosh_png_bg.wasm and b/packages/next/server/lib/squoosh/png/squoosh_png_bg.wasm differ diff --git a/packages/next/server/lib/squoosh/resize/squoosh_resize.js b/packages/next/server/lib/squoosh/resize/squoosh_resize.js index f9553f3bd6b5a..20510a245b1fb 100644 --- a/packages/next/server/lib/squoosh/resize/squoosh_resize.js +++ b/packages/next/server/lib/squoosh/resize/squoosh_resize.js @@ -31,8 +31,19 @@ function getInt32Memory0() { return cachegetInt32Memory0 } -function getArrayU8FromWasm0(ptr, len) { - return getUint8Memory0().subarray(ptr / 1, ptr / 1 + len) +let cachegetUint8ClampedMemory0 = null +function getUint8ClampedMemory0() { + if ( + cachegetUint8ClampedMemory0 === null || + cachegetUint8ClampedMemory0.buffer !== wasm.memory.buffer + ) { + cachegetUint8ClampedMemory0 = new Uint8ClampedArray(wasm.memory.buffer) + } + return cachegetUint8ClampedMemory0 +} + +function getClampedArrayU8FromWasm0(ptr, len) { + return getUint8ClampedMemory0().subarray(ptr / 1, ptr / 1 + len) } /** * @param {Uint8Array} input_image @@ -43,7 +54,7 @@ function getArrayU8FromWasm0(ptr, len) { * @param {number} typ_idx * @param {boolean} premultiply * @param {boolean} color_space_conversion - * @returns {Uint8Array} + * @returns {Uint8ClampedArray} */ export function resize( input_image, @@ -55,42 +66,36 @@ export function resize( premultiply, color_space_conversion ) { - var ptr0 = passArray8ToWasm0(input_image, wasm.__wbindgen_malloc) - var len0 = WASM_VECTOR_LEN - wasm.resize( - 8, - ptr0, - len0, - input_width, - input_height, - output_width, - output_height, - typ_idx, - premultiply, - color_space_conversion - ) - var r0 = getInt32Memory0()[8 / 4 + 0] - var r1 = getInt32Memory0()[8 / 4 + 1] - var v1 = getArrayU8FromWasm0(r0, r1).slice() - wasm.__wbindgen_free(r0, r1 * 1) - return v1 + try { + const retptr = wasm.__wbindgen_add_to_stack_pointer(-16) + var ptr0 = passArray8ToWasm0(input_image, wasm.__wbindgen_malloc) + var len0 = WASM_VECTOR_LEN + wasm.resize( + retptr, + ptr0, + len0, + input_width, + input_height, + output_width, + output_height, + typ_idx, + premultiply, + color_space_conversion + ) + var r0 = getInt32Memory0()[retptr / 4 + 0] + var r1 = getInt32Memory0()[retptr / 4 + 1] + var v1 = getClampedArrayU8FromWasm0(r0, r1).slice() + wasm.__wbindgen_free(r0, r1 * 1) + return v1 + } finally { + wasm.__wbindgen_add_to_stack_pointer(16) + } } async function load(module, imports) { if (typeof Response === 'function' && module instanceof Response) { if (typeof WebAssembly.instantiateStreaming === 'function') { - try { - return await WebAssembly.instantiateStreaming(module, imports) - } catch (e) { - if (module.headers.get('Content-Type') !== 'application/wasm') { - 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 - ) - } else { - throw e - } - } + return await WebAssembly.instantiateStreaming(module, imports) } const bytes = await module.arrayBuffer() @@ -107,10 +112,6 @@ async function load(module, imports) { } async function init(input) { - if (typeof input === 'undefined') { - // input = import.meta.url.replace(/\.js$/, '_bg.wasm') - throw new Error('invariant') - } const imports = {} if ( diff --git a/packages/next/server/lib/squoosh/resize/squoosh_resize_bg.wasm b/packages/next/server/lib/squoosh/resize/squoosh_resize_bg.wasm index 0a10cca382dcc..b910c97b050df 100644 Binary files a/packages/next/server/lib/squoosh/resize/squoosh_resize_bg.wasm and b/packages/next/server/lib/squoosh/resize/squoosh_resize_bg.wasm differ diff --git a/packages/next/server/lib/squoosh/rotate/rotate.wasm b/packages/next/server/lib/squoosh/rotate/rotate.wasm old mode 100644 new mode 100755 diff --git a/packages/next/server/lib/squoosh/text-decoder.ts b/packages/next/server/lib/squoosh/text-decoder.ts deleted file mode 100644 index 397791f66e582..0000000000000 --- a/packages/next/server/lib/squoosh/text-decoder.ts +++ /dev/null @@ -1,4 +0,0 @@ -const textDecoder = - typeof TextDecoder !== 'undefined' ? TextDecoder : require('util').TextDecoder - -export { textDecoder as TextDecoder } diff --git a/packages/next/server/lib/squoosh/webp/webp_enc.d.ts b/packages/next/server/lib/squoosh/webp/webp_enc.d.ts new file mode 100644 index 0000000000000..3c45068299a1f --- /dev/null +++ b/packages/next/server/lib/squoosh/webp/webp_enc.d.ts @@ -0,0 +1,42 @@ +export interface EncodeOptions { + quality: number + target_size: number + target_PSNR: number + method: number + sns_strength: number + filter_strength: number + filter_sharpness: number + filter_type: number + partitions: number + segments: number + pass: number + show_compressed: number + preprocessing: number + autofilter: number + partition_limit: number + alpha_compression: number + alpha_filtering: number + alpha_quality: number + lossless: number + exact: number + image_hint: number + emulate_jpeg_size: number + thread_level: number + low_memory: number + near_lossless: number + use_delta_palette: number + use_sharp_yuv: number +} + +export interface WebPModule extends EmscriptenWasm.Module { + encode( + data: BufferSource, + width: number, + height: number, + options: EncodeOptions + ): Uint8Array +} + +declare var moduleFactory: EmscriptenWasm.ModuleFactory + +export default moduleFactory diff --git a/packages/next/server/lib/squoosh/webp/webp_node_dec.js b/packages/next/server/lib/squoosh/webp/webp_node_dec.js index d5772445f7869..2968ece180b2c 100644 --- a/packages/next/server/lib/squoosh/webp/webp_node_dec.js +++ b/packages/next/server/lib/squoosh/webp/webp_node_dec.js @@ -1,225 +1,478 @@ /* eslint-disable */ -import { TextDecoder } from '../text-decoder' - var Module = (function () { - // var _scriptDir = import.meta.url - return function (Module) { Module = Module || {} - var e - e || (e = typeof Module !== 'undefined' ? Module : {}) - var aa, r - e.ready = new Promise(function (a, b) { - aa = a - r = b + var Module = typeof Module !== 'undefined' ? Module : {} + var readyPromiseResolve, readyPromiseReject + Module['ready'] = new Promise(function (resolve, reject) { + readyPromiseResolve = resolve + readyPromiseReject = reject }) - var t = {}, - u - for (u in e) e.hasOwnProperty(u) && (t[u] = e[u]) - var v = '', - ba, - ca, - da, - ea - v = __dirname + '/' - ba = function (a) { - da || (da = require('fs')) - ea || (ea = require('path')) - a = ea.normalize(a) - return da.readFileSync(a, null) - } - ca = function (a) { - a = ba(a) - a.buffer || (a = new Uint8Array(a)) - a.buffer || x('Assertion failed: undefined') - return a - } - e.inspect = function () { - return '[Emscripten Module object]' - } - e.print || console.log.bind(console) - var y = e.printErr || console.warn.bind(console) - for (u in t) t.hasOwnProperty(u) && (e[u] = t[u]) - t = null - var z - e.wasmBinary && (z = e.wasmBinary) - var noExitRuntime - e.noExitRuntime && (noExitRuntime = e.noExitRuntime) - 'object' !== typeof WebAssembly && x('no native wasm support detected') - var B, - fa = !1, - ha = new TextDecoder('utf8') - function ia(a, b, c) { - var d = C - if (0 < c) { - c = b + c - 1 - for (var f = 0; f < a.length; ++f) { - var g = a.charCodeAt(f) - if (55296 <= g && 57343 >= g) { - var l = a.charCodeAt(++f) - g = (65536 + ((g & 1023) << 10)) | (l & 1023) - } - if (127 >= g) { - if (b >= c) break - d[b++] = g - } else { - if (2047 >= g) { - if (b + 1 >= c) break - d[b++] = 192 | (g >> 6) - } else { - if (65535 >= g) { - if (b + 2 >= c) break - d[b++] = 224 | (g >> 12) - } else { - if (b + 3 >= c) break - d[b++] = 240 | (g >> 18) - d[b++] = 128 | ((g >> 12) & 63) - } - d[b++] = 128 | ((g >> 6) & 63) - } - d[b++] = 128 | (g & 63) - } + var moduleOverrides = {} + var key + for (key in Module) { + if (Module.hasOwnProperty(key)) { + moduleOverrides[key] = Module[key] + } + } + var arguments_ = [] + var thisProgram = './this.program' + var quit_ = function (status, toThrow) { + throw toThrow + } + var ENVIRONMENT_IS_WEB = false + var ENVIRONMENT_IS_WORKER = false + var ENVIRONMENT_IS_NODE = true + var scriptDirectory = '' + function locateFile(path) { + if (Module['locateFile']) { + return Module['locateFile'](path, scriptDirectory) + } + return scriptDirectory + path + } + var read_, readBinary + var nodeFS + var nodePath + if (ENVIRONMENT_IS_NODE) { + if (ENVIRONMENT_IS_WORKER) { + scriptDirectory = require('path').dirname(scriptDirectory) + '/' + } else { + scriptDirectory = __dirname + '/' + } + read_ = function shell_read(filename, binary) { + if (!nodeFS) nodeFS = require('fs') + if (!nodePath) nodePath = require('path') + filename = nodePath['normalize'](filename) + return nodeFS['readFileSync'](filename, binary ? null : 'utf8') + } + readBinary = function readBinary(filename) { + var ret = read_(filename, true) + if (!ret.buffer) { + ret = new Uint8Array(ret) } - d[b] = 0 - } - } - var ja = new TextDecoder('utf-16le') - function ka(a, b) { - var c = a >> 1 - for (b = c + b / 2; !(c >= b) && D[c]; ) ++c - return ja.decode(C.subarray(a, c << 1)) - } - function la(a, b, c) { - void 0 === c && (c = 2147483647) - if (2 > c) return 0 - c -= 2 - var d = b - c = c < 2 * a.length ? c / 2 : a.length - for (var f = 0; f < c; ++f) (E[b >> 1] = a.charCodeAt(f)), (b += 2) - E[b >> 1] = 0 - return b - d - } - function ma(a) { - return 2 * a.length - } - function na(a, b) { - for (var c = 0, d = ''; !(c >= b / 4); ) { - var f = F[(a + 4 * c) >> 2] - if (0 == f) break - ++c - 65536 <= f - ? ((f -= 65536), - (d += String.fromCharCode(55296 | (f >> 10), 56320 | (f & 1023)))) - : (d += String.fromCharCode(f)) - } - return d - } - function oa(a, b, c) { - void 0 === c && (c = 2147483647) - if (4 > c) return 0 - var d = b - c = d + c - 4 - for (var f = 0; f < a.length; ++f) { - var g = a.charCodeAt(f) - if (55296 <= g && 57343 >= g) { - var l = a.charCodeAt(++f) - g = (65536 + ((g & 1023) << 10)) | (l & 1023) + assert(ret.buffer) + return ret + } + if (process['argv'].length > 1) { + thisProgram = process['argv'][1].replace(/\\/g, '/') + } + arguments_ = process['argv'].slice(2) + quit_ = function (status) { + process['exit'](status) + } + Module['inspect'] = function () { + return '[Emscripten Module object]' + } + } else { + } + var out = Module['print'] || console.log.bind(console) + var err = Module['printErr'] || console.warn.bind(console) + for (key in moduleOverrides) { + if (moduleOverrides.hasOwnProperty(key)) { + Module[key] = moduleOverrides[key] + } + } + moduleOverrides = null + if (Module['arguments']) arguments_ = Module['arguments'] + if (Module['thisProgram']) thisProgram = Module['thisProgram'] + if (Module['quit']) quit_ = Module['quit'] + var wasmBinary + if (Module['wasmBinary']) wasmBinary = Module['wasmBinary'] + var noExitRuntime = Module['noExitRuntime'] || true + if (typeof WebAssembly !== 'object') { + abort('no native wasm support detected') + } + var wasmMemory + var ABORT = false + var EXITSTATUS + function assert(condition, text) { + if (!condition) { + abort('Assertion failed: ' + text) + } + } + var UTF8Decoder = new TextDecoder('utf8') + function UTF8ToString(ptr, maxBytesToRead) { + if (!ptr) return '' + var maxPtr = ptr + maxBytesToRead + for (var end = ptr; !(end >= maxPtr) && HEAPU8[end]; ) ++end + return UTF8Decoder.decode(HEAPU8.subarray(ptr, end)) + } + function stringToUTF8Array(str, heap, outIdx, maxBytesToWrite) { + if (!(maxBytesToWrite > 0)) return 0 + var startIdx = outIdx + var endIdx = outIdx + maxBytesToWrite - 1 + for (var i = 0; i < str.length; ++i) { + var u = str.charCodeAt(i) + if (u >= 55296 && u <= 57343) { + var u1 = str.charCodeAt(++i) + u = (65536 + ((u & 1023) << 10)) | (u1 & 1023) } - F[b >> 2] = g - b += 4 - if (b + 4 > c) break - } - F[b >> 2] = 0 - return b - d - } - function pa(a) { - for (var b = 0, c = 0; c < a.length; ++c) { - var d = a.charCodeAt(c) - 55296 <= d && 57343 >= d && ++c - b += 4 - } - return b - } - var G, qa, C, E, D, F, I, ra, sa - function ta(a) { - G = a - e.HEAP8 = qa = new Int8Array(a) - e.HEAP16 = E = new Int16Array(a) - e.HEAP32 = F = new Int32Array(a) - e.HEAPU8 = C = new Uint8Array(a) - e.HEAPU16 = D = new Uint16Array(a) - e.HEAPU32 = I = new Uint32Array(a) - e.HEAPF32 = ra = new Float32Array(a) - e.HEAPF64 = sa = new Float64Array(a) - } - var ua = e.INITIAL_MEMORY || 16777216 - e.wasmMemory - ? (B = e.wasmMemory) - : (B = new WebAssembly.Memory({ initial: ua / 65536, maximum: 32768 })) - B && (G = B.buffer) - ua = G.byteLength - ta(G) - var J, - va = [], - wa = [], - xa = [], - ya = [] - function za() { - var a = e.preRun.shift() - va.unshift(a) - } - var L = 0, - Aa = null, - M = null - e.preloadedImages = {} - e.preloadedAudios = {} - function x(a) { - if (e.onAbort) e.onAbort(a) - y(a) - fa = !0 - a = new WebAssembly.RuntimeError( - 'abort(' + a + '). Build with -s ASSERTIONS=1 for more info.' - ) - r(a) - throw a + if (u <= 127) { + if (outIdx >= endIdx) break + heap[outIdx++] = u + } else if (u <= 2047) { + if (outIdx + 1 >= endIdx) break + heap[outIdx++] = 192 | (u >> 6) + heap[outIdx++] = 128 | (u & 63) + } else if (u <= 65535) { + if (outIdx + 2 >= endIdx) break + heap[outIdx++] = 224 | (u >> 12) + heap[outIdx++] = 128 | ((u >> 6) & 63) + heap[outIdx++] = 128 | (u & 63) + } else { + if (outIdx + 3 >= endIdx) break + heap[outIdx++] = 240 | (u >> 18) + heap[outIdx++] = 128 | ((u >> 12) & 63) + heap[outIdx++] = 128 | ((u >> 6) & 63) + heap[outIdx++] = 128 | (u & 63) + } + } + heap[outIdx] = 0 + return outIdx - startIdx } - function Ba() { - var a = N - return String.prototype.startsWith - ? a.startsWith('data:application/octet-stream;base64,') - : 0 === a.indexOf('data:application/octet-stream;base64,') + function stringToUTF8(str, outPtr, maxBytesToWrite) { + return stringToUTF8Array(str, HEAPU8, outPtr, maxBytesToWrite) } - var N = 'webp_node_dec.wasm' - if (!Ba()) { - var Ca = N - N = e.locateFile ? e.locateFile(Ca, v) : v + Ca + function lengthBytesUTF8(str) { + var len = 0 + for (var i = 0; i < str.length; ++i) { + var u = str.charCodeAt(i) + if (u >= 55296 && u <= 57343) + u = (65536 + ((u & 1023) << 10)) | (str.charCodeAt(++i) & 1023) + if (u <= 127) ++len + else if (u <= 2047) len += 2 + else if (u <= 65535) len += 3 + else len += 4 + } + return len + } + var UTF16Decoder = new TextDecoder('utf-16le') + function UTF16ToString(ptr, maxBytesToRead) { + var endPtr = ptr + var idx = endPtr >> 1 + var maxIdx = idx + maxBytesToRead / 2 + while (!(idx >= maxIdx) && HEAPU16[idx]) ++idx + endPtr = idx << 1 + return UTF16Decoder.decode(HEAPU8.subarray(ptr, endPtr)) + var str = '' + for (var i = 0; !(i >= maxBytesToRead / 2); ++i) { + var codeUnit = HEAP16[(ptr + i * 2) >> 1] + if (codeUnit == 0) break + str += String.fromCharCode(codeUnit) + } + return str } - function Da() { + function stringToUTF16(str, outPtr, maxBytesToWrite) { + if (maxBytesToWrite === undefined) { + maxBytesToWrite = 2147483647 + } + if (maxBytesToWrite < 2) return 0 + maxBytesToWrite -= 2 + var startPtr = outPtr + var numCharsToWrite = + maxBytesToWrite < str.length * 2 ? maxBytesToWrite / 2 : str.length + for (var i = 0; i < numCharsToWrite; ++i) { + var codeUnit = str.charCodeAt(i) + HEAP16[outPtr >> 1] = codeUnit + outPtr += 2 + } + HEAP16[outPtr >> 1] = 0 + return outPtr - startPtr + } + function lengthBytesUTF16(str) { + return str.length * 2 + } + function UTF32ToString(ptr, maxBytesToRead) { + var i = 0 + var str = '' + while (!(i >= maxBytesToRead / 4)) { + var utf32 = HEAP32[(ptr + i * 4) >> 2] + if (utf32 == 0) break + ++i + if (utf32 >= 65536) { + var ch = utf32 - 65536 + str += String.fromCharCode(55296 | (ch >> 10), 56320 | (ch & 1023)) + } else { + str += String.fromCharCode(utf32) + } + } + return str + } + function stringToUTF32(str, outPtr, maxBytesToWrite) { + if (maxBytesToWrite === undefined) { + maxBytesToWrite = 2147483647 + } + if (maxBytesToWrite < 4) return 0 + var startPtr = outPtr + var endPtr = startPtr + maxBytesToWrite - 4 + for (var i = 0; i < str.length; ++i) { + var codeUnit = str.charCodeAt(i) + if (codeUnit >= 55296 && codeUnit <= 57343) { + var trailSurrogate = str.charCodeAt(++i) + codeUnit = + (65536 + ((codeUnit & 1023) << 10)) | (trailSurrogate & 1023) + } + HEAP32[outPtr >> 2] = codeUnit + outPtr += 4 + if (outPtr + 4 > endPtr) break + } + HEAP32[outPtr >> 2] = 0 + return outPtr - startPtr + } + function lengthBytesUTF32(str) { + var len = 0 + for (var i = 0; i < str.length; ++i) { + var codeUnit = str.charCodeAt(i) + if (codeUnit >= 55296 && codeUnit <= 57343) ++i + len += 4 + } + return len + } + function alignUp(x, multiple) { + if (x % multiple > 0) { + x += multiple - (x % multiple) + } + return x + } + var buffer, + HEAP8, + HEAPU8, + HEAP16, + HEAPU16, + HEAP32, + HEAPU32, + HEAPF32, + HEAPF64 + function updateGlobalBufferAndViews(buf) { + buffer = buf + Module['HEAP8'] = HEAP8 = new Int8Array(buf) + Module['HEAP16'] = HEAP16 = new Int16Array(buf) + Module['HEAP32'] = HEAP32 = new Int32Array(buf) + Module['HEAPU8'] = HEAPU8 = new Uint8Array(buf) + Module['HEAPU16'] = HEAPU16 = new Uint16Array(buf) + Module['HEAPU32'] = HEAPU32 = new Uint32Array(buf) + Module['HEAPF32'] = HEAPF32 = new Float32Array(buf) + Module['HEAPF64'] = HEAPF64 = new Float64Array(buf) + } + var INITIAL_MEMORY = Module['INITIAL_MEMORY'] || 16777216 + var wasmTable + var __ATPRERUN__ = [] + var __ATINIT__ = [] + var __ATPOSTRUN__ = [] + var runtimeInitialized = false + function preRun() { + if (Module['preRun']) { + if (typeof Module['preRun'] == 'function') + Module['preRun'] = [Module['preRun']] + while (Module['preRun'].length) { + addOnPreRun(Module['preRun'].shift()) + } + } + callRuntimeCallbacks(__ATPRERUN__) + } + function initRuntime() { + runtimeInitialized = true + callRuntimeCallbacks(__ATINIT__) + } + function postRun() { + if (Module['postRun']) { + if (typeof Module['postRun'] == 'function') + Module['postRun'] = [Module['postRun']] + while (Module['postRun'].length) { + addOnPostRun(Module['postRun'].shift()) + } + } + callRuntimeCallbacks(__ATPOSTRUN__) + } + function addOnPreRun(cb) { + __ATPRERUN__.unshift(cb) + } + function addOnInit(cb) { + __ATINIT__.unshift(cb) + } + function addOnPostRun(cb) { + __ATPOSTRUN__.unshift(cb) + } + var runDependencies = 0 + var runDependencyWatcher = null + var dependenciesFulfilled = null + function addRunDependency(id) { + runDependencies++ + if (Module['monitorRunDependencies']) { + Module['monitorRunDependencies'](runDependencies) + } + } + function removeRunDependency(id) { + runDependencies-- + if (Module['monitorRunDependencies']) { + Module['monitorRunDependencies'](runDependencies) + } + if (runDependencies == 0) { + if (runDependencyWatcher !== null) { + clearInterval(runDependencyWatcher) + runDependencyWatcher = null + } + if (dependenciesFulfilled) { + var callback = dependenciesFulfilled + dependenciesFulfilled = null + callback() + } + } + } + Module['preloadedImages'] = {} + Module['preloadedAudios'] = {} + function abort(what) { + if (Module['onAbort']) { + Module['onAbort'](what) + } + what += '' + err(what) + ABORT = true + EXITSTATUS = 1 + what = 'abort(' + what + '). Build with -s ASSERTIONS=1 for more info.' + var e = new WebAssembly.RuntimeError(what) + readyPromiseReject(e) + throw e + } + var dataURIPrefix = 'data:application/octet-stream;base64,' + function isDataURI(filename) { + return filename.startsWith(dataURIPrefix) + } + if (Module['locateFile']) { + var wasmBinaryFile = 'webp_node_dec.wasm' + if (!isDataURI(wasmBinaryFile)) { + wasmBinaryFile = locateFile(wasmBinaryFile) + } + } else { + throw new Error('invariant') + } + function getBinary(file) { try { - if (z) return new Uint8Array(z) - if (ca) return ca(N) - throw 'both async and sync fetching of the wasm failed' - } catch (a) { - x(a) - } - } - function O(a) { - for (; 0 < a.length; ) { - var b = a.shift() - if ('function' == typeof b) b(e) - else { - var c = b.G - 'number' === typeof c - ? void 0 === b.C - ? J.get(c)() - : J.get(c)(b.C) - : c(void 0 === b.C ? null : b.C) + if (file == wasmBinaryFile && wasmBinary) { + return new Uint8Array(wasmBinary) + } + if (readBinary) { + return readBinary(file) + } else { + throw 'both async and sync fetching of the wasm failed' + } + } catch (err) { + abort(err) + } + } + function getBinaryPromise() { + if (!wasmBinary && (ENVIRONMENT_IS_WEB || ENVIRONMENT_IS_WORKER)) { + if (typeof fetch === 'function') { + return fetch(wasmBinaryFile, { credentials: 'same-origin' }) + .then(function (response) { + if (!response['ok']) { + throw ( + "failed to load wasm binary file at '" + wasmBinaryFile + "'" + ) + } + return response['arrayBuffer']() + }) + .catch(function () { + return getBinary(wasmBinaryFile) + }) + } + } + return Promise.resolve().then(function () { + return getBinary(wasmBinaryFile) + }) + } + function createWasm() { + var info = { a: asmLibraryArg } + function receiveInstance(instance, module) { + var exports = instance.exports + Module['asm'] = exports + wasmMemory = Module['asm']['s'] + updateGlobalBufferAndViews(wasmMemory.buffer) + wasmTable = Module['asm']['y'] + addOnInit(Module['asm']['t']) + removeRunDependency('wasm-instantiate') + } + addRunDependency('wasm-instantiate') + function receiveInstantiationResult(result) { + receiveInstance(result['instance']) + } + function instantiateArrayBuffer(receiver) { + return getBinaryPromise() + .then(function (binary) { + var result = WebAssembly.instantiate(binary, info) + return result + }) + .then(receiver, function (reason) { + err('failed to asynchronously prepare wasm: ' + reason) + abort(reason) + }) + } + function instantiateAsync() { + if ( + !wasmBinary && + typeof WebAssembly.instantiateStreaming === 'function' && + !isDataURI(wasmBinaryFile) && + typeof fetch === 'function' + ) { + return fetch(wasmBinaryFile, { credentials: 'same-origin' }).then( + function (response) { + var result = WebAssembly.instantiateStreaming(response, info) + return result.then(receiveInstantiationResult, function (reason) { + err('wasm streaming compile failed: ' + reason) + err('falling back to ArrayBuffer instantiation') + return instantiateArrayBuffer(receiveInstantiationResult) + }) + } + ) + } else { + return instantiateArrayBuffer(receiveInstantiationResult) + } + } + if (Module['instantiateWasm']) { + try { + var exports = Module['instantiateWasm'](info, receiveInstance) + return exports + } catch (e) { + err('Module.instantiateWasm callback failed with error: ' + e) + return false + } + } + instantiateAsync().catch(readyPromiseReject) + return {} + } + function callRuntimeCallbacks(callbacks) { + while (callbacks.length > 0) { + var callback = callbacks.shift() + if (typeof callback == 'function') { + callback(Module) + continue + } + var func = callback.func + if (typeof func === 'number') { + if (callback.arg === undefined) { + wasmTable.get(func)() + } else { + wasmTable.get(func)(callback.arg) + } + } else { + func(callback.arg === undefined ? null : callback.arg) } } } - function Ea(a) { - switch (a) { + function _atexit(func, arg) {} + function ___cxa_thread_atexit(a0, a1) { + return _atexit(a0, a1) + } + function __embind_register_bigint( + primitiveType, + name, + size, + minRange, + maxRange + ) {} + function getShiftFromSize(size) { + switch (size) { case 1: return 0 case 2: @@ -229,877 +482,1160 @@ var Module = (function () { case 8: return 3 default: - throw new TypeError('Unknown type size: ' + a) + throw new TypeError('Unknown type size: ' + size) } } - var Fa = void 0 - function P(a) { - for (var b = ''; C[a]; ) b += Fa[C[a++]] - return b + function embind_init_charCodes() { + var codes = new Array(256) + for (var i = 0; i < 256; ++i) { + codes[i] = String.fromCharCode(i) + } + embind_charCodes = codes } - var Q = {}, - R = {}, - S = {} - function Ga(a) { - if (void 0 === a) return '_unknown' - a = a.replace(/[^a-zA-Z0-9_]/g, '$') - var b = a.charCodeAt(0) - return 48 <= b && 57 >= b ? '_' + a : a + var embind_charCodes = undefined + function readLatin1String(ptr) { + var ret = '' + var c = ptr + while (HEAPU8[c]) { + ret += embind_charCodes[HEAPU8[c++]] + } + return ret } - function Ha(a, b) { - a = Ga(a) + var awaitingDependencies = {} + var registeredTypes = {} + var typeDependencies = {} + var char_0 = 48 + var char_9 = 57 + function makeLegalFunctionName(name) { + if (undefined === name) { + return '_unknown' + } + name = name.replace(/[^a-zA-Z0-9_]/g, '$') + var f = name.charCodeAt(0) + if (f >= char_0 && f <= char_9) { + return '_' + name + } else { + return name + } + } + function createNamedFunction(name, body) { + name = makeLegalFunctionName(name) return new Function( 'body', 'return function ' + - a + - '() {\n "use strict"; return body.apply(this, arguments);\n};\n' - )(b) - } - function Ia(a) { - var b = Error, - c = Ha(a, function (d) { - this.name = a - this.message = d - d = Error(d).stack - void 0 !== d && - (this.stack = - this.toString() + '\n' + d.replace(/^Error(:[^\n]*)?\n/, '')) - }) - c.prototype = Object.create(b.prototype) - c.prototype.constructor = c - c.prototype.toString = function () { - return void 0 === this.message - ? this.name - : this.name + ': ' + this.message - } - return c - } - var Ja = void 0 - function T(a) { - throw new Ja(a) - } - var Ka = void 0 - function La(a, b) { - function c(h) { - h = b(h) - if (h.length !== d.length) - throw new Ka('Mismatched type converter count') - for (var k = 0; k < d.length; ++k) U(d[k], h[k]) - } - var d = [] - d.forEach(function (h) { - S[h] = a + name + + '() {\n' + + ' "use strict";' + + ' return body.apply(this, arguments);\n' + + '};\n' + )(body) + } + function extendError(baseErrorType, errorName) { + var errorClass = createNamedFunction(errorName, function (message) { + this.name = errorName + this.message = message + var stack = new Error(message).stack + if (stack !== undefined) { + this.stack = + this.toString() + '\n' + stack.replace(/^Error(:[^\n]*)?\n/, '') + } }) - var f = Array(a.length), - g = [], - l = 0 - a.forEach(function (h, k) { - R.hasOwnProperty(h) - ? (f[k] = R[h]) - : (g.push(h), - Q.hasOwnProperty(h) || (Q[h] = []), - Q[h].push(function () { - f[k] = R[h] - ++l - l === g.length && c(f) - })) + errorClass.prototype = Object.create(baseErrorType.prototype) + errorClass.prototype.constructor = errorClass + errorClass.prototype.toString = function () { + if (this.message === undefined) { + return this.name + } else { + return this.name + ': ' + this.message + } + } + return errorClass + } + var BindingError = undefined + function throwBindingError(message) { + throw new BindingError(message) + } + var InternalError = undefined + function throwInternalError(message) { + throw new InternalError(message) + } + function whenDependentTypesAreResolved( + myTypes, + dependentTypes, + getTypeConverters + ) { + myTypes.forEach(function (type) { + typeDependencies[type] = dependentTypes }) - 0 === g.length && c(f) + function onComplete(typeConverters) { + var myTypeConverters = getTypeConverters(typeConverters) + if (myTypeConverters.length !== myTypes.length) { + throwInternalError('Mismatched type converter count') + } + for (var i = 0; i < myTypes.length; ++i) { + registerType(myTypes[i], myTypeConverters[i]) + } + } + var typeConverters = new Array(dependentTypes.length) + var unregisteredTypes = [] + var registered = 0 + dependentTypes.forEach(function (dt, i) { + if (registeredTypes.hasOwnProperty(dt)) { + typeConverters[i] = registeredTypes[dt] + } else { + unregisteredTypes.push(dt) + if (!awaitingDependencies.hasOwnProperty(dt)) { + awaitingDependencies[dt] = [] + } + awaitingDependencies[dt].push(function () { + typeConverters[i] = registeredTypes[dt] + ++registered + if (registered === unregisteredTypes.length) { + onComplete(typeConverters) + } + }) + } + }) + if (0 === unregisteredTypes.length) { + onComplete(typeConverters) + } } - function U(a, b, c) { - c = c || {} - if (!('argPackAdvance' in b)) + function registerType(rawType, registeredInstance, options) { + options = options || {} + if (!('argPackAdvance' in registeredInstance)) { throw new TypeError( 'registerType registeredInstance requires argPackAdvance' ) - var d = b.name - a || T('type "' + d + '" must have a positive integer typeid pointer') - if (R.hasOwnProperty(a)) { - if (c.H) return - T("Cannot register type '" + d + "' twice") - } - R[a] = b - delete S[a] - Q.hasOwnProperty(a) && - ((b = Q[a]), - delete Q[a], - b.forEach(function (f) { - f() - })) - } - var Oa = [], - V = [{}, { value: void 0 }, { value: null }, { value: !0 }, { value: !1 }] - function Pa(a) { - 4 < a && 0 === --V[a].D && ((V[a] = void 0), Oa.push(a)) - } - function W(a) { - switch (a) { - case void 0: + } + var name = registeredInstance.name + if (!rawType) { + throwBindingError( + 'type "' + name + '" must have a positive integer typeid pointer' + ) + } + if (registeredTypes.hasOwnProperty(rawType)) { + if (options.ignoreDuplicateRegistrations) { + return + } else { + throwBindingError("Cannot register type '" + name + "' twice") + } + } + registeredTypes[rawType] = registeredInstance + delete typeDependencies[rawType] + if (awaitingDependencies.hasOwnProperty(rawType)) { + var callbacks = awaitingDependencies[rawType] + delete awaitingDependencies[rawType] + callbacks.forEach(function (cb) { + cb() + }) + } + } + function __embind_register_bool( + rawType, + name, + size, + trueValue, + falseValue + ) { + var shift = getShiftFromSize(size) + name = readLatin1String(name) + registerType(rawType, { + name: name, + fromWireType: function (wt) { + return !!wt + }, + toWireType: function (destructors, o) { + return o ? trueValue : falseValue + }, + argPackAdvance: 8, + readValueFromPointer: function (pointer) { + var heap + if (size === 1) { + heap = HEAP8 + } else if (size === 2) { + heap = HEAP16 + } else if (size === 4) { + heap = HEAP32 + } else { + throw new TypeError('Unknown boolean type size: ' + name) + } + return this['fromWireType'](heap[pointer >> shift]) + }, + destructorFunction: null, + }) + } + var emval_free_list = [] + var emval_handle_array = [ + {}, + { value: undefined }, + { value: null }, + { value: true }, + { value: false }, + ] + function __emval_decref(handle) { + if (handle > 4 && 0 === --emval_handle_array[handle].refcount) { + emval_handle_array[handle] = undefined + emval_free_list.push(handle) + } + } + function count_emval_handles() { + var count = 0 + for (var i = 5; i < emval_handle_array.length; ++i) { + if (emval_handle_array[i] !== undefined) { + ++count + } + } + return count + } + function get_first_emval() { + for (var i = 5; i < emval_handle_array.length; ++i) { + if (emval_handle_array[i] !== undefined) { + return emval_handle_array[i] + } + } + return null + } + function init_emval() { + Module['count_emval_handles'] = count_emval_handles + Module['get_first_emval'] = get_first_emval + } + function __emval_register(value) { + switch (value) { + case undefined: { return 1 - case null: + } + case null: { return 2 - case !0: + } + case true: { return 3 - case !1: + } + case false: { return 4 - default: - var b = Oa.length ? Oa.pop() : V.length - V[b] = { D: 1, value: a } - return b + } + default: { + var handle = emval_free_list.length + ? emval_free_list.pop() + : emval_handle_array.length + emval_handle_array[handle] = { refcount: 1, value: value } + return handle + } } } - function Qa(a) { - return this.fromWireType(I[a >> 2]) + function simpleReadValueFromPointer(pointer) { + return this['fromWireType'](HEAPU32[pointer >> 2]) + } + function __embind_register_emval(rawType, name) { + name = readLatin1String(name) + registerType(rawType, { + name: name, + fromWireType: function (handle) { + var rv = emval_handle_array[handle].value + __emval_decref(handle) + return rv + }, + toWireType: function (destructors, value) { + return __emval_register(value) + }, + argPackAdvance: 8, + readValueFromPointer: simpleReadValueFromPointer, + destructorFunction: null, + }) } - function Ra(a) { - if (null === a) return 'null' - var b = typeof a - return 'object' === b || 'array' === b || 'function' === b - ? a.toString() - : '' + a + function _embind_repr(v) { + if (v === null) { + return 'null' + } + var t = typeof v + if (t === 'object' || t === 'array' || t === 'function') { + return v.toString() + } else { + return '' + v + } } - function Sa(a, b) { - switch (b) { + function floatReadValueFromPointer(name, shift) { + switch (shift) { case 2: - return function (c) { - return this.fromWireType(ra[c >> 2]) + return function (pointer) { + return this['fromWireType'](HEAPF32[pointer >> 2]) } case 3: - return function (c) { - return this.fromWireType(sa[c >> 3]) + return function (pointer) { + return this['fromWireType'](HEAPF64[pointer >> 3]) } default: - throw new TypeError('Unknown float type: ' + a) + throw new TypeError('Unknown float type: ' + name) } } - function Ta(a) { - var b = Function - if (!(b instanceof Function)) + function __embind_register_float(rawType, name, size) { + var shift = getShiftFromSize(size) + name = readLatin1String(name) + registerType(rawType, { + name: name, + fromWireType: function (value) { + return value + }, + toWireType: function (destructors, value) { + if (typeof value !== 'number' && typeof value !== 'boolean') { + throw new TypeError( + 'Cannot convert "' + _embind_repr(value) + '" to ' + this.name + ) + } + return value + }, + argPackAdvance: 8, + readValueFromPointer: floatReadValueFromPointer(name, shift), + destructorFunction: null, + }) + } + function new_(constructor, argumentList) { + if (!(constructor instanceof Function)) { throw new TypeError( 'new_ called with constructor type ' + - typeof b + + typeof constructor + ' which is not a function' ) - var c = Ha(b.name || 'unknownFunctionName', function () {}) - c.prototype = b.prototype - c = new c() - a = b.apply(c, a) - return a instanceof Object ? a : c - } - function Ua(a) { - for (; a.length; ) { - var b = a.pop() - a.pop()(b) - } - } - function Va(a, b) { - var c = e - if (void 0 === c[a].A) { - var d = c[a] - c[a] = function () { - c[a].A.hasOwnProperty(arguments.length) || - T( + } + var dummy = createNamedFunction( + constructor.name || 'unknownFunctionName', + function () {} + ) + dummy.prototype = constructor.prototype + var obj = new dummy() + var r = constructor.apply(obj, argumentList) + return r instanceof Object ? r : obj + } + function runDestructors(destructors) { + while (destructors.length) { + var ptr = destructors.pop() + var del = destructors.pop() + del(ptr) + } + } + function craftInvokerFunction( + humanName, + argTypes, + classType, + cppInvokerFunc, + cppTargetFunc + ) { + var argCount = argTypes.length + if (argCount < 2) { + throwBindingError( + "argTypes array size mismatch! Must at least get return value and 'this' types!" + ) + } + var isClassMethodFunc = argTypes[1] !== null && classType !== null + var needsDestructorStack = false + for (var i = 1; i < argTypes.length; ++i) { + if ( + argTypes[i] !== null && + argTypes[i].destructorFunction === undefined + ) { + needsDestructorStack = true + break + } + } + var returns = argTypes[0].name !== 'void' + var argsList = '' + var argsListWired = '' + for (var i = 0; i < argCount - 2; ++i) { + argsList += (i !== 0 ? ', ' : '') + 'arg' + i + argsListWired += (i !== 0 ? ', ' : '') + 'arg' + i + 'Wired' + } + var invokerFnBody = + 'return function ' + + makeLegalFunctionName(humanName) + + '(' + + argsList + + ') {\n' + + 'if (arguments.length !== ' + + (argCount - 2) + + ') {\n' + + "throwBindingError('function " + + humanName + + " called with ' + arguments.length + ' arguments, expected " + + (argCount - 2) + + " args!');\n" + + '}\n' + if (needsDestructorStack) { + invokerFnBody += 'var destructors = [];\n' + } + var dtorStack = needsDestructorStack ? 'destructors' : 'null' + var args1 = [ + 'throwBindingError', + 'invoker', + 'fn', + 'runDestructors', + 'retType', + 'classParam', + ] + var args2 = [ + throwBindingError, + cppInvokerFunc, + cppTargetFunc, + runDestructors, + argTypes[0], + argTypes[1], + ] + if (isClassMethodFunc) { + invokerFnBody += + 'var thisWired = classParam.toWireType(' + dtorStack + ', this);\n' + } + for (var i = 0; i < argCount - 2; ++i) { + invokerFnBody += + 'var arg' + + i + + 'Wired = argType' + + i + + '.toWireType(' + + dtorStack + + ', arg' + + i + + '); // ' + + argTypes[i + 2].name + + '\n' + args1.push('argType' + i) + args2.push(argTypes[i + 2]) + } + if (isClassMethodFunc) { + argsListWired = + 'thisWired' + (argsListWired.length > 0 ? ', ' : '') + argsListWired + } + invokerFnBody += + (returns ? 'var rv = ' : '') + + 'invoker(fn' + + (argsListWired.length > 0 ? ', ' : '') + + argsListWired + + ');\n' + if (needsDestructorStack) { + invokerFnBody += 'runDestructors(destructors);\n' + } else { + for (var i = isClassMethodFunc ? 1 : 2; i < argTypes.length; ++i) { + var paramName = i === 1 ? 'thisWired' : 'arg' + (i - 2) + 'Wired' + if (argTypes[i].destructorFunction !== null) { + invokerFnBody += + paramName + + '_dtor(' + + paramName + + '); // ' + + argTypes[i].name + + '\n' + args1.push(paramName + '_dtor') + args2.push(argTypes[i].destructorFunction) + } + } + } + if (returns) { + invokerFnBody += + 'var ret = retType.fromWireType(rv);\n' + 'return ret;\n' + } else { + } + invokerFnBody += '}\n' + args1.push(invokerFnBody) + var invokerFunction = new_(Function, args1).apply(null, args2) + return invokerFunction + } + function ensureOverloadTable(proto, methodName, humanName) { + if (undefined === proto[methodName].overloadTable) { + var prevFunc = proto[methodName] + proto[methodName] = function () { + if ( + !proto[methodName].overloadTable.hasOwnProperty(arguments.length) + ) { + throwBindingError( "Function '" + - b + + humanName + "' called with an invalid number of arguments (" + arguments.length + ') - expects one of (' + - c[a].A + + proto[methodName].overloadTable + ')!' ) - return c[a].A[arguments.length].apply(this, arguments) + } + return proto[methodName].overloadTable[arguments.length].apply( + this, + arguments + ) } - c[a].A = [] - c[a].A[d.F] = d - } - } - function Wa(a, b, c) { - e.hasOwnProperty(a) - ? ((void 0 === c || (void 0 !== e[a].A && void 0 !== e[a].A[c])) && - T("Cannot register public name '" + a + "' twice"), - Va(a, a), - e.hasOwnProperty(c) && - T( - 'Cannot register multiple overloads of a function with the same number of arguments (' + - c + - ')!' - ), - (e[a].A[c] = b)) - : ((e[a] = b), void 0 !== c && (e[a].J = c)) - } - function Xa(a, b) { - for (var c = [], d = 0; d < a; d++) c.push(F[(b >> 2) + d]) - return c - } - function Ya(a, b) { - 0 <= a.indexOf('j') || - x('Assertion failed: getDynCaller should only be called with i64 sigs') - var c = [] + proto[methodName].overloadTable = [] + proto[methodName].overloadTable[prevFunc.argCount] = prevFunc + } + } + function exposePublicSymbol(name, value, numArguments) { + if (Module.hasOwnProperty(name)) { + if ( + undefined === numArguments || + (undefined !== Module[name].overloadTable && + undefined !== Module[name].overloadTable[numArguments]) + ) { + throwBindingError("Cannot register public name '" + name + "' twice") + } + ensureOverloadTable(Module, name, name) + if (Module.hasOwnProperty(numArguments)) { + throwBindingError( + 'Cannot register multiple overloads of a function with the same number of arguments (' + + numArguments + + ')!' + ) + } + Module[name].overloadTable[numArguments] = value + } else { + Module[name] = value + if (undefined !== numArguments) { + Module[name].numArguments = numArguments + } + } + } + function heap32VectorToArray(count, firstElement) { + var array = [] + for (var i = 0; i < count; i++) { + array.push(HEAP32[(firstElement >> 2) + i]) + } + return array + } + function replacePublicSymbol(name, value, numArguments) { + if (!Module.hasOwnProperty(name)) { + throwInternalError('Replacing nonexistant public symbol') + } + if ( + undefined !== Module[name].overloadTable && + undefined !== numArguments + ) { + Module[name].overloadTable[numArguments] = value + } else { + Module[name] = value + Module[name].argCount = numArguments + } + } + function dynCallLegacy(sig, ptr, args) { + var f = Module['dynCall_' + sig] + return args && args.length + ? f.apply(null, [ptr].concat(args)) + : f.call(null, ptr) + } + function dynCall(sig, ptr, args) { + if (sig.includes('j')) { + return dynCallLegacy(sig, ptr, args) + } + return wasmTable.get(ptr).apply(null, args) + } + function getDynCaller(sig, ptr) { + var argCache = [] return function () { - c.length = arguments.length - for (var d = 0; d < arguments.length; d++) c[d] = arguments[d] - var f - ;-1 != a.indexOf('j') - ? (f = - c && c.length - ? e['dynCall_' + a].apply(null, [b].concat(c)) - : e['dynCall_' + a].call(null, b)) - : (f = J.get(b).apply(null, c)) - return f - } - } - function Za(a, b) { - a = P(a) - var c = -1 != a.indexOf('j') ? Ya(a, b) : J.get(b) - 'function' !== typeof c && - T('unknown function pointer with signature ' + a + ': ' + b) - return c - } - var $a = void 0 - function ab(a) { - a = bb(a) - var b = P(a) - X(a) - return b - } - function cb(a, b) { - function c(g) { - f[g] || R[g] || (S[g] ? S[g].forEach(c) : (d.push(g), (f[g] = !0))) - } - var d = [], - f = {} - b.forEach(c) - throw new $a(a + ': ' + d.map(ab).join([', '])) - } - function db(a, b, c) { - switch (b) { + argCache.length = arguments.length + for (var i = 0; i < arguments.length; i++) { + argCache[i] = arguments[i] + } + return dynCall(sig, ptr, argCache) + } + } + function embind__requireFunction(signature, rawFunction) { + signature = readLatin1String(signature) + function makeDynCaller() { + if (signature.includes('j')) { + return getDynCaller(signature, rawFunction) + } + return wasmTable.get(rawFunction) + } + var fp = makeDynCaller() + if (typeof fp !== 'function') { + throwBindingError( + 'unknown function pointer with signature ' + + signature + + ': ' + + rawFunction + ) + } + return fp + } + var UnboundTypeError = undefined + function getTypeName(type) { + var ptr = ___getTypeName(type) + var rv = readLatin1String(ptr) + _free(ptr) + return rv + } + function throwUnboundTypeError(message, types) { + var unboundTypes = [] + var seen = {} + function visit(type) { + if (seen[type]) { + return + } + if (registeredTypes[type]) { + return + } + if (typeDependencies[type]) { + typeDependencies[type].forEach(visit) + return + } + unboundTypes.push(type) + seen[type] = true + } + types.forEach(visit) + throw new UnboundTypeError( + message + ': ' + unboundTypes.map(getTypeName).join([', ']) + ) + } + function __embind_register_function( + name, + argCount, + rawArgTypesAddr, + signature, + rawInvoker, + fn + ) { + var argTypes = heap32VectorToArray(argCount, rawArgTypesAddr) + name = readLatin1String(name) + rawInvoker = embind__requireFunction(signature, rawInvoker) + exposePublicSymbol( + name, + function () { + throwUnboundTypeError( + 'Cannot call ' + name + ' due to unbound types', + argTypes + ) + }, + argCount - 1 + ) + whenDependentTypesAreResolved([], argTypes, function (argTypes) { + var invokerArgsArray = [argTypes[0], null].concat(argTypes.slice(1)) + replacePublicSymbol( + name, + craftInvokerFunction(name, invokerArgsArray, null, rawInvoker, fn), + argCount - 1 + ) + return [] + }) + } + function integerReadValueFromPointer(name, shift, signed) { + switch (shift) { case 0: - return c - ? function (d) { - return qa[d] + return signed + ? function readS8FromPointer(pointer) { + return HEAP8[pointer] } - : function (d) { - return C[d] + : function readU8FromPointer(pointer) { + return HEAPU8[pointer] } case 1: - return c - ? function (d) { - return E[d >> 1] + return signed + ? function readS16FromPointer(pointer) { + return HEAP16[pointer >> 1] } - : function (d) { - return D[d >> 1] + : function readU16FromPointer(pointer) { + return HEAPU16[pointer >> 1] } case 2: - return c - ? function (d) { - return F[d >> 2] + return signed + ? function readS32FromPointer(pointer) { + return HEAP32[pointer >> 2] } - : function (d) { - return I[d >> 2] + : function readU32FromPointer(pointer) { + return HEAPU32[pointer >> 2] } default: - throw new TypeError('Unknown integer type: ' + a) - } - } - var eb = {} - function fb() { - return 'object' === typeof globalThis - ? globalThis - : Function('return this')() - } - function gb(a, b) { - var c = R[a] - void 0 === c && T(b + ' has unknown type ' + ab(a)) - return c - } - for (var hb = {}, ib = Array(256), Y = 0; 256 > Y; ++Y) - ib[Y] = String.fromCharCode(Y) - Fa = ib - Ja = e.BindingError = Ia('BindingError') - Ka = e.InternalError = Ia('InternalError') - e.count_emval_handles = function () { - for (var a = 0, b = 5; b < V.length; ++b) void 0 !== V[b] && ++a - return a - } - e.get_first_emval = function () { - for (var a = 5; a < V.length; ++a) if (void 0 !== V[a]) return V[a] - return null + throw new TypeError('Unknown integer type: ' + name) + } } - $a = e.UnboundTypeError = Ia('UnboundTypeError') - wa.push({ - G: function () { - jb() - }, - }) - var lb = { - g: function () {}, - o: function (a, b, c, d, f) { - var g = Ea(c) - b = P(b) - U(a, { - name: b, - fromWireType: function (l) { - return !!l - }, - toWireType: function (l, h) { - return h ? d : f - }, - argPackAdvance: 8, - readValueFromPointer: function (l) { - if (1 === c) var h = qa - else if (2 === c) h = E - else if (4 === c) h = F - else throw new TypeError('Unknown boolean type size: ' + b) - return this.fromWireType(h[l >> g]) - }, - B: null, - }) - }, - r: function (a, b) { - b = P(b) - U(a, { - name: b, - fromWireType: function (c) { - var d = V[c].value - Pa(c) - return d - }, - toWireType: function (c, d) { - return W(d) - }, - argPackAdvance: 8, - readValueFromPointer: Qa, - B: null, - }) - }, - n: function (a, b, c) { - c = Ea(c) - b = P(b) - U(a, { - name: b, - fromWireType: function (d) { - return d - }, - toWireType: function (d, f) { - if ('number' !== typeof f && 'boolean' !== typeof f) - throw new TypeError( - 'Cannot convert "' + Ra(f) + '" to ' + this.name - ) - return f - }, - argPackAdvance: 8, - readValueFromPointer: Sa(b, c), - B: null, - }) - }, - j: function (a, b, c, d, f, g) { - var l = Xa(b, c) - a = P(a) - f = Za(d, f) - Wa( - a, - function () { - cb('Cannot call ' + a + ' due to unbound types', l) - }, - b - 1 - ) - La(l, function (h) { - var k = [h[0], null].concat(h.slice(1)), - n = (h = a), - p = f, - q = k.length - 2 > q && - T( - "argTypes array size mismatch! Must at least get return value and 'this' types!" + function __embind_register_integer( + primitiveType, + name, + size, + minRange, + maxRange + ) { + name = readLatin1String(name) + if (maxRange === -1) { + maxRange = 4294967295 + } + var shift = getShiftFromSize(size) + var fromWireType = function (value) { + return value + } + if (minRange === 0) { + var bitshift = 32 - 8 * size + fromWireType = function (value) { + return (value << bitshift) >>> bitshift + } + } + var isUnsignedType = name.includes('unsigned') + registerType(primitiveType, { + name: name, + fromWireType: fromWireType, + toWireType: function (destructors, value) { + if (typeof value !== 'number' && typeof value !== 'boolean') { + throw new TypeError( + 'Cannot convert "' + _embind_repr(value) + '" to ' + this.name ) - for (var w = null !== k[1] && !1, A = !1, m = 1; m < k.length; ++m) - if (null !== k[m] && void 0 === k[m].B) { - A = !0 - break - } - var Ma = 'void' !== k[0].name, - H = '', - K = '' - for (m = 0; m < q - 2; ++m) - (H += (0 !== m ? ', ' : '') + 'arg' + m), - (K += (0 !== m ? ', ' : '') + 'arg' + m + 'Wired') - n = - 'return function ' + - Ga(n) + - '(' + - H + - ') {\nif (arguments.length !== ' + - (q - 2) + - ") {\nthrowBindingError('function " + - n + - " called with ' + arguments.length + ' arguments, expected " + - (q - 2) + - " args!');\n}\n" - A && (n += 'var destructors = [];\n') - var Na = A ? 'destructors' : 'null' - H = - 'throwBindingError invoker fn runDestructors retType classParam'.split( - ' ' + } + if (value < minRange || value > maxRange) { + throw new TypeError( + 'Passing a number "' + + _embind_repr(value) + + '" from JS side to C/C++ side to an argument of type "' + + name + + '", which is outside the valid range [' + + minRange + + ', ' + + maxRange + + ']!' ) - p = [T, p, g, Ua, k[0], k[1]] - w && - (n += 'var thisWired = classParam.toWireType(' + Na + ', this);\n') - for (m = 0; m < q - 2; ++m) - (n += - 'var arg' + - m + - 'Wired = argType' + - m + - '.toWireType(' + - Na + - ', arg' + - m + - '); // ' + - k[m + 2].name + - '\n'), - H.push('argType' + m), - p.push(k[m + 2]) - w && (K = 'thisWired' + (0 < K.length ? ', ' : '') + K) - n += - (Ma ? 'var rv = ' : '') + - 'invoker(fn' + - (0 < K.length ? ', ' : '') + - K + - ');\n' - if (A) n += 'runDestructors(destructors);\n' - else - for (m = w ? 1 : 2; m < k.length; ++m) - (q = 1 === m ? 'thisWired' : 'arg' + (m - 2) + 'Wired'), - null !== k[m].B && - ((n += q + '_dtor(' + q + '); // ' + k[m].name + '\n'), - H.push(q + '_dtor'), - p.push(k[m].B)) - Ma && (n += 'var ret = retType.fromWireType(rv);\nreturn ret;\n') - H.push(n + '}\n') - k = Ta(H).apply(null, p) - m = b - 1 - if (!e.hasOwnProperty(h)) - throw new Ka('Replacing nonexistant public symbol') - void 0 !== e[h].A && void 0 !== m - ? (e[h].A[m] = k) - : ((e[h] = k), (e[h].F = m)) - return [] - }) - }, - c: function (a, b, c, d, f) { - function g(n) { - return n - } - b = P(b) - ;-1 === f && (f = 4294967295) - var l = Ea(c) - if (0 === d) { - var h = 32 - 8 * c - g = function (n) { - return (n << h) >>> h } - } - var k = -1 != b.indexOf('unsigned') - U(a, { - name: b, - fromWireType: g, - toWireType: function (n, p) { - if ('number' !== typeof p && 'boolean' !== typeof p) - throw new TypeError( - 'Cannot convert "' + Ra(p) + '" to ' + this.name - ) - if (p < d || p > f) - throw new TypeError( - 'Passing a number "' + - Ra(p) + - '" from JS side to C/C++ side to an argument of type "' + - b + - '", which is outside the valid range [' + - d + - ', ' + - f + - ']!' - ) - return k ? p >>> 0 : p | 0 - }, + return isUnsignedType ? value >>> 0 : value | 0 + }, + argPackAdvance: 8, + readValueFromPointer: integerReadValueFromPointer( + name, + shift, + minRange !== 0 + ), + destructorFunction: null, + }) + } + function __embind_register_memory_view(rawType, dataTypeIndex, name) { + var typeMapping = [ + Int8Array, + Uint8Array, + Int16Array, + Uint16Array, + Int32Array, + Uint32Array, + Float32Array, + Float64Array, + ] + var TA = typeMapping[dataTypeIndex] + function decodeMemoryView(handle) { + handle = handle >> 2 + var heap = HEAPU32 + var size = heap[handle] + var data = heap[handle + 1] + return new TA(buffer, data, size) + } + name = readLatin1String(name) + registerType( + rawType, + { + name: name, + fromWireType: decodeMemoryView, argPackAdvance: 8, - readValueFromPointer: db(b, l, 0 !== d), - B: null, - }) - }, - b: function (a, b, c) { - function d(g) { - g >>= 2 - var l = I - return new f(G, l[g + 1], l[g]) - } - var f = [ - Int8Array, - Uint8Array, - Int16Array, - Uint16Array, - Int32Array, - Uint32Array, - Float32Array, - Float64Array, - ][b] - c = P(c) - U( - a, - { - name: c, - fromWireType: d, - argPackAdvance: 8, - readValueFromPointer: d, - }, - { H: !0 } - ) - }, - i: function (a, b) { - b = P(b) - var c = 'std::string' === b - U(a, { - name: b, - fromWireType: function (d) { - var f = I[d >> 2] - if (c) - for (var g = d + 4, l = 0; l <= f; ++l) { - var h = d + 4 + l - if (l == f || 0 == C[h]) { - if (g) { - for (var k = g + (h - g), n = g; !(n >= k) && C[n]; ) ++n - g = ha.decode(C.subarray(g, n)) - } else g = '' - if (void 0 === p) var p = g - else (p += String.fromCharCode(0)), (p += g) - g = h + 1 + readValueFromPointer: decodeMemoryView, + }, + { ignoreDuplicateRegistrations: true } + ) + } + function __embind_register_std_string(rawType, name) { + name = readLatin1String(name) + var stdStringIsUTF8 = name === 'std::string' + registerType(rawType, { + name: name, + fromWireType: function (value) { + var length = HEAPU32[value >> 2] + var str + if (stdStringIsUTF8) { + var decodeStartPtr = value + 4 + for (var i = 0; i <= length; ++i) { + var currentBytePtr = value + 4 + i + if (i == length || HEAPU8[currentBytePtr] == 0) { + var maxRead = currentBytePtr - decodeStartPtr + var stringSegment = UTF8ToString(decodeStartPtr, maxRead) + if (str === undefined) { + str = stringSegment + } else { + str += String.fromCharCode(0) + str += stringSegment } + decodeStartPtr = currentBytePtr + 1 } - else { - p = Array(f) - for (l = 0; l < f; ++l) p[l] = String.fromCharCode(C[d + 4 + l]) - p = p.join('') } - X(d) - return p - }, - toWireType: function (d, f) { - f instanceof ArrayBuffer && (f = new Uint8Array(f)) - var g = 'string' === typeof f - g || - f instanceof Uint8Array || - f instanceof Uint8ClampedArray || - f instanceof Int8Array || - T('Cannot pass non-string to std::string') - var l = ( - c && g - ? function () { - for (var n = 0, p = 0; p < f.length; ++p) { - var q = f.charCodeAt(p) - 55296 <= q && - 57343 >= q && - (q = - (65536 + ((q & 1023) << 10)) | - (f.charCodeAt(++p) & 1023)) - 127 >= q - ? ++n - : (n = 2047 >= q ? n + 2 : 65535 >= q ? n + 3 : n + 4) - } - return n - } - : function () { - return f.length - } - )(), - h = kb(4 + l + 1) - I[h >> 2] = l - if (c && g) ia(f, h + 4, l + 1) - else if (g) - for (g = 0; g < l; ++g) { - var k = f.charCodeAt(g) - 255 < k && - (X(h), - T('String has UTF-16 code units that do not fit in 8 bits')) - C[h + 4 + g] = k - } - else for (g = 0; g < l; ++g) C[h + 4 + g] = f[g] - null !== d && d.push(X, h) - return h - }, - argPackAdvance: 8, - readValueFromPointer: Qa, - B: function (d) { - X(d) - }, - }) - }, - h: function (a, b, c) { - c = P(c) - if (2 === b) { - var d = ka - var f = la - var g = ma - var l = function () { - return D + } else { + var a = new Array(length) + for (var i = 0; i < length; ++i) { + a[i] = String.fromCharCode(HEAPU8[value + 4 + i]) + } + str = a.join('') + } + _free(value) + return str + }, + toWireType: function (destructors, value) { + if (value instanceof ArrayBuffer) { + value = new Uint8Array(value) } - var h = 1 - } else - 4 === b && - ((d = na), - (f = oa), - (g = pa), - (l = function () { - return I - }), - (h = 2)) - U(a, { - name: c, - fromWireType: function (k) { - for (var n = I[k >> 2], p = l(), q, w = k + 4, A = 0; A <= n; ++A) { - var m = k + 4 + A * b - if (A == n || 0 == p[m >> h]) - (w = d(w, m - w)), - void 0 === q - ? (q = w) - : ((q += String.fromCharCode(0)), (q += w)), - (w = m + b) + var getLength + var valueIsOfTypeString = typeof value === 'string' + if ( + !( + valueIsOfTypeString || + value instanceof Uint8Array || + value instanceof Uint8ClampedArray || + value instanceof Int8Array + ) + ) { + throwBindingError('Cannot pass non-string to std::string') + } + if (stdStringIsUTF8 && valueIsOfTypeString) { + getLength = function () { + return lengthBytesUTF8(value) } - X(k) - return q - }, - toWireType: function (k, n) { - 'string' !== typeof n && - T('Cannot pass non-string to C++ string type ' + c) - var p = g(n), - q = kb(4 + p + b) - I[q >> 2] = p >> h - f(n, q + 4, p + b) - null !== k && k.push(X, q) - return q - }, - argPackAdvance: 8, - readValueFromPointer: Qa, - B: function (k) { - X(k) - }, - }) - }, - p: function (a, b) { - b = P(b) - U(a, { - I: !0, - name: b, - argPackAdvance: 0, - fromWireType: function () {}, - toWireType: function () {}, - }) - }, - e: Pa, - f: function (a) { - if (0 === a) return W(fb()) - var b = eb[a] - a = void 0 === b ? P(a) : b - return W(fb()[a]) - }, - k: function (a) { - 4 < a && (V[a].D += 1) - }, - l: function (a, b, c, d) { - a || T('Cannot use deleted val. handle = ' + a) - a = V[a].value - var f = hb[b] - if (!f) { - f = '' - for (var g = 0; g < b; ++g) f += (0 !== g ? ', ' : '') + 'arg' + g - var l = - 'return function emval_allocator_' + - b + - '(constructor, argTypes, args) {\n' - for (g = 0; g < b; ++g) - l += - 'var argType' + - g + - " = requireRegisteredType(Module['HEAP32'][(argTypes >>> 2) + " + - g + - '], "parameter ' + - g + - '");\nvar arg' + - g + - ' = argType' + - g + - '.readValueFromPointer(args);\nargs += argType' + - g + - "['argPackAdvance'];\n" - f = new Function( - 'requireRegisteredType', - 'Module', - '__emval_register', - l + - ('var obj = new constructor(' + - f + - ');\nreturn __emval_register(obj);\n}\n') - )(gb, e, W) - hb[b] = f - } - return f(a, c, d) - }, - m: function () { - x() - }, - q: function (a, b, c) { - C.copyWithin(a, b, b + c) - }, - d: function (a) { - a >>>= 0 - var b = C.length - if (2147483648 < a) return !1 - for (var c = 1; 4 >= c; c *= 2) { - var d = b * (1 + 0.2 / c) - d = Math.min(d, a + 100663296) - d = Math.max(16777216, a, d) - 0 < d % 65536 && (d += 65536 - (d % 65536)) - a: { - try { - B.grow((Math.min(2147483648, d) - G.byteLength + 65535) >>> 16) - ta(B.buffer) - var f = 1 - break a - } catch (g) {} - f = void 0 + } else { + getLength = function () { + return value.length + } + } + var length = getLength() + var ptr = _malloc(4 + length + 1) + HEAPU32[ptr >> 2] = length + if (stdStringIsUTF8 && valueIsOfTypeString) { + stringToUTF8(value, ptr + 4, length + 1) + } else { + if (valueIsOfTypeString) { + for (var i = 0; i < length; ++i) { + var charCode = value.charCodeAt(i) + if (charCode > 255) { + _free(ptr) + throwBindingError( + 'String has UTF-16 code units that do not fit in 8 bits' + ) + } + HEAPU8[ptr + 4 + i] = charCode + } + } else { + for (var i = 0; i < length; ++i) { + HEAPU8[ptr + 4 + i] = value[i] + } + } + } + if (destructors !== null) { + destructors.push(_free, ptr) } - if (f) return !0 + return ptr + }, + argPackAdvance: 8, + readValueFromPointer: simpleReadValueFromPointer, + destructorFunction: function (ptr) { + _free(ptr) + }, + }) + } + function __embind_register_std_wstring(rawType, charSize, name) { + name = readLatin1String(name) + var decodeString, encodeString, getHeap, lengthBytesUTF, shift + if (charSize === 2) { + decodeString = UTF16ToString + encodeString = stringToUTF16 + lengthBytesUTF = lengthBytesUTF16 + getHeap = function () { + return HEAPU16 } - return !1 - }, - a: B, - } - ;(function () { - function a(f) { - e.asm = f.exports - J = e.asm.s - L-- - e.monitorRunDependencies && e.monitorRunDependencies(L) - 0 == L && - (null !== Aa && (clearInterval(Aa), (Aa = null)), - M && ((f = M), (M = null), f())) - } - function b(f) { - a(f.instance) - } - function c(f) { - return Promise.resolve() - .then(Da) - .then(function (g) { - return WebAssembly.instantiate(g, d) - }) - .then(f, function (g) { - y('failed to asynchronously prepare wasm: ' + g) - x(g) - }) - } - var d = { a: lb } - L++ - e.monitorRunDependencies && e.monitorRunDependencies(L) - if (e.instantiateWasm) - try { - return e.instantiateWasm(d, a) - } catch (f) { - return ( - y('Module.instantiateWasm callback failed with error: ' + f), !1 - ) + shift = 1 + } else if (charSize === 4) { + decodeString = UTF32ToString + encodeString = stringToUTF32 + lengthBytesUTF = lengthBytesUTF32 + getHeap = function () { + return HEAPU32 } - ;(function () { - return z || - 'function' !== typeof WebAssembly.instantiateStreaming || - Ba() || - 'function' !== typeof fetch - ? c(b) - : fetch(N, { credentials: 'same-origin' }).then(function (f) { - return WebAssembly.instantiateStreaming(f, d).then( - b, - function (g) { - y('wasm streaming compile failed: ' + g) - y('falling back to ArrayBuffer instantiation') - return c(b) - } - ) - }) - })().catch(r) - return {} - })() - var jb = (e.___wasm_call_ctors = function () { - return (jb = e.___wasm_call_ctors = e.asm.t).apply(null, arguments) - }), - kb = (e._malloc = function () { - return (kb = e._malloc = e.asm.u).apply(null, arguments) - }), - X = (e._free = function () { - return (X = e._free = e.asm.v).apply(null, arguments) - }), - bb = (e.___getTypeName = function () { - return (bb = e.___getTypeName = e.asm.w).apply(null, arguments) + shift = 2 + } + registerType(rawType, { + name: name, + fromWireType: function (value) { + var length = HEAPU32[value >> 2] + var HEAP = getHeap() + var str + var decodeStartPtr = value + 4 + for (var i = 0; i <= length; ++i) { + var currentBytePtr = value + 4 + i * charSize + if (i == length || HEAP[currentBytePtr >> shift] == 0) { + var maxReadBytes = currentBytePtr - decodeStartPtr + var stringSegment = decodeString(decodeStartPtr, maxReadBytes) + if (str === undefined) { + str = stringSegment + } else { + str += String.fromCharCode(0) + str += stringSegment + } + decodeStartPtr = currentBytePtr + charSize + } + } + _free(value) + return str + }, + toWireType: function (destructors, value) { + if (!(typeof value === 'string')) { + throwBindingError( + 'Cannot pass non-string to C++ string type ' + name + ) + } + var length = lengthBytesUTF(value) + var ptr = _malloc(4 + length + charSize) + HEAPU32[ptr >> 2] = length >> shift + encodeString(value, ptr + 4, length + charSize) + if (destructors !== null) { + destructors.push(_free, ptr) + } + return ptr + }, + argPackAdvance: 8, + readValueFromPointer: simpleReadValueFromPointer, + destructorFunction: function (ptr) { + _free(ptr) + }, + }) + } + function __embind_register_void(rawType, name) { + name = readLatin1String(name) + registerType(rawType, { + isVoid: true, + name: name, + argPackAdvance: 0, + fromWireType: function () { + return undefined + }, + toWireType: function (destructors, o) { + return undefined + }, }) - e.___embind_register_native_and_builtin_types = function () { - return (e.___embind_register_native_and_builtin_types = e.asm.x).apply( + } + var emval_symbols = {} + function getStringOrSymbol(address) { + var symbol = emval_symbols[address] + if (symbol === undefined) { + return readLatin1String(address) + } else { + return symbol + } + } + function emval_get_global() { + if (typeof globalThis === 'object') { + return globalThis + } + return (function () { + return Function + })()('return this')() + } + function __emval_get_global(name) { + if (name === 0) { + return __emval_register(emval_get_global()) + } else { + name = getStringOrSymbol(name) + return __emval_register(emval_get_global()[name]) + } + } + function __emval_incref(handle) { + if (handle > 4) { + emval_handle_array[handle].refcount += 1 + } + } + function requireRegisteredType(rawType, humanName) { + var impl = registeredTypes[rawType] + if (undefined === impl) { + throwBindingError( + humanName + ' has unknown type ' + getTypeName(rawType) + ) + } + return impl + } + function craftEmvalAllocator(argCount) { + var argsList = '' + for (var i = 0; i < argCount; ++i) { + argsList += (i !== 0 ? ', ' : '') + 'arg' + i + } + var functionBody = + 'return function emval_allocator_' + + argCount + + '(constructor, argTypes, args) {\n' + for (var i = 0; i < argCount; ++i) { + functionBody += + 'var argType' + + i + + " = requireRegisteredType(Module['HEAP32'][(argTypes >>> 2) + " + + i + + '], "parameter ' + + i + + '");\n' + + 'var arg' + + i + + ' = argType' + + i + + '.readValueFromPointer(args);\n' + + 'args += argType' + + i + + "['argPackAdvance'];\n" + } + functionBody += + 'var obj = new constructor(' + + argsList + + ');\n' + + 'return __emval_register(obj);\n' + + '}\n' + return new Function( + 'requireRegisteredType', + 'Module', + '__emval_register', + functionBody + )(requireRegisteredType, Module, __emval_register) + } + var emval_newers = {} + function requireHandle(handle) { + if (!handle) { + throwBindingError('Cannot use deleted val. handle = ' + handle) + } + return emval_handle_array[handle].value + } + function __emval_new(handle, argCount, argTypes, args) { + handle = requireHandle(handle) + var newer = emval_newers[argCount] + if (!newer) { + newer = craftEmvalAllocator(argCount) + emval_newers[argCount] = newer + } + return newer(handle, argTypes, args) + } + function _abort() { + abort() + } + function _emscripten_memcpy_big(dest, src, num) { + HEAPU8.copyWithin(dest, src, src + num) + } + function emscripten_realloc_buffer(size) { + try { + wasmMemory.grow((size - buffer.byteLength + 65535) >>> 16) + updateGlobalBufferAndViews(wasmMemory.buffer) + return 1 + } catch (e) {} + } + function _emscripten_resize_heap(requestedSize) { + var oldSize = HEAPU8.length + requestedSize = requestedSize >>> 0 + var maxHeapSize = 2147483648 + if (requestedSize > maxHeapSize) { + return false + } + for (var cutDown = 1; cutDown <= 4; cutDown *= 2) { + var overGrownHeapSize = oldSize * (1 + 0.2 / cutDown) + overGrownHeapSize = Math.min( + overGrownHeapSize, + requestedSize + 100663296 + ) + var newSize = Math.min( + maxHeapSize, + alignUp(Math.max(requestedSize, overGrownHeapSize), 65536) + ) + var replacement = emscripten_realloc_buffer(newSize) + if (replacement) { + return true + } + } + return false + } + embind_init_charCodes() + BindingError = Module['BindingError'] = extendError(Error, 'BindingError') + InternalError = Module['InternalError'] = extendError( + Error, + 'InternalError' + ) + init_emval() + UnboundTypeError = Module['UnboundTypeError'] = extendError( + Error, + 'UnboundTypeError' + ) + var asmLibraryArg = { + e: ___cxa_thread_atexit, + p: __embind_register_bigint, + n: __embind_register_bool, + r: __embind_register_emval, + m: __embind_register_float, + i: __embind_register_function, + b: __embind_register_integer, + a: __embind_register_memory_view, + h: __embind_register_std_string, + f: __embind_register_std_wstring, + o: __embind_register_void, + c: __emval_decref, + d: __emval_get_global, + j: __emval_incref, + k: __emval_new, + l: _abort, + q: _emscripten_memcpy_big, + g: _emscripten_resize_heap, + } + var asm = createWasm() + var ___wasm_call_ctors = (Module['___wasm_call_ctors'] = function () { + return (___wasm_call_ctors = Module['___wasm_call_ctors'] = + Module['asm']['t']).apply(null, arguments) + }) + var _malloc = (Module['_malloc'] = function () { + return (_malloc = Module['_malloc'] = Module['asm']['u']).apply( + null, + arguments + ) + }) + var _free = (Module['_free'] = function () { + return (_free = Module['_free'] = Module['asm']['v']).apply( null, arguments ) + }) + var ___getTypeName = (Module['___getTypeName'] = function () { + return (___getTypeName = Module['___getTypeName'] = + Module['asm']['w']).apply(null, arguments) + }) + var ___embind_register_native_and_builtin_types = (Module[ + '___embind_register_native_and_builtin_types' + ] = function () { + return (___embind_register_native_and_builtin_types = Module[ + '___embind_register_native_and_builtin_types' + ] = + Module['asm']['x']).apply(null, arguments) + }) + var calledRun + dependenciesFulfilled = function runCaller() { + if (!calledRun) run() + if (!calledRun) dependenciesFulfilled = runCaller } - var Z - M = function mb() { - Z || nb() - Z || (M = mb) - } - function nb() { - function a() { - if (!Z && ((Z = !0), (e.calledRun = !0), !fa)) { - O(wa) - O(xa) - aa(e) - if (e.onRuntimeInitialized) e.onRuntimeInitialized() - if (e.postRun) - for ( - 'function' == typeof e.postRun && (e.postRun = [e.postRun]); - e.postRun.length; - - ) { - var b = e.postRun.shift() - ya.unshift(b) - } - O(ya) - } + function run(args) { + args = args || arguments_ + if (runDependencies > 0) { + return } - if (!(0 < L)) { - if (e.preRun) - for ( - 'function' == typeof e.preRun && (e.preRun = [e.preRun]); - e.preRun.length; - - ) - za() - O(va) - 0 < L || - (e.setStatus - ? (e.setStatus('Running...'), - setTimeout(function () { - setTimeout(function () { - e.setStatus('') - }, 1) - a() - }, 1)) - : a()) - } - } - e.run = nb - if (e.preInit) - for ( - 'function' == typeof e.preInit && (e.preInit = [e.preInit]); - 0 < e.preInit.length; - - ) - e.preInit.pop()() - noExitRuntime = !0 - nb() + preRun() + if (runDependencies > 0) { + return + } + function doRun() { + if (calledRun) return + calledRun = true + Module['calledRun'] = true + if (ABORT) return + initRuntime() + readyPromiseResolve(Module) + if (Module['onRuntimeInitialized']) Module['onRuntimeInitialized']() + postRun() + } + if (Module['setStatus']) { + Module['setStatus']('Running...') + setTimeout(function () { + setTimeout(function () { + Module['setStatus']('') + }, 1) + doRun() + }, 1) + } else { + doRun() + } + } + Module['run'] = run + if (Module['preInit']) { + if (typeof Module['preInit'] == 'function') + Module['preInit'] = [Module['preInit']] + while (Module['preInit'].length > 0) { + Module['preInit'].pop()() + } + } + run() return Module.ready } diff --git a/packages/next/server/lib/squoosh/webp/webp_node_dec.wasm b/packages/next/server/lib/squoosh/webp/webp_node_dec.wasm old mode 100644 new mode 100755 index c3363498515a1..5df324336ca62 Binary files a/packages/next/server/lib/squoosh/webp/webp_node_dec.wasm and b/packages/next/server/lib/squoosh/webp/webp_node_dec.wasm differ diff --git a/packages/next/server/lib/squoosh/webp/webp_node_enc.js b/packages/next/server/lib/squoosh/webp/webp_node_enc.js index 2bcd7aaeff899..bcd443016f94e 100644 --- a/packages/next/server/lib/squoosh/webp/webp_node_enc.js +++ b/packages/next/server/lib/squoosh/webp/webp_node_enc.js @@ -1,299 +1,663 @@ /* eslint-disable */ -import { TextDecoder } from '../text-decoder' - var Module = (function () { - // var _scriptDir = import.meta.url - return function (Module) { Module = Module || {} - var f - f || (f = typeof Module !== 'undefined' ? Module : {}) - var aa, ba - f.ready = new Promise(function (a, b) { - aa = a - ba = b + var Module = typeof Module !== 'undefined' ? Module : {} + var readyPromiseResolve, readyPromiseReject + Module['ready'] = new Promise(function (resolve, reject) { + readyPromiseResolve = resolve + readyPromiseReject = reject }) - var r = {}, - t - for (t in f) f.hasOwnProperty(t) && (r[t] = f[t]) - var ca = '', - ea, - fa, - ha, - ia - ca = __dirname + '/' - ea = function (a) { - ha || (ha = require('fs')) - ia || (ia = require('path')) - a = ia.normalize(a) - return ha.readFileSync(a, null) - } - fa = function (a) { - a = ea(a) - a.buffer || (a = new Uint8Array(a)) - a.buffer || u('Assertion failed: undefined') - return a - } - f.inspect = function () { - return '[Emscripten Module object]' - } - f.print || console.log.bind(console) - var v = f.printErr || console.warn.bind(console) - for (t in r) r.hasOwnProperty(t) && (f[t] = r[t]) - r = null - var z - f.wasmBinary && (z = f.wasmBinary) - var noExitRuntime - f.noExitRuntime && (noExitRuntime = f.noExitRuntime) - 'object' !== typeof WebAssembly && u('no native wasm support detected') - var A, - ja = !1, - ka = new TextDecoder('utf8') - function la(a, b, c) { - var d = B - if (0 < c) { - c = b + c - 1 - for (var e = 0; e < a.length; ++e) { - var g = a.charCodeAt(e) - if (55296 <= g && 57343 >= g) { - var l = a.charCodeAt(++e) - g = (65536 + ((g & 1023) << 10)) | (l & 1023) - } - if (127 >= g) { - if (b >= c) break - d[b++] = g - } else { - if (2047 >= g) { - if (b + 1 >= c) break - d[b++] = 192 | (g >> 6) - } else { - if (65535 >= g) { - if (b + 2 >= c) break - d[b++] = 224 | (g >> 12) - } else { - if (b + 3 >= c) break - d[b++] = 240 | (g >> 18) - d[b++] = 128 | ((g >> 12) & 63) - } - d[b++] = 128 | ((g >> 6) & 63) - } - d[b++] = 128 | (g & 63) - } + var moduleOverrides = {} + var key + for (key in Module) { + if (Module.hasOwnProperty(key)) { + moduleOverrides[key] = Module[key] + } + } + var arguments_ = [] + var thisProgram = './this.program' + var quit_ = function (status, toThrow) { + throw toThrow + } + var ENVIRONMENT_IS_WEB = false + var ENVIRONMENT_IS_WORKER = false + var ENVIRONMENT_IS_NODE = true + var scriptDirectory = '' + function locateFile(path) { + if (Module['locateFile']) { + return Module['locateFile'](path, scriptDirectory) + } + return scriptDirectory + path + } + var read_, readBinary + var nodeFS + var nodePath + if (ENVIRONMENT_IS_NODE) { + if (ENVIRONMENT_IS_WORKER) { + scriptDirectory = require('path').dirname(scriptDirectory) + '/' + } else { + scriptDirectory = __dirname + '/' + } + read_ = function shell_read(filename, binary) { + if (!nodeFS) nodeFS = require('fs') + if (!nodePath) nodePath = require('path') + filename = nodePath['normalize'](filename) + return nodeFS['readFileSync'](filename, binary ? null : 'utf8') + } + readBinary = function readBinary(filename) { + var ret = read_(filename, true) + if (!ret.buffer) { + ret = new Uint8Array(ret) } - d[b] = 0 - } - } - var ma = new TextDecoder('utf-16le') - function na(a, b) { - var c = a >> 1 - for (b = c + b / 2; !(c >= b) && C[c]; ) ++c - return ma.decode(B.subarray(a, c << 1)) - } - function oa(a, b, c) { - void 0 === c && (c = 2147483647) - if (2 > c) return 0 - c -= 2 - var d = b - c = c < 2 * a.length ? c / 2 : a.length - for (var e = 0; e < c; ++e) (D[b >> 1] = a.charCodeAt(e)), (b += 2) - D[b >> 1] = 0 - return b - d - } - function pa(a) { - return 2 * a.length - } - function qa(a, b) { - for (var c = 0, d = ''; !(c >= b / 4); ) { - var e = F[(a + 4 * c) >> 2] - if (0 == e) break - ++c - 65536 <= e - ? ((e -= 65536), - (d += String.fromCharCode(55296 | (e >> 10), 56320 | (e & 1023)))) - : (d += String.fromCharCode(e)) - } - return d - } - function ra(a, b, c) { - void 0 === c && (c = 2147483647) - if (4 > c) return 0 - var d = b - c = d + c - 4 - for (var e = 0; e < a.length; ++e) { - var g = a.charCodeAt(e) - if (55296 <= g && 57343 >= g) { - var l = a.charCodeAt(++e) - g = (65536 + ((g & 1023) << 10)) | (l & 1023) + assert(ret.buffer) + return ret + } + if (process['argv'].length > 1) { + thisProgram = process['argv'][1].replace(/\\/g, '/') + } + arguments_ = process['argv'].slice(2) + quit_ = function (status) { + process['exit'](status) + } + Module['inspect'] = function () { + return '[Emscripten Module object]' + } + } else { + } + var out = Module['print'] || console.log.bind(console) + var err = Module['printErr'] || console.warn.bind(console) + for (key in moduleOverrides) { + if (moduleOverrides.hasOwnProperty(key)) { + Module[key] = moduleOverrides[key] + } + } + moduleOverrides = null + if (Module['arguments']) arguments_ = Module['arguments'] + if (Module['thisProgram']) thisProgram = Module['thisProgram'] + if (Module['quit']) quit_ = Module['quit'] + var wasmBinary + if (Module['wasmBinary']) wasmBinary = Module['wasmBinary'] + var noExitRuntime = Module['noExitRuntime'] || true + if (typeof WebAssembly !== 'object') { + abort('no native wasm support detected') + } + var wasmMemory + var ABORT = false + var EXITSTATUS + function assert(condition, text) { + if (!condition) { + abort('Assertion failed: ' + text) + } + } + var UTF8Decoder = new TextDecoder('utf8') + function UTF8ToString(ptr, maxBytesToRead) { + if (!ptr) return '' + var maxPtr = ptr + maxBytesToRead + for (var end = ptr; !(end >= maxPtr) && HEAPU8[end]; ) ++end + return UTF8Decoder.decode(HEAPU8.subarray(ptr, end)) + } + function stringToUTF8Array(str, heap, outIdx, maxBytesToWrite) { + if (!(maxBytesToWrite > 0)) return 0 + var startIdx = outIdx + var endIdx = outIdx + maxBytesToWrite - 1 + for (var i = 0; i < str.length; ++i) { + var u = str.charCodeAt(i) + if (u >= 55296 && u <= 57343) { + var u1 = str.charCodeAt(++i) + u = (65536 + ((u & 1023) << 10)) | (u1 & 1023) } - F[b >> 2] = g - b += 4 - if (b + 4 > c) break - } - F[b >> 2] = 0 - return b - d - } - function sa(a) { - for (var b = 0, c = 0; c < a.length; ++c) { - var d = a.charCodeAt(c) - 55296 <= d && 57343 >= d && ++c - b += 4 - } - return b - } - var G, H, B, D, C, F, I, ta, ua - function va(a) { - G = a - f.HEAP8 = H = new Int8Array(a) - f.HEAP16 = D = new Int16Array(a) - f.HEAP32 = F = new Int32Array(a) - f.HEAPU8 = B = new Uint8Array(a) - f.HEAPU16 = C = new Uint16Array(a) - f.HEAPU32 = I = new Uint32Array(a) - f.HEAPF32 = ta = new Float32Array(a) - f.HEAPF64 = ua = new Float64Array(a) - } - var wa = f.INITIAL_MEMORY || 16777216 - f.wasmMemory - ? (A = f.wasmMemory) - : (A = new WebAssembly.Memory({ initial: wa / 65536, maximum: 32768 })) - A && (G = A.buffer) - wa = G.byteLength - va(G) - var J, - xa = [], - ya = [], - za = [], - Aa = [] - function Ba() { - var a = f.preRun.shift() - xa.unshift(a) - } - var K = 0, - Ca = null, - L = null - f.preloadedImages = {} - f.preloadedAudios = {} - function u(a) { - if (f.onAbort) f.onAbort(a) - v(a) - ja = !0 - a = new WebAssembly.RuntimeError( - 'abort(' + a + '). Build with -s ASSERTIONS=1 for more info.' - ) - ba(a) - throw a + if (u <= 127) { + if (outIdx >= endIdx) break + heap[outIdx++] = u + } else if (u <= 2047) { + if (outIdx + 1 >= endIdx) break + heap[outIdx++] = 192 | (u >> 6) + heap[outIdx++] = 128 | (u & 63) + } else if (u <= 65535) { + if (outIdx + 2 >= endIdx) break + heap[outIdx++] = 224 | (u >> 12) + heap[outIdx++] = 128 | ((u >> 6) & 63) + heap[outIdx++] = 128 | (u & 63) + } else { + if (outIdx + 3 >= endIdx) break + heap[outIdx++] = 240 | (u >> 18) + heap[outIdx++] = 128 | ((u >> 12) & 63) + heap[outIdx++] = 128 | ((u >> 6) & 63) + heap[outIdx++] = 128 | (u & 63) + } + } + heap[outIdx] = 0 + return outIdx - startIdx + } + function stringToUTF8(str, outPtr, maxBytesToWrite) { + return stringToUTF8Array(str, HEAPU8, outPtr, maxBytesToWrite) + } + function lengthBytesUTF8(str) { + var len = 0 + for (var i = 0; i < str.length; ++i) { + var u = str.charCodeAt(i) + if (u >= 55296 && u <= 57343) + u = (65536 + ((u & 1023) << 10)) | (str.charCodeAt(++i) & 1023) + if (u <= 127) ++len + else if (u <= 2047) len += 2 + else if (u <= 65535) len += 3 + else len += 4 + } + return len + } + var UTF16Decoder = new TextDecoder('utf-16le') + function UTF16ToString(ptr, maxBytesToRead) { + var endPtr = ptr + var idx = endPtr >> 1 + var maxIdx = idx + maxBytesToRead / 2 + while (!(idx >= maxIdx) && HEAPU16[idx]) ++idx + endPtr = idx << 1 + return UTF16Decoder.decode(HEAPU8.subarray(ptr, endPtr)) + var str = '' + for (var i = 0; !(i >= maxBytesToRead / 2); ++i) { + var codeUnit = HEAP16[(ptr + i * 2) >> 1] + if (codeUnit == 0) break + str += String.fromCharCode(codeUnit) + } + return str + } + function stringToUTF16(str, outPtr, maxBytesToWrite) { + if (maxBytesToWrite === undefined) { + maxBytesToWrite = 2147483647 + } + if (maxBytesToWrite < 2) return 0 + maxBytesToWrite -= 2 + var startPtr = outPtr + var numCharsToWrite = + maxBytesToWrite < str.length * 2 ? maxBytesToWrite / 2 : str.length + for (var i = 0; i < numCharsToWrite; ++i) { + var codeUnit = str.charCodeAt(i) + HEAP16[outPtr >> 1] = codeUnit + outPtr += 2 + } + HEAP16[outPtr >> 1] = 0 + return outPtr - startPtr + } + function lengthBytesUTF16(str) { + return str.length * 2 + } + function UTF32ToString(ptr, maxBytesToRead) { + var i = 0 + var str = '' + while (!(i >= maxBytesToRead / 4)) { + var utf32 = HEAP32[(ptr + i * 4) >> 2] + if (utf32 == 0) break + ++i + if (utf32 >= 65536) { + var ch = utf32 - 65536 + str += String.fromCharCode(55296 | (ch >> 10), 56320 | (ch & 1023)) + } else { + str += String.fromCharCode(utf32) + } + } + return str + } + function stringToUTF32(str, outPtr, maxBytesToWrite) { + if (maxBytesToWrite === undefined) { + maxBytesToWrite = 2147483647 + } + if (maxBytesToWrite < 4) return 0 + var startPtr = outPtr + var endPtr = startPtr + maxBytesToWrite - 4 + for (var i = 0; i < str.length; ++i) { + var codeUnit = str.charCodeAt(i) + if (codeUnit >= 55296 && codeUnit <= 57343) { + var trailSurrogate = str.charCodeAt(++i) + codeUnit = + (65536 + ((codeUnit & 1023) << 10)) | (trailSurrogate & 1023) + } + HEAP32[outPtr >> 2] = codeUnit + outPtr += 4 + if (outPtr + 4 > endPtr) break + } + HEAP32[outPtr >> 2] = 0 + return outPtr - startPtr } - function Da() { - var a = M - return String.prototype.startsWith - ? a.startsWith('data:application/octet-stream;base64,') - : 0 === a.indexOf('data:application/octet-stream;base64,') + function lengthBytesUTF32(str) { + var len = 0 + for (var i = 0; i < str.length; ++i) { + var codeUnit = str.charCodeAt(i) + if (codeUnit >= 55296 && codeUnit <= 57343) ++i + len += 4 + } + return len + } + function alignUp(x, multiple) { + if (x % multiple > 0) { + x += multiple - (x % multiple) + } + return x } - var M = 'webp_node_enc.wasm' - if (!Da()) { - var Ea = M - M = f.locateFile ? f.locateFile(Ea, ca) : ca + Ea + var buffer, + HEAP8, + HEAPU8, + HEAP16, + HEAPU16, + HEAP32, + HEAPU32, + HEAPF32, + HEAPF64 + function updateGlobalBufferAndViews(buf) { + buffer = buf + Module['HEAP8'] = HEAP8 = new Int8Array(buf) + Module['HEAP16'] = HEAP16 = new Int16Array(buf) + Module['HEAP32'] = HEAP32 = new Int32Array(buf) + Module['HEAPU8'] = HEAPU8 = new Uint8Array(buf) + Module['HEAPU16'] = HEAPU16 = new Uint16Array(buf) + Module['HEAPU32'] = HEAPU32 = new Uint32Array(buf) + Module['HEAPF32'] = HEAPF32 = new Float32Array(buf) + Module['HEAPF64'] = HEAPF64 = new Float64Array(buf) } - function Fa() { + var INITIAL_MEMORY = Module['INITIAL_MEMORY'] || 16777216 + var wasmTable + var __ATPRERUN__ = [] + var __ATINIT__ = [] + var __ATPOSTRUN__ = [] + var runtimeInitialized = false + function preRun() { + if (Module['preRun']) { + if (typeof Module['preRun'] == 'function') + Module['preRun'] = [Module['preRun']] + while (Module['preRun'].length) { + addOnPreRun(Module['preRun'].shift()) + } + } + callRuntimeCallbacks(__ATPRERUN__) + } + function initRuntime() { + runtimeInitialized = true + callRuntimeCallbacks(__ATINIT__) + } + function postRun() { + if (Module['postRun']) { + if (typeof Module['postRun'] == 'function') + Module['postRun'] = [Module['postRun']] + while (Module['postRun'].length) { + addOnPostRun(Module['postRun'].shift()) + } + } + callRuntimeCallbacks(__ATPOSTRUN__) + } + function addOnPreRun(cb) { + __ATPRERUN__.unshift(cb) + } + function addOnInit(cb) { + __ATINIT__.unshift(cb) + } + function addOnPostRun(cb) { + __ATPOSTRUN__.unshift(cb) + } + var runDependencies = 0 + var runDependencyWatcher = null + var dependenciesFulfilled = null + function addRunDependency(id) { + runDependencies++ + if (Module['monitorRunDependencies']) { + Module['monitorRunDependencies'](runDependencies) + } + } + function removeRunDependency(id) { + runDependencies-- + if (Module['monitorRunDependencies']) { + Module['monitorRunDependencies'](runDependencies) + } + if (runDependencies == 0) { + if (runDependencyWatcher !== null) { + clearInterval(runDependencyWatcher) + runDependencyWatcher = null + } + if (dependenciesFulfilled) { + var callback = dependenciesFulfilled + dependenciesFulfilled = null + callback() + } + } + } + Module['preloadedImages'] = {} + Module['preloadedAudios'] = {} + function abort(what) { + if (Module['onAbort']) { + Module['onAbort'](what) + } + what += '' + err(what) + ABORT = true + EXITSTATUS = 1 + what = 'abort(' + what + '). Build with -s ASSERTIONS=1 for more info.' + var e = new WebAssembly.RuntimeError(what) + readyPromiseReject(e) + throw e + } + var dataURIPrefix = 'data:application/octet-stream;base64,' + function isDataURI(filename) { + return filename.startsWith(dataURIPrefix) + } + if (Module['locateFile']) { + var wasmBinaryFile = 'webp_node_enc.wasm' + if (!isDataURI(wasmBinaryFile)) { + wasmBinaryFile = locateFile(wasmBinaryFile) + } + } else { + throw new Error('invariant') + } + function getBinary(file) { try { - if (z) return new Uint8Array(z) - if (fa) return fa(M) - throw 'both async and sync fetching of the wasm failed' - } catch (a) { - u(a) - } - } - function N(a) { - for (; 0 < a.length; ) { - var b = a.shift() - if ('function' == typeof b) b(f) - else { - var c = b.L - 'number' === typeof c - ? void 0 === b.G - ? J.get(c)() - : J.get(c)(b.G) - : c(void 0 === b.G ? null : b.G) + if (file == wasmBinaryFile && wasmBinary) { + return new Uint8Array(wasmBinary) + } + if (readBinary) { + return readBinary(file) + } else { + throw 'both async and sync fetching of the wasm failed' } + } catch (err) { + abort(err) } } - var O = {} - function Ga(a) { - for (; a.length; ) { - var b = a.pop() - a.pop()(b) + function getBinaryPromise() { + if (!wasmBinary && (ENVIRONMENT_IS_WEB || ENVIRONMENT_IS_WORKER)) { + if (typeof fetch === 'function') { + return fetch(wasmBinaryFile, { credentials: 'same-origin' }) + .then(function (response) { + if (!response['ok']) { + throw ( + "failed to load wasm binary file at '" + wasmBinaryFile + "'" + ) + } + return response['arrayBuffer']() + }) + .catch(function () { + return getBinary(wasmBinaryFile) + }) + } } + return Promise.resolve().then(function () { + return getBinary(wasmBinaryFile) + }) } - function P(a) { - return this.fromWireType(I[a >> 2]) + function createWasm() { + var info = { a: asmLibraryArg } + function receiveInstance(instance, module) { + var exports = instance.exports + Module['asm'] = exports + wasmMemory = Module['asm']['x'] + updateGlobalBufferAndViews(wasmMemory.buffer) + wasmTable = Module['asm']['D'] + addOnInit(Module['asm']['y']) + removeRunDependency('wasm-instantiate') + } + addRunDependency('wasm-instantiate') + function receiveInstantiationResult(result) { + receiveInstance(result['instance']) + } + function instantiateArrayBuffer(receiver) { + return getBinaryPromise() + .then(function (binary) { + var result = WebAssembly.instantiate(binary, info) + return result + }) + .then(receiver, function (reason) { + err('failed to asynchronously prepare wasm: ' + reason) + abort(reason) + }) + } + function instantiateAsync() { + if ( + !wasmBinary && + typeof WebAssembly.instantiateStreaming === 'function' && + !isDataURI(wasmBinaryFile) && + typeof fetch === 'function' + ) { + return fetch(wasmBinaryFile, { credentials: 'same-origin' }).then( + function (response) { + var result = WebAssembly.instantiateStreaming(response, info) + return result.then(receiveInstantiationResult, function (reason) { + err('wasm streaming compile failed: ' + reason) + err('falling back to ArrayBuffer instantiation') + return instantiateArrayBuffer(receiveInstantiationResult) + }) + } + ) + } else { + return instantiateArrayBuffer(receiveInstantiationResult) + } + } + if (Module['instantiateWasm']) { + try { + var exports = Module['instantiateWasm'](info, receiveInstance) + return exports + } catch (e) { + err('Module.instantiateWasm callback failed with error: ' + e) + return false + } + } + instantiateAsync().catch(readyPromiseReject) + return {} } - var Q = {}, - R = {}, - S = {} - function Ha(a) { - if (void 0 === a) return '_unknown' - a = a.replace(/[^a-zA-Z0-9_]/g, '$') - var b = a.charCodeAt(0) - return 48 <= b && 57 >= b ? '_' + a : a + function callRuntimeCallbacks(callbacks) { + while (callbacks.length > 0) { + var callback = callbacks.shift() + if (typeof callback == 'function') { + callback(Module) + continue + } + var func = callback.func + if (typeof func === 'number') { + if (callback.arg === undefined) { + wasmTable.get(func)() + } else { + wasmTable.get(func)(callback.arg) + } + } else { + func(callback.arg === undefined ? null : callback.arg) + } + } } - function Ia(a, b) { - a = Ha(a) + function _atexit(func, arg) {} + function ___cxa_thread_atexit(a0, a1) { + return _atexit(a0, a1) + } + var structRegistrations = {} + function runDestructors(destructors) { + while (destructors.length) { + var ptr = destructors.pop() + var del = destructors.pop() + del(ptr) + } + } + function simpleReadValueFromPointer(pointer) { + return this['fromWireType'](HEAPU32[pointer >> 2]) + } + var awaitingDependencies = {} + var registeredTypes = {} + var typeDependencies = {} + var char_0 = 48 + var char_9 = 57 + function makeLegalFunctionName(name) { + if (undefined === name) { + return '_unknown' + } + name = name.replace(/[^a-zA-Z0-9_]/g, '$') + var f = name.charCodeAt(0) + if (f >= char_0 && f <= char_9) { + return '_' + name + } else { + return name + } + } + function createNamedFunction(name, body) { + name = makeLegalFunctionName(name) return new Function( 'body', 'return function ' + - a + - '() {\n "use strict"; return body.apply(this, arguments);\n};\n' - )(b) - } - function Ja(a) { - var b = Error, - c = Ia(a, function (d) { - this.name = a - this.message = d - d = Error(d).stack - void 0 !== d && - (this.stack = - this.toString() + '\n' + d.replace(/^Error(:[^\n]*)?\n/, '')) - }) - c.prototype = Object.create(b.prototype) - c.prototype.constructor = c - c.prototype.toString = function () { - return void 0 === this.message - ? this.name - : this.name + ': ' + this.message - } - return c - } - var Ka = void 0 - function La(a, b, c) { - function d(h) { - h = c(h) - if (h.length !== a.length) - throw new Ka('Mismatched type converter count') - for (var k = 0; k < a.length; ++k) U(a[k], h[k]) - } - a.forEach(function (h) { - S[h] = b + name + + '() {\n' + + ' "use strict";' + + ' return body.apply(this, arguments);\n' + + '};\n' + )(body) + } + function extendError(baseErrorType, errorName) { + var errorClass = createNamedFunction(errorName, function (message) { + this.name = errorName + this.message = message + var stack = new Error(message).stack + if (stack !== undefined) { + this.stack = + this.toString() + '\n' + stack.replace(/^Error(:[^\n]*)?\n/, '') + } + }) + errorClass.prototype = Object.create(baseErrorType.prototype) + errorClass.prototype.constructor = errorClass + errorClass.prototype.toString = function () { + if (this.message === undefined) { + return this.name + } else { + return this.name + ': ' + this.message + } + } + return errorClass + } + var InternalError = undefined + function throwInternalError(message) { + throw new InternalError(message) + } + function whenDependentTypesAreResolved( + myTypes, + dependentTypes, + getTypeConverters + ) { + myTypes.forEach(function (type) { + typeDependencies[type] = dependentTypes }) - var e = Array(b.length), - g = [], - l = 0 - b.forEach(function (h, k) { - R.hasOwnProperty(h) - ? (e[k] = R[h]) - : (g.push(h), - Q.hasOwnProperty(h) || (Q[h] = []), - Q[h].push(function () { - e[k] = R[h] - ++l - l === g.length && d(e) - })) + function onComplete(typeConverters) { + var myTypeConverters = getTypeConverters(typeConverters) + if (myTypeConverters.length !== myTypes.length) { + throwInternalError('Mismatched type converter count') + } + for (var i = 0; i < myTypes.length; ++i) { + registerType(myTypes[i], myTypeConverters[i]) + } + } + var typeConverters = new Array(dependentTypes.length) + var unregisteredTypes = [] + var registered = 0 + dependentTypes.forEach(function (dt, i) { + if (registeredTypes.hasOwnProperty(dt)) { + typeConverters[i] = registeredTypes[dt] + } else { + unregisteredTypes.push(dt) + if (!awaitingDependencies.hasOwnProperty(dt)) { + awaitingDependencies[dt] = [] + } + awaitingDependencies[dt].push(function () { + typeConverters[i] = registeredTypes[dt] + ++registered + if (registered === unregisteredTypes.length) { + onComplete(typeConverters) + } + }) + } }) - 0 === g.length && d(e) + if (0 === unregisteredTypes.length) { + onComplete(typeConverters) + } + } + function __embind_finalize_value_object(structType) { + var reg = structRegistrations[structType] + delete structRegistrations[structType] + var rawConstructor = reg.rawConstructor + var rawDestructor = reg.rawDestructor + var fieldRecords = reg.fields + var fieldTypes = fieldRecords + .map(function (field) { + return field.getterReturnType + }) + .concat( + fieldRecords.map(function (field) { + return field.setterArgumentType + }) + ) + whenDependentTypesAreResolved( + [structType], + fieldTypes, + function (fieldTypes) { + var fields = {} + fieldRecords.forEach(function (field, i) { + var fieldName = field.fieldName + var getterReturnType = fieldTypes[i] + var getter = field.getter + var getterContext = field.getterContext + var setterArgumentType = fieldTypes[i + fieldRecords.length] + var setter = field.setter + var setterContext = field.setterContext + fields[fieldName] = { + read: function (ptr) { + return getterReturnType['fromWireType']( + getter(getterContext, ptr) + ) + }, + write: function (ptr, o) { + var destructors = [] + setter( + setterContext, + ptr, + setterArgumentType['toWireType'](destructors, o) + ) + runDestructors(destructors) + }, + } + }) + return [ + { + name: reg.name, + fromWireType: function (ptr) { + var rv = {} + for (var i in fields) { + rv[i] = fields[i].read(ptr) + } + rawDestructor(ptr) + return rv + }, + toWireType: function (destructors, o) { + for (var fieldName in fields) { + if (!(fieldName in o)) { + throw new TypeError('Missing field: "' + fieldName + '"') + } + } + var ptr = rawConstructor() + for (fieldName in fields) { + fields[fieldName].write(ptr, o[fieldName]) + } + if (destructors !== null) { + destructors.push(rawDestructor, ptr) + } + return ptr + }, + argPackAdvance: 8, + readValueFromPointer: simpleReadValueFromPointer, + destructorFunction: rawDestructor, + }, + ] + } + ) } - function Ma(a) { - switch (a) { + function __embind_register_bigint( + primitiveType, + name, + size, + minRange, + maxRange + ) {} + function getShiftFromSize(size) { + switch (size) { case 1: return 0 case 2: @@ -303,920 +667,1160 @@ var Module = (function () { case 8: return 3 default: - throw new TypeError('Unknown type size: ' + a) + throw new TypeError('Unknown type size: ' + size) + } + } + function embind_init_charCodes() { + var codes = new Array(256) + for (var i = 0; i < 256; ++i) { + codes[i] = String.fromCharCode(i) } + embind_charCodes = codes } - var Na = void 0 - function V(a) { - for (var b = ''; B[a]; ) b += Na[B[a++]] - return b + var embind_charCodes = undefined + function readLatin1String(ptr) { + var ret = '' + var c = ptr + while (HEAPU8[c]) { + ret += embind_charCodes[HEAPU8[c++]] + } + return ret } - var Oa = void 0 - function W(a) { - throw new Oa(a) + var BindingError = undefined + function throwBindingError(message) { + throw new BindingError(message) } - function U(a, b, c) { - c = c || {} - if (!('argPackAdvance' in b)) + function registerType(rawType, registeredInstance, options) { + options = options || {} + if (!('argPackAdvance' in registeredInstance)) { throw new TypeError( 'registerType registeredInstance requires argPackAdvance' ) - var d = b.name - a || W('type "' + d + '" must have a positive integer typeid pointer') - if (R.hasOwnProperty(a)) { - if (c.P) return - W("Cannot register type '" + d + "' twice") - } - R[a] = b - delete S[a] - Q.hasOwnProperty(a) && - ((b = Q[a]), - delete Q[a], - b.forEach(function (e) { - e() - })) - } - var Pa = [], - X = [{}, { value: void 0 }, { value: null }, { value: !0 }, { value: !1 }] - function Qa(a) { - 4 < a && 0 === --X[a].H && ((X[a] = void 0), Pa.push(a)) - } - function Ra(a) { - switch (a) { - case void 0: + } + var name = registeredInstance.name + if (!rawType) { + throwBindingError( + 'type "' + name + '" must have a positive integer typeid pointer' + ) + } + if (registeredTypes.hasOwnProperty(rawType)) { + if (options.ignoreDuplicateRegistrations) { + return + } else { + throwBindingError("Cannot register type '" + name + "' twice") + } + } + registeredTypes[rawType] = registeredInstance + delete typeDependencies[rawType] + if (awaitingDependencies.hasOwnProperty(rawType)) { + var callbacks = awaitingDependencies[rawType] + delete awaitingDependencies[rawType] + callbacks.forEach(function (cb) { + cb() + }) + } + } + function __embind_register_bool( + rawType, + name, + size, + trueValue, + falseValue + ) { + var shift = getShiftFromSize(size) + name = readLatin1String(name) + registerType(rawType, { + name: name, + fromWireType: function (wt) { + return !!wt + }, + toWireType: function (destructors, o) { + return o ? trueValue : falseValue + }, + argPackAdvance: 8, + readValueFromPointer: function (pointer) { + var heap + if (size === 1) { + heap = HEAP8 + } else if (size === 2) { + heap = HEAP16 + } else if (size === 4) { + heap = HEAP32 + } else { + throw new TypeError('Unknown boolean type size: ' + name) + } + return this['fromWireType'](heap[pointer >> shift]) + }, + destructorFunction: null, + }) + } + var emval_free_list = [] + var emval_handle_array = [ + {}, + { value: undefined }, + { value: null }, + { value: true }, + { value: false }, + ] + function __emval_decref(handle) { + if (handle > 4 && 0 === --emval_handle_array[handle].refcount) { + emval_handle_array[handle] = undefined + emval_free_list.push(handle) + } + } + function count_emval_handles() { + var count = 0 + for (var i = 5; i < emval_handle_array.length; ++i) { + if (emval_handle_array[i] !== undefined) { + ++count + } + } + return count + } + function get_first_emval() { + for (var i = 5; i < emval_handle_array.length; ++i) { + if (emval_handle_array[i] !== undefined) { + return emval_handle_array[i] + } + } + return null + } + function init_emval() { + Module['count_emval_handles'] = count_emval_handles + Module['get_first_emval'] = get_first_emval + } + function __emval_register(value) { + switch (value) { + case undefined: { return 1 - case null: + } + case null: { return 2 - case !0: + } + case true: { return 3 - case !1: + } + case false: { return 4 - default: - var b = Pa.length ? Pa.pop() : X.length - X[b] = { H: 1, value: a } - return b - } - } - function Sa(a, b) { - var c = f - if (void 0 === c[a].F) { - var d = c[a] - c[a] = function () { - c[a].F.hasOwnProperty(arguments.length) || - W( + } + default: { + var handle = emval_free_list.length + ? emval_free_list.pop() + : emval_handle_array.length + emval_handle_array[handle] = { refcount: 1, value: value } + return handle + } + } + } + function __embind_register_emval(rawType, name) { + name = readLatin1String(name) + registerType(rawType, { + name: name, + fromWireType: function (handle) { + var rv = emval_handle_array[handle].value + __emval_decref(handle) + return rv + }, + toWireType: function (destructors, value) { + return __emval_register(value) + }, + argPackAdvance: 8, + readValueFromPointer: simpleReadValueFromPointer, + destructorFunction: null, + }) + } + function ensureOverloadTable(proto, methodName, humanName) { + if (undefined === proto[methodName].overloadTable) { + var prevFunc = proto[methodName] + proto[methodName] = function () { + if ( + !proto[methodName].overloadTable.hasOwnProperty(arguments.length) + ) { + throwBindingError( "Function '" + - b + + humanName + "' called with an invalid number of arguments (" + arguments.length + ') - expects one of (' + - c[a].F + + proto[methodName].overloadTable + ')!' ) - return c[a].F[arguments.length].apply(this, arguments) + } + return proto[methodName].overloadTable[arguments.length].apply( + this, + arguments + ) } - c[a].F = [] - c[a].F[d.J] = d - } - } - function Ta(a, b, c) { - f.hasOwnProperty(a) - ? ((void 0 === c || (void 0 !== f[a].F && void 0 !== f[a].F[c])) && - W("Cannot register public name '" + a + "' twice"), - Sa(a, a), - f.hasOwnProperty(c) && - W( - 'Cannot register multiple overloads of a function with the same number of arguments (' + - c + - ')!' - ), - (f[a].F[c] = b)) - : ((f[a] = b), void 0 !== c && (f[a].X = c)) + proto[methodName].overloadTable = [] + proto[methodName].overloadTable[prevFunc.argCount] = prevFunc + } + } + function exposePublicSymbol(name, value, numArguments) { + if (Module.hasOwnProperty(name)) { + if ( + undefined === numArguments || + (undefined !== Module[name].overloadTable && + undefined !== Module[name].overloadTable[numArguments]) + ) { + throwBindingError("Cannot register public name '" + name + "' twice") + } + ensureOverloadTable(Module, name, name) + if (Module.hasOwnProperty(numArguments)) { + throwBindingError( + 'Cannot register multiple overloads of a function with the same number of arguments (' + + numArguments + + ')!' + ) + } + Module[name].overloadTable[numArguments] = value + } else { + Module[name] = value + if (undefined !== numArguments) { + Module[name].numArguments = numArguments + } + } } - function Ua(a, b, c) { - switch (b) { + function enumReadValueFromPointer(name, shift, signed) { + switch (shift) { case 0: - return function (d) { - return this.fromWireType((c ? H : B)[d]) + return function (pointer) { + var heap = signed ? HEAP8 : HEAPU8 + return this['fromWireType'](heap[pointer]) } case 1: - return function (d) { - return this.fromWireType((c ? D : C)[d >> 1]) + return function (pointer) { + var heap = signed ? HEAP16 : HEAPU16 + return this['fromWireType'](heap[pointer >> 1]) } case 2: - return function (d) { - return this.fromWireType((c ? F : I)[d >> 2]) + return function (pointer) { + var heap = signed ? HEAP32 : HEAPU32 + return this['fromWireType'](heap[pointer >> 2]) } default: - throw new TypeError('Unknown integer type: ' + a) + throw new TypeError('Unknown integer type: ' + name) } } - function Va(a) { - a = Wa(a) - var b = V(a) - Y(a) - return b + function __embind_register_enum(rawType, name, size, isSigned) { + var shift = getShiftFromSize(size) + name = readLatin1String(name) + function ctor() {} + ctor.values = {} + registerType(rawType, { + name: name, + constructor: ctor, + fromWireType: function (c) { + return this.constructor.values[c] + }, + toWireType: function (destructors, c) { + return c.value + }, + argPackAdvance: 8, + readValueFromPointer: enumReadValueFromPointer(name, shift, isSigned), + destructorFunction: null, + }) + exposePublicSymbol(name, ctor) + } + function getTypeName(type) { + var ptr = ___getTypeName(type) + var rv = readLatin1String(ptr) + _free(ptr) + return rv + } + function requireRegisteredType(rawType, humanName) { + var impl = registeredTypes[rawType] + if (undefined === impl) { + throwBindingError( + humanName + ' has unknown type ' + getTypeName(rawType) + ) + } + return impl } - function Xa(a, b) { - var c = R[a] - void 0 === c && W(b + ' has unknown type ' + Va(a)) - return c + function __embind_register_enum_value(rawEnumType, name, enumValue) { + var enumType = requireRegisteredType(rawEnumType, 'enum') + name = readLatin1String(name) + var Enum = enumType.constructor + var Value = Object.create(enumType.constructor.prototype, { + value: { value: enumValue }, + constructor: { + value: createNamedFunction( + enumType.name + '_' + name, + function () {} + ), + }, + }) + Enum.values[enumValue] = Value + Enum[name] = Value } - function Ya(a) { - if (null === a) return 'null' - var b = typeof a - return 'object' === b || 'array' === b || 'function' === b - ? a.toString() - : '' + a + function _embind_repr(v) { + if (v === null) { + return 'null' + } + var t = typeof v + if (t === 'object' || t === 'array' || t === 'function') { + return v.toString() + } else { + return '' + v + } } - function Za(a, b) { - switch (b) { + function floatReadValueFromPointer(name, shift) { + switch (shift) { case 2: - return function (c) { - return this.fromWireType(ta[c >> 2]) + return function (pointer) { + return this['fromWireType'](HEAPF32[pointer >> 2]) } case 3: - return function (c) { - return this.fromWireType(ua[c >> 3]) + return function (pointer) { + return this['fromWireType'](HEAPF64[pointer >> 3]) } default: - throw new TypeError('Unknown float type: ' + a) + throw new TypeError('Unknown float type: ' + name) } } - function $a(a) { - var b = Function - if (!(b instanceof Function)) + function __embind_register_float(rawType, name, size) { + var shift = getShiftFromSize(size) + name = readLatin1String(name) + registerType(rawType, { + name: name, + fromWireType: function (value) { + return value + }, + toWireType: function (destructors, value) { + if (typeof value !== 'number' && typeof value !== 'boolean') { + throw new TypeError( + 'Cannot convert "' + _embind_repr(value) + '" to ' + this.name + ) + } + return value + }, + argPackAdvance: 8, + readValueFromPointer: floatReadValueFromPointer(name, shift), + destructorFunction: null, + }) + } + function new_(constructor, argumentList) { + if (!(constructor instanceof Function)) { throw new TypeError( 'new_ called with constructor type ' + - typeof b + + typeof constructor + ' which is not a function' ) - var c = Ia(b.name || 'unknownFunctionName', function () {}) - c.prototype = b.prototype - c = new c() - a = b.apply(c, a) - return a instanceof Object ? a : c - } - function ab(a, b) { - for (var c = [], d = 0; d < a; d++) c.push(F[(b >> 2) + d]) - return c - } - function bb(a, b) { - 0 <= a.indexOf('j') || - u('Assertion failed: getDynCaller should only be called with i64 sigs') - var c = [] + } + var dummy = createNamedFunction( + constructor.name || 'unknownFunctionName', + function () {} + ) + dummy.prototype = constructor.prototype + var obj = new dummy() + var r = constructor.apply(obj, argumentList) + return r instanceof Object ? r : obj + } + function craftInvokerFunction( + humanName, + argTypes, + classType, + cppInvokerFunc, + cppTargetFunc + ) { + var argCount = argTypes.length + if (argCount < 2) { + throwBindingError( + "argTypes array size mismatch! Must at least get return value and 'this' types!" + ) + } + var isClassMethodFunc = argTypes[1] !== null && classType !== null + var needsDestructorStack = false + for (var i = 1; i < argTypes.length; ++i) { + if ( + argTypes[i] !== null && + argTypes[i].destructorFunction === undefined + ) { + needsDestructorStack = true + break + } + } + var returns = argTypes[0].name !== 'void' + var argsList = '' + var argsListWired = '' + for (var i = 0; i < argCount - 2; ++i) { + argsList += (i !== 0 ? ', ' : '') + 'arg' + i + argsListWired += (i !== 0 ? ', ' : '') + 'arg' + i + 'Wired' + } + var invokerFnBody = + 'return function ' + + makeLegalFunctionName(humanName) + + '(' + + argsList + + ') {\n' + + 'if (arguments.length !== ' + + (argCount - 2) + + ') {\n' + + "throwBindingError('function " + + humanName + + " called with ' + arguments.length + ' arguments, expected " + + (argCount - 2) + + " args!');\n" + + '}\n' + if (needsDestructorStack) { + invokerFnBody += 'var destructors = [];\n' + } + var dtorStack = needsDestructorStack ? 'destructors' : 'null' + var args1 = [ + 'throwBindingError', + 'invoker', + 'fn', + 'runDestructors', + 'retType', + 'classParam', + ] + var args2 = [ + throwBindingError, + cppInvokerFunc, + cppTargetFunc, + runDestructors, + argTypes[0], + argTypes[1], + ] + if (isClassMethodFunc) { + invokerFnBody += + 'var thisWired = classParam.toWireType(' + dtorStack + ', this);\n' + } + for (var i = 0; i < argCount - 2; ++i) { + invokerFnBody += + 'var arg' + + i + + 'Wired = argType' + + i + + '.toWireType(' + + dtorStack + + ', arg' + + i + + '); // ' + + argTypes[i + 2].name + + '\n' + args1.push('argType' + i) + args2.push(argTypes[i + 2]) + } + if (isClassMethodFunc) { + argsListWired = + 'thisWired' + (argsListWired.length > 0 ? ', ' : '') + argsListWired + } + invokerFnBody += + (returns ? 'var rv = ' : '') + + 'invoker(fn' + + (argsListWired.length > 0 ? ', ' : '') + + argsListWired + + ');\n' + if (needsDestructorStack) { + invokerFnBody += 'runDestructors(destructors);\n' + } else { + for (var i = isClassMethodFunc ? 1 : 2; i < argTypes.length; ++i) { + var paramName = i === 1 ? 'thisWired' : 'arg' + (i - 2) + 'Wired' + if (argTypes[i].destructorFunction !== null) { + invokerFnBody += + paramName + + '_dtor(' + + paramName + + '); // ' + + argTypes[i].name + + '\n' + args1.push(paramName + '_dtor') + args2.push(argTypes[i].destructorFunction) + } + } + } + if (returns) { + invokerFnBody += + 'var ret = retType.fromWireType(rv);\n' + 'return ret;\n' + } else { + } + invokerFnBody += '}\n' + args1.push(invokerFnBody) + var invokerFunction = new_(Function, args1).apply(null, args2) + return invokerFunction + } + function heap32VectorToArray(count, firstElement) { + var array = [] + for (var i = 0; i < count; i++) { + array.push(HEAP32[(firstElement >> 2) + i]) + } + return array + } + function replacePublicSymbol(name, value, numArguments) { + if (!Module.hasOwnProperty(name)) { + throwInternalError('Replacing nonexistant public symbol') + } + if ( + undefined !== Module[name].overloadTable && + undefined !== numArguments + ) { + Module[name].overloadTable[numArguments] = value + } else { + Module[name] = value + Module[name].argCount = numArguments + } + } + function dynCallLegacy(sig, ptr, args) { + var f = Module['dynCall_' + sig] + return args && args.length + ? f.apply(null, [ptr].concat(args)) + : f.call(null, ptr) + } + function dynCall(sig, ptr, args) { + if (sig.includes('j')) { + return dynCallLegacy(sig, ptr, args) + } + return wasmTable.get(ptr).apply(null, args) + } + function getDynCaller(sig, ptr) { + var argCache = [] return function () { - c.length = arguments.length - for (var d = 0; d < arguments.length; d++) c[d] = arguments[d] - var e - ;-1 != a.indexOf('j') - ? (e = - c && c.length - ? f['dynCall_' + a].apply(null, [b].concat(c)) - : f['dynCall_' + a].call(null, b)) - : (e = J.get(b).apply(null, c)) - return e - } - } - function Z(a, b) { - a = V(a) - var c = -1 != a.indexOf('j') ? bb(a, b) : J.get(b) - 'function' !== typeof c && - W('unknown function pointer with signature ' + a + ': ' + b) - return c - } - var cb = void 0 - function db(a, b) { - function c(g) { - e[g] || R[g] || (S[g] ? S[g].forEach(c) : (d.push(g), (e[g] = !0))) - } - var d = [], - e = {} - b.forEach(c) - throw new cb(a + ': ' + d.map(Va).join([', '])) - } - function eb(a, b, c) { - switch (b) { + argCache.length = arguments.length + for (var i = 0; i < arguments.length; i++) { + argCache[i] = arguments[i] + } + return dynCall(sig, ptr, argCache) + } + } + function embind__requireFunction(signature, rawFunction) { + signature = readLatin1String(signature) + function makeDynCaller() { + if (signature.includes('j')) { + return getDynCaller(signature, rawFunction) + } + return wasmTable.get(rawFunction) + } + var fp = makeDynCaller() + if (typeof fp !== 'function') { + throwBindingError( + 'unknown function pointer with signature ' + + signature + + ': ' + + rawFunction + ) + } + return fp + } + var UnboundTypeError = undefined + function throwUnboundTypeError(message, types) { + var unboundTypes = [] + var seen = {} + function visit(type) { + if (seen[type]) { + return + } + if (registeredTypes[type]) { + return + } + if (typeDependencies[type]) { + typeDependencies[type].forEach(visit) + return + } + unboundTypes.push(type) + seen[type] = true + } + types.forEach(visit) + throw new UnboundTypeError( + message + ': ' + unboundTypes.map(getTypeName).join([', ']) + ) + } + function __embind_register_function( + name, + argCount, + rawArgTypesAddr, + signature, + rawInvoker, + fn + ) { + var argTypes = heap32VectorToArray(argCount, rawArgTypesAddr) + name = readLatin1String(name) + rawInvoker = embind__requireFunction(signature, rawInvoker) + exposePublicSymbol( + name, + function () { + throwUnboundTypeError( + 'Cannot call ' + name + ' due to unbound types', + argTypes + ) + }, + argCount - 1 + ) + whenDependentTypesAreResolved([], argTypes, function (argTypes) { + var invokerArgsArray = [argTypes[0], null].concat(argTypes.slice(1)) + replacePublicSymbol( + name, + craftInvokerFunction(name, invokerArgsArray, null, rawInvoker, fn), + argCount - 1 + ) + return [] + }) + } + function integerReadValueFromPointer(name, shift, signed) { + switch (shift) { case 0: - return c - ? function (d) { - return H[d] + return signed + ? function readS8FromPointer(pointer) { + return HEAP8[pointer] } - : function (d) { - return B[d] + : function readU8FromPointer(pointer) { + return HEAPU8[pointer] } case 1: - return c - ? function (d) { - return D[d >> 1] + return signed + ? function readS16FromPointer(pointer) { + return HEAP16[pointer >> 1] } - : function (d) { - return C[d >> 1] + : function readU16FromPointer(pointer) { + return HEAPU16[pointer >> 1] } case 2: - return c - ? function (d) { - return F[d >> 2] + return signed + ? function readS32FromPointer(pointer) { + return HEAP32[pointer >> 2] } - : function (d) { - return I[d >> 2] + : function readU32FromPointer(pointer) { + return HEAPU32[pointer >> 2] } default: - throw new TypeError('Unknown integer type: ' + a) - } - } - var fb = {} - function gb() { - return 'object' === typeof globalThis - ? globalThis - : Function('return this')() - } - var hb = {} - Ka = f.InternalError = Ja('InternalError') - for (var ib = Array(256), jb = 0; 256 > jb; ++jb) - ib[jb] = String.fromCharCode(jb) - Na = ib - Oa = f.BindingError = Ja('BindingError') - f.count_emval_handles = function () { - for (var a = 0, b = 5; b < X.length; ++b) void 0 !== X[b] && ++a - return a - } - f.get_first_emval = function () { - for (var a = 5; a < X.length; ++a) if (void 0 !== X[a]) return X[a] - return null + throw new TypeError('Unknown integer type: ' + name) + } } - cb = f.UnboundTypeError = Ja('UnboundTypeError') - ya.push({ - L: function () { - kb() - }, - }) - var mb = { - w: function () {}, - m: function (a) { - var b = O[a] - delete O[a] - var c = b.R, - d = b.S, - e = b.I, - g = e - .map(function (l) { - return l.O - }) - .concat( - e.map(function (l) { - return l.U - }) - ) - La([a], g, function (l) { - var h = {} - e.forEach(function (k, m) { - var n = l[m], - q = k.M, - w = k.N, - x = l[m + e.length], - p = k.T, - da = k.V - h[k.K] = { - read: function (y) { - return n.fromWireType(q(w, y)) - }, - write: function (y, E) { - var T = [] - p(da, y, x.toWireType(T, E)) - Ga(T) - }, - } - }) - return [ - { - name: b.name, - fromWireType: function (k) { - var m = {}, - n - for (n in h) m[n] = h[n].read(k) - d(k) - return m - }, - toWireType: function (k, m) { - for (var n in h) - if (!(n in m)) - throw new TypeError('Missing field: "' + n + '"') - var q = c() - for (n in h) h[n].write(q, m[n]) - null !== k && k.push(d, q) - return q - }, - argPackAdvance: 8, - readValueFromPointer: P, - D: d, - }, - ] - }) - }, - s: function (a, b, c, d, e) { - var g = Ma(c) - b = V(b) - U(a, { - name: b, - fromWireType: function (l) { - return !!l - }, - toWireType: function (l, h) { - return h ? d : e - }, - argPackAdvance: 8, - readValueFromPointer: function (l) { - if (1 === c) var h = H - else if (2 === c) h = D - else if (4 === c) h = F - else throw new TypeError('Unknown boolean type size: ' + b) - return this.fromWireType(h[l >> g]) - }, - D: null, - }) - }, - r: function (a, b) { - b = V(b) - U(a, { - name: b, - fromWireType: function (c) { - var d = X[c].value - Qa(c) - return d - }, - toWireType: function (c, d) { - return Ra(d) - }, - argPackAdvance: 8, - readValueFromPointer: P, - D: null, - }) - }, - o: function (a, b, c, d) { - function e() {} - c = Ma(c) - b = V(b) - e.values = {} - U(a, { - name: b, - constructor: e, - fromWireType: function (g) { - return this.constructor.values[g] - }, - toWireType: function (g, l) { - return l.value - }, - argPackAdvance: 8, - readValueFromPointer: Ua(b, c, d), - D: null, - }) - Ta(b, e) - }, - f: function (a, b, c) { - var d = Xa(a, 'enum') - b = V(b) - a = d.constructor - d = Object.create(d.constructor.prototype, { - value: { value: c }, - constructor: { value: Ia(d.name + '_' + b, function () {}) }, - }) - a.values[c] = d - a[b] = d - }, - k: function (a, b, c) { - c = Ma(c) - b = V(b) - U(a, { - name: b, - fromWireType: function (d) { - return d - }, - toWireType: function (d, e) { - if ('number' !== typeof e && 'boolean' !== typeof e) - throw new TypeError( - 'Cannot convert "' + Ya(e) + '" to ' + this.name - ) - return e - }, - argPackAdvance: 8, - readValueFromPointer: Za(b, c), - D: null, - }) - }, - i: function (a, b, c, d, e, g) { - var l = ab(b, c) - a = V(a) - e = Z(d, e) - Ta( - a, - function () { - db('Cannot call ' + a + ' due to unbound types', l) - }, - b - 1 - ) - La([], l, function (h) { - var k = [h[0], null].concat(h.slice(1)), - m = (h = a), - n = e, - q = k.length - 2 > q && - W( - "argTypes array size mismatch! Must at least get return value and 'this' types!" + function __embind_register_integer( + primitiveType, + name, + size, + minRange, + maxRange + ) { + name = readLatin1String(name) + if (maxRange === -1) { + maxRange = 4294967295 + } + var shift = getShiftFromSize(size) + var fromWireType = function (value) { + return value + } + if (minRange === 0) { + var bitshift = 32 - 8 * size + fromWireType = function (value) { + return (value << bitshift) >>> bitshift + } + } + var isUnsignedType = name.includes('unsigned') + registerType(primitiveType, { + name: name, + fromWireType: fromWireType, + toWireType: function (destructors, value) { + if (typeof value !== 'number' && typeof value !== 'boolean') { + throw new TypeError( + 'Cannot convert "' + _embind_repr(value) + '" to ' + this.name ) - for (var w = null !== k[1] && !1, x = !1, p = 1; p < k.length; ++p) - if (null !== k[p] && void 0 === k[p].D) { - x = !0 - break - } - var da = 'void' !== k[0].name, - y = '', - E = '' - for (p = 0; p < q - 2; ++p) - (y += (0 !== p ? ', ' : '') + 'arg' + p), - (E += (0 !== p ? ', ' : '') + 'arg' + p + 'Wired') - m = - 'return function ' + - Ha(m) + - '(' + - y + - ') {\nif (arguments.length !== ' + - (q - 2) + - ") {\nthrowBindingError('function " + - m + - " called with ' + arguments.length + ' arguments, expected " + - (q - 2) + - " args!');\n}\n" - x && (m += 'var destructors = [];\n') - var T = x ? 'destructors' : 'null' - y = - 'throwBindingError invoker fn runDestructors retType classParam'.split( - ' ' + } + if (value < minRange || value > maxRange) { + throw new TypeError( + 'Passing a number "' + + _embind_repr(value) + + '" from JS side to C/C++ side to an argument of type "' + + name + + '", which is outside the valid range [' + + minRange + + ', ' + + maxRange + + ']!' ) - n = [W, n, g, Ga, k[0], k[1]] - w && - (m += 'var thisWired = classParam.toWireType(' + T + ', this);\n') - for (p = 0; p < q - 2; ++p) - (m += - 'var arg' + - p + - 'Wired = argType' + - p + - '.toWireType(' + - T + - ', arg' + - p + - '); // ' + - k[p + 2].name + - '\n'), - y.push('argType' + p), - n.push(k[p + 2]) - w && (E = 'thisWired' + (0 < E.length ? ', ' : '') + E) - m += - (da ? 'var rv = ' : '') + - 'invoker(fn' + - (0 < E.length ? ', ' : '') + - E + - ');\n' - if (x) m += 'runDestructors(destructors);\n' - else - for (p = w ? 1 : 2; p < k.length; ++p) - (q = 1 === p ? 'thisWired' : 'arg' + (p - 2) + 'Wired'), - null !== k[p].D && - ((m += q + '_dtor(' + q + '); // ' + k[p].name + '\n'), - y.push(q + '_dtor'), - n.push(k[p].D)) - da && (m += 'var ret = retType.fromWireType(rv);\nreturn ret;\n') - y.push(m + '}\n') - k = $a(y).apply(null, n) - p = b - 1 - if (!f.hasOwnProperty(h)) - throw new Ka('Replacing nonexistant public symbol') - void 0 !== f[h].F && void 0 !== p - ? (f[h].F[p] = k) - : ((f[h] = k), (f[h].J = p)) - return [] - }) - }, - d: function (a, b, c, d, e) { - function g(m) { - return m - } - b = V(b) - ;-1 === e && (e = 4294967295) - var l = Ma(c) - if (0 === d) { - var h = 32 - 8 * c - g = function (m) { - return (m << h) >>> h } - } - var k = -1 != b.indexOf('unsigned') - U(a, { - name: b, - fromWireType: g, - toWireType: function (m, n) { - if ('number' !== typeof n && 'boolean' !== typeof n) - throw new TypeError( - 'Cannot convert "' + Ya(n) + '" to ' + this.name - ) - if (n < d || n > e) - throw new TypeError( - 'Passing a number "' + - Ya(n) + - '" from JS side to C/C++ side to an argument of type "' + - b + - '", which is outside the valid range [' + - d + - ', ' + - e + - ']!' - ) - return k ? n >>> 0 : n | 0 - }, + return isUnsignedType ? value >>> 0 : value | 0 + }, + argPackAdvance: 8, + readValueFromPointer: integerReadValueFromPointer( + name, + shift, + minRange !== 0 + ), + destructorFunction: null, + }) + } + function __embind_register_memory_view(rawType, dataTypeIndex, name) { + var typeMapping = [ + Int8Array, + Uint8Array, + Int16Array, + Uint16Array, + Int32Array, + Uint32Array, + Float32Array, + Float64Array, + ] + var TA = typeMapping[dataTypeIndex] + function decodeMemoryView(handle) { + handle = handle >> 2 + var heap = HEAPU32 + var size = heap[handle] + var data = heap[handle + 1] + return new TA(buffer, data, size) + } + name = readLatin1String(name) + registerType( + rawType, + { + name: name, + fromWireType: decodeMemoryView, argPackAdvance: 8, - readValueFromPointer: eb(b, l, 0 !== d), - D: null, - }) - }, - c: function (a, b, c) { - function d(g) { - g >>= 2 - var l = I - return new e(G, l[g + 1], l[g]) - } - var e = [ - Int8Array, - Uint8Array, - Int16Array, - Uint16Array, - Int32Array, - Uint32Array, - Float32Array, - Float64Array, - ][b] - c = V(c) - U( - a, - { - name: c, - fromWireType: d, - argPackAdvance: 8, - readValueFromPointer: d, - }, - { P: !0 } - ) - }, - l: function (a, b) { - b = V(b) - var c = 'std::string' === b - U(a, { - name: b, - fromWireType: function (d) { - var e = I[d >> 2] - if (c) - for (var g = d + 4, l = 0; l <= e; ++l) { - var h = d + 4 + l - if (l == e || 0 == B[h]) { - if (g) { - for (var k = g + (h - g), m = g; !(m >= k) && B[m]; ) ++m - g = ka.decode(B.subarray(g, m)) - } else g = '' - if (void 0 === n) var n = g - else (n += String.fromCharCode(0)), (n += g) - g = h + 1 + readValueFromPointer: decodeMemoryView, + }, + { ignoreDuplicateRegistrations: true } + ) + } + function __embind_register_std_string(rawType, name) { + name = readLatin1String(name) + var stdStringIsUTF8 = name === 'std::string' + registerType(rawType, { + name: name, + fromWireType: function (value) { + var length = HEAPU32[value >> 2] + var str + if (stdStringIsUTF8) { + var decodeStartPtr = value + 4 + for (var i = 0; i <= length; ++i) { + var currentBytePtr = value + 4 + i + if (i == length || HEAPU8[currentBytePtr] == 0) { + var maxRead = currentBytePtr - decodeStartPtr + var stringSegment = UTF8ToString(decodeStartPtr, maxRead) + if (str === undefined) { + str = stringSegment + } else { + str += String.fromCharCode(0) + str += stringSegment } + decodeStartPtr = currentBytePtr + 1 } - else { - n = Array(e) - for (l = 0; l < e; ++l) n[l] = String.fromCharCode(B[d + 4 + l]) - n = n.join('') } - Y(d) - return n - }, - toWireType: function (d, e) { - e instanceof ArrayBuffer && (e = new Uint8Array(e)) - var g = 'string' === typeof e - g || - e instanceof Uint8Array || - e instanceof Uint8ClampedArray || - e instanceof Int8Array || - W('Cannot pass non-string to std::string') - var l = ( - c && g - ? function () { - for (var m = 0, n = 0; n < e.length; ++n) { - var q = e.charCodeAt(n) - 55296 <= q && - 57343 >= q && - (q = - (65536 + ((q & 1023) << 10)) | - (e.charCodeAt(++n) & 1023)) - 127 >= q - ? ++m - : (m = 2047 >= q ? m + 2 : 65535 >= q ? m + 3 : m + 4) - } - return m - } - : function () { - return e.length - } - )(), - h = lb(4 + l + 1) - I[h >> 2] = l - if (c && g) la(e, h + 4, l + 1) - else if (g) - for (g = 0; g < l; ++g) { - var k = e.charCodeAt(g) - 255 < k && - (Y(h), - W('String has UTF-16 code units that do not fit in 8 bits')) - B[h + 4 + g] = k - } - else for (g = 0; g < l; ++g) B[h + 4 + g] = e[g] - null !== d && d.push(Y, h) - return h - }, - argPackAdvance: 8, - readValueFromPointer: P, - D: function (d) { - Y(d) - }, - }) - }, - h: function (a, b, c) { - c = V(c) - if (2 === b) { - var d = na - var e = oa - var g = pa - var l = function () { - return C + } else { + var a = new Array(length) + for (var i = 0; i < length; ++i) { + a[i] = String.fromCharCode(HEAPU8[value + 4 + i]) + } + str = a.join('') + } + _free(value) + return str + }, + toWireType: function (destructors, value) { + if (value instanceof ArrayBuffer) { + value = new Uint8Array(value) } - var h = 1 - } else - 4 === b && - ((d = qa), - (e = ra), - (g = sa), - (l = function () { - return I - }), - (h = 2)) - U(a, { - name: c, - fromWireType: function (k) { - for (var m = I[k >> 2], n = l(), q, w = k + 4, x = 0; x <= m; ++x) { - var p = k + 4 + x * b - if (x == m || 0 == n[p >> h]) - (w = d(w, p - w)), - void 0 === q - ? (q = w) - : ((q += String.fromCharCode(0)), (q += w)), - (w = p + b) + var getLength + var valueIsOfTypeString = typeof value === 'string' + if ( + !( + valueIsOfTypeString || + value instanceof Uint8Array || + value instanceof Uint8ClampedArray || + value instanceof Int8Array + ) + ) { + throwBindingError('Cannot pass non-string to std::string') + } + if (stdStringIsUTF8 && valueIsOfTypeString) { + getLength = function () { + return lengthBytesUTF8(value) + } + } else { + getLength = function () { + return value.length + } + } + var length = getLength() + var ptr = _malloc(4 + length + 1) + HEAPU32[ptr >> 2] = length + if (stdStringIsUTF8 && valueIsOfTypeString) { + stringToUTF8(value, ptr + 4, length + 1) + } else { + if (valueIsOfTypeString) { + for (var i = 0; i < length; ++i) { + var charCode = value.charCodeAt(i) + if (charCode > 255) { + _free(ptr) + throwBindingError( + 'String has UTF-16 code units that do not fit in 8 bits' + ) + } + HEAPU8[ptr + 4 + i] = charCode + } + } else { + for (var i = 0; i < length; ++i) { + HEAPU8[ptr + 4 + i] = value[i] + } } - Y(k) - return q - }, - toWireType: function (k, m) { - 'string' !== typeof m && - W('Cannot pass non-string to C++ string type ' + c) - var n = g(m), - q = lb(4 + n + b) - I[q >> 2] = n >> h - e(m, q + 4, n + b) - null !== k && k.push(Y, q) - return q - }, - argPackAdvance: 8, - readValueFromPointer: P, - D: function (k) { - Y(k) - }, - }) - }, - n: function (a, b, c, d, e, g) { - O[a] = { name: V(b), R: Z(c, d), S: Z(e, g), I: [] } - }, - b: function (a, b, c, d, e, g, l, h, k, m) { - O[a].I.push({ K: V(b), O: c, M: Z(d, e), N: g, U: l, T: Z(h, k), V: m }) - }, - t: function (a, b) { - b = V(b) - U(a, { - W: !0, - name: b, - argPackAdvance: 0, - fromWireType: function () {}, - toWireType: function () {}, - }) - }, - g: Qa, - v: function (a) { - if (0 === a) return Ra(gb()) - var b = fb[a] - a = void 0 === b ? V(a) : b - return Ra(gb()[a]) - }, - u: function (a) { - 4 < a && (X[a].H += 1) - }, - p: function (a, b, c, d) { - a || W('Cannot use deleted val. handle = ' + a) - a = X[a].value - var e = hb[b] - if (!e) { - e = '' - for (var g = 0; g < b; ++g) e += (0 !== g ? ', ' : '') + 'arg' + g - var l = - 'return function emval_allocator_' + - b + - '(constructor, argTypes, args) {\n' - for (g = 0; g < b; ++g) - l += - 'var argType' + - g + - " = requireRegisteredType(Module['HEAP32'][(argTypes >>> 2) + " + - g + - '], "parameter ' + - g + - '");\nvar arg' + - g + - ' = argType' + - g + - '.readValueFromPointer(args);\nargs += argType' + - g + - "['argPackAdvance'];\n" - e = new Function( - 'requireRegisteredType', - 'Module', - '__emval_register', - l + - ('var obj = new constructor(' + - e + - ');\nreturn __emval_register(obj);\n}\n') - )(Xa, f, Ra) - hb[b] = e - } - return e(a, c, d) - }, - j: function () { - u() - }, - q: function (a, b, c) { - B.copyWithin(a, b, b + c) - }, - e: function (a) { - a >>>= 0 - var b = B.length - if (2147483648 < a) return !1 - for (var c = 1; 4 >= c; c *= 2) { - var d = b * (1 + 0.2 / c) - d = Math.min(d, a + 100663296) - d = Math.max(16777216, a, d) - 0 < d % 65536 && (d += 65536 - (d % 65536)) - a: { - try { - A.grow((Math.min(2147483648, d) - G.byteLength + 65535) >>> 16) - va(A.buffer) - var e = 1 - break a - } catch (g) {} - e = void 0 } - if (e) return !0 + if (destructors !== null) { + destructors.push(_free, ptr) + } + return ptr + }, + argPackAdvance: 8, + readValueFromPointer: simpleReadValueFromPointer, + destructorFunction: function (ptr) { + _free(ptr) + }, + }) + } + function __embind_register_std_wstring(rawType, charSize, name) { + name = readLatin1String(name) + var decodeString, encodeString, getHeap, lengthBytesUTF, shift + if (charSize === 2) { + decodeString = UTF16ToString + encodeString = stringToUTF16 + lengthBytesUTF = lengthBytesUTF16 + getHeap = function () { + return HEAPU16 } - return !1 - }, - a: A, - } - ;(function () { - function a(e) { - f.asm = e.exports - J = f.asm.x - K-- - f.monitorRunDependencies && f.monitorRunDependencies(K) - 0 == K && - (null !== Ca && (clearInterval(Ca), (Ca = null)), - L && ((e = L), (L = null), e())) - } - function b(e) { - a(e.instance) - } - function c(e) { - return Promise.resolve() - .then(Fa) - .then(function (g) { - return WebAssembly.instantiate(g, d) - }) - .then(e, function (g) { - v('failed to asynchronously prepare wasm: ' + g) - u(g) - }) - } - var d = { a: mb } - K++ - f.monitorRunDependencies && f.monitorRunDependencies(K) - if (f.instantiateWasm) - try { - return f.instantiateWasm(d, a) - } catch (e) { - return ( - v('Module.instantiateWasm callback failed with error: ' + e), !1 - ) + shift = 1 + } else if (charSize === 4) { + decodeString = UTF32ToString + encodeString = stringToUTF32 + lengthBytesUTF = lengthBytesUTF32 + getHeap = function () { + return HEAPU32 } - ;(function () { - return z || - 'function' !== typeof WebAssembly.instantiateStreaming || - Da() || - 'function' !== typeof fetch - ? c(b) - : fetch(M, { credentials: 'same-origin' }).then(function (e) { - return WebAssembly.instantiateStreaming(e, d).then( - b, - function (g) { - v('wasm streaming compile failed: ' + g) - v('falling back to ArrayBuffer instantiation') - return c(b) - } - ) - }) - })().catch(ba) - return {} - })() - var kb = (f.___wasm_call_ctors = function () { - return (kb = f.___wasm_call_ctors = f.asm.y).apply(null, arguments) - }), - lb = (f._malloc = function () { - return (lb = f._malloc = f.asm.z).apply(null, arguments) - }), - Y = (f._free = function () { - return (Y = f._free = f.asm.A).apply(null, arguments) - }), - Wa = (f.___getTypeName = function () { - return (Wa = f.___getTypeName = f.asm.B).apply(null, arguments) + shift = 2 + } + registerType(rawType, { + name: name, + fromWireType: function (value) { + var length = HEAPU32[value >> 2] + var HEAP = getHeap() + var str + var decodeStartPtr = value + 4 + for (var i = 0; i <= length; ++i) { + var currentBytePtr = value + 4 + i * charSize + if (i == length || HEAP[currentBytePtr >> shift] == 0) { + var maxReadBytes = currentBytePtr - decodeStartPtr + var stringSegment = decodeString(decodeStartPtr, maxReadBytes) + if (str === undefined) { + str = stringSegment + } else { + str += String.fromCharCode(0) + str += stringSegment + } + decodeStartPtr = currentBytePtr + charSize + } + } + _free(value) + return str + }, + toWireType: function (destructors, value) { + if (!(typeof value === 'string')) { + throwBindingError( + 'Cannot pass non-string to C++ string type ' + name + ) + } + var length = lengthBytesUTF(value) + var ptr = _malloc(4 + length + charSize) + HEAPU32[ptr >> 2] = length >> shift + encodeString(value, ptr + 4, length + charSize) + if (destructors !== null) { + destructors.push(_free, ptr) + } + return ptr + }, + argPackAdvance: 8, + readValueFromPointer: simpleReadValueFromPointer, + destructorFunction: function (ptr) { + _free(ptr) + }, + }) + } + function __embind_register_value_object( + rawType, + name, + constructorSignature, + rawConstructor, + destructorSignature, + rawDestructor + ) { + structRegistrations[rawType] = { + name: readLatin1String(name), + rawConstructor: embind__requireFunction( + constructorSignature, + rawConstructor + ), + rawDestructor: embind__requireFunction( + destructorSignature, + rawDestructor + ), + fields: [], + } + } + function __embind_register_value_object_field( + structType, + fieldName, + getterReturnType, + getterSignature, + getter, + getterContext, + setterArgumentType, + setterSignature, + setter, + setterContext + ) { + structRegistrations[structType].fields.push({ + fieldName: readLatin1String(fieldName), + getterReturnType: getterReturnType, + getter: embind__requireFunction(getterSignature, getter), + getterContext: getterContext, + setterArgumentType: setterArgumentType, + setter: embind__requireFunction(setterSignature, setter), + setterContext: setterContext, }) - f.___embind_register_native_and_builtin_types = function () { - return (f.___embind_register_native_and_builtin_types = f.asm.C).apply( + } + function __embind_register_void(rawType, name) { + name = readLatin1String(name) + registerType(rawType, { + isVoid: true, + name: name, + argPackAdvance: 0, + fromWireType: function () { + return undefined + }, + toWireType: function (destructors, o) { + return undefined + }, + }) + } + var emval_symbols = {} + function getStringOrSymbol(address) { + var symbol = emval_symbols[address] + if (symbol === undefined) { + return readLatin1String(address) + } else { + return symbol + } + } + function emval_get_global() { + if (typeof globalThis === 'object') { + return globalThis + } + return (function () { + return Function + })()('return this')() + } + function __emval_get_global(name) { + if (name === 0) { + return __emval_register(emval_get_global()) + } else { + name = getStringOrSymbol(name) + return __emval_register(emval_get_global()[name]) + } + } + function __emval_incref(handle) { + if (handle > 4) { + emval_handle_array[handle].refcount += 1 + } + } + function craftEmvalAllocator(argCount) { + var argsList = '' + for (var i = 0; i < argCount; ++i) { + argsList += (i !== 0 ? ', ' : '') + 'arg' + i + } + var functionBody = + 'return function emval_allocator_' + + argCount + + '(constructor, argTypes, args) {\n' + for (var i = 0; i < argCount; ++i) { + functionBody += + 'var argType' + + i + + " = requireRegisteredType(Module['HEAP32'][(argTypes >>> 2) + " + + i + + '], "parameter ' + + i + + '");\n' + + 'var arg' + + i + + ' = argType' + + i + + '.readValueFromPointer(args);\n' + + 'args += argType' + + i + + "['argPackAdvance'];\n" + } + functionBody += + 'var obj = new constructor(' + + argsList + + ');\n' + + 'return __emval_register(obj);\n' + + '}\n' + return new Function( + 'requireRegisteredType', + 'Module', + '__emval_register', + functionBody + )(requireRegisteredType, Module, __emval_register) + } + var emval_newers = {} + function requireHandle(handle) { + if (!handle) { + throwBindingError('Cannot use deleted val. handle = ' + handle) + } + return emval_handle_array[handle].value + } + function __emval_new(handle, argCount, argTypes, args) { + handle = requireHandle(handle) + var newer = emval_newers[argCount] + if (!newer) { + newer = craftEmvalAllocator(argCount) + emval_newers[argCount] = newer + } + return newer(handle, argTypes, args) + } + function _abort() { + abort() + } + function _emscripten_memcpy_big(dest, src, num) { + HEAPU8.copyWithin(dest, src, src + num) + } + function emscripten_realloc_buffer(size) { + try { + wasmMemory.grow((size - buffer.byteLength + 65535) >>> 16) + updateGlobalBufferAndViews(wasmMemory.buffer) + return 1 + } catch (e) {} + } + function _emscripten_resize_heap(requestedSize) { + var oldSize = HEAPU8.length + requestedSize = requestedSize >>> 0 + var maxHeapSize = 2147483648 + if (requestedSize > maxHeapSize) { + return false + } + for (var cutDown = 1; cutDown <= 4; cutDown *= 2) { + var overGrownHeapSize = oldSize * (1 + 0.2 / cutDown) + overGrownHeapSize = Math.min( + overGrownHeapSize, + requestedSize + 100663296 + ) + var newSize = Math.min( + maxHeapSize, + alignUp(Math.max(requestedSize, overGrownHeapSize), 65536) + ) + var replacement = emscripten_realloc_buffer(newSize) + if (replacement) { + return true + } + } + return false + } + InternalError = Module['InternalError'] = extendError( + Error, + 'InternalError' + ) + embind_init_charCodes() + BindingError = Module['BindingError'] = extendError(Error, 'BindingError') + init_emval() + UnboundTypeError = Module['UnboundTypeError'] = extendError( + Error, + 'UnboundTypeError' + ) + var asmLibraryArg = { + w: ___cxa_thread_atexit, + l: __embind_finalize_value_object, + p: __embind_register_bigint, + s: __embind_register_bool, + r: __embind_register_emval, + n: __embind_register_enum, + d: __embind_register_enum_value, + j: __embind_register_float, + h: __embind_register_function, + c: __embind_register_integer, + b: __embind_register_memory_view, + k: __embind_register_std_string, + g: __embind_register_std_wstring, + m: __embind_register_value_object, + a: __embind_register_value_object_field, + t: __embind_register_void, + f: __emval_decref, + v: __emval_get_global, + u: __emval_incref, + o: __emval_new, + i: _abort, + q: _emscripten_memcpy_big, + e: _emscripten_resize_heap, + } + var asm = createWasm() + var ___wasm_call_ctors = (Module['___wasm_call_ctors'] = function () { + return (___wasm_call_ctors = Module['___wasm_call_ctors'] = + Module['asm']['y']).apply(null, arguments) + }) + var _malloc = (Module['_malloc'] = function () { + return (_malloc = Module['_malloc'] = Module['asm']['z']).apply( + null, + arguments + ) + }) + var _free = (Module['_free'] = function () { + return (_free = Module['_free'] = Module['asm']['A']).apply( null, arguments ) + }) + var ___getTypeName = (Module['___getTypeName'] = function () { + return (___getTypeName = Module['___getTypeName'] = + Module['asm']['B']).apply(null, arguments) + }) + var ___embind_register_native_and_builtin_types = (Module[ + '___embind_register_native_and_builtin_types' + ] = function () { + return (___embind_register_native_and_builtin_types = Module[ + '___embind_register_native_and_builtin_types' + ] = + Module['asm']['C']).apply(null, arguments) + }) + var calledRun + dependenciesFulfilled = function runCaller() { + if (!calledRun) run() + if (!calledRun) dependenciesFulfilled = runCaller } - var nb - L = function ob() { - nb || pb() - nb || (L = ob) - } - function pb() { - function a() { - if (!nb && ((nb = !0), (f.calledRun = !0), !ja)) { - N(ya) - N(za) - aa(f) - if (f.onRuntimeInitialized) f.onRuntimeInitialized() - if (f.postRun) - for ( - 'function' == typeof f.postRun && (f.postRun = [f.postRun]); - f.postRun.length; - - ) { - var b = f.postRun.shift() - Aa.unshift(b) - } - N(Aa) - } + function run(args) { + args = args || arguments_ + if (runDependencies > 0) { + return } - if (!(0 < K)) { - if (f.preRun) - for ( - 'function' == typeof f.preRun && (f.preRun = [f.preRun]); - f.preRun.length; - - ) - Ba() - N(xa) - 0 < K || - (f.setStatus - ? (f.setStatus('Running...'), - setTimeout(function () { - setTimeout(function () { - f.setStatus('') - }, 1) - a() - }, 1)) - : a()) - } - } - f.run = pb - if (f.preInit) - for ( - 'function' == typeof f.preInit && (f.preInit = [f.preInit]); - 0 < f.preInit.length; - - ) - f.preInit.pop()() - noExitRuntime = !0 - pb() + preRun() + if (runDependencies > 0) { + return + } + function doRun() { + if (calledRun) return + calledRun = true + Module['calledRun'] = true + if (ABORT) return + initRuntime() + readyPromiseResolve(Module) + if (Module['onRuntimeInitialized']) Module['onRuntimeInitialized']() + postRun() + } + if (Module['setStatus']) { + Module['setStatus']('Running...') + setTimeout(function () { + setTimeout(function () { + Module['setStatus']('') + }, 1) + doRun() + }, 1) + } else { + doRun() + } + } + Module['run'] = run + if (Module['preInit']) { + if (typeof Module['preInit'] == 'function') + Module['preInit'] = [Module['preInit']] + while (Module['preInit'].length > 0) { + Module['preInit'].pop()() + } + } + run() return Module.ready } diff --git a/packages/next/server/lib/squoosh/webp/webp_node_enc.wasm b/packages/next/server/lib/squoosh/webp/webp_node_enc.wasm old mode 100644 new mode 100755 index c1b08f136c12a..7621054164f6f Binary files a/packages/next/server/lib/squoosh/webp/webp_node_enc.wasm and b/packages/next/server/lib/squoosh/webp/webp_node_enc.wasm differ diff --git a/test/integration/image-component/base-path/test/static.test.js b/test/integration/image-component/base-path/test/static.test.js index ad1a17b271346..2940de3984557 100644 --- a/test/integration/image-component/base-path/test/static.test.js +++ b/test/integration/image-component/base-path/test/static.test.js @@ -67,21 +67,21 @@ const runTests = (isDev = false) => { expect(html).toContain('width:200px;height:200px') expect(html).not.toContain('width:400px;height:400px') }) - it('Should add a blurry placeholder to statically imported jpg', async () => { + it('Should add a blur placeholder to statically imported jpg', async () => { expect(html).toContain( `style="position:absolute;top:0;left:0;bottom:0;right:0;box-sizing:border-box;padding:0;border:none;margin:auto;display:block;width:0;height:0;min-width:100%;max-width:100%;min-height:100%;max-height:100%;filter:blur(20px);background-size:cover;background-image:url(${ isDev ? '"/docs/_next/image?url=%2Fdocs%2F_next%2Fstatic%2Fimage%2Fpublic%2Ftest.480a01e5ea850d0231aec0fa94bd23a0.jpg&w=8&q=70"' - : '"data:image/jpeg;base64,/9j/4AAQSkZJRgABAQAAAQABAAD/2wCEAAoKCgoKCgsMDAsPEA4QDxYUExMUFiIYGhgaGCIzICUgICUgMy03LCksNy1RQDg4QFFeT0pPXnFlZXGPiI+7u/sBCgoKCgoKCwwMCw8QDhAPFhQTExQWIhgaGBoYIjMgJSAgJSAzLTcsKSw3LVFAODhAUV5PSk9ecWVlcY+Ij7u7+//CABEIAAgACAMBIgACEQEDEQH/xAAUAAEAAAAAAAAAAAAAAAAAAAAH/9oACAEBAAAAADX/xAAUAQEAAAAAAAAAAAAAAAAAAAAA/9oACAECEAAAAH//xAAUAQEAAAAAAAAAAAAAAAAAAAAA/9oACAEDEAAAAH//xAAdEAABAgcAAAAAAAAAAAAAAAATEhUAAwUUIzLS/9oACAEBAAE/AB0ZlUac43GqMYuo/8QAFBEBAAAAAAAAAAAAAAAAAAAAAP/aAAgBAgEBPwB//8QAFBEBAAAAAAAAAAAAAAAAAAAAAP/aAAgBAwEBPwB//9k="' + : '"data:image/jpeg;base64,/9j/4AAQSkZJRgABAQAAAQABAAD/2wCEAAoKCgoKCgsMDAsPEA4QDxYUExMUFiIYGhgaGCIzICUgICUgMy03LCksNy1RQDg4QFFeT0pPXnFlZXGPiI+7u/sBCgoKCgoKCwwMCw8QDhAPFhQTExQWIhgaGBoYIjMgJSAgJSAzLTcsKSw3LVFAODhAUV5PSk9ecWVlcY+Ij7u7+//CABEIAAYACAMBIgACEQEDEQH/xAAnAAEBAAAAAAAAAAAAAAAAAAAABwEBAAAAAAAAAAAAAAAAAAAAAP/aAAwDAQACEAMQAAAAmgP/xAAcEAACAQUBAAAAAAAAAAAAAAASFBMAAQMFERX/2gAIAQEAAT8AZ1HjrKZX55JysIc4Ff/EABQRAQAAAAAAAAAAAAAAAAAAAAD/2gAIAQIBAT8Af//EABQRAQAAAAAAAAAAAAAAAAAAAAD/2gAIAQMBAT8Af//Z"' });background-position:0% 0%"` ) }) - it('Should add a blurry placeholder to statically imported png', async () => { + it('Should add a blur placeholder to statically imported png', async () => { expect(html).toContain( `style="position:absolute;top:0;left:0;bottom:0;right:0;box-sizing:border-box;padding:0;border:none;margin:auto;display:block;width:0;height:0;min-width:100%;max-width:100%;min-height:100%;max-height:100%;filter:blur(20px);background-size:cover;background-image:url(${ isDev ? '"/docs/_next/image?url=%2Fdocs%2F_next%2Fstatic%2Fimage%2Fpublic%2Ftest.eba16dd4cf631c11162a5e9faeb5415b.png&w=8&q=70"' - : '"data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAAgAAAAICAQAAABuBnYAAAAATklEQVR42i2I0QmAMBQD869Q9K+IsxU6RkfoiA6T55VXDpJLJC9uUJIzcx+XFd2dXMbx8n+QpoeYDpgY66RaDA83jCUfVpK2pER1dcEUP+KfSBtXK+BpAAAAAElFTkSuQmCC"' + : '"data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAAMAAAAICAAAAAAZhBqgAAAAJklEQVR42mNgkmBkYGXgZGBoY2Co/lPAcOf/dYaCzHwGEBAVEwUAZZIG0TbWicQAAAAASUVORK5CYII="' });background-position:0% 0%"` ) }) diff --git a/test/integration/image-component/default/test/static.test.js b/test/integration/image-component/default/test/static.test.js index f5ebfda7db442..32ef254504401 100644 --- a/test/integration/image-component/default/test/static.test.js +++ b/test/integration/image-component/default/test/static.test.js @@ -63,14 +63,14 @@ const runTests = () => { expect(html).toContain('width:200px;height:200px') expect(html).not.toContain('width:400px;height:400px') }) - it('Should add a blurry placeholder to statically imported jpg', async () => { + it('Should add a blur placeholder to statically imported jpg', async () => { expect(html).toContain( - `style="position:absolute;top:0;left:0;bottom:0;right:0;box-sizing:border-box;padding:0;border:none;margin:auto;display:block;width:0;height:0;min-width:100%;max-width:100%;min-height:100%;max-height:100%;filter:blur(20px);background-size:cover;background-image:url("data:image/jpeg;base64,/9j/4AAQSkZJRgABAQAAAQABAAD/2wCEAAoKCgoKCgsMDAsPEA4QDxYUExMUFiIYGhgaGCIzICUgICUgMy03LCksNy1RQDg4QFFeT0pPXnFlZXGPiI+7u/sBCgoKCgoKCwwMCw8QDhAPFhQTExQWIhgaGBoYIjMgJSAgJSAzLTcsKSw3LVFAODhAUV5PSk9ecWVlcY+Ij7u7+//CABEIAAgACAMBIgACEQEDEQH/xAAUAAEAAAAAAAAAAAAAAAAAAAAH/9oACAEBAAAAADX/xAAUAQEAAAAAAAAAAAAAAAAAAAAA/9oACAECEAAAAH//xAAUAQEAAAAAAAAAAAAAAAAAAAAA/9oACAEDEAAAAH//xAAdEAABAgcAAAAAAAAAAAAAAAATEhUAAwUUIzLS/9oACAEBAAE/AB0ZlUac43GqMYuo/8QAFBEBAAAAAAAAAAAAAAAAAAAAAP/aAAgBAgEBPwB//8QAFBEBAAAAAAAAAAAAAAAAAAAAAP/aAAgBAwEBPwB//9k=");background-position:0% 0%"` + `style="position:absolute;top:0;left:0;bottom:0;right:0;box-sizing:border-box;padding:0;border:none;margin:auto;display:block;width:0;height:0;min-width:100%;max-width:100%;min-height:100%;max-height:100%;filter:blur(20px);background-size:cover;background-image:url("data:image/jpeg;base64,/9j/4AAQSkZJRgABAQAAAQABAAD/2wCEAAoKCgoKCgsMDAsPEA4QDxYUExMUFiIYGhgaGCIzICUgICUgMy03LCksNy1RQDg4QFFeT0pPXnFlZXGPiI+7u/sBCgoKCgoKCwwMCw8QDhAPFhQTExQWIhgaGBoYIjMgJSAgJSAzLTcsKSw3LVFAODhAUV5PSk9ecWVlcY+Ij7u7+//CABEIAAYACAMBIgACEQEDEQH/xAAnAAEBAAAAAAAAAAAAAAAAAAAABwEBAAAAAAAAAAAAAAAAAAAAAP/aAAwDAQACEAMQAAAAmgP/xAAcEAACAQUBAAAAAAAAAAAAAAASFBMAAQMFERX/2gAIAQEAAT8AZ1HjrKZX55JysIc4Ff/EABQRAQAAAAAAAAAAAAAAAAAAAAD/2gAIAQIBAT8Af//EABQRAQAAAAAAAAAAAAAAAAAAAAD/2gAIAQMBAT8Af//Z");background-position:0% 0%"` ) }) - it('Should add a blurry placeholder to statically imported png', async () => { + it('Should add a blur placeholder to statically imported png', async () => { expect(html).toContain( - `style="position:absolute;top:0;left:0;bottom:0;right:0;box-sizing:border-box;padding:0;border:none;margin:auto;display:block;width:0;height:0;min-width:100%;max-width:100%;min-height:100%;max-height:100%;filter:blur(20px);background-size:cover;background-image:url("data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAAgAAAAICAQAAABuBnYAAAAATklEQVR42i2I0QmAMBQD869Q9K+IsxU6RkfoiA6T55VXDpJLJC9uUJIzcx+XFd2dXMbx8n+QpoeYDpgY66RaDA83jCUfVpK2pER1dcEUP+KfSBtXK+BpAAAAAElFTkSuQmCC");background-position:0% 0%"` + `style="position:absolute;top:0;left:0;bottom:0;right:0;box-sizing:border-box;padding:0;border:none;margin:auto;display:block;width:0;height:0;min-width:100%;max-width:100%;min-height:100%;max-height:100%;filter:blur(20px);background-size:cover;background-image:url("data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAAgAAAAICAAAAADhZOFXAAAAOklEQVR42iWGsQkAIBDE0iuIdiLOJjiGIzjiL/Meb4okiNYIlLjK3hJMzCQG1/0qmXXOUkjAV+m9wAMe3QiV6Ne8VgAAAABJRU5ErkJggg==");background-position:0% 0%"` ) }) }