3 lines
3.3 KiB
JavaScript
3 lines
3.3 KiB
JavaScript
try{self["workbox:window:7.3.0"]&&_()}catch(t){}function t(t,s){return new Promise((i=>{const e=new MessageChannel;e.port1.onmessage=t=>{i(t.data)},t.postMessage(s,[e.port2])}))}try{self["workbox:core:7.3.0"]&&_()}catch(t){}class s{constructor(){this.promise=new Promise(((t,s)=>{this.resolve=t,this.reject=s}))}}class i{constructor(){this.Pt=new Map}addEventListener(t,s){this.Wt(t).add(s)}removeEventListener(t,s){this.Wt(t).delete(s)}dispatchEvent(t){t.target=this;const s=this.Wt(t.type);for(const i of s)i(t)}Wt(t){return this.Pt.has(t)||this.Pt.set(t,new Set),this.Pt.get(t)}}function e(t,s){const{href:i}=location;return new URL(t,i).href===new URL(s,i).href}class h{constructor(t,s){this.type=t,Object.assign(this,s)}}const n={type:"SKIP_WAITING"};class a extends i{constructor(t,i={}){super(),this._t={},this.Lt=0,this.Ct=new s,this.Tt=new s,this.Ut=new s,this.Mt=0,this.Gt=new Set,this.Kt=()=>{const t=this.Nt,s=t.installing;this.Lt>0||!e(s.scriptURL,this.Ot.toString())||performance.now()>this.Mt+6e4?(this.zt=s,t.removeEventListener("updatefound",this.Kt)):(this.Ft=s,this.Gt.add(s),this.Ct.resolve(s)),++this.Lt,s.addEventListener("statechange",this.Ht)},this.Ht=t=>{const s=this.Nt,i=t.target,{state:e}=i,n=i===this.zt,a={sw:i,isExternal:n,originalEvent:t};!n&&this.Jt&&(a.isUpdate=!0),this.dispatchEvent(new h(e,a)),"installed"===e?this.Qt=self.setTimeout((()=>{"installed"===e&&s.waiting===i&&this.dispatchEvent(new h("waiting",a))}),200):"activating"===e&&(clearTimeout(this.Qt),n||this.Tt.resolve(i))},this.Vt=t=>{const s=this.Ft,i=s!==navigator.serviceWorker.controller;this.dispatchEvent(new h("controlling",{isExternal:i,originalEvent:t,sw:s,isUpdate:this.Jt})),i||this.Ut.resolve(s)},this.Xt=async t=>{const{data:s,ports:i,source:e}=t;await this.getSW(),this.Gt.has(e)&&this.dispatchEvent(new h("message",{data:s,originalEvent:t,ports:i,sw:e}))},this.Ot=t,this._t=i,navigator.serviceWorker.addEventListener("message",this.Xt)}async register({immediate:t=!1}={}){t||"complete"===document.readyState||await new Promise((t=>window.addEventListener("load",t))),this.Jt=Boolean(navigator.serviceWorker.controller),this.Yt=this.Zt(),this.Nt=await this.$t(),this.Yt&&(this.Ft=this.Yt,this.Tt.resolve(this.Yt),this.Ut.resolve(this.Yt),this.Yt.addEventListener("statechange",this.Ht,{once:!0}));const s=this.Nt.waiting;return s&&e(s.scriptURL,this.Ot.toString())&&(this.Ft=s,Promise.resolve().then((()=>{this.dispatchEvent(new h("waiting",{sw:s,wasWaitingBeforeRegister:!0}))})).then((()=>{}))),this.Ft&&(this.Ct.resolve(this.Ft),this.Gt.add(this.Ft)),this.Nt.addEventListener("updatefound",this.Kt),navigator.serviceWorker.addEventListener("controllerchange",this.Vt),this.Nt}async update(){this.Nt&&await this.Nt.update()}get active(){return this.Tt.promise}get controlling(){return this.Ut.promise}getSW(){return void 0!==this.Ft?Promise.resolve(this.Ft):this.Ct.promise}async messageSW(s){return t(await this.getSW(),s)}messageSkipWaiting(){this.Nt&&this.Nt.waiting&&t(this.Nt.waiting,n)}Zt(){const t=navigator.serviceWorker.controller;return t&&e(t.scriptURL,this.Ot.toString())?t:void 0}async $t(){try{const t=await navigator.serviceWorker.register(this.Ot,this._t);return this.Mt=performance.now(),t}catch(t){throw t}}}export{a as Workbox,h as WorkboxEvent,t as messageSW};
|
|
//# sourceMappingURL=workbox-window.prod.mjs.map
|