@liascript/editor 1.1.43--2.0.1 → 1.1.43--2.1.0
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.
- package/CHANGELOG.md +19 -0
- package/dist/Ably.607911cd.js +1 -0
- package/dist/Ably.c7811c13.js +1 -0
- package/dist/Nostr.a4f09542.js +1 -0
- package/dist/Nostr.a7641a38.js +1 -0
- package/dist/Nostr.c6fda72a.js +1 -0
- package/dist/Nostr.da928c49.js +1 -0
- package/dist/index.59b516bc.js +1 -0
- package/dist/index.7892bde1.css +1 -0
- package/dist/index.94c5f8cc.js +1 -0
- package/dist/index.9bf04aba.js +1 -0
- package/dist/index.d807fb84.js +1 -0
- package/dist/index.html +1 -1
- package/dist/{jszip.min.7f7f29fe.js → jszip.min.0e12e848.js} +1 -1
- package/dist/{jszip.min.a7b69263.js → jszip.min.78e0bc9c.js} +1 -1
- package/package.json +7 -2
- package/dist/Ably.140d23cc.js +0 -1
- package/dist/Ably.9f94dcaa.js +0 -1
- package/dist/Nostr.2b404c26.js +0 -1
- package/dist/Nostr.2c8140ac.js +0 -1
- package/dist/Nostr.329b3a71.js +0 -1
- package/dist/Nostr.d5c9f5db.js +0 -1
- package/dist/index.a89e1a4c.js +0 -1
- package/dist/index.b1a8e24f.js +0 -1
- package/dist/index.c18b1883.js +0 -1
- package/dist/index.c7acbc74.css +0 -1
- package/dist/index.e92af917.js +0 -1
package/dist/Nostr.329b3a71.js
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
!function(){function e(e,t,n,r){Object.defineProperty(e,t,{get:n,set:r,enumerable:!0,configurable:!0})}var t="undefined"!=typeof globalThis?globalThis:"undefined"!=typeof self?self:"undefined"!=typeof window?window:"undefined"!=typeof global?global:{},n=t.parcelRequirea18f;n.register("9Xb5B",(function(t,r){e(t.exports,"Sync",(function(){return d})),n("4nLZ9");var s=n("iYjQj"),i=n("hxuAG"),o=n("axlxN"),c=n("66xmW"),a=n("cV7be"),h=(n("3Lnfd"),n("a4k16"));function l(e=16){let t="";for(let n=0;n<e;n++)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,n,r,s=!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=n,this.onReceive=r,this.replyOnReceive=s;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,s.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),n=JSON.parse(t);this.onReceive?.(n.topic,n.message)}catch(e){console.warn("Sync: pubsubReceive",e.message)}}load(e,t){try{for(let n=0;n<e.length;n++){const r=document.createElement("script");r.async=!1,r.defer=!0,r.src=e[n],this.urlCounter++;let s=this;r.onload=function(){console.log("successfully loaded =>",e),s.urlCounter--,0==s.urlCounter&&t.init(!0)},r.onerror=function(n){console.warn("could not load =>",e,n),s.urlCounter=0,t.init(!1,`could not load => ${e}`)},document.head.appendChild(r)}}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 n=0;n<e.message.param[t].length;n++)this.db.initCode(e.track[0][1],t,n,e.message.param[t][n]);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)}}}})),n.register("4nLZ9",(function(t,r){e(t.exports,"GenericProvider",(function(){return n("iYjQj").GenericProvider})),e(t.exports,"extractDocUpdates",(function(){return n("iYjQj").extractDocUpdates})),e(t.exports,"frameDocUpdate",(function(){return n("iYjQj").frameDocUpdate})),n("iYjQj"),n("iYjQj"),n("05asq")})),n.register("iYjQj",(function(t,r){e(t.exports,"extractDocUpdates",(function(){return v})),e(t.exports,"frameDocUpdate",(function(){return U})),e(t.exports,"GenericProvider",(function(){return C}));var s=n("7I2MU"),i=n("232M8"),o=n("jmfTU"),c=n("j3EDv"),a=n("heYZO"),h=n("fACbm"),l=n("7Ecpa");const d=0,u=3,p=4,g=6,f=(()=>{const e=new Uint32Array(256);for(let t=0;t<256;t++){let n=t;for(let e=0;e<8;e++)n=1&n?n>>>1^3988292384:n>>>1;e[t]=n}return e})();function w(e){let t=4294967295;for(let n=0;n<e.length;n++)t=t>>>8^f[255&(t^e[n])];return(4294967295^t)>>>0}function y(e){const t=w(e),n=new Uint8Array(4+e.length);return n[0]=t>>>24&255,n[1]=t>>>16&255,n[2]=t>>>8&255,n[3]=255&t,n.set(e,4),n}function _(e,t){if(e.length!==t.length)return!1;for(let n=0;n<e.length;n++)if(e[n]!==t[n])return!1;return!0}const m="undefined"!=typeof CompressionStream&&"undefined"!=typeof DecompressionStream;async function S(e){const t=[],n=e.getReader();for(;;){const{done:e,value:r}=await n.read();if(e)break;t.push(r)}const r=t.reduce(((e,t)=>e+t.length),0),s=new Uint8Array(r);let i=0;for(const e of t)s.set(e,i),i+=e.length;return s}function b(e,t){const n=new Uint8Array(1+t.length);return n[0]=e,n.set(t,1),n}function k(e){const t=s.encodeStateVector(e);let n=0;for(let e=0;e<t.length;e++)n=(n<<5)-n+t[e]|0;return n}function v(e){const t=[],n=e=>{const r=a.createDecoder(e),s=a.readVarUint(r);switch(s){case p:for(;a.hasContent(r);)n(a.readVarUint8Array(r));break;case u:case d:{s===u&&(a.readVarUint(r),a.readVarUint(r));const e=a.readVarUint(r);e!==o.messageYjsSyncStep2&&e!==o.messageYjsUpdate||t.push(a.readVarUint8Array(r));break}case g:t.push(a.readVarUint8Array(r))}};try{e.length>4&&n(e.subarray(4))}catch{return[]}return t}function U(e){const t=c.createEncoder();return c.writeVarUint(t,d),c.writeVarUint(t,o.messageYjsSyncStep2),c.writeVarUint8Array(t,e),y(c.toUint8Array(t))}class A extends h.Observable{constructor(e){super(),this.provider=e}publish(e,t){this.provider._sendPubSub(e,t)}subscribe(e,t){const n=(n,r)=>{"*"!==e&&e!==r||t(n,r)};return this.on("message",n),()=>this.off("message",n)}_handleMessage(e,t){this.emit("message",[t,e])}}class C extends h.Observable{constructor(e,t,n={}){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 A(this),this.awareness=n.awareness||new i.Awareness(e),this._syncInterval=n.syncInterval??5e3,this._verifyUpdates=n.verifyUpdates??!0,this._batchUpdates=n.batchUpdates??t.preferredBatchMs??0,this._disableBc=n.disableBc??!1,this._awarenessInterval=n.awarenessInterval??t.preferredAwarenessMs??100,this._maxSyncRequestsPerWindow=n.maxSyncRequestsPerWindow??20,this._syncRequestWindowMs=n.syncRequestWindowMs??1e4,this._syncReplySuppressionMs=n.syncReplySuppressionMs??30,this._peerConnectDebounceMs=n.peerConnectDebounceMs??50,this._gapGraceMs=n.gapGraceMs??300,this._seqWindowSize=n.seqWindowSize??64,this._compressionThresholdBytes=(n.compressionThresholdBytes??t.preferredCompressMinBytes)||void 0,this._idleBackoffEnabled=n.idleBackoffEnabled??!0,this._idleBackoffMaxMs=n.idleBackoffMaxMs??6e4,this._trickleK=n.trickleK??1,this._ownsAwareness=!n.awareness,this._awarenessTimeoutMs=n.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=s.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,n=0){if(!this._tryReserveSyncSlot())return!1;const r=[];if(e){const e=s.encodeStateAsUpdate(this.doc,this._confirmedSv??void 0);let t=e.length>0;if(t&&null!==this._confirmedSv)try{t=s.parseUpdateMeta(e).to.size>0||this._deleteSetHash()!==this._confirmedDsHash}catch{t=!0}t&&r.push(this._encodePush(e))}return r.push(this._encodeSyncStep1(n)),t&&r.push(...t()),this._sendBatch(r),1&n&&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(n,e/10*(.8+.4*Math.random()))},n=()=>{const n=Date.now();if(this._ownsAwareness){const t=this.awareness.meta.get(this.doc.clientID);null!==this.awareness.getLocalState()&&void 0!==t&&e/2<=n-t.lastUpdated&&(this.awareness.setLocalState(this.awareness.getLocalState()),this._broadcastAwareness([this.doc.clientID]));const r=[];this.awareness.meta.forEach(((t,s)=>{s!==this.doc.clientID&&e<=n-t.lastUpdated&&this.awareness.getStates().has(s)&&r.push(s)})),r.length>0&&i.removeAwarenessStates(this.awareness,r,"timeout")}for(const[t,r]of this._knownPeers)e<=n-r&&(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[n,r]of this._peerAddress)r===e&&t.push(n);for(const e of t)this._peerAddress.delete(e),this._knownPeers.delete(e);const n=t.filter((e=>this.awareness.getStates().has(e)));n.length>0&&i.removeAwarenessStates(this.awareness,n,"peer-left")}_deleteSetHash(){return null===this._dsHashCache&&(this._dsHashCache=function(e){const t=s.createDeleteSetFromStructStore(e.store),n=c.createEncoder(),r=Array.from(t.clients.keys()).sort(((e,t)=>e-t));for(const e of r){c.writeVarUint(n,e);for(const r of t.clients.get(e))c.writeVarUint(n,r.clock),c.writeVarUint(n,r.len)}return w(c.toUint8Array(n))}(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 n of e)this._sendToTransport(t,n)}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=s.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:n},r)=>{if(r===this&&(n.length>0&&this._cancelPendingAwarenessRemovalIfOverlaps(n),!n.includes(this.awareness.clientID)))return;const s=e.concat(t).concat(n);"timeout"!==r&&"peer-left"!==r?this._broadcastAwareness(s):this._scheduleAwarenessRemoval(s,r)},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 n=e[0],r=e.subarray(1);0!==n?m?async function(e){const t=new DecompressionStream("deflate-raw"),n=t.writable.getWriter();return n.write(e).catch((()=>{})),n.close().catch((()=>{})),S(t.readable)}(r).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(r,t)}_processWrappedMessage(e,t){const n=function(e){if(e.length<4)return null;const t=(e[0]<<24|e[1]<<16|e[2]<<8|e[3])>>>0,n=e.subarray(4);return w(n)!==t?null:n}(e);if(null===n)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(n,t)}catch(e){console.error("[GenericProvider] Error handling message:",e)}}_dispatchMessage(e,t){const n=a.createDecoder(e),r=a.readVarUint(n);switch(r){case p:for(;a.hasContent(n);){const e=a.readVarUint8Array(n);this._dispatchMessage(e,t)}break;case 5:this._handleDigest(n,t);break;case g:s.applyUpdate(this.doc,a.readVarUint8Array(n),this),this._checkPendingAfterReply();break;case d:{const e=c.createEncoder();c.writeVarUint(e,d),o.readSyncMessage(n,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(n),t=this._scanAwarenessPayload(e);t.removed.length>0&&this._cancelPendingAwarenessRemovalIfOverlaps(t.removed),t.coversUs&&(this._presenceCovered=!0);const r=Date.now();for(const e of t.present)e!==this.doc.clientID&&this._knownPeers.set(e,r);i.applyAwarenessUpdate(this.awareness,e,this);break}case 2:{const t=a.readVarString(n),r=a.readVarUint8Array(n);try{const e=(new TextDecoder).decode(r),n=JSON.parse(e);this.pubsub._handleMessage(t,n)}catch(e){console.error("Error decoding pub/sub message:",e)}break}case u:{const e=a.readVarUint(n),r=a.readVarUint(n);this._trackRemoteSeq(r,e),this._knownPeers.set(r,Date.now()),void 0!==t&&this._peerAddress.set(r,t),this._touchPeer(r);const s=this._peekSyncUpdate(n),i=c.createEncoder();c.writeVarUint(i,d);const h=o.readSyncMessage(n,i,this.doc,this);h===o.messageYjsSyncStep2&&(this._cancelPendingSyncReply(),this._confirmed=!0,this._checkPendingAfterReply(),this._noteResponse(!0));const l=a.readVarInt(n),u=k(this.doc);if(u!==l){const e=this._gapCheckTimers.has(r),t=this._isLateUpdate(s);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:",r)}}_handleDigest(e,t){a.readVarUint(e);const n=a.readVarUint(e),r=a.readVarUint(e);this._knownPeers.set(r,Date.now()),void 0!==t&&this._peerAddress.set(r,t),this._touchPeer(r);const i=a.readVarUint8Array(e),h=a.readVarUint(e),l=s.decodeStateVector(i),u=s.decodeStateVector(s.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&n)w&&(8&n?(this._confirmed=!0,this._noteResponse(!0)):this._equalUnsettledSeen=!0,this._markSynced(),this._cancelPendingAck());else{if(!w||5&n||(this._equalBeaconsHeard++,8&n?(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,r)}else 5&n&&this._replyToSyncRequest(this._encodeAck(i,h),!0,null,r);!g&&f&&this._markSynced(),g&&this._scheduleBehindCheck(i),1&n&&null!==this.awareness.getLocalState()&&this._schedulePresenceResponse(r)}}_schedulePresenceResponse(e){if(this._presencePending.add(e),void 0!==this._presenceResponseTimer)return;this._presenceCovered=!1;const t=this._rttMinMs(),n=!this._canUnicast(e)&&this._knownPeers.size>=3&&0===this._responderRank(0,1),r=n?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 n of e)this._sendDirect(n,t)}else n?this._sendAwarenessNow(Array.from(this.awareness.getStates().keys())):this._presenceCovered||this._broadcastAwareness([this.doc.clientID])}),r)}_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))),n=this._rttMinMs();return null===n?t:Math.min(2e3,Math.max(t,1.5*n))}_scheduleSyncReply(e,t=!1,n=null,r=null){if(void 0!==this._pendingSyncReplyTimeoutId&&null!==this._pendingSyncReply){if(_(this._pendingSyncReply,e))return;if(null!==n&&null!==this._pendingSyncReplyTargetSv&&_(this._pendingSyncReplyTargetSv,n))return void(this._pendingSyncReply=e);if(!t&&!this._pendingSyncReplyIsAck&&null!==n&&null!==this._pendingSyncReplyTargetSv){const e=function(e,t){const n=s.decodeStateVector(e),r=s.decodeStateVector(t),i=new Map;for(const[e,t]of n){const n=Math.min(t,r.get(e)??0);n>0&&i.set(e,n)}return s.encodeStateVector(i)}(this._pendingSyncReplyTargetSv,n),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=n;const i=t?Math.random()*this._replySuppressionMaxDelay():this._replyDelay(r);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,n=null,r){if(null===this.doc.store.pendingStructs&&null===this.doc.store.pendingDs)if(void 0!==r&&this._canUnicast(r)){if(!this._selectedResponder(r))return;if(!this._tryReserveReplySlot())return;this._sendDirect(r,e)}else t||this._peerCount()>=3?this._scheduleSyncReply(e,t,n,r??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 n=Math.floor(Date.now()/2e3),r=t=>(Math.imul(e^n,2654435761)^Math.imul(t,2246822507))>>>0,s=r(this.doc.clientID);let i=0;for(const n of this._knownPeers.keys())if(n!==e&&n!==this.doc.clientID&&r(n)<s&&++i>=t)break;return i}_replyDelay(e){const t=this._replySuppressionMaxDelay(),n=this._rttMinMs();if(null===e||null===n)return Math.random()*t;const r=Math.max(this._syncReplySuppressionMs,.75*n),s=this._responderRank(e,8);return s*r+(s>=8?Math.random()*t:0)}_sendDirect(e,t){const n=this._peerAddress.get(e);return void 0!==n&&"function"==typeof this.transport.sendTo&&!!this.transport.isConnected&&(this._sendToTransport(y(t),n),!0)}_scheduleBehindCheck(e){if(this._behindSv=e,void 0!==this._behindCheckTimer)return;const t=this._rttMinMs(),n=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<n)return;const t=s.decodeStateVector(e),r=s.decodeStateVector(s.encodeStateVector(this.doc));for(const[e,n]of t)if((r.get(e)??0)<n)return void this._requestResync()}),n)}_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}=s.parseUpdateMeta(e);if(0===t.size)return!1;const n=s.decodeStateVector(s.encodeStateVector(this.doc));for(const[e,r]of t)if((n.get(e)??0)<=r)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(),n=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)}),n)}_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 n of e)t.includes(n)||t.push(n);return void(this._pendingAwarenessRemoval=t)}this._pendingAwarenessRemoval=e.slice();const n=this._replySuppressionMaxDelay(),r=Math.random()*("peer-left"===t?Math.max(1e3,10*n):n);this._pendingAwarenessRemovalTimeoutId=setTimeout((()=>{this._pendingAwarenessRemovalTimeoutId=void 0,this._pendingAwarenessRemoval&&(this._broadcastAwareness(this._pendingAwarenessRemoval),this._pendingAwarenessRemoval=null)}),r)}_scanAwarenessPayload(e){const t=[],n=[];let r=!1;try{const s=a.createDecoder(e),i=a.readVarUint(s),o=this.awareness.meta.get(this.awareness.clientID)?.clock??0;for(let e=0;e<i;e++){const e=a.readVarUint(s),i=a.readVarUint(s);null===JSON.parse(a.readVarString(s))?t.push(e):(n.push(e),e===this.awareness.clientID&&i>=o&&(r=!0))}}catch{}return{removed:t,present:n,coversUs:r}}_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 n=this._remoteSeqInfo.get(e);if(n||(n={highest:-1,seen:new Set},this._remoteSeqInfo.set(e,n)),n.seen.has(t))return;n.seen.add(t),t>n.highest&&(n.highest>=0&&t>n.highest+1&&this._scheduleGapCheck(e,n.highest+1,t-1),n.highest=t);const r=n.highest-this._seqWindowSize;if(r>0)for(const e of n.seen)e<r&&n.seen.delete(e)}_scheduleGapCheck(e,t,n){if(this._gapCheckTimers.has(e))return;const r=setTimeout((()=>{this._gapCheckTimers.delete(e);const r=this._remoteSeqInfo.get(e);if(!r||this._destroying)return;let s=0;for(let e=t;e<=n;e++)r.seen.has(e)||s++;s>0&&this.transport.isConnected&&(console.warn(`[GenericProvider] Sequence gap confirmed from client ${e}: ${s} message(s) still missing after ${this._gapGraceMs}ms grace period`),this._requestResync())}),this._gapGraceMs);this._gapCheckTimers.set(e,r)}_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 n=0;for(const r of e)t-r<this._syncRequestWindowMs&&(e[n++]=r);return e.length=n,!(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,s.encodeStateVector(this.doc)),c.writeVarUint(t,this._deleteSetHash()),c.toUint8Array(t)}_encodeAck(e,t){this._touchPeer(this.doc.clientID);const n=c.createEncoder();return c.writeVarUint(n,5),c.writeVarUint(n,1),c.writeVarUint(n,2|(this._confirmed?8:0)),c.writeVarUint(n,this.doc.clientID),c.writeVarUint8Array(n,e),c.writeVarUint(n,t),c.toUint8Array(n)}_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 n=k(this.doc);c.writeVarInt(t,n)}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 n=c.createEncoder();c.writeVarUint(n,2),c.writeVarString(n,e);const r=JSON.stringify(t),s=(new TextEncoder).encode(r);c.writeVarUint8Array(n,s),this._send(c.toUint8Array(n))}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 n=Date.now()-this._lastAwarenessTime,r=Math.max(0,t-n);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)])}),r)}_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 n=Array.from(this._pendingAwarenessClients);return this._pendingAwarenessClients.clear(),0===n.length?null:(this._lastAwarenessTime=Date.now(),this._encodeAwareness(n))}_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 n=new Uint8Array(e);this._handleIncomingMessage(n)},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 n=c.createEncoder();if(c.writeVarUint(n,d),o.writeSyncStep2(n,this.doc),this._bcPublish(y(c.toUint8Array(n))),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 n of e)c.writeVarUint8Array(t,n);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?b(0,e):e,this)}_sendToTransport(e,t){const n=this._compressionThresholdBytes;n?!m||e.length<n?this._dispatchToTransport(b(0,e),t):async function(e){const t=new CompressionStream("deflate-raw"),n=t.writable.getWriter();return n.write(e).catch((()=>{})),n.close().catch((()=>{})),S(t.readable)}(e).then((e=>{this._dispatchToTransport(b(1,e),t)})).catch((n=>{console.error("[GenericProvider] Compression failed, sending uncompressed:",n),this._dispatchToTransport(b(0,e),t)})):this._dispatchToTransport(e,t)}_dispatchToTransport(e,t){try{const n=void 0!==t&&"function"==typeof this.transport.sendTo?this.transport.sendTo(t,e):this.transport.send(e);n instanceof Promise&&n.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})),n.register("7I2MU",(function(r,s){e(r.exports,"createDeleteSetFromStructStore",(function(){return E})),e(r.exports,"Doc",(function(){return P})),e(r.exports,"Array",(function(){return lt})),e(r.exports,"Text",(function(){return It})),e(r.exports,"Map",(function(){return ut})),e(r.exports,"applyUpdate",(function(){return H})),e(r.exports,"decodeStateVector",(function(){return Y})),e(r.exports,"mergeUpdates",(function(){return Te})),e(r.exports,"encodeStateAsUpdate",(function(){return J})),e(r.exports,"encodeStateVector",(function(){return Q})),e(r.exports,"parseUpdateMeta",(function(){return Ie}));var i=n("fACbm"),o=n("kDMzp"),c=n("iUL32"),a=n("cuboK"),h=n("j3EDv"),l=n("heYZO"),d=n("9c5sf"),u=n("hpG0a"),p=n("f6bdK"),g=n("jtAN9"),f=n("diuv2"),w=n("ixCIn"),y=(w=n("ixCIn"),n("aYKIU")),_=n("fK7I3"),m=n("37RhN"),S=(n("k2yVv"),n("fJq6z"),n("fiX3Z")),b=n("gBQSU"),k=n("1TTGp");i.ObservableV2;class v{constructor(e,t){this.clock=e,this.len=t}}class U{constructor(){this.clients=new Map}}const A=(e,t,n)=>t.clients.forEach(((t,r)=>{const s=e.doc.store.clients.get(r);if(null!=s){const r=s[s.length-1],i=r.id.clock+r.length;for(let r=0,o=t[r];r<t.length&&o.clock<i;o=t[++r])_e(e,s,o.clock,o.len,n)}})),C=(e,t)=>{const n=e.clients.get(t.client);return void 0!==n&&null!==((e,t)=>{let n=0,r=e.length-1;for(;n<=r;){const s=c.floor((n+r)/2),i=e[s],o=i.clock;if(o<=t){if(t<o+i.len)return s;n=s+1}else r=s-1}return null})(n,t.clock)},T=e=>{e.clients.forEach((e=>{let t,n;for(e.sort(((e,t)=>e.clock-t.clock)),t=1,n=1;t<e.length;t++){const r=e[n-1],s=e[t];r.clock+r.len>=s.clock?r.len=c.max(r.len,s.clock+s.len-r.clock):(n<t&&(e[n]=s),n++)}e.length=n}))},I=e=>{const t=new U;for(let n=0;n<e.length;n++)e[n].clients.forEach(((r,s)=>{if(!t.clients.has(s)){const i=r.slice();for(let t=n+1;t<e.length;t++)o.appendTo(i,e[t].clients.get(s)||[]);t.clients.set(s,i)}}));return T(t),t},D=(e,t,n,r)=>{a.setIfUndefined(e.clients,t,(()=>[])).push(new v(n,r))},x=()=>new U,E=e=>{const t=x();return e.clients.forEach(((e,n)=>{const r=[];for(let t=0;t<e.length;t++){const n=e[t];if(n.deleted){const s=n.id.clock;let i=n.length;if(t+1<e.length)for(let n=e[t+1];t+1<e.length&&n.deleted;n=e[1+ ++t])i+=n.length;r.push(new v(s,i))}}r.length>0&&t.clients.set(n,r)})),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,n])=>{e.resetDsCurVal(),h.writeVarUint(e.restEncoder,t);const r=n.length;h.writeVarUint(e.restEncoder,r);for(let t=0;t<r;t++){const r=n[t];e.writeDsClock(r.clock),e.writeDsLen(r.len)}}))},M=e=>{const t=new U,n=l.readVarUint(e.restDecoder);for(let r=0;r<n;r++){e.resetDsCurVal();const n=l.readVarUint(e.restDecoder),r=l.readVarUint(e.restDecoder);if(r>0){const s=a.setIfUndefined(t.clients,n,(()=>[]));for(let t=0;t<r;t++)s.push(new v(e.readDsClock(),e.readDsLen()))}}return t},V=(e,t,n)=>{const r=new U,s=l.readVarUint(e.restDecoder);for(let i=0;i<s;i++){e.resetDsCurVal();const s=l.readVarUint(e.restDecoder),i=l.readVarUint(e.restDecoder),o=n.clients.get(s)||[],c=de(n,s);for(let n=0;n<i;n++){const n=e.readDsClock(),i=n+e.readDsLen();if(n<c){c<i&&D(r,s,c,i-c);let e=pe(o,n),a=o[e];for(!a.deleted&&a.id.clock<n&&(o.splice(e+1,0,nn(t,a,n-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,nn(t,a,i-a.id.clock)),a.delete(t))}else D(r,s,n,i-n)}}if(r.clients.size>0){const e=new W;return h.writeVarUint(e.restEncoder,0),R(e,r),e.toUint8Array()}return null},O=d.uint32;class P extends i.ObservableV2{constructor({guid:e=d.uuidv4(),collectionid:t=null,gc:n=!0,gcFilter:r=(()=>!0),meta:s=null,autoLoad:i=!1,shouldLoad:o=!0}={}){super(),this.gc=n,this.gcFilter=r,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=s,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=n=>{void 0!==n&&!0!==n||(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||Ue(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 Ue(this,e,t)}get(e,t=Ge){const n=a.setIfUndefined(this.share,e,(()=>{const e=new t;return e._integrate(this,null),e})),r=n.constructor;if(t!==Ge&&r!==t){if(r===Ge){const r=new t;r._map=n._map,n._map.forEach((e=>{for(;null!==e;e=e.left)e.parent=r})),r._start=n._start;for(let e=r._start;null!==e;e=e.right)e.parent=r;return r._length=n._length,this.share.set(e,r),r._integrate(this,null),r}throw new Error(`Type with the name ${e} has already been defined with a different constructor`)}return n}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,xt)}toJSON(){const e={};return this.share.forEach(((t,n)=>{e[n]=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,Ue(e.parent.doc,(n=>{const r=t.doc;e.deleted||n.subdocsAdded.add(r),n.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 re(this.clientDecoder.read(),this.leftClockDecoder.read())}readRightID(){return new re(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 K{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 j extends K{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 z{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 W extends z{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 F=(e,t,n)=>{const r=new Map;n.forEach(((e,n)=>{de(t,n)>e&&r.set(n,e)})),le(t).forEach(((e,t)=>{n.has(t)||r.set(t,0)})),h.writeVarUint(e.restEncoder,r.size),o.from(r.entries()).sort(((e,t)=>t[0]-e[0])).forEach((([n,r])=>{((e,t,n,r)=>{r=c.max(r,t[0].id.clock);const s=pe(t,r);h.writeVarUint(e.restEncoder,t.length-s),e.writeClient(n),h.writeVarUint(e.restEncoder,r);const i=t[s];i.write(e,r-i.id.clock);for(let n=s+1;n<t.length;n++)t[n].write(e,0)})(e,t.clients.get(n),n,r)}))},G=(e,t,n,r=q)=>{const s=l.createDecoder(t);((e,t,n,r=new q(e))=>{Ue(t,(e=>{e.local=!1;let t=!1;const n=e.doc,s=n.store,i=((e,t)=>{const n=a.create(),r=l.readVarUint(e.restDecoder);for(let s=0;s<r;s++){const r=l.readVarUint(e.restDecoder),s=new Array(r),i=e.readClient();let o=l.readVarUint(e.restDecoder);n.set(i,{i:0,refs:s});for(let n=0;n<r;n++){const r=e.readInfo();switch(f.BITS5&r){case 0:{const t=e.readLen();s[n]=new Pt(ie(i,o),t),o+=t;break}case 10:{const t=l.readVarUint(e.restDecoder);s[n]=new cn(ie(i,o),t),o+=t;break}default:{const c=!(r&(f.BIT7|f.BIT8)),a=new rn(ie(i,o),null,(r&f.BIT8)===f.BIT8?e.readLeftID():null,null,(r&f.BIT7)===f.BIT7?e.readRightID():null,c?e.readParentInfo()?t.get(e.readString()):e.readLeftID():null,c&&(r&f.BIT6)===f.BIT6?e.readString():null,sn(e,r));s[n]=a,o+=a.length}}}}return n})(r,n),c=((e,t,n)=>{const r=[];let s=o.from(n.keys()).sort(((e,t)=>e-t));if(0===s.length)return null;const i=()=>{if(0===s.length)return null;let e=n.get(s[s.length-1]);for(;e.refs.length===e.i;){if(s.pop(),!(s.length>0))return null;e=n.get(s[s.length-1])}return e};let c=i();if(null===c)return null;const l=new he,d=new Map,u=(e,t)=>{const n=d.get(e);(null==n||n>t)&&d.set(e,t)};let p=c.refs[c.i++];const g=new Map,f=()=>{for(const e of r){const t=e.id.client,r=n.get(t);r?(r.i--,l.clients.set(t,r.refs.slice(r.i)),n.delete(t),r.i=0,r.refs=[]):l.clients.set(t,[e]),s=s.filter((e=>e!==t))}r.length=0};for(;;){if(p.constructor!==cn){const s=a.setIfUndefined(g,p.id.client,(()=>de(t,p.id.client)))-p.id.clock;if(s<0)r.push(p),u(p.id.client,p.id.clock-1),f();else{const i=p.getMissing(e,t);if(null!==i){r.push(p);const e=n.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===s||s<p.length)&&(p.integrate(e,s),g.set(p.id.client,p.id.clock+p.length))}}if(r.length>0)p=r.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 W;return F(e,l,new Map),h.writeVarUint(e.restEncoder,0),{missing:d,update:e.toUint8Array()}}return null})(e,s,i),d=s.pendingStructs;if(d){for(const[e,n]of d.missing)if(n<de(s,e)){t=!0;break}if(c){for(const[e,t]of c.missing){const n=d.missing.get(e);(null==n||n>t)&&d.missing.set(e,t)}d.update=xe([d.update,c.update])}}else s.pendingStructs=c;const u=V(r,e,s);if(s.pendingDs){const t=new q(l.createDecoder(s.pendingDs));l.readVarUint(t.restDecoder);const n=V(t,e,s);s.pendingDs=u&&n?xe([u,n]):u||n}else s.pendingDs=u;if(t){const t=s.pendingStructs.update;s.pendingStructs=null,G(e.doc,t)}}),n,!1)})(s,e,n,new r(s))},H=(e,t,n)=>G(e,t,n,N),J=(e,t)=>((e,t=new Uint8Array([0]),n=new W)=>{((e,t,n=new Map)=>{F(e,t.store,n),R(e,E(t.store))})(n,e,Y(t));const r=[n.toUint8Array()];if(e.store.pendingDs&&r.push(e.store.pendingDs),e.store.pendingStructs&&r.push(Ee(e.store.pendingStructs.update,t)),r.length>1){if(n.constructor===j)return Te(r.map(((e,t)=>0===t?e:Oe(e))));if(n.constructor===W)return xe(r)}return r[0]})(e,t,new j),Y=e=>(e=>{const t=new Map,n=l.readVarUint(e.restDecoder);for(let r=0;r<n;r++){const n=l.readVarUint(e.restDecoder),r=l.readVarUint(e.restDecoder);t.set(n,r)}return t})(new B(l.createDecoder(e))),$=(e,t)=>(h.writeVarUint(e.restEncoder,t.size),o.from(t.entries()).sort(((e,t)=>t[0]-e[0])).forEach((([t,n])=>{h.writeVarUint(e.restEncoder,t),h.writeVarUint(e.restEncoder,n)})),e),Q=e=>((e,t=new z)=>(e instanceof Map?$(t,e):((e,t)=>{$(e,le(t.store))})(t,e),t.toUint8Array()))(e,new K);class Z{constructor(){this.l=[]}}const X=()=>new Z,ee=(e,t)=>e.l.push(t),te=(e,t)=>{const n=e.l,r=n.length;e.l=n.filter((e=>t!==e)),r===e.l.length&&console.error("[yjs] Tried to remove event handler that doesn't exist.")},ne=(e,t,n)=>w.callAll(e.l,[t,n]);class re{constructor(e,t){this.client=e,this.clock=t}}const se=(e,t)=>e===t||null!==e&&null!==t&&e.client===t.client&&e.clock===t.clock,ie=(e,t)=>new re(e,t);class oe{constructor(e,t){this.ds=e,this.sv=t}}const ce=(((e,t)=>{new oe(e,t)})(x(),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 n=a.setIfUndefined(e.meta,ae,y.create),r=e.doc.store;n.has(t)||(t.sv.forEach(((t,n)=>{t<de(r,n)&&we(e,ie(n,t))})),A(e,t.ds,(e=>{})),n.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,n)=>{const r=e[e.length-1];t.set(n,r.id.clock+r.length)})),t},de=(e,t)=>{const n=e.clients.get(t);if(void 0===n)return 0;const r=n[n.length-1];return r.id.clock+r.length},ue=(e,t)=>{let n=e.clients.get(t.id.client);if(void 0===n)n=[],e.clients.set(t.id.client,n);else{const e=n[n.length-1];if(e.id.clock+e.length!==t.id.clock)throw g.unexpectedCase()}n.push(t)},pe=(e,t)=>{let n=0,r=e.length-1,s=e[r],i=s.id.clock;if(i===t)return r;let o=c.floor(t/(i+s.length-1)*r);for(;n<=r;){if(s=e[o],i=s.id.clock,i<=t){if(t<i+s.length)return o;n=o+1}else r=o-1;o=c.floor((n+r)/2)}throw g.unexpectedCase()},ge=(e,t)=>{const n=e.clients.get(t.client);return n[pe(n,t.clock)]},fe=(e,t,n)=>{const r=pe(t,n),s=t[r];return s.id.clock<n&&s instanceof rn?(t.splice(r+1,0,nn(e,s,n-s.id.clock)),r+1):r},we=(e,t)=>{const n=e.doc.store.clients.get(t.client);return n[fe(e,n,t.clock)]},ye=(e,t,n)=>{const r=t.clients.get(n.client),s=pe(r,n.clock),i=r[s];return n.clock!==i.id.clock+i.length-1&&i.constructor!==Pt&&r.splice(s+1,0,nn(e,i,n.clock-i.id.clock+1)),i},_e=(e,t,n,r,s)=>{if(0===r)return;const i=n+r;let o,c=fe(e,t,n);do{o=t[c++],i<o.id.clock+o.length&&fe(e,t,i),s(o)}while(c<t.length&&t[c].id.clock<i)};class me{constructor(e,t,n){this.doc=e,this.deleteSet=new U,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=n,this.subdocsAdded=new Set,this.subdocsRemoved=new Set,this.subdocsLoaded=new Set,this._needFormattingCleanup=!1}}const Se=(e,t)=>!(0===t.deleteSet.clients.size&&!a.any(t.afterState,((e,n)=>t.beforeState.get(n)!==e))||(T(t.deleteSet),((e,t)=>{F(e,t.doc.store,t.beforeState)})(e,t),R(e,t.deleteSet),0)),be=(e,t,n)=>{const r=t._item;(null===r||r.id.clock<(e.beforeState.get(r.id.client)||0)&&!r.deleted)&&a.setIfUndefined(e.changed,t,y.create).add(n)},ke=(e,t)=>{let n=e[t],r=e[t-1],s=t;for(;s>0&&r.deleted===n.deleted&&r.constructor===n.constructor&&r.mergeWith(n);n=r,r=e[--s-1])n instanceof rn&&null!==n.parentSub&&n.parent._map.get(n.parentSub)===n&&n.parent._map.set(n.parentSub,r);const i=t-s;return i&&e.splice(t+1-i,i),i},ve=(e,t)=>{if(t<e.length){const n=e[t],r=n.doc,s=r.store,i=n.deleteSet,o=n._mergeStructs;try{T(i),n.afterState=le(n.doc.store),r.emit("beforeObserverCalls",[n,r]);const e=[];n.changed.forEach(((t,r)=>e.push((()=>{null!==r._item&&r._item.deleted||r._callObserver(n,t)})))),e.push((()=>{n.changedParentTypes.forEach(((t,r)=>{r._dEH.l.length>0&&(null===r._item||!r._item.deleted)&&((t=t.filter((e=>null===e.target._item||!e.target._item.deleted))).forEach((e=>{e.currentTarget=r,e._path=null})),t.sort(((e,t)=>e.path.length-t.path.length)),e.push((()=>{ne(r._dEH,t,n)})))})),e.push((()=>r.emit("afterTransaction",[n,r]))),e.push((()=>{n._needFormattingCleanup&&At(n)}))})),(0,w.callAll)(e,[])}finally{r.gc&&((e,t,n)=>{for(const[r,s]of e.clients.entries()){const e=t.clients.get(r);for(let r=s.length-1;r>=0;r--){const i=s[r],o=i.clock+i.len;for(let r=pe(e,i.clock),s=e[r];r<e.length&&s.id.clock<o;s=e[++r]){const s=e[r];if(i.clock+i.len<=s.id.clock)break;s instanceof rn&&s.deleted&&!s.keep&&n(s)&&s.gc(t,!1)}}}})(i,s,r.gcFilter),((e,t)=>{e.clients.forEach(((e,n)=>{const r=t.clients.get(n);for(let t=e.length-1;t>=0;t--){const n=e[t];for(let e=c.min(r.length-1,1+pe(r,n.clock+n.len-1)),t=r[e];e>0&&t.id.clock>=n.clock;t=r[e])e-=1+ke(r,e)}}))})(i,s),n.afterState.forEach(((e,t)=>{const r=n.beforeState.get(t)||0;if(r!==e){const e=s.clients.get(t),n=c.max(pe(e,r),1);for(let t=e.length-1;t>=n;)t-=1+ke(e,t)}}));for(let e=o.length-1;e>=0;e--){const{client:t,clock:n}=o[e].id,r=s.clients.get(t),i=pe(r,n);i+1<r.length&&ke(r,i+1)>1||i>0&&ke(r,i)}if(n.local||n.afterState.get(r.clientID)===n.beforeState.get(r.clientID)||(_.print(m.ORANGE,m.BOLD,"[yjs] ",m.UNBOLD,m.RED,"Changed the client-id because another client seems to be using it."),r.clientID=O()),r.emit("afterTransactionCleanup",[n,r]),r._observers.has("update")){const e=new j;Se(e,n)&&r.emit("update",[e.toUint8Array(),n.origin,r,n])}if(r._observers.has("updateV2")){const e=new W;Se(e,n)&&r.emit("updateV2",[e.toUint8Array(),n.origin,r,n])}const{subdocsAdded:a,subdocsLoaded:h,subdocsRemoved:l}=n;(a.size>0||l.size>0||h.size>0)&&(a.forEach((e=>{e.clientID=r.clientID,null==e.collectionid&&(e.collectionid=r.collectionid),r.subdocs.add(e)})),l.forEach((e=>r.subdocs.delete(e))),r.emit("subdocs",[{loaded:h,added:a,removed:l},r,n]),l.forEach((e=>e.destroy()))),e.length<=t+1?(r._transactionCleanups=[],r.emit("afterAllTransactions",[r,e])):ve(e,t+1)}}},Ue=(e,t,n=null,r=!0)=>{const s=e._transactionCleanups;let i=!1,o=null;null===e._transaction&&(i=!0,e._transaction=new me(e,n,r),s.push(e._transaction),1===s.length&&e.emit("beforeAllTransactions",[e]),e.emit("beforeTransaction",[e._transaction,e]));try{o=t(e._transaction)}finally{if(i){const t=e._transaction===s[0];e._transaction=null,t&&ve(s,0)}}return o};i.ObservableV2;class Ae{constructor(e,t){this.gen=function*(e){const t=l.readVarUint(e.restDecoder);for(let n=0;n<t;n++){const t=l.readVarUint(e.restDecoder),n=e.readClient();let r=l.readVarUint(e.restDecoder);for(let s=0;s<t;s++){const t=e.readInfo();if(10===t){const t=l.readVarUint(e.restDecoder);yield new cn(ie(n,r),t),r+=t}else if(f.BITS5&t){const s=!(t&(f.BIT7|f.BIT8)),i=new rn(ie(n,r),null,(t&f.BIT8)===f.BIT8?e.readLeftID():null,null,(t&f.BIT7)===f.BIT7?e.readRightID():null,s?e.readParentInfo()?e.readString():e.readLeftID():null,s&&(t&f.BIT6)===f.BIT6?e.readString():null,sn(e,t));yield i,r+=i.length}else{const t=e.readLen();yield new Pt(ie(n,r),t),r+=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===cn);return this.curr}}class Ce{constructor(e){this.currClient=0,this.startClock=0,this.written=0,this.encoder=e,this.clientStructs=[]}}const Te=e=>xe(e,N,j),Ie=e=>((e,t=q)=>{const n=new Map,r=new Map,s=new Ae(new t(l.createDecoder(e)),!1);let i=s.curr;if(null!==i){let e=i.id.client,t=i.id.clock;for(n.set(e,t);null!==i;i=s.next())e!==i.id.client&&(r.set(e,t),n.set(i.id.client,i.id.clock),e=i.id.client),t=i.id.clock+i.length;r.set(e,t)}return{from:n,to:r}})(e,N),De=(e,t)=>{if(e.constructor===Pt){const{client:n,clock:r}=e.id;return new Pt(ie(n,r+t),e.length-t)}if(e.constructor===cn){const{client:n,clock:r}=e.id;return new cn(ie(n,r+t),e.length-t)}{const n=e,{client:r,clock:s}=n.id;return new rn(ie(r,s+t),null,ie(r,s+t-1),null,n.rightOrigin,n.parent,n.parentSub,n.content.splice(t))}},xe=(e,t=q,n=W)=>{if(1===e.length)return e[0];const r=e.map((e=>new t(l.createDecoder(e))));let s=r.map((e=>new Ae(e,!0))),i=null;const o=new n,c=new Ce(o);for(;s=s.filter((e=>null!==e.curr)),s.sort(((e,t)=>{if(e.curr.id.client===t.curr.id.client){const n=e.curr.id.clock-t.curr.id.clock;return 0===n?e.curr.constructor===t.curr.constructor?0:e.curr.constructor===cn?1:-1:n}return t.curr.id.client-e.curr.id.client})),0!==s.length;){const e=s[0],t=e.curr.id.client;if(null!==i){let n=e.curr,r=!1;for(;null!==n&&n.id.clock+n.length<=i.struct.id.clock+i.struct.length&&n.id.client>=i.struct.id.client;)n=e.next(),r=!0;if(null===n||n.id.client!==t||r&&n.id.clock>i.struct.id.clock+i.struct.length)continue;if(t!==i.struct.id.client)Me(c,i.struct,i.offset),i={struct:n,offset:0},e.next();else if(i.struct.id.clock+i.struct.length<n.id.clock)if(i.struct.constructor===cn)i.struct.length=n.id.clock+n.length-i.struct.id.clock;else{Me(c,i.struct,i.offset);const e=n.id.clock-i.struct.id.clock-i.struct.length;i={struct:new cn(ie(t,i.struct.id.clock+i.struct.length),e),offset:0}}else{const t=i.struct.id.clock+i.struct.length-n.id.clock;t>0&&(i.struct.constructor===cn?i.struct.length-=t:n=De(n,t)),i.struct.mergeWith(n)||(Me(c,i.struct,i.offset),i={struct:n,offset:0},e.next())}}else i={struct:e.curr,offset:0},e.next();for(let n=e.curr;null!==n&&n.id.client===t&&n.id.clock===i.struct.id.clock+i.struct.length&&n.constructor!==cn;n=e.next())Me(c,i.struct,i.offset),i={struct:n,offset:0}}null!==i&&(Me(c,i.struct,i.offset),i=null),Ve(c);const a=r.map((e=>M(e))),h=I(a);return R(o,h),o.toUint8Array()},Ee=(e,t,n=q,r=W)=>{const s=Y(t),i=new r,o=new Ce(i),a=new n(l.createDecoder(e)),h=new Ae(a,!1);for(;h.curr;){const e=h.curr,t=e.id.client,n=s.get(t)||0;if(h.curr.constructor!==cn)if(e.id.clock+e.length>n)for(Me(o,e,c.max(n-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<=n;)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,n)=>{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+n)),t.write(e.encoder,n),e.written++},Ve=e=>{Re(e);const t=e.encoder.restEncoder;h.writeVarUint(t,e.clientStructs.length);for(let n=0;n<e.clientStructs.length;n++){const r=e.clientStructs[n];h.writeVarUint(t,r.written),h.writeUint8Array(t,r.restEncoder)}},Oe=e=>((e,t,n,r)=>{const s=new n(l.createDecoder(e)),i=new Ae(s,!1),o=new r,c=new Ce(o);for(let e=i.curr;null!==e;e=i.next())Me(c,t(e),0);Ve(c);const a=M(s);return R(o,a),o.toUint8Array()})(e,w.id,q,j),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((n=>{if(null!==n){const r=t._map.get(n);let s,i;if(this.adds(r)){let e=r.left;for(;null!==e&&this.adds(e);)e=e.left;if(this.deletes(r)){if(null===e||!this.deletes(e))return;s="delete",i=o.last(e.content.getContent())}else null!==e&&this.deletes(e)?(s="update",i=o.last(e.content.getContent())):(s="add",i=void 0)}else{if(!this.deletes(r))return;s="delete",i=o.last(r.content.getContent())}e.set(n,{action:s,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,n=y.create(),r=y.create(),s=[];if(e={added:n,deleted:r,delta:s,keys:this.keys},this.transaction.changed.get(t).has(null)){let e=null;const i=()=>{e&&s.push(e)};for(let s=t._start;null!==s;s=s.right)s.deleted?this.deletes(s)&&!this.adds(s)&&(null!==e&&void 0!==e.delete||(i(),e={delete:0}),e.delete+=s.length,r.add(s)):this.adds(s)?(null!==e&&void 0!==e.insert||(i(),e={insert:[]}),e.insert=e.insert.concat(s.content.getContent()),n.add(s)):(null!==e&&void 0!==e.retain||(i(),e={retain:0}),e.retain+=s.length);null!==e&&void 0===e.retain&&i()}this._changes=e}return e}}const Ne=(e,t)=>{const n=[];for(;null!==t._item&&t!==e;){if(null!==t._item.parentSub)n.unshift(t._item.parentSub);else{let e=0,r=t._item.parent._start;for(;r!==t._item&&null!==r;)!r.deleted&&r.countable&&(e+=r.length),r=r.right;n.unshift(e)}t=t._item.parent}return n},Le=()=>{_.warn("Invalid access: Add Yjs type to a document before reading data.")};let qe=0;class Ke{constructor(e,t){e.marker=!0,this.p=e,this.index=t,this.timestamp=qe++}}const je=(e,t,n)=>{e.p.marker=!1,e.p=t,t.marker=!0,e.index=n,e.timestamp=qe++},ze=(e,t)=>{if(null===e._start||0===t||null===e._searchMarker)return null;const n=0===e._searchMarker.length?null:e._searchMarker.reduce(((e,n)=>c.abs(t-e.index)<c.abs(t-n.index)?e:n));let r=e._start,s=0;for(null!==n&&(r=n.p,s=n.index,(e=>{e.timestamp=qe++})(n));null!==r.right&&s<t;){if(!r.deleted&&r.countable){if(t<s+r.length)break;s+=r.length}r=r.right}for(;null!==r.left&&s>t;)r=r.left,!r.deleted&&r.countable&&(s-=r.length);for(;null!==r.left&&r.left.id.client===r.id.client&&r.left.id.clock+r.left.length===r.id.clock;)r=r.left,!r.deleted&&r.countable&&(s-=r.length);return null!==n&&c.abs(n.index-s)<r.parent.length/80?(je(n,r,s),n):((e,t,n)=>{if(e.length>=80){const r=e.reduce(((e,t)=>e.timestamp<t.timestamp?e:t));return je(r,t,n),r}{const r=new Ke(t,n);return e.push(r),r}})(e._searchMarker,r,s)},We=(e,t,n)=>{for(let r=e.length-1;r>=0;r--){const s=e[r];if(n>0){let t=s.p;for(t.marker=!1;t&&(t.deleted||!t.countable);)t=t.left,t&&!t.deleted&&t.countable&&(s.index-=t.length);if(null===t||!0===t.marker){e.splice(r,1);continue}s.p=t,t.marker=!0}(t<s.index||n>0&&t===s.index)&&(s.index=c.max(t,s.index+n))}},Fe=(e,t,n)=>{const r=e,s=t.changedParentTypes;for(;a.setIfUndefined(s,e,(()=>[])).push(n),null!==e._item;)e=e._item.parent;ne(r._eH,n,t)};class Ge{constructor(){this._item=null,this._map=new Map,this._start=null,this.doc=null,this._length=0,this._eH=X(),this._dEH=X(),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 He=(e,t,n)=>{e.doc??Le(),t<0&&(t=e._length+t),n<0&&(n=e._length+n);let r=n-t;const s=[];let i=e._start;for(;null!==i&&r>0;){if(i.countable&&!i.deleted){const e=i.content.getContent();if(e.length<=t)t-=e.length;else{for(let n=t;n<e.length&&r>0;n++)s.push(e[n]),r--;t=0}}i=i.right}return s},Je=e=>{e.doc??Le();const t=[];let n=e._start;for(;null!==n;){if(n.countable&&!n.deleted){const e=n.content.getContent();for(let n=0;n<e.length;n++)t.push(e[n])}n=n.right}return t},Ye=(e,t)=>{let n=0,r=e._start;for(e.doc??Le();null!==r;){if(r.countable&&!r.deleted){const s=r.content.getContent();for(let r=0;r<s.length;r++)t(s[r],n++,e)}r=r.right}},$e=(e,t)=>{const n=[];return Ye(e,((r,s)=>{n.push(t(r,s,e))})),n},Qe=e=>{let t=e._start,n=null,r=0;return{[Symbol.iterator](){return this},next:()=>{if(null===n){for(;null!==t&&t.deleted;)t=t.right;if(null===t)return{done:!0,value:void 0};n=t.content.getContent(),r=0,t=t.right}const e=n[r++];return n.length<=r&&(n=null),{done:!1,value:e}}}},Ze=(e,t)=>{e.doc??Le();const n=ze(e,t);let r=e._start;for(null!==n&&(r=n.p,t-=n.index);null!==r;r=r.right)if(!r.deleted&&r.countable){if(t<r.length)return r.content.getContent()[t];t-=r.length}},Xe=(e,t,n,r)=>{let s=n;const i=e.doc,o=i.clientID,c=i.store,a=null===n?t._start:n.right;let h=[];const l=()=>{h.length>0&&(s=new rn(ie(o,de(c,o)),s,s&&s.lastId,a,a&&a.id,t,null,new Ft(h)),s.integrate(e,0),h=[])};r.forEach((n=>{if(null===n)h.push(n);else switch(n.constructor){case Number:case Object:case Boolean:case Array:case String:h.push(n);break;default:switch(l(),n.constructor){case Uint8Array:case ArrayBuffer:s=new rn(ie(o,de(c,o)),s,s&&s.lastId,a,a&&a.id,t,null,new Bt(new Uint8Array(n))),s.integrate(e,0);break;case P:s=new rn(ie(o,de(c,o)),s,s&&s.lastId,a,a&&a.id,t,null,new qt(n)),s.integrate(e,0);break;default:if(!(n instanceof Ge))throw new Error("Unexpected content type in insert operation");s=new rn(ie(o,de(c,o)),s,s&&s.lastId,a,a&&a.id,t,null,new tn(n)),s.integrate(e,0)}}})),l()},et=()=>g.create("Length exceeded!"),tt=(e,t,n,r)=>{if(n>t._length)throw et();if(0===n)return t._searchMarker&&We(t._searchMarker,n,r.length),Xe(e,t,null,r);const s=n,i=ze(t,n);let o=t._start;for(null!==i&&(o=i.p,0==(n-=i.index)&&(o=o.prev,n+=o&&o.countable&&!o.deleted?o.length:0));null!==o;o=o.right)if(!o.deleted&&o.countable){if(n<=o.length){n<o.length&&we(e,ie(o.id.client,o.id.clock+n));break}n-=o.length}return t._searchMarker&&We(t._searchMarker,s,r.length),Xe(e,t,o,r)},nt=(e,t,n,r)=>{if(0===r)return;const s=n,i=r,o=ze(t,n);let c=t._start;for(null!==o&&(c=o.p,n-=o.index);null!==c&&n>0;c=c.right)!c.deleted&&c.countable&&(n<c.length&&we(e,ie(c.id.client,c.id.clock+n)),n-=c.length);for(;r>0&&null!==c;)c.deleted||(r<c.length&&we(e,ie(c.id.client,c.id.clock+r)),c.delete(e),r-=c.length),c=c.right;if(r>0)throw et();t._searchMarker&&We(t._searchMarker,s,-i+r)},rt=(e,t,n)=>{const r=t._map.get(n);void 0!==r&&r.delete(e)},st=(e,t,n,r)=>{const s=t._map.get(n)||null,i=e.doc,o=i.clientID;let c;if(null==r)c=new Ft([r]);else switch(r.constructor){case Number:case Object:case Boolean:case Array:case String:case Date:case BigInt:c=new Ft([r]);break;case Uint8Array:c=new Bt(r);break;case P:c=new qt(r);break;default:if(!(r instanceof Ge))throw new Error("Unexpected content type");c=new tn(r)}new rn(ie(o,de(i.store,o)),s,s&&s.lastId,null,null,t,n,c).integrate(e,0)},it=(e,t)=>{e.doc??Le();const n=e._map.get(t);return void 0===n||n.deleted?void 0:n.content.getContent()[n.length-1]},ot=e=>{const t={};return e.doc??Le(),e._map.forEach(((e,n)=>{e.deleted||(t[n]=e.content.getContent()[e.length-1])})),t},ct=(e,t)=>{e.doc??Le();const n=e._map.get(t);return void 0!==n&&!n.deleted},at=e=>(e.doc??Le(),S.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),Fe(this,e,new ht(this,e))}insert(e,t){null!==this.doc?Ue(this.doc,(n=>{tt(n,this,e,t)})):this._prelimContent.splice(e,0,...t)}push(e){null!==this.doc?Ue(this.doc,(t=>{((e,t,n)=>{let r=(t._searchMarker||[]).reduce(((e,t)=>t.index>e.index?t:e),{index:0,p:t._start}).p;if(r)for(;r.right;)r=r.right;Xe(e,t,r,n)})(t,this,e)})):this._prelimContent.push(...e)}unshift(e){this.insert(0,e)}delete(e,t=1){null!==this.doc?Ue(this.doc,(n=>{nt(n,this,e,t)})):this._prelimContent.splice(e,t)}get(e){return Ze(this,e)}toArray(){return Je(this)}slice(e=0,t=this.length){return He(this,e,t)}toJSON(){return this.map((e=>e instanceof Ge?e.toJSON():e))}map(e){return $e(this,e)}forEach(e){Ye(this,e)}[Symbol.iterator](){return Qe(this)}_write(e){e.writeTypeRef(Jt)}}class dt extends Be{constructor(e,t,n){super(e,t),this.keysChanged=n}}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,n)=>{e.set(n,t instanceof Ge?t.clone():t)})),e}_callObserver(e,t){Fe(this,e,new dt(this,e,t))}toJSON(){this.doc??Le();const e={};return this._map.forEach(((t,n)=>{if(!t.deleted){const r=t.content.getContent()[t.length-1];e[n]=r instanceof Ge?r.toJSON():r}})),e}get size(){return[...at(this)].length}keys(){return S.iteratorMap(at(this),(e=>e[0]))}values(){return S.iteratorMap(at(this),(e=>e[1].content.getContent()[e[1].length-1]))}entries(){return S.iteratorMap(at(this),(e=>[e[0],e[1].content.getContent()[e[1].length-1]]))}forEach(e){this.doc??Le(),this._map.forEach(((t,n)=>{t.deleted||e(t.content.getContent()[t.length-1],n,this)}))}[Symbol.iterator](){return this.entries()}delete(e){null!==this.doc?Ue(this.doc,(t=>{rt(t,this,e)})):this._prelimContent.delete(e)}set(e,t){return null!==this.doc?Ue(this.doc,(n=>{st(n,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?Ue(this.doc,(e=>{this.forEach((function(t,n,r){rt(e,r,n)}))})):this._prelimContent.clear()}_write(e){e.writeTypeRef(Yt)}}const pt=(e,t)=>e===t||"object"==typeof e&&"object"==typeof t&&e&&t&&b.equalFlat(e,t);class gt{constructor(e,t,n,r){this.left=e,this.right=t,this.index=n,this.currentAttributes=r}forward(){null===this.right&&g.unexpectedCase(),this.right.content.constructor===jt?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,n)=>{for(;null!==t.right&&n>0;)t.right.content.constructor===jt?t.right.deleted||_t(t.currentAttributes,t.right.content):t.right.deleted||(n<t.right.length&&we(e,ie(t.right.id.client,t.right.id.clock+n)),t.index+=t.right.length,n-=t.right.length),t.left=t.right,t.right=t.right.right;return t},wt=(e,t,n,r)=>{const s=new Map,i=r?ze(t,n):null;if(i){const t=new gt(i.p.left,i.p,i.index,s);return ft(e,t,n-i.index)}{const r=new gt(null,t._start,0,s);return ft(e,r,n)}},yt=(e,t,n,r)=>{for(;null!==n.right&&(!0===n.right.deleted||n.right.content.constructor===jt&&pt(r.get(n.right.content.key),n.right.content.value));)n.right.deleted||r.delete(n.right.content.key),n.forward();const s=e.doc,i=s.clientID;r.forEach(((r,o)=>{const c=n.left,a=n.right,h=new rn(ie(i,de(s.store,i)),c,c&&c.lastId,a,a&&a.id,t,null,new jt(o,r));h.integrate(e,0),n.right=h,n.forward()}))},_t=(e,t)=>{const{key:n,value:r}=t;null===r?e.delete(n):e.set(n,r)},mt=(e,t)=>{for(;null!==e.right&&(e.right.deleted||e.right.content.constructor===jt&&pt(t[e.right.content.key]??null,e.right.content.value));)e.forward()},St=(e,t,n,r)=>{const s=e.doc,i=s.clientID,o=new Map;for(const c in r){const a=r[c],h=n.currentAttributes.get(c)??null;if(!pt(h,a)){o.set(c,h);const{left:r,right:l}=n;n.right=new rn(ie(i,de(s.store,i)),r,r&&r.lastId,l,l&&l.id,t,null,new jt(c,a)),n.right.integrate(e,0),n.forward()}}return o},bt=(e,t,n,r,s)=>{n.currentAttributes.forEach(((e,t)=>{void 0===s[t]&&(s[t]=null)}));const i=e.doc,o=i.clientID;mt(n,s);const c=St(e,t,n,s),a=r.constructor===String?new Gt(r):r instanceof Ge?new tn(r):new Kt(r);let{left:h,right:l,index:d}=n;t._searchMarker&&We(t._searchMarker,n.index,a.getLength()),l=new rn(ie(o,de(i.store,o)),h,h&&h.lastId,l,l&&l.id,t,null,a),l.integrate(e,0),n.right=l,n.index=d,n.forward(),yt(e,t,n,c)},kt=(e,t,n,r,s)=>{const i=e.doc,o=i.clientID;mt(n,s);const c=St(e,t,n,s);e:for(;null!==n.right&&(r>0||c.size>0&&(n.right.deleted||n.right.content.constructor===jt));){if(!n.right.deleted)switch(n.right.content.constructor){case jt:{const{key:t,value:i}=n.right.content,o=s[t];if(void 0!==o){if(pt(o,i))c.delete(t);else{if(0===r)break e;c.set(t,i)}n.right.delete(e)}else n.currentAttributes.set(t,i);break}default:r<n.right.length&&we(e,ie(n.right.id.client,n.right.id.clock+r)),r-=n.right.length}n.forward()}if(r>0){let s="";for(;r>0;r--)s+="\n";n.right=new rn(ie(o,de(i.store,o)),n.left,n.left&&n.left.lastId,n.right,n.right&&n.right.id,t,null,new Gt(s)),n.right.integrate(e,0),n.forward()}yt(e,t,n,c)},vt=(e,t,n,r,s)=>{let i=t;const o=a.create();for(;i&&(!i.countable||i.deleted);){if(!i.deleted&&i.content.constructor===jt){const e=i.content;o.set(e.key,e)}i=i.right}let c=0,h=!1;for(;t!==i;){if(n===t&&(h=!0),!t.deleted){const n=t.content;switch(n.constructor){case jt:{const{key:i,value:a}=n,l=r.get(i)??null;o.get(i)===n&&l!==a||(t.delete(e),c++,h||(s.get(i)??null)!==a||l===a||(null===l?s.delete(i):s.set(i,l))),h||t.deleted||_t(s,n);break}}}t=t.right}return c},Ut=e=>{let t=0;return Ue(e.doc,(n=>{let r=e._start,s=e._start,i=a.create();const o=a.copy(i);for(;s;)!1===s.deleted&&(s.content.constructor===jt?_t(o,s.content):(t+=vt(n,r,s,i,o),i=a.copy(o),r=s)),s=s.right})),t},At=e=>{const t=new Set,n=e.doc;for(const[r,s]of e.afterState.entries()){const i=e.beforeState.get(r)||0;s!==i&&_e(e,n.store.clients.get(r),i,s,(e=>{e.deleted||e.content.constructor!==jt||e.constructor===Pt||t.add(e.parent)}))}Ue(n,(n=>{A(e,e.deleteSet,(e=>{if(e instanceof Pt||!e.parent._hasFormatting||t.has(e.parent))return;const r=e.parent;e.content.constructor===jt?t.add(r):((e,t)=>{for(;t&&t.right&&(t.right.deleted||!t.right.countable);)t=t.right;const n=new Set;for(;t&&(t.deleted||!t.countable);){if(!t.deleted&&t.content.constructor===jt){const r=t.content.key;n.has(r)?t.delete(e):n.add(r)}t=t.left}})(n,e)}));for(const e of t)Ut(e)}))},Ct=(e,t,n)=>{const r=n,s=a.copy(t.currentAttributes),i=t.right;for(;n>0&&null!==t.right;){if(!1===t.right.deleted)switch(t.right.content.constructor){case tn:case Kt:case Gt:n<t.right.length&&we(e,ie(t.right.id.client,t.right.id.clock+n)),n-=t.right.length,t.right.delete(e)}t.forward()}i&&vt(e,i,t.right,s,t.currentAttributes);const o=(t.left||t.right).parent;return o._searchMarker&&We(o._searchMarker,t.index,-r+n),t};class Tt extends Be{constructor(e,t,n){super(e,t),this.childListChanged=!1,this.keysChanged=new Set,n.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=[];Ue(e,(e=>{const n=new Map,r=new Map;let s=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},n.size>0&&(e.attributes={},n.forEach(((t,n)=>{null!==t&&(e.attributes[n]=t)})))),c="";break;case"retain":a>0&&(e={retain:a},b.isEmpty(o)||(e.attributes=b.assign({},o))),a=0}e&&t.push(e),i=null}};for(;null!==s;){switch(s.content.constructor){case tn:case Kt:this.adds(s)?this.deletes(s)||(l(),i="insert",c=s.content.getContent()[0],l()):this.deletes(s)?("delete"!==i&&(l(),i="delete"),h+=1):s.deleted||("retain"!==i&&(l(),i="retain"),a+=1);break;case Gt:this.adds(s)?this.deletes(s)||("insert"!==i&&(l(),i="insert"),c+=s.content.str):this.deletes(s)?("delete"!==i&&(l(),i="delete"),h+=s.length):s.deleted||("retain"!==i&&(l(),i="retain"),a+=s.length);break;case jt:{const{key:t,value:c}=s.content;if(this.adds(s)){if(!this.deletes(s)){const a=n.get(t)??null;pt(a,c)?null!==c&&s.delete(e):("retain"===i&&l(),pt(c,r.get(t)??null)?delete o[t]:o[t]=c)}}else if(this.deletes(s)){r.set(t,c);const e=n.get(t)??null;pt(e,c)||("retain"===i&&l(),o[t]=e)}else if(!s.deleted){r.set(t,c);const n=o[t];void 0!==n&&(pt(n,c)?null!==n&&s.delete(e):("retain"===i&&l(),null===c?delete o[t]:o[t]=c))}s.deleted||("insert"===i&&l(),_t(n,s.content));break}}s=s.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 n=new Tt(this,e,t);Fe(this,e,n),!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?Ue(this.doc,(n=>{const r=new gt(null,this._start,0,new Map);for(let s=0;s<e.length;s++){const i=e[s];if(void 0!==i.insert){const o=t||"string"!=typeof i.insert||s!==e.length-1||null!==r.right||"\n"!==i.insert.slice(-1)?i.insert:i.insert.slice(0,-1);("string"!=typeof o||o.length>0)&&bt(n,this,r,o,i.attributes||{})}else void 0!==i.retain?kt(n,this,r,i.retain,i.attributes||{}):void 0!==i.delete&&Ct(n,r,i.delete)}})):this._pending.push((()=>this.applyDelta(e)))}toDelta(e,t,n){this.doc??Le();const r=[],s=new Map,i=this.doc;let o="",c=this._start;function a(){if(o.length>0){const e={};let t=!1;s.forEach(((n,r)=>{t=!0,e[r]=n}));const n={insert:o};t&&(n.attributes=e),r.push(n),o=""}}const h=()=>{for(;null!==c;){if(ce(c,e)||void 0!==t&&ce(c,t))switch(c.content.constructor){case Gt:{const r=s.get("ychange");void 0===e||ce(c,e)?void 0===t||ce(c,t)?void 0!==r&&(a(),s.delete("ychange")):void 0!==r&&r.user===c.id.client&&"added"===r.type||(a(),s.set("ychange",n?n("added",c.id):{type:"added"})):void 0!==r&&r.user===c.id.client&&"removed"===r.type||(a(),s.set("ychange",n?n("removed",c.id):{type:"removed"})),o+=c.content.str;break}case tn:case Kt:{a();const e={insert:c.content.getContent()[0]};if(s.size>0){const t={};e.attributes=t,s.forEach(((e,n)=>{t[n]=e}))}r.push(e);break}case jt:ce(c,e)&&(a(),_t(s,c.content))}c=c.right}a()};return e||t?Ue(i,(n=>{e&&ae(n,e),t&&ae(n,t),h()}),"cleanup"):h(),r}insert(e,t,n){if(t.length<=0)return;const r=this.doc;null!==r?Ue(r,(r=>{const s=wt(r,this,e,!n);n||(n={},s.currentAttributes.forEach(((e,t)=>{n[t]=e}))),bt(r,this,s,t,n)})):this._pending.push((()=>this.insert(e,t,n)))}insertEmbed(e,t,n){const r=this.doc;null!==r?Ue(r,(r=>{const s=wt(r,this,e,!n);bt(r,this,s,t,n||{})})):this._pending.push((()=>this.insertEmbed(e,t,n||{})))}delete(e,t){if(0===t)return;const n=this.doc;null!==n?Ue(n,(n=>{Ct(n,wt(n,this,e,!0),t)})):this._pending.push((()=>this.delete(e,t)))}format(e,t,n){if(0===t)return;const r=this.doc;null!==r?Ue(r,(r=>{const s=wt(r,this,e,!1);null!==s.right&&kt(r,this,s,t,n)})):this._pending.push((()=>this.format(e,t,n)))}removeAttribute(e){null!==this.doc?Ue(this.doc,(t=>{rt(t,this,e)})):this._pending.push((()=>this.removeAttribute(e)))}setAttribute(e,t){null!==this.doc?Ue(this.doc,(n=>{st(n,this,e,t)})):this._pending.push((()=>this.setAttribute(e,t)))}getAttribute(e){return it(this,e)}getAttributes(){return ot(this)}_write(e){e.writeTypeRef($t)}}class Dt{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!==xt||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 xt 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 xt}clone(){const e=new xt;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 Dt(this,e)}querySelector(e){e=e.toUpperCase();const t=new Dt(this,(t=>t.nodeName&&t.nodeName.toUpperCase()===e)).next();return t.done?null:t.value}querySelectorAll(e){return e=e.toUpperCase(),o.from(new Dt(this,(t=>t.nodeName&&t.nodeName.toUpperCase()===e)))}_callObserver(e,t){Fe(this,e,new Rt(this,t,e))}toString(){return $e(this,(e=>e.toString())).join("")}toJSON(){return this.toString()}toDOM(e=document,t={},n){const r=e.createDocumentFragment();return void 0!==n&&n._createAssociation(r,this),Ye(this,(s=>{r.insertBefore(s.toDOM(e,t,n),null)})),r}insert(e,t){null!==this.doc?Ue(this.doc,(n=>{tt(n,this,e,t)})):this._prelimContent.splice(e,0,...t)}insertAfter(e,t){if(null!==this.doc)Ue(this.doc,(n=>{const r=e&&e instanceof Ge?e._item:e;Xe(n,this,r,t)}));else{const n=this._prelimContent,r=null===e?0:n.findIndex((t=>t===e))+1;if(0===r&&null!==e)throw g.create("Reference item not found");n.splice(r,0,...t)}}delete(e,t=1){null!==this.doc?Ue(this.doc,(n=>{nt(n,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 Ze(this,e)}slice(e=0,t=this.length){return He(this,e,t)}forEach(e){Ye(this,e)}_write(e){e.writeTypeRef(Zt)}}class Et extends xt{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 b.forEach(t,((t,n)=>{e.setAttribute(n,t)})),e.insert(0,this.toArray().map((e=>e instanceof Ge?e.clone():e))),e}toString(){const e=this.getAttributes(),t=[],n=[];for(const t in e)n.push(t);n.sort();const r=n.length;for(let s=0;s<r;s++){const r=n[s];t.push(r+'="'+e[r]+'"')}const s=this.nodeName.toLocaleLowerCase();return`<${s}${t.length>0?" "+t.join(" "):""}>${super.toString()}</${s}>`}removeAttribute(e){null!==this.doc?Ue(this.doc,(t=>{rt(t,this,e)})):this._prelimAttrs.delete(e)}setAttribute(e,t){null!==this.doc?Ue(this.doc,(n=>{st(n,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 n={};return this._map.forEach(((e,r)=>{let s=e;for(;null!==s&&(!t.sv.has(s.id.client)||s.id.clock>=(t.sv.get(s.id.client)||0));)s=s.left;null!==s&&ce(s,t)&&(n[r]=s.content.getContent()[s.length-1])})),n})(0,e):ot(this)}toDOM(e=document,t={},n){const r=e.createElement(this.nodeName),s=this.getAttributes();for(const e in s){const t=s[e];"string"==typeof t&&r.setAttribute(e,t)}return Ye(this,(s=>{r.appendChild(s.toDOM(e,t,n))})),void 0!==n&&n._createAssociation(r,this),r}_write(e){e.writeTypeRef(Qt),e.writeKey(this.nodeName)}}class Rt extends Be{constructor(e,t,n){super(e,n),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,n)=>{e.set(n,t)})),e}toDOM(e=document,t={},n){const r=t[this.hookName];let s;return s=void 0!==r?r.createDom(this):document.createElement(this.hookName),s.setAttribute("data-yjs-hook",this.hookName),void 0!==n&&n._createAssociation(s,this),s}_write(e){e.writeTypeRef(Xt),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,n){const r=e.createTextNode(this.toString());return void 0!==n&&n._createAssociation(r,this),r}toString(){return this.toDelta().map((e=>{const t=[];for(const n in e.attributes){const r=[];for(const t in e.attributes[n])r.push({key:t,value:e.attributes[n][t]});r.sort(((e,t)=>e.key<t.key?-1:1)),t.push({nodeName:n,attrs:r})}t.sort(((e,t)=>e.nodeName<t.nodeName?-1:1));let n="";for(let e=0;e<t.length;e++){const r=t[e];n+=`<${r.nodeName}`;for(let e=0;e<r.attrs.length;e++){const t=r.attrs[e];n+=` ${t.key}="${t.value}"`}n+=">"}n+=e.insert;for(let e=t.length-1;e>=0;e--)n+=`</${t[e].nodeName}>`;return n})).join("")}toJSON(){return this.toString()}_write(e){e.writeTypeRef(en)}}class Ot{constructor(e,t){this.id=e,this.length=t}get deleted(){throw g.methodUnimplemented()}mergeWith(e){return!1}write(e,t,n){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){D(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 Kt{constructor(e){this.embed=e}getLength(){return 1}getContent(){return[this.embed]}isCountable(){return!0}copy(){return new Kt(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 jt{constructor(e,t){this.key=e,this.value=t}getLength(){return 1}getContent(){return[]}isCountable(){return!1}copy(){return new jt(this.key,this.value)}splice(e){throw g.methodUnimplemented()}mergeWith(e){return!1}integrate(e,t){const n=t.parent;n._searchMarker=null,n._hasFormatting=!0}delete(e){}gc(e){}write(e,t){e.writeKey(this.key),e.writeJSON(this.value)}getRef(){return 6}}class zt{constructor(e){this.arr=e}getLength(){return this.arr.length}getContent(){return this.arr}isCountable(){return!0}copy(){return new zt(this.arr)}splice(e){const t=new zt(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 n=this.arr.length;e.writeLen(n-t);for(let r=t;r<n;r++){const t=this.arr[r];e.writeString(void 0===t?"undefined":JSON.stringify(t))}}getRef(){return 2}}const Wt="development"===k.getVariable("node_env");class Ft{constructor(e){this.arr=e,Wt&&b.deepFreeze(e)}getLength(){return this.arr.length}getContent(){return this.arr}isCountable(){return!0}copy(){return new Ft(this.arr)}splice(e){const t=new Ft(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 n=this.arr.length;e.writeLen(n-t);for(let r=t;r<n;r++){const t=this.arr[r];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 n=this.str.charCodeAt(e-1);return n>=55296&&n<=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 Ht=[e=>new lt,e=>new ut,e=>new It,e=>new Et(e.readKey()),e=>new xt,e=>new Mt(e.readKey()),e=>new Vt],Jt=0,Yt=1,$t=2,Qt=3,Zt=4,Xt=5,en=6;class tn{constructor(e){this.type=e}getLength(){return 1}getContent(){return[this.type]}isCountable(){return!0}copy(){return new tn(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 nn=(e,t,n)=>{const{client:r,clock:s}=t.id,i=new rn(ie(r,s+n),t,ie(r,s+n-1),t.right,t.rightOrigin,t.parent,t.parentSub,t.content.splice(n));return t.deleted&&i.markDeleted(),t.keep&&(i.keep=!0),null!==t.redone&&(i.redone=ie(t.redone.client,t.redone.clock+n)),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=n,i};class rn extends Ot{constructor(e,t,n,r,s,i,o,c){super(e,c.getLength()),this.origin=n,this.left=t,this.right=r,this.rightOrigin=s,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===re&&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===re){const e=ge(t,this.parent);e.constructor===Pt?this.parent=null:this.parent=e.content.type}}else this.left&&this.left.constructor===rn?(this.parent=this.left.parent,this.parentSub=this.left.parentSub):this.right&&this.right.constructor===rn&&(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,n=this.left;if(null!==n)t=n.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 r=new Set,s=new Set;for(;null!==t&&t!==this.right;){if(s.add(t),r.add(t),se(this.origin,t.origin)){if(t.id.client<this.id.client)n=t,r.clear();else if(se(this.rightOrigin,t.rightOrigin))break}else{if(null===t.origin||!s.has(ge(e.doc.store,t.origin)))break;r.has(ge(e.doc.store,t.origin))||(n=t,r.clear())}t=t.right}this.left=n}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),be(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&&se(e.origin,this.lastId)&&this.right===e&&se(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(),D(e.deleteSet,this.id.client,this.id.clock,this.length),be(e,t,this.parentSub),this.content.delete(e)}}gc(e,t){if(!this.deleted)throw g.unexpectedCase();this.content.gc(e),t?((e,t,n)=>{const r=e.clients.get(t.id.client);r[pe(r,t.id.clock)]=n})(e,this,new Pt(this.id,this.length)):this.content=new Nt(this.length)}write(e,t){const n=t>0?ie(this.id.client,this.id.clock+t-1):this.origin,r=this.rightOrigin,s=this.parentSub,i=this.content.getRef()&f.BITS5|(null===n?0:f.BIT8)|(null===r?0:f.BIT7)|(null===s?0:f.BIT6);if(e.writeInfo(i),null!==n&&e.writeLeftID(n),null!==r&&e.writeRightID(r),null===n&&null===r){const t=this.parent;if(void 0!==t._item){const n=t._item;if(null===n){const n=(e=>{for(const[t,n]of e.doc.share.entries())if(n===e)return t;throw g.unexpectedCase()})(t);e.writeParentInfo(!0),e.writeString(n)}else e.writeParentInfo(!1),e.writeLeftID(n.id)}else t.constructor===String?(e.writeParentInfo(!0),e.writeString(t)):t.constructor===re?(e.writeParentInfo(!1),e.writeLeftID(t)):g.unexpectedCase();null!==s&&e.writeString(s)}this.content.write(e,t)}}const sn=(e,t)=>on[t&f.BITS5](e),on=[()=>{g.unexpectedCase()},e=>new Nt(e.readLen()),e=>{const t=e.readLen(),n=[];for(let r=0;r<t;r++){const t=e.readString();"undefined"===t?n.push(void 0):n.push(JSON.parse(t))}return new zt(n)},e=>new Bt(e.readBuf()),e=>new Gt(e.readString()),e=>new Kt(e.readJSON()),e=>new jt(e.readKey(),e.readJSON()),e=>new tn(Ht[e.readTypeRef()](e)),e=>{const t=e.readLen(),n=[];for(let r=0;r<t;r++)n.push(e.readAny());return new Ft(n)},e=>new qt(Lt(e.readString(),e.readAny())),()=>{g.unexpectedCase()}];class cn 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 an="undefined"!=typeof globalThis?globalThis:"undefined"!=typeof window?window:void 0!==t?t:{},hn="__ $YJS$ __";!0===an[hn]&&console.error("Yjs was already imported. This breaks constructor checks and will lead to issues! - https://github.com/yjs/yjs/issues/438"),an[hn]=!0})),n.register("fACbm",(function(t,r){e(t.exports,"ObservableV2",(function(){return c})),e(t.exports,"Observable",(function(){return a}));var s=n("cuboK"),i=n("aYKIU"),o=n("kDMzp");class c{constructor(){this._observers=s.create()}on(e,t){return s.setIfUndefined(this._observers,e,i.create).add(t),t}once(e,t){const n=(...r)=>{this.off(e,n),t(...r)};this.on(e,n)}off(e,t){const n=this._observers.get(e);void 0!==n&&(n.delete(t),0===n.size&&this._observers.delete(e))}emit(e,t){return o.from((this._observers.get(e)||s.create()).values()).forEach((e=>e(...t)))}destroy(){this._observers=s.create()}}class a{constructor(){this._observers=s.create()}on(e,t){s.setIfUndefined(this._observers,e,i.create).add(t)}once(e,t){const n=(...r)=>{this.off(e,n),t(...r)};this.on(e,n)}off(e,t){const n=this._observers.get(e);void 0!==n&&(n.delete(t),0===n.size&&this._observers.delete(e))}emit(e,t){return o.from((this._observers.get(e)||s.create()).values()).forEach((e=>e(...t)))}destroy(){this._observers=s.create()}}})),n.register("cuboK",(function(t,n){e(t.exports,"create",(function(){return r})),e(t.exports,"copy",(function(){return s})),e(t.exports,"setIfUndefined",(function(){return i})),e(t.exports,"map",(function(){return o})),e(t.exports,"any",(function(){return c}));const r=()=>new Map,s=e=>{const t=r();return e.forEach(((e,n)=>{t.set(n,e)})),t},i=(e,t,n)=>{let r=e.get(t);return void 0===r&&e.set(t,r=n()),r},o=(e,t)=>{const n=[];for(const[r,s]of e)n.push(t(s,r));return n},c=(e,t)=>{for(const[n,r]of e)if(t(r,n))return!0;return!1}})),n.register("aYKIU",(function(t,n){e(t.exports,"create",(function(){return r})),e(t.exports,"from",(function(){return s}));const r=()=>new Set,s=e=>new Set(e)})),n.register("kDMzp",(function(t,r){e(t.exports,"last",(function(){return s})),e(t.exports,"appendTo",(function(){return i})),e(t.exports,"from",(function(){return o})),e(t.exports,"some",(function(){return c})),e(t.exports,"equalFlat",(function(){return a})),e(t.exports,"unfold",(function(){return h})),e(t.exports,"isArray",(function(){return l})),e(t.exports,"map",(function(){return d})),n("aYKIU");const s=e=>e[e.length-1],i=(e,t)=>{for(let n=0;n<t.length;n++)e.push(t[n])},o=Array.from,c=(e,t)=>{for(let n=0;n<e.length;n++)if(t(e[n],n,e))return!0;return!1},a=(e,t)=>e.length===t.length&&((e,t)=>{for(let n=0;n<e.length;n++)if(!t(e[n],n))return!1;return!0})(e,((e,n)=>e===t[n])),h=(e,t)=>{const n=new Array(e);for(let r=0;r<e;r++)n[r]=t(r,n);return n},l=Array.isArray,d=(e,t)=>{const n=Array(e.length);for(let r=0;r<e.length;r++)n[r]=t(e[r],r,e);return n}})),n.register("iUL32",(function(t,n){e(t.exports,"floor",(function(){return r})),e(t.exports,"ceil",(function(){return s})),e(t.exports,"abs",(function(){return i})),e(t.exports,"round",(function(){return o})),e(t.exports,"log10",(function(){return c})),e(t.exports,"min",(function(){return a})),e(t.exports,"max",(function(){return h})),e(t.exports,"exp10",(function(){return l})),e(t.exports,"isNegativeZero",(function(){return d}));const r=Math.floor,s=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)})),n.register("j3EDv",(function(t,r){e(t.exports,"createEncoder",(function(){return l})),e(t.exports,"encode",(function(){return d})),e(t.exports,"toUint8Array",(function(){return p})),e(t.exports,"length",(function(){return u})),e(t.exports,"write",(function(){return g})),e(t.exports,"writeUint8",(function(){return f})),e(t.exports,"writeVarUint",(function(){return w})),e(t.exports,"writeVarInt",(function(){return y})),e(t.exports,"writeVarUint8Array",(function(){return v})),e(t.exports,"writeVarString",(function(){return S})),e(t.exports,"writeBinaryEncoder",(function(){return b})),e(t.exports,"writeUint8Array",(function(){return k})),e(t.exports,"writeAny",(function(){return C})),e(t.exports,"RleEncoder",(function(){return T})),e(t.exports,"UintOptRleEncoder",(function(){return D})),e(t.exports,"IntDiffOptRleEncoder",(function(){return E})),e(t.exports,"StringEncoder",(function(){return R}));var s=n("iUL32"),i=n("5ug58"),o=n("diuv2"),c=n("fJq6z"),a=n("kDMzp");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 n=0;n<e.bufs.length;n++)t+=e.bufs[n].length;return t},p=e=>{const t=new Uint8Array(u(e));let n=0;for(let r=0;r<e.bufs.length;r++){const s=e.bufs[r];t.set(s,n),n+=s.length}return t.set(new Uint8Array(e.cbuf.buffer,0,e.cpos),n),t},g=(e,t)=>{const n=e.cbuf.length;e.cpos===n&&(e.bufs.push(e.cbuf),e.cbuf=new Uint8Array(2*n),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=s.floor(t/128);g(e,o.BITS7&t)},y=(e,t)=>{const n=s.isNegativeZero(t);for(n&&(t=-t),g(e,(t>o.BITS6?o.BIT8:0)|(n?o.BIT7:0)|o.BITS6&t),t=s.floor(t/64);t>0;)g(e,(t>o.BITS7?o.BIT8:0)|o.BITS7&t),t=s.floor(t/128)},_=new Uint8Array(3e4),m=_.length/3,S=c.utf8TextEncoder&&c.utf8TextEncoder.encodeInto?(e,t)=>{if(t.length<m){const n=c.utf8TextEncoder.encodeInto(t,_).written||0;w(e,n);for(let t=0;t<n;t++)g(e,_[t])}else v(e,c.encodeUtf8(t))}:(e,t)=>{const n=unescape(encodeURIComponent(t)),r=n.length;w(e,r);for(let t=0;t<r;t++)g(e,n.codePointAt(t))},b=(e,t)=>k(e,p(t)),k=(e,t)=>{const n=e.cbuf.length,r=e.cpos,i=s.min(n-r,t.length),o=t.length-i;e.cbuf.set(t.subarray(0,i),r),e.cpos+=i,o>0&&(e.bufs.push(e.cbuf),e.cbuf=new Uint8Array(s.max(2*n,o)),e.cbuf.set(t.subarray(i)),e.cpos=o)},v=(e,t)=>{w(e,t.byteLength),k(e,t)},U=(e,t)=>{((e,t)=>{const n=e.cbuf.length;n-e.cpos<t&&(e.bufs.push(new Uint8Array(e.cbuf.buffer,0,e.cpos)),e.cbuf=new Uint8Array(2*s.max(n,t)),e.cpos=0)})(e,t);const n=new DataView(e.cbuf.buffer,e.cpos,t);return e.cpos+=t,n},A=new DataView(new ArrayBuffer(4)),C=(e,t)=>{switch(typeof t){case"string":g(e,119),S(e,t);break;case"number":i.isInteger(t)&&s.abs(t)<=o.BITS31?(g(e,125),y(e,t)):(n=t,A.setFloat32(0,n),A.getFloat32(0)===n?(g(e,124),((e,t)=>{U(e,4).setFloat32(0,t,!1)})(e,t)):(g(e,123),((e,t)=>{U(e,8).setFloat64(0,t,!1)})(e,t)));break;case"bigint":g(e,122),((e,t)=>{U(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 n=0;n<t.length;n++)C(e,t[n])}else if(t instanceof Uint8Array)g(e,116),v(e,t);else{g(e,118);const n=Object.keys(t);w(e,n.length);for(let r=0;r<n.length;r++){const s=n[r];S(e,s),C(e,t[s])}}break;case"boolean":g(e,t?120:121);break;default:g(e,127)}var n};class T 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 D{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 x=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++):(x(this),this.count=1,this.diff=e-this.s,this.s=e)}toUint8Array(){return x(this),p(this.encoder)}}class R{constructor(){this.sarr=[],this.s="",this.lensE=new D}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="",S(e,this.sarr.join("")),k(e,this.lensE.toUint8Array()),p(e)}}})),n.register("5ug58",(function(t,r){e(t.exports,"MAX_SAFE_INTEGER",(function(){return o})),e(t.exports,"isInteger",(function(){return c}));var s=n("iUL32"),i=n("diuv2");const o=Number.MAX_SAFE_INTEGER,c=(Number.MIN_SAFE_INTEGER,i.BITS31,i.BITS32,Number.isInteger||(e=>"number"==typeof e&&isFinite(e)&&s.floor(e)===e));Number.isNaN,Number.parseInt})),n.register("diuv2",(function(t,n){e(t.exports,"BIT1",(function(){return r})),e(t.exports,"BIT2",(function(){return s})),e(t.exports,"BIT3",(function(){return i})),e(t.exports,"BIT4",(function(){return o})),e(t.exports,"BIT6",(function(){return c})),e(t.exports,"BIT7",(function(){return a})),e(t.exports,"BIT8",(function(){return h})),e(t.exports,"BITS5",(function(){return l})),e(t.exports,"BITS6",(function(){return d})),e(t.exports,"BITS7",(function(){return u})),e(t.exports,"BITS8",(function(){return p})),e(t.exports,"BITS21",(function(){return g})),e(t.exports,"BITS31",(function(){return f})),e(t.exports,"BITS32",(function(){return w}));const r=1,s=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})),n.register("fJq6z",(function(t,r){e(t.exports,"fromCharCode",(function(){return i})),e(t.exports,"fromCamelCase",(function(){return a})),e(t.exports,"utf8TextEncoder",(function(){return h})),e(t.exports,"encodeUtf8",(function(){return l})),e(t.exports,"utf8TextDecoder",(function(){return d})),e(t.exports,"decodeUtf8",(function(){return u})),e(t.exports,"repeat",(function(){return p}));var s=n("kDMzp");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)),n=t.length,r=new Uint8Array(n);for(let e=0;e<n;e++)r[e]=t.codePointAt(e);return r};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,n="",r=0;for(;t>0;){const s=t<1e4?t:1e4,i=e.subarray(r,r+s);r+=s,n+=String.fromCodePoint.apply(null,i),t-=s}return decodeURIComponent(escape(n))},p=(e,t)=>s.unfold(t,(()=>e)).join("")})),n.register("heYZO",(function(t,r){e(t.exports,"createDecoder",(function(){return u})),e(t.exports,"hasContent",(function(){return p})),e(t.exports,"clone",(function(){return g})),e(t.exports,"readVarUint8Array",(function(){return f})),e(t.exports,"readVarUint",(function(){return y})),e(t.exports,"readUint8",(function(){return w})),e(t.exports,"readVarInt",(function(){return _})),e(t.exports,"readVarString",(function(){return m})),e(t.exports,"readAny",(function(){return k})),e(t.exports,"RleDecoder",(function(){return v})),e(t.exports,"UintOptRleDecoder",(function(){return U})),e(t.exports,"IntDiffOptRleDecoder",(function(){return A})),e(t.exports,"StringDecoder",(function(){return C}));var s=n("diuv2"),i=n("iUL32"),o=n("5ug58"),c=n("fJq6z"),a=n("jtAN9");n("j3EDv");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 n=u(e.arr);return n.pos=t,n},f=e=>((e,t)=>{const n=new Uint8Array(e.arr.buffer,e.pos+e.arr.byteOffset,t);return e.pos+=t,n})(e,y(e)),w=e=>e.arr[e.pos++],y=e=>{let t=0,n=1;const r=e.arr.length;for(;e.pos<r;){const r=e.arr[e.pos++];if(t+=(r&s.BITS7)*n,n*=128,r<s.BIT8)return t;if(t>o.MAX_SAFE_INTEGER)throw l}throw h},_=e=>{let t=e.arr[e.pos++],n=t&s.BITS6,r=64;const i=(t&s.BIT7)>0?-1:1;if(!(t&s.BIT8))return i*n;const c=e.arr.length;for(;e.pos<c;){if(t=e.arr[e.pos++],n+=(t&s.BITS7)*r,r*=128,t<s.BIT8)return i*n;if(n>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 n=String.fromCodePoint(w(e));if(--t<100)for(;t--;)n+=String.fromCodePoint(w(e));else for(;t>0;){const r=t<1e4?t:1e4,s=e.arr.subarray(e.pos,e.pos+r);e.pos+=r,n+=String.fromCodePoint.apply(null,s),t-=r}return decodeURIComponent(escape(n))}},S=(e,t)=>{const n=new DataView(e.arr.buffer,e.arr.byteOffset+e.pos,t);return e.pos+=t,n},b=[e=>{},e=>null,_,e=>S(e,4).getFloat32(0,!1),e=>S(e,8).getFloat64(0,!1),e=>S(e,8).getBigInt64(0,!1),e=>!1,e=>!0,m,e=>{const t=y(e),n={};for(let r=0;r<t;r++)n[m(e)]=k(e);return n},e=>{const t=y(e),n=[];for(let r=0;r<t;r++)n.push(k(e));return n},f],k=e=>b[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 U 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 A 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 U(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}}})),n.register("jtAN9",(function(t,n){e(t.exports,"create",(function(){return r})),e(t.exports,"methodUnimplemented",(function(){return s})),e(t.exports,"unexpectedCase",(function(){return i}));const r=e=>new Error(e),s=()=>{throw r("Method unimplemented")},i=()=>{throw r("Unexpected case")}})),n.register("9c5sf",(function(t,r){e(t.exports,"uint32",(function(){return i})),e(t.exports,"uuidv4",(function(){return o})),n("iUL32"),n("diuv2");var s=n("56GYt");Math.random;const i=()=>(0,s.getRandomValues)(new Uint32Array(1))[0],o=()=>"10000000-1000-4000-8000-100000000000".replace(/[018]/g,(e=>(e^i()&15>>e/4).toString(16)))})),n.register("56GYt",(function(t,n){e(t.exports,"getRandomValues",(function(){return r})),crypto.subtle;const r=crypto.getRandomValues.bind(crypto)})),n.register("hpG0a",(function(t,r){e(t.exports,"create",(function(){return s})),n("k2yVv");const s=e=>new Promise(e);Promise.all.bind(Promise)})),n.register("k2yVv",(function(t,r){e(t.exports,"getUnixTime",(function(){return s})),n("4OCIJ"),n("iUL32");const s=Date.now})),n.register("4OCIJ",(function(t,r){e(t.exports,"prefix",(function(){return c}));var s=n("iUL32");const i=["","k","M","G","T","P","E","Z","Y"],o=["","m","μ","n","p","f","a","z","y"],c=(e,t=0)=>{const n=0===e?0:s.log10(e);let r=0;for(;n<3*r&&t>-8;)t--,r--;for(;n>=3+3*r&&t<8;)t++,r++;const c=t<0?o[-t]:i[t];return{n:s.round(1e12*(r>0?e/s.exp10(3*r):e*s.exp10(-3*r)))/1e12,prefix:c}}})),n.register("f6bdK",(function(t,r){e(t.exports,"createUint8ArrayFromArrayBuffer",(function(){return a})),e(t.exports,"toBase64",(function(){return h})),e(t.exports,"fromBase64",(function(){return l})),e(t.exports,"copyUint8Array",(function(){return d}));var s=n("fJq6z"),i=n("1TTGp"),o=(n("kDMzp"),n("iUL32"),n("j3EDv"),n("heYZO"),n("1D1do").Buffer);const c=e=>new Uint8Array(e),a=e=>new Uint8Array(e),h=i.isBrowser?e=>{let t="";for(let n=0;n<e.byteLength;n++)t+=s.fromCharCode(e[n]);return btoa(t)}:e=>o.from(e.buffer,e.byteOffset,e.byteLength).toString("base64"),l=i.isBrowser?e=>{const t=atob(e),n=c(t.length);for(let e=0;e<t.length;e++)n[e]=t.charCodeAt(e);return n}:e=>{const t=o.from(e,"base64");return n=t.buffer,r=t.byteOffset,s=t.byteLength,new Uint8Array(n,r,s);var n,r,s},d=e=>{const t=c(e.byteLength);return t.set(e),t}})),n.register("1TTGp",(function(t,r){e(t.exports,"isBrowser",(function(){return d})),e(t.exports,"getVariable",(function(){return f})),e(t.exports,"supportsColor",(function(){return y}));var s=n("cuboK"),i=n("fJq6z"),o=n("buSng"),c=n("0ztOM"),a=n("ixCIn"),h=n("5Cbw2");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=s.create();const e=h.argv;let t=null;for(let n=0;n<e.length;n++){const r=e[n];"-"===r[0]?(null!==t&&u.set(t,""),t=r):null!==t?(u.set(t,r),t=null):p.push(r)}null!==t&&u.set(t,"")}else"object"==typeof location?(u=s.create(),(location.search||"?").slice(1).split("&").forEach((e=>{if(0!==e.length){const[t,n]=e.split("=");u.set(`--${i.fromCamelCase(t,"-")}`,n),u.set(`-${i.fromCamelCase(t,"-")}`,n)}}))):u=s.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")))})),n.register("buSng",(function(t,n){e(t.exports,"undefinedToNull",(function(){return r}));const r=e=>void 0===e?null:e})),n.register("0ztOM",(function(t,n){e(t.exports,"varStorage",(function(){return i})),e(t.exports,"onChange",(function(){return o})),e(t.exports,"offChange",(function(){return c}));let r=new class{constructor(){this.map=new Map}setItem(e,t){this.map.set(e,t)}getItem(e){return this.map.get(e)}},s=!0;try{"undefined"!=typeof localStorage&&localStorage&&(r=localStorage,s=!1)}catch(e){}const i=r,o=e=>s||addEventListener("storage",e),c=e=>s||removeEventListener("storage",e)})),n.register("ixCIn",(function(t,r){e(t.exports,"callAll",(function(){return c})),e(t.exports,"nop",(function(){return a})),e(t.exports,"id",(function(){return h})),e(t.exports,"equalityDeep",(function(){return l})),e(t.exports,"isOneOf",(function(){return d}));var s=n("kDMzp"),i=n("gBQSU"),o=n("kGyU6");const c=(e,t,n=0)=>{try{for(;n<e.length;n++)e[n](...t)}finally{n<e.length&&c(e,t,n+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 n=0;n<e.length;n++)if(e[n]!==t[n])return!1;break;case Set:if(e.size!==t.size)return!1;for(const n of e)if(!t.has(n))return!1;break;case Map:if(e.size!==t.size)return!1;for(const n of e.keys())if(!t.has(n)||!l(e.get(n),t.get(n)))return!1;break;case Object:if(i.length(e)!==i.length(t))return!1;for(const n in e)if(!i.hasProperty(e,n)||!l(e[n],t[n]))return!1;break;case Array:if(e.length!==t.length)return!1;for(let n=0;n<e.length;n++)if(!l(e[n],t[n]))return!1;break;default:return!1}return!0},d=(e,t)=>t.includes(e);s.isArray})),n.register("gBQSU",(function(t,n){e(t.exports,"assign",(function(){return r})),e(t.exports,"forEach",(function(){return i})),e(t.exports,"length",(function(){return o})),e(t.exports,"isEmpty",(function(){return a})),e(t.exports,"hasProperty",(function(){return h})),e(t.exports,"equalFlat",(function(){return l})),e(t.exports,"deepFreeze",(function(){return u}));const r=Object.assign,s=Object.keys,i=(Object.values,(e,t)=>{for(const n in e)t(e[n],n)}),o=e=>s(e).length,c=e=>s(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 n in e)if(!t(e[n],n))return!1;return!0})(e,((e,n)=>(void 0!==e||h(t,n))&&t[n]===e)),d=Object.freeze,u=e=>{for(const t in e){const n=e[t];"object"!=typeof n&&"function"!=typeof n||u(e[t])}return d(e)}})),n.register("kGyU6",(function(t,n){e(t.exports,"EqualityTraitSymbol",(function(){return r}));const r=Symbol("Equality")})),n.register("fK7I3",(function(t,r){e(t.exports,"print",(function(){return u})),e(t.exports,"warn",(function(){return p})),e(t.exports,"BOLD",(function(){return n("37RhN").BOLD})),e(t.exports,"UNBOLD",(function(){return n("37RhN").UNBOLD})),e(t.exports,"RED",(function(){return n("37RhN").RED})),e(t.exports,"ORANGE",(function(){return n("37RhN").ORANGE}));var s=n("1TTGp"),i=n("aYKIU"),o=n("cGRJO"),c=n("7Nfk8"),a=(n("4RKQg"),n("cuboK")),h=(n("92eZa"),n("iUL32"),n("37RhN"));h=n("37RhN");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=s.supportsColor?e=>{1===e.length&&e[0]?.constructor===Function&&(e=e[0]());const t=[],n=[],r=a.create();let s=[],i=0;for(;i<e.length;i++){const s=e[i],o=l[s];if(void 0!==o)r.set(o.left,o.right);else{if(void 0===s)break;if(s.constructor!==String&&s.constructor!==Number)break;{const e=c.mapToStyleString(r);i>0||e.length>0?(t.push("%c"+s),n.push(e)):t.push(s)}}}for(i>0&&(s=n,s.unshift(t.join("")));i<e.length;i++){const t=e[i];t instanceof Symbol||s.push(t)}return s}: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()})),n.register("cGRJO",(function(t,n){e(t.exports,"create",(function(){return s})),e(t.exports,"forEach",(function(){return i}));class r{constructor(e,t){this.left=e,this.right=t}}const s=(e,t)=>new r(e,t),i=(e,t)=>e.forEach((e=>t(e.left,e.right)))})),n.register("7Nfk8",(function(t,r){e(t.exports,"append",(function(){return a})),e(t.exports,"addEventListener",(function(){return h})),e(t.exports,"element",(function(){return l})),e(t.exports,"text",(function(){return d})),e(t.exports,"mapToStyleString",(function(){return u}));var s=n("cGRJO"),i=n("cuboK");const o="undefined"!=typeof document?document:{},c=("undefined"!=typeof DOMParser&&new DOMParser,e=>{const t=o.createDocumentFragment();for(let n=0;n<e.length;n++)p(t,e[n]);return t}),a=(e,t)=>(p(e,c(t)),e),h=(e,t,n)=>e.addEventListener(t,n),l=(e,t=[],n=[])=>a(((e,t)=>(s.forEach(t,((t,n)=>{!1===n?e.removeAttribute(t):!0===n?e.setAttribute(t,""):e.setAttribute(t,n)})),e))((e=>o.createElement(e))(e),t),n),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})),n.register("4RKQg",(function(t,n){e(t.exports,"stringify",(function(){return r}));const r=JSON.stringify;JSON.parse})),n.register("92eZa",(function(t,r){e(t.exports,"enqueue",(function(){return o})),n("k2yVv");let s=[];const i=()=>{for(let e=0;e<s.length;e++)s[e]();s=[]},o=e=>{s.push(e),1===s.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)))})),n.register("37RhN",(function(t,r){e(t.exports,"BOLD",(function(){return h})),e(t.exports,"UNBOLD",(function(){return l})),e(t.exports,"BLUE",(function(){return d})),e(t.exports,"GREY",(function(){return u})),e(t.exports,"GREEN",(function(){return p})),e(t.exports,"RED",(function(){return g})),e(t.exports,"PURPLE",(function(){return f})),e(t.exports,"ORANGE",(function(){return w})),e(t.exports,"UNCOLOR",(function(){return y})),e(t.exports,"computeNoColorLoggingArgs",(function(){return _})),e(t.exports,"createModuleLogger",(function(){return k}));var s=n("jR3GT"),i=n("k2yVv"),o=n("1TTGp"),c=n("ixCIn"),a=n("4RKQg");const h=s.create(),l=s.create(),d=s.create(),u=s.create(),p=s.create(),g=s.create(),f=s.create(),w=s.create(),y=s.create(),_=e=>{1===e.length&&e[0]?.constructor===Function&&(e=e[0]());const t=[],n=[];let r=0;for(;r<e.length;r++){const n=e[r];if(void 0===n)break;if(n.constructor===String||n.constructor===Number)t.push(n);else if(n.constructor===Object)break}for(r>0&&n.push(t.join(""));r<e.length;r++){const t=e[r];t instanceof Symbol||n.push(t)}return n},m=[p,f,w,d];let S=0,b=i.getUnixTime();const k=(e,t)=>{const n=m[S],r=o.getVariable("log"),s=null!==r&&("*"===r||"true"===r||new RegExp(r,"gi").test(t));return S=(S+1)%m.length,t+=": ",s?(...r)=>{1===r.length&&r[0]?.constructor===Function&&(r=r[0]());const s=i.getUnixTime(),o=s-b;b=s,e(n,t,y,...r.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)}})),n," +"+o+"ms")}:c.nop}})),n.register("jR3GT",(function(t,n){e(t.exports,"create",(function(){return r}));const r=Symbol})),n.register("fiX3Z",(function(t,n){e(t.exports,"iteratorFilter",(function(){return s})),e(t.exports,"iteratorMap",(function(){return i}));const r=e=>({[Symbol.iterator](){return this},next:e}),s=(e,t)=>r((()=>{let n;do{n=e.next()}while(!n.done&&!t(n.value));return n})),i=(e,t)=>r((()=>{const{done:n,value:r}=e.next();return{done:n,value:n?void 0:t(r)}}))})),n.register("232M8",(function(t,r){e(t.exports,"Awareness",(function(){return l})),e(t.exports,"removeAwarenessStates",(function(){return d})),e(t.exports,"encodeAwarenessUpdate",(function(){return u})),e(t.exports,"applyAwarenessUpdate",(function(){return p}));var s=n("j3EDv"),i=n("heYZO"),o=n("k2yVv"),c=n("iUL32"),a=n("fACbm"),h=n("ixCIn");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(((n,r)=>{r!==this.clientID&&3e4<=e-n.lastUpdated&&this.states.has(r)&&t.push(r)})),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,n=this.meta.get(t),r=void 0===n?0:n.clock+1,s=this.states.get(t);null===e?this.states.delete(t):this.states.set(t,e),this.meta.set(t,{clock:r,lastUpdated:o.getUnixTime()});const i=[],c=[],a=[],l=[];null===e?l.push(t):null==s?null!=e&&i.push(t):(c.push(t),h.equalityDeep(s,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 n=this.getLocalState();null!==n&&this.setLocalState({...n,[e]:t})}getStates(){return this.states}}const d=(e,t,n)=>{const r=[];for(let n=0;n<t.length;n++){const s=t[n];if(e.states.has(s)){if(e.states.delete(s),s===e.clientID){const t=e.meta.get(s);e.meta.set(s,{clock:t.clock+1,lastUpdated:o.getUnixTime()})}r.push(s)}}r.length>0&&(e.emit("change",[{added:[],updated:[],removed:r},n]),e.emit("update",[{added:[],updated:[],removed:r},n]))},u=(e,t,n=e.states)=>{const r=t.length,i=s.createEncoder();s.writeVarUint(i,r);for(let o=0;o<r;o++){const r=t[o],c=n.get(r)||null,a=e.meta.get(r).clock;s.writeVarUint(i,r),s.writeVarUint(i,a),s.writeVarString(i,JSON.stringify(c))}return s.toUint8Array(i)},p=(e,t,n)=>{const r=i.createDecoder(t),s=o.getUnixTime(),c=[],a=[],l=[],d=[],u=i.readVarUint(r);for(let t=0;t<u;t++){const t=i.readVarUint(r);let n=i.readVarUint(r);const o=JSON.parse(i.readVarString(r)),u=e.meta.get(t),p=e.states.get(t),g=void 0===u?0:u.clock;(g<n||g===n&&null===o&&e.states.has(t))&&(null===o?t===e.clientID&&null!=e.getLocalState()?n++:e.states.delete(t):e.states.set(t,o),e.meta.set(t,{clock:n,lastUpdated:s}),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},n]),(c.length>0||a.length>0||d.length>0)&&e.emit("update",[{added:c,updated:a,removed:d},n])}})),n.register("jmfTU",(function(t,r){e(t.exports,"messageYjsSyncStep1",(function(){return c})),e(t.exports,"messageYjsSyncStep2",(function(){return a})),e(t.exports,"messageYjsUpdate",(function(){return h})),e(t.exports,"writeSyncStep1",(function(){return l})),e(t.exports,"writeSyncStep2",(function(){return d})),e(t.exports,"writeUpdate",(function(){return p})),e(t.exports,"readSyncMessage",(function(){return f}));var s=n("j3EDv"),i=n("heYZO"),o=n("7I2MU");const c=0,a=1,h=2,l=(e,t)=>{s.writeVarUint(e,c);const n=o.encodeStateVector(t);s.writeVarUint8Array(e,n)},d=(e,t,n)=>{s.writeVarUint(e,a),s.writeVarUint8Array(e,o.encodeStateAsUpdate(t,n))},u=(e,t,n,r)=>{try{o.applyUpdate(t,i.readVarUint8Array(e),n)}catch(e){null!=r&&r(e),console.error("Caught error while handling a Yjs update",e)}},p=(e,t)=>{s.writeVarUint(e,h),s.writeVarUint8Array(e,t)},g=u,f=(e,t,n,r,s)=>{const o=i.readVarUint(e);switch(o){case c:((e,t,n)=>{d(t,n,i.readVarUint8Array(e))})(e,t,n);break;case a:u(e,n,r,s);break;case h:g(e,n,r,s);break;default:throw new Error("Unknown message type")}return o}})),n.register("7Ecpa",(function(t,r){e(t.exports,"subscribe",(function(){return d})),e(t.exports,"unsubscribe",(function(){return u})),e(t.exports,"publish",(function(){return p}));var s=n("cuboK"),i=n("aYKIU"),o=n("f6bdK"),c=n("0ztOM");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=>s.setIfUndefined(a,e,(()=>{const t=i.create(),n=new h(e);return n.onmessage=e=>t.forEach((t=>t(e.data,"broadcastchannel"))),{bc:n,subs:t}})),d=(e,t)=>(l(e).subs.add(t),t),u=(e,t)=>{const n=l(e),r=n.subs.delete(t);return r&&0===n.subs.size&&(n.bc.close(),a.delete(e)),r},p=(e,t,n=null)=>{const r=l(e);r.bc.postMessage(t),r.subs.forEach((e=>e(t,n)))}})),n.register("05asq",(function(e,t){n("7I2MU")})),n.register("hxuAG",(function(t,r){e(t.exports,"DexieTransport",(function(){return c})),n("4nLZ9");var s=n("iYjQj"),i=n("7I2MU"),o=n("cLx6L");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,s.extractDocUpdates)(e)));return 0===t.length?null:(0,s.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,s.extractDocUpdates)(e);if(0!==t.length)return o.default.appendYjsUpdate(this.uidDB,this.key,(0,s.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)}}})),n.register("66xmW",(function(t,r){e(t.exports,"CRDT",(function(){return p}));var s=n("7I2MU"),i=n("axlxN"),o=n("cV7be"),c=n("7ckmy"),a=n("fpqzD"),h=n("eh3Be"),l=n("g4rKG");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 s.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,n,r){this.classroomMode=e,this.roomId=t,this.uidDB=n,this.ownerTokenHash=r?.ownerTokenHash||void 0,this.incomingOwnerToken=r?.ownerToken||void 0}async resolveOwnerToken(){const e=`${this.roomId??"default"}:ownerToken`,t=this.uidDB??"default";if(this.incomingOwnerToken){const n=await o.sha256Base64(this.incomingOwnerToken);return this.ownerTokenHash&&n!==this.ownerTokenHash||(this.localOwnerToken=this.incomingOwnerToken,this.ownerTokenHash=n,await(0,c.putStoredValue)(t,e,this.localOwnerToken)),{hash:this.ownerTokenHash??"",token:this.localOwnerToken}}const n=await(0,c.getStoredValue)(t,e);if(n){const e=await o.sha256Base64(n);this.ownerTokenHash&&e!==this.ownerTokenHash||(this.localOwnerToken=n,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 n=0;n<e.length;n++)await this.collectInitWrites(d,n,e[n][d],t),await this.collectInitWrites(u,n,e[n][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,n,r){if(n&&0!==n.length)for(let s=0;s<n.length;s++){const i=n[s][this.peerID];if(void 0===i)continue;const c=0!==this.classroomMode?await o.encryptValue(await this.ensureContentKey(),i):i;r.push({type:e,id:t,i:s,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 n=this.getCursors();n.length>0&&this.callback(n,"cursor"),this.scheduleQuizSurvey();const r=new Set;for(const e of this.codes.keys())try{const[t]=JSON.parse(e);r.add(t)}catch{}r.size>0&&this.callback(this.getCode(r),"code");const s=await this.buildChatVector();s.length>0&&this.callback(s,"chat")}async buildChatVector(){const e=[];for(const[t,n]of this.chat.map)e.push({...n.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 n=await o.verifyChatMessage(t,{message:String(e.message),user:String(e.user),ts:e.id},e.signature);return{...e,verified:n}}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 n=this.getCursors();n.length>0&&this.callback(n,"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[n,r]of e)"add"===r.action&&t.push({id:parseInt(n),entry:r.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 n of e)if(n.target===this.codes)n.keysChanged.forEach((e=>{try{const[n]=JSON.parse(e);t.add(n)}catch{}}));else try{const[e]=JSON.parse(n.path[0]);t.add(e)}catch{}t.size>0&&this.callback(this.getCode(t),"code")}))}encode(){return s.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 n=0;n<t.length;n++)for(let r=0;r<t[n].length;r++)this.initCode(e,n,r,t[n][r])}getCode(e){let t=[];for(const n of e)t.push({id:n,data:this.getAllTexts(n)});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,n]of this.identities)e[t]=n;return e}id(e,t,n){return void 0===n?JSON.stringify([e,t]):JSON.stringify([e,t,n])}collectSectionIds(e){const t=new Set;for(const[,n]of this.user){const r=n.get(e);if(r)for(const e of r.keys())t.add(Number(e))}return t}async getSection(e,t){const n=[];for(const[r,s]of this.user){const i=s.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 s=await this.decryptSectionValue(r,t);void 0!==s&&(n[e]||(n[e]={}),n[e][r]=s)}}for(let e=0;e<n.length;e++)n[e]||(n[e]={});return n}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 n=await this.getPeerContentKey(e);if(!n)return;return await o.decryptValue(n,t)}}catch(e){return}}async getPeerContentKey(e){const t=this.wrappedKeys.get(e);if(!t)return;const n=this.peerKeyCache.get(e);if(n&&n.wrapped===t)return n.key;const r=await o.unwrapContentKey(t,this.ownerKeyPair.privateKey);return this.peerKeyCache.set(e,{wrapped:t,key:r}),r}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 n=await this.ensureContentKey(),r=await o.wrapContentKeyForOwner(n,t);this.wrappedKeys.set(this.peerID,r)}getAllTexts(e){let t,n=[];for(let r=0;this.codes.has(this.id(e,r,0));r++){let s=[];for(let n=0;this.codes.has(this.id(e,r,n));n++)t=this.codes.get(this.id(e,r,n)),s.push(t?.toString()||"");n.push(s)}return n}addQuiz(e,t,n){this.addRecord(d,e,t,n).catch((e=>console.warn("addQuiz failed ->",e)))}addSurvey(e,t,n){this.addRecord(u,e,t,n).catch((e=>console.warn("addSurvey failed ->",e)))}async addRecord(e,t,n,r){const s=0!==this.classroomMode?await o.encryptValue(await this.ensureContentKey(),r):r;this.doc.transact((()=>{const r=this.getOwnSectionArray(e,t);(0,a.setArrayValue)(r,n,s)}),this.peerID)}getOwnSectionArray(e,t){let n=this.user.get(this.peerID);n||(n=new s.Map,this.user.set(this.peerID,n));let r=n.get(e);r||(r=new s.Map,n.set(e,r));let i=r.get(String(t));return i||(i=new s.Array,r.set(String(t),i)),i}initCode(e,t,n,r){if(!this.codes.has(this.id(e,t,n))){const i=this.doc.clientID;this.doc.clientID=0;const o=new s.Text;o.insert(0,r),this.codes.set(this.id(e,t,n),o),this.doc.clientID=i}}async addChatMessage(e){const t=Date.now(),n=await this.signingKeyReady,r=await o.signChatMessage(n.privateKey,{message:e,user:this.peerID,ts:t});this.chat.set(""+t,{color:this.getColor(),message:e,user:this.peerID,signature:r})}updateCode(e,t,n,r){this.codes.has(this.id(e,t,n))&&this.doc.transact((()=>{const s=this.codes.get(this.id(e,t,n));if(void 0!==s)for(let e of r)switch(e.action){case"insert":s.insert(e.index,e.content);break;case"remove":s.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,n){this.awareness?.setLocalStateField("cursor",{id:this.peerID,section:e,project:t.project,file:t.file,state:t.state,color:this.getColor(),name:n})}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}}})),n.register("7ckmy",(function(t,r){e(t.exports,"getOrCreateKey",(function(){return i})),e(t.exports,"getStoredValue",(function(){return o})),e(t.exports,"putStoredValue",(function(){return c}));var s=n("cLx6L");async function i(e,t,n){try{const r=await s.default.getKey(e,t);if(r)return r;const i=await n();return await s.default.putKey(e,t,i),i}catch(e){return console.warn("keyStore: falling back to session-only key ->",e),n()}}async function o(e,t){try{return await s.default.getKey(e,t)}catch(e){return void console.warn("keyStore: getStoredValue unavailable ->",e)}}async function c(e,t,n){try{await s.default.putKey(e,t,n)}catch(e){console.warn("keyStore: putStoredValue unavailable ->",e)}}})),n.register("fpqzD",(function(t,n){function r(e,t,n){if(e.length>t)e.delete(t,1);else for(;e.length<t;)e.push([null]);e.insert(t,[n])}e(t.exports,"setArrayValue",(function(){return r}))})),n.register("eh3Be",(function(t,n){function r(e){let t=!1,n=!1;const r=()=>{if(t)return void(n=!0);t=!0;const s=()=>{t=!1,n&&(n=!1,r())};e().then(s,s)};return r}e(t.exports,"coalesce",(function(){return r}))})),n.register("g4rKG",(function(t,r){e(t.exports,"YKeyValue",(function(){return i}));var s=n("fACbm");class i extends s.Observable{constructor(e){super(),this.yarray=e,this.doc=e.doc,this.map=new Map;{const t=e.toArray();this.doc.transact((()=>{for(let n=t.length-1;n>=0;n--){const r=t[n];this.map.has(r.key)?e.delete(n):this.map.set(r.key,r)}}))}e.observe(((t,n)=>{const r=new Map,s=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),r.set(e.key,{action:"delete",oldValue:e.val}))}))}));const i=new Map;s.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 n=c[t];if(o.has(n.key))o.delete(n.key),e.delete(t,1);else if(i.get(n.key)===n){const e=this.map.get(n.key);if(e)o.add(n.key),r.set(n.key,{action:"update",oldValue:e.val,newValue:n.val});else{const e=r.get(n.key);e&&"delete"===e.action?r.set(n.key,{action:"update",newValue:n.val,oldValue:e.oldValue}):r.set(n.key,{action:"add",newValue:n.val})}i.delete(n.key),this.map.set(n.key,n)}else i.has(n.key)&&(o.add(n.key),i.delete(n.key))}})),r.size>0&&this.emit("change",[r,n])}))}set(e,t){this.doc.transact((n=>{this.map.has(e)&&this.delete(e),this.yarray.push([{key:e,val:t}])}))}delete(e){let t=0;for(const n of this.yarray){if(n.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)}}})),n.register("duJo0",(function(t,r){e(t.exports,"wrapTransport",(function(){return o}));var s=n("3Lnfd"),i=n("6LsB2");function o(e,t,n=0){return t?{connect:t=>e.connect(t),disconnect:()=>e.disconnect(),send:t=>{const r=(new TextEncoder).encode(i.Crypto.encode((0,s.encode)(t)));if(0===n)return e.send(r);const o=new Uint8Array(n+r.length);return o.set(r,n),e.send(o)},onMessage:t=>e.onMessage((e=>{try{const r=0===n?e:e.subarray(n),o=(0,s.decode)(i.Crypto.decode((new TextDecoder).decode(r)));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}})),n.register("6LsB2",(function(t,n){e(t.exports,"Crypto",(function(){return r}));const r={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)}}}))}();
|
package/dist/Nostr.d5c9f5db.js
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
!function(){function t(t,e,s,n){Object.defineProperty(t,e,{get:s,set:n,enumerable:!0,configurable:!0})}var e=("undefined"!=typeof globalThis?globalThis:"undefined"!=typeof self?self:"undefined"!=typeof window?window:"undefined"!=typeof global?global:{}).parcelRequirea18f;e.register("fAQE6",(function(s,n){t(s.exports,"Sync",(function(){return c}));var i=e("9Xb5B"),o=e("fOMcY"),r=e("4nLZ9"),h=e("duJo0"),l=e("6LsB2");class c extends i.Sync{persistent=!1;syncFallbackTimer=null;destroy(){null!==this.syncFallbackTimer&&(clearTimeout(this.syncFallbackTimer),this.syncFallbackTimer=null),super.destroy(),this.provider?.disconnect()}async connect(t){super.connect(t),this.relayUrls=t.config?.relayUrls?.length?t.config.relayUrls:void 0,this.persistent=t.config?.persistent||!1;const e=[];window.NostrTools||e.push("https://cdn.jsdelivr.net/npm/nostr-tools@2/lib/nostr.bundle.js"),this.password&&!window.SimpleCrypto&&e.push(l.Crypto.url),0===e.length?this.init(!0):this.load(e,this)}init(t,e){const s=this.uniqueID();if(t&&window.NostrTools&&s){this.password&&l.Crypto.init(this.password);const t=window.NostrTools;class e extends t.SimplePool{constructor(){super({enableReconnect:!0})}}this.transport=new(0,o.NostrTransport)({finalizeEvent:t.finalizeEvent,getPublicKey:t.getPublicKey,SimplePool:e}),this.provider=new(0,r.GenericProvider)(this.db.doc,(0,h.wrapTransport)(this.transport,this.password)),this.db.setAwareness(this.provider.awareness,this.name);let n=!1;const i=()=>{n||(n=!0,null!==this.syncFallbackTimer&&(clearTimeout(this.syncFallbackTimer),this.syncFallbackTimer=null),this.sendConnect())};this.provider.on("synced",(t=>{console.log("Nostr: document synchronized",t.synced),i()})),this.provider.on("status",(t=>{const e=t.state;console.log(`Nostr status: ${e}`),"connected"===e?this.syncFallbackTimer=setTimeout((()=>{console.log("Nostr: sync fallback, proceeding as first peer"),i()}),2e3):"disconnected"===e&&console.warn("Nostr: disconnected")})),this.provider.pubsub.subscribe("*",((t,e)=>{this.onReceive?.(e,t)})),this.provider.connect({room:s,relays:this.relayUrls,persistent:this.persistent,doc:this.persistent?this.db.doc:void 0,waitFor:this.persistReady,...this.password?{password:this.password}:{}})}else{let t="Nostr unknown error";e?t="Could not load resource: "+e:window.NostrTools||(t="Could not load nostr-tools"),this.sendDisconnectError(t)}}pubsubSend(t,e){this.provider&&(this.provider.pubsub.publish(t,e),this.replyOnReceive&&this.onReceive?.(t,e))}}})),e.register("fOMcY",(function(s,n){t(s.exports,"NostrTransport",(function(){return p}));var i=e("7I2MU"),o=e("j3EDv"),r=e("1yxKI");const h=6e4,l=(()=>{const t=new Uint32Array(256);for(let e=0;e<256;e++){let s=e;for(let t=0;t<8;t++)s=1&s?3988292384^s>>>1:s>>>1;t[e]=s}return t})();function c(t){let e="";for(let s=0;s<t.length;s++)e+=String.fromCharCode(t[s]);return btoa(e)}function a(t){const e=atob(t),s=new Uint8Array(e.length);for(let t=0;t<e.length;t++)s[t]=e.charCodeAt(t);return s}const u=["wss://relay.damus.io","wss://nos.lol","wss://nostr.mom"];class p{constructor(t){this.preferredBatchMs=150,this.preferredCompressMinBytes=2048,this.expectedRttMs=600,this._connected=!1,this._buffer=[],this._chunks=new(0,r.ChunkAssembler),this.pool=null,this.sub=null,this.relays=[],this.pubkey="",this.roomTag="",this.persistentMode=!1,this.doc=null,this.persistentKind=30078,this.persistDebounceMs=2e3,this.isPublishingSnapshot=!1,this.publishPending=!1,this.snapshotSub=null,this.snapshotChunks=new(0,r.ChunkAssembler),this._onDocUpdate=()=>this._queueSnapshotPublish(),this.opts=t,this.eventKind=t.eventKind??27370,this.secretKey=t.secretKey??new Uint8Array(32)}get isConnected(){return this._connected}async connect(t){if(this._connected)throw new Error("NostrTransport: already connected");const e=t.debug??this.opts.debug??!1;this.relays=t.relays&&t.relays.length>0?t.relays:u,this.opts.secretKey?this.secretKey=this.opts.secretKey:this.secretKey=crypto.getRandomValues(new Uint8Array(32)),this.pubkey=this.opts.getPublicKey(this.secretKey),this.roomTag=t.password?`${t.room}-${await async function(t){const e=(new TextEncoder).encode(t),s=await crypto.subtle.digest("SHA-256",e);return Array.from(new Uint8Array(s)).map((t=>t.toString(16).padStart(2,"0"))).join("").substring(0,16)}(t.password)}`:t.room;const s=t.historyWindowSecs??86400,n=s>0?Math.floor(Date.now()/1e3)-s:Math.floor(Date.now()/1e3),i={kinds:[this.eventKind],"#r":[this.roomTag],since:n};if(this.pool=new this.opts.SimplePool,e&&console.log("[NostrTransport] Connecting. relays:",this.relays,"room:",this.roomTag,"kind:",this.eventKind,"filter.since:",n),this.sub=this.pool.subscribeMany(this.relays,i,{onevent:t=>{if(t.pubkey!==this.pubkey){e&&console.log("[NostrTransport] Received event",t.id.substring(0,8),"from",t.pubkey.substring(0,8));try{let e=t.content;if(e.startsWith("{")){const t=JSON.parse(e);if(!(0,r.isChunk)(t))return;const s=this._chunks.push(t);if(null===s)return;e=s}this._deliver(a(e))}catch(t){console.warn("[NostrTransport] Failed to decode event content:",t)}}},oneose:()=>{e&&console.log("[NostrTransport] EOSE — stored events delivered")}}),this._connected=!0,this.persistentMode=t.persistent??!1,this.persistentMode){if(!t.doc)throw new Error("NostrTransport: config.doc is required when persistent is true");this.doc=t.doc,this.persistentKind=t.persistentKind??30078,this.persistDebounceMs=t.persistDebounceMs??2e3;const s=Array.from({length:20},((t,e)=>`${this.roomTag}#${e}`));this.snapshotSub=this.pool.subscribeMany(this.relays,{kinds:[this.persistentKind],"#d":s},{onevent:t=>{try{const s=JSON.parse(t.content);if(!(0,r.isChunk)(s))return;const n=this.snapshotChunks.push(s);if(null===n)return;const i=a(n),h=o.createEncoder();o.writeVarUint(h,6),o.writeVarUint8Array(h,i),this._deliver(function(t){const e=function(t){let e=4294967295;for(let s=0;s<t.length;s++)e=e>>>8^l[255&(e^t[s])];return(4294967295^e)>>>0}(t),s=new Uint8Array(5+t.length);return s[1]=e>>>24&255,s[2]=e>>>16&255,s[3]=e>>>8&255,s[4]=255&e,s.set(t,5),s}(o.toUint8Array(h))),e&&console.log("[NostrTransport] Applied persisted snapshot,",i.length,"bytes")}catch(t){console.warn("[NostrTransport] Failed to decode snapshot event:",t)}}}),this.doc.on("update",this._onDocUpdate)}e&&console.log("[NostrTransport] Connected, pubkey:",this.pubkey)}disconnect(){this.sub&&(this.sub.close(),this.sub=null),this.snapshotSub&&(this.snapshotSub.close(),this.snapshotSub=null),this.doc&&(this.doc.off("update",this._onDocUpdate),this.doc=null),this.persistTimer&&(clearTimeout(this.persistTimer),this.persistTimer=void 0),this.persistentMode=!1,this.publishPending=!1,this.snapshotChunks.clear(),this.pool&&(this.pool.close(this.relays),this.pool=null),this._connected=!1,this._buffer=[]}async send(t){if(!this._connected||!this.pool)return void console.warn("[NostrTransport] Cannot send: not connected");const e=c(t),s=e.length>h?(0,r.splitChunks)(e,h).map((t=>JSON.stringify(t))):[e];for(const t of s){const e=this.opts.finalizeEvent({kind:this.eventKind,created_at:Math.floor(Date.now()/1e3),tags:[["r",this.roomTag]],content:t},this.secretKey);await Promise.allSettled(this.pool.publish(this.relays,e))}}_queueSnapshotPublish(){this.persistTimer&&clearTimeout(this.persistTimer),this.persistTimer=setTimeout((()=>this._publishSnapshot()),this.persistDebounceMs)}async _publishSnapshot(){if(this.pool&&this.doc)if(this.isPublishingSnapshot)this.publishPending=!0;else{this.isPublishingSnapshot=!0,this.publishPending=!1;try{const t=c(i.encodeStateAsUpdate(this.doc)),e=(0,r.splitChunks)(t,h);if(e.length>20)return void console.warn(`[NostrTransport] Snapshot needs ${e.length} chunks, more than MAX_SNAPSHOT_CHUNKS (20); skipping this publish. The live update channel still keeps connected peers in sync; the next smaller snapshot will catch late joiners up again.`);for(const t of e){const e=this.opts.finalizeEvent({kind:this.persistentKind,created_at:Math.floor(Date.now()/1e3),tags:[["d",`${this.roomTag}#${t.index}`]],content:JSON.stringify(t)},this.secretKey);await Promise.allSettled(this.pool.publish(this.relays,e))}}catch(t){console.warn("[NostrTransport] Failed to publish snapshot:",t)}finally{this.isPublishingSnapshot=!1,this.publishPending&&this._queueSnapshotPublish()}}}onMessage(t){if(this._callback=t,this._buffer.length>0){for(const e of this._buffer)t(e);this._buffer=[]}return()=>{this._callback=void 0}}_deliver(t){this._callback?this._callback(t):this._buffer.push(t)}}})),e.register("1yxKI",(function(e,s){function n(t){return"object"==typeof t&&null!==t&&!0===t.chunked&&"string"==typeof t.id&&"string"==typeof t.data}function i(t,e){const s=Math.random().toString(36).slice(2)+Date.now().toString(36),n=Math.max(1,Math.ceil(t.length/e)),i=[];for(let o=0;o<n;o++)i.push({chunked:!0,id:s,index:o,total:n,data:t.slice(o*e,(o+1)*e)});return i}t(e.exports,"isChunk",(function(){return n})),t(e.exports,"splitChunks",(function(){return i})),t(e.exports,"ChunkAssembler",(function(){return o}));class o{constructor(t=32){this.maxPending=t,this.pending=new Map}push(t){let e=this.pending.get(t.id);if(e||(this.pending.size>=this.maxPending&&this.pending.delete(this.pending.keys().next().value),e=new Map,this.pending.set(t.id,e)),e.set(t.index,t.data),e.size<t.total)return null;this.pending.delete(t.id);let s="";for(let n=0;n<t.total;n++){const t=e.get(n);if(void 0===t)return null;s+=t}return s}clear(){this.pending.clear()}}})),e.register("5Cbw2",(function(t,e){var s,n,i=t.exports={};function o(){throw new Error("setTimeout has not been defined")}function r(){throw new Error("clearTimeout has not been defined")}function h(t){if(s===setTimeout)return setTimeout(t,0);if((s===o||!s)&&setTimeout)return s=setTimeout,setTimeout(t,0);try{return s(t,0)}catch(e){try{return s.call(null,t,0)}catch(e){return s.call(this,t,0)}}}!function(){try{s="function"==typeof setTimeout?setTimeout:o}catch(t){s=o}try{n="function"==typeof clearTimeout?clearTimeout:r}catch(t){n=r}}();var l,c=[],a=!1,u=-1;function p(){a&&l&&(a=!1,l.length?c=l.concat(c):u=-1,c.length&&d())}function d(){if(!a){var t=h(p);a=!0;for(var e=c.length;e;){for(l=c,c=[];++u<e;)l&&l[u].run();u=-1,e=c.length}l=null,a=!1,function(t){if(n===clearTimeout)return clearTimeout(t);if((n===r||!n)&&clearTimeout)return n=clearTimeout,clearTimeout(t);try{return n(t)}catch(e){try{return n.call(null,t)}catch(e){return n.call(this,t)}}}(t)}}function f(t,e){this.fun=t,this.array=e}function y(){}i.nextTick=function(t){var e=new Array(arguments.length-1);if(arguments.length>1)for(var s=1;s<arguments.length;s++)e[s-1]=arguments[s];c.push(new f(t,e)),1!==c.length||a||h(d)},f.prototype.run=function(){this.fun.apply(null,this.array)},i.title="browser",i.browser=!0,i.env={},i.argv=[],i.version="",i.versions={},i.on=y,i.addListener=y,i.once=y,i.off=y,i.removeListener=y,i.removeAllListeners=y,i.emit=y,i.prependListener=y,i.prependOnceListener=y,i.listeners=function(t){return[]},i.binding=function(t){throw new Error("process.binding is not supported")},i.cwd=function(){return"/"},i.chdir=function(t){throw new Error("process.chdir is not supported")},i.umask=function(){return 0}}))}();
|