!function(t,e){"object"==typeof exports&&"undefined"!=typeof module?e(exports):"function"==typeof define&&define.amd?define(["exports"],e):e((t="undefined"!=typeof globalThis?globalThis:t||self).wasmUtil={})}(this,(function(t){"use strict";const e="undefined"!=typeof WebAssembly?WebAssembly:"undefined"!=typeof WXWebAssembly?WXWebAssembly:void 0;if(!e)throw new Error("WebAssembly is not supported in this environment");function n(t,e){if(null===t||"object"!=typeof t)throw new TypeError(`${e} must be an object. Received ${null===t?"null":typeof t}`)}function i(t,e){if("string"!=typeof t)throw new TypeError(`${e} must be a string. Received ${null===t?"null":typeof t}`)}function r(t,e){if("function"!=typeof t)throw new TypeError(`${e} must be a function. Received ${null===t?"null":typeof t}`)}function s(t,e){if(void 0!==t)throw new TypeError(`${e} must be undefined. Received ${null===t?"null":typeof t}`)}function o(t){return!(!t||"object"!=typeof t&&"function"!=typeof t||"function"!=typeof t.then)}function a(t,e){const n=Object.create(null);return Object.keys(t).forEach((i=>{const r=t[i];Object.defineProperty(n,i,{enumerable:!0,value:e(r,i)})})),n}function c(t,e,n){return"function"==typeof SharedArrayBuffer&&t.buffer instanceof SharedArrayBuffer||"[object SharedArrayBuffer]"===Object.prototype.toString.call(t.buffer.constructor)?t.slice(e,n):t.subarray(e,n)}const u=["asyncify_get_state","asyncify_start_rewind","asyncify_start_unwind","asyncify_stop_rewind","asyncify_stop_unwind"];function f(t,e,n,i){if("function"!=typeof t.exports[i]||n<=0)return{wasm64:e,dataPtr:16,start:e?32:24,end:1024};const r=t.exports[i],s=e?Number(r(BigInt(16)+BigInt(n))):r(8+n);if(0===s)throw new Error("Allocate asyncify data failed");return e?{wasm64:e,dataPtr:s,start:s+16,end:s+16+n}:{wasm64:e,dataPtr:s,start:s+8,end:s+8+n}}class h{constructor(){this.value=void 0,this.exports=void 0,this.dataPtr=0}init(t,n,i){var r,s;if(this.exports)throw new Error("Asyncify has been initialized");if(!(t instanceof e.Memory))throw new TypeError("Require WebAssembly.Memory object");const o=n.exports;for(let t=0;t{const i=t[n],r={};Object.keys(i).forEach((t=>{const e=i[t];r[t]="function"==typeof e?this.wrapImportFunction(e):e})),e[n]=r})),e}wrapExportFunction(t){const e=this;return async function(){e.assertState();let n=t.apply(this,arguments);for(;1===e.exports.asyncify_get_state();)e.exports.asyncify_stop_unwind(),e.value=await e.value,e.assertState(),e.exports.asyncify_start_rewind(e.dataPtr),n=t.call(this);return e.assertState(),n}}wrapExports(t,e){return a(t,((t,n)=>{let i=-1!==u.indexOf(n)||"function"!=typeof t;return Array.isArray(e)&&(i=i||-1===e.indexOf(n)),i?t:this.wrapExportFunction(t)}))}}function d(t){if(t&&"object"!=typeof t)throw new TypeError("imports must be an object or undefined")}function g(t,n){return"undefined"!=typeof wx&&"undefined"!=typeof __wxConfig?e.instantiate(t,n):fetch(t).then((t=>t.arrayBuffer())).then((t=>e.instantiate(t,n)))}function l(t,n){let i;if(d(n),n=null!=n?n:{},t instanceof ArrayBuffer||ArrayBuffer.isView(t))return e.instantiate(t,n);if(t instanceof e.Module)return e.instantiate(t,n).then((e=>({instance:e,module:t})));if("string"!=typeof t&&!(t instanceof URL))throw new TypeError("Invalid source");if("function"==typeof e.instantiateStreaming){let r;try{r=fetch(t),i=e.instantiateStreaming(r,n).catch((()=>g(t,n)))}catch(e){i=g(t,n)}}else i=g(t,n);return i}function _(t,n){let i;if(d(n),n=null!=n?n:{},t instanceof ArrayBuffer||ArrayBuffer.isView(t))i=new e.Module(t);else{if(!(t instanceof WebAssembly.Module))throw new TypeError("Invalid source");i=t}return{instance:new e.Instance(i,n),module:i}}const y=46,p=47;function E(t){return t===p}function I(...t){let e="",n=!1;for(let r=t.length-1;r>=-1&&!n;r--){const s=r>=0?t[r]:"/";i(s,"path"),0!==s.length&&(e=`${s}/${e}`,n=s.charCodeAt(0)===p)}return e=function(t,e,n,i){let r="",s=0,o=-1,a=0,c=0;for(let u=0;u<=t.length;++u){if(u2){const t=r.indexOf(n);-1===t?(r="",s=0):(r=r.slice(0,t),s=r.length-1-r.indexOf(n)),o=u,a=0;continue}if(0!==r.length){r="",s=0,o=u,a=0;continue}}e&&(r+=r.length>0?`${n}..`:"..",s=2)}else r.length>0?r+=`${n}${t.slice(o+1,u)}`:r=t.slice(o+1,u),s=u-o-1;o=u,a=0}else c===y&&-1!==a?++a:a=-1}return r}(e,!n,"/",E),n?`/${e}`:e.length>0?e:"."}const m={FD_DATASYNC:BigInt(1)<=0)n=e;else for(let e=0;e"),this.insertStdio(t.out,1,""),this.insertStdio(t.err,2,"")}insertStdio(t,e,n){const{base:i,inheriting:r}=H(this.stdio,t,2,2),s=this.insert(t,n,n,2,i,r,0);if(s.id!==e)throw new A(`id: ${s.id} !== expected: ${e}`,8);return s}insert(t,e,n,i,r,s,o){var a,c;let u,f=-1;if(this.used>=this.size){const t=2*this.size;this.fds.length=t,f=this.size,this.size=t}else for(let t=0;t"===e?new C(null!==(c=this.printErr)&&void 0!==c?c:console.error,f,t,e,n,i,r,s,o):new k(f,t,e,n,i,r,s,o),this.fds[f]=u,this.used++,u}get(t,e,n){if(t>=this.size)throw new A("Invalid fd",8);const i=this.fds[t];if(!i||i.id!==t)throw new A("Bad file descriptor",8);if((~i.rightsBase&e)!==BigInt(0)||(~i.rightsInheriting&n)!==BigInt(0))throw new A("Capabilities insufficient",76);return i}remove(t){if(t>=this.size)throw new A("Invalid fd",8);const e=this.fds[t];if(!e||e.id!==t)throw new A("Bad file descriptor",8);this.fds[t]=void 0,this.used--}}class z extends W{constructor(t){super(t),this.fs=t.fs}getFileTypeByFd(t){return x(this.fs.fstatSync(t,{bigint:!0}))}insertPreopen(t,e,n){const i=this.getFileTypeByFd(t);if(3!==i)throw new A(`Preopen not dir: ["${e}", "${n}"]`,54);const r=H(this.stdio,t,0,i);return this.insert(t,e,n,i,r.base,r.inheriting,1)}renumber(t,e){if(t===e)return;if(t>=this.size||e>=this.size)throw new A("Invalid fd",8);const n=this.fds[t],i=this.fds[e];if(!n||!i||n.id!==t||i.id!==e)throw new A("Invalid fd",8);this.fs.closeSync(n.fd),this.fds[t]=this.fds[e],this.fds[t].id=t,this.fds[e]=void 0,this.used--}}class K extends W{constructor(t){super(t)}async getFileTypeByFd(t){return x(await t.stat({bigint:!0}))}async insertPreopen(t,e,n){const i=await this.getFileTypeByFd(t);if(3!==i)throw new A(`Preopen not dir: ["${e}", "${n}"]`,54);const r=H(this.stdio,t.fd,0,i);return this.insert(t,e,n,i,r.base,r.inheriting,1)}async renumber(t,e){if(t===e)return;if(t>=this.size||e>=this.size)throw new A("Invalid fd",8);const n=this.fds[t],i=this.fds[e];if(!n||!i||n.id!==t||i.id!==e)throw new A("Invalid fd",8);await n.fd.close(),this.fds[t]=this.fds[e],this.fds[t].id=t,this.fds[e]=void 0,this.used--}}const j=function(){return e.Memory}();class G extends j{constructor(t){super(t)}get HEAP8(){return new Int8Array(super.buffer)}get HEAPU8(){return new Uint8Array(super.buffer)}get HEAP16(){return new Int16Array(super.buffer)}get HEAPU16(){return new Uint16Array(super.buffer)}get HEAP32(){return new Int32Array(super.buffer)}get HEAPU32(){return new Uint32Array(super.buffer)}get HEAP64(){return new BigInt64Array(super.buffer)}get HEAPU64(){return new BigUint64Array(super.buffer)}get HEAPF32(){return new Float32Array(super.buffer)}get HEAPF64(){return new Float64Array(super.buffer)}get view(){return new DataView(super.buffer)}}function Y(t){return Object.getPrototypeOf(t)===e.Memory.prototype&&Object.setPrototypeOf(t,G.prototype),t}function $(){const t=e.Function;if("function"!=typeof t)throw new Error('WebAssembly.Function is not supported in this environment. If you are using V8 based browser like Chrome, try to specify --js-flags="--wasm-staging --experimental-wasm-stack-switching"');return t}function V(t,e,n){const i=$();if("function"!=typeof t)throw new TypeError("Function required");const r=e.slice(0);return r.unshift("externref"),new i({parameters:r,results:n},t,{suspending:"first"})}function Z(t){const e=$();if("function"!=typeof t)throw new TypeError("Function required");return new e({parameters:[...e.type(t).parameters.slice(1)],results:["externref"]},t,{promising:"first"})}function q(t,e){if(0===t.length||0===e.length)return 0;let n=0,i=e.length-n;for(let r=0;rt),nt):e}))}function rt(t,e,n,i){let r=I(e.realPath,n);if(1==(1&i))try{r=t.readlinkSync(r)}catch(t){if("EINVAL"!==t.code&&"ENOENT"!==t.code)throw t}return r}async function st(t,e,n,i){let r=I(e.realPath,n);if(1==(1&i))try{r=await t.promises.readlink(r)}catch(t){if("EINVAL"!==t.code&&"ENOENT"!==t.code)throw t}return r}const ot=new TextEncoder,at=new TextDecoder,ct=(BigInt(1)<i.rightsBase||(n|i.rightsInheriting)>i.rightsInheriting?76:(i.rightsBase=e,i.rightsInheriting=n,0)})),this.fd_prestat_get=it(this,"fd_prestat_get",(function(t,e){if(0===(e=Number(e)))return 28;const n=Q.get(this);let i;try{i=n.fds.get(t,BigInt(0),BigInt(0))}catch(t){if(t instanceof A)return t.errno;throw t}if(1!==i.preopen)return 28;const{view:r}=tt(this);return r.setUint32(e,0,!0),r.setUint32(e+4,ot.encode(i.path).length,!0),0})),this.fd_prestat_dir_name=it(this,"fd_prestat_dir_name",(function(t,e,n){if(e=Number(e),n=Number(n),0===e)return 28;const i=Q.get(this).fds.get(t,BigInt(0),BigInt(0));if(1!==i.preopen)return 8;const r=ot.encode(i.path);if(r.length>n)return 42;const{HEAPU8:s}=tt(this);return s.set(r,e),0})),this.fd_seek=it(this,"fd_seek",(function(t,e,n,i){if(0===(i=Number(i)))return 28;if(0===t||1===t||2===t)return 0;const r=Q.get(this).fds.get(t,m.FD_SEEK,BigInt(0)).seek(e,n),{view:s}=tt(this);return s.setBigUint64(i,r,!0),0})),this.fd_tell=it(this,"fd_tell",(function(t,e){const n=Q.get(this).fds.get(t,m.FD_TELL,BigInt(0)),i=BigInt(n.pos),{view:r}=tt(this);return r.setBigUint64(Number(e),i,!0),0})),this.poll_oneoff=it(this,"poll_oneoff",(function(t,e,n,i){if(t=Number(t),e=Number(e),i=Number(i),n=Number(n),n>>>=0,0===t||0===e||0===n||0===i)return 28;const{view:r}=tt(this);r.setUint32(i,0,!0);let s,o=0,a=BigInt(0),c=BigInt(0),u=0,f=BigInt(0);const h=Array(n);for(o=0;o0){for(o=0;o!1));const t=e;r.setBigUint64(t,a,!0),r.setUint32(t+8,0,!0),r.setUint32(t+12,0,!0),r.setUint32(i,1,!0)}return 0})),this.proc_exit=it(this,"proc_exit",(function(t){return"object"==typeof process&&null!==process&&"function"==typeof process.exit&&process.exit(t),0})),this.proc_raise=it(this,"proc_raise",(function(t){return 52})),this.sched_yield=it(this,"sched_yield",(function(){return 0})),this.random_get="undefined"!=typeof crypto&&"function"==typeof crypto.getRandomValues?it(this,"random_get",(function(t,e){if(0===(t=Number(t)))return 28;e=Number(e);const{HEAPU8:n,view:i}=tt(this);if("function"==typeof SharedArrayBuffer&&n.buffer instanceof SharedArrayBuffer||"[object SharedArrayBuffer]"===Object.prototype.toString.call(n.buffer)){for(let n=t;nct)return 28;const{HEAPU8:s,view:o}=tt(this),a=Q.get(this).fds.get(t,m.FD_READ|m.FD_SEEK,BigInt(0));if(!n)return o.setUint32(r,0,!0),0;let c=0;const u=Array.from({length:Number(n)},((t,n)=>{const i=e+8*n,r=o.getInt32(i,!0),a=o.getUint32(i+4,!0);return c+=a,s.subarray(r,r+a)}));let f=0;const h=(()=>{try{return new Uint8Array(new SharedArrayBuffer(c))}catch(t){return new Uint8Array(c)}})();h._isBuffer=!0;const d=et(this).readSync(a.fd,h,0,h.length,Number(i));return f=h?q(u,h.subarray(0,d)):0,o.setUint32(r,f,!0),0}),(async function(t,e,n,i,r){if(e=Number(e),r=Number(r),0===e&&n||0===r||i>ct)return 28;const{HEAPU8:s,view:o}=tt(this),a=Q.get(this).fds.get(t,m.FD_READ|m.FD_SEEK,BigInt(0));if(!n)return o.setUint32(r,0,!0),0;let c=0;const u=Array.from({length:Number(n)},((t,n)=>{const i=e+8*n,r=o.getInt32(i,!0),a=o.getUint32(i+4,!0);return c+=a,s.subarray(r,r+a)}));let f=0;const h=new Uint8Array(c);h._isBuffer=!0;const{bytesRead:d}=await a.fd.read(h,0,h.length,Number(i));return f=h?q(u,h.subarray(0,d)):0,o.setUint32(r,f,!0),0}),["i32","i32","i32","i64","i32"],["i32"]),u("fd_pwrite",(function(t,e,n,i,r){if(e=Number(e),r=Number(r),0===e&&n||0===r||i>ct)return 28;const{HEAPU8:s,view:o}=tt(this),a=Q.get(this).fds.get(t,m.FD_WRITE|m.FD_SEEK,BigInt(0));if(!n)return o.setUint32(r,0,!0),0;const c=O(Array.from({length:Number(n)},((t,n)=>{const i=e+8*n,r=o.getInt32(i,!0),a=o.getUint32(i+4,!0);return s.subarray(r,r+a)}))),u=et(this).writeSync(a.fd,c,0,c.length,Number(i));return o.setUint32(r,u,!0),0}),(async function(t,e,n,i,r){if(e=Number(e),r=Number(r),0===e&&n||0===r||i>ct)return 28;const{HEAPU8:s,view:o}=tt(this),a=Q.get(this).fds.get(t,m.FD_WRITE|m.FD_SEEK,BigInt(0));if(!n)return o.setUint32(r,0,!0),0;const c=O(Array.from({length:Number(n)},((t,n)=>{const i=e+8*n,r=o.getInt32(i,!0),a=o.getUint32(i+4,!0);return s.subarray(r,r+a)}))),{bytesWritten:u}=await a.fd.write(c,0,c.length,Number(i));return o.setUint32(r,u,!0),0}),["i32","i32","i32","i64","i32"],["i32"]),u("fd_read",(function(t,e,n,i){if(e=Number(e),i=Number(i),0===e&&n||0===i)return 28;const{HEAPU8:r,view:s}=tt(this),o=Q.get(this).fds.get(t,m.FD_READ,BigInt(0));if(!n)return s.setUint32(i,0,!0),0;let a=0;const c=Array.from({length:Number(n)},((t,n)=>{const i=e+8*n,o=s.getInt32(i,!0),c=s.getUint32(i+4,!0);return a+=c,r.subarray(o,o+c)}));let u,f=0;if(0===t){if("undefined"==typeof window||"function"!=typeof window.prompt)return 58;u=ut(),f=u?q(c,u):0}else{u=(()=>{try{return new Uint8Array(new SharedArrayBuffer(a))}catch(t){return new Uint8Array(a)}})(),u._isBuffer=!0;const t=et(this).readSync(o.fd,u,0,u.length,Number(o.pos));f=u?q(c,u.subarray(0,t)):0,o.pos+=BigInt(f)}return s.setUint32(i,f,!0),0}),(async function(t,e,n,i){if(e=Number(e),i=Number(i),0===e&&n||0===i)return 28;const{HEAPU8:r,view:s}=tt(this),o=Q.get(this).fds.get(t,m.FD_READ,BigInt(0));if(!n)return s.setUint32(i,0,!0),0;let a=0;const c=Array.from({length:Number(n)},((t,n)=>{const i=e+8*n,o=s.getInt32(i,!0),c=s.getUint32(i+4,!0);return a+=c,r.subarray(o,o+c)}));let u,f=0;if(0===t){if("undefined"==typeof window||"function"!=typeof window.prompt)return 58;u=ut(),f=u?q(c,u):0}else{u=new Uint8Array(a),u._isBuffer=!0;const{bytesRead:t}=await o.fd.read(u,0,u.length,Number(o.pos));f=u?q(c,u.subarray(0,t)):0,o.pos+=BigInt(f)}return s.setUint32(i,f,!0),0}),["i32","i32","i32","i32"],["i32"]),u("fd_readdir",(function(t,e,n,i,r){if(e=Number(e),n=Number(n),r=Number(r),0===e||0===r)return 0;const s=Q.get(this).fds.get(t,m.FD_READDIR,BigInt(0)),o=et(this),a=o.readdirSync(s.realPath,{withFileTypes:!0}),{HEAPU8:c,view:u}=tt(this);let f=0;for(let t=Number(i);t{const i=e+8*n,o=s.getInt32(i,!0),a=s.getUint32(i+4,!0);return r.subarray(o,o+a)})));let c;if(1===t||2===t)c=o.write(a);else{c=et(this).writeSync(o.fd,a,0,a.length,Number(o.pos)),o.pos+=BigInt(c)}return s.setUint32(i,c,!0),0}),(async function(t,e,n,i){if(e=Number(e),i=Number(i),0===e&&n||0===i)return 28;const{HEAPU8:r,view:s}=tt(this),o=Q.get(this).fds.get(t,m.FD_WRITE,BigInt(0));if(!n)return s.setUint32(i,0,!0),0;const a=O(Array.from({length:Number(n)},((t,n)=>{const i=e+8*n,o=s.getInt32(i,!0),a=s.getUint32(i+4,!0);return r.subarray(o,o+a)})));let c;return 1===t||2===t?c=o.write(a):(c=await(await o.fd.write(a,0,a.length,Number(o.pos))).bytesWritten,o.pos+=BigInt(c)),s.setUint32(i,c,!0),0}),["i32","i32","i32","i32"],["i32"]),u("path_create_directory",(function(t,e,n){if(e=Number(e),n=Number(n),0===e)return 28;const{HEAPU8:i}=tt(this),r=Q.get(this).fds.get(t,m.PATH_CREATE_DIRECTORY,BigInt(0));let s=at.decode(c(i,e,e+n));s=I(r.realPath,s);return et(this).mkdirSync(s),0}),(async function(t,e,n){if(e=Number(e),n=Number(n),0===e)return 28;const{HEAPU8:i}=tt(this),r=Q.get(this).fds.get(t,m.PATH_CREATE_DIRECTORY,BigInt(0));let s=at.decode(c(i,e,e+n));s=I(r.realPath,s);const o=et(this);return await o.promises.mkdir(s),0}),["i32","i32","i32"],["i32"]),u("path_filestat_get",(function(t,e,n,i,r){if(n=Number(n),i=Number(i),r=Number(r),0===n||0===r)return 28;const{HEAPU8:s,view:o}=tt(this),a=Q.get(this).fds.get(t,m.PATH_FILESTAT_GET,BigInt(0));let u=at.decode(c(s,n,n+i));const f=et(this);let h;return u=I(a.realPath,u),h=1==(1&e)?f.statSync(u,{bigint:!0}):f.lstatSync(u,{bigint:!0}),M(o,r,h),0}),(async function(t,e,n,i,r){if(n=Number(n),i=Number(i),r=Number(r),0===n||0===r)return 28;const{HEAPU8:s,view:o}=tt(this),a=Q.get(this).fds.get(t,m.PATH_FILESTAT_GET,BigInt(0));let u=at.decode(c(s,n,n+i));const f=et(this);let h;return u=I(a.realPath,u),h=1==(1&e)?await f.promises.stat(u,{bigint:!0}):await f.promises.lstat(u,{bigint:!0}),M(o,r,h),0}),["i32","i32","i32","i32","i32"],["i32"]),u("path_filestat_set_times",(function(t,e,n,i,r,s,o){if(n=Number(n),i=Number(i),0===n)return 28;const{HEAPU8:a}=tt(this),u=Q.get(this).fds.get(t,m.PATH_FILESTAT_SET_TIMES,BigInt(0));if(ft(o))return 28;const f=et(this),h=rt(f,u,at.decode(c(a,n,n+i)),e);return 2==(2&o)&&(r=BigInt(1e6*Date.now())),8==(8&o)&&(s=BigInt(1e6*Date.now())),f.utimesSync(h,Number(r),Number(s)),0}),(async function(t,e,n,i,r,s,o){if(n=Number(n),i=Number(i),0===n)return 28;const{HEAPU8:a}=tt(this),u=Q.get(this).fds.get(t,m.PATH_FILESTAT_SET_TIMES,BigInt(0));if(ft(o))return 28;const f=et(this),h=await st(f,u,at.decode(c(a,n,n+i)),e);return 2==(2&o)&&(r=BigInt(1e6*Date.now())),8==(8&o)&&(s=BigInt(1e6*Date.now())),await f.promises.utimes(h,Number(r),Number(s)),0}),["i32","i32","i32","i32","i64","i64","i32"],["i32"]),u("path_link",(function(t,e,n,i,r,s,o){if(n=Number(n),i=Number(i),s=Number(s),o=Number(o),0===n||0===s)return 28;const a=Q.get(this);let u,f;t===r?u=f=a.fds.get(t,m.PATH_LINK_SOURCE|m.PATH_LINK_TARGET,BigInt(0)):(u=a.fds.get(t,m.PATH_LINK_SOURCE,BigInt(0)),f=a.fds.get(r,m.PATH_LINK_TARGET,BigInt(0)));const{HEAPU8:h}=tt(this),d=et(this),g=rt(d,u,at.decode(c(h,n,n+i)),e),l=I(f.realPath,at.decode(c(h,s,s+o)));return d.linkSync(g,l),0}),(async function(t,e,n,i,r,s,o){if(n=Number(n),i=Number(i),s=Number(s),o=Number(o),0===n||0===s)return 28;const a=Q.get(this);let u,f;t===r?u=f=a.fds.get(t,m.PATH_LINK_SOURCE|m.PATH_LINK_TARGET,BigInt(0)):(u=a.fds.get(t,m.PATH_LINK_SOURCE,BigInt(0)),f=a.fds.get(r,m.PATH_LINK_TARGET,BigInt(0)));const{HEAPU8:h}=tt(this),d=et(this),g=await st(d,u,at.decode(c(h,n,n+i)),e),l=I(f.realPath,at.decode(c(h,s,s+o)));return await d.promises.link(g,l),0}),["i32","i32","i32","i32","i32","i32","i32"],["i32"]),u("path_open",(function(t,e,n,i,r,s,o,a,u){if(n=Number(n),u=Number(u),0===n||0===u)return 28;i=Number(i),s=BigInt(s),o=BigInt(o);const{flags:f,needed_base:d,needed_inheriting:g}=h(r,s,o,a),l=Q.get(this),_=l.fds.get(t,d,g),y=tt(this),p=y.HEAPU8,E=at.decode(c(p,n,n+i)),I=et(this),m=rt(I,_,E,e),A=I.openSync(m,f,438),b=l.fds.getFileTypeByFd(A);if(3!==b&&(0!=(2&r)||m.endsWith("/")))return 54;const{base:T,inheriting:w}=H(l.fds.stdio,A,f,b),B=l.fds.insert(A,m,m,b,s&T,o&w,0),N=I.fstatSync(A,{bigint:!0});N.isFile()&&(B.size=N.size,0!=(1024&f)&&(B.pos=N.size));return y.view.setInt32(u,B.id,!0),0}),(async function(t,e,n,i,r,s,o,a,u){if(n=Number(n),u=Number(u),0===n||0===u)return 28;i=Number(i),s=BigInt(s),o=BigInt(o);const{flags:f,needed_base:d,needed_inheriting:g}=h(r,s,o,a),l=Q.get(this),_=l.fds.get(t,d,g),y=tt(this),p=y.HEAPU8,E=at.decode(c(p,n,n+i)),I=et(this),m=await st(I,_,E,e),A=await I.promises.open(m,f,438),b=await l.fds.getFileTypeByFd(A);if(0!=(2&r)&&3!==b)return 54;const{base:T,inheriting:w}=H(l.fds.stdio,A.fd,f,b),B=l.fds.insert(A,m,m,b,s&T,o&w,0),N=await A.stat({bigint:!0});N.isFile()&&(B.size=N.size,0!=(1024&f)&&(B.pos=N.size));return y.view.setInt32(u,B.id,!0),0}),["i32","i32","i32","i32","i32","i64","i64","i32","i32"],["i32"]),u("path_readlink",(function(t,e,n,i,r,s){if(e=Number(e),n=Number(n),i=Number(i),r=Number(r),s=Number(s),0===e||0===i||0===s)return 28;const{HEAPU8:o,view:a}=tt(this),u=Q.get(this).fds.get(t,m.PATH_READLINK,BigInt(0));let f=at.decode(c(o,e,e+n));f=I(u.realPath,f);const h=et(this).readlinkSync(f),d=ot.encode(h),g=Math.min(d.length,r);return g>=r?42:(o.set(d.subarray(0,g),i),o[i+g]=0,a.setUint32(s,g,!0),0)}),(async function(t,e,n,i,r,s){if(e=Number(e),n=Number(n),i=Number(i),r=Number(r),s=Number(s),0===e||0===i||0===s)return 28;const{HEAPU8:o,view:a}=tt(this),u=Q.get(this).fds.get(t,m.PATH_READLINK,BigInt(0));let f=at.decode(c(o,e,e+n));f=I(u.realPath,f);const h=et(this),d=await h.promises.readlink(f),g=ot.encode(d),l=Math.min(g.length,r);return l>=r?42:(o.set(g.subarray(0,l),i),o[i+l]=0,a.setUint32(s,l,!0),0)}),["i32","i32","i32","i32","i32","i32"],["i32"]),u("path_remove_directory",(function(t,e,n){if(e=Number(e),n=Number(n),0===e)return 28;const{HEAPU8:i}=tt(this),r=Q.get(this).fds.get(t,m.PATH_REMOVE_DIRECTORY,BigInt(0));let s=at.decode(c(i,e,e+n));s=I(r.realPath,s);return et(this).rmdirSync(s),0}),(async function(t,e,n){if(e=Number(e),n=Number(n),0===e)return 28;const{HEAPU8:i}=tt(this),r=Q.get(this).fds.get(t,m.PATH_REMOVE_DIRECTORY,BigInt(0));let s=at.decode(c(i,e,e+n));s=I(r.realPath,s);const o=et(this);return await o.promises.rmdir(s),0}),["i32","i32","i32"],["i32"]),u("path_rename",(function(t,e,n,i,r,s){if(e=Number(e),n=Number(n),r=Number(r),s=Number(s),0===e||0===r)return 28;const o=Q.get(this);let a,u;t===i?a=u=o.fds.get(t,m.PATH_RENAME_SOURCE|m.PATH_RENAME_TARGET,BigInt(0)):(a=o.fds.get(t,m.PATH_RENAME_SOURCE,BigInt(0)),u=o.fds.get(i,m.PATH_RENAME_TARGET,BigInt(0)));const{HEAPU8:f}=tt(this),h=I(a.realPath,at.decode(c(f,e,e+n))),d=I(u.realPath,at.decode(c(f,r,r+s)));return et(this).renameSync(h,d),0}),(async function(t,e,n,i,r,s){if(e=Number(e),n=Number(n),r=Number(r),s=Number(s),0===e||0===r)return 28;const o=Q.get(this);let a,u;t===i?a=u=o.fds.get(t,m.PATH_RENAME_SOURCE|m.PATH_RENAME_TARGET,BigInt(0)):(a=o.fds.get(t,m.PATH_RENAME_SOURCE,BigInt(0)),u=o.fds.get(i,m.PATH_RENAME_TARGET,BigInt(0)));const{HEAPU8:f}=tt(this),h=I(a.realPath,at.decode(c(f,e,e+n))),d=I(u.realPath,at.decode(c(f,r,r+s))),g=et(this);return await g.promises.rename(h,d),0}),["i32","i32","i32","i32","i32","i32"],["i32"]),u("path_symlink",(function(t,e,n,i,r){if(t=Number(t),e=Number(e),i=Number(i),r=Number(r),0===t||0===i)return 28;const{HEAPU8:s}=tt(this),o=Q.get(this).fds.get(n,m.PATH_SYMLINK,BigInt(0)),a=at.decode(c(s,t,t+e));if(a.length>0&&"/"===a[0])return 63;let u=at.decode(c(s,i,i+r));u=I(o.realPath,u);return et(this).symlinkSync(a,u),0}),(async function(t,e,n,i,r){if(t=Number(t),e=Number(e),i=Number(i),r=Number(r),0===t||0===i)return 28;const{HEAPU8:s}=tt(this),o=Q.get(this).fds.get(n,m.PATH_SYMLINK,BigInt(0)),a=at.decode(c(s,t,t+e));let u=at.decode(c(s,i,i+r));u=I(o.realPath,u);const f=et(this);return await f.promises.symlink(a,u),0}),["i32","i32","i32","i32","i32"],["i32"]),u("path_unlink_file",(function(t,e,n){if(e=Number(e),n=Number(n),0===e)return 28;const{HEAPU8:i}=tt(this),r=Q.get(this).fds.get(t,m.PATH_UNLINK_FILE,BigInt(0));let s=at.decode(c(i,e,e+n));s=I(r.realPath,s);return et(this).unlinkSync(s),0}),(async function(t,e,n){if(e=Number(e),n=Number(n),0===e)return 28;const{HEAPU8:i}=tt(this),r=Q.get(this).fds.get(t,m.PATH_UNLINK_FILE,BigInt(0));let s=at.decode(c(i,e,e+n));s=I(r.realPath,s);const o=et(this);return await o.promises.unlink(s),0}),["i32","i32","i32"],["i32"]),this._setMemory=function(t){if(!(t instanceof e.Memory))throw new TypeError('"instance.exports.memory" property must be a WebAssembly.Memory');X.set(a,Y(t))}}static createSync(t,e,n,i,r,s,o){const a=new z({size:3,in:i[0],out:i[1],err:i[2],fs:r,print:s,printErr:o}),c=new ht(t,e,a,!1,r);if(n.length>0)for(let t=0;t0)for(let t=0;t{void 0!==e&&a.push(`${t}=${e}`)})));const c=[];if(void 0!==t.preopens&&(n(t.preopens,"options.preopens"),Object.entries(t.preopens).forEach((({0:t,1:e})=>c.push({mappedPath:String(t),realPath:String(e)})))),c.length>0){if(void 0===t.fs)throw new Error("filesystem is disabled, can not preopen directory");try{n(t.fs,"options.fs")}catch(t){throw new TypeError("Node.js fs like implementation is not provided")}}void 0!==t.print&&r(t.print,"options.print"),void 0!==t.printErr&&r(t.printErr,"options.printErr"),void 0!==t.returnOnExit&&function(t,e){if("boolean"!=typeof t)throw new TypeError(`${e} must be a boolean. Received ${null===t?"null":typeof t}`)}(t.returnOnExit,"options.returnOnExit");return{args:o,env:a,preopens:c,stdio:[0,1,2],_WASI:s}}function It(t,e){this[lt]=t,this.wasiImport=e,this[_t]=!1,this[gt]=0,this[yt]=void 0}class mt{constructor(t=dt){const{args:e,env:n,preopens:i,stdio:r,_WASI:s}=Et.call(this,t),o=s.createSync(e,n,i,r,t.fs,t.print,t.printErr),a=o._setMemory;delete o._setMemory,It.call(this,a,o),t.returnOnExit&&(o.proc_exit=At.bind(this))}finalizeBindings(t,e){var i,{memory:r=(null===(i=null==t?void 0:t.exports)||void 0===i?void 0:i.memory)}=void 0===e?{}:e;if(this[_t])throw new Error("WASI instance has already started");n(t,"instance"),n(t.exports,"instance.exports"),this[lt](r),this[yt]=t,this[_t]=!0}start(t){this.finalizeBindings(t);const{_start:e,_initialize:n}=this[yt].exports;let i;r(e,"instance.exports._start"),s(n,"instance.exports._initialize");try{i=e()}catch(t){if(t!==gt)throw t}return i instanceof Promise?i.then((()=>this[gt]),(t=>{if(t!==gt)throw t;return this[gt]})):this[gt]}initialize(t){this.finalizeBindings(t);const{_start:e,_initialize:n}=this[yt].exports;if(s(e,"instance.exports._start"),void 0!==n)return r(n,"instance.exports._initialize"),n()}getImportObject(){return{[this[pt]]:this.wasiImport}}}function At(t){throw this[gt]=t,gt}t.Asyncify=h,t.Memory=G,t.WASI=mt,t.WebAssemblyMemory=j,t.asyncifyLoad=function(t,e,n){d(n),n=null!=n?n:{};const i=new h;return l(e,n=i.wrapImports(n)).then((e=>{var r;const s=e.instance.exports.memory||(null===(r=n.env)||void 0===r?void 0:r.memory);return{module:e.module,instance:i.init(s,e.instance,t)}}))},t.asyncifyLoadSync=function(t,e,n){var i;d(n),n=null!=n?n:{};const r=new h,s=_(e,n=r.wrapImports(n)),o=s.instance.exports.memory||(null===(i=n.env)||void 0===i?void 0:i.memory);return{module:s.module,instance:r.init(o,s.instance,t)}},t.createAsyncWASI=async function(t=dt){const e=Object.create(mt.prototype),{args:i,env:s,preopens:o,stdio:a,_WASI:c}=Et.call(e,t);void 0!==t.asyncify&&(n(t.asyncify,"options.asyncify"),r(t.asyncify.wrapImportFunction,"options.asyncify.wrapImportFunction"));const u=await c.createAsync(i,s,o,a,t.fs,t.print,t.printErr,t.asyncify),f=u._setMemory;return delete u._setMemory,It.call(e,f,u),t.returnOnExit&&(u.proc_exit=At.bind(e)),e},t.extendMemory=Y,t.load=l,t.loadSync=_,t.wrapAsyncExport=Z,t.wrapAsyncImport=V,t.wrapExports=function(t,e){return a(t,((t,n)=>{let i="function"!=typeof t;return Array.isArray(e)&&(i=i||-1===e.indexOf(n)),i?t:Z(t)}))},Object.defineProperty(t,"__esModule",{value:!0})}));