HEX
Server: nginx
System: Linux pool195-106-36.bur.atomicsites.net 6.12.57+deb12-amd64 #1 SMP PREEMPT_DYNAMIC Debian 6.12.57-1~bpo12+1 (2025-11-17) x86_64
User: (0)
PHP: 8.3.32
Disabled: pcntl_fork
Upload Files
File: //srv/wordpress/core/beta/wp-includes/js/dist/sync.min.js
/*! This file is auto-generated */
"use strict";var wp;(wp||={}).sync=(()=>{var zl=Object.create;var Jn=Object.defineProperty;var Gl=Object.getOwnPropertyDescriptor;var ql=Object.getOwnPropertyNames;var Hl=Object.getPrototypeOf,Jl=Object.prototype.hasOwnProperty;var Kn=(e,t)=>()=>(t||e((t={exports:{}}).exports,t),t.exports),qo=(e,t)=>{for(var n in t)Jn(e,n,{get:t[n],enumerable:!0})},Ho=(e,t,n,r)=>{if(t&&typeof t=="object"||typeof t=="function")for(let s of ql(t))!Jl.call(e,s)&&s!==n&&Jn(e,s,{get:()=>t[s],enumerable:!(r=Gl(t,s))||r.enumerable});return e};var Zt=(e,t,n)=>(n=e!=null?zl(Hl(e)):{},Ho(t||!e||!e.__esModule?Jn(n,"default",{value:e,enumerable:!0}):n,e)),Kl=e=>Ho(Jn({},"__esModule",{value:!0}),e);var Xc=Kn((Df,Wc)=>{Wc.exports=window.wp.privateApis});var Kr=Kn((vf,rl)=>{rl.exports=window.wp.hooks});var ml=Kn((Lf,gl)=>{gl.exports=window.wp.apiFetch});var $o=Kn((xp,Vl)=>{"use strict";Vl.exports=function e(t,n){if(t===n)return!0;if(t&&n&&typeof t=="object"&&typeof n=="object"){if(t.constructor!==n.constructor)return!1;var r,s,o;if(Array.isArray(t)){if(r=t.length,r!=n.length)return!1;for(s=r;s--!==0;)if(!e(t[s],n[s]))return!1;return!0}if(t instanceof Map&&n instanceof Map){if(t.size!==n.size)return!1;for(s of t.entries())if(!n.has(s[0]))return!1;for(s of t.entries())if(!e(s[1],n.get(s[0])))return!1;return!0}if(t instanceof Set&&n instanceof Set){if(t.size!==n.size)return!1;for(s of t.entries())if(!n.has(s[0]))return!1;return!0}if(ArrayBuffer.isView(t)&&ArrayBuffer.isView(n)){if(r=t.length,r!=n.length)return!1;for(s=r;s--!==0;)if(t[s]!==n[s])return!1;return!0}if(t.constructor===RegExp)return t.source===n.source&&t.flags===n.flags;if(t.valueOf!==Object.prototype.valueOf)return t.valueOf()===n.valueOf();if(t.toString!==Object.prototype.toString)return t.toString()===n.toString();if(o=Object.keys(t),r=o.length,r!==Object.keys(n).length)return!1;for(s=r;s--!==0;)if(!Object.prototype.hasOwnProperty.call(n,o[s]))return!1;for(s=r;s--!==0;){var i=o[s];if(!e(t[i],n[i]))return!1}return!0}return t!==t&&n!==n}});var Th={};qo(Th,{Awareness:()=>cn,Y:()=>Ht,YJS_VERSION:()=>Dh,privateApis:()=>zo});var Ht={};qo(Ht,{AbsolutePosition:()=>Ir,AbstractConnector:()=>zs,AbstractStruct:()=>rn,AbstractType:()=>R,Array:()=>me,ContentAny:()=>Gt,ContentBinary:()=>Se,ContentDeleted:()=>sn,ContentDoc:()=>_e,ContentEmbed:()=>vt,ContentFormat:()=>L,ContentJSON:()=>Pn,ContentString:()=>mt,ContentType:()=>ut,Doc:()=>bt,GC:()=>X,ID:()=>Ut,Item:()=>D,Map:()=>ye,PermanentUserData:()=>qs,RelativePosition:()=>en,Skip:()=>q,Snapshot:()=>Rn,Text:()=>nn,Transaction:()=>Or,UndoManager:()=>fe,UpdateDecoderV1:()=>st,UpdateDecoderV2:()=>Z,UpdateEncoderV1:()=>kt,UpdateEncoderV2:()=>ct,XmlElement:()=>xe,XmlFragment:()=>we,XmlHook:()=>Bn,XmlText:()=>Pr,YArrayEvent:()=>Nr,YEvent:()=>ge,YMapEvent:()=>Mr,YTextEvent:()=>Vr,YXmlEvent:()=>Br,applyUpdate:()=>so,applyUpdateV2:()=>At,cleanupYTextFormatting:()=>$c,compareIDs:()=>le,compareRelativePositions:()=>Pd,convertUpdateFormatV1ToV2:()=>iu,convertUpdateFormatV2ToV1:()=>bc,createAbsolutePositionFromRelativePosition:()=>Bd,createDeleteSet:()=>jr,createDeleteSetFromStructStore:()=>eo,createDocFromSnapshot:()=>Gd,createID:()=>S,createRelativePositionFromJSON:()=>Id,createRelativePositionFromTypeIndex:()=>Od,createSnapshot:()=>uo,decodeRelativePosition:()=>Md,decodeSnapshot:()=>Fd,decodeSnapshotV2:()=>dc,decodeStateVector:()=>io,decodeUpdate:()=>Zd,decodeUpdateV2:()=>yc,diffUpdate:()=>ru,diffUpdateV2:()=>ho,emptySnapshot:()=>Yd,encodeRelativePosition:()=>Ld,encodeSnapshot:()=>jd,encodeSnapshotV2:()=>ac,encodeStateAsUpdate:()=>oo,encodeStateAsUpdateV2:()=>qt,encodeStateVector:()=>lo,encodeStateVectorFromUpdate:()=>tu,encodeStateVectorFromUpdateV2:()=>xc,equalDeleteSets:()=>oc,equalSnapshots:()=>$d,findIndexSS:()=>dt,findRootTypeKey:()=>ao,getItem:()=>ae,getItemCleanEnd:()=>Ks,getItemCleanStart:()=>W,getState:()=>I,getTypeChildren:()=>du,isDeleted:()=>Ee,isParentOf:()=>On,iterateDeletedStructs:()=>de,logType:()=>Td,logUpdate:()=>Qd,logUpdateV2:()=>mc,mergeDeleteSets:()=>ue,mergeUpdates:()=>wc,mergeUpdatesV2:()=>pe,obfuscateUpdate:()=>su,obfuscateUpdateV2:()=>ou,parseUpdateMeta:()=>eu,parseUpdateMetaV2:()=>Sc,readUpdate:()=>kd,readUpdateV2:()=>ro,relativePositionToJSON:()=>Ud,snapshot:()=>zd,snapshotContainsUpdate:()=>Hd,transact:()=>A,tryGc:()=>Wd,typeListToArraySnapshot:()=>uu,typeMapGetAllSnapshot:()=>Nc,typeMapGetSnapshot:()=>pu});var v=()=>new Map,Wn=e=>{let t=v();return e.forEach((n,r)=>{t.set(r,n)}),t},B=(e,t,n)=>{let r=e.get(t);return r===void 0&&e.set(t,r=n()),r},Jo=(e,t)=>{let n=[];for(let[r,s]of e)n.push(t(s,r));return n},Ko=(e,t)=>{for(let[n,r]of e)if(t(r,n))return!0;return!1};var wt=()=>new Set;var Xn=e=>e[e.length-1];var Wo=(e,t)=>{for(let n=0;n<t.length;n++)e.push(t[n])},ft=Array.from,Qn=(e,t)=>{for(let n=0;n<e.length;n++)if(!t(e[n],n,e))return!1;return!0},hn=(e,t)=>{for(let n=0;n<e.length;n++)if(t(e[n],n,e))return!0;return!1};var Xo=(e,t)=>{let n=new Array(e);for(let r=0;r<e;r++)n[r]=t(r,n);return n};var pt=Array.isArray;var Nt=class{constructor(){this._observers=v()}on(t,n){return B(this._observers,t,wt).add(n),n}once(t,n){let r=(...s)=>{this.off(t,r),n(...s)};this.on(t,r)}off(t,n){let r=this._observers.get(t);r!==void 0&&(r.delete(n),r.size===0&&this._observers.delete(t))}emit(t,n){return ft((this._observers.get(t)||v()).values()).forEach(r=>r(...n))}destroy(){this._observers=v()}},Oe=class{constructor(){this._observers=v()}on(t,n){B(this._observers,t,wt).add(n)}once(t,n){let r=(...s)=>{this.off(t,r),n(...s)};this.on(t,r)}off(t,n){let r=this._observers.get(t);r!==void 0&&(r.delete(n),r.size===0&&this._observers.delete(t))}emit(t,n){return ft((this._observers.get(t)||v()).values()).forEach(r=>r(...n))}destroy(){this._observers=v()}};var F=Math.floor;var te=Math.abs;var Zn=(e,t)=>e<t?e:t,Tt=(e,t)=>e>t?e:t,vh=Number.isNaN;var tr=e=>e!==0?e<0:1/e<0;var Le=Number.MAX_SAFE_INTEGER,os=Number.MIN_SAFE_INTEGER,Oh=1<<31;var Qo=Number.isInteger||(e=>typeof e=="number"&&isFinite(e)&&F(e)===e),Rh=Number.isNaN,Lh=Number.parseInt;var fn=String.fromCharCode,Wl=String.fromCodePoint,Nh=fn(65535),Xl=e=>e.toLowerCase(),Ql=/^\s*/g,Zl=e=>e.replace(Ql,""),ta=/([A-Z])/g,cs=(e,t)=>Zl(e.replace(ta,n=>`${t}${Xl(n)}`));var ea=e=>{let t=unescape(encodeURIComponent(e)),n=t.length,r=new Uint8Array(n);for(let s=0;s<n;s++)r[s]=t.codePointAt(s);return r},Me=typeof TextEncoder<"u"?new TextEncoder:null,na=e=>Me.encode(e),Zo=Me?na:ea;var Ne=typeof TextDecoder>"u"?null:new TextDecoder("utf-8",{fatal:!0,ignoreBOM:!0});Ne&&Ne.decode(new Uint8Array).length===1&&(Ne=null);var er=(e,t)=>Xo(t,()=>e).join("");var ee=class{constructor(){this.cpos=0,this.cbuf=new Uint8Array(100),this.bufs=[]}},gt=()=>new ee;var ra=e=>{let t=e.cpos;for(let n=0;n<e.bufs.length;n++)t+=e.bufs[n].length;return t};var K=e=>{let t=new Uint8Array(ra(e)),n=0;for(let r=0;r<e.bufs.length;r++){let s=e.bufs[r];t.set(s,n),n+=s.length}return t.set(new Uint8Array(e.cbuf.buffer,0,e.cpos),n),t},sa=(e,t)=>{let n=e.cbuf.length;n-e.cpos<t&&(e.bufs.push(new Uint8Array(e.cbuf.buffer,0,e.cpos)),e.cbuf=new Uint8Array(Tt(n,t)*2),e.cpos=0)},P=(e,t)=>{let n=e.cbuf.length;e.cpos===n&&(e.bufs.push(e.cbuf),e.cbuf=new Uint8Array(n*2),e.cpos=0),e.cbuf[e.cpos++]=t};var je=P;var y=(e,t)=>{for(;t>127;)P(e,128|127&t),t=F(t/128);P(e,127&t)},gn=(e,t)=>{let n=tr(t);for(n&&(t=-t),P(e,(t>63?128:0)|(n?64:0)|63&t),t=F(t/64);t>0;)P(e,(t>127?128:0)|127&t),t=F(t/128)},ls=new Uint8Array(3e4),oa=ls.length/3,ia=(e,t)=>{if(t.length<oa){let n=Me.encodeInto(t,ls).written||0;y(e,n);for(let r=0;r<n;r++)P(e,ls[r])}else Y(e,Zo(t))},ca=(e,t)=>{let n=unescape(encodeURIComponent(t)),r=n.length;y(e,r);for(let s=0;s<r;s++)P(e,n.codePointAt(s))},Mt=Me&&Me.encodeInto?ia:ca;var si=(e,t)=>Fe(e,K(t)),Fe=(e,t)=>{let n=e.cbuf.length,r=e.cpos,s=Zn(n-r,t.length),o=t.length-s;e.cbuf.set(t.subarray(0,s),r),e.cpos+=s,o>0&&(e.bufs.push(e.cbuf),e.cbuf=new Uint8Array(Tt(n*2,o)),e.cbuf.set(t.subarray(s)),e.cpos=o)},Y=(e,t)=>{y(e,t.byteLength),Fe(e,t)},as=(e,t)=>{sa(e,t);let n=new DataView(e.cbuf.buffer,e.cpos,t);return e.cpos+=t,n},la=(e,t)=>as(e,4).setFloat32(0,t,!1),aa=(e,t)=>as(e,8).setFloat64(0,t,!1),da=(e,t)=>as(e,8).setBigInt64(0,t,!1);var ei=new DataView(new ArrayBuffer(4)),ua=e=>(ei.setFloat32(0,e),ei.getFloat32(0)===e),Pe=(e,t)=>{switch(typeof t){case"string":P(e,119),Mt(e,t);break;case"number":Qo(t)&&te(t)<=2147483647?(P(e,125),gn(e,t)):ua(t)?(P(e,124),la(e,t)):(P(e,123),aa(e,t));break;case"bigint":P(e,122),da(e,t);break;case"object":if(t===null)P(e,126);else if(pt(t)){P(e,117),y(e,t.length);for(let n=0;n<t.length;n++)Pe(e,t[n])}else if(t instanceof Uint8Array)P(e,116),Y(e,t);else{P(e,118);let n=Object.keys(t);y(e,n.length);for(let r=0;r<n.length;r++){let s=n[r];Mt(e,s),Pe(e,t[s])}}break;case"boolean":P(e,t?120:121);break;default:P(e,127)}},pn=class extends ee{constructor(t){super(),this.w=t,this.s=null,this.count=0}write(t){this.s===t?this.count++:(this.count>0&&y(this,this.count-1),this.count=1,this.w(this,t),this.s=t)}};var ni=e=>{e.count>0&&(gn(e.encoder,e.count===1?e.s:-e.s),e.count>1&&y(e.encoder,e.count-2))},ne=class{constructor(){this.encoder=new ee,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),K(this.encoder)}};var ri=e=>{if(e.count>0){let t=e.diff*2+(e.count===1?0:1);gn(e.encoder,t),e.count>1&&y(e.encoder,e.count-2)}},$e=class{constructor(){this.encoder=new ee,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),K(this.encoder)}},nr=class{constructor(){this.sarr=[],this.s="",this.lensE=new ne}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 ee;return this.sarr.push(this.s),this.s="",Mt(t,this.sarr.join("")),Fe(t,this.lensE.toUint8Array()),K(t)}};var ot=e=>new Error(e),it=()=>{throw ot("Method unimplemented")},$=()=>{throw ot("Unexpected case")};var oi=ot("Unexpected end of array"),ii=ot("Integer out of Range"),Ye=class{constructor(t){this.arr=t,this.pos=0}},N=e=>new Ye(e),hs=e=>e.pos!==e.arr.length;var ha=(e,t)=>{let n=new Uint8Array(e.arr.buffer,e.pos+e.arr.byteOffset,t);return e.pos+=t,n},z=e=>ha(e,_(e));var re=e=>e.arr[e.pos++];var _=e=>{let t=0,n=1,r=e.arr.length;for(;e.pos<r;){let s=e.arr[e.pos++];if(t=t+(s&127)*n,n*=128,s<128)return t;if(t>Le)throw ii}throw oi},yn=e=>{let t=e.arr[e.pos++],n=t&63,r=64,s=(t&64)>0?-1:1;if((t&128)===0)return s*n;let o=e.arr.length;for(;e.pos<o;){if(t=e.arr[e.pos++],n=n+(t&127)*r,r*=128,t<128)return s*n;if(n>Le)throw ii}throw oi};var fa=e=>{let t=_(e);if(t===0)return"";{let n=String.fromCodePoint(re(e));if(--t<100)for(;t--;)n+=String.fromCodePoint(re(e));else for(;t>0;){let r=t<1e4?t:1e4,s=e.arr.subarray(e.pos,e.pos+r);e.pos+=r,n+=String.fromCodePoint.apply(null,s),t-=r}return decodeURIComponent(escape(n))}},pa=e=>Ne.decode(z(e)),Bt=Ne?pa:fa;var fs=(e,t)=>{let n=new DataView(e.arr.buffer,e.arr.byteOffset+e.pos,t);return e.pos+=t,n},ga=e=>fs(e,4).getFloat32(0,!1),ma=e=>fs(e,8).getFloat64(0,!1),ya=e=>fs(e,8).getBigInt64(0,!1);var wa=[e=>{},e=>null,yn,ga,ma,ya,e=>!1,e=>!0,Bt,e=>{let t=_(e),n={};for(let r=0;r<t;r++){let s=Bt(e);n[s]=ze(e)}return n},e=>{let t=_(e),n=[];for(let r=0;r<t;r++)n.push(ze(e));return n},z],ze=e=>wa[127-re(e)](e),mn=class extends Ye{constructor(t,n){super(t),this.reader=n,this.s=null,this.count=0}read(){return this.count===0&&(this.s=this.reader(this),hs(this)?this.count=_(this)+1:this.count=-1),this.count--,this.s}};var se=class extends Ye{constructor(t){super(t),this.s=0,this.count=0}read(){if(this.count===0){this.s=yn(this);let t=tr(this.s);this.count=1,t&&(this.s=-this.s,this.count=_(this)+2)}return this.count--,this.s}};var Ge=class extends Ye{constructor(t){super(t),this.s=0,this.count=0,this.diff=0}read(){if(this.count===0){let t=yn(this),n=t&1;this.diff=F(t/2),this.count=1,n&&(this.count=_(this)+2)}return this.s+=this.diff,this.count--,this.s}},rr=class{constructor(t){this.decoder=new se(t),this.str=Bt(this.decoder),this.spos=0}read(){let t=this.spos+this.decoder.read(),n=this.str.slice(this.spos,t);return this.spos=t,n}};var Bh=crypto.subtle,ci=crypto.getRandomValues.bind(crypto);var gs=()=>ci(new Uint32Array(1))[0];var xa="10000000-1000-4000-8000"+-1e11,li=()=>xa.replace(/[018]/g,e=>(e^gs()&15>>e/4).toString(16));var Pt=Date.now;var ys=e=>new Promise(e);var jh=Promise.all.bind(Promise);var ws=e=>e===void 0?null:e;var xs=class{constructor(){this.map=new Map}setItem(t,n){this.map.set(t,n)}getItem(t){return this.map.get(t)}},ai=new xs,ba=!0;try{typeof localStorage<"u"&&localStorage&&(ai=localStorage,ba=!1)}catch{}var di=ai;var oe=Symbol("Equality"),sr=(e,t)=>e===t||!!e?.[oe]?.(t)||!1;var ui=e=>typeof e=="object",hi=Object.assign,Ca=Object.keys;var fi=(e,t)=>{for(let n in e)t(e[n],n)};var wn=e=>Ca(e).length;var pi=e=>{for(let t in e)return!1;return!0},qe=(e,t)=>{for(let n in e)if(!t(e[n],n))return!1;return!0},xn=(e,t)=>Object.prototype.hasOwnProperty.call(e,t),_s=(e,t)=>e===t||wn(e)===wn(t)&&qe(e,(n,r)=>(n!==void 0||xn(t,r))&&sr(t[r],n)),Aa=Object.freeze,Es=e=>{for(let t in e){let n=e[t];(typeof n=="object"||typeof n=="function")&&Es(e[t])}return Aa(e)};var Sn=(e,t,n=0)=>{try{for(;n<e.length;n++)e[n](...t)}finally{n<e.length&&Sn(e,t,n+1)}};var ks=e=>e;var ie=(e,t)=>{if(e===t)return!0;if(e==null||t==null||e.constructor!==t.constructor&&(e.constructor||Object)!==(t.constructor||Object))return!1;if(e[oe]!=null)return e[oe](t);switch(e.constructor){case ArrayBuffer:e=new Uint8Array(e),t=new Uint8Array(t);case Uint8Array:{if(e.byteLength!==t.byteLength)return!1;for(let n=0;n<e.length;n++)if(e[n]!==t[n])return!1;break}case Set:{if(e.size!==t.size)return!1;for(let n of e)if(!t.has(n))return!1;break}case Map:{if(e.size!==t.size)return!1;for(let n of e.keys())if(!t.has(n)||!ie(e.get(n),t.get(n)))return!1;break}case void 0:case Object:if(wn(e)!==wn(t))return!1;for(let n in e)if(!xn(e,n)||!ie(e[n],t[n]))return!1;break;case Array:if(e.length!==t.length)return!1;for(let n=0;n<e.length;n++)if(!ie(e[n],t[n]))return!1;break;default:return!1}return!0},gi=(e,t)=>t.includes(e);var He=typeof process<"u"&&process.release&&/node|io\.js/.test(process.release.name)&&Object.prototype.toString.call(typeof process<"u"?process:0)==="[object process]",ir=typeof window<"u"&&typeof document<"u"&&!He,Fh=typeof navigator<"u"?/Mac/.test(navigator.platform):!1,xt,Da=[],Ta=()=>{if(xt===void 0)if(He){xt=v();let e=process.argv,t=null;for(let n=0;n<e.length;n++){let r=e[n];r[0]==="-"?(t!==null&&xt.set(t,""),t=r):t!==null?(xt.set(t,r),t=null):Da.push(r)}t!==null&&xt.set(t,"")}else typeof location=="object"?(xt=v(),(location.search||"?").slice(1).split("&").forEach(e=>{if(e.length!==0){let[t,n]=e.split("=");xt.set(`--${cs(t,"-")}`,n),xt.set(`-${cs(t,"-")}`,n)}})):xt=v();return xt},Cs=e=>Ta().has(e);var _n=e=>He?ws(process.env[e.toUpperCase().replaceAll("-","_")]):ws(di.getItem(e));var mi=e=>Cs("--"+e)||_n(e)!==null,yi=mi("production"),Ua=He&&gi(process.env.FORCE_COLOR,["true","1","2"]),wi=Ua||!Cs("--no-colors")&&!mi("no-color")&&(!He||process.stdout.isTTY)&&(!He||Cs("--color")||_n("COLORTERM")!==null||(_n("TERM")||"").includes("color"));var xi=e=>new Uint8Array(e),Ia=(e,t,n)=>new Uint8Array(e,t,n);var va=e=>{let t="";for(let n=0;n<e.byteLength;n++)t+=fn(e[n]);return btoa(t)},Oa=e=>Buffer.from(e.buffer,e.byteOffset,e.byteLength).toString("base64"),Ra=e=>{let t=atob(e),n=xi(t.length);for(let r=0;r<t.length;r++)n[r]=t.charCodeAt(r);return n},La=e=>{let t=Buffer.from(e,"base64");return Ia(t.buffer,t.byteOffset,t.byteLength)},Si=ir?va:Oa,_i=ir?Ra:La;var Ei=e=>{let t=xi(e.byteLength);return t.set(e),t};var As=class{constructor(t,n){this.left=t,this.right=n}},St=(e,t)=>new As(e,t);var Ds=e=>e.next()>=.5,lr=(e,t,n)=>F(e.next()*(n+1-t)+t);var Ts=(e,t,n)=>F(e.next()*(n+1-t)+t);var Us=(e,t,n)=>Ts(e,t,n);var Ma=e=>fn(Us(e,97,122)),ki=(e,t=0,n=20)=>{let r=Us(e,t,n),s="";for(let o=0;o<r;o++)s+=Ma(e);return s};var ar=(e,t)=>t[Us(e,0,t.length-1)];var Ba=Symbol("0schema"),Is=class{constructor(){this._rerrs=[]}extend(t,n,r,s=null){this._rerrs.push({path:t,expected:n,has:r,message:s})}toString(){let t=[];for(let n=this._rerrs.length-1;n>0;n--){let r=this._rerrs[n];t.push(er(" ",(this._rerrs.length-n)*2)+`${r.path!=null?`[${r.path}] `:""}${r.has} doesn't match ${r.expected}. ${r.message}`)}return t.join(`
`)}},vs=(e,t)=>e===t?!0:e==null||t==null||e.constructor!==t.constructor?!1:e[oe]?sr(e,t):pt(e)?Qn(e,n=>hn(t,r=>vs(n,r))):ui(e)?qe(e,(n,r)=>vs(n,t[r])):!1,G=class{static _dilutes=!1;extends(t){let[n,r]=[this.shape,t.shape];return this.constructor._dilutes&&([r,n]=[n,r]),vs(n,r)}equals(t){return this.constructor===t.constructor&&ie(this.shape,t.shape)}[Ba](){return!0}[oe](t){return this.equals(t)}validate(t){return this.check(t)}check(t,n){it()}get nullable(){return Qe(this,_r)}get optional(){return new dr(this)}cast(t){return Ci(t,this),t}expect(t){return Ci(t,this),t}},En=class extends G{constructor(t,n){super(),this.shape=t,this._c=n}check(t,n=void 0){let r=t?.constructor===this.shape&&(this._c==null||this._c(t));return!r&&n?.extend(null,this.shape.name,t?.constructor.name,t?.constructor!==this.shape?"Constructor match failed":"Check failed"),r}},M=(e,t=null)=>new En(e,t),zh=M(En),bn=class extends G{constructor(t){super(),this.shape=t}check(t,n){let r=this.shape(t);return!r&&n?.extend(null,"custom prop",t?.constructor.name,"failed to check custom prop"),r}},V=e=>new bn(e),Gh=M(bn),We=class extends G{constructor(t){super(),this.shape=t}check(t,n){let r=this.shape.some(s=>s===t);return!r&&n?.extend(null,this.shape.join(" | "),t.toString()),r}},xr=(...e)=>new We(e),Ai=M(We),Pa=RegExp.escape||(e=>e.replace(/[().|&,$^[\]]/g,t=>"\\"+t)),Di=e=>{if(Xe.check(e))return[Pa(e)];if(Ai.check(e))return e.shape.map(t=>t+"");if(Oi.check(e))return["[+-]?\\d+.?\\d*"];if(Ri.check(e))return[".*"];if(yr.check(e))return e.shape.map(Di).flat(1);$()},Os=class extends G{constructor(t){super(),this.shape=t,this._r=new RegExp("^"+t.map(Di).map(n=>`(${n.join("|")})`).join("")+"$")}check(t,n){let r=this._r.exec(t)!=null;return!r&&n?.extend(null,this._r.toString(),t.toString(),"String doesn't match string template."),r}};var qh=M(Os),$a=Symbol("optional"),dr=class extends G{constructor(t){super(),this.shape=t}check(t,n){let r=t===void 0||this.shape.check(t);return!r&&n?.extend(null,"undefined (optional)","()"),r}get[$a](){return!0}},ja=M(dr),ur=class extends G{check(t,n){return n?.extend(null,"never",typeof t),!1}},Hh=new ur,Jh=M(ur),hr=class e extends G{constructor(t,n=!1){super(),this.shape=t,this._isPartial=n}static _dilutes=!0;get partial(){return new e(this.shape,!0)}check(t,n){return t==null?(n?.extend(null,"object","null"),!1):qe(this.shape,(r,s)=>{let o=this._isPartial&&!xn(t,s)||r.check(t[s],n);return!o&&n?.extend(s.toString(),r.toString(),typeof t[s],"Object property does not match"),o})}},Fa=e=>new hr(e),Ya=M(hr),za=V(e=>e!=null&&(e.constructor===Object||e.constructor==null)),fr=class extends G{constructor(t,n){super(),this.shape={keys:t,values:n}}check(t,n){return t!=null&&qe(t,(r,s)=>{let o=this.shape.keys.check(s,n);return!o&&n?.extend(s+"","Record",typeof t,o?"Key doesn't match schema":"Value doesn't match value"),o&&this.shape.values.check(r,n)})}},Ti=(e,t)=>new fr(e,t),Ga=M(fr),pr=class extends G{constructor(t){super(),this.shape=t}check(t,n){return t!=null&&qe(this.shape,(r,s)=>{let o=r.check(t[s],n);return!o&&n?.extend(s.toString(),"Tuple",typeof r),o})}},qa=(...e)=>new pr(e),Kh=M(pr),gr=class extends G{constructor(t){super(),this.shape=t.length===1?t[0]:new kn(t)}check(t,n){let r=pt(t)&&Qn(t,s=>this.shape.check(s));return!r&&n?.extend(null,"Array",""),r}},Ui=(...e)=>new gr(e),Ha=M(gr),Ja=V(e=>pt(e)),mr=class extends G{constructor(t,n){super(),this.shape=t,this._c=n}check(t,n){let r=t instanceof this.shape&&(this._c==null||this._c(t));return!r&&n?.extend(null,this.shape.name,t?.constructor.name),r}},Ka=(e,t=null)=>new mr(e,t),Wh=M(mr),Wa=Ka(G),Rs=class extends G{constructor(t){super(),this.len=t.length-1,this.args=qa(...t.slice(-1)),this.res=t[this.len]}check(t,n){let r=t.constructor===Function&&t.length<=this.len;return!r&&n?.extend(null,"function",typeof t),r}};var Xa=M(Rs),Qa=V(e=>typeof e=="function"),Ls=class extends G{constructor(t){super(),this.shape=t}check(t,n){let r=Qn(this.shape,s=>s.check(t,n));return!r&&n?.extend(null,"Intersectinon",typeof t),r}};var Xh=M(Ls,e=>e.shape.length>0),kn=class extends G{static _dilutes=!0;constructor(t){super(),this.shape=t}check(t,n){let r=hn(this.shape,s=>s.check(t,n));return n?.extend(null,"Union",typeof t),r}},Qe=(...e)=>e.findIndex(t=>yr.check(t))>=0?Qe(...e.map(t=>Cn(t)).map(t=>yr.check(t)?t.shape:[t]).flat(1)):e.length===1?e[0]:new kn(e),yr=M(kn),Ii=()=>!0,wr=V(Ii),Za=M(bn,e=>e.shape===Ii),Ms=V(e=>typeof e=="bigint"),td=V(e=>e===Ms),vi=V(e=>typeof e=="symbol"),Qh=V(e=>e===vi),Ke=V(e=>typeof e=="number"),Oi=V(e=>e===Ke),Xe=V(e=>typeof e=="string"),Ri=V(e=>e===Xe),Sr=V(e=>typeof e=="boolean"),ed=V(e=>e===Sr),Li=xr(void 0),Zh=M(We,e=>e.shape.length===1&&e.shape[0]===void 0),tf=xr(void 0);var _r=xr(null),nd=M(We,e=>e.shape.length===1&&e.shape[0]===null),ef=M(Uint8Array),nf=M(En,e=>e.shape===Uint8Array),rd=Qe(Ke,Xe,_r,Li,Ms,Sr,vi),rf=(()=>{let e=Ui(wr),t=Ti(Xe,wr),n=Qe(Ke,Xe,_r,Sr,e,t);return e.shape=n,t.shape.values=n,n})(),Cn=e=>{if(Wa.check(e))return e;if(za.check(e)){let t={};for(let n in e)t[n]=Cn(e[n]);return Fa(t)}else{if(Ja.check(e))return Qe(...e.map(Cn));if(rd.check(e))return xr(e);if(Qa.check(e))return M(e)}$()},Ci=yi?()=>{}:(e,t)=>{let n=new Is;if(!t.check(e,n))throw ot(`Expected value to be of type ${t.constructor.name}.
${n.toString()}`)},Ns=class{constructor(t){this.patterns=[],this.$state=t}if(t,n){return this.patterns.push({if:Cn(t),h:n}),this}else(t){return this.if(wr,t)}done(){return(t,n)=>{for(let r=0;r<this.patterns.length;r++){let s=this.patterns[r];if(s.if.check(t))return s.h(t,n)}throw ot("Unhandled pattern")}}},sd=e=>new Ns(e),Ni=sd(wr).if(Oi,(e,t)=>lr(t,os,Le)).if(Ri,(e,t)=>ki(t)).if(ed,(e,t)=>Ds(t)).if(td,(e,t)=>BigInt(lr(t,os,Le))).if(yr,(e,t)=>Je(t,ar(t,e.shape))).if(Ya,(e,t)=>{let n={};for(let r in e.shape){let s=e.shape[r];if(ja.check(s)){if(Ds(t))continue;s=s.shape}n[r]=Ni(s,t)}return n}).if(Ha,(e,t)=>{let n=[],r=Ts(t,0,42);for(let s=0;s<r;s++)n.push(Je(t,e.shape));return n}).if(Ai,(e,t)=>ar(t,e.shape)).if(nd,(e,t)=>null).if(Xa,(e,t)=>{let n=Je(t,e.res);return()=>n}).if(Za,(e,t)=>Je(t,ar(t,[Ke,Xe,_r,Li,Ms,Sr,Ui(Ke),Ti(Qe("a","b","c"),Ke)]))).if(Ga,(e,t)=>{let n={},r=lr(t,0,3);for(let s=0;s<r;s++){let o=Je(t,e.shape.keys),i=Je(t,e.shape.values);n[o]=i}return n}).done(),Je=(e,t)=>Ni(Cn(t),e);var ce=typeof document<"u"?document:{};var sf=V(e=>e.nodeType===ad);var of=typeof DOMParser<"u"?new DOMParser:null;var cf=V(e=>e.nodeType===id);var lf=V(e=>e.nodeType===cd);var Mi=e=>Jo(e,(t,n)=>`${n}:${t};`).join("");var id=ce.ELEMENT_NODE,cd=ce.TEXT_NODE,af=ce.CDATA_SECTION_NODE,df=ce.COMMENT_NODE,ld=ce.DOCUMENT_NODE,uf=ce.DOCUMENT_TYPE_NODE,ad=ce.DOCUMENT_FRAGMENT_NODE,hf=V(e=>e.nodeType===ld);var _t=Symbol;var An=_t(),Dn=_t(),Vs=_t(),Bs=_t(),Ps=_t(),Tn=_t(),$s=_t(),Ze=_t(),js=_t(),Vi=e=>{e.length===1&&e[0]?.constructor===Function&&(e=e[0]());let t=[],n=[],r=0;for(;r<e.length;r++){let s=e[r];if(s===void 0)break;if(s.constructor===String||s.constructor===Number)t.push(s);else if(s.constructor===Object)break}for(r>0&&n.push(t.join(""));r<e.length;r++){let s=e[r];s instanceof Symbol||n.push(s)}return n};var ff=Pt();var fd={[An]:St("font-weight","bold"),[Dn]:St("font-weight","normal"),[Vs]:St("color","blue"),[Ps]:St("color","green"),[Bs]:St("color","grey"),[Tn]:St("color","red"),[$s]:St("color","purple"),[Ze]:St("color","orange"),[js]:St("color","black")},pd=e=>{e.length===1&&e[0]?.constructor===Function&&(e=e[0]());let t=[],n=[],r=v(),s=[],o=0;for(;o<e.length;o++){let i=e[o],c=fd[i];if(c!==void 0)r.set(c.left,c.right);else{if(i===void 0)break;if(i.constructor===String||i.constructor===Number){let l=Mi(r);o>0||l.length>0?(t.push("%c"+i),n.push(l)):t.push(i)}else break}}for(o>0&&(s=n,s.unshift(t.join("")));o<e.length;o++){let i=e[o];i instanceof Symbol||s.push(i)}return s},Bi=wi?pd:Vi,Er=(...e)=>{console.log(...Bi(e)),Pi.forEach(t=>t.print(e))},Fs=(...e)=>{console.warn(...Bi(e)),e.unshift(Ze),Pi.forEach(t=>t.print(e))};var Pi=wt();var $i=e=>({[Symbol.iterator](){return this},next:e}),ji=(e,t)=>$i(()=>{let n;do n=e.next();while(!n.done&&!t(n.value));return n}),br=(e,t)=>$i(()=>{let{done:n,value:r}=e.next();return{done:n,value:n?void 0:t(r)}});var zs=class extends Nt{constructor(t,n){super(),this.doc=t,this.awareness=n}},In=class{constructor(t,n){this.clock=t,this.len=n}},Yt=class{constructor(){this.clients=new Map}},de=(e,t,n)=>t.clients.forEach((r,s)=>{let o=e.doc.store.clients.get(s);if(o!=null){let i=o[o.length-1],c=i.id.clock+i.length;for(let l=0,a=r[l];l<r.length&&a.clock<c;a=r[++l])hc(e,o,a.clock,a.len,n)}}),xd=(e,t)=>{let n=0,r=e.length-1;for(;n<=r;){let s=F((n+r)/2),o=e[s],i=o.clock;if(i<=t){if(t<i+o.len)return s;n=s+1}else r=s-1}return null},Ee=(e,t)=>{let n=e.clients.get(t.client);return n!==void 0&&xd(n,t.clock)!==null},to=e=>{e.clients.forEach(t=>{t.sort((s,o)=>s.clock-o.clock);let n,r;for(n=1,r=1;n<t.length;n++){let s=t[r-1],o=t[n];s.clock+s.len>=o.clock?s.len=Tt(s.len,o.clock+o.len-s.clock):(r<n&&(t[r]=o),r++)}t.length=r})},ue=e=>{let t=new Yt;for(let n=0;n<e.length;n++)e[n].clients.forEach((r,s)=>{if(!t.clients.has(s)){let o=r.slice();for(let i=n+1;i<e.length;i++)Wo(o,e[i].clients.get(s)||[]);t.clients.set(s,o)}});return to(t),t},vn=(e,t,n,r)=>{B(e.clients,t,()=>[]).push(new In(n,r))},jr=()=>new Yt,eo=e=>{let t=jr();return e.clients.forEach((n,r)=>{let s=[];for(let o=0;o<n.length;o++){let i=n[o];if(i.deleted){let c=i.id.clock,l=i.length;if(o+1<n.length)for(let a=n[o+1];o+1<n.length&&a.deleted;a=n[++o+1])l+=a.length;s.push(new In(c,l))}}s.length>0&&t.clients.set(r,s)}),t},Et=(e,t)=>{y(e.restEncoder,t.clients.size),ft(t.clients.entries()).sort((n,r)=>r[0]-n[0]).forEach(([n,r])=>{e.resetDsCurVal(),y(e.restEncoder,n);let s=r.length;y(e.restEncoder,s);for(let o=0;o<s;o++){let i=r[o];e.writeDsClock(i.clock),e.writeDsLen(i.len)}})},It=e=>{let t=new Yt,n=_(e.restDecoder);for(let r=0;r<n;r++){e.resetDsCurVal();let s=_(e.restDecoder),o=_(e.restDecoder);if(o>0){let i=B(t.clients,s,()=>[]);for(let c=0;c<o;c++)i.push(new In(e.readDsClock(),e.readDsLen()))}}return t},zi=(e,t,n)=>{let r=new Yt,s=_(e.restDecoder);for(let o=0;o<s;o++){e.resetDsCurVal();let i=_(e.restDecoder),c=_(e.restDecoder),l=n.clients.get(i)||[],a=I(n,i);for(let d=0;d<c;d++){let u=e.readDsClock(),h=u+e.readDsLen();if(u<a){a<h&&vn(r,i,a,h-a);let f=dt(l,u),p=l[f];for(!p.deleted&&p.id.clock<u&&(l.splice(f+1,0,$r(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,$r(t,p,h-p.id.clock)),p.delete(t))}else vn(r,i,u,h-u)}}if(r.clients.size>0){let o=new ct;return y(o.restEncoder,0),Et(o,r),o.toUint8Array()}return null},oc=(e,t)=>{if(e.clients.size!==t.clients.size)return!1;for(let[n,r]of e.clients.entries()){let s=t.clients.get(n);if(s===void 0||r.length!==s.length)return!1;for(let o=0;o<r.length;o++){let i=r[o],c=s[o];if(i.clock!==c.clock||i.len!==c.len)return!1}}return!0},ic=gs,bt=class e extends Nt{constructor({guid:t=li(),collectionid:n=null,gc:r=!0,gcFilter:s=()=>!0,meta:o=null,autoLoad:i=!1,shouldLoad:c=!0}={}){super(),this.gc=r,this.gcFilter=s,this.clientID=ic(),this.guid=t,this.collectionid=n,this.share=new Map,this.store=new vr,this._transaction=null,this._transactionCleanups=[],this.subdocs=new Set,this._item=null,this.shouldLoad=c,this.autoLoad=i,this.meta=o,this.isLoaded=!1,this.isSynced=!1,this.isDestroyed=!1,this.whenLoaded=ys(a=>{this.on("load",()=>{this.isLoaded=!0,a(this)})});let l=()=>ys(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&&A(t.parent.doc,n=>{n.subdocsLoaded.add(this)},null,!0),this.shouldLoad=!0}getSubdocs(){return this.subdocs}getSubdocGuids(){return new Set(ft(this.subdocs).map(t=>t.guid))}transact(t,n=null){return A(this,t,n)}get(t,n=R){let r=B(this.share,t,()=>{let o=new n;return o._integrate(this,null),o}),s=r.constructor;if(n!==R&&s!==n)if(s===R){let o=new n;o._map=r._map,r._map.forEach(i=>{for(;i!==null;i=i.left)i.parent=o}),o._start=r._start;for(let i=o._start;i!==null;i=i.right)i.parent=o;return o._length=r._length,this.share.set(t,o),o._integrate(this,null),o}else throw new Error(`Type with the name ${t} has already been defined with a different constructor`);return r}getArray(t=""){return this.get(t,me)}getText(t=""){return this.get(t,nn)}getMap(t=""){return this.get(t,ye)}getXmlElement(t=""){return this.get(t,xe)}getXmlFragment(t=""){return this.get(t,we)}toJSON(){let t={};return this.share.forEach((n,r)=>{t[r]=n.toJSON()}),t}destroy(){this.isDestroyed=!0,ft(this.subdocs).forEach(n=>n.destroy());let t=this._item;if(t!==null){this._item=null;let n=t.content;n.doc=new e({guid:this.guid,...n.opts,shouldLoad:!1}),n.doc._item=t,A(t.parent.doc,r=>{let s=n.doc;t.deleted||r.subdocsAdded.add(s),r.subdocsRemoved.add(this)},null,!0)}this.emit("destroyed",[!0]),this.emit("destroy",[this]),super.destroy()}},he=class{constructor(t){this.restDecoder=t}resetDsCurVal(){}readDsClock(){return _(this.restDecoder)}readDsLen(){return _(this.restDecoder)}},st=class extends he{readLeftID(){return S(_(this.restDecoder),_(this.restDecoder))}readRightID(){return S(_(this.restDecoder),_(this.restDecoder))}readClient(){return _(this.restDecoder)}readInfo(){return re(this.restDecoder)}readString(){return Bt(this.restDecoder)}readParentInfo(){return _(this.restDecoder)===1}readTypeRef(){return _(this.restDecoder)}readLen(){return _(this.restDecoder)}readAny(){return ze(this.restDecoder)}readBuf(){return Ei(z(this.restDecoder))}readJSON(){return JSON.parse(Bt(this.restDecoder))}readKey(){return Bt(this.restDecoder)}},Ur=class{constructor(t){this.dsCurrVal=0,this.restDecoder=t}resetDsCurVal(){this.dsCurrVal=0}readDsClock(){return this.dsCurrVal+=_(this.restDecoder),this.dsCurrVal}readDsLen(){let t=_(this.restDecoder)+1;return this.dsCurrVal+=t,t}},Z=class extends Ur{constructor(t){super(t),this.keys=[],_(t),this.keyClockDecoder=new Ge(z(t)),this.clientDecoder=new se(z(t)),this.leftClockDecoder=new Ge(z(t)),this.rightClockDecoder=new Ge(z(t)),this.infoDecoder=new mn(z(t),re),this.stringDecoder=new rr(z(t)),this.parentInfoDecoder=new mn(z(t),re),this.typeRefDecoder=new se(z(t)),this.lenDecoder=new se(z(t))}readLeftID(){return new Ut(this.clientDecoder.read(),this.leftClockDecoder.read())}readRightID(){return new Ut(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 ze(this.restDecoder)}readBuf(){return z(this.restDecoder)}readJSON(){return ze(this.restDecoder)}readKey(){let t=this.keyClockDecoder.read();if(t<this.keys.length)return this.keys[t];{let n=this.stringDecoder.read();return this.keys.push(n),n}}},zt=class{constructor(){this.restEncoder=gt()}toUint8Array(){return K(this.restEncoder)}resetDsCurVal(){}writeDsClock(t){y(this.restEncoder,t)}writeDsLen(t){y(this.restEncoder,t)}},kt=class extends zt{writeLeftID(t){y(this.restEncoder,t.client),y(this.restEncoder,t.clock)}writeRightID(t){y(this.restEncoder,t.client),y(this.restEncoder,t.clock)}writeClient(t){y(this.restEncoder,t)}writeInfo(t){je(this.restEncoder,t)}writeString(t){Mt(this.restEncoder,t)}writeParentInfo(t){y(this.restEncoder,t?1:0)}writeTypeRef(t){y(this.restEncoder,t)}writeLen(t){y(this.restEncoder,t)}writeAny(t){Pe(this.restEncoder,t)}writeBuf(t){Y(this.restEncoder,t)}writeJSON(t){Mt(this.restEncoder,JSON.stringify(t))}writeKey(t){Mt(this.restEncoder,t)}},tn=class{constructor(){this.restEncoder=gt(),this.dsCurrVal=0}toUint8Array(){return K(this.restEncoder)}resetDsCurVal(){this.dsCurrVal=0}writeDsClock(t){let n=t-this.dsCurrVal;this.dsCurrVal=t,y(this.restEncoder,n)}writeDsLen(t){t===0&&$(),y(this.restEncoder,t-1),this.dsCurrVal+=t}},ct=class extends tn{constructor(){super(),this.keyMap=new Map,this.keyClock=0,this.keyClockEncoder=new $e,this.clientEncoder=new ne,this.leftClockEncoder=new $e,this.rightClockEncoder=new $e,this.infoEncoder=new pn(je),this.stringEncoder=new nr,this.parentInfoEncoder=new pn(je),this.typeRefEncoder=new ne,this.lenEncoder=new ne}toUint8Array(){let t=gt();return y(t,0),Y(t,this.keyClockEncoder.toUint8Array()),Y(t,this.clientEncoder.toUint8Array()),Y(t,this.leftClockEncoder.toUint8Array()),Y(t,this.rightClockEncoder.toUint8Array()),Y(t,K(this.infoEncoder)),Y(t,this.stringEncoder.toUint8Array()),Y(t,K(this.parentInfoEncoder)),Y(t,this.typeRefEncoder.toUint8Array()),Y(t,this.lenEncoder.toUint8Array()),Fe(t,K(this.restEncoder)),K(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){Pe(this.restEncoder,t)}writeBuf(t){Y(this.restEncoder,t)}writeJSON(t){Pe(this.restEncoder,t)}writeKey(t){let n=this.keyMap.get(t);n===void 0?(this.keyClockEncoder.write(this.keyClock++),this.stringEncoder.write(t)):this.keyClockEncoder.write(n)}},Sd=(e,t,n,r)=>{r=Tt(r,t[0].id.clock);let s=dt(t,r);y(e.restEncoder,t.length-s),e.writeClient(n),y(e.restEncoder,r);let o=t[s];o.write(e,r-o.id.clock);for(let i=s+1;i<t.length;i++)t[i].write(e,0)},no=(e,t,n)=>{let r=new Map;n.forEach((s,o)=>{I(t,o)>s&&r.set(o,s)}),$n(t).forEach((s,o)=>{n.has(o)||r.set(o,0)}),y(e.restEncoder,r.size),ft(r.entries()).sort((s,o)=>o[0]-s[0]).forEach(([s,o])=>{Sd(e,t.clients.get(s),s,o)})},_d=(e,t)=>{let n=v(),r=_(e.restDecoder);for(let s=0;s<r;s++){let o=_(e.restDecoder),i=new Array(o),c=e.readClient(),l=_(e.restDecoder);n.set(c,{i:0,refs:i});for(let a=0;a<o;a++){let d=e.readInfo();switch(31&d){case 0:{let u=e.readLen();i[a]=new X(S(c,l),u),l+=u;break}case 10:{let u=_(e.restDecoder);i[a]=new q(S(c,l),u),l+=u;break}default:{let u=(d&192)===0,h=new D(S(c,l),null,(d&128)===128?e.readLeftID():null,null,(d&64)===64?e.readRightID():null,u?e.readParentInfo()?t.get(e.readString()):e.readLeftID():null,u&&(d&32)===32?e.readString():null,Yc(e,d));i[a]=h,l+=h.length}}}}return n},Ed=(e,t,n)=>{let r=[],s=ft(n.keys()).sort((f,p)=>f-p);if(s.length===0)return null;let o=()=>{if(s.length===0)return null;let f=n.get(s[s.length-1]);for(;f.refs.length===f.i;)if(s.pop(),s.length>0)f=n.get(s[s.length-1]);else return null;return f},i=o();if(i===null)return null;let c=new vr,l=new Map,a=(f,p)=>{let m=l.get(f);(m==null||m>p)&&l.set(f,p)},d=i.refs[i.i++],u=new Map,h=()=>{for(let f of r){let p=f.id.client,m=n.get(p);m?(m.i--,c.clients.set(p,m.refs.slice(m.i)),n.delete(p),m.i=0,m.refs=[]):c.clients.set(p,[f]),s=s.filter(E=>E!==p)}r.length=0};for(;;){if(d.constructor!==q){let p=B(u,d.id.client,()=>I(t,d.id.client))-d.id.clock;if(p<0)r.push(d),a(d.id.client,d.id.clock-1),h();else{let m=d.getMissing(e,t);if(m!==null){r.push(d);let E=n.get(m)||{refs:[],i:0};if(E.refs.length===E.i)a(m,I(t,m)),h();else{d=E.refs[E.i++];continue}}else(p===0||p<d.length)&&(d.integrate(e,p),u.set(d.id.client,d.id.clock+d.length))}}if(r.length>0)d=r.pop();else if(i!==null&&i.i<i.refs.length)d=i.refs[i.i++];else{if(i=o(),i===null)break;d=i.refs[i.i++]}}if(c.clients.size>0){let f=new ct;return no(f,c,new Map),y(f.restEncoder,0),{missing:l,update:f.toUint8Array()}}return null},bd=(e,t)=>no(e,t.doc.store,t.beforeState),ro=(e,t,n,r=new Z(e))=>A(t,s=>{s.local=!1;let o=!1,i=s.doc,c=i.store,l=_d(r,i),a=Ed(s,c,l),d=c.pendingStructs;if(d){for(let[h,f]of d.missing)if(f<I(c,h)){o=!0;break}if(a){for(let[h,f]of a.missing){let p=d.missing.get(h);(p==null||p>f)&&d.missing.set(h,f)}d.update=pe([d.update,a.update])}}else c.pendingStructs=a;let u=zi(r,s,c);if(c.pendingDs){let h=new Z(N(c.pendingDs));_(h.restDecoder);let f=zi(h,s,c);u&&f?c.pendingDs=pe([u,f]):c.pendingDs=u||f}else c.pendingDs=u;if(o){let h=c.pendingStructs.update;c.pendingStructs=null,At(s.doc,h)}},n,!1),kd=(e,t,n)=>ro(e,t,n,new st(e)),At=(e,t,n,r=Z)=>{let s=N(t);ro(s,e,n,new r(s))},so=(e,t,n)=>At(e,t,n,st),Cd=(e,t,n=new Map)=>{no(e,t.store,n),Et(e,eo(t.store))},qt=(e,t=new Uint8Array([0]),n=new ct)=>{let r=io(t);Cd(n,e,r);let s=[n.toUint8Array()];if(e.store.pendingDs&&s.push(e.store.pendingDs),e.store.pendingStructs&&s.push(ho(e.store.pendingStructs.update,t)),s.length>1){if(n.constructor===kt)return wc(s.map((o,i)=>i===0?o:bc(o)));if(n.constructor===ct)return pe(s)}return s[0]},oo=(e,t)=>qt(e,t,new kt),cc=e=>{let t=new Map,n=_(e.restDecoder);for(let r=0;r<n;r++){let s=_(e.restDecoder),o=_(e.restDecoder);t.set(s,o)}return t},io=e=>cc(new he(N(e))),co=(e,t)=>(y(e.restEncoder,t.size),ft(t.entries()).sort((n,r)=>r[0]-n[0]).forEach(([n,r])=>{y(e.restEncoder,n),y(e.restEncoder,r)}),e),Ad=(e,t)=>co(e,$n(t.store)),Dd=(e,t=new tn)=>(e instanceof Map?co(t,e):Ad(t,e),t.toUint8Array()),lo=e=>Dd(e,new zt),Gs=class{constructor(){this.l=[]}},Gi=()=>new Gs,qi=(e,t)=>e.l.push(t),Hi=(e,t)=>{let n=e.l,r=n.length;e.l=n.filter(s=>t!==s),r===e.l.length&&console.error("[yjs] Tried to remove event handler that doesn't exist.")},lc=(e,t,n)=>Sn(e.l,[t,n]),Ut=class{constructor(t,n){this.client=t,this.clock=n}},le=(e,t)=>e===t||e!==null&&t!==null&&e.client===t.client&&e.clock===t.clock,S=(e,t)=>new Ut(e,t),Ji=(e,t)=>{y(e,t.client),y(e,t.clock)},Ki=e=>S(_(e),_(e)),ao=e=>{for(let[t,n]of e.doc.share.entries())if(n===e)return t;throw $()},On=(e,t)=>{for(;t!==null;){if(t.parent===e)return!0;t=t.parent._item}return!1},Td=e=>{let t=[],n=e._start;for(;n;)t.push(n),n=n.right;console.log("Children: ",t),console.log("Children content: ",t.filter(r=>!r.deleted).map(r=>r.content))},qs=class{constructor(t,n=t.getMap("users")){let r=new Map;this.yusers=n,this.doc=t,this.clients=new Map,this.dss=r;let s=(o,i)=>{let c=o.get("ds"),l=o.get("ids"),a=d=>this.clients.set(d,i);c.observe(d=>{d.changes.added.forEach(u=>{u.content.getContent().forEach(h=>{h instanceof Uint8Array&&this.dss.set(i,ue([this.dss.get(i)||jr(),It(new he(N(h)))]))})})}),this.dss.set(i,ue(c.map(d=>It(new he(N(d)))))),l.observe(d=>d.changes.added.forEach(u=>u.content.getContent().forEach(a))),l.forEach(a)};n.observe(o=>{o.keysChanged.forEach(i=>s(n.get(i),i))}),n.forEach(s)}setUserMapping(t,n,r,{filter:s=()=>!0}={}){let o=this.yusers,i=o.get(r);i||(i=new ye,i.set("ids",new me),i.set("ds",new me),o.set(r,i)),i.get("ids").push([n]),o.observe(c=>{setTimeout(()=>{let l=o.get(r);if(l!==i){i=l,this.clients.forEach((u,h)=>{r===u&&i.get("ids").push([h])});let a=new zt,d=this.dss.get(r);d&&(Et(a,d),i.get("ds").push([a.toUint8Array()]))}},0)}),t.on("afterTransaction",c=>{setTimeout(()=>{let l=i.get("ds"),a=c.deleteSet;if(c.local&&a.clients.size>0&&s(c,a)){let d=new zt;Et(d,a),l.push([d.toUint8Array()])}})})}getUserByClientId(t){return this.clients.get(t)||null}getUserByDeletedId(t){for(let[n,r]of this.dss.entries())if(Ee(r,t))return n;return null}},en=class{constructor(t,n,r,s=0){this.type=t,this.tname=n,this.item=r,this.assoc=s}},Ud=e=>{let t={};return e.type&&(t.type=e.type),e.tname&&(t.tname=e.tname),e.item&&(t.item=e.item),e.assoc!=null&&(t.assoc=e.assoc),t},Id=e=>new en(e.type==null?null:S(e.type.client,e.type.clock),e.tname??null,e.item==null?null:S(e.item.client,e.item.clock),e.assoc==null?0:e.assoc),Ir=class{constructor(t,n,r=0){this.type=t,this.index=n,this.assoc=r}},vd=(e,t,n=0)=>new Ir(e,t,n),kr=(e,t,n)=>{let r=null,s=null;return e._item===null?s=ao(e):r=S(e._item.id.client,e._item.id.clock),new en(r,s,t,n)},Od=(e,t,n=0)=>{let r=e._start;if(n<0){if(t===0)return kr(e,null,n);t--}for(;r!==null;){if(!r.deleted&&r.countable){if(r.length>t)return kr(e,S(r.id.client,r.id.clock+t),n);t-=r.length}if(r.right===null&&n<0)return kr(e,r.lastId,n);r=r.right}return kr(e,null,n)},Rd=(e,t)=>{let{type:n,tname:r,item:s,assoc:o}=t;if(s!==null)y(e,0),Ji(e,s);else if(r!==null)je(e,1),Mt(e,r);else if(n!==null)je(e,2),Ji(e,n);else throw $();return gn(e,o),e},Ld=e=>{let t=gt();return Rd(t,e),K(t)},Nd=e=>{let t=null,n=null,r=null;switch(_(e)){case 0:r=Ki(e);break;case 1:n=Bt(e);break;case 2:t=Ki(e)}let s=hs(e)?yn(e):0;return new en(t,n,r,s)},Md=e=>Nd(N(e)),Vd=(e,t)=>{let n=ae(e,t),r=t.clock-n.id.clock;return{item:n,diff:r}},Bd=(e,t,n=!0)=>{let r=t.store,s=e.item,o=e.type,i=e.tname,c=e.assoc,l=null,a=0;if(s!==null){if(I(r,s.client)<=s.clock)return null;let d=n?Qs(r,s):Vd(r,s),u=d.item;if(!(u instanceof D))return null;if(l=u.parent,l._item===null||!l._item.deleted){a=u.deleted||!u.countable?0:d.diff+(c>=0?0:1);let h=u.left;for(;h!==null;)!h.deleted&&h.countable&&(a+=h.length),h=h.left}}else{if(i!==null)l=t.get(i);else if(o!==null){if(I(r,o.client)<=o.clock)return null;let{item:d}=n?Qs(r,o):{item:ae(r,o)};if(d instanceof D&&d.content instanceof ut)l=d.content.type;else return null}else throw $();c>=0?a=l._length:a=0}return vd(l,a,e.assoc)},Pd=(e,t)=>e===t||e!==null&&t!==null&&e.tname===t.tname&&le(e.item,t.item)&&le(e.type,t.type)&&e.assoc===t.assoc,Rn=class{constructor(t,n){this.ds=t,this.sv=n}},$d=(e,t)=>{let n=e.ds.clients,r=t.ds.clients,s=e.sv,o=t.sv;if(s.size!==o.size||n.size!==r.size)return!1;for(let[i,c]of s.entries())if(o.get(i)!==c)return!1;for(let[i,c]of n.entries()){let l=r.get(i)||[];if(c.length!==l.length)return!1;for(let a=0;a<c.length;a++){let d=c[a],u=l[a];if(d.clock!==u.clock||d.len!==u.len)return!1}}return!0},ac=(e,t=new tn)=>(Et(t,e.ds),co(t,e.sv),t.toUint8Array()),jd=e=>ac(e,new zt),dc=(e,t=new Ur(N(e)))=>new Rn(It(t),cc(t)),Fd=e=>dc(e,new he(N(e))),uo=(e,t)=>new Rn(e,t),Yd=uo(jr(),new Map),zd=e=>uo(eo(e.store),$n(e.store)),$t=(e,t)=>t===void 0?!e.deleted:t.sv.has(e.id.client)&&(t.sv.get(e.id.client)||0)>e.id.clock&&!Ee(t.ds,e.id),Hs=(e,t)=>{let n=B(e.meta,Hs,wt),r=e.doc.store;n.has(t)||(t.sv.forEach((s,o)=>{s<I(r,o)&&W(e,S(o,s))}),de(e,t.ds,s=>{}),n.add(t))},Gd=(e,t,n=new bt)=>{if(e.gc)throw new Error("Garbage-collection must be disabled in `originDoc`!");let{sv:r,ds:s}=t,o=new ct;return e.transact(i=>{let c=0;r.forEach(l=>{l>0&&c++}),y(o.restEncoder,c);for(let[l,a]of r){if(a===0)continue;a<I(e.store,l)&&W(i,S(l,a));let d=e.store.clients.get(l)||[],u=dt(d,a-1);y(o.restEncoder,u+1),o.writeClient(l),y(o.restEncoder,0);for(let h=0;h<=u;h++)d[h].write(o,0)}Et(o,s)}),At(n,o.toUint8Array(),"snapshot"),n},qd=(e,t,n=Z)=>{let r=new n(N(t)),s=new Ct(r,!1);for(let i=s.curr;i!==null;i=s.next())if((e.sv.get(i.id.client)||0)<i.id.clock+i.length)return!1;let o=ue([e.ds,It(r)]);return oc(e.ds,o)},Hd=(e,t)=>qd(e,t,st),vr=class{constructor(){this.clients=new Map,this.pendingStructs=null,this.pendingDs=null}},$n=e=>{let t=new Map;return e.clients.forEach((n,r)=>{let s=n[n.length-1];t.set(r,s.id.clock+s.length)}),t},I=(e,t)=>{let n=e.clients.get(t);if(n===void 0)return 0;let r=n[n.length-1];return r.id.clock+r.length},uc=(e,t)=>{let n=e.clients.get(t.id.client);if(n===void 0)n=[],e.clients.set(t.id.client,n);else{let r=n[n.length-1];if(r.id.clock+r.length!==t.id.clock)throw $()}n.push(t)},dt=(e,t)=>{let n=0,r=e.length-1,s=e[r],o=s.id.clock;if(o===t)return r;let i=F(t/(o+s.length-1)*r);for(;n<=r;){if(s=e[i],o=s.id.clock,o<=t){if(t<o+s.length)return i;n=i+1}else r=i-1;i=F((n+r)/2)}throw $()},Jd=(e,t)=>{let n=e.clients.get(t.client);return n[dt(n,t.clock)]},ae=Jd,Js=(e,t,n)=>{let r=dt(t,n),s=t[r];return s.id.clock<n&&s instanceof D?(t.splice(r+1,0,$r(e,s,n-s.id.clock)),r+1):r},W=(e,t)=>{let n=e.doc.store.clients.get(t.client);return n[Js(e,n,t.clock)]},Ks=(e,t,n)=>{let r=t.clients.get(n.client),s=dt(r,n.clock),o=r[s];return n.clock!==o.id.clock+o.length-1&&o.constructor!==X&&r.splice(s+1,0,$r(e,o,n.clock-o.id.clock+1)),o},Kd=(e,t,n)=>{let r=e.clients.get(t.id.client);r[dt(r,t.id.clock)]=n},hc=(e,t,n,r,s)=>{if(r===0)return;let o=n+r,i=Js(e,t,n),c;do c=t[i++],o<c.id.clock+c.length&&Js(e,t,o),s(c);while(i<t.length&&t[i].id.clock<o)},Or=class{constructor(t,n,r){this.doc=t,this.deleteSet=new Yt,this.beforeState=$n(t.store),this.afterState=new Map,this.changed=new Map,this.changedParentTypes=new Map,this._mergeStructs=[],this.origin=n,this.meta=new Map,this.local=r,this.subdocsAdded=new Set,this.subdocsRemoved=new Set,this.subdocsLoaded=new Set,this._needFormattingCleanup=!1}},Wi=(e,t)=>t.deleteSet.clients.size===0&&!Ko(t.afterState,(n,r)=>t.beforeState.get(r)!==n)?!1:(to(t.deleteSet),bd(e,t),Et(e,t.deleteSet),!0),Xi=(e,t,n)=>{let r=t._item;(r===null||r.id.clock<(e.beforeState.get(r.id.client)||0)&&!r.deleted)&&B(e.changed,t,wt).add(n)},Dr=(e,t)=>{let n=e[t],r=e[t-1],s=t;for(;s>0;n=r,r=e[--s-1]){if(r.deleted===n.deleted&&r.constructor===n.constructor&&r.mergeWith(n)){n instanceof D&&n.parentSub!==null&&n.parent._map.get(n.parentSub)===n&&n.parent._map.set(n.parentSub,r);continue}break}let o=t-s;return o&&e.splice(t+1-o,o),o},fc=(e,t,n)=>{for(let[r,s]of e.clients.entries()){let o=t.clients.get(r);for(let i=s.length-1;i>=0;i--){let c=s[i],l=c.clock+c.len;for(let a=dt(o,c.clock),d=o[a];a<o.length&&d.id.clock<l;d=o[++a]){let u=o[a];if(c.clock+c.len<=u.id.clock)break;u instanceof D&&u.deleted&&!u.keep&&n(u)&&u.gc(t,!1)}}}},pc=(e,t)=>{e.clients.forEach((n,r)=>{let s=t.clients.get(r);for(let o=n.length-1;o>=0;o--){let i=n[o],c=Zn(s.length-1,1+dt(s,i.clock+i.len-1));for(let l=c,a=s[l];l>0&&a.id.clock>=i.clock;a=s[l])l-=1+Dr(s,l)}})},Wd=(e,t,n)=>{fc(e,t,n),pc(e,t)},gc=(e,t)=>{if(t<e.length){let n=e[t],r=n.doc,s=r.store,o=n.deleteSet,i=n._mergeStructs;try{to(o),n.afterState=$n(n.doc.store),r.emit("beforeObserverCalls",[n,r]);let c=[];n.changed.forEach((l,a)=>c.push(()=>{(a._item===null||!a._item.deleted)&&a._callObserver(n,l)})),c.push(()=>{n.changedParentTypes.forEach((l,a)=>{a._dEH.l.length>0&&(a._item===null||!a._item.deleted)&&(l=l.filter(d=>d.target._item===null||!d.target._item.deleted),l.forEach(d=>{d.currentTarget=a,d._path=null}),l.sort((d,u)=>d.path.length-u.path.length),c.push(()=>{lc(a._dEH,l,n)}))}),c.push(()=>r.emit("afterTransaction",[n,r])),c.push(()=>{n._needFormattingCleanup&&wu(n)})}),Sn(c,[])}finally{r.gc&&fc(o,s,r.gcFilter),pc(o,s),n.afterState.forEach((d,u)=>{let h=n.beforeState.get(u)||0;if(h!==d){let f=s.clients.get(u),p=Tt(dt(f,h),1);for(let m=f.length-1;m>=p;)m-=1+Dr(f,m)}});for(let d=i.length-1;d>=0;d--){let{client:u,clock:h}=i[d].id,f=s.clients.get(u),p=dt(f,h);p+1<f.length&&Dr(f,p+1)>1||p>0&&Dr(f,p)}if(!n.local&&n.afterState.get(r.clientID)!==n.beforeState.get(r.clientID)&&(Er(Ze,An,"[yjs] ",Dn,Tn,"Changed the client-id because another client seems to be using it."),r.clientID=ic()),r.emit("afterTransactionCleanup",[n,r]),r._observers.has("update")){let d=new kt;Wi(d,n)&&r.emit("update",[d.toUint8Array(),n.origin,r,n])}if(r._observers.has("updateV2")){let d=new ct;Wi(d,n)&&r.emit("updateV2",[d.toUint8Array(),n.origin,r,n])}let{subdocsAdded:c,subdocsLoaded:l,subdocsRemoved:a}=n;(c.size>0||a.size>0||l.size>0)&&(c.forEach(d=>{d.clientID=r.clientID,d.collectionid==null&&(d.collectionid=r.collectionid),r.subdocs.add(d)}),a.forEach(d=>r.subdocs.delete(d)),r.emit("subdocs",[{loaded:l,added:c,removed:a},r,n]),a.forEach(d=>d.destroy())),e.length<=t+1?(r._transactionCleanups=[],r.emit("afterAllTransactions",[r,e])):gc(e,t+1)}}},A=(e,t,n=null,r=!0)=>{let s=e._transactionCleanups,o=!1,i=null;e._transaction===null&&(o=!0,e._transaction=new Or(e,n,r),s.push(e._transaction),s.length===1&&e.emit("beforeAllTransactions",[e]),e.emit("beforeTransaction",[e._transaction,e]));try{i=t(e._transaction)}finally{if(o){let c=e._transaction===s[0];e._transaction=null,c&&gc(s,0)}}return i},Ws=class{constructor(t,n){this.insertions=n,this.deletions=t,this.meta=new Map}},Qi=(e,t,n)=>{de(e,n.deletions,r=>{r instanceof D&&t.scope.some(s=>s===e.doc||On(s,r))&&yo(r,!1)})},Zi=(e,t,n)=>{let r=null,s=e.doc,o=e.scope;A(s,c=>{for(;t.length>0&&e.currStackItem===null;){let l=s.store,a=t.pop(),d=new Set,u=[],h=!1;de(c,a.insertions,f=>{if(f instanceof D){if(f.redone!==null){let{item:p,diff:m}=Qs(l,f.id);m>0&&(p=W(c,S(p.id.client,p.id.clock+m))),f=p}!f.deleted&&o.some(p=>p===c.doc||On(p,f))&&u.push(f)}}),de(c,a.deletions,f=>{f instanceof D&&o.some(p=>p===c.doc||On(p,f))&&!Ee(a.insertions,f.id)&&d.add(f)}),d.forEach(f=>{h=Fc(c,f,d,a.insertions,e.ignoreRemoteMapChanges,e)!==null||h});for(let f=u.length-1;f>=0;f--){let p=u[f];e.deleteFilter(p)&&(p.delete(c),h=!0)}e.currStackItem=h?a:null}c.changed.forEach((l,a)=>{l.has(null)&&a._searchMarker&&(a._searchMarker.length=0)}),r=c},e);let i=e.currStackItem;if(i!=null){let c=r.changedParentTypes;e.emit("stack-item-popped",[{stackItem:i,type:n,changedParentTypes:c,origin:e},e]),e.currStackItem=null}return i},fe=class extends Nt{constructor(t,{captureTimeout:n=500,captureTransaction:r=l=>!0,deleteFilter:s=()=>!0,trackedOrigins:o=new Set([null]),ignoreRemoteMapChanges:i=!1,doc:c=pt(t)?t[0].doc:t instanceof bt?t:t.doc}={}){super(),this.scope=[],this.doc=c,this.addToScope(t),this.deleteFilter=s,o.add(this),this.trackedOrigins=o,this.captureTransaction=r,this.undoStack=[],this.redoStack=[],this.undoing=!1,this.redoing=!1,this.currStackItem=null,this.lastChange=0,this.ignoreRemoteMapChanges=i,this.captureTimeout=n,this.afterTransactionHandler=l=>{if(!this.captureTransaction(l)||!this.scope.some(E=>l.changedParentTypes.has(E)||E===this.doc)||!this.trackedOrigins.has(l.origin)&&(!l.origin||!this.trackedOrigins.has(l.origin.constructor)))return;let a=this.undoing,d=this.redoing,u=a?this.redoStack:this.undoStack;a?this.stopCapturing():d||this.clear(!1,!0);let h=new Yt;l.afterState.forEach((E,C)=>{let g=l.beforeState.get(C)||0,x=E-g;x>0&&vn(h,C,g,x)});let f=Pt(),p=!1;if(this.lastChange>0&&f-this.lastChange<this.captureTimeout&&u.length>0&&!a&&!d){let E=u[u.length-1];E.deletions=ue([E.deletions,l.deleteSet]),E.insertions=ue([E.insertions,h])}else u.push(new Ws(l.deleteSet,h)),p=!0;!a&&!d&&(this.lastChange=f),de(l,l.deleteSet,E=>{E instanceof D&&this.scope.some(C=>C===l.doc||On(C,E))&&yo(E,!0)});let m=[{stackItem:u[u.length-1],origin:l.origin,type:a?"redo":"undo",changedParentTypes:l.changedParentTypes},this];p?this.emit("stack-item-added",m):this.emit("stack-item-updated",m)},this.doc.on("afterTransaction",this.afterTransactionHandler),this.doc.on("destroy",()=>{this.destroy()})}addToScope(t){let n=new Set(this.scope);t=pt(t)?t:[t],t.forEach(r=>{n.has(r)||(n.add(r),(r instanceof R?r.doc!==this.doc:r!==this.doc)&&Fs("[yjs#509] Not same Y.Doc"),this.scope.push(r))})}addTrackedOrigin(t){this.trackedOrigins.add(t)}removeTrackedOrigin(t){this.trackedOrigins.delete(t)}clear(t=!0,n=!0){(t&&this.canUndo()||n&&this.canRedo())&&this.doc.transact(r=>{t&&(this.undoStack.forEach(s=>Qi(r,this,s)),this.undoStack=[]),n&&(this.redoStack.forEach(s=>Qi(r,this,s)),this.redoStack=[]),this.emit("stack-cleared",[{undoStackCleared:t,redoStackCleared:n}])})}stopCapturing(){this.lastChange=0}undo(){this.undoing=!0;let t;try{t=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*Xd(e){let t=_(e.restDecoder);for(let n=0;n<t;n++){let r=_(e.restDecoder),s=e.readClient(),o=_(e.restDecoder);for(let i=0;i<r;i++){let c=e.readInfo();if(c===10){let l=_(e.restDecoder);yield new q(S(s,o),l),o+=l}else if((31&c)!==0){let l=(c&192)===0,a=new D(S(s,o),null,(c&128)===128?e.readLeftID():null,null,(c&64)===64?e.readRightID():null,l?e.readParentInfo()?e.readString():e.readLeftID():null,l&&(c&32)===32?e.readString():null,Yc(e,c));yield a,o+=a.length}else{let l=e.readLen();yield new X(S(s,o),l),o+=l}}}}var Ct=class{constructor(t,n){this.gen=Xd(t),this.curr=null,this.done=!1,this.filterSkips=n,this.next()}next(){do this.curr=this.gen.next().value||null;while(this.filterSkips&&this.curr!==null&&this.curr.constructor===q);return this.curr}},Qd=e=>mc(e,st),mc=(e,t=Z)=>{let n=[],r=new t(N(e)),s=new Ct(r,!1);for(let i=s.curr;i!==null;i=s.next())n.push(i);Er("Structs: ",n);let o=It(r);Er("DeleteSet: ",o)},Zd=e=>yc(e,st),yc=(e,t=Z)=>{let n=[],r=new t(N(e)),s=new Ct(r,!1);for(let o=s.curr;o!==null;o=s.next())n.push(o);return{structs:n,ds:It(r)}},Ln=class{constructor(t){this.currClient=0,this.startClock=0,this.written=0,this.encoder=t,this.clientStructs=[]}},wc=e=>pe(e,st,kt),xc=(e,t=tn,n=Z)=>{let r=new t,s=new Ct(new n(N(e)),!1),o=s.curr;if(o!==null){let i=0,c=o.id.client,l=o.id.clock!==0,a=l?0:o.id.clock+o.length;for(;o!==null;o=s.next())c!==o.id.client&&(a!==0&&(i++,y(r.restEncoder,c),y(r.restEncoder,a)),c=o.id.client,a=0,l=o.id.clock!==0),o.constructor===q&&(l=!0),l||(a=o.id.clock+o.length);a!==0&&(i++,y(r.restEncoder,c),y(r.restEncoder,a));let d=gt();return y(d,i),si(d,r.restEncoder),r.restEncoder=d,r.toUint8Array()}else return y(r.restEncoder,0),r.toUint8Array()},tu=e=>xc(e,zt,st),Sc=(e,t=Z)=>{let n=new Map,r=new Map,s=new Ct(new t(N(e)),!1),o=s.curr;if(o!==null){let i=o.id.client,c=o.id.clock;for(n.set(i,c);o!==null;o=s.next())i!==o.id.client&&(r.set(i,c),n.set(o.id.client,o.id.clock),i=o.id.client),c=o.id.clock+o.length;r.set(i,c)}return{from:n,to:r}},eu=e=>Sc(e,st),nu=(e,t)=>{if(e.constructor===X){let{client:n,clock:r}=e.id;return new X(S(n,r+t),e.length-t)}else if(e.constructor===q){let{client:n,clock:r}=e.id;return new q(S(n,r+t),e.length-t)}else{let n=e,{client:r,clock:s}=n.id;return new D(S(r,s+t),null,S(r,s+t-1),null,n.rightOrigin,n.parent,n.parentSub,n.content.splice(t))}},pe=(e,t=Z,n=ct)=>{if(e.length===1)return e[0];let r=e.map(d=>new t(N(d))),s=r.map(d=>new Ct(d,!0)),o=null,i=new n,c=new Ln(i);for(;s=s.filter(h=>h.curr!==null),s.sort((h,f)=>{if(h.curr.id.client===f.curr.id.client){let p=h.curr.id.clock-f.curr.id.clock;return p===0?h.curr.constructor===f.curr.constructor?0:h.curr.constructor===q?1:-1:p}else return f.curr.id.client-h.curr.id.client}),s.length!==0;){let d=s[0],u=d.curr.id.client;if(o!==null){let h=d.curr,f=!1;for(;h!==null&&h.id.clock+h.length<=o.struct.id.clock+o.struct.length&&h.id.client>=o.struct.id.client;)h=d.next(),f=!0;if(h===null||h.id.client!==u||f&&h.id.clock>o.struct.id.clock+o.struct.length)continue;if(u!==o.struct.id.client)jt(c,o.struct,o.offset),o={struct:h,offset:0},d.next();else if(o.struct.id.clock+o.struct.length<h.id.clock)if(o.struct.constructor===q)o.struct.length=h.id.clock+h.length-o.struct.id.clock;else{jt(c,o.struct,o.offset);let p=h.id.clock-o.struct.id.clock-o.struct.length;o={struct:new q(S(u,o.struct.id.clock+o.struct.length),p),offset:0}}else{let p=o.struct.id.clock+o.struct.length-h.id.clock;p>0&&(o.struct.constructor===q?o.struct.length-=p:h=nu(h,p)),o.struct.mergeWith(h)||(jt(c,o.struct,o.offset),o={struct:h,offset:0},d.next())}}else o={struct:d.curr,offset:0},d.next();for(let h=d.curr;h!==null&&h.id.client===u&&h.id.clock===o.struct.id.clock+o.struct.length&&h.constructor!==q;h=d.next())jt(c,o.struct,o.offset),o={struct:h,offset:0}}o!==null&&(jt(c,o.struct,o.offset),o=null),fo(c);let l=r.map(d=>It(d)),a=ue(l);return Et(i,a),i.toUint8Array()},ho=(e,t,n=Z,r=ct)=>{let s=io(t),o=new r,i=new Ln(o),c=new n(N(e)),l=new Ct(c,!1);for(;l.curr;){let d=l.curr,u=d.id.client,h=s.get(u)||0;if(l.curr.constructor===q){l.next();continue}if(d.id.clock+d.length>h)for(jt(i,d,Tt(h-d.id.clock,0)),l.next();l.curr&&l.curr.id.client===u;)jt(i,l.curr,0),l.next();else for(;l.curr&&l.curr.id.client===u&&l.curr.id.clock+l.curr.length<=h;)l.next()}fo(i);let a=It(c);return Et(o,a),o.toUint8Array()},ru=(e,t)=>ho(e,t,st,kt),_c=e=>{e.written>0&&(e.clientStructs.push({written:e.written,restEncoder:K(e.encoder.restEncoder)}),e.encoder.restEncoder=gt(),e.written=0)},jt=(e,t,n)=>{e.written>0&&e.currClient!==t.id.client&&_c(e),e.written===0&&(e.currClient=t.id.client,e.encoder.writeClient(t.id.client),y(e.encoder.restEncoder,t.id.clock+n)),t.write(e.encoder,n),e.written++},fo=e=>{_c(e);let t=e.encoder.restEncoder;y(t,e.clientStructs.length);for(let n=0;n<e.clientStructs.length;n++){let r=e.clientStructs[n];y(t,r.written),Fe(t,r.restEncoder)}},Fr=(e,t,n,r)=>{let s=new n(N(e)),o=new Ct(s,!1),i=new r,c=new Ln(i);for(let a=o.curr;a!==null;a=o.next())jt(c,t(a),0);fo(c);let l=It(s);return Et(i,l),i.toUint8Array()},Ec=({formatting:e=!0,subdocs:t=!0,yxml:n=!0}={})=>{let r=0,s=v(),o=v(),i=v(),c=v();return c.set(null,null),l=>{switch(l.constructor){case X:case q:return l;case D:{let a=l,d=a.content;switch(d.constructor){case sn:break;case ut:{if(n){let u=d.type;u instanceof xe&&(u.nodeName=B(o,u.nodeName,()=>"node-"+r)),u instanceof Bn&&(u.hookName=B(o,u.hookName,()=>"hook-"+r))}break}case Gt:{let u=d;u.arr=u.arr.map(()=>r);break}case Se:{let u=d;u.content=new Uint8Array([r]);break}case _e:{let u=d;t&&(u.opts={},u.doc.guid=r+"");break}case vt:{let u=d;u.embed={};break}case L:{let u=d;e&&(u.key=B(i,u.key,()=>r+""),u.value=B(c,u.value,()=>({i:r})));break}case Pn:{let u=d;u.arr=u.arr.map(()=>r);break}case mt:{let u=d;u.str=er(r%10+"",u.str.length);break}default:$()}return a.parentSub&&(a.parentSub=B(s,a.parentSub,()=>r+"")),r++,l}default:$()}}},su=(e,t)=>Fr(e,Ec(t),st,kt),ou=(e,t)=>Fr(e,Ec(t),Z,ct),iu=e=>Fr(e,ks,st,ct),bc=e=>Fr(e,ks,Z,kt),tc="You must not compute changes after the event-handler fired.",ge=class{constructor(t,n){this.target=t,this.currentTarget=t,this.transaction=n,this._changes=null,this._keys=null,this._delta=null,this._path=null}get path(){return this._path||(this._path=cu(this.currentTarget,this.target))}deletes(t){return Ee(this.transaction.deleteSet,t.id)}get keys(){if(this._keys===null){if(this.transaction.doc._transactionCleanups.length===0)throw ot(tc);let t=new Map,n=this.target;this.transaction.changed.get(n).forEach(s=>{if(s!==null){let o=n._map.get(s),i,c;if(this.adds(o)){let l=o.left;for(;l!==null&&this.adds(l);)l=l.left;if(this.deletes(o))if(l!==null&&this.deletes(l))i="delete",c=Xn(l.content.getContent());else return;else l!==null&&this.deletes(l)?(i="update",c=Xn(l.content.getContent())):(i="add",c=void 0)}else if(this.deletes(o))i="delete",c=Xn(o.content.getContent());else return;t.set(s,{action:i,oldValue:c})}}),this._keys=t}return this._keys}get delta(){return this.changes.delta}adds(t){return t.id.clock>=(this.transaction.beforeState.get(t.id.client)||0)}get changes(){let t=this._changes;if(t===null){if(this.transaction.doc._transactionCleanups.length===0)throw ot(tc);let n=this.target,r=wt(),s=wt(),o=[];if(t={added:r,deleted:s,delta:o,keys:this.keys},this.transaction.changed.get(n).has(null)){let c=null,l=()=>{c&&o.push(c)};for(let a=n._start;a!==null;a=a.right)a.deleted?this.deletes(a)&&!this.adds(a)&&((c===null||c.delete===void 0)&&(l(),c={delete:0}),c.delete+=a.length,s.add(a)):this.adds(a)?((c===null||c.insert===void 0)&&(l(),c={insert:[]}),c.insert=c.insert.concat(a.content.getContent()),r.add(a)):((c===null||c.retain===void 0)&&(l(),c={retain:0}),c.retain+=a.length);c!==null&&c.retain===void 0&&l()}this._changes=t}return t}},cu=(e,t)=>{let n=[];for(;t._item!==null&&t!==e;){if(t._item.parentSub!==null)n.unshift(t._item.parentSub);else{let r=0,s=t._item.parent._start;for(;s!==t._item&&s!==null;)!s.deleted&&s.countable&&(r+=s.length),s=s.right;n.unshift(r)}t=t._item.parent}return n},H=()=>{Fs("Invalid access: Add Yjs type to a document before reading data.")},kc=80,po=0,Xs=class{constructor(t,n){t.marker=!0,this.p=t,this.index=n,this.timestamp=po++}},lu=e=>{e.timestamp=po++},Cc=(e,t,n)=>{e.p.marker=!1,e.p=t,t.marker=!0,e.index=n,e.timestamp=po++},au=(e,t,n)=>{if(e.length>=kc){let r=e.reduce((s,o)=>s.timestamp<o.timestamp?s:o);return Cc(r,t,n),r}else{let r=new Xs(t,n);return e.push(r),r}},Yr=(e,t)=>{if(e._start===null||t===0||e._searchMarker===null)return null;let n=e._searchMarker.length===0?null:e._searchMarker.reduce((o,i)=>te(t-o.index)<te(t-i.index)?o:i),r=e._start,s=0;for(n!==null&&(r=n.p,s=n.index,lu(n));r.right!==null&&s<t;){if(!r.deleted&&r.countable){if(t<s+r.length)break;s+=r.length}r=r.right}for(;r.left!==null&&s>t;)r=r.left,!r.deleted&&r.countable&&(s-=r.length);for(;r.left!==null&&r.left.id.client===r.id.client&&r.left.id.clock+r.left.length===r.id.clock;)r=r.left,!r.deleted&&r.countable&&(s-=r.length);return n!==null&&te(n.index-s)<r.parent.length/kc?(Cc(n,r,s),n):au(e._searchMarker,r,s)},Nn=(e,t,n)=>{for(let r=e.length-1;r>=0;r--){let s=e[r];if(n>0){let o=s.p;for(o.marker=!1;o&&(o.deleted||!o.countable);)o=o.left,o&&!o.deleted&&o.countable&&(s.index-=o.length);if(o===null||o.marker===!0){e.splice(r,1);continue}s.p=o,o.marker=!0}(t<s.index||n>0&&t===s.index)&&(s.index=Tt(t,s.index+n))}},du=e=>{e.doc??H();let t=e._start,n=[];for(;t;)n.push(t),t=t.right;return n},zr=(e,t,n)=>{let r=e,s=t.changedParentTypes;for(;B(s,e,()=>[]).push(n),e._item!==null;)e=e._item.parent;lc(r._eH,n,t)},R=class{constructor(){this._item=null,this._map=new Map,this._start=null,this.doc=null,this._length=0,this._eH=Gi(),this._dEH=Gi(),this._searchMarker=null}get parent(){return this._item?this._item.parent:null}_integrate(t,n){this.doc=t,this._item=n}_copy(){throw it()}clone(){throw it()}_write(t){}get _first(){let t=this._start;for(;t!==null&&t.deleted;)t=t.right;return t}_callObserver(t,n){!t.local&&this._searchMarker&&(this._searchMarker.length=0)}observe(t){qi(this._eH,t)}observeDeep(t){qi(this._dEH,t)}unobserve(t){Hi(this._eH,t)}unobserveDeep(t){Hi(this._dEH,t)}toJSON(){}},Ac=(e,t,n)=>{e.doc??H(),t<0&&(t=e._length+t),n<0&&(n=e._length+n);let r=n-t,s=[],o=e._start;for(;o!==null&&r>0;){if(o.countable&&!o.deleted){let i=o.content.getContent();if(i.length<=t)t-=i.length;else{for(let c=t;c<i.length&&r>0;c++)s.push(i[c]),r--;t=0}}o=o.right}return s},Dc=e=>{e.doc??H();let t=[],n=e._start;for(;n!==null;){if(n.countable&&!n.deleted){let r=n.content.getContent();for(let s=0;s<r.length;s++)t.push(r[s])}n=n.right}return t},uu=(e,t)=>{let n=[],r=e._start;for(;r!==null;){if(r.countable&&$t(r,t)){let s=r.content.getContent();for(let o=0;o<s.length;o++)n.push(s[o])}r=r.right}return n},Mn=(e,t)=>{let n=0,r=e._start;for(e.doc??H();r!==null;){if(r.countable&&!r.deleted){let s=r.content.getContent();for(let o=0;o<s.length;o++)t(s[o],n++,e)}r=r.right}},Tc=(e,t)=>{let n=[];return Mn(e,(r,s)=>{n.push(t(r,s,e))}),n},hu=e=>{let t=e._start,n=null,r=0;return{[Symbol.iterator](){return this},next:()=>{if(n===null){for(;t!==null&&t.deleted;)t=t.right;if(t===null)return{done:!0,value:void 0};n=t.content.getContent(),r=0,t=t.right}let s=n[r++];return n.length<=r&&(n=null),{done:!1,value:s}}}},Uc=(e,t)=>{e.doc??H();let n=Yr(e,t),r=e._start;for(n!==null&&(r=n.p,t-=n.index);r!==null;r=r.right)if(!r.deleted&&r.countable){if(t<r.length)return r.content.getContent()[t];t-=r.length}},Rr=(e,t,n,r)=>{let s=n,o=e.doc,i=o.clientID,c=o.store,l=n===null?t._start:n.right,a=[],d=()=>{a.length>0&&(s=new D(S(i,I(c,i)),s,s&&s.lastId,l,l&&l.id,t,null,new Gt(a)),s.integrate(e,0),a=[])};r.forEach(u=>{if(u===null)a.push(u);else switch(u.constructor){case Number:case Object:case Boolean:case Array:case String:a.push(u);break;default:switch(d(),u.constructor){case Uint8Array:case ArrayBuffer:s=new D(S(i,I(c,i)),s,s&&s.lastId,l,l&&l.id,t,null,new Se(new Uint8Array(u))),s.integrate(e,0);break;case bt:s=new D(S(i,I(c,i)),s,s&&s.lastId,l,l&&l.id,t,null,new _e(u)),s.integrate(e,0);break;default:if(u instanceof R)s=new D(S(i,I(c,i)),s,s&&s.lastId,l,l&&l.id,t,null,new ut(u)),s.integrate(e,0);else throw new Error("Unexpected content type in insert operation")}}}),d()},Ic=()=>ot("Length exceeded!"),vc=(e,t,n,r)=>{if(n>t._length)throw Ic();if(n===0)return t._searchMarker&&Nn(t._searchMarker,n,r.length),Rr(e,t,null,r);let s=n,o=Yr(t,n),i=t._start;for(o!==null&&(i=o.p,n-=o.index,n===0&&(i=i.prev,n+=i&&i.countable&&!i.deleted?i.length:0));i!==null;i=i.right)if(!i.deleted&&i.countable){if(n<=i.length){n<i.length&&W(e,S(i.id.client,i.id.clock+n));break}n-=i.length}return t._searchMarker&&Nn(t._searchMarker,s,r.length),Rr(e,t,i,r)},fu=(e,t,n)=>{let s=(t._searchMarker||[]).reduce((o,i)=>i.index>o.index?i:o,{index:0,p:t._start}).p;if(s)for(;s.right;)s=s.right;return Rr(e,t,s,n)},Oc=(e,t,n,r)=>{if(r===0)return;let s=n,o=r,i=Yr(t,n),c=t._start;for(i!==null&&(c=i.p,n-=i.index);c!==null&&n>0;c=c.right)!c.deleted&&c.countable&&(n<c.length&&W(e,S(c.id.client,c.id.clock+n)),n-=c.length);for(;r>0&&c!==null;)c.deleted||(r<c.length&&W(e,S(c.id.client,c.id.clock+r)),c.delete(e),r-=c.length),c=c.right;if(r>0)throw Ic();t._searchMarker&&Nn(t._searchMarker,s,-o+r)},Lr=(e,t,n)=>{let r=t._map.get(n);r!==void 0&&r.delete(e)},go=(e,t,n,r)=>{let s=t._map.get(n)||null,o=e.doc,i=o.clientID,c;if(r==null)c=new Gt([r]);else switch(r.constructor){case Number:case Object:case Boolean:case Array:case String:case Date:case BigInt:c=new Gt([r]);break;case Uint8Array:c=new Se(r);break;case bt:c=new _e(r);break;default:if(r instanceof R)c=new ut(r);else throw new Error("Unexpected content type")}new D(S(i,I(o.store,i)),s,s&&s.lastId,null,null,t,n,c).integrate(e,0)},mo=(e,t)=>{e.doc??H();let n=e._map.get(t);return n!==void 0&&!n.deleted?n.content.getContent()[n.length-1]:void 0},Rc=e=>{let t={};return e.doc??H(),e._map.forEach((n,r)=>{n.deleted||(t[r]=n.content.getContent()[n.length-1])}),t},Lc=(e,t)=>{e.doc??H();let n=e._map.get(t);return n!==void 0&&!n.deleted},pu=(e,t,n)=>{let r=e._map.get(t)||null;for(;r!==null&&(!n.sv.has(r.id.client)||r.id.clock>=(n.sv.get(r.id.client)||0));)r=r.left;return r!==null&&$t(r,n)?r.content.getContent()[r.length-1]:void 0},Nc=(e,t)=>{let n={};return e._map.forEach((r,s)=>{let o=r;for(;o!==null&&(!t.sv.has(o.id.client)||o.id.clock>=(t.sv.get(o.id.client)||0));)o=o.left;o!==null&&$t(o,t)&&(n[s]=o.content.getContent()[o.length-1])}),n},Cr=e=>(e.doc??H(),ji(e._map.entries(),t=>!t[1].deleted)),Nr=class extends ge{},me=class e extends R{constructor(){super(),this._prelimContent=[],this._searchMarker=[]}static from(t){let n=new e;return n.push(t),n}_integrate(t,n){super._integrate(t,n),this.insert(0,this._prelimContent),this._prelimContent=null}_copy(){return new e}clone(){let t=new e;return t.insert(0,this.toArray().map(n=>n instanceof R?n.clone():n)),t}get length(){return this.doc??H(),this._length}_callObserver(t,n){super._callObserver(t,n),zr(this,t,new Nr(this,t))}insert(t,n){this.doc!==null?A(this.doc,r=>{vc(r,this,t,n)}):this._prelimContent.splice(t,0,...n)}push(t){this.doc!==null?A(this.doc,n=>{fu(n,this,t)}):this._prelimContent.push(...t)}unshift(t){this.insert(0,t)}delete(t,n=1){this.doc!==null?A(this.doc,r=>{Oc(r,this,t,n)}):this._prelimContent.splice(t,n)}get(t){return Uc(this,t)}toArray(){return Dc(this)}slice(t=0,n=this.length){return Ac(this,t,n)}toJSON(){return this.map(t=>t instanceof R?t.toJSON():t)}map(t){return Tc(this,t)}forEach(t){Mn(this,t)}[Symbol.iterator](){return hu(this)}_write(t){t.writeTypeRef(Nu)}},gu=e=>new me,Mr=class extends ge{constructor(t,n,r){super(t,n),this.keysChanged=r}},ye=class e extends R{constructor(t){super(),this._prelimContent=null,t===void 0?this._prelimContent=new Map:this._prelimContent=new Map(t)}_integrate(t,n){super._integrate(t,n),this._prelimContent.forEach((r,s)=>{this.set(s,r)}),this._prelimContent=null}_copy(){return new e}clone(){let t=new e;return this.forEach((n,r)=>{t.set(r,n instanceof R?n.clone():n)}),t}_callObserver(t,n){zr(this,t,new Mr(this,t,n))}toJSON(){this.doc??H();let t={};return this._map.forEach((n,r)=>{if(!n.deleted){let s=n.content.getContent()[n.length-1];t[r]=s instanceof R?s.toJSON():s}}),t}get size(){return[...Cr(this)].length}keys(){return br(Cr(this),t=>t[0])}values(){return br(Cr(this),t=>t[1].content.getContent()[t[1].length-1])}entries(){return br(Cr(this),t=>[t[0],t[1].content.getContent()[t[1].length-1]])}forEach(t){this.doc??H(),this._map.forEach((n,r)=>{n.deleted||t(n.content.getContent()[n.length-1],r,this)})}[Symbol.iterator](){return this.entries()}delete(t){this.doc!==null?A(this.doc,n=>{Lr(n,this,t)}):this._prelimContent.delete(t)}set(t,n){return this.doc!==null?A(this.doc,r=>{go(r,this,t,n)}):this._prelimContent.set(t,n),n}get(t){return mo(this,t)}has(t){return Lc(this,t)}clear(){this.doc!==null?A(this.doc,t=>{this.forEach(function(n,r,s){Lr(t,s,r)})}):this._prelimContent.clear()}_write(t){t.writeTypeRef(Mu)}},mu=e=>new ye,Ft=(e,t)=>e===t||typeof e=="object"&&typeof t=="object"&&e&&t&&_s(e,t),Vn=class{constructor(t,n,r,s){this.left=t,this.right=n,this.index=r,this.currentAttributes=s}forward(){this.right===null&&$(),this.right.content.constructor===L?this.right.deleted||on(this.currentAttributes,this.right.content):this.right.deleted||(this.index+=this.right.length),this.left=this.right,this.right=this.right.right}},ec=(e,t,n)=>{for(;t.right!==null&&n>0;)t.right.content.constructor===L?t.right.deleted||on(t.currentAttributes,t.right.content):t.right.deleted||(n<t.right.length&&W(e,S(t.right.id.client,t.right.id.clock+n)),t.index+=t.right.length,n-=t.right.length),t.left=t.right,t.right=t.right.right;return t},Ar=(e,t,n,r)=>{let s=new Map,o=r?Yr(t,n):null;if(o){let i=new Vn(o.p.left,o.p,o.index,s);return ec(e,i,n-o.index)}else{let i=new Vn(null,t._start,0,s);return ec(e,i,n)}},Mc=(e,t,n,r)=>{for(;n.right!==null&&(n.right.deleted===!0||n.right.content.constructor===L&&Ft(r.get(n.right.content.key),n.right.content.value));)n.right.deleted||r.delete(n.right.content.key),n.forward();let s=e.doc,o=s.clientID;r.forEach((i,c)=>{let l=n.left,a=n.right,d=new D(S(o,I(s.store,o)),l,l&&l.lastId,a,a&&a.id,t,null,new L(c,i));d.integrate(e,0),n.right=d,n.forward()})},on=(e,t)=>{let{key:n,value:r}=t;r===null?e.delete(n):e.set(n,r)},Vc=(e,t)=>{for(;e.right!==null;){if(!(e.right.deleted||e.right.content.constructor===L&&Ft(t[e.right.content.key]??null,e.right.content.value)))break;e.forward()}},Bc=(e,t,n,r)=>{let s=e.doc,o=s.clientID,i=new Map;for(let c in r){let l=r[c],a=n.currentAttributes.get(c)??null;if(!Ft(a,l)){i.set(c,a);let{left:d,right:u}=n;n.right=new D(S(o,I(s.store,o)),d,d&&d.lastId,u,u&&u.id,t,null,new L(c,l)),n.right.integrate(e,0),n.forward()}}return i},Ys=(e,t,n,r,s)=>{n.currentAttributes.forEach((h,f)=>{s[f]===void 0&&(s[f]=null)});let o=e.doc,i=o.clientID;Vc(n,s);let c=Bc(e,t,n,s),l=r.constructor===String?new mt(r):r instanceof R?new ut(r):new vt(r),{left:a,right:d,index:u}=n;t._searchMarker&&Nn(t._searchMarker,n.index,l.getLength()),d=new D(S(i,I(o.store,i)),a,a&&a.lastId,d,d&&d.id,t,null,l),d.integrate(e,0),n.right=d,n.index=u,n.forward(),Mc(e,t,n,c)},nc=(e,t,n,r,s)=>{let o=e.doc,i=o.clientID;Vc(n,s);let c=Bc(e,t,n,s);t:for(;n.right!==null&&(r>0||c.size>0&&(n.right.deleted||n.right.content.constructor===L));){if(!n.right.deleted)switch(n.right.content.constructor){case L:{let{key:l,value:a}=n.right.content,d=s[l];if(d!==void 0){if(Ft(d,a))c.delete(l);else{if(r===0)break t;c.set(l,a)}n.right.delete(e)}else n.currentAttributes.set(l,a);break}default:r<n.right.length&&W(e,S(n.right.id.client,n.right.id.clock+r)),r-=n.right.length;break}n.forward()}if(r>0){let l="";for(;r>0;r--)l+=`
`;n.right=new D(S(i,I(o.store,i)),n.left,n.left&&n.left.lastId,n.right,n.right&&n.right.id,t,null,new mt(l)),n.right.integrate(e,0),n.forward()}Mc(e,t,n,c)},Pc=(e,t,n,r,s)=>{let o=t,i=v();for(;o&&(!o.countable||o.deleted);){if(!o.deleted&&o.content.constructor===L){let a=o.content;i.set(a.key,a)}o=o.right}let c=0,l=!1;for(;t!==o;){if(n===t&&(l=!0),!t.deleted){let a=t.content;if(a.constructor===L){let{key:d,value:u}=a,h=r.get(d)??null;(i.get(d)!==a||h===u)&&(t.delete(e),c++,!l&&(s.get(d)??null)===u&&h!==u&&(h===null?s.delete(d):s.set(d,h))),!l&&!t.deleted&&on(s,a)}}t=t.right}return c},yu=(e,t)=>{for(;t&&t.right&&(t.right.deleted||!t.right.countable);)t=t.right;let n=new Set;for(;t&&(t.deleted||!t.countable);){if(!t.deleted&&t.content.constructor===L){let r=t.content.key;n.has(r)?t.delete(e):n.add(r)}t=t.left}},$c=e=>{let t=0;return A(e.doc,n=>{let r=e._start,s=e._start,o=v(),i=Wn(o);for(;s;)s.deleted===!1&&(s.content.constructor===L?on(i,s.content):(t+=Pc(n,r,s,o,i),o=Wn(i),r=s)),s=s.right}),t},wu=e=>{let t=new Set,n=e.doc;for(let[r,s]of e.afterState.entries()){let o=e.beforeState.get(r)||0;s!==o&&hc(e,n.store.clients.get(r),o,s,i=>{!i.deleted&&i.content.constructor===L&&i.constructor!==X&&t.add(i.parent)})}A(n,r=>{de(e,e.deleteSet,s=>{if(s instanceof X||!s.parent._hasFormatting||t.has(s.parent))return;let o=s.parent;s.content.constructor===L?t.add(o):yu(r,s)});for(let s of t)$c(s)})},rc=(e,t,n)=>{let r=n,s=Wn(t.currentAttributes),o=t.right;for(;n>0&&t.right!==null;){if(t.right.deleted===!1)switch(t.right.content.constructor){case ut:case vt:case mt:n<t.right.length&&W(e,S(t.right.id.client,t.right.id.clock+n)),n-=t.right.length,t.right.delete(e);break}t.forward()}o&&Pc(e,o,t.right,s,t.currentAttributes);let i=(t.left||t.right).parent;return i._searchMarker&&Nn(i._searchMarker,t.index,-r+n),t},Vr=class extends ge{constructor(t,n,r){super(t,n),this.childListChanged=!1,this.keysChanged=new Set,r.forEach(s=>{s===null?this.childListChanged=!0:this.keysChanged.add(s)})}get changes(){if(this._changes===null){let t={keys:this.keys,delta:this.delta,added:new Set,deleted:new Set};this._changes=t}return this._changes}get delta(){if(this._delta===null){let t=this.target.doc,n=[];A(t,r=>{let s=new Map,o=new Map,i=this.target._start,c=null,l={},a="",d=0,u=0,h=()=>{if(c!==null){let f=null;switch(c){case"delete":u>0&&(f={delete:u}),u=0;break;case"insert":(typeof a=="object"||a.length>0)&&(f={insert:a},s.size>0&&(f.attributes={},s.forEach((p,m)=>{p!==null&&(f.attributes[m]=p)}))),a="";break;case"retain":d>0&&(f={retain:d},pi(l)||(f.attributes=hi({},l))),d=0;break}f&&n.push(f),c=null}};for(;i!==null;){switch(i.content.constructor){case ut:case vt:this.adds(i)?this.deletes(i)||(h(),c="insert",a=i.content.getContent()[0],h()):this.deletes(i)?(c!=="delete"&&(h(),c="delete"),u+=1):i.deleted||(c!=="retain"&&(h(),c="retain"),d+=1);break;case mt:this.adds(i)?this.deletes(i)||(c!=="insert"&&(h(),c="insert"),a+=i.content.str):this.deletes(i)?(c!=="delete"&&(h(),c="delete"),u+=i.length):i.deleted||(c!=="retain"&&(h(),c="retain"),d+=i.length);break;case L:{let{key:f,value:p}=i.content;if(this.adds(i)){if(!this.deletes(i)){let m=s.get(f)??null;Ft(m,p)?p!==null&&i.delete(r):(c==="retain"&&h(),Ft(p,o.get(f)??null)?delete l[f]:l[f]=p)}}else if(this.deletes(i)){o.set(f,p);let m=s.get(f)??null;Ft(m,p)||(c==="retain"&&h(),l[f]=m)}else if(!i.deleted){o.set(f,p);let m=l[f];m!==void 0&&(Ft(m,p)?m!==null&&i.delete(r):(c==="retain"&&h(),p===null?delete l[f]:l[f]=p))}i.deleted||(c==="insert"&&h(),on(s,i.content));break}}i=i.right}for(h();n.length>0;){let f=n[n.length-1];if(f.retain!==void 0&&f.attributes===void 0)n.pop();else break}}),this._delta=n}return this._delta}},nn=class e extends R{constructor(t){super(),this._pending=t!==void 0?[()=>this.insert(0,t)]:[],this._searchMarker=[],this._hasFormatting=!1}get length(){return this.doc??H(),this._length}_integrate(t,n){super._integrate(t,n);try{this._pending.forEach(r=>r())}catch(r){console.error(r)}this._pending=null}_copy(){return new e}clone(){let t=new e;return t.applyDelta(this.toDelta()),t}_callObserver(t,n){super._callObserver(t,n);let r=new Vr(this,t,n);zr(this,t,r),!t.local&&this._hasFormatting&&(t._needFormattingCleanup=!0)}toString(){this.doc??H();let t="",n=this._start;for(;n!==null;)!n.deleted&&n.countable&&n.content.constructor===mt&&(t+=n.content.str),n=n.right;return t}toJSON(){return this.toString()}applyDelta(t,{sanitize:n=!0}={}){this.doc!==null?A(this.doc,r=>{let s=new Vn(null,this._start,0,new Map);for(let o=0;o<t.length;o++){let i=t[o];if(i.insert!==void 0){let c=!n&&typeof i.insert=="string"&&o===t.length-1&&s.right===null&&i.insert.slice(-1)===`
`?i.insert.slice(0,-1):i.insert;(typeof c!="string"||c.length>0)&&Ys(r,this,s,c,i.attributes||{})}else i.retain!==void 0?nc(r,this,s,i.retain,i.attributes||{}):i.delete!==void 0&&rc(r,s,i.delete)}}):this._pending.push(()=>this.applyDelta(t))}toDelta(t,n,r){this.doc??H();let s=[],o=new Map,i=this.doc,c="",l=this._start;function a(){if(c.length>0){let u={},h=!1;o.forEach((p,m)=>{h=!0,u[m]=p});let f={insert:c};h&&(f.attributes=u),s.push(f),c=""}}let d=()=>{for(;l!==null;){if($t(l,t)||n!==void 0&&$t(l,n))switch(l.content.constructor){case mt:{let u=o.get("ychange");t!==void 0&&!$t(l,t)?(u===void 0||u.user!==l.id.client||u.type!=="removed")&&(a(),o.set("ychange",r?r("removed",l.id):{type:"removed"})):n!==void 0&&!$t(l,n)?(u===void 0||u.user!==l.id.client||u.type!=="added")&&(a(),o.set("ychange",r?r("added",l.id):{type:"added"})):u!==void 0&&(a(),o.delete("ychange")),c+=l.content.str;break}case ut:case vt:{a();let u={insert:l.content.getContent()[0]};if(o.size>0){let h={};u.attributes=h,o.forEach((f,p)=>{h[p]=f})}s.push(u);break}case L:$t(l,t)&&(a(),on(o,l.content));break}l=l.right}a()};return t||n?A(i,u=>{t&&Hs(u,t),n&&Hs(u,n),d()},"cleanup"):d(),s}insert(t,n,r){if(n.length<=0)return;let s=this.doc;s!==null?A(s,o=>{let i=Ar(o,this,t,!r);r||(r={},i.currentAttributes.forEach((c,l)=>{r[l]=c})),Ys(o,this,i,n,r)}):this._pending.push(()=>this.insert(t,n,r))}insertEmbed(t,n,r){let s=this.doc;s!==null?A(s,o=>{let i=Ar(o,this,t,!r);Ys(o,this,i,n,r||{})}):this._pending.push(()=>this.insertEmbed(t,n,r||{}))}delete(t,n){if(n===0)return;let r=this.doc;r!==null?A(r,s=>{rc(s,Ar(s,this,t,!0),n)}):this._pending.push(()=>this.delete(t,n))}format(t,n,r){if(n===0)return;let s=this.doc;s!==null?A(s,o=>{let i=Ar(o,this,t,!1);i.right!==null&&nc(o,this,i,n,r)}):this._pending.push(()=>this.format(t,n,r))}removeAttribute(t){this.doc!==null?A(this.doc,n=>{Lr(n,this,t)}):this._pending.push(()=>this.removeAttribute(t))}setAttribute(t,n){this.doc!==null?A(this.doc,r=>{go(r,this,t,n)}):this._pending.push(()=>this.setAttribute(t,n))}getAttribute(t){return mo(this,t)}getAttributes(){return Rc(this)}_write(t){t.writeTypeRef(Vu)}},xu=e=>new nn,Un=class{constructor(t,n=()=>!0){this._filter=n,this._root=t,this._currentNode=t._start,this._firstCall=!0,t.doc??H()}[Symbol.iterator](){return this}next(){let t=this._currentNode,n=t&&t.content&&t.content.type;if(t!==null&&(!this._firstCall||t.deleted||!this._filter(n)))do if(n=t.content.type,!t.deleted&&(n.constructor===xe||n.constructor===we)&&n._start!==null)t=n._start;else for(;t!==null;){let r=t.next;if(r!==null){t=r;break}else t.parent===this._root?t=null:t=t.parent._item}while(t!==null&&(t.deleted||!this._filter(t.content.type)));return this._firstCall=!1,t===null?{value:void 0,done:!0}:(this._currentNode=t,{value:t.content.type,done:!1})}},we=class e extends R{constructor(){super(),this._prelimContent=[]}get firstChild(){let t=this._first;return t?t.content.getContent()[0]:null}_integrate(t,n){super._integrate(t,n),this.insert(0,this._prelimContent),this._prelimContent=null}_copy(){return new e}clone(){let t=new e;return t.insert(0,this.toArray().map(n=>n instanceof R?n.clone():n)),t}get length(){return this.doc??H(),this._prelimContent===null?this._length:this._prelimContent.length}createTreeWalker(t){return new Un(this,t)}querySelector(t){t=t.toUpperCase();let r=new Un(this,s=>s.nodeName&&s.nodeName.toUpperCase()===t).next();return r.done?null:r.value}querySelectorAll(t){return t=t.toUpperCase(),ft(new Un(this,n=>n.nodeName&&n.nodeName.toUpperCase()===t))}_callObserver(t,n){zr(this,t,new Br(this,n,t))}toString(){return Tc(this,t=>t.toString()).join("")}toJSON(){return this.toString()}toDOM(t=document,n={},r){let s=t.createDocumentFragment();return r!==void 0&&r._createAssociation(s,this),Mn(this,o=>{s.insertBefore(o.toDOM(t,n,r),null)}),s}insert(t,n){this.doc!==null?A(this.doc,r=>{vc(r,this,t,n)}):this._prelimContent.splice(t,0,...n)}insertAfter(t,n){if(this.doc!==null)A(this.doc,r=>{let s=t&&t instanceof R?t._item:t;Rr(r,this,s,n)});else{let r=this._prelimContent,s=t===null?0:r.findIndex(o=>o===t)+1;if(s===0&&t!==null)throw ot("Reference item not found");r.splice(s,0,...n)}}delete(t,n=1){this.doc!==null?A(this.doc,r=>{Oc(r,this,t,n)}):this._prelimContent.splice(t,n)}toArray(){return Dc(this)}push(t){this.insert(this.length,t)}unshift(t){this.insert(0,t)}get(t){return Uc(this,t)}slice(t=0,n=this.length){return Ac(this,t,n)}forEach(t){Mn(this,t)}_write(t){t.writeTypeRef(Pu)}},Su=e=>new we,xe=class e extends we{constructor(t="UNDEFINED"){super(),this.nodeName=t,this._prelimAttrs=new Map}get nextSibling(){let t=this._item?this._item.next:null;return t?t.content.type:null}get prevSibling(){let t=this._item?this._item.prev:null;return t?t.content.type:null}_integrate(t,n){super._integrate(t,n),this._prelimAttrs.forEach((r,s)=>{this.setAttribute(s,r)}),this._prelimAttrs=null}_copy(){return new e(this.nodeName)}clone(){let t=new e(this.nodeName),n=this.getAttributes();return fi(n,(r,s)=>{t.setAttribute(s,r)}),t.insert(0,this.toArray().map(r=>r instanceof R?r.clone():r)),t}toString(){let t=this.getAttributes(),n=[],r=[];for(let c in t)r.push(c);r.sort();let s=r.length;for(let c=0;c<s;c++){let l=r[c];n.push(l+'="'+t[l]+'"')}let o=this.nodeName.toLocaleLowerCase(),i=n.length>0?" "+n.join(" "):"";return`<${o}${i}>${super.toString()}</${o}>`}removeAttribute(t){this.doc!==null?A(this.doc,n=>{Lr(n,this,t)}):this._prelimAttrs.delete(t)}setAttribute(t,n){this.doc!==null?A(this.doc,r=>{go(r,this,t,n)}):this._prelimAttrs.set(t,n)}getAttribute(t){return mo(this,t)}hasAttribute(t){return Lc(this,t)}getAttributes(t){return t?Nc(this,t):Rc(this)}toDOM(t=document,n={},r){let s=t.createElement(this.nodeName),o=this.getAttributes();for(let i in o){let c=o[i];typeof c=="string"&&s.setAttribute(i,c)}return Mn(this,i=>{s.appendChild(i.toDOM(t,n,r))}),r!==void 0&&r._createAssociation(s,this),s}_write(t){t.writeTypeRef(Bu),t.writeKey(this.nodeName)}},_u=e=>new xe(e.readKey()),Br=class extends ge{constructor(t,n,r){super(t,r),this.childListChanged=!1,this.attributesChanged=new Set,n.forEach(s=>{s===null?this.childListChanged=!0:this.attributesChanged.add(s)})}},Bn=class e extends ye{constructor(t){super(),this.hookName=t}_copy(){return new e(this.hookName)}clone(){let t=new e(this.hookName);return this.forEach((n,r)=>{t.set(r,n)}),t}toDOM(t=document,n={},r){let s=n[this.hookName],o;return s!==void 0?o=s.createDom(this):o=document.createElement(this.hookName),o.setAttribute("data-yjs-hook",this.hookName),r!==void 0&&r._createAssociation(o,this),o}_write(t){t.writeTypeRef($u),t.writeKey(this.hookName)}},Eu=e=>new Bn(e.readKey()),Pr=class e extends nn{get nextSibling(){let t=this._item?this._item.next:null;return t?t.content.type:null}get prevSibling(){let t=this._item?this._item.prev:null;return t?t.content.type:null}_copy(){return new e}clone(){let t=new e;return t.applyDelta(this.toDelta()),t}toDOM(t=document,n,r){let s=t.createTextNode(this.toString());return r!==void 0&&r._createAssociation(s,this),s}toString(){return this.toDelta().map(t=>{let n=[];for(let s in t.attributes){let o=[];for(let i in t.attributes[s])o.push({key:i,value:t.attributes[s][i]});o.sort((i,c)=>i.key<c.key?-1:1),n.push({nodeName:s,attrs:o})}n.sort((s,o)=>s.nodeName<o.nodeName?-1:1);let r="";for(let s=0;s<n.length;s++){let o=n[s];r+=`<${o.nodeName}`;for(let i=0;i<o.attrs.length;i++){let c=o.attrs[i];r+=` ${c.key}="${c.value}"`}r+=">"}r+=t.insert;for(let s=n.length-1;s>=0;s--)r+=`</${n[s].nodeName}>`;return r}).join("")}toJSON(){return this.toString()}_write(t){t.writeTypeRef(ju)}},bu=e=>new Pr,rn=class{constructor(t,n){this.id=t,this.length=n}get deleted(){throw it()}mergeWith(t){return!1}write(t,n,r){throw it()}integrate(t,n){throw it()}},ku=0,X=class extends rn{get deleted(){return!0}delete(){}mergeWith(t){return this.constructor!==t.constructor?!1:(this.length+=t.length,!0)}integrate(t,n){n>0&&(this.id.clock+=n,this.length-=n),uc(t.doc.store,this)}write(t,n){t.writeInfo(ku),t.writeLen(this.length-n)}getMissing(t,n){return null}},Se=class e{constructor(t){this.content=t}getLength(){return 1}getContent(){return[this.content]}isCountable(){return!0}copy(){return new e(this.content)}splice(t){throw it()}mergeWith(t){return!1}integrate(t,n){}delete(t){}gc(t){}write(t,n){t.writeBuf(this.content)}getRef(){return 3}},Cu=e=>new Se(e.readBuf()),sn=class e{constructor(t){this.len=t}getLength(){return this.len}getContent(){return[]}isCountable(){return!1}copy(){return new e(this.len)}splice(t){let n=new e(this.len-t);return this.len=t,n}mergeWith(t){return this.len+=t.len,!0}integrate(t,n){vn(t.deleteSet,n.id.client,n.id.clock,this.len),n.markDeleted()}delete(t){}gc(t){}write(t,n){t.writeLen(this.len-n)}getRef(){return 1}},Au=e=>new sn(e.readLen()),jc=(e,t)=>new bt({guid:e,...t,shouldLoad:t.shouldLoad||t.autoLoad||!1}),_e=class e{constructor(t){t._item&&console.error("This document was already integrated as a sub-document. You should create a second instance instead with the same guid."),this.doc=t;let n={};this.opts=n,t.gc||(n.gc=!1),t.autoLoad&&(n.autoLoad=!0),t.meta!==null&&(n.meta=t.meta)}getLength(){return 1}getContent(){return[this.doc]}isCountable(){return!0}copy(){return new e(jc(this.doc.guid,this.opts))}splice(t){throw it()}mergeWith(t){return!1}integrate(t,n){this.doc._item=n,t.subdocsAdded.add(this.doc),this.doc.shouldLoad&&t.subdocsLoaded.add(this.doc)}delete(t){t.subdocsAdded.has(this.doc)?t.subdocsAdded.delete(this.doc):t.subdocsRemoved.add(this.doc)}gc(t){}write(t,n){t.writeString(this.doc.guid),t.writeAny(this.opts)}getRef(){return 9}},Du=e=>new _e(jc(e.readString(),e.readAny())),vt=class e{constructor(t){this.embed=t}getLength(){return 1}getContent(){return[this.embed]}isCountable(){return!0}copy(){return new e(this.embed)}splice(t){throw it()}mergeWith(t){return!1}integrate(t,n){}delete(t){}gc(t){}write(t,n){t.writeJSON(this.embed)}getRef(){return 5}},Tu=e=>new vt(e.readJSON()),L=class e{constructor(t,n){this.key=t,this.value=n}getLength(){return 1}getContent(){return[]}isCountable(){return!1}copy(){return new e(this.key,this.value)}splice(t){throw it()}mergeWith(t){return!1}integrate(t,n){let r=n.parent;r._searchMarker=null,r._hasFormatting=!0}delete(t){}gc(t){}write(t,n){t.writeKey(this.key),t.writeJSON(this.value)}getRef(){return 6}},Uu=e=>new L(e.readKey(),e.readJSON()),Pn=class e{constructor(t){this.arr=t}getLength(){return this.arr.length}getContent(){return this.arr}isCountable(){return!0}copy(){return new e(this.arr)}splice(t){let n=new e(this.arr.slice(t));return this.arr=this.arr.slice(0,t),n}mergeWith(t){return this.arr=this.arr.concat(t.arr),!0}integrate(t,n){}delete(t){}gc(t){}write(t,n){let r=this.arr.length;t.writeLen(r-n);for(let s=n;s<r;s++){let o=this.arr[s];t.writeString(o===void 0?"undefined":JSON.stringify(o))}}getRef(){return 2}},Iu=e=>{let t=e.readLen(),n=[];for(let r=0;r<t;r++){let s=e.readString();s==="undefined"?n.push(void 0):n.push(JSON.parse(s))}return new Pn(n)},vu=_n("node_env")==="development",Gt=class e{constructor(t){this.arr=t,vu&&Es(t)}getLength(){return this.arr.length}getContent(){return this.arr}isCountable(){return!0}copy(){return new e(this.arr)}splice(t){let n=new e(this.arr.slice(t));return this.arr=this.arr.slice(0,t),n}mergeWith(t){return this.arr=this.arr.concat(t.arr),!0}integrate(t,n){}delete(t){}gc(t){}write(t,n){let r=this.arr.length;t.writeLen(r-n);for(let s=n;s<r;s++){let o=this.arr[s];t.writeAny(o)}}getRef(){return 8}},Ou=e=>{let t=e.readLen(),n=[];for(let r=0;r<t;r++)n.push(e.readAny());return new Gt(n)},mt=class e{constructor(t){this.str=t}getLength(){return this.str.length}getContent(){return this.str.split("")}isCountable(){return!0}copy(){return new e(this.str)}splice(t){let n=new e(this.str.slice(t));this.str=this.str.slice(0,t);let r=this.str.charCodeAt(t-1);return r>=55296&&r<=56319&&(this.str=this.str.slice(0,t-1)+"\uFFFD",n.str="\uFFFD"+n.str.slice(1)),n}mergeWith(t){return this.str+=t.str,!0}integrate(t,n){}delete(t){}gc(t){}write(t,n){t.writeString(n===0?this.str:this.str.slice(n))}getRef(){return 4}},Ru=e=>new mt(e.readString()),Lu=[gu,mu,xu,_u,Su,Eu,bu],Nu=0,Mu=1,Vu=2,Bu=3,Pu=4,$u=5,ju=6,ut=class e{constructor(t){this.type=t}getLength(){return 1}getContent(){return[this.type]}isCountable(){return!0}copy(){return new e(this.type._copy())}splice(t){throw it()}mergeWith(t){return!1}integrate(t,n){this.type._integrate(t.doc,n)}delete(t){let n=this.type._start;for(;n!==null;)n.deleted?n.id.clock<(t.beforeState.get(n.id.client)||0)&&t._mergeStructs.push(n):n.delete(t),n=n.right;this.type._map.forEach(r=>{r.deleted?r.id.clock<(t.beforeState.get(r.id.client)||0)&&t._mergeStructs.push(r):r.delete(t)}),t.changed.delete(this.type)}gc(t){let n=this.type._start;for(;n!==null;)n.gc(t,!0),n=n.right;this.type._start=null,this.type._map.forEach(r=>{for(;r!==null;)r.gc(t,!0),r=r.left}),this.type._map=new Map}write(t,n){this.type._write(t)}getRef(){return 7}},Fu=e=>new ut(Lu[e.readTypeRef()](e)),Qs=(e,t)=>{let n=t,r=0,s;do r>0&&(n=S(n.client,n.clock+r)),s=ae(e,n),r=n.clock-s.id.clock,n=s.redone;while(n!==null&&s instanceof D);return{item:s,diff:r}},yo=(e,t)=>{for(;e!==null&&e.keep!==t;)e.keep=t,e=e.parent._item},$r=(e,t,n)=>{let{client:r,clock:s}=t.id,o=new D(S(r,s+n),t,S(r,s+n-1),t.right,t.rightOrigin,t.parent,t.parentSub,t.content.splice(n));return t.deleted&&o.markDeleted(),t.keep&&(o.keep=!0),t.redone!==null&&(o.redone=S(t.redone.client,t.redone.clock+n)),t.right=o,o.right!==null&&(o.right.left=o),e._mergeStructs.push(o),o.parentSub!==null&&o.right===null&&o.parent._map.set(o.parentSub,o),t.length=n,o},sc=(e,t)=>hn(e,n=>Ee(n.deletions,t)),Fc=(e,t,n,r,s,o)=>{let i=e.doc,c=i.store,l=i.clientID,a=t.redone;if(a!==null)return W(e,a);let d=t.parent._item,u=null,h;if(d!==null&&d.deleted===!0){if(d.redone===null&&(!n.has(d)||Fc(e,d,n,r,s,o)===null))return null;for(;d.redone!==null;)d=W(e,d.redone)}let f=d===null?t.parent:d.content.type;if(t.parentSub===null){for(u=t.left,h=t;u!==null;){let C=u;for(;C!==null&&C.parent._item!==d;)C=C.redone===null?null:W(e,C.redone);if(C!==null&&C.parent._item===d){u=C;break}u=u.left}for(;h!==null;){let C=h;for(;C!==null&&C.parent._item!==d;)C=C.redone===null?null:W(e,C.redone);if(C!==null&&C.parent._item===d){h=C;break}h=h.right}}else if(h=null,t.right&&!s){for(u=t;u!==null&&u.right!==null&&(u.right.redone||Ee(r,u.right.id)||sc(o.undoStack,u.right.id)||sc(o.redoStack,u.right.id));)for(u=u.right;u.redone;)u=W(e,u.redone);if(u&&u.right!==null)return null}else u=f._map.get(t.parentSub)||null;let p=I(c,l),m=S(l,p),E=new D(m,u,u&&u.lastId,h,h&&h.id,f,t.parentSub,t.content.copy());return t.redone=m,yo(E,!0),E.integrate(e,0),E},D=class e extends rn{constructor(t,n,r,s,o,i,c,l){super(t,l.getLength()),this.origin=r,this.left=n,this.right=s,this.rightOrigin=o,this.parent=i,this.parentSub=c,this.redone=null,this.content=l,this.info=this.content.isCountable()?2:0}set marker(t){(this.info&8)>0!==t&&(this.info^=8)}get marker(){return(this.info&8)>0}get keep(){return(this.info&1)>0}set keep(t){this.keep!==t&&(this.info^=1)}get countable(){return(this.info&2)>0}get deleted(){return(this.info&4)>0}set deleted(t){this.deleted!==t&&(this.info^=4)}markDeleted(){this.info|=4}getMissing(t,n){if(this.origin&&this.origin.client!==this.id.client&&this.origin.clock>=I(n,this.origin.client))return this.origin.client;if(this.rightOrigin&&this.rightOrigin.client!==this.id.client&&this.rightOrigin.clock>=I(n,this.rightOrigin.client))return this.rightOrigin.client;if(this.parent&&this.parent.constructor===Ut&&this.id.client!==this.parent.client&&this.parent.clock>=I(n,this.parent.client))return this.parent.client;if(this.origin&&(this.left=Ks(t,n,this.origin),this.origin=this.left.lastId),this.rightOrigin&&(this.right=W(t,this.rightOrigin),this.rightOrigin=this.right.id),this.left&&this.left.constructor===X||this.right&&this.right.constructor===X)this.parent=null;else if(!this.parent)this.left&&this.left.constructor===e?(this.parent=this.left.parent,this.parentSub=this.left.parentSub):this.right&&this.right.constructor===e&&(this.parent=this.right.parent,this.parentSub=this.right.parentSub);else if(this.parent.constructor===Ut){let r=ae(n,this.parent);r.constructor===X?this.parent=null:this.parent=r.content.type}return null}integrate(t,n){if(n>0&&(this.id.clock+=n,this.left=Ks(t,t.doc.store,S(this.id.client,this.id.clock-1)),this.origin=this.left.lastId,this.content=this.content.splice(n),this.length-=n),this.parent){if(!this.left&&(!this.right||this.right.left!==null)||this.left&&this.left.right!==this.right){let r=this.left,s;if(r!==null)s=r.right;else if(this.parentSub!==null)for(s=this.parent._map.get(this.parentSub)||null;s!==null&&s.left!==null;)s=s.left;else s=this.parent._start;let o=new Set,i=new Set;for(;s!==null&&s!==this.right;){if(i.add(s),o.add(s),le(this.origin,s.origin)){if(s.id.client<this.id.client)r=s,o.clear();else if(le(this.rightOrigin,s.rightOrigin))break}else if(s.origin!==null&&i.has(ae(t.doc.store,s.origin)))o.has(ae(t.doc.store,s.origin))||(r=s,o.clear());else break;s=s.right}this.left=r}if(this.left!==null){let r=this.left.right;this.right=r,this.left.right=this}else{let r;if(this.parentSub!==null)for(r=this.parent._map.get(this.parentSub)||null;r!==null&&r.left!==null;)r=r.left;else r=this.parent._start,this.parent._start=this;this.right=r}this.right!==null?this.right.left=this:this.parentSub!==null&&(this.parent._map.set(this.parentSub,this),this.left!==null&&this.left.delete(t)),this.parentSub===null&&this.countable&&!this.deleted&&(this.parent._length+=this.length),uc(t.doc.store,this),this.content.integrate(t,this),Xi(t,this.parent,this.parentSub),(this.parent._item!==null&&this.parent._item.deleted||this.parentSub!==null&&this.right!==null)&&this.delete(t)}else new X(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:S(this.id.client,this.id.clock+this.length-1)}mergeWith(t){if(this.constructor===t.constructor&&le(t.origin,this.lastId)&&this.right===t&&le(this.rightOrigin,t.rightOrigin)&&this.id.client===t.id.client&&this.id.clock+this.length===t.id.clock&&this.deleted===t.deleted&&this.redone===null&&t.redone===null&&this.content.constructor===t.content.constructor&&this.content.mergeWith(t.content)){let n=this.parent._searchMarker;return n&&n.forEach(r=>{r.p===t&&(r.p=this,!this.deleted&&this.countable&&(r.index-=this.length))}),t.keep&&(this.keep=!0),this.right=t.right,this.right!==null&&(this.right.left=this),this.length+=t.length,!0}return!1}delete(t){if(!this.deleted){let n=this.parent;this.countable&&this.parentSub===null&&(n._length-=this.length),this.markDeleted(),vn(t.deleteSet,this.id.client,this.id.clock,this.length),Xi(t,n,this.parentSub),this.content.delete(t)}}gc(t,n){if(!this.deleted)throw $();this.content.gc(t),n?Kd(t,this,new X(this.id,this.length)):this.content=new sn(this.length)}write(t,n){let r=n>0?S(this.id.client,this.id.clock+n-1):this.origin,s=this.rightOrigin,o=this.parentSub,i=this.content.getRef()&31|(r===null?0:128)|(s===null?0:64)|(o===null?0:32);if(t.writeInfo(i),r!==null&&t.writeLeftID(r),s!==null&&t.writeRightID(s),r===null&&s===null){let c=this.parent;if(c._item!==void 0){let l=c._item;if(l===null){let a=ao(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===Ut?(t.writeParentInfo(!1),t.writeLeftID(c)):$();o!==null&&t.writeString(o)}this.content.write(t,n)}},Yc=(e,t)=>Yu[t&31](e),Yu=[()=>{$()},Au,Iu,Cu,Ru,Tu,Uu,Fu,Ou,Du,()=>{$()}],zu=10,q=class extends rn{get deleted(){return!0}delete(){}mergeWith(t){return this.constructor!==t.constructor?!1:(this.length+=t.length,!0)}integrate(t,n){$()}write(t,n){t.writeInfo(zu),y(t.restEncoder,this.length-n)}getMissing(t,n){return null}},zc=typeof globalThis<"u"?globalThis:typeof window<"u"?window:typeof global<"u"?global:{},Gc="__ $YJS$ __";zc[Gc]===!0&&console.error("Yjs was already imported. This breaks constructor checks and will lead to issues! - https://github.com/yjs/yjs/issues/438");zc[Gc]=!0;var wo=3e4,cn=class extends Oe{constructor(t){super(),this.doc=t,this.clientID=t.clientID,this.states=new Map,this.meta=new Map,this._checkInterval=setInterval(()=>{let n=Pt();this.getLocalState()!==null&&wo/2<=n-this.meta.get(this.clientID).lastUpdated&&this.setLocalState(this.getLocalState());let r=[];this.meta.forEach((s,o)=>{o!==this.clientID&&wo<=n-s.lastUpdated&&this.states.has(o)&&r.push(o)}),r.length>0&&xo(this,r,"timeout")},F(wo/10)),t.on("destroy",()=>{this.destroy()}),this.setLocalState({})}destroy(){this.emit("destroy",[this]),this.setLocalState(null),super.destroy(),clearInterval(this._checkInterval)}getLocalState(){return this.states.get(this.clientID)||null}setLocalState(t){let n=this.clientID,r=this.meta.get(n),s=r===void 0?0:r.clock+1,o=this.states.get(n);t===null?this.states.delete(n):this.states.set(n,t),this.meta.set(n,{clock:s,lastUpdated:Pt()});let i=[],c=[],l=[],a=[];t===null?a.push(n):o==null?t!=null&&i.push(n):(c.push(n),ie(o,t)||l.push(n)),(i.length>0||l.length>0||a.length>0)&&this.emit("change",[{added:i,updated:l,removed:a},"local"]),this.emit("update",[{added:i,updated:c,removed:a},"local"])}setLocalStateField(t,n){let r=this.getLocalState();r!==null&&this.setLocalState({...r,[t]:n})}getStates(){return this.states}},xo=(e,t,n)=>{let r=[];for(let s=0;s<t.length;s++){let o=t[s];if(e.states.has(o)){if(e.states.delete(o),o===e.clientID){let i=e.meta.get(o);e.meta.set(o,{clock:i.clock+1,lastUpdated:Pt()})}r.push(o)}}r.length>0&&(e.emit("change",[{added:[],updated:[],removed:r},n]),e.emit("update",[{added:[],updated:[],removed:r},n]))};var qc=1,Gr="fromPersistence",qr="document",ln="state",be="savedAt",Hc="savedBy",Jc="version",Hr="gutenberg",So="syncManager",Kc="gutenberg-undo-ignored";var ke=(e=>(e.AUTHENTICATION_FAILED="authentication-failed",e.CONNECTION_EXPIRED="connection-expired",e.CONNECTION_LIMIT_EXCEEDED="connection-limit-exceeded",e.DOCUMENT_SIZE_LIMIT_EXCEEDED="document-size-limit-exceeded",e.PROTOCOL_MISMATCH="protocol-mismatch",e.UNKNOWN_ERROR="unknown-error",e))(ke||{}),Jr=class extends Error{constructor(e="unknown-error",t){super(t),this.code=e,this.name="ConnectionError"}};var Qc=Zt(Xc(),1),{lock:Zc,unlock:Tf}=(0,Qc.__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 tl(e){return function(...t){let n=performance.now(),r=e.apply(this,t),s=performance.now();return console.log(`[SyncManager][performance]: ${e.name} took ${(s-n).toFixed(2)} ms`),r}}function el(e){return((...t)=>e(...t))}function nl(e){return function(...t){setTimeout(()=>{e.apply(this,t)},0)}}var Dl=Zt(Kr(),1);var El=Zt(Kr(),1);var sl=0,ol=1,Gu=2,il=(e,t)=>{y(e,sl);let n=lo(t);Y(e,n)},qu=(e,t,n)=>{y(e,ol),Y(e,oo(t,n))},Hu=(e,t,n)=>qu(t,n,z(e)),cl=(e,t,n,r)=>{try{so(t,z(e),n)}catch(s){r?.(s),console.error("Caught error while handling a Yjs update",s)}};var Ju=cl,_o=(e,t,n,r,s)=>{let o=_(e);switch(o){case sl:Hu(e,t,n);break;case ol:cl(e,n,r,s);break;case Gu:Ju(e,n,r,s);break;default:throw new Error("Unknown message type")}return o};var ll=Zt(Kr(),1),Eo=3,bo=[2e3,4e3,8e3,12e3],ko=[1e3,2e3,4e3,8e3],al=3e4,dl=15e3,Wu=1*1024*1024,Co=Math.floor(Wu/4)*3,jn=50,Wr=15*1024*1024,ul=2*1024*1024,Xu=4e3,Qu=1e3;function hl(e,t){let n=(0,ll.applyFilters)(e,t);return typeof n!="number"||!Number.isFinite(n)||n<=0?t:Math.min(n,t)}var Ao=hl("sync.pollingManager.pollingInterval",Xu),fl=hl("sync.pollingManager.pollingIntervalWithCollaborators",Qu),pl=25*1e3;var tt=(e=>(e.COMPACTION="compaction",e.SYNC_STEP_1="sync_step1",e.SYNC_STEP_2="sync_step2",e.UPDATE="update",e))(tt||{});var Do=Zt(ml(),1);var yl="/wp-sync/v1/updates";function Zu(e){let t="",n=e.byteLength;for(let r=0;r<n;r++)t+=String.fromCharCode(e[r]);return globalThis.btoa(t)}function To(e){let t=globalThis.atob(e),n=t.length,r=new Uint8Array(n);for(let s=0;s<n;s++)r[s]=t.charCodeAt(s);return r}function an(e,t){return{data:Zu(e),type:t}}function wl(e=[],t=!0){let n=t,r=[...e];return{add(s){r.push(s)},addBulk(s){s.length!==0&&r.push(...s)},clear(){r.splice(0,r.length)},get(){return n?[]:r.splice(0,r.length)},pause(){n=!0},peek(){return n?[]:[...r]},restore(s){let o=s.filter(i=>i.type!==tt.COMPACTION);o.length!==0&&r.unshift(...o)},restoreExact(s){s.length!==0&&r.unshift(...s)},resume(){n=!1},size(){return r.length},take(s){return n||s<=0?[]:r.splice(0,s)}}}function xl(e){return(0,Do.default)({method:"POST",path:yl,data:e})}function Uo(e){e.rooms.length!==0&&(0,Do.default)({method:"POST",path:yl,data:e,keepalive:!0}).catch(()=>{})}function Sl(e,t){let n=parseInt(String(e),10);return isNaN(n)?t:n}function _l(e,t,n){if(e.length===0)return{window:[],nextOffset:0};let r=(t%e.length+e.length)%e.length;return{window:[...e.slice(r),...e.slice(0,r)].slice(0,Math.max(0,n)),nextOffset:(r+Math.max(0,n))%e.length}}var Gn="polling-manager";function th(e){return e?.data?.status===403}function eh(e){return e?.data?.status===413&&e?.code==="rest_sync_body_too_large"}function nh(e){return e?.code==="rest_sync_protocol_mismatch"}function rh(e,t){let n=new Set(t.map(s=>s.room)),r=Array.isArray(e.data.rooms)?e.data.rooms.filter(s=>n.has(s)):[];if(r.length>0){for(let s of r){let o=T.get(s);o&&(o.log("Permission denied, unregistering room",{error:e},"error",!0),dn(s,{sendDisconnectSignal:!1}))}for(let s of t){if(r.includes(s.room)||!T.has(s.room))continue;let o=T.get(s.room);s.updates.length>0&&o.updateQueue.restore(s.updates)}}else{let s=[...T.keys()];for(let o of s){let i=T.get(o);i&&(i.log("Permission denied, unregistering room",{error:e},"error",!0),dn(o,{sendDisconnectSignal:!1}))}}}var T=new Map;function sh(e){let t=e.filter(n=>[tt.COMPACTION,tt.UPDATE].includes(n.type)).map(n=>To(n.data));return an(pe(t),tt.COMPACTION)}function oh(e){let t=gt();return il(t,e),an(K(t),tt.SYNC_STEP_1)}function ih(e,t){let n=N(t),r=gt();return _o(n,r,e,Gn),an(K(r),tt.SYNC_STEP_2)}function ch(e,t){let n=t.getStates(),r=new Set,s=new Set,o=new Set(Array.from(n.keys()).filter(i=>!e[i]));Object.entries(e).forEach(([i,c])=>{let l=Number(i);if(l===t.clientID)return;if(c===null){n.delete(l),o.add(l);return}if(!n.has(l)){n.set(l,c),r.add(l);return}let a=n.get(l);JSON.stringify(a)!==JSON.stringify(c)&&(n.set(l,c),s.add(l))}),r.size+s.size>0&&t.emit("change",[{added:Array.from(r),updated:Array.from(s),removed:[]}]),o.size>0&&xo(t,Array.from(o),Gn)}function lh(e,t,n){let r=To(e.data);switch(e.type){case tt.SYNC_STEP_1:return ih(t,r);case tt.SYNC_STEP_2:{let s=N(r),o=gt();_o(s,o,t,Gn),n();return}case tt.COMPACTION:case tt.UPDATE:At(t,r,Gn)}}function ah(e,t){if(!t.isPrimaryRoom||Io)return!1;Io=!0;let n=(0,El.applyFilters)("sync.pollingProvider.maxClientsPerRoom",Eo,t.room),r=Object.keys(e).length,s=Sl(n,Eo);return r>s?(t.log("Connection limit exceeded",{clientCount:r,maxClientsPerRoom:s,room:t.room}),!0):!1}var Qr=!1,Ce=0,Io=!1,Xr=!1,Fn=!1,zn=document.visibilityState==="visible",Yn=!1,vo=!1,yt=Ao,Jt=null,Ae=Wr,Oo=0;function bl(){vo=!0}function kl(){let e=Array.from(T.entries()).map(([t,n])=>({after:0,awareness:null,client_id:n.clientId,room:t,updates:[]}));for(let t=0;t<e.length;t+=jn)Uo({rooms:e.slice(t,t+jn)})}function Cl(){let e=zn;zn=document.visibilityState==="visible",zn&&!e&&Jt&&(clearTimeout(Jt),Jt=null,Zr())}function dh(){let e=Array.from(T.values());if(e.length<=jn)return e;let t=e.find(i=>i.isPrimaryRoom),n=e.filter(i=>i!==t),r=jn-(t?1:0),{window:s,nextOffset:o}=_l(n,Oo,r);return Oo=o,t?[t,...s]:s}var uh=new TextEncoder;function Ro(e){return uh.encode(JSON.stringify(e)).byteLength}function hh(e,t=[]){return{after:e.endCursor??0,awareness:e.localAwarenessState,client_id:e.clientId,room:e.room,updates:t}}function fh(e,t){return(e===0?0:1)+Ro(t)}function ph(e){let t={rooms:[]},n=[];for(let c of e){let l=hh(c),a={rooms:[...t.rooms,l]};if(t.rooms.length>0&&Ro(a)>Ae)break;t.rooms.push(l),n.push(c)}let r=n.map(c=>c.updateQueue.peek()),s=n.map(()=>0),o=Ro(t),i=!0;for(;i;){i=!1;for(let c=0;c<n.length;c++){let l=r[c][s[c]];if(!l)continue;let a=fh(s[c],l);o+a>Ae||(s[c]++,o+=a,i=!0)}}for(let c=0;c<n.length;c++)t.rooms[c].updates=n[c].updateQueue.take(s[c]);return{payload:t,roomsInRequest:n}}function gh(e){for(let t of e.rooms)!T.has(t.room)||t.updates.length===0||T.get(t.room).updateQueue.restoreExact(t.updates)}function Zr(){Yn=!0,Jt=null;async function e(){if(T.size===0){Yn=!1;return}vo=!1;let{payload:t,roomsInRequest:n}=ph(dh());n.forEach(r=>{r.onStatusChange({status:"connecting"})});try{let{rooms:r}=await xl(t);Ce=0,Xr=!1,Ae=Wr,n.forEach(s=>{T.get(s.room)===s&&s.onStatusChange({status:"connected"})}),Fn=!1,r.forEach(s=>{if(!T.has(s.room))return;let o=T.get(s.room);if(o.endCursor=s.end_cursor,ah(s.awareness,o)){o.onStatusChange({status:"disconnected",error:new Jr(ke.CONNECTION_LIMIT_EXCEEDED,"Connection limit exceeded")}),dn(s.room);return}o.processAwarenessUpdate(s.awareness),o.isPrimaryRoom&&Object.keys(s.awareness).length>1&&(Fn=!0,T.forEach(c=>{c.updateQueue.resume()}));let i=[];for(let c of s.updates)try{let l=o.processDocUpdate(c);l&&i.push(l)}catch(l){o.log("Failed to apply sync update",{error:l,update:c},"error",!0)}o.updateQueue.addBulk(i),s.should_compact?(o.log("Server requested compaction update"),o.updateQueue.clear(),o.updateQueue.add(o.createCompactionUpdate())):s.compaction_request&&(o.log("Server requested (old) compaction update"),o.updateQueue.add(sh(s.compaction_request)))}),zn&&Fn?yt=fl:zn?yt=Ao:yt=pl}catch(r){if(th(r)){if(rh(r,t.rooms),T.size===0){Yn=!1;return}}else if(eh(r)){Ae=Math.max(ul,Math.floor(Ae/2)),yt=Fn?ko[0]:bo[0],gh(t);for(let s of t.rooms)T.has(s.room)&&T.get(s.room).log("Sync request body too large, retrying with smaller batches",{error:r,nextPoll:yt,syncRequestBodySizeLimit:Ae},"error",!0)}else if(nh(r)){let s=[...T.entries()];for(let[,o]of s)o.onStatusChange({status:"disconnected",error:new Jr(ke.PROTOCOL_MISMATCH,"Protocol mismatch between client and server")});for(let[o]of s)dn(o,{sendDisconnectSignal:!1});Yn=!1;return}else{Ce++;let s=Fn?ko:bo;Ce<=s.length?yt=s[Ce-1]:yt=al,Xr&&(yt=dl,Xr=!1);for(let o of t.rooms){if(!T.has(o.room))continue;let i=T.get(o.room);o.updates.length>0&&i.endCursor>0?(i.updateQueue.clear(),i.updateQueue.add(i.createCompactionUpdate())):o.updates.length>0&&i.updateQueue.restore(o.updates),i.log("Error posting sync update, will retry with backoff",{error:r,nextPoll:yt},"error",!0)}if(!vo){let o=Ce>s.length;n.forEach(i=>{T.get(i.room)===i&&i.onStatusChange({status:"disconnected",canManuallyRetry:!0,consecutiveFailures:Ce,backgroundRetriesFailed:o,willAutoRetryInMs:yt})})}}}Jt=setTimeout(Zr,yt)}e()}function mh({room:e,doc:t,awareness:n,log:r,onSync:s,onStatusChange:o}){if(T.has(e))return;let i=wl([oh(t)]),c=T.size===0;function l(){u.localAwarenessState=n.getLocalState()??{}}function a(h,f){if(Gn!==f){if(h.byteLength>Co){let p=T.get(e);if(!p)return;p.log("Document size limit exceeded",{maxUpdateSizeInBytes:Co,updateSizeInBytes:h.byteLength}),p.onStatusChange({status:"disconnected",error:new Jr(ke.DOCUMENT_SIZE_LIMIT_EXCEEDED,"Document size limit exceeded")}),dn(e);return}i.add(an(h,tt.UPDATE))}}function d(){t.off("updateV2",a),n.off("change",l),i.clear()}let u={clientId:t.clientID,createCompactionUpdate:()=>an(qt(t),tt.COMPACTION),endCursor:0,isPrimaryRoom:c,localAwarenessState:n.getLocalState()??{},log:r,onStatusChange:o,processAwarenessUpdate:h=>ch(h,n),processDocUpdate:h=>lh(h,t,s),room:e,unregister:d,updateQueue:i};t.on("updateV2",a),n.on("change",l),T.set(e,u),Qr||(window.addEventListener("beforeunload",bl),window.addEventListener("pagehide",kl),document.addEventListener("visibilitychange",Cl),Qr=!0),Yn||Zr()}function dn(e,{sendDisconnectSignal:t=!0}={}){let n=T.get(e);if(n){if(t){let r=[{after:0,awareness:null,client_id:n.clientId,room:e,updates:[]}];Uo({rooms:r})}n.unregister(),T.delete(e)}T.size===0&&Qr&&(window.removeEventListener("beforeunload",bl),window.removeEventListener("pagehide",kl),document.removeEventListener("visibilitychange",Cl),Qr=!1,Io=!1,Ce=0,Oo=0,Ae=Wr)}function yh(){Xr=!0,Jt&&(clearTimeout(Jt),Jt=null,Zr())}var qn={registerRoom:mh,retryNow:yh,unregisterRoom:dn};var wh=class extends Nt{constructor(e){super(),this.options=e,this.log("Initializing",{room:e.room}),this.awareness=e.awareness??new cn(e.ydoc),this.connect()}awareness;status="disconnected";synced=!1;connect(){this.log("Connecting"),qn.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"),qn.unregisterRoom(this.options.room),this.emitStatus({status:"disconnected"})}emitStatus=e=>{let{status:t}=e,n=t==="disconnected"?e.error:void 0;this.status===t&&!n||t==="connecting"&&this.status!=="disconnected"||(this.log("Status change",{status:t,error:n}),this.status=t,this.emit("status",[e]))};log=(e,t={},n="log",r=!1)=>{if(!this.options.debug&&!r)return;(console[n]||console.log)(`[${this.constructor.name}]: ${e}`,{room:this.options.room,...t})};onSync=()=>{this.synced||(this.synced=!0,this.log("Synced"))}};function Al(){return async({awareness:e,objectType:t,objectId:n,ydoc:r})=>{let s=n?`${t}:${n}`:t,o=new wh({awareness:e,room:s,ydoc:r});return{destroy:()=>o.destroy(),on:(i,c)=>{o.on(i,c)}}}}var un=null;function xh(){return[Al()]}function Sh(e){return typeof e=="function"}function Lo(){if(un)return un;if(!window._wpCollaborationEnabled)return[];let e=(0,Dl.applyFilters)("sync.providers",xh());return Array.isArray(e)?(un=e.filter(Sh),un):(un=[],un)}var Tl=(e,t)=>{let n=t==="undo"?e.undoStack:e.redoStack;for(;n.length>0;){let r=n.pop(),s=t==="undo"?r.undoStack:r.redoStack,o=s.pop(),i=!1;if(t==="undo"?(r.undoStack=[o],i=r.undo()!==null,r.undoStack=s):(r.redoStack=[o],i=r.redo()!==null,r.redoStack=s),i)return o}return null},Ul=class extends Oe{constructor(e=[],t={}){super(),this.docs=new Map,this.trackedOrigins=t.trackedOrigins||new Set([null]),t.trackedOrigins=this.trackedOrigins,this._defaultOpts=t,this.undoStack=[],this.redoStack=[],this.addToScope(e)}addToScope(e){e=pt(e)?e:[e],e.forEach(t=>{let n=t.doc,r=B(this.docs,n,()=>{let s=new fe([t],this._defaultOpts);return s.on("stack-cleared",({undoStackCleared:o,redoStackCleared:i})=>{this.clear(o,i)}),n.on("destroy",()=>{this.docs.delete(n),this.undoStack=this.undoStack.filter(o=>o.doc!==n),this.redoStack=this.redoStack.filter(o=>o.doc!==n)}),s.on("stack-item-added",o=>{(o.type==="undo"?this.undoStack:this.redoStack).push(s),this.emit("stack-item-added",[{...o,ydoc:n},this])}),s.on("stack-item-updated",o=>{this.emit("stack-item-updated",[{...o,ydoc:n},this])}),s.on("stack-item-popped",o=>{this.emit("stack-item-popped",[{...o,ydoc:n},this])}),s});r.scope.every(s=>s!==t)&&r.scope.push(t)})}addTrackedOrigin(e){this.trackedOrigins.add(e)}removeTrackedOrigin(e){this.trackedOrigins.delete(e)}undo(){return Tl(this,"undo")}redo(){return Tl(this,"redo")}clear(e=!0,t=!0){(e&&this.canUndo()||t&&this.canRedo())&&(this.docs.forEach(n=>{e&&(this.undoStack=[]),t&&(this.redoStack=[]),n.clear(e,t)}),this.emit("stack-cleared",[{undoStackCleared:e,redoStackCleared:t}]))}stopCapturing(){this.docs.forEach(e=>{e.stopCapturing()})}canUndo(){return this.undoStack.length>0}canRedo(){return this.redoStack.length>0}destroy(){this.docs.forEach(e=>e.destroy()),super.destroy()}};function Il(){let e=new Map,t=new Ul([],{captureTimeout:500,trackedOrigins:new Set([Hr])}),n=()=>({hasRedo:t.canRedo(),hasUndo:t.canUndo()}),r=s=>{e.get(s)?.onUndoStackChange?.(n())};return t.on("stack-item-added",s=>{let o=e.get(s.ydoc);o&&(o.addUndoMeta(s.ydoc,s.stackItem.meta),r(s.ydoc))}),t.on("stack-item-updated",s=>{r(s.ydoc)}),t.on("stack-item-popped",s=>{let o=e.get(s.ydoc);o&&(o.restoreUndoMeta(s.ydoc,s.stackItem.meta),r(s.ydoc))}),t.on("stack-cleared",()=>{e.forEach(s=>{s.onUndoStackChange?.(n())})}),{addRecord(s,o=!1){},addToScope(s,o){if(s.doc===null)return;let i=s.doc;t.addToScope(s),e.has(i)||i.on("destroy",()=>e.delete(i)),e.set(i,o)},undo(){if(t.canUndo())return t.undo(),[]},redo(){if(t.canRedo())return t.redo(),[]},hasUndo(){return t.canUndo()},hasRedo(){return t.canRedo()},stopCapturing(){t.stopCapturing()}}}function ts(e={}){let t=new Map(Object.entries(e));return new bt({meta:t})}function No(e){e.getMap(ln).set(Jc,qc)}function Mo(e){let t=e.getMap(ln);t.set(be,Date.now()),t.set(Hc,e.clientID)}function vl(){return Math.floor(Math.random()*1e9)}function Ol(e){return JSON.stringify({document:Si(qt(e)),updateId:vl()})}function Rl(e){try{let{document:t}=JSON.parse(e),n={[Gr]:!0},r=ts(n),s=_i(t);return At(r,s),r.clientID=vl(),r}catch{return null}}function Kt(e,t){return`${e}_${t}`}function Ll(e=!1){let t=e?tl:el,n=new Map,r=new Map,s;function o(g,x,w,k={}){e&&console.log(`[SyncManager][${g}]: ${x}`,{...k,entityId:w})}async function i(g,x,w,k,b){let O=Lo(),U=Kt(x,w);if(O.length===0){o("loadEntity","no providers, skipping",U);return}if(r.has(U)){o("loadEntity","already loaded",U);return}if(g.shouldSync?.(x,w)===!1){o("loadEntity","shouldSync false, skipping",U);return}o("loadEntity","loading",U),b={addUndoMeta:t(b.addUndoMeta),editRecord:t(b.editRecord),getEditedRecord:t(b.getEditedRecord),onStatusChange:t(b.onStatusChange),persistCRDTDoc:t(b.persistCRDTDoc),refetchRecord:t(b.refetchRecord),restoreUndoMeta:t(b.restoreUndoMeta),onUndoStackChange:b.onUndoStackChange?t(b.onUndoStackChange):void 0};let j=ts({objectType:x}),nt=j.getMap(qr),J=j.getMap(ln),Ot=Date.now(),rt=!1,Wt=!1,Xt=()=>{o("loadEntity","unloading",U),Wt=!0,rs?.forEach(Lt=>Lt.destroy()),b.onStatusChange(null),rt&&(nt.unobserveDeep(lt),J.unobserve(Dt)),j.destroy(),r.delete(U)},Rt=g.createAwareness?.(j,w),lt=(Lt,Qt)=>{Qt.local&&!(Qt.origin instanceof fe)||C.updateEntityRecord(x,w)},Dt=(Lt,Qt)=>{Qt.local||Lt.keysChanged.forEach(Yl=>{if(Yl===be){let Go=J.get(be);typeof Go=="number"&&Go>Ot&&(o("loadEntity","refetching record",U),b.refetchRecord().catch(()=>{}))}})};s||(s=Il());let{addUndoMeta:Ue,onUndoStackChange:Hn,restoreUndoMeta:jl}=b;s.addToScope(nt,{addUndoMeta:Ue,restoreUndoMeta:jl,onUndoStackChange:Hn});let rs,Fl={awareness:Rt,handlers:b,objectId:w,objectType:x,syncConfig:g,unload:Xt,ydoc:j};if(r.set(U,Fl),o("loadEntity","connecting",U),rs=await Promise.all(O.map(async Lt=>{let Qt=await Lt({objectType:x,objectId:w,ydoc:j,awareness:Rt});return Qt.on("status",b.onStatusChange),Qt})),Wt){o("loadEntity","unloaded during connect, aborting",U),rs.forEach(Lt=>Lt.destroy());return}No(j),C.applyPersistedCrdtDoc(x,w,k),nt.observeDeep(lt),J.observe(Dt),rt=!0}async function c(g,x,w){let k=Lo(),b=Kt(x,null);if(k.length===0){o("loadCollection","no providers, skipping",b);return}if(n.has(x)){o("loadCollection","already loaded",b);return}if(g.shouldSync?.(x,null)===!1){o("loadCollection","shouldSync false, skipping",b);return}o("loadCollection","loading",b);let O=ts({collection:!0,objectType:x}),U=O.getMap(ln),j=Date.now(),nt=!1,J=!1,Ot=()=>{o("loadCollection","unloading",b),J=!0,Xt?.forEach(lt=>lt.destroy()),w.onStatusChange(null),nt&&U.unobserve(rt),O.destroy(),n.delete(x)},rt=(lt,Dt)=>{Dt.local||lt.keysChanged.forEach(Ue=>{if(Ue===be){let Hn=U.get(be);typeof Hn=="number"&&Hn>j&&w.refetchRecords().catch(()=>{})}})},Wt=g.createAwareness?.(O),Xt,Rt={awareness:Wt,handlers:w,syncConfig:g,unload:Ot,ydoc:O};if(n.set(x,Rt),o("loadCollection","connecting",b),Xt=await Promise.all(k.map(async lt=>{let Dt=await lt({awareness:Wt,objectType:x,objectId:null,ydoc:O});return Dt.on("status",w.onStatusChange),Dt})),J){o("loadCollection","unloaded during connect, aborting",b),Xt.forEach(lt=>lt.destroy());return}U.observe(rt),nt=!0,No(O)}function l(g,x){let w=Kt(g,x);o("unloadEntity","unloading",w),r.get(w)?.unload(),h(g,null,{},origin,{isSave:!0})}function a(){o("unloadAll","unloading all entities","all");for(let[,g]of[...r])g.unload();r.clear(),s=void 0;for(let[,g]of[...n])g.unload();n.clear()}function d(g,x){let w=Kt(g,x),k=r.get(w);if(!(!k||!k.awareness))return k.awareness}function u(g,x,w){let k=Kt(g,x),b=r.get(k);if(!b){o("applyPersistedCrdtDoc","no entity state",k);return}let{handlers:O,syncConfig:{applyChangesToCRDTDoc:U,getChangesFromCRDTDoc:j,getPersistedCRDTDoc:nt},ydoc:J}=b,Ot=nt?.(w),rt=Ot?Rl(Ot):null;if(!rt){o("applyPersistedCrdtDoc","no persisted doc",k),J.transact(()=>{U(J,w),O.persistCRDTDoc()},So);return}let Wt=qt(rt);At(J,Wt);let Xt=j(rt,w),Rt=Object.keys(Xt);if(rt.destroy(),Rt.length===0){o("applyPersistedCrdtDoc","valid persisted doc",k);return}o("applyPersistedCrdtDoc","invalidated keys",k,{invalidatedKeys:Rt});let lt=Rt.reduce((Dt,Ue)=>Object.assign(Dt,{[Ue]:w[Ue]}),{});J.transact(()=>{U(J,lt),O.persistCRDTDoc()},So)}function h(g,x,w,k,b={}){let{isSave:O=!1,isNewUndoLevel:U=!1}=b,j=Kt(g,x),nt=r.get(j),J=n.get(g);if(nt){let{syncConfig:Ot,ydoc:rt}=nt;U&&s&&s.stopCapturing?.(),rt.transact(()=>{o("updateCRDTDoc","applying changes",j,{changedKeys:Object.keys(w)}),Ot.applyChangesToCRDTDoc(rt,w),O&&Mo(rt)},k)}J&&O&&J.ydoc.transact(()=>{Mo(J.ydoc)},k)}let f=nl(h);function p(g,x,w,k,b={}){((d(g,x)?.getStates().size??0)>1?h:f)(g,x,w,k,b)}async function m(g,x){let w=Kt(g,x),k=r.get(w);if(!k){o("updateEntityRecord","no entity state",w);return}let{handlers:b,syncConfig:O,ydoc:U}=k,j=O.getChangesFromCRDTDoc(U,await b.getEditedRecord()),nt=Object.keys(j);nt.length!==0&&(o("updateEntityRecord","changes",w,{changedKeys:nt}),b.editRecord(j))}async function E(g,x){let w=Kt(g,x),k=r.get(w);return k?.ydoc?(await new Promise(b=>setTimeout(b,0)),Ol(k.ydoc)):null}let C={applyPersistedCrdtDoc:t(u),updateEntityRecord:t(m)};return{createPersistedCRDTDoc:t(E),getAwareness:d,load:t(i),loadCollection:t(c),get undoManager(){return s},unload:t(l),unloadAll:t(a),update:t(p)}}var De=class{diff(t,n,r={}){let s;typeof r=="function"?(s=r,r={}):"callback"in r&&(s=r.callback);let o=this.castInput(t,r),i=this.castInput(n,r),c=this.removeEmpty(this.tokenize(o,r)),l=this.removeEmpty(this.tokenize(i,r));return this.diffWithOptionsObj(c,l,r,s)}diffWithOptionsObj(t,n,r,s){var o;let i=g=>{if(g=this.postProcess(g,r),s){setTimeout(function(){s(g)},0);return}else return g},c=n.length,l=t.length,a=1,d=c+l;r.maxEditLength!=null&&(d=Math.min(d,r.maxEditLength));let u=(o=r.timeout)!==null&&o!==void 0?o:1/0,h=Date.now()+u,f=[{oldPos:-1,lastComponent:void 0}],p=this.extractCommon(f[0],n,t,0,r);if(f[0].oldPos+1>=l&&p+1>=c)return i(this.buildValues(f[0].lastComponent,n,t));let m=-1/0,E=1/0,C=()=>{for(let g=Math.max(m,-a);g<=Math.min(E,a);g+=2){let x,w=f[g-1],k=f[g+1];w&&(f[g-1]=void 0);let b=!1;if(k){let U=k.oldPos-g;b=k&&0<=U&&U<c}let O=w&&w.oldPos+1<l;if(!b&&!O){f[g]=void 0;continue}if(!O||b&&w.oldPos<k.oldPos?x=this.addToPath(k,!0,!1,0,r):x=this.addToPath(w,!1,!0,1,r),p=this.extractCommon(x,n,t,g,r),x.oldPos+1>=l&&p+1>=c)return i(this.buildValues(x.lastComponent,n,t))||!0;f[g]=x,x.oldPos+1>=l&&(E=Math.min(E,g-1)),p+1>=c&&(m=Math.max(m,g+1))}a++};if(s)(function g(){setTimeout(function(){if(a>d||Date.now()>h)return s(void 0);C()||g()},0)})();else for(;a<=d&&Date.now()<=h;){let g=C();if(g)return g}}addToPath(t,n,r,s,o){let i=t.lastComponent;return i&&!o.oneChangePerToken&&i.added===n&&i.removed===r?{oldPos:t.oldPos+s,lastComponent:{count:i.count+1,added:n,removed:r,previousComponent:i.previousComponent}}:{oldPos:t.oldPos+s,lastComponent:{count:1,added:n,removed:r,previousComponent:i}}}extractCommon(t,n,r,s,o){let i=n.length,c=r.length,l=t.oldPos,a=l-s,d=0;for(;a+1<i&&l+1<c&&this.equals(r[l+1],n[a+1],o);)a++,l++,d++,o.oneChangePerToken&&(t.lastComponent={count:1,previousComponent:t.lastComponent,added:!1,removed:!1});return d&&!o.oneChangePerToken&&(t.lastComponent={count:d,previousComponent:t.lastComponent,added:!1,removed:!1}),t.oldPos=l,a}equals(t,n,r){return r.comparator?r.comparator(t,n):t===n||!!r.ignoreCase&&t.toLowerCase()===n.toLowerCase()}removeEmpty(t){let n=[];for(let r=0;r<t.length;r++)t[r]&&n.push(t[r]);return n}castInput(t,n){return t}tokenize(t,n){return Array.from(t)}join(t){return t.join("")}postProcess(t,n){return t}get useLongestToken(){return!1}buildValues(t,n,r){let s=[],o;for(;t;)s.push(t),o=t.previousComponent,delete t.previousComponent,t=o;s.reverse();let i=s.length,c=0,l=0,a=0;for(;c<i;c++){let d=s[c];if(d.removed)d.value=this.join(r.slice(a,a+d.count)),a+=d.count;else{if(!d.added&&this.useLongestToken){let u=n.slice(l,l+d.count);u=u.map(function(h,f){let p=r[a+f];return p.length>h.length?p:h}),d.value=this.join(u)}else d.value=this.join(n.slice(l,l+d.count));l+=d.count,d.added||(a+=d.count)}}return s}};var Vo=class extends De{},Nl=new Vo;function es(e,t,n){return Nl.diff(e,t,n)}var Bo=class extends De{constructor(){super(...arguments),this.tokenize=_h}equals(t,n,r){return r.ignoreWhitespace?((!r.newlineIsToken||!t.includes(`
`))&&(t=t.trim()),(!r.newlineIsToken||!n.includes(`
`))&&(n=n.trim())):r.ignoreNewlineAtEof&&!r.newlineIsToken&&(t.endsWith(`
`)&&(t=t.slice(0,-1)),n.endsWith(`
`)&&(n=n.slice(0,-1))),super.equals(t,n,r)}},Ml=new Bo;function Po(e,t,n){return Ml.diff(e,t,n)}function _h(e,t){t.stripTrailingCr&&(e=e.replace(/\r\n/g,`
`));let n=[],r=e.split(/(\n|\r\n)/);r[r.length-1]||r.pop();for(let s=0;s<r.length;s++){let o=r[s];s%2&&!t.newlineIsToken?n[n.length-1]+=o:n.push(o)}return n}var ns=Zt($o(),1);var Bl=Zt($o(),1);function Eh(e){return JSON.parse(JSON.stringify(e))}var jo;(e=>{function t(o={},i={},c=!1){typeof o!="object"&&(o={}),typeof i!="object"&&(i={});let l=Eh(i);c||(l=Object.keys(l).reduce((a,d)=>((l[d]!==null||l[d]!==void 0)&&(a[d]=l[d]),a),{}));for(let a in o)o[a]!==void 0&&i[a]===void 0&&(l[a]=o[a]);return Object.keys(l).length>0?l:void 0}e.compose=t;function n(o={},i={}){typeof o!="object"&&(o={}),typeof i!="object"&&(i={});let c=Object.keys(o).concat(Object.keys(i)).reduce((l,a)=>((0,Bl.default)(o[a],i[a])||(l[a]=i[a]===void 0?null:i[a]),l),{});return Object.keys(c).length>0?c:void 0}e.diff=n;function r(o={},i={}){o=o||{};let c=Object.keys(i).reduce((l,a)=>(i[a]!==o[a]&&o[a]!==void 0&&(l[a]=i[a]),l),{});return Object.keys(o).reduce((l,a)=>(o[a]!==i[a]&&i[a]===void 0&&(l[a]=null),l),c)}e.invert=r;function s(o,i,c=!1){if(typeof o!="object")return i;if(typeof i!="object")return;if(!c)return i;let l=Object.keys(i).reduce((a,d)=>(o[d]===void 0&&(a[d]=i[d]),a),{});return Object.keys(l).length>0?l:void 0}e.transform=s})(jo||(jo={}));var Te=jo;var Fo;(e=>{function t(n){return typeof n.delete=="number"?n.delete:typeof n.retain=="number"?n.retain:typeof n.retain=="object"&&n.retain!==null?1:typeof n.insert=="string"?n.insert.length:1}e.length=t})(Fo||(Fo={}));var ht=Fo;var Q=class{ops;index;offset;constructor(e){this.ops=e,this.index=0,this.offset=0}hasNext(){return this.peekLength()<1/0}next(e){e||(e=1/0);let t=this.ops[this.index];if(t){let n=this.offset,r=ht.length(t);if(e>=r-n?(e=r-n,this.index+=1,this.offset=0):this.offset+=e,typeof t.delete=="number")return{delete:e};let s={};return t.attributes&&(s.attributes=t.attributes),typeof t.retain=="number"?s.retain=e:typeof t.retain=="object"&&t.retain!==null?s.retain=t.retain:typeof t.insert=="string"?s.insert=t.insert.substr(n,e):s.insert=t.insert,s}return{retain:1/0}}peek(){return this.ops[this.index]}peekLength(){return this.ops[this.index]?ht.length(this.ops[this.index])-this.offset:1/0}peekType(){let e=this.ops[this.index];return e?typeof e.delete=="number"?"delete":typeof e.retain=="number"||typeof e.retain=="object"&&e.retain!==null?"retain":"insert":"retain"}rest(){if(this.hasNext()){if(this.offset===0)return this.ops.slice(this.index)}else return[];let e=this.offset,t=this.index,n=this.next(),r=this.ops.slice(this.index);return this.offset=e,this.index=t,[n].concat(r)}};function bh(e){return JSON.parse(JSON.stringify(e))}var kh="\0",Ch=1e4;function Yo(e){return e.map(t=>({...t,count:t.value.length}))}var Pl=(e,t)=>{if(typeof e!="object"||e===null)throw new Error(`cannot retain a ${typeof e}`);if(typeof t!="object"||t===null)throw new Error(`cannot retain a ${typeof t}`);let n=Object.keys(e)[0];if(!n||n!==Object.keys(t)[0])throw new Error(`embed types not matched: ${n} != ${Object.keys(t)[0]}`);return[n,e[n],t[n]]},Ah=class et{static Op=ht;static OpIterator=Q;static AttributeMap=Te;static handlers={};static registerEmbed(t,n){this.handlers[t]=n}static unregisterEmbed(t){delete this.handlers[t]}static getHandler(t){let n=this.handlers[t];if(!n)throw new Error(`no handlers for embed type "${t}"`);return n}ops;constructor(t){Array.isArray(t)?this.ops=t:t!=null&&Array.isArray(t.ops)?this.ops=t.ops:this.ops=[]}insert(t,n){let r={};return typeof t=="string"&&t.length===0?this:(r.insert=t,n!=null&&typeof n=="object"&&Object.keys(n).length>0&&(r.attributes=n),this.push(r))}delete(t){return t<=0?this:this.push({delete:t})}retain(t,n){if(typeof t=="number"&&t<=0)return this;let r={retain:t};return n!=null&&typeof n=="object"&&Object.keys(n).length>0&&(r.attributes=n),this.push(r)}push(t){let n=this.ops.length,r=this.ops[n-1];if(t=bh(t),typeof r=="object"){if(typeof t.delete=="number"&&typeof r.delete=="number")return this.ops[n-1]={delete:r.delete+t.delete},this;if(typeof r.delete=="number"&&t.insert!==null&&t.insert!==void 0&&(n-=1,r=this.ops[n-1],typeof r!="object"))return this.ops.unshift(t),this;if((0,ns.default)(t.attributes,r.attributes)){if(typeof t.insert=="string"&&typeof r.insert=="string")return this.ops[n-1]={insert:r.insert+t.insert},typeof t.attributes=="object"&&(this.ops[n-1].attributes=t.attributes),this;if(typeof t.retain=="number"&&typeof r.retain=="number")return this.ops[n-1]={retain:r.retain+t.retain},typeof t.attributes=="object"&&(this.ops[n-1].attributes=t.attributes),this}}return n===this.ops.length?this.ops.push(t):this.ops.splice(n,0,t),this}chop(){let t=this.ops[this.ops.length-1];return t&&typeof t.retain=="number"&&!t.attributes&&this.ops.pop(),this}filter(t){return this.ops.filter(t)}forEach(t){this.ops.forEach(t)}map(t){return this.ops.map(t)}partition(t){let n=[],r=[];return this.forEach(s=>{(t(s)?n:r).push(s)}),[n,r]}reduce(t,n){return this.ops.reduce(t,n)}changeLength(){return this.reduce((t,n)=>n.insert?t+ht.length(n):n.delete?t-n.delete:t,0)}length(){return this.reduce((t,n)=>t+ht.length(n),0)}slice(t=0,n=1/0){let r=[],s=new Q(this.ops),o=0;for(;o<n&&s.hasNext();){let i;o<t?i=s.next(t-o):(i=s.next(n-o),r.push(i)),o+=ht.length(i)}return new et(r)}compose(t){let n=new Q(this.ops),r=new Q(t.ops),s=[],o=r.peek();if(o!=null&&typeof o.retain=="number"&&(o.attributes===null||o.attributes===void 0)){let c=o.retain;for(;n.peekType()==="insert"&&n.peekLength()<=c;)c-=n.peekLength(),s.push(n.next());o.retain-c>0&&r.next(o.retain-c)}let i=new et(s);for(;n.hasNext()||r.hasNext();)if(r.peekType()==="insert")i.push(r.next());else if(n.peekType()==="delete")i.push(n.next());else{let c=Math.min(n.peekLength(),r.peekLength()),l=n.next(c),a=r.next(c);if(a.retain){let d={};if(typeof l.retain=="number")d.retain=typeof a.retain=="number"?c:a.retain;else if(typeof a.retain=="number")l.retain===null||l.retain===void 0?d.insert=l.insert:d.retain=l.retain;else{let h=l.retain===null||l.retain===void 0?"insert":"retain",[f,p,m]=Pl(l[h],a.retain),E=et.getHandler(f);d[h]={[f]:E.compose(p,m,h==="retain")}}let u=Te.compose(l.attributes,a.attributes,typeof l.retain=="number");if(u&&(d.attributes=u),i.push(d),!r.hasNext()&&(0,ns.default)(i.ops[i.ops.length-1],d)){let h=new et(n.rest());return i.concat(h).chop()}}else typeof a.delete=="number"&&(typeof l.retain=="number"||typeof l.retain=="object"&&l.retain!==null)&&i.push(a)}return i.chop()}concat(t){let n=new et(this.ops.slice());return t.ops.length>0&&(n.push(t.ops[0]),n.ops=n.ops.concat(t.ops.slice(1))),n}diff(t){if(this.ops===t.ops)return new et;let n=this.deltasToStrings(t),r=Yo(es(n[0],n[1])),s=new Q(this.ops),o=new Q(t.ops);return this.convertChangesToDelta(r,s,o).chop()}eachLine(t,n=`
`){let r=new Q(this.ops),s=new et,o=0;for(;r.hasNext();){if(r.peekType()!=="insert")return;let i=r.peek(),c=ht.length(i)-r.peekLength(),l=typeof i.insert=="string"?i.insert.indexOf(n,c)-c:-1;if(l<0)s.push(r.next());else if(l>0)s.push(r.next(l));else{if(t(s,r.next(1).attributes||{},o)===!1)return;o+=1,s=new et}}s.length()>0&&t(s,{},o)}invert(t){let n=new et;return this.reduce((r,s)=>{if(s.insert)n.delete(ht.length(s));else{if(typeof s.retain=="number"&&(s.attributes===null||s.attributes===void 0))return n.retain(s.retain),r+s.retain;if(s.delete||typeof s.retain=="number"){let o=s.delete||s.retain;return t.slice(r,r+o).forEach(c=>{s.delete?n.push(c):s.retain&&s.attributes&&n.retain(ht.length(c),Te.invert(s.attributes,c.attributes))}),r+o}else if(typeof s.retain=="object"&&s.retain!==null){let o=t.slice(r,r+1),i=new Q(o.ops).next(),[c,l,a]=Pl(s.retain,i.insert),d=et.getHandler(c);return n.retain({[c]:d.invert(l,a)},Te.invert(s.attributes,i.attributes)),r+1}}return r},0),n.chop()}transform(t,n=!1){if(n=!!n,typeof t=="number")return this.transformPosition(t,n);let r=t,s=new Q(this.ops),o=new Q(r.ops),i=new et;for(;s.hasNext()||o.hasNext();)if(s.peekType()==="insert"&&(n||o.peekType()!=="insert"))i.retain(ht.length(s.next()));else if(o.peekType()==="insert")i.push(o.next());else{let c=Math.min(s.peekLength(),o.peekLength()),l=s.next(c),a=o.next(c);if(l.delete)continue;if(a.delete)i.push(a);else{let d=l.retain,u=a.retain,h=typeof u=="object"&&u!==null?u:c;if(typeof d=="object"&&d!==null&&typeof u=="object"&&u!==null){let f=Object.keys(d)[0];if(f===Object.keys(u)[0]){let p=et.getHandler(f);p&&(h={[f]:p.transform(d[f],u[f],n)})}}i.retain(h,Te.transform(l.attributes,a.attributes,n))}}return i.chop()}transformPosition(t,n=!1){n=!!n;let r=new Q(this.ops),s=0;for(;r.hasNext()&&s<=t;){let o=r.peekLength(),i=r.peekType();if(r.next(),i==="delete"){t-=Math.min(o,t-s);continue}else i==="insert"&&(s<t||!n)&&(t+=o);s+=o}return t}diffWithCursor(t,n){if(this.ops===t.ops)return new et;let r=this.deltasToStrings(t);if(Math.max(...r.map(u=>u.length))>Ch){let u=Yo(Po(r[0],r[1])),h=new Q(this.ops),f=new Q(t.ops);return this.convertChangesToDelta(u,h,f).chop()}else if(n===null)return this.diff(t);let o=Yo(es(r[0],r[1])),i=0,c=[];for(let u=0;u<o.length;u++){let h=o[u],f=i,p=i+(h.count??0),m=n>f&&n<=p,E=!h.added&&!h.removed,C=h.removed&&!h.added,g=o[u+1],x=g&&g.added&&!g.removed;if(E&&m&&x){let w=this.tryMoveInsertionToCursor(h,g,n,f);if(w){c.push(...w),u++,i=p;continue}}if(C){let w=this.tryMoveDeletionToCursor(h,c,n,i);if(w){c.pop(),c.push(...w),i+=h.count??0;continue}}c.push(h),h.added||(i+=h.count??0)}o=c;let l=new Q(this.ops),a=new Q(t.ops);return this.convertChangesToDelta(o,l,a).chop()}tryMoveInsertionToCursor(t,n,r,s){let o=n.value,i=o.length,c=r-s-i;if(!(t.value.substring(c,c+o.length)===o))return null;let d=t.value.substring(0,c),u=t.value.substring(c),h=[];return d.length>0&&h.push({value:d,count:d.length,added:!1,removed:!1}),h.push(n),u.length>0&&h.push({value:u,count:u.length,added:!1,removed:!1}),h}tryMoveDeletionToCursor(t,n,r,s){let o=n[n.length-1];if(!o||o.added||o.removed)return null;let i=s-(o.count??0),c=s;if(r<i||r>=c)return null;let l=t.value,a=r-i;if(!(o.value.substring(a,a+l.length)===l))return null;let h=o.value.substring(0,a),f=o.value.substring(a),p=t.count??0,m=f.substring(p),E=[];return h.length>0&&E.push({value:h,count:h.length,added:!1,removed:!1}),E.push(t),m.length>0&&E.push({value:m,count:m.length,added:!1,removed:!1}),E}deltasToStrings(t){return[this,t].map(n=>n.map(r=>{if(r.insert!==null||r.insert!==void 0)return typeof r.insert=="string"?r.insert:kh;let s=n===t?"on":"with";throw new Error("diff() called "+s+" non-document")}).join(""))}convertChangesToDelta(t,n,r){let s=new et;return t.forEach(o=>{let i=o.count??0;for(;i>0;){let c=0;if(o.added)c=Math.min(r.peekLength(),i),s.push(r.next(c));else if(o.removed)c=Math.min(i,n.peekLength()),n.next(c),s.delete(c);else{c=Math.min(n.peekLength(),r.peekLength(),i);let l=n.next(c),a=r.next(c);(0,ns.default)(l.insert,a.insert)?s.retain(c,Te.diff(l.attributes,a.attributes)):s.push(a).delete(c)}i-=c}}),s}},$l=Ah;var zo={};Zc(zo,{ConnectionErrorCode:ke,createSyncManager:Ll,Delta:$l,CRDT_DOC_META_PERSISTENCE_KEY:Gr,CRDT_RECORD_MAP_KEY:qr,LOCAL_EDITOR_ORIGIN:Hr,LOCAL_UNDO_IGNORED_ORIGIN:Kc,retrySyncConnection:()=>qn.retryNow()});var Dh="13";return Kl(Th);})();