@tailwindcss/oxide-wasm32-wasi 4.2.4 → 4.3.1

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.
Files changed (57) hide show
  1. package/node_modules/@emnapi/core/dist/emnapi-core.cjs.js +854 -307
  2. package/node_modules/@emnapi/core/dist/emnapi-core.cjs.min.d.ts +3 -2
  3. package/node_modules/@emnapi/core/dist/emnapi-core.cjs.min.js +1 -1
  4. package/node_modules/@emnapi/core/dist/emnapi-core.d.mts +3 -2
  5. package/node_modules/@emnapi/core/dist/emnapi-core.d.ts +3 -2
  6. package/node_modules/@emnapi/core/dist/emnapi-core.esm-bundler.js +892 -313
  7. package/node_modules/@emnapi/core/dist/emnapi-core.js +904 -328
  8. package/node_modules/@emnapi/core/dist/emnapi-core.min.d.mts +3 -2
  9. package/node_modules/@emnapi/core/dist/emnapi-core.min.js +1 -1
  10. package/node_modules/@emnapi/core/dist/emnapi-core.min.mjs +1 -1
  11. package/node_modules/@emnapi/core/dist/emnapi-core.mjs +854 -307
  12. package/node_modules/@emnapi/core/package.json +2 -2
  13. package/node_modules/@emnapi/runtime/dist/emnapi.cjs.js +32 -5
  14. package/node_modules/@emnapi/runtime/dist/emnapi.cjs.min.d.ts +8 -2
  15. package/node_modules/@emnapi/runtime/dist/emnapi.cjs.min.js +1 -1
  16. package/node_modules/@emnapi/runtime/dist/emnapi.d.mts +8 -2
  17. package/node_modules/@emnapi/runtime/dist/emnapi.d.ts +8 -2
  18. package/node_modules/@emnapi/runtime/dist/emnapi.esm-bundler.js +33 -5
  19. package/node_modules/@emnapi/runtime/dist/emnapi.iife.d.ts +8 -2
  20. package/node_modules/@emnapi/runtime/dist/emnapi.iife.js +33 -5
  21. package/node_modules/@emnapi/runtime/dist/emnapi.js +33 -5
  22. package/node_modules/@emnapi/runtime/dist/emnapi.min.d.mts +8 -2
  23. package/node_modules/@emnapi/runtime/dist/emnapi.min.js +1 -1
  24. package/node_modules/@emnapi/runtime/dist/emnapi.min.mjs +1 -1
  25. package/node_modules/@emnapi/runtime/dist/emnapi.mjs +32 -5
  26. package/node_modules/@emnapi/runtime/package.json +1 -1
  27. package/node_modules/@emnapi/wasi-threads/dist/wasi-threads.cjs.js +17 -20
  28. package/node_modules/@emnapi/wasi-threads/dist/wasi-threads.cjs.min.d.ts +2 -0
  29. package/node_modules/@emnapi/wasi-threads/dist/wasi-threads.cjs.min.js +1 -1
  30. package/node_modules/@emnapi/wasi-threads/dist/wasi-threads.d.mts +2 -0
  31. package/node_modules/@emnapi/wasi-threads/dist/wasi-threads.d.ts +2 -0
  32. package/node_modules/@emnapi/wasi-threads/dist/wasi-threads.esm-bundler.js +17 -20
  33. package/node_modules/@emnapi/wasi-threads/dist/wasi-threads.js +17 -20
  34. package/node_modules/@emnapi/wasi-threads/dist/wasi-threads.min.d.mts +2 -0
  35. package/node_modules/@emnapi/wasi-threads/dist/wasi-threads.min.js +1 -1
  36. package/node_modules/@emnapi/wasi-threads/dist/wasi-threads.min.mjs +1 -1
  37. package/node_modules/@emnapi/wasi-threads/dist/wasi-threads.mjs +17 -20
  38. package/node_modules/@emnapi/wasi-threads/package.json +1 -1
  39. package/node_modules/@napi-rs/wasm-runtime/dist/fs-proxy.cjs +47 -12
  40. package/node_modules/@napi-rs/wasm-runtime/dist/fs.js +14310 -10201
  41. package/node_modules/@napi-rs/wasm-runtime/fs-proxy.js +47 -12
  42. package/node_modules/@napi-rs/wasm-runtime/package.json +6 -4
  43. package/node_modules/@tybys/wasm-util/dist/wasm-util.esm-bundler.js +164 -2
  44. package/node_modules/@tybys/wasm-util/dist/wasm-util.esm.js +164 -2
  45. package/node_modules/@tybys/wasm-util/dist/wasm-util.esm.min.js +1 -1
  46. package/node_modules/@tybys/wasm-util/dist/wasm-util.js +164 -2
  47. package/node_modules/@tybys/wasm-util/dist/wasm-util.min.js +1 -1
  48. package/node_modules/@tybys/wasm-util/lib/cjs/wasi/path.js +142 -0
  49. package/node_modules/@tybys/wasm-util/lib/cjs/wasi/preview1.js +22 -2
  50. package/node_modules/@tybys/wasm-util/lib/mjs/wasi/path.mjs +142 -0
  51. package/node_modules/@tybys/wasm-util/lib/mjs/wasi/preview1.mjs +22 -2
  52. package/node_modules/@tybys/wasm-util/package.json +1 -1
  53. package/package.json +6 -6
  54. package/tailwindcss-oxide.wasi-browser.js +1 -0
  55. package/tailwindcss-oxide.wasi.cjs +1 -1
  56. package/tailwindcss-oxide.wasm32-wasi.wasm +0 -0
  57. package/wasi-worker-browser.mjs +2 -0
@@ -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}function a(t,e,n){return"function"==typeof SharedArrayBuffer&&t.buffer instanceof SharedArrayBuffer||"[object SharedArrayBuffer]"===Object.prototype.toString.call(t.buffer.constructor)?t.slice(e,n):t.subarray(e,n)}const c=["asyncify_get_state","asyncify_start_rewind","asyncify_start_unwind","asyncify_stop_rewind","asyncify_stop_unwind"];function u(t,e,n,r){if("function"!=typeof t.exports[r]||n<=0)return{wasm64:e,dataPtr:16,start:e?32:24,end:1024};const i=t.exports[r],s=e?Number(i(BigInt(16)+BigInt(n))):i(8+n);if(0===s)throw new Error("Allocate asyncify data failed");return e?{wasm64:e,dataPtr:s,start:s+16,end:s+16+n}:{wasm64:e,dataPtr:s,start:s+8,end:s+8+n}}class f{constructor(){this.value=void 0,this.exports=void 0,this.dataPtr=0}init(e,n,r){var i,s;if(this.exports)throw new Error("Asyncify has been initialized");if(!(e instanceof t.Memory))throw new TypeError("Require WebAssembly.Memory object");const o=n.exports;for(let t=0;t<c.length;++t)if("function"!=typeof o[c[t]])throw new TypeError("Invalid asyncify wasm");let a;const f=Boolean(r.wasm64);a=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=a.dataPtr,f?new BigInt64Array(e.buffer,this.dataPtr).set([BigInt(a.start),BigInt(a.end)]):new Int32Array(e.buffer,this.dataPtr).set([a.start,a.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!==c.indexOf(n)||"function"!=typeof t;return Array.isArray(e)&&(r=r||-1===e.indexOf(n)),r?t:this.wrapExportFunction(t)}))}}function h(t){if(t&&"object"!=typeof t)throw new TypeError("imports must be an object or undefined")}function g(e,n){return"undefined"!=typeof wx&&"undefined"!=typeof __wxConfig?t.instantiate(e,n):fetch(e).then((t=>t.arrayBuffer())).then((e=>t.instantiate(e,n)))}function d(e,n){let r;if(h(n),n=null!=n?n:{},e instanceof ArrayBuffer||ArrayBuffer.isView(e))return t.instantiate(e,n);if(e instanceof t.Module)return t.instantiate(e,n).then((t=>({instance:t,module:e})));if("string"!=typeof e&&!(e instanceof URL))throw new TypeError("Invalid source");if("function"==typeof t.instantiateStreaming){let i;try{i=fetch(e),r=t.instantiateStreaming(i,n).catch((()=>g(e,n)))}catch(t){r=g(e,n)}}else r=g(e,n);return r}function l(t,e,n){h(n),n=null!=n?n:{};const r=new f;return d(e,n=r.wrapImports(n)).then((e=>{var i;const s=e.instance.exports.memory||(null===(i=n.env)||void 0===i?void 0:i.memory);return{module:e.module,instance:r.init(s,e.instance,t)}}))}function _(e,n){let r;if(h(n),n=null!=n?n:{},e instanceof ArrayBuffer||ArrayBuffer.isView(e))r=new t.Module(e);else{if(!(e instanceof WebAssembly.Module))throw new TypeError("Invalid source");r=e}return{instance:new t.Instance(r,n),module:r}}function p(t,e,n){var r;h(n),n=null!=n?n:{};const i=new f,s=_(e,n=i.wrapImports(n)),o=s.instance.exports.memory||(null===(r=n.env)||void 0===r?void 0:r.memory);return{module:s.module,instance:i.init(o,s.instance,t)}}const E=46,y=47;function I(t){return t===y}function m(...t){let e="",r=!1;for(let i=t.length-1;i>=-1&&!r;i--){const s=i>=0?t[i]:"/";n(s,"path"),0!==s.length&&(e=`${s}/${e}`,r=s.charCodeAt(0)===y)}return e=function(t,e,n,r){let i="",s=0,o=-1,a=0,c=0;for(let u=0;u<=t.length;++u){if(u<t.length)c=t.charCodeAt(u);else{if(r(c))break;c=y}if(r(c)){if(o===u-1||1===a);else if(2===a){if(i.length<2||2!==s||i.charCodeAt(i.length-1)!==E||i.charCodeAt(i.length-2)!==E){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=u,a=0;continue}if(0!==i.length){i="",s=0,o=u,a=0;continue}}e&&(i+=i.length>0?`${n}..`:"..",s=2)}else i.length>0?i+=`${n}${t.slice(o+1,u)}`:i=t.slice(o+1,u),s=u-o-1;o=u,a=0}else c===E&&-1!==a?++a:a=-1}return i}(e,!r,"/",I),r?`/${e}`:e.length>0?e:"."}const A={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 b 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(b.prototype,"name",{configurable:!0,writable:!0,value:"WasiError"});const T=A.FD_DATASYNC|A.FD_READ|A.FD_SEEK|A.FD_FDSTAT_SET_FLAGS|A.FD_SYNC|A.FD_TELL|A.FD_WRITE|A.FD_ADVISE|A.FD_ALLOCATE|A.PATH_CREATE_DIRECTORY|A.PATH_CREATE_FILE|A.PATH_LINK_SOURCE|A.PATH_LINK_TARGET|A.PATH_OPEN|A.FD_READDIR|A.PATH_READLINK|A.PATH_RENAME_SOURCE|A.PATH_RENAME_TARGET|A.PATH_FILESTAT_GET|A.PATH_FILESTAT_SET_SIZE|A.PATH_FILESTAT_SET_TIMES|A.FD_FILESTAT_GET|A.FD_FILESTAT_SET_TIMES|A.FD_FILESTAT_SET_SIZE|A.PATH_SYMLINK|A.PATH_UNLINK_FILE|A.PATH_REMOVE_DIRECTORY|A.POLL_FD_READWRITE|A.SOCK_SHUTDOWN|A.SOCK_ACCEPT,w=T,B=T,N=T,S=T,P=A.FD_DATASYNC|A.FD_READ|A.FD_SEEK|A.FD_FDSTAT_SET_FLAGS|A.FD_SYNC|A.FD_TELL|A.FD_WRITE|A.FD_ADVISE|A.FD_ALLOCATE|A.FD_FILESTAT_GET|A.FD_FILESTAT_SET_SIZE|A.FD_FILESTAT_SET_TIMES|A.POLL_FD_READWRITE,D=BigInt(0),F=A.FD_FDSTAT_SET_FLAGS|A.FD_SYNC|A.FD_ADVISE|A.PATH_CREATE_DIRECTORY|A.PATH_CREATE_FILE|A.PATH_LINK_SOURCE|A.PATH_LINK_TARGET|A.PATH_OPEN|A.FD_READDIR|A.PATH_READLINK|A.PATH_RENAME_SOURCE|A.PATH_RENAME_TARGET|A.PATH_FILESTAT_GET|A.PATH_FILESTAT_SET_SIZE|A.PATH_FILESTAT_SET_TIMES|A.FD_FILESTAT_GET|A.FD_FILESTAT_SET_TIMES|A.PATH_SYMLINK|A.PATH_UNLINK_FILE|A.PATH_REMOVE_DIRECTORY|A.POLL_FD_READWRITE,U=F|P,v=A.FD_READ|A.FD_FDSTAT_SET_FLAGS|A.FD_WRITE|A.FD_FILESTAT_GET|A.POLL_FD_READWRITE|A.SOCK_SHUTDOWN,R=T,L=A.FD_READ|A.FD_FDSTAT_SET_FLAGS|A.FD_WRITE|A.FD_FILESTAT_GET|A.POLL_FD_READWRITE,H=BigInt(0);function O(t,e,n,r){const i={base:BigInt(0),inheriting:BigInt(0)};if(0===r)throw new b("Unknown file type",28);switch(r){case 4:i.base=P,i.inheriting=D;break;case 3:i.base=F,i.inheriting=U;break;case 6:case 5:i.base=v,i.inheriting=R;break;case 2:-1!==t.indexOf(e)?(i.base=L,i.inheriting=H):(i.base=N,i.inheriting=S);break;case 1:i.base=w,i.inheriting=B;break;default:i.base=BigInt(0),i.inheriting=BigInt(0)}const s=3&n;return 0===s?i.base&=~A.FD_WRITE:1===s&&(i.base&=~A.FD_READ),i}function k(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 C{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 b("Unknown whence",29);this.pos=BigInt(this.size)-BigInt(t)}return this.pos}}class x extends C{constructor(t,e,n,r,i,s,o,a,c){super(e,n,r,i,s,o,a,c),this._log=t,this._buf=null}write(t){const e=t;if(this._buf&&(t=k([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 M(t){return t.isBlockDevice()?1:t.isCharacterDevice()?2:t.isDirectory()?3:t.isSocket()?6:t.isFile()?4:t.isSymbolicLink()?7:0}function z(t,e,n){t.setBigUint64(e,n.dev,!0),t.setBigUint64(e+8,n.ino,!0),t.setBigUint64(e+16,BigInt(M(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}=O(this.stdio,t,2,2),s=this.insert(t,n,n,2,r,i,0);if(s.id!==e)throw new b(`id: ${s.id} !== expected: ${e}`,8);return s}insert(t,e,n,r,i,s,o){var a,c;let u,f=-1;if(this.used>=this.size){const t=2*this.size;this.fds.length=t,f=this.size,this.size=t}else for(let t=0;t<this.size;++t)if(null==this.fds[t]){f=t;break}return u="<stdout>"===e?new x(null!==(a=this.print)&&void 0!==a?a:console.log,f,t,e,n,r,i,s,o):"<stderr>"===e?new x(null!==(c=this.printErr)&&void 0!==c?c:console.error,f,t,e,n,r,i,s,o):new C(f,t,e,n,r,i,s,o),this.fds[f]=u,this.used++,u}get(t,e,n){if(t>=this.size)throw new b("Invalid fd",8);const r=this.fds[t];if(!r||r.id!==t)throw new b("Bad file descriptor",8);if((~r.rightsBase&e)!==BigInt(0)||(~r.rightsInheriting&n)!==BigInt(0))throw new b("Capabilities insufficient",76);return r}remove(t){if(t>=this.size)throw new b("Invalid fd",8);const e=this.fds[t];if(!e||e.id!==t)throw new b("Bad file descriptor",8);this.fds[t]=void 0,this.used--}}class W extends K{constructor(t){super(t),this.fs=t.fs}getFileTypeByFd(t){return M(this.fs.fstatSync(t,{bigint:!0}))}insertPreopen(t,e,n){const r=this.getFileTypeByFd(t);if(3!==r)throw new b(`Preopen not dir: ["${e}", "${n}"]`,54);const i=O(this.stdio,t,0,r);return this.insert(t,e,n,r,i.base,i.inheriting,1)}renumber(t,e){if(t===e)return;if(t>=this.size||e>=this.size)throw new b("Invalid fd",8);const n=this.fds[t],r=this.fds[e];if(!n||!r||n.id!==t||r.id!==e)throw new b("Invalid fd",8);this.fs.closeSync(n.fd),this.fds[t]=this.fds[e],this.fds[t].id=t,this.fds[e]=void 0,this.used--}}class j extends K{constructor(t){super(t)}async getFileTypeByFd(t){return M(await t.stat({bigint:!0}))}async insertPreopen(t,e,n){const r=await this.getFileTypeByFd(t);if(3!==r)throw new b(`Preopen not dir: ["${e}", "${n}"]`,54);const i=O(this.stdio,t.fd,0,r);return this.insert(t,e,n,r,i.base,i.inheriting,1)}async renumber(t,e){if(t===e)return;if(t>=this.size||e>=this.size)throw new b("Invalid fd",8);const n=this.fds[t],r=this.fds[e];if(!n||!r||n.id!==t||r.id!==e)throw new b("Invalid fd",8);await n.fd.close(),this.fds[t]=this.fds[e],this.fds[t].id=t,this.fds[e]=void 0,this.used--}}const G=function(){return t.Memory}();class Y extends G{constructor(t){super(t)}get HEAP8(){return new Int8Array(super.buffer)}get HEAPU8(){return new Uint8Array(super.buffer)}get HEAP16(){return new Int16Array(super.buffer)}get HEAPU16(){return new Uint16Array(super.buffer)}get HEAP32(){return new Int32Array(super.buffer)}get HEAPU32(){return new Uint32Array(super.buffer)}get HEAP64(){return new BigInt64Array(super.buffer)}get HEAPU64(){return new BigUint64Array(super.buffer)}get HEAPF32(){return new Float32Array(super.buffer)}get HEAPF64(){return new Float64Array(super.buffer)}get view(){return new DataView(super.buffer)}}function $(e){return Object.getPrototypeOf(e)===t.Memory.prototype&&Object.setPrototypeOf(e,Y.prototype),e}function V(){const e=t.Function;if("function"!=typeof e)throw new Error('WebAssembly.Function is not supported in this environment. If you are using V8 based browser like Chrome, try to specify --js-flags="--wasm-staging --experimental-wasm-stack-switching"');return e}function Z(t,e,n){const r=V();if("function"!=typeof t)throw new TypeError("Function required");const i=e.slice(0);return i.unshift("externref"),new r({parameters:i,results:n},t,{suspending:"first"})}function q(t){const e=V();if("function"!=typeof t)throw new TypeError("Function required");return new e({parameters:[...e.type(t).parameters.slice(1)],results:["externref"]},t,{promising:"first"})}function X(t,e){return o(t,((t,n)=>{let r="function"!=typeof t;return Array.isArray(e)&&(r=r||-1===e.indexOf(n)),r?t:q(t)}))}function Q(t,e){if(0===t.length||0===e.length)return 0;let n=0,r=e.length-n;for(let i=0;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 J=new WeakMap,tt=new WeakMap,et=new WeakMap;function nt(t){return J.get(t)}function rt(t){const e=et.get(t);if(!e)throw new Error("filesystem is unavailable");return e}function it(t){if(t instanceof b)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 st(t,e){return Object.defineProperty(e,"name",{value:t}),e}function ot(t,e,n){let r;try{r=t.apply(e,n)}catch(t){return it(t)}return s(r)?r.then((t=>t),it):r}function at(t,e,n){let r=!1;const i=(()=>{try{return}catch(t){return}})();return"string"==typeof i&&i.split(",").includes("wasi")&&(r=!0),st(e,r?function(){const r=Array.prototype.slice.call(arguments);let i=[`${e}(${Array.from({length:arguments.length}).map((()=>"%d")).join(", ")})`];return i=i.concat(r),console.debug.apply(console,i),ot(n,t,r)}:function(){return ot(n,t,arguments)})}function ct(t,e,n,r){let i=m(e.realPath,n);if(1==(1&r))try{i=t.readlinkSync(i)}catch(t){if("EINVAL"!==t.code&&"ENOENT"!==t.code)throw t}return i}async function ut(t,e,n,r){let i=m(e.realPath,n);if(1==(1&r))try{i=await t.promises.readlink(i)}catch(t){if("EINVAL"!==t.code&&"ENOENT"!==t.code)throw t}return i}const ft=new TextEncoder,ht=new TextDecoder,gt=(BigInt(1)<<BigInt(63))-BigInt(1);function dt(){const t=window.prompt();if(null===t)return new Uint8Array;return(new TextEncoder).encode(t+"\n")}function lt(t){return Boolean(-16&t)||3==(3&t)||12==(12&t)}class _t{constructor(e,n,r,i,s,o){this.args_get=at(this,"args_get",(function(t,e){if(t=Number(t),e=Number(e),0===t||0===e)return 28;const{HEAPU8:n,view:r}=nt(this),i=tt.get(this).args;for(let s=0;s<i.length;++s){const o=i[s];r.setInt32(t,e,!0),t+=4;const a=ft.encode(o+"\0");n.set(a,e),e+=a.length}return 0})),this.args_sizes_get=at(this,"args_sizes_get",(function(t,e){if(t=Number(t),e=Number(e),0===t||0===e)return 28;const{view:n}=nt(this),r=tt.get(this).args;return n.setUint32(t,r.length,!0),n.setUint32(e,ft.encode(r.join("\0")+"\0").length,!0),0})),this.environ_get=at(this,"environ_get",(function(t,e){if(t=Number(t),e=Number(e),0===t||0===e)return 28;const{HEAPU8:n,view:r}=nt(this),i=tt.get(this).env;for(let s=0;s<i.length;++s){const o=i[s];r.setInt32(t,e,!0),t+=4;const a=ft.encode(o+"\0");n.set(a,e),e+=a.length}return 0})),this.environ_sizes_get=at(this,"environ_sizes_get",(function(t,e){if(t=Number(t),e=Number(e),0===t||0===e)return 28;const{view:n}=nt(this),r=tt.get(this);return n.setUint32(t,r.env.length,!0),n.setUint32(e,ft.encode(r.env.join("\0")+"\0").length,!0),0})),this.clock_res_get=at(this,"clock_res_get",(function(t,e){if(0===(e=Number(e)))return 28;const{view:n}=nt(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=at(this,"clock_time_get",(function(t,e,n){if(0===(n=Number(n)))return 28;const{view:r}=nt(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()/1e3,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=at(this,"fd_advise",(function(t,e,n,r){return 52})),this.fd_fdstat_get=at(this,"fd_fdstat_get",(function(t,e){if(0===(e=Number(e)))return 28;const n=tt.get(this).fds.get(t,BigInt(0),BigInt(0)),{view:r}=nt(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=at(this,"fd_fdstat_set_flags",(function(t,e){return 52})),this.fd_fdstat_set_rights=at(this,"fd_fdstat_set_rights",(function(t,e,n){const r=tt.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=at(this,"fd_prestat_get",(function(t,e){if(0===(e=Number(e)))return 28;const n=tt.get(this);let r;try{r=n.fds.get(t,BigInt(0),BigInt(0))}catch(t){if(t instanceof b)return t.errno;throw t}if(1!==r.preopen)return 28;const{view:i}=nt(this);return i.setUint32(e,0,!0),i.setUint32(e+4,ft.encode(r.path).length,!0),0})),this.fd_prestat_dir_name=at(this,"fd_prestat_dir_name",(function(t,e,n){if(e=Number(e),n=Number(n),0===e)return 28;const r=tt.get(this).fds.get(t,BigInt(0),BigInt(0));if(1!==r.preopen)return 8;const i=ft.encode(r.path);if(i.length>n)return 42;const{HEAPU8:s}=nt(this);return s.set(i,e),0})),this.fd_seek=at(this,"fd_seek",(function(t,e,n,r){if(0===(r=Number(r)))return 28;if(0===t||1===t||2===t)return 0;const i=tt.get(this).fds.get(t,A.FD_SEEK,BigInt(0)).seek(e,n),{view:s}=nt(this);return s.setBigUint64(r,i,!0),0})),this.fd_tell=at(this,"fd_tell",(function(t,e){const n=tt.get(this).fds.get(t,A.FD_TELL,BigInt(0)),r=BigInt(n.pos),{view:i}=nt(this);return i.setBigUint64(Number(e),r,!0),0})),this.poll_oneoff=at(this,"poll_oneoff",(function(t,e,n,r){if(t=Number(t),e=Number(e),r=Number(r),n=Number(n),n>>>=0,0===t||0===e||0===n||0===r)return 28;const{view:i}=nt(this);i.setUint32(r,0,!0);let s,o=0,a=BigInt(0),c=BigInt(0),u=0,f=BigInt(0);const h=Array(n);for(o=0;o<n;o++){s=t+48*o;const e=i.getBigUint64(s,!0),n=i.getUint8(s+8),r=i.getUint32(s+16,!0),a=i.getBigUint64(s+24,!0),c=i.getBigUint64(s+32,!0),u=i.getUint16(s+40,!0);h[o]={userdata:e,type:n,u:{clock:{clock_id:r,timeout:a,precision:c,flags:u},fd_readwrite:{fd:r}}}}const g=[];for(o=0;o<n;o++)switch(s=h[o],s.type){case 0:if(1===s.u.clock.flags){const t=BigInt(Date.now())*BigInt(1e6);c=s.u.clock.timeout-t}else c=s.u.clock.timeout;(0===u||c<f)&&(f=c,a=s.userdata,u=1);break;case 1:case 2:g.push(s);break;default:return 28}if(g.length>0){for(o=0;o<g.length;o++){const t=g[o],n=e+32*o;i.setBigUint64(n,t.userdata,!0),i.setUint32(n+8,52,!0),i.setUint32(n+12,t.type,!0),i.setBigUint64(n+16,BigInt(0),!0),i.setUint16(n+24,0,!0),i.setUint32(r,1,!0)}return i.setUint32(r,g.length,!0),0}if(u){!function(t,e){const n=Date.now()+t;let r=!1;for(;Date.now()<n;)if(e()){r=!0;break}}(Number(f/BigInt(1e6)),(()=>!1));const t=e;i.setBigUint64(t,a,!0),i.setUint32(t+8,0,!0),i.setUint32(t+12,0,!0),i.setUint32(r,1,!0)}return 0})),this.proc_exit=at(this,"proc_exit",(function(t){return"object"==typeof process&&null!==process&&"function"==typeof process.exit&&process.exit(t),0})),this.proc_raise=at(this,"proc_raise",(function(t){return 52})),this.sched_yield=at(this,"sched_yield",(function(){return 0})),this.random_get="undefined"!=typeof crypto&&"function"==typeof crypto.getRandomValues?at(this,"random_get",(function(t,e){if(0===(t=Number(t)))return 28;e=Number(e);const{HEAPU8:n,view:r}=nt(this);if("function"==typeof SharedArrayBuffer&&n.buffer instanceof SharedArrayBuffer||"[object SharedArrayBuffer]"===Object.prototype.toString.call(n.buffer)){for(let n=t;n<t+e;++n)r.setUint8(n,Math.floor(256*Math.random()));return 0}let i;const s=65536;for(i=0;i+s<e;i+=s)crypto.getRandomValues(n.subarray(t+i,t+i+s));return crypto.getRandomValues(n.subarray(t+i,t+e)),0})):at(this,"random_get",(function(t,e){if(0===(t=Number(t)))return 28;e=Number(e);const{view:n}=nt(this);for(let r=t;r<t+e;++r)n.setUint8(r,Math.floor(256*Math.random()));return 0})),this.sock_recv=at(this,"sock_recv",(function(){return 58})),this.sock_send=at(this,"sock_send",(function(){return 58})),this.sock_shutdown=at(this,"sock_shutdown",(function(){return 58})),this.sock_accept=at(this,"sock_accept",(function(){return 58})),tt.set(this,{fds:r,args:e,env:n}),s&&et.set(this,s);const c=this;function u(t,e,n,r,s){c[t]=i?o?o.wrapImportFunction(at(c,t,n)):Z(at(c,t,n),r,s):at(c,t,e)}function f(t,e,n,r){const i=tt.get(this).fds.get(t,A.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 h(t,e,n,r){const i=(e&(A.FD_READ|A.FD_READDIR))!==BigInt(0),s=(e&(A.FD_DATASYNC|A.FD_WRITE|A.FD_ALLOCATE|A.FD_FILESTAT_SET_SIZE))!==BigInt(0);let o=s?i?2:1:0,a=A.PATH_OPEN,c=e|n;return 0!=(1&t)&&(o|=64,a|=A.PATH_CREATE_FILE),0!=(2&t)&&(o|=65536),0!=(4&t)&&(o|=128),0!=(8&t)&&(o|=512,a|=A.PATH_FILESTAT_SET_SIZE),0!=(1&r)&&(o|=1024),0!=(2&r)&&(c|=A.FD_DATASYNC),0!=(4&r)&&(o|=2048),0!=(8&r)&&(o|=1052672,c|=A.FD_SYNC),0!=(16&r)&&(o|=1052672,c|=A.FD_SYNC),s&&0==(1536&o)&&(c|=A.FD_SEEK),{flags:o,needed_base:a,needed_inheriting:c}}u("fd_allocate",(function(t,e,n){const r=tt.get(this),i=rt(this),s=r.fds.get(t,A.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=tt.get(this).fds.get(t,A.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=tt.get(this),n=e.fds.get(t,BigInt(0),BigInt(0));return rt(this).closeSync(n.fd),e.fds.remove(t),0}),(async function(t){const e=tt.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=tt.get(this).fds.get(t,A.FD_DATASYNC,BigInt(0));return rt(this).fdatasyncSync(e.fd),0}),(async function(t){const e=tt.get(this).fds.get(t,A.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=tt.get(this).fds.get(t,A.FD_FILESTAT_GET,BigInt(0)),r=rt(this).fstatSync(n.fd,{bigint:!0}),{view:i}=nt(this);return z(i,e,r),0}),(async function(t,e){if(0===(e=Number(e)))return 28;const n=tt.get(this).fds.get(t,A.FD_FILESTAT_GET,BigInt(0)).fd,r=await n.stat({bigint:!0}),{view:i}=nt(this);return z(i,e,r),0}),["i32","i32"],["i32"]),u("fd_filestat_set_size",(function(t,e){const n=tt.get(this).fds.get(t,A.FD_FILESTAT_SET_SIZE,BigInt(0));return rt(this).ftruncateSync(n.fd,Number(e)),0}),(async function(t,e){const n=tt.get(this).fds.get(t,A.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){if(lt(r))return 28;const{fileDescriptor:i,atim:s,mtim:o}=f.call(this,t,e,n,r);return rt(this).futimesSync(i.fd,Number(s),Number(o)),0}),(async function(t,e,n,r){if(lt(r))return 28;const{fileDescriptor:i,atim:s,mtim:o}=f.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&&n||0===i||r>gt)return 28;const{HEAPU8:s,view:o}=nt(this),a=tt.get(this).fds.get(t,A.FD_READ|A.FD_SEEK,BigInt(0));if(!n)return o.setUint32(i,0,!0),0;let c=0;const u=Array.from({length:Number(n)},((t,n)=>{const r=e+8*n,i=o.getInt32(r,!0),a=o.getUint32(r+4,!0);return c+=a,s.subarray(i,i+a)}));let f=0;const h=(()=>{try{return new Uint8Array(new SharedArrayBuffer(c))}catch(t){return new Uint8Array(c)}})();h._isBuffer=!0;const g=rt(this).readSync(a.fd,h,0,h.length,Number(r));return f=h?Q(u,h.subarray(0,g)):0,o.setUint32(i,f,!0),0}),(async function(t,e,n,r,i){if(e=Number(e),i=Number(i),0===e&&n||0===i||r>gt)return 28;const{HEAPU8:s,view:o}=nt(this),a=tt.get(this).fds.get(t,A.FD_READ|A.FD_SEEK,BigInt(0));if(!n)return o.setUint32(i,0,!0),0;let c=0;const u=Array.from({length:Number(n)},((t,n)=>{const r=e+8*n,i=o.getInt32(r,!0),a=o.getUint32(r+4,!0);return c+=a,s.subarray(i,i+a)}));let f=0;const h=new Uint8Array(c);h._isBuffer=!0;const{bytesRead:g}=await a.fd.read(h,0,h.length,Number(r));return f=h?Q(u,h.subarray(0,g)):0,o.setUint32(i,f,!0),0}),["i32","i32","i32","i64","i32"],["i32"]),u("fd_pwrite",(function(t,e,n,r,i){if(e=Number(e),i=Number(i),0===e&&n||0===i||r>gt)return 28;const{HEAPU8:s,view:o}=nt(this),a=tt.get(this).fds.get(t,A.FD_WRITE|A.FD_SEEK,BigInt(0));if(!n)return o.setUint32(i,0,!0),0;const c=k(Array.from({length:Number(n)},((t,n)=>{const r=e+8*n,i=o.getInt32(r,!0),a=o.getUint32(r+4,!0);return s.subarray(i,i+a)}))),u=rt(this).writeSync(a.fd,c,0,c.length,Number(r));return o.setUint32(i,u,!0),0}),(async function(t,e,n,r,i){if(e=Number(e),i=Number(i),0===e&&n||0===i||r>gt)return 28;const{HEAPU8:s,view:o}=nt(this),a=tt.get(this).fds.get(t,A.FD_WRITE|A.FD_SEEK,BigInt(0));if(!n)return o.setUint32(i,0,!0),0;const c=k(Array.from({length:Number(n)},((t,n)=>{const r=e+8*n,i=o.getInt32(r,!0),a=o.getUint32(r+4,!0);return s.subarray(i,i+a)}))),{bytesWritten:u}=await a.fd.write(c,0,c.length,Number(r));return o.setUint32(i,u,!0),0}),["i32","i32","i32","i64","i32"],["i32"]),u("fd_read",(function(t,e,n,r){if(e=Number(e),r=Number(r),0===e&&n||0===r)return 28;const{HEAPU8:i,view:s}=nt(this),o=tt.get(this).fds.get(t,A.FD_READ,BigInt(0));if(!n)return s.setUint32(r,0,!0),0;let a=0;const c=Array.from({length:Number(n)},((t,n)=>{const r=e+8*n,o=s.getInt32(r,!0),c=s.getUint32(r+4,!0);return a+=c,i.subarray(o,o+c)}));let u,f=0;if(0===t){if("undefined"==typeof window||"function"!=typeof window.prompt)return 58;u=dt(),f=u?Q(c,u):0}else{u=(()=>{try{return new Uint8Array(new SharedArrayBuffer(a))}catch(t){return new Uint8Array(a)}})(),u._isBuffer=!0;const t=rt(this).readSync(o.fd,u,0,u.length,Number(o.pos));f=u?Q(c,u.subarray(0,t)):0,o.pos+=BigInt(f)}return s.setUint32(r,f,!0),0}),(async function(t,e,n,r){if(e=Number(e),r=Number(r),0===e&&n||0===r)return 28;const{HEAPU8:i,view:s}=nt(this),o=tt.get(this).fds.get(t,A.FD_READ,BigInt(0));if(!n)return s.setUint32(r,0,!0),0;let a=0;const c=Array.from({length:Number(n)},((t,n)=>{const r=e+8*n,o=s.getInt32(r,!0),c=s.getUint32(r+4,!0);return a+=c,i.subarray(o,o+c)}));let u,f=0;if(0===t){if("undefined"==typeof window||"function"!=typeof window.prompt)return 58;u=dt(),f=u?Q(c,u):0}else{u=new Uint8Array(a),u._isBuffer=!0;const{bytesRead:t}=await o.fd.read(u,0,u.length,Number(o.pos));f=u?Q(c,u.subarray(0,t)):0,o.pos+=BigInt(f)}return s.setUint32(r,f,!0),0}),["i32","i32","i32","i32"],["i32"]),u("fd_readdir",(function(t,e,n,r,i){if(e=Number(e),n=Number(n),i=Number(i),0===e||0===i)return 0;const s=tt.get(this).fds.get(t,A.FD_READDIR,BigInt(0)),o=rt(this),a=o.readdirSync(s.realPath,{withFileTypes:!0}),{HEAPU8:c,view:u}=nt(this);let f=0;for(let t=Number(r);t<a.length;t++){const r=ft.encode(a[t].name),i=o.statSync(m(s.realPath,a[t].name),{bigint:!0}),u=new Uint8Array(24+r.byteLength),h=new DataView(u.buffer);let g;h.setBigUint64(0,BigInt(t+1),!0),h.setBigUint64(8,BigInt(i.ino?i.ino:0),!0),h.setUint32(16,r.byteLength,!0),g=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,g),u.set(r,24);const d=u.slice(0,Math.min(u.length,n-f));c.set(d,e+f),f+=d.byteLength}return u.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=tt.get(this).fds.get(t,A.FD_READDIR,BigInt(0)),o=rt(this),a=await o.promises.readdir(s.realPath,{withFileTypes:!0}),{HEAPU8:c,view:u}=nt(this);let f=0;for(let t=Number(r);t<a.length;t++){const r=ft.encode(a[t].name),i=await o.promises.stat(m(s.realPath,a[t].name),{bigint:!0}),u=new Uint8Array(24+r.byteLength),h=new DataView(u.buffer);let g;h.setBigUint64(0,BigInt(t+1),!0),h.setBigUint64(8,BigInt(i.ino?i.ino:0),!0),h.setUint32(16,r.byteLength,!0),g=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,g),u.set(r,24);const d=u.slice(0,Math.min(u.length,n-f));c.set(d,e+f),f+=d.byteLength}return u.setUint32(i,f,!0),0}),["i32","i32","i32","i64","i32"],["i32"]),u("fd_renumber",(function(t,e){return tt.get(this).fds.renumber(e,t),0}),(async function(t,e){const n=tt.get(this);return await n.fds.renumber(e,t),0}),["i32","i32"],["i32"]),u("fd_sync",(function(t){const e=tt.get(this).fds.get(t,A.FD_SYNC,BigInt(0));return rt(this).fsyncSync(e.fd),0}),(async function(t){const e=tt.get(this).fds.get(t,A.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&&n||0===r)return 28;const{HEAPU8:i,view:s}=nt(this),o=tt.get(this).fds.get(t,A.FD_WRITE,BigInt(0));if(!n)return s.setUint32(r,0,!0),0;const a=k(Array.from({length:Number(n)},((t,n)=>{const r=e+8*n,o=s.getInt32(r,!0),a=s.getUint32(r+4,!0);return i.subarray(o,o+a)})));let c;if(1===t||2===t)c=o.write(a);else{c=rt(this).writeSync(o.fd,a,0,a.length,Number(o.pos)),o.pos+=BigInt(c)}return s.setUint32(r,c,!0),0}),(async function(t,e,n,r){if(e=Number(e),r=Number(r),0===e&&n||0===r)return 28;const{HEAPU8:i,view:s}=nt(this),o=tt.get(this).fds.get(t,A.FD_WRITE,BigInt(0));if(!n)return s.setUint32(r,0,!0),0;const a=k(Array.from({length:Number(n)},((t,n)=>{const r=e+8*n,o=s.getInt32(r,!0),a=s.getUint32(r+4,!0);return i.subarray(o,o+a)})));let c;return 1===t||2===t?c=o.write(a):(c=await(await o.fd.write(a,0,a.length,Number(o.pos))).bytesWritten,o.pos+=BigInt(c)),s.setUint32(r,c,!0),0}),["i32","i32","i32","i32"],["i32"]),u("path_create_directory",(function(t,e,n){if(e=Number(e),n=Number(n),0===e)return 28;const{HEAPU8:r}=nt(this),i=tt.get(this).fds.get(t,A.PATH_CREATE_DIRECTORY,BigInt(0));let s=ht.decode(a(r,e,e+n));s=m(i.realPath,s);return rt(this).mkdirSync(s),0}),(async function(t,e,n){if(e=Number(e),n=Number(n),0===e)return 28;const{HEAPU8:r}=nt(this),i=tt.get(this).fds.get(t,A.PATH_CREATE_DIRECTORY,BigInt(0));let s=ht.decode(a(r,e,e+n));s=m(i.realPath,s);const o=rt(this);return await o.promises.mkdir(s),0}),["i32","i32","i32"],["i32"]),u("path_filestat_get",(function(t,e,n,r,i){if(n=Number(n),r=Number(r),i=Number(i),0===n||0===i)return 28;const{HEAPU8:s,view:o}=nt(this),c=tt.get(this).fds.get(t,A.PATH_FILESTAT_GET,BigInt(0));let u=ht.decode(a(s,n,n+r));const f=rt(this);let h;return u=m(c.realPath,u),h=1==(1&e)?f.statSync(u,{bigint:!0}):f.lstatSync(u,{bigint:!0}),z(o,i,h),0}),(async function(t,e,n,r,i){if(n=Number(n),r=Number(r),i=Number(i),0===n||0===i)return 28;const{HEAPU8:s,view:o}=nt(this),c=tt.get(this).fds.get(t,A.PATH_FILESTAT_GET,BigInt(0));let u=ht.decode(a(s,n,n+r));const f=rt(this);let h;return u=m(c.realPath,u),h=1==(1&e)?await f.promises.stat(u,{bigint:!0}):await f.promises.lstat(u,{bigint:!0}),z(o,i,h),0}),["i32","i32","i32","i32","i32"],["i32"]),u("path_filestat_set_times",(function(t,e,n,r,i,s,o){if(n=Number(n),r=Number(r),0===n)return 28;const{HEAPU8:c}=nt(this),u=tt.get(this).fds.get(t,A.PATH_FILESTAT_SET_TIMES,BigInt(0));if(lt(o))return 28;const f=rt(this),h=ct(f,u,ht.decode(a(c,n,n+r)),e);return 2==(2&o)&&(i=BigInt(1e6*Date.now())),8==(8&o)&&(s=BigInt(1e6*Date.now())),f.utimesSync(h,Number(i),Number(s)),0}),(async function(t,e,n,r,i,s,o){if(n=Number(n),r=Number(r),0===n)return 28;const{HEAPU8:c}=nt(this),u=tt.get(this).fds.get(t,A.PATH_FILESTAT_SET_TIMES,BigInt(0));if(lt(o))return 28;const f=rt(this),h=await ut(f,u,ht.decode(a(c,n,n+r)),e);return 2==(2&o)&&(i=BigInt(1e6*Date.now())),8==(8&o)&&(s=BigInt(1e6*Date.now())),await f.promises.utimes(h,Number(i),Number(s)),0}),["i32","i32","i32","i32","i64","i64","i32"],["i32"]),u("path_link",(function(t,e,n,r,i,s,o){if(n=Number(n),r=Number(r),s=Number(s),o=Number(o),0===n||0===s)return 28;const c=tt.get(this);let u,f;t===i?u=f=c.fds.get(t,A.PATH_LINK_SOURCE|A.PATH_LINK_TARGET,BigInt(0)):(u=c.fds.get(t,A.PATH_LINK_SOURCE,BigInt(0)),f=c.fds.get(i,A.PATH_LINK_TARGET,BigInt(0)));const{HEAPU8:h}=nt(this),g=rt(this),d=ct(g,u,ht.decode(a(h,n,n+r)),e),l=m(f.realPath,ht.decode(a(h,s,s+o)));return g.linkSync(d,l),0}),(async function(t,e,n,r,i,s,o){if(n=Number(n),r=Number(r),s=Number(s),o=Number(o),0===n||0===s)return 28;const c=tt.get(this);let u,f;t===i?u=f=c.fds.get(t,A.PATH_LINK_SOURCE|A.PATH_LINK_TARGET,BigInt(0)):(u=c.fds.get(t,A.PATH_LINK_SOURCE,BigInt(0)),f=c.fds.get(i,A.PATH_LINK_TARGET,BigInt(0)));const{HEAPU8:h}=nt(this),g=rt(this),d=await ut(g,u,ht.decode(a(h,n,n+r)),e),l=m(f.realPath,ht.decode(a(h,s,s+o)));return await g.promises.link(d,l),0}),["i32","i32","i32","i32","i32","i32","i32"],["i32"]),u("path_open",(function(t,e,n,r,i,s,o,c,u){if(n=Number(n),u=Number(u),0===n||0===u)return 28;r=Number(r),s=BigInt(s),o=BigInt(o);const{flags:f,needed_base:g,needed_inheriting:d}=h(i,s,o,c),l=tt.get(this),_=l.fds.get(t,g,d),p=nt(this),E=p.HEAPU8,y=ht.decode(a(E,n,n+r)),I=rt(this),m=ct(I,_,y,e),A=I.openSync(m,f,438),b=l.fds.getFileTypeByFd(A);if(3!==b&&(0!=(2&i)||m.endsWith("/")))return 54;const{base:T,inheriting:w}=O(l.fds.stdio,A,f,b),B=l.fds.insert(A,m,m,b,s&T,o&w,0),N=I.fstatSync(A,{bigint:!0});N.isFile()&&(B.size=N.size,0!=(1024&f)&&(B.pos=N.size));return p.view.setInt32(u,B.id,!0),0}),(async function(t,e,n,r,i,s,o,c,u){if(n=Number(n),u=Number(u),0===n||0===u)return 28;r=Number(r),s=BigInt(s),o=BigInt(o);const{flags:f,needed_base:g,needed_inheriting:d}=h(i,s,o,c),l=tt.get(this),_=l.fds.get(t,g,d),p=nt(this),E=p.HEAPU8,y=ht.decode(a(E,n,n+r)),I=rt(this),m=await ut(I,_,y,e),A=await I.promises.open(m,f,438),b=await l.fds.getFileTypeByFd(A);if(0!=(2&i)&&3!==b)return 54;const{base:T,inheriting:w}=O(l.fds.stdio,A.fd,f,b),B=l.fds.insert(A,m,m,b,s&T,o&w,0),N=await A.stat({bigint:!0});N.isFile()&&(B.size=N.size,0!=(1024&f)&&(B.pos=N.size));return p.view.setInt32(u,B.id,!0),0}),["i32","i32","i32","i32","i32","i64","i64","i32","i32"],["i32"]),u("path_readlink",(function(t,e,n,r,i,s){if(e=Number(e),n=Number(n),r=Number(r),i=Number(i),s=Number(s),0===e||0===r||0===s)return 28;const{HEAPU8:o,view:c}=nt(this),u=tt.get(this).fds.get(t,A.PATH_READLINK,BigInt(0));let f=ht.decode(a(o,e,e+n));f=m(u.realPath,f);const h=rt(this).readlinkSync(f),g=ft.encode(h),d=Math.min(g.length,i);return d>=i?42:(o.set(g.subarray(0,d),r),o[r+d]=0,c.setUint32(s,d,!0),0)}),(async function(t,e,n,r,i,s){if(e=Number(e),n=Number(n),r=Number(r),i=Number(i),s=Number(s),0===e||0===r||0===s)return 28;const{HEAPU8:o,view:c}=nt(this),u=tt.get(this).fds.get(t,A.PATH_READLINK,BigInt(0));let f=ht.decode(a(o,e,e+n));f=m(u.realPath,f);const h=rt(this),g=await h.promises.readlink(f),d=ft.encode(g),l=Math.min(d.length,i);return l>=i?42:(o.set(d.subarray(0,l),r),o[r+l]=0,c.setUint32(s,l,!0),0)}),["i32","i32","i32","i32","i32","i32"],["i32"]),u("path_remove_directory",(function(t,e,n){if(e=Number(e),n=Number(n),0===e)return 28;const{HEAPU8:r}=nt(this),i=tt.get(this).fds.get(t,A.PATH_REMOVE_DIRECTORY,BigInt(0));let s=ht.decode(a(r,e,e+n));s=m(i.realPath,s);return rt(this).rmdirSync(s),0}),(async function(t,e,n){if(e=Number(e),n=Number(n),0===e)return 28;const{HEAPU8:r}=nt(this),i=tt.get(this).fds.get(t,A.PATH_REMOVE_DIRECTORY,BigInt(0));let s=ht.decode(a(r,e,e+n));s=m(i.realPath,s);const o=rt(this);return await o.promises.rmdir(s),0}),["i32","i32","i32"],["i32"]),u("path_rename",(function(t,e,n,r,i,s){if(e=Number(e),n=Number(n),i=Number(i),s=Number(s),0===e||0===i)return 28;const o=tt.get(this);let c,u;t===r?c=u=o.fds.get(t,A.PATH_RENAME_SOURCE|A.PATH_RENAME_TARGET,BigInt(0)):(c=o.fds.get(t,A.PATH_RENAME_SOURCE,BigInt(0)),u=o.fds.get(r,A.PATH_RENAME_TARGET,BigInt(0)));const{HEAPU8:f}=nt(this),h=m(c.realPath,ht.decode(a(f,e,e+n))),g=m(u.realPath,ht.decode(a(f,i,i+s)));return rt(this).renameSync(h,g),0}),(async function(t,e,n,r,i,s){if(e=Number(e),n=Number(n),i=Number(i),s=Number(s),0===e||0===i)return 28;const o=tt.get(this);let c,u;t===r?c=u=o.fds.get(t,A.PATH_RENAME_SOURCE|A.PATH_RENAME_TARGET,BigInt(0)):(c=o.fds.get(t,A.PATH_RENAME_SOURCE,BigInt(0)),u=o.fds.get(r,A.PATH_RENAME_TARGET,BigInt(0)));const{HEAPU8:f}=nt(this),h=m(c.realPath,ht.decode(a(f,e,e+n))),g=m(u.realPath,ht.decode(a(f,i,i+s))),d=rt(this);return await d.promises.rename(h,g),0}),["i32","i32","i32","i32","i32","i32"],["i32"]),u("path_symlink",(function(t,e,n,r,i){if(t=Number(t),e=Number(e),r=Number(r),i=Number(i),0===t||0===r)return 28;const{HEAPU8:s}=nt(this),o=tt.get(this).fds.get(n,A.PATH_SYMLINK,BigInt(0)),c=ht.decode(a(s,t,t+e));if(c.length>0&&"/"===c[0])return 63;let u=ht.decode(a(s,r,r+i));u=m(o.realPath,u);return rt(this).symlinkSync(c,u),0}),(async function(t,e,n,r,i){if(t=Number(t),e=Number(e),r=Number(r),i=Number(i),0===t||0===r)return 28;const{HEAPU8:s}=nt(this),o=tt.get(this).fds.get(n,A.PATH_SYMLINK,BigInt(0)),c=ht.decode(a(s,t,t+e));let u=ht.decode(a(s,r,r+i));u=m(o.realPath,u);const f=rt(this);return await f.promises.symlink(c,u),0}),["i32","i32","i32","i32","i32"],["i32"]),u("path_unlink_file",(function(t,e,n){if(e=Number(e),n=Number(n),0===e)return 28;const{HEAPU8:r}=nt(this),i=tt.get(this).fds.get(t,A.PATH_UNLINK_FILE,BigInt(0));let s=ht.decode(a(r,e,e+n));s=m(i.realPath,s);return rt(this).unlinkSync(s),0}),(async function(t,e,n){if(e=Number(e),n=Number(n),0===e)return 28;const{HEAPU8:r}=nt(this),i=tt.get(this).fds.get(t,A.PATH_UNLINK_FILE,BigInt(0));let s=ht.decode(a(r,e,e+n));s=m(i.realPath,s);const o=rt(this);return await o.promises.unlink(s),0}),["i32","i32","i32"],["i32"]),this._setMemory=function(e){if(!(e instanceof t.Memory))throw new TypeError('"instance.exports.memory" property must be a WebAssembly.Memory');J.set(c,$(e))}}static createSync(t,e,n,r,i,s,o){const a=new W({size:3,in:r[0],out:r[1],err:r[2],fs:i,print:s,printErr:o}),c=new _t(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 c}static async createAsync(t,e,n,r,i,s,o,a){const c=new j({size:3,in:r[0],out:r[1],err:r[2],print:s,printErr:o}),u=new _t(t,e,c,!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 c.insertPreopen(s,e.mappedPath,r)}return u}}const pt=Object.freeze(Object.create(null)),Et=Symbol("kExitCode"),yt=Symbol("kSetMemory"),It=Symbol("kStarted"),mt=Symbol("kInstance"),At=Symbol("kBindingName");function bt(t){var i;let s;if(e(t,"options"),void 0!==t.version)switch(n(t.version,"options.version"),t.version){case"unstable":s=_t,this[At]="wasi_unstable";break;case"preview1":s=_t,this[At]="wasi_snapshot_preview1";break;default:throw new TypeError(`unsupported WASI version "${t.version}"`)}else s=_t,this[At]="wasi_snapshot_preview1";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 o=(null!==(i=t.args)&&void 0!==i?i:[]).map(String),a=[];void 0!==t.env&&(e(t.env,"options.env"),Object.entries(t.env).forEach((({0:t,1:e})=>{void 0!==e&&a.push(`${t}=${e}`)})));const c=[];if(void 0!==t.preopens&&(e(t.preopens,"options.preopens"),Object.entries(t.preopens).forEach((({0:t,1:e})=>c.push({mappedPath:String(t),realPath:String(e)})))),c.length>0){if(void 0===t.fs)throw new Error("filesystem is disabled, can not preopen directory");try{e(t.fs,"options.fs")}catch(t){throw new TypeError("Node.js fs like implementation is not provided")}}void 0!==t.print&&r(t.print,"options.print"),void 0!==t.printErr&&r(t.printErr,"options.printErr"),void 0!==t.returnOnExit&&function(t,e){if("boolean"!=typeof t)throw new TypeError(`${e} must be a boolean. Received ${null===t?"null":typeof t}`)}(t.returnOnExit,"options.returnOnExit");return{args:o,env:a,preopens:c,stdio:[0,1,2],_WASI:s}}function Tt(t,e){this[yt]=t,this.wasiImport=e,this[It]=!1,this[Et]=0,this[mt]=void 0}class wt{constructor(t=pt){const{args:e,env:n,preopens:r,stdio:i,_WASI:s}=bt.call(this,t),o=s.createSync(e,n,r,i,t.fs,t.print,t.printErr),a=o._setMemory;delete o._setMemory,Tt.call(this,a,o),t.returnOnExit&&(o.proc_exit=Bt.bind(this))}finalizeBindings(t,n){var r,{memory:i=(null===(r=null==t?void 0:t.exports)||void 0===r?void 0:r.memory)}=void 0===n?{}:n;if(this[It])throw new Error("WASI instance has already started");e(t,"instance"),e(t.exports,"instance.exports"),this[yt](i),this[mt]=t,this[It]=!0}start(t){this.finalizeBindings(t);const{_start:e,_initialize:n}=this[mt].exports;let s;r(e,"instance.exports._start"),i(n,"instance.exports._initialize");try{s=e()}catch(t){if(t!==Et)throw t}return s instanceof Promise?s.then((()=>this[Et]),(t=>{if(t!==Et)throw t;return this[Et]})):this[Et]}initialize(t){this.finalizeBindings(t);const{_start:e,_initialize:n}=this[mt].exports;if(i(e,"instance.exports._start"),void 0!==n)return r(n,"instance.exports._initialize"),n()}getImportObject(){return{[this[At]]:this.wasiImport}}}function Bt(t){throw this[Et]=t,Et}async function Nt(t=pt){const n=Object.create(wt.prototype),{args:i,env:s,preopens:o,stdio:a,_WASI:c}=bt.call(n,t);void 0!==t.asyncify&&(e(t.asyncify,"options.asyncify"),r(t.asyncify.wrapImportFunction,"options.asyncify.wrapImportFunction"));const u=await c.createAsync(i,s,o,a,t.fs,t.print,t.printErr,t.asyncify),f=u._setMemory;return delete u._setMemory,Tt.call(n,f,u),t.returnOnExit&&(u.proc_exit=Bt.bind(n)),n}export{f as Asyncify,Y as Memory,wt as WASI,G as WebAssemblyMemory,l as asyncifyLoad,p as asyncifyLoadSync,Nt as createAsyncWASI,$ as extendMemory,d as load,_ as loadSync,q as wrapAsyncExport,Z as wrapAsyncImport,X 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}function a(t,e,n){return"function"==typeof SharedArrayBuffer&&t.buffer instanceof SharedArrayBuffer||"[object SharedArrayBuffer]"===Object.prototype.toString.call(t.buffer.constructor)?t.slice(e,n):t.subarray(e,n)}const c=["asyncify_get_state","asyncify_start_rewind","asyncify_start_unwind","asyncify_stop_rewind","asyncify_stop_unwind"];function u(t,e,n,r){if("function"!=typeof t.exports[r]||n<=0)return{wasm64:e,dataPtr:16,start:e?32:24,end:1024};const i=t.exports[r],s=e?Number(i(BigInt(16)+BigInt(n))):i(8+n);if(0===s)throw new Error("Allocate asyncify data failed");return e?{wasm64:e,dataPtr:s,start:s+16,end:s+16+n}:{wasm64:e,dataPtr:s,start:s+8,end:s+8+n}}class f{constructor(){this.value=void 0,this.exports=void 0,this.dataPtr=0}init(e,n,r){var i,s;if(this.exports)throw new Error("Asyncify has been initialized");if(!(e instanceof t.Memory))throw new TypeError("Require WebAssembly.Memory object");const o=n.exports;for(let t=0;t<c.length;++t)if("function"!=typeof o[c[t]])throw new TypeError("Invalid asyncify wasm");let a;const f=Boolean(r.wasm64);a=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=a.dataPtr,f?new BigInt64Array(e.buffer,this.dataPtr).set([BigInt(a.start),BigInt(a.end)]):new Int32Array(e.buffer,this.dataPtr).set([a.start,a.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!==c.indexOf(n)||"function"!=typeof t;return Array.isArray(e)&&(r=r||-1===e.indexOf(n)),r?t:this.wrapExportFunction(t)}))}}function h(t){if(t&&"object"!=typeof t)throw new TypeError("imports must be an object or undefined")}function d(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 g(e,n){let r;if(h(n),n=null!=n?n:{},e instanceof ArrayBuffer||ArrayBuffer.isView(e))return t.instantiate(e,n);if(e instanceof t.Module)return t.instantiate(e,n).then((t=>({instance:t,module:e})));if("string"!=typeof e&&!(e instanceof URL))throw new TypeError("Invalid source");if("function"==typeof t.instantiateStreaming){let i;try{i=fetch(e),r=t.instantiateStreaming(i,n).catch((()=>d(e,n)))}catch(t){r=d(e,n)}}else r=d(e,n);return r}function l(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)}}))}function _(e,n){let r;if(h(n),n=null!=n?n:{},e instanceof ArrayBuffer||ArrayBuffer.isView(e))r=new t.Module(e);else{if(!(e instanceof WebAssembly.Module))throw new TypeError("Invalid source");r=e}return{instance:new t.Instance(r,n),module:r}}function p(t,e,n){var r;h(n),n=null!=n?n:{};const i=new f,s=_(e,n=i.wrapImports(n)),o=s.instance.exports.memory||(null===(r=n.env)||void 0===r?void 0:r.memory);return{module:s.module,instance:i.init(o,s.instance,t)}}const y=46,E=47,I=92,m=58,A=65,b=90,T=97,w=122;function B(t){return t===E||t===I}function N(t){return t>=A&&t<=b||t>=T&&t<=w}const S="undefined"!=typeof process&&"win32"===process.platform;function P(t){return t===E}function D(t,e,n,r){let i="",s=0,o=-1,a=0,c=0;for(let u=0;u<=t.length;++u){if(u<t.length)c=t.charCodeAt(u);else{if(r(c))break;c=E}if(r(c)){if(o===u-1||1===a);else if(2===a){if(i.length<2||2!==s||i.charCodeAt(i.length-1)!==y||i.charCodeAt(i.length-2)!==y){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=u,a=0;continue}if(0!==i.length){i="",s=0,o=u,a=0;continue}}e&&(i+=i.length>0?`${n}..`:"..",s=2)}else i.length>0?i+=`${n}${t.slice(o+1,u)}`:i=t.slice(o+1,u),s=u-o-1;o=u,a=0}else c===y&&-1!==a?++a:a=-1}return i}function F(...t){if(S)return function(t){let e="",r="",i=!1;for(let s=t.length-1;s>=-1;s--){let o;if(s>=0){if(o=t[s],n(o,"path"),0===o.length)continue}else if(0===e.length)o="undefined"!=typeof process&&"function"==typeof process.cwd?process.cwd():"";else{const t=`=${e}`,n="undefined"!=typeof process?process.env:void 0;o=n&&"string"==typeof n[t]?n[t]:"undefined"!=typeof process&&"function"==typeof process.cwd?process.cwd():"",(void 0===o||o.slice(0,2).toLowerCase()!==e.toLowerCase()&&o.charCodeAt(2)===I)&&(o=`${e}\\`)}const a=o.length;let c=0,u="",f=!1;const h=o.charCodeAt(0);if(1===a)B(h)&&(c=1,f=!0);else if(B(h))if(f=!0,B(o.charCodeAt(1))){let t=2,e=t;for(;t<a&&!B(o.charCodeAt(t));)t++;if(t<a&&t!==e){const n=o.slice(e,t);for(e=t;t<a&&B(o.charCodeAt(t));)t++;if(t<a&&t!==e){for(e=t;t<a&&!B(o.charCodeAt(t));)t++;t!==a&&t===e||(u=`\\\\${n}\\${o.slice(e,t)}`,c=t)}}}else c=1;else N(h)&&o.charCodeAt(1)===m&&(u=o.slice(0,2),c=2,a>2&&B(o.charCodeAt(2))&&(f=!0,c=3));if(u.length>0)if(e.length>0){if(u.toLowerCase()!==e.toLowerCase())continue}else e=u;if(i){if(e.length>0)break}else if(r=`${o.slice(c)}\\${r}`,i=f,f&&e.length>0)break}return r=D(r,!i,"\\",B),e+(i?"\\":"")+r||"."}(t);let e="",r=!1;for(let i=t.length-1;i>=-1&&!r;i--){const s=i>=0?t[i]:"/";n(s,"path"),0!==s.length&&(e=`${s}/${e}`,r=s.charCodeAt(0)===E)}return e=D(e,!r,"/",P),r?`/${e}`:e.length>0?e:"."}const v={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 U 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(U.prototype,"name",{configurable:!0,writable:!0,value:"WasiError"});const R=v.FD_DATASYNC|v.FD_READ|v.FD_SEEK|v.FD_FDSTAT_SET_FLAGS|v.FD_SYNC|v.FD_TELL|v.FD_WRITE|v.FD_ADVISE|v.FD_ALLOCATE|v.PATH_CREATE_DIRECTORY|v.PATH_CREATE_FILE|v.PATH_LINK_SOURCE|v.PATH_LINK_TARGET|v.PATH_OPEN|v.FD_READDIR|v.PATH_READLINK|v.PATH_RENAME_SOURCE|v.PATH_RENAME_TARGET|v.PATH_FILESTAT_GET|v.PATH_FILESTAT_SET_SIZE|v.PATH_FILESTAT_SET_TIMES|v.FD_FILESTAT_GET|v.FD_FILESTAT_SET_TIMES|v.FD_FILESTAT_SET_SIZE|v.PATH_SYMLINK|v.PATH_UNLINK_FILE|v.PATH_REMOVE_DIRECTORY|v.POLL_FD_READWRITE|v.SOCK_SHUTDOWN|v.SOCK_ACCEPT,L=R,H=R,O=R,C=R,k=v.FD_DATASYNC|v.FD_READ|v.FD_SEEK|v.FD_FDSTAT_SET_FLAGS|v.FD_SYNC|v.FD_TELL|v.FD_WRITE|v.FD_ADVISE|v.FD_ALLOCATE|v.FD_FILESTAT_GET|v.FD_FILESTAT_SET_SIZE|v.FD_FILESTAT_SET_TIMES|v.POLL_FD_READWRITE,x=BigInt(0),M=v.FD_FDSTAT_SET_FLAGS|v.FD_SYNC|v.FD_ADVISE|v.PATH_CREATE_DIRECTORY|v.PATH_CREATE_FILE|v.PATH_LINK_SOURCE|v.PATH_LINK_TARGET|v.PATH_OPEN|v.FD_READDIR|v.PATH_READLINK|v.PATH_RENAME_SOURCE|v.PATH_RENAME_TARGET|v.PATH_FILESTAT_GET|v.PATH_FILESTAT_SET_SIZE|v.PATH_FILESTAT_SET_TIMES|v.FD_FILESTAT_GET|v.FD_FILESTAT_SET_TIMES|v.PATH_SYMLINK|v.PATH_UNLINK_FILE|v.PATH_REMOVE_DIRECTORY|v.POLL_FD_READWRITE,z=M|k,K=v.FD_READ|v.FD_FDSTAT_SET_FLAGS|v.FD_WRITE|v.FD_FILESTAT_GET|v.POLL_FD_READWRITE|v.SOCK_SHUTDOWN,W=R,$=v.FD_READ|v.FD_FDSTAT_SET_FLAGS|v.FD_WRITE|v.FD_FILESTAT_GET|v.POLL_FD_READWRITE,j=BigInt(0);function G(t,e,n,r){const i={base:BigInt(0),inheriting:BigInt(0)};if(0===r)throw new U("Unknown file type",28);switch(r){case 4:i.base=k,i.inheriting=x;break;case 3:i.base=M,i.inheriting=z;break;case 6:case 5:i.base=K,i.inheriting=W;break;case 2:-1!==t.indexOf(e)?(i.base=$,i.inheriting=j):(i.base=O,i.inheriting=C);break;case 1:i.base=L,i.inheriting=H;break;default:i.base=BigInt(0),i.inheriting=BigInt(0)}const s=3&n;return 0===s?i.base&=~v.FD_WRITE:1===s&&(i.base&=~v.FD_READ),i}function Y(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 V{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 U("Unknown whence",29);this.pos=BigInt(this.size)-BigInt(t)}return this.pos}}class Z extends V{constructor(t,e,n,r,i,s,o,a,c){super(e,n,r,i,s,o,a,c),this._log=t,this._buf=null}write(t){const e=t;if(this._buf&&(t=Y([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 q(t){return t.isBlockDevice()?1:t.isCharacterDevice()?2:t.isDirectory()?3:t.isSocket()?6:t.isFile()?4:t.isSymbolicLink()?7:0}function X(t,e,n){t.setBigUint64(e,n.dev,!0),t.setBigUint64(e+8,n.ino,!0),t.setBigUint64(e+16,BigInt(q(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 Q{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}=G(this.stdio,t,2,2),s=this.insert(t,n,n,2,r,i,0);if(s.id!==e)throw new U(`id: ${s.id} !== expected: ${e}`,8);return s}insert(t,e,n,r,i,s,o){var a,c;let u,f=-1;if(this.used>=this.size){const t=2*this.size;this.fds.length=t,f=this.size,this.size=t}else for(let t=0;t<this.size;++t)if(null==this.fds[t]){f=t;break}return u="<stdout>"===e?new Z(null!==(a=this.print)&&void 0!==a?a:console.log,f,t,e,n,r,i,s,o):"<stderr>"===e?new Z(null!==(c=this.printErr)&&void 0!==c?c:console.error,f,t,e,n,r,i,s,o):new V(f,t,e,n,r,i,s,o),this.fds[f]=u,this.used++,u}get(t,e,n){if(t>=this.size)throw new U("Invalid fd",8);const r=this.fds[t];if(!r||r.id!==t)throw new U("Bad file descriptor",8);if((~r.rightsBase&e)!==BigInt(0)||(~r.rightsInheriting&n)!==BigInt(0))throw new U("Capabilities insufficient",76);return r}remove(t){if(t>=this.size)throw new U("Invalid fd",8);const e=this.fds[t];if(!e||e.id!==t)throw new U("Bad file descriptor",8);this.fds[t]=void 0,this.used--}}class J extends Q{constructor(t){super(t),this.fs=t.fs}getFileTypeByFd(t){return q(this.fs.fstatSync(t,{bigint:!0}))}insertPreopen(t,e,n){const r=this.getFileTypeByFd(t);if(3!==r)throw new U(`Preopen not dir: ["${e}", "${n}"]`,54);const i=G(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 U("Invalid fd",8);const n=this.fds[t],r=this.fds[e];if(!n||!r||n.id!==t||r.id!==e)throw new U("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 tt extends Q{constructor(t){super(t)}async getFileTypeByFd(t){return q(await t.stat({bigint:!0}))}async insertPreopen(t,e,n){const r=await this.getFileTypeByFd(t);if(3!==r)throw new U(`Preopen not dir: ["${e}", "${n}"]`,54);const i=G(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 U("Invalid fd",8);const n=this.fds[t],r=this.fds[e];if(!n||!r||n.id!==t||r.id!==e)throw new U("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 et=function(){return t.Memory}();class nt extends et{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 rt(e){return Object.getPrototypeOf(e)===t.Memory.prototype&&Object.setPrototypeOf(e,nt.prototype),e}function it(){const e=t.Function;if("function"!=typeof e)throw new Error('WebAssembly.Function is not supported in this environment. If you are using V8 based browser like Chrome, try to specify --js-flags="--wasm-staging --experimental-wasm-stack-switching"');return e}function st(t,e,n){const r=it();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 ot(t){const e=it();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 at(t,e){return o(t,((t,n)=>{let r="function"!=typeof t;return Array.isArray(e)&&(r=r||-1===e.indexOf(n)),r?t:ot(t)}))}const ct="undefined"!=typeof process&&"win32"===process.platform;function ut(t){let e=3&t;return 0!=(64&t)&&(e|=256),0!=(128&t)&&(e|=1024),0!=(512&t)&&(e|=512),0!=(1024&t)&&(e|=8),e}function ft(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 ht=new WeakMap,dt=new WeakMap,gt=new WeakMap;function lt(t){return ht.get(t)}function _t(t){const e=gt.get(t);if(!e)throw new Error("filesystem is unavailable");return e}function pt(t){if(t instanceof U)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 yt(t,e){return Object.defineProperty(e,"name",{value:t}),e}function Et(t,e,n){let r;try{r=t.apply(e,n)}catch(t){return pt(t)}return s(r)?r.then((t=>t),pt):r}function It(t,e,n){let r=!1;const i=(()=>{try{return}catch(t){return}})();return"string"==typeof i&&i.split(",").includes("wasi")&&(r=!0),yt(e,r?function(){const r=Array.prototype.slice.call(arguments);let i=[`${e}(${Array.from({length:arguments.length}).map((()=>"%d")).join(", ")})`];return i=i.concat(r),console.debug.apply(console,i),Et(n,t,r)}:function(){return Et(n,t,arguments)})}function mt(t,e,n,r){let i=F(e.realPath,n);if(1==(1&r))try{i=t.readlinkSync(i)}catch(t){if("EINVAL"!==t.code&&"ENOENT"!==t.code)throw t}return i}async function At(t,e,n,r){let i=F(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 bt=new TextEncoder,Tt=new TextDecoder,wt=(BigInt(1)<<BigInt(63))-BigInt(1);function Bt(){const t=window.prompt();if(null===t)return new Uint8Array;return(new TextEncoder).encode(t+"\n")}function Nt(t){return Boolean(-16&t)||3==(3&t)||12==(12&t)}class St{constructor(e,n,r,i,s,o){this.args_get=It(this,"args_get",(function(t,e){if(t=Number(t),e=Number(e),0===t||0===e)return 28;const{HEAPU8:n,view:r}=lt(this),i=dt.get(this).args;for(let s=0;s<i.length;++s){const o=i[s];r.setInt32(t,e,!0),t+=4;const a=bt.encode(o+"\0");n.set(a,e),e+=a.length}return 0})),this.args_sizes_get=It(this,"args_sizes_get",(function(t,e){if(t=Number(t),e=Number(e),0===t||0===e)return 28;const{view:n}=lt(this),r=dt.get(this).args;return n.setUint32(t,r.length,!0),n.setUint32(e,bt.encode(r.join("\0")+"\0").length,!0),0})),this.environ_get=It(this,"environ_get",(function(t,e){if(t=Number(t),e=Number(e),0===t||0===e)return 28;const{HEAPU8:n,view:r}=lt(this),i=dt.get(this).env;for(let s=0;s<i.length;++s){const o=i[s];r.setInt32(t,e,!0),t+=4;const a=bt.encode(o+"\0");n.set(a,e),e+=a.length}return 0})),this.environ_sizes_get=It(this,"environ_sizes_get",(function(t,e){if(t=Number(t),e=Number(e),0===t||0===e)return 28;const{view:n}=lt(this),r=dt.get(this);return n.setUint32(t,r.env.length,!0),n.setUint32(e,bt.encode(r.env.join("\0")+"\0").length,!0),0})),this.clock_res_get=It(this,"clock_res_get",(function(t,e){if(0===(e=Number(e)))return 28;const{view:n}=lt(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=It(this,"clock_time_get",(function(t,e,n){if(0===(n=Number(n)))return 28;const{view:r}=lt(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()/1e3,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=It(this,"fd_advise",(function(t,e,n,r){return 52})),this.fd_fdstat_get=It(this,"fd_fdstat_get",(function(t,e){if(0===(e=Number(e)))return 28;const n=dt.get(this).fds.get(t,BigInt(0),BigInt(0)),{view:r}=lt(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=It(this,"fd_fdstat_set_flags",(function(t,e){return 52})),this.fd_fdstat_set_rights=It(this,"fd_fdstat_set_rights",(function(t,e,n){const r=dt.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=It(this,"fd_prestat_get",(function(t,e){if(0===(e=Number(e)))return 28;const n=dt.get(this);let r;try{r=n.fds.get(t,BigInt(0),BigInt(0))}catch(t){if(t instanceof U)return t.errno;throw t}if(1!==r.preopen)return 28;const{view:i}=lt(this);return i.setUint32(e,0,!0),i.setUint32(e+4,bt.encode(r.path).length,!0),0})),this.fd_prestat_dir_name=It(this,"fd_prestat_dir_name",(function(t,e,n){if(e=Number(e),n=Number(n),0===e)return 28;const r=dt.get(this).fds.get(t,BigInt(0),BigInt(0));if(1!==r.preopen)return 8;const i=bt.encode(r.path);if(i.length>n)return 42;const{HEAPU8:s}=lt(this);return s.set(i,e),0})),this.fd_seek=It(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=dt.get(this).fds.get(t,v.FD_SEEK,BigInt(0)).seek(e,n),{view:s}=lt(this);return s.setBigUint64(r,i,!0),0})),this.fd_tell=It(this,"fd_tell",(function(t,e){const n=dt.get(this).fds.get(t,v.FD_TELL,BigInt(0)),r=BigInt(n.pos),{view:i}=lt(this);return i.setBigUint64(Number(e),r,!0),0})),this.poll_oneoff=It(this,"poll_oneoff",(function(t,e,n,r){if(t=Number(t),e=Number(e),r=Number(r),n=Number(n),n>>>=0,0===t||0===e||0===n||0===r)return 28;const{view:i}=lt(this);i.setUint32(r,0,!0);let s,o=0,a=BigInt(0),c=BigInt(0),u=0,f=BigInt(0);const h=Array(n);for(o=0;o<n;o++){s=t+48*o;const e=i.getBigUint64(s,!0),n=i.getUint8(s+8),r=i.getUint32(s+16,!0),a=i.getBigUint64(s+24,!0),c=i.getBigUint64(s+32,!0),u=i.getUint16(s+40,!0);h[o]={userdata:e,type:n,u:{clock:{clock_id:r,timeout:a,precision:c,flags:u},fd_readwrite:{fd:r}}}}const d=[];for(o=0;o<n;o++)switch(s=h[o],s.type){case 0:if(1===s.u.clock.flags){const t=BigInt(Date.now())*BigInt(1e6);c=s.u.clock.timeout-t}else c=s.u.clock.timeout;(0===u||c<f)&&(f=c,a=s.userdata,u=1);break;case 1:case 2:d.push(s);break;default:return 28}if(d.length>0){for(o=0;o<d.length;o++){const t=d[o],n=e+32*o;i.setBigUint64(n,t.userdata,!0),i.setUint32(n+8,52,!0),i.setUint32(n+12,t.type,!0),i.setBigUint64(n+16,BigInt(0),!0),i.setUint16(n+24,0,!0),i.setUint32(r,1,!0)}return i.setUint32(r,d.length,!0),0}if(u){!function(t,e){const n=Date.now()+t;let r=!1;for(;Date.now()<n;)if(e()){r=!0;break}}(Number(f/BigInt(1e6)),(()=>!1));const t=e;i.setBigUint64(t,a,!0),i.setUint32(t+8,0,!0),i.setUint32(t+12,0,!0),i.setUint32(r,1,!0)}return 0})),this.proc_exit=It(this,"proc_exit",(function(t){return"object"==typeof process&&null!==process&&"function"==typeof process.exit&&process.exit(t),0})),this.proc_raise=It(this,"proc_raise",(function(t){return 52})),this.sched_yield=It(this,"sched_yield",(function(){return 0})),this.random_get="undefined"!=typeof crypto&&"function"==typeof crypto.getRandomValues?It(this,"random_get",(function(t,e){if(0===(t=Number(t)))return 28;e=Number(e);const{HEAPU8:n,view:r}=lt(this);if("function"==typeof SharedArrayBuffer&&n.buffer instanceof SharedArrayBuffer||"[object SharedArrayBuffer]"===Object.prototype.toString.call(n.buffer)){for(let n=t;n<t+e;++n)r.setUint8(n,Math.floor(256*Math.random()));return 0}let i;const s=65536;for(i=0;i+s<e;i+=s)crypto.getRandomValues(n.subarray(t+i,t+i+s));return crypto.getRandomValues(n.subarray(t+i,t+e)),0})):It(this,"random_get",(function(t,e){if(0===(t=Number(t)))return 28;e=Number(e);const{view:n}=lt(this);for(let r=t;r<t+e;++r)n.setUint8(r,Math.floor(256*Math.random()));return 0})),this.sock_recv=It(this,"sock_recv",(function(){return 58})),this.sock_send=It(this,"sock_send",(function(){return 58})),this.sock_shutdown=It(this,"sock_shutdown",(function(){return 58})),this.sock_accept=It(this,"sock_accept",(function(){return 58})),dt.set(this,{fds:r,args:e,env:n}),s&&gt.set(this,s);const c=this;function u(t,e,n,r,s){c[t]=i?o?o.wrapImportFunction(It(c,t,n)):st(It(c,t,n),r,s):It(c,t,e)}function f(t,e,n,r){const i=dt.get(this).fds.get(t,v.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 h(t,e,n,r){const i=(e&(v.FD_READ|v.FD_READDIR))!==BigInt(0),s=(e&(v.FD_DATASYNC|v.FD_WRITE|v.FD_ALLOCATE|v.FD_FILESTAT_SET_SIZE))!==BigInt(0);let o=s?i?2:1:0,a=v.PATH_OPEN,c=e|n;return 0!=(1&t)&&(o|=64,a|=v.PATH_CREATE_FILE),0!=(2&t)&&(o|=65536),0!=(4&t)&&(o|=128),0!=(8&t)&&(o|=512,a|=v.PATH_FILESTAT_SET_SIZE),0!=(1&r)&&(o|=1024),0!=(2&r)&&(c|=v.FD_DATASYNC),0!=(4&r)&&(o|=2048),0!=(8&r)&&(o|=1052672,c|=v.FD_SYNC),0!=(16&r)&&(o|=1052672,c|=v.FD_SYNC),s&&0==(1536&o)&&(c|=v.FD_SEEK),{flags:o,needed_base:a,needed_inheriting:c}}u("fd_allocate",(function(t,e,n){const r=dt.get(this),i=_t(this),s=r.fds.get(t,v.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=dt.get(this).fds.get(t,v.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=dt.get(this),n=e.fds.get(t,BigInt(0),BigInt(0));return _t(this).closeSync(n.fd),e.fds.remove(t),0}),(async function(t){const e=dt.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=dt.get(this).fds.get(t,v.FD_DATASYNC,BigInt(0));return _t(this).fdatasyncSync(e.fd),0}),(async function(t){const e=dt.get(this).fds.get(t,v.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=dt.get(this).fds.get(t,v.FD_FILESTAT_GET,BigInt(0)),r=_t(this).fstatSync(n.fd,{bigint:!0}),{view:i}=lt(this);return X(i,e,r),0}),(async function(t,e){if(0===(e=Number(e)))return 28;const n=dt.get(this).fds.get(t,v.FD_FILESTAT_GET,BigInt(0)).fd,r=await n.stat({bigint:!0}),{view:i}=lt(this);return X(i,e,r),0}),["i32","i32"],["i32"]),u("fd_filestat_set_size",(function(t,e){const n=dt.get(this).fds.get(t,v.FD_FILESTAT_SET_SIZE,BigInt(0));return _t(this).ftruncateSync(n.fd,Number(e)),0}),(async function(t,e){const n=dt.get(this).fds.get(t,v.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){if(Nt(r))return 28;const{fileDescriptor:i,atim:s,mtim:o}=f.call(this,t,e,n,r);return _t(this).futimesSync(i.fd,Number(s),Number(o)),0}),(async function(t,e,n,r){if(Nt(r))return 28;const{fileDescriptor:i,atim:s,mtim:o}=f.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&&n||0===i||r>wt)return 28;const{HEAPU8:s,view:o}=lt(this),a=dt.get(this).fds.get(t,v.FD_READ|v.FD_SEEK,BigInt(0));if(!n)return o.setUint32(i,0,!0),0;let c=0;const u=Array.from({length:Number(n)},((t,n)=>{const r=e+8*n,i=o.getInt32(r,!0),a=o.getUint32(r+4,!0);return c+=a,s.subarray(i,i+a)}));let f=0;const h=(()=>{try{return new Uint8Array(new SharedArrayBuffer(c))}catch(t){return new Uint8Array(c)}})();h._isBuffer=!0;const d=_t(this).readSync(a.fd,h,0,h.length,Number(r));return f=h?ft(u,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&&n||0===i||r>wt)return 28;const{HEAPU8:s,view:o}=lt(this),a=dt.get(this).fds.get(t,v.FD_READ|v.FD_SEEK,BigInt(0));if(!n)return o.setUint32(i,0,!0),0;let c=0;const u=Array.from({length:Number(n)},((t,n)=>{const r=e+8*n,i=o.getInt32(r,!0),a=o.getUint32(r+4,!0);return c+=a,s.subarray(i,i+a)}));let f=0;const h=new Uint8Array(c);h._isBuffer=!0;const{bytesRead:d}=await a.fd.read(h,0,h.length,Number(r));return f=h?ft(u,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&&n||0===i||r>wt)return 28;const{HEAPU8:s,view:o}=lt(this),a=dt.get(this).fds.get(t,v.FD_WRITE|v.FD_SEEK,BigInt(0));if(!n)return o.setUint32(i,0,!0),0;const c=Y(Array.from({length:Number(n)},((t,n)=>{const r=e+8*n,i=o.getInt32(r,!0),a=o.getUint32(r+4,!0);return s.subarray(i,i+a)}))),u=_t(this).writeSync(a.fd,c,0,c.length,Number(r));return o.setUint32(i,u,!0),0}),(async function(t,e,n,r,i){if(e=Number(e),i=Number(i),0===e&&n||0===i||r>wt)return 28;const{HEAPU8:s,view:o}=lt(this),a=dt.get(this).fds.get(t,v.FD_WRITE|v.FD_SEEK,BigInt(0));if(!n)return o.setUint32(i,0,!0),0;const c=Y(Array.from({length:Number(n)},((t,n)=>{const r=e+8*n,i=o.getInt32(r,!0),a=o.getUint32(r+4,!0);return s.subarray(i,i+a)}))),{bytesWritten:u}=await a.fd.write(c,0,c.length,Number(r));return o.setUint32(i,u,!0),0}),["i32","i32","i32","i64","i32"],["i32"]),u("fd_read",(function(t,e,n,r){if(e=Number(e),r=Number(r),0===e&&n||0===r)return 28;const{HEAPU8:i,view:s}=lt(this),o=dt.get(this).fds.get(t,v.FD_READ,BigInt(0));if(!n)return s.setUint32(r,0,!0),0;let a=0;const c=Array.from({length:Number(n)},((t,n)=>{const r=e+8*n,o=s.getInt32(r,!0),c=s.getUint32(r+4,!0);return a+=c,i.subarray(o,o+c)}));let u,f=0;if(0===t){if("undefined"==typeof window||"function"!=typeof window.prompt)return 58;u=Bt(),f=u?ft(c,u):0}else{u=(()=>{try{return new Uint8Array(new SharedArrayBuffer(a))}catch(t){return new Uint8Array(a)}})(),u._isBuffer=!0;const t=_t(this).readSync(o.fd,u,0,u.length,Number(o.pos));f=u?ft(c,u.subarray(0,t)):0,o.pos+=BigInt(f)}return s.setUint32(r,f,!0),0}),(async function(t,e,n,r){if(e=Number(e),r=Number(r),0===e&&n||0===r)return 28;const{HEAPU8:i,view:s}=lt(this),o=dt.get(this).fds.get(t,v.FD_READ,BigInt(0));if(!n)return s.setUint32(r,0,!0),0;let a=0;const c=Array.from({length:Number(n)},((t,n)=>{const r=e+8*n,o=s.getInt32(r,!0),c=s.getUint32(r+4,!0);return a+=c,i.subarray(o,o+c)}));let u,f=0;if(0===t){if("undefined"==typeof window||"function"!=typeof window.prompt)return 58;u=Bt(),f=u?ft(c,u):0}else{u=new Uint8Array(a),u._isBuffer=!0;const{bytesRead:t}=await o.fd.read(u,0,u.length,Number(o.pos));f=u?ft(c,u.subarray(0,t)):0,o.pos+=BigInt(f)}return s.setUint32(r,f,!0),0}),["i32","i32","i32","i32"],["i32"]),u("fd_readdir",(function(t,e,n,r,i){if(e=Number(e),n=Number(n),i=Number(i),0===e||0===i)return 0;const s=dt.get(this).fds.get(t,v.FD_READDIR,BigInt(0)),o=_t(this),a=o.readdirSync(s.realPath,{withFileTypes:!0}),{HEAPU8:c,view:u}=lt(this);let f=0;for(let t=Number(r);t<a.length;t++){const r=bt.encode(a[t].name),i=o.statSync(F(s.realPath,a[t].name),{bigint:!0}),u=new Uint8Array(24+r.byteLength),h=new DataView(u.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),u.set(r,24);const g=u.slice(0,Math.min(u.length,n-f));c.set(g,e+f),f+=g.byteLength}return u.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=dt.get(this).fds.get(t,v.FD_READDIR,BigInt(0)),o=_t(this),a=await o.promises.readdir(s.realPath,{withFileTypes:!0}),{HEAPU8:c,view:u}=lt(this);let f=0;for(let t=Number(r);t<a.length;t++){const r=bt.encode(a[t].name),i=await o.promises.stat(F(s.realPath,a[t].name),{bigint:!0}),u=new Uint8Array(24+r.byteLength),h=new DataView(u.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),u.set(r,24);const g=u.slice(0,Math.min(u.length,n-f));c.set(g,e+f),f+=g.byteLength}return u.setUint32(i,f,!0),0}),["i32","i32","i32","i64","i32"],["i32"]),u("fd_renumber",(function(t,e){return dt.get(this).fds.renumber(e,t),0}),(async function(t,e){const n=dt.get(this);return await n.fds.renumber(e,t),0}),["i32","i32"],["i32"]),u("fd_sync",(function(t){const e=dt.get(this).fds.get(t,v.FD_SYNC,BigInt(0));return _t(this).fsyncSync(e.fd),0}),(async function(t){const e=dt.get(this).fds.get(t,v.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&&n||0===r)return 28;const{HEAPU8:i,view:s}=lt(this),o=dt.get(this).fds.get(t,v.FD_WRITE,BigInt(0));if(!n)return s.setUint32(r,0,!0),0;const a=Y(Array.from({length:Number(n)},((t,n)=>{const r=e+8*n,o=s.getInt32(r,!0),a=s.getUint32(r+4,!0);return i.subarray(o,o+a)})));let c;if(1===t||2===t)c=o.write(a);else{c=_t(this).writeSync(o.fd,a,0,a.length,Number(o.pos)),o.pos+=BigInt(c)}return s.setUint32(r,c,!0),0}),(async function(t,e,n,r){if(e=Number(e),r=Number(r),0===e&&n||0===r)return 28;const{HEAPU8:i,view:s}=lt(this),o=dt.get(this).fds.get(t,v.FD_WRITE,BigInt(0));if(!n)return s.setUint32(r,0,!0),0;const a=Y(Array.from({length:Number(n)},((t,n)=>{const r=e+8*n,o=s.getInt32(r,!0),a=s.getUint32(r+4,!0);return i.subarray(o,o+a)})));let c;return 1===t||2===t?c=o.write(a):(c=await(await o.fd.write(a,0,a.length,Number(o.pos))).bytesWritten,o.pos+=BigInt(c)),s.setUint32(r,c,!0),0}),["i32","i32","i32","i32"],["i32"]),u("path_create_directory",(function(t,e,n){if(e=Number(e),n=Number(n),0===e)return 28;const{HEAPU8:r}=lt(this),i=dt.get(this).fds.get(t,v.PATH_CREATE_DIRECTORY,BigInt(0));let s=Tt.decode(a(r,e,e+n));s=F(i.realPath,s);return _t(this).mkdirSync(s),0}),(async function(t,e,n){if(e=Number(e),n=Number(n),0===e)return 28;const{HEAPU8:r}=lt(this),i=dt.get(this).fds.get(t,v.PATH_CREATE_DIRECTORY,BigInt(0));let s=Tt.decode(a(r,e,e+n));s=F(i.realPath,s);const o=_t(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}=lt(this),c=dt.get(this).fds.get(t,v.PATH_FILESTAT_GET,BigInt(0));let u=Tt.decode(a(s,n,n+r));const f=_t(this);let h;return u=F(c.realPath,u),h=1==(1&e)?f.statSync(u,{bigint:!0}):f.lstatSync(u,{bigint:!0}),X(o,i,h),0}),(async function(t,e,n,r,i){if(n=Number(n),r=Number(r),i=Number(i),0===n||0===i)return 28;const{HEAPU8:s,view:o}=lt(this),c=dt.get(this).fds.get(t,v.PATH_FILESTAT_GET,BigInt(0));let u=Tt.decode(a(s,n,n+r));const f=_t(this);let h;return u=F(c.realPath,u),h=1==(1&e)?await f.promises.stat(u,{bigint:!0}):await f.promises.lstat(u,{bigint:!0}),X(o,i,h),0}),["i32","i32","i32","i32","i32"],["i32"]),u("path_filestat_set_times",(function(t,e,n,r,i,s,o){if(n=Number(n),r=Number(r),0===n)return 28;const{HEAPU8:c}=lt(this),u=dt.get(this).fds.get(t,v.PATH_FILESTAT_SET_TIMES,BigInt(0));if(Nt(o))return 28;const f=_t(this),h=mt(f,u,Tt.decode(a(c,n,n+r)),e);return 2==(2&o)&&(i=BigInt(1e6*Date.now())),8==(8&o)&&(s=BigInt(1e6*Date.now())),f.utimesSync(h,Number(i),Number(s)),0}),(async function(t,e,n,r,i,s,o){if(n=Number(n),r=Number(r),0===n)return 28;const{HEAPU8:c}=lt(this),u=dt.get(this).fds.get(t,v.PATH_FILESTAT_SET_TIMES,BigInt(0));if(Nt(o))return 28;const f=_t(this),h=await At(f,u,Tt.decode(a(c,n,n+r)),e);return 2==(2&o)&&(i=BigInt(1e6*Date.now())),8==(8&o)&&(s=BigInt(1e6*Date.now())),await f.promises.utimes(h,Number(i),Number(s)),0}),["i32","i32","i32","i32","i64","i64","i32"],["i32"]),u("path_link",(function(t,e,n,r,i,s,o){if(n=Number(n),r=Number(r),s=Number(s),o=Number(o),0===n||0===s)return 28;const c=dt.get(this);let u,f;t===i?u=f=c.fds.get(t,v.PATH_LINK_SOURCE|v.PATH_LINK_TARGET,BigInt(0)):(u=c.fds.get(t,v.PATH_LINK_SOURCE,BigInt(0)),f=c.fds.get(i,v.PATH_LINK_TARGET,BigInt(0)));const{HEAPU8:h}=lt(this),d=_t(this),g=mt(d,u,Tt.decode(a(h,n,n+r)),e),l=F(f.realPath,Tt.decode(a(h,s,s+o)));return d.linkSync(g,l),0}),(async function(t,e,n,r,i,s,o){if(n=Number(n),r=Number(r),s=Number(s),o=Number(o),0===n||0===s)return 28;const c=dt.get(this);let u,f;t===i?u=f=c.fds.get(t,v.PATH_LINK_SOURCE|v.PATH_LINK_TARGET,BigInt(0)):(u=c.fds.get(t,v.PATH_LINK_SOURCE,BigInt(0)),f=c.fds.get(i,v.PATH_LINK_TARGET,BigInt(0)));const{HEAPU8:h}=lt(this),d=_t(this),g=await At(d,u,Tt.decode(a(h,n,n+r)),e),l=F(f.realPath,Tt.decode(a(h,s,s+o)));return await d.promises.link(g,l),0}),["i32","i32","i32","i32","i32","i32","i32"],["i32"]),u("path_open",(function(t,e,n,r,i,s,o,c,u){if(n=Number(n),u=Number(u),0===n||0===u)return 28;r=Number(r),s=BigInt(s),o=BigInt(o);const{flags:f,needed_base:d,needed_inheriting:g}=h(i,s,o,c),l=dt.get(this),_=l.fds.get(t,d,g),p=lt(this),y=p.HEAPU8,E=Tt.decode(a(y,n,n+r)),I=_t(this),m=mt(I,_,E,e),A=I.openSync(m,ct?ut(f):f,438),b=l.fds.getFileTypeByFd(A);if(3!==b&&(0!=(2&i)||m.endsWith("/")))return 54;const{base:T,inheriting:w}=G(l.fds.stdio,A,f,b),B=l.fds.insert(A,m,m,b,s&T,o&w,0),N=I.fstatSync(A,{bigint:!0});N.isFile()&&(B.size=N.size,0!=(1024&f)&&(B.pos=N.size));return p.view.setInt32(u,B.id,!0),0}),(async function(t,e,n,r,i,s,o,c,u){if(n=Number(n),u=Number(u),0===n||0===u)return 28;r=Number(r),s=BigInt(s),o=BigInt(o);const{flags:f,needed_base:d,needed_inheriting:g}=h(i,s,o,c),l=dt.get(this),_=l.fds.get(t,d,g),p=lt(this),y=p.HEAPU8,E=Tt.decode(a(y,n,n+r)),I=_t(this),m=await At(I,_,E,e),A=await I.promises.open(m,ct?ut(f):f,438),b=await l.fds.getFileTypeByFd(A);if(0!=(2&i)&&3!==b)return 54;const{base:T,inheriting:w}=G(l.fds.stdio,A.fd,f,b),B=l.fds.insert(A,m,m,b,s&T,o&w,0),N=await A.stat({bigint:!0});N.isFile()&&(B.size=N.size,0!=(1024&f)&&(B.pos=N.size));return p.view.setInt32(u,B.id,!0),0}),["i32","i32","i32","i32","i32","i64","i64","i32","i32"],["i32"]),u("path_readlink",(function(t,e,n,r,i,s){if(e=Number(e),n=Number(n),r=Number(r),i=Number(i),s=Number(s),0===e||0===r||0===s)return 28;const{HEAPU8:o,view:c}=lt(this),u=dt.get(this).fds.get(t,v.PATH_READLINK,BigInt(0));let f=Tt.decode(a(o,e,e+n));f=F(u.realPath,f);const h=_t(this).readlinkSync(f),d=bt.encode(h),g=Math.min(d.length,i);return g>=i?42:(o.set(d.subarray(0,g),r),o[r+g]=0,c.setUint32(s,g,!0),0)}),(async function(t,e,n,r,i,s){if(e=Number(e),n=Number(n),r=Number(r),i=Number(i),s=Number(s),0===e||0===r||0===s)return 28;const{HEAPU8:o,view:c}=lt(this),u=dt.get(this).fds.get(t,v.PATH_READLINK,BigInt(0));let f=Tt.decode(a(o,e,e+n));f=F(u.realPath,f);const h=_t(this),d=await h.promises.readlink(f),g=bt.encode(d),l=Math.min(g.length,i);return l>=i?42:(o.set(g.subarray(0,l),r),o[r+l]=0,c.setUint32(s,l,!0),0)}),["i32","i32","i32","i32","i32","i32"],["i32"]),u("path_remove_directory",(function(t,e,n){if(e=Number(e),n=Number(n),0===e)return 28;const{HEAPU8:r}=lt(this),i=dt.get(this).fds.get(t,v.PATH_REMOVE_DIRECTORY,BigInt(0));let s=Tt.decode(a(r,e,e+n));s=F(i.realPath,s);return _t(this).rmdirSync(s),0}),(async function(t,e,n){if(e=Number(e),n=Number(n),0===e)return 28;const{HEAPU8:r}=lt(this),i=dt.get(this).fds.get(t,v.PATH_REMOVE_DIRECTORY,BigInt(0));let s=Tt.decode(a(r,e,e+n));s=F(i.realPath,s);const o=_t(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=dt.get(this);let c,u;t===r?c=u=o.fds.get(t,v.PATH_RENAME_SOURCE|v.PATH_RENAME_TARGET,BigInt(0)):(c=o.fds.get(t,v.PATH_RENAME_SOURCE,BigInt(0)),u=o.fds.get(r,v.PATH_RENAME_TARGET,BigInt(0)));const{HEAPU8:f}=lt(this),h=F(c.realPath,Tt.decode(a(f,e,e+n))),d=F(u.realPath,Tt.decode(a(f,i,i+s)));return _t(this).renameSync(h,d),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=dt.get(this);let c,u;t===r?c=u=o.fds.get(t,v.PATH_RENAME_SOURCE|v.PATH_RENAME_TARGET,BigInt(0)):(c=o.fds.get(t,v.PATH_RENAME_SOURCE,BigInt(0)),u=o.fds.get(r,v.PATH_RENAME_TARGET,BigInt(0)));const{HEAPU8:f}=lt(this),h=F(c.realPath,Tt.decode(a(f,e,e+n))),d=F(u.realPath,Tt.decode(a(f,i,i+s))),g=_t(this);return await g.promises.rename(h,d),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}=lt(this),o=dt.get(this).fds.get(n,v.PATH_SYMLINK,BigInt(0)),c=Tt.decode(a(s,t,t+e));if(c.length>0&&"/"===c[0])return 63;let u=Tt.decode(a(s,r,r+i));u=F(o.realPath,u);return _t(this).symlinkSync(c,u),0}),(async function(t,e,n,r,i){if(t=Number(t),e=Number(e),r=Number(r),i=Number(i),0===t||0===r)return 28;const{HEAPU8:s}=lt(this),o=dt.get(this).fds.get(n,v.PATH_SYMLINK,BigInt(0)),c=Tt.decode(a(s,t,t+e));let u=Tt.decode(a(s,r,r+i));u=F(o.realPath,u);const f=_t(this);return await f.promises.symlink(c,u),0}),["i32","i32","i32","i32","i32"],["i32"]),u("path_unlink_file",(function(t,e,n){if(e=Number(e),n=Number(n),0===e)return 28;const{HEAPU8:r}=lt(this),i=dt.get(this).fds.get(t,v.PATH_UNLINK_FILE,BigInt(0));let s=Tt.decode(a(r,e,e+n));s=F(i.realPath,s);return _t(this).unlinkSync(s),0}),(async function(t,e,n){if(e=Number(e),n=Number(n),0===e)return 28;const{HEAPU8:r}=lt(this),i=dt.get(this).fds.get(t,v.PATH_UNLINK_FILE,BigInt(0));let s=Tt.decode(a(r,e,e+n));s=F(i.realPath,s);const o=_t(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');ht.set(c,rt(e))}}static createSync(t,e,n,r,i,s,o){const a=new J({size:3,in:r[0],out:r[1],err:r[2],fs:i,print:s,printErr:o}),c=new St(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 c}static async createAsync(t,e,n,r,i,s,o,a){const c=new tt({size:3,in:r[0],out:r[1],err:r[2],print:s,printErr:o}),u=new St(t,e,c,!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 c.insertPreopen(s,e.mappedPath,r)}return u}}const Pt=Object.freeze(Object.create(null)),Dt=Symbol("kExitCode"),Ft=Symbol("kSetMemory"),vt=Symbol("kStarted"),Ut=Symbol("kInstance"),Rt=Symbol("kBindingName");function Lt(t){var i;let s;if(e(t,"options"),void 0!==t.version)switch(n(t.version,"options.version"),t.version){case"unstable":s=St,this[Rt]="wasi_unstable";break;case"preview1":s=St,this[Rt]="wasi_snapshot_preview1";break;default:throw new TypeError(`unsupported WASI version "${t.version}"`)}else s=St,this[Rt]="wasi_snapshot_preview1";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 o=(null!==(i=t.args)&&void 0!==i?i:[]).map(String),a=[];void 0!==t.env&&(e(t.env,"options.env"),Object.entries(t.env).forEach((({0:t,1:e})=>{void 0!==e&&a.push(`${t}=${e}`)})));const c=[];if(void 0!==t.preopens&&(e(t.preopens,"options.preopens"),Object.entries(t.preopens).forEach((({0:t,1:e})=>c.push({mappedPath:String(t),realPath:String(e)})))),c.length>0){if(void 0===t.fs)throw new Error("filesystem is disabled, can not preopen directory");try{e(t.fs,"options.fs")}catch(t){throw new TypeError("Node.js fs like implementation is not provided")}}void 0!==t.print&&r(t.print,"options.print"),void 0!==t.printErr&&r(t.printErr,"options.printErr"),void 0!==t.returnOnExit&&function(t,e){if("boolean"!=typeof t)throw new TypeError(`${e} must be a boolean. Received ${null===t?"null":typeof t}`)}(t.returnOnExit,"options.returnOnExit");return{args:o,env:a,preopens:c,stdio:[0,1,2],_WASI:s}}function Ht(t,e){this[Ft]=t,this.wasiImport=e,this[vt]=!1,this[Dt]=0,this[Ut]=void 0}class Ot{constructor(t=Pt){const{args:e,env:n,preopens:r,stdio:i,_WASI:s}=Lt.call(this,t),o=s.createSync(e,n,r,i,t.fs,t.print,t.printErr),a=o._setMemory;delete o._setMemory,Ht.call(this,a,o),t.returnOnExit&&(o.proc_exit=Ct.bind(this))}finalizeBindings(t,n){var r,{memory:i=(null===(r=null==t?void 0:t.exports)||void 0===r?void 0:r.memory)}=void 0===n?{}:n;if(this[vt])throw new Error("WASI instance has already started");e(t,"instance"),e(t.exports,"instance.exports"),this[Ft](i),this[Ut]=t,this[vt]=!0}start(t){this.finalizeBindings(t);const{_start:e,_initialize:n}=this[Ut].exports;let s;r(e,"instance.exports._start"),i(n,"instance.exports._initialize");try{s=e()}catch(t){if(t!==Dt)throw t}return s instanceof Promise?s.then((()=>this[Dt]),(t=>{if(t!==Dt)throw t;return this[Dt]})):this[Dt]}initialize(t){this.finalizeBindings(t);const{_start:e,_initialize:n}=this[Ut].exports;if(i(e,"instance.exports._start"),void 0!==n)return r(n,"instance.exports._initialize"),n()}getImportObject(){return{[this[Rt]]:this.wasiImport}}}function Ct(t){throw this[Dt]=t,Dt}async function kt(t=Pt){const n=Object.create(Ot.prototype),{args:i,env:s,preopens:o,stdio:a,_WASI:c}=Lt.call(n,t);void 0!==t.asyncify&&(e(t.asyncify,"options.asyncify"),r(t.asyncify.wrapImportFunction,"options.asyncify.wrapImportFunction"));const u=await c.createAsync(i,s,o,a,t.fs,t.print,t.printErr,t.asyncify),f=u._setMemory;return delete u._setMemory,Ht.call(n,f,u),t.returnOnExit&&(u.proc_exit=Ct.bind(n)),n}export{f as Asyncify,nt as Memory,Ot as WASI,et as WebAssemblyMemory,l as asyncifyLoad,p as asyncifyLoadSync,kt as createAsyncWASI,rt as extendMemory,g as load,_ as loadSync,ot as wrapAsyncExport,st as wrapAsyncImport,at as wrapExports};
@@ -312,6 +312,141 @@
312
312
 
313
313
  const CHAR_DOT = 46; /* . */
314
314
  const CHAR_FORWARD_SLASH = 47; /* / */
315
+ const CHAR_BACKWARD_SLASH = 92; /* \ */
316
+ const CHAR_COLON = 58; /* : */
317
+ const CHAR_UPPERCASE_A = 65; /* A */
318
+ const CHAR_UPPERCASE_Z = 90; /* Z */
319
+ const CHAR_LOWERCASE_A = 97; /* a */
320
+ const CHAR_LOWERCASE_Z = 122; /* z */
321
+ function isPathSeparatorWin(code) {
322
+ return code === CHAR_FORWARD_SLASH || code === CHAR_BACKWARD_SLASH;
323
+ }
324
+ function isWindowsDeviceRoot(code) {
325
+ return (code >= CHAR_UPPERCASE_A && code <= CHAR_UPPERCASE_Z) ||
326
+ (code >= CHAR_LOWERCASE_A && code <= CHAR_LOWERCASE_Z);
327
+ }
328
+ const _isWin32 = typeof process !== 'undefined' && process.platform === 'win32';
329
+ /**
330
+ * Windows variant of `resolve()`. Mirrors Node's `path.win32.resolve`
331
+ * semantics enough for the WASI shim's needs (drive-letter absolutes
332
+ * + UNC paths + per-drive cwd lookups via `process.env`/`process.cwd`).
333
+ *
334
+ * Why this is needed: on Windows, `FileDescriptor.realPath` is the
335
+ * host realpath returned by `fs.realpathSync(realPath, 'utf8')` — the
336
+ * backslash form `D:\…`. The POSIX-only `resolveImpl` below only
337
+ * treats `/` as a separator, reads `D` as non-`/`, decides realPath
338
+ * is "relative", and produces a garbage joined path. Downstream
339
+ * `fs.openSync(garbage)` then returns `EINVAL` and the WASI caller
340
+ * sees a permanent failure. This function gives us the correct
341
+ * Windows-style resolution without taking a Node-only `path` import
342
+ * (which would break browser bundles of this package).
343
+ *
344
+ * Cribbed from Node's `lib/path.js` `win32.resolve()` (MIT-licensed),
345
+ * trimmed to what WASI realpath resolution actually exercises.
346
+ */
347
+ function resolveWin32(args) {
348
+ let resolvedDevice = '';
349
+ let resolvedTail = '';
350
+ let resolvedAbsolute = false;
351
+ for (let i = args.length - 1; i >= -1; i--) {
352
+ let path;
353
+ if (i >= 0) {
354
+ path = args[i];
355
+ validateString(path, 'path');
356
+ if (path.length === 0)
357
+ continue;
358
+ }
359
+ else if (resolvedDevice.length === 0) {
360
+ path = (typeof process !== 'undefined' && typeof process.cwd === 'function')
361
+ ? process.cwd()
362
+ : '';
363
+ }
364
+ else {
365
+ // Look up per-drive cwd via the `=X:` env var convention; fall back
366
+ // to the global cwd if absent.
367
+ const envKey = `=${resolvedDevice}`;
368
+ const env = (typeof process !== 'undefined') ? process.env : undefined;
369
+ path = (env && typeof env[envKey] === 'string')
370
+ ? env[envKey]
371
+ : (typeof process !== 'undefined' && typeof process.cwd === 'function')
372
+ ? process.cwd()
373
+ : '';
374
+ if (path === undefined ||
375
+ (path.slice(0, 2).toLowerCase() !== resolvedDevice.toLowerCase() &&
376
+ path.charCodeAt(2) === CHAR_BACKWARD_SLASH)) {
377
+ path = `${resolvedDevice}\\`;
378
+ }
379
+ }
380
+ const len = path.length;
381
+ let rootEnd = 0;
382
+ let device = '';
383
+ let isAbsolute = false;
384
+ const code = path.charCodeAt(0);
385
+ if (len === 1) {
386
+ if (isPathSeparatorWin(code)) {
387
+ rootEnd = 1;
388
+ isAbsolute = true;
389
+ }
390
+ }
391
+ else if (isPathSeparatorWin(code)) {
392
+ isAbsolute = true;
393
+ if (isPathSeparatorWin(path.charCodeAt(1))) {
394
+ // UNC path: `\\server\share\…`
395
+ let j = 2;
396
+ let last = j;
397
+ while (j < len && !isPathSeparatorWin(path.charCodeAt(j)))
398
+ j++;
399
+ if (j < len && j !== last) {
400
+ const firstPart = path.slice(last, j);
401
+ last = j;
402
+ while (j < len && isPathSeparatorWin(path.charCodeAt(j)))
403
+ j++;
404
+ if (j < len && j !== last) {
405
+ last = j;
406
+ while (j < len && !isPathSeparatorWin(path.charCodeAt(j)))
407
+ j++;
408
+ if (j === len || j !== last) {
409
+ device = `\\\\${firstPart}\\${path.slice(last, j)}`;
410
+ rootEnd = j;
411
+ }
412
+ }
413
+ }
414
+ }
415
+ else {
416
+ rootEnd = 1;
417
+ }
418
+ }
419
+ else if (isWindowsDeviceRoot(code) && path.charCodeAt(1) === CHAR_COLON) {
420
+ device = path.slice(0, 2);
421
+ rootEnd = 2;
422
+ if (len > 2 && isPathSeparatorWin(path.charCodeAt(2))) {
423
+ isAbsolute = true;
424
+ rootEnd = 3;
425
+ }
426
+ }
427
+ if (device.length > 0) {
428
+ if (resolvedDevice.length > 0) {
429
+ if (device.toLowerCase() !== resolvedDevice.toLowerCase())
430
+ continue;
431
+ }
432
+ else {
433
+ resolvedDevice = device;
434
+ }
435
+ }
436
+ if (resolvedAbsolute) {
437
+ if (resolvedDevice.length > 0)
438
+ break;
439
+ }
440
+ else {
441
+ resolvedTail = `${path.slice(rootEnd)}\\${resolvedTail}`;
442
+ resolvedAbsolute = isAbsolute;
443
+ if (isAbsolute && resolvedDevice.length > 0)
444
+ break;
445
+ }
446
+ }
447
+ resolvedTail = normalizeString(resolvedTail, !resolvedAbsolute, '\\', isPathSeparatorWin);
448
+ return resolvedDevice + (resolvedAbsolute ? '\\' : '') + resolvedTail || '.';
449
+ }
315
450
  function isPosixPathSeparator(code) {
316
451
  return code === CHAR_FORWARD_SLASH;
317
452
  }
@@ -387,6 +522,13 @@
387
522
  return res;
388
523
  }
389
524
  function resolve(...args) {
525
+ // On Windows, host paths are `D:\…` style. The POSIX-only resolver
526
+ // below treats `D` as a non-`/` character and produces garbage; route
527
+ // to the Windows-aware variant. POSIX hosts (Linux/macOS/browser)
528
+ // run the original code path unchanged — `_isWin32` is constant-folded
529
+ // away on those targets.
530
+ if (_isWin32)
531
+ return resolveWin32(args);
390
532
  let resolvedPath = '';
391
533
  let resolvedAbsolute = false;
392
534
  for (let i = args.length - 1; i >= -1 && !resolvedAbsolute; i--) {
@@ -1023,6 +1165,26 @@
1023
1165
  });
1024
1166
  }
1025
1167
 
1168
+ // Linux fcntl flag bits ↔ Windows libuv flag bits. `pathOpen()` builds
1169
+ // `flagsRes` using Linux constants (O_CREAT=0x40, O_EXCL=0x80,
1170
+ // O_APPEND=0x400). Windows libuv expects different bits (O_CREAT=0x100,
1171
+ // O_EXCL=0x400, O_APPEND=0x8). Without translation,
1172
+ // `fs.openSync(path, 0x241 /* L:WRONLY|CREAT|TRUNC */)` is rejected
1173
+ // with EINVAL because Linux's 0x40 happens to mean O_TEMPORARY on
1174
+ // Windows — and O_TEMPORARY without O_CREAT is invalid.
1175
+ const _isWin32Flags = typeof process !== 'undefined' && process.platform === 'win32';
1176
+ function _toWinOpenFlags(f) {
1177
+ let r = f & 3; // RDONLY/WRONLY/RDWR — same on both
1178
+ if ((f & 0x40) !== 0)
1179
+ r |= 0x100; // O_CREAT: Linux 0x40 -> Windows 0x100
1180
+ if ((f & 0x80) !== 0)
1181
+ r |= 0x400; // O_EXCL: Linux 0x80 -> Windows 0x400
1182
+ if ((f & 0x200) !== 0)
1183
+ r |= 0x200; // O_TRUNC: same value on both
1184
+ if ((f & 0x400) !== 0)
1185
+ r |= 0x8; // O_APPEND: Linux 0x400 -> Windows 0x8
1186
+ return r;
1187
+ }
1026
1188
  function copyMemory(targets, src) {
1027
1189
  if (targets.length === 0 || src.length === 0)
1028
1190
  return 0;
@@ -2279,7 +2441,7 @@
2279
2441
  const pathString = decoder.decode(unsharedSlice(HEAPU8, path, path + path_len));
2280
2442
  const fs = getFs(this);
2281
2443
  const resolved_path = resolvePathSync(fs, fileDescriptor, pathString, dirflags);
2282
- const r = fs.openSync(resolved_path, flagsRes, 0o666);
2444
+ const r = fs.openSync(resolved_path, _isWin32Flags ? _toWinOpenFlags(flagsRes) : flagsRes, 0o666);
2283
2445
  const filetype = wasi.fds.getFileTypeByFd(r);
2284
2446
  if ((filetype !== 3 /* WasiFileType.DIRECTORY */) &&
2285
2447
  ((o_flags & 2 /* WasiFileControlFlag.O_DIRECTORY */) !== 0 ||
@@ -2315,7 +2477,7 @@
2315
2477
  const pathString = decoder.decode(unsharedSlice(HEAPU8, path, path + path_len));
2316
2478
  const fs = getFs(this);
2317
2479
  const resolved_path = await resolvePathAsync(fs, fileDescriptor, pathString, dirflags);
2318
- const r = await fs.promises.open(resolved_path, flagsRes, 0o666);
2480
+ const r = await fs.promises.open(resolved_path, _isWin32Flags ? _toWinOpenFlags(flagsRes) : flagsRes, 0o666);
2319
2481
  const filetype = await wasi.fds.getFileTypeByFd(r);
2320
2482
  if ((o_flags & 2 /* WasiFileControlFlag.O_DIRECTORY */) !== 0 && filetype !== 3 /* WasiFileType.DIRECTORY */) {
2321
2483
  return 54 /* WasiErrno.ENOTDIR */;