@tybys/wasm-util 0.5.2 → 0.5.3

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -202,50 +202,53 @@ function validateImports(imports) {
202
202
  throw new TypeError('imports must be an object or undefined');
203
203
  }
204
204
  }
205
- async function fetchWasm(urlOrBuffer, imports) {
205
+ function fetchWasm(urlOrBuffer, imports) {
206
206
  if (typeof wx !== 'undefined' && typeof __wxConfig !== 'undefined') {
207
- return await _WebAssembly.instantiate(urlOrBuffer, imports);
207
+ return _WebAssembly.instantiate(urlOrBuffer, imports);
208
208
  }
209
- const response = await fetch(urlOrBuffer);
210
- const buffer = await response.arrayBuffer();
211
- const source = await _WebAssembly.instantiate(buffer, imports);
212
- return source;
209
+ return fetch(urlOrBuffer)
210
+ .then(response => response.arrayBuffer())
211
+ .then(buffer => _WebAssembly.instantiate(buffer, imports));
213
212
  }
214
213
  /** @public */
215
- async function load(urlOrBuffer, imports) {
214
+ function load(urlOrBuffer, imports) {
216
215
  validateImports(imports);
217
216
  imports = imports !== null && imports !== void 0 ? imports : {};
218
217
  let source;
219
218
  if (urlOrBuffer instanceof ArrayBuffer || ArrayBuffer.isView(urlOrBuffer)) {
220
- source = await _WebAssembly.instantiate(urlOrBuffer, imports);
221
- return source;
219
+ return _WebAssembly.instantiate(urlOrBuffer, imports);
222
220
  }
223
221
  if (typeof urlOrBuffer !== 'string' && !(urlOrBuffer instanceof URL)) {
224
222
  throw new TypeError('Invalid source');
225
223
  }
226
224
  if (typeof _WebAssembly.instantiateStreaming === 'function') {
225
+ let responsePromise;
227
226
  try {
228
- source = await _WebAssembly.instantiateStreaming(fetch(urlOrBuffer), imports);
227
+ responsePromise = fetch(urlOrBuffer);
228
+ source = _WebAssembly.instantiateStreaming(responsePromise, imports).catch(() => {
229
+ return fetchWasm(urlOrBuffer, imports);
230
+ });
229
231
  }
230
232
  catch (_) {
231
- source = await fetchWasm(urlOrBuffer, imports);
233
+ source = fetchWasm(urlOrBuffer, imports);
232
234
  }
233
235
  }
234
236
  else {
235
- source = await fetchWasm(urlOrBuffer, imports);
237
+ source = fetchWasm(urlOrBuffer, imports);
236
238
  }
237
239
  return source;
238
240
  }
239
241
  /** @public */
240
- async function asyncifyLoad(asyncify, urlOrBuffer, imports) {
241
- var _a;
242
+ function asyncifyLoad(asyncify, urlOrBuffer, imports) {
242
243
  validateImports(imports);
243
244
  imports = imports !== null && imports !== void 0 ? imports : {};
244
245
  const asyncifyHelper = new Asyncify();
245
246
  imports = asyncifyHelper.wrapImports(imports);
246
- const source = await load(urlOrBuffer, imports);
247
- const memory = source.instance.exports.memory || ((_a = imports.env) === null || _a === void 0 ? void 0 : _a.memory);
248
- return { module: source.module, instance: asyncifyHelper.init(memory, source.instance, asyncify) };
247
+ return load(urlOrBuffer, imports).then(source => {
248
+ var _a;
249
+ const memory = source.instance.exports.memory || ((_a = imports.env) === null || _a === void 0 ? void 0 : _a.memory);
250
+ return { module: source.module, instance: asyncifyHelper.init(memory, source.instance, asyncify) };
251
+ });
249
252
  }
250
253
  /** @public */
251
254
  function loadSync(buffer, imports) {
@@ -202,50 +202,53 @@ function validateImports(imports) {
202
202
  throw new TypeError('imports must be an object or undefined');
203
203
  }
204
204
  }
205
- async function fetchWasm(urlOrBuffer, imports) {
205
+ function fetchWasm(urlOrBuffer, imports) {
206
206
  if (typeof wx !== 'undefined' && typeof __wxConfig !== 'undefined') {
207
- return await _WebAssembly.instantiate(urlOrBuffer, imports);
207
+ return _WebAssembly.instantiate(urlOrBuffer, imports);
208
208
  }
209
- const response = await fetch(urlOrBuffer);
210
- const buffer = await response.arrayBuffer();
211
- const source = await _WebAssembly.instantiate(buffer, imports);
212
- return source;
209
+ return fetch(urlOrBuffer)
210
+ .then(response => response.arrayBuffer())
211
+ .then(buffer => _WebAssembly.instantiate(buffer, imports));
213
212
  }
214
213
  /** @public */
215
- async function load(urlOrBuffer, imports) {
214
+ function load(urlOrBuffer, imports) {
216
215
  validateImports(imports);
217
216
  imports = imports !== null && imports !== void 0 ? imports : {};
218
217
  let source;
219
218
  if (urlOrBuffer instanceof ArrayBuffer || ArrayBuffer.isView(urlOrBuffer)) {
220
- source = await _WebAssembly.instantiate(urlOrBuffer, imports);
221
- return source;
219
+ return _WebAssembly.instantiate(urlOrBuffer, imports);
222
220
  }
223
221
  if (typeof urlOrBuffer !== 'string' && !(urlOrBuffer instanceof URL)) {
224
222
  throw new TypeError('Invalid source');
225
223
  }
226
224
  if (typeof _WebAssembly.instantiateStreaming === 'function') {
225
+ let responsePromise;
227
226
  try {
228
- source = await _WebAssembly.instantiateStreaming(fetch(urlOrBuffer), imports);
227
+ responsePromise = fetch(urlOrBuffer);
228
+ source = _WebAssembly.instantiateStreaming(responsePromise, imports).catch(() => {
229
+ return fetchWasm(urlOrBuffer, imports);
230
+ });
229
231
  }
230
232
  catch (_) {
231
- source = await fetchWasm(urlOrBuffer, imports);
233
+ source = fetchWasm(urlOrBuffer, imports);
232
234
  }
233
235
  }
234
236
  else {
235
- source = await fetchWasm(urlOrBuffer, imports);
237
+ source = fetchWasm(urlOrBuffer, imports);
236
238
  }
237
239
  return source;
238
240
  }
239
241
  /** @public */
240
- async function asyncifyLoad(asyncify, urlOrBuffer, imports) {
241
- var _a;
242
+ function asyncifyLoad(asyncify, urlOrBuffer, imports) {
242
243
  validateImports(imports);
243
244
  imports = imports !== null && imports !== void 0 ? imports : {};
244
245
  const asyncifyHelper = new Asyncify();
245
246
  imports = asyncifyHelper.wrapImports(imports);
246
- const source = await load(urlOrBuffer, imports);
247
- const memory = source.instance.exports.memory || ((_a = imports.env) === null || _a === void 0 ? void 0 : _a.memory);
248
- return { module: source.module, instance: asyncifyHelper.init(memory, source.instance, asyncify) };
247
+ return load(urlOrBuffer, imports).then(source => {
248
+ var _a;
249
+ const memory = source.instance.exports.memory || ((_a = imports.env) === null || _a === void 0 ? void 0 : _a.memory);
250
+ return { module: source.module, instance: asyncifyHelper.init(memory, source.instance, asyncify) };
251
+ });
249
252
  }
250
253
  /** @public */
251
254
  function loadSync(buffer, imports) {
@@ -1 +1 @@
1
- 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}const a=["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 c{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<a.length;++t)if("function"!=typeof o[a[t]])throw new TypeError("Invalid asyncify wasm");let c;const f=Boolean(r.wasm64);c=r.tryAllocate?!0===r.tryAllocate?u(n,f,4096,"malloc"):u(n,f,null!==(i=r.tryAllocate.size)&&void 0!==i?i:4096,null!==(s=r.tryAllocate.name)&&void 0!==s?s:"malloc"):{wasm64:f,dataPtr:16,start:f?32:24,end:1024},this.dataPtr=c.dataPtr,f?new BigInt64Array(e.buffer,this.dataPtr).set([BigInt(c.start),BigInt(c.end)]):new Int32Array(e.buffer,this.dataPtr).set([c.start,c.end]),this.exports=this.wrapExports(o,r.wrapExports);const h=Object.create(t.Instance.prototype);return Object.defineProperty(h,"exports",{value:this.exports}),h}assertState(){if(0!==this.exports.asyncify_get_state())throw new Error("Asyncify state error")}wrapImportFunction(t){const e=this;return function(){for(;2===e.exports.asyncify_get_state();)return e.exports.asyncify_stop_rewind(),e.value;e.assertState();const n=t.apply(this,arguments);if(!s(n))return n;e.exports.asyncify_start_unwind(e.dataPtr),e.value=n}}wrapImports(t){const e={};return Object.keys(t).forEach((n=>{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!==a.indexOf(n)||"function"!=typeof t;return Array.isArray(e)&&(r=r||-1===e.indexOf(n)),r?t:this.wrapExportFunction(t)}))}}function f(t){if(t&&"object"!=typeof t)throw new TypeError("imports must be an object or undefined")}async function h(e,n){if("undefined"!=typeof wx&&"undefined"!=typeof __wxConfig)return await t.instantiate(e,n);const r=await fetch(e),i=await r.arrayBuffer();return await t.instantiate(i,n)}async function d(e,n){let r;if(f(n),n=null!=n?n:{},e instanceof ArrayBuffer||ArrayBuffer.isView(e))return r=await t.instantiate(e,n),r;if("string"!=typeof e&&!(e instanceof URL))throw new TypeError("Invalid source");if("function"==typeof t.instantiateStreaming)try{r=await t.instantiateStreaming(fetch(e),n)}catch(t){r=await h(e,n)}else r=await h(e,n);return r}async function g(t,e,n){var r;f(n),n=null!=n?n:{};const i=new c;n=i.wrapImports(n);const s=await d(e,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)}}function l(e,n){if(e instanceof ArrayBuffer&&!ArrayBuffer.isView(e))throw new TypeError("Invalid source");f(n),n=null!=n?n:{};const r=new t.Module(e);return{instance:new t.Instance(r,n),module:r}}function _(t,e,n){var r;f(n),n=null!=n?n:{};const i=new c,s=l(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)}}function E(t){return 47===t}function y(...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=47===s.charCodeAt(0))}return e=function(t,e,n,r){let i="",s=0,o=-1,a=0,u=0;for(let c=0;c<=t.length;++c){if(c<t.length)u=t.charCodeAt(c);else{if(r(u))break;u=47}if(r(u)){if(o===c-1||1===a);else if(2===a){if(i.length<2||2!==s||46!==i.charCodeAt(i.length-1)||46!==i.charCodeAt(i.length-2)){if(i.length>2){const t=i.indexOf(n);-1===t?(i="",s=0):(i=i.slice(0,t),s=i.length-1-i.indexOf(n)),o=c,a=0;continue}if(0!==i.length){i="",s=0,o=c,a=0;continue}}e&&(i+=i.length>0?`${n}..`:"..",s=2)}else i.length>0?i+=`${n}${t.slice(o+1,c)}`:i=t.slice(o+1,c),s=c-o-1;o=c,a=0}else 46===u&&-1!==a?++a:a=-1}return i}(e,!r,"/",E),r?`/${e}`:e.length>0?e:"."}const p={FD_DATASYNC:BigInt(1)<<BigInt(0),FD_READ:BigInt(1)<<BigInt(1),FD_SEEK:BigInt(1)<<BigInt(2),FD_FDSTAT_SET_FLAGS:BigInt(1)<<BigInt(3),FD_SYNC:BigInt(1)<<BigInt(4),FD_TELL:BigInt(1)<<BigInt(5),FD_WRITE:BigInt(1)<<BigInt(6),FD_ADVISE:BigInt(1)<<BigInt(7),FD_ALLOCATE:BigInt(1)<<BigInt(8),PATH_CREATE_DIRECTORY:BigInt(1)<<BigInt(9),PATH_CREATE_FILE:BigInt(1)<<BigInt(10),PATH_LINK_SOURCE:BigInt(1)<<BigInt(11),PATH_LINK_TARGET:BigInt(1)<<BigInt(12),PATH_OPEN:BigInt(1)<<BigInt(13),FD_READDIR:BigInt(1)<<BigInt(14),PATH_READLINK:BigInt(1)<<BigInt(15),PATH_RENAME_SOURCE:BigInt(1)<<BigInt(16),PATH_RENAME_TARGET:BigInt(1)<<BigInt(17),PATH_FILESTAT_GET:BigInt(1)<<BigInt(18),PATH_FILESTAT_SET_SIZE:BigInt(1)<<BigInt(19),PATH_FILESTAT_SET_TIMES:BigInt(1)<<BigInt(20),FD_FILESTAT_GET:BigInt(1)<<BigInt(21),FD_FILESTAT_SET_SIZE:BigInt(1)<<BigInt(22),FD_FILESTAT_SET_TIMES:BigInt(1)<<BigInt(23),PATH_SYMLINK:BigInt(1)<<BigInt(24),PATH_REMOVE_DIRECTORY:BigInt(1)<<BigInt(25),PATH_UNLINK_FILE:BigInt(1)<<BigInt(26),POLL_FD_READWRITE:BigInt(1)<<BigInt(27),SOCK_SHUTDOWN:BigInt(1)<<BigInt(28),SOCK_ACCEPT:BigInt(1)<<BigInt(29)};class I extends Error{constructor(t,e){super(t),this.errno=e}getErrorMessage(){return function(t){switch(t){case 0:return"Success";case 1:return"Argument list too long";case 2:return"Permission denied";case 3:return"Address in use";case 4:return"Address not available";case 5:return"Address family not supported by protocol";case 6:return"Resource temporarily unavailable";case 7:return"Operation already in progress";case 8:return"Bad file descriptor";case 9:return"Bad message";case 10:return"Resource busy";case 11:return"Operation canceled";case 12:return"No child process";case 13:return"Connection aborted";case 14:return"Connection refused";case 15:return"Connection reset by peer";case 16:return"Resource deadlock would occur";case 17:return"Destination address required";case 18:return"Domain error";case 19:return"Quota exceeded";case 20:return"File exists";case 21:return"Bad address";case 22:return"File too large";case 23:return"Host is unreachable";case 24:return"Identifier removed";case 25:return"Illegal byte sequence";case 26:return"Operation in progress";case 27:return"Interrupted system call";case 28:return"Invalid argument";case 29:return"I/O error";case 30:return"Socket is connected";case 31:return"Is a directory";case 32:return"Symbolic link loop";case 33:return"No file descriptors available";case 34:return"Too many links";case 35:return"Message too large";case 36:return"Multihop attempted";case 37:return"Filename too long";case 38:return"Network is down";case 39:return"Connection reset by network";case 40:return"Network unreachable";case 41:return"Too many files open in system";case 42:return"No buffer space available";case 43:return"No such device";case 44:return"No such file or directory";case 45:return"Exec format error";case 46:return"No locks available";case 47:return"Link has been severed";case 48:return"Out of memory";case 49:return"No message of the desired type";case 50:return"Protocol not available";case 51:return"No space left on device";case 52:return"Function not implemented";case 53:return"Socket not connected";case 54:return"Not a directory";case 55:return"Directory not empty";case 56:return"State not recoverable";case 57:return"Not a socket";case 58:return"Not supported";case 59:return"Not a tty";case 60:return"No such device or address";case 61:return"Value too large for data type";case 62:return"Previous owner died";case 63:return"Operation not permitted";case 64:return"Broken pipe";case 65:return"Protocol error";case 66:return"Protocol not supported";case 67:return"Protocol wrong type for socket";case 68:return"Result not representable";case 69:return"Read-only file system";case 70:return"Invalid seek";case 71:return"No such process";case 72:return"Stale file handle";case 73:return"Operation timed out";case 74:return"Text file busy";case 75:return"Cross-device link";case 76:return"Capabilities insufficient";default:return"Unknown error"}}(this.errno)}}Object.defineProperty(I.prototype,"name",{configurable:!0,writable:!0,value:"WasiError"});const b=p.FD_DATASYNC|p.FD_READ|p.FD_SEEK|p.FD_FDSTAT_SET_FLAGS|p.FD_SYNC|p.FD_TELL|p.FD_WRITE|p.FD_ADVISE|p.FD_ALLOCATE|p.PATH_CREATE_DIRECTORY|p.PATH_CREATE_FILE|p.PATH_LINK_SOURCE|p.PATH_LINK_TARGET|p.PATH_OPEN|p.FD_READDIR|p.PATH_READLINK|p.PATH_RENAME_SOURCE|p.PATH_RENAME_TARGET|p.PATH_FILESTAT_GET|p.PATH_FILESTAT_SET_SIZE|p.PATH_FILESTAT_SET_TIMES|p.FD_FILESTAT_GET|p.FD_FILESTAT_SET_TIMES|p.FD_FILESTAT_SET_SIZE|p.PATH_SYMLINK|p.PATH_UNLINK_FILE|p.PATH_REMOVE_DIRECTORY|p.POLL_FD_READWRITE|p.SOCK_SHUTDOWN,m=b,A=b,T=b,w=b,N=p.FD_DATASYNC|p.FD_READ|p.FD_SEEK|p.FD_FDSTAT_SET_FLAGS|p.FD_SYNC|p.FD_TELL|p.FD_WRITE|p.FD_ADVISE|p.FD_ALLOCATE|p.FD_FILESTAT_GET|p.FD_FILESTAT_SET_SIZE|p.FD_FILESTAT_SET_TIMES|p.POLL_FD_READWRITE,B=BigInt(0),S=p.FD_FDSTAT_SET_FLAGS|p.FD_SYNC|p.FD_ADVISE|p.PATH_CREATE_DIRECTORY|p.PATH_CREATE_FILE|p.PATH_LINK_SOURCE|p.PATH_LINK_TARGET|p.PATH_OPEN|p.FD_READDIR|p.PATH_READLINK|p.PATH_RENAME_SOURCE|p.PATH_RENAME_TARGET|p.PATH_FILESTAT_GET|p.PATH_FILESTAT_SET_SIZE|p.PATH_FILESTAT_SET_TIMES|p.FD_FILESTAT_GET|p.FD_FILESTAT_SET_TIMES|p.PATH_SYMLINK|p.PATH_UNLINK_FILE|p.PATH_REMOVE_DIRECTORY|p.POLL_FD_READWRITE,P=S|N,D=p.FD_READ|p.FD_FDSTAT_SET_FLAGS|p.FD_WRITE|p.FD_FILESTAT_GET|p.POLL_FD_READWRITE|p.SOCK_SHUTDOWN,F=b,R=p.FD_READ|p.FD_FDSTAT_SET_FLAGS|p.FD_WRITE|p.FD_FILESTAT_GET|p.POLL_FD_READWRITE,v=BigInt(0);function U(t,e,n,r){const i={base:BigInt(0),inheriting:BigInt(0)};if(0===r)throw new I("Unknown file type",28);switch(r){case 4:i.base=N,i.inheriting=B;break;case 3:i.base=S,i.inheriting=P;break;case 6:case 5:i.base=D,i.inheriting=F;break;case 2:-1!==t.indexOf(e)?(i.base=R,i.inheriting=v):(i.base=T,i.inheriting=w);break;case 1:i.base=m,i.inheriting=A;break;default:i.base=BigInt(0),i.inheriting=BigInt(0)}const s=3&n;return 0===s?i.base&=~p.FD_WRITE:1===s&&(i.base&=~p.FD_READ),i}function L(t,e){let n=0;if("number"==typeof e&&e>=0)n=e;else for(let e=0;e<t.length;e++){n+=t[e].length}let r=0;const i=new Uint8Array(n);for(let e=0;e<t.length;e++){const n=t[e];i.set(n,r),r+=n.length}return i}class H{constructor(t,e,n,r,i,s,o,a){this.id=t,this.fd=e,this.path=n,this.realPath=r,this.type=i,this.rightsBase=s,this.rightsInheriting=o,this.preopen=a,this.pos=BigInt(0),this.size=BigInt(0)}seek(t,e){if(0===e)this.pos=BigInt(t);else if(1===e)this.pos+=BigInt(t);else{if(2!==e)throw new I("Unknown whence",29);this.pos=BigInt(this.size)-BigInt(t)}return this.pos}}class O extends H{constructor(t,e,n,r,i,s,o,a,u){super(e,n,r,i,s,o,a,u),this._log=t,this._buf=null}write(t){const e=t;if(this._buf&&(t=L([this._buf,t]),this._buf=null),-1===t.indexOf(10))return this._buf=t,e.byteLength;let n,r=0,i=0;for(;-1!==(n=t.indexOf(10,r));){const e=(new TextDecoder).decode(t.subarray(i,n));this._log(e),r+=n-i+1,i=n+1}return r<t.length&&(this._buf=t.slice(r)),e.byteLength}}function C(t){return t.isBlockDevice()?1:t.isCharacterDevice()?2:t.isDirectory()?3:t.isSocket()?6:t.isFile()?4:t.isSymbolicLink()?7:0}function k(t,e,n){t.setBigUint64(e,n.dev,!0),t.setBigUint64(e+8,n.ino,!0),t.setBigUint64(e+16,BigInt(C(n)),!0),t.setBigUint64(e+24,n.nlink,!0),t.setBigUint64(e+32,n.size,!0),t.setBigUint64(e+40,n.atimeMs*BigInt(1e6),!0),t.setBigUint64(e+48,n.mtimeMs*BigInt(1e6),!0),t.setBigUint64(e+56,n.ctimeMs*BigInt(1e6),!0)}class x{constructor(t){this.used=0,this.size=t.size,this.fds=Array(t.size),this.stdio=[t.in,t.out,t.err],this.print=t.print,this.printErr=t.printErr,this.insertStdio(t.in,0,"<stdin>"),this.insertStdio(t.out,1,"<stdout>"),this.insertStdio(t.err,2,"<stderr>")}insertStdio(t,e,n){const{base:r,inheriting:i}=U(this.stdio,t,2,2),s=this.insert(t,n,n,2,r,i,0);if(s.id!==e)throw new I(`id: ${s.id} !== expected: ${e}`,8);return s}insert(t,e,n,r,i,s,o){var a,u;let c,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<this.size;++t)if(null==this.fds[t]){f=t;break}return c="<stdout>"===e?new O(null!==(a=this.print)&&void 0!==a?a:console.log,f,t,e,n,r,i,s,o):"<stderr>"===e?new O(null!==(u=this.printErr)&&void 0!==u?u:console.error,f,t,e,n,r,i,s,o):new H(f,t,e,n,r,i,s,o),this.fds[f]=c,this.used++,c}get(t,e,n){if(t>=this.size)throw new I("Invalid fd",8);const r=this.fds[t];if(!r||r.id!==t)throw new I("Bad file descriptor",8);if((~r.rightsBase&e)!==BigInt(0)||(~r.rightsInheriting&n)!==BigInt(0))throw new I("Capabilities insufficient",76);return r}remove(t){if(t>=this.size)throw new I("Invalid fd",8);const e=this.fds[t];if(!e||e.id!==t)throw new I("Bad file descriptor",8);this.fds[t]=void 0,this.used--}}class M extends x{constructor(t){super(t),this.fs=t.fs}getFileTypeByFd(t){return C(this.fs.fstatSync(t,{bigint:!0}))}insertPreopen(t,e,n){const r=this.getFileTypeByFd(t);if(3!==r)throw new I(`Preopen not dir: ["${e}", "${n}"]`,54);const i=U(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 I("Invalid fd",8);const n=this.fds[t],r=this.fds[e];if(!n||!r||n.id!==t||r.id!==e)throw new I("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 x{constructor(t){super(t)}async getFileTypeByFd(t){return C(await t.stat({bigint:!0}))}async insertPreopen(t,e,n){const r=await this.getFileTypeByFd(t);if(3!==r)throw new I(`Preopen not dir: ["${e}", "${n}"]`,54);const i=U(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 I("Invalid fd",8);const n=this.fds[t],r=this.fds[e];if(!n||!r||n.id!==t||r.id!==e)throw new I("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 z=function(){return t.Memory}();class W extends z{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 G(e){return Object.getPrototypeOf(e)===t.Memory.prototype&&Object.setPrototypeOf(e,W.prototype),e}function Y(){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-flag="--wasm-staging --experimental-wasm-stack-switching"');return e}function $(t,e,n){const r=Y();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 j(t){const e=Y();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 V(t,e){return o(t,((t,n)=>{let r="function"!=typeof t;return Array.isArray(e)&&(r=r||-1===e.indexOf(n)),r?t:j(t)}))}function Z(t,e){if(0===t.length||0===e.length)return 0;let n=0,r=e.length-n;for(let i=0;i<t.length;++i){const s=t[i];if(r<s.length)return s.set(e.subarray(n,n+r),0),n+=r,r=0,n;s.set(e.subarray(n,n+s.length),0),n+=s.length,r-=s.length}return n}const q=new WeakMap,X=new WeakMap,Q=new WeakMap;function J(t){return q.get(t)}function tt(t){const e=Q.get(t);if(!e)throw new Error("filesystem is unavailable");return e}function et(t){if(t instanceof I)return t.errno;switch(t.code){case"ENOENT":return 44;case"EBADF":return 8;case"EINVAL":return 28;case"EPERM":return 63;case"EPROTO":return 65;case"EEXIST":return 20;case"ENOTDIR":return 54;case"EMFILE":return 33;case"EACCES":return 2;case"EISDIR":return 31;case"ENOTEMPTY":return 55;case"ENOSYS":return 52}throw t}function nt(t,e,n){return function(t,e){return Object.defineProperty(e,"name",{value:t}),e}(e,(function(){let e;try{e=n.apply(t,arguments)}catch(t){return et(t)}return s(e)?e.then((t=>t),et):e}))}function rt(t,e,n,r){let i=y(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 it(t,e,n,r){let i=y(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 st=new TextEncoder,ot=new TextDecoder;function at(){const t=window.prompt();if(null===t)return new Uint8Array;return(new TextEncoder).encode(t+"\n")}class ut{constructor(e,n,r,i,s,o){this.args_get=nt(this,"args_get",(function(t,e){if(t=Number(t),e=Number(e),0===t||0===e)return 28;const{HEAPU8:n,view:r}=J(this),i=X.get(this).args;for(let s=0;s<i.length;++s){const o=i[s];r.setInt32(t,e,!0),t+=4;const a=st.encode(o+"\0");n.set(a,e),e+=a.length}return 0})),this.args_sizes_get=nt(this,"args_sizes_get",(function(t,e){if(t=Number(t),e=Number(e),0===t||0===e)return 28;const{view:n}=J(this),r=X.get(this).args;return n.setUint32(t,r.length,!0),n.setUint32(e,st.encode(r.join("\0")+"\0").length,!0),0})),this.environ_get=nt(this,"environ_get",(function(t,e){if(t=Number(t),e=Number(e),0===t||0===e)return 28;const{HEAPU8:n,view:r}=J(this),i=X.get(this).env;for(let s=0;s<i.length;++s){const o=i[s];r.setInt32(t,e,!0),t+=4;const a=st.encode(o+"\0");n.set(a,e),e+=a.length}return 0})),this.environ_sizes_get=nt(this,"environ_sizes_get",(function(t,e){if(t=Number(t),e=Number(e),0===t||0===e)return 28;const{view:n}=J(this),r=X.get(this);return n.setUint32(t,r.env.length,!0),n.setUint32(e,st.encode(r.env.join("\0")+"\0").length,!0),0})),this.clock_res_get=nt(this,"clock_res_get",(function(t,e){if(0===(e=Number(e)))return 28;const{view:n}=J(this);switch(t){case 0:return n.setBigUint64(e,BigInt(1e6),!0),0;case 1:case 2:case 3:return n.setBigUint64(e,BigInt(1e3),!0),0;default:return 28}})),this.clock_time_get=nt(this,"clock_time_get",(function(t,e,n){if(0===(n=Number(n)))return 28;const{view:r}=J(this);switch(t){case 0:return r.setBigUint64(n,BigInt(Date.now())*BigInt(1e6),!0),0;case 1:case 2:case 3:{const t=performance.now(),e=Math.trunc(t),i=Math.floor(1e3*(t-e)),s=BigInt(e)*BigInt(1e9)+BigInt(i)*BigInt(1e6);return r.setBigUint64(n,s,!0),0}default:return 28}})),this.fd_advise=nt(this,"fd_advise",(function(t,e,n,r){return 52})),this.fd_fdstat_get=nt(this,"fd_fdstat_get",(function(t,e){if(0===(e=Number(e)))return 28;const n=X.get(this).fds.get(t,BigInt(0),BigInt(0)),{view:r}=J(this);return r.setUint16(e,n.type,!0),r.setUint16(e+2,0,!0),r.setBigUint64(e+8,n.rightsBase,!0),r.setBigUint64(e+16,n.rightsInheriting,!0),0})),this.fd_fdstat_set_flags=nt(this,"fd_fdstat_set_flags",(function(t,e){return 52})),this.fd_fdstat_set_rights=nt(this,"fd_fdstat_set_rights",(function(t,e,n){const r=X.get(this).fds.get(t,BigInt(0),BigInt(0));return(e|r.rightsBase)>r.rightsBase||(n|r.rightsInheriting)>r.rightsInheriting?76:(r.rightsBase=e,r.rightsInheriting=n,0)})),this.fd_prestat_get=nt(this,"fd_prestat_get",(function(t,e){if(0===(e=Number(e)))return 28;const n=X.get(this);let r;try{r=n.fds.get(t,BigInt(0),BigInt(0))}catch(t){if(t instanceof I)return t.errno;throw t}if(1!==r.preopen)return 28;const{view:i}=J(this);return i.setUint32(e,0,!0),i.setUint32(e+4,st.encode(r.path).length+1,!0),0})),this.fd_prestat_dir_name=nt(this,"fd_prestat_dir_name",(function(t,e,n){if(e=Number(e),n=Number(n),0===e)return 28;const r=X.get(this).fds.get(t,BigInt(0),BigInt(0));if(1!==r.preopen)return 8;const i=st.encode(r.path+"\0");if(i.length>n)return 42;const{HEAPU8:s}=J(this);return s.set(i,e),0})),this.fd_seek=nt(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=X.get(this).fds.get(t,p.FD_SEEK,BigInt(0)).seek(e,n),{view:s}=J(this);return s.setBigUint64(r,i,!0),0})),this.fd_tell=nt(this,"fd_tell",(function(t,e){const n=X.get(this).fds.get(t,p.FD_TELL,BigInt(0)),r=BigInt(n.pos),{view:i}=J(this);return i.setBigUint64(Number(e),r,!0),0})),this.poll_oneoff=nt(this,"poll_oneoff",(function(t,e,n,r){return 52})),this.proc_exit=nt(this,"proc_exit",(function(t){return 0})),this.proc_raise=nt(this,"proc_raise",(function(t){return 52})),this.sched_yield=nt(this,"sched_yield",(function(){return 0})),this.random_get="undefined"!=typeof crypto&&"function"==typeof crypto.getRandomValues?nt(this,"random_get",(function(t,e){if(0===(t=Number(t)))return 28;e=Number(e);const{HEAPU8:n}=J(this);let r;const i=65536;for(r=0;r+i<e;r+=i)crypto.getRandomValues(n.subarray(t+r,t+r+i));return crypto.getRandomValues(n.subarray(t+r,t+e)),0})):nt(this,"random_get",(function(t,e){if(0===(t=Number(t)))return 28;e=Number(e);const{view:n}=J(this);for(let r=t;r<t+e;++r)n.setUint8(r,Math.floor(256*Math.random()));return 0})),this.sock_recv=nt(this,"sock_recv",(function(){return 58})),this.sock_send=nt(this,"sock_send",(function(){return 58})),this.sock_shutdown=nt(this,"sock_shutdown",(function(){return 58})),X.set(this,{fds:r,args:e,env:n}),s&&Q.set(this,s);const a=this;function u(t,e,n,r,s){a[t]=i?o?o.wrapImportFunction(nt(a,t,n)):$(nt(a,t,n),r,s):nt(a,t,e)}function c(t,e,n,r){const i=X.get(this).fds.get(t,p.FD_FILESTAT_SET_TIMES,BigInt(0));return 2==(2&r)&&(e=BigInt(1e6*Date.now())),8==(8&r)&&(n=BigInt(1e6*Date.now())),{fileDescriptor:i,atim:e,mtim:n}}function f(t,e,n,r){const i=(e&(p.FD_READ|p.FD_READDIR))!==BigInt(0),s=(e&(p.FD_DATASYNC|p.FD_WRITE|p.FD_ALLOCATE|p.FD_FILESTAT_SET_SIZE))!==BigInt(0);let o=s?i?2:1:0,a=p.PATH_OPEN,u=e|n;return 0!=(1&t)&&(o|=64,a|=p.PATH_CREATE_FILE),0!=(2&t)&&(o|=65536),0!=(4&t)&&(o|=128),0!=(8&t)&&(o|=512,a|=p.PATH_FILESTAT_SET_SIZE),0!=(1&r)&&(o|=1024),0!=(2&r)&&(u|=p.FD_DATASYNC),0!=(4&r)&&(o|=2048),0!=(8&r)&&(o|=1052672,u|=p.FD_SYNC),0!=(16&r)&&(o|=1052672,u|=p.FD_SYNC),s&&0==(1536&o)&&(u|=p.FD_SEEK),{flags:o,needed_base:a,needed_inheriting:u}}u("fd_allocate",(function(t,e,n){const r=X.get(this),i=tt(this),s=r.fds.get(t,p.FD_ALLOCATE,BigInt(0));return i.fstatSync(s.fd,{bigint:!0}).size<e+n&&i.ftruncateSync(s.fd,Number(e+n)),0}),(async function(t,e,n){const r=X.get(this).fds.get(t,p.FD_ALLOCATE,BigInt(0)).fd;return(await r.stat({bigint:!0})).size<e+n&&await r.truncate(Number(e+n)),0}),["i32","i64","f64"],["i32"]),u("fd_close",(function(t){const e=X.get(this),n=e.fds.get(t,BigInt(0),BigInt(0));return tt(this).closeSync(n.fd),e.fds.remove(t),0}),(async function(t){const e=X.get(this),n=e.fds.get(t,BigInt(0),BigInt(0));return await n.fd.close(),e.fds.remove(t),0}),["i32"],["i32"]),u("fd_datasync",(function(t){const e=X.get(this).fds.get(t,p.FD_DATASYNC,BigInt(0));return tt(this).fdatasyncSync(e.fd),0}),(async function(t){const e=X.get(this).fds.get(t,p.FD_DATASYNC,BigInt(0));return await e.fd.datasync(),0}),["i32"],["i32"]),u("fd_filestat_get",(function(t,e){if(0===(e=Number(e)))return 28;const n=X.get(this).fds.get(t,p.FD_FILESTAT_GET,BigInt(0)),r=tt(this).fstatSync(n.fd,{bigint:!0}),{view:i}=J(this);return k(i,e,r),0}),(async function(t,e){if(0===(e=Number(e)))return 28;const n=X.get(this).fds.get(t,p.FD_FILESTAT_GET,BigInt(0)).fd,r=await n.stat({bigint:!0}),{view:i}=J(this);return k(i,e,r),0}),["i32","i32"],["i32"]),u("fd_filestat_set_size",(function(t,e){const n=X.get(this).fds.get(t,p.FD_FILESTAT_SET_SIZE,BigInt(0));return tt(this).ftruncateSync(n.fd,Number(e)),0}),(async function(t,e){const n=X.get(this).fds.get(t,p.FD_FILESTAT_SET_SIZE,BigInt(0)).fd;return await n.truncate(Number(e)),0}),["i32","i64"],["i32"]),u("fd_filestat_set_times",(function(t,e,n,r){const{fileDescriptor:i,atim:s,mtim:o}=c.call(this,t,e,n,r);return tt(this).futimesSync(i.fd,Number(s),Number(o)),0}),(async function(t,e,n,r){const{fileDescriptor:i,atim:s,mtim:o}=c.call(this,t,e,n,r),a=i.fd;return await a.utimes(Number(s),Number(o)),0}),["i32","i64","i64","i32"],["i32"]),u("fd_pread",(function(t,e,n,r,i){if(e=Number(e),i=Number(i),0===e||0===i)return 28;const{HEAPU8:s,view:o}=J(this),a=X.get(this).fds.get(t,p.FD_READ|p.FD_SEEK,BigInt(0));let u=0;const c=Array.from({length:Number(n)},((t,n)=>{const r=e+8*n,i=o.getInt32(r,!0),a=o.getUint32(r+4,!0);return u+=a,s.subarray(i,i+a)}));let f=0;const h=new Uint8Array(u);h._isBuffer=!0;const d=tt(this).readSync(a.fd,h,0,h.length,Number(r));return f=h?Z(c,h.subarray(0,d)):0,o.setUint32(i,f,!0),0}),(async function(t,e,n,r,i){if(e=Number(e),i=Number(i),0===e||0===i)return 28;const{HEAPU8:s,view:o}=J(this),a=X.get(this).fds.get(t,p.FD_READ|p.FD_SEEK,BigInt(0));let u=0;const c=Array.from({length:Number(n)},((t,n)=>{const r=e+8*n,i=o.getInt32(r,!0),a=o.getUint32(r+4,!0);return u+=a,s.subarray(i,i+a)}));let f=0;const h=new Uint8Array(u);h._isBuffer=!0;const{bytesRead:d}=await a.fd.read(h,0,h.length,Number(r));return f=h?Z(c,h.subarray(0,d)):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||0===i)return 28;const{HEAPU8:s,view:o}=J(this),a=X.get(this).fds.get(t,p.FD_WRITE|p.FD_SEEK,BigInt(0)),u=L(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)}))),c=tt(this).writeSync(a.fd,u,0,u.length,Number(r));return o.setUint32(i,c,!0),0}),(async function(t,e,n,r,i){if(e=Number(e),i=Number(i),0===e||0===i)return 28;const{HEAPU8:s,view:o}=J(this),a=X.get(this).fds.get(t,p.FD_WRITE|p.FD_SEEK,BigInt(0)),u=L(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:c}=await a.fd.write(u,0,u.length,Number(r));return o.setUint32(i,c,!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||0===r)return 28;const{HEAPU8:i,view:s}=J(this),o=X.get(this).fds.get(t,p.FD_READ,BigInt(0));let a=0;const u=Array.from({length:Number(n)},((t,n)=>{const r=e+8*n,o=s.getInt32(r,!0),u=s.getUint32(r+4,!0);return a+=u,i.subarray(o,o+u)}));let c,f=0;if(0===t){if("undefined"==typeof window||"function"!=typeof window.prompt)return 58;c=at(),f=c?Z(u,c):0}else{c=new Uint8Array(a),c._isBuffer=!0;const t=tt(this).readSync(o.fd,c,0,c.length,Number(o.pos));f=c?Z(u,c.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||0===r)return 28;const{HEAPU8:i,view:s}=J(this),o=X.get(this).fds.get(t,p.FD_READ,BigInt(0));let a=0;const u=Array.from({length:Number(n)},((t,n)=>{const r=e+8*n,o=s.getInt32(r,!0),u=s.getUint32(r+4,!0);return a+=u,i.subarray(o,o+u)}));let c,f=0;if(0===t){if("undefined"==typeof window||"function"!=typeof window.prompt)return 58;c=at(),f=c?Z(u,c):0}else{c=new Uint8Array(a),c._isBuffer=!0;const{bytesRead:t}=await o.fd.read(c,0,c.length,Number(o.pos));f=c?Z(u,c.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=X.get(this).fds.get(t,p.FD_READDIR,BigInt(0)),o=tt(this),a=o.readdirSync(s.realPath,{withFileTypes:!0}),{HEAPU8:u,view:c}=J(this);let f=0;for(let t=Number(r);t<a.length;t++){const r=st.encode(a[t].name),i=o.statSync(y(s.realPath,a[t].name),{bigint:!0}),c=new Uint8Array(24+r.byteLength),h=new DataView(c.buffer);let d;h.setBigUint64(0,BigInt(t+1),!0),h.setBigUint64(8,BigInt(i.ino?i.ino:0),!0),h.setUint32(16,r.byteLength,!0),d=a[t].isFile()?4:a[t].isDirectory()?3:a[t].isSymbolicLink()?7:a[t].isCharacterDevice()?2:a[t].isBlockDevice()?1:a[t].isSocket()?6:0,h.setUint8(20,d),c.set(r,24);const g=c.slice(0,Math.min(c.length,n-f));u.set(g,e+f),f+=g.byteLength}return c.setUint32(i,f,!0),0}),(async function(t,e,n,r,i){if(e=Number(e),n=Number(n),i=Number(i),0===e||0===i)return 0;const s=X.get(this).fds.get(t,p.FD_READDIR,BigInt(0)),o=tt(this),a=await o.promises.readdir(s.realPath,{withFileTypes:!0}),{HEAPU8:u,view:c}=J(this);let f=0;for(let t=Number(r);t<a.length;t++){const r=st.encode(a[t].name),i=await o.promises.stat(y(s.realPath,a[t].name),{bigint:!0}),c=new Uint8Array(24+r.byteLength),h=new DataView(c.buffer);let d;h.setBigUint64(0,BigInt(t+1),!0),h.setBigUint64(8,BigInt(i.ino?i.ino:0),!0),h.setUint32(16,r.byteLength,!0),d=a[t].isFile()?4:a[t].isDirectory()?3:a[t].isSymbolicLink()?7:a[t].isCharacterDevice()?2:a[t].isBlockDevice()?1:a[t].isSocket()?6:0,h.setUint8(20,d),c.set(r,24);const g=c.slice(0,Math.min(c.length,n-f));u.set(g,e+f),f+=g.byteLength}return c.setUint32(i,f,!0),0}),["i32","i32","i32","i64","i32"],["i32"]),u("fd_renumber",(function(t,e){return X.get(this).fds.renumber(e,t),0}),(async function(t,e){const n=X.get(this);return await n.fds.renumber(e,t),0}),["i32","i32"],["i32"]),u("fd_sync",(function(t){const e=X.get(this).fds.get(t,p.FD_SYNC,BigInt(0));return tt(this).fsyncSync(e.fd),0}),(async function(t){const e=X.get(this).fds.get(t,p.FD_SYNC,BigInt(0));return await e.fd.sync(),0}),["i32"],["i32"]),u("fd_write",(function(t,e,n,r){if(e=Number(e),r=Number(r),0===e||0===r)return 28;const{HEAPU8:i,view:s}=J(this),o=X.get(this).fds.get(t,p.FD_WRITE,BigInt(0)),a=L(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 u;if(1===t||2===t)u=o.write(a);else{u=tt(this).writeSync(o.fd,a,0,a.length,Number(o.pos)),o.pos+=BigInt(u)}return s.setUint32(r,u,!0),0}),(async function(t,e,n,r){if(e=Number(e),r=Number(r),0===e||0===r)return 28;const{HEAPU8:i,view:s}=J(this),o=X.get(this).fds.get(t,p.FD_WRITE,BigInt(0)),a=L(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 u;return 1===t||2===t?u=o.write(a):(u=await(await o.fd.write(a,0,a.length,Number(o.pos))).bytesWritten,o.pos+=BigInt(u)),s.setUint32(r,u,!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}=J(this),i=X.get(this).fds.get(t,p.PATH_CREATE_DIRECTORY,BigInt(0));let s=ot.decode(r.subarray(e,e+n));s=y(i.realPath,s);return tt(this).mkdirSync(s),0}),(async function(t,e,n){if(e=Number(e),n=Number(n),0===e)return 28;const{HEAPU8:r}=J(this),i=X.get(this).fds.get(t,p.PATH_CREATE_DIRECTORY,BigInt(0));let s=ot.decode(r.subarray(e,e+n));s=y(i.realPath,s);const o=tt(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}=J(this),a=X.get(this).fds.get(t,p.PATH_FILESTAT_GET,BigInt(0));let u=ot.decode(s.subarray(n,n+r));const c=tt(this);let f;return u=y(a.realPath,u),f=1==(1&e)?c.statSync(u,{bigint:!0}):c.lstatSync(u,{bigint:!0}),k(o,i,f),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}=J(this),a=X.get(this).fds.get(t,p.PATH_FILESTAT_GET,BigInt(0));let u=ot.decode(s.subarray(n,n+r));const c=tt(this);let f;return u=y(a.realPath,u),f=1==(1&e)?await c.promises.stat(u,{bigint:!0}):await c.promises.lstat(u,{bigint:!0}),k(o,i,f),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;if(-16&o)return 28;const{HEAPU8:a}=J(this),u=X.get(this).fds.get(t,p.PATH_FILESTAT_SET_TIMES,BigInt(0)),c=tt(this),f=rt(c,u,ot.decode(a.subarray(n,n+r)),e);return 2==(2&o)&&(i=BigInt(1e6*Date.now())),8==(8&o)&&(s=BigInt(1e6*Date.now())),c.utimesSync(f,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;if(-16&o)return 28;const{HEAPU8:a}=J(this),u=X.get(this).fds.get(t,p.PATH_FILESTAT_SET_TIMES,BigInt(0)),c=tt(this),f=await it(c,u,ot.decode(a.subarray(n,n+r)),e);return 2==(2&o)&&(i=BigInt(1e6*Date.now())),8==(8&o)&&(s=BigInt(1e6*Date.now())),await c.promises.utimes(f,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 a=X.get(this);let u,c;t===i?u=c=a.fds.get(t,p.PATH_LINK_SOURCE|p.PATH_LINK_TARGET,BigInt(0)):(u=a.fds.get(t,p.PATH_LINK_SOURCE,BigInt(0)),c=a.fds.get(i,p.PATH_LINK_TARGET,BigInt(0)));const{HEAPU8:f}=J(this),h=tt(this),d=rt(h,u,ot.decode(f.subarray(n,n+r)),e),g=y(c.realPath,ot.decode(f.subarray(s,s+o)));return h.linkSync(d,g),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 a=X.get(this);let u,c;t===i?u=c=a.fds.get(t,p.PATH_LINK_SOURCE|p.PATH_LINK_TARGET,BigInt(0)):(u=a.fds.get(t,p.PATH_LINK_SOURCE,BigInt(0)),c=a.fds.get(i,p.PATH_LINK_TARGET,BigInt(0)));const{HEAPU8:f}=J(this),h=tt(this),d=await it(h,u,ot.decode(f.subarray(n,n+r)),e),g=y(c.realPath,ot.decode(f.subarray(s,s+o)));return await h.promises.link(d,g),0}),["i32","i32","i32","i32","i32","i32","i32"],["i32"]),u("path_open",(function(t,e,n,r,i,s,o,a,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:c,needed_base:h,needed_inheriting:d}=f(i,s,o,a),g=X.get(this),l=g.fds.get(t,h,d),_=J(this),E=_.HEAPU8,y=ot.decode(E.subarray(n,n+r)),p=tt(this),I=rt(p,l,y,e),b=p.openSync(I,c,438),m=g.fds.getFileTypeByFd(b);if(0!=(2&i)&&3!==m)return 54;const{base:A,inheriting:T}=U(g.fds.stdio,b,c,m),w=g.fds.insert(b,I,I,m,s&A,o&T,0),N=p.fstatSync(b,{bigint:!0});N.isFile()&&(w.size=N.size,0!=(1024&c)&&(w.pos=N.size));return _.view.setInt32(u,w.id,!0),0}),(async function(t,e,n,r,i,s,o,a,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:c,needed_base:h,needed_inheriting:d}=f(i,s,o,a),g=X.get(this),l=g.fds.get(t,h,d),_=J(this),E=_.HEAPU8,y=ot.decode(E.subarray(n,n+r)),p=tt(this),I=await it(p,l,y,e),b=await p.promises.open(I,c,438),m=await g.fds.getFileTypeByFd(b);if(0!=(2&i)&&3!==m)return 54;const{base:A,inheriting:T}=U(g.fds.stdio,b.fd,c,m),w=g.fds.insert(b,I,I,m,s&A,o&T,0),N=await b.stat({bigint:!0});N.isFile()&&(w.size=N.size,0!=(1024&c)&&(w.pos=N.size));return _.view.setInt32(u,w.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:a}=J(this),u=X.get(this).fds.get(t,p.PATH_READLINK,BigInt(0));let c=ot.decode(o.subarray(e,e+n));c=y(u.realPath,c);const f=tt(this).readlinkSync(c),h=st.encode(f),d=Math.min(h.length,i);return d>=i?42:(o.set(h.subarray(0,d),r),o[r+d]=0,a.setUint32(s,d+1,!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:a}=J(this),u=X.get(this).fds.get(t,p.PATH_READLINK,BigInt(0));let c=ot.decode(o.subarray(e,e+n));c=y(u.realPath,c);const f=tt(this),h=await f.promises.readlink(c),d=st.encode(h),g=Math.min(d.length,i);return g>=i?42:(o.set(d.subarray(0,g),r),o[r+g]=0,a.setUint32(s,g+1,!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}=J(this),i=X.get(this).fds.get(t,p.PATH_REMOVE_DIRECTORY,BigInt(0));let s=ot.decode(r.subarray(e,e+n));s=y(i.realPath,s);return tt(this).rmdirSync(s),0}),(async function(t,e,n){if(e=Number(e),n=Number(n),0===e)return 28;const{HEAPU8:r}=J(this),i=X.get(this).fds.get(t,p.PATH_REMOVE_DIRECTORY,BigInt(0));let s=ot.decode(r.subarray(e,e+n));s=y(i.realPath,s);const o=tt(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=X.get(this);let a,u;t===r?a=u=o.fds.get(t,p.PATH_RENAME_SOURCE|p.PATH_RENAME_TARGET,BigInt(0)):(a=o.fds.get(t,p.PATH_RENAME_SOURCE,BigInt(0)),u=o.fds.get(r,p.PATH_RENAME_TARGET,BigInt(0)));const{HEAPU8:c}=J(this),f=y(a.realPath,ot.decode(c.subarray(e,e+n))),h=y(u.realPath,ot.decode(c.subarray(i,i+s)));return tt(this).renameSync(f,h),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=X.get(this);let a,u;t===r?a=u=o.fds.get(t,p.PATH_RENAME_SOURCE|p.PATH_RENAME_TARGET,BigInt(0)):(a=o.fds.get(t,p.PATH_RENAME_SOURCE,BigInt(0)),u=o.fds.get(r,p.PATH_RENAME_TARGET,BigInt(0)));const{HEAPU8:c}=J(this),f=y(a.realPath,ot.decode(c.subarray(e,e+n))),h=y(u.realPath,ot.decode(c.subarray(i,i+s))),d=tt(this);return await d.promises.rename(f,h),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}=J(this),o=X.get(this).fds.get(n,p.PATH_SYMLINK,BigInt(0)),a=ot.decode(s.subarray(t,t+e));let u=ot.decode(s.subarray(r,r+i));u=y(o.realPath,u);return tt(this).symlinkSync(a,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}=J(this),o=X.get(this).fds.get(n,p.PATH_SYMLINK,BigInt(0)),a=ot.decode(s.subarray(t,t+e));let u=ot.decode(s.subarray(r,r+i));u=y(o.realPath,u);const c=tt(this);return await c.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:r}=J(this),i=X.get(this).fds.get(t,p.PATH_UNLINK_FILE,BigInt(0));let s=ot.decode(r.subarray(e,e+n));s=y(i.realPath,s);return tt(this).unlinkSync(s),0}),(async function(t,e,n){if(e=Number(e),n=Number(n),0===e)return 28;const{HEAPU8:r}=J(this),i=X.get(this).fds.get(t,p.PATH_UNLINK_FILE,BigInt(0));let s=ot.decode(r.subarray(e,e+n));s=y(i.realPath,s);const o=tt(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');q.set(a,G(e))}}static createSync(t,e,n,r,i,s,o){const a=new M({size:3,in:r[0],out:r[1],err:r[2],fs:i,print:s,printErr:o}),u=new ut(t,e,a,!1,i);if(n.length>0)for(let t=0;t<n.length;++t){const e=i.realpathSync(n[t].realPath,"utf8"),r=i.openSync(e,"r",438);a.insertPreopen(r,n[t].mappedPath,e)}return u}static async createAsync(t,e,n,r,i,s,o,a){const u=new K({size:3,in:r[0],out:r[1],err:r[2],print:s,printErr:o}),c=new ut(t,e,u,!0,i,a);if(n.length>0)for(let t=0;t<n.length;++t){const e=n[t],r=await i.promises.realpath(e.realPath),s=await i.promises.open(r,"r",438);await u.insertPreopen(s,e.mappedPath,r)}return c}}const ct=Object.freeze(Object.create(null)),ft=Symbol("kExitCode"),ht=Symbol("kSetMemory"),dt=Symbol("kStarted"),gt=Symbol("kInstance");function lt(t,n){e(n,"instance"),e(n.exports,"instance.exports"),t[gt]=n,t[ht](n.exports.memory)}function _t(t){var n;e(t,"options"),void 0!==t.args&&function(t,e){if(!Array.isArray(t))throw new TypeError(`${e} must be an array. Received ${null===t?"null":typeof t}`)}(t.args,"options.args");const i=(null!==(n=t.args)&&void 0!==n?n:[]).map(String),s=[];void 0!==t.env&&(e(t.env,"options.env"),Object.entries(t.env).forEach((({0:t,1:e})=>{void 0!==e&&s.push(`${t}=${e}`)})));const o=[];if(void 0!==t.preopens&&(e(t.preopens,"options.preopens"),Object.entries(t.preopens).forEach((({0:t,1:e})=>o.push({mappedPath:String(t),realPath:String(e)})))),o.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:i,env:s,preopens:o,stdio:[0,1,2]}}class Et{constructor(t,e){this[ht]=t,this.wasiImport=e,this[dt]=!1,this[ft]=0,this[gt]=void 0}static createSync(t=ct){const{args:e,env:n,preopens:r,stdio:i}=_t(t),s=ut.createSync(e,n,r,i,t.fs,t.print,t.printErr),o=s._setMemory;delete s._setMemory;const a=new Et(o,s);return t.returnOnExit&&(s.proc_exit=yt.bind(a)),a}static async createAsync(t=ct){const{args:n,env:i,preopens:s,stdio:o}=_t(t);void 0!==t.asyncify&&(e(t.asyncify,"options.asyncify"),r(t.asyncify.wrapImportFunction,"options.asyncify.wrapImportFunction"));const a=await ut.createAsync(n,i,s,o,t.fs,t.print,t.printErr,t.asyncify),u=a._setMemory;delete a._setMemory;const c=new Et(u,a);return t.returnOnExit&&(a.proc_exit=yt.bind(c)),c}start(t){if(this[dt])throw new Error("WASI instance has already started");this[dt]=!0,lt(this,t);const{_start:e,_initialize:n}=this[gt].exports;let s;r(e,"instance.exports._start"),i(n,"instance.exports._initialize");try{s=e()}catch(t){if(t!==ft)throw t}return s instanceof Promise?s.then((()=>this[ft]),(t=>{if(t!==ft)throw t;return this[ft]})):this[ft]}initialize(t){if(this[dt])throw new Error("WASI instance has already started");this[dt]=!0,lt(this,t);const{_start:e,_initialize:n}=this[gt].exports;if(i(e,"instance.exports._start"),void 0!==n)return r(n,"instance.exports._initialize"),n()}}function yt(t){throw this[ft]=t,ft}export{c as Asyncify,W as Memory,Et as WASI,z as WebAssemblyMemory,g as asyncifyLoad,_ as asyncifyLoadSync,G as extendMemory,d as load,l as loadSync,j as wrapAsyncExport,$ as wrapAsyncImport,V as wrapExports};
1
+ 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}const a=["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 c{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<a.length;++t)if("function"!=typeof o[a[t]])throw new TypeError("Invalid asyncify wasm");let c;const f=Boolean(r.wasm64);c=r.tryAllocate?!0===r.tryAllocate?u(n,f,4096,"malloc"):u(n,f,null!==(i=r.tryAllocate.size)&&void 0!==i?i:4096,null!==(s=r.tryAllocate.name)&&void 0!==s?s:"malloc"):{wasm64:f,dataPtr:16,start:f?32:24,end:1024},this.dataPtr=c.dataPtr,f?new BigInt64Array(e.buffer,this.dataPtr).set([BigInt(c.start),BigInt(c.end)]):new Int32Array(e.buffer,this.dataPtr).set([c.start,c.end]),this.exports=this.wrapExports(o,r.wrapExports);const h=Object.create(t.Instance.prototype);return Object.defineProperty(h,"exports",{value:this.exports}),h}assertState(){if(0!==this.exports.asyncify_get_state())throw new Error("Asyncify state error")}wrapImportFunction(t){const e=this;return function(){for(;2===e.exports.asyncify_get_state();)return e.exports.asyncify_stop_rewind(),e.value;e.assertState();const n=t.apply(this,arguments);if(!s(n))return n;e.exports.asyncify_start_unwind(e.dataPtr),e.value=n}}wrapImports(t){const e={};return Object.keys(t).forEach((n=>{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!==a.indexOf(n)||"function"!=typeof t;return Array.isArray(e)&&(r=r||-1===e.indexOf(n)),r?t:this.wrapExportFunction(t)}))}}function f(t){if(t&&"object"!=typeof t)throw new TypeError("imports must be an object or undefined")}function h(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(f(n),n=null!=n?n:{},e instanceof ArrayBuffer||ArrayBuffer.isView(e))return t.instantiate(e,n);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((()=>h(e,n)))}catch(t){r=h(e,n)}}else r=h(e,n);return r}function g(t,e,n){f(n),n=null!=n?n:{};const r=new c;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 l(e,n){if(e instanceof ArrayBuffer&&!ArrayBuffer.isView(e))throw new TypeError("Invalid source");f(n),n=null!=n?n:{};const r=new t.Module(e);return{instance:new t.Instance(r,n),module:r}}function _(t,e,n){var r;f(n),n=null!=n?n:{};const i=new c,s=l(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)}}function E(t){return 47===t}function y(...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=47===s.charCodeAt(0))}return e=function(t,e,n,r){let i="",s=0,o=-1,a=0,u=0;for(let c=0;c<=t.length;++c){if(c<t.length)u=t.charCodeAt(c);else{if(r(u))break;u=47}if(r(u)){if(o===c-1||1===a);else if(2===a){if(i.length<2||2!==s||46!==i.charCodeAt(i.length-1)||46!==i.charCodeAt(i.length-2)){if(i.length>2){const t=i.indexOf(n);-1===t?(i="",s=0):(i=i.slice(0,t),s=i.length-1-i.indexOf(n)),o=c,a=0;continue}if(0!==i.length){i="",s=0,o=c,a=0;continue}}e&&(i+=i.length>0?`${n}..`:"..",s=2)}else i.length>0?i+=`${n}${t.slice(o+1,c)}`:i=t.slice(o+1,c),s=c-o-1;o=c,a=0}else 46===u&&-1!==a?++a:a=-1}return i}(e,!r,"/",E),r?`/${e}`:e.length>0?e:"."}const p={FD_DATASYNC:BigInt(1)<<BigInt(0),FD_READ:BigInt(1)<<BigInt(1),FD_SEEK:BigInt(1)<<BigInt(2),FD_FDSTAT_SET_FLAGS:BigInt(1)<<BigInt(3),FD_SYNC:BigInt(1)<<BigInt(4),FD_TELL:BigInt(1)<<BigInt(5),FD_WRITE:BigInt(1)<<BigInt(6),FD_ADVISE:BigInt(1)<<BigInt(7),FD_ALLOCATE:BigInt(1)<<BigInt(8),PATH_CREATE_DIRECTORY:BigInt(1)<<BigInt(9),PATH_CREATE_FILE:BigInt(1)<<BigInt(10),PATH_LINK_SOURCE:BigInt(1)<<BigInt(11),PATH_LINK_TARGET:BigInt(1)<<BigInt(12),PATH_OPEN:BigInt(1)<<BigInt(13),FD_READDIR:BigInt(1)<<BigInt(14),PATH_READLINK:BigInt(1)<<BigInt(15),PATH_RENAME_SOURCE:BigInt(1)<<BigInt(16),PATH_RENAME_TARGET:BigInt(1)<<BigInt(17),PATH_FILESTAT_GET:BigInt(1)<<BigInt(18),PATH_FILESTAT_SET_SIZE:BigInt(1)<<BigInt(19),PATH_FILESTAT_SET_TIMES:BigInt(1)<<BigInt(20),FD_FILESTAT_GET:BigInt(1)<<BigInt(21),FD_FILESTAT_SET_SIZE:BigInt(1)<<BigInt(22),FD_FILESTAT_SET_TIMES:BigInt(1)<<BigInt(23),PATH_SYMLINK:BigInt(1)<<BigInt(24),PATH_REMOVE_DIRECTORY:BigInt(1)<<BigInt(25),PATH_UNLINK_FILE:BigInt(1)<<BigInt(26),POLL_FD_READWRITE:BigInt(1)<<BigInt(27),SOCK_SHUTDOWN:BigInt(1)<<BigInt(28),SOCK_ACCEPT:BigInt(1)<<BigInt(29)};class I extends Error{constructor(t,e){super(t),this.errno=e}getErrorMessage(){return function(t){switch(t){case 0:return"Success";case 1:return"Argument list too long";case 2:return"Permission denied";case 3:return"Address in use";case 4:return"Address not available";case 5:return"Address family not supported by protocol";case 6:return"Resource temporarily unavailable";case 7:return"Operation already in progress";case 8:return"Bad file descriptor";case 9:return"Bad message";case 10:return"Resource busy";case 11:return"Operation canceled";case 12:return"No child process";case 13:return"Connection aborted";case 14:return"Connection refused";case 15:return"Connection reset by peer";case 16:return"Resource deadlock would occur";case 17:return"Destination address required";case 18:return"Domain error";case 19:return"Quota exceeded";case 20:return"File exists";case 21:return"Bad address";case 22:return"File too large";case 23:return"Host is unreachable";case 24:return"Identifier removed";case 25:return"Illegal byte sequence";case 26:return"Operation in progress";case 27:return"Interrupted system call";case 28:return"Invalid argument";case 29:return"I/O error";case 30:return"Socket is connected";case 31:return"Is a directory";case 32:return"Symbolic link loop";case 33:return"No file descriptors available";case 34:return"Too many links";case 35:return"Message too large";case 36:return"Multihop attempted";case 37:return"Filename too long";case 38:return"Network is down";case 39:return"Connection reset by network";case 40:return"Network unreachable";case 41:return"Too many files open in system";case 42:return"No buffer space available";case 43:return"No such device";case 44:return"No such file or directory";case 45:return"Exec format error";case 46:return"No locks available";case 47:return"Link has been severed";case 48:return"Out of memory";case 49:return"No message of the desired type";case 50:return"Protocol not available";case 51:return"No space left on device";case 52:return"Function not implemented";case 53:return"Socket not connected";case 54:return"Not a directory";case 55:return"Directory not empty";case 56:return"State not recoverable";case 57:return"Not a socket";case 58:return"Not supported";case 59:return"Not a tty";case 60:return"No such device or address";case 61:return"Value too large for data type";case 62:return"Previous owner died";case 63:return"Operation not permitted";case 64:return"Broken pipe";case 65:return"Protocol error";case 66:return"Protocol not supported";case 67:return"Protocol wrong type for socket";case 68:return"Result not representable";case 69:return"Read-only file system";case 70:return"Invalid seek";case 71:return"No such process";case 72:return"Stale file handle";case 73:return"Operation timed out";case 74:return"Text file busy";case 75:return"Cross-device link";case 76:return"Capabilities insufficient";default:return"Unknown error"}}(this.errno)}}Object.defineProperty(I.prototype,"name",{configurable:!0,writable:!0,value:"WasiError"});const b=p.FD_DATASYNC|p.FD_READ|p.FD_SEEK|p.FD_FDSTAT_SET_FLAGS|p.FD_SYNC|p.FD_TELL|p.FD_WRITE|p.FD_ADVISE|p.FD_ALLOCATE|p.PATH_CREATE_DIRECTORY|p.PATH_CREATE_FILE|p.PATH_LINK_SOURCE|p.PATH_LINK_TARGET|p.PATH_OPEN|p.FD_READDIR|p.PATH_READLINK|p.PATH_RENAME_SOURCE|p.PATH_RENAME_TARGET|p.PATH_FILESTAT_GET|p.PATH_FILESTAT_SET_SIZE|p.PATH_FILESTAT_SET_TIMES|p.FD_FILESTAT_GET|p.FD_FILESTAT_SET_TIMES|p.FD_FILESTAT_SET_SIZE|p.PATH_SYMLINK|p.PATH_UNLINK_FILE|p.PATH_REMOVE_DIRECTORY|p.POLL_FD_READWRITE|p.SOCK_SHUTDOWN,m=b,A=b,T=b,w=b,N=p.FD_DATASYNC|p.FD_READ|p.FD_SEEK|p.FD_FDSTAT_SET_FLAGS|p.FD_SYNC|p.FD_TELL|p.FD_WRITE|p.FD_ADVISE|p.FD_ALLOCATE|p.FD_FILESTAT_GET|p.FD_FILESTAT_SET_SIZE|p.FD_FILESTAT_SET_TIMES|p.POLL_FD_READWRITE,B=BigInt(0),S=p.FD_FDSTAT_SET_FLAGS|p.FD_SYNC|p.FD_ADVISE|p.PATH_CREATE_DIRECTORY|p.PATH_CREATE_FILE|p.PATH_LINK_SOURCE|p.PATH_LINK_TARGET|p.PATH_OPEN|p.FD_READDIR|p.PATH_READLINK|p.PATH_RENAME_SOURCE|p.PATH_RENAME_TARGET|p.PATH_FILESTAT_GET|p.PATH_FILESTAT_SET_SIZE|p.PATH_FILESTAT_SET_TIMES|p.FD_FILESTAT_GET|p.FD_FILESTAT_SET_TIMES|p.PATH_SYMLINK|p.PATH_UNLINK_FILE|p.PATH_REMOVE_DIRECTORY|p.POLL_FD_READWRITE,P=S|N,D=p.FD_READ|p.FD_FDSTAT_SET_FLAGS|p.FD_WRITE|p.FD_FILESTAT_GET|p.POLL_FD_READWRITE|p.SOCK_SHUTDOWN,F=b,R=p.FD_READ|p.FD_FDSTAT_SET_FLAGS|p.FD_WRITE|p.FD_FILESTAT_GET|p.POLL_FD_READWRITE,v=BigInt(0);function U(t,e,n,r){const i={base:BigInt(0),inheriting:BigInt(0)};if(0===r)throw new I("Unknown file type",28);switch(r){case 4:i.base=N,i.inheriting=B;break;case 3:i.base=S,i.inheriting=P;break;case 6:case 5:i.base=D,i.inheriting=F;break;case 2:-1!==t.indexOf(e)?(i.base=R,i.inheriting=v):(i.base=T,i.inheriting=w);break;case 1:i.base=m,i.inheriting=A;break;default:i.base=BigInt(0),i.inheriting=BigInt(0)}const s=3&n;return 0===s?i.base&=~p.FD_WRITE:1===s&&(i.base&=~p.FD_READ),i}function L(t,e){let n=0;if("number"==typeof e&&e>=0)n=e;else for(let e=0;e<t.length;e++){n+=t[e].length}let r=0;const i=new Uint8Array(n);for(let e=0;e<t.length;e++){const n=t[e];i.set(n,r),r+=n.length}return i}class H{constructor(t,e,n,r,i,s,o,a){this.id=t,this.fd=e,this.path=n,this.realPath=r,this.type=i,this.rightsBase=s,this.rightsInheriting=o,this.preopen=a,this.pos=BigInt(0),this.size=BigInt(0)}seek(t,e){if(0===e)this.pos=BigInt(t);else if(1===e)this.pos+=BigInt(t);else{if(2!==e)throw new I("Unknown whence",29);this.pos=BigInt(this.size)-BigInt(t)}return this.pos}}class O extends H{constructor(t,e,n,r,i,s,o,a,u){super(e,n,r,i,s,o,a,u),this._log=t,this._buf=null}write(t){const e=t;if(this._buf&&(t=L([this._buf,t]),this._buf=null),-1===t.indexOf(10))return this._buf=t,e.byteLength;let n,r=0,i=0;for(;-1!==(n=t.indexOf(10,r));){const e=(new TextDecoder).decode(t.subarray(i,n));this._log(e),r+=n-i+1,i=n+1}return r<t.length&&(this._buf=t.slice(r)),e.byteLength}}function C(t){return t.isBlockDevice()?1:t.isCharacterDevice()?2:t.isDirectory()?3:t.isSocket()?6:t.isFile()?4:t.isSymbolicLink()?7:0}function k(t,e,n){t.setBigUint64(e,n.dev,!0),t.setBigUint64(e+8,n.ino,!0),t.setBigUint64(e+16,BigInt(C(n)),!0),t.setBigUint64(e+24,n.nlink,!0),t.setBigUint64(e+32,n.size,!0),t.setBigUint64(e+40,n.atimeMs*BigInt(1e6),!0),t.setBigUint64(e+48,n.mtimeMs*BigInt(1e6),!0),t.setBigUint64(e+56,n.ctimeMs*BigInt(1e6),!0)}class x{constructor(t){this.used=0,this.size=t.size,this.fds=Array(t.size),this.stdio=[t.in,t.out,t.err],this.print=t.print,this.printErr=t.printErr,this.insertStdio(t.in,0,"<stdin>"),this.insertStdio(t.out,1,"<stdout>"),this.insertStdio(t.err,2,"<stderr>")}insertStdio(t,e,n){const{base:r,inheriting:i}=U(this.stdio,t,2,2),s=this.insert(t,n,n,2,r,i,0);if(s.id!==e)throw new I(`id: ${s.id} !== expected: ${e}`,8);return s}insert(t,e,n,r,i,s,o){var a,u;let c,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<this.size;++t)if(null==this.fds[t]){f=t;break}return c="<stdout>"===e?new O(null!==(a=this.print)&&void 0!==a?a:console.log,f,t,e,n,r,i,s,o):"<stderr>"===e?new O(null!==(u=this.printErr)&&void 0!==u?u:console.error,f,t,e,n,r,i,s,o):new H(f,t,e,n,r,i,s,o),this.fds[f]=c,this.used++,c}get(t,e,n){if(t>=this.size)throw new I("Invalid fd",8);const r=this.fds[t];if(!r||r.id!==t)throw new I("Bad file descriptor",8);if((~r.rightsBase&e)!==BigInt(0)||(~r.rightsInheriting&n)!==BigInt(0))throw new I("Capabilities insufficient",76);return r}remove(t){if(t>=this.size)throw new I("Invalid fd",8);const e=this.fds[t];if(!e||e.id!==t)throw new I("Bad file descriptor",8);this.fds[t]=void 0,this.used--}}class M extends x{constructor(t){super(t),this.fs=t.fs}getFileTypeByFd(t){return C(this.fs.fstatSync(t,{bigint:!0}))}insertPreopen(t,e,n){const r=this.getFileTypeByFd(t);if(3!==r)throw new I(`Preopen not dir: ["${e}", "${n}"]`,54);const i=U(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 I("Invalid fd",8);const n=this.fds[t],r=this.fds[e];if(!n||!r||n.id!==t||r.id!==e)throw new I("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 x{constructor(t){super(t)}async getFileTypeByFd(t){return C(await t.stat({bigint:!0}))}async insertPreopen(t,e,n){const r=await this.getFileTypeByFd(t);if(3!==r)throw new I(`Preopen not dir: ["${e}", "${n}"]`,54);const i=U(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 I("Invalid fd",8);const n=this.fds[t],r=this.fds[e];if(!n||!r||n.id!==t||r.id!==e)throw new I("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 z=function(){return t.Memory}();class W extends z{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 G(e){return Object.getPrototypeOf(e)===t.Memory.prototype&&Object.setPrototypeOf(e,W.prototype),e}function Y(){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-flag="--wasm-staging --experimental-wasm-stack-switching"');return e}function $(t,e,n){const r=Y();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 j(t){const e=Y();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 V(t,e){return o(t,((t,n)=>{let r="function"!=typeof t;return Array.isArray(e)&&(r=r||-1===e.indexOf(n)),r?t:j(t)}))}function Z(t,e){if(0===t.length||0===e.length)return 0;let n=0,r=e.length-n;for(let i=0;i<t.length;++i){const s=t[i];if(r<s.length)return s.set(e.subarray(n,n+r),0),n+=r,r=0,n;s.set(e.subarray(n,n+s.length),0),n+=s.length,r-=s.length}return n}const q=new WeakMap,X=new WeakMap,Q=new WeakMap;function J(t){return q.get(t)}function tt(t){const e=Q.get(t);if(!e)throw new Error("filesystem is unavailable");return e}function et(t){if(t instanceof I)return t.errno;switch(t.code){case"ENOENT":return 44;case"EBADF":return 8;case"EINVAL":return 28;case"EPERM":return 63;case"EPROTO":return 65;case"EEXIST":return 20;case"ENOTDIR":return 54;case"EMFILE":return 33;case"EACCES":return 2;case"EISDIR":return 31;case"ENOTEMPTY":return 55;case"ENOSYS":return 52}throw t}function nt(t,e,n){return function(t,e){return Object.defineProperty(e,"name",{value:t}),e}(e,(function(){let e;try{e=n.apply(t,arguments)}catch(t){return et(t)}return s(e)?e.then((t=>t),et):e}))}function rt(t,e,n,r){let i=y(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 it(t,e,n,r){let i=y(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 st=new TextEncoder,ot=new TextDecoder;function at(){const t=window.prompt();if(null===t)return new Uint8Array;return(new TextEncoder).encode(t+"\n")}class ut{constructor(e,n,r,i,s,o){this.args_get=nt(this,"args_get",(function(t,e){if(t=Number(t),e=Number(e),0===t||0===e)return 28;const{HEAPU8:n,view:r}=J(this),i=X.get(this).args;for(let s=0;s<i.length;++s){const o=i[s];r.setInt32(t,e,!0),t+=4;const a=st.encode(o+"\0");n.set(a,e),e+=a.length}return 0})),this.args_sizes_get=nt(this,"args_sizes_get",(function(t,e){if(t=Number(t),e=Number(e),0===t||0===e)return 28;const{view:n}=J(this),r=X.get(this).args;return n.setUint32(t,r.length,!0),n.setUint32(e,st.encode(r.join("\0")+"\0").length,!0),0})),this.environ_get=nt(this,"environ_get",(function(t,e){if(t=Number(t),e=Number(e),0===t||0===e)return 28;const{HEAPU8:n,view:r}=J(this),i=X.get(this).env;for(let s=0;s<i.length;++s){const o=i[s];r.setInt32(t,e,!0),t+=4;const a=st.encode(o+"\0");n.set(a,e),e+=a.length}return 0})),this.environ_sizes_get=nt(this,"environ_sizes_get",(function(t,e){if(t=Number(t),e=Number(e),0===t||0===e)return 28;const{view:n}=J(this),r=X.get(this);return n.setUint32(t,r.env.length,!0),n.setUint32(e,st.encode(r.env.join("\0")+"\0").length,!0),0})),this.clock_res_get=nt(this,"clock_res_get",(function(t,e){if(0===(e=Number(e)))return 28;const{view:n}=J(this);switch(t){case 0:return n.setBigUint64(e,BigInt(1e6),!0),0;case 1:case 2:case 3:return n.setBigUint64(e,BigInt(1e3),!0),0;default:return 28}})),this.clock_time_get=nt(this,"clock_time_get",(function(t,e,n){if(0===(n=Number(n)))return 28;const{view:r}=J(this);switch(t){case 0:return r.setBigUint64(n,BigInt(Date.now())*BigInt(1e6),!0),0;case 1:case 2:case 3:{const t=performance.now(),e=Math.trunc(t),i=Math.floor(1e3*(t-e)),s=BigInt(e)*BigInt(1e9)+BigInt(i)*BigInt(1e6);return r.setBigUint64(n,s,!0),0}default:return 28}})),this.fd_advise=nt(this,"fd_advise",(function(t,e,n,r){return 52})),this.fd_fdstat_get=nt(this,"fd_fdstat_get",(function(t,e){if(0===(e=Number(e)))return 28;const n=X.get(this).fds.get(t,BigInt(0),BigInt(0)),{view:r}=J(this);return r.setUint16(e,n.type,!0),r.setUint16(e+2,0,!0),r.setBigUint64(e+8,n.rightsBase,!0),r.setBigUint64(e+16,n.rightsInheriting,!0),0})),this.fd_fdstat_set_flags=nt(this,"fd_fdstat_set_flags",(function(t,e){return 52})),this.fd_fdstat_set_rights=nt(this,"fd_fdstat_set_rights",(function(t,e,n){const r=X.get(this).fds.get(t,BigInt(0),BigInt(0));return(e|r.rightsBase)>r.rightsBase||(n|r.rightsInheriting)>r.rightsInheriting?76:(r.rightsBase=e,r.rightsInheriting=n,0)})),this.fd_prestat_get=nt(this,"fd_prestat_get",(function(t,e){if(0===(e=Number(e)))return 28;const n=X.get(this);let r;try{r=n.fds.get(t,BigInt(0),BigInt(0))}catch(t){if(t instanceof I)return t.errno;throw t}if(1!==r.preopen)return 28;const{view:i}=J(this);return i.setUint32(e,0,!0),i.setUint32(e+4,st.encode(r.path).length+1,!0),0})),this.fd_prestat_dir_name=nt(this,"fd_prestat_dir_name",(function(t,e,n){if(e=Number(e),n=Number(n),0===e)return 28;const r=X.get(this).fds.get(t,BigInt(0),BigInt(0));if(1!==r.preopen)return 8;const i=st.encode(r.path+"\0");if(i.length>n)return 42;const{HEAPU8:s}=J(this);return s.set(i,e),0})),this.fd_seek=nt(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=X.get(this).fds.get(t,p.FD_SEEK,BigInt(0)).seek(e,n),{view:s}=J(this);return s.setBigUint64(r,i,!0),0})),this.fd_tell=nt(this,"fd_tell",(function(t,e){const n=X.get(this).fds.get(t,p.FD_TELL,BigInt(0)),r=BigInt(n.pos),{view:i}=J(this);return i.setBigUint64(Number(e),r,!0),0})),this.poll_oneoff=nt(this,"poll_oneoff",(function(t,e,n,r){return 52})),this.proc_exit=nt(this,"proc_exit",(function(t){return 0})),this.proc_raise=nt(this,"proc_raise",(function(t){return 52})),this.sched_yield=nt(this,"sched_yield",(function(){return 0})),this.random_get="undefined"!=typeof crypto&&"function"==typeof crypto.getRandomValues?nt(this,"random_get",(function(t,e){if(0===(t=Number(t)))return 28;e=Number(e);const{HEAPU8:n}=J(this);let r;const i=65536;for(r=0;r+i<e;r+=i)crypto.getRandomValues(n.subarray(t+r,t+r+i));return crypto.getRandomValues(n.subarray(t+r,t+e)),0})):nt(this,"random_get",(function(t,e){if(0===(t=Number(t)))return 28;e=Number(e);const{view:n}=J(this);for(let r=t;r<t+e;++r)n.setUint8(r,Math.floor(256*Math.random()));return 0})),this.sock_recv=nt(this,"sock_recv",(function(){return 58})),this.sock_send=nt(this,"sock_send",(function(){return 58})),this.sock_shutdown=nt(this,"sock_shutdown",(function(){return 58})),X.set(this,{fds:r,args:e,env:n}),s&&Q.set(this,s);const a=this;function u(t,e,n,r,s){a[t]=i?o?o.wrapImportFunction(nt(a,t,n)):$(nt(a,t,n),r,s):nt(a,t,e)}function c(t,e,n,r){const i=X.get(this).fds.get(t,p.FD_FILESTAT_SET_TIMES,BigInt(0));return 2==(2&r)&&(e=BigInt(1e6*Date.now())),8==(8&r)&&(n=BigInt(1e6*Date.now())),{fileDescriptor:i,atim:e,mtim:n}}function f(t,e,n,r){const i=(e&(p.FD_READ|p.FD_READDIR))!==BigInt(0),s=(e&(p.FD_DATASYNC|p.FD_WRITE|p.FD_ALLOCATE|p.FD_FILESTAT_SET_SIZE))!==BigInt(0);let o=s?i?2:1:0,a=p.PATH_OPEN,u=e|n;return 0!=(1&t)&&(o|=64,a|=p.PATH_CREATE_FILE),0!=(2&t)&&(o|=65536),0!=(4&t)&&(o|=128),0!=(8&t)&&(o|=512,a|=p.PATH_FILESTAT_SET_SIZE),0!=(1&r)&&(o|=1024),0!=(2&r)&&(u|=p.FD_DATASYNC),0!=(4&r)&&(o|=2048),0!=(8&r)&&(o|=1052672,u|=p.FD_SYNC),0!=(16&r)&&(o|=1052672,u|=p.FD_SYNC),s&&0==(1536&o)&&(u|=p.FD_SEEK),{flags:o,needed_base:a,needed_inheriting:u}}u("fd_allocate",(function(t,e,n){const r=X.get(this),i=tt(this),s=r.fds.get(t,p.FD_ALLOCATE,BigInt(0));return i.fstatSync(s.fd,{bigint:!0}).size<e+n&&i.ftruncateSync(s.fd,Number(e+n)),0}),(async function(t,e,n){const r=X.get(this).fds.get(t,p.FD_ALLOCATE,BigInt(0)).fd;return(await r.stat({bigint:!0})).size<e+n&&await r.truncate(Number(e+n)),0}),["i32","i64","f64"],["i32"]),u("fd_close",(function(t){const e=X.get(this),n=e.fds.get(t,BigInt(0),BigInt(0));return tt(this).closeSync(n.fd),e.fds.remove(t),0}),(async function(t){const e=X.get(this),n=e.fds.get(t,BigInt(0),BigInt(0));return await n.fd.close(),e.fds.remove(t),0}),["i32"],["i32"]),u("fd_datasync",(function(t){const e=X.get(this).fds.get(t,p.FD_DATASYNC,BigInt(0));return tt(this).fdatasyncSync(e.fd),0}),(async function(t){const e=X.get(this).fds.get(t,p.FD_DATASYNC,BigInt(0));return await e.fd.datasync(),0}),["i32"],["i32"]),u("fd_filestat_get",(function(t,e){if(0===(e=Number(e)))return 28;const n=X.get(this).fds.get(t,p.FD_FILESTAT_GET,BigInt(0)),r=tt(this).fstatSync(n.fd,{bigint:!0}),{view:i}=J(this);return k(i,e,r),0}),(async function(t,e){if(0===(e=Number(e)))return 28;const n=X.get(this).fds.get(t,p.FD_FILESTAT_GET,BigInt(0)).fd,r=await n.stat({bigint:!0}),{view:i}=J(this);return k(i,e,r),0}),["i32","i32"],["i32"]),u("fd_filestat_set_size",(function(t,e){const n=X.get(this).fds.get(t,p.FD_FILESTAT_SET_SIZE,BigInt(0));return tt(this).ftruncateSync(n.fd,Number(e)),0}),(async function(t,e){const n=X.get(this).fds.get(t,p.FD_FILESTAT_SET_SIZE,BigInt(0)).fd;return await n.truncate(Number(e)),0}),["i32","i64"],["i32"]),u("fd_filestat_set_times",(function(t,e,n,r){const{fileDescriptor:i,atim:s,mtim:o}=c.call(this,t,e,n,r);return tt(this).futimesSync(i.fd,Number(s),Number(o)),0}),(async function(t,e,n,r){const{fileDescriptor:i,atim:s,mtim:o}=c.call(this,t,e,n,r),a=i.fd;return await a.utimes(Number(s),Number(o)),0}),["i32","i64","i64","i32"],["i32"]),u("fd_pread",(function(t,e,n,r,i){if(e=Number(e),i=Number(i),0===e||0===i)return 28;const{HEAPU8:s,view:o}=J(this),a=X.get(this).fds.get(t,p.FD_READ|p.FD_SEEK,BigInt(0));let u=0;const c=Array.from({length:Number(n)},((t,n)=>{const r=e+8*n,i=o.getInt32(r,!0),a=o.getUint32(r+4,!0);return u+=a,s.subarray(i,i+a)}));let f=0;const h=new Uint8Array(u);h._isBuffer=!0;const d=tt(this).readSync(a.fd,h,0,h.length,Number(r));return f=h?Z(c,h.subarray(0,d)):0,o.setUint32(i,f,!0),0}),(async function(t,e,n,r,i){if(e=Number(e),i=Number(i),0===e||0===i)return 28;const{HEAPU8:s,view:o}=J(this),a=X.get(this).fds.get(t,p.FD_READ|p.FD_SEEK,BigInt(0));let u=0;const c=Array.from({length:Number(n)},((t,n)=>{const r=e+8*n,i=o.getInt32(r,!0),a=o.getUint32(r+4,!0);return u+=a,s.subarray(i,i+a)}));let f=0;const h=new Uint8Array(u);h._isBuffer=!0;const{bytesRead:d}=await a.fd.read(h,0,h.length,Number(r));return f=h?Z(c,h.subarray(0,d)):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||0===i)return 28;const{HEAPU8:s,view:o}=J(this),a=X.get(this).fds.get(t,p.FD_WRITE|p.FD_SEEK,BigInt(0)),u=L(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)}))),c=tt(this).writeSync(a.fd,u,0,u.length,Number(r));return o.setUint32(i,c,!0),0}),(async function(t,e,n,r,i){if(e=Number(e),i=Number(i),0===e||0===i)return 28;const{HEAPU8:s,view:o}=J(this),a=X.get(this).fds.get(t,p.FD_WRITE|p.FD_SEEK,BigInt(0)),u=L(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:c}=await a.fd.write(u,0,u.length,Number(r));return o.setUint32(i,c,!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||0===r)return 28;const{HEAPU8:i,view:s}=J(this),o=X.get(this).fds.get(t,p.FD_READ,BigInt(0));let a=0;const u=Array.from({length:Number(n)},((t,n)=>{const r=e+8*n,o=s.getInt32(r,!0),u=s.getUint32(r+4,!0);return a+=u,i.subarray(o,o+u)}));let c,f=0;if(0===t){if("undefined"==typeof window||"function"!=typeof window.prompt)return 58;c=at(),f=c?Z(u,c):0}else{c=new Uint8Array(a),c._isBuffer=!0;const t=tt(this).readSync(o.fd,c,0,c.length,Number(o.pos));f=c?Z(u,c.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||0===r)return 28;const{HEAPU8:i,view:s}=J(this),o=X.get(this).fds.get(t,p.FD_READ,BigInt(0));let a=0;const u=Array.from({length:Number(n)},((t,n)=>{const r=e+8*n,o=s.getInt32(r,!0),u=s.getUint32(r+4,!0);return a+=u,i.subarray(o,o+u)}));let c,f=0;if(0===t){if("undefined"==typeof window||"function"!=typeof window.prompt)return 58;c=at(),f=c?Z(u,c):0}else{c=new Uint8Array(a),c._isBuffer=!0;const{bytesRead:t}=await o.fd.read(c,0,c.length,Number(o.pos));f=c?Z(u,c.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=X.get(this).fds.get(t,p.FD_READDIR,BigInt(0)),o=tt(this),a=o.readdirSync(s.realPath,{withFileTypes:!0}),{HEAPU8:u,view:c}=J(this);let f=0;for(let t=Number(r);t<a.length;t++){const r=st.encode(a[t].name),i=o.statSync(y(s.realPath,a[t].name),{bigint:!0}),c=new Uint8Array(24+r.byteLength),h=new DataView(c.buffer);let d;h.setBigUint64(0,BigInt(t+1),!0),h.setBigUint64(8,BigInt(i.ino?i.ino:0),!0),h.setUint32(16,r.byteLength,!0),d=a[t].isFile()?4:a[t].isDirectory()?3:a[t].isSymbolicLink()?7:a[t].isCharacterDevice()?2:a[t].isBlockDevice()?1:a[t].isSocket()?6:0,h.setUint8(20,d),c.set(r,24);const g=c.slice(0,Math.min(c.length,n-f));u.set(g,e+f),f+=g.byteLength}return c.setUint32(i,f,!0),0}),(async function(t,e,n,r,i){if(e=Number(e),n=Number(n),i=Number(i),0===e||0===i)return 0;const s=X.get(this).fds.get(t,p.FD_READDIR,BigInt(0)),o=tt(this),a=await o.promises.readdir(s.realPath,{withFileTypes:!0}),{HEAPU8:u,view:c}=J(this);let f=0;for(let t=Number(r);t<a.length;t++){const r=st.encode(a[t].name),i=await o.promises.stat(y(s.realPath,a[t].name),{bigint:!0}),c=new Uint8Array(24+r.byteLength),h=new DataView(c.buffer);let d;h.setBigUint64(0,BigInt(t+1),!0),h.setBigUint64(8,BigInt(i.ino?i.ino:0),!0),h.setUint32(16,r.byteLength,!0),d=a[t].isFile()?4:a[t].isDirectory()?3:a[t].isSymbolicLink()?7:a[t].isCharacterDevice()?2:a[t].isBlockDevice()?1:a[t].isSocket()?6:0,h.setUint8(20,d),c.set(r,24);const g=c.slice(0,Math.min(c.length,n-f));u.set(g,e+f),f+=g.byteLength}return c.setUint32(i,f,!0),0}),["i32","i32","i32","i64","i32"],["i32"]),u("fd_renumber",(function(t,e){return X.get(this).fds.renumber(e,t),0}),(async function(t,e){const n=X.get(this);return await n.fds.renumber(e,t),0}),["i32","i32"],["i32"]),u("fd_sync",(function(t){const e=X.get(this).fds.get(t,p.FD_SYNC,BigInt(0));return tt(this).fsyncSync(e.fd),0}),(async function(t){const e=X.get(this).fds.get(t,p.FD_SYNC,BigInt(0));return await e.fd.sync(),0}),["i32"],["i32"]),u("fd_write",(function(t,e,n,r){if(e=Number(e),r=Number(r),0===e||0===r)return 28;const{HEAPU8:i,view:s}=J(this),o=X.get(this).fds.get(t,p.FD_WRITE,BigInt(0)),a=L(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 u;if(1===t||2===t)u=o.write(a);else{u=tt(this).writeSync(o.fd,a,0,a.length,Number(o.pos)),o.pos+=BigInt(u)}return s.setUint32(r,u,!0),0}),(async function(t,e,n,r){if(e=Number(e),r=Number(r),0===e||0===r)return 28;const{HEAPU8:i,view:s}=J(this),o=X.get(this).fds.get(t,p.FD_WRITE,BigInt(0)),a=L(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 u;return 1===t||2===t?u=o.write(a):(u=await(await o.fd.write(a,0,a.length,Number(o.pos))).bytesWritten,o.pos+=BigInt(u)),s.setUint32(r,u,!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}=J(this),i=X.get(this).fds.get(t,p.PATH_CREATE_DIRECTORY,BigInt(0));let s=ot.decode(r.subarray(e,e+n));s=y(i.realPath,s);return tt(this).mkdirSync(s),0}),(async function(t,e,n){if(e=Number(e),n=Number(n),0===e)return 28;const{HEAPU8:r}=J(this),i=X.get(this).fds.get(t,p.PATH_CREATE_DIRECTORY,BigInt(0));let s=ot.decode(r.subarray(e,e+n));s=y(i.realPath,s);const o=tt(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}=J(this),a=X.get(this).fds.get(t,p.PATH_FILESTAT_GET,BigInt(0));let u=ot.decode(s.subarray(n,n+r));const c=tt(this);let f;return u=y(a.realPath,u),f=1==(1&e)?c.statSync(u,{bigint:!0}):c.lstatSync(u,{bigint:!0}),k(o,i,f),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}=J(this),a=X.get(this).fds.get(t,p.PATH_FILESTAT_GET,BigInt(0));let u=ot.decode(s.subarray(n,n+r));const c=tt(this);let f;return u=y(a.realPath,u),f=1==(1&e)?await c.promises.stat(u,{bigint:!0}):await c.promises.lstat(u,{bigint:!0}),k(o,i,f),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;if(-16&o)return 28;const{HEAPU8:a}=J(this),u=X.get(this).fds.get(t,p.PATH_FILESTAT_SET_TIMES,BigInt(0)),c=tt(this),f=rt(c,u,ot.decode(a.subarray(n,n+r)),e);return 2==(2&o)&&(i=BigInt(1e6*Date.now())),8==(8&o)&&(s=BigInt(1e6*Date.now())),c.utimesSync(f,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;if(-16&o)return 28;const{HEAPU8:a}=J(this),u=X.get(this).fds.get(t,p.PATH_FILESTAT_SET_TIMES,BigInt(0)),c=tt(this),f=await it(c,u,ot.decode(a.subarray(n,n+r)),e);return 2==(2&o)&&(i=BigInt(1e6*Date.now())),8==(8&o)&&(s=BigInt(1e6*Date.now())),await c.promises.utimes(f,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 a=X.get(this);let u,c;t===i?u=c=a.fds.get(t,p.PATH_LINK_SOURCE|p.PATH_LINK_TARGET,BigInt(0)):(u=a.fds.get(t,p.PATH_LINK_SOURCE,BigInt(0)),c=a.fds.get(i,p.PATH_LINK_TARGET,BigInt(0)));const{HEAPU8:f}=J(this),h=tt(this),d=rt(h,u,ot.decode(f.subarray(n,n+r)),e),g=y(c.realPath,ot.decode(f.subarray(s,s+o)));return h.linkSync(d,g),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 a=X.get(this);let u,c;t===i?u=c=a.fds.get(t,p.PATH_LINK_SOURCE|p.PATH_LINK_TARGET,BigInt(0)):(u=a.fds.get(t,p.PATH_LINK_SOURCE,BigInt(0)),c=a.fds.get(i,p.PATH_LINK_TARGET,BigInt(0)));const{HEAPU8:f}=J(this),h=tt(this),d=await it(h,u,ot.decode(f.subarray(n,n+r)),e),g=y(c.realPath,ot.decode(f.subarray(s,s+o)));return await h.promises.link(d,g),0}),["i32","i32","i32","i32","i32","i32","i32"],["i32"]),u("path_open",(function(t,e,n,r,i,s,o,a,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:c,needed_base:h,needed_inheriting:d}=f(i,s,o,a),g=X.get(this),l=g.fds.get(t,h,d),_=J(this),E=_.HEAPU8,y=ot.decode(E.subarray(n,n+r)),p=tt(this),I=rt(p,l,y,e),b=p.openSync(I,c,438),m=g.fds.getFileTypeByFd(b);if(0!=(2&i)&&3!==m)return 54;const{base:A,inheriting:T}=U(g.fds.stdio,b,c,m),w=g.fds.insert(b,I,I,m,s&A,o&T,0),N=p.fstatSync(b,{bigint:!0});N.isFile()&&(w.size=N.size,0!=(1024&c)&&(w.pos=N.size));return _.view.setInt32(u,w.id,!0),0}),(async function(t,e,n,r,i,s,o,a,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:c,needed_base:h,needed_inheriting:d}=f(i,s,o,a),g=X.get(this),l=g.fds.get(t,h,d),_=J(this),E=_.HEAPU8,y=ot.decode(E.subarray(n,n+r)),p=tt(this),I=await it(p,l,y,e),b=await p.promises.open(I,c,438),m=await g.fds.getFileTypeByFd(b);if(0!=(2&i)&&3!==m)return 54;const{base:A,inheriting:T}=U(g.fds.stdio,b.fd,c,m),w=g.fds.insert(b,I,I,m,s&A,o&T,0),N=await b.stat({bigint:!0});N.isFile()&&(w.size=N.size,0!=(1024&c)&&(w.pos=N.size));return _.view.setInt32(u,w.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:a}=J(this),u=X.get(this).fds.get(t,p.PATH_READLINK,BigInt(0));let c=ot.decode(o.subarray(e,e+n));c=y(u.realPath,c);const f=tt(this).readlinkSync(c),h=st.encode(f),d=Math.min(h.length,i);return d>=i?42:(o.set(h.subarray(0,d),r),o[r+d]=0,a.setUint32(s,d+1,!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:a}=J(this),u=X.get(this).fds.get(t,p.PATH_READLINK,BigInt(0));let c=ot.decode(o.subarray(e,e+n));c=y(u.realPath,c);const f=tt(this),h=await f.promises.readlink(c),d=st.encode(h),g=Math.min(d.length,i);return g>=i?42:(o.set(d.subarray(0,g),r),o[r+g]=0,a.setUint32(s,g+1,!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}=J(this),i=X.get(this).fds.get(t,p.PATH_REMOVE_DIRECTORY,BigInt(0));let s=ot.decode(r.subarray(e,e+n));s=y(i.realPath,s);return tt(this).rmdirSync(s),0}),(async function(t,e,n){if(e=Number(e),n=Number(n),0===e)return 28;const{HEAPU8:r}=J(this),i=X.get(this).fds.get(t,p.PATH_REMOVE_DIRECTORY,BigInt(0));let s=ot.decode(r.subarray(e,e+n));s=y(i.realPath,s);const o=tt(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=X.get(this);let a,u;t===r?a=u=o.fds.get(t,p.PATH_RENAME_SOURCE|p.PATH_RENAME_TARGET,BigInt(0)):(a=o.fds.get(t,p.PATH_RENAME_SOURCE,BigInt(0)),u=o.fds.get(r,p.PATH_RENAME_TARGET,BigInt(0)));const{HEAPU8:c}=J(this),f=y(a.realPath,ot.decode(c.subarray(e,e+n))),h=y(u.realPath,ot.decode(c.subarray(i,i+s)));return tt(this).renameSync(f,h),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=X.get(this);let a,u;t===r?a=u=o.fds.get(t,p.PATH_RENAME_SOURCE|p.PATH_RENAME_TARGET,BigInt(0)):(a=o.fds.get(t,p.PATH_RENAME_SOURCE,BigInt(0)),u=o.fds.get(r,p.PATH_RENAME_TARGET,BigInt(0)));const{HEAPU8:c}=J(this),f=y(a.realPath,ot.decode(c.subarray(e,e+n))),h=y(u.realPath,ot.decode(c.subarray(i,i+s))),d=tt(this);return await d.promises.rename(f,h),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}=J(this),o=X.get(this).fds.get(n,p.PATH_SYMLINK,BigInt(0)),a=ot.decode(s.subarray(t,t+e));let u=ot.decode(s.subarray(r,r+i));u=y(o.realPath,u);return tt(this).symlinkSync(a,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}=J(this),o=X.get(this).fds.get(n,p.PATH_SYMLINK,BigInt(0)),a=ot.decode(s.subarray(t,t+e));let u=ot.decode(s.subarray(r,r+i));u=y(o.realPath,u);const c=tt(this);return await c.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:r}=J(this),i=X.get(this).fds.get(t,p.PATH_UNLINK_FILE,BigInt(0));let s=ot.decode(r.subarray(e,e+n));s=y(i.realPath,s);return tt(this).unlinkSync(s),0}),(async function(t,e,n){if(e=Number(e),n=Number(n),0===e)return 28;const{HEAPU8:r}=J(this),i=X.get(this).fds.get(t,p.PATH_UNLINK_FILE,BigInt(0));let s=ot.decode(r.subarray(e,e+n));s=y(i.realPath,s);const o=tt(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');q.set(a,G(e))}}static createSync(t,e,n,r,i,s,o){const a=new M({size:3,in:r[0],out:r[1],err:r[2],fs:i,print:s,printErr:o}),u=new ut(t,e,a,!1,i);if(n.length>0)for(let t=0;t<n.length;++t){const e=i.realpathSync(n[t].realPath,"utf8"),r=i.openSync(e,"r",438);a.insertPreopen(r,n[t].mappedPath,e)}return u}static async createAsync(t,e,n,r,i,s,o,a){const u=new K({size:3,in:r[0],out:r[1],err:r[2],print:s,printErr:o}),c=new ut(t,e,u,!0,i,a);if(n.length>0)for(let t=0;t<n.length;++t){const e=n[t],r=await i.promises.realpath(e.realPath),s=await i.promises.open(r,"r",438);await u.insertPreopen(s,e.mappedPath,r)}return c}}const ct=Object.freeze(Object.create(null)),ft=Symbol("kExitCode"),ht=Symbol("kSetMemory"),dt=Symbol("kStarted"),gt=Symbol("kInstance");function lt(t,n){e(n,"instance"),e(n.exports,"instance.exports"),t[gt]=n,t[ht](n.exports.memory)}function _t(t){var n;e(t,"options"),void 0!==t.args&&function(t,e){if(!Array.isArray(t))throw new TypeError(`${e} must be an array. Received ${null===t?"null":typeof t}`)}(t.args,"options.args");const i=(null!==(n=t.args)&&void 0!==n?n:[]).map(String),s=[];void 0!==t.env&&(e(t.env,"options.env"),Object.entries(t.env).forEach((({0:t,1:e})=>{void 0!==e&&s.push(`${t}=${e}`)})));const o=[];if(void 0!==t.preopens&&(e(t.preopens,"options.preopens"),Object.entries(t.preopens).forEach((({0:t,1:e})=>o.push({mappedPath:String(t),realPath:String(e)})))),o.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:i,env:s,preopens:o,stdio:[0,1,2]}}class Et{constructor(t,e){this[ht]=t,this.wasiImport=e,this[dt]=!1,this[ft]=0,this[gt]=void 0}static createSync(t=ct){const{args:e,env:n,preopens:r,stdio:i}=_t(t),s=ut.createSync(e,n,r,i,t.fs,t.print,t.printErr),o=s._setMemory;delete s._setMemory;const a=new Et(o,s);return t.returnOnExit&&(s.proc_exit=yt.bind(a)),a}static async createAsync(t=ct){const{args:n,env:i,preopens:s,stdio:o}=_t(t);void 0!==t.asyncify&&(e(t.asyncify,"options.asyncify"),r(t.asyncify.wrapImportFunction,"options.asyncify.wrapImportFunction"));const a=await ut.createAsync(n,i,s,o,t.fs,t.print,t.printErr,t.asyncify),u=a._setMemory;delete a._setMemory;const c=new Et(u,a);return t.returnOnExit&&(a.proc_exit=yt.bind(c)),c}start(t){if(this[dt])throw new Error("WASI instance has already started");this[dt]=!0,lt(this,t);const{_start:e,_initialize:n}=this[gt].exports;let s;r(e,"instance.exports._start"),i(n,"instance.exports._initialize");try{s=e()}catch(t){if(t!==ft)throw t}return s instanceof Promise?s.then((()=>this[ft]),(t=>{if(t!==ft)throw t;return this[ft]})):this[ft]}initialize(t){if(this[dt])throw new Error("WASI instance has already started");this[dt]=!0,lt(this,t);const{_start:e,_initialize:n}=this[gt].exports;if(i(e,"instance.exports._start"),void 0!==n)return r(n,"instance.exports._initialize"),n()}}function yt(t){throw this[ft]=t,ft}export{c as Asyncify,W as Memory,Et as WASI,z as WebAssemblyMemory,g as asyncifyLoad,_ as asyncifyLoadSync,G as extendMemory,d as load,l as loadSync,j as wrapAsyncExport,$ as wrapAsyncImport,V as wrapExports};
package/dist/wasm-util.js CHANGED
@@ -208,50 +208,53 @@
208
208
  throw new TypeError('imports must be an object or undefined');
209
209
  }
210
210
  }
211
- async function fetchWasm(urlOrBuffer, imports) {
211
+ function fetchWasm(urlOrBuffer, imports) {
212
212
  if (typeof wx !== 'undefined' && typeof __wxConfig !== 'undefined') {
213
- return await _WebAssembly.instantiate(urlOrBuffer, imports);
213
+ return _WebAssembly.instantiate(urlOrBuffer, imports);
214
214
  }
215
- const response = await fetch(urlOrBuffer);
216
- const buffer = await response.arrayBuffer();
217
- const source = await _WebAssembly.instantiate(buffer, imports);
218
- return source;
215
+ return fetch(urlOrBuffer)
216
+ .then(response => response.arrayBuffer())
217
+ .then(buffer => _WebAssembly.instantiate(buffer, imports));
219
218
  }
220
219
  /** @public */
221
- async function load(urlOrBuffer, imports) {
220
+ function load(urlOrBuffer, imports) {
222
221
  validateImports(imports);
223
222
  imports = imports !== null && imports !== void 0 ? imports : {};
224
223
  let source;
225
224
  if (urlOrBuffer instanceof ArrayBuffer || ArrayBuffer.isView(urlOrBuffer)) {
226
- source = await _WebAssembly.instantiate(urlOrBuffer, imports);
227
- return source;
225
+ return _WebAssembly.instantiate(urlOrBuffer, imports);
228
226
  }
229
227
  if (typeof urlOrBuffer !== 'string' && !(urlOrBuffer instanceof URL)) {
230
228
  throw new TypeError('Invalid source');
231
229
  }
232
230
  if (typeof _WebAssembly.instantiateStreaming === 'function') {
231
+ let responsePromise;
233
232
  try {
234
- source = await _WebAssembly.instantiateStreaming(fetch(urlOrBuffer), imports);
233
+ responsePromise = fetch(urlOrBuffer);
234
+ source = _WebAssembly.instantiateStreaming(responsePromise, imports).catch(() => {
235
+ return fetchWasm(urlOrBuffer, imports);
236
+ });
235
237
  }
236
238
  catch (_) {
237
- source = await fetchWasm(urlOrBuffer, imports);
239
+ source = fetchWasm(urlOrBuffer, imports);
238
240
  }
239
241
  }
240
242
  else {
241
- source = await fetchWasm(urlOrBuffer, imports);
243
+ source = fetchWasm(urlOrBuffer, imports);
242
244
  }
243
245
  return source;
244
246
  }
245
247
  /** @public */
246
- async function asyncifyLoad(asyncify, urlOrBuffer, imports) {
247
- var _a;
248
+ function asyncifyLoad(asyncify, urlOrBuffer, imports) {
248
249
  validateImports(imports);
249
250
  imports = imports !== null && imports !== void 0 ? imports : {};
250
251
  const asyncifyHelper = new Asyncify();
251
252
  imports = asyncifyHelper.wrapImports(imports);
252
- const source = await load(urlOrBuffer, imports);
253
- const memory = source.instance.exports.memory || ((_a = imports.env) === null || _a === void 0 ? void 0 : _a.memory);
254
- return { module: source.module, instance: asyncifyHelper.init(memory, source.instance, asyncify) };
253
+ return load(urlOrBuffer, imports).then(source => {
254
+ var _a;
255
+ const memory = source.instance.exports.memory || ((_a = imports.env) === null || _a === void 0 ? void 0 : _a.memory);
256
+ return { module: source.module, instance: asyncifyHelper.init(memory, source.instance, asyncify) };
257
+ });
255
258
  }
256
259
  /** @public */
257
260
  function loadSync(buffer, imports) {
@@ -1 +1 @@
1
- !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 r(t,e){if("string"!=typeof t)throw new TypeError(`${e} must be a string. Received ${null===t?"null":typeof t}`)}function i(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((r=>{const i=t[r];Object.defineProperty(n,r,{enumerable:!0,value:e(i,r)})})),n}const u=["asyncify_get_state","asyncify_start_rewind","asyncify_start_unwind","asyncify_stop_rewind","asyncify_stop_unwind"];function c(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(t,n,r){var i,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<u.length;++t)if("function"!=typeof o[u[t]])throw new TypeError("Invalid asyncify wasm");let a;const f=Boolean(r.wasm64);a=r.tryAllocate?!0===r.tryAllocate?c(n,f,4096,"malloc"):c(n,f,null!==(i=r.tryAllocate.size)&&void 0!==i?i:4096,null!==(s=r.tryAllocate.name)&&void 0!==s?s:"malloc"):{wasm64:f,dataPtr:16,start:f?32:24,end:1024},this.dataPtr=a.dataPtr,f?new BigInt64Array(t.buffer,this.dataPtr).set([BigInt(a.start),BigInt(a.end)]):new Int32Array(t.buffer,this.dataPtr).set([a.start,a.end]),this.exports=this.wrapExports(o,r.wrapExports);const h=Object.create(e.Instance.prototype);return Object.defineProperty(h,"exports",{value:this.exports}),h}assertState(){if(0!==this.exports.asyncify_get_state())throw new Error("Asyncify state error")}wrapImportFunction(t){const e=this;return function(){for(;2===e.exports.asyncify_get_state();)return e.exports.asyncify_stop_rewind(),e.value;e.assertState();const n=t.apply(this,arguments);if(!o(n))return n;e.exports.asyncify_start_unwind(e.dataPtr),e.value=n}}wrapImports(t){const e={};return Object.keys(t).forEach((n=>{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 a(t,((t,n)=>{let r=-1!==u.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")}async function d(t,n){if("undefined"!=typeof wx&&"undefined"!=typeof __wxConfig)return await e.instantiate(t,n);const r=await fetch(t),i=await r.arrayBuffer();return await e.instantiate(i,n)}async function g(t,n){let r;if(h(n),n=null!=n?n:{},t instanceof ArrayBuffer||ArrayBuffer.isView(t))return r=await e.instantiate(t,n),r;if("string"!=typeof t&&!(t instanceof URL))throw new TypeError("Invalid source");if("function"==typeof e.instantiateStreaming)try{r=await e.instantiateStreaming(fetch(t),n)}catch(e){r=await d(t,n)}else r=await d(t,n);return r}function l(t,n){if(t instanceof ArrayBuffer&&!ArrayBuffer.isView(t))throw new TypeError("Invalid source");h(n),n=null!=n?n:{};const r=new e.Module(t);return{instance:new e.Instance(r,n),module:r}}function _(t){return 47===t}function y(...t){let e="",n=!1;for(let i=t.length-1;i>=-1&&!n;i--){const s=i>=0?t[i]:"/";r(s,"path"),0!==s.length&&(e=`${s}/${e}`,n=47===s.charCodeAt(0))}return e=function(t,e,n,r){let i="",s=0,o=-1,a=0,u=0;for(let c=0;c<=t.length;++c){if(c<t.length)u=t.charCodeAt(c);else{if(r(u))break;u=47}if(r(u)){if(o===c-1||1===a);else if(2===a){if(i.length<2||2!==s||46!==i.charCodeAt(i.length-1)||46!==i.charCodeAt(i.length-2)){if(i.length>2){const t=i.indexOf(n);-1===t?(i="",s=0):(i=i.slice(0,t),s=i.length-1-i.indexOf(n)),o=c,a=0;continue}if(0!==i.length){i="",s=0,o=c,a=0;continue}}e&&(i+=i.length>0?`${n}..`:"..",s=2)}else i.length>0?i+=`${n}${t.slice(o+1,c)}`:i=t.slice(o+1,c),s=c-o-1;o=c,a=0}else 46===u&&-1!==a?++a:a=-1}return i}(e,!n,"/",_),n?`/${e}`:e.length>0?e:"."}const E={FD_DATASYNC:BigInt(1)<<BigInt(0),FD_READ:BigInt(1)<<BigInt(1),FD_SEEK:BigInt(1)<<BigInt(2),FD_FDSTAT_SET_FLAGS:BigInt(1)<<BigInt(3),FD_SYNC:BigInt(1)<<BigInt(4),FD_TELL:BigInt(1)<<BigInt(5),FD_WRITE:BigInt(1)<<BigInt(6),FD_ADVISE:BigInt(1)<<BigInt(7),FD_ALLOCATE:BigInt(1)<<BigInt(8),PATH_CREATE_DIRECTORY:BigInt(1)<<BigInt(9),PATH_CREATE_FILE:BigInt(1)<<BigInt(10),PATH_LINK_SOURCE:BigInt(1)<<BigInt(11),PATH_LINK_TARGET:BigInt(1)<<BigInt(12),PATH_OPEN:BigInt(1)<<BigInt(13),FD_READDIR:BigInt(1)<<BigInt(14),PATH_READLINK:BigInt(1)<<BigInt(15),PATH_RENAME_SOURCE:BigInt(1)<<BigInt(16),PATH_RENAME_TARGET:BigInt(1)<<BigInt(17),PATH_FILESTAT_GET:BigInt(1)<<BigInt(18),PATH_FILESTAT_SET_SIZE:BigInt(1)<<BigInt(19),PATH_FILESTAT_SET_TIMES:BigInt(1)<<BigInt(20),FD_FILESTAT_GET:BigInt(1)<<BigInt(21),FD_FILESTAT_SET_SIZE:BigInt(1)<<BigInt(22),FD_FILESTAT_SET_TIMES:BigInt(1)<<BigInt(23),PATH_SYMLINK:BigInt(1)<<BigInt(24),PATH_REMOVE_DIRECTORY:BigInt(1)<<BigInt(25),PATH_UNLINK_FILE:BigInt(1)<<BigInt(26),POLL_FD_READWRITE:BigInt(1)<<BigInt(27),SOCK_SHUTDOWN:BigInt(1)<<BigInt(28),SOCK_ACCEPT:BigInt(1)<<BigInt(29)};class p extends Error{constructor(t,e){super(t),this.errno=e}getErrorMessage(){return function(t){switch(t){case 0:return"Success";case 1:return"Argument list too long";case 2:return"Permission denied";case 3:return"Address in use";case 4:return"Address not available";case 5:return"Address family not supported by protocol";case 6:return"Resource temporarily unavailable";case 7:return"Operation already in progress";case 8:return"Bad file descriptor";case 9:return"Bad message";case 10:return"Resource busy";case 11:return"Operation canceled";case 12:return"No child process";case 13:return"Connection aborted";case 14:return"Connection refused";case 15:return"Connection reset by peer";case 16:return"Resource deadlock would occur";case 17:return"Destination address required";case 18:return"Domain error";case 19:return"Quota exceeded";case 20:return"File exists";case 21:return"Bad address";case 22:return"File too large";case 23:return"Host is unreachable";case 24:return"Identifier removed";case 25:return"Illegal byte sequence";case 26:return"Operation in progress";case 27:return"Interrupted system call";case 28:return"Invalid argument";case 29:return"I/O error";case 30:return"Socket is connected";case 31:return"Is a directory";case 32:return"Symbolic link loop";case 33:return"No file descriptors available";case 34:return"Too many links";case 35:return"Message too large";case 36:return"Multihop attempted";case 37:return"Filename too long";case 38:return"Network is down";case 39:return"Connection reset by network";case 40:return"Network unreachable";case 41:return"Too many files open in system";case 42:return"No buffer space available";case 43:return"No such device";case 44:return"No such file or directory";case 45:return"Exec format error";case 46:return"No locks available";case 47:return"Link has been severed";case 48:return"Out of memory";case 49:return"No message of the desired type";case 50:return"Protocol not available";case 51:return"No space left on device";case 52:return"Function not implemented";case 53:return"Socket not connected";case 54:return"Not a directory";case 55:return"Directory not empty";case 56:return"State not recoverable";case 57:return"Not a socket";case 58:return"Not supported";case 59:return"Not a tty";case 60:return"No such device or address";case 61:return"Value too large for data type";case 62:return"Previous owner died";case 63:return"Operation not permitted";case 64:return"Broken pipe";case 65:return"Protocol error";case 66:return"Protocol not supported";case 67:return"Protocol wrong type for socket";case 68:return"Result not representable";case 69:return"Read-only file system";case 70:return"Invalid seek";case 71:return"No such process";case 72:return"Stale file handle";case 73:return"Operation timed out";case 74:return"Text file busy";case 75:return"Cross-device link";case 76:return"Capabilities insufficient";default:return"Unknown error"}}(this.errno)}}Object.defineProperty(p.prototype,"name",{configurable:!0,writable:!0,value:"WasiError"});const I=E.FD_DATASYNC|E.FD_READ|E.FD_SEEK|E.FD_FDSTAT_SET_FLAGS|E.FD_SYNC|E.FD_TELL|E.FD_WRITE|E.FD_ADVISE|E.FD_ALLOCATE|E.PATH_CREATE_DIRECTORY|E.PATH_CREATE_FILE|E.PATH_LINK_SOURCE|E.PATH_LINK_TARGET|E.PATH_OPEN|E.FD_READDIR|E.PATH_READLINK|E.PATH_RENAME_SOURCE|E.PATH_RENAME_TARGET|E.PATH_FILESTAT_GET|E.PATH_FILESTAT_SET_SIZE|E.PATH_FILESTAT_SET_TIMES|E.FD_FILESTAT_GET|E.FD_FILESTAT_SET_TIMES|E.FD_FILESTAT_SET_SIZE|E.PATH_SYMLINK|E.PATH_UNLINK_FILE|E.PATH_REMOVE_DIRECTORY|E.POLL_FD_READWRITE|E.SOCK_SHUTDOWN,b=I,m=I,A=I,T=I,w=E.FD_DATASYNC|E.FD_READ|E.FD_SEEK|E.FD_FDSTAT_SET_FLAGS|E.FD_SYNC|E.FD_TELL|E.FD_WRITE|E.FD_ADVISE|E.FD_ALLOCATE|E.FD_FILESTAT_GET|E.FD_FILESTAT_SET_SIZE|E.FD_FILESTAT_SET_TIMES|E.POLL_FD_READWRITE,N=BigInt(0),B=E.FD_FDSTAT_SET_FLAGS|E.FD_SYNC|E.FD_ADVISE|E.PATH_CREATE_DIRECTORY|E.PATH_CREATE_FILE|E.PATH_LINK_SOURCE|E.PATH_LINK_TARGET|E.PATH_OPEN|E.FD_READDIR|E.PATH_READLINK|E.PATH_RENAME_SOURCE|E.PATH_RENAME_TARGET|E.PATH_FILESTAT_GET|E.PATH_FILESTAT_SET_SIZE|E.PATH_FILESTAT_SET_TIMES|E.FD_FILESTAT_GET|E.FD_FILESTAT_SET_TIMES|E.PATH_SYMLINK|E.PATH_UNLINK_FILE|E.PATH_REMOVE_DIRECTORY|E.POLL_FD_READWRITE,S=B|w,P=E.FD_READ|E.FD_FDSTAT_SET_FLAGS|E.FD_WRITE|E.FD_FILESTAT_GET|E.POLL_FD_READWRITE|E.SOCK_SHUTDOWN,D=I,F=E.FD_READ|E.FD_FDSTAT_SET_FLAGS|E.FD_WRITE|E.FD_FILESTAT_GET|E.POLL_FD_READWRITE,R=BigInt(0);function v(t,e,n,r){const i={base:BigInt(0),inheriting:BigInt(0)};if(0===r)throw new p("Unknown file type",28);switch(r){case 4:i.base=w,i.inheriting=N;break;case 3:i.base=B,i.inheriting=S;break;case 6:case 5:i.base=P,i.inheriting=D;break;case 2:-1!==t.indexOf(e)?(i.base=F,i.inheriting=R):(i.base=A,i.inheriting=T);break;case 1:i.base=b,i.inheriting=m;break;default:i.base=BigInt(0),i.inheriting=BigInt(0)}const s=3&n;return 0===s?i.base&=~E.FD_WRITE:1===s&&(i.base&=~E.FD_READ),i}function U(t,e){let n=0;if("number"==typeof e&&e>=0)n=e;else for(let e=0;e<t.length;e++){n+=t[e].length}let r=0;const i=new Uint8Array(n);for(let e=0;e<t.length;e++){const n=t[e];i.set(n,r),r+=n.length}return i}class L{constructor(t,e,n,r,i,s,o,a){this.id=t,this.fd=e,this.path=n,this.realPath=r,this.type=i,this.rightsBase=s,this.rightsInheriting=o,this.preopen=a,this.pos=BigInt(0),this.size=BigInt(0)}seek(t,e){if(0===e)this.pos=BigInt(t);else if(1===e)this.pos+=BigInt(t);else{if(2!==e)throw new p("Unknown whence",29);this.pos=BigInt(this.size)-BigInt(t)}return this.pos}}class H extends L{constructor(t,e,n,r,i,s,o,a,u){super(e,n,r,i,s,o,a,u),this._log=t,this._buf=null}write(t){const e=t;if(this._buf&&(t=U([this._buf,t]),this._buf=null),-1===t.indexOf(10))return this._buf=t,e.byteLength;let n,r=0,i=0;for(;-1!==(n=t.indexOf(10,r));){const e=(new TextDecoder).decode(t.subarray(i,n));this._log(e),r+=n-i+1,i=n+1}return r<t.length&&(this._buf=t.slice(r)),e.byteLength}}function O(t){return t.isBlockDevice()?1:t.isCharacterDevice()?2:t.isDirectory()?3:t.isSocket()?6:t.isFile()?4:t.isSymbolicLink()?7:0}function C(t,e,n){t.setBigUint64(e,n.dev,!0),t.setBigUint64(e+8,n.ino,!0),t.setBigUint64(e+16,BigInt(O(n)),!0),t.setBigUint64(e+24,n.nlink,!0),t.setBigUint64(e+32,n.size,!0),t.setBigUint64(e+40,n.atimeMs*BigInt(1e6),!0),t.setBigUint64(e+48,n.mtimeMs*BigInt(1e6),!0),t.setBigUint64(e+56,n.ctimeMs*BigInt(1e6),!0)}class k{constructor(t){this.used=0,this.size=t.size,this.fds=Array(t.size),this.stdio=[t.in,t.out,t.err],this.print=t.print,this.printErr=t.printErr,this.insertStdio(t.in,0,"<stdin>"),this.insertStdio(t.out,1,"<stdout>"),this.insertStdio(t.err,2,"<stderr>")}insertStdio(t,e,n){const{base:r,inheriting:i}=v(this.stdio,t,2,2),s=this.insert(t,n,n,2,r,i,0);if(s.id!==e)throw new p(`id: ${s.id} !== expected: ${e}`,8);return s}insert(t,e,n,r,i,s,o){var a,u;let c,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<this.size;++t)if(null==this.fds[t]){f=t;break}return c="<stdout>"===e?new H(null!==(a=this.print)&&void 0!==a?a:console.log,f,t,e,n,r,i,s,o):"<stderr>"===e?new H(null!==(u=this.printErr)&&void 0!==u?u:console.error,f,t,e,n,r,i,s,o):new L(f,t,e,n,r,i,s,o),this.fds[f]=c,this.used++,c}get(t,e,n){if(t>=this.size)throw new p("Invalid fd",8);const r=this.fds[t];if(!r||r.id!==t)throw new p("Bad file descriptor",8);if((~r.rightsBase&e)!==BigInt(0)||(~r.rightsInheriting&n)!==BigInt(0))throw new p("Capabilities insufficient",76);return r}remove(t){if(t>=this.size)throw new p("Invalid fd",8);const e=this.fds[t];if(!e||e.id!==t)throw new p("Bad file descriptor",8);this.fds[t]=void 0,this.used--}}class x extends k{constructor(t){super(t),this.fs=t.fs}getFileTypeByFd(t){return O(this.fs.fstatSync(t,{bigint:!0}))}insertPreopen(t,e,n){const r=this.getFileTypeByFd(t);if(3!==r)throw new p(`Preopen not dir: ["${e}", "${n}"]`,54);const i=v(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 p("Invalid fd",8);const n=this.fds[t],r=this.fds[e];if(!n||!r||n.id!==t||r.id!==e)throw new p("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 M extends k{constructor(t){super(t)}async getFileTypeByFd(t){return O(await t.stat({bigint:!0}))}async insertPreopen(t,e,n){const r=await this.getFileTypeByFd(t);if(3!==r)throw new p(`Preopen not dir: ["${e}", "${n}"]`,54);const i=v(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 p("Invalid fd",8);const n=this.fds[t],r=this.fds[e];if(!n||!r||n.id!==t||r.id!==e)throw new p("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 K=function(){return e.Memory}();class z extends K{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 W(t){return Object.getPrototypeOf(t)===e.Memory.prototype&&Object.setPrototypeOf(t,z.prototype),t}function G(){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-flag="--wasm-staging --experimental-wasm-stack-switching"');return t}function Y(t,e,n){const r=G();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 j(t){const e=G();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 $(t,e){if(0===t.length||0===e.length)return 0;let n=0,r=e.length-n;for(let i=0;i<t.length;++i){const s=t[i];if(r<s.length)return s.set(e.subarray(n,n+r),0),n+=r,r=0,n;s.set(e.subarray(n,n+s.length),0),n+=s.length,r-=s.length}return n}const V=new WeakMap,Z=new WeakMap,q=new WeakMap;function X(t){return V.get(t)}function Q(t){const e=q.get(t);if(!e)throw new Error("filesystem is unavailable");return e}function J(t){if(t instanceof p)return t.errno;switch(t.code){case"ENOENT":return 44;case"EBADF":return 8;case"EINVAL":return 28;case"EPERM":return 63;case"EPROTO":return 65;case"EEXIST":return 20;case"ENOTDIR":return 54;case"EMFILE":return 33;case"EACCES":return 2;case"EISDIR":return 31;case"ENOTEMPTY":return 55;case"ENOSYS":return 52}throw t}function tt(t,e,n){return function(t,e){return Object.defineProperty(e,"name",{value:t}),e}(e,(function(){let e;try{e=n.apply(t,arguments)}catch(t){return J(t)}return o(e)?e.then((t=>t),J):e}))}function et(t,e,n,r){let i=y(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 nt(t,e,n,r){let i=y(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 rt=new TextEncoder,it=new TextDecoder;function st(){const t=window.prompt();if(null===t)return new Uint8Array;return(new TextEncoder).encode(t+"\n")}class ot{constructor(t,n,r,i,s,o){this.args_get=tt(this,"args_get",(function(t,e){if(t=Number(t),e=Number(e),0===t||0===e)return 28;const{HEAPU8:n,view:r}=X(this),i=Z.get(this).args;for(let s=0;s<i.length;++s){const o=i[s];r.setInt32(t,e,!0),t+=4;const a=rt.encode(o+"\0");n.set(a,e),e+=a.length}return 0})),this.args_sizes_get=tt(this,"args_sizes_get",(function(t,e){if(t=Number(t),e=Number(e),0===t||0===e)return 28;const{view:n}=X(this),r=Z.get(this).args;return n.setUint32(t,r.length,!0),n.setUint32(e,rt.encode(r.join("\0")+"\0").length,!0),0})),this.environ_get=tt(this,"environ_get",(function(t,e){if(t=Number(t),e=Number(e),0===t||0===e)return 28;const{HEAPU8:n,view:r}=X(this),i=Z.get(this).env;for(let s=0;s<i.length;++s){const o=i[s];r.setInt32(t,e,!0),t+=4;const a=rt.encode(o+"\0");n.set(a,e),e+=a.length}return 0})),this.environ_sizes_get=tt(this,"environ_sizes_get",(function(t,e){if(t=Number(t),e=Number(e),0===t||0===e)return 28;const{view:n}=X(this),r=Z.get(this);return n.setUint32(t,r.env.length,!0),n.setUint32(e,rt.encode(r.env.join("\0")+"\0").length,!0),0})),this.clock_res_get=tt(this,"clock_res_get",(function(t,e){if(0===(e=Number(e)))return 28;const{view:n}=X(this);switch(t){case 0:return n.setBigUint64(e,BigInt(1e6),!0),0;case 1:case 2:case 3:return n.setBigUint64(e,BigInt(1e3),!0),0;default:return 28}})),this.clock_time_get=tt(this,"clock_time_get",(function(t,e,n){if(0===(n=Number(n)))return 28;const{view:r}=X(this);switch(t){case 0:return r.setBigUint64(n,BigInt(Date.now())*BigInt(1e6),!0),0;case 1:case 2:case 3:{const t=performance.now(),e=Math.trunc(t),i=Math.floor(1e3*(t-e)),s=BigInt(e)*BigInt(1e9)+BigInt(i)*BigInt(1e6);return r.setBigUint64(n,s,!0),0}default:return 28}})),this.fd_advise=tt(this,"fd_advise",(function(t,e,n,r){return 52})),this.fd_fdstat_get=tt(this,"fd_fdstat_get",(function(t,e){if(0===(e=Number(e)))return 28;const n=Z.get(this).fds.get(t,BigInt(0),BigInt(0)),{view:r}=X(this);return r.setUint16(e,n.type,!0),r.setUint16(e+2,0,!0),r.setBigUint64(e+8,n.rightsBase,!0),r.setBigUint64(e+16,n.rightsInheriting,!0),0})),this.fd_fdstat_set_flags=tt(this,"fd_fdstat_set_flags",(function(t,e){return 52})),this.fd_fdstat_set_rights=tt(this,"fd_fdstat_set_rights",(function(t,e,n){const r=Z.get(this).fds.get(t,BigInt(0),BigInt(0));return(e|r.rightsBase)>r.rightsBase||(n|r.rightsInheriting)>r.rightsInheriting?76:(r.rightsBase=e,r.rightsInheriting=n,0)})),this.fd_prestat_get=tt(this,"fd_prestat_get",(function(t,e){if(0===(e=Number(e)))return 28;const n=Z.get(this);let r;try{r=n.fds.get(t,BigInt(0),BigInt(0))}catch(t){if(t instanceof p)return t.errno;throw t}if(1!==r.preopen)return 28;const{view:i}=X(this);return i.setUint32(e,0,!0),i.setUint32(e+4,rt.encode(r.path).length+1,!0),0})),this.fd_prestat_dir_name=tt(this,"fd_prestat_dir_name",(function(t,e,n){if(e=Number(e),n=Number(n),0===e)return 28;const r=Z.get(this).fds.get(t,BigInt(0),BigInt(0));if(1!==r.preopen)return 8;const i=rt.encode(r.path+"\0");if(i.length>n)return 42;const{HEAPU8:s}=X(this);return s.set(i,e),0})),this.fd_seek=tt(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=Z.get(this).fds.get(t,E.FD_SEEK,BigInt(0)).seek(e,n),{view:s}=X(this);return s.setBigUint64(r,i,!0),0})),this.fd_tell=tt(this,"fd_tell",(function(t,e){const n=Z.get(this).fds.get(t,E.FD_TELL,BigInt(0)),r=BigInt(n.pos),{view:i}=X(this);return i.setBigUint64(Number(e),r,!0),0})),this.poll_oneoff=tt(this,"poll_oneoff",(function(t,e,n,r){return 52})),this.proc_exit=tt(this,"proc_exit",(function(t){return 0})),this.proc_raise=tt(this,"proc_raise",(function(t){return 52})),this.sched_yield=tt(this,"sched_yield",(function(){return 0})),this.random_get="undefined"!=typeof crypto&&"function"==typeof crypto.getRandomValues?tt(this,"random_get",(function(t,e){if(0===(t=Number(t)))return 28;e=Number(e);const{HEAPU8:n}=X(this);let r;const i=65536;for(r=0;r+i<e;r+=i)crypto.getRandomValues(n.subarray(t+r,t+r+i));return crypto.getRandomValues(n.subarray(t+r,t+e)),0})):tt(this,"random_get",(function(t,e){if(0===(t=Number(t)))return 28;e=Number(e);const{view:n}=X(this);for(let r=t;r<t+e;++r)n.setUint8(r,Math.floor(256*Math.random()));return 0})),this.sock_recv=tt(this,"sock_recv",(function(){return 58})),this.sock_send=tt(this,"sock_send",(function(){return 58})),this.sock_shutdown=tt(this,"sock_shutdown",(function(){return 58})),Z.set(this,{fds:r,args:t,env:n}),s&&q.set(this,s);const a=this;function u(t,e,n,r,s){a[t]=i?o?o.wrapImportFunction(tt(a,t,n)):Y(tt(a,t,n),r,s):tt(a,t,e)}function c(t,e,n,r){const i=Z.get(this).fds.get(t,E.FD_FILESTAT_SET_TIMES,BigInt(0));return 2==(2&r)&&(e=BigInt(1e6*Date.now())),8==(8&r)&&(n=BigInt(1e6*Date.now())),{fileDescriptor:i,atim:e,mtim:n}}function f(t,e,n,r){const i=(e&(E.FD_READ|E.FD_READDIR))!==BigInt(0),s=(e&(E.FD_DATASYNC|E.FD_WRITE|E.FD_ALLOCATE|E.FD_FILESTAT_SET_SIZE))!==BigInt(0);let o=s?i?2:1:0,a=E.PATH_OPEN,u=e|n;return 0!=(1&t)&&(o|=64,a|=E.PATH_CREATE_FILE),0!=(2&t)&&(o|=65536),0!=(4&t)&&(o|=128),0!=(8&t)&&(o|=512,a|=E.PATH_FILESTAT_SET_SIZE),0!=(1&r)&&(o|=1024),0!=(2&r)&&(u|=E.FD_DATASYNC),0!=(4&r)&&(o|=2048),0!=(8&r)&&(o|=1052672,u|=E.FD_SYNC),0!=(16&r)&&(o|=1052672,u|=E.FD_SYNC),s&&0==(1536&o)&&(u|=E.FD_SEEK),{flags:o,needed_base:a,needed_inheriting:u}}u("fd_allocate",(function(t,e,n){const r=Z.get(this),i=Q(this),s=r.fds.get(t,E.FD_ALLOCATE,BigInt(0));return i.fstatSync(s.fd,{bigint:!0}).size<e+n&&i.ftruncateSync(s.fd,Number(e+n)),0}),(async function(t,e,n){const r=Z.get(this).fds.get(t,E.FD_ALLOCATE,BigInt(0)).fd;return(await r.stat({bigint:!0})).size<e+n&&await r.truncate(Number(e+n)),0}),["i32","i64","f64"],["i32"]),u("fd_close",(function(t){const e=Z.get(this),n=e.fds.get(t,BigInt(0),BigInt(0));return Q(this).closeSync(n.fd),e.fds.remove(t),0}),(async function(t){const e=Z.get(this),n=e.fds.get(t,BigInt(0),BigInt(0));return await n.fd.close(),e.fds.remove(t),0}),["i32"],["i32"]),u("fd_datasync",(function(t){const e=Z.get(this).fds.get(t,E.FD_DATASYNC,BigInt(0));return Q(this).fdatasyncSync(e.fd),0}),(async function(t){const e=Z.get(this).fds.get(t,E.FD_DATASYNC,BigInt(0));return await e.fd.datasync(),0}),["i32"],["i32"]),u("fd_filestat_get",(function(t,e){if(0===(e=Number(e)))return 28;const n=Z.get(this).fds.get(t,E.FD_FILESTAT_GET,BigInt(0)),r=Q(this).fstatSync(n.fd,{bigint:!0}),{view:i}=X(this);return C(i,e,r),0}),(async function(t,e){if(0===(e=Number(e)))return 28;const n=Z.get(this).fds.get(t,E.FD_FILESTAT_GET,BigInt(0)).fd,r=await n.stat({bigint:!0}),{view:i}=X(this);return C(i,e,r),0}),["i32","i32"],["i32"]),u("fd_filestat_set_size",(function(t,e){const n=Z.get(this).fds.get(t,E.FD_FILESTAT_SET_SIZE,BigInt(0));return Q(this).ftruncateSync(n.fd,Number(e)),0}),(async function(t,e){const n=Z.get(this).fds.get(t,E.FD_FILESTAT_SET_SIZE,BigInt(0)).fd;return await n.truncate(Number(e)),0}),["i32","i64"],["i32"]),u("fd_filestat_set_times",(function(t,e,n,r){const{fileDescriptor:i,atim:s,mtim:o}=c.call(this,t,e,n,r);return Q(this).futimesSync(i.fd,Number(s),Number(o)),0}),(async function(t,e,n,r){const{fileDescriptor:i,atim:s,mtim:o}=c.call(this,t,e,n,r),a=i.fd;return await a.utimes(Number(s),Number(o)),0}),["i32","i64","i64","i32"],["i32"]),u("fd_pread",(function(t,e,n,r,i){if(e=Number(e),i=Number(i),0===e||0===i)return 28;const{HEAPU8:s,view:o}=X(this),a=Z.get(this).fds.get(t,E.FD_READ|E.FD_SEEK,BigInt(0));let u=0;const c=Array.from({length:Number(n)},((t,n)=>{const r=e+8*n,i=o.getInt32(r,!0),a=o.getUint32(r+4,!0);return u+=a,s.subarray(i,i+a)}));let f=0;const h=new Uint8Array(u);h._isBuffer=!0;const d=Q(this).readSync(a.fd,h,0,h.length,Number(r));return f=h?$(c,h.subarray(0,d)):0,o.setUint32(i,f,!0),0}),(async function(t,e,n,r,i){if(e=Number(e),i=Number(i),0===e||0===i)return 28;const{HEAPU8:s,view:o}=X(this),a=Z.get(this).fds.get(t,E.FD_READ|E.FD_SEEK,BigInt(0));let u=0;const c=Array.from({length:Number(n)},((t,n)=>{const r=e+8*n,i=o.getInt32(r,!0),a=o.getUint32(r+4,!0);return u+=a,s.subarray(i,i+a)}));let f=0;const h=new Uint8Array(u);h._isBuffer=!0;const{bytesRead:d}=await a.fd.read(h,0,h.length,Number(r));return f=h?$(c,h.subarray(0,d)):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||0===i)return 28;const{HEAPU8:s,view:o}=X(this),a=Z.get(this).fds.get(t,E.FD_WRITE|E.FD_SEEK,BigInt(0)),u=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 s.subarray(i,i+a)}))),c=Q(this).writeSync(a.fd,u,0,u.length,Number(r));return o.setUint32(i,c,!0),0}),(async function(t,e,n,r,i){if(e=Number(e),i=Number(i),0===e||0===i)return 28;const{HEAPU8:s,view:o}=X(this),a=Z.get(this).fds.get(t,E.FD_WRITE|E.FD_SEEK,BigInt(0)),u=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 s.subarray(i,i+a)}))),{bytesWritten:c}=await a.fd.write(u,0,u.length,Number(r));return o.setUint32(i,c,!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||0===r)return 28;const{HEAPU8:i,view:s}=X(this),o=Z.get(this).fds.get(t,E.FD_READ,BigInt(0));let a=0;const u=Array.from({length:Number(n)},((t,n)=>{const r=e+8*n,o=s.getInt32(r,!0),u=s.getUint32(r+4,!0);return a+=u,i.subarray(o,o+u)}));let c,f=0;if(0===t){if("undefined"==typeof window||"function"!=typeof window.prompt)return 58;c=st(),f=c?$(u,c):0}else{c=new Uint8Array(a),c._isBuffer=!0;const t=Q(this).readSync(o.fd,c,0,c.length,Number(o.pos));f=c?$(u,c.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||0===r)return 28;const{HEAPU8:i,view:s}=X(this),o=Z.get(this).fds.get(t,E.FD_READ,BigInt(0));let a=0;const u=Array.from({length:Number(n)},((t,n)=>{const r=e+8*n,o=s.getInt32(r,!0),u=s.getUint32(r+4,!0);return a+=u,i.subarray(o,o+u)}));let c,f=0;if(0===t){if("undefined"==typeof window||"function"!=typeof window.prompt)return 58;c=st(),f=c?$(u,c):0}else{c=new Uint8Array(a),c._isBuffer=!0;const{bytesRead:t}=await o.fd.read(c,0,c.length,Number(o.pos));f=c?$(u,c.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=Z.get(this).fds.get(t,E.FD_READDIR,BigInt(0)),o=Q(this),a=o.readdirSync(s.realPath,{withFileTypes:!0}),{HEAPU8:u,view:c}=X(this);let f=0;for(let t=Number(r);t<a.length;t++){const r=rt.encode(a[t].name),i=o.statSync(y(s.realPath,a[t].name),{bigint:!0}),c=new Uint8Array(24+r.byteLength),h=new DataView(c.buffer);let d;h.setBigUint64(0,BigInt(t+1),!0),h.setBigUint64(8,BigInt(i.ino?i.ino:0),!0),h.setUint32(16,r.byteLength,!0),d=a[t].isFile()?4:a[t].isDirectory()?3:a[t].isSymbolicLink()?7:a[t].isCharacterDevice()?2:a[t].isBlockDevice()?1:a[t].isSocket()?6:0,h.setUint8(20,d),c.set(r,24);const g=c.slice(0,Math.min(c.length,n-f));u.set(g,e+f),f+=g.byteLength}return c.setUint32(i,f,!0),0}),(async function(t,e,n,r,i){if(e=Number(e),n=Number(n),i=Number(i),0===e||0===i)return 0;const s=Z.get(this).fds.get(t,E.FD_READDIR,BigInt(0)),o=Q(this),a=await o.promises.readdir(s.realPath,{withFileTypes:!0}),{HEAPU8:u,view:c}=X(this);let f=0;for(let t=Number(r);t<a.length;t++){const r=rt.encode(a[t].name),i=await o.promises.stat(y(s.realPath,a[t].name),{bigint:!0}),c=new Uint8Array(24+r.byteLength),h=new DataView(c.buffer);let d;h.setBigUint64(0,BigInt(t+1),!0),h.setBigUint64(8,BigInt(i.ino?i.ino:0),!0),h.setUint32(16,r.byteLength,!0),d=a[t].isFile()?4:a[t].isDirectory()?3:a[t].isSymbolicLink()?7:a[t].isCharacterDevice()?2:a[t].isBlockDevice()?1:a[t].isSocket()?6:0,h.setUint8(20,d),c.set(r,24);const g=c.slice(0,Math.min(c.length,n-f));u.set(g,e+f),f+=g.byteLength}return c.setUint32(i,f,!0),0}),["i32","i32","i32","i64","i32"],["i32"]),u("fd_renumber",(function(t,e){return Z.get(this).fds.renumber(e,t),0}),(async function(t,e){const n=Z.get(this);return await n.fds.renumber(e,t),0}),["i32","i32"],["i32"]),u("fd_sync",(function(t){const e=Z.get(this).fds.get(t,E.FD_SYNC,BigInt(0));return Q(this).fsyncSync(e.fd),0}),(async function(t){const e=Z.get(this).fds.get(t,E.FD_SYNC,BigInt(0));return await e.fd.sync(),0}),["i32"],["i32"]),u("fd_write",(function(t,e,n,r){if(e=Number(e),r=Number(r),0===e||0===r)return 28;const{HEAPU8:i,view:s}=X(this),o=Z.get(this).fds.get(t,E.FD_WRITE,BigInt(0)),a=U(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 u;if(1===t||2===t)u=o.write(a);else{u=Q(this).writeSync(o.fd,a,0,a.length,Number(o.pos)),o.pos+=BigInt(u)}return s.setUint32(r,u,!0),0}),(async function(t,e,n,r){if(e=Number(e),r=Number(r),0===e||0===r)return 28;const{HEAPU8:i,view:s}=X(this),o=Z.get(this).fds.get(t,E.FD_WRITE,BigInt(0)),a=U(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 u;return 1===t||2===t?u=o.write(a):(u=await(await o.fd.write(a,0,a.length,Number(o.pos))).bytesWritten,o.pos+=BigInt(u)),s.setUint32(r,u,!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}=X(this),i=Z.get(this).fds.get(t,E.PATH_CREATE_DIRECTORY,BigInt(0));let s=it.decode(r.subarray(e,e+n));s=y(i.realPath,s);return Q(this).mkdirSync(s),0}),(async function(t,e,n){if(e=Number(e),n=Number(n),0===e)return 28;const{HEAPU8:r}=X(this),i=Z.get(this).fds.get(t,E.PATH_CREATE_DIRECTORY,BigInt(0));let s=it.decode(r.subarray(e,e+n));s=y(i.realPath,s);const o=Q(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}=X(this),a=Z.get(this).fds.get(t,E.PATH_FILESTAT_GET,BigInt(0));let u=it.decode(s.subarray(n,n+r));const c=Q(this);let f;return u=y(a.realPath,u),f=1==(1&e)?c.statSync(u,{bigint:!0}):c.lstatSync(u,{bigint:!0}),C(o,i,f),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}=X(this),a=Z.get(this).fds.get(t,E.PATH_FILESTAT_GET,BigInt(0));let u=it.decode(s.subarray(n,n+r));const c=Q(this);let f;return u=y(a.realPath,u),f=1==(1&e)?await c.promises.stat(u,{bigint:!0}):await c.promises.lstat(u,{bigint:!0}),C(o,i,f),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;if(-16&o)return 28;const{HEAPU8:a}=X(this),u=Z.get(this).fds.get(t,E.PATH_FILESTAT_SET_TIMES,BigInt(0)),c=Q(this),f=et(c,u,it.decode(a.subarray(n,n+r)),e);return 2==(2&o)&&(i=BigInt(1e6*Date.now())),8==(8&o)&&(s=BigInt(1e6*Date.now())),c.utimesSync(f,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;if(-16&o)return 28;const{HEAPU8:a}=X(this),u=Z.get(this).fds.get(t,E.PATH_FILESTAT_SET_TIMES,BigInt(0)),c=Q(this),f=await nt(c,u,it.decode(a.subarray(n,n+r)),e);return 2==(2&o)&&(i=BigInt(1e6*Date.now())),8==(8&o)&&(s=BigInt(1e6*Date.now())),await c.promises.utimes(f,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 a=Z.get(this);let u,c;t===i?u=c=a.fds.get(t,E.PATH_LINK_SOURCE|E.PATH_LINK_TARGET,BigInt(0)):(u=a.fds.get(t,E.PATH_LINK_SOURCE,BigInt(0)),c=a.fds.get(i,E.PATH_LINK_TARGET,BigInt(0)));const{HEAPU8:f}=X(this),h=Q(this),d=et(h,u,it.decode(f.subarray(n,n+r)),e),g=y(c.realPath,it.decode(f.subarray(s,s+o)));return h.linkSync(d,g),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 a=Z.get(this);let u,c;t===i?u=c=a.fds.get(t,E.PATH_LINK_SOURCE|E.PATH_LINK_TARGET,BigInt(0)):(u=a.fds.get(t,E.PATH_LINK_SOURCE,BigInt(0)),c=a.fds.get(i,E.PATH_LINK_TARGET,BigInt(0)));const{HEAPU8:f}=X(this),h=Q(this),d=await nt(h,u,it.decode(f.subarray(n,n+r)),e),g=y(c.realPath,it.decode(f.subarray(s,s+o)));return await h.promises.link(d,g),0}),["i32","i32","i32","i32","i32","i32","i32"],["i32"]),u("path_open",(function(t,e,n,r,i,s,o,a,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:c,needed_base:h,needed_inheriting:d}=f(i,s,o,a),g=Z.get(this),l=g.fds.get(t,h,d),_=X(this),y=_.HEAPU8,E=it.decode(y.subarray(n,n+r)),p=Q(this),I=et(p,l,E,e),b=p.openSync(I,c,438),m=g.fds.getFileTypeByFd(b);if(0!=(2&i)&&3!==m)return 54;const{base:A,inheriting:T}=v(g.fds.stdio,b,c,m),w=g.fds.insert(b,I,I,m,s&A,o&T,0),N=p.fstatSync(b,{bigint:!0});N.isFile()&&(w.size=N.size,0!=(1024&c)&&(w.pos=N.size));return _.view.setInt32(u,w.id,!0),0}),(async function(t,e,n,r,i,s,o,a,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:c,needed_base:h,needed_inheriting:d}=f(i,s,o,a),g=Z.get(this),l=g.fds.get(t,h,d),_=X(this),y=_.HEAPU8,E=it.decode(y.subarray(n,n+r)),p=Q(this),I=await nt(p,l,E,e),b=await p.promises.open(I,c,438),m=await g.fds.getFileTypeByFd(b);if(0!=(2&i)&&3!==m)return 54;const{base:A,inheriting:T}=v(g.fds.stdio,b.fd,c,m),w=g.fds.insert(b,I,I,m,s&A,o&T,0),N=await b.stat({bigint:!0});N.isFile()&&(w.size=N.size,0!=(1024&c)&&(w.pos=N.size));return _.view.setInt32(u,w.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:a}=X(this),u=Z.get(this).fds.get(t,E.PATH_READLINK,BigInt(0));let c=it.decode(o.subarray(e,e+n));c=y(u.realPath,c);const f=Q(this).readlinkSync(c),h=rt.encode(f),d=Math.min(h.length,i);return d>=i?42:(o.set(h.subarray(0,d),r),o[r+d]=0,a.setUint32(s,d+1,!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:a}=X(this),u=Z.get(this).fds.get(t,E.PATH_READLINK,BigInt(0));let c=it.decode(o.subarray(e,e+n));c=y(u.realPath,c);const f=Q(this),h=await f.promises.readlink(c),d=rt.encode(h),g=Math.min(d.length,i);return g>=i?42:(o.set(d.subarray(0,g),r),o[r+g]=0,a.setUint32(s,g+1,!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}=X(this),i=Z.get(this).fds.get(t,E.PATH_REMOVE_DIRECTORY,BigInt(0));let s=it.decode(r.subarray(e,e+n));s=y(i.realPath,s);return Q(this).rmdirSync(s),0}),(async function(t,e,n){if(e=Number(e),n=Number(n),0===e)return 28;const{HEAPU8:r}=X(this),i=Z.get(this).fds.get(t,E.PATH_REMOVE_DIRECTORY,BigInt(0));let s=it.decode(r.subarray(e,e+n));s=y(i.realPath,s);const o=Q(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=Z.get(this);let a,u;t===r?a=u=o.fds.get(t,E.PATH_RENAME_SOURCE|E.PATH_RENAME_TARGET,BigInt(0)):(a=o.fds.get(t,E.PATH_RENAME_SOURCE,BigInt(0)),u=o.fds.get(r,E.PATH_RENAME_TARGET,BigInt(0)));const{HEAPU8:c}=X(this),f=y(a.realPath,it.decode(c.subarray(e,e+n))),h=y(u.realPath,it.decode(c.subarray(i,i+s)));return Q(this).renameSync(f,h),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=Z.get(this);let a,u;t===r?a=u=o.fds.get(t,E.PATH_RENAME_SOURCE|E.PATH_RENAME_TARGET,BigInt(0)):(a=o.fds.get(t,E.PATH_RENAME_SOURCE,BigInt(0)),u=o.fds.get(r,E.PATH_RENAME_TARGET,BigInt(0)));const{HEAPU8:c}=X(this),f=y(a.realPath,it.decode(c.subarray(e,e+n))),h=y(u.realPath,it.decode(c.subarray(i,i+s))),d=Q(this);return await d.promises.rename(f,h),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}=X(this),o=Z.get(this).fds.get(n,E.PATH_SYMLINK,BigInt(0)),a=it.decode(s.subarray(t,t+e));let u=it.decode(s.subarray(r,r+i));u=y(o.realPath,u);return Q(this).symlinkSync(a,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}=X(this),o=Z.get(this).fds.get(n,E.PATH_SYMLINK,BigInt(0)),a=it.decode(s.subarray(t,t+e));let u=it.decode(s.subarray(r,r+i));u=y(o.realPath,u);const c=Q(this);return await c.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:r}=X(this),i=Z.get(this).fds.get(t,E.PATH_UNLINK_FILE,BigInt(0));let s=it.decode(r.subarray(e,e+n));s=y(i.realPath,s);return Q(this).unlinkSync(s),0}),(async function(t,e,n){if(e=Number(e),n=Number(n),0===e)return 28;const{HEAPU8:r}=X(this),i=Z.get(this).fds.get(t,E.PATH_UNLINK_FILE,BigInt(0));let s=it.decode(r.subarray(e,e+n));s=y(i.realPath,s);const o=Q(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');V.set(a,W(t))}}static createSync(t,e,n,r,i,s,o){const a=new x({size:3,in:r[0],out:r[1],err:r[2],fs:i,print:s,printErr:o}),u=new ot(t,e,a,!1,i);if(n.length>0)for(let t=0;t<n.length;++t){const e=i.realpathSync(n[t].realPath,"utf8"),r=i.openSync(e,"r",438);a.insertPreopen(r,n[t].mappedPath,e)}return u}static async createAsync(t,e,n,r,i,s,o,a){const u=new M({size:3,in:r[0],out:r[1],err:r[2],print:s,printErr:o}),c=new ot(t,e,u,!0,i,a);if(n.length>0)for(let t=0;t<n.length;++t){const e=n[t],r=await i.promises.realpath(e.realPath),s=await i.promises.open(r,"r",438);await u.insertPreopen(s,e.mappedPath,r)}return c}}const at=Object.freeze(Object.create(null)),ut=Symbol("kExitCode"),ct=Symbol("kSetMemory"),ft=Symbol("kStarted"),ht=Symbol("kInstance");function dt(t,e){n(e,"instance"),n(e.exports,"instance.exports"),t[ht]=e,t[ct](e.exports.memory)}function gt(t){var e;n(t,"options"),void 0!==t.args&&function(t,e){if(!Array.isArray(t))throw new TypeError(`${e} must be an array. Received ${null===t?"null":typeof t}`)}(t.args,"options.args");const r=(null!==(e=t.args)&&void 0!==e?e:[]).map(String),s=[];void 0!==t.env&&(n(t.env,"options.env"),Object.entries(t.env).forEach((({0:t,1:e})=>{void 0!==e&&s.push(`${t}=${e}`)})));const o=[];if(void 0!==t.preopens&&(n(t.preopens,"options.preopens"),Object.entries(t.preopens).forEach((({0:t,1:e})=>o.push({mappedPath:String(t),realPath:String(e)})))),o.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&&i(t.print,"options.print"),void 0!==t.printErr&&i(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:r,env:s,preopens:o,stdio:[0,1,2]}}class lt{constructor(t,e){this[ct]=t,this.wasiImport=e,this[ft]=!1,this[ut]=0,this[ht]=void 0}static createSync(t=at){const{args:e,env:n,preopens:r,stdio:i}=gt(t),s=ot.createSync(e,n,r,i,t.fs,t.print,t.printErr),o=s._setMemory;delete s._setMemory;const a=new lt(o,s);return t.returnOnExit&&(s.proc_exit=_t.bind(a)),a}static async createAsync(t=at){const{args:e,env:r,preopens:s,stdio:o}=gt(t);void 0!==t.asyncify&&(n(t.asyncify,"options.asyncify"),i(t.asyncify.wrapImportFunction,"options.asyncify.wrapImportFunction"));const a=await ot.createAsync(e,r,s,o,t.fs,t.print,t.printErr,t.asyncify),u=a._setMemory;delete a._setMemory;const c=new lt(u,a);return t.returnOnExit&&(a.proc_exit=_t.bind(c)),c}start(t){if(this[ft])throw new Error("WASI instance has already started");this[ft]=!0,dt(this,t);const{_start:e,_initialize:n}=this[ht].exports;let r;i(e,"instance.exports._start"),s(n,"instance.exports._initialize");try{r=e()}catch(t){if(t!==ut)throw t}return r instanceof Promise?r.then((()=>this[ut]),(t=>{if(t!==ut)throw t;return this[ut]})):this[ut]}initialize(t){if(this[ft])throw new Error("WASI instance has already started");this[ft]=!0,dt(this,t);const{_start:e,_initialize:n}=this[ht].exports;if(s(e,"instance.exports._start"),void 0!==n)return i(n,"instance.exports._initialize"),n()}}function _t(t){throw this[ut]=t,ut}t.Asyncify=f,t.Memory=z,t.WASI=lt,t.WebAssemblyMemory=K,t.asyncifyLoad=async function(t,e,n){var r;h(n),n=null!=n?n:{};const i=new f;n=i.wrapImports(n);const s=await g(e,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)}},t.asyncifyLoadSync=function(t,e,n){var r;h(n),n=null!=n?n:{};const i=new f,s=l(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)}},t.extendMemory=W,t.load=g,t.loadSync=l,t.wrapAsyncExport=j,t.wrapAsyncImport=Y,t.wrapExports=function(t,e){return a(t,((t,n)=>{let r="function"!=typeof t;return Array.isArray(e)&&(r=r||-1===e.indexOf(n)),r?t:j(t)}))},Object.defineProperty(t,"__esModule",{value:!0})}));
1
+ !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 r(t,e){if("string"!=typeof t)throw new TypeError(`${e} must be a string. Received ${null===t?"null":typeof t}`)}function i(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((r=>{const i=t[r];Object.defineProperty(n,r,{enumerable:!0,value:e(i,r)})})),n}const u=["asyncify_get_state","asyncify_start_rewind","asyncify_start_unwind","asyncify_stop_rewind","asyncify_stop_unwind"];function c(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(t,n,r){var i,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<u.length;++t)if("function"!=typeof o[u[t]])throw new TypeError("Invalid asyncify wasm");let a;const f=Boolean(r.wasm64);a=r.tryAllocate?!0===r.tryAllocate?c(n,f,4096,"malloc"):c(n,f,null!==(i=r.tryAllocate.size)&&void 0!==i?i:4096,null!==(s=r.tryAllocate.name)&&void 0!==s?s:"malloc"):{wasm64:f,dataPtr:16,start:f?32:24,end:1024},this.dataPtr=a.dataPtr,f?new BigInt64Array(t.buffer,this.dataPtr).set([BigInt(a.start),BigInt(a.end)]):new Int32Array(t.buffer,this.dataPtr).set([a.start,a.end]),this.exports=this.wrapExports(o,r.wrapExports);const h=Object.create(e.Instance.prototype);return Object.defineProperty(h,"exports",{value:this.exports}),h}assertState(){if(0!==this.exports.asyncify_get_state())throw new Error("Asyncify state error")}wrapImportFunction(t){const e=this;return function(){for(;2===e.exports.asyncify_get_state();)return e.exports.asyncify_stop_rewind(),e.value;e.assertState();const n=t.apply(this,arguments);if(!o(n))return n;e.exports.asyncify_start_unwind(e.dataPtr),e.value=n}}wrapImports(t){const e={};return Object.keys(t).forEach((n=>{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 a(t,((t,n)=>{let r=-1!==u.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 d(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 g(t,n){let r;if(h(n),n=null!=n?n:{},t instanceof ArrayBuffer||ArrayBuffer.isView(t))return e.instantiate(t,n);if("string"!=typeof t&&!(t instanceof URL))throw new TypeError("Invalid source");if("function"==typeof e.instantiateStreaming){let i;try{i=fetch(t),r=e.instantiateStreaming(i,n).catch((()=>d(t,n)))}catch(e){r=d(t,n)}}else r=d(t,n);return r}function l(t,n){if(t instanceof ArrayBuffer&&!ArrayBuffer.isView(t))throw new TypeError("Invalid source");h(n),n=null!=n?n:{};const r=new e.Module(t);return{instance:new e.Instance(r,n),module:r}}function _(t){return 47===t}function y(...t){let e="",n=!1;for(let i=t.length-1;i>=-1&&!n;i--){const s=i>=0?t[i]:"/";r(s,"path"),0!==s.length&&(e=`${s}/${e}`,n=47===s.charCodeAt(0))}return e=function(t,e,n,r){let i="",s=0,o=-1,a=0,u=0;for(let c=0;c<=t.length;++c){if(c<t.length)u=t.charCodeAt(c);else{if(r(u))break;u=47}if(r(u)){if(o===c-1||1===a);else if(2===a){if(i.length<2||2!==s||46!==i.charCodeAt(i.length-1)||46!==i.charCodeAt(i.length-2)){if(i.length>2){const t=i.indexOf(n);-1===t?(i="",s=0):(i=i.slice(0,t),s=i.length-1-i.indexOf(n)),o=c,a=0;continue}if(0!==i.length){i="",s=0,o=c,a=0;continue}}e&&(i+=i.length>0?`${n}..`:"..",s=2)}else i.length>0?i+=`${n}${t.slice(o+1,c)}`:i=t.slice(o+1,c),s=c-o-1;o=c,a=0}else 46===u&&-1!==a?++a:a=-1}return i}(e,!n,"/",_),n?`/${e}`:e.length>0?e:"."}const E={FD_DATASYNC:BigInt(1)<<BigInt(0),FD_READ:BigInt(1)<<BigInt(1),FD_SEEK:BigInt(1)<<BigInt(2),FD_FDSTAT_SET_FLAGS:BigInt(1)<<BigInt(3),FD_SYNC:BigInt(1)<<BigInt(4),FD_TELL:BigInt(1)<<BigInt(5),FD_WRITE:BigInt(1)<<BigInt(6),FD_ADVISE:BigInt(1)<<BigInt(7),FD_ALLOCATE:BigInt(1)<<BigInt(8),PATH_CREATE_DIRECTORY:BigInt(1)<<BigInt(9),PATH_CREATE_FILE:BigInt(1)<<BigInt(10),PATH_LINK_SOURCE:BigInt(1)<<BigInt(11),PATH_LINK_TARGET:BigInt(1)<<BigInt(12),PATH_OPEN:BigInt(1)<<BigInt(13),FD_READDIR:BigInt(1)<<BigInt(14),PATH_READLINK:BigInt(1)<<BigInt(15),PATH_RENAME_SOURCE:BigInt(1)<<BigInt(16),PATH_RENAME_TARGET:BigInt(1)<<BigInt(17),PATH_FILESTAT_GET:BigInt(1)<<BigInt(18),PATH_FILESTAT_SET_SIZE:BigInt(1)<<BigInt(19),PATH_FILESTAT_SET_TIMES:BigInt(1)<<BigInt(20),FD_FILESTAT_GET:BigInt(1)<<BigInt(21),FD_FILESTAT_SET_SIZE:BigInt(1)<<BigInt(22),FD_FILESTAT_SET_TIMES:BigInt(1)<<BigInt(23),PATH_SYMLINK:BigInt(1)<<BigInt(24),PATH_REMOVE_DIRECTORY:BigInt(1)<<BigInt(25),PATH_UNLINK_FILE:BigInt(1)<<BigInt(26),POLL_FD_READWRITE:BigInt(1)<<BigInt(27),SOCK_SHUTDOWN:BigInt(1)<<BigInt(28),SOCK_ACCEPT:BigInt(1)<<BigInt(29)};class p extends Error{constructor(t,e){super(t),this.errno=e}getErrorMessage(){return function(t){switch(t){case 0:return"Success";case 1:return"Argument list too long";case 2:return"Permission denied";case 3:return"Address in use";case 4:return"Address not available";case 5:return"Address family not supported by protocol";case 6:return"Resource temporarily unavailable";case 7:return"Operation already in progress";case 8:return"Bad file descriptor";case 9:return"Bad message";case 10:return"Resource busy";case 11:return"Operation canceled";case 12:return"No child process";case 13:return"Connection aborted";case 14:return"Connection refused";case 15:return"Connection reset by peer";case 16:return"Resource deadlock would occur";case 17:return"Destination address required";case 18:return"Domain error";case 19:return"Quota exceeded";case 20:return"File exists";case 21:return"Bad address";case 22:return"File too large";case 23:return"Host is unreachable";case 24:return"Identifier removed";case 25:return"Illegal byte sequence";case 26:return"Operation in progress";case 27:return"Interrupted system call";case 28:return"Invalid argument";case 29:return"I/O error";case 30:return"Socket is connected";case 31:return"Is a directory";case 32:return"Symbolic link loop";case 33:return"No file descriptors available";case 34:return"Too many links";case 35:return"Message too large";case 36:return"Multihop attempted";case 37:return"Filename too long";case 38:return"Network is down";case 39:return"Connection reset by network";case 40:return"Network unreachable";case 41:return"Too many files open in system";case 42:return"No buffer space available";case 43:return"No such device";case 44:return"No such file or directory";case 45:return"Exec format error";case 46:return"No locks available";case 47:return"Link has been severed";case 48:return"Out of memory";case 49:return"No message of the desired type";case 50:return"Protocol not available";case 51:return"No space left on device";case 52:return"Function not implemented";case 53:return"Socket not connected";case 54:return"Not a directory";case 55:return"Directory not empty";case 56:return"State not recoverable";case 57:return"Not a socket";case 58:return"Not supported";case 59:return"Not a tty";case 60:return"No such device or address";case 61:return"Value too large for data type";case 62:return"Previous owner died";case 63:return"Operation not permitted";case 64:return"Broken pipe";case 65:return"Protocol error";case 66:return"Protocol not supported";case 67:return"Protocol wrong type for socket";case 68:return"Result not representable";case 69:return"Read-only file system";case 70:return"Invalid seek";case 71:return"No such process";case 72:return"Stale file handle";case 73:return"Operation timed out";case 74:return"Text file busy";case 75:return"Cross-device link";case 76:return"Capabilities insufficient";default:return"Unknown error"}}(this.errno)}}Object.defineProperty(p.prototype,"name",{configurable:!0,writable:!0,value:"WasiError"});const I=E.FD_DATASYNC|E.FD_READ|E.FD_SEEK|E.FD_FDSTAT_SET_FLAGS|E.FD_SYNC|E.FD_TELL|E.FD_WRITE|E.FD_ADVISE|E.FD_ALLOCATE|E.PATH_CREATE_DIRECTORY|E.PATH_CREATE_FILE|E.PATH_LINK_SOURCE|E.PATH_LINK_TARGET|E.PATH_OPEN|E.FD_READDIR|E.PATH_READLINK|E.PATH_RENAME_SOURCE|E.PATH_RENAME_TARGET|E.PATH_FILESTAT_GET|E.PATH_FILESTAT_SET_SIZE|E.PATH_FILESTAT_SET_TIMES|E.FD_FILESTAT_GET|E.FD_FILESTAT_SET_TIMES|E.FD_FILESTAT_SET_SIZE|E.PATH_SYMLINK|E.PATH_UNLINK_FILE|E.PATH_REMOVE_DIRECTORY|E.POLL_FD_READWRITE|E.SOCK_SHUTDOWN,b=I,m=I,A=I,T=I,w=E.FD_DATASYNC|E.FD_READ|E.FD_SEEK|E.FD_FDSTAT_SET_FLAGS|E.FD_SYNC|E.FD_TELL|E.FD_WRITE|E.FD_ADVISE|E.FD_ALLOCATE|E.FD_FILESTAT_GET|E.FD_FILESTAT_SET_SIZE|E.FD_FILESTAT_SET_TIMES|E.POLL_FD_READWRITE,N=BigInt(0),B=E.FD_FDSTAT_SET_FLAGS|E.FD_SYNC|E.FD_ADVISE|E.PATH_CREATE_DIRECTORY|E.PATH_CREATE_FILE|E.PATH_LINK_SOURCE|E.PATH_LINK_TARGET|E.PATH_OPEN|E.FD_READDIR|E.PATH_READLINK|E.PATH_RENAME_SOURCE|E.PATH_RENAME_TARGET|E.PATH_FILESTAT_GET|E.PATH_FILESTAT_SET_SIZE|E.PATH_FILESTAT_SET_TIMES|E.FD_FILESTAT_GET|E.FD_FILESTAT_SET_TIMES|E.PATH_SYMLINK|E.PATH_UNLINK_FILE|E.PATH_REMOVE_DIRECTORY|E.POLL_FD_READWRITE,S=B|w,P=E.FD_READ|E.FD_FDSTAT_SET_FLAGS|E.FD_WRITE|E.FD_FILESTAT_GET|E.POLL_FD_READWRITE|E.SOCK_SHUTDOWN,D=I,F=E.FD_READ|E.FD_FDSTAT_SET_FLAGS|E.FD_WRITE|E.FD_FILESTAT_GET|E.POLL_FD_READWRITE,R=BigInt(0);function v(t,e,n,r){const i={base:BigInt(0),inheriting:BigInt(0)};if(0===r)throw new p("Unknown file type",28);switch(r){case 4:i.base=w,i.inheriting=N;break;case 3:i.base=B,i.inheriting=S;break;case 6:case 5:i.base=P,i.inheriting=D;break;case 2:-1!==t.indexOf(e)?(i.base=F,i.inheriting=R):(i.base=A,i.inheriting=T);break;case 1:i.base=b,i.inheriting=m;break;default:i.base=BigInt(0),i.inheriting=BigInt(0)}const s=3&n;return 0===s?i.base&=~E.FD_WRITE:1===s&&(i.base&=~E.FD_READ),i}function U(t,e){let n=0;if("number"==typeof e&&e>=0)n=e;else for(let e=0;e<t.length;e++){n+=t[e].length}let r=0;const i=new Uint8Array(n);for(let e=0;e<t.length;e++){const n=t[e];i.set(n,r),r+=n.length}return i}class L{constructor(t,e,n,r,i,s,o,a){this.id=t,this.fd=e,this.path=n,this.realPath=r,this.type=i,this.rightsBase=s,this.rightsInheriting=o,this.preopen=a,this.pos=BigInt(0),this.size=BigInt(0)}seek(t,e){if(0===e)this.pos=BigInt(t);else if(1===e)this.pos+=BigInt(t);else{if(2!==e)throw new p("Unknown whence",29);this.pos=BigInt(this.size)-BigInt(t)}return this.pos}}class H extends L{constructor(t,e,n,r,i,s,o,a,u){super(e,n,r,i,s,o,a,u),this._log=t,this._buf=null}write(t){const e=t;if(this._buf&&(t=U([this._buf,t]),this._buf=null),-1===t.indexOf(10))return this._buf=t,e.byteLength;let n,r=0,i=0;for(;-1!==(n=t.indexOf(10,r));){const e=(new TextDecoder).decode(t.subarray(i,n));this._log(e),r+=n-i+1,i=n+1}return r<t.length&&(this._buf=t.slice(r)),e.byteLength}}function O(t){return t.isBlockDevice()?1:t.isCharacterDevice()?2:t.isDirectory()?3:t.isSocket()?6:t.isFile()?4:t.isSymbolicLink()?7:0}function C(t,e,n){t.setBigUint64(e,n.dev,!0),t.setBigUint64(e+8,n.ino,!0),t.setBigUint64(e+16,BigInt(O(n)),!0),t.setBigUint64(e+24,n.nlink,!0),t.setBigUint64(e+32,n.size,!0),t.setBigUint64(e+40,n.atimeMs*BigInt(1e6),!0),t.setBigUint64(e+48,n.mtimeMs*BigInt(1e6),!0),t.setBigUint64(e+56,n.ctimeMs*BigInt(1e6),!0)}class k{constructor(t){this.used=0,this.size=t.size,this.fds=Array(t.size),this.stdio=[t.in,t.out,t.err],this.print=t.print,this.printErr=t.printErr,this.insertStdio(t.in,0,"<stdin>"),this.insertStdio(t.out,1,"<stdout>"),this.insertStdio(t.err,2,"<stderr>")}insertStdio(t,e,n){const{base:r,inheriting:i}=v(this.stdio,t,2,2),s=this.insert(t,n,n,2,r,i,0);if(s.id!==e)throw new p(`id: ${s.id} !== expected: ${e}`,8);return s}insert(t,e,n,r,i,s,o){var a,u;let c,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<this.size;++t)if(null==this.fds[t]){f=t;break}return c="<stdout>"===e?new H(null!==(a=this.print)&&void 0!==a?a:console.log,f,t,e,n,r,i,s,o):"<stderr>"===e?new H(null!==(u=this.printErr)&&void 0!==u?u:console.error,f,t,e,n,r,i,s,o):new L(f,t,e,n,r,i,s,o),this.fds[f]=c,this.used++,c}get(t,e,n){if(t>=this.size)throw new p("Invalid fd",8);const r=this.fds[t];if(!r||r.id!==t)throw new p("Bad file descriptor",8);if((~r.rightsBase&e)!==BigInt(0)||(~r.rightsInheriting&n)!==BigInt(0))throw new p("Capabilities insufficient",76);return r}remove(t){if(t>=this.size)throw new p("Invalid fd",8);const e=this.fds[t];if(!e||e.id!==t)throw new p("Bad file descriptor",8);this.fds[t]=void 0,this.used--}}class x extends k{constructor(t){super(t),this.fs=t.fs}getFileTypeByFd(t){return O(this.fs.fstatSync(t,{bigint:!0}))}insertPreopen(t,e,n){const r=this.getFileTypeByFd(t);if(3!==r)throw new p(`Preopen not dir: ["${e}", "${n}"]`,54);const i=v(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 p("Invalid fd",8);const n=this.fds[t],r=this.fds[e];if(!n||!r||n.id!==t||r.id!==e)throw new p("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 M extends k{constructor(t){super(t)}async getFileTypeByFd(t){return O(await t.stat({bigint:!0}))}async insertPreopen(t,e,n){const r=await this.getFileTypeByFd(t);if(3!==r)throw new p(`Preopen not dir: ["${e}", "${n}"]`,54);const i=v(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 p("Invalid fd",8);const n=this.fds[t],r=this.fds[e];if(!n||!r||n.id!==t||r.id!==e)throw new p("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 K=function(){return e.Memory}();class z extends K{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 W(t){return Object.getPrototypeOf(t)===e.Memory.prototype&&Object.setPrototypeOf(t,z.prototype),t}function G(){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-flag="--wasm-staging --experimental-wasm-stack-switching"');return t}function Y(t,e,n){const r=G();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 j(t){const e=G();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 $(t,e){if(0===t.length||0===e.length)return 0;let n=0,r=e.length-n;for(let i=0;i<t.length;++i){const s=t[i];if(r<s.length)return s.set(e.subarray(n,n+r),0),n+=r,r=0,n;s.set(e.subarray(n,n+s.length),0),n+=s.length,r-=s.length}return n}const V=new WeakMap,Z=new WeakMap,q=new WeakMap;function X(t){return V.get(t)}function Q(t){const e=q.get(t);if(!e)throw new Error("filesystem is unavailable");return e}function J(t){if(t instanceof p)return t.errno;switch(t.code){case"ENOENT":return 44;case"EBADF":return 8;case"EINVAL":return 28;case"EPERM":return 63;case"EPROTO":return 65;case"EEXIST":return 20;case"ENOTDIR":return 54;case"EMFILE":return 33;case"EACCES":return 2;case"EISDIR":return 31;case"ENOTEMPTY":return 55;case"ENOSYS":return 52}throw t}function tt(t,e,n){return function(t,e){return Object.defineProperty(e,"name",{value:t}),e}(e,(function(){let e;try{e=n.apply(t,arguments)}catch(t){return J(t)}return o(e)?e.then((t=>t),J):e}))}function et(t,e,n,r){let i=y(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 nt(t,e,n,r){let i=y(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 rt=new TextEncoder,it=new TextDecoder;function st(){const t=window.prompt();if(null===t)return new Uint8Array;return(new TextEncoder).encode(t+"\n")}class ot{constructor(t,n,r,i,s,o){this.args_get=tt(this,"args_get",(function(t,e){if(t=Number(t),e=Number(e),0===t||0===e)return 28;const{HEAPU8:n,view:r}=X(this),i=Z.get(this).args;for(let s=0;s<i.length;++s){const o=i[s];r.setInt32(t,e,!0),t+=4;const a=rt.encode(o+"\0");n.set(a,e),e+=a.length}return 0})),this.args_sizes_get=tt(this,"args_sizes_get",(function(t,e){if(t=Number(t),e=Number(e),0===t||0===e)return 28;const{view:n}=X(this),r=Z.get(this).args;return n.setUint32(t,r.length,!0),n.setUint32(e,rt.encode(r.join("\0")+"\0").length,!0),0})),this.environ_get=tt(this,"environ_get",(function(t,e){if(t=Number(t),e=Number(e),0===t||0===e)return 28;const{HEAPU8:n,view:r}=X(this),i=Z.get(this).env;for(let s=0;s<i.length;++s){const o=i[s];r.setInt32(t,e,!0),t+=4;const a=rt.encode(o+"\0");n.set(a,e),e+=a.length}return 0})),this.environ_sizes_get=tt(this,"environ_sizes_get",(function(t,e){if(t=Number(t),e=Number(e),0===t||0===e)return 28;const{view:n}=X(this),r=Z.get(this);return n.setUint32(t,r.env.length,!0),n.setUint32(e,rt.encode(r.env.join("\0")+"\0").length,!0),0})),this.clock_res_get=tt(this,"clock_res_get",(function(t,e){if(0===(e=Number(e)))return 28;const{view:n}=X(this);switch(t){case 0:return n.setBigUint64(e,BigInt(1e6),!0),0;case 1:case 2:case 3:return n.setBigUint64(e,BigInt(1e3),!0),0;default:return 28}})),this.clock_time_get=tt(this,"clock_time_get",(function(t,e,n){if(0===(n=Number(n)))return 28;const{view:r}=X(this);switch(t){case 0:return r.setBigUint64(n,BigInt(Date.now())*BigInt(1e6),!0),0;case 1:case 2:case 3:{const t=performance.now(),e=Math.trunc(t),i=Math.floor(1e3*(t-e)),s=BigInt(e)*BigInt(1e9)+BigInt(i)*BigInt(1e6);return r.setBigUint64(n,s,!0),0}default:return 28}})),this.fd_advise=tt(this,"fd_advise",(function(t,e,n,r){return 52})),this.fd_fdstat_get=tt(this,"fd_fdstat_get",(function(t,e){if(0===(e=Number(e)))return 28;const n=Z.get(this).fds.get(t,BigInt(0),BigInt(0)),{view:r}=X(this);return r.setUint16(e,n.type,!0),r.setUint16(e+2,0,!0),r.setBigUint64(e+8,n.rightsBase,!0),r.setBigUint64(e+16,n.rightsInheriting,!0),0})),this.fd_fdstat_set_flags=tt(this,"fd_fdstat_set_flags",(function(t,e){return 52})),this.fd_fdstat_set_rights=tt(this,"fd_fdstat_set_rights",(function(t,e,n){const r=Z.get(this).fds.get(t,BigInt(0),BigInt(0));return(e|r.rightsBase)>r.rightsBase||(n|r.rightsInheriting)>r.rightsInheriting?76:(r.rightsBase=e,r.rightsInheriting=n,0)})),this.fd_prestat_get=tt(this,"fd_prestat_get",(function(t,e){if(0===(e=Number(e)))return 28;const n=Z.get(this);let r;try{r=n.fds.get(t,BigInt(0),BigInt(0))}catch(t){if(t instanceof p)return t.errno;throw t}if(1!==r.preopen)return 28;const{view:i}=X(this);return i.setUint32(e,0,!0),i.setUint32(e+4,rt.encode(r.path).length+1,!0),0})),this.fd_prestat_dir_name=tt(this,"fd_prestat_dir_name",(function(t,e,n){if(e=Number(e),n=Number(n),0===e)return 28;const r=Z.get(this).fds.get(t,BigInt(0),BigInt(0));if(1!==r.preopen)return 8;const i=rt.encode(r.path+"\0");if(i.length>n)return 42;const{HEAPU8:s}=X(this);return s.set(i,e),0})),this.fd_seek=tt(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=Z.get(this).fds.get(t,E.FD_SEEK,BigInt(0)).seek(e,n),{view:s}=X(this);return s.setBigUint64(r,i,!0),0})),this.fd_tell=tt(this,"fd_tell",(function(t,e){const n=Z.get(this).fds.get(t,E.FD_TELL,BigInt(0)),r=BigInt(n.pos),{view:i}=X(this);return i.setBigUint64(Number(e),r,!0),0})),this.poll_oneoff=tt(this,"poll_oneoff",(function(t,e,n,r){return 52})),this.proc_exit=tt(this,"proc_exit",(function(t){return 0})),this.proc_raise=tt(this,"proc_raise",(function(t){return 52})),this.sched_yield=tt(this,"sched_yield",(function(){return 0})),this.random_get="undefined"!=typeof crypto&&"function"==typeof crypto.getRandomValues?tt(this,"random_get",(function(t,e){if(0===(t=Number(t)))return 28;e=Number(e);const{HEAPU8:n}=X(this);let r;const i=65536;for(r=0;r+i<e;r+=i)crypto.getRandomValues(n.subarray(t+r,t+r+i));return crypto.getRandomValues(n.subarray(t+r,t+e)),0})):tt(this,"random_get",(function(t,e){if(0===(t=Number(t)))return 28;e=Number(e);const{view:n}=X(this);for(let r=t;r<t+e;++r)n.setUint8(r,Math.floor(256*Math.random()));return 0})),this.sock_recv=tt(this,"sock_recv",(function(){return 58})),this.sock_send=tt(this,"sock_send",(function(){return 58})),this.sock_shutdown=tt(this,"sock_shutdown",(function(){return 58})),Z.set(this,{fds:r,args:t,env:n}),s&&q.set(this,s);const a=this;function u(t,e,n,r,s){a[t]=i?o?o.wrapImportFunction(tt(a,t,n)):Y(tt(a,t,n),r,s):tt(a,t,e)}function c(t,e,n,r){const i=Z.get(this).fds.get(t,E.FD_FILESTAT_SET_TIMES,BigInt(0));return 2==(2&r)&&(e=BigInt(1e6*Date.now())),8==(8&r)&&(n=BigInt(1e6*Date.now())),{fileDescriptor:i,atim:e,mtim:n}}function f(t,e,n,r){const i=(e&(E.FD_READ|E.FD_READDIR))!==BigInt(0),s=(e&(E.FD_DATASYNC|E.FD_WRITE|E.FD_ALLOCATE|E.FD_FILESTAT_SET_SIZE))!==BigInt(0);let o=s?i?2:1:0,a=E.PATH_OPEN,u=e|n;return 0!=(1&t)&&(o|=64,a|=E.PATH_CREATE_FILE),0!=(2&t)&&(o|=65536),0!=(4&t)&&(o|=128),0!=(8&t)&&(o|=512,a|=E.PATH_FILESTAT_SET_SIZE),0!=(1&r)&&(o|=1024),0!=(2&r)&&(u|=E.FD_DATASYNC),0!=(4&r)&&(o|=2048),0!=(8&r)&&(o|=1052672,u|=E.FD_SYNC),0!=(16&r)&&(o|=1052672,u|=E.FD_SYNC),s&&0==(1536&o)&&(u|=E.FD_SEEK),{flags:o,needed_base:a,needed_inheriting:u}}u("fd_allocate",(function(t,e,n){const r=Z.get(this),i=Q(this),s=r.fds.get(t,E.FD_ALLOCATE,BigInt(0));return i.fstatSync(s.fd,{bigint:!0}).size<e+n&&i.ftruncateSync(s.fd,Number(e+n)),0}),(async function(t,e,n){const r=Z.get(this).fds.get(t,E.FD_ALLOCATE,BigInt(0)).fd;return(await r.stat({bigint:!0})).size<e+n&&await r.truncate(Number(e+n)),0}),["i32","i64","f64"],["i32"]),u("fd_close",(function(t){const e=Z.get(this),n=e.fds.get(t,BigInt(0),BigInt(0));return Q(this).closeSync(n.fd),e.fds.remove(t),0}),(async function(t){const e=Z.get(this),n=e.fds.get(t,BigInt(0),BigInt(0));return await n.fd.close(),e.fds.remove(t),0}),["i32"],["i32"]),u("fd_datasync",(function(t){const e=Z.get(this).fds.get(t,E.FD_DATASYNC,BigInt(0));return Q(this).fdatasyncSync(e.fd),0}),(async function(t){const e=Z.get(this).fds.get(t,E.FD_DATASYNC,BigInt(0));return await e.fd.datasync(),0}),["i32"],["i32"]),u("fd_filestat_get",(function(t,e){if(0===(e=Number(e)))return 28;const n=Z.get(this).fds.get(t,E.FD_FILESTAT_GET,BigInt(0)),r=Q(this).fstatSync(n.fd,{bigint:!0}),{view:i}=X(this);return C(i,e,r),0}),(async function(t,e){if(0===(e=Number(e)))return 28;const n=Z.get(this).fds.get(t,E.FD_FILESTAT_GET,BigInt(0)).fd,r=await n.stat({bigint:!0}),{view:i}=X(this);return C(i,e,r),0}),["i32","i32"],["i32"]),u("fd_filestat_set_size",(function(t,e){const n=Z.get(this).fds.get(t,E.FD_FILESTAT_SET_SIZE,BigInt(0));return Q(this).ftruncateSync(n.fd,Number(e)),0}),(async function(t,e){const n=Z.get(this).fds.get(t,E.FD_FILESTAT_SET_SIZE,BigInt(0)).fd;return await n.truncate(Number(e)),0}),["i32","i64"],["i32"]),u("fd_filestat_set_times",(function(t,e,n,r){const{fileDescriptor:i,atim:s,mtim:o}=c.call(this,t,e,n,r);return Q(this).futimesSync(i.fd,Number(s),Number(o)),0}),(async function(t,e,n,r){const{fileDescriptor:i,atim:s,mtim:o}=c.call(this,t,e,n,r),a=i.fd;return await a.utimes(Number(s),Number(o)),0}),["i32","i64","i64","i32"],["i32"]),u("fd_pread",(function(t,e,n,r,i){if(e=Number(e),i=Number(i),0===e||0===i)return 28;const{HEAPU8:s,view:o}=X(this),a=Z.get(this).fds.get(t,E.FD_READ|E.FD_SEEK,BigInt(0));let u=0;const c=Array.from({length:Number(n)},((t,n)=>{const r=e+8*n,i=o.getInt32(r,!0),a=o.getUint32(r+4,!0);return u+=a,s.subarray(i,i+a)}));let f=0;const h=new Uint8Array(u);h._isBuffer=!0;const d=Q(this).readSync(a.fd,h,0,h.length,Number(r));return f=h?$(c,h.subarray(0,d)):0,o.setUint32(i,f,!0),0}),(async function(t,e,n,r,i){if(e=Number(e),i=Number(i),0===e||0===i)return 28;const{HEAPU8:s,view:o}=X(this),a=Z.get(this).fds.get(t,E.FD_READ|E.FD_SEEK,BigInt(0));let u=0;const c=Array.from({length:Number(n)},((t,n)=>{const r=e+8*n,i=o.getInt32(r,!0),a=o.getUint32(r+4,!0);return u+=a,s.subarray(i,i+a)}));let f=0;const h=new Uint8Array(u);h._isBuffer=!0;const{bytesRead:d}=await a.fd.read(h,0,h.length,Number(r));return f=h?$(c,h.subarray(0,d)):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||0===i)return 28;const{HEAPU8:s,view:o}=X(this),a=Z.get(this).fds.get(t,E.FD_WRITE|E.FD_SEEK,BigInt(0)),u=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 s.subarray(i,i+a)}))),c=Q(this).writeSync(a.fd,u,0,u.length,Number(r));return o.setUint32(i,c,!0),0}),(async function(t,e,n,r,i){if(e=Number(e),i=Number(i),0===e||0===i)return 28;const{HEAPU8:s,view:o}=X(this),a=Z.get(this).fds.get(t,E.FD_WRITE|E.FD_SEEK,BigInt(0)),u=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 s.subarray(i,i+a)}))),{bytesWritten:c}=await a.fd.write(u,0,u.length,Number(r));return o.setUint32(i,c,!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||0===r)return 28;const{HEAPU8:i,view:s}=X(this),o=Z.get(this).fds.get(t,E.FD_READ,BigInt(0));let a=0;const u=Array.from({length:Number(n)},((t,n)=>{const r=e+8*n,o=s.getInt32(r,!0),u=s.getUint32(r+4,!0);return a+=u,i.subarray(o,o+u)}));let c,f=0;if(0===t){if("undefined"==typeof window||"function"!=typeof window.prompt)return 58;c=st(),f=c?$(u,c):0}else{c=new Uint8Array(a),c._isBuffer=!0;const t=Q(this).readSync(o.fd,c,0,c.length,Number(o.pos));f=c?$(u,c.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||0===r)return 28;const{HEAPU8:i,view:s}=X(this),o=Z.get(this).fds.get(t,E.FD_READ,BigInt(0));let a=0;const u=Array.from({length:Number(n)},((t,n)=>{const r=e+8*n,o=s.getInt32(r,!0),u=s.getUint32(r+4,!0);return a+=u,i.subarray(o,o+u)}));let c,f=0;if(0===t){if("undefined"==typeof window||"function"!=typeof window.prompt)return 58;c=st(),f=c?$(u,c):0}else{c=new Uint8Array(a),c._isBuffer=!0;const{bytesRead:t}=await o.fd.read(c,0,c.length,Number(o.pos));f=c?$(u,c.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=Z.get(this).fds.get(t,E.FD_READDIR,BigInt(0)),o=Q(this),a=o.readdirSync(s.realPath,{withFileTypes:!0}),{HEAPU8:u,view:c}=X(this);let f=0;for(let t=Number(r);t<a.length;t++){const r=rt.encode(a[t].name),i=o.statSync(y(s.realPath,a[t].name),{bigint:!0}),c=new Uint8Array(24+r.byteLength),h=new DataView(c.buffer);let d;h.setBigUint64(0,BigInt(t+1),!0),h.setBigUint64(8,BigInt(i.ino?i.ino:0),!0),h.setUint32(16,r.byteLength,!0),d=a[t].isFile()?4:a[t].isDirectory()?3:a[t].isSymbolicLink()?7:a[t].isCharacterDevice()?2:a[t].isBlockDevice()?1:a[t].isSocket()?6:0,h.setUint8(20,d),c.set(r,24);const g=c.slice(0,Math.min(c.length,n-f));u.set(g,e+f),f+=g.byteLength}return c.setUint32(i,f,!0),0}),(async function(t,e,n,r,i){if(e=Number(e),n=Number(n),i=Number(i),0===e||0===i)return 0;const s=Z.get(this).fds.get(t,E.FD_READDIR,BigInt(0)),o=Q(this),a=await o.promises.readdir(s.realPath,{withFileTypes:!0}),{HEAPU8:u,view:c}=X(this);let f=0;for(let t=Number(r);t<a.length;t++){const r=rt.encode(a[t].name),i=await o.promises.stat(y(s.realPath,a[t].name),{bigint:!0}),c=new Uint8Array(24+r.byteLength),h=new DataView(c.buffer);let d;h.setBigUint64(0,BigInt(t+1),!0),h.setBigUint64(8,BigInt(i.ino?i.ino:0),!0),h.setUint32(16,r.byteLength,!0),d=a[t].isFile()?4:a[t].isDirectory()?3:a[t].isSymbolicLink()?7:a[t].isCharacterDevice()?2:a[t].isBlockDevice()?1:a[t].isSocket()?6:0,h.setUint8(20,d),c.set(r,24);const g=c.slice(0,Math.min(c.length,n-f));u.set(g,e+f),f+=g.byteLength}return c.setUint32(i,f,!0),0}),["i32","i32","i32","i64","i32"],["i32"]),u("fd_renumber",(function(t,e){return Z.get(this).fds.renumber(e,t),0}),(async function(t,e){const n=Z.get(this);return await n.fds.renumber(e,t),0}),["i32","i32"],["i32"]),u("fd_sync",(function(t){const e=Z.get(this).fds.get(t,E.FD_SYNC,BigInt(0));return Q(this).fsyncSync(e.fd),0}),(async function(t){const e=Z.get(this).fds.get(t,E.FD_SYNC,BigInt(0));return await e.fd.sync(),0}),["i32"],["i32"]),u("fd_write",(function(t,e,n,r){if(e=Number(e),r=Number(r),0===e||0===r)return 28;const{HEAPU8:i,view:s}=X(this),o=Z.get(this).fds.get(t,E.FD_WRITE,BigInt(0)),a=U(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 u;if(1===t||2===t)u=o.write(a);else{u=Q(this).writeSync(o.fd,a,0,a.length,Number(o.pos)),o.pos+=BigInt(u)}return s.setUint32(r,u,!0),0}),(async function(t,e,n,r){if(e=Number(e),r=Number(r),0===e||0===r)return 28;const{HEAPU8:i,view:s}=X(this),o=Z.get(this).fds.get(t,E.FD_WRITE,BigInt(0)),a=U(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 u;return 1===t||2===t?u=o.write(a):(u=await(await o.fd.write(a,0,a.length,Number(o.pos))).bytesWritten,o.pos+=BigInt(u)),s.setUint32(r,u,!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}=X(this),i=Z.get(this).fds.get(t,E.PATH_CREATE_DIRECTORY,BigInt(0));let s=it.decode(r.subarray(e,e+n));s=y(i.realPath,s);return Q(this).mkdirSync(s),0}),(async function(t,e,n){if(e=Number(e),n=Number(n),0===e)return 28;const{HEAPU8:r}=X(this),i=Z.get(this).fds.get(t,E.PATH_CREATE_DIRECTORY,BigInt(0));let s=it.decode(r.subarray(e,e+n));s=y(i.realPath,s);const o=Q(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}=X(this),a=Z.get(this).fds.get(t,E.PATH_FILESTAT_GET,BigInt(0));let u=it.decode(s.subarray(n,n+r));const c=Q(this);let f;return u=y(a.realPath,u),f=1==(1&e)?c.statSync(u,{bigint:!0}):c.lstatSync(u,{bigint:!0}),C(o,i,f),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}=X(this),a=Z.get(this).fds.get(t,E.PATH_FILESTAT_GET,BigInt(0));let u=it.decode(s.subarray(n,n+r));const c=Q(this);let f;return u=y(a.realPath,u),f=1==(1&e)?await c.promises.stat(u,{bigint:!0}):await c.promises.lstat(u,{bigint:!0}),C(o,i,f),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;if(-16&o)return 28;const{HEAPU8:a}=X(this),u=Z.get(this).fds.get(t,E.PATH_FILESTAT_SET_TIMES,BigInt(0)),c=Q(this),f=et(c,u,it.decode(a.subarray(n,n+r)),e);return 2==(2&o)&&(i=BigInt(1e6*Date.now())),8==(8&o)&&(s=BigInt(1e6*Date.now())),c.utimesSync(f,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;if(-16&o)return 28;const{HEAPU8:a}=X(this),u=Z.get(this).fds.get(t,E.PATH_FILESTAT_SET_TIMES,BigInt(0)),c=Q(this),f=await nt(c,u,it.decode(a.subarray(n,n+r)),e);return 2==(2&o)&&(i=BigInt(1e6*Date.now())),8==(8&o)&&(s=BigInt(1e6*Date.now())),await c.promises.utimes(f,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 a=Z.get(this);let u,c;t===i?u=c=a.fds.get(t,E.PATH_LINK_SOURCE|E.PATH_LINK_TARGET,BigInt(0)):(u=a.fds.get(t,E.PATH_LINK_SOURCE,BigInt(0)),c=a.fds.get(i,E.PATH_LINK_TARGET,BigInt(0)));const{HEAPU8:f}=X(this),h=Q(this),d=et(h,u,it.decode(f.subarray(n,n+r)),e),g=y(c.realPath,it.decode(f.subarray(s,s+o)));return h.linkSync(d,g),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 a=Z.get(this);let u,c;t===i?u=c=a.fds.get(t,E.PATH_LINK_SOURCE|E.PATH_LINK_TARGET,BigInt(0)):(u=a.fds.get(t,E.PATH_LINK_SOURCE,BigInt(0)),c=a.fds.get(i,E.PATH_LINK_TARGET,BigInt(0)));const{HEAPU8:f}=X(this),h=Q(this),d=await nt(h,u,it.decode(f.subarray(n,n+r)),e),g=y(c.realPath,it.decode(f.subarray(s,s+o)));return await h.promises.link(d,g),0}),["i32","i32","i32","i32","i32","i32","i32"],["i32"]),u("path_open",(function(t,e,n,r,i,s,o,a,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:c,needed_base:h,needed_inheriting:d}=f(i,s,o,a),g=Z.get(this),l=g.fds.get(t,h,d),_=X(this),y=_.HEAPU8,E=it.decode(y.subarray(n,n+r)),p=Q(this),I=et(p,l,E,e),b=p.openSync(I,c,438),m=g.fds.getFileTypeByFd(b);if(0!=(2&i)&&3!==m)return 54;const{base:A,inheriting:T}=v(g.fds.stdio,b,c,m),w=g.fds.insert(b,I,I,m,s&A,o&T,0),N=p.fstatSync(b,{bigint:!0});N.isFile()&&(w.size=N.size,0!=(1024&c)&&(w.pos=N.size));return _.view.setInt32(u,w.id,!0),0}),(async function(t,e,n,r,i,s,o,a,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:c,needed_base:h,needed_inheriting:d}=f(i,s,o,a),g=Z.get(this),l=g.fds.get(t,h,d),_=X(this),y=_.HEAPU8,E=it.decode(y.subarray(n,n+r)),p=Q(this),I=await nt(p,l,E,e),b=await p.promises.open(I,c,438),m=await g.fds.getFileTypeByFd(b);if(0!=(2&i)&&3!==m)return 54;const{base:A,inheriting:T}=v(g.fds.stdio,b.fd,c,m),w=g.fds.insert(b,I,I,m,s&A,o&T,0),N=await b.stat({bigint:!0});N.isFile()&&(w.size=N.size,0!=(1024&c)&&(w.pos=N.size));return _.view.setInt32(u,w.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:a}=X(this),u=Z.get(this).fds.get(t,E.PATH_READLINK,BigInt(0));let c=it.decode(o.subarray(e,e+n));c=y(u.realPath,c);const f=Q(this).readlinkSync(c),h=rt.encode(f),d=Math.min(h.length,i);return d>=i?42:(o.set(h.subarray(0,d),r),o[r+d]=0,a.setUint32(s,d+1,!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:a}=X(this),u=Z.get(this).fds.get(t,E.PATH_READLINK,BigInt(0));let c=it.decode(o.subarray(e,e+n));c=y(u.realPath,c);const f=Q(this),h=await f.promises.readlink(c),d=rt.encode(h),g=Math.min(d.length,i);return g>=i?42:(o.set(d.subarray(0,g),r),o[r+g]=0,a.setUint32(s,g+1,!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}=X(this),i=Z.get(this).fds.get(t,E.PATH_REMOVE_DIRECTORY,BigInt(0));let s=it.decode(r.subarray(e,e+n));s=y(i.realPath,s);return Q(this).rmdirSync(s),0}),(async function(t,e,n){if(e=Number(e),n=Number(n),0===e)return 28;const{HEAPU8:r}=X(this),i=Z.get(this).fds.get(t,E.PATH_REMOVE_DIRECTORY,BigInt(0));let s=it.decode(r.subarray(e,e+n));s=y(i.realPath,s);const o=Q(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=Z.get(this);let a,u;t===r?a=u=o.fds.get(t,E.PATH_RENAME_SOURCE|E.PATH_RENAME_TARGET,BigInt(0)):(a=o.fds.get(t,E.PATH_RENAME_SOURCE,BigInt(0)),u=o.fds.get(r,E.PATH_RENAME_TARGET,BigInt(0)));const{HEAPU8:c}=X(this),f=y(a.realPath,it.decode(c.subarray(e,e+n))),h=y(u.realPath,it.decode(c.subarray(i,i+s)));return Q(this).renameSync(f,h),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=Z.get(this);let a,u;t===r?a=u=o.fds.get(t,E.PATH_RENAME_SOURCE|E.PATH_RENAME_TARGET,BigInt(0)):(a=o.fds.get(t,E.PATH_RENAME_SOURCE,BigInt(0)),u=o.fds.get(r,E.PATH_RENAME_TARGET,BigInt(0)));const{HEAPU8:c}=X(this),f=y(a.realPath,it.decode(c.subarray(e,e+n))),h=y(u.realPath,it.decode(c.subarray(i,i+s))),d=Q(this);return await d.promises.rename(f,h),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}=X(this),o=Z.get(this).fds.get(n,E.PATH_SYMLINK,BigInt(0)),a=it.decode(s.subarray(t,t+e));let u=it.decode(s.subarray(r,r+i));u=y(o.realPath,u);return Q(this).symlinkSync(a,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}=X(this),o=Z.get(this).fds.get(n,E.PATH_SYMLINK,BigInt(0)),a=it.decode(s.subarray(t,t+e));let u=it.decode(s.subarray(r,r+i));u=y(o.realPath,u);const c=Q(this);return await c.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:r}=X(this),i=Z.get(this).fds.get(t,E.PATH_UNLINK_FILE,BigInt(0));let s=it.decode(r.subarray(e,e+n));s=y(i.realPath,s);return Q(this).unlinkSync(s),0}),(async function(t,e,n){if(e=Number(e),n=Number(n),0===e)return 28;const{HEAPU8:r}=X(this),i=Z.get(this).fds.get(t,E.PATH_UNLINK_FILE,BigInt(0));let s=it.decode(r.subarray(e,e+n));s=y(i.realPath,s);const o=Q(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');V.set(a,W(t))}}static createSync(t,e,n,r,i,s,o){const a=new x({size:3,in:r[0],out:r[1],err:r[2],fs:i,print:s,printErr:o}),u=new ot(t,e,a,!1,i);if(n.length>0)for(let t=0;t<n.length;++t){const e=i.realpathSync(n[t].realPath,"utf8"),r=i.openSync(e,"r",438);a.insertPreopen(r,n[t].mappedPath,e)}return u}static async createAsync(t,e,n,r,i,s,o,a){const u=new M({size:3,in:r[0],out:r[1],err:r[2],print:s,printErr:o}),c=new ot(t,e,u,!0,i,a);if(n.length>0)for(let t=0;t<n.length;++t){const e=n[t],r=await i.promises.realpath(e.realPath),s=await i.promises.open(r,"r",438);await u.insertPreopen(s,e.mappedPath,r)}return c}}const at=Object.freeze(Object.create(null)),ut=Symbol("kExitCode"),ct=Symbol("kSetMemory"),ft=Symbol("kStarted"),ht=Symbol("kInstance");function dt(t,e){n(e,"instance"),n(e.exports,"instance.exports"),t[ht]=e,t[ct](e.exports.memory)}function gt(t){var e;n(t,"options"),void 0!==t.args&&function(t,e){if(!Array.isArray(t))throw new TypeError(`${e} must be an array. Received ${null===t?"null":typeof t}`)}(t.args,"options.args");const r=(null!==(e=t.args)&&void 0!==e?e:[]).map(String),s=[];void 0!==t.env&&(n(t.env,"options.env"),Object.entries(t.env).forEach((({0:t,1:e})=>{void 0!==e&&s.push(`${t}=${e}`)})));const o=[];if(void 0!==t.preopens&&(n(t.preopens,"options.preopens"),Object.entries(t.preopens).forEach((({0:t,1:e})=>o.push({mappedPath:String(t),realPath:String(e)})))),o.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&&i(t.print,"options.print"),void 0!==t.printErr&&i(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:r,env:s,preopens:o,stdio:[0,1,2]}}class lt{constructor(t,e){this[ct]=t,this.wasiImport=e,this[ft]=!1,this[ut]=0,this[ht]=void 0}static createSync(t=at){const{args:e,env:n,preopens:r,stdio:i}=gt(t),s=ot.createSync(e,n,r,i,t.fs,t.print,t.printErr),o=s._setMemory;delete s._setMemory;const a=new lt(o,s);return t.returnOnExit&&(s.proc_exit=_t.bind(a)),a}static async createAsync(t=at){const{args:e,env:r,preopens:s,stdio:o}=gt(t);void 0!==t.asyncify&&(n(t.asyncify,"options.asyncify"),i(t.asyncify.wrapImportFunction,"options.asyncify.wrapImportFunction"));const a=await ot.createAsync(e,r,s,o,t.fs,t.print,t.printErr,t.asyncify),u=a._setMemory;delete a._setMemory;const c=new lt(u,a);return t.returnOnExit&&(a.proc_exit=_t.bind(c)),c}start(t){if(this[ft])throw new Error("WASI instance has already started");this[ft]=!0,dt(this,t);const{_start:e,_initialize:n}=this[ht].exports;let r;i(e,"instance.exports._start"),s(n,"instance.exports._initialize");try{r=e()}catch(t){if(t!==ut)throw t}return r instanceof Promise?r.then((()=>this[ut]),(t=>{if(t!==ut)throw t;return this[ut]})):this[ut]}initialize(t){if(this[ft])throw new Error("WASI instance has already started");this[ft]=!0,dt(this,t);const{_start:e,_initialize:n}=this[ht].exports;if(s(e,"instance.exports._start"),void 0!==n)return i(n,"instance.exports._initialize"),n()}}function _t(t){throw this[ut]=t,ut}t.Asyncify=f,t.Memory=z,t.WASI=lt,t.WebAssemblyMemory=K,t.asyncifyLoad=function(t,e,n){h(n),n=null!=n?n:{};const r=new f;return g(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)}}))},t.asyncifyLoadSync=function(t,e,n){var r;h(n),n=null!=n?n:{};const i=new f,s=l(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)}},t.extendMemory=W,t.load=g,t.loadSync=l,t.wrapAsyncExport=j,t.wrapAsyncImport=Y,t.wrapExports=function(t,e){return a(t,((t,n)=>{let r="function"!=typeof t;return Array.isArray(e)&&(r=r||-1===e.indexOf(n)),r?t:j(t)}))},Object.defineProperty(t,"__esModule",{value:!0})}));
package/lib/cjs/load.js CHANGED
@@ -8,51 +8,54 @@ function validateImports(imports) {
8
8
  throw new TypeError('imports must be an object or undefined');
9
9
  }
10
10
  }
11
- async function fetchWasm(urlOrBuffer, imports) {
11
+ function fetchWasm(urlOrBuffer, imports) {
12
12
  if (typeof wx !== 'undefined' && typeof __wxConfig !== 'undefined') {
13
- return await webassembly_1._WebAssembly.instantiate(urlOrBuffer, imports);
13
+ return webassembly_1._WebAssembly.instantiate(urlOrBuffer, imports);
14
14
  }
15
- const response = await fetch(urlOrBuffer);
16
- const buffer = await response.arrayBuffer();
17
- const source = await webassembly_1._WebAssembly.instantiate(buffer, imports);
18
- return source;
15
+ return fetch(urlOrBuffer)
16
+ .then(response => response.arrayBuffer())
17
+ .then(buffer => webassembly_1._WebAssembly.instantiate(buffer, imports));
19
18
  }
20
19
  /** @public */
21
- async function load(urlOrBuffer, imports) {
20
+ function load(urlOrBuffer, imports) {
22
21
  validateImports(imports);
23
22
  imports = imports !== null && imports !== void 0 ? imports : {};
24
23
  let source;
25
24
  if (urlOrBuffer instanceof ArrayBuffer || ArrayBuffer.isView(urlOrBuffer)) {
26
- source = await webassembly_1._WebAssembly.instantiate(urlOrBuffer, imports);
27
- return source;
25
+ return webassembly_1._WebAssembly.instantiate(urlOrBuffer, imports);
28
26
  }
29
27
  if (typeof urlOrBuffer !== 'string' && !(urlOrBuffer instanceof URL)) {
30
28
  throw new TypeError('Invalid source');
31
29
  }
32
30
  if (typeof webassembly_1._WebAssembly.instantiateStreaming === 'function') {
31
+ let responsePromise;
33
32
  try {
34
- source = await webassembly_1._WebAssembly.instantiateStreaming(fetch(urlOrBuffer), imports);
33
+ responsePromise = fetch(urlOrBuffer);
34
+ source = webassembly_1._WebAssembly.instantiateStreaming(responsePromise, imports).catch(() => {
35
+ return fetchWasm(urlOrBuffer, imports);
36
+ });
35
37
  }
36
38
  catch (_) {
37
- source = await fetchWasm(urlOrBuffer, imports);
39
+ source = fetchWasm(urlOrBuffer, imports);
38
40
  }
39
41
  }
40
42
  else {
41
- source = await fetchWasm(urlOrBuffer, imports);
43
+ source = fetchWasm(urlOrBuffer, imports);
42
44
  }
43
45
  return source;
44
46
  }
45
47
  exports.load = load;
46
48
  /** @public */
47
- async function asyncifyLoad(asyncify, urlOrBuffer, imports) {
48
- var _a;
49
+ function asyncifyLoad(asyncify, urlOrBuffer, imports) {
49
50
  validateImports(imports);
50
51
  imports = imports !== null && imports !== void 0 ? imports : {};
51
52
  const asyncifyHelper = new asyncify_1.Asyncify();
52
53
  imports = asyncifyHelper.wrapImports(imports);
53
- const source = await load(urlOrBuffer, imports);
54
- const memory = source.instance.exports.memory || ((_a = imports.env) === null || _a === void 0 ? void 0 : _a.memory);
55
- return { module: source.module, instance: asyncifyHelper.init(memory, source.instance, asyncify) };
54
+ return load(urlOrBuffer, imports).then(source => {
55
+ var _a;
56
+ const memory = source.instance.exports.memory || ((_a = imports.env) === null || _a === void 0 ? void 0 : _a.memory);
57
+ return { module: source.module, instance: asyncifyHelper.init(memory, source.instance, asyncify) };
58
+ });
56
59
  }
57
60
  exports.asyncifyLoad = asyncifyLoad;
58
61
  /** @public */
package/lib/mjs/load.mjs CHANGED
@@ -5,50 +5,53 @@ function validateImports(imports) {
5
5
  throw new TypeError('imports must be an object or undefined');
6
6
  }
7
7
  }
8
- async function fetchWasm(urlOrBuffer, imports) {
8
+ function fetchWasm(urlOrBuffer, imports) {
9
9
  if (typeof wx !== 'undefined' && typeof __wxConfig !== 'undefined') {
10
- return await _WebAssembly.instantiate(urlOrBuffer, imports);
10
+ return _WebAssembly.instantiate(urlOrBuffer, imports);
11
11
  }
12
- const response = await fetch(urlOrBuffer);
13
- const buffer = await response.arrayBuffer();
14
- const source = await _WebAssembly.instantiate(buffer, imports);
15
- return source;
12
+ return fetch(urlOrBuffer)
13
+ .then(response => response.arrayBuffer())
14
+ .then(buffer => _WebAssembly.instantiate(buffer, imports));
16
15
  }
17
16
  /** @public */
18
- export async function load(urlOrBuffer, imports) {
17
+ export function load(urlOrBuffer, imports) {
19
18
  validateImports(imports);
20
19
  imports = imports !== null && imports !== void 0 ? imports : {};
21
20
  let source;
22
21
  if (urlOrBuffer instanceof ArrayBuffer || ArrayBuffer.isView(urlOrBuffer)) {
23
- source = await _WebAssembly.instantiate(urlOrBuffer, imports);
24
- return source;
22
+ return _WebAssembly.instantiate(urlOrBuffer, imports);
25
23
  }
26
24
  if (typeof urlOrBuffer !== 'string' && !(urlOrBuffer instanceof URL)) {
27
25
  throw new TypeError('Invalid source');
28
26
  }
29
27
  if (typeof _WebAssembly.instantiateStreaming === 'function') {
28
+ let responsePromise;
30
29
  try {
31
- source = await _WebAssembly.instantiateStreaming(fetch(urlOrBuffer), imports);
30
+ responsePromise = fetch(urlOrBuffer);
31
+ source = _WebAssembly.instantiateStreaming(responsePromise, imports).catch(() => {
32
+ return fetchWasm(urlOrBuffer, imports);
33
+ });
32
34
  }
33
35
  catch (_) {
34
- source = await fetchWasm(urlOrBuffer, imports);
36
+ source = fetchWasm(urlOrBuffer, imports);
35
37
  }
36
38
  }
37
39
  else {
38
- source = await fetchWasm(urlOrBuffer, imports);
40
+ source = fetchWasm(urlOrBuffer, imports);
39
41
  }
40
42
  return source;
41
43
  }
42
44
  /** @public */
43
- export async function asyncifyLoad(asyncify, urlOrBuffer, imports) {
44
- var _a;
45
+ export function asyncifyLoad(asyncify, urlOrBuffer, imports) {
45
46
  validateImports(imports);
46
47
  imports = imports !== null && imports !== void 0 ? imports : {};
47
48
  const asyncifyHelper = new Asyncify();
48
49
  imports = asyncifyHelper.wrapImports(imports);
49
- const source = await load(urlOrBuffer, imports);
50
- const memory = source.instance.exports.memory || ((_a = imports.env) === null || _a === void 0 ? void 0 : _a.memory);
51
- return { module: source.module, instance: asyncifyHelper.init(memory, source.instance, asyncify) };
50
+ return load(urlOrBuffer, imports).then(source => {
51
+ var _a;
52
+ const memory = source.instance.exports.memory || ((_a = imports.env) === null || _a === void 0 ? void 0 : _a.memory);
53
+ return { module: source.module, instance: asyncifyHelper.init(memory, source.instance, asyncify) };
54
+ });
52
55
  }
53
56
  /** @public */
54
57
  export function loadSync(buffer, imports) {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@tybys/wasm-util",
3
- "version": "0.5.2",
3
+ "version": "0.5.3",
4
4
  "description": "WASI polyfill for browser and some wasm util",
5
5
  "main": "./lib/cjs/index.js",
6
6
  "module": "./dist/wasm-util.esm-bundler.js",
@@ -35,6 +35,9 @@
35
35
  },
36
36
  "author": "toyobayashi",
37
37
  "license": "MIT",
38
+ "dependencies": {
39
+ "tslib": "^2.4.0"
40
+ },
38
41
  "devDependencies": {
39
42
  "@tybys/ts-transform-module-specifier": "^0.0.2",
40
43
  "@tybys/ts-transform-pure-class": "^0.1.1",