(self.rspackChunk_jupyter_collaboration_extension=self.rspackChunk_jupyter_collaboration_extension||[]).push([[840],{9907(e){var t,s,n,o=e.exports={};function r(){throw Error("setTimeout has not been defined")}function c(){throw Error("clearTimeout has not been defined")}try{t="function"==typeof setTimeout?setTimeout:r}catch(e){t=r}try{s="function"==typeof clearTimeout?clearTimeout:c}catch(e){s=c}function i(e){if(t===setTimeout)return setTimeout(e,0);if((t===r||!t)&&setTimeout)return t=setTimeout,setTimeout(e,0);try{return t(e,0)}catch(s){try{return t.call(null,e,0)}catch(s){return t.call(this,e,0)}}}var a=[],l=!1,h=-1;function u(){l&&n&&(l=!1,n.length?a=n.concat(a):h=-1,a.length&&d())}function d(){if(!l){var e=i(u);l=!0;for(var t=a.length;t;){for(n=a,a=[];++h<t;)n&&n[h].run();h=-1,t=a.length}n=null,l=!1,function(e){if(s===clearTimeout)return clearTimeout(e);if((s===c||!s)&&clearTimeout)return s=clearTimeout,clearTimeout(e);try{s(e)}catch(t){try{return s.call(null,e)}catch(t){return s.call(this,e)}}}(e)}}function f(e,t){this.fun=e,this.array=t}function w(){}o.nextTick=function(e){var t=Array(arguments.length-1);if(arguments.length>1)for(var s=1;s<arguments.length;s++)t[s-1]=arguments[s];a.push(new f(e,t)),1!==a.length||l||i(d)},f.prototype.run=function(){this.fun.apply(null,this.array)},o.title="browser",o.browser=!0,o.env={},o.argv=[],o.version="",o.versions={},o.on=w,o.addListener=w,o.once=w,o.off=w,o.removeListener=w,o.removeAllListeners=w,o.emit=w,o.prependListener=w,o.prependOnceListener=w,o.listeners=function(e){return[]},o.binding=function(e){throw Error("process.binding is not supported")},o.cwd=function(){return"/"},o.chdir=function(e){throw Error("process.chdir is not supported")},o.umask=function(){return 0}},3187(e,t,s){"use strict";let n;s.r(t),s.d(t,{WebsocketProvider:()=>N,messageAuth:()=>O,messageAwareness:()=>H,messageQueryAwareness:()=>M,messageSync:()=>j});var o=s(7581),r=s(6505),c=s(9279),i=s(1554);let a=e=>void 0===e?null:e,l=new class{constructor(){this.map=new Map}setItem(e,t){this.map.set(e,t)}getItem(e){return this.map.get(e)}},h=!0;try{"u">typeof localStorage&&localStorage&&(l=localStorage,h=!1)}catch(e){}let u=l;var d=s(6527),f=s(9907);let w=void 0!==f&&f.release&&/node|io\.js/.test(f.release.name)&&"[object process]"===Object.prototype.toString.call(void 0!==f?f:0),p="u">typeof window&&"u">typeof document&&!w;"u">typeof navigator&&/Mac/.test(navigator.platform);let g=[],m=e=>(()=>{if(void 0===n)if(w){n=r.vt();let e=f.argv,t=null;for(let s=0;s<e.length;s++){let o=e[s];"-"===o[0]?(null!==t&&n.set(t,""),t=o):null!==t?(n.set(t,o),t=null):g.push(o)}null!==t&&n.set(t,"")}else"object"==typeof location?(n=r.vt(),(location.search||"?").slice(1).split("&").forEach(e=>{if(0!==e.length){let[t,s]=e.split("=");n.set(`--${i.jN(t,"-")}`,s),n.set(`-${i.jN(t,"-")}`,s)}})):n=r.vt();return n})().has(e),b=e=>w?a(f.env[e.toUpperCase().replaceAll("-","_")]):a(u.getItem(e)),y=e=>m("--"+e)||null!==b(e);y("production"),w&&d.EK(f.env.FORCE_COLOR,["true","1","2"])||!m("--no-colors")&&!y("no-color")&&(!w||f.stdout.isTTY)&&(!w||m("--color")||null!==b("COLORTERM")||(b("TERM")||"").includes("color"));let v=p?e=>{let t="";for(let s=0;s<e.byteLength;s++)t+=i.QV(e[s]);return btoa(t)}:e=>Buffer.from(e.buffer,e.byteOffset,e.byteLength).toString("base64"),_=p?e=>{let t=atob(e),s=new Uint8Array(t.length);for(let e=0;e<t.length;e++)s[e]=t.charCodeAt(e);return s}:e=>{let t,s=Buffer.from(e,"base64");return t=s.buffer,new Uint8Array(t,s.byteOffset,s.byteLength)},C=new Map,T="u"<typeof BroadcastChannel?class{constructor(e){this.room=e,this.onmessage=null,this._onChange=t=>t.key===e&&null!==this.onmessage&&this.onmessage({data:_(t.newValue||"")}),(e=>h||addEventListener("storage",e))(this._onChange)}postMessage(e){u.setItem(this.room,v(new Uint8Array(e)))}close(){let e;e=this._onChange,h||removeEventListener("storage",e)}}:BroadcastChannel,x=e=>r._4(C,e,()=>{let t=c.vt(),s=new T(e);return s.onmessage=e=>t.forEach(t=>t(e.data,"broadcastchannel")),{bc:s,subs:t}}),I=(e,t,s=null)=>{let n=x(e);n.bc.postMessage(t),n.subs.forEach(e=>e(t,s))};var k=s(482),S=s(6214),U=s(1926);let L=(e,t)=>{S.zd(e,0);let s=o.encodeStateVector(t);S.Gu(e,s)},z=(e,t,s)=>{S.zd(e,1),S.Gu(e,o.encodeStateAsUpdate(t,s))};var E=s(7784),A=s(1370),R=s(801),B=s(6132),F=s(9907);let j=0,M=3,H=1,O=2,G=[];G[0]=(e,t,s,n,r)=>{S.zd(e,j);let c=((e,t,s,n)=>{let r=U.cw(e);switch(r){case 0:z(t,s,U.bo(e));break;case 1:case 2:var c=e,i=s,a=n,l=void 0;try{o.applyUpdate(i,U.bo(c),a)}catch(e){null!=l&&l(e),console.error("Caught error while handling a Yjs update",e)}break;default:throw Error("Unknown message type")}return r})(t,e,s.doc,s);n&&1===c&&!s.synced&&(s.synced=!0)},G[M]=(e,t,s,n,o)=>{S.zd(e,H),S.Gu(e,E.X3(s.awareness,Array.from(s.awareness.getStates().keys())))},G[H]=(e,t,s,n,o)=>{E.tQ(s.awareness,U.bo(t),s)},G[O]=(e,t,s,n,o)=>{var r;r=s.doc,0===U.cw(t)&&((e,t)=>$(s,t))(r,U.t3(t))};let $=(e,t)=>console.warn(`Permission denied to access ${e.url}.
${t}`),D=(e,t,s)=>{let n=U.$C(t),o=S.xv(),r=U.cw(n),c=e.messageHandlers[r];return c?c(o,n,e,s,r):console.error("Unable to compute message"),o},W=e=>{if(e.shouldConnect&&null===e.ws){let t=new e._WS(e.url);t.binaryType="arraybuffer",e.ws=t,e.wsconnecting=!0,e.wsconnected=!1,e.synced=!1,t.onmessage=s=>{e.wsLastMessageReceived=k._g();let n=D(e,new Uint8Array(s.data),!0);S.Bw(n)>1&&t.send(S.Fo(n))},t.onerror=t=>{e.emit("connection-error",[t,e])},t.onclose=t=>{e.emit("connection-close",[t,e]),e.ws=null,e.wsconnecting=!1,e.wsconnected?(e.wsconnected=!1,e.synced=!1,E._g(e.awareness,Array.from(e.awareness.getStates().keys()).filter(t=>t!==e.doc.clientID),e),e.emit("status",[{status:"disconnected"}])):e.wsUnsuccessfulReconnects++,setTimeout(W,R.jk(100*R.n7(2,e.wsUnsuccessfulReconnects),e.maxBackoffTime),e)},t.onopen=()=>{e.wsLastMessageReceived=k._g(),e.wsconnecting=!1,e.wsconnected=!0,e.wsUnsuccessfulReconnects=0,e.emit("status",[{status:"connected"}]);let s=S.xv();if(S.zd(s,j),L(s,e.doc),t.send(S.Fo(s)),null!==e.awareness.getLocalState()){let s=S.xv();S.zd(s,H),S.Gu(s,E.X3(e.awareness,[e.doc.clientID])),t.send(S.Fo(s))}},e.emit("status",[{status:"connecting"}])}},X=(e,t)=>{let s=e.ws;e.wsconnected&&s&&s.readyState===s.OPEN&&s.send(t),e.bcconnected&&I(e.bcChannel,t,e)};class N extends A.c{constructor(e,t,s,{connect:n=!0,awareness:o=new E.ww(s),params:r={},WebSocketPolyfill:c=WebSocket,resyncInterval:i=-1,maxBackoffTime:a=2500,disableBc:l=!1}={}){for(super();"/"===e[e.length-1];)e=e.slice(0,e.length-1);const h=(e=>B.Tj(e,(e,t)=>`${encodeURIComponent(t)}=${encodeURIComponent(e)}`).join("&"))(r);this.maxBackoffTime=a,this.bcChannel=e+"/"+t,this.url=e+"/"+t+(0===h.length?"":"?"+h),this.roomname=t,this.doc=s,this._WS=c,this.awareness=o,this.wsconnected=!1,this.wsconnecting=!1,this.bcconnected=!1,this.disableBc=l,this.wsUnsuccessfulReconnects=0,this.messageHandlers=G.slice(),this._synced=!1,this.ws=null,this.wsLastMessageReceived=0,this.shouldConnect=n,this._resyncInterval=0,i>0&&(this._resyncInterval=setInterval(()=>{if(this.ws&&this.ws.readyState===WebSocket.OPEN){let e=S.xv();S.zd(e,j),L(e,s),this.ws.send(S.Fo(e))}},i)),this._bcSubscriber=(e,t)=>{if(t!==this){let t=D(this,new Uint8Array(e),!1);S.Bw(t)>1&&I(this.bcChannel,S.Fo(t),this)}},this._updateHandler=(e,t)=>{if(t!==this){let t=S.xv();S.zd(t,j),S.zd(t,2),S.Gu(t,e),X(this,S.Fo(t))}},this.doc.on("update",this._updateHandler),this._awarenessUpdateHandler=({added:e,updated:t,removed:s},n)=>{let r=e.concat(t).concat(s),c=S.xv();S.zd(c,H),S.Gu(c,E.X3(o,r)),X(this,S.Fo(c))},this._exitHandler=()=>{E._g(this.awareness,[s.clientID],"app closed")},w&&void 0!==F&&F.on("exit",this._exitHandler),o.on("update",this._awarenessUpdateHandler),this._checkInterval=setInterval(()=>{this.wsconnected&&3e4<k._g()-this.wsLastMessageReceived&&this.ws.close()},3e3),n&&this.connect()}get synced(){return this._synced}set synced(e){this._synced!==e&&(this._synced=e,this.emit("synced",[e]),this.emit("sync",[e]))}destroy(){0!==this._resyncInterval&&clearInterval(this._resyncInterval),clearInterval(this._checkInterval),this.disconnect(),w&&void 0!==F&&F.off("exit",this._exitHandler),this.awareness.off("update",this._awarenessUpdateHandler),this.doc.off("update",this._updateHandler),super.destroy()}connectBc(){if(this.disableBc)return;if(!this.bcconnected){var e,t;e=this.bcChannel,t=this._bcSubscriber,x(e).subs.add(t),this.bcconnected=!0}let s=S.xv();S.zd(s,j),L(s,this.doc),I(this.bcChannel,S.Fo(s),this);let n=S.xv();S.zd(n,j),z(n,this.doc),I(this.bcChannel,S.Fo(n),this);let o=S.xv();S.zd(o,M),I(this.bcChannel,S.Fo(o),this);let r=S.xv();S.zd(r,H),S.Gu(r,E.X3(this.awareness,[this.doc.clientID])),I(this.bcChannel,S.Fo(r),this)}disconnectBc(){let e=S.xv();if(S.zd(e,H),S.Gu(e,E.X3(this.awareness,[this.doc.clientID],new Map)),X(this,S.Fo(e)),this.bcconnected){var t,s;let e;t=this.bcChannel,s=this._bcSubscriber,(e=x(t)).subs.delete(s)&&0===e.subs.size&&(e.bc.close(),C.delete(t)),this.bcconnected=!1}}disconnect(){this.shouldConnect=!1,this.disconnectBc(),null!==this.ws&&this.ws.close()}connect(){this.shouldConnect=!0,this.wsconnected||null!==this.ws||(W(this),this.connectBc())}}}}]);