-
Notifications
You must be signed in to change notification settings - Fork 0
/
browser-fs-dom.min.js
11 lines (11 loc) · 23.2 KB
/
browser-fs-dom.min.js
1
2
3
4
5
6
7
8
9
10
11
var BrowserFS_DOM=(()=>{var $e=Object.create;var M=Object.defineProperty;var Ve=Object.getOwnPropertyDescriptor;var qe=Object.getOwnPropertyNames;var je=Object.getPrototypeOf,Ke=Object.prototype.hasOwnProperty;var c=(i,r)=>M(i,"name",{value:r,configurable:!0});var I=(i,r)=>()=>(r||i((r={exports:{}}).exports,r),r.exports),We=(i,r)=>{for(var e in r)M(i,e,{get:r[e],enumerable:!0})},pe=(i,r,e,t)=>{if(r&&typeof r=="object"||typeof r=="function")for(let n of qe(r))!Ke.call(i,n)&&n!==e&&M(i,n,{get:()=>r[n],enumerable:!(t=Ve(r,n))||t.enumerable});return i};var h=(i,r,e)=>(e=i!=null?$e(je(i)):{},pe(r||!i||!i.__esModule?M(e,"default",{value:i,enumerable:!0}):e,i)),ze=i=>pe(M({},"__esModule",{value:!0}),i);var T=I((ot,me)=>{me.exports=BrowserFS});var he=I((at,ye)=>{ye.exports=BrowserFS});var oe=I((ct,ge)=>{ge.exports=BrowserFS});var J=I((lt,be)=>{be.exports=BrowserFS});var ae=I((ut,we)=>{we.exports=BrowserFS});var Ce=I((Pt,Te)=>{Te.exports=BrowserFS});var ve=I((Ht,Ne)=>{Ne.exports=BrowserFS});var Be=I((jt,ke)=>{ke.exports=BrowserFS});var it={};We(it,{FileSystemAccessFile:()=>$,FileSystemAccessFileSystem:()=>R,HTTPRequest:()=>N,IndexedDBFileSystem:()=>_,IndexedDBROTransaction:()=>B,IndexedDBRWTransaction:()=>q,IndexedDBStore:()=>v,StorageFileSystem:()=>P,StorageStore:()=>K,WorkerFS:()=>D});function U(i,r){if(typeof i!="string")throw new TypeError(`"${r}" is not a string`)}c(U,"validateString");function Ye(i,r){let e="",t=0,n=-1,s=0,o="\0";for(let a=0;a<=i.length;++a){if(a<i.length)o=i[a];else{if(o=="/")break;o="/"}if(o=="/"){if(!(n===a-1||s===1))if(s===2){if(e.length<2||t!==2||e.at(-1)!=="."||e.at(-2)!=="."){if(e.length>2){let l=e.lastIndexOf("/");l===-1?(e="",t=0):(e=e.slice(0,l),t=e.length-1-e.lastIndexOf("/")),n=a,s=0;continue}else if(e.length!==0){e="",t=0,n=a,s=0;continue}}r&&(e+=e.length>0?"/..":"..",t=2)}else e.length>0?e+="/"+i.slice(n+1,a):e=i.slice(n+1,a),t=a-n-1;n=a,s=0}else o==="."&&s!==-1?++s:s=-1}return e}c(Ye,"normalizeString");function Xe(i){if(U(i,"path"),i.length===0)return".";let r=i[0]==="/",e=i.at(-1)==="/";return i=Ye(i,!r),i.length===0?r?"/":e?"./":".":(e&&(i+="/"),r?`/${i}`:i)}c(Xe,"normalize");function X(...i){if(i.length===0)return".";let r;for(let e=0;e<i.length;++e){let t=i[e];U(t,"path"),t.length>0&&(r===void 0?r=t:r+=`/${t}`)}return r===void 0?".":Xe(r)}c(X,"join");function L(i){if(U(i,"path"),i.length===0)return".";let r=i[0]==="/",e=-1,t=!0;for(let n=i.length-1;n>=1;--n)if(i[n]==="/"){if(!t){e=n;break}}else t=!1;return e===-1?r?"/":".":r&&e===1?"//":i.slice(0,e)}c(L,"dirname");function se(i,r){r!==void 0&&U(r,"ext"),U(i,"path");let e=0,t=-1,n=!0;if(r!==void 0&&r.length>0&&r.length<=i.length){if(r===i)return"";let s=r.length-1,o=-1;for(let a=i.length-1;a>=0;--a)if(i[a]==="/"){if(!n){e=a+1;break}}else o===-1&&(n=!1,o=a+1),s>=0&&(i[a]===r[s]?--s===-1&&(t=a):(s=-1,t=o));return e===t?t=o:t===-1&&(t=i.length),i.slice(e,t)}for(let s=i.length-1;s>=0;--s)if(i[s]==="/"){if(!n){e=s+1;break}}else t===-1&&(n=!1,t=s+1);return t===-1?"":i.slice(e,t)}c(se,"basename");var p=h(T(),1),Oe=h(he(),1),Z=h(oe(),1),Ae=h(J(),1),O=h(ae(),1);var d;(function(i){i[i.EPERM=1]="EPERM",i[i.ENOENT=2]="ENOENT",i[i.EIO=5]="EIO",i[i.EBADF=9]="EBADF",i[i.EACCES=13]="EACCES",i[i.EBUSY=16]="EBUSY",i[i.EEXIST=17]="EEXIST",i[i.ENOTDIR=20]="ENOTDIR",i[i.EISDIR=21]="EISDIR",i[i.EINVAL=22]="EINVAL",i[i.EFBIG=27]="EFBIG",i[i.ENOSPC=28]="ENOSPC",i[i.EROFS=30]="EROFS",i[i.ENOTEMPTY=39]="ENOTEMPTY",i[i.ENOTSUP=95]="ENOTSUP"})(d=d||(d={}));var xe={[d.EPERM]:"Operation not permitted.",[d.ENOENT]:"No such file or directory.",[d.EIO]:"Input/output error.",[d.EBADF]:"Bad file descriptor.",[d.EACCES]:"Permission denied.",[d.EBUSY]:"Resource busy or locked.",[d.EEXIST]:"File exists.",[d.ENOTDIR]:"File is not a directory.",[d.EISDIR]:"File is a directory.",[d.EINVAL]:"Invalid argument.",[d.EFBIG]:"File is too big.",[d.ENOSPC]:"No space left on disk.",[d.EROFS]:"Cannot modify a read-only file system.",[d.ENOTEMPTY]:"Directory is not empty.",[d.ENOTSUP]:"Operation is not supported."},x=class extends Error{static fromJSON(r){let e=new x(r.errno,r.message,r.path);return e.code=r.code,e.stack=r.stack,e}static Derserialize(r,e=0){let t=new DataView("buffer"in r?r.buffer:r),n=Ee(t.buffer.slice(e+4,e+4+t.getUint32(e,!0)));return x.fromJSON(JSON.parse(n))}static FileError(r,e){return new x(r,xe[r],e)}static EACCES(r){return this.FileError(d.EACCES,r)}static ENOENT(r){return this.FileError(d.ENOENT,r)}static EEXIST(r){return this.FileError(d.EEXIST,r)}static EISDIR(r){return this.FileError(d.EISDIR,r)}static ENOTDIR(r){return this.FileError(d.ENOTDIR,r)}static EPERM(r){return this.FileError(d.EPERM,r)}static ENOTEMPTY(r){return this.FileError(d.ENOTEMPTY,r)}constructor(r,e=xe[r],t){super(e),this.syscall="",this.errno=r,this.code=d[r],this.path=t,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(r=new Uint8Array(this.bufferSize()),e=0){let t=new DataView("buffer"in r?r.buffer:r),n=new Uint8Array(t.buffer),s=Se(JSON.stringify(this.toJSON()));return n.set(s),t.setUint32(e,s.byteLength,!0),n}bufferSize(){return 4+JSON.stringify(this.toJSON()).length}};c(x,"ApiError");function G(i,r,e,t,n){return Math.min(i+1,r+1,e+1,t===n?r:r+1)}c(G,"_min");function Ge(i,r){if(i===r)return 0;i.length>r.length&&([i,r]=[r,i]);let e=i.length,t=r.length;for(;e>0&&i.charCodeAt(e-1)===r.charCodeAt(t-1);)e--,t--;let n=0;for(;n<e&&i.charCodeAt(n)===r.charCodeAt(n);)n++;if(e-=n,t-=n,e===0||t===1)return t;let s=new Array(e<<1);for(let y=0;y<e;)s[e+y]=i.charCodeAt(n+y),s[y]=++y;let o,a,l,f,m;for(o=0;o+3<t;){let y=r.charCodeAt(n+(a=o)),w=r.charCodeAt(n+(l=o+1)),k=r.charCodeAt(n+(f=o+2)),Le=r.charCodeAt(n+(m=o+3)),ne=o+=4;for(let z=0;z<e;){let Y=s[e+z],de=s[z];a=G(de,a,l,y,Y),l=G(a,l,f,w,Y),f=G(l,f,m,k,Y),ne=G(f,m,ne,Le,Y),s[z++]=ne,m=f,f=l,l=a,a=de}}let u=0;for(;o<t;){let y=r.charCodeAt(n+(a=o));u=++o;for(let w=0;w<e;w++){let k=s[w];s[w]=u=k<a||u<a?k>u?u+1:k+1:y===s[e+w]?a:a+1,a=k}}return u}c(Ge,"levenshtein");async function Fe(i,r){let e=i.Options,t=i.Name,n=0,s=!1,o=!1;for(let a in e)if(Object.prototype.hasOwnProperty.call(e,a)){let l=e[a],f=r&&r[a];if(f==null){if(!l.optional){let m=Object.keys(r).filter(u=>!(u in e)).map(u=>({str:u,distance:Ge(a,u)})).filter(u=>u.distance<5).sort((u,y)=>u.distance-y.distance);if(s)return;throw s=!0,new x(d.EINVAL,`[${t}] Required option '${a}' not provided.${m.length>0?` You provided unrecognized option '${m[0].str}'; perhaps you meant to type '${a}'.`:""}
Option description: ${l.description}`)}}else{let m=!1;if(Array.isArray(l.type)?m=l.type.indexOf(typeof f)!==-1:m=typeof f===l.type,m){if(l.validator){n++;try{await l.validator(f)}catch(u){if(!s){if(u)throw s=!0,u;if(n--,n===0&&o)return}}}}else{if(s)return;throw s=!0,new x(d.EINVAL,`[${t}] Value provided for option ${a} is not the proper type. Expected ${Array.isArray(l.type)?`one of {${l.type.join(", ")}}`:l.type}, but received ${typeof f}
Option description: ${l.description}`)}}}o=!0}c(Fe,"checkOptions");var yt=typeof globalThis.setImmediate=="function"?globalThis.setImmediate:i=>setTimeout(i,0);function Se(i,r="utf8"){let e=i||"";switch(r){default:case"utf8":case"utf-8":return new TextEncoder().encode(e);case"utf16le":case"utf-16le":case"ucs2":case"ucs-2":return new Uint8Array(Uint16Array.from(e.split(""),t=>t.charCodeAt(0)).buffer);case"ascii":case"latin1":case"binary":return Uint8Array.from(e.split(""),t=>t.charCodeAt(0));case"hex":return Uint8Array.from(e.match(/../g),t=>parseInt(t,16));case"base64":case"base64url":return e=e.replaceAll("-","+").replaceAll("_","/"),Uint8Array.from(atob(e).split(""),t=>t.charCodeAt(0))}}c(Se,"encode");function Ee(i,r="utf8"){if(!i||!i.byteLength)return"";let e=new Uint8Array("buffer"in i?i.buffer:i);switch(r){default:case"utf8":case"utf-8":return new TextDecoder("utf-8").decode(e);case"utf16le":case"utf-16le":case"ucs2":case"ucs-2":return new TextDecoder("utf-16le").decode(e);case"ascii":return new TextDecoder("utf-8").decode(e.map(t=>t&127));case"latin1":case"binary":return new TextDecoder("utf-16").decode(new Uint8Array(Uint16Array.from(e).buffer));case"hex":return Array.from(e,t=>t.toString(16).padStart(2,"0")).join("");case"base64":return btoa(new TextDecoder("utf-16").decode(new Uint8Array(Uint16Array.from(e).buffer)));case"base64url":return btoa(new TextDecoder("utf-16").decode(new Uint8Array(Uint16Array.from(e).buffer))).replaceAll("+","-").replaceAll("/","_").replaceAll("=","")}}c(Ee,"decode");function S(i,r){r=typeof i=="function"?i:r,Fe(this,i);let e=new this(typeof i=="function"?{}:i);if(typeof r!="function")return e.whenReady();e.whenReady().then(t=>r(null,t)).catch(t=>r(t))}c(S,"CreateBackend");var C=c((i="",r)=>{throw r instanceof p.ApiError?r:r.name==="NotFoundError"?p.ApiError.ENOENT(i):r.name==="TypeError"?p.ApiError.ENOENT(i):r.name==="NotAllowedError"?p.ApiError.EACCES(i):r?.message?new p.ApiError(p.ErrorCode.EIO,r.message,i):p.ApiError.FileError(p.ErrorCode.EIO,i)},"handleError"),Ie=c(async i=>{let r=[];for await(let e of i)r.push(e);return r},"Array_fromAsync"),$=class extends Z.PreloadFile{constructor(r,e,t,n,s){super(r,e,t,n,s)}async sync(){this.isDirty()&&(await this._fs._sync(this.getPath(),this.getBuffer(),this.getStats(),Oe.Cred.Root),this.resetDirty())}async close(){await this.sync()}};c($,"FileSystemAccessFile");var Q=class extends Ae.BaseFileSystem{constructor({handle:e}){super();this._handles=new Map;this._ready=(async(t,n)=>{if(t=await t,!(t instanceof FileSystemDirectoryHandle))throw p.ApiError.ENOTDIR("/");try{await t.keys().next()}catch(s){C("/",s)}return this._handles.set("/",t),n})(e||navigator.storage.getDirectory(),this._ready)}static isAvailable(){return typeof FileSystemHandle=="function"}get metadata(){return{...super.metadata,name:Q.Name}}async _sync(e,t,n,s){let o=await this.stat(e,s);n.mtime!==o.mtime&&await this.writeFile(e,t,Z.FileFlag.getFileFlag("w"),o.mode,s)}async rename(e,t,n){let s=e;try{let o=await this.getHandle(e),a=await this.getHandle(L(e),{parent:!0});if(o instanceof FileSystemDirectoryHandle){let l=await Ie(o.keys());await this.getHandle(t,{create:"directory"});for(let f of l)await this.rename(X(e,f),X(t,f),n);a.isSameEntry(o)||await a.removeEntry(o.name)}if(o instanceof FileSystemFileHandle){let f=await(await o.getFile()).arrayBuffer();s=t;let u=await(await this.getHandle(t,{create:"file"})).createWritable();await u.write(f),s=t,u.close(),s=e,await a.removeEntry(o.name)}}catch(o){C(s,o)}}async writeFile(e,t,n,s,o){try{let l=await(await this.getHandle(e,{create:"file"})).createWritable();await l.write(t),await l.close()}catch(a){C(e,a)}}async createFile(e,t,n,s){return await this.writeFile(e,new Uint8Array,t,n,s),this.openFile(e,t,s)}async stat(e,t){try{let n=await this.getHandle(e);if(n instanceof FileSystemDirectoryHandle)return new O.Stats(O.FileType.DIRECTORY,4096);if(n instanceof FileSystemFileHandle){let{lastModified:s,size:o}=await n.getFile();return new O.Stats(O.FileType.FILE,o,void 0,void 0,s)}}catch(n){C(e,n)}}async exists(e,t){try{return await this.getHandle(e),!0}catch(n){if(n?.errno!==p.ErrorCode.ENOENT)throw n;return!1}}async openFile(e,t,n){try{let s=await this.getHandle(e);if(s instanceof FileSystemFileHandle){let o=await s.getFile(),a=await o.arrayBuffer();return this.newFile(e,t,a,o.size,o.lastModified)}else throw p.ApiError.EISDIR(e)}catch(s){C(e,s)}}async unlink(e,t){if(e==="/"){let n=await this.readdir(e,t);for(let s of n)await this.unlink("/"+s,t);return}try{let n=await this.getHandle(e);await(await this.getHandle(L(e),{parent:!0})).removeEntry(se(e),{recursive:!0})}catch(n){if(n?.errno===p.ErrorCode.ENOENT)return;C(e,n)}}async rmdir(e,t){return this.unlink(e,t)}async mkdir(e,t,n){try{throw await this.getHandle(e),p.ApiError.EEXIST(e)}catch(s){if(s?.errno!==p.ErrorCode.ENOENT)throw s}await this.getHandle(e,{create:"directory"})}async readdir(e,t){let n=await this.getHandle(e);if(!(n instanceof FileSystemDirectoryHandle))throw p.ApiError.ENOTDIR(e);return await Ie(n.keys())}newFile(e,t,n,s,o){return new $(this,e,t,new O.Stats(O.FileType.FILE,s||0,void 0,void 0,o||new Date().getTime()),new Uint8Array(n))}async getHandle(e,{create:t,parent:n}={}){try{let o=this._handles.get(e);if(o instanceof FileSystemFileHandle&&await o.getFile(),o instanceof FileSystemDirectoryHandle&&(n||await o.keys().next()),o)return o}catch{}var s="";try{var s=L(e);let o=null;try{let u=this._handles.get(s);u instanceof FileSystemDirectoryHandle&&(s==="/"||await u.keys().next(),o=u)}catch(u){if(u?.name==="TypeMismatchError")throw p.ApiError.ENOTDIR(s)}if(!o){let[,...u]=e.split("/");s="/",o=this._handles.get("/");for(let y of u)try{s=X(s,y),o=await o.getDirectoryHandle(y),this._handles.set(s,o)}catch(w){throw w?.name!=="TypeMismatchError"?w:(this._handles.set(s,await o.getFileHandle(y)),p.ApiError.ENOTDIR(s))}}let a=se(e);var s=e;let f;try{f=await o.getDirectoryHandle(a,{create:t==="directory"})}catch(u){let y=u?.name==="TypeMismatchError",w=t&&u?.name==="NotFoundError";if(!(y||w))throw u;f=await o.getFileHandle(a,{create:t==="file"})}this._handles.set(s,f);let m=n?"directory":t;if(m&&m!==f.kind)throw n?p.ApiError.ENOTDIR(s):f.kind==="directory"?p.ApiError.EISDIR(s):p.ApiError.EEXIST(s);return f}catch(o){C(s,o);return}}},R=Q;c(R,"FileSystemAccessFileSystem"),R.Name="FileSystemAccess",R.Create=S.bind(Q),R.Options={};var Re=h(J(),1),g=h(T(),1),A=h(oe(),1),le=h(ae(),1);var E=h(T(),1);var _e=typeof fetch<"u"&&fetch!==null;function ee(i){throw new E.ApiError(E.ErrorCode.EIO,i.message)}c(ee,"convertError");async function ce(i,r){let e=await fetch(i).catch(ee);if(!e.ok)throw new E.ApiError(E.ErrorCode.EIO,`fetch error: response returned code ${e.status}`);switch(r){case"buffer":let t=await e.arrayBuffer().catch(ee);return new Uint8Array(t);case"json":return e.json().catch(ee);default:throw new E.ApiError(E.ErrorCode.EINVAL,"Invalid download type: "+r)}}c(ce,"fetchFile");async function Pe(i){let r=await fetch(i,{method:"HEAD"}).catch(ee);if(!r.ok)throw new E.ApiError(E.ErrorCode.EIO,`fetch HEAD error: response returned code ${r.status}`);return parseInt(r.headers.get("Content-Length")||"-1",10)}c(Pe,"fetchFileSize");var F=h(Ce(),1);var te=class extends Re.BaseFileSystem{constructor({index:e,baseUrl:t=""}){super();e||(e="index.json");let n=typeof e=="string"?ce(e,"json"):Promise.resolve(e);this._ready=n.then(s=>(this._index=F.FileIndex.fromListing(s),this)),t.length>0&&t.charAt(t.length-1)!=="/"&&(t=t+"/"),this.prefixUrl=t}static isAvailable(){return _e}get metadata(){return{...super.metadata,name:te.Name,readonly:!0}}empty(){this._index.fileIterator(function(e){e.fileData=null})}preloadFile(e,t){let n=this._index.getInode(e);if((0,F.isIndexFileInode)(n)){if(n===null)throw g.ApiError.ENOENT(e);let s=n.getData();s.size=t.length,s.fileData=t}else throw g.ApiError.EISDIR(e)}async stat(e,t){let n=this._index.getInode(e);if(n===null)throw g.ApiError.ENOENT(e);if(!n.toStats().hasAccess(4,t))throw g.ApiError.EACCES(e);let s;if((0,F.isIndexFileInode)(n))s=n.getData(),s.size<0&&(s.size=await this._requestFileSize(e));else if((0,F.isIndexDirInode)(n))s=n.getStats();else throw g.ApiError.FileError(g.ErrorCode.EINVAL,e);return s}async open(e,t,n,s){if(t.isWriteable())throw new g.ApiError(g.ErrorCode.EPERM,e);let o=this._index.getInode(e);if(o===null)throw g.ApiError.ENOENT(e);if(!o.toStats().hasAccess(t.getMode(),s))throw g.ApiError.EACCES(e);if((0,F.isIndexFileInode)(o)||(0,F.isIndexDirInode)(o))switch(t.pathExistsAction()){case A.ActionType.THROW_EXCEPTION:case A.ActionType.TRUNCATE_FILE:throw g.ApiError.EEXIST(e);case A.ActionType.NOP:if((0,F.isIndexDirInode)(o)){let f=o.getStats();return new A.NoSyncFile(this,e,t,f,f.fileData||void 0)}let a=o.getData();if(a.fileData)return new A.NoSyncFile(this,e,t,le.Stats.clone(a),a.fileData);let l=await this._requestFile(e,"buffer");return a.size=l.length,a.fileData=l,new A.NoSyncFile(this,e,t,le.Stats.clone(a),l);default:throw new g.ApiError(g.ErrorCode.EINVAL,"Invalid FileMode object.")}else throw g.ApiError.EPERM(e)}async readdir(e,t){return this.readdirSync(e,t)}async readFile(e,t,n){let s=await this.open(e,t,420,n);try{return s.getBuffer()}finally{await s.close()}}_getHTTPPath(e){return e.charAt(0)==="/"&&(e=e.slice(1)),this.prefixUrl+e}_requestFile(e,t){return ce(this._getHTTPPath(e),t)}_requestFileSize(e){return Pe(this._getHTTPPath(e))}},N=te;c(N,"HTTPRequest"),N.Name="HTTPRequest",N.Create=S.bind(te),N.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 De=h(ve(),1),b=h(T(),1);function V(i,r=i.toString()){switch(i.name){case"NotFoundError":return new b.ApiError(b.ErrorCode.ENOENT,r);case"QuotaExceededError":return new b.ApiError(b.ErrorCode.ENOSPC,r);default:return new b.ApiError(b.ErrorCode.EIO,r)}}c(V,"convertError");function j(i,r=b.ErrorCode.EIO,e=null){return function(t){t.preventDefault(),i(new b.ApiError(r,e!==null?e:void 0))}}c(j,"onErrorHandler");var B=class{constructor(r,e){this.tx=r;this.store=e}get(r){return new Promise((e,t)=>{try{let n=this.store.get(r);n.onerror=j(t),n.onsuccess=s=>{let o=s.target.result;e(o===void 0?o:Uint8Array.from(o))}}catch(n){t(V(n))}})}};c(B,"IndexedDBROTransaction");var q=class extends B{constructor(r,e){super(r,e)}put(r,e,t){return new Promise((n,s)=>{try{let o=t?this.store.put(e,r):this.store.add(e,r);o.onerror=j(s),o.onsuccess=()=>{n(!0)}}catch(o){s(V(o))}})}del(r){return new Promise((e,t)=>{try{let n=this.store.delete(r);n.onerror=j(t),n.onsuccess=()=>{e()}}catch(n){t(V(n))}})}commit(){return new Promise(r=>{setTimeout(r,0)})}abort(){return new Promise((r,e)=>{try{this.tx.abort(),r()}catch(t){e(V(t))}})}};c(q,"IndexedDBRWTransaction");var v=class{constructor(r,e){this.db=r;this.storeName=e}static Create(r,e){return new Promise((t,n)=>{let s=e.open(r,1);s.onupgradeneeded=o=>{let a=o.target.result;a.objectStoreNames.contains(r)&&a.deleteObjectStore(r),a.createObjectStore(r)},s.onsuccess=o=>{t(new v(o.target.result,r))},s.onerror=j(n,b.ErrorCode.EACCES)})}name(){return _.Name+" - "+this.storeName}clear(){return new Promise((r,e)=>{try{let t=this.db.transaction(this.storeName,"readwrite"),n=t.objectStore(this.storeName),s=n.clear();s.onsuccess=()=>{setTimeout(r,0)},s.onerror=j(e)}catch(t){e(V(t))}})}beginTransaction(r="readonly"){let e=this.db.transaction(this.storeName,r),t=e.objectStore(this.storeName);if(r==="readwrite")return new q(e,t);if(r==="readonly")return new B(e,t);throw new b.ApiError(b.ErrorCode.EINVAL,"Invalid transaction type.")}};c(v,"IndexedDBStore");var ue=class extends De.AsyncKeyValueFileSystem{static isAvailable(r=globalThis.indexedDB){try{if(!(r instanceof IDBFactory)||!r.open("__browserfs_test__"))return!1}catch{return!1}}constructor({cacheSize:r=100,storeName:e="browserfs",idbFactory:t=globalThis.indexedDB}){super(r),this._ready=v.Create(e,t).then(n=>(this.init(n),this))}},_=ue;c(_,"IndexedDBFileSystem"),_.Name="IndexedDB",_.Create=S.bind(ue),_.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 re=h(Be(),1),H=h(T(),1);var Ze=c(i=>String.fromCodePoint(i>>11!==27?i:i|65536),"itoc"),et=c(i=>i.codePointAt(0),"ctoi"),tt=new Int16Array(Int8Array.from([-1,0]).buffer)[0]<0?(i,r)=>String.fromCodePoint(i<<8|r):(i,r)=>String.fromCharCode(i|r<<8);function He(i){let{length:r,buffer:e,byteOffset:t,byteLength:n}=i,s=t%2,o=n%2,a;s&&(i=new Uint8Array(e,--t,n+1),a=i[0],i.copyWithin(0,1));let l=new Uint16Array(e,t,n>>1),f=o&&i[r-1],m=2-o,u=Array.from(l,Ze);return u.push(tt(f,m)),s&&(i.copyWithin(1,0),i[0]=a),u.join("")}c(He,"utf16Encode");function Me(i){let r=Uint16Array.from(i,et),e=new Uint8Array(r.buffer),{length:t,buffer:n}=e,s=e[t-1];return new Uint8Array(n.slice(0,t-s))}c(Me,"utf16Decode");var K=class{constructor(r){this._storage=r}name(){return P.Name}clear(){this._storage.clear()}beginTransaction(r){return new re.SimpleSyncRWTransaction(this)}get(r){let e=this._storage.getItem(r);if(typeof e=="string")return Me(e)}put(r,e,t){try{return!t&&this._storage.getItem(r)!==null?!1:(this._storage.setItem(r,He(e)),!0)}catch{throw new H.ApiError(H.ErrorCode.ENOSPC,"Storage is full.")}}del(r){try{this._storage.removeItem(r)}catch(e){throw new H.ApiError(H.ErrorCode.EIO,"Unable to delete key "+r+": "+e)}}};c(K,"StorageStore");var fe=class extends re.SyncKeyValueFileSystem{static isAvailable(r=globalThis.localStorage){return r instanceof Storage}constructor({storage:r=globalThis.localStorage}){super({store:new K(r)})}},P=fe;c(P,"StorageFileSystem"),P.Name="Storage",P.Create=S.bind(fe),P.Options={storage:{type:"object",optional:!0,description:"The Storage to use. Defaults to globalThis.localStorage."}};var Ue=h(J(),1),W=h(T(),1);function rt(i){return typeof i=="object"&&"isBFS"in i&&!!i.isBFS}c(rt,"isRPCMessage");var ie=class extends Ue.BaseFileSystem{constructor({worker:e}){super();this._currentID=0;this._requests=new Map;this._isInitialized=!1;this._worker=e,this._worker.onmessage=t=>{if(!rt(t.data))return;let{id:n,method:s,value:o}=t.data;if(s==="metadata"){this._metadata=o,this._isInitialized=!0;return}let{resolve:a,reject:l}=this._requests.get(n);if(this._requests.delete(n),o instanceof Error||o instanceof W.ApiError){l(o);return}a(o)}}static isAvailable(){return typeof importScripts<"u"||typeof Worker<"u"}get metadata(){return{...super.metadata,...this._metadata,name:ie.Name,synchronous:!1}}async _rpc(e,...t){return new Promise((n,s)=>{let o=this._currentID++;this._requests.set(o,{resolve:n,reject:s}),this._worker.postMessage({isBFS:!0,id:o,method:e,args:t})})}rename(e,t,n){return this._rpc("rename",e,t,n)}stat(e,t){return this._rpc("stat",e,t)}open(e,t,n,s){return this._rpc("open",e,t,n,s)}unlink(e,t){return this._rpc("unlink",e,t)}rmdir(e,t){return this._rpc("rmdir",e,t)}mkdir(e,t,n){return this._rpc("mkdir",e,t,n)}readdir(e,t){return this._rpc("readdir",e,t)}exists(e,t){return this._rpc("exists",e,t)}realpath(e,t){return this._rpc("realpath",e,t)}truncate(e,t,n){return this._rpc("truncate",e,t,n)}readFile(e,t,n){return this._rpc("readFile",e,t,n)}writeFile(e,t,n,s,o){return this._rpc("writeFile",e,t,n,s,o)}appendFile(e,t,n,s,o){return this._rpc("appendFile",e,t,n,s,o)}chmod(e,t,n){return this._rpc("chmod",e,t,n)}chown(e,t,n,s){return this._rpc("chown",e,t,n,s)}utimes(e,t,n,s){return this._rpc("utimes",e,t,n,s)}link(e,t,n){return this._rpc("link",e,t,n)}symlink(e,t,n,s){return this._rpc("symlink",e,t,n,s)}readlink(e,t){return this._rpc("readlink",e,t)}syncClose(e,t){return this._rpc("syncClose",e,t)}},D=ie;c(D,"WorkerFS"),D.Name="WorkerFS",D.Create=S.bind(ie),D.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 W.ApiError(W.ErrorCode.EINVAL,"option must be a Web Worker instance.")}}};return ze(it);})();
(__=>(typeof module === 'object')
&& (typeof exports === 'object')
&& (module?.exports === (exports||''))
? (module.exports = __)
: (typeof define === 'function')
&& define.amd && define(__)
)(globalThis.BrowserFS_DOM = BrowserFS_DOM)
//# sourceMappingURL=browser-fs-dom.min.js.map