tweb/public/437.e3c1b82898e079a73d1f.bundle.js
2022-08-22 13:15:27 +02:00

2 lines
7.0 KiB
JavaScript

"use strict";(this.webpackChunktweb=this.webpackChunktweb||[]).push([[437],{410:(s,t,e)=>{e.d(t,{GO:()=>n,ZP:()=>o});const i=e(1267).Z.debug,n="undefined"!=typeof window?window:self,o=i},1267:(s,t,e)=>{e.d(t,{Z:()=>n});const i={test:location.search.indexOf("test=1")>0,debug:location.search.indexOf("debug=1")>0,http:!1,ssl:!0,multipleConnections:!0,asServiceWorker:!1,transport:"websocket"};i.http=location.search.indexOf("http=1")>0,i.http&&(i.transport="https");const n=i},6761:(s,t,e)=>{e.d(t,{Z:()=>i});const i="undefined"!=typeof window?window:self},4064:(s,t,e)=>{function i(s,t){const e=s.findIndex(t);return-1!==e?s.splice(e,1)[0]:void 0}e.d(t,{Z:()=>i})},1655:(s,t,e)=>{function i(s,t){const e=s.indexOf(t),i=-1!==e&&s.splice(e,1);return i&&i[0]}e.d(t,{Z:()=>i})},5289:(s,t,e)=>{e.d(t,{Z:()=>n});const i=Date.now();function n(){return"["+((Date.now()-i)/1e3).toFixed(3)+"]"}},3241:(s,t,e)=>{e.d(t,{Z:()=>n});var i=e(4064);class n{constructor(s){this._constructor(s)}_constructor(s=!1){this.reuseResults=s,this.listeners={},this.listenerResults={}}addEventListener(s,t,e){var i;(null!==(i=this.listeners[s])&&void 0!==i?i:this.listeners[s]=[]).push({callback:t,options:e}),this.listenerResults.hasOwnProperty(s)&&(t(...this.listenerResults[s]),null==e?void 0:e.once)&&this.listeners[s].pop()}addMultipleEventsListeners(s){for(const t in s)this.addEventListener(t,s[t])}removeEventListener(s,t,e){this.listeners[s]&&(0,i.Z)(this.listeners[s],(s=>s.callback===t))}invokeListenerCallback(s,t,...e){var i;let n;try{n=t.callback(...e)}catch(s){console.error(s)}return(null===(i=t.options)||void 0===i?void 0:i.once)&&this.removeEventListener(s,t.callback),n}_dispatchEvent(s,t,...e){this.reuseResults&&(this.listenerResults[s]=e);const i=t&&[],n=this.listeners[s];return n&&n.slice().forEach((t=>{if(-1===n.findIndex((s=>s.callback===t.callback)))return;const o=this.invokeListenerCallback(s,t,...e);i&&i.push(o)})),i}dispatchResultableEvent(s,...t){return this._dispatchEvent(s,!0,...t)}dispatchEvent(s,...t){this._dispatchEvent(s,!1,...t)}cleanup(){this.listeners={},this.listenerResults={}}}},5471:(s,t,e)=>{function i(s){return{type:s}}e.d(t,{Z:()=>i})},153:(s,t,e)=>{e.d(t,{Z:()=>l});var i=e(410),n=e(6761),o=e(1655),r=e(1352),a=e(3241),c=e(5471),h=e(5003);class l extends a.Z{constructor(s){if(super(!1),this.onMessage=s=>{const t=s.data,e=s.source||s.currentTarget;this.processTaskMap[t.type](t,e,s)},this.processResultTask=s=>{const{taskId:t,result:e,error:i}=s.payload,n=this.awaiting[t];n&&(this.debug&&this.log.debug("done",n.taskType,e,i),"error"in s.payload?n.reject(i):n.resolve(e),delete this.awaiting[t])},this.processAckTask=s=>{const t=s.payload,e=this.awaiting[t.taskId];e&&((0,e.resolve)({cached:t.cached,result:t.cached?"result"in t?Promise.resolve(t.result):Promise.reject(t.error):new Promise(((s,t)=>{e.resolve=s,e.reject=t}))}),t.cached&&delete this.awaiting[t.taskId])},this.processPingTask=(s,t,e)=>{this.pushTask(this.createTask("pong",void 0),e.source)},this.processPongTask=(s,t,e)=>{const i=this.pingResolves.get(t);i&&(this.pingResolves.delete(t),i())},this.processCloseTask=(s,t,e)=>{this.detachPort(t)},this.processLockTask=(s,t,e)=>{navigator.locks.request(s.payload,(()=>{this.processCloseTask(void 0,t,void 0)}))},this.processInvokeTask=(s,t,e)=>{return i=this,n=void 0,r=function*(){const i=s.id,n=s.payload;let o,r,a,c;n.void||(o={taskId:i},r=this.createTask("result",o)),n.withAck&&(a=this.createTask("ack",{taskId:i,cached:!0}));try{const s=this.listeners[n.type];if(!(null==s?void 0:s.length))throw new Error("no listener");const i=s[0];let r=this.invokeListenerCallback(n.type,i,n.payload,t,e);if(n.void)return;if(c=r instanceof Promise,a){const s=!c;if(a.payload.cached=s,s&&(a.payload.result=r),this.pushTask(a,t),s)return}c&&(r=yield r),o.result=r}catch(e){if(this.log.error("worker task error:",e,s),n.void)return;if(a&&a.payload.cached)return a.payload.error=e,void this.pushTask(a,t);o.error=e}this.pushTask(r,t)},new((o=void 0)||(o=Promise))((function(s,t){function e(s){try{c(r.next(s))}catch(s){t(s)}}function a(s){try{c(r.throw(s))}catch(s){t(s)}}function c(t){var i;t.done?s(t.value):(i=t.value,i instanceof o?i:new o((function(s){s(i)}))).then(e,a)}c((r=r.apply(i,n||[])).next())}));var i,n,o,r},this.listenPorts=[],this.sendPorts=[],this.pingResolves=new Map,this.taskId=0,this.awaiting={},this.pending=new Map,this.log=(0,h.kg)("MP"+(s?"-"+s:"")),this.debug=i.ZP,"undefined"!=typeof window)if("locks"in navigator){const s="lock-"+Date.now()+(65535*Math.random()|0);navigator.locks.request(s,(()=>new Promise((()=>{})))),this.pushTask(this.createTask("lock",s))}else window.addEventListener("beforeunload",(()=>{const s=this.createTask("close",void 0);this.postMessage(void 0,s)}));this.processTaskMap={result:this.processResultTask,ack:this.processAckTask,invoke:this.processInvokeTask,ping:this.processPingTask,pong:this.processPongTask,close:this.processCloseTask,lock:this.processLockTask}}setOnPortDisconnect(s){this.onPortDisconnect=s}attachPort(s){this.attachListenPort(s),this.attachSendPort(s)}attachListenPort(s){this.listenPorts.push(s),s.addEventListener("message",this.onMessage)}attachSendPort(s){var t,e;this.log.warn("attaching send port"),null===(e=(t=s).start)||void 0===e||e.call(t),this.sendPorts.push(s),this.releasePending()}detachPort(s){var t,e,i,n;this.log.warn("disconnecting port"),(0,o.Z)(this.listenPorts,s),(0,o.Z)(this.sendPorts,s),null===(t=s.removeEventListener)||void 0===t||t.call(s,"message",this.onMessage),null===(i=(e=s).close)||void 0===i||i.call(e),null===(n=this.onPortDisconnect)||void 0===n||n.call(this,s);const r=(0,c.Z)("PORT_DISCONNECTED");for(const t in this.awaiting){const e=this.awaiting[t];e.port===s&&(e.reject(r),delete this.awaiting[t])}}postMessage(s,t){(Array.isArray(s)?s:s?[s]:this.sendPorts).forEach((s=>{s.postMessage(t,t.transfer)}))}releasePending(){this.releasingPending||(this.releasingPending=!0,this.debug&&this.log.debug("releasing tasks, length:",this.pending.size),this.pending.forEach(((s,t)=>{const e=s,i=t?[t]:this.sendPorts;i.length&&(e.forEach((s=>{try{this.postMessage(i,s)}catch(t){this.log.error("postMessage error:",t,s,i)}})),this.pending.delete(t))})),this.debug&&this.log.debug("released tasks"),this.releasingPending=!1)}createTask(s,t,e){return{type:s,payload:t,id:this.taskId++,transfer:e}}createInvokeTask(s,t,e,i,n){return this.createTask("invoke",{type:s,payload:t,withAck:e,void:i},n)}pushTask(s,t){let e=this.pending.get(t);e||this.pending.set(t,e=[]),e.push(s),this.releasePending()}invokeVoid(s,t,e,i){const n=this.createInvokeTask(s,t,void 0,!0,i);this.pushTask(n,e)}invoke(s,t,e,i,o){let a;this.debug&&this.log.debug("start",s,t);const c=new Promise(((n,r)=>{a=this.createInvokeTask(s,t,e,void 0,o),this.awaiting[a.id]={resolve:n,reject:r,taskType:s,port:i},this.pushTask(a,i)}));if(r.kC){c.finally((()=>{clearInterval(s)}));const s=n.Z.setInterval((()=>{this.log.error("task still has no result",a,i)}),5e3)}return c}invokeExceptSource(s,t,e){const i=this.sendPorts.slice();(0,o.Z)(i,e),i.forEach((e=>{this.invokeVoid(s,t,e)}))}}}}]);
//# sourceMappingURL=437.e3c1b82898e079a73d1f.bundle.js.map