@liascript/editor 1.1.43--2.0.0 → 1.1.43--2.0.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1 +1 @@
1
- function e(e,t,s,n){Object.defineProperty(e,t,{get:s,set:n,enumerable:!0,configurable:!0})}var t="undefined"!=typeof globalThis?globalThis:"undefined"!=typeof self?self:"undefined"!=typeof window?window:"undefined"!=typeof global?global:{},s=t.parcelRequirea18f;s.register("bQEo7",(function(t,n){e(t.exports,"Sync",(()=>d)),s("6frWy");var r=s("P7Ozw"),i=s("iV07c"),o=s("8kr9p"),c=s("bDw11"),a=s("c4j9z"),h=(s("gjWRH"),s("8haH3"));function l(e=16){let t="";for(let s=0;s<e;s++)t+="ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789".charAt(Math.floor(62*Math.random()));return t}class d{isConnected=!1;name="";mode=0;replyOnReceive=!1;persistReady=Promise.resolve();constructor(e,t,s,n,r=!1,i=!0){let o;try{o=window.localStorage.getItem("lia-token"),o||(o=l(),window.localStorage.setItem("lia-token",o))}catch(e){console.warn("cannot write to localStorage"),o=l()}this.token=o,this.urlCounter=0,this.cbConnection=e,this.cbRelay=t,this.onConnect=s,this.onReceive=n,this.replyOnReceive=r;const a=this;this.db=new(0,c.CRDT)(o,i?(e,t)=>{if(a.db)switch(t){case"cursor":this.sync("update",{cmd:"cursor",param:e});break;case"peer":this.sync("update",{cmd:"peer",param:e});break;case"identity":this.sync("update",{cmd:"identity",param:e});break;case"code":this.sync("update",{cmd:"code",param:e});break;case"quiz":this.sync("update",{cmd:"quiz",param:e});break;case"survey":this.sync("update",{cmd:"survey",param:e});break;case"chat":this.sync("update",{cmd:"chat",param:e});break;case"ownership":this.sync("update",{cmd:"ownership",param:e});break;default:console.warn("Sync unknown origin",t)}}:void 0)}connect(e){if(this.room=e.room,this.course=e.course,this.password=e.password,this.mode=e.mode,this.pwSalt=e.pwSalt,this.pwCheck=e.pwCheck,this.ownerTokenHash=e.ownerTokenHash,this.db.setMode(e.mode,`${e.course}|${e.room}|${e.password||""}`,e.uidDB||e.course,{ownerTokenHash:e.ownerTokenHash,ownerToken:e.ownerToken}),this.name=e.name.trim(),this.isConnected=!0,e.persistent){const t=new(0,i.DexieTransport);this.persistProvider=new(0,r.GenericProvider)(this.db.doc,t),this.persistReady=this.persistProvider.connect({room:(0,h.docId)(e.uidDB||e.course,e.room,e.fullBackend||""),uidDB:e.uidDB||e.course}),this.persistReady.catch((e=>{console.warn("Sync: local persistence unavailable ->",e?.message||e)}))}else this.persistReady=Promise.resolve()}destroy(){this.persistProvider?.disconnect(),this.persistProvider=void 0,this.db.destroy(),this.cbConnection("disconnect",this.token),this.isConnected=!1}disconnect(){this.db.removePeer(),this.destroy()}uniqueID(e){let t=null;return"string"==typeof this.room&&(this.room.startsWith('"')&&this.room.endsWith('"')||this.room.startsWith("'")&&this.room.endsWith("'"))&&(t=this.room),this.course&&this.room&&(t=JSON.stringify({course:this.course,room:this.room,pw:o.getHashCode(this.password||""),mode:this.mode})),t&&(t=Math.abs(o.getHashCode(t+(e||""))).toString(16)),t||console.warn("Sync: no uniqueID"),t}sendToLia(e){this.cbRelay(e)}sync(e,t=null){this.cbConnection(e,t)}sendDisconnectError(e){this.sync("error",e)}sendWarning(e){this.sync("warning",e)}async sendConnect(){const e=await this.db.resolveOwnerToken();this.ownerTokenHash=e.hash,this.password&&!this.pwCheck&&(this.pwSalt=a.randomBytesBase64(16),this.pwCheck=await a.pbkdf2Base64(this.password,this.pwSalt)),this.sync("connect",{id:this.token,ownerTokenHash:this.ownerTokenHash||"",pwSalt:this.pwSalt||"",pwCheck:this.pwCheck||"",ownerToken:e.token||""}),this.onConnect&&this.onConnect(),this.persistReady.catch((()=>{})).then((()=>{this.password&&0===Object.keys(this.db.getPeers()).filter((e=>e!==this.token)).length&&this.sendWarning("No other participants found — double-check that your classroom password matches theirs."),this.db.claimOwnership()}))}pubsubSend(e,t){JSON.stringify({topic:e,message:t}),new TextEncoder,this.replyOnReceive&&this.onReceive?.(e,t)}pubsubReceive(e){try{const t=(new TextDecoder).decode(e),s=JSON.parse(t);this.onReceive?.(s.topic,s.message)}catch(e){console.warn("Sync: pubsubReceive",e.message)}}load(e,t){try{for(let s=0;s<e.length;s++){const n=document.createElement("script");n.async=!1,n.defer=!0,n.src=e[s],this.urlCounter++;let r=this;n.onload=function(){console.log("successfully loaded =>",e),r.urlCounter--,0==r.urlCounter&&t.init(!0)},n.onerror=function(s){console.warn("could not load =>",e,s),r.urlCounter=0,t.init(!1,`could not load => ${e}`)},document.head.appendChild(n)}}catch(e){console.error("load: ",e),t.init(!1,e.message)}}publish(e){switch(e.message.cmd){case"update":break;case"join":this.db.init(e.message.param).catch((e=>console.warn("db.init failed ->",e)));break;case"chat":this.db.addChatMessage(e.message.param).catch((e=>console.warn("addChatMessage failed ->",e)));break;case"quiz":"quiz"===e.track?.[0][0]&&"id"===e.track?.[1][0]?this.db.addQuiz(e.track[0][1],e.track[1][1],e.message.param):console.warn("SyncTX wrong event ->",e);break;case"survey":"survey"===e.track?.[0][0]&&"id"===e.track?.[1][0]?this.db.addSurvey(e.track[0][1],e.track[1][1],e.message.param):console.warn("SyncTX wrong event ->",e);break;case"code":"code"===e.track?.[0][0]&&"id"===e.track?.[1][0]?this.db.updateCode(e.track[0][1],e.track[1][1],e.message.param.j,e.message.param.msg):console.warn("SyncTX wrong event ->",e);break;case"codes":if("code"===e.track?.[0][0]&&1===e.track.length)for(let t=0;t<e.message.param.length;t++)for(let s=0;s<e.message.param[t].length;s++)this.db.initCode(e.track[0][1],t,s,e.message.param[t][s]);else console.warn("SyncTX wrong event ->",e);break;case"cursor":"code"==e.track?.[0][0]&&this.db.setCursor(e.track[0][1],e.message.param,this.name);break;default:console.warn("SyncTX unknown command:",e.message)}}}})),s.register("6frWy",(function(t,n){e(t.exports,"GenericProvider",(()=>s("P7Ozw").GenericProvider)),e(t.exports,"extractDocUpdates",(()=>s("P7Ozw").extractDocUpdates)),e(t.exports,"frameDocUpdate",(()=>s("P7Ozw").frameDocUpdate)),s("P7Ozw"),s("P7Ozw"),s("cIOyM")})),s.register("P7Ozw",(function(t,n){e(t.exports,"extractDocUpdates",(()=>v)),e(t.exports,"frameDocUpdate",(()=>A)),e(t.exports,"GenericProvider",(()=>C));var r=s("bx9uf"),i=s("4AWOh"),o=s("kRCFI"),c=s("7BTJz"),a=s("l5188"),h=s("8Gyr5"),l=s("bEPl9");const d=0,u=3,p=4,g=6,f=(()=>{const e=new Uint32Array(256);for(let t=0;t<256;t++){let s=t;for(let e=0;e<8;e++)s=1&s?s>>>1^3988292384:s>>>1;e[t]=s}return e})();function w(e){let t=4294967295;for(let s=0;s<e.length;s++)t=t>>>8^f[255&(t^e[s])];return(4294967295^t)>>>0}function y(e){const t=w(e),s=new Uint8Array(4+e.length);return s[0]=t>>>24&255,s[1]=t>>>16&255,s[2]=t>>>8&255,s[3]=255&t,s.set(e,4),s}function _(e,t){if(e.length!==t.length)return!1;for(let s=0;s<e.length;s++)if(e[s]!==t[s])return!1;return!0}const m="undefined"!=typeof CompressionStream&&"undefined"!=typeof DecompressionStream;async function b(e){const t=[],s=e.getReader();for(;;){const{done:e,value:n}=await s.read();if(e)break;t.push(n)}const n=t.reduce(((e,t)=>e+t.length),0),r=new Uint8Array(n);let i=0;for(const e of t)r.set(e,i),i+=e.length;return r}function S(e,t){const s=new Uint8Array(1+t.length);return s[0]=e,s.set(t,1),s}function k(e){const t=r.encodeStateVector(e);let s=0;for(let e=0;e<t.length;e++)s=(s<<5)-s+t[e]|0;return s}function v(e){const t=[],s=e=>{const n=a.createDecoder(e),r=a.readVarUint(n);switch(r){case p:for(;a.hasContent(n);)s(a.readVarUint8Array(n));break;case u:case d:{r===u&&(a.readVarUint(n),a.readVarUint(n));const e=a.readVarUint(n);e!==o.messageYjsSyncStep2&&e!==o.messageYjsUpdate||t.push(a.readVarUint8Array(n));break}case g:t.push(a.readVarUint8Array(n))}};try{e.length>4&&s(e.subarray(4))}catch{return[]}return t}function A(e){const t=c.createEncoder();return c.writeVarUint(t,d),c.writeVarUint(t,o.messageYjsSyncStep2),c.writeVarUint8Array(t,e),y(c.toUint8Array(t))}class T extends h.Observable{constructor(e){super(),this.provider=e}publish(e,t){this.provider._sendPubSub(e,t)}subscribe(e,t){const s=(s,n)=>{"*"!==e&&e!==n||t(s,n)};return this.on("message",s),()=>this.off("message",s)}_handleMessage(e,t){this.emit("message",[t,e])}}class C extends h.Observable{constructor(e,t,s={}){if(super(),this._status={state:"disconnected"},this._synced=!1,this._destroying=!1,this._lastActivityTime=Date.now(),this._lastPeriodicTickTime=Date.now(),this._equalBeaconsHeard=0,this._beaconForced=!1,this._bcChannel="",this._bcConnected=!1,this._resyncAttemptCount=0,this._lastResyncAttemptTime=0,this._syncRequestTimes=[],this._syncReplyTimes=[],this._pendingSyncReply=null,this._pendingSyncReplyIsAck=!1,this._pendingSyncReplyTargetSv=null,this._responseWaitAttempts=0,this._responseSeen=!1,this._equalUnsettledSeen=!1,this._responseWaitFlags=0,this._behindSv=null,this._rttSamples=[],this._requestSentAt=0,this._confirmed=!1,this._knownPeers=new Map,this._peerAddress=new Map,this._presencePending=new Set,this._presenceCovered=!1,this._pendingAwarenessRemoval=null,this._pendingPeerConnectIds=new Set,this._confirmedSv=null,this._confirmedDsHash=null,this._loading=!1,this._dsHashCache=null,this._localSeqNum=0,this._remoteSeqInfo=new Map,this._gapCheckTimers=new Map,this._batchUpdates=0,this._pendingUpdate=null,this._flushScheduled=!1,this._awarenessInterval=100,this._pendingAwarenessClients=new Set,this._lastAwarenessTime=0,this.doc=e,this.transport=t,this.pubsub=new T(this),this.awareness=s.awareness||new i.Awareness(e),this._syncInterval=s.syncInterval??5e3,this._verifyUpdates=s.verifyUpdates??!0,this._batchUpdates=s.batchUpdates??t.preferredBatchMs??0,this._disableBc=s.disableBc??!1,this._awarenessInterval=s.awarenessInterval??t.preferredAwarenessMs??100,this._maxSyncRequestsPerWindow=s.maxSyncRequestsPerWindow??20,this._syncRequestWindowMs=s.syncRequestWindowMs??1e4,this._syncReplySuppressionMs=s.syncReplySuppressionMs??30,this._peerConnectDebounceMs=s.peerConnectDebounceMs??50,this._gapGraceMs=s.gapGraceMs??300,this._seqWindowSize=s.seqWindowSize??64,this._compressionThresholdBytes=(s.compressionThresholdBytes??t.preferredCompressMinBytes)||void 0,this._idleBackoffEnabled=s.idleBackoffEnabled??!0,this._idleBackoffMaxMs=s.idleBackoffMaxMs??6e4,this._trickleK=s.trickleK??1,this._ownsAwareness=!s.awareness,this._awarenessTimeoutMs=s.awarenessTimeoutMs??("function"==typeof t.onPeerDisconnect?3e5:3e4),this._ownsAwareness){const e=this.awareness;void 0!==e._checkInterval&&clearInterval(e._checkInterval)}this._currentSyncIntervalMs=this._syncInterval,this._setupDocumentSync(),this._setupAwarenessSync()}async connect(e){if(this._destroying)throw new Error("Provider is being destroyed");if("connected"!==this._status.state)if("connecting"!==this._status.state){this._setStatus({state:"connecting"});try{if(this._setupBroadcastChannel(e),this._unsubscribeTransport=this.transport.onMessage(((e,t)=>{this._handleIncomingMessage(e,t)})),this.transport.onPeerConnect){const e=this.transport.onPeerConnect((e=>{this._destroying||this._schedulePeerConnectSync(e)})),t=this._unsubscribeTransport;this._unsubscribeTransport=()=>{t?.(),e()}}if(this.transport.onPeerDisconnect){const e=this.transport.onPeerDisconnect((e=>{this._destroying||this._handlePeerLeave(e)})),t=this._unsubscribeTransport;this._unsubscribeTransport=()=>{t?.(),e()}}if(await this.transport.connect(e),this._setStatus({state:"connected"}),this._startAwarenessSweep(),this.transport.expectedRttMs&&(this._rttSamples=[this.transport.expectedRttMs]),e.waitFor){this._loading=!0;try{await e.waitFor}catch{}if(this._loading=!1,this._destroying||!this.transport.isConnected)return;this._confirmedSv=r.encodeStateVector(this.doc),this._confirmedDsHash=this._deleteSetHash()}if(this.syncNow(),this._syncInterval>0){this._currentSyncIntervalMs=this._syncInterval,this._lastActivityTime=Date.now(),this._lastPeriodicTickTime=Date.now(),this._equalBeaconsHeard=0,this._beaconForced=!1;const e=t=>{this._syncIntervalId=setTimeout((()=>{const t=Date.now();if(this._idleBackoffEnabled){const e=this._lastActivityTime>this._lastPeriodicTickTime;this._currentSyncIntervalMs=e?this._syncInterval:Math.min(this._idleBackoffMaxMs,2*this._currentSyncIntervalMs)}this._lastPeriodicTickTime=t,this.transport.isConnected&&!this._destroying&&(this._trickleK>0&&!this._beaconForced&&this._equalBeaconsHeard>=this._trickleK||this._sendSyncStep1(),this._equalBeaconsHeard=0,this._beaconForced=!1),this._destroying||e()}),t??this._jitteredSyncInterval())};this._periodicScheduler=e,e()}}catch(e){throw this._setStatus({state:"error",error:e instanceof Error?e:new Error(String(e))}),e}}else console.warn("[GenericProvider] Connection already in progress, ignoring connect() call");else console.warn("[GenericProvider] Already connected, ignoring connect() call")}disconnect(){void 0!==this._syncIntervalId&&(clearTimeout(this._syncIntervalId),this._syncIntervalId=void 0),this._periodicScheduler=void 0,void 0!==this._awarenessSweepId&&(clearTimeout(this._awarenessSweepId),this._awarenessSweepId=void 0),this._resyncAttemptCount=0,this._lastResyncAttemptTime=0,void 0!==this._pendingResyncTimeoutId&&(clearTimeout(this._pendingResyncTimeoutId),this._pendingResyncTimeoutId=void 0);for(const e of this._gapCheckTimers.values())clearTimeout(e);if(this._gapCheckTimers.clear(),this._remoteSeqInfo.clear(),void 0!==this._pendingPeerConnectSyncTimeoutId&&(clearTimeout(this._pendingPeerConnectSyncTimeoutId),this._pendingPeerConnectSyncTimeoutId=void 0),this._pendingPeerConnectIds.clear(),this._syncRequestTimes=[],this._syncReplyTimes=[],this._knownPeers.clear(),this._peerAddress.clear(),this._presencePending.clear(),void 0!==this._responseWaitTimer&&(clearTimeout(this._responseWaitTimer),this._responseWaitTimer=void 0),void 0!==this._pendingCheckTimer&&(clearTimeout(this._pendingCheckTimer),this._pendingCheckTimer=void 0),void 0!==this._behindCheckTimer&&(clearTimeout(this._behindCheckTimer),this._behindCheckTimer=void 0),this._behindSv=null,void 0!==this._presenceResponseTimer&&(clearTimeout(this._presenceResponseTimer),this._presenceResponseTimer=void 0),this._responseWaitAttempts=0,this._responseSeen=!1,this._equalUnsettledSeen=!1,this._rttSamples=[],this._requestSentAt=0,this._confirmed=!1,this._cancelPendingSyncReply(),this._cancelPendingAwarenessRemoval(),this._flushPendingUpdate(),void 0!==this._awarenessTimeoutId&&(clearTimeout(this._awarenessTimeoutId),this._awarenessTimeoutId=void 0,this._pendingAwarenessClients.size>0&&this.transport.isConnected)){const e=Array.from(this._pendingAwarenessClients);this._sendAwarenessNow(e)}this._pendingAwarenessClients.clear(),this._disconnectBroadcastChannel(),this._unsubscribeTransport&&(this._unsubscribeTransport(),this._unsubscribeTransport=void 0),i.removeAwarenessStates(this.awareness,[this.doc.clientID],"disconnect"),this.transport.disconnect(),this._synced=!1,this._setStatus({state:"disconnected"})}destroy(){this._destroying=!0,void 0!==this._syncIntervalId&&(clearTimeout(this._syncIntervalId),this._syncIntervalId=void 0);for(const e of this._gapCheckTimers.values())clearTimeout(e);this._gapCheckTimers.clear(),this._cancelPendingSyncReply(),this._cancelPendingAwarenessRemoval(),this._flushPendingUpdate(),this.disconnect(),this._updateHandler&&(this.doc.off("update",this._updateHandler),this._updateHandler=void 0),this._awarenessUpdateHandler&&(this.awareness.off(this._ownsAwareness?"change":"update",this._awarenessUpdateHandler),this._awarenessUpdateHandler=void 0),void 0!==this._awarenessSweepId&&(clearTimeout(this._awarenessSweepId),this._awarenessSweepId=void 0),this._beforeUnloadHandler&&"undefined"!=typeof window&&(window.removeEventListener("beforeunload",this._beforeUnloadHandler),this._beforeUnloadHandler=void 0),this.awareness.destroy(),super.destroy()}get status(){return this._status}get connected(){return this.transport.isConnected}get bcConnected(){return this._bcConnected}get synced(){return this._synced}_trySyncPushPull(e=!0,t,s=0){if(!this._tryReserveSyncSlot())return!1;const n=[];if(e){const e=r.encodeStateAsUpdate(this.doc,this._confirmedSv??void 0);let t=e.length>0;if(t&&null!==this._confirmedSv)try{t=r.parseUpdateMeta(e).to.size>0||this._deleteSetHash()!==this._confirmedDsHash}catch{t=!0}t&&n.push(this._encodePush(e))}return n.push(this._encodeSyncStep1(s)),t&&n.push(...t()),this._sendBatch(n),1&s&&this._armResponseWait(4),!0}syncNow(){this._syncNow(1)}_syncNow(e){if(!this.transport.isConnected)return void console.warn("Cannot sync: transport not connected");1&e&&(this._confirmed=!1);let t=!1;this._trySyncPushPull(!0,(()=>{const e=this._tryImmediateAwarenessMessage([this.doc.clientID]);return e?(t=!0,[e]):[]}),e)&&t||this._broadcastAwareness([this.doc.clientID])}_jitteredSyncInterval(){const e=1+.2*(2*Math.random()-1);return this._currentSyncIntervalMs*e}_markActivity(){this._lastActivityTime=Date.now(),this._idleBackoffEnabled&&this._currentSyncIntervalMs!==this._syncInterval&&void 0!==this._syncIntervalId&&void 0!==this._periodicScheduler&&(clearTimeout(this._syncIntervalId),this._currentSyncIntervalMs=this._syncInterval,this._beaconForced=!0,this._periodicScheduler(Math.random()*this._syncInterval))}_startAwarenessSweep(){if(void 0!==this._awarenessSweepId)return;const e=this._awarenessTimeoutMs,t=()=>{this._awarenessSweepId=setTimeout(s,e/10*(.8+.4*Math.random()))},s=()=>{const s=Date.now();if(this._ownsAwareness){const t=this.awareness.meta.get(this.doc.clientID);null!==this.awareness.getLocalState()&&void 0!==t&&e/2<=s-t.lastUpdated&&(this.awareness.setLocalState(this.awareness.getLocalState()),this._broadcastAwareness([this.doc.clientID]));const n=[];this.awareness.meta.forEach(((t,r)=>{r!==this.doc.clientID&&e<=s-t.lastUpdated&&this.awareness.getStates().has(r)&&n.push(r)})),n.length>0&&i.removeAwarenessStates(this.awareness,n,"timeout")}for(const[t,n]of this._knownPeers)e<=s-n&&(this._knownPeers.delete(t),this._peerAddress.delete(t),this._remoteSeqInfo.delete(t));this._destroying||"connected"!==this._status.state?this._awarenessSweepId=void 0:t()};t()}_touchPeer(e){const t=this.awareness.meta.get(e);void 0!==t&&this.awareness.getStates().has(e)&&(t.lastUpdated=Date.now())}_handlePeerLeave(e){const t=[];for(const[s,n]of this._peerAddress)n===e&&t.push(s);for(const e of t)this._peerAddress.delete(e),this._knownPeers.delete(e);const s=t.filter((e=>this.awareness.getStates().has(e)));s.length>0&&i.removeAwarenessStates(this.awareness,s,"peer-left")}_deleteSetHash(){return null===this._dsHashCache&&(this._dsHashCache=function(e){const t=r.createDeleteSetFromStructStore(e.store),s=c.createEncoder(),n=Array.from(t.clients.keys()).sort(((e,t)=>e-t));for(const e of n){c.writeVarUint(s,e);for(const n of t.clients.get(e))c.writeVarUint(s,n.clock),c.writeVarUint(s,n.len)}return w(c.toUint8Array(s))}(this.doc)),this._dsHashCache}_schedulePeerConnectSync(e){void 0!==e&&this._pendingPeerConnectIds.add(e),void 0===this._pendingPeerConnectSyncTimeoutId&&(this._pendingPeerConnectSyncTimeoutId=setTimeout((()=>{this._pendingPeerConnectSyncTimeoutId=void 0;const e=Array.from(this._pendingPeerConnectIds);if(this._pendingPeerConnectIds.clear(),this.transport.isConnected&&!this._destroying)if("function"==typeof this.transport.sendTo&&e.length>0){const t=y(this._encodeSyncStep1(0));for(const s of e)this._sendToTransport(t,s)}else this._syncNow(0)}),this._peerConnectDebounceMs))}_setupDocumentSync(){this._updateHandler=(e,t)=>{this._dsHashCache=null,this._equalBeaconsHeard=0,t===this||this._loading||(this._markActivity(),this._batchUpdate(e))},this.doc.on("update",this._updateHandler)}_batchUpdate(e){if(this._pendingUpdate)try{this._pendingUpdate=r.mergeUpdates([this._pendingUpdate,e])}catch(t){console.error("[GenericProvider] Failed to merge updates:",t),this._sendUpdate(this._pendingUpdate),this._pendingUpdate=e}else this._pendingUpdate=e;if(this._batchUpdates>0)return void 0!==this._batchTimeoutId&&clearTimeout(this._batchTimeoutId),this._batchTimeoutId=setTimeout((()=>{this._batchTimeoutId=void 0,this._flushPendingUpdate()}),this._batchUpdates),void(this._flushScheduled=!0);this._flushScheduled||(this._flushScheduled=!0,queueMicrotask((()=>this._flushPendingUpdate())))}_flushPendingUpdate(){this._flushScheduled=!1,void 0!==this._batchTimeoutId&&(clearTimeout(this._batchTimeoutId),this._batchTimeoutId=void 0);const e=this._pendingUpdate;this._pendingUpdate=null,e&&this.transport.isConnected&&this._sendUpdate(e)}_setupAwarenessSync(){this._awarenessUpdateHandler=({added:e,updated:t,removed:s},n)=>{if(n===this&&(s.length>0&&this._cancelPendingAwarenessRemovalIfOverlaps(s),!s.includes(this.awareness.clientID)))return;const r=e.concat(t).concat(s);"timeout"!==n&&"peer-left"!==n?this._broadcastAwareness(r):this._scheduleAwarenessRemoval(r,n)},this.awareness.on(this._ownsAwareness?"change":"update",this._awarenessUpdateHandler),"undefined"!=typeof window&&(this._beforeUnloadHandler=()=>{i.removeAwarenessStates(this.awareness,[this.doc.clientID],"window unload"),this._disconnectBroadcastChannel()},window.addEventListener("beforeunload",this._beforeUnloadHandler))}_handleIncomingMessage(e,t){if(!this._compressionThresholdBytes)return void this._processWrappedMessage(e,t);if(e.length<1)return void console.warn("[GenericProvider] Dropping empty message (missing compression flag byte)");const s=e[0],n=e.subarray(1);0!==s?m?async function(e){const t=new DecompressionStream("deflate-raw"),s=t.writable.getWriter();return s.write(e).catch((()=>{})),s.close().catch((()=>{})),b(t.readable)}(n).then((e=>this._processWrappedMessage(e,t))).catch((e=>{console.warn("[GenericProvider] Failed to decompress incoming message, treating as corrupted:",e),this._requestResync()})):console.warn("[GenericProvider] Received a compressed message but this runtime has no DecompressionStream - dropping it."):this._processWrappedMessage(n,t)}_processWrappedMessage(e,t){const s=function(e){if(e.length<4)return null;const t=(e[0]<<24|e[1]<<16|e[2]<<8|e[3])>>>0,s=e.subarray(4);return w(s)!==t?null:s}(e);if(null===s)return console.warn("[GenericProvider] 💥 Corrupted message rejected: CRC32 checksum mismatch. This is expected if data corruption simulation is enabled."),this._markActivity(),void this._requestResync();try{this._dispatchMessage(s,t)}catch(e){console.error("[GenericProvider] Error handling message:",e)}}_dispatchMessage(e,t){const s=a.createDecoder(e),n=a.readVarUint(s);switch(n){case p:for(;a.hasContent(s);){const e=a.readVarUint8Array(s);this._dispatchMessage(e,t)}break;case 5:this._handleDigest(s,t);break;case g:r.applyUpdate(this.doc,a.readVarUint8Array(s),this),this._checkPendingAfterReply();break;case d:{const e=c.createEncoder();c.writeVarUint(e,d),o.readSyncMessage(s,e,this.doc,this)===o.messageYjsSyncStep2&&(this._confirmed=!0,this._noteResponse(!0),this._markSynced(),this._checkPendingAfterReply(),this._cancelPendingSyncReply()),c.length(e)>1&&this._replyToSyncRequest(c.toUint8Array(e));break}case 1:{const e=a.readVarUint8Array(s),t=this._scanAwarenessPayload(e);t.removed.length>0&&this._cancelPendingAwarenessRemovalIfOverlaps(t.removed),t.coversUs&&(this._presenceCovered=!0);const n=Date.now();for(const e of t.present)e!==this.doc.clientID&&this._knownPeers.set(e,n);i.applyAwarenessUpdate(this.awareness,e,this);break}case 2:{const t=a.readVarString(s),n=a.readVarUint8Array(s);try{const e=(new TextDecoder).decode(n),s=JSON.parse(e);this.pubsub._handleMessage(t,s)}catch(e){console.error("Error decoding pub/sub message:",e)}break}case u:{const e=a.readVarUint(s),n=a.readVarUint(s);this._trackRemoteSeq(n,e),this._knownPeers.set(n,Date.now()),void 0!==t&&this._peerAddress.set(n,t),this._touchPeer(n);const r=this._peekSyncUpdate(s),i=c.createEncoder();c.writeVarUint(i,d);const h=o.readSyncMessage(s,i,this.doc,this);h===o.messageYjsSyncStep2&&(this._cancelPendingSyncReply(),this._confirmed=!0,this._checkPendingAfterReply(),this._noteResponse(!0));const l=a.readVarInt(s),u=k(this.doc);if(u!==l){const e=this._gapCheckTimers.has(n),t=this._isLateUpdate(r);null!==this.doc.store.pendingStructs||null!==this.doc.store.pendingDs?this._schedulePendingCheck():e||t||(this._requestResync(),console.warn(`[GenericProvider] Hash mismatch #${this._resyncAttemptCount} detected! Local: ${u}, Expected: ${l}`))}h===o.messageYjsSyncStep2&&u===l&&this._markSynced(),c.length(i)>1&&this._replyToSyncRequest(c.toUint8Array(i));break}default:console.warn("Unknown message type:",n)}}_handleDigest(e,t){a.readVarUint(e);const s=a.readVarUint(e),n=a.readVarUint(e);this._knownPeers.set(n,Date.now()),void 0!==t&&this._peerAddress.set(n,t),this._touchPeer(n);const i=a.readVarUint8Array(e),h=a.readVarUint(e),l=r.decodeStateVector(i),u=r.decodeStateVector(r.encodeStateVector(this.doc));let p=!1;for(const[e,t]of u)if((l.get(e)??0)<t){p=!0;break}let g=!1;for(const[e,t]of l)if((u.get(e)??0)<t){g=!0;break}const f=h===this._deleteSetHash(),w=!p&&!g&&f;if(w&&(this._confirmedSv=i,this._confirmedDsHash=h),2&s)w&&(8&s?(this._confirmed=!0,this._noteResponse(!0)):this._equalUnsettledSeen=!0,this._markSynced(),this._cancelPendingAck());else{if(!w||5&s||(this._equalBeaconsHeard++,8&s?(this._confirmed=!0,this._noteResponse(!1)):this._equalUnsettledSeen=!0,this._cancelPendingAck()),p||!f){const e=c.createEncoder();c.writeVarUint(e,d),o.writeSyncStep2(e,this.doc,i);let t=c.toUint8Array(e);f||(t=this._encodeBatch([t,this._encodeSyncStep1(0)])),this._replyToSyncRequest(t,!1,i,n)}else 5&s&&this._replyToSyncRequest(this._encodeAck(i,h),!0,null,n);!g&&f&&this._markSynced(),g&&this._scheduleBehindCheck(i),1&s&&null!==this.awareness.getLocalState()&&this._schedulePresenceResponse(n)}}_schedulePresenceResponse(e){if(this._presencePending.add(e),void 0!==this._presenceResponseTimer)return;this._presenceCovered=!1;const t=this._rttMinMs(),s=!this._canUnicast(e)&&this._knownPeers.size>=3&&0===this._responderRank(0,1),n=s?0:Math.min(500,Math.max(100,null===t?0:2*t));this._presenceResponseTimer=setTimeout((()=>{this._presenceResponseTimer=void 0;const e=Array.from(this._presencePending);if(this._presencePending.clear(),!this._destroying&&this.transport.isConnected&&null!==this.awareness.getLocalState())if(e.every((e=>this._canUnicast(e)))){const t=this._encodeAwareness([this.doc.clientID]);for(const s of e)this._sendDirect(s,t)}else s?this._sendAwarenessNow(Array.from(this.awareness.getStates().keys())):this._presenceCovered||this._broadcastAwareness([this.doc.clientID])}),n)}_peerCount(){return Math.max(this.awareness.getStates().size,this._knownPeers.size+1)}_effectiveAwarenessInterval(){if("auto"!==this._awarenessInterval)return this._awarenessInterval;const e=this.transport.preferredAwarenessMs??100;return Math.max(e,C.AWARENESS_AUTO_MS_PER_PEER*this._peerCount())}_replySuppressionMaxDelay(){const e=this._peerCount(),t=Math.min(200,this._syncReplySuppressionMs*Math.log2(Math.max(2,e))),s=this._rttMinMs();return null===s?t:Math.min(2e3,Math.max(t,1.5*s))}_scheduleSyncReply(e,t=!1,s=null,n=null){if(void 0!==this._pendingSyncReplyTimeoutId&&null!==this._pendingSyncReply){if(_(this._pendingSyncReply,e))return;if(null!==s&&null!==this._pendingSyncReplyTargetSv&&_(this._pendingSyncReplyTargetSv,s))return void(this._pendingSyncReply=e);if(!t&&!this._pendingSyncReplyIsAck&&null!==s&&null!==this._pendingSyncReplyTargetSv){const e=function(e,t){const s=r.decodeStateVector(e),n=r.decodeStateVector(t),i=new Map;for(const[e,t]of s){const s=Math.min(t,n.get(e)??0);s>0&&i.set(e,s)}return r.encodeStateVector(i)}(this._pendingSyncReplyTargetSv,s),t=c.createEncoder();return c.writeVarUint(t,d),o.writeSyncStep2(t,this.doc,e),this._pendingSyncReply=c.toUint8Array(t),void(this._pendingSyncReplyTargetSv=e)}if(t)return;this._pendingSyncReplyIsAck&&(clearTimeout(this._pendingSyncReplyTimeoutId),this._pendingSyncReplyTimeoutId=void 0)}void 0!==this._pendingSyncReplyTimeoutId&&(this._pendingSyncReply&&this._sendSyncReply(this._pendingSyncReply),clearTimeout(this._pendingSyncReplyTimeoutId),this._pendingSyncReplyTimeoutId=void 0),this._pendingSyncReply=e,this._pendingSyncReplyIsAck=t,this._pendingSyncReplyTargetSv=s;const i=t?Math.random()*this._replySuppressionMaxDelay():this._replyDelay(n);this._pendingSyncReplyTimeoutId=setTimeout((()=>{this._pendingSyncReplyTimeoutId=void 0,this._pendingSyncReply&&(this._sendSyncReply(this._pendingSyncReply),this._pendingSyncReply=null,this._pendingSyncReplyTargetSv=null)}),i)}_cancelPendingSyncReply(){void 0!==this._pendingSyncReplyTimeoutId&&(clearTimeout(this._pendingSyncReplyTimeoutId),this._pendingSyncReplyTimeoutId=void 0),this._pendingSyncReply=null,this._pendingSyncReplyIsAck=!1,this._pendingSyncReplyTargetSv=null}_cancelPendingAck(){this._pendingSyncReplyIsAck&&this._cancelPendingSyncReply()}_replyToSyncRequest(e,t=!1,s=null,n){if(null===this.doc.store.pendingStructs&&null===this.doc.store.pendingDs)if(void 0!==n&&this._canUnicast(n)){if(!this._selectedResponder(n))return;if(!this._tryReserveReplySlot())return;this._sendDirect(n,e)}else t||this._peerCount()>=3?this._scheduleSyncReply(e,t,s,n??null):this._sendSyncReply(e)}_canUnicast(e){return"function"==typeof this.transport.sendTo&&this._peerAddress.has(e)}_selectedResponder(e){return this._peerCount()<4||this._responderRank(e,3)<3}_responderRank(e,t){const s=Math.floor(Date.now()/2e3),n=t=>(Math.imul(e^s,2654435761)^Math.imul(t,2246822507))>>>0,r=n(this.doc.clientID);let i=0;for(const s of this._knownPeers.keys())if(s!==e&&s!==this.doc.clientID&&n(s)<r&&++i>=t)break;return i}_replyDelay(e){const t=this._replySuppressionMaxDelay(),s=this._rttMinMs();if(null===e||null===s)return Math.random()*t;const n=Math.max(this._syncReplySuppressionMs,.75*s),r=this._responderRank(e,8);return r*n+(r>=8?Math.random()*t:0)}_sendDirect(e,t){const s=this._peerAddress.get(e);return void 0!==s&&"function"==typeof this.transport.sendTo&&!!this.transport.isConnected&&(this._sendToTransport(y(t),s),!0)}_scheduleBehindCheck(e){if(this._behindSv=e,void 0!==this._behindCheckTimer)return;const t=this._rttMinMs(),s=Math.max(this._gapGraceMs,null===t?0:2*t);this._behindCheckTimer=setTimeout((()=>{this._behindCheckTimer=void 0;const e=this._behindSv;if(this._behindSv=null,null===e||this._destroying||!this.transport.isConnected)return;if(this._requestSentAt>0&&Date.now()-this._requestSentAt<s)return;const t=r.decodeStateVector(e),n=r.decodeStateVector(r.encodeStateVector(this.doc));for(const[e,s]of t)if((n.get(e)??0)<s)return void this._requestResync()}),s)}_checkPendingAfterReply(){null===this.doc.store.pendingStructs&&null===this.doc.store.pendingDs||this._schedulePendingCheck()}_schedulePendingCheck(){void 0===this._pendingCheckTimer&&(this._pendingCheckTimer=setTimeout((()=>{if(this._pendingCheckTimer=void 0,this._destroying||!this.transport.isConnected)return;const e=this._rttMinMs(),t=Math.max(this._gapGraceMs,null===e?0:2*e);this._requestSentAt>0&&Date.now()-this._requestSentAt<t?this._schedulePendingCheck():null===this.doc.store.pendingStructs&&null===this.doc.store.pendingDs||this._requestResync()}),this._gapGraceMs))}_peekSyncUpdate(e){const t=a.clone(e);try{return a.readVarUint(t)===o.messageYjsSyncStep1?null:a.readVarUint8Array(t)}catch{return null}}_isLateUpdate(e){if(!e)return!1;try{const{to:t}=r.parseUpdateMeta(e);if(0===t.size)return!1;const s=r.decodeStateVector(r.encodeStateVector(this.doc));for(const[e,n]of t)if((s.get(e)??0)<=n)return!1;return!0}catch{return!1}}_markSynced(){this._synced||(this._synced=!0,this.emit("synced",[!0]))}_armResponseWait(e){if(void 0!==this._responseWaitTimer)return;this._responseSeen=!1,0===this._responseWaitAttempts&&(this._equalUnsettledSeen=!1),this._responseWaitFlags=e,this._requestSentAt=Date.now();const t=this._rttMinMs(),s=Math.max(1e3,null===t?0:4*t)*Math.pow(2,this._responseWaitAttempts);this._responseWaitTimer=setTimeout((()=>{this._responseWaitTimer=void 0;const e=this._equalUnsettledSeen&&this._responseWaitAttempts>=1;if(this._responseSeen||this._responseWaitAttempts>=3||e||!this.transport.isConnected||this._destroying)return(this._responseWaitAttempts>=3||e)&&(this._confirmed=!0),void(this._responseWaitAttempts=0);this._responseWaitAttempts++,this._sendSyncStep1(this._responseWaitFlags),this._armResponseWait(this._responseWaitFlags)}),s)}_noteResponse(e){e&&this._requestSentAt>0&&(this._rttSamples.push(Date.now()-this._requestSentAt),this._rttSamples.length>8&&this._rttSamples.shift()),this._requestSentAt=0,this._responseSeen=!0,this._responseWaitAttempts=0,void 0!==this._responseWaitTimer&&(clearTimeout(this._responseWaitTimer),this._responseWaitTimer=void 0)}_rttMinMs(){return 0===this._rttSamples.length?null:Math.min(...this._rttSamples)}_scheduleAwarenessRemoval(e,t="timeout"){if(void 0!==this._pendingAwarenessRemovalTimeoutId){const t=this._pendingAwarenessRemoval??[];for(const s of e)t.includes(s)||t.push(s);return void(this._pendingAwarenessRemoval=t)}this._pendingAwarenessRemoval=e.slice();const s=this._replySuppressionMaxDelay(),n=Math.random()*("peer-left"===t?Math.max(1e3,10*s):s);this._pendingAwarenessRemovalTimeoutId=setTimeout((()=>{this._pendingAwarenessRemovalTimeoutId=void 0,this._pendingAwarenessRemoval&&(this._broadcastAwareness(this._pendingAwarenessRemoval),this._pendingAwarenessRemoval=null)}),n)}_scanAwarenessPayload(e){const t=[],s=[];let n=!1;try{const r=a.createDecoder(e),i=a.readVarUint(r),o=this.awareness.meta.get(this.awareness.clientID)?.clock??0;for(let e=0;e<i;e++){const e=a.readVarUint(r),i=a.readVarUint(r);null===JSON.parse(a.readVarString(r))?t.push(e):(s.push(e),e===this.awareness.clientID&&i>=o&&(n=!0))}}catch{}return{removed:t,present:s,coversUs:n}}_cancelPendingAwarenessRemovalIfOverlaps(e){if(!this._pendingAwarenessRemoval)return;const t=this._pendingAwarenessRemoval.filter((t=>!e.includes(t)));t.length!==this._pendingAwarenessRemoval.length&&(t.length>0?this._pendingAwarenessRemoval=t:(void 0!==this._pendingAwarenessRemovalTimeoutId&&(clearTimeout(this._pendingAwarenessRemovalTimeoutId),this._pendingAwarenessRemovalTimeoutId=void 0),this._pendingAwarenessRemoval=null))}_cancelPendingAwarenessRemoval(){void 0!==this._pendingAwarenessRemovalTimeoutId&&(clearTimeout(this._pendingAwarenessRemovalTimeoutId),this._pendingAwarenessRemovalTimeoutId=void 0),this._pendingAwarenessRemoval=null}_sendSyncReply(e){this._tryReserveReplySlot()&&this._send(e)}_trackRemoteSeq(e,t){let s=this._remoteSeqInfo.get(e);if(s||(s={highest:-1,seen:new Set},this._remoteSeqInfo.set(e,s)),s.seen.has(t))return;s.seen.add(t),t>s.highest&&(s.highest>=0&&t>s.highest+1&&this._scheduleGapCheck(e,s.highest+1,t-1),s.highest=t);const n=s.highest-this._seqWindowSize;if(n>0)for(const e of s.seen)e<n&&s.seen.delete(e)}_scheduleGapCheck(e,t,s){if(this._gapCheckTimers.has(e))return;const n=setTimeout((()=>{this._gapCheckTimers.delete(e);const n=this._remoteSeqInfo.get(e);if(!n||this._destroying)return;let r=0;for(let e=t;e<=s;e++)n.seen.has(e)||r++;r>0&&this.transport.isConnected&&(console.warn(`[GenericProvider] Sequence gap confirmed from client ${e}: ${r} message(s) still missing after ${this._gapGraceMs}ms grace period`),this._requestResync())}),this._gapGraceMs);this._gapCheckTimers.set(e,n)}_requestResync(){if(void 0!==this._pendingResyncTimeoutId)return;this._resyncAttemptCount++;const e=Date.now();e-this._lastResyncAttemptTime>1e4&&(this._resyncAttemptCount=1),this._lastResyncAttemptTime=e;const t=Math.min(5e3,100*Math.pow(5,Math.min(this._resyncAttemptCount-1,3)));console.warn(`[GenericProvider] Resync scheduled in ${t}ms (attempt #${this._resyncAttemptCount})...`),this._pendingResyncTimeoutId=setTimeout((()=>{this._pendingResyncTimeoutId=void 0,this.transport.isConnected&&!this._destroying&&(this._sendSyncStep1(0)?this._armResponseWait(0):this._requestResync())}),t)}_tryReserveSyncSlot(){return this._tryReserveSlot(this._syncRequestTimes)}_tryReserveReplySlot(){return this._tryReserveSlot(this._syncReplyTimes)}_tryReserveSlot(e){const t=Date.now();let s=0;for(const n of e)t-n<this._syncRequestWindowMs&&(e[s++]=n);return e.length=s,!(e.length>=this._maxSyncRequestsPerWindow||(e.push(t),0))}_encodeSyncStep1(e=0){this._confirmed&&(e|=8),this._touchPeer(this.doc.clientID);const t=c.createEncoder();return c.writeVarUint(t,5),c.writeVarUint(t,1),c.writeVarUint(t,e),c.writeVarUint(t,this.doc.clientID),c.writeVarUint8Array(t,r.encodeStateVector(this.doc)),c.writeVarUint(t,this._deleteSetHash()),c.toUint8Array(t)}_encodeAck(e,t){this._touchPeer(this.doc.clientID);const s=c.createEncoder();return c.writeVarUint(s,5),c.writeVarUint(s,1),c.writeVarUint(s,2|(this._confirmed?8:0)),c.writeVarUint(s,this.doc.clientID),c.writeVarUint8Array(s,e),c.writeVarUint(s,t),c.toUint8Array(s)}_sendSyncStep1(e=0){return this._tryReserveSyncSlot()?(this._send(this._encodeSyncStep1(e)),!0):(console.warn(`[GenericProvider] Sync rate limit exceeded (${this._maxSyncRequestsPerWindow} requests per ${this._syncRequestWindowMs/1e3}s), throttling...`),!1)}_encodeUpdate(e){const t=c.createEncoder();if(this._verifyUpdates){this._touchPeer(this.doc.clientID),c.writeVarUint(t,u),c.writeVarUint(t,this._localSeqNum++),c.writeVarUint(t,this.doc.clientID),o.writeUpdate(t,e);const s=k(this.doc);c.writeVarInt(t,s)}else c.writeVarUint(t,d),o.writeUpdate(t,e);return c.toUint8Array(t)}_encodePush(e){const t=c.createEncoder();return c.writeVarUint(t,g),c.writeVarUint8Array(t,e),c.toUint8Array(t)}_sendUpdate(e){this._sendBatch([this._encodeUpdate(e),...this._takePendingAwareness()])}_sendAwarenessUpdate(e){const t=c.createEncoder();c.writeVarUint(t,1),c.writeVarUint8Array(t,i.encodeAwarenessUpdate(this.awareness,e)),this._send(c.toUint8Array(t))}_sendPubSub(e,t){if(this.transport.isConnected)try{const s=c.createEncoder();c.writeVarUint(s,2),c.writeVarString(s,e);const n=JSON.stringify(t),r=(new TextEncoder).encode(n);c.writeVarUint8Array(s,r),this._send(c.toUint8Array(s))}catch(e){console.error("Error sending pub/sub message:",e)}else console.warn("Cannot send pub/sub message: not connected")}_broadcastAwareness(e){if(0===e.length)return;const t=this._effectiveAwarenessInterval();if(t<=0)return void this._sendAwarenessNow(e);for(const t of e)this._pendingAwarenessClients.add(t);if(void 0!==this._awarenessTimeoutId)return;const s=Date.now()-this._lastAwarenessTime,n=Math.max(0,t-s);this._awarenessTimeoutId=setTimeout((()=>{this._awarenessTimeoutId=void 0,this._lastAwarenessTime=Date.now();const e=Array.from(this._pendingAwarenessClients);this._pendingAwarenessClients.clear(),e.length>0&&this._sendBatch([...this._takePendingUpdate(),this._encodeAwareness(e)])}),n)}_takePendingAwareness(){if(void 0===this._awarenessTimeoutId)return[];clearTimeout(this._awarenessTimeoutId),this._awarenessTimeoutId=void 0;const e=Array.from(this._pendingAwarenessClients);return this._pendingAwarenessClients.clear(),0===e.length?[]:(this._lastAwarenessTime=Date.now(),[this._encodeAwareness(e)])}_takePendingUpdate(){if(void 0===this._batchTimeoutId||!this._pendingUpdate)return[];clearTimeout(this._batchTimeoutId),this._batchTimeoutId=void 0,this._flushScheduled=!1;const e=this._pendingUpdate;return this._pendingUpdate=null,[this._encodeUpdate(e)]}_encodeAwareness(e){const t=c.createEncoder();return c.writeVarUint(t,1),c.writeVarUint8Array(t,i.encodeAwarenessUpdate(this.awareness,e)),c.toUint8Array(t)}_sendAwarenessNow(e){this._send(this._encodeAwareness(e))}_tryImmediateAwarenessMessage(e){if(0===e.length)return null;if(void 0!==this._awarenessTimeoutId)return null;const t=this._effectiveAwarenessInterval();if(t>0&&Date.now()-this._lastAwarenessTime<t)return null;for(const t of e)this._pendingAwarenessClients.add(t);const s=Array.from(this._pendingAwarenessClients);return this._pendingAwarenessClients.clear(),0===s.length?null:(this._lastAwarenessTime=Date.now(),this._encodeAwareness(s))}_setupBroadcastChannel(e){if(this._disableBc||"undefined"==typeof BroadcastChannel||"undefined"==typeof window)return;this._bcChannel=`yjs-${e.room}`,this._bcSubscriber=(e,t)=>{if(t===this)return;const s=new Uint8Array(e);this._handleIncomingMessage(s)},l.subscribe(this._bcChannel,this._bcSubscriber),this._bcConnected=!0;const t=c.createEncoder();c.writeVarUint(t,d),o.writeSyncStep1(t,this.doc),this._bcPublish(y(c.toUint8Array(t)));const s=c.createEncoder();if(c.writeVarUint(s,d),o.writeSyncStep2(s,this.doc),this._bcPublish(y(c.toUint8Array(s))),null!==this.awareness.getLocalState()){const e=c.createEncoder();c.writeVarUint(e,1),c.writeVarUint8Array(e,i.encodeAwarenessUpdate(this.awareness,[this.doc.clientID])),this._bcPublish(y(c.toUint8Array(e)))}}_disconnectBroadcastChannel(){if(!this._bcConnected||!this._bcSubscriber)return;const e=c.createEncoder();c.writeVarUint(e,1),c.writeVarUint8Array(e,i.encodeAwarenessUpdate(this.awareness,[this.doc.clientID],new Map)),this._bcPublish(y(c.toUint8Array(e))),l.unsubscribe(this._bcChannel,this._bcSubscriber),this._bcConnected=!1,this._bcSubscriber=void 0}_sendBatch(e){0!==e.length&&(1!==e.length?this._send(this._encodeBatch(e)):this._send(e[0]))}_encodeBatch(e){const t=c.createEncoder();c.writeVarUint(t,p);for(const s of e)c.writeVarUint8Array(t,s);return c.toUint8Array(t)}_send(e){const t=y(e);this._bcConnected&&this._bcPublish(t),this.transport.isConnected&&this._sendToTransport(t)}_bcPublish(e){l.publish(this._bcChannel,this._compressionThresholdBytes?S(0,e):e,this)}_sendToTransport(e,t){const s=this._compressionThresholdBytes;s?!m||e.length<s?this._dispatchToTransport(S(0,e),t):async function(e){const t=new CompressionStream("deflate-raw"),s=t.writable.getWriter();return s.write(e).catch((()=>{})),s.close().catch((()=>{})),b(t.readable)}(e).then((e=>{this._dispatchToTransport(S(1,e),t)})).catch((s=>{console.error("[GenericProvider] Compression failed, sending uncompressed:",s),this._dispatchToTransport(S(0,e),t)})):this._dispatchToTransport(e,t)}_dispatchToTransport(e,t){try{const s=void 0!==t&&"function"==typeof this.transport.sendTo?this.transport.sendTo(t,e):this.transport.send(e);s instanceof Promise&&s.catch((e=>{console.error("Error sending data:",e)}))}catch(e){console.error("Error sending data:",e)}}_setStatus(e){this._status=e,this.emit("status",[e])}_testSetSequenceNumber(e){this._localSeqNum=e,console.warn(`[GenericProvider TEST] Sequence number set to ${e} (MAX_SAFE_INTEGER: ${Number.MAX_SAFE_INTEGER})`)}_testGetSequenceNumber(){return this._localSeqNum}}C.AWARENESS_AUTO_MS_PER_PEER=20})),s.register("bx9uf",(function(n,r){e(n.exports,"createDeleteSetFromStructStore",(()=>E)),e(n.exports,"Doc",(()=>P)),e(n.exports,"Array",(()=>lt)),e(n.exports,"Text",(()=>It)),e(n.exports,"Map",(()=>ut)),e(n.exports,"applyUpdate",(()=>K)),e(n.exports,"decodeStateVector",(()=>$)),e(n.exports,"mergeUpdates",(()=>Ue)),e(n.exports,"encodeStateAsUpdate",(()=>J)),e(n.exports,"encodeStateVector",(()=>X)),e(n.exports,"parseUpdateMeta",(()=>Ie));var i=s("8Gyr5"),o=s("9GMWx"),c=s("bGsfJ"),a=s("96q9T"),h=s("7BTJz"),l=s("l5188"),d=s("ouOhr"),u=s("fJEwH"),p=s("jx2H5"),g=s("3Y8uz"),f=s("bcXZT"),w=s("4H1bc"),y=(w=s("4H1bc"),s("5zT0w")),_=s("9hwjE"),m=s("9okbY"),b=(s("16gRh"),s("8drkQ"),s("iRxFz")),S=s("7C9F2"),k=s("isVtz");i.ObservableV2;class v{constructor(e,t){this.clock=e,this.len=t}}class A{constructor(){this.clients=new Map}}const T=(e,t,s)=>t.clients.forEach(((t,n)=>{const r=e.doc.store.clients.get(n);if(null!=r){const n=r[r.length-1],i=n.id.clock+n.length;for(let n=0,o=t[n];n<t.length&&o.clock<i;o=t[++n])_e(e,r,o.clock,o.len,s)}})),C=(e,t)=>{const s=e.clients.get(t.client);return void 0!==s&&null!==((e,t)=>{let s=0,n=e.length-1;for(;s<=n;){const r=c.floor((s+n)/2),i=e[r],o=i.clock;if(o<=t){if(t<o+i.len)return r;s=r+1}else n=r-1}return null})(s,t.clock)},U=e=>{e.clients.forEach((e=>{let t,s;for(e.sort(((e,t)=>e.clock-t.clock)),t=1,s=1;t<e.length;t++){const n=e[s-1],r=e[t];n.clock+n.len>=r.clock?n.len=c.max(n.len,r.clock+r.len-n.clock):(s<t&&(e[s]=r),s++)}e.length=s}))},I=e=>{const t=new A;for(let s=0;s<e.length;s++)e[s].clients.forEach(((n,r)=>{if(!t.clients.has(r)){const i=n.slice();for(let t=s+1;t<e.length;t++)o.appendTo(i,e[t].clients.get(r)||[]);t.clients.set(r,i)}}));return U(t),t},x=(e,t,s,n)=>{a.setIfUndefined(e.clients,t,(()=>[])).push(new v(s,n))},D=()=>new A,E=e=>{const t=D();return e.clients.forEach(((e,s)=>{const n=[];for(let t=0;t<e.length;t++){const s=e[t];if(s.deleted){const r=s.id.clock;let i=s.length;if(t+1<e.length)for(let s=e[t+1];t+1<e.length&&s.deleted;s=e[1+ ++t])i+=s.length;n.push(new v(r,i))}}n.length>0&&t.clients.set(s,n)})),t},R=(e,t)=>{h.writeVarUint(e.restEncoder,t.clients.size),o.from(t.clients.entries()).sort(((e,t)=>t[0]-e[0])).forEach((([t,s])=>{e.resetDsCurVal(),h.writeVarUint(e.restEncoder,t);const n=s.length;h.writeVarUint(e.restEncoder,n);for(let t=0;t<n;t++){const n=s[t];e.writeDsClock(n.clock),e.writeDsLen(n.len)}}))},M=e=>{const t=new A,s=l.readVarUint(e.restDecoder);for(let n=0;n<s;n++){e.resetDsCurVal();const s=l.readVarUint(e.restDecoder),n=l.readVarUint(e.restDecoder);if(n>0){const r=a.setIfUndefined(t.clients,s,(()=>[]));for(let t=0;t<n;t++)r.push(new v(e.readDsClock(),e.readDsLen()))}}return t},V=(e,t,s)=>{const n=new A,r=l.readVarUint(e.restDecoder);for(let i=0;i<r;i++){e.resetDsCurVal();const r=l.readVarUint(e.restDecoder),i=l.readVarUint(e.restDecoder),o=s.clients.get(r)||[],c=de(s,r);for(let s=0;s<i;s++){const s=e.readDsClock(),i=s+e.readDsLen();if(s<c){c<i&&x(n,r,c,i-c);let e=pe(o,s),a=o[e];for(!a.deleted&&a.id.clock<s&&(o.splice(e+1,0,ss(t,a,s-a.id.clock)),e++);e<o.length&&(a=o[e++],a.id.clock<i);)a.deleted||(i<a.id.clock+a.length&&o.splice(e,0,ss(t,a,i-a.id.clock)),a.delete(t))}else x(n,r,s,i-s)}}if(n.clients.size>0){const e=new F;return h.writeVarUint(e.restEncoder,0),R(e,n),e.toUint8Array()}return null},O=d.uint32;class P extends i.ObservableV2{constructor({guid:e=d.uuidv4(),collectionid:t=null,gc:s=!0,gcFilter:n=(()=>!0),meta:r=null,autoLoad:i=!1,shouldLoad:o=!0}={}){super(),this.gc=s,this.gcFilter=n,this.clientID=O(),this.guid=e,this.collectionid=t,this.share=new Map,this.store=new he,this._transaction=null,this._transactionCleanups=[],this.subdocs=new Set,this._item=null,this.shouldLoad=o,this.autoLoad=i,this.meta=r,this.isLoaded=!1,this.isSynced=!1,this.isDestroyed=!1,this.whenLoaded=u.create((e=>{this.on("load",(()=>{this.isLoaded=!0,e(this)}))}));const c=()=>u.create((e=>{const t=s=>{void 0!==s&&!0!==s||(this.off("sync",t),e())};this.on("sync",t)}));this.on("sync",(e=>{!1===e&&this.isSynced&&(this.whenSynced=c()),this.isSynced=void 0===e||!0===e,this.isSynced&&!this.isLoaded&&this.emit("load",[this])})),this.whenSynced=c()}load(){const e=this._item;null===e||this.shouldLoad||Ae(e.parent.doc,(e=>{e.subdocsLoaded.add(this)}),null,!0),this.shouldLoad=!0}getSubdocs(){return this.subdocs}getSubdocGuids(){return new Set(o.from(this.subdocs).map((e=>e.guid)))}transact(e,t=null){return Ae(this,e,t)}get(e,t=Ge){const s=a.setIfUndefined(this.share,e,(()=>{const e=new t;return e._integrate(this,null),e})),n=s.constructor;if(t!==Ge&&n!==t){if(n===Ge){const n=new t;n._map=s._map,s._map.forEach((e=>{for(;null!==e;e=e.left)e.parent=n})),n._start=s._start;for(let e=n._start;null!==e;e=e.right)e.parent=n;return n._length=s._length,this.share.set(e,n),n._integrate(this,null),n}throw new Error(`Type with the name ${e} has already been defined with a different constructor`)}return s}getArray(e=""){return this.get(e,lt)}getText(e=""){return this.get(e,It)}getMap(e=""){return this.get(e,ut)}getXmlElement(e=""){return this.get(e,Et)}getXmlFragment(e=""){return this.get(e,Dt)}toJSON(){const e={};return this.share.forEach(((t,s)=>{e[s]=t.toJSON()})),e}destroy(){this.isDestroyed=!0,o.from(this.subdocs).forEach((e=>e.destroy()));const e=this._item;if(null!==e){this._item=null;const t=e.content;t.doc=new P({guid:this.guid,...t.opts,shouldLoad:!1}),t.doc._item=e,Ae(e.parent.doc,(s=>{const n=t.doc;e.deleted||s.subdocsAdded.add(n),s.subdocsRemoved.add(this)}),null,!0)}this.emit("destroyed",[!0]),this.emit("destroy",[this]),super.destroy()}}class B{constructor(e){this.restDecoder=e}resetDsCurVal(){}readDsClock(){return l.readVarUint(this.restDecoder)}readDsLen(){return l.readVarUint(this.restDecoder)}}class N extends B{readLeftID(){return ie(l.readVarUint(this.restDecoder),l.readVarUint(this.restDecoder))}readRightID(){return ie(l.readVarUint(this.restDecoder),l.readVarUint(this.restDecoder))}readClient(){return l.readVarUint(this.restDecoder)}readInfo(){return l.readUint8(this.restDecoder)}readString(){return l.readVarString(this.restDecoder)}readParentInfo(){return 1===l.readVarUint(this.restDecoder)}readTypeRef(){return l.readVarUint(this.restDecoder)}readLen(){return l.readVarUint(this.restDecoder)}readAny(){return l.readAny(this.restDecoder)}readBuf(){return p.copyUint8Array(l.readVarUint8Array(this.restDecoder))}readJSON(){return JSON.parse(l.readVarString(this.restDecoder))}readKey(){return l.readVarString(this.restDecoder)}}class L{constructor(e){this.dsCurrVal=0,this.restDecoder=e}resetDsCurVal(){this.dsCurrVal=0}readDsClock(){return this.dsCurrVal+=l.readVarUint(this.restDecoder),this.dsCurrVal}readDsLen(){const e=l.readVarUint(this.restDecoder)+1;return this.dsCurrVal+=e,e}}class q extends L{constructor(e){super(e),this.keys=[],l.readVarUint(e),this.keyClockDecoder=new l.IntDiffOptRleDecoder(l.readVarUint8Array(e)),this.clientDecoder=new l.UintOptRleDecoder(l.readVarUint8Array(e)),this.leftClockDecoder=new l.IntDiffOptRleDecoder(l.readVarUint8Array(e)),this.rightClockDecoder=new l.IntDiffOptRleDecoder(l.readVarUint8Array(e)),this.infoDecoder=new l.RleDecoder(l.readVarUint8Array(e),l.readUint8),this.stringDecoder=new l.StringDecoder(l.readVarUint8Array(e)),this.parentInfoDecoder=new l.RleDecoder(l.readVarUint8Array(e),l.readUint8),this.typeRefDecoder=new l.UintOptRleDecoder(l.readVarUint8Array(e)),this.lenDecoder=new l.UintOptRleDecoder(l.readVarUint8Array(e))}readLeftID(){return new ne(this.clientDecoder.read(),this.leftClockDecoder.read())}readRightID(){return new ne(this.clientDecoder.read(),this.rightClockDecoder.read())}readClient(){return this.clientDecoder.read()}readInfo(){return this.infoDecoder.read()}readString(){return this.stringDecoder.read()}readParentInfo(){return 1===this.parentInfoDecoder.read()}readTypeRef(){return this.typeRefDecoder.read()}readLen(){return this.lenDecoder.read()}readAny(){return l.readAny(this.restDecoder)}readBuf(){return l.readVarUint8Array(this.restDecoder)}readJSON(){return l.readAny(this.restDecoder)}readKey(){const e=this.keyClockDecoder.read();if(e<this.keys.length)return this.keys[e];{const e=this.stringDecoder.read();return this.keys.push(e),e}}}class z{constructor(){this.restEncoder=h.createEncoder()}toUint8Array(){return h.toUint8Array(this.restEncoder)}resetDsCurVal(){}writeDsClock(e){h.writeVarUint(this.restEncoder,e)}writeDsLen(e){h.writeVarUint(this.restEncoder,e)}}class W extends z{writeLeftID(e){h.writeVarUint(this.restEncoder,e.client),h.writeVarUint(this.restEncoder,e.clock)}writeRightID(e){h.writeVarUint(this.restEncoder,e.client),h.writeVarUint(this.restEncoder,e.clock)}writeClient(e){h.writeVarUint(this.restEncoder,e)}writeInfo(e){h.writeUint8(this.restEncoder,e)}writeString(e){h.writeVarString(this.restEncoder,e)}writeParentInfo(e){h.writeVarUint(this.restEncoder,e?1:0)}writeTypeRef(e){h.writeVarUint(this.restEncoder,e)}writeLen(e){h.writeVarUint(this.restEncoder,e)}writeAny(e){h.writeAny(this.restEncoder,e)}writeBuf(e){h.writeVarUint8Array(this.restEncoder,e)}writeJSON(e){h.writeVarString(this.restEncoder,JSON.stringify(e))}writeKey(e){h.writeVarString(this.restEncoder,e)}}class H{constructor(){this.restEncoder=h.createEncoder(),this.dsCurrVal=0}toUint8Array(){return h.toUint8Array(this.restEncoder)}resetDsCurVal(){this.dsCurrVal=0}writeDsClock(e){const t=e-this.dsCurrVal;this.dsCurrVal=e,h.writeVarUint(this.restEncoder,t)}writeDsLen(e){0===e&&g.unexpectedCase(),h.writeVarUint(this.restEncoder,e-1),this.dsCurrVal+=e}}class F extends H{constructor(){super(),this.keyMap=new Map,this.keyClock=0,this.keyClockEncoder=new h.IntDiffOptRleEncoder,this.clientEncoder=new h.UintOptRleEncoder,this.leftClockEncoder=new h.IntDiffOptRleEncoder,this.rightClockEncoder=new h.IntDiffOptRleEncoder,this.infoEncoder=new h.RleEncoder(h.writeUint8),this.stringEncoder=new h.StringEncoder,this.parentInfoEncoder=new h.RleEncoder(h.writeUint8),this.typeRefEncoder=new h.UintOptRleEncoder,this.lenEncoder=new h.UintOptRleEncoder}toUint8Array(){const e=h.createEncoder();return h.writeVarUint(e,0),h.writeVarUint8Array(e,this.keyClockEncoder.toUint8Array()),h.writeVarUint8Array(e,this.clientEncoder.toUint8Array()),h.writeVarUint8Array(e,this.leftClockEncoder.toUint8Array()),h.writeVarUint8Array(e,this.rightClockEncoder.toUint8Array()),h.writeVarUint8Array(e,h.toUint8Array(this.infoEncoder)),h.writeVarUint8Array(e,this.stringEncoder.toUint8Array()),h.writeVarUint8Array(e,h.toUint8Array(this.parentInfoEncoder)),h.writeVarUint8Array(e,this.typeRefEncoder.toUint8Array()),h.writeVarUint8Array(e,this.lenEncoder.toUint8Array()),h.writeUint8Array(e,h.toUint8Array(this.restEncoder)),h.toUint8Array(e)}writeLeftID(e){this.clientEncoder.write(e.client),this.leftClockEncoder.write(e.clock)}writeRightID(e){this.clientEncoder.write(e.client),this.rightClockEncoder.write(e.clock)}writeClient(e){this.clientEncoder.write(e)}writeInfo(e){this.infoEncoder.write(e)}writeString(e){this.stringEncoder.write(e)}writeParentInfo(e){this.parentInfoEncoder.write(e?1:0)}writeTypeRef(e){this.typeRefEncoder.write(e)}writeLen(e){this.lenEncoder.write(e)}writeAny(e){h.writeAny(this.restEncoder,e)}writeBuf(e){h.writeVarUint8Array(this.restEncoder,e)}writeJSON(e){h.writeAny(this.restEncoder,e)}writeKey(e){const t=this.keyMap.get(e);void 0===t?(this.keyClockEncoder.write(this.keyClock++),this.stringEncoder.write(e)):this.keyClockEncoder.write(t)}}const j=(e,t,s)=>{const n=new Map;s.forEach(((e,s)=>{de(t,s)>e&&n.set(s,e)})),le(t).forEach(((e,t)=>{s.has(t)||n.set(t,0)})),h.writeVarUint(e.restEncoder,n.size),o.from(n.entries()).sort(((e,t)=>t[0]-e[0])).forEach((([s,n])=>{((e,t,s,n)=>{n=c.max(n,t[0].id.clock);const r=pe(t,n);h.writeVarUint(e.restEncoder,t.length-r),e.writeClient(s),h.writeVarUint(e.restEncoder,n);const i=t[r];i.write(e,n-i.id.clock);for(let s=r+1;s<t.length;s++)t[s].write(e,0)})(e,t.clients.get(s),s,n)}))},G=(e,t,s,n=q)=>{const r=l.createDecoder(t);((e,t,s,n=new q(e))=>{Ae(t,(e=>{e.local=!1;let t=!1;const s=e.doc,r=s.store,i=((e,t)=>{const s=a.create(),n=l.readVarUint(e.restDecoder);for(let r=0;r<n;r++){const n=l.readVarUint(e.restDecoder),r=new Array(n),i=e.readClient();let o=l.readVarUint(e.restDecoder);s.set(i,{i:0,refs:r});for(let s=0;s<n;s++){const n=e.readInfo();switch(f.BITS5&n){case 0:{const t=e.readLen();r[s]=new Pt(ie(i,o),t),o+=t;break}case 10:{const t=l.readVarUint(e.restDecoder);r[s]=new os(ie(i,o),t),o+=t;break}default:{const c=!(n&(f.BIT7|f.BIT8)),a=new ns(ie(i,o),null,(n&f.BIT8)===f.BIT8?e.readLeftID():null,null,(n&f.BIT7)===f.BIT7?e.readRightID():null,c?e.readParentInfo()?t.get(e.readString()):e.readLeftID():null,c&&(n&f.BIT6)===f.BIT6?e.readString():null,rs(e,n));r[s]=a,o+=a.length}}}}return s})(n,s),c=((e,t,s)=>{const n=[];let r=o.from(s.keys()).sort(((e,t)=>e-t));if(0===r.length)return null;const i=()=>{if(0===r.length)return null;let e=s.get(r[r.length-1]);for(;e.refs.length===e.i;){if(r.pop(),!(r.length>0))return null;e=s.get(r[r.length-1])}return e};let c=i();if(null===c)return null;const l=new he,d=new Map,u=(e,t)=>{const s=d.get(e);(null==s||s>t)&&d.set(e,t)};let p=c.refs[c.i++];const g=new Map,f=()=>{for(const e of n){const t=e.id.client,n=s.get(t);n?(n.i--,l.clients.set(t,n.refs.slice(n.i)),s.delete(t),n.i=0,n.refs=[]):l.clients.set(t,[e]),r=r.filter((e=>e!==t))}n.length=0};for(;;){if(p.constructor!==os){const r=a.setIfUndefined(g,p.id.client,(()=>de(t,p.id.client)))-p.id.clock;if(r<0)n.push(p),u(p.id.client,p.id.clock-1),f();else{const i=p.getMissing(e,t);if(null!==i){n.push(p);const e=s.get(i)||{refs:[],i:0};if(e.refs.length!==e.i){p=e.refs[e.i++];continue}u(i,de(t,i)),f()}else(0===r||r<p.length)&&(p.integrate(e,r),g.set(p.id.client,p.id.clock+p.length))}}if(n.length>0)p=n.pop();else if(null!==c&&c.i<c.refs.length)p=c.refs[c.i++];else{if(c=i(),null===c)break;p=c.refs[c.i++]}}if(l.clients.size>0){const e=new F;return j(e,l,new Map),h.writeVarUint(e.restEncoder,0),{missing:d,update:e.toUint8Array()}}return null})(e,r,i),d=r.pendingStructs;if(d){for(const[e,s]of d.missing)if(s<de(r,e)){t=!0;break}if(c){for(const[e,t]of c.missing){const s=d.missing.get(e);(null==s||s>t)&&d.missing.set(e,t)}d.update=De([d.update,c.update])}}else r.pendingStructs=c;const u=V(n,e,r);if(r.pendingDs){const t=new q(l.createDecoder(r.pendingDs));l.readVarUint(t.restDecoder);const s=V(t,e,r);r.pendingDs=u&&s?De([u,s]):u||s}else r.pendingDs=u;if(t){const t=r.pendingStructs.update;r.pendingStructs=null,G(e.doc,t)}}),s,!1)})(r,e,s,new n(r))},K=(e,t,s)=>G(e,t,s,N),J=(e,t)=>((e,t=new Uint8Array([0]),s=new F)=>{((e,t,s=new Map)=>{j(e,t.store,s),R(e,E(t.store))})(s,e,$(t));const n=[s.toUint8Array()];if(e.store.pendingDs&&n.push(e.store.pendingDs),e.store.pendingStructs&&n.push(Ee(e.store.pendingStructs.update,t)),n.length>1){if(s.constructor===W)return Ue(n.map(((e,t)=>0===t?e:Oe(e))));if(s.constructor===F)return De(n)}return n[0]})(e,t,new W),$=e=>(e=>{const t=new Map,s=l.readVarUint(e.restDecoder);for(let n=0;n<s;n++){const s=l.readVarUint(e.restDecoder),n=l.readVarUint(e.restDecoder);t.set(s,n)}return t})(new B(l.createDecoder(e))),Y=(e,t)=>(h.writeVarUint(e.restEncoder,t.size),o.from(t.entries()).sort(((e,t)=>t[0]-e[0])).forEach((([t,s])=>{h.writeVarUint(e.restEncoder,t),h.writeVarUint(e.restEncoder,s)})),e),X=e=>((e,t=new H)=>(e instanceof Map?Y(t,e):((e,t)=>{Y(e,le(t.store))})(t,e),t.toUint8Array()))(e,new z);class Q{constructor(){this.l=[]}}const Z=()=>new Q,ee=(e,t)=>e.l.push(t),te=(e,t)=>{const s=e.l,n=s.length;e.l=s.filter((e=>t!==e)),n===e.l.length&&console.error("[yjs] Tried to remove event handler that doesn't exist.")},se=(e,t,s)=>w.callAll(e.l,[t,s]);class ne{constructor(e,t){this.client=e,this.clock=t}}const re=(e,t)=>e===t||null!==e&&null!==t&&e.client===t.client&&e.clock===t.clock,ie=(e,t)=>new ne(e,t);class oe{constructor(e,t){this.ds=e,this.sv=t}}const ce=(((e,t)=>{new oe(e,t)})(D(),new Map),(e,t)=>void 0===t?!e.deleted:t.sv.has(e.id.client)&&(t.sv.get(e.id.client)||0)>e.id.clock&&!C(t.ds,e.id)),ae=(e,t)=>{const s=a.setIfUndefined(e.meta,ae,y.create),n=e.doc.store;s.has(t)||(t.sv.forEach(((t,s)=>{t<de(n,s)&&we(e,ie(s,t))})),T(e,t.ds,(e=>{})),s.add(t))};class he{constructor(){this.clients=new Map,this.pendingStructs=null,this.pendingDs=null}}const le=e=>{const t=new Map;return e.clients.forEach(((e,s)=>{const n=e[e.length-1];t.set(s,n.id.clock+n.length)})),t},de=(e,t)=>{const s=e.clients.get(t);if(void 0===s)return 0;const n=s[s.length-1];return n.id.clock+n.length},ue=(e,t)=>{let s=e.clients.get(t.id.client);if(void 0===s)s=[],e.clients.set(t.id.client,s);else{const e=s[s.length-1];if(e.id.clock+e.length!==t.id.clock)throw g.unexpectedCase()}s.push(t)},pe=(e,t)=>{let s=0,n=e.length-1,r=e[n],i=r.id.clock;if(i===t)return n;let o=c.floor(t/(i+r.length-1)*n);for(;s<=n;){if(r=e[o],i=r.id.clock,i<=t){if(t<i+r.length)return o;s=o+1}else n=o-1;o=c.floor((s+n)/2)}throw g.unexpectedCase()},ge=(e,t)=>{const s=e.clients.get(t.client);return s[pe(s,t.clock)]},fe=(e,t,s)=>{const n=pe(t,s),r=t[n];return r.id.clock<s&&r instanceof ns?(t.splice(n+1,0,ss(e,r,s-r.id.clock)),n+1):n},we=(e,t)=>{const s=e.doc.store.clients.get(t.client);return s[fe(e,s,t.clock)]},ye=(e,t,s)=>{const n=t.clients.get(s.client),r=pe(n,s.clock),i=n[r];return s.clock!==i.id.clock+i.length-1&&i.constructor!==Pt&&n.splice(r+1,0,ss(e,i,s.clock-i.id.clock+1)),i},_e=(e,t,s,n,r)=>{if(0===n)return;const i=s+n;let o,c=fe(e,t,s);do{o=t[c++],i<o.id.clock+o.length&&fe(e,t,i),r(o)}while(c<t.length&&t[c].id.clock<i)};class me{constructor(e,t,s){this.doc=e,this.deleteSet=new A,this.beforeState=le(e.store),this.afterState=new Map,this.changed=new Map,this.changedParentTypes=new Map,this._mergeStructs=[],this.origin=t,this.meta=new Map,this.local=s,this.subdocsAdded=new Set,this.subdocsRemoved=new Set,this.subdocsLoaded=new Set,this._needFormattingCleanup=!1}}const be=(e,t)=>!(0===t.deleteSet.clients.size&&!a.any(t.afterState,((e,s)=>t.beforeState.get(s)!==e))||(U(t.deleteSet),((e,t)=>{j(e,t.doc.store,t.beforeState)})(e,t),R(e,t.deleteSet),0)),Se=(e,t,s)=>{const n=t._item;(null===n||n.id.clock<(e.beforeState.get(n.id.client)||0)&&!n.deleted)&&a.setIfUndefined(e.changed,t,y.create).add(s)},ke=(e,t)=>{let s=e[t],n=e[t-1],r=t;for(;r>0&&n.deleted===s.deleted&&n.constructor===s.constructor&&n.mergeWith(s);s=n,n=e[--r-1])s instanceof ns&&null!==s.parentSub&&s.parent._map.get(s.parentSub)===s&&s.parent._map.set(s.parentSub,n);const i=t-r;return i&&e.splice(t+1-i,i),i},ve=(e,t)=>{if(t<e.length){const s=e[t],n=s.doc,r=n.store,i=s.deleteSet,o=s._mergeStructs;try{U(i),s.afterState=le(s.doc.store),n.emit("beforeObserverCalls",[s,n]);const e=[];s.changed.forEach(((t,n)=>e.push((()=>{null!==n._item&&n._item.deleted||n._callObserver(s,t)})))),e.push((()=>{s.changedParentTypes.forEach(((t,n)=>{n._dEH.l.length>0&&(null===n._item||!n._item.deleted)&&((t=t.filter((e=>null===e.target._item||!e.target._item.deleted))).forEach((e=>{e.currentTarget=n,e._path=null})),t.sort(((e,t)=>e.path.length-t.path.length)),e.push((()=>{se(n._dEH,t,s)})))})),e.push((()=>n.emit("afterTransaction",[s,n]))),e.push((()=>{s._needFormattingCleanup&&Tt(s)}))})),(0,w.callAll)(e,[])}finally{n.gc&&((e,t,s)=>{for(const[n,r]of e.clients.entries()){const e=t.clients.get(n);for(let n=r.length-1;n>=0;n--){const i=r[n],o=i.clock+i.len;for(let n=pe(e,i.clock),r=e[n];n<e.length&&r.id.clock<o;r=e[++n]){const r=e[n];if(i.clock+i.len<=r.id.clock)break;r instanceof ns&&r.deleted&&!r.keep&&s(r)&&r.gc(t,!1)}}}})(i,r,n.gcFilter),((e,t)=>{e.clients.forEach(((e,s)=>{const n=t.clients.get(s);for(let t=e.length-1;t>=0;t--){const s=e[t];for(let e=c.min(n.length-1,1+pe(n,s.clock+s.len-1)),t=n[e];e>0&&t.id.clock>=s.clock;t=n[e])e-=1+ke(n,e)}}))})(i,r),s.afterState.forEach(((e,t)=>{const n=s.beforeState.get(t)||0;if(n!==e){const e=r.clients.get(t),s=c.max(pe(e,n),1);for(let t=e.length-1;t>=s;)t-=1+ke(e,t)}}));for(let e=o.length-1;e>=0;e--){const{client:t,clock:s}=o[e].id,n=r.clients.get(t),i=pe(n,s);i+1<n.length&&ke(n,i+1)>1||i>0&&ke(n,i)}if(s.local||s.afterState.get(n.clientID)===s.beforeState.get(n.clientID)||(_.print(m.ORANGE,m.BOLD,"[yjs] ",m.UNBOLD,m.RED,"Changed the client-id because another client seems to be using it."),n.clientID=O()),n.emit("afterTransactionCleanup",[s,n]),n._observers.has("update")){const e=new W;be(e,s)&&n.emit("update",[e.toUint8Array(),s.origin,n,s])}if(n._observers.has("updateV2")){const e=new F;be(e,s)&&n.emit("updateV2",[e.toUint8Array(),s.origin,n,s])}const{subdocsAdded:a,subdocsLoaded:h,subdocsRemoved:l}=s;(a.size>0||l.size>0||h.size>0)&&(a.forEach((e=>{e.clientID=n.clientID,null==e.collectionid&&(e.collectionid=n.collectionid),n.subdocs.add(e)})),l.forEach((e=>n.subdocs.delete(e))),n.emit("subdocs",[{loaded:h,added:a,removed:l},n,s]),l.forEach((e=>e.destroy()))),e.length<=t+1?(n._transactionCleanups=[],n.emit("afterAllTransactions",[n,e])):ve(e,t+1)}}},Ae=(e,t,s=null,n=!0)=>{const r=e._transactionCleanups;let i=!1,o=null;null===e._transaction&&(i=!0,e._transaction=new me(e,s,n),r.push(e._transaction),1===r.length&&e.emit("beforeAllTransactions",[e]),e.emit("beforeTransaction",[e._transaction,e]));try{o=t(e._transaction)}finally{if(i){const t=e._transaction===r[0];e._transaction=null,t&&ve(r,0)}}return o};i.ObservableV2;class Te{constructor(e,t){this.gen=function*(e){const t=l.readVarUint(e.restDecoder);for(let s=0;s<t;s++){const t=l.readVarUint(e.restDecoder),s=e.readClient();let n=l.readVarUint(e.restDecoder);for(let r=0;r<t;r++){const t=e.readInfo();if(10===t){const t=l.readVarUint(e.restDecoder);yield new os(ie(s,n),t),n+=t}else if(f.BITS5&t){const r=!(t&(f.BIT7|f.BIT8)),i=new ns(ie(s,n),null,(t&f.BIT8)===f.BIT8?e.readLeftID():null,null,(t&f.BIT7)===f.BIT7?e.readRightID():null,r?e.readParentInfo()?e.readString():e.readLeftID():null,r&&(t&f.BIT6)===f.BIT6?e.readString():null,rs(e,t));yield i,n+=i.length}else{const t=e.readLen();yield new Pt(ie(s,n),t),n+=t}}}}(e),this.curr=null,this.done=!1,this.filterSkips=t,this.next()}next(){do{this.curr=this.gen.next().value||null}while(this.filterSkips&&null!==this.curr&&this.curr.constructor===os);return this.curr}}class Ce{constructor(e){this.currClient=0,this.startClock=0,this.written=0,this.encoder=e,this.clientStructs=[]}}const Ue=e=>De(e,N,W),Ie=e=>((e,t=q)=>{const s=new Map,n=new Map,r=new Te(new t(l.createDecoder(e)),!1);let i=r.curr;if(null!==i){let e=i.id.client,t=i.id.clock;for(s.set(e,t);null!==i;i=r.next())e!==i.id.client&&(n.set(e,t),s.set(i.id.client,i.id.clock),e=i.id.client),t=i.id.clock+i.length;n.set(e,t)}return{from:s,to:n}})(e,N),xe=(e,t)=>{if(e.constructor===Pt){const{client:s,clock:n}=e.id;return new Pt(ie(s,n+t),e.length-t)}if(e.constructor===os){const{client:s,clock:n}=e.id;return new os(ie(s,n+t),e.length-t)}{const s=e,{client:n,clock:r}=s.id;return new ns(ie(n,r+t),null,ie(n,r+t-1),null,s.rightOrigin,s.parent,s.parentSub,s.content.splice(t))}},De=(e,t=q,s=F)=>{if(1===e.length)return e[0];const n=e.map((e=>new t(l.createDecoder(e))));let r=n.map((e=>new Te(e,!0))),i=null;const o=new s,c=new Ce(o);for(;r=r.filter((e=>null!==e.curr)),r.sort(((e,t)=>{if(e.curr.id.client===t.curr.id.client){const s=e.curr.id.clock-t.curr.id.clock;return 0===s?e.curr.constructor===t.curr.constructor?0:e.curr.constructor===os?1:-1:s}return t.curr.id.client-e.curr.id.client})),0!==r.length;){const e=r[0],t=e.curr.id.client;if(null!==i){let s=e.curr,n=!1;for(;null!==s&&s.id.clock+s.length<=i.struct.id.clock+i.struct.length&&s.id.client>=i.struct.id.client;)s=e.next(),n=!0;if(null===s||s.id.client!==t||n&&s.id.clock>i.struct.id.clock+i.struct.length)continue;if(t!==i.struct.id.client)Me(c,i.struct,i.offset),i={struct:s,offset:0},e.next();else if(i.struct.id.clock+i.struct.length<s.id.clock)if(i.struct.constructor===os)i.struct.length=s.id.clock+s.length-i.struct.id.clock;else{Me(c,i.struct,i.offset);const e=s.id.clock-i.struct.id.clock-i.struct.length;i={struct:new os(ie(t,i.struct.id.clock+i.struct.length),e),offset:0}}else{const t=i.struct.id.clock+i.struct.length-s.id.clock;t>0&&(i.struct.constructor===os?i.struct.length-=t:s=xe(s,t)),i.struct.mergeWith(s)||(Me(c,i.struct,i.offset),i={struct:s,offset:0},e.next())}}else i={struct:e.curr,offset:0},e.next();for(let s=e.curr;null!==s&&s.id.client===t&&s.id.clock===i.struct.id.clock+i.struct.length&&s.constructor!==os;s=e.next())Me(c,i.struct,i.offset),i={struct:s,offset:0}}null!==i&&(Me(c,i.struct,i.offset),i=null),Ve(c);const a=n.map((e=>M(e))),h=I(a);return R(o,h),o.toUint8Array()},Ee=(e,t,s=q,n=F)=>{const r=$(t),i=new n,o=new Ce(i),a=new s(l.createDecoder(e)),h=new Te(a,!1);for(;h.curr;){const e=h.curr,t=e.id.client,s=r.get(t)||0;if(h.curr.constructor!==os)if(e.id.clock+e.length>s)for(Me(o,e,c.max(s-e.id.clock,0)),h.next();h.curr&&h.curr.id.client===t;)Me(o,h.curr,0),h.next();else for(;h.curr&&h.curr.id.client===t&&h.curr.id.clock+h.curr.length<=s;)h.next();else h.next()}Ve(o);const d=M(a);return R(i,d),i.toUint8Array()},Re=e=>{e.written>0&&(e.clientStructs.push({written:e.written,restEncoder:h.toUint8Array(e.encoder.restEncoder)}),e.encoder.restEncoder=h.createEncoder(),e.written=0)},Me=(e,t,s)=>{e.written>0&&e.currClient!==t.id.client&&Re(e),0===e.written&&(e.currClient=t.id.client,e.encoder.writeClient(t.id.client),h.writeVarUint(e.encoder.restEncoder,t.id.clock+s)),t.write(e.encoder,s),e.written++},Ve=e=>{Re(e);const t=e.encoder.restEncoder;h.writeVarUint(t,e.clientStructs.length);for(let s=0;s<e.clientStructs.length;s++){const n=e.clientStructs[s];h.writeVarUint(t,n.written),h.writeUint8Array(t,n.restEncoder)}},Oe=e=>((e,t,s,n)=>{const r=new s(l.createDecoder(e)),i=new Te(r,!1),o=new n,c=new Ce(o);for(let e=i.curr;null!==e;e=i.next())Me(c,t(e),0);Ve(c);const a=M(r);return R(o,a),o.toUint8Array()})(e,w.id,q,W),Pe="You must not compute changes after the event-handler fired.";class Be{constructor(e,t){this.target=e,this.currentTarget=e,this.transaction=t,this._changes=null,this._keys=null,this._delta=null,this._path=null}get path(){return this._path||(this._path=Ne(this.currentTarget,this.target))}deletes(e){return C(this.transaction.deleteSet,e.id)}get keys(){if(null===this._keys){if(0===this.transaction.doc._transactionCleanups.length)throw g.create(Pe);const e=new Map,t=this.target;this.transaction.changed.get(t).forEach((s=>{if(null!==s){const n=t._map.get(s);let r,i;if(this.adds(n)){let e=n.left;for(;null!==e&&this.adds(e);)e=e.left;if(this.deletes(n)){if(null===e||!this.deletes(e))return;r="delete",i=o.last(e.content.getContent())}else null!==e&&this.deletes(e)?(r="update",i=o.last(e.content.getContent())):(r="add",i=void 0)}else{if(!this.deletes(n))return;r="delete",i=o.last(n.content.getContent())}e.set(s,{action:r,oldValue:i})}})),this._keys=e}return this._keys}get delta(){return this.changes.delta}adds(e){return e.id.clock>=(this.transaction.beforeState.get(e.id.client)||0)}get changes(){let e=this._changes;if(null===e){if(0===this.transaction.doc._transactionCleanups.length)throw g.create(Pe);const t=this.target,s=y.create(),n=y.create(),r=[];if(e={added:s,deleted:n,delta:r,keys:this.keys},this.transaction.changed.get(t).has(null)){let e=null;const i=()=>{e&&r.push(e)};for(let r=t._start;null!==r;r=r.right)r.deleted?this.deletes(r)&&!this.adds(r)&&(null!==e&&void 0!==e.delete||(i(),e={delete:0}),e.delete+=r.length,n.add(r)):this.adds(r)?(null!==e&&void 0!==e.insert||(i(),e={insert:[]}),e.insert=e.insert.concat(r.content.getContent()),s.add(r)):(null!==e&&void 0!==e.retain||(i(),e={retain:0}),e.retain+=r.length);null!==e&&void 0===e.retain&&i()}this._changes=e}return e}}const Ne=(e,t)=>{const s=[];for(;null!==t._item&&t!==e;){if(null!==t._item.parentSub)s.unshift(t._item.parentSub);else{let e=0,n=t._item.parent._start;for(;n!==t._item&&null!==n;)!n.deleted&&n.countable&&(e+=n.length),n=n.right;s.unshift(e)}t=t._item.parent}return s},Le=()=>{_.warn("Invalid access: Add Yjs type to a document before reading data.")};let qe=0;class ze{constructor(e,t){e.marker=!0,this.p=e,this.index=t,this.timestamp=qe++}}const We=(e,t,s)=>{e.p.marker=!1,e.p=t,t.marker=!0,e.index=s,e.timestamp=qe++},He=(e,t)=>{if(null===e._start||0===t||null===e._searchMarker)return null;const s=0===e._searchMarker.length?null:e._searchMarker.reduce(((e,s)=>c.abs(t-e.index)<c.abs(t-s.index)?e:s));let n=e._start,r=0;for(null!==s&&(n=s.p,r=s.index,(e=>{e.timestamp=qe++})(s));null!==n.right&&r<t;){if(!n.deleted&&n.countable){if(t<r+n.length)break;r+=n.length}n=n.right}for(;null!==n.left&&r>t;)n=n.left,!n.deleted&&n.countable&&(r-=n.length);for(;null!==n.left&&n.left.id.client===n.id.client&&n.left.id.clock+n.left.length===n.id.clock;)n=n.left,!n.deleted&&n.countable&&(r-=n.length);return null!==s&&c.abs(s.index-r)<n.parent.length/80?(We(s,n,r),s):((e,t,s)=>{if(e.length>=80){const n=e.reduce(((e,t)=>e.timestamp<t.timestamp?e:t));return We(n,t,s),n}{const n=new ze(t,s);return e.push(n),n}})(e._searchMarker,n,r)},Fe=(e,t,s)=>{for(let n=e.length-1;n>=0;n--){const r=e[n];if(s>0){let t=r.p;for(t.marker=!1;t&&(t.deleted||!t.countable);)t=t.left,t&&!t.deleted&&t.countable&&(r.index-=t.length);if(null===t||!0===t.marker){e.splice(n,1);continue}r.p=t,t.marker=!0}(t<r.index||s>0&&t===r.index)&&(r.index=c.max(t,r.index+s))}},je=(e,t,s)=>{const n=e,r=t.changedParentTypes;for(;a.setIfUndefined(r,e,(()=>[])).push(s),null!==e._item;)e=e._item.parent;se(n._eH,s,t)};class Ge{constructor(){this._item=null,this._map=new Map,this._start=null,this.doc=null,this._length=0,this._eH=Z(),this._dEH=Z(),this._searchMarker=null}get parent(){return this._item?this._item.parent:null}_integrate(e,t){this.doc=e,this._item=t}_copy(){throw g.methodUnimplemented()}clone(){throw g.methodUnimplemented()}_write(e){}get _first(){let e=this._start;for(;null!==e&&e.deleted;)e=e.right;return e}_callObserver(e,t){!e.local&&this._searchMarker&&(this._searchMarker.length=0)}observe(e){ee(this._eH,e)}observeDeep(e){ee(this._dEH,e)}unobserve(e){te(this._eH,e)}unobserveDeep(e){te(this._dEH,e)}toJSON(){}}const Ke=(e,t,s)=>{e.doc??Le(),t<0&&(t=e._length+t),s<0&&(s=e._length+s);let n=s-t;const r=[];let i=e._start;for(;null!==i&&n>0;){if(i.countable&&!i.deleted){const e=i.content.getContent();if(e.length<=t)t-=e.length;else{for(let s=t;s<e.length&&n>0;s++)r.push(e[s]),n--;t=0}}i=i.right}return r},Je=e=>{e.doc??Le();const t=[];let s=e._start;for(;null!==s;){if(s.countable&&!s.deleted){const e=s.content.getContent();for(let s=0;s<e.length;s++)t.push(e[s])}s=s.right}return t},$e=(e,t)=>{let s=0,n=e._start;for(e.doc??Le();null!==n;){if(n.countable&&!n.deleted){const r=n.content.getContent();for(let n=0;n<r.length;n++)t(r[n],s++,e)}n=n.right}},Ye=(e,t)=>{const s=[];return $e(e,((n,r)=>{s.push(t(n,r,e))})),s},Xe=e=>{let t=e._start,s=null,n=0;return{[Symbol.iterator](){return this},next:()=>{if(null===s){for(;null!==t&&t.deleted;)t=t.right;if(null===t)return{done:!0,value:void 0};s=t.content.getContent(),n=0,t=t.right}const e=s[n++];return s.length<=n&&(s=null),{done:!1,value:e}}}},Qe=(e,t)=>{e.doc??Le();const s=He(e,t);let n=e._start;for(null!==s&&(n=s.p,t-=s.index);null!==n;n=n.right)if(!n.deleted&&n.countable){if(t<n.length)return n.content.getContent()[t];t-=n.length}},Ze=(e,t,s,n)=>{let r=s;const i=e.doc,o=i.clientID,c=i.store,a=null===s?t._start:s.right;let h=[];const l=()=>{h.length>0&&(r=new ns(ie(o,de(c,o)),r,r&&r.lastId,a,a&&a.id,t,null,new jt(h)),r.integrate(e,0),h=[])};n.forEach((s=>{if(null===s)h.push(s);else switch(s.constructor){case Number:case Object:case Boolean:case Array:case String:h.push(s);break;default:switch(l(),s.constructor){case Uint8Array:case ArrayBuffer:r=new ns(ie(o,de(c,o)),r,r&&r.lastId,a,a&&a.id,t,null,new Bt(new Uint8Array(s))),r.integrate(e,0);break;case P:r=new ns(ie(o,de(c,o)),r,r&&r.lastId,a,a&&a.id,t,null,new qt(s)),r.integrate(e,0);break;default:if(!(s instanceof Ge))throw new Error("Unexpected content type in insert operation");r=new ns(ie(o,de(c,o)),r,r&&r.lastId,a,a&&a.id,t,null,new ts(s)),r.integrate(e,0)}}})),l()},et=()=>g.create("Length exceeded!"),tt=(e,t,s,n)=>{if(s>t._length)throw et();if(0===s)return t._searchMarker&&Fe(t._searchMarker,s,n.length),Ze(e,t,null,n);const r=s,i=He(t,s);let o=t._start;for(null!==i&&(o=i.p,0==(s-=i.index)&&(o=o.prev,s+=o&&o.countable&&!o.deleted?o.length:0));null!==o;o=o.right)if(!o.deleted&&o.countable){if(s<=o.length){s<o.length&&we(e,ie(o.id.client,o.id.clock+s));break}s-=o.length}return t._searchMarker&&Fe(t._searchMarker,r,n.length),Ze(e,t,o,n)},st=(e,t,s,n)=>{if(0===n)return;const r=s,i=n,o=He(t,s);let c=t._start;for(null!==o&&(c=o.p,s-=o.index);null!==c&&s>0;c=c.right)!c.deleted&&c.countable&&(s<c.length&&we(e,ie(c.id.client,c.id.clock+s)),s-=c.length);for(;n>0&&null!==c;)c.deleted||(n<c.length&&we(e,ie(c.id.client,c.id.clock+n)),c.delete(e),n-=c.length),c=c.right;if(n>0)throw et();t._searchMarker&&Fe(t._searchMarker,r,-i+n)},nt=(e,t,s)=>{const n=t._map.get(s);void 0!==n&&n.delete(e)},rt=(e,t,s,n)=>{const r=t._map.get(s)||null,i=e.doc,o=i.clientID;let c;if(null==n)c=new jt([n]);else switch(n.constructor){case Number:case Object:case Boolean:case Array:case String:case Date:case BigInt:c=new jt([n]);break;case Uint8Array:c=new Bt(n);break;case P:c=new qt(n);break;default:if(!(n instanceof Ge))throw new Error("Unexpected content type");c=new ts(n)}new ns(ie(o,de(i.store,o)),r,r&&r.lastId,null,null,t,s,c).integrate(e,0)},it=(e,t)=>{e.doc??Le();const s=e._map.get(t);return void 0===s||s.deleted?void 0:s.content.getContent()[s.length-1]},ot=e=>{const t={};return e.doc??Le(),e._map.forEach(((e,s)=>{e.deleted||(t[s]=e.content.getContent()[e.length-1])})),t},ct=(e,t)=>{e.doc??Le();const s=e._map.get(t);return void 0!==s&&!s.deleted},at=e=>(e.doc??Le(),b.iteratorFilter(e._map.entries(),(e=>!e[1].deleted)));class ht extends Be{}class lt extends Ge{constructor(){super(),this._prelimContent=[],this._searchMarker=[]}static from(e){const t=new lt;return t.push(e),t}_integrate(e,t){super._integrate(e,t),this.insert(0,this._prelimContent),this._prelimContent=null}_copy(){return new lt}clone(){const e=new lt;return e.insert(0,this.toArray().map((e=>e instanceof Ge?e.clone():e))),e}get length(){return this.doc??Le(),this._length}_callObserver(e,t){super._callObserver(e,t),je(this,e,new ht(this,e))}insert(e,t){null!==this.doc?Ae(this.doc,(s=>{tt(s,this,e,t)})):this._prelimContent.splice(e,0,...t)}push(e){null!==this.doc?Ae(this.doc,(t=>{((e,t,s)=>{let n=(t._searchMarker||[]).reduce(((e,t)=>t.index>e.index?t:e),{index:0,p:t._start}).p;if(n)for(;n.right;)n=n.right;Ze(e,t,n,s)})(t,this,e)})):this._prelimContent.push(...e)}unshift(e){this.insert(0,e)}delete(e,t=1){null!==this.doc?Ae(this.doc,(s=>{st(s,this,e,t)})):this._prelimContent.splice(e,t)}get(e){return Qe(this,e)}toArray(){return Je(this)}slice(e=0,t=this.length){return Ke(this,e,t)}toJSON(){return this.map((e=>e instanceof Ge?e.toJSON():e))}map(e){return Ye(this,e)}forEach(e){$e(this,e)}[Symbol.iterator](){return Xe(this)}_write(e){e.writeTypeRef(Jt)}}class dt extends Be{constructor(e,t,s){super(e,t),this.keysChanged=s}}class ut extends Ge{constructor(e){super(),this._prelimContent=null,this._prelimContent=void 0===e?new Map:new Map(e)}_integrate(e,t){super._integrate(e,t),this._prelimContent.forEach(((e,t)=>{this.set(t,e)})),this._prelimContent=null}_copy(){return new ut}clone(){const e=new ut;return this.forEach(((t,s)=>{e.set(s,t instanceof Ge?t.clone():t)})),e}_callObserver(e,t){je(this,e,new dt(this,e,t))}toJSON(){this.doc??Le();const e={};return this._map.forEach(((t,s)=>{if(!t.deleted){const n=t.content.getContent()[t.length-1];e[s]=n instanceof Ge?n.toJSON():n}})),e}get size(){return[...at(this)].length}keys(){return b.iteratorMap(at(this),(e=>e[0]))}values(){return b.iteratorMap(at(this),(e=>e[1].content.getContent()[e[1].length-1]))}entries(){return b.iteratorMap(at(this),(e=>[e[0],e[1].content.getContent()[e[1].length-1]]))}forEach(e){this.doc??Le(),this._map.forEach(((t,s)=>{t.deleted||e(t.content.getContent()[t.length-1],s,this)}))}[Symbol.iterator](){return this.entries()}delete(e){null!==this.doc?Ae(this.doc,(t=>{nt(t,this,e)})):this._prelimContent.delete(e)}set(e,t){return null!==this.doc?Ae(this.doc,(s=>{rt(s,this,e,t)})):this._prelimContent.set(e,t),t}get(e){return it(this,e)}has(e){return ct(this,e)}clear(){null!==this.doc?Ae(this.doc,(e=>{this.forEach((function(t,s,n){nt(e,n,s)}))})):this._prelimContent.clear()}_write(e){e.writeTypeRef($t)}}const pt=(e,t)=>e===t||"object"==typeof e&&"object"==typeof t&&e&&t&&S.equalFlat(e,t);class gt{constructor(e,t,s,n){this.left=e,this.right=t,this.index=s,this.currentAttributes=n}forward(){null===this.right&&g.unexpectedCase(),this.right.content.constructor===Wt?this.right.deleted||_t(this.currentAttributes,this.right.content):this.right.deleted||(this.index+=this.right.length),this.left=this.right,this.right=this.right.right}}const ft=(e,t,s)=>{for(;null!==t.right&&s>0;)t.right.content.constructor===Wt?t.right.deleted||_t(t.currentAttributes,t.right.content):t.right.deleted||(s<t.right.length&&we(e,ie(t.right.id.client,t.right.id.clock+s)),t.index+=t.right.length,s-=t.right.length),t.left=t.right,t.right=t.right.right;return t},wt=(e,t,s,n)=>{const r=new Map,i=n?He(t,s):null;if(i){const t=new gt(i.p.left,i.p,i.index,r);return ft(e,t,s-i.index)}{const n=new gt(null,t._start,0,r);return ft(e,n,s)}},yt=(e,t,s,n)=>{for(;null!==s.right&&(!0===s.right.deleted||s.right.content.constructor===Wt&&pt(n.get(s.right.content.key),s.right.content.value));)s.right.deleted||n.delete(s.right.content.key),s.forward();const r=e.doc,i=r.clientID;n.forEach(((n,o)=>{const c=s.left,a=s.right,h=new ns(ie(i,de(r.store,i)),c,c&&c.lastId,a,a&&a.id,t,null,new Wt(o,n));h.integrate(e,0),s.right=h,s.forward()}))},_t=(e,t)=>{const{key:s,value:n}=t;null===n?e.delete(s):e.set(s,n)},mt=(e,t)=>{for(;null!==e.right&&(e.right.deleted||e.right.content.constructor===Wt&&pt(t[e.right.content.key]??null,e.right.content.value));)e.forward()},bt=(e,t,s,n)=>{const r=e.doc,i=r.clientID,o=new Map;for(const c in n){const a=n[c],h=s.currentAttributes.get(c)??null;if(!pt(h,a)){o.set(c,h);const{left:n,right:l}=s;s.right=new ns(ie(i,de(r.store,i)),n,n&&n.lastId,l,l&&l.id,t,null,new Wt(c,a)),s.right.integrate(e,0),s.forward()}}return o},St=(e,t,s,n,r)=>{s.currentAttributes.forEach(((e,t)=>{void 0===r[t]&&(r[t]=null)}));const i=e.doc,o=i.clientID;mt(s,r);const c=bt(e,t,s,r),a=n.constructor===String?new Gt(n):n instanceof Ge?new ts(n):new zt(n);let{left:h,right:l,index:d}=s;t._searchMarker&&Fe(t._searchMarker,s.index,a.getLength()),l=new ns(ie(o,de(i.store,o)),h,h&&h.lastId,l,l&&l.id,t,null,a),l.integrate(e,0),s.right=l,s.index=d,s.forward(),yt(e,t,s,c)},kt=(e,t,s,n,r)=>{const i=e.doc,o=i.clientID;mt(s,r);const c=bt(e,t,s,r);e:for(;null!==s.right&&(n>0||c.size>0&&(s.right.deleted||s.right.content.constructor===Wt));){if(!s.right.deleted)switch(s.right.content.constructor){case Wt:{const{key:t,value:i}=s.right.content,o=r[t];if(void 0!==o){if(pt(o,i))c.delete(t);else{if(0===n)break e;c.set(t,i)}s.right.delete(e)}else s.currentAttributes.set(t,i);break}default:n<s.right.length&&we(e,ie(s.right.id.client,s.right.id.clock+n)),n-=s.right.length}s.forward()}if(n>0){let r="";for(;n>0;n--)r+="\n";s.right=new ns(ie(o,de(i.store,o)),s.left,s.left&&s.left.lastId,s.right,s.right&&s.right.id,t,null,new Gt(r)),s.right.integrate(e,0),s.forward()}yt(e,t,s,c)},vt=(e,t,s,n,r)=>{let i=t;const o=a.create();for(;i&&(!i.countable||i.deleted);){if(!i.deleted&&i.content.constructor===Wt){const e=i.content;o.set(e.key,e)}i=i.right}let c=0,h=!1;for(;t!==i;){if(s===t&&(h=!0),!t.deleted){const s=t.content;switch(s.constructor){case Wt:{const{key:i,value:a}=s,l=n.get(i)??null;o.get(i)===s&&l!==a||(t.delete(e),c++,h||(r.get(i)??null)!==a||l===a||(null===l?r.delete(i):r.set(i,l))),h||t.deleted||_t(r,s);break}}}t=t.right}return c},At=e=>{let t=0;return Ae(e.doc,(s=>{let n=e._start,r=e._start,i=a.create();const o=a.copy(i);for(;r;)!1===r.deleted&&(r.content.constructor===Wt?_t(o,r.content):(t+=vt(s,n,r,i,o),i=a.copy(o),n=r)),r=r.right})),t},Tt=e=>{const t=new Set,s=e.doc;for(const[n,r]of e.afterState.entries()){const i=e.beforeState.get(n)||0;r!==i&&_e(e,s.store.clients.get(n),i,r,(e=>{e.deleted||e.content.constructor!==Wt||e.constructor===Pt||t.add(e.parent)}))}Ae(s,(s=>{T(e,e.deleteSet,(e=>{if(e instanceof Pt||!e.parent._hasFormatting||t.has(e.parent))return;const n=e.parent;e.content.constructor===Wt?t.add(n):((e,t)=>{for(;t&&t.right&&(t.right.deleted||!t.right.countable);)t=t.right;const s=new Set;for(;t&&(t.deleted||!t.countable);){if(!t.deleted&&t.content.constructor===Wt){const n=t.content.key;s.has(n)?t.delete(e):s.add(n)}t=t.left}})(s,e)}));for(const e of t)At(e)}))},Ct=(e,t,s)=>{const n=s,r=a.copy(t.currentAttributes),i=t.right;for(;s>0&&null!==t.right;){if(!1===t.right.deleted)switch(t.right.content.constructor){case ts:case zt:case Gt:s<t.right.length&&we(e,ie(t.right.id.client,t.right.id.clock+s)),s-=t.right.length,t.right.delete(e)}t.forward()}i&&vt(e,i,t.right,r,t.currentAttributes);const o=(t.left||t.right).parent;return o._searchMarker&&Fe(o._searchMarker,t.index,-n+s),t};class Ut extends Be{constructor(e,t,s){super(e,t),this.childListChanged=!1,this.keysChanged=new Set,s.forEach((e=>{null===e?this.childListChanged=!0:this.keysChanged.add(e)}))}get changes(){if(null===this._changes){const e={keys:this.keys,delta:this.delta,added:new Set,deleted:new Set};this._changes=e}return this._changes}get delta(){if(null===this._delta){const e=this.target.doc,t=[];Ae(e,(e=>{const s=new Map,n=new Map;let r=this.target._start,i=null;const o={};let c="",a=0,h=0;const l=()=>{if(null!==i){let e=null;switch(i){case"delete":h>0&&(e={delete:h}),h=0;break;case"insert":("object"==typeof c||c.length>0)&&(e={insert:c},s.size>0&&(e.attributes={},s.forEach(((t,s)=>{null!==t&&(e.attributes[s]=t)})))),c="";break;case"retain":a>0&&(e={retain:a},S.isEmpty(o)||(e.attributes=S.assign({},o))),a=0}e&&t.push(e),i=null}};for(;null!==r;){switch(r.content.constructor){case ts:case zt:this.adds(r)?this.deletes(r)||(l(),i="insert",c=r.content.getContent()[0],l()):this.deletes(r)?("delete"!==i&&(l(),i="delete"),h+=1):r.deleted||("retain"!==i&&(l(),i="retain"),a+=1);break;case Gt:this.adds(r)?this.deletes(r)||("insert"!==i&&(l(),i="insert"),c+=r.content.str):this.deletes(r)?("delete"!==i&&(l(),i="delete"),h+=r.length):r.deleted||("retain"!==i&&(l(),i="retain"),a+=r.length);break;case Wt:{const{key:t,value:c}=r.content;if(this.adds(r)){if(!this.deletes(r)){const a=s.get(t)??null;pt(a,c)?null!==c&&r.delete(e):("retain"===i&&l(),pt(c,n.get(t)??null)?delete o[t]:o[t]=c)}}else if(this.deletes(r)){n.set(t,c);const e=s.get(t)??null;pt(e,c)||("retain"===i&&l(),o[t]=e)}else if(!r.deleted){n.set(t,c);const s=o[t];void 0!==s&&(pt(s,c)?null!==s&&r.delete(e):("retain"===i&&l(),null===c?delete o[t]:o[t]=c))}r.deleted||("insert"===i&&l(),_t(s,r.content));break}}r=r.right}for(l();t.length>0;){const e=t[t.length-1];if(void 0===e.retain||void 0!==e.attributes)break;t.pop()}})),this._delta=t}return this._delta}}class It extends Ge{constructor(e){super(),this._pending=void 0!==e?[()=>this.insert(0,e)]:[],this._searchMarker=[],this._hasFormatting=!1}get length(){return this.doc??Le(),this._length}_integrate(e,t){super._integrate(e,t);try{this._pending.forEach((e=>e()))}catch(e){console.error(e)}this._pending=null}_copy(){return new It}clone(){const e=new It;return e.applyDelta(this.toDelta()),e}_callObserver(e,t){super._callObserver(e,t);const s=new Ut(this,e,t);je(this,e,s),!e.local&&this._hasFormatting&&(e._needFormattingCleanup=!0)}toString(){this.doc??Le();let e="",t=this._start;for(;null!==t;)!t.deleted&&t.countable&&t.content.constructor===Gt&&(e+=t.content.str),t=t.right;return e}toJSON(){return this.toString()}applyDelta(e,{sanitize:t=!0}={}){null!==this.doc?Ae(this.doc,(s=>{const n=new gt(null,this._start,0,new Map);for(let r=0;r<e.length;r++){const i=e[r];if(void 0!==i.insert){const o=t||"string"!=typeof i.insert||r!==e.length-1||null!==n.right||"\n"!==i.insert.slice(-1)?i.insert:i.insert.slice(0,-1);("string"!=typeof o||o.length>0)&&St(s,this,n,o,i.attributes||{})}else void 0!==i.retain?kt(s,this,n,i.retain,i.attributes||{}):void 0!==i.delete&&Ct(s,n,i.delete)}})):this._pending.push((()=>this.applyDelta(e)))}toDelta(e,t,s){this.doc??Le();const n=[],r=new Map,i=this.doc;let o="",c=this._start;function a(){if(o.length>0){const e={};let t=!1;r.forEach(((s,n)=>{t=!0,e[n]=s}));const s={insert:o};t&&(s.attributes=e),n.push(s),o=""}}const h=()=>{for(;null!==c;){if(ce(c,e)||void 0!==t&&ce(c,t))switch(c.content.constructor){case Gt:{const n=r.get("ychange");void 0===e||ce(c,e)?void 0===t||ce(c,t)?void 0!==n&&(a(),r.delete("ychange")):void 0!==n&&n.user===c.id.client&&"added"===n.type||(a(),r.set("ychange",s?s("added",c.id):{type:"added"})):void 0!==n&&n.user===c.id.client&&"removed"===n.type||(a(),r.set("ychange",s?s("removed",c.id):{type:"removed"})),o+=c.content.str;break}case ts:case zt:{a();const e={insert:c.content.getContent()[0]};if(r.size>0){const t={};e.attributes=t,r.forEach(((e,s)=>{t[s]=e}))}n.push(e);break}case Wt:ce(c,e)&&(a(),_t(r,c.content))}c=c.right}a()};return e||t?Ae(i,(s=>{e&&ae(s,e),t&&ae(s,t),h()}),"cleanup"):h(),n}insert(e,t,s){if(t.length<=0)return;const n=this.doc;null!==n?Ae(n,(n=>{const r=wt(n,this,e,!s);s||(s={},r.currentAttributes.forEach(((e,t)=>{s[t]=e}))),St(n,this,r,t,s)})):this._pending.push((()=>this.insert(e,t,s)))}insertEmbed(e,t,s){const n=this.doc;null!==n?Ae(n,(n=>{const r=wt(n,this,e,!s);St(n,this,r,t,s||{})})):this._pending.push((()=>this.insertEmbed(e,t,s||{})))}delete(e,t){if(0===t)return;const s=this.doc;null!==s?Ae(s,(s=>{Ct(s,wt(s,this,e,!0),t)})):this._pending.push((()=>this.delete(e,t)))}format(e,t,s){if(0===t)return;const n=this.doc;null!==n?Ae(n,(n=>{const r=wt(n,this,e,!1);null!==r.right&&kt(n,this,r,t,s)})):this._pending.push((()=>this.format(e,t,s)))}removeAttribute(e){null!==this.doc?Ae(this.doc,(t=>{nt(t,this,e)})):this._pending.push((()=>this.removeAttribute(e)))}setAttribute(e,t){null!==this.doc?Ae(this.doc,(s=>{rt(s,this,e,t)})):this._pending.push((()=>this.setAttribute(e,t)))}getAttribute(e){return it(this,e)}getAttributes(){return ot(this)}_write(e){e.writeTypeRef(Yt)}}class xt{constructor(e,t=(()=>!0)){this._filter=t,this._root=e,this._currentNode=e._start,this._firstCall=!0,e.doc??Le()}[Symbol.iterator](){return this}next(){let e=this._currentNode,t=e&&e.content&&e.content.type;if(null!==e&&(!this._firstCall||e.deleted||!this._filter(t)))do{if(t=e.content.type,e.deleted||t.constructor!==Et&&t.constructor!==Dt||null===t._start)for(;null!==e;){const t=e.next;if(null!==t){e=t;break}e=e.parent===this._root?null:e.parent._item}else e=t._start}while(null!==e&&(e.deleted||!this._filter(e.content.type)));return this._firstCall=!1,null===e?{value:void 0,done:!0}:(this._currentNode=e,{value:e.content.type,done:!1})}}class Dt extends Ge{constructor(){super(),this._prelimContent=[]}get firstChild(){const e=this._first;return e?e.content.getContent()[0]:null}_integrate(e,t){super._integrate(e,t),this.insert(0,this._prelimContent),this._prelimContent=null}_copy(){return new Dt}clone(){const e=new Dt;return e.insert(0,this.toArray().map((e=>e instanceof Ge?e.clone():e))),e}get length(){return this.doc??Le(),null===this._prelimContent?this._length:this._prelimContent.length}createTreeWalker(e){return new xt(this,e)}querySelector(e){e=e.toUpperCase();const t=new xt(this,(t=>t.nodeName&&t.nodeName.toUpperCase()===e)).next();return t.done?null:t.value}querySelectorAll(e){return e=e.toUpperCase(),o.from(new xt(this,(t=>t.nodeName&&t.nodeName.toUpperCase()===e)))}_callObserver(e,t){je(this,e,new Rt(this,t,e))}toString(){return Ye(this,(e=>e.toString())).join("")}toJSON(){return this.toString()}toDOM(e=document,t={},s){const n=e.createDocumentFragment();return void 0!==s&&s._createAssociation(n,this),$e(this,(r=>{n.insertBefore(r.toDOM(e,t,s),null)})),n}insert(e,t){null!==this.doc?Ae(this.doc,(s=>{tt(s,this,e,t)})):this._prelimContent.splice(e,0,...t)}insertAfter(e,t){if(null!==this.doc)Ae(this.doc,(s=>{const n=e&&e instanceof Ge?e._item:e;Ze(s,this,n,t)}));else{const s=this._prelimContent,n=null===e?0:s.findIndex((t=>t===e))+1;if(0===n&&null!==e)throw g.create("Reference item not found");s.splice(n,0,...t)}}delete(e,t=1){null!==this.doc?Ae(this.doc,(s=>{st(s,this,e,t)})):this._prelimContent.splice(e,t)}toArray(){return Je(this)}push(e){this.insert(this.length,e)}unshift(e){this.insert(0,e)}get(e){return Qe(this,e)}slice(e=0,t=this.length){return Ke(this,e,t)}forEach(e){$e(this,e)}_write(e){e.writeTypeRef(Qt)}}class Et extends Dt{constructor(e="UNDEFINED"){super(),this.nodeName=e,this._prelimAttrs=new Map}get nextSibling(){const e=this._item?this._item.next:null;return e?e.content.type:null}get prevSibling(){const e=this._item?this._item.prev:null;return e?e.content.type:null}_integrate(e,t){super._integrate(e,t),this._prelimAttrs.forEach(((e,t)=>{this.setAttribute(t,e)})),this._prelimAttrs=null}_copy(){return new Et(this.nodeName)}clone(){const e=new Et(this.nodeName),t=this.getAttributes();return S.forEach(t,((t,s)=>{e.setAttribute(s,t)})),e.insert(0,this.toArray().map((e=>e instanceof Ge?e.clone():e))),e}toString(){const e=this.getAttributes(),t=[],s=[];for(const t in e)s.push(t);s.sort();const n=s.length;for(let r=0;r<n;r++){const n=s[r];t.push(n+'="'+e[n]+'"')}const r=this.nodeName.toLocaleLowerCase();return`<${r}${t.length>0?" "+t.join(" "):""}>${super.toString()}</${r}>`}removeAttribute(e){null!==this.doc?Ae(this.doc,(t=>{nt(t,this,e)})):this._prelimAttrs.delete(e)}setAttribute(e,t){null!==this.doc?Ae(this.doc,(s=>{rt(s,this,e,t)})):this._prelimAttrs.set(e,t)}getAttribute(e){return it(this,e)}hasAttribute(e){return ct(this,e)}getAttributes(e){return e?((e,t)=>{const s={};return this._map.forEach(((e,n)=>{let r=e;for(;null!==r&&(!t.sv.has(r.id.client)||r.id.clock>=(t.sv.get(r.id.client)||0));)r=r.left;null!==r&&ce(r,t)&&(s[n]=r.content.getContent()[r.length-1])})),s})(0,e):ot(this)}toDOM(e=document,t={},s){const n=e.createElement(this.nodeName),r=this.getAttributes();for(const e in r){const t=r[e];"string"==typeof t&&n.setAttribute(e,t)}return $e(this,(r=>{n.appendChild(r.toDOM(e,t,s))})),void 0!==s&&s._createAssociation(n,this),n}_write(e){e.writeTypeRef(Xt),e.writeKey(this.nodeName)}}class Rt extends Be{constructor(e,t,s){super(e,s),this.childListChanged=!1,this.attributesChanged=new Set,t.forEach((e=>{null===e?this.childListChanged=!0:this.attributesChanged.add(e)}))}}class Mt extends ut{constructor(e){super(),this.hookName=e}_copy(){return new Mt(this.hookName)}clone(){const e=new Mt(this.hookName);return this.forEach(((t,s)=>{e.set(s,t)})),e}toDOM(e=document,t={},s){const n=t[this.hookName];let r;return r=void 0!==n?n.createDom(this):document.createElement(this.hookName),r.setAttribute("data-yjs-hook",this.hookName),void 0!==s&&s._createAssociation(r,this),r}_write(e){e.writeTypeRef(Zt),e.writeKey(this.hookName)}}class Vt extends It{get nextSibling(){const e=this._item?this._item.next:null;return e?e.content.type:null}get prevSibling(){const e=this._item?this._item.prev:null;return e?e.content.type:null}_copy(){return new Vt}clone(){const e=new Vt;return e.applyDelta(this.toDelta()),e}toDOM(e=document,t,s){const n=e.createTextNode(this.toString());return void 0!==s&&s._createAssociation(n,this),n}toString(){return this.toDelta().map((e=>{const t=[];for(const s in e.attributes){const n=[];for(const t in e.attributes[s])n.push({key:t,value:e.attributes[s][t]});n.sort(((e,t)=>e.key<t.key?-1:1)),t.push({nodeName:s,attrs:n})}t.sort(((e,t)=>e.nodeName<t.nodeName?-1:1));let s="";for(let e=0;e<t.length;e++){const n=t[e];s+=`<${n.nodeName}`;for(let e=0;e<n.attrs.length;e++){const t=n.attrs[e];s+=` ${t.key}="${t.value}"`}s+=">"}s+=e.insert;for(let e=t.length-1;e>=0;e--)s+=`</${t[e].nodeName}>`;return s})).join("")}toJSON(){return this.toString()}_write(e){e.writeTypeRef(es)}}class Ot{constructor(e,t){this.id=e,this.length=t}get deleted(){throw g.methodUnimplemented()}mergeWith(e){return!1}write(e,t,s){throw g.methodUnimplemented()}integrate(e,t){throw g.methodUnimplemented()}}class Pt extends Ot{get deleted(){return!0}delete(){}mergeWith(e){return this.constructor===e.constructor&&(this.length+=e.length,!0)}integrate(e,t){t>0&&(this.id.clock+=t,this.length-=t),ue(e.doc.store,this)}write(e,t){e.writeInfo(0),e.writeLen(this.length-t)}getMissing(e,t){return null}}class Bt{constructor(e){this.content=e}getLength(){return 1}getContent(){return[this.content]}isCountable(){return!0}copy(){return new Bt(this.content)}splice(e){throw g.methodUnimplemented()}mergeWith(e){return!1}integrate(e,t){}delete(e){}gc(e){}write(e,t){e.writeBuf(this.content)}getRef(){return 3}}class Nt{constructor(e){this.len=e}getLength(){return this.len}getContent(){return[]}isCountable(){return!1}copy(){return new Nt(this.len)}splice(e){const t=new Nt(this.len-e);return this.len=e,t}mergeWith(e){return this.len+=e.len,!0}integrate(e,t){x(e.deleteSet,t.id.client,t.id.clock,this.len),t.markDeleted()}delete(e){}gc(e){}write(e,t){e.writeLen(this.len-t)}getRef(){return 1}}const Lt=(e,t)=>new P({guid:e,...t,shouldLoad:t.shouldLoad||t.autoLoad||!1});class qt{constructor(e){e._item&&console.error("This document was already integrated as a sub-document. You should create a second instance instead with the same guid."),this.doc=e;const t={};this.opts=t,e.gc||(t.gc=!1),e.autoLoad&&(t.autoLoad=!0),null!==e.meta&&(t.meta=e.meta)}getLength(){return 1}getContent(){return[this.doc]}isCountable(){return!0}copy(){return new qt(Lt(this.doc.guid,this.opts))}splice(e){throw g.methodUnimplemented()}mergeWith(e){return!1}integrate(e,t){this.doc._item=t,e.subdocsAdded.add(this.doc),this.doc.shouldLoad&&e.subdocsLoaded.add(this.doc)}delete(e){e.subdocsAdded.has(this.doc)?e.subdocsAdded.delete(this.doc):e.subdocsRemoved.add(this.doc)}gc(e){}write(e,t){e.writeString(this.doc.guid),e.writeAny(this.opts)}getRef(){return 9}}class zt{constructor(e){this.embed=e}getLength(){return 1}getContent(){return[this.embed]}isCountable(){return!0}copy(){return new zt(this.embed)}splice(e){throw g.methodUnimplemented()}mergeWith(e){return!1}integrate(e,t){}delete(e){}gc(e){}write(e,t){e.writeJSON(this.embed)}getRef(){return 5}}class Wt{constructor(e,t){this.key=e,this.value=t}getLength(){return 1}getContent(){return[]}isCountable(){return!1}copy(){return new Wt(this.key,this.value)}splice(e){throw g.methodUnimplemented()}mergeWith(e){return!1}integrate(e,t){const s=t.parent;s._searchMarker=null,s._hasFormatting=!0}delete(e){}gc(e){}write(e,t){e.writeKey(this.key),e.writeJSON(this.value)}getRef(){return 6}}class Ht{constructor(e){this.arr=e}getLength(){return this.arr.length}getContent(){return this.arr}isCountable(){return!0}copy(){return new Ht(this.arr)}splice(e){const t=new Ht(this.arr.slice(e));return this.arr=this.arr.slice(0,e),t}mergeWith(e){return this.arr=this.arr.concat(e.arr),!0}integrate(e,t){}delete(e){}gc(e){}write(e,t){const s=this.arr.length;e.writeLen(s-t);for(let n=t;n<s;n++){const t=this.arr[n];e.writeString(void 0===t?"undefined":JSON.stringify(t))}}getRef(){return 2}}const Ft="development"===k.getVariable("node_env");class jt{constructor(e){this.arr=e,Ft&&S.deepFreeze(e)}getLength(){return this.arr.length}getContent(){return this.arr}isCountable(){return!0}copy(){return new jt(this.arr)}splice(e){const t=new jt(this.arr.slice(e));return this.arr=this.arr.slice(0,e),t}mergeWith(e){return this.arr=this.arr.concat(e.arr),!0}integrate(e,t){}delete(e){}gc(e){}write(e,t){const s=this.arr.length;e.writeLen(s-t);for(let n=t;n<s;n++){const t=this.arr[n];e.writeAny(t)}}getRef(){return 8}}class Gt{constructor(e){this.str=e}getLength(){return this.str.length}getContent(){return this.str.split("")}isCountable(){return!0}copy(){return new Gt(this.str)}splice(e){const t=new Gt(this.str.slice(e));this.str=this.str.slice(0,e);const s=this.str.charCodeAt(e-1);return s>=55296&&s<=56319&&(this.str=this.str.slice(0,e-1)+"�",t.str="�"+t.str.slice(1)),t}mergeWith(e){return this.str+=e.str,!0}integrate(e,t){}delete(e){}gc(e){}write(e,t){e.writeString(0===t?this.str:this.str.slice(t))}getRef(){return 4}}const Kt=[e=>new lt,e=>new ut,e=>new It,e=>new Et(e.readKey()),e=>new Dt,e=>new Mt(e.readKey()),e=>new Vt],Jt=0,$t=1,Yt=2,Xt=3,Qt=4,Zt=5,es=6;class ts{constructor(e){this.type=e}getLength(){return 1}getContent(){return[this.type]}isCountable(){return!0}copy(){return new ts(this.type._copy())}splice(e){throw g.methodUnimplemented()}mergeWith(e){return!1}integrate(e,t){this.type._integrate(e.doc,t)}delete(e){let t=this.type._start;for(;null!==t;)t.deleted?t.id.clock<(e.beforeState.get(t.id.client)||0)&&e._mergeStructs.push(t):t.delete(e),t=t.right;this.type._map.forEach((t=>{t.deleted?t.id.clock<(e.beforeState.get(t.id.client)||0)&&e._mergeStructs.push(t):t.delete(e)})),e.changed.delete(this.type)}gc(e){let t=this.type._start;for(;null!==t;)t.gc(e,!0),t=t.right;this.type._start=null,this.type._map.forEach((t=>{for(;null!==t;)t.gc(e,!0),t=t.left})),this.type._map=new Map}write(e,t){this.type._write(e)}getRef(){return 7}}const ss=(e,t,s)=>{const{client:n,clock:r}=t.id,i=new ns(ie(n,r+s),t,ie(n,r+s-1),t.right,t.rightOrigin,t.parent,t.parentSub,t.content.splice(s));return t.deleted&&i.markDeleted(),t.keep&&(i.keep=!0),null!==t.redone&&(i.redone=ie(t.redone.client,t.redone.clock+s)),t.right=i,null!==i.right&&(i.right.left=i),e._mergeStructs.push(i),null!==i.parentSub&&null===i.right&&i.parent._map.set(i.parentSub,i),t.length=s,i};class ns extends Ot{constructor(e,t,s,n,r,i,o,c){super(e,c.getLength()),this.origin=s,this.left=t,this.right=n,this.rightOrigin=r,this.parent=i,this.parentSub=o,this.redone=null,this.content=c,this.info=this.content.isCountable()?f.BIT2:0}set marker(e){(this.info&f.BIT4)>0!==e&&(this.info^=f.BIT4)}get marker(){return(this.info&f.BIT4)>0}get keep(){return(this.info&f.BIT1)>0}set keep(e){this.keep!==e&&(this.info^=f.BIT1)}get countable(){return(this.info&f.BIT2)>0}get deleted(){return(this.info&f.BIT3)>0}set deleted(e){this.deleted!==e&&(this.info^=f.BIT3)}markDeleted(){this.info|=f.BIT3}getMissing(e,t){if(this.origin&&this.origin.client!==this.id.client&&this.origin.clock>=de(t,this.origin.client))return this.origin.client;if(this.rightOrigin&&this.rightOrigin.client!==this.id.client&&this.rightOrigin.clock>=de(t,this.rightOrigin.client))return this.rightOrigin.client;if(this.parent&&this.parent.constructor===ne&&this.id.client!==this.parent.client&&this.parent.clock>=de(t,this.parent.client))return this.parent.client;if(this.origin&&(this.left=ye(e,t,this.origin),this.origin=this.left.lastId),this.rightOrigin&&(this.right=we(e,this.rightOrigin),this.rightOrigin=this.right.id),this.left&&this.left.constructor===Pt||this.right&&this.right.constructor===Pt)this.parent=null;else if(this.parent){if(this.parent.constructor===ne){const e=ge(t,this.parent);e.constructor===Pt?this.parent=null:this.parent=e.content.type}}else this.left&&this.left.constructor===ns?(this.parent=this.left.parent,this.parentSub=this.left.parentSub):this.right&&this.right.constructor===ns&&(this.parent=this.right.parent,this.parentSub=this.right.parentSub);return null}integrate(e,t){if(t>0&&(this.id.clock+=t,this.left=ye(e,e.doc.store,ie(this.id.client,this.id.clock-1)),this.origin=this.left.lastId,this.content=this.content.splice(t),this.length-=t),this.parent){if(!this.left&&(!this.right||null!==this.right.left)||this.left&&this.left.right!==this.right){let t,s=this.left;if(null!==s)t=s.right;else if(null!==this.parentSub)for(t=this.parent._map.get(this.parentSub)||null;null!==t&&null!==t.left;)t=t.left;else t=this.parent._start;const n=new Set,r=new Set;for(;null!==t&&t!==this.right;){if(r.add(t),n.add(t),re(this.origin,t.origin)){if(t.id.client<this.id.client)s=t,n.clear();else if(re(this.rightOrigin,t.rightOrigin))break}else{if(null===t.origin||!r.has(ge(e.doc.store,t.origin)))break;n.has(ge(e.doc.store,t.origin))||(s=t,n.clear())}t=t.right}this.left=s}if(null!==this.left){const e=this.left.right;this.right=e,this.left.right=this}else{let e;if(null!==this.parentSub)for(e=this.parent._map.get(this.parentSub)||null;null!==e&&null!==e.left;)e=e.left;else e=this.parent._start,this.parent._start=this;this.right=e}null!==this.right?this.right.left=this:null!==this.parentSub&&(this.parent._map.set(this.parentSub,this),null!==this.left&&this.left.delete(e)),null===this.parentSub&&this.countable&&!this.deleted&&(this.parent._length+=this.length),ue(e.doc.store,this),this.content.integrate(e,this),Se(e,this.parent,this.parentSub),(null!==this.parent._item&&this.parent._item.deleted||null!==this.parentSub&&null!==this.right)&&this.delete(e)}else new Pt(this.id,this.length).integrate(e,0)}get next(){let e=this.right;for(;null!==e&&e.deleted;)e=e.right;return e}get prev(){let e=this.left;for(;null!==e&&e.deleted;)e=e.left;return e}get lastId(){return 1===this.length?this.id:ie(this.id.client,this.id.clock+this.length-1)}mergeWith(e){if(this.constructor===e.constructor&&re(e.origin,this.lastId)&&this.right===e&&re(this.rightOrigin,e.rightOrigin)&&this.id.client===e.id.client&&this.id.clock+this.length===e.id.clock&&this.deleted===e.deleted&&null===this.redone&&null===e.redone&&this.content.constructor===e.content.constructor&&this.content.mergeWith(e.content)){const t=this.parent._searchMarker;return t&&t.forEach((t=>{t.p===e&&(t.p=this,!this.deleted&&this.countable&&(t.index-=this.length))})),e.keep&&(this.keep=!0),this.right=e.right,null!==this.right&&(this.right.left=this),this.length+=e.length,!0}return!1}delete(e){if(!this.deleted){const t=this.parent;this.countable&&null===this.parentSub&&(t._length-=this.length),this.markDeleted(),x(e.deleteSet,this.id.client,this.id.clock,this.length),Se(e,t,this.parentSub),this.content.delete(e)}}gc(e,t){if(!this.deleted)throw g.unexpectedCase();this.content.gc(e),t?((e,t,s)=>{const n=e.clients.get(t.id.client);n[pe(n,t.id.clock)]=s})(e,this,new Pt(this.id,this.length)):this.content=new Nt(this.length)}write(e,t){const s=t>0?ie(this.id.client,this.id.clock+t-1):this.origin,n=this.rightOrigin,r=this.parentSub,i=this.content.getRef()&f.BITS5|(null===s?0:f.BIT8)|(null===n?0:f.BIT7)|(null===r?0:f.BIT6);if(e.writeInfo(i),null!==s&&e.writeLeftID(s),null!==n&&e.writeRightID(n),null===s&&null===n){const t=this.parent;if(void 0!==t._item){const s=t._item;if(null===s){const s=(e=>{for(const[t,s]of e.doc.share.entries())if(s===e)return t;throw g.unexpectedCase()})(t);e.writeParentInfo(!0),e.writeString(s)}else e.writeParentInfo(!1),e.writeLeftID(s.id)}else t.constructor===String?(e.writeParentInfo(!0),e.writeString(t)):t.constructor===ne?(e.writeParentInfo(!1),e.writeLeftID(t)):g.unexpectedCase();null!==r&&e.writeString(r)}this.content.write(e,t)}}const rs=(e,t)=>is[t&f.BITS5](e),is=[()=>{g.unexpectedCase()},e=>new Nt(e.readLen()),e=>{const t=e.readLen(),s=[];for(let n=0;n<t;n++){const t=e.readString();"undefined"===t?s.push(void 0):s.push(JSON.parse(t))}return new Ht(s)},e=>new Bt(e.readBuf()),e=>new Gt(e.readString()),e=>new zt(e.readJSON()),e=>new Wt(e.readKey(),e.readJSON()),e=>new ts(Kt[e.readTypeRef()](e)),e=>{const t=e.readLen(),s=[];for(let n=0;n<t;n++)s.push(e.readAny());return new jt(s)},e=>new qt(Lt(e.readString(),e.readAny())),()=>{g.unexpectedCase()}];class os extends Ot{get deleted(){return!0}delete(){}mergeWith(e){return this.constructor===e.constructor&&(this.length+=e.length,!0)}integrate(e,t){g.unexpectedCase()}write(e,t){e.writeInfo(10),h.writeVarUint(e.restEncoder,this.length-t)}getMissing(e,t){return null}}const cs="undefined"!=typeof globalThis?globalThis:"undefined"!=typeof window?window:void 0!==t?t:{},as="__ $YJS$ __";!0===cs[as]&&console.error("Yjs was already imported. This breaks constructor checks and will lead to issues! - https://github.com/yjs/yjs/issues/438"),cs[as]=!0})),s.register("8Gyr5",(function(t,n){e(t.exports,"ObservableV2",(()=>c)),e(t.exports,"Observable",(()=>a));var r=s("96q9T"),i=s("5zT0w"),o=s("9GMWx");class c{constructor(){this._observers=r.create()}on(e,t){return r.setIfUndefined(this._observers,e,i.create).add(t),t}once(e,t){const s=(...n)=>{this.off(e,s),t(...n)};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 o.from((this._observers.get(e)||r.create()).values()).forEach((e=>e(...t)))}destroy(){this._observers=r.create()}}class a{constructor(){this._observers=r.create()}on(e,t){r.setIfUndefined(this._observers,e,i.create).add(t)}once(e,t){const s=(...n)=>{this.off(e,s),t(...n)};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 o.from((this._observers.get(e)||r.create()).values()).forEach((e=>e(...t)))}destroy(){this._observers=r.create()}}})),s.register("96q9T",(function(t,s){e(t.exports,"create",(()=>n)),e(t.exports,"copy",(()=>r)),e(t.exports,"setIfUndefined",(()=>i)),e(t.exports,"map",(()=>o)),e(t.exports,"any",(()=>c));const n=()=>new Map,r=e=>{const t=n();return e.forEach(((e,s)=>{t.set(s,e)})),t},i=(e,t,s)=>{let n=e.get(t);return void 0===n&&e.set(t,n=s()),n},o=(e,t)=>{const s=[];for(const[n,r]of e)s.push(t(r,n));return s},c=(e,t)=>{for(const[s,n]of e)if(t(n,s))return!0;return!1}})),s.register("5zT0w",(function(t,s){e(t.exports,"create",(()=>n)),e(t.exports,"from",(()=>r));const n=()=>new Set,r=e=>new Set(e)})),s.register("9GMWx",(function(t,n){e(t.exports,"last",(()=>r)),e(t.exports,"appendTo",(()=>i)),e(t.exports,"from",(()=>o)),e(t.exports,"some",(()=>c)),e(t.exports,"equalFlat",(()=>a)),e(t.exports,"unfold",(()=>h)),e(t.exports,"isArray",(()=>l)),e(t.exports,"map",(()=>d)),s("5zT0w");const r=e=>e[e.length-1],i=(e,t)=>{for(let s=0;s<t.length;s++)e.push(t[s])},o=Array.from,c=(e,t)=>{for(let s=0;s<e.length;s++)if(t(e[s],s,e))return!0;return!1},a=(e,t)=>e.length===t.length&&((e,t)=>{for(let s=0;s<e.length;s++)if(!t(e[s],s))return!1;return!0})(e,((e,s)=>e===t[s])),h=(e,t)=>{const s=new Array(e);for(let n=0;n<e;n++)s[n]=t(n,s);return s},l=Array.isArray,d=(e,t)=>{const s=Array(e.length);for(let n=0;n<e.length;n++)s[n]=t(e[n],n,e);return s}})),s.register("bGsfJ",(function(t,s){e(t.exports,"floor",(()=>n)),e(t.exports,"ceil",(()=>r)),e(t.exports,"abs",(()=>i)),e(t.exports,"round",(()=>o)),e(t.exports,"log10",(()=>c)),e(t.exports,"min",(()=>a)),e(t.exports,"max",(()=>h)),e(t.exports,"exp10",(()=>l)),e(t.exports,"isNegativeZero",(()=>d));const n=Math.floor,r=Math.ceil,i=Math.abs,o=(Math.imul,Math.round),c=Math.log10,a=(Math.log2,Math.log,Math.sqrt,(e,t)=>e<t?e:t),h=(e,t)=>e>t?e:t,l=(Number.isNaN,Math.pow,e=>Math.pow(10,e)),d=(Math.sign,e=>0!==e?e<0:1/e<0)})),s.register("7BTJz",(function(t,n){e(t.exports,"createEncoder",(()=>l)),e(t.exports,"encode",(()=>d)),e(t.exports,"toUint8Array",(()=>p)),e(t.exports,"length",(()=>u)),e(t.exports,"write",(()=>g)),e(t.exports,"writeUint8",(()=>f)),e(t.exports,"writeVarUint",(()=>w)),e(t.exports,"writeVarInt",(()=>y)),e(t.exports,"writeVarUint8Array",(()=>v)),e(t.exports,"writeVarString",(()=>b)),e(t.exports,"writeBinaryEncoder",(()=>S)),e(t.exports,"writeUint8Array",(()=>k)),e(t.exports,"writeAny",(()=>C)),e(t.exports,"RleEncoder",(()=>U)),e(t.exports,"UintOptRleEncoder",(()=>x)),e(t.exports,"IntDiffOptRleEncoder",(()=>E)),e(t.exports,"StringEncoder",(()=>R));var r=s("bGsfJ"),i=s("5es75"),o=s("bcXZT"),c=s("8drkQ"),a=s("9GMWx");class h{constructor(){this.cpos=0,this.cbuf=new Uint8Array(100),this.bufs=[]}}const l=()=>new h,d=e=>{const t=l();return e(t),p(t)},u=e=>{let t=e.cpos;for(let s=0;s<e.bufs.length;s++)t+=e.bufs[s].length;return t},p=e=>{const t=new Uint8Array(u(e));let s=0;for(let n=0;n<e.bufs.length;n++){const r=e.bufs[n];t.set(r,s),s+=r.length}return t.set(new Uint8Array(e.cbuf.buffer,0,e.cpos),s),t},g=(e,t)=>{const s=e.cbuf.length;e.cpos===s&&(e.bufs.push(e.cbuf),e.cbuf=new Uint8Array(2*s),e.cpos=0),e.cbuf[e.cpos++]=t},f=g,w=(e,t)=>{for(;t>o.BITS7;)g(e,o.BIT8|o.BITS7&t),t=r.floor(t/128);g(e,o.BITS7&t)},y=(e,t)=>{const s=r.isNegativeZero(t);for(s&&(t=-t),g(e,(t>o.BITS6?o.BIT8:0)|(s?o.BIT7:0)|o.BITS6&t),t=r.floor(t/64);t>0;)g(e,(t>o.BITS7?o.BIT8:0)|o.BITS7&t),t=r.floor(t/128)},_=new Uint8Array(3e4),m=_.length/3,b=c.utf8TextEncoder&&c.utf8TextEncoder.encodeInto?(e,t)=>{if(t.length<m){const s=c.utf8TextEncoder.encodeInto(t,_).written||0;w(e,s);for(let t=0;t<s;t++)g(e,_[t])}else v(e,c.encodeUtf8(t))}:(e,t)=>{const s=unescape(encodeURIComponent(t)),n=s.length;w(e,n);for(let t=0;t<n;t++)g(e,s.codePointAt(t))},S=(e,t)=>k(e,p(t)),k=(e,t)=>{const s=e.cbuf.length,n=e.cpos,i=r.min(s-n,t.length),o=t.length-i;e.cbuf.set(t.subarray(0,i),n),e.cpos+=i,o>0&&(e.bufs.push(e.cbuf),e.cbuf=new Uint8Array(r.max(2*s,o)),e.cbuf.set(t.subarray(i)),e.cpos=o)},v=(e,t)=>{w(e,t.byteLength),k(e,t)},A=(e,t)=>{((e,t)=>{const s=e.cbuf.length;s-e.cpos<t&&(e.bufs.push(new Uint8Array(e.cbuf.buffer,0,e.cpos)),e.cbuf=new Uint8Array(2*r.max(s,t)),e.cpos=0)})(e,t);const s=new DataView(e.cbuf.buffer,e.cpos,t);return e.cpos+=t,s},T=new DataView(new ArrayBuffer(4)),C=(e,t)=>{switch(typeof t){case"string":g(e,119),b(e,t);break;case"number":i.isInteger(t)&&r.abs(t)<=o.BITS31?(g(e,125),y(e,t)):(s=t,T.setFloat32(0,s),T.getFloat32(0)===s?(g(e,124),((e,t)=>{A(e,4).setFloat32(0,t,!1)})(e,t)):(g(e,123),((e,t)=>{A(e,8).setFloat64(0,t,!1)})(e,t)));break;case"bigint":g(e,122),((e,t)=>{A(e,8).setBigInt64(0,t,!1)})(e,t);break;case"object":if(null===t)g(e,126);else if(a.isArray(t)){g(e,117),w(e,t.length);for(let s=0;s<t.length;s++)C(e,t[s])}else if(t instanceof Uint8Array)g(e,116),v(e,t);else{g(e,118);const s=Object.keys(t);w(e,s.length);for(let n=0;n<s.length;n++){const r=s[n];b(e,r),C(e,t[r])}}break;case"boolean":g(e,t?120:121);break;default:g(e,127)}var s};class U extends h{constructor(e){super(),this.w=e,this.s=null,this.count=0}write(e){this.s===e?this.count++:(this.count>0&&w(this,this.count-1),this.count=1,this.w(this,e),this.s=e)}}const I=e=>{e.count>0&&(y(e.encoder,1===e.count?e.s:-e.s),e.count>1&&w(e.encoder,e.count-2))};class x{constructor(){this.encoder=new h,this.s=0,this.count=0}write(e){this.s===e?this.count++:(I(this),this.count=1,this.s=e)}toUint8Array(){return I(this),p(this.encoder)}}const D=e=>{if(e.count>0){const t=2*e.diff+(1===e.count?0:1);y(e.encoder,t),e.count>1&&w(e.encoder,e.count-2)}};class E{constructor(){this.encoder=new h,this.s=0,this.count=0,this.diff=0}write(e){this.diff===e-this.s?(this.s=e,this.count++):(D(this),this.count=1,this.diff=e-this.s,this.s=e)}toUint8Array(){return D(this),p(this.encoder)}}class R{constructor(){this.sarr=[],this.s="",this.lensE=new x}write(e){this.s+=e,this.s.length>19&&(this.sarr.push(this.s),this.s=""),this.lensE.write(e.length)}toUint8Array(){const e=new h;return this.sarr.push(this.s),this.s="",b(e,this.sarr.join("")),k(e,this.lensE.toUint8Array()),p(e)}}})),s.register("5es75",(function(t,n){e(t.exports,"MAX_SAFE_INTEGER",(()=>o)),e(t.exports,"isInteger",(()=>c));var r=s("bGsfJ"),i=s("bcXZT");const o=Number.MAX_SAFE_INTEGER,c=(Number.MIN_SAFE_INTEGER,i.BITS31,i.BITS32,Number.isInteger||(e=>"number"==typeof e&&isFinite(e)&&r.floor(e)===e));Number.isNaN,Number.parseInt})),s.register("bcXZT",(function(t,s){e(t.exports,"BIT1",(()=>n)),e(t.exports,"BIT2",(()=>r)),e(t.exports,"BIT3",(()=>i)),e(t.exports,"BIT4",(()=>o)),e(t.exports,"BIT6",(()=>c)),e(t.exports,"BIT7",(()=>a)),e(t.exports,"BIT8",(()=>h)),e(t.exports,"BITS5",(()=>l)),e(t.exports,"BITS6",(()=>d)),e(t.exports,"BITS7",(()=>u)),e(t.exports,"BITS8",(()=>p)),e(t.exports,"BITS21",(()=>g)),e(t.exports,"BITS31",(()=>f)),e(t.exports,"BITS32",(()=>w));const n=1,r=2,i=4,o=8,c=32,a=64,h=128,l=31,d=63,u=127,p=255,g=2097151,f=2147483647,w=4294967295})),s.register("8drkQ",(function(t,n){e(t.exports,"fromCharCode",(()=>i)),e(t.exports,"fromCamelCase",(()=>a)),e(t.exports,"utf8TextEncoder",(()=>h)),e(t.exports,"encodeUtf8",(()=>l)),e(t.exports,"utf8TextDecoder",(()=>d)),e(t.exports,"decodeUtf8",(()=>u)),e(t.exports,"repeat",(()=>p));var r=s("9GMWx");const i=String.fromCharCode,o=(String.fromCodePoint,i(65535),/^\s*/g),c=/([A-Z])/g,a=(e,t)=>(e=>e.replace(o,""))(e.replace(c,(e=>`${t}${(e=>e.toLowerCase())(e)}`))),h="undefined"!=typeof TextEncoder?new TextEncoder:null,l=h?e=>h.encode(e):e=>{const t=unescape(encodeURIComponent(e)),s=t.length,n=new Uint8Array(s);for(let e=0;e<s;e++)n[e]=t.codePointAt(e);return n};let d="undefined"==typeof TextDecoder?null:new TextDecoder("utf-8",{fatal:!0,ignoreBOM:!0});d&&1===d.decode(new Uint8Array).length&&(d=null);const u=d?e=>d.decode(e):e=>{let t=e.length,s="",n=0;for(;t>0;){const r=t<1e4?t:1e4,i=e.subarray(n,n+r);n+=r,s+=String.fromCodePoint.apply(null,i),t-=r}return decodeURIComponent(escape(s))},p=(e,t)=>r.unfold(t,(()=>e)).join("")})),s.register("l5188",(function(t,n){e(t.exports,"createDecoder",(()=>u)),e(t.exports,"hasContent",(()=>p)),e(t.exports,"clone",(()=>g)),e(t.exports,"readVarUint8Array",(()=>f)),e(t.exports,"readVarUint",(()=>y)),e(t.exports,"readUint8",(()=>w)),e(t.exports,"readVarInt",(()=>_)),e(t.exports,"readVarString",(()=>m)),e(t.exports,"readAny",(()=>k)),e(t.exports,"RleDecoder",(()=>v)),e(t.exports,"UintOptRleDecoder",(()=>A)),e(t.exports,"IntDiffOptRleDecoder",(()=>T)),e(t.exports,"StringDecoder",(()=>C));var r=s("bcXZT"),i=s("bGsfJ"),o=s("5es75"),c=s("8drkQ"),a=s("3Y8uz");s("7BTJz");const h=a.create("Unexpected end of array"),l=a.create("Integer out of Range");class d{constructor(e){this.arr=e,this.pos=0}}const u=e=>new d(e),p=e=>e.pos!==e.arr.length,g=(e,t=e.pos)=>{const s=u(e.arr);return s.pos=t,s},f=e=>((e,t)=>{const s=new Uint8Array(e.arr.buffer,e.pos+e.arr.byteOffset,t);return e.pos+=t,s})(e,y(e)),w=e=>e.arr[e.pos++],y=e=>{let t=0,s=1;const n=e.arr.length;for(;e.pos<n;){const n=e.arr[e.pos++];if(t+=(n&r.BITS7)*s,s*=128,n<r.BIT8)return t;if(t>o.MAX_SAFE_INTEGER)throw l}throw h},_=e=>{let t=e.arr[e.pos++],s=t&r.BITS6,n=64;const i=(t&r.BIT7)>0?-1:1;if(!(t&r.BIT8))return i*s;const c=e.arr.length;for(;e.pos<c;){if(t=e.arr[e.pos++],s+=(t&r.BITS7)*n,n*=128,t<r.BIT8)return i*s;if(s>o.MAX_SAFE_INTEGER)throw l}throw h},m=c.utf8TextDecoder?e=>c.utf8TextDecoder.decode(f(e)):e=>{let t=y(e);if(0===t)return"";{let s=String.fromCodePoint(w(e));if(--t<100)for(;t--;)s+=String.fromCodePoint(w(e));else for(;t>0;){const n=t<1e4?t:1e4,r=e.arr.subarray(e.pos,e.pos+n);e.pos+=n,s+=String.fromCodePoint.apply(null,r),t-=n}return decodeURIComponent(escape(s))}},b=(e,t)=>{const s=new DataView(e.arr.buffer,e.arr.byteOffset+e.pos,t);return e.pos+=t,s},S=[e=>{},e=>null,_,e=>b(e,4).getFloat32(0,!1),e=>b(e,8).getFloat64(0,!1),e=>b(e,8).getBigInt64(0,!1),e=>!1,e=>!0,m,e=>{const t=y(e),s={};for(let n=0;n<t;n++)s[m(e)]=k(e);return s},e=>{const t=y(e),s=[];for(let n=0;n<t;n++)s.push(k(e));return s},f],k=e=>S[127-w(e)](e);class v extends d{constructor(e,t){super(e),this.reader=t,this.s=null,this.count=0}read(){return 0===this.count&&(this.s=this.reader(this),p(this)?this.count=y(this)+1:this.count=-1),this.count--,this.s}}class A extends d{constructor(e){super(e),this.s=0,this.count=0}read(){if(0===this.count){this.s=_(this);const e=i.isNegativeZero(this.s);this.count=1,e&&(this.s=-this.s,this.count=y(this)+2)}return this.count--,this.s}}class T extends d{constructor(e){super(e),this.s=0,this.count=0,this.diff=0}read(){if(0===this.count){const e=_(this),t=1&e;this.diff=i.floor(e/2),this.count=1,t&&(this.count=y(this)+2)}return this.s+=this.diff,this.count--,this.s}}class C{constructor(e){this.decoder=new A(e),this.str=m(this.decoder),this.spos=0}read(){const e=this.spos+this.decoder.read(),t=this.str.slice(this.spos,e);return this.spos=e,t}}})),s.register("3Y8uz",(function(t,s){e(t.exports,"create",(()=>n)),e(t.exports,"methodUnimplemented",(()=>r)),e(t.exports,"unexpectedCase",(()=>i));const n=e=>new Error(e),r=()=>{throw n("Method unimplemented")},i=()=>{throw n("Unexpected case")}})),s.register("ouOhr",(function(t,n){e(t.exports,"uint32",(()=>i)),e(t.exports,"uuidv4",(()=>o)),s("bGsfJ"),s("bcXZT");var r=s("2grmT");Math.random;const i=()=>(0,r.getRandomValues)(new Uint32Array(1))[0],o=()=>"10000000-1000-4000-8000-100000000000".replace(/[018]/g,(e=>(e^i()&15>>e/4).toString(16)))})),s.register("2grmT",(function(t,s){e(t.exports,"getRandomValues",(()=>n)),crypto.subtle;const n=crypto.getRandomValues.bind(crypto)})),s.register("fJEwH",(function(t,n){e(t.exports,"create",(()=>r)),s("16gRh");const r=e=>new Promise(e);Promise.all.bind(Promise)})),s.register("16gRh",(function(t,n){e(t.exports,"getUnixTime",(()=>r)),s("cdEUL"),s("bGsfJ");const r=Date.now})),s.register("cdEUL",(function(t,n){e(t.exports,"prefix",(()=>c));var r=s("bGsfJ");const i=["","k","M","G","T","P","E","Z","Y"],o=["","m","μ","n","p","f","a","z","y"],c=(e,t=0)=>{const s=0===e?0:r.log10(e);let n=0;for(;s<3*n&&t>-8;)t--,n--;for(;s>=3+3*n&&t<8;)t++,n++;const c=t<0?o[-t]:i[t];return{n:r.round(1e12*(n>0?e/r.exp10(3*n):e*r.exp10(-3*n)))/1e12,prefix:c}}})),s.register("jx2H5",(function(t,n){e(t.exports,"createUint8ArrayFromArrayBuffer",(()=>a)),e(t.exports,"toBase64",(()=>h)),e(t.exports,"fromBase64",(()=>l)),e(t.exports,"copyUint8Array",(()=>d));var r=s("8drkQ"),i=s("isVtz"),o=(s("9GMWx"),s("bGsfJ"),s("7BTJz"),s("l5188"),s("laHbQ").Buffer);const c=e=>new Uint8Array(e),a=e=>new Uint8Array(e),h=i.isBrowser?e=>{let t="";for(let s=0;s<e.byteLength;s++)t+=r.fromCharCode(e[s]);return btoa(t)}:e=>o.from(e.buffer,e.byteOffset,e.byteLength).toString("base64"),l=i.isBrowser?e=>{const t=atob(e),s=c(t.length);for(let e=0;e<t.length;e++)s[e]=t.charCodeAt(e);return s}:e=>{const t=o.from(e,"base64");return s=t.buffer,n=t.byteOffset,r=t.byteLength,new Uint8Array(s,n,r);var s,n,r},d=e=>{const t=c(e.byteLength);return t.set(e),t}})),s.register("isVtz",(function(t,n){e(t.exports,"isBrowser",(()=>d)),e(t.exports,"getVariable",(()=>f)),e(t.exports,"supportsColor",(()=>y));var r=s("96q9T"),i=s("8drkQ"),o=s("9xF6A"),c=s("hpXBJ"),a=s("4H1bc"),h=s("b3MRX");const l=void 0!==h&&h.release&&/node|io\.js/.test(h.release.name)&&"[object process]"===Object.prototype.toString.call(void 0!==h?h:0),d="undefined"!=typeof window&&"undefined"!=typeof document&&!l;let u;"undefined"!=typeof navigator&&/Mac/.test(navigator.platform);const p=[],g=e=>(()=>{if(void 0===u)if(l){u=r.create();const e=h.argv;let t=null;for(let s=0;s<e.length;s++){const n=e[s];"-"===n[0]?(null!==t&&u.set(t,""),t=n):null!==t?(u.set(t,n),t=null):p.push(n)}null!==t&&u.set(t,"")}else"object"==typeof location?(u=r.create(),(location.search||"?").slice(1).split("&").forEach((e=>{if(0!==e.length){const[t,s]=e.split("=");u.set(`--${i.fromCamelCase(t,"-")}`,s),u.set(`-${i.fromCamelCase(t,"-")}`,s)}}))):u=r.create();return u})().has(e),f=e=>l?o.undefinedToNull(h.env[e.toUpperCase().replaceAll("-","_")]):o.undefinedToNull(c.varStorage.getItem(e)),w=e=>g("--"+e)||null!==f(e),y=(w("production"),l&&a.isOneOf(void 0,["true","1","2"])||!g("--no-colors")&&!w("no-color")&&(!l||h.stdout.isTTY)&&(!l||g("--color")||null!==f("COLORTERM")||(f("TERM")||"").includes("color")))})),s.register("9xF6A",(function(t,s){e(t.exports,"undefinedToNull",(()=>n));const n=e=>void 0===e?null:e})),s.register("hpXBJ",(function(t,s){e(t.exports,"varStorage",(()=>i)),e(t.exports,"onChange",(()=>o)),e(t.exports,"offChange",(()=>c));let n=new class{constructor(){this.map=new Map}setItem(e,t){this.map.set(e,t)}getItem(e){return this.map.get(e)}},r=!0;try{"undefined"!=typeof localStorage&&localStorage&&(n=localStorage,r=!1)}catch(e){}const i=n,o=e=>r||addEventListener("storage",e),c=e=>r||removeEventListener("storage",e)})),s.register("4H1bc",(function(t,n){e(t.exports,"callAll",(()=>c)),e(t.exports,"nop",(()=>a)),e(t.exports,"id",(()=>h)),e(t.exports,"equalityDeep",(()=>l)),e(t.exports,"isOneOf",(()=>d));var r=s("9GMWx"),i=s("7C9F2"),o=s("aeA7S");const c=(e,t,s=0)=>{try{for(;s<e.length;s++)e[s](...t)}finally{s<e.length&&c(e,t,s+1)}},a=()=>{},h=e=>e,l=(e,t)=>{if(e===t)return!0;if(null==e||null==t||e.constructor!==t.constructor)return!1;if(null!=e[o.EqualityTraitSymbol])return e[o.EqualityTraitSymbol](t);switch(e.constructor){case ArrayBuffer:e=new Uint8Array(e),t=new Uint8Array(t);case Uint8Array:if(e.byteLength!==t.byteLength)return!1;for(let s=0;s<e.length;s++)if(e[s]!==t[s])return!1;break;case Set:if(e.size!==t.size)return!1;for(const s of e)if(!t.has(s))return!1;break;case Map:if(e.size!==t.size)return!1;for(const s of e.keys())if(!t.has(s)||!l(e.get(s),t.get(s)))return!1;break;case Object:if(i.length(e)!==i.length(t))return!1;for(const s in e)if(!i.hasProperty(e,s)||!l(e[s],t[s]))return!1;break;case Array:if(e.length!==t.length)return!1;for(let s=0;s<e.length;s++)if(!l(e[s],t[s]))return!1;break;default:return!1}return!0},d=(e,t)=>t.includes(e);r.isArray})),s.register("7C9F2",(function(t,s){e(t.exports,"assign",(()=>n)),e(t.exports,"forEach",(()=>i)),e(t.exports,"length",(()=>o)),e(t.exports,"isEmpty",(()=>a)),e(t.exports,"hasProperty",(()=>h)),e(t.exports,"equalFlat",(()=>l)),e(t.exports,"deepFreeze",(()=>u));const n=Object.assign,r=Object.keys,i=(Object.values,(e,t)=>{for(const s in e)t(e[s],s)}),o=e=>r(e).length,c=e=>r(e).length,a=e=>{for(const t in e)return!1;return!0},h=(e,t)=>Object.prototype.hasOwnProperty.call(e,t),l=(e,t)=>e===t||c(e)===c(t)&&((e,t)=>{for(const s in e)if(!t(e[s],s))return!1;return!0})(e,((e,s)=>(void 0!==e||h(t,s))&&t[s]===e)),d=Object.freeze,u=e=>{for(const t in e){const s=e[t];"object"!=typeof s&&"function"!=typeof s||u(e[t])}return d(e)}})),s.register("aeA7S",(function(t,s){e(t.exports,"EqualityTraitSymbol",(()=>n));const n=Symbol("Equality")})),s.register("9hwjE",(function(t,n){e(t.exports,"print",(()=>u)),e(t.exports,"warn",(()=>p)),e(t.exports,"BOLD",(()=>s("9okbY").BOLD)),e(t.exports,"UNBOLD",(()=>s("9okbY").UNBOLD)),e(t.exports,"RED",(()=>s("9okbY").RED)),e(t.exports,"ORANGE",(()=>s("9okbY").ORANGE));var r=s("isVtz"),i=s("5zT0w"),o=s("2djb1"),c=s("8kkbA"),a=(s("kQNaO"),s("96q9T")),h=(s("kdpDU"),s("bGsfJ"),s("9okbY"));h=s("9okbY");const l={[h.BOLD]:o.create("font-weight","bold"),[h.UNBOLD]:o.create("font-weight","normal"),[h.BLUE]:o.create("color","blue"),[h.GREEN]:o.create("color","green"),[h.GREY]:o.create("color","grey"),[h.RED]:o.create("color","red"),[h.PURPLE]:o.create("color","purple"),[h.ORANGE]:o.create("color","orange"),[h.UNCOLOR]:o.create("color","black")},d=r.supportsColor?e=>{1===e.length&&e[0]?.constructor===Function&&(e=e[0]());const t=[],s=[],n=a.create();let r=[],i=0;for(;i<e.length;i++){const r=e[i],o=l[r];if(void 0!==o)n.set(o.left,o.right);else{if(void 0===r)break;if(r.constructor!==String&&r.constructor!==Number)break;{const e=c.mapToStyleString(n);i>0||e.length>0?(t.push("%c"+r),s.push(e)):t.push(r)}}}for(i>0&&(r=s,r.unshift(t.join("")));i<e.length;i++){const t=e[i];t instanceof Symbol||r.push(t)}return r}:h.computeNoColorLoggingArgs,u=(...e)=>{console.log(...d(e)),g.forEach((t=>t.print(e)))},p=(...e)=>{console.warn(...d(e)),e.unshift(h.ORANGE),g.forEach((t=>t.print(e)))},g=i.create()})),s.register("2djb1",(function(t,s){e(t.exports,"create",(()=>r)),e(t.exports,"forEach",(()=>i));class n{constructor(e,t){this.left=e,this.right=t}}const r=(e,t)=>new n(e,t),i=(e,t)=>e.forEach((e=>t(e.left,e.right)))})),s.register("8kkbA",(function(t,n){e(t.exports,"append",(()=>a)),e(t.exports,"addEventListener",(()=>h)),e(t.exports,"element",(()=>l)),e(t.exports,"text",(()=>d)),e(t.exports,"mapToStyleString",(()=>u));var r=s("2djb1"),i=s("96q9T");const o="undefined"!=typeof document?document:{},c=("undefined"!=typeof DOMParser&&new DOMParser,e=>{const t=o.createDocumentFragment();for(let s=0;s<e.length;s++)p(t,e[s]);return t}),a=(e,t)=>(p(e,c(t)),e),h=(e,t,s)=>e.addEventListener(t,s),l=(e,t=[],s=[])=>a(((e,t)=>(r.forEach(t,((t,s)=>{!1===s?e.removeAttribute(t):!0===s?e.setAttribute(t,""):e.setAttribute(t,s)})),e))((e=>o.createElement(e))(e),t),s),d=e=>o.createTextNode(e),u=e=>i.map(e,((e,t)=>`${t}:${e};`)).join(""),p=(e,t)=>e.appendChild(t);o.ELEMENT_NODE,o.TEXT_NODE,o.CDATA_SECTION_NODE,o.COMMENT_NODE,o.DOCUMENT_NODE,o.DOCUMENT_TYPE_NODE,o.DOCUMENT_FRAGMENT_NODE})),s.register("kQNaO",(function(t,s){e(t.exports,"stringify",(()=>n));const n=JSON.stringify;JSON.parse})),s.register("kdpDU",(function(t,n){e(t.exports,"enqueue",(()=>o)),s("16gRh");let r=[];const i=()=>{for(let e=0;e<r.length;e++)r[e]();r=[]},o=e=>{r.push(e),1===r.length&&setTimeout(i,0)},c=e=>class{constructor(e){this._=e}destroy(){e(this._)}};c(clearTimeout),c(clearInterval),c((e=>"undefined"!=typeof requestAnimationFrame&&cancelAnimationFrame(e))),c((e=>"undefined"!=typeof cancelIdleCallback&&cancelIdleCallback(e)))})),s.register("9okbY",(function(t,n){e(t.exports,"BOLD",(()=>h)),e(t.exports,"UNBOLD",(()=>l)),e(t.exports,"BLUE",(()=>d)),e(t.exports,"GREY",(()=>u)),e(t.exports,"GREEN",(()=>p)),e(t.exports,"RED",(()=>g)),e(t.exports,"PURPLE",(()=>f)),e(t.exports,"ORANGE",(()=>w)),e(t.exports,"UNCOLOR",(()=>y)),e(t.exports,"computeNoColorLoggingArgs",(()=>_)),e(t.exports,"createModuleLogger",(()=>k));var r=s("9Juxm"),i=s("16gRh"),o=s("isVtz"),c=s("4H1bc"),a=s("kQNaO");const h=r.create(),l=r.create(),d=r.create(),u=r.create(),p=r.create(),g=r.create(),f=r.create(),w=r.create(),y=r.create(),_=e=>{1===e.length&&e[0]?.constructor===Function&&(e=e[0]());const t=[],s=[];let n=0;for(;n<e.length;n++){const s=e[n];if(void 0===s)break;if(s.constructor===String||s.constructor===Number)t.push(s);else if(s.constructor===Object)break}for(n>0&&s.push(t.join(""));n<e.length;n++){const t=e[n];t instanceof Symbol||s.push(t)}return s},m=[p,f,w,d];let b=0,S=i.getUnixTime();const k=(e,t)=>{const s=m[b],n=o.getVariable("log"),r=null!==n&&("*"===n||"true"===n||new RegExp(n,"gi").test(t));return b=(b+1)%m.length,t+=": ",r?(...n)=>{1===n.length&&n[0]?.constructor===Function&&(n=n[0]());const r=i.getUnixTime(),o=r-S;S=r,e(s,t,y,...n.map((e=>{switch(null!=e&&e.constructor===Uint8Array&&(e=Array.from(e)),typeof e){case"string":case"symbol":return e;default:return a.stringify(e)}})),s," +"+o+"ms")}:c.nop}})),s.register("9Juxm",(function(t,s){e(t.exports,"create",(()=>n));const n=Symbol})),s.register("iRxFz",(function(t,s){e(t.exports,"iteratorFilter",(()=>r)),e(t.exports,"iteratorMap",(()=>i));const n=e=>({[Symbol.iterator](){return this},next:e}),r=(e,t)=>n((()=>{let s;do{s=e.next()}while(!s.done&&!t(s.value));return s})),i=(e,t)=>n((()=>{const{done:s,value:n}=e.next();return{done:s,value:s?void 0:t(n)}}))})),s.register("4AWOh",(function(t,n){e(t.exports,"Awareness",(()=>l)),e(t.exports,"removeAwarenessStates",(()=>d)),e(t.exports,"encodeAwarenessUpdate",(()=>u)),e(t.exports,"applyAwarenessUpdate",(()=>p));var r=s("7BTJz"),i=s("l5188"),o=s("16gRh"),c=s("bGsfJ"),a=s("8Gyr5"),h=s("4H1bc");class l extends a.Observable{constructor(e){super(),this.doc=e,this.clientID=e.clientID,this.states=new Map,this.meta=new Map,this._checkInterval=setInterval((()=>{const e=o.getUnixTime();null!==this.getLocalState()&&15e3<=e-this.meta.get(this.clientID).lastUpdated&&this.setLocalState(this.getLocalState());const t=[];this.meta.forEach(((s,n)=>{n!==this.clientID&&3e4<=e-s.lastUpdated&&this.states.has(n)&&t.push(n)})),t.length>0&&d(this,t,"timeout")}),c.floor(3e3)),e.on("destroy",(()=>{this.destroy()})),this.setLocalState({})}destroy(){this.emit("destroy",[this]),this.setLocalState(null),super.destroy(),clearInterval(this._checkInterval)}getLocalState(){return this.states.get(this.clientID)||null}setLocalState(e){const t=this.clientID,s=this.meta.get(t),n=void 0===s?0:s.clock+1,r=this.states.get(t);null===e?this.states.delete(t):this.states.set(t,e),this.meta.set(t,{clock:n,lastUpdated:o.getUnixTime()});const i=[],c=[],a=[],l=[];null===e?l.push(t):null==r?null!=e&&i.push(t):(c.push(t),h.equalityDeep(r,e)||a.push(t)),(i.length>0||a.length>0||l.length>0)&&this.emit("change",[{added:i,updated:a,removed:l},"local"]),this.emit("update",[{added:i,updated:c,removed:l},"local"])}setLocalStateField(e,t){const s=this.getLocalState();null!==s&&this.setLocalState({...s,[e]:t})}getStates(){return this.states}}const d=(e,t,s)=>{const n=[];for(let s=0;s<t.length;s++){const r=t[s];if(e.states.has(r)){if(e.states.delete(r),r===e.clientID){const t=e.meta.get(r);e.meta.set(r,{clock:t.clock+1,lastUpdated:o.getUnixTime()})}n.push(r)}}n.length>0&&(e.emit("change",[{added:[],updated:[],removed:n},s]),e.emit("update",[{added:[],updated:[],removed:n},s]))},u=(e,t,s=e.states)=>{const n=t.length,i=r.createEncoder();r.writeVarUint(i,n);for(let o=0;o<n;o++){const n=t[o],c=s.get(n)||null,a=e.meta.get(n).clock;r.writeVarUint(i,n),r.writeVarUint(i,a),r.writeVarString(i,JSON.stringify(c))}return r.toUint8Array(i)},p=(e,t,s)=>{const n=i.createDecoder(t),r=o.getUnixTime(),c=[],a=[],l=[],d=[],u=i.readVarUint(n);for(let t=0;t<u;t++){const t=i.readVarUint(n);let s=i.readVarUint(n);const o=JSON.parse(i.readVarString(n)),u=e.meta.get(t),p=e.states.get(t),g=void 0===u?0:u.clock;(g<s||g===s&&null===o&&e.states.has(t))&&(null===o?t===e.clientID&&null!=e.getLocalState()?s++:e.states.delete(t):e.states.set(t,o),e.meta.set(t,{clock:s,lastUpdated:r}),void 0===u&&null!==o?c.push(t):void 0!==u&&null===o?d.push(t):null!==o&&(h.equalityDeep(o,p)||l.push(t),a.push(t)))}(c.length>0||l.length>0||d.length>0)&&e.emit("change",[{added:c,updated:l,removed:d},s]),(c.length>0||a.length>0||d.length>0)&&e.emit("update",[{added:c,updated:a,removed:d},s])}})),s.register("kRCFI",(function(t,n){e(t.exports,"messageYjsSyncStep1",(()=>c)),e(t.exports,"messageYjsSyncStep2",(()=>a)),e(t.exports,"messageYjsUpdate",(()=>h)),e(t.exports,"writeSyncStep1",(()=>l)),e(t.exports,"writeSyncStep2",(()=>d)),e(t.exports,"writeUpdate",(()=>p)),e(t.exports,"readSyncMessage",(()=>f));var r=s("7BTJz"),i=s("l5188"),o=s("bx9uf");const c=0,a=1,h=2,l=(e,t)=>{r.writeVarUint(e,c);const s=o.encodeStateVector(t);r.writeVarUint8Array(e,s)},d=(e,t,s)=>{r.writeVarUint(e,a),r.writeVarUint8Array(e,o.encodeStateAsUpdate(t,s))},u=(e,t,s,n)=>{try{o.applyUpdate(t,i.readVarUint8Array(e),s)}catch(e){null!=n&&n(e),console.error("Caught error while handling a Yjs update",e)}},p=(e,t)=>{r.writeVarUint(e,h),r.writeVarUint8Array(e,t)},g=u,f=(e,t,s,n,r)=>{const o=i.readVarUint(e);switch(o){case c:((e,t,s)=>{d(t,s,i.readVarUint8Array(e))})(e,t,s);break;case a:u(e,s,n,r);break;case h:g(e,s,n,r);break;default:throw new Error("Unknown message type")}return o}})),s.register("bEPl9",(function(t,n){e(t.exports,"subscribe",(()=>d)),e(t.exports,"unsubscribe",(()=>u)),e(t.exports,"publish",(()=>p));var r=s("96q9T"),i=s("5zT0w"),o=s("jx2H5"),c=s("hpXBJ");const a=new Map,h="undefined"==typeof BroadcastChannel?class{constructor(e){this.room=e,this.onmessage=null,this._onChange=t=>t.key===e&&null!==this.onmessage&&this.onmessage({data:o.fromBase64(t.newValue||"")}),c.onChange(this._onChange)}postMessage(e){c.varStorage.setItem(this.room,o.toBase64(o.createUint8ArrayFromArrayBuffer(e)))}close(){c.offChange(this._onChange)}}:BroadcastChannel,l=e=>r.setIfUndefined(a,e,(()=>{const t=i.create(),s=new h(e);return s.onmessage=e=>t.forEach((t=>t(e.data,"broadcastchannel"))),{bc:s,subs:t}})),d=(e,t)=>(l(e).subs.add(t),t),u=(e,t)=>{const s=l(e),n=s.subs.delete(t);return n&&0===s.subs.size&&(s.bc.close(),a.delete(e)),n},p=(e,t,s=null)=>{const n=l(e);n.bc.postMessage(t),n.subs.forEach((e=>e(t,s)))}})),s.register("cIOyM",(function(e,t){s("bx9uf")})),s.register("iV07c",(function(t,n){e(t.exports,"DexieTransport",(()=>c)),s("6frWy");var r=s("P7Ozw"),i=s("bx9uf"),o=s("cPWby");class c{uidDB="";key="";_isConnected=!1;pending=null;replayed=!1;get isConnected(){return this._isConnected}async connect(e){this.uidDB=e.uidDB,this.key=e.room,this.pending=await o.default.compactYjsUpdates(this.uidDB,this.key,(e=>{const t=e.flatMap((e=>(0,r.extractDocUpdates)(e)));return 0===t.length?null:(0,r.frameDocUpdate)(i.mergeUpdates(t))})),this._isConnected=!0,this.replayIfReady()}disconnect(){this._isConnected=!1,this.messageCallback=void 0,this.pending=null,this.replayed=!1}send(e){const t=(0,r.extractDocUpdates)(e);if(0!==t.length)return o.default.appendYjsUpdate(this.uidDB,this.key,(0,r.frameDocUpdate)(1===t.length?t[0]:i.mergeUpdates(t)))}onMessage(e){return this.messageCallback=e,this.replayIfReady(),()=>{this.messageCallback=void 0}}replayIfReady(){if(this.replayed||!this._isConnected||!this.messageCallback)return;this.replayed=!0;const e=this.pending;this.pending=null,e&&this.messageCallback(e)}}})),s.register("bDw11",(function(t,n){e(t.exports,"CRDT",(()=>u));var r=s("bx9uf"),i=s("8kr9p"),o=s("c4j9z"),c=s("goBin"),a=s("du9vu"),h=s("7X7lt");const l="q",d="s";class u{timestamp=Date.now();classroomMode=0;peerKeyCache=new Map;constructor(e,t){this.doc=new r.Doc,this.callback=t||((e,t)=>{console.warn("SyncDB: no callback provided")}),this.length=0,this.peerID=e,this.codes=this.doc.getMap("c"),this.chat=new(0,h.YKeyValue)(this.doc.getArray("chat")),this.metadata=this.doc.getArray("meta"),this.identities=this.doc.getMap("name"),this.user=this.doc.getMap("user"),this.ownerKey=this.doc.getMap("ownerKey"),this.wrappedKeys=this.doc.getMap("wrappedKeys"),this.signingKeys=this.doc.getMap("signingKeys"),this.signingKeyReady=o.generateSigningKeyPair().then((async e=>{const t=await o.exportPublicKey(e.publicKey);return this.signingKeys.set(this.peerID,t),e}))}setMode(e,t,s,n){this.classroomMode=e,this.roomId=t,this.uidDB=s,this.ownerTokenHash=n?.ownerTokenHash||void 0,this.incomingOwnerToken=n?.ownerToken||void 0}async resolveOwnerToken(){const e=`${this.roomId??"default"}:ownerToken`,t=this.uidDB??"default";if(this.incomingOwnerToken){const s=await o.sha256Base64(this.incomingOwnerToken);return this.ownerTokenHash&&s!==this.ownerTokenHash||(this.localOwnerToken=this.incomingOwnerToken,this.ownerTokenHash=s,await(0,c.putStoredValue)(t,e,this.localOwnerToken)),{hash:this.ownerTokenHash??"",token:this.localOwnerToken}}const s=await(0,c.getStoredValue)(t,e);if(s){const e=await o.sha256Base64(s);this.ownerTokenHash&&e!==this.ownerTokenHash||(this.localOwnerToken=s,this.ownerTokenHash=e)}return{hash:this.ownerTokenHash??"",token:this.localOwnerToken}}async init(e){this.length=Math.max(this.length,e.length);const t=[];for(let s=0;s<e.length;s++)await this.collectInitWrites(l,s,e[s][l],t),await this.collectInitWrites(d,s,e[s][d],t);this.doc.transact((()=>{for(const e of t){const t=this.getOwnSectionArray(e.type,e.id);(t.length<=e.i||null==t.get(e.i))&&(0,a.setArrayValue)(t,e.i,e.value)}for(let t=0;t<e.length;t++)this.initText(t,e[t].c)}),this.peerID),this.registerCallbacks(),await this.maybeBecomeOwner().catch((e=>console.warn("maybeBecomeOwner failed ->",e))),await this.rewrapForCurrentOwner().catch((e=>console.warn("rewrapForCurrentOwner failed ->",e))),await this.fireInitialState(),clearTimeout(this.resyncTimer),this.resyncTimer=setTimeout((()=>{this.fireQuizSurvey().catch((e=>console.warn("delayed quiz/survey re-check failed ->",e)))}),4e3)}async collectInitWrites(e,t,s,n){if(s&&0!==s.length)for(let r=0;r<s.length;r++){const i=s[r][this.peerID];if(void 0===i)continue;const c=0!==this.classroomMode?await o.encryptValue(await this.ensureContentKey(),i):i;n.push({type:e,id:t,i:r,value:c})}}async fireQuizSurvey(){const e=this.collectSectionIds(l);e.size>0&&this.callback(await Promise.all([...e].map((async e=>({id:e,data:await this.getSection(e,l)})))),"quiz");const t=this.collectSectionIds(d);t.size>0&&this.callback(await Promise.all([...t].map((async e=>({id:e,data:await this.getSection(e,d)})))),"survey")}async fireInitialState(){const e=this.getPeers();Object.keys(e).length>0&&this.callback(e,"peer");const t=this.getIdentities();Object.keys(t).length>0&&this.callback(t,"identity");const s=this.getCursors();s.length>0&&this.callback(s,"cursor"),await this.fireQuizSurvey();const n=new Set;for(const e of this.codes.keys())try{const[t]=JSON.parse(e);n.add(t)}catch{}n.size>0&&this.callback(this.getCode(n),"code");const r=await this.buildChatVector();r.length>0&&this.callback(r,"chat")}async buildChatVector(){const e=[];for(const[t,s]of this.chat.map)e.push({...s.val,id:parseInt(t)});const t=await Promise.all(e.map((e=>this.verifyChatEntry(e))));return t.sort(((e,t)=>e.id-t.id)),t}async verifyChatEntry(e){if(!e.signature)return{...e,verified:!1};const t=this.signingKeys.get(String(e.user));if(!t)return{...e,verified:!1};const s=await o.verifyChatMessage(t,{message:String(e.message),user:String(e.user),ts:e.id},e.signature);return{...e,verified:s}}setAwareness(e,t){this.awareness=e,e.setLocalState({peerID:this.peerID,color:this.getColor(),name:t}),t&&this.identities.get(this.peerID)!==t&&this.identities.set(this.peerID,t),e.on("change",(e=>{const t=this.getPeers();this.callback(t,"peer");const s=this.getCursors();s.length>0&&this.callback(s,"cursor")})),this.callback(this.getPeers(),"peer")}registerCallbacks(){this.metadata.observe((()=>{this.callback(this.getOwner()===this.peerID,"ownership"),this.maybeBecomeOwner().catch((e=>console.warn("maybeBecomeOwner failed ->",e)))})),this.ownerKey.observe((()=>{this.rewrapForCurrentOwner().catch((e=>console.warn("rewrapForCurrentOwner failed ->",e)))})),this.user.observeDeep((e=>{if(0===e.length)return;const t=this.collectSectionIds(l);t.size>0&&Promise.all([...t].map((async e=>({id:e,data:await this.getSection(e,l)})))).then((e=>this.callback(e,"quiz"))).catch((e=>console.warn("quiz decrypt failed ->",e)));const s=this.collectSectionIds(d);s.size>0&&Promise.all([...s].map((async e=>({id:e,data:await this.getSection(e,d)})))).then((e=>this.callback(e,"survey"))).catch((e=>console.warn("survey decrypt failed ->",e)))})),this.identities.observe((()=>{this.callback(this.getIdentities(),"identity")})),this.signingKeys.observe((()=>{this.buildChatVector().then((e=>{e.length>0&&this.callback(e,"chat")})).catch((e=>console.warn("chat re-verify failed ->",e)))})),this.chat.on("change",(e=>{const t=[];for(let[s,n]of e)"add"===n.action&&t.push({id:parseInt(s),entry:n.newValue});0!==t.length&&Promise.all(t.map((({id:e,entry:t})=>this.verifyChatEntry({...t,id:e})))).then((e=>this.callback(e,"chat"))).catch((e=>console.warn("chat verify failed ->",e)))})),this.codes.observeDeep((e=>{const t=new Set;for(const s of e)if(s.target===this.codes)s.keysChanged.forEach((e=>{try{const[s]=JSON.parse(e);t.add(s)}catch{}}));else try{const[e]=JSON.parse(s.path[0]);t.add(e)}catch{}t.size>0&&this.callback(this.getCode(t),"code")}))}encode(){return r.encodeStateAsUpdate(this.doc)}destroy(){clearTimeout(this.resyncTimer),this.doc.destroy()}log(){console.warn("*********** PEERS ***********"),console.warn(this.getPeers()),console.warn("*********** CURSORS ***********"),console.warn(this.getCursors()),console.warn("*********** STATE ***********"),console.warn(this.doc.toJSON())}initText(e,t){if(0!==t.length)for(let s=0;s<t.length;s++)for(let n=0;n<t[s].length;n++)this.initCode(e,s,n,t[s][n])}getCode(e){let t=[];for(const s of e)t.push({id:s,data:this.getAllTexts(s)});return t}getCursors(){if(!this.awareness)return[];const e=[];for(const[,t]of this.awareness.getStates())t?.cursor&&t?.peerID&&t.peerID!==this.peerID&&e.push(t.cursor);return e}getPeers(){if(!this.awareness)return{};const e={};for(const[,t]of this.awareness.getStates())t?.peerID&&(e[t.peerID]=t.name);return e}removePeer(){this.awareness?.setLocalState(null)}getIdentities(){const e={};for(const[t,s]of this.identities)e[t]=s;return e}id(e,t,s){return void 0===s?JSON.stringify([e,t]):JSON.stringify([e,t,s])}collectSectionIds(e){const t=new Set;for(const[,s]of this.user){const n=s.get(e);if(n)for(const e of n.keys())t.add(Number(e))}return t}async getSection(e,t){const s=[];for(const[n,r]of this.user){const i=r.get(t),o=i?.get(String(e));if(o)for(let e=0;e<o.length;e++){const t=o.get(e);if(null==t)continue;const r=await this.decryptSectionValue(n,t);void 0!==r&&(s[e]||(s[e]={}),s[e][n]=r)}}for(let e=0;e<s.length;e++)s[e]||(s[e]={});return s}async decryptSectionValue(e,t){if(0===this.classroomMode||!o.isEncryptedValue(t))return t;try{if(e===this.peerID)return await o.decryptValue(await this.ensureContentKey(),t);if(this.getOwner()===this.peerID&&this.ownerKeyPair){const s=await this.getPeerContentKey(e);if(!s)return;return await o.decryptValue(s,t)}}catch(e){return}}async getPeerContentKey(e){const t=this.wrappedKeys.get(e);if(!t)return;const s=this.peerKeyCache.get(e);if(s&&s.wrapped===t)return s.key;const n=await o.unwrapContentKey(t,this.ownerKeyPair.privateKey);return this.peerKeyCache.set(e,{wrapped:t,key:n}),n}ensureContentKey(){return this.contentKeyReady||(this.contentKeyReady=(0,c.getOrCreateKey)(this.uidDB??"default",`${this.roomId??"default"}:content:${this.peerID}`,(()=>o.generateContentKey())).then((e=>(this.contentKey=e,e)))),this.contentKeyReady}async maybeBecomeOwner(){if(0===this.classroomMode)return;if(this.getOwner()!==this.peerID)return;if(this.ownerKeyPair)return;this.ownerKeyPair=await(0,c.getOrCreateKey)(this.uidDB??"default",this.roomId??"default",(()=>o.generateECDHKeyPair()));const e=await o.exportPublicKey(this.ownerKeyPair.publicKey);this.ownerKey.get(this.peerID)!==e&&this.ownerKey.set(this.peerID,e)}async rewrapForCurrentOwner(){if(0===this.classroomMode)return;const e=this.getOwner();if(!e)return;const t=this.ownerKey.get(e);if(!t)return;const s=await this.ensureContentKey(),n=await o.wrapContentKeyForOwner(s,t);this.wrappedKeys.set(this.peerID,n)}getAllTexts(e){let t,s=[];for(let n=0;this.codes.has(this.id(e,n,0));n++){let r=[];for(let s=0;this.codes.has(this.id(e,n,s));s++)t=this.codes.get(this.id(e,n,s)),r.push(t?.toString()||"");s.push(r)}return s}addQuiz(e,t,s){this.addRecord(l,e,t,s).catch((e=>console.warn("addQuiz failed ->",e)))}addSurvey(e,t,s){this.addRecord(d,e,t,s).catch((e=>console.warn("addSurvey failed ->",e)))}async addRecord(e,t,s,n){const r=0!==this.classroomMode?await o.encryptValue(await this.ensureContentKey(),n):n;this.doc.transact((()=>{const n=this.getOwnSectionArray(e,t);(0,a.setArrayValue)(n,s,r)}),this.peerID)}getOwnSectionArray(e,t){let s=this.user.get(this.peerID);s||(s=new r.Map,this.user.set(this.peerID,s));let n=s.get(e);n||(n=new r.Map,s.set(e,n));let i=n.get(String(t));return i||(i=new r.Array,n.set(String(t),i)),i}initCode(e,t,s,n){if(!this.codes.has(this.id(e,t,s))){const i=this.doc.clientID;this.doc.clientID=0;const o=new r.Text;o.insert(0,n),this.codes.set(this.id(e,t,s),o),this.doc.clientID=i}}async addChatMessage(e){const t=Date.now(),s=await this.signingKeyReady,n=await o.signChatMessage(s.privateKey,{message:e,user:this.peerID,ts:t});this.chat.set(""+t,{color:this.getColor(),message:e,user:this.peerID,signature:n})}updateCode(e,t,s,n){this.codes.has(this.id(e,t,s))&&this.doc.transact((()=>{const r=this.codes.get(this.id(e,t,s));if(void 0!==r)for(let e of n)switch(e.action){case"insert":r.insert(e.index,e.content);break;case"remove":r.delete(e.index,e.content.length);break;default:console.warn("Sync code, unknown action ->",e)}}),"code")}getColor(){return this.color||(this.color=i.getColorFor(this.peerID)),this.color}setCursor(e,t,s){this.awareness?.setLocalStateField("cursor",{id:this.peerID,section:e,project:t.project,file:t.file,state:t.state,color:this.getColor(),name:s})}removeCursor(){this.awareness?.setLocalStateField("cursor",null)}parseClaim(e){const t=e.lastIndexOf("@");return-1===t?{id:e,ts:0}:{id:e.slice(0,t),ts:Number(e.slice(t+1))||0}}claimOwnership(){this.localOwnerToken&&(this.metadata.toArray().map((e=>this.parseClaim(e))).some((e=>e.id===this.peerID))||this.metadata.push([`${this.peerID}@${Date.now()}`])),this.callback(this.getOwner()===this.peerID,"ownership")}getOwner(){const e=this.metadata.toArray().map((e=>this.parseClaim(e)));return 0===e.length?null:e.reduce(((e,t)=>t.ts<e.ts?t:e)).id}}})),s.register("goBin",(function(t,n){e(t.exports,"getOrCreateKey",(()=>i)),e(t.exports,"getStoredValue",(()=>o)),e(t.exports,"putStoredValue",(()=>c));var r=s("cPWby");async function i(e,t,s){try{const n=await r.default.getKey(e,t);if(n)return n;const i=await s();return await r.default.putKey(e,t,i),i}catch(e){return console.warn("keyStore: falling back to session-only key ->",e),s()}}async function o(e,t){try{return await r.default.getKey(e,t)}catch(e){return void console.warn("keyStore: getStoredValue unavailable ->",e)}}async function c(e,t,s){try{await r.default.putKey(e,t,s)}catch(e){console.warn("keyStore: putStoredValue unavailable ->",e)}}})),s.register("du9vu",(function(t,s){function n(e,t,s){if(e.length>t)e.delete(t,1);else for(;e.length<t;)e.push([null]);e.insert(t,[s])}e(t.exports,"setArrayValue",(()=>n))})),s.register("7X7lt",(function(t,n){e(t.exports,"YKeyValue",(()=>i));var r=s("8Gyr5");class i extends r.Observable{constructor(e){super(),this.yarray=e,this.doc=e.doc,this.map=new Map;{const t=e.toArray();this.doc.transact((()=>{for(let s=t.length-1;s>=0;s--){const n=t[s];this.map.has(n.key)?e.delete(s):this.map.set(n.key,n)}}))}e.observe(((t,s)=>{const n=new Map,r=Array.from(t.changes.added);t.changes.deleted.forEach((e=>{e.content.getContent().forEach((e=>{this.map.get(e.key)===e&&(this.map.delete(e.key),n.set(e.key,{action:"delete",oldValue:e.val}))}))}));const i=new Map;r.map((e=>e.content.getContent())).flat().forEach((e=>{i.set(e.key,e)}));const o=new Set,c=e.toArray();this.doc.transact((t=>{for(let t=c.length-1;t>=0&&(i.size>0||o.size>0);t--){const s=c[t];if(o.has(s.key))o.delete(s.key),e.delete(t,1);else if(i.get(s.key)===s){const e=this.map.get(s.key);if(e)o.add(s.key),n.set(s.key,{action:"update",oldValue:e.val,newValue:s.val});else{const e=n.get(s.key);e&&"delete"===e.action?n.set(s.key,{action:"update",newValue:s.val,oldValue:e.oldValue}):n.set(s.key,{action:"add",newValue:s.val})}i.delete(s.key),this.map.set(s.key,s)}else i.has(s.key)&&(o.add(s.key),i.delete(s.key))}})),n.size>0&&this.emit("change",[n,s])}))}set(e,t){this.doc.transact((s=>{this.map.has(e)&&this.delete(e),this.yarray.push([{key:e,val:t}])}))}delete(e){let t=0;for(const s of this.yarray){if(s.key===e){this.yarray.delete(t);break}t++}}get(e){const t=this.map.get(e);return t&&t.val}has(e){return this.map.has(e)}}})),s.register("3MQ2P",(function(t,n){e(t.exports,"wrapTransport",(()=>o));var r=s("gjWRH"),i=s("kPRWr");function o(e,t,s=0){return t?{connect:t=>e.connect(t),disconnect:()=>e.disconnect(),send:t=>{const n=(new TextEncoder).encode(i.Crypto.encode((0,r.encode)(t)));if(0===s)return e.send(n);const o=new Uint8Array(s+n.length);return o.set(n,s),e.send(o)},onMessage:t=>e.onMessage((e=>{try{const n=0===s?e:e.subarray(s),o=(0,r.decode)(i.Crypto.decode((new TextDecoder).decode(n)));t(o)}catch(e){console.warn("security: dropping undecryptable frame ->",e)}})),onPeerConnect:e.onPeerConnect?t=>e.onPeerConnect(t):void 0,get isConnected(){return e.isConnected},get preferredBatchMs(){return e.preferredBatchMs}}:e}})),s.register("kPRWr",(function(t,s){e(t.exports,"Crypto",(()=>n));const n={url:"https://cdn.jsdelivr.net/npm/simple-crypto-js@2.5.0/dist/SimpleCrypto.min.js",crypt:null,check:function(){return!!window.SimpleCrypto},init:function(e){try{"string"==typeof e&&e.length>0?this.crypt=new SimpleCrypto(e):this.crypt=null}catch(e){console.warn("Crypto: ",e),this.crypt=null}},encode:function(e){return this.crypt?this.crypt.encrypt(btoa(encodeURIComponent(JSON.stringify(e)))):JSON.stringify(e)},decode:function(e){return this.crypt?JSON.parse(decodeURIComponent(atob(this.crypt.decrypt(e)))):JSON.parse(e)}}}));
1
+ function e(e,t,s,n){Object.defineProperty(e,t,{get:s,set:n,enumerable:!0,configurable:!0})}var t="undefined"!=typeof globalThis?globalThis:"undefined"!=typeof self?self:"undefined"!=typeof window?window:"undefined"!=typeof global?global:{},s=t.parcelRequirea18f;s.register("bQEo7",(function(t,n){e(t.exports,"Sync",(()=>d)),s("6frWy");var r=s("P7Ozw"),i=s("iV07c"),o=s("8kr9p"),c=s("bDw11"),a=s("c4j9z"),h=(s("gjWRH"),s("8haH3"));function l(e=16){let t="";for(let s=0;s<e;s++)t+="ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789".charAt(Math.floor(62*Math.random()));return t}class d{isConnected=!1;name="";mode=0;replyOnReceive=!1;persistReady=Promise.resolve();constructor(e,t,s,n,r=!1,i=!0){let o;try{o=window.localStorage.getItem("lia-token"),o||(o=l(),window.localStorage.setItem("lia-token",o))}catch(e){console.warn("cannot write to localStorage"),o=l()}this.token=o,this.urlCounter=0,this.cbConnection=e,this.cbRelay=t,this.onConnect=s,this.onReceive=n,this.replyOnReceive=r;const a=this;this.db=new(0,c.CRDT)(o,i?(e,t)=>{if(a.db)switch(t){case"cursor":this.sync("update",{cmd:"cursor",param:e});break;case"peer":this.sync("update",{cmd:"peer",param:e});break;case"identity":this.sync("update",{cmd:"identity",param:e});break;case"code":this.sync("update",{cmd:"code",param:e});break;case"quiz":this.sync("update",{cmd:"quiz",param:e});break;case"survey":this.sync("update",{cmd:"survey",param:e});break;case"chat":this.sync("update",{cmd:"chat",param:e});break;case"ownership":this.sync("update",{cmd:"ownership",param:e});break;default:console.warn("Sync unknown origin",t)}}:void 0)}connect(e){if(this.room=e.room,this.course=e.course,this.password=e.password,this.mode=e.mode,this.pwSalt=e.pwSalt,this.pwCheck=e.pwCheck,this.ownerTokenHash=e.ownerTokenHash,this.db.setMode(e.mode,`${e.course}|${e.room}|${e.password||""}`,e.uidDB||e.course,{ownerTokenHash:e.ownerTokenHash,ownerToken:e.ownerToken}),this.name=e.name.trim(),this.isConnected=!0,e.persistent){const t=new(0,i.DexieTransport);this.persistProvider=new(0,r.GenericProvider)(this.db.doc,t),this.persistReady=this.persistProvider.connect({room:(0,h.docId)(e.uidDB||e.course,e.room,e.fullBackend||""),uidDB:e.uidDB||e.course}),this.persistReady.catch((e=>{console.warn("Sync: local persistence unavailable ->",e?.message||e)}))}else this.persistReady=Promise.resolve()}destroy(){this.persistProvider?.disconnect(),this.persistProvider=void 0,this.db.destroy(),this.cbConnection("disconnect",this.token),this.isConnected=!1}disconnect(){this.db.removePeer(),this.destroy()}uniqueID(e){let t=null;return"string"==typeof this.room&&(this.room.startsWith('"')&&this.room.endsWith('"')||this.room.startsWith("'")&&this.room.endsWith("'"))&&(t=this.room),this.course&&this.room&&(t=JSON.stringify({course:this.course,room:this.room,pw:o.getHashCode(this.password||""),mode:this.mode})),t&&(t=Math.abs(o.getHashCode(t+(e||""))).toString(16)),t||console.warn("Sync: no uniqueID"),t}sendToLia(e){this.cbRelay(e)}sync(e,t=null){this.cbConnection(e,t)}sendDisconnectError(e){this.sync("error",e)}sendWarning(e){this.sync("warning",e)}async sendConnect(){const e=await this.db.resolveOwnerToken();this.ownerTokenHash=e.hash,this.password&&!this.pwCheck&&(this.pwSalt=a.randomBytesBase64(16),this.pwCheck=await a.pbkdf2Base64(this.password,this.pwSalt)),this.sync("connect",{id:this.token,ownerTokenHash:this.ownerTokenHash||"",pwSalt:this.pwSalt||"",pwCheck:this.pwCheck||"",ownerToken:e.token||""}),this.onConnect&&this.onConnect(),this.persistReady.catch((()=>{})).then((()=>{this.password&&0===Object.keys(this.db.getPeers()).filter((e=>e!==this.token)).length&&this.sendWarning("No other participants found — double-check that your classroom password matches theirs."),this.db.claimOwnership()}))}pubsubSend(e,t){JSON.stringify({topic:e,message:t}),new TextEncoder,this.replyOnReceive&&this.onReceive?.(e,t)}pubsubReceive(e){try{const t=(new TextDecoder).decode(e),s=JSON.parse(t);this.onReceive?.(s.topic,s.message)}catch(e){console.warn("Sync: pubsubReceive",e.message)}}load(e,t){try{for(let s=0;s<e.length;s++){const n=document.createElement("script");n.async=!1,n.defer=!0,n.src=e[s],this.urlCounter++;let r=this;n.onload=function(){console.log("successfully loaded =>",e),r.urlCounter--,0==r.urlCounter&&t.init(!0)},n.onerror=function(s){console.warn("could not load =>",e,s),r.urlCounter=0,t.init(!1,`could not load => ${e}`)},document.head.appendChild(n)}}catch(e){console.error("load: ",e),t.init(!1,e.message)}}publish(e){switch(e.message.cmd){case"update":break;case"join":this.db.init(e.message.param).catch((e=>console.warn("db.init failed ->",e)));break;case"chat":this.db.addChatMessage(e.message.param).catch((e=>console.warn("addChatMessage failed ->",e)));break;case"quiz":"quiz"===e.track?.[0][0]&&"id"===e.track?.[1][0]?this.db.addQuiz(e.track[0][1],e.track[1][1],e.message.param):console.warn("SyncTX wrong event ->",e);break;case"survey":"survey"===e.track?.[0][0]&&"id"===e.track?.[1][0]?this.db.addSurvey(e.track[0][1],e.track[1][1],e.message.param):console.warn("SyncTX wrong event ->",e);break;case"code":"code"===e.track?.[0][0]&&"id"===e.track?.[1][0]?this.db.updateCode(e.track[0][1],e.track[1][1],e.message.param.j,e.message.param.msg):console.warn("SyncTX wrong event ->",e);break;case"codes":if("code"===e.track?.[0][0]&&1===e.track.length)for(let t=0;t<e.message.param.length;t++)for(let s=0;s<e.message.param[t].length;s++)this.db.initCode(e.track[0][1],t,s,e.message.param[t][s]);else console.warn("SyncTX wrong event ->",e);break;case"cursor":"code"==e.track?.[0][0]&&this.db.setCursor(e.track[0][1],e.message.param,this.name);break;default:console.warn("SyncTX unknown command:",e.message)}}}})),s.register("6frWy",(function(t,n){e(t.exports,"GenericProvider",(()=>s("P7Ozw").GenericProvider)),e(t.exports,"extractDocUpdates",(()=>s("P7Ozw").extractDocUpdates)),e(t.exports,"frameDocUpdate",(()=>s("P7Ozw").frameDocUpdate)),s("P7Ozw"),s("P7Ozw"),s("cIOyM")})),s.register("P7Ozw",(function(t,n){e(t.exports,"extractDocUpdates",(()=>v)),e(t.exports,"frameDocUpdate",(()=>A)),e(t.exports,"GenericProvider",(()=>C));var r=s("bx9uf"),i=s("4AWOh"),o=s("kRCFI"),c=s("7BTJz"),a=s("l5188"),h=s("8Gyr5"),l=s("bEPl9");const d=0,u=3,p=4,g=6,f=(()=>{const e=new Uint32Array(256);for(let t=0;t<256;t++){let s=t;for(let e=0;e<8;e++)s=1&s?s>>>1^3988292384:s>>>1;e[t]=s}return e})();function w(e){let t=4294967295;for(let s=0;s<e.length;s++)t=t>>>8^f[255&(t^e[s])];return(4294967295^t)>>>0}function y(e){const t=w(e),s=new Uint8Array(4+e.length);return s[0]=t>>>24&255,s[1]=t>>>16&255,s[2]=t>>>8&255,s[3]=255&t,s.set(e,4),s}function _(e,t){if(e.length!==t.length)return!1;for(let s=0;s<e.length;s++)if(e[s]!==t[s])return!1;return!0}const m="undefined"!=typeof CompressionStream&&"undefined"!=typeof DecompressionStream;async function b(e){const t=[],s=e.getReader();for(;;){const{done:e,value:n}=await s.read();if(e)break;t.push(n)}const n=t.reduce(((e,t)=>e+t.length),0),r=new Uint8Array(n);let i=0;for(const e of t)r.set(e,i),i+=e.length;return r}function S(e,t){const s=new Uint8Array(1+t.length);return s[0]=e,s.set(t,1),s}function k(e){const t=r.encodeStateVector(e);let s=0;for(let e=0;e<t.length;e++)s=(s<<5)-s+t[e]|0;return s}function v(e){const t=[],s=e=>{const n=a.createDecoder(e),r=a.readVarUint(n);switch(r){case p:for(;a.hasContent(n);)s(a.readVarUint8Array(n));break;case u:case d:{r===u&&(a.readVarUint(n),a.readVarUint(n));const e=a.readVarUint(n);e!==o.messageYjsSyncStep2&&e!==o.messageYjsUpdate||t.push(a.readVarUint8Array(n));break}case g:t.push(a.readVarUint8Array(n))}};try{e.length>4&&s(e.subarray(4))}catch{return[]}return t}function A(e){const t=c.createEncoder();return c.writeVarUint(t,d),c.writeVarUint(t,o.messageYjsSyncStep2),c.writeVarUint8Array(t,e),y(c.toUint8Array(t))}class T extends h.Observable{constructor(e){super(),this.provider=e}publish(e,t){this.provider._sendPubSub(e,t)}subscribe(e,t){const s=(s,n)=>{"*"!==e&&e!==n||t(s,n)};return this.on("message",s),()=>this.off("message",s)}_handleMessage(e,t){this.emit("message",[t,e])}}class C extends h.Observable{constructor(e,t,s={}){if(super(),this._status={state:"disconnected"},this._synced=!1,this._destroying=!1,this._lastActivityTime=Date.now(),this._lastPeriodicTickTime=Date.now(),this._equalBeaconsHeard=0,this._beaconForced=!1,this._bcChannel="",this._bcConnected=!1,this._resyncAttemptCount=0,this._lastResyncAttemptTime=0,this._syncRequestTimes=[],this._syncReplyTimes=[],this._pendingSyncReply=null,this._pendingSyncReplyIsAck=!1,this._pendingSyncReplyTargetSv=null,this._responseWaitAttempts=0,this._responseSeen=!1,this._equalUnsettledSeen=!1,this._responseWaitFlags=0,this._behindSv=null,this._rttSamples=[],this._requestSentAt=0,this._confirmed=!1,this._knownPeers=new Map,this._peerAddress=new Map,this._presencePending=new Set,this._presenceCovered=!1,this._pendingAwarenessRemoval=null,this._pendingPeerConnectIds=new Set,this._confirmedSv=null,this._confirmedDsHash=null,this._loading=!1,this._dsHashCache=null,this._localSeqNum=0,this._remoteSeqInfo=new Map,this._gapCheckTimers=new Map,this._batchUpdates=0,this._pendingUpdate=null,this._flushScheduled=!1,this._awarenessInterval=100,this._pendingAwarenessClients=new Set,this._lastAwarenessTime=0,this.doc=e,this.transport=t,this.pubsub=new T(this),this.awareness=s.awareness||new i.Awareness(e),this._syncInterval=s.syncInterval??5e3,this._verifyUpdates=s.verifyUpdates??!0,this._batchUpdates=s.batchUpdates??t.preferredBatchMs??0,this._disableBc=s.disableBc??!1,this._awarenessInterval=s.awarenessInterval??t.preferredAwarenessMs??100,this._maxSyncRequestsPerWindow=s.maxSyncRequestsPerWindow??20,this._syncRequestWindowMs=s.syncRequestWindowMs??1e4,this._syncReplySuppressionMs=s.syncReplySuppressionMs??30,this._peerConnectDebounceMs=s.peerConnectDebounceMs??50,this._gapGraceMs=s.gapGraceMs??300,this._seqWindowSize=s.seqWindowSize??64,this._compressionThresholdBytes=(s.compressionThresholdBytes??t.preferredCompressMinBytes)||void 0,this._idleBackoffEnabled=s.idleBackoffEnabled??!0,this._idleBackoffMaxMs=s.idleBackoffMaxMs??6e4,this._trickleK=s.trickleK??1,this._ownsAwareness=!s.awareness,this._awarenessTimeoutMs=s.awarenessTimeoutMs??("function"==typeof t.onPeerDisconnect?3e5:3e4),this._ownsAwareness){const e=this.awareness;void 0!==e._checkInterval&&clearInterval(e._checkInterval)}this._currentSyncIntervalMs=this._syncInterval,this._setupDocumentSync(),this._setupAwarenessSync()}async connect(e){if(this._destroying)throw new Error("Provider is being destroyed");if("connected"!==this._status.state)if("connecting"!==this._status.state){this._setStatus({state:"connecting"});try{if(this._setupBroadcastChannel(e),this._unsubscribeTransport=this.transport.onMessage(((e,t)=>{this._handleIncomingMessage(e,t)})),this.transport.onPeerConnect){const e=this.transport.onPeerConnect((e=>{this._destroying||this._schedulePeerConnectSync(e)})),t=this._unsubscribeTransport;this._unsubscribeTransport=()=>{t?.(),e()}}if(this.transport.onPeerDisconnect){const e=this.transport.onPeerDisconnect((e=>{this._destroying||this._handlePeerLeave(e)})),t=this._unsubscribeTransport;this._unsubscribeTransport=()=>{t?.(),e()}}if(await this.transport.connect(e),this._setStatus({state:"connected"}),this._startAwarenessSweep(),this.transport.expectedRttMs&&(this._rttSamples=[this.transport.expectedRttMs]),e.waitFor){this._loading=!0;try{await e.waitFor}catch{}if(this._loading=!1,this._destroying||!this.transport.isConnected)return;this._confirmedSv=r.encodeStateVector(this.doc),this._confirmedDsHash=this._deleteSetHash()}if(this.syncNow(),this._syncInterval>0){this._currentSyncIntervalMs=this._syncInterval,this._lastActivityTime=Date.now(),this._lastPeriodicTickTime=Date.now(),this._equalBeaconsHeard=0,this._beaconForced=!1;const e=t=>{this._syncIntervalId=setTimeout((()=>{const t=Date.now();if(this._idleBackoffEnabled){const e=this._lastActivityTime>this._lastPeriodicTickTime;this._currentSyncIntervalMs=e?this._syncInterval:Math.min(this._idleBackoffMaxMs,2*this._currentSyncIntervalMs)}this._lastPeriodicTickTime=t,this.transport.isConnected&&!this._destroying&&(this._trickleK>0&&!this._beaconForced&&this._equalBeaconsHeard>=this._trickleK||this._sendSyncStep1(),this._equalBeaconsHeard=0,this._beaconForced=!1),this._destroying||e()}),t??this._jitteredSyncInterval())};this._periodicScheduler=e,e()}}catch(e){throw this._setStatus({state:"error",error:e instanceof Error?e:new Error(String(e))}),e}}else console.warn("[GenericProvider] Connection already in progress, ignoring connect() call");else console.warn("[GenericProvider] Already connected, ignoring connect() call")}disconnect(){void 0!==this._syncIntervalId&&(clearTimeout(this._syncIntervalId),this._syncIntervalId=void 0),this._periodicScheduler=void 0,void 0!==this._awarenessSweepId&&(clearTimeout(this._awarenessSweepId),this._awarenessSweepId=void 0),this._resyncAttemptCount=0,this._lastResyncAttemptTime=0,void 0!==this._pendingResyncTimeoutId&&(clearTimeout(this._pendingResyncTimeoutId),this._pendingResyncTimeoutId=void 0);for(const e of this._gapCheckTimers.values())clearTimeout(e);if(this._gapCheckTimers.clear(),this._remoteSeqInfo.clear(),void 0!==this._pendingPeerConnectSyncTimeoutId&&(clearTimeout(this._pendingPeerConnectSyncTimeoutId),this._pendingPeerConnectSyncTimeoutId=void 0),this._pendingPeerConnectIds.clear(),this._syncRequestTimes=[],this._syncReplyTimes=[],this._knownPeers.clear(),this._peerAddress.clear(),this._presencePending.clear(),void 0!==this._responseWaitTimer&&(clearTimeout(this._responseWaitTimer),this._responseWaitTimer=void 0),void 0!==this._pendingCheckTimer&&(clearTimeout(this._pendingCheckTimer),this._pendingCheckTimer=void 0),void 0!==this._behindCheckTimer&&(clearTimeout(this._behindCheckTimer),this._behindCheckTimer=void 0),this._behindSv=null,void 0!==this._presenceResponseTimer&&(clearTimeout(this._presenceResponseTimer),this._presenceResponseTimer=void 0),this._responseWaitAttempts=0,this._responseSeen=!1,this._equalUnsettledSeen=!1,this._rttSamples=[],this._requestSentAt=0,this._confirmed=!1,this._cancelPendingSyncReply(),this._cancelPendingAwarenessRemoval(),this._flushPendingUpdate(),void 0!==this._awarenessTimeoutId&&(clearTimeout(this._awarenessTimeoutId),this._awarenessTimeoutId=void 0,this._pendingAwarenessClients.size>0&&this.transport.isConnected)){const e=Array.from(this._pendingAwarenessClients);this._sendAwarenessNow(e)}this._pendingAwarenessClients.clear(),this._disconnectBroadcastChannel(),this._unsubscribeTransport&&(this._unsubscribeTransport(),this._unsubscribeTransport=void 0),i.removeAwarenessStates(this.awareness,[this.doc.clientID],"disconnect"),this.transport.disconnect(),this._synced=!1,this._setStatus({state:"disconnected"})}destroy(){this._destroying=!0,void 0!==this._syncIntervalId&&(clearTimeout(this._syncIntervalId),this._syncIntervalId=void 0);for(const e of this._gapCheckTimers.values())clearTimeout(e);this._gapCheckTimers.clear(),this._cancelPendingSyncReply(),this._cancelPendingAwarenessRemoval(),this._flushPendingUpdate(),this.disconnect(),this._updateHandler&&(this.doc.off("update",this._updateHandler),this._updateHandler=void 0),this._awarenessUpdateHandler&&(this.awareness.off(this._ownsAwareness?"change":"update",this._awarenessUpdateHandler),this._awarenessUpdateHandler=void 0),void 0!==this._awarenessSweepId&&(clearTimeout(this._awarenessSweepId),this._awarenessSweepId=void 0),this._beforeUnloadHandler&&"undefined"!=typeof window&&(window.removeEventListener("beforeunload",this._beforeUnloadHandler),this._beforeUnloadHandler=void 0),this.awareness.destroy(),super.destroy()}get status(){return this._status}get connected(){return this.transport.isConnected}get bcConnected(){return this._bcConnected}get synced(){return this._synced}_trySyncPushPull(e=!0,t,s=0){if(!this._tryReserveSyncSlot())return!1;const n=[];if(e){const e=r.encodeStateAsUpdate(this.doc,this._confirmedSv??void 0);let t=e.length>0;if(t&&null!==this._confirmedSv)try{t=r.parseUpdateMeta(e).to.size>0||this._deleteSetHash()!==this._confirmedDsHash}catch{t=!0}t&&n.push(this._encodePush(e))}return n.push(this._encodeSyncStep1(s)),t&&n.push(...t()),this._sendBatch(n),1&s&&this._armResponseWait(4),!0}syncNow(){this._syncNow(1)}_syncNow(e){if(!this.transport.isConnected)return void console.warn("Cannot sync: transport not connected");1&e&&(this._confirmed=!1);let t=!1;this._trySyncPushPull(!0,(()=>{const e=this._tryImmediateAwarenessMessage([this.doc.clientID]);return e?(t=!0,[e]):[]}),e)&&t||this._broadcastAwareness([this.doc.clientID])}_jitteredSyncInterval(){const e=1+.2*(2*Math.random()-1);return this._currentSyncIntervalMs*e}_markActivity(){this._lastActivityTime=Date.now(),this._idleBackoffEnabled&&this._currentSyncIntervalMs!==this._syncInterval&&void 0!==this._syncIntervalId&&void 0!==this._periodicScheduler&&(clearTimeout(this._syncIntervalId),this._currentSyncIntervalMs=this._syncInterval,this._beaconForced=!0,this._periodicScheduler(Math.random()*this._syncInterval))}_startAwarenessSweep(){if(void 0!==this._awarenessSweepId)return;const e=this._awarenessTimeoutMs,t=()=>{this._awarenessSweepId=setTimeout(s,e/10*(.8+.4*Math.random()))},s=()=>{const s=Date.now();if(this._ownsAwareness){const t=this.awareness.meta.get(this.doc.clientID);null!==this.awareness.getLocalState()&&void 0!==t&&e/2<=s-t.lastUpdated&&(this.awareness.setLocalState(this.awareness.getLocalState()),this._broadcastAwareness([this.doc.clientID]));const n=[];this.awareness.meta.forEach(((t,r)=>{r!==this.doc.clientID&&e<=s-t.lastUpdated&&this.awareness.getStates().has(r)&&n.push(r)})),n.length>0&&i.removeAwarenessStates(this.awareness,n,"timeout")}for(const[t,n]of this._knownPeers)e<=s-n&&(this._knownPeers.delete(t),this._peerAddress.delete(t),this._remoteSeqInfo.delete(t));this._destroying||"connected"!==this._status.state?this._awarenessSweepId=void 0:t()};t()}_touchPeer(e){const t=this.awareness.meta.get(e);void 0!==t&&this.awareness.getStates().has(e)&&(t.lastUpdated=Date.now())}_handlePeerLeave(e){const t=[];for(const[s,n]of this._peerAddress)n===e&&t.push(s);for(const e of t)this._peerAddress.delete(e),this._knownPeers.delete(e);const s=t.filter((e=>this.awareness.getStates().has(e)));s.length>0&&i.removeAwarenessStates(this.awareness,s,"peer-left")}_deleteSetHash(){return null===this._dsHashCache&&(this._dsHashCache=function(e){const t=r.createDeleteSetFromStructStore(e.store),s=c.createEncoder(),n=Array.from(t.clients.keys()).sort(((e,t)=>e-t));for(const e of n){c.writeVarUint(s,e);for(const n of t.clients.get(e))c.writeVarUint(s,n.clock),c.writeVarUint(s,n.len)}return w(c.toUint8Array(s))}(this.doc)),this._dsHashCache}_schedulePeerConnectSync(e){void 0!==e&&this._pendingPeerConnectIds.add(e),void 0===this._pendingPeerConnectSyncTimeoutId&&(this._pendingPeerConnectSyncTimeoutId=setTimeout((()=>{this._pendingPeerConnectSyncTimeoutId=void 0;const e=Array.from(this._pendingPeerConnectIds);if(this._pendingPeerConnectIds.clear(),this.transport.isConnected&&!this._destroying)if("function"==typeof this.transport.sendTo&&e.length>0){const t=y(this._encodeSyncStep1(0));for(const s of e)this._sendToTransport(t,s)}else this._syncNow(0)}),this._peerConnectDebounceMs))}_setupDocumentSync(){this._updateHandler=(e,t)=>{this._dsHashCache=null,this._equalBeaconsHeard=0,t===this||this._loading||(this._markActivity(),this._batchUpdate(e))},this.doc.on("update",this._updateHandler)}_batchUpdate(e){if(this._pendingUpdate)try{this._pendingUpdate=r.mergeUpdates([this._pendingUpdate,e])}catch(t){console.error("[GenericProvider] Failed to merge updates:",t),this._sendUpdate(this._pendingUpdate),this._pendingUpdate=e}else this._pendingUpdate=e;if(this._batchUpdates>0)return void 0!==this._batchTimeoutId&&clearTimeout(this._batchTimeoutId),this._batchTimeoutId=setTimeout((()=>{this._batchTimeoutId=void 0,this._flushPendingUpdate()}),this._batchUpdates),void(this._flushScheduled=!0);this._flushScheduled||(this._flushScheduled=!0,queueMicrotask((()=>this._flushPendingUpdate())))}_flushPendingUpdate(){this._flushScheduled=!1,void 0!==this._batchTimeoutId&&(clearTimeout(this._batchTimeoutId),this._batchTimeoutId=void 0);const e=this._pendingUpdate;this._pendingUpdate=null,e&&this.transport.isConnected&&this._sendUpdate(e)}_setupAwarenessSync(){this._awarenessUpdateHandler=({added:e,updated:t,removed:s},n)=>{if(n===this&&(s.length>0&&this._cancelPendingAwarenessRemovalIfOverlaps(s),!s.includes(this.awareness.clientID)))return;const r=e.concat(t).concat(s);"timeout"!==n&&"peer-left"!==n?this._broadcastAwareness(r):this._scheduleAwarenessRemoval(r,n)},this.awareness.on(this._ownsAwareness?"change":"update",this._awarenessUpdateHandler),"undefined"!=typeof window&&(this._beforeUnloadHandler=()=>{i.removeAwarenessStates(this.awareness,[this.doc.clientID],"window unload"),this._disconnectBroadcastChannel()},window.addEventListener("beforeunload",this._beforeUnloadHandler))}_handleIncomingMessage(e,t){if(!this._compressionThresholdBytes)return void this._processWrappedMessage(e,t);if(e.length<1)return void console.warn("[GenericProvider] Dropping empty message (missing compression flag byte)");const s=e[0],n=e.subarray(1);0!==s?m?async function(e){const t=new DecompressionStream("deflate-raw"),s=t.writable.getWriter();return s.write(e).catch((()=>{})),s.close().catch((()=>{})),b(t.readable)}(n).then((e=>this._processWrappedMessage(e,t))).catch((e=>{console.warn("[GenericProvider] Failed to decompress incoming message, treating as corrupted:",e),this._requestResync()})):console.warn("[GenericProvider] Received a compressed message but this runtime has no DecompressionStream - dropping it."):this._processWrappedMessage(n,t)}_processWrappedMessage(e,t){const s=function(e){if(e.length<4)return null;const t=(e[0]<<24|e[1]<<16|e[2]<<8|e[3])>>>0,s=e.subarray(4);return w(s)!==t?null:s}(e);if(null===s)return console.warn("[GenericProvider] 💥 Corrupted message rejected: CRC32 checksum mismatch. This is expected if data corruption simulation is enabled."),this._markActivity(),void this._requestResync();try{this._dispatchMessage(s,t)}catch(e){console.error("[GenericProvider] Error handling message:",e)}}_dispatchMessage(e,t){const s=a.createDecoder(e),n=a.readVarUint(s);switch(n){case p:for(;a.hasContent(s);){const e=a.readVarUint8Array(s);this._dispatchMessage(e,t)}break;case 5:this._handleDigest(s,t);break;case g:r.applyUpdate(this.doc,a.readVarUint8Array(s),this),this._checkPendingAfterReply();break;case d:{const e=c.createEncoder();c.writeVarUint(e,d),o.readSyncMessage(s,e,this.doc,this)===o.messageYjsSyncStep2&&(this._confirmed=!0,this._noteResponse(!0),this._markSynced(),this._checkPendingAfterReply(),this._cancelPendingSyncReply()),c.length(e)>1&&this._replyToSyncRequest(c.toUint8Array(e));break}case 1:{const e=a.readVarUint8Array(s),t=this._scanAwarenessPayload(e);t.removed.length>0&&this._cancelPendingAwarenessRemovalIfOverlaps(t.removed),t.coversUs&&(this._presenceCovered=!0);const n=Date.now();for(const e of t.present)e!==this.doc.clientID&&this._knownPeers.set(e,n);i.applyAwarenessUpdate(this.awareness,e,this);break}case 2:{const t=a.readVarString(s),n=a.readVarUint8Array(s);try{const e=(new TextDecoder).decode(n),s=JSON.parse(e);this.pubsub._handleMessage(t,s)}catch(e){console.error("Error decoding pub/sub message:",e)}break}case u:{const e=a.readVarUint(s),n=a.readVarUint(s);this._trackRemoteSeq(n,e),this._knownPeers.set(n,Date.now()),void 0!==t&&this._peerAddress.set(n,t),this._touchPeer(n);const r=this._peekSyncUpdate(s),i=c.createEncoder();c.writeVarUint(i,d);const h=o.readSyncMessage(s,i,this.doc,this);h===o.messageYjsSyncStep2&&(this._cancelPendingSyncReply(),this._confirmed=!0,this._checkPendingAfterReply(),this._noteResponse(!0));const l=a.readVarInt(s),u=k(this.doc);if(u!==l){const e=this._gapCheckTimers.has(n),t=this._isLateUpdate(r);null!==this.doc.store.pendingStructs||null!==this.doc.store.pendingDs?this._schedulePendingCheck():e||t||(this._requestResync(),console.warn(`[GenericProvider] Hash mismatch #${this._resyncAttemptCount} detected! Local: ${u}, Expected: ${l}`))}h===o.messageYjsSyncStep2&&u===l&&this._markSynced(),c.length(i)>1&&this._replyToSyncRequest(c.toUint8Array(i));break}default:console.warn("Unknown message type:",n)}}_handleDigest(e,t){a.readVarUint(e);const s=a.readVarUint(e),n=a.readVarUint(e);this._knownPeers.set(n,Date.now()),void 0!==t&&this._peerAddress.set(n,t),this._touchPeer(n);const i=a.readVarUint8Array(e),h=a.readVarUint(e),l=r.decodeStateVector(i),u=r.decodeStateVector(r.encodeStateVector(this.doc));let p=!1;for(const[e,t]of u)if((l.get(e)??0)<t){p=!0;break}let g=!1;for(const[e,t]of l)if((u.get(e)??0)<t){g=!0;break}const f=h===this._deleteSetHash(),w=!p&&!g&&f;if(w&&(this._confirmedSv=i,this._confirmedDsHash=h),2&s)w&&(8&s?(this._confirmed=!0,this._noteResponse(!0)):this._equalUnsettledSeen=!0,this._markSynced(),this._cancelPendingAck());else{if(!w||5&s||(this._equalBeaconsHeard++,8&s?(this._confirmed=!0,this._noteResponse(!1)):this._equalUnsettledSeen=!0,this._cancelPendingAck()),p||!f){const e=c.createEncoder();c.writeVarUint(e,d),o.writeSyncStep2(e,this.doc,i);let t=c.toUint8Array(e);f||(t=this._encodeBatch([t,this._encodeSyncStep1(0)])),this._replyToSyncRequest(t,!1,i,n)}else 5&s&&this._replyToSyncRequest(this._encodeAck(i,h),!0,null,n);!g&&f&&this._markSynced(),g&&this._scheduleBehindCheck(i),1&s&&null!==this.awareness.getLocalState()&&this._schedulePresenceResponse(n)}}_schedulePresenceResponse(e){if(this._presencePending.add(e),void 0!==this._presenceResponseTimer)return;this._presenceCovered=!1;const t=this._rttMinMs(),s=!this._canUnicast(e)&&this._knownPeers.size>=3&&0===this._responderRank(0,1),n=s?0:Math.min(500,Math.max(100,null===t?0:2*t));this._presenceResponseTimer=setTimeout((()=>{this._presenceResponseTimer=void 0;const e=Array.from(this._presencePending);if(this._presencePending.clear(),!this._destroying&&this.transport.isConnected&&null!==this.awareness.getLocalState())if(e.every((e=>this._canUnicast(e)))){const t=this._encodeAwareness([this.doc.clientID]);for(const s of e)this._sendDirect(s,t)}else s?this._sendAwarenessNow(Array.from(this.awareness.getStates().keys())):this._presenceCovered||this._broadcastAwareness([this.doc.clientID])}),n)}_peerCount(){return Math.max(this.awareness.getStates().size,this._knownPeers.size+1)}_effectiveAwarenessInterval(){if("auto"!==this._awarenessInterval)return this._awarenessInterval;const e=this.transport.preferredAwarenessMs??100;return Math.max(e,C.AWARENESS_AUTO_MS_PER_PEER*this._peerCount())}_replySuppressionMaxDelay(){const e=this._peerCount(),t=Math.min(200,this._syncReplySuppressionMs*Math.log2(Math.max(2,e))),s=this._rttMinMs();return null===s?t:Math.min(2e3,Math.max(t,1.5*s))}_scheduleSyncReply(e,t=!1,s=null,n=null){if(void 0!==this._pendingSyncReplyTimeoutId&&null!==this._pendingSyncReply){if(_(this._pendingSyncReply,e))return;if(null!==s&&null!==this._pendingSyncReplyTargetSv&&_(this._pendingSyncReplyTargetSv,s))return void(this._pendingSyncReply=e);if(!t&&!this._pendingSyncReplyIsAck&&null!==s&&null!==this._pendingSyncReplyTargetSv){const e=function(e,t){const s=r.decodeStateVector(e),n=r.decodeStateVector(t),i=new Map;for(const[e,t]of s){const s=Math.min(t,n.get(e)??0);s>0&&i.set(e,s)}return r.encodeStateVector(i)}(this._pendingSyncReplyTargetSv,s),t=c.createEncoder();return c.writeVarUint(t,d),o.writeSyncStep2(t,this.doc,e),this._pendingSyncReply=c.toUint8Array(t),void(this._pendingSyncReplyTargetSv=e)}if(t)return;this._pendingSyncReplyIsAck&&(clearTimeout(this._pendingSyncReplyTimeoutId),this._pendingSyncReplyTimeoutId=void 0)}void 0!==this._pendingSyncReplyTimeoutId&&(this._pendingSyncReply&&this._sendSyncReply(this._pendingSyncReply),clearTimeout(this._pendingSyncReplyTimeoutId),this._pendingSyncReplyTimeoutId=void 0),this._pendingSyncReply=e,this._pendingSyncReplyIsAck=t,this._pendingSyncReplyTargetSv=s;const i=t?Math.random()*this._replySuppressionMaxDelay():this._replyDelay(n);this._pendingSyncReplyTimeoutId=setTimeout((()=>{this._pendingSyncReplyTimeoutId=void 0,this._pendingSyncReply&&(this._sendSyncReply(this._pendingSyncReply),this._pendingSyncReply=null,this._pendingSyncReplyTargetSv=null)}),i)}_cancelPendingSyncReply(){void 0!==this._pendingSyncReplyTimeoutId&&(clearTimeout(this._pendingSyncReplyTimeoutId),this._pendingSyncReplyTimeoutId=void 0),this._pendingSyncReply=null,this._pendingSyncReplyIsAck=!1,this._pendingSyncReplyTargetSv=null}_cancelPendingAck(){this._pendingSyncReplyIsAck&&this._cancelPendingSyncReply()}_replyToSyncRequest(e,t=!1,s=null,n){if(null===this.doc.store.pendingStructs&&null===this.doc.store.pendingDs)if(void 0!==n&&this._canUnicast(n)){if(!this._selectedResponder(n))return;if(!this._tryReserveReplySlot())return;this._sendDirect(n,e)}else t||this._peerCount()>=3?this._scheduleSyncReply(e,t,s,n??null):this._sendSyncReply(e)}_canUnicast(e){return"function"==typeof this.transport.sendTo&&this._peerAddress.has(e)}_selectedResponder(e){return this._peerCount()<4||this._responderRank(e,3)<3}_responderRank(e,t){const s=Math.floor(Date.now()/2e3),n=t=>(Math.imul(e^s,2654435761)^Math.imul(t,2246822507))>>>0,r=n(this.doc.clientID);let i=0;for(const s of this._knownPeers.keys())if(s!==e&&s!==this.doc.clientID&&n(s)<r&&++i>=t)break;return i}_replyDelay(e){const t=this._replySuppressionMaxDelay(),s=this._rttMinMs();if(null===e||null===s)return Math.random()*t;const n=Math.max(this._syncReplySuppressionMs,.75*s),r=this._responderRank(e,8);return r*n+(r>=8?Math.random()*t:0)}_sendDirect(e,t){const s=this._peerAddress.get(e);return void 0!==s&&"function"==typeof this.transport.sendTo&&!!this.transport.isConnected&&(this._sendToTransport(y(t),s),!0)}_scheduleBehindCheck(e){if(this._behindSv=e,void 0!==this._behindCheckTimer)return;const t=this._rttMinMs(),s=Math.max(this._gapGraceMs,null===t?0:2*t);this._behindCheckTimer=setTimeout((()=>{this._behindCheckTimer=void 0;const e=this._behindSv;if(this._behindSv=null,null===e||this._destroying||!this.transport.isConnected)return;if(this._requestSentAt>0&&Date.now()-this._requestSentAt<s)return;const t=r.decodeStateVector(e),n=r.decodeStateVector(r.encodeStateVector(this.doc));for(const[e,s]of t)if((n.get(e)??0)<s)return void this._requestResync()}),s)}_checkPendingAfterReply(){null===this.doc.store.pendingStructs&&null===this.doc.store.pendingDs||this._schedulePendingCheck()}_schedulePendingCheck(){void 0===this._pendingCheckTimer&&(this._pendingCheckTimer=setTimeout((()=>{if(this._pendingCheckTimer=void 0,this._destroying||!this.transport.isConnected)return;const e=this._rttMinMs(),t=Math.max(this._gapGraceMs,null===e?0:2*e);this._requestSentAt>0&&Date.now()-this._requestSentAt<t?this._schedulePendingCheck():null===this.doc.store.pendingStructs&&null===this.doc.store.pendingDs||this._requestResync()}),this._gapGraceMs))}_peekSyncUpdate(e){const t=a.clone(e);try{return a.readVarUint(t)===o.messageYjsSyncStep1?null:a.readVarUint8Array(t)}catch{return null}}_isLateUpdate(e){if(!e)return!1;try{const{to:t}=r.parseUpdateMeta(e);if(0===t.size)return!1;const s=r.decodeStateVector(r.encodeStateVector(this.doc));for(const[e,n]of t)if((s.get(e)??0)<=n)return!1;return!0}catch{return!1}}_markSynced(){this._synced||(this._synced=!0,this.emit("synced",[!0]))}_armResponseWait(e){if(void 0!==this._responseWaitTimer)return;this._responseSeen=!1,0===this._responseWaitAttempts&&(this._equalUnsettledSeen=!1),this._responseWaitFlags=e,this._requestSentAt=Date.now();const t=this._rttMinMs(),s=Math.max(1e3,null===t?0:4*t)*Math.pow(2,this._responseWaitAttempts);this._responseWaitTimer=setTimeout((()=>{this._responseWaitTimer=void 0;const e=this._equalUnsettledSeen&&this._responseWaitAttempts>=1;if(this._responseSeen||this._responseWaitAttempts>=3||e||!this.transport.isConnected||this._destroying)return(this._responseWaitAttempts>=3||e)&&(this._confirmed=!0),void(this._responseWaitAttempts=0);this._responseWaitAttempts++,this._sendSyncStep1(this._responseWaitFlags),this._armResponseWait(this._responseWaitFlags)}),s)}_noteResponse(e){e&&this._requestSentAt>0&&(this._rttSamples.push(Date.now()-this._requestSentAt),this._rttSamples.length>8&&this._rttSamples.shift()),this._requestSentAt=0,this._responseSeen=!0,this._responseWaitAttempts=0,void 0!==this._responseWaitTimer&&(clearTimeout(this._responseWaitTimer),this._responseWaitTimer=void 0)}_rttMinMs(){return 0===this._rttSamples.length?null:Math.min(...this._rttSamples)}_scheduleAwarenessRemoval(e,t="timeout"){if(void 0!==this._pendingAwarenessRemovalTimeoutId){const t=this._pendingAwarenessRemoval??[];for(const s of e)t.includes(s)||t.push(s);return void(this._pendingAwarenessRemoval=t)}this._pendingAwarenessRemoval=e.slice();const s=this._replySuppressionMaxDelay(),n=Math.random()*("peer-left"===t?Math.max(1e3,10*s):s);this._pendingAwarenessRemovalTimeoutId=setTimeout((()=>{this._pendingAwarenessRemovalTimeoutId=void 0,this._pendingAwarenessRemoval&&(this._broadcastAwareness(this._pendingAwarenessRemoval),this._pendingAwarenessRemoval=null)}),n)}_scanAwarenessPayload(e){const t=[],s=[];let n=!1;try{const r=a.createDecoder(e),i=a.readVarUint(r),o=this.awareness.meta.get(this.awareness.clientID)?.clock??0;for(let e=0;e<i;e++){const e=a.readVarUint(r),i=a.readVarUint(r);null===JSON.parse(a.readVarString(r))?t.push(e):(s.push(e),e===this.awareness.clientID&&i>=o&&(n=!0))}}catch{}return{removed:t,present:s,coversUs:n}}_cancelPendingAwarenessRemovalIfOverlaps(e){if(!this._pendingAwarenessRemoval)return;const t=this._pendingAwarenessRemoval.filter((t=>!e.includes(t)));t.length!==this._pendingAwarenessRemoval.length&&(t.length>0?this._pendingAwarenessRemoval=t:(void 0!==this._pendingAwarenessRemovalTimeoutId&&(clearTimeout(this._pendingAwarenessRemovalTimeoutId),this._pendingAwarenessRemovalTimeoutId=void 0),this._pendingAwarenessRemoval=null))}_cancelPendingAwarenessRemoval(){void 0!==this._pendingAwarenessRemovalTimeoutId&&(clearTimeout(this._pendingAwarenessRemovalTimeoutId),this._pendingAwarenessRemovalTimeoutId=void 0),this._pendingAwarenessRemoval=null}_sendSyncReply(e){this._tryReserveReplySlot()&&this._send(e)}_trackRemoteSeq(e,t){let s=this._remoteSeqInfo.get(e);if(s||(s={highest:-1,seen:new Set},this._remoteSeqInfo.set(e,s)),s.seen.has(t))return;s.seen.add(t),t>s.highest&&(s.highest>=0&&t>s.highest+1&&this._scheduleGapCheck(e,s.highest+1,t-1),s.highest=t);const n=s.highest-this._seqWindowSize;if(n>0)for(const e of s.seen)e<n&&s.seen.delete(e)}_scheduleGapCheck(e,t,s){if(this._gapCheckTimers.has(e))return;const n=setTimeout((()=>{this._gapCheckTimers.delete(e);const n=this._remoteSeqInfo.get(e);if(!n||this._destroying)return;let r=0;for(let e=t;e<=s;e++)n.seen.has(e)||r++;r>0&&this.transport.isConnected&&(console.warn(`[GenericProvider] Sequence gap confirmed from client ${e}: ${r} message(s) still missing after ${this._gapGraceMs}ms grace period`),this._requestResync())}),this._gapGraceMs);this._gapCheckTimers.set(e,n)}_requestResync(){if(void 0!==this._pendingResyncTimeoutId)return;this._resyncAttemptCount++;const e=Date.now();e-this._lastResyncAttemptTime>1e4&&(this._resyncAttemptCount=1),this._lastResyncAttemptTime=e;const t=Math.min(5e3,100*Math.pow(5,Math.min(this._resyncAttemptCount-1,3)));console.warn(`[GenericProvider] Resync scheduled in ${t}ms (attempt #${this._resyncAttemptCount})...`),this._pendingResyncTimeoutId=setTimeout((()=>{this._pendingResyncTimeoutId=void 0,this.transport.isConnected&&!this._destroying&&(this._sendSyncStep1(0)?this._armResponseWait(0):this._requestResync())}),t)}_tryReserveSyncSlot(){return this._tryReserveSlot(this._syncRequestTimes)}_tryReserveReplySlot(){return this._tryReserveSlot(this._syncReplyTimes)}_tryReserveSlot(e){const t=Date.now();let s=0;for(const n of e)t-n<this._syncRequestWindowMs&&(e[s++]=n);return e.length=s,!(e.length>=this._maxSyncRequestsPerWindow||(e.push(t),0))}_encodeSyncStep1(e=0){this._confirmed&&(e|=8),this._touchPeer(this.doc.clientID);const t=c.createEncoder();return c.writeVarUint(t,5),c.writeVarUint(t,1),c.writeVarUint(t,e),c.writeVarUint(t,this.doc.clientID),c.writeVarUint8Array(t,r.encodeStateVector(this.doc)),c.writeVarUint(t,this._deleteSetHash()),c.toUint8Array(t)}_encodeAck(e,t){this._touchPeer(this.doc.clientID);const s=c.createEncoder();return c.writeVarUint(s,5),c.writeVarUint(s,1),c.writeVarUint(s,2|(this._confirmed?8:0)),c.writeVarUint(s,this.doc.clientID),c.writeVarUint8Array(s,e),c.writeVarUint(s,t),c.toUint8Array(s)}_sendSyncStep1(e=0){return this._tryReserveSyncSlot()?(this._send(this._encodeSyncStep1(e)),!0):(console.warn(`[GenericProvider] Sync rate limit exceeded (${this._maxSyncRequestsPerWindow} requests per ${this._syncRequestWindowMs/1e3}s), throttling...`),!1)}_encodeUpdate(e){const t=c.createEncoder();if(this._verifyUpdates){this._touchPeer(this.doc.clientID),c.writeVarUint(t,u),c.writeVarUint(t,this._localSeqNum++),c.writeVarUint(t,this.doc.clientID),o.writeUpdate(t,e);const s=k(this.doc);c.writeVarInt(t,s)}else c.writeVarUint(t,d),o.writeUpdate(t,e);return c.toUint8Array(t)}_encodePush(e){const t=c.createEncoder();return c.writeVarUint(t,g),c.writeVarUint8Array(t,e),c.toUint8Array(t)}_sendUpdate(e){this._sendBatch([this._encodeUpdate(e),...this._takePendingAwareness()])}_sendAwarenessUpdate(e){const t=c.createEncoder();c.writeVarUint(t,1),c.writeVarUint8Array(t,i.encodeAwarenessUpdate(this.awareness,e)),this._send(c.toUint8Array(t))}_sendPubSub(e,t){if(this.transport.isConnected)try{const s=c.createEncoder();c.writeVarUint(s,2),c.writeVarString(s,e);const n=JSON.stringify(t),r=(new TextEncoder).encode(n);c.writeVarUint8Array(s,r),this._send(c.toUint8Array(s))}catch(e){console.error("Error sending pub/sub message:",e)}else console.warn("Cannot send pub/sub message: not connected")}_broadcastAwareness(e){if(0===e.length)return;const t=this._effectiveAwarenessInterval();if(t<=0)return void this._sendAwarenessNow(e);for(const t of e)this._pendingAwarenessClients.add(t);if(void 0!==this._awarenessTimeoutId)return;const s=Date.now()-this._lastAwarenessTime,n=Math.max(0,t-s);this._awarenessTimeoutId=setTimeout((()=>{this._awarenessTimeoutId=void 0,this._lastAwarenessTime=Date.now();const e=Array.from(this._pendingAwarenessClients);this._pendingAwarenessClients.clear(),e.length>0&&this._sendBatch([...this._takePendingUpdate(),this._encodeAwareness(e)])}),n)}_takePendingAwareness(){if(void 0===this._awarenessTimeoutId)return[];clearTimeout(this._awarenessTimeoutId),this._awarenessTimeoutId=void 0;const e=Array.from(this._pendingAwarenessClients);return this._pendingAwarenessClients.clear(),0===e.length?[]:(this._lastAwarenessTime=Date.now(),[this._encodeAwareness(e)])}_takePendingUpdate(){if(void 0===this._batchTimeoutId||!this._pendingUpdate)return[];clearTimeout(this._batchTimeoutId),this._batchTimeoutId=void 0,this._flushScheduled=!1;const e=this._pendingUpdate;return this._pendingUpdate=null,[this._encodeUpdate(e)]}_encodeAwareness(e){const t=c.createEncoder();return c.writeVarUint(t,1),c.writeVarUint8Array(t,i.encodeAwarenessUpdate(this.awareness,e)),c.toUint8Array(t)}_sendAwarenessNow(e){this._send(this._encodeAwareness(e))}_tryImmediateAwarenessMessage(e){if(0===e.length)return null;if(void 0!==this._awarenessTimeoutId)return null;const t=this._effectiveAwarenessInterval();if(t>0&&Date.now()-this._lastAwarenessTime<t)return null;for(const t of e)this._pendingAwarenessClients.add(t);const s=Array.from(this._pendingAwarenessClients);return this._pendingAwarenessClients.clear(),0===s.length?null:(this._lastAwarenessTime=Date.now(),this._encodeAwareness(s))}_setupBroadcastChannel(e){if(this._disableBc||"undefined"==typeof BroadcastChannel||"undefined"==typeof window)return;this._bcChannel=`yjs-${e.room}`,this._bcSubscriber=(e,t)=>{if(t===this)return;const s=new Uint8Array(e);this._handleIncomingMessage(s)},l.subscribe(this._bcChannel,this._bcSubscriber),this._bcConnected=!0;const t=c.createEncoder();c.writeVarUint(t,d),o.writeSyncStep1(t,this.doc),this._bcPublish(y(c.toUint8Array(t)));const s=c.createEncoder();if(c.writeVarUint(s,d),o.writeSyncStep2(s,this.doc),this._bcPublish(y(c.toUint8Array(s))),null!==this.awareness.getLocalState()){const e=c.createEncoder();c.writeVarUint(e,1),c.writeVarUint8Array(e,i.encodeAwarenessUpdate(this.awareness,[this.doc.clientID])),this._bcPublish(y(c.toUint8Array(e)))}}_disconnectBroadcastChannel(){if(!this._bcConnected||!this._bcSubscriber)return;const e=c.createEncoder();c.writeVarUint(e,1),c.writeVarUint8Array(e,i.encodeAwarenessUpdate(this.awareness,[this.doc.clientID],new Map)),this._bcPublish(y(c.toUint8Array(e))),l.unsubscribe(this._bcChannel,this._bcSubscriber),this._bcConnected=!1,this._bcSubscriber=void 0}_sendBatch(e){0!==e.length&&(1!==e.length?this._send(this._encodeBatch(e)):this._send(e[0]))}_encodeBatch(e){const t=c.createEncoder();c.writeVarUint(t,p);for(const s of e)c.writeVarUint8Array(t,s);return c.toUint8Array(t)}_send(e){const t=y(e);this._bcConnected&&this._bcPublish(t),this.transport.isConnected&&this._sendToTransport(t)}_bcPublish(e){l.publish(this._bcChannel,this._compressionThresholdBytes?S(0,e):e,this)}_sendToTransport(e,t){const s=this._compressionThresholdBytes;s?!m||e.length<s?this._dispatchToTransport(S(0,e),t):async function(e){const t=new CompressionStream("deflate-raw"),s=t.writable.getWriter();return s.write(e).catch((()=>{})),s.close().catch((()=>{})),b(t.readable)}(e).then((e=>{this._dispatchToTransport(S(1,e),t)})).catch((s=>{console.error("[GenericProvider] Compression failed, sending uncompressed:",s),this._dispatchToTransport(S(0,e),t)})):this._dispatchToTransport(e,t)}_dispatchToTransport(e,t){try{const s=void 0!==t&&"function"==typeof this.transport.sendTo?this.transport.sendTo(t,e):this.transport.send(e);s instanceof Promise&&s.catch((e=>{console.error("Error sending data:",e)}))}catch(e){console.error("Error sending data:",e)}}_setStatus(e){this._status=e,this.emit("status",[e])}_testSetSequenceNumber(e){this._localSeqNum=e,console.warn(`[GenericProvider TEST] Sequence number set to ${e} (MAX_SAFE_INTEGER: ${Number.MAX_SAFE_INTEGER})`)}_testGetSequenceNumber(){return this._localSeqNum}}C.AWARENESS_AUTO_MS_PER_PEER=20})),s.register("bx9uf",(function(n,r){e(n.exports,"createDeleteSetFromStructStore",(()=>E)),e(n.exports,"Doc",(()=>P)),e(n.exports,"Array",(()=>lt)),e(n.exports,"Text",(()=>It)),e(n.exports,"Map",(()=>ut)),e(n.exports,"applyUpdate",(()=>K)),e(n.exports,"decodeStateVector",(()=>$)),e(n.exports,"mergeUpdates",(()=>Ue)),e(n.exports,"encodeStateAsUpdate",(()=>J)),e(n.exports,"encodeStateVector",(()=>X)),e(n.exports,"parseUpdateMeta",(()=>Ie));var i=s("8Gyr5"),o=s("9GMWx"),c=s("bGsfJ"),a=s("96q9T"),h=s("7BTJz"),l=s("l5188"),d=s("ouOhr"),u=s("fJEwH"),p=s("jx2H5"),g=s("3Y8uz"),f=s("bcXZT"),w=s("4H1bc"),y=(w=s("4H1bc"),s("5zT0w")),_=s("9hwjE"),m=s("9okbY"),b=(s("16gRh"),s("8drkQ"),s("iRxFz")),S=s("7C9F2"),k=s("isVtz");i.ObservableV2;class v{constructor(e,t){this.clock=e,this.len=t}}class A{constructor(){this.clients=new Map}}const T=(e,t,s)=>t.clients.forEach(((t,n)=>{const r=e.doc.store.clients.get(n);if(null!=r){const n=r[r.length-1],i=n.id.clock+n.length;for(let n=0,o=t[n];n<t.length&&o.clock<i;o=t[++n])_e(e,r,o.clock,o.len,s)}})),C=(e,t)=>{const s=e.clients.get(t.client);return void 0!==s&&null!==((e,t)=>{let s=0,n=e.length-1;for(;s<=n;){const r=c.floor((s+n)/2),i=e[r],o=i.clock;if(o<=t){if(t<o+i.len)return r;s=r+1}else n=r-1}return null})(s,t.clock)},U=e=>{e.clients.forEach((e=>{let t,s;for(e.sort(((e,t)=>e.clock-t.clock)),t=1,s=1;t<e.length;t++){const n=e[s-1],r=e[t];n.clock+n.len>=r.clock?n.len=c.max(n.len,r.clock+r.len-n.clock):(s<t&&(e[s]=r),s++)}e.length=s}))},I=e=>{const t=new A;for(let s=0;s<e.length;s++)e[s].clients.forEach(((n,r)=>{if(!t.clients.has(r)){const i=n.slice();for(let t=s+1;t<e.length;t++)o.appendTo(i,e[t].clients.get(r)||[]);t.clients.set(r,i)}}));return U(t),t},x=(e,t,s,n)=>{a.setIfUndefined(e.clients,t,(()=>[])).push(new v(s,n))},D=()=>new A,E=e=>{const t=D();return e.clients.forEach(((e,s)=>{const n=[];for(let t=0;t<e.length;t++){const s=e[t];if(s.deleted){const r=s.id.clock;let i=s.length;if(t+1<e.length)for(let s=e[t+1];t+1<e.length&&s.deleted;s=e[1+ ++t])i+=s.length;n.push(new v(r,i))}}n.length>0&&t.clients.set(s,n)})),t},R=(e,t)=>{h.writeVarUint(e.restEncoder,t.clients.size),o.from(t.clients.entries()).sort(((e,t)=>t[0]-e[0])).forEach((([t,s])=>{e.resetDsCurVal(),h.writeVarUint(e.restEncoder,t);const n=s.length;h.writeVarUint(e.restEncoder,n);for(let t=0;t<n;t++){const n=s[t];e.writeDsClock(n.clock),e.writeDsLen(n.len)}}))},M=e=>{const t=new A,s=l.readVarUint(e.restDecoder);for(let n=0;n<s;n++){e.resetDsCurVal();const s=l.readVarUint(e.restDecoder),n=l.readVarUint(e.restDecoder);if(n>0){const r=a.setIfUndefined(t.clients,s,(()=>[]));for(let t=0;t<n;t++)r.push(new v(e.readDsClock(),e.readDsLen()))}}return t},V=(e,t,s)=>{const n=new A,r=l.readVarUint(e.restDecoder);for(let i=0;i<r;i++){e.resetDsCurVal();const r=l.readVarUint(e.restDecoder),i=l.readVarUint(e.restDecoder),o=s.clients.get(r)||[],c=de(s,r);for(let s=0;s<i;s++){const s=e.readDsClock(),i=s+e.readDsLen();if(s<c){c<i&&x(n,r,c,i-c);let e=pe(o,s),a=o[e];for(!a.deleted&&a.id.clock<s&&(o.splice(e+1,0,ss(t,a,s-a.id.clock)),e++);e<o.length&&(a=o[e++],a.id.clock<i);)a.deleted||(i<a.id.clock+a.length&&o.splice(e,0,ss(t,a,i-a.id.clock)),a.delete(t))}else x(n,r,s,i-s)}}if(n.clients.size>0){const e=new F;return h.writeVarUint(e.restEncoder,0),R(e,n),e.toUint8Array()}return null},O=d.uint32;class P extends i.ObservableV2{constructor({guid:e=d.uuidv4(),collectionid:t=null,gc:s=!0,gcFilter:n=(()=>!0),meta:r=null,autoLoad:i=!1,shouldLoad:o=!0}={}){super(),this.gc=s,this.gcFilter=n,this.clientID=O(),this.guid=e,this.collectionid=t,this.share=new Map,this.store=new he,this._transaction=null,this._transactionCleanups=[],this.subdocs=new Set,this._item=null,this.shouldLoad=o,this.autoLoad=i,this.meta=r,this.isLoaded=!1,this.isSynced=!1,this.isDestroyed=!1,this.whenLoaded=u.create((e=>{this.on("load",(()=>{this.isLoaded=!0,e(this)}))}));const c=()=>u.create((e=>{const t=s=>{void 0!==s&&!0!==s||(this.off("sync",t),e())};this.on("sync",t)}));this.on("sync",(e=>{!1===e&&this.isSynced&&(this.whenSynced=c()),this.isSynced=void 0===e||!0===e,this.isSynced&&!this.isLoaded&&this.emit("load",[this])})),this.whenSynced=c()}load(){const e=this._item;null===e||this.shouldLoad||Ae(e.parent.doc,(e=>{e.subdocsLoaded.add(this)}),null,!0),this.shouldLoad=!0}getSubdocs(){return this.subdocs}getSubdocGuids(){return new Set(o.from(this.subdocs).map((e=>e.guid)))}transact(e,t=null){return Ae(this,e,t)}get(e,t=Ge){const s=a.setIfUndefined(this.share,e,(()=>{const e=new t;return e._integrate(this,null),e})),n=s.constructor;if(t!==Ge&&n!==t){if(n===Ge){const n=new t;n._map=s._map,s._map.forEach((e=>{for(;null!==e;e=e.left)e.parent=n})),n._start=s._start;for(let e=n._start;null!==e;e=e.right)e.parent=n;return n._length=s._length,this.share.set(e,n),n._integrate(this,null),n}throw new Error(`Type with the name ${e} has already been defined with a different constructor`)}return s}getArray(e=""){return this.get(e,lt)}getText(e=""){return this.get(e,It)}getMap(e=""){return this.get(e,ut)}getXmlElement(e=""){return this.get(e,Et)}getXmlFragment(e=""){return this.get(e,Dt)}toJSON(){const e={};return this.share.forEach(((t,s)=>{e[s]=t.toJSON()})),e}destroy(){this.isDestroyed=!0,o.from(this.subdocs).forEach((e=>e.destroy()));const e=this._item;if(null!==e){this._item=null;const t=e.content;t.doc=new P({guid:this.guid,...t.opts,shouldLoad:!1}),t.doc._item=e,Ae(e.parent.doc,(s=>{const n=t.doc;e.deleted||s.subdocsAdded.add(n),s.subdocsRemoved.add(this)}),null,!0)}this.emit("destroyed",[!0]),this.emit("destroy",[this]),super.destroy()}}class B{constructor(e){this.restDecoder=e}resetDsCurVal(){}readDsClock(){return l.readVarUint(this.restDecoder)}readDsLen(){return l.readVarUint(this.restDecoder)}}class N extends B{readLeftID(){return ie(l.readVarUint(this.restDecoder),l.readVarUint(this.restDecoder))}readRightID(){return ie(l.readVarUint(this.restDecoder),l.readVarUint(this.restDecoder))}readClient(){return l.readVarUint(this.restDecoder)}readInfo(){return l.readUint8(this.restDecoder)}readString(){return l.readVarString(this.restDecoder)}readParentInfo(){return 1===l.readVarUint(this.restDecoder)}readTypeRef(){return l.readVarUint(this.restDecoder)}readLen(){return l.readVarUint(this.restDecoder)}readAny(){return l.readAny(this.restDecoder)}readBuf(){return p.copyUint8Array(l.readVarUint8Array(this.restDecoder))}readJSON(){return JSON.parse(l.readVarString(this.restDecoder))}readKey(){return l.readVarString(this.restDecoder)}}class L{constructor(e){this.dsCurrVal=0,this.restDecoder=e}resetDsCurVal(){this.dsCurrVal=0}readDsClock(){return this.dsCurrVal+=l.readVarUint(this.restDecoder),this.dsCurrVal}readDsLen(){const e=l.readVarUint(this.restDecoder)+1;return this.dsCurrVal+=e,e}}class q extends L{constructor(e){super(e),this.keys=[],l.readVarUint(e),this.keyClockDecoder=new l.IntDiffOptRleDecoder(l.readVarUint8Array(e)),this.clientDecoder=new l.UintOptRleDecoder(l.readVarUint8Array(e)),this.leftClockDecoder=new l.IntDiffOptRleDecoder(l.readVarUint8Array(e)),this.rightClockDecoder=new l.IntDiffOptRleDecoder(l.readVarUint8Array(e)),this.infoDecoder=new l.RleDecoder(l.readVarUint8Array(e),l.readUint8),this.stringDecoder=new l.StringDecoder(l.readVarUint8Array(e)),this.parentInfoDecoder=new l.RleDecoder(l.readVarUint8Array(e),l.readUint8),this.typeRefDecoder=new l.UintOptRleDecoder(l.readVarUint8Array(e)),this.lenDecoder=new l.UintOptRleDecoder(l.readVarUint8Array(e))}readLeftID(){return new ne(this.clientDecoder.read(),this.leftClockDecoder.read())}readRightID(){return new ne(this.clientDecoder.read(),this.rightClockDecoder.read())}readClient(){return this.clientDecoder.read()}readInfo(){return this.infoDecoder.read()}readString(){return this.stringDecoder.read()}readParentInfo(){return 1===this.parentInfoDecoder.read()}readTypeRef(){return this.typeRefDecoder.read()}readLen(){return this.lenDecoder.read()}readAny(){return l.readAny(this.restDecoder)}readBuf(){return l.readVarUint8Array(this.restDecoder)}readJSON(){return l.readAny(this.restDecoder)}readKey(){const e=this.keyClockDecoder.read();if(e<this.keys.length)return this.keys[e];{const e=this.stringDecoder.read();return this.keys.push(e),e}}}class z{constructor(){this.restEncoder=h.createEncoder()}toUint8Array(){return h.toUint8Array(this.restEncoder)}resetDsCurVal(){}writeDsClock(e){h.writeVarUint(this.restEncoder,e)}writeDsLen(e){h.writeVarUint(this.restEncoder,e)}}class W extends z{writeLeftID(e){h.writeVarUint(this.restEncoder,e.client),h.writeVarUint(this.restEncoder,e.clock)}writeRightID(e){h.writeVarUint(this.restEncoder,e.client),h.writeVarUint(this.restEncoder,e.clock)}writeClient(e){h.writeVarUint(this.restEncoder,e)}writeInfo(e){h.writeUint8(this.restEncoder,e)}writeString(e){h.writeVarString(this.restEncoder,e)}writeParentInfo(e){h.writeVarUint(this.restEncoder,e?1:0)}writeTypeRef(e){h.writeVarUint(this.restEncoder,e)}writeLen(e){h.writeVarUint(this.restEncoder,e)}writeAny(e){h.writeAny(this.restEncoder,e)}writeBuf(e){h.writeVarUint8Array(this.restEncoder,e)}writeJSON(e){h.writeVarString(this.restEncoder,JSON.stringify(e))}writeKey(e){h.writeVarString(this.restEncoder,e)}}class H{constructor(){this.restEncoder=h.createEncoder(),this.dsCurrVal=0}toUint8Array(){return h.toUint8Array(this.restEncoder)}resetDsCurVal(){this.dsCurrVal=0}writeDsClock(e){const t=e-this.dsCurrVal;this.dsCurrVal=e,h.writeVarUint(this.restEncoder,t)}writeDsLen(e){0===e&&g.unexpectedCase(),h.writeVarUint(this.restEncoder,e-1),this.dsCurrVal+=e}}class F extends H{constructor(){super(),this.keyMap=new Map,this.keyClock=0,this.keyClockEncoder=new h.IntDiffOptRleEncoder,this.clientEncoder=new h.UintOptRleEncoder,this.leftClockEncoder=new h.IntDiffOptRleEncoder,this.rightClockEncoder=new h.IntDiffOptRleEncoder,this.infoEncoder=new h.RleEncoder(h.writeUint8),this.stringEncoder=new h.StringEncoder,this.parentInfoEncoder=new h.RleEncoder(h.writeUint8),this.typeRefEncoder=new h.UintOptRleEncoder,this.lenEncoder=new h.UintOptRleEncoder}toUint8Array(){const e=h.createEncoder();return h.writeVarUint(e,0),h.writeVarUint8Array(e,this.keyClockEncoder.toUint8Array()),h.writeVarUint8Array(e,this.clientEncoder.toUint8Array()),h.writeVarUint8Array(e,this.leftClockEncoder.toUint8Array()),h.writeVarUint8Array(e,this.rightClockEncoder.toUint8Array()),h.writeVarUint8Array(e,h.toUint8Array(this.infoEncoder)),h.writeVarUint8Array(e,this.stringEncoder.toUint8Array()),h.writeVarUint8Array(e,h.toUint8Array(this.parentInfoEncoder)),h.writeVarUint8Array(e,this.typeRefEncoder.toUint8Array()),h.writeVarUint8Array(e,this.lenEncoder.toUint8Array()),h.writeUint8Array(e,h.toUint8Array(this.restEncoder)),h.toUint8Array(e)}writeLeftID(e){this.clientEncoder.write(e.client),this.leftClockEncoder.write(e.clock)}writeRightID(e){this.clientEncoder.write(e.client),this.rightClockEncoder.write(e.clock)}writeClient(e){this.clientEncoder.write(e)}writeInfo(e){this.infoEncoder.write(e)}writeString(e){this.stringEncoder.write(e)}writeParentInfo(e){this.parentInfoEncoder.write(e?1:0)}writeTypeRef(e){this.typeRefEncoder.write(e)}writeLen(e){this.lenEncoder.write(e)}writeAny(e){h.writeAny(this.restEncoder,e)}writeBuf(e){h.writeVarUint8Array(this.restEncoder,e)}writeJSON(e){h.writeAny(this.restEncoder,e)}writeKey(e){const t=this.keyMap.get(e);void 0===t?(this.keyClockEncoder.write(this.keyClock++),this.stringEncoder.write(e)):this.keyClockEncoder.write(t)}}const j=(e,t,s)=>{const n=new Map;s.forEach(((e,s)=>{de(t,s)>e&&n.set(s,e)})),le(t).forEach(((e,t)=>{s.has(t)||n.set(t,0)})),h.writeVarUint(e.restEncoder,n.size),o.from(n.entries()).sort(((e,t)=>t[0]-e[0])).forEach((([s,n])=>{((e,t,s,n)=>{n=c.max(n,t[0].id.clock);const r=pe(t,n);h.writeVarUint(e.restEncoder,t.length-r),e.writeClient(s),h.writeVarUint(e.restEncoder,n);const i=t[r];i.write(e,n-i.id.clock);for(let s=r+1;s<t.length;s++)t[s].write(e,0)})(e,t.clients.get(s),s,n)}))},G=(e,t,s,n=q)=>{const r=l.createDecoder(t);((e,t,s,n=new q(e))=>{Ae(t,(e=>{e.local=!1;let t=!1;const s=e.doc,r=s.store,i=((e,t)=>{const s=a.create(),n=l.readVarUint(e.restDecoder);for(let r=0;r<n;r++){const n=l.readVarUint(e.restDecoder),r=new Array(n),i=e.readClient();let o=l.readVarUint(e.restDecoder);s.set(i,{i:0,refs:r});for(let s=0;s<n;s++){const n=e.readInfo();switch(f.BITS5&n){case 0:{const t=e.readLen();r[s]=new Pt(ie(i,o),t),o+=t;break}case 10:{const t=l.readVarUint(e.restDecoder);r[s]=new os(ie(i,o),t),o+=t;break}default:{const c=!(n&(f.BIT7|f.BIT8)),a=new ns(ie(i,o),null,(n&f.BIT8)===f.BIT8?e.readLeftID():null,null,(n&f.BIT7)===f.BIT7?e.readRightID():null,c?e.readParentInfo()?t.get(e.readString()):e.readLeftID():null,c&&(n&f.BIT6)===f.BIT6?e.readString():null,rs(e,n));r[s]=a,o+=a.length}}}}return s})(n,s),c=((e,t,s)=>{const n=[];let r=o.from(s.keys()).sort(((e,t)=>e-t));if(0===r.length)return null;const i=()=>{if(0===r.length)return null;let e=s.get(r[r.length-1]);for(;e.refs.length===e.i;){if(r.pop(),!(r.length>0))return null;e=s.get(r[r.length-1])}return e};let c=i();if(null===c)return null;const l=new he,d=new Map,u=(e,t)=>{const s=d.get(e);(null==s||s>t)&&d.set(e,t)};let p=c.refs[c.i++];const g=new Map,f=()=>{for(const e of n){const t=e.id.client,n=s.get(t);n?(n.i--,l.clients.set(t,n.refs.slice(n.i)),s.delete(t),n.i=0,n.refs=[]):l.clients.set(t,[e]),r=r.filter((e=>e!==t))}n.length=0};for(;;){if(p.constructor!==os){const r=a.setIfUndefined(g,p.id.client,(()=>de(t,p.id.client)))-p.id.clock;if(r<0)n.push(p),u(p.id.client,p.id.clock-1),f();else{const i=p.getMissing(e,t);if(null!==i){n.push(p);const e=s.get(i)||{refs:[],i:0};if(e.refs.length!==e.i){p=e.refs[e.i++];continue}u(i,de(t,i)),f()}else(0===r||r<p.length)&&(p.integrate(e,r),g.set(p.id.client,p.id.clock+p.length))}}if(n.length>0)p=n.pop();else if(null!==c&&c.i<c.refs.length)p=c.refs[c.i++];else{if(c=i(),null===c)break;p=c.refs[c.i++]}}if(l.clients.size>0){const e=new F;return j(e,l,new Map),h.writeVarUint(e.restEncoder,0),{missing:d,update:e.toUint8Array()}}return null})(e,r,i),d=r.pendingStructs;if(d){for(const[e,s]of d.missing)if(s<de(r,e)){t=!0;break}if(c){for(const[e,t]of c.missing){const s=d.missing.get(e);(null==s||s>t)&&d.missing.set(e,t)}d.update=De([d.update,c.update])}}else r.pendingStructs=c;const u=V(n,e,r);if(r.pendingDs){const t=new q(l.createDecoder(r.pendingDs));l.readVarUint(t.restDecoder);const s=V(t,e,r);r.pendingDs=u&&s?De([u,s]):u||s}else r.pendingDs=u;if(t){const t=r.pendingStructs.update;r.pendingStructs=null,G(e.doc,t)}}),s,!1)})(r,e,s,new n(r))},K=(e,t,s)=>G(e,t,s,N),J=(e,t)=>((e,t=new Uint8Array([0]),s=new F)=>{((e,t,s=new Map)=>{j(e,t.store,s),R(e,E(t.store))})(s,e,$(t));const n=[s.toUint8Array()];if(e.store.pendingDs&&n.push(e.store.pendingDs),e.store.pendingStructs&&n.push(Ee(e.store.pendingStructs.update,t)),n.length>1){if(s.constructor===W)return Ue(n.map(((e,t)=>0===t?e:Oe(e))));if(s.constructor===F)return De(n)}return n[0]})(e,t,new W),$=e=>(e=>{const t=new Map,s=l.readVarUint(e.restDecoder);for(let n=0;n<s;n++){const s=l.readVarUint(e.restDecoder),n=l.readVarUint(e.restDecoder);t.set(s,n)}return t})(new B(l.createDecoder(e))),Y=(e,t)=>(h.writeVarUint(e.restEncoder,t.size),o.from(t.entries()).sort(((e,t)=>t[0]-e[0])).forEach((([t,s])=>{h.writeVarUint(e.restEncoder,t),h.writeVarUint(e.restEncoder,s)})),e),X=e=>((e,t=new H)=>(e instanceof Map?Y(t,e):((e,t)=>{Y(e,le(t.store))})(t,e),t.toUint8Array()))(e,new z);class Q{constructor(){this.l=[]}}const Z=()=>new Q,ee=(e,t)=>e.l.push(t),te=(e,t)=>{const s=e.l,n=s.length;e.l=s.filter((e=>t!==e)),n===e.l.length&&console.error("[yjs] Tried to remove event handler that doesn't exist.")},se=(e,t,s)=>w.callAll(e.l,[t,s]);class ne{constructor(e,t){this.client=e,this.clock=t}}const re=(e,t)=>e===t||null!==e&&null!==t&&e.client===t.client&&e.clock===t.clock,ie=(e,t)=>new ne(e,t);class oe{constructor(e,t){this.ds=e,this.sv=t}}const ce=(((e,t)=>{new oe(e,t)})(D(),new Map),(e,t)=>void 0===t?!e.deleted:t.sv.has(e.id.client)&&(t.sv.get(e.id.client)||0)>e.id.clock&&!C(t.ds,e.id)),ae=(e,t)=>{const s=a.setIfUndefined(e.meta,ae,y.create),n=e.doc.store;s.has(t)||(t.sv.forEach(((t,s)=>{t<de(n,s)&&we(e,ie(s,t))})),T(e,t.ds,(e=>{})),s.add(t))};class he{constructor(){this.clients=new Map,this.pendingStructs=null,this.pendingDs=null}}const le=e=>{const t=new Map;return e.clients.forEach(((e,s)=>{const n=e[e.length-1];t.set(s,n.id.clock+n.length)})),t},de=(e,t)=>{const s=e.clients.get(t);if(void 0===s)return 0;const n=s[s.length-1];return n.id.clock+n.length},ue=(e,t)=>{let s=e.clients.get(t.id.client);if(void 0===s)s=[],e.clients.set(t.id.client,s);else{const e=s[s.length-1];if(e.id.clock+e.length!==t.id.clock)throw g.unexpectedCase()}s.push(t)},pe=(e,t)=>{let s=0,n=e.length-1,r=e[n],i=r.id.clock;if(i===t)return n;let o=c.floor(t/(i+r.length-1)*n);for(;s<=n;){if(r=e[o],i=r.id.clock,i<=t){if(t<i+r.length)return o;s=o+1}else n=o-1;o=c.floor((s+n)/2)}throw g.unexpectedCase()},ge=(e,t)=>{const s=e.clients.get(t.client);return s[pe(s,t.clock)]},fe=(e,t,s)=>{const n=pe(t,s),r=t[n];return r.id.clock<s&&r instanceof ns?(t.splice(n+1,0,ss(e,r,s-r.id.clock)),n+1):n},we=(e,t)=>{const s=e.doc.store.clients.get(t.client);return s[fe(e,s,t.clock)]},ye=(e,t,s)=>{const n=t.clients.get(s.client),r=pe(n,s.clock),i=n[r];return s.clock!==i.id.clock+i.length-1&&i.constructor!==Pt&&n.splice(r+1,0,ss(e,i,s.clock-i.id.clock+1)),i},_e=(e,t,s,n,r)=>{if(0===n)return;const i=s+n;let o,c=fe(e,t,s);do{o=t[c++],i<o.id.clock+o.length&&fe(e,t,i),r(o)}while(c<t.length&&t[c].id.clock<i)};class me{constructor(e,t,s){this.doc=e,this.deleteSet=new A,this.beforeState=le(e.store),this.afterState=new Map,this.changed=new Map,this.changedParentTypes=new Map,this._mergeStructs=[],this.origin=t,this.meta=new Map,this.local=s,this.subdocsAdded=new Set,this.subdocsRemoved=new Set,this.subdocsLoaded=new Set,this._needFormattingCleanup=!1}}const be=(e,t)=>!(0===t.deleteSet.clients.size&&!a.any(t.afterState,((e,s)=>t.beforeState.get(s)!==e))||(U(t.deleteSet),((e,t)=>{j(e,t.doc.store,t.beforeState)})(e,t),R(e,t.deleteSet),0)),Se=(e,t,s)=>{const n=t._item;(null===n||n.id.clock<(e.beforeState.get(n.id.client)||0)&&!n.deleted)&&a.setIfUndefined(e.changed,t,y.create).add(s)},ke=(e,t)=>{let s=e[t],n=e[t-1],r=t;for(;r>0&&n.deleted===s.deleted&&n.constructor===s.constructor&&n.mergeWith(s);s=n,n=e[--r-1])s instanceof ns&&null!==s.parentSub&&s.parent._map.get(s.parentSub)===s&&s.parent._map.set(s.parentSub,n);const i=t-r;return i&&e.splice(t+1-i,i),i},ve=(e,t)=>{if(t<e.length){const s=e[t],n=s.doc,r=n.store,i=s.deleteSet,o=s._mergeStructs;try{U(i),s.afterState=le(s.doc.store),n.emit("beforeObserverCalls",[s,n]);const e=[];s.changed.forEach(((t,n)=>e.push((()=>{null!==n._item&&n._item.deleted||n._callObserver(s,t)})))),e.push((()=>{s.changedParentTypes.forEach(((t,n)=>{n._dEH.l.length>0&&(null===n._item||!n._item.deleted)&&((t=t.filter((e=>null===e.target._item||!e.target._item.deleted))).forEach((e=>{e.currentTarget=n,e._path=null})),t.sort(((e,t)=>e.path.length-t.path.length)),e.push((()=>{se(n._dEH,t,s)})))})),e.push((()=>n.emit("afterTransaction",[s,n]))),e.push((()=>{s._needFormattingCleanup&&Tt(s)}))})),(0,w.callAll)(e,[])}finally{n.gc&&((e,t,s)=>{for(const[n,r]of e.clients.entries()){const e=t.clients.get(n);for(let n=r.length-1;n>=0;n--){const i=r[n],o=i.clock+i.len;for(let n=pe(e,i.clock),r=e[n];n<e.length&&r.id.clock<o;r=e[++n]){const r=e[n];if(i.clock+i.len<=r.id.clock)break;r instanceof ns&&r.deleted&&!r.keep&&s(r)&&r.gc(t,!1)}}}})(i,r,n.gcFilter),((e,t)=>{e.clients.forEach(((e,s)=>{const n=t.clients.get(s);for(let t=e.length-1;t>=0;t--){const s=e[t];for(let e=c.min(n.length-1,1+pe(n,s.clock+s.len-1)),t=n[e];e>0&&t.id.clock>=s.clock;t=n[e])e-=1+ke(n,e)}}))})(i,r),s.afterState.forEach(((e,t)=>{const n=s.beforeState.get(t)||0;if(n!==e){const e=r.clients.get(t),s=c.max(pe(e,n),1);for(let t=e.length-1;t>=s;)t-=1+ke(e,t)}}));for(let e=o.length-1;e>=0;e--){const{client:t,clock:s}=o[e].id,n=r.clients.get(t),i=pe(n,s);i+1<n.length&&ke(n,i+1)>1||i>0&&ke(n,i)}if(s.local||s.afterState.get(n.clientID)===s.beforeState.get(n.clientID)||(_.print(m.ORANGE,m.BOLD,"[yjs] ",m.UNBOLD,m.RED,"Changed the client-id because another client seems to be using it."),n.clientID=O()),n.emit("afterTransactionCleanup",[s,n]),n._observers.has("update")){const e=new W;be(e,s)&&n.emit("update",[e.toUint8Array(),s.origin,n,s])}if(n._observers.has("updateV2")){const e=new F;be(e,s)&&n.emit("updateV2",[e.toUint8Array(),s.origin,n,s])}const{subdocsAdded:a,subdocsLoaded:h,subdocsRemoved:l}=s;(a.size>0||l.size>0||h.size>0)&&(a.forEach((e=>{e.clientID=n.clientID,null==e.collectionid&&(e.collectionid=n.collectionid),n.subdocs.add(e)})),l.forEach((e=>n.subdocs.delete(e))),n.emit("subdocs",[{loaded:h,added:a,removed:l},n,s]),l.forEach((e=>e.destroy()))),e.length<=t+1?(n._transactionCleanups=[],n.emit("afterAllTransactions",[n,e])):ve(e,t+1)}}},Ae=(e,t,s=null,n=!0)=>{const r=e._transactionCleanups;let i=!1,o=null;null===e._transaction&&(i=!0,e._transaction=new me(e,s,n),r.push(e._transaction),1===r.length&&e.emit("beforeAllTransactions",[e]),e.emit("beforeTransaction",[e._transaction,e]));try{o=t(e._transaction)}finally{if(i){const t=e._transaction===r[0];e._transaction=null,t&&ve(r,0)}}return o};i.ObservableV2;class Te{constructor(e,t){this.gen=function*(e){const t=l.readVarUint(e.restDecoder);for(let s=0;s<t;s++){const t=l.readVarUint(e.restDecoder),s=e.readClient();let n=l.readVarUint(e.restDecoder);for(let r=0;r<t;r++){const t=e.readInfo();if(10===t){const t=l.readVarUint(e.restDecoder);yield new os(ie(s,n),t),n+=t}else if(f.BITS5&t){const r=!(t&(f.BIT7|f.BIT8)),i=new ns(ie(s,n),null,(t&f.BIT8)===f.BIT8?e.readLeftID():null,null,(t&f.BIT7)===f.BIT7?e.readRightID():null,r?e.readParentInfo()?e.readString():e.readLeftID():null,r&&(t&f.BIT6)===f.BIT6?e.readString():null,rs(e,t));yield i,n+=i.length}else{const t=e.readLen();yield new Pt(ie(s,n),t),n+=t}}}}(e),this.curr=null,this.done=!1,this.filterSkips=t,this.next()}next(){do{this.curr=this.gen.next().value||null}while(this.filterSkips&&null!==this.curr&&this.curr.constructor===os);return this.curr}}class Ce{constructor(e){this.currClient=0,this.startClock=0,this.written=0,this.encoder=e,this.clientStructs=[]}}const Ue=e=>De(e,N,W),Ie=e=>((e,t=q)=>{const s=new Map,n=new Map,r=new Te(new t(l.createDecoder(e)),!1);let i=r.curr;if(null!==i){let e=i.id.client,t=i.id.clock;for(s.set(e,t);null!==i;i=r.next())e!==i.id.client&&(n.set(e,t),s.set(i.id.client,i.id.clock),e=i.id.client),t=i.id.clock+i.length;n.set(e,t)}return{from:s,to:n}})(e,N),xe=(e,t)=>{if(e.constructor===Pt){const{client:s,clock:n}=e.id;return new Pt(ie(s,n+t),e.length-t)}if(e.constructor===os){const{client:s,clock:n}=e.id;return new os(ie(s,n+t),e.length-t)}{const s=e,{client:n,clock:r}=s.id;return new ns(ie(n,r+t),null,ie(n,r+t-1),null,s.rightOrigin,s.parent,s.parentSub,s.content.splice(t))}},De=(e,t=q,s=F)=>{if(1===e.length)return e[0];const n=e.map((e=>new t(l.createDecoder(e))));let r=n.map((e=>new Te(e,!0))),i=null;const o=new s,c=new Ce(o);for(;r=r.filter((e=>null!==e.curr)),r.sort(((e,t)=>{if(e.curr.id.client===t.curr.id.client){const s=e.curr.id.clock-t.curr.id.clock;return 0===s?e.curr.constructor===t.curr.constructor?0:e.curr.constructor===os?1:-1:s}return t.curr.id.client-e.curr.id.client})),0!==r.length;){const e=r[0],t=e.curr.id.client;if(null!==i){let s=e.curr,n=!1;for(;null!==s&&s.id.clock+s.length<=i.struct.id.clock+i.struct.length&&s.id.client>=i.struct.id.client;)s=e.next(),n=!0;if(null===s||s.id.client!==t||n&&s.id.clock>i.struct.id.clock+i.struct.length)continue;if(t!==i.struct.id.client)Me(c,i.struct,i.offset),i={struct:s,offset:0},e.next();else if(i.struct.id.clock+i.struct.length<s.id.clock)if(i.struct.constructor===os)i.struct.length=s.id.clock+s.length-i.struct.id.clock;else{Me(c,i.struct,i.offset);const e=s.id.clock-i.struct.id.clock-i.struct.length;i={struct:new os(ie(t,i.struct.id.clock+i.struct.length),e),offset:0}}else{const t=i.struct.id.clock+i.struct.length-s.id.clock;t>0&&(i.struct.constructor===os?i.struct.length-=t:s=xe(s,t)),i.struct.mergeWith(s)||(Me(c,i.struct,i.offset),i={struct:s,offset:0},e.next())}}else i={struct:e.curr,offset:0},e.next();for(let s=e.curr;null!==s&&s.id.client===t&&s.id.clock===i.struct.id.clock+i.struct.length&&s.constructor!==os;s=e.next())Me(c,i.struct,i.offset),i={struct:s,offset:0}}null!==i&&(Me(c,i.struct,i.offset),i=null),Ve(c);const a=n.map((e=>M(e))),h=I(a);return R(o,h),o.toUint8Array()},Ee=(e,t,s=q,n=F)=>{const r=$(t),i=new n,o=new Ce(i),a=new s(l.createDecoder(e)),h=new Te(a,!1);for(;h.curr;){const e=h.curr,t=e.id.client,s=r.get(t)||0;if(h.curr.constructor!==os)if(e.id.clock+e.length>s)for(Me(o,e,c.max(s-e.id.clock,0)),h.next();h.curr&&h.curr.id.client===t;)Me(o,h.curr,0),h.next();else for(;h.curr&&h.curr.id.client===t&&h.curr.id.clock+h.curr.length<=s;)h.next();else h.next()}Ve(o);const d=M(a);return R(i,d),i.toUint8Array()},Re=e=>{e.written>0&&(e.clientStructs.push({written:e.written,restEncoder:h.toUint8Array(e.encoder.restEncoder)}),e.encoder.restEncoder=h.createEncoder(),e.written=0)},Me=(e,t,s)=>{e.written>0&&e.currClient!==t.id.client&&Re(e),0===e.written&&(e.currClient=t.id.client,e.encoder.writeClient(t.id.client),h.writeVarUint(e.encoder.restEncoder,t.id.clock+s)),t.write(e.encoder,s),e.written++},Ve=e=>{Re(e);const t=e.encoder.restEncoder;h.writeVarUint(t,e.clientStructs.length);for(let s=0;s<e.clientStructs.length;s++){const n=e.clientStructs[s];h.writeVarUint(t,n.written),h.writeUint8Array(t,n.restEncoder)}},Oe=e=>((e,t,s,n)=>{const r=new s(l.createDecoder(e)),i=new Te(r,!1),o=new n,c=new Ce(o);for(let e=i.curr;null!==e;e=i.next())Me(c,t(e),0);Ve(c);const a=M(r);return R(o,a),o.toUint8Array()})(e,w.id,q,W),Pe="You must not compute changes after the event-handler fired.";class Be{constructor(e,t){this.target=e,this.currentTarget=e,this.transaction=t,this._changes=null,this._keys=null,this._delta=null,this._path=null}get path(){return this._path||(this._path=Ne(this.currentTarget,this.target))}deletes(e){return C(this.transaction.deleteSet,e.id)}get keys(){if(null===this._keys){if(0===this.transaction.doc._transactionCleanups.length)throw g.create(Pe);const e=new Map,t=this.target;this.transaction.changed.get(t).forEach((s=>{if(null!==s){const n=t._map.get(s);let r,i;if(this.adds(n)){let e=n.left;for(;null!==e&&this.adds(e);)e=e.left;if(this.deletes(n)){if(null===e||!this.deletes(e))return;r="delete",i=o.last(e.content.getContent())}else null!==e&&this.deletes(e)?(r="update",i=o.last(e.content.getContent())):(r="add",i=void 0)}else{if(!this.deletes(n))return;r="delete",i=o.last(n.content.getContent())}e.set(s,{action:r,oldValue:i})}})),this._keys=e}return this._keys}get delta(){return this.changes.delta}adds(e){return e.id.clock>=(this.transaction.beforeState.get(e.id.client)||0)}get changes(){let e=this._changes;if(null===e){if(0===this.transaction.doc._transactionCleanups.length)throw g.create(Pe);const t=this.target,s=y.create(),n=y.create(),r=[];if(e={added:s,deleted:n,delta:r,keys:this.keys},this.transaction.changed.get(t).has(null)){let e=null;const i=()=>{e&&r.push(e)};for(let r=t._start;null!==r;r=r.right)r.deleted?this.deletes(r)&&!this.adds(r)&&(null!==e&&void 0!==e.delete||(i(),e={delete:0}),e.delete+=r.length,n.add(r)):this.adds(r)?(null!==e&&void 0!==e.insert||(i(),e={insert:[]}),e.insert=e.insert.concat(r.content.getContent()),s.add(r)):(null!==e&&void 0!==e.retain||(i(),e={retain:0}),e.retain+=r.length);null!==e&&void 0===e.retain&&i()}this._changes=e}return e}}const Ne=(e,t)=>{const s=[];for(;null!==t._item&&t!==e;){if(null!==t._item.parentSub)s.unshift(t._item.parentSub);else{let e=0,n=t._item.parent._start;for(;n!==t._item&&null!==n;)!n.deleted&&n.countable&&(e+=n.length),n=n.right;s.unshift(e)}t=t._item.parent}return s},Le=()=>{_.warn("Invalid access: Add Yjs type to a document before reading data.")};let qe=0;class ze{constructor(e,t){e.marker=!0,this.p=e,this.index=t,this.timestamp=qe++}}const We=(e,t,s)=>{e.p.marker=!1,e.p=t,t.marker=!0,e.index=s,e.timestamp=qe++},He=(e,t)=>{if(null===e._start||0===t||null===e._searchMarker)return null;const s=0===e._searchMarker.length?null:e._searchMarker.reduce(((e,s)=>c.abs(t-e.index)<c.abs(t-s.index)?e:s));let n=e._start,r=0;for(null!==s&&(n=s.p,r=s.index,(e=>{e.timestamp=qe++})(s));null!==n.right&&r<t;){if(!n.deleted&&n.countable){if(t<r+n.length)break;r+=n.length}n=n.right}for(;null!==n.left&&r>t;)n=n.left,!n.deleted&&n.countable&&(r-=n.length);for(;null!==n.left&&n.left.id.client===n.id.client&&n.left.id.clock+n.left.length===n.id.clock;)n=n.left,!n.deleted&&n.countable&&(r-=n.length);return null!==s&&c.abs(s.index-r)<n.parent.length/80?(We(s,n,r),s):((e,t,s)=>{if(e.length>=80){const n=e.reduce(((e,t)=>e.timestamp<t.timestamp?e:t));return We(n,t,s),n}{const n=new ze(t,s);return e.push(n),n}})(e._searchMarker,n,r)},Fe=(e,t,s)=>{for(let n=e.length-1;n>=0;n--){const r=e[n];if(s>0){let t=r.p;for(t.marker=!1;t&&(t.deleted||!t.countable);)t=t.left,t&&!t.deleted&&t.countable&&(r.index-=t.length);if(null===t||!0===t.marker){e.splice(n,1);continue}r.p=t,t.marker=!0}(t<r.index||s>0&&t===r.index)&&(r.index=c.max(t,r.index+s))}},je=(e,t,s)=>{const n=e,r=t.changedParentTypes;for(;a.setIfUndefined(r,e,(()=>[])).push(s),null!==e._item;)e=e._item.parent;se(n._eH,s,t)};class Ge{constructor(){this._item=null,this._map=new Map,this._start=null,this.doc=null,this._length=0,this._eH=Z(),this._dEH=Z(),this._searchMarker=null}get parent(){return this._item?this._item.parent:null}_integrate(e,t){this.doc=e,this._item=t}_copy(){throw g.methodUnimplemented()}clone(){throw g.methodUnimplemented()}_write(e){}get _first(){let e=this._start;for(;null!==e&&e.deleted;)e=e.right;return e}_callObserver(e,t){!e.local&&this._searchMarker&&(this._searchMarker.length=0)}observe(e){ee(this._eH,e)}observeDeep(e){ee(this._dEH,e)}unobserve(e){te(this._eH,e)}unobserveDeep(e){te(this._dEH,e)}toJSON(){}}const Ke=(e,t,s)=>{e.doc??Le(),t<0&&(t=e._length+t),s<0&&(s=e._length+s);let n=s-t;const r=[];let i=e._start;for(;null!==i&&n>0;){if(i.countable&&!i.deleted){const e=i.content.getContent();if(e.length<=t)t-=e.length;else{for(let s=t;s<e.length&&n>0;s++)r.push(e[s]),n--;t=0}}i=i.right}return r},Je=e=>{e.doc??Le();const t=[];let s=e._start;for(;null!==s;){if(s.countable&&!s.deleted){const e=s.content.getContent();for(let s=0;s<e.length;s++)t.push(e[s])}s=s.right}return t},$e=(e,t)=>{let s=0,n=e._start;for(e.doc??Le();null!==n;){if(n.countable&&!n.deleted){const r=n.content.getContent();for(let n=0;n<r.length;n++)t(r[n],s++,e)}n=n.right}},Ye=(e,t)=>{const s=[];return $e(e,((n,r)=>{s.push(t(n,r,e))})),s},Xe=e=>{let t=e._start,s=null,n=0;return{[Symbol.iterator](){return this},next:()=>{if(null===s){for(;null!==t&&t.deleted;)t=t.right;if(null===t)return{done:!0,value:void 0};s=t.content.getContent(),n=0,t=t.right}const e=s[n++];return s.length<=n&&(s=null),{done:!1,value:e}}}},Qe=(e,t)=>{e.doc??Le();const s=He(e,t);let n=e._start;for(null!==s&&(n=s.p,t-=s.index);null!==n;n=n.right)if(!n.deleted&&n.countable){if(t<n.length)return n.content.getContent()[t];t-=n.length}},Ze=(e,t,s,n)=>{let r=s;const i=e.doc,o=i.clientID,c=i.store,a=null===s?t._start:s.right;let h=[];const l=()=>{h.length>0&&(r=new ns(ie(o,de(c,o)),r,r&&r.lastId,a,a&&a.id,t,null,new jt(h)),r.integrate(e,0),h=[])};n.forEach((s=>{if(null===s)h.push(s);else switch(s.constructor){case Number:case Object:case Boolean:case Array:case String:h.push(s);break;default:switch(l(),s.constructor){case Uint8Array:case ArrayBuffer:r=new ns(ie(o,de(c,o)),r,r&&r.lastId,a,a&&a.id,t,null,new Bt(new Uint8Array(s))),r.integrate(e,0);break;case P:r=new ns(ie(o,de(c,o)),r,r&&r.lastId,a,a&&a.id,t,null,new qt(s)),r.integrate(e,0);break;default:if(!(s instanceof Ge))throw new Error("Unexpected content type in insert operation");r=new ns(ie(o,de(c,o)),r,r&&r.lastId,a,a&&a.id,t,null,new ts(s)),r.integrate(e,0)}}})),l()},et=()=>g.create("Length exceeded!"),tt=(e,t,s,n)=>{if(s>t._length)throw et();if(0===s)return t._searchMarker&&Fe(t._searchMarker,s,n.length),Ze(e,t,null,n);const r=s,i=He(t,s);let o=t._start;for(null!==i&&(o=i.p,0==(s-=i.index)&&(o=o.prev,s+=o&&o.countable&&!o.deleted?o.length:0));null!==o;o=o.right)if(!o.deleted&&o.countable){if(s<=o.length){s<o.length&&we(e,ie(o.id.client,o.id.clock+s));break}s-=o.length}return t._searchMarker&&Fe(t._searchMarker,r,n.length),Ze(e,t,o,n)},st=(e,t,s,n)=>{if(0===n)return;const r=s,i=n,o=He(t,s);let c=t._start;for(null!==o&&(c=o.p,s-=o.index);null!==c&&s>0;c=c.right)!c.deleted&&c.countable&&(s<c.length&&we(e,ie(c.id.client,c.id.clock+s)),s-=c.length);for(;n>0&&null!==c;)c.deleted||(n<c.length&&we(e,ie(c.id.client,c.id.clock+n)),c.delete(e),n-=c.length),c=c.right;if(n>0)throw et();t._searchMarker&&Fe(t._searchMarker,r,-i+n)},nt=(e,t,s)=>{const n=t._map.get(s);void 0!==n&&n.delete(e)},rt=(e,t,s,n)=>{const r=t._map.get(s)||null,i=e.doc,o=i.clientID;let c;if(null==n)c=new jt([n]);else switch(n.constructor){case Number:case Object:case Boolean:case Array:case String:case Date:case BigInt:c=new jt([n]);break;case Uint8Array:c=new Bt(n);break;case P:c=new qt(n);break;default:if(!(n instanceof Ge))throw new Error("Unexpected content type");c=new ts(n)}new ns(ie(o,de(i.store,o)),r,r&&r.lastId,null,null,t,s,c).integrate(e,0)},it=(e,t)=>{e.doc??Le();const s=e._map.get(t);return void 0===s||s.deleted?void 0:s.content.getContent()[s.length-1]},ot=e=>{const t={};return e.doc??Le(),e._map.forEach(((e,s)=>{e.deleted||(t[s]=e.content.getContent()[e.length-1])})),t},ct=(e,t)=>{e.doc??Le();const s=e._map.get(t);return void 0!==s&&!s.deleted},at=e=>(e.doc??Le(),b.iteratorFilter(e._map.entries(),(e=>!e[1].deleted)));class ht extends Be{}class lt extends Ge{constructor(){super(),this._prelimContent=[],this._searchMarker=[]}static from(e){const t=new lt;return t.push(e),t}_integrate(e,t){super._integrate(e,t),this.insert(0,this._prelimContent),this._prelimContent=null}_copy(){return new lt}clone(){const e=new lt;return e.insert(0,this.toArray().map((e=>e instanceof Ge?e.clone():e))),e}get length(){return this.doc??Le(),this._length}_callObserver(e,t){super._callObserver(e,t),je(this,e,new ht(this,e))}insert(e,t){null!==this.doc?Ae(this.doc,(s=>{tt(s,this,e,t)})):this._prelimContent.splice(e,0,...t)}push(e){null!==this.doc?Ae(this.doc,(t=>{((e,t,s)=>{let n=(t._searchMarker||[]).reduce(((e,t)=>t.index>e.index?t:e),{index:0,p:t._start}).p;if(n)for(;n.right;)n=n.right;Ze(e,t,n,s)})(t,this,e)})):this._prelimContent.push(...e)}unshift(e){this.insert(0,e)}delete(e,t=1){null!==this.doc?Ae(this.doc,(s=>{st(s,this,e,t)})):this._prelimContent.splice(e,t)}get(e){return Qe(this,e)}toArray(){return Je(this)}slice(e=0,t=this.length){return Ke(this,e,t)}toJSON(){return this.map((e=>e instanceof Ge?e.toJSON():e))}map(e){return Ye(this,e)}forEach(e){$e(this,e)}[Symbol.iterator](){return Xe(this)}_write(e){e.writeTypeRef(Jt)}}class dt extends Be{constructor(e,t,s){super(e,t),this.keysChanged=s}}class ut extends Ge{constructor(e){super(),this._prelimContent=null,this._prelimContent=void 0===e?new Map:new Map(e)}_integrate(e,t){super._integrate(e,t),this._prelimContent.forEach(((e,t)=>{this.set(t,e)})),this._prelimContent=null}_copy(){return new ut}clone(){const e=new ut;return this.forEach(((t,s)=>{e.set(s,t instanceof Ge?t.clone():t)})),e}_callObserver(e,t){je(this,e,new dt(this,e,t))}toJSON(){this.doc??Le();const e={};return this._map.forEach(((t,s)=>{if(!t.deleted){const n=t.content.getContent()[t.length-1];e[s]=n instanceof Ge?n.toJSON():n}})),e}get size(){return[...at(this)].length}keys(){return b.iteratorMap(at(this),(e=>e[0]))}values(){return b.iteratorMap(at(this),(e=>e[1].content.getContent()[e[1].length-1]))}entries(){return b.iteratorMap(at(this),(e=>[e[0],e[1].content.getContent()[e[1].length-1]]))}forEach(e){this.doc??Le(),this._map.forEach(((t,s)=>{t.deleted||e(t.content.getContent()[t.length-1],s,this)}))}[Symbol.iterator](){return this.entries()}delete(e){null!==this.doc?Ae(this.doc,(t=>{nt(t,this,e)})):this._prelimContent.delete(e)}set(e,t){return null!==this.doc?Ae(this.doc,(s=>{rt(s,this,e,t)})):this._prelimContent.set(e,t),t}get(e){return it(this,e)}has(e){return ct(this,e)}clear(){null!==this.doc?Ae(this.doc,(e=>{this.forEach((function(t,s,n){nt(e,n,s)}))})):this._prelimContent.clear()}_write(e){e.writeTypeRef($t)}}const pt=(e,t)=>e===t||"object"==typeof e&&"object"==typeof t&&e&&t&&S.equalFlat(e,t);class gt{constructor(e,t,s,n){this.left=e,this.right=t,this.index=s,this.currentAttributes=n}forward(){null===this.right&&g.unexpectedCase(),this.right.content.constructor===Wt?this.right.deleted||_t(this.currentAttributes,this.right.content):this.right.deleted||(this.index+=this.right.length),this.left=this.right,this.right=this.right.right}}const ft=(e,t,s)=>{for(;null!==t.right&&s>0;)t.right.content.constructor===Wt?t.right.deleted||_t(t.currentAttributes,t.right.content):t.right.deleted||(s<t.right.length&&we(e,ie(t.right.id.client,t.right.id.clock+s)),t.index+=t.right.length,s-=t.right.length),t.left=t.right,t.right=t.right.right;return t},wt=(e,t,s,n)=>{const r=new Map,i=n?He(t,s):null;if(i){const t=new gt(i.p.left,i.p,i.index,r);return ft(e,t,s-i.index)}{const n=new gt(null,t._start,0,r);return ft(e,n,s)}},yt=(e,t,s,n)=>{for(;null!==s.right&&(!0===s.right.deleted||s.right.content.constructor===Wt&&pt(n.get(s.right.content.key),s.right.content.value));)s.right.deleted||n.delete(s.right.content.key),s.forward();const r=e.doc,i=r.clientID;n.forEach(((n,o)=>{const c=s.left,a=s.right,h=new ns(ie(i,de(r.store,i)),c,c&&c.lastId,a,a&&a.id,t,null,new Wt(o,n));h.integrate(e,0),s.right=h,s.forward()}))},_t=(e,t)=>{const{key:s,value:n}=t;null===n?e.delete(s):e.set(s,n)},mt=(e,t)=>{for(;null!==e.right&&(e.right.deleted||e.right.content.constructor===Wt&&pt(t[e.right.content.key]??null,e.right.content.value));)e.forward()},bt=(e,t,s,n)=>{const r=e.doc,i=r.clientID,o=new Map;for(const c in n){const a=n[c],h=s.currentAttributes.get(c)??null;if(!pt(h,a)){o.set(c,h);const{left:n,right:l}=s;s.right=new ns(ie(i,de(r.store,i)),n,n&&n.lastId,l,l&&l.id,t,null,new Wt(c,a)),s.right.integrate(e,0),s.forward()}}return o},St=(e,t,s,n,r)=>{s.currentAttributes.forEach(((e,t)=>{void 0===r[t]&&(r[t]=null)}));const i=e.doc,o=i.clientID;mt(s,r);const c=bt(e,t,s,r),a=n.constructor===String?new Gt(n):n instanceof Ge?new ts(n):new zt(n);let{left:h,right:l,index:d}=s;t._searchMarker&&Fe(t._searchMarker,s.index,a.getLength()),l=new ns(ie(o,de(i.store,o)),h,h&&h.lastId,l,l&&l.id,t,null,a),l.integrate(e,0),s.right=l,s.index=d,s.forward(),yt(e,t,s,c)},kt=(e,t,s,n,r)=>{const i=e.doc,o=i.clientID;mt(s,r);const c=bt(e,t,s,r);e:for(;null!==s.right&&(n>0||c.size>0&&(s.right.deleted||s.right.content.constructor===Wt));){if(!s.right.deleted)switch(s.right.content.constructor){case Wt:{const{key:t,value:i}=s.right.content,o=r[t];if(void 0!==o){if(pt(o,i))c.delete(t);else{if(0===n)break e;c.set(t,i)}s.right.delete(e)}else s.currentAttributes.set(t,i);break}default:n<s.right.length&&we(e,ie(s.right.id.client,s.right.id.clock+n)),n-=s.right.length}s.forward()}if(n>0){let r="";for(;n>0;n--)r+="\n";s.right=new ns(ie(o,de(i.store,o)),s.left,s.left&&s.left.lastId,s.right,s.right&&s.right.id,t,null,new Gt(r)),s.right.integrate(e,0),s.forward()}yt(e,t,s,c)},vt=(e,t,s,n,r)=>{let i=t;const o=a.create();for(;i&&(!i.countable||i.deleted);){if(!i.deleted&&i.content.constructor===Wt){const e=i.content;o.set(e.key,e)}i=i.right}let c=0,h=!1;for(;t!==i;){if(s===t&&(h=!0),!t.deleted){const s=t.content;switch(s.constructor){case Wt:{const{key:i,value:a}=s,l=n.get(i)??null;o.get(i)===s&&l!==a||(t.delete(e),c++,h||(r.get(i)??null)!==a||l===a||(null===l?r.delete(i):r.set(i,l))),h||t.deleted||_t(r,s);break}}}t=t.right}return c},At=e=>{let t=0;return Ae(e.doc,(s=>{let n=e._start,r=e._start,i=a.create();const o=a.copy(i);for(;r;)!1===r.deleted&&(r.content.constructor===Wt?_t(o,r.content):(t+=vt(s,n,r,i,o),i=a.copy(o),n=r)),r=r.right})),t},Tt=e=>{const t=new Set,s=e.doc;for(const[n,r]of e.afterState.entries()){const i=e.beforeState.get(n)||0;r!==i&&_e(e,s.store.clients.get(n),i,r,(e=>{e.deleted||e.content.constructor!==Wt||e.constructor===Pt||t.add(e.parent)}))}Ae(s,(s=>{T(e,e.deleteSet,(e=>{if(e instanceof Pt||!e.parent._hasFormatting||t.has(e.parent))return;const n=e.parent;e.content.constructor===Wt?t.add(n):((e,t)=>{for(;t&&t.right&&(t.right.deleted||!t.right.countable);)t=t.right;const s=new Set;for(;t&&(t.deleted||!t.countable);){if(!t.deleted&&t.content.constructor===Wt){const n=t.content.key;s.has(n)?t.delete(e):s.add(n)}t=t.left}})(s,e)}));for(const e of t)At(e)}))},Ct=(e,t,s)=>{const n=s,r=a.copy(t.currentAttributes),i=t.right;for(;s>0&&null!==t.right;){if(!1===t.right.deleted)switch(t.right.content.constructor){case ts:case zt:case Gt:s<t.right.length&&we(e,ie(t.right.id.client,t.right.id.clock+s)),s-=t.right.length,t.right.delete(e)}t.forward()}i&&vt(e,i,t.right,r,t.currentAttributes);const o=(t.left||t.right).parent;return o._searchMarker&&Fe(o._searchMarker,t.index,-n+s),t};class Ut extends Be{constructor(e,t,s){super(e,t),this.childListChanged=!1,this.keysChanged=new Set,s.forEach((e=>{null===e?this.childListChanged=!0:this.keysChanged.add(e)}))}get changes(){if(null===this._changes){const e={keys:this.keys,delta:this.delta,added:new Set,deleted:new Set};this._changes=e}return this._changes}get delta(){if(null===this._delta){const e=this.target.doc,t=[];Ae(e,(e=>{const s=new Map,n=new Map;let r=this.target._start,i=null;const o={};let c="",a=0,h=0;const l=()=>{if(null!==i){let e=null;switch(i){case"delete":h>0&&(e={delete:h}),h=0;break;case"insert":("object"==typeof c||c.length>0)&&(e={insert:c},s.size>0&&(e.attributes={},s.forEach(((t,s)=>{null!==t&&(e.attributes[s]=t)})))),c="";break;case"retain":a>0&&(e={retain:a},S.isEmpty(o)||(e.attributes=S.assign({},o))),a=0}e&&t.push(e),i=null}};for(;null!==r;){switch(r.content.constructor){case ts:case zt:this.adds(r)?this.deletes(r)||(l(),i="insert",c=r.content.getContent()[0],l()):this.deletes(r)?("delete"!==i&&(l(),i="delete"),h+=1):r.deleted||("retain"!==i&&(l(),i="retain"),a+=1);break;case Gt:this.adds(r)?this.deletes(r)||("insert"!==i&&(l(),i="insert"),c+=r.content.str):this.deletes(r)?("delete"!==i&&(l(),i="delete"),h+=r.length):r.deleted||("retain"!==i&&(l(),i="retain"),a+=r.length);break;case Wt:{const{key:t,value:c}=r.content;if(this.adds(r)){if(!this.deletes(r)){const a=s.get(t)??null;pt(a,c)?null!==c&&r.delete(e):("retain"===i&&l(),pt(c,n.get(t)??null)?delete o[t]:o[t]=c)}}else if(this.deletes(r)){n.set(t,c);const e=s.get(t)??null;pt(e,c)||("retain"===i&&l(),o[t]=e)}else if(!r.deleted){n.set(t,c);const s=o[t];void 0!==s&&(pt(s,c)?null!==s&&r.delete(e):("retain"===i&&l(),null===c?delete o[t]:o[t]=c))}r.deleted||("insert"===i&&l(),_t(s,r.content));break}}r=r.right}for(l();t.length>0;){const e=t[t.length-1];if(void 0===e.retain||void 0!==e.attributes)break;t.pop()}})),this._delta=t}return this._delta}}class It extends Ge{constructor(e){super(),this._pending=void 0!==e?[()=>this.insert(0,e)]:[],this._searchMarker=[],this._hasFormatting=!1}get length(){return this.doc??Le(),this._length}_integrate(e,t){super._integrate(e,t);try{this._pending.forEach((e=>e()))}catch(e){console.error(e)}this._pending=null}_copy(){return new It}clone(){const e=new It;return e.applyDelta(this.toDelta()),e}_callObserver(e,t){super._callObserver(e,t);const s=new Ut(this,e,t);je(this,e,s),!e.local&&this._hasFormatting&&(e._needFormattingCleanup=!0)}toString(){this.doc??Le();let e="",t=this._start;for(;null!==t;)!t.deleted&&t.countable&&t.content.constructor===Gt&&(e+=t.content.str),t=t.right;return e}toJSON(){return this.toString()}applyDelta(e,{sanitize:t=!0}={}){null!==this.doc?Ae(this.doc,(s=>{const n=new gt(null,this._start,0,new Map);for(let r=0;r<e.length;r++){const i=e[r];if(void 0!==i.insert){const o=t||"string"!=typeof i.insert||r!==e.length-1||null!==n.right||"\n"!==i.insert.slice(-1)?i.insert:i.insert.slice(0,-1);("string"!=typeof o||o.length>0)&&St(s,this,n,o,i.attributes||{})}else void 0!==i.retain?kt(s,this,n,i.retain,i.attributes||{}):void 0!==i.delete&&Ct(s,n,i.delete)}})):this._pending.push((()=>this.applyDelta(e)))}toDelta(e,t,s){this.doc??Le();const n=[],r=new Map,i=this.doc;let o="",c=this._start;function a(){if(o.length>0){const e={};let t=!1;r.forEach(((s,n)=>{t=!0,e[n]=s}));const s={insert:o};t&&(s.attributes=e),n.push(s),o=""}}const h=()=>{for(;null!==c;){if(ce(c,e)||void 0!==t&&ce(c,t))switch(c.content.constructor){case Gt:{const n=r.get("ychange");void 0===e||ce(c,e)?void 0===t||ce(c,t)?void 0!==n&&(a(),r.delete("ychange")):void 0!==n&&n.user===c.id.client&&"added"===n.type||(a(),r.set("ychange",s?s("added",c.id):{type:"added"})):void 0!==n&&n.user===c.id.client&&"removed"===n.type||(a(),r.set("ychange",s?s("removed",c.id):{type:"removed"})),o+=c.content.str;break}case ts:case zt:{a();const e={insert:c.content.getContent()[0]};if(r.size>0){const t={};e.attributes=t,r.forEach(((e,s)=>{t[s]=e}))}n.push(e);break}case Wt:ce(c,e)&&(a(),_t(r,c.content))}c=c.right}a()};return e||t?Ae(i,(s=>{e&&ae(s,e),t&&ae(s,t),h()}),"cleanup"):h(),n}insert(e,t,s){if(t.length<=0)return;const n=this.doc;null!==n?Ae(n,(n=>{const r=wt(n,this,e,!s);s||(s={},r.currentAttributes.forEach(((e,t)=>{s[t]=e}))),St(n,this,r,t,s)})):this._pending.push((()=>this.insert(e,t,s)))}insertEmbed(e,t,s){const n=this.doc;null!==n?Ae(n,(n=>{const r=wt(n,this,e,!s);St(n,this,r,t,s||{})})):this._pending.push((()=>this.insertEmbed(e,t,s||{})))}delete(e,t){if(0===t)return;const s=this.doc;null!==s?Ae(s,(s=>{Ct(s,wt(s,this,e,!0),t)})):this._pending.push((()=>this.delete(e,t)))}format(e,t,s){if(0===t)return;const n=this.doc;null!==n?Ae(n,(n=>{const r=wt(n,this,e,!1);null!==r.right&&kt(n,this,r,t,s)})):this._pending.push((()=>this.format(e,t,s)))}removeAttribute(e){null!==this.doc?Ae(this.doc,(t=>{nt(t,this,e)})):this._pending.push((()=>this.removeAttribute(e)))}setAttribute(e,t){null!==this.doc?Ae(this.doc,(s=>{rt(s,this,e,t)})):this._pending.push((()=>this.setAttribute(e,t)))}getAttribute(e){return it(this,e)}getAttributes(){return ot(this)}_write(e){e.writeTypeRef(Yt)}}class xt{constructor(e,t=(()=>!0)){this._filter=t,this._root=e,this._currentNode=e._start,this._firstCall=!0,e.doc??Le()}[Symbol.iterator](){return this}next(){let e=this._currentNode,t=e&&e.content&&e.content.type;if(null!==e&&(!this._firstCall||e.deleted||!this._filter(t)))do{if(t=e.content.type,e.deleted||t.constructor!==Et&&t.constructor!==Dt||null===t._start)for(;null!==e;){const t=e.next;if(null!==t){e=t;break}e=e.parent===this._root?null:e.parent._item}else e=t._start}while(null!==e&&(e.deleted||!this._filter(e.content.type)));return this._firstCall=!1,null===e?{value:void 0,done:!0}:(this._currentNode=e,{value:e.content.type,done:!1})}}class Dt extends Ge{constructor(){super(),this._prelimContent=[]}get firstChild(){const e=this._first;return e?e.content.getContent()[0]:null}_integrate(e,t){super._integrate(e,t),this.insert(0,this._prelimContent),this._prelimContent=null}_copy(){return new Dt}clone(){const e=new Dt;return e.insert(0,this.toArray().map((e=>e instanceof Ge?e.clone():e))),e}get length(){return this.doc??Le(),null===this._prelimContent?this._length:this._prelimContent.length}createTreeWalker(e){return new xt(this,e)}querySelector(e){e=e.toUpperCase();const t=new xt(this,(t=>t.nodeName&&t.nodeName.toUpperCase()===e)).next();return t.done?null:t.value}querySelectorAll(e){return e=e.toUpperCase(),o.from(new xt(this,(t=>t.nodeName&&t.nodeName.toUpperCase()===e)))}_callObserver(e,t){je(this,e,new Rt(this,t,e))}toString(){return Ye(this,(e=>e.toString())).join("")}toJSON(){return this.toString()}toDOM(e=document,t={},s){const n=e.createDocumentFragment();return void 0!==s&&s._createAssociation(n,this),$e(this,(r=>{n.insertBefore(r.toDOM(e,t,s),null)})),n}insert(e,t){null!==this.doc?Ae(this.doc,(s=>{tt(s,this,e,t)})):this._prelimContent.splice(e,0,...t)}insertAfter(e,t){if(null!==this.doc)Ae(this.doc,(s=>{const n=e&&e instanceof Ge?e._item:e;Ze(s,this,n,t)}));else{const s=this._prelimContent,n=null===e?0:s.findIndex((t=>t===e))+1;if(0===n&&null!==e)throw g.create("Reference item not found");s.splice(n,0,...t)}}delete(e,t=1){null!==this.doc?Ae(this.doc,(s=>{st(s,this,e,t)})):this._prelimContent.splice(e,t)}toArray(){return Je(this)}push(e){this.insert(this.length,e)}unshift(e){this.insert(0,e)}get(e){return Qe(this,e)}slice(e=0,t=this.length){return Ke(this,e,t)}forEach(e){$e(this,e)}_write(e){e.writeTypeRef(Qt)}}class Et extends Dt{constructor(e="UNDEFINED"){super(),this.nodeName=e,this._prelimAttrs=new Map}get nextSibling(){const e=this._item?this._item.next:null;return e?e.content.type:null}get prevSibling(){const e=this._item?this._item.prev:null;return e?e.content.type:null}_integrate(e,t){super._integrate(e,t),this._prelimAttrs.forEach(((e,t)=>{this.setAttribute(t,e)})),this._prelimAttrs=null}_copy(){return new Et(this.nodeName)}clone(){const e=new Et(this.nodeName),t=this.getAttributes();return S.forEach(t,((t,s)=>{e.setAttribute(s,t)})),e.insert(0,this.toArray().map((e=>e instanceof Ge?e.clone():e))),e}toString(){const e=this.getAttributes(),t=[],s=[];for(const t in e)s.push(t);s.sort();const n=s.length;for(let r=0;r<n;r++){const n=s[r];t.push(n+'="'+e[n]+'"')}const r=this.nodeName.toLocaleLowerCase();return`<${r}${t.length>0?" "+t.join(" "):""}>${super.toString()}</${r}>`}removeAttribute(e){null!==this.doc?Ae(this.doc,(t=>{nt(t,this,e)})):this._prelimAttrs.delete(e)}setAttribute(e,t){null!==this.doc?Ae(this.doc,(s=>{rt(s,this,e,t)})):this._prelimAttrs.set(e,t)}getAttribute(e){return it(this,e)}hasAttribute(e){return ct(this,e)}getAttributes(e){return e?((e,t)=>{const s={};return this._map.forEach(((e,n)=>{let r=e;for(;null!==r&&(!t.sv.has(r.id.client)||r.id.clock>=(t.sv.get(r.id.client)||0));)r=r.left;null!==r&&ce(r,t)&&(s[n]=r.content.getContent()[r.length-1])})),s})(0,e):ot(this)}toDOM(e=document,t={},s){const n=e.createElement(this.nodeName),r=this.getAttributes();for(const e in r){const t=r[e];"string"==typeof t&&n.setAttribute(e,t)}return $e(this,(r=>{n.appendChild(r.toDOM(e,t,s))})),void 0!==s&&s._createAssociation(n,this),n}_write(e){e.writeTypeRef(Xt),e.writeKey(this.nodeName)}}class Rt extends Be{constructor(e,t,s){super(e,s),this.childListChanged=!1,this.attributesChanged=new Set,t.forEach((e=>{null===e?this.childListChanged=!0:this.attributesChanged.add(e)}))}}class Mt extends ut{constructor(e){super(),this.hookName=e}_copy(){return new Mt(this.hookName)}clone(){const e=new Mt(this.hookName);return this.forEach(((t,s)=>{e.set(s,t)})),e}toDOM(e=document,t={},s){const n=t[this.hookName];let r;return r=void 0!==n?n.createDom(this):document.createElement(this.hookName),r.setAttribute("data-yjs-hook",this.hookName),void 0!==s&&s._createAssociation(r,this),r}_write(e){e.writeTypeRef(Zt),e.writeKey(this.hookName)}}class Vt extends It{get nextSibling(){const e=this._item?this._item.next:null;return e?e.content.type:null}get prevSibling(){const e=this._item?this._item.prev:null;return e?e.content.type:null}_copy(){return new Vt}clone(){const e=new Vt;return e.applyDelta(this.toDelta()),e}toDOM(e=document,t,s){const n=e.createTextNode(this.toString());return void 0!==s&&s._createAssociation(n,this),n}toString(){return this.toDelta().map((e=>{const t=[];for(const s in e.attributes){const n=[];for(const t in e.attributes[s])n.push({key:t,value:e.attributes[s][t]});n.sort(((e,t)=>e.key<t.key?-1:1)),t.push({nodeName:s,attrs:n})}t.sort(((e,t)=>e.nodeName<t.nodeName?-1:1));let s="";for(let e=0;e<t.length;e++){const n=t[e];s+=`<${n.nodeName}`;for(let e=0;e<n.attrs.length;e++){const t=n.attrs[e];s+=` ${t.key}="${t.value}"`}s+=">"}s+=e.insert;for(let e=t.length-1;e>=0;e--)s+=`</${t[e].nodeName}>`;return s})).join("")}toJSON(){return this.toString()}_write(e){e.writeTypeRef(es)}}class Ot{constructor(e,t){this.id=e,this.length=t}get deleted(){throw g.methodUnimplemented()}mergeWith(e){return!1}write(e,t,s){throw g.methodUnimplemented()}integrate(e,t){throw g.methodUnimplemented()}}class Pt extends Ot{get deleted(){return!0}delete(){}mergeWith(e){return this.constructor===e.constructor&&(this.length+=e.length,!0)}integrate(e,t){t>0&&(this.id.clock+=t,this.length-=t),ue(e.doc.store,this)}write(e,t){e.writeInfo(0),e.writeLen(this.length-t)}getMissing(e,t){return null}}class Bt{constructor(e){this.content=e}getLength(){return 1}getContent(){return[this.content]}isCountable(){return!0}copy(){return new Bt(this.content)}splice(e){throw g.methodUnimplemented()}mergeWith(e){return!1}integrate(e,t){}delete(e){}gc(e){}write(e,t){e.writeBuf(this.content)}getRef(){return 3}}class Nt{constructor(e){this.len=e}getLength(){return this.len}getContent(){return[]}isCountable(){return!1}copy(){return new Nt(this.len)}splice(e){const t=new Nt(this.len-e);return this.len=e,t}mergeWith(e){return this.len+=e.len,!0}integrate(e,t){x(e.deleteSet,t.id.client,t.id.clock,this.len),t.markDeleted()}delete(e){}gc(e){}write(e,t){e.writeLen(this.len-t)}getRef(){return 1}}const Lt=(e,t)=>new P({guid:e,...t,shouldLoad:t.shouldLoad||t.autoLoad||!1});class qt{constructor(e){e._item&&console.error("This document was already integrated as a sub-document. You should create a second instance instead with the same guid."),this.doc=e;const t={};this.opts=t,e.gc||(t.gc=!1),e.autoLoad&&(t.autoLoad=!0),null!==e.meta&&(t.meta=e.meta)}getLength(){return 1}getContent(){return[this.doc]}isCountable(){return!0}copy(){return new qt(Lt(this.doc.guid,this.opts))}splice(e){throw g.methodUnimplemented()}mergeWith(e){return!1}integrate(e,t){this.doc._item=t,e.subdocsAdded.add(this.doc),this.doc.shouldLoad&&e.subdocsLoaded.add(this.doc)}delete(e){e.subdocsAdded.has(this.doc)?e.subdocsAdded.delete(this.doc):e.subdocsRemoved.add(this.doc)}gc(e){}write(e,t){e.writeString(this.doc.guid),e.writeAny(this.opts)}getRef(){return 9}}class zt{constructor(e){this.embed=e}getLength(){return 1}getContent(){return[this.embed]}isCountable(){return!0}copy(){return new zt(this.embed)}splice(e){throw g.methodUnimplemented()}mergeWith(e){return!1}integrate(e,t){}delete(e){}gc(e){}write(e,t){e.writeJSON(this.embed)}getRef(){return 5}}class Wt{constructor(e,t){this.key=e,this.value=t}getLength(){return 1}getContent(){return[]}isCountable(){return!1}copy(){return new Wt(this.key,this.value)}splice(e){throw g.methodUnimplemented()}mergeWith(e){return!1}integrate(e,t){const s=t.parent;s._searchMarker=null,s._hasFormatting=!0}delete(e){}gc(e){}write(e,t){e.writeKey(this.key),e.writeJSON(this.value)}getRef(){return 6}}class Ht{constructor(e){this.arr=e}getLength(){return this.arr.length}getContent(){return this.arr}isCountable(){return!0}copy(){return new Ht(this.arr)}splice(e){const t=new Ht(this.arr.slice(e));return this.arr=this.arr.slice(0,e),t}mergeWith(e){return this.arr=this.arr.concat(e.arr),!0}integrate(e,t){}delete(e){}gc(e){}write(e,t){const s=this.arr.length;e.writeLen(s-t);for(let n=t;n<s;n++){const t=this.arr[n];e.writeString(void 0===t?"undefined":JSON.stringify(t))}}getRef(){return 2}}const Ft="development"===k.getVariable("node_env");class jt{constructor(e){this.arr=e,Ft&&S.deepFreeze(e)}getLength(){return this.arr.length}getContent(){return this.arr}isCountable(){return!0}copy(){return new jt(this.arr)}splice(e){const t=new jt(this.arr.slice(e));return this.arr=this.arr.slice(0,e),t}mergeWith(e){return this.arr=this.arr.concat(e.arr),!0}integrate(e,t){}delete(e){}gc(e){}write(e,t){const s=this.arr.length;e.writeLen(s-t);for(let n=t;n<s;n++){const t=this.arr[n];e.writeAny(t)}}getRef(){return 8}}class Gt{constructor(e){this.str=e}getLength(){return this.str.length}getContent(){return this.str.split("")}isCountable(){return!0}copy(){return new Gt(this.str)}splice(e){const t=new Gt(this.str.slice(e));this.str=this.str.slice(0,e);const s=this.str.charCodeAt(e-1);return s>=55296&&s<=56319&&(this.str=this.str.slice(0,e-1)+"�",t.str="�"+t.str.slice(1)),t}mergeWith(e){return this.str+=e.str,!0}integrate(e,t){}delete(e){}gc(e){}write(e,t){e.writeString(0===t?this.str:this.str.slice(t))}getRef(){return 4}}const Kt=[e=>new lt,e=>new ut,e=>new It,e=>new Et(e.readKey()),e=>new Dt,e=>new Mt(e.readKey()),e=>new Vt],Jt=0,$t=1,Yt=2,Xt=3,Qt=4,Zt=5,es=6;class ts{constructor(e){this.type=e}getLength(){return 1}getContent(){return[this.type]}isCountable(){return!0}copy(){return new ts(this.type._copy())}splice(e){throw g.methodUnimplemented()}mergeWith(e){return!1}integrate(e,t){this.type._integrate(e.doc,t)}delete(e){let t=this.type._start;for(;null!==t;)t.deleted?t.id.clock<(e.beforeState.get(t.id.client)||0)&&e._mergeStructs.push(t):t.delete(e),t=t.right;this.type._map.forEach((t=>{t.deleted?t.id.clock<(e.beforeState.get(t.id.client)||0)&&e._mergeStructs.push(t):t.delete(e)})),e.changed.delete(this.type)}gc(e){let t=this.type._start;for(;null!==t;)t.gc(e,!0),t=t.right;this.type._start=null,this.type._map.forEach((t=>{for(;null!==t;)t.gc(e,!0),t=t.left})),this.type._map=new Map}write(e,t){this.type._write(e)}getRef(){return 7}}const ss=(e,t,s)=>{const{client:n,clock:r}=t.id,i=new ns(ie(n,r+s),t,ie(n,r+s-1),t.right,t.rightOrigin,t.parent,t.parentSub,t.content.splice(s));return t.deleted&&i.markDeleted(),t.keep&&(i.keep=!0),null!==t.redone&&(i.redone=ie(t.redone.client,t.redone.clock+s)),t.right=i,null!==i.right&&(i.right.left=i),e._mergeStructs.push(i),null!==i.parentSub&&null===i.right&&i.parent._map.set(i.parentSub,i),t.length=s,i};class ns extends Ot{constructor(e,t,s,n,r,i,o,c){super(e,c.getLength()),this.origin=s,this.left=t,this.right=n,this.rightOrigin=r,this.parent=i,this.parentSub=o,this.redone=null,this.content=c,this.info=this.content.isCountable()?f.BIT2:0}set marker(e){(this.info&f.BIT4)>0!==e&&(this.info^=f.BIT4)}get marker(){return(this.info&f.BIT4)>0}get keep(){return(this.info&f.BIT1)>0}set keep(e){this.keep!==e&&(this.info^=f.BIT1)}get countable(){return(this.info&f.BIT2)>0}get deleted(){return(this.info&f.BIT3)>0}set deleted(e){this.deleted!==e&&(this.info^=f.BIT3)}markDeleted(){this.info|=f.BIT3}getMissing(e,t){if(this.origin&&this.origin.client!==this.id.client&&this.origin.clock>=de(t,this.origin.client))return this.origin.client;if(this.rightOrigin&&this.rightOrigin.client!==this.id.client&&this.rightOrigin.clock>=de(t,this.rightOrigin.client))return this.rightOrigin.client;if(this.parent&&this.parent.constructor===ne&&this.id.client!==this.parent.client&&this.parent.clock>=de(t,this.parent.client))return this.parent.client;if(this.origin&&(this.left=ye(e,t,this.origin),this.origin=this.left.lastId),this.rightOrigin&&(this.right=we(e,this.rightOrigin),this.rightOrigin=this.right.id),this.left&&this.left.constructor===Pt||this.right&&this.right.constructor===Pt)this.parent=null;else if(this.parent){if(this.parent.constructor===ne){const e=ge(t,this.parent);e.constructor===Pt?this.parent=null:this.parent=e.content.type}}else this.left&&this.left.constructor===ns?(this.parent=this.left.parent,this.parentSub=this.left.parentSub):this.right&&this.right.constructor===ns&&(this.parent=this.right.parent,this.parentSub=this.right.parentSub);return null}integrate(e,t){if(t>0&&(this.id.clock+=t,this.left=ye(e,e.doc.store,ie(this.id.client,this.id.clock-1)),this.origin=this.left.lastId,this.content=this.content.splice(t),this.length-=t),this.parent){if(!this.left&&(!this.right||null!==this.right.left)||this.left&&this.left.right!==this.right){let t,s=this.left;if(null!==s)t=s.right;else if(null!==this.parentSub)for(t=this.parent._map.get(this.parentSub)||null;null!==t&&null!==t.left;)t=t.left;else t=this.parent._start;const n=new Set,r=new Set;for(;null!==t&&t!==this.right;){if(r.add(t),n.add(t),re(this.origin,t.origin)){if(t.id.client<this.id.client)s=t,n.clear();else if(re(this.rightOrigin,t.rightOrigin))break}else{if(null===t.origin||!r.has(ge(e.doc.store,t.origin)))break;n.has(ge(e.doc.store,t.origin))||(s=t,n.clear())}t=t.right}this.left=s}if(null!==this.left){const e=this.left.right;this.right=e,this.left.right=this}else{let e;if(null!==this.parentSub)for(e=this.parent._map.get(this.parentSub)||null;null!==e&&null!==e.left;)e=e.left;else e=this.parent._start,this.parent._start=this;this.right=e}null!==this.right?this.right.left=this:null!==this.parentSub&&(this.parent._map.set(this.parentSub,this),null!==this.left&&this.left.delete(e)),null===this.parentSub&&this.countable&&!this.deleted&&(this.parent._length+=this.length),ue(e.doc.store,this),this.content.integrate(e,this),Se(e,this.parent,this.parentSub),(null!==this.parent._item&&this.parent._item.deleted||null!==this.parentSub&&null!==this.right)&&this.delete(e)}else new Pt(this.id,this.length).integrate(e,0)}get next(){let e=this.right;for(;null!==e&&e.deleted;)e=e.right;return e}get prev(){let e=this.left;for(;null!==e&&e.deleted;)e=e.left;return e}get lastId(){return 1===this.length?this.id:ie(this.id.client,this.id.clock+this.length-1)}mergeWith(e){if(this.constructor===e.constructor&&re(e.origin,this.lastId)&&this.right===e&&re(this.rightOrigin,e.rightOrigin)&&this.id.client===e.id.client&&this.id.clock+this.length===e.id.clock&&this.deleted===e.deleted&&null===this.redone&&null===e.redone&&this.content.constructor===e.content.constructor&&this.content.mergeWith(e.content)){const t=this.parent._searchMarker;return t&&t.forEach((t=>{t.p===e&&(t.p=this,!this.deleted&&this.countable&&(t.index-=this.length))})),e.keep&&(this.keep=!0),this.right=e.right,null!==this.right&&(this.right.left=this),this.length+=e.length,!0}return!1}delete(e){if(!this.deleted){const t=this.parent;this.countable&&null===this.parentSub&&(t._length-=this.length),this.markDeleted(),x(e.deleteSet,this.id.client,this.id.clock,this.length),Se(e,t,this.parentSub),this.content.delete(e)}}gc(e,t){if(!this.deleted)throw g.unexpectedCase();this.content.gc(e),t?((e,t,s)=>{const n=e.clients.get(t.id.client);n[pe(n,t.id.clock)]=s})(e,this,new Pt(this.id,this.length)):this.content=new Nt(this.length)}write(e,t){const s=t>0?ie(this.id.client,this.id.clock+t-1):this.origin,n=this.rightOrigin,r=this.parentSub,i=this.content.getRef()&f.BITS5|(null===s?0:f.BIT8)|(null===n?0:f.BIT7)|(null===r?0:f.BIT6);if(e.writeInfo(i),null!==s&&e.writeLeftID(s),null!==n&&e.writeRightID(n),null===s&&null===n){const t=this.parent;if(void 0!==t._item){const s=t._item;if(null===s){const s=(e=>{for(const[t,s]of e.doc.share.entries())if(s===e)return t;throw g.unexpectedCase()})(t);e.writeParentInfo(!0),e.writeString(s)}else e.writeParentInfo(!1),e.writeLeftID(s.id)}else t.constructor===String?(e.writeParentInfo(!0),e.writeString(t)):t.constructor===ne?(e.writeParentInfo(!1),e.writeLeftID(t)):g.unexpectedCase();null!==r&&e.writeString(r)}this.content.write(e,t)}}const rs=(e,t)=>is[t&f.BITS5](e),is=[()=>{g.unexpectedCase()},e=>new Nt(e.readLen()),e=>{const t=e.readLen(),s=[];for(let n=0;n<t;n++){const t=e.readString();"undefined"===t?s.push(void 0):s.push(JSON.parse(t))}return new Ht(s)},e=>new Bt(e.readBuf()),e=>new Gt(e.readString()),e=>new zt(e.readJSON()),e=>new Wt(e.readKey(),e.readJSON()),e=>new ts(Kt[e.readTypeRef()](e)),e=>{const t=e.readLen(),s=[];for(let n=0;n<t;n++)s.push(e.readAny());return new jt(s)},e=>new qt(Lt(e.readString(),e.readAny())),()=>{g.unexpectedCase()}];class os extends Ot{get deleted(){return!0}delete(){}mergeWith(e){return this.constructor===e.constructor&&(this.length+=e.length,!0)}integrate(e,t){g.unexpectedCase()}write(e,t){e.writeInfo(10),h.writeVarUint(e.restEncoder,this.length-t)}getMissing(e,t){return null}}const cs="undefined"!=typeof globalThis?globalThis:"undefined"!=typeof window?window:void 0!==t?t:{},as="__ $YJS$ __";!0===cs[as]&&console.error("Yjs was already imported. This breaks constructor checks and will lead to issues! - https://github.com/yjs/yjs/issues/438"),cs[as]=!0})),s.register("8Gyr5",(function(t,n){e(t.exports,"ObservableV2",(()=>c)),e(t.exports,"Observable",(()=>a));var r=s("96q9T"),i=s("5zT0w"),o=s("9GMWx");class c{constructor(){this._observers=r.create()}on(e,t){return r.setIfUndefined(this._observers,e,i.create).add(t),t}once(e,t){const s=(...n)=>{this.off(e,s),t(...n)};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 o.from((this._observers.get(e)||r.create()).values()).forEach((e=>e(...t)))}destroy(){this._observers=r.create()}}class a{constructor(){this._observers=r.create()}on(e,t){r.setIfUndefined(this._observers,e,i.create).add(t)}once(e,t){const s=(...n)=>{this.off(e,s),t(...n)};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 o.from((this._observers.get(e)||r.create()).values()).forEach((e=>e(...t)))}destroy(){this._observers=r.create()}}})),s.register("96q9T",(function(t,s){e(t.exports,"create",(()=>n)),e(t.exports,"copy",(()=>r)),e(t.exports,"setIfUndefined",(()=>i)),e(t.exports,"map",(()=>o)),e(t.exports,"any",(()=>c));const n=()=>new Map,r=e=>{const t=n();return e.forEach(((e,s)=>{t.set(s,e)})),t},i=(e,t,s)=>{let n=e.get(t);return void 0===n&&e.set(t,n=s()),n},o=(e,t)=>{const s=[];for(const[n,r]of e)s.push(t(r,n));return s},c=(e,t)=>{for(const[s,n]of e)if(t(n,s))return!0;return!1}})),s.register("5zT0w",(function(t,s){e(t.exports,"create",(()=>n)),e(t.exports,"from",(()=>r));const n=()=>new Set,r=e=>new Set(e)})),s.register("9GMWx",(function(t,n){e(t.exports,"last",(()=>r)),e(t.exports,"appendTo",(()=>i)),e(t.exports,"from",(()=>o)),e(t.exports,"some",(()=>c)),e(t.exports,"equalFlat",(()=>a)),e(t.exports,"unfold",(()=>h)),e(t.exports,"isArray",(()=>l)),e(t.exports,"map",(()=>d)),s("5zT0w");const r=e=>e[e.length-1],i=(e,t)=>{for(let s=0;s<t.length;s++)e.push(t[s])},o=Array.from,c=(e,t)=>{for(let s=0;s<e.length;s++)if(t(e[s],s,e))return!0;return!1},a=(e,t)=>e.length===t.length&&((e,t)=>{for(let s=0;s<e.length;s++)if(!t(e[s],s))return!1;return!0})(e,((e,s)=>e===t[s])),h=(e,t)=>{const s=new Array(e);for(let n=0;n<e;n++)s[n]=t(n,s);return s},l=Array.isArray,d=(e,t)=>{const s=Array(e.length);for(let n=0;n<e.length;n++)s[n]=t(e[n],n,e);return s}})),s.register("bGsfJ",(function(t,s){e(t.exports,"floor",(()=>n)),e(t.exports,"ceil",(()=>r)),e(t.exports,"abs",(()=>i)),e(t.exports,"round",(()=>o)),e(t.exports,"log10",(()=>c)),e(t.exports,"min",(()=>a)),e(t.exports,"max",(()=>h)),e(t.exports,"exp10",(()=>l)),e(t.exports,"isNegativeZero",(()=>d));const n=Math.floor,r=Math.ceil,i=Math.abs,o=(Math.imul,Math.round),c=Math.log10,a=(Math.log2,Math.log,Math.sqrt,(e,t)=>e<t?e:t),h=(e,t)=>e>t?e:t,l=(Number.isNaN,Math.pow,e=>Math.pow(10,e)),d=(Math.sign,e=>0!==e?e<0:1/e<0)})),s.register("7BTJz",(function(t,n){e(t.exports,"createEncoder",(()=>l)),e(t.exports,"encode",(()=>d)),e(t.exports,"toUint8Array",(()=>p)),e(t.exports,"length",(()=>u)),e(t.exports,"write",(()=>g)),e(t.exports,"writeUint8",(()=>f)),e(t.exports,"writeVarUint",(()=>w)),e(t.exports,"writeVarInt",(()=>y)),e(t.exports,"writeVarUint8Array",(()=>v)),e(t.exports,"writeVarString",(()=>b)),e(t.exports,"writeBinaryEncoder",(()=>S)),e(t.exports,"writeUint8Array",(()=>k)),e(t.exports,"writeAny",(()=>C)),e(t.exports,"RleEncoder",(()=>U)),e(t.exports,"UintOptRleEncoder",(()=>x)),e(t.exports,"IntDiffOptRleEncoder",(()=>E)),e(t.exports,"StringEncoder",(()=>R));var r=s("bGsfJ"),i=s("5es75"),o=s("bcXZT"),c=s("8drkQ"),a=s("9GMWx");class h{constructor(){this.cpos=0,this.cbuf=new Uint8Array(100),this.bufs=[]}}const l=()=>new h,d=e=>{const t=l();return e(t),p(t)},u=e=>{let t=e.cpos;for(let s=0;s<e.bufs.length;s++)t+=e.bufs[s].length;return t},p=e=>{const t=new Uint8Array(u(e));let s=0;for(let n=0;n<e.bufs.length;n++){const r=e.bufs[n];t.set(r,s),s+=r.length}return t.set(new Uint8Array(e.cbuf.buffer,0,e.cpos),s),t},g=(e,t)=>{const s=e.cbuf.length;e.cpos===s&&(e.bufs.push(e.cbuf),e.cbuf=new Uint8Array(2*s),e.cpos=0),e.cbuf[e.cpos++]=t},f=g,w=(e,t)=>{for(;t>o.BITS7;)g(e,o.BIT8|o.BITS7&t),t=r.floor(t/128);g(e,o.BITS7&t)},y=(e,t)=>{const s=r.isNegativeZero(t);for(s&&(t=-t),g(e,(t>o.BITS6?o.BIT8:0)|(s?o.BIT7:0)|o.BITS6&t),t=r.floor(t/64);t>0;)g(e,(t>o.BITS7?o.BIT8:0)|o.BITS7&t),t=r.floor(t/128)},_=new Uint8Array(3e4),m=_.length/3,b=c.utf8TextEncoder&&c.utf8TextEncoder.encodeInto?(e,t)=>{if(t.length<m){const s=c.utf8TextEncoder.encodeInto(t,_).written||0;w(e,s);for(let t=0;t<s;t++)g(e,_[t])}else v(e,c.encodeUtf8(t))}:(e,t)=>{const s=unescape(encodeURIComponent(t)),n=s.length;w(e,n);for(let t=0;t<n;t++)g(e,s.codePointAt(t))},S=(e,t)=>k(e,p(t)),k=(e,t)=>{const s=e.cbuf.length,n=e.cpos,i=r.min(s-n,t.length),o=t.length-i;e.cbuf.set(t.subarray(0,i),n),e.cpos+=i,o>0&&(e.bufs.push(e.cbuf),e.cbuf=new Uint8Array(r.max(2*s,o)),e.cbuf.set(t.subarray(i)),e.cpos=o)},v=(e,t)=>{w(e,t.byteLength),k(e,t)},A=(e,t)=>{((e,t)=>{const s=e.cbuf.length;s-e.cpos<t&&(e.bufs.push(new Uint8Array(e.cbuf.buffer,0,e.cpos)),e.cbuf=new Uint8Array(2*r.max(s,t)),e.cpos=0)})(e,t);const s=new DataView(e.cbuf.buffer,e.cpos,t);return e.cpos+=t,s},T=new DataView(new ArrayBuffer(4)),C=(e,t)=>{switch(typeof t){case"string":g(e,119),b(e,t);break;case"number":i.isInteger(t)&&r.abs(t)<=o.BITS31?(g(e,125),y(e,t)):(s=t,T.setFloat32(0,s),T.getFloat32(0)===s?(g(e,124),((e,t)=>{A(e,4).setFloat32(0,t,!1)})(e,t)):(g(e,123),((e,t)=>{A(e,8).setFloat64(0,t,!1)})(e,t)));break;case"bigint":g(e,122),((e,t)=>{A(e,8).setBigInt64(0,t,!1)})(e,t);break;case"object":if(null===t)g(e,126);else if(a.isArray(t)){g(e,117),w(e,t.length);for(let s=0;s<t.length;s++)C(e,t[s])}else if(t instanceof Uint8Array)g(e,116),v(e,t);else{g(e,118);const s=Object.keys(t);w(e,s.length);for(let n=0;n<s.length;n++){const r=s[n];b(e,r),C(e,t[r])}}break;case"boolean":g(e,t?120:121);break;default:g(e,127)}var s};class U extends h{constructor(e){super(),this.w=e,this.s=null,this.count=0}write(e){this.s===e?this.count++:(this.count>0&&w(this,this.count-1),this.count=1,this.w(this,e),this.s=e)}}const I=e=>{e.count>0&&(y(e.encoder,1===e.count?e.s:-e.s),e.count>1&&w(e.encoder,e.count-2))};class x{constructor(){this.encoder=new h,this.s=0,this.count=0}write(e){this.s===e?this.count++:(I(this),this.count=1,this.s=e)}toUint8Array(){return I(this),p(this.encoder)}}const D=e=>{if(e.count>0){const t=2*e.diff+(1===e.count?0:1);y(e.encoder,t),e.count>1&&w(e.encoder,e.count-2)}};class E{constructor(){this.encoder=new h,this.s=0,this.count=0,this.diff=0}write(e){this.diff===e-this.s?(this.s=e,this.count++):(D(this),this.count=1,this.diff=e-this.s,this.s=e)}toUint8Array(){return D(this),p(this.encoder)}}class R{constructor(){this.sarr=[],this.s="",this.lensE=new x}write(e){this.s+=e,this.s.length>19&&(this.sarr.push(this.s),this.s=""),this.lensE.write(e.length)}toUint8Array(){const e=new h;return this.sarr.push(this.s),this.s="",b(e,this.sarr.join("")),k(e,this.lensE.toUint8Array()),p(e)}}})),s.register("5es75",(function(t,n){e(t.exports,"MAX_SAFE_INTEGER",(()=>o)),e(t.exports,"isInteger",(()=>c));var r=s("bGsfJ"),i=s("bcXZT");const o=Number.MAX_SAFE_INTEGER,c=(Number.MIN_SAFE_INTEGER,i.BITS31,i.BITS32,Number.isInteger||(e=>"number"==typeof e&&isFinite(e)&&r.floor(e)===e));Number.isNaN,Number.parseInt})),s.register("bcXZT",(function(t,s){e(t.exports,"BIT1",(()=>n)),e(t.exports,"BIT2",(()=>r)),e(t.exports,"BIT3",(()=>i)),e(t.exports,"BIT4",(()=>o)),e(t.exports,"BIT6",(()=>c)),e(t.exports,"BIT7",(()=>a)),e(t.exports,"BIT8",(()=>h)),e(t.exports,"BITS5",(()=>l)),e(t.exports,"BITS6",(()=>d)),e(t.exports,"BITS7",(()=>u)),e(t.exports,"BITS8",(()=>p)),e(t.exports,"BITS21",(()=>g)),e(t.exports,"BITS31",(()=>f)),e(t.exports,"BITS32",(()=>w));const n=1,r=2,i=4,o=8,c=32,a=64,h=128,l=31,d=63,u=127,p=255,g=2097151,f=2147483647,w=4294967295})),s.register("8drkQ",(function(t,n){e(t.exports,"fromCharCode",(()=>i)),e(t.exports,"fromCamelCase",(()=>a)),e(t.exports,"utf8TextEncoder",(()=>h)),e(t.exports,"encodeUtf8",(()=>l)),e(t.exports,"utf8TextDecoder",(()=>d)),e(t.exports,"decodeUtf8",(()=>u)),e(t.exports,"repeat",(()=>p));var r=s("9GMWx");const i=String.fromCharCode,o=(String.fromCodePoint,i(65535),/^\s*/g),c=/([A-Z])/g,a=(e,t)=>(e=>e.replace(o,""))(e.replace(c,(e=>`${t}${(e=>e.toLowerCase())(e)}`))),h="undefined"!=typeof TextEncoder?new TextEncoder:null,l=h?e=>h.encode(e):e=>{const t=unescape(encodeURIComponent(e)),s=t.length,n=new Uint8Array(s);for(let e=0;e<s;e++)n[e]=t.codePointAt(e);return n};let d="undefined"==typeof TextDecoder?null:new TextDecoder("utf-8",{fatal:!0,ignoreBOM:!0});d&&1===d.decode(new Uint8Array).length&&(d=null);const u=d?e=>d.decode(e):e=>{let t=e.length,s="",n=0;for(;t>0;){const r=t<1e4?t:1e4,i=e.subarray(n,n+r);n+=r,s+=String.fromCodePoint.apply(null,i),t-=r}return decodeURIComponent(escape(s))},p=(e,t)=>r.unfold(t,(()=>e)).join("")})),s.register("l5188",(function(t,n){e(t.exports,"createDecoder",(()=>u)),e(t.exports,"hasContent",(()=>p)),e(t.exports,"clone",(()=>g)),e(t.exports,"readVarUint8Array",(()=>f)),e(t.exports,"readVarUint",(()=>y)),e(t.exports,"readUint8",(()=>w)),e(t.exports,"readVarInt",(()=>_)),e(t.exports,"readVarString",(()=>m)),e(t.exports,"readAny",(()=>k)),e(t.exports,"RleDecoder",(()=>v)),e(t.exports,"UintOptRleDecoder",(()=>A)),e(t.exports,"IntDiffOptRleDecoder",(()=>T)),e(t.exports,"StringDecoder",(()=>C));var r=s("bcXZT"),i=s("bGsfJ"),o=s("5es75"),c=s("8drkQ"),a=s("3Y8uz");s("7BTJz");const h=a.create("Unexpected end of array"),l=a.create("Integer out of Range");class d{constructor(e){this.arr=e,this.pos=0}}const u=e=>new d(e),p=e=>e.pos!==e.arr.length,g=(e,t=e.pos)=>{const s=u(e.arr);return s.pos=t,s},f=e=>((e,t)=>{const s=new Uint8Array(e.arr.buffer,e.pos+e.arr.byteOffset,t);return e.pos+=t,s})(e,y(e)),w=e=>e.arr[e.pos++],y=e=>{let t=0,s=1;const n=e.arr.length;for(;e.pos<n;){const n=e.arr[e.pos++];if(t+=(n&r.BITS7)*s,s*=128,n<r.BIT8)return t;if(t>o.MAX_SAFE_INTEGER)throw l}throw h},_=e=>{let t=e.arr[e.pos++],s=t&r.BITS6,n=64;const i=(t&r.BIT7)>0?-1:1;if(!(t&r.BIT8))return i*s;const c=e.arr.length;for(;e.pos<c;){if(t=e.arr[e.pos++],s+=(t&r.BITS7)*n,n*=128,t<r.BIT8)return i*s;if(s>o.MAX_SAFE_INTEGER)throw l}throw h},m=c.utf8TextDecoder?e=>c.utf8TextDecoder.decode(f(e)):e=>{let t=y(e);if(0===t)return"";{let s=String.fromCodePoint(w(e));if(--t<100)for(;t--;)s+=String.fromCodePoint(w(e));else for(;t>0;){const n=t<1e4?t:1e4,r=e.arr.subarray(e.pos,e.pos+n);e.pos+=n,s+=String.fromCodePoint.apply(null,r),t-=n}return decodeURIComponent(escape(s))}},b=(e,t)=>{const s=new DataView(e.arr.buffer,e.arr.byteOffset+e.pos,t);return e.pos+=t,s},S=[e=>{},e=>null,_,e=>b(e,4).getFloat32(0,!1),e=>b(e,8).getFloat64(0,!1),e=>b(e,8).getBigInt64(0,!1),e=>!1,e=>!0,m,e=>{const t=y(e),s={};for(let n=0;n<t;n++)s[m(e)]=k(e);return s},e=>{const t=y(e),s=[];for(let n=0;n<t;n++)s.push(k(e));return s},f],k=e=>S[127-w(e)](e);class v extends d{constructor(e,t){super(e),this.reader=t,this.s=null,this.count=0}read(){return 0===this.count&&(this.s=this.reader(this),p(this)?this.count=y(this)+1:this.count=-1),this.count--,this.s}}class A extends d{constructor(e){super(e),this.s=0,this.count=0}read(){if(0===this.count){this.s=_(this);const e=i.isNegativeZero(this.s);this.count=1,e&&(this.s=-this.s,this.count=y(this)+2)}return this.count--,this.s}}class T extends d{constructor(e){super(e),this.s=0,this.count=0,this.diff=0}read(){if(0===this.count){const e=_(this),t=1&e;this.diff=i.floor(e/2),this.count=1,t&&(this.count=y(this)+2)}return this.s+=this.diff,this.count--,this.s}}class C{constructor(e){this.decoder=new A(e),this.str=m(this.decoder),this.spos=0}read(){const e=this.spos+this.decoder.read(),t=this.str.slice(this.spos,e);return this.spos=e,t}}})),s.register("3Y8uz",(function(t,s){e(t.exports,"create",(()=>n)),e(t.exports,"methodUnimplemented",(()=>r)),e(t.exports,"unexpectedCase",(()=>i));const n=e=>new Error(e),r=()=>{throw n("Method unimplemented")},i=()=>{throw n("Unexpected case")}})),s.register("ouOhr",(function(t,n){e(t.exports,"uint32",(()=>i)),e(t.exports,"uuidv4",(()=>o)),s("bGsfJ"),s("bcXZT");var r=s("2grmT");Math.random;const i=()=>(0,r.getRandomValues)(new Uint32Array(1))[0],o=()=>"10000000-1000-4000-8000-100000000000".replace(/[018]/g,(e=>(e^i()&15>>e/4).toString(16)))})),s.register("2grmT",(function(t,s){e(t.exports,"getRandomValues",(()=>n)),crypto.subtle;const n=crypto.getRandomValues.bind(crypto)})),s.register("fJEwH",(function(t,n){e(t.exports,"create",(()=>r)),s("16gRh");const r=e=>new Promise(e);Promise.all.bind(Promise)})),s.register("16gRh",(function(t,n){e(t.exports,"getUnixTime",(()=>r)),s("cdEUL"),s("bGsfJ");const r=Date.now})),s.register("cdEUL",(function(t,n){e(t.exports,"prefix",(()=>c));var r=s("bGsfJ");const i=["","k","M","G","T","P","E","Z","Y"],o=["","m","μ","n","p","f","a","z","y"],c=(e,t=0)=>{const s=0===e?0:r.log10(e);let n=0;for(;s<3*n&&t>-8;)t--,n--;for(;s>=3+3*n&&t<8;)t++,n++;const c=t<0?o[-t]:i[t];return{n:r.round(1e12*(n>0?e/r.exp10(3*n):e*r.exp10(-3*n)))/1e12,prefix:c}}})),s.register("jx2H5",(function(t,n){e(t.exports,"createUint8ArrayFromArrayBuffer",(()=>a)),e(t.exports,"toBase64",(()=>h)),e(t.exports,"fromBase64",(()=>l)),e(t.exports,"copyUint8Array",(()=>d));var r=s("8drkQ"),i=s("isVtz"),o=(s("9GMWx"),s("bGsfJ"),s("7BTJz"),s("l5188"),s("laHbQ").Buffer);const c=e=>new Uint8Array(e),a=e=>new Uint8Array(e),h=i.isBrowser?e=>{let t="";for(let s=0;s<e.byteLength;s++)t+=r.fromCharCode(e[s]);return btoa(t)}:e=>o.from(e.buffer,e.byteOffset,e.byteLength).toString("base64"),l=i.isBrowser?e=>{const t=atob(e),s=c(t.length);for(let e=0;e<t.length;e++)s[e]=t.charCodeAt(e);return s}:e=>{const t=o.from(e,"base64");return s=t.buffer,n=t.byteOffset,r=t.byteLength,new Uint8Array(s,n,r);var s,n,r},d=e=>{const t=c(e.byteLength);return t.set(e),t}})),s.register("isVtz",(function(t,n){e(t.exports,"isBrowser",(()=>d)),e(t.exports,"getVariable",(()=>f)),e(t.exports,"supportsColor",(()=>y));var r=s("96q9T"),i=s("8drkQ"),o=s("9xF6A"),c=s("hpXBJ"),a=s("4H1bc"),h=s("b3MRX");const l=void 0!==h&&h.release&&/node|io\.js/.test(h.release.name)&&"[object process]"===Object.prototype.toString.call(void 0!==h?h:0),d="undefined"!=typeof window&&"undefined"!=typeof document&&!l;let u;"undefined"!=typeof navigator&&/Mac/.test(navigator.platform);const p=[],g=e=>(()=>{if(void 0===u)if(l){u=r.create();const e=h.argv;let t=null;for(let s=0;s<e.length;s++){const n=e[s];"-"===n[0]?(null!==t&&u.set(t,""),t=n):null!==t?(u.set(t,n),t=null):p.push(n)}null!==t&&u.set(t,"")}else"object"==typeof location?(u=r.create(),(location.search||"?").slice(1).split("&").forEach((e=>{if(0!==e.length){const[t,s]=e.split("=");u.set(`--${i.fromCamelCase(t,"-")}`,s),u.set(`-${i.fromCamelCase(t,"-")}`,s)}}))):u=r.create();return u})().has(e),f=e=>l?o.undefinedToNull(h.env[e.toUpperCase().replaceAll("-","_")]):o.undefinedToNull(c.varStorage.getItem(e)),w=e=>g("--"+e)||null!==f(e),y=(w("production"),l&&a.isOneOf(void 0,["true","1","2"])||!g("--no-colors")&&!w("no-color")&&(!l||h.stdout.isTTY)&&(!l||g("--color")||null!==f("COLORTERM")||(f("TERM")||"").includes("color")))})),s.register("9xF6A",(function(t,s){e(t.exports,"undefinedToNull",(()=>n));const n=e=>void 0===e?null:e})),s.register("hpXBJ",(function(t,s){e(t.exports,"varStorage",(()=>i)),e(t.exports,"onChange",(()=>o)),e(t.exports,"offChange",(()=>c));let n=new class{constructor(){this.map=new Map}setItem(e,t){this.map.set(e,t)}getItem(e){return this.map.get(e)}},r=!0;try{"undefined"!=typeof localStorage&&localStorage&&(n=localStorage,r=!1)}catch(e){}const i=n,o=e=>r||addEventListener("storage",e),c=e=>r||removeEventListener("storage",e)})),s.register("4H1bc",(function(t,n){e(t.exports,"callAll",(()=>c)),e(t.exports,"nop",(()=>a)),e(t.exports,"id",(()=>h)),e(t.exports,"equalityDeep",(()=>l)),e(t.exports,"isOneOf",(()=>d));var r=s("9GMWx"),i=s("7C9F2"),o=s("aeA7S");const c=(e,t,s=0)=>{try{for(;s<e.length;s++)e[s](...t)}finally{s<e.length&&c(e,t,s+1)}},a=()=>{},h=e=>e,l=(e,t)=>{if(e===t)return!0;if(null==e||null==t||e.constructor!==t.constructor)return!1;if(null!=e[o.EqualityTraitSymbol])return e[o.EqualityTraitSymbol](t);switch(e.constructor){case ArrayBuffer:e=new Uint8Array(e),t=new Uint8Array(t);case Uint8Array:if(e.byteLength!==t.byteLength)return!1;for(let s=0;s<e.length;s++)if(e[s]!==t[s])return!1;break;case Set:if(e.size!==t.size)return!1;for(const s of e)if(!t.has(s))return!1;break;case Map:if(e.size!==t.size)return!1;for(const s of e.keys())if(!t.has(s)||!l(e.get(s),t.get(s)))return!1;break;case Object:if(i.length(e)!==i.length(t))return!1;for(const s in e)if(!i.hasProperty(e,s)||!l(e[s],t[s]))return!1;break;case Array:if(e.length!==t.length)return!1;for(let s=0;s<e.length;s++)if(!l(e[s],t[s]))return!1;break;default:return!1}return!0},d=(e,t)=>t.includes(e);r.isArray})),s.register("7C9F2",(function(t,s){e(t.exports,"assign",(()=>n)),e(t.exports,"forEach",(()=>i)),e(t.exports,"length",(()=>o)),e(t.exports,"isEmpty",(()=>a)),e(t.exports,"hasProperty",(()=>h)),e(t.exports,"equalFlat",(()=>l)),e(t.exports,"deepFreeze",(()=>u));const n=Object.assign,r=Object.keys,i=(Object.values,(e,t)=>{for(const s in e)t(e[s],s)}),o=e=>r(e).length,c=e=>r(e).length,a=e=>{for(const t in e)return!1;return!0},h=(e,t)=>Object.prototype.hasOwnProperty.call(e,t),l=(e,t)=>e===t||c(e)===c(t)&&((e,t)=>{for(const s in e)if(!t(e[s],s))return!1;return!0})(e,((e,s)=>(void 0!==e||h(t,s))&&t[s]===e)),d=Object.freeze,u=e=>{for(const t in e){const s=e[t];"object"!=typeof s&&"function"!=typeof s||u(e[t])}return d(e)}})),s.register("aeA7S",(function(t,s){e(t.exports,"EqualityTraitSymbol",(()=>n));const n=Symbol("Equality")})),s.register("9hwjE",(function(t,n){e(t.exports,"print",(()=>u)),e(t.exports,"warn",(()=>p)),e(t.exports,"BOLD",(()=>s("9okbY").BOLD)),e(t.exports,"UNBOLD",(()=>s("9okbY").UNBOLD)),e(t.exports,"RED",(()=>s("9okbY").RED)),e(t.exports,"ORANGE",(()=>s("9okbY").ORANGE));var r=s("isVtz"),i=s("5zT0w"),o=s("2djb1"),c=s("8kkbA"),a=(s("kQNaO"),s("96q9T")),h=(s("kdpDU"),s("bGsfJ"),s("9okbY"));h=s("9okbY");const l={[h.BOLD]:o.create("font-weight","bold"),[h.UNBOLD]:o.create("font-weight","normal"),[h.BLUE]:o.create("color","blue"),[h.GREEN]:o.create("color","green"),[h.GREY]:o.create("color","grey"),[h.RED]:o.create("color","red"),[h.PURPLE]:o.create("color","purple"),[h.ORANGE]:o.create("color","orange"),[h.UNCOLOR]:o.create("color","black")},d=r.supportsColor?e=>{1===e.length&&e[0]?.constructor===Function&&(e=e[0]());const t=[],s=[],n=a.create();let r=[],i=0;for(;i<e.length;i++){const r=e[i],o=l[r];if(void 0!==o)n.set(o.left,o.right);else{if(void 0===r)break;if(r.constructor!==String&&r.constructor!==Number)break;{const e=c.mapToStyleString(n);i>0||e.length>0?(t.push("%c"+r),s.push(e)):t.push(r)}}}for(i>0&&(r=s,r.unshift(t.join("")));i<e.length;i++){const t=e[i];t instanceof Symbol||r.push(t)}return r}:h.computeNoColorLoggingArgs,u=(...e)=>{console.log(...d(e)),g.forEach((t=>t.print(e)))},p=(...e)=>{console.warn(...d(e)),e.unshift(h.ORANGE),g.forEach((t=>t.print(e)))},g=i.create()})),s.register("2djb1",(function(t,s){e(t.exports,"create",(()=>r)),e(t.exports,"forEach",(()=>i));class n{constructor(e,t){this.left=e,this.right=t}}const r=(e,t)=>new n(e,t),i=(e,t)=>e.forEach((e=>t(e.left,e.right)))})),s.register("8kkbA",(function(t,n){e(t.exports,"append",(()=>a)),e(t.exports,"addEventListener",(()=>h)),e(t.exports,"element",(()=>l)),e(t.exports,"text",(()=>d)),e(t.exports,"mapToStyleString",(()=>u));var r=s("2djb1"),i=s("96q9T");const o="undefined"!=typeof document?document:{},c=("undefined"!=typeof DOMParser&&new DOMParser,e=>{const t=o.createDocumentFragment();for(let s=0;s<e.length;s++)p(t,e[s]);return t}),a=(e,t)=>(p(e,c(t)),e),h=(e,t,s)=>e.addEventListener(t,s),l=(e,t=[],s=[])=>a(((e,t)=>(r.forEach(t,((t,s)=>{!1===s?e.removeAttribute(t):!0===s?e.setAttribute(t,""):e.setAttribute(t,s)})),e))((e=>o.createElement(e))(e),t),s),d=e=>o.createTextNode(e),u=e=>i.map(e,((e,t)=>`${t}:${e};`)).join(""),p=(e,t)=>e.appendChild(t);o.ELEMENT_NODE,o.TEXT_NODE,o.CDATA_SECTION_NODE,o.COMMENT_NODE,o.DOCUMENT_NODE,o.DOCUMENT_TYPE_NODE,o.DOCUMENT_FRAGMENT_NODE})),s.register("kQNaO",(function(t,s){e(t.exports,"stringify",(()=>n));const n=JSON.stringify;JSON.parse})),s.register("kdpDU",(function(t,n){e(t.exports,"enqueue",(()=>o)),s("16gRh");let r=[];const i=()=>{for(let e=0;e<r.length;e++)r[e]();r=[]},o=e=>{r.push(e),1===r.length&&setTimeout(i,0)},c=e=>class{constructor(e){this._=e}destroy(){e(this._)}};c(clearTimeout),c(clearInterval),c((e=>"undefined"!=typeof requestAnimationFrame&&cancelAnimationFrame(e))),c((e=>"undefined"!=typeof cancelIdleCallback&&cancelIdleCallback(e)))})),s.register("9okbY",(function(t,n){e(t.exports,"BOLD",(()=>h)),e(t.exports,"UNBOLD",(()=>l)),e(t.exports,"BLUE",(()=>d)),e(t.exports,"GREY",(()=>u)),e(t.exports,"GREEN",(()=>p)),e(t.exports,"RED",(()=>g)),e(t.exports,"PURPLE",(()=>f)),e(t.exports,"ORANGE",(()=>w)),e(t.exports,"UNCOLOR",(()=>y)),e(t.exports,"computeNoColorLoggingArgs",(()=>_)),e(t.exports,"createModuleLogger",(()=>k));var r=s("9Juxm"),i=s("16gRh"),o=s("isVtz"),c=s("4H1bc"),a=s("kQNaO");const h=r.create(),l=r.create(),d=r.create(),u=r.create(),p=r.create(),g=r.create(),f=r.create(),w=r.create(),y=r.create(),_=e=>{1===e.length&&e[0]?.constructor===Function&&(e=e[0]());const t=[],s=[];let n=0;for(;n<e.length;n++){const s=e[n];if(void 0===s)break;if(s.constructor===String||s.constructor===Number)t.push(s);else if(s.constructor===Object)break}for(n>0&&s.push(t.join(""));n<e.length;n++){const t=e[n];t instanceof Symbol||s.push(t)}return s},m=[p,f,w,d];let b=0,S=i.getUnixTime();const k=(e,t)=>{const s=m[b],n=o.getVariable("log"),r=null!==n&&("*"===n||"true"===n||new RegExp(n,"gi").test(t));return b=(b+1)%m.length,t+=": ",r?(...n)=>{1===n.length&&n[0]?.constructor===Function&&(n=n[0]());const r=i.getUnixTime(),o=r-S;S=r,e(s,t,y,...n.map((e=>{switch(null!=e&&e.constructor===Uint8Array&&(e=Array.from(e)),typeof e){case"string":case"symbol":return e;default:return a.stringify(e)}})),s," +"+o+"ms")}:c.nop}})),s.register("9Juxm",(function(t,s){e(t.exports,"create",(()=>n));const n=Symbol})),s.register("iRxFz",(function(t,s){e(t.exports,"iteratorFilter",(()=>r)),e(t.exports,"iteratorMap",(()=>i));const n=e=>({[Symbol.iterator](){return this},next:e}),r=(e,t)=>n((()=>{let s;do{s=e.next()}while(!s.done&&!t(s.value));return s})),i=(e,t)=>n((()=>{const{done:s,value:n}=e.next();return{done:s,value:s?void 0:t(n)}}))})),s.register("4AWOh",(function(t,n){e(t.exports,"Awareness",(()=>l)),e(t.exports,"removeAwarenessStates",(()=>d)),e(t.exports,"encodeAwarenessUpdate",(()=>u)),e(t.exports,"applyAwarenessUpdate",(()=>p));var r=s("7BTJz"),i=s("l5188"),o=s("16gRh"),c=s("bGsfJ"),a=s("8Gyr5"),h=s("4H1bc");class l extends a.Observable{constructor(e){super(),this.doc=e,this.clientID=e.clientID,this.states=new Map,this.meta=new Map,this._checkInterval=setInterval((()=>{const e=o.getUnixTime();null!==this.getLocalState()&&15e3<=e-this.meta.get(this.clientID).lastUpdated&&this.setLocalState(this.getLocalState());const t=[];this.meta.forEach(((s,n)=>{n!==this.clientID&&3e4<=e-s.lastUpdated&&this.states.has(n)&&t.push(n)})),t.length>0&&d(this,t,"timeout")}),c.floor(3e3)),e.on("destroy",(()=>{this.destroy()})),this.setLocalState({})}destroy(){this.emit("destroy",[this]),this.setLocalState(null),super.destroy(),clearInterval(this._checkInterval)}getLocalState(){return this.states.get(this.clientID)||null}setLocalState(e){const t=this.clientID,s=this.meta.get(t),n=void 0===s?0:s.clock+1,r=this.states.get(t);null===e?this.states.delete(t):this.states.set(t,e),this.meta.set(t,{clock:n,lastUpdated:o.getUnixTime()});const i=[],c=[],a=[],l=[];null===e?l.push(t):null==r?null!=e&&i.push(t):(c.push(t),h.equalityDeep(r,e)||a.push(t)),(i.length>0||a.length>0||l.length>0)&&this.emit("change",[{added:i,updated:a,removed:l},"local"]),this.emit("update",[{added:i,updated:c,removed:l},"local"])}setLocalStateField(e,t){const s=this.getLocalState();null!==s&&this.setLocalState({...s,[e]:t})}getStates(){return this.states}}const d=(e,t,s)=>{const n=[];for(let s=0;s<t.length;s++){const r=t[s];if(e.states.has(r)){if(e.states.delete(r),r===e.clientID){const t=e.meta.get(r);e.meta.set(r,{clock:t.clock+1,lastUpdated:o.getUnixTime()})}n.push(r)}}n.length>0&&(e.emit("change",[{added:[],updated:[],removed:n},s]),e.emit("update",[{added:[],updated:[],removed:n},s]))},u=(e,t,s=e.states)=>{const n=t.length,i=r.createEncoder();r.writeVarUint(i,n);for(let o=0;o<n;o++){const n=t[o],c=s.get(n)||null,a=e.meta.get(n).clock;r.writeVarUint(i,n),r.writeVarUint(i,a),r.writeVarString(i,JSON.stringify(c))}return r.toUint8Array(i)},p=(e,t,s)=>{const n=i.createDecoder(t),r=o.getUnixTime(),c=[],a=[],l=[],d=[],u=i.readVarUint(n);for(let t=0;t<u;t++){const t=i.readVarUint(n);let s=i.readVarUint(n);const o=JSON.parse(i.readVarString(n)),u=e.meta.get(t),p=e.states.get(t),g=void 0===u?0:u.clock;(g<s||g===s&&null===o&&e.states.has(t))&&(null===o?t===e.clientID&&null!=e.getLocalState()?s++:e.states.delete(t):e.states.set(t,o),e.meta.set(t,{clock:s,lastUpdated:r}),void 0===u&&null!==o?c.push(t):void 0!==u&&null===o?d.push(t):null!==o&&(h.equalityDeep(o,p)||l.push(t),a.push(t)))}(c.length>0||l.length>0||d.length>0)&&e.emit("change",[{added:c,updated:l,removed:d},s]),(c.length>0||a.length>0||d.length>0)&&e.emit("update",[{added:c,updated:a,removed:d},s])}})),s.register("kRCFI",(function(t,n){e(t.exports,"messageYjsSyncStep1",(()=>c)),e(t.exports,"messageYjsSyncStep2",(()=>a)),e(t.exports,"messageYjsUpdate",(()=>h)),e(t.exports,"writeSyncStep1",(()=>l)),e(t.exports,"writeSyncStep2",(()=>d)),e(t.exports,"writeUpdate",(()=>p)),e(t.exports,"readSyncMessage",(()=>f));var r=s("7BTJz"),i=s("l5188"),o=s("bx9uf");const c=0,a=1,h=2,l=(e,t)=>{r.writeVarUint(e,c);const s=o.encodeStateVector(t);r.writeVarUint8Array(e,s)},d=(e,t,s)=>{r.writeVarUint(e,a),r.writeVarUint8Array(e,o.encodeStateAsUpdate(t,s))},u=(e,t,s,n)=>{try{o.applyUpdate(t,i.readVarUint8Array(e),s)}catch(e){null!=n&&n(e),console.error("Caught error while handling a Yjs update",e)}},p=(e,t)=>{r.writeVarUint(e,h),r.writeVarUint8Array(e,t)},g=u,f=(e,t,s,n,r)=>{const o=i.readVarUint(e);switch(o){case c:((e,t,s)=>{d(t,s,i.readVarUint8Array(e))})(e,t,s);break;case a:u(e,s,n,r);break;case h:g(e,s,n,r);break;default:throw new Error("Unknown message type")}return o}})),s.register("bEPl9",(function(t,n){e(t.exports,"subscribe",(()=>d)),e(t.exports,"unsubscribe",(()=>u)),e(t.exports,"publish",(()=>p));var r=s("96q9T"),i=s("5zT0w"),o=s("jx2H5"),c=s("hpXBJ");const a=new Map,h="undefined"==typeof BroadcastChannel?class{constructor(e){this.room=e,this.onmessage=null,this._onChange=t=>t.key===e&&null!==this.onmessage&&this.onmessage({data:o.fromBase64(t.newValue||"")}),c.onChange(this._onChange)}postMessage(e){c.varStorage.setItem(this.room,o.toBase64(o.createUint8ArrayFromArrayBuffer(e)))}close(){c.offChange(this._onChange)}}:BroadcastChannel,l=e=>r.setIfUndefined(a,e,(()=>{const t=i.create(),s=new h(e);return s.onmessage=e=>t.forEach((t=>t(e.data,"broadcastchannel"))),{bc:s,subs:t}})),d=(e,t)=>(l(e).subs.add(t),t),u=(e,t)=>{const s=l(e),n=s.subs.delete(t);return n&&0===s.subs.size&&(s.bc.close(),a.delete(e)),n},p=(e,t,s=null)=>{const n=l(e);n.bc.postMessage(t),n.subs.forEach((e=>e(t,s)))}})),s.register("cIOyM",(function(e,t){s("bx9uf")})),s.register("iV07c",(function(t,n){e(t.exports,"DexieTransport",(()=>c)),s("6frWy");var r=s("P7Ozw"),i=s("bx9uf"),o=s("cPWby");class c{uidDB="";key="";_isConnected=!1;pending=null;replayed=!1;get isConnected(){return this._isConnected}async connect(e){this.uidDB=e.uidDB,this.key=e.room,this.pending=await o.default.compactYjsUpdates(this.uidDB,this.key,(e=>{const t=e.flatMap((e=>(0,r.extractDocUpdates)(e)));return 0===t.length?null:(0,r.frameDocUpdate)(i.mergeUpdates(t))})),this._isConnected=!0,this.replayIfReady()}disconnect(){this._isConnected=!1,this.messageCallback=void 0,this.pending=null,this.replayed=!1}send(e){const t=(0,r.extractDocUpdates)(e);if(0!==t.length)return o.default.appendYjsUpdate(this.uidDB,this.key,(0,r.frameDocUpdate)(1===t.length?t[0]:i.mergeUpdates(t)))}onMessage(e){return this.messageCallback=e,this.replayIfReady(),()=>{this.messageCallback=void 0}}replayIfReady(){if(this.replayed||!this._isConnected||!this.messageCallback)return;this.replayed=!0;const e=this.pending;this.pending=null,e&&this.messageCallback(e)}}})),s.register("bDw11",(function(t,n){e(t.exports,"CRDT",(()=>p));var r=s("bx9uf"),i=s("8kr9p"),o=s("c4j9z"),c=s("goBin"),a=s("du9vu"),h=s("cRGOZ"),l=s("7X7lt");const d="q",u="s";class p{timestamp=Date.now();classroomMode=0;peerKeyCache=new Map;scheduleQuizSurvey=(0,h.coalesce)((()=>this.fireQuizSurvey().catch((e=>console.warn("quiz/survey re-check failed ->",e)))));constructor(e,t){this.doc=new r.Doc,this.callback=t||((e,t)=>{console.warn("SyncDB: no callback provided")}),this.length=0,this.peerID=e,this.codes=this.doc.getMap("c"),this.chat=new(0,l.YKeyValue)(this.doc.getArray("chat")),this.metadata=this.doc.getArray("meta"),this.identities=this.doc.getMap("name"),this.user=this.doc.getMap("user"),this.ownerKey=this.doc.getMap("ownerKey"),this.wrappedKeys=this.doc.getMap("wrappedKeys"),this.signingKeys=this.doc.getMap("signingKeys"),this.signingKeyReady=o.generateSigningKeyPair().then((async e=>{const t=await o.exportPublicKey(e.publicKey);return this.signingKeys.set(this.peerID,t),e}))}setMode(e,t,s,n){this.classroomMode=e,this.roomId=t,this.uidDB=s,this.ownerTokenHash=n?.ownerTokenHash||void 0,this.incomingOwnerToken=n?.ownerToken||void 0}async resolveOwnerToken(){const e=`${this.roomId??"default"}:ownerToken`,t=this.uidDB??"default";if(this.incomingOwnerToken){const s=await o.sha256Base64(this.incomingOwnerToken);return this.ownerTokenHash&&s!==this.ownerTokenHash||(this.localOwnerToken=this.incomingOwnerToken,this.ownerTokenHash=s,await(0,c.putStoredValue)(t,e,this.localOwnerToken)),{hash:this.ownerTokenHash??"",token:this.localOwnerToken}}const s=await(0,c.getStoredValue)(t,e);if(s){const e=await o.sha256Base64(s);this.ownerTokenHash&&e!==this.ownerTokenHash||(this.localOwnerToken=s,this.ownerTokenHash=e)}return{hash:this.ownerTokenHash??"",token:this.localOwnerToken}}async init(e){this.length=Math.max(this.length,e.length);const t=[];for(let s=0;s<e.length;s++)await this.collectInitWrites(d,s,e[s][d],t),await this.collectInitWrites(u,s,e[s][u],t);this.doc.transact((()=>{for(const e of t){const t=this.getOwnSectionArray(e.type,e.id);(t.length<=e.i||null==t.get(e.i))&&(0,a.setArrayValue)(t,e.i,e.value)}for(let t=0;t<e.length;t++)this.initText(t,e[t].c)}),this.peerID),this.registerCallbacks(),await this.maybeBecomeOwner().catch((e=>console.warn("maybeBecomeOwner failed ->",e))),await this.rewrapForCurrentOwner().catch((e=>console.warn("rewrapForCurrentOwner failed ->",e))),await this.fireInitialState(),clearTimeout(this.resyncTimer),this.resyncTimer=setTimeout((()=>this.scheduleQuizSurvey()),4e3)}async collectInitWrites(e,t,s,n){if(s&&0!==s.length)for(let r=0;r<s.length;r++){const i=s[r][this.peerID];if(void 0===i)continue;const c=0!==this.classroomMode?await o.encryptValue(await this.ensureContentKey(),i):i;n.push({type:e,id:t,i:r,value:c})}}async fireQuizSurvey(){const e=this.collectSectionIds(d);e.size>0&&this.callback(await Promise.all([...e].map((async e=>({id:e,data:await this.getSection(e,d)})))),"quiz");const t=this.collectSectionIds(u);t.size>0&&this.callback(await Promise.all([...t].map((async e=>({id:e,data:await this.getSection(e,u)})))),"survey")}async fireInitialState(){const e=this.getPeers();Object.keys(e).length>0&&this.callback(e,"peer");const t=this.getIdentities();Object.keys(t).length>0&&this.callback(t,"identity");const s=this.getCursors();s.length>0&&this.callback(s,"cursor"),this.scheduleQuizSurvey();const n=new Set;for(const e of this.codes.keys())try{const[t]=JSON.parse(e);n.add(t)}catch{}n.size>0&&this.callback(this.getCode(n),"code");const r=await this.buildChatVector();r.length>0&&this.callback(r,"chat")}async buildChatVector(){const e=[];for(const[t,s]of this.chat.map)e.push({...s.val,id:parseInt(t)});const t=await Promise.all(e.map((e=>this.verifyChatEntry(e))));return t.sort(((e,t)=>e.id-t.id)),t}async verifyChatEntry(e){if(!e.signature)return{...e,verified:!1};const t=this.signingKeys.get(String(e.user));if(!t)return{...e,verified:!1};const s=await o.verifyChatMessage(t,{message:String(e.message),user:String(e.user),ts:e.id},e.signature);return{...e,verified:s}}setAwareness(e,t){this.awareness=e,e.setLocalState({peerID:this.peerID,color:this.getColor(),name:t}),t&&this.identities.get(this.peerID)!==t&&this.identities.set(this.peerID,t),e.on("change",(e=>{const t=this.getPeers();this.callback(t,"peer");const s=this.getCursors();s.length>0&&this.callback(s,"cursor")})),this.callback(this.getPeers(),"peer")}registerCallbacks(){this.metadata.observe((()=>{this.callback(this.getOwner()===this.peerID,"ownership"),this.maybeBecomeOwner().catch((e=>console.warn("maybeBecomeOwner failed ->",e)))})),this.ownerKey.observe((()=>{this.rewrapForCurrentOwner().catch((e=>console.warn("rewrapForCurrentOwner failed ->",e)))})),this.user.observeDeep((e=>{e.length>0&&this.scheduleQuizSurvey()})),this.wrappedKeys.observe((()=>this.scheduleQuizSurvey())),this.identities.observe((()=>{this.callback(this.getIdentities(),"identity")})),this.signingKeys.observe((()=>{this.buildChatVector().then((e=>{e.length>0&&this.callback(e,"chat")})).catch((e=>console.warn("chat re-verify failed ->",e)))})),this.chat.on("change",(e=>{const t=[];for(let[s,n]of e)"add"===n.action&&t.push({id:parseInt(s),entry:n.newValue});0!==t.length&&Promise.all(t.map((({id:e,entry:t})=>this.verifyChatEntry({...t,id:e})))).then((e=>this.callback(e,"chat"))).catch((e=>console.warn("chat verify failed ->",e)))})),this.codes.observeDeep((e=>{const t=new Set;for(const s of e)if(s.target===this.codes)s.keysChanged.forEach((e=>{try{const[s]=JSON.parse(e);t.add(s)}catch{}}));else try{const[e]=JSON.parse(s.path[0]);t.add(e)}catch{}t.size>0&&this.callback(this.getCode(t),"code")}))}encode(){return r.encodeStateAsUpdate(this.doc)}destroy(){clearTimeout(this.resyncTimer),this.doc.destroy()}log(){console.warn("*********** PEERS ***********"),console.warn(this.getPeers()),console.warn("*********** CURSORS ***********"),console.warn(this.getCursors()),console.warn("*********** STATE ***********"),console.warn(this.doc.toJSON())}initText(e,t){if(0!==t.length)for(let s=0;s<t.length;s++)for(let n=0;n<t[s].length;n++)this.initCode(e,s,n,t[s][n])}getCode(e){let t=[];for(const s of e)t.push({id:s,data:this.getAllTexts(s)});return t}getCursors(){if(!this.awareness)return[];const e=[];for(const[,t]of this.awareness.getStates())t?.cursor&&t?.peerID&&t.peerID!==this.peerID&&e.push(t.cursor);return e}getPeers(){if(!this.awareness)return{};const e={};for(const[,t]of this.awareness.getStates())t?.peerID&&(e[t.peerID]=t.name);return e}removePeer(){this.awareness?.setLocalState(null)}getIdentities(){const e={};for(const[t,s]of this.identities)e[t]=s;return e}id(e,t,s){return void 0===s?JSON.stringify([e,t]):JSON.stringify([e,t,s])}collectSectionIds(e){const t=new Set;for(const[,s]of this.user){const n=s.get(e);if(n)for(const e of n.keys())t.add(Number(e))}return t}async getSection(e,t){const s=[];for(const[n,r]of this.user){const i=r.get(t),o=i?.get(String(e));if(o)for(let e=0;e<o.length;e++){const t=o.get(e);if(null==t)continue;const r=await this.decryptSectionValue(n,t);void 0!==r&&(s[e]||(s[e]={}),s[e][n]=r)}}for(let e=0;e<s.length;e++)s[e]||(s[e]={});return s}async decryptSectionValue(e,t){if(0===this.classroomMode||!o.isEncryptedValue(t))return t;try{if(e===this.peerID)return await o.decryptValue(await this.ensureContentKey(),t);if(this.getOwner()===this.peerID&&this.ownerKeyPair){const s=await this.getPeerContentKey(e);if(!s)return;return await o.decryptValue(s,t)}}catch(e){return}}async getPeerContentKey(e){const t=this.wrappedKeys.get(e);if(!t)return;const s=this.peerKeyCache.get(e);if(s&&s.wrapped===t)return s.key;const n=await o.unwrapContentKey(t,this.ownerKeyPair.privateKey);return this.peerKeyCache.set(e,{wrapped:t,key:n}),n}ensureContentKey(){return this.contentKeyReady||(this.contentKeyReady=(0,c.getOrCreateKey)(this.uidDB??"default",`${this.roomId??"default"}:content:${this.peerID}`,(()=>o.generateContentKey())).then((e=>(this.contentKey=e,e)))),this.contentKeyReady}async maybeBecomeOwner(){if(0===this.classroomMode)return;if(this.getOwner()!==this.peerID)return;if(this.ownerKeyPair)return;this.ownerKeyPair=await(0,c.getOrCreateKey)(this.uidDB??"default",this.roomId??"default",(()=>o.generateECDHKeyPair())),this.scheduleQuizSurvey();const e=await o.exportPublicKey(this.ownerKeyPair.publicKey);this.ownerKey.get(this.peerID)!==e&&this.ownerKey.set(this.peerID,e)}async rewrapForCurrentOwner(){if(0===this.classroomMode)return;const e=this.getOwner();if(!e)return;const t=this.ownerKey.get(e);if(!t)return;const s=await this.ensureContentKey(),n=await o.wrapContentKeyForOwner(s,t);this.wrappedKeys.set(this.peerID,n)}getAllTexts(e){let t,s=[];for(let n=0;this.codes.has(this.id(e,n,0));n++){let r=[];for(let s=0;this.codes.has(this.id(e,n,s));s++)t=this.codes.get(this.id(e,n,s)),r.push(t?.toString()||"");s.push(r)}return s}addQuiz(e,t,s){this.addRecord(d,e,t,s).catch((e=>console.warn("addQuiz failed ->",e)))}addSurvey(e,t,s){this.addRecord(u,e,t,s).catch((e=>console.warn("addSurvey failed ->",e)))}async addRecord(e,t,s,n){const r=0!==this.classroomMode?await o.encryptValue(await this.ensureContentKey(),n):n;this.doc.transact((()=>{const n=this.getOwnSectionArray(e,t);(0,a.setArrayValue)(n,s,r)}),this.peerID)}getOwnSectionArray(e,t){let s=this.user.get(this.peerID);s||(s=new r.Map,this.user.set(this.peerID,s));let n=s.get(e);n||(n=new r.Map,s.set(e,n));let i=n.get(String(t));return i||(i=new r.Array,n.set(String(t),i)),i}initCode(e,t,s,n){if(!this.codes.has(this.id(e,t,s))){const i=this.doc.clientID;this.doc.clientID=0;const o=new r.Text;o.insert(0,n),this.codes.set(this.id(e,t,s),o),this.doc.clientID=i}}async addChatMessage(e){const t=Date.now(),s=await this.signingKeyReady,n=await o.signChatMessage(s.privateKey,{message:e,user:this.peerID,ts:t});this.chat.set(""+t,{color:this.getColor(),message:e,user:this.peerID,signature:n})}updateCode(e,t,s,n){this.codes.has(this.id(e,t,s))&&this.doc.transact((()=>{const r=this.codes.get(this.id(e,t,s));if(void 0!==r)for(let e of n)switch(e.action){case"insert":r.insert(e.index,e.content);break;case"remove":r.delete(e.index,e.content.length);break;default:console.warn("Sync code, unknown action ->",e)}}),"code")}getColor(){return this.color||(this.color=i.getColorFor(this.peerID)),this.color}setCursor(e,t,s){this.awareness?.setLocalStateField("cursor",{id:this.peerID,section:e,project:t.project,file:t.file,state:t.state,color:this.getColor(),name:s})}removeCursor(){this.awareness?.setLocalStateField("cursor",null)}parseClaim(e){const t=e.lastIndexOf("@");return-1===t?{id:e,ts:0}:{id:e.slice(0,t),ts:Number(e.slice(t+1))||0}}claimOwnership(){this.localOwnerToken&&(this.metadata.toArray().map((e=>this.parseClaim(e))).some((e=>e.id===this.peerID))||this.metadata.push([`${this.peerID}@${Date.now()}`])),this.callback(this.getOwner()===this.peerID,"ownership")}getOwner(){const e=this.metadata.toArray().map((e=>this.parseClaim(e)));return 0===e.length?null:e.reduce(((e,t)=>t.ts<e.ts?t:e)).id}}})),s.register("goBin",(function(t,n){e(t.exports,"getOrCreateKey",(()=>i)),e(t.exports,"getStoredValue",(()=>o)),e(t.exports,"putStoredValue",(()=>c));var r=s("cPWby");async function i(e,t,s){try{const n=await r.default.getKey(e,t);if(n)return n;const i=await s();return await r.default.putKey(e,t,i),i}catch(e){return console.warn("keyStore: falling back to session-only key ->",e),s()}}async function o(e,t){try{return await r.default.getKey(e,t)}catch(e){return void console.warn("keyStore: getStoredValue unavailable ->",e)}}async function c(e,t,s){try{await r.default.putKey(e,t,s)}catch(e){console.warn("keyStore: putStoredValue unavailable ->",e)}}})),s.register("du9vu",(function(t,s){function n(e,t,s){if(e.length>t)e.delete(t,1);else for(;e.length<t;)e.push([null]);e.insert(t,[s])}e(t.exports,"setArrayValue",(()=>n))})),s.register("cRGOZ",(function(t,s){function n(e){let t=!1,s=!1;const n=()=>{if(t)return void(s=!0);t=!0;const r=()=>{t=!1,s&&(s=!1,n())};e().then(r,r)};return n}e(t.exports,"coalesce",(()=>n))})),s.register("7X7lt",(function(t,n){e(t.exports,"YKeyValue",(()=>i));var r=s("8Gyr5");class i extends r.Observable{constructor(e){super(),this.yarray=e,this.doc=e.doc,this.map=new Map;{const t=e.toArray();this.doc.transact((()=>{for(let s=t.length-1;s>=0;s--){const n=t[s];this.map.has(n.key)?e.delete(s):this.map.set(n.key,n)}}))}e.observe(((t,s)=>{const n=new Map,r=Array.from(t.changes.added);t.changes.deleted.forEach((e=>{e.content.getContent().forEach((e=>{this.map.get(e.key)===e&&(this.map.delete(e.key),n.set(e.key,{action:"delete",oldValue:e.val}))}))}));const i=new Map;r.map((e=>e.content.getContent())).flat().forEach((e=>{i.set(e.key,e)}));const o=new Set,c=e.toArray();this.doc.transact((t=>{for(let t=c.length-1;t>=0&&(i.size>0||o.size>0);t--){const s=c[t];if(o.has(s.key))o.delete(s.key),e.delete(t,1);else if(i.get(s.key)===s){const e=this.map.get(s.key);if(e)o.add(s.key),n.set(s.key,{action:"update",oldValue:e.val,newValue:s.val});else{const e=n.get(s.key);e&&"delete"===e.action?n.set(s.key,{action:"update",newValue:s.val,oldValue:e.oldValue}):n.set(s.key,{action:"add",newValue:s.val})}i.delete(s.key),this.map.set(s.key,s)}else i.has(s.key)&&(o.add(s.key),i.delete(s.key))}})),n.size>0&&this.emit("change",[n,s])}))}set(e,t){this.doc.transact((s=>{this.map.has(e)&&this.delete(e),this.yarray.push([{key:e,val:t}])}))}delete(e){let t=0;for(const s of this.yarray){if(s.key===e){this.yarray.delete(t);break}t++}}get(e){const t=this.map.get(e);return t&&t.val}has(e){return this.map.has(e)}}})),s.register("3MQ2P",(function(t,n){e(t.exports,"wrapTransport",(()=>o));var r=s("gjWRH"),i=s("kPRWr");function o(e,t,s=0){return t?{connect:t=>e.connect(t),disconnect:()=>e.disconnect(),send:t=>{const n=(new TextEncoder).encode(i.Crypto.encode((0,r.encode)(t)));if(0===s)return e.send(n);const o=new Uint8Array(s+n.length);return o.set(n,s),e.send(o)},onMessage:t=>e.onMessage((e=>{try{const n=0===s?e:e.subarray(s),o=(0,r.decode)(i.Crypto.decode((new TextDecoder).decode(n)));t(o)}catch(e){console.warn("security: dropping undecryptable frame ->",e)}})),onPeerConnect:e.onPeerConnect?t=>e.onPeerConnect(t):void 0,get isConnected(){return e.isConnected},get preferredBatchMs(){return e.preferredBatchMs}}:e}})),s.register("kPRWr",(function(t,s){e(t.exports,"Crypto",(()=>n));const n={url:"https://cdn.jsdelivr.net/npm/simple-crypto-js@2.5.0/dist/SimpleCrypto.min.js",crypt:null,check:function(){return!!window.SimpleCrypto},init:function(e){try{"string"==typeof e&&e.length>0?this.crypt=new SimpleCrypto(e):this.crypt=null}catch(e){console.warn("Crypto: ",e),this.crypt=null}},encode:function(e){return this.crypt?this.crypt.encrypt(btoa(encodeURIComponent(JSON.stringify(e)))):JSON.stringify(e)},decode:function(e){return this.crypt?JSON.parse(decodeURIComponent(atob(this.crypt.decrypt(e)))):JSON.parse(e)}}}));