@zenfs/dom 0.0.6 → 0.1.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.
@@ -1,4 +1,2 @@
1
- var ZenFS_DOM=(()=>{var yt=Object.defineProperty;var te=Object.getOwnPropertyDescriptor;var ee=Object.getOwnPropertyNames;var ie=Object.prototype.hasOwnProperty;var u=(o,t)=>yt(o,"name",{value:t,configurable:!0});var re=(o,t)=>{for(var e in t)yt(o,e,{get:t[e],enumerable:!0})},se=(o,t,e,i)=>{if(t&&typeof t=="object"||typeof t=="function")for(let r of ee(t))!ie.call(o,r)&&r!==e&&yt(o,r,{get:()=>t[r],enumerable:!(i=te(t,r))||i.enumerable});return o};var ne=o=>se(yt({},"__esModule",{value:!0}),o);var de={};re(de,{FileSystemAccessFile:()=>ot,FileSystemAccessFileSystem:()=>Y,HTTPRequest:()=>X,IndexedDBFileSystem:()=>L,IndexedDBROTransaction:()=>it,IndexedDBRWTransaction:()=>dt,IndexedDBStore:()=>K,StorageFileSystem:()=>B,StorageStore:()=>mt,WorkerFS:()=>J});var oe="/",z="/";function G(o,t){if(typeof o!="string")throw new TypeError(`"${t}" is not a string`)}u(G,"validateString");function jt(o,t){let e="",i=0,r=-1,s=0,n="\0";for(let c=0;c<=o.length;++c){if(c<o.length)n=o[c];else{if(n=="/")break;n="/"}if(n=="/"){if(!(r===c-1||s===1))if(s===2){if(e.length<2||i!==2||e.at(-1)!=="."||e.at(-2)!=="."){if(e.length>2){let h=e.lastIndexOf("/");h===-1?(e="",i=0):(e=e.slice(0,h),i=e.length-1-e.lastIndexOf("/")),r=c,s=0;continue}else if(e.length!==0){e="",i=0,r=c,s=0;continue}}t&&(e+=e.length>0?"/..":"..",i=2)}else e.length>0?e+="/"+o.slice(r+1,c):e=o.slice(r+1,c),i=c-r-1;r=c,s=0}else n==="."&&s!==-1?++s:s=-1}return e}u(jt,"normalizeString");function H(...o){let t="",e=!1;for(let i=o.length-1;i>=-1&&!e;i--){let r=i>=0?o[i]:oe;G(r,`paths[${i}]`),r.length!==0&&(t=`${r}/${t}`,e=r[0]==="/")}return t=jt(t,!e),e?`/${t}`:t.length>0?t:"."}u(H,"resolve");function ae(o){if(G(o,"path"),o.length===0)return".";let t=o[0]==="/",e=o.at(-1)==="/";return o=jt(o,!t),o.length===0?t?"/":e?"./":".":(e&&(o+="/"),t?`/${o}`:o)}u(ae,"normalize");function F(...o){if(o.length===0)return".";let t;for(let e=0;e<o.length;++e){let i=o[e];G(i,"path"),i.length>0&&(t===void 0?t=i:t+=`/${i}`)}return t===void 0?".":ae(t)}u(F,"join");function y(o){if(G(o,"path"),o.length===0)return".";let t=o[0]==="/",e=-1,i=!0;for(let r=o.length-1;r>=1;--r)if(o[r]==="/"){if(!i){e=r;break}}else i=!1;return e===-1?t?"/":".":t&&e===1?"//":o.slice(0,e)}u(y,"dirname");function _(o,t){t!==void 0&&G(t,"ext"),G(o,"path");let e=0,i=-1,r=!0;if(t!==void 0&&t.length>0&&t.length<=o.length){if(t===o)return"";let s=t.length-1,n=-1;for(let c=o.length-1;c>=0;--c)if(o[c]==="/"){if(!r){e=c+1;break}}else n===-1&&(r=!1,n=c+1),s>=0&&(o[c]===t[s]?--s===-1&&(i=c):(s=-1,i=n));return e===i?i=n:i===-1&&(i=o.length),o.slice(e,i)}for(let s=o.length-1;s>=0;--s)if(o[s]==="/"){if(!r){e=s+1;break}}else i===-1&&(r=!1,i=s+1);return i===-1?"":o.slice(e,i)}u(_,"basename");function gt(o,t,e,i,r){return Math.min(o+1,t+1,e+1,i===r?t:t+1)}u(gt,"_min");function ce(o,t){if(o===t)return 0;o.length>t.length&&([o,t]=[t,o]);let e=o.length,i=t.length;for(;e>0&&o.charCodeAt(e-1)===t.charCodeAt(i-1);)e--,i--;let r=0;for(;r<e&&o.charCodeAt(r)===t.charCodeAt(r);)r++;if(e-=r,i-=r,e===0||i===1)return i;let s=new Array(e<<1);for(let p=0;p<e;)s[e+p]=o.charCodeAt(r+p),s[p]=++p;let n,c,h,d,f;for(n=0;n+3<i;){let p=t.charCodeAt(r+(c=n)),w=t.charCodeAt(r+(h=n+1)),S=t.charCodeAt(r+(d=n+2)),U=t.charCodeAt(r+(f=n+3)),rt=n+=4;for(let pt=0;pt<e;){let wt=s[e+pt],Ht=s[pt];c=gt(Ht,c,h,p,wt),h=gt(c,h,d,w,wt),d=gt(h,d,f,S,wt),rt=gt(d,f,rt,U,wt),s[pt++]=rt,f=d,d=h,h=c,c=Ht}}let m=0;for(;n<i;){let p=t.charCodeAt(r+(c=n));m=++n;for(let w=0;w<e;w++){let S=s[w];s[w]=m=S<c||m<c?S>m?m+1:S+1:p===s[e+w]?c:c+1,c=S}}return m}u(ce,"levenshtein");async function Vt(o,t){let e=o.Options,i=o.Name,r=0,s=!1,n=!1;for(let c in e)if(Object.prototype.hasOwnProperty.call(e,c)){let h=e[c],d=t&&t[c];if(d==null){if(!h.optional){let f=Object.keys(t).filter(m=>!(m in e)).map(m=>({str:m,distance:ce(c,m)})).filter(m=>m.distance<5).sort((m,p)=>m.distance-p.distance);if(s)return;throw s=!0,new a(l.EINVAL,`[${i}] Required option '${c}' not provided.${f.length>0?` You provided unrecognized option '${f[0].str}'; perhaps you meant to type '${c}'.`:""}
2
- Option description: ${h.description}`)}}else{let f=!1;if(Array.isArray(h.type)?f=h.type.indexOf(typeof d)!==-1:f=typeof d===h.type,f){if(h.validator){r++;try{await h.validator(d)}catch(m){if(!s){if(m)throw s=!0,m;if(r--,r===0&&n)return}}}}else{if(s)return;throw s=!0,new a(l.EINVAL,`[${i}] Value provided for option ${c} is not the proper type. Expected ${Array.isArray(h.type)?`one of {${h.type.join(", ")}}`:h.type}, but received ${typeof d}
3
- Option description: ${h.description}`)}}}n=!0}u(Vt,"checkOptions");var we=typeof globalThis.setImmediate=="function"?globalThis.setImmediate:o=>setTimeout(o,0),P="/",kt=new Map,le=new globalThis.TextEncoder;function E(o,t="utf8"){return le.encode(o)}u(E,"encode");function C(o,t="utf8"){if(!kt.has(t)){let e=new globalThis.TextDecoder(t);kt.set(t,e.decode.bind(e))}return kt.get(t)(o)}u(C,"decode");function Q(){return"xxxxxxxx-xxxx-4xxx-yxxx-xxxxxxxxxxxx".replace(/[xy]/g,function(o){let t=Math.random()*16|0;return(o==="x"?t:t&3|8).toString(16)})}u(Q,"randomUUID");var l;(function(o){o[o.EPERM=1]="EPERM",o[o.ENOENT=2]="ENOENT",o[o.EIO=5]="EIO",o[o.EBADF=9]="EBADF",o[o.EACCES=13]="EACCES",o[o.EBUSY=16]="EBUSY",o[o.EEXIST=17]="EEXIST",o[o.ENOTDIR=20]="ENOTDIR",o[o.EISDIR=21]="EISDIR",o[o.EINVAL=22]="EINVAL",o[o.EFBIG=27]="EFBIG",o[o.ENOSPC=28]="ENOSPC",o[o.EROFS=30]="EROFS",o[o.ENOTEMPTY=39]="ENOTEMPTY",o[o.ENOTSUP=95]="ENOTSUP"})(l=l||(l={}));var $t={[l.EPERM]:"Operation not permitted.",[l.ENOENT]:"No such file or directory.",[l.EIO]:"Input/output error.",[l.EBADF]:"Bad file descriptor.",[l.EACCES]:"Permission denied.",[l.EBUSY]:"Resource busy or locked.",[l.EEXIST]:"File exists.",[l.ENOTDIR]:"File is not a directory.",[l.EISDIR]:"File is a directory.",[l.EINVAL]:"Invalid argument.",[l.EFBIG]:"File is too big.",[l.ENOSPC]:"No space left on disk.",[l.EROFS]:"Cannot modify a read-only file system.",[l.ENOTEMPTY]:"Directory is not empty.",[l.ENOTSUP]:"Operation is not supported."},a=class extends Error{static fromJSON(t){let e=new a(t.errno,t.message,t.path);return e.code=t.code,e.stack=t.stack,e}static Derserialize(t,e=0){let i=new DataView("buffer"in t?t.buffer:t),r=C(i.buffer.slice(e+4,e+4+i.getUint32(e,!0)));return a.fromJSON(JSON.parse(r))}static FileError(t,e){return new a(t,$t[t],e)}static EACCES(t){return this.FileError(l.EACCES,t)}static ENOENT(t){return this.FileError(l.ENOENT,t)}static EEXIST(t){return this.FileError(l.EEXIST,t)}static EISDIR(t){return this.FileError(l.EISDIR,t)}static ENOTDIR(t){return this.FileError(l.ENOTDIR,t)}static EPERM(t){return this.FileError(l.EPERM,t)}static ENOTEMPTY(t){return this.FileError(l.ENOTEMPTY,t)}constructor(t,e=$t[t],i){super(e),this.syscall="",this.errno=t,this.code=l[t],this.path=i,this.message=`Error: ${this.code}: ${e}${this.path?`, '${this.path}'`:""}`}toString(){return this.message}toJSON(){return{errno:this.errno,code:this.code,path:this.path,stack:this.stack,message:this.message}}serialize(t=new Uint8Array(this.bufferSize()),e=0){let i=new DataView("buffer"in t?t.buffer:t),r=new Uint8Array(i.buffer),s=E(JSON.stringify(this.toJSON()));return r.set(s),i.setUint32(e,s.byteLength,!0),r}bufferSize(){return 4+JSON.stringify(this.toJSON()).length}};u(a,"ApiError");var D=class{constructor(t,e,i,r,s,n){this.uid=t,this.gid=e,this.suid=i,this.sgid=r,this.euid=s,this.egid=n}};u(D,"Cred");D.Root=new D(0,0,0,0,0,0);var g;(function(o){o[o.FILE=32768]="FILE",o[o.DIRECTORY=16384]="DIRECTORY",o[o.SYMLINK=40960]="SYMLINK"})(g=g||(g={}));var Et=class{static Deserialize(t){throw new ReferenceError("Called static abstract method: StatsCommon.Deserialize()")}get _typename(){return this._isBigint?"bigint":"number"}get _typename_inverse(){return this._isBigint?"number":"bigint"}_convert(t){return this._isBigint?BigInt(t):Number(t)}get atime(){return new Date(Number(this.atimeMs))}get mtime(){return new Date(Number(this.mtimeMs))}get ctime(){return new Date(Number(this.ctimeMs))}get birthtime(){return new Date(Number(this.birthtimeMs))}constructor(t=g.FILE,e=-1,i,r,s,n,c,h,d){this.dev=this._convert(0),this.ino=this._convert(0),this.rdev=this._convert(0),this.nlink=this._convert(1),this.blksize=this._convert(4096),this.uid=this._convert(0),this.gid=this._convert(0),this.fileData=null;let f=Date.now(),m=u((p,w)=>typeof p==this._typename?p:this._convert(typeof p==this._typename_inverse?p:w),"resolveT");if(this.atimeMs=m(r,f),this.mtimeMs=m(s,f),this.ctimeMs=m(n,f),this.birthtimeMs=m(d,f),this.uid=m(c,0),this.gid=m(h,0),this.size=this._convert(e),i)this.mode=this._convert(i);else switch(t){case g.FILE:this.mode=this._convert(420);break;case g.DIRECTORY:default:this.mode=this._convert(511)}this.blocks=this._convert(Math.ceil(Number(e)/512)),this.mode&61440||(this.mode=this.mode|this._convert(t))}isFile(){return(this.mode&61440)===32768}isDirectory(){return(this.mode&61440)===16384}isSymbolicLink(){return(this.mode&61440)===40960}hasAccess(t,e){if(e.euid===0||e.egid===0)return!0;let i=this.mode&-61441,r=15,s=15,n=15;if(e.euid==this.uid){let d=(3840&i)>>8;r=(t^d)&t}if(e.egid==this.gid){let d=(240&i)>>4;s=(t^d)&t}let c=15&i;return n=(t^c)&t,!(r&s&n)}getCred(t=Number(this.uid),e=Number(this.gid)){return new D(t,e,Number(this.uid),Number(this.gid),t,e)}chmod(t){this.mode=this._convert(this.mode&61440|t)}chown(t,e){t=Number(t),e=Number(e),!isNaN(t)&&0<=t&&t<2**32&&(this.uid=this._convert(t)),!isNaN(e)&&0<=e&&e<2**32&&(this.gid=this._convert(e))}isSocket(){return!1}isBlockDevice(){return!1}isCharacterDevice(){return!1}isFIFO(){return!1}};u(Et,"StatsCommon");var x=class extends Et{constructor(){super(...arguments),this._isBigint=!1}static clone(t){return new x(t.mode&61440,t.size,t.mode&-61441,t.atimeMs,t.mtimeMs,t.ctimeMs,t.uid,t.gid,t.birthtimeMs)}static Deserialize(t){let e=new DataView("buffer"in t?t.buffer:t),i=e.getUint32(0,!0),r=e.getUint32(4,!0),s=e.getFloat64(8,!0),n=e.getFloat64(16,!0),c=e.getFloat64(24,!0),h=e.getUint32(32,!0),d=e.getUint32(36,!0);return new x(r&61440,i,r&-61441,s,n,c,h,d)}serialize(){let t=new Uint8Array(32),e=new DataView(t.buffer);return e.setUint32(0,this.size,!0),e.setUint32(4,this.mode,!0),e.setFloat64(8,this.atime.getTime(),!0),e.setFloat64(16,this.mtime.getTime(),!0),e.setFloat64(24,this.ctime.getTime(),!0),e.setUint32(32,this.uid,!0),e.setUint32(36,this.gid,!0),t}};u(x,"Stats");var Xt,St=class{constructor(t){}};u(St,"FileSystem");var O=class extends St{constructor(t){super(),this._ready=Promise.resolve(this)}get metadata(){return{name:this.constructor.name,readonly:!1,synchronous:!1,supportsProperties:!1,supportsLinks:!1,totalSpace:0,freeSpace:0}}whenReady(){return this._ready}async openFile(t,e,i){throw new a(l.ENOTSUP)}async createFile(t,e,i,r){throw new a(l.ENOTSUP)}async open(t,e,i,r){try{let s=await this.stat(t,r);switch(e.pathExistsAction()){case b.THROW_EXCEPTION:throw a.EEXIST(t);case b.TRUNCATE_FILE:let n=await this.openFile(t,e,r);if(!n)throw new Error("BFS has reached an impossible code path; please file a bug.");return await n.truncate(0),await n.sync(),n;case b.NOP:return this.openFile(t,e,r);default:throw new a(l.EINVAL,"Invalid FileFlag object.")}}catch{switch(e.pathNotExistsAction()){case b.CREATE_FILE:let n=await this.stat(y(t),r);if(n&&!n.isDirectory())throw a.ENOTDIR(y(t));return this.createFile(t,e,i,r);case b.THROW_EXCEPTION:throw a.ENOENT(t);default:throw new a(l.EINVAL,"Invalid FileFlag object.")}}}async access(t,e,i){throw new a(l.ENOTSUP)}accessSync(t,e,i){throw new a(l.ENOTSUP)}async rename(t,e,i){throw new a(l.ENOTSUP)}renameSync(t,e,i){throw new a(l.ENOTSUP)}async stat(t,e){throw new a(l.ENOTSUP)}statSync(t,e){throw new a(l.ENOTSUP)}openFileSync(t,e,i){throw new a(l.ENOTSUP)}createFileSync(t,e,i,r){throw new a(l.ENOTSUP)}openSync(t,e,i,r){let s;try{s=this.statSync(t,r)}catch{switch(e.pathNotExistsAction()){case b.CREATE_FILE:if(!this.statSync(y(t),r).isDirectory())throw a.ENOTDIR(y(t));return this.createFileSync(t,e,i,r);case b.THROW_EXCEPTION:throw a.ENOENT(t);default:throw new a(l.EINVAL,"Invalid FileFlag object.")}}if(!s.hasAccess(i,r))throw a.EACCES(t);switch(e.pathExistsAction()){case b.THROW_EXCEPTION:throw a.EEXIST(t);case b.TRUNCATE_FILE:return this.unlinkSync(t,r),this.createFileSync(t,e,s.mode,r);case b.NOP:return this.openFileSync(t,e,r);default:throw new a(l.EINVAL,"Invalid FileFlag object.")}}async unlink(t,e){throw new a(l.ENOTSUP)}unlinkSync(t,e){throw new a(l.ENOTSUP)}async rmdir(t,e){throw new a(l.ENOTSUP)}rmdirSync(t,e){throw new a(l.ENOTSUP)}async mkdir(t,e,i){throw new a(l.ENOTSUP)}mkdirSync(t,e,i){throw new a(l.ENOTSUP)}async readdir(t,e){throw new a(l.ENOTSUP)}readdirSync(t,e){throw new a(l.ENOTSUP)}async exists(t,e){try{return await this.stat(t,e),!0}catch{return!1}}existsSync(t,e){try{return this.statSync(t,e),!0}catch{return!1}}async realpath(t,e){if(this.metadata.supportsLinks){let i=t.split(z);for(let r=0;r<i.length;r++){let s=i.slice(0,r+1);i[r]=F(...s)}return i.join(z)}else{if(!await this.exists(t,e))throw a.ENOENT(t);return t}}realpathSync(t,e){if(this.metadata.supportsLinks){let i=t.split(z);for(let r=0;r<i.length;r++){let s=i.slice(0,r+1);i[r]=F(...s)}return i.join(z)}else{if(this.existsSync(t,e))return t;throw a.ENOENT(t)}}async truncate(t,e,i){let r=await this.open(t,N.getFileFlag("r+"),420,i);try{await r.truncate(e)}finally{await r.close()}}truncateSync(t,e,i){let r=this.openSync(t,N.getFileFlag("r+"),420,i);try{r.truncateSync(e)}finally{r.closeSync()}}async readFile(t,e,i){let r=await this.open(t,e,420,i);try{let s=await r.stat(),n=new Uint8Array(s.size);return await r.read(n,0,s.size,0),await r.close(),n}finally{await r.close()}}readFileSync(t,e,i){let r=this.openSync(t,e,420,i);try{let s=r.statSync(),n=new Uint8Array(s.size);return r.readSync(n,0,s.size,0),r.closeSync(),n}finally{r.closeSync()}}async writeFile(t,e,i,r,s){let n=await this.open(t,i,r,s);try{typeof e=="string"&&(e=E(e)),await n.write(e,0,e.length,0)}finally{await n.close()}}writeFileSync(t,e,i,r,s){let n=this.openSync(t,i,r,s);try{typeof e=="string"&&(e=E(e)),n.writeSync(e,0,e.length,0)}finally{n.closeSync()}}async appendFile(t,e,i,r,s){let n=await this.open(t,i,r,s);try{typeof e=="string"&&(e=E(e)),await n.write(e,0,e.length,null)}finally{await n.close()}}appendFileSync(t,e,i,r,s){let n=this.openSync(t,i,r,s);try{typeof e=="string"&&(e=E(e)),n.writeSync(e,0,e.length,null)}finally{n.closeSync()}}async chmod(t,e,i){throw new a(l.ENOTSUP)}chmodSync(t,e,i){throw new a(l.ENOTSUP)}async chown(t,e,i,r){throw new a(l.ENOTSUP)}chownSync(t,e,i,r){throw new a(l.ENOTSUP)}async utimes(t,e,i,r){throw new a(l.ENOTSUP)}utimesSync(t,e,i,r){throw new a(l.ENOTSUP)}async link(t,e,i){throw new a(l.ENOTSUP)}linkSync(t,e,i){throw new a(l.ENOTSUP)}async symlink(t,e,i,r){throw new a(l.ENOTSUP)}symlinkSync(t,e,i,r){throw new a(l.ENOTSUP)}async readlink(t,e){throw new a(l.ENOTSUP)}readlinkSync(t,e){throw new a(l.ENOTSUP)}};u(O,"BaseFileSystem");Xt=O;O.Name=Xt.name;var st=class extends O{get metadata(){return{...super.metadata,synchronous:!0}}async access(t,e,i){return this.accessSync(t,e,i)}async rename(t,e,i){return this.renameSync(t,e,i)}async stat(t,e){return this.statSync(t,e)}async open(t,e,i,r){return this.openSync(t,e,i,r)}async unlink(t,e){return this.unlinkSync(t,e)}async rmdir(t,e){return this.rmdirSync(t,e)}async mkdir(t,e,i){return this.mkdirSync(t,e,i)}async readdir(t,e){return this.readdirSync(t,e)}async chmod(t,e,i){return this.chmodSync(t,e,i)}async chown(t,e,i,r){return this.chownSync(t,e,i,r)}async utimes(t,e,i,r){return this.utimesSync(t,e,i,r)}async link(t,e,i){return this.linkSync(t,e,i)}async symlink(t,e,i,r){return this.symlinkSync(t,e,i,r)}async readlink(t,e){return this.readlinkSync(t,e)}};u(st,"SynchronousFileSystem");var I=class{static Deserialize(t){let e=new DataView("buffer"in t?t.buffer:t);return new I(C(e.buffer.slice(38)),e.getUint32(0,!0),e.getUint16(4,!0),e.getFloat64(6,!0),e.getFloat64(14,!0),e.getFloat64(22,!0),e.getUint32(30,!0),e.getUint32(34,!0))}constructor(t,e,i,r,s,n,c,h){this.id=t,this.size=e,this.mode=i,this.atime=r,this.mtime=s,this.ctime=n,this.uid=c,this.gid=h}toStats(){return new x((this.mode&61440)===g.DIRECTORY?g.DIRECTORY:g.FILE,this.size,this.mode,this.atime,this.mtime,this.ctime,this.uid,this.gid)}getSize(){return 38+this.id.length}serialize(t=new Uint8Array(this.getSize())){let e=new DataView("buffer"in t?t.buffer:t);e.setUint32(0,this.size,!0),e.setUint16(4,this.mode,!0),e.setFloat64(6,this.atime,!0),e.setFloat64(14,this.mtime,!0),e.setFloat64(22,this.ctime,!0),e.setUint32(30,this.uid,!0),e.setUint32(34,this.gid,!0);let i=new Uint8Array(e.buffer);return i.set(E(this.id),38),i}update(t){let e=!1;this.size!==t.size&&(this.size=t.size,e=!0),this.mode!==t.mode&&(this.mode=t.mode,e=!0);let i=t.atime.getTime();this.atime!==i&&(this.atime=i,e=!0);let r=t.mtime.getTime();this.mtime!==r&&(this.mtime=r,e=!0);let s=t.ctime.getTime();return this.ctime!==s&&(this.ctime=s,e=!0),this.uid!==t.uid&&(this.uid=t.uid,e=!0),this.uid!==t.uid&&(this.uid=t.uid,e=!0),e}isFile(){return(this.mode&61440)===g.FILE}isDirectory(){return(this.mode&61440)===g.DIRECTORY}};u(I,"Inode");var j=class{constructor(t){this.store=t,this.originalData={},this.modifiedKeys=[]}get(t){let e=this.store.get(t);return this.stashOldValue(t,e),e}put(t,e,i){return this.markModified(t),this.store.put(t,e,i)}del(t){this.markModified(t),this.store.del(t)}commit(){}abort(){for(let t of this.modifiedKeys){let e=this.originalData[t];e?this.store.put(t,e,!0):this.store.del(t)}}_has(t){return Object.prototype.hasOwnProperty.call(this.originalData,t)}stashOldValue(t,e){this._has(t)||(this.originalData[t]=e)}markModified(t){this.modifiedKeys.indexOf(t)===-1&&(this.modifiedKeys.push(t),this._has(t)||(this.originalData[t]=this.store.get(t)))}};u(j,"SimpleSyncRWTransaction");var nt=class extends A{constructor(t,e,i,r,s){super(t,e,i,r,s)}syncSync(){this.isDirty()&&(this._fs._syncSync(this.getPath(),this.getBuffer(),this.getStats()),this.resetDirty())}closeSync(){this.syncSync()}};u(nt,"SyncKeyValueFile");var V=class extends st{static isAvailable(){return!0}constructor(t){super(),this.store=t.store,this.makeRootDirectory()}getName(){return this.store.name()}isReadOnly(){return!1}supportsSymlinks(){return!1}supportsProps(){return!0}supportsSynch(){return!0}empty(){this.store.clear(),this.makeRootDirectory()}accessSync(t,e,i){let r=this.store.beginTransaction("readonly");if(!this.findINode(r,t).toStats().hasAccess(e,i))throw a.EACCES(t)}renameSync(t,e,i){let r=this.store.beginTransaction("readwrite"),s=y(t),n=_(t),c=y(e),h=_(e),d=this.findINode(r,s),f=this.getDirListing(r,s,d);if(!d.toStats().hasAccess(2,i))throw a.EACCES(t);if(!f[n])throw a.ENOENT(t);let m=f[n];if(delete f[n],(c+"/").indexOf(t+"/")===0)throw new a(l.EBUSY,s);let p,w;if(c===s?(p=d,w=f):(p=this.findINode(r,c),w=this.getDirListing(r,c,p)),w[h]){let S=this.getINode(r,e,w[h]);if(S.isFile())try{r.del(S.id),r.del(w[h])}catch(U){throw r.abort(),U}else throw a.EPERM(e)}w[h]=m;try{r.put(d.id,E(JSON.stringify(f)),!0),r.put(p.id,E(JSON.stringify(w)),!0)}catch(S){throw r.abort(),S}r.commit()}statSync(t,e){let i=this.findINode(this.store.beginTransaction("readonly"),t).toStats();if(!i.hasAccess(4,e))throw a.EACCES(t);return i}createFileSync(t,e,i,r){let s=this.store.beginTransaction("readwrite"),n=new Uint8Array(0),c=this.commitNewFile(s,t,g.FILE,i,r,n);return new nt(this,t,e,c.toStats(),n)}openFileSync(t,e,i){let r=this.store.beginTransaction("readonly"),s=this.findINode(r,t),n=r.get(s.id);if(!s.toStats().hasAccess(e.getMode(),i))throw a.EACCES(t);if(n===void 0)throw a.ENOENT(t);return new nt(this,t,e,s.toStats(),n)}unlinkSync(t,e){this.removeEntry(t,!1,e)}rmdirSync(t,e){if(this.readdirSync(t,e).length>0)throw a.ENOTEMPTY(t);this.removeEntry(t,!0,e)}mkdirSync(t,e,i){let r=this.store.beginTransaction("readwrite"),s=E("{}");this.commitNewFile(r,t,g.DIRECTORY,e,i,s)}readdirSync(t,e){let i=this.store.beginTransaction("readonly"),r=this.findINode(i,t);if(!r.toStats().hasAccess(4,e))throw a.EACCES(t);return Object.keys(this.getDirListing(i,t,r))}chmodSync(t,e,i){this.openFileSync(t,N.getFileFlag("r+"),i).chmodSync(e)}chownSync(t,e,i,r){this.openFileSync(t,N.getFileFlag("r+"),r).chownSync(e,i)}_syncSync(t,e,i){let r=this.store.beginTransaction("readwrite"),s=this._findINode(r,y(t),_(t)),n=this.getINode(r,t,s),c=n.update(i);try{r.put(n.id,e,!0),c&&r.put(s,n.serialize(),!0)}catch(h){throw r.abort(),h}r.commit()}makeRootDirectory(){let t=this.store.beginTransaction("readwrite");if(t.get(P)===void 0){let e=new Date().getTime(),i=new I(Q(),4096,511|g.DIRECTORY,e,e,e,0,0);t.put(i.id,E("{}"),!1),t.put(P,i.serialize(),!1),t.commit()}}_findINode(t,e,i,r=new Set){let s=F(e,i);if(r.has(s))throw new a(l.EIO,"Infinite loop detected while finding inode",s);r.add(s);let n=u(c=>{let h=this.getDirListing(t,e,c);if(h[i])return h[i];throw a.ENOENT(H(e,i))},"readDirectory");return e==="/"?i===""?P:n(this.getINode(t,e,P)):n(this.getINode(t,e+z+i,this._findINode(t,y(e),_(e),r)))}findINode(t,e){return this.getINode(t,e,this._findINode(t,y(e),_(e)))}getINode(t,e,i){let r=t.get(i);if(r===void 0)throw a.ENOENT(e);return I.Deserialize(r)}getDirListing(t,e,i){if(!i.isDirectory())throw a.ENOTDIR(e);let r=t.get(i.id);if(r===void 0)throw a.ENOENT(e);return JSON.parse(C(r))}addNewNode(t,e){let r;for(;0<5;)try{return r=Q(),t.put(r,e,!1),r}catch{}throw new a(l.EIO,"Unable to commit data to key-value store.")}commitNewFile(t,e,i,r,s,n){let c=y(e),h=_(e),d=this.findINode(t,c),f=this.getDirListing(t,c,d),m=new Date().getTime();if(!d.toStats().hasAccess(4,s))throw a.EACCES(e);if(e==="/")throw a.EEXIST(e);if(f[h])throw a.EEXIST(e);let p;try{let w=this.addNewNode(t,n);p=new I(w,n.length,r|i,m,m,m,s.uid,s.gid);let S=this.addNewNode(t,p.serialize());f[h]=S,t.put(d.id,E(JSON.stringify(f)),!0)}catch(w){throw t.abort(),w}return t.commit(),p}removeEntry(t,e,i){let r=this.store.beginTransaction("readwrite"),s=y(t),n=this.findINode(r,s),c=this.getDirListing(r,s,n),h=_(t);if(!c[h])throw a.ENOENT(t);let d=c[h],f=this.getINode(r,t,d);if(!f.toStats().hasAccess(2,i))throw a.EACCES(t);if(delete c[h],!e&&f.isDirectory())throw a.EISDIR(t);if(e&&!f.isDirectory())throw a.ENOTDIR(t);try{r.del(f.id),r.del(d),r.put(n.id,E(JSON.stringify(c)),!0)}catch(m){throw r.abort(),m}r.commit()}};u(V,"SyncKeyValueFileSystem");function T(o,t){t=typeof o=="function"?o:t,Vt(this,o);let e=new this(typeof o=="function"?{}:o);if(typeof t!="function")return e.whenReady();e.whenReady().then(i=>t(null,i)).catch(i=>t(i))}u(T,"CreateBackend");var Kt,bt=class{constructor(){this.store=new Map}name(){return v.Name}clear(){this.store.clear()}beginTransaction(t){return new j(this)}get(t){return this.store.get(t)}put(t,e,i){return!i&&this.store.has(t)?!1:(this.store.set(t,e),!0)}del(t){this.store.delete(t)}};u(bt,"InMemoryStore");var v=class extends V{constructor(){super({store:new bt})}};u(v,"InMemoryFileSystem");Kt=v;v.Name="InMemory";v.Create=T.bind(Kt);v.Options={};var ni=D.Root;var Mt=new Map;v.Create().then(o=>he("/",o));function Nt(o){return Mt.get(o)}u(Nt,"getMount");function he(o,t){if(o[0]!=="/"&&(o="/"+o),o=H(o),Mt.has(o))throw new a(l.EINVAL,"Mount point "+o+" is already in use.");Mt.set(o,t)}u(he,"mount");var b;(function(o){o[o.NOP=0]="NOP",o[o.THROW_EXCEPTION=1]="THROW_EXCEPTION",o[o.TRUNCATE_FILE=2]="TRUNCATE_FILE",o[o.CREATE_FILE=3]="CREATE_FILE"})(b=b||(b={}));var N=class{static getFileFlag(t){return N.flagCache.has(t)||N.flagCache.set(t,new N(t)),N.flagCache.get(t)}constructor(t){if(typeof t=="number"&&(t=N.StringFromNumber(t)),N.validFlagStrs.indexOf(t)<0)throw new a(l.EINVAL,"Invalid flag string: "+t);this.flagStr=t}static StringFromNumber(t){switch(t){case 0:return"r";case 1052672:return"rs";case 2:return"r+";case 1052674:return"rs+";case 577:return"w";case 705:return"wx";case 578:return"w+";case 706:return"wx+";case 1089:return"a";case 1217:return"ax";case 1090:return"a+";case 1218:return"ax+";default:throw new a(l.EINVAL,"Invalid flag number: "+t)}}getFlagString(){return this.flagStr}getMode(){let t=0;return t<<=1,t+=+this.isReadable(),t<<=1,t+=+this.isWriteable(),t<<=1,t}isReadable(){return this.flagStr.indexOf("r")!==-1||this.flagStr.indexOf("+")!==-1}isWriteable(){return this.flagStr.indexOf("w")!==-1||this.flagStr.indexOf("a")!==-1||this.flagStr.indexOf("+")!==-1}isTruncating(){return this.flagStr.indexOf("w")!==-1}isAppendable(){return this.flagStr.indexOf("a")!==-1}isSynchronous(){return this.flagStr.indexOf("s")!==-1}isExclusive(){return this.flagStr.indexOf("x")!==-1}pathExistsAction(){return this.isExclusive()?b.THROW_EXCEPTION:this.isTruncating()?b.TRUNCATE_FILE:b.NOP}pathNotExistsAction(){return(this.isWriteable()||this.isAppendable())&&this.flagStr!=="r+"?b.CREATE_FILE:b.THROW_EXCEPTION}};u(N,"FileFlag");N.flagCache=new Map;N.validFlagStrs=["r","r+","rs","rs+","w","wx","w+","wx+","a","ax","a+","ax+"];var Ft=class{async sync(){throw new a(l.ENOTSUP)}syncSync(){throw new a(l.ENOTSUP)}async datasync(){return this.sync()}datasyncSync(){return this.syncSync()}async chown(t,e){throw new a(l.ENOTSUP)}chownSync(t,e){throw new a(l.ENOTSUP)}async chmod(t){throw new a(l.ENOTSUP)}chmodSync(t){throw new a(l.ENOTSUP)}async utimes(t,e){throw new a(l.ENOTSUP)}utimesSync(t,e){throw new a(l.ENOTSUP)}};u(Ft,"BaseFile");var A=class extends Ft{constructor(t,e,i,r,s){if(super(),this._pos=0,this._dirty=!1,this._fs=t,this._path=e,this._flag=i,this._stat=r,this._buffer=s||new Uint8Array(0),this._stat.size!==this._buffer.length&&this._flag.isReadable())throw new Error(`Invalid buffer: Uint8Array is ${this._buffer.length} long, yet Stats object specifies that file is ${this._stat.size} long.`)}getBuffer(){return this._buffer}getStats(){return this._stat}getFlag(){return this._flag}getPath(){return this._path}getPos(){return this._flag.isAppendable()?this._stat.size:this._pos}advancePos(t){return this._pos+=t}setPos(t){return this._pos=t}async sync(){this.syncSync()}syncSync(){throw new a(l.ENOTSUP)}async close(){this.closeSync()}closeSync(){throw new a(l.ENOTSUP)}async stat(){return x.clone(this._stat)}statSync(){return x.clone(this._stat)}truncate(t){if(this.truncateSync(t),this._flag.isSynchronous()&&!Nt("/").metadata.synchronous)return this.sync()}truncateSync(t){if(this._dirty=!0,!this._flag.isWriteable())throw new a(l.EPERM,"File not opened with a writeable mode.");if(this._stat.mtimeMs=Date.now(),t>this._buffer.length){let e=new Uint8Array(t-this._buffer.length);this.writeSync(e,0,e.length,this._buffer.length),this._flag.isSynchronous()&&Nt("/").metadata.synchronous&&this.syncSync();return}this._stat.size=t,this._buffer=this._buffer.subarray(0,t),this._flag.isSynchronous()&&Nt("/").metadata.synchronous&&this.syncSync()}async write(t,e,i,r){return this.writeSync(t,e,i,r)}writeSync(t,e,i,r){if(this._dirty=!0,r==null&&(r=this.getPos()),!this._flag.isWriteable())throw new a(l.EPERM,"File not opened with a writeable mode.");let s=r+i;if(s>this._stat.size&&(this._stat.size=s,s>this._buffer.length)){let c=new Uint8Array(s);c.set(this._buffer),this._buffer=c}this._buffer.set(t.slice(e,e+i),r);let n=this._buffer.length;return this._stat.mtimeMs=Date.now(),this._flag.isSynchronous()?(this.syncSync(),n):(this.setPos(r+n),n)}async read(t,e,i,r){return{bytesRead:this.readSync(t,e,i,r),buffer:t}}readSync(t,e,i,r){if(!this._flag.isReadable())throw new a(l.EPERM,"File not opened with a readable mode.");return r==null&&(r=this.getPos()),r+i>this._stat.size&&(i=this._stat.size-r),this._buffer.set(t.slice(e,e+i),r),this._stat.atimeMs=Date.now(),this._pos=r+i,this._buffer.length}async chmod(t){this.chmodSync(t)}chmodSync(t){if(!this._fs.metadata.supportsProperties)throw new a(l.ENOTSUP);this._dirty=!0,this._stat.chmod(t),this.syncSync()}async chown(t,e){this.chownSync(t,e)}chownSync(t,e){if(!this._fs.metadata.supportsProperties)throw new a(l.ENOTSUP);this._dirty=!0,this._stat.chown(t,e),this.syncSync()}isDirty(){return this._dirty}resetDirty(){this._dirty=!1}};u(A,"PreloadFile");var W=class extends A{constructor(t,e,i,r,s){super(t,e,i,r,s)}async sync(){}syncSync(){}async close(){}closeSync(){}};u(W,"NoSyncFile");var Tt=u((o="",t)=>{throw t.name==="NotFoundError"?a.ENOENT(o):t},"handleError"),ot=class extends A{constructor(t,e,i,r,s){super(t,e,i,r,s)}async sync(){this.isDirty()&&(await this._fs._sync(this.getPath(),this.getBuffer(),this.getStats(),D.Root),this.resetDirty())}async close(){await this.sync()}};u(ot,"FileSystemAccessFile");var Pt=class extends O{constructor({handle:e}){super();this._handles=new Map;this._handles.set("/",e)}static isAvailable(){return typeof FileSystemHandle=="function"}get metadata(){return{...super.metadata,name:Pt.Name}}async _sync(e,i,r,s){let n=await this.stat(e,s);r.mtime!==n.mtime&&await this.writeFile(e,i,N.getFileFlag("w"),n.mode,s)}async rename(e,i,r){try{let s=await this.getHandle(e);if(s instanceof FileSystemDirectoryHandle){let n=await this.readdir(e,r);if(await this.mkdir(i,"wx",r),n.length===0)await this.unlink(e,r);else for(let c of n)await this.rename(F(e,c),F(i,c),r),await this.unlink(e,r)}if(s instanceof FileSystemFileHandle){let n=await s.getFile(),c=await this.getHandle(y(i));if(c instanceof FileSystemDirectoryHandle){let d=await(await c.getFileHandle(_(i),{create:!0})).createWritable(),f=await n.arrayBuffer();await d.write(f),d.close(),await this.unlink(e,r)}}}catch(s){Tt(e,s)}}async writeFile(e,i,r,s,n,c){let h=await this.getHandle(y(e));if(h instanceof FileSystemDirectoryHandle){let f=await(await h.getFileHandle(_(e),{create:!0})).createWritable();await f.write(i),await f.close()}}async createFile(e,i,r,s){return await this.writeFile(e,new Uint8Array,i,r,s,!0),this.openFile(e,i,s)}async stat(e,i){let r=await this.getHandle(e);if(!r)throw a.FileError(l.EINVAL,e);if(r instanceof FileSystemDirectoryHandle)return new x(g.DIRECTORY,4096);if(r instanceof FileSystemFileHandle){let{lastModified:s,size:n}=await r.getFile();return new x(g.FILE,n,void 0,void 0,s)}}async exists(e,i){try{return await this.getHandle(e),!0}catch{return!1}}async openFile(e,i,r){let s=await this.getHandle(e);if(s instanceof FileSystemFileHandle){let n=await s.getFile(),c=await n.arrayBuffer();return this.newFile(e,i,c,n.size,n.lastModified)}}async unlink(e,i){let r=await this.getHandle(y(e));if(r instanceof FileSystemDirectoryHandle)try{await r.removeEntry(_(e),{recursive:!0})}catch(s){Tt(e,s)}}async rmdir(e,i){return this.unlink(e,i)}async mkdir(e,i,r){let s=i&&i.flag&&i.flag.includes("w")&&!i.flag.includes("x");if(await this.getHandle(e)&&!s)throw a.EEXIST(e);let c=await this.getHandle(y(e));c instanceof FileSystemDirectoryHandle&&await c.getDirectoryHandle(_(e),{create:!0})}async readdir(e,i){let r=await this.getHandle(e);if(!(r instanceof FileSystemDirectoryHandle))throw a.ENOTDIR(e);let s=[];for await(let n of r.keys())s.push(F(e,n));return s}newFile(e,i,r,s,n){return new ot(this,e,i,new x(g.FILE,s||0,void 0,void 0,n||new Date().getTime()),new Uint8Array(r))}async getHandle(e){if(this._handles.has(e))return this._handles.get(e);let i="/",[,...r]=e.split("/"),s=u(async([n,...c])=>{let h=F(i,n),d=u(m=>{if(i=h,this._handles.set(i,m),c.length===0)return this._handles.get(e);s(c)},"continueWalk"),f=this._handles.get(i);try{return await d(await f.getDirectoryHandle(n))}catch(m){if(m.name==="TypeMismatchError")try{return await d(await f.getFileHandle(n))}catch(p){Tt(h,p)}else{if(m.message==="Name is not allowed.")throw new a(l.ENOENT,m.message,h);Tt(h,m)}}},"getHandleParts");await s(r)}},Y=Pt;u(Y,"FileSystemAccessFileSystem"),Y.Name="FileSystemAccess",Y.Create=T.bind(Pt),Y.Options={};var Qt=typeof fetch<"u"&&fetch!==null;function Dt(o){throw new a(l.EIO,o.message)}u(Dt,"convertError");async function Lt(o,t){let e=await fetch(o).catch(Dt);if(!e.ok)throw new a(l.EIO,`fetch error: response returned code ${e.status}`);switch(t){case"buffer":let i=await e.arrayBuffer().catch(Dt);return new Uint8Array(i);case"json":return e.json().catch(Dt);default:throw new a(l.EINVAL,"Invalid download type: "+t)}}u(Lt,"fetchFile");async function Zt(o){let t=await fetch(o,{method:"HEAD"}).catch(Dt);if(!t.ok)throw new a(l.EIO,`fetch HEAD error: response returned code ${t.status}`);return parseInt(t.headers.get("Content-Length")||"-1",10)}u(Zt,"fetchFileSize");var q=class{static fromListing(t){let e=new q,i=new M;e._index["/"]=i;let r=[["",t,i]];for(;r.length>0;){let s,n=r.pop(),c=n[0],h=n[1],d=n[2];for(let f in h)if(Object.prototype.hasOwnProperty.call(h,f)){let m=h[f],p=`${c}/${f}`;m?(e._index[p]=s=new M,r.push([p,m,s])):s=new Ct(new x(g.FILE,-1,365)),d&&(d._ls[f]=s)}}return e}constructor(){this._index={},this.addPath("/",new M)}fileIterator(t){for(let e in this._index)if(Object.prototype.hasOwnProperty.call(this._index,e)){let i=this._index[e],r=i.getListing();for(let s of r){let n=i.getItem(s);at(n)&&t(n.getData())}}}addPath(t,e){if(!e)throw new Error("Inode must be specified");if(t[0]!=="/")throw new Error("Path must be absolute, got: "+t);if(Object.prototype.hasOwnProperty.call(this._index,t))return this._index[t]===e;let i=this._split_path(t),r=i[0],s=i[1],n=this._index[r];return n===void 0&&t!=="/"&&(n=new M,!this.addPath(r,n))||t!=="/"&&!n.addItem(s,e)?!1:(et(e)&&(this._index[t]=e),!0)}addPathFast(t,e){let i=t.lastIndexOf("/"),r=i===0?"/":t.substring(0,i),s=t.substring(i+1),n=this._index[r];return n===void 0&&(n=new M,this.addPathFast(r,n)),n.addItem(s,e)?(e.isDir()&&(this._index[t]=e),!0):!1}removePath(t){let e=this._split_path(t),i=e[0],r=e[1],s=this._index[i];if(s===void 0)return null;let n=s.remItem(r);if(n===null)return null;if(et(n)){let c=n.getListing();for(let h of c)this.removePath(t+"/"+h);t!=="/"&&delete this._index[t]}return n}ls(t){let e=this._index[t];return e===void 0?null:e.getListing()}getInode(t){let e=this._split_path(t),i=e[0],r=e[1],s=this._index[i];return s===void 0?null:i===t?s:s.getItem(r)}_split_path(t){let e=y(t),i=t.slice(e.length+(e==="/"?0:1));return[e,i]}};u(q,"FileIndex");var Ct=class{constructor(t){this.data=t}isFile(){return!0}isDir(){return!1}getData(){return this.data}setData(t){this.data=t}toStats(){return new x(g.FILE,4096,438)}};u(Ct,"IndexFileInode");var M=class{constructor(t=null){this.data=t,this._ls={}}isFile(){return!1}isDir(){return!0}getData(){return this.data}getStats(){return new x(g.DIRECTORY,4096,365)}toStats(){return this.getStats()}getListing(){return Object.keys(this._ls)}getItem(t){let e=this._ls[t];return e||null}addItem(t,e){return t in this._ls?!1:(this._ls[t]=e,!0)}remItem(t){let e=this._ls[t];return e===void 0?null:(delete this._ls[t],e)}};u(M,"IndexDirInode");function at(o){return!!o&&o.isFile()}u(at,"isIndexFileInode");function et(o){return!!o&&o.isDir()}u(et,"isIndexDirInode");var Rt=class extends O{constructor({index:e,baseUrl:i=""}){super();e||(e="index.json");let r=typeof e=="string"?Lt(e,"json"):Promise.resolve(e);this._ready=r.then(s=>(this._index=q.fromListing(s),this)),i.length>0&&i.charAt(i.length-1)!=="/"&&(i=i+"/"),this.prefixUrl=i}static isAvailable(){return Qt}get metadata(){return{...super.metadata,name:Rt.Name,readonly:!0}}empty(){this._index.fileIterator(function(e){e.fileData=null})}preloadFile(e,i){let r=this._index.getInode(e);if(at(r)){if(r===null)throw a.ENOENT(e);let s=r.getData();s.size=i.length,s.fileData=i}else throw a.EISDIR(e)}async stat(e,i){let r=this._index.getInode(e);if(r===null)throw a.ENOENT(e);if(!r.toStats().hasAccess(4,i))throw a.EACCES(e);let s;if(at(r))s=r.getData(),s.size<0&&(s.size=await this._requestFileSize(e));else if(et(r))s=r.getStats();else throw a.FileError(l.EINVAL,e);return s}async open(e,i,r,s){if(i.isWriteable())throw new a(l.EPERM,e);let n=this._index.getInode(e);if(n===null)throw a.ENOENT(e);if(!n.toStats().hasAccess(i.getMode(),s))throw a.EACCES(e);if(at(n)||et(n))switch(i.pathExistsAction()){case b.THROW_EXCEPTION:case b.TRUNCATE_FILE:throw a.EEXIST(e);case b.NOP:if(et(n)){let d=n.getStats();return new W(this,e,i,d,d.fileData||void 0)}let c=n.getData();if(c.fileData)return new W(this,e,i,x.clone(c),c.fileData);let h=await this._requestFile(e,"buffer");return c.size=h.length,c.fileData=h,new W(this,e,i,x.clone(c),h);default:throw new a(l.EINVAL,"Invalid FileMode object.")}else throw a.EPERM(e)}async readdir(e,i){return this.readdirSync(e,i)}async readFile(e,i,r){let s=await this.open(e,i,420,r);try{return s.getBuffer()}finally{await s.close()}}_getHTTPPath(e){return e.charAt(0)==="/"&&(e=e.slice(1)),this.prefixUrl+e}_requestFile(e,i){return Lt(this._getHTTPPath(e),i)}_requestFileSize(e){return Zt(this._getHTTPPath(e))}},X=Rt;u(X,"HTTPRequest"),X.Name="HTTPRequest",X.Create=T.bind(Rt),X.Options={index:{type:["string","object"],optional:!0,description:"URL to a file index as a JSON file or the file index object itself, generated with the make_http_index script. Defaults to `index.json`."},baseUrl:{type:"string",optional:!0,description:"Used as the URL prefix for fetched files. Default: Fetch files relative to the index."}};var ct=class{constructor(t,e){this.key=t,this.value=e,this.prev=null,this.next=null}};u(ct,"LRUNode");var At=class{constructor(t){this.limit=t,this.size=0,this.map={},this.head=null,this.tail=null}set(t,e){let i=new ct(t,e);this.map[t]?(this.map[t].value=i.value,this.remove(i.key)):this.size>=this.limit&&(delete this.map[this.tail.key],this.size--,this.tail=this.tail.prev,this.tail.next=null),this.setHead(i)}get(t){if(this.map[t]){let e=this.map[t].value,i=new ct(t,e);return this.remove(t),this.setHead(i),e}else return null}remove(t){let e=this.map[t];e&&(e.prev!==null?e.prev.next=e.next:this.head=e.next,e.next!==null?e.next.prev=e.prev:this.tail=e.prev,delete this.map[t],this.size--)}removeAll(){this.size=0,this.map={},this.head=null,this.tail=null}setHead(t){t.next=this.head,t.prev=null,this.head!==null&&(this.head.prev=t),this.head=t,this.tail===null&&(this.tail=t),this.size++,this.map[t.key]=t}};u(At,"LRUCache");var lt=class extends A{constructor(t,e,i,r,s){super(t,e,i,r,s)}async sync(){this.isDirty()&&(await this._fs._sync(this.getPath(),this.getBuffer(),this.getStats()),this.resetDirty())}async close(){this.sync()}};u(lt,"AsyncKeyValueFile");var ht=class extends O{static isAvailable(){return!0}constructor(t){super(),this._cache=null,t>0&&(this._cache=new At(t))}async init(t){this.store=t,await this.makeRootDirectory()}getName(){return this.store.name()}isReadOnly(){return!1}supportsSymlinks(){return!1}supportsProps(){return!0}supportsSynch(){return!1}async empty(){this._cache&&this._cache.removeAll(),await this.store.clear(),await this.makeRootDirectory()}async access(t,e,i){let r=this.store.beginTransaction("readonly"),s=await this.findINode(r,t);if(!s)throw a.ENOENT(t);if(!s.toStats().hasAccess(e,i))throw a.EACCES(t)}async rename(t,e,i){let r=this._cache;this._cache&&(this._cache=null,r.removeAll());try{let s=this.store.beginTransaction("readwrite"),n=y(t),c=_(t),h=y(e),d=_(e),f=await this.findINode(s,n),m=await this.getDirListing(s,n,f);if(!f.toStats().hasAccess(2,i))throw a.EACCES(t);if(!m[c])throw a.ENOENT(t);let p=m[c];if(delete m[c],(h+"/").indexOf(t+"/")===0)throw new a(l.EBUSY,n);let w,S;if(h===n?(w=f,S=m):(w=await this.findINode(s,h),S=await this.getDirListing(s,h,w)),S[d]){let U=await this.getINode(s,e,S[d]);if(U.isFile())try{await s.del(U.id),await s.del(S[d])}catch(rt){throw await s.abort(),rt}else throw a.EPERM(e)}S[d]=p;try{await s.put(f.id,E(JSON.stringify(m)),!0),await s.put(w.id,E(JSON.stringify(S)),!0)}catch(U){throw await s.abort(),U}await s.commit()}finally{r&&(this._cache=r)}}async stat(t,e){let i=this.store.beginTransaction("readonly"),s=(await this.findINode(i,t)).toStats();if(!s.hasAccess(4,e))throw a.EACCES(t);return s}async createFile(t,e,i,r){let s=this.store.beginTransaction("readwrite"),n=new Uint8Array(0),c=await this.commitNewFile(s,t,g.FILE,i,r,n);return new lt(this,t,e,c.toStats(),n)}async openFile(t,e,i){let r=this.store.beginTransaction("readonly"),s=await this.findINode(r,t),n=await r.get(s.id);if(!s.toStats().hasAccess(e.getMode(),i))throw a.EACCES(t);if(n===void 0)throw a.ENOENT(t);return new lt(this,t,e,s.toStats(),n)}async unlink(t,e){return this.removeEntry(t,!1,e)}async rmdir(t,e){if((await this.readdir(t,e)).length>0)throw a.ENOTEMPTY(t);await this.removeEntry(t,!0,e)}async mkdir(t,e,i){let r=this.store.beginTransaction("readwrite"),s=E("{}");await this.commitNewFile(r,t,g.DIRECTORY,e,i,s)}async readdir(t,e){let i=this.store.beginTransaction("readonly"),r=await this.findINode(i,t);if(!r.toStats().hasAccess(4,e))throw a.EACCES(t);return Object.keys(await this.getDirListing(i,t,r))}async chmod(t,e,i){await(await this.openFile(t,N.getFileFlag("r+"),i)).chmod(e)}async chown(t,e,i,r){await(await this.openFile(t,N.getFileFlag("r+"),r)).chown(e,i)}async _sync(t,e,i){let r=this.store.beginTransaction("readwrite"),s=await this._findINode(r,y(t),_(t)),n=await this.getINode(r,t,s),c=n.update(i);try{await r.put(n.id,e,!0),c&&await r.put(s,n.serialize(),!0)}catch(h){throw await r.abort(),h}await r.commit()}async makeRootDirectory(){let t=this.store.beginTransaction("readwrite");if(await t.get(P)===void 0){let e=new Date().getTime(),i=new I(Q(),4096,511|g.DIRECTORY,e,e,e,0,0);await t.put(i.id,E("{}"),!1),await t.put(P,i.serialize(),!1),await t.commit()}}async _findINode(t,e,i,r=new Set){let s=F(e,i);if(r.has(s))throw new a(l.EIO,"Infinite loop detected while finding inode",s);if(r.add(s),this._cache){let n=this._cache.get(s);if(n)return n}if(e==="/"){if(i==="")return this._cache&&this._cache.set(s,P),P;{let n=await this.getINode(t,e,P),c=await this.getDirListing(t,e,n);if(c[i]){let h=c[i];return this._cache&&this._cache.set(s,h),h}else throw a.ENOENT(H(e,i))}}else{let n=await this.findINode(t,e,r),c=await this.getDirListing(t,e,n);if(c[i]){let h=c[i];return this._cache&&this._cache.set(s,h),h}else throw a.ENOENT(H(e,i))}}async findINode(t,e,i=new Set){let r=await this._findINode(t,y(e),_(e),i);return this.getINode(t,e,r)}async getINode(t,e,i){let r=await t.get(i);if(!r)throw a.ENOENT(e);return I.Deserialize(r)}async getDirListing(t,e,i){if(!i.isDirectory())throw a.ENOTDIR(e);let r=await t.get(i.id);try{return JSON.parse(C(r))}catch{throw a.ENOENT(e)}}async addNewNode(t,e){let i=0,r=u(async()=>{if(++i===5)throw new a(l.EIO,"Unable to commit data to key-value store.");{let s=Q();return await t.put(s,e,!1)?s:r()}},"reroll");return r()}async commitNewFile(t,e,i,r,s,n){let c=y(e),h=_(e),d=await this.findINode(t,c),f=await this.getDirListing(t,c,d),m=new Date().getTime();if(!d.toStats().hasAccess(2,s))throw a.EACCES(e);if(e==="/")throw a.EEXIST(e);if(f[h])throw await t.abort(),a.EEXIST(e);try{let p=await this.addNewNode(t,n),w=new I(p,n.length,r|i,m,m,m,s.uid,s.gid),S=await this.addNewNode(t,w.serialize());return f[h]=S,await t.put(d.id,E(JSON.stringify(f)),!0),await t.commit(),w}catch(p){throw t.abort(),p}}async removeEntry(t,e,i){this._cache&&this._cache.remove(t);let r=this.store.beginTransaction("readwrite"),s=y(t),n=await this.findINode(r,s),c=await this.getDirListing(r,s,n),h=_(t);if(!c[h])throw a.ENOENT(t);let d=c[h],f=await this.getINode(r,t,d);if(!f.toStats().hasAccess(2,i))throw a.EACCES(t);if(delete c[h],!e&&f.isDirectory())throw a.EISDIR(t);if(e&&!f.isDirectory())throw a.ENOTDIR(t);try{await r.del(f.id),await r.del(d),await r.put(n.id,E(JSON.stringify(c)),!0)}catch(m){throw await r.abort(),m}await r.commit()}};u(ht,"AsyncKeyValueFileSystem");function ut(o,t=o.toString()){switch(o.name){case"NotFoundError":return new a(l.ENOENT,t);case"QuotaExceededError":return new a(l.ENOSPC,t);default:return new a(l.EIO,t)}}u(ut,"convertError");function ft(o,t=l.EIO,e=null){return function(i){i.preventDefault(),o(new a(t,e!==null?e:void 0))}}u(ft,"onErrorHandler");var it=class{constructor(t,e){this.tx=t;this.store=e}get(t){return new Promise((e,i)=>{try{let r=this.store.get(t);r.onerror=ft(i),r.onsuccess=s=>{let n=s.target.result;e(n===void 0?n:Uint8Array.from(n))}}catch(r){i(ut(r))}})}};u(it,"IndexedDBROTransaction");var dt=class extends it{constructor(t,e){super(t,e)}put(t,e,i){return new Promise((r,s)=>{try{let n=i?this.store.put(e,t):this.store.add(e,t);n.onerror=ft(s),n.onsuccess=()=>{r(!0)}}catch(n){s(ut(n))}})}del(t){return new Promise((e,i)=>{try{let r=this.store.delete(t);r.onerror=ft(i),r.onsuccess=()=>{e()}}catch(r){i(ut(r))}})}commit(){return new Promise(t=>{setTimeout(t,0)})}abort(){return new Promise((t,e)=>{try{this.tx.abort(),t()}catch(i){e(ut(i))}})}};u(dt,"IndexedDBRWTransaction");var K=class{constructor(t,e){this.db=t;this.storeName=e}static Create(t,e){return new Promise((i,r)=>{let s=e.open(t,1);s.onupgradeneeded=n=>{let c=n.target.result;c.objectStoreNames.contains(t)&&c.deleteObjectStore(t),c.createObjectStore(t)},s.onsuccess=n=>{i(new K(n.target.result,t))},s.onerror=ft(r,l.EACCES)})}name(){return L.Name+" - "+this.storeName}clear(){return new Promise((t,e)=>{try{let i=this.db.transaction(this.storeName,"readwrite"),r=i.objectStore(this.storeName),s=r.clear();s.onsuccess=()=>{setTimeout(t,0)},s.onerror=ft(e)}catch(i){e(ut(i))}})}beginTransaction(t="readonly"){let e=this.db.transaction(this.storeName,t),i=e.objectStore(this.storeName);if(t==="readwrite")return new dt(e,i);if(t==="readonly")return new it(e,i);throw new a(l.EINVAL,"Invalid transaction type.")}};u(K,"IndexedDBStore");var Bt=class extends ht{static isAvailable(t=globalThis.indexedDB){try{if(!(t instanceof IDBFactory)||!t.open("__zenfs_test__"))return!1}catch{return!1}}constructor({cacheSize:t=100,storeName:e="zenfs",idbFactory:i=globalThis.indexedDB}){super(t),this._ready=K.Create(e,i).then(r=>(this.init(r),this))}},L=Bt;u(L,"IndexedDBFileSystem"),L.Name="IndexedDB",L.Create=T.bind(Bt),L.Options={storeName:{type:"string",optional:!0,description:"The name of this file system. You can have multiple IndexedDB file systems operating at once, but each must have a different name."},cacheSize:{type:"number",optional:!0,description:"The size of the inode cache. Defaults to 100. A size of 0 or below disables caching."},idbFactory:{type:"object",optional:!0,description:"The IDBFactory to use. Defaults to globalThis.indexedDB."}};var mt=class{constructor(t){this._storage=t}name(){return B.Name}clear(){this._storage.clear()}beginTransaction(t){return new j(this)}get(t){let e=this._storage.getItem(t);if(typeof e=="string")return E(e)}put(t,e,i){try{return!i&&this._storage.getItem(t)!==null?!1:(this._storage.setItem(t,C(e)),!0)}catch{throw new a(l.ENOSPC,"Storage is full.")}}del(t){try{this._storage.removeItem(t)}catch(e){throw new a(l.EIO,"Unable to delete key "+t+": "+e)}}};u(mt,"StorageStore");var zt=class extends V{static isAvailable(t=globalThis.localStorage){return t instanceof Storage}constructor({storage:t=globalThis.localStorage}){super({store:new mt(t)})}},B=zt;u(B,"StorageFileSystem"),B.Name="Storage",B.Create=T.bind(zt),B.Options={storage:{type:"object",optional:!0,description:"The Storage to use. Defaults to globalThis.localStorage."}};function ue(o){return typeof o=="object"&&"isBFS"in o&&!!o.isBFS}u(ue,"isRPCMessage");var vt=class extends O{constructor({worker:e}){super();this._currentID=0;this._requests=new Map;this._isInitialized=!1;this._worker=e,this._worker.onmessage=i=>{if(!ue(i.data))return;let{id:r,method:s,value:n}=i.data;if(s==="metadata"){this._metadata=n,this._isInitialized=!0;return}let{resolve:c,reject:h}=this._requests.get(r);if(this._requests.delete(r),n instanceof Error||n instanceof a){h(n);return}c(n)}}static isAvailable(){return typeof importScripts<"u"||typeof Worker<"u"}get metadata(){return{...super.metadata,...this._metadata,name:vt.Name,synchronous:!1}}async _rpc(e,...i){return new Promise((r,s)=>{let n=this._currentID++;this._requests.set(n,{resolve:r,reject:s}),this._worker.postMessage({isBFS:!0,id:n,method:e,args:i})})}rename(e,i,r){return this._rpc("rename",e,i,r)}stat(e,i){return this._rpc("stat",e,i)}open(e,i,r,s){return this._rpc("open",e,i,r,s)}unlink(e,i){return this._rpc("unlink",e,i)}rmdir(e,i){return this._rpc("rmdir",e,i)}mkdir(e,i,r){return this._rpc("mkdir",e,i,r)}readdir(e,i){return this._rpc("readdir",e,i)}exists(e,i){return this._rpc("exists",e,i)}realpath(e,i){return this._rpc("realpath",e,i)}truncate(e,i,r){return this._rpc("truncate",e,i,r)}readFile(e,i,r){return this._rpc("readFile",e,i,r)}writeFile(e,i,r,s,n){return this._rpc("writeFile",e,i,r,s,n)}appendFile(e,i,r,s,n){return this._rpc("appendFile",e,i,r,s,n)}chmod(e,i,r){return this._rpc("chmod",e,i,r)}chown(e,i,r,s){return this._rpc("chown",e,i,r,s)}utimes(e,i,r,s){return this._rpc("utimes",e,i,r,s)}link(e,i,r){return this._rpc("link",e,i,r)}symlink(e,i,r,s){return this._rpc("symlink",e,i,r,s)}readlink(e,i){return this._rpc("readlink",e,i)}syncClose(e,i){return this._rpc("syncClose",e,i)}},J=vt;u(J,"WorkerFS"),J.Name="WorkerFS",J.Create=T.bind(vt),J.Options={worker:{type:"object",description:"The target worker that you want to connect to, or the current worker if in a worker context.",validator(e){if(typeof e?.postMessage!="function")throw new a(l.EINVAL,"option must be a Web Worker instance.")}}};return ne(de);})();
1
+ var ZenFS_DOM=(()=>{var st=Object.defineProperty;var _t=Object.getOwnPropertyDescriptor;var Dt=Object.getOwnPropertyNames;var Tt=Object.prototype.hasOwnProperty;var l=(s,t)=>st(s,"name",{value:t,configurable:!0});var At=(s,t)=>{for(var e in t)st(s,e,{get:t[e],enumerable:!0})},Rt=(s,t,e,r)=>{if(t&&typeof t=="object"||typeof t=="function")for(let i of Dt(t))!Tt.call(s,i)&&i!==e&&st(s,i,{get:()=>t[i],enumerable:!(r=_t(t,i))||r.enumerable});return s};var Ft=s=>Rt(st({},"__esModule",{value:!0}),s);var Ct={};At(Ct,{FileSystemAccess:()=>Pt,FileSystemAccessFS:()=>j,FileSystemAccessFile:()=>V,IndexedDB:()=>xt,IndexedDBROTransaction:()=>K,IndexedDBRWTransaction:()=>tt,IndexedDBStore:()=>Y,Storage:()=>It,StorageStore:()=>rt});var vt="/",wt="/";function $(s,t){if(typeof s!="string")throw new TypeError(`"${t}" is not a string`)}l($,"validateString");function yt(s,t){let e="",r=0,i=-1,n=0,o="\0";for(let c=0;c<=s.length;++c){if(c<s.length)o=s[c];else{if(o=="/")break;o="/"}if(o=="/"){if(!(i===c-1||n===1))if(n===2){if(e.length<2||r!==2||e.at(-1)!=="."||e.at(-2)!=="."){if(e.length>2){let d=e.lastIndexOf("/");d===-1?(e="",r=0):(e=e.slice(0,d),r=e.length-1-e.lastIndexOf("/")),i=c,n=0;continue}else if(e.length!==0){e="",r=0,i=c,n=0;continue}}t&&(e+=e.length>0?"/..":"..",r=2)}else e.length>0?e+="/"+s.slice(i+1,c):e=s.slice(i+1,c),r=c-i-1;i=c,n=0}else o==="."&&n!==-1?++n:n=-1}return e}l(yt,"normalizeString");function X(...s){let t="",e=!1;for(let r=s.length-1;r>=-1&&!e;r--){let i=r>=0?s[r]:vt;$(i,`paths[${r}]`),i.length!==0&&(t=`${i}/${t}`,e=i[0]==="/")}return t=yt(t,!e),e?`/${t}`:t.length>0?t:"."}l(X,"resolve");function kt(s){if($(s,"path"),s.length===0)return".";let t=s[0]==="/",e=s.at(-1)==="/";return s=yt(s,!t),s.length===0?t?"/":e?"./":".":(e&&(s+="/"),t?`/${s}`:s)}l(kt,"normalize");function v(...s){if(s.length===0)return".";let t;for(let e=0;e<s.length;++e){let r=s[e];$(r,"path"),r.length>0&&(t===void 0?t=r:t+=`/${r}`)}return t===void 0?".":kt(t)}l(v,"join");function w(s){if($(s,"path"),s.length===0)return".";let t=s[0]==="/",e=-1,r=!0;for(let i=s.length-1;i>=1;--i)if(s[i]==="/"){if(!r){e=i;break}}else r=!1;return e===-1?t?"/":".":t&&e===1?"//":s.slice(0,e)}l(w,"dirname");function g(s,t){t!==void 0&&$(t,"ext"),$(s,"path");let e=0,r=-1,i=!0;if(t!==void 0&&t.length>0&&t.length<=s.length){if(t===s)return"";let n=t.length-1,o=-1;for(let c=s.length-1;c>=0;--c)if(s[c]==="/"){if(!i){e=c+1;break}}else o===-1&&(i=!1,o=c+1),n>=0&&(s[c]===t[n]?--n===-1&&(r=c):(n=-1,r=o));return e===r?r=o:r===-1&&(r=s.length),s.slice(e,r)}for(let n=s.length-1;n>=0;--n)if(s[n]==="/"){if(!i){e=n+1;break}}else r===-1&&(i=!1,r=n+1);return r===-1?"":s.slice(e,r)}l(g,"basename");var h;(function(s){s[s.EPERM=1]="EPERM",s[s.ENOENT=2]="ENOENT",s[s.EIO=5]="EIO",s[s.EBADF=9]="EBADF",s[s.EACCES=13]="EACCES",s[s.EBUSY=16]="EBUSY",s[s.EEXIST=17]="EEXIST",s[s.ENOTDIR=20]="ENOTDIR",s[s.EISDIR=21]="EISDIR",s[s.EINVAL=22]="EINVAL",s[s.EFBIG=27]="EFBIG",s[s.ENOSPC=28]="ENOSPC",s[s.EROFS=30]="EROFS",s[s.ENOTEMPTY=39]="ENOTEMPTY",s[s.ENOTSUP=95]="ENOTSUP"})(h=h||(h={}));var gt={[h.EPERM]:"Operation not permitted.",[h.ENOENT]:"No such file or directory.",[h.EIO]:"Input/output error.",[h.EBADF]:"Bad file descriptor.",[h.EACCES]:"Permission denied.",[h.EBUSY]:"Resource busy or locked.",[h.EEXIST]:"File exists.",[h.ENOTDIR]:"File is not a directory.",[h.EISDIR]:"File is a directory.",[h.EINVAL]:"Invalid argument.",[h.EFBIG]:"File is too big.",[h.ENOSPC]:"No space left on disk.",[h.EROFS]:"Cannot modify a read-only file system.",[h.ENOTEMPTY]:"Directory is not empty.",[h.ENOTSUP]:"Operation is not supported."},a=class extends Error{static fromJSON(t){let e=new a(t.errno,t.message,t.path);return e.code=t.code,e.stack=t.stack,e}static OnPath(t,e){return new a(t,gt[t],e)}static EACCES(t){return this.OnPath(h.EACCES,t)}static ENOENT(t){return this.OnPath(h.ENOENT,t)}static EEXIST(t){return this.OnPath(h.EEXIST,t)}static EISDIR(t){return this.OnPath(h.EISDIR,t)}static ENOTDIR(t){return this.OnPath(h.ENOTDIR,t)}static EPERM(t){return this.OnPath(h.EPERM,t)}static ENOTEMPTY(t){return this.OnPath(h.ENOTEMPTY,t)}constructor(t,e=gt[t],r){super(e),this.errno=t,this.path=r,this.syscall="",this.code=h[t],this.message=`${this.code}: ${e}${this.path?`, '${this.path}'`:""}`}toString(){return this.message}toJSON(){return{errno:this.errno,code:this.code,path:this.path,stack:this.stack,message:this.message}}bufferSize(){return 4+JSON.stringify(this.toJSON()).length}};l(a,"ApiError");var z=class{constructor(t,e,r,i,n,o){this.uid=t,this.gid=e,this.suid=r,this.sgid=i,this.euid=n,this.egid=o}};l(z,"Cred");z.Root=new z(0,0,0,0,0,0);var E;(function(s){s[s.FILE=32768]="FILE",s[s.DIRECTORY=16384]="DIRECTORY",s[s.SYMLINK=40960]="SYMLINK"})(E=E||(E={}));var nt=class{get _typename(){return this._isBigint?"bigint":"number"}get _typename_inverse(){return this._isBigint?"number":"bigint"}_convert(t){return this._isBigint?BigInt(t):Number(t)}get atime(){return new Date(Number(this.atimeMs))}set atime(t){this.atimeMs=this._convert(t.getTime())}get mtime(){return new Date(Number(this.mtimeMs))}set mtime(t){this.mtimeMs=this._convert(t.getTime())}get ctime(){return new Date(Number(this.ctimeMs))}set ctime(t){this.ctimeMs=this._convert(t.getTime())}get birthtime(){return new Date(Number(this.birthtimeMs))}set birthtime(t){this.birthtimeMs=this._convert(t.getTime())}constructor({atimeMs:t,mtimeMs:e,ctimeMs:r,birthtimeMs:i,uid:n,gid:o,size:c,mode:d}={}){this.dev=this._convert(0),this.ino=this._convert(0),this.rdev=this._convert(0),this.nlink=this._convert(1),this.blksize=this._convert(4096),this.uid=this._convert(0),this.gid=this._convert(0),this.fileData=null;let m=Date.now(),u=l((S,N)=>typeof S==this._typename?S:this._convert(typeof S==this._typename_inverse?S:N),"resolveT");this.atimeMs=u(t,m),this.mtimeMs=u(e,m),this.ctimeMs=u(r,m),this.birthtimeMs=u(i,m),this.uid=u(n,0),this.gid=u(o,0),this.size=this._convert(c);let f=Number(d)&61440||E.FILE;if(d)this.mode=this._convert(d);else switch(f){case E.FILE:this.mode=this._convert(420);break;case E.DIRECTORY:default:this.mode=this._convert(511)}this.blocks=this._convert(Math.ceil(Number(c)/512)),this.mode&61440||(this.mode=this.mode|this._convert(f))}isFile(){return(this.mode&61440)===32768}isDirectory(){return(this.mode&61440)===16384}isSymbolicLink(){return(this.mode&61440)===40960}isSocket(){return!1}isBlockDevice(){return!1}isCharacterDevice(){return!1}isFIFO(){return!1}hasAccess(t,e){if(e.euid===0||e.egid===0)return!0;let r=this.mode&-61441,i=15,n=15,o=15;if(e.euid==this.uid){let m=(3840&r)>>8;i=(t^m)&t}if(e.egid==this.gid){let m=(240&r)>>4;n=(t^m)&t}let c=15&r;return o=(t^c)&t,!(i&n&o)}getCred(t=Number(this.uid),e=Number(this.gid)){return new z(t,e,Number(this.uid),Number(this.gid),t,e)}chmod(t){this.mode=this._convert(this.mode&61440|t)}chown(t,e){t=Number(t),e=Number(e),!isNaN(t)&&0<=t&&t<2**32&&(this.uid=this._convert(t)),!isNaN(e)&&0<=e&&e<2**32&&(this.gid=this._convert(e))}};l(nt,"StatsCommon");var b=class extends nt{constructor(){super(...arguments),this._isBigint=!1}static clone(t){return new b(t)}};l(b,"Stats");var mt=2**32-1,T=0n;function Nt(){return Math.round(Math.random()*2**32).toString(16)}l(Nt,"_random");function q(){return BigInt("0x"+Nt()+Nt())}l(q,"randomIno");var y;(function(s){s[s.ino=0]="ino",s[s.size=8]="size",s[s.mode=12]="mode",s[s.nlink=14]="nlink",s[s.uid=18]="uid",s[s.gid=22]="gid",s[s.atime=26]="atime",s[s.birthtime=34]="birthtime",s[s.mtime=42]="mtime",s[s.ctime=50]="ctime",s[s.end=58]="end"})(y||(y={}));var D=class{get data(){return new Uint8Array(this.buffer)}constructor(t){let e=!t;if(t??(t=new ArrayBuffer(y.end)),t?.byteLength<y.end)throw new RangeError(`Can not create an inode from a buffer less than ${y.end} bytes`);if(this.view=new DataView(t),this.buffer=t,!e)return;this.ino=q(),this.nlink=1,this.size=4096;let r=Date.now();this.atimeMs=r,this.mtimeMs=r,this.ctimeMs=r,this.birthtimeMs=r}get ino(){return this.view.getBigUint64(y.ino,!0)}set ino(t){this.view.setBigUint64(y.ino,t,!0)}get size(){return this.view.getUint32(y.size,!0)}set size(t){this.view.setUint32(y.size,t,!0)}get mode(){return this.view.getUint16(y.mode,!0)}set mode(t){this.view.setUint16(y.mode,t,!0)}get nlink(){return this.view.getUint32(y.nlink,!0)}set nlink(t){this.view.setUint32(y.nlink,t,!0)}get uid(){return this.view.getUint32(y.uid,!0)}set uid(t){this.view.setUint32(y.uid,t,!0)}get gid(){return this.view.getUint32(y.gid,!0)}set gid(t){this.view.setUint32(y.gid,t,!0)}get atimeMs(){return this.view.getFloat64(y.atime,!0)}set atimeMs(t){this.view.setFloat64(y.atime,t,!0)}get birthtimeMs(){return this.view.getFloat64(y.birthtime,!0)}set birthtimeMs(t){this.view.setFloat64(y.birthtime,t,!0)}get mtimeMs(){return this.view.getFloat64(y.mtime,!0)}set mtimeMs(t){this.view.setFloat64(y.mtime,t,!0)}get ctimeMs(){return this.view.getFloat64(y.ctime,!0)}set ctimeMs(t){this.view.setFloat64(y.ctime,t,!0)}toStats(){return new b(this)}update(t){let e=!1;return this.size!==t.size&&(this.size=t.size,e=!0),this.mode!==t.mode&&(this.mode=t.mode,e=!0),this.nlink!==t.nlink&&(this.nlink=t.nlink,e=!0),this.uid!==t.uid&&(this.uid=t.uid,e=!0),this.uid!==t.uid&&(this.uid=t.uid,e=!0),this.atimeMs!==t.atimeMs&&(this.atimeMs=t.atimeMs,e=!0),this.mtimeMs!==t.mtimeMs&&(this.mtimeMs=t.mtimeMs,e=!0),this.ctimeMs!==t.ctimeMs&&(this.ctimeMs=t.ctimeMs,e=!0),e}};l(D,"Inode");var B;(function(s){s[s.NOP=0]="NOP",s[s.THROW=1]="THROW",s[s.TRUNCATE=2]="TRUNCATE",s[s.CREATE=3]="CREATE"})(B=B||(B={}));var O=class{static Get(t){return O.cache.has(t)||O.cache.set(t,new O(t)),O.cache.get(t)}constructor(t){if(typeof t=="number"&&(t=O.StringOf(t)),!O.validStrings.includes(t))throw new a(h.EINVAL,"Invalid flag string: "+t);this._flag=t}static StringOf(t){switch(t){case 0:return"r";case 1052672:return"rs";case 2:return"r+";case 1052674:return"rs+";case 577:return"w";case 705:return"wx";case 578:return"w+";case 706:return"wx+";case 1089:return"a";case 1217:return"ax";case 1090:return"a+";case 1218:return"ax+";default:throw new a(h.EINVAL,"Invalid flag number: "+t)}}static NumberOf(t){switch(t){case"r":return 0;case"rs":return 1052672;case"r+":return 2;case"rs+":return 1052674;case"w":return 577;case"wx":return 705;case"w+":return 578;case"wx+":return 706;case"a":return 1089;case"ax":return 1217;case"a+":return 1090;case"ax+":return 1218;default:throw new a(h.EINVAL,"Invalid flag string: "+t)}}toString(){return this._flag}get mode(){let t=0;return t<<=1,t+=+this.isReadable(),t<<=1,t+=+this.isWriteable(),t<<=1,t}isReadable(){return this._flag.indexOf("r")!=-1||this._flag.indexOf("+")!=-1}isWriteable(){return this._flag.indexOf("w")!=-1||this._flag.indexOf("a")!=-1||this._flag.indexOf("+")!=-1}isTruncating(){return this._flag.indexOf("w")!==-1}isAppendable(){return this._flag.indexOf("a")!==-1}isSynchronous(){return this._flag.indexOf("s")!==-1}isExclusive(){return this._flag.indexOf("x")!==-1}pathExistsAction(){return this.isExclusive()?B.THROW:this.isTruncating()?B.TRUNCATE:B.NOP}pathNotExistsAction(){return(this.isWriteable()||this.isAppendable())&&this._flag!="r+"?B.CREATE:B.THROW}};l(O,"FileFlag");O.cache=new Map;O.validStrings=["r","r+","rs","rs+","w","wx","w+","wx+","a","ax","a+","ax+"];var ct=class{datasync(){return this.sync()}datasyncSync(){return this.syncSync()}};l(ct,"File");var k=class extends ct{constructor(t,e,r,i,n=new Uint8Array(new ArrayBuffer(0,{maxByteLength:mt}))){if(super(),this.fs=t,this.path=e,this.flag=r,this.stats=i,this._buffer=n,this._position=0,this._dirty=!1,this.stats.size!=n.byteLength){if(this.flag.isReadable())throw new Error(`Size mismatch: buffer length ${n.byteLength}, stats size ${this.stats.size}`);this._dirty=!0}}get buffer(){return this._buffer}get position(){return this.flag.isAppendable()?this.stats.size:this._position}set position(t){this._position=t}async stat(){return new b(this.stats)}statSync(){return new b(this.stats)}truncate(t){if(this.truncateSync(t),this.flag.isSynchronous()&&!this.fs.metadata().synchronous)return this.sync()}truncateSync(t){if(this._dirty=!0,!this.flag.isWriteable())throw new a(h.EPERM,"File not opened with a writeable mode.");if(this.stats.mtimeMs=Date.now(),t>this._buffer.length){let e=new Uint8Array(t-this._buffer.length);this.writeSync(e,0,e.length,this._buffer.length),this.flag.isSynchronous()&&this.fs.metadata().synchronous&&this.syncSync();return}this.stats.size=t,this._buffer=this._buffer.subarray(0,t),this.flag.isSynchronous()&&this.fs.metadata().synchronous&&this.syncSync()}async write(t,e=0,r=this.stats.size,i=0){return this.writeSync(t,e,r,i)}writeSync(t,e=0,r=this.stats.size,i=0){if(this._dirty=!0,i??(i=this.position),!this.flag.isWriteable())throw new a(h.EPERM,"File not opened with a writeable mode.");let n=i+r;if(n>this.stats.size&&(this.stats.size=n,n>this._buffer.byteLength))if(this._buffer.buffer.resizable&&this._buffer.buffer.maxByteLength<=n)this._buffer.buffer.resize(n);else{let c=new Uint8Array(new ArrayBuffer(n,{maxByteLength:mt}));c.set(this._buffer),this._buffer=c}this._buffer.set(t.slice(e,e+r),i);let o=this._buffer.byteOffset;return this.stats.mtimeMs=Date.now(),this.flag.isSynchronous()?(this.syncSync(),o):(this.position=i+o,o)}async read(t,e=0,r=this.stats.size,i=0){return{bytesRead:this.readSync(t,e,r,i),buffer:t}}readSync(t,e=0,r=this.stats.size,i=0){if(!this.flag.isReadable())throw new a(h.EPERM,"File not opened with a readable mode.");i??(i=this.position);let n=i+r;n>this.stats.size&&(n=i+Math.max(this.stats.size-i,0)),this.stats.atimeMs=Date.now(),this._position=n;let o=n-i;return o==0||t.set(this._buffer.slice(i,n),e),o}async chmod(t){this.chmodSync(t)}chmodSync(t){if(!this.fs.metadata().supportsProperties)throw new a(h.ENOTSUP);this._dirty=!0,this.stats.chmod(t),this.syncSync()}async chown(t,e){this.chownSync(t,e)}chownSync(t,e){if(!this.fs.metadata().supportsProperties)throw new a(h.ENOTSUP);this._dirty=!0,this.stats.chown(t,e),this.syncSync()}async utimes(t,e){this.utimesSync(t,e)}utimesSync(t,e){if(!this.fs.metadata().supportsProperties)throw new a(h.ENOTSUP);this._dirty=!0,this.stats.atime=t,this.stats.mtime=e,this.syncSync()}isDirty(){return this._dirty}resetDirty(){this._dirty=!1}_setType(t){return this._dirty=!0,this.stats.mode=this.stats.mode&-61441|t,this.sync()}_setTypeSync(t){this._dirty=!0,this.stats.mode=this.stats.mode&-61441|t,this.syncSync()}};l(k,"PreloadFile");var P=class{metadata(){return{name:this.constructor.name,readonly:!1,synchronous:!1,supportsProperties:!1,totalSpace:0,freeSpace:0}}constructor(t){}async exists(t,e){try{return await this.stat(t,e),!0}catch{return!1}}existsSync(t,e){try{return this.statSync(t,e),!0}catch{return!1}}};l(P,"FileSystem");function bt(s){class t extends s{metadata(){return{...super.metadata(),synchronous:!0}}async ready(){return this}async exists(r,i){return this.existsSync(r,i)}async rename(r,i,n){return this.renameSync(r,i,n)}async stat(r,i){return this.statSync(r,i)}async createFile(r,i,n,o){return this.createFileSync(r,i,n,o)}async openFile(r,i,n){return this.openFileSync(r,i,n)}async unlink(r,i){return this.unlinkSync(r,i)}async rmdir(r,i){return this.rmdirSync(r,i)}async mkdir(r,i,n){return this.mkdirSync(r,i,n)}async readdir(r,i){return this.readdirSync(r,i)}async link(r,i,n){return this.linkSync(r,i,n)}async sync(r,i,n){return this.syncSync(r,i,n)}}return l(t,"_SyncFileSystem"),t}l(bt,"Sync");function ht(s){class t extends s{metadata(){return{...super.metadata(),synchronous:!1}}renameSync(r,i,n){throw new a(h.ENOTSUP)}statSync(r,i){throw new a(h.ENOTSUP)}createFileSync(r,i,n,o){throw new a(h.ENOTSUP)}openFileSync(r,i,n){throw new a(h.ENOTSUP)}unlinkSync(r,i){throw new a(h.ENOTSUP)}rmdirSync(r,i){throw new a(h.ENOTSUP)}mkdirSync(r,i,n){throw new a(h.ENOTSUP)}readdirSync(r,i){throw new a(h.ENOTSUP)}linkSync(r,i,n){throw new a(h.ENOTSUP)}syncSync(r,i,n){throw new a(h.ENOTSUP)}}return l(t,"_AsyncFileSystem"),t}l(ht,"Async");var lt=l((s="",t)=>{throw t.name==="NotFoundError"?a.ENOENT(s):t},"handleError"),V=class extends k{constructor(t,e,r,i,n){super(t,e,r,i,n)}syncSync(){throw new a(h.ENOTSUP)}async sync(){this.isDirty()&&(await this.fs.sync(this.path,this.buffer,this.stats),this.resetDirty())}async close(){await this.sync()}closeSync(){throw new a(h.ENOTSUP)}};l(V,"FileSystemAccessFile");var j=class extends ht(P){constructor({handle:e}){super();this._handles=new Map;this._handles.set("/",e)}async ready(){return this}metadata(){return{...super.metadata(),name:"FileSystemAccess"}}async sync(e,r,i){let n=await this.stat(e);i.mtime!==n.mtime&&await this.writeFile(e,r)}async rename(e,r){try{let i=await this.getHandle(e);if(i instanceof FileSystemDirectoryHandle){let u=await this.readdir(e);if(await this.mkdir(r),u.length==0)await this.unlink(e);else for(let f of u)await this.rename(v(e,f),v(r,f)),await this.unlink(e)}if(!(i instanceof FileSystemFileHandle))return;let n=await i.getFile(),o=await this.getHandle(w(r));if(!(o instanceof FileSystemDirectoryHandle))return;let d=await(await o.getFileHandle(g(r),{create:!0})).createWritable(),m=await n.arrayBuffer();await d.write(m),d.close(),await this.unlink(e)}catch(i){lt(e,i)}}async writeFile(e,r){let i=await this.getHandle(w(e));if(!(i instanceof FileSystemDirectoryHandle))return;let o=await(await i.getFileHandle(g(e),{create:!0})).createWritable();await o.write(r),await o.close()}async createFile(e,r){return await this.writeFile(e,new Uint8Array),this.openFile(e,r)}async stat(e){let r=await this.getHandle(e);if(!r)throw a.OnPath(h.ENOENT,e);if(r instanceof FileSystemDirectoryHandle)return new b({mode:511|E.DIRECTORY,size:4096});if(r instanceof FileSystemFileHandle){let{lastModified:i,size:n}=await r.getFile();return new b({mode:511|E.FILE,size:n,mtimeMs:i})}}async openFile(e,r){let i=await this.getHandle(e);if(i instanceof FileSystemFileHandle){let n=await i.getFile(),o=new Uint8Array(await n.arrayBuffer()),c=new b({mode:511|E.FILE,size:n.size,mtimeMs:n.lastModified});return new V(this,e,r,c,o)}}async unlink(e){let r=await this.getHandle(w(e));if(r instanceof FileSystemDirectoryHandle)try{await r.removeEntry(g(e),{recursive:!0})}catch(i){lt(e,i)}}async link(){throw new a(h.ENOTSUP)}async rmdir(e){return this.unlink(e)}async mkdir(e){if(await this.getHandle(e))throw a.EEXIST(e);let i=await this.getHandle(w(e));i instanceof FileSystemDirectoryHandle&&await i.getDirectoryHandle(g(e),{create:!0})}async readdir(e){let r=await this.getHandle(e);if(!(r instanceof FileSystemDirectoryHandle))throw a.ENOTDIR(e);let i=[];for await(let n of r.keys())i.push(v(e,n));return i}async getHandle(e){if(this._handles.has(e))return this._handles.get(e);let r="/",[,...i]=e.split("/"),n=l(async([o,...c])=>{let d=v(r,o),m=l(f=>{if(r=d,this._handles.set(r,f),c.length===0)return this._handles.get(e);n(c)},"continueWalk"),u=this._handles.get(r);try{return m(await u.getDirectoryHandle(o))}catch(f){if(f.name==="TypeMismatchError")try{return m(await u.getFileHandle(o))}catch(S){lt(d,S)}else{if(f.message==="Name is not allowed.")throw new a(h.ENOENT,f.message,d);lt(d,f)}}},"getHandleParts");return await n(i)}};l(j,"FileSystemAccessFS");var Pt={name:"FileSystemAccess",options:{handle:{type:"object",required:!0,description:"The directory handle to use for the root"}},isAvailable(){return typeof FileSystemHandle=="function"},create(s){return new j(s)}};var ye=typeof globalThis.setImmediate=="function"?globalThis.setImmediate:s=>setTimeout(s,0);function A(s,t="utf8"){if(typeof s!="string")throw new a(h.EINVAL,"Can not encode a non-string");switch(t){case"ascii":case"latin1":case"binary":return new Uint8Array(Array.from(s).map(r=>r.charCodeAt(0)));case"utf8":case"utf-8":return new Uint8Array(Array.from(s).flatMap(r=>{let i=r.charCodeAt(0);if(i<128)return i;let n=i&63|128;if(i<2048)return[i>>6|192,n];let o=i>>6&63|128;return i<65536?[i>>12|224,o,n]:[i>>18|240,i>>12&63|128,o,n]}));case"base64":return A(atob(s),"utf-8");case"base64url":return A(s.replace("_","/").replace("-","+"),"base64");case"hex":return new Uint8Array(s.match(/.{1,2}/g).map(r=>parseInt(r,16)));case"utf16le":case"ucs2":case"ucs-2":let e=new Uint16Array(new ArrayBuffer(s.length*2));for(let r=0;r<s.length;r++)e[r]=s.charCodeAt(r);return new Uint8Array(e.buffer);default:throw new a(h.EINVAL,"Invalid encoding: "+t)}}l(A,"encode");function G(s,t="utf8"){if(!(s instanceof Uint8Array))throw new a(h.EINVAL,"Can not decode a non-Uint8Array");switch(t){case"ascii":case"latin1":case"binary":return Array.from(s).map(i=>String.fromCharCode(i)).join("");case"utf8":case"utf-8":let e="";for(let i=0;i<s.length;i++){let n;s[i]<128?n=s[i]:s[i]<224?n=(s[i]&31)<<6|s[++i]&63:s[i]<240?n=(s[i]&15)<<12|(s[++i]&63)<<6|s[++i]&63:n=(s[i]&7)<<18|(s[++i]&63)<<12|(s[++i]&63)<<6|s[++i]&63,e+=String.fromCharCode(n)}return e;case"utf16le":case"ucs2":case"ucs-2":let r="";for(let i=0;i<s.length;i+=2){let n=s[i]|s[i+1]<<8;r+=String.fromCharCode(n)}return r;case"base64":return btoa(G(s,"utf-8"));case"base64url":return G(s,"base64").replace("/","_").replace("+","-");case"hex":return Array.from(s).map(i=>i.toString(16).padStart(2,"0")).join("");default:throw new a(h.EINVAL,"Invalid encoding: "+t)}}l(G,"decode");function dt(s){return JSON.parse(G(s),(t,e)=>t==""?e:BigInt(e))}l(dt,"decodeDirListing");function _(s){return A(JSON.stringify(s,(t,e)=>t==""?e:e.toString()))}l(_,"encodeDirListing");var ut=class{constructor(t){this.limit=t,this.cache=[]}set(t,e){let r=this.cache.findIndex(i=>i.key===t);r!=-1?this.cache.splice(r,1):this.cache.length>=this.limit&&this.cache.shift(),this.cache.push({key:t,value:e})}get(t){let e=this.cache.find(r=>r.key===t);if(e)return this.set(t,e.value),e.value}remove(t){let e=this.cache.findIndex(r=>r.key===t);e!==-1&&this.cache.splice(e,1)}reset(){this.cache=[]}};l(ut,"LRUCache");var J=class extends k{constructor(t,e,r,i,n){super(t,e,r,i,n)}async sync(){this.isDirty()&&(await this.fs.sync(this.path,this._buffer,this.stats),this.resetDirty())}syncSync(){throw new a(h.ENOTSUP)}async close(){this.sync()}closeSync(){throw new a(h.ENOTSUP)}};l(J,"AsyncFile");var Q=class extends ht(P){ready(){return this._ready}metadata(){return{...super.metadata(),name:this.store.name}}constructor({store:t,cacheSize:e}){super(),e>0&&(this._cache=new ut(e)),this._ready=this._initialize(t)}async _initialize(t){return this.store=await t,await this.makeRootDirectory(),this}async empty(){this._cache&&this._cache.reset(),await this.store.clear(),await this.makeRootDirectory()}async rename(t,e,r){let i=this._cache;this._cache&&(this._cache=null,i.reset());try{let n=this.store.beginTransaction("readwrite"),o=w(t),c=g(t),d=w(e),m=g(e),u=await this.findINode(n,o),f=await this.getDirListing(n,u,o);if(!u.toStats().hasAccess(2,r))throw a.EACCES(t);if(!f[c])throw a.ENOENT(t);let S=f[c];if(delete f[c],(d+"/").indexOf(t+"/")===0)throw new a(h.EBUSY,o);let N,x;if(d===o?(N=u,x=f):(N=await this.findINode(n,d),x=await this.getDirListing(n,N,d)),x[m]){let W=await this.getINode(n,x[m],e);if(W.toStats().isFile())try{await n.remove(W.ino),await n.remove(x[m])}catch(Ot){throw await n.abort(),Ot}else throw a.EPERM(e)}x[m]=S;try{await n.put(u.ino,_(f),!0),await n.put(N.ino,_(x),!0)}catch(W){throw await n.abort(),W}await n.commit()}finally{i&&(this._cache=i)}}async stat(t,e){let r=this.store.beginTransaction("readonly"),i=await this.findINode(r,t);if(!i)throw a.ENOENT(t);let n=i.toStats();if(!n.hasAccess(4,e))throw a.EACCES(t);return n}async createFile(t,e,r,i){let n=this.store.beginTransaction("readwrite"),o=new Uint8Array(0),c=await this.commitNewFile(n,t,E.FILE,r,i,o);return new J(this,t,e,c.toStats(),o)}async openFile(t,e,r){let i=this.store.beginTransaction("readonly"),n=await this.findINode(i,t),o=await i.get(n.ino);if(!n.toStats().hasAccess(e.mode,r))throw a.EACCES(t);if(!o)throw a.ENOENT(t);return new J(this,t,e,n.toStats(),o)}async unlink(t,e){return this.removeEntry(t,!1,e)}async rmdir(t,e){if((await this.readdir(t,e)).length>0)throw a.ENOTEMPTY(t);await this.removeEntry(t,!0,e)}async mkdir(t,e,r){let i=this.store.beginTransaction("readwrite"),n=A("{}");await this.commitNewFile(i,t,E.DIRECTORY,e,r,n)}async readdir(t,e){let r=this.store.beginTransaction("readonly"),i=await this.findINode(r,t);if(!i.toStats().hasAccess(4,e))throw a.EACCES(t);return Object.keys(await this.getDirListing(r,i,t))}async sync(t,e,r){let i=this.store.beginTransaction("readwrite"),n=await this._findINode(i,w(t),g(t)),o=await this.getINode(i,n,t),c=o.update(r);try{await i.put(o.ino,e,!0),c&&await i.put(n,o.data,!0)}catch(d){throw await i.abort(),d}await i.commit()}async link(t,e,r){let i=this.store.beginTransaction("readwrite"),n=w(t);if(!(await this.findINode(i,n)).toStats().hasAccess(4,r))throw a.EACCES(n);let c=w(e),d=await this.findINode(i,c),m=await this.getDirListing(i,d,c);if(!d.toStats().hasAccess(2,r))throw a.EACCES(c);let u=await this._findINode(i,n,g(t)),f=await this.getINode(i,u,t);if(!f.toStats().hasAccess(2,r))throw a.EACCES(e);f.nlink++,m[g(e)]=u;try{i.put(u,f.data,!0),i.put(d.ino,_(m),!0)}catch(S){throw i.abort(),S}i.commit()}async makeRootDirectory(){let t=this.store.beginTransaction("readwrite");if(await t.get(T)===void 0){let e=new D;e.mode=511|E.DIRECTORY,await t.put(e.ino,A("{}"),!1),await t.put(T,e.data,!1),await t.commit()}}async _findINode(t,e,r,i=new Set){let n=v(e,r);if(i.has(n))throw new a(h.EIO,"Infinite loop detected while finding inode",n);if(i.add(n),this._cache){let o=this._cache.get(n);if(o)return o}if(e==="/"){if(r==="")return this._cache&&this._cache.set(n,T),T;{let o=await this.getINode(t,T,e),c=await this.getDirListing(t,o,e);if(c[r]){let d=c[r];return this._cache&&this._cache.set(n,d),d}else throw a.ENOENT(X(e,r))}}else{let o=await this.findINode(t,e,i),c=await this.getDirListing(t,o,e);if(c[r]){let d=c[r];return this._cache&&this._cache.set(n,d),d}else throw a.ENOENT(X(e,r))}}async findINode(t,e,r=new Set){let i=await this._findINode(t,w(e),g(e),r);return this.getINode(t,i,e)}async getINode(t,e,r){let i=await t.get(e);if(!i)throw a.ENOENT(r);return new D(i.buffer)}async getDirListing(t,e,r){if(!e.toStats().isDirectory())throw a.ENOTDIR(r);let i=await t.get(e.ino);if(!i)throw a.ENOENT(r);return dt(i)}async addNewNode(t,e){let r=0,i=l(async()=>{if(++r===5)throw new a(h.EIO,"Unable to commit data to key-value store.");{let n=q();return await t.put(n,e,!1)?n:i()}},"reroll");return i()}async commitNewFile(t,e,r,i,n,o){let c=w(e),d=g(e),m=await this.findINode(t,c),u=await this.getDirListing(t,m,c);if(!m.toStats().hasAccess(2,n))throw a.EACCES(e);if(e==="/")throw a.EEXIST(e);if(u[d])throw await t.abort(),a.EEXIST(e);try{let f=new D;return f.ino=await this.addNewNode(t,o),f.mode=i|r,f.uid=n.uid,f.gid=n.gid,f.size=o.length,u[d]=await this.addNewNode(t,f.data),await t.put(m.ino,_(u),!0),await t.commit(),f}catch(f){throw t.abort(),f}}async removeEntry(t,e,r){this._cache&&this._cache.remove(t);let i=this.store.beginTransaction("readwrite"),n=w(t),o=await this.findINode(i,n),c=await this.getDirListing(i,o,n),d=g(t);if(!c[d])throw a.ENOENT(t);let m=c[d],u=await this.getINode(i,m,t);if(!u.toStats().hasAccess(2,r))throw a.EACCES(t);if(delete c[d],!e&&u.toStats().isDirectory())throw a.EISDIR(t);if(e&&!u.toStats().isDirectory())throw a.ENOTDIR(t);try{await i.put(o.ino,_(c),!0),--u.nlink<1&&(await i.remove(u.ino),await i.remove(m))}catch(f){throw await i.abort(),f}await i.commit()}};l(Q,"AsyncStoreFS");function Z(s,t=s.toString()){switch(s.name){case"NotFoundError":return new a(h.ENOENT,t);case"QuotaExceededError":return new a(h.ENOSPC,t);default:return new a(h.EIO,t)}}l(Z,"convertError");var K=class{constructor(t,e){this.tx=t;this.store=e}get(t){return new Promise((e,r)=>{try{let i=this.store.get(t.toString());i.onerror=n=>{n.preventDefault(),r(new a(h.EIO))},i.onsuccess=()=>{let n=i.result;e(n===void 0?n:Uint8Array.from(n))}}catch(i){r(Z(i))}})}};l(K,"IndexedDBROTransaction");var tt=class extends K{constructor(t,e){super(t,e)}put(t,e,r){return new Promise((i,n)=>{try{let o=r?this.store.put(e,t.toString()):this.store.add(e,t.toString());o.onerror=c=>{c.preventDefault(),n(new a(h.EIO))},o.onsuccess=()=>i(!0)}catch(o){n(Z(o))}})}remove(t){return new Promise((e,r)=>{try{let i=this.store.delete(t.toString());i.onerror=n=>{n.preventDefault(),r(new a(h.EIO))},i.onsuccess=()=>e}catch(i){r(Z(i))}})}commit(){return new Promise(t=>setTimeout(t,0))}async abort(){try{this.tx.abort()}catch(t){throw Z(t)}}};l(tt,"IndexedDBRWTransaction");var Y=class{constructor(t,e){this.db=t;this.storeName=e}static create(t,e){return new Promise((r,i)=>{let n=e.open(t,1);n.onupgradeneeded=()=>{let o=n.result;o.objectStoreNames.contains(t)&&o.deleteObjectStore(t),o.createObjectStore(t)},n.onsuccess=()=>r(new Y(n.result,t)),n.onerror=o=>{o.preventDefault(),i(new a(h.EACCES))}})}get name(){return xt.name+":"+this.storeName}clear(){return new Promise((t,e)=>{try{let r=this.db.transaction(this.storeName,"readwrite").objectStore(this.storeName).clear();r.onsuccess=()=>setTimeout(t,0),r.onerror=i=>{i.preventDefault(),e(new a(h.EIO))}}catch(r){e(Z(r))}})}beginTransaction(t="readonly"){let e=this.db.transaction(this.storeName,t),r=e.objectStore(this.storeName);if(t==="readwrite")return new tt(e,r);if(t==="readonly")return new K(e,r);throw new a(h.EINVAL,"Invalid transaction type.")}};l(Y,"IndexedDBStore");var xt={name:"IndexedDB",options:{storeName:{type:"string",required:!1,description:"The name of this file system. You can have multiple IndexedDB file systems operating at once, but each must have a different name."},cacheSize:{type:"number",required:!1,description:"The size of the inode cache. Defaults to 100. A size of 0 or below disables caching."},idbFactory:{type:"object",required:!1,description:"The IDBFactory to use. Defaults to globalThis.indexedDB."}},isAvailable(s=globalThis.indexedDB){try{if(!(s instanceof IDBFactory))return!1;let t=s.open("__zenfs_test");if(!t)return!1;t.onsuccess=()=>s.deleteDatabase("__zenfs_test")}catch{return!1}return!0},create({cacheSize:s=100,storeName:t="zenfs",idbFactory:e=globalThis.indexedDB}){let r=Y.create(t,e);return new Q({cacheSize:s,store:r})}};var et=class{constructor(t){this.store=t,this.originalData=new Map,this.modifiedKeys=new Set}get(t){let e=this.store.get(t);return this.stashOldValue(t,e),e}put(t,e,r){return this.markModified(t),this.store.put(t,e,r)}remove(t){this.markModified(t),this.store.remove(t)}commit(){}abort(){for(let t of this.modifiedKeys){let e=this.originalData.get(t);e?this.store.put(t,e,!0):this.store.remove(t)}}stashOldValue(t,e){this.originalData.has(t)||this.originalData.set(t,e)}markModified(t){this.modifiedKeys.add(t),this.originalData.has(t)||this.originalData.set(t,this.store.get(t))}};l(et,"SimpleSyncRWTransaction");var ft=class extends k{constructor(t,e,r,i,n){super(t,e,r,i,n)}async sync(){this.syncSync()}syncSync(){this.isDirty()&&(this.fs.syncSync(this.path,this._buffer,this.stats),this.resetDirty())}async close(){this.closeSync()}closeSync(){this.syncSync()}};l(ft,"SyncStoreFile");var it=class extends bt(P){constructor(t){super(),this.store=t.store,this.makeRootDirectory()}metadata(){return{...super.metadata(),name:this.store.name}}empty(){this.store.clear(),this.makeRootDirectory()}renameSync(t,e,r){let i=this.store.beginTransaction("readwrite"),n=w(t),o=g(t),c=w(e),d=g(e),m=this.findINode(i,n),u=this.getDirListing(i,m,n);if(!m.toStats().hasAccess(2,r))throw a.EACCES(t);if(!u[o])throw a.ENOENT(t);let f=u[o];if(delete u[o],(c+"/").indexOf(t+"/")==0)throw new a(h.EBUSY,n);let S,N;if(c===n?(S=m,N=u):(S=this.findINode(i,c),N=this.getDirListing(i,S,c)),N[d]){let x=this.getINode(i,N[d],e);if(x.toStats().isFile())try{i.remove(x.ino),i.remove(N[d])}catch(W){throw i.abort(),W}else throw a.EPERM(e)}N[d]=f;try{i.put(m.ino,_(u),!0),i.put(S.ino,_(N),!0)}catch(x){throw i.abort(),x}i.commit()}statSync(t,e){let r=this.findINode(this.store.beginTransaction("readonly"),t).toStats();if(!r.hasAccess(4,e))throw a.EACCES(t);return r}createFileSync(t,e,r,i){return this.commitNewFile(t,E.FILE,r,i),this.openFileSync(t,e,i)}openFileSync(t,e,r){let i=this.store.beginTransaction("readonly"),n=this.findINode(i,t),o=i.get(n.ino);if(!n.toStats().hasAccess(e.mode,r))throw a.EACCES(t);if(o===null)throw a.ENOENT(t);return new ft(this,t,e,n.toStats(),o)}unlinkSync(t,e){this.removeEntry(t,!1,e)}rmdirSync(t,e){if(this.readdirSync(t,e).length>0)throw a.ENOTEMPTY(t);this.removeEntry(t,!0,e)}mkdirSync(t,e,r){this.commitNewFile(t,E.DIRECTORY,e,r,A("{}"))}readdirSync(t,e){let r=this.store.beginTransaction("readonly"),i=this.findINode(r,t);if(!i.toStats().hasAccess(4,e))throw a.EACCES(t);return Object.keys(this.getDirListing(r,i,t))}syncSync(t,e,r){let i=this.store.beginTransaction("readwrite"),n=this._findINode(i,w(t),g(t)),o=this.getINode(i,n,t),c=o.update(r);try{i.put(o.ino,e,!0),c&&i.put(n,o.data,!0)}catch(d){throw i.abort(),d}i.commit()}linkSync(t,e,r){let i=this.store.beginTransaction("readwrite"),n=w(t);if(!this.findINode(i,n).toStats().hasAccess(4,r))throw a.EACCES(n);let c=w(e),d=this.findINode(i,c),m=this.getDirListing(i,d,c);if(!d.toStats().hasAccess(2,r))throw a.EACCES(c);let u=this._findINode(i,n,g(t)),f=this.getINode(i,u,t);if(!f.toStats().hasAccess(2,r))throw a.EACCES(e);f.nlink++,m[g(e)]=u;try{i.put(u,f.data,!0),i.put(d.ino,_(m),!0)}catch(S){throw i.abort(),S}i.commit()}makeRootDirectory(){let t=this.store.beginTransaction("readwrite");if(t.get(T))return;let e=new D;e.mode=511|E.DIRECTORY,t.put(e.ino,A("{}"),!1),t.put(T,e.data,!1),t.commit()}_findINode(t,e,r,i=new Set){let n=v(e,r);if(i.has(n))throw new a(h.EIO,"Infinite loop detected while finding inode",n);if(i.add(n),e!="/"){let o=this._findINode(t,w(e),g(e),i),c=this.getDirListing(t,this.getINode(t,o,e+wt+r),e);if(!(r in c))throw a.ENOENT(X(e,r));return c[r]}if(r!=""){let o=this.getDirListing(t,this.getINode(t,T,e),e);if(!(r in o))throw a.ENOENT(X(e,r));return o[r]}return T}findINode(t,e){let r=this._findINode(t,w(e),g(e));return this.getINode(t,r,e)}getINode(t,e,r){let i=t.get(e);if(!i)throw a.ENOENT(r);return new D(i.buffer)}getDirListing(t,e,r){if(!e.toStats().isDirectory())throw a.ENOTDIR(r);let i=t.get(e.ino);if(!i)throw a.ENOENT(r);return dt(i)}addNewNode(t,e){let i;for(;0<5;)try{return i=q(),t.put(i,e,!1),i}catch{}throw new a(h.EIO,"Unable to commit data to key-value store.")}commitNewFile(t,e,r,i,n=new Uint8Array){let o=this.store.beginTransaction("readwrite"),c=w(t),d=g(t),m=this.findINode(o,c),u=this.getDirListing(o,m,c);if(!m.toStats().hasAccess(2,i))throw a.EACCES(t);if(t==="/")throw a.EEXIST(t);if(u[d])throw a.EEXIST(t);let f=new D;try{f.ino=this.addNewNode(o,n),f.size=n.length,f.mode=r|e,f.uid=i.uid,f.gid=i.gid,u[d]=this.addNewNode(o,f.data),o.put(m.ino,_(u),!0)}catch(S){throw o.abort(),S}return o.commit(),f}removeEntry(t,e,r){let i=this.store.beginTransaction("readwrite"),n=w(t),o=this.findINode(i,n),c=this.getDirListing(i,o,n),d=g(t),m=c[d];if(!m)throw a.ENOENT(t);let u=this.getINode(i,m,t);if(!u.toStats().hasAccess(2,r))throw a.EACCES(t);if(delete c[d],!e&&u.toStats().isDirectory())throw a.EISDIR(t);if(e&&!u.toStats().isDirectory())throw a.ENOTDIR(t);try{i.put(o.ino,_(c),!0),--u.nlink<1&&(i.remove(u.ino),i.remove(m))}catch(f){throw i.abort(),f}i.commit()}};l(it,"SyncStoreFS");var rt=class{constructor(t){this._storage=t}get name(){return It.name}clear(){this._storage.clear()}beginTransaction(){return new et(this)}get(t){let e=this._storage.getItem(t.toString());if(typeof e=="string")return A(e)}put(t,e,r){try{return!r&&this._storage.getItem(t.toString())!==null?!1:(this._storage.setItem(t.toString(),G(e)),!0)}catch{throw new a(h.ENOSPC,"Storage is full.")}}remove(t){try{this._storage.removeItem(t.toString())}catch(e){throw new a(h.EIO,"Unable to delete key "+t+": "+e)}}};l(rt,"StorageStore");var It={name:"Storage",options:{storage:{type:"object",required:!1,description:"The Storage to use. Defaults to globalThis.localStorage."}},isAvailable(s=globalThis.localStorage){return s instanceof globalThis.Storage},create({storage:s=globalThis.localStorage}){return new it({store:new rt(s)})}};return Ft(Ct);})();
4
2
  //# sourceMappingURL=browser.min.js.map