@layers-app/editor 0.5.8-optimization → 0.5.10-optimization

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.
Files changed (51) hide show
  1. package/README.md +0 -19
  2. package/dist/ExcalidrawComponent-D7Z_2awF.cjs +1 -0
  3. package/dist/ExcalidrawComponent-Re4zFgLg.js +283 -0
  4. package/dist/InlineImageComponent-DHgCaPNk.cjs +1 -0
  5. package/dist/InlineImageComponent-kXhZcmF6.js +265 -0
  6. package/dist/collaboration-C7xVk0Zj.cjs +4 -0
  7. package/dist/collaboration-Cn7KizEJ.js +5997 -0
  8. package/dist/excalidraw-C-6bid_P.js +16497 -0
  9. package/dist/excalidraw-DpwKTNBz.cjs +574 -0
  10. package/dist/index-B4yOqKUQ.cjs +1 -0
  11. package/dist/index-BZu8Qnrg.cjs +1 -0
  12. package/dist/index-CFA9Drk2.cjs +16 -0
  13. package/dist/index-CX5msaMB.js +296 -0
  14. package/dist/index-CbQX0N2c.js +136 -0
  15. package/dist/index-DEC5JR_F.js +60 -0
  16. package/dist/index-Dan3tqoj.cjs +1 -0
  17. package/dist/index-WCOc4LNL.js +16600 -0
  18. package/dist/index.cjs +2 -2
  19. package/dist/index.js +12 -13
  20. package/dist/lexical-2rxs76dr.cjs +41 -0
  21. package/dist/lexical-C60GkwxR.js +13122 -0
  22. package/dist/lexical-code-DKIWiZdJ.js +604 -0
  23. package/dist/lexical-code-VafvPacU.cjs +9 -0
  24. package/dist/lexical-collab-1tX9tFVC.js +1025 -0
  25. package/dist/lexical-collab-Nk2LVpJv.cjs +1 -0
  26. package/dist/lexical-file-C52Mze5k.cjs +1 -0
  27. package/dist/lexical-file-DjHP4vVw.js +43 -0
  28. package/dist/lexical-markdown-BSl_ahWw.cjs +12 -0
  29. package/dist/lexical-markdown-DcEwQQba.js +488 -0
  30. package/dist/lodash-3PEMjFQT.cjs +1 -0
  31. package/dist/lodash-jftOdrxX.js +711 -0
  32. package/dist/stats.html +4949 -0
  33. package/dist/vendor-BrXDSyZX.js +136433 -0
  34. package/dist/vendor-Bt6Lma3y.cjs +2469 -0
  35. package/package.json +42 -74
  36. package/dist/layers.8yssqxrI.js +0 -6774
  37. package/dist/layers.B8z-e4Vg.js +0 -7
  38. package/dist/layers.BQLznd92.js +0 -4
  39. package/dist/layers.BVRvG1mv.js +0 -3
  40. package/dist/layers.BjCQNcdJ.js +0 -341
  41. package/dist/layers.BnVn2uMi.js +0 -7723
  42. package/dist/layers.CLcioDq5.js +0 -2511
  43. package/dist/layers.CTSBFg3j.js +0 -1
  44. package/dist/layers.CoCZDINv.js +0 -864
  45. package/dist/layers.D0ZtUpST.js +0 -2
  46. package/dist/layers.D2zjLyjP.js +0 -6
  47. package/dist/layers.DNCgFYS7.js +0 -27
  48. package/dist/layers.Dt_Jdn4Y.js +0 -2227
  49. package/dist/layers.DwX5sVtx.js +0 -1
  50. package/dist/layers.QjAkD17S.js +0 -3677
  51. package/dist/layers.pre7B8K-.js +0 -530
@@ -0,0 +1,4 @@
1
+ "use strict";const c=require("./vendor-Bt6Lma3y.cjs");class De{constructor(t,e){this.clock=t,this.len=e}}class Mt{constructor(){this.clients=new Map}}const At=(r,t,e)=>t.clients.forEach((n,s)=>{const i=r.doc.store.clients.get(s);if(i!=null){const l=i[i.length-1],o=l.id.clock+l.length;for(let a=0,d=n[a];a<n.length&&d.clock<o;d=n[++a])un(r,i,d.clock,d.len,e)}}),Hn=(r,t)=>{let e=0,n=r.length-1;for(;e<=n;){const s=c.floor((e+n)/2),i=r[s],l=i.clock;if(l<=t){if(t<l+i.len)return s;e=s+1}else n=s-1}return null},Rt=(r,t)=>{const e=r.clients.get(t.client);return e!==void 0&&Hn(e,t.clock)!==null},be=r=>{r.clients.forEach(t=>{t.sort((s,i)=>s.clock-i.clock);let e,n;for(e=1,n=1;e<t.length;e++){const s=t[n-1],i=t[e];s.clock+s.len>=i.clock?s.len=c.max(s.len,i.clock+i.len-s.clock):(n<e&&(t[n]=i),n++)}t.length=n})},me=r=>{const t=new Mt;for(let e=0;e<r.length;e++)r[e].clients.forEach((n,s)=>{if(!t.clients.has(s)){const i=n.slice();for(let l=e+1;l<r.length;l++)c.appendTo(i,r[l].clients.get(s)||[]);t.clients.set(s,i)}});return be(t),t},xt=(r,t,e,n)=>{c.setIfUndefined(r.clients,t,()=>[]).push(new De(e,n))},Wn=()=>new Mt,jn=r=>{const t=Wn();return r.clients.forEach((e,n)=>{const s=[];for(let i=0;i<e.length;i++){const l=e[i];if(l.deleted){const o=l.id.clock;let a=l.length;if(i+1<e.length)for(let d=e[i+1];i+1<e.length&&d.deleted;d=e[++i+1])a+=d.length;s.push(new De(o,a))}}s.length>0&&t.clients.set(n,s)}),t},Tt=(r,t)=>{c.writeVarUint(r.restEncoder,t.clients.size),c.from(t.clients.entries()).sort((e,n)=>n[0]-e[0]).forEach(([e,n])=>{r.resetDsCurVal(),c.writeVarUint(r.restEncoder,e);const s=n.length;c.writeVarUint(r.restEncoder,s);for(let i=0;i<s;i++){const l=n[i];r.writeDsClock(l.clock),r.writeDsLen(l.len)}})},Ce=r=>{const t=new Mt,e=c.readVarUint(r.restDecoder);for(let n=0;n<e;n++){r.resetDsCurVal();const s=c.readVarUint(r.restDecoder),i=c.readVarUint(r.restDecoder);if(i>0){const l=c.setIfUndefined(t.clients,s,()=>[]);for(let o=0;o<i;o++)l.push(new De(r.readDsClock(),r.readDsLen()))}}return t},ve=(r,t,e)=>{const n=new Mt,s=c.readVarUint(r.restDecoder);for(let i=0;i<s;i++){r.resetDsCurVal();const l=c.readVarUint(r.restDecoder),o=c.readVarUint(r.restDecoder),a=e.clients.get(l)||[],d=L(e,l);for(let h=0;h<o;h++){const u=r.readDsClock(),f=u+r.readDsLen();if(u<d){d<f&&xt(n,l,d,f-d);let g=nt(a,u),p=a[g];for(!p.deleted&&p.id.clock<u&&(a.splice(g+1,0,ie(t,p,u-p.id.clock)),g++);g<a.length&&(p=a[g++],p.id.clock<f);)p.deleted||(f<p.id.clock+p.length&&a.splice(g,0,ie(t,p,f-p.id.clock)),p.delete(t))}else xt(n,l,u,f-u)}}if(n.clients.size>0){const i=new gt;return c.writeVarUint(i.restEncoder,0),Tt(i,n),i.toUint8Array()}return null},Pe=c.uint32;class kt extends c.ObservableV2{constructor({guid:t=c.uuidv4(),collectionid:e=null,gc:n=!0,gcFilter:s=()=>!0,meta:i=null,autoLoad:l=!1,shouldLoad:o=!0}={}){super(),this.gc=n,this.gcFilter=s,this.clientID=Pe(),this.guid=t,this.collectionid=e,this.share=new Map,this.store=new hn,this._transaction=null,this._transactionCleanups=[],this.subdocs=new Set,this._item=null,this.shouldLoad=o,this.autoLoad=l,this.meta=i,this.isLoaded=!1,this.isSynced=!1,this.isDestroyed=!1,this.whenLoaded=c.create(d=>{this.on("load",()=>{this.isLoaded=!0,d(this)})});const a=()=>c.create(d=>{const h=u=>{(u===void 0||u===!0)&&(this.off("sync",h),d())};this.on("sync",h)});this.on("sync",d=>{d===!1&&this.isSynced&&(this.whenSynced=a()),this.isSynced=d===void 0||d===!0,this.isSynced&&!this.isLoaded&&this.emit("load",[this])}),this.whenSynced=a()}load(){const t=this._item;t!==null&&!this.shouldLoad&&V(t.parent.doc,e=>{e.subdocsLoaded.add(this)},null,!0),this.shouldLoad=!0}getSubdocs(){return this.subdocs}getSubdocGuids(){return new Set(c.from(this.subdocs).map(t=>t.guid))}transact(t,e=null){return V(this,t,e)}get(t,e=N){const n=c.setIfUndefined(this.share,t,()=>{const i=new e;return i._integrate(this,null),i}),s=n.constructor;if(e!==N&&s!==e)if(s===N){const i=new e;i._map=n._map,n._map.forEach(l=>{for(;l!==null;l=l.left)l.parent=i}),i._start=n._start;for(let l=i._start;l!==null;l=l.right)l.parent=i;return i._length=n._length,this.share.set(t,i),i._integrate(this,null),i}else throw new Error(`Type with the name ${t} has already been defined with a different constructor`);return n}getArray(t=""){return this.get(t,ft)}getText(t=""){return this.get(t,It)}getMap(t=""){return this.get(t,pt)}getXmlElement(t=""){return this.get(t,mt)}getXmlFragment(t=""){return this.get(t,wt)}toJSON(){const t={};return this.share.forEach((e,n)=>{t[n]=e.toJSON()}),t}destroy(){this.isDestroyed=!0,c.from(this.subdocs).forEach(e=>e.destroy());const t=this._item;if(t!==null){this._item=null;const e=t.content;e.doc=new kt({guid:this.guid,...e.opts,shouldLoad:!1}),e.doc._item=t,V(t.parent.doc,n=>{const s=e.doc;t.deleted||n.subdocsAdded.add(s),n.subdocsRemoved.add(this)},null,!0)}this.emit("destroyed",[!0]),this.emit("destroy",[this]),super.destroy()}}class tn{constructor(t){this.restDecoder=t}resetDsCurVal(){}readDsClock(){return c.readVarUint(this.restDecoder)}readDsLen(){return c.readVarUint(this.restDecoder)}}class en extends tn{readLeftID(){return A(c.readVarUint(this.restDecoder),c.readVarUint(this.restDecoder))}readRightID(){return A(c.readVarUint(this.restDecoder),c.readVarUint(this.restDecoder))}readClient(){return c.readVarUint(this.restDecoder)}readInfo(){return c.readUint8(this.restDecoder)}readString(){return c.readVarString(this.restDecoder)}readParentInfo(){return c.readVarUint(this.restDecoder)===1}readTypeRef(){return c.readVarUint(this.restDecoder)}readLen(){return c.readVarUint(this.restDecoder)}readAny(){return c.readAny(this.restDecoder)}readBuf(){return c.copyUint8Array(c.readVarUint8Array(this.restDecoder))}readJSON(){return JSON.parse(c.readVarString(this.restDecoder))}readKey(){return c.readVarString(this.restDecoder)}}class Jn{constructor(t){this.dsCurrVal=0,this.restDecoder=t}resetDsCurVal(){this.dsCurrVal=0}readDsClock(){return this.dsCurrVal+=c.readVarUint(this.restDecoder),this.dsCurrVal}readDsLen(){const t=c.readVarUint(this.restDecoder)+1;return this.dsCurrVal+=t,t}}class Et extends Jn{constructor(t){super(t),this.keys=[],c.readVarUint(t),this.keyClockDecoder=new c.IntDiffOptRleDecoder(c.readVarUint8Array(t)),this.clientDecoder=new c.UintOptRleDecoder(c.readVarUint8Array(t)),this.leftClockDecoder=new c.IntDiffOptRleDecoder(c.readVarUint8Array(t)),this.rightClockDecoder=new c.IntDiffOptRleDecoder(c.readVarUint8Array(t)),this.infoDecoder=new c.RleDecoder(c.readVarUint8Array(t),c.readUint8),this.stringDecoder=new c.StringDecoder(c.readVarUint8Array(t)),this.parentInfoDecoder=new c.RleDecoder(c.readVarUint8Array(t),c.readUint8),this.typeRefDecoder=new c.UintOptRleDecoder(c.readVarUint8Array(t)),this.lenDecoder=new c.UintOptRleDecoder(c.readVarUint8Array(t))}readLeftID(){return new bt(this.clientDecoder.read(),this.leftClockDecoder.read())}readRightID(){return new bt(this.clientDecoder.read(),this.rightClockDecoder.read())}readClient(){return this.clientDecoder.read()}readInfo(){return this.infoDecoder.read()}readString(){return this.stringDecoder.read()}readParentInfo(){return this.parentInfoDecoder.read()===1}readTypeRef(){return this.typeRefDecoder.read()}readLen(){return this.lenDecoder.read()}readAny(){return c.readAny(this.restDecoder)}readBuf(){return c.readVarUint8Array(this.restDecoder)}readJSON(){return c.readAny(this.restDecoder)}readKey(){const t=this.keyClockDecoder.read();if(t<this.keys.length)return this.keys[t];{const e=this.stringDecoder.read();return this.keys.push(e),e}}}class nn{constructor(){this.restEncoder=c.createEncoder()}toUint8Array(){return c.toUint8Array(this.restEncoder)}resetDsCurVal(){}writeDsClock(t){c.writeVarUint(this.restEncoder,t)}writeDsLen(t){c.writeVarUint(this.restEncoder,t)}}class Yt extends nn{writeLeftID(t){c.writeVarUint(this.restEncoder,t.client),c.writeVarUint(this.restEncoder,t.clock)}writeRightID(t){c.writeVarUint(this.restEncoder,t.client),c.writeVarUint(this.restEncoder,t.clock)}writeClient(t){c.writeVarUint(this.restEncoder,t)}writeInfo(t){c.writeUint8(this.restEncoder,t)}writeString(t){c.writeVarString(this.restEncoder,t)}writeParentInfo(t){c.writeVarUint(this.restEncoder,t?1:0)}writeTypeRef(t){c.writeVarUint(this.restEncoder,t)}writeLen(t){c.writeVarUint(this.restEncoder,t)}writeAny(t){c.writeAny(this.restEncoder,t)}writeBuf(t){c.writeVarUint8Array(this.restEncoder,t)}writeJSON(t){c.writeVarString(this.restEncoder,JSON.stringify(t))}writeKey(t){c.writeVarString(this.restEncoder,t)}}class rn{constructor(){this.restEncoder=c.createEncoder(),this.dsCurrVal=0}toUint8Array(){return c.toUint8Array(this.restEncoder)}resetDsCurVal(){this.dsCurrVal=0}writeDsClock(t){const e=t-this.dsCurrVal;this.dsCurrVal=t,c.writeVarUint(this.restEncoder,e)}writeDsLen(t){t===0&&c.unexpectedCase(),c.writeVarUint(this.restEncoder,t-1),this.dsCurrVal+=t}}class gt extends rn{constructor(){super(),this.keyMap=new Map,this.keyClock=0,this.keyClockEncoder=new c.IntDiffOptRleEncoder,this.clientEncoder=new c.UintOptRleEncoder,this.leftClockEncoder=new c.IntDiffOptRleEncoder,this.rightClockEncoder=new c.IntDiffOptRleEncoder,this.infoEncoder=new c.RleEncoder(c.writeUint8),this.stringEncoder=new c.StringEncoder,this.parentInfoEncoder=new c.RleEncoder(c.writeUint8),this.typeRefEncoder=new c.UintOptRleEncoder,this.lenEncoder=new c.UintOptRleEncoder}toUint8Array(){const t=c.createEncoder();return c.writeVarUint(t,0),c.writeVarUint8Array(t,this.keyClockEncoder.toUint8Array()),c.writeVarUint8Array(t,this.clientEncoder.toUint8Array()),c.writeVarUint8Array(t,this.leftClockEncoder.toUint8Array()),c.writeVarUint8Array(t,this.rightClockEncoder.toUint8Array()),c.writeVarUint8Array(t,c.toUint8Array(this.infoEncoder)),c.writeVarUint8Array(t,this.stringEncoder.toUint8Array()),c.writeVarUint8Array(t,c.toUint8Array(this.parentInfoEncoder)),c.writeVarUint8Array(t,this.typeRefEncoder.toUint8Array()),c.writeVarUint8Array(t,this.lenEncoder.toUint8Array()),c.writeUint8Array(t,c.toUint8Array(this.restEncoder)),c.toUint8Array(t)}writeLeftID(t){this.clientEncoder.write(t.client),this.leftClockEncoder.write(t.clock)}writeRightID(t){this.clientEncoder.write(t.client),this.rightClockEncoder.write(t.clock)}writeClient(t){this.clientEncoder.write(t)}writeInfo(t){this.infoEncoder.write(t)}writeString(t){this.stringEncoder.write(t)}writeParentInfo(t){this.parentInfoEncoder.write(t?1:0)}writeTypeRef(t){this.typeRefEncoder.write(t)}writeLen(t){this.lenEncoder.write(t)}writeAny(t){c.writeAny(this.restEncoder,t)}writeBuf(t){c.writeVarUint8Array(this.restEncoder,t)}writeJSON(t){c.writeAny(this.restEncoder,t)}writeKey(t){const e=this.keyMap.get(t);e===void 0?(this.keyClockEncoder.write(this.keyClock++),this.stringEncoder.write(t)):this.keyClockEncoder.write(e)}}const Gn=(r,t,e,n)=>{n=c.max(n,t[0].id.clock);const s=nt(t,n);c.writeVarUint(r.restEncoder,t.length-s),r.writeClient(e),c.writeVarUint(r.restEncoder,n);const i=t[s];i.write(r,n-i.id.clock);for(let l=s+1;l<t.length;l++)t[l].write(r,0)},Ue=(r,t,e)=>{const n=new Map;e.forEach((s,i)=>{L(t,i)>s&&n.set(i,s)}),ce(t).forEach((s,i)=>{e.has(i)||n.set(i,0)}),c.writeVarUint(r.restEncoder,n.size),c.from(n.entries()).sort((s,i)=>i[0]-s[0]).forEach(([s,i])=>{Gn(r,t.clients.get(s),s,i)})},zn=(r,t)=>{const e=c.create$3(),n=c.readVarUint(r.restDecoder);for(let s=0;s<n;s++){const i=c.readVarUint(r.restDecoder),l=new Array(i),o=r.readClient();let a=c.readVarUint(r.restDecoder);e.set(o,{i:0,refs:l});for(let d=0;d<i;d++){const h=r.readInfo();switch(c.BITS5&h){case 0:{const u=r.readLen();l[d]=new q(A(o,a),u),a+=u;break}case 10:{const u=c.readVarUint(r.restDecoder);l[d]=new Q(A(o,a),u),a+=u;break}default:{const u=(h&(c.BIT7|c.BIT8))===0,f=new x(A(o,a),null,(h&c.BIT8)===c.BIT8?r.readLeftID():null,null,(h&c.BIT7)===c.BIT7?r.readRightID():null,u?r.readParentInfo()?t.get(r.readString()):r.readLeftID():null,u&&(h&c.BIT6)===c.BIT6?r.readString():null,Ln(r,h));l[d]=f,a+=f.length}}}}return e},Xn=(r,t,e)=>{const n=[];let s=c.from(e.keys()).sort((g,p)=>g-p);if(s.length===0)return null;const i=()=>{if(s.length===0)return null;let g=e.get(s[s.length-1]);for(;g.refs.length===g.i;)if(s.pop(),s.length>0)g=e.get(s[s.length-1]);else return null;return g};let l=i();if(l===null)return null;const o=new hn,a=new Map,d=(g,p)=>{const b=a.get(g);(b==null||b>p)&&a.set(g,p)};let h=l.refs[l.i++];const u=new Map,f=()=>{for(const g of n){const p=g.id.client,b=e.get(p);b?(b.i--,o.clients.set(p,b.refs.slice(b.i)),e.delete(p),b.i=0,b.refs=[]):o.clients.set(p,[g]),s=s.filter(k=>k!==p)}n.length=0};for(;;){if(h.constructor!==Q){const p=c.setIfUndefined(u,h.id.client,()=>L(t,h.id.client))-h.id.clock;if(p<0)n.push(h),d(h.id.client,h.id.clock-1),f();else{const b=h.getMissing(r,t);if(b!==null){n.push(h);const k=e.get(b)||{refs:[],i:0};if(k.refs.length===k.i)d(b,L(t,b)),f();else{h=k.refs[k.i++];continue}}else(p===0||p<h.length)&&(h.integrate(r,p),u.set(h.id.client,h.id.clock+h.length))}}if(n.length>0)h=n.pop();else if(l!==null&&l.i<l.refs.length)h=l.refs[l.i++];else{if(l=i(),l===null)break;h=l.refs[l.i++]}}if(o.clients.size>0){const g=new gt;return Ue(g,o,new Map),c.writeVarUint(g.restEncoder,0),{missing:a,update:g.toUint8Array()}}return null},Zn=(r,t)=>Ue(r,t.doc.store,t.beforeState),Kn=(r,t,e,n=new Et(r))=>V(t,s=>{s.local=!1;let i=!1;const l=s.doc,o=l.store,a=zn(n,l),d=Xn(s,o,a),h=o.pendingStructs;if(h){for(const[f,g]of h.missing)if(g<L(o,f)){i=!0;break}if(d){for(const[f,g]of d.missing){const p=h.missing.get(f);(p==null||p>g)&&h.missing.set(f,g)}h.update=te([h.update,d.update])}}else o.pendingStructs=d;const u=ve(n,s,o);if(o.pendingDs){const f=new Et(c.createDecoder(o.pendingDs));c.readVarUint(f.restDecoder);const g=ve(f,s,o);u&&g?o.pendingDs=te([u,g]):o.pendingDs=u||g}else o.pendingDs=u;if(i){const f=o.pendingStructs.update;o.pendingStructs=null,sn(s.doc,f)}},e,!1),sn=(r,t,e,n=Et)=>{const s=c.createDecoder(t);Kn(s,r,e,new n(s))},qn=(r,t,e)=>sn(r,t,e,en),Qn=(r,t,e=new Map)=>{Ue(r,t.store,e),Tt(r,jn(t.store))},Pn=(r,t=new Uint8Array([0]),e=new gt)=>{const n=cn(t);Qn(e,r,n);const s=[e.toUint8Array()];if(r.store.pendingDs&&s.push(r.store.pendingDs),r.store.pendingStructs&&s.push(br(r.store.pendingStructs.update,t)),s.length>1){if(e.constructor===Yt)return _r(s.map((i,l)=>l===0?i:Ur(i)));if(e.constructor===gt)return te(s)}return s[0]},tr=(r,t)=>Pn(r,t,new Yt),er=r=>{const t=new Map,e=c.readVarUint(r.restDecoder);for(let n=0;n<e;n++){const s=c.readVarUint(r.restDecoder),i=c.readVarUint(r.restDecoder);t.set(s,i)}return t},cn=r=>er(new tn(c.createDecoder(r))),ln=(r,t)=>(c.writeVarUint(r.restEncoder,t.size),c.from(t.entries()).sort((e,n)=>n[0]-e[0]).forEach(([e,n])=>{c.writeVarUint(r.restEncoder,e),c.writeVarUint(r.restEncoder,n)}),r),nr=(r,t)=>ln(r,ce(t.store)),rr=(r,t=new rn)=>(r instanceof Map?ln(t,r):nr(t,r),t.toUint8Array()),sr=r=>rr(r,new nn);class ir{constructor(){this.l=[]}}const Oe=()=>new ir,Le=(r,t)=>r.l.push(t),Re=(r,t)=>{const e=r.l,n=e.length;r.l=e.filter(s=>t!==s),n===r.l.length&&console.error("[yjs] Tried to remove event handler that doesn't exist.")},on=(r,t,e)=>c.callAll(r.l,[t,e]);class bt{constructor(t,e){this.client=t,this.clock=e}}const Dt=(r,t)=>r===t||r!==null&&t!==null&&r.client===t.client&&r.clock===t.clock,A=(r,t)=>new bt(r,t),an=r=>{for(const[t,e]of r.doc.share.entries())if(e===r)return t;throw c.unexpectedCase()},Pt=(r,t)=>{for(;t!==null;){if(t.parent===r)return!0;t=t.parent._item}return!1};class cr{constructor(t,e,n,s=0){this.type=t,this.tname=e,this.item=n,this.assoc=s}}class lr{constructor(t,e,n=0){this.type=t,this.index=e,this.assoc=n}}const or=(r,t,e=0)=>new lr(r,t,e),Jt=(r,t,e)=>{let n=null,s=null;return r._item===null?s=an(r):n=A(r._item.id.client,r._item.id.clock),new cr(n,s,t,e)},ar=(r,t,e=0)=>{let n=r._start;if(e<0){if(t===0)return Jt(r,null,e);t--}for(;n!==null;){if(!n.deleted&&n.countable){if(n.length>t)return Jt(r,A(n.id.client,n.id.clock+t),e);t-=n.length}if(n.right===null&&e<0)return Jt(r,n.lastId,e);n=n.right}return Jt(r,null,e)},hr=(r,t)=>{const e=Ct(r,t),n=t.clock-e.id.clock;return{item:e,diff:n}},dr=(r,t,e=!0)=>{const n=t.store,s=r.item,i=r.type,l=r.tname,o=r.assoc;let a=null,d=0;if(s!==null){if(L(n,s.client)<=s.clock)return null;const h=e?_e(n,s):hr(n,s),u=h.item;if(!(u instanceof x))return null;if(a=u.parent,a._item===null||!a._item.deleted){d=u.deleted||!u.countable?0:h.diff+(o>=0?0:1);let f=u.left;for(;f!==null;)!f.deleted&&f.countable&&(d+=f.length),f=f.left}}else{if(l!==null)a=t.get(l);else if(i!==null){if(L(n,i.client)<=i.clock)return null;const{item:h}=e?_e(n,i):{item:Ct(n,i)};if(h instanceof x&&h.content instanceof st)a=h.content.type;else return null}else throw c.unexpectedCase();o>=0?d=a._length:d=0}return or(a,d,r.assoc)},ur=(r,t)=>r===t||r!==null&&t!==null&&r.tname===t.tname&&Dt(r.item,t.item)&&Dt(r.type,t.type)&&r.assoc===t.assoc,_t=(r,t)=>t===void 0?!r.deleted:t.sv.has(r.id.client)&&(t.sv.get(r.id.client)||0)>r.id.clock&&!Rt(t.ds,r.id),ye=(r,t)=>{const e=c.setIfUndefined(r.meta,ye,c.create$2),n=r.doc.store;e.has(t)||(t.sv.forEach((s,i)=>{s<L(n,i)&&z(r,A(i,s))}),At(r,t.ds,s=>{}),e.add(t))};class hn{constructor(){this.clients=new Map,this.pendingStructs=null,this.pendingDs=null}}const ce=r=>{const t=new Map;return r.clients.forEach((e,n)=>{const s=e[e.length-1];t.set(n,s.id.clock+s.length)}),t},L=(r,t)=>{const e=r.clients.get(t);if(e===void 0)return 0;const n=e[e.length-1];return n.id.clock+n.length},dn=(r,t)=>{let e=r.clients.get(t.id.client);if(e===void 0)e=[],r.clients.set(t.id.client,e);else{const n=e[e.length-1];if(n.id.clock+n.length!==t.id.clock)throw c.unexpectedCase()}e.push(t)},nt=(r,t)=>{let e=0,n=r.length-1,s=r[n],i=s.id.clock;if(i===t)return n;let l=c.floor(t/(i+s.length-1)*n);for(;e<=n;){if(s=r[l],i=s.id.clock,i<=t){if(t<i+s.length)return l;e=l+1}else n=l-1;l=c.floor((e+n)/2)}throw c.unexpectedCase()},fr=(r,t)=>{const e=r.clients.get(t.client);return e[nt(e,t.clock)]},Ct=fr,ke=(r,t,e)=>{const n=nt(t,e),s=t[n];return s.id.clock<e&&s instanceof x?(t.splice(n+1,0,ie(r,s,e-s.id.clock)),n+1):n},z=(r,t)=>{const e=r.doc.store.clients.get(t.client);return e[ke(r,e,t.clock)]},Ye=(r,t,e)=>{const n=t.clients.get(e.client),s=nt(n,e.clock),i=n[s];return e.clock!==i.id.clock+i.length-1&&i.constructor!==q&&n.splice(s+1,0,ie(r,i,e.clock-i.id.clock+1)),i},gr=(r,t,e)=>{const n=r.clients.get(t.id.client);n[nt(n,t.id.clock)]=e},un=(r,t,e,n,s)=>{if(n===0)return;const i=e+n;let l=ke(r,t,e),o;do o=t[l++],i<o.id.clock+o.length&&ke(r,t,i),s(o);while(l<t.length&&t[l].id.clock<i)};class pr{constructor(t,e,n){this.doc=t,this.deleteSet=new Mt,this.beforeState=ce(t.store),this.afterState=new Map,this.changed=new Map,this.changedParentTypes=new Map,this._mergeStructs=[],this.origin=e,this.meta=new Map,this.local=n,this.subdocsAdded=new Set,this.subdocsRemoved=new Set,this.subdocsLoaded=new Set,this._needFormattingCleanup=!1}}const Ne=(r,t)=>t.deleteSet.clients.size===0&&!c.any(t.afterState,(e,n)=>t.beforeState.get(n)!==e)?!1:(be(t.deleteSet),Zn(r,t),Tt(r,t.deleteSet),!0),Fe=(r,t,e)=>{const n=t._item;(n===null||n.id.clock<(r.beforeState.get(n.id.client)||0)&&!n.deleted)&&c.setIfUndefined(r.changed,t,c.create$2).add(e)},Xt=(r,t)=>{let e=r[t],n=r[t-1],s=t;for(;s>0;e=n,n=r[--s-1]){if(n.deleted===e.deleted&&n.constructor===e.constructor&&n.mergeWith(e)){e instanceof x&&e.parentSub!==null&&e.parent._map.get(e.parentSub)===e&&e.parent._map.set(e.parentSub,n);continue}break}const i=t-s;return i&&r.splice(t+1-i,i),i},wr=(r,t,e)=>{for(const[n,s]of r.clients.entries()){const i=t.clients.get(n);for(let l=s.length-1;l>=0;l--){const o=s[l],a=o.clock+o.len;for(let d=nt(i,o.clock),h=i[d];d<i.length&&h.id.clock<a;h=i[++d]){const u=i[d];if(o.clock+o.len<=u.id.clock)break;u instanceof x&&u.deleted&&!u.keep&&e(u)&&u.gc(t,!1)}}}},mr=(r,t)=>{r.clients.forEach((e,n)=>{const s=t.clients.get(n);for(let i=e.length-1;i>=0;i--){const l=e[i],o=c.min(s.length-1,1+nt(s,l.clock+l.len-1));for(let a=o,d=s[a];a>0&&d.id.clock>=l.clock;d=s[a])a-=1+Xt(s,a)}})},fn=(r,t)=>{if(t<r.length){const e=r[t],n=e.doc,s=n.store,i=e.deleteSet,l=e._mergeStructs;try{be(i),e.afterState=ce(e.doc.store),n.emit("beforeObserverCalls",[e,n]);const o=[];e.changed.forEach((a,d)=>o.push(()=>{(d._item===null||!d._item.deleted)&&d._callObserver(e,a)})),o.push(()=>{e.changedParentTypes.forEach((a,d)=>{d._dEH.l.length>0&&(d._item===null||!d._item.deleted)&&(a=a.filter(h=>h.target._item===null||!h.target._item.deleted),a.forEach(h=>{h.currentTarget=d,h._path=null}),a.sort((h,u)=>h.path.length-u.path.length),on(d._dEH,a,e))})}),o.push(()=>n.emit("afterTransaction",[e,n])),c.callAll(o,[]),e._needFormattingCleanup&&Rr(e)}finally{n.gc&&wr(i,s,n.gcFilter),mr(i,s),e.afterState.forEach((h,u)=>{const f=e.beforeState.get(u)||0;if(f!==h){const g=s.clients.get(u),p=c.max(nt(g,f),1);for(let b=g.length-1;b>=p;)b-=1+Xt(g,b)}});for(let h=l.length-1;h>=0;h--){const{client:u,clock:f}=l[h].id,g=s.clients.get(u),p=nt(g,f);p+1<g.length&&Xt(g,p+1)>1||p>0&&Xt(g,p)}if(!e.local&&e.afterState.get(n.clientID)!==e.beforeState.get(n.clientID)&&(c.print(c.ORANGE,c.BOLD,"[yjs] ",c.UNBOLD,c.RED,"Changed the client-id because another client seems to be using it."),n.clientID=Pe()),n.emit("afterTransactionCleanup",[e,n]),n._observers.has("update")){const h=new Yt;Ne(h,e)&&n.emit("update",[h.toUint8Array(),e.origin,n,e])}if(n._observers.has("updateV2")){const h=new gt;Ne(h,e)&&n.emit("updateV2",[h.toUint8Array(),e.origin,n,e])}const{subdocsAdded:o,subdocsLoaded:a,subdocsRemoved:d}=e;(o.size>0||d.size>0||a.size>0)&&(o.forEach(h=>{h.clientID=n.clientID,h.collectionid==null&&(h.collectionid=n.collectionid),n.subdocs.add(h)}),d.forEach(h=>n.subdocs.delete(h)),n.emit("subdocs",[{loaded:a,added:o,removed:d},n,e]),d.forEach(h=>h.destroy())),r.length<=t+1?(n._transactionCleanups=[],n.emit("afterAllTransactions",[n,r])):fn(r,t+1)}}},V=(r,t,e=null,n=!0)=>{const s=r._transactionCleanups;let i=!1,l=null;r._transaction===null&&(i=!0,r._transaction=new pr(r,e,n),s.push(r._transaction),s.length===1&&r.emit("beforeAllTransactions",[r]),r.emit("beforeTransaction",[r._transaction,r]));try{l=t(r._transaction)}finally{if(i){const o=r._transaction===s[0];r._transaction=null,o&&fn(s,0)}}return l};class yr{constructor(t,e){this.insertions=e,this.deletions=t,this.meta=new Map}}const Be=(r,t,e)=>{At(r,e.deletions,n=>{n instanceof x&&t.scope.some(s=>s===r.doc||Pt(s,n))&&$e(n,!1)})},He=(r,t,e)=>{let n=null;const s=r.doc,i=r.scope;V(s,o=>{for(;t.length>0&&r.currStackItem===null;){const a=s.store,d=t.pop(),h=new Set,u=[];let f=!1;At(o,d.insertions,g=>{if(g instanceof x){if(g.redone!==null){let{item:p,diff:b}=_e(a,g.id);b>0&&(p=z(o,A(p.id.client,p.id.clock+b))),g=p}!g.deleted&&i.some(p=>p===o.doc||Pt(p,g))&&u.push(g)}}),At(o,d.deletions,g=>{g instanceof x&&i.some(p=>p===o.doc||Pt(p,g))&&!Rt(d.insertions,g.id)&&h.add(g)}),h.forEach(g=>{f=On(o,g,h,d.insertions,r.ignoreRemoteMapChanges,r)!==null||f});for(let g=u.length-1;g>=0;g--){const p=u[g];r.deleteFilter(p)&&(p.delete(o),f=!0)}r.currStackItem=f?d:null}o.changed.forEach((a,d)=>{a.has(null)&&d._searchMarker&&(d._searchMarker.length=0)}),n=o},r);const l=r.currStackItem;if(l!=null){const o=n.changedParentTypes;r.emit("stack-item-popped",[{stackItem:l,type:e,changedParentTypes:o,origin:r},r]),r.currStackItem=null}return l};class kr extends c.ObservableV2{constructor(t,{captureTimeout:e=500,captureTransaction:n=a=>!0,deleteFilter:s=()=>!0,trackedOrigins:i=new Set([null]),ignoreRemoteMapChanges:l=!1,doc:o=c.isArray(t)?t[0].doc:t instanceof kt?t:t.doc}={}){super(),this.scope=[],this.doc=o,this.addToScope(t),this.deleteFilter=s,i.add(this),this.trackedOrigins=i,this.captureTransaction=n,this.undoStack=[],this.redoStack=[],this.undoing=!1,this.redoing=!1,this.currStackItem=null,this.lastChange=0,this.ignoreRemoteMapChanges=l,this.captureTimeout=e,this.afterTransactionHandler=a=>{if(!this.captureTransaction(a)||!this.scope.some(k=>a.changedParentTypes.has(k)||k===this.doc)||!this.trackedOrigins.has(a.origin)&&(!a.origin||!this.trackedOrigins.has(a.origin.constructor)))return;const d=this.undoing,h=this.redoing,u=d?this.redoStack:this.undoStack;d?this.stopCapturing():h||this.clear(!1,!0);const f=new Mt;a.afterState.forEach((k,S)=>{const T=a.beforeState.get(S)||0,M=k-T;M>0&&xt(f,S,T,M)});const g=c.getUnixTime();let p=!1;if(this.lastChange>0&&g-this.lastChange<this.captureTimeout&&u.length>0&&!d&&!h){const k=u[u.length-1];k.deletions=me([k.deletions,a.deleteSet]),k.insertions=me([k.insertions,f])}else u.push(new yr(a.deleteSet,f)),p=!0;!d&&!h&&(this.lastChange=g),At(a,a.deleteSet,k=>{k instanceof x&&this.scope.some(S=>S===a.doc||Pt(S,k))&&$e(k,!0)});const b=[{stackItem:u[u.length-1],origin:a.origin,type:d?"redo":"undo",changedParentTypes:a.changedParentTypes},this];p?this.emit("stack-item-added",b):this.emit("stack-item-updated",b)},this.doc.on("afterTransaction",this.afterTransactionHandler),this.doc.on("destroy",()=>{this.destroy()})}addToScope(t){const e=new Set(this.scope);t=c.isArray(t)?t:[t],t.forEach(n=>{e.has(n)||(e.add(n),(n instanceof N?n.doc!==this.doc:n!==this.doc)&&c.warn("[yjs#509] Not same Y.Doc"),this.scope.push(n))})}addTrackedOrigin(t){this.trackedOrigins.add(t)}removeTrackedOrigin(t){this.trackedOrigins.delete(t)}clear(t=!0,e=!0){(t&&this.canUndo()||e&&this.canRedo())&&this.doc.transact(n=>{t&&(this.undoStack.forEach(s=>Be(n,this,s)),this.undoStack=[]),e&&(this.redoStack.forEach(s=>Be(n,this,s)),this.redoStack=[]),this.emit("stack-cleared",[{undoStackCleared:t,redoStackCleared:e}])})}stopCapturing(){this.lastChange=0}undo(){this.undoing=!0;let t;try{t=He(this,this.undoStack,"undo")}finally{this.undoing=!1}return t}redo(){this.redoing=!0;let t;try{t=He(this,this.redoStack,"redo")}finally{this.redoing=!1}return t}canUndo(){return this.undoStack.length>0}canRedo(){return this.redoStack.length>0}destroy(){this.trackedOrigins.delete(this),this.doc.off("afterTransaction",this.afterTransactionHandler),super.destroy()}}function*Sr(r){const t=c.readVarUint(r.restDecoder);for(let e=0;e<t;e++){const n=c.readVarUint(r.restDecoder),s=r.readClient();let i=c.readVarUint(r.restDecoder);for(let l=0;l<n;l++){const o=r.readInfo();if(o===10){const a=c.readVarUint(r.restDecoder);yield new Q(A(s,i),a),i+=a}else if((c.BITS5&o)!==0){const a=(o&(c.BIT7|c.BIT8))===0,d=new x(A(s,i),null,(o&c.BIT8)===c.BIT8?r.readLeftID():null,null,(o&c.BIT7)===c.BIT7?r.readRightID():null,a?r.readParentInfo()?r.readString():r.readLeftID():null,a&&(o&c.BIT6)===c.BIT6?r.readString():null,Ln(r,o));yield d,i+=d.length}else{const a=r.readLen();yield new q(A(s,i),a),i+=a}}}}class Ae{constructor(t,e){this.gen=Sr(t),this.curr=null,this.done=!1,this.filterSkips=e,this.next()}next(){do this.curr=this.gen.next().value||null;while(this.filterSkips&&this.curr!==null&&this.curr.constructor===Q);return this.curr}}class Ee{constructor(t){this.currClient=0,this.startClock=0,this.written=0,this.encoder=t,this.clientStructs=[]}}const _r=r=>te(r,en,Yt),Dr=(r,t)=>{if(r.constructor===q){const{client:e,clock:n}=r.id;return new q(A(e,n+t),r.length-t)}else if(r.constructor===Q){const{client:e,clock:n}=r.id;return new Q(A(e,n+t),r.length-t)}else{const e=r,{client:n,clock:s}=e.id;return new x(A(n,s+t),null,A(n,s+t-1),null,e.rightOrigin,e.parent,e.parentSub,e.content.splice(t))}},te=(r,t=Et,e=gt)=>{if(r.length===1)return r[0];const n=r.map(h=>new t(c.createDecoder(h)));let s=n.map(h=>new Ae(h,!0)),i=null;const l=new e,o=new Ee(l);for(;s=s.filter(f=>f.curr!==null),s.sort((f,g)=>{if(f.curr.id.client===g.curr.id.client){const p=f.curr.id.clock-g.curr.id.clock;return p===0?f.curr.constructor===g.curr.constructor?0:f.curr.constructor===Q?1:-1:p}else return g.curr.id.client-f.curr.id.client}),s.length!==0;){const h=s[0],u=h.curr.id.client;if(i!==null){let f=h.curr,g=!1;for(;f!==null&&f.id.clock+f.length<=i.struct.id.clock+i.struct.length&&f.id.client>=i.struct.id.client;)f=h.next(),g=!0;if(f===null||f.id.client!==u||g&&f.id.clock>i.struct.id.clock+i.struct.length)continue;if(u!==i.struct.id.client)at(o,i.struct,i.offset),i={struct:f,offset:0},h.next();else if(i.struct.id.clock+i.struct.length<f.id.clock)if(i.struct.constructor===Q)i.struct.length=f.id.clock+f.length-i.struct.id.clock;else{at(o,i.struct,i.offset);const p=f.id.clock-i.struct.id.clock-i.struct.length;i={struct:new Q(A(u,i.struct.id.clock+i.struct.length),p),offset:0}}else{const p=i.struct.id.clock+i.struct.length-f.id.clock;p>0&&(i.struct.constructor===Q?i.struct.length-=p:f=Dr(f,p)),i.struct.mergeWith(f)||(at(o,i.struct,i.offset),i={struct:f,offset:0},h.next())}}else i={struct:h.curr,offset:0},h.next();for(let f=h.curr;f!==null&&f.id.client===u&&f.id.clock===i.struct.id.clock+i.struct.length&&f.constructor!==Q;f=h.next())at(o,i.struct,i.offset),i={struct:f,offset:0}}i!==null&&(at(o,i.struct,i.offset),i=null),Ie(o);const a=n.map(h=>Ce(h)),d=me(a);return Tt(l,d),l.toUint8Array()},br=(r,t,e=Et,n=gt)=>{const s=cn(t),i=new n,l=new Ee(i),o=new e(c.createDecoder(r)),a=new Ae(o,!1);for(;a.curr;){const h=a.curr,u=h.id.client,f=s.get(u)||0;if(a.curr.constructor===Q){a.next();continue}if(h.id.clock+h.length>f)for(at(l,h,c.max(f-h.id.clock,0)),a.next();a.curr&&a.curr.id.client===u;)at(l,a.curr,0),a.next();else for(;a.curr&&a.curr.id.client===u&&a.curr.id.clock+a.curr.length<=f;)a.next()}Ie(l);const d=Ce(o);return Tt(i,d),i.toUint8Array()},gn=r=>{r.written>0&&(r.clientStructs.push({written:r.written,restEncoder:c.toUint8Array(r.encoder.restEncoder)}),r.encoder.restEncoder=c.createEncoder(),r.written=0)},at=(r,t,e)=>{r.written>0&&r.currClient!==t.id.client&&gn(r),r.written===0&&(r.currClient=t.id.client,r.encoder.writeClient(t.id.client),c.writeVarUint(r.encoder.restEncoder,t.id.clock+e)),t.write(r.encoder,e),r.written++},Ie=r=>{gn(r);const t=r.encoder.restEncoder;c.writeVarUint(t,r.clientStructs.length);for(let e=0;e<r.clientStructs.length;e++){const n=r.clientStructs[e];c.writeVarUint(t,n.written),c.writeUint8Array(t,n.restEncoder)}},Cr=(r,t,e,n)=>{const s=new e(c.createDecoder(r)),i=new Ae(s,!1),l=new n,o=new Ee(l);for(let d=i.curr;d!==null;d=i.next())at(o,t(d),0);Ie(o);const a=Ce(s);return Tt(l,a),l.toUint8Array()},Ur=r=>Cr(r,c.id,Et,Yt),We="You must not compute changes after the event-handler fired.";class le{constructor(t,e){this.target=t,this.currentTarget=t,this.transaction=e,this._changes=null,this._keys=null,this._delta=null,this._path=null}get path(){return this._path||(this._path=Ar(this.currentTarget,this.target))}deletes(t){return Rt(this.transaction.deleteSet,t.id)}get keys(){if(this._keys===null){if(this.transaction.doc._transactionCleanups.length===0)throw c.create$1(We);const t=new Map,e=this.target;this.transaction.changed.get(e).forEach(s=>{if(s!==null){const i=e._map.get(s);let l,o;if(this.adds(i)){let a=i.left;for(;a!==null&&this.adds(a);)a=a.left;if(this.deletes(i))if(a!==null&&this.deletes(a))l="delete",o=c.last(a.content.getContent());else return;else a!==null&&this.deletes(a)?(l="update",o=c.last(a.content.getContent())):(l="add",o=void 0)}else if(this.deletes(i))l="delete",o=c.last(i.content.getContent());else return;t.set(s,{action:l,oldValue:o})}}),this._keys=t}return this._keys}get delta(){return this.changes.delta}adds(t){return t.id.clock>=(this.transaction.beforeState.get(t.id.client)||0)}get changes(){let t=this._changes;if(t===null){if(this.transaction.doc._transactionCleanups.length===0)throw c.create$1(We);const e=this.target,n=c.create$2(),s=c.create$2(),i=[];if(t={added:n,deleted:s,delta:i,keys:this.keys},this.transaction.changed.get(e).has(null)){let o=null;const a=()=>{o&&i.push(o)};for(let d=e._start;d!==null;d=d.right)d.deleted?this.deletes(d)&&!this.adds(d)&&((o===null||o.delete===void 0)&&(a(),o={delete:0}),o.delete+=d.length,s.add(d)):this.adds(d)?((o===null||o.insert===void 0)&&(a(),o={insert:[]}),o.insert=o.insert.concat(d.content.getContent()),n.add(d)):((o===null||o.retain===void 0)&&(a(),o={retain:0}),o.retain+=d.length);o!==null&&o.retain===void 0&&a()}this._changes=t}return t}}const Ar=(r,t)=>{const e=[];for(;t._item!==null&&t!==r;){if(t._item.parentSub!==null)e.unshift(t._item.parentSub);else{let n=0,s=t._item.parent._start;for(;s!==t._item&&s!==null;)!s.deleted&&s.countable&&(n+=s.length),s=s.right;e.unshift(n)}t=t._item.parent}return e},B=()=>{c.warn("Invalid access: Add Yjs type to a document before reading data.")},pn=80;let Me=0;class Er{constructor(t,e){t.marker=!0,this.p=t,this.index=e,this.timestamp=Me++}}const Ir=r=>{r.timestamp=Me++},wn=(r,t,e)=>{r.p.marker=!1,r.p=t,t.marker=!0,r.index=e,r.timestamp=Me++},Mr=(r,t,e)=>{if(r.length>=pn){const n=r.reduce((s,i)=>s.timestamp<i.timestamp?s:i);return wn(n,t,e),n}else{const n=new Er(t,e);return r.push(n),n}},oe=(r,t)=>{if(r._start===null||t===0||r._searchMarker===null)return null;const e=r._searchMarker.length===0?null:r._searchMarker.reduce((i,l)=>c.abs(t-i.index)<c.abs(t-l.index)?i:l);let n=r._start,s=0;for(e!==null&&(n=e.p,s=e.index,Ir(e));n.right!==null&&s<t;){if(!n.deleted&&n.countable){if(t<s+n.length)break;s+=n.length}n=n.right}for(;n.left!==null&&s>t;)n=n.left,!n.deleted&&n.countable&&(s-=n.length);for(;n.left!==null&&n.left.id.client===n.id.client&&n.left.id.clock+n.left.length===n.id.clock;)n=n.left,!n.deleted&&n.countable&&(s-=n.length);return e!==null&&c.abs(e.index-s)<n.parent.length/pn?(wn(e,n,s),e):Mr(r._searchMarker,n,s)},$t=(r,t,e)=>{for(let n=r.length-1;n>=0;n--){const s=r[n];if(e>0){let i=s.p;for(i.marker=!1;i&&(i.deleted||!i.countable);)i=i.left,i&&!i.deleted&&i.countable&&(s.index-=i.length);if(i===null||i.marker===!0){r.splice(n,1);continue}s.p=i,i.marker=!0}(t<s.index||e>0&&t===s.index)&&(s.index=c.max(t,s.index+e))}},ae=(r,t,e)=>{const n=r,s=t.changedParentTypes;for(;c.setIfUndefined(s,r,()=>[]).push(e),r._item!==null;)r=r._item.parent;on(n._eH,e,t)};class N{constructor(){this._item=null,this._map=new Map,this._start=null,this.doc=null,this._length=0,this._eH=Oe(),this._dEH=Oe(),this._searchMarker=null}get parent(){return this._item?this._item.parent:null}_integrate(t,e){this.doc=t,this._item=e}_copy(){throw c.methodUnimplemented()}clone(){throw c.methodUnimplemented()}_write(t){}get _first(){let t=this._start;for(;t!==null&&t.deleted;)t=t.right;return t}_callObserver(t,e){!t.local&&this._searchMarker&&(this._searchMarker.length=0)}observe(t){Le(this._eH,t)}observeDeep(t){Le(this._dEH,t)}unobserve(t){Re(this._eH,t)}unobserveDeep(t){Re(this._dEH,t)}toJSON(){}}const mn=(r,t,e)=>{r.doc??B(),t<0&&(t=r._length+t),e<0&&(e=r._length+e);let n=e-t;const s=[];let i=r._start;for(;i!==null&&n>0;){if(i.countable&&!i.deleted){const l=i.content.getContent();if(l.length<=t)t-=l.length;else{for(let o=t;o<l.length&&n>0;o++)s.push(l[o]),n--;t=0}}i=i.right}return s},yn=r=>{r.doc??B();const t=[];let e=r._start;for(;e!==null;){if(e.countable&&!e.deleted){const n=e.content.getContent();for(let s=0;s<n.length;s++)t.push(n[s])}e=e.right}return t},vt=(r,t)=>{let e=0,n=r._start;for(r.doc??B();n!==null;){if(n.countable&&!n.deleted){const s=n.content.getContent();for(let i=0;i<s.length;i++)t(s[i],e++,r)}n=n.right}},kn=(r,t)=>{const e=[];return vt(r,(n,s)=>{e.push(t(n,s,r))}),e},Tr=r=>{let t=r._start,e=null,n=0;return{[Symbol.iterator](){return this},next:()=>{if(e===null){for(;t!==null&&t.deleted;)t=t.right;if(t===null)return{done:!0,value:void 0};e=t.content.getContent(),n=0,t=t.right}const s=e[n++];return e.length<=n&&(e=null),{done:!1,value:s}}}},Sn=(r,t)=>{r.doc??B();const e=oe(r,t);let n=r._start;for(e!==null&&(n=e.p,t-=e.index);n!==null;n=n.right)if(!n.deleted&&n.countable){if(t<n.length)return n.content.getContent()[t];t-=n.length}},ee=(r,t,e,n)=>{let s=e;const i=r.doc,l=i.clientID,o=i.store,a=e===null?t._start:e.right;let d=[];const h=()=>{d.length>0&&(s=new x(A(l,L(o,l)),s,s&&s.lastId,a,a&&a.id,t,null,new yt(d)),s.integrate(r,0),d=[])};n.forEach(u=>{if(u===null)d.push(u);else switch(u.constructor){case Number:case Object:case Boolean:case Array:case String:d.push(u);break;default:switch(h(),u.constructor){case Uint8Array:case ArrayBuffer:s=new x(A(l,L(o,l)),s,s&&s.lastId,a,a&&a.id,t,null,new Nt(new Uint8Array(u))),s.integrate(r,0);break;case kt:s=new x(A(l,L(o,l)),s,s&&s.lastId,a,a&&a.id,t,null,new Ft(u)),s.integrate(r,0);break;default:if(u instanceof N)s=new x(A(l,L(o,l)),s,s&&s.lastId,a,a&&a.id,t,null,new st(u)),s.integrate(r,0);else throw new Error("Unexpected content type in insert operation")}}}),h()},_n=()=>c.create$1("Length exceeded!"),Dn=(r,t,e,n)=>{if(e>t._length)throw _n();if(e===0)return t._searchMarker&&$t(t._searchMarker,e,n.length),ee(r,t,null,n);const s=e,i=oe(t,e);let l=t._start;for(i!==null&&(l=i.p,e-=i.index,e===0&&(l=l.prev,e+=l&&l.countable&&!l.deleted?l.length:0));l!==null;l=l.right)if(!l.deleted&&l.countable){if(e<=l.length){e<l.length&&z(r,A(l.id.client,l.id.clock+e));break}e-=l.length}return t._searchMarker&&$t(t._searchMarker,s,n.length),ee(r,t,l,n)},Vr=(r,t,e)=>{let s=(t._searchMarker||[]).reduce((i,l)=>l.index>i.index?l:i,{index:0,p:t._start}).p;if(s)for(;s.right;)s=s.right;return ee(r,t,s,e)},bn=(r,t,e,n)=>{if(n===0)return;const s=e,i=n,l=oe(t,e);let o=t._start;for(l!==null&&(o=l.p,e-=l.index);o!==null&&e>0;o=o.right)!o.deleted&&o.countable&&(e<o.length&&z(r,A(o.id.client,o.id.clock+e)),e-=o.length);for(;n>0&&o!==null;)o.deleted||(n<o.length&&z(r,A(o.id.client,o.id.clock+n)),o.delete(r),n-=o.length),o=o.right;if(n>0)throw _n();t._searchMarker&&$t(t._searchMarker,s,-i+n)},ne=(r,t,e)=>{const n=t._map.get(e);n!==void 0&&n.delete(r)},Te=(r,t,e,n)=>{const s=t._map.get(e)||null,i=r.doc,l=i.clientID;let o;if(n==null)o=new yt([n]);else switch(n.constructor){case Number:case Object:case Boolean:case Array:case String:case Date:case BigInt:o=new yt([n]);break;case Uint8Array:o=new Nt(n);break;case kt:o=new Ft(n);break;default:if(n instanceof N)o=new st(n);else throw new Error("Unexpected content type")}new x(A(l,L(i.store,l)),s,s&&s.lastId,null,null,t,e,o).integrate(r,0)},Ve=(r,t)=>{r.doc??B();const e=r._map.get(t);return e!==void 0&&!e.deleted?e.content.getContent()[e.length-1]:void 0},Cn=r=>{const t={};return r.doc??B(),r._map.forEach((e,n)=>{e.deleted||(t[n]=e.content.getContent()[e.length-1])}),t},Un=(r,t)=>{r.doc??B();const e=r._map.get(t);return e!==void 0&&!e.deleted},xr=(r,t)=>{const e={};return r._map.forEach((n,s)=>{let i=n;for(;i!==null&&(!t.sv.has(i.id.client)||i.id.clock>=(t.sv.get(i.id.client)||0));)i=i.left;i!==null&&_t(i,t)&&(e[s]=i.content.getContent()[i.length-1])}),e},Gt=r=>(r.doc??B(),c.iteratorFilter(r._map.entries(),t=>!t[1].deleted));class An extends le{}class ft extends N{constructor(){super(),this._prelimContent=[],this._searchMarker=[]}static from(t){const e=new ft;return e.push(t),e}_integrate(t,e){super._integrate(t,e),this.insert(0,this._prelimContent),this._prelimContent=null}_copy(){return new ft}clone(){const t=new ft;return t.insert(0,this.toArray().map(e=>e instanceof N?e.clone():e)),t}get length(){return this.doc??B(),this._length}_callObserver(t,e){super._callObserver(t,e),ae(this,t,new An(this,t))}insert(t,e){this.doc!==null?V(this.doc,n=>{Dn(n,this,t,e)}):this._prelimContent.splice(t,0,...e)}push(t){this.doc!==null?V(this.doc,e=>{Vr(e,this,t)}):this._prelimContent.push(...t)}unshift(t){this.insert(0,t)}delete(t,e=1){this.doc!==null?V(this.doc,n=>{bn(n,this,t,e)}):this._prelimContent.splice(t,e)}get(t){return Sn(this,t)}toArray(){return yn(this)}slice(t=0,e=this.length){return mn(this,t,e)}toJSON(){return this.map(t=>t instanceof N?t.toJSON():t)}map(t){return kn(this,t)}forEach(t){vt(this,t)}[Symbol.iterator](){return Tr(this)}_write(t){t.writeTypeRef(ts)}}const $r=r=>new ft;class En extends le{constructor(t,e,n){super(t,e),this.keysChanged=n}}class pt extends N{constructor(t){super(),this._prelimContent=null,t===void 0?this._prelimContent=new Map:this._prelimContent=new Map(t)}_integrate(t,e){super._integrate(t,e),this._prelimContent.forEach((n,s)=>{this.set(s,n)}),this._prelimContent=null}_copy(){return new pt}clone(){const t=new pt;return this.forEach((e,n)=>{t.set(n,e instanceof N?e.clone():e)}),t}_callObserver(t,e){ae(this,t,new En(this,t,e))}toJSON(){this.doc??B();const t={};return this._map.forEach((e,n)=>{if(!e.deleted){const s=e.content.getContent()[e.length-1];t[n]=s instanceof N?s.toJSON():s}}),t}get size(){return[...Gt(this)].length}keys(){return c.iteratorMap(Gt(this),t=>t[0])}values(){return c.iteratorMap(Gt(this),t=>t[1].content.getContent()[t[1].length-1])}entries(){return c.iteratorMap(Gt(this),t=>[t[0],t[1].content.getContent()[t[1].length-1]])}forEach(t){this.doc??B(),this._map.forEach((e,n)=>{e.deleted||t(e.content.getContent()[e.length-1],n,this)})}[Symbol.iterator](){return this.entries()}delete(t){this.doc!==null?V(this.doc,e=>{ne(e,this,t)}):this._prelimContent.delete(t)}set(t,e){return this.doc!==null?V(this.doc,n=>{Te(n,this,t,e)}):this._prelimContent.set(t,e),e}get(t){return Ve(this,t)}has(t){return Un(this,t)}clear(){this.doc!==null?V(this.doc,t=>{this.forEach(function(e,n,s){ne(t,s,n)})}):this._prelimContent.clear()}_write(t){t.writeTypeRef(es)}}const vr=r=>new pt,ht=(r,t)=>r===t||typeof r=="object"&&typeof t=="object"&&r&&t&&c.equalFlat(r,t);class Se{constructor(t,e,n,s){this.left=t,this.right=e,this.index=n,this.currentAttributes=s}forward(){switch(this.right===null&&c.unexpectedCase(),this.right.content.constructor){case R:this.right.deleted||Vt(this.currentAttributes,this.right.content);break;default:this.right.deleted||(this.index+=this.right.length);break}this.left=this.right,this.right=this.right.right}}const je=(r,t,e)=>{for(;t.right!==null&&e>0;){switch(t.right.content.constructor){case R:t.right.deleted||Vt(t.currentAttributes,t.right.content);break;default:t.right.deleted||(e<t.right.length&&z(r,A(t.right.id.client,t.right.id.clock+e)),t.index+=t.right.length,e-=t.right.length);break}t.left=t.right,t.right=t.right.right}return t},zt=(r,t,e,n)=>{const s=new Map,i=n?oe(t,e):null;if(i){const l=new Se(i.p.left,i.p,i.index,s);return je(r,l,e-i.index)}else{const l=new Se(null,t._start,0,s);return je(r,l,e)}},In=(r,t,e,n)=>{for(;e.right!==null&&(e.right.deleted===!0||e.right.content.constructor===R&&ht(n.get(e.right.content.key),e.right.content.value));)e.right.deleted||n.delete(e.right.content.key),e.forward();const s=r.doc,i=s.clientID;n.forEach((l,o)=>{const a=e.left,d=e.right,h=new x(A(i,L(s.store,i)),a,a&&a.lastId,d,d&&d.id,t,null,new R(o,l));h.integrate(r,0),e.right=h,e.forward()})},Vt=(r,t)=>{const{key:e,value:n}=t;n===null?r.delete(e):r.set(e,n)},Mn=(r,t)=>{for(;r.right!==null;){if(!(r.right.deleted||r.right.content.constructor===R&&ht(t[r.right.content.key]??null,r.right.content.value)))break;r.forward()}},Tn=(r,t,e,n)=>{const s=r.doc,i=s.clientID,l=new Map;for(const o in n){const a=n[o],d=e.currentAttributes.get(o)??null;if(!ht(d,a)){l.set(o,d);const{left:h,right:u}=e;e.right=new x(A(i,L(s.store,i)),h,h&&h.lastId,u,u&&u.id,t,null,new R(o,a)),e.right.integrate(r,0),e.forward()}}return l},ge=(r,t,e,n,s)=>{e.currentAttributes.forEach((f,g)=>{s[g]===void 0&&(s[g]=null)});const i=r.doc,l=i.clientID;Mn(e,s);const o=Tn(r,t,e,s),a=n.constructor===String?new rt(n):n instanceof N?new st(n):new St(n);let{left:d,right:h,index:u}=e;t._searchMarker&&$t(t._searchMarker,e.index,a.getLength()),h=new x(A(l,L(i.store,l)),d,d&&d.lastId,h,h&&h.id,t,null,a),h.integrate(r,0),e.right=h,e.index=u,e.forward(),In(r,t,e,o)},Je=(r,t,e,n,s)=>{const i=r.doc,l=i.clientID;Mn(e,s);const o=Tn(r,t,e,s);t:for(;e.right!==null&&(n>0||o.size>0&&(e.right.deleted||e.right.content.constructor===R));){if(!e.right.deleted)switch(e.right.content.constructor){case R:{const{key:a,value:d}=e.right.content,h=s[a];if(h!==void 0){if(ht(h,d))o.delete(a);else{if(n===0)break t;o.set(a,d)}e.right.delete(r)}else e.currentAttributes.set(a,d);break}default:n<e.right.length&&z(r,A(e.right.id.client,e.right.id.clock+n)),n-=e.right.length;break}e.forward()}if(n>0){let a="";for(;n>0;n--)a+=`
2
+ `;e.right=new x(A(l,L(i.store,l)),e.left,e.left&&e.left.lastId,e.right,e.right&&e.right.id,t,null,new rt(a)),e.right.integrate(r,0),e.forward()}In(r,t,e,o)},Vn=(r,t,e,n,s)=>{let i=t;const l=c.create$3();for(;i&&(!i.countable||i.deleted);){if(!i.deleted&&i.content.constructor===R){const d=i.content;l.set(d.key,d)}i=i.right}let o=0,a=!1;for(;t!==i;){if(e===t&&(a=!0),!t.deleted){const d=t.content;switch(d.constructor){case R:{const{key:h,value:u}=d,f=n.get(h)??null;(l.get(h)!==d||f===u)&&(t.delete(r),o++,!a&&(s.get(h)??null)===u&&f!==u&&(f===null?s.delete(h):s.set(h,f))),!a&&!t.deleted&&Vt(s,d);break}}}t=t.right}return o},Or=(r,t)=>{for(;t&&t.right&&(t.right.deleted||!t.right.countable);)t=t.right;const e=new Set;for(;t&&(t.deleted||!t.countable);){if(!t.deleted&&t.content.constructor===R){const n=t.content.key;e.has(n)?t.delete(r):e.add(n)}t=t.left}},Lr=r=>{let t=0;return V(r.doc,e=>{let n=r._start,s=r._start,i=c.create$3();const l=c.copy(i);for(;s;){if(s.deleted===!1)switch(s.content.constructor){case R:Vt(l,s.content);break;default:t+=Vn(e,n,s,i,l),i=c.copy(l),n=s;break}s=s.right}}),t},Rr=r=>{const t=new Set,e=r.doc;for(const[n,s]of r.afterState.entries()){const i=r.beforeState.get(n)||0;s!==i&&un(r,e.store.clients.get(n),i,s,l=>{!l.deleted&&l.content.constructor===R&&l.constructor!==q&&t.add(l.parent)})}V(e,n=>{At(r,r.deleteSet,s=>{if(s instanceof q||!s.parent._hasFormatting||t.has(s.parent))return;const i=s.parent;s.content.constructor===R?t.add(i):Or(n,s)});for(const s of t)Lr(s)})},Ge=(r,t,e)=>{const n=e,s=c.copy(t.currentAttributes),i=t.right;for(;e>0&&t.right!==null;){if(t.right.deleted===!1)switch(t.right.content.constructor){case st:case St:case rt:e<t.right.length&&z(r,A(t.right.id.client,t.right.id.clock+e)),e-=t.right.length,t.right.delete(r);break}t.forward()}i&&Vn(r,i,t.right,s,t.currentAttributes);const l=(t.left||t.right).parent;return l._searchMarker&&$t(l._searchMarker,t.index,-n+e),t};class xn extends le{constructor(t,e,n){super(t,e),this.childListChanged=!1,this.keysChanged=new Set,n.forEach(s=>{s===null?this.childListChanged=!0:this.keysChanged.add(s)})}get changes(){if(this._changes===null){const t={keys:this.keys,delta:this.delta,added:new Set,deleted:new Set};this._changes=t}return this._changes}get delta(){if(this._delta===null){const t=this.target.doc,e=[];V(t,n=>{const s=new Map,i=new Map;let l=this.target._start,o=null;const a={};let d="",h=0,u=0;const f=()=>{if(o!==null){let g=null;switch(o){case"delete":u>0&&(g={delete:u}),u=0;break;case"insert":(typeof d=="object"||d.length>0)&&(g={insert:d},s.size>0&&(g.attributes={},s.forEach((p,b)=>{p!==null&&(g.attributes[b]=p)}))),d="";break;case"retain":h>0&&(g={retain:h},c.isEmpty(a)||(g.attributes=c.assign({},a))),h=0;break}g&&e.push(g),o=null}};for(;l!==null;){switch(l.content.constructor){case st:case St:this.adds(l)?this.deletes(l)||(f(),o="insert",d=l.content.getContent()[0],f()):this.deletes(l)?(o!=="delete"&&(f(),o="delete"),u+=1):l.deleted||(o!=="retain"&&(f(),o="retain"),h+=1);break;case rt:this.adds(l)?this.deletes(l)||(o!=="insert"&&(f(),o="insert"),d+=l.content.str):this.deletes(l)?(o!=="delete"&&(f(),o="delete"),u+=l.length):l.deleted||(o!=="retain"&&(f(),o="retain"),h+=l.length);break;case R:{const{key:g,value:p}=l.content;if(this.adds(l)){if(!this.deletes(l)){const b=s.get(g)??null;ht(b,p)?p!==null&&l.delete(n):(o==="retain"&&f(),ht(p,i.get(g)??null)?delete a[g]:a[g]=p)}}else if(this.deletes(l)){i.set(g,p);const b=s.get(g)??null;ht(b,p)||(o==="retain"&&f(),a[g]=b)}else if(!l.deleted){i.set(g,p);const b=a[g];b!==void 0&&(ht(b,p)?b!==null&&l.delete(n):(o==="retain"&&f(),p===null?delete a[g]:a[g]=p))}l.deleted||(o==="insert"&&f(),Vt(s,l.content));break}}l=l.right}for(f();e.length>0;){const g=e[e.length-1];if(g.retain!==void 0&&g.attributes===void 0)e.pop();else break}}),this._delta=e}return this._delta}}class It extends N{constructor(t){super(),this._pending=t!==void 0?[()=>this.insert(0,t)]:[],this._searchMarker=[],this._hasFormatting=!1}get length(){return this.doc??B(),this._length}_integrate(t,e){super._integrate(t,e);try{this._pending.forEach(n=>n())}catch(n){console.error(n)}this._pending=null}_copy(){return new It}clone(){const t=new It;return t.applyDelta(this.toDelta()),t}_callObserver(t,e){super._callObserver(t,e);const n=new xn(this,t,e);ae(this,t,n),!t.local&&this._hasFormatting&&(t._needFormattingCleanup=!0)}toString(){this.doc??B();let t="",e=this._start;for(;e!==null;)!e.deleted&&e.countable&&e.content.constructor===rt&&(t+=e.content.str),e=e.right;return t}toJSON(){return this.toString()}applyDelta(t,{sanitize:e=!0}={}){this.doc!==null?V(this.doc,n=>{const s=new Se(null,this._start,0,new Map);for(let i=0;i<t.length;i++){const l=t[i];if(l.insert!==void 0){const o=!e&&typeof l.insert=="string"&&i===t.length-1&&s.right===null&&l.insert.slice(-1)===`
3
+ `?l.insert.slice(0,-1):l.insert;(typeof o!="string"||o.length>0)&&ge(n,this,s,o,l.attributes||{})}else l.retain!==void 0?Je(n,this,s,l.retain,l.attributes||{}):l.delete!==void 0&&Ge(n,s,l.delete)}}):this._pending.push(()=>this.applyDelta(t))}toDelta(t,e,n){this.doc??B();const s=[],i=new Map,l=this.doc;let o="",a=this._start;function d(){if(o.length>0){const u={};let f=!1;i.forEach((p,b)=>{f=!0,u[b]=p});const g={insert:o};f&&(g.attributes=u),s.push(g),o=""}}const h=()=>{for(;a!==null;){if(_t(a,t)||e!==void 0&&_t(a,e))switch(a.content.constructor){case rt:{const u=i.get("ychange");t!==void 0&&!_t(a,t)?(u===void 0||u.user!==a.id.client||u.type!=="removed")&&(d(),i.set("ychange",n?n("removed",a.id):{type:"removed"})):e!==void 0&&!_t(a,e)?(u===void 0||u.user!==a.id.client||u.type!=="added")&&(d(),i.set("ychange",n?n("added",a.id):{type:"added"})):u!==void 0&&(d(),i.delete("ychange")),o+=a.content.str;break}case st:case St:{d();const u={insert:a.content.getContent()[0]};if(i.size>0){const f={};u.attributes=f,i.forEach((g,p)=>{f[p]=g})}s.push(u);break}case R:_t(a,t)&&(d(),Vt(i,a.content));break}a=a.right}d()};return t||e?V(l,u=>{t&&ye(u,t),e&&ye(u,e),h()},"cleanup"):h(),s}insert(t,e,n){if(e.length<=0)return;const s=this.doc;s!==null?V(s,i=>{const l=zt(i,this,t,!n);n||(n={},l.currentAttributes.forEach((o,a)=>{n[a]=o})),ge(i,this,l,e,n)}):this._pending.push(()=>this.insert(t,e,n))}insertEmbed(t,e,n){const s=this.doc;s!==null?V(s,i=>{const l=zt(i,this,t,!n);ge(i,this,l,e,n||{})}):this._pending.push(()=>this.insertEmbed(t,e,n||{}))}delete(t,e){if(e===0)return;const n=this.doc;n!==null?V(n,s=>{Ge(s,zt(s,this,t,!0),e)}):this._pending.push(()=>this.delete(t,e))}format(t,e,n){if(e===0)return;const s=this.doc;s!==null?V(s,i=>{const l=zt(i,this,t,!1);l.right!==null&&Je(i,this,l,e,n)}):this._pending.push(()=>this.format(t,e,n))}removeAttribute(t){this.doc!==null?V(this.doc,e=>{ne(e,this,t)}):this._pending.push(()=>this.removeAttribute(t))}setAttribute(t,e){this.doc!==null?V(this.doc,n=>{Te(n,this,t,e)}):this._pending.push(()=>this.setAttribute(t,e))}getAttribute(t){return Ve(this,t)}getAttributes(){return Cn(this)}_write(t){t.writeTypeRef(ns)}}const Yr=r=>new It;class pe{constructor(t,e=()=>!0){this._filter=e,this._root=t,this._currentNode=t._start,this._firstCall=!0,t.doc??B()}[Symbol.iterator](){return this}next(){let t=this._currentNode,e=t&&t.content&&t.content.type;if(t!==null&&(!this._firstCall||t.deleted||!this._filter(e)))do if(e=t.content.type,!t.deleted&&(e.constructor===mt||e.constructor===wt)&&e._start!==null)t=e._start;else for(;t!==null;){const n=t.next;if(n!==null){t=n;break}else t.parent===this._root?t=null:t=t.parent._item}while(t!==null&&(t.deleted||!this._filter(t.content.type)));return this._firstCall=!1,t===null?{value:void 0,done:!0}:(this._currentNode=t,{value:t.content.type,done:!1})}}class wt extends N{constructor(){super(),this._prelimContent=[]}get firstChild(){const t=this._first;return t?t.content.getContent()[0]:null}_integrate(t,e){super._integrate(t,e),this.insert(0,this._prelimContent),this._prelimContent=null}_copy(){return new wt}clone(){const t=new wt;return t.insert(0,this.toArray().map(e=>e instanceof N?e.clone():e)),t}get length(){return this.doc??B(),this._prelimContent===null?this._length:this._prelimContent.length}createTreeWalker(t){return new pe(this,t)}querySelector(t){t=t.toUpperCase();const n=new pe(this,s=>s.nodeName&&s.nodeName.toUpperCase()===t).next();return n.done?null:n.value}querySelectorAll(t){return t=t.toUpperCase(),c.from(new pe(this,e=>e.nodeName&&e.nodeName.toUpperCase()===t))}_callObserver(t,e){ae(this,t,new $n(this,e,t))}toString(){return kn(this,t=>t.toString()).join("")}toJSON(){return this.toString()}toDOM(t=document,e={},n){const s=t.createDocumentFragment();return n!==void 0&&n._createAssociation(s,this),vt(this,i=>{s.insertBefore(i.toDOM(t,e,n),null)}),s}insert(t,e){this.doc!==null?V(this.doc,n=>{Dn(n,this,t,e)}):this._prelimContent.splice(t,0,...e)}insertAfter(t,e){if(this.doc!==null)V(this.doc,n=>{const s=t&&t instanceof N?t._item:t;ee(n,this,s,e)});else{const n=this._prelimContent,s=t===null?0:n.findIndex(i=>i===t)+1;if(s===0&&t!==null)throw c.create$1("Reference item not found");n.splice(s,0,...e)}}delete(t,e=1){this.doc!==null?V(this.doc,n=>{bn(n,this,t,e)}):this._prelimContent.splice(t,e)}toArray(){return yn(this)}push(t){this.insert(this.length,t)}unshift(t){this.insert(0,t)}get(t){return Sn(this,t)}slice(t=0,e=this.length){return mn(this,t,e)}forEach(t){vt(this,t)}_write(t){t.writeTypeRef(ss)}}const Nr=r=>new wt;class mt extends wt{constructor(t="UNDEFINED"){super(),this.nodeName=t,this._prelimAttrs=new Map}get nextSibling(){const t=this._item?this._item.next:null;return t?t.content.type:null}get prevSibling(){const t=this._item?this._item.prev:null;return t?t.content.type:null}_integrate(t,e){super._integrate(t,e),this._prelimAttrs.forEach((n,s)=>{this.setAttribute(s,n)}),this._prelimAttrs=null}_copy(){return new mt(this.nodeName)}clone(){const t=new mt(this.nodeName),e=this.getAttributes();return c.forEach(e,(n,s)=>{typeof n=="string"&&t.setAttribute(s,n)}),t.insert(0,this.toArray().map(n=>n instanceof N?n.clone():n)),t}toString(){const t=this.getAttributes(),e=[],n=[];for(const o in t)n.push(o);n.sort();const s=n.length;for(let o=0;o<s;o++){const a=n[o];e.push(a+'="'+t[a]+'"')}const i=this.nodeName.toLocaleLowerCase(),l=e.length>0?" "+e.join(" "):"";return`<${i}${l}>${super.toString()}</${i}>`}removeAttribute(t){this.doc!==null?V(this.doc,e=>{ne(e,this,t)}):this._prelimAttrs.delete(t)}setAttribute(t,e){this.doc!==null?V(this.doc,n=>{Te(n,this,t,e)}):this._prelimAttrs.set(t,e)}getAttribute(t){return Ve(this,t)}hasAttribute(t){return Un(this,t)}getAttributes(t){return t?xr(this,t):Cn(this)}toDOM(t=document,e={},n){const s=t.createElement(this.nodeName),i=this.getAttributes();for(const l in i){const o=i[l];typeof o=="string"&&s.setAttribute(l,o)}return vt(this,l=>{s.appendChild(l.toDOM(t,e,n))}),n!==void 0&&n._createAssociation(s,this),s}_write(t){t.writeTypeRef(rs),t.writeKey(this.nodeName)}}const Fr=r=>new mt(r.readKey());class $n extends le{constructor(t,e,n){super(t,n),this.childListChanged=!1,this.attributesChanged=new Set,e.forEach(s=>{s===null?this.childListChanged=!0:this.attributesChanged.add(s)})}}class re extends pt{constructor(t){super(),this.hookName=t}_copy(){return new re(this.hookName)}clone(){const t=new re(this.hookName);return this.forEach((e,n)=>{t.set(n,e)}),t}toDOM(t=document,e={},n){const s=e[this.hookName];let i;return s!==void 0?i=s.createDom(this):i=document.createElement(this.hookName),i.setAttribute("data-yjs-hook",this.hookName),n!==void 0&&n._createAssociation(i,this),i}_write(t){t.writeTypeRef(is),t.writeKey(this.hookName)}}const Br=r=>new re(r.readKey());class Ot extends It{get nextSibling(){const t=this._item?this._item.next:null;return t?t.content.type:null}get prevSibling(){const t=this._item?this._item.prev:null;return t?t.content.type:null}_copy(){return new Ot}clone(){const t=new Ot;return t.applyDelta(this.toDelta()),t}toDOM(t=document,e,n){const s=t.createTextNode(this.toString());return n!==void 0&&n._createAssociation(s,this),s}toString(){return this.toDelta().map(t=>{const e=[];for(const s in t.attributes){const i=[];for(const l in t.attributes[s])i.push({key:l,value:t.attributes[s][l]});i.sort((l,o)=>l.key<o.key?-1:1),e.push({nodeName:s,attrs:i})}e.sort((s,i)=>s.nodeName<i.nodeName?-1:1);let n="";for(let s=0;s<e.length;s++){const i=e[s];n+=`<${i.nodeName}`;for(let l=0;l<i.attrs.length;l++){const o=i.attrs[l];n+=` ${o.key}="${o.value}"`}n+=">"}n+=t.insert;for(let s=e.length-1;s>=0;s--)n+=`</${e[s].nodeName}>`;return n}).join("")}toJSON(){return this.toString()}_write(t){t.writeTypeRef(cs)}}const Hr=r=>new Ot;class xe{constructor(t,e){this.id=t,this.length=e}get deleted(){throw c.methodUnimplemented()}mergeWith(t){return!1}write(t,e,n){throw c.methodUnimplemented()}integrate(t,e){throw c.methodUnimplemented()}}const Wr=0;class q extends xe{get deleted(){return!0}delete(){}mergeWith(t){return this.constructor!==t.constructor?!1:(this.length+=t.length,!0)}integrate(t,e){e>0&&(this.id.clock+=e,this.length-=e),dn(t.doc.store,this)}write(t,e){t.writeInfo(Wr),t.writeLen(this.length-e)}getMissing(t,e){return null}}class Nt{constructor(t){this.content=t}getLength(){return 1}getContent(){return[this.content]}isCountable(){return!0}copy(){return new Nt(this.content)}splice(t){throw c.methodUnimplemented()}mergeWith(t){return!1}integrate(t,e){}delete(t){}gc(t){}write(t,e){t.writeBuf(this.content)}getRef(){return 3}}const jr=r=>new Nt(r.readBuf());class Lt{constructor(t){this.len=t}getLength(){return this.len}getContent(){return[]}isCountable(){return!1}copy(){return new Lt(this.len)}splice(t){const e=new Lt(this.len-t);return this.len=t,e}mergeWith(t){return this.len+=t.len,!0}integrate(t,e){xt(t.deleteSet,e.id.client,e.id.clock,this.len),e.markDeleted()}delete(t){}gc(t){}write(t,e){t.writeLen(this.len-e)}getRef(){return 1}}const Jr=r=>new Lt(r.readLen()),vn=(r,t)=>new kt({guid:r,...t,shouldLoad:t.shouldLoad||t.autoLoad||!1});class Ft{constructor(t){t._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=t;const e={};this.opts=e,t.gc||(e.gc=!1),t.autoLoad&&(e.autoLoad=!0),t.meta!==null&&(e.meta=t.meta)}getLength(){return 1}getContent(){return[this.doc]}isCountable(){return!0}copy(){return new Ft(vn(this.doc.guid,this.opts))}splice(t){throw c.methodUnimplemented()}mergeWith(t){return!1}integrate(t,e){this.doc._item=e,t.subdocsAdded.add(this.doc),this.doc.shouldLoad&&t.subdocsLoaded.add(this.doc)}delete(t){t.subdocsAdded.has(this.doc)?t.subdocsAdded.delete(this.doc):t.subdocsRemoved.add(this.doc)}gc(t){}write(t,e){t.writeString(this.doc.guid),t.writeAny(this.opts)}getRef(){return 9}}const Gr=r=>new Ft(vn(r.readString(),r.readAny()));class St{constructor(t){this.embed=t}getLength(){return 1}getContent(){return[this.embed]}isCountable(){return!0}copy(){return new St(this.embed)}splice(t){throw c.methodUnimplemented()}mergeWith(t){return!1}integrate(t,e){}delete(t){}gc(t){}write(t,e){t.writeJSON(this.embed)}getRef(){return 5}}const zr=r=>new St(r.readJSON());class R{constructor(t,e){this.key=t,this.value=e}getLength(){return 1}getContent(){return[]}isCountable(){return!1}copy(){return new R(this.key,this.value)}splice(t){throw c.methodUnimplemented()}mergeWith(t){return!1}integrate(t,e){const n=e.parent;n._searchMarker=null,n._hasFormatting=!0}delete(t){}gc(t){}write(t,e){t.writeKey(this.key),t.writeJSON(this.value)}getRef(){return 6}}const Xr=r=>new R(r.readKey(),r.readJSON());class se{constructor(t){this.arr=t}getLength(){return this.arr.length}getContent(){return this.arr}isCountable(){return!0}copy(){return new se(this.arr)}splice(t){const e=new se(this.arr.slice(t));return this.arr=this.arr.slice(0,t),e}mergeWith(t){return this.arr=this.arr.concat(t.arr),!0}integrate(t,e){}delete(t){}gc(t){}write(t,e){const n=this.arr.length;t.writeLen(n-e);for(let s=e;s<n;s++){const i=this.arr[s];t.writeString(i===void 0?"undefined":JSON.stringify(i))}}getRef(){return 2}}const Zr=r=>{const t=r.readLen(),e=[];for(let n=0;n<t;n++){const s=r.readString();s==="undefined"?e.push(void 0):e.push(JSON.parse(s))}return new se(e)},Kr=c.getVariable("node_env")==="development";class yt{constructor(t){this.arr=t,Kr&&c.deepFreeze(t)}getLength(){return this.arr.length}getContent(){return this.arr}isCountable(){return!0}copy(){return new yt(this.arr)}splice(t){const e=new yt(this.arr.slice(t));return this.arr=this.arr.slice(0,t),e}mergeWith(t){return this.arr=this.arr.concat(t.arr),!0}integrate(t,e){}delete(t){}gc(t){}write(t,e){const n=this.arr.length;t.writeLen(n-e);for(let s=e;s<n;s++){const i=this.arr[s];t.writeAny(i)}}getRef(){return 8}}const qr=r=>{const t=r.readLen(),e=[];for(let n=0;n<t;n++)e.push(r.readAny());return new yt(e)};class rt{constructor(t){this.str=t}getLength(){return this.str.length}getContent(){return this.str.split("")}isCountable(){return!0}copy(){return new rt(this.str)}splice(t){const e=new rt(this.str.slice(t));this.str=this.str.slice(0,t);const n=this.str.charCodeAt(t-1);return n>=55296&&n<=56319&&(this.str=this.str.slice(0,t-1)+"�",e.str="�"+e.str.slice(1)),e}mergeWith(t){return this.str+=t.str,!0}integrate(t,e){}delete(t){}gc(t){}write(t,e){t.writeString(e===0?this.str:this.str.slice(e))}getRef(){return 4}}const Qr=r=>new rt(r.readString()),Pr=[$r,vr,Yr,Fr,Nr,Br,Hr],ts=0,es=1,ns=2,rs=3,ss=4,is=5,cs=6;class st{constructor(t){this.type=t}getLength(){return 1}getContent(){return[this.type]}isCountable(){return!0}copy(){return new st(this.type._copy())}splice(t){throw c.methodUnimplemented()}mergeWith(t){return!1}integrate(t,e){this.type._integrate(t.doc,e)}delete(t){let e=this.type._start;for(;e!==null;)e.deleted?e.id.clock<(t.beforeState.get(e.id.client)||0)&&t._mergeStructs.push(e):e.delete(t),e=e.right;this.type._map.forEach(n=>{n.deleted?n.id.clock<(t.beforeState.get(n.id.client)||0)&&t._mergeStructs.push(n):n.delete(t)}),t.changed.delete(this.type)}gc(t){let e=this.type._start;for(;e!==null;)e.gc(t,!0),e=e.right;this.type._start=null,this.type._map.forEach(n=>{for(;n!==null;)n.gc(t,!0),n=n.left}),this.type._map=new Map}write(t,e){this.type._write(t)}getRef(){return 7}}const ls=r=>new st(Pr[r.readTypeRef()](r)),_e=(r,t)=>{let e=t,n=0,s;do n>0&&(e=A(e.client,e.clock+n)),s=Ct(r,e),n=e.clock-s.id.clock,e=s.redone;while(e!==null&&s instanceof x);return{item:s,diff:n}},$e=(r,t)=>{for(;r!==null&&r.keep!==t;)r.keep=t,r=r.parent._item},ie=(r,t,e)=>{const{client:n,clock:s}=t.id,i=new x(A(n,s+e),t,A(n,s+e-1),t.right,t.rightOrigin,t.parent,t.parentSub,t.content.splice(e));return t.deleted&&i.markDeleted(),t.keep&&(i.keep=!0),t.redone!==null&&(i.redone=A(t.redone.client,t.redone.clock+e)),t.right=i,i.right!==null&&(i.right.left=i),r._mergeStructs.push(i),i.parentSub!==null&&i.right===null&&i.parent._map.set(i.parentSub,i),t.length=e,i},ze=(r,t)=>c.some(r,e=>Rt(e.deletions,t)),On=(r,t,e,n,s,i)=>{const l=r.doc,o=l.store,a=l.clientID,d=t.redone;if(d!==null)return z(r,d);let h=t.parent._item,u=null,f;if(h!==null&&h.deleted===!0){if(h.redone===null&&(!e.has(h)||On(r,h,e,n,s,i)===null))return null;for(;h.redone!==null;)h=z(r,h.redone)}const g=h===null?t.parent:h.content.type;if(t.parentSub===null){for(u=t.left,f=t;u!==null;){let S=u;for(;S!==null&&S.parent._item!==h;)S=S.redone===null?null:z(r,S.redone);if(S!==null&&S.parent._item===h){u=S;break}u=u.left}for(;f!==null;){let S=f;for(;S!==null&&S.parent._item!==h;)S=S.redone===null?null:z(r,S.redone);if(S!==null&&S.parent._item===h){f=S;break}f=f.right}}else if(f=null,t.right&&!s){for(u=t;u!==null&&u.right!==null&&(u.right.redone||Rt(n,u.right.id)||ze(i.undoStack,u.right.id)||ze(i.redoStack,u.right.id));)for(u=u.right;u.redone;)u=z(r,u.redone);if(u&&u.right!==null)return null}else u=g._map.get(t.parentSub)||null;const p=L(o,a),b=A(a,p),k=new x(b,u,u&&u.lastId,f,f&&f.id,g,t.parentSub,t.content.copy());return t.redone=b,$e(k,!0),k.integrate(r,0),k};class x extends xe{constructor(t,e,n,s,i,l,o,a){super(t,a.getLength()),this.origin=n,this.left=e,this.right=s,this.rightOrigin=i,this.parent=l,this.parentSub=o,this.redone=null,this.content=a,this.info=this.content.isCountable()?c.BIT2:0}set marker(t){(this.info&c.BIT4)>0!==t&&(this.info^=c.BIT4)}get marker(){return(this.info&c.BIT4)>0}get keep(){return(this.info&c.BIT1)>0}set keep(t){this.keep!==t&&(this.info^=c.BIT1)}get countable(){return(this.info&c.BIT2)>0}get deleted(){return(this.info&c.BIT3)>0}set deleted(t){this.deleted!==t&&(this.info^=c.BIT3)}markDeleted(){this.info|=c.BIT3}getMissing(t,e){if(this.origin&&this.origin.client!==this.id.client&&this.origin.clock>=L(e,this.origin.client))return this.origin.client;if(this.rightOrigin&&this.rightOrigin.client!==this.id.client&&this.rightOrigin.clock>=L(e,this.rightOrigin.client))return this.rightOrigin.client;if(this.parent&&this.parent.constructor===bt&&this.id.client!==this.parent.client&&this.parent.clock>=L(e,this.parent.client))return this.parent.client;if(this.origin&&(this.left=Ye(t,e,this.origin),this.origin=this.left.lastId),this.rightOrigin&&(this.right=z(t,this.rightOrigin),this.rightOrigin=this.right.id),this.left&&this.left.constructor===q||this.right&&this.right.constructor===q)this.parent=null;else if(!this.parent)this.left&&this.left.constructor===x?(this.parent=this.left.parent,this.parentSub=this.left.parentSub):this.right&&this.right.constructor===x&&(this.parent=this.right.parent,this.parentSub=this.right.parentSub);else if(this.parent.constructor===bt){const n=Ct(e,this.parent);n.constructor===q?this.parent=null:this.parent=n.content.type}return null}integrate(t,e){if(e>0&&(this.id.clock+=e,this.left=Ye(t,t.doc.store,A(this.id.client,this.id.clock-1)),this.origin=this.left.lastId,this.content=this.content.splice(e),this.length-=e),this.parent){if(!this.left&&(!this.right||this.right.left!==null)||this.left&&this.left.right!==this.right){let n=this.left,s;if(n!==null)s=n.right;else if(this.parentSub!==null)for(s=this.parent._map.get(this.parentSub)||null;s!==null&&s.left!==null;)s=s.left;else s=this.parent._start;const i=new Set,l=new Set;for(;s!==null&&s!==this.right;){if(l.add(s),i.add(s),Dt(this.origin,s.origin)){if(s.id.client<this.id.client)n=s,i.clear();else if(Dt(this.rightOrigin,s.rightOrigin))break}else if(s.origin!==null&&l.has(Ct(t.doc.store,s.origin)))i.has(Ct(t.doc.store,s.origin))||(n=s,i.clear());else break;s=s.right}this.left=n}if(this.left!==null){const n=this.left.right;this.right=n,this.left.right=this}else{let n;if(this.parentSub!==null)for(n=this.parent._map.get(this.parentSub)||null;n!==null&&n.left!==null;)n=n.left;else n=this.parent._start,this.parent._start=this;this.right=n}this.right!==null?this.right.left=this:this.parentSub!==null&&(this.parent._map.set(this.parentSub,this),this.left!==null&&this.left.delete(t)),this.parentSub===null&&this.countable&&!this.deleted&&(this.parent._length+=this.length),dn(t.doc.store,this),this.content.integrate(t,this),Fe(t,this.parent,this.parentSub),(this.parent._item!==null&&this.parent._item.deleted||this.parentSub!==null&&this.right!==null)&&this.delete(t)}else new q(this.id,this.length).integrate(t,0)}get next(){let t=this.right;for(;t!==null&&t.deleted;)t=t.right;return t}get prev(){let t=this.left;for(;t!==null&&t.deleted;)t=t.left;return t}get lastId(){return this.length===1?this.id:A(this.id.client,this.id.clock+this.length-1)}mergeWith(t){if(this.constructor===t.constructor&&Dt(t.origin,this.lastId)&&this.right===t&&Dt(this.rightOrigin,t.rightOrigin)&&this.id.client===t.id.client&&this.id.clock+this.length===t.id.clock&&this.deleted===t.deleted&&this.redone===null&&t.redone===null&&this.content.constructor===t.content.constructor&&this.content.mergeWith(t.content)){const e=this.parent._searchMarker;return e&&e.forEach(n=>{n.p===t&&(n.p=this,!this.deleted&&this.countable&&(n.index-=this.length))}),t.keep&&(this.keep=!0),this.right=t.right,this.right!==null&&(this.right.left=this),this.length+=t.length,!0}return!1}delete(t){if(!this.deleted){const e=this.parent;this.countable&&this.parentSub===null&&(e._length-=this.length),this.markDeleted(),xt(t.deleteSet,this.id.client,this.id.clock,this.length),Fe(t,e,this.parentSub),this.content.delete(t)}}gc(t,e){if(!this.deleted)throw c.unexpectedCase();this.content.gc(t),e?gr(t,this,new q(this.id,this.length)):this.content=new Lt(this.length)}write(t,e){const n=e>0?A(this.id.client,this.id.clock+e-1):this.origin,s=this.rightOrigin,i=this.parentSub,l=this.content.getRef()&c.BITS5|(n===null?0:c.BIT8)|(s===null?0:c.BIT7)|(i===null?0:c.BIT6);if(t.writeInfo(l),n!==null&&t.writeLeftID(n),s!==null&&t.writeRightID(s),n===null&&s===null){const o=this.parent;if(o._item!==void 0){const a=o._item;if(a===null){const d=an(o);t.writeParentInfo(!0),t.writeString(d)}else t.writeParentInfo(!1),t.writeLeftID(a.id)}else o.constructor===String?(t.writeParentInfo(!0),t.writeString(o)):o.constructor===bt?(t.writeParentInfo(!1),t.writeLeftID(o)):c.unexpectedCase();i!==null&&t.writeString(i)}this.content.write(t,e)}}const Ln=(r,t)=>os[t&c.BITS5](r),os=[()=>{c.unexpectedCase()},Jr,Zr,jr,Qr,zr,Xr,ls,qr,Gr,()=>{c.unexpectedCase()}],as=10;class Q extends xe{get deleted(){return!0}delete(){}mergeWith(t){return this.constructor!==t.constructor?!1:(this.length+=t.length,!0)}integrate(t,e){c.unexpectedCase()}write(t,e){t.writeInfo(as),c.writeVarUint(t.restEncoder,this.length-e)}getMissing(t,e){return null}}const Rn=typeof globalThis<"u"?globalThis:typeof window<"u"?window:typeof global<"u"?global:{},Yn="__ $YJS$ __";Rn[Yn]===!0&&console.error("Yjs was already imported. This breaks constructor checks and will lead to issues! - https://github.com/yjs/yjs/issues/438");Rn[Yn]=!0;const ut=0,Nn=3,Ut=1,hs=2,Bt=[];Bt[ut]=(r,t,e,n,s)=>{c.writeVarUint(r,ut);const i=c.readSyncMessage(t,r,e.doc,e);n&&i===c.messageYjsSyncStep2&&!e.synced&&(e.synced=!0)};Bt[Nn]=(r,t,e,n,s)=>{c.writeVarUint(r,Ut),c.writeVarUint8Array(r,c.encodeAwarenessUpdate(e.awareness,Array.from(e.awareness.getStates().keys())))};Bt[Ut]=(r,t,e,n,s)=>{c.applyAwarenessUpdate(e.awareness,c.readVarUint8Array(t),e)};Bt[hs]=(r,t,e,n,s)=>{c.readAuthMessage(t,e.doc,(i,l)=>ds(e,l))};const Xe=3e4,ds=(r,t)=>console.warn(`Permission denied to access ${r.url}.
4
+ ${t}`),Fn=(r,t,e)=>{const n=c.createDecoder(t),s=c.createEncoder(),i=c.readVarUint(n),l=r.messageHandlers[i];return l?l(s,n,r,e,i):console.error("Unable to compute message"),s},Bn=r=>{if(r.shouldConnect&&r.ws===null){const t=new r._WS(r.url);t.binaryType="arraybuffer",r.ws=t,r.wsconnecting=!0,r.wsconnected=!1,r.synced=!1,t.onmessage=e=>{r.wsLastMessageReceived=c.getUnixTime();const n=Fn(r,new Uint8Array(e.data),!0);c.length(n)>1&&t.send(c.toUint8Array(n))},t.onerror=e=>{r.emit("connection-error",[e,r])},t.onclose=e=>{r.emit("connection-close",[e,r]),r.ws=null,r.wsconnecting=!1,r.wsconnected?(r.wsconnected=!1,r.synced=!1,c.removeAwarenessStates(r.awareness,Array.from(r.awareness.getStates().keys()).filter(n=>n!==r.doc.clientID),r),r.emit("status",[{status:"disconnected"}])):r.wsUnsuccessfulReconnects++,setTimeout(Bn,c.min(c.pow(2,r.wsUnsuccessfulReconnects)*100,r.maxBackoffTime),r)},t.onopen=()=>{r.wsLastMessageReceived=c.getUnixTime(),r.wsconnecting=!1,r.wsconnected=!0,r.wsUnsuccessfulReconnects=0,r.emit("status",[{status:"connected"}]);const e=c.createEncoder();if(c.writeVarUint(e,ut),c.writeSyncStep1(e,r.doc),t.send(c.toUint8Array(e)),r.awareness.getLocalState()!==null){const n=c.createEncoder();c.writeVarUint(n,Ut),c.writeVarUint8Array(n,c.encodeAwarenessUpdate(r.awareness,[r.doc.clientID])),t.send(c.toUint8Array(n))}},r.emit("status",[{status:"connecting"}])}},we=(r,t)=>{const e=r.ws;r.wsconnected&&e&&e.readyState===e.OPEN&&e.send(t),r.bcconnected&&c.publish(r.bcChannel,t,r)};class us extends c.Observable{constructor(t,e,n,{connect:s=!0,awareness:i=new c.Awareness(n),params:l={},WebSocketPolyfill:o=WebSocket,resyncInterval:a=-1,maxBackoffTime:d=2500,disableBc:h=!1}={}){for(super();t[t.length-1]==="/";)t=t.slice(0,t.length-1);const u=c.encodeQueryParams(l);this.maxBackoffTime=d,this.bcChannel=t+"/"+e,this.url=t+"/"+e+(u.length===0?"":"?"+u),this.roomname=e,this.doc=n,this._WS=o,this.awareness=i,this.wsconnected=!1,this.wsconnecting=!1,this.bcconnected=!1,this.disableBc=h,this.wsUnsuccessfulReconnects=0,this.messageHandlers=Bt.slice(),this._synced=!1,this.ws=null,this.wsLastMessageReceived=0,this.shouldConnect=s,this._resyncInterval=0,a>0&&(this._resyncInterval=setInterval(()=>{if(this.ws&&this.ws.readyState===WebSocket.OPEN){const f=c.createEncoder();c.writeVarUint(f,ut),c.writeSyncStep1(f,n),this.ws.send(c.toUint8Array(f))}},a)),this._bcSubscriber=(f,g)=>{if(g!==this){const p=Fn(this,new Uint8Array(f),!1);c.length(p)>1&&c.publish(this.bcChannel,c.toUint8Array(p),this)}},this._updateHandler=(f,g)=>{if(g!==this){const p=c.createEncoder();c.writeVarUint(p,ut),c.writeUpdate(p,f),we(this,c.toUint8Array(p))}},this.doc.on("update",this._updateHandler),this._awarenessUpdateHandler=({added:f,updated:g,removed:p},b)=>{const k=f.concat(g).concat(p),S=c.createEncoder();c.writeVarUint(S,Ut),c.writeVarUint8Array(S,c.encodeAwarenessUpdate(i,k)),we(this,c.toUint8Array(S))},this._exitHandler=()=>{c.removeAwarenessStates(this.awareness,[n.clientID],"app closed")},c.isNode&&typeof process<"u"&&process.on("exit",this._exitHandler),i.on("update",this._awarenessUpdateHandler),this._checkInterval=setInterval(()=>{this.wsconnected&&Xe<c.getUnixTime()-this.wsLastMessageReceived&&this.ws.close()},Xe/10),s&&this.connect()}get synced(){return this._synced}set synced(t){this._synced!==t&&(this._synced=t,this.emit("synced",[t]),this.emit("sync",[t]))}destroy(){this._resyncInterval!==0&&clearInterval(this._resyncInterval),clearInterval(this._checkInterval),this.disconnect(),c.isNode&&typeof process<"u"&&process.off("exit",this._exitHandler),this.awareness.off("update",this._awarenessUpdateHandler),this.doc.off("update",this._updateHandler),super.destroy()}connectBc(){if(this.disableBc)return;this.bcconnected||(c.subscribe(this.bcChannel,this._bcSubscriber),this.bcconnected=!0);const t=c.createEncoder();c.writeVarUint(t,ut),c.writeSyncStep1(t,this.doc),c.publish(this.bcChannel,c.toUint8Array(t),this);const e=c.createEncoder();c.writeVarUint(e,ut),c.writeSyncStep2(e,this.doc),c.publish(this.bcChannel,c.toUint8Array(e),this);const n=c.createEncoder();c.writeVarUint(n,Nn),c.publish(this.bcChannel,c.toUint8Array(n),this);const s=c.createEncoder();c.writeVarUint(s,Ut),c.writeVarUint8Array(s,c.encodeAwarenessUpdate(this.awareness,[this.doc.clientID])),c.publish(this.bcChannel,c.toUint8Array(s),this)}disconnectBc(){const t=c.createEncoder();c.writeVarUint(t,Ut),c.writeVarUint8Array(t,c.encodeAwarenessUpdate(this.awareness,[this.doc.clientID],new Map)),we(this,c.toUint8Array(t)),this.bcconnected&&(c.unsubscribe(this.bcChannel,this._bcSubscriber),this.bcconnected=!1)}disconnect(){this.shouldConnect=!1,this.disconnectBc(),this.ws!==null&&this.ws.close()}connect(){this.shouldConnect=!0,!this.wsconnected&&this.ws===null&&(Bn(this),this.connectBc())}}var fs=typeof globalThis<"u"?globalThis:typeof window<"u"?window:typeof global<"u"?global:typeof self<"u"?self:{};function Ht(r){return r&&r.__esModule&&Object.prototype.hasOwnProperty.call(r,"default")?r.default:r}var Zt={exports:{}},gs=Zt.exports,Ze;function ps(){return Ze||(Ze=1,(function(r,t){(function(e,n){r.exports=n()})(gs,(function(){var e=1e3,n=6e4,s=36e5,i="millisecond",l="second",o="minute",a="hour",d="day",h="week",u="month",f="quarter",g="year",p="date",b="Invalid Date",k=/^(\d{4})[-/]?(\d{1,2})?[-/]?(\d{0,2})[Tt\s]*(\d{1,2})?:?(\d{1,2})?:?(\d{1,2})?[.:]?(\d+)?$/,S=/\[([^\]]+)]|Y{1,4}|M{1,4}|D{1,2}|d{1,4}|H{1,2}|h{1,2}|a|A|m{1,2}|s{1,2}|Z{1,2}|SSS/g,T={name:"en",weekdays:"Sunday_Monday_Tuesday_Wednesday_Thursday_Friday_Saturday".split("_"),months:"January_February_March_April_May_June_July_August_September_October_November_December".split("_"),ordinal:function(D){var m=["th","st","nd","rd"],w=D%100;return"["+D+(m[(w-20)%10]||m[w]||m[0])+"]"}},M=function(D,m,w){var _=String(D);return!_||_.length>=m?D:""+Array(m+1-_.length).join(w)+D},P={s:M,z:function(D){var m=-D.utcOffset(),w=Math.abs(m),_=Math.floor(w/60),y=w%60;return(m<=0?"+":"-")+M(_,2,"0")+":"+M(y,2,"0")},m:function D(m,w){if(m.date()<w.date())return-D(w,m);var _=12*(w.year()-m.year())+(w.month()-m.month()),y=m.clone().add(_,u),C=w-y<0,U=m.clone().add(_+(C?-1:1),u);return+(-(_+(w-y)/(C?y-U:U-y))||0)},a:function(D){return D<0?Math.ceil(D)||0:Math.floor(D)},p:function(D){return{M:u,y:g,w:h,d,D:p,h:a,m:o,s:l,ms:i,Q:f}[D]||String(D||"").toLowerCase().replace(/s$/,"")},u:function(D){return D===void 0}},H="en",X={};X[H]=T;var tt="$isDayjsObject",Z=function(D){return D instanceof W||!(!D||!D[tt])},j=function D(m,w,_){var y;if(!m)return H;if(typeof m=="string"){var C=m.toLowerCase();X[C]&&(y=C),w&&(X[C]=w,y=C);var U=m.split("-");if(!y&&U.length>1)return D(U[0])}else{var E=m.name;X[E]=m,y=E}return!_&&y&&(H=y),y||!_&&H},$=function(D,m){if(Z(D))return D.clone();var w=typeof m=="object"?m:{};return w.date=D,w.args=arguments,new W(w)},I=P;I.l=j,I.i=Z,I.w=function(D,m){return $(D,{locale:m.$L,utc:m.$u,x:m.$x,$offset:m.$offset})};var W=(function(){function D(w){this.$L=j(w.locale,null,!0),this.parse(w),this.$x=this.$x||w.x||{},this[tt]=!0}var m=D.prototype;return m.parse=function(w){this.$d=(function(_){var y=_.date,C=_.utc;if(y===null)return new Date(NaN);if(I.u(y))return new Date;if(y instanceof Date)return new Date(y);if(typeof y=="string"&&!/Z$/i.test(y)){var U=y.match(k);if(U){var E=U[2]-1||0,v=(U[7]||"0").substring(0,3);return C?new Date(Date.UTC(U[1],E,U[3]||1,U[4]||0,U[5]||0,U[6]||0,v)):new Date(U[1],E,U[3]||1,U[4]||0,U[5]||0,U[6]||0,v)}}return new Date(y)})(w),this.init()},m.init=function(){var w=this.$d;this.$y=w.getFullYear(),this.$M=w.getMonth(),this.$D=w.getDate(),this.$W=w.getDay(),this.$H=w.getHours(),this.$m=w.getMinutes(),this.$s=w.getSeconds(),this.$ms=w.getMilliseconds()},m.$utils=function(){return I},m.isValid=function(){return this.$d.toString()!==b},m.isSame=function(w,_){var y=$(w);return this.startOf(_)<=y&&y<=this.endOf(_)},m.isAfter=function(w,_){return $(w)<this.startOf(_)},m.isBefore=function(w,_){return this.endOf(_)<$(w)},m.$g=function(w,_,y){return I.u(w)?this[_]:this.set(y,w)},m.unix=function(){return Math.floor(this.valueOf()/1e3)},m.valueOf=function(){return this.$d.getTime()},m.startOf=function(w,_){var y=this,C=!!I.u(_)||_,U=I.p(w),E=function(et,F){var K=I.w(y.$u?Date.UTC(y.$y,F,et):new Date(y.$y,F,et),y);return C?K:K.endOf(d)},v=function(et,F){return I.w(y.toDate()[et].apply(y.toDate("s"),(C?[0,0,0,0]:[23,59,59,999]).slice(F)),y)},O=this.$W,Y=this.$M,G=this.$D,lt="set"+(this.$u?"UTC":"");switch(U){case g:return C?E(1,0):E(31,11);case u:return C?E(1,Y):E(0,Y+1);case h:var it=this.$locale().weekStart||0,dt=(O<it?O+7:O)-it;return E(C?G-dt:G+(6-dt),Y);case d:case p:return v(lt+"Hours",0);case a:return v(lt+"Minutes",1);case o:return v(lt+"Seconds",2);case l:return v(lt+"Milliseconds",3);default:return this.clone()}},m.endOf=function(w){return this.startOf(w,!1)},m.$set=function(w,_){var y,C=I.p(w),U="set"+(this.$u?"UTC":""),E=(y={},y[d]=U+"Date",y[p]=U+"Date",y[u]=U+"Month",y[g]=U+"FullYear",y[a]=U+"Hours",y[o]=U+"Minutes",y[l]=U+"Seconds",y[i]=U+"Milliseconds",y)[C],v=C===d?this.$D+(_-this.$W):_;if(C===u||C===g){var O=this.clone().set(p,1);O.$d[E](v),O.init(),this.$d=O.set(p,Math.min(this.$D,O.daysInMonth())).$d}else E&&this.$d[E](v);return this.init(),this},m.set=function(w,_){return this.clone().$set(w,_)},m.get=function(w){return this[I.p(w)]()},m.add=function(w,_){var y,C=this;w=Number(w);var U=I.p(_),E=function(Y){var G=$(C);return I.w(G.date(G.date()+Math.round(Y*w)),C)};if(U===u)return this.set(u,this.$M+w);if(U===g)return this.set(g,this.$y+w);if(U===d)return E(1);if(U===h)return E(7);var v=(y={},y[o]=n,y[a]=s,y[l]=e,y)[U]||1,O=this.$d.getTime()+w*v;return I.w(O,this)},m.subtract=function(w,_){return this.add(-1*w,_)},m.format=function(w){var _=this,y=this.$locale();if(!this.isValid())return y.invalidDate||b;var C=w||"YYYY-MM-DDTHH:mm:ssZ",U=I.z(this),E=this.$H,v=this.$m,O=this.$M,Y=y.weekdays,G=y.months,lt=y.meridiem,it=function(F,K,ct,ot){return F&&(F[K]||F(_,C))||ct[K].slice(0,ot)},dt=function(F){return I.s(E%12||12,F,"0")},et=lt||function(F,K,ct){var ot=F<12?"AM":"PM";return ct?ot.toLowerCase():ot};return C.replace(S,(function(F,K){return K||(function(ct){switch(ct){case"YY":return String(_.$y).slice(-2);case"YYYY":return I.s(_.$y,4,"0");case"M":return O+1;case"MM":return I.s(O+1,2,"0");case"MMM":return it(y.monthsShort,O,G,3);case"MMMM":return it(G,O);case"D":return _.$D;case"DD":return I.s(_.$D,2,"0");case"d":return String(_.$W);case"dd":return it(y.weekdaysMin,_.$W,Y,2);case"ddd":return it(y.weekdaysShort,_.$W,Y,3);case"dddd":return Y[_.$W];case"H":return String(E);case"HH":return I.s(E,2,"0");case"h":return dt(1);case"hh":return dt(2);case"a":return et(E,v,!0);case"A":return et(E,v,!1);case"m":return String(v);case"mm":return I.s(v,2,"0");case"s":return String(_.$s);case"ss":return I.s(_.$s,2,"0");case"SSS":return I.s(_.$ms,3,"0");case"Z":return U}return null})(F)||U.replace(":","")}))},m.utcOffset=function(){return 15*-Math.round(this.$d.getTimezoneOffset()/15)},m.diff=function(w,_,y){var C,U=this,E=I.p(_),v=$(w),O=(v.utcOffset()-this.utcOffset())*n,Y=this-v,G=function(){return I.m(U,v)};switch(E){case g:C=G()/12;break;case u:C=G();break;case f:C=G()/3;break;case h:C=(Y-O)/6048e5;break;case d:C=(Y-O)/864e5;break;case a:C=Y/s;break;case o:C=Y/n;break;case l:C=Y/e;break;default:C=Y}return y?C:I.a(C)},m.daysInMonth=function(){return this.endOf(u).$D},m.$locale=function(){return X[this.$L]},m.locale=function(w,_){if(!w)return this.$L;var y=this.clone(),C=j(w,_,!0);return C&&(y.$L=C),y},m.clone=function(){return I.w(this.$d,this)},m.toDate=function(){return new Date(this.valueOf())},m.toJSON=function(){return this.isValid()?this.toISOString():null},m.toISOString=function(){return this.$d.toISOString()},m.toString=function(){return this.$d.toUTCString()},D})(),J=W.prototype;return $.prototype=J,[["$ms",i],["$s",l],["$m",o],["$H",a],["$W",d],["$M",u],["$y",g],["$D",p]].forEach((function(D){J[D[1]]=function(m){return this.$g(m,D[0],D[1])}})),$.extend=function(D,m){return D.$i||(D(m,W,$),D.$i=!0),$},$.locale=j,$.isDayjs=Z,$.unix=function(D){return $(1e3*D)},$.en=X[H],$.Ls=X,$.p={},$}))})(Zt)),Zt.exports}var ws=ps();const ms=Ht(ws);var Kt={exports:{}},ys=Kt.exports,Ke;function ks(){return Ke||(Ke=1,(function(r,t){(function(e,n){r.exports=n()})(ys,(function(){var e="day";return function(n,s,i){var l=function(d){return d.add(4-d.isoWeekday(),e)},o=s.prototype;o.isoWeekYear=function(){return l(this).year()},o.isoWeek=function(d){if(!this.$utils().u(d))return this.add(7*(d-this.isoWeek()),e);var h,u,f,g,p=l(this),b=(h=this.isoWeekYear(),u=this.$u,f=(u?i.utc:i)().year(h).startOf("year"),g=4-f.isoWeekday(),f.isoWeekday()>4&&(g+=7),f.add(g,e));return p.diff(b,"week")+1},o.isoWeekday=function(d){return this.$utils().u(d)?this.day()||7:this.day(this.day()%7?d:d-7)};var a=o.startOf;o.startOf=function(d,h){var u=this.$utils(),f=!!u.u(h)||h;return u.p(d)==="isoweek"?f?this.date(this.date()-(this.isoWeekday()-1)).startOf("day"):this.date(this.date()-1-(this.isoWeekday()-1)+7).endOf("day"):a.bind(this)(d,h)}}}))})(Kt)),Kt.exports}var Ss=ks();const _s=Ht(Ss);var qt={exports:{}},Ds=qt.exports,qe;function bs(){return qe||(qe=1,(function(r,t){(function(e,n){r.exports=n()})(Ds,(function(){var e={LTS:"h:mm:ss A",LT:"h:mm A",L:"MM/DD/YYYY",LL:"MMMM D, YYYY",LLL:"MMMM D, YYYY h:mm A",LLLL:"dddd, MMMM D, YYYY h:mm A"},n=/(\[[^[]*\])|([-_:/.,()\s]+)|(A|a|Q|YYYY|YY?|ww?|MM?M?M?|Do|DD?|hh?|HH?|mm?|ss?|S{1,3}|z|ZZ?)/g,s=/\d/,i=/\d\d/,l=/\d\d?/,o=/\d*[^-_:/,()\s\d]+/,a={},d=function(k){return(k=+k)+(k>68?1900:2e3)},h=function(k){return function(S){this[k]=+S}},u=[/[+-]\d\d:?(\d\d)?|Z/,function(k){(this.zone||(this.zone={})).offset=(function(S){if(!S||S==="Z")return 0;var T=S.match(/([+-]|\d\d)/g),M=60*T[1]+(+T[2]||0);return M===0?0:T[0]==="+"?-M:M})(k)}],f=function(k){var S=a[k];return S&&(S.indexOf?S:S.s.concat(S.f))},g=function(k,S){var T,M=a.meridiem;if(M){for(var P=1;P<=24;P+=1)if(k.indexOf(M(P,0,S))>-1){T=P>12;break}}else T=k===(S?"pm":"PM");return T},p={A:[o,function(k){this.afternoon=g(k,!1)}],a:[o,function(k){this.afternoon=g(k,!0)}],Q:[s,function(k){this.month=3*(k-1)+1}],S:[s,function(k){this.milliseconds=100*+k}],SS:[i,function(k){this.milliseconds=10*+k}],SSS:[/\d{3}/,function(k){this.milliseconds=+k}],s:[l,h("seconds")],ss:[l,h("seconds")],m:[l,h("minutes")],mm:[l,h("minutes")],H:[l,h("hours")],h:[l,h("hours")],HH:[l,h("hours")],hh:[l,h("hours")],D:[l,h("day")],DD:[i,h("day")],Do:[o,function(k){var S=a.ordinal,T=k.match(/\d+/);if(this.day=T[0],S)for(var M=1;M<=31;M+=1)S(M).replace(/\[|\]/g,"")===k&&(this.day=M)}],w:[l,h("week")],ww:[i,h("week")],M:[l,h("month")],MM:[i,h("month")],MMM:[o,function(k){var S=f("months"),T=(f("monthsShort")||S.map((function(M){return M.slice(0,3)}))).indexOf(k)+1;if(T<1)throw new Error;this.month=T%12||T}],MMMM:[o,function(k){var S=f("months").indexOf(k)+1;if(S<1)throw new Error;this.month=S%12||S}],Y:[/[+-]?\d+/,h("year")],YY:[i,function(k){this.year=d(k)}],YYYY:[/\d{4}/,h("year")],Z:u,ZZ:u};function b(k){var S,T;S=k,T=a&&a.formats;for(var M=(k=S.replace(/(\[[^\]]+])|(LTS?|l{1,4}|L{1,4})/g,(function($,I,W){var J=W&&W.toUpperCase();return I||T[W]||e[W]||T[J].replace(/(\[[^\]]+])|(MMMM|MM|DD|dddd)/g,(function(D,m,w){return m||w.slice(1)}))}))).match(n),P=M.length,H=0;H<P;H+=1){var X=M[H],tt=p[X],Z=tt&&tt[0],j=tt&&tt[1];M[H]=j?{regex:Z,parser:j}:X.replace(/^\[|\]$/g,"")}return function($){for(var I={},W=0,J=0;W<P;W+=1){var D=M[W];if(typeof D=="string")J+=D.length;else{var m=D.regex,w=D.parser,_=$.slice(J),y=m.exec(_)[0];w.call(I,y),$=$.replace(y,"")}}return(function(C){var U=C.afternoon;if(U!==void 0){var E=C.hours;U?E<12&&(C.hours+=12):E===12&&(C.hours=0),delete C.afternoon}})(I),I}}return function(k,S,T){T.p.customParseFormat=!0,k&&k.parseTwoDigitYear&&(d=k.parseTwoDigitYear);var M=S.prototype,P=M.parse;M.parse=function(H){var X=H.date,tt=H.utc,Z=H.args;this.$u=tt;var j=Z[1];if(typeof j=="string"){var $=Z[2]===!0,I=Z[3]===!0,W=$||I,J=Z[2];I&&(J=Z[2]),a=this.$locale(),!$&&J&&(a=T.Ls[J]),this.$d=(function(_,y,C,U){try{if(["x","X"].indexOf(y)>-1)return new Date((y==="X"?1e3:1)*_);var E=b(y)(_),v=E.year,O=E.month,Y=E.day,G=E.hours,lt=E.minutes,it=E.seconds,dt=E.milliseconds,et=E.zone,F=E.week,K=new Date,ct=Y||(v||O?1:K.getDate()),ot=v||K.getFullYear(),Wt=0;v&&!O||(Wt=O>0?O-1:K.getMonth());var jt,he=G||0,de=lt||0,ue=it||0,fe=dt||0;return et?new Date(Date.UTC(ot,Wt,ct,he,de,ue,fe+60*et.offset*1e3)):C?new Date(Date.UTC(ot,Wt,ct,he,de,ue,fe)):(jt=new Date(ot,Wt,ct,he,de,ue,fe),F&&(jt=U(jt).week(F).toDate()),jt)}catch{return new Date("")}})(X,j,tt,T),this.init(),J&&J!==!0&&(this.$L=this.locale(J).$L),W&&X!=this.format(j)&&(this.$d=new Date("")),a={}}else if(j instanceof Array)for(var D=j.length,m=1;m<=D;m+=1){Z[1]=j[m-1];var w=T.apply(this,Z);if(w.isValid()){this.$d=w.$d,this.$L=w.$L,this.init();break}m===D&&(this.$d=new Date(""))}else P.call(this,H)}}}))})(qt)),qt.exports}var Cs=bs();const Us=Ht(Cs);var Qt={exports:{}},As=Qt.exports,Qe;function Es(){return Qe||(Qe=1,(function(r,t){(function(e,n){r.exports=n()})(As,(function(){return function(e,n){var s=n.prototype,i=s.format;s.format=function(l){var o=this,a=this.$locale();if(!this.isValid())return i.bind(this)(l);var d=this.$utils(),h=(l||"YYYY-MM-DDTHH:mm:ssZ").replace(/\[([^\]]+)]|Q|wo|ww|w|WW|W|zzz|z|gggg|GGGG|Do|X|x|k{1,2}|S/g,(function(u){switch(u){case"Q":return Math.ceil((o.$M+1)/3);case"Do":return a.ordinal(o.$D);case"gggg":return o.weekYear();case"GGGG":return o.isoWeekYear();case"wo":return a.ordinal(o.week(),"W");case"w":case"ww":return d.s(o.week(),u==="w"?1:2,"0");case"W":case"WW":return d.s(o.isoWeek(),u==="W"?1:2,"0");case"k":case"kk":return d.s(String(o.$H===0?24:o.$H),u==="k"?1:2,"0");case"X":return Math.floor(o.$d.getTime()/1e3);case"x":return o.$d.getTime();case"z":return"["+o.offsetName()+"]";case"zzz":return"["+o.offsetName("long")+"]";default:return u}}));return i.bind(this)(h)}}}))})(Qt)),Qt.exports}var Is=Es();const Ms=Ht(Is);exports.Doc=kt;exports.UndoManager=kr;exports.WebsocketProvider=us;exports.YArray=ft;exports.YArrayEvent=An;exports.YMap=pt;exports.YMapEvent=En;exports.YTextEvent=xn;exports.YXmlElement=mt;exports.YXmlEvent=$n;exports.YXmlText=Ot;exports.applyUpdate=qn;exports.commonjsGlobal=fs;exports.compareRelativePositions=ur;exports.createAbsolutePositionFromRelativePosition=dr;exports.createRelativePositionFromTypeIndex=ar;exports.dayjs=ms;exports.dayjsAdvancedFormat=Ms;exports.dayjsCustomParseFormat=Us;exports.dayjsIsoWeek=_s;exports.encodeStateAsUpdate=tr;exports.encodeStateVector=sr;exports.getDefaultExportFromCjs=Ht;