lexxy-realtime 0.4.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +7 -0
- data/LICENSE +21 -0
- data/README.md +129 -0
- data/app/assets/javascript/lexxy_realtime/lexical.js +11418 -0
- data/app/assets/javascript/lexxy_realtime/lexical.js.map +1 -0
- data/app/assets/javascript/lexxy_realtime/lexical.min.js +17 -0
- data/app/assets/javascript/lexxy_realtime/lexxy-realtime.js +15357 -0
- data/app/assets/javascript/lexxy_realtime/lexxy-realtime.js.map +1 -0
- data/app/assets/javascript/lexxy_realtime/lexxy-realtime.min.js +6 -0
- data/app/assets/javascript/lexxy_realtime/lexxy.js +30472 -0
- data/app/assets/javascript/lexxy_realtime/lexxy.js.map +1 -0
- data/app/assets/javascript/lexxy_realtime/lexxy.min.js +306 -0
- data/lib/generators/lexxy_realtime/install/USAGE +15 -0
- data/lib/generators/lexxy_realtime/install/install_generator.rb +84 -0
- data/lib/generators/lexxy_realtime/install/templates/application_cable_channel.rb +6 -0
- data/lib/generators/lexxy_realtime/install/templates/application_cable_connection.rb +13 -0
- data/lib/generators/lexxy_realtime/install/templates/document_channel.rb +57 -0
- data/lib/lexxy-realtime.rb +4 -0
- data/lib/lexxy_realtime/collaborative.rb +84 -0
- data/lib/lexxy_realtime/engine.rb +26 -0
- data/lib/lexxy_realtime/form_builder.rb +41 -0
- data/lib/lexxy_realtime/version.rb +5 -0
- data/lib/lexxy_realtime.rb +38 -0
- metadata +123 -0
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
import{$addUpdateTag as e,$caretFromPoint as t,$caretRangeFromSelection as n,$cloneWithProperties as r,$cloneWithPropertiesEphemeral as i,$createChildrenArray as a,$createParagraphNode as o,$createRangeSelection as s,$createTextNode as c,$extendCaretToRange as l,$findMatchingParent as u,$getCharacterOffsets as d,$getEditor as f,$getNodeByKey as p,$getNodeByKeyOrThrow as m,$getPreviousSelection as h,$getRoot as g,$getSelection as _,$getState as ee,$getWritableNodeState as te,$hasAncestor as ne,$isChildCaret as re,$isDecoratorNode as ie,$isElementNode as v,$isExtendableTextPointCaret as ae,$isLeafNode as oe,$isLineBreakNode as se,$isRangeSelection as y,$isRootNode as ce,$isRootOrShadowRoot as le,$isTextNode as b,$isTokenOrSegmented as ue,$nodesOfType as de,$selectAll as fe,$setSelection as pe,COLLABORATION_TAG as me,ElementNode as he,HISTORIC_TAG as ge,HISTORY_MERGE_TAG as _e,INTERNAL_$isBlock as ve,RootNode as ye,SKIP_SCROLL_INTO_VIEW_TAG as be,TextNode as xe,createCommand as Se,createEditor as Ce,createState as we,getStyleObjectFromCSS as Te,removeFromParent as Ee,setDOMStyleObject as De}from"lexical";var Oe=Object.defineProperty,ke=(e,t)=>{let n={};for(var r in e)Oe(n,r,{get:e[r],enumerable:!0});return t||Oe(n,Symbol.toStringTag,{value:`Module`}),n};const x=()=>new Map,Ae=e=>{let t=x();return e.forEach((e,n)=>{t.set(n,e)}),t},je=(e,t,n)=>{let r=e.get(t);return r===void 0&&e.set(t,r=n()),r},Me=(e,t)=>{let n=[];for(let[r,i]of e)n.push(t(i,r));return n},Ne=(e,t)=>{for(let[n,r]of e)if(t(r,n))return!0;return!1},Pe=()=>new Set,Fe=e=>e[e.length-1],Ie=(e,t)=>{for(let n=0;n<t.length;n++)e.push(t[n])},Le=Array.from,Re=(e,t)=>{for(let n=0;n<e.length;n++)if(!t(e[n],n,e))return!1;return!0},ze=(e,t)=>{for(let n=0;n<e.length;n++)if(t(e[n],n,e))return!0;return!1},Be=(e,t)=>{let n=Array(e);for(let r=0;r<e;r++)n[r]=t(r,n);return n},Ve=Array.isArray;var He=class{constructor(){this._observers=x()}on(e,t){return je(this._observers,e,Pe).add(t),t}once(e,t){let n=(...r)=>{this.off(e,n),t(...r)};this.on(e,n)}off(e,t){let n=this._observers.get(e);n!==void 0&&(n.delete(t),n.size===0&&this._observers.delete(e))}emit(e,t){return Le((this._observers.get(e)||x()).values()).forEach(e=>e(...t))}destroy(){this._observers=x()}},Ue=class{constructor(){this._observers=x()}on(e,t){je(this._observers,e,Pe).add(t)}once(e,t){let n=(...r)=>{this.off(e,n),t(...r)};this.on(e,n)}off(e,t){let n=this._observers.get(e);n!==void 0&&(n.delete(t),n.size===0&&this._observers.delete(e))}emit(e,t){return Le((this._observers.get(e)||x()).values()).forEach(e=>e(...t))}destroy(){this._observers=x()}};const S=Math.floor,We=Math.abs,Ge=(e,t)=>e<t?e:t,Ke=(e,t)=>e>t?e:t;Number.isNaN;const qe=e=>e===0?1/e<0:e<0,Je=2**53-1,Ye=-(2**53-1),Xe=Number.isInteger||(e=>typeof e==`number`&&isFinite(e)&&S(e)===e);Number.isNaN,Number.parseInt;const Ze=String.fromCharCode;String.fromCodePoint,Ze(65535);const Qe=e=>e.toLowerCase(),$e=/^\s*/g,et=e=>e.replace($e,``),tt=/([A-Z])/g,nt=(e,t)=>et(e.replace(tt,e=>`${t}${Qe(e)}`)),rt=e=>{let t=unescape(encodeURIComponent(e)),n=t.length,r=new Uint8Array(n);for(let e=0;e<n;e++)r[e]=t.codePointAt(e);return r},it=typeof TextEncoder<`u`?new TextEncoder:null,at=it?e=>it.encode(e):rt;let ot=typeof TextDecoder>`u`?null:new TextDecoder(`utf-8`,{fatal:!0,ignoreBOM:!0});ot&&ot.decode(new Uint8Array).length===1&&(ot=null);const st=(e,t)=>Be(t,()=>e).join(``);var ct=class{constructor(){this.cpos=0,this.cbuf=new Uint8Array(100),this.bufs=[]}};const lt=()=>new ct,ut=e=>{let t=e.cpos;for(let n=0;n<e.bufs.length;n++)t+=e.bufs[n].length;return t},C=e=>{let t=new Uint8Array(ut(e)),n=0;for(let r=0;r<e.bufs.length;r++){let i=e.bufs[r];t.set(i,n),n+=i.length}return t.set(new Uint8Array(e.cbuf.buffer,0,e.cpos),n),t},dt=(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(Ke(n,t)*2),e.cpos=0)},w=(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},ft=w,T=(e,t)=>{for(;t>127;)w(e,128|127&t),t=S(t/128);w(e,127&t)},pt=(e,t)=>{let n=qe(t);for(n&&(t=-t),w(e,(t>63?128:0)|(n?64:0)|63&t),t=S(t/64);t>0;)w(e,(t>127?128:0)|127&t),t=S(t/128)},mt=new Uint8Array(3e4),ht=mt.length/3,gt=it&&it.encodeInto?(e,t)=>{if(t.length<ht){let n=it.encodeInto(t,mt).written||0;T(e,n);for(let t=0;t<n;t++)w(e,mt[t])}else E(e,at(t))}:(e,t)=>{let n=unescape(encodeURIComponent(t)),r=n.length;T(e,r);for(let t=0;t<r;t++)w(e,n.codePointAt(t))},_t=(e,t)=>{let n=e.cbuf.length,r=e.cpos,i=Ge(n-r,t.length),a=t.length-i;e.cbuf.set(t.subarray(0,i),r),e.cpos+=i,a>0&&(e.bufs.push(e.cbuf),e.cbuf=new Uint8Array(Ke(n*2,a)),e.cbuf.set(t.subarray(i)),e.cpos=a)},E=(e,t)=>{T(e,t.byteLength),_t(e,t)},vt=(e,t)=>{dt(e,t);let n=new DataView(e.cbuf.buffer,e.cpos,t);return e.cpos+=t,n},yt=(e,t)=>vt(e,4).setFloat32(0,t,!1),bt=(e,t)=>vt(e,8).setFloat64(0,t,!1),xt=(e,t)=>vt(e,8).setBigInt64(0,t,!1),St=new DataView(new ArrayBuffer(4)),Ct=e=>(St.setFloat32(0,e),St.getFloat32(0)===e),wt=(e,t)=>{switch(typeof t){case`string`:w(e,119),gt(e,t);break;case`number`:Xe(t)&&We(t)<=2147483647?(w(e,125),pt(e,t)):Ct(t)?(w(e,124),yt(e,t)):(w(e,123),bt(e,t));break;case`bigint`:w(e,122),xt(e,t);break;case`object`:if(t===null)w(e,126);else if(Ve(t)){w(e,117),T(e,t.length);for(let n=0;n<t.length;n++)wt(e,t[n])}else if(t instanceof Uint8Array)w(e,116),E(e,t);else{w(e,118);let n=Object.keys(t);T(e,n.length);for(let r=0;r<n.length;r++){let i=n[r];gt(e,i),wt(e,t[i])}}break;case`boolean`:w(e,t?120:121);break;default:w(e,127)}};var Tt=class extends ct{constructor(e){super(),this.w=e,this.s=null,this.count=0}write(e){this.s===e?this.count++:(this.count>0&&T(this,this.count-1),this.count=1,this.w(this,e),this.s=e)}};const Et=e=>{e.count>0&&(pt(e.encoder,e.count===1?e.s:-e.s),e.count>1&&T(e.encoder,e.count-2))};var Dt=class{constructor(){this.encoder=new ct,this.s=0,this.count=0}write(e){this.s===e?this.count++:(Et(this),this.count=1,this.s=e)}toUint8Array(){return Et(this),C(this.encoder)}};const Ot=e=>{if(e.count>0){let t=e.diff*2+(e.count===1?0:1);pt(e.encoder,t),e.count>1&&T(e.encoder,e.count-2)}};var kt=class{constructor(){this.encoder=new ct,this.s=0,this.count=0,this.diff=0}write(e){this.diff===e-this.s?(this.s=e,this.count++):(Ot(this),this.count=1,this.diff=e-this.s,this.s=e)}toUint8Array(){return Ot(this),C(this.encoder)}},At=class{constructor(){this.sarr=[],this.s=``,this.lensE=new Dt}write(e){this.s+=e,this.s.length>19&&(this.sarr.push(this.s),this.s=``),this.lensE.write(e.length)}toUint8Array(){let e=new ct;return this.sarr.push(this.s),this.s=``,gt(e,this.sarr.join(``)),_t(e,this.lensE.toUint8Array()),C(e)}};const jt=e=>Error(e),D=()=>{throw jt(`Method unimplemented`)},O=()=>{throw jt(`Unexpected case`)},Mt=jt(`Unexpected end of array`),Nt=jt(`Integer out of Range`);var Pt=class{constructor(e){this.arr=e,this.pos=0}};const k=e=>new Pt(e),Ft=e=>e.pos!==e.arr.length,It=(e,t)=>{let n=new Uint8Array(e.arr.buffer,e.pos+e.arr.byteOffset,t);return e.pos+=t,n},A=e=>It(e,j(e)),Lt=e=>e.arr[e.pos++],j=e=>{let t=0,n=1,r=e.arr.length;for(;e.pos<r;){let r=e.arr[e.pos++];if(t+=(r&127)*n,n*=128,r<128)return t;if(t>Je)throw Nt}throw Mt},Rt=e=>{let t=e.arr[e.pos++],n=t&63,r=64,i=(t&64)>0?-1:1;if(!(t&128))return i*n;let a=e.arr.length;for(;e.pos<a;){if(t=e.arr[e.pos++],n+=(t&127)*r,r*=128,t<128)return i*n;if(n>Je)throw Nt}throw Mt},zt=ot?e=>ot.decode(A(e)):e=>{let t=j(e);if(t===0)return``;{let n=String.fromCodePoint(Lt(e));if(--t<100)for(;t--;)n+=String.fromCodePoint(Lt(e));else for(;t>0;){let r=t<1e4?t:1e4,i=e.arr.subarray(e.pos,e.pos+r);e.pos+=r,n+=String.fromCodePoint.apply(null,i),t-=r}return decodeURIComponent(escape(n))}},Bt=(e,t)=>{let n=new DataView(e.arr.buffer,e.arr.byteOffset+e.pos,t);return e.pos+=t,n},Vt=[e=>void 0,e=>null,Rt,e=>Bt(e,4).getFloat32(0,!1),e=>Bt(e,8).getFloat64(0,!1),e=>Bt(e,8).getBigInt64(0,!1),e=>!1,e=>!0,zt,e=>{let t=j(e),n={};for(let r=0;r<t;r++){let t=zt(e);n[t]=Ht(e)}return n},e=>{let t=j(e),n=[];for(let r=0;r<t;r++)n.push(Ht(e));return n},A],Ht=e=>Vt[127-Lt(e)](e);var Ut=class extends Pt{constructor(e,t){super(e),this.reader=t,this.s=null,this.count=0}read(){return this.count===0&&(this.s=this.reader(this),this.count=Ft(this)?j(this)+1:-1),this.count--,this.s}},Wt=class extends Pt{constructor(e){super(e),this.s=0,this.count=0}read(){if(this.count===0){this.s=Rt(this);let e=qe(this.s);this.count=1,e&&(this.s=-this.s,this.count=j(this)+2)}return this.count--,this.s}},Gt=class extends Pt{constructor(e){super(e),this.s=0,this.count=0,this.diff=0}read(){if(this.count===0){let e=Rt(this),t=e&1;this.diff=S(e/2),this.count=1,t&&(this.count=j(this)+2)}return this.s+=this.diff,this.count--,this.s}},Kt=class{constructor(e){this.decoder=new Wt(e),this.str=zt(this.decoder),this.spos=0}read(){let e=this.spos+this.decoder.read(),t=this.str.slice(this.spos,e);return this.spos=e,t}};crypto.subtle;const qt=crypto.getRandomValues.bind(crypto),Jt=()=>qt(new Uint32Array(1))[0],Yt=()=>`10000000-1000-4000-8000-100000000000`.replace(/[018]/g,e=>(e^Jt()&15>>e/4).toString(16)),Xt=Date.now,Zt=e=>new Promise(e);Promise.all.bind(Promise);const Qt=e=>e===void 0?null:e;let $t=new class{constructor(){this.map=new Map}setItem(e,t){this.map.set(e,t)}getItem(e){return this.map.get(e)}};try{typeof localStorage<`u`&&localStorage&&($t=localStorage)}catch{}const en=$t,tn=Symbol(`Equality`),nn=(e,t)=>e===t||!!e?.[tn]?.(t)||!1,rn=e=>typeof e==`object`,an=Object.assign,on=Object.keys,sn=(e,t)=>{for(let n in e)t(e[n],n)},cn=e=>on(e).length,ln=e=>{for(let t in e)return!1;return!0},un=(e,t)=>{for(let n in e)if(!t(e[n],n))return!1;return!0},dn=(e,t)=>Object.prototype.hasOwnProperty.call(e,t),fn=(e,t)=>e===t||cn(e)===cn(t)&&un(e,(e,n)=>(e!==void 0||dn(t,n))&&nn(t[n],e)),pn=Object.freeze,mn=e=>{for(let t in e){let n=e[t];(typeof n==`object`||typeof n==`function`)&&mn(e[t])}return pn(e)},hn=(e,t,n=0)=>{try{for(;n<e.length;n++)e[n](...t)}finally{n<e.length&&hn(e,t,n+1)}},gn=e=>e,_n=(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[tn]!=null)return e[tn](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)||!_n(e.get(n),t.get(n)))return!1;break;case void 0:case Object:if(cn(e)!==cn(t))return!1;for(let n in e)if(!dn(e,n)||!_n(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(!_n(e[n],t[n]))return!1;break;default:return!1}return!0},vn=(e,t)=>t.includes(e),yn=typeof process<`u`&&process.release&&/node|io\.js/.test(process.release.name)&&Object.prototype.toString.call(typeof process<`u`?process:0)===`[object process]`;typeof navigator<`u`&&/Mac/.test(navigator.platform);let bn;const xn=[],Sn=()=>{if(bn===void 0)if(yn){bn=x();let e=process.argv,t=null;for(let n=0;n<e.length;n++){let r=e[n];r[0]===`-`?(t!==null&&bn.set(t,``),t=r):t===null?xn.push(r):(bn.set(t,r),t=null)}t!==null&&bn.set(t,``)}else typeof location==`object`?(bn=x(),(location.search||`?`).slice(1).split(`&`).forEach(e=>{if(e.length!==0){let[t,n]=e.split(`=`);bn.set(`--${nt(t,`-`)}`,n),bn.set(`-${nt(t,`-`)}`,n)}})):bn=x();return bn},Cn=e=>Sn().has(e),wn=e=>Qt(yn?process.env[e.toUpperCase().replaceAll(`-`,`_`)]:en.getItem(e)),Tn=e=>Cn(`--`+e)||wn(e)!==null,En=Tn(`production`),Dn=yn&&vn(process.env.FORCE_COLOR,[`true`,`1`,`2`])||!Cn(`--no-colors`)&&!Tn(`no-color`)&&(!yn||process.stdout.isTTY)&&(!yn||Cn(`--color`)||wn(`COLORTERM`)!==null||(wn(`TERM`)||``).includes(`color`)),On=e=>new Uint8Array(e),kn=e=>{let t=On(e.byteLength);return t.set(e),t};var An=class{constructor(e,t){this.left=e,this.right=t}};const jn=(e,t)=>new An(e,t),Mn=e=>e.next()>=.5,Nn=(e,t,n)=>S(e.next()*(n+1-t)+t),Pn=(e,t,n)=>S(e.next()*(n+1-t)+t),Fn=(e,t,n)=>Pn(e,t,n),In=e=>Ze(Fn(e,97,122)),Ln=(e,t=0,n=20)=>{let r=Fn(e,t,n),i=``;for(let t=0;t<r;t++)i+=In(e);return i},Rn=(e,t)=>t[Fn(e,0,t.length-1)],zn=Symbol(`0schema`);var Bn=class{constructor(){this._rerrs=[]}extend(e,t,n,r=null){this._rerrs.push({path:e,expected:t,has:n,message:r})}toString(){let e=[];for(let t=this._rerrs.length-1;t>0;t--){let n=this._rerrs[t];e.push(st(` `,(this._rerrs.length-t)*2)+`${n.path==null?``:`[${n.path}] `}${n.has} doesn't match ${n.expected}. ${n.message}`)}return e.join(`
|
|
2
|
+
`)}};const Vn=(e,t)=>e===t?!0:e==null||t==null||e.constructor!==t.constructor?!1:e[tn]?nn(e,t):Ve(e)?Re(e,e=>ze(t,t=>Vn(e,t))):rn(e)?un(e,(e,n)=>Vn(e,t[n])):!1;var M=class{static _dilutes=!1;extends(e){let[t,n]=[this.shape,e.shape];return this.constructor._dilutes&&([n,t]=[t,n]),Vn(t,n)}equals(e){return this.constructor===e.constructor&&_n(this.shape,e.shape)}[zn](){return!0}[tn](e){return this.equals(e)}validate(e){return this.check(e)}check(e,t){D()}get nullable(){return vr(this,Nr)}get optional(){return new Xn(this)}cast(e){return Lr(e,this),e}expect(e){return Lr(e,this),e}},Hn=class extends M{constructor(e,t){super(),this.shape=e,this._c=t}check(e,t=void 0){let n=e?.constructor===this.shape&&(this._c==null||this._c(e));return!n&&t?.extend(null,this.shape.name,e?.constructor.name,e?.constructor===this.shape?`Check failed`:`Constructor match failed`),n}};const N=(e,t=null)=>new Hn(e,t);N(Hn);var Un=class extends M{constructor(e){super(),this.shape=e}check(e,t){let n=this.shape(e);return!n&&t?.extend(null,`custom prop`,e?.constructor.name,`failed to check custom prop`),n}};const P=e=>new Un(e);N(Un);var Wn=class extends M{constructor(e){super(),this.shape=e}check(e,t){let n=this.shape.some(t=>t===e);return!n&&t?.extend(null,this.shape.join(` | `),e.toString()),n}};const Gn=(...e)=>new Wn(e),Kn=N(Wn),qn=RegExp.escape||(e=>e.replace(/[().|&,$^[\]]/g,e=>`\\`+e)),Jn=e=>{if(Or.check(e))return[qn(e)];if(Kn.check(e))return e.shape.map(e=>e+``);if(Dr.check(e))return[`[+-]?\\d+.?\\d*`];if(kr.check(e))return[`.*`];if(yr.check(e))return e.shape.map(Jn).flat(1);O()};N(class extends M{constructor(e){super(),this.shape=e,this._r=RegExp(`^`+e.map(Jn).map(e=>`(${e.join(`|`)})`).join(``)+`$`)}check(e,t){let n=this._r.exec(e)!=null;return!n&&t?.extend(null,this._r.toString(),e.toString(),`String doesn't match string template.`),n}});const Yn=Symbol(`optional`);var Xn=class extends M{constructor(e){super(),this.shape=e}check(e,t){let n=e===void 0||this.shape.check(e);return!n&&t?.extend(null,`undefined (optional)`,`()`),n}get[Yn](){return!0}};const Zn=N(Xn);var Qn=class extends M{check(e,t){return t?.extend(null,`never`,typeof e),!1}};new Qn,N(Qn);var $n=class e extends M{constructor(e,t=!1){super(),this.shape=e,this._isPartial=t}static _dilutes=!0;get partial(){return new e(this.shape,!0)}check(e,t){return e==null?(t?.extend(null,`object`,`null`),!1):un(this.shape,(n,r)=>{let i=this._isPartial&&!dn(e,r)||n.check(e[r],t);return!i&&t?.extend(r.toString(),n.toString(),typeof e[r],`Object property does not match`),i})}};const er=e=>new $n(e),tr=N($n),nr=P(e=>e!=null&&(e.constructor===Object||e.constructor==null));var rr=class extends M{constructor(e,t){super(),this.shape={keys:e,values:t}}check(e,t){return e!=null&&un(e,(n,r)=>{let i=this.shape.keys.check(r,t);return!i&&t?.extend(r+``,`Record`,typeof e,i?`Key doesn't match schema`:`Value doesn't match value`),i&&this.shape.values.check(n,t)})}};const ir=(e,t)=>new rr(e,t),ar=N(rr);var or=class extends M{constructor(e){super(),this.shape=e}check(e,t){return e!=null&&un(this.shape,(n,r)=>{let i=n.check(e[r],t);return!i&&t?.extend(r.toString(),`Tuple`,typeof n),i})}};const sr=(...e)=>new or(e);N(or);var cr=class extends M{constructor(e){super(),this.shape=e.length===1?e[0]:new _r(e)}check(e,t){let n=Ve(e)&&Re(e,e=>this.shape.check(e));return!n&&t?.extend(null,`Array`,``),n}};const lr=(...e)=>new cr(e),ur=N(cr),dr=P(e=>Ve(e));var fr=class extends M{constructor(e,t){super(),this.shape=e,this._c=t}check(e,t){let n=e instanceof this.shape&&(this._c==null||this._c(e));return!n&&t?.extend(null,this.shape.name,e?.constructor.name),n}};const pr=(e,t=null)=>new fr(e,t);N(fr);const mr=pr(M),hr=N(class extends M{constructor(e){super(),this.len=e.length-1,this.args=sr(...e.slice(-1)),this.res=e[this.len]}check(e,t){let n=e.constructor===Function&&e.length<=this.len;return!n&&t?.extend(null,`function`,typeof e),n}}),gr=P(e=>typeof e==`function`);N(class extends M{constructor(e){super(),this.shape=e}check(e,t){let n=Re(this.shape,n=>n.check(e,t));return!n&&t?.extend(null,`Intersectinon`,typeof e),n}},e=>e.shape.length>0);var _r=class extends M{static _dilutes=!0;constructor(e){super(),this.shape=e}check(e,t){let n=ze(this.shape,n=>n.check(e,t));return t?.extend(null,`Union`,typeof e),n}};const vr=(...e)=>e.findIndex(e=>yr.check(e))>=0?vr(...e.map(e=>Ir(e)).map(e=>yr.check(e)?e.shape:[e]).flat(1)):e.length===1?e[0]:new _r(e),yr=N(_r),br=()=>!0,xr=P(br),Sr=N(Un,e=>e.shape===br),Cr=P(e=>typeof e==`bigint`),wr=P(e=>e===Cr),Tr=P(e=>typeof e==`symbol`);P(e=>e===Tr);const Er=P(e=>typeof e==`number`),Dr=P(e=>e===Er),Or=P(e=>typeof e==`string`),kr=P(e=>e===Or),Ar=P(e=>typeof e==`boolean`),jr=P(e=>e===Ar),Mr=Gn(void 0);N(Wn,e=>e.shape.length===1&&e.shape[0]===void 0),Gn(void 0);const Nr=Gn(null),Pr=N(Wn,e=>e.shape.length===1&&e.shape[0]===null);N(Uint8Array),N(Hn,e=>e.shape===Uint8Array);const Fr=vr(Er,Or,Nr,Mr,Cr,Ar,Tr);(()=>{let e=lr(xr),t=ir(Or,xr),n=vr(Er,Or,Nr,Ar,e,t);return e.shape=n,t.shape.values=n,n})();const Ir=e=>{if(mr.check(e))return e;if(nr.check(e)){let t={};for(let n in e)t[n]=Ir(e[n]);return er(t)}if(dr.check(e))return vr(...e.map(Ir));if(Fr.check(e))return Gn(e);if(gr.check(e))return N(e);O()},Lr=En?()=>{}:(e,t)=>{let n=new Bn;if(!t.check(e,n))throw jt(`Expected value to be of type ${t.constructor.name}.\n${n.toString()}`)};var Rr=class{constructor(e){this.patterns=[],this.$state=e}if(e,t){return this.patterns.push({if:Ir(e),h:t}),this}else(e){return this.if(xr,e)}done(){return(e,t)=>{for(let n=0;n<this.patterns.length;n++){let r=this.patterns[n];if(r.if.check(e))return r.h(e,t)}throw jt(`Unhandled pattern`)}}};const zr=(e=>new Rr(e))(xr).if(Dr,(e,t)=>Nn(t,Ye,Je)).if(kr,(e,t)=>Ln(t)).if(jr,(e,t)=>Mn(t)).if(wr,(e,t)=>BigInt(Nn(t,Ye,Je))).if(yr,(e,t)=>Br(t,Rn(t,e.shape))).if(tr,(e,t)=>{let n={};for(let r in e.shape){let i=e.shape[r];if(Zn.check(i)){if(Mn(t))continue;i=i.shape}n[r]=zr(i,t)}return n}).if(ur,(e,t)=>{let n=[],r=Pn(t,0,42);for(let i=0;i<r;i++)n.push(Br(t,e.shape));return n}).if(Kn,(e,t)=>Rn(t,e.shape)).if(Pr,(e,t)=>null).if(hr,(e,t)=>{let n=Br(t,e.res);return()=>n}).if(Sr,(e,t)=>Br(t,Rn(t,[Er,Or,Nr,Mr,Cr,Ar,lr(Er),ir(vr(`a`,`b`,`c`),Er)]))).if(ar,(e,t)=>{let n={},r=Nn(t,0,3);for(let i=0;i<r;i++){let r=Br(t,e.shape.keys);n[r]=Br(t,e.shape.values)}return n}).done(),Br=(e,t)=>zr(Ir(t),e),Vr=typeof document<`u`?document:{};P(e=>e.nodeType===Kr),typeof DOMParser<`u`&&new DOMParser,P(e=>e.nodeType===Ur),P(e=>e.nodeType===Wr);const Hr=e=>Me(e,(e,t)=>`${t}:${e};`).join(``),Ur=Vr.ELEMENT_NODE,Wr=Vr.TEXT_NODE;Vr.CDATA_SECTION_NODE,Vr.COMMENT_NODE;const Gr=Vr.DOCUMENT_NODE;Vr.DOCUMENT_TYPE_NODE;const Kr=Vr.DOCUMENT_FRAGMENT_NODE;P(e=>e.nodeType===Gr);const qr=Symbol,Jr=qr(),Yr=qr(),Xr=qr(),Zr=qr(),Qr=qr(),$r=qr(),ei=qr(),ti=qr(),ni=qr(),ri=e=>{e.length===1&&e[0]?.constructor===Function&&(e=e[0]());let t=[],n=[],r=0;for(;r<e.length;r++){let n=e[r];if(n===void 0)break;if(n.constructor===String||n.constructor===Number)t.push(n);else if(n.constructor===Object)break}for(r>0&&n.push(t.join(``));r<e.length;r++){let t=e[r];t instanceof Symbol||n.push(t)}return n};Xt();const ii={[Jr]:jn(`font-weight`,`bold`),[Yr]:jn(`font-weight`,`normal`),[Xr]:jn(`color`,`blue`),[Qr]:jn(`color`,`green`),[Zr]:jn(`color`,`grey`),[$r]:jn(`color`,`red`),[ei]:jn(`color`,`purple`),[ti]:jn(`color`,`orange`),[ni]:jn(`color`,`black`)},ai=Dn?e=>{e.length===1&&e[0]?.constructor===Function&&(e=e[0]());let t=[],n=[],r=x(),i=[],a=0;for(;a<e.length;a++){let i=e[a],o=ii[i];if(o!==void 0)r.set(o.left,o.right);else{if(i===void 0)break;if(i.constructor===String||i.constructor===Number){let e=Hr(r);a>0||e.length>0?(t.push(`%c`+i),n.push(e)):t.push(i)}else break}}for(a>0&&(i=n,i.unshift(t.join(``)));a<e.length;a++){let t=e[a];t instanceof Symbol||i.push(t)}return i}:ri,oi=(...e)=>{console.log(...ai(e)),ci.forEach(t=>t.print(e))},si=(...e)=>{console.warn(...ai(e)),e.unshift(ti),ci.forEach(t=>t.print(e))},ci=Pe(),li=e=>({[Symbol.iterator](){return this},next:e}),ui=(e,t)=>li(()=>{let n;do n=e.next();while(!n.done&&!t(n.value));return n}),di=(e,t)=>li(()=>{let{done:n,value:r}=e.next();return{done:n,value:n?void 0:t(r)}});var fi=class{constructor(e,t){this.clock=e,this.len=t}},pi=class{constructor(){this.clients=new Map}};const mi=(e,t,n)=>t.clients.forEach((t,r)=>{let i=e.doc.store.clients.get(r);if(i!=null){let r=i[i.length-1],a=r.id.clock+r.length;for(let r=0,o=t[r];r<t.length&&o.clock<a;o=t[++r])Aa(e,i,o.clock,o.len,n)}}),hi=(e,t)=>{let n=0,r=e.length-1;for(;n<=r;){let i=S((n+r)/2),a=e[i],o=a.clock;if(o<=t){if(t<o+a.len)return i;n=i+1}else r=i-1}return null},gi=(e,t)=>{let n=e.clients.get(t.client);return n!==void 0&&hi(n,t.clock)!==null},_i=e=>{e.clients.forEach(e=>{e.sort((e,t)=>e.clock-t.clock);let t,n;for(t=1,n=1;t<e.length;t++){let r=e[n-1],i=e[t];r.clock+r.len>=i.clock?e[n-1]=new fi(r.clock,Ke(r.len,i.clock+i.len-r.clock)):(n<t&&(e[n]=i),n++)}e.length=n})},vi=e=>{let t=new pi;for(let n=0;n<e.length;n++)e[n].clients.forEach((r,i)=>{if(!t.clients.has(i)){let a=r.slice();for(let t=n+1;t<e.length;t++)Ie(a,e[t].clients.get(i)||[]);t.clients.set(i,a)}});return _i(t),t},yi=(e,t,n,r)=>{je(e.clients,t,()=>[]).push(new fi(n,r))},bi=()=>new pi,xi=e=>{let t=bi();return e.clients.forEach((e,n)=>{let r=[];for(let t=0;t<e.length;t++){let n=e[t];if(n.deleted){let i=n.id.clock,a=n.length;if(t+1<e.length)for(let n=e[t+1];t+1<e.length&&n.deleted;n=e[++t+1])a+=n.length;r.push(new fi(i,a))}}r.length>0&&t.clients.set(n,r)}),t},Si=(e,t)=>{T(e.restEncoder,t.clients.size),Le(t.clients.entries()).sort((e,t)=>t[0]-e[0]).forEach(([t,n])=>{e.resetDsCurVal(),T(e.restEncoder,t);let r=n.length;T(e.restEncoder,r);for(let t=0;t<r;t++){let r=n[t];e.writeDsClock(r.clock),e.writeDsLen(r.len)}})},Ci=e=>{let t=new pi,n=j(e.restDecoder);for(let r=0;r<n;r++){e.resetDsCurVal();let n=j(e.restDecoder),r=j(e.restDecoder);if(r>0){let i=je(t.clients,n,()=>[]);for(let t=0;t<r;t++)i.push(new fi(e.readDsClock(),e.readDsLen()))}}return t},wi=(e,t,n)=>{let r=new pi,i=j(e.restDecoder);for(let a=0;a<i;a++){e.resetDsCurVal();let i=j(e.restDecoder),a=j(e.restDecoder),o=n.clients.get(i)||[],s=I(n,i);for(let n=0;n<a;n++){let n=e.readDsClock(),a=n+e.readDsLen();if(n<s){s<a&&yi(r,i,s,a-s);let e=Ta(o,n),c=o[e];for(!c.deleted&&c.id.clock<n&&(o.splice(e+1,0,Rs(t,c,n-c.id.clock)),e++);e<o.length&&(c=o[e++],c.id.clock<a);)c.deleted||(a<c.id.clock+c.length&&o.splice(e,0,Rs(t,c,a-c.id.clock)),c.delete(t))}else yi(r,i,n,a-n)}}if(r.clients.size>0){let e=new Pi;return T(e.restEncoder,0),Si(e,r),e.toUint8Array()}return null},Ti=Jt;var Ei=class e extends He{constructor({guid:e=Yt(),collectionid:t=null,gc:n=!0,gcFilter:r=()=>!0,meta:i=null,autoLoad:a=!1,shouldLoad:o=!0}={}){super(),this.gc=n,this.gcFilter=r,this.clientID=Ti(),this.guid=e,this.collectionid=t,this.share=new Map,this.store=new Sa,this._transaction=null,this._transactionCleanups=[],this.subdocs=new Set,this._item=null,this.shouldLoad=o,this.autoLoad=a,this.meta=i,this.isLoaded=!1,this.isSynced=!1,this.isDestroyed=!1,this.whenLoaded=Zt(e=>{this.on(`load`,()=>{this.isLoaded=!0,e(this)})});let s=()=>Zt(e=>{let t=n=>{(n===void 0||n===!0)&&(this.off(`sync`,t),e())};this.on(`sync`,t)});this.on(`sync`,e=>{e===!1&&this.isSynced&&(this.whenSynced=s()),this.isSynced=e===void 0||e===!0,this.isSynced&&!this.isLoaded&&this.emit(`load`,[this])}),this.whenSynced=s()}load(){let e=this._item;e!==null&&!this.shouldLoad&&R(e.parent.doc,e=>{e.subdocsLoaded.add(this)},null,!0),this.shouldLoad=!0}getSubdocs(){return this.subdocs}getSubdocGuids(){return new Set(Le(this.subdocs).map(e=>e.guid))}transact(e,t=null){return R(this,e,t)}get(e,t=B){let n=je(this.share,e,()=>{let e=new t;return e._integrate(this,null),e}),r=n.constructor;if(t!==B&&r!==t)if(r===B){let r=new t;r._map=n._map,n._map.forEach(e=>{for(;e!==null;e=e.left)e.parent=r}),r._start=n._start;for(let e=r._start;e!==null;e=e.right)e.parent=r;return r._length=n._length,this.share.set(e,r),r._integrate(this,null),r}else throw Error(`Type with the name ${e} has already been defined with a different constructor`);return n}getArray(e=``){return this.get(e,Mo)}getText(e=``){return this.get(e,Qo)}getMap(e=``){return this.get(e,V)}getXmlElement(e=``){return this.get(e,H)}getXmlFragment(e=``){return this.get(e,ts)}toJSON(){let e={};return this.share.forEach((t,n)=>{e[n]=t.toJSON()}),e}destroy(){this.isDestroyed=!0,Le(this.subdocs).forEach(e=>e.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,R(t.parent.doc,e=>{let r=n.doc;t.deleted||e.subdocsAdded.add(r),e.subdocsRemoved.add(this)},null,!0)}this.emit(`destroyed`,[!0]),this.emit(`destroy`,[this]),super.destroy()}},Di=class{constructor(e){this.restDecoder=e}resetDsCurVal(){}readDsClock(){return j(this.restDecoder)}readDsLen(){return j(this.restDecoder)}},Oi=class extends Di{readLeftID(){return F(j(this.restDecoder),j(this.restDecoder))}readRightID(){return F(j(this.restDecoder),j(this.restDecoder))}readClient(){return j(this.restDecoder)}readInfo(){return Lt(this.restDecoder)}readString(){return zt(this.restDecoder)}readParentInfo(){return j(this.restDecoder)===1}readTypeRef(){return j(this.restDecoder)}readLen(){return j(this.restDecoder)}readAny(){return Ht(this.restDecoder)}readBuf(){return kn(A(this.restDecoder))}readJSON(){return JSON.parse(zt(this.restDecoder))}readKey(){return zt(this.restDecoder)}},ki=class{constructor(e){this.dsCurrVal=0,this.restDecoder=e}resetDsCurVal(){this.dsCurrVal=0}readDsClock(){return this.dsCurrVal+=j(this.restDecoder),this.dsCurrVal}readDsLen(){let e=j(this.restDecoder)+1;return this.dsCurrVal+=e,e}},Ai=class extends ki{constructor(e){super(e),this.keys=[],j(e),this.keyClockDecoder=new Gt(A(e)),this.clientDecoder=new Wt(A(e)),this.leftClockDecoder=new Gt(A(e)),this.rightClockDecoder=new Gt(A(e)),this.infoDecoder=new Ut(A(e),Lt),this.stringDecoder=new Kt(A(e)),this.parentInfoDecoder=new Ut(A(e),Lt),this.typeRefDecoder=new Wt(A(e)),this.lenDecoder=new Wt(A(e))}readLeftID(){return new ra(this.clientDecoder.read(),this.leftClockDecoder.read())}readRightID(){return new ra(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 Ht(this.restDecoder)}readBuf(){return A(this.restDecoder)}readJSON(){return Ht(this.restDecoder)}readKey(){let e=this.keyClockDecoder.read();if(e<this.keys.length)return this.keys[e];{let e=this.stringDecoder.read();return this.keys.push(e),e}}},ji=class{constructor(){this.restEncoder=lt()}toUint8Array(){return C(this.restEncoder)}resetDsCurVal(){}writeDsClock(e){T(this.restEncoder,e)}writeDsLen(e){T(this.restEncoder,e)}},Mi=class extends ji{writeLeftID(e){T(this.restEncoder,e.client),T(this.restEncoder,e.clock)}writeRightID(e){T(this.restEncoder,e.client),T(this.restEncoder,e.clock)}writeClient(e){T(this.restEncoder,e)}writeInfo(e){ft(this.restEncoder,e)}writeString(e){gt(this.restEncoder,e)}writeParentInfo(e){T(this.restEncoder,+!!e)}writeTypeRef(e){T(this.restEncoder,e)}writeLen(e){T(this.restEncoder,e)}writeAny(e){wt(this.restEncoder,e)}writeBuf(e){E(this.restEncoder,e)}writeJSON(e){gt(this.restEncoder,JSON.stringify(e))}writeKey(e){gt(this.restEncoder,e)}},Ni=class{constructor(){this.restEncoder=lt(),this.dsCurrVal=0}toUint8Array(){return C(this.restEncoder)}resetDsCurVal(){this.dsCurrVal=0}writeDsClock(e){let t=e-this.dsCurrVal;this.dsCurrVal=e,T(this.restEncoder,t)}writeDsLen(e){e===0&&O(),T(this.restEncoder,e-1),this.dsCurrVal+=e}},Pi=class extends Ni{constructor(){super(),this.keyMap=new Map,this.keyClock=0,this.keyClockEncoder=new kt,this.clientEncoder=new Dt,this.leftClockEncoder=new kt,this.rightClockEncoder=new kt,this.infoEncoder=new Tt(ft),this.stringEncoder=new At,this.parentInfoEncoder=new Tt(ft),this.typeRefEncoder=new Dt,this.lenEncoder=new Dt}toUint8Array(){let e=lt();return T(e,0),E(e,this.keyClockEncoder.toUint8Array()),E(e,this.clientEncoder.toUint8Array()),E(e,this.leftClockEncoder.toUint8Array()),E(e,this.rightClockEncoder.toUint8Array()),E(e,C(this.infoEncoder)),E(e,this.stringEncoder.toUint8Array()),E(e,C(this.parentInfoEncoder)),E(e,this.typeRefEncoder.toUint8Array()),E(e,this.lenEncoder.toUint8Array()),_t(e,C(this.restEncoder)),C(e)}writeLeftID(e){this.clientEncoder.write(e.client),this.leftClockEncoder.write(e.clock)}writeRightID(e){this.clientEncoder.write(e.client),this.rightClockEncoder.write(e.clock)}writeClient(e){this.clientEncoder.write(e)}writeInfo(e){this.infoEncoder.write(e)}writeString(e){this.stringEncoder.write(e)}writeParentInfo(e){this.parentInfoEncoder.write(+!!e)}writeTypeRef(e){this.typeRefEncoder.write(e)}writeLen(e){this.lenEncoder.write(e)}writeAny(e){wt(this.restEncoder,e)}writeBuf(e){E(this.restEncoder,e)}writeJSON(e){wt(this.restEncoder,e)}writeKey(e){let t=this.keyMap.get(e);t===void 0?(this.keyClockEncoder.write(this.keyClock++),this.stringEncoder.write(e)):this.keyClockEncoder.write(t)}};const Fi=(e,t,n,r)=>{r=Ke(r,t[0].id.clock);let i=Ta(t,r);T(e.restEncoder,t.length-i),e.writeClient(n),T(e.restEncoder,r);let a=t[i];a.write(e,r-a.id.clock);for(let n=i+1;n<t.length;n++)t[n].write(e,0)},Ii=(e,t,n)=>{let r=new Map;n.forEach((e,n)=>{I(t,n)>e&&r.set(n,e)}),Ca(t).forEach((e,t)=>{n.has(t)||r.set(t,0)}),T(e.restEncoder,r.size),Le(r.entries()).sort((e,t)=>t[0]-e[0]).forEach(([n,r])=>{Fi(e,t.clients.get(n),n,r)})},Li=(e,t)=>{let n=x(),r=j(e.restDecoder);for(let i=0;i<r;i++){let r=j(e.restDecoder),i=Array(r),a=e.readClient(),o=j(e.restDecoder);n.set(a,{i:0,refs:i});for(let n=0;n<r;n++){let r=e.readInfo();switch(31&r){case 0:{let t=e.readLen();i[n]=new W(F(a,o),t),o+=t;break}case 10:{let t=j(e.restDecoder);i[n]=new q(F(a,o),t),o+=t;break}default:{let s=!(r&192),c=new K(F(a,o),null,(r&128)==128?e.readLeftID():null,null,(r&64)==64?e.readRightID():null,s?e.readParentInfo()?t.get(e.readString()):e.readLeftID():null,s&&(r&32)==32?e.readString():null,Vs(e,r));i[n]=c,o+=c.length}}}}return n},Ri=(e,t,n)=>{let r=[],i=Le(n.keys()).sort((e,t)=>e-t);if(i.length===0)return null;let a=()=>{if(i.length===0)return null;let e=n.get(i[i.length-1]);for(;e.refs.length===e.i;)if(i.pop(),i.length>0)e=n.get(i[i.length-1]);else return null;return e},o=a();if(o===null)return null;let s=new Sa,c=new Map,l=(e,t)=>{let n=c.get(e);(n==null||n>t)&&c.set(e,t)},u=o.refs[o.i++],d=new Map,f=()=>{for(let e of r){let t=e.id.client,r=n.get(t);r?(r.i--,s.clients.set(t,r.refs.slice(r.i)),n.delete(t),r.i=0,r.refs=[]):s.clients.set(t,[e]),i=i.filter(e=>e!==t)}r.length=0};for(;;){if(u.constructor!==q){let i=je(d,u.id.client,()=>I(t,u.id.client))-u.id.clock;if(i<0)r.push(u),l(u.id.client,u.id.clock-1),f();else{let a=u.getMissing(e,t);if(a!==null){r.push(u);let e=n.get(a)||{refs:[],i:0};if(e.refs.length===e.i)l(a,I(t,a)),f();else{u=e.refs[e.i++];continue}}else(i===0||i<u.length)&&(u.integrate(e,i),d.set(u.id.client,u.id.clock+u.length))}}if(r.length>0)u=r.pop();else if(o!==null&&o.i<o.refs.length)u=o.refs[o.i++];else{if(o=a(),o===null)break;u=o.refs[o.i++]}}if(s.clients.size>0){let e=new Pi;return Ii(e,s,new Map),T(e.restEncoder,0),{missing:c,update:e.toUint8Array()}}return null},zi=(e,t)=>Ii(e,t.doc.store,t.beforeState),Bi=(e,t,n,r=new Ai(e))=>R(t,e=>{e.local=!1;let t=!1,n=e.doc,i=n.store,a=Li(r,n),o=Ri(e,i,a),s=i.pendingStructs;if(s){for(let[e,n]of s.missing)if(n<I(i,e)){t=!0;break}if(o){for(let[e,t]of o.missing){let n=s.missing.get(e);(n==null||n>t)&&s.missing.set(e,t)}s.update=qa([s.update,o.update])}}else i.pendingStructs=o;let c=wi(r,e,i);if(i.pendingDs){let t=new Ai(k(i.pendingDs));j(t.restDecoder);let n=wi(t,e,i);i.pendingDs=c&&n?qa([c,n]):c||n}else i.pendingDs=c;if(t){let t=i.pendingStructs.update;i.pendingStructs=null,Vi(e.doc,t)}},n,!1),Vi=(e,t,n,r=Ai)=>{let i=k(t);Bi(i,e,n,new r(i))},Hi=(e,t,n)=>Vi(e,t,n,Oi),Ui=(e,t,n=new Map)=>{Ii(e,t.store,n),Si(e,xi(t.store))},Wi=(e,t=new Uint8Array([0]),n=new Pi)=>{let r=qi(t);Ui(n,e,r);let i=[n.toUint8Array()];if(e.store.pendingDs&&i.push(e.store.pendingDs),e.store.pendingStructs&&i.push(Ja(e.store.pendingStructs.update,t)),i.length>1){if(n.constructor===Mi)return Ga(i.map((e,t)=>t===0?e:$a(e)));if(n.constructor===Pi)return qa(i)}return i[0]},Gi=(e,t)=>Wi(e,t,new Mi),Ki=e=>{let t=new Map,n=j(e.restDecoder);for(let r=0;r<n;r++){let n=j(e.restDecoder),r=j(e.restDecoder);t.set(n,r)}return t},qi=e=>Ki(new Di(k(e))),Ji=(e,t)=>(T(e.restEncoder,t.size),Le(t.entries()).sort((e,t)=>t[0]-e[0]).forEach(([t,n])=>{T(e.restEncoder,t),T(e.restEncoder,n)}),e),Yi=(e,t)=>Ji(e,Ca(t.store)),Xi=(e,t=new Ni)=>(e instanceof Map?Ji(t,e):Yi(t,e),t.toUint8Array()),Zi=e=>Xi(e,new ji);var Qi=class{constructor(){this.l=[]}};const $i=()=>new Qi,ea=(e,t)=>e.l.push(t),ta=(e,t)=>{let n=e.l,r=n.length;e.l=n.filter(e=>t!==e),r===e.l.length&&console.error(`[yjs] Tried to remove event handler that doesn't exist.`)},na=(e,t,n)=>hn(e.l,[t,n]);var ra=class{constructor(e,t){this.client=e,this.clock=t}};const ia=(e,t)=>e===t||e!==null&&t!==null&&e.client===t.client&&e.clock===t.clock,F=(e,t)=>new ra(e,t),aa=e=>{for(let[t,n]of e.doc.share.entries())if(n===e)return t;throw O()},oa=(e,t)=>{for(;t!==null;){if(t.parent===e)return!0;t=t.parent._item}return!1};var sa=class{constructor(e,t=e.getMap(`users`)){let n=new Map;this.yusers=t,this.doc=e,this.clients=new Map,this.dss=n;let r=(e,t)=>{let n=e.get(`ds`),r=e.get(`ids`),i=e=>this.clients.set(e,t);n.observe(e=>{e.changes.added.forEach(e=>{e.content.getContent().forEach(e=>{e instanceof Uint8Array&&this.dss.set(t,vi([this.dss.get(t)||bi(),Ci(new Di(k(e)))]))})})}),this.dss.set(t,vi(n.map(e=>Ci(new Di(k(e)))))),r.observe(e=>e.changes.added.forEach(e=>e.content.getContent().forEach(i))),r.forEach(i)};t.observe(e=>{e.keysChanged.forEach(e=>r(t.get(e),e))}),t.forEach(r)}setUserMapping(e,t,n,{filter:r=()=>!0}={}){let i=this.yusers,a=i.get(n);a||(a=new V,a.set(`ids`,new Mo),a.set(`ds`,new Mo),i.set(n,a)),a.get(`ids`).push([t]),i.observe(e=>{setTimeout(()=>{let e=i.get(n);if(e!==a){a=e,this.clients.forEach((e,t)=>{n===e&&a.get(`ids`).push([t])});let t=new ji,r=this.dss.get(n);r&&(Si(t,r),a.get(`ds`).push([t.toUint8Array()]))}},0)}),e.on(`afterTransaction`,e=>{setTimeout(()=>{let t=a.get(`ds`),n=e.deleteSet;if(e.local&&n.clients.size>0&&r(e,n)){let e=new ji;Si(e,n),t.push([e.toUint8Array()])}})})}getUserByClientId(e){return this.clients.get(e)||null}getUserByDeletedId(e){for(let[t,n]of this.dss.entries())if(gi(n,e))return t;return null}},ca=class{constructor(e,t,n,r=0){this.type=e,this.tname=t,this.item=n,this.assoc=r}},la=class{constructor(e,t,n=0){this.type=e,this.index=t,this.assoc=n}};const ua=(e,t,n=0)=>new la(e,t,n),da=(e,t,n)=>{let r=null,i=null;return e._item===null?i=aa(e):r=F(e._item.id.client,e._item.id.clock),new ca(r,i,t,n)},fa=(e,t,n=0)=>{let r=e._start;if(n<0){if(t===0)return da(e,null,n);t--}for(;r!==null;){if(!r.deleted&&r.countable){if(r.length>t)return da(e,F(r.id.client,r.id.clock+t),n);t-=r.length}if(r.right===null&&n<0)return da(e,r.lastId,n);r=r.right}return da(e,null,n)},pa=(e,t)=>{let n=Ea(e,t);return{item:n,diff:t.clock-n.id.clock}},ma=(e,t,n=!0)=>{let r=t.store,i=e.item,a=e.type,o=e.tname,s=e.assoc,c=null,l=0;if(i!==null){if(I(r,i.client)<=i.clock)return null;let e=n?Is(r,i):pa(r,i),t=e.item;if(!(t instanceof K))return null;if(c=t.parent,c._item===null||!c._item.deleted){l=t.deleted||!t.countable?0:e.diff+(s>=0?0:1);let n=t.left;for(;n!==null;)!n.deleted&&n.countable&&(l+=n.length),n=n.left}}else{if(o!==null)c=t.get(o);else if(a!==null){if(I(r,a.client)<=a.clock)return null;let{item:e}=n?Is(r,a):{item:Ea(r,a)};if(e instanceof K&&e.content instanceof Ps)c=e.content.type;else return null}else throw O();l=s>=0?c._length:0}return ua(c,l,e.assoc)},ha=(e,t)=>e===t||e!==null&&t!==null&&e.tname===t.tname&&ia(e.item,t.item)&&ia(e.type,t.type)&&e.assoc===t.assoc;var ga=class{constructor(e,t){this.ds=e,this.sv=t}};const _a=(e,t)=>new ga(e,t),va=_a(bi(),new Map),ya=e=>_a(xi(e.store),Ca(e.store)),ba=(e,t)=>t===void 0?!e.deleted:t.sv.has(e.id.client)&&(t.sv.get(e.id.client)||0)>e.id.clock&&!gi(t.ds,e.id),xa=(e,t)=>{let n=je(e.meta,xa,Pe),r=e.doc.store;n.has(t)||(t.sv.forEach((t,n)=>{t<I(r,n)&&L(e,F(n,t))}),mi(e,t.ds,e=>{}),n.add(t))};var Sa=class{constructor(){this.clients=new Map,this.pendingStructs=null,this.pendingDs=null}};const Ca=e=>{let t=new Map;return e.clients.forEach((e,n)=>{let r=e[e.length-1];t.set(n,r.id.clock+r.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},wa=(e,t)=>{let n=e.clients.get(t.id.client);if(n===void 0)n=[],e.clients.set(t.id.client,n);else{let e=n[n.length-1];if(e.id.clock+e.length!==t.id.clock)throw O()}n.push(t)},Ta=(e,t)=>{let n=0,r=e.length-1,i=e[r],a=i.id.clock;if(a===t)return r;let o=S(t/(a+i.length-1)*r);for(;n<=r;){if(i=e[o],a=i.id.clock,a<=t){if(t<a+i.length)return o;n=o+1}else r=o-1;o=S((n+r)/2)}throw O()},Ea=(e,t)=>{let n=e.clients.get(t.client);return n[Ta(n,t.clock)]},Da=(e,t,n)=>{let r=Ta(t,n),i=t[r];return i.id.clock<n&&i instanceof K?(t.splice(r+1,0,Rs(e,i,n-i.id.clock)),r+1):r},L=(e,t)=>{let n=e.doc.store.clients.get(t.client);return n[Da(e,n,t.clock)]},Oa=(e,t,n)=>{let r=t.clients.get(n.client),i=Ta(r,n.clock),a=r[i];return n.clock!==a.id.clock+a.length-1&&a.constructor!==W&&r.splice(i+1,0,Rs(e,a,n.clock-a.id.clock+1)),a},ka=(e,t,n)=>{let r=e.clients.get(t.id.client);r[Ta(r,t.id.clock)]=n},Aa=(e,t,n,r,i)=>{if(r===0)return;let a=n+r,o=Da(e,t,n),s;do s=t[o++],a<s.id.clock+s.length&&Da(e,t,a),i(s);while(o<t.length&&t[o].id.clock<a)};var ja=class{constructor(e,t,n){this.doc=e,this.deleteSet=new pi,this.beforeState=Ca(e.store),this.afterState=new Map,this.changed=new Map,this.changedParentTypes=new Map,this._mergeStructs=[],this.origin=t,this.meta=new Map,this.local=n,this.subdocsAdded=new Set,this.subdocsRemoved=new Set,this.subdocsLoaded=new Set,this._needFormattingCleanup=!1}};const Ma=(e,t)=>t.deleteSet.clients.size===0&&!Ne(t.afterState,(e,n)=>t.beforeState.get(n)!==e)?!1:(_i(t.deleteSet),zi(e,t),Si(e,t.deleteSet),!0),Na=(e,t,n)=>{let r=t._item;(r===null||r.id.clock<(e.beforeState.get(r.id.client)||0)&&!r.deleted)&&je(e.changed,t,Pe).add(n)},Pa=(e,t)=>{let n=e[t],r=e[t-1],i=t;for(;i>0;n=r,r=e[--i-1]){if(r.deleted===n.deleted&&r.constructor===n.constructor&&r.mergeWith(n)){n instanceof K&&n.parentSub!==null&&n.parent._map.get(n.parentSub)===n&&n.parent._map.set(n.parentSub,r);continue}break}let a=t-i;return a&&e.splice(t+1-a,a),a},Fa=(e,t,n)=>{for(let[r,i]of e.clients.entries()){let e=t.clients.get(r);for(let r=i.length-1;r>=0;r--){let a=i[r],o=a.clock+a.len;for(let r=Ta(e,a.clock),i=e[r];r<e.length&&i.id.clock<o;i=e[++r]){let i=e[r];if(a.clock+a.len<=i.id.clock)break;i instanceof K&&i.deleted&&!i.keep&&n(i)&&i.gc(t,!1)}}}},Ia=(e,t)=>{e.clients.forEach((e,n)=>{let r=t.clients.get(n);for(let t=e.length-1;t>=0;t--){let n=e[t],i=Ge(r.length-1,1+Ta(r,n.clock+n.len-1));for(let e=i,t=r[e];e>0&&t.id.clock>=n.clock;t=r[e])e-=1+Pa(r,e)}})},La=(e,t)=>{if(t<e.length){let n=e[t],r=n.doc,i=r.store,a=n.deleteSet,o=n._mergeStructs;try{_i(a),n.afterState=Ca(n.doc.store),r.emit(`beforeObserverCalls`,[n,r]);let e=[];n.changed.forEach((t,r)=>e.push(()=>{(r._item===null||!r._item.deleted)&&r._callObserver(n,t)})),e.push(()=>{n.changedParentTypes.forEach((t,r)=>{r._dEH.l.length>0&&(r._item===null||!r._item.deleted)&&(t=t.filter(e=>e.target._item===null||!e.target._item.deleted),t.forEach(e=>{e.currentTarget=r,e._path=null}),t.sort((e,t)=>e.path.length-t.path.length),e.push(()=>{na(r._dEH,t,n)}))}),e.push(()=>r.emit(`afterTransaction`,[n,r])),e.push(()=>{n._needFormattingCleanup&&Yo(n)})}),hn(e,[])}finally{r.gc&&Fa(a,i,r.gcFilter),Ia(a,i),n.afterState.forEach((e,t)=>{let r=n.beforeState.get(t)||0;if(r!==e){let e=i.clients.get(t),n=Ke(Ta(e,r),1);for(let t=e.length-1;t>=n;)t-=1+Pa(e,t)}});for(let e=o.length-1;e>=0;e--){let{client:t,clock:n}=o[e].id,r=i.clients.get(t),a=Ta(r,n);a+1<r.length&&Pa(r,a+1)>1||a>0&&Pa(r,a)}if(!n.local&&n.afterState.get(r.clientID)!==n.beforeState.get(r.clientID)&&(oi(ti,Jr,`[yjs] `,Yr,$r,`Changed the client-id because another client seems to be using it.`),r.clientID=Ti()),r.emit(`afterTransactionCleanup`,[n,r]),r._observers.has(`update`)){let e=new Mi;Ma(e,n)&&r.emit(`update`,[e.toUint8Array(),n.origin,r,n])}if(r._observers.has(`updateV2`)){let e=new Pi;Ma(e,n)&&r.emit(`updateV2`,[e.toUint8Array(),n.origin,r,n])}let{subdocsAdded:s,subdocsLoaded:c,subdocsRemoved:l}=n;(s.size>0||l.size>0||c.size>0)&&(s.forEach(e=>{e.clientID=r.clientID,e.collectionid??=r.collectionid,r.subdocs.add(e)}),l.forEach(e=>r.subdocs.delete(e)),r.emit(`subdocs`,[{loaded:c,added:s,removed:l},r,n]),l.forEach(e=>e.destroy())),e.length<=t+1?(r._transactionCleanups=[],r.emit(`afterAllTransactions`,[r,e])):La(e,t+1)}}},R=(e,t,n=null,r=!0)=>{let i=e._transactionCleanups,a=!1,o=null;e._transaction===null&&(a=!0,e._transaction=new ja(e,n,r),i.push(e._transaction),i.length===1&&e.emit(`beforeAllTransactions`,[e]),e.emit(`beforeTransaction`,[e._transaction,e]));try{o=t(e._transaction)}finally{if(a){let t=e._transaction===i[0];e._transaction=null,t&&La(i,0)}}return o};var Ra=class{constructor(e,t){this.insertions=t,this.deletions=e,this.meta=new Map}};const za=(e,t,n)=>{mi(e,n.deletions,n=>{n instanceof K&&t.scope.some(t=>t===e.doc||oa(t,n))&&Ls(n,!1)})},Ba=(e,t,n)=>{let r=null,i=e.doc,a=e.scope;R(i,n=>{for(;t.length>0&&e.currStackItem===null;){let r=i.store,o=t.pop(),s=new Set,c=[],l=!1;mi(n,o.insertions,e=>{if(e instanceof K){if(e.redone!==null){let{item:t,diff:i}=Is(r,e.id);i>0&&(t=L(n,F(t.id.client,t.id.clock+i))),e=t}!e.deleted&&a.some(t=>t===n.doc||oa(t,e))&&c.push(e)}}),mi(n,o.deletions,e=>{e instanceof K&&a.some(t=>t===n.doc||oa(t,e))&&!gi(o.insertions,e.id)&&s.add(e)}),s.forEach(t=>{l=Bs(n,t,s,o.insertions,e.ignoreRemoteMapChanges,e)!==null||l});for(let t=c.length-1;t>=0;t--){let r=c[t];e.deleteFilter(r)&&(r.delete(n),l=!0)}e.currStackItem=l?o:null}n.changed.forEach((e,t)=>{e.has(null)&&t._searchMarker&&(t._searchMarker.length=0)}),r=n},e);let o=e.currStackItem;if(o!=null){let t=r.changedParentTypes;e.emit(`stack-item-popped`,[{stackItem:o,type:n,changedParentTypes:t,origin:e},e]),e.currStackItem=null}return o};var Va=class extends He{constructor(e,{captureTimeout:t=500,captureTransaction:n=e=>!0,deleteFilter:r=()=>!0,trackedOrigins:i=new Set([null]),ignoreRemoteMapChanges:a=!1,doc:o=Ve(e)?e[0].doc:e instanceof Ei?e:e.doc}={}){super(),this.scope=[],this.doc=o,this.addToScope(e),this.deleteFilter=r,i.add(this),this.trackedOrigins=i,this.captureTransaction=n,this.undoStack=[],this.redoStack=[],this.undoing=!1,this.redoing=!1,this.currStackItem=null,this.lastChange=0,this.ignoreRemoteMapChanges=a,this.captureTimeout=t,this.afterTransactionHandler=e=>{if(!this.captureTransaction(e)||!this.scope.some(t=>e.changedParentTypes.has(t)||t===this.doc)||!this.trackedOrigins.has(e.origin)&&(!e.origin||!this.trackedOrigins.has(e.origin.constructor)))return;let t=this.undoing,n=this.redoing,r=t?this.redoStack:this.undoStack;t?this.stopCapturing():n||this.clear(!1,!0);let i=new pi;e.afterState.forEach((t,n)=>{let r=e.beforeState.get(n)||0,a=t-r;a>0&&yi(i,n,r,a)});let a=Xt(),o=!1;if(this.lastChange>0&&a-this.lastChange<this.captureTimeout&&r.length>0&&!t&&!n){let t=r[r.length-1];t.deletions=vi([t.deletions,e.deleteSet]),t.insertions=vi([t.insertions,i])}else r.push(new Ra(e.deleteSet,i)),o=!0;!t&&!n&&(this.lastChange=a),mi(e,e.deleteSet,t=>{t instanceof K&&this.scope.some(n=>n===e.doc||oa(n,t))&&Ls(t,!0)});let s=[{stackItem:r[r.length-1],origin:e.origin,type:t?`redo`:`undo`,changedParentTypes:e.changedParentTypes},this];o?this.emit(`stack-item-added`,s):this.emit(`stack-item-updated`,s)},this.doc.on(`afterTransaction`,this.afterTransactionHandler),this.doc.on(`destroy`,()=>{this.destroy()})}addToScope(e){let t=new Set(this.scope);e=Ve(e)?e:[e],e.forEach(e=>{t.has(e)||(t.add(e),(e instanceof B?e.doc!==this.doc:e!==this.doc)&&si(`[yjs#509] Not same Y.Doc`),this.scope.push(e))})}addTrackedOrigin(e){this.trackedOrigins.add(e)}removeTrackedOrigin(e){this.trackedOrigins.delete(e)}clear(e=!0,t=!0){(e&&this.canUndo()||t&&this.canRedo())&&this.doc.transact(n=>{e&&(this.undoStack.forEach(e=>za(n,this,e)),this.undoStack=[]),t&&(this.redoStack.forEach(e=>za(n,this,e)),this.redoStack=[]),this.emit(`stack-cleared`,[{undoStackCleared:e,redoStackCleared:t}])})}stopCapturing(){this.lastChange=0}undo(){this.undoing=!0;let e;try{e=Ba(this,this.undoStack,`undo`)}finally{this.undoing=!1}return e}redo(){this.redoing=!0;let e;try{e=Ba(this,this.redoStack,`redo`)}finally{this.redoing=!1}return e}canUndo(){return this.undoStack.length>0}canRedo(){return this.redoStack.length>0}destroy(){this.trackedOrigins.delete(this),this.doc.off(`afterTransaction`,this.afterTransactionHandler),super.destroy()}};function*Ha(e){let t=j(e.restDecoder);for(let n=0;n<t;n++){let t=j(e.restDecoder),n=e.readClient(),r=j(e.restDecoder);for(let i=0;i<t;i++){let t=e.readInfo();if(t===10){let t=j(e.restDecoder);yield new q(F(n,r),t),r+=t}else if(31&t){let i=!(t&192),a=new K(F(n,r),null,(t&128)==128?e.readLeftID():null,null,(t&64)==64?e.readRightID():null,i?e.readParentInfo()?e.readString():e.readLeftID():null,i&&(t&32)==32?e.readString():null,Vs(e,t));yield a,r+=a.length}else{let t=e.readLen();yield new W(F(n,r),t),r+=t}}}}var Ua=class{constructor(e,t){this.gen=Ha(e),this.curr=null,this.done=!1,this.filterSkips=t,this.next()}next(){do this.curr=this.gen.next().value||null;while(this.filterSkips&&this.curr!==null&&this.curr.constructor===q);return this.curr}},Wa=class{constructor(e){this.currClient=0,this.startClock=0,this.written=0,this.encoder=e,this.clientStructs=[]}};const Ga=e=>qa(e,Oi,Mi),Ka=(e,t)=>{if(e.constructor===W){let{client:n,clock:r}=e.id;return new W(F(n,r+t),e.length-t)}if(e.constructor===q){let{client:n,clock:r}=e.id;return new q(F(n,r+t),e.length-t)}{let n=e,{client:r,clock:i}=n.id;return new K(F(r,i+t),null,F(r,i+t-1),null,n.rightOrigin,n.parent,n.parentSub,n.content.splice(t))}},qa=(e,t=Ai,n=Pi)=>{if(e.length===1)return e[0];let r=e.map(e=>new t(k(e))),i=r.map(e=>new Ua(e,!0)),a=null,o=new n,s=new Wa(o);for(;i=i.filter(e=>e.curr!==null),i.sort((e,t)=>{if(e.curr.id.client===t.curr.id.client){let n=e.curr.id.clock-t.curr.id.clock;return n===0?e.curr.constructor===t.curr.constructor?0:e.curr.constructor===q?1:-1:n}return t.curr.id.client-e.curr.id.client}),i.length!==0;){let e=i[0],t=e.curr.id.client;if(a!==null){let n=e.curr,r=!1;for(;n!==null&&n.id.clock+n.length<=a.struct.id.clock+a.struct.length&&n.id.client>=a.struct.id.client;)n=e.next(),r=!0;if(n===null||n.id.client!==t||r&&n.id.clock>a.struct.id.clock+a.struct.length)continue;if(t!==a.struct.id.client)Xa(s,a.struct,a.offset),a={struct:n,offset:0},e.next();else if(a.struct.id.clock+a.struct.length<n.id.clock)if(a.struct.constructor===q)a.struct.length=n.id.clock+n.length-a.struct.id.clock;else{Xa(s,a.struct,a.offset);let e=n.id.clock-a.struct.id.clock-a.struct.length;a={struct:new q(F(t,a.struct.id.clock+a.struct.length),e),offset:0}}else{let t=a.struct.id.clock+a.struct.length-n.id.clock;t>0&&(a.struct.constructor===q?a.struct.length-=t:n=Ka(n,t)),a.struct.mergeWith(n)||(Xa(s,a.struct,a.offset),a={struct:n,offset:0},e.next())}}else a={struct:e.curr,offset:0},e.next();for(let n=e.curr;n!==null&&n.id.client===t&&n.id.clock===a.struct.id.clock+a.struct.length&&n.constructor!==q;n=e.next())Xa(s,a.struct,a.offset),a={struct:n,offset:0}}a!==null&&(Xa(s,a.struct,a.offset),a=null),Za(s);let c=r.map(e=>Ci(e)),l=vi(c);return Si(o,l),o.toUint8Array()},Ja=(e,t,n=Ai,r=Pi)=>{let i=qi(t),a=new r,o=new Wa(a),s=new n(k(e)),c=new Ua(s,!1);for(;c.curr;){let e=c.curr,t=e.id.client,n=i.get(t)||0;if(c.curr.constructor===q){c.next();continue}if(e.id.clock+e.length>n)for(Xa(o,e,Ke(n-e.id.clock,0)),c.next();c.curr&&c.curr.id.client===t;)Xa(o,c.curr,0),c.next();else for(;c.curr&&c.curr.id.client===t&&c.curr.id.clock+c.curr.length<=n;)c.next()}Za(o);let l=Ci(s);return Si(a,l),a.toUint8Array()},Ya=e=>{e.written>0&&(e.clientStructs.push({written:e.written,restEncoder:C(e.encoder.restEncoder)}),e.encoder.restEncoder=lt(),e.written=0)},Xa=(e,t,n)=>{e.written>0&&e.currClient!==t.id.client&&Ya(e),e.written===0&&(e.currClient=t.id.client,e.encoder.writeClient(t.id.client),T(e.encoder.restEncoder,t.id.clock+n)),t.write(e.encoder,n),e.written++},Za=e=>{Ya(e);let t=e.encoder.restEncoder;T(t,e.clientStructs.length);for(let n=0;n<e.clientStructs.length;n++){let r=e.clientStructs[n];T(t,r.written),_t(t,r.restEncoder)}},Qa=(e,t,n,r)=>{let i=new n(k(e)),a=new Ua(i,!1),o=new r,s=new Wa(o);for(let e=a.curr;e!==null;e=a.next())Xa(s,t(e),0);Za(s);let c=Ci(i);return Si(o,c),o.toUint8Array()},$a=e=>Qa(e,gn,Ai,Mi),eo=`You must not compute changes after the event-handler fired.`;var to=class{constructor(e,t){this.target=e,this.currentTarget=e,this.transaction=t,this._changes=null,this._keys=null,this._delta=null,this._path=null}get path(){return this._path||=no(this.currentTarget,this.target)}deletes(e){return gi(this.transaction.deleteSet,e.id)}get keys(){if(this._keys===null){if(this.transaction.doc._transactionCleanups.length===0)throw jt(eo);let e=new Map,t=this.target;this.transaction.changed.get(t).forEach(n=>{if(n!==null){let r=t._map.get(n),i,a;if(this.adds(r)){let e=r.left;for(;e!==null&&this.adds(e);)e=e.left;if(this.deletes(r))if(e!==null&&this.deletes(e))i=`delete`,a=Fe(e.content.getContent());else return;else e!==null&&this.deletes(e)?(i=`update`,a=Fe(e.content.getContent())):(i=`add`,a=void 0)}else if(this.deletes(r))i=`delete`,a=Fe(r.content.getContent());else return;e.set(n,{action:i,oldValue:a})}}),this._keys=e}return this._keys}get delta(){return this.changes.delta}adds(e){return e.id.clock>=(this.transaction.beforeState.get(e.id.client)||0)}get changes(){let e=this._changes;if(e===null){if(this.transaction.doc._transactionCleanups.length===0)throw jt(eo);let t=this.target,n=Pe(),r=Pe(),i=[];if(e={added:n,deleted:r,delta:i,keys:this.keys},this.transaction.changed.get(t).has(null)){let e=null,a=()=>{e&&i.push(e)};for(let i=t._start;i!==null;i=i.right)i.deleted?this.deletes(i)&&!this.adds(i)&&((e===null||e.delete===void 0)&&(a(),e={delete:0}),e.delete+=i.length,r.add(i)):this.adds(i)?((e===null||e.insert===void 0)&&(a(),e={insert:[]}),e.insert=e.insert.concat(i.content.getContent()),n.add(i)):((e===null||e.retain===void 0)&&(a(),e={retain:0}),e.retain+=i.length);e!==null&&e.retain===void 0&&a()}this._changes=e}return e}};const no=(e,t)=>{let n=[];for(;t._item!==null&&t!==e;){if(t._item.parentSub!==null)n.unshift(t._item.parentSub);else{let e=0,r=t._item.parent._start;for(;r!==t._item&&r!==null;)!r.deleted&&r.countable&&(e+=r.length),r=r.right;n.unshift(e)}t=t._item.parent}return n},z=()=>{si(`Invalid access: Add Yjs type to a document before reading data.`)};let ro=0;var io=class{constructor(e,t){e.marker=!0,this.p=e,this.index=t,this.timestamp=ro++}};const ao=e=>{e.timestamp=ro++},oo=(e,t,n)=>{e.p.marker=!1,e.p=t,t.marker=!0,e.index=n,e.timestamp=ro++},so=(e,t,n)=>{if(e.length>=80){let r=e.reduce((e,t)=>e.timestamp<t.timestamp?e:t);return oo(r,t,n),r}{let r=new io(t,n);return e.push(r),r}},co=(e,t)=>{if(e._start===null||t===0||e._searchMarker===null)return null;let n=e._searchMarker.length===0?null:e._searchMarker.reduce((e,n)=>We(t-e.index)<We(t-n.index)?e:n),r=e._start,i=0;for(n!==null&&(r=n.p,i=n.index,ao(n));r.right!==null&&i<t;){if(!r.deleted&&r.countable){if(t<i+r.length)break;i+=r.length}r=r.right}for(;r.left!==null&&i>t;)r=r.left,!r.deleted&&r.countable&&(i-=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&&(i-=r.length);return n!==null&&We(n.index-i)<r.parent.length/80?(oo(n,r,i),n):so(e._searchMarker,r,i)},lo=(e,t,n)=>{for(let r=e.length-1;r>=0;r--){let i=e[r];if(n>0){let t=i.p;for(t.marker=!1;t&&(t.deleted||!t.countable);)t=t.left,t&&!t.deleted&&t.countable&&(i.index-=t.length);if(t===null||t.marker===!0){e.splice(r,1);continue}i.p=t,t.marker=!0}(t<i.index||n>0&&t===i.index)&&(i.index=Ke(t,i.index+n))}},uo=(e,t,n)=>{let r=e,i=t.changedParentTypes;for(;je(i,e,()=>[]).push(n),e._item!==null;)e=e._item.parent;na(r._eH,n,t)};var B=class{constructor(){this._item=null,this._map=new Map,this._start=null,this.doc=null,this._length=0,this._eH=$i(),this._dEH=$i(),this._searchMarker=null}get parent(){return this._item?this._item.parent:null}_integrate(e,t){this.doc=e,this._item=t}_copy(){throw D()}clone(){throw D()}_write(e){}get _first(){let e=this._start;for(;e!==null&&e.deleted;)e=e.right;return e}_callObserver(e,t){!e.local&&this._searchMarker&&(this._searchMarker.length=0)}observe(e){ea(this._eH,e)}observeDeep(e){ea(this._dEH,e)}unobserve(e){ta(this._eH,e)}unobserveDeep(e){ta(this._dEH,e)}toJSON(){}};const fo=(e,t,n)=>{e.doc??z(),t<0&&(t=e._length+t),n<0&&(n=e._length+n);let r=n-t,i=[],a=e._start;for(;a!==null&&r>0;){if(a.countable&&!a.deleted){let e=a.content.getContent();if(e.length<=t)t-=e.length;else{for(let n=t;n<e.length&&r>0;n++)i.push(e[n]),r--;t=0}}a=a.right}return i},po=e=>{e.doc??z();let t=[],n=e._start;for(;n!==null;){if(n.countable&&!n.deleted){let e=n.content.getContent();for(let n=0;n<e.length;n++)t.push(e[n])}n=n.right}return t},mo=(e,t)=>{let n=[],r=e._start;for(;r!==null;){if(r.countable&&ba(r,t)){let e=r.content.getContent();for(let t=0;t<e.length;t++)n.push(e[t])}r=r.right}return n},ho=(e,t)=>{let n=0,r=e._start;for(e.doc??z();r!==null;){if(r.countable&&!r.deleted){let i=r.content.getContent();for(let r=0;r<i.length;r++)t(i[r],n++,e)}r=r.right}},go=(e,t)=>{let n=[];return ho(e,(r,i)=>{n.push(t(r,i,e))}),n},_o=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 e=n[r++];return n.length<=r&&(n=null),{done:!1,value:e}}}},vo=(e,t)=>{e.doc??z();let n=co(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}},yo=(e,t,n,r)=>{let i=n,a=e.doc,o=a.clientID,s=a.store,c=n===null?t._start:n.right,l=[],u=()=>{l.length>0&&(i=new K(F(o,I(s,o)),i,i&&i.lastId,c,c&&c.id,t,null,new Ss(l)),i.integrate(e,0),l=[])};r.forEach(n=>{if(n===null)l.push(n);else switch(n.constructor){case Number:case Object:case Boolean:case Array:case String:l.push(n);break;default:switch(u(),n.constructor){case Uint8Array:case ArrayBuffer:i=new K(F(o,I(s,o)),i,i&&i.lastId,c,c&&c.id,t,null,new ls(new Uint8Array(n))),i.integrate(e,0);break;case Ei:i=new K(F(o,I(s,o)),i,i&&i.lastId,c,c&&c.id,t,null,new ms(n)),i.integrate(e,0);break;default:if(n instanceof B)i=new K(F(o,I(s,o)),i,i&&i.lastId,c,c&&c.id,t,null,new Ps(n)),i.integrate(e,0);else throw Error(`Unexpected content type in insert operation`)}}}),u()},bo=()=>jt(`Length exceeded!`),xo=(e,t,n,r)=>{if(n>t._length)throw bo();if(n===0)return t._searchMarker&&lo(t._searchMarker,n,r.length),yo(e,t,null,r);let i=n,a=co(t,n),o=t._start;for(a!==null&&(o=a.p,n-=a.index,n===0&&(o=o.prev,n+=o&&o.countable&&!o.deleted?o.length:0));o!==null;o=o.right)if(!o.deleted&&o.countable){if(n<=o.length){n<o.length&&L(e,F(o.id.client,o.id.clock+n));break}n-=o.length}return t._searchMarker&&lo(t._searchMarker,i,r.length),yo(e,t,o,r)},So=(e,t,n)=>{let r=(t._searchMarker||[]).reduce((e,t)=>t.index>e.index?t:e,{index:0,p:t._start}).p;if(r)for(;r.right;)r=r.right;return yo(e,t,r,n)},Co=(e,t,n,r)=>{if(r===0)return;let i=n,a=r,o=co(t,n),s=t._start;for(o!==null&&(s=o.p,n-=o.index);s!==null&&n>0;s=s.right)!s.deleted&&s.countable&&(n<s.length&&L(e,F(s.id.client,s.id.clock+n)),n-=s.length);for(;r>0&&s!==null;)s.deleted||(r<s.length&&L(e,F(s.id.client,s.id.clock+r)),s.delete(e),r-=s.length),s=s.right;if(r>0)throw bo();t._searchMarker&&lo(t._searchMarker,i,-a+r)},wo=(e,t,n)=>{let r=t._map.get(n);r!==void 0&&r.delete(e)},To=(e,t,n,r)=>{let i=t._map.get(n)||null,a=e.doc,o=a.clientID,s;if(r==null)s=new Ss([r]);else switch(r.constructor){case Number:case Object:case Boolean:case Array:case String:case Date:case BigInt:s=new Ss([r]);break;case Uint8Array:s=new ls(r);break;case Ei:s=new ms(r);break;default:if(r instanceof B)s=new Ps(r);else throw Error(`Unexpected content type`)}new K(F(o,I(a.store,o)),i,i&&i.lastId,null,null,t,n,s).integrate(e,0)},Eo=(e,t)=>{e.doc??z();let n=e._map.get(t);return n!==void 0&&!n.deleted?n.content.getContent()[n.length-1]:void 0},Do=e=>{let t={};return e.doc??z(),e._map.forEach((e,n)=>{e.deleted||(t[n]=e.content.getContent()[e.length-1])}),t},Oo=(e,t)=>{e.doc??z();let n=e._map.get(t);return n!==void 0&&!n.deleted},ko=(e,t)=>{let n={};return e._map.forEach((e,r)=>{let i=e;for(;i!==null&&(!t.sv.has(i.id.client)||i.id.clock>=(t.sv.get(i.id.client)||0));)i=i.left;i!==null&&ba(i,t)&&(n[r]=i.content.getContent()[i.length-1])}),n},Ao=e=>(e.doc??z(),ui(e._map.entries(),e=>!e[1].deleted));var jo=class extends to{},Mo=class e extends B{constructor(){super(),this._prelimContent=[],this._searchMarker=[]}static from(t){let n=new e;return n.push(t),n}_integrate(e,t){super._integrate(e,t),this.insert(0,this._prelimContent),this._prelimContent=null}_copy(){return new e}clone(){let t=new e;return t.insert(0,this.toArray().map(e=>e instanceof B?e.clone():e)),t}get length(){return this.doc??z(),this._length}_callObserver(e,t){super._callObserver(e,t),uo(this,e,new jo(this,e))}insert(e,t){this.doc===null?this._prelimContent.splice(e,0,...t):R(this.doc,n=>{xo(n,this,e,t)})}push(e){this.doc===null?this._prelimContent.push(...e):R(this.doc,t=>{So(t,this,e)})}unshift(e){this.insert(0,e)}delete(e,t=1){this.doc===null?this._prelimContent.splice(e,t):R(this.doc,n=>{Co(n,this,e,t)})}get(e){return vo(this,e)}toArray(){return po(this)}slice(e=0,t=this.length){return fo(this,e,t)}toJSON(){return this.map(e=>e instanceof B?e.toJSON():e)}map(e){return go(this,e)}forEach(e){ho(this,e)}[Symbol.iterator](){return _o(this)}_write(e){e.writeTypeRef(Ds)}};const No=e=>new Mo;var Po=class extends to{constructor(e,t,n){super(e,t),this.keysChanged=n}},V=class e extends B{constructor(e){super(),this._prelimContent=null,this._prelimContent=e===void 0?new Map:new Map(e)}_integrate(e,t){super._integrate(e,t),this._prelimContent.forEach((e,t)=>{this.set(t,e)}),this._prelimContent=null}_copy(){return new e}clone(){let t=new e;return this.forEach((e,n)=>{t.set(n,e instanceof B?e.clone():e)}),t}_callObserver(e,t){uo(this,e,new Po(this,e,t))}toJSON(){this.doc??z();let e={};return this._map.forEach((t,n)=>{if(!t.deleted){let r=t.content.getContent()[t.length-1];e[n]=r instanceof B?r.toJSON():r}}),e}get size(){return[...Ao(this)].length}keys(){return di(Ao(this),e=>e[0])}values(){return di(Ao(this),e=>e[1].content.getContent()[e[1].length-1])}entries(){return di(Ao(this),e=>[e[0],e[1].content.getContent()[e[1].length-1]])}forEach(e){this.doc??z(),this._map.forEach((t,n)=>{t.deleted||e(t.content.getContent()[t.length-1],n,this)})}[Symbol.iterator](){return this.entries()}delete(e){this.doc===null?this._prelimContent.delete(e):R(this.doc,t=>{wo(t,this,e)})}set(e,t){return this.doc===null?this._prelimContent.set(e,t):R(this.doc,n=>{To(n,this,e,t)}),t}get(e){return Eo(this,e)}has(e){return Oo(this,e)}clear(){this.doc===null?this._prelimContent.clear():R(this.doc,e=>{this.forEach(function(t,n,r){wo(e,r,n)})})}_write(e){e.writeTypeRef(Os)}};const Fo=e=>new V,Io=(e,t)=>e===t||typeof e==`object`&&typeof t==`object`&&e&&t&&fn(e,t);var Lo=class{constructor(e,t,n,r){this.left=e,this.right=t,this.index=n,this.currentAttributes=r}forward(){switch(this.right===null&&O(),this.right.content.constructor){case G:this.right.deleted||Vo(this.currentAttributes,this.right.content);break;default:this.right.deleted||(this.index+=this.right.length)}this.left=this.right,this.right=this.right.right}};const Ro=(e,t,n)=>{for(;t.right!==null&&n>0;){switch(t.right.content.constructor){case G:t.right.deleted||Vo(t.currentAttributes,t.right.content);break;default:t.right.deleted||(n<t.right.length&&L(e,F(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},zo=(e,t,n,r)=>{let i=new Map,a=r?co(t,n):null;if(a){let t=new Lo(a.p.left,a.p,a.index,i);return Ro(e,t,n-a.index)}{let r=new Lo(null,t._start,0,i);return Ro(e,r,n)}},Bo=(e,t,n,r)=>{for(;n.right!==null&&(n.right.deleted===!0||n.right.content.constructor===G&&Io(r.get(n.right.content.key),n.right.content.value));)n.right.deleted||r.delete(n.right.content.key),n.forward();let i=e.doc,a=i.clientID;r.forEach((r,o)=>{let s=n.left,c=n.right,l=new K(F(a,I(i.store,a)),s,s&&s.lastId,c,c&&c.id,t,null,new G(o,r));l.integrate(e,0),n.right=l,n.forward()})},Vo=(e,t)=>{let{key:n,value:r}=t;r===null?e.delete(n):e.set(n,r)},Ho=(e,t)=>{for(;e.right!==null&&(e.right.deleted||e.right.content.constructor===G&&Io(t[e.right.content.key]??null,e.right.content.value));)e.forward()},Uo=(e,t,n,r)=>{let i=e.doc,a=i.clientID,o=new Map;for(let s in r){let c=r[s],l=n.currentAttributes.get(s)??null;if(!Io(l,c)){o.set(s,l);let{left:r,right:u}=n;n.right=new K(F(a,I(i.store,a)),r,r&&r.lastId,u,u&&u.id,t,null,new G(s,c)),n.right.integrate(e,0),n.forward()}}return o},Wo=(e,t,n,r,i)=>{n.currentAttributes.forEach((e,t)=>{i[t]===void 0&&(i[t]=null)});let a=e.doc,o=a.clientID;Ho(n,i);let s=Uo(e,t,n,i),c=r.constructor===String?new ws(r):r instanceof B?new Ps(r):new gs(r),{left:l,right:u,index:d}=n;t._searchMarker&&lo(t._searchMarker,n.index,c.getLength()),u=new K(F(o,I(a.store,o)),l,l&&l.lastId,u,u&&u.id,t,null,c),u.integrate(e,0),n.right=u,n.index=d,n.forward(),Bo(e,t,n,s)},Go=(e,t,n,r,i)=>{let a=e.doc,o=a.clientID;Ho(n,i);let s=Uo(e,t,n,i);iterationLoop:for(;n.right!==null&&(r>0||s.size>0&&(n.right.deleted||n.right.content.constructor===G));){if(!n.right.deleted)switch(n.right.content.constructor){case G:{let{key:t,value:a}=n.right.content,o=i[t];if(o!==void 0){if(Io(o,a))s.delete(t);else{if(r===0)break iterationLoop;s.set(t,a)}n.right.delete(e)}else n.currentAttributes.set(t,a);break}default:r<n.right.length&&L(e,F(n.right.id.client,n.right.id.clock+r)),r-=n.right.length}n.forward()}if(r>0){let i=``;for(;r>0;r--)i+=`
|
|
3
|
+
`;n.right=new K(F(o,I(a.store,o)),n.left,n.left&&n.left.lastId,n.right,n.right&&n.right.id,t,null,new ws(i)),n.right.integrate(e,0),n.forward()}Bo(e,t,n,s)},Ko=(e,t,n,r,i)=>{let a=t,o=x();for(;a&&(!a.countable||a.deleted);){if(!a.deleted&&a.content.constructor===G){let e=a.content;o.set(e.key,e)}a=a.right}let s=0,c=!1;for(;t!==a;){if(n===t&&(c=!0),!t.deleted){let n=t.content;switch(n.constructor){case G:{let{key:a,value:l}=n,u=r.get(a)??null;(o.get(a)!==n||u===l)&&(t.delete(e),s++,!c&&(i.get(a)??null)===l&&u!==l&&(u===null?i.delete(a):i.set(a,u))),!c&&!t.deleted&&Vo(i,n);break}}}t=t.right}return s},qo=(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===G){let r=t.content.key;n.has(r)?t.delete(e):n.add(r)}t=t.left}},Jo=e=>{let t=0;return R(e.doc,n=>{let r=e._start,i=e._start,a=x(),o=Ae(a);for(;i;){if(i.deleted===!1)switch(i.content.constructor){case G:Vo(o,i.content);break;default:t+=Ko(n,r,i,a,o),a=Ae(o),r=i}i=i.right}}),t},Yo=e=>{let t=new Set,n=e.doc;for(let[r,i]of e.afterState.entries()){let a=e.beforeState.get(r)||0;i!==a&&Aa(e,n.store.clients.get(r),a,i,e=>{!e.deleted&&e.content.constructor===G&&e.constructor!==W&&t.add(e.parent)})}R(n,n=>{mi(e,e.deleteSet,e=>{if(e instanceof W||!e.parent._hasFormatting||t.has(e.parent))return;let r=e.parent;e.content.constructor===G?t.add(r):qo(n,e)});for(let e of t)Jo(e)})},Xo=(e,t,n)=>{let r=n,i=Ae(t.currentAttributes),a=t.right;for(;n>0&&t.right!==null;){if(t.right.deleted===!1)switch(t.right.content.constructor){case Ps:case gs:case ws:n<t.right.length&&L(e,F(t.right.id.client,t.right.id.clock+n)),n-=t.right.length,t.right.delete(e)}t.forward()}a&&Ko(e,a,t.right,i,t.currentAttributes);let o=(t.left||t.right).parent;return o._searchMarker&&lo(o._searchMarker,t.index,-r+n),t};var Zo=class extends to{constructor(e,t,n){super(e,t),this.childListChanged=!1,this.keysChanged=new Set,n.forEach(e=>{e===null?this.childListChanged=!0:this.keysChanged.add(e)})}get changes(){if(this._changes===null){let e={keys:this.keys,delta:this.delta,added:new Set,deleted:new Set};this._changes=e}return this._changes}get delta(){if(this._delta===null){let e=this.target.doc,t=[];R(e,e=>{let n=new Map,r=new Map,i=this.target._start,a=null,o={},s=``,c=0,l=0,u=()=>{if(a!==null){let e=null;switch(a){case`delete`:l>0&&(e={delete:l}),l=0;break;case`insert`:(typeof s==`object`||s.length>0)&&(e={insert:s},n.size>0&&(e.attributes={},n.forEach((t,n)=>{t!==null&&(e.attributes[n]=t)}))),s=``;break;case`retain`:c>0&&(e={retain:c},ln(o)||(e.attributes=an({},o))),c=0}e&&t.push(e),a=null}};for(;i!==null;){switch(i.content.constructor){case Ps:case gs:this.adds(i)?this.deletes(i)||(u(),a=`insert`,s=i.content.getContent()[0],u()):this.deletes(i)?(a!==`delete`&&(u(),a=`delete`),l+=1):i.deleted||(a!==`retain`&&(u(),a=`retain`),c+=1);break;case ws:this.adds(i)?this.deletes(i)||(a!==`insert`&&(u(),a=`insert`),s+=i.content.str):this.deletes(i)?(a!==`delete`&&(u(),a=`delete`),l+=i.length):i.deleted||(a!==`retain`&&(u(),a=`retain`),c+=i.length);break;case G:{let{key:t,value:s}=i.content;if(this.adds(i)){if(!this.deletes(i)){let c=n.get(t)??null;Io(c,s)?s!==null&&i.delete(e):(a===`retain`&&u(),Io(s,r.get(t)??null)?delete o[t]:o[t]=s)}}else if(this.deletes(i)){r.set(t,s);let e=n.get(t)??null;Io(e,s)||(a===`retain`&&u(),o[t]=e)}else if(!i.deleted){r.set(t,s);let n=o[t];n!==void 0&&(Io(n,s)?n!==null&&i.delete(e):(a===`retain`&&u(),s===null?delete o[t]:o[t]=s))}i.deleted||(a===`insert`&&u(),Vo(n,i.content));break}}i=i.right}for(u();t.length>0;){let e=t[t.length-1];if(e.retain!==void 0&&e.attributes===void 0)t.pop();else break}}),this._delta=t}return this._delta}},Qo=class e extends B{constructor(e){super(),this._pending=e===void 0?[]:[()=>this.insert(0,e)],this._searchMarker=[],this._hasFormatting=!1}get length(){return this.doc??z(),this._length}_integrate(e,t){super._integrate(e,t);try{this._pending.forEach(e=>e())}catch(e){console.error(e)}this._pending=null}_copy(){return new e}clone(){let t=new e;return t.applyDelta(this.toDelta()),t}_callObserver(e,t){super._callObserver(e,t);let n=new Zo(this,e,t);uo(this,e,n),!e.local&&this._hasFormatting&&(e._needFormattingCleanup=!0)}toString(){this.doc??z();let e=``,t=this._start;for(;t!==null;)!t.deleted&&t.countable&&t.content.constructor===ws&&(e+=t.content.str),t=t.right;return e}toJSON(){return this.toString()}applyDelta(e,{sanitize:t=!0}={}){this.doc===null?this._pending.push(()=>this.applyDelta(e)):R(this.doc,n=>{let r=new Lo(null,this._start,0,new Map);for(let i=0;i<e.length;i++){let a=e[i];if(a.insert!==void 0){let o=!t&&typeof a.insert==`string`&&i===e.length-1&&r.right===null&&a.insert.slice(-1)===`
|
|
4
|
+
`?a.insert.slice(0,-1):a.insert;(typeof o!=`string`||o.length>0)&&Wo(n,this,r,o,a.attributes||{})}else a.retain===void 0?a.delete!==void 0&&Xo(n,r,a.delete):Go(n,this,r,a.retain,a.attributes||{})}})}toDelta(e,t,n){this.doc??z();let r=[],i=new Map,a=this.doc,o=``,s=this._start;function c(){if(o.length>0){let e={},t=!1;i.forEach((n,r)=>{t=!0,e[r]=n});let n={insert:o};t&&(n.attributes=e),r.push(n),o=``}}let l=()=>{for(;s!==null;){if(ba(s,e)||t!==void 0&&ba(s,t))switch(s.content.constructor){case ws:{let r=i.get(`ychange`);e!==void 0&&!ba(s,e)?(r===void 0||r.user!==s.id.client||r.type!==`removed`)&&(c(),i.set(`ychange`,n?n(`removed`,s.id):{type:`removed`})):t!==void 0&&!ba(s,t)?(r===void 0||r.user!==s.id.client||r.type!==`added`)&&(c(),i.set(`ychange`,n?n(`added`,s.id):{type:`added`})):r!==void 0&&(c(),i.delete(`ychange`)),o+=s.content.str;break}case Ps:case gs:{c();let e={insert:s.content.getContent()[0]};if(i.size>0){let t={};e.attributes=t,i.forEach((e,n)=>{t[n]=e})}r.push(e);break}case G:ba(s,e)&&(c(),Vo(i,s.content))}s=s.right}c()};return e||t?R(a,n=>{e&&xa(n,e),t&&xa(n,t),l()},`cleanup`):l(),r}insert(e,t,n){if(t.length<=0)return;let r=this.doc;r===null?this._pending.push(()=>this.insert(e,t,n)):R(r,r=>{let i=zo(r,this,e,!n);n||(n={},i.currentAttributes.forEach((e,t)=>{n[t]=e})),Wo(r,this,i,t,n)})}insertEmbed(e,t,n){let r=this.doc;r===null?this._pending.push(()=>this.insertEmbed(e,t,n||{})):R(r,r=>{let i=zo(r,this,e,!n);Wo(r,this,i,t,n||{})})}delete(e,t){if(t===0)return;let n=this.doc;n===null?this._pending.push(()=>this.delete(e,t)):R(n,n=>{Xo(n,zo(n,this,e,!0),t)})}format(e,t,n){if(t===0)return;let r=this.doc;r===null?this._pending.push(()=>this.format(e,t,n)):R(r,r=>{let i=zo(r,this,e,!1);i.right!==null&&Go(r,this,i,t,n)})}removeAttribute(e){this.doc===null?this._pending.push(()=>this.removeAttribute(e)):R(this.doc,t=>{wo(t,this,e)})}setAttribute(e,t){this.doc===null?this._pending.push(()=>this.setAttribute(e,t)):R(this.doc,n=>{To(n,this,e,t)})}getAttribute(e){return Eo(this,e)}getAttributes(){return Do(this)}_write(e){e.writeTypeRef(ks)}};const $o=e=>new Qo;var es=class{constructor(e,t=()=>!0){this._filter=t,this._root=e,this._currentNode=e._start,this._firstCall=!0,e.doc??z()}[Symbol.iterator](){return this}next(){let e=this._currentNode,t=e&&e.content&&e.content.type;if(e!==null&&(!this._firstCall||e.deleted||!this._filter(t)))do if(t=e.content.type,!e.deleted&&(t.constructor===H||t.constructor===ts)&&t._start!==null)e=t._start;else for(;e!==null;){let t=e.next;if(t!==null){e=t;break}e=e.parent===this._root?null:e.parent._item}while(e!==null&&(e.deleted||!this._filter(e.content.type)));return this._firstCall=!1,e===null?{value:void 0,done:!0}:(this._currentNode=e,{value:e.content.type,done:!1})}},ts=class e extends B{constructor(){super(),this._prelimContent=[]}get firstChild(){let e=this._first;return e?e.content.getContent()[0]:null}_integrate(e,t){super._integrate(e,t),this.insert(0,this._prelimContent),this._prelimContent=null}_copy(){return new e}clone(){let t=new e;return t.insert(0,this.toArray().map(e=>e instanceof B?e.clone():e)),t}get length(){return this.doc??z(),this._prelimContent===null?this._length:this._prelimContent.length}createTreeWalker(e){return new es(this,e)}querySelector(e){e=e.toUpperCase();let t=new es(this,t=>t.nodeName&&t.nodeName.toUpperCase()===e).next();return t.done?null:t.value}querySelectorAll(e){return e=e.toUpperCase(),Le(new es(this,t=>t.nodeName&&t.nodeName.toUpperCase()===e))}_callObserver(e,t){uo(this,e,new is(this,t,e))}toString(){return go(this,e=>e.toString()).join(``)}toJSON(){return this.toString()}toDOM(e=document,t={},n){let r=e.createDocumentFragment();return n!==void 0&&n._createAssociation(r,this),ho(this,i=>{r.insertBefore(i.toDOM(e,t,n),null)}),r}insert(e,t){this.doc===null?this._prelimContent.splice(e,0,...t):R(this.doc,n=>{xo(n,this,e,t)})}insertAfter(e,t){if(this.doc!==null)R(this.doc,n=>{let r=e&&e instanceof B?e._item:e;yo(n,this,r,t)});else{let n=this._prelimContent,r=e===null?0:n.findIndex(t=>t===e)+1;if(r===0&&e!==null)throw jt(`Reference item not found`);n.splice(r,0,...t)}}delete(e,t=1){this.doc===null?this._prelimContent.splice(e,t):R(this.doc,n=>{Co(n,this,e,t)})}toArray(){return po(this)}push(e){this.insert(this.length,e)}unshift(e){this.insert(0,e)}get(e){return vo(this,e)}slice(e=0,t=this.length){return fo(this,e,t)}forEach(e){ho(this,e)}_write(e){e.writeTypeRef(js)}};const ns=e=>new ts;var H=class e extends ts{constructor(e=`UNDEFINED`){super(),this.nodeName=e,this._prelimAttrs=new Map}get nextSibling(){let e=this._item?this._item.next:null;return e?e.content.type:null}get prevSibling(){let e=this._item?this._item.prev:null;return e?e.content.type:null}_integrate(e,t){super._integrate(e,t),this._prelimAttrs.forEach((e,t)=>{this.setAttribute(t,e)}),this._prelimAttrs=null}_copy(){return new e(this.nodeName)}clone(){let t=new e(this.nodeName),n=this.getAttributes();return sn(n,(e,n)=>{t.setAttribute(n,e)}),t.insert(0,this.toArray().map(e=>e instanceof B?e.clone():e)),t}toString(){let e=this.getAttributes(),t=[],n=[];for(let t in e)n.push(t);n.sort();let r=n.length;for(let i=0;i<r;i++){let r=n[i];t.push(r+`="`+e[r]+`"`)}let i=this.nodeName.toLocaleLowerCase();return`<${i}${t.length>0?` `+t.join(` `):``}>${super.toString()}</${i}>`}removeAttribute(e){this.doc===null?this._prelimAttrs.delete(e):R(this.doc,t=>{wo(t,this,e)})}setAttribute(e,t){this.doc===null?this._prelimAttrs.set(e,t):R(this.doc,n=>{To(n,this,e,t)})}getAttribute(e){return Eo(this,e)}hasAttribute(e){return Oo(this,e)}getAttributes(e){return e?ko(this,e):Do(this)}toDOM(e=document,t={},n){let r=e.createElement(this.nodeName),i=this.getAttributes();for(let e in i){let t=i[e];typeof t==`string`&&r.setAttribute(e,t)}return ho(this,i=>{r.appendChild(i.toDOM(e,t,n))}),n!==void 0&&n._createAssociation(r,this),r}_write(e){e.writeTypeRef(As),e.writeKey(this.nodeName)}};const rs=e=>new H(e.readKey());var is=class extends to{constructor(e,t,n){super(e,n),this.childListChanged=!1,this.attributesChanged=new Set,t.forEach(e=>{e===null?this.childListChanged=!0:this.attributesChanged.add(e)})}},as=class e extends V{constructor(e){super(),this.hookName=e}_copy(){return new e(this.hookName)}clone(){let t=new e(this.hookName);return this.forEach((e,n)=>{t.set(n,e)}),t}toDOM(e=document,t={},n){let r=t[this.hookName],i;return i=r===void 0?document.createElement(this.hookName):r.createDom(this),i.setAttribute(`data-yjs-hook`,this.hookName),n!==void 0&&n._createAssociation(i,this),i}_write(e){e.writeTypeRef(Ms),e.writeKey(this.hookName)}};const os=e=>new as(e.readKey());var U=class e extends Qo{get nextSibling(){let e=this._item?this._item.next:null;return e?e.content.type:null}get prevSibling(){let e=this._item?this._item.prev:null;return e?e.content.type:null}_copy(){return new e}clone(){let t=new e;return t.applyDelta(this.toDelta()),t}toDOM(e=document,t,n){let r=e.createTextNode(this.toString());return n!==void 0&&n._createAssociation(r,this),r}toString(){return this.toDelta().map(e=>{let t=[];for(let n in e.attributes){let r=[];for(let t in e.attributes[n])r.push({key:t,value:e.attributes[n][t]});r.sort((e,t)=>e.key<t.key?-1:1),t.push({nodeName:n,attrs:r})}t.sort((e,t)=>e.nodeName<t.nodeName?-1:1);let n=``;for(let e=0;e<t.length;e++){let r=t[e];n+=`<${r.nodeName}`;for(let e=0;e<r.attrs.length;e++){let t=r.attrs[e];n+=` ${t.key}="${t.value}"`}n+=`>`}n+=e.insert;for(let e=t.length-1;e>=0;e--)n+=`</${t[e].nodeName}>`;return n}).join(``)}toJSON(){return this.toString()}_write(e){e.writeTypeRef(Ns)}};const ss=e=>new U;var cs=class{constructor(e,t){this.id=e,this.length=t}get deleted(){throw D()}mergeWith(e){return!1}write(e,t,n){throw D()}integrate(e,t){throw D()}},W=class extends cs{get deleted(){return!0}delete(){}mergeWith(e){return this.constructor===e.constructor&&(this.length+=e.length,!0)}integrate(e,t){t>0&&(this.id.clock+=t,this.length-=t),wa(e.doc.store,this)}write(e,t){e.writeInfo(0),e.writeLen(this.length-t)}getMissing(e,t){return null}},ls=class e{constructor(e){this.content=e}getLength(){return 1}getContent(){return[this.content]}isCountable(){return!0}copy(){return new e(this.content)}splice(e){throw D()}mergeWith(e){return!1}integrate(e,t){}delete(e){}gc(e){}write(e,t){e.writeBuf(this.content)}getRef(){return 3}};const us=e=>new ls(e.readBuf());var ds=class e{constructor(e){this.len=e}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(e){return this.len+=e.len,!0}integrate(e,t){yi(e.deleteSet,t.id.client,t.id.clock,this.len),t.markDeleted()}delete(e){}gc(e){}write(e,t){e.writeLen(this.len-t)}getRef(){return 1}};const fs=e=>new ds(e.readLen()),ps=(e,t)=>new Ei({guid:e,...t,shouldLoad:t.shouldLoad||t.autoLoad||!1});var ms=class e{constructor(e){e._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=e;let t={};this.opts=t,e.gc||(t.gc=!1),e.autoLoad&&(t.autoLoad=!0),e.meta!==null&&(t.meta=e.meta)}getLength(){return 1}getContent(){return[this.doc]}isCountable(){return!0}copy(){return new e(ps(this.doc.guid,this.opts))}splice(e){throw D()}mergeWith(e){return!1}integrate(e,t){this.doc._item=t,e.subdocsAdded.add(this.doc),this.doc.shouldLoad&&e.subdocsLoaded.add(this.doc)}delete(e){e.subdocsAdded.has(this.doc)?e.subdocsAdded.delete(this.doc):e.subdocsRemoved.add(this.doc)}gc(e){}write(e,t){e.writeString(this.doc.guid),e.writeAny(this.opts)}getRef(){return 9}};const hs=e=>new ms(ps(e.readString(),e.readAny()));var gs=class e{constructor(e){this.embed=e}getLength(){return 1}getContent(){return[this.embed]}isCountable(){return!0}copy(){return new e(this.embed)}splice(e){throw D()}mergeWith(e){return!1}integrate(e,t){}delete(e){}gc(e){}write(e,t){e.writeJSON(this.embed)}getRef(){return 5}};const _s=e=>new gs(e.readJSON());var G=class e{constructor(e,t){this.key=e,this.value=t}getLength(){return 1}getContent(){return[]}isCountable(){return!1}copy(){return new e(this.key,this.value)}splice(e){throw D()}mergeWith(e){return!1}integrate(e,t){let n=t.parent;n._searchMarker=null,n._hasFormatting=!0}delete(e){}gc(e){}write(e,t){e.writeKey(this.key),e.writeJSON(this.value)}getRef(){return 6}};const vs=e=>new G(e.readKey(),e.readJSON());var ys=class e{constructor(e){this.arr=e}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(e){return this.arr=this.arr.concat(e.arr),!0}integrate(e,t){}delete(e){}gc(e){}write(e,t){let n=this.arr.length;e.writeLen(n-t);for(let r=t;r<n;r++){let t=this.arr[r];e.writeString(t===void 0?`undefined`:JSON.stringify(t))}}getRef(){return 2}};const bs=e=>{let t=e.readLen(),n=[];for(let r=0;r<t;r++){let t=e.readString();t===`undefined`?n.push(void 0):n.push(JSON.parse(t))}return new ys(n)},xs=wn(`node_env`)===`development`;var Ss=class e{constructor(e){this.arr=e,xs&&mn(e)}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(e){return this.arr=this.arr.concat(e.arr),!0}integrate(e,t){}delete(e){}gc(e){}write(e,t){let n=this.arr.length;e.writeLen(n-t);for(let r=t;r<n;r++){let t=this.arr[r];e.writeAny(t)}}getRef(){return 8}};const Cs=e=>{let t=e.readLen(),n=[];for(let r=0;r<t;r++)n.push(e.readAny());return new Ss(n)};var ws=class e{constructor(e){this.str=e}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)+`�`,n.str=`�`+n.str.slice(1)),n}mergeWith(e){return this.str+=e.str,!0}integrate(e,t){}delete(e){}gc(e){}write(e,t){e.writeString(t===0?this.str:this.str.slice(t))}getRef(){return 4}};const Ts=e=>new ws(e.readString()),Es=[No,Fo,$o,rs,ns,os,ss],Ds=0,Os=1,ks=2,As=3,js=4,Ms=5,Ns=6;var Ps=class e{constructor(e){this.type=e}getLength(){return 1}getContent(){return[this.type]}isCountable(){return!0}copy(){return new e(this.type._copy())}splice(e){throw D()}mergeWith(e){return!1}integrate(e,t){this.type._integrate(e.doc,t)}delete(e){let t=this.type._start;for(;t!==null;)t.deleted?t.id.clock<(e.beforeState.get(t.id.client)||0)&&e._mergeStructs.push(t):t.delete(e),t=t.right;this.type._map.forEach(t=>{t.deleted?t.id.clock<(e.beforeState.get(t.id.client)||0)&&e._mergeStructs.push(t):t.delete(e)}),e.changed.delete(this.type)}gc(e){let t=this.type._start;for(;t!==null;)t.gc(e,!0),t=t.right;this.type._start=null,this.type._map.forEach(t=>{for(;t!==null;)t.gc(e,!0),t=t.left}),this.type._map=new Map}write(e,t){this.type._write(e)}getRef(){return 7}};const Fs=e=>new Ps(Es[e.readTypeRef()](e)),Is=(e,t)=>{let n=t,r=0,i;do r>0&&(n=F(n.client,n.clock+r)),i=Ea(e,n),r=n.clock-i.id.clock,n=i.redone;while(n!==null&&i instanceof K);return{item:i,diff:r}},Ls=(e,t)=>{for(;e!==null&&e.keep!==t;)e.keep=t,e=e.parent._item},Rs=(e,t,n)=>{let{client:r,clock:i}=t.id,a=new K(F(r,i+n),t,F(r,i+n-1),t.right,t.rightOrigin,t.parent,t.parentSub,t.content.splice(n));return t.deleted&&a.markDeleted(),t.keep&&(a.keep=!0),t.redone!==null&&(a.redone=F(t.redone.client,t.redone.clock+n)),t.right=a,a.right!==null&&(a.right.left=a),e._mergeStructs.push(a),a.parentSub!==null&&a.right===null&&a.parent._map.set(a.parentSub,a),t.length=n,a},zs=(e,t)=>ze(e,e=>gi(e.deletions,t)),Bs=(e,t,n,r,i,a)=>{let o=e.doc,s=o.store,c=o.clientID,l=t.redone;if(l!==null)return L(e,l);let u=t.parent._item,d=null,f;if(u!==null&&u.deleted===!0){if(u.redone===null&&(!n.has(u)||Bs(e,u,n,r,i,a)===null))return null;for(;u.redone!==null;)u=L(e,u.redone)}let p=u===null?t.parent:u.content.type;if(t.parentSub===null){for(d=t.left,f=t;d!==null;){let t=d;for(;t!==null&&t.parent._item!==u;)t=t.redone===null?null:L(e,t.redone);if(t!==null&&t.parent._item===u){d=t;break}d=d.left}for(;f!==null;){let t=f;for(;t!==null&&t.parent._item!==u;)t=t.redone===null?null:L(e,t.redone);if(t!==null&&t.parent._item===u){f=t;break}f=f.right}}else{if(f=null,t.right&&!i){for(d=t;d!==null&&d.right!==null&&(d.right.redone||gi(r,d.right.id)||zs(a.undoStack,d.right.id)||zs(a.redoStack,d.right.id));)for(d=d.right;d.redone;)d=L(e,d.redone);if(d&&d.right!==null)return null}else d=p._map.get(t.parentSub)||null;d!==null&&d.parent._item!==u&&(d=p._map.get(t.parentSub)||null)}let m=I(s,c),h=F(c,m),g=new K(h,d,d&&d.lastId,f,f&&f.id,p,t.parentSub,t.content.copy());return t.redone=h,Ls(g,!0),g.integrate(e,0),g};var K=class e extends cs{constructor(e,t,n,r,i,a,o,s){super(e,s.getLength()),this.origin=n,this.left=t,this.right=r,this.rightOrigin=i,this.parent=a,this.parentSub=o,this.redone=null,this.content=s,this.info=this.content.isCountable()?2:0}set marker(e){(this.info&8)>0!==e&&(this.info^=8)}get marker(){return(this.info&8)>0}get keep(){return(this.info&1)>0}set keep(e){this.keep!==e&&(this.info^=1)}get countable(){return(this.info&2)>0}get deleted(){return(this.info&4)>0}set deleted(e){this.deleted!==e&&(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===ra&&this.id.client!==this.parent.client&&this.parent.clock>=I(n,this.parent.client))return this.parent.client;if(this.origin&&=(this.left=Oa(t,n,this.origin),this.left.lastId),this.rightOrigin&&=(this.right=L(t,this.rightOrigin),this.right.id),this.left&&this.left.constructor===W||this.right&&this.right.constructor===W)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===ra){let e=Ea(n,this.parent);this.parent=e.constructor===W?null:e.content.type}return null}integrate(e,t){if(t>0&&(this.id.clock+=t,this.left=Oa(e,e.doc.store,F(this.id.client,this.id.clock-1)),this.origin=this.left.lastId,this.content=this.content.splice(t),this.length-=t),this.parent){if(!this.left&&(!this.right||this.right.left!==null)||this.left&&this.left.right!==this.right){let t=this.left,n;if(t!==null)n=t.right;else if(this.parentSub!==null)for(n=this.parent._map.get(this.parentSub)||null;n!==null&&n.left!==null;)n=n.left;else n=this.parent._start;let r=new Set,i=new Set;for(;n!==null&&n!==this.right;){if(i.add(n),r.add(n),ia(this.origin,n.origin)){if(n.id.client<this.id.client)t=n,r.clear();else if(ia(this.rightOrigin,n.rightOrigin))break}else if(n.origin!==null&&i.has(Ea(e.doc.store,n.origin)))r.has(Ea(e.doc.store,n.origin))||(t=n,r.clear());else break;n=n.right}this.left=t}if(this.left!==null){let e=this.left.right;this.right=e,this.left.right=this}else{let e;if(this.parentSub!==null)for(e=this.parent._map.get(this.parentSub)||null;e!==null&&e.left!==null;)e=e.left;else e=this.parent._start,this.parent._start=this;this.right=e}this.right===null?this.parentSub!==null&&(this.parent._map.set(this.parentSub,this),this.left!==null&&this.left.delete(e)):this.right.left=this,this.parentSub===null&&this.countable&&!this.deleted&&(this.parent._length+=this.length),wa(e.doc.store,this),this.content.integrate(e,this),Na(e,this.parent,this.parentSub),(this.parent._item!==null&&this.parent._item.deleted||this.parentSub!==null&&this.right!==null)&&this.delete(e)}else new W(this.id,this.length).integrate(e,0)}get next(){let e=this.right;for(;e!==null&&e.deleted;)e=e.right;return e}get prev(){let e=this.left;for(;e!==null&&e.deleted;)e=e.left;return e}get lastId(){return this.length===1?this.id:F(this.id.client,this.id.clock+this.length-1)}mergeWith(e){if(this.constructor===e.constructor&&ia(e.origin,this.lastId)&&this.right===e&&ia(this.rightOrigin,e.rightOrigin)&&this.id.client===e.id.client&&this.id.clock+this.length===e.id.clock&&this.deleted===e.deleted&&this.redone===null&&e.redone===null&&this.content.constructor===e.content.constructor&&this.content.mergeWith(e.content)){let t=this.parent._searchMarker;return t&&t.forEach(t=>{t.p===e&&(t.p=this,!this.deleted&&this.countable&&(t.index-=this.length))}),e.keep&&(this.keep=!0),this.right=e.right,this.right!==null&&(this.right.left=this),this.length+=e.length,!0}return!1}delete(e){if(!this.deleted){let t=this.parent;this.countable&&this.parentSub===null&&(t._length-=this.length),this.markDeleted(),yi(e.deleteSet,this.id.client,this.id.clock,this.length),Na(e,t,this.parentSub),this.content.delete(e)}}gc(e,t){if(!this.deleted)throw O();this.content.gc(e),t?ka(e,this,new W(this.id,this.length)):this.content=new ds(this.length)}write(e,t){let n=t>0?F(this.id.client,this.id.clock+t-1):this.origin,r=this.rightOrigin,i=this.parentSub,a=this.content.getRef()&31|(n===null?0:128)|(r===null?0:64)|(i===null?0:32);if(e.writeInfo(a),n!==null&&e.writeLeftID(n),r!==null&&e.writeRightID(r),n===null&&r===null){let t=this.parent;if(t._item!==void 0){let n=t._item;if(n===null){let n=aa(t);e.writeParentInfo(!0),e.writeString(n)}else e.writeParentInfo(!1),e.writeLeftID(n.id)}else t.constructor===String?(e.writeParentInfo(!0),e.writeString(t)):t.constructor===ra?(e.writeParentInfo(!1),e.writeLeftID(t)):O();i!==null&&e.writeString(i)}this.content.write(e,t)}};const Vs=(e,t)=>Hs[t&31](e),Hs=[()=>{O()},fs,bs,us,Ts,_s,vs,Fs,Cs,hs,()=>{O()}];var q=class extends cs{get deleted(){return!0}delete(){}mergeWith(e){return this.constructor===e.constructor&&(this.length+=e.length,!0)}integrate(e,t){O()}write(e,t){e.writeInfo(10),T(e.restEncoder,this.length-t)}getMissing(e,t){return null}};const Us=typeof globalThis<`u`?globalThis:typeof window<`u`?window:typeof global<`u`?global:{},Ws=`__ $YJS$ __`;Us[Ws]===!0&&console.error(`Yjs was already imported. This breaks constructor checks and will lead to issues! - https://github.com/yjs/yjs/issues/438`),Us[Ws]=!0;var Gs=ke({$addNodeStyle:()=>ic,$cloneWithProperties:()=>r,$copyBlockFormatIndent:()=>lc,$ensureForwardRangeSelection:()=>cc,$forEachSelectedTextNode:()=>sc,$getComputedStyleForElement:()=>Qs,$getComputedStyleForParent:()=>$s,$getSelectionStyleValueForProperty:()=>Sc,$isAtNodeEnd:()=>nc,$isParentElementRTL:()=>yc,$isParentRTL:()=>ec,$moveCaretSelection:()=>vc,$moveCharacter:()=>bc,$patchStyleText:()=>oc,$selectAll:()=>fe,$setBlocksType:()=>uc,$shouldOverrideDefaultCharacterSelection:()=>_c,$sliceSelectedTextNodeContent:()=>tc,$trimTextContentFromAnchor:()=>rc,$wrapNodes:()=>pc,createDOMRange:()=>Ys,createRectsFromDOMRange:()=>Xs,getCSSFromStyleObject:()=>Zs,getStyleObjectFromCSS:()=>Cc,trimTextContentFromAnchor:()=>wc});function Ks(e,...t){let n=new URL(`https://lexical.dev/docs/error`),r=new URLSearchParams;r.append(`code`,e);for(let e of t)r.append(`v`,e);throw n.search=r.toString(),Error(`Minified Lexical error #${e}; visit ${n.toString()} for the full message or use the non-minified dev environment for full errors and additional helpful warnings.`)}function qs(e){let t=e;for(;t!=null;){if(t.nodeType===Node.TEXT_NODE)return t;t=t.firstChild}return null}function Js(e){let t=e.parentNode;if(t==null)throw Error(`Should never happen`);return[t,Array.from(t.childNodes).indexOf(e)]}function Ys(e,t,n,r,i){let a=t.getKey(),o=r.getKey(),s=document.createRange(),c=e.getElementByKey(a),l=e.getElementByKey(o),u=n,d=i;if(b(t)&&(c=qs(c)),b(r)&&(l=qs(l)),t===void 0||r===void 0||c===null||l===null)return null;c.nodeName===`BR`&&([c,u]=Js(c)),l.nodeName===`BR`&&([l,d]=Js(l));let f=c.firstChild;c===l&&f!=null&&f.nodeName===`BR`&&u===0&&d===0&&(d=1);try{s.setStart(c,u),s.setEnd(l,d)}catch{return null}return!s.collapsed||u===d&&a===o||(s.setStart(l,d),s.setEnd(c,u)),s}function Xs(e,t){let n=e.getRootElement();if(n===null)return[];let r=n.getBoundingClientRect(),i=getComputedStyle(n),a=parseFloat(i.paddingLeft)+parseFloat(i.paddingRight),o=Array.from(t.getClientRects()),s,c=o.length;o.sort((e,t)=>{let n=e.top-t.top;return Math.abs(n)<=3?e.left-t.left:n});for(let e=0;e<c;e++){let t=o[e],n=s&&s.top<=t.top&&s.top+s.height>t.top&&s.left+s.width>t.left,i=t.width+a===r.width;n||i?(o.splice(e--,1),c--):s=t}return o}function Zs(e){let t=``;for(let n in e)n&&(t+=`${n}: ${e[n]};`);return t}function Qs(e){let t=f().getElementByKey(e.getKey());if(t===null)return null;let n=t.ownerDocument.defaultView;return n===null?null:n.getComputedStyle(t)}function $s(e){return Qs(ce(e)?e:e.getParentOrThrow())}function ec(e){let t=$s(e);return t!==null&&t.direction===`rtl`}function tc(e,t,n=`self`){let r=e.getStartEndPoints();if(t.isSelected(e)&&!ue(t)&&r!==null){let[a,o]=r,s=e.isBackward(),c=a.getNode(),l=o.getNode(),u=t.is(c),f=t.is(l);if(u||f){let[r,a]=d(e),o=c.is(l),u=t.is(s?l:c),f=t.is(s?c:l),p,m=0;o?(m=r>a?a:r,p=r>a?r:a):u?(m=s?a:r,p=void 0):f&&(m=0,p=s?r:a);let h=t.__text.slice(m,p);h!==t.__text&&(n===`clone`&&(t=i(t)),t.__text=h)}}return t}function nc(e){if(e.type===`text`)return e.offset===e.getNode().getTextContentSize();let t=e.getNode();return v(t)||Ks(177),e.offset===t.getChildrenSize()}function rc(e,t,n){let r=t.getNode(),i=n;if(v(r)){let e=r.getDescendantByIndex(t.offset);e!==null&&(r=e)}for(;i>0&&r!==null;){if(v(r)){let e=r.getLastDescendant();e!==null&&(r=e)}let n=r.getPreviousSibling(),a=0;if(n===null){let e=r.getParentOrThrow(),t=e.getPreviousSibling();for(;t===null;){if(e=e.getParent(),e===null){n=null;break}t=e.getPreviousSibling()}e!==null&&(a=e.isInline()?0:2,n=t)}let o=r.getTextContent();o===``&&v(r)&&!r.isInline()&&(o=`
|
|
5
|
+
|
|
6
|
+
`);let s=o.length;if(!b(r)||i>=s){let e=r.getParent();r.remove(),e==null||e.getChildrenSize()!==0||ce(e)||e.remove(),i-=s+a,r=n}else{let n=r.getKey(),a=e.getEditorState().read(()=>{let e=p(n);return b(e)&&e.isSimpleText()?e.getTextContent():null}),l=s-i,u=o.slice(0,l);if(a!==null&&a!==o){let e=h(),t=r;if(r.isSimpleText())r.setTextContent(a);else{let e=c(a);r.replace(e),t=e}if(y(e)&&e.isCollapsed()){let n=e.anchor.offset;t.select(n,n)}}else if(r.isSimpleText()){let e=t.key===n,a=t.offset;a<i&&(a=s);let o=e?a-i:0,c=e?a:l;if(e&&o===0){let[e]=r.splitText(o,c);e.remove()}else{let[,e]=r.splitText(o,c);e.remove()}}else{let e=c(u);r.replace(e)}i=0}}}const ic=()=>{};function ac(e,t){(y(e)?e.isCollapsed():b(e)||v(e))||Ks(280);let n=Te(y(e)?e.style:b(e)?e.getStyle():e.getTextStyle()),r=Zs(Object.entries(t).reduce((t,[r,i])=>(typeof i==`function`?t[r]=i(n[r],e):i===null?delete t[r]:t[r]=i,t),{...n}));y(e)||b(e)?e.setStyle(r):e.setTextStyle(r)}function oc(e,t){if(y(e)&&e.isCollapsed()){ac(e,t);let n=e.anchor.getNode();v(n)&&n.isEmpty()&&ac(n,t)}sc(e=>{ac(e,t)});let n=e.getNodes();if(n.length>0){let e=new Set;for(let r of n){if(!v(r)||!r.canBeEmpty()||r.getChildrenSize()!==0)continue;let n=r.getKey();e.has(n)||(e.add(n),ac(r,t))}}}function sc(e){let t=_();if(!t)return;let r=new Map,i=e=>r.get(e.getKey())||[0,e.getTextContentSize()];if(y(t))for(let e of n(t).getTextSlices())e&&r.set(e.caret.origin.getKey(),e.getSliceIndices());let a=t.getNodes();for(let t of a){if(!b(t)||!t.canHaveFormat())continue;let[n,r]=i(t);r!==n&&(ue(t)||n===0&&r===t.getTextContentSize()?e(t):e(t.splitText(n,r)[n===0?0:1]))}y(t)&&t.anchor.type===`text`&&t.focus.type===`text`&&t.anchor.key===t.focus.key&&cc(t)}function cc(e){if(e.isBackward()){let{anchor:t,focus:n}=e,{key:r,offset:i,type:a}=t;t.set(n.key,n.offset,n.type),n.set(r,i,a)}}function lc(e,t){let n=e.getFormatType(),r=e.getIndent();n!==t.getFormatType()&&t.setFormat(n),r!==t.getIndent()&&t.setIndent(r)}function uc(e,t,n=lc){if(e===null)return;let r=e.getStartEndPoints(),i=new Map,a=null;if(r){let[e,t]=r;a=s(),a.anchor.set(e.key,e.offset,e.type),a.focus.set(t.key,t.offset,t.type);let n=u(e.getNode(),ve),o=u(t.getNode(),ve);v(n)&&i.set(n.getKey(),n),v(o)&&i.set(o.getKey(),o)}for(let t of e.getNodes())if(v(t)&&ve(t))i.set(t.getKey(),t);else if(r===null){let e=u(t,ve);v(e)&&i.set(e.getKey(),e)}for(let[e,r]of i){let i=t();n(r,i),r.replace(i,!0),a&&(e===a.anchor.key&&a.anchor.set(i.getKey(),a.anchor.offset,a.anchor.type),e===a.focus.key&&a.focus.set(i.getKey(),a.focus.offset,a.focus.type))}a&&e.is(_())&&pe(a)}function dc(e){return e.getNode().isAttached()}function fc(e){let t=e;for(;t!==null&&!le(t);){let e=t.getLatest(),n=t.getParent();e.getChildrenSize()===0&&t.remove(!0),t=n}}function pc(e,t,n=null){let r=e.getStartEndPoints(),i=r?r[0]:null,a=e.getNodes(),o=a.length;if(i!==null&&(o===0||o===1&&i.type===`element`&&i.getNode().getChildrenSize()===0)){let e=i.type===`text`?i.getNode().getParentOrThrow():i.getNode(),r=e.getChildren(),a=t();a.setFormat(e.getFormatType()),a.setIndent(e.getIndent()),r.forEach(e=>a.append(e)),n&&(a=n.append(a)),e.replace(a);return}let s=null,c=[];for(let r=0;r<o;r++){let i=a[r];le(i)?(mc(e,c,c.length,t,n),c=[],s=i):s===null||s!==null&&ne(i,s)?c.push(i):(mc(e,c,c.length,t,n),c=[i])}mc(e,c,c.length,t,n)}function mc(e,t,n,r,i=null){if(t.length===0)return;let a=t[0],o=new Map,s=[],c=v(a)?a:a.getParentOrThrow();c.isInline()&&(c=c.getParentOrThrow());let l=!1;for(;c!==null;){let e=c.getPreviousSibling();if(e!==null){c=e,l=!0;break}if(c=c.getParentOrThrow(),le(c))break}let u=new Set;for(let e=0;e<n;e++){let n=t[e];v(n)&&n.getChildrenSize()===0&&u.add(n.getKey())}let d=new Set;for(let e=0;e<n;e++){let n=t[e],i=n.getParent();if(i!==null&&i.isInline()&&(i=i.getParent()),i!==null&&oe(n)&&!d.has(n.getKey())){let e=i.getKey();if(o.get(e)===void 0){let t=r();t.setFormat(i.getFormatType()),t.setIndent(i.getIndent()),s.push(t),o.set(e,t),i.getChildren().forEach(e=>{t.append(e),d.add(e.getKey()),v(e)&&e.getChildrenKeys().forEach(e=>d.add(e))}),fc(i)}}else if(u.has(n.getKey())){v(n)||Ks(179);let e=r();e.setFormat(n.getFormatType()),e.setIndent(n.getIndent()),s.push(e),n.remove(!0)}}if(i!==null)for(let e=0;e<s.length;e++){let t=s[e];i.append(t)}let f=null;if(le(c))if(l)if(i!==null)c.insertAfter(i);else for(let e=s.length-1;e>=0;e--){let t=s[e];c.insertAfter(t)}else{let e=c.getFirstChild();if(v(e)&&(c=e),e===null)if(i)c.append(i);else for(let e=0;e<s.length;e++){let t=s[e];c.append(t),f=t}else if(i!==null)e.insertBefore(i);else for(let t=0;t<s.length;t++){let n=s[t];e.insertBefore(n),f=n}}else if(i)c.insertAfter(i);else for(let e=s.length-1;e>=0;e--){let t=s[e];c.insertAfter(t),f=t}let p=h();y(p)&&dc(p.anchor)&&dc(p.focus)?pe(p.clone()):f===null?e.dirty=!0:f.selectEnd()}function hc(e){let t=gc(e);return t!==null&&t.writingMode===`vertical-rl`}function gc(e){let t=e.anchor.getNode();return v(t)?Qs(t):$s(t)}function _c(e,n){let r=hc(e)?!n:n;yc(e)&&(r=!r);let i=t(e.focus,r?`previous`:`next`);if(ae(i))return!1;for(let e of l(i)){if(re(e))return!e.origin.isInline();if(!v(e.origin)){if(ie(e.origin))return!0;break}}return!1}function vc(e,t,n,r){e.modify(t?`extend`:`move`,n,r)}function yc(e){let t=gc(e);return t!==null&&t.direction===`rtl`}function bc(e,t,n){let r=yc(e),i;i=hc(e)||r?!n:n,vc(e,t,i,`character`)}function xc(e,t,n){let r=e.getStyle(),i=Te(r);return i!==null&&i[t]||n}function Sc(e,t,n=``){let r=null,i=e.getNodes(),a=e.anchor,o=e.focus,s=e.isBackward(),c=s?o.getNode():a.getNode(),l=s?a.getNode():o.getNode(),u=s?o.offset:a.offset,d=s?a.offset:o.offset;if(y(e)&&e.isCollapsed()&&e.style!==``){let n=e.style,r=Te(n);if(r!==null&&t in r)return r[t]}for(let e=0;e<i.length;e++){let a=i[e];if((e!==0||!a.is(c)||!b(a)||u!==a.getTextContentSize())&&(e===0||!a.is(l)||d!==0)&&b(a)){let e=xc(a,t,n);if(r===null)r=e;else if(r!==e){r=``;break}}}return r===null?n:r}const Cc=Te,wc=rc,J=Gs;J.$addNodeStyle,J.$cloneWithProperties,J.$copyBlockFormatIndent,J.$ensureForwardRangeSelection,J.$forEachSelectedTextNode,J.$getComputedStyleForElement,J.$getComputedStyleForParent,J.$getSelectionStyleValueForProperty,J.$isAtNodeEnd,J.$isParentElementRTL,J.$isParentRTL,J.$moveCaretSelection,J.$moveCharacter,J.$patchStyleText,J.$selectAll,J.$setBlocksType,J.$shouldOverrideDefaultCharacterSelection,J.$sliceSelectedTextNodeContent,J.$trimTextContentFromAnchor,J.$wrapNodes;const Tc=J.createDOMRange,Ec=J.createRectsFromDOMRange;J.getCSSFromStyleObject,J.getStyleObjectFromCSS,J.trimTextContentFromAnchor;var Dc=ke({$getYChangeState:()=>Al,CLEAR_DIFF_VERSIONS_COMMAND__EXPERIMENTAL:()=>cu,CONNECTED_COMMAND:()=>au,DIFF_VERSIONS_COMMAND__EXPERIMENTAL:()=>su,TOGGLE_CONNECT_COMMAND:()=>ou,createBinding:()=>Rc,createBindingV2__EXPERIMENTAL:()=>zc,createUndoManager:()=>lu,getAnchorAndFocusCollabNodesForUserState:()=>Vl,initLocalState:()=>uu,renderSnapshot__EXPERIMENTAL:()=>jl,setLocalStateFocus:()=>du,syncCursorPositions:()=>Jl,syncLexicalUpdateToYjs:()=>eu,syncLexicalUpdateToYjsV2__EXPERIMENTAL:()=>iu,syncYjsChangesToLexical:()=>Zl,syncYjsChangesToLexicalV2__EXPERIMENTAL:()=>nu,syncYjsStateToLexicalV2__EXPERIMENTAL:()=>ru});function Y(e,...t){let n=new URL(`https://lexical.dev/docs/error`),r=new URLSearchParams;r.append(`code`,e);for(let e of t)r.append(`v`,e);throw n.search=r.toString(),Error(`Minified Lexical error #${e}; visit ${n.toString()} for the full message or use the non-minified dev environment for full errors and additional helpful warnings.`)}function Oc(e,t,n){let r=e.length,i=t.length,a=0,o=0;for(;a<r&&a<i&&e[a]===t[a]&&a<n;)a++;for(;o+a<r&&o+a<i&&e[r-o-1]===t[i-o-1];)o++;for(;o+a<r&&o+a<i&&e[a]===t[a];)a++;return{index:a,insert:t.slice(a,i-o),remove:r-a-o}}var kc=class{_xmlElem;_key;_parent;_type;constructor(e,t,n){this._key=``,this._xmlElem=e,this._parent=t,this._type=n}getPrevNode(e){if(e===null)return null;let t=e.get(this._key);return ie(t)?t:null}getNode(){let e=p(this._key);return ie(e)?e:null}getSharedType(){return this._xmlElem}getType(){return this._type}getKey(){return this._key}getSize(){return 1}getOffset(){return this._parent.getChildOffset(this)}syncPropertiesFromLexical(e,t,n){let r=this.getPrevNode(n);tl(e,this._xmlElem,r,t)}syncPropertiesFromYjs(e,t){let n=this.getNode();n===null&&Y(83),Zc(e,this._xmlElem,n,t)}destroy(e){let t=e.collabNodeMap;t.get(this._key)===this&&t.delete(this._key)}};function Ac(e,t,n){let r=new kc(e,t,n);return e._collabNode=r,r}var jc=class{_map;_key;_parent;_type;constructor(e,t){this._key=``,this._map=e,this._parent=t,this._type=`linebreak`}getNode(){let e=p(this._key);return se(e)?e:null}getKey(){return this._key}getSharedType(){return this._map}getType(){return this._type}getSize(){return 1}getOffset(){return this._parent.getChildOffset(this)}destroy(e){let t=e.collabNodeMap;t.get(this._key)===this&&t.delete(this._key)}};function Mc(e,t){let n=new jc(e,t);return e._collabNode=n,n}var X=class{_map;_key;_parent;_text;_type;_normalized;constructor(e,t,n,r){this._key=``,this._map=e,this._parent=n,this._text=t,this._type=r,this._normalized=!1}getPrevNode(e){if(e===null)return null;let t=e.get(this._key);return b(t)?t:null}getNode(){let e=p(this._key);return b(e)?e:null}getSharedType(){return this._map}getType(){return this._type}getKey(){return this._key}getSize(){return this._text.length+ +!this._normalized}getOffset(){return this._parent.getChildOffset(this)}spliceText(e,t,n){let r=this._parent._xmlText,i=this.getOffset()+1+e;t!==0&&r.delete(i,t),n!==``&&r.insert(i,n)}syncPropertiesAndTextFromLexical(e,t,n){let r=this.getPrevNode(n),i=t.__text;if(tl(e,this._map,r,t),r!==null){let e=r.__text;e!==i&&((function(e,t,n,r){let i=_(),a=r.length;if(y(i)&&i.isCollapsed()){let e=i.anchor;e.key===t&&(a=e.offset)}let o=Oc(n,r,a);e.spliceText(o.index,o.remove,o.insert)})(this,t.__key,e,i),this._text=i)}}syncPropertiesAndTextFromYjs(e,t){let n=this.getNode();n===null&&Y(84),Zc(e,this._map,n,t);let r=this._text;n.__text!==r&&n.setTextContent(r)}destroy(e){let t=e.collabNodeMap;t.get(this._key)===this&&t.delete(this._key)}};function Nc(e,t,n,r){let i=new X(e,t,n,r);return e._collabNode=i,i}var Pc=class e{_key;_children;_xmlText;_type;_parent;constructor(e,t,n){this._key=``,this._children=[],this._xmlText=e,this._type=n,this._parent=t}getPrevNode(e){if(e===null)return null;let t=e.get(this._key);return v(t)?t:null}getNode(){let e=p(this._key);return v(e)?e:null}getSharedType(){return this._xmlText}getType(){return this._type}getKey(){return this._key}isEmpty(){return this._children.length===0}getSize(){return 1}getOffset(){let e=this._parent;return e===null&&Y(90),e.getChildOffset(this)}syncPropertiesFromYjs(e,t){let n=this.getNode();n===null&&Y(91),Zc(e,this._xmlText,n,t)}applyChildrenYjsDelta(t,n){let r=this._children,i=0,a=null;for(let o=0;o<n.length;o++){let s=n[o],c=s.insert,l=s.delete;if(s.retain!=null)i+=s.retain;else if(typeof l==`number`){let t=l;for(;t>0;){let{node:n,nodeIndex:a,offset:o,length:s}=rl(this,i,!1);if(n instanceof e||n instanceof jc||n instanceof kc)r.splice(a,1),--t;else{if(!(n instanceof X))break;{let e=Math.min(t,s),i=a===0?null:r[a-1],c=n.getSize();if(o===0&&s===c){r.splice(a,1);let t=nl(n._text,o,e-1,``);t.length>0&&(i instanceof X?i._text+=t:this._xmlText.delete(o,t.length))}else n._text=nl(n._text,o,e,``);t-=e}}}}else{if(c==null)throw Error(`Unexpected delta format`);if(typeof c==`string`){let{node:e,offset:t}=rl(this,i,!0);e instanceof X?e._text=nl(e._text,t,0,c):this._xmlText.delete(t,c.length),i+=c.length}else{let e=c,{node:n,nodeIndex:o,length:s}=rl(this,i,!1),l=Yc(t,e,this);if(n instanceof X&&s>0&&s<n._text.length){let e=n._text,t=e.length-s;n._text=nl(e,t,s,``),r.splice(o+1,0,l),a=nl(e,0,t,``)}else r.splice(o,0,l);a!==null&&l instanceof X&&(l._text=a+l._text,a=null),i+=1}}}}syncChildrenFromYjs(t){let n=this.getNode();n===null&&Y(92);let r=n.__key,i=a(n,null),o=i.length,s=this._children,c=s.length,l=t.collabNodeMap,u=new Set,d,f,p=0,h=null;c!==o&&(f=n.getWritable());for(let a=0;a<c;a++){let o=i[p],g=s[a],_=g.getNode(),ee=g._key;if(_!==null&&o===ee){let n=b(_);if(u.add(o),n)if(g._key=o,g instanceof e){let e=g._xmlText;g.syncPropertiesFromYjs(t,null),g.applyChildrenYjsDelta(t,e.toDelta()),g.syncChildrenFromYjs(t)}else g instanceof X?g.syncPropertiesAndTextFromYjs(t,null):g instanceof kc?g.syncPropertiesFromYjs(t,null):g instanceof jc||Y(93);h=_,p++}else{if(d===void 0){d=new Set;for(let e=0;e<c;e++){let t=s[e]._key;t!==``&&d.add(t)}}if(_!==null&&o!==void 0&&!d.has(o)){let e=m(o);Ee(e),a--,p++;continue}f=n.getWritable();let e=Xc(t,g,r),i=e.__key;if(l.set(i,g),h===null){let t=f.getFirstChild();if(f.__first=i,t!==null){let n=t.getWritable();n.__prev=i,e.__next=n.__key}}else{let t=h.getWritable(),n=h.getNextSibling();if(t.__next=i,e.__prev=h.__key,n!==null){let t=n.getWritable();t.__prev=i,e.__next=t.__key}}a===c-1&&(f.__last=i),f.__size++,h=e}}for(let e=0;e<o;e++){let n=i[e];if(!u.has(n)){let e=m(n),r=t.collabNodeMap.get(n);r!==void 0&&r.destroy(t),Ee(e)}}}syncPropertiesFromLexical(e,t,n){tl(e,this._xmlText,this.getPrevNode(n),t)}_syncChildFromLexical(t,n,r,i,a,o){let s=this._children[n],c=m(r);s instanceof e&&v(c)?(s.syncPropertiesFromLexical(t,c,i),s.syncChildrenFromLexical(t,c,i,a,o)):s instanceof X&&b(c)?s.syncPropertiesAndTextFromLexical(t,c,i):s instanceof kc&&ie(c)&&s.syncPropertiesFromLexical(t,c,i)}syncChildrenFromLexical(e,t,n,r,i){let o=this.getPrevNode(n),s=o===null?[]:a(o,n),c=a(t,null),l=s.length-1,u=c.length-1,d=e.collabNodeMap,f,p,h=0,g=0;for(;h<=l&&g<=u;){let t=s[h],a=c[g];if(t===a)this._syncChildFromLexical(e,g,a,n,r,i),h++,g++;else{f===void 0&&(f=new Set(s)),p===void 0&&(p=new Set(c));let n=p.has(t),r=f.has(a);if(n){let t=qc(e,m(a),this);d.set(a,t),r?(this.splice(e,g,1,t),h++,g++):(this.splice(e,g,0,t),g++)}else this.splice(e,g,1),h++}}let _=h>l,ee=g>u;if(_&&!ee)for(;g<=u;++g){let t=c[g],n=qc(e,m(t),this);this.append(n),d.set(t,n)}else if(ee&&!_)for(let t=this._children.length-1;t>=g;t--)this.splice(e,t,1)}append(t){let n=this._xmlText,r=this._children,i=r[r.length-1],a=i===void 0?0:i.getOffset()+i.getSize();if(t instanceof e)n.insertEmbed(a,t._xmlText);else if(t instanceof X){let e=t._map;e.parent===null&&n.insertEmbed(a,e),n.insert(a+1,t._text)}else t instanceof jc?n.insertEmbed(a,t._map):t instanceof kc&&n.insertEmbed(a,t._xmlElem);this._children.push(t)}splice(t,n,r,i){let a=this._children,o=a[n];if(o===void 0)return i===void 0&&Y(94),void this.append(i);let s=o.getOffset();s===-1&&Y(95);let c=this._xmlText;if(r!==0&&c.delete(s,o.getSize()),i instanceof e)c.insertEmbed(s,i._xmlText);else if(i instanceof X){let e=i._map;e.parent===null&&c.insertEmbed(s,e),c.insert(s+1,i._text)}else i instanceof jc?c.insertEmbed(s,i._map):i instanceof kc&&c.insertEmbed(s,i._xmlElem);if(r!==0){let e=a.slice(n,n+r);for(let n=0;n<e.length;n++)e[n].destroy(t)}i===void 0?a.splice(n,r):a.splice(n,r,i)}getChildOffset(e){let t=0,n=this._children;for(let r=0;r<n.length;r++){let i=n[r];if(i===e)return t;t+=i.getSize()}return-1}destroy(e){let t=e.collabNodeMap,n=this._children;for(let t=0;t<n.length;t++)n[t].destroy(e);t.get(this._key)===this&&t.delete(this._key)}};function Fc(e,t,n){let r=new Pc(e,t,n);return e._collabNode=r,r}var Ic=class{_nodeMap=new Map;_sharedTypeToNodeKeys=new Map;_nodeKeyToSharedType=new Map;set(e,t){let n=t instanceof Array;this.delete(e);let r=n?t:[t];for(let e of r){let t=e.getKey();if(this._nodeKeyToSharedType.has(t)){let e=this._nodeKeyToSharedType.get(t),n=this._sharedTypeToNodeKeys.get(e).indexOf(t);n!==-1&&this._sharedTypeToNodeKeys.get(e).splice(n,1),this._nodeKeyToSharedType.delete(t),this._nodeMap.delete(t)}}if(e instanceof U){if(n||Y(331),t.length===0)return;this._sharedTypeToNodeKeys.set(e,t.map(e=>e.getKey()));for(let n of t)this._nodeMap.set(n.getKey(),n),this._nodeKeyToSharedType.set(n.getKey(),e)}else n&&Y(332),b(t)&&Y(333),this._sharedTypeToNodeKeys.set(e,[t.getKey()]),this._nodeMap.set(t.getKey(),t),this._nodeKeyToSharedType.set(t.getKey(),e)}get(e){let t=this._sharedTypeToNodeKeys.get(e);if(t!==void 0){if(e instanceof U){let e=Array.from(t.map(e=>this._nodeMap.get(e)));return e.length>0?e:void 0}return this._nodeMap.get(t[0])}}getSharedType(e){return this._nodeKeyToSharedType.get(e.getKey())}delete(e){let t=this._sharedTypeToNodeKeys.get(e);if(t!==void 0){for(let e of t)this._nodeMap.delete(e),this._nodeKeyToSharedType.delete(e);this._sharedTypeToNodeKeys.delete(e)}}deleteNode(e){let t=this._nodeKeyToSharedType.get(e);t&&this.delete(t),this._nodeMap.delete(e)}has(e){return this._sharedTypeToNodeKeys.has(e)}clear(){this._nodeMap.clear(),this._sharedTypeToNodeKeys.clear(),this._nodeKeyToSharedType.clear()}};function Lc(e,t,n,r,i){n??Y(81);let a={clientID:n.clientID,cursors:new Map,cursorsContainer:null,doc:n,docMap:r,editor:e,excludedProperties:i||new Map,id:t,nodeProperties:new Map};return function(e){let{editor:t,nodeProperties:n}=e;t.update(()=>{t._nodes.forEach(t=>{let r=new t.klass,i={};for(let[t,n]of Object.entries(r))Gc(t,r,e)||(i[t]=n);n.set(r.__type,Object.freeze(i))})})}(a),a}function Rc(e,t,n,r,i,a){r??Y(81);let o=Fc(r.get(`root`,U),null,`root`);return o._key=`root`,{...Lc(e,n,r,i,a),collabNodeMap:new Map,root:o}}function zc(e,t,n,r,i={}){n??Y(81);let{excludedProperties:a,rootName:o=`root-v2`}=i;return{...Lc(e,t,n,r,a),mapping:new Ic,root:n.get(o,H)}}function Bc(e){return Object.hasOwn(e,`collabNodeMap`)}const Vc=new Set([`__key`,`__parent`,`__next`,`__prev`,`__state`]),Hc=new Set([`__first`,`__last`,`__size`]),Uc=new Set([`__cachedText`]),Wc=new Set([`__text`]);function Gc(e,t,n){if(Vc.has(e)||typeof t[e]==`function`)return!0;if(b(t)){if(Wc.has(e))return!0}else if(v(t)&&(Hc.has(e)||ce(t)&&Uc.has(e)))return!0;let r=t.constructor,i=n.excludedProperties.get(r);return i!=null&&i.has(e)}function Kc(e,t){let n=e.__type,{nodeProperties:r}=t,i=r.get(n);return i===void 0&&Y(330,n),i}function qc(e,t,n){let r=t.__type,i;if(v(t))i=Fc(new U,n,r),i.syncPropertiesFromLexical(e,t,null),i.syncChildrenFromLexical(e,t,null,null,null);else if(b(t))i=Nc(new V,t.__text,n,r),i.syncPropertiesAndTextFromLexical(e,t,null);else if(se(t)){let e=new V;e.set(`__type`,`linebreak`),i=Mc(e,n)}else ie(t)?(i=Ac(new H,n,r),i.syncPropertiesFromLexical(e,t,null)):Y(86);return i._key=t.__key,i}function Jc(e){let t=Qc(e,`__type`);return typeof t!=`string`&&t!==void 0&&Y(87),t}function Yc(e,t,n){let r=t._collabNode;if(r===void 0){let r=e.editor._nodes,i=Jc(t);typeof i!=`string`&&Y(87),r.get(i)===void 0&&Y(88,i);let a=t.parent,o=n===void 0&&a!==null?Yc(e,a):n||null;if(o instanceof Pc||Y(89),t instanceof U)return Fc(t,o,i);if(t instanceof V)return i===`linebreak`?Mc(t,o):Nc(t,``,o,i);if(t instanceof H)return Ac(t,o,i)}return r}function Xc(e,t,n){let r=t.getType(),i=e.editor._nodes.get(r);i===void 0&&Y(88,r);let a=new i.klass;if(a.__parent=n,t._key=a.__key,t instanceof Pc){let n=t._xmlText;t.syncPropertiesFromYjs(e,null),t.applyChildrenYjsDelta(e,n.toDelta()),t.syncChildrenFromYjs(e)}else t instanceof X?t.syncPropertiesAndTextFromYjs(e,null):t instanceof kc&&t.syncPropertiesFromYjs(e,null);return e.collabNodeMap.set(a.__key,t),a}function Zc(e,t,n,r){let i=r===null?t instanceof V?Array.from(t.keys()):t instanceof U||t instanceof H?Object.keys(t.getAttributes()):Object.keys(t):Array.from(r),a;for(let r=0;r<i.length;r++){let o=i[r];if(Gc(o,n,e)){o===`__state`&&Bc(e)&&(a||=n.getWritable(),el(t,a));continue}let s=n[o],c=Qc(t,o);if(s!==c){if(c instanceof Ei){let t=e.docMap;s instanceof Ei&&t.delete(s.guid);let n=Ce(),r=c.guid;n._key=r,t.set(r,c),c=n}a===void 0&&(a=n.getWritable()),a[o]=c}}}function Qc(e,t){return e instanceof V?e.get(t):e instanceof U||e instanceof H?e.getAttribute(t):e[t]}function $c(e,t,n){e instanceof V?e.set(t,n):e.setAttribute(t,n)}function el(e,t){let n=Qc(e,`__state`);n instanceof V&&te(t).updateFromJSON(n.toJSON())}function tl(e,t,n,r){let i=Object.keys(Kc(r,e)),a=e.editor.constructor;(function(e,t,n,r){let i=r.__state,a=t.doc===null?void 0:Qc(t,`__state`);if(!i)return;let[o,s]=i.getInternalState(),c=n&&n.__state,l=a instanceof V?a:new V;if(c===i)return;let[u,d]=c&&l.doc?c.getInternalState():[void 0,new Map];if(o)for(let[e,t]of Object.entries(o))u&&t!==u[e]&&l.set(e,t);for(let[e,t]of s)d.get(e)!==t&&l.set(e.key,e.unparse(t));a||$c(t,`__state`,l)})(0,t,n,r);for(let o=0;o<i.length;o++){let s=i[o],c=n===null?void 0:n[s],l=r[s];if(c!==l){if(l instanceof a){let t=e.docMap,n;if(c instanceof a){let e=c._key;n=t.get(e),t.delete(e)}let i=n||new Ei,o=i.guid;l._key=o,t.set(o,i),l=i,e.editor.update(()=>{r.markDirty()})}$c(t,s,l)}}}function nl(e,t,n,r){return e.slice(0,t)+r+e.slice(t+n)}function rl(e,t,n){let r=0,i=0,a=e._children,o=a.length;for(;i<o;i++){let e=a[i],s=r;if(r+=e.getSize(),(n?r>=t:r>t)&&e instanceof X){let n=t-s-1;return n<0&&(n=0),{length:r-t,node:e,nodeIndex:i,offset:n}}if(r>t)return{length:0,node:e,nodeIndex:i,offset:s};if(i===o-1)return{length:0,node:null,nodeIndex:i+1,offset:s+1}}return{length:0,node:null,nodeIndex:0,offset:0}}function il(e){let t=e.anchor,n=e.focus,r=!1;try{let e=t.getNode(),i=n.getNode();(!e.isAttached()||!i.isAttached()||b(e)&&t.offset>e.getTextContentSize()||b(i)&&n.offset>i.getTextContentSize())&&(r=!0)}catch{r=!0}return r}function al(e,t){e.doc.transact(t,e)}function ol(e,t){let n=t._nodeMap.get(e);if(!n)return void g().selectStart();let r=n.__prev,i=null;r&&(i=p(r)),i===null&&n.__parent!==null&&(i=p(n.__parent)),i===null?g().selectStart():i!==null&&i.isAttached()?i.selectEnd():ol(i.__key,t)}const sl=e=>e.nodeName===`UNDEFINED`,cl=(e,t,n,r,i,a,o)=>{let s=t.mapping.get(e);if(s&&n&&n.size===0&&!r)return s;let c=sl(e)?ye.getType():e.nodeName,l=t.editor._nodes.get(c);if(l===void 0)throw Error(`$createOrUpdateNodeFromYElement: Node ${c} is not registered`);if(s||(s=new l.klass,n=null,r=!0),r&&s instanceof he){let n=[],r=e=>{if(e instanceof H){let r=cl(e,t,new Set,!1,i,a,o);r!==null&&n.push(r)}else if(e instanceof U){let r=dl(e,t,i,a,o);r!==null&&r.forEach(e=>{e!==null&&n.push(e)})}else Y(329)};i===void 0||a===void 0?e.toArray().forEach(r):mo(e,new ga(a.ds,i.sv)).filter(e=>!e._item.deleted||ul(e._item,i)||ul(e._item,a)).forEach(r),ll(s,n)}let u=e.getAttributes(i);sl(e)||i===void 0||(ul(e._item,i)?ul(e._item,a)||(u[wl(`ychange`)]=o?o(`added`,e._item.id):{type:`added`}):u[wl(`ychange`)]=o?o(`removed`,e._item.id):{type:`removed`});let d={...Kc(s,t)},f={};for(let e in u)e.startsWith(Cl)?f[Tl(e)]=u[e]:d[e]=u[e];if(Zc(t,d,s,n),n){let e=Object.keys(f).filter(e=>n.has(wl(e)));if(e.length>0){let t=te(s);for(let n of e)t.updateFromUnknown(n,f[n])}}else te(s).updateFromJSON(f);let p=s.getLatest();return t.mapping.set(e,p),p},ll=(e,t)=>{let n=e.getChildren(),r=new Set(n.map(e=>e.getKey())),i=new Set(t.map(e=>e.getKey())),a=n.length-1,o=t.length-1,s=0,c=0;for(;s<=a&&c<=o;){let a=n[s].getKey(),o=t[c].getKey();if(a===o){s++,c++;continue}let l=i.has(a),u=r.has(o);if(!l){if(c===0&&e.getChildrenSize()===1)return void e.splice(c,1,t.slice(c));e.splice(c,1,[]),s++;continue}let d=t[c];u?(e.splice(c,1,[d]),s++,c++):(e.splice(c,0,[d]),c++)}let l=s>a,u=c>o;l&&!u?e.append(...t.slice(c)):u&&!l&&e.splice(t.length,e.getChildrenSize()-t.length,[])},ul=(e,t)=>t===void 0?!e.deleted:t.sv.has(e.id.client)&&t.sv.get(e.id.client)>e.id.clock&&!gi(t.ds,e.id),dl=(e,t,n,r,i)=>{let a=xl(e,n,r,i),o=t.mapping.get(e)??[],s=a.map(e=>e.attributes.t??xe.getType());if(!(o.length===s.length&&o.every((e,t)=>e.getType()===s[t]))){let e=t.editor._nodes;o=s.map(t=>{let n=e.get(t);if(n===void 0)throw Error(`$createTextNodesFromYText: Node ${t} is not registered`);let r=new n.klass;if(!b(r))throw Error(`$createTextNodesFromYText: Node ${t} is not a TextNode`);return r})}for(let e=0;e<a.length;e++){let n=o[e],{attributes:r,insert:i}=a[e];n.__text!==i&&n.setTextContent(i);let s={...Kc(n,t),...r.p},c=Object.fromEntries(Object.entries(r).filter(([e])=>e.startsWith(Cl)).map(([e,t])=>[Tl(e),t]));Zc(t,s,n,null),te(n).updateFromJSON(c)}let c=o.map(e=>e.getLatest());return t.mapping.set(e,c),c},fl=(e,t)=>e instanceof Array?((e,t)=>{let n=new U;return bl(n,e,t),n})(e,t):((e,t)=>{let n=new H(e.getType()),r={...Sl(e,t),...El(e)};for(let e in r){let t=r[e];t!==null&&n.setAttribute(e,t)}return e instanceof he?(n.insert(0,hl(e).map(e=>fl(e,t))),t.mapping.set(n,e),n):n})(e,t),pl=e=>typeof e==`object`&&!!e,ml=(e,t)=>{let n=Object.keys(e).filter(t=>e[t]!==null);if(t==null)return n.length===0;let r=n.length===Object.keys(t).filter(e=>t[e]!==null).length;for(let i=0;i<n.length&&r;i++){let a=n[i],o=e[a],s=t[a];r=a===`ychange`||o===s||pl(o)&&pl(s)&&ml(o,s)}return r},hl=e=>{if(!(e instanceof he))return[];let t=e.getChildren(),n=[];for(let e=0;e<t.length;e++){let r=t[e];if(b(r)){let r=[];for(let n=t[e];e<t.length&&b(n);n=t[++e])r.push(n);e--,n.push(r)}else n.push(r)}return n},gl=(e,t,n)=>{let r=xl(e);return r.length===t.length&&r.every((e,r)=>{let i=t[r],a=e.attributes.t??xe.getType(),o=e.attributes.p??{},s=Object.fromEntries(Object.entries(e.attributes).filter(([e])=>e.startsWith(Cl)));return e.insert===i.getTextContent()&&a===i.getType()&&ml(o,Sl(i,n))&&ml(s,El(i))})},_l=(e,t,n)=>{if(e instanceof H&&!(t instanceof Array)&&Ol(e,t)){let r=hl(t);return e._length===r.length&&ml(e.getAttributes(),{...Sl(t,n),...El(t)})&&e.toArray().every((e,t)=>_l(e,r[t],n))}return e instanceof U&&t instanceof Array&&gl(e,t,n)},vl=(e,t)=>e===t||e instanceof Array&&t instanceof Array&&e.length===t.length&&e.every((e,n)=>t[n]===e),yl=(e,t,n)=>{let r=e.toArray(),i=hl(t),a=i.length,o=r.length,s=Math.min(o,a),c=0,l=0,u=!1;for(;c<s;c++){let e=r[c],t=i[c];if(e instanceof as)break;if(vl(n.mapping.get(e),t))u=!0;else if(!_l(e,t,n))break}for(;c+l<s;l++){let e=r[o-l-1],t=i[a-l-1];if(e instanceof as)break;if(vl(n.mapping.get(e),t))u=!0;else if(!_l(e,t,n))break}return{equalityFactor:c+l,foundMappedChild:u}},bl=(e,t,n)=>{n.mapping.set(e,t);let{nAttrs:r,str:i}=(e=>{let t=``,n=e._start,r={};for(;n!==null;)n.deleted||(n.countable&&n.content instanceof ws?t+=n.content.str:n.content instanceof G&&(r[n.content.key]=null)),n=n.right;return{nAttrs:r,str:t}})(e),a=t.map((e,t)=>{let i=e.getType(),a=Sl(e,n);return Object.keys(a).length===0&&(a=null),{attributes:Object.assign({},r,{...i!==xe.getType()&&{t:i},p:a,...El(e),...t>0&&{i:t}}),insert:e.getTextContent(),nodeKey:e.getKey()}}),o=a.map(e=>e.insert).join(``),s=_(),c;if(y(s)&&s.isCollapsed()){c=0;for(let e of a){if(e.nodeKey===s.anchor.key){c+=s.anchor.offset;break}c+=e.insert.length}}else c=o.length;let{insert:l,remove:u,index:d}=Oc(i,o,c);e.delete(d,u),e.insert(d,l),e.applyDelta(a.map(e=>({attributes:e.attributes,retain:e.insert.length})))},xl=(e,t,n,r)=>e.toDelta(t,n,r).map(e=>{let t=e.attributes??{};return`ychange`in t&&(t[wl(`ychange`)]=t.ychange,delete t.ychange),{...e,attributes:t}}),Sl=(e,t)=>{let n=Kc(e,t),r={};return Object.entries(n).forEach(([t,n])=>{let i=e[t];i!==n&&(r[t]=i)}),r},Cl=`s_`,wl=e=>`s_${e}`,Tl=e=>{if(!e.startsWith(`s_`))throw Error(`Invalid state key: ${e}`);return e.slice(2)},El=e=>{let t=e.__state;if(!t)return{};let[n={},r]=t.getInternalState(),i={};for(let[e,t]of Object.entries(n))i[wl(e)]=t;for(let[e,t]of r)i[wl(e.key)]=e.unparse(t);return i},Dl=(e,t,n,r,i)=>{if(t instanceof H&&t.nodeName!==n.getType()&&(!sl(t)||n.getType()!==ye.getType()))throw Error(`node name mismatch!`);if(r.mapping.set(t,n),t instanceof H){let e=t.getAttributes(),i={...Sl(n,r),...El(n)};for(let n in i)i[n]==null?t.removeAttribute(n):e[n]===i[n]||pl(e[n])&&pl(i[n])&&ml(e[n],i[n])||n===`ychange`||t.setAttribute(n,i[n]);for(let n in e)i[n]===void 0&&t.removeAttribute(n)}let a=hl(n),o=a.length,s=t.toArray(),c=s.length,l=Math.min(o,c),u=0,d=0;for(;u<l;u++){let t=s[u],n=a[u];if(t instanceof as)break;if(vl(r.mapping.get(t),n))n instanceof he&&i.has(n.getKey())&&Dl(e,t,n,r,i);else{if(!_l(t,n,r))break;r.mapping.set(t,n)}}for(;d+u<l;d++){let t=s[c-d-1],n=a[o-d-1];if(t instanceof as)break;if(vl(r.mapping.get(t),n))n instanceof he&&i.has(n.getKey())&&Dl(e,t,n,r,i);else{if(!_l(t,n,r))break;r.mapping.set(t,n)}}for(;c-u-d>0&&o-u-d>0;){let n=s[u],l=a[u],f=s[c-d-1],p=a[o-d-1];if(n instanceof U&&l instanceof Array)gl(n,l,r)||bl(n,l,r),u+=1;else{let a=n instanceof H&&Ol(n,l),o=f instanceof H&&Ol(f,p);if(a&&o){let e=yl(n,l,r),t=yl(f,p,r);e.foundMappedChild&&!t.foundMappedChild?o=!1:!e.foundMappedChild&&t.foundMappedChild||e.equalityFactor<t.equalityFactor?a=!1:o=!1}a?(Dl(e,n,l,r,i),u+=1):o?(Dl(e,f,p,r,i),d+=1):(r.mapping.delete(t.get(u)),t.delete(u,1),t.insert(u,[fl(l,r)]),u+=1)}}let f=c-u-d;if(c===1&&o===0&&s[0]instanceof U?(r.mapping.delete(s[0]),s[0].delete(0,s[0].length)):f>0&&(t.slice(u,u+f).forEach(e=>r.mapping.delete(e)),t.delete(u,f)),u+d<o){let e=[];for(let t=u;t<o-d;t++)e.push(fl(a[t],r));t.insert(u,e)}},Ol=(e,t)=>!(t instanceof Array)&&e.nodeName===t.getType(),kl=we(`ychange`,{isEqual:(e,t)=>e===t,parse:e=>e??null});function Al(e){return ee(e,kl)}const jl=(e,t=ya(e.doc),n=va)=>{let{doc:r}=e;r.gc&&Y(325),r.transact(i=>{let a=new sa(r);a&&a.dss.forEach(e=>{mi(i,e,e=>{})});let o=(e,t)=>({id:t,type:e,user:(e===`added`?a.getUserByClientId(t.client):a.getUserByDeletedId(t))??null});e.mapping.clear(),e.editor.update(()=>{g().clear(),cl(e.root,e,null,!0,t,n,o)})},e)};function Ml(e,t){let n=t.collabNodeMap.get(e.key);if(n===void 0)return null;let r=e.offset,i=n.getSharedType();if(n instanceof X){i=n._parent._xmlText;let e=n.getOffset();if(e===-1)return null;r=e+1+r}else if(n instanceof Pc&&e.type===`element`){let t=e.getNode();v(t)||Y(184);let n=0,i=0,a=t.getFirstChild();for(;a!==null&&i++<r;)b(a)?n+=a.getTextContentSize()+1:n++,a=a.getNextSibling();r=n}return fa(i,r)}function Nl(e,t){let{mapping:n}=t,{offset:r}=e,i=e.getNode(),a=n.getSharedType(i);if(a===void 0)return null;if(e.type===`text`){b(i)||Y(326);let e=i.getPreviousSibling(),t=r;for(;b(e);)t+=e.getTextContentSize(),e=e.getPreviousSibling();return fa(a,t)}if(e.type===`element`){v(i)||Y(184);let e=0,t=i.getFirstChild();for(;t!==null&&e<r;){if(b(t)){let e=t.getNextSibling();for(;b(e);)e=e.getNextSibling()}e++,t=t.getNextSibling()}return fa(a,e)}return null}function Pl(e,t){return ma(e,t.doc)}function Fl(e,t){if(e==null){if(t!=null)return!0}else if(t==null||!ha(e,t))return!0;return!1}function Il(e,t){return{color:t,name:e,selection:null}}function Ll(e,t){let n=e.cursorsContainer;if(n!==null){let e=t.selections,r=e.length;for(let t=0;t<r;t++)n.removeChild(e[t])}}function Rl(e,t){let n=t.selection;n!==null&&Ll(e,n)}function zl(e,t,n,r,i,a={}){let o=e.color,s=document.createElement(`span`);a.cursor?(s.className=a.cursor,De(s.style,{"--lexical-cursor-color":o,bottom:`0`,position:`absolute`,right:`-1px`,top:`0`})):De(s.style,{"background-color":o,bottom:`0`,position:`absolute`,right:`-1px`,top:`0`,width:`1px`,"z-index":`10`});let c=document.createElement(`span`);return c.textContent=e.name,a.cursorName?c.className=a.cursorName:De(c.style,{"background-color":o,color:`#fff`,"font-family":`Arial`,"font-size":`12px`,"font-weight":`bold`,left:`-2px`,"line-height":`12px`,padding:`2px`,position:`absolute`,top:`-16px`,"white-space":`nowrap`}),s.appendChild(c),{anchor:{key:t,offset:n},caret:s,color:o,focus:{key:r,offset:i},name:c,selections:[]}}function Bl(e,t,n,r,i={}){let a=e.editor,o=a.getRootElement(),s=e.cursorsContainer;if(s===null||o===null)return;let c=s.offsetParent;if(c===null)return;let l=c.getBoundingClientRect(),u=t.selection;if(n===null)return u===null?void 0:(t.selection=null,void Ll(e,u));t.selection=n;let d=n.caret,f=n.color,p=n.selections,m=n.anchor,h=n.focus,g=m.key,_=h.key,ee=r.get(g),te=r.get(_);if(ee==null||te==null)return;let ne;if(ee===te&&se(ee))ne=[a.getElementByKey(g).getBoundingClientRect()];else{let e=Tc(a,ee,m.offset,te,h.offset);if(e===null)return;ne=Ec(a,e)}let re=p.length,ie=ne.length;for(let e=0;e<ie;e++){let t=ne[e],n=p[e];if(n===void 0){n=document.createElement(`span`),p[e]=n;let t=document.createElement(`span`);i.selectionBg&&(t.className=i.selectionBg),n.appendChild(t),s.appendChild(n)}let r=t.top-l.top,a=t.left-l.left,o={height:`${t.height}px`,left:`${a}px`,"pointer-events":`none`,position:`absolute`,top:`${r}px`,width:`${t.width}px`};i.selection?(n.className=i.selection,De(n.style,{...o,"--lexical-cursor-color":f}),De(n.firstChild.style,{height:`100%`,left:`0`,position:`absolute`,top:`0`,width:`100%`})):(De(n.style,o),De(n.firstChild.style,{...o,"background-color":f,left:`0`,opacity:`0.3`,top:`0`,"z-index":`5`})),e===ie-1&&d.parentNode!==n&&n.appendChild(d)}for(let e=re-1;e>=ie;e--){let t=p[e];s.removeChild(t),p.pop()}}function Vl(e,t){let{anchorPos:n,focusPos:r}=t,i=null,a=0,o=null,s=0;if(n!==null&&r!==null){let t=Pl(n,e),c=Pl(r,e);t!==null&&c!==null&&([i,a]=Gl(t.type,t.index),[o,s]=Gl(c.type,c.index))}return{anchorCollabNode:i,anchorOffset:a,focusCollabNode:o,focusOffset:s}}function Hl(e,t){let{anchorPos:n,focusPos:r}=t,i=n?Pl(n,e):null,a=r?Pl(r,e):null;if(i===null||a===null)return{anchorKey:null,anchorOffset:0,focusKey:null,focusOffset:0};if(Bc(e)){let[e,t]=Gl(i.type,i.index),[n,r]=Gl(a.type,a.index);return{anchorKey:e===null?null:e.getKey(),anchorOffset:t,focusKey:n===null?null:n.getKey(),focusOffset:r}}let[o,s]=Kl(e.mapping,i),[c,l]=Kl(e.mapping,a);if(c&&o&&(c!==o||l!==s)){let e=c.isBefore(o),t=e?c:o,n=e?l:s;b(t)&&b(t.getNextSibling())&&n===t.getTextContentSize()&&(e?(c=t.getNextSibling(),l=0):(o=t.getNextSibling(),s=0))}return{anchorKey:o===null?null:o.getKey(),anchorOffset:s,focusKey:c===null?null:c.getKey(),focusOffset:l}}function Ul(e,t){let n=t.awareness.getLocalState();if(n===null)return;let{anchorKey:r,anchorOffset:i,focusKey:a,focusOffset:o}=Hl(e,n);if(r!==null&&a!==null){let e=_();if(!y(e))return;Wl(e.anchor,r,i),Wl(e.focus,a,o)}}function Wl(e,t,n){if(e.key!==t||e.offset!==n){let r=p(t);if(r!==null&&!v(r)&&!b(r)){let e=r.getParentOrThrow();t=e.getKey(),n=r.getIndexWithinParent(),r=e}e.set(t,n,v(r)?`element`:`text`)}}function Gl(e,t){let n=e._collabNode;if(n===void 0)return[null,0];if(n instanceof Pc){let{node:e,offset:r}=rl(n,t,!0);return e===null?[n,0]:[e,r]}return[null,0]}function Kl(e,t){let n=t.type,r=t.index;if(n instanceof H){let t=e.get(n);if(t===void 0)return[null,0];if(!v(t))return[t,r];let i=r,a=0,o=t.getChildren();for(;i>0&&a<o.length;){let e=o[a];if(--i,a+=1,b(e))for(;a<o.length&&b(o[a]);)a+=1}return[t,a]}{let t=e.get(n);if(t===void 0)return[null,0];let i=0,a=r;for(;a>t[i].getTextContentSize()&&i+1<t.length;)a-=t[i].getTextContentSize(),i++;let o=t[i];return[o,Math.min(a,o.getTextContentSize())]}}function ql(e,t){return t.awareness.getStates()}function Jl(e,t,n){let{getAwarenessStates:r=ql}=n??{},i=Array.from(r(e,t)),a=e.clientID,o=e.cursors,s=e.editor,c=s._config.theme.collaboration,l=s._editorState._nodeMap,u=new Set;for(let t=0;t<i.length;t++){let[n,r]=i[t];if(n!==0&&n!==a){u.add(n);let{name:t,color:i,focusing:a}=r,d=null,f=o.get(n);if(f===void 0&&(f=Il(t,i),o.set(n,f)),a){let{anchorKey:t,anchorOffset:n,focusKey:i,focusOffset:a}=s.read(()=>Hl(e,r));if(t!==null&&i!==null)if(d=f.selection,d===null)d=zl(f,t,n,i,a,c);else{let e=d.anchor,r=d.focus;e.key=t,e.offset=n,r.key=i,r.offset=a}}Bl(e,f,d,l,c)}}let d=Array.from(o.keys());for(let t=0;t<d.length;t++){let n=d[t];if(!u.has(n)){let t=o.get(n);t!==void 0&&(Rl(e,t),o.delete(n))}}}function Yl(e,t,n,r){let i=t.awareness,a=i.getLocalState();if(a===null)return;let{anchorPos:o,focusPos:s,name:c,color:l,focusing:u,awarenessData:d}=a,f=null,p=null;(r!==null&&(o===null||r.is(n))||n!==null)&&(y(r)&&(Bc(e)?(f=Ml(r.anchor,e),p=Ml(r.focus,e)):(f=Nl(r.anchor,e),p=Nl(r.focus,e))),(Fl(o,f)||Fl(s,p))&&i.setLocalState({...a,anchorPos:f,awarenessData:d,color:l,focusPos:p,focusing:u,name:c}))}function Xl(e,t){if(t instanceof Po&&function(e,t){let{target:n}=t;if(!n._item||n._item.parentSub!==`__state`||Jc(n)!==void 0||!(n.parent instanceof U||n.parent instanceof H||n.parent instanceof V))return!1;let r=Yc(e,n.parent).getNode();if(r){let e=te(r.getWritable());for(let r of t.keysChanged)e.updateFromUnknown(r,n.get(r))}return!0}(e,t))return;let{target:n}=t,r=Yc(e,n);if(r instanceof Pc&&t instanceof Zo){let{keysChanged:n,childListChanged:i,delta:a}=t;n.size>0&&r.syncPropertiesFromYjs(e,n),i&&(r.applyChildrenYjsDelta(e,a),r.syncChildrenFromYjs(e))}else if(r instanceof X&&t instanceof Po){let{keysChanged:n}=t;n.size>0&&r.syncPropertiesAndTextFromYjs(e,n)}else if(r instanceof kc&&t instanceof is){let{attributesChanged:n}=t;n.size>0&&r.syncPropertiesFromYjs(e,n)}else Y(82)}function Zl(t,n,r,i,a=Jl){let o=t.editor,s=o._editorState;r.forEach(e=>e.delta),o.update(()=>{for(let e=0;e<r.length;e++){let n=r[e];Xl(t,n)}Ql(s,t,n),i||e(be)},{onUpdate:()=>{a(t,n),o.update(()=>$l())},skipTransforms:!0,tag:i?ge:me})}function Ql(e,t,n){let r=_();if(y(r))if(il(r)){let i=e._selection;y(i)&&(Ul(t,n),il(r))&&ol(r.anchor.key,e),Yl(t,n,i,_())}else Ul(t,n)}function $l(){g().getChildrenSize()===0&&g().append(o())}function eu(e,t,n,r,i,a,o,s){al(e,()=>{r.read(()=>{if(s.has(me)||s.has(ge))return void(o.size>0&&function(e,t){let n=Array.from(t),r=e.collabNodeMap,i=[],a=[];for(let e=0;e<n.length;e++){let t=n[e],o=p(t),s=r.get(t);if(s instanceof X)if(b(o))i.push([s,o.__text]);else{let e=s.getOffset();if(e===-1)continue;let t=s._parent;s._normalized=!0,t._xmlText.delete(e,1),a.push(s)}}for(let e=0;e<a.length;e++){let t=a[e],n=t.getKey();r.delete(n);let i=t._parent._children,o=i.indexOf(t);i.splice(o,1)}for(let e=0;e<i.length;e++){let[t,n]=i[e];t._text=n}}(e,o));if(i.has(`root`)){let t=n._nodeMap,r=g(),o=e.root;o.syncPropertiesFromLexical(e,r,t),o.syncChildrenFromLexical(e,r,t,i,a)}let r=_(),c=n._selection;Yl(e,t,c,r)})})}function tu(e,t){let{target:n}=t;if(n instanceof H&&t instanceof is)cl(n,e,t.attributesChanged,t.childListChanged);else if(n instanceof U&&t instanceof Zo){let t=n.parent;t instanceof H?cl(t,e,new Set,!0):Y(327)}else Y(328)}function nu(t,n,r,i,a){let o=t.editor,s=o._editorState;mi(i,i.deleteSet,e=>{if(e.constructor===K){let n=e.content.type;n&&t.mapping.delete(n)}}),r.forEach(e=>e.delta),o.update(()=>{for(let e=0;e<r.length;e++){let n=r[e];tu(t,n)}Ql(s,t,n),a||e(be)},{discrete:!0,onUpdate:()=>{Jl(t,n),o.update(()=>$l())},skipTransforms:!0,tag:a?ge:me})}function ru(t,n){t.mapping.clear();let r=t.editor;r.update(()=>{g().clear(),cl(t.root,t,null,!0),e(me)},{discrete:!0,onUpdate:()=>{Jl(t,n),r.update(()=>$l())},skipTransforms:!0,tag:me})}function iu(e,t,n,r,i,a,o){(o.has(me)||o.has(ge))&&a.size===0||(a.forEach(t=>{e.mapping.deleteNode(t)}),al(e,()=>{r.read(()=>{i.has(`root`)&&Dl(e.doc,e.root,g(),e,new Set(i.keys()));let r=_(),a=n._selection;Yl(e,t,a,r)})}))}const au=Se(`CONNECTED_COMMAND`),ou=Se(`TOGGLE_CONNECT_COMMAND`),su=Se(`DIFF_VERSIONS_COMMAND`),cu=Se(`CLEAR_DIFF_VERSIONS_COMMAND`);function lu(e,t){return new Va(t,{trackedOrigins:new Set([e,null])})}function uu(e,t,n,r,i){e.awareness.setLocalState({anchorPos:null,awarenessData:i,color:n,focusPos:null,focusing:r,name:t})}function du(e,t,n,r,i){let{awareness:a}=e,o=a.getLocalState();o===null&&(o={anchorPos:null,awarenessData:i,color:n,focusPos:null,focusing:r,name:t}),o.focusing=r,a.setLocalState(o)}const Z=Dc;Z.$getYChangeState,Z.CLEAR_DIFF_VERSIONS_COMMAND__EXPERIMENTAL,Z.CONNECTED_COMMAND,Z.DIFF_VERSIONS_COMMAND__EXPERIMENTAL,Z.TOGGLE_CONNECT_COMMAND;const fu=Z.createBinding;Z.createBindingV2__EXPERIMENTAL,Z.createUndoManager,Z.getAnchorAndFocusCollabNodesForUserState;const pu=Z.initLocalState;Z.renderSnapshot__EXPERIMENTAL;const mu=Z.setLocalStateFocus,hu=Z.syncCursorPositions,gu=Z.syncLexicalUpdateToYjs;Z.syncLexicalUpdateToYjsV2__EXPERIMENTAL;const _u=Z.syncYjsChangesToLexical;Z.syncYjsChangesToLexicalV2__EXPERIMENTAL,Z.syncYjsStateToLexicalV2__EXPERIMENTAL;var vu={logger:typeof console<`u`?console:void 0,WebSocket:typeof WebSocket<`u`?WebSocket:void 0},Q={log(...e){this.enabled&&(e.push(Date.now()),vu.logger.log(`[ActionCable]`,...e))}};const yu=()=>new Date().getTime(),bu=e=>(yu()-e)/1e3;var xu=class{constructor(e){this.visibilityDidChange=this.visibilityDidChange.bind(this),this.connection=e,this.reconnectAttempts=0}start(){this.isRunning()||(this.startedAt=yu(),delete this.stoppedAt,this.startPolling(),addEventListener(`visibilitychange`,this.visibilityDidChange),Q.log(`ConnectionMonitor started. stale threshold = ${this.constructor.staleThreshold} s`))}stop(){this.isRunning()&&(this.stoppedAt=yu(),this.stopPolling(),removeEventListener(`visibilitychange`,this.visibilityDidChange),Q.log(`ConnectionMonitor stopped`))}isRunning(){return this.startedAt&&!this.stoppedAt}recordMessage(){this.pingedAt=yu()}recordConnect(){this.reconnectAttempts=0,delete this.disconnectedAt,Q.log(`ConnectionMonitor recorded connect`)}recordDisconnect(){this.disconnectedAt=yu(),Q.log(`ConnectionMonitor recorded disconnect`)}startPolling(){this.stopPolling(),this.poll()}stopPolling(){clearTimeout(this.pollTimeout)}poll(){this.pollTimeout=setTimeout((()=>{this.reconnectIfStale(),this.poll()}),this.getPollInterval())}getPollInterval(){let{staleThreshold:e,reconnectionBackoffRate:t}=this.constructor,n=(1+t)**+Math.min(this.reconnectAttempts,10),r=(this.reconnectAttempts===0?1:t)*Math.random();return e*1e3*n*(1+r)}reconnectIfStale(){this.connectionIsStale()&&(Q.log(`ConnectionMonitor detected stale connection. reconnectAttempts = ${this.reconnectAttempts}, time stale = ${bu(this.refreshedAt)} s, stale threshold = ${this.constructor.staleThreshold} s`),this.reconnectAttempts++,this.disconnectedRecently()?Q.log(`ConnectionMonitor skipping reopening recent disconnect. time disconnected = ${bu(this.disconnectedAt)} s`):(Q.log(`ConnectionMonitor reopening`),this.connection.reopen()))}get refreshedAt(){return this.pingedAt?this.pingedAt:this.startedAt}connectionIsStale(){return bu(this.refreshedAt)>this.constructor.staleThreshold}disconnectedRecently(){return this.disconnectedAt&&bu(this.disconnectedAt)<this.constructor.staleThreshold}visibilityDidChange(){document.visibilityState===`visible`&&setTimeout((()=>{(this.connectionIsStale()||!this.connection.isOpen())&&(Q.log(`ConnectionMonitor reopening stale connection on visibilitychange. visibilityState = ${document.visibilityState}`),this.connection.reopen())}),200)}};xu.staleThreshold=6,xu.reconnectionBackoffRate=.15;var Su={message_types:{welcome:`welcome`,disconnect:`disconnect`,ping:`ping`,confirmation:`confirm_subscription`,rejection:`reject_subscription`},disconnect_reasons:{unauthorized:`unauthorized`,invalid_request:`invalid_request`,server_restart:`server_restart`,remote:`remote`},default_mount_path:`/cable`,protocols:[`actioncable-v1-json`,`actioncable-unsupported`]};const{message_types:Cu,protocols:wu}=Su,Tu=wu.slice(0,wu.length-1),Eu=[].indexOf;var Du=class{constructor(e){this.open=this.open.bind(this),this.consumer=e,this.subscriptions=this.consumer.subscriptions,this.monitor=new xu(this),this.disconnected=!0}send(e){return this.isOpen()?(this.webSocket.send(JSON.stringify(e)),!0):!1}open(){if(this.isActive())return Q.log(`Attempted to open WebSocket, but existing socket is ${this.getState()}`),!1;{let e=[...wu,...this.consumer.subprotocols||[]];return Q.log(`Opening WebSocket, current state is ${this.getState()}, subprotocols: ${e}`),this.webSocket&&this.uninstallEventHandlers(),this.webSocket=new vu.WebSocket(this.consumer.url,e),this.installEventHandlers(),this.monitor.start(),!0}}close({allowReconnect:e}={allowReconnect:!0}){if(e||this.monitor.stop(),this.isOpen())return this.webSocket.close()}reopen(){if(Q.log(`Reopening WebSocket, current state is ${this.getState()}`),this.isActive())try{return this.close()}catch(e){Q.log(`Failed to reopen WebSocket`,e)}finally{Q.log(`Reopening WebSocket in ${this.constructor.reopenDelay}ms`),setTimeout(this.open,this.constructor.reopenDelay)}else return this.open()}getProtocol(){if(this.webSocket)return this.webSocket.protocol}isOpen(){return this.isState(`open`)}isActive(){return this.isState(`open`,`connecting`)}triedToReconnect(){return this.monitor.reconnectAttempts>0}isProtocolSupported(){return Eu.call(Tu,this.getProtocol())>=0}isState(...e){return Eu.call(e,this.getState())>=0}getState(){if(this.webSocket){for(let e in vu.WebSocket)if(vu.WebSocket[e]===this.webSocket.readyState)return e.toLowerCase()}return null}installEventHandlers(){for(let e in this.events){let t=this.events[e].bind(this);this.webSocket[`on${e}`]=t}}uninstallEventHandlers(){for(let e in this.events)this.webSocket[`on${e}`]=function(){}}};Du.reopenDelay=500,Du.prototype.events={message(e){if(!this.isProtocolSupported())return;let{identifier:t,message:n,reason:r,reconnect:i,type:a}=JSON.parse(e.data);switch(this.monitor.recordMessage(),a){case Cu.welcome:return this.triedToReconnect()&&(this.reconnectAttempted=!0),this.monitor.recordConnect(),this.subscriptions.reload();case Cu.disconnect:return Q.log(`Disconnecting. Reason: ${r}`),this.close({allowReconnect:i});case Cu.ping:return null;case Cu.confirmation:return this.subscriptions.confirmSubscription(t),this.reconnectAttempted?(this.reconnectAttempted=!1,this.subscriptions.notify(t,`connected`,{reconnected:!0})):this.subscriptions.notify(t,`connected`,{reconnected:!1});case Cu.rejection:return this.subscriptions.reject(t);default:return this.subscriptions.notify(t,`received`,n)}},open(){if(Q.log(`WebSocket onopen event, using '${this.getProtocol()}' subprotocol`),this.disconnected=!1,!this.isProtocolSupported())return Q.log(`Protocol is unsupported. Stopping monitor and disconnecting.`),this.close({allowReconnect:!1})},close(e){if(Q.log(`WebSocket onclose event`),!this.disconnected)return this.disconnected=!0,this.monitor.recordDisconnect(),this.subscriptions.notifyAll(`disconnected`,{willAttemptReconnect:this.monitor.isRunning()})},error(){Q.log(`WebSocket onerror event`)}};const Ou=function(e,t){if(t!=null)for(let n in t)e[n]=t[n];return e};var ku=class{constructor(e,t={},n){this.consumer=e,this.identifier=JSON.stringify(t),Ou(this,n)}perform(e,t={}){return t.action=e,this.send(t)}send(e){return this.consumer.send({command:`message`,identifier:this.identifier,data:JSON.stringify(e)})}unsubscribe(){return this.consumer.subscriptions.remove(this)}},Au=class{constructor(e){this.subscriptions=e,this.pendingSubscriptions=[]}guarantee(e){this.pendingSubscriptions.indexOf(e)==-1?(Q.log(`SubscriptionGuarantor guaranteeing ${e.identifier}`),this.pendingSubscriptions.push(e)):Q.log(`SubscriptionGuarantor already guaranteeing ${e.identifier}`),this.startGuaranteeing()}forget(e){Q.log(`SubscriptionGuarantor forgetting ${e.identifier}`),this.pendingSubscriptions=this.pendingSubscriptions.filter((t=>t!==e))}startGuaranteeing(){this.stopGuaranteeing(),this.retrySubscribing()}stopGuaranteeing(){clearTimeout(this.retryTimeout)}retrySubscribing(){this.retryTimeout=setTimeout((()=>{this.subscriptions&&typeof this.subscriptions.subscribe==`function`&&this.pendingSubscriptions.map((e=>{Q.log(`SubscriptionGuarantor resubscribing ${e.identifier}`),this.subscriptions.subscribe(e)}))}),500)}},ju=class{constructor(e){this.consumer=e,this.guarantor=new Au(this),this.subscriptions=[]}create(e,t){let n=e,r=typeof n==`object`?n:{channel:n},i=new ku(this.consumer,r,t);return this.add(i)}add(e){return this.subscriptions.push(e),this.consumer.ensureActiveConnection(),this.notify(e,`initialized`),this.subscribe(e),e}remove(e){return this.forget(e),this.findAll(e.identifier).length||this.sendCommand(e,`unsubscribe`),e}reject(e){return this.findAll(e).map((e=>(this.forget(e),this.notify(e,`rejected`),e)))}forget(e){return this.guarantor.forget(e),this.subscriptions=this.subscriptions.filter((t=>t!==e)),e}findAll(e){return this.subscriptions.filter((t=>t.identifier===e))}reload(){return this.subscriptions.map((e=>this.subscribe(e)))}notifyAll(e,...t){return this.subscriptions.map((n=>this.notify(n,e,...t)))}notify(e,t,...n){let r;return r=typeof e==`string`?this.findAll(e):[e],r.map((e=>typeof e[t]==`function`?e[t](...n):void 0))}subscribe(e){this.sendCommand(e,`subscribe`)&&this.guarantor.guarantee(e)}confirmSubscription(e){Q.log(`Subscription confirmed ${e}`),this.findAll(e).map((e=>this.guarantor.forget(e)))}sendCommand(e,t){let{identifier:n}=e;return this.consumer.send({command:t,identifier:n})}},Mu=class{constructor(e){this._url=e,this.subscriptions=new ju(this),this.connection=new Du(this),this.subprotocols=[]}get url(){return Nu(this._url)}send(e){return this.connection.send(e)}connect(){return this.connection.open()}disconnect(){return this.connection.close({allowReconnect:!1})}ensureActiveConnection(){if(!this.connection.isActive())return this.connection.open()}addSubProtocol(e){this.subprotocols=[...this.subprotocols,e]}};function Nu(e){if(typeof e==`function`&&(e=e()),e&&!/^wss?:/i.test(e)){let t=document.createElement(`a`);return t.href=e,t.href=t.href,t.protocol=t.protocol.replace(`http`,`ws`),t.href}return e}function Pu(e=Fu(`url`)||Su.default_mount_path){return new Mu(e)}function Fu(e){let t=document.head.querySelector(`meta[name='action-cable-${e}']`);if(t)return t.getAttribute(`content`)}const Iu={resendInterval:1e3};var Lu=class{pending=[];#e;#t;#n;#r;#i;#a=1;#o=!1;#s=void 0;#c=void 0;constructor(e){let{send:t,merge:n,resendInterval:r}=e??{};if(typeof t!=`function`)throw TypeError(`ReliableSync requires a send(update, id) function`);if(typeof n!=`function`)throw TypeError(`ReliableSync requires a merge(updates) function`);this.#e=t,this.#t=n;let i=r??Iu.resendInterval;if(!Number.isFinite(i)||i<=0)throw TypeError(`ReliableSync resendInterval must be a positive number`);this.#n=i,this.#r=e.setInterval??((e,t)=>setInterval(e,t)),this.#i=e.clearInterval??(e=>clearInterval(e))}get hasPending(){return this.pending.length>0}enqueue(e){this.pending.push({seq:this.#a++,update:e}),this.#c=void 0,this.#o&&this.#u(),this.flush()}flush(){!this.#o||this.pending.length===0||this.#e(this.#l(),this.pending[this.pending.length-1].seq)}onAck(e){!Number.isSafeInteger(e)||e<0||this.pending.length>0&&e>this.pending[this.pending.length-1].seq||(this.pending=this.pending.filter(t=>t.seq>e),this.#c=void 0,this.pending.length===0&&this.#d())}onConnect(){this.#o=!0,this.flush(),this.pending.length>0&&this.#u()}onDisconnect(){this.#o=!1,this.#d()}onTick(){!this.#o||this.pending.length===0||this.flush()}destroy(){this.#o=!1,this.#d(),this.pending=[],this.#c=void 0}#l(){if(this.#c===void 0){let e=this.pending.map(e=>e.update);this.#c=e.length===1?e[0]:this.#t(e)}return this.#c}#u(){if(this.#s!==void 0)return;this.#s=this.#r(()=>this.onTick(),this.#n);let e=this.#s;e&&typeof e.unref==`function`&&e.unref()}#d(){this.#s!==void 0&&this.#i(this.#s),this.#s=void 0}};const Ru=(e,t)=>{T(e,0);let n=Zi(t);E(e,n)},zu=(e,t,n)=>{T(e,1),E(e,Gi(t,n))},Bu=(e,t,n)=>zu(t,n,A(e)),Vu=(e,t,n,r)=>{try{Hi(t,A(e),n)}catch(e){r?.(e),console.error(`Caught error while handling a Yjs update`,e)}},Hu=(e,t)=>{T(e,2),E(e,t)},Uu=Vu,Wu=(e,t,n,r,i)=>{let a=j(e);switch(a){case 0:Bu(e,t,n);break;case 1:Vu(e,n,r,i);break;case 2:Uu(e,n,r,i);break;default:throw Error(`Unknown message type`)}return a};var Gu=class extends Ue{constructor(e){super(),this.doc=e,this.clientID=e.clientID,this.states=new Map,this.meta=new Map,this._checkInterval=setInterval(()=>{let e=Xt();this.getLocalState()!==null&&3e4/2<=e-this.meta.get(this.clientID).lastUpdated&&this.setLocalState(this.getLocalState());let t=[];this.meta.forEach((n,r)=>{r!==this.clientID&&3e4<=e-n.lastUpdated&&this.states.has(r)&&t.push(r)}),t.length>0&&Ku(this,t,`timeout`)},S(3e4/10)),e.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(e){let t=this.clientID,n=this.meta.get(t),r=n===void 0?0:n.clock+1,i=this.states.get(t);e===null?this.states.delete(t):this.states.set(t,e),this.meta.set(t,{clock:r,lastUpdated:Xt()});let a=[],o=[],s=[],c=[];e===null?c.push(t):i==null?e!=null&&a.push(t):(o.push(t),_n(i,e)||s.push(t)),(a.length>0||s.length>0||c.length>0)&&this.emit(`change`,[{added:a,updated:s,removed:c},`local`]),this.emit(`update`,[{added:a,updated:o,removed:c},`local`])}setLocalStateField(e,t){let n=this.getLocalState();n!==null&&this.setLocalState({...n,[e]:t})}getStates(){return this.states}};const Ku=(e,t,n)=>{let r=[];for(let n=0;n<t.length;n++){let i=t[n];if(e.states.has(i)){if(e.states.delete(i),i===e.clientID){let t=e.meta.get(i);e.meta.set(i,{clock:t.clock+1,lastUpdated:Xt()})}r.push(i)}}r.length>0&&(e.emit(`change`,[{added:[],updated:[],removed:r},n]),e.emit(`update`,[{added:[],updated:[],removed:r},n]))},qu=(e,t,n=e.states)=>{let r=t.length,i=lt();T(i,r);for(let a=0;a<r;a++){let r=t[a],o=n.get(r)||null,s=e.meta.get(r).clock;T(i,r),T(i,s),gt(i,JSON.stringify(o))}return C(i)},Ju=(e,t,n)=>{let r=k(t),i=Xt(),a=[],o=[],s=[],c=[],l=j(r);for(let t=0;t<l;t++){let t=j(r),n=j(r),l=JSON.parse(zt(r)),u=e.meta.get(t),d=e.states.get(t),f=u===void 0?0:u.clock;(f<n||f===n&&l===null&&e.states.has(t))&&(l===null?t===e.clientID&&e.getLocalState()!=null?n++:e.states.delete(t):e.states.set(t,l),e.meta.set(t,{clock:n,lastUpdated:i}),u===void 0&&l!==null?a.push(t):u!==void 0&&l===null?c.push(t):l!==null&&(_n(l,d)||s.push(t),o.push(t)))}(a.length>0||s.length>0||c.length>0)&&e.emit(`change`,[{added:a,updated:s,removed:c},n]),(a.length>0||o.length>0||c.length>0)&&e.emit(`update`,[{added:a,updated:o,removed:c},n])},$={Sync:0,Awareness:1};var Yu=class{doc;awareness;#e;#t;#n=!1;#r;#i;#a;constructor(e,t){let{send:n,awareness:r=null,resendInterval:i,onError:a,setInterval:o,clearInterval:s}=t??{};if(!e)throw TypeError(`YProtocolSession requires a Y.Doc`);if(typeof n!=`function`)throw TypeError(`YProtocolSession requires a send(frame, id) function`);this.doc=e,this.awareness=r,this.#e=n,this.#t=a??((e,t)=>console.warn(`[yrby] ${t}:`,e)),this.#r=new Lu({merge:Ga,send:(e,t)=>this.#e(this.#s(e),t),resendInterval:i,setInterval:o,clearInterval:s}),this.#i=(e,t)=>{t!==this&&this.#r.enqueue(e)},this.doc.on(`update`,this.#i),this.awareness&&(this.#a=({added:e,updated:t,removed:n},r)=>{if(r===this)return;let i=e.concat(t,n);this.#e(this.#c(i),void 0)},this.awareness.on(`update`,this.#a))}get synced(){return this.#n}get hasPending(){return this.#r.hasPending}onConnect(){this.#e(this.#o(),void 0),this.awareness&&this.awareness.getLocalState()!==null&&this.#e(this.#c([this.doc.clientID]),void 0),this.#r.onConnect()}onDisconnect(){if(this.#n=!1,this.#r.onDisconnect(),this.awareness){let e=[...this.awareness.getStates().keys()].filter(e=>e!==this.doc.clientID);e.length&&Ku(this.awareness,e,this)}}removeLocalAwareness(){this.awareness&&this.awareness.getLocalState()!==null&&this.awareness.setLocalState(null)}ack(e){this.#r.onAck(e)}applyRemoteUpdate(e){Hi(this.doc,e,this)}receive(e){try{if(this.#l(e)===null)return null;let t=k(e),n=lt();switch(j(t)){case $.Sync:{T(n,$.Sync);let e=Wu(t,n,this.doc,this);!this.#n&&e===1&&(this.#n=!0);break}case $.Awareness:this.awareness&&Ju(this.awareness,A(t),this);break;default:return null}return ut(n)>1?C(n):null}catch(e){return this.#t(e,`receive`),null}}destroy(){this.doc.off(`update`,this.#i),this.awareness&&this.#a&&this.awareness.off(`update`,this.#a),this.#r.destroy()}#o(){let e=lt();return T(e,$.Sync),Ru(e,this.doc),C(e)}#s(e){let t=lt();return T(t,$.Sync),Hu(t,e),C(t)}#c(e){let t=lt();return T(t,$.Awareness),E(t,qu(this.awareness,e)),C(t)}#l(e){let t=k(e),n=j(t);switch(n){case $.Sync:{let e=new Ei;try{let n=lt();T(n,$.Sync),Wu(t,n,e,this)}finally{e.destroy()}break}case $.Awareness:{let e=A(t),n=k(e),r=j(n);for(let e=0;e<r;e++)j(n),j(n),JSON.parse(zt(n));if(Ft(n))throw Error(`awareness payload has trailing bytes`)}break;default:return null}if(Ft(t))throw Error(`frame has trailing bytes after a complete message`);return n}};const Xu=e=>btoa(Array.from(e,e=>String.fromCharCode(e)).join(``)),Zu=e=>Uint8Array.from(atob(e),e=>e.charCodeAt(0));var Qu=class{doc;consumer;channelName;channelParams;awareness;session;#e=null;#t;#n=!1;#r=`disconnected`;#i=new Set;#a=null;#o=!1;#s=null;#c=null;#l=null;constructor(e,t,n,r={},i={}){this.doc=e,this.consumer=t,this.channelName=n,this.channelParams=r,this.awareness=new Gu(e),this.#t=i.onError??((e,t)=>console.warn(`[yrby] ${t}:`,e)),this.session=new Yu(e,{awareness:this.awareness,resendInterval:i.resendInterval,onError:this.#t,send:(e,t)=>this.#m(e,t)})}get synced(){return this.session.synced}get whenSynced(){return this.#a??=this.#o?Promise.resolve():new Promise(e=>{let t=this.onStatusChange(({status:n})=>{n===`synced`&&(t(),e())})}),this.#a}get hasPending(){return this.session.hasPending}applyRemoteUpdate(e){this.session.applyRemoteUpdate(e)}get status(){return this.#r}onStatusChange(e){return this.#i.add(e),()=>this.#i.delete(e)}connect(){if(this.#e)return;let e=this;this.#e=this.consumer.subscriptions.create({channel:this.channelName,...this.channelParams},{received(t){if(t&&t.ack!==void 0){e.session.ack(t.ack);return}let n=t&&t.awareness,r=t&&(n??t.update);if(typeof r!=`string`)return;let i;try{i=Zu(r)}catch(t){e.#t(t,`received`);return}if(n!==void 0&&i[0]!==$.Awareness){e.#t(Error(`awareness envelope carried a non-awareness frame`),`received`);return}let a=e.session.receive(i);a&&e.#m(a,void 0),e.#d()},connected(){e.#n=!0,e.session.onConnect(),e.#d()},disconnected(){e.#n=!1,e.session.onDisconnect(),e.#d()},rejected(){e.#t(Error(`subscription rejected by the server`),`rejected`),e.disconnect()}}),this.#f(),this.#d()}disconnect(){if(!this.#e)return;let e=this.#e;this.session.removeLocalAwareness(),this.session.onDisconnect(),this.#n=!1,this.#e=null,this.#p(),queueMicrotask(()=>e.unsubscribe?.()),this.#d()}destroy(){this.disconnect(),this.session.destroy(),this.awareness.destroy(),this.#i.clear()}#u(){return this.#e?this.#n?this.session.synced?`synced`:`connected`:`connecting`:`disconnected`}#d(){let e=this.#u();if(e!==this.#r){this.#r=e,e===`synced`&&(this.#o=!0);for(let t of this.#i)t({status:e})}}#f(){typeof window>`u`||this.#s||(this.#s=()=>{this.#l=this.awareness.getLocalState(),this.session.removeLocalAwareness()},this.#c=e=>{!e.persisted||!this.#l||(this.awareness.getLocalState()===null&&this.awareness.setLocalState(this.#l),this.#l=null)},window.addEventListener(`pagehide`,this.#s),window.addEventListener(`pageshow`,this.#c))}#p(){typeof window>`u`||(this.#s&&=(window.removeEventListener(`pagehide`,this.#s),null),this.#c&&=(window.removeEventListener(`pageshow`,this.#c),null))}#m(e,t){let n=this.#e;if(!n)return;let r=Xu(e),i=e[0]===$.Awareness;try{if(i&&typeof n.whisper==`function`){this.#h(n.whisper({awareness:r}));return}let e=t===void 0?{update:r}:{update:r,id:t};this.#h(n.send(e))}catch(e){this.#t(e,`send`)}}#h(e){e instanceof Promise&&e.catch(e=>this.#t(e,`send`))}};const $u=new Set([`editor`,`file`,`previewSrc`,`uploadUrl`,`blobUrlTemplate`]),ed=new Set([`action_text_attachment`,`action_text_attachment_upload`,`custom_action_text_attachment`]);function td(e){let t=new Map,n=e?._nodes;return!n||typeof n.forEach!=`function`||n.forEach((e,n)=>{ed.has(n)&&t.set(e.klass,$u)}),t}function nd(e){let t=e?.root?.constructor?.prototype;if(!t||typeof t.splice!=`function`||t.__yrbySplicePatched)return;let n=t.splice;t.splice=function(e,t,r,i){if(this._children[t]!==void 0||i!==void 0)return n.call(this,e,t,r,i)},t.__yrbySplicePatched=!0}function rd(e,t,n,r){let i=e=>{e?.persisted||ad(t)};window.addEventListener(`pagehide`,i);let a=n=>{e.closest(`[data-turbo-permanent]`)||n.type===`turbo:before-frame-render`&&!n.target.contains(e)||ad(t)};document.addEventListener(`turbo:before-cache`,a),document.addEventListener(`turbo:before-frame-render`,a);let o=id(t,n,r);return()=>{window.removeEventListener(`pagehide`,i),document.removeEventListener(`turbo:before-cache`,a),document.removeEventListener(`turbo:before-frame-render`,a),o()}}function id(e,t,n){let r=null,i=!1,a=()=>n.getStates().size<=1,o=()=>{if(r=null,i||!a())return;if(!t.synced){s();return}let n=e?._nodes?.get?.(`action_text_attachment_upload`);n&&e.update(()=>{for(let e of de(n.klass))e.getType()===`action_text_attachment_upload`&&!e.file&&e.remove()},{discrete:!0,tag:_e})},s=()=>{!i&&!r&&a()&&(r=setTimeout(o,25e3))},c=()=>{a()?s():r&&=(clearTimeout(r),null)};return n.on(`change`,c),t.doc?.on?.(`update`,s),t.whenSynced?.then?.(s),s(),()=>{i=!0,clearTimeout(r),r=null,n.off(`change`,c),t.doc?.off?.(`update`,s)}}function ad(e){let t=`action_text_attachment_upload`,n=e?._nodes?.get?.(t);n&&e.update(()=>{for(let e of de(n.klass))e.getType()===t&&e.file&&e.remove()},{discrete:!0,tag:_e})}let od,sd;function cd(e){sd=e}function ld(){return typeof sd==`function`&&(sd=sd()),sd||(od??=Pu())}var ud=class extends HTMLElement{#e=null;connectedCallback(){if(this.editorElement=this.closest(`lexxy-editor`),!this.editorElement){console.error(`<lexxy-collaboration> must be placed inside a <lexxy-editor>.`);return}this.editor=this.editorElement.editor,this.editor?this.#t():this.editorElement.addEventListener(`lexxy:initialize`,()=>{this.editor=this.editorElement.editor,this.#t()},{once:!0})}disconnectedCallback(){this.#e?.()}#t(){let e=this.getAttribute(`doc-id`)||`main`,t=this.getAttribute(`name`)||`Example User`,n=this.getAttribute(`color`)||`#958DF1`,r=this.getAttribute(`channel-name`)||`SyncChannel`,i=this.getAttribute(`channel-params`)||`{}`,a;try{a=typeof i==`string`?JSON.parse(i):i}catch{console.error(`<lexxy-collaboration>: invalid channel-params attribute (expected JSON); using {}.`,i),a={}}let o=!this.provider,s=!this.doc,c=this.doc||new Ei,l=this.provider||new Qu(c,this.consumer||ld(),r,a);o&&l.connect();let u=l.awareness,d=new Map;d.set(e,c);let f=this.editor.getEditorState();this.editor.update(()=>g().clear(),{tag:_e,discrete:!0});let p=td(this.editor),m=fu(this.editor,l,e,c,d,p);nd(m);let h=pd(this.editor,l,m),_=fd(this.editor,l,m,f),ee=this.#n();m.cursorsContainer=ee,pu(l,t,n,!0,{name:t,color:n}),mu(l,t,n,!0,{name:t,color:n});let te=rd(this.editorElement,this.editor,l,u),ne=()=>hu(m,l);u.on(`update`,ne);let re=this.editor.registerUpdateListener(ne);hu(m,l),this.provider=l,this.doc=c,this.awareness=u,this.binding=m,this.#e=()=>{this.#e=null,te(),u.off(`update`,ne),re(),h(),_(),ee.remove(),o&&(l.disconnect(),this.provider=null),s&&(this.doc=null)}}#n(){let e=this.editorElement.querySelector(`.lexxy-editor-container`)||this.editorElement;getComputedStyle(e).position===`static`&&(e.style.position=`relative`);let t=document.createElement(`div`);return t.className=`lexxy-collab-cursors`,t.style.cssText=`position:absolute;inset:0;pointer-events:none;`,e.appendChild(t),t}};function dd(e){return e.read(()=>{let e=g();if(e.getChildrenSize()===0)return!0;let t=e.getChildrenSize()===1&&e.getFirstChild();return!!t&&t.getType()===`paragraph`&&t.getChildrenSize()===0})}function fd(e,t,n,r){let i=!1,a=()=>{if(!(i||!t.synced)&&(i=!0,s&&clearInterval(s),n.root.getSharedType().length===0)){if(r&&!dd(r)){e.setEditorState(r,{tag:_e});return}e.update(()=>{let e=g();e.clear(),e.append(o())},{tag:_e})}},s;return t.whenSynced?.then?t.whenSynced.then(a,()=>{}):(s=setInterval(a,50),typeof s?.unref==`function`&&s.unref()),()=>{i=!0,s&&clearInterval(s)}}function pd(e,t,n){let r=e.registerUpdateListener(({dirtyElements:r,dirtyLeaves:i,editorState:a,normalizedNodes:o,prevEditorState:s,tags:c})=>{e.getEditorState().read(()=>{c.has(`skip-collab`)===!1&&gu(n,t,s,a,r,i,o,c)})}),i=(e,r)=>{r.origin!==n&&_u(n,t,e,!1)};return n.root.getSharedType().observeDeep(i),()=>{r(),n.root.getSharedType().unobserveDeep(i)}}customElements.get(`lexxy-collaboration`)||customElements.define(`lexxy-collaboration`,ud);export{ud as Collaboration,Qu as YrbyProvider,cd as setConsumer};
|