PluginProbe
Gutenberg / 22.7.0
Gutenberg v22.7.0
24.0.0 23.9.1 23.9.0 23.8.0 23.7.2 23.7.1 23.7.0 23.6.1 23.6.2 23.6.0 23.5.3 23.5.2 23.5.1 23.5.0 23.4.0 23.3.2 23.3.1 23.3.0 23.2.0 23.2.1 23.2.2 23.1.1 23.1.0 23.0.1 12.6.0 All 403 releases
← All changes | build/scripts/sync/index.min.js +4 -9 23.2.2 → 22.7.0 View file →
@@ -1,10 +1,5 @@
1 -"use strict";var wp;(wp||={}).sync=(()=>{var Rc=Object.create;var _n=Object.defineProperty;var Lc=Object.getOwnPropertyDescriptor;var Nc=Object.getOwnPropertyNames;var Mc=Object.getPrototypeOf,Vc=Object.prototype.hasOwnProperty;var bn=(n,t)=>()=>(t||n((t={exports:{}}).exports,t),t.exports),zs=(n,t)=>{for(var e in t)_n(n,e,{get:t[e],enumerable:!0})},Gs=(n,t,e,r)=>{if(t&&typeof t=="object"||typeof t=="function")for(let s of Nc(t))!Vc.call(n,s)&&s!==e&&_n(n,s,{get:()=>t[s],enumerable:!(r=Lc(t,s))||r.enumerable});return n};var Yt=(n,t,e)=>(e=n!=null?Rc(Mc(n)):{},Gs(t||!n||!n.__esModule?_n(e,"default",{value:n,enumerable:!0}):e,n)),Bc=n=>Gs(_n({},"__esModule",{value:!0}),n);var Yo=bn((Eu,jo)=>{jo.exports=window.wp.privateApis});var rr=bn((Cu,Ko)=>{Ko.exports=window.wp.hooks});var oc=bn((Uu,ic)=>{ic.exports=window.wp.apiFetch});var Vs=bn((fh,Ac)=>{"use strict";Ac.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 Nd={};zs(Nd,{Awareness:()=>Be,Y:()=>Bt,YJS_VERSION:()=>Ld,privateApis:()=>js});var Bt={};zs(Bt,{AbsolutePosition:()=>Pn,AbstractConnector:()=>zr,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:()=>Hr,RelativePosition:()=>Re,Skip:()=>P,Snapshot:()=>ln,Text:()=>Le,Transaction:()=>jn,UndoManager:()=>te,UpdateDecoderV1:()=>X,UpdateDecoderV2:()=>J,UpdateEncoderV1:()=>wt,UpdateEncoderV2:()=>Q,XmlElement:()=>oe,XmlFragment:()=>ie,XmlHook:()=>fn,XmlText:()=>Kn,YArrayEvent:()=>Gn,YEvent:()=>ne,YMapEvent:()=>Hn,YTextEvent:()=>$n,YXmlEvent:()=>Jn,applyUpdate:()=>rs,applyUpdateV2:()=>St,cleanupYTextFormatting:()=>vo,compareIDs:()=>qt,compareRelativePositions:()=>ta,convertUpdateFormatV1ToV2:()=>Ea,convertUpdateFormatV2ToV1:()=>po,createAbsolutePositionFromRelativePosition:()=>Zl,createDeleteSet:()=>Wn,createDeleteSetFromStructStore:()=>ts,createDocFromSnapshot:()=>oa,createID:()=>x,createRelativePositionFromJSON:()=>Hl,createRelativePositionFromTypeIndex:()=>Jl,createSnapshot:()=>as,decodeRelativePosition:()=>Xl,decodeSnapshot:()=>ra,decodeSnapshotV2:()=>to,decodeStateVector:()=>is,decodeUpdate:()=>pa,decodeUpdateV2:()=>co,diffUpdate:()=>ya,diffUpdateV2:()=>ds,emptySnapshot:()=>sa,encodeRelativePosition:()=>ql,encodeSnapshot:()=>na,encodeSnapshotV2:()=>Zi,encodeStateAsUpdate:()=>ss,encodeStateAsUpdateV2:()=>Vt,encodeStateVector:()=>cs,encodeStateVectorFromUpdate:()=>ga,encodeStateVectorFromUpdateV2:()=>ao,equalDeleteSets:()=>qi,equalSnapshots:()=>ea,findIndexSS:()=>et,findRootTypeKey:()=>ls,getItem:()=>Wt,getItemCleanEnd:()=>Kr,getItemCleanStart:()=>z,getState:()=>A,getTypeChildren:()=>Ca,isDeleted:()=>ae,isParentOf:()=>cn,iterateDeletedStructs:()=>Xt,logType:()=>zl,logUpdate:()=>fa,logUpdateV2:()=>oo,mergeDeleteSets:()=>Qt,mergeUpdates:()=>lo,mergeUpdatesV2:()=>ee,obfuscateUpdate:()=>Sa,obfuscateUpdateV2:()=>xa,parseUpdateMeta:()=>ma,parseUpdateMetaV2:()=>uo,readUpdate:()=>Pl,readUpdateV2:()=>ns,relativePositionToJSON:()=>Gl,snapshot:()=>ia,snapshotContainsUpdate:()=>la,transact:()=>k,tryGc:()=>ua,typeListToArraySnapshot:()=>Da,typeMapGetAllSnapshot:()=>Do,typeMapGetSnapshot:()=>Ta});var T=()=>new Map,kn=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},Hs=(n,t)=>{let e=[];for(let[r,s]of n)e.push(t(s,r));return e},$s=(n,t)=>{for(let[e,r]of n)if(t(r,e))return!0;return!1};var dt=()=>new Set;var Cn=n=>n[n.length-1];var Js=(n,t)=>{for(let e=0;e<t.length;e++)n.push(t[e])},it=Array.from;var Ks=(n,t)=>{for(let e=0;e<n.length;e++)if(t(n[e],e,n))return!0;return!1};var qs=(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 Dn=(n,t)=>n<t?n:t,Et=(n,t)=>n>t?n:t,Bd=Number.isNaN;var An=n=>n!==0?n<0:1/n<0;var fr=Number.MAX_SAFE_INTEGER,Pd=Number.MIN_SAFE_INTEGER,Fd=1<<31;var Ws=Number.isInteger||(n=>typeof n=="number"&&isFinite(n)&&W(n)===n),jd=Number.isNaN,Yd=Number.parseInt;var pr=String.fromCharCode,zd=String.fromCodePoint,Gd=pr(65535),Pc=n=>n.toLowerCase(),Fc=/^\s*/g,jc=n=>n.replace(Fc,""),Yc=/([A-Z])/g,gr=(n,t)=>jc(n.replace(Yc,e=>`${t}${Pc(e)}`));var zc=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,Gc=n=>Ee.encode(n),Qs=Ee?Gc:zc;var xe=typeof TextDecoder>"u"?null:new TextDecoder("utf-8",{fatal:!0,ignoreBOM:!0});xe&&xe.decode(new Uint8Array).length===1&&(xe=null);var Zs=(n,t)=>qs(t,()=>n).join("");var Gt=class{constructor(){this.cpos=0,this.cbuf=new Uint8Array(100),this.bufs=[]}},ot=()=>new Gt;var Hc=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(Hc(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},$c=(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=An(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)},mr=new Uint8Array(3e4),Jc=mr.length/3,Kc=(n,t)=>{if(t.length<Jc){let e=Ee.encodeInto(t,mr).written||0;S(n,e);for(let r=0;r<e;r++)M(n,mr[r])}else V(n,Qs(t))},qc=(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?Kc:qc;var si=(n,t)=>De(n,Y(t)),De=(n,t)=>{let e=n.cbuf.length,r=n.cpos,s=Dn(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)},wr=(n,t)=>{$c(n,t);let e=new DataView(n.cbuf.buffer,n.cpos,t);return n.cpos+=t,e},Wc=(n,t)=>wr(n,4).setFloat32(0,t,!1),Xc=(n,t)=>wr(n,8).setFloat64(0,t,!1),Qc=(n,t)=>wr(n,8).setBigInt64(0,t,!1);var ei=new DataView(new ArrayBuffer(4)),Zc=n=>(ei.setFloat32(0,n),ei.getFloat32(0)===n),be=(n,t)=>{switch(typeof t){case"string":M(n,119),At(n,t);break;case"number":Ws(t)&&Se(t)<=2147483647?(M(n,125),Ke(n,t)):Zc(t)?(M(n,124),Wc(n,t)):(M(n,123),Xc(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 ni=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++:(ni(this),this.count=1,this.s=t)}toUint8Array(){return ni(this),Y(this.encoder)}};var ri=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++):(ri(this),this.count=1,this.diff=t-this.s,this.s=t)}toUint8Array(){return ri(this),Y(this.encoder)}},Un=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 oi=ut("Unexpected end of array"),ci=ut("Integer out of Range"),Ae=class{constructor(t){this.arr=t,this.pos=0}},R=n=>new Ae(n),Sr=n=>n.pos!==n.arr.length;var tl=(n,t)=>{let e=new Uint8Array(n.arr.buffer,n.pos+n.arr.byteOffset,t);return n.pos+=t,e},B=n=>tl(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>fr)throw ci}throw oi},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>fr)throw ci}throw oi};var el=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))}},nl=n=>xe.decode(B(n)),Tt=xe?nl:el;var xr=(n,t)=>{let e=new DataView(n.arr.buffer,n.arr.byteOffset+n.pos,t);return n.pos+=t,e},rl=n=>xr(n,4).getFloat32(0,!1),sl=n=>xr(n,8).getFloat64(0,!1),il=n=>xr(n,8).getBigInt64(0,!1);var ol=[n=>{},n=>null,We,rl,sl,il,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=>ol[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),Sr(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=An(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}},Tn=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 Jd=crypto.subtle,li=crypto.getRandomValues.bind(crypto);var _r=()=>li(new Uint32Array(1))[0];var cl="10000000-1000-4000-8000"+-1e11,ai=()=>cl.replace(/[018]/g,n=>(n^_r()&15>>n/4).toString(16));var It=Date.now;var kr=n=>new Promise(n);var Wd=Promise.all.bind(Promise);var Cr=n=>n===void 0?null:n;var Dr=class{constructor(){this.map=new Map}setItem(t,e){this.map.set(t,e)}getItem(t){return this.map.get(t)}},di=new Dr,ul=!0;try{typeof localStorage<"u"&&localStorage&&(di=localStorage,ul=!1)}catch{}var ui=di;var fi=Object.assign,pi=Object.keys,gi=(n,t)=>{for(let e in n)t(n[e],e)};var Ar=n=>pi(n).length,hi=n=>pi(n).length;var mi=n=>{for(let t in n)return!1;return!0},fl=(n,t)=>{for(let e in n)if(!t(n[e],e))return!1;return!0},Ur=(n,t)=>Object.prototype.hasOwnProperty.call(n,t),Tr=(n,t)=>n===t||hi(n)===hi(t)&&fl(n,(e,r)=>(e!==void 0||Ur(t,r))&&t[r]===e),pl=Object.freeze,Ir=n=>{for(let t in n){let e=n[t];(typeof e=="object"||typeof e=="function")&&Ir(n[t])}return pl(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 vr=n=>n,gl=(n,t)=>n===t;var Xe=(n,t)=>{if(n==null||t==null)return gl(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(Ar(n)!==Ar(t))return!1;for(let e in n)if(!Ur(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},yi=(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]",In=typeof window<"u"&&typeof document<"u"&&!Ie,Xd=typeof navigator<"u"?/Mac/.test(navigator.platform):!1,ht,ml=[],wl=()=>{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):ml.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(`--${gr(t,"-")}`,e),ht.set(`-${gr(t,"-")}`,e)}})):ht=T();return ht},Rr=n=>wl().has(n);var Ze=n=>Ie?Cr(process.env[n.toUpperCase().replaceAll("-","_")]):Cr(ui.getItem(n));var Si=n=>Rr("--"+n)||Ze(n)!==null,Qd=Si("production"),yl=Ie&&yi(process.env.FORCE_COLOR,["true","1","2"]),xi=yl||!Rr("--no-colors")&&!Si("no-color")&&(!Ie||process.stdout.isTTY)&&(!Ie||Rr("--color")||Ze("COLORTERM")!==null||(Ze("TERM")||"").includes("color"));var Ei=n=>new Uint8Array(n),Sl=(n,t,e)=>new Uint8Array(n,t,e);var xl=n=>{let t="";for(let e=0;e<n.byteLength;e++)t+=pr(n[e]);return btoa(t)},El=n=>Buffer.from(n.buffer,n.byteOffset,n.byteLength).toString("base64"),_l=n=>{let t=atob(n),e=Ei(t.length);for(let r=0;r<t.length;r++)e[r]=t.charCodeAt(r);return e},bl=n=>{let t=Buffer.from(n,"base64");return Sl(t.buffer,t.byteOffset,t.byteLength)},_i=In?xl:El,bi=In?_l:bl;var ki=n=>{let t=Ei(n.byteLength);return t.set(n),t};var Nr=class{constructor(t,e){this.left=t,this.right=e}},ft=(n,t)=>new Nr(n,t);var Kt=typeof document<"u"?document:{};var Zd=typeof DOMParser<"u"?new DOMParser:null;var Di=n=>Hs(n,(t,e)=>`${e}:${t};`).join("");var tu=Kt.ELEMENT_NODE,eu=Kt.TEXT_NODE,nu=Kt.CDATA_SECTION_NODE,ru=Kt.COMMENT_NODE,su=Kt.DOCUMENT_NODE,iu=Kt.DOCUMENT_TYPE_NODE,ou=Kt.DOCUMENT_FRAGMENT_NODE;var pt=Symbol;var tn=pt(),en=pt(),Mr=pt(),Vr=pt(),Br=pt(),nn=pt(),Pr=pt(),ve=pt(),Fr=pt(),Ai=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 cu=It();var Ul={[tn]:ft("font-weight","bold"),[en]:ft("font-weight","normal"),[Mr]:ft("color","blue"),[Br]:ft("color","green"),[Vr]:ft("color","grey"),[nn]:ft("color","red"),[Pr]:ft("color","purple"),[ve]:ft("color","orange"),[Fr]:ft("color","black")},Tl=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=Ul[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=Di(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},Ui=xi?Tl:Ai,vn=(...n)=>{console.log(...Ui(n)),Ti.forEach(t=>t.print(n))},jr=(...n)=>{console.warn(...Ui(n)),n.unshift(ve),Ti.forEach(t=>t.print(n))};var Ti=dt();var Ii=n=>({[Symbol.iterator](){return this},next:n}),vi=(n,t)=>Ii(()=>{let e;do e=n.next();while(!e.done&&!t(e.value));return e}),On=(n,t)=>Ii(()=>{let{done:e,value:r}=n.next();return{done:e,value:e?void 0:t(r)}});var zr=class extends Dt{constructor(t,e){super(),this.doc=t,this.awareness=e}},sn=class{constructor(t,e){this.clock=t,this.len=e}},Lt=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])no(n,i,a.clock,a.len,e)}}),Ll=(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&&Ll(e,t.clock)!==null},Zr=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 Lt;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++)Js(i,n[o].clients.get(s)||[]);t.clients.set(s,i)}});return Zr(t),t},on=(n,t,e,r)=>{N(n.clients,t,()=>[]).push(new sn(e,r))},Wn=()=>new Lt,ts=n=>{let t=Wn();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 Lt,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},Li=(n,t,e)=>{let r=new Lt,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=A(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,qn(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,qn(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},qi=(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},Wi=_r,mt=class n extends Dt{constructor({guid:t=ai(),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=Wi(),this.guid=t,this.collectionid=e,this.share=new Map,this.store=new Fn,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=kr(a=>{this.on("load",()=>{this.isLoaded=!0,a(this)})});let l=()=>kr(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,Le)}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 ki(B(this.restDecoder))}readJSON(){return JSON.parse(Tt(this.restDecoder))}readKey(){return Tt(this.restDecoder)}},Bn=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 Bn{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 Tn(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 Un,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)}},Nl=(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)},es=(n,t,e)=>{let r=new Map;e.forEach((s,i)=>{A(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])=>{Nl(n,t.clients.get(s),s,i)})},Ml=(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,Lo(n,d));o[a]=h,l+=h.length}}}}return e},Vl=(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 Fn,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,()=>A(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,A(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 es(f,c,new Map),S(f.restEncoder,0),{missing:l,update:f.toUint8Array()}}return null},Bl=(n,t)=>es(n,t.doc.store,t.beforeState),ns=(n,t,e,r=new J(n))=>k(t,s=>{s.local=!1;let i=!1,o=s.doc,c=o.store,l=Ml(r,o),a=Vl(s,c,l),d=c.pendingStructs;if(d){for(let[h,f]of d.missing)if(f<A(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=Li(r,s,c);if(c.pendingDs){let h=new J(R(c.pendingDs));E(h.restDecoder);let f=Li(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),Pl=(n,t,e)=>ns(n,t,e,new X(n)),St=(n,t,e,r=J)=>{let s=R(t);ns(s,n,e,new r(s))},rs=(n,t,e)=>St(n,t,e,X),Fl=(n,t,e=new Map)=>{es(n,t.store,e),gt(n,ts(t.store))},Vt=(n,t=new Uint8Array([0]),e=new Q)=>{let r=is(t);Fl(e,n,r);let s=[e.toUint8Array()];if(n.store.pendingDs&&s.push(n.store.pendingDs),n.store.pendingStructs&&s.push(ds(n.store.pendingStructs.update,t)),s.length>1){if(e.constructor===wt)return lo(s.map((i,o)=>o===0?i:po(i)));if(e.constructor===Q)return ee(s)}return s[0]},ss=(n,t)=>Vt(n,t,new wt),Xi=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},is=n=>Xi(new Zt(R(n))),os=(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),jl=(n,t)=>os(n,gn(t.store)),Yl=(n,t=new Oe)=>(n instanceof Map?os(t,n):jl(t,n),t.toUint8Array()),cs=n=>Yl(n,new Nt),Gr=class{constructor(){this.l=[]}},Ni=()=>new Gr,Mi=(n,t)=>n.l.push(t),Vi=(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.")},Qi=(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),Bi=(n,t)=>{S(n,t.client),S(n,t.clock)},Pi=n=>x(E(n),E(n)),ls=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},zl=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))},Hr=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)||Wn(),bt(new Zt(R(h)))]))})})}),this.dss.set(o,Qt(c.map(d=>bt(new Zt(R(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}},Re=class{constructor(t,e,r,s=0){this.type=t,this.tname=e,this.item=r,this.assoc=s}},Gl=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},Hl=n=>new Re(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),Pn=class{constructor(t,e,r=0){this.type=t,this.index=e,this.assoc=r}},$l=(n,t,e=0)=>new Pn(n,t,e),Rn=(n,t,e)=>{let r=null,s=null;return n._item===null?s=ls(n):r=x(n._item.id.client,n._item.id.clock),new Re(r,s,t,e)},Jl=(n,t,e=0)=>{let r=n._start;if(e<0){if(t===0)return Rn(n,null,e);t--}for(;r!==null;){if(!r.deleted&&r.countable){if(r.length>t)return Rn(n,x(r.id.client,r.id.clock+t),e);t-=r.length}if(r.right===null&&e<0)return Rn(n,r.lastId,e);r=r.right}return Rn(n,null,e)},Kl=(n,t)=>{let{type:e,tname:r,item:s,assoc:i}=t;if(s!==null)S(n,0),Bi(n,s);else if(r!==null)Ce(n,1),At(n,r);else if(e!==null)Ce(n,2),Bi(n,e);else throw $();return Ke(n,i),n},ql=n=>{let t=ot();return Kl(t,n),Y(t)},Wl=n=>{let t=null,e=null,r=null;switch(E(n)){case 0:r=Pi(n);break;case 1:e=Tt(n);break;case 2:t=Pi(n)}let s=Sr(n)?We(n):0;return new Re(t,e,r,s)},Xl=n=>Wl(R(n)),Ql=(n,t)=>{let e=Wt(n,t),r=t.clock-e.id.clock;return{item:e,diff:r}},Zl=(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(A(r,s.client)<=s.clock)return null;let d=e?Xr(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(A(r,i.client)<=i.clock)return null;let{item:d}=e?Xr(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 $l(l,a,n.assoc)},ta=(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}},ea=(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},Zi=(n,t=new Oe)=>(gt(t,n.ds),os(t,n.sv),t.toUint8Array()),na=n=>Zi(n,new Nt),to=(n,t=new Bn(R(n)))=>new ln(bt(t),Xi(t)),ra=n=>to(n,new Zt(R(n))),as=(n,t)=>new ln(n,t),sa=as(Wn(),new Map),ia=n=>as(ts(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),$r=(n,t)=>{let e=N(n.meta,$r,dt),r=n.doc.store;e.has(t)||(t.sv.forEach((s,i)=>{s<A(r,i)&&z(n,x(i,s))}),Xt(n,t.ds,s=>{}),e.add(t))},oa=(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<A(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},ca=(n,t,e=J)=>{let r=new e(R(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 qi(n.ds,i)},la=(n,t)=>ca(n,t,X),Fn=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},A=(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},eo=(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 $()},aa=(n,t)=>{let e=n.clients.get(t.client);return e[et(e,t.clock)]},Wt=aa,Jr=(n,t,e)=>{let r=et(t,e),s=t[r];return s.id.clock<e&&s instanceof C?(t.splice(r+1,0,qn(n,s,e-s.id.clock)),r+1):r},z=(n,t)=>{let e=n.doc.store.clients.get(t.client);return e[Jr(n,e,t.clock)]},Kr=(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,qn(n,i,e.clock-i.id.clock+1)),i},da=(n,t,e)=>{let r=n.clients.get(t.id.client);r[et(r,t.id.clock)]=e},no=(n,t,e,r,s)=>{if(r===0)return;let i=e+r,o=Jr(n,t,e),c;do c=t[o++],i<c.id.clock+c.length&&Jr(n,t,i),s(c);while(o<t.length&&t[o].id.clock<i)},jn=class{constructor(t,e,r){this.doc=t,this.deleteSet=new Lt,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}},Fi=(n,t)=>t.deleteSet.clients.size===0&&!$s(t.afterState,(e,r)=>t.beforeState.get(r)!==e)?!1:(Zr(t.deleteSet),Bl(n,t),gt(n,t.deleteSet),!0),ji=(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)},Mn=(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},ro=(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)}}}},so=(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=Dn(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+Mn(s,l)}})},ua=(n,t,e)=>{ro(n,t,e),so(n,t)},io=(n,t)=>{if(t<n.length){let e=n[t],r=e.doc,s=r.store,i=e.deleteSet,o=e._mergeStructs;try{Zr(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(()=>{Qi(a._dEH,l,e)}))}),c.push(()=>r.emit("afterTransaction",[e,r])),c.push(()=>{e._needFormattingCleanup&&Ra(e)})}),Qe(c,[])}finally{r.gc&&ro(i,s,r.gcFilter),so(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+Mn(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&&Mn(f,p+1)>1||p>0&&Mn(f,p)}if(!e.local&&e.afterState.get(r.clientID)!==e.beforeState.get(r.clientID)&&(vn(ve,tn,"[yjs] ",en,nn,"Changed the client-id because another client seems to be using it."),r.clientID=Wi()),r.emit("afterTransactionCleanup",[e,r]),r._observers.has("update")){let d=new wt;Fi(d,e)&&r.emit("update",[d.toUint8Array(),e.origin,r,e])}if(r._observers.has("updateV2")){let d=new Q;Fi(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])):io(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 jn(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&&io(s,0)}}return o},qr=class{constructor(t,e){this.insertions=e,this.deletions=t,this.meta=new Map}},Yi=(n,t,e)=>{Xt(n,e.deletions,r=>{r instanceof C&&t.scope.some(s=>s===n.doc||cn(s,r))&&gs(r,!1)})},zi=(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}=Xr(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=Ro(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 Lt;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 qr(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))&&gs(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)&&jr("[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=>Yi(r,this,s)),this.undoStack=[]),e&&(this.redoStack.forEach(s=>Yi(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=zi(this,this.undoStack,"undo")}finally{this.undoing=!1}return t}redo(){this.redoing=!0;let t;try{t=zi(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*ha(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,Lo(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=ha(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}},fa=n=>oo(n,X),oo=(n,t=J)=>{let e=[],r=new t(R(n)),s=new yt(r,!1);for(let o=s.curr;o!==null;o=s.next())e.push(o);vn("Structs: ",e);let i=bt(r);vn("DeleteSet: ",i)},pa=n=>co(n,X),co=(n,t=J)=>{let e=[],r=new t(R(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=[]}},lo=n=>ee(n,X,wt),ao=(n,t=Oe,e=J)=>{let r=new t,s=new yt(new e(R(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),si(d,r.restEncoder),r.restEncoder=d,r.toUint8Array()}else return S(r.restEncoder,0),r.toUint8Array()},ga=n=>ao(n,Nt,X),uo=(n,t=J)=>{let e=new Map,r=new Map,s=new yt(new t(R(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}},ma=n=>uo(n,X),wa=(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(R(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=wa(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),us(c);let l=r.map(d=>bt(d)),a=Qt(l);return gt(o,a),o.toUint8Array()},ds=(n,t,e=J,r=Q)=>{let s=is(t),i=new r,o=new an(i),c=new e(R(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()}us(o);let a=bt(c);return gt(i,a),i.toUint8Array()},ya=(n,t)=>ds(n,t,X,wt),ho=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&&ho(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++},us=n=>{ho(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)}},Xn=(n,t,e,r)=>{let s=new e(R(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);us(c);let l=bt(s);return gt(o,l),o.toUint8Array()},fo=({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=Zs(r%10+"",u.str.length);break}default:$()}return a.parentSub&&(a.parentSub=N(s,a.parentSub,()=>r+"")),r++,l}default:$()}}},Sa=(n,t)=>Xn(n,fo(t),X,wt),xa=(n,t)=>Xn(n,fo(t),J,Q),Ea=n=>Xn(n,vr,X,Q),po=n=>Xn(n,vr,J,wt),Gi="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=_a(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(Gi);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=Cn(l.content.getContent());else return;else l!==null&&this.deletes(l)?(o="update",c=Cn(l.content.getContent())):(o="add",c=void 0)}else if(this.deletes(i))o="delete",c=Cn(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(Gi);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}},_a=(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=()=>{jr("Invalid access: Add Yjs type to a document before reading data.")},go=80,hs=0,Wr=class{constructor(t,e){t.marker=!0,this.p=t,this.index=e,this.timestamp=hs++}},ba=n=>{n.timestamp=hs++},mo=(n,t,e)=>{n.p.marker=!1,n.p=t,t.marker=!0,n.index=e,n.timestamp=hs++},ka=(n,t,e)=>{if(n.length>=go){let r=n.reduce((s,i)=>s.timestamp<i.timestamp?s:i);return mo(r,t,e),r}else{let r=new Wr(t,e);return n.push(r),r}},Qn=(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,ba(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/go?(mo(e,r,s),e):ka(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))}},Ca=n=>{n.doc??F();let t=n._start,e=[];for(;t;)e.push(t),t=t.right;return e},Zn=(n,t,e)=>{let r=n,s=t.changedParentTypes;for(;N(s,n,()=>[]).push(e),n._item!==null;)n=n._item.parent;Qi(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=Ni(),this._dEH=Ni(),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){Mi(this._eH,t)}observeDeep(t){Mi(this._dEH,t)}unobserve(t){Vi(this._eH,t)}unobserveDeep(t){Vi(this._dEH,t)}toJSON(){}},wo=(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},yo=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},Da=(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}},So=(n,t)=>{let e=[];return un(n,(r,s)=>{e.push(t(r,s,n))}),e},Aa=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}}}},xo=(n,t)=>{n.doc??F();let e=Qn(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}},Yn=(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,A(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,A(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,A(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,A(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()},Eo=()=>ut("Length exceeded!"),_o=(n,t,e,r)=>{if(e>t._length)throw Eo();if(e===0)return t._searchMarker&&dn(t._searchMarker,e,r.length),Yn(n,t,null,r);let s=e,i=Qn(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),Yn(n,t,o,r)},Ua=(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 Yn(n,t,s,e)},bo=(n,t,e,r)=>{if(r===0)return;let s=e,i=r,o=Qn(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 Eo();t._searchMarker&&dn(t._searchMarker,s,-i+r)},zn=(n,t,e)=>{let r=t._map.get(e);r!==void 0&&r.delete(n)},fs=(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,A(i.store,o)),s,s&&s.lastId,null,null,t,e,c).integrate(n,0)},ps=(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},ko=n=>{let t={};return n.doc??F(),n._map.forEach((e,r)=>{e.deleted||(t[r]=e.content.getContent()[e.length-1])}),t},Co=(n,t)=>{n.doc??F();let e=n._map.get(t);return e!==void 0&&!e.deleted},Ta=(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},Do=(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(),vi(n._map.entries(),t=>!t[1].deleted)),Gn=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),Zn(this,t,new Gn(this,t))}insert(t,e){this.doc!==null?k(this.doc,r=>{_o(r,this,t,e)}):this._prelimContent.splice(t,0,...e)}push(t){this.doc!==null?k(this.doc,e=>{Ua(e,this,t)}):this._prelimContent.push(...t)}unshift(t){this.insert(0,t)}delete(t,e=1){this.doc!==null?k(this.doc,r=>{bo(r,this,t,e)}):this._prelimContent.splice(t,e)}get(t){return xo(this,t)}toArray(){return yo(this)}slice(t=0,e=this.length){return wo(this,t,e)}toJSON(){return this.map(t=>t instanceof v?t.toJSON():t)}map(t){return So(this,t)}forEach(t){un(this,t)}[Symbol.iterator](){return Aa(this)}_write(t){t.writeTypeRef(Wa)}},Ia=n=>new re,Hn=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){Zn(this,t,new Hn(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 On(Ln(this),t=>t[0])}values(){return On(Ln(this),t=>t[1].content.getContent()[t[1].length-1])}entries(){return On(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=>{zn(e,this,t)}):this._prelimContent.delete(t)}set(t,e){return this.doc!==null?k(this.doc,r=>{fs(r,this,t,e)}):this._prelimContent.set(t,e),e}get(t){return ps(this,t)}has(t){return Co(this,t)}clear(){this.doc!==null?k(this.doc,t=>{this.forEach(function(e,r,s){zn(t,s,r)})}):this._prelimContent.clear()}_write(t){t.writeTypeRef(Xa)}},va=n=>new se,Rt=(n,t)=>n===t||typeof n=="object"&&typeof t=="object"&&n&&t&&Tr(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}},Hi=(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},Nn=(n,t,e,r)=>{let s=new Map,i=r?Qn(t,e):null;if(i){let o=new hn(i.p.left,i.p,i.index,s);return Hi(n,o,e-i.index)}else{let o=new hn(null,t._start,0,s);return Hi(n,o,e)}},Ao=(n,t,e,r)=>{for(;e.right!==null&&(e.right.deleted===!0||e.right.content.constructor===O&&Rt(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,A(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)},Uo=(n,t)=>{for(;n.right!==null;){if(!(n.right.deleted||n.right.content.constructor===O&&Rt(t[n.right.content.key]??null,n.right.content.value)))break;n.forward()}},To=(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(!Rt(a,l)){o.set(c,a);let{left:d,right:u}=e;e.right=new C(x(i,A(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},Yr=(n,t,e,r,s)=>{e.currentAttributes.forEach((h,f)=>{s[f]===void 0&&(s[f]=null)});let i=n.doc,o=i.clientID;Uo(e,s);let c=To(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,A(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(),Ao(n,t,e,c)},$i=(n,t,e,r,s)=>{let i=n.doc,o=i.clientID;Uo(e,s);let c=To(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(Rt(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,A(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()}Ao(n,t,e,c)},Io=(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},Oa=(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}},vo=n=>{let t=0;return k(n.doc,e=>{let r=n._start,s=n._start,i=T(),o=kn(i);for(;s;)s.deleted===!1&&(s.content.constructor===O?Ve(o,s.content):(t+=Io(e,r,s,i,o),i=kn(o),r=s)),s=s.right}),t},Ra=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&&no(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):Oa(r,s)});for(let s of t)vo(s)})},Ji=(n,t,e)=>{let r=e,s=kn(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&&Io(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},$n=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},mi(l)||(f.attributes=fi({},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;Rt(g,p)?p!==null&&o.delete(r):(c==="retain"&&h(),Rt(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;Rt(g,p)||(c==="retain"&&h(),l[f]=g)}else if(!o.deleted){i.set(f,p);let g=l[f];g!==void 0&&(Rt(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}},Le=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 $n(this,t,e);Zn(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)&&Yr(r,this,s,c,o.attributes||{})}else o.retain!==void 0?$i(r,this,s,o.retain,o.attributes||{}):o.delete!==void 0&&Ji(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&&$r(u,t),e&&$r(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=Nn(i,this,t,!r);r||(r={},o.currentAttributes.forEach((c,l)=>{r[l]=c})),Yr(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=Nn(i,this,t,!r);Yr(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=>{Ji(s,Nn(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=Nn(i,this,t,!1);o.right!==null&&$i(i,this,o,e,r)}):this._pending.push(()=>this.format(t,e,r))}removeAttribute(t){this.doc!==null?k(this.doc,e=>{zn(e,this,t)}):this._pending.push(()=>this.removeAttribute(t))}setAttribute(t,e){this.doc!==null?k(this.doc,r=>{fs(r,this,t,e)}):this._pending.push(()=>this.setAttribute(t,e))}getAttribute(t){return ps(this,t)}getAttributes(){return ko(this)}_write(t){t.writeTypeRef(Qa)}},La=n=>new Le,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){Zn(this,t,new Jn(this,e,t))}toString(){return So(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=>{_o(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;Yn(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=>{bo(r,this,t,e)}):this._prelimContent.splice(t,e)}toArray(){return yo(this)}push(t){this.insert(this.length,t)}unshift(t){this.insert(0,t)}get(t){return xo(this,t)}slice(t=0,e=this.length){return wo(this,t,e)}forEach(t){un(this,t)}_write(t){t.writeTypeRef(td)}},Na=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 gi(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=>{zn(e,this,t)}):this._prelimAttrs.delete(t)}setAttribute(t,e){this.doc!==null?k(this.doc,r=>{fs(r,this,t,e)}):this._prelimAttrs.set(t,e)}getAttribute(t){return ps(this,t)}hasAttribute(t){return Co(this,t)}getAttributes(t){return t?Do(this,t):ko(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(Za),t.writeKey(this.nodeName)}},Ma=n=>new oe(n.readKey()),Jn=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(ed),t.writeKey(this.hookName)}},Va=n=>new fn(n.readKey()),Kn=class n extends Le{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(nd)}},Ba=n=>new Kn,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()}},Pa=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),eo(t.doc.store,this)}write(t,e){t.writeInfo(Pa),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}},Fa=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}},ja=n=>new Me(n.readLen()),Oo=(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(Oo(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}},Ya=n=>new le(Oo(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}},za=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}},Ga=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}},Ha=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)},$a=Ze("node_env")==="development",Mt=class n{constructor(t){this.arr=t,$a&&Ir(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}},Ja=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}},Ka=n=>new lt(n.readString()),qa=[Ia,va,La,Ma,Na,Va,Ba],Wa=0,Xa=1,Qa=2,Za=3,td=4,ed=5,nd=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}},rd=n=>new nt(qa[n.readTypeRef()](n)),Xr=(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}},gs=(n,t)=>{for(;n!==null&&n.keep!==t;)n.keep=t,n=n.parent._item},qn=(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},Ki=(n,t)=>Ks(n,e=>ae(e.deletions,t)),Ro=(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)||Ro(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)||Ki(i.undoStack,u.right.id)||Ki(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=A(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,gs(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>=A(e,this.origin.client))return this.origin.client;if(this.rightOrigin&&this.rightOrigin.client!==this.id.client&&this.rightOrigin.clock>=A(e,this.rightOrigin.client))return this.rightOrigin.client;if(this.parent&&this.parent.constructor===_t&&this.id.client!==this.parent.client&&this.parent.clock>=A(e,this.parent.client))return this.parent.client;if(this.origin&&(this.left=Kr(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=Kr(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),eo(t.doc.store,this),this.content.integrate(t,this),ji(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),ji(t,e,this.parentSub),this.content.delete(t)}}gc(t,e){if(!this.deleted)throw $();this.content.gc(t),e?da(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=ls(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)}},Lo=(n,t)=>sd[t&31](n),sd=[()=>{$()},ja,Ha,Fa,Ka,za,Ga,rd,Ja,Ya,()=>{$()}],id=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(id),S(t.restEncoder,this.length-e)}getMissing(t,e){return null}},No=typeof globalThis<"u"?globalThis:typeof window<"u"?window:typeof global<"u"?global:{},Mo="__ $YJS$ __";No[Mo]===!0&&console.error("Yjs was already imported. This breaks constructor checks and will lead to issues! - https://github.com/yjs/yjs/issues/438");No[Mo]=!0;var ms=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&&ms/2<=e-this.meta.get(this.clientID).lastUpdated&&this.setLocalState(this.getLocalState());let r=[];this.meta.forEach((s,i)=>{i!==this.clientID&&ms<=e-s.lastUpdated&&this.states.has(i)&&r.push(i)}),r.length>0&&ws(this,r,"timeout")},W(ms/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}},ws=(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 Vo=1,tr="fromPersistence",er="document",Pe="state",de="savedAt",Bo="savedBy",Po="version",nr="gutenberg",ys="syncManager",Fo="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||{}),Ss=class extends Error{constructor(n="unknown-error",t){super(t),this.code=n,this.name="ConnectionError"}};var zo=Yt(Yo(),1),{lock:Go,unlock:_u}=(0,zo.__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 Ho(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 $o(n){return((...t)=>n(...t))}function Jo(n){return function(...t){setTimeout(()=>{n.apply(this,t)},0)}}var wc=Yt(rr(),1);var hc=Yt(rr(),1);var qo=0,Wo=1,od=2,Xo=(n,t)=>{S(n,qo);let e=cs(t);V(n,e)},cd=(n,t,e)=>{S(n,Wo),V(n,ss(t,e))},ld=(n,t,e)=>cd(t,e,B(n)),Qo=(n,t,e,r)=>{try{rs(t,B(n),e)}catch(s){r?.(s),console.error("Caught error while handling a Yjs update",s)}};var ad=Qo,xs=(n,t,e,r,s)=>{let i=E(n);switch(i){case qo:ld(n,t,e);break;case Wo:Qo(n,e,r,s);break;case od:ad(n,e,r,s);break;default:throw new Error("Unknown message type")}return i};var Es=Yt(rr(),1),_s=3,Zo=[2e3,4e3,8e3,12e3],tc=[1e3,2e3,4e3,8e3],ec=3e4,nc=15e3,ud=1*1024*1024,bs=Math.floor(ud/4)*3,mn=50,ks=(0,Es.applyFilters)("sync.pollingManager.pollingInterval",4e3),rc=(0,Es.applyFilters)("sync.pollingManager.pollingIntervalWithCollaborators",1e3),sc=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 Cs=Yt(oc(),1);var cc="/wp-sync/v1/updates";function hd(n){let t="",e=n.byteLength;for(let r=0;r<e;r++)t+=String.fromCharCode(n[r]);return globalThis.btoa(t)}function Ds(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:hd(n),type:t}}function lc(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 ac(n){return(0,Cs.default)({method:"POST",path:cc,data:n})}function As(n){n.rooms.length!==0&&(0,Cs.default)({method:"POST",path:cc,data:n,keepalive:!0}).catch(()=>{})}function dc(n,t){let e=parseInt(String(n),10);return isNaN(e)?t:e}function uc(n,t,e){if(n.length===0)return{window:[],nextOffset:0};let r=(t%n.length+n.length)%n.length;return{window:[...n.slice(r),...n.slice(0,r)].slice(0,Math.max(0,e)),nextOffset:(r+Math.max(0,e))%n.length}}var yn="polling-manager";function fd(n){return n?.data?.status===403}function pd(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 gd(n,t){let e=pd(n,t.map(r=>r.room));if(e){let r=U.get(e);r&&(r.log("Permission denied, unregistering room",{error:n},"error",!0),Sn(e,{sendDisconnectSignal:!1}));for(let s of t){if(s.room===e||!U.has(s.room))continue;let i=U.get(s.room);s.updates.length>0&&i.updateQueue.restore(s.updates)}}else{let r=[...U.keys()];for(let s of r){let i=U.get(s);i&&(i.log("Permission denied, unregistering room",{error:n},"error",!0),Sn(s,{sendDisconnectSignal:!1}))}}}var U=new Map;function md(n){let t=n.filter(e=>[K.COMPACTION,K.UPDATE].includes(e.type)).map(e=>Ds(e.data));return je(ee(t),K.COMPACTION)}function wd(n){let t=ot();return Xo(t,n),je(Y(t),K.SYNC_STEP_1)}function yd(n,t){let e=R(t),r=ot();return xs(e,r,n,yn),je(Y(r),K.SYNC_STEP_2)}function Sd(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&&ws(t,Array.from(i),yn)}function xd(n,t,e){let r=Ds(n.data);switch(n.type){case K.SYNC_STEP_1:return yd(t,r);case K.SYNC_STEP_2:{let s=R(r),i=ot();xs(s,i,t,yn),e();return}case K.COMPACTION:case K.UPDATE:St(t,r,yn)}}function Ed(n,t){if(!t.isPrimaryRoom||Us)return!1;Us=!0;let e=(0,hc.applyFilters)("sync.pollingProvider.maxClientsPerRoom",_s,t.room),r=Object.keys(n).length,s=dc(e,_s);return r>s?(t.log("Connection limit exceeded",{clientCount:r,maxClientsPerRoom:s,room:t.room}),!0):!1}var cr=!1,ue=0,Us=!1,ir=!1,sr=!1,wn=document.visibilityState==="visible",or=!1,Ts=!1,Ct=ks,Pt=null,Is=0;function fc(){Ts=!0}function pc(){let n=Array.from(U.entries()).map(([t,e])=>({after:0,awareness:null,client_id:e.clientId,room:t,updates:[]}));for(let t=0;t<n.length;t+=mn)As({rooms:n.slice(t,t+mn)})}function gc(){let n=wn;wn=document.visibilityState==="visible",wn&&!n&&Pt&&(clearTimeout(Pt),Pt=null,lr())}function _d(){let n=Array.from(U.values());if(n.length<=mn)return n;let t=n.find(o=>o.isPrimaryRoom),e=n.filter(o=>o!==t),r=mn-(t?1:0),{window:s,nextOffset:i}=uc(e,Is,r);return Is=i,t?[t,...s]:s}function lr(){or=!0,Pt=null;async function n(){if(U.size===0){or=!1;return}Ts=!1;let t=_d(),e={rooms:t.map(r=>({after:r.endCursor??0,awareness:r.localAwarenessState,client_id:r.clientId,room:r.room,updates:r.updateQueue.get()}))};t.forEach(r=>{r.onStatusChange({status:"connecting"})});try{let{rooms:r}=await ac(e);ue=0,ir=!1,t.forEach(s=>{U.get(s.room)===s&&s.onStatusChange({status:"connected"})}),sr=!1,r.forEach(s=>{if(!U.has(s.room))return;let i=U.get(s.room);if(i.endCursor=s.end_cursor,Ed(s.awareness,i)){i.onStatusChange({status:"disconnected",error:new Ss(Fe.CONNECTION_LIMIT_EXCEEDED,"Connection limit exceeded")}),Sn(s.room);return}i.processAwarenessUpdate(s.awareness),i.isPrimaryRoom&&Object.keys(s.awareness).length>1&&(sr=!0,U.forEach(c=>{c.updateQueue.resume()}));let o=[];for(let c of s.updates)try{let l=i.processDocUpdate(c);l&&o.push(l)}catch(l){i.log("Failed to apply sync update",{error:l,update:c},"error",!0)}i.updateQueue.addBulk(o),s.should_compact?(i.log("Server requested compaction update"),i.updateQueue.clear(),i.updateQueue.add(i.createCompactionUpdate())):s.compaction_request&&(i.log("Server requested (old) compaction update"),i.updateQueue.add(md(s.compaction_request)))}),wn&&sr?Ct=rc:wn?Ct=ks:Ct=sc}catch(r){if(fd(r)){if(gd(r,e.rooms),U.size===0){or=!1;return}}else{ue++;let s=sr?tc:Zo;ue<=s.length?Ct=s[ue-1]:Ct=ec,ir&&(Ct=nc,ir=!1);for(let i of e.rooms){if(!U.has(i.room))continue;let o=U.get(i.room);i.updates.length>0&&o.endCursor>0?(o.updateQueue.clear(),o.updateQueue.add(o.createCompactionUpdate())):i.updates.length>0&&o.updateQueue.restore(i.updates),o.log("Error posting sync update, will retry with backoff",{error:r,nextPoll:Ct},"error",!0)}if(!Ts){let i=ue>s.length;t.forEach(o=>{U.get(o.room)===o&&o.onStatusChange({status:"disconnected",canManuallyRetry:!0,consecutiveFailures:ue,backgroundRetriesFailed:i,willAutoRetryInMs:Ct})})}}}Pt=setTimeout(lr,Ct)}n()}function bd({room:n,doc:t,awareness:e,log:r,onSync:s,onStatusChange:i}){if(U.has(n))return;let o=lc([wd(t)]),c=U.size===0;function l(){u.localAwarenessState=e.getLocalState()??{}}function a(h,f){if(yn!==f){if(h.byteLength>bs){let p=U.get(n);if(!p)return;p.log("Document size limit exceeded",{maxUpdateSizeInBytes:bs,updateSizeInBytes:h.byteLength}),p.onStatusChange({status:"disconnected",error:new Ss(Fe.DOCUMENT_SIZE_LIMIT_EXCEEDED,"Document size limit exceeded")}),Sn(n);return}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=>Sd(h,e),processDocUpdate:h=>xd(h,t,s),room:n,unregister:d,updateQueue:o};t.on("updateV2",a),e.on("change",l),U.set(n,u),cr||(window.addEventListener("beforeunload",fc),window.addEventListener("pagehide",pc),document.addEventListener("visibilitychange",gc),cr=!0),or||lr()}function Sn(n,{sendDisconnectSignal:t=!0}={}){let e=U.get(n);if(e){if(t){let r=[{after:0,awareness:null,client_id:e.clientId,room:n,updates:[]}];As({rooms:r})}e.unregister(),U.delete(n)}U.size===0&&cr&&(window.removeEventListener("beforeunload",fc),window.removeEventListener("pagehide",pc),document.removeEventListener("visibilitychange",gc),cr=!1,Us=!1,ue=0,Is=0)}function kd(){ir=!0,Pt&&(clearTimeout(Pt),Pt=null,lr())}var xn={registerRoom:bd,retryNow:kd,unregisterRoom:Sn};var Cd=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"),xn.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"),xn.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 mc(){return async({awareness:n,objectType:t,objectId:e,ydoc:r})=>{let s=e?`${t}:${e}`:t,i=new Cd({awareness:n,room:s,ydoc:r});return{destroy:()=>i.destroy(),on:(o,c)=>{i.on(o,c)}}}}var Ye=null;function Dd(){return[mc()]}function Ad(n){return typeof n=="function"}function vs(){if(Ye)return Ye;if(!window._wpCollaborationEnabled)return[];let n=(0,wc.applyFilters)("sync.providers",Dd());return Array.isArray(n)?(Ye=n.filter(Ad),Ye):(Ye=[],Ye)}var yc=(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},Sc=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 yc(this,"undo")}redo(){return yc(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 xc(){let n=new Map,t=new Sc([],{captureTimeout:500,trackedOrigins:new Set([nr])});return t.on("stack-item-added",e=>{let r=n.get(e.ydoc);r&&r.addUndoMeta(e.ydoc,e.stackItem.meta)}),t.on("stack-item-popped",e=>{let r=n.get(e.ydoc);r&&r.restoreUndoMeta(e.ydoc,e.stackItem.meta)}),{addRecord(e,r=!1){},addToScope(e,r){if(e.doc===null)return;let s=e.doc;t.addToScope(e),n.has(s)||s.on("destroy",()=>n.delete(s)),n.set(s,r)},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 ar(n={}){let t=new Map(Object.entries(n));return new mt({meta:t})}function Os(n){n.getMap(Pe).set(Po,Vo)}function Rs(n){let t=n.getMap(Pe);t.set(de,Date.now()),t.set(Bo,n.clientID)}function Ec(){return Math.floor(Math.random()*1e9)}function _c(n){return JSON.stringify({document:_i(Vt(n)),updateId:Ec()})}function bc(n){try{let{document:t}=JSON.parse(n),e={[tr]:!0},r=ar(e),s=bi(t);return St(r,s),r.clientID=Ec(),r}catch{return null}}function Ft(n,t){return`${n}_${t}`}function kc(n=!1){let t=n?Ho:$o,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=vs(),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=ar({objectType:m}),j=I.getMap(er),L=I.getMap(Pe),xt=Date.now(),Z=()=>{i("loadEntity","unloading",D),vc.forEach(me=>me.destroy()),_.onStatusChange(null),j.unobserveDeep(at),L.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(Oc=>{if(Oc===de){let Ys=L.get(de);typeof Ys=="number"&&Ys>xt&&(i("loadEntity","refetching record",D),_.refetchRecord().catch(()=>{}))}})};s||(s=xc());let{addUndoMeta:ze,restoreUndoMeta:ge}=_;s.addToScope(j,{addUndoMeta:ze,restoreUndoMeta:ge});let En={awareness:pe,handlers:_,objectId:w,objectType:m,syncConfig:g,unload:Z,ydoc:I};r.set(D,En),i("loadEntity","connecting",D);let vc=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}));Os(I),p.applyPersistedCrdtDoc(m,w,y),j.observeDeep(at),L.observe(st)}async function c(g,m,w){let y=vs(),_=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=ar({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(L),b.destroy(),e.delete(m)},L=(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(L),Os(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:L}=_,xt=j?.(w),Z=xt?bc(xt):null;if(!Z){i("applyPersistedCrdtDoc","no persisted doc",y),L.transact(()=>{D(L,w),b.persistCRDTDoc()},ys);return}let pe=Vt(Z);St(L,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,En)=>Object.assign(ge,{[En]:w[En]}),{});L.transact(()=>{D(L,ze),b.persistCRDTDoc()},ys)}function u(g,m,w,y,_={}){let{isSave:b=!1,isNewUndoLevel:D=!1}=_,I=Ft(g,m),j=r.get(I),L=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&&Rs(Z)},y)}L&&b&&L.ydoc.transact(()=>{Rs(L.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)),_c(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(Jo(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 L=D.oldPos-y;I=D&&0<=L&&L<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 Ls=class extends he{},Cc=new Ls;function dr(n,t,e){return Cc.diff(n,t,e)}var Ns=class extends he{constructor(){super(...arguments),this.tokenize=Ud}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)}},Dc=new Ns;function Ms(n,t,e){return Dc.diff(n,t,e)}function Ud(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 ur=Yt(Vs(),1);var Uc=Yt(Vs(),1);function Td(n){return JSON.parse(JSON.stringify(n))}var Bs;(n=>{function t(i={},o={},c=!1){typeof i!="object"&&(i={}),typeof o!="object"&&(o={});let l=Td(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,Uc.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})(Bs||(Bs={}));var fe=Bs;var Ps;(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})(Ps||(Ps={}));var rt=Ps;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 Id(n){return JSON.parse(JSON.stringify(n))}var vd="\0",Od=1e4;function Fs(n){return n.map(t=>({...t,count:t.value.length}))}var Tc=(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]]},Rd=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=Id(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,ur.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]=Tc(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,ur.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=Fs(dr(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]=Tc(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))>Od){let u=Fs(Ms(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=Fs(dr(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:vd;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,ur.default)(l.insert,a.insert)?s.retain(c,fe.diff(l.attributes,a.attributes)):s.push(a).delete(c)}o-=c}}),s}},Ic=Rd;var js={};Go(js,{ConnectionErrorCode:Fe,createSyncManager:kc,Delta:Ic,CRDT_DOC_META_PERSISTENCE_KEY:tr,CRDT_RECORD_MAP_KEY:er,LOCAL_EDITOR_ORIGIN:nr,LOCAL_UNDO_IGNORED_ORIGIN:Fo,retrySyncConnection:()=>xn.retryNow()});var Ld="13";return Bc(Nd);})();
1 +"use strict";var wp;(wp||={}).sync=(()=>{var ac=Object.create;var xn=Object.defineProperty;var dc=Object.getOwnPropertyDescriptor;var uc=Object.getOwnPropertyNames;var hc=Object.getPrototypeOf,fc=Object.prototype.hasOwnProperty;var bn=(n,t)=>()=>(t||n((t={exports:{}}).exports,t),t.exports),As=(n,t)=>{for(var e in t)xn(n,e,{get:t[e],enumerable:!0})},vs=(n,t,e,r)=>{if(t&&typeof t=="object"||typeof t=="function")for(let s of uc(t))!fc.call(n,s)&&s!==e&&xn(n,s,{get:()=>t[s],enumerable:!(r=dc(t,s))||r.enumerable});return n};var Pe=(n,t,e)=>(e=n!=null?ac(hc(n)):{},vs(t||!n||!n.__esModule?xn(e,"default",{value:n,enumerable:!0}):e,n)),pc=n=>vs(xn({},"__esModule",{value:!0}),n);var _o=bn(($d,Co)=>{Co.exports=window.wp.privateApis});var Oo=bn((qd,Io)=>{Io.exports=window.wp.hooks});var Bo=bn((Xd,Ro)=>{Ro.exports=window.wp.apiFetch});var Es=bn((Tu,nc)=>{"use strict";nc.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 cd={};As(cd,{Awareness:()=>Le,Y:()=>Rt,YJS_VERSION:()=>od,privateApis:()=>Us});var Rt={};As(Rt,{AbsolutePosition:()=>Rn,AbstractConnector:()=>Br,AbstractStruct:()=>Te,AbstractType:()=>T,Array:()=>te,ContentAny:()=>Nt,ContentBinary:()=>se,ContentDeleted:()=>Ie,ContentDoc:()=>ie,ContentEmbed:()=>Et,ContentFormat:()=>I,ContentJSON:()=>un,ContentString:()=>lt,ContentType:()=>nt,Doc:()=>mt,GC:()=>z,ID:()=>bt,Item:()=>C,Map:()=>ee,PermanentUserData:()=>jr,RelativePosition:()=>Ae,Skip:()=>B,Snapshot:()=>rn,Text:()=>ve,Transaction:()=>Pn,UndoManager:()=>Qt,UpdateDecoderV1:()=>W,UpdateDecoderV2:()=>$,UpdateEncoderV1:()=>wt,UpdateEncoderV2:()=>Q,XmlElement:()=>re,XmlFragment:()=>ne,XmlHook:()=>dn,XmlText:()=>Hn,YArrayEvent:()=>Yn,YEvent:()=>Zt,YMapEvent:()=>zn,YTextEvent:()=>Gn,YXmlEvent:()=>$n,applyUpdate:()=>hn,applyUpdateV2:()=>Vt,cleanupYTextFormatting:()=>go,compareIDs:()=>Jt,compareRelativePositions:()=>Tl,convertUpdateFormatV1ToV2:()=>Xl,convertUpdateFormatV2ToV1:()=>Xi,createAbsolutePositionFromRelativePosition:()=>vl,createDeleteSet:()=>Kn,createDeleteSetFromStructStore:()=>qr,createDocFromSnapshot:()=>Vl,createID:()=>b,createRelativePositionFromJSON:()=>bl,createRelativePositionFromTypeIndex:()=>El,createSnapshot:()=>ns,decodeRelativePosition:()=>Dl,decodeSnapshot:()=>Ml,decodeSnapshotV2:()=>Pi,decodeStateVector:()=>Qr,decodeUpdate:()=>Gl,decodeUpdateV2:()=>Hi,diffUpdate:()=>Kl,diffUpdateV2:()=>rs,emptySnapshot:()=>Ll,encodeRelativePosition:()=>_l,encodeSnapshot:()=>Ol,encodeSnapshotV2:()=>Bi,encodeStateAsUpdate:()=>fn,encodeStateAsUpdateV2:()=>Oe,encodeStateVector:()=>ts,encodeStateVectorFromUpdate:()=>$l,encodeStateVectorFromUpdateV2:()=>Ji,equalDeleteSets:()=>Li,equalSnapshots:()=>Il,findIndexSS:()=>et,findRootTypeKey:()=>es,getItem:()=>Kt,getItemCleanEnd:()=>zr,getItemCleanStart:()=>Y,getState:()=>D,getTypeChildren:()=>ea,isDeleted:()=>oe,isParentOf:()=>nn,iterateDeletedStructs:()=>qt,logType:()=>Sl,logUpdate:()=>zl,logUpdateV2:()=>$i,mergeDeleteSets:()=>Wt,mergeUpdates:()=>qn,mergeUpdatesV2:()=>on,obfuscateUpdate:()=>ql,obfuscateUpdateV2:()=>Wl,parseUpdateMeta:()=>Hl,parseUpdateMetaV2:()=>Ki,readUpdate:()=>gl,readUpdateV2:()=>Xr,relativePositionToJSON:()=>xl,snapshot:()=>Nl,snapshotContainsUpdate:()=>Bl,transact:()=>E,tryGc:()=>Fl,typeListToArraySnapshot:()=>na,typeMapGetAllSnapshot:()=>ao,typeMapGetSnapshot:()=>ia});var A=()=>new Map,kn=n=>{let t=A();return n.forEach((e,r)=>{t.set(r,e)}),t},L=(n,t,e)=>{let r=n.get(t);return r===void 0&&n.set(t,r=e()),r},Ts=(n,t)=>{let e=[];for(let[r,s]of n)e.push(t(s,r));return e},Is=(n,t)=>{for(let[e,r]of n)if(t(r,e))return!0;return!1};var dt=()=>new Set;var En=n=>n[n.length-1];var Os=(n,t)=>{for(let e=0;e<t.length;e++)n.push(t[e])},it=Array.from;var Ms=(n,t)=>{for(let e=0;e<n.length;e++)if(t(n[e],e,n))return!0;return!1};var Ls=(n,t)=>{let e=new Array(n);for(let r=0;r<n;r++)e[r]=t(r,e);return e};var Ft=Array.isArray;var _t=class{constructor(){this._observers=A()}on(t,e){return L(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)||A()).values()).forEach(r=>r(...e))}destroy(){this._observers=A()}},fe=class{constructor(){this._observers=A()}on(t,e){L(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)||A()).values()).forEach(r=>r(...e))}destroy(){this._observers=A()}};var q=Math.floor;var pe=Math.abs;var Cn=(n,t)=>n<t?n:t,xt=(n,t)=>n>t?n:t,dd=Number.isNaN;var _n=n=>n!==0?n<0:1/n<0;var lr=Number.MAX_SAFE_INTEGER,ud=Number.MIN_SAFE_INTEGER,hd=1<<31;var Ns=Number.isInteger||(n=>typeof n=="number"&&isFinite(n)&&q(n)===n),fd=Number.isNaN,pd=Number.parseInt;var ar=String.fromCharCode,gd=String.fromCodePoint,md=ar(65535),gc=n=>n.toLowerCase(),mc=/^\s*/g,wc=n=>n.replace(mc,""),yc=/([A-Z])/g,dr=(n,t)=>wc(n.replace(yc,e=>`${t}${gc(e)}`));var Sc=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},me=typeof TextEncoder<"u"?new TextEncoder:null,xc=n=>me.encode(n),Rs=me?xc:Sc;var ge=typeof TextDecoder>"u"?null:new TextDecoder("utf-8",{fatal:!0,ignoreBOM:!0});ge&&ge.decode(new Uint8Array).length===1&&(ge=null);var Bs=(n,t)=>Ls(t,()=>n).join("");var Yt=class{constructor(){this.cpos=0,this.cbuf=new Uint8Array(100),this.bufs=[]}},ot=()=>new Yt;var bc=n=>{let t=n.cpos;for(let e=0;e<n.bufs.length;e++)t+=n.bufs[e].length;return t};var F=n=>{let t=new Uint8Array(bc(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},kc=(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(xt(e,t)*2),n.cpos=0)},N=(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 xe=N;var S=(n,t)=>{for(;t>127;)N(n,128|127&t),t=q(t/128);N(n,127&t)},Ge=(n,t)=>{let e=_n(t);for(e&&(t=-t),N(n,(t>63?128:0)|(e?64:0)|63&t),t=q(t/64);t>0;)N(n,(t>127?128:0)|127&t),t=q(t/128)},ur=new Uint8Array(3e4),Ec=ur.length/3,Cc=(n,t)=>{if(t.length<Ec){let e=me.encodeInto(t,ur).written||0;S(n,e);for(let r=0;r<e;r++)N(n,ur[r])}else V(n,Rs(t))},_c=(n,t)=>{let e=unescape(encodeURIComponent(t)),r=e.length;S(n,r);for(let s=0;s<r;s++)N(n,e.codePointAt(s))},Ut=me&&me.encodeInto?Cc:_c;var zs=(n,t)=>be(n,F(t)),be=(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(xt(e*2,i)),n.cbuf.set(t.subarray(s)),n.cpos=i)},V=(n,t)=>{S(n,t.byteLength),be(n,t)},hr=(n,t)=>{kc(n,t);let e=new DataView(n.cbuf.buffer,n.cpos,t);return n.cpos+=t,e},Uc=(n,t)=>hr(n,4).setFloat32(0,t,!1),Dc=(n,t)=>hr(n,8).setFloat64(0,t,!1),Ac=(n,t)=>hr(n,8).setBigInt64(0,t,!1);var js=new DataView(new ArrayBuffer(4)),vc=n=>(js.setFloat32(0,n),js.getFloat32(0)===n),ye=(n,t)=>{switch(typeof t){case"string":N(n,119),Ut(n,t);break;case"number":Ns(t)&&pe(t)<=2147483647?(N(n,125),Ge(n,t)):vc(t)?(N(n,124),Uc(n,t)):(N(n,123),Dc(n,t));break;case"bigint":N(n,122),Ac(n,t);break;case"object":if(t===null)N(n,126);else if(Ft(t)){N(n,117),S(n,t.length);for(let e=0;e<t.length;e++)ye(n,t[e])}else if(t instanceof Uint8Array)N(n,116),V(n,t);else{N(n,118);let e=Object.keys(t);S(n,e.length);for(let r=0;r<e.length;r++){let s=e[r];Ut(n,s),ye(n,t[s])}}break;case"boolean":N(n,t?120:121);break;default:N(n,127)}},ze=class extends Yt{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 Fs=n=>{n.count>0&&(Ge(n.encoder,n.count===1?n.s:-n.s),n.count>1&&S(n.encoder,n.count-2))},zt=class{constructor(){this.encoder=new Yt,this.s=0,this.count=0}write(t){this.s===t?this.count++:(Fs(this),this.count=1,this.s=t)}toUint8Array(){return Fs(this),F(this.encoder)}};var Ys=n=>{if(n.count>0){let t=n.diff*2+(n.count===1?0:1);Ge(n.encoder,t),n.count>1&&S(n.encoder,n.count-2)}},Se=class{constructor(){this.encoder=new Yt,this.s=0,this.count=0,this.diff=0}write(t){this.diff===t-this.s?(this.s=t,this.count++):(Ys(this),this.count=1,this.diff=t-this.s,this.s=t)}toUint8Array(){return Ys(this),F(this.encoder)}},Un=class{constructor(){this.sarr=[],this.s="",this.lensE=new zt}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 Yt;return this.sarr.push(this.s),this.s="",Ut(t,this.sarr.join("")),be(t,this.lensE.toUint8Array()),F(t)}};var ut=n=>new Error(n),ct=()=>{throw ut("Method unimplemented")},G=()=>{throw ut("Unexpected case")};var $s=ut("Unexpected end of array"),Hs=ut("Integer out of Range"),ke=class{constructor(t){this.arr=t,this.pos=0}},O=n=>new ke(n),pr=n=>n.pos!==n.arr.length;var Tc=(n,t)=>{let e=new Uint8Array(n.arr.buffer,n.pos+n.arr.byteOffset,t);return n.pos+=t,e},R=n=>Tc(n,k(n));var Gt=n=>n.arr[n.pos++];var k=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>lr)throw Hs}throw $s},He=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>lr)throw Hs}throw $s};var Ic=n=>{let t=k(n);if(t===0)return"";{let e=String.fromCodePoint(Gt(n));if(--t<100)for(;t--;)e+=String.fromCodePoint(Gt(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))}},Oc=n=>ge.decode(R(n)),At=ge?Oc:Ic;var gr=(n,t)=>{let e=new DataView(n.arr.buffer,n.arr.byteOffset+n.pos,t);return n.pos+=t,e},Mc=n=>gr(n,4).getFloat32(0,!1),Lc=n=>gr(n,8).getFloat64(0,!1),Nc=n=>gr(n,8).getBigInt64(0,!1);var Vc=[n=>{},n=>null,He,Mc,Lc,Nc,n=>!1,n=>!0,At,n=>{let t=k(n),e={};for(let r=0;r<t;r++){let s=At(n);e[s]=Ee(n)}return e},n=>{let t=k(n),e=[];for(let r=0;r<t;r++)e.push(Ee(n));return e},R],Ee=n=>Vc[127-Gt(n)](n),$e=class extends ke{constructor(t,e){super(t),this.reader=e,this.s=null,this.count=0}read(){return this.count===0&&(this.s=this.reader(this),pr(this)?this.count=k(this)+1:this.count=-1),this.count--,this.s}};var $t=class extends ke{constructor(t){super(t),this.s=0,this.count=0}read(){if(this.count===0){this.s=He(this);let t=_n(this.s);this.count=1,t&&(this.s=-this.s,this.count=k(this)+2)}return this.count--,this.s}};var Ce=class extends ke{constructor(t){super(t),this.s=0,this.count=0,this.diff=0}read(){if(this.count===0){let t=He(this),e=t&1;this.diff=q(t/2),this.count=1,e&&(this.count=k(this)+2)}return this.s+=this.diff,this.count--,this.s}},Dn=class{constructor(t){this.decoder=new $t(t),this.str=At(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 Sd=crypto.subtle,Js=crypto.getRandomValues.bind(crypto);var wr=()=>Js(new Uint32Array(1))[0];var Rc="10000000-1000-4000-8000"+-1e11,Ks=()=>Rc.replace(/[018]/g,n=>(n^wr()&15>>n/4).toString(16));var vt=Date.now;var Sr=n=>new Promise(n);var kd=Promise.all.bind(Promise);var xr=n=>n===void 0?null:n;var br=class{constructor(){this.map=new Map}setItem(t,e){this.map.set(t,e)}getItem(t){return this.map.get(t)}},qs=new br,Fc=!0;try{typeof localStorage<"u"&&localStorage&&(qs=localStorage,Fc=!1)}catch{}var Ws=qs;var Qs=Object.assign,Zs=Object.keys,ti=(n,t)=>{for(let e in n)t(n[e],e)};var kr=n=>Zs(n).length,Xs=n=>Zs(n).length;var ei=n=>{for(let t in n)return!1;return!0},zc=(n,t)=>{for(let e in n)if(!t(n[e],e))return!1;return!0},Er=(n,t)=>Object.prototype.hasOwnProperty.call(n,t),Cr=(n,t)=>n===t||Xs(n)===Xs(t)&&zc(n,(e,r)=>(e!==void 0||Er(t,r))&&t[r]===e),Gc=Object.freeze,_r=n=>{for(let t in n){let e=n[t];(typeof e=="object"||typeof e=="function")&&_r(n[t])}return Gc(n)};var Ke=(n,t,e=0)=>{try{for(;e<n.length;e++)n[e](...t)}finally{e<n.length&&Ke(n,t,e+1)}};var Ur=n=>n,$c=(n,t)=>n===t;var Je=(n,t)=>{if(n==null||t==null)return $c(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)||!Je(n.get(e),t.get(e)))return!1;break}case Object:if(kr(n)!==kr(t))return!1;for(let e in n)if(!Er(n,e)||!Je(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(!Je(n[e],t[e]))return!1;break;default:return!1}return!0},ri=(n,t)=>t.includes(n);var _e=typeof process<"u"&&process.release&&/node|io\.js/.test(process.release.name)&&Object.prototype.toString.call(typeof process<"u"?process:0)==="[object process]",An=typeof window<"u"&&typeof document<"u"&&!_e,Ed=typeof navigator<"u"?/Mac/.test(navigator.platform):!1,ht,Hc=[],Jc=()=>{if(ht===void 0)if(_e){ht=A();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):Hc.push(r)}t!==null&&ht.set(t,"")}else typeof location=="object"?(ht=A(),(location.search||"?").slice(1).split("&").forEach(n=>{if(n.length!==0){let[t,e]=n.split("=");ht.set(`--${dr(t,"-")}`,e),ht.set(`-${dr(t,"-")}`,e)}})):ht=A();return ht},Ar=n=>Jc().has(n);var qe=n=>_e?xr(process.env[n.toUpperCase().replaceAll("-","_")]):xr(Ws.getItem(n));var si=n=>Ar("--"+n)||qe(n)!==null,Cd=si("production"),Kc=_e&&ri(process.env.FORCE_COLOR,["true","1","2"]),ii=Kc||!Ar("--no-colors")&&!si("no-color")&&(!_e||process.stdout.isTTY)&&(!_e||Ar("--color")||qe("COLORTERM")!==null||(qe("TERM")||"").includes("color"));var oi=n=>new Uint8Array(n),qc=(n,t,e)=>new Uint8Array(n,t,e);var Wc=n=>{let t="";for(let e=0;e<n.byteLength;e++)t+=ar(n[e]);return btoa(t)},Xc=n=>Buffer.from(n.buffer,n.byteOffset,n.byteLength).toString("base64"),Qc=n=>{let t=atob(n),e=oi(t.length);for(let r=0;r<t.length;r++)e[r]=t.charCodeAt(r);return e},Zc=n=>{let t=Buffer.from(n,"base64");return qc(t.buffer,t.byteOffset,t.byteLength)},ci=An?Wc:Xc,li=An?Qc:Zc;var ai=n=>{let t=oi(n.byteLength);return t.set(n),t};var Tr=class{constructor(t,e){this.left=t,this.right=e}},ft=(n,t)=>new Tr(n,t);var Ht=typeof document<"u"?document:{};var _d=typeof DOMParser<"u"?new DOMParser:null;var ui=n=>Ts(n,(t,e)=>`${e}:${t};`).join("");var Ud=Ht.ELEMENT_NODE,Dd=Ht.TEXT_NODE,Ad=Ht.CDATA_SECTION_NODE,vd=Ht.COMMENT_NODE,Td=Ht.DOCUMENT_NODE,Id=Ht.DOCUMENT_TYPE_NODE,Od=Ht.DOCUMENT_FRAGMENT_NODE;var pt=Symbol;var We=pt(),Xe=pt(),Ir=pt(),Or=pt(),Mr=pt(),Qe=pt(),Lr=pt(),Ue=pt(),Nr=pt(),hi=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 Md=vt();var sl={[We]:ft("font-weight","bold"),[Xe]:ft("font-weight","normal"),[Ir]:ft("color","blue"),[Mr]:ft("color","green"),[Or]:ft("color","grey"),[Qe]:ft("color","red"),[Lr]:ft("color","purple"),[Ue]:ft("color","orange"),[Nr]:ft("color","black")},il=n=>{n.length===1&&n[0]?.constructor===Function&&(n=n[0]());let t=[],e=[],r=A(),s=[],i=0;for(;i<n.length;i++){let o=n[i],c=sl[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=ui(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},fi=ii?il:hi,vn=(...n)=>{console.log(...fi(n)),pi.forEach(t=>t.print(n))},Vr=(...n)=>{console.warn(...fi(n)),n.unshift(Ue),pi.forEach(t=>t.print(n))};var pi=dt();var gi=n=>({[Symbol.iterator](){return this},next:n}),mi=(n,t)=>gi(()=>{let e;do e=n.next();while(!e.done&&!t(e.value));return e}),Tn=(n,t)=>gi(()=>{let{done:e,value:r}=n.next();return{done:e,value:e?void 0:t(r)}});var Br=class extends _t{constructor(t,e){super(),this.doc=t,this.awareness=e}},tn=class{constructor(t,e){this.clock=t,this.len=e}},Mt=class{constructor(){this.clients=new Map}},qt=(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])Fi(n,i,a.clock,a.len,e)}}),dl=(n,t)=>{let e=0,r=n.length-1;for(;e<=r;){let s=q((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},oe=(n,t)=>{let e=n.clients.get(t.client);return e!==void 0&&dl(e,t.clock)!==null},Kr=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=xt(s.len,i.clock+i.len-s.clock):(r<e&&(t[r]=i),r++)}t.length=r})},Wt=n=>{let t=new Mt;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++)Os(i,n[o].clients.get(s)||[]);t.clients.set(s,i)}});return Kr(t),t},en=(n,t,e,r)=>{L(n.clients,t,()=>[]).push(new tn(e,r))},Kn=()=>new Mt,qr=n=>{let t=Kn();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 tn(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)}})},kt=n=>{let t=new Mt,e=k(n.restDecoder);for(let r=0;r<e;r++){n.resetDsCurVal();let s=k(n.restDecoder),i=k(n.restDecoder);if(i>0){let o=L(t.clients,s,()=>[]);for(let c=0;c<i;c++)o.push(new tn(n.readDsClock(),n.readDsLen()))}}return t},Si=(n,t,e)=>{let r=new Mt,s=k(n.restDecoder);for(let i=0;i<s;i++){n.resetDsCurVal();let o=k(n.restDecoder),c=k(n.restDecoder),l=e.clients.get(o)||[],a=D(e,o);for(let d=0;d<c;d++){let u=n.readDsClock(),h=u+n.readDsLen();if(u<a){a<h&&en(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,Jn(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,Jn(t,p,h-p.id.clock)),p.delete(t))}else en(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},Li=(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},Ni=wr,mt=class n extends _t{constructor({guid:t=Ks(),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=Ni(),this.guid=t,this.collectionid=e,this.share=new Map,this.store=new Bn,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=Sr(a=>{this.on("load",()=>{this.isLoaded=!0,a(this)})});let l=()=>Sr(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&&E(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 E(this,t,e)}get(t,e=T){let r=L(this.share,t,()=>{let i=new e;return i._integrate(this,null),i}),s=r.constructor;if(e!==T&&s!==e)if(s===T){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,te)}getText(t=""){return this.get(t,ve)}getMap(t=""){return this.get(t,ee)}getXmlElement(t=""){return this.get(t,re)}getXmlFragment(t=""){return this.get(t,ne)}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,E(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()}},Xt=class{constructor(t){this.restDecoder=t}resetDsCurVal(){}readDsClock(){return k(this.restDecoder)}readDsLen(){return k(this.restDecoder)}},W=class extends Xt{readLeftID(){return b(k(this.restDecoder),k(this.restDecoder))}readRightID(){return b(k(this.restDecoder),k(this.restDecoder))}readClient(){return k(this.restDecoder)}readInfo(){return Gt(this.restDecoder)}readString(){return At(this.restDecoder)}readParentInfo(){return k(this.restDecoder)===1}readTypeRef(){return k(this.restDecoder)}readLen(){return k(this.restDecoder)}readAny(){return Ee(this.restDecoder)}readBuf(){return ai(R(this.restDecoder))}readJSON(){return JSON.parse(At(this.restDecoder))}readKey(){return At(this.restDecoder)}},Vn=class{constructor(t){this.dsCurrVal=0,this.restDecoder=t}resetDsCurVal(){this.dsCurrVal=0}readDsClock(){return this.dsCurrVal+=k(this.restDecoder),this.dsCurrVal}readDsLen(){let t=k(this.restDecoder)+1;return this.dsCurrVal+=t,t}},$=class extends Vn{constructor(t){super(t),this.keys=[],k(t),this.keyClockDecoder=new Ce(R(t)),this.clientDecoder=new $t(R(t)),this.leftClockDecoder=new Ce(R(t)),this.rightClockDecoder=new Ce(R(t)),this.infoDecoder=new $e(R(t),Gt),this.stringDecoder=new Dn(R(t)),this.parentInfoDecoder=new $e(R(t),Gt),this.typeRefDecoder=new $t(R(t)),this.lenDecoder=new $t(R(t))}readLeftID(){return new bt(this.clientDecoder.read(),this.leftClockDecoder.read())}readRightID(){return new bt(this.clientDecoder.read(),this.rightClockDecoder.read())}readClient(){return this.clientDecoder.read()}readInfo(){return this.infoDecoder.read()}readString(){return this.stringDecoder.read()}readParentInfo(){return this.parentInfoDecoder.read()===1}readTypeRef(){return this.typeRefDecoder.read()}readLen(){return this.lenDecoder.read()}readAny(){return Ee(this.restDecoder)}readBuf(){return R(this.restDecoder)}readJSON(){return Ee(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}}},Lt=class{constructor(){this.restEncoder=ot()}toUint8Array(){return F(this.restEncoder)}resetDsCurVal(){}writeDsClock(t){S(this.restEncoder,t)}writeDsLen(t){S(this.restEncoder,t)}},wt=class extends Lt{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){xe(this.restEncoder,t)}writeString(t){Ut(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){ye(this.restEncoder,t)}writeBuf(t){V(this.restEncoder,t)}writeJSON(t){Ut(this.restEncoder,JSON.stringify(t))}writeKey(t){Ut(this.restEncoder,t)}},De=class{constructor(){this.restEncoder=ot(),this.dsCurrVal=0}toUint8Array(){return F(this.restEncoder)}resetDsCurVal(){this.dsCurrVal=0}writeDsClock(t){let e=t-this.dsCurrVal;this.dsCurrVal=t,S(this.restEncoder,e)}writeDsLen(t){t===0&&G(),S(this.restEncoder,t-1),this.dsCurrVal+=t}},Q=class extends De{constructor(){super(),this.keyMap=new Map,this.keyClock=0,this.keyClockEncoder=new Se,this.clientEncoder=new zt,this.leftClockEncoder=new Se,this.rightClockEncoder=new Se,this.infoEncoder=new ze(xe),this.stringEncoder=new Un,this.parentInfoEncoder=new ze(xe),this.typeRefEncoder=new zt,this.lenEncoder=new zt}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,F(this.infoEncoder)),V(t,this.stringEncoder.toUint8Array()),V(t,F(this.parentInfoEncoder)),V(t,this.typeRefEncoder.toUint8Array()),V(t,this.lenEncoder.toUint8Array()),be(t,F(this.restEncoder)),F(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){V(this.restEncoder,t)}writeJSON(t){ye(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)}},ul=(n,t,e,r)=>{r=xt(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)},Wr=(n,t,e)=>{let r=new Map;e.forEach((s,i)=>{D(t,i)>s&&r.set(i,s)}),pn(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])=>{ul(n,t.clients.get(s),s,i)})},hl=(n,t)=>{let e=A(),r=k(n.restDecoder);for(let s=0;s<r;s++){let i=k(n.restDecoder),o=new Array(i),c=n.readClient(),l=k(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 z(b(c,l),u),l+=u;break}case 10:{let u=k(n.restDecoder);o[a]=new B(b(c,l),u),l+=u;break}default:{let u=(d&192)===0,h=new C(b(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,yo(n,d));o[a]=h,l+=h.length}}}}return e},fl=(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 Bn,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!==B){let p=L(u,d.id.client,()=>D(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,D(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 Wr(f,c,new Map),S(f.restEncoder,0),{missing:l,update:f.toUint8Array()}}return null},pl=(n,t)=>Wr(n,t.doc.store,t.beforeState),Xr=(n,t,e,r=new $(n))=>E(t,s=>{s.local=!1;let i=!1,o=s.doc,c=o.store,l=hl(r,o),a=fl(s,c,l),d=c.pendingStructs;if(d){for(let[h,f]of d.missing)if(f<D(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=on([d.update,a.update])}}else c.pendingStructs=a;let u=Si(r,s,c);if(c.pendingDs){let h=new $(O(c.pendingDs));k(h.restDecoder);let f=Si(h,s,c);u&&f?c.pendingDs=on([u,f]):c.pendingDs=u||f}else c.pendingDs=u;if(i){let h=c.pendingStructs.update;c.pendingStructs=null,Vt(s.doc,h)}},e,!1),gl=(n,t,e)=>Xr(n,t,e,new W(n)),Vt=(n,t,e,r=$)=>{let s=O(t);Xr(s,n,e,new r(s))},hn=(n,t,e)=>Vt(n,t,e,W),ml=(n,t,e=new Map)=>{Wr(n,t.store,e),gt(n,qr(t.store))},Oe=(n,t=new Uint8Array([0]),e=new Q)=>{let r=Qr(t);ml(e,n,r);let s=[e.toUint8Array()];if(n.store.pendingDs&&s.push(n.store.pendingDs),n.store.pendingStructs&&s.push(rs(n.store.pendingStructs.update,t)),s.length>1){if(e.constructor===wt)return qn(s.map((i,o)=>o===0?i:Xi(i)));if(e.constructor===Q)return on(s)}return s[0]},fn=(n,t)=>Oe(n,t,new wt),Vi=n=>{let t=new Map,e=k(n.restDecoder);for(let r=0;r<e;r++){let s=k(n.restDecoder),i=k(n.restDecoder);t.set(s,i)}return t},Qr=n=>Vi(new Xt(O(n))),Zr=(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),wl=(n,t)=>Zr(n,pn(t.store)),yl=(n,t=new De)=>(n instanceof Map?Zr(t,n):wl(t,n),t.toUint8Array()),ts=n=>yl(n,new Lt),Pr=class{constructor(){this.l=[]}},xi=()=>new Pr,bi=(n,t)=>n.l.push(t),ki=(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.")},Ri=(n,t,e)=>Ke(n.l,[t,e]),bt=class{constructor(t,e){this.client=t,this.clock=e}},Jt=(n,t)=>n===t||n!==null&&t!==null&&n.client===t.client&&n.clock===t.clock,b=(n,t)=>new bt(n,t),Ei=(n,t)=>{S(n,t.client),S(n,t.clock)},Ci=n=>b(k(n),k(n)),es=n=>{for(let[t,e]of n.doc.share.entries())if(e===n)return t;throw G()},nn=(n,t)=>{for(;t!==null;){if(t.parent===n)return!0;t=t.parent._item}return!1},Sl=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))},jr=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,Wt([this.dss.get(o)||Kn(),kt(new Xt(O(h)))]))})})}),this.dss.set(o,Wt(c.map(d=>kt(new Xt(O(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 ee,o.set("ids",new te),o.set("ds",new te),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 Lt,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 Lt;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(oe(r,t))return e;return null}},Ae=class{constructor(t,e,r,s=0){this.type=t,this.tname=e,this.item=r,this.assoc=s}},xl=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},bl=n=>new Ae(n.type==null?null:b(n.type.client,n.type.clock),n.tname??null,n.item==null?null:b(n.item.client,n.item.clock),n.assoc==null?0:n.assoc),Rn=class{constructor(t,e,r=0){this.type=t,this.index=e,this.assoc=r}},kl=(n,t,e=0)=>new Rn(n,t,e),In=(n,t,e)=>{let r=null,s=null;return n._item===null?s=es(n):r=b(n._item.id.client,n._item.id.clock),new Ae(r,s,t,e)},El=(n,t,e=0)=>{let r=n._start;if(e<0){if(t===0)return In(n,null,e);t--}for(;r!==null;){if(!r.deleted&&r.countable){if(r.length>t)return In(n,b(r.id.client,r.id.clock+t),e);t-=r.length}if(r.right===null&&e<0)return In(n,r.lastId,e);r=r.right}return In(n,null,e)},Cl=(n,t)=>{let{type:e,tname:r,item:s,assoc:i}=t;if(s!==null)S(n,0),Ei(n,s);else if(r!==null)xe(n,1),Ut(n,r);else if(e!==null)xe(n,2),Ei(n,e);else throw G();return Ge(n,i),n},_l=n=>{let t=ot();return Cl(t,n),F(t)},Ul=n=>{let t=null,e=null,r=null;switch(k(n)){case 0:r=Ci(n);break;case 1:e=At(n);break;case 2:t=Ci(n)}let s=pr(n)?He(n):0;return new Ae(t,e,r,s)},Dl=n=>Ul(O(n)),Al=(n,t)=>{let e=Kt(n,t),r=t.clock-e.id.clock;return{item:e,diff:r}},vl=(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(D(r,s.client)<=s.clock)return null;let d=e?Hr(r,s):Al(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(D(r,i.client)<=i.clock)return null;let{item:d}=e?Hr(r,i):{item:Kt(r,i)};if(d instanceof C&&d.content instanceof nt)l=d.content.type;else return null}else throw G();c>=0?a=l._length:a=0}return kl(l,a,n.assoc)},Tl=(n,t)=>n===t||n!==null&&t!==null&&n.tname===t.tname&&Jt(n.item,t.item)&&Jt(n.type,t.type)&&n.assoc===t.assoc,rn=class{constructor(t,e){this.ds=t,this.sv=e}},Il=(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},Bi=(n,t=new De)=>(gt(t,n.ds),Zr(t,n.sv),t.toUint8Array()),Ol=n=>Bi(n,new Lt),Pi=(n,t=new Vn(O(n)))=>new rn(kt(t),Vi(t)),Ml=n=>Pi(n,new Xt(O(n))),ns=(n,t)=>new rn(n,t),Ll=ns(Kn(),new Map),Nl=n=>ns(qr(n.store),pn(n.store)),Tt=(n,t)=>t===void 0?!n.deleted:t.sv.has(n.id.client)&&(t.sv.get(n.id.client)||0)>n.id.clock&&!oe(t.ds,n.id),Fr=(n,t)=>{let e=L(n.meta,Fr,dt),r=n.doc.store;e.has(t)||(t.sv.forEach((s,i)=>{s<D(r,i)&&Y(n,b(i,s))}),qt(n,t.ds,s=>{}),e.add(t))},Vl=(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<D(n.store,l)&&Y(o,b(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)}),Vt(e,i.toUint8Array(),"snapshot"),e},Rl=(n,t,e=$)=>{let r=new e(O(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=Wt([n.ds,kt(r)]);return Li(n.ds,i)},Bl=(n,t)=>Rl(n,t,W),Bn=class{constructor(){this.clients=new Map,this.pendingStructs=null,this.pendingDs=null}},pn=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},D=(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},ji=(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 G()}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=q(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=q((e+r)/2)}throw G()},Pl=(n,t)=>{let e=n.clients.get(t.client);return e[et(e,t.clock)]},Kt=Pl,Yr=(n,t,e)=>{let r=et(t,e),s=t[r];return s.id.clock<e&&s instanceof C?(t.splice(r+1,0,Jn(n,s,e-s.id.clock)),r+1):r},Y=(n,t)=>{let e=n.doc.store.clients.get(t.client);return e[Yr(n,e,t.clock)]},zr=(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!==z&&r.splice(s+1,0,Jn(n,i,e.clock-i.id.clock+1)),i},jl=(n,t,e)=>{let r=n.clients.get(t.id.client);r[et(r,t.id.clock)]=e},Fi=(n,t,e,r,s)=>{if(r===0)return;let i=e+r,o=Yr(n,t,e),c;do c=t[o++],i<c.id.clock+c.length&&Yr(n,t,i),s(c);while(o<t.length&&t[o].id.clock<i)},Pn=class{constructor(t,e,r){this.doc=t,this.deleteSet=new Mt,this.beforeState=pn(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}},_i=(n,t)=>t.deleteSet.clients.size===0&&!Is(t.afterState,(e,r)=>t.beforeState.get(r)!==e)?!1:(Kr(t.deleteSet),pl(n,t),gt(n,t.deleteSet),!0),Ui=(n,t,e)=>{let r=t._item;(r===null||r.id.clock<(n.beforeState.get(r.id.client)||0)&&!r.deleted)&&L(n.changed,t,dt).add(e)},Ln=(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},Yi=(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)}}}},zi=(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+Ln(s,l)}})},Fl=(n,t,e)=>{Yi(n,t,e),zi(n,t)},Gi=(n,t)=>{if(t<n.length){let e=n[t],r=e.doc,s=r.store,i=e.deleteSet,o=e._mergeStructs;try{Kr(i),e.afterState=pn(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(()=>{Ri(a._dEH,l,e)}))}),c.push(()=>r.emit("afterTransaction",[e,r])),c.push(()=>{e._needFormattingCleanup&&aa(e)})}),Ke(c,[])}finally{r.gc&&Yi(i,s,r.gcFilter),zi(i,s),e.afterState.forEach((d,u)=>{let h=e.beforeState.get(u)||0;if(h!==d){let f=s.clients.get(u),p=xt(et(f,h),1);for(let g=f.length-1;g>=p;)g-=1+Ln(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&&Ln(f,p+1)>1||p>0&&Ln(f,p)}if(!e.local&&e.afterState.get(r.clientID)!==e.beforeState.get(r.clientID)&&(vn(Ue,We,"[yjs] ",Xe,Qe,"Changed the client-id because another client seems to be using it."),r.clientID=Ni()),r.emit("afterTransactionCleanup",[e,r]),r._observers.has("update")){let d=new wt;_i(d,e)&&r.emit("update",[d.toUint8Array(),e.origin,r,e])}if(r._observers.has("updateV2")){let d=new Q;_i(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])):Gi(n,t+1)}}},E=(n,t,e=null,r=!0)=>{let s=n._transactionCleanups,i=!1,o=null;n._transaction===null&&(i=!0,n._transaction=new Pn(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&&Gi(s,0)}}return o},Gr=class{constructor(t,e){this.insertions=e,this.deletions=t,this.meta=new Map}},Di=(n,t,e)=>{qt(n,e.deletions,r=>{r instanceof C&&t.scope.some(s=>s===n.doc||nn(s,r))&&ls(r,!1)})},Ai=(n,t,e)=>{let r=null,s=n.doc,i=n.scope;E(s,c=>{for(;t.length>0&&n.currStackItem===null;){let l=s.store,a=t.pop(),d=new Set,u=[],h=!1;qt(c,a.insertions,f=>{if(f instanceof C){if(f.redone!==null){let{item:p,diff:g}=Hr(l,f.id);g>0&&(p=Y(c,b(p.id.client,p.id.clock+g))),f=p}!f.deleted&&i.some(p=>p===c.doc||nn(p,f))&&u.push(f)}}),qt(c,a.deletions,f=>{f instanceof C&&i.some(p=>p===c.doc||nn(p,f))&&!oe(a.insertions,f.id)&&d.add(f)}),d.forEach(f=>{h=wo(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},Qt=class extends _t{constructor(t,{captureTimeout:e=500,captureTransaction:r=l=>!0,deleteFilter:s=()=>!0,trackedOrigins:i=new Set([null]),ignoreRemoteMapChanges:o=!1,doc:c=Ft(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 Mt;l.afterState.forEach((m,w)=>{let y=l.beforeState.get(w)||0,x=m-y;x>0&&en(h,w,y,x)});let f=vt(),p=!1;if(this.lastChange>0&&f-this.lastChange<this.captureTimeout&&u.length>0&&!a&&!d){let m=u[u.length-1];m.deletions=Wt([m.deletions,l.deleteSet]),m.insertions=Wt([m.insertions,h])}else u.push(new Gr(l.deleteSet,h)),p=!0;!a&&!d&&(this.lastChange=f),qt(l,l.deleteSet,m=>{m instanceof C&&this.scope.some(w=>w===l.doc||nn(w,m))&&ls(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=Ft(t)?t:[t],t.forEach(r=>{e.has(r)||(e.add(r),(r instanceof T?r.doc!==this.doc:r!==this.doc)&&Vr("[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=>Di(r,this,s)),this.undoStack=[]),e&&(this.redoStack.forEach(s=>Di(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=Ai(this,this.undoStack,"undo")}finally{this.undoing=!1}return t}redo(){this.redoing=!0;let t;try{t=Ai(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*Yl(n){let t=k(n.restDecoder);for(let e=0;e<t;e++){let r=k(n.restDecoder),s=n.readClient(),i=k(n.restDecoder);for(let o=0;o<r;o++){let c=n.readInfo();if(c===10){let l=k(n.restDecoder);yield new B(b(s,i),l),i+=l}else if((31&c)!==0){let l=(c&192)===0,a=new C(b(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,yo(n,c));yield a,i+=a.length}else{let l=n.readLen();yield new z(b(s,i),l),i+=l}}}}var yt=class{constructor(t,e){this.gen=Yl(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===B);return this.curr}},zl=n=>$i(n,W),$i=(n,t=$)=>{let e=[],r=new t(O(n)),s=new yt(r,!1);for(let o=s.curr;o!==null;o=s.next())e.push(o);vn("Structs: ",e);let i=kt(r);vn("DeleteSet: ",i)},Gl=n=>Hi(n,W),Hi=(n,t=$)=>{let e=[],r=new t(O(n)),s=new yt(r,!1);for(let i=s.curr;i!==null;i=s.next())e.push(i);return{structs:e,ds:kt(r)}},sn=class{constructor(t){this.currClient=0,this.startClock=0,this.written=0,this.encoder=t,this.clientStructs=[]}},qn=n=>on(n,W,wt),Ji=(n,t=De,e=$)=>{let r=new t,s=new yt(new e(O(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===B&&(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),zs(d,r.restEncoder),r.restEncoder=d,r.toUint8Array()}else return S(r.restEncoder,0),r.toUint8Array()},$l=n=>Ji(n,Lt,W),Ki=(n,t=$)=>{let e=new Map,r=new Map,s=new yt(new t(O(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}},Hl=n=>Ki(n,W),Jl=(n,t)=>{if(n.constructor===z){let{client:e,clock:r}=n.id;return new z(b(e,r+t),n.length-t)}else if(n.constructor===B){let{client:e,clock:r}=n.id;return new B(b(e,r+t),n.length-t)}else{let e=n,{client:r,clock:s}=e.id;return new C(b(r,s+t),null,b(r,s+t-1),null,e.rightOrigin,e.parent,e.parentSub,e.content.splice(t))}},on=(n,t=$,e=Q)=>{if(n.length===1)return n[0];let r=n.map(d=>new t(O(d))),s=r.map(d=>new yt(d,!0)),i=null,o=new e,c=new sn(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===B?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)It(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===B)i.struct.length=h.id.clock+h.length-i.struct.id.clock;else{It(c,i.struct,i.offset);let p=h.id.clock-i.struct.id.clock-i.struct.length;i={struct:new B(b(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===B?i.struct.length-=p:h=Jl(h,p)),i.struct.mergeWith(h)||(It(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!==B;h=d.next())It(c,i.struct,i.offset),i={struct:h,offset:0}}i!==null&&(It(c,i.struct,i.offset),i=null),ss(c);let l=r.map(d=>kt(d)),a=Wt(l);return gt(o,a),o.toUint8Array()},rs=(n,t,e=$,r=Q)=>{let s=Qr(t),i=new r,o=new sn(i),c=new e(O(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===B){l.next();continue}if(d.id.clock+d.length>h)for(It(o,d,xt(h-d.id.clock,0)),l.next();l.curr&&l.curr.id.client===u;)It(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()}ss(o);let a=kt(c);return gt(i,a),i.toUint8Array()},Kl=(n,t)=>rs(n,t,W,wt),qi=n=>{n.written>0&&(n.clientStructs.push({written:n.written,restEncoder:F(n.encoder.restEncoder)}),n.encoder.restEncoder=ot(),n.written=0)},It=(n,t,e)=>{n.written>0&&n.currClient!==t.id.client&&qi(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++},ss=n=>{qi(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),be(t,r.restEncoder)}},Wn=(n,t,e,r)=>{let s=new e(O(n)),i=new yt(s,!1),o=new r,c=new sn(o);for(let a=i.curr;a!==null;a=i.next())It(c,t(a),0);ss(c);let l=kt(s);return gt(o,l),o.toUint8Array()},Wi=({formatting:n=!0,subdocs:t=!0,yxml:e=!0}={})=>{let r=0,s=A(),i=A(),o=A(),c=A();return c.set(null,null),l=>{switch(l.constructor){case z:case B:return l;case C:{let a=l,d=a.content;switch(d.constructor){case Ie:break;case nt:{if(e){let u=d.type;u instanceof re&&(u.nodeName=L(i,u.nodeName,()=>"node-"+r)),u instanceof dn&&(u.hookName=L(i,u.hookName,()=>"hook-"+r))}break}case Nt:{let u=d;u.arr=u.arr.map(()=>r);break}case se:{let u=d;u.content=new Uint8Array([r]);break}case ie:{let u=d;t&&(u.opts={},u.doc.guid=r+"");break}case Et:{let u=d;u.embed={};break}case I:{let u=d;n&&(u.key=L(o,u.key,()=>r+""),u.value=L(c,u.value,()=>({i:r})));break}case un:{let u=d;u.arr=u.arr.map(()=>r);break}case lt:{let u=d;u.str=Bs(r%10+"",u.str.length);break}default:G()}return a.parentSub&&(a.parentSub=L(s,a.parentSub,()=>r+"")),r++,l}default:G()}}},ql=(n,t)=>Wn(n,Wi(t),W,wt),Wl=(n,t)=>Wn(n,Wi(t),$,Q),Xl=n=>Wn(n,Ur,W,Q),Xi=n=>Wn(n,Ur,$,wt),vi="You must not compute changes after the event-handler fired.",Zt=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=Ql(this.currentTarget,this.target))}deletes(t){return oe(this.transaction.deleteSet,t.id)}get keys(){if(this._keys===null){if(this.transaction.doc._transactionCleanups.length===0)throw ut(vi);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=En(l.content.getContent());else return;else l!==null&&this.deletes(l)?(o="update",c=En(l.content.getContent())):(o="add",c=void 0)}else if(this.deletes(i))o="delete",c=En(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(vi);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}},Ql=(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},P=()=>{Vr("Invalid access: Add Yjs type to a document before reading data.")},Qi=80,is=0,$r=class{constructor(t,e){t.marker=!0,this.p=t,this.index=e,this.timestamp=is++}},Zl=n=>{n.timestamp=is++},Zi=(n,t,e)=>{n.p.marker=!1,n.p=t,t.marker=!0,n.index=e,n.timestamp=is++},ta=(n,t,e)=>{if(n.length>=Qi){let r=n.reduce((s,i)=>s.timestamp<i.timestamp?s:i);return Zi(r,t,e),r}else{let r=new $r(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)=>pe(t-i.index)<pe(t-o.index)?i:o),r=n._start,s=0;for(e!==null&&(r=e.p,s=e.index,Zl(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&&pe(e.index-s)<r.parent.length/Qi?(Zi(e,r,s),e):ta(n._searchMarker,r,s)},cn=(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=xt(t,s.index+e))}},ea=n=>{n.doc??P();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(;L(s,n,()=>[]).push(e),n._item!==null;)n=n._item.parent;Ri(r._eH,e,t)},T=class{constructor(){this._item=null,this._map=new Map,this._start=null,this.doc=null,this._length=0,this._eH=xi(),this._dEH=xi(),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){bi(this._eH,t)}observeDeep(t){bi(this._dEH,t)}unobserve(t){ki(this._eH,t)}unobserveDeep(t){ki(this._dEH,t)}toJSON(){}},to=(n,t,e)=>{n.doc??P(),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},eo=n=>{n.doc??P();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},na=(n,t)=>{let e=[],r=n._start;for(;r!==null;){if(r.countable&&Tt(r,t)){let s=r.content.getContent();for(let i=0;i<s.length;i++)e.push(s[i])}r=r.right}return e},ln=(n,t)=>{let e=0,r=n._start;for(n.doc??P();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}},no=(n,t)=>{let e=[];return ln(n,(r,s)=>{e.push(t(r,s,n))}),e},ra=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}}}},ro=(n,t)=>{n.doc??P();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(b(o,D(c,o)),s,s&&s.lastId,l,l&&l.id,t,null,new Nt(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(b(o,D(c,o)),s,s&&s.lastId,l,l&&l.id,t,null,new se(new Uint8Array(u))),s.integrate(n,0);break;case mt:s=new C(b(o,D(c,o)),s,s&&s.lastId,l,l&&l.id,t,null,new ie(u)),s.integrate(n,0);break;default:if(u instanceof T)s=new C(b(o,D(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!"),io=(n,t,e,r)=>{if(e>t._length)throw so();if(e===0)return t._searchMarker&&cn(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&&Y(n,b(o.id.client,o.id.clock+e));break}e-=o.length}return t._searchMarker&&cn(t._searchMarker,s,r.length),jn(n,t,o,r)},sa=(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)},oo=(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&&Y(n,b(c.id.client,c.id.clock+e)),e-=c.length);for(;r>0&&c!==null;)c.deleted||(r<c.length&&Y(n,b(c.id.client,c.id.clock+r)),c.delete(n),r-=c.length),c=c.right;if(r>0)throw so();t._searchMarker&&cn(t._searchMarker,s,-i+r)},Fn=(n,t,e)=>{let r=t._map.get(e);r!==void 0&&r.delete(n)},os=(n,t,e,r)=>{let s=t._map.get(e)||null,i=n.doc,o=i.clientID,c;if(r==null)c=new Nt([r]);else switch(r.constructor){case Number:case Object:case Boolean:case Array:case String:case Date:case BigInt:c=new Nt([r]);break;case Uint8Array:c=new se(r);break;case mt:c=new ie(r);break;default:if(r instanceof T)c=new nt(r);else throw new Error("Unexpected content type")}new C(b(o,D(i.store,o)),s,s&&s.lastId,null,null,t,e,c).integrate(n,0)},cs=(n,t)=>{n.doc??P();let e=n._map.get(t);return e!==void 0&&!e.deleted?e.content.getContent()[e.length-1]:void 0},co=n=>{let t={};return n.doc??P(),n._map.forEach((e,r)=>{e.deleted||(t[r]=e.content.getContent()[e.length-1])}),t},lo=(n,t)=>{n.doc??P();let e=n._map.get(t);return e!==void 0&&!e.deleted},ia=(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&&Tt(r,e)?r.content.getContent()[r.length-1]:void 0},ao=(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&&Tt(i,t)&&(e[s]=i.content.getContent()[i.length-1])}),e},On=n=>(n.doc??P(),mi(n._map.entries(),t=>!t[1].deleted)),Yn=class extends Zt{},te=class n extends T{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 T?e.clone():e)),t}get length(){return this.doc??P(),this._length}_callObserver(t,e){super._callObserver(t,e),Qn(this,t,new Yn(this,t))}insert(t,e){this.doc!==null?E(this.doc,r=>{io(r,this,t,e)}):this._prelimContent.splice(t,0,...e)}push(t){this.doc!==null?E(this.doc,e=>{sa(e,this,t)}):this._prelimContent.push(...t)}unshift(t){this.insert(0,t)}delete(t,e=1){this.doc!==null?E(this.doc,r=>{oo(r,this,t,e)}):this._prelimContent.splice(t,e)}get(t){return ro(this,t)}toArray(){return eo(this)}slice(t=0,e=this.length){return to(this,t,e)}toJSON(){return this.map(t=>t instanceof T?t.toJSON():t)}map(t){return no(this,t)}forEach(t){ln(this,t)}[Symbol.iterator](){return ra(this)}_write(t){t.writeTypeRef(Ua)}},oa=n=>new te,zn=class extends Zt{constructor(t,e,r){super(t,e),this.keysChanged=r}},ee=class n extends T{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 T?e.clone():e)}),t}_callObserver(t,e){Qn(this,t,new zn(this,t,e))}toJSON(){this.doc??P();let t={};return this._map.forEach((e,r)=>{if(!e.deleted){let s=e.content.getContent()[e.length-1];t[r]=s instanceof T?s.toJSON():s}}),t}get size(){return[...On(this)].length}keys(){return Tn(On(this),t=>t[0])}values(){return Tn(On(this),t=>t[1].content.getContent()[t[1].length-1])}entries(){return Tn(On(this),t=>[t[0],t[1].content.getContent()[t[1].length-1]])}forEach(t){this.doc??P(),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?E(this.doc,e=>{Fn(e,this,t)}):this._prelimContent.delete(t)}set(t,e){return this.doc!==null?E(this.doc,r=>{os(r,this,t,e)}):this._prelimContent.set(t,e),e}get(t){return cs(this,t)}has(t){return lo(this,t)}clear(){this.doc!==null?E(this.doc,t=>{this.forEach(function(e,r,s){Fn(t,s,r)})}):this._prelimContent.clear()}_write(t){t.writeTypeRef(Da)}},ca=n=>new ee,Ot=(n,t)=>n===t||typeof n=="object"&&typeof t=="object"&&n&&t&&Cr(n,t),an=class{constructor(t,e,r,s){this.left=t,this.right=e,this.index=r,this.currentAttributes=s}forward(){this.right===null&&G(),this.right.content.constructor===I?this.right.deleted||Me(this.currentAttributes,this.right.content):this.right.deleted||(this.index+=this.right.length),this.left=this.right,this.right=this.right.right}},Ti=(n,t,e)=>{for(;t.right!==null&&e>0;)t.right.content.constructor===I?t.right.deleted||Me(t.currentAttributes,t.right.content):t.right.deleted||(e<t.right.length&&Y(n,b(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},Mn=(n,t,e,r)=>{let s=new Map,i=r?Xn(t,e):null;if(i){let o=new an(i.p.left,i.p,i.index,s);return Ti(n,o,e-i.index)}else{let o=new an(null,t._start,0,s);return Ti(n,o,e)}},uo=(n,t,e,r)=>{for(;e.right!==null&&(e.right.deleted===!0||e.right.content.constructor===I&&Ot(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(b(i,D(s.store,i)),l,l&&l.lastId,a,a&&a.id,t,null,new I(c,o));d.integrate(n,0),e.right=d,e.forward()})},Me=(n,t)=>{let{key:e,value:r}=t;r===null?n.delete(e):n.set(e,r)},ho=(n,t)=>{for(;n.right!==null;){if(!(n.right.deleted||n.right.content.constructor===I&&Ot(t[n.right.content.key]??null,n.right.content.value)))break;n.forward()}},fo=(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(!Ot(a,l)){o.set(c,a);let{left:d,right:u}=e;e.right=new C(b(i,D(s.store,i)),d,d&&d.lastId,u,u&&u.id,t,null,new I(c,l)),e.right.integrate(n,0),e.forward()}}return o},Rr=(n,t,e,r,s)=>{e.currentAttributes.forEach((h,f)=>{s[f]===void 0&&(s[f]=null)});let i=n.doc,o=i.clientID;ho(e,s);let c=fo(n,t,e,s),l=r.constructor===String?new lt(r):r instanceof T?new nt(r):new Et(r),{left:a,right:d,index:u}=e;t._searchMarker&&cn(t._searchMarker,e.index,l.getLength()),d=new C(b(o,D(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(),uo(n,t,e,c)},Ii=(n,t,e,r,s)=>{let i=n.doc,o=i.clientID;ho(e,s);let c=fo(n,t,e,s);t:for(;e.right!==null&&(r>0||c.size>0&&(e.right.deleted||e.right.content.constructor===I));){if(!e.right.deleted)switch(e.right.content.constructor){case I:{let{key:l,value:a}=e.right.content,d=s[l];if(d!==void 0){if(Ot(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&&Y(n,b(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(b(o,D(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()}uo(n,t,e,c)},po=(n,t,e,r,s)=>{let i=t,o=A();for(;i&&(!i.countable||i.deleted);){if(!i.deleted&&i.content.constructor===I){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===I){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&&Me(s,a)}}t=t.right}return c},la=(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===I){let r=t.content.key;e.has(r)?t.delete(n):e.add(r)}t=t.left}},go=n=>{let t=0;return E(n.doc,e=>{let r=n._start,s=n._start,i=A(),o=kn(i);for(;s;)s.deleted===!1&&(s.content.constructor===I?Me(o,s.content):(t+=po(e,r,s,i,o),i=kn(o),r=s)),s=s.right}),t},aa=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&&Fi(n,e.store.clients.get(r),i,s,o=>{!o.deleted&&o.content.constructor===I&&o.constructor!==z&&t.add(o.parent)})}E(e,r=>{qt(n,n.deleteSet,s=>{if(s instanceof z||!s.parent._hasFormatting||t.has(s.parent))return;let i=s.parent;s.content.constructor===I?t.add(i):la(r,s)});for(let s of t)go(s)})},Oi=(n,t,e)=>{let r=e,s=kn(t.currentAttributes),i=t.right;for(;e>0&&t.right!==null;){if(t.right.deleted===!1)switch(t.right.content.constructor){case nt:case Et:case lt:e<t.right.length&&Y(n,b(t.right.id.client,t.right.id.clock+e)),e-=t.right.length,t.right.delete(n);break}t.forward()}i&&po(n,i,t.right,s,t.currentAttributes);let o=(t.left||t.right).parent;return o._searchMarker&&cn(o._searchMarker,t.index,-r+e),t},Gn=class extends Zt{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=[];E(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},ei(l)||(f.attributes=Qs({},l))),d=0;break}f&&e.push(f),c=null}};for(;o!==null;){switch(o.content.constructor){case nt:case Et: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 I:{let{key:f,value:p}=o.content;if(this.adds(o)){if(!this.deletes(o)){let g=s.get(f)??null;Ot(g,p)?p!==null&&o.delete(r):(c==="retain"&&h(),Ot(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;Ot(g,p)||(c==="retain"&&h(),l[f]=g)}else if(!o.deleted){i.set(f,p);let g=l[f];g!==void 0&&(Ot(g,p)?g!==null&&o.delete(r):(c==="retain"&&h(),p===null?delete l[f]:l[f]=p))}o.deleted||(c==="insert"&&h(),Me(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}},ve=class n extends T{constructor(t){super(),this._pending=t!==void 0?[()=>this.insert(0,t)]:[],this._searchMarker=[],this._hasFormatting=!1}get length(){return this.doc??P(),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 Gn(this,t,e);Qn(this,t,r),!t.local&&this._hasFormatting&&(t._needFormattingCleanup=!0)}toString(){this.doc??P();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?E(this.doc,r=>{let s=new an(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)&&Rr(r,this,s,c,o.attributes||{})}else o.retain!==void 0?Ii(r,this,s,o.retain,o.attributes||{}):o.delete!==void 0&&Oi(r,s,o.delete)}}):this._pending.push(()=>this.applyDelta(t))}toDelta(t,e,r){this.doc??P();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(Tt(l,t)||e!==void 0&&Tt(l,e))switch(l.content.constructor){case lt:{let u=i.get("ychange");t!==void 0&&!Tt(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&&!Tt(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 Et:{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 I:Tt(l,t)&&(a(),Me(i,l.content));break}l=l.right}a()};return t||e?E(o,u=>{t&&Fr(u,t),e&&Fr(u,e),d()},"cleanup"):d(),s}insert(t,e,r){if(e.length<=0)return;let s=this.doc;s!==null?E(s,i=>{let o=Mn(i,this,t,!r);r||(r={},o.currentAttributes.forEach((c,l)=>{r[l]=c})),Rr(i,this,o,e,r)}):this._pending.push(()=>this.insert(t,e,r))}insertEmbed(t,e,r){let s=this.doc;s!==null?E(s,i=>{let o=Mn(i,this,t,!r);Rr(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?E(r,s=>{Oi(s,Mn(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?E(s,i=>{let o=Mn(i,this,t,!1);o.right!==null&&Ii(i,this,o,e,r)}):this._pending.push(()=>this.format(t,e,r))}removeAttribute(t){this.doc!==null?E(this.doc,e=>{Fn(e,this,t)}):this._pending.push(()=>this.removeAttribute(t))}setAttribute(t,e){this.doc!==null?E(this.doc,r=>{os(r,this,t,e)}):this._pending.push(()=>this.setAttribute(t,e))}getAttribute(t){return cs(this,t)}getAttributes(){return co(this)}_write(t){t.writeTypeRef(Aa)}},da=n=>new ve,Ze=class{constructor(t,e=()=>!0){this._filter=e,this._root=t,this._currentNode=t._start,this._firstCall=!0,t.doc??P()}[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===re||e.constructor===ne)&&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})}},ne=class n extends T{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 T?e.clone():e)),t}get length(){return this.doc??P(),this._prelimContent===null?this._length:this._prelimContent.length}createTreeWalker(t){return new Ze(this,t)}querySelector(t){t=t.toUpperCase();let r=new Ze(this,s=>s.nodeName&&s.nodeName.toUpperCase()===t).next();return r.done?null:r.value}querySelectorAll(t){return t=t.toUpperCase(),it(new Ze(this,e=>e.nodeName&&e.nodeName.toUpperCase()===t))}_callObserver(t,e){Qn(this,t,new $n(this,e,t))}toString(){return no(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),ln(this,i=>{s.insertBefore(i.toDOM(t,e,r),null)}),s}insert(t,e){this.doc!==null?E(this.doc,r=>{io(r,this,t,e)}):this._prelimContent.splice(t,0,...e)}insertAfter(t,e){if(this.doc!==null)E(this.doc,r=>{let s=t&&t instanceof T?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?E(this.doc,r=>{oo(r,this,t,e)}):this._prelimContent.splice(t,e)}toArray(){return eo(this)}push(t){this.insert(this.length,t)}unshift(t){this.insert(0,t)}get(t){return ro(this,t)}slice(t=0,e=this.length){return to(this,t,e)}forEach(t){ln(this,t)}_write(t){t.writeTypeRef(Ta)}},ua=n=>new ne,re=class n extends ne{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 ti(e,(r,s)=>{t.setAttribute(s,r)}),t.insert(0,this.toArray().map(r=>r instanceof T?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?E(this.doc,e=>{Fn(e,this,t)}):this._prelimAttrs.delete(t)}setAttribute(t,e){this.doc!==null?E(this.doc,r=>{os(r,this,t,e)}):this._prelimAttrs.set(t,e)}getAttribute(t){return cs(this,t)}hasAttribute(t){return lo(this,t)}getAttributes(t){return t?ao(this,t):co(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 ln(this,o=>{s.appendChild(o.toDOM(t,e,r))}),r!==void 0&&r._createAssociation(s,this),s}_write(t){t.writeTypeRef(va),t.writeKey(this.nodeName)}},ha=n=>new re(n.readKey()),$n=class extends Zt{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)})}},dn=class n extends ee{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(Ia),t.writeKey(this.hookName)}},fa=n=>new dn(n.readKey()),Hn=class n extends ve{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(Oa)}},pa=n=>new Hn,Te=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()}},ga=0,z=class extends Te{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),ji(t.doc.store,this)}write(t,e){t.writeInfo(ga),t.writeLen(this.length-e)}getMissing(t,e){return null}},se=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}},ma=n=>new se(n.readBuf()),Ie=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){en(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}},wa=n=>new Ie(n.readLen()),mo=(n,t)=>new mt({guid:n,...t,shouldLoad:t.shouldLoad||t.autoLoad||!1}),ie=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(mo(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}},ya=n=>new ie(mo(n.readString(),n.readAny())),Et=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}},Sa=n=>new Et(n.readJSON()),I=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}},xa=n=>new I(n.readKey(),n.readJSON()),un=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}},ba=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 un(e)},ka=qe("node_env")==="development",Nt=class n{constructor(t){this.arr=t,ka&&_r(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}},Ea=n=>{let t=n.readLen(),e=[];for(let r=0;r<t;r++)e.push(n.readAny());return new Nt(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}},Ca=n=>new lt(n.readString()),_a=[oa,ca,da,ha,ua,fa,pa],Ua=0,Da=1,Aa=2,va=3,Ta=4,Ia=5,Oa=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}},Ma=n=>new nt(_a[n.readTypeRef()](n)),Hr=(n,t)=>{let e=t,r=0,s;do r>0&&(e=b(e.client,e.clock+r)),s=Kt(n,e),r=e.clock-s.id.clock,e=s.redone;while(e!==null&&s instanceof C);return{item:s,diff:r}},ls=(n,t)=>{for(;n!==null&&n.keep!==t;)n.keep=t,n=n.parent._item},Jn=(n,t,e)=>{let{client:r,clock:s}=t.id,i=new C(b(r,s+e),t,b(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=b(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},Mi=(n,t)=>Ms(n,e=>oe(e.deletions,t)),wo=(n,t,e,r,s,i)=>{let o=n.doc,c=o.store,l=o.clientID,a=t.redone;if(a!==null)return Y(n,a);let d=t.parent._item,u=null,h;if(d!==null&&d.deleted===!0){if(d.redone===null&&(!e.has(d)||wo(n,d,e,r,s,i)===null))return null;for(;d.redone!==null;)d=Y(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:Y(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:Y(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||oe(r,u.right.id)||Mi(i.undoStack,u.right.id)||Mi(i.redoStack,u.right.id));)for(u=u.right;u.redone;)u=Y(n,u.redone);if(u&&u.right!==null)return null}else u=f._map.get(t.parentSub)||null;let p=D(c,l),g=b(l,p),m=new C(g,u,u&&u.lastId,h,h&&h.id,f,t.parentSub,t.content.copy());return t.redone=g,ls(m,!0),m.integrate(n,0),m},C=class n extends Te{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>=D(e,this.origin.client))return this.origin.client;if(this.rightOrigin&&this.rightOrigin.client!==this.id.client&&this.rightOrigin.clock>=D(e,this.rightOrigin.client))return this.rightOrigin.client;if(this.parent&&this.parent.constructor===bt&&this.id.client!==this.parent.client&&this.parent.clock>=D(e,this.parent.client))return this.parent.client;if(this.origin&&(this.left=zr(t,e,this.origin),this.origin=this.left.lastId),this.rightOrigin&&(this.right=Y(t,this.rightOrigin),this.rightOrigin=this.right.id),this.left&&this.left.constructor===z||this.right&&this.right.constructor===z)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===bt){let r=Kt(e,this.parent);r.constructor===z?this.parent=null:this.parent=r.content.type}return null}integrate(t,e){if(e>0&&(this.id.clock+=e,this.left=zr(t,t.doc.store,b(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),Jt(this.origin,s.origin)){if(s.id.client<this.id.client)r=s,i.clear();else if(Jt(this.rightOrigin,s.rightOrigin))break}else if(s.origin!==null&&o.has(Kt(t.doc.store,s.origin)))i.has(Kt(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),ji(t.doc.store,this),this.content.integrate(t,this),Ui(t,this.parent,this.parentSub),(this.parent._item!==null&&this.parent._item.deleted||this.parentSub!==null&&this.right!==null)&&this.delete(t)}else new z(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:b(this.id.client,this.id.clock+this.length-1)}mergeWith(t){if(this.constructor===t.constructor&&Jt(t.origin,this.lastId)&&this.right===t&&Jt(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(),en(t.deleteSet,this.id.client,this.id.clock,this.length),Ui(t,e,this.parentSub),this.content.delete(t)}}gc(t,e){if(!this.deleted)throw G();this.content.gc(t),e?jl(t,this,new z(this.id,this.length)):this.content=new Ie(this.length)}write(t,e){let r=e>0?b(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=es(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===bt?(t.writeParentInfo(!1),t.writeLeftID(c)):G();i!==null&&t.writeString(i)}this.content.write(t,e)}},yo=(n,t)=>La[t&31](n),La=[()=>{G()},wa,ba,ma,Ca,Sa,xa,Ma,Ea,ya,()=>{G()}],Na=10,B=class extends Te{get deleted(){return!0}delete(){}mergeWith(t){return this.constructor!==t.constructor?!1:(this.length+=t.length,!0)}integrate(t,e){G()}write(t,e){t.writeInfo(Na),S(t.restEncoder,this.length-e)}getMissing(t,e){return null}},So=typeof globalThis<"u"?globalThis:typeof window<"u"?window:typeof global<"u"?global:{},xo="__ $YJS$ __";So[xo]===!0&&console.error("Yjs was already imported. This breaks constructor checks and will lead to issues! - https://github.com/yjs/yjs/issues/438");So[xo]=!0;var as=3e4,Le=class extends fe{constructor(t){super(),this.doc=t,this.clientID=t.clientID,this.states=new Map,this.meta=new Map,this._checkInterval=setInterval(()=>{let e=vt();this.getLocalState()!==null&&as/2<=e-this.meta.get(this.clientID).lastUpdated&&this.setLocalState(this.getLocalState());let r=[];this.meta.forEach((s,i)=>{i!==this.clientID&&as<=e-s.lastUpdated&&this.states.has(i)&&r.push(i)}),r.length>0&&ds(this,r,"timeout")},q(as/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:vt()});let o=[],c=[],l=[],a=[];t===null?a.push(e):i==null?t!=null&&o.push(e):(c.push(e),Je(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}},ds=(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:vt()})}r.push(i)}}r.length>0&&(n.emit("change",[{added:[],updated:[],removed:r},e]),n.emit("update",[{added:[],updated:[],removed:r},e]))};var bo=1,Zn="fromPersistence",tr="document",Ne="state",ce="savedAt",ko="savedBy",Eo="version",er="gutenberg",us="syncManager";var Uo=Pe(_o(),1),{lock:Do,unlock:Hd}=(0,Uo.__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 Ao(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 vo(n){return((...t)=>n(...t))}function To(n){return function(...t){setTimeout(()=>{n.apply(this,t)},0)}}var Jo=Pe(Oo(),1);var Mo=0,Lo=1,Va=2,No=(n,t)=>{S(n,Mo);let e=ts(t);V(n,e)},Ra=(n,t,e)=>{S(n,Lo),V(n,fn(t,e))},Ba=(n,t,e)=>Ra(t,e,R(n)),Vo=(n,t,e,r)=>{try{hn(t,R(n),e)}catch(s){r?.(s),console.error("Caught error while handling a Yjs update",s)}};var Pa=Vo,hs=(n,t,e,r,s)=>{let i=k(n);switch(i){case Mo:Ba(n,t,e);break;case Lo:Vo(n,e,r,s);break;case Va:Pa(n,e,r,s);break;default:throw new Error("Unknown message type")}return i};var H=(n=>(n.COMPACTION="compaction",n.SYNC_STEP_1="sync_step1",n.SYNC_STEP_2="sync_step2",n.UPDATE="update",n))(H||{});var fs=Pe(Bo(),1);var Po="/wp-sync/v1/updates";function Fa(n){let t="",e=n.byteLength;for(let r=0;r<e;r++)t+=String.fromCharCode(n[r]);return globalThis.btoa(t)}function ps(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 Ve(n,t){return{data:Fa(n),type:t}}function jo(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!==H.COMPACTION);i.length!==0&&r.unshift(...i)},resume(){e=!1},size(){return r.length}}}async function Fo(n){let t=await(0,fs.default)({body:JSON.stringify(n),headers:{"Content-Type":"application/json"},method:"POST",parse:!1,path:Po});if(!t.ok)throw new Error(`Sync update failed with status ${t.status}`);return await t.json()}function gs(n){n.rooms.length!==0&&(0,fs.default)({body:JSON.stringify(n),headers:{"Content-Type":"application/json"},keepalive:!0,method:"POST",parse:!1,path:Po}).catch(()=>{})}var ys=1e3,Ya=250,za=25*1e3,Ga=30*1e3,mn="polling-manager",J=new Map;function $a(n){let t=n.filter(e=>[H.COMPACTION,H.UPDATE].includes(e.type)).map(e=>ps(e.data));return Ve(qn(t),H.COMPACTION)}function Ha(n){let t=ot();return No(t,n),Ve(F(t),H.SYNC_STEP_1)}function Ja(n,t){let e=O(t),r=ot();return hs(e,r,n,mn),Ve(F(r),H.SYNC_STEP_2)}function Ka(n,t){let e=t.getStates(),r=new Set,s=new Set,i=new Set(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&&ds(t,Array.from(i),mn)}function qa(n,t,e){let r=ps(n.data);switch(n.type){case H.SYNC_STEP_1:return Ja(t,r);case H.SYNC_STEP_2:{let s=O(r),i=ot();hs(s,i,t,mn),e();return}case H.COMPACTION:case H.UPDATE:hn(t,r,mn)}}var nr=!1,Yo=!1,gn=document.visibilityState==="visible",ms=!1,ws=!1,Ct=ys,Bt=null;function zo(){ws=!0}function Go(){let n=Array.from(J.entries()).map(([t,e])=>({after:0,awareness:null,client_id:e.clientId,room:t,updates:[]}));gs({rooms:n})}function $o(){let n=gn;gn=document.visibilityState==="visible",gn&&!n&&Bt&&(clearTimeout(Bt),Bt=null,rr())}function rr(){ms=!0,Bt=null;async function n(){if(J.size===0){ms=!1;return}ws=!1,J.forEach(e=>{e.onStatusChange({status:"connecting"})});let t={rooms:Array.from(J.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 Fo(t);J.forEach(r=>{r.onStatusChange({status:"connected"})}),e.forEach(r=>{if(!J.has(r.room))return;let s=J.get(r.room);s.endCursor=r.end_cursor,s.processAwarenessUpdate(r.awareness),Object.keys(r.awareness).length>1&&(Yo=!0,s.updateQueue.resume());let i=r.updates.map(o=>s.processDocUpdate(o)).filter(o=>!!o);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($a(r.compaction_request)))}),gn&&Yo?Ct=Ya:gn?Ct=ys:Ct=za}catch(e){Ct=Math.min(Ct*2,Ga);for(let r of t.rooms){if(!J.has(r.room))continue;let s=J.get(r.room);s.updateQueue.restore(r.updates),s.log("Error posting sync update, will retry with backoff",{error:e,nextPoll:Ct})}ws||J.forEach(r=>{r.onStatusChange({status:"disconnected",retryInMs:Ct})})}Bt=setTimeout(rr,Ct)}n()}function Wa({room:n,doc:t,awareness:e,log:r,onSync:s,onStatusChange:i}){if(J.has(n))return;let o=jo([Ha(t)]);function c(){d.localAwarenessState=e.getLocalState()??{}}function l(u,h){mn!==h&&o.add(Ve(u,H.UPDATE))}function a(){t.off("update",l),e.off("change",c),o.clear()}let d={clientId:t.clientID,createCompactionUpdate:()=>Ve(fn(t),H.COMPACTION),endCursor:0,localAwarenessState:e.getLocalState()??{},log:r,onStatusChange:i,processAwarenessUpdate:u=>Ka(u,e),processDocUpdate:u=>qa(u,t,s),unregister:a,updateQueue:o};t.on("update",l),e.on("change",c),J.set(n,d),nr||(window.addEventListener("beforeunload",zo),window.addEventListener("pagehide",Go),document.addEventListener("visibilitychange",$o),nr=!0),ms||rr()}function Xa(n){let t=J.get(n);if(t){let e=[{after:0,awareness:null,client_id:t.clientId,room:n,updates:[]}];gs({rooms:e}),t.unregister(),J.delete(n)}J.size===0&&nr&&(window.removeEventListener("beforeunload",zo),window.removeEventListener("pagehide",Go),document.removeEventListener("visibilitychange",$o),nr=!1)}function Qa(){Ct=ys*2,Bt&&(clearTimeout(Bt),Bt=null,rr())}var wn={registerRoom:Wa,retryNow:Qa,unregisterRoom:Xa};var Za=class extends _t{constructor(n){super(),this.options=n,this.log("Initializing",{room:n.room}),this.awareness=n.awareness??new Le(n.ydoc),this.connect()}awareness;status="disconnected";synced=!1;connect(){this.log("Connecting"),wn.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"),wn.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={})=>{this.options.debug&&console.log(`[${this.constructor.name}]: ${n}`,{room:this.options.room,...t})};onSync=()=>{this.synced||(this.synced=!0,this.log("Synced"))}};function Ho(){return async({awareness:n,objectType:t,objectId:e,ydoc:r})=>{let s=e?`${t}:${e}`:t,i=new Za({awareness:n,room:s,ydoc:r});return{destroy:()=>i.destroy(),on:(o,c)=>{i.on(o,c)}}}}var Re=null;function td(){return[Ho()]}function ed(n){return typeof n=="function"}function Ss(){if(Re)return Re;if(!window._wpCollaborationEnabled)return[];let n=(0,Jo.applyFilters)("sync.providers",td());return Array.isArray(n)?(Re=n.filter(ed),Re):(Re=[],Re)}var Ko=(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},qo=class extends fe{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=Ft(n)?n:[n],n.forEach(t=>{let e=t.doc,r=L(this.docs,e,()=>{let s=new Qt([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 Ko(this,"undo")}redo(){return Ko(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 Wo(){let n=new qo([],{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 sr(n={}){let t=new Map(Object.entries(n));return new mt({meta:t})}function xs(n){n.getMap(Ne).set(Eo,bo)}function bs(n){let t=n.getMap(Ne);t.set(ce,Date.now()),t.set(ko,n.clientID)}function Xo(){return Math.floor(Math.random()*1e9)}function Qo(n){return JSON.stringify({document:ci(Oe(n)),updateId:Xo()})}function Zo(n){try{let{document:t}=JSON.parse(n),e={[Zn]:!0},r=sr(e),s=li(t);return Vt(r,s),r.clientID=Xo(),r}catch{return null}}function Pt(n,t){return`${n}_${t}`}function tc(n=!1){let t=n?Ao:vo,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,x){let U=Ss(),_=Pt(m,w);if(U.length===0){i("loadEntity","no providers, skipping",_);return}if(r.has(_)){i("loadEntity","already loaded",_);return}i("loadEntity","loading",_),x={addUndoMeta:t(x.addUndoMeta),editRecord:t(x.editRecord),getEditedRecord:t(x.getEditedRecord),onStatusChange:t(x.onStatusChange),refetchRecord:t(x.refetchRecord),restoreUndoMeta:t(x.restoreUndoMeta),saveRecord:t(x.saveRecord)};let v=sr({objectType:m}),j=v.getMap(tr),M=v.getMap(Ne),St=Date.now(),Z=()=>{i("loadEntity","unloading",_),cc.forEach(ue=>ue.destroy()),x.onStatusChange(null),j.unobserveDeep(at),M.unobserve(st),v.destroy(),r.delete(_)},ae=g.createAwareness?.(v,w),at=(ue,jt)=>{jt.local&&!(jt.origin instanceof Qt)||p.updateEntityRecord(m,w)},st=(ue,jt)=>{jt.local||ue.keysChanged.forEach(lc=>{if(lc===ce){let Ds=M.get(ce);typeof Ds=="number"&&Ds>St&&(i("loadEntity","refetching record",_),x.refetchRecord().catch(()=>{}))}})};s||(s=Wo());let{addUndoMeta:Be,restoreUndoMeta:de}=x;s.addToScope(j,{addUndoMeta:Be,restoreUndoMeta:de});let Sn={awareness:ae,handlers:x,objectId:w,objectType:m,syncConfig:g,unload:Z,ydoc:v};r.set(_,Sn),i("loadEntity","connecting",_);let cc=await Promise.all(U.map(async ue=>{let jt=await ue({objectType:m,objectId:w,ydoc:v,awareness:ae});return jt.on("status",x.onStatusChange),jt}));j.observeDeep(at),M.observe(st),xs(v),p.applyPersistedCrdtDoc(m,w,y)}async function c(g,m,w){let y=Ss(),x=Pt(m,null);if(y.length===0){i("loadCollection","no providers, skipping",x);return}if(e.has(m)){i("loadCollection","already loaded",x);return}i("loadCollection","loading",x);let U=sr({collection:!0,objectType:m}),_=U.getMap(Ne),v=Date.now(),j=()=>{i("loadCollection","unloading",x),ae.forEach(at=>at.destroy()),w.onStatusChange(null),_.unobserve(M),U.destroy(),e.delete(m)},M=(at,st)=>{st.local||at.keysChanged.forEach(Be=>{if(Be===ce){let de=_.get(ce);typeof de=="number"&&de>v&&w.refetchRecords().catch(()=>{})}})},St=g.createAwareness?.(U),Z={awareness:St,handlers:w,syncConfig:g,unload:j,ydoc:U};e.set(m,Z),i("loadCollection","connecting",x);let ae=await Promise.all(y.map(async at=>{let st=await at({awareness:St,objectType:m,objectId:null,ydoc:U});return st.on("status",w.onStatusChange),st}));_.observe(M),xs(U)}function l(g,m){let w=Pt(g,m);i("unloadEntity","unloading",w),r.get(w)?.unload(),u(g,null,{},origin,{isSave:!0})}function a(g,m){let w=Pt(g,m),y=r.get(w);if(!(!y||!y.awareness))return y.awareness}function d(g,m,w){let y=Pt(g,m),x=r.get(y);if(!x){i("applyPersistedCrdtDoc","no entity state",y);return}let{handlers:U,syncConfig:{applyChangesToCRDTDoc:_,getChangesFromCRDTDoc:v,getPersistedCRDTDoc:j},ydoc:M}=x,St=j?.(w),Z=St?Zo(St):null;if(!Z){i("applyPersistedCrdtDoc","no persisted doc",y),M.transact(()=>{_(M,w),U.saveRecord()},us);return}let ae=Oe(Z);Vt(M,ae);let at=v(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 Be=st.reduce((de,Sn)=>Object.assign(de,{[Sn]:w[Sn]}),{});M.transact(()=>{_(M,Be),U.saveRecord()},us)}function u(g,m,w,y,x={}){let{isSave:U=!1,isNewUndoLevel:_=!1}=x,v=Pt(g,m),j=r.get(v),M=e.get(g);if(j){let{syncConfig:St,ydoc:Z}=j;_&&s&&s.stopCapturing?.(),Z.transact(()=>{i("updateCRDTDoc","applying changes",v,{changedKeys:Object.keys(w)}),St.applyChangesToCRDTDoc(Z,w),U&&bs(Z)},y)}M&&U&&M.ydoc.transact(()=>{bs(M.ydoc)},y)}async function h(g,m){let w=Pt(g,m),y=r.get(w);if(!y){i("updateEntityRecord","no entity state",w);return}let{handlers:x,syncConfig:U,ydoc:_}=y,v=U.getChangesFromCRDTDoc(_,await x.getEditedRecord()),j=Object.keys(v);j.length!==0&&(i("updateEntityRecord","changes",w,{changedKeys:j}),x.editRecord(v))}async function f(g,m){let w=Pt(g,m),y=r.get(w);return y?.ydoc?(await new Promise(x=>setTimeout(x,0)),Qo(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(To(u))}}var yn=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 x,U=f[y-1],_=f[y+1];U&&(f[y-1]=void 0);let v=!1;if(_){let M=_.oldPos-y;v=_&&0<=M&&M<c}let j=U&&U.oldPos+1<l;if(!v&&!j){f[y]=void 0;continue}if(!j||v&&U.oldPos<_.oldPos?x=this.addToPath(_,!0,!1,0,r):x=this.addToPath(U,!1,!0,1,r),p=this.extractCommon(x,e,t,y,r),x.oldPos+1>=l&&p+1>=c)return o(this.buildValues(x.lastComponent,e,t))||!0;f[y]=x,x.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 ks=class extends yn{},ec=new ks;function ir(n,t,e){return ec.diff(n,t,e)}var or=Pe(Es(),1);var rc=Pe(Es(),1);function nd(n){return JSON.parse(JSON.stringify(n))}var Cs;(n=>{function t(i={},o={},c=!1){typeof i!="object"&&(i={}),typeof o!="object"&&(o={});let l=nd(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,rc.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})(Cs||(Cs={}));var le=Cs;var _s;(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})(_s||(_s={}));var rt=_s;var X=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 rd(n){return JSON.parse(JSON.stringify(n))}var sd="\0";function sc(n){return n.map(t=>({...t,count:t.value.length}))}var ic=(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]]},id=class K{static Op=rt;static OpIterator=X;static AttributeMap=le;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=rd(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,or.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 X(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 K(r)}compose(t){let e=new X(this.ops),r=new X(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 K(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]=ic(l[h],a.retain),m=K.getHandler(f);d[h]={[f]:m.compose(p,g,h==="retain")}}let u=le.compose(l.attributes,a.attributes,typeof l.retain=="number");if(u&&(d.attributes=u),o.push(d),!r.hasNext()&&(0,or.default)(o.ops[o.ops.length-1],d)){let h=new K(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 K(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 K;let e=this.deltasToStrings(t),r=sc(ir(e[0],e[1])),s=new X(this.ops),i=new X(t.ops);return this.convertChangesToDelta(r,s,i).chop()}eachLine(t,e=`
4 +`){let r=new X(this.ops),s=new K,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 K}}s.length()>0&&t(s,{},i)}invert(t){let e=new K;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),le.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 X(i.ops).next(),[c,l,a]=ic(s.retain,o.insert),d=K.getHandler(c);return e.retain({[c]:d.invert(l,a)},le.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 X(this.ops),i=new X(r.ops),o=new K;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=K.getHandler(f);p&&(h={[f]:p.transform(d[f],u[f],e)})}}o.retain(h,le.transform(l.attributes,a.attributes,e))}}return o.chop()}transformPosition(t,e=!1){e=!!e;let r=new X(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 K;if(e===null)return this.diff(t);let r=this.deltasToStrings(t),s=sc(ir(r[0],r[1])),i=0,o=[];for(let d=0;d<s.length;d++){let u=s[d],h=i,f=i+(u.count??0),p=e>h&&e<=f,g=!u.added&&!u.removed,m=u.removed&&!u.added,w=s[d+1],y=w&&w.added&&!w.removed;if(g&&p&&y){let x=this.tryMoveInsertionToCursor(u,w,e,h);if(x){o.push(...x),d++,i=f;continue}}if(m){let x=this.tryMoveDeletionToCursor(u,o,e,i);if(x){o.pop(),o.push(...x),i+=u.count??0;continue}}o.push(u),u.added||(i+=u.count??0)}s=o;let c=new X(this.ops),l=new X(t.ops);return this.convertChangesToDelta(s,c,l).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:sd;let s=e===t?"on":"with";throw new Error("diff() called "+s+" non-document")}).join(""))}convertChangesToDelta(t,e,r){let s=new K;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,or.default)(l.insert,a.insert)?s.retain(c,le.diff(l.attributes,a.attributes)):s.push(a).delete(c)}o-=c}}),s}},oc=id;var Us={};Do(Us,{createSyncManager:tc,Delta:oc,CRDT_DOC_META_PERSISTENCE_KEY:Zn,CRDT_RECORD_MAP_KEY:tr,LOCAL_EDITOR_ORIGIN:er,retrySyncConnection:()=>wn.retryNow()});var od="13";return pc(cd);})();
10 5 //# sourceMappingURL=index.min.js.map