"use strict";(self.webpackChunk_jupyter_shared_docprovider_extension=self.webpackChunk_jupyter_shared_docprovider_extension||[]).push([[3,516],{198:(e,t,s)=>{s.d(t,{HT:()=>r,cy:()=>o});const r=Array.from,o=Array.isArray},489:(e,t,s)=>{s.d(t,{vt:()=>r});const r=e=>new Error(e)},505:(e,t,s)=>{s.d(t,{Tj:()=>n,_4:()=>o,vt:()=>r});const r=()=>new Map,o=(e,t,s)=>{let r=e.get(t);return void 0===r&&e.set(t,r=s()),r},n=(e,t)=>{const s=[];for(const[r,o]of e)s.push(t(o,r));return s}},370:(e,t,s)=>{s.d(t,{W:()=>i,c:()=>d});var r=s(505),o=s(279),n=s(198);class i{constructor(){this._observers=r.vt()}on(e,t){return r._4(this._observers,e,o.vt).add(t),t}once(e,t){const s=(...r)=>{this.off(e,s),t(...r)};this.on(e,s)}off(e,t){const s=this._observers.get(e);void 0!==s&&(s.delete(t),0===s.size&&this._observers.delete(e))}emit(e,t){return n.HT((this._observers.get(e)||r.vt()).values()).forEach((e=>e(...t)))}destroy(){this._observers=r.vt()}}class d{constructor(){this._observers=r.vt()}on(e,t){r._4(this._observers,e,o.vt).add(t)}once(e,t){const s=(...r)=>{this.off(e,s),t(...r)};this.on(e,s)}off(e,t){const s=this._observers.get(e);void 0!==s&&(s.delete(t),0===s.size&&this._observers.delete(e))}emit(e,t){return n.HT((this._observers.get(e)||r.vt()).values()).forEach((e=>e(...t)))}destroy(){this._observers=r.vt()}}},706:(e,t,s)=>{s.d(t,{hd:()=>n,ku:()=>o,vt:()=>r});const r=e=>new Promise(e),o=(Promise.all.bind(Promise),e=>Promise.reject(e)),n=e=>Promise.resolve(e)},279:(e,t,s)=>{s.d(t,{vt:()=>r});const r=()=>new Set},516:(e,t,s)=>{s.d(t,{nS:()=>p});var r=s(206),o=s(706),n=s(489);const i=e=>o.vt(((t,s)=>{e.onerror=e=>s(new Error(e.target.error)),e.onsuccess=e=>t(e.target.result)})),d=(e,t,s="readwrite")=>{const r=e.transaction(t,s);return t.map((e=>_(r,e)))},h=(e,t)=>i(e.count(t)),c=(e,t)=>i(e.delete(t)),u=(e,t)=>i(e.add(t)),a=(e,t,s,r="next")=>((e,t)=>o.vt(((s,r)=>{e.onerror=r,e.onsuccess=async e=>{const r=e.target.result;if(null===r||!1===await t(r))return s();r.continue()}})))(e.openKeyCursor(t,r),(e=>s(e.key))),_=(e,t)=>e.objectStore(t);var l=s(370);const v="custom",b="updates",y=(e,t=()=>{},s=()=>{})=>{const[o]=d(e.db,[b]);return(n=o,_=e._dbref,c=IDBKeyRange.lowerBound(_,!1),i(n.getAll(c,u))).then((n=>{e._destroyed||(t(o),r.transact(e.doc,(()=>{n.forEach((t=>r.applyUpdate(e.doc,t)))}),e,!1),s(o))})).then((()=>((e,t=null)=>((e,t,s)=>{let r=null;return a(e,t,(e=>(r=e,!1)),s).then((()=>r))})(e,t,"prev"))(o).then((t=>{e._dbref=t+1})))).then((()=>h(o).then((t=>{e._dbsize=t})))).then((()=>o));var n,c,u,_};class p extends l.c{constructor(e,t){super(),this.doc=t,this.name=e,this._dbref=0,this._dbsize=0,this._destroyed=!1,this.db=null,this.synced=!1,this._db=(e=>o.vt(((t,s)=>{const r=indexedDB.open(e);r.onupgradeneeded=e=>(e=>[["updates",{autoIncrement:!0}],["custom"]].forEach((t=>e.createObjectStore.apply(e,t))))(e.target.result),r.onerror=e=>s(n.vt(e.target.error)),r.onsuccess=e=>{const s=e.target.result;s.onversionchange=()=>{s.close()},t(s)}})))(e),this.whenSynced=o.vt((e=>this.on("synced",(()=>e(this))))),this._db.then((e=>{this.db=e,y(this,(e=>u(e,r.encodeStateAsUpdate(t))),(()=>{if(this._destroyed)return this;this.synced=!0,this.emit("synced",[this])}))})),this._storeTimeout=1e3,this._storeTimeoutId=null,this._storeUpdate=(e,t)=>{if(this.db&&t!==this){const[t]=d(this.db,[b]);u(t,e),++this._dbsize>=500&&(null!==this._storeTimeoutId&&clearTimeout(this._storeTimeoutId),this._storeTimeoutId=setTimeout((()=>{((e,t=!0)=>{y(e).then((s=>{(t||e._dbsize>=500)&&u(s,r.encodeStateAsUpdate(e.doc)).then((()=>{return c(s,(t=e._dbref,IDBKeyRange.upperBound(t,!0)));var t})).then((()=>h(s).then((t=>{e._dbsize=t}))))}))})(this,!1),this._storeTimeoutId=null}),this._storeTimeout))}},t.on("update",this._storeUpdate),this.destroy=this.destroy.bind(this),t.on("destroy",this.destroy)}destroy(){return this._storeTimeoutId&&clearTimeout(this._storeTimeoutId),this.doc.off("update",this._storeUpdate),this.doc.off("destroy",this.destroy),this._destroyed=!0,this._db.then((e=>{e.close()}))}clearData(){return this.destroy().then((()=>{var e;e=this.name,i(indexedDB.deleteDatabase(e))}))}get(e){return this._db.then((t=>{const[s]=d(t,[v],"readonly");return((e,t)=>i(e.get(t)))(s,e)}))}set(e,t){return this._db.then((s=>{const[r]=d(s,[v]);return((e,t,s)=>i(e.put(t,s)))(r,t,e)}))}del(e){return this._db.then((t=>{const[s]=d(t,[v]);return c(s,e)}))}}}}]);