@richscripts/richtexteditor 2.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.
Files changed (184) hide show
  1. package/README.md +360 -0
  2. package/admin/index.d.ts +100 -0
  3. package/admin/index.js +94 -0
  4. package/angular/component.ts +284 -0
  5. package/angular/index.d.ts +80 -0
  6. package/angular/index.ts +24 -0
  7. package/headless/index.d.ts +65 -0
  8. package/headless/index.js +272 -0
  9. package/index.d.ts +1412 -0
  10. package/integrations/shared.d.ts +138 -0
  11. package/integrations/shared.js +5182 -0
  12. package/package.json +130 -0
  13. package/react/index.d.ts +104 -0
  14. package/react/index.js +310 -0
  15. package/richtexteditor/CHANGELOG.md +1876 -0
  16. package/richtexteditor/all_plugins.js +31125 -0
  17. package/richtexteditor/all_plugins.min.js +78 -0
  18. package/richtexteditor/lang/rte-lang-af.js +193 -0
  19. package/richtexteditor/lang/rte-lang-ar.js +193 -0
  20. package/richtexteditor/lang/rte-lang-bg.js +193 -0
  21. package/richtexteditor/lang/rte-lang-bn.js +193 -0
  22. package/richtexteditor/lang/rte-lang-bs.js +193 -0
  23. package/richtexteditor/lang/rte-lang-ca.js +193 -0
  24. package/richtexteditor/lang/rte-lang-cs.js +193 -0
  25. package/richtexteditor/lang/rte-lang-cy.js +193 -0
  26. package/richtexteditor/lang/rte-lang-da.js +193 -0
  27. package/richtexteditor/lang/rte-lang-de.js +193 -0
  28. package/richtexteditor/lang/rte-lang-el.js +193 -0
  29. package/richtexteditor/lang/rte-lang-en.js +6 -0
  30. package/richtexteditor/lang/rte-lang-es.js +193 -0
  31. package/richtexteditor/lang/rte-lang-et.js +193 -0
  32. package/richtexteditor/lang/rte-lang-fa.js +193 -0
  33. package/richtexteditor/lang/rte-lang-fi.js +193 -0
  34. package/richtexteditor/lang/rte-lang-fil.js +193 -0
  35. package/richtexteditor/lang/rte-lang-fj.js +193 -0
  36. package/richtexteditor/lang/rte-lang-fr.js +193 -0
  37. package/richtexteditor/lang/rte-lang-ga.js +193 -0
  38. package/richtexteditor/lang/rte-lang-gu.js +193 -0
  39. package/richtexteditor/lang/rte-lang-he.js +193 -0
  40. package/richtexteditor/lang/rte-lang-hi.js +193 -0
  41. package/richtexteditor/lang/rte-lang-hr.js +193 -0
  42. package/richtexteditor/lang/rte-lang-ht.js +193 -0
  43. package/richtexteditor/lang/rte-lang-hu.js +193 -0
  44. package/richtexteditor/lang/rte-lang-id.js +193 -0
  45. package/richtexteditor/lang/rte-lang-is.js +193 -0
  46. package/richtexteditor/lang/rte-lang-it.js +193 -0
  47. package/richtexteditor/lang/rte-lang-ja.js +193 -0
  48. package/richtexteditor/lang/rte-lang-kn.js +193 -0
  49. package/richtexteditor/lang/rte-lang-ko.js +193 -0
  50. package/richtexteditor/lang/rte-lang-lt.js +193 -0
  51. package/richtexteditor/lang/rte-lang-lv.js +193 -0
  52. package/richtexteditor/lang/rte-lang-mg.js +193 -0
  53. package/richtexteditor/lang/rte-lang-mi.js +193 -0
  54. package/richtexteditor/lang/rte-lang-ml.js +193 -0
  55. package/richtexteditor/lang/rte-lang-mr.js +193 -0
  56. package/richtexteditor/lang/rte-lang-ms.js +193 -0
  57. package/richtexteditor/lang/rte-lang-mt.js +193 -0
  58. package/richtexteditor/lang/rte-lang-mww.js +193 -0
  59. package/richtexteditor/lang/rte-lang-nb.js +193 -0
  60. package/richtexteditor/lang/rte-lang-nl.js +193 -0
  61. package/richtexteditor/lang/rte-lang-otq.js +193 -0
  62. package/richtexteditor/lang/rte-lang-pa.js +193 -0
  63. package/richtexteditor/lang/rte-lang-pl.js +193 -0
  64. package/richtexteditor/lang/rte-lang-pt-pt.js +193 -0
  65. package/richtexteditor/lang/rte-lang-pt.js +193 -0
  66. package/richtexteditor/lang/rte-lang-ro.js +193 -0
  67. package/richtexteditor/lang/rte-lang-ru.js +193 -0
  68. package/richtexteditor/lang/rte-lang-sk.js +193 -0
  69. package/richtexteditor/lang/rte-lang-sl.js +193 -0
  70. package/richtexteditor/lang/rte-lang-sm.js +193 -0
  71. package/richtexteditor/lang/rte-lang-sr-Cyrl.js +193 -0
  72. package/richtexteditor/lang/rte-lang-sr-Latn.js +193 -0
  73. package/richtexteditor/lang/rte-lang-sv.js +193 -0
  74. package/richtexteditor/lang/rte-lang-sw.js +193 -0
  75. package/richtexteditor/lang/rte-lang-ta.js +193 -0
  76. package/richtexteditor/lang/rte-lang-te.js +193 -0
  77. package/richtexteditor/lang/rte-lang-th.js +193 -0
  78. package/richtexteditor/lang/rte-lang-tlh-Latn.js +193 -0
  79. package/richtexteditor/lang/rte-lang-tlh-Piqd.js +193 -0
  80. package/richtexteditor/lang/rte-lang-to.js +193 -0
  81. package/richtexteditor/lang/rte-lang-tr.js +193 -0
  82. package/richtexteditor/lang/rte-lang-ty.js +193 -0
  83. package/richtexteditor/lang/rte-lang-uk.js +193 -0
  84. package/richtexteditor/lang/rte-lang-ur.js +193 -0
  85. package/richtexteditor/lang/rte-lang-vi.js +193 -0
  86. package/richtexteditor/lang/rte-lang-yua.js +193 -0
  87. package/richtexteditor/lang/rte-lang-zh-Hans.js +193 -0
  88. package/richtexteditor/lang/rte-lang-zh-Hant.js +193 -0
  89. package/richtexteditor/lang/rte-lang.js +1 -0
  90. package/richtexteditor/plugins/-combine-plugin.txt +2 -0
  91. package/richtexteditor/plugins/-combine-plugins.bat +20 -0
  92. package/richtexteditor/plugins/a11yenhance.js +90 -0
  93. package/richtexteditor/plugins/accessibilitychecker.js +579 -0
  94. package/richtexteditor/plugins/aitoolkit.css +15830 -0
  95. package/richtexteditor/plugins/aitoolkit.js +19171 -0
  96. package/richtexteditor/plugins/all_plugins.js +31125 -0
  97. package/richtexteditor/plugins/all_plugins.min.js +78 -0
  98. package/richtexteditor/plugins/autoembed.js +174 -0
  99. package/richtexteditor/plugins/blocktypes.js +175 -0
  100. package/richtexteditor/plugins/bookmarkcard.js +226 -0
  101. package/richtexteditor/plugins/charlimit.js +195 -0
  102. package/richtexteditor/plugins/comments.js +672 -0
  103. package/richtexteditor/plugins/contentminimap.js +369 -0
  104. package/richtexteditor/plugins/crdt-engine.js +8905 -0
  105. package/richtexteditor/plugins/crdt-engine.min.js +5 -0
  106. package/richtexteditor/plugins/dialoga11y.js +174 -0
  107. package/richtexteditor/plugins/dictation.js +268 -0
  108. package/richtexteditor/plugins/documentimport.js +369 -0
  109. package/richtexteditor/plugins/documentoutline.js +341 -0
  110. package/richtexteditor/plugins/emailtoolkit.js +165 -0
  111. package/richtexteditor/plugins/emojiautocomplete.js +241 -0
  112. package/richtexteditor/plugins/foldheadings.js +181 -0
  113. package/richtexteditor/plugins/ghostcomplete.js +297 -0
  114. package/richtexteditor/plugins/html2pdf.js +158 -0
  115. package/richtexteditor/plugins/imageeditor.js +159 -0
  116. package/richtexteditor/plugins/insertcode.js +319 -0
  117. package/richtexteditor/plugins/insertemoji.js +229 -0
  118. package/richtexteditor/plugins/insertgallery.js +362 -0
  119. package/richtexteditor/plugins/inserttemplate.js +261 -0
  120. package/richtexteditor/plugins/localdraft.js +213 -0
  121. package/richtexteditor/plugins/markdownexport.js +110 -0
  122. package/richtexteditor/plugins/mathdialog.js +153 -0
  123. package/richtexteditor/plugins/mentionplugin.js +534 -0
  124. package/richtexteditor/plugins/mermaiddiagram.js +294 -0
  125. package/richtexteditor/plugins/readabilitystats.js +148 -0
  126. package/richtexteditor/plugins/readaloud.js +243 -0
  127. package/richtexteditor/plugins/restrictedediting.js +208 -0
  128. package/richtexteditor/plugins/revisionhistory.js +670 -0
  129. package/richtexteditor/plugins/samples/insertcode_v1.js +76 -0
  130. package/richtexteditor/plugins/slashcommand.js +705 -0
  131. package/richtexteditor/plugins/smartchips.js +250 -0
  132. package/richtexteditor/plugins/spellcheck.js +181 -0
  133. package/richtexteditor/plugins/todolist.js +137 -0
  134. package/richtexteditor/plugins/trackedchanges.js +658 -0
  135. package/richtexteditor/plugins/tui.image-editor/fabric.min.js +8 -0
  136. package/richtexteditor/plugins/tui.image-editor/note.txt +5 -0
  137. package/richtexteditor/plugins/tui.image-editor/svg/icon-a.svg +235 -0
  138. package/richtexteditor/plugins/tui.image-editor/svg/icon-b.svg +224 -0
  139. package/richtexteditor/plugins/tui.image-editor/svg/icon-c.svg +224 -0
  140. package/richtexteditor/plugins/tui.image-editor/svg/icon-d.svg +224 -0
  141. package/richtexteditor/plugins/tui.image-editor/tui-code-snippet.min.js +7 -0
  142. package/richtexteditor/plugins/tui.image-editor/tui-color-picker.min.css +6 -0
  143. package/richtexteditor/plugins/tui.image-editor/tui-color-picker.min.js +7 -0
  144. package/richtexteditor/plugins/tui.image-editor/tui-image-editor.min.css +7 -0
  145. package/richtexteditor/plugins/tui.image-editor/tui-image-editor.min.js +15 -0
  146. package/richtexteditor/plugins/typewriter.js +203 -0
  147. package/richtexteditor/plugins/wordexport.js +0 -0
  148. package/richtexteditor/plugins/yjscollab.js +693 -0
  149. package/richtexteditor/plugins/zz_richtextbox_dialog_style.js +335 -0
  150. package/richtexteditor/rte-config.js +933 -0
  151. package/richtexteditor/rte.js +943 -0
  152. package/richtexteditor/rte_mobile.css +234 -0
  153. package/richtexteditor/rte_theme_default.css +4819 -0
  154. package/richtexteditor/runtime/colorpicker_more_ns.htm +2613 -0
  155. package/richtexteditor/runtime/help.htm +162 -0
  156. package/richtexteditor/runtime/images/1x1.gif +0 -0
  157. package/richtexteditor/runtime/images/cpie_Color.cur +0 -0
  158. package/richtexteditor/runtime/images/cpie_GradientPositionDark.gif +0 -0
  159. package/richtexteditor/runtime/images/cpie_GradientPositionLight.gif +0 -0
  160. package/richtexteditor/runtime/images/cpie_VerticalPosition.gif +0 -0
  161. package/richtexteditor/runtime/images/cpie_WebSafe.gif +0 -0
  162. package/richtexteditor/runtime/images/cpie_gradients.png +0 -0
  163. package/richtexteditor/runtime/images/cpns_Color.cur +0 -0
  164. package/richtexteditor/runtime/images/cpns_ColorSpace1.png +0 -0
  165. package/richtexteditor/runtime/images/cpns_ColorSpace2.png +0 -0
  166. package/richtexteditor/runtime/images/cpns_GradientPositionDark.gif +0 -0
  167. package/richtexteditor/runtime/images/cpns_GradientPositionLight.gif +0 -0
  168. package/richtexteditor/runtime/images/cpns_Vertical1.png +0 -0
  169. package/richtexteditor/runtime/images/cpns_Vertical2.png +0 -0
  170. package/richtexteditor/runtime/images/cpns_VerticalPosition.gif +0 -0
  171. package/richtexteditor/runtime/images/cpns_WebSafe.gif +0 -0
  172. package/richtexteditor/runtime/images/cpns_gradients.png +0 -0
  173. package/richtexteditor/runtime/images/cpns_hue2.png +0 -0
  174. package/richtexteditor/runtime/images/formbn.gif +0 -0
  175. package/richtexteditor/runtime/images/multiclavier.gif +0 -0
  176. package/richtexteditor/runtime/richtexteditor_content.css +362 -0
  177. package/richtexteditor/runtime/richtexteditor_preview.css +302 -0
  178. package/richtexteditor/runtime/richtexteditor_preview.js +1 -0
  179. package/server/index.d.ts +21 -0
  180. package/server/index.js +23 -0
  181. package/svelte/index.d.ts +19 -0
  182. package/svelte/index.js +59 -0
  183. package/vue/index.d.ts +94 -0
  184. package/vue/index.js +291 -0
@@ -0,0 +1,5 @@
1
+ "use strict";(()=>{var fr=Object.defineProperty,Ri=(e,t,r)=>t in e?fr(e,t,{enumerable:!0,configurable:!0,writable:!0,value:r}):e[t]=r,Fi=(e,t)=>{for(var r in t)fr(e,r,{get:t[r],enumerable:!0})},ue=(e,t,r)=>Ri(e,typeof t!="symbol"?t+"":t,r),dr={};Fi(dr,{BLOCK_TAGS:()=>ii,INLINE_MARK_TAGS:()=>si,LEAF_TAGS:()=>li,LOCAL_ORIGIN:()=>W,SUPPORTED_MARKS:()=>Xo,attachAwareness:()=>ga,attachCollab:()=>_a,attachCrdtBinding:()=>Ci,attachUndoManager:()=>fa,captureSelection:()=>di,classify:()=>Nt,htmlToYFragment:()=>ka,renderFragmentToHost:()=>ce,renderYNodeToDom:()=>Ze,restoreSelection:()=>gi});var W=Symbol.for("rte.crdt.local"),R=()=>new Map,fe=e=>{const t=R();return e.forEach((r,n)=>{t.set(n,r)}),t},et=(e,t,r)=>{let n=e.get(t);return n===void 0&&e.set(t,n=r()),n},Ui=(e,t)=>{const r=[];for(const[n,i]of e)r.push(t(i,n));return r},Bi=(e,t)=>{for(const[r,n]of e)if(t(n,r))return!0;return!1},rt=()=>new Set,de=e=>e[e.length-1],ji=(e,t)=>{for(let r=0;r<t.length;r++)e.push(t[r])},nt=Array.from,ge=(e,t)=>{for(let r=0;r<e.length;r++)if(!t(e[r],r,e))return!1;return!0},pe=(e,t)=>{for(let r=0;r<e.length;r++)if(t(e[r],r,e))return!0;return!1},Yi=(e,t)=>{const r=new Array(e);for(let n=0;n<e;n++)r[n]=t(n,r);return r},it=Array.isArray,gr=class{constructor(){this._observers=R()}on(e,t){return et(this._observers,e,rt).add(t),t}once(e,t){const r=(...n)=>{this.off(e,r),t(...n)};this.on(e,r)}off(e,t){const r=this._observers.get(e);r!==void 0&&(r.delete(t),r.size===0&&this._observers.delete(e))}emit(e,t){return nt((this._observers.get(e)||R()).values()).forEach(r=>r(...t))}destroy(){this._observers=R()}},Y=Math.floor,Dt=Math.abs,pr=(e,t)=>e<t?e:t,st=(e,t)=>e>t?e:t,Sa=Number.isNaN,Vi=e=>e!==0?e<0:1/e<0,vr=1,mr=2,ve=4,me=8,Pi=32,we=64,J=128,Hi=1<<17,Gi=1<<18,Xi=1<<19,zi=1<<20,Wi=1<<21,Ji=1<<22,Ki=1<<23,qi=1<<24,Zi=1<<25,Qi=1<<26,ts=1<<27,es=1<<28,rs=1<<29,ns=1<<30,Ea=1<<31,is=31,be=63,K=127,Ca=Hi-1,Ta=Gi-1,Aa=Xi-1,Ia=zi-1,Na=Wi-1,Da=Ji-1,Oa=Ki-1,xa=qi-1,La=Zi-1,Ma=Qi-1,$a=ts-1,Ra=es-1,Fa=rs-1,Ua=ns-1,ss=2147483647,Ot=Number.MAX_SAFE_INTEGER,wr=Number.MIN_SAFE_INTEGER,Ba=1<<31,ls=Number.isInteger||(e=>typeof e=="number"&&isFinite(e)&&Y(e)===e),ja=Number.isNaN,Ya=Number.parseInt,br=String.fromCharCode,Va=String.fromCodePoint,Pa=br(65535),os=e=>e.toLowerCase(),as=/^\s*/g,cs=e=>e.replace(as,""),hs=/([A-Z])/g,_r=(e,t)=>cs(e.replace(hs,r=>`${t}${os(r)}`)),us=e=>{const t=unescape(encodeURIComponent(e)),r=t.length,n=new Uint8Array(r);for(let i=0;i<r;i++)n[i]=t.codePointAt(i);return n},vt=typeof TextEncoder<"u"?new TextEncoder:null,fs=e=>vt.encode(e),ds=vt?fs:us,mt=typeof TextDecoder>"u"?null:new TextDecoder("utf-8",{fatal:!0,ignoreBOM:!0});mt&&mt.decode(new Uint8Array).length===1&&(mt=null);var gs=(e,t)=>Yi(t,()=>e).join(""),wt=class{constructor(){this.cpos=0,this.cbuf=new Uint8Array(100),this.bufs=[]}},xt=()=>new wt,ps=e=>{let t=e.cpos;for(let r=0;r<e.bufs.length;r++)t+=e.bufs[r].length;return t},F=e=>{const t=new Uint8Array(ps(e));let r=0;for(let n=0;n<e.bufs.length;n++){const i=e.bufs[n];t.set(i,r),r+=i.length}return t.set(new Uint8Array(e.cbuf.buffer,0,e.cpos),r),t},vs=(e,t)=>{const r=e.cbuf.length;r-e.cpos<t&&(e.bufs.push(new Uint8Array(e.cbuf.buffer,0,e.cpos)),e.cbuf=new Uint8Array(st(r,t)*2),e.cpos=0)},S=(e,t)=>{const r=e.cbuf.length;e.cpos===r&&(e.bufs.push(e.cbuf),e.cbuf=new Uint8Array(r*2),e.cpos=0),e.cbuf[e.cpos++]=t},bt=S,w=(e,t)=>{for(;t>K;)S(e,J|K&t),t=Y(t/128);S(e,K&t)},Lt=(e,t)=>{const r=Vi(t);for(r&&(t=-t),S(e,(t>be?J:0)|(r?we:0)|be&t),t=Y(t/64);t>0;)S(e,(t>K?J:0)|K&t),t=Y(t/128)},_e=new Uint8Array(3e4),ms=_e.length/3,ws=(e,t)=>{if(t.length<ms){const r=vt.encodeInto(t,_e).written||0;w(e,r);for(let n=0;n<r;n++)S(e,_e[n])}else x(e,ds(t))},bs=(e,t)=>{const r=unescape(encodeURIComponent(t)),n=r.length;w(e,n);for(let i=0;i<n;i++)S(e,r.codePointAt(i))},q=vt&&vt.encodeInto?ws:bs,ke=(e,t)=>{const r=e.cbuf.length,n=e.cpos,i=pr(r-n,t.length),s=t.length-i;e.cbuf.set(t.subarray(0,i),n),e.cpos+=i,s>0&&(e.bufs.push(e.cbuf),e.cbuf=new Uint8Array(st(r*2,s)),e.cbuf.set(t.subarray(i)),e.cpos=s)},x=(e,t)=>{w(e,t.byteLength),ke(e,t)},ye=(e,t)=>{vs(e,t);const r=new DataView(e.cbuf.buffer,e.cpos,t);return e.cpos+=t,r},_s=(e,t)=>ye(e,4).setFloat32(0,t,!1),ks=(e,t)=>ye(e,8).setFloat64(0,t,!1),ys=(e,t)=>ye(e,8).setBigInt64(0,t,!1),kr=new DataView(new ArrayBuffer(4)),Ss=e=>(kr.setFloat32(0,e),kr.getFloat32(0)===e),_t=(e,t)=>{switch(typeof t){case"string":S(e,119),q(e,t);break;case"number":ls(t)&&Dt(t)<=ss?(S(e,125),Lt(e,t)):Ss(t)?(S(e,124),_s(e,t)):(S(e,123),ks(e,t));break;case"bigint":S(e,122),ys(e,t);break;case"object":if(t===null)S(e,126);else if(it(t)){S(e,117),w(e,t.length);for(let r=0;r<t.length;r++)_t(e,t[r])}else if(t instanceof Uint8Array)S(e,116),x(e,t);else{S(e,118);const r=Object.keys(t);w(e,r.length);for(let n=0;n<r.length;n++){const i=r[n];q(e,i),_t(e,t[i])}}break;case"boolean":S(e,t?120:121);break;default:S(e,127)}},yr=class extends wt{constructor(e){super(),this.w=e,this.s=null,this.count=0}write(e){this.s===e?this.count++:(this.count>0&&w(this,this.count-1),this.count=1,this.w(this,e),this.s=e)}},Sr=e=>{e.count>0&&(Lt(e.encoder,e.count===1?e.s:-e.s),e.count>1&&w(e.encoder,e.count-2))},Mt=class{constructor(){this.encoder=new wt,this.s=0,this.count=0}write(e){this.s===e?this.count++:(Sr(this),this.count=1,this.s=e)}toUint8Array(){return Sr(this),F(this.encoder)}},Er=e=>{if(e.count>0){const t=e.diff*2+(e.count===1?0:1);Lt(e.encoder,t),e.count>1&&w(e.encoder,e.count-2)}},Se=class{constructor(){this.encoder=new wt,this.s=0,this.count=0,this.diff=0}write(e){this.diff===e-this.s?(this.s=e,this.count++):(Er(this),this.count=1,this.diff=e-this.s,this.s=e)}toUint8Array(){return Er(this),F(this.encoder)}},Es=class{constructor(){this.sarr=[],this.s="",this.lensE=new Mt}write(e){this.s+=e,this.s.length>19&&(this.sarr.push(this.s),this.s=""),this.lensE.write(e.length)}toUint8Array(){const e=new wt;return this.sarr.push(this.s),this.s="",q(e,this.sarr.join("")),ke(e,this.lensE.toUint8Array()),F(e)}},U=e=>new Error(e),L=()=>{throw U("Method unimplemented")},M=()=>{throw U("Unexpected case")},Cr=U("Unexpected end of array"),Tr=U("Integer out of Range"),Cs=class{constructor(e){this.arr=e,this.pos=0}},Ts=e=>new Cs(e),As=e=>e.pos!==e.arr.length,Is=(e,t)=>{const r=new Uint8Array(e.arr.buffer,e.pos+e.arr.byteOffset,t);return e.pos+=t,r},Ns=e=>Is(e,kt(e)),Ar=e=>e.arr[e.pos++],kt=e=>{let t=0,r=1;const n=e.arr.length;for(;e.pos<n;){const i=e.arr[e.pos++];if(t=t+(i&K)*r,r*=128,i<J)return t;if(t>Ot)throw Tr}throw Cr},Ds=e=>{let t=e.arr[e.pos++],r=t&be,n=64;const i=(t&we)>0?-1:1;if((t&J)===0)return i*r;const s=e.arr.length;for(;e.pos<s;){if(t=e.arr[e.pos++],r=r+(t&K)*n,n*=128,t<J)return i*r;if(r>Ot)throw Tr}throw Cr},Os=e=>{let t=kt(e);if(t===0)return"";{let r=String.fromCodePoint(Ar(e));if(--t<100)for(;t--;)r+=String.fromCodePoint(Ar(e));else for(;t>0;){const n=t<1e4?t:1e4,i=e.arr.subarray(e.pos,e.pos+n);e.pos+=n,r+=String.fromCodePoint.apply(null,i),t-=n}return decodeURIComponent(escape(r))}},xs=e=>mt.decode(Ns(e)),Ls=mt?xs:Os,Ha=crypto.subtle,Ms=crypto.getRandomValues.bind(crypto),Ir=()=>Ms(new Uint32Array(1))[0],$s="10000000-1000-4000-8000"+-1e11,Rs=()=>$s.replace(/[018]/g,e=>(e^Ir()&15>>e/4).toString(16)),Nr=Date.now,Dr=e=>new Promise(e),Ga=Promise.all.bind(Promise),Or=e=>e===void 0?null:e,Fs=class{constructor(){this.map=new Map}setItem(e,t){this.map.set(e,t)}getItem(e){return this.map.get(e)}},xr=new Fs,Us=!0;try{typeof localStorage<"u"&&localStorage&&(xr=localStorage,Us=!1)}catch{}var Bs=xr,yt=Symbol("Equality"),Lr=(e,t)=>{var r;return e===t||!!((r=e?.[yt])!=null&&r.call(e,t))||!1},js=e=>typeof e=="object",Ys=Object.assign,Vs=Object.keys,Ps=(e,t)=>{for(const r in e)t(e[r],r)},$t=e=>Vs(e).length,Hs=e=>{for(const t in e)return!1;return!0},St=(e,t)=>{for(const r in e)if(!t(e[r],r))return!1;return!0},Ee=(e,t)=>Object.prototype.hasOwnProperty.call(e,t),Gs=(e,t)=>e===t||$t(e)===$t(t)&&St(e,(r,n)=>(r!==void 0||Ee(t,n))&&Lr(t[n],r)),Xs=Object.freeze,Mr=e=>{for(const t in e){const r=e[t];(typeof r=="object"||typeof r=="function")&&Mr(e[t])}return Xs(e)},Ce=(e,t,r=0)=>{try{for(;r<e.length;r++)e[r](...t)}finally{r<e.length&&Ce(e,t,r+1)}},Rt=(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[yt]!=null)return e[yt](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 r=0;r<e.length;r++)if(e[r]!==t[r])return!1;break}case Set:{if(e.size!==t.size)return!1;for(const r of e)if(!t.has(r))return!1;break}case Map:{if(e.size!==t.size)return!1;for(const r of e.keys())if(!t.has(r)||!Rt(e.get(r),t.get(r)))return!1;break}case void 0:case Object:if($t(e)!==$t(t))return!1;for(const r in e)if(!Ee(e,r)||!Rt(e[r],t[r]))return!1;break;case Array:if(e.length!==t.length)return!1;for(let r=0;r<e.length;r++)if(!Rt(e[r],t[r]))return!1;break;default:return!1}return!0},zs=(e,t)=>t.includes(e),Et=typeof process<"u"&&process.release&&/node|io\.js/.test(process.release.name)&&Object.prototype.toString.call(typeof process<"u"?process:0)==="[object process]",Xa=typeof navigator<"u"?/Mac/.test(navigator.platform):!1,B,Ws=[],Js=()=>{if(B===void 0)if(Et){B=R();const e=process.argv;let t=null;for(let r=0;r<e.length;r++){const n=e[r];n[0]==="-"?(t!==null&&B.set(t,""),t=n):t!==null?(B.set(t,n),t=null):Ws.push(n)}t!==null&&B.set(t,"")}else typeof location=="object"?(B=R(),(location.search||"?").slice(1).split("&").forEach(e=>{if(e.length!==0){const[t,r]=e.split("=");B.set(`--${_r(t,"-")}`,r),B.set(`-${_r(t,"-")}`,r)}})):B=R();return B},Te=e=>Js().has(e),Ft=e=>Or(Et?process.env[e.toUpperCase().replaceAll("-","_")]:Bs.getItem(e)),$r=e=>Te("--"+e)||Ft(e)!==null,Ks=$r("production"),qs=Et&&zs(process.env.FORCE_COLOR,["true","1","2"]),Zs=qs||!Te("--no-colors")&&!$r("no-color")&&(!Et||process.stdout.isTTY)&&(!Et||Te("--color")||Ft("COLORTERM")!==null||(Ft("TERM")||"").includes("color")),Qs=class{constructor(e,t){this.left=e,this.right=t}},V=(e,t)=>new Qs(e,t),Rr=e=>e.next()>=.5,Ae=(e,t,r)=>Y(e.next()*(r+1-t)+t),Fr=(e,t,r)=>Y(e.next()*(r+1-t)+t),Ie=(e,t,r)=>Fr(e,t,r),tl=e=>br(Ie(e,97,122)),el=(e,t=0,r=20)=>{const n=Ie(e,t,r);let i="";for(let s=0;s<n;s++)i+=tl(e);return i},Ne=(e,t)=>t[Ie(e,0,t.length-1)],rl=Symbol("0schema"),nl=class{constructor(){this._rerrs=[]}extend(e,t,r,n=null){this._rerrs.push({path:e,expected:t,has:r,message:n})}toString(){const e=[];for(let t=this._rerrs.length-1;t>0;t--){const r=this._rerrs[t];e.push(gs(" ",(this._rerrs.length-t)*2)+`${r.path!=null?`[${r.path}] `:""}${r.has} doesn't match ${r.expected}. ${r.message}`)}return e.join(`
2
+ `)}},De=(e,t)=>e===t?!0:e==null||t==null||e.constructor!==t.constructor?!1:e[yt]?Lr(e,t):it(e)?ge(e,r=>pe(t,n=>De(r,n))):js(e)?St(e,(r,n)=>De(r,t[n])):!1,A=class{extends(e){let[t,r]=[this.shape,e.shape];return this.constructor._dilutes&&([r,t]=[t,r]),De(t,r)}equals(e){return this.constructor===e.constructor&&Rt(this.shape,e.shape)}[rl](){return!0}[yt](e){return this.equals(e)}validate(e){return this.check(e)}check(e,t){L()}get nullable(){return lt(this,Ht)}get optional(){return new jr(this)}cast(e){return en(e,this),e}expect(e){return en(e,this),e}};ue(A,"_dilutes",!1);var Oe=class extends A{constructor(e,t){super(),this.shape=e,this._c=t}check(e,t=void 0){const r=e?.constructor===this.shape&&(this._c==null||this._c(e));return!r&&t?.extend(null,this.shape.name,e?.constructor.name,e?.constructor!==this.shape?"Constructor match failed":"Check failed"),r}},y=(e,t=null)=>new Oe(e,t),za=y(Oe),xe=class extends A{constructor(e){super(),this.shape=e}check(e,t){const r=this.shape(e);return!r&&t?.extend(null,"custom prop",e?.constructor.name,"failed to check custom prop"),r}},E=e=>new xe(e),Wa=y(xe),Ut=class extends A{constructor(e){super(),this.shape=e}check(e,t){const r=this.shape.some(n=>n===e);return!r&&t?.extend(null,this.shape.join(" | "),e.toString()),r}},Bt=(...e)=>new Ut(e),Ur=y(Ut),il=RegExp.escape||(e=>e.replace(/[().|&,$^[\]]/g,t=>"\\"+t)),Br=e=>{if(at.check(e))return[il(e)];if(Ur.check(e))return e.shape.map(t=>t+"");if(Zr.check(e))return["[+-]?\\d+.?\\d*"];if(Qr.check(e))return[".*"];if(Yt.check(e))return e.shape.map(Br).flat(1);M()},sl=class extends A{constructor(e){super(),this.shape=e,this._r=new RegExp("^"+e.map(Br).map(t=>`(${t.join("|")})`).join("")+"$")}check(e,t){const r=this._r.exec(e)!=null;return!r&&t?.extend(null,this._r.toString(),e.toString(),"String doesn't match string template."),r}},Ja=y(sl),ll=Symbol("optional"),jr=class extends A{constructor(e){super(),this.shape=e}check(e,t){const r=e===void 0||this.shape.check(e);return!r&&t?.extend(null,"undefined (optional)","()"),r}get[ll](){return!0}},ol=y(jr),Yr=class extends A{check(e,t){return t?.extend(null,"never",typeof e),!1}},Ka=new Yr,qa=y(Yr),Vr=class Ni extends A{constructor(t,r=!1){super(),this.shape=t,this._isPartial=r}get partial(){return new Ni(this.shape,!0)}check(t,r){return t==null?(r?.extend(null,"object","null"),!1):St(this.shape,(n,i)=>{const s=this._isPartial&&!Ee(t,i)||n.check(t[i],r);return!s&&r?.extend(i.toString(),n.toString(),typeof t[i],"Object property does not match"),s})}};ue(Vr,"_dilutes",!0);var Pr=Vr,al=e=>new Pr(e),cl=y(Pr),hl=E(e=>e!=null&&(e.constructor===Object||e.constructor==null)),Hr=class extends A{constructor(e,t){super(),this.shape={keys:e,values:t}}check(e,t){return e!=null&&St(e,(r,n)=>{const i=this.shape.keys.check(n,t);return!i&&t?.extend(n+"","Record",typeof e,i?"Key doesn't match schema":"Value doesn't match value"),i&&this.shape.values.check(r,t)})}},Gr=(e,t)=>new Hr(e,t),ul=y(Hr),Xr=class extends A{constructor(e){super(),this.shape=e}check(e,t){return e!=null&&St(this.shape,(r,n)=>{const i=r.check(e[n],t);return!i&&t?.extend(n.toString(),"Tuple",typeof r),i})}},fl=(...e)=>new Xr(e),Za=y(Xr),zr=class extends A{constructor(e){super(),this.shape=e.length===1?e[0]:new jt(e)}check(e,t){const r=it(e)&&ge(e,n=>this.shape.check(n));return!r&&t?.extend(null,"Array",""),r}},Wr=(...e)=>new zr(e),dl=y(zr),gl=E(e=>it(e)),Jr=class extends A{constructor(e,t){super(),this.shape=e,this._c=t}check(e,t){const r=e instanceof this.shape&&(this._c==null||this._c(e));return!r&&t?.extend(null,this.shape.name,e?.constructor.name),r}},pl=(e,t=null)=>new Jr(e,t),Qa=y(Jr),vl=pl(A),ml=class extends A{constructor(e){super(),this.len=e.length-1,this.args=fl(...e.slice(-1)),this.res=e[this.len]}check(e,t){const r=e.constructor===Function&&e.length<=this.len;return!r&&t?.extend(null,"function",typeof e),r}},wl=y(ml),bl=E(e=>typeof e=="function"),_l=class extends A{constructor(e){super(),this.shape=e}check(e,t){const r=ge(this.shape,n=>n.check(e,t));return!r&&t?.extend(null,"Intersectinon",typeof e),r}},tc=y(_l,e=>e.shape.length>0),jt=class extends A{constructor(e){super(),this.shape=e}check(e,t){const r=pe(this.shape,n=>n.check(e,t));return t?.extend(null,"Union",typeof e),r}};ue(jt,"_dilutes",!0);var lt=(...e)=>e.findIndex(t=>Yt.check(t))>=0?lt(...e.map(t=>Ct(t)).map(t=>Yt.check(t)?t.shape:[t]).flat(1)):e.length===1?e[0]:new jt(e),Yt=y(jt),Kr=()=>!0,Vt=E(Kr),kl=y(xe,e=>e.shape===Kr),Le=E(e=>typeof e=="bigint"),yl=E(e=>e===Le),qr=E(e=>typeof e=="symbol"),ec=E(e=>e===qr),ot=E(e=>typeof e=="number"),Zr=E(e=>e===ot),at=E(e=>typeof e=="string"),Qr=E(e=>e===at),Pt=E(e=>typeof e=="boolean"),Sl=E(e=>e===Pt),tn=Bt(void 0),rc=y(Ut,e=>e.shape.length===1&&e.shape[0]===void 0),nc=Bt(void 0),Ht=Bt(null),El=y(Ut,e=>e.shape.length===1&&e.shape[0]===null),ic=y(Uint8Array),sc=y(Oe,e=>e.shape===Uint8Array),Cl=lt(ot,at,Ht,tn,Le,Pt,qr),lc=(()=>{const e=Wr(Vt),t=Gr(at,Vt),r=lt(ot,at,Ht,Pt,e,t);return e.shape=r,t.shape.values=r,r})(),Ct=e=>{if(vl.check(e))return e;if(hl.check(e)){const t={};for(const r in e)t[r]=Ct(e[r]);return al(t)}else{if(gl.check(e))return lt(...e.map(Ct));if(Cl.check(e))return Bt(e);if(bl.check(e))return y(e)}M()},en=Ks?()=>{}:(e,t)=>{const r=new nl;if(!t.check(e,r))throw U(`Expected value to be of type ${t.constructor.name}.
3
+ ${r.toString()}`)},Tl=class{constructor(e){this.patterns=[],this.$state=e}if(e,t){return this.patterns.push({if:Ct(e),h:t}),this}else(e){return this.if(Vt,e)}done(){return((e,t)=>{for(let r=0;r<this.patterns.length;r++){const n=this.patterns[r];if(n.if.check(e))return n.h(e,t)}throw U("Unhandled pattern")})}},Al=e=>new Tl(e),rn=Al(Vt).if(Zr,(e,t)=>Ae(t,wr,Ot)).if(Qr,(e,t)=>el(t)).if(Sl,(e,t)=>Rr(t)).if(yl,(e,t)=>BigInt(Ae(t,wr,Ot))).if(Yt,(e,t)=>ct(t,Ne(t,e.shape))).if(cl,(e,t)=>{const r={};for(const n in e.shape){let i=e.shape[n];if(ol.check(i)){if(Rr(t))continue;i=i.shape}r[n]=rn(i,t)}return r}).if(dl,(e,t)=>{const r=[],n=Fr(t,0,42);for(let i=0;i<n;i++)r.push(ct(t,e.shape));return r}).if(Ur,(e,t)=>Ne(t,e.shape)).if(El,(e,t)=>null).if(wl,(e,t)=>{const r=ct(t,e.res);return()=>r}).if(kl,(e,t)=>ct(t,Ne(t,[ot,at,Ht,tn,Le,Pt,Wr(ot),Gr(lt("a","b","c"),ot)]))).if(ul,(e,t)=>{const r={},n=Ae(t,0,3);for(let i=0;i<n;i++){const s=ct(t,e.shape.keys),l=ct(t,e.shape.values);r[s]=l}return r}).done(),ct=(e,t)=>rn(Ct(t),e),Z=typeof document<"u"?document:{},oc=E(e=>e.nodeType===xl),ac=typeof DOMParser<"u"?new DOMParser:null,cc=E(e=>e.nodeType===Nl),hc=E(e=>e.nodeType===Dl),Il=e=>Ui(e,(t,r)=>`${r}:${t};`).join(""),Nl=Z.ELEMENT_NODE,Dl=Z.TEXT_NODE,uc=Z.CDATA_SECTION_NODE,fc=Z.COMMENT_NODE,Ol=Z.DOCUMENT_NODE,dc=Z.DOCUMENT_TYPE_NODE,xl=Z.DOCUMENT_FRAGMENT_NODE,gc=E(e=>e.nodeType===Ol),P=Symbol,nn=P(),sn=P(),Ll=P(),Ml=P(),$l=P(),ln=P(),Rl=P(),Me=P(),Fl=P(),Ul=e=>{var t;e.length===1&&((t=e[0])==null?void 0:t.constructor)===Function&&(e=e[0]());const r=[],n=[];let i=0;for(;i<e.length;i++){const s=e[i];if(s===void 0)break;if(s.constructor===String||s.constructor===Number)r.push(s);else if(s.constructor===Object)break}for(i>0&&n.push(r.join(""));i<e.length;i++){const s=e[i];s instanceof Symbol||n.push(s)}return n},pc=Nr(),Bl={[nn]:V("font-weight","bold"),[sn]:V("font-weight","normal"),[Ll]:V("color","blue"),[$l]:V("color","green"),[Ml]:V("color","grey"),[ln]:V("color","red"),[Rl]:V("color","purple"),[Me]:V("color","orange"),[Fl]:V("color","black")},jl=e=>{var t;e.length===1&&((t=e[0])==null?void 0:t.constructor)===Function&&(e=e[0]());const r=[],n=[],i=R();let s=[],l=0;for(;l<e.length;l++){const o=e[l],a=Bl[o];if(a!==void 0)i.set(a.left,a.right);else{if(o===void 0)break;if(o.constructor===String||o.constructor===Number){const c=Il(i);l>0||c.length>0?(r.push("%c"+o),n.push(c)):r.push(o)}else break}}for(l>0&&(s=n,s.unshift(r.join("")));l<e.length;l++){const o=e[l];o instanceof Symbol||s.push(o)}return s},on=Zs?jl:Ul,Yl=(...e)=>{console.log(...on(e)),cn.forEach(t=>t.print(e))},an=(...e)=>{console.warn(...on(e)),e.unshift(Me),cn.forEach(t=>t.print(e))},cn=rt(),hn=e=>({[Symbol.iterator](){return this},next:e}),Vl=(e,t)=>hn(()=>{let r;do r=e.next();while(!r.done&&!t(r.value));return r}),$e=(e,t)=>hn(()=>{const{done:r,value:n}=e.next();return{done:r,value:r?void 0:t(n)}}),un=class{constructor(e,t){this.clock=e,this.len=t}},Gt=class{constructor(){this.clients=new Map}},ht=(e,t,r)=>t.clients.forEach((n,i)=>{const s=e.doc.store.clients.get(i);if(s!=null){const l=s[s.length-1],o=l.id.clock+l.length;for(let a=0,c=n[a];a<n.length&&c.clock<o;c=n[++a])En(e,s,c.clock,c.len,r)}}),Pl=(e,t)=>{let r=0,n=e.length-1;for(;r<=n;){const i=Y((r+n)/2),s=e[i],l=s.clock;if(l<=t){if(t<l+s.len)return i;r=i+1}else n=i-1}return null},Tt=(e,t)=>{const r=e.clients.get(t.client);return r!==void 0&&Pl(r,t.clock)!==null},Re=e=>{e.clients.forEach(t=>{t.sort((i,s)=>i.clock-s.clock);let r,n;for(r=1,n=1;r<t.length;r++){const i=t[n-1],s=t[r];i.clock+i.len>=s.clock?t[n-1]=new un(i.clock,st(i.len,s.clock+s.len-i.clock)):(n<r&&(t[n]=s),n++)}t.length=n})},fn=e=>{const t=new Gt;for(let r=0;r<e.length;r++)e[r].clients.forEach((n,i)=>{if(!t.clients.has(i)){const s=n.slice();for(let l=r+1;l<e.length;l++)ji(s,e[l].clients.get(i)||[]);t.clients.set(i,s)}});return Re(t),t},Fe=(e,t,r,n)=>{et(e.clients,t,()=>[]).push(new un(r,n))},Hl=()=>new Gt,Gl=(e,t)=>{w(e.restEncoder,t.clients.size),nt(t.clients.entries()).sort((r,n)=>n[0]-r[0]).forEach(([r,n])=>{e.resetDsCurVal(),w(e.restEncoder,r);const i=n.length;w(e.restEncoder,i);for(let s=0;s<i;s++){const l=n[s];e.writeDsClock(l.clock),e.writeDsLen(l.len)}})},dn=Ir,Xt=class Di extends gr{constructor({guid:t=Rs(),collectionid:r=null,gc:n=!0,gcFilter:i=()=>!0,meta:s=null,autoLoad:l=!1,shouldLoad:o=!0}={}){super(),this.gc=n,this.gcFilter=i,this.clientID=dn(),this.guid=t,this.collectionid=r,this.share=new Map,this.store=new uo,this._transaction=null,this._transactionCleanups=[],this.subdocs=new Set,this._item=null,this.shouldLoad=o,this.autoLoad=l,this.meta=s,this.isLoaded=!1,this.isSynced=!1,this.isDestroyed=!1,this.whenLoaded=Dr(c=>{this.on("load",()=>{this.isLoaded=!0,c(this)})});const a=()=>Dr(c=>{const h=u=>{(u===void 0||u===!0)&&(this.off("sync",h),c())};this.on("sync",h)});this.on("sync",c=>{c===!1&&this.isSynced&&(this.whenSynced=a()),this.isSynced=c===void 0||c===!0,this.isSynced&&!this.isLoaded&&this.emit("load",[this])}),this.whenSynced=a()}load(){const t=this._item;t!==null&&!this.shouldLoad&&_(t.parent.doc,r=>{r.subdocsLoaded.add(this)},null,!0),this.shouldLoad=!0}getSubdocs(){return this.subdocs}getSubdocGuids(){return new Set(nt(this.subdocs).map(t=>t.guid))}transact(t,r=null){return _(this,t,r)}get(t,r=C){const n=et(this.share,t,()=>{const s=new r;return s._integrate(this,null),s}),i=n.constructor;if(r!==C&&i!==r)if(i===C){const s=new r;s._map=n._map,n._map.forEach(l=>{for(;l!==null;l=l.left)l.parent=s}),s._start=n._start;for(let l=s._start;l!==null;l=l.right)l.parent=s;return s._length=n._length,this.share.set(t,s),s._integrate(this,null),s}else throw new Error(`Type with the name ${t} has already been defined with a different constructor`);return n}getArray(t=""){return this.get(t,Io)}getText(t=""){return this.get(t,Jn)}getMap(t=""){return this.get(t,Do)}getXmlElement(t=""){return this.get(t,gt)}getXmlFragment(t=""){return this.get(t,se)}toJSON(){const t={};return this.share.forEach((r,n)=>{t[n]=r.toJSON()}),t}destroy(){this.isDestroyed=!0,nt(this.subdocs).forEach(r=>r.destroy());const t=this._item;if(t!==null){this._item=null;const r=t.content;r.doc=new Di({guid:this.guid,...r.opts,shouldLoad:!1}),r.doc._item=t,_(t.parent.doc,n=>{const i=r.doc;t.deleted||n.subdocsAdded.add(i),n.subdocsRemoved.add(this)},null,!0)}this.emit("destroyed",[!0]),this.emit("destroy",[this]),super.destroy()}},Xl=class{constructor(){this.restEncoder=xt()}toUint8Array(){return F(this.restEncoder)}resetDsCurVal(){}writeDsClock(e){w(this.restEncoder,e)}writeDsLen(e){w(this.restEncoder,e)}},zl=class extends Xl{writeLeftID(e){w(this.restEncoder,e.client),w(this.restEncoder,e.clock)}writeRightID(e){w(this.restEncoder,e.client),w(this.restEncoder,e.clock)}writeClient(e){w(this.restEncoder,e)}writeInfo(e){bt(this.restEncoder,e)}writeString(e){q(this.restEncoder,e)}writeParentInfo(e){w(this.restEncoder,e?1:0)}writeTypeRef(e){w(this.restEncoder,e)}writeLen(e){w(this.restEncoder,e)}writeAny(e){_t(this.restEncoder,e)}writeBuf(e){x(this.restEncoder,e)}writeJSON(e){q(this.restEncoder,JSON.stringify(e))}writeKey(e){q(this.restEncoder,e)}},Wl=class{constructor(){this.restEncoder=xt(),this.dsCurrVal=0}toUint8Array(){return F(this.restEncoder)}resetDsCurVal(){this.dsCurrVal=0}writeDsClock(e){const t=e-this.dsCurrVal;this.dsCurrVal=e,w(this.restEncoder,t)}writeDsLen(e){e===0&&M(),w(this.restEncoder,e-1),this.dsCurrVal+=e}},Jl=class extends Wl{constructor(){super(),this.keyMap=new Map,this.keyClock=0,this.keyClockEncoder=new Se,this.clientEncoder=new Mt,this.leftClockEncoder=new Se,this.rightClockEncoder=new Se,this.infoEncoder=new yr(bt),this.stringEncoder=new Es,this.parentInfoEncoder=new yr(bt),this.typeRefEncoder=new Mt,this.lenEncoder=new Mt}toUint8Array(){const e=xt();return w(e,0),x(e,this.keyClockEncoder.toUint8Array()),x(e,this.clientEncoder.toUint8Array()),x(e,this.leftClockEncoder.toUint8Array()),x(e,this.rightClockEncoder.toUint8Array()),x(e,F(this.infoEncoder)),x(e,this.stringEncoder.toUint8Array()),x(e,F(this.parentInfoEncoder)),x(e,this.typeRefEncoder.toUint8Array()),x(e,this.lenEncoder.toUint8Array()),ke(e,F(this.restEncoder)),F(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?1:0)}writeTypeRef(e){this.typeRefEncoder.write(e)}writeLen(e){this.lenEncoder.write(e)}writeAny(e){_t(this.restEncoder,e)}writeBuf(e){x(this.restEncoder,e)}writeJSON(e){_t(this.restEncoder,e)}writeKey(e){const t=this.keyMap.get(e);t===void 0?(this.keyClockEncoder.write(this.keyClock++),this.stringEncoder.write(e)):this.keyClockEncoder.write(t)}},Kl=(e,t,r,n)=>{n=st(n,t[0].id.clock);const i=H(t,n);w(e.restEncoder,t.length-i),e.writeClient(r),w(e.restEncoder,n);const s=t[i];s.write(e,n-s.id.clock);for(let l=i+1;l<t.length;l++)t[l].write(e,0)},ql=(e,t,r)=>{const n=new Map;r.forEach((i,s)=>{T(t,s)>i&&n.set(s,i)}),Be(t).forEach((i,s)=>{r.has(s)||n.set(s,0)}),w(e.restEncoder,n.size),nt(n.entries()).sort((i,s)=>s[0]-i[0]).forEach(([i,s])=>{Kl(e,t.clients.get(i),i,s)})},Zl=(e,t)=>ql(e,t.doc.store,t.beforeState),Ql=class{constructor(){this.l=[]}},gn=()=>new Ql,pn=(e,t)=>e.l.push(t),vn=(e,t)=>{const r=e.l,n=r.length;e.l=r.filter(i=>t!==i),n===e.l.length&&console.error("[yjs] Tried to remove event handler that doesn't exist.")},mn=(e,t,r)=>Ce(e.l,[t,r]),zt=class{constructor(e,t){this.client=e,this.clock=t}},Wt=(e,t)=>e===t||e!==null&&t!==null&&e.client===t.client&&e.clock===t.clock,b=(e,t)=>new zt(e,t),wn=(e,t)=>{w(e,t.client),w(e,t.clock)},bn=e=>b(kt(e),kt(e)),_n=e=>{for(const[t,r]of e.doc.share.entries())if(r===e)return t;throw M()},Jt=(e,t)=>{for(;t!==null;){if(t.parent===e)return!0;t=t.parent._item}return!1},kn=class{constructor(e,t,r,n=0){this.type=e,this.tname=t,this.item=r,this.assoc=n}},to=class{constructor(e,t,r=0){this.type=e,this.index=t,this.assoc=r}},eo=(e,t,r=0)=>new to(e,t,r),Kt=(e,t,r)=>{let n=null,i=null;return e._item===null?i=_n(e):n=b(e._item.id.client,e._item.id.clock),new kn(n,i,t,r)},ro=(e,t,r=0)=>{let n=e._start;if(r<0){if(t===0)return Kt(e,null,r);t--}for(;n!==null;){if(!n.deleted&&n.countable){if(n.length>t)return Kt(e,b(n.id.client,n.id.clock+t),r);t-=n.length}if(n.right===null&&r<0)return Kt(e,n.lastId,r);n=n.right}return Kt(e,null,r)},no=(e,t)=>{const{type:r,tname:n,item:i,assoc:s}=t;if(i!==null)w(e,0),wn(e,i);else if(n!==null)bt(e,1),q(e,n);else if(r!==null)bt(e,2),wn(e,r);else throw M();return Lt(e,s),e},io=e=>{const t=xt();return no(t,e),F(t)},so=e=>{let t=null,r=null,n=null;switch(kt(e)){case 0:n=bn(e);break;case 1:r=Ls(e);break;case 2:t=bn(e)}const i=As(e)?Ds(e):0;return new kn(t,r,n,i)},lo=e=>so(Ts(e)),oo=(e,t)=>{const r=ft(e,t),n=t.clock-r.id.clock;return{item:r,diff:n}},ao=(e,t,r=!0)=>{const n=t.store,i=e.item,s=e.type,l=e.tname,o=e.assoc;let a=null,c=0;if(i!==null){if(T(n,i.client)<=i.clock)return null;const h=r?We(n,i):oo(n,i),u=h.item;if(!(u instanceof k))return null;if(a=u.parent,a._item===null||!a._item.deleted){c=u.deleted||!u.countable?0:h.diff+(o>=0?0:1);let f=u.left;for(;f!==null;)!f.deleted&&f.countable&&(c+=f.length),f=f.left}}else{if(l!==null)a=t.get(l);else if(s!==null){if(T(n,s.client)<=s.clock)return null;const{item:h}=r?We(n,s):{item:ft(n,s)};if(h instanceof k&&h.content instanceof Q)a=h.content.type;else return null}else throw M();o>=0?c=a._length:c=0}return eo(a,c,e.assoc)},co=class{constructor(e,t){this.ds=e,this.sv=t}},ho=(e,t)=>new co(e,t),vc=ho(Hl(),new Map),ut=(e,t)=>t===void 0?!e.deleted:t.sv.has(e.id.client)&&(t.sv.get(e.id.client)||0)>e.id.clock&&!Tt(t.ds,e.id),Ue=(e,t)=>{const r=et(e.meta,Ue,rt),n=e.doc.store;r.has(t)||(t.sv.forEach((i,s)=>{i<T(n,s)&&O(e,b(s,i))}),ht(e,t.ds,i=>{}),r.add(t))},uo=class{constructor(){this.clients=new Map,this.pendingStructs=null,this.pendingDs=null}},Be=e=>{const t=new Map;return e.clients.forEach((r,n)=>{const i=r[r.length-1];t.set(n,i.id.clock+i.length)}),t},T=(e,t)=>{const r=e.clients.get(t);if(r===void 0)return 0;const n=r[r.length-1];return n.id.clock+n.length},yn=(e,t)=>{let r=e.clients.get(t.id.client);if(r===void 0)r=[],e.clients.set(t.id.client,r);else{const n=r[r.length-1];if(n.id.clock+n.length!==t.id.clock)throw M()}r.push(t)},H=(e,t)=>{let r=0,n=e.length-1,i=e[n],s=i.id.clock;if(s===t)return n;let l=Y(t/(s+i.length-1)*n);for(;r<=n;){if(i=e[l],s=i.id.clock,s<=t){if(t<s+i.length)return l;r=l+1}else n=l-1;l=Y((r+n)/2)}throw M()},fo=(e,t)=>{const r=e.clients.get(t.client);return r[H(r,t.clock)]},ft=fo,je=(e,t,r)=>{const n=H(t,r),i=t[n];return i.id.clock<r&&i instanceof k?(t.splice(n+1,0,Qn(e,i,r-i.id.clock)),n+1):n},O=(e,t)=>{const r=e.doc.store.clients.get(t.client);return r[je(e,r,t.clock)]},Sn=(e,t,r)=>{const n=t.clients.get(r.client),i=H(n,r.clock),s=n[i];return r.clock!==s.id.clock+s.length-1&&s.constructor!==X&&n.splice(i+1,0,Qn(e,s,r.clock-s.id.clock+1)),s},go=(e,t,r)=>{const n=e.clients.get(t.id.client);n[H(n,t.id.clock)]=r},En=(e,t,r,n,i)=>{if(n===0)return;const s=r+n;let l=je(e,t,r),o;do o=t[l++],s<o.id.clock+o.length&&je(e,t,s),i(o);while(l<t.length&&t[l].id.clock<s)},po=class{constructor(e,t,r){this.doc=e,this.deleteSet=new Gt,this.beforeState=Be(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=r,this.subdocsAdded=new Set,this.subdocsRemoved=new Set,this.subdocsLoaded=new Set,this._needFormattingCleanup=!1}},Cn=(e,t)=>t.deleteSet.clients.size===0&&!Bi(t.afterState,(r,n)=>t.beforeState.get(n)!==r)?!1:(Re(t.deleteSet),Zl(e,t),Gl(e,t.deleteSet),!0),Tn=(e,t,r)=>{const n=t._item;(n===null||n.id.clock<(e.beforeState.get(n.id.client)||0)&&!n.deleted)&&et(e.changed,t,rt).add(r)},qt=(e,t)=>{let r=e[t],n=e[t-1],i=t;for(;i>0;r=n,n=e[--i-1]){if(n.deleted===r.deleted&&n.constructor===r.constructor&&n.mergeWith(r)){r instanceof k&&r.parentSub!==null&&r.parent._map.get(r.parentSub)===r&&r.parent._map.set(r.parentSub,n);continue}break}const s=t-i;return s&&e.splice(t+1-s,s),s},vo=(e,t,r)=>{for(const[n,i]of e.clients.entries()){const s=t.clients.get(n);for(let l=i.length-1;l>=0;l--){const o=i[l],a=o.clock+o.len;for(let c=H(s,o.clock),h=s[c];c<s.length&&h.id.clock<a;h=s[++c]){const u=s[c];if(o.clock+o.len<=u.id.clock)break;u instanceof k&&u.deleted&&!u.keep&&r(u)&&u.gc(t,!1)}}}},mo=(e,t)=>{e.clients.forEach((r,n)=>{const i=t.clients.get(n);for(let s=r.length-1;s>=0;s--){const l=r[s],o=pr(i.length-1,1+H(i,l.clock+l.len-1));for(let a=o,c=i[a];a>0&&c.id.clock>=l.clock;c=i[a])a-=1+qt(i,a)}})},An=(e,t)=>{if(t<e.length){const r=e[t],n=r.doc,i=n.store,s=r.deleteSet,l=r._mergeStructs;try{Re(s),r.afterState=Be(r.doc.store),n.emit("beforeObserverCalls",[r,n]);const o=[];r.changed.forEach((a,c)=>o.push(()=>{(c._item===null||!c._item.deleted)&&c._callObserver(r,a)})),o.push(()=>{r.changedParentTypes.forEach((a,c)=>{c._dEH.l.length>0&&(c._item===null||!c._item.deleted)&&(a=a.filter(h=>h.target._item===null||!h.target._item.deleted),a.forEach(h=>{h.currentTarget=c,h._path=null}),a.sort((h,u)=>h.path.length-u.path.length),o.push(()=>{mn(c._dEH,a,r)}))}),o.push(()=>n.emit("afterTransaction",[r,n])),o.push(()=>{r._needFormattingCleanup&&Lo(r)})}),Ce(o,[])}finally{n.gc&&vo(s,i,n.gcFilter),mo(s,i),r.afterState.forEach((h,u)=>{const f=r.beforeState.get(u)||0;if(f!==h){const d=i.clients.get(u),g=st(H(d,f),1);for(let p=d.length-1;p>=g;)p-=1+qt(d,p)}});for(let h=l.length-1;h>=0;h--){const{client:u,clock:f}=l[h].id,d=i.clients.get(u),g=H(d,f);g+1<d.length&&qt(d,g+1)>1||g>0&&qt(d,g)}if(!r.local&&r.afterState.get(n.clientID)!==r.beforeState.get(n.clientID)&&(Yl(Me,nn,"[yjs] ",sn,ln,"Changed the client-id because another client seems to be using it."),n.clientID=dn()),n.emit("afterTransactionCleanup",[r,n]),n._observers.has("update")){const h=new zl;Cn(h,r)&&n.emit("update",[h.toUint8Array(),r.origin,n,r])}if(n._observers.has("updateV2")){const h=new Jl;Cn(h,r)&&n.emit("updateV2",[h.toUint8Array(),r.origin,n,r])}const{subdocsAdded:o,subdocsLoaded:a,subdocsRemoved:c}=r;(o.size>0||c.size>0||a.size>0)&&(o.forEach(h=>{h.clientID=n.clientID,h.collectionid==null&&(h.collectionid=n.collectionid),n.subdocs.add(h)}),c.forEach(h=>n.subdocs.delete(h)),n.emit("subdocs",[{loaded:a,added:o,removed:c},n,r]),c.forEach(h=>h.destroy())),e.length<=t+1?(n._transactionCleanups=[],n.emit("afterAllTransactions",[n,e])):An(e,t+1)}}},_=(e,t,r=null,n=!0)=>{const i=e._transactionCleanups;let s=!1,l=null;e._transaction===null&&(s=!0,e._transaction=new po(e,r,n),i.push(e._transaction),i.length===1&&e.emit("beforeAllTransactions",[e]),e.emit("beforeTransaction",[e._transaction,e]));try{l=t(e._transaction)}finally{if(s){const o=e._transaction===i[0];e._transaction=null,o&&An(i,0)}}return l},wo=class{constructor(e,t){this.insertions=t,this.deletions=e,this.meta=new Map}},In=(e,t,r)=>{ht(e,r.deletions,n=>{n instanceof k&&t.scope.some(i=>i===e.doc||Jt(i,n))&&Je(n,!1)})},Nn=(e,t,r)=>{let n=null;const i=e.doc,s=e.scope;_(i,o=>{for(;t.length>0&&e.currStackItem===null;){const a=i.store,c=t.pop(),h=new Set,u=[];let f=!1;ht(o,c.insertions,d=>{if(d instanceof k){if(d.redone!==null){let{item:g,diff:p}=We(a,d.id);p>0&&(g=O(o,b(g.id.client,g.id.clock+p))),d=g}!d.deleted&&s.some(g=>g===o.doc||Jt(g,d))&&u.push(d)}}),ht(o,c.deletions,d=>{d instanceof k&&s.some(g=>g===o.doc||Jt(g,d))&&!Tt(c.insertions,d.id)&&h.add(d)}),h.forEach(d=>{f=ei(o,d,h,c.insertions,e.ignoreRemoteMapChanges,e)!==null||f});for(let d=u.length-1;d>=0;d--){const g=u[d];e.deleteFilter(g)&&(g.delete(o),f=!0)}e.currStackItem=f?c:null}o.changed.forEach((a,c)=>{a.has(null)&&c._searchMarker&&(c._searchMarker.length=0)}),n=o},e);const l=e.currStackItem;if(l!=null){const o=n.changedParentTypes;e.emit("stack-item-popped",[{stackItem:l,type:r,changedParentTypes:o,origin:e},e]),e.currStackItem=null}return l},bo=class extends gr{constructor(e,{captureTimeout:t=500,captureTransaction:r=o=>!0,deleteFilter:n=()=>!0,trackedOrigins:i=new Set([null]),ignoreRemoteMapChanges:s=!1,doc:l=it(e)?e[0].doc:e instanceof Xt?e:e.doc}={}){super(),this.scope=[],this.doc=l,this.addToScope(e),this.deleteFilter=n,i.add(this),this.trackedOrigins=i,this.captureTransaction=r,this.undoStack=[],this.redoStack=[],this.undoing=!1,this.redoing=!1,this.currStackItem=null,this.lastChange=0,this.ignoreRemoteMapChanges=s,this.captureTimeout=t,this.afterTransactionHandler=o=>{if(!this.captureTransaction(o)||!this.scope.some(p=>o.changedParentTypes.has(p)||p===this.doc)||!this.trackedOrigins.has(o.origin)&&(!o.origin||!this.trackedOrigins.has(o.origin.constructor)))return;const a=this.undoing,c=this.redoing,h=a?this.redoStack:this.undoStack;a?this.stopCapturing():c||this.clear(!1,!0);const u=new Gt;o.afterState.forEach((p,m)=>{const v=o.beforeState.get(m)||0,j=p-v;j>0&&Fe(u,m,v,j)});const f=Nr();let d=!1;if(this.lastChange>0&&f-this.lastChange<this.captureTimeout&&h.length>0&&!a&&!c){const p=h[h.length-1];p.deletions=fn([p.deletions,o.deleteSet]),p.insertions=fn([p.insertions,u])}else h.push(new wo(o.deleteSet,u)),d=!0;!a&&!c&&(this.lastChange=f),ht(o,o.deleteSet,p=>{p instanceof k&&this.scope.some(m=>m===o.doc||Jt(m,p))&&Je(p,!0)});const g=[{stackItem:h[h.length-1],origin:o.origin,type:a?"redo":"undo",changedParentTypes:o.changedParentTypes},this];d?this.emit("stack-item-added",g):this.emit("stack-item-updated",g)},this.doc.on("afterTransaction",this.afterTransactionHandler),this.doc.on("destroy",()=>{this.destroy()})}addToScope(e){const t=new Set(this.scope);e=it(e)?e:[e],e.forEach(r=>{t.has(r)||(t.add(r),(r instanceof C?r.doc!==this.doc:r!==this.doc)&&an("[yjs#509] Not same Y.Doc"),this.scope.push(r))})}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(r=>{e&&(this.undoStack.forEach(n=>In(r,this,n)),this.undoStack=[]),t&&(this.redoStack.forEach(n=>In(r,this,n)),this.redoStack=[]),this.emit("stack-cleared",[{undoStackCleared:e,redoStackCleared:t}])})}stopCapturing(){this.lastChange=0}undo(){this.undoing=!0;let e;try{e=Nn(this,this.undoStack,"undo")}finally{this.undoing=!1}return e}redo(){this.redoing=!0;let e;try{e=Nn(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()}},Dn="You must not compute changes after the event-handler fired.",Zt=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||(this._path=_o(this.currentTarget,this.target))}deletes(e){return Tt(this.transaction.deleteSet,e.id)}get keys(){if(this._keys===null){if(this.transaction.doc._transactionCleanups.length===0)throw U(Dn);const e=new Map,t=this.target;this.transaction.changed.get(t).forEach(n=>{if(n!==null){const i=t._map.get(n);let s,l;if(this.adds(i)){let o=i.left;for(;o!==null&&this.adds(o);)o=o.left;if(this.deletes(i))if(o!==null&&this.deletes(o))s="delete",l=de(o.content.getContent());else return;else o!==null&&this.deletes(o)?(s="update",l=de(o.content.getContent())):(s="add",l=void 0)}else if(this.deletes(i))s="delete",l=de(i.content.getContent());else return;e.set(n,{action:s,oldValue:l})}}),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 U(Dn);const t=this.target,r=rt(),n=rt(),i=[];if(e={added:r,deleted:n,delta:i,keys:this.keys},this.transaction.changed.get(t).has(null)){let l=null;const o=()=>{l&&i.push(l)};for(let a=t._start;a!==null;a=a.right)a.deleted?this.deletes(a)&&!this.adds(a)&&((l===null||l.delete===void 0)&&(o(),l={delete:0}),l.delete+=a.length,n.add(a)):this.adds(a)?((l===null||l.insert===void 0)&&(o(),l={insert:[]}),l.insert=l.insert.concat(a.content.getContent()),r.add(a)):((l===null||l.retain===void 0)&&(o(),l={retain:0}),l.retain+=a.length);l!==null&&l.retain===void 0&&o()}this._changes=e}return e}},_o=(e,t)=>{const r=[];for(;t._item!==null&&t!==e;){if(t._item.parentSub!==null)r.unshift(t._item.parentSub);else{let n=0,i=t._item.parent._start;for(;i!==t._item&&i!==null;)!i.deleted&&i.countable&&(n+=i.length),i=i.right;r.unshift(n)}t=t._item.parent}return r},I=()=>{an("Invalid access: Add Yjs type to a document before reading data.")},On=80,Ye=0,ko=class{constructor(e,t){e.marker=!0,this.p=e,this.index=t,this.timestamp=Ye++}},yo=e=>{e.timestamp=Ye++},xn=(e,t,r)=>{e.p.marker=!1,e.p=t,t.marker=!0,e.index=r,e.timestamp=Ye++},So=(e,t,r)=>{if(e.length>=On){const n=e.reduce((i,s)=>i.timestamp<s.timestamp?i:s);return xn(n,t,r),n}else{const n=new ko(t,r);return e.push(n),n}},Qt=(e,t)=>{if(e._start===null||t===0||e._searchMarker===null)return null;const r=e._searchMarker.length===0?null:e._searchMarker.reduce((s,l)=>Dt(t-s.index)<Dt(t-l.index)?s:l);let n=e._start,i=0;for(r!==null&&(n=r.p,i=r.index,yo(r));n.right!==null&&i<t;){if(!n.deleted&&n.countable){if(t<i+n.length)break;i+=n.length}n=n.right}for(;n.left!==null&&i>t;)n=n.left,!n.deleted&&n.countable&&(i-=n.length);for(;n.left!==null&&n.left.id.client===n.id.client&&n.left.id.clock+n.left.length===n.id.clock;)n=n.left,!n.deleted&&n.countable&&(i-=n.length);return r!==null&&Dt(r.index-i)<n.parent.length/On?(xn(r,n,i),r):So(e._searchMarker,n,i)},At=(e,t,r)=>{for(let n=e.length-1;n>=0;n--){const i=e[n];if(r>0){let s=i.p;for(s.marker=!1;s&&(s.deleted||!s.countable);)s=s.left,s&&!s.deleted&&s.countable&&(i.index-=s.length);if(s===null||s.marker===!0){e.splice(n,1);continue}i.p=s,s.marker=!0}(t<i.index||r>0&&t===i.index)&&(i.index=st(t,i.index+r))}},te=(e,t,r)=>{const n=e,i=t.changedParentTypes;for(;et(i,e,()=>[]).push(r),e._item!==null;)e=e._item.parent;mn(n._eH,r,t)},C=class{constructor(){this._item=null,this._map=new Map,this._start=null,this.doc=null,this._length=0,this._eH=gn(),this._dEH=gn(),this._searchMarker=null}get parent(){return this._item?this._item.parent:null}_integrate(e,t){this.doc=e,this._item=t}_copy(){throw L()}clone(){throw L()}_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){pn(this._eH,e)}observeDeep(e){pn(this._dEH,e)}unobserve(e){vn(this._eH,e)}unobserveDeep(e){vn(this._dEH,e)}toJSON(){}},Ln=(e,t,r)=>{var n;(n=e.doc)!=null||I(),t<0&&(t=e._length+t),r<0&&(r=e._length+r);let i=r-t;const s=[];let l=e._start;for(;l!==null&&i>0;){if(l.countable&&!l.deleted){const o=l.content.getContent();if(o.length<=t)t-=o.length;else{for(let a=t;a<o.length&&i>0;a++)s.push(o[a]),i--;t=0}}l=l.right}return s},Mn=e=>{var t;(t=e.doc)!=null||I();const r=[];let n=e._start;for(;n!==null;){if(n.countable&&!n.deleted){const i=n.content.getContent();for(let s=0;s<i.length;s++)r.push(i[s])}n=n.right}return r},It=(e,t)=>{var r;let n=0,i=e._start;for((r=e.doc)!=null||I();i!==null;){if(i.countable&&!i.deleted){const s=i.content.getContent();for(let l=0;l<s.length;l++)t(s[l],n++,e)}i=i.right}},$n=(e,t)=>{const r=[];return It(e,(n,i)=>{r.push(t(n,i,e))}),r},Eo=e=>{let t=e._start,r=null,n=0;return{[Symbol.iterator](){return this},next:()=>{if(r===null){for(;t!==null&&t.deleted;)t=t.right;if(t===null)return{done:!0,value:void 0};r=t.content.getContent(),n=0,t=t.right}const i=r[n++];return r.length<=n&&(r=null),{done:!1,value:i}}}},Rn=(e,t)=>{var r;(r=e.doc)!=null||I();const n=Qt(e,t);let i=e._start;for(n!==null&&(i=n.p,t-=n.index);i!==null;i=i.right)if(!i.deleted&&i.countable){if(t<i.length)return i.content.getContent()[t];t-=i.length}},ee=(e,t,r,n)=>{let i=r;const s=e.doc,l=s.clientID,o=s.store,a=r===null?t._start:r.right;let c=[];const h=()=>{c.length>0&&(i=new k(b(l,T(o,l)),i,i&&i.lastId,a,a&&a.id,t,null,new ze(c)),i.integrate(e,0),c=[])};n.forEach(u=>{if(u===null)c.push(u);else switch(u.constructor){case Number:case Object:case Boolean:case Array:case String:c.push(u);break;default:switch(h(),u.constructor){case Uint8Array:case ArrayBuffer:i=new k(b(l,T(o,l)),i,i&&i.lastId,a,a&&a.id,t,null,new qn(new Uint8Array(u))),i.integrate(e,0);break;case Xt:i=new k(b(l,T(o,l)),i,i&&i.lastId,a,a&&a.id,t,null,new Zn(u)),i.integrate(e,0);break;default:if(u instanceof C)i=new k(b(l,T(o,l)),i,i&&i.lastId,a,a&&a.id,t,null,new Q(u)),i.integrate(e,0);else throw new Error("Unexpected content type in insert operation")}}}),h()},Fn=()=>U("Length exceeded!"),Un=(e,t,r,n)=>{if(r>t._length)throw Fn();if(r===0)return t._searchMarker&&At(t._searchMarker,r,n.length),ee(e,t,null,n);const i=r,s=Qt(t,r);let l=t._start;for(s!==null&&(l=s.p,r-=s.index,r===0&&(l=l.prev,r+=l&&l.countable&&!l.deleted?l.length:0));l!==null;l=l.right)if(!l.deleted&&l.countable){if(r<=l.length){r<l.length&&O(e,b(l.id.client,l.id.clock+r));break}r-=l.length}return t._searchMarker&&At(t._searchMarker,i,n.length),ee(e,t,l,n)},Co=(e,t,r)=>{let i=(t._searchMarker||[]).reduce((s,l)=>l.index>s.index?l:s,{index:0,p:t._start}).p;if(i)for(;i.right;)i=i.right;return ee(e,t,i,r)},Bn=(e,t,r,n)=>{if(n===0)return;const i=r,s=n,l=Qt(t,r);let o=t._start;for(l!==null&&(o=l.p,r-=l.index);o!==null&&r>0;o=o.right)!o.deleted&&o.countable&&(r<o.length&&O(e,b(o.id.client,o.id.clock+r)),r-=o.length);for(;n>0&&o!==null;)o.deleted||(n<o.length&&O(e,b(o.id.client,o.id.clock+n)),o.delete(e),n-=o.length),o=o.right;if(n>0)throw Fn();t._searchMarker&&At(t._searchMarker,i,-s+n)},re=(e,t,r)=>{const n=t._map.get(r);n!==void 0&&n.delete(e)},Ve=(e,t,r,n)=>{const i=t._map.get(r)||null,s=e.doc,l=s.clientID;let o;if(n==null)o=new ze([n]);else switch(n.constructor){case Number:case Object:case Boolean:case Array:case String:case Date:case BigInt:o=new ze([n]);break;case Uint8Array:o=new qn(n);break;case Xt:o=new Zn(n);break;default:if(n instanceof C)o=new Q(n);else throw new Error("Unexpected content type")}new k(b(l,T(s.store,l)),i,i&&i.lastId,null,null,t,r,o).integrate(e,0)},Pe=(e,t)=>{var r;(r=e.doc)!=null||I();const n=e._map.get(t);return n!==void 0&&!n.deleted?n.content.getContent()[n.length-1]:void 0},jn=e=>{var t;const r={};return(t=e.doc)!=null||I(),e._map.forEach((n,i)=>{n.deleted||(r[i]=n.content.getContent()[n.length-1])}),r},Yn=(e,t)=>{var r;(r=e.doc)!=null||I();const n=e._map.get(t);return n!==void 0&&!n.deleted},To=(e,t)=>{const r={};return e._map.forEach((n,i)=>{let s=n;for(;s!==null&&(!t.sv.has(s.id.client)||s.id.clock>=(t.sv.get(s.id.client)||0));)s=s.left;s!==null&&ut(s,t)&&(r[i]=s.content.getContent()[s.length-1])}),r},ne=e=>{var t;return(t=e.doc)!=null||I(),Vl(e._map.entries(),r=>!r[1].deleted)},Ao=class extends Zt{},Io=class he extends C{constructor(){super(),this._prelimContent=[],this._searchMarker=[]}static from(t){const r=new he;return r.push(t),r}_integrate(t,r){super._integrate(t,r),this.insert(0,this._prelimContent),this._prelimContent=null}_copy(){return new he}clone(){const t=new he;return t.insert(0,this.toArray().map(r=>r instanceof C?r.clone():r)),t}get length(){var t;return(t=this.doc)!=null||I(),this._length}_callObserver(t,r){super._callObserver(t,r),te(this,t,new Ao(this,t))}insert(t,r){this.doc!==null?_(this.doc,n=>{Un(n,this,t,r)}):this._prelimContent.splice(t,0,...r)}push(t){this.doc!==null?_(this.doc,r=>{Co(r,this,t)}):this._prelimContent.push(...t)}unshift(t){this.insert(0,t)}delete(t,r=1){this.doc!==null?_(this.doc,n=>{Bn(n,this,t,r)}):this._prelimContent.splice(t,r)}get(t){return Rn(this,t)}toArray(){return Mn(this)}slice(t=0,r=this.length){return Ln(this,t,r)}toJSON(){return this.map(t=>t instanceof C?t.toJSON():t)}map(t){return $n(this,t)}forEach(t){It(this,t)}[Symbol.iterator](){return Eo(this)}_write(t){t.writeTypeRef(jo)}},No=class extends Zt{constructor(e,t,r){super(e,t),this.keysChanged=r}},Do=class nr extends C{constructor(t){super(),this._prelimContent=null,t===void 0?this._prelimContent=new Map:this._prelimContent=new Map(t)}_integrate(t,r){super._integrate(t,r),this._prelimContent.forEach((n,i)=>{this.set(i,n)}),this._prelimContent=null}_copy(){return new nr}clone(){const t=new nr;return this.forEach((r,n)=>{t.set(n,r instanceof C?r.clone():r)}),t}_callObserver(t,r){te(this,t,new No(this,t,r))}toJSON(){var t;(t=this.doc)!=null||I();const r={};return this._map.forEach((n,i)=>{if(!n.deleted){const s=n.content.getContent()[n.length-1];r[i]=s instanceof C?s.toJSON():s}}),r}get size(){return[...ne(this)].length}keys(){return $e(ne(this),t=>t[0])}values(){return $e(ne(this),t=>t[1].content.getContent()[t[1].length-1])}entries(){return $e(ne(this),t=>[t[0],t[1].content.getContent()[t[1].length-1]])}forEach(t){var r;(r=this.doc)!=null||I(),this._map.forEach((n,i)=>{n.deleted||t(n.content.getContent()[n.length-1],i,this)})}[Symbol.iterator](){return this.entries()}delete(t){this.doc!==null?_(this.doc,r=>{re(r,this,t)}):this._prelimContent.delete(t)}set(t,r){return this.doc!==null?_(this.doc,n=>{Ve(n,this,t,r)}):this._prelimContent.set(t,r),r}get(t){return Pe(this,t)}has(t){return Yn(this,t)}clear(){this.doc!==null?_(this.doc,t=>{this.forEach(function(r,n,i){re(t,i,n)})}):this._prelimContent.clear()}_write(t){t.writeTypeRef(Yo)}},G=(e,t)=>e===t||typeof e=="object"&&typeof t=="object"&&e&&t&&Gs(e,t),He=class{constructor(e,t,r,n){this.left=e,this.right=t,this.index=r,this.currentAttributes=n}forward(){this.right===null&&M(),this.right.content.constructor===N?this.right.deleted||dt(this.currentAttributes,this.right.content):this.right.deleted||(this.index+=this.right.length),this.left=this.right,this.right=this.right.right}},Vn=(e,t,r)=>{for(;t.right!==null&&r>0;)t.right.content.constructor===N?t.right.deleted||dt(t.currentAttributes,t.right.content):t.right.deleted||(r<t.right.length&&O(e,b(t.right.id.client,t.right.id.clock+r)),t.index+=t.right.length,r-=t.right.length),t.left=t.right,t.right=t.right.right;return t},ie=(e,t,r,n)=>{const i=new Map,s=n?Qt(t,r):null;if(s){const l=new He(s.p.left,s.p,s.index,i);return Vn(e,l,r-s.index)}else{const l=new He(null,t._start,0,i);return Vn(e,l,r)}},Pn=(e,t,r,n)=>{for(;r.right!==null&&(r.right.deleted===!0||r.right.content.constructor===N&&G(n.get(r.right.content.key),r.right.content.value));)r.right.deleted||n.delete(r.right.content.key),r.forward();const i=e.doc,s=i.clientID;n.forEach((l,o)=>{const a=r.left,c=r.right,h=new k(b(s,T(i.store,s)),a,a&&a.lastId,c,c&&c.id,t,null,new N(o,l));h.integrate(e,0),r.right=h,r.forward()})},dt=(e,t)=>{const{key:r,value:n}=t;n===null?e.delete(r):e.set(r,n)},Hn=(e,t)=>{for(var r;e.right!==null;){if(!(e.right.deleted||e.right.content.constructor===N&&G((r=t[e.right.content.key])!=null?r:null,e.right.content.value)))break;e.forward()}},Gn=(e,t,r,n)=>{var i;const s=e.doc,l=s.clientID,o=new Map;for(const a in n){const c=n[a],h=(i=r.currentAttributes.get(a))!=null?i:null;if(!G(h,c)){o.set(a,h);const{left:u,right:f}=r;r.right=new k(b(l,T(s.store,l)),u,u&&u.lastId,f,f&&f.id,t,null,new N(a,c)),r.right.integrate(e,0),r.forward()}}return o},Ge=(e,t,r,n,i)=>{r.currentAttributes.forEach((f,d)=>{i[d]===void 0&&(i[d]=null)});const s=e.doc,l=s.clientID;Hn(r,i);const o=Gn(e,t,r,i),a=n.constructor===String?new pt(n):n instanceof C?new Q(n):new oe(n);let{left:c,right:h,index:u}=r;t._searchMarker&&At(t._searchMarker,r.index,a.getLength()),h=new k(b(l,T(s.store,l)),c,c&&c.lastId,h,h&&h.id,t,null,a),h.integrate(e,0),r.right=h,r.index=u,r.forward(),Pn(e,t,r,o)},Xn=(e,t,r,n,i)=>{const s=e.doc,l=s.clientID;Hn(r,i);const o=Gn(e,t,r,i);t:for(;r.right!==null&&(n>0||o.size>0&&(r.right.deleted||r.right.content.constructor===N));){if(!r.right.deleted)switch(r.right.content.constructor){case N:{const{key:a,value:c}=r.right.content,h=i[a];if(h!==void 0){if(G(h,c))o.delete(a);else{if(n===0)break t;o.set(a,c)}r.right.delete(e)}else r.currentAttributes.set(a,c);break}default:n<r.right.length&&O(e,b(r.right.id.client,r.right.id.clock+n)),n-=r.right.length;break}r.forward()}if(n>0){let a="";for(;n>0;n--)a+=`
4
+ `;r.right=new k(b(l,T(s.store,l)),r.left,r.left&&r.left.lastId,r.right,r.right&&r.right.id,t,null,new pt(a)),r.right.integrate(e,0),r.forward()}Pn(e,t,r,o)},zn=(e,t,r,n,i)=>{var s,l;let o=t;const a=R();for(;o&&(!o.countable||o.deleted);){if(!o.deleted&&o.content.constructor===N){const u=o.content;a.set(u.key,u)}o=o.right}let c=0,h=!1;for(;t!==o;){if(r===t&&(h=!0),!t.deleted){const u=t.content;if(u.constructor===N){const{key:f,value:d}=u,g=(s=n.get(f))!=null?s:null;(a.get(f)!==u||g===d)&&(t.delete(e),c++,!h&&((l=i.get(f))!=null?l:null)===d&&g!==d&&(g===null?i.delete(f):i.set(f,g))),!h&&!t.deleted&&dt(i,u)}}t=t.right}return c},Oo=(e,t)=>{for(;t&&t.right&&(t.right.deleted||!t.right.countable);)t=t.right;const r=new Set;for(;t&&(t.deleted||!t.countable);){if(!t.deleted&&t.content.constructor===N){const n=t.content.key;r.has(n)?t.delete(e):r.add(n)}t=t.left}},xo=e=>{let t=0;return _(e.doc,r=>{let n=e._start,i=e._start,s=R();const l=fe(s);for(;i;)i.deleted===!1&&(i.content.constructor===N?dt(l,i.content):(t+=zn(r,n,i,s,l),s=fe(l),n=i)),i=i.right}),t},Lo=e=>{const t=new Set,r=e.doc;for(const[n,i]of e.afterState.entries()){const s=e.beforeState.get(n)||0;i!==s&&En(e,r.store.clients.get(n),s,i,l=>{!l.deleted&&l.content.constructor===N&&l.constructor!==X&&t.add(l.parent)})}_(r,n=>{ht(e,e.deleteSet,i=>{if(i instanceof X||!i.parent._hasFormatting||t.has(i.parent))return;const s=i.parent;i.content.constructor===N?t.add(s):Oo(n,i)});for(const i of t)xo(i)})},Wn=(e,t,r)=>{const n=r,i=fe(t.currentAttributes),s=t.right;for(;r>0&&t.right!==null;){if(t.right.deleted===!1)switch(t.right.content.constructor){case Q:case oe:case pt:r<t.right.length&&O(e,b(t.right.id.client,t.right.id.clock+r)),r-=t.right.length,t.right.delete(e);break}t.forward()}s&&zn(e,s,t.right,i,t.currentAttributes);const l=(t.left||t.right).parent;return l._searchMarker&&At(l._searchMarker,t.index,-n+r),t},Mo=class extends Zt{constructor(e,t,r){super(e,t),this.childListChanged=!1,this.keysChanged=new Set,r.forEach(n=>{n===null?this.childListChanged=!0:this.keysChanged.add(n)})}get changes(){if(this._changes===null){const 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){const e=this.target.doc,t=[];_(e,r=>{var n,i,s;const l=new Map,o=new Map;let a=this.target._start,c=null;const h={};let u="",f=0,d=0;const g=()=>{if(c!==null){let p=null;switch(c){case"delete":d>0&&(p={delete:d}),d=0;break;case"insert":(typeof u=="object"||u.length>0)&&(p={insert:u},l.size>0&&(p.attributes={},l.forEach((m,v)=>{m!==null&&(p.attributes[v]=m)}))),u="";break;case"retain":f>0&&(p={retain:f},Hs(h)||(p.attributes=Ys({},h))),f=0;break}p&&t.push(p),c=null}};for(;a!==null;){switch(a.content.constructor){case Q:case oe:this.adds(a)?this.deletes(a)||(g(),c="insert",u=a.content.getContent()[0],g()):this.deletes(a)?(c!=="delete"&&(g(),c="delete"),d+=1):a.deleted||(c!=="retain"&&(g(),c="retain"),f+=1);break;case pt:this.adds(a)?this.deletes(a)||(c!=="insert"&&(g(),c="insert"),u+=a.content.str):this.deletes(a)?(c!=="delete"&&(g(),c="delete"),d+=a.length):a.deleted||(c!=="retain"&&(g(),c="retain"),f+=a.length);break;case N:{const{key:p,value:m}=a.content;if(this.adds(a)){if(!this.deletes(a)){const v=(n=l.get(p))!=null?n:null;G(v,m)?m!==null&&a.delete(r):(c==="retain"&&g(),G(m,(i=o.get(p))!=null?i:null)?delete h[p]:h[p]=m)}}else if(this.deletes(a)){o.set(p,m);const v=(s=l.get(p))!=null?s:null;G(v,m)||(c==="retain"&&g(),h[p]=v)}else if(!a.deleted){o.set(p,m);const v=h[p];v!==void 0&&(G(v,m)?v!==null&&a.delete(r):(c==="retain"&&g(),m===null?delete h[p]:h[p]=m))}a.deleted||(c==="insert"&&g(),dt(l,a.content));break}}a=a.right}for(g();t.length>0;){const p=t[t.length-1];if(p.retain!==void 0&&p.attributes===void 0)t.pop();else break}}),this._delta=t}return this._delta}},Jn=class ir extends C{constructor(t){super(),this._pending=t!==void 0?[()=>this.insert(0,t)]:[],this._searchMarker=[],this._hasFormatting=!1}get length(){var t;return(t=this.doc)!=null||I(),this._length}_integrate(t,r){super._integrate(t,r);try{this._pending.forEach(n=>n())}catch(n){console.error(n)}this._pending=null}_copy(){return new ir}clone(){const t=new ir;return t.applyDelta(this.toDelta()),t}_callObserver(t,r){super._callObserver(t,r);const n=new Mo(this,t,r);te(this,t,n),!t.local&&this._hasFormatting&&(t._needFormattingCleanup=!0)}toString(){var t;(t=this.doc)!=null||I();let r="",n=this._start;for(;n!==null;)!n.deleted&&n.countable&&n.content.constructor===pt&&(r+=n.content.str),n=n.right;return r}toJSON(){return this.toString()}applyDelta(t,{sanitize:r=!0}={}){this.doc!==null?_(this.doc,n=>{const i=new He(null,this._start,0,new Map);for(let s=0;s<t.length;s++){const l=t[s];if(l.insert!==void 0){const o=!r&&typeof l.insert=="string"&&s===t.length-1&&i.right===null&&l.insert.slice(-1)===`
5
+ `?l.insert.slice(0,-1):l.insert;(typeof o!="string"||o.length>0)&&Ge(n,this,i,o,l.attributes||{})}else l.retain!==void 0?Xn(n,this,i,l.retain,l.attributes||{}):l.delete!==void 0&&Wn(n,i,l.delete)}}):this._pending.push(()=>this.applyDelta(t))}toDelta(t,r,n){var i;(i=this.doc)!=null||I();const s=[],l=new Map,o=this.doc;let a="",c=this._start;function h(){if(a.length>0){const f={};let d=!1;l.forEach((p,m)=>{d=!0,f[m]=p});const g={insert:a};d&&(g.attributes=f),s.push(g),a=""}}const u=()=>{for(;c!==null;){if(ut(c,t)||r!==void 0&&ut(c,r))switch(c.content.constructor){case pt:{const f=l.get("ychange");t!==void 0&&!ut(c,t)?(f===void 0||f.user!==c.id.client||f.type!=="removed")&&(h(),l.set("ychange",n?n("removed",c.id):{type:"removed"})):r!==void 0&&!ut(c,r)?(f===void 0||f.user!==c.id.client||f.type!=="added")&&(h(),l.set("ychange",n?n("added",c.id):{type:"added"})):f!==void 0&&(h(),l.delete("ychange")),a+=c.content.str;break}case Q:case oe:{h();const f={insert:c.content.getContent()[0]};if(l.size>0){const d={};f.attributes=d,l.forEach((g,p)=>{d[p]=g})}s.push(f);break}case N:ut(c,t)&&(h(),dt(l,c.content));break}c=c.right}h()};return t||r?_(o,f=>{t&&Ue(f,t),r&&Ue(f,r),u()},"cleanup"):u(),s}insert(t,r,n){if(r.length<=0)return;const i=this.doc;i!==null?_(i,s=>{const l=ie(s,this,t,!n);n||(n={},l.currentAttributes.forEach((o,a)=>{n[a]=o})),Ge(s,this,l,r,n)}):this._pending.push(()=>this.insert(t,r,n))}insertEmbed(t,r,n){const i=this.doc;i!==null?_(i,s=>{const l=ie(s,this,t,!n);Ge(s,this,l,r,n||{})}):this._pending.push(()=>this.insertEmbed(t,r,n||{}))}delete(t,r){if(r===0)return;const n=this.doc;n!==null?_(n,i=>{Wn(i,ie(i,this,t,!0),r)}):this._pending.push(()=>this.delete(t,r))}format(t,r,n){if(r===0)return;const i=this.doc;i!==null?_(i,s=>{const l=ie(s,this,t,!1);l.right!==null&&Xn(s,this,l,r,n)}):this._pending.push(()=>this.format(t,r,n))}removeAttribute(t){this.doc!==null?_(this.doc,r=>{re(r,this,t)}):this._pending.push(()=>this.removeAttribute(t))}setAttribute(t,r){this.doc!==null?_(this.doc,n=>{Ve(n,this,t,r)}):this._pending.push(()=>this.setAttribute(t,r))}getAttribute(t){return Pe(this,t)}getAttributes(){return jn(this)}_write(t){t.writeTypeRef(Vo)}},Xe=class{constructor(e,t=()=>!0){var r;this._filter=t,this._root=e,this._currentNode=e._start,this._firstCall=!0,(r=e.doc)!=null||I()}[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===gt||t.constructor===se)&&t._start!==null)e=t._start;else for(;e!==null;){const r=e.next;if(r!==null){e=r;break}else e.parent===this._root?e=null:e=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})}},se=class sr extends C{constructor(){super(),this._prelimContent=[]}get firstChild(){const t=this._first;return t?t.content.getContent()[0]:null}_integrate(t,r){super._integrate(t,r),this.insert(0,this._prelimContent),this._prelimContent=null}_copy(){return new sr}clone(){const t=new sr;return t.insert(0,this.toArray().map(r=>r instanceof C?r.clone():r)),t}get length(){var t;return(t=this.doc)!=null||I(),this._prelimContent===null?this._length:this._prelimContent.length}createTreeWalker(t){return new Xe(this,t)}querySelector(t){t=t.toUpperCase();const n=new Xe(this,i=>i.nodeName&&i.nodeName.toUpperCase()===t).next();return n.done?null:n.value}querySelectorAll(t){return t=t.toUpperCase(),nt(new Xe(this,r=>r.nodeName&&r.nodeName.toUpperCase()===t))}_callObserver(t,r){te(this,t,new $o(this,r,t))}toString(){return $n(this,t=>t.toString()).join("")}toJSON(){return this.toString()}toDOM(t=document,r={},n){const i=t.createDocumentFragment();return n!==void 0&&n._createAssociation(i,this),It(this,s=>{i.insertBefore(s.toDOM(t,r,n),null)}),i}insert(t,r){this.doc!==null?_(this.doc,n=>{Un(n,this,t,r)}):this._prelimContent.splice(t,0,...r)}insertAfter(t,r){if(this.doc!==null)_(this.doc,n=>{const i=t&&t instanceof C?t._item:t;ee(n,this,i,r)});else{const n=this._prelimContent,i=t===null?0:n.findIndex(s=>s===t)+1;if(i===0&&t!==null)throw U("Reference item not found");n.splice(i,0,...r)}}delete(t,r=1){this.doc!==null?_(this.doc,n=>{Bn(n,this,t,r)}):this._prelimContent.splice(t,r)}toArray(){return Mn(this)}push(t){this.insert(this.length,t)}unshift(t){this.insert(0,t)}get(t){return Rn(this,t)}slice(t=0,r=this.length){return Ln(this,t,r)}forEach(t){It(this,t)}_write(t){t.writeTypeRef(Ho)}},gt=class lr extends se{constructor(t="UNDEFINED"){super(),this.nodeName=t,this._prelimAttrs=new Map}get nextSibling(){const t=this._item?this._item.next:null;return t?t.content.type:null}get prevSibling(){const t=this._item?this._item.prev:null;return t?t.content.type:null}_integrate(t,r){super._integrate(t,r),this._prelimAttrs.forEach((n,i)=>{this.setAttribute(i,n)}),this._prelimAttrs=null}_copy(){return new lr(this.nodeName)}clone(){const t=new lr(this.nodeName),r=this.getAttributes();return Ps(r,(n,i)=>{t.setAttribute(i,n)}),t.insert(0,this.toArray().map(n=>n instanceof C?n.clone():n)),t}toString(){const t=this.getAttributes(),r=[],n=[];for(const o in t)n.push(o);n.sort();const i=n.length;for(let o=0;o<i;o++){const a=n[o];r.push(a+'="'+t[a]+'"')}const s=this.nodeName.toLocaleLowerCase(),l=r.length>0?" "+r.join(" "):"";return`<${s}${l}>${super.toString()}</${s}>`}removeAttribute(t){this.doc!==null?_(this.doc,r=>{re(r,this,t)}):this._prelimAttrs.delete(t)}setAttribute(t,r){this.doc!==null?_(this.doc,n=>{Ve(n,this,t,r)}):this._prelimAttrs.set(t,r)}getAttribute(t){return Pe(this,t)}hasAttribute(t){return Yn(this,t)}getAttributes(t){return t?To(this,t):jn(this)}toDOM(t=document,r={},n){const i=t.createElement(this.nodeName),s=this.getAttributes();for(const l in s){const o=s[l];typeof o=="string"&&i.setAttribute(l,o)}return It(this,l=>{i.appendChild(l.toDOM(t,r,n))}),n!==void 0&&n._createAssociation(i,this),i}_write(t){t.writeTypeRef(Po),t.writeKey(this.nodeName)}},$o=class extends Zt{constructor(e,t,r){super(e,r),this.childListChanged=!1,this.attributesChanged=new Set,t.forEach(n=>{n===null?this.childListChanged=!0:this.attributesChanged.add(n)})}},le=class or extends Jn{get nextSibling(){const t=this._item?this._item.next:null;return t?t.content.type:null}get prevSibling(){const t=this._item?this._item.prev:null;return t?t.content.type:null}_copy(){return new or}clone(){const t=new or;return t.applyDelta(this.toDelta()),t}toDOM(t=document,r,n){const i=t.createTextNode(this.toString());return n!==void 0&&n._createAssociation(i,this),i}toString(){return this.toDelta().map(t=>{const r=[];for(const i in t.attributes){const s=[];for(const l in t.attributes[i])s.push({key:l,value:t.attributes[i][l]});s.sort((l,o)=>l.key<o.key?-1:1),r.push({nodeName:i,attrs:s})}r.sort((i,s)=>i.nodeName<s.nodeName?-1:1);let n="";for(let i=0;i<r.length;i++){const s=r[i];n+=`<${s.nodeName}`;for(let l=0;l<s.attrs.length;l++){const o=s.attrs[l];n+=` ${o.key}="${o.value}"`}n+=">"}n+=t.insert;for(let i=r.length-1;i>=0;i--)n+=`</${r[i].nodeName}>`;return n}).join("")}toJSON(){return this.toString()}_write(t){t.writeTypeRef(Go)}},Kn=class{constructor(e,t){this.id=e,this.length=t}get deleted(){throw L()}mergeWith(e){return!1}write(e,t,r){throw L()}integrate(e,t){throw L()}},Ro=0,X=class extends Kn{get deleted(){return!0}delete(){}mergeWith(e){return this.constructor!==e.constructor?!1:(this.length+=e.length,!0)}integrate(e,t){t>0&&(this.id.clock+=t,this.length-=t),yn(e.doc.store,this)}write(e,t){e.writeInfo(Ro),e.writeLen(this.length-t)}getMissing(e,t){return null}},qn=class Oi{constructor(t){this.content=t}getLength(){return 1}getContent(){return[this.content]}isCountable(){return!0}copy(){return new Oi(this.content)}splice(t){throw L()}mergeWith(t){return!1}integrate(t,r){}delete(t){}gc(t){}write(t,r){t.writeBuf(this.content)}getRef(){return 3}},Fo=class ar{constructor(t){this.len=t}getLength(){return this.len}getContent(){return[]}isCountable(){return!1}copy(){return new ar(this.len)}splice(t){const r=new ar(this.len-t);return this.len=t,r}mergeWith(t){return this.len+=t.len,!0}integrate(t,r){Fe(t.deleteSet,r.id.client,r.id.clock,this.len),r.markDeleted()}delete(t){}gc(t){}write(t,r){t.writeLen(this.len-r)}getRef(){return 1}},Uo=(e,t)=>new Xt({guid:e,...t,shouldLoad:t.shouldLoad||t.autoLoad||!1}),Zn=class xi{constructor(t){t._item&&console.error("This document was already integrated as a sub-document. You should create a second instance instead with the same guid."),this.doc=t;const r={};this.opts=r,t.gc||(r.gc=!1),t.autoLoad&&(r.autoLoad=!0),t.meta!==null&&(r.meta=t.meta)}getLength(){return 1}getContent(){return[this.doc]}isCountable(){return!0}copy(){return new xi(Uo(this.doc.guid,this.opts))}splice(t){throw L()}mergeWith(t){return!1}integrate(t,r){this.doc._item=r,t.subdocsAdded.add(this.doc),this.doc.shouldLoad&&t.subdocsLoaded.add(this.doc)}delete(t){t.subdocsAdded.has(this.doc)?t.subdocsAdded.delete(this.doc):t.subdocsRemoved.add(this.doc)}gc(t){}write(t,r){t.writeString(this.doc.guid),t.writeAny(this.opts)}getRef(){return 9}},oe=class Li{constructor(t){this.embed=t}getLength(){return 1}getContent(){return[this.embed]}isCountable(){return!0}copy(){return new Li(this.embed)}splice(t){throw L()}mergeWith(t){return!1}integrate(t,r){}delete(t){}gc(t){}write(t,r){t.writeJSON(this.embed)}getRef(){return 5}},N=class Mi{constructor(t,r){this.key=t,this.value=r}getLength(){return 1}getContent(){return[]}isCountable(){return!1}copy(){return new Mi(this.key,this.value)}splice(t){throw L()}mergeWith(t){return!1}integrate(t,r){const n=r.parent;n._searchMarker=null,n._hasFormatting=!0}delete(t){}gc(t){}write(t,r){t.writeKey(this.key),t.writeJSON(this.value)}getRef(){return 6}},Bo=Ft("node_env")==="development",ze=class cr{constructor(t){this.arr=t,Bo&&Mr(t)}getLength(){return this.arr.length}getContent(){return this.arr}isCountable(){return!0}copy(){return new cr(this.arr)}splice(t){const r=new cr(this.arr.slice(t));return this.arr=this.arr.slice(0,t),r}mergeWith(t){return this.arr=this.arr.concat(t.arr),!0}integrate(t,r){}delete(t){}gc(t){}write(t,r){const n=this.arr.length;t.writeLen(n-r);for(let i=r;i<n;i++){const s=this.arr[i];t.writeAny(s)}}getRef(){return 8}},pt=class hr{constructor(t){this.str=t}getLength(){return this.str.length}getContent(){return this.str.split("")}isCountable(){return!0}copy(){return new hr(this.str)}splice(t){const r=new hr(this.str.slice(t));this.str=this.str.slice(0,t);const n=this.str.charCodeAt(t-1);return n>=55296&&n<=56319&&(this.str=this.str.slice(0,t-1)+"\uFFFD",r.str="\uFFFD"+r.str.slice(1)),r}mergeWith(t){return this.str+=t.str,!0}integrate(t,r){}delete(t){}gc(t){}write(t,r){t.writeString(r===0?this.str:this.str.slice(r))}getRef(){return 4}},jo=0,Yo=1,Vo=2,Po=3,Ho=4,Go=6,Q=class $i{constructor(t){this.type=t}getLength(){return 1}getContent(){return[this.type]}isCountable(){return!0}copy(){return new $i(this.type._copy())}splice(t){throw L()}mergeWith(t){return!1}integrate(t,r){this.type._integrate(t.doc,r)}delete(t){let r=this.type._start;for(;r!==null;)r.deleted?r.id.clock<(t.beforeState.get(r.id.client)||0)&&t._mergeStructs.push(r):r.delete(t),r=r.right;this.type._map.forEach(n=>{n.deleted?n.id.clock<(t.beforeState.get(n.id.client)||0)&&t._mergeStructs.push(n):n.delete(t)}),t.changed.delete(this.type)}gc(t){let r=this.type._start;for(;r!==null;)r.gc(t,!0),r=r.right;this.type._start=null,this.type._map.forEach(n=>{for(;n!==null;)n.gc(t,!0),n=n.left}),this.type._map=new Map}write(t,r){this.type._write(t)}getRef(){return 7}},We=(e,t)=>{let r=t,n=0,i;do n>0&&(r=b(r.client,r.clock+n)),i=ft(e,r),n=r.clock-i.id.clock,r=i.redone;while(r!==null&&i instanceof k);return{item:i,diff:n}},Je=(e,t)=>{for(;e!==null&&e.keep!==t;)e.keep=t,e=e.parent._item},Qn=(e,t,r)=>{const{client:n,clock:i}=t.id,s=new k(b(n,i+r),t,b(n,i+r-1),t.right,t.rightOrigin,t.parent,t.parentSub,t.content.splice(r));return t.deleted&&s.markDeleted(),t.keep&&(s.keep=!0),t.redone!==null&&(s.redone=b(t.redone.client,t.redone.clock+r)),t.right=s,s.right!==null&&(s.right.left=s),e._mergeStructs.push(s),s.parentSub!==null&&s.right===null&&s.parent._map.set(s.parentSub,s),t.length=r,s},ti=(e,t)=>pe(e,r=>Tt(r.deletions,t)),ei=(e,t,r,n,i,s)=>{const l=e.doc,o=l.store,a=l.clientID,c=t.redone;if(c!==null)return O(e,c);let h=t.parent._item,u=null,f;if(h!==null&&h.deleted===!0){if(h.redone===null&&(!r.has(h)||ei(e,h,r,n,i,s)===null))return null;for(;h.redone!==null;)h=O(e,h.redone)}const d=h===null?t.parent:h.content.type;if(t.parentSub===null){for(u=t.left,f=t;u!==null;){let v=u;for(;v!==null&&v.parent._item!==h;)v=v.redone===null?null:O(e,v.redone);if(v!==null&&v.parent._item===h){u=v;break}u=u.left}for(;f!==null;){let v=f;for(;v!==null&&v.parent._item!==h;)v=v.redone===null?null:O(e,v.redone);if(v!==null&&v.parent._item===h){f=v;break}f=f.right}}else if(f=null,t.right&&!i){for(u=t;u!==null&&u.right!==null&&(u.right.redone||Tt(n,u.right.id)||ti(s.undoStack,u.right.id)||ti(s.redoStack,u.right.id));)for(u=u.right;u.redone;)u=O(e,u.redone);if(u&&u.right!==null)return null}else u=d._map.get(t.parentSub)||null;const g=T(o,a),p=b(a,g),m=new k(p,u,u&&u.lastId,f,f&&f.id,d,t.parentSub,t.content.copy());return t.redone=p,Je(m,!0),m.integrate(e,0),m},k=class ur extends Kn{constructor(t,r,n,i,s,l,o,a){super(t,a.getLength()),this.origin=n,this.left=r,this.right=i,this.rightOrigin=s,this.parent=l,this.parentSub=o,this.redone=null,this.content=a,this.info=this.content.isCountable()?mr:0}set marker(t){(this.info&me)>0!==t&&(this.info^=me)}get marker(){return(this.info&me)>0}get keep(){return(this.info&vr)>0}set keep(t){this.keep!==t&&(this.info^=vr)}get countable(){return(this.info&mr)>0}get deleted(){return(this.info&ve)>0}set deleted(t){this.deleted!==t&&(this.info^=ve)}markDeleted(){this.info|=ve}getMissing(t,r){if(this.origin&&this.origin.client!==this.id.client&&this.origin.clock>=T(r,this.origin.client))return this.origin.client;if(this.rightOrigin&&this.rightOrigin.client!==this.id.client&&this.rightOrigin.clock>=T(r,this.rightOrigin.client))return this.rightOrigin.client;if(this.parent&&this.parent.constructor===zt&&this.id.client!==this.parent.client&&this.parent.clock>=T(r,this.parent.client))return this.parent.client;if(this.origin&&(this.left=Sn(t,r,this.origin),this.origin=this.left.lastId),this.rightOrigin&&(this.right=O(t,this.rightOrigin),this.rightOrigin=this.right.id),this.left&&this.left.constructor===X||this.right&&this.right.constructor===X)this.parent=null;else if(!this.parent)this.left&&this.left.constructor===ur?(this.parent=this.left.parent,this.parentSub=this.left.parentSub):this.right&&this.right.constructor===ur&&(this.parent=this.right.parent,this.parentSub=this.right.parentSub);else if(this.parent.constructor===zt){const n=ft(r,this.parent);n.constructor===X?this.parent=null:this.parent=n.content.type}return null}integrate(t,r){if(r>0&&(this.id.clock+=r,this.left=Sn(t,t.doc.store,b(this.id.client,this.id.clock-1)),this.origin=this.left.lastId,this.content=this.content.splice(r),this.length-=r),this.parent){if(!this.left&&(!this.right||this.right.left!==null)||this.left&&this.left.right!==this.right){let n=this.left,i;if(n!==null)i=n.right;else if(this.parentSub!==null)for(i=this.parent._map.get(this.parentSub)||null;i!==null&&i.left!==null;)i=i.left;else i=this.parent._start;const s=new Set,l=new Set;for(;i!==null&&i!==this.right;){if(l.add(i),s.add(i),Wt(this.origin,i.origin)){if(i.id.client<this.id.client)n=i,s.clear();else if(Wt(this.rightOrigin,i.rightOrigin))break}else if(i.origin!==null&&l.has(ft(t.doc.store,i.origin)))s.has(ft(t.doc.store,i.origin))||(n=i,s.clear());else break;i=i.right}this.left=n}if(this.left!==null){const n=this.left.right;this.right=n,this.left.right=this}else{let n;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,this.parent._start=this;this.right=n}this.right!==null?this.right.left=this:this.parentSub!==null&&(this.parent._map.set(this.parentSub,this),this.left!==null&&this.left.delete(t)),this.parentSub===null&&this.countable&&!this.deleted&&(this.parent._length+=this.length),yn(t.doc.store,this),this.content.integrate(t,this),Tn(t,this.parent,this.parentSub),(this.parent._item!==null&&this.parent._item.deleted||this.parentSub!==null&&this.right!==null)&&this.delete(t)}else new X(this.id,this.length).integrate(t,0)}get next(){let t=this.right;for(;t!==null&&t.deleted;)t=t.right;return t}get prev(){let t=this.left;for(;t!==null&&t.deleted;)t=t.left;return t}get lastId(){return this.length===1?this.id:b(this.id.client,this.id.clock+this.length-1)}mergeWith(t){if(this.constructor===t.constructor&&Wt(t.origin,this.lastId)&&this.right===t&&Wt(this.rightOrigin,t.rightOrigin)&&this.id.client===t.id.client&&this.id.clock+this.length===t.id.clock&&this.deleted===t.deleted&&this.redone===null&&t.redone===null&&this.content.constructor===t.content.constructor&&this.content.mergeWith(t.content)){const r=this.parent._searchMarker;return r&&r.forEach(n=>{n.p===t&&(n.p=this,!this.deleted&&this.countable&&(n.index-=this.length))}),t.keep&&(this.keep=!0),this.right=t.right,this.right!==null&&(this.right.left=this),this.length+=t.length,!0}return!1}delete(t){if(!this.deleted){const r=this.parent;this.countable&&this.parentSub===null&&(r._length-=this.length),this.markDeleted(),Fe(t.deleteSet,this.id.client,this.id.clock,this.length),Tn(t,r,this.parentSub),this.content.delete(t)}}gc(t,r){if(!this.deleted)throw M();this.content.gc(t),r?go(t,this,new X(this.id,this.length)):this.content=new Fo(this.length)}write(t,r){const n=r>0?b(this.id.client,this.id.clock+r-1):this.origin,i=this.rightOrigin,s=this.parentSub,l=this.content.getRef()&is|(n===null?0:J)|(i===null?0:we)|(s===null?0:Pi);if(t.writeInfo(l),n!==null&&t.writeLeftID(n),i!==null&&t.writeRightID(i),n===null&&i===null){const o=this.parent;if(o._item!==void 0){const a=o._item;if(a===null){const c=_n(o);t.writeParentInfo(!0),t.writeString(c)}else t.writeParentInfo(!1),t.writeLeftID(a.id)}else o.constructor===String?(t.writeParentInfo(!0),t.writeString(o)):o.constructor===zt?(t.writeParentInfo(!1),t.writeLeftID(o)):M();s!==null&&t.writeString(s)}this.content.write(t,r)}},ri=typeof globalThis<"u"?globalThis:typeof window<"u"?window:typeof global<"u"?global:{},ni="__ $YJS$ __";ri[ni]===!0&&console.error("Yjs was already imported. This breaks constructor checks and will lead to issues! - https://github.com/yjs/yjs/issues/438"),ri[ni]=!0;var ii=new Set(["p","div","section","article","header","footer","main","aside","h1","h2","h3","h4","h5","h6","ul","ol","li","blockquote","pre","table","thead","tbody","tfoot","tr","td","th","figure","figcaption"]),si=new Set(["strong","b","em","i","u","s","strike","del","ins","mark","small","sub","sup","code","kbd","samp","var","span","font","a"]),li=new Set(["br","hr","img","video","audio","source","iframe","embed","object"]);function Nt(e){const t=e.toLowerCase();return ii.has(t)?"block":li.has(t)?"leaf":si.has(t)?"mark":"unknown"}var Xo=["bold","italic","underline","strikethrough","subscript","superscript","color","backcolor","fontFamily","fontSize","link","code"],D="http://www.w3.org/1999/xhtml",Ke=null,qe=null;function oi(e){return e&&typeof e.XmlText=="function"&&typeof e.XmlElement=="function"?(Ke=e.XmlText,qe=e.XmlElement,!0):!1}function zo(e){e&&oi(e.Y)||typeof window<"u"&&oi(window.Y)||(Ke=le,qe=gt)}function ai(e){return new(Ke||le)(e)}function ci(e){return new(qe||gt)(e)}function ae(e){return!!e&&typeof e.nodeName=="string"&&typeof e.getAttributes=="function"}function hi(e){return!!e&&typeof e.toDelta=="function"&&typeof e.nodeName!="string"}function Wo(e){return e?e.textContent&&e.textContent.trim().length>0?!0:!!e.querySelector&&!!e.querySelector("img,table,hr,video,iframe,figure,ul,ol,blockquote,pre"):!1}function ce(e,t){for(;t.firstChild;)t.removeChild(t.firstChild);const r=t.ownerDocument;if(!r)throw new Error("renderFragmentToHost: editable host has no ownerDocument");for(let n=0;n<e.length;n++){const i=e.get(n),s=Ze(i,r);s&&t.appendChild(s)}t.childNodes.length===0&&t.appendChild(r.createElementNS(D,"p"))}function Ze(e,t){return hi(e)?Ko(e,t):ae(e)?Jo(e,t):null}function Jo(e,t){const r=e.nodeName.toLowerCase(),n=Nt(r);if(n==="unknown"){const s=t.createElementNS(D,"span");return s.setAttribute("data-rte-unknown",r),fi(e,s),ui(e,s,t),s}const i=t.createElementNS(D,r);return fi(e,i),n==="leaf"||ui(e,i,t),i}function ui(e,t,r){const n=e.length;for(let i=0;i<n;i++){const s=e.get(i),l=Ze(s,r);l&&t.appendChild(l)}}function fi(e,t){const r=e.getAttributes();for(const[n,i]of Object.entries(r))i!=null&&t.setAttribute(n,String(i))}function Ko(e,t){var r;const n=t.createDocumentFragment(),i=e.toDelta();for(const s of i){if(typeof s.insert!="string"||s.insert.length===0)continue;const l=Zo(s.attributes);let o=t.createTextNode(s.insert);for(let a=l.length-1;a>=0;a--){const c=Qo(l[a],(r=s.attributes)!=null?r:{},t);c.appendChild(o),o=c}n.appendChild(o)}return n}var qo=["link","color","backcolor","fontFamily","fontSize","code","underline","strikethrough","subscript","superscript","italic","bold"];function Zo(e){if(!e)return[];const t=[];for(const r of qo)r in e&&e[r]!=null&&e[r]!==!1&&t.push(r);return t}function Qo(e,t,r){switch(e){case"bold":return r.createElementNS(D,"strong");case"italic":return r.createElementNS(D,"em");case"underline":return r.createElementNS(D,"u");case"strikethrough":return r.createElementNS(D,"s");case"subscript":return r.createElementNS(D,"sub");case"superscript":return r.createElementNS(D,"sup");case"code":return r.createElementNS(D,"code");case"link":{const n=r.createElementNS(D,"a"),i=t.link;return typeof i=="string"&&n.setAttribute("href",i),n}case"color":{const n=r.createElementNS(D,"span");return n.setAttribute("style",`color:${t.color}`),n}case"backcolor":{const n=r.createElementNS(D,"span");return n.setAttribute("style",`background-color:${t.backcolor}`),n}case"fontFamily":{const n=r.createElementNS(D,"span");return n.setAttribute("style",`font-family:${t.fontFamily}`),n}case"fontSize":{const n=r.createElementNS(D,"span");return n.setAttribute("style",`font-size:${t.fontSize}`),n}default:return r.createElementNS(D,"span")}}function di(e){var t;const r=(t=e.ownerDocument)==null?void 0:t.defaultView,n=r?.getSelection(),i={insideHost:!1,anchorPath:[],anchorOffset:0,focusPath:[],focusOffset:0};if(!n||n.rangeCount===0)return i;const s=n.getRangeAt(0);return!e.contains(s.startContainer)||!e.contains(s.endContainer)?i:{insideHost:!0,anchorPath:pi(e,s.startContainer),anchorOffset:s.startOffset,focusPath:pi(e,s.endContainer),focusOffset:s.endOffset}}function gi(e,t){if(!t.insideHost)return;const r=e.ownerDocument,n=r?.defaultView;if(!r||!n)return;const i=n.getSelection();if(!i)return;const s=vi(e,t.anchorPath,t.anchorOffset),l=t.anchorPath===t.focusPath?s:vi(e,t.focusPath,t.focusOffset);try{const o=r.createRange();o.setStart(s.node,s.offset),o.setEnd(l.node,l.offset),i.removeAllRanges(),i.addRange(o)}catch{}}function pi(e,t){const r=[];let n=t;for(;n&&n!==e;){const i=n.parentNode;if(!i)break;let s=0,l=i.firstChild;for(;l&&l!==n;)s++,l=l.nextSibling;r.unshift(s),n=i}return r}function vi(e,t,r){let n=e;for(const s of t){const l=n.childNodes.item(s);if(!l)return{node:n,offset:0};n=l}const i=ta(n,r);return{node:n,offset:i}}function ta(e,t){if(e.nodeType===3){const n=e.data.length;return Math.max(0,Math.min(t,n))}const r=e.childNodes.length;return Math.max(0,Math.min(t,r))}function ea(e){var t,r;const n=(t=e.editable.ownerDocument)==null?void 0:t.defaultView;if(!n)return{disconnect:()=>{},drainPending:()=>{}};const i=(r=n.MutationObserver)!=null?r:globalThis.MutationObserver;if(!i)return{disconnect:()=>{},drainPending:()=>{}};const s=new i(l=>{var o;e.isApplyingRemote()||(o=e.fragment.doc)==null||o.transact(()=>{for(const a of l)ra(a,e)},W)});return s.observe(e.editable,{childList:!0,subtree:!0,characterData:!0,characterDataOldValue:!0,attributes:!0,attributeOldValue:!0}),{disconnect:()=>s.disconnect(),drainPending:()=>{s.takeRecords()}}}function ra(e,t){switch(e.type){case"characterData":na(e,t);break;case"childList":ia(e,t);break;case"attributes":la(e,t);break}}function na(e,t){const r=e.target;if(r.nodeType!==3)return;const n=oa(r,t);if(!n)return;const i=r.data;n.toString()!==i&&(n.delete(0,n.length),n.insert(0,i))}function ia(e,t){if(e.target===t.editable){tr(t);return}e.target.nodeType===1&&sa(e.target,t)}function sa(e,t){const r=mi(e,t);if(!r){aa(t);return}r.delete(0,r.length);const n=ki(Array.from(e.childNodes));n.children.length>0&&(r.insert(0,n.children),er(n.marked))}function la(e,t){if(e.target.nodeType!==1)return;const r=e.target,n=mi(r,t);if(!n||e.attributeName===null)return;const i=r.getAttribute(e.attributeName);i===null?n.removeAttribute(e.attributeName):n.getAttribute(e.attributeName)!==i&&n.setAttribute(e.attributeName,i)}function oa(e,t){const r=wi(t.editable,e);if(r.length===0)return null;let n=t.fragment;for(let s=0;s<r.length-1;s++){const l=r[s],o=n.get(l);if(!ae(o))return null;n=o}const i=n.get(r[r.length-1]);return hi(i)?i:null}function mi(e,t){const r=wi(t.editable,e);if(r.length===0)return null;let n=t.fragment;for(const i of r){const s=n.get(i);if(!ae(s))return null;n=s}return ae(n)?n:null}function wi(e,t){const r=[];let n=t;for(;n&&n!==e;){const i=n.parentNode;if(!i)break;let s=0,l=i.firstChild;for(;l&&l!==n;)s++,l=l.nextSibling;r.unshift(s),n=i}return r}var Qe=new WeakSet;function aa(e){Qe.has(e.fragment)||(Qe.add(e.fragment),queueMicrotask(()=>{var t;Qe.delete(e.fragment),(t=e.fragment.doc)==null||t.transact(()=>tr(e),W)}))}function tr(e){e.fragment.delete(0,e.fragment.length);const t=bi(e.editable);t.children.length>0&&(e.fragment.insert(0,t.children),er(t.marked))}function bi(e){const t={children:[],marked:[]};for(let r=0;r<e.childNodes.length;r++){const n=e.childNodes.item(r),i=_i(n);if(i){i.node&&t.children.push(i.node);for(const s of i.marked)t.marked.push(s)}}return t}function _i(e){if(e.nodeType===3)return{node:ai(e.data),marked:[]};if(e.nodeType!==1)return null;const t=e,r=t.tagName.toLowerCase(),n=Nt(r);if(n==="mark")return null;const i=ci(r);for(const l of Array.from(t.attributes))i.setAttribute(l.name,l.value);if(n==="leaf")return{node:i,marked:[]};const s=ki(Array.from(t.childNodes));for(const l of s.children)i.insert(i.length,[l]);return{node:i,marked:s.marked}}function ca(){return{str:"",ranges:[]}}function ki(e){const t={marked:[],children:[]};let r=null;const n=()=>{if(r&&r.str.length>0){const s=ai(r.str);t.children.push(s),r.ranges.length>0&&t.marked.push({text:s,ranges:r.ranges})}r=null},i=()=>(r||(r=ca()),r);for(const s of e){if(s.nodeType===3){const c=s.data;if(c.length===0)continue;const h=i();h.str+=c;continue}if(s.nodeType!==1)continue;const l=s,o=l.tagName.toLowerCase(),a=Nt(o);if(a==="mark"){const c=i(),h=Ei(l);yi(l,c,h);continue}if(n(),a==="leaf"){const c=ci(o);for(const h of Array.from(l.attributes))c.setAttribute(h.name,h.value);t.children.push(c)}else{const c=_i(l);if(c&&c.node){t.children.push(c.node);for(const h of c.marked)t.marked.push(h)}}}return n(),t}function yi(e,t,r){for(const n of Array.from(e.childNodes)){if(n.nodeType===3){const l=n.data;if(l.length===0)continue;const o=t.str.length;t.str+=l;const a=t.str.length;Object.keys(r).length>0&&t.ranges.push({start:o,end:a,marks:r});continue}if(n.nodeType!==1)continue;const i=n;if(Nt(i.tagName.toLowerCase())==="mark"){const l={...r,...Ei(i)};yi(i,t,l)}}}function er(e){for(const t of e)for(const r of t.ranges){const n=r.end-r.start;n<=0||t.text.format(r.start,n,r.marks)}}var Si={buildYNodesFromDom:bi,applyDeferredMarks:er};function Ei(e){switch(e.tagName.toLowerCase()){case"strong":case"b":return{bold:!0};case"em":case"i":return{italic:!0};case"u":return{underline:!0};case"s":case"strike":case"del":return{strikethrough:!0};case"sub":return{subscript:!0};case"sup":return{superscript:!0};case"code":case"kbd":case"samp":return{code:!0};case"a":{const r=e.getAttribute("href");return r?{link:r}:{}}case"span":case"font":return ha(e);default:return{}}}function ha(e){var t;const r={},n=(t=e.getAttribute("style"))!=null?t:"";for(const i of n.split(";")){const[s,...l]=i.split(":");if(!s||l.length===0)continue;const o=s.trim().toLowerCase(),a=l.join(":").trim();if(a)switch(o){case"color":r.color=a;break;case"background-color":case"background":r.backcolor=a;break;case"font-family":r.fontFamily=a;break;case"font-size":r.fontSize=a;break}}if(e.tagName.toLowerCase()==="font"){const i=e.getAttribute("color");i&&(r.color=i);const s=e.getAttribute("face");s&&(r.fontFamily=s)}return r}function Ci(e){var t,r,n;zo(e);const i=(t=e.fragmentName)!=null?t:"default",s=e.ydoc.getXmlFragment(i),l=(n=e.awareness)!=null?n:(r=e.provider)==null?void 0:r.awareness;let o=!1;const a=ea({editable:e.editable,fragment:s,isApplyingRemote:()=>o}),c=Wo(e.editable);let h=!1,u=null;const f=()=>{if(!h){if(h=!0,u!=null){try{clearTimeout(u)}catch{}u=null}o=!0;try{if(s.length>0)ce(s,e.editable);else if(c&&e.seedFromHost!==!1){const $=s.doc;$&&$.transact(()=>tr({editable:e.editable,fragment:s}),W)}else ce(s,e.editable)}finally{a.drainPending(),o=!1}}};let d=()=>{};o=!0;const g=e.provider;if(g&&g.synced===!0)f();else if(g&&typeof g.on=="function"){const $=z=>{(z===void 0||z)&&f()};g.on("sync",$),g.on("synced",$),d=()=>{try{typeof g.off=="function"&&(g.off("sync",$),g.off("synced",$))}catch{}},typeof setTimeout=="function"?u=setTimeout(f,3e3):f()}else f();const p=($,z)=>{if(!h||z===W||z===W)return;const ya=di(e.editable);o=!0;try{ce(s,e.editable)}finally{a.drainPending(),o=!1}gi(e.editable,ya)};e.ydoc.on("update",p);const m=()=>{e.ydoc.off("update",p)},v=()=>a.disconnect(),j=ua(l,e.initialAwareness);let tt=[m,v,j,d];return{ydoc:e.ydoc,fragment:s,dispose(){for(const $ of tt)try{$()}catch(z){console.error("[crdt-engine] dispose cleanup error:",z)}tt=[]}}}function ua(e,t){return e?(t&&e.setLocalState(t),()=>e.setLocalState(null)):()=>{}}function fa(e){var t;const r=new Set([W]);if(e.extraTrackedOrigins)for(const n of e.extraTrackedOrigins)r.add(n);return new bo(e.fragment,{trackedOrigins:r,captureTimeout:(t=e.captureTimeoutMs)!=null?t:500})}var da=32;function ga(e){var t,r;const n=(t=e.editable.ownerDocument)==null?void 0:t.defaultView,i=e.editable.ownerDocument,s=(r=e.throttleMs)!=null?r:da;let l=null,o=null,a=null;const c=()=>{var f;if(!i)return;const d=n?.getSelection();if(!d||d.rangeCount===0){e.awareness.setLocalStateField("cursor",null);return}const g=d.getRangeAt(0);if(!e.editable.contains(g.startContainer)||!e.editable.contains(g.endContainer)){e.awareness.setLocalStateField("cursor",null);return}const p=Ti(e.fragment,e.editable,g.startContainer,g.startOffset),m=d.isCollapsed?p:Ti(e.fragment,e.editable,g.endContainer,g.endOffset);if(!p||!m){e.awareness.setLocalStateField("cursor",null);return}if(l&&o&&Ii(l,p)&&Ii(o,m))return;l=p,o=m;const v={...e.user?{user:e.user}:{},cursor:{anchor:{encoded:p},head:{encoded:m}}};e.awareness.setLocalState({...(f=e.awareness.getStates().get(e.awareness.clientID))!=null?f:{},...v,active:Date.now()})},h=()=>{a==null&&(a=setTimeout(()=>{a=null,c()},s))},u=()=>h();return i&&i.addEventListener("selectionchange",u),{dispose(){a!=null&&clearTimeout(a),i&&i.removeEventListener("selectionchange",u),e.awareness.setLocalStateField("cursor",null)},publishNow(){a!=null&&(clearTimeout(a),a=null),c()},snapshotPeers(){var f,d;const g=[];for(const[p,m]of e.awareness.getStates()){if(p===e.awareness.clientID)continue;const v=m;if(!v.cursor)continue;const j=Ai(e.fragment,e.editable,v.cursor.anchor.encoded),tt=v.cursor.head===v.cursor.anchor?j:Ai(e.fragment,e.editable,v.cursor.head.encoded);g.push({clientID:p,user:(f=v.user)!=null?f:{},anchor:j,head:tt,isCollapsed:j!==null&&tt!==null&&j.node===tt.node&&j.offset===tt.offset,activeAt:(d=v.active)!=null?d:0})}return g}}}function Ti(e,t,r,n){const i=pa(e,t,r,n);if(!i)return null;try{const s=ro(i.parent,i.index);return io(s)}catch{return null}}function Ai(e,t,r){if(!e.doc)return null;try{const n=lo(r),i=ao(n,e.doc);return i?va(t,i.type,i.index):null}catch{return null}}function pa(e,t,r,n){var i;const s=[];let l=n,o=r;if(o.nodeType===3)for(;o&&o!==t;){const u=o.parentNode;if(!u)break;let f=0,d=u.firstChild;for(;d&&d!==o;)f+=rr(d),d=d.nextSibling;if(l+=f,u===t||wa(u)){o=u;break}o=u}else if(o.nodeType===1){let u=0;for(let f=0;f<n&&f<o.childNodes.length;f++)u+=rr(o.childNodes.item(f));l=u}if(o===t){const u=(i=ba(t,r===t?t:r).at(0))!=null?i:0;return{parent:e,index:u}}let a=o;for(;a&&a!==t;){const u=a.parentNode;if(!u)return null;let f=0,d=u.firstChild;for(;d&&d!==a;)f++,d=d.nextSibling;s.unshift(f),a=u}let c=e;for(const u of s){const f=c.get(u);if(!(f instanceof gt))return null;c=f}const h=c.get(0);return h instanceof le?{parent:h,index:l}:{parent:c,index:0}}function va(e,t,r){const n=[];let i=t,s=!0;for(;i;){const a=i._item;if(!a)break;const c=a.parent;if(!c)break;let h=0,u=!1;if(c instanceof se||c instanceof gt){for(let f=0;f<c.length;f++)if(c.get(f)===i){h=f,u=!0;break}}if(!u)break;s&&t instanceof le||n.unshift(h),s=!1,i=c}let l=e;for(const a of n){const c=l.childNodes.item(a);if(!c)return null;l=c}return ma(l,r)}function ma(e,t){let r=t;const n=[];for(let i=e.childNodes.length-1;i>=0;i--)n.push(e.childNodes.item(i));for(;n.length>0;){const i=n.pop();if(i.nodeType===3){const s=i.data.length;if(r<=s)return{node:i,offset:r};r-=s;continue}if(i.nodeType===1)for(let s=i.childNodes.length-1;s>=0;s--)n.push(i.childNodes.item(s))}return{node:e,offset:e.childNodes.length}}function rr(e){if(e.nodeType===3)return e.data.length;let t=0;for(let r=0;r<e.childNodes.length;r++)t+=rr(e.childNodes.item(r));return t}function wa(e){if(e.nodeType!==1)return!1;const t=e.tagName.toLowerCase();return!["strong","b","em","i","u","s","strike","del","ins","mark","small","sub","sup","code","kbd","samp","var","span","font","a"].includes(t)}function ba(e,t){const r=[];let n=t;for(;n&&n!==e;){const i=n.parentNode;if(!i)break;let s=0,l=i.firstChild;for(;l&&l!==n;)s++,l=l.nextSibling;r.unshift(s),n=i}return r}function Ii(e,t){if(e.length!==t.length)return!1;for(let r=0;r<e.length;r++)if(e[r]!==t[r])return!1;return!0}function _a(e){var t,r;const n=(t=e.textSync)!=null?t:!1;if(n==="crdt")return Ci(e);if(n===!0){if(!e.legacySnapshotAttach)throw new Error("[crdt-engine] textSync: true requires `legacySnapshotAttach` to be provided by the host. See M5.1 in the sprint README for the back-compat contract.");return e.legacySnapshotAttach(e)}const i=e.ydoc.getXmlFragment((r=e.fragmentName)!=null?r:"default");return{ydoc:e.ydoc,fragment:i,dispose(){}}}function ka(e){var t;const r=(t=e.fragmentName)!=null?t:"default",n=e.ydoc.getXmlFragment(r),i=e.parserDocument.createElement("div");i.innerHTML=e.html;let s=i;const l=i.querySelector("body");l&&(s=l);const o=Si.buildYNodesFromDom(s);return e.replace!==!1&&n.length>0&&n.delete(0,n.length),o.children.length>0&&(n.insert(n.length,o.children),Si.applyDeferredMarks(o.marked)),n}typeof window<"u"&&(window.RichTextEditorCrdt=dr)})();
@@ -0,0 +1,174 @@
1
+ if (!window.RTE_DefaultConfig) window.RTE_DefaultConfig = {};
2
+
3
+ // 2026-06-07 Dialog accessibility. The editor's dialogs/popups render as
4
+ // <rte-dropdown-panel class="rte-panel-general"> containers that hold an
5
+ // <rte-dialog-header> title (e.g. "Insert Link") and fields wrapped in
6
+ // <rte-dialog-line-URL>, <rte-dialog-line-TEXT>, etc. — but the panel carries no
7
+ // role/aria-label and the fields carry no programmatic label, so a screen-reader
8
+ // user lands in an unnamed dialog on unlabeled inputs (WCAG 4.1.2 / 1.3.1 / 3.3.2).
9
+ //
10
+ // This plugin adds the missing metadata WITHOUT touching the core, deriving every
11
+ // name from the editor's OWN markup (never guessing): the dialog name is the
12
+ // header text, and each field's label is the `rte-dialog-line-<X>` suffix. Plain
13
+ // dropdowns (color/font pickers — no <rte-dialog-header>) are deliberately left
14
+ // alone so they aren't mislabeled as dialogs.
15
+ //
16
+ // Disable with config.dialogA11y = false.
17
+ RTE_DefaultConfig.plugin_dialoga11y = RTE_Plugin_DialogA11y;
18
+ if (typeof RTE_DefaultConfig.dialogA11y === "undefined") RTE_DefaultConfig.dialogA11y = true;
19
+
20
+ function RTE_Plugin_DialogA11y() {
21
+ var obj = this;
22
+ var config, editor, boundDoc = null, observer = null, timer = null;
23
+ var pending = [];
24
+
25
+ obj.PluginName = "DialogA11y";
26
+
27
+ // Nicer wording for known field-line suffixes; anything else is title-cased.
28
+ var LINE_LABELS = {
29
+ URL: "URL", SRC: "Source URL", HREF: "URL", LINK: "URL",
30
+ TEXT: "Text", TITLE: "Title", NAME: "Name", CAPTION: "Caption",
31
+ TARGET: "Open in a new window", ALT: "Alternative text",
32
+ WIDTH: "Width", HEIGHT: "Height", SIZE: "Size",
33
+ CLASS: "CSS class", STYLE: "Style", LANG: "Language",
34
+ ROWS: "Rows", COLS: "Columns", COLUMNS: "Columns", BORDER: "Border"
35
+ };
36
+
37
+ obj.InitConfig = function (argconfig) { config = argconfig; };
38
+
39
+ obj.InitEditor = function (argeditor) {
40
+ editor = argeditor;
41
+ if (config.dialogA11y === false) return;
42
+ setup();
43
+ try { editor.attachEvent("ready", setup); } catch (e) {}
44
+ setTimeout(setup, 0); setTimeout(setup, 300);
45
+ editor.applyDialogAccessibility = function () { enhanceAll(hostDoc()); };
46
+ };
47
+
48
+ function hostDoc() {
49
+ try { if (config.container && config.container.ownerDocument) return config.container.ownerDocument; } catch (e) {}
50
+ return (typeof document !== "undefined") ? document : null;
51
+ }
52
+
53
+ function setup() {
54
+ var host = hostDoc(); if (!host) return;
55
+ enhanceAll(host);
56
+ if (host === boundDoc || observer) return;
57
+ boundDoc = host;
58
+ try {
59
+ var MO = (host.defaultView && host.defaultView.MutationObserver) || window.MutationObserver;
60
+ observer = new MO(onMutations);
61
+ observer.observe(host.body || host.documentElement, {
62
+ subtree: true, childList: true, attributes: true, attributeFilter: ["style", "class", "hidden"]
63
+ });
64
+ } catch (e) {}
65
+ }
66
+
67
+ function onMutations(muts) {
68
+ for (var i = 0; i < muts.length; i++) {
69
+ var m = muts[i];
70
+ if (m.type === "attributes" && isPanel(m.target)) schedule(m.target);
71
+ if (m.addedNodes) {
72
+ for (var j = 0; j < m.addedNodes.length; j++) {
73
+ var n = m.addedNodes[j];
74
+ if (n.nodeType !== 1) continue;
75
+ if (isPanel(n)) schedule(n);
76
+ if (n.querySelectorAll) {
77
+ var ps = n.querySelectorAll("rte-dropdown-panel,[class*='rte-panel-general']");
78
+ for (var k = 0; k < ps.length; k++) schedule(ps[k]);
79
+ }
80
+ }
81
+ }
82
+ }
83
+ }
84
+
85
+ function isPanel(el) {
86
+ return el && el.nodeType === 1 &&
87
+ (el.tagName === "RTE-DROPDOWN-PANEL" || /rte-panel-general/.test(el.className || ""));
88
+ }
89
+
90
+ function schedule(panel) {
91
+ if (pending.indexOf(panel) < 0) pending.push(panel);
92
+ if (timer) return;
93
+ timer = setTimeout(function () {
94
+ timer = null;
95
+ var list = pending.slice(); pending.length = 0;
96
+ for (var i = 0; i < list.length; i++) {
97
+ enhancePanel(list[i]);
98
+ // Some dialog fields render lazily after the panel opens; run a
99
+ // second pass so they still get labelled.
100
+ (function (pnl) { setTimeout(function () { enhancePanel(pnl); }, 60); })(list[i]);
101
+ }
102
+ }, 0);
103
+ }
104
+
105
+ function enhanceAll(host) {
106
+ if (!host || !host.querySelectorAll) return;
107
+ var ps = host.querySelectorAll("rte-dropdown-panel,[class*='rte-panel-general']");
108
+ for (var i = 0; i < ps.length; i++) enhancePanel(ps[i]);
109
+ }
110
+
111
+ function enhancePanel(panel) {
112
+ if (!panel || panel.nodeType !== 1 || !panel.querySelector) return;
113
+ var headerEl = panel.querySelector("rte-dialog-header");
114
+ if (!headerEl) return; // only header-bearing panels are dialogs
115
+
116
+ var name = (headerEl.textContent || "").trim()
117
+ .replace(/\s*\((?:Ctrl|Cmd|Alt|Shift|⌘|⇧|⌥)[^)]*\)\s*$/i, "").trim();
118
+
119
+ // A titled, form-bearing popup is a dialog, not a menu — override the
120
+ // core's default role="menu" (a menu must not contain text fields).
121
+ var role = panel.getAttribute("role");
122
+ if (!role || role === "menu") panel.setAttribute("role", "dialog");
123
+ if (name && !panel.getAttribute("aria-label") && !panel.getAttribute("aria-labelledby")) {
124
+ panel.setAttribute("aria-label", name);
125
+ }
126
+
127
+ var fields = panel.querySelectorAll("input,select,textarea");
128
+ for (var i = 0; i < fields.length; i++) {
129
+ var f = fields[i];
130
+ if (f.type === "hidden") continue;
131
+ if (f.getAttribute("aria-label") || f.getAttribute("aria-labelledby")) continue;
132
+ if (f.labels && f.labels.length) continue;
133
+ var label = fieldLabel(f, name);
134
+ if (label) f.setAttribute("aria-label", label);
135
+ }
136
+ }
137
+
138
+ function fieldLabel(f, dialogName) {
139
+ // 1) nearest <rte-dialog-line-X> ancestor — the suffix is the field meaning
140
+ var n = f.parentElement;
141
+ for (var i = 0; i < 8 && n; i++) {
142
+ var mm = /^RTE-DIALOG-LINE-(.+)$/.exec(n.tagName || "");
143
+ if (mm) {
144
+ var key = mm[1].toUpperCase().replace(/-/g, " ").trim();
145
+ var first = key.split(" ")[0];
146
+ if (LINE_LABELS[key]) return LINE_LABELS[key];
147
+ if (LINE_LABELS[first]) return LINE_LABELS[first];
148
+ return titleCase(key);
149
+ }
150
+ n = n.parentElement;
151
+ }
152
+ // 2) placeholder
153
+ var ph = f.getAttribute("placeholder"); if (ph) return ph;
154
+ // 3) nearby visible text
155
+ var near = nearbyText(f); if (near) return near;
156
+ // 4) contextual fallback (the dialog name) — not wrong, just generic
157
+ return dialogName || null;
158
+ }
159
+
160
+ function nearbyText(f) {
161
+ var prev = f.previousElementSibling;
162
+ if (prev && prev.textContent && prev.textContent.trim() && prev.textContent.trim().length < 30) return prev.textContent.trim();
163
+ var par = f.parentElement;
164
+ if (par) {
165
+ for (var k = 0; k < par.childNodes.length; k++) {
166
+ var nd = par.childNodes[k];
167
+ if (nd.nodeType === 3 && nd.textContent.trim()) return nd.textContent.trim().slice(0, 40);
168
+ }
169
+ }
170
+ return "";
171
+ }
172
+
173
+ function titleCase(s) { return s.toLowerCase().replace(/\b\w/g, function (c) { return c.toUpperCase(); }); }
174
+ }