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