@editora/plugins 1.2.1 → 1.2.3
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/dist/collaboration.cjs.js +1 -1
- package/dist/collaboration.esm.js +97 -97
- package/dist/plugins.css +1 -1
- package/dist/table.cjs.js +13 -13
- package/dist/table.esm.js +181 -180
- package/package.json +3 -3
|
@@ -3,7 +3,7 @@
|
|
|
3
3
|
${n.toString()}`)};class qo{constructor(t){this.patterns=[],this.$state=t}if(t,n){return this.patterns.push({if:Gt(t),h:n}),this}else(t){return this.if(me,t)}done(){return(t,n)=>{for(let s=0;s<this.patterns.length;s++){const r=this.patterns[s];if(r.if.check(t))return r.h(t,n)}throw Y("Unhandled pattern")}}}const Qo=e=>new qo(e),rr=Qo(me).if(er,(e,t)=>Je(t,Zn,fe)).if(nr,(e,t)=>Do(t)).if(Ko,(e,t)=>ls(t)).if(Jo,(e,t)=>BigInt(Je(t,Zn,fe))).if(we,(e,t)=>bt(t,Ke(t,e.shape))).if(Uo,(e,t)=>{const n={};for(const s in e.shape){let r=e.shape[s];if(Oo.check(r)){if(ls(t))continue;r=r.shape}n[s]=rr(r,t)}return n}).if(Bo,(e,t)=>{const n=[],s=zs(t,0,42);for(let r=0;r<s;r++)n.push(bt(t,e.shape));return n}).if(Ys,(e,t)=>Ke(t,e.shape)).if(Wo,(e,t)=>null).if(zo,(e,t)=>{const n=bt(t,e.res);return()=>n}).if(Go,(e,t)=>bt(t,Ke(t,[Et,Lt,ve,sr,On,Ue,qs(Et),Ks(vt("a","b","c"),Et)]))).if(Ro,(e,t)=>{const n={},s=Je(t,0,3);for(let r=0;r<s;r++){const i=bt(t,e.shape.keys),o=bt(t,e.shape.values);n[i]=o}return n}).done(),bt=(e,t)=>rr(Gt(t),e),Re=typeof document<"u"?document:{};L(e=>e.nodeType===sc);typeof DOMParser<"u"&&new DOMParser;L(e=>e.nodeType===tc);L(e=>e.nodeType===ec);const Zo=e=>di(e,(t,n)=>`${n}:${t};`).join(""),tc=Re.ELEMENT_NODE,ec=Re.TEXT_NODE,nc=Re.DOCUMENT_NODE,sc=Re.DOCUMENT_FRAGMENT_NODE;L(e=>e.nodeType===nc);const Z=Symbol,ir=Z(),or=Z(),rc=Z(),ic=Z(),oc=Z(),cr=Z(),cc=Z(),Nn=Z(),lc=Z(),ac=e=>{e.length===1&&e[0]?.constructor===Function&&(e=e[0]());const t=[],n=[];let s=0;for(;s<e.length;s++){const r=e[s];if(r===void 0)break;if(r.constructor===String||r.constructor===Number)t.push(r);else if(r.constructor===Object)break}for(s>0&&n.push(t.join(""));s<e.length;s++){const r=e[s];r instanceof Symbol||n.push(r)}return n},hc={[ir]:K("font-weight","bold"),[or]:K("font-weight","normal"),[rc]:K("color","blue"),[oc]:K("color","green"),[ic]:K("color","grey"),[cr]:K("color","red"),[cc]:K("color","purple"),[Nn]:K("color","orange"),[lc]:K("color","black")},uc=e=>{e.length===1&&e[0]?.constructor===Function&&(e=e[0]());const t=[],n=[],s=R();let r=[],i=0;for(;i<e.length;i++){const o=e[i],c=hc[o];if(c!==void 0)s.set(c.left,c.right);else{if(o===void 0)break;if(o.constructor===String||o.constructor===Number){const l=Zo(s);i>0||l.length>0?(t.push("%c"+o),n.push(l)):t.push(o)}else break}}for(i>0&&(r=n,r.unshift(t.join("")));i<e.length;i++){const o=e[i];o instanceof Symbol||r.push(o)}return r},lr=go?uc:ac,dc=(...e)=>{console.log(...lr(e)),hr.forEach(t=>t.print(e))},ar=(...e)=>{console.warn(...lr(e)),e.unshift(Nn),hr.forEach(t=>t.print(e))},hr=rt(),ur=e=>({[Symbol.iterator](){return this},next:e}),fc=(e,t)=>ur(()=>{let n;do n=e.next();while(!n.done&&!t(n.value));return n}),We=(e,t)=>ur(()=>{const{done:n,value:s}=e.next();return{done:n,value:n?void 0:t(s)}});class $e{constructor(t,n){this.clock=t,this.len=n}}class Rt{constructor(){this.clients=new Map}}const Ot=(e,t,n)=>t.clients.forEach((s,r)=>{const i=e.doc.store.clients.get(r);if(i!=null){const o=i[i.length-1],c=o.id.clock+o.length;for(let l=0,a=s[l];l<s.length&&a.clock<c;a=s[++l])Cr(e,i,a.clock,a.len,n)}}),gc=(e,t)=>{let n=0,s=e.length-1;for(;n<=s;){const r=H((n+s)/2),i=e[r],o=i.clock;if(o<=t){if(t<o+i.len)return r;n=r+1}else s=r-1}return null},Zt=(e,t)=>{const n=e.clients.get(t.client);return n!==void 0&&gc(n,t.clock)!==null},Mn=e=>{e.clients.forEach(t=>{t.sort((r,i)=>r.clock-i.clock);let n,s;for(n=1,s=1;n<t.length;n++){const r=t[s-1],i=t[n];r.clock+r.len>=i.clock?t[s-1]=new $e(r.clock,wt(r.len,i.clock+i.len-r.clock)):(s<n&&(t[s]=i),s++)}t.length=s})},ln=e=>{const t=new Rt;for(let n=0;n<e.length;n++)e[n].clients.forEach((s,r)=>{if(!t.clients.has(r)){const i=s.slice();for(let o=n+1;o<e.length;o++)gi(i,e[o].clients.get(r)||[]);t.clients.set(r,i)}});return Mn(t),t},Jt=(e,t,n,s)=>{J(e.clients,t,()=>[]).push(new $e(n,s))},pc=()=>new Rt,wc=e=>{const t=pc();return e.clients.forEach((n,s)=>{const r=[];for(let i=0;i<n.length;i++){const o=n[i];if(o.deleted){const c=o.id.clock;let l=o.length;if(i+1<n.length)for(let a=n[i+1];i+1<n.length&&a.deleted;a=n[++i+1])l+=a.length;r.push(new $e(c,l))}}r.length>0&&t.clients.set(s,r)}),t},$t=(e,t)=>{w(e.restEncoder,t.clients.size),X(t.clients.entries()).sort((n,s)=>s[0]-n[0]).forEach(([n,s])=>{e.resetDsCurVal(),w(e.restEncoder,n);const r=s.length;w(e.restEncoder,r);for(let i=0;i<r;i++){const o=s[i];e.writeDsClock(o.clock),e.writeDsLen(o.len)}})},Un=e=>{const t=new Rt,n=m(e.restDecoder);for(let s=0;s<n;s++){e.resetDsCurVal();const r=m(e.restDecoder),i=m(e.restDecoder);if(i>0){const o=J(t.clients,r,()=>[]);for(let c=0;c<i;c++)o.push(new $e(e.readDsClock(),e.readDsLen()))}}return t},hs=(e,t,n)=>{const s=new Rt,r=m(e.restDecoder);for(let i=0;i<r;i++){e.resetDsCurVal();const o=m(e.restDecoder),c=m(e.restDecoder),l=n.clients.get(o)||[],a=A(n,o);for(let h=0;h<c;h++){const u=e.readDsClock(),d=u+e.readDsLen();if(u<a){a<d&&Jt(s,o,a,d-a);let f=P(l,u),g=l[f];for(!g.deleted&&g.id.clock<u&&(l.splice(f+1,0,Ee(t,g,u-g.id.clock)),f++);f<l.length&&(g=l[f++],g.id.clock<d);)g.deleted||(d<g.id.clock+g.length&&l.splice(f,0,Ee(t,g,d-g.id.clock)),g.delete(t))}else Jt(s,o,u,d-u)}}if(s.clients.size>0){const i=new ut;return w(i.restEncoder,0),$t(i,s),i.toUint8Array()}return null},dr=vs;class mt extends mn{constructor({guid:t=Xi(),collectionid:n=null,gc:s=!0,gcFilter:r=()=>!0,meta:i=null,autoLoad:o=!1,shouldLoad:c=!0}={}){super(),this.gc=s,this.gcFilter=r,this.clientID=dr(),this.guid=t,this.collectionid=n,this.share=new Map,this.store=new _r,this._transaction=null,this._transactionCleanups=[],this.subdocs=new Set,this._item=null,this.shouldLoad=c,this.autoLoad=o,this.meta=i,this.isLoaded=!1,this.isSynced=!1,this.isDestroyed=!1,this.whenLoaded=os(a=>{this.on("load",()=>{this.isLoaded=!0,a(this)})});const l=()=>os(a=>{const h=u=>{(u===void 0||u===!0)&&(this.off("sync",h),a())};this.on("sync",h)});this.on("sync",a=>{a===!1&&this.isSynced&&(this.whenSynced=l()),this.isSynced=a===void 0||a===!0,this.isSynced&&!this.isLoaded&&this.emit("load",[this])}),this.whenSynced=l()}load(){const t=this._item;t!==null&&!this.shouldLoad&&_(t.parent.doc,n=>{n.subdocsLoaded.add(this)},null,!0),this.shouldLoad=!0}getSubdocs(){return this.subdocs}getSubdocGuids(){return new Set(X(this.subdocs).map(t=>t.guid))}transact(t,n=null){return _(this,t,n)}get(t,n=I){const s=J(this.share,t,()=>{const i=new n;return i._integrate(this,null),i}),r=s.constructor;if(n!==I&&r!==n)if(r===I){const i=new n;i._map=s._map,s._map.forEach(o=>{for(;o!==null;o=o.left)o.parent=i}),i._start=s._start;for(let o=i._start;o!==null;o=o.right)o.parent=i;return i._length=s._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 s}getArray(t=""){return this.get(t,At)}getText(t=""){return this.get(t,Ut)}getMap(t=""){return this.get(t,Mt)}getXmlElement(t=""){return this.get(t,q)}getXmlFragment(t=""){return this.get(t,dt)}toJSON(){const t={};return this.share.forEach((n,s)=>{t[s]=n.toJSON()}),t}destroy(){this.isDestroyed=!0,X(this.subdocs).forEach(n=>n.destroy());const t=this._item;if(t!==null){this._item=null;const n=t.content;n.doc=new mt({guid:this.guid,...n.opts,shouldLoad:!1}),n.doc._item=t,_(t.parent.doc,s=>{const r=n.doc;t.deleted||s.subdocsAdded.add(r),s.subdocsRemoved.add(this)},null,!0)}this.emit("destroyed",[!0]),this.emit("destroy",[this]),super.destroy()}}class fr{constructor(t){this.restDecoder=t}resetDsCurVal(){}readDsClock(){return m(this.restDecoder)}readDsLen(){return m(this.restDecoder)}}class gr extends fr{readLeftID(){return y(m(this.restDecoder),m(this.restDecoder))}readRightID(){return y(m(this.restDecoder),m(this.restDecoder))}readClient(){return m(this.restDecoder)}readInfo(){return It(this.restDecoder)}readString(){return st(this.restDecoder)}readParentInfo(){return m(this.restDecoder)===1}readTypeRef(){return m(this.restDecoder)}readLen(){return m(this.restDecoder)}readAny(){return Yt(this.restDecoder)}readBuf(){return So(O(this.restDecoder))}readJSON(){return JSON.parse(st(this.restDecoder))}readKey(){return st(this.restDecoder)}}class mc{constructor(t){this.dsCurrVal=0,this.restDecoder=t}resetDsCurVal(){this.dsCurrVal=0}readDsClock(){return this.dsCurrVal+=m(this.restDecoder),this.dsCurrVal}readDsLen(){const t=m(this.restDecoder)+1;return this.dsCurrVal+=t,t}}class Nt extends mc{constructor(t){super(t),this.keys=[],m(t),this.keyClockDecoder=new Ge(O(t)),this.clientDecoder=new ae(O(t)),this.leftClockDecoder=new Ge(O(t)),this.rightClockDecoder=new Ge(O(t)),this.infoDecoder=new is(O(t),It),this.stringDecoder=new Ji(O(t)),this.parentInfoDecoder=new is(O(t),It),this.typeRefDecoder=new ae(O(t)),this.lenDecoder=new ae(O(t))}readLeftID(){return new Dt(this.clientDecoder.read(),this.leftClockDecoder.read())}readRightID(){return new Dt(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 Yt(this.restDecoder)}readBuf(){return O(this.restDecoder)}readJSON(){return Yt(this.restDecoder)}readKey(){const t=this.keyClockDecoder.read();if(t<this.keys.length)return this.keys[t];{const n=this.stringDecoder.read();return this.keys.push(n),n}}}class pr{constructor(){this.restEncoder=N()}toUint8Array(){return C(this.restEncoder)}resetDsCurVal(){}writeDsClock(t){w(this.restEncoder,t)}writeDsLen(t){w(this.restEncoder,t)}}class te extends pr{writeLeftID(t){w(this.restEncoder,t.client),w(this.restEncoder,t.clock)}writeRightID(t){w(this.restEncoder,t.client),w(this.restEncoder,t.clock)}writeClient(t){w(this.restEncoder,t)}writeInfo(t){sn(this.restEncoder,t)}writeString(t){ht(this.restEncoder,t)}writeParentInfo(t){w(this.restEncoder,t?1:0)}writeTypeRef(t){w(this.restEncoder,t)}writeLen(t){w(this.restEncoder,t)}writeAny(t){zt(this.restEncoder,t)}writeBuf(t){E(this.restEncoder,t)}writeJSON(t){ht(this.restEncoder,JSON.stringify(t))}writeKey(t){ht(this.restEncoder,t)}}class wr{constructor(){this.restEncoder=N(),this.dsCurrVal=0}toUint8Array(){return C(this.restEncoder)}resetDsCurVal(){this.dsCurrVal=0}writeDsClock(t){const n=t-this.dsCurrVal;this.dsCurrVal=t,w(this.restEncoder,n)}writeDsLen(t){t===0&&V(),w(this.restEncoder,t-1),this.dsCurrVal+=t}}class ut extends wr{constructor(){super(),this.keyMap=new Map,this.keyClock=0,this.keyClockEncoder=new Pe,this.clientEncoder=new le,this.leftClockEncoder=new Pe,this.rightClockEncoder=new Pe,this.infoEncoder=new ns(sn),this.stringEncoder=new Ri,this.parentInfoEncoder=new ns(sn),this.typeRefEncoder=new le,this.lenEncoder=new le}toUint8Array(){const t=N();return w(t,0),E(t,this.keyClockEncoder.toUint8Array()),E(t,this.clientEncoder.toUint8Array()),E(t,this.leftClockEncoder.toUint8Array()),E(t,this.rightClockEncoder.toUint8Array()),E(t,C(this.infoEncoder)),E(t,this.stringEncoder.toUint8Array()),E(t,C(this.parentInfoEncoder)),E(t,this.typeRefEncoder.toUint8Array()),E(t,this.lenEncoder.toUint8Array()),xe(t,C(this.restEncoder)),C(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){zt(this.restEncoder,t)}writeBuf(t){E(this.restEncoder,t)}writeJSON(t){zt(this.restEncoder,t)}writeKey(t){const n=this.keyMap.get(t);n===void 0?(this.keyClockEncoder.write(this.keyClock++),this.stringEncoder.write(t)):this.keyClockEncoder.write(n)}}const yc=(e,t,n,s)=>{s=wt(s,t[0].id.clock);const r=P(t,s);w(e.restEncoder,t.length-r),e.writeClient(n),w(e.restEncoder,s);const i=t[r];i.write(e,s-i.id.clock);for(let o=r+1;o<t.length;o++)t[o].write(e,0)},vn=(e,t,n)=>{const s=new Map;n.forEach((r,i)=>{A(t,i)>r&&s.set(i,r)}),Be(t).forEach((r,i)=>{n.has(i)||s.set(i,0)}),w(e.restEncoder,s.size),X(s.entries()).sort((r,i)=>i[0]-r[0]).forEach(([r,i])=>{yc(e,t.clients.get(r),r,i)})},bc=(e,t)=>{const n=R(),s=m(e.restDecoder);for(let r=0;r<s;r++){const i=m(e.restDecoder),o=new Array(i),c=e.readClient();let l=m(e.restDecoder);n.set(c,{i:0,refs:o});for(let a=0;a<i;a++){const h=e.readInfo();switch(Te&h){case 0:{const u=e.readLen();o[a]=new B(y(c,l),u),l+=u;break}case 10:{const u=m(e.restDecoder);o[a]=new F(y(c,l),u),l+=u;break}default:{const u=(h&(W|$))===0,d=new S(y(c,l),null,(h&$)===$?e.readLeftID():null,null,(h&W)===W?e.readRightID():null,u?e.readParentInfo()?t.get(e.readString()):e.readLeftID():null,u&&(h&jt)===jt?e.readString():null,zr(e,h));o[a]=d,l+=d.length}}}}return n},kc=(e,t,n)=>{const s=[];let r=X(n.keys()).sort((f,g)=>f-g);if(r.length===0)return null;const i=()=>{if(r.length===0)return null;let f=n.get(r[r.length-1]);for(;f.refs.length===f.i;)if(r.pop(),r.length>0)f=n.get(r[r.length-1]);else return null;return f};let o=i();if(o===null)return null;const c=new _r,l=new Map,a=(f,g)=>{const p=l.get(f);(p==null||p>g)&&l.set(f,g)};let h=o.refs[o.i++];const u=new Map,d=()=>{for(const f of s){const g=f.id.client,p=n.get(g);p?(p.i--,c.clients.set(g,p.refs.slice(p.i)),n.delete(g),p.i=0,p.refs=[]):c.clients.set(g,[f]),r=r.filter(b=>b!==g)}s.length=0};for(;;){if(h.constructor!==F){const g=J(u,h.id.client,()=>A(t,h.id.client))-h.id.clock;if(g<0)s.push(h),a(h.id.client,h.id.clock-1),d();else{const p=h.getMissing(e,t);if(p!==null){s.push(h);const b=n.get(p)||{refs:[],i:0};if(b.refs.length===b.i)a(p,A(t,p)),d();else{h=b.refs[b.i++];continue}}else(g===0||g<h.length)&&(h.integrate(e,g),u.set(h.id.client,h.id.clock+h.length))}}if(s.length>0)h=s.pop();else if(o!==null&&o.i<o.refs.length)h=o.refs[o.i++];else{if(o=i(),o===null)break;h=o.refs[o.i++]}}if(c.clients.size>0){const f=new ut;return vn(f,c,new Map),w(f.restEncoder,0),{missing:l,update:f.toUint8Array()}}return null},_c=(e,t)=>vn(e,t.doc.store,t.beforeState),Sc=(e,t,n,s=new Nt(e))=>_(t,r=>{r.local=!1;let i=!1;const o=r.doc,c=o.store,l=bc(s,o),a=kc(r,c,l),h=c.pendingStructs;if(h){for(const[d,f]of h.missing)if(f<A(c,d)){i=!0;break}if(a){for(const[d,f]of a.missing){const g=h.missing.get(d);(g==null||g>f)&&h.missing.set(d,f)}h.update=be([h.update,a.update])}}else c.pendingStructs=a;const u=hs(s,r,c);if(c.pendingDs){const d=new Nt(ct(c.pendingDs));m(d.restDecoder);const f=hs(d,r,c);u&&f?c.pendingDs=be([u,f]):c.pendingDs=u||f}else c.pendingDs=u;if(i){const d=c.pendingStructs.update;c.pendingStructs=null,mr(r.doc,d)}},n,!1),mr=(e,t,n,s=Nt)=>{const r=ct(t);Sc(r,e,n,new s(r))},Cc=(e,t,n)=>mr(e,t,n,gr),Ec=(e,t,n=new Map)=>{vn(e,t.store,n),$t(e,wc(t.store))},Dc=(e,t=new Uint8Array([0]),n=new ut)=>{const s=yr(t);Ec(n,e,s);const r=[n.toUint8Array()];if(e.store.pendingDs&&r.push(e.store.pendingDs),e.store.pendingStructs&&r.push(zc(e.store.pendingStructs.update,t)),r.length>1){if(n.constructor===te)return jc(r.map((i,o)=>o===0?i:Pc(i)));if(n.constructor===ut)return be(r)}return r[0]},Ac=(e,t)=>Dc(e,t,new te),Tc=e=>{const t=new Map,n=m(e.restDecoder);for(let s=0;s<n;s++){const r=m(e.restDecoder),i=m(e.restDecoder);t.set(r,i)}return t},yr=e=>Tc(new fr(ct(e))),br=(e,t)=>(w(e.restEncoder,t.size),X(t.entries()).sort((n,s)=>s[0]-n[0]).forEach(([n,s])=>{w(e.restEncoder,n),w(e.restEncoder,s)}),e),xc=(e,t)=>br(e,Be(t.store)),Ic=(e,t=new wr)=>(e instanceof Map?br(t,e):xc(t,e),t.toUint8Array()),Lc=e=>Ic(e,new pr);class Oc{constructor(){this.l=[]}}const us=()=>new Oc,ds=(e,t)=>e.l.push(t),fs=(e,t)=>{const n=e.l,s=n.length;e.l=n.filter(r=>t!==r),s===e.l.length&&console.error("[yjs] Tried to remove event handler that doesn't exist.")},kr=(e,t,n)=>An(e.l,[t,n]);class Dt{constructor(t,n){this.client=t,this.clock=n}}const re=(e,t)=>e===t||e!==null&&t!==null&&e.client===t.client&&e.clock===t.clock,y=(e,t)=>new Dt(e,t),Nc=e=>{for(const[t,n]of e.doc.share.entries())if(n===e)return t;throw V()},ye=(e,t)=>{for(;t!==null;){if(t.parent===e)return!0;t=t.parent._item}return!1},kt=(e,t)=>t===void 0?!e.deleted:t.sv.has(e.id.client)&&(t.sv.get(e.id.client)||0)>e.id.clock&&!Zt(t.ds,e.id),an=(e,t)=>{const n=J(e.meta,an,rt),s=e.doc.store;n.has(t)||(t.sv.forEach((r,i)=>{r<A(s,i)&&v(e,y(i,r))}),Ot(e,t.ds,r=>{}),n.add(t))};class _r{constructor(){this.clients=new Map,this.pendingStructs=null,this.pendingDs=null}}const Be=e=>{const t=new Map;return e.clients.forEach((n,s)=>{const r=n[n.length-1];t.set(s,r.id.clock+r.length)}),t},A=(e,t)=>{const n=e.clients.get(t);if(n===void 0)return 0;const s=n[n.length-1];return s.id.clock+s.length},Sr=(e,t)=>{let n=e.clients.get(t.id.client);if(n===void 0)n=[],e.clients.set(t.id.client,n);else{const s=n[n.length-1];if(s.id.clock+s.length!==t.id.clock)throw V()}n.push(t)},P=(e,t)=>{let n=0,s=e.length-1,r=e[s],i=r.id.clock;if(i===t)return s;let o=H(t/(i+r.length-1)*s);for(;n<=s;){if(r=e[o],i=r.id.clock,i<=t){if(t<i+r.length)return o;n=o+1}else s=o-1;o=H((n+s)/2)}throw V()},Mc=(e,t)=>{const n=e.clients.get(t.client);return n[P(n,t.clock)]},he=Mc,hn=(e,t,n)=>{const s=P(t,n),r=t[s];return r.id.clock<n&&r instanceof S?(t.splice(s+1,0,Ee(e,r,n-r.id.clock)),s+1):s},v=(e,t)=>{const n=e.doc.store.clients.get(t.client);return n[hn(e,n,t.clock)]},gs=(e,t,n)=>{const s=t.clients.get(n.client),r=P(s,n.clock),i=s[r];return n.clock!==i.id.clock+i.length-1&&i.constructor!==B&&s.splice(r+1,0,Ee(e,i,n.clock-i.id.clock+1)),i},Uc=(e,t,n)=>{const s=e.clients.get(t.id.client);s[P(s,t.id.clock)]=n},Cr=(e,t,n,s,r)=>{if(s===0)return;const i=n+s;let o=hn(e,t,n),c;do c=t[o++],i<c.id.clock+c.length&&hn(e,t,i),r(c);while(o<t.length&&t[o].id.clock<i)};class vc{constructor(t,n,s){this.doc=t,this.deleteSet=new Rt,this.beforeState=Be(t.store),this.afterState=new Map,this.changed=new Map,this.changedParentTypes=new Map,this._mergeStructs=[],this.origin=n,this.meta=new Map,this.local=s,this.subdocsAdded=new Set,this.subdocsRemoved=new Set,this.subdocsLoaded=new Set,this._needFormattingCleanup=!1}}const ps=(e,t)=>t.deleteSet.clients.size===0&&!fi(t.afterState,(n,s)=>t.beforeState.get(s)!==n)?!1:(Mn(t.deleteSet),_c(e,t),$t(e,t.deleteSet),!0),ws=(e,t,n)=>{const s=t._item;(s===null||s.id.clock<(e.beforeState.get(s.id.client)||0)&&!s.deleted)&&J(e.changed,t,rt).add(n)},ue=(e,t)=>{let n=e[t],s=e[t-1],r=t;for(;r>0;n=s,s=e[--r-1]){if(s.deleted===n.deleted&&s.constructor===n.constructor&&s.mergeWith(n)){n instanceof S&&n.parentSub!==null&&n.parent._map.get(n.parentSub)===n&&n.parent._map.set(n.parentSub,s);continue}break}const i=t-r;return i&&e.splice(t+1-i,i),i},Rc=(e,t,n)=>{for(const[s,r]of e.clients.entries()){const i=t.clients.get(s);for(let o=r.length-1;o>=0;o--){const c=r[o],l=c.clock+c.len;for(let a=P(i,c.clock),h=i[a];a<i.length&&h.id.clock<l;h=i[++a]){const u=i[a];if(c.clock+c.len<=u.id.clock)break;u instanceof S&&u.deleted&&!u.keep&&n(u)&&u.gc(t,!1)}}}},$c=(e,t)=>{e.clients.forEach((n,s)=>{const r=t.clients.get(s);for(let i=n.length-1;i>=0;i--){const o=n[i],c=yn(r.length-1,1+P(r,o.clock+o.len-1));for(let l=c,a=r[l];l>0&&a.id.clock>=o.clock;a=r[l])l-=1+ue(r,l)}})},Er=(e,t)=>{if(t<e.length){const n=e[t],s=n.doc,r=s.store,i=n.deleteSet,o=n._mergeStructs;try{Mn(i),n.afterState=Be(n.doc.store),s.emit("beforeObserverCalls",[n,s]);const c=[];n.changed.forEach((l,a)=>c.push(()=>{(a._item===null||!a._item.deleted)&&a._callObserver(n,l)})),c.push(()=>{n.changedParentTypes.forEach((l,a)=>{a._dEH.l.length>0&&(a._item===null||!a._item.deleted)&&c.push(()=>{l=l.filter(h=>h.target._item===null||!h.target._item.deleted),l.forEach(h=>{h.currentTarget=a,h._path=null}),l.sort((h,u)=>h.path.length-u.path.length),kr(a._dEH,l,n)})}),c.push(()=>s.emit("afterTransaction",[n,s])),c.push(()=>{n._needFormattingCleanup&&il(n)})}),An(c,[])}finally{s.gc&&Rc(i,r,s.gcFilter),$c(i,r),n.afterState.forEach((h,u)=>{const d=n.beforeState.get(u)||0;if(d!==h){const f=r.clients.get(u),g=wt(P(f,d),1);for(let p=f.length-1;p>=g;)p-=1+ue(f,p)}});for(let h=o.length-1;h>=0;h--){const{client:u,clock:d}=o[h].id,f=r.clients.get(u),g=P(f,d);g+1<f.length&&ue(f,g+1)>1||g>0&&ue(f,g)}if(!n.local&&n.afterState.get(s.clientID)!==n.beforeState.get(s.clientID)&&(dc(Nn,ir,"[yjs] ",or,cr,"Changed the client-id because another client seems to be using it."),s.clientID=dr()),s.emit("afterTransactionCleanup",[n,s]),s._observers.has("update")){const h=new te;ps(h,n)&&s.emit("update",[h.toUint8Array(),n.origin,s,n])}if(s._observers.has("updateV2")){const h=new ut;ps(h,n)&&s.emit("updateV2",[h.toUint8Array(),n.origin,s,n])}const{subdocsAdded:c,subdocsLoaded:l,subdocsRemoved:a}=n;(c.size>0||a.size>0||l.size>0)&&(c.forEach(h=>{h.clientID=s.clientID,h.collectionid==null&&(h.collectionid=s.collectionid),s.subdocs.add(h)}),a.forEach(h=>s.subdocs.delete(h)),s.emit("subdocs",[{loaded:l,added:c,removed:a},s,n]),a.forEach(h=>h.destroy())),e.length<=t+1?(s._transactionCleanups=[],s.emit("afterAllTransactions",[s,e])):Er(e,t+1)}}},_=(e,t,n=null,s=!0)=>{const r=e._transactionCleanups;let i=!1,o=null;e._transaction===null&&(i=!0,e._transaction=new vc(e,n,s),r.push(e._transaction),r.length===1&&e.emit("beforeAllTransactions",[e]),e.emit("beforeTransaction",[e._transaction,e]));try{o=t(e._transaction)}finally{if(i){const c=e._transaction===r[0];e._transaction=null,c&&Er(r,0)}}return o};class Bc{constructor(t,n){this.insertions=n,this.deletions=t,this.meta=new Map}}const ms=(e,t,n)=>{Ot(e,n.deletions,s=>{s instanceof S&&t.scope.some(r=>r===e.doc||ye(r,s))&&zn(s,!1)})},ys=(e,t,n)=>{let s=null;const r=e.doc,i=e.scope;_(r,c=>{for(;t.length>0&&e.currStackItem===null;){const l=r.store,a=t.pop(),h=new Set,u=[];let d=!1;Ot(c,a.insertions,f=>{if(f instanceof S){if(f.redone!==null){let{item:g,diff:p}=Nl(l,f.id);p>0&&(g=v(c,y(g.id.client,g.id.clock+p))),f=g}!f.deleted&&i.some(g=>g===c.doc||ye(g,f))&&u.push(f)}}),Ot(c,a.deletions,f=>{f instanceof S&&i.some(g=>g===c.doc||ye(g,f))&&!Zt(a.insertions,f.id)&&h.add(f)}),h.forEach(f=>{d=Hr(c,f,h,a.insertions,e.ignoreRemoteMapChanges,e)!==null||d});for(let f=u.length-1;f>=0;f--){const g=u[f];e.deleteFilter(g)&&(g.delete(c),d=!0)}e.currStackItem=d?a:null}c.changed.forEach((l,a)=>{l.has(null)&&a._searchMarker&&(a._searchMarker.length=0)}),s=c},e);const o=e.currStackItem;if(o!=null){const c=s.changedParentTypes;e.emit("stack-item-popped",[{stackItem:o,type:n,changedParentTypes:c,origin:e},e]),e.currStackItem=null}return o};class Fc extends mn{constructor(t,{captureTimeout:n=500,captureTransaction:s=l=>!0,deleteFilter:r=()=>!0,trackedOrigins:i=new Set([null]),ignoreRemoteMapChanges:o=!1,doc:c=xt(t)?t[0].doc:t instanceof mt?t:t.doc}={}){super(),this.scope=[],this.doc=c,this.addToScope(t),this.deleteFilter=r,i.add(this),this.trackedOrigins=i,this.captureTransaction=s,this.undoStack=[],this.redoStack=[],this.undoing=!1,this.redoing=!1,this.currStackItem=null,this.lastChange=0,this.ignoreRemoteMapChanges=o,this.captureTimeout=n,this.afterTransactionHandler=l=>{if(!this.captureTransaction(l)||!this.scope.some(b=>l.changedParentTypes.has(b)||b===this.doc)||!this.trackedOrigins.has(l.origin)&&(!l.origin||!this.trackedOrigins.has(l.origin.constructor)))return;const a=this.undoing,h=this.redoing,u=a?this.redoStack:this.undoStack;a?this.stopCapturing():h||this.clear(!1,!0);const d=new Rt;l.afterState.forEach((b,k)=>{const Wn=l.beforeState.get(k)||0,Xn=b-Wn;Xn>0&&Jt(d,k,Wn,Xn)});const f=it();let g=!1;if(this.lastChange>0&&f-this.lastChange<this.captureTimeout&&u.length>0&&!a&&!h){const b=u[u.length-1];b.deletions=ln([b.deletions,l.deleteSet]),b.insertions=ln([b.insertions,d])}else u.push(new Bc(l.deleteSet,d)),g=!0;!a&&!h&&(this.lastChange=f),Ot(l,l.deleteSet,b=>{b instanceof S&&this.scope.some(k=>k===l.doc||ye(k,b))&&zn(b,!0)});const p=[{stackItem:u[u.length-1],origin:l.origin,type:a?"redo":"undo",changedParentTypes:l.changedParentTypes},this];g?this.emit("stack-item-added",p):this.emit("stack-item-updated",p)},this.destroy=this.destroy.bind(this),this.doc.on("afterTransaction",this.afterTransactionHandler),this.doc.on("destroy",this.destroy)}addToScope(t){const n=new Set(this.scope);t=xt(t)?t:[t],t.forEach(s=>{n.has(s)||(n.add(s),(s instanceof I?s.doc!==this.doc:s!==this.doc)&&ar("[yjs#509] Not same Y.Doc"),this.scope.push(s))})}addTrackedOrigin(t){this.trackedOrigins.add(t)}removeTrackedOrigin(t){this.trackedOrigins.delete(t)}clear(t=!0,n=!0){(t&&this.canUndo()||n&&this.canRedo())&&this.doc.transact(s=>{t&&(this.undoStack.forEach(r=>ms(s,this,r)),this.undoStack=[]),n&&(this.redoStack.forEach(r=>ms(s,this,r)),this.redoStack=[]),this.emit("stack-cleared",[{undoStackCleared:t,redoStackCleared:n}])})}stopCapturing(){this.lastChange=0}undo(){this.undoing=!0;let t;try{t=ys(this,this.undoStack,"undo")}finally{this.undoing=!1}return t}redo(){this.redoing=!0;let t;try{t=ys(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),this.doc.off("destroy",this.destroy),super.destroy()}}function*Vc(e){const t=m(e.restDecoder);for(let n=0;n<t;n++){const s=m(e.restDecoder),r=e.readClient();let i=m(e.restDecoder);for(let o=0;o<s;o++){const c=e.readInfo();if(c===10){const l=m(e.restDecoder);yield new F(y(r,i),l),i+=l}else if((Te&c)!==0){const l=(c&(W|$))===0,a=new S(y(r,i),null,(c&$)===$?e.readLeftID():null,null,(c&W)===W?e.readRightID():null,l?e.readParentInfo()?e.readString():e.readLeftID():null,l&&(c&jt)===jt?e.readString():null,zr(e,c));yield a,i+=a.length}else{const l=e.readLen();yield new B(y(r,i),l),i+=l}}}}class Rn{constructor(t,n){this.gen=Vc(t),this.curr=null,this.done=!1,this.filterSkips=n,this.next()}next(){do this.curr=this.gen.next().value||null;while(this.filterSkips&&this.curr!==null&&this.curr.constructor===F);return this.curr}}class $n{constructor(t){this.currClient=0,this.startClock=0,this.written=0,this.encoder=t,this.clientStructs=[]}}const jc=e=>be(e,gr,te),Hc=(e,t)=>{if(e.constructor===B){const{client:n,clock:s}=e.id;return new B(y(n,s+t),e.length-t)}else if(e.constructor===F){const{client:n,clock:s}=e.id;return new F(y(n,s+t),e.length-t)}else{const n=e,{client:s,clock:r}=n.id;return new S(y(s,r+t),null,y(s,r+t-1),null,n.rightOrigin,n.parent,n.parentSub,n.content.splice(t))}},be=(e,t=Nt,n=ut)=>{if(e.length===1)return e[0];const s=e.map(h=>new t(ct(h)));let r=s.map(h=>new Rn(h,!0)),i=null;const o=new n,c=new $n(o);for(;r=r.filter(d=>d.curr!==null),r.sort((d,f)=>{if(d.curr.id.client===f.curr.id.client){const g=d.curr.id.clock-f.curr.id.clock;return g===0?d.curr.constructor===f.curr.constructor?0:d.curr.constructor===F?1:-1:g}else return f.curr.id.client-d.curr.id.client}),r.length!==0;){const h=r[0],u=h.curr.id.client;if(i!==null){let d=h.curr,f=!1;for(;d!==null&&d.id.clock+d.length<=i.struct.id.clock+i.struct.length&&d.id.client>=i.struct.id.client;)d=h.next(),f=!0;if(d===null||d.id.client!==u||f&&d.id.clock>i.struct.id.clock+i.struct.length)continue;if(u!==i.struct.id.client)et(c,i.struct,i.offset),i={struct:d,offset:0},h.next();else if(i.struct.id.clock+i.struct.length<d.id.clock)if(i.struct.constructor===F)i.struct.length=d.id.clock+d.length-i.struct.id.clock;else{et(c,i.struct,i.offset);const g=d.id.clock-i.struct.id.clock-i.struct.length;i={struct:new F(y(u,i.struct.id.clock+i.struct.length),g),offset:0}}else{const g=i.struct.id.clock+i.struct.length-d.id.clock;g>0&&(i.struct.constructor===F?i.struct.length-=g:d=Hc(d,g)),i.struct.mergeWith(d)||(et(c,i.struct,i.offset),i={struct:d,offset:0},h.next())}}else i={struct:h.curr,offset:0},h.next();for(let d=h.curr;d!==null&&d.id.client===u&&d.id.clock===i.struct.id.clock+i.struct.length&&d.constructor!==F;d=h.next())et(c,i.struct,i.offset),i={struct:d,offset:0}}i!==null&&(et(c,i.struct,i.offset),i=null),Bn(c);const l=s.map(h=>Un(h)),a=ln(l);return $t(o,a),o.toUint8Array()},zc=(e,t,n=Nt,s=ut)=>{const r=yr(t),i=new s,o=new $n(i),c=new n(ct(e)),l=new Rn(c,!1);for(;l.curr;){const h=l.curr,u=h.id.client,d=r.get(u)||0;if(l.curr.constructor===F){l.next();continue}if(h.id.clock+h.length>d)for(et(o,h,wt(d-h.id.clock,0)),l.next();l.curr&&l.curr.id.client===u;)et(o,l.curr,0),l.next();else for(;l.curr&&l.curr.id.client===u&&l.curr.id.clock+l.curr.length<=d;)l.next()}Bn(o);const a=Un(c);return $t(i,a),i.toUint8Array()},Dr=e=>{e.written>0&&(e.clientStructs.push({written:e.written,restEncoder:C(e.encoder.restEncoder)}),e.encoder.restEncoder=N(),e.written=0)},et=(e,t,n)=>{e.written>0&&e.currClient!==t.id.client&&Dr(e),e.written===0&&(e.currClient=t.id.client,e.encoder.writeClient(t.id.client),w(e.encoder.restEncoder,t.id.clock+n)),t.write(e.encoder,n),e.written++},Bn=e=>{Dr(e);const t=e.encoder.restEncoder;w(t,e.clientStructs.length);for(let n=0;n<e.clientStructs.length;n++){const s=e.clientStructs[n];w(t,s.written),xe(t,s.restEncoder)}},Yc=(e,t,n,s)=>{const r=new n(ct(e)),i=new Rn(r,!1),o=new s,c=new $n(o);for(let a=i.curr;a!==null;a=i.next())et(c,t(a),0);Bn(c);const l=Un(r);return $t(o,l),o.toUint8Array()},Pc=e=>Yc(e,lo,Nt,te),bs="You must not compute changes after the event-handler fired.";class Fe{constructor(t,n){this.target=t,this.currentTarget=t,this.transaction=n,this._changes=null,this._keys=null,this._delta=null,this._path=null}get path(){return this._path||(this._path=Gc(this.currentTarget,this.target))}deletes(t){return Zt(this.transaction.deleteSet,t.id)}get keys(){if(this._keys===null){if(this.transaction.doc._transactionCleanups.length===0)throw Y(bs);const t=new Map,n=this.target;this.transaction.changed.get(n).forEach(r=>{if(r!==null){const i=n._map.get(r);let o,c;if(this.adds(i)){let l=i.left;for(;l!==null&&this.adds(l);)l=l.left;if(this.deletes(i))if(l!==null&&this.deletes(l))o="delete",c=He(l.content.getContent());else return;else l!==null&&this.deletes(l)?(o="update",c=He(l.content.getContent())):(o="add",c=void 0)}else if(this.deletes(i))o="delete",c=He(i.content.getContent());else return;t.set(r,{action:o,oldValue:c})}}),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 Y(bs);const n=this.target,s=rt(),r=rt(),i=[];if(t={added:s,deleted:r,delta:i,keys:this.keys},this.transaction.changed.get(n).has(null)){let c=null;const l=()=>{c&&i.push(c)};for(let a=n._start;a!==null;a=a.right)a.deleted?this.deletes(a)&&!this.adds(a)&&((c===null||c.delete===void 0)&&(l(),c={delete:0}),c.delete+=a.length,r.add(a)):this.adds(a)?((c===null||c.insert===void 0)&&(l(),c={insert:[]}),c.insert=c.insert.concat(a.content.getContent()),s.add(a)):((c===null||c.retain===void 0)&&(l(),c={retain:0}),c.retain+=a.length);c!==null&&c.retain===void 0&&l()}this._changes=t}return t}}const Gc=(e,t)=>{const n=[];for(;t._item!==null&&t!==e;){if(t._item.parentSub!==null)n.unshift(t._item.parentSub);else{let s=0,r=t._item.parent._start;for(;r!==t._item&&r!==null;)!r.deleted&&r.countable&&(s+=r.length),r=r.right;n.unshift(s)}t=t._item.parent}return n},M=()=>{ar("Invalid access: Add Yjs type to a document before reading data.")},Ar=80;let Fn=0;class Jc{constructor(t,n){t.marker=!0,this.p=t,this.index=n,this.timestamp=Fn++}}const Kc=e=>{e.timestamp=Fn++},Tr=(e,t,n)=>{e.p.marker=!1,e.p=t,t.marker=!0,e.index=n,e.timestamp=Fn++},Wc=(e,t,n)=>{if(e.length>=Ar){const s=e.reduce((r,i)=>r.timestamp<i.timestamp?r:i);return Tr(s,t,n),s}else{const s=new Jc(t,n);return e.push(s),s}},Ve=(e,t)=>{if(e._start===null||t===0||e._searchMarker===null)return null;const n=e._searchMarker.length===0?null:e._searchMarker.reduce((i,o)=>ce(t-i.index)<ce(t-o.index)?i:o);let s=e._start,r=0;for(n!==null&&(s=n.p,r=n.index,Kc(n));s.right!==null&&r<t;){if(!s.deleted&&s.countable){if(t<r+s.length)break;r+=s.length}s=s.right}for(;s.left!==null&&r>t;)s=s.left,!s.deleted&&s.countable&&(r-=s.length);for(;s.left!==null&&s.left.id.client===s.id.client&&s.left.id.clock+s.left.length===s.id.clock;)s=s.left,!s.deleted&&s.countable&&(r-=s.length);return n!==null&&ce(n.index-r)<s.parent.length/Ar?(Tr(n,s,r),n):Wc(e._searchMarker,s,r)},Kt=(e,t,n)=>{for(let s=e.length-1;s>=0;s--){const r=e[s];if(n>0){let i=r.p;for(i.marker=!1;i&&(i.deleted||!i.countable);)i=i.left,i&&!i.deleted&&i.countable&&(r.index-=i.length);if(i===null||i.marker===!0){e.splice(s,1);continue}r.p=i,i.marker=!0}(t<r.index||n>0&&t===r.index)&&(r.index=wt(t,r.index+n))}},je=(e,t,n)=>{const s=e,r=t.changedParentTypes;for(;J(r,e,()=>[]).push(n),e._item!==null;)e=e._item.parent;kr(s._eH,n,t)};class I{constructor(){this._item=null,this._map=new Map,this._start=null,this.doc=null,this._length=0,this._eH=us(),this._dEH=us(),this._searchMarker=null}get parent(){return this._item?this._item.parent:null}_integrate(t,n){this.doc=t,this._item=n}_copy(){throw j()}clone(){throw j()}_write(t){}get _first(){let t=this._start;for(;t!==null&&t.deleted;)t=t.right;return t}_callObserver(t,n){!t.local&&this._searchMarker&&(this._searchMarker.length=0)}observe(t){ds(this._eH,t)}observeDeep(t){ds(this._dEH,t)}unobserve(t){fs(this._eH,t)}unobserveDeep(t){fs(this._dEH,t)}toJSON(){}}const xr=(e,t,n)=>{e.doc??M(),t<0&&(t=e._length+t),n<0&&(n=e._length+n);let s=n-t;const r=[];let i=e._start;for(;i!==null&&s>0;){if(i.countable&&!i.deleted){const o=i.content.getContent();if(o.length<=t)t-=o.length;else{for(let c=t;c<o.length&&s>0;c++)r.push(o[c]),s--;t=0}}i=i.right}return r},Ir=e=>{e.doc??M();const t=[];let n=e._start;for(;n!==null;){if(n.countable&&!n.deleted){const s=n.content.getContent();for(let r=0;r<s.length;r++)t.push(s[r])}n=n.right}return t},Wt=(e,t)=>{let n=0,s=e._start;for(e.doc??M();s!==null;){if(s.countable&&!s.deleted){const r=s.content.getContent();for(let i=0;i<r.length;i++)t(r[i],n++,e)}s=s.right}},Lr=(e,t)=>{const n=[];return Wt(e,(s,r)=>{n.push(t(s,r,e))}),n},Xc=e=>{let t=e._start,n=null,s=0;return{[Symbol.iterator](){return this},next:()=>{if(n===null){for(;t!==null&&t.deleted;)t=t.right;if(t===null)return{done:!0,value:void 0};n=t.content.getContent(),s=0,t=t.right}const r=n[s++];return n.length<=s&&(n=null),{done:!1,value:r}}}},Or=(e,t)=>{e.doc??M();const n=Ve(e,t);let s=e._start;for(n!==null&&(s=n.p,t-=n.index);s!==null;s=s.right)if(!s.deleted&&s.countable){if(t<s.length)return s.content.getContent()[t];t-=s.length}},ke=(e,t,n,s)=>{let r=n;const i=e.doc,o=i.clientID,c=i.store,l=n===null?t._start:n.right;let a=[];const h=()=>{a.length>0&&(r=new S(y(o,A(c,o)),r,r&&r.lastId,l,l&&l.id,t,null,new ft(a)),r.integrate(e,0),a=[])};s.forEach(u=>{if(u===null)a.push(u);else switch(u.constructor){case Number:case Object:case Boolean:case Array:case String:a.push(u);break;default:switch(h(),u.constructor){case Uint8Array:case ArrayBuffer:r=new S(y(o,A(c,o)),r,r&&r.lastId,l,l&&l.id,t,null,new ee(new Uint8Array(u))),r.integrate(e,0);break;case mt:r=new S(y(o,A(c,o)),r,r&&r.lastId,l,l&&l.id,t,null,new ne(u)),r.integrate(e,0);break;default:if(u instanceof I)r=new S(y(o,A(c,o)),r,r&&r.lastId,l,l&&l.id,t,null,new tt(u)),r.integrate(e,0);else throw new Error("Unexpected content type in insert operation")}}}),h()},Nr=()=>Y("Length exceeded!"),Mr=(e,t,n,s)=>{if(n>t._length)throw Nr();if(n===0)return t._searchMarker&&Kt(t._searchMarker,n,s.length),ke(e,t,null,s);const r=n,i=Ve(t,n);let o=t._start;for(i!==null&&(o=i.p,n-=i.index,n===0&&(o=o.prev,n+=o&&o.countable&&!o.deleted?o.length:0));o!==null;o=o.right)if(!o.deleted&&o.countable){if(n<=o.length){n<o.length&&v(e,y(o.id.client,o.id.clock+n));break}n-=o.length}return t._searchMarker&&Kt(t._searchMarker,r,s.length),ke(e,t,o,s)},qc=(e,t,n)=>{let r=(t._searchMarker||[]).reduce((i,o)=>o.index>i.index?o:i,{index:0,p:t._start}).p;if(r)for(;r.right;)r=r.right;return ke(e,t,r,n)},Ur=(e,t,n,s)=>{if(s===0)return;const r=n,i=s,o=Ve(t,n);let c=t._start;for(o!==null&&(c=o.p,n-=o.index);c!==null&&n>0;c=c.right)!c.deleted&&c.countable&&(n<c.length&&v(e,y(c.id.client,c.id.clock+n)),n-=c.length);for(;s>0&&c!==null;)c.deleted||(s<c.length&&v(e,y(c.id.client,c.id.clock+s)),c.delete(e),s-=c.length),c=c.right;if(s>0)throw Nr();t._searchMarker&&Kt(t._searchMarker,r,-i+s)},_e=(e,t,n)=>{const s=t._map.get(n);s!==void 0&&s.delete(e)},Vn=(e,t,n,s)=>{const r=t._map.get(n)||null,i=e.doc,o=i.clientID;let c;if(s==null)c=new ft([s]);else switch(s.constructor){case Number:case Object:case Boolean:case Array:case String:case Date:case BigInt:c=new ft([s]);break;case Uint8Array:c=new ee(s);break;case mt:c=new ne(s);break;default:if(s instanceof I)c=new tt(s);else throw new Error("Unexpected content type")}new S(y(o,A(i.store,o)),r,r&&r.lastId,null,null,t,n,c).integrate(e,0)},jn=(e,t)=>{e.doc??M();const n=e._map.get(t);return n!==void 0&&!n.deleted?n.content.getContent()[n.length-1]:void 0},vr=e=>{const t={};return e.doc??M(),e._map.forEach((n,s)=>{n.deleted||(t[s]=n.content.getContent()[n.length-1])}),t},Rr=(e,t)=>{e.doc??M();const n=e._map.get(t);return n!==void 0&&!n.deleted},Qc=(e,t)=>{const n={};return e._map.forEach((s,r)=>{let i=s;for(;i!==null&&(!t.sv.has(i.id.client)||i.id.clock>=(t.sv.get(i.id.client)||0));)i=i.left;i!==null&&kt(i,t)&&(n[r]=i.content.getContent()[i.length-1])}),n},ie=e=>(e.doc??M(),fc(e._map.entries(),t=>!t[1].deleted));class Zc extends Fe{}class At extends I{constructor(){super(),this._prelimContent=[],this._searchMarker=[]}static from(t){const n=new At;return n.push(t),n}_integrate(t,n){super._integrate(t,n),this.insert(0,this._prelimContent),this._prelimContent=null}_copy(){return new At}clone(){const t=new At;return t.insert(0,this.toArray().map(n=>n instanceof I?n.clone():n)),t}get length(){return this.doc??M(),this._length}_callObserver(t,n){super._callObserver(t,n),je(this,t,new Zc(this,t))}insert(t,n){this.doc!==null?_(this.doc,s=>{Mr(s,this,t,n)}):this._prelimContent.splice(t,0,...n)}push(t){this.doc!==null?_(this.doc,n=>{qc(n,this,t)}):this._prelimContent.push(...t)}unshift(t){this.insert(0,t)}delete(t,n=1){this.doc!==null?_(this.doc,s=>{Ur(s,this,t,n)}):this._prelimContent.splice(t,n)}get(t){return Or(this,t)}toArray(){return Ir(this)}slice(t=0,n=this.length){return xr(this,t,n)}toJSON(){return this.map(t=>t instanceof I?t.toJSON():t)}map(t){return Lr(this,t)}forEach(t){Wt(this,t)}[Symbol.iterator](){return Xc(this)}_write(t){t.writeTypeRef(El)}}const tl=e=>new At;class el extends Fe{constructor(t,n,s){super(t,n),this.keysChanged=s}}class Mt extends I{constructor(t){super(),this._prelimContent=null,t===void 0?this._prelimContent=new Map:this._prelimContent=new Map(t)}_integrate(t,n){super._integrate(t,n),this._prelimContent.forEach((s,r)=>{this.set(r,s)}),this._prelimContent=null}_copy(){return new Mt}clone(){const t=new Mt;return this.forEach((n,s)=>{t.set(s,n instanceof I?n.clone():n)}),t}_callObserver(t,n){je(this,t,new el(this,t,n))}toJSON(){this.doc??M();const t={};return this._map.forEach((n,s)=>{if(!n.deleted){const r=n.content.getContent()[n.length-1];t[s]=r instanceof I?r.toJSON():r}}),t}get size(){return[...ie(this)].length}keys(){return We(ie(this),t=>t[0])}values(){return We(ie(this),t=>t[1].content.getContent()[t[1].length-1])}entries(){return We(ie(this),t=>[t[0],t[1].content.getContent()[t[1].length-1]])}forEach(t){this.doc??M(),this._map.forEach((n,s)=>{n.deleted||t(n.content.getContent()[n.length-1],s,this)})}[Symbol.iterator](){return this.entries()}delete(t){this.doc!==null?_(this.doc,n=>{_e(n,this,t)}):this._prelimContent.delete(t)}set(t,n){return this.doc!==null?_(this.doc,s=>{Vn(s,this,t,n)}):this._prelimContent.set(t,n),n}get(t){return jn(this,t)}has(t){return Rr(this,t)}clear(){this.doc!==null?_(this.doc,t=>{this.forEach(function(n,s,r){_e(t,r,s)})}):this._prelimContent.clear()}_write(t){t.writeTypeRef(Dl)}}const nl=e=>new Mt,nt=(e,t)=>e===t||typeof e=="object"&&typeof t=="object"&&e&&t&&oo(e,t);class un{constructor(t,n,s,r){this.left=t,this.right=n,this.index=s,this.currentAttributes=r}forward(){this.right===null&&V(),this.right.content.constructor===T?this.right.deleted||Bt(this.currentAttributes,this.right.content):this.right.deleted||(this.index+=this.right.length),this.left=this.right,this.right=this.right.right}}const ks=(e,t,n)=>{for(;t.right!==null&&n>0;)t.right.content.constructor===T?t.right.deleted||Bt(t.currentAttributes,t.right.content):t.right.deleted||(n<t.right.length&&v(e,y(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},oe=(e,t,n,s)=>{const r=new Map,i=s?Ve(t,n):null;if(i){const o=new un(i.p.left,i.p,i.index,r);return ks(e,o,n-i.index)}else{const o=new un(null,t._start,0,r);return ks(e,o,n)}},$r=(e,t,n,s)=>{for(;n.right!==null&&(n.right.deleted===!0||n.right.content.constructor===T&&nt(s.get(n.right.content.key),n.right.content.value));)n.right.deleted||s.delete(n.right.content.key),n.forward();const r=e.doc,i=r.clientID;s.forEach((o,c)=>{const l=n.left,a=n.right,h=new S(y(i,A(r.store,i)),l,l&&l.lastId,a,a&&a.id,t,null,new T(c,o));h.integrate(e,0),n.right=h,n.forward()})},Bt=(e,t)=>{const{key:n,value:s}=t;s===null?e.delete(n):e.set(n,s)},Br=(e,t)=>{for(;e.right!==null;){if(!(e.right.deleted||e.right.content.constructor===T&&nt(t[e.right.content.key]??null,e.right.content.value)))break;e.forward()}},Fr=(e,t,n,s)=>{const r=e.doc,i=r.clientID,o=new Map;for(const c in s){const l=s[c],a=n.currentAttributes.get(c)??null;if(!nt(a,l)){o.set(c,a);const{left:h,right:u}=n;n.right=new S(y(i,A(r.store,i)),h,h&&h.lastId,u,u&&u.id,t,null,new T(c,l)),n.right.integrate(e,0),n.forward()}}return o},Xe=(e,t,n,s,r)=>{n.currentAttributes.forEach((d,f)=>{r[f]===void 0&&(r[f]=null)});const i=e.doc,o=i.clientID;Br(n,r);const c=Fr(e,t,n,r),l=s.constructor===String?new G(s):s instanceof I?new tt(s):new yt(s);let{left:a,right:h,index:u}=n;t._searchMarker&&Kt(t._searchMarker,n.index,l.getLength()),h=new S(y(o,A(i.store,o)),a,a&&a.lastId,h,h&&h.id,t,null,l),h.integrate(e,0),n.right=h,n.index=u,n.forward(),$r(e,t,n,c)},_s=(e,t,n,s,r)=>{const i=e.doc,o=i.clientID;Br(n,r);const c=Fr(e,t,n,r);t:for(;n.right!==null&&(s>0||c.size>0&&(n.right.deleted||n.right.content.constructor===T));){if(!n.right.deleted)switch(n.right.content.constructor){case T:{const{key:l,value:a}=n.right.content,h=r[l];if(h!==void 0){if(nt(h,a))c.delete(l);else{if(s===0)break t;c.set(l,a)}n.right.delete(e)}else n.currentAttributes.set(l,a);break}default:s<n.right.length&&v(e,y(n.right.id.client,n.right.id.clock+s)),s-=n.right.length;break}n.forward()}if(s>0){let l="";for(;s>0;s--)l+=`
|
|
4
4
|
`;n.right=new S(y(o,A(i.store,o)),n.left,n.left&&n.left.lastId,n.right,n.right&&n.right.id,t,null,new G(l)),n.right.integrate(e,0),n.forward()}$r(e,t,n,c)},Vr=(e,t,n,s,r)=>{let i=t;const o=R();for(;i&&(!i.countable||i.deleted);){if(!i.deleted&&i.content.constructor===T){const a=i.content;o.set(a.key,a)}i=i.right}let c=0,l=!1;for(;t!==i;){if(n===t&&(l=!0),!t.deleted){const a=t.content;if(a.constructor===T){const{key:h,value:u}=a,d=s.get(h)??null;(o.get(h)!==a||d===u)&&(t.delete(e),c++,!l&&(r.get(h)??null)===u&&d!==u&&(d===null?r.delete(h):r.set(h,d))),!l&&!t.deleted&&Bt(r,a)}}t=t.right}return c},sl=(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===T){const s=t.content.key;n.has(s)?t.delete(e):n.add(s)}t=t.left}},rl=e=>{let t=0;return _(e.doc,n=>{let s=e._start,r=e._start,i=R();const o=en(i);for(;r;)r.deleted===!1&&(r.content.constructor===T?Bt(o,r.content):(t+=Vr(n,s,r,i,o),i=en(o),s=r)),r=r.right}),t},il=e=>{const t=new Set,n=e.doc;for(const[s,r]of e.afterState.entries()){const i=e.beforeState.get(s)||0;r!==i&&Cr(e,n.store.clients.get(s),i,r,o=>{!o.deleted&&o.content.constructor===T&&o.constructor!==B&&t.add(o.parent)})}_(n,s=>{Ot(e,e.deleteSet,r=>{if(r instanceof B||!r.parent._hasFormatting||t.has(r.parent))return;const i=r.parent;r.content.constructor===T?t.add(i):sl(s,r)});for(const r of t)rl(r)})},Ss=(e,t,n)=>{const s=n,r=en(t.currentAttributes),i=t.right;for(;n>0&&t.right!==null;){if(t.right.deleted===!1)switch(t.right.content.constructor){case tt:case yt:case G:n<t.right.length&&v(e,y(t.right.id.client,t.right.id.clock+n)),n-=t.right.length,t.right.delete(e);break}t.forward()}i&&Vr(e,i,t.right,r,t.currentAttributes);const o=(t.left||t.right).parent;return o._searchMarker&&Kt(o._searchMarker,t.index,-s+n),t};class ol extends Fe{constructor(t,n,s){super(t,n),this.childListChanged=!1,this.keysChanged=new Set,s.forEach(r=>{r===null?this.childListChanged=!0:this.keysChanged.add(r)})}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,n=[];_(t,s=>{const r=new Map,i=new Map;let o=this.target._start,c=null;const l={};let a="",h=0,u=0;const d=()=>{if(c!==null){let f=null;switch(c){case"delete":u>0&&(f={delete:u}),u=0;break;case"insert":(typeof a=="object"||a.length>0)&&(f={insert:a},r.size>0&&(f.attributes={},r.forEach((g,p)=>{g!==null&&(f.attributes[p]=g)}))),a="";break;case"retain":h>0&&(f={retain:h},io(l)||(f.attributes=eo({},l))),h=0;break}f&&n.push(f),c=null}};for(;o!==null;){switch(o.content.constructor){case tt:case yt:this.adds(o)?this.deletes(o)||(d(),c="insert",a=o.content.getContent()[0],d()):this.deletes(o)?(c!=="delete"&&(d(),c="delete"),u+=1):o.deleted||(c!=="retain"&&(d(),c="retain"),h+=1);break;case G:this.adds(o)?this.deletes(o)||(c!=="insert"&&(d(),c="insert"),a+=o.content.str):this.deletes(o)?(c!=="delete"&&(d(),c="delete"),u+=o.length):o.deleted||(c!=="retain"&&(d(),c="retain"),h+=o.length);break;case T:{const{key:f,value:g}=o.content;if(this.adds(o)){if(!this.deletes(o)){const p=r.get(f)??null;nt(p,g)?g!==null&&o.delete(s):(c==="retain"&&d(),nt(g,i.get(f)??null)?delete l[f]:l[f]=g)}}else if(this.deletes(o)){i.set(f,g);const p=r.get(f)??null;nt(p,g)||(c==="retain"&&d(),l[f]=p)}else if(!o.deleted){i.set(f,g);const p=l[f];p!==void 0&&(nt(p,g)?p!==null&&o.delete(s):(c==="retain"&&d(),g===null?delete l[f]:l[f]=g))}o.deleted||(c==="insert"&&d(),Bt(r,o.content));break}}o=o.right}for(d();n.length>0;){const f=n[n.length-1];if(f.retain!==void 0&&f.attributes===void 0)n.pop();else break}}),this._delta=n}return this._delta}}class Ut extends I{constructor(t){super(),this._pending=t!==void 0?[()=>this.insert(0,t)]:[],this._searchMarker=[],this._hasFormatting=!1}get length(){return this.doc??M(),this._length}_integrate(t,n){super._integrate(t,n);try{this._pending.forEach(s=>s())}catch(s){console.error(s)}this._pending=null}_copy(){return new Ut}clone(){const t=new Ut;return t.applyDelta(this.toDelta()),t}_callObserver(t,n){super._callObserver(t,n);const s=new ol(this,t,n);je(this,t,s),!t.local&&this._hasFormatting&&(t._needFormattingCleanup=!0)}toString(){this.doc??M();let t="",n=this._start;for(;n!==null;)!n.deleted&&n.countable&&n.content.constructor===G&&(t+=n.content.str),n=n.right;return t}toJSON(){return this.toString()}applyDelta(t,{sanitize:n=!0}={}){this.doc!==null?_(this.doc,s=>{const r=new un(null,this._start,0,new Map);for(let i=0;i<t.length;i++){const o=t[i];if(o.insert!==void 0){const c=!n&&typeof o.insert=="string"&&i===t.length-1&&r.right===null&&o.insert.slice(-1)===`
|
|
5
5
|
`?o.insert.slice(0,-1):o.insert;(typeof c!="string"||c.length>0)&&Xe(s,this,r,c,o.attributes||{})}else o.retain!==void 0?_s(s,this,r,o.retain,o.attributes||{}):o.delete!==void 0&&Ss(s,r,o.delete)}}):this._pending.push(()=>this.applyDelta(t))}toDelta(t,n,s){this.doc??M();const r=[],i=new Map,o=this.doc;let c="",l=this._start;function a(){if(c.length>0){const u={};let d=!1;i.forEach((g,p)=>{d=!0,u[p]=g});const f={insert:c};d&&(f.attributes=u),r.push(f),c=""}}const h=()=>{for(;l!==null;){if(kt(l,t)||n!==void 0&&kt(l,n))switch(l.content.constructor){case G:{const u=i.get("ychange");t!==void 0&&!kt(l,t)?(u===void 0||u.user!==l.id.client||u.type!=="removed")&&(a(),i.set("ychange",s?s("removed",l.id):{type:"removed"})):n!==void 0&&!kt(l,n)?(u===void 0||u.user!==l.id.client||u.type!=="added")&&(a(),i.set("ychange",s?s("added",l.id):{type:"added"})):u!==void 0&&(a(),i.delete("ychange")),c+=l.content.str;break}case tt:case yt:{a();const u={insert:l.content.getContent()[0]};if(i.size>0){const d={};u.attributes=d,i.forEach((f,g)=>{d[g]=f})}r.push(u);break}case T:kt(l,t)&&(a(),Bt(i,l.content));break}l=l.right}a()};return t||n?_(o,u=>{t&&an(u,t),n&&an(u,n),h()},"cleanup"):h(),r}insert(t,n,s){if(n.length<=0)return;const r=this.doc;r!==null?_(r,i=>{const o=oe(i,this,t,!s);s||(s={},o.currentAttributes.forEach((c,l)=>{s[l]=c})),Xe(i,this,o,n,s)}):this._pending.push(()=>this.insert(t,n,s))}insertEmbed(t,n,s){const r=this.doc;r!==null?_(r,i=>{const o=oe(i,this,t,!s);Xe(i,this,o,n,s||{})}):this._pending.push(()=>this.insertEmbed(t,n,s||{}))}delete(t,n){if(n===0)return;const s=this.doc;s!==null?_(s,r=>{Ss(r,oe(r,this,t,!0),n)}):this._pending.push(()=>this.delete(t,n))}format(t,n,s){if(n===0)return;const r=this.doc;r!==null?_(r,i=>{const o=oe(i,this,t,!1);o.right!==null&&_s(i,this,o,n,s)}):this._pending.push(()=>this.format(t,n,s))}removeAttribute(t){this.doc!==null?_(this.doc,n=>{_e(n,this,t)}):this._pending.push(()=>this.removeAttribute(t))}setAttribute(t,n){this.doc!==null?_(this.doc,s=>{Vn(s,this,t,n)}):this._pending.push(()=>this.setAttribute(t,n))}getAttribute(t){return jn(this,t)}getAttributes(){return vr(this)}_write(t){t.writeTypeRef(Al)}}const cl=e=>new Ut;class qe{constructor(t,n=()=>!0){this._filter=n,this._root=t,this._currentNode=t._start,this._firstCall=!0,t.doc??M()}[Symbol.iterator](){return this}next(){let t=this._currentNode,n=t&&t.content&&t.content.type;if(t!==null&&(!this._firstCall||t.deleted||!this._filter(n)))do if(n=t.content.type,!t.deleted&&(n.constructor===q||n.constructor===dt)&&n._start!==null)t=n._start;else for(;t!==null;){const s=t.next;if(s!==null){t=s;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 dt extends I{constructor(){super(),this._prelimContent=[]}get firstChild(){const t=this._first;return t?t.content.getContent()[0]:null}_integrate(t,n){super._integrate(t,n),this.insert(0,this._prelimContent),this._prelimContent=null}_copy(){return new dt}clone(){const t=new dt;return t.insert(0,this.toArray().map(n=>n instanceof I?n.clone():n)),t}get length(){return this.doc??M(),this._prelimContent===null?this._length:this._prelimContent.length}createTreeWalker(t){return new qe(this,t)}querySelector(t){t=t.toUpperCase();const s=new qe(this,r=>r.nodeName&&r.nodeName.toUpperCase()===t).next();return s.done?null:s.value}querySelectorAll(t){return t=t.toUpperCase(),X(new qe(this,n=>n.nodeName&&n.nodeName.toUpperCase()===t))}_callObserver(t,n){je(this,t,new hl(this,n,t))}toString(){return Lr(this,t=>t.toString()).join("")}toJSON(){return this.toString()}toDOM(t=document,n={},s){const r=t.createDocumentFragment();return s!==void 0&&s._createAssociation(r,this),Wt(this,i=>{r.insertBefore(i.toDOM(t,n,s),null)}),r}insert(t,n){this.doc!==null?_(this.doc,s=>{Mr(s,this,t,n)}):this._prelimContent.splice(t,0,...n)}insertAfter(t,n){if(this.doc!==null)_(this.doc,s=>{const r=t&&t instanceof I?t._item:t;ke(s,this,r,n)});else{const s=this._prelimContent,r=t===null?0:s.findIndex(i=>i===t)+1;if(r===0&&t!==null)throw Y("Reference item not found");s.splice(r,0,...n)}}delete(t,n=1){this.doc!==null?_(this.doc,s=>{Ur(s,this,t,n)}):this._prelimContent.splice(t,n)}toArray(){return Ir(this)}push(t){this.insert(this.length,t)}unshift(t){this.insert(0,t)}get(t){return Or(this,t)}slice(t=0,n=this.length){return xr(this,t,n)}forEach(t){Wt(this,t)}_write(t){t.writeTypeRef(xl)}}const ll=e=>new dt;class q extends dt{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,n){super._integrate(t,n),this._prelimAttrs.forEach((s,r)=>{this.setAttribute(r,s)}),this._prelimAttrs=null}_copy(){return new q(this.nodeName)}clone(){const t=new q(this.nodeName),n=this.getAttributes();return so(n,(s,r)=>{t.setAttribute(r,s)}),t.insert(0,this.toArray().map(s=>s instanceof I?s.clone():s)),t}toString(){const t=this.getAttributes(),n=[],s=[];for(const c in t)s.push(c);s.sort();const r=s.length;for(let c=0;c<r;c++){const l=s[c];n.push(l+'="'+t[l]+'"')}const i=this.nodeName.toLocaleLowerCase(),o=n.length>0?" "+n.join(" "):"";return`<${i}${o}>${super.toString()}</${i}>`}removeAttribute(t){this.doc!==null?_(this.doc,n=>{_e(n,this,t)}):this._prelimAttrs.delete(t)}setAttribute(t,n){this.doc!==null?_(this.doc,s=>{Vn(s,this,t,n)}):this._prelimAttrs.set(t,n)}getAttribute(t){return jn(this,t)}hasAttribute(t){return Rr(this,t)}getAttributes(t){return t?Qc(this,t):vr(this)}toDOM(t=document,n={},s){const r=t.createElement(this.nodeName),i=this.getAttributes();for(const o in i){const c=i[o];typeof c=="string"&&r.setAttribute(o,c)}return Wt(this,o=>{r.appendChild(o.toDOM(t,n,s))}),s!==void 0&&s._createAssociation(r,this),r}_write(t){t.writeTypeRef(Tl),t.writeKey(this.nodeName)}}const al=e=>new q(e.readKey());class hl extends Fe{constructor(t,n,s){super(t,s),this.childListChanged=!1,this.attributesChanged=new Set,n.forEach(r=>{r===null?this.childListChanged=!0:this.attributesChanged.add(r)})}}class Se extends Mt{constructor(t){super(),this.hookName=t}_copy(){return new Se(this.hookName)}clone(){const t=new Se(this.hookName);return this.forEach((n,s)=>{t.set(s,n)}),t}toDOM(t=document,n={},s){const r=n[this.hookName];let i;return r!==void 0?i=r.createDom(this):i=document.createElement(this.hookName),i.setAttribute("data-yjs-hook",this.hookName),s!==void 0&&s._createAssociation(i,this),i}_write(t){t.writeTypeRef(Il),t.writeKey(this.hookName)}}const ul=e=>new Se(e.readKey());class Q extends Ut{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 Q}clone(){const t=new Q;return t.applyDelta(this.toDelta()),t}toDOM(t=document,n,s){const r=t.createTextNode(this.toString());return s!==void 0&&s._createAssociation(r,this),r}toString(){return this.toDelta().map(t=>{const n=[];for(const r in t.attributes){const i=[];for(const o in t.attributes[r])i.push({key:o,value:t.attributes[r][o]});i.sort((o,c)=>o.key<c.key?-1:1),n.push({nodeName:r,attrs:i})}n.sort((r,i)=>r.nodeName<i.nodeName?-1:1);let s="";for(let r=0;r<n.length;r++){const i=n[r];s+=`<${i.nodeName}`;for(let o=0;o<i.attrs.length;o++){const c=i.attrs[o];s+=` ${c.key}="${c.value}"`}s+=">"}s+=t.insert;for(let r=n.length-1;r>=0;r--)s+=`</${n[r].nodeName}>`;return s}).join("")}toJSON(){return this.toString()}_write(t){t.writeTypeRef(Ll)}}const dl=e=>new Q;class Hn{constructor(t,n){this.id=t,this.length=n}get deleted(){throw j()}mergeWith(t){return!1}write(t,n,s){throw j()}integrate(t,n){throw j()}}const fl=0;class B extends Hn{get deleted(){return!0}delete(){}mergeWith(t){return this.constructor!==t.constructor?!1:(this.length+=t.length,!0)}integrate(t,n){n>0&&(this.id.clock+=n,this.length-=n),Sr(t.doc.store,this)}write(t,n){t.writeInfo(fl),t.writeLen(this.length-n)}getMissing(t,n){return null}}class ee{constructor(t){this.content=t}getLength(){return 1}getContent(){return[this.content]}isCountable(){return!0}copy(){return new ee(this.content)}splice(t){throw j()}mergeWith(t){return!1}integrate(t,n){}delete(t){}gc(t){}write(t,n){t.writeBuf(this.content)}getRef(){return 3}}const gl=e=>new ee(e.readBuf());class Xt{constructor(t){this.len=t}getLength(){return this.len}getContent(){return[]}isCountable(){return!1}copy(){return new Xt(this.len)}splice(t){const n=new Xt(this.len-t);return this.len=t,n}mergeWith(t){return this.len+=t.len,!0}integrate(t,n){Jt(t.deleteSet,n.id.client,n.id.clock,this.len),n.markDeleted()}delete(t){}gc(t){}write(t,n){t.writeLen(this.len-n)}getRef(){return 1}}const pl=e=>new Xt(e.readLen()),jr=(e,t)=>new mt({guid:e,...t,shouldLoad:t.shouldLoad||t.autoLoad||!1});class ne{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 n={};this.opts=n,t.gc||(n.gc=!1),t.autoLoad&&(n.autoLoad=!0),t.meta!==null&&(n.meta=t.meta)}getLength(){return 1}getContent(){return[this.doc]}isCountable(){return!0}copy(){return new ne(jr(this.doc.guid,this.opts))}splice(t){throw j()}mergeWith(t){return!1}integrate(t,n){this.doc._item=n,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,n){t.writeString(this.doc.guid),t.writeAny(this.opts)}getRef(){return 9}}const wl=e=>new ne(jr(e.readString(),e.readAny()));class yt{constructor(t){this.embed=t}getLength(){return 1}getContent(){return[this.embed]}isCountable(){return!0}copy(){return new yt(this.embed)}splice(t){throw j()}mergeWith(t){return!1}integrate(t,n){}delete(t){}gc(t){}write(t,n){t.writeJSON(this.embed)}getRef(){return 5}}const ml=e=>new yt(e.readJSON());class T{constructor(t,n){this.key=t,this.value=n}getLength(){return 1}getContent(){return[]}isCountable(){return!1}copy(){return new T(this.key,this.value)}splice(t){throw j()}mergeWith(t){return!1}integrate(t,n){const s=n.parent;s._searchMarker=null,s._hasFormatting=!0}delete(t){}gc(t){}write(t,n){t.writeKey(this.key),t.writeJSON(this.value)}getRef(){return 6}}const yl=e=>new T(e.readKey(),e.readJSON());class Ce{constructor(t){this.arr=t}getLength(){return this.arr.length}getContent(){return this.arr}isCountable(){return!0}copy(){return new Ce(this.arr)}splice(t){const n=new Ce(this.arr.slice(t));return this.arr=this.arr.slice(0,t),n}mergeWith(t){return this.arr=this.arr.concat(t.arr),!0}integrate(t,n){}delete(t){}gc(t){}write(t,n){const s=this.arr.length;t.writeLen(s-n);for(let r=n;r<s;r++){const i=this.arr[r];t.writeString(i===void 0?"undefined":JSON.stringify(i))}}getRef(){return 2}}const bl=e=>{const t=e.readLen(),n=[];for(let s=0;s<t;s++){const r=e.readString();r==="undefined"?n.push(void 0):n.push(JSON.parse(r))}return new Ce(n)},kl=pe("node_env")==="development";class ft{constructor(t){this.arr=t,kl&&Fs(t)}getLength(){return this.arr.length}getContent(){return this.arr}isCountable(){return!0}copy(){return new ft(this.arr)}splice(t){const n=new ft(this.arr.slice(t));return this.arr=this.arr.slice(0,t),n}mergeWith(t){return this.arr=this.arr.concat(t.arr),!0}integrate(t,n){}delete(t){}gc(t){}write(t,n){const s=this.arr.length;t.writeLen(s-n);for(let r=n;r<s;r++){const i=this.arr[r];t.writeAny(i)}}getRef(){return 8}}const _l=e=>{const t=e.readLen(),n=[];for(let s=0;s<t;s++)n.push(e.readAny());return new ft(n)};class G{constructor(t){this.str=t}getLength(){return this.str.length}getContent(){return this.str.split("")}isCountable(){return!0}copy(){return new G(this.str)}splice(t){const n=new G(this.str.slice(t));this.str=this.str.slice(0,t);const s=this.str.charCodeAt(t-1);return s>=55296&&s<=56319&&(this.str=this.str.slice(0,t-1)+"�",n.str="�"+n.str.slice(1)),n}mergeWith(t){return this.str+=t.str,!0}integrate(t,n){}delete(t){}gc(t){}write(t,n){t.writeString(n===0?this.str:this.str.slice(n))}getRef(){return 4}}const Sl=e=>new G(e.readString()),Cl=[tl,nl,cl,al,ll,ul,dl],El=0,Dl=1,Al=2,Tl=3,xl=4,Il=5,Ll=6;class tt{constructor(t){this.type=t}getLength(){return 1}getContent(){return[this.type]}isCountable(){return!0}copy(){return new tt(this.type._copy())}splice(t){throw j()}mergeWith(t){return!1}integrate(t,n){this.type._integrate(t.doc,n)}delete(t){let n=this.type._start;for(;n!==null;)n.deleted?n.id.clock<(t.beforeState.get(n.id.client)||0)&&t._mergeStructs.push(n):n.delete(t),n=n.right;this.type._map.forEach(s=>{s.deleted?s.id.clock<(t.beforeState.get(s.id.client)||0)&&t._mergeStructs.push(s):s.delete(t)}),t.changed.delete(this.type)}gc(t){let n=this.type._start;for(;n!==null;)n.gc(t,!0),n=n.right;this.type._start=null,this.type._map.forEach(s=>{for(;s!==null;)s.gc(t,!0),s=s.left}),this.type._map=new Map}write(t,n){this.type._write(t)}getRef(){return 7}}const Ol=e=>new tt(Cl[e.readTypeRef()](e)),Nl=(e,t)=>{let n=t,s=0,r;do s>0&&(n=y(n.client,n.clock+s)),r=he(e,n),s=n.clock-r.id.clock,n=r.redone;while(n!==null&&r instanceof S);return{item:r,diff:s}},zn=(e,t)=>{for(;e!==null&&e.keep!==t;)e.keep=t,e=e.parent._item},Ee=(e,t,n)=>{const{client:s,clock:r}=t.id,i=new S(y(s,r+n),t,y(s,r+n-1),t.right,t.rightOrigin,t.parent,t.parentSub,t.content.splice(n));return t.deleted&&i.markDeleted(),t.keep&&(i.keep=!0),t.redone!==null&&(i.redone=y(t.redone.client,t.redone.clock+n)),t.right=i,i.right!==null&&(i.right.left=i),e._mergeStructs.push(i),i.parentSub!==null&&i.right===null&&i.parent._map.set(i.parentSub,i),t.length=n,i},Cs=(e,t)=>wn(e,n=>Zt(n.deletions,t)),Hr=(e,t,n,s,r,i)=>{const o=e.doc,c=o.store,l=o.clientID,a=t.redone;if(a!==null)return v(e,a);let h=t.parent._item,u=null,d;if(h!==null&&h.deleted===!0){if(h.redone===null&&(!n.has(h)||Hr(e,h,n,s,r,i)===null))return null;for(;h.redone!==null;)h=v(e,h.redone)}const f=h===null?t.parent:h.content.type;if(t.parentSub===null){for(u=t.left,d=t;u!==null;){let k=u;for(;k!==null&&k.parent._item!==h;)k=k.redone===null?null:v(e,k.redone);if(k!==null&&k.parent._item===h){u=k;break}u=u.left}for(;d!==null;){let k=d;for(;k!==null&&k.parent._item!==h;)k=k.redone===null?null:v(e,k.redone);if(k!==null&&k.parent._item===h){d=k;break}d=d.right}}else{if(d=null,t.right&&!r){for(u=t;u!==null&&u.right!==null&&(u.right.redone||Zt(s,u.right.id)||Cs(i.undoStack,u.right.id)||Cs(i.redoStack,u.right.id));)for(u=u.right;u.redone;)u=v(e,u.redone);if(u&&u.right!==null)return null}else u=f._map.get(t.parentSub)||null;u!==null&&u.parent._item!==h&&(u=f._map.get(t.parentSub)||null)}const g=A(c,l),p=y(l,g),b=new S(p,u,u&&u.lastId,d,d&&d.id,f,t.parentSub,t.content.copy());return t.redone=p,zn(b,!0),b.integrate(e,0),b};class S extends Hn{constructor(t,n,s,r,i,o,c,l){super(t,l.getLength()),this.origin=s,this.left=n,this.right=r,this.rightOrigin=i,this.parent=o,this.parentSub=c,this.redone=null,this.content=l,this.info=this.content.isCountable()?Qn:0}set marker(t){(this.info&Ye)>0!==t&&(this.info^=Ye)}get marker(){return(this.info&Ye)>0}get keep(){return(this.info&qn)>0}set keep(t){this.keep!==t&&(this.info^=qn)}get countable(){return(this.info&Qn)>0}get deleted(){return(this.info&ze)>0}set deleted(t){this.deleted!==t&&(this.info^=ze)}markDeleted(){this.info|=ze}getMissing(t,n){if(this.origin&&this.origin.client!==this.id.client&&this.origin.clock>=A(n,this.origin.client))return this.origin.client;if(this.rightOrigin&&this.rightOrigin.client!==this.id.client&&this.rightOrigin.clock>=A(n,this.rightOrigin.client))return this.rightOrigin.client;if(this.parent&&this.parent.constructor===Dt&&this.id.client!==this.parent.client&&this.parent.clock>=A(n,this.parent.client))return this.parent.client;if(this.origin&&(this.left=gs(t,n,this.origin),this.origin=this.left.lastId),this.rightOrigin&&(this.right=v(t,this.rightOrigin),this.rightOrigin=this.right.id),this.left&&this.left.constructor===B||this.right&&this.right.constructor===B)this.parent=null;else if(!this.parent)this.left&&this.left.constructor===S?(this.parent=this.left.parent,this.parentSub=this.left.parentSub):this.right&&this.right.constructor===S&&(this.parent=this.right.parent,this.parentSub=this.right.parentSub);else if(this.parent.constructor===Dt){const s=he(n,this.parent);s.constructor===B?this.parent=null:this.parent=s.content.type}return null}integrate(t,n){if(n>0&&(this.id.clock+=n,this.left=gs(t,t.doc.store,y(this.id.client,this.id.clock-1)),this.origin=this.left.lastId,this.content=this.content.splice(n),this.length-=n),this.parent){if(!this.left&&(!this.right||this.right.left!==null)||this.left&&this.left.right!==this.right){let s=this.left,r;if(s!==null)r=s.right;else if(this.parentSub!==null)for(r=this.parent._map.get(this.parentSub)||null;r!==null&&r.left!==null;)r=r.left;else r=this.parent._start;const i=new Set,o=new Set;for(;r!==null&&r!==this.right;){if(o.add(r),i.add(r),re(this.origin,r.origin)){if(r.id.client<this.id.client)s=r,i.clear();else if(re(this.rightOrigin,r.rightOrigin))break}else if(r.origin!==null&&o.has(he(t.doc.store,r.origin)))i.has(he(t.doc.store,r.origin))||(s=r,i.clear());else break;r=r.right}this.left=s}if(this.left!==null){const s=this.left.right;this.right=s,this.left.right=this}else{let s;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,this.parent._start=this;this.right=s}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),Sr(t.doc.store,this),this.content.integrate(t,this),ws(t,this.parent,this.parentSub),(this.parent._item!==null&&this.parent._item.deleted||this.parentSub!==null&&this.right!==null)&&this.delete(t)}else new B(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:y(this.id.client,this.id.clock+this.length-1)}mergeWith(t){if(this.constructor===t.constructor&&re(t.origin,this.lastId)&&this.right===t&&re(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 n=this.parent._searchMarker;return n&&n.forEach(s=>{s.p===t&&(s.p=this,!this.deleted&&this.countable&&(s.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 n=this.parent;this.countable&&this.parentSub===null&&(n._length-=this.length),this.markDeleted(),Jt(t.deleteSet,this.id.client,this.id.clock,this.length),ws(t,n,this.parentSub),this.content.delete(t)}}gc(t,n){if(!this.deleted)throw V();this.content.gc(t),n?Uc(t,this,new B(this.id,this.length)):this.content=new Xt(this.length)}write(t,n){const s=n>0?y(this.id.client,this.id.clock+n-1):this.origin,r=this.rightOrigin,i=this.parentSub,o=this.content.getRef()&Te|(s===null?0:$)|(r===null?0:W)|(i===null?0:jt);if(t.writeInfo(o),s!==null&&t.writeLeftID(s),r!==null&&t.writeRightID(r),s===null&&r===null){const c=this.parent;if(c._item!==void 0){const l=c._item;if(l===null){const a=Nc(c);t.writeParentInfo(!0),t.writeString(a)}else t.writeParentInfo(!1),t.writeLeftID(l.id)}else c.constructor===String?(t.writeParentInfo(!0),t.writeString(c)):c.constructor===Dt?(t.writeParentInfo(!1),t.writeLeftID(c)):V();i!==null&&t.writeString(i)}this.content.write(t,n)}}const zr=(e,t)=>Ml[t&Te](e),Ml=[()=>{V()},pl,bl,gl,Sl,ml,yl,Ol,_l,wl,()=>{V()}],Ul=10;class F extends Hn{get deleted(){return!0}delete(){}mergeWith(t){return this.constructor!==t.constructor?!1:(this.length+=t.length,!0)}integrate(t,n){V()}write(t,n){t.writeInfo(Ul),w(t.restEncoder,this.length-n)}getMissing(t,n){return null}}const Yr=typeof globalThis<"u"?globalThis:typeof window<"u"?window:typeof global<"u"?global:{},Pr="__ $YJS$ __";Yr[Pr]===!0&&console.error("Yjs was already imported. This breaks constructor checks and will lead to issues! - https://github.com/yjs/yjs/issues/438");Yr[Pr]=!0;const Gr=new Map;class vl{constructor(t){this.room=t,this.onmessage=null,this._onChange=n=>n.key===t&&this.onmessage!==null&&this.onmessage({data:_o(n.newValue||"")}),Qi(this._onChange)}postMessage(t){$s.setItem(this.room,ko(po(t)))}close(){Zi(this._onChange)}}const Rl=typeof BroadcastChannel>"u"?vl:BroadcastChannel,Yn=e=>J(Gr,e,()=>{const t=rt(),n=new Rl(e);return n.onmessage=s=>t.forEach(r=>r(s.data,"broadcastchannel")),{bc:n,subs:t}}),$l=(e,t)=>(Yn(e).subs.add(t),t),Bl=(e,t)=>{const n=Yn(e),s=n.subs.delete(t);return s&&n.subs.size===0&&(n.bc.close(),Gr.delete(e)),s},_t=(e,t,n=null)=>{const s=Yn(e);s.bc.postMessage(t),s.subs.forEach(r=>r(t,n))},Jr=0,Pn=1,Kr=2,dn=(e,t)=>{w(e,Jr);const n=Lc(t);E(e,n)},Wr=(e,t,n)=>{w(e,Pn),E(e,Ac(t,n))},Fl=(e,t,n)=>Wr(t,n,O(e)),Xr=(e,t,n,s)=>{try{Cc(t,O(e),n)}catch(r){s?.(r),console.error("Caught error while handling a Yjs update",r)}},Vl=(e,t)=>{w(e,Kr),E(e,t)},jl=Xr,Hl=(e,t,n,s,r)=>{const i=m(e);switch(i){case Jr:Fl(e,t,n);break;case Pn:Xr(e,n,s,r);break;case Kr:jl(e,n,s,r);break;default:throw new Error("Unknown message type")}return i},zl=0,Yl=(e,t,n)=>{m(e)===zl&&n(t,st(e))},Qe=3e4;class Pl extends wi{constructor(t){super(),this.doc=t,this.clientID=t.clientID,this.states=new Map,this.meta=new Map,this._checkInterval=setInterval(()=>{const n=it();this.getLocalState()!==null&&Qe/2<=n-this.meta.get(this.clientID).lastUpdated&&this.setLocalState(this.getLocalState());const s=[];this.meta.forEach((r,i)=>{i!==this.clientID&&Qe<=n-r.lastUpdated&&this.states.has(i)&&s.push(i)}),s.length>0&&Gn(this,s,"timeout")},H(Qe/10)),t.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(t){const n=this.clientID,s=this.meta.get(n),r=s===void 0?0:s.clock+1,i=this.states.get(n);t===null?this.states.delete(n):this.states.set(n,t),this.meta.set(n,{clock:r,lastUpdated:it()});const o=[],c=[],l=[],a=[];t===null?a.push(n):i==null?t!=null&&o.push(n):(c.push(n),Ct(i,t)||l.push(n)),(o.length>0||l.length>0||a.length>0)&&this.emit("change",[{added:o,updated:l,removed:a},"local"]),this.emit("update",[{added:o,updated:c,removed:a},"local"])}setLocalStateField(t,n){const s=this.getLocalState();s!==null&&this.setLocalState({...s,[t]:n})}getStates(){return this.states}}const Gn=(e,t,n)=>{const s=[];for(let r=0;r<t.length;r++){const i=t[r];if(e.states.has(i)){if(e.states.delete(i),i===e.clientID){const o=e.meta.get(i);e.meta.set(i,{clock:o.clock+1,lastUpdated:it()})}s.push(i)}}s.length>0&&(e.emit("change",[{added:[],updated:[],removed:s},n]),e.emit("update",[{added:[],updated:[],removed:s},n]))},Vt=(e,t,n=e.states)=>{const s=t.length,r=N();w(r,s);for(let i=0;i<s;i++){const o=t[i],c=n.get(o)||null,l=e.meta.get(o).clock;w(r,o),w(r,l),ht(r,JSON.stringify(c))}return C(r)},Gl=(e,t,n)=>{const s=ct(t),r=it(),i=[],o=[],c=[],l=[],a=m(s);for(let h=0;h<a;h++){const u=m(s);let d=m(s);const f=JSON.parse(st(s)),g=e.meta.get(u),p=e.states.get(u),b=g===void 0?0:g.clock;(b<d||b===d&&f===null&&e.states.has(u))&&(f===null?u===e.clientID&&e.getLocalState()!=null?d++:e.states.delete(u):e.states.set(u,f),e.meta.set(u,{clock:d,lastUpdated:r}),g===void 0&&f!==null?i.push(u):g!==void 0&&f===null?l.push(u):f!==null&&(Ct(f,p)||c.push(u),o.push(u)))}(i.length>0||c.length>0||l.length>0)&&e.emit("change",[{added:i,updated:c,removed:l},n]),(i.length>0||o.length>0||l.length>0)&&e.emit("update",[{added:i,updated:o,removed:l},n])},Jl=e=>ro(e,(t,n)=>`${encodeURIComponent(n)}=${encodeURIComponent(t)}`).join("&"),lt=0,qr=3,Tt=1,Kl=2,se=[];se[lt]=(e,t,n,s,r)=>{w(e,lt);const i=Hl(t,e,n.doc,n);s&&i===Pn&&!n.synced&&(n.synced=!0)};se[qr]=(e,t,n,s,r)=>{w(e,Tt),E(e,Vt(n.awareness,Array.from(n.awareness.getStates().keys())))};se[Tt]=(e,t,n,s,r)=>{Gl(n.awareness,O(t),n)};se[Kl]=(e,t,n,s,r)=>{Yl(t,n.doc,(i,o)=>Wl(n,o))};const Es=3e4,Wl=(e,t)=>console.warn(`Permission denied to access ${e.url}.
|
|
6
|
-
${t}`),Qr=(e,t,n)=>{const s=ct(t),r=N(),i=m(s),o=e.messageHandlers[i];return o?o(r,s,e,n,i):console.error("Unable to compute message"),r},fn=(e,t,n)=>{t===e.ws&&(e.emit("connection-close",[n,e]),e.ws=null,t.close(),e.wsconnecting=!1,e.wsconnected?(e.wsconnected=!1,e.synced=!1,Gn(e.awareness,Array.from(e.awareness.getStates().keys()).filter(s=>s!==e.doc.clientID),e),e.emit("status",[{status:"disconnected"}])):e.wsUnsuccessfulReconnects++,setTimeout(Zr,yn(mi(2,e.wsUnsuccessfulReconnects)*100,e.maxBackoffTime),e))},Zr=e=>{if(e.shouldConnect&&e.ws===null){const t=new e._WS(e.url,e.protocols);t.binaryType="arraybuffer",e.ws=t,e.wsconnecting=!0,e.wsconnected=!1,e.synced=!1,t.onmessage=n=>{e.wsLastMessageReceived=it();const s=Qr(e,new Uint8Array(n.data),!0);bn(s)>1&&t.send(C(s))},t.onerror=n=>{e.emit("connection-error",[n,e])},t.onclose=n=>{fn(e,t,n)},t.onopen=()=>{e.wsLastMessageReceived=it(),e.wsconnecting=!1,e.wsconnected=!0,e.wsUnsuccessfulReconnects=0,e.emit("status",[{status:"connected"}]);const n=N();if(w(n,lt),dn(n,e.doc),t.send(C(n)),e.awareness.getLocalState()!==null){const s=N();w(s,Tt),E(s,Vt(e.awareness,[e.doc.clientID])),t.send(C(s))}},e.emit("status",[{status:"connecting"}])}},Ze=(e,t)=>{const n=e.ws;e.wsconnected&&n&&n.readyState===n.OPEN&&n.send(t),e.bcconnected&&_t(e.bcChannel,t,e)};class Xl extends mn{constructor(t,n,s,{connect:r=!0,awareness:i=new Pl(s),params:o={},protocols:c=[],WebSocketPolyfill:l=WebSocket,resyncInterval:a=-1,maxBackoffTime:h=2500,disableBc:u=!1}={}){for(super();t[t.length-1]==="/";)t=t.slice(0,t.length-1);this.serverUrl=t,this.bcChannel=t+"/"+n,this.maxBackoffTime=h,this.params=o,this.protocols=c,this.roomname=n,this.doc=s,this._WS=l,this.awareness=i,this.wsconnected=!1,this.wsconnecting=!1,this.bcconnected=!1,this.disableBc=u,this.wsUnsuccessfulReconnects=0,this.messageHandlers=se.slice(),this._synced=!1,this.ws=null,this.wsLastMessageReceived=0,this.shouldConnect=r,this._resyncInterval=0,a>0&&(this._resyncInterval=setInterval(()=>{if(this.ws&&this.ws.readyState===WebSocket.OPEN){const d=N();w(d,lt),dn(d,s),this.ws.send(C(d))}},a)),this._bcSubscriber=(d,f)=>{if(f!==this){const g=Qr(this,new Uint8Array(d),!1);bn(g)>1&&_t(this.bcChannel,C(g),this)}},this._updateHandler=(d,f)=>{if(f!==this){const g=N();w(g,lt),Vl(g,d),Ze(this,C(g))}},this.doc.on("update",this._updateHandler),this._awarenessUpdateHandler=({added:d,updated:f,removed:g},p)=>{const b=d.concat(f).concat(g),k=N();w(k,Tt),E(k,Vt(i,b)),Ze(this,C(k))},this._exitHandler=()=>{Gn(this.awareness,[s.clientID],"app closed")},ot&&typeof process<"u"&&process.on("exit",this._exitHandler),i.on("update",this._awarenessUpdateHandler),this._checkInterval=setInterval(()=>{this.wsconnected&&Es<it()-this.wsLastMessageReceived&&fn(this,this.ws,null)},Es/10),r&&this.connect()}get url(){const t=Jl(this.params);return this.serverUrl+"/"+this.roomname+(t.length===0?"":"?"+t)}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(),ot&&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||($l(this.bcChannel,this._bcSubscriber),this.bcconnected=!0);const t=N();w(t,lt),dn(t,this.doc),_t(this.bcChannel,C(t),this);const n=N();w(n,lt),Wr(n,this.doc),_t(this.bcChannel,C(n),this);const s=N();w(s,qr),_t(this.bcChannel,C(s),this);const r=N();w(r,Tt),E(r,Vt(this.awareness,[this.doc.clientID])),_t(this.bcChannel,C(r),this)}disconnectBc(){const t=N();w(t,Tt),E(t,Vt(this.awareness,[this.doc.clientID],new Map)),Ze(this,C(t)),this.bcconnected&&(Bl(this.bcChannel,this._bcSubscriber),this.bcconnected=!1)}disconnect(){this.shouldConnect=!1,this.disconnectBc(),this.ws!==null&&fn(this,this.ws,null)}connect(){this.shouldConnect=!0,!this.wsconnected&&this.ws===null&&(Zr(this),this.connectBc())}}const ti="data-collab-blocked",ei=/^[a-z][a-z0-9-]*$/,ql=/^[a-z_:][-a-z0-9_:.]*$/i,Ql=new Set(["script","style","iframe","frame","frameset","object","embed","applet","link","meta","base","noscript","template","portal"]),Zl=new Set(["href","src","xlink:href","action","formaction","data","poster","background","cite","codebase","manifest","ping","longdesc","usemap","lowsrc","dynsrc"]),ta=/^data:image\/(?:png|gif|jpe?g|webp|avif|bmp|x-icon);/,ea=new RegExp("[\\u0000-\\u0020\\u007f-\\u009f\\u00ad\\u200b-\\u200f\\u2028\\u2029\\ufeff]","g");function na(e){const t=e.replace(ea,"").toLowerCase();return/^(?:javascript|vbscript|livescript|mocha):/.test(t)?!1:t.startsWith("data:")?ta.test(t):!0}function sa(e){if(!("data-editora-embed"in e))return!1;const t=e.src?.trim();if(!t||/\s/.test(t))return!1;try{const n=new URL(t);return(n.protocol==="https:"||n.protocol==="http:")&&n.hostname.length>0}catch{return!1}}function ra(e,t){const n=e.toLowerCase();return ei.test(n)?n==="iframe"?!sa(t):Ql.has(n):!0}function ni(e,t){if(!ql.test(e))return!1;const n=e.toLowerCase();return n.startsWith("on")||n==="srcdoc"?!1:Zl.has(n)?na(String(t)):!0}function ia(e,t){const n=e.createElement("span");return n.setAttribute(ti,ei.test(t.toLowerCase())?t.toLowerCase().slice(0,32):"invalid"),n.hidden=!0,n}function De(e){return e.nodeType===Node.ELEMENT_NODE&&e.hasAttribute(ti)}function oa(e){return e instanceof Q||e instanceof q}function Jn(e){return e.toArray().filter(oa)}function ca(e,t){if(e===t)return null;let n=0;const s=Math.min(e.length,t.length);for(;n<s&&e[n]===t[n];)n++;let r=0;const i=Math.min(e.length-n,t.length-n);for(;r<i&&e[e.length-1-r]===t[t.length-1-r];)r++;return{start:n,deleteCount:e.length-n-r,insertText:t.slice(n,t.length-r)}}function la(e){const t=new q(e.tagName.toLowerCase());for(const s of Array.from(e.attributes))t.setAttribute(s.name,s.value);const n=si(e.childNodes);return n.length&&t.insert(0,n),t}function si(e){const t=[];for(const n of Array.from(e))n.nodeType===Node.TEXT_NODE?t.push(new Q(n.textContent??"")):n.nodeType===Node.ELEMENT_NODE&&t.push(la(n));return t}function ri(e){return ra(e.nodeName,e.getAttributes())}function aa(e,t){if(ri(e))return ia(t,e.nodeName);const n=t.createElement(e.nodeName);for(const[s,r]of Object.entries(e.getAttributes()))ni(s,r)&&n.setAttribute(s,r);for(const s of Jn(e))n.appendChild(ii(s,t));return n}function ii(e,t){return e instanceof Q?t.createTextNode(e.toString()):aa(e,t)}function oi(e,t){return ri(t)?De(e):!De(e)&&e.tagName.toLowerCase()===t.nodeName.toLowerCase()}function gn(e,t){const n=Array.from(t.childNodes).filter(o=>o.nodeType===Node.TEXT_NODE||o.nodeType===Node.ELEMENT_NODE),s=Jn(e),r=Math.min(n.length,s.length);let i=0;for(;i<r;i++){const o=n[i],c=s[i];if(o.nodeType===Node.TEXT_NODE){if(c instanceof Q){const l=ca(c.toString(),o.textContent??"");l&&(l.deleteCount>0&&c.delete(l.start,l.deleteCount),l.insertText&&c.insert(l.start,l.insertText));continue}break}if(c instanceof q&&oi(o,c)){if(De(o))continue;ha(c,o),gn(c,o);continue}break}if(i<s.length&&e.delete(i,s.length-i),i<n.length){const o=si(n.slice(i));o.length&&e.insert(i,o)}}function ha(e,t){const n=e.getAttributes(),s=new Set(Array.from(t.attributes).map(r=>r.name));for(const r of Object.keys(n))s.has(r)||e.removeAttribute(r);for(const r of Array.from(t.attributes))n[r.name]!==r.value&&e.setAttribute(r.name,r.value)}function ci(e,t,n){const s=Jn(t),r=Array.from(e.childNodes).filter(c=>c.nodeType===Node.TEXT_NODE||c.nodeType===Node.ELEMENT_NODE),i=Math.min(s.length,r.length);let o=0;for(;o<i;o++){const c=s[o],l=r[o];if(c instanceof Q){if(l.nodeType===Node.TEXT_NODE){const a=c.toString();l.textContent!==a&&(l.textContent=a);continue}break}if(l.nodeType===Node.ELEMENT_NODE&&oi(l,c)){if(De(l))continue;ua(l,c),ci(l,c,n);continue}break}for(let c=r.length-1;c>=o;c--)e.removeChild(r[c]);for(let c=o;c<s.length;c++)e.appendChild(ii(s[c],n))}function ua(e,t){const n=t.getAttributes(),s=new Set(Array.from(e.attributes).map(r=>r.name));for(const r of s)r in n||e.removeAttribute(r);for(const[r,i]of Object.entries(n)){if(!ni(r,i)){e.removeAttribute(r);continue}e.getAttribute(r)!==i&&e.setAttribute(r,i)}}class da{constructor(t,n,s){this.root=t,this.doc=n,this.fragment=s,this.pending=!1,this.destroyed=!1,this.onFragmentChange=(r,i)=>{i.origin!==this&&this.applyRemoteToDom()},this.observer=new MutationObserver(()=>this.scheduleLocalSync()),this.fragment.length===0&&this.root.childNodes.length>0?this.doc.transact(()=>gn(this.fragment,this.root),this):this.applyRemoteToDom(),this.observer.observe(this.root,{childList:!0,characterData:!0,subtree:!0,attributes:!0}),this.fragment.observeDeep(this.onFragmentChange)}scheduleLocalSync(){this.pending||(this.pending=!0,queueMicrotask(()=>{this.pending=!1,!this.destroyed&&this.doc.transact(()=>gn(this.fragment,this.root),this)}))}applyRemoteToDom(){if(this.destroyed)return;const t=this.captureSelection();this.observer.disconnect();try{ci(this.root,this.fragment,this.root.ownerDocument),this.root.dispatchEvent(new Event("input",{bubbles:!0,composed:!0}))}finally{this.observer.observe(this.root,{childList:!0,characterData:!0,subtree:!0,attributes:!0})}t&&this.restoreSelection(t)}pathTo(t,n){if(!this.root.contains(t))return null;const s=[];let r=t;for(;r&&r!==this.root;){const i=r.parentNode;if(!i)return null;s.unshift(Array.prototype.indexOf.call(i.childNodes,r)),r=i}return{path:s,offset:n}}resolvePath(t){let n=this.root;for(const s of t){const r=n.childNodes[s];if(!r)return null;n=r}return n}captureSelection(){const t=this.root.ownerDocument.defaultView?.getSelection();if(!t||t.rangeCount===0||!t.anchorNode||!t.focusNode)return null;const n=this.pathTo(t.anchorNode,t.anchorOffset),s=this.pathTo(t.focusNode,t.focusOffset);return!n||!s?null:{anchor:n,focus:s}}restoreSelection(t){const n=this.root.ownerDocument.defaultView?.getSelection();if(!n)return;const s=this.resolvePath(t.anchor.path),r=this.resolvePath(t.focus.path);if(!(!s||!r))try{const i=Math.min(t.anchor.offset,(s.textContent??"").length),o=Math.min(t.focus.offset,(r.textContent??"").length);n.setBaseAndExtent(s,i,r,o)}catch{}}destroy(){this.destroyed=!0,this.observer.disconnect(),this.fragment.unobserveDeep(this.onFragmentChange)}}const Ds="editora-collaboration-cursor-styles";function fa(){if(typeof document>"u"||document.getElementById(Ds))return;const e=document.createElement("style");e.id=Ds,e.textContent=`
|
|
6
|
+
${t}`),Qr=(e,t,n)=>{const s=ct(t),r=N(),i=m(s),o=e.messageHandlers[i];return o?o(r,s,e,n,i):console.error("Unable to compute message"),r},fn=(e,t,n)=>{t===e.ws&&(e.emit("connection-close",[n,e]),e.ws=null,t.close(),e.wsconnecting=!1,e.wsconnected?(e.wsconnected=!1,e.synced=!1,Gn(e.awareness,Array.from(e.awareness.getStates().keys()).filter(s=>s!==e.doc.clientID),e),e.emit("status",[{status:"disconnected"}])):e.wsUnsuccessfulReconnects++,setTimeout(Zr,yn(mi(2,e.wsUnsuccessfulReconnects)*100,e.maxBackoffTime),e))},Zr=e=>{if(e.shouldConnect&&e.ws===null){const t=new e._WS(e.url,e.protocols);t.binaryType="arraybuffer",e.ws=t,e.wsconnecting=!0,e.wsconnected=!1,e.synced=!1,t.onmessage=n=>{e.wsLastMessageReceived=it();const s=Qr(e,new Uint8Array(n.data),!0);bn(s)>1&&t.send(C(s))},t.onerror=n=>{e.emit("connection-error",[n,e])},t.onclose=n=>{fn(e,t,n)},t.onopen=()=>{e.wsLastMessageReceived=it(),e.wsconnecting=!1,e.wsconnected=!0,e.wsUnsuccessfulReconnects=0,e.emit("status",[{status:"connected"}]);const n=N();if(w(n,lt),dn(n,e.doc),t.send(C(n)),e.awareness.getLocalState()!==null){const s=N();w(s,Tt),E(s,Vt(e.awareness,[e.doc.clientID])),t.send(C(s))}},e.emit("status",[{status:"connecting"}])}},Ze=(e,t)=>{const n=e.ws;e.wsconnected&&n&&n.readyState===n.OPEN&&n.send(t),e.bcconnected&&_t(e.bcChannel,t,e)};class Xl extends mn{constructor(t,n,s,{connect:r=!0,awareness:i=new Pl(s),params:o={},protocols:c=[],WebSocketPolyfill:l=WebSocket,resyncInterval:a=-1,maxBackoffTime:h=2500,disableBc:u=!1}={}){for(super();t[t.length-1]==="/";)t=t.slice(0,t.length-1);this.serverUrl=t,this.bcChannel=t+"/"+n,this.maxBackoffTime=h,this.params=o,this.protocols=c,this.roomname=n,this.doc=s,this._WS=l,this.awareness=i,this.wsconnected=!1,this.wsconnecting=!1,this.bcconnected=!1,this.disableBc=u,this.wsUnsuccessfulReconnects=0,this.messageHandlers=se.slice(),this._synced=!1,this.ws=null,this.wsLastMessageReceived=0,this.shouldConnect=r,this._resyncInterval=0,a>0&&(this._resyncInterval=setInterval(()=>{if(this.ws&&this.ws.readyState===WebSocket.OPEN){const d=N();w(d,lt),dn(d,s),this.ws.send(C(d))}},a)),this._bcSubscriber=(d,f)=>{if(f!==this){const g=Qr(this,new Uint8Array(d),!1);bn(g)>1&&_t(this.bcChannel,C(g),this)}},this._updateHandler=(d,f)=>{if(f!==this){const g=N();w(g,lt),Vl(g,d),Ze(this,C(g))}},this.doc.on("update",this._updateHandler),this._awarenessUpdateHandler=({added:d,updated:f,removed:g},p)=>{const b=d.concat(f).concat(g),k=N();w(k,Tt),E(k,Vt(i,b)),Ze(this,C(k))},this._exitHandler=()=>{Gn(this.awareness,[s.clientID],"app closed")},ot&&typeof process<"u"&&process.on("exit",this._exitHandler),i.on("update",this._awarenessUpdateHandler),this._checkInterval=setInterval(()=>{this.wsconnected&&Es<it()-this.wsLastMessageReceived&&fn(this,this.ws,null)},Es/10),r&&this.connect()}get url(){const t=Jl(this.params);return this.serverUrl+"/"+this.roomname+(t.length===0?"":"?"+t)}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(),ot&&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||($l(this.bcChannel,this._bcSubscriber),this.bcconnected=!0);const t=N();w(t,lt),dn(t,this.doc),_t(this.bcChannel,C(t),this);const n=N();w(n,lt),Wr(n,this.doc),_t(this.bcChannel,C(n),this);const s=N();w(s,qr),_t(this.bcChannel,C(s),this);const r=N();w(r,Tt),E(r,Vt(this.awareness,[this.doc.clientID])),_t(this.bcChannel,C(r),this)}disconnectBc(){const t=N();w(t,Tt),E(t,Vt(this.awareness,[this.doc.clientID],new Map)),Ze(this,C(t)),this.bcconnected&&(Bl(this.bcChannel,this._bcSubscriber),this.bcconnected=!1)}disconnect(){this.shouldConnect=!1,this.disconnectBc(),this.ws!==null&&fn(this,this.ws,null)}connect(){this.shouldConnect=!0,!this.wsconnected&&this.ws===null&&(Zr(this),this.connectBc())}}const ti="data-collab-blocked",ei=/^[a-z][a-z0-9-]*$/,ql=/^[a-z_:][-a-z0-9_:.]*$/i,Ql=new Set(["script","style","iframe","frame","frameset","object","embed","applet","link","meta","base","noscript","template","portal"]),Zl=new Set(["href","src","xlink:href","action","formaction","data","poster","background","cite","codebase","manifest","ping","longdesc","usemap","lowsrc","dynsrc"]),ta=/^data:image\/(?:png|gif|jpe?g|webp|avif|bmp|x-icon);/,ea=new RegExp("[\\u0000-\\u0020\\u007f-\\u009f\\u00ad\\u200b-\\u200f\\u2028\\u2029\\ufeff]","g");function na(e){const t=e.replace(ea,"").toLowerCase();return/^(?:javascript|vbscript|livescript|mocha):/.test(t)?!1:t.startsWith("data:")?ta.test(t):!0}function sa(e){if(!("data-editora-embed"in e))return!1;const t=e.src?.trim();if(!t||/\s/.test(t))return!1;try{const n=new URL(t);return(n.protocol==="https:"||n.protocol==="http:")&&n.hostname.length>0}catch{return!1}}function ra(e,t){const n=e.toLowerCase();return ei.test(n)?n==="iframe"?!sa(t):Ql.has(n):!0}function ni(e,t){if(!ql.test(e))return!1;const n=e.toLowerCase();return n.startsWith("on")||n==="srcdoc"?!1:Zl.has(n)?na(String(t)):!0}function ia(e,t){const n=e.createElement("span");return n.setAttribute(ti,ei.test(t.toLowerCase())?t.toLowerCase().slice(0,32):"invalid"),n.hidden=!0,n}function De(e){return e.nodeType===Node.ELEMENT_NODE&&e.hasAttribute(ti)}function oa(e){return e instanceof Q||e instanceof q}function Jn(e){return e.toArray().filter(oa)}function ca(e,t){if(e===t)return null;let n=0;const s=Math.min(e.length,t.length);for(;n<s&&e[n]===t[n];)n++;let r=0;const i=Math.min(e.length-n,t.length-n);for(;r<i&&e[e.length-1-r]===t[t.length-1-r];)r++;return{start:n,deleteCount:e.length-n-r,insertText:t.slice(n,t.length-r)}}function la(e){const t=new q(e.tagName.toLowerCase());for(const s of Array.from(e.attributes))t.setAttribute(s.name,s.value);const n=si(e.childNodes);return n.length&&t.insert(0,n),t}function si(e){const t=[];for(const n of Array.from(e))n.nodeType===Node.TEXT_NODE?t.push(new Q(n.textContent??"")):n.nodeType===Node.ELEMENT_NODE&&t.push(la(n));return t}function ri(e){return ra(e.nodeName,e.getAttributes())}function aa(e,t){if(ri(e))return ia(t,e.nodeName);const n=t.createElement(e.nodeName);for(const[s,r]of Object.entries(e.getAttributes()))ni(s,r)&&n.setAttribute(s,r);for(const s of Jn(e))n.appendChild(ii(s,t));return n}function ii(e,t){return e instanceof Q?t.createTextNode(e.toString()):aa(e,t)}function oi(e,t){return ri(t)?De(e):!De(e)&&e.tagName.toLowerCase()===t.nodeName.toLowerCase()}function gn(e,t){const n=Array.from(t.childNodes).filter(o=>o.nodeType===Node.TEXT_NODE||o.nodeType===Node.ELEMENT_NODE),s=Jn(e),r=Math.min(n.length,s.length);let i=0;for(;i<r;i++){const o=n[i],c=s[i];if(o.nodeType===Node.TEXT_NODE){if(c instanceof Q){const l=ca(c.toString(),o.textContent??"");l&&(l.deleteCount>0&&c.delete(l.start,l.deleteCount),l.insertText&&c.insert(l.start,l.insertText));continue}break}if(c instanceof q&&oi(o,c)){if(De(o))continue;ha(c,o),gn(c,o);continue}break}if(i<s.length&&e.delete(i,s.length-i),i<n.length){const o=si(n.slice(i));o.length&&e.insert(i,o)}}function ha(e,t){const n=e.getAttributes(),s=new Set(Array.from(t.attributes).map(r=>r.name));for(const r of Object.keys(n))s.has(r)||e.removeAttribute(r);for(const r of Array.from(t.attributes))n[r.name]!==r.value&&e.setAttribute(r.name,r.value)}function ci(e,t,n){const s=Jn(t),r=Array.from(e.childNodes).filter(c=>c.nodeType===Node.TEXT_NODE||c.nodeType===Node.ELEMENT_NODE),i=Math.min(s.length,r.length);let o=0;for(;o<i;o++){const c=s[o],l=r[o];if(c instanceof Q){if(l.nodeType===Node.TEXT_NODE){const a=c.toString();l.textContent!==a&&(l.textContent=a);continue}break}if(l.nodeType===Node.ELEMENT_NODE&&oi(l,c)){if(De(l))continue;ua(l,c),ci(l,c,n);continue}break}for(let c=r.length-1;c>=o;c--)e.removeChild(r[c]);for(let c=o;c<s.length;c++)e.appendChild(ii(s[c],n))}function ua(e,t){const n=t.getAttributes(),s=new Set(Array.from(e.attributes).map(r=>r.name));for(const r of s)r in n||e.removeAttribute(r);for(const[r,i]of Object.entries(n)){if(!ni(r,i)){e.removeAttribute(r);continue}e.getAttribute(r)!==i&&e.setAttribute(r,i)}}class da{constructor(t,n,s){this.root=t,this.doc=n,this.fragment=s,this.pending=!1,this.destroyed=!1,this.onFragmentChange=(r,i)=>{i.origin!==this&&this.applyRemoteToDom()},this.observer=new MutationObserver(()=>this.scheduleLocalSync()),this.fragment.length===0&&this.root.childNodes.length>0?this.doc.transact(()=>gn(this.fragment,this.root),this):this.applyRemoteToDom(),this.observer.observe(this.root,{childList:!0,characterData:!0,subtree:!0,attributes:!0}),this.fragment.observeDeep(this.onFragmentChange)}scheduleLocalSync(){this.pending||(this.pending=!0,queueMicrotask(()=>{this.pending=!1,!this.destroyed&&this.doc.transact(()=>gn(this.fragment,this.root),this)}))}applyRemoteToDom(){if(this.destroyed)return;const t=this.captureSelection();this.observer.disconnect(),this.root.dispatchEvent(new CustomEvent("provenance:expect",{detail:{kind:"collaborator",timeoutMs:1e3},bubbles:!0}));try{ci(this.root,this.fragment,this.root.ownerDocument),this.root.dispatchEvent(new Event("input",{bubbles:!0,composed:!0}))}finally{this.observer.observe(this.root,{childList:!0,characterData:!0,subtree:!0,attributes:!0})}t&&this.restoreSelection(t)}pathTo(t,n){if(!this.root.contains(t))return null;const s=[];let r=t;for(;r&&r!==this.root;){const i=r.parentNode;if(!i)return null;s.unshift(Array.prototype.indexOf.call(i.childNodes,r)),r=i}return{path:s,offset:n}}resolvePath(t){let n=this.root;for(const s of t){const r=n.childNodes[s];if(!r)return null;n=r}return n}captureSelection(){const t=this.root.ownerDocument.defaultView?.getSelection();if(!t||t.rangeCount===0||!t.anchorNode||!t.focusNode)return null;const n=this.pathTo(t.anchorNode,t.anchorOffset),s=this.pathTo(t.focusNode,t.focusOffset);return!n||!s?null:{anchor:n,focus:s}}restoreSelection(t){const n=this.root.ownerDocument.defaultView?.getSelection();if(!n)return;const s=this.resolvePath(t.anchor.path),r=this.resolvePath(t.focus.path);if(!(!s||!r))try{const i=Math.min(t.anchor.offset,(s.textContent??"").length),o=Math.min(t.focus.offset,(r.textContent??"").length);n.setBaseAndExtent(s,i,r,o)}catch{}}destroy(){this.destroyed=!0,this.observer.disconnect(),this.fragment.unobserveDeep(this.onFragmentChange)}}const Ds="editora-collaboration-cursor-styles";function fa(){if(typeof document>"u"||document.getElementById(Ds))return;const e=document.createElement("style");e.id=Ds,e.textContent=`
|
|
7
7
|
.editora-collab-caret {
|
|
8
8
|
position: fixed;
|
|
9
9
|
width: 2px;
|