-
Notifications
You must be signed in to change notification settings - Fork 0
/
storage.js
2 lines (2 loc) · 29.3 KB
/
storage.js
1
2
var be=Object.defineProperty;var Ce=(a,e,t)=>e in a?be(a,e,{enumerable:!0,configurable:!0,writable:!0,value:t}):a[e]=t;var w=(a,e)=>()=>(a&&(e=a(a=0)),e);var C=(a,e)=>{for(var t in e)be(a,t,{get:e[t],enumerable:!0})};var v=(a,e,t)=>(Ce(a,typeof e!="symbol"?e+"":e,t),t);var Me,I,G=w(()=>{Me={ReadableStream:globalThis.ReadableStream,WritableStream:globalThis.WritableStream,TransformStream:globalThis.TransformStream,DOMException:globalThis.DOMException,Blob:globalThis.Blob,File:globalThis.File},I=Me});var $={};C($,{FileHandle:()=>A,FolderHandle:()=>_,Sink:()=>V,default:()=>We});var M,Ae,u,_e,E,ge,Be,re,Ut,ze,V,A,_,Re,We,X=w(()=>{B();G();({File:M,Blob:Ae,DOMException:u}=I),{INVALID:_e,GONE:E,MISMATCH:ge,MOD_ERR:Be,SYNTAX:re,SECURITY:Ut,DISALLOWED:ze}=T,V=class{constructor(e,t){this.fileHandle=e,this.file=t,this.size=t.size,this.position=0}write(e){let t=this.file;if(typeof e=="object"){if(e.type==="write"){if(Number.isInteger(e.position)&&e.position>=0&&(this.position=e.position,this.size<e.position&&(this.file=new M([this.file,new ArrayBuffer(e.position-this.size)],this.file.name,this.file))),!("data"in e))throw new u(...re("write requires a data argument"));e=e.data}else if(e.type==="seek")if(Number.isInteger(e.position)&&e.position>=0){if(this.size<e.position)throw new u(..._e);this.position=e.position;return}else throw new u(...re("seek requires a position argument"));else if(e.type==="truncate")if(Number.isInteger(e.size)&&e.size>=0){t=e.size<this.size?new M([t.slice(0,e.size)],t.name,t):new M([t,new Uint8Array(e.size-this.size)],t.name),this.size=t.size,this.position>t.size&&(this.position=t.size),this.file=t;return}else throw new u(...re("truncate requires a size argument"))}e=new Ae([e]);let i=this.file,r=i.slice(0,this.position),o=i.slice(this.position+e.size),n=this.position-r.size;n<0&&(n=0),i=new M([r,new Uint8Array(n),e,o],i.name),this.size=i.size,this.position+=e.size,this.file=i}close(){if(this.fileHandle._deleted)throw new u(...E);this.fileHandle._file=this.file,this.file=this.position=this.size=null,this.fileHandle.onclose&&this.fileHandle.onclose(this.fileHandle)}},A=class{constructor(e="",t=new M([],e),i=!0){this._file=t,this.name=e,this.kind="file",this._deleted=!1,this.writable=i,this.readable=!0}async getFile(){if(this._deleted)throw new u(...E);return this._file}async createWritable(e){if(!this.writable)throw new u(...ze);if(this._deleted)throw new u(...E);let t=e.keepExistingData?await this.getFile():new M([],this.name);return new V(this,t)}async isSameEntry(e){return this===e}async _destroy(){this._deleted=!0,this._file=null}},_=class{constructor(e,t=!0){this.name=e,this.kind="directory",this._deleted=!1,this._entries={},this.writable=t,this.readable=!0}async*entries(){if(this._deleted)throw new u(...E);yield*Object.entries(this._entries)}async isSameEntry(e){return this===e}async getDirectoryHandle(e,t){if(this._deleted)throw new u(...E);let i=this._entries[e];if(i){if(i instanceof A)throw new u(...ge);return i}else{if(t.create)return this._entries[e]=new _(e);throw new u(...E)}}async getFileHandle(e,t){let i=this._entries[e],r=i instanceof A;if(i&&r)return i;if(i&&!r)throw new u(...ge);if(!i&&!t.create)throw new u(...E);if(!i&&t.create)return this._entries[e]=new A(e)}async removeEntry(e,t){let i=this._entries[e];if(!i)throw new u(...E);await i._destroy(t.recursive),delete this._entries[e]}async _destroy(e){for(let t of Object.values(this._entries)){if(!e)throw new u(...Be);await t._destroy(e)}this._entries={},this._deleted=!0}},Re=new _(""),We=()=>Re});var ne={};C(ne,{FileHandle:()=>O,FolderHandle:()=>S,default:()=>Oe});var qe,Y,O,S,Oe,oe=w(()=>{B();({DISALLOWED:qe}=T),Y=class{constructor(e,t){this.writer=e,this.fileEntry=t}async write(e){if(typeof e=="object"){if(e.type==="write"){if(Number.isInteger(e.position)&&e.position>=0&&(this.writer.seek(e.position),this.writer.position!==e.position&&(await new Promise((t,i)=>{this.writer.onwriteend=t,this.writer.onerror=i,this.writer.truncate(e.position)}),this.writer.seek(e.position))),!("data"in e))throw new DOMException("Failed to execute 'write' on 'UnderlyingSinkBase': Invalid params passed. write requires a data argument","SyntaxError");e=e.data}else if(e.type==="seek")if(Number.isInteger(e.position)&&e.position>=0){if(this.writer.seek(e.position),this.writer.position!==e.position)throw new DOMException("seeking position failed","InvalidStateError");return}else throw new DOMException("Failed to execute 'write' on 'UnderlyingSinkBase': Invalid params passed. seek requires a position argument","SyntaxError");else if(e.type==="truncate")return new Promise(t=>{if(Number.isInteger(e.size)&&e.size>=0)this.writer.onwriteend=i=>t(),this.writer.truncate(e.size);else throw new DOMException("Failed to execute 'write' on 'UnderlyingSinkBase': Invalid params passed. truncate requires a size argument","SyntaxError")})}await new Promise((t,i)=>{this.writer.onwriteend=t,this.writer.onerror=i,this.writer.write(new Blob([e]))})}close(){return new Promise(this.fileEntry.file.bind(this.fileEntry))}},O=class{constructor(e,t=!0){this.file=e,this.kind="file",this.writable=t,this.readable=!0}get name(){return this.file.name}isSameEntry(e){return this.file.toURL()===e.file.toURL()}getFile(){return new Promise(this.file.file.bind(this.file))}createWritable(e){if(!this.writable)throw new DOMException(...qe);return new Promise((t,i)=>this.file.createWriter(r=>{e.keepExistingData===!1?(r.onwriteend=o=>t(new Y(r,this.file)),r.truncate(0)):t(new Y(r,this.file))},i))}},S=class{constructor(e,t=!0){this.dir=e,this.writable=t,this.readable=!0,this.kind="directory",this.name=e.name}isSameEntry(e){return this.dir.fullPath===e.dir.fullPath}async*entries(){let e=this.dir.createReader(),t=await new Promise(e.readEntries.bind(e));for(let i of t)yield[i.name,i.isFile?new O(i,this.writable):new S(i,this.writable)]}getDirectoryHandle(e,t){return new Promise((i,r)=>{this.dir.getDirectory(e,t,o=>{i(new S(o))},r)})}getFileHandle(e,t){return new Promise((i,r)=>this.dir.getFile(e,t,o=>i(new O(o)),r))}async removeEntry(e,t){let i=await this.getDirectoryHandle(e,{create:!1}).catch(r=>r.name==="TypeMismatchError"?this.getFileHandle(e,{create:!1}):r);if(i instanceof Error)throw i;return new Promise((r,o)=>{i instanceof S?t.recursive?i.dir.removeRecursively(()=>r(),o):i.dir.remove(()=>r(),o):i.file&&i.file.remove(()=>r(),o)})}},Oe=(a={})=>new Promise((e,t)=>window.webkitRequestFileSystem(a._persistent,0,i=>e(new S(i.root)),t))});var x,Ne,Q,N,J=w(()=>{x=Symbol("adapter"),Q=class{constructor(e){v(this,Ne);v(this,"name");v(this,"kind");this.kind=e.kind,this.name=e.name,this[x]=e}async queryPermission({mode:e="read"}={}){let t=this[x];if(t.queryPermission)return t.queryPermission({mode:e});if(e==="read")return"granted";if(e==="readwrite")return t.writable?"granted":"denied";throw new TypeError(`Mode ${e} must be 'read' or 'readwrite'`)}async requestPermission({mode:e="read"}={}){let t=this[x];if(t.requestPermission)return t.requestPermission({mode:e});if(e==="read")return"granted";if(e==="readwrite")return t.writable?"granted":"denied";throw new TypeError(`Mode ${e} must be 'read' or 'readwrite'`)}async remove(e={}){await this[x].remove(e)}async isSameEntry(e){return this===e?!0:!e||typeof e!="object"||this.kind!==e.kind||!e[x]?!1:this[x].isSameEntry(e[x])}};Ne=x;Object.defineProperty(Q.prototype,Symbol.toStringTag,{value:"FileSystemHandle",writable:!1,enumerable:!1,configurable:!0});N=Q});var je,H,ae,se=w(()=>{G();({WritableStream:je}=I),H=class extends je{constructor(...e){super(...e),Object.setPrototypeOf(this,H.prototype),this._closed=!1}close(){this._closed=!0;let e=this.getWriter(),t=e.close();return e.releaseLock(),t}seek(e){return this.write({type:"seek",position:e})}truncate(e){return this.write({type:"truncate",size:e})}write(e){if(this._closed)return Promise.reject(new TypeError("Cannot write to a CLOSED writable stream"));let t=this.getWriter(),i=t.write(e);return t.releaseLock(),i}};Object.defineProperty(H.prototype,Symbol.toStringTag,{value:"FileSystemWritableFileStream",writable:!1,enumerable:!1,configurable:!0});Object.defineProperties(H.prototype,{close:{enumerable:!0},seek:{enumerable:!0},truncate:{enumerable:!0},write:{enumerable:!0}});ae=H});var k={};C(k,{FileSystemFileHandle:()=>z,default:()=>ve});var Z,Ue,z,ve,F=w(()=>{J();se();Z=Symbol("adapter"),z=class extends N{constructor(t){super(t);v(this,Ue);this[Z]=t}async createWritable(t={}){return new ae(await this[Z].createWritable(t))}async getFile(){return this[Z].getFile()}};Ue=Z;Object.defineProperty(z.prototype,Symbol.toStringTag,{value:"FileSystemFileHandle",writable:!1,enumerable:!1,configurable:!0});Object.defineProperties(z.prototype,{createWritable:{enumerable:!0},getFile:{enumerable:!0}});ve=z});var ee={};C(ee,{FileSystemDirectoryHandle:()=>b,default:()=>Ee});var L,Ke,b,Ee,j=w(()=>{J();L=Symbol("adapter"),b=class extends N{constructor(t){super(t);v(this,Ke);this[L]=t}async getDirectoryHandle(t,i={}){if(t==="")throw new TypeError("Name can't be an empty string.");if(t==="."||t===".."||t.includes("/"))throw new TypeError("Name contains invalid characters.");i.create=!!i.create;let r=await this[L].getDirectoryHandle(t,i);return new b(r)}async*entries(){let{FileSystemFileHandle:t}=await Promise.resolve().then(()=>(F(),k));for await(let[i,r]of this[L].entries())yield[r.name,r.kind==="file"?new t(r):new b(r)]}async*getEntries(){let{FileSystemFileHandle:t}=await Promise.resolve().then(()=>(F(),k));console.warn("deprecated, use .entries() instead");for await(let i of this[L].entries())yield i.kind==="file"?new t(i):new b(i)}async getFileHandle(t,i={}){let{FileSystemFileHandle:r}=await Promise.resolve().then(()=>(F(),k));if(t==="")throw new TypeError("Name can't be an empty string.");if(t==="."||t===".."||t.includes("/"))throw new TypeError("Name contains invalid characters.");i.create=!!i.create;let o=await this[L].getFileHandle(t,i);return new r(o)}async removeEntry(t,i={}){if(t==="")throw new TypeError("Name can't be an empty string.");if(t==="."||t===".."||t.includes("/"))throw new TypeError("Name contains invalid characters.");return i.recursive=!!i.recursive,this[L].removeEntry(t,i)}async resolve(t){if(await t.isSameEntry(this))return[];let i=[{handle:this,path:[]}];for(;i.length;){let{handle:r,path:o}=i.pop();for await(let n of r.values()){if(await n.isSameEntry(t))return[...o,n.name];n.kind==="directory"&&i.push({handle:n,path:[...o,n.name]})}}return null}async*keys(){for await(let[t]of this[L].entries())yield t}async*values(){for await(let[t,i]of this)yield i}[(Ke=L,Symbol.asyncIterator)](){return this.entries()}};Object.defineProperty(b.prototype,Symbol.toStringTag,{value:"FileSystemDirectoryHandle",writable:!1,enumerable:!1,configurable:!0});Object.defineProperties(b.prototype,{getDirectoryHandle:{enumerable:!0},entries:{enumerable:!0},getFileHandle:{enumerable:!0},removeEntry:{enumerable:!0}});Ee=b});var le={};C(le,{config:()=>Ge,errors:()=>T,fromDataTransfer:()=>Ve,getDirHandlesFromInput:()=>$e,getFileHandlesFromInput:()=>Xe});async function Ve(a){console.warn("deprecated fromDataTransfer - use `dt.items[0].getAsFileSystemHandle()` instead");let[e,t,i]=await Promise.all([Promise.resolve().then(()=>(X(),$)),Promise.resolve().then(()=>(oe(),ne)),Promise.resolve().then(()=>(j(),ee))]),r=new e.FolderHandle("",!1);return r._entries=a.map(o=>o.isFile?new t.FileHandle(o,!1):new t.FolderHandle(o,!1)),new i.FileSystemDirectoryHandle(r)}async function $e(a){let{FolderHandle:e,FileHandle:t}=await Promise.resolve().then(()=>(X(),$)),{FileSystemDirectoryHandle:i}=await Promise.resolve().then(()=>(j(),ee)),r=Array.from(a.files),o=r[0].webkitRelativePath.split("/",1)[0],n=new e(o,!1);return r.forEach(l=>{let c=l.webkitRelativePath.split("/");c.shift();let d=c.pop(),h=c.reduce((m,s)=>(m._entries[s]||(m._entries[s]=new e(s,!1)),m._entries[s]),n);h._entries[d]=new t(l.name,l,!1)}),new i(n)}async function Xe(a){let{FileHandle:e}=await Promise.resolve().then(()=>(X(),$)),{FileSystemFileHandle:t}=await Promise.resolve().then(()=>(F(),k));return Array.from(a.files).map(i=>new t(new e(i.name,i,!1)))}var T,Ge,B=w(()=>{T={INVALID:["seeking position failed.","InvalidStateError"],GONE:["A requested file or directory could not be found at the time an operation was processed.","NotFoundError"],MISMATCH:["The path supplied exists, but was not an entry of requested type.","TypeMismatchError"],MOD_ERR:["The object can not be modified in this way.","InvalidModificationError"],SYNTAX:a=>[`Failed to execute 'write' on 'UnderlyingSinkBase': Invalid params passed. ${a}`,"SyntaxError"],SECURITY:["It was determined that certain files are unsafe for access within a Web application, or that too many calls are being made on file resources.","SecurityError"],DISALLOWED:["The request is not allowed by the user agent or the platform in the current context.","NotAllowedError"]},Ge={writable:globalThis.WritableStream}});var Te={};C(Te,{FileHandle:()=>pe});var Fe,Le,Ze,Pe,et,tt,pe,it,rt,nt,ot,at,ue,me,He=w(()=>{B();G();({WritableStream:Fe,TransformStream:Le,DOMException:Ze,Blob:Pe}=I),{GONE:et}=T,tt=/constructor/i.test(window.HTMLElement)||window.safari||window.WebKitPoint,pe=class{constructor(e="unkown"){this.name=e,this.kind="file"}async getFile(){throw new Ze(...et)}async isSameEntry(e){return this===e}async createWritable(e={}){var n;let t=await((n=navigator.serviceWorker)==null?void 0:n.getRegistration()),i=document.createElement("a"),r=new Le,o=r.writable;if(i.download=this.name,tt||!t){let l=[];r.readable.pipeTo(new Fe({write(c){l.push(new Pe([c]))},close(){let c=new Pe(l,{type:"application/octet-stream; charset=utf-8"});l=[],i.href=URL.createObjectURL(c),i.click(),setTimeout(()=>URL.revokeObjectURL(i.href),1e4)}}))}else{let{writable:l,readablePort:c}=new me(Fe),d=encodeURIComponent(this.name).replace(/['()]/g,escape).replace(/\*/g,"%2A"),h={"content-disposition":"attachment; filename*=UTF-8''"+d,"content-type":"application/octet-stream; charset=utf-8",...e.size?{"content-length":e.size}:{}},m=setTimeout(()=>t.active.postMessage(0),1e4);r.readable.pipeThrough(new Le({transform(p,y){if(p instanceof Uint8Array)return y.enqueue(p);let g=new Response(p).body.getReader(),R=lt=>g.read().then(ye=>ye.done?0:R(y.enqueue(ye.value)));return R()}})).pipeTo(l).finally(()=>{clearInterval(m)}),t.active.postMessage({url:t.scope+d,headers:h,readablePort:c},[c]);let s=document.createElement("iframe");s.hidden=!0,s.src=t.scope+d,document.body.appendChild(s)}return o.getWriter()}},it=0,rt=0,nt=1,ot=1,at=2,ue=class{constructor(e){e.onmessage=t=>this._onMessage(t.data),this._port=e,this._resetReady()}start(e){return this._controller=e,this._readyPromise}write(e){let t={type:it,chunk:e};return this._port.postMessage(t,[e.buffer]),this._resetReady(),this._readyPromise}close(){this._port.postMessage({type:at}),this._port.close()}abort(e){this._port.postMessage({type:ot,reason:e}),this._port.close()}_onMessage(e){e.type===rt&&this._resolveReady(),e.type===nt&&this._onError(e.reason)}_onError(e){this._controller.error(e),this._rejectReady(e),this._port.close()}_resetReady(){this._readyPromise=new Promise((e,t)=>{this._readyResolve=e,this._readyReject=t}),this._readyPending=!0}_resolveReady(){this._readyResolve(),this._readyPending=!1}_rejectReady(e){this._readyPending||this._resetReady(),this._readyPromise.catch(()=>{}),this._readyReject(e),this._readyPending=!1}},me=class{constructor(e){let t=new MessageChannel;this.readablePort=t.port1,this.writable=new e(new ue(t.port2))}}});var te=class{constructor(e){this.database=e}openStore(e,t){return this.database.transaction(e,t).objectStore(e)}async put(e,t,i){let r=this.openStore(e,"readwrite");return await new Promise((o,n)=>{let l=r.put(t,i);l.onsuccess=()=>{o(l.result)},l.onerror=()=>{n(l.error)}})}get(e,t){let i=this.openStore(e,"readonly");return new Promise((r,o)=>{let n=i.get(t);n.onsuccess=()=>{r(n.result)},n.onerror=()=>{o(n.error)}})}async delete(e,t){let i=this.openStore(e,"readwrite");return await new Promise((r,o)=>{let n=i.delete(t);n.onsuccess=()=>{r()},n.onerror=()=>{o(n.error)}})}close(){this.database.close()}},ie=class{constructor(e,t){this.databaseName=e;this.objectStores=t}async connect(){let e=window.indexedDB.open(this.databaseName,1);return e.onupgradeneeded=t=>{let i=t.target.result;this.objectStores.forEach(r=>{i.createObjectStore(r)})},await new Promise((t,i)=>{e.onsuccess=r=>{t(new te(r.target.result))},e.onerror=r=>{i(r.target.error)}})}},D="fileBookmarks",W=new ie("AvaloniaDb",[D]);var U=class{static getCaretCoordinates(e,t,i){var m,s;if(!we)throw new Error("textarea-caret-position#getCaretCoordinates should only be called in a browser");let r=(m=i==null?void 0:i.debug)!=null?m:!1;if(r){let p=document.querySelector("#input-textarea-caret-position-mirror-div");p&&((s=p.parentNode)==null||s.removeChild(p))}let o=document.createElement("div");o.id="input-textarea-caret-position-mirror-div",document.body.appendChild(o);let n=o.style,l=window.getComputedStyle?window.getComputedStyle(e):e.currentStyle,c=e.nodeName==="INPUT";n.whiteSpace="pre-wrap",c||(n.wordWrap="break-word"),n.position="absolute",r||(n.visibility="hidden"),De.forEach(p=>{if(c&&p==="lineHeight")if(l.boxSizing==="border-box"){let y=parseInt(l.height),g=parseInt(l.paddingTop)+parseInt(l.paddingBottom)+parseInt(l.borderTopWidth)+parseInt(l.borderBottomWidth),R=g+parseInt(l.lineHeight);y>R?n.lineHeight=`${y-g}px`:y===R?n.lineHeight=l.lineHeight:n.lineHeight="0"}else n.lineHeight=l.height;else n[p]=l[p]}),Ie?e.scrollHeight>parseInt(l.height)&&(n.overflowY="scroll"):n.overflow="hidden",o.textContent=e.value.substring(0,t),c&&(o.textContent=o.textContent.replace(/\s/g,"\xA0"));let d=document.createElement("span");d.textContent=e.value.substring(t)||".",o.appendChild(d);let h={top:d.offsetTop+parseInt(l.borderTopWidth),left:d.offsetLeft+parseInt(l.borderLeftWidth),height:parseInt(l.lineHeight)};return r?d.style.backgroundColor="#aaa":document.body.removeChild(o),h}},De=["direction","boxSizing","width","height","overflowX","overflowY","borderTopWidth","borderRightWidth","borderBottomWidth","borderLeftWidth","borderStyle","paddingTop","paddingRight","paddingBottom","paddingLeft","fontStyle","fontVariant","fontWeight","fontStretch","fontSize","fontSizeAdjust","lineHeight","fontFamily","textAlign","textTransform","textIndent","textDecoration","letterSpacing","wordSpacing","tabSize","MozTabSize"],we=typeof window!="undefined",Ie=we&&window.mozInnerScreenX!=null;var K=class{static initializeBackgroundHandlers(){this.clipboardState===0&&(globalThis.addEventListener("paste",e=>{this.clipboardState===2&&this.resolveClipboard(e.clipboardData.getData("text"))}),this.clipboardState=1)}static async readClipboardText(){if(globalThis.navigator.clipboard.readText)return await globalThis.navigator.clipboard.readText();try{return await new Promise((e,t)=>{this.clipboardState=2,this.resolveClipboard=e,this.rejectClipboard=t})}finally{this.clipboardState=1,this.resolveClipboard=null,this.rejectClipboard=null}}static subscribeKeyEvents(e,t,i){let r=n=>{t(n.code,n.key,this.getModifiers(n))&&this.clipboardState!==2&&n.preventDefault()};e.addEventListener("keydown",r);let o=n=>{i(n.code,n.key,this.getModifiers(n))&&n.preventDefault(),this.rejectClipboard&&this.rejectClipboard()};return e.addEventListener("keyup",o),()=>{e.removeEventListener("keydown",r),e.removeEventListener("keyup",o)}}static subscribeTextEvents(e,t,i,r,o,n){let l=s=>{let p=s;i(p.type,p.data)&&s.preventDefault()};e.addEventListener("input",l);let c=s=>{r(s)&&s.preventDefault()};e.addEventListener("compositionstart",c);let d=s=>{let p=s.getTargetRanges(),y=-1,g=-1;p.length>0&&(y=p[0].startOffset,g=p[0].endOffset),s.inputType==="insertCompositionText"&&(y=2,g=y+2),t(s,y,g)&&s.preventDefault()};e.addEventListener("beforeinput",d);let h=s=>{o(s)&&s.preventDefault()};e.addEventListener("compositionupdate",h);let m=s=>{n(s)&&s.preventDefault()};return e.addEventListener("compositionend",m),()=>{e.removeEventListener("input",l),e.removeEventListener("compositionstart",c),e.removeEventListener("compositionupdate",h),e.removeEventListener("compositionend",m)}}static subscribePointerEvents(e,t,i,r,o,n){let l=s=>{t(s),s.preventDefault()},c=s=>{i(s),s.preventDefault()},d=s=>{r(s),s.preventDefault()},h=s=>{o(s),s.preventDefault()},m=s=>{n(s),s.preventDefault()};return e.addEventListener("pointermove",l),e.addEventListener("pointerdown",c),e.addEventListener("pointerup",d),e.addEventListener("wheel",m),e.addEventListener("pointercancel",h),()=>{e.removeEventListener("pointerover",l),e.removeEventListener("pointerdown",c),e.removeEventListener("pointerup",d),e.removeEventListener("pointercancel",h),e.removeEventListener("wheel",m)}}static subscribeInputEvents(e,t){let i=r=>{t(r.value)&&r.preventDefault()};return e.addEventListener("input",i),()=>{e.removeEventListener("input",i)}}static subscribeDropEvents(e,t){let i=r=>{t(r)&&r.preventDefault()};return e.addEventListener("dragover",i),e.addEventListener("dragenter",i),e.addEventListener("dragleave",i),e.addEventListener("drop",i),()=>{e.removeEventListener("dragover",i),e.removeEventListener("dragenter",i),e.removeEventListener("dragleave",i),e.removeEventListener("drop",i)}}static getCoalescedEvents(e){return e.getCoalescedEvents()}static clearInput(e){e.value=""}static focusElement(e){e.focus()}static setCursor(e,t){t==="default"?e.style.removeProperty("cursor"):e.style.cursor=t}static setBounds(e,t,i,r,o,n){e.style.left=t.toFixed(0)+"px",e.style.top=i.toFixed(0)+"px";let{left:l,top:c}=U.getCaretCoordinates(e,n);e.style.left=(t-l).toFixed(0)+"px",e.style.top=(i-c).toFixed(0)+"px"}static hide(e){e.style.display="none"}static show(e){e.style.display="block"}static setSurroundingText(e,t,i,r){!e||(e.value=t,e.setSelectionRange(i,r),e.style.width="20px",e.style.width=`${e.scrollWidth}px`)}static getModifiers(e){let t=0;return e.ctrlKey&&(t|=2),e.altKey&&(t|=1),e.shiftKey&&(t|=4),e.metaKey&&(t|=8),t}};K.clipboardState=0;var P=class{static hasNativeFilePicker(){return"showSaveFilePicker"in globalThis}static isMobile(){var o;let e=(o=globalThis.navigator)==null?void 0:o.userAgentData;if(e)return e.mobile;let t=navigator.userAgent,i=/(android|bb\d+|meego).+mobile|avantgo|bada\/|blackberry|blazer|compal|elaine|fennec|hiptop|iemobile|ip(hone|od)|iris|kindle|lge |maemo|midp|mmp|mobile.+firefox|netfront|opera m(ob|in)i|palm( os)?|phone|p(ixi|re)\/|plucker|pocket|psp|series(4|6)0|symbian|treo|up\.(browser|link)|vodafone|wap|windows ce|xda|xiino/i,r=/1207|6310|6590|3gso|4thp|50[1-6]i|770s|802s|a wa|abac|ac(er|oo|s)|ai(ko|rn)|al(av|ca|co)|amoi|an(ex|ny|yw)|aptu|ar(ch|go)|as(te|us)|attw|au(di|m|r |s )|avan|be(ck|ll|nq)|bi(lb|rd)|bl(ac|az)|br(e|v)w|bumb|bw(n|u)|c55\/|capi|ccwa|cdm|cell|chtm|cldc|cmd|co(mp|nd)|craw|da(it|ll|ng)|dbte|dcs|devi|dica|dmob|do(c|p)o|ds(12|d)|el(49|ai)|em(l2|ul)|er(ic|k0)|esl8|ez([4-7]0|os|wa|ze)|fetc|fly(|_)|g1 u|g560|gene|gf5|gmo|go(\.w|od)|gr(ad|un)|haie|hcit|hd(m|p|t)|hei|hi(pt|ta)|hp( i|ip)|hsc|ht(c(| |_|a|g|p|s|t)|tp)|hu(aw|tc)|i(20|go|ma)|i230|iac( ||\/)|ibro|idea|ig01|ikom|im1k|inno|ipaq|iris|ja(t|v)a|jbro|jemu|jigs|kddi|keji|kgt( |\/)|klon|kpt |kwc|kyo(c|k)|le(no|xi)|lg( g|\/(k|l|u)|50|54|[a-w])|libw|lynx|m1w|m3ga|m50\/|ma(te|ui|xo)|mc(01|21|ca)|mcr|me(rc|ri)|mi(o8|oa|ts)|mmef|mo(01|02|bi|de|do|t(| |o|v)|zz)|mt(50|p1|v )|mwbp|mywa|n10[0-2]|n20[2-3]|n30(0|2)|n50(0|2|5)|n7(0(0|1)|10)|ne((c|m)|on|tf|wf|wg|wt)|nok(6|i)|nzph|o2im|op(ti|wv)|oran|owg1|p800|pan(a|d|t)|pdxg|pg(13|([1-8]|c))|phil|pire|pl(ay|uc)|pn2|po(ck|rt|se)|prox|psio|ptg|qaa|qc(07|12|21|32|60|[2-7]|i)|qtek|r380|r600|raks|rim9|ro(ve|zo)|s55\/|sa(ge|ma|mm|ms|ny|va)|sc(01|h|oo|p)|sdk\/|se(c(|0|1)|47|mc|nd|ri)|sgh|shar|sie(|m)|sk0|sl(45|id)|sm(al|ar|b3|it|t5)|so(ft|ny)|sp(01|h|v|v )|sy(01|mb)|t2(18|50)|t6(00|10|18)|ta(gt|lk)|tcl|tdg|tel(i|m)|tim|tmo|to(pl|sh)|ts(70|m|m3|m5)|tx9|up(\.b|g1|si)|utst|v400|v750|veri|vi(rg|te)|vk(40|5[0-3]|v)|vm40|voda|vulc|vx(52|53|60|61|70|80|81|83|85|98)|w3c(| )|webc|whit|wi(g |nc|nw)|wmlb|wonu|x700|yas|your|zeto|zte/i;return i.test(t)||r.test(t.substr(0,4))}};var f=class{constructor(e,t,i,r){this.handle=e;this.file=t;this.bookmarkId=i;this.wellKnownType=r}get name(){var e;return this.handle?this.handle.name:this.file?this.file.name:(e=this.wellKnownType)!=null?e:""}get kind(){return this.handle?this.handle.kind:this.file?"file":"directory"}static createFromHandle(e,t){return new f(e,void 0,t,void 0)}static createFromFile(e){return new f(void 0,e,void 0,void 0)}static createWellKnownDirectory(e){return new f(void 0,void 0,void 0,e)}static async openRead(e){if(e.file)return e.file;if(!e.handle||e.kind!=="file")throw new Error("StorageItem is not a file");return await e.verityPermissions("read"),await e.handle.getFile()}static async openWrite(e){if(!e.handle||e.kind!=="file")throw new Error("StorageItem is not a writeable file");return await e.verityPermissions("readwrite"),await e.handle.createWritable({keepExistingData:!0})}static async getProperties(e){try{let t=e.handle&&"getFile"in e.handle?await e.handle.getFile():e.file;return t?{Size:t.size,LastModified:t.lastModified,Type:t.type}:null}catch(t){return null}}static getItemsIterator(e){return e.kind!=="directory"||!e.handle?null:e.handle.entries()}static async createFile(e,t){if(e.kind!=="directory"||!e.handle)throw new TypeError("Unable to create item in the requested directory");return await e.verityPermissions("readwrite"),await e.handle.getFileHandle(t,{create:!0})}static async createFolder(e,t){if(e.kind!=="directory"||!e.handle)throw new TypeError("Unable to create item in the requested directory");return await e.verityPermissions("readwrite"),await e.handle.getDirectoryHandle(t,{create:!0})}static async deleteAsync(e){return e.handle?(await e.verityPermissions("readwrite"),await e.handle.remove({recursive:!0})):null}static async moveAsync(e,t){if(!e.handle)return null;if(t.kind!=="directory"||!t.handle)throw new TypeError("Unable to move item to the requested directory");return await e.verityPermissions("readwrite"),await e.handle.move(t)}async verityPermissions(e){if(!!this.handle&&!!P.hasNativeFilePicker()&&await this.handle.queryPermission({mode:e})!=="granted"&&await this.handle.requestPermission({mode:e})==="denied")throw new Error("Permissions denied")}static async saveBookmark(e){if(e.bookmarkId)return e.bookmarkId;if(!e.handle||!P.hasNativeFilePicker())return null;let t=await W.connect();try{return await t.put(D,e.handle,e.generateBookmarkId())}finally{t.close()}}static async deleteBookmark(e){if(!e.bookmarkId||!P.hasNativeFilePicker())return;let t=await W.connect();try{await t.delete(D,e.bookmarkId)}finally{t.close()}}generateBookmarkId(){return Date.now().toString(36)+Math.random().toString(36).substring(2)}},q=class{constructor(e){this.items=e}static itemsArray(e){return e.items}static filesToItemsArray(e){if(!e)return[];let t=[];for(let i=0;i<e.length;i++)t[i]=f.createFromFile(e[i]);return t}};var Se=globalThis.showDirectoryPicker;async function Ye(a={}){if(Se&&!a._preferPolyfill)return Se(a);let e=document.createElement("input");if(e.type="file",!("webkitdirectory"in e))throw new Error("HTMLInputElement.webkitdirectory is not supported");e.style.position="fixed",e.style.top="-100000px",e.style.left="-100000px",document.body.appendChild(e),e.webkitdirectory=!0;let t=Promise.resolve().then(()=>(B(),le));return await new Promise(i=>{e.addEventListener("change",i),e.click()}),t.then(i=>i.getDirHandlesFromInput(e))}var ce=Ye;var Qe={accepts:[]},xe=globalThis.showOpenFilePicker;async function Je(a={}){let e={...Qe,...a};if(xe&&!a._preferPolyfill)return xe(e);let t=document.createElement("input");t.type="file",t.multiple=e.multiple,t.accept=(e.accepts||[]).map(r=>[...(r.extensions||[]).map(o=>"."+o),...r.mimeTypes||[]]).flat().join(","),t.style.position="fixed",t.style.top="-100000px",t.style.left="-100000px",document.body.appendChild(t);let i=Promise.resolve().then(()=>(B(),le));return await new Promise(r=>{t.addEventListener("change",r),t.click()}),i.then(r=>r.getFileHandlesFromInput(t))}var de=Je;var ke=globalThis.showSaveFilePicker;async function st(a={}){if(ke&&!a._preferPolyfill)return ke(a);a._name&&(console.warn("deprecated _name, spec now have `suggestedName`"),a.suggestedName=a._name);let{FileSystemFileHandle:e}=await Promise.resolve().then(()=>(F(),k)),{FileHandle:t}=await Promise.resolve().then(()=>(He(),Te));return new e(new t(a.suggestedName))}var he=st;globalThis.DataTransferItem&&!DataTransferItem.prototype.getAsFileSystemHandle&&(DataTransferItem.prototype.getAsFileSystemHandle=async function(){let a=this.webkitGetAsEntry(),[{FileHandle:e,FolderHandle:t},{FileSystemDirectoryHandle:i},{FileSystemFileHandle:r}]=await Promise.all([Promise.resolve().then(()=>(oe(),ne)),Promise.resolve().then(()=>(j(),ee)),Promise.resolve().then(()=>(F(),k))]);return a.isFile?new r(new e(a,!1)):new i(new t(a,!1))});j();F();J();se();var fe=class{static async selectFolderDialog(e,t){var o,n;let i={startIn:(n=(o=e==null?void 0:e.wellKnownType)!=null?o:e==null?void 0:e.handle)!=null?n:void 0,_preferPolyfill:t},r=await ce(i);return f.createFromHandle(r)}static async openFileDialog(e,t,i,r,o){var c,d;let n={startIn:(d=(c=e==null?void 0:e.wellKnownType)!=null?c:e==null?void 0:e.handle)!=null?d:void 0,multiple:t,excludeAcceptAllOption:r,types:i!=null?i:void 0,_preferPolyfill:o},l=await de(n);return new q(l.map(h=>f.createFromHandle(h)))}static async saveFileDialog(e,t,i,r,o){var c,d;let n={startIn:(d=(c=e==null?void 0:e.wellKnownType)!=null?c:e==null?void 0:e.handle)!=null?d:void 0,suggestedName:t!=null?t:void 0,excludeAcceptAllOption:r,types:i!=null?i:void 0,_preferPolyfill:o},l=await he(n);return f.createFromHandle(l)}static async openBookmark(e){let t=await W.connect();try{let i=await t.get(D,e);return i&&f.createFromHandle(i,e)}finally{t.close()}}static createAcceptType(e,t,i){let r={};return t.forEach(o=>{r[o]=i!=null?i:[]}),{description:e,accept:r}}};export{f as StorageItem,q as StorageItems,fe as StorageProvider};
//# sourceMappingURL=storage.js.map