| @@ -1,10 +1,15 @@ | ||
| 1 | -"use strict";var wp;(wp||={}).sync=(()=>{var Ic=Object.create;var En=Object.defineProperty;var vc=Object.getOwnPropertyDescriptor;var Oc=Object.getOwnPropertyNames;var Lc=Object.getPrototypeOf,Rc=Object.prototype.hasOwnProperty;var _n=(n,t)=>()=>(t||n((t={exports:{}}).exports,t),t.exports),js=(n,t)=>{for(var e in t)En(n,e,{get:t[e],enumerable:!0})},Ys=(n,t,e,r)=>{if(t&&typeof t=="object"||typeof t=="function")for(let s of Oc(t))!Rc.call(n,s)&&s!==e&&En(n,s,{get:()=>t[s],enumerable:!(r=vc(t,s))||r.enumerable});return n};var Yt=(n,t,e)=>(e=n!=null?Ic(Lc(n)):{},Ys(t||!n||!n.__esModule?En(e,"default",{value:n,enumerable:!0}):e,n)),Nc=n=>Ys(En({},"__esModule",{value:!0}),n);var Fo=_n((mu,Po)=>{Po.exports=window.wp.privateApis});var nr=_n((xu,$o)=>{$o.exports=window.wp.hooks});var sc=_n((bu,rc)=>{rc.exports=window.wp.apiFetch});var Ns=_n((lh,kc)=>{"use strict";kc.exports=function n(t,e){if(t===e)return!0;if(t&&e&&typeof t=="object"&&typeof e=="object"){if(t.constructor!==e.constructor)return!1;var r,s,i;if(Array.isArray(t)){if(r=t.length,r!=e.length)return!1;for(s=r;s--!==0;)if(!n(t[s],e[s]))return!1;return!0}if(t instanceof Map&&e instanceof Map){if(t.size!==e.size)return!1;for(s of t.entries())if(!e.has(s[0]))return!1;for(s of t.entries())if(!n(s[1],e.get(s[0])))return!1;return!0}if(t instanceof Set&&e instanceof Set){if(t.size!==e.size)return!1;for(s of t.entries())if(!e.has(s[0]))return!1;return!0}if(ArrayBuffer.isView(t)&&ArrayBuffer.isView(e)){if(r=t.length,r!=e.length)return!1;for(s=r;s--!==0;)if(t[s]!==e[s])return!1;return!0}if(t.constructor===RegExp)return t.source===e.source&&t.flags===e.flags;if(t.valueOf!==Object.prototype.valueOf)return t.valueOf()===e.valueOf();if(t.toString!==Object.prototype.toString)return t.toString()===e.toString();if(i=Object.keys(t),r=i.length,r!==Object.keys(e).length)return!1;for(s=r;s--!==0;)if(!Object.prototype.hasOwnProperty.call(e,i[s]))return!1;for(s=r;s--!==0;){var o=i[s];if(!n(t[o],e[o]))return!1}return!0}return t!==t&&e!==e}});var Id={};js(Id,{Awareness:()=>Be,Y:()=>Bt,YJS_VERSION:()=>Td,privateApis:()=>Ps});var Bt={};js(Bt,{AbsolutePosition:()=>Bn,AbstractConnector:()=>Yr,AbstractStruct:()=>Ne,AbstractType:()=>v,Array:()=>re,ContentAny:()=>Mt,ContentBinary:()=>ce,ContentDeleted:()=>Me,ContentDoc:()=>le,ContentEmbed:()=>kt,ContentFormat:()=>O,ContentJSON:()=>pn,ContentString:()=>lt,ContentType:()=>nt,Doc:()=>mt,GC:()=>G,ID:()=>_t,Item:()=>C,Map:()=>se,PermanentUserData:()=>Gr,RelativePosition:()=>Le,Skip:()=>P,Snapshot:()=>ln,Text:()=>Re,Transaction:()=>Fn,UndoManager:()=>te,UpdateDecoderV1:()=>X,UpdateDecoderV2:()=>J,UpdateEncoderV1:()=>wt,UpdateEncoderV2:()=>Q,XmlElement:()=>oe,XmlFragment:()=>ie,XmlHook:()=>fn,XmlText:()=>Jn,YArrayEvent:()=>zn,YEvent:()=>ne,YMapEvent:()=>Gn,YTextEvent:()=>Hn,YXmlEvent:()=>$n,applyUpdate:()=>ns,applyUpdateV2:()=>St,cleanupYTextFormatting:()=>To,compareIDs:()=>qt,compareRelativePositions:()=>Xl,convertUpdateFormatV1ToV2:()=>ya,convertUpdateFormatV2ToV1:()=>ho,createAbsolutePositionFromRelativePosition:()=>Wl,createDeleteSet:()=>qn,createDeleteSetFromStructStore:()=>Zr,createDocFromSnapshot:()=>ra,createID:()=>x,createRelativePositionFromJSON:()=>Yl,createRelativePositionFromTypeIndex:()=>Gl,createSnapshot:()=>ls,decodeRelativePosition:()=>Kl,decodeSnapshot:()=>ta,decodeSnapshotV2:()=>Qi,decodeStateVector:()=>ss,decodeUpdate:()=>ua,decodeUpdateV2:()=>io,diffUpdate:()=>ga,diffUpdateV2:()=>as,emptySnapshot:()=>ea,encodeRelativePosition:()=>$l,encodeSnapshot:()=>Zl,encodeSnapshotV2:()=>Xi,encodeStateAsUpdate:()=>rs,encodeStateAsUpdateV2:()=>Vt,encodeStateVector:()=>os,encodeStateVectorFromUpdate:()=>ha,encodeStateVectorFromUpdateV2:()=>co,equalDeleteSets:()=>Ji,equalSnapshots:()=>Ql,findIndexSS:()=>et,findRootTypeKey:()=>cs,getItem:()=>Wt,getItemCleanEnd:()=>Jr,getItemCleanStart:()=>z,getState:()=>U,getTypeChildren:()=>_a,isDeleted:()=>ae,isParentOf:()=>cn,iterateDeletedStructs:()=>Xt,logType:()=>Fl,logUpdate:()=>da,logUpdateV2:()=>so,mergeDeleteSets:()=>Qt,mergeUpdates:()=>oo,mergeUpdatesV2:()=>ee,obfuscateUpdate:()=>ma,obfuscateUpdateV2:()=>wa,parseUpdateMeta:()=>fa,parseUpdateMetaV2:()=>lo,readUpdate:()=>Ml,readUpdateV2:()=>es,relativePositionToJSON:()=>jl,snapshot:()=>na,snapshotContainsUpdate:()=>ia,transact:()=>k,tryGc:()=>la,typeListToArraySnapshot:()=>ba,typeMapGetAllSnapshot:()=>ko,typeMapGetSnapshot:()=>Da});var T=()=>new Map,bn=n=>{let t=T();return n.forEach((e,r)=>{t.set(r,e)}),t},N=(n,t,e)=>{let r=n.get(t);return r===void 0&&n.set(t,r=e()),r},zs=(n,t)=>{let e=[];for(let[r,s]of n)e.push(t(s,r));return e},Gs=(n,t)=>{for(let[e,r]of n)if(t(r,e))return!0;return!1};var dt=()=>new Set;var kn=n=>n[n.length-1];var Hs=(n,t)=>{for(let e=0;e<t.length;e++)n.push(t[e])},it=Array.from;var $s=(n,t)=>{for(let e=0;e<n.length;e++)if(t(n[e],e,n))return!0;return!1};var Js=(n,t)=>{let e=new Array(n);for(let r=0;r<n;r++)e[r]=t(r,e);return e};var zt=Array.isArray;var Dt=class{constructor(){this._observers=T()}on(t,e){return N(this._observers,t,dt).add(e),e}once(t,e){let r=(...s)=>{this.off(t,r),e(...s)};this.on(t,r)}off(t,e){let r=this._observers.get(t);r!==void 0&&(r.delete(e),r.size===0&&this._observers.delete(t))}emit(t,e){return it((this._observers.get(t)||T()).values()).forEach(r=>r(...e))}destroy(){this._observers=T()}},ye=class{constructor(){this._observers=T()}on(t,e){N(this._observers,t,dt).add(e)}once(t,e){let r=(...s)=>{this.off(t,r),e(...s)};this.on(t,r)}off(t,e){let r=this._observers.get(t);r!==void 0&&(r.delete(e),r.size===0&&this._observers.delete(t))}emit(t,e){return it((this._observers.get(t)||T()).values()).forEach(r=>r(...e))}destroy(){this._observers=T()}};var W=Math.floor;var Se=Math.abs;var Cn=(n,t)=>n<t?n:t,Et=(n,t)=>n>t?n:t,Ld=Number.isNaN;var Dn=n=>n!==0?n<0:1/n<0;var hr=Number.MAX_SAFE_INTEGER,Rd=Number.MIN_SAFE_INTEGER,Nd=1<<31;var Ks=Number.isInteger||(n=>typeof n=="number"&&isFinite(n)&&W(n)===n),Md=Number.isNaN,Vd=Number.parseInt;var fr=String.fromCharCode,Bd=String.fromCodePoint,Pd=fr(65535),Mc=n=>n.toLowerCase(),Vc=/^\s*/g,Bc=n=>n.replace(Vc,""),Pc=/([A-Z])/g,pr=(n,t)=>Bc(n.replace(Pc,e=>`${t}${Mc(e)}`));var Fc=n=>{let t=unescape(encodeURIComponent(n)),e=t.length,r=new Uint8Array(e);for(let s=0;s<e;s++)r[s]=t.codePointAt(s);return r},Ee=typeof TextEncoder<"u"?new TextEncoder:null,jc=n=>Ee.encode(n),Ws=Ee?jc:Fc;var xe=typeof TextDecoder>"u"?null:new TextDecoder("utf-8",{fatal:!0,ignoreBOM:!0});xe&&xe.decode(new Uint8Array).length===1&&(xe=null);var Xs=(n,t)=>Js(t,()=>n).join("");var Gt=class{constructor(){this.cpos=0,this.cbuf=new Uint8Array(100),this.bufs=[]}},ot=()=>new Gt;var Yc=n=>{let t=n.cpos;for(let e=0;e<n.bufs.length;e++)t+=n.bufs[e].length;return t};var Y=n=>{let t=new Uint8Array(Yc(n)),e=0;for(let r=0;r<n.bufs.length;r++){let s=n.bufs[r];t.set(s,e),e+=s.length}return t.set(new Uint8Array(n.cbuf.buffer,0,n.cpos),e),t},zc=(n,t)=>{let e=n.cbuf.length;e-n.cpos<t&&(n.bufs.push(new Uint8Array(n.cbuf.buffer,0,n.cpos)),n.cbuf=new Uint8Array(Et(e,t)*2),n.cpos=0)},M=(n,t)=>{let e=n.cbuf.length;n.cpos===e&&(n.bufs.push(n.cbuf),n.cbuf=new Uint8Array(e*2),n.cpos=0),n.cbuf[n.cpos++]=t};var Ce=M;var S=(n,t)=>{for(;t>127;)M(n,128|127&t),t=W(t/128);M(n,127&t)},Ke=(n,t)=>{let e=Dn(t);for(e&&(t=-t),M(n,(t>63?128:0)|(e?64:0)|63&t),t=W(t/64);t>0;)M(n,(t>127?128:0)|127&t),t=W(t/128)},gr=new Uint8Array(3e4),Gc=gr.length/3,Hc=(n,t)=>{if(t.length<Gc){let e=Ee.encodeInto(t,gr).written||0;S(n,e);for(let r=0;r<e;r++)M(n,gr[r])}else V(n,Ws(t))},$c=(n,t)=>{let e=unescape(encodeURIComponent(t)),r=e.length;S(n,r);for(let s=0;s<r;s++)M(n,e.codePointAt(s))},At=Ee&&Ee.encodeInto?Hc:$c;var ni=(n,t)=>De(n,Y(t)),De=(n,t)=>{let e=n.cbuf.length,r=n.cpos,s=Cn(e-r,t.length),i=t.length-s;n.cbuf.set(t.subarray(0,s),r),n.cpos+=s,i>0&&(n.bufs.push(n.cbuf),n.cbuf=new Uint8Array(Et(e*2,i)),n.cbuf.set(t.subarray(s)),n.cpos=i)},V=(n,t)=>{S(n,t.byteLength),De(n,t)},mr=(n,t)=>{zc(n,t);let e=new DataView(n.cbuf.buffer,n.cpos,t);return n.cpos+=t,e},Jc=(n,t)=>mr(n,4).setFloat32(0,t,!1),Kc=(n,t)=>mr(n,8).setFloat64(0,t,!1),qc=(n,t)=>mr(n,8).setBigInt64(0,t,!1);var Zs=new DataView(new ArrayBuffer(4)),Wc=n=>(Zs.setFloat32(0,n),Zs.getFloat32(0)===n),be=(n,t)=>{switch(typeof t){case"string":M(n,119),At(n,t);break;case"number":Ks(t)&&Se(t)<=2147483647?(M(n,125),Ke(n,t)):Wc(t)?(M(n,124),Jc(n,t)):(M(n,123),Kc(n,t));break;case"bigint":M(n,122),qc(n,t);break;case"object":if(t===null)M(n,126);else if(zt(t)){M(n,117),S(n,t.length);for(let e=0;e<t.length;e++)be(n,t[e])}else if(t instanceof Uint8Array)M(n,116),V(n,t);else{M(n,118);let e=Object.keys(t);S(n,e.length);for(let r=0;r<e.length;r++){let s=e[r];At(n,s),be(n,t[s])}}break;case"boolean":M(n,t?120:121);break;default:M(n,127)}},Je=class extends Gt{constructor(t){super(),this.w=t,this.s=null,this.count=0}write(t){this.s===t?this.count++:(this.count>0&&S(this,this.count-1),this.count=1,this.w(this,t),this.s=t)}};var ti=n=>{n.count>0&&(Ke(n.encoder,n.count===1?n.s:-n.s),n.count>1&&S(n.encoder,n.count-2))},Ht=class{constructor(){this.encoder=new Gt,this.s=0,this.count=0}write(t){this.s===t?this.count++:(ti(this),this.count=1,this.s=t)}toUint8Array(){return ti(this),Y(this.encoder)}};var ei=n=>{if(n.count>0){let t=n.diff*2+(n.count===1?0:1);Ke(n.encoder,t),n.count>1&&S(n.encoder,n.count-2)}},ke=class{constructor(){this.encoder=new Gt,this.s=0,this.count=0,this.diff=0}write(t){this.diff===t-this.s?(this.s=t,this.count++):(ei(this),this.count=1,this.diff=t-this.s,this.s=t)}toUint8Array(){return ei(this),Y(this.encoder)}},An=class{constructor(){this.sarr=[],this.s="",this.lensE=new Ht}write(t){this.s+=t,this.s.length>19&&(this.sarr.push(this.s),this.s=""),this.lensE.write(t.length)}toUint8Array(){let t=new Gt;return this.sarr.push(this.s),this.s="",At(t,this.sarr.join("")),De(t,this.lensE.toUint8Array()),Y(t)}};var ut=n=>new Error(n),ct=()=>{throw ut("Method unimplemented")},$=()=>{throw ut("Unexpected case")};var si=ut("Unexpected end of array"),ii=ut("Integer out of Range"),Ae=class{constructor(t){this.arr=t,this.pos=0}},L=n=>new Ae(n),yr=n=>n.pos!==n.arr.length;var Xc=(n,t)=>{let e=new Uint8Array(n.arr.buffer,n.pos+n.arr.byteOffset,t);return n.pos+=t,e},B=n=>Xc(n,E(n));var $t=n=>n.arr[n.pos++];var E=n=>{let t=0,e=1,r=n.arr.length;for(;n.pos<r;){let s=n.arr[n.pos++];if(t=t+(s&127)*e,e*=128,s<128)return t;if(t>hr)throw ii}throw si},We=n=>{let t=n.arr[n.pos++],e=t&63,r=64,s=(t&64)>0?-1:1;if((t&128)===0)return s*e;let i=n.arr.length;for(;n.pos<i;){if(t=n.arr[n.pos++],e=e+(t&127)*r,r*=128,t<128)return s*e;if(e>hr)throw ii}throw si};var Qc=n=>{let t=E(n);if(t===0)return"";{let e=String.fromCodePoint($t(n));if(--t<100)for(;t--;)e+=String.fromCodePoint($t(n));else for(;t>0;){let r=t<1e4?t:1e4,s=n.arr.subarray(n.pos,n.pos+r);n.pos+=r,e+=String.fromCodePoint.apply(null,s),t-=r}return decodeURIComponent(escape(e))}},Zc=n=>xe.decode(B(n)),Tt=xe?Zc:Qc;var Sr=(n,t)=>{let e=new DataView(n.arr.buffer,n.arr.byteOffset+n.pos,t);return n.pos+=t,e},tl=n=>Sr(n,4).getFloat32(0,!1),el=n=>Sr(n,8).getFloat64(0,!1),nl=n=>Sr(n,8).getBigInt64(0,!1);var rl=[n=>{},n=>null,We,tl,el,nl,n=>!1,n=>!0,Tt,n=>{let t=E(n),e={};for(let r=0;r<t;r++){let s=Tt(n);e[s]=Ue(n)}return e},n=>{let t=E(n),e=[];for(let r=0;r<t;r++)e.push(Ue(n));return e},B],Ue=n=>rl[127-$t(n)](n),qe=class extends Ae{constructor(t,e){super(t),this.reader=e,this.s=null,this.count=0}read(){return this.count===0&&(this.s=this.reader(this),yr(this)?this.count=E(this)+1:this.count=-1),this.count--,this.s}};var Jt=class extends Ae{constructor(t){super(t),this.s=0,this.count=0}read(){if(this.count===0){this.s=We(this);let t=Dn(this.s);this.count=1,t&&(this.s=-this.s,this.count=E(this)+2)}return this.count--,this.s}};var Te=class extends Ae{constructor(t){super(t),this.s=0,this.count=0,this.diff=0}read(){if(this.count===0){let t=We(this),e=t&1;this.diff=W(t/2),this.count=1,e&&(this.count=E(this)+2)}return this.s+=this.diff,this.count--,this.s}},Un=class{constructor(t){this.decoder=new Jt(t),this.str=Tt(this.decoder),this.spos=0}read(){let t=this.spos+this.decoder.read(),e=this.str.slice(this.spos,t);return this.spos=t,e}};var Yd=crypto.subtle,oi=crypto.getRandomValues.bind(crypto);var Er=()=>oi(new Uint32Array(1))[0];var sl="10000000-1000-4000-8000"+-1e11,ci=()=>sl.replace(/[018]/g,n=>(n^Er()&15>>n/4).toString(16));var It=Date.now;var br=n=>new Promise(n);var Hd=Promise.all.bind(Promise);var kr=n=>n===void 0?null:n;var Cr=class{constructor(){this.map=new Map}setItem(t,e){this.map.set(t,e)}getItem(t){return this.map.get(t)}},li=new Cr,ll=!0;try{typeof localStorage<"u"&&localStorage&&(li=localStorage,ll=!1)}catch{}var ai=li;var ui=Object.assign,hi=Object.keys,fi=(n,t)=>{for(let e in n)t(n[e],e)};var Dr=n=>hi(n).length,di=n=>hi(n).length;var pi=n=>{for(let t in n)return!1;return!0},dl=(n,t)=>{for(let e in n)if(!t(n[e],e))return!1;return!0},Ar=(n,t)=>Object.prototype.hasOwnProperty.call(n,t),Ur=(n,t)=>n===t||di(n)===di(t)&&dl(n,(e,r)=>(e!==void 0||Ar(t,r))&&t[r]===e),ul=Object.freeze,Tr=n=>{for(let t in n){let e=n[t];(typeof e=="object"||typeof e=="function")&&Tr(n[t])}return ul(n)};var Qe=(n,t,e=0)=>{try{for(;e<n.length;e++)n[e](...t)}finally{e<n.length&&Qe(n,t,e+1)}};var Ir=n=>n,hl=(n,t)=>n===t;var Xe=(n,t)=>{if(n==null||t==null)return hl(n,t);if(n.constructor!==t.constructor)return!1;if(n===t)return!0;switch(n.constructor){case ArrayBuffer:n=new Uint8Array(n),t=new Uint8Array(t);case Uint8Array:{if(n.byteLength!==t.byteLength)return!1;for(let e=0;e<n.length;e++)if(n[e]!==t[e])return!1;break}case Set:{if(n.size!==t.size)return!1;for(let e of n)if(!t.has(e))return!1;break}case Map:{if(n.size!==t.size)return!1;for(let e of n.keys())if(!t.has(e)||!Xe(n.get(e),t.get(e)))return!1;break}case Object:if(Dr(n)!==Dr(t))return!1;for(let e in n)if(!Ar(n,e)||!Xe(n[e],t[e]))return!1;break;case Array:if(n.length!==t.length)return!1;for(let e=0;e<n.length;e++)if(!Xe(n[e],t[e]))return!1;break;default:return!1}return!0},mi=(n,t)=>t.includes(n);var Ie=typeof process<"u"&&process.release&&/node|io\.js/.test(process.release.name)&&Object.prototype.toString.call(typeof process<"u"?process:0)==="[object process]",Tn=typeof window<"u"&&typeof document<"u"&&!Ie,$d=typeof navigator<"u"?/Mac/.test(navigator.platform):!1,ht,fl=[],pl=()=>{if(ht===void 0)if(Ie){ht=T();let n=process.argv,t=null;for(let e=0;e<n.length;e++){let r=n[e];r[0]==="-"?(t!==null&&ht.set(t,""),t=r):t!==null?(ht.set(t,r),t=null):fl.push(r)}t!==null&&ht.set(t,"")}else typeof location=="object"?(ht=T(),(location.search||"?").slice(1).split("&").forEach(n=>{if(n.length!==0){let[t,e]=n.split("=");ht.set(`--${pr(t,"-")}`,e),ht.set(`-${pr(t,"-")}`,e)}})):ht=T();return ht},Or=n=>pl().has(n);var Ze=n=>Ie?kr(process.env[n.toUpperCase().replaceAll("-","_")]):kr(ai.getItem(n));var wi=n=>Or("--"+n)||Ze(n)!==null,Jd=wi("production"),gl=Ie&&mi(process.env.FORCE_COLOR,["true","1","2"]),yi=gl||!Or("--no-colors")&&!wi("no-color")&&(!Ie||process.stdout.isTTY)&&(!Ie||Or("--color")||Ze("COLORTERM")!==null||(Ze("TERM")||"").includes("color"));var Si=n=>new Uint8Array(n),ml=(n,t,e)=>new Uint8Array(n,t,e);var wl=n=>{let t="";for(let e=0;e<n.byteLength;e++)t+=fr(n[e]);return btoa(t)},yl=n=>Buffer.from(n.buffer,n.byteOffset,n.byteLength).toString("base64"),Sl=n=>{let t=atob(n),e=Si(t.length);for(let r=0;r<t.length;r++)e[r]=t.charCodeAt(r);return e},xl=n=>{let t=Buffer.from(n,"base64");return ml(t.buffer,t.byteOffset,t.byteLength)},xi=Tn?wl:yl,Ei=Tn?Sl:xl;var _i=n=>{let t=Si(n.byteLength);return t.set(n),t};var Rr=class{constructor(t,e){this.left=t,this.right=e}},ft=(n,t)=>new Rr(n,t);var Kt=typeof document<"u"?document:{};var Kd=typeof DOMParser<"u"?new DOMParser:null;var ki=n=>zs(n,(t,e)=>`${e}:${t};`).join("");var qd=Kt.ELEMENT_NODE,Wd=Kt.TEXT_NODE,Xd=Kt.CDATA_SECTION_NODE,Qd=Kt.COMMENT_NODE,Zd=Kt.DOCUMENT_NODE,tu=Kt.DOCUMENT_TYPE_NODE,eu=Kt.DOCUMENT_FRAGMENT_NODE;var pt=Symbol;var tn=pt(),en=pt(),Nr=pt(),Mr=pt(),Vr=pt(),nn=pt(),Br=pt(),ve=pt(),Pr=pt(),Ci=n=>{n.length===1&&n[0]?.constructor===Function&&(n=n[0]());let t=[],e=[],r=0;for(;r<n.length;r++){let s=n[r];if(s===void 0)break;if(s.constructor===String||s.constructor===Number)t.push(s);else if(s.constructor===Object)break}for(r>0&&e.push(t.join(""));r<n.length;r++){let s=n[r];s instanceof Symbol||e.push(s)}return e};var nu=It();var Cl={[tn]:ft("font-weight","bold"),[en]:ft("font-weight","normal"),[Nr]:ft("color","blue"),[Vr]:ft("color","green"),[Mr]:ft("color","grey"),[nn]:ft("color","red"),[Br]:ft("color","purple"),[ve]:ft("color","orange"),[Pr]:ft("color","black")},Dl=n=>{n.length===1&&n[0]?.constructor===Function&&(n=n[0]());let t=[],e=[],r=T(),s=[],i=0;for(;i<n.length;i++){let o=n[i],c=Cl[o];if(c!==void 0)r.set(c.left,c.right);else{if(o===void 0)break;if(o.constructor===String||o.constructor===Number){let l=ki(r);i>0||l.length>0?(t.push("%c"+o),e.push(l)):t.push(o)}else break}}for(i>0&&(s=e,s.unshift(t.join("")));i<n.length;i++){let o=n[i];o instanceof Symbol||s.push(o)}return s},Di=yi?Dl:Ci,In=(...n)=>{console.log(...Di(n)),Ai.forEach(t=>t.print(n))},Fr=(...n)=>{console.warn(...Di(n)),n.unshift(ve),Ai.forEach(t=>t.print(n))};var Ai=dt();var Ui=n=>({[Symbol.iterator](){return this},next:n}),Ti=(n,t)=>Ui(()=>{let e;do e=n.next();while(!e.done&&!t(e.value));return e}),vn=(n,t)=>Ui(()=>{let{done:e,value:r}=n.next();return{done:e,value:e?void 0:t(r)}});var Yr=class extends Dt{constructor(t,e){super(),this.doc=t,this.awareness=e}},sn=class{constructor(t,e){this.clock=t,this.len=e}},Rt=class{constructor(){this.clients=new Map}},Xt=(n,t,e)=>t.clients.forEach((r,s)=>{let i=n.doc.store.clients.get(s);if(i!=null){let o=i[i.length-1],c=o.id.clock+o.length;for(let l=0,a=r[l];l<r.length&&a.clock<c;a=r[++l])to(n,i,a.clock,a.len,e)}}),vl=(n,t)=>{let e=0,r=n.length-1;for(;e<=r;){let s=W((e+r)/2),i=n[s],o=i.clock;if(o<=t){if(t<o+i.len)return s;e=s+1}else r=s-1}return null},ae=(n,t)=>{let e=n.clients.get(t.client);return e!==void 0&&vl(e,t.clock)!==null},Qr=n=>{n.clients.forEach(t=>{t.sort((s,i)=>s.clock-i.clock);let e,r;for(e=1,r=1;e<t.length;e++){let s=t[r-1],i=t[e];s.clock+s.len>=i.clock?s.len=Et(s.len,i.clock+i.len-s.clock):(r<e&&(t[r]=i),r++)}t.length=r})},Qt=n=>{let t=new Rt;for(let e=0;e<n.length;e++)n[e].clients.forEach((r,s)=>{if(!t.clients.has(s)){let i=r.slice();for(let o=e+1;o<n.length;o++)Hs(i,n[o].clients.get(s)||[]);t.clients.set(s,i)}});return Qr(t),t},on=(n,t,e,r)=>{N(n.clients,t,()=>[]).push(new sn(e,r))},qn=()=>new Rt,Zr=n=>{let t=qn();return n.clients.forEach((e,r)=>{let s=[];for(let i=0;i<e.length;i++){let o=e[i];if(o.deleted){let c=o.id.clock,l=o.length;if(i+1<e.length)for(let a=e[i+1];i+1<e.length&&a.deleted;a=e[++i+1])l+=a.length;s.push(new sn(c,l))}}s.length>0&&t.clients.set(r,s)}),t},gt=(n,t)=>{S(n.restEncoder,t.clients.size),it(t.clients.entries()).sort((e,r)=>r[0]-e[0]).forEach(([e,r])=>{n.resetDsCurVal(),S(n.restEncoder,e);let s=r.length;S(n.restEncoder,s);for(let i=0;i<s;i++){let o=r[i];n.writeDsClock(o.clock),n.writeDsLen(o.len)}})},bt=n=>{let t=new Rt,e=E(n.restDecoder);for(let r=0;r<e;r++){n.resetDsCurVal();let s=E(n.restDecoder),i=E(n.restDecoder);if(i>0){let o=N(t.clients,s,()=>[]);for(let c=0;c<i;c++)o.push(new sn(n.readDsClock(),n.readDsLen()))}}return t},Oi=(n,t,e)=>{let r=new Rt,s=E(n.restDecoder);for(let i=0;i<s;i++){n.resetDsCurVal();let o=E(n.restDecoder),c=E(n.restDecoder),l=e.clients.get(o)||[],a=U(e,o);for(let d=0;d<c;d++){let u=n.readDsClock(),h=u+n.readDsLen();if(u<a){a<h&&on(r,o,a,h-a);let f=et(l,u),p=l[f];for(!p.deleted&&p.id.clock<u&&(l.splice(f+1,0,Kn(t,p,u-p.id.clock)),f++);f<l.length&&(p=l[f++],p.id.clock<h);)p.deleted||(h<p.id.clock+p.length&&l.splice(f,0,Kn(t,p,h-p.id.clock)),p.delete(t))}else on(r,o,u,h-u)}}if(r.clients.size>0){let i=new Q;return S(i.restEncoder,0),gt(i,r),i.toUint8Array()}return null},Ji=(n,t)=>{if(n.clients.size!==t.clients.size)return!1;for(let[e,r]of n.clients.entries()){let s=t.clients.get(e);if(s===void 0||r.length!==s.length)return!1;for(let i=0;i<r.length;i++){let o=r[i],c=s[i];if(o.clock!==c.clock||o.len!==c.len)return!1}}return!0},Ki=Er,mt=class n extends Dt{constructor({guid:t=ci(),collectionid:e=null,gc:r=!0,gcFilter:s=()=>!0,meta:i=null,autoLoad:o=!1,shouldLoad:c=!0}={}){super(),this.gc=r,this.gcFilter=s,this.clientID=Ki(),this.guid=t,this.collectionid=e,this.share=new Map,this.store=new Pn,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=br(a=>{this.on("load",()=>{this.isLoaded=!0,a(this)})});let l=()=>br(a=>{let d=u=>{(u===void 0||u===!0)&&(this.off("sync",d),a())};this.on("sync",d)});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(){let t=this._item;t!==null&&!this.shouldLoad&&k(t.parent.doc,e=>{e.subdocsLoaded.add(this)},null,!0),this.shouldLoad=!0}getSubdocs(){return this.subdocs}getSubdocGuids(){return new Set(it(this.subdocs).map(t=>t.guid))}transact(t,e=null){return k(this,t,e)}get(t,e=v){let r=N(this.share,t,()=>{let i=new e;return i._integrate(this,null),i}),s=r.constructor;if(e!==v&&s!==e)if(s===v){let i=new e;i._map=r._map,r._map.forEach(o=>{for(;o!==null;o=o.left)o.parent=i}),i._start=r._start;for(let o=i._start;o!==null;o=o.right)o.parent=i;return i._length=r._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 r}getArray(t=""){return this.get(t,re)}getText(t=""){return this.get(t,Re)}getMap(t=""){return this.get(t,se)}getXmlElement(t=""){return this.get(t,oe)}getXmlFragment(t=""){return this.get(t,ie)}toJSON(){let t={};return this.share.forEach((e,r)=>{t[r]=e.toJSON()}),t}destroy(){this.isDestroyed=!0,it(this.subdocs).forEach(e=>e.destroy());let t=this._item;if(t!==null){this._item=null;let e=t.content;e.doc=new n({guid:this.guid,...e.opts,shouldLoad:!1}),e.doc._item=t,k(t.parent.doc,r=>{let s=e.doc;t.deleted||r.subdocsAdded.add(s),r.subdocsRemoved.add(this)},null,!0)}this.emit("destroyed",[!0]),this.emit("destroy",[this]),super.destroy()}},Zt=class{constructor(t){this.restDecoder=t}resetDsCurVal(){}readDsClock(){return E(this.restDecoder)}readDsLen(){return E(this.restDecoder)}},X=class extends Zt{readLeftID(){return x(E(this.restDecoder),E(this.restDecoder))}readRightID(){return x(E(this.restDecoder),E(this.restDecoder))}readClient(){return E(this.restDecoder)}readInfo(){return $t(this.restDecoder)}readString(){return Tt(this.restDecoder)}readParentInfo(){return E(this.restDecoder)===1}readTypeRef(){return E(this.restDecoder)}readLen(){return E(this.restDecoder)}readAny(){return Ue(this.restDecoder)}readBuf(){return _i(B(this.restDecoder))}readJSON(){return JSON.parse(Tt(this.restDecoder))}readKey(){return Tt(this.restDecoder)}},Vn=class{constructor(t){this.dsCurrVal=0,this.restDecoder=t}resetDsCurVal(){this.dsCurrVal=0}readDsClock(){return this.dsCurrVal+=E(this.restDecoder),this.dsCurrVal}readDsLen(){let t=E(this.restDecoder)+1;return this.dsCurrVal+=t,t}},J=class extends Vn{constructor(t){super(t),this.keys=[],E(t),this.keyClockDecoder=new Te(B(t)),this.clientDecoder=new Jt(B(t)),this.leftClockDecoder=new Te(B(t)),this.rightClockDecoder=new Te(B(t)),this.infoDecoder=new qe(B(t),$t),this.stringDecoder=new Un(B(t)),this.parentInfoDecoder=new qe(B(t),$t),this.typeRefDecoder=new Jt(B(t)),this.lenDecoder=new Jt(B(t))}readLeftID(){return new _t(this.clientDecoder.read(),this.leftClockDecoder.read())}readRightID(){return new _t(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 Ue(this.restDecoder)}readBuf(){return B(this.restDecoder)}readJSON(){return Ue(this.restDecoder)}readKey(){let t=this.keyClockDecoder.read();if(t<this.keys.length)return this.keys[t];{let e=this.stringDecoder.read();return this.keys.push(e),e}}},Nt=class{constructor(){this.restEncoder=ot()}toUint8Array(){return Y(this.restEncoder)}resetDsCurVal(){}writeDsClock(t){S(this.restEncoder,t)}writeDsLen(t){S(this.restEncoder,t)}},wt=class extends Nt{writeLeftID(t){S(this.restEncoder,t.client),S(this.restEncoder,t.clock)}writeRightID(t){S(this.restEncoder,t.client),S(this.restEncoder,t.clock)}writeClient(t){S(this.restEncoder,t)}writeInfo(t){Ce(this.restEncoder,t)}writeString(t){At(this.restEncoder,t)}writeParentInfo(t){S(this.restEncoder,t?1:0)}writeTypeRef(t){S(this.restEncoder,t)}writeLen(t){S(this.restEncoder,t)}writeAny(t){be(this.restEncoder,t)}writeBuf(t){V(this.restEncoder,t)}writeJSON(t){At(this.restEncoder,JSON.stringify(t))}writeKey(t){At(this.restEncoder,t)}},Oe=class{constructor(){this.restEncoder=ot(),this.dsCurrVal=0}toUint8Array(){return Y(this.restEncoder)}resetDsCurVal(){this.dsCurrVal=0}writeDsClock(t){let e=t-this.dsCurrVal;this.dsCurrVal=t,S(this.restEncoder,e)}writeDsLen(t){t===0&&$(),S(this.restEncoder,t-1),this.dsCurrVal+=t}},Q=class extends Oe{constructor(){super(),this.keyMap=new Map,this.keyClock=0,this.keyClockEncoder=new ke,this.clientEncoder=new Ht,this.leftClockEncoder=new ke,this.rightClockEncoder=new ke,this.infoEncoder=new Je(Ce),this.stringEncoder=new An,this.parentInfoEncoder=new Je(Ce),this.typeRefEncoder=new Ht,this.lenEncoder=new Ht}toUint8Array(){let t=ot();return S(t,0),V(t,this.keyClockEncoder.toUint8Array()),V(t,this.clientEncoder.toUint8Array()),V(t,this.leftClockEncoder.toUint8Array()),V(t,this.rightClockEncoder.toUint8Array()),V(t,Y(this.infoEncoder)),V(t,this.stringEncoder.toUint8Array()),V(t,Y(this.parentInfoEncoder)),V(t,this.typeRefEncoder.toUint8Array()),V(t,this.lenEncoder.toUint8Array()),De(t,Y(this.restEncoder)),Y(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){be(this.restEncoder,t)}writeBuf(t){V(this.restEncoder,t)}writeJSON(t){be(this.restEncoder,t)}writeKey(t){let e=this.keyMap.get(t);e===void 0?(this.keyClockEncoder.write(this.keyClock++),this.stringEncoder.write(t)):this.keyClockEncoder.write(e)}},Ol=(n,t,e,r)=>{r=Et(r,t[0].id.clock);let s=et(t,r);S(n.restEncoder,t.length-s),n.writeClient(e),S(n.restEncoder,r);let i=t[s];i.write(n,r-i.id.clock);for(let o=s+1;o<t.length;o++)t[o].write(n,0)},ts=(n,t,e)=>{let r=new Map;e.forEach((s,i)=>{U(t,i)>s&&r.set(i,s)}),gn(t).forEach((s,i)=>{e.has(i)||r.set(i,0)}),S(n.restEncoder,r.size),it(r.entries()).sort((s,i)=>i[0]-s[0]).forEach(([s,i])=>{Ol(n,t.clients.get(s),s,i)})},Ll=(n,t)=>{let e=T(),r=E(n.restDecoder);for(let s=0;s<r;s++){let i=E(n.restDecoder),o=new Array(i),c=n.readClient(),l=E(n.restDecoder);e.set(c,{i:0,refs:o});for(let a=0;a<i;a++){let d=n.readInfo();switch(31&d){case 0:{let u=n.readLen();o[a]=new G(x(c,l),u),l+=u;break}case 10:{let u=E(n.restDecoder);o[a]=new P(x(c,l),u),l+=u;break}default:{let u=(d&192)===0,h=new C(x(c,l),null,(d&128)===128?n.readLeftID():null,null,(d&64)===64?n.readRightID():null,u?n.readParentInfo()?t.get(n.readString()):n.readLeftID():null,u&&(d&32)===32?n.readString():null,Oo(n,d));o[a]=h,l+=h.length}}}}return e},Rl=(n,t,e)=>{let r=[],s=it(e.keys()).sort((f,p)=>f-p);if(s.length===0)return null;let i=()=>{if(s.length===0)return null;let f=e.get(s[s.length-1]);for(;f.refs.length===f.i;)if(s.pop(),s.length>0)f=e.get(s[s.length-1]);else return null;return f},o=i();if(o===null)return null;let c=new Pn,l=new Map,a=(f,p)=>{let g=l.get(f);(g==null||g>p)&&l.set(f,p)},d=o.refs[o.i++],u=new Map,h=()=>{for(let f of r){let p=f.id.client,g=e.get(p);g?(g.i--,c.clients.set(p,g.refs.slice(g.i)),e.delete(p),g.i=0,g.refs=[]):c.clients.set(p,[f]),s=s.filter(m=>m!==p)}r.length=0};for(;;){if(d.constructor!==P){let p=N(u,d.id.client,()=>U(t,d.id.client))-d.id.clock;if(p<0)r.push(d),a(d.id.client,d.id.clock-1),h();else{let g=d.getMissing(n,t);if(g!==null){r.push(d);let m=e.get(g)||{refs:[],i:0};if(m.refs.length===m.i)a(g,U(t,g)),h();else{d=m.refs[m.i++];continue}}else(p===0||p<d.length)&&(d.integrate(n,p),u.set(d.id.client,d.id.clock+d.length))}}if(r.length>0)d=r.pop();else if(o!==null&&o.i<o.refs.length)d=o.refs[o.i++];else{if(o=i(),o===null)break;d=o.refs[o.i++]}}if(c.clients.size>0){let f=new Q;return ts(f,c,new Map),S(f.restEncoder,0),{missing:l,update:f.toUint8Array()}}return null},Nl=(n,t)=>ts(n,t.doc.store,t.beforeState),es=(n,t,e,r=new J(n))=>k(t,s=>{s.local=!1;let i=!1,o=s.doc,c=o.store,l=Ll(r,o),a=Rl(s,c,l),d=c.pendingStructs;if(d){for(let[h,f]of d.missing)if(f<U(c,h)){i=!0;break}if(a){for(let[h,f]of a.missing){let p=d.missing.get(h);(p==null||p>f)&&d.missing.set(h,f)}d.update=ee([d.update,a.update])}}else c.pendingStructs=a;let u=Oi(r,s,c);if(c.pendingDs){let h=new J(L(c.pendingDs));E(h.restDecoder);let f=Oi(h,s,c);u&&f?c.pendingDs=ee([u,f]):c.pendingDs=u||f}else c.pendingDs=u;if(i){let h=c.pendingStructs.update;c.pendingStructs=null,St(s.doc,h)}},e,!1),Ml=(n,t,e)=>es(n,t,e,new X(n)),St=(n,t,e,r=J)=>{let s=L(t);es(s,n,e,new r(s))},ns=(n,t,e)=>St(n,t,e,X),Vl=(n,t,e=new Map)=>{ts(n,t.store,e),gt(n,Zr(t.store))},Vt=(n,t=new Uint8Array([0]),e=new Q)=>{let r=ss(t);Vl(e,n,r);let s=[e.toUint8Array()];if(n.store.pendingDs&&s.push(n.store.pendingDs),n.store.pendingStructs&&s.push(as(n.store.pendingStructs.update,t)),s.length>1){if(e.constructor===wt)return oo(s.map((i,o)=>o===0?i:ho(i)));if(e.constructor===Q)return ee(s)}return s[0]},rs=(n,t)=>Vt(n,t,new wt),qi=n=>{let t=new Map,e=E(n.restDecoder);for(let r=0;r<e;r++){let s=E(n.restDecoder),i=E(n.restDecoder);t.set(s,i)}return t},ss=n=>qi(new Zt(L(n))),is=(n,t)=>(S(n.restEncoder,t.size),it(t.entries()).sort((e,r)=>r[0]-e[0]).forEach(([e,r])=>{S(n.restEncoder,e),S(n.restEncoder,r)}),n),Bl=(n,t)=>is(n,gn(t.store)),Pl=(n,t=new Oe)=>(n instanceof Map?is(t,n):Bl(t,n),t.toUint8Array()),os=n=>Pl(n,new Nt),zr=class{constructor(){this.l=[]}},Li=()=>new zr,Ri=(n,t)=>n.l.push(t),Ni=(n,t)=>{let e=n.l,r=e.length;n.l=e.filter(s=>t!==s),r===n.l.length&&console.error("[yjs] Tried to remove event handler that doesn't exist.")},Wi=(n,t,e)=>Qe(n.l,[t,e]),_t=class{constructor(t,e){this.client=t,this.clock=e}},qt=(n,t)=>n===t||n!==null&&t!==null&&n.client===t.client&&n.clock===t.clock,x=(n,t)=>new _t(n,t),Mi=(n,t)=>{S(n,t.client),S(n,t.clock)},Vi=n=>x(E(n),E(n)),cs=n=>{for(let[t,e]of n.doc.share.entries())if(e===n)return t;throw $()},cn=(n,t)=>{for(;t!==null;){if(t.parent===n)return!0;t=t.parent._item}return!1},Fl=n=>{let t=[],e=n._start;for(;e;)t.push(e),e=e.right;console.log("Children: ",t),console.log("Children content: ",t.filter(r=>!r.deleted).map(r=>r.content))},Gr=class{constructor(t,e=t.getMap("users")){let r=new Map;this.yusers=e,this.doc=t,this.clients=new Map,this.dss=r;let s=(i,o)=>{let c=i.get("ds"),l=i.get("ids"),a=d=>this.clients.set(d,o);c.observe(d=>{d.changes.added.forEach(u=>{u.content.getContent().forEach(h=>{h instanceof Uint8Array&&this.dss.set(o,Qt([this.dss.get(o)||qn(),bt(new Zt(L(h)))]))})})}),this.dss.set(o,Qt(c.map(d=>bt(new Zt(L(d)))))),l.observe(d=>d.changes.added.forEach(u=>u.content.getContent().forEach(a))),l.forEach(a)};e.observe(i=>{i.keysChanged.forEach(o=>s(e.get(o),o))}),e.forEach(s)}setUserMapping(t,e,r,{filter:s=()=>!0}={}){let i=this.yusers,o=i.get(r);o||(o=new se,o.set("ids",new re),o.set("ds",new re),i.set(r,o)),o.get("ids").push([e]),i.observe(c=>{setTimeout(()=>{let l=i.get(r);if(l!==o){o=l,this.clients.forEach((u,h)=>{r===u&&o.get("ids").push([h])});let a=new Nt,d=this.dss.get(r);d&&(gt(a,d),o.get("ds").push([a.toUint8Array()]))}},0)}),t.on("afterTransaction",c=>{setTimeout(()=>{let l=o.get("ds"),a=c.deleteSet;if(c.local&&a.clients.size>0&&s(c,a)){let d=new Nt;gt(d,a),l.push([d.toUint8Array()])}})})}getUserByClientId(t){return this.clients.get(t)||null}getUserByDeletedId(t){for(let[e,r]of this.dss.entries())if(ae(r,t))return e;return null}},Le=class{constructor(t,e,r,s=0){this.type=t,this.tname=e,this.item=r,this.assoc=s}},jl=n=>{let t={};return n.type&&(t.type=n.type),n.tname&&(t.tname=n.tname),n.item&&(t.item=n.item),n.assoc!=null&&(t.assoc=n.assoc),t},Yl=n=>new Le(n.type==null?null:x(n.type.client,n.type.clock),n.tname??null,n.item==null?null:x(n.item.client,n.item.clock),n.assoc==null?0:n.assoc),Bn=class{constructor(t,e,r=0){this.type=t,this.index=e,this.assoc=r}},zl=(n,t,e=0)=>new Bn(n,t,e),On=(n,t,e)=>{let r=null,s=null;return n._item===null?s=cs(n):r=x(n._item.id.client,n._item.id.clock),new Le(r,s,t,e)},Gl=(n,t,e=0)=>{let r=n._start;if(e<0){if(t===0)return On(n,null,e);t--}for(;r!==null;){if(!r.deleted&&r.countable){if(r.length>t)return On(n,x(r.id.client,r.id.clock+t),e);t-=r.length}if(r.right===null&&e<0)return On(n,r.lastId,e);r=r.right}return On(n,null,e)},Hl=(n,t)=>{let{type:e,tname:r,item:s,assoc:i}=t;if(s!==null)S(n,0),Mi(n,s);else if(r!==null)Ce(n,1),At(n,r);else if(e!==null)Ce(n,2),Mi(n,e);else throw $();return Ke(n,i),n},$l=n=>{let t=ot();return Hl(t,n),Y(t)},Jl=n=>{let t=null,e=null,r=null;switch(E(n)){case 0:r=Vi(n);break;case 1:e=Tt(n);break;case 2:t=Vi(n)}let s=yr(n)?We(n):0;return new Le(t,e,r,s)},Kl=n=>Jl(L(n)),ql=(n,t)=>{let e=Wt(n,t),r=t.clock-e.id.clock;return{item:e,diff:r}},Wl=(n,t,e=!0)=>{let r=t.store,s=n.item,i=n.type,o=n.tname,c=n.assoc,l=null,a=0;if(s!==null){if(U(r,s.client)<=s.clock)return null;let d=e?Wr(r,s):ql(r,s),u=d.item;if(!(u instanceof C))return null;if(l=u.parent,l._item===null||!l._item.deleted){a=u.deleted||!u.countable?0:d.diff+(c>=0?0:1);let h=u.left;for(;h!==null;)!h.deleted&&h.countable&&(a+=h.length),h=h.left}}else{if(o!==null)l=t.get(o);else if(i!==null){if(U(r,i.client)<=i.clock)return null;let{item:d}=e?Wr(r,i):{item:Wt(r,i)};if(d instanceof C&&d.content instanceof nt)l=d.content.type;else return null}else throw $();c>=0?a=l._length:a=0}return zl(l,a,n.assoc)},Xl=(n,t)=>n===t||n!==null&&t!==null&&n.tname===t.tname&&qt(n.item,t.item)&&qt(n.type,t.type)&&n.assoc===t.assoc,ln=class{constructor(t,e){this.ds=t,this.sv=e}},Ql=(n,t)=>{let e=n.ds.clients,r=t.ds.clients,s=n.sv,i=t.sv;if(s.size!==i.size||e.size!==r.size)return!1;for(let[o,c]of s.entries())if(i.get(o)!==c)return!1;for(let[o,c]of e.entries()){let l=r.get(o)||[];if(c.length!==l.length)return!1;for(let a=0;a<c.length;a++){let d=c[a],u=l[a];if(d.clock!==u.clock||d.len!==u.len)return!1}}return!0},Xi=(n,t=new Oe)=>(gt(t,n.ds),is(t,n.sv),t.toUint8Array()),Zl=n=>Xi(n,new Nt),Qi=(n,t=new Vn(L(n)))=>new ln(bt(t),qi(t)),ta=n=>Qi(n,new Zt(L(n))),ls=(n,t)=>new ln(n,t),ea=ls(qn(),new Map),na=n=>ls(Zr(n.store),gn(n.store)),vt=(n,t)=>t===void 0?!n.deleted:t.sv.has(n.id.client)&&(t.sv.get(n.id.client)||0)>n.id.clock&&!ae(t.ds,n.id),Hr=(n,t)=>{let e=N(n.meta,Hr,dt),r=n.doc.store;e.has(t)||(t.sv.forEach((s,i)=>{s<U(r,i)&&z(n,x(i,s))}),Xt(n,t.ds,s=>{}),e.add(t))},ra=(n,t,e=new mt)=>{if(n.gc)throw new Error("Garbage-collection must be disabled in `originDoc`!");let{sv:r,ds:s}=t,i=new Q;return n.transact(o=>{let c=0;r.forEach(l=>{l>0&&c++}),S(i.restEncoder,c);for(let[l,a]of r){if(a===0)continue;a<U(n.store,l)&&z(o,x(l,a));let d=n.store.clients.get(l)||[],u=et(d,a-1);S(i.restEncoder,u+1),i.writeClient(l),S(i.restEncoder,0);for(let h=0;h<=u;h++)d[h].write(i,0)}gt(i,s)}),St(e,i.toUint8Array(),"snapshot"),e},sa=(n,t,e=J)=>{let r=new e(L(t)),s=new yt(r,!1);for(let o=s.curr;o!==null;o=s.next())if((n.sv.get(o.id.client)||0)<o.id.clock+o.length)return!1;let i=Qt([n.ds,bt(r)]);return Ji(n.ds,i)},ia=(n,t)=>sa(n,t,X),Pn=class{constructor(){this.clients=new Map,this.pendingStructs=null,this.pendingDs=null}},gn=n=>{let t=new Map;return n.clients.forEach((e,r)=>{let s=e[e.length-1];t.set(r,s.id.clock+s.length)}),t},U=(n,t)=>{let e=n.clients.get(t);if(e===void 0)return 0;let r=e[e.length-1];return r.id.clock+r.length},Zi=(n,t)=>{let e=n.clients.get(t.id.client);if(e===void 0)e=[],n.clients.set(t.id.client,e);else{let r=e[e.length-1];if(r.id.clock+r.length!==t.id.clock)throw $()}e.push(t)},et=(n,t)=>{let e=0,r=n.length-1,s=n[r],i=s.id.clock;if(i===t)return r;let o=W(t/(i+s.length-1)*r);for(;e<=r;){if(s=n[o],i=s.id.clock,i<=t){if(t<i+s.length)return o;e=o+1}else r=o-1;o=W((e+r)/2)}throw $()},oa=(n,t)=>{let e=n.clients.get(t.client);return e[et(e,t.clock)]},Wt=oa,$r=(n,t,e)=>{let r=et(t,e),s=t[r];return s.id.clock<e&&s instanceof C?(t.splice(r+1,0,Kn(n,s,e-s.id.clock)),r+1):r},z=(n,t)=>{let e=n.doc.store.clients.get(t.client);return e[$r(n,e,t.clock)]},Jr=(n,t,e)=>{let r=t.clients.get(e.client),s=et(r,e.clock),i=r[s];return e.clock!==i.id.clock+i.length-1&&i.constructor!==G&&r.splice(s+1,0,Kn(n,i,e.clock-i.id.clock+1)),i},ca=(n,t,e)=>{let r=n.clients.get(t.id.client);r[et(r,t.id.clock)]=e},to=(n,t,e,r,s)=>{if(r===0)return;let i=e+r,o=$r(n,t,e),c;do c=t[o++],i<c.id.clock+c.length&&$r(n,t,i),s(c);while(o<t.length&&t[o].id.clock<i)},Fn=class{constructor(t,e,r){this.doc=t,this.deleteSet=new Rt,this.beforeState=gn(t.store),this.afterState=new Map,this.changed=new Map,this.changedParentTypes=new Map,this._mergeStructs=[],this.origin=e,this.meta=new Map,this.local=r,this.subdocsAdded=new Set,this.subdocsRemoved=new Set,this.subdocsLoaded=new Set,this._needFormattingCleanup=!1}},Bi=(n,t)=>t.deleteSet.clients.size===0&&!Gs(t.afterState,(e,r)=>t.beforeState.get(r)!==e)?!1:(Qr(t.deleteSet),Nl(n,t),gt(n,t.deleteSet),!0),Pi=(n,t,e)=>{let r=t._item;(r===null||r.id.clock<(n.beforeState.get(r.id.client)||0)&&!r.deleted)&&N(n.changed,t,dt).add(e)},Nn=(n,t)=>{let e=n[t],r=n[t-1],s=t;for(;s>0;e=r,r=n[--s-1]){if(r.deleted===e.deleted&&r.constructor===e.constructor&&r.mergeWith(e)){e instanceof C&&e.parentSub!==null&&e.parent._map.get(e.parentSub)===e&&e.parent._map.set(e.parentSub,r);continue}break}let i=t-s;return i&&n.splice(t+1-i,i),i},eo=(n,t,e)=>{for(let[r,s]of n.clients.entries()){let i=t.clients.get(r);for(let o=s.length-1;o>=0;o--){let c=s[o],l=c.clock+c.len;for(let a=et(i,c.clock),d=i[a];a<i.length&&d.id.clock<l;d=i[++a]){let u=i[a];if(c.clock+c.len<=u.id.clock)break;u instanceof C&&u.deleted&&!u.keep&&e(u)&&u.gc(t,!1)}}}},no=(n,t)=>{n.clients.forEach((e,r)=>{let s=t.clients.get(r);for(let i=e.length-1;i>=0;i--){let o=e[i],c=Cn(s.length-1,1+et(s,o.clock+o.len-1));for(let l=c,a=s[l];l>0&&a.id.clock>=o.clock;a=s[l])l-=1+Nn(s,l)}})},la=(n,t,e)=>{eo(n,t,e),no(n,t)},ro=(n,t)=>{if(t<n.length){let e=n[t],r=e.doc,s=r.store,i=e.deleteSet,o=e._mergeStructs;try{Qr(i),e.afterState=gn(e.doc.store),r.emit("beforeObserverCalls",[e,r]);let c=[];e.changed.forEach((l,a)=>c.push(()=>{(a._item===null||!a._item.deleted)&&a._callObserver(e,l)})),c.push(()=>{e.changedParentTypes.forEach((l,a)=>{a._dEH.l.length>0&&(a._item===null||!a._item.deleted)&&(l=l.filter(d=>d.target._item===null||!d.target._item.deleted),l.forEach(d=>{d.currentTarget=a,d._path=null}),l.sort((d,u)=>d.path.length-u.path.length),c.push(()=>{Wi(a._dEH,l,e)}))}),c.push(()=>r.emit("afterTransaction",[e,r])),c.push(()=>{e._needFormattingCleanup&&Ia(e)})}),Qe(c,[])}finally{r.gc&&eo(i,s,r.gcFilter),no(i,s),e.afterState.forEach((d,u)=>{let h=e.beforeState.get(u)||0;if(h!==d){let f=s.clients.get(u),p=Et(et(f,h),1);for(let g=f.length-1;g>=p;)g-=1+Nn(f,g)}});for(let d=o.length-1;d>=0;d--){let{client:u,clock:h}=o[d].id,f=s.clients.get(u),p=et(f,h);p+1<f.length&&Nn(f,p+1)>1||p>0&&Nn(f,p)}if(!e.local&&e.afterState.get(r.clientID)!==e.beforeState.get(r.clientID)&&(In(ve,tn,"[yjs] ",en,nn,"Changed the client-id because another client seems to be using it."),r.clientID=Ki()),r.emit("afterTransactionCleanup",[e,r]),r._observers.has("update")){let d=new wt;Bi(d,e)&&r.emit("update",[d.toUint8Array(),e.origin,r,e])}if(r._observers.has("updateV2")){let d=new Q;Bi(d,e)&&r.emit("updateV2",[d.toUint8Array(),e.origin,r,e])}let{subdocsAdded:c,subdocsLoaded:l,subdocsRemoved:a}=e;(c.size>0||a.size>0||l.size>0)&&(c.forEach(d=>{d.clientID=r.clientID,d.collectionid==null&&(d.collectionid=r.collectionid),r.subdocs.add(d)}),a.forEach(d=>r.subdocs.delete(d)),r.emit("subdocs",[{loaded:l,added:c,removed:a},r,e]),a.forEach(d=>d.destroy())),n.length<=t+1?(r._transactionCleanups=[],r.emit("afterAllTransactions",[r,n])):ro(n,t+1)}}},k=(n,t,e=null,r=!0)=>{let s=n._transactionCleanups,i=!1,o=null;n._transaction===null&&(i=!0,n._transaction=new Fn(n,e,r),s.push(n._transaction),s.length===1&&n.emit("beforeAllTransactions",[n]),n.emit("beforeTransaction",[n._transaction,n]));try{o=t(n._transaction)}finally{if(i){let c=n._transaction===s[0];n._transaction=null,c&&ro(s,0)}}return o},Kr=class{constructor(t,e){this.insertions=e,this.deletions=t,this.meta=new Map}},Fi=(n,t,e)=>{Xt(n,e.deletions,r=>{r instanceof C&&t.scope.some(s=>s===n.doc||cn(s,r))&&ps(r,!1)})},ji=(n,t,e)=>{let r=null,s=n.doc,i=n.scope;k(s,c=>{for(;t.length>0&&n.currStackItem===null;){let l=s.store,a=t.pop(),d=new Set,u=[],h=!1;Xt(c,a.insertions,f=>{if(f instanceof C){if(f.redone!==null){let{item:p,diff:g}=Wr(l,f.id);g>0&&(p=z(c,x(p.id.client,p.id.clock+g))),f=p}!f.deleted&&i.some(p=>p===c.doc||cn(p,f))&&u.push(f)}}),Xt(c,a.deletions,f=>{f instanceof C&&i.some(p=>p===c.doc||cn(p,f))&&!ae(a.insertions,f.id)&&d.add(f)}),d.forEach(f=>{h=vo(c,f,d,a.insertions,n.ignoreRemoteMapChanges,n)!==null||h});for(let f=u.length-1;f>=0;f--){let p=u[f];n.deleteFilter(p)&&(p.delete(c),h=!0)}n.currStackItem=h?a:null}c.changed.forEach((l,a)=>{l.has(null)&&a._searchMarker&&(a._searchMarker.length=0)}),r=c},n);let o=n.currStackItem;if(o!=null){let c=r.changedParentTypes;n.emit("stack-item-popped",[{stackItem:o,type:e,changedParentTypes:c,origin:n},n]),n.currStackItem=null}return o},te=class extends Dt{constructor(t,{captureTimeout:e=500,captureTransaction:r=l=>!0,deleteFilter:s=()=>!0,trackedOrigins:i=new Set([null]),ignoreRemoteMapChanges:o=!1,doc:c=zt(t)?t[0].doc:t instanceof mt?t:t.doc}={}){super(),this.scope=[],this.doc=c,this.addToScope(t),this.deleteFilter=s,i.add(this),this.trackedOrigins=i,this.captureTransaction=r,this.undoStack=[],this.redoStack=[],this.undoing=!1,this.redoing=!1,this.currStackItem=null,this.lastChange=0,this.ignoreRemoteMapChanges=o,this.captureTimeout=e,this.afterTransactionHandler=l=>{if(!this.captureTransaction(l)||!this.scope.some(m=>l.changedParentTypes.has(m)||m===this.doc)||!this.trackedOrigins.has(l.origin)&&(!l.origin||!this.trackedOrigins.has(l.origin.constructor)))return;let a=this.undoing,d=this.redoing,u=a?this.redoStack:this.undoStack;a?this.stopCapturing():d||this.clear(!1,!0);let h=new Rt;l.afterState.forEach((m,w)=>{let y=l.beforeState.get(w)||0,_=m-y;_>0&&on(h,w,y,_)});let f=It(),p=!1;if(this.lastChange>0&&f-this.lastChange<this.captureTimeout&&u.length>0&&!a&&!d){let m=u[u.length-1];m.deletions=Qt([m.deletions,l.deleteSet]),m.insertions=Qt([m.insertions,h])}else u.push(new Kr(l.deleteSet,h)),p=!0;!a&&!d&&(this.lastChange=f),Xt(l,l.deleteSet,m=>{m instanceof C&&this.scope.some(w=>w===l.doc||cn(w,m))&&ps(m,!0)});let g=[{stackItem:u[u.length-1],origin:l.origin,type:a?"redo":"undo",changedParentTypes:l.changedParentTypes},this];p?this.emit("stack-item-added",g):this.emit("stack-item-updated",g)},this.doc.on("afterTransaction",this.afterTransactionHandler),this.doc.on("destroy",()=>{this.destroy()})}addToScope(t){let e=new Set(this.scope);t=zt(t)?t:[t],t.forEach(r=>{e.has(r)||(e.add(r),(r instanceof v?r.doc!==this.doc:r!==this.doc)&&Fr("[yjs#509] Not same Y.Doc"),this.scope.push(r))})}addTrackedOrigin(t){this.trackedOrigins.add(t)}removeTrackedOrigin(t){this.trackedOrigins.delete(t)}clear(t=!0,e=!0){(t&&this.canUndo()||e&&this.canRedo())&&this.doc.transact(r=>{t&&(this.undoStack.forEach(s=>Fi(r,this,s)),this.undoStack=[]),e&&(this.redoStack.forEach(s=>Fi(r,this,s)),this.redoStack=[]),this.emit("stack-cleared",[{undoStackCleared:t,redoStackCleared:e}])})}stopCapturing(){this.lastChange=0}undo(){this.undoing=!0;let t;try{t=ji(this,this.undoStack,"undo")}finally{this.undoing=!1}return t}redo(){this.redoing=!0;let t;try{t=ji(this,this.redoStack,"redo")}finally{this.redoing=!1}return t}canUndo(){return this.undoStack.length>0}canRedo(){return this.redoStack.length>0}destroy(){this.trackedOrigins.delete(this),this.doc.off("afterTransaction",this.afterTransactionHandler),super.destroy()}};function*aa(n){let t=E(n.restDecoder);for(let e=0;e<t;e++){let r=E(n.restDecoder),s=n.readClient(),i=E(n.restDecoder);for(let o=0;o<r;o++){let c=n.readInfo();if(c===10){let l=E(n.restDecoder);yield new P(x(s,i),l),i+=l}else if((31&c)!==0){let l=(c&192)===0,a=new C(x(s,i),null,(c&128)===128?n.readLeftID():null,null,(c&64)===64?n.readRightID():null,l?n.readParentInfo()?n.readString():n.readLeftID():null,l&&(c&32)===32?n.readString():null,Oo(n,c));yield a,i+=a.length}else{let l=n.readLen();yield new G(x(s,i),l),i+=l}}}}var yt=class{constructor(t,e){this.gen=aa(t),this.curr=null,this.done=!1,this.filterSkips=e,this.next()}next(){do this.curr=this.gen.next().value||null;while(this.filterSkips&&this.curr!==null&&this.curr.constructor===P);return this.curr}},da=n=>so(n,X),so=(n,t=J)=>{let e=[],r=new t(L(n)),s=new yt(r,!1);for(let o=s.curr;o!==null;o=s.next())e.push(o);In("Structs: ",e);let i=bt(r);In("DeleteSet: ",i)},ua=n=>io(n,X),io=(n,t=J)=>{let e=[],r=new t(L(n)),s=new yt(r,!1);for(let i=s.curr;i!==null;i=s.next())e.push(i);return{structs:e,ds:bt(r)}},an=class{constructor(t){this.currClient=0,this.startClock=0,this.written=0,this.encoder=t,this.clientStructs=[]}},oo=n=>ee(n,X,wt),co=(n,t=Oe,e=J)=>{let r=new t,s=new yt(new e(L(n)),!1),i=s.curr;if(i!==null){let o=0,c=i.id.client,l=i.id.clock!==0,a=l?0:i.id.clock+i.length;for(;i!==null;i=s.next())c!==i.id.client&&(a!==0&&(o++,S(r.restEncoder,c),S(r.restEncoder,a)),c=i.id.client,a=0,l=i.id.clock!==0),i.constructor===P&&(l=!0),l||(a=i.id.clock+i.length);a!==0&&(o++,S(r.restEncoder,c),S(r.restEncoder,a));let d=ot();return S(d,o),ni(d,r.restEncoder),r.restEncoder=d,r.toUint8Array()}else return S(r.restEncoder,0),r.toUint8Array()},ha=n=>co(n,Nt,X),lo=(n,t=J)=>{let e=new Map,r=new Map,s=new yt(new t(L(n)),!1),i=s.curr;if(i!==null){let o=i.id.client,c=i.id.clock;for(e.set(o,c);i!==null;i=s.next())o!==i.id.client&&(r.set(o,c),e.set(i.id.client,i.id.clock),o=i.id.client),c=i.id.clock+i.length;r.set(o,c)}return{from:e,to:r}},fa=n=>lo(n,X),pa=(n,t)=>{if(n.constructor===G){let{client:e,clock:r}=n.id;return new G(x(e,r+t),n.length-t)}else if(n.constructor===P){let{client:e,clock:r}=n.id;return new P(x(e,r+t),n.length-t)}else{let e=n,{client:r,clock:s}=e.id;return new C(x(r,s+t),null,x(r,s+t-1),null,e.rightOrigin,e.parent,e.parentSub,e.content.splice(t))}},ee=(n,t=J,e=Q)=>{if(n.length===1)return n[0];let r=n.map(d=>new t(L(d))),s=r.map(d=>new yt(d,!0)),i=null,o=new e,c=new an(o);for(;s=s.filter(h=>h.curr!==null),s.sort((h,f)=>{if(h.curr.id.client===f.curr.id.client){let p=h.curr.id.clock-f.curr.id.clock;return p===0?h.curr.constructor===f.curr.constructor?0:h.curr.constructor===P?1:-1:p}else return f.curr.id.client-h.curr.id.client}),s.length!==0;){let d=s[0],u=d.curr.id.client;if(i!==null){let h=d.curr,f=!1;for(;h!==null&&h.id.clock+h.length<=i.struct.id.clock+i.struct.length&&h.id.client>=i.struct.id.client;)h=d.next(),f=!0;if(h===null||h.id.client!==u||f&&h.id.clock>i.struct.id.clock+i.struct.length)continue;if(u!==i.struct.id.client)Ot(c,i.struct,i.offset),i={struct:h,offset:0},d.next();else if(i.struct.id.clock+i.struct.length<h.id.clock)if(i.struct.constructor===P)i.struct.length=h.id.clock+h.length-i.struct.id.clock;else{Ot(c,i.struct,i.offset);let p=h.id.clock-i.struct.id.clock-i.struct.length;i={struct:new P(x(u,i.struct.id.clock+i.struct.length),p),offset:0}}else{let p=i.struct.id.clock+i.struct.length-h.id.clock;p>0&&(i.struct.constructor===P?i.struct.length-=p:h=pa(h,p)),i.struct.mergeWith(h)||(Ot(c,i.struct,i.offset),i={struct:h,offset:0},d.next())}}else i={struct:d.curr,offset:0},d.next();for(let h=d.curr;h!==null&&h.id.client===u&&h.id.clock===i.struct.id.clock+i.struct.length&&h.constructor!==P;h=d.next())Ot(c,i.struct,i.offset),i={struct:h,offset:0}}i!==null&&(Ot(c,i.struct,i.offset),i=null),ds(c);let l=r.map(d=>bt(d)),a=Qt(l);return gt(o,a),o.toUint8Array()},as=(n,t,e=J,r=Q)=>{let s=ss(t),i=new r,o=new an(i),c=new e(L(n)),l=new yt(c,!1);for(;l.curr;){let d=l.curr,u=d.id.client,h=s.get(u)||0;if(l.curr.constructor===P){l.next();continue}if(d.id.clock+d.length>h)for(Ot(o,d,Et(h-d.id.clock,0)),l.next();l.curr&&l.curr.id.client===u;)Ot(o,l.curr,0),l.next();else for(;l.curr&&l.curr.id.client===u&&l.curr.id.clock+l.curr.length<=h;)l.next()}ds(o);let a=bt(c);return gt(i,a),i.toUint8Array()},ga=(n,t)=>as(n,t,X,wt),ao=n=>{n.written>0&&(n.clientStructs.push({written:n.written,restEncoder:Y(n.encoder.restEncoder)}),n.encoder.restEncoder=ot(),n.written=0)},Ot=(n,t,e)=>{n.written>0&&n.currClient!==t.id.client&&ao(n),n.written===0&&(n.currClient=t.id.client,n.encoder.writeClient(t.id.client),S(n.encoder.restEncoder,t.id.clock+e)),t.write(n.encoder,e),n.written++},ds=n=>{ao(n);let t=n.encoder.restEncoder;S(t,n.clientStructs.length);for(let e=0;e<n.clientStructs.length;e++){let r=n.clientStructs[e];S(t,r.written),De(t,r.restEncoder)}},Wn=(n,t,e,r)=>{let s=new e(L(n)),i=new yt(s,!1),o=new r,c=new an(o);for(let a=i.curr;a!==null;a=i.next())Ot(c,t(a),0);ds(c);let l=bt(s);return gt(o,l),o.toUint8Array()},uo=({formatting:n=!0,subdocs:t=!0,yxml:e=!0}={})=>{let r=0,s=T(),i=T(),o=T(),c=T();return c.set(null,null),l=>{switch(l.constructor){case G:case P:return l;case C:{let a=l,d=a.content;switch(d.constructor){case Me:break;case nt:{if(e){let u=d.type;u instanceof oe&&(u.nodeName=N(i,u.nodeName,()=>"node-"+r)),u instanceof fn&&(u.hookName=N(i,u.hookName,()=>"hook-"+r))}break}case Mt:{let u=d;u.arr=u.arr.map(()=>r);break}case ce:{let u=d;u.content=new Uint8Array([r]);break}case le:{let u=d;t&&(u.opts={},u.doc.guid=r+"");break}case kt:{let u=d;u.embed={};break}case O:{let u=d;n&&(u.key=N(o,u.key,()=>r+""),u.value=N(c,u.value,()=>({i:r})));break}case pn:{let u=d;u.arr=u.arr.map(()=>r);break}case lt:{let u=d;u.str=Xs(r%10+"",u.str.length);break}default:$()}return a.parentSub&&(a.parentSub=N(s,a.parentSub,()=>r+"")),r++,l}default:$()}}},ma=(n,t)=>Wn(n,uo(t),X,wt),wa=(n,t)=>Wn(n,uo(t),J,Q),ya=n=>Wn(n,Ir,X,Q),ho=n=>Wn(n,Ir,J,wt),Yi="You must not compute changes after the event-handler fired.",ne=class{constructor(t,e){this.target=t,this.currentTarget=t,this.transaction=e,this._changes=null,this._keys=null,this._delta=null,this._path=null}get path(){return this._path||(this._path=Sa(this.currentTarget,this.target))}deletes(t){return ae(this.transaction.deleteSet,t.id)}get keys(){if(this._keys===null){if(this.transaction.doc._transactionCleanups.length===0)throw ut(Yi);let t=new Map,e=this.target;this.transaction.changed.get(e).forEach(s=>{if(s!==null){let i=e._map.get(s),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=kn(l.content.getContent());else return;else l!==null&&this.deletes(l)?(o="update",c=kn(l.content.getContent())):(o="add",c=void 0)}else if(this.deletes(i))o="delete",c=kn(i.content.getContent());else return;t.set(s,{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 ut(Yi);let e=this.target,r=dt(),s=dt(),i=[];if(t={added:r,deleted:s,delta:i,keys:this.keys},this.transaction.changed.get(e).has(null)){let c=null,l=()=>{c&&i.push(c)};for(let a=e._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,s.add(a)):this.adds(a)?((c===null||c.insert===void 0)&&(l(),c={insert:[]}),c.insert=c.insert.concat(a.content.getContent()),r.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}},Sa=(n,t)=>{let e=[];for(;t._item!==null&&t!==n;){if(t._item.parentSub!==null)e.unshift(t._item.parentSub);else{let r=0,s=t._item.parent._start;for(;s!==t._item&&s!==null;)!s.deleted&&s.countable&&(r+=s.length),s=s.right;e.unshift(r)}t=t._item.parent}return e},F=()=>{Fr("Invalid access: Add Yjs type to a document before reading data.")},fo=80,us=0,qr=class{constructor(t,e){t.marker=!0,this.p=t,this.index=e,this.timestamp=us++}},xa=n=>{n.timestamp=us++},po=(n,t,e)=>{n.p.marker=!1,n.p=t,t.marker=!0,n.index=e,n.timestamp=us++},Ea=(n,t,e)=>{if(n.length>=fo){let r=n.reduce((s,i)=>s.timestamp<i.timestamp?s:i);return po(r,t,e),r}else{let r=new qr(t,e);return n.push(r),r}},Xn=(n,t)=>{if(n._start===null||t===0||n._searchMarker===null)return null;let e=n._searchMarker.length===0?null:n._searchMarker.reduce((i,o)=>Se(t-i.index)<Se(t-o.index)?i:o),r=n._start,s=0;for(e!==null&&(r=e.p,s=e.index,xa(e));r.right!==null&&s<t;){if(!r.deleted&&r.countable){if(t<s+r.length)break;s+=r.length}r=r.right}for(;r.left!==null&&s>t;)r=r.left,!r.deleted&&r.countable&&(s-=r.length);for(;r.left!==null&&r.left.id.client===r.id.client&&r.left.id.clock+r.left.length===r.id.clock;)r=r.left,!r.deleted&&r.countable&&(s-=r.length);return e!==null&&Se(e.index-s)<r.parent.length/fo?(po(e,r,s),e):Ea(n._searchMarker,r,s)},dn=(n,t,e)=>{for(let r=n.length-1;r>=0;r--){let s=n[r];if(e>0){let i=s.p;for(i.marker=!1;i&&(i.deleted||!i.countable);)i=i.left,i&&!i.deleted&&i.countable&&(s.index-=i.length);if(i===null||i.marker===!0){n.splice(r,1);continue}s.p=i,i.marker=!0}(t<s.index||e>0&&t===s.index)&&(s.index=Et(t,s.index+e))}},_a=n=>{n.doc??F();let t=n._start,e=[];for(;t;)e.push(t),t=t.right;return e},Qn=(n,t,e)=>{let r=n,s=t.changedParentTypes;for(;N(s,n,()=>[]).push(e),n._item!==null;)n=n._item.parent;Wi(r._eH,e,t)},v=class{constructor(){this._item=null,this._map=new Map,this._start=null,this.doc=null,this._length=0,this._eH=Li(),this._dEH=Li(),this._searchMarker=null}get parent(){return this._item?this._item.parent:null}_integrate(t,e){this.doc=t,this._item=e}_copy(){throw ct()}clone(){throw ct()}_write(t){}get _first(){let t=this._start;for(;t!==null&&t.deleted;)t=t.right;return t}_callObserver(t,e){!t.local&&this._searchMarker&&(this._searchMarker.length=0)}observe(t){Ri(this._eH,t)}observeDeep(t){Ri(this._dEH,t)}unobserve(t){Ni(this._eH,t)}unobserveDeep(t){Ni(this._dEH,t)}toJSON(){}},go=(n,t,e)=>{n.doc??F(),t<0&&(t=n._length+t),e<0&&(e=n._length+e);let r=e-t,s=[],i=n._start;for(;i!==null&&r>0;){if(i.countable&&!i.deleted){let o=i.content.getContent();if(o.length<=t)t-=o.length;else{for(let c=t;c<o.length&&r>0;c++)s.push(o[c]),r--;t=0}}i=i.right}return s},mo=n=>{n.doc??F();let t=[],e=n._start;for(;e!==null;){if(e.countable&&!e.deleted){let r=e.content.getContent();for(let s=0;s<r.length;s++)t.push(r[s])}e=e.right}return t},ba=(n,t)=>{let e=[],r=n._start;for(;r!==null;){if(r.countable&&vt(r,t)){let s=r.content.getContent();for(let i=0;i<s.length;i++)e.push(s[i])}r=r.right}return e},un=(n,t)=>{let e=0,r=n._start;for(n.doc??F();r!==null;){if(r.countable&&!r.deleted){let s=r.content.getContent();for(let i=0;i<s.length;i++)t(s[i],e++,n)}r=r.right}},wo=(n,t)=>{let e=[];return un(n,(r,s)=>{e.push(t(r,s,n))}),e},ka=n=>{let t=n._start,e=null,r=0;return{[Symbol.iterator](){return this},next:()=>{if(e===null){for(;t!==null&&t.deleted;)t=t.right;if(t===null)return{done:!0,value:void 0};e=t.content.getContent(),r=0,t=t.right}let s=e[r++];return e.length<=r&&(e=null),{done:!1,value:s}}}},yo=(n,t)=>{n.doc??F();let e=Xn(n,t),r=n._start;for(e!==null&&(r=e.p,t-=e.index);r!==null;r=r.right)if(!r.deleted&&r.countable){if(t<r.length)return r.content.getContent()[t];t-=r.length}},jn=(n,t,e,r)=>{let s=e,i=n.doc,o=i.clientID,c=i.store,l=e===null?t._start:e.right,a=[],d=()=>{a.length>0&&(s=new C(x(o,U(c,o)),s,s&&s.lastId,l,l&&l.id,t,null,new Mt(a)),s.integrate(n,0),a=[])};r.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(d(),u.constructor){case Uint8Array:case ArrayBuffer:s=new C(x(o,U(c,o)),s,s&&s.lastId,l,l&&l.id,t,null,new ce(new Uint8Array(u))),s.integrate(n,0);break;case mt:s=new C(x(o,U(c,o)),s,s&&s.lastId,l,l&&l.id,t,null,new le(u)),s.integrate(n,0);break;default:if(u instanceof v)s=new C(x(o,U(c,o)),s,s&&s.lastId,l,l&&l.id,t,null,new nt(u)),s.integrate(n,0);else throw new Error("Unexpected content type in insert operation")}}}),d()},So=()=>ut("Length exceeded!"),xo=(n,t,e,r)=>{if(e>t._length)throw So();if(e===0)return t._searchMarker&&dn(t._searchMarker,e,r.length),jn(n,t,null,r);let s=e,i=Xn(t,e),o=t._start;for(i!==null&&(o=i.p,e-=i.index,e===0&&(o=o.prev,e+=o&&o.countable&&!o.deleted?o.length:0));o!==null;o=o.right)if(!o.deleted&&o.countable){if(e<=o.length){e<o.length&&z(n,x(o.id.client,o.id.clock+e));break}e-=o.length}return t._searchMarker&&dn(t._searchMarker,s,r.length),jn(n,t,o,r)},Ca=(n,t,e)=>{let s=(t._searchMarker||[]).reduce((i,o)=>o.index>i.index?o:i,{index:0,p:t._start}).p;if(s)for(;s.right;)s=s.right;return jn(n,t,s,e)},Eo=(n,t,e,r)=>{if(r===0)return;let s=e,i=r,o=Xn(t,e),c=t._start;for(o!==null&&(c=o.p,e-=o.index);c!==null&&e>0;c=c.right)!c.deleted&&c.countable&&(e<c.length&&z(n,x(c.id.client,c.id.clock+e)),e-=c.length);for(;r>0&&c!==null;)c.deleted||(r<c.length&&z(n,x(c.id.client,c.id.clock+r)),c.delete(n),r-=c.length),c=c.right;if(r>0)throw So();t._searchMarker&&dn(t._searchMarker,s,-i+r)},Yn=(n,t,e)=>{let r=t._map.get(e);r!==void 0&&r.delete(n)},hs=(n,t,e,r)=>{let s=t._map.get(e)||null,i=n.doc,o=i.clientID,c;if(r==null)c=new Mt([r]);else switch(r.constructor){case Number:case Object:case Boolean:case Array:case String:case Date:case BigInt:c=new Mt([r]);break;case Uint8Array:c=new ce(r);break;case mt:c=new le(r);break;default:if(r instanceof v)c=new nt(r);else throw new Error("Unexpected content type")}new C(x(o,U(i.store,o)),s,s&&s.lastId,null,null,t,e,c).integrate(n,0)},fs=(n,t)=>{n.doc??F();let e=n._map.get(t);return e!==void 0&&!e.deleted?e.content.getContent()[e.length-1]:void 0},_o=n=>{let t={};return n.doc??F(),n._map.forEach((e,r)=>{e.deleted||(t[r]=e.content.getContent()[e.length-1])}),t},bo=(n,t)=>{n.doc??F();let e=n._map.get(t);return e!==void 0&&!e.deleted},Da=(n,t,e)=>{let r=n._map.get(t)||null;for(;r!==null&&(!e.sv.has(r.id.client)||r.id.clock>=(e.sv.get(r.id.client)||0));)r=r.left;return r!==null&&vt(r,e)?r.content.getContent()[r.length-1]:void 0},ko=(n,t)=>{let e={};return n._map.forEach((r,s)=>{let i=r;for(;i!==null&&(!t.sv.has(i.id.client)||i.id.clock>=(t.sv.get(i.id.client)||0));)i=i.left;i!==null&&vt(i,t)&&(e[s]=i.content.getContent()[i.length-1])}),e},Ln=n=>(n.doc??F(),Ti(n._map.entries(),t=>!t[1].deleted)),zn=class extends ne{},re=class n extends v{constructor(){super(),this._prelimContent=[],this._searchMarker=[]}static from(t){let e=new n;return e.push(t),e}_integrate(t,e){super._integrate(t,e),this.insert(0,this._prelimContent),this._prelimContent=null}_copy(){return new n}clone(){let t=new n;return t.insert(0,this.toArray().map(e=>e instanceof v?e.clone():e)),t}get length(){return this.doc??F(),this._length}_callObserver(t,e){super._callObserver(t,e),Qn(this,t,new zn(this,t))}insert(t,e){this.doc!==null?k(this.doc,r=>{xo(r,this,t,e)}):this._prelimContent.splice(t,0,...e)}push(t){this.doc!==null?k(this.doc,e=>{Ca(e,this,t)}):this._prelimContent.push(...t)}unshift(t){this.insert(0,t)}delete(t,e=1){this.doc!==null?k(this.doc,r=>{Eo(r,this,t,e)}):this._prelimContent.splice(t,e)}get(t){return yo(this,t)}toArray(){return mo(this)}slice(t=0,e=this.length){return go(this,t,e)}toJSON(){return this.map(t=>t instanceof v?t.toJSON():t)}map(t){return wo(this,t)}forEach(t){un(this,t)}[Symbol.iterator](){return ka(this)}_write(t){t.writeTypeRef(Ja)}},Aa=n=>new re,Gn=class extends ne{constructor(t,e,r){super(t,e),this.keysChanged=r}},se=class n extends v{constructor(t){super(),this._prelimContent=null,t===void 0?this._prelimContent=new Map:this._prelimContent=new Map(t)}_integrate(t,e){super._integrate(t,e),this._prelimContent.forEach((r,s)=>{this.set(s,r)}),this._prelimContent=null}_copy(){return new n}clone(){let t=new n;return this.forEach((e,r)=>{t.set(r,e instanceof v?e.clone():e)}),t}_callObserver(t,e){Qn(this,t,new Gn(this,t,e))}toJSON(){this.doc??F();let t={};return this._map.forEach((e,r)=>{if(!e.deleted){let s=e.content.getContent()[e.length-1];t[r]=s instanceof v?s.toJSON():s}}),t}get size(){return[...Ln(this)].length}keys(){return vn(Ln(this),t=>t[0])}values(){return vn(Ln(this),t=>t[1].content.getContent()[t[1].length-1])}entries(){return vn(Ln(this),t=>[t[0],t[1].content.getContent()[t[1].length-1]])}forEach(t){this.doc??F(),this._map.forEach((e,r)=>{e.deleted||t(e.content.getContent()[e.length-1],r,this)})}[Symbol.iterator](){return this.entries()}delete(t){this.doc!==null?k(this.doc,e=>{Yn(e,this,t)}):this._prelimContent.delete(t)}set(t,e){return this.doc!==null?k(this.doc,r=>{hs(r,this,t,e)}):this._prelimContent.set(t,e),e}get(t){return fs(this,t)}has(t){return bo(this,t)}clear(){this.doc!==null?k(this.doc,t=>{this.forEach(function(e,r,s){Yn(t,s,r)})}):this._prelimContent.clear()}_write(t){t.writeTypeRef(Ka)}},Ua=n=>new se,Lt=(n,t)=>n===t||typeof n=="object"&&typeof t=="object"&&n&&t&&Ur(n,t),hn=class{constructor(t,e,r,s){this.left=t,this.right=e,this.index=r,this.currentAttributes=s}forward(){this.right===null&&$(),this.right.content.constructor===O?this.right.deleted||Ve(this.currentAttributes,this.right.content):this.right.deleted||(this.index+=this.right.length),this.left=this.right,this.right=this.right.right}},zi=(n,t,e)=>{for(;t.right!==null&&e>0;)t.right.content.constructor===O?t.right.deleted||Ve(t.currentAttributes,t.right.content):t.right.deleted||(e<t.right.length&&z(n,x(t.right.id.client,t.right.id.clock+e)),t.index+=t.right.length,e-=t.right.length),t.left=t.right,t.right=t.right.right;return t},Rn=(n,t,e,r)=>{let s=new Map,i=r?Xn(t,e):null;if(i){let o=new hn(i.p.left,i.p,i.index,s);return zi(n,o,e-i.index)}else{let o=new hn(null,t._start,0,s);return zi(n,o,e)}},Co=(n,t,e,r)=>{for(;e.right!==null&&(e.right.deleted===!0||e.right.content.constructor===O&&Lt(r.get(e.right.content.key),e.right.content.value));)e.right.deleted||r.delete(e.right.content.key),e.forward();let s=n.doc,i=s.clientID;r.forEach((o,c)=>{let l=e.left,a=e.right,d=new C(x(i,U(s.store,i)),l,l&&l.lastId,a,a&&a.id,t,null,new O(c,o));d.integrate(n,0),e.right=d,e.forward()})},Ve=(n,t)=>{let{key:e,value:r}=t;r===null?n.delete(e):n.set(e,r)},Do=(n,t)=>{for(;n.right!==null;){if(!(n.right.deleted||n.right.content.constructor===O&&Lt(t[n.right.content.key]??null,n.right.content.value)))break;n.forward()}},Ao=(n,t,e,r)=>{let s=n.doc,i=s.clientID,o=new Map;for(let c in r){let l=r[c],a=e.currentAttributes.get(c)??null;if(!Lt(a,l)){o.set(c,a);let{left:d,right:u}=e;e.right=new C(x(i,U(s.store,i)),d,d&&d.lastId,u,u&&u.id,t,null,new O(c,l)),e.right.integrate(n,0),e.forward()}}return o},jr=(n,t,e,r,s)=>{e.currentAttributes.forEach((h,f)=>{s[f]===void 0&&(s[f]=null)});let i=n.doc,o=i.clientID;Do(e,s);let c=Ao(n,t,e,s),l=r.constructor===String?new lt(r):r instanceof v?new nt(r):new kt(r),{left:a,right:d,index:u}=e;t._searchMarker&&dn(t._searchMarker,e.index,l.getLength()),d=new C(x(o,U(i.store,o)),a,a&&a.lastId,d,d&&d.id,t,null,l),d.integrate(n,0),e.right=d,e.index=u,e.forward(),Co(n,t,e,c)},Gi=(n,t,e,r,s)=>{let i=n.doc,o=i.clientID;Do(e,s);let c=Ao(n,t,e,s);t:for(;e.right!==null&&(r>0||c.size>0&&(e.right.deleted||e.right.content.constructor===O));){if(!e.right.deleted)switch(e.right.content.constructor){case O:{let{key:l,value:a}=e.right.content,d=s[l];if(d!==void 0){if(Lt(d,a))c.delete(l);else{if(r===0)break t;c.set(l,a)}e.right.delete(n)}else e.currentAttributes.set(l,a);break}default:r<e.right.length&&z(n,x(e.right.id.client,e.right.id.clock+r)),r-=e.right.length;break}e.forward()}if(r>0){let l="";for(;r>0;r--)l+=` | |
| 2 | -`;e.right=new C(x(o,U(i.store,o)),e.left,e.left&&e.left.lastId,e.right,e.right&&e.right.id,t,null,new lt(l)),e.right.integrate(n,0),e.forward()}Co(n,t,e,c)},Uo=(n,t,e,r,s)=>{let i=t,o=T();for(;i&&(!i.countable||i.deleted);){if(!i.deleted&&i.content.constructor===O){let a=i.content;o.set(a.key,a)}i=i.right}let c=0,l=!1;for(;t!==i;){if(e===t&&(l=!0),!t.deleted){let a=t.content;if(a.constructor===O){let{key:d,value:u}=a,h=r.get(d)??null;(o.get(d)!==a||h===u)&&(t.delete(n),c++,!l&&(s.get(d)??null)===u&&h!==u&&(h===null?s.delete(d):s.set(d,h))),!l&&!t.deleted&&Ve(s,a)}}t=t.right}return c},Ta=(n,t)=>{for(;t&&t.right&&(t.right.deleted||!t.right.countable);)t=t.right;let e=new Set;for(;t&&(t.deleted||!t.countable);){if(!t.deleted&&t.content.constructor===O){let r=t.content.key;e.has(r)?t.delete(n):e.add(r)}t=t.left}},To=n=>{let t=0;return k(n.doc,e=>{let r=n._start,s=n._start,i=T(),o=bn(i);for(;s;)s.deleted===!1&&(s.content.constructor===O?Ve(o,s.content):(t+=Uo(e,r,s,i,o),i=bn(o),r=s)),s=s.right}),t},Ia=n=>{let t=new Set,e=n.doc;for(let[r,s]of n.afterState.entries()){let i=n.beforeState.get(r)||0;s!==i&&to(n,e.store.clients.get(r),i,s,o=>{!o.deleted&&o.content.constructor===O&&o.constructor!==G&&t.add(o.parent)})}k(e,r=>{Xt(n,n.deleteSet,s=>{if(s instanceof G||!s.parent._hasFormatting||t.has(s.parent))return;let i=s.parent;s.content.constructor===O?t.add(i):Ta(r,s)});for(let s of t)To(s)})},Hi=(n,t,e)=>{let r=e,s=bn(t.currentAttributes),i=t.right;for(;e>0&&t.right!==null;){if(t.right.deleted===!1)switch(t.right.content.constructor){case nt:case kt:case lt:e<t.right.length&&z(n,x(t.right.id.client,t.right.id.clock+e)),e-=t.right.length,t.right.delete(n);break}t.forward()}i&&Uo(n,i,t.right,s,t.currentAttributes);let o=(t.left||t.right).parent;return o._searchMarker&&dn(o._searchMarker,t.index,-r+e),t},Hn=class extends ne{constructor(t,e,r){super(t,e),this.childListChanged=!1,this.keysChanged=new Set,r.forEach(s=>{s===null?this.childListChanged=!0:this.keysChanged.add(s)})}get changes(){if(this._changes===null){let 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){let t=this.target.doc,e=[];k(t,r=>{let s=new Map,i=new Map,o=this.target._start,c=null,l={},a="",d=0,u=0,h=()=>{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},s.size>0&&(f.attributes={},s.forEach((p,g)=>{p!==null&&(f.attributes[g]=p)}))),a="";break;case"retain":d>0&&(f={retain:d},pi(l)||(f.attributes=ui({},l))),d=0;break}f&&e.push(f),c=null}};for(;o!==null;){switch(o.content.constructor){case nt:case kt:this.adds(o)?this.deletes(o)||(h(),c="insert",a=o.content.getContent()[0],h()):this.deletes(o)?(c!=="delete"&&(h(),c="delete"),u+=1):o.deleted||(c!=="retain"&&(h(),c="retain"),d+=1);break;case lt:this.adds(o)?this.deletes(o)||(c!=="insert"&&(h(),c="insert"),a+=o.content.str):this.deletes(o)?(c!=="delete"&&(h(),c="delete"),u+=o.length):o.deleted||(c!=="retain"&&(h(),c="retain"),d+=o.length);break;case O:{let{key:f,value:p}=o.content;if(this.adds(o)){if(!this.deletes(o)){let g=s.get(f)??null;Lt(g,p)?p!==null&&o.delete(r):(c==="retain"&&h(),Lt(p,i.get(f)??null)?delete l[f]:l[f]=p)}}else if(this.deletes(o)){i.set(f,p);let g=s.get(f)??null;Lt(g,p)||(c==="retain"&&h(),l[f]=g)}else if(!o.deleted){i.set(f,p);let g=l[f];g!==void 0&&(Lt(g,p)?g!==null&&o.delete(r):(c==="retain"&&h(),p===null?delete l[f]:l[f]=p))}o.deleted||(c==="insert"&&h(),Ve(s,o.content));break}}o=o.right}for(h();e.length>0;){let f=e[e.length-1];if(f.retain!==void 0&&f.attributes===void 0)e.pop();else break}}),this._delta=e}return this._delta}},Re=class n extends v{constructor(t){super(),this._pending=t!==void 0?[()=>this.insert(0,t)]:[],this._searchMarker=[],this._hasFormatting=!1}get length(){return this.doc??F(),this._length}_integrate(t,e){super._integrate(t,e);try{this._pending.forEach(r=>r())}catch(r){console.error(r)}this._pending=null}_copy(){return new n}clone(){let t=new n;return t.applyDelta(this.toDelta()),t}_callObserver(t,e){super._callObserver(t,e);let r=new Hn(this,t,e);Qn(this,t,r),!t.local&&this._hasFormatting&&(t._needFormattingCleanup=!0)}toString(){this.doc??F();let t="",e=this._start;for(;e!==null;)!e.deleted&&e.countable&&e.content.constructor===lt&&(t+=e.content.str),e=e.right;return t}toJSON(){return this.toString()}applyDelta(t,{sanitize:e=!0}={}){this.doc!==null?k(this.doc,r=>{let s=new hn(null,this._start,0,new Map);for(let i=0;i<t.length;i++){let o=t[i];if(o.insert!==void 0){let c=!e&&typeof o.insert=="string"&&i===t.length-1&&s.right===null&&o.insert.slice(-1)===` | |
| 3 | -`?o.insert.slice(0,-1):o.insert;(typeof c!="string"||c.length>0)&&jr(r,this,s,c,o.attributes||{})}else o.retain!==void 0?Gi(r,this,s,o.retain,o.attributes||{}):o.delete!==void 0&&Hi(r,s,o.delete)}}):this._pending.push(()=>this.applyDelta(t))}toDelta(t,e,r){this.doc??F();let s=[],i=new Map,o=this.doc,c="",l=this._start;function a(){if(c.length>0){let u={},h=!1;i.forEach((p,g)=>{h=!0,u[g]=p});let f={insert:c};h&&(f.attributes=u),s.push(f),c=""}}let d=()=>{for(;l!==null;){if(vt(l,t)||e!==void 0&&vt(l,e))switch(l.content.constructor){case lt:{let u=i.get("ychange");t!==void 0&&!vt(l,t)?(u===void 0||u.user!==l.id.client||u.type!=="removed")&&(a(),i.set("ychange",r?r("removed",l.id):{type:"removed"})):e!==void 0&&!vt(l,e)?(u===void 0||u.user!==l.id.client||u.type!=="added")&&(a(),i.set("ychange",r?r("added",l.id):{type:"added"})):u!==void 0&&(a(),i.delete("ychange")),c+=l.content.str;break}case nt:case kt:{a();let u={insert:l.content.getContent()[0]};if(i.size>0){let h={};u.attributes=h,i.forEach((f,p)=>{h[p]=f})}s.push(u);break}case O:vt(l,t)&&(a(),Ve(i,l.content));break}l=l.right}a()};return t||e?k(o,u=>{t&&Hr(u,t),e&&Hr(u,e),d()},"cleanup"):d(),s}insert(t,e,r){if(e.length<=0)return;let s=this.doc;s!==null?k(s,i=>{let o=Rn(i,this,t,!r);r||(r={},o.currentAttributes.forEach((c,l)=>{r[l]=c})),jr(i,this,o,e,r)}):this._pending.push(()=>this.insert(t,e,r))}insertEmbed(t,e,r){let s=this.doc;s!==null?k(s,i=>{let o=Rn(i,this,t,!r);jr(i,this,o,e,r||{})}):this._pending.push(()=>this.insertEmbed(t,e,r||{}))}delete(t,e){if(e===0)return;let r=this.doc;r!==null?k(r,s=>{Hi(s,Rn(s,this,t,!0),e)}):this._pending.push(()=>this.delete(t,e))}format(t,e,r){if(e===0)return;let s=this.doc;s!==null?k(s,i=>{let o=Rn(i,this,t,!1);o.right!==null&&Gi(i,this,o,e,r)}):this._pending.push(()=>this.format(t,e,r))}removeAttribute(t){this.doc!==null?k(this.doc,e=>{Yn(e,this,t)}):this._pending.push(()=>this.removeAttribute(t))}setAttribute(t,e){this.doc!==null?k(this.doc,r=>{hs(r,this,t,e)}):this._pending.push(()=>this.setAttribute(t,e))}getAttribute(t){return fs(this,t)}getAttributes(){return _o(this)}_write(t){t.writeTypeRef(qa)}},va=n=>new Re,rn=class{constructor(t,e=()=>!0){this._filter=e,this._root=t,this._currentNode=t._start,this._firstCall=!0,t.doc??F()}[Symbol.iterator](){return this}next(){let t=this._currentNode,e=t&&t.content&&t.content.type;if(t!==null&&(!this._firstCall||t.deleted||!this._filter(e)))do if(e=t.content.type,!t.deleted&&(e.constructor===oe||e.constructor===ie)&&e._start!==null)t=e._start;else for(;t!==null;){let r=t.next;if(r!==null){t=r;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})}},ie=class n extends v{constructor(){super(),this._prelimContent=[]}get firstChild(){let t=this._first;return t?t.content.getContent()[0]:null}_integrate(t,e){super._integrate(t,e),this.insert(0,this._prelimContent),this._prelimContent=null}_copy(){return new n}clone(){let t=new n;return t.insert(0,this.toArray().map(e=>e instanceof v?e.clone():e)),t}get length(){return this.doc??F(),this._prelimContent===null?this._length:this._prelimContent.length}createTreeWalker(t){return new rn(this,t)}querySelector(t){t=t.toUpperCase();let r=new rn(this,s=>s.nodeName&&s.nodeName.toUpperCase()===t).next();return r.done?null:r.value}querySelectorAll(t){return t=t.toUpperCase(),it(new rn(this,e=>e.nodeName&&e.nodeName.toUpperCase()===t))}_callObserver(t,e){Qn(this,t,new $n(this,e,t))}toString(){return wo(this,t=>t.toString()).join("")}toJSON(){return this.toString()}toDOM(t=document,e={},r){let s=t.createDocumentFragment();return r!==void 0&&r._createAssociation(s,this),un(this,i=>{s.insertBefore(i.toDOM(t,e,r),null)}),s}insert(t,e){this.doc!==null?k(this.doc,r=>{xo(r,this,t,e)}):this._prelimContent.splice(t,0,...e)}insertAfter(t,e){if(this.doc!==null)k(this.doc,r=>{let s=t&&t instanceof v?t._item:t;jn(r,this,s,e)});else{let r=this._prelimContent,s=t===null?0:r.findIndex(i=>i===t)+1;if(s===0&&t!==null)throw ut("Reference item not found");r.splice(s,0,...e)}}delete(t,e=1){this.doc!==null?k(this.doc,r=>{Eo(r,this,t,e)}):this._prelimContent.splice(t,e)}toArray(){return mo(this)}push(t){this.insert(this.length,t)}unshift(t){this.insert(0,t)}get(t){return yo(this,t)}slice(t=0,e=this.length){return go(this,t,e)}forEach(t){un(this,t)}_write(t){t.writeTypeRef(Xa)}},Oa=n=>new ie,oe=class n extends ie{constructor(t="UNDEFINED"){super(),this.nodeName=t,this._prelimAttrs=new Map}get nextSibling(){let t=this._item?this._item.next:null;return t?t.content.type:null}get prevSibling(){let t=this._item?this._item.prev:null;return t?t.content.type:null}_integrate(t,e){super._integrate(t,e),this._prelimAttrs.forEach((r,s)=>{this.setAttribute(s,r)}),this._prelimAttrs=null}_copy(){return new n(this.nodeName)}clone(){let t=new n(this.nodeName),e=this.getAttributes();return fi(e,(r,s)=>{t.setAttribute(s,r)}),t.insert(0,this.toArray().map(r=>r instanceof v?r.clone():r)),t}toString(){let t=this.getAttributes(),e=[],r=[];for(let c in t)r.push(c);r.sort();let s=r.length;for(let c=0;c<s;c++){let l=r[c];e.push(l+'="'+t[l]+'"')}let i=this.nodeName.toLocaleLowerCase(),o=e.length>0?" "+e.join(" "):"";return`<${i}${o}>${super.toString()}</${i}>`}removeAttribute(t){this.doc!==null?k(this.doc,e=>{Yn(e,this,t)}):this._prelimAttrs.delete(t)}setAttribute(t,e){this.doc!==null?k(this.doc,r=>{hs(r,this,t,e)}):this._prelimAttrs.set(t,e)}getAttribute(t){return fs(this,t)}hasAttribute(t){return bo(this,t)}getAttributes(t){return t?ko(this,t):_o(this)}toDOM(t=document,e={},r){let s=t.createElement(this.nodeName),i=this.getAttributes();for(let o in i){let c=i[o];typeof c=="string"&&s.setAttribute(o,c)}return un(this,o=>{s.appendChild(o.toDOM(t,e,r))}),r!==void 0&&r._createAssociation(s,this),s}_write(t){t.writeTypeRef(Wa),t.writeKey(this.nodeName)}},La=n=>new oe(n.readKey()),$n=class extends ne{constructor(t,e,r){super(t,r),this.childListChanged=!1,this.attributesChanged=new Set,e.forEach(s=>{s===null?this.childListChanged=!0:this.attributesChanged.add(s)})}},fn=class n extends se{constructor(t){super(),this.hookName=t}_copy(){return new n(this.hookName)}clone(){let t=new n(this.hookName);return this.forEach((e,r)=>{t.set(r,e)}),t}toDOM(t=document,e={},r){let s=e[this.hookName],i;return s!==void 0?i=s.createDom(this):i=document.createElement(this.hookName),i.setAttribute("data-yjs-hook",this.hookName),r!==void 0&&r._createAssociation(i,this),i}_write(t){t.writeTypeRef(Qa),t.writeKey(this.hookName)}},Ra=n=>new fn(n.readKey()),Jn=class n extends Re{get nextSibling(){let t=this._item?this._item.next:null;return t?t.content.type:null}get prevSibling(){let t=this._item?this._item.prev:null;return t?t.content.type:null}_copy(){return new n}clone(){let t=new n;return t.applyDelta(this.toDelta()),t}toDOM(t=document,e,r){let s=t.createTextNode(this.toString());return r!==void 0&&r._createAssociation(s,this),s}toString(){return this.toDelta().map(t=>{let e=[];for(let s in t.attributes){let i=[];for(let o in t.attributes[s])i.push({key:o,value:t.attributes[s][o]});i.sort((o,c)=>o.key<c.key?-1:1),e.push({nodeName:s,attrs:i})}e.sort((s,i)=>s.nodeName<i.nodeName?-1:1);let r="";for(let s=0;s<e.length;s++){let i=e[s];r+=`<${i.nodeName}`;for(let o=0;o<i.attrs.length;o++){let c=i.attrs[o];r+=` ${c.key}="${c.value}"`}r+=">"}r+=t.insert;for(let s=e.length-1;s>=0;s--)r+=`</${e[s].nodeName}>`;return r}).join("")}toJSON(){return this.toString()}_write(t){t.writeTypeRef(Za)}},Na=n=>new Jn,Ne=class{constructor(t,e){this.id=t,this.length=e}get deleted(){throw ct()}mergeWith(t){return!1}write(t,e,r){throw ct()}integrate(t,e){throw ct()}},Ma=0,G=class extends Ne{get deleted(){return!0}delete(){}mergeWith(t){return this.constructor!==t.constructor?!1:(this.length+=t.length,!0)}integrate(t,e){e>0&&(this.id.clock+=e,this.length-=e),Zi(t.doc.store,this)}write(t,e){t.writeInfo(Ma),t.writeLen(this.length-e)}getMissing(t,e){return null}},ce=class n{constructor(t){this.content=t}getLength(){return 1}getContent(){return[this.content]}isCountable(){return!0}copy(){return new n(this.content)}splice(t){throw ct()}mergeWith(t){return!1}integrate(t,e){}delete(t){}gc(t){}write(t,e){t.writeBuf(this.content)}getRef(){return 3}},Va=n=>new ce(n.readBuf()),Me=class n{constructor(t){this.len=t}getLength(){return this.len}getContent(){return[]}isCountable(){return!1}copy(){return new n(this.len)}splice(t){let e=new n(this.len-t);return this.len=t,e}mergeWith(t){return this.len+=t.len,!0}integrate(t,e){on(t.deleteSet,e.id.client,e.id.clock,this.len),e.markDeleted()}delete(t){}gc(t){}write(t,e){t.writeLen(this.len-e)}getRef(){return 1}},Ba=n=>new Me(n.readLen()),Io=(n,t)=>new mt({guid:n,...t,shouldLoad:t.shouldLoad||t.autoLoad||!1}),le=class n{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;let e={};this.opts=e,t.gc||(e.gc=!1),t.autoLoad&&(e.autoLoad=!0),t.meta!==null&&(e.meta=t.meta)}getLength(){return 1}getContent(){return[this.doc]}isCountable(){return!0}copy(){return new n(Io(this.doc.guid,this.opts))}splice(t){throw ct()}mergeWith(t){return!1}integrate(t,e){this.doc._item=e,t.subdocsAdded.add(this.doc),this.doc.shouldLoad&&t.subdocsLoaded.add(this.doc)}delete(t){t.subdocsAdded.has(this.doc)?t.subdocsAdded.delete(this.doc):t.subdocsRemoved.add(this.doc)}gc(t){}write(t,e){t.writeString(this.doc.guid),t.writeAny(this.opts)}getRef(){return 9}},Pa=n=>new le(Io(n.readString(),n.readAny())),kt=class n{constructor(t){this.embed=t}getLength(){return 1}getContent(){return[this.embed]}isCountable(){return!0}copy(){return new n(this.embed)}splice(t){throw ct()}mergeWith(t){return!1}integrate(t,e){}delete(t){}gc(t){}write(t,e){t.writeJSON(this.embed)}getRef(){return 5}},Fa=n=>new kt(n.readJSON()),O=class n{constructor(t,e){this.key=t,this.value=e}getLength(){return 1}getContent(){return[]}isCountable(){return!1}copy(){return new n(this.key,this.value)}splice(t){throw ct()}mergeWith(t){return!1}integrate(t,e){let r=e.parent;r._searchMarker=null,r._hasFormatting=!0}delete(t){}gc(t){}write(t,e){t.writeKey(this.key),t.writeJSON(this.value)}getRef(){return 6}},ja=n=>new O(n.readKey(),n.readJSON()),pn=class n{constructor(t){this.arr=t}getLength(){return this.arr.length}getContent(){return this.arr}isCountable(){return!0}copy(){return new n(this.arr)}splice(t){let e=new n(this.arr.slice(t));return this.arr=this.arr.slice(0,t),e}mergeWith(t){return this.arr=this.arr.concat(t.arr),!0}integrate(t,e){}delete(t){}gc(t){}write(t,e){let r=this.arr.length;t.writeLen(r-e);for(let s=e;s<r;s++){let i=this.arr[s];t.writeString(i===void 0?"undefined":JSON.stringify(i))}}getRef(){return 2}},Ya=n=>{let t=n.readLen(),e=[];for(let r=0;r<t;r++){let s=n.readString();s==="undefined"?e.push(void 0):e.push(JSON.parse(s))}return new pn(e)},za=Ze("node_env")==="development",Mt=class n{constructor(t){this.arr=t,za&&Tr(t)}getLength(){return this.arr.length}getContent(){return this.arr}isCountable(){return!0}copy(){return new n(this.arr)}splice(t){let e=new n(this.arr.slice(t));return this.arr=this.arr.slice(0,t),e}mergeWith(t){return this.arr=this.arr.concat(t.arr),!0}integrate(t,e){}delete(t){}gc(t){}write(t,e){let r=this.arr.length;t.writeLen(r-e);for(let s=e;s<r;s++){let i=this.arr[s];t.writeAny(i)}}getRef(){return 8}},Ga=n=>{let t=n.readLen(),e=[];for(let r=0;r<t;r++)e.push(n.readAny());return new Mt(e)},lt=class n{constructor(t){this.str=t}getLength(){return this.str.length}getContent(){return this.str.split("")}isCountable(){return!0}copy(){return new n(this.str)}splice(t){let e=new n(this.str.slice(t));this.str=this.str.slice(0,t);let r=this.str.charCodeAt(t-1);return r>=55296&&r<=56319&&(this.str=this.str.slice(0,t-1)+"\uFFFD",e.str="\uFFFD"+e.str.slice(1)),e}mergeWith(t){return this.str+=t.str,!0}integrate(t,e){}delete(t){}gc(t){}write(t,e){t.writeString(e===0?this.str:this.str.slice(e))}getRef(){return 4}},Ha=n=>new lt(n.readString()),$a=[Aa,Ua,va,La,Oa,Ra,Na],Ja=0,Ka=1,qa=2,Wa=3,Xa=4,Qa=5,Za=6,nt=class n{constructor(t){this.type=t}getLength(){return 1}getContent(){return[this.type]}isCountable(){return!0}copy(){return new n(this.type._copy())}splice(t){throw ct()}mergeWith(t){return!1}integrate(t,e){this.type._integrate(t.doc,e)}delete(t){let e=this.type._start;for(;e!==null;)e.deleted?e.id.clock<(t.beforeState.get(e.id.client)||0)&&t._mergeStructs.push(e):e.delete(t),e=e.right;this.type._map.forEach(r=>{r.deleted?r.id.clock<(t.beforeState.get(r.id.client)||0)&&t._mergeStructs.push(r):r.delete(t)}),t.changed.delete(this.type)}gc(t){let e=this.type._start;for(;e!==null;)e.gc(t,!0),e=e.right;this.type._start=null,this.type._map.forEach(r=>{for(;r!==null;)r.gc(t,!0),r=r.left}),this.type._map=new Map}write(t,e){this.type._write(t)}getRef(){return 7}},td=n=>new nt($a[n.readTypeRef()](n)),Wr=(n,t)=>{let e=t,r=0,s;do r>0&&(e=x(e.client,e.clock+r)),s=Wt(n,e),r=e.clock-s.id.clock,e=s.redone;while(e!==null&&s instanceof C);return{item:s,diff:r}},ps=(n,t)=>{for(;n!==null&&n.keep!==t;)n.keep=t,n=n.parent._item},Kn=(n,t,e)=>{let{client:r,clock:s}=t.id,i=new C(x(r,s+e),t,x(r,s+e-1),t.right,t.rightOrigin,t.parent,t.parentSub,t.content.splice(e));return t.deleted&&i.markDeleted(),t.keep&&(i.keep=!0),t.redone!==null&&(i.redone=x(t.redone.client,t.redone.clock+e)),t.right=i,i.right!==null&&(i.right.left=i),n._mergeStructs.push(i),i.parentSub!==null&&i.right===null&&i.parent._map.set(i.parentSub,i),t.length=e,i},$i=(n,t)=>$s(n,e=>ae(e.deletions,t)),vo=(n,t,e,r,s,i)=>{let o=n.doc,c=o.store,l=o.clientID,a=t.redone;if(a!==null)return z(n,a);let d=t.parent._item,u=null,h;if(d!==null&&d.deleted===!0){if(d.redone===null&&(!e.has(d)||vo(n,d,e,r,s,i)===null))return null;for(;d.redone!==null;)d=z(n,d.redone)}let f=d===null?t.parent:d.content.type;if(t.parentSub===null){for(u=t.left,h=t;u!==null;){let w=u;for(;w!==null&&w.parent._item!==d;)w=w.redone===null?null:z(n,w.redone);if(w!==null&&w.parent._item===d){u=w;break}u=u.left}for(;h!==null;){let w=h;for(;w!==null&&w.parent._item!==d;)w=w.redone===null?null:z(n,w.redone);if(w!==null&&w.parent._item===d){h=w;break}h=h.right}}else if(h=null,t.right&&!s){for(u=t;u!==null&&u.right!==null&&(u.right.redone||ae(r,u.right.id)||$i(i.undoStack,u.right.id)||$i(i.redoStack,u.right.id));)for(u=u.right;u.redone;)u=z(n,u.redone);if(u&&u.right!==null)return null}else u=f._map.get(t.parentSub)||null;let p=U(c,l),g=x(l,p),m=new C(g,u,u&&u.lastId,h,h&&h.id,f,t.parentSub,t.content.copy());return t.redone=g,ps(m,!0),m.integrate(n,0),m},C=class n extends Ne{constructor(t,e,r,s,i,o,c,l){super(t,l.getLength()),this.origin=r,this.left=e,this.right=s,this.rightOrigin=i,this.parent=o,this.parentSub=c,this.redone=null,this.content=l,this.info=this.content.isCountable()?2:0}set marker(t){(this.info&8)>0!==t&&(this.info^=8)}get marker(){return(this.info&8)>0}get keep(){return(this.info&1)>0}set keep(t){this.keep!==t&&(this.info^=1)}get countable(){return(this.info&2)>0}get deleted(){return(this.info&4)>0}set deleted(t){this.deleted!==t&&(this.info^=4)}markDeleted(){this.info|=4}getMissing(t,e){if(this.origin&&this.origin.client!==this.id.client&&this.origin.clock>=U(e,this.origin.client))return this.origin.client;if(this.rightOrigin&&this.rightOrigin.client!==this.id.client&&this.rightOrigin.clock>=U(e,this.rightOrigin.client))return this.rightOrigin.client;if(this.parent&&this.parent.constructor===_t&&this.id.client!==this.parent.client&&this.parent.clock>=U(e,this.parent.client))return this.parent.client;if(this.origin&&(this.left=Jr(t,e,this.origin),this.origin=this.left.lastId),this.rightOrigin&&(this.right=z(t,this.rightOrigin),this.rightOrigin=this.right.id),this.left&&this.left.constructor===G||this.right&&this.right.constructor===G)this.parent=null;else if(!this.parent)this.left&&this.left.constructor===n?(this.parent=this.left.parent,this.parentSub=this.left.parentSub):this.right&&this.right.constructor===n&&(this.parent=this.right.parent,this.parentSub=this.right.parentSub);else if(this.parent.constructor===_t){let r=Wt(e,this.parent);r.constructor===G?this.parent=null:this.parent=r.content.type}return null}integrate(t,e){if(e>0&&(this.id.clock+=e,this.left=Jr(t,t.doc.store,x(this.id.client,this.id.clock-1)),this.origin=this.left.lastId,this.content=this.content.splice(e),this.length-=e),this.parent){if(!this.left&&(!this.right||this.right.left!==null)||this.left&&this.left.right!==this.right){let r=this.left,s;if(r!==null)s=r.right;else if(this.parentSub!==null)for(s=this.parent._map.get(this.parentSub)||null;s!==null&&s.left!==null;)s=s.left;else s=this.parent._start;let i=new Set,o=new Set;for(;s!==null&&s!==this.right;){if(o.add(s),i.add(s),qt(this.origin,s.origin)){if(s.id.client<this.id.client)r=s,i.clear();else if(qt(this.rightOrigin,s.rightOrigin))break}else if(s.origin!==null&&o.has(Wt(t.doc.store,s.origin)))i.has(Wt(t.doc.store,s.origin))||(r=s,i.clear());else break;s=s.right}this.left=r}if(this.left!==null){let r=this.left.right;this.right=r,this.left.right=this}else{let r;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,this.parent._start=this;this.right=r}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),Zi(t.doc.store,this),this.content.integrate(t,this),Pi(t,this.parent,this.parentSub),(this.parent._item!==null&&this.parent._item.deleted||this.parentSub!==null&&this.right!==null)&&this.delete(t)}else new G(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:x(this.id.client,this.id.clock+this.length-1)}mergeWith(t){if(this.constructor===t.constructor&&qt(t.origin,this.lastId)&&this.right===t&&qt(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)){let e=this.parent._searchMarker;return e&&e.forEach(r=>{r.p===t&&(r.p=this,!this.deleted&&this.countable&&(r.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){let e=this.parent;this.countable&&this.parentSub===null&&(e._length-=this.length),this.markDeleted(),on(t.deleteSet,this.id.client,this.id.clock,this.length),Pi(t,e,this.parentSub),this.content.delete(t)}}gc(t,e){if(!this.deleted)throw $();this.content.gc(t),e?ca(t,this,new G(this.id,this.length)):this.content=new Me(this.length)}write(t,e){let r=e>0?x(this.id.client,this.id.clock+e-1):this.origin,s=this.rightOrigin,i=this.parentSub,o=this.content.getRef()&31|(r===null?0:128)|(s===null?0:64)|(i===null?0:32);if(t.writeInfo(o),r!==null&&t.writeLeftID(r),s!==null&&t.writeRightID(s),r===null&&s===null){let c=this.parent;if(c._item!==void 0){let l=c._item;if(l===null){let a=cs(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===_t?(t.writeParentInfo(!1),t.writeLeftID(c)):$();i!==null&&t.writeString(i)}this.content.write(t,e)}},Oo=(n,t)=>ed[t&31](n),ed=[()=>{$()},Ba,Ya,Va,Ha,Fa,ja,td,Ga,Pa,()=>{$()}],nd=10,P=class extends Ne{get deleted(){return!0}delete(){}mergeWith(t){return this.constructor!==t.constructor?!1:(this.length+=t.length,!0)}integrate(t,e){$()}write(t,e){t.writeInfo(nd),S(t.restEncoder,this.length-e)}getMissing(t,e){return null}},Lo=typeof globalThis<"u"?globalThis:typeof window<"u"?window:typeof global<"u"?global:{},Ro="__ $YJS$ __";Lo[Ro]===!0&&console.error("Yjs was already imported. This breaks constructor checks and will lead to issues! - https://github.com/yjs/yjs/issues/438");Lo[Ro]=!0;var gs=3e4,Be=class extends ye{constructor(t){super(),this.doc=t,this.clientID=t.clientID,this.states=new Map,this.meta=new Map,this._checkInterval=setInterval(()=>{let e=It();this.getLocalState()!==null&&gs/2<=e-this.meta.get(this.clientID).lastUpdated&&this.setLocalState(this.getLocalState());let r=[];this.meta.forEach((s,i)=>{i!==this.clientID&&gs<=e-s.lastUpdated&&this.states.has(i)&&r.push(i)}),r.length>0&&ms(this,r,"timeout")},W(gs/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){let e=this.clientID,r=this.meta.get(e),s=r===void 0?0:r.clock+1,i=this.states.get(e);t===null?this.states.delete(e):this.states.set(e,t),this.meta.set(e,{clock:s,lastUpdated:It()});let o=[],c=[],l=[],a=[];t===null?a.push(e):i==null?t!=null&&o.push(e):(c.push(e),Xe(i,t)||l.push(e)),(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,e){let r=this.getLocalState();r!==null&&this.setLocalState({...r,[t]:e})}getStates(){return this.states}},ms=(n,t,e)=>{let r=[];for(let s=0;s<t.length;s++){let i=t[s];if(n.states.has(i)){if(n.states.delete(i),i===n.clientID){let o=n.meta.get(i);n.meta.set(i,{clock:o.clock+1,lastUpdated:It()})}r.push(i)}}r.length>0&&(n.emit("change",[{added:[],updated:[],removed:r},e]),n.emit("update",[{added:[],updated:[],removed:r},e]))};var No=1,Zn="fromPersistence",tr="document",Pe="state",de="savedAt",Mo="savedBy",Vo="version",er="gutenberg",ws="syncManager",Bo="gutenberg-undo-ignored";var Fe=(n=>(n.AUTHENTICATION_FAILED="authentication-failed",n.CONNECTION_EXPIRED="connection-expired",n.CONNECTION_LIMIT_EXCEEDED="connection-limit-exceeded",n.DOCUMENT_SIZE_LIMIT_EXCEEDED="document-size-limit-exceeded",n.UNKNOWN_ERROR="unknown-error",n))(Fe||{}),ys=class extends Error{constructor(n="unknown-error",t){super(t),this.code=n,this.name="ConnectionError"}};var jo=Yt(Fo(),1),{lock:Yo,unlock:wu}=(0,jo.__dangerousOptInToUnstableAPIsOnlyForCoreModules)("I acknowledge private features are not for use in themes or plugins and doing so will break in the next version of WordPress.","@wordpress/sync");function zo(n){return function(...t){let e=performance.now(),r=n.apply(this,t),s=performance.now();return console.log(`[SyncManager][performance]: ${n.name} took ${(s-e).toFixed(2)} ms`),r}}function Go(n){return((...t)=>n(...t))}function Ho(n){return function(...t){setTimeout(()=>{n.apply(this,t)},0)}}var pc=Yt(nr(),1);var ac=Yt(nr(),1);var Jo=0,Ko=1,rd=2,qo=(n,t)=>{S(n,Jo);let e=os(t);V(n,e)},sd=(n,t,e)=>{S(n,Ko),V(n,rs(t,e))},id=(n,t,e)=>sd(t,e,B(n)),Wo=(n,t,e,r)=>{try{ns(t,B(n),e)}catch(s){r?.(s),console.error("Caught error while handling a Yjs update",s)}};var od=Wo,Ss=(n,t,e,r,s)=>{let i=E(n);switch(i){case Jo:id(n,t,e);break;case Ko:Wo(n,e,r,s);break;case rd:od(n,e,r,s);break;default:throw new Error("Unknown message type")}return i};var xs=Yt(nr(),1),Es=3,Xo=[2e3,4e3,8e3,12e3],Qo=[1e3,2e3,4e3,8e3],Zo=3e4,tc=15e3,_s=1*1024*1024,bs=(0,xs.applyFilters)("sync.pollingManager.pollingInterval",4e3),ec=(0,xs.applyFilters)("sync.pollingManager.pollingIntervalWithCollaborators",1e3),nc=25*1e3;var K=(n=>(n.COMPACTION="compaction",n.SYNC_STEP_1="sync_step1",n.SYNC_STEP_2="sync_step2",n.UPDATE="update",n))(K||{});var ks=Yt(sc(),1);var ic="/wp-sync/v1/updates";function ld(n){let t="",e=n.byteLength;for(let r=0;r<e;r++)t+=String.fromCharCode(n[r]);return globalThis.btoa(t)}function Cs(n){let t=globalThis.atob(n),e=t.length,r=new Uint8Array(e);for(let s=0;s<e;s++)r[s]=t.charCodeAt(s);return r}function je(n,t){return{data:ld(n),type:t}}function oc(n=[],t=!0){let e=t,r=[...n];return{add(s){r.push(s)},addBulk(s){s.length!==0&&r.push(...s)},clear(){r.splice(0,r.length)},get(){return e?[]:r.splice(0,r.length)},pause(){e=!0},restore(s){let i=s.filter(o=>o.type!==K.COMPACTION);i.length!==0&&r.unshift(...i)},resume(){e=!1},size(){return r.length}}}function cc(n){return(0,ks.default)({method:"POST",path:ic,data:n})}function Ds(n){n.rooms.length!==0&&(0,ks.default)({method:"POST",path:ic,data:n,keepalive:!0}).catch(()=>{})}function lc(n,t){let e=parseInt(String(n),10);return isNaN(e)?t:e}var wn="polling-manager";function ad(n){return n?.data?.status===403}function dd(n,t){let e=typeof n.message=="string"?n.message:"",r=[...t].sort((s,i)=>i.length-s.length);for(let s of r)if(e.includes(s))return s;return null}function ud(n,t){let e=dd(n,t.map(r=>r.room));if(e){let r=A.get(e);r&&(r.log("Permission denied, unregistering room",{error:n},"error",!0),yn(e,{sendDisconnectSignal:!1}));for(let s of t){if(s.room===e||!A.has(s.room))continue;let i=A.get(s.room);s.updates.length>0&&i.updateQueue.restore(s.updates)}}else{let r=[...A.keys()];for(let s of r){let i=A.get(s);i&&(i.log("Permission denied, unregistering room",{error:n},"error",!0),yn(s,{sendDisconnectSignal:!1}))}}}var A=new Map;function hd(n){let t=n.filter(e=>[K.COMPACTION,K.UPDATE].includes(e.type)).map(e=>Cs(e.data));return je(ee(t),K.COMPACTION)}function fd(n){let t=ot();return qo(t,n),je(Y(t),K.SYNC_STEP_1)}function pd(n,t){let e=L(t),r=ot();return Ss(e,r,n,wn),je(Y(r),K.SYNC_STEP_2)}function gd(n,t){let e=t.getStates(),r=new Set,s=new Set,i=new Set(Array.from(e.keys()).filter(o=>!n[o]));Object.entries(n).forEach(([o,c])=>{let l=Number(o);if(l===t.clientID)return;if(c===null){e.delete(l),i.add(l);return}if(!e.has(l)){e.set(l,c),r.add(l);return}let a=e.get(l);JSON.stringify(a)!==JSON.stringify(c)&&(e.set(l,c),s.add(l))}),r.size+s.size>0&&t.emit("change",[{added:Array.from(r),updated:Array.from(s),removed:[]}]),i.size>0&&ms(t,Array.from(i),wn)}function md(n,t,e){let r=Cs(n.data);switch(n.type){case K.SYNC_STEP_1:return pd(t,r);case K.SYNC_STEP_2:{let s=L(r),i=ot();Ss(s,i,t,wn),e();return}case K.COMPACTION:case K.UPDATE:St(t,r,wn)}}function wd(n,t){if(!t.isPrimaryRoom||As)return!1;As=!0;let e=(0,ac.applyFilters)("sync.pollingProvider.maxClientsPerRoom",Es,t.room),r=Object.keys(n).length,s=lc(e,Es);return r>s?(t.log("Connection limit exceeded",{clientCount:r,maxClientsPerRoom:s,room:t.room}),!0):!1}var or=!1,ue=0,As=!1,sr=!1,rr=!1,mn=document.visibilityState==="visible",ir=!1,Us=!1,Ct=bs,Pt=null;function dc(){Us=!0}function uc(){let n=Array.from(A.entries()).map(([t,e])=>({after:0,awareness:null,client_id:e.clientId,room:t,updates:[]}));Ds({rooms:n})}function hc(){let n=mn;mn=document.visibilityState==="visible",mn&&!n&&Pt&&(clearTimeout(Pt),Pt=null,cr())}function cr(){ir=!0,Pt=null;async function n(){if(A.size===0){ir=!1;return}Us=!1,A.forEach(e=>{e.onStatusChange({status:"connecting"})});let t={rooms:Array.from(A.entries()).map(([e,r])=>({after:r.endCursor??0,awareness:r.localAwarenessState,client_id:r.clientId,room:e,updates:r.updateQueue.get()}))};try{let{rooms:e}=await cc(t);ue=0,sr=!1,A.forEach(r=>{r.onStatusChange({status:"connected"})}),rr=!1,e.forEach(r=>{if(!A.has(r.room))return;let s=A.get(r.room);if(s.endCursor=r.end_cursor,wd(r.awareness,s)){s.onStatusChange({status:"disconnected",error:new ys(Fe.CONNECTION_LIMIT_EXCEEDED,"Connection limit exceeded")}),yn(r.room);return}s.processAwarenessUpdate(r.awareness),s.isPrimaryRoom&&Object.keys(r.awareness).length>1&&(rr=!0,A.forEach(o=>{o.updateQueue.resume()}));let i=[];for(let o of r.updates)try{let c=s.processDocUpdate(o);c&&i.push(c)}catch(c){s.log("Failed to apply sync update",{error:c,update:o},"error",!0)}s.updateQueue.addBulk(i),r.should_compact?(s.log("Server requested compaction update"),s.updateQueue.clear(),s.updateQueue.add(s.createCompactionUpdate())):r.compaction_request&&(s.log("Server requested (old) compaction update"),s.updateQueue.add(hd(r.compaction_request)))}),mn&&rr?Ct=ec:mn?Ct=bs:Ct=nc}catch(e){if(ad(e)){if(ud(e,t.rooms),A.size===0){ir=!1;return}}else{ue++;let r=rr?Qo:Xo;ue<=r.length?Ct=r[ue-1]:Ct=Zo,sr&&(Ct=tc,sr=!1);for(let s of t.rooms){if(!A.has(s.room))continue;let i=A.get(s.room);s.updates.length>0&&i.endCursor>0?(i.updateQueue.clear(),i.updateQueue.add(i.createCompactionUpdate())):s.updates.length>0&&i.updateQueue.restore(s.updates),i.log("Error posting sync update, will retry with backoff",{error:e,nextPoll:Ct},"error",!0)}if(!Us){let s=ue>r.length;A.forEach(i=>{i.onStatusChange({status:"disconnected",canManuallyRetry:!0,consecutiveFailures:ue,backgroundRetriesFailed:s,willAutoRetryInMs:Ct})})}}}Pt=setTimeout(cr,Ct)}n()}function yd({room:n,doc:t,awareness:e,log:r,onSync:s,onStatusChange:i}){if(A.has(n))return;let o=oc([fd(t)]),c=A.size===0;function l(){u.localAwarenessState=e.getLocalState()??{}}function a(h,f){if(wn!==f){if(h.byteLength>_s){let p=A.get(n);if(!p)return;p.log("Document size limit exceeded",{maxUpdateSizeInBytes:_s,updateSizeInBytes:h.byteLength}),p.onStatusChange({status:"disconnected",error:new ys(Fe.DOCUMENT_SIZE_LIMIT_EXCEEDED,"Document size limit exceeded")}),yn(n)}o.add(je(h,K.UPDATE))}}function d(){t.off("updateV2",a),e.off("change",l),o.clear()}let u={clientId:t.clientID,createCompactionUpdate:()=>je(Vt(t),K.COMPACTION),endCursor:0,isPrimaryRoom:c,localAwarenessState:e.getLocalState()??{},log:r,onStatusChange:i,processAwarenessUpdate:h=>gd(h,e),processDocUpdate:h=>md(h,t,s),room:n,unregister:d,updateQueue:o};t.on("updateV2",a),e.on("change",l),A.set(n,u),or||(window.addEventListener("beforeunload",dc),window.addEventListener("pagehide",uc),document.addEventListener("visibilitychange",hc),or=!0),ir||cr()}function yn(n,{sendDisconnectSignal:t=!0}={}){let e=A.get(n);if(e){if(t){let r=[{after:0,awareness:null,client_id:e.clientId,room:n,updates:[]}];Ds({rooms:r})}e.unregister(),A.delete(n)}A.size===0&&or&&(window.removeEventListener("beforeunload",dc),window.removeEventListener("pagehide",uc),document.removeEventListener("visibilitychange",hc),or=!1,As=!1,ue=0)}function Sd(){sr=!0,Pt&&(clearTimeout(Pt),Pt=null,cr())}var Sn={registerRoom:yd,retryNow:Sd,unregisterRoom:yn};var xd=class extends Dt{constructor(n){super(),this.options=n,this.log("Initializing",{room:n.room}),this.awareness=n.awareness??new Be(n.ydoc),this.connect()}awareness;status="disconnected";synced=!1;connect(){this.log("Connecting"),Sn.registerRoom({room:this.options.room,doc:this.options.ydoc,awareness:this.awareness,log:this.log,onStatusChange:this.emitStatus,onSync:this.onSync})}destroy(){this.disconnect(),super.destroy()}disconnect(){this.log("Disconnecting"),Sn.unregisterRoom(this.options.room),this.emitStatus({status:"disconnected"})}emitStatus=n=>{let{status:t}=n,e=t==="disconnected"?n.error:void 0;this.status===t&&!e||t==="connecting"&&this.status!=="disconnected"||(this.log("Status change",{status:t,error:e}),this.status=t,this.emit("status",[n]))};log=(n,t={},e="log",r=!1)=>{if(!this.options.debug&&!r)return;(console[e]||console.log)(`[${this.constructor.name}]: ${n}`,{room:this.options.room,...t})};onSync=()=>{this.synced||(this.synced=!0,this.log("Synced"))}};function fc(){return async({awareness:n,objectType:t,objectId:e,ydoc:r})=>{let s=e?`${t}:${e}`:t,i=new xd({awareness:n,room:s,ydoc:r});return{destroy:()=>i.destroy(),on:(o,c)=>{i.on(o,c)}}}}var Ye=null;function Ed(){return[fc()]}function _d(n){return typeof n=="function"}function Ts(){if(Ye)return Ye;if(!window._wpCollaborationEnabled)return[];let n=(0,pc.applyFilters)("sync.providers",Ed());return Array.isArray(n)?(Ye=n.filter(_d),Ye):(Ye=[],Ye)}var gc=(n,t)=>{let e=t==="undo"?n.undoStack:n.redoStack;for(;e.length>0;){let r=e.pop(),s=t==="undo"?r.undoStack:r.redoStack,i=s.pop(),o=!1;if(t==="undo"?(r.undoStack=[i],o=r.undo()!==null,r.undoStack=s):(r.redoStack=[i],o=r.redo()!==null,r.redoStack=s),o)return i}return null},mc=class extends ye{constructor(n=[],t={}){super(),this.docs=new Map,this.trackedOrigins=t.trackedOrigins||new Set([null]),t.trackedOrigins=this.trackedOrigins,this._defaultOpts=t,this.undoStack=[],this.redoStack=[],this.addToScope(n)}addToScope(n){n=zt(n)?n:[n],n.forEach(t=>{let e=t.doc,r=N(this.docs,e,()=>{let s=new te([t],this._defaultOpts);return s.on("stack-cleared",({undoStackCleared:i,redoStackCleared:o})=>{this.clear(i,o)}),e.on("destroy",()=>{this.docs.delete(e),this.undoStack=this.undoStack.filter(i=>i.doc!==e),this.redoStack=this.redoStack.filter(i=>i.doc!==e)}),s.on("stack-item-added",i=>{(i.type==="undo"?this.undoStack:this.redoStack).push(s),this.emit("stack-item-added",[{...i,ydoc:e},this])}),s.on("stack-item-updated",i=>{this.emit("stack-item-updated",[{...i,ydoc:e},this])}),s.on("stack-item-popped",i=>{this.emit("stack-item-popped",[{...i,ydoc:e},this])}),s});r.scope.every(s=>s!==t)&&r.scope.push(t)})}addTrackedOrigin(n){this.trackedOrigins.add(n)}removeTrackedOrigin(n){this.trackedOrigins.delete(n)}undo(){return gc(this,"undo")}redo(){return gc(this,"redo")}clear(n=!0,t=!0){(n&&this.canUndo()||t&&this.canRedo())&&(this.docs.forEach(e=>{n&&(this.undoStack=[]),t&&(this.redoStack=[]),e.clear(n,t)}),this.emit("stack-cleared",[{undoStackCleared:n,redoStackCleared:t}]))}stopCapturing(){this.docs.forEach(n=>{n.stopCapturing()})}canUndo(){return this.undoStack.length>0}canRedo(){return this.redoStack.length>0}destroy(){this.docs.forEach(n=>n.destroy()),super.destroy()}};function wc(){let n=new mc([],{captureTimeout:500,trackedOrigins:new Set([er])});return{addRecord(t,e=!1){},addToScope(t,e){if(t.doc===null)return;let r=t.doc;n.addToScope(t);let{addUndoMeta:s,restoreUndoMeta:i}=e;n.on("stack-item-added",o=>{s(r,o.stackItem.meta)}),n.on("stack-item-popped",o=>{i(r,o.stackItem.meta)})},undo(){if(n.canUndo())return n.undo(),[]},redo(){if(n.canRedo())return n.redo(),[]},hasUndo(){return n.canUndo()},hasRedo(){return n.canRedo()},stopCapturing(){n.stopCapturing()}}}function lr(n={}){let t=new Map(Object.entries(n));return new mt({meta:t})}function Is(n){n.getMap(Pe).set(Vo,No)}function vs(n){let t=n.getMap(Pe);t.set(de,Date.now()),t.set(Mo,n.clientID)}function yc(){return Math.floor(Math.random()*1e9)}function Sc(n){return JSON.stringify({document:xi(Vt(n)),updateId:yc()})}function xc(n){try{let{document:t}=JSON.parse(n),e={[Zn]:!0},r=lr(e),s=Ei(t);return St(r,s),r.clientID=yc(),r}catch{return null}}function Ft(n,t){return`${n}_${t}`}function Ec(n=!1){let t=n?zo:Go,e=new Map,r=new Map,s;function i(g,m,w,y={}){n&&console.log(`[SyncManager][${g}]: ${m}`,{...y,entityId:w})}async function o(g,m,w,y,_){let b=Ts(),D=Ft(m,w);if(b.length===0){i("loadEntity","no providers, skipping",D);return}if(r.has(D)){i("loadEntity","already loaded",D);return}if(g.shouldSync?.(m,w)===!1){i("loadEntity","shouldSync false, skipping",D);return}i("loadEntity","loading",D),_={addUndoMeta:t(_.addUndoMeta),editRecord:t(_.editRecord),getEditedRecord:t(_.getEditedRecord),onStatusChange:t(_.onStatusChange),persistCRDTDoc:t(_.persistCRDTDoc),refetchRecord:t(_.refetchRecord),restoreUndoMeta:t(_.restoreUndoMeta)};let I=lr({objectType:m}),j=I.getMap(tr),R=I.getMap(Pe),xt=Date.now(),Z=()=>{i("loadEntity","unloading",D),Uc.forEach(me=>me.destroy()),_.onStatusChange(null),j.unobserveDeep(at),R.unobserve(st),I.destroy(),r.delete(D)},pe=g.createAwareness?.(I,w),at=(me,jt)=>{jt.local&&!(jt.origin instanceof te)||p.updateEntityRecord(m,w)},st=(me,jt)=>{jt.local||me.keysChanged.forEach(Tc=>{if(Tc===de){let Fs=R.get(de);typeof Fs=="number"&&Fs>xt&&(i("loadEntity","refetching record",D),_.refetchRecord().catch(()=>{}))}})};s||(s=wc());let{addUndoMeta:ze,restoreUndoMeta:ge}=_;s.addToScope(j,{addUndoMeta:ze,restoreUndoMeta:ge});let xn={awareness:pe,handlers:_,objectId:w,objectType:m,syncConfig:g,unload:Z,ydoc:I};r.set(D,xn),i("loadEntity","connecting",D);let Uc=await Promise.all(b.map(async me=>{let jt=await me({objectType:m,objectId:w,ydoc:I,awareness:pe});return jt.on("status",_.onStatusChange),jt}));j.observeDeep(at),R.observe(st),Is(I),p.applyPersistedCrdtDoc(m,w,y)}async function c(g,m,w){let y=Ts(),_=Ft(m,null);if(y.length===0){i("loadCollection","no providers, skipping",_);return}if(e.has(m)){i("loadCollection","already loaded",_);return}if(g.shouldSync?.(m,null)===!1){i("loadCollection","shouldSync false, skipping",_);return}i("loadCollection","loading",_);let b=lr({collection:!0,objectType:m}),D=b.getMap(Pe),I=Date.now(),j=()=>{i("loadCollection","unloading",_),pe.forEach(at=>at.destroy()),w.onStatusChange(null),D.unobserve(R),b.destroy(),e.delete(m)},R=(at,st)=>{st.local||at.keysChanged.forEach(ze=>{if(ze===de){let ge=D.get(de);typeof ge=="number"&&ge>I&&w.refetchRecords().catch(()=>{})}})},xt=g.createAwareness?.(b),Z={awareness:xt,handlers:w,syncConfig:g,unload:j,ydoc:b};e.set(m,Z),i("loadCollection","connecting",_);let pe=await Promise.all(y.map(async at=>{let st=await at({awareness:xt,objectType:m,objectId:null,ydoc:b});return st.on("status",w.onStatusChange),st}));D.observe(R),Is(b)}function l(g,m){let w=Ft(g,m);i("unloadEntity","unloading",w),r.get(w)?.unload(),u(g,null,{},origin,{isSave:!0})}function a(g,m){let w=Ft(g,m),y=r.get(w);if(!(!y||!y.awareness))return y.awareness}function d(g,m,w){let y=Ft(g,m),_=r.get(y);if(!_){i("applyPersistedCrdtDoc","no entity state",y);return}let{handlers:b,syncConfig:{applyChangesToCRDTDoc:D,getChangesFromCRDTDoc:I,getPersistedCRDTDoc:j},ydoc:R}=_,xt=j?.(w),Z=xt?xc(xt):null;if(!Z){i("applyPersistedCrdtDoc","no persisted doc",y),R.transact(()=>{D(R,w),b.persistCRDTDoc()},ws);return}let pe=Vt(Z);St(R,pe);let at=I(Z,w),st=Object.keys(at);if(Z.destroy(),st.length===0){i("applyPersistedCrdtDoc","valid persisted doc",y);return}i("applyPersistedCrdtDoc","invalidated keys",y,{invalidatedKeys:st});let ze=st.reduce((ge,xn)=>Object.assign(ge,{[xn]:w[xn]}),{});R.transact(()=>{D(R,ze),b.persistCRDTDoc()},ws)}function u(g,m,w,y,_={}){let{isSave:b=!1,isNewUndoLevel:D=!1}=_,I=Ft(g,m),j=r.get(I),R=e.get(g);if(j){let{syncConfig:xt,ydoc:Z}=j;D&&s&&s.stopCapturing?.(),Z.transact(()=>{i("updateCRDTDoc","applying changes",I,{changedKeys:Object.keys(w)}),xt.applyChangesToCRDTDoc(Z,w),b&&vs(Z)},y)}R&&b&&R.ydoc.transact(()=>{vs(R.ydoc)},y)}async function h(g,m){let w=Ft(g,m),y=r.get(w);if(!y){i("updateEntityRecord","no entity state",w);return}let{handlers:_,syncConfig:b,ydoc:D}=y,I=b.getChangesFromCRDTDoc(D,await _.getEditedRecord()),j=Object.keys(I);j.length!==0&&(i("updateEntityRecord","changes",w,{changedKeys:j}),_.editRecord(I))}async function f(g,m){let w=Ft(g,m),y=r.get(w);return y?.ydoc?(await new Promise(_=>setTimeout(_,0)),Sc(y.ydoc)):null}let p={applyPersistedCrdtDoc:t(d),updateEntityRecord:t(h)};return{createPersistedCRDTDoc:t(f),getAwareness:a,load:t(o),loadCollection:t(c),get undoManager(){return s},unload:t(l),update:t(Ho(u))}}var he=class{diff(t,e,r={}){let s;typeof r=="function"?(s=r,r={}):"callback"in r&&(s=r.callback);let i=this.castInput(t,r),o=this.castInput(e,r),c=this.removeEmpty(this.tokenize(i,r)),l=this.removeEmpty(this.tokenize(o,r));return this.diffWithOptionsObj(c,l,r,s)}diffWithOptionsObj(t,e,r,s){var i;let o=y=>{if(y=this.postProcess(y,r),s){setTimeout(function(){s(y)},0);return}else return y},c=e.length,l=t.length,a=1,d=c+l;r.maxEditLength!=null&&(d=Math.min(d,r.maxEditLength));let u=(i=r.timeout)!==null&&i!==void 0?i:1/0,h=Date.now()+u,f=[{oldPos:-1,lastComponent:void 0}],p=this.extractCommon(f[0],e,t,0,r);if(f[0].oldPos+1>=l&&p+1>=c)return o(this.buildValues(f[0].lastComponent,e,t));let g=-1/0,m=1/0,w=()=>{for(let y=Math.max(g,-a);y<=Math.min(m,a);y+=2){let _,b=f[y-1],D=f[y+1];b&&(f[y-1]=void 0);let I=!1;if(D){let R=D.oldPos-y;I=D&&0<=R&&R<c}let j=b&&b.oldPos+1<l;if(!I&&!j){f[y]=void 0;continue}if(!j||I&&b.oldPos<D.oldPos?_=this.addToPath(D,!0,!1,0,r):_=this.addToPath(b,!1,!0,1,r),p=this.extractCommon(_,e,t,y,r),_.oldPos+1>=l&&p+1>=c)return o(this.buildValues(_.lastComponent,e,t))||!0;f[y]=_,_.oldPos+1>=l&&(m=Math.min(m,y-1)),p+1>=c&&(g=Math.max(g,y+1))}a++};if(s)(function y(){setTimeout(function(){if(a>d||Date.now()>h)return s(void 0);w()||y()},0)})();else for(;a<=d&&Date.now()<=h;){let y=w();if(y)return y}}addToPath(t,e,r,s,i){let o=t.lastComponent;return o&&!i.oneChangePerToken&&o.added===e&&o.removed===r?{oldPos:t.oldPos+s,lastComponent:{count:o.count+1,added:e,removed:r,previousComponent:o.previousComponent}}:{oldPos:t.oldPos+s,lastComponent:{count:1,added:e,removed:r,previousComponent:o}}}extractCommon(t,e,r,s,i){let o=e.length,c=r.length,l=t.oldPos,a=l-s,d=0;for(;a+1<o&&l+1<c&&this.equals(r[l+1],e[a+1],i);)a++,l++,d++,i.oneChangePerToken&&(t.lastComponent={count:1,previousComponent:t.lastComponent,added:!1,removed:!1});return d&&!i.oneChangePerToken&&(t.lastComponent={count:d,previousComponent:t.lastComponent,added:!1,removed:!1}),t.oldPos=l,a}equals(t,e,r){return r.comparator?r.comparator(t,e):t===e||!!r.ignoreCase&&t.toLowerCase()===e.toLowerCase()}removeEmpty(t){let e=[];for(let r=0;r<t.length;r++)t[r]&&e.push(t[r]);return e}castInput(t,e){return t}tokenize(t,e){return Array.from(t)}join(t){return t.join("")}postProcess(t,e){return t}get useLongestToken(){return!1}buildValues(t,e,r){let s=[],i;for(;t;)s.push(t),i=t.previousComponent,delete t.previousComponent,t=i;s.reverse();let o=s.length,c=0,l=0,a=0;for(;c<o;c++){let d=s[c];if(d.removed)d.value=this.join(r.slice(a,a+d.count)),a+=d.count;else{if(!d.added&&this.useLongestToken){let u=e.slice(l,l+d.count);u=u.map(function(h,f){let p=r[a+f];return p.length>h.length?p:h}),d.value=this.join(u)}else d.value=this.join(e.slice(l,l+d.count));l+=d.count,d.added||(a+=d.count)}}return s}};var Os=class extends he{},_c=new Os;function ar(n,t,e){return _c.diff(n,t,e)}var Ls=class extends he{constructor(){super(...arguments),this.tokenize=bd}equals(t,e,r){return r.ignoreWhitespace?((!r.newlineIsToken||!t.includes(` | |
| 4 | -`))&&(t=t.trim()),(!r.newlineIsToken||!e.includes(` | |
| 5 | -`))&&(e=e.trim())):r.ignoreNewlineAtEof&&!r.newlineIsToken&&(t.endsWith(` | |
| 6 | -`)&&(t=t.slice(0,-1)),e.endsWith(` | |
| 7 | -`)&&(e=e.slice(0,-1))),super.equals(t,e,r)}},bc=new Ls;function Rs(n,t,e){return bc.diff(n,t,e)}function bd(n,t){t.stripTrailingCr&&(n=n.replace(/\r\n/g,` | |
| 8 | -`));let e=[],r=n.split(/(\n|\r\n)/);r[r.length-1]||r.pop();for(let s=0;s<r.length;s++){let i=r[s];s%2&&!t.newlineIsToken?e[e.length-1]+=i:e.push(i)}return e}var dr=Yt(Ns(),1);var Cc=Yt(Ns(),1);function kd(n){return JSON.parse(JSON.stringify(n))}var Ms;(n=>{function t(i={},o={},c=!1){typeof i!="object"&&(i={}),typeof o!="object"&&(o={});let l=kd(o);c||(l=Object.keys(l).reduce((a,d)=>((l[d]!==null||l[d]!==void 0)&&(a[d]=l[d]),a),{}));for(let a in i)i[a]!==void 0&&o[a]===void 0&&(l[a]=i[a]);return Object.keys(l).length>0?l:void 0}n.compose=t;function e(i={},o={}){typeof i!="object"&&(i={}),typeof o!="object"&&(o={});let c=Object.keys(i).concat(Object.keys(o)).reduce((l,a)=>((0,Cc.default)(i[a],o[a])||(l[a]=o[a]===void 0?null:o[a]),l),{});return Object.keys(c).length>0?c:void 0}n.diff=e;function r(i={},o={}){i=i||{};let c=Object.keys(o).reduce((l,a)=>(o[a]!==i[a]&&i[a]!==void 0&&(l[a]=o[a]),l),{});return Object.keys(i).reduce((l,a)=>(i[a]!==o[a]&&o[a]===void 0&&(l[a]=null),l),c)}n.invert=r;function s(i,o,c=!1){if(typeof i!="object")return o;if(typeof o!="object")return;if(!c)return o;let l=Object.keys(o).reduce((a,d)=>(i[d]===void 0&&(a[d]=o[d]),a),{});return Object.keys(l).length>0?l:void 0}n.transform=s})(Ms||(Ms={}));var fe=Ms;var Vs;(n=>{function t(e){return typeof e.delete=="number"?e.delete:typeof e.retain=="number"?e.retain:typeof e.retain=="object"&&e.retain!==null?1:typeof e.insert=="string"?e.insert.length:1}n.length=t})(Vs||(Vs={}));var rt=Vs;var H=class{ops;index;offset;constructor(n){this.ops=n,this.index=0,this.offset=0}hasNext(){return this.peekLength()<1/0}next(n){n||(n=1/0);let t=this.ops[this.index];if(t){let e=this.offset,r=rt.length(t);if(n>=r-e?(n=r-e,this.index+=1,this.offset=0):this.offset+=n,typeof t.delete=="number")return{delete:n};let s={};return t.attributes&&(s.attributes=t.attributes),typeof t.retain=="number"?s.retain=n:typeof t.retain=="object"&&t.retain!==null?s.retain=t.retain:typeof t.insert=="string"?s.insert=t.insert.substr(e,n):s.insert=t.insert,s}return{retain:1/0}}peek(){return this.ops[this.index]}peekLength(){return this.ops[this.index]?rt.length(this.ops[this.index])-this.offset:1/0}peekType(){let n=this.ops[this.index];return n?typeof n.delete=="number"?"delete":typeof n.retain=="number"||typeof n.retain=="object"&&n.retain!==null?"retain":"insert":"retain"}rest(){if(this.hasNext()){if(this.offset===0)return this.ops.slice(this.index)}else return[];let n=this.offset,t=this.index,e=this.next(),r=this.ops.slice(this.index);return this.offset=n,this.index=t,[e].concat(r)}};function Cd(n){return JSON.parse(JSON.stringify(n))}var Dd="\0",Ad=1e4;function Bs(n){return n.map(t=>({...t,count:t.value.length}))}var Dc=(n,t)=>{if(typeof n!="object"||n===null)throw new Error(`cannot retain a ${typeof n}`);if(typeof t!="object"||t===null)throw new Error(`cannot retain a ${typeof t}`);let e=Object.keys(n)[0];if(!e||e!==Object.keys(t)[0])throw new Error(`embed types not matched: ${e} != ${Object.keys(t)[0]}`);return[e,n[e],t[e]]},Ud=class q{static Op=rt;static OpIterator=H;static AttributeMap=fe;static handlers={};static registerEmbed(t,e){this.handlers[t]=e}static unregisterEmbed(t){delete this.handlers[t]}static getHandler(t){let e=this.handlers[t];if(!e)throw new Error(`no handlers for embed type "${t}"`);return e}ops;constructor(t){Array.isArray(t)?this.ops=t:t!=null&&Array.isArray(t.ops)?this.ops=t.ops:this.ops=[]}insert(t,e){let r={};return typeof t=="string"&&t.length===0?this:(r.insert=t,e!=null&&typeof e=="object"&&Object.keys(e).length>0&&(r.attributes=e),this.push(r))}delete(t){return t<=0?this:this.push({delete:t})}retain(t,e){if(typeof t=="number"&&t<=0)return this;let r={retain:t};return e!=null&&typeof e=="object"&&Object.keys(e).length>0&&(r.attributes=e),this.push(r)}push(t){let e=this.ops.length,r=this.ops[e-1];if(t=Cd(t),typeof r=="object"){if(typeof t.delete=="number"&&typeof r.delete=="number")return this.ops[e-1]={delete:r.delete+t.delete},this;if(typeof r.delete=="number"&&t.insert!==null&&t.insert!==void 0&&(e-=1,r=this.ops[e-1],typeof r!="object"))return this.ops.unshift(t),this;if((0,dr.default)(t.attributes,r.attributes)){if(typeof t.insert=="string"&&typeof r.insert=="string")return this.ops[e-1]={insert:r.insert+t.insert},typeof t.attributes=="object"&&(this.ops[e-1].attributes=t.attributes),this;if(typeof t.retain=="number"&&typeof r.retain=="number")return this.ops[e-1]={retain:r.retain+t.retain},typeof t.attributes=="object"&&(this.ops[e-1].attributes=t.attributes),this}}return e===this.ops.length?this.ops.push(t):this.ops.splice(e,0,t),this}chop(){let t=this.ops[this.ops.length-1];return t&&typeof t.retain=="number"&&!t.attributes&&this.ops.pop(),this}filter(t){return this.ops.filter(t)}forEach(t){this.ops.forEach(t)}map(t){return this.ops.map(t)}partition(t){let e=[],r=[];return this.forEach(s=>{(t(s)?e:r).push(s)}),[e,r]}reduce(t,e){return this.ops.reduce(t,e)}changeLength(){return this.reduce((t,e)=>e.insert?t+rt.length(e):e.delete?t-e.delete:t,0)}length(){return this.reduce((t,e)=>t+rt.length(e),0)}slice(t=0,e=1/0){let r=[],s=new H(this.ops),i=0;for(;i<e&&s.hasNext();){let o;i<t?o=s.next(t-i):(o=s.next(e-i),r.push(o)),i+=rt.length(o)}return new q(r)}compose(t){let e=new H(this.ops),r=new H(t.ops),s=[],i=r.peek();if(i!=null&&typeof i.retain=="number"&&(i.attributes===null||i.attributes===void 0)){let c=i.retain;for(;e.peekType()==="insert"&&e.peekLength()<=c;)c-=e.peekLength(),s.push(e.next());i.retain-c>0&&r.next(i.retain-c)}let o=new q(s);for(;e.hasNext()||r.hasNext();)if(r.peekType()==="insert")o.push(r.next());else if(e.peekType()==="delete")o.push(e.next());else{let c=Math.min(e.peekLength(),r.peekLength()),l=e.next(c),a=r.next(c);if(a.retain){let d={};if(typeof l.retain=="number")d.retain=typeof a.retain=="number"?c:a.retain;else if(typeof a.retain=="number")l.retain===null||l.retain===void 0?d.insert=l.insert:d.retain=l.retain;else{let h=l.retain===null||l.retain===void 0?"insert":"retain",[f,p,g]=Dc(l[h],a.retain),m=q.getHandler(f);d[h]={[f]:m.compose(p,g,h==="retain")}}let u=fe.compose(l.attributes,a.attributes,typeof l.retain=="number");if(u&&(d.attributes=u),o.push(d),!r.hasNext()&&(0,dr.default)(o.ops[o.ops.length-1],d)){let h=new q(e.rest());return o.concat(h).chop()}}else typeof a.delete=="number"&&(typeof l.retain=="number"||typeof l.retain=="object"&&l.retain!==null)&&o.push(a)}return o.chop()}concat(t){let e=new q(this.ops.slice());return t.ops.length>0&&(e.push(t.ops[0]),e.ops=e.ops.concat(t.ops.slice(1))),e}diff(t){if(this.ops===t.ops)return new q;let e=this.deltasToStrings(t),r=Bs(ar(e[0],e[1])),s=new H(this.ops),i=new H(t.ops);return this.convertChangesToDelta(r,s,i).chop()}eachLine(t,e=` | |
| 9 | -`){let r=new H(this.ops),s=new q,i=0;for(;r.hasNext();){if(r.peekType()!=="insert")return;let o=r.peek(),c=rt.length(o)-r.peekLength(),l=typeof o.insert=="string"?o.insert.indexOf(e,c)-c:-1;if(l<0)s.push(r.next());else if(l>0)s.push(r.next(l));else{if(t(s,r.next(1).attributes||{},i)===!1)return;i+=1,s=new q}}s.length()>0&&t(s,{},i)}invert(t){let e=new q;return this.reduce((r,s)=>{if(s.insert)e.delete(rt.length(s));else{if(typeof s.retain=="number"&&(s.attributes===null||s.attributes===void 0))return e.retain(s.retain),r+s.retain;if(s.delete||typeof s.retain=="number"){let i=s.delete||s.retain;return t.slice(r,r+i).forEach(c=>{s.delete?e.push(c):s.retain&&s.attributes&&e.retain(rt.length(c),fe.invert(s.attributes,c.attributes))}),r+i}else if(typeof s.retain=="object"&&s.retain!==null){let i=t.slice(r,r+1),o=new H(i.ops).next(),[c,l,a]=Dc(s.retain,o.insert),d=q.getHandler(c);return e.retain({[c]:d.invert(l,a)},fe.invert(s.attributes,o.attributes)),r+1}}return r},0),e.chop()}transform(t,e=!1){if(e=!!e,typeof t=="number")return this.transformPosition(t,e);let r=t,s=new H(this.ops),i=new H(r.ops),o=new q;for(;s.hasNext()||i.hasNext();)if(s.peekType()==="insert"&&(e||i.peekType()!=="insert"))o.retain(rt.length(s.next()));else if(i.peekType()==="insert")o.push(i.next());else{let c=Math.min(s.peekLength(),i.peekLength()),l=s.next(c),a=i.next(c);if(l.delete)continue;if(a.delete)o.push(a);else{let d=l.retain,u=a.retain,h=typeof u=="object"&&u!==null?u:c;if(typeof d=="object"&&d!==null&&typeof u=="object"&&u!==null){let f=Object.keys(d)[0];if(f===Object.keys(u)[0]){let p=q.getHandler(f);p&&(h={[f]:p.transform(d[f],u[f],e)})}}o.retain(h,fe.transform(l.attributes,a.attributes,e))}}return o.chop()}transformPosition(t,e=!1){e=!!e;let r=new H(this.ops),s=0;for(;r.hasNext()&&s<=t;){let i=r.peekLength(),o=r.peekType();if(r.next(),o==="delete"){t-=Math.min(i,t-s);continue}else o==="insert"&&(s<t||!e)&&(t+=i);s+=i}return t}diffWithCursor(t,e){if(this.ops===t.ops)return new q;let r=this.deltasToStrings(t);if(Math.max(...r.map(u=>u.length))>Ad){let u=Bs(Rs(r[0],r[1])),h=new H(this.ops),f=new H(t.ops);return this.convertChangesToDelta(u,h,f).chop()}else if(e===null)return this.diff(t);let i=Bs(ar(r[0],r[1])),o=0,c=[];for(let u=0;u<i.length;u++){let h=i[u],f=o,p=o+(h.count??0),g=e>f&&e<=p,m=!h.added&&!h.removed,w=h.removed&&!h.added,y=i[u+1],_=y&&y.added&&!y.removed;if(m&&g&&_){let b=this.tryMoveInsertionToCursor(h,y,e,f);if(b){c.push(...b),u++,o=p;continue}}if(w){let b=this.tryMoveDeletionToCursor(h,c,e,o);if(b){c.pop(),c.push(...b),o+=h.count??0;continue}}c.push(h),h.added||(o+=h.count??0)}i=c;let l=new H(this.ops),a=new H(t.ops);return this.convertChangesToDelta(i,l,a).chop()}tryMoveInsertionToCursor(t,e,r,s){let i=e.value,o=i.length,c=r-s-o;if(!(t.value.substring(c,c+i.length)===i))return null;let d=t.value.substring(0,c),u=t.value.substring(c),h=[];return d.length>0&&h.push({value:d,count:d.length,added:!1,removed:!1}),h.push(e),u.length>0&&h.push({value:u,count:u.length,added:!1,removed:!1}),h}tryMoveDeletionToCursor(t,e,r,s){let i=e[e.length-1];if(!i||i.added||i.removed)return null;let o=s-(i.count??0),c=s;if(r<o||r>=c)return null;let l=t.value,a=r-o;if(!(i.value.substring(a,a+l.length)===l))return null;let h=i.value.substring(0,a),f=i.value.substring(a),p=t.count??0,g=f.substring(p),m=[];return h.length>0&&m.push({value:h,count:h.length,added:!1,removed:!1}),m.push(t),g.length>0&&m.push({value:g,count:g.length,added:!1,removed:!1}),m}deltasToStrings(t){return[this,t].map(e=>e.map(r=>{if(r.insert!==null||r.insert!==void 0)return typeof r.insert=="string"?r.insert:Dd;let s=e===t?"on":"with";throw new Error("diff() called "+s+" non-document")}).join(""))}convertChangesToDelta(t,e,r){let s=new q;return t.forEach(i=>{let o=i.count??0;for(;o>0;){let c=0;if(i.added)c=Math.min(r.peekLength(),o),s.push(r.next(c));else if(i.removed)c=Math.min(o,e.peekLength()),e.next(c),s.delete(c);else{c=Math.min(e.peekLength(),r.peekLength(),o);let l=e.next(c),a=r.next(c);(0,dr.default)(l.insert,a.insert)?s.retain(c,fe.diff(l.attributes,a.attributes)):s.push(a).delete(c)}o-=c}}),s}},Ac=Ud;var Ps={};Yo(Ps,{ConnectionErrorCode:Fe,createSyncManager:Ec,Delta:Ac,CRDT_DOC_META_PERSISTENCE_KEY:Zn,CRDT_RECORD_MAP_KEY:tr,LOCAL_EDITOR_ORIGIN:er,LOCAL_UNDO_IGNORED_ORIGIN:Bo,retrySyncConnection:()=>Sn.retryNow()});var Td="13";return Nc(Id);})(); | |
| 1 | +(function() { | |
| 2 | +"use strict";var wp;(wp||={}).sync=(()=>{var Wl=Object.create;var tr=Object.defineProperty;var Xl=Object.getOwnPropertyDescriptor;var Ql=Object.getOwnPropertyNames;var Zl=Object.getPrototypeOf,ta=Object.prototype.hasOwnProperty;var er=(e,t)=>()=>(t||e((t={exports:{}}).exports,t),t.exports),ri=(e,t)=>{for(var n in t)tr(e,n,{get:t[n],enumerable:!0})},si=(e,t,n,r)=>{if(t&&typeof t=="object"||typeof t=="function")for(let s of Ql(t))!ta.call(e,s)&&s!==n&&tr(e,s,{get:()=>t[s],enumerable:!(r=Xl(t,s))||r.enumerable});return e};var se=(e,t,n)=>(n=e!=null?Wl(Zl(e)):{},si(t||!e||!e.__esModule?tr(n,"default",{value:e,enumerable:!0}):n,e)),ea=e=>si(tr({},"__esModule",{value:!0}),e);var nl=er((Of,el)=>{el.exports=window.wp.privateApis});var is=er((Mf,cl)=>{cl.exports=window.wp.hooks});var Sl=er((Pf,xl)=>{xl.exports=window.wp.apiFetch});var Xo=er((Ap,Yl)=>{"use strict";Yl.exports=function e(t,n){if(t===n)return!0;if(t&&n&&typeof t=="object"&&typeof n=="object"){if(t.constructor!==n.constructor)return!1;var r,s,o;if(Array.isArray(t)){if(r=t.length,r!=n.length)return!1;for(s=r;s--!==0;)if(!e(t[s],n[s]))return!1;return!0}if(t instanceof Map&&n instanceof Map){if(t.size!==n.size)return!1;for(s of t.entries())if(!n.has(s[0]))return!1;for(s of t.entries())if(!e(s[1],n.get(s[0])))return!1;return!0}if(t instanceof Set&&n instanceof Set){if(t.size!==n.size)return!1;for(s of t.entries())if(!n.has(s[0]))return!1;return!0}if(ArrayBuffer.isView(t)&&ArrayBuffer.isView(n)){if(r=t.length,r!=n.length)return!1;for(s=r;s--!==0;)if(t[s]!==n[s])return!1;return!0}if(t.constructor===RegExp)return t.source===n.source&&t.flags===n.flags;if(t.valueOf!==Object.prototype.valueOf)return t.valueOf()===n.valueOf();if(t.toString!==Object.prototype.toString)return t.toString()===n.toString();if(o=Object.keys(t),r=o.length,r!==Object.keys(n).length)return!1;for(s=r;s--!==0;)if(!Object.prototype.hasOwnProperty.call(n,o[s]))return!1;for(s=r;s--!==0;){var i=o[s];if(!e(t[i],n[i]))return!1}return!0}return t!==t&&n!==n}});var Rh={};ri(Rh,{Awareness:()=>un,Y:()=>_t,YJS_VERSION:()=>Oh,privateApis:()=>ei});var _t={};ri(_t,{AbsolutePosition:()=>Br,AbstractConnector:()=>eo,AbstractStruct:()=>ln,AbstractType:()=>R,Array:()=>Se,ContentAny:()=>Zt,ContentBinary:()=>ke,ContentDeleted:()=>an,ContentDoc:()=>Ce,ContentEmbed:()=>Vt,ContentFormat:()=>L,ContentJSON:()=>Yn,ContentString:()=>xt,ContentType:()=>pt,Doc:()=>Tt,GC:()=>Q,ID:()=>Lt,Item:()=>T,Map:()=>_e,PermanentUserData:()=>ro,RelativePosition:()=>on,Skip:()=>H,Snapshot:()=>Vn,Text:()=>cn,Transaction:()=>$r,UndoManager:()=>ye,UpdateDecoderV1:()=>it,UpdateDecoderV2:()=>tt,UpdateEncoderV1:()=>Ut,UpdateEncoderV2:()=>dt,XmlElement:()=>be,XmlFragment:()=>Ee,XmlHook:()=>Fn,XmlText:()=>Hr,YArrayEvent:()=>Yr,YEvent:()=>xe,YMapEvent:()=>zr,YTextEvent:()=>qr,YXmlEvent:()=>Gr,applyUpdate:()=>mo,applyUpdateV2:()=>St,cleanupYTextFormatting:()=>qc,compareIDs:()=>fe,compareRelativePositions:()=>qd,convertUpdateFormatV1ToV2:()=>uu,convertUpdateFormatV2ToV1:()=>Tc,createAbsolutePositionFromRelativePosition:()=>zd,createDeleteSet:()=>Kr,createDeleteSetFromStructStore:()=>fo,createDocFromSnapshot:()=>Wd,createID:()=>y,createRelativePositionFromJSON:()=>Md,createRelativePositionFromTypeIndex:()=>Bd,createSnapshot:()=>Eo,decodeRelativePosition:()=>Fd,decodeSnapshot:()=>Jd,decodeSnapshotV2:()=>Qr,decodeStateVector:()=>wo,decodeUpdate:()=>su,decodeUpdateV2:()=>Ec,diffUpdate:()=>lu,diffUpdateV2:()=>bo,emptySnapshot:()=>Kd,encodeRelativePosition:()=>$d,encodeSnapshot:()=>Hd,encodeSnapshotV2:()=>Xr,encodeStateAsUpdate:()=>yo,encodeStateAsUpdateV2:()=>Bt,encodeStateVector:()=>So,encodeStateVectorFromUpdate:()=>ou,encodeStateVectorFromUpdateV2:()=>kc,equalDeleteSets:()=>Wr,equalSnapshots:()=>Gd,findIndexSS:()=>ft,findRootTypeKey:()=>_o,getItem:()=>pe,getItemCleanEnd:()=>io,getItemCleanStart:()=>X,getState:()=>I,getTypeChildren:()=>gu,isDeleted:()=>Ae,isParentOf:()=>Mn,iterateDeletedStructs:()=>ge,logType:()=>Ld,logUpdate:()=>ru,logUpdateV2:()=>_c,mergeDeleteSets:()=>Nt,mergeUpdates:()=>bc,mergeUpdatesV2:()=>we,obfuscateUpdate:()=>au,obfuscateUpdateV2:()=>du,parseUpdateMeta:()=>iu,parseUpdateMetaV2:()=>Cc,readUpdate:()=>Id,readUpdateV2:()=>go,relativePositionToJSON:()=>Nd,snapshot:()=>zn,snapshotContainsUpdate:()=>Qd,transact:()=>D,tryGc:()=>eu,typeListToArraySnapshot:()=>mu,typeMapGetAllSnapshot:()=>$c,typeMapGetSnapshot:()=>xu});var O=()=>new Map,nr=e=>{let t=O();return e.forEach((n,r)=>{t.set(r,n)}),t},P=(e,t,n)=>{let r=e.get(t);return r===void 0&&e.set(t,r=n()),r},oi=(e,t)=>{let n=[];for(let[r,s]of e)n.push(t(s,r));return n},ii=(e,t)=>{for(let[n,r]of e)if(t(r,n))return!0;return!1};var bt=()=>new Set;var rr=e=>e[e.length-1];var ci=(e,t)=>{for(let n=0;n<t.length;n++)e.push(t[n])},mt=Array.from,sr=(e,t)=>{for(let n=0;n<e.length;n++)if(!t(e[n],n,e))return!1;return!0},mn=(e,t)=>{for(let n=0;n<e.length;n++)if(t(e[n],n,e))return!0;return!1};var li=(e,t)=>{let n=new Array(e);for(let r=0;r<e;r++)n[r]=t(r,n);return n};var yt=Array.isArray;var Yt=class{constructor(){this._observers=O()}on(t,n){return P(this._observers,t,bt).add(n),n}once(t,n){let r=(...s)=>{this.off(t,r),n(...s)};this.on(t,r)}off(t,n){let r=this._observers.get(t);r!==void 0&&(r.delete(n),r.size===0&&this._observers.delete(t))}emit(t,n){return mt((this._observers.get(t)||O()).values()).forEach(r=>r(...n))}destroy(){this._observers=O()}},Me=class{constructor(){this._observers=O()}on(t,n){P(this._observers,t,bt).add(n)}once(t,n){let r=(...s)=>{this.off(t,r),n(...s)};this.on(t,r)}off(t,n){let r=this._observers.get(t);r!==void 0&&(r.delete(n),r.size===0&&this._observers.delete(t))}emit(t,n){return mt((this._observers.get(t)||O()).values()).forEach(r=>r(...n))}destroy(){this._observers=O()}};var Y=Math.floor;var oe=Math.abs;var or=(e,t)=>e<t?e:t,Rt=(e,t)=>e>t?e:t,Mh=Number.isNaN;var ir=e=>e!==0?e<0:1/e<0;var Be=Number.MAX_SAFE_INTEGER,gs=Number.MIN_SAFE_INTEGER,Vh=1<<31;var ai=Number.isInteger||(e=>typeof e=="number"&&isFinite(e)&&Y(e)===e),Bh=Number.isNaN,Ph=Number.parseInt;var yn=String.fromCharCode,na=String.fromCodePoint,$h=yn(65535),ra=e=>e.toLowerCase(),sa=/^\s*/g,oa=e=>e.replace(sa,""),ia=/([A-Z])/g,ys=(e,t)=>oa(e.replace(ia,n=>`${t}${ra(n)}`));var ca=e=>{let t=unescape(encodeURIComponent(e)),n=t.length,r=new Uint8Array(n);for(let s=0;s<n;s++)r[s]=t.codePointAt(s);return r},$e=typeof TextEncoder<"u"?new TextEncoder:null,la=e=>$e.encode(e),di=$e?la:ca;var Pe=typeof TextDecoder>"u"?null:new TextDecoder("utf-8",{fatal:!0,ignoreBOM:!0});Pe&&Pe.decode(new Uint8Array).length===1&&(Pe=null);var cr=(e,t)=>li(t,()=>e).join("");var ie=class{constructor(){this.cpos=0,this.cbuf=new Uint8Array(100),this.bufs=[]}},wt=()=>new ie;var aa=e=>{let t=e.cpos;for(let n=0;n<e.bufs.length;n++)t+=e.bufs[n].length;return t};var W=e=>{let t=new Uint8Array(aa(e)),n=0;for(let r=0;r<e.bufs.length;r++){let s=e.bufs[r];t.set(s,n),n+=s.length}return t.set(new Uint8Array(e.cbuf.buffer,0,e.cpos),n),t},da=(e,t)=>{let n=e.cbuf.length;n-e.cpos<t&&(e.bufs.push(new Uint8Array(e.cbuf.buffer,0,e.cpos)),e.cbuf=new Uint8Array(Rt(n,t)*2),e.cpos=0)},$=(e,t)=>{let n=e.cbuf.length;e.cpos===n&&(e.bufs.push(e.cbuf),e.cbuf=new Uint8Array(n*2),e.cpos=0),e.cbuf[e.cpos++]=t};var qe=$;var m=(e,t)=>{for(;t>127;)$(e,128|127&t),t=Y(t/128);$(e,127&t)},xn=(e,t)=>{let n=ir(t);for(n&&(t=-t),$(e,(t>63?128:0)|(n?64:0)|63&t),t=Y(t/64);t>0;)$(e,(t>127?128:0)|127&t),t=Y(t/128)},ws=new Uint8Array(3e4),ua=ws.length/3,ha=(e,t)=>{if(t.length<ua){let n=$e.encodeInto(t,ws).written||0;m(e,n);for(let r=0;r<n;r++)$(e,ws[r])}else z(e,di(t))},fa=(e,t)=>{let n=unescape(encodeURIComponent(t)),r=n.length;m(e,r);for(let s=0;s<r;s++)$(e,n.codePointAt(s))},zt=$e&&$e.encodeInto?ha:fa;var gi=(e,t)=>Ge(e,W(t)),Ge=(e,t)=>{let n=e.cbuf.length,r=e.cpos,s=or(n-r,t.length),o=t.length-s;e.cbuf.set(t.subarray(0,s),r),e.cpos+=s,o>0&&(e.bufs.push(e.cbuf),e.cbuf=new Uint8Array(Rt(n*2,o)),e.cbuf.set(t.subarray(s)),e.cpos=o)},z=(e,t)=>{m(e,t.byteLength),Ge(e,t)},xs=(e,t)=>{da(e,t);let n=new DataView(e.cbuf.buffer,e.cpos,t);return e.cpos+=t,n},pa=(e,t)=>xs(e,4).setFloat32(0,t,!1),ga=(e,t)=>xs(e,8).setFloat64(0,t,!1),ma=(e,t)=>xs(e,8).setBigInt64(0,t,!1);var hi=new DataView(new ArrayBuffer(4)),ya=e=>(hi.setFloat32(0,e),hi.getFloat32(0)===e),Ye=(e,t)=>{switch(typeof t){case"string":$(e,119),zt(e,t);break;case"number":ai(t)&&oe(t)<=2147483647?($(e,125),xn(e,t)):ya(t)?($(e,124),pa(e,t)):($(e,123),ga(e,t));break;case"bigint":$(e,122),ma(e,t);break;case"object":if(t===null)$(e,126);else if(yt(t)){$(e,117),m(e,t.length);for(let n=0;n<t.length;n++)Ye(e,t[n])}else if(t instanceof Uint8Array)$(e,116),z(e,t);else{$(e,118);let n=Object.keys(t);m(e,n.length);for(let r=0;r<n.length;r++){let s=n[r];zt(e,s),Ye(e,t[s])}}break;case"boolean":$(e,t?120:121);break;default:$(e,127)}},wn=class extends ie{constructor(t){super(),this.w=t,this.s=null,this.count=0}write(t){this.s===t?this.count++:(this.count>0&&m(this,this.count-1),this.count=1,this.w(this,t),this.s=t)}};var fi=e=>{e.count>0&&(xn(e.encoder,e.count===1?e.s:-e.s),e.count>1&&m(e.encoder,e.count-2))},ce=class{constructor(){this.encoder=new ie,this.s=0,this.count=0}write(t){this.s===t?this.count++:(fi(this),this.count=1,this.s=t)}toUint8Array(){return fi(this),W(this.encoder)}};var pi=e=>{if(e.count>0){let t=e.diff*2+(e.count===1?0:1);xn(e.encoder,t),e.count>1&&m(e.encoder,e.count-2)}},ze=class{constructor(){this.encoder=new ie,this.s=0,this.count=0,this.diff=0}write(t){this.diff===t-this.s?(this.s=t,this.count++):(pi(this),this.count=1,this.diff=t-this.s,this.s=t)}toUint8Array(){return pi(this),W(this.encoder)}},lr=class{constructor(){this.sarr=[],this.s="",this.lensE=new ce}write(t){this.s+=t,this.s.length>19&&(this.sarr.push(this.s),this.s=""),this.lensE.write(t.length)}toUint8Array(){let t=new ie;return this.sarr.push(this.s),this.s="",zt(t,this.sarr.join("")),Ge(t,this.lensE.toUint8Array()),W(t)}};var lt=e=>new Error(e),at=()=>{throw lt("Method unimplemented")},j=()=>{throw lt("Unexpected case")};var mi=lt("Unexpected end of array"),yi=lt("Integer out of Range"),He=class{constructor(t){this.arr=t,this.pos=0}},N=e=>new He(e),Es=e=>e.pos!==e.arr.length;var wa=(e,t)=>{let n=new Uint8Array(e.arr.buffer,e.pos+e.arr.byteOffset,t);return e.pos+=t,n},q=e=>wa(e,S(e));var le=e=>e.arr[e.pos++];var S=e=>{let t=0,n=1,r=e.arr.length;for(;e.pos<r;){let s=e.arr[e.pos++];if(t=t+(s&127)*n,n*=128,s<128)return t;if(t>Be)throw yi}throw mi},_n=e=>{let t=e.arr[e.pos++],n=t&63,r=64,s=(t&64)>0?-1:1;if((t&128)===0)return s*n;let o=e.arr.length;for(;e.pos<o;){if(t=e.arr[e.pos++],n=n+(t&127)*r,r*=128,t<128)return s*n;if(n>Be)throw yi}throw mi};var xa=e=>{let t=S(e);if(t===0)return"";{let n=String.fromCodePoint(le(e));if(--t<100)for(;t--;)n+=String.fromCodePoint(le(e));else for(;t>0;){let r=t<1e4?t:1e4,s=e.arr.subarray(e.pos,e.pos+r);e.pos+=r,n+=String.fromCodePoint.apply(null,s),t-=r}return decodeURIComponent(escape(n))}},Sa=e=>Pe.decode(q(e)),Gt=Pe?Sa:xa;var bs=(e,t)=>{let n=new DataView(e.arr.buffer,e.arr.byteOffset+e.pos,t);return e.pos+=t,n},_a=e=>bs(e,4).getFloat32(0,!1),Ea=e=>bs(e,8).getFloat64(0,!1),ba=e=>bs(e,8).getBigInt64(0,!1);var ka=[e=>{},e=>null,_n,_a,Ea,ba,e=>!1,e=>!0,Gt,e=>{let t=S(e),n={};for(let r=0;r<t;r++){let s=Gt(e);n[s]=Je(e)}return n},e=>{let t=S(e),n=[];for(let r=0;r<t;r++)n.push(Je(e));return n},q],Je=e=>ka[127-le(e)](e),Sn=class extends He{constructor(t,n){super(t),this.reader=n,this.s=null,this.count=0}read(){return this.count===0&&(this.s=this.reader(this),Es(this)?this.count=S(this)+1:this.count=-1),this.count--,this.s}};var ae=class extends He{constructor(t){super(t),this.s=0,this.count=0}read(){if(this.count===0){this.s=_n(this);let t=ir(this.s);this.count=1,t&&(this.s=-this.s,this.count=S(this)+2)}return this.count--,this.s}};var Ke=class extends He{constructor(t){super(t),this.s=0,this.count=0,this.diff=0}read(){if(this.count===0){let t=_n(this),n=t&1;this.diff=Y(t/2),this.count=1,n&&(this.count=S(this)+2)}return this.s+=this.diff,this.count--,this.s}},ar=class{constructor(t){this.decoder=new ae(t),this.str=Gt(this.decoder),this.spos=0}read(){let t=this.spos+this.decoder.read(),n=this.str.slice(this.spos,t);return this.spos=t,n}};var Yh=crypto.subtle,wi=crypto.getRandomValues.bind(crypto);var Cs=()=>wi(new Uint32Array(1))[0];var Ca="10000000-1000-4000-8000"+-1e11,xi=()=>Ca.replace(/[018]/g,e=>(e^Cs()&15>>e/4).toString(16));var Ht=Date.now;var Ds=e=>new Promise(e);var Gh=Promise.all.bind(Promise);var Ts=e=>e===void 0?null:e;var Us=class{constructor(){this.map=new Map}setItem(t,n){this.map.set(t,n)}getItem(t){return this.map.get(t)}},Si=new Us,Ua=!0;try{typeof localStorage<"u"&&localStorage&&(Si=localStorage,Ua=!1)}catch{}var _i=Si;var de=Symbol("Equality"),dr=(e,t)=>e===t||!!e?.[de]?.(t)||!1;var Ei=e=>typeof e=="object",bi=Object.assign,va=Object.keys;var ki=(e,t)=>{for(let n in e)t(e[n],n)};var En=e=>va(e).length;var Ci=e=>{for(let t in e)return!1;return!0},We=(e,t)=>{for(let n in e)if(!t(e[n],n))return!1;return!0},bn=(e,t)=>Object.prototype.hasOwnProperty.call(e,t),vs=(e,t)=>e===t||En(e)===En(t)&&We(e,(n,r)=>(n!==void 0||bn(t,r))&&dr(t[r],n)),Oa=Object.freeze,Os=e=>{for(let t in e){let n=e[t];(typeof n=="object"||typeof n=="function")&&Os(e[t])}return Oa(e)};var kn=(e,t,n=0)=>{try{for(;n<e.length;n++)e[n](...t)}finally{n<e.length&&kn(e,t,n+1)}};var Ls=e=>e;var ue=(e,t)=>{if(e===t)return!0;if(e==null||t==null||e.constructor!==t.constructor&&(e.constructor||Object)!==(t.constructor||Object))return!1;if(e[de]!=null)return e[de](t);switch(e.constructor){case ArrayBuffer:e=new Uint8Array(e),t=new Uint8Array(t);case Uint8Array:{if(e.byteLength!==t.byteLength)return!1;for(let n=0;n<e.length;n++)if(e[n]!==t[n])return!1;break}case Set:{if(e.size!==t.size)return!1;for(let n of e)if(!t.has(n))return!1;break}case Map:{if(e.size!==t.size)return!1;for(let n of e.keys())if(!t.has(n)||!ue(e.get(n),t.get(n)))return!1;break}case void 0:case Object:if(En(e)!==En(t))return!1;for(let n in e)if(!bn(e,n)||!ue(e[n],t[n]))return!1;break;case Array:if(e.length!==t.length)return!1;for(let n=0;n<e.length;n++)if(!ue(e[n],t[n]))return!1;break;default:return!1}return!0},Ai=(e,t)=>t.includes(e);var Xe=typeof process<"u"&&process.release&&/node|io\.js/.test(process.release.name)&&Object.prototype.toString.call(typeof process<"u"?process:0)==="[object process]",hr=typeof window<"u"&&typeof document<"u"&&!Xe,Hh=typeof navigator<"u"?/Mac/.test(navigator.platform):!1,kt,Ra=[],La=()=>{if(kt===void 0)if(Xe){kt=O();let e=process.argv,t=null;for(let n=0;n<e.length;n++){let r=e[n];r[0]==="-"?(t!==null&&kt.set(t,""),t=r):t!==null?(kt.set(t,r),t=null):Ra.push(r)}t!==null&&kt.set(t,"")}else typeof location=="object"?(kt=O(),(location.search||"?").slice(1).split("&").forEach(e=>{if(e.length!==0){let[t,n]=e.split("=");kt.set(`--${ys(t,"-")}`,n),kt.set(`-${ys(t,"-")}`,n)}})):kt=O();return kt},Ns=e=>La().has(e);var Cn=e=>Xe?Ts(process.env[e.toUpperCase().replaceAll("-","_")]):Ts(_i.getItem(e));var Di=e=>Ns("--"+e)||Cn(e)!==null,Ti=Di("production"),Na=Xe&&Ai(process.env.FORCE_COLOR,["true","1","2"]),Ui=Na||!Ns("--no-colors")&&!Di("no-color")&&(!Xe||process.stdout.isTTY)&&(!Xe||Ns("--color")||Cn("COLORTERM")!==null||(Cn("TERM")||"").includes("color"));var Ii=e=>new Uint8Array(e),Ma=(e,t,n)=>new Uint8Array(e,t,n);var Va=e=>{let t="";for(let n=0;n<e.byteLength;n++)t+=yn(e[n]);return btoa(t)},Ba=e=>Buffer.from(e.buffer,e.byteOffset,e.byteLength).toString("base64"),Pa=e=>{let t=atob(e),n=Ii(t.length);for(let r=0;r<t.length;r++)n[r]=t.charCodeAt(r);return n},$a=e=>{let t=Buffer.from(e,"base64");return Ma(t.buffer,t.byteOffset,t.byteLength)},pr=hr?Va:Ba,gr=hr?Pa:$a;var vi=e=>{let t=Ii(e.byteLength);return t.set(e),t};var Vs=class{constructor(t,n){this.left=t,this.right=n}},Ct=(e,t)=>new Vs(e,t);var Bs=e=>e.next()>=.5,mr=(e,t,n)=>Y(e.next()*(n+1-t)+t);var Ps=(e,t,n)=>Y(e.next()*(n+1-t)+t);var $s=(e,t,n)=>Ps(e,t,n);var Fa=e=>yn($s(e,97,122)),Oi=(e,t=0,n=20)=>{let r=$s(e,t,n),s="";for(let o=0;o<r;o++)s+=Fa(e);return s};var yr=(e,t)=>t[$s(e,0,t.length-1)];var za=Symbol("0schema"),js=class{constructor(){this._rerrs=[]}extend(t,n,r,s=null){this._rerrs.push({path:t,expected:n,has:r,message:s})}toString(){let t=[];for(let n=this._rerrs.length-1;n>0;n--){let r=this._rerrs[n];t.push(cr(" ",(this._rerrs.length-n)*2)+`${r.path!=null?`[${r.path}] `:""}${r.has} doesn't match ${r.expected}. ${r.message}`)}return t.join(` | |
| 3 | +`)}},Fs=(e,t)=>e===t?!0:e==null||t==null||e.constructor!==t.constructor?!1:e[de]?dr(e,t):yt(e)?sr(e,n=>mn(t,r=>Fs(n,r))):Ei(e)?We(e,(n,r)=>Fs(n,t[r])):!1,G=class{static _dilutes=!1;extends(t){let[n,r]=[this.shape,t.shape];return this.constructor._dilutes&&([r,n]=[n,r]),Fs(n,r)}equals(t){return this.constructor===t.constructor&&ue(this.shape,t.shape)}[za](){return!0}[de](t){return this.equals(t)}validate(t){return this.check(t)}check(t,n){at()}get nullable(){return nn(this,Ur)}get optional(){return new wr(this)}cast(t){return Ri(t,this),t}expect(t){return Ri(t,this),t}},An=class extends G{constructor(t,n){super(),this.shape=t,this._c=n}check(t,n=void 0){let r=t?.constructor===this.shape&&(this._c==null||this._c(t));return!r&&n?.extend(null,this.shape.name,t?.constructor.name,t?.constructor!==this.shape?"Constructor match failed":"Check failed"),r}},M=(e,t=null)=>new An(e,t),Kh=M(An),Dn=class extends G{constructor(t){super(),this.shape=t}check(t,n){let r=this.shape(t);return!r&&n?.extend(null,"custom prop",t?.constructor.name,"failed to check custom prop"),r}},V=e=>new Dn(e),Wh=M(Dn),tn=class extends G{constructor(t){super(),this.shape=t}check(t,n){let r=this.shape.some(s=>s===t);return!r&&n?.extend(null,this.shape.join(" | "),t.toString()),r}},Dr=(...e)=>new tn(e),Li=M(tn),qa=RegExp.escape||(e=>e.replace(/[().|&,$^[\]]/g,t=>"\\"+t)),Ni=e=>{if(en.check(e))return[qa(e)];if(Li.check(e))return e.shape.map(t=>t+"");if($i.check(e))return["[+-]?\\d+.?\\d*"];if(ji.check(e))return[".*"];if(Cr.check(e))return e.shape.map(Ni).flat(1);j()},Ys=class extends G{constructor(t){super(),this.shape=t,this._r=new RegExp("^"+t.map(Ni).map(n=>`(${n.join("|")})`).join("")+"$")}check(t,n){let r=this._r.exec(t)!=null;return!r&&n?.extend(null,this._r.toString(),t.toString(),"String doesn't match string template."),r}};var Xh=M(Ys),Ga=Symbol("optional"),wr=class extends G{constructor(t){super(),this.shape=t}check(t,n){let r=t===void 0||this.shape.check(t);return!r&&n?.extend(null,"undefined (optional)","()"),r}get[Ga](){return!0}},Ha=M(wr),xr=class extends G{check(t,n){return n?.extend(null,"never",typeof t),!1}},Qh=new xr,Zh=M(xr),Sr=class e extends G{constructor(t,n=!1){super(),this.shape=t,this._isPartial=n}static _dilutes=!0;get partial(){return new e(this.shape,!0)}check(t,n){return t==null?(n?.extend(null,"object","null"),!1):We(this.shape,(r,s)=>{let o=this._isPartial&&!bn(t,s)||r.check(t[s],n);return!o&&n?.extend(s.toString(),r.toString(),typeof t[s],"Object property does not match"),o})}},Ja=e=>new Sr(e),Ka=M(Sr),Wa=V(e=>e!=null&&(e.constructor===Object||e.constructor==null)),_r=class extends G{constructor(t,n){super(),this.shape={keys:t,values:n}}check(t,n){return t!=null&&We(t,(r,s)=>{let o=this.shape.keys.check(s,n);return!o&&n?.extend(s+"","Record",typeof t,o?"Key doesn't match schema":"Value doesn't match value"),o&&this.shape.values.check(r,n)})}},Mi=(e,t)=>new _r(e,t),Xa=M(_r),Er=class extends G{constructor(t){super(),this.shape=t}check(t,n){return t!=null&&We(this.shape,(r,s)=>{let o=r.check(t[s],n);return!o&&n?.extend(s.toString(),"Tuple",typeof r),o})}},Qa=(...e)=>new Er(e),tf=M(Er),br=class extends G{constructor(t){super(),this.shape=t.length===1?t[0]:new Tn(t)}check(t,n){let r=yt(t)&&sr(t,s=>this.shape.check(s));return!r&&n?.extend(null,"Array",""),r}},Vi=(...e)=>new br(e),Za=M(br),td=V(e=>yt(e)),kr=class extends G{constructor(t,n){super(),this.shape=t,this._c=n}check(t,n){let r=t instanceof this.shape&&(this._c==null||this._c(t));return!r&&n?.extend(null,this.shape.name,t?.constructor.name),r}},ed=(e,t=null)=>new kr(e,t),ef=M(kr),nd=ed(G),zs=class extends G{constructor(t){super(),this.len=t.length-1,this.args=Qa(...t.slice(-1)),this.res=t[this.len]}check(t,n){let r=t.constructor===Function&&t.length<=this.len;return!r&&n?.extend(null,"function",typeof t),r}};var rd=M(zs),sd=V(e=>typeof e=="function"),qs=class extends G{constructor(t){super(),this.shape=t}check(t,n){let r=sr(this.shape,s=>s.check(t,n));return!r&&n?.extend(null,"Intersectinon",typeof t),r}};var nf=M(qs,e=>e.shape.length>0),Tn=class extends G{static _dilutes=!0;constructor(t){super(),this.shape=t}check(t,n){let r=mn(this.shape,s=>s.check(t,n));return n?.extend(null,"Union",typeof t),r}},nn=(...e)=>e.findIndex(t=>Cr.check(t))>=0?nn(...e.map(t=>Un(t)).map(t=>Cr.check(t)?t.shape:[t]).flat(1)):e.length===1?e[0]:new Tn(e),Cr=M(Tn),Bi=()=>!0,Ar=V(Bi),od=M(Dn,e=>e.shape===Bi),Hs=V(e=>typeof e=="bigint"),id=V(e=>e===Hs),Pi=V(e=>typeof e=="symbol"),rf=V(e=>e===Pi),Ze=V(e=>typeof e=="number"),$i=V(e=>e===Ze),en=V(e=>typeof e=="string"),ji=V(e=>e===en),Tr=V(e=>typeof e=="boolean"),cd=V(e=>e===Tr),Fi=Dr(void 0),sf=M(tn,e=>e.shape.length===1&&e.shape[0]===void 0),of=Dr(void 0);var Ur=Dr(null),ld=M(tn,e=>e.shape.length===1&&e.shape[0]===null),cf=M(Uint8Array),lf=M(An,e=>e.shape===Uint8Array),ad=nn(Ze,en,Ur,Fi,Hs,Tr,Pi),af=(()=>{let e=Vi(Ar),t=Mi(en,Ar),n=nn(Ze,en,Ur,Tr,e,t);return e.shape=n,t.shape.values=n,n})(),Un=e=>{if(nd.check(e))return e;if(Wa.check(e)){let t={};for(let n in e)t[n]=Un(e[n]);return Ja(t)}else{if(td.check(e))return nn(...e.map(Un));if(ad.check(e))return Dr(e);if(sd.check(e))return M(e)}j()},Ri=Ti?()=>{}:(e,t)=>{let n=new js;if(!t.check(e,n))throw lt(`Expected value to be of type ${t.constructor.name}. | |
| 4 | +${n.toString()}`)},Gs=class{constructor(t){this.patterns=[],this.$state=t}if(t,n){return this.patterns.push({if:Un(t),h:n}),this}else(t){return this.if(Ar,t)}done(){return(t,n)=>{for(let r=0;r<this.patterns.length;r++){let s=this.patterns[r];if(s.if.check(t))return s.h(t,n)}throw lt("Unhandled pattern")}}},dd=e=>new Gs(e),Yi=dd(Ar).if($i,(e,t)=>mr(t,gs,Be)).if(ji,(e,t)=>Oi(t)).if(cd,(e,t)=>Bs(t)).if(id,(e,t)=>BigInt(mr(t,gs,Be))).if(Cr,(e,t)=>Qe(t,yr(t,e.shape))).if(Ka,(e,t)=>{let n={};for(let r in e.shape){let s=e.shape[r];if(Ha.check(s)){if(Bs(t))continue;s=s.shape}n[r]=Yi(s,t)}return n}).if(Za,(e,t)=>{let n=[],r=Ps(t,0,42);for(let s=0;s<r;s++)n.push(Qe(t,e.shape));return n}).if(Li,(e,t)=>yr(t,e.shape)).if(ld,(e,t)=>null).if(rd,(e,t)=>{let n=Qe(t,e.res);return()=>n}).if(od,(e,t)=>Qe(t,yr(t,[Ze,en,Ur,Fi,Hs,Tr,Vi(Ze),Mi(nn("a","b","c"),Ze)]))).if(Xa,(e,t)=>{let n={},r=mr(t,0,3);for(let s=0;s<r;s++){let o=Qe(t,e.shape.keys),i=Qe(t,e.shape.values);n[o]=i}return n}).done(),Qe=(e,t)=>Yi(Un(t),e);var he=typeof document<"u"?document:{};var df=V(e=>e.nodeType===gd);var uf=typeof DOMParser<"u"?new DOMParser:null;var hf=V(e=>e.nodeType===hd);var ff=V(e=>e.nodeType===fd);var zi=e=>oi(e,(t,n)=>`${n}:${t};`).join("");var hd=he.ELEMENT_NODE,fd=he.TEXT_NODE,pf=he.CDATA_SECTION_NODE,gf=he.COMMENT_NODE,pd=he.DOCUMENT_NODE,mf=he.DOCUMENT_TYPE_NODE,gd=he.DOCUMENT_FRAGMENT_NODE,yf=V(e=>e.nodeType===pd);var At=Symbol;var In=At(),vn=At(),Js=At(),Ks=At(),Ws=At(),On=At(),Xs=At(),rn=At(),Qs=At(),qi=e=>{e.length===1&&e[0]?.constructor===Function&&(e=e[0]());let t=[],n=[],r=0;for(;r<e.length;r++){let s=e[r];if(s===void 0)break;if(s.constructor===String||s.constructor===Number)t.push(s);else if(s.constructor===Object)break}for(r>0&&n.push(t.join(""));r<e.length;r++){let s=e[r];s instanceof Symbol||n.push(s)}return n};var wf=Ht();var xd={[In]:Ct("font-weight","bold"),[vn]:Ct("font-weight","normal"),[Js]:Ct("color","blue"),[Ws]:Ct("color","green"),[Ks]:Ct("color","grey"),[On]:Ct("color","red"),[Xs]:Ct("color","purple"),[rn]:Ct("color","orange"),[Qs]:Ct("color","black")},Sd=e=>{e.length===1&&e[0]?.constructor===Function&&(e=e[0]());let t=[],n=[],r=O(),s=[],o=0;for(;o<e.length;o++){let i=e[o],c=xd[i];if(c!==void 0)r.set(c.left,c.right);else{if(i===void 0)break;if(i.constructor===String||i.constructor===Number){let l=zi(r);o>0||l.length>0?(t.push("%c"+i),n.push(l)):t.push(i)}else break}}for(o>0&&(s=n,s.unshift(t.join("")));o<e.length;o++){let i=e[o];i instanceof Symbol||s.push(i)}return s},Gi=Ui?Sd:qi,Ir=(...e)=>{console.log(...Gi(e)),Hi.forEach(t=>t.print(e))},Zs=(...e)=>{console.warn(...Gi(e)),e.unshift(rn),Hi.forEach(t=>t.print(e))};var Hi=bt();var Ji=e=>({[Symbol.iterator](){return this},next:e}),Ki=(e,t)=>Ji(()=>{let n;do n=e.next();while(!n.done&&!t(n.value));return n}),vr=(e,t)=>Ji(()=>{let{done:n,value:r}=e.next();return{done:n,value:n?void 0:t(r)}});var eo=class extends Yt{constructor(t,n){super(),this.doc=t,this.awareness=n}},Ln=class{constructor(t,n){this.clock=t,this.len=n}},Xt=class{constructor(){this.clients=new Map}},ge=(e,t,n)=>t.clients.forEach((r,s)=>{let o=e.doc.store.clients.get(s);if(o!=null){let i=o[o.length-1],c=i.id.clock+i.length;for(let l=0,a=r[l];l<r.length&&a.clock<c;a=r[++l])yc(e,o,a.clock,a.len,n)}}),Cd=(e,t)=>{let n=0,r=e.length-1;for(;n<=r;){let s=Y((n+r)/2),o=e[s],i=o.clock;if(i<=t){if(t<i+o.len)return s;n=s+1}else r=s-1}return null},Ae=(e,t)=>{let n=e.clients.get(t.client);return n!==void 0&&Cd(n,t.clock)!==null},ho=e=>{e.clients.forEach(t=>{t.sort((s,o)=>s.clock-o.clock);let n,r;for(n=1,r=1;n<t.length;n++){let s=t[r-1],o=t[n];s.clock+s.len>=o.clock?s.len=Rt(s.len,o.clock+o.len-s.clock):(r<n&&(t[r]=o),r++)}t.length=r})},Nt=e=>{let t=new Xt;for(let n=0;n<e.length;n++)e[n].clients.forEach((r,s)=>{if(!t.clients.has(s)){let o=r.slice();for(let i=n+1;i<e.length;i++)ci(o,e[i].clients.get(s)||[]);t.clients.set(s,o)}});return ho(t),t},Nn=(e,t,n,r)=>{P(e.clients,t,()=>[]).push(new Ln(n,r))},Kr=()=>new Xt,fo=e=>{let t=Kr();return e.clients.forEach((n,r)=>{let s=[];for(let o=0;o<n.length;o++){let i=n[o];if(i.deleted){let c=i.id.clock,l=i.length;if(o+1<n.length)for(let a=n[o+1];o+1<n.length&&a.deleted;a=n[++o+1])l+=a.length;s.push(new Ln(c,l))}}s.length>0&&t.clients.set(r,s)}),t},Dt=(e,t)=>{m(e.restEncoder,t.clients.size),mt(t.clients.entries()).sort((n,r)=>r[0]-n[0]).forEach(([n,r])=>{e.resetDsCurVal(),m(e.restEncoder,n);let s=r.length;m(e.restEncoder,s);for(let o=0;o<s;o++){let i=r[o];e.writeDsClock(i.clock),e.writeDsLen(i.len)}})},Mt=e=>{let t=new Xt,n=S(e.restDecoder);for(let r=0;r<n;r++){e.resetDsCurVal();let s=S(e.restDecoder),o=S(e.restDecoder);if(o>0){let i=P(t.clients,s,()=>[]);for(let c=0;c<o;c++)i.push(new Ln(e.readDsClock(),e.readDsLen()))}}return t},Qi=(e,t,n)=>{let r=new Xt,s=S(e.restDecoder);for(let o=0;o<s;o++){e.resetDsCurVal();let i=S(e.restDecoder),c=S(e.restDecoder),l=n.clients.get(i)||[],a=I(n,i);for(let d=0;d<c;d++){let u=e.readDsClock(),h=u+e.readDsLen();if(u<a){a<h&&Nn(r,i,a,h-a);let f=ft(l,u),p=l[f];for(!p.deleted&&p.id.clock<u&&(l.splice(f+1,0,Jr(t,p,u-p.id.clock)),f++);f<l.length&&(p=l[f++],p.id.clock<h);)p.deleted||(h<p.id.clock+p.length&&l.splice(f,0,Jr(t,p,h-p.id.clock)),p.delete(t))}else Nn(r,i,u,h-u)}}if(r.clients.size>0){let o=new dt;return m(o.restEncoder,0),Dt(o,r),o.toUint8Array()}return null},Wr=(e,t)=>{if(e.clients.size!==t.clients.size)return!1;for(let[n,r]of e.clients.entries()){let s=t.clients.get(n);if(s===void 0||r.length!==s.length)return!1;for(let o=0;o<r.length;o++){let i=r[o],c=s[o];if(i.clock!==c.clock||i.len!==c.len)return!1}}return!0},fc=Cs,Tt=class e extends Yt{constructor({guid:t=xi(),collectionid:n=null,gc:r=!0,gcFilter:s=()=>!0,meta:o=null,autoLoad:i=!1,shouldLoad:c=!0}={}){super(),this.gc=r,this.gcFilter=s,this.clientID=fc(),this.guid=t,this.collectionid=n,this.share=new Map,this.store=new Pr,this._transaction=null,this._transactionCleanups=[],this.subdocs=new Set,this._item=null,this.shouldLoad=c,this.autoLoad=i,this.meta=o,this.isLoaded=!1,this.isSynced=!1,this.isDestroyed=!1,this.whenLoaded=Ds(a=>{this.on("load",()=>{this.isLoaded=!0,a(this)})});let l=()=>Ds(a=>{let d=u=>{(u===void 0||u===!0)&&(this.off("sync",d),a())};this.on("sync",d)});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(){let t=this._item;t!==null&&!this.shouldLoad&&D(t.parent.doc,n=>{n.subdocsLoaded.add(this)},null,!0),this.shouldLoad=!0}getSubdocs(){return this.subdocs}getSubdocGuids(){return new Set(mt(this.subdocs).map(t=>t.guid))}transact(t,n=null){return D(this,t,n)}get(t,n=R){let r=P(this.share,t,()=>{let o=new n;return o._integrate(this,null),o}),s=r.constructor;if(n!==R&&s!==n)if(s===R){let o=new n;o._map=r._map,r._map.forEach(i=>{for(;i!==null;i=i.left)i.parent=o}),o._start=r._start;for(let i=o._start;i!==null;i=i.right)i.parent=o;return o._length=r._length,this.share.set(t,o),o._integrate(this,null),o}else throw new Error(`Type with the name ${t} has already been defined with a different constructor`);return r}getArray(t=""){return this.get(t,Se)}getText(t=""){return this.get(t,cn)}getMap(t=""){return this.get(t,_e)}getXmlElement(t=""){return this.get(t,be)}getXmlFragment(t=""){return this.get(t,Ee)}toJSON(){let t={};return this.share.forEach((n,r)=>{t[r]=n.toJSON()}),t}destroy(){this.isDestroyed=!0,mt(this.subdocs).forEach(n=>n.destroy());let t=this._item;if(t!==null){this._item=null;let n=t.content;n.doc=new e({guid:this.guid,...n.opts,shouldLoad:!1}),n.doc._item=t,D(t.parent.doc,r=>{let s=n.doc;t.deleted||r.subdocsAdded.add(s),r.subdocsRemoved.add(this)},null,!0)}this.emit("destroyed",[!0]),this.emit("destroy",[this]),super.destroy()}},me=class{constructor(t){this.restDecoder=t}resetDsCurVal(){}readDsClock(){return S(this.restDecoder)}readDsLen(){return S(this.restDecoder)}},it=class extends me{readLeftID(){return y(S(this.restDecoder),S(this.restDecoder))}readRightID(){return y(S(this.restDecoder),S(this.restDecoder))}readClient(){return S(this.restDecoder)}readInfo(){return le(this.restDecoder)}readString(){return Gt(this.restDecoder)}readParentInfo(){return S(this.restDecoder)===1}readTypeRef(){return S(this.restDecoder)}readLen(){return S(this.restDecoder)}readAny(){return Je(this.restDecoder)}readBuf(){return vi(q(this.restDecoder))}readJSON(){return JSON.parse(Gt(this.restDecoder))}readKey(){return Gt(this.restDecoder)}},Vr=class{constructor(t){this.dsCurrVal=0,this.restDecoder=t}resetDsCurVal(){this.dsCurrVal=0}readDsClock(){return this.dsCurrVal+=S(this.restDecoder),this.dsCurrVal}readDsLen(){let t=S(this.restDecoder)+1;return this.dsCurrVal+=t,t}},tt=class extends Vr{constructor(t){super(t),this.keys=[],S(t),this.keyClockDecoder=new Ke(q(t)),this.clientDecoder=new ae(q(t)),this.leftClockDecoder=new Ke(q(t)),this.rightClockDecoder=new Ke(q(t)),this.infoDecoder=new Sn(q(t),le),this.stringDecoder=new ar(q(t)),this.parentInfoDecoder=new Sn(q(t),le),this.typeRefDecoder=new ae(q(t)),this.lenDecoder=new ae(q(t))}readLeftID(){return new Lt(this.clientDecoder.read(),this.leftClockDecoder.read())}readRightID(){return new Lt(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 Je(this.restDecoder)}readBuf(){return q(this.restDecoder)}readJSON(){return Je(this.restDecoder)}readKey(){let t=this.keyClockDecoder.read();if(t<this.keys.length)return this.keys[t];{let n=this.stringDecoder.read();return this.keys.push(n),n}}},Qt=class{constructor(){this.restEncoder=wt()}toUint8Array(){return W(this.restEncoder)}resetDsCurVal(){}writeDsClock(t){m(this.restEncoder,t)}writeDsLen(t){m(this.restEncoder,t)}},Ut=class extends Qt{writeLeftID(t){m(this.restEncoder,t.client),m(this.restEncoder,t.clock)}writeRightID(t){m(this.restEncoder,t.client),m(this.restEncoder,t.clock)}writeClient(t){m(this.restEncoder,t)}writeInfo(t){qe(this.restEncoder,t)}writeString(t){zt(this.restEncoder,t)}writeParentInfo(t){m(this.restEncoder,t?1:0)}writeTypeRef(t){m(this.restEncoder,t)}writeLen(t){m(this.restEncoder,t)}writeAny(t){Ye(this.restEncoder,t)}writeBuf(t){z(this.restEncoder,t)}writeJSON(t){zt(this.restEncoder,JSON.stringify(t))}writeKey(t){zt(this.restEncoder,t)}},sn=class{constructor(){this.restEncoder=wt(),this.dsCurrVal=0}toUint8Array(){return W(this.restEncoder)}resetDsCurVal(){this.dsCurrVal=0}writeDsClock(t){let n=t-this.dsCurrVal;this.dsCurrVal=t,m(this.restEncoder,n)}writeDsLen(t){t===0&&j(),m(this.restEncoder,t-1),this.dsCurrVal+=t}},dt=class extends sn{constructor(){super(),this.keyMap=new Map,this.keyClock=0,this.keyClockEncoder=new ze,this.clientEncoder=new ce,this.leftClockEncoder=new ze,this.rightClockEncoder=new ze,this.infoEncoder=new wn(qe),this.stringEncoder=new lr,this.parentInfoEncoder=new wn(qe),this.typeRefEncoder=new ce,this.lenEncoder=new ce}toUint8Array(){let t=wt();return m(t,0),z(t,this.keyClockEncoder.toUint8Array()),z(t,this.clientEncoder.toUint8Array()),z(t,this.leftClockEncoder.toUint8Array()),z(t,this.rightClockEncoder.toUint8Array()),z(t,W(this.infoEncoder)),z(t,this.stringEncoder.toUint8Array()),z(t,W(this.parentInfoEncoder)),z(t,this.typeRefEncoder.toUint8Array()),z(t,this.lenEncoder.toUint8Array()),Ge(t,W(this.restEncoder)),W(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){Ye(this.restEncoder,t)}writeBuf(t){z(this.restEncoder,t)}writeJSON(t){Ye(this.restEncoder,t)}writeKey(t){let n=this.keyMap.get(t);n===void 0?(this.keyClockEncoder.write(this.keyClock++),this.stringEncoder.write(t)):this.keyClockEncoder.write(n)}},Ad=(e,t,n,r)=>{r=Rt(r,t[0].id.clock);let s=ft(t,r);m(e.restEncoder,t.length-s),e.writeClient(n),m(e.restEncoder,r);let o=t[s];o.write(e,r-o.id.clock);for(let i=s+1;i<t.length;i++)t[i].write(e,0)},po=(e,t,n)=>{let r=new Map;n.forEach((s,o)=>{I(t,o)>s&&r.set(o,s)}),qn(t).forEach((s,o)=>{n.has(o)||r.set(o,0)}),m(e.restEncoder,r.size),mt(r.entries()).sort((s,o)=>o[0]-s[0]).forEach(([s,o])=>{Ad(e,t.clients.get(s),s,o)})},Dd=(e,t)=>{let n=O(),r=S(e.restDecoder);for(let s=0;s<r;s++){let o=S(e.restDecoder),i=new Array(o),c=e.readClient(),l=S(e.restDecoder);n.set(c,{i:0,refs:i});for(let a=0;a<o;a++){let d=e.readInfo();switch(31&d){case 0:{let u=e.readLen();i[a]=new Q(y(c,l),u),l+=u;break}case 10:{let u=S(e.restDecoder);i[a]=new H(y(c,l),u),l+=u;break}default:{let u=(d&192)===0,h=new T(y(c,l),null,(d&128)===128?e.readLeftID():null,null,(d&64)===64?e.readRightID():null,u?e.readParentInfo()?t.get(e.readString()):e.readLeftID():null,u&&(d&32)===32?e.readString():null,Jc(e,d));i[a]=h,l+=h.length}}}}return n},Td=(e,t,n)=>{let r=[],s=mt(n.keys()).sort((f,p)=>f-p);if(s.length===0)return null;let o=()=>{if(s.length===0)return null;let f=n.get(s[s.length-1]);for(;f.refs.length===f.i;)if(s.pop(),s.length>0)f=n.get(s[s.length-1]);else return null;return f},i=o();if(i===null)return null;let c=new Pr,l=new Map,a=(f,p)=>{let g=l.get(f);(g==null||g>p)&&l.set(f,p)},d=i.refs[i.i++],u=new Map,h=()=>{for(let f of r){let p=f.id.client,g=n.get(p);g?(g.i--,c.clients.set(p,g.refs.slice(g.i)),n.delete(p),g.i=0,g.refs=[]):c.clients.set(p,[f]),s=s.filter(E=>E!==p)}r.length=0};for(;;){if(d.constructor!==H){let p=P(u,d.id.client,()=>I(t,d.id.client))-d.id.clock;if(p<0)r.push(d),a(d.id.client,d.id.clock-1),h();else{let g=d.getMissing(e,t);if(g!==null){r.push(d);let E=n.get(g)||{refs:[],i:0};if(E.refs.length===E.i)a(g,I(t,g)),h();else{d=E.refs[E.i++];continue}}else(p===0||p<d.length)&&(d.integrate(e,p),u.set(d.id.client,d.id.clock+d.length))}}if(r.length>0)d=r.pop();else if(i!==null&&i.i<i.refs.length)d=i.refs[i.i++];else{if(i=o(),i===null)break;d=i.refs[i.i++]}}if(c.clients.size>0){let f=new dt;return po(f,c,new Map),m(f.restEncoder,0),{missing:l,update:f.toUint8Array()}}return null},Ud=(e,t)=>po(e,t.doc.store,t.beforeState),go=(e,t,n,r=new tt(e))=>D(t,s=>{s.local=!1;let o=!1,i=s.doc,c=i.store,l=Dd(r,i),a=Td(s,c,l),d=c.pendingStructs;if(d){for(let[h,f]of d.missing)if(f<I(c,h)){o=!0;break}if(a){for(let[h,f]of a.missing){let p=d.missing.get(h);(p==null||p>f)&&d.missing.set(h,f)}d.update=we([d.update,a.update])}}else c.pendingStructs=a;let u=Qi(r,s,c);if(c.pendingDs){let h=new tt(N(c.pendingDs));S(h.restDecoder);let f=Qi(h,s,c);u&&f?c.pendingDs=we([u,f]):c.pendingDs=u||f}else c.pendingDs=u;if(o){let h=c.pendingStructs.update;c.pendingStructs=null,St(s.doc,h)}},n,!1),Id=(e,t,n)=>go(e,t,n,new it(e)),St=(e,t,n,r=tt)=>{let s=N(t);go(s,e,n,new r(s))},mo=(e,t,n)=>St(e,t,n,it),vd=(e,t,n=new Map)=>{po(e,t.store,n),Dt(e,fo(t.store))},Bt=(e,t=new Uint8Array([0]),n=new dt)=>{let r=wo(t);vd(n,e,r);let s=[n.toUint8Array()];if(e.store.pendingDs&&s.push(e.store.pendingDs),e.store.pendingStructs&&s.push(bo(e.store.pendingStructs.update,t)),s.length>1){if(n.constructor===Ut)return bc(s.map((o,i)=>i===0?o:Tc(o)));if(n.constructor===dt)return we(s)}return s[0]},yo=(e,t)=>Bt(e,t,new Ut),pc=e=>{let t=new Map,n=S(e.restDecoder);for(let r=0;r<n;r++){let s=S(e.restDecoder),o=S(e.restDecoder);t.set(s,o)}return t},wo=e=>pc(new me(N(e))),xo=(e,t)=>(m(e.restEncoder,t.size),mt(t.entries()).sort((n,r)=>r[0]-n[0]).forEach(([n,r])=>{m(e.restEncoder,n),m(e.restEncoder,r)}),e),Od=(e,t)=>xo(e,qn(t.store)),Rd=(e,t=new sn)=>(e instanceof Map?xo(t,e):Od(t,e),t.toUint8Array()),So=e=>Rd(e,new Qt),no=class{constructor(){this.l=[]}},Zi=()=>new no,tc=(e,t)=>e.l.push(t),ec=(e,t)=>{let n=e.l,r=n.length;e.l=n.filter(s=>t!==s),r===e.l.length&&console.error("[yjs] Tried to remove event handler that doesn't exist.")},gc=(e,t,n)=>kn(e.l,[t,n]),Lt=class{constructor(t,n){this.client=t,this.clock=n}},fe=(e,t)=>e===t||e!==null&&t!==null&&e.client===t.client&&e.clock===t.clock,y=(e,t)=>new Lt(e,t),nc=(e,t)=>{m(e,t.client),m(e,t.clock)},rc=e=>y(S(e),S(e)),_o=e=>{for(let[t,n]of e.doc.share.entries())if(n===e)return t;throw j()},Mn=(e,t)=>{for(;t!==null;){if(t.parent===e)return!0;t=t.parent._item}return!1},Ld=e=>{let t=[],n=e._start;for(;n;)t.push(n),n=n.right;console.log("Children: ",t),console.log("Children content: ",t.filter(r=>!r.deleted).map(r=>r.content))},ro=class{constructor(t,n=t.getMap("users")){let r=new Map;this.yusers=n,this.doc=t,this.clients=new Map,this.dss=r;let s=(o,i)=>{let c=o.get("ds"),l=o.get("ids"),a=d=>this.clients.set(d,i);c.observe(d=>{d.changes.added.forEach(u=>{u.content.getContent().forEach(h=>{h instanceof Uint8Array&&this.dss.set(i,Nt([this.dss.get(i)||Kr(),Mt(new me(N(h)))]))})})}),this.dss.set(i,Nt(c.map(d=>Mt(new me(N(d)))))),l.observe(d=>d.changes.added.forEach(u=>u.content.getContent().forEach(a))),l.forEach(a)};n.observe(o=>{o.keysChanged.forEach(i=>s(n.get(i),i))}),n.forEach(s)}setUserMapping(t,n,r,{filter:s=()=>!0}={}){let o=this.yusers,i=o.get(r);i||(i=new _e,i.set("ids",new Se),i.set("ds",new Se),o.set(r,i)),i.get("ids").push([n]),o.observe(c=>{setTimeout(()=>{let l=o.get(r);if(l!==i){i=l,this.clients.forEach((u,h)=>{r===u&&i.get("ids").push([h])});let a=new Qt,d=this.dss.get(r);d&&(Dt(a,d),i.get("ds").push([a.toUint8Array()]))}},0)}),t.on("afterTransaction",c=>{setTimeout(()=>{let l=i.get("ds"),a=c.deleteSet;if(c.local&&a.clients.size>0&&s(c,a)){let d=new Qt;Dt(d,a),l.push([d.toUint8Array()])}})})}getUserByClientId(t){return this.clients.get(t)||null}getUserByDeletedId(t){for(let[n,r]of this.dss.entries())if(Ae(r,t))return n;return null}},on=class{constructor(t,n,r,s=0){this.type=t,this.tname=n,this.item=r,this.assoc=s}},Nd=e=>{let t={};return e.type&&(t.type=e.type),e.tname&&(t.tname=e.tname),e.item&&(t.item=e.item),e.assoc!=null&&(t.assoc=e.assoc),t},Md=e=>new on(e.type==null?null:y(e.type.client,e.type.clock),e.tname??null,e.item==null?null:y(e.item.client,e.item.clock),e.assoc==null?0:e.assoc),Br=class{constructor(t,n,r=0){this.type=t,this.index=n,this.assoc=r}},Vd=(e,t,n=0)=>new Br(e,t,n),Or=(e,t,n)=>{let r=null,s=null;return e._item===null?s=_o(e):r=y(e._item.id.client,e._item.id.clock),new on(r,s,t,n)},Bd=(e,t,n=0)=>{let r=e._start;if(n<0){if(t===0)return Or(e,null,n);t--}for(;r!==null;){if(!r.deleted&&r.countable){if(r.length>t)return Or(e,y(r.id.client,r.id.clock+t),n);t-=r.length}if(r.right===null&&n<0)return Or(e,r.lastId,n);r=r.right}return Or(e,null,n)},Pd=(e,t)=>{let{type:n,tname:r,item:s,assoc:o}=t;if(s!==null)m(e,0),nc(e,s);else if(r!==null)qe(e,1),zt(e,r);else if(n!==null)qe(e,2),nc(e,n);else throw j();return xn(e,o),e},$d=e=>{let t=wt();return Pd(t,e),W(t)},jd=e=>{let t=null,n=null,r=null;switch(S(e)){case 0:r=rc(e);break;case 1:n=Gt(e);break;case 2:t=rc(e)}let s=Es(e)?_n(e):0;return new on(t,n,r,s)},Fd=e=>jd(N(e)),Yd=(e,t)=>{let n=pe(e,t),r=t.clock-n.id.clock;return{item:n,diff:r}},zd=(e,t,n=!0)=>{let r=t.store,s=e.item,o=e.type,i=e.tname,c=e.assoc,l=null,a=0;if(s!==null){if(I(r,s.client)<=s.clock)return null;let d=n?ao(r,s):Yd(r,s),u=d.item;if(!(u instanceof T))return null;if(l=u.parent,l._item===null||!l._item.deleted){a=u.deleted||!u.countable?0:d.diff+(c>=0?0:1);let h=u.left;for(;h!==null;)!h.deleted&&h.countable&&(a+=h.length),h=h.left}}else{if(i!==null)l=t.get(i);else if(o!==null){if(I(r,o.client)<=o.clock)return null;let{item:d}=n?ao(r,o):{item:pe(r,o)};if(d instanceof T&&d.content instanceof pt)l=d.content.type;else return null}else throw j();c>=0?a=l._length:a=0}return Vd(l,a,e.assoc)},qd=(e,t)=>e===t||e!==null&&t!==null&&e.tname===t.tname&&fe(e.item,t.item)&&fe(e.type,t.type)&&e.assoc===t.assoc,Vn=class{constructor(t,n){this.ds=t,this.sv=n}},Gd=(e,t)=>{let n=e.ds.clients,r=t.ds.clients,s=e.sv,o=t.sv;if(s.size!==o.size||n.size!==r.size)return!1;for(let[i,c]of s.entries())if(o.get(i)!==c)return!1;for(let[i,c]of n.entries()){let l=r.get(i)||[];if(c.length!==l.length)return!1;for(let a=0;a<c.length;a++){let d=c[a],u=l[a];if(d.clock!==u.clock||d.len!==u.len)return!1}}return!0},Xr=(e,t=new sn)=>(Dt(t,e.ds),xo(t,e.sv),t.toUint8Array()),Hd=e=>Xr(e,new Qt),Qr=(e,t=new Vr(N(e)))=>new Vn(Mt(t),pc(t)),Jd=e=>Qr(e,new me(N(e))),Eo=(e,t)=>new Vn(e,t),Kd=Eo(Kr(),new Map),zn=e=>Eo(fo(e.store),qn(e.store)),Jt=(e,t)=>t===void 0?!e.deleted:t.sv.has(e.id.client)&&(t.sv.get(e.id.client)||0)>e.id.clock&&!Ae(t.ds,e.id),so=(e,t)=>{let n=P(e.meta,so,bt),r=e.doc.store;n.has(t)||(t.sv.forEach((s,o)=>{s<I(r,o)&&X(e,y(o,s))}),ge(e,t.ds,s=>{}),n.add(t))},Wd=(e,t,n=new Tt)=>{if(e.gc)throw new Error("Garbage-collection must be disabled in `originDoc`!");let{sv:r,ds:s}=t,o=new dt;return e.transact(i=>{let c=0;r.forEach(l=>{l>0&&c++}),m(o.restEncoder,c);for(let[l,a]of r){if(a===0)continue;a<I(e.store,l)&&X(i,y(l,a));let d=e.store.clients.get(l)||[],u=ft(d,a-1);m(o.restEncoder,u+1),o.writeClient(l),m(o.restEncoder,0);for(let h=0;h<=u;h++)d[h].write(o,0)}Dt(o,s)}),St(n,o.toUint8Array(),"snapshot"),n},Xd=(e,t,n=tt)=>{let r=new n(N(t)),s=new It(r,!1);for(let i=s.curr;i!==null;i=s.next())if((e.sv.get(i.id.client)||0)<i.id.clock+i.length)return!1;let o=Nt([e.ds,Mt(r)]);return Wr(e.ds,o)},Qd=(e,t)=>Xd(e,t,it),Pr=class{constructor(){this.clients=new Map,this.pendingStructs=null,this.pendingDs=null}},qn=e=>{let t=new Map;return e.clients.forEach((n,r)=>{let s=n[n.length-1];t.set(r,s.id.clock+s.length)}),t},I=(e,t)=>{let n=e.clients.get(t);if(n===void 0)return 0;let r=n[n.length-1];return r.id.clock+r.length},mc=(e,t)=>{let n=e.clients.get(t.id.client);if(n===void 0)n=[],e.clients.set(t.id.client,n);else{let r=n[n.length-1];if(r.id.clock+r.length!==t.id.clock)throw j()}n.push(t)},ft=(e,t)=>{let n=0,r=e.length-1,s=e[r],o=s.id.clock;if(o===t)return r;let i=Y(t/(o+s.length-1)*r);for(;n<=r;){if(s=e[i],o=s.id.clock,o<=t){if(t<o+s.length)return i;n=i+1}else r=i-1;i=Y((n+r)/2)}throw j()},Zd=(e,t)=>{let n=e.clients.get(t.client);return n[ft(n,t.clock)]},pe=Zd,oo=(e,t,n)=>{let r=ft(t,n),s=t[r];return s.id.clock<n&&s instanceof T?(t.splice(r+1,0,Jr(e,s,n-s.id.clock)),r+1):r},X=(e,t)=>{let n=e.doc.store.clients.get(t.client);return n[oo(e,n,t.clock)]},io=(e,t,n)=>{let r=t.clients.get(n.client),s=ft(r,n.clock),o=r[s];return n.clock!==o.id.clock+o.length-1&&o.constructor!==Q&&r.splice(s+1,0,Jr(e,o,n.clock-o.id.clock+1)),o},tu=(e,t,n)=>{let r=e.clients.get(t.id.client);r[ft(r,t.id.clock)]=n},yc=(e,t,n,r,s)=>{if(r===0)return;let o=n+r,i=oo(e,t,n),c;do c=t[i++],o<c.id.clock+c.length&&oo(e,t,o),s(c);while(i<t.length&&t[i].id.clock<o)},$r=class{constructor(t,n,r){this.doc=t,this.deleteSet=new Xt,this.beforeState=qn(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=r,this.subdocsAdded=new Set,this.subdocsRemoved=new Set,this.subdocsLoaded=new Set,this._needFormattingCleanup=!1}},sc=(e,t)=>t.deleteSet.clients.size===0&&!ii(t.afterState,(n,r)=>t.beforeState.get(r)!==n)?!1:(ho(t.deleteSet),Ud(e,t),Dt(e,t.deleteSet),!0),oc=(e,t,n)=>{let r=t._item;(r===null||r.id.clock<(e.beforeState.get(r.id.client)||0)&&!r.deleted)&&P(e.changed,t,bt).add(n)},Nr=(e,t)=>{let n=e[t],r=e[t-1],s=t;for(;s>0;n=r,r=e[--s-1]){if(r.deleted===n.deleted&&r.constructor===n.constructor&&r.mergeWith(n)){n instanceof T&&n.parentSub!==null&&n.parent._map.get(n.parentSub)===n&&n.parent._map.set(n.parentSub,r);continue}break}let o=t-s;return o&&e.splice(t+1-o,o),o},wc=(e,t,n)=>{for(let[r,s]of e.clients.entries()){let o=t.clients.get(r);for(let i=s.length-1;i>=0;i--){let c=s[i],l=c.clock+c.len;for(let a=ft(o,c.clock),d=o[a];a<o.length&&d.id.clock<l;d=o[++a]){let u=o[a];if(c.clock+c.len<=u.id.clock)break;u instanceof T&&u.deleted&&!u.keep&&n(u)&&u.gc(t,!1)}}}},xc=(e,t)=>{e.clients.forEach((n,r)=>{let s=t.clients.get(r);for(let o=n.length-1;o>=0;o--){let i=n[o],c=or(s.length-1,1+ft(s,i.clock+i.len-1));for(let l=c,a=s[l];l>0&&a.id.clock>=i.clock;a=s[l])l-=1+Nr(s,l)}})},eu=(e,t,n)=>{wc(e,t,n),xc(e,t)},Sc=(e,t)=>{if(t<e.length){let n=e[t],r=n.doc,s=r.store,o=n.deleteSet,i=n._mergeStructs;try{ho(o),n.afterState=qn(n.doc.store),r.emit("beforeObserverCalls",[n,r]);let 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)&&(l=l.filter(d=>d.target._item===null||!d.target._item.deleted),l.forEach(d=>{d.currentTarget=a,d._path=null}),l.sort((d,u)=>d.path.length-u.path.length),c.push(()=>{gc(a._dEH,l,n)}))}),c.push(()=>r.emit("afterTransaction",[n,r])),c.push(()=>{n._needFormattingCleanup&&bu(n)})}),kn(c,[])}finally{r.gc&&wc(o,s,r.gcFilter),xc(o,s),n.afterState.forEach((d,u)=>{let h=n.beforeState.get(u)||0;if(h!==d){let f=s.clients.get(u),p=Rt(ft(f,h),1);for(let g=f.length-1;g>=p;)g-=1+Nr(f,g)}});for(let d=i.length-1;d>=0;d--){let{client:u,clock:h}=i[d].id,f=s.clients.get(u),p=ft(f,h);p+1<f.length&&Nr(f,p+1)>1||p>0&&Nr(f,p)}if(!n.local&&n.afterState.get(r.clientID)!==n.beforeState.get(r.clientID)&&(Ir(rn,In,"[yjs] ",vn,On,"Changed the client-id because another client seems to be using it."),r.clientID=fc()),r.emit("afterTransactionCleanup",[n,r]),r._observers.has("update")){let d=new Ut;sc(d,n)&&r.emit("update",[d.toUint8Array(),n.origin,r,n])}if(r._observers.has("updateV2")){let d=new dt;sc(d,n)&&r.emit("updateV2",[d.toUint8Array(),n.origin,r,n])}let{subdocsAdded:c,subdocsLoaded:l,subdocsRemoved:a}=n;(c.size>0||a.size>0||l.size>0)&&(c.forEach(d=>{d.clientID=r.clientID,d.collectionid==null&&(d.collectionid=r.collectionid),r.subdocs.add(d)}),a.forEach(d=>r.subdocs.delete(d)),r.emit("subdocs",[{loaded:l,added:c,removed:a},r,n]),a.forEach(d=>d.destroy())),e.length<=t+1?(r._transactionCleanups=[],r.emit("afterAllTransactions",[r,e])):Sc(e,t+1)}}},D=(e,t,n=null,r=!0)=>{let s=e._transactionCleanups,o=!1,i=null;e._transaction===null&&(o=!0,e._transaction=new $r(e,n,r),s.push(e._transaction),s.length===1&&e.emit("beforeAllTransactions",[e]),e.emit("beforeTransaction",[e._transaction,e]));try{i=t(e._transaction)}finally{if(o){let c=e._transaction===s[0];e._transaction=null,c&&Sc(s,0)}}return i},co=class{constructor(t,n){this.insertions=n,this.deletions=t,this.meta=new Map}},ic=(e,t,n)=>{ge(e,n.deletions,r=>{r instanceof T&&t.scope.some(s=>s===e.doc||Mn(s,r))&&To(r,!1)})},cc=(e,t,n)=>{let r=null,s=e.doc,o=e.scope;D(s,c=>{for(;t.length>0&&e.currStackItem===null;){let l=s.store,a=t.pop(),d=new Set,u=[],h=!1;ge(c,a.insertions,f=>{if(f instanceof T){if(f.redone!==null){let{item:p,diff:g}=ao(l,f.id);g>0&&(p=X(c,y(p.id.client,p.id.clock+g))),f=p}!f.deleted&&o.some(p=>p===c.doc||Mn(p,f))&&u.push(f)}}),ge(c,a.deletions,f=>{f instanceof T&&o.some(p=>p===c.doc||Mn(p,f))&&!Ae(a.insertions,f.id)&&d.add(f)}),d.forEach(f=>{h=Hc(c,f,d,a.insertions,e.ignoreRemoteMapChanges,e)!==null||h});for(let f=u.length-1;f>=0;f--){let p=u[f];e.deleteFilter(p)&&(p.delete(c),h=!0)}e.currStackItem=h?a:null}c.changed.forEach((l,a)=>{l.has(null)&&a._searchMarker&&(a._searchMarker.length=0)}),r=c},e);let i=e.currStackItem;if(i!=null){let c=r.changedParentTypes;e.emit("stack-item-popped",[{stackItem:i,type:n,changedParentTypes:c,origin:e},e]),e.currStackItem=null}return i},ye=class extends Yt{constructor(t,{captureTimeout:n=500,captureTransaction:r=l=>!0,deleteFilter:s=()=>!0,trackedOrigins:o=new Set([null]),ignoreRemoteMapChanges:i=!1,doc:c=yt(t)?t[0].doc:t instanceof Tt?t:t.doc}={}){super(),this.scope=[],this.doc=c,this.addToScope(t),this.deleteFilter=s,o.add(this),this.trackedOrigins=o,this.captureTransaction=r,this.undoStack=[],this.redoStack=[],this.undoing=!1,this.redoing=!1,this.currStackItem=null,this.lastChange=0,this.ignoreRemoteMapChanges=i,this.captureTimeout=n,this.afterTransactionHandler=l=>{if(!this.captureTransaction(l)||!this.scope.some(E=>l.changedParentTypes.has(E)||E===this.doc)||!this.trackedOrigins.has(l.origin)&&(!l.origin||!this.trackedOrigins.has(l.origin.constructor)))return;let a=this.undoing,d=this.redoing,u=a?this.redoStack:this.undoStack;a?this.stopCapturing():d||this.clear(!1,!0);let h=new Xt;l.afterState.forEach((E,A)=>{let C=l.beforeState.get(A)||0,rt=E-C;rt>0&&Nn(h,A,C,rt)});let f=Ht(),p=!1;if(this.lastChange>0&&f-this.lastChange<this.captureTimeout&&u.length>0&&!a&&!d){let E=u[u.length-1];E.deletions=Nt([E.deletions,l.deleteSet]),E.insertions=Nt([E.insertions,h])}else u.push(new co(l.deleteSet,h)),p=!0;!a&&!d&&(this.lastChange=f),ge(l,l.deleteSet,E=>{E instanceof T&&this.scope.some(A=>A===l.doc||Mn(A,E))&&To(E,!0)});let g=[{stackItem:u[u.length-1],origin:l.origin,type:a?"redo":"undo",changedParentTypes:l.changedParentTypes},this];p?this.emit("stack-item-added",g):this.emit("stack-item-updated",g)},this.doc.on("afterTransaction",this.afterTransactionHandler),this.doc.on("destroy",()=>{this.destroy()})}addToScope(t){let n=new Set(this.scope);t=yt(t)?t:[t],t.forEach(r=>{n.has(r)||(n.add(r),(r instanceof R?r.doc!==this.doc:r!==this.doc)&&Zs("[yjs#509] Not same Y.Doc"),this.scope.push(r))})}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(r=>{t&&(this.undoStack.forEach(s=>ic(r,this,s)),this.undoStack=[]),n&&(this.redoStack.forEach(s=>ic(r,this,s)),this.redoStack=[]),this.emit("stack-cleared",[{undoStackCleared:t,redoStackCleared:n}])})}stopCapturing(){this.lastChange=0}undo(){this.undoing=!0;let t;try{t=cc(this,this.undoStack,"undo")}finally{this.undoing=!1}return t}redo(){this.redoing=!0;let t;try{t=cc(this,this.redoStack,"redo")}finally{this.redoing=!1}return t}canUndo(){return this.undoStack.length>0}canRedo(){return this.redoStack.length>0}destroy(){this.trackedOrigins.delete(this),this.doc.off("afterTransaction",this.afterTransactionHandler),super.destroy()}};function*nu(e){let t=S(e.restDecoder);for(let n=0;n<t;n++){let r=S(e.restDecoder),s=e.readClient(),o=S(e.restDecoder);for(let i=0;i<r;i++){let c=e.readInfo();if(c===10){let l=S(e.restDecoder);yield new H(y(s,o),l),o+=l}else if((31&c)!==0){let l=(c&192)===0,a=new T(y(s,o),null,(c&128)===128?e.readLeftID():null,null,(c&64)===64?e.readRightID():null,l?e.readParentInfo()?e.readString():e.readLeftID():null,l&&(c&32)===32?e.readString():null,Jc(e,c));yield a,o+=a.length}else{let l=e.readLen();yield new Q(y(s,o),l),o+=l}}}}var It=class{constructor(t,n){this.gen=nu(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===H);return this.curr}},ru=e=>_c(e,it),_c=(e,t=tt)=>{let n=[],r=new t(N(e)),s=new It(r,!1);for(let i=s.curr;i!==null;i=s.next())n.push(i);Ir("Structs: ",n);let o=Mt(r);Ir("DeleteSet: ",o)},su=e=>Ec(e,it),Ec=(e,t=tt)=>{let n=[],r=new t(N(e)),s=new It(r,!1);for(let o=s.curr;o!==null;o=s.next())n.push(o);return{structs:n,ds:Mt(r)}},Bn=class{constructor(t){this.currClient=0,this.startClock=0,this.written=0,this.encoder=t,this.clientStructs=[]}},bc=e=>we(e,it,Ut),kc=(e,t=sn,n=tt)=>{let r=new t,s=new It(new n(N(e)),!1),o=s.curr;if(o!==null){let i=0,c=o.id.client,l=o.id.clock!==0,a=l?0:o.id.clock+o.length;for(;o!==null;o=s.next())c!==o.id.client&&(a!==0&&(i++,m(r.restEncoder,c),m(r.restEncoder,a)),c=o.id.client,a=0,l=o.id.clock!==0),o.constructor===H&&(l=!0),l||(a=o.id.clock+o.length);a!==0&&(i++,m(r.restEncoder,c),m(r.restEncoder,a));let d=wt();return m(d,i),gi(d,r.restEncoder),r.restEncoder=d,r.toUint8Array()}else return m(r.restEncoder,0),r.toUint8Array()},ou=e=>kc(e,Qt,it),Cc=(e,t=tt)=>{let n=new Map,r=new Map,s=new It(new t(N(e)),!1),o=s.curr;if(o!==null){let i=o.id.client,c=o.id.clock;for(n.set(i,c);o!==null;o=s.next())i!==o.id.client&&(r.set(i,c),n.set(o.id.client,o.id.clock),i=o.id.client),c=o.id.clock+o.length;r.set(i,c)}return{from:n,to:r}},iu=e=>Cc(e,it),cu=(e,t)=>{if(e.constructor===Q){let{client:n,clock:r}=e.id;return new Q(y(n,r+t),e.length-t)}else if(e.constructor===H){let{client:n,clock:r}=e.id;return new H(y(n,r+t),e.length-t)}else{let n=e,{client:r,clock:s}=n.id;return new T(y(r,s+t),null,y(r,s+t-1),null,n.rightOrigin,n.parent,n.parentSub,n.content.splice(t))}},we=(e,t=tt,n=dt)=>{if(e.length===1)return e[0];let r=e.map(d=>new t(N(d))),s=r.map(d=>new It(d,!0)),o=null,i=new n,c=new Bn(i);for(;s=s.filter(h=>h.curr!==null),s.sort((h,f)=>{if(h.curr.id.client===f.curr.id.client){let p=h.curr.id.clock-f.curr.id.clock;return p===0?h.curr.constructor===f.curr.constructor?0:h.curr.constructor===H?1:-1:p}else return f.curr.id.client-h.curr.id.client}),s.length!==0;){let d=s[0],u=d.curr.id.client;if(o!==null){let h=d.curr,f=!1;for(;h!==null&&h.id.clock+h.length<=o.struct.id.clock+o.struct.length&&h.id.client>=o.struct.id.client;)h=d.next(),f=!0;if(h===null||h.id.client!==u||f&&h.id.clock>o.struct.id.clock+o.struct.length)continue;if(u!==o.struct.id.client)Kt(c,o.struct,o.offset),o={struct:h,offset:0},d.next();else if(o.struct.id.clock+o.struct.length<h.id.clock)if(o.struct.constructor===H)o.struct.length=h.id.clock+h.length-o.struct.id.clock;else{Kt(c,o.struct,o.offset);let p=h.id.clock-o.struct.id.clock-o.struct.length;o={struct:new H(y(u,o.struct.id.clock+o.struct.length),p),offset:0}}else{let p=o.struct.id.clock+o.struct.length-h.id.clock;p>0&&(o.struct.constructor===H?o.struct.length-=p:h=cu(h,p)),o.struct.mergeWith(h)||(Kt(c,o.struct,o.offset),o={struct:h,offset:0},d.next())}}else o={struct:d.curr,offset:0},d.next();for(let h=d.curr;h!==null&&h.id.client===u&&h.id.clock===o.struct.id.clock+o.struct.length&&h.constructor!==H;h=d.next())Kt(c,o.struct,o.offset),o={struct:h,offset:0}}o!==null&&(Kt(c,o.struct,o.offset),o=null),ko(c);let l=r.map(d=>Mt(d)),a=Nt(l);return Dt(i,a),i.toUint8Array()},bo=(e,t,n=tt,r=dt)=>{let s=wo(t),o=new r,i=new Bn(o),c=new n(N(e)),l=new It(c,!1);for(;l.curr;){let d=l.curr,u=d.id.client,h=s.get(u)||0;if(l.curr.constructor===H){l.next();continue}if(d.id.clock+d.length>h)for(Kt(i,d,Rt(h-d.id.clock,0)),l.next();l.curr&&l.curr.id.client===u;)Kt(i,l.curr,0),l.next();else for(;l.curr&&l.curr.id.client===u&&l.curr.id.clock+l.curr.length<=h;)l.next()}ko(i);let a=Mt(c);return Dt(o,a),o.toUint8Array()},lu=(e,t)=>bo(e,t,it,Ut),Ac=e=>{e.written>0&&(e.clientStructs.push({written:e.written,restEncoder:W(e.encoder.restEncoder)}),e.encoder.restEncoder=wt(),e.written=0)},Kt=(e,t,n)=>{e.written>0&&e.currClient!==t.id.client&&Ac(e),e.written===0&&(e.currClient=t.id.client,e.encoder.writeClient(t.id.client),m(e.encoder.restEncoder,t.id.clock+n)),t.write(e.encoder,n),e.written++},ko=e=>{Ac(e);let t=e.encoder.restEncoder;m(t,e.clientStructs.length);for(let n=0;n<e.clientStructs.length;n++){let r=e.clientStructs[n];m(t,r.written),Ge(t,r.restEncoder)}},Zr=(e,t,n,r)=>{let s=new n(N(e)),o=new It(s,!1),i=new r,c=new Bn(i);for(let a=o.curr;a!==null;a=o.next())Kt(c,t(a),0);ko(c);let l=Mt(s);return Dt(i,l),i.toUint8Array()},Dc=({formatting:e=!0,subdocs:t=!0,yxml:n=!0}={})=>{let r=0,s=O(),o=O(),i=O(),c=O();return c.set(null,null),l=>{switch(l.constructor){case Q:case H:return l;case T:{let a=l,d=a.content;switch(d.constructor){case an:break;case pt:{if(n){let u=d.type;u instanceof be&&(u.nodeName=P(o,u.nodeName,()=>"node-"+r)),u instanceof Fn&&(u.hookName=P(o,u.hookName,()=>"hook-"+r))}break}case Zt:{let u=d;u.arr=u.arr.map(()=>r);break}case ke:{let u=d;u.content=new Uint8Array([r]);break}case Ce:{let u=d;t&&(u.opts={},u.doc.guid=r+"");break}case Vt:{let u=d;u.embed={};break}case L:{let u=d;e&&(u.key=P(i,u.key,()=>r+""),u.value=P(c,u.value,()=>({i:r})));break}case Yn:{let u=d;u.arr=u.arr.map(()=>r);break}case xt:{let u=d;u.str=cr(r%10+"",u.str.length);break}default:j()}return a.parentSub&&(a.parentSub=P(s,a.parentSub,()=>r+"")),r++,l}default:j()}}},au=(e,t)=>Zr(e,Dc(t),it,Ut),du=(e,t)=>Zr(e,Dc(t),tt,dt),uu=e=>Zr(e,Ls,it,dt),Tc=e=>Zr(e,Ls,tt,Ut),lc="You must not compute changes after the event-handler fired.",xe=class{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=hu(this.currentTarget,this.target))}deletes(t){return Ae(this.transaction.deleteSet,t.id)}get keys(){if(this._keys===null){if(this.transaction.doc._transactionCleanups.length===0)throw lt(lc);let t=new Map,n=this.target;this.transaction.changed.get(n).forEach(s=>{if(s!==null){let o=n._map.get(s),i,c;if(this.adds(o)){let l=o.left;for(;l!==null&&this.adds(l);)l=l.left;if(this.deletes(o))if(l!==null&&this.deletes(l))i="delete",c=rr(l.content.getContent());else return;else l!==null&&this.deletes(l)?(i="update",c=rr(l.content.getContent())):(i="add",c=void 0)}else if(this.deletes(o))i="delete",c=rr(o.content.getContent());else return;t.set(s,{action:i,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 lt(lc);let n=this.target,r=bt(),s=bt(),o=[];if(t={added:r,deleted:s,delta:o,keys:this.keys},this.transaction.changed.get(n).has(null)){let c=null,l=()=>{c&&o.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,s.add(a)):this.adds(a)?((c===null||c.insert===void 0)&&(l(),c={insert:[]}),c.insert=c.insert.concat(a.content.getContent()),r.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}},hu=(e,t)=>{let n=[];for(;t._item!==null&&t!==e;){if(t._item.parentSub!==null)n.unshift(t._item.parentSub);else{let r=0,s=t._item.parent._start;for(;s!==t._item&&s!==null;)!s.deleted&&s.countable&&(r+=s.length),s=s.right;n.unshift(r)}t=t._item.parent}return n},J=()=>{Zs("Invalid access: Add Yjs type to a document before reading data.")},Uc=80,Co=0,lo=class{constructor(t,n){t.marker=!0,this.p=t,this.index=n,this.timestamp=Co++}},fu=e=>{e.timestamp=Co++},Ic=(e,t,n)=>{e.p.marker=!1,e.p=t,t.marker=!0,e.index=n,e.timestamp=Co++},pu=(e,t,n)=>{if(e.length>=Uc){let r=e.reduce((s,o)=>s.timestamp<o.timestamp?s:o);return Ic(r,t,n),r}else{let r=new lo(t,n);return e.push(r),r}},ts=(e,t)=>{if(e._start===null||t===0||e._searchMarker===null)return null;let n=e._searchMarker.length===0?null:e._searchMarker.reduce((o,i)=>oe(t-o.index)<oe(t-i.index)?o:i),r=e._start,s=0;for(n!==null&&(r=n.p,s=n.index,fu(n));r.right!==null&&s<t;){if(!r.deleted&&r.countable){if(t<s+r.length)break;s+=r.length}r=r.right}for(;r.left!==null&&s>t;)r=r.left,!r.deleted&&r.countable&&(s-=r.length);for(;r.left!==null&&r.left.id.client===r.id.client&&r.left.id.clock+r.left.length===r.id.clock;)r=r.left,!r.deleted&&r.countable&&(s-=r.length);return n!==null&&oe(n.index-s)<r.parent.length/Uc?(Ic(n,r,s),n):pu(e._searchMarker,r,s)},Pn=(e,t,n)=>{for(let r=e.length-1;r>=0;r--){let s=e[r];if(n>0){let o=s.p;for(o.marker=!1;o&&(o.deleted||!o.countable);)o=o.left,o&&!o.deleted&&o.countable&&(s.index-=o.length);if(o===null||o.marker===!0){e.splice(r,1);continue}s.p=o,o.marker=!0}(t<s.index||n>0&&t===s.index)&&(s.index=Rt(t,s.index+n))}},gu=e=>{e.doc??J();let t=e._start,n=[];for(;t;)n.push(t),t=t.right;return n},es=(e,t,n)=>{let r=e,s=t.changedParentTypes;for(;P(s,e,()=>[]).push(n),e._item!==null;)e=e._item.parent;gc(r._eH,n,t)},R=class{constructor(){this._item=null,this._map=new Map,this._start=null,this.doc=null,this._length=0,this._eH=Zi(),this._dEH=Zi(),this._searchMarker=null}get parent(){return this._item?this._item.parent:null}_integrate(t,n){this.doc=t,this._item=n}_copy(){throw at()}clone(){throw at()}_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){tc(this._eH,t)}observeDeep(t){tc(this._dEH,t)}unobserve(t){ec(this._eH,t)}unobserveDeep(t){ec(this._dEH,t)}toJSON(){}},vc=(e,t,n)=>{e.doc??J(),t<0&&(t=e._length+t),n<0&&(n=e._length+n);let r=n-t,s=[],o=e._start;for(;o!==null&&r>0;){if(o.countable&&!o.deleted){let i=o.content.getContent();if(i.length<=t)t-=i.length;else{for(let c=t;c<i.length&&r>0;c++)s.push(i[c]),r--;t=0}}o=o.right}return s},Oc=e=>{e.doc??J();let t=[],n=e._start;for(;n!==null;){if(n.countable&&!n.deleted){let r=n.content.getContent();for(let s=0;s<r.length;s++)t.push(r[s])}n=n.right}return t},mu=(e,t)=>{let n=[],r=e._start;for(;r!==null;){if(r.countable&&Jt(r,t)){let s=r.content.getContent();for(let o=0;o<s.length;o++)n.push(s[o])}r=r.right}return n},$n=(e,t)=>{let n=0,r=e._start;for(e.doc??J();r!==null;){if(r.countable&&!r.deleted){let s=r.content.getContent();for(let o=0;o<s.length;o++)t(s[o],n++,e)}r=r.right}},Rc=(e,t)=>{let n=[];return $n(e,(r,s)=>{n.push(t(r,s,e))}),n},yu=e=>{let t=e._start,n=null,r=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(),r=0,t=t.right}let s=n[r++];return n.length<=r&&(n=null),{done:!1,value:s}}}},Lc=(e,t)=>{e.doc??J();let n=ts(e,t),r=e._start;for(n!==null&&(r=n.p,t-=n.index);r!==null;r=r.right)if(!r.deleted&&r.countable){if(t<r.length)return r.content.getContent()[t];t-=r.length}},jr=(e,t,n,r)=>{let s=n,o=e.doc,i=o.clientID,c=o.store,l=n===null?t._start:n.right,a=[],d=()=>{a.length>0&&(s=new T(y(i,I(c,i)),s,s&&s.lastId,l,l&&l.id,t,null,new Zt(a)),s.integrate(e,0),a=[])};r.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(d(),u.constructor){case Uint8Array:case ArrayBuffer:s=new T(y(i,I(c,i)),s,s&&s.lastId,l,l&&l.id,t,null,new ke(new Uint8Array(u))),s.integrate(e,0);break;case Tt:s=new T(y(i,I(c,i)),s,s&&s.lastId,l,l&&l.id,t,null,new Ce(u)),s.integrate(e,0);break;default:if(u instanceof R)s=new T(y(i,I(c,i)),s,s&&s.lastId,l,l&&l.id,t,null,new pt(u)),s.integrate(e,0);else throw new Error("Unexpected content type in insert operation")}}}),d()},Nc=()=>lt("Length exceeded!"),Mc=(e,t,n,r)=>{if(n>t._length)throw Nc();if(n===0)return t._searchMarker&&Pn(t._searchMarker,n,r.length),jr(e,t,null,r);let s=n,o=ts(t,n),i=t._start;for(o!==null&&(i=o.p,n-=o.index,n===0&&(i=i.prev,n+=i&&i.countable&&!i.deleted?i.length:0));i!==null;i=i.right)if(!i.deleted&&i.countable){if(n<=i.length){n<i.length&&X(e,y(i.id.client,i.id.clock+n));break}n-=i.length}return t._searchMarker&&Pn(t._searchMarker,s,r.length),jr(e,t,i,r)},wu=(e,t,n)=>{let s=(t._searchMarker||[]).reduce((o,i)=>i.index>o.index?i:o,{index:0,p:t._start}).p;if(s)for(;s.right;)s=s.right;return jr(e,t,s,n)},Vc=(e,t,n,r)=>{if(r===0)return;let s=n,o=r,i=ts(t,n),c=t._start;for(i!==null&&(c=i.p,n-=i.index);c!==null&&n>0;c=c.right)!c.deleted&&c.countable&&(n<c.length&&X(e,y(c.id.client,c.id.clock+n)),n-=c.length);for(;r>0&&c!==null;)c.deleted||(r<c.length&&X(e,y(c.id.client,c.id.clock+r)),c.delete(e),r-=c.length),c=c.right;if(r>0)throw Nc();t._searchMarker&&Pn(t._searchMarker,s,-o+r)},Fr=(e,t,n)=>{let r=t._map.get(n);r!==void 0&&r.delete(e)},Ao=(e,t,n,r)=>{let s=t._map.get(n)||null,o=e.doc,i=o.clientID,c;if(r==null)c=new Zt([r]);else switch(r.constructor){case Number:case Object:case Boolean:case Array:case String:case Date:case BigInt:c=new Zt([r]);break;case Uint8Array:c=new ke(r);break;case Tt:c=new Ce(r);break;default:if(r instanceof R)c=new pt(r);else throw new Error("Unexpected content type")}new T(y(i,I(o.store,i)),s,s&&s.lastId,null,null,t,n,c).integrate(e,0)},Do=(e,t)=>{e.doc??J();let n=e._map.get(t);return n!==void 0&&!n.deleted?n.content.getContent()[n.length-1]:void 0},Bc=e=>{let t={};return e.doc??J(),e._map.forEach((n,r)=>{n.deleted||(t[r]=n.content.getContent()[n.length-1])}),t},Pc=(e,t)=>{e.doc??J();let n=e._map.get(t);return n!==void 0&&!n.deleted},xu=(e,t,n)=>{let r=e._map.get(t)||null;for(;r!==null&&(!n.sv.has(r.id.client)||r.id.clock>=(n.sv.get(r.id.client)||0));)r=r.left;return r!==null&&Jt(r,n)?r.content.getContent()[r.length-1]:void 0},$c=(e,t)=>{let n={};return e._map.forEach((r,s)=>{let o=r;for(;o!==null&&(!t.sv.has(o.id.client)||o.id.clock>=(t.sv.get(o.id.client)||0));)o=o.left;o!==null&&Jt(o,t)&&(n[s]=o.content.getContent()[o.length-1])}),n},Rr=e=>(e.doc??J(),Ki(e._map.entries(),t=>!t[1].deleted)),Yr=class extends xe{},Se=class e extends R{constructor(){super(),this._prelimContent=[],this._searchMarker=[]}static from(t){let n=new e;return n.push(t),n}_integrate(t,n){super._integrate(t,n),this.insert(0,this._prelimContent),this._prelimContent=null}_copy(){return new e}clone(){let t=new e;return t.insert(0,this.toArray().map(n=>n instanceof R?n.clone():n)),t}get length(){return this.doc??J(),this._length}_callObserver(t,n){super._callObserver(t,n),es(this,t,new Yr(this,t))}insert(t,n){this.doc!==null?D(this.doc,r=>{Mc(r,this,t,n)}):this._prelimContent.splice(t,0,...n)}push(t){this.doc!==null?D(this.doc,n=>{wu(n,this,t)}):this._prelimContent.push(...t)}unshift(t){this.insert(0,t)}delete(t,n=1){this.doc!==null?D(this.doc,r=>{Vc(r,this,t,n)}):this._prelimContent.splice(t,n)}get(t){return Lc(this,t)}toArray(){return Oc(this)}slice(t=0,n=this.length){return vc(this,t,n)}toJSON(){return this.map(t=>t instanceof R?t.toJSON():t)}map(t){return Rc(this,t)}forEach(t){$n(this,t)}[Symbol.iterator](){return yu(this)}_write(t){t.writeTypeRef($u)}},Su=e=>new Se,zr=class extends xe{constructor(t,n,r){super(t,n),this.keysChanged=r}},_e=class e extends R{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((r,s)=>{this.set(s,r)}),this._prelimContent=null}_copy(){return new e}clone(){let t=new e;return this.forEach((n,r)=>{t.set(r,n instanceof R?n.clone():n)}),t}_callObserver(t,n){es(this,t,new zr(this,t,n))}toJSON(){this.doc??J();let t={};return this._map.forEach((n,r)=>{if(!n.deleted){let s=n.content.getContent()[n.length-1];t[r]=s instanceof R?s.toJSON():s}}),t}get size(){return[...Rr(this)].length}keys(){return vr(Rr(this),t=>t[0])}values(){return vr(Rr(this),t=>t[1].content.getContent()[t[1].length-1])}entries(){return vr(Rr(this),t=>[t[0],t[1].content.getContent()[t[1].length-1]])}forEach(t){this.doc??J(),this._map.forEach((n,r)=>{n.deleted||t(n.content.getContent()[n.length-1],r,this)})}[Symbol.iterator](){return this.entries()}delete(t){this.doc!==null?D(this.doc,n=>{Fr(n,this,t)}):this._prelimContent.delete(t)}set(t,n){return this.doc!==null?D(this.doc,r=>{Ao(r,this,t,n)}):this._prelimContent.set(t,n),n}get(t){return Do(this,t)}has(t){return Pc(this,t)}clear(){this.doc!==null?D(this.doc,t=>{this.forEach(function(n,r,s){Fr(t,s,r)})}):this._prelimContent.clear()}_write(t){t.writeTypeRef(ju)}},_u=e=>new _e,Wt=(e,t)=>e===t||typeof e=="object"&&typeof t=="object"&&e&&t&&vs(e,t),jn=class{constructor(t,n,r,s){this.left=t,this.right=n,this.index=r,this.currentAttributes=s}forward(){this.right===null&&j(),this.right.content.constructor===L?this.right.deleted||dn(this.currentAttributes,this.right.content):this.right.deleted||(this.index+=this.right.length),this.left=this.right,this.right=this.right.right}},ac=(e,t,n)=>{for(;t.right!==null&&n>0;)t.right.content.constructor===L?t.right.deleted||dn(t.currentAttributes,t.right.content):t.right.deleted||(n<t.right.length&&X(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},Lr=(e,t,n,r)=>{let s=new Map,o=r?ts(t,n):null;if(o){let i=new jn(o.p.left,o.p,o.index,s);return ac(e,i,n-o.index)}else{let i=new jn(null,t._start,0,s);return ac(e,i,n)}},jc=(e,t,n,r)=>{for(;n.right!==null&&(n.right.deleted===!0||n.right.content.constructor===L&&Wt(r.get(n.right.content.key),n.right.content.value));)n.right.deleted||r.delete(n.right.content.key),n.forward();let s=e.doc,o=s.clientID;r.forEach((i,c)=>{let l=n.left,a=n.right,d=new T(y(o,I(s.store,o)),l,l&&l.lastId,a,a&&a.id,t,null,new L(c,i));d.integrate(e,0),n.right=d,n.forward()})},dn=(e,t)=>{let{key:n,value:r}=t;r===null?e.delete(n):e.set(n,r)},Fc=(e,t)=>{for(;e.right!==null;){if(!(e.right.deleted||e.right.content.constructor===L&&Wt(t[e.right.content.key]??null,e.right.content.value)))break;e.forward()}},Yc=(e,t,n,r)=>{let s=e.doc,o=s.clientID,i=new Map;for(let c in r){let l=r[c],a=n.currentAttributes.get(c)??null;if(!Wt(a,l)){i.set(c,a);let{left:d,right:u}=n;n.right=new T(y(o,I(s.store,o)),d,d&&d.lastId,u,u&&u.id,t,null,new L(c,l)),n.right.integrate(e,0),n.forward()}}return i},to=(e,t,n,r,s)=>{n.currentAttributes.forEach((h,f)=>{s[f]===void 0&&(s[f]=null)});let o=e.doc,i=o.clientID;Fc(n,s);let c=Yc(e,t,n,s),l=r.constructor===String?new xt(r):r instanceof R?new pt(r):new Vt(r),{left:a,right:d,index:u}=n;t._searchMarker&&Pn(t._searchMarker,n.index,l.getLength()),d=new T(y(i,I(o.store,i)),a,a&&a.lastId,d,d&&d.id,t,null,l),d.integrate(e,0),n.right=d,n.index=u,n.forward(),jc(e,t,n,c)},dc=(e,t,n,r,s)=>{let o=e.doc,i=o.clientID;Fc(n,s);let c=Yc(e,t,n,s);t:for(;n.right!==null&&(r>0||c.size>0&&(n.right.deleted||n.right.content.constructor===L));){if(!n.right.deleted)switch(n.right.content.constructor){case L:{let{key:l,value:a}=n.right.content,d=s[l];if(d!==void 0){if(Wt(d,a))c.delete(l);else{if(r===0)break t;c.set(l,a)}n.right.delete(e)}else n.currentAttributes.set(l,a);break}default:r<n.right.length&&X(e,y(n.right.id.client,n.right.id.clock+r)),r-=n.right.length;break}n.forward()}if(r>0){let l="";for(;r>0;r--)l+=` | |
| 5 | +`;n.right=new T(y(i,I(o.store,i)),n.left,n.left&&n.left.lastId,n.right,n.right&&n.right.id,t,null,new xt(l)),n.right.integrate(e,0),n.forward()}jc(e,t,n,c)},zc=(e,t,n,r,s)=>{let o=t,i=O();for(;o&&(!o.countable||o.deleted);){if(!o.deleted&&o.content.constructor===L){let a=o.content;i.set(a.key,a)}o=o.right}let c=0,l=!1;for(;t!==o;){if(n===t&&(l=!0),!t.deleted){let a=t.content;if(a.constructor===L){let{key:d,value:u}=a,h=r.get(d)??null;(i.get(d)!==a||h===u)&&(t.delete(e),c++,!l&&(s.get(d)??null)===u&&h!==u&&(h===null?s.delete(d):s.set(d,h))),!l&&!t.deleted&&dn(s,a)}}t=t.right}return c},Eu=(e,t)=>{for(;t&&t.right&&(t.right.deleted||!t.right.countable);)t=t.right;let n=new Set;for(;t&&(t.deleted||!t.countable);){if(!t.deleted&&t.content.constructor===L){let r=t.content.key;n.has(r)?t.delete(e):n.add(r)}t=t.left}},qc=e=>{let t=0;return D(e.doc,n=>{let r=e._start,s=e._start,o=O(),i=nr(o);for(;s;)s.deleted===!1&&(s.content.constructor===L?dn(i,s.content):(t+=zc(n,r,s,o,i),o=nr(i),r=s)),s=s.right}),t},bu=e=>{let t=new Set,n=e.doc;for(let[r,s]of e.afterState.entries()){let o=e.beforeState.get(r)||0;s!==o&&yc(e,n.store.clients.get(r),o,s,i=>{!i.deleted&&i.content.constructor===L&&i.constructor!==Q&&t.add(i.parent)})}D(n,r=>{ge(e,e.deleteSet,s=>{if(s instanceof Q||!s.parent._hasFormatting||t.has(s.parent))return;let o=s.parent;s.content.constructor===L?t.add(o):Eu(r,s)});for(let s of t)qc(s)})},uc=(e,t,n)=>{let r=n,s=nr(t.currentAttributes),o=t.right;for(;n>0&&t.right!==null;){if(t.right.deleted===!1)switch(t.right.content.constructor){case pt:case Vt:case xt:n<t.right.length&&X(e,y(t.right.id.client,t.right.id.clock+n)),n-=t.right.length,t.right.delete(e);break}t.forward()}o&&zc(e,o,t.right,s,t.currentAttributes);let i=(t.left||t.right).parent;return i._searchMarker&&Pn(i._searchMarker,t.index,-r+n),t},qr=class extends xe{constructor(t,n,r){super(t,n),this.childListChanged=!1,this.keysChanged=new Set,r.forEach(s=>{s===null?this.childListChanged=!0:this.keysChanged.add(s)})}get changes(){if(this._changes===null){let 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){let t=this.target.doc,n=[];D(t,r=>{let s=new Map,o=new Map,i=this.target._start,c=null,l={},a="",d=0,u=0,h=()=>{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},s.size>0&&(f.attributes={},s.forEach((p,g)=>{p!==null&&(f.attributes[g]=p)}))),a="";break;case"retain":d>0&&(f={retain:d},Ci(l)||(f.attributes=bi({},l))),d=0;break}f&&n.push(f),c=null}};for(;i!==null;){switch(i.content.constructor){case pt:case Vt:this.adds(i)?this.deletes(i)||(h(),c="insert",a=i.content.getContent()[0],h()):this.deletes(i)?(c!=="delete"&&(h(),c="delete"),u+=1):i.deleted||(c!=="retain"&&(h(),c="retain"),d+=1);break;case xt:this.adds(i)?this.deletes(i)||(c!=="insert"&&(h(),c="insert"),a+=i.content.str):this.deletes(i)?(c!=="delete"&&(h(),c="delete"),u+=i.length):i.deleted||(c!=="retain"&&(h(),c="retain"),d+=i.length);break;case L:{let{key:f,value:p}=i.content;if(this.adds(i)){if(!this.deletes(i)){let g=s.get(f)??null;Wt(g,p)?p!==null&&i.delete(r):(c==="retain"&&h(),Wt(p,o.get(f)??null)?delete l[f]:l[f]=p)}}else if(this.deletes(i)){o.set(f,p);let g=s.get(f)??null;Wt(g,p)||(c==="retain"&&h(),l[f]=g)}else if(!i.deleted){o.set(f,p);let g=l[f];g!==void 0&&(Wt(g,p)?g!==null&&i.delete(r):(c==="retain"&&h(),p===null?delete l[f]:l[f]=p))}i.deleted||(c==="insert"&&h(),dn(s,i.content));break}}i=i.right}for(h();n.length>0;){let f=n[n.length-1];if(f.retain!==void 0&&f.attributes===void 0)n.pop();else break}}),this._delta=n}return this._delta}},cn=class e extends R{constructor(t){super(),this._pending=t!==void 0?[()=>this.insert(0,t)]:[],this._searchMarker=[],this._hasFormatting=!1}get length(){return this.doc??J(),this._length}_integrate(t,n){super._integrate(t,n);try{this._pending.forEach(r=>r())}catch(r){console.error(r)}this._pending=null}_copy(){return new e}clone(){let t=new e;return t.applyDelta(this.toDelta()),t}_callObserver(t,n){super._callObserver(t,n);let r=new qr(this,t,n);es(this,t,r),!t.local&&this._hasFormatting&&(t._needFormattingCleanup=!0)}toString(){this.doc??J();let t="",n=this._start;for(;n!==null;)!n.deleted&&n.countable&&n.content.constructor===xt&&(t+=n.content.str),n=n.right;return t}toJSON(){return this.toString()}applyDelta(t,{sanitize:n=!0}={}){this.doc!==null?D(this.doc,r=>{let s=new jn(null,this._start,0,new Map);for(let o=0;o<t.length;o++){let i=t[o];if(i.insert!==void 0){let c=!n&&typeof i.insert=="string"&&o===t.length-1&&s.right===null&&i.insert.slice(-1)===` | |
| 6 | +`?i.insert.slice(0,-1):i.insert;(typeof c!="string"||c.length>0)&&to(r,this,s,c,i.attributes||{})}else i.retain!==void 0?dc(r,this,s,i.retain,i.attributes||{}):i.delete!==void 0&&uc(r,s,i.delete)}}):this._pending.push(()=>this.applyDelta(t))}toDelta(t,n,r){this.doc??J();let s=[],o=new Map,i=this.doc,c="",l=this._start;function a(){if(c.length>0){let u={},h=!1;o.forEach((p,g)=>{h=!0,u[g]=p});let f={insert:c};h&&(f.attributes=u),s.push(f),c=""}}let d=()=>{for(;l!==null;){if(Jt(l,t)||n!==void 0&&Jt(l,n))switch(l.content.constructor){case xt:{let u=o.get("ychange");t!==void 0&&!Jt(l,t)?(u===void 0||u.user!==l.id.client||u.type!=="removed")&&(a(),o.set("ychange",r?r("removed",l.id):{type:"removed"})):n!==void 0&&!Jt(l,n)?(u===void 0||u.user!==l.id.client||u.type!=="added")&&(a(),o.set("ychange",r?r("added",l.id):{type:"added"})):u!==void 0&&(a(),o.delete("ychange")),c+=l.content.str;break}case pt:case Vt:{a();let u={insert:l.content.getContent()[0]};if(o.size>0){let h={};u.attributes=h,o.forEach((f,p)=>{h[p]=f})}s.push(u);break}case L:Jt(l,t)&&(a(),dn(o,l.content));break}l=l.right}a()};return t||n?D(i,u=>{t&&so(u,t),n&&so(u,n),d()},"cleanup"):d(),s}insert(t,n,r){if(n.length<=0)return;let s=this.doc;s!==null?D(s,o=>{let i=Lr(o,this,t,!r);r||(r={},i.currentAttributes.forEach((c,l)=>{r[l]=c})),to(o,this,i,n,r)}):this._pending.push(()=>this.insert(t,n,r))}insertEmbed(t,n,r){let s=this.doc;s!==null?D(s,o=>{let i=Lr(o,this,t,!r);to(o,this,i,n,r||{})}):this._pending.push(()=>this.insertEmbed(t,n,r||{}))}delete(t,n){if(n===0)return;let r=this.doc;r!==null?D(r,s=>{uc(s,Lr(s,this,t,!0),n)}):this._pending.push(()=>this.delete(t,n))}format(t,n,r){if(n===0)return;let s=this.doc;s!==null?D(s,o=>{let i=Lr(o,this,t,!1);i.right!==null&&dc(o,this,i,n,r)}):this._pending.push(()=>this.format(t,n,r))}removeAttribute(t){this.doc!==null?D(this.doc,n=>{Fr(n,this,t)}):this._pending.push(()=>this.removeAttribute(t))}setAttribute(t,n){this.doc!==null?D(this.doc,r=>{Ao(r,this,t,n)}):this._pending.push(()=>this.setAttribute(t,n))}getAttribute(t){return Do(this,t)}getAttributes(){return Bc(this)}_write(t){t.writeTypeRef(Fu)}},ku=e=>new cn,Rn=class{constructor(t,n=()=>!0){this._filter=n,this._root=t,this._currentNode=t._start,this._firstCall=!0,t.doc??J()}[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===be||n.constructor===Ee)&&n._start!==null)t=n._start;else for(;t!==null;){let r=t.next;if(r!==null){t=r;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})}},Ee=class e extends R{constructor(){super(),this._prelimContent=[]}get firstChild(){let 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 e}clone(){let t=new e;return t.insert(0,this.toArray().map(n=>n instanceof R?n.clone():n)),t}get length(){return this.doc??J(),this._prelimContent===null?this._length:this._prelimContent.length}createTreeWalker(t){return new Rn(this,t)}querySelector(t){t=t.toUpperCase();let r=new Rn(this,s=>s.nodeName&&s.nodeName.toUpperCase()===t).next();return r.done?null:r.value}querySelectorAll(t){return t=t.toUpperCase(),mt(new Rn(this,n=>n.nodeName&&n.nodeName.toUpperCase()===t))}_callObserver(t,n){es(this,t,new Gr(this,n,t))}toString(){return Rc(this,t=>t.toString()).join("")}toJSON(){return this.toString()}toDOM(t=document,n={},r){let s=t.createDocumentFragment();return r!==void 0&&r._createAssociation(s,this),$n(this,o=>{s.insertBefore(o.toDOM(t,n,r),null)}),s}insert(t,n){this.doc!==null?D(this.doc,r=>{Mc(r,this,t,n)}):this._prelimContent.splice(t,0,...n)}insertAfter(t,n){if(this.doc!==null)D(this.doc,r=>{let s=t&&t instanceof R?t._item:t;jr(r,this,s,n)});else{let r=this._prelimContent,s=t===null?0:r.findIndex(o=>o===t)+1;if(s===0&&t!==null)throw lt("Reference item not found");r.splice(s,0,...n)}}delete(t,n=1){this.doc!==null?D(this.doc,r=>{Vc(r,this,t,n)}):this._prelimContent.splice(t,n)}toArray(){return Oc(this)}push(t){this.insert(this.length,t)}unshift(t){this.insert(0,t)}get(t){return Lc(this,t)}slice(t=0,n=this.length){return vc(this,t,n)}forEach(t){$n(this,t)}_write(t){t.writeTypeRef(zu)}},Cu=e=>new Ee,be=class e extends Ee{constructor(t="UNDEFINED"){super(),this.nodeName=t,this._prelimAttrs=new Map}get nextSibling(){let t=this._item?this._item.next:null;return t?t.content.type:null}get prevSibling(){let t=this._item?this._item.prev:null;return t?t.content.type:null}_integrate(t,n){super._integrate(t,n),this._prelimAttrs.forEach((r,s)=>{this.setAttribute(s,r)}),this._prelimAttrs=null}_copy(){return new e(this.nodeName)}clone(){let t=new e(this.nodeName),n=this.getAttributes();return ki(n,(r,s)=>{t.setAttribute(s,r)}),t.insert(0,this.toArray().map(r=>r instanceof R?r.clone():r)),t}toString(){let t=this.getAttributes(),n=[],r=[];for(let c in t)r.push(c);r.sort();let s=r.length;for(let c=0;c<s;c++){let l=r[c];n.push(l+'="'+t[l]+'"')}let o=this.nodeName.toLocaleLowerCase(),i=n.length>0?" "+n.join(" "):"";return`<${o}${i}>${super.toString()}</${o}>`}removeAttribute(t){this.doc!==null?D(this.doc,n=>{Fr(n,this,t)}):this._prelimAttrs.delete(t)}setAttribute(t,n){this.doc!==null?D(this.doc,r=>{Ao(r,this,t,n)}):this._prelimAttrs.set(t,n)}getAttribute(t){return Do(this,t)}hasAttribute(t){return Pc(this,t)}getAttributes(t){return t?$c(this,t):Bc(this)}toDOM(t=document,n={},r){let s=t.createElement(this.nodeName),o=this.getAttributes();for(let i in o){let c=o[i];typeof c=="string"&&s.setAttribute(i,c)}return $n(this,i=>{s.appendChild(i.toDOM(t,n,r))}),r!==void 0&&r._createAssociation(s,this),s}_write(t){t.writeTypeRef(Yu),t.writeKey(this.nodeName)}},Au=e=>new be(e.readKey()),Gr=class extends xe{constructor(t,n,r){super(t,r),this.childListChanged=!1,this.attributesChanged=new Set,n.forEach(s=>{s===null?this.childListChanged=!0:this.attributesChanged.add(s)})}},Fn=class e extends _e{constructor(t){super(),this.hookName=t}_copy(){return new e(this.hookName)}clone(){let t=new e(this.hookName);return this.forEach((n,r)=>{t.set(r,n)}),t}toDOM(t=document,n={},r){let s=n[this.hookName],o;return s!==void 0?o=s.createDom(this):o=document.createElement(this.hookName),o.setAttribute("data-yjs-hook",this.hookName),r!==void 0&&r._createAssociation(o,this),o}_write(t){t.writeTypeRef(qu),t.writeKey(this.hookName)}},Du=e=>new Fn(e.readKey()),Hr=class e extends cn{get nextSibling(){let t=this._item?this._item.next:null;return t?t.content.type:null}get prevSibling(){let t=this._item?this._item.prev:null;return t?t.content.type:null}_copy(){return new e}clone(){let t=new e;return t.applyDelta(this.toDelta()),t}toDOM(t=document,n,r){let s=t.createTextNode(this.toString());return r!==void 0&&r._createAssociation(s,this),s}toString(){return this.toDelta().map(t=>{let n=[];for(let s in t.attributes){let o=[];for(let i in t.attributes[s])o.push({key:i,value:t.attributes[s][i]});o.sort((i,c)=>i.key<c.key?-1:1),n.push({nodeName:s,attrs:o})}n.sort((s,o)=>s.nodeName<o.nodeName?-1:1);let r="";for(let s=0;s<n.length;s++){let o=n[s];r+=`<${o.nodeName}`;for(let i=0;i<o.attrs.length;i++){let c=o.attrs[i];r+=` ${c.key}="${c.value}"`}r+=">"}r+=t.insert;for(let s=n.length-1;s>=0;s--)r+=`</${n[s].nodeName}>`;return r}).join("")}toJSON(){return this.toString()}_write(t){t.writeTypeRef(Gu)}},Tu=e=>new Hr,ln=class{constructor(t,n){this.id=t,this.length=n}get deleted(){throw at()}mergeWith(t){return!1}write(t,n,r){throw at()}integrate(t,n){throw at()}},Uu=0,Q=class extends ln{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),mc(t.doc.store,this)}write(t,n){t.writeInfo(Uu),t.writeLen(this.length-n)}getMissing(t,n){return null}},ke=class e{constructor(t){this.content=t}getLength(){return 1}getContent(){return[this.content]}isCountable(){return!0}copy(){return new e(this.content)}splice(t){throw at()}mergeWith(t){return!1}integrate(t,n){}delete(t){}gc(t){}write(t,n){t.writeBuf(this.content)}getRef(){return 3}},Iu=e=>new ke(e.readBuf()),an=class e{constructor(t){this.len=t}getLength(){return this.len}getContent(){return[]}isCountable(){return!1}copy(){return new e(this.len)}splice(t){let n=new e(this.len-t);return this.len=t,n}mergeWith(t){return this.len+=t.len,!0}integrate(t,n){Nn(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}},vu=e=>new an(e.readLen()),Gc=(e,t)=>new Tt({guid:e,...t,shouldLoad:t.shouldLoad||t.autoLoad||!1}),Ce=class e{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;let 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 e(Gc(this.doc.guid,this.opts))}splice(t){throw at()}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}},Ou=e=>new Ce(Gc(e.readString(),e.readAny())),Vt=class e{constructor(t){this.embed=t}getLength(){return 1}getContent(){return[this.embed]}isCountable(){return!0}copy(){return new e(this.embed)}splice(t){throw at()}mergeWith(t){return!1}integrate(t,n){}delete(t){}gc(t){}write(t,n){t.writeJSON(this.embed)}getRef(){return 5}},Ru=e=>new Vt(e.readJSON()),L=class e{constructor(t,n){this.key=t,this.value=n}getLength(){return 1}getContent(){return[]}isCountable(){return!1}copy(){return new e(this.key,this.value)}splice(t){throw at()}mergeWith(t){return!1}integrate(t,n){let r=n.parent;r._searchMarker=null,r._hasFormatting=!0}delete(t){}gc(t){}write(t,n){t.writeKey(this.key),t.writeJSON(this.value)}getRef(){return 6}},Lu=e=>new L(e.readKey(),e.readJSON()),Yn=class e{constructor(t){this.arr=t}getLength(){return this.arr.length}getContent(){return this.arr}isCountable(){return!0}copy(){return new e(this.arr)}splice(t){let n=new e(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){let r=this.arr.length;t.writeLen(r-n);for(let s=n;s<r;s++){let o=this.arr[s];t.writeString(o===void 0?"undefined":JSON.stringify(o))}}getRef(){return 2}},Nu=e=>{let t=e.readLen(),n=[];for(let r=0;r<t;r++){let s=e.readString();s==="undefined"?n.push(void 0):n.push(JSON.parse(s))}return new Yn(n)},Mu=Cn("node_env")==="development",Zt=class e{constructor(t){this.arr=t,Mu&&Os(t)}getLength(){return this.arr.length}getContent(){return this.arr}isCountable(){return!0}copy(){return new e(this.arr)}splice(t){let n=new e(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){let r=this.arr.length;t.writeLen(r-n);for(let s=n;s<r;s++){let o=this.arr[s];t.writeAny(o)}}getRef(){return 8}},Vu=e=>{let t=e.readLen(),n=[];for(let r=0;r<t;r++)n.push(e.readAny());return new Zt(n)},xt=class e{constructor(t){this.str=t}getLength(){return this.str.length}getContent(){return this.str.split("")}isCountable(){return!0}copy(){return new e(this.str)}splice(t){let n=new e(this.str.slice(t));this.str=this.str.slice(0,t);let r=this.str.charCodeAt(t-1);return r>=55296&&r<=56319&&(this.str=this.str.slice(0,t-1)+"\uFFFD",n.str="\uFFFD"+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}},Bu=e=>new xt(e.readString()),Pu=[Su,_u,ku,Au,Cu,Du,Tu],$u=0,ju=1,Fu=2,Yu=3,zu=4,qu=5,Gu=6,pt=class e{constructor(t){this.type=t}getLength(){return 1}getContent(){return[this.type]}isCountable(){return!0}copy(){return new e(this.type._copy())}splice(t){throw at()}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(r=>{r.deleted?r.id.clock<(t.beforeState.get(r.id.client)||0)&&t._mergeStructs.push(r):r.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(r=>{for(;r!==null;)r.gc(t,!0),r=r.left}),this.type._map=new Map}write(t,n){this.type._write(t)}getRef(){return 7}},Hu=e=>new pt(Pu[e.readTypeRef()](e)),ao=(e,t)=>{let n=t,r=0,s;do r>0&&(n=y(n.client,n.clock+r)),s=pe(e,n),r=n.clock-s.id.clock,n=s.redone;while(n!==null&&s instanceof T);return{item:s,diff:r}},To=(e,t)=>{for(;e!==null&&e.keep!==t;)e.keep=t,e=e.parent._item},Jr=(e,t,n)=>{let{client:r,clock:s}=t.id,o=new T(y(r,s+n),t,y(r,s+n-1),t.right,t.rightOrigin,t.parent,t.parentSub,t.content.splice(n));return t.deleted&&o.markDeleted(),t.keep&&(o.keep=!0),t.redone!==null&&(o.redone=y(t.redone.client,t.redone.clock+n)),t.right=o,o.right!==null&&(o.right.left=o),e._mergeStructs.push(o),o.parentSub!==null&&o.right===null&&o.parent._map.set(o.parentSub,o),t.length=n,o},hc=(e,t)=>mn(e,n=>Ae(n.deletions,t)),Hc=(e,t,n,r,s,o)=>{let i=e.doc,c=i.store,l=i.clientID,a=t.redone;if(a!==null)return X(e,a);let d=t.parent._item,u=null,h;if(d!==null&&d.deleted===!0){if(d.redone===null&&(!n.has(d)||Hc(e,d,n,r,s,o)===null))return null;for(;d.redone!==null;)d=X(e,d.redone)}let f=d===null?t.parent:d.content.type;if(t.parentSub===null){for(u=t.left,h=t;u!==null;){let A=u;for(;A!==null&&A.parent._item!==d;)A=A.redone===null?null:X(e,A.redone);if(A!==null&&A.parent._item===d){u=A;break}u=u.left}for(;h!==null;){let A=h;for(;A!==null&&A.parent._item!==d;)A=A.redone===null?null:X(e,A.redone);if(A!==null&&A.parent._item===d){h=A;break}h=h.right}}else if(h=null,t.right&&!s){for(u=t;u!==null&&u.right!==null&&(u.right.redone||Ae(r,u.right.id)||hc(o.undoStack,u.right.id)||hc(o.redoStack,u.right.id));)for(u=u.right;u.redone;)u=X(e,u.redone);if(u&&u.right!==null)return null}else u=f._map.get(t.parentSub)||null;let p=I(c,l),g=y(l,p),E=new T(g,u,u&&u.lastId,h,h&&h.id,f,t.parentSub,t.content.copy());return t.redone=g,To(E,!0),E.integrate(e,0),E},T=class e extends ln{constructor(t,n,r,s,o,i,c,l){super(t,l.getLength()),this.origin=r,this.left=n,this.right=s,this.rightOrigin=o,this.parent=i,this.parentSub=c,this.redone=null,this.content=l,this.info=this.content.isCountable()?2:0}set marker(t){(this.info&8)>0!==t&&(this.info^=8)}get marker(){return(this.info&8)>0}get keep(){return(this.info&1)>0}set keep(t){this.keep!==t&&(this.info^=1)}get countable(){return(this.info&2)>0}get deleted(){return(this.info&4)>0}set deleted(t){this.deleted!==t&&(this.info^=4)}markDeleted(){this.info|=4}getMissing(t,n){if(this.origin&&this.origin.client!==this.id.client&&this.origin.clock>=I(n,this.origin.client))return this.origin.client;if(this.rightOrigin&&this.rightOrigin.client!==this.id.client&&this.rightOrigin.clock>=I(n,this.rightOrigin.client))return this.rightOrigin.client;if(this.parent&&this.parent.constructor===Lt&&this.id.client!==this.parent.client&&this.parent.clock>=I(n,this.parent.client))return this.parent.client;if(this.origin&&(this.left=io(t,n,this.origin),this.origin=this.left.lastId),this.rightOrigin&&(this.right=X(t,this.rightOrigin),this.rightOrigin=this.right.id),this.left&&this.left.constructor===Q||this.right&&this.right.constructor===Q)this.parent=null;else if(!this.parent)this.left&&this.left.constructor===e?(this.parent=this.left.parent,this.parentSub=this.left.parentSub):this.right&&this.right.constructor===e&&(this.parent=this.right.parent,this.parentSub=this.right.parentSub);else if(this.parent.constructor===Lt){let r=pe(n,this.parent);r.constructor===Q?this.parent=null:this.parent=r.content.type}return null}integrate(t,n){if(n>0&&(this.id.clock+=n,this.left=io(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 r=this.left,s;if(r!==null)s=r.right;else if(this.parentSub!==null)for(s=this.parent._map.get(this.parentSub)||null;s!==null&&s.left!==null;)s=s.left;else s=this.parent._start;let o=new Set,i=new Set;for(;s!==null&&s!==this.right;){if(i.add(s),o.add(s),fe(this.origin,s.origin)){if(s.id.client<this.id.client)r=s,o.clear();else if(fe(this.rightOrigin,s.rightOrigin))break}else if(s.origin!==null&&i.has(pe(t.doc.store,s.origin)))o.has(pe(t.doc.store,s.origin))||(r=s,o.clear());else break;s=s.right}this.left=r}if(this.left!==null){let r=this.left.right;this.right=r,this.left.right=this}else{let r;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,this.parent._start=this;this.right=r}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),mc(t.doc.store,this),this.content.integrate(t,this),oc(t,this.parent,this.parentSub),(this.parent._item!==null&&this.parent._item.deleted||this.parentSub!==null&&this.right!==null)&&this.delete(t)}else new Q(this.id,this.length).integrate(t,0)}get next(){let t=this.right;for(;t!==null&&t.deleted;)t=t.right;return t}get prev(){let t=this.left;for(;t!==null&&t.deleted;)t=t.left;return t}get lastId(){return this.length===1?this.id:y(this.id.client,this.id.clock+this.length-1)}mergeWith(t){if(this.constructor===t.constructor&&fe(t.origin,this.lastId)&&this.right===t&&fe(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)){let n=this.parent._searchMarker;return n&&n.forEach(r=>{r.p===t&&(r.p=this,!this.deleted&&this.countable&&(r.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){let n=this.parent;this.countable&&this.parentSub===null&&(n._length-=this.length),this.markDeleted(),Nn(t.deleteSet,this.id.client,this.id.clock,this.length),oc(t,n,this.parentSub),this.content.delete(t)}}gc(t,n){if(!this.deleted)throw j();this.content.gc(t),n?tu(t,this,new Q(this.id,this.length)):this.content=new an(this.length)}write(t,n){let r=n>0?y(this.id.client,this.id.clock+n-1):this.origin,s=this.rightOrigin,o=this.parentSub,i=this.content.getRef()&31|(r===null?0:128)|(s===null?0:64)|(o===null?0:32);if(t.writeInfo(i),r!==null&&t.writeLeftID(r),s!==null&&t.writeRightID(s),r===null&&s===null){let c=this.parent;if(c._item!==void 0){let l=c._item;if(l===null){let a=_o(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===Lt?(t.writeParentInfo(!1),t.writeLeftID(c)):j();o!==null&&t.writeString(o)}this.content.write(t,n)}},Jc=(e,t)=>Ju[t&31](e),Ju=[()=>{j()},vu,Nu,Iu,Bu,Ru,Lu,Hu,Vu,Ou,()=>{j()}],Ku=10,H=class extends ln{get deleted(){return!0}delete(){}mergeWith(t){return this.constructor!==t.constructor?!1:(this.length+=t.length,!0)}integrate(t,n){j()}write(t,n){t.writeInfo(Ku),m(t.restEncoder,this.length-n)}getMissing(t,n){return null}},Kc=typeof globalThis<"u"?globalThis:typeof window<"u"?window:typeof global<"u"?global:{},Wc="__ $YJS$ __";Kc[Wc]===!0&&console.error("Yjs was already imported. This breaks constructor checks and will lead to issues! - https://github.com/yjs/yjs/issues/438");Kc[Wc]=!0;var Uo=3e4,un=class extends Me{constructor(t){super(),this.doc=t,this.clientID=t.clientID,this.states=new Map,this.meta=new Map,this._checkInterval=setInterval(()=>{let n=Ht();this.getLocalState()!==null&&Uo/2<=n-this.meta.get(this.clientID).lastUpdated&&this.setLocalState(this.getLocalState());let r=[];this.meta.forEach((s,o)=>{o!==this.clientID&&Uo<=n-s.lastUpdated&&this.states.has(o)&&r.push(o)}),r.length>0&&Io(this,r,"timeout")},Y(Uo/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){let n=this.clientID,r=this.meta.get(n),s=r===void 0?0:r.clock+1,o=this.states.get(n);t===null?this.states.delete(n):this.states.set(n,t),this.meta.set(n,{clock:s,lastUpdated:Ht()});let i=[],c=[],l=[],a=[];t===null?a.push(n):o==null?t!=null&&i.push(n):(c.push(n),ue(o,t)||l.push(n)),(i.length>0||l.length>0||a.length>0)&&this.emit("change",[{added:i,updated:l,removed:a},"local"]),this.emit("update",[{added:i,updated:c,removed:a},"local"])}setLocalStateField(t,n){let r=this.getLocalState();r!==null&&this.setLocalState({...r,[t]:n})}getStates(){return this.states}},Io=(e,t,n)=>{let r=[];for(let s=0;s<t.length;s++){let o=t[s];if(e.states.has(o)){if(e.states.delete(o),o===e.clientID){let i=e.meta.get(o);e.meta.set(o,{clock:i.clock+1,lastUpdated:Ht()})}r.push(o)}}r.length>0&&(e.emit("change",[{added:[],updated:[],removed:r},n]),e.emit("update",[{added:[],updated:[],removed:r},n]))};var Xc=1,ns="fromPersistence",rs="document",hn="state",De="savedAt",Qc="savedBy",Zc="version",ss="gutenberg",vo="syncManager",tl="gutenberg-undo-ignored";var Te=(e=>(e.AUTHENTICATION_FAILED="authentication-failed",e.CONNECTION_EXPIRED="connection-expired",e.CONNECTION_LIMIT_EXCEEDED="connection-limit-exceeded",e.DOCUMENT_SIZE_LIMIT_EXCEEDED="document-size-limit-exceeded",e.PROTOCOL_MISMATCH="protocol-mismatch",e.UNKNOWN_ERROR="unknown-error",e))(Te||{}),os=class extends Error{constructor(e="unknown-error",t){super(t),this.code=e,this.name="ConnectionError"}};var rl=se(nl(),1),{lock:sl,unlock:Rf}=(0,rl.__dangerousOptInToUnstableAPIsOnlyForCoreModules)("I acknowledge private features are not for use in themes or plugins and doing so will break in the next version of WordPress.","@wordpress/sync");function ol(e){return function(...t){let n=performance.now(),r=e.apply(this,t),s=performance.now();return console.log(`[SyncManager][performance]: ${e.name} took ${(s-n).toFixed(2)} ms`),r}}function il(e){return((...t)=>e(...t))}var vl=se(is(),1);var Al=se(is(),1);var ll=0,al=1,Wu=2,dl=(e,t)=>{m(e,ll);let n=So(t);z(e,n)},Xu=(e,t,n)=>{m(e,al),z(e,yo(t,n))},Qu=(e,t,n)=>Xu(t,n,q(e)),ul=(e,t,n,r)=>{try{mo(t,q(e),n)}catch(s){r?.(s),console.error("Caught error while handling a Yjs update",s)}};var Zu=ul,Oo=(e,t,n,r,s)=>{let o=S(e);switch(o){case ll:Qu(e,t,n);break;case al:ul(e,n,r,s);break;case Wu:Zu(e,n,r,s);break;default:throw new Error("Unknown message type")}return o};var hl=se(is(),1),Ro=3,Lo=[2e3,4e3,8e3,12e3],No=[1e3,2e3,4e3,8e3],fl=3e4,pl=15e3,eh=1*1024*1024,Mo=Math.floor(eh/4)*3,Gn=50,cs=15*1024*1024,gl=2*1024*1024,nh=4e3,rh=1e3;function ml(e,t){let n=(0,hl.applyFilters)(e,t);return typeof n!="number"||!Number.isFinite(n)||n<=0?t:Math.min(n,t)}var Vo=ml("sync.pollingManager.pollingInterval",nh),yl=ml("sync.pollingManager.pollingIntervalWithCollaborators",rh),wl=25*1e3;var et=(e=>(e.COMPACTION="compaction",e.SYNC_STEP_1="sync_step1",e.SYNC_STEP_2="sync_step2",e.UPDATE="update",e))(et||{});var Bo=se(Sl(),1);var _l="/wp-sync/v1/updates";function sh(e){let t="",n=e.byteLength;for(let r=0;r<n;r++)t+=String.fromCharCode(e[r]);return globalThis.btoa(t)}function Po(e){let t=globalThis.atob(e),n=t.length,r=new Uint8Array(n);for(let s=0;s<n;s++)r[s]=t.charCodeAt(s);return r}function fn(e,t){return{data:sh(e),type:t}}function El(e=[],t=!0){let n=t,r=[...e];return{add(s){r.push(s)},addBulk(s){s.length!==0&&r.push(...s)},clear(){r.splice(0,r.length)},get(){return n?[]:r.splice(0,r.length)},pause(){n=!0},peek(){return n?[]:[...r]},restore(s){let o=s.filter(i=>i.type!==et.COMPACTION);o.length!==0&&r.unshift(...o)},restoreExact(s){s.length!==0&&r.unshift(...s)},resume(){n=!1},size(){return r.length},take(s){return n||s<=0?[]:r.splice(0,s)}}}function bl(e){return(0,Bo.default)({method:"POST",path:_l,data:e})}function $o(e){e.rooms.length!==0&&(0,Bo.default)({method:"POST",path:_l,data:e,keepalive:!0}).catch(()=>{})}function kl(e,t){let n=parseInt(String(e),10);return isNaN(n)?t:n}function Cl(e,t,n){if(e.length===0)return{window:[],nextOffset:0};let r=(t%e.length+e.length)%e.length;return{window:[...e.slice(r),...e.slice(0,r)].slice(0,Math.max(0,n)),nextOffset:(r+Math.max(0,n))%e.length}}var Wn="polling-manager";function oh(e){return e?.data?.status===403}function ih(e){return e?.data?.status===413&&e?.code==="rest_sync_body_too_large"}function ch(e){return e?.code==="rest_sync_protocol_mismatch"}function lh(e,t){let n=new Set(t.map(s=>s.room)),r=Array.isArray(e.data.rooms)?e.data.rooms.filter(s=>n.has(s)):[];if(r.length>0){for(let s of r){let o=U.get(s);o&&(o.log("Permission denied, unregistering room",{error:e},"error",!0),pn(s,{sendDisconnectSignal:!1}))}for(let s of t){if(r.includes(s.room)||!U.has(s.room))continue;let o=U.get(s.room);s.updates.length>0&&o.updateQueue.restore(s.updates)}}else{let s=[...U.keys()];for(let o of s){let i=U.get(o);i&&(i.log("Permission denied, unregistering room",{error:e},"error",!0),pn(o,{sendDisconnectSignal:!1}))}}}var U=new Map;function ah(e){let t=e.filter(n=>[et.COMPACTION,et.UPDATE].includes(n.type)).map(n=>Po(n.data));return fn(we(t),et.COMPACTION)}function dh(e){let t=wt();return dl(t,e),fn(W(t),et.SYNC_STEP_1)}function uh(e,t){let n=N(t),r=wt();return Oo(n,r,e,Wn),fn(W(r),et.SYNC_STEP_2)}function hh(e,t){let n=t.getStates(),r=new Set,s=new Set,o=new Set(Array.from(n.keys()).filter(i=>!e[i]));Object.entries(e).forEach(([i,c])=>{let l=Number(i);if(l===t.clientID)return;if(c===null){n.delete(l),o.add(l);return}if(!n.has(l)){n.set(l,c),r.add(l);return}let a=n.get(l);JSON.stringify(a)!==JSON.stringify(c)&&(n.set(l,c),s.add(l))}),r.size+s.size>0&&t.emit("change",[{added:Array.from(r),updated:Array.from(s),removed:[]}]),o.size>0&&Io(t,Array.from(o),Wn)}function fh(e,t){let n=Po(e.data);switch(e.type){case et.SYNC_STEP_1:return uh(t,n);case et.SYNC_STEP_2:{let r=N(n),s=wt();Oo(r,s,t,Wn);return}case et.COMPACTION:case et.UPDATE:St(t,n,Wn)}}function ph(e,t){if(!t.isPrimaryRoom||jo)return!1;jo=!0;let n=(0,Al.applyFilters)("sync.pollingProvider.maxClientsPerRoom",Ro,t.room),r=Object.keys(e).length,s=kl(n,Ro);return r>s?(t.log("Connection limit exceeded",{clientCount:r,maxClientsPerRoom:s,room:t.room}),!0):!1}var as=!1,Ue=0,jo=!1,ls=!1,Hn=!1,Kn=document.visibilityState==="visible",Jn=!1,Fo=!1,Et=Vo,te=null,Ie=cs,Yo=0;function Dl(){Fo=!0}function Tl(){let e=Array.from(U.entries()).map(([t,n])=>({after:0,awareness:null,client_id:n.clientId,room:t,updates:[]}));for(let t=0;t<e.length;t+=Gn)$o({rooms:e.slice(t,t+Gn)})}function Ul(){let e=Kn;Kn=document.visibilityState==="visible",Kn&&!e&&te&&(clearTimeout(te),te=null,ds())}function gh(){let e=Array.from(U.values());if(e.length<=Gn)return e;let t=e.find(i=>i.isPrimaryRoom),n=e.filter(i=>i!==t),r=Gn-(t?1:0),{window:s,nextOffset:o}=Cl(n,Yo,r);return Yo=o,t?[t,...s]:s}var mh=new TextEncoder;function zo(e){return mh.encode(JSON.stringify(e)).byteLength}function yh(e,t=[]){return{after:e.endCursor??0,awareness:e.localAwarenessState,client_id:e.clientId,room:e.room,updates:t}}function wh(e,t){return(e===0?0:1)+zo(t)}function xh(e){let t={rooms:[]},n=[];for(let c of e){let l=yh(c),a={rooms:[...t.rooms,l]};if(t.rooms.length>0&&zo(a)>Ie)break;t.rooms.push(l),n.push(c)}let r=n.map(c=>c.updateQueue.peek()),s=n.map(()=>0),o=zo(t),i=!0;for(;i;){i=!1;for(let c=0;c<n.length;c++){let l=r[c][s[c]];if(!l)continue;let a=wh(s[c],l);o+a>Ie||(s[c]++,o+=a,i=!0)}}for(let c=0;c<n.length;c++)t.rooms[c].updates=n[c].updateQueue.take(s[c]);return{payload:t,roomsInRequest:n}}function Sh(e){for(let t of e.rooms)!U.has(t.room)||t.updates.length===0||U.get(t.room).updateQueue.restoreExact(t.updates)}function ds(){Jn=!0,te=null;async function e(){if(U.size===0){Jn=!1;return}Fo=!1;let{payload:t,roomsInRequest:n}=xh(gh());n.forEach(r=>{r.onStatusChange({status:"connecting"})});try{let{rooms:r}=await bl(t);Ue=0,ls=!1,Ie=cs,n.forEach(s=>{U.get(s.room)===s&&s.onStatusChange({status:"connected"})}),Hn=!1,r.forEach(s=>{if(!U.has(s.room))return;let o=U.get(s.room);if(o.endCursor=s.end_cursor,ph(s.awareness,o)){o.onStatusChange({status:"disconnected",error:new os(Te.CONNECTION_LIMIT_EXCEEDED,"Connection limit exceeded")}),pn(s.room);return}o.processAwarenessUpdate(s.awareness),o.isPrimaryRoom&&Object.keys(s.awareness).length>1&&(Hn=!0,U.forEach(c=>{c.updateQueue.resume()}));let i=[];for(let c of s.updates)try{let l=o.processDocUpdate(c);l&&i.push(l)}catch(l){o.log("Failed to apply sync update",{error:l,update:c},"error",!0)}o.updateQueue.addBulk(i),s.should_compact?(o.log("Server requested compaction update"),o.updateQueue.clear(),o.updateQueue.add(o.createCompactionUpdate())):s.compaction_request&&(o.log("Server requested (old) compaction update"),o.updateQueue.add(ah(s.compaction_request)))}),Kn&&Hn?Et=yl:Kn?Et=Vo:Et=wl}catch(r){if(oh(r)){if(lh(r,t.rooms),U.size===0){Jn=!1;return}}else if(ih(r)){Ie=Math.max(gl,Math.floor(Ie/2)),Et=Hn?No[0]:Lo[0],Sh(t);for(let s of t.rooms)U.has(s.room)&&U.get(s.room).log("Sync request body too large, retrying with smaller batches",{error:r,nextPoll:Et,syncRequestBodySizeLimit:Ie},"error",!0)}else if(ch(r)){let s=[...U.entries()];for(let[,o]of s)o.onStatusChange({status:"disconnected",error:new os(Te.PROTOCOL_MISMATCH,"Protocol mismatch between client and server")});for(let[o]of s)pn(o,{sendDisconnectSignal:!1});Jn=!1;return}else{Ue++;let s=Hn?No:Lo;Ue<=s.length?Et=s[Ue-1]:Et=fl,ls&&(Et=pl,ls=!1);for(let o of t.rooms){if(!U.has(o.room))continue;let i=U.get(o.room);o.updates.length>0&&i.endCursor>0?(i.updateQueue.clear(),i.updateQueue.add(i.createCompactionUpdate())):o.updates.length>0&&i.updateQueue.restore(o.updates),i.log("Error posting sync update, will retry with backoff",{error:r,nextPoll:Et},"error",!0)}if(!Fo){let o=Ue>s.length;n.forEach(i=>{U.get(i.room)===i&&i.onStatusChange({status:"disconnected",canManuallyRetry:!0,consecutiveFailures:Ue,backgroundRetriesFailed:o,willAutoRetryInMs:Et})})}}}te=setTimeout(ds,Et)}e()}function _h({room:e,doc:t,awareness:n,log:r,onStatusChange:s}){if(U.has(e))return;let o=El([dh(t)]),i=U.size===0;function c(){d.localAwarenessState=n.getLocalState()??{}}function l(u,h){if(Wn!==h){if(u.byteLength>Mo){let f=U.get(e);if(!f)return;f.log("Document size limit exceeded",{maxUpdateSizeInBytes:Mo,updateSizeInBytes:u.byteLength}),f.onStatusChange({status:"disconnected",error:new os(Te.DOCUMENT_SIZE_LIMIT_EXCEEDED,"Document size limit exceeded")}),pn(e);return}o.add(fn(u,et.UPDATE))}}function a(){t.off("updateV2",l),n.off("change",c),o.clear()}let d={clientId:t.clientID,createCompactionUpdate:()=>fn(Bt(t),et.COMPACTION),endCursor:0,isPrimaryRoom:i,localAwarenessState:n.getLocalState()??{},log:r,onStatusChange:s,processAwarenessUpdate:u=>hh(u,n),processDocUpdate:u=>fh(u,t),room:e,unregister:a,updateQueue:o};t.on("updateV2",l),n.on("change",c),U.set(e,d),as||(window.addEventListener("beforeunload",Dl),window.addEventListener("pagehide",Tl),document.addEventListener("visibilitychange",Ul),as=!0),Jn||ds()}function pn(e,{sendDisconnectSignal:t=!0}={}){let n=U.get(e);if(n){if(t){let r=[{after:0,awareness:null,client_id:n.clientId,room:e,updates:[]}];$o({rooms:r})}n.unregister(),U.delete(e)}U.size===0&&as&&(window.removeEventListener("beforeunload",Dl),window.removeEventListener("pagehide",Tl),document.removeEventListener("visibilitychange",Ul),as=!1,jo=!1,Ue=0,Yo=0,Ie=cs)}function Eh(){ls=!0,te&&(clearTimeout(te),te=null,ds())}var Xn={registerRoom:_h,retryNow:Eh,unregisterRoom:pn};var bh=class extends Yt{constructor(e){super(),this.options=e,this.log("Initializing",{room:e.room}),this.awareness=e.awareness??new un(e.ydoc),this.connect()}awareness;status="disconnected";connect(){this.log("Connecting"),Xn.registerRoom({room:this.options.room,doc:this.options.ydoc,awareness:this.awareness,log:this.log,onStatusChange:this.emitStatus})}destroy(){this.disconnect(),super.destroy()}disconnect(){this.log("Disconnecting"),Xn.unregisterRoom(this.options.room),this.emitStatus({status:"disconnected"})}emitStatus=e=>{let{status:t}=e,n=t==="disconnected"?e.error:void 0;this.status===t&&!n||t==="connecting"&&this.status!=="disconnected"||(this.log("Status change",{status:t,error:n}),this.status=t,this.emit("status",[e]))};log=(e,t={},n="log",r=!1)=>{if(!this.options.debug&&!r)return;(console[n]||console.log)(`[${this.constructor.name}]: ${e}`,{room:this.options.room,...t})}};function Il(){return async({awareness:e,objectType:t,objectId:n,ydoc:r})=>{let s=n?`${t}:${n}`:t,o=new bh({awareness:e,room:s,ydoc:r});return{destroy:()=>o.destroy(),on:(i,c)=>{o.on(i,c)}}}}var gn=null;function kh(){return window.__experimentalEnableRealTimeCollaboration?[Il()]:[]}function Ch(e){return typeof e=="function"}function qo(){if(gn)return gn;if(!window.__experimentalEnableRealTimeCollaboration)return[];let e=(0,vl.applyFilters)("sync.providers",kh());return Array.isArray(e)?(gn=e.filter(Ch),gn):(gn=[],gn)}var Ol=(e,t)=>{let n=t==="undo"?e.undoStack:e.redoStack;for(;n.length>0;){let r=n.pop(),s=t==="undo"?r.undoStack:r.redoStack,o=s.pop(),i=!1;if(t==="undo"?(r.undoStack=[o],i=r.undo()!==null,r.undoStack=s):(r.redoStack=[o],i=r.redo()!==null,r.redoStack=s),i)return o}return null},Rl=class extends Me{constructor(e=[],t={}){super(),this.docs=new Map,this.trackedOrigins=t.trackedOrigins||new Set([null]),t.trackedOrigins=this.trackedOrigins,this._defaultOpts=t,this.undoStack=[],this.redoStack=[],this.addToScope(e)}addToScope(e){e=yt(e)?e:[e],e.forEach(t=>{let n=t.doc,r=P(this.docs,n,()=>{let s=new ye([t],this._defaultOpts);return s.on("stack-cleared",({undoStackCleared:o,redoStackCleared:i})=>{this.clear(o,i)}),n.on("destroy",()=>{this.docs.delete(n),this.undoStack=this.undoStack.filter(o=>o.doc!==n),this.redoStack=this.redoStack.filter(o=>o.doc!==n)}),s.on("stack-item-added",o=>{(o.type==="undo"?this.undoStack:this.redoStack).push(s),this.emit("stack-item-added",[{...o,ydoc:n},this])}),s.on("stack-item-updated",o=>{this.emit("stack-item-updated",[{...o,ydoc:n},this])}),s.on("stack-item-popped",o=>{this.emit("stack-item-popped",[{...o,ydoc:n},this])}),s});r.scope.every(s=>s!==t)&&r.scope.push(t)})}addTrackedOrigin(e){this.trackedOrigins.add(e)}removeTrackedOrigin(e){this.trackedOrigins.delete(e)}undo(){return Ol(this,"undo")}redo(){return Ol(this,"redo")}clear(e=!0,t=!0){(e&&this.canUndo()||t&&this.canRedo())&&(this.docs.forEach(n=>{e&&(this.undoStack=[]),t&&(this.redoStack=[]),n.clear(e,t)}),this.emit("stack-cleared",[{undoStackCleared:e,redoStackCleared:t}]))}stopCapturing(){this.docs.forEach(e=>{e.stopCapturing()})}canUndo(){return this.undoStack.length>0}canRedo(){return this.redoStack.length>0}destroy(){this.docs.forEach(e=>e.destroy()),super.destroy()}};function Ll(){let e=new Map,t=new Rl([],{captureTimeout:500,trackedOrigins:new Set([ss])}),n=()=>({hasRedo:t.canRedo(),hasUndo:t.canUndo()}),r=s=>{e.get(s)?.onUndoStackChange?.(n())};return t.on("stack-item-added",s=>{let o=e.get(s.ydoc);o&&(o.addUndoMeta(s.ydoc,s.stackItem.meta),r(s.ydoc))}),t.on("stack-item-updated",s=>{r(s.ydoc)}),t.on("stack-item-popped",s=>{let o=e.get(s.ydoc);o&&(o.restoreUndoMeta(s.ydoc,s.stackItem.meta),r(s.ydoc))}),t.on("stack-cleared",()=>{e.forEach(s=>{s.onUndoStackChange?.(n())})}),{addRecord(s,o=!1){},addToScope(s,o){if(s.doc===null)return;let i=s.doc;t.addToScope(s),e.has(i)||i.on("destroy",()=>e.delete(i)),e.set(i,o)},undo(){if(t.canUndo())return t.undo(),[]},redo(){if(t.canRedo())return t.redo(),[]},hasUndo(){return t.canUndo()},hasRedo(){return t.canRedo()},stopCapturing(){t.stopCapturing()}}}function Nl(e){return pr(Xr(zn(e)))}function Ml(e,t){let n;try{n=Qr(gr(t))}catch{return!1}let r=zn(e);for(let[i,c]of n.sv)if((r.sv.get(i)??0)<c)return!1;let s=zn(e).ds,o=Nt([s,n.ds]);return Wr(r.ds,o)}function Qn(e={}){let t=new Map(Object.entries(e));return new Tt({meta:t})}function Go(e){e.getMap(hn).set(Zc,Xc)}function Ho(e){let t=e.getMap(hn);t.set(De,Date.now()),t.set(Qc,e.clientID)}function Vl(){return Math.floor(Math.random()*1e9)}function Bl(e){let t=Qn();St(t,Bt(e));let n=Bt(t);return t.destroy(),JSON.stringify({document:pr(n),updateId:Vl()})}function Pl(e){try{let{document:t}=JSON.parse(e),n={[ns]:!0},r=Qn(n),s=gr(t);return St(r,s),r.clientID=Vl(),r}catch{return null}}function vt(e,t){return`${e}_${t}`}function $l(e=!1){let t=e?ol:il,n=new Map,r=new Map,s;function o(w,_,x,k={}){e&&console.log(`[SyncManager][${w}]: ${_}`,{...k,entityId:x})}async function i(w,_,x,k,b){let B=qo(),v=vt(_,x);if(B.length===0){o("loadEntity","no providers, skipping",v);return}if(r.has(v)){o("loadEntity","already loaded",v);return}if(w.shouldSync?.(_,x)===!1){o("loadEntity","shouldSync false, skipping",v);return}o("loadEntity","loading",v),b={addUndoMeta:t(b.addUndoMeta),editRecord:t(b.editRecord),getEditedRecord:t(b.getEditedRecord),onStatusChange:t(b.onStatusChange),persistCRDTDoc:t(b.persistCRDTDoc),refetchRecord:t(b.refetchRecord),restoreUndoMeta:t(b.restoreUndoMeta),onUndoStackChange:b.onUndoStackChange?t(b.onUndoStackChange):void 0};let F=Qn({objectType:_}),st=F.getMap(rs),K=F.getMap(hn),$t=Date.now(),ot=!1,ee=!1,ne=()=>{o("loadEntity","unloading",v),ee=!0,fs?.forEach(Ft=>Ft.destroy()),b.onStatusChange(null),ot&&(st.unobserveDeep(ut),K.unobserve(Ot)),F.destroy(),r.delete(v)},jt=w.createAwareness?.(F,x),ut=(Ft,re)=>{re.local&&!(re.origin instanceof ye)||Pt.updateEntityRecord(_,x)},Ot=(Ft,re)=>{re.local||Ft.keysChanged.forEach(Kl=>{if(Kl===De){let ni=K.get(De);typeof ni=="number"&&ni>$t&&(o("loadEntity","refetching record",v),b.refetchRecord().catch(()=>{}))}})};s||(s=Ll());let{addUndoMeta:Re,onUndoStackChange:Zn,restoreUndoMeta:Hl}=b;s.addToScope(st,{addUndoMeta:Re,restoreUndoMeta:Hl,onUndoStackChange:Zn});let fs,Jl={awareness:jt,handlers:b,objectId:x,objectType:_,syncConfig:w,unload:ne,ydoc:F};if(r.set(v,Jl),o("loadEntity","connecting",v),fs=await Promise.all(B.map(async Ft=>{let re=await Ft({objectType:_,objectId:x,ydoc:F,awareness:jt,Y:_t});return re.on("status",b.onStatusChange),re})),ee){o("loadEntity","unloaded during connect, aborting",v),fs.forEach(Ft=>Ft.destroy());return}Go(F),Pt.applyPersistedCrdtDoc(_,x,k),st.observeDeep(ut),K.observe(Ot),ot=!0}async function c(w,_,x){let k=qo(),b=vt(_,null);if(k.length===0){o("loadCollection","no providers, skipping",b);return}if(n.has(_)){o("loadCollection","already loaded",b);return}if(w.shouldSync?.(_,null)===!1){o("loadCollection","shouldSync false, skipping",b);return}o("loadCollection","loading",b);let B=Qn({collection:!0,objectType:_}),v=B.getMap(hn),F=Date.now(),st=!1,K=!1,$t=()=>{o("loadCollection","unloading",b),K=!0,ne?.forEach(ut=>ut.destroy()),x.onStatusChange(null),st&&v.unobserve(ot),B.destroy(),n.delete(_)},ot=(ut,Ot)=>{Ot.local||ut.keysChanged.forEach(Re=>{if(Re===De){let Zn=v.get(De);typeof Zn=="number"&&Zn>F&&x.refetchRecords().catch(()=>{})}})},ee=w.createAwareness?.(B),ne,jt={awareness:ee,handlers:x,syncConfig:w,unload:$t,ydoc:B};if(n.set(_,jt),o("loadCollection","connecting",b),ne=await Promise.all(k.map(async ut=>{let Ot=await ut({awareness:ee,objectType:_,objectId:null,ydoc:B,Y:_t});return Ot.on("status",x.onStatusChange),Ot})),K){o("loadCollection","unloaded during connect, aborting",b),ne.forEach(ut=>ut.destroy());return}v.observe(ot),st=!0,Go(B)}function l(w,_){let x=vt(w,_);o("unloadEntity","unloading",x),r.get(x)?.unload(),h(w,null,{},origin,{isSave:!0})}function a(){o("unloadAll","unloading all entities","all");for(let[,w]of[...r])w.unload();r.clear(),s=void 0;for(let[,w]of[...n])w.unload();n.clear()}function d(w,_){let x=vt(w,_),k=r.get(x);if(!(!k||!k.awareness))return k.awareness}function u(w,_,x){let k=vt(w,_),b=r.get(k);if(!b){o("applyPersistedCrdtDoc","no entity state",k);return}let{handlers:B,syncConfig:{applyChangesToCRDTDoc:v,getChangesFromCRDTDoc:F,getPersistedCRDTDoc:st},ydoc:K}=b,$t=st?.(x),ot=$t?Pl($t):null;if(!ot){o("applyPersistedCrdtDoc","no persisted doc",k),K.transact(()=>{v(K,x),B.persistCRDTDoc()},vo);return}let ee=Bt(ot);St(K,ee);let ne=F(ot,x),jt=Object.keys(ne);if(ot.destroy(),jt.length===0){o("applyPersistedCrdtDoc","valid persisted doc",k);return}o("applyPersistedCrdtDoc","invalidated keys",k,{invalidatedKeys:jt});let ut=jt.reduce((Ot,Re)=>Object.assign(Ot,{[Re]:x[Re]}),{});K.transact(()=>{v(K,ut),B.persistCRDTDoc()},vo)}function h(w,_,x,k,b={}){let{isSave:B=!1,isNewUndoLevel:v=!1}=b,F=vt(w,_),st=r.get(F),K=n.get(w);if(st){let{syncConfig:$t,ydoc:ot}=st;v&&s&&s.stopCapturing?.(),ot.transact(()=>{o("updateCRDTDoc","applying changes",F,{changedKeys:Object.keys(x)}),$t.applyChangesToCRDTDoc(ot,x),B&&Ho(ot)},k)}K&&B&&K.ydoc.transact(()=>{Ho(K.ydoc)},k)}let f=[];function p(){for(;f.length>0;){let w=f.shift();w&&h(...w)}}function g(...w){f.push(w),setTimeout(p,0)}function E(w,_,x,k,b={}){if((d(w,_)?.getStates().size??0)>1){p(),h(w,_,x,k,b);return}g(w,_,x,k,b)}function A(w,_){let x=vt(w,_),k=r.get(x);if(!k){o("getEntitySnapshot","no entity state",x);return}return p(),Nl(k.ydoc)}function C(w,_,x){let k=vt(w,_),b=r.get(k);return b?(p(),Ml(b.ydoc,x)):!1}async function rt(w,_){let x=vt(w,_),k=r.get(x);if(!k){o("updateEntityRecord","no entity state",x);return}let{handlers:b,syncConfig:B,ydoc:v}=k,F=B.getChangesFromCRDTDoc(v,await b.getEditedRecord()),st=Object.keys(F);st.length!==0&&(o("updateEntityRecord","changes",x,{changedKeys:st}),b.editRecord(F))}async function ct(w,_){let x=vt(w,_),k=r.get(x);return k?.ydoc?(p(),Bl(k.ydoc)):null}let Pt={applyPersistedCrdtDoc:t(u),updateEntityRecord:t(rt)};return{createPersistedCRDTDoc:t(ct),entityContainsSnapshot:t(C),getAwareness:d,getEntitySnapshot:t(A),load:t(i),loadCollection:t(c),get undoManager(){return s},unload:t(l),unloadAll:t(a),update:t(E)}}var ve=class{diff(t,n,r={}){let s;typeof r=="function"?(s=r,r={}):"callback"in r&&(s=r.callback);let o=this.castInput(t,r),i=this.castInput(n,r),c=this.removeEmpty(this.tokenize(o,r)),l=this.removeEmpty(this.tokenize(i,r));return this.diffWithOptionsObj(c,l,r,s)}diffWithOptionsObj(t,n,r,s){var o;let i=C=>{if(C=this.postProcess(C,r),s){setTimeout(function(){s(C)},0);return}else return C},c=n.length,l=t.length,a=1,d=c+l;r.maxEditLength!=null&&(d=Math.min(d,r.maxEditLength));let u=(o=r.timeout)!==null&&o!==void 0?o:1/0,h=Date.now()+u,f=[{oldPos:-1,lastComponent:void 0}],p=this.extractCommon(f[0],n,t,0,r);if(f[0].oldPos+1>=l&&p+1>=c)return i(this.buildValues(f[0].lastComponent,n,t));let g=-1/0,E=1/0,A=()=>{for(let C=Math.max(g,-a);C<=Math.min(E,a);C+=2){let rt,ct=f[C-1],Pt=f[C+1];ct&&(f[C-1]=void 0);let w=!1;if(Pt){let x=Pt.oldPos-C;w=Pt&&0<=x&&x<c}let _=ct&&ct.oldPos+1<l;if(!w&&!_){f[C]=void 0;continue}if(!_||w&&ct.oldPos<Pt.oldPos?rt=this.addToPath(Pt,!0,!1,0,r):rt=this.addToPath(ct,!1,!0,1,r),p=this.extractCommon(rt,n,t,C,r),rt.oldPos+1>=l&&p+1>=c)return i(this.buildValues(rt.lastComponent,n,t))||!0;f[C]=rt,rt.oldPos+1>=l&&(E=Math.min(E,C-1)),p+1>=c&&(g=Math.max(g,C+1))}a++};if(s)(function C(){setTimeout(function(){if(a>d||Date.now()>h)return s(void 0);A()||C()},0)})();else for(;a<=d&&Date.now()<=h;){let C=A();if(C)return C}}addToPath(t,n,r,s,o){let i=t.lastComponent;return i&&!o.oneChangePerToken&&i.added===n&&i.removed===r?{oldPos:t.oldPos+s,lastComponent:{count:i.count+1,added:n,removed:r,previousComponent:i.previousComponent}}:{oldPos:t.oldPos+s,lastComponent:{count:1,added:n,removed:r,previousComponent:i}}}extractCommon(t,n,r,s,o){let i=n.length,c=r.length,l=t.oldPos,a=l-s,d=0;for(;a+1<i&&l+1<c&&this.equals(r[l+1],n[a+1],o);)a++,l++,d++,o.oneChangePerToken&&(t.lastComponent={count:1,previousComponent:t.lastComponent,added:!1,removed:!1});return d&&!o.oneChangePerToken&&(t.lastComponent={count:d,previousComponent:t.lastComponent,added:!1,removed:!1}),t.oldPos=l,a}equals(t,n,r){return r.comparator?r.comparator(t,n):t===n||!!r.ignoreCase&&t.toLowerCase()===n.toLowerCase()}removeEmpty(t){let n=[];for(let r=0;r<t.length;r++)t[r]&&n.push(t[r]);return n}castInput(t,n){return t}tokenize(t,n){return Array.from(t)}join(t){return t.join("")}postProcess(t,n){return t}get useLongestToken(){return!1}buildValues(t,n,r){let s=[],o;for(;t;)s.push(t),o=t.previousComponent,delete t.previousComponent,t=o;s.reverse();let i=s.length,c=0,l=0,a=0;for(;c<i;c++){let d=s[c];if(d.removed)d.value=this.join(r.slice(a,a+d.count)),a+=d.count;else{if(!d.added&&this.useLongestToken){let u=n.slice(l,l+d.count);u=u.map(function(h,f){let p=r[a+f];return p.length>h.length?p:h}),d.value=this.join(u)}else d.value=this.join(n.slice(l,l+d.count));l+=d.count,d.added||(a+=d.count)}}return s}};var Jo=class extends ve{},jl=new Jo;function us(e,t,n){return jl.diff(e,t,n)}var Ko=class extends ve{constructor(){super(...arguments),this.tokenize=Ah}equals(t,n,r){return r.ignoreWhitespace?((!r.newlineIsToken||!t.includes(` | |
| 7 | +`))&&(t=t.trim()),(!r.newlineIsToken||!n.includes(` | |
| 8 | +`))&&(n=n.trim())):r.ignoreNewlineAtEof&&!r.newlineIsToken&&(t.endsWith(` | |
| 9 | +`)&&(t=t.slice(0,-1)),n.endsWith(` | |
| 10 | +`)&&(n=n.slice(0,-1))),super.equals(t,n,r)}},Fl=new Ko;function Wo(e,t,n){return Fl.diff(e,t,n)}function Ah(e,t){t.stripTrailingCr&&(e=e.replace(/\r\n/g,` | |
| 11 | +`));let n=[],r=e.split(/(\n|\r\n)/);r[r.length-1]||r.pop();for(let s=0;s<r.length;s++){let o=r[s];s%2&&!t.newlineIsToken?n[n.length-1]+=o:n.push(o)}return n}var hs=se(Xo(),1);var zl=se(Xo(),1);function Dh(e){return JSON.parse(JSON.stringify(e))}var Qo;(e=>{function t(o={},i={},c=!1){typeof o!="object"&&(o={}),typeof i!="object"&&(i={});let l=Dh(i);c||(l=Object.keys(l).reduce((a,d)=>((l[d]!==null||l[d]!==void 0)&&(a[d]=l[d]),a),{}));for(let a in o)o[a]!==void 0&&i[a]===void 0&&(l[a]=o[a]);return Object.keys(l).length>0?l:void 0}e.compose=t;function n(o={},i={}){typeof o!="object"&&(o={}),typeof i!="object"&&(i={});let c=Object.keys(o).concat(Object.keys(i)).reduce((l,a)=>((0,zl.default)(o[a],i[a])||(l[a]=i[a]===void 0?null:i[a]),l),{});return Object.keys(c).length>0?c:void 0}e.diff=n;function r(o={},i={}){o=o||{};let c=Object.keys(i).reduce((l,a)=>(i[a]!==o[a]&&o[a]!==void 0&&(l[a]=i[a]),l),{});return Object.keys(o).reduce((l,a)=>(o[a]!==i[a]&&i[a]===void 0&&(l[a]=null),l),c)}e.invert=r;function s(o,i,c=!1){if(typeof o!="object")return i;if(typeof i!="object")return;if(!c)return i;let l=Object.keys(i).reduce((a,d)=>(o[d]===void 0&&(a[d]=i[d]),a),{});return Object.keys(l).length>0?l:void 0}e.transform=s})(Qo||(Qo={}));var Oe=Qo;var Zo;(e=>{function t(n){return typeof n.delete=="number"?n.delete:typeof n.retain=="number"?n.retain:typeof n.retain=="object"&&n.retain!==null?1:typeof n.insert=="string"?n.insert.length:1}e.length=t})(Zo||(Zo={}));var gt=Zo;var Z=class{ops;index;offset;constructor(e){this.ops=e,this.index=0,this.offset=0}hasNext(){return this.peekLength()<1/0}next(e){e||(e=1/0);let t=this.ops[this.index];if(t){let n=this.offset,r=gt.length(t);if(e>=r-n?(e=r-n,this.index+=1,this.offset=0):this.offset+=e,typeof t.delete=="number")return{delete:e};let s={};return t.attributes&&(s.attributes=t.attributes),typeof t.retain=="number"?s.retain=e:typeof t.retain=="object"&&t.retain!==null?s.retain=t.retain:typeof t.insert=="string"?s.insert=t.insert.substr(n,e):s.insert=t.insert,s}return{retain:1/0}}peek(){return this.ops[this.index]}peekLength(){return this.ops[this.index]?gt.length(this.ops[this.index])-this.offset:1/0}peekType(){let e=this.ops[this.index];return e?typeof e.delete=="number"?"delete":typeof e.retain=="number"||typeof e.retain=="object"&&e.retain!==null?"retain":"insert":"retain"}rest(){if(this.hasNext()){if(this.offset===0)return this.ops.slice(this.index)}else return[];let e=this.offset,t=this.index,n=this.next(),r=this.ops.slice(this.index);return this.offset=e,this.index=t,[n].concat(r)}};function Th(e){return JSON.parse(JSON.stringify(e))}var Uh="\0",Ih=1e4;function ti(e){return e.map(t=>({...t,count:t.value.length}))}var ql=(e,t)=>{if(typeof e!="object"||e===null)throw new Error(`cannot retain a ${typeof e}`);if(typeof t!="object"||t===null)throw new Error(`cannot retain a ${typeof t}`);let n=Object.keys(e)[0];if(!n||n!==Object.keys(t)[0])throw new Error(`embed types not matched: ${n} != ${Object.keys(t)[0]}`);return[n,e[n],t[n]]},vh=class nt{static Op=gt;static OpIterator=Z;static AttributeMap=Oe;static handlers={};static registerEmbed(t,n){this.handlers[t]=n}static unregisterEmbed(t){delete this.handlers[t]}static getHandler(t){let n=this.handlers[t];if(!n)throw new Error(`no handlers for embed type "${t}"`);return n}ops;constructor(t){Array.isArray(t)?this.ops=t:t!=null&&Array.isArray(t.ops)?this.ops=t.ops:this.ops=[]}insert(t,n){let r={};return typeof t=="string"&&t.length===0?this:(r.insert=t,n!=null&&typeof n=="object"&&Object.keys(n).length>0&&(r.attributes=n),this.push(r))}delete(t){return t<=0?this:this.push({delete:t})}retain(t,n){if(typeof t=="number"&&t<=0)return this;let r={retain:t};return n!=null&&typeof n=="object"&&Object.keys(n).length>0&&(r.attributes=n),this.push(r)}push(t){let n=this.ops.length,r=this.ops[n-1];if(t=Th(t),typeof r=="object"){if(typeof t.delete=="number"&&typeof r.delete=="number")return this.ops[n-1]={delete:r.delete+t.delete},this;if(typeof r.delete=="number"&&t.insert!==null&&t.insert!==void 0&&(n-=1,r=this.ops[n-1],typeof r!="object"))return this.ops.unshift(t),this;if((0,hs.default)(t.attributes,r.attributes)){if(typeof t.insert=="string"&&typeof r.insert=="string")return this.ops[n-1]={insert:r.insert+t.insert},typeof t.attributes=="object"&&(this.ops[n-1].attributes=t.attributes),this;if(typeof t.retain=="number"&&typeof r.retain=="number")return this.ops[n-1]={retain:r.retain+t.retain},typeof t.attributes=="object"&&(this.ops[n-1].attributes=t.attributes),this}}return n===this.ops.length?this.ops.push(t):this.ops.splice(n,0,t),this}chop(){let t=this.ops[this.ops.length-1];return t&&typeof t.retain=="number"&&!t.attributes&&this.ops.pop(),this}filter(t){return this.ops.filter(t)}forEach(t){this.ops.forEach(t)}map(t){return this.ops.map(t)}partition(t){let n=[],r=[];return this.forEach(s=>{(t(s)?n:r).push(s)}),[n,r]}reduce(t,n){return this.ops.reduce(t,n)}changeLength(){return this.reduce((t,n)=>n.insert?t+gt.length(n):n.delete?t-n.delete:t,0)}length(){return this.reduce((t,n)=>t+gt.length(n),0)}slice(t=0,n=1/0){let r=[],s=new Z(this.ops),o=0;for(;o<n&&s.hasNext();){let i;o<t?i=s.next(t-o):(i=s.next(n-o),r.push(i)),o+=gt.length(i)}return new nt(r)}compose(t){let n=new Z(this.ops),r=new Z(t.ops),s=[],o=r.peek();if(o!=null&&typeof o.retain=="number"&&(o.attributes===null||o.attributes===void 0)){let c=o.retain;for(;n.peekType()==="insert"&&n.peekLength()<=c;)c-=n.peekLength(),s.push(n.next());o.retain-c>0&&r.next(o.retain-c)}let i=new nt(s);for(;n.hasNext()||r.hasNext();)if(r.peekType()==="insert")i.push(r.next());else if(n.peekType()==="delete")i.push(n.next());else{let c=Math.min(n.peekLength(),r.peekLength()),l=n.next(c),a=r.next(c);if(a.retain){let d={};if(typeof l.retain=="number")d.retain=typeof a.retain=="number"?c:a.retain;else if(typeof a.retain=="number")l.retain===null||l.retain===void 0?d.insert=l.insert:d.retain=l.retain;else{let h=l.retain===null||l.retain===void 0?"insert":"retain",[f,p,g]=ql(l[h],a.retain),E=nt.getHandler(f);d[h]={[f]:E.compose(p,g,h==="retain")}}let u=Oe.compose(l.attributes,a.attributes,typeof l.retain=="number");if(u&&(d.attributes=u),i.push(d),!r.hasNext()&&(0,hs.default)(i.ops[i.ops.length-1],d)){let h=new nt(n.rest());return i.concat(h).chop()}}else typeof a.delete=="number"&&(typeof l.retain=="number"||typeof l.retain=="object"&&l.retain!==null)&&i.push(a)}return i.chop()}concat(t){let n=new nt(this.ops.slice());return t.ops.length>0&&(n.push(t.ops[0]),n.ops=n.ops.concat(t.ops.slice(1))),n}diff(t){if(this.ops===t.ops)return new nt;let n=this.deltasToStrings(t),r=ti(us(n[0],n[1])),s=new Z(this.ops),o=new Z(t.ops);return this.convertChangesToDelta(r,s,o).chop()}eachLine(t,n=` | |
| 12 | +`){let r=new Z(this.ops),s=new nt,o=0;for(;r.hasNext();){if(r.peekType()!=="insert")return;let i=r.peek(),c=gt.length(i)-r.peekLength(),l=typeof i.insert=="string"?i.insert.indexOf(n,c)-c:-1;if(l<0)s.push(r.next());else if(l>0)s.push(r.next(l));else{if(t(s,r.next(1).attributes||{},o)===!1)return;o+=1,s=new nt}}s.length()>0&&t(s,{},o)}invert(t){let n=new nt;return this.reduce((r,s)=>{if(s.insert)n.delete(gt.length(s));else{if(typeof s.retain=="number"&&(s.attributes===null||s.attributes===void 0))return n.retain(s.retain),r+s.retain;if(s.delete||typeof s.retain=="number"){let o=s.delete||s.retain;return t.slice(r,r+o).forEach(c=>{s.delete?n.push(c):s.retain&&s.attributes&&n.retain(gt.length(c),Oe.invert(s.attributes,c.attributes))}),r+o}else if(typeof s.retain=="object"&&s.retain!==null){let o=t.slice(r,r+1),i=new Z(o.ops).next(),[c,l,a]=ql(s.retain,i.insert),d=nt.getHandler(c);return n.retain({[c]:d.invert(l,a)},Oe.invert(s.attributes,i.attributes)),r+1}}return r},0),n.chop()}transform(t,n=!1){if(n=!!n,typeof t=="number")return this.transformPosition(t,n);let r=t,s=new Z(this.ops),o=new Z(r.ops),i=new nt;for(;s.hasNext()||o.hasNext();)if(s.peekType()==="insert"&&(n||o.peekType()!=="insert"))i.retain(gt.length(s.next()));else if(o.peekType()==="insert")i.push(o.next());else{let c=Math.min(s.peekLength(),o.peekLength()),l=s.next(c),a=o.next(c);if(l.delete)continue;if(a.delete)i.push(a);else{let d=l.retain,u=a.retain,h=typeof u=="object"&&u!==null?u:c;if(typeof d=="object"&&d!==null&&typeof u=="object"&&u!==null){let f=Object.keys(d)[0];if(f===Object.keys(u)[0]){let p=nt.getHandler(f);p&&(h={[f]:p.transform(d[f],u[f],n)})}}i.retain(h,Oe.transform(l.attributes,a.attributes,n))}}return i.chop()}transformPosition(t,n=!1){n=!!n;let r=new Z(this.ops),s=0;for(;r.hasNext()&&s<=t;){let o=r.peekLength(),i=r.peekType();if(r.next(),i==="delete"){t-=Math.min(o,t-s);continue}else i==="insert"&&(s<t||!n)&&(t+=o);s+=o}return t}diffWithCursor(t,n){if(this.ops===t.ops)return new nt;let r=this.deltasToStrings(t);if(Math.max(...r.map(u=>u.length))>Ih){let u=ti(Wo(r[0],r[1])),h=new Z(this.ops),f=new Z(t.ops);return this.convertChangesToDelta(u,h,f).chop()}else if(n===null)return this.diff(t);let o=ti(us(r[0],r[1])),i=0,c=[];for(let u=0;u<o.length;u++){let h=o[u],f=i,p=i+(h.count??0),g=n>f&&n<=p,E=!h.added&&!h.removed,A=h.removed&&!h.added,C=o[u+1],rt=C&&C.added&&!C.removed;if(E&&g&&rt){let ct=this.tryMoveInsertionToCursor(h,C,n,f);if(ct){c.push(...ct),u++,i=p;continue}}if(A){let ct=this.tryMoveDeletionToCursor(h,c,n,i);if(ct){c.pop(),c.push(...ct),i+=h.count??0;continue}}c.push(h),h.added||(i+=h.count??0)}o=c;let l=new Z(this.ops),a=new Z(t.ops);return this.convertChangesToDelta(o,l,a).chop()}tryMoveInsertionToCursor(t,n,r,s){let o=n.value,i=o.length,c=r-s-i;if(!(t.value.substring(c,c+o.length)===o))return null;let d=t.value.substring(0,c),u=t.value.substring(c),h=[];return d.length>0&&h.push({value:d,count:d.length,added:!1,removed:!1}),h.push(n),u.length>0&&h.push({value:u,count:u.length,added:!1,removed:!1}),h}tryMoveDeletionToCursor(t,n,r,s){let o=n[n.length-1];if(!o||o.added||o.removed)return null;let i=s-(o.count??0),c=s;if(r<i||r>=c)return null;let l=t.value,a=r-i;if(!(o.value.substring(a,a+l.length)===l))return null;let h=o.value.substring(0,a),f=o.value.substring(a),p=t.count??0,g=f.substring(p),E=[];return h.length>0&&E.push({value:h,count:h.length,added:!1,removed:!1}),E.push(t),g.length>0&&E.push({value:g,count:g.length,added:!1,removed:!1}),E}deltasToStrings(t){return[this,t].map(n=>n.map(r=>{if(r.insert!==null||r.insert!==void 0)return typeof r.insert=="string"?r.insert:Uh;let s=n===t?"on":"with";throw new Error("diff() called "+s+" non-document")}).join(""))}convertChangesToDelta(t,n,r){let s=new nt;return t.forEach(o=>{let i=o.count??0;for(;i>0;){let c=0;if(o.added)c=Math.min(r.peekLength(),i),s.push(r.next(c));else if(o.removed)c=Math.min(i,n.peekLength()),n.next(c),s.delete(c);else{c=Math.min(n.peekLength(),r.peekLength(),i);let l=n.next(c),a=r.next(c);(0,hs.default)(l.insert,a.insert)?s.retain(c,Oe.diff(l.attributes,a.attributes)):s.push(a).delete(c)}i-=c}}),s}},Gl=vh;var ei={};sl(ei,{ConnectionErrorCode:Te,createSyncManager:$l,Delta:Gl,CRDT_DOC_META_PERSISTENCE_KEY:ns,CRDT_RECORD_MAP_KEY:rs,LOCAL_EDITOR_ORIGIN:ss,LOCAL_UNDO_IGNORED_ORIGIN:tl,retrySyncConnection:()=>Xn.retryNow()});var Oh="13";return ea(Rh);})(); | |
| 13 | +(window.wp ||= {}).sync = wp.sync; | |
| 14 | +})(); | |
| 10 | 15 | //# sourceMappingURL=index.min.js.map |