@inkeep/open-knowledge 0.0.0-dev-20260501034226 → 0.0.0-dev-20260501045551

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 (38) hide show
  1. package/dist/THIRD_PARTY_NOTICES.md +15 -0
  2. package/dist/cli.mjs +7 -7
  3. package/dist/constants-CYAWu1t_.mjs +2 -0
  4. package/dist/index.mjs +1 -1
  5. package/dist/init-3aNImgts.mjs +1 -0
  6. package/dist/{init-298Ayrtx.mjs → init-C4wke4uB.mjs} +2 -2
  7. package/dist/{init-CXD7S1br.mjs → init-CD1Q6xzB.mjs} +3 -3
  8. package/dist/init-DcSlN0vZ.mjs +1 -0
  9. package/dist/loader-C-9Jcwv3.mjs +1 -0
  10. package/dist/{loader-CBGPucqb.mjs → loader-LlG0LgdL.mjs} +2 -2
  11. package/dist/paths-CinA1Uub.mjs +2 -0
  12. package/dist/paths-D8xkWudL.mjs +1 -0
  13. package/dist/{preview-YdZO7Xe-.mjs → preview-BaEgnUY0.mjs} +2 -2
  14. package/dist/preview-j16n7DSe.mjs +1 -0
  15. package/dist/public/assets/{ActivityModeContent-Dh5iGi22.js → ActivityModeContent-BLbgxGR9.js} +1 -1
  16. package/dist/public/assets/{DocumentContext-BtLDstmc.js → DocumentContext-CjSzCZL0.js} +1 -1
  17. package/dist/public/assets/SettingsPane-ztNlE-yh.js +6 -0
  18. package/dist/public/assets/{SourceEditor-C0WLCZqD.js → SourceEditor-D-FWP4Ng.js} +1 -1
  19. package/dist/public/assets/{clipboard-CIRkQ4_J.js → clipboard-DiHLkR-W.js} +1 -1
  20. package/dist/public/assets/config-validation-events-GcLpFEMN.js +1 -0
  21. package/dist/public/assets/{index-BbGfAZdV.css → index-Du0-WJgD.css} +1 -1
  22. package/dist/public/assets/{index-CrNx3AgB.js → index-kpNzOlZa.js} +72 -72
  23. package/dist/public/index.html +6 -6
  24. package/dist/src-aFcF98AM.mjs +1 -0
  25. package/dist/start-DW0GxweG.mjs +1 -0
  26. package/dist/{start-S8FFCxLU.mjs → start-cf2OdewF.mjs} +2 -2
  27. package/package.json +1 -1
  28. package/dist/constants-BVSgu1p0.mjs +0 -2
  29. package/dist/init-BRaqMC9N.mjs +0 -1
  30. package/dist/init-CFRhnDnB.mjs +0 -1
  31. package/dist/loader-Cl1JDwMN.mjs +0 -1
  32. package/dist/paths-B42XU6NV.mjs +0 -1
  33. package/dist/paths-C7JyDBWk.mjs +0 -2
  34. package/dist/preview-DMu5oITV.mjs +0 -1
  35. package/dist/public/assets/SettingsPane-C93_FdcE.js +0 -5
  36. package/dist/public/assets/config-validation-events-ClxIZ8iZ.js +0 -1
  37. package/dist/src-r-4kerBt.mjs +0 -1
  38. package/dist/start-DUwONCW8.mjs +0 -1
@@ -3,7 +3,7 @@ import{r as e,t}from"./chunk-DECur_0Z.js";import{i as n,n as r,t as i}from"./pro
3
3
  `)}},Wc=(e,t)=>e===t?!0:e==null||t==null||e.constructor!==t.constructor?!1:e[tc]?nc(e,t):ho(e)?fo(e,e=>po(t,t=>Wc(e,t))):rc(e)?lc(e,(e,n)=>Wc(e,t[n])):!1,Gc=class{static _dilutes=!1;extends(e){let[t,n]=[this.shape,e.shape];return this.constructor._dilutes&&([n,t]=[t,n]),Wc(t,n)}equals(e){return this.constructor===e.constructor&&gc(this.shape,e.shape)}[Hc](){return!0}[tc](e){return this.equals(e)}validate(e){return this.check(e)}check(e,t){Ts()}get nullable(){return wl(this,zl)}get optional(){return new nl(this)}cast(e){return Ul(e,this),e}expect(e){return Ul(e,this),e}},Kc=class extends Gc{constructor(e,t){super(),this.shape=e,this._c=t}check(e,t=void 0){let n=e?.constructor===this.shape&&(this._c==null||this._c(e));return!n&&t?.extend(null,this.shape.name,e?.constructor.name,e?.constructor===this.shape?`Check failed`:`Constructor match failed`),n}},qc=(e,t=null)=>new Kc(e,t);qc(Kc);var Jc=class extends Gc{constructor(e){super(),this.shape=e}check(e,t){let n=this.shape(e);return!n&&t?.extend(null,`custom prop`,e?.constructor.name,`failed to check custom prop`),n}},Yc=e=>new Jc(e);qc(Jc);var Xc=class extends Gc{constructor(e){super(),this.shape=e}check(e,t){let n=this.shape.some(t=>t===e);return!n&&t?.extend(null,this.shape.join(` | `),e.toString()),n}},Zc=(...e)=>new Xc(e),Qc=qc(Xc),$c=RegExp.escape||(e=>e.replace(/[().|&,$^[\]]/g,e=>`\\`+e)),el=e=>{if(Pl.check(e))return[$c(e)];if(Qc.check(e))return e.shape.map(e=>e+``);if(Nl.check(e))return[`[+-]?\\d+.?\\d*`];if(Fl.check(e))return[`.*`];if(Tl.check(e))return e.shape.map(el).flat(1);Es()};qc(class extends Gc{constructor(e){super(),this.shape=e,this._r=RegExp(`^`+e.map(el).map(e=>`(${e.join(`|`)})`).join(``)+`$`)}check(e,t){let n=this._r.exec(e)!=null;return!n&&t?.extend(null,this._r.toString(),e.toString(),`String doesn't match string template.`),n}});var tl=Symbol(`optional`),nl=class extends Gc{constructor(e){super(),this.shape=e}check(e,t){let n=e===void 0||this.shape.check(e);return!n&&t?.extend(null,`undefined (optional)`,`()`),n}get[tl](){return!0}},rl=qc(nl),il=class extends Gc{check(e,t){return t?.extend(null,`never`,typeof e),!1}};new il,qc(il);var al=class e extends Gc{constructor(e,t=!1){super(),this.shape=e,this._isPartial=t}static _dilutes=!0;get partial(){return new e(this.shape,!0)}check(e,t){return e==null?(t?.extend(null,`object`,`null`),!1):lc(this.shape,(n,r)=>{let i=this._isPartial&&!uc(e,r)||n.check(e[r],t);return!i&&t?.extend(r.toString(),n.toString(),typeof e[r],`Object property does not match`),i})}},ol=e=>new al(e),sl=qc(al),cl=Yc(e=>e!=null&&(e.constructor===Object||e.constructor==null)),ll=class extends Gc{constructor(e,t){super(),this.shape={keys:e,values:t}}check(e,t){return e!=null&&lc(e,(n,r)=>{let i=this.shape.keys.check(r,t);return!i&&t?.extend(r+``,`Record`,typeof e,i?`Key doesn't match schema`:`Value doesn't match value`),i&&this.shape.values.check(n,t)})}},ul=(e,t)=>new ll(e,t),dl=qc(ll),fl=class extends Gc{constructor(e){super(),this.shape=e}check(e,t){return e!=null&&lc(this.shape,(n,r)=>{let i=n.check(e[r],t);return!i&&t?.extend(r.toString(),`Tuple`,typeof n),i})}},pl=(...e)=>new fl(e);qc(fl);var ml=class extends Gc{constructor(e){super(),this.shape=e.length===1?e[0]:new Cl(e)}check(e,t){let n=ho(e)&&fo(e,e=>this.shape.check(e));return!n&&t?.extend(null,`Array`,``),n}},hl=(...e)=>new ml(e),gl=qc(ml),_l=Yc(e=>ho(e)),vl=class extends Gc{constructor(e,t){super(),this.shape=e,this._c=t}check(e,t){let n=e instanceof this.shape&&(this._c==null||this._c(e));return!n&&t?.extend(null,this.shape.name,e?.constructor.name),n}},yl=(e,t=null)=>new vl(e,t);qc(vl);var bl=yl(Gc),xl=qc(class extends Gc{constructor(e){super(),this.len=e.length-1,this.args=pl(...e.slice(-1)),this.res=e[this.len]}check(e,t){let n=e.constructor===Function&&e.length<=this.len;return!n&&t?.extend(null,`function`,typeof e),n}}),Sl=Yc(e=>typeof e==`function`);qc(class extends Gc{constructor(e){super(),this.shape=e}check(e,t){let n=fo(this.shape,n=>n.check(e,t));return!n&&t?.extend(null,`Intersectinon`,typeof e),n}},e=>e.shape.length>0);var Cl=class extends Gc{static _dilutes=!0;constructor(e){super(),this.shape=e}check(e,t){let n=po(this.shape,n=>n.check(e,t));return t?.extend(null,`Union`,typeof e),n}},wl=(...e)=>e.findIndex(e=>Tl.check(e))>=0?wl(...e.map(e=>Hl(e)).map(e=>Tl.check(e)?e.shape:[e]).flat(1)):e.length===1?e[0]:new Cl(e),Tl=qc(Cl),El=()=>!0,Dl=Yc(El),Ol=qc(Jc,e=>e.shape===El),kl=Yc(e=>typeof e==`bigint`),Al=Yc(e=>e===kl),jl=Yc(e=>typeof e==`symbol`);Yc(e=>e===jl);var Ml=Yc(e=>typeof e==`number`),Nl=Yc(e=>e===Ml),Pl=Yc(e=>typeof e==`string`),Fl=Yc(e=>e===Pl),Il=Yc(e=>typeof e==`boolean`),Ll=Yc(e=>e===Il),Rl=Zc(void 0);qc(Xc,e=>e.shape.length===1&&e.shape[0]===void 0),Zc(void 0);var zl=Zc(null),Bl=qc(Xc,e=>e.shape.length===1&&e.shape[0]===null);qc(Uint8Array),qc(Kc,e=>e.shape===Uint8Array);var Vl=wl(Ml,Pl,zl,Rl,kl,Il,jl);(()=>{let e=hl(Dl),t=ul(Pl,Dl),n=wl(Ml,Pl,zl,Il,e,t);return e.shape=n,t.shape.values=n,n})();var Hl=e=>{if(bl.check(e))return e;if(cl.check(e)){let t={};for(let n in e)t[n]=Hl(e[n]);return ol(t)}else if(_l.check(e))return wl(...e.map(Hl));else if(Vl.check(e))return Zc(e);else if(Sl.check(e))return qc(e);Es()},Ul=Ec?()=>{}:(e,t)=>{let n=new Uc;if(!t.check(e,n))throw ws(`Expected value to be of type ${t.constructor.name}.\n${n.toString()}`)},Wl=class{constructor(e){this.patterns=[],this.$state=e}if(e,t){return this.patterns.push({if:Hl(e),h:t}),this}else(e){return this.if(Dl,e)}done(){return(e,t)=>{for(let n=0;n<this.patterns.length;n++){let r=this.patterns[n];if(r.if.check(e))return r.h(e,t)}throw ws(`Unhandled pattern`)}}},Gl=(e=>new Wl(e))(Dl).if(Nl,(e,t)=>Ic(t,Lo,Io)).if(Fl,(e,t)=>Bc(t)).if(Ll,(e,t)=>Fc(t)).if(Al,(e,t)=>BigInt(Ic(t,Lo,Io))).if(Tl,(e,t)=>Kl(t,Vc(t,e.shape))).if(sl,(e,t)=>{let n={};for(let r in e.shape){let i=e.shape[r];if(rl.check(i)){if(Fc(t))continue;i=i.shape}n[r]=Gl(i,t)}return n}).if(gl,(e,t)=>{let n=[],r=Lc(t,0,42);for(let i=0;i<r;i++)n.push(Kl(t,e.shape));return n}).if(Qc,(e,t)=>Vc(t,e.shape)).if(Bl,(e,t)=>null).if(xl,(e,t)=>{let n=Kl(t,e.res);return()=>n}).if(Ol,(e,t)=>Kl(t,Vc(t,[Ml,Pl,zl,Rl,kl,Il,hl(Ml),ul(wl(`a`,`b`,`c`),Ml)]))).if(dl,(e,t)=>{let n={},r=Ic(t,0,3);for(let i=0;i<r;i++){let r=Kl(t,e.shape.keys);n[r]=Kl(t,e.shape.values)}return n}).done(),Kl=(e,t)=>Gl(Hl(t),e),ql=typeof document<`u`?document:{},Jl=e=>ql.createElement(e),Yl=()=>ql.createDocumentFragment();Yc(e=>e.nodeType===su);var Xl=e=>ql.createTextNode(e);typeof DOMParser<`u`&&new DOMParser;var Zl=(e,t)=>(Pc(t,(t,n)=>{n===!1?e.removeAttribute(t):n===!0?e.setAttribute(t,``):e.setAttribute(t,n)}),e),Ql=e=>{let t=Yl();for(let n=0;n<e.length;n++)ru(t,e[n]);return t},$l=(e,t)=>(ru(e,Ql(t)),e),eu=(e,t=[],n=[])=>$l(Zl(Jl(e),t),n);Yc(e=>e.nodeType===iu);var tu=Xl;Yc(e=>e.nodeType===au);var nu=e=>ao(e,(e,t)=>`${t}:${e};`).join(``),ru=(e,t)=>e.appendChild(t),iu=ql.ELEMENT_NODE,au=ql.TEXT_NODE;ql.CDATA_SECTION_NODE,ql.COMMENT_NODE;var ou=ql.DOCUMENT_NODE;ql.DOCUMENT_TYPE_NODE;var su=ql.DOCUMENT_FRAGMENT_NODE;Yc(e=>e.nodeType===ou);var cu=(e=>class{constructor(e){this._=e}destroy(){e(this._)}})(clearTimeout),lu=(e,t)=>new cu(setTimeout(t,e)),uu=Symbol,du=uu(),fu=uu(),pu=uu(),mu=uu(),hu=uu(),gu=uu(),_u=uu(),vu=uu(),yu=uu(),bu=e=>{e.length===1&&e[0]?.constructor===Function&&(e=e[0]());let t=[],n=[],r=0;for(;r<e.length;r++){let n=e[r];if(n===void 0)break;if(n.constructor===String||n.constructor===Number)t.push(n);else if(n.constructor===Object)break}for(r>0&&n.push(t.join(``));r<e.length;r++){let t=e[r];t instanceof Symbol||n.push(t)}return n};Xs();var xu={[du]:Nc(`font-weight`,`bold`),[fu]:Nc(`font-weight`,`normal`),[pu]:Nc(`color`,`blue`),[hu]:Nc(`color`,`green`),[mu]:Nc(`color`,`grey`),[gu]:Nc(`color`,`red`),[_u]:Nc(`color`,`purple`),[vu]:Nc(`color`,`orange`),[yu]:Nc(`color`,`black`)},Su=Dc?e=>{e.length===1&&e[0]?.constructor===Function&&(e=e[0]());let t=[],n=[],r=no(),i=[],a=0;for(;a<e.length;a++){let i=e[a],o=xu[i];if(o!==void 0)r.set(o.left,o.right);else{if(i===void 0)break;if(i.constructor===String||i.constructor===Number){let e=nu(r);a>0||e.length>0?(t.push(`%c`+i),n.push(e)):t.push(i)}else break}}for(a>0&&(i=n,i.unshift(t.join(``)));a<e.length;a++){let t=e[a];t instanceof Symbol||i.push(t)}return i}:bu,Cu=(...e)=>{console.log(...Su(e)),Tu.forEach(t=>t.print(e))},wu=(...e)=>{console.warn(...Su(e)),e.unshift(vu),Tu.forEach(t=>t.print(e))},Tu=so(),Eu=e=>({[Symbol.iterator](){return this},next:e}),Du=(e,t)=>Eu(()=>{let n;do n=e.next();while(!n.done&&!t(n.value));return n}),Ou=(e,t)=>Eu(()=>{let{done:n,value:r}=e.next();return{done:n,value:n?void 0:t(r)}}),ku=class{constructor(e,t){this.clock=e,this.len=t}},Au=class{constructor(){this.clients=new Map}},ju=(e,t,n)=>t.clients.forEach((t,r)=>{let i=e.doc.store.clients.get(r);if(i!=null){let r=i[i.length-1],a=r.id.clock+r.length;for(let r=0,o=t[r];r<t.length&&o.clock<a;o=t[++r])Yd(e,i,o.clock,o.len,n)}}),Mu=(e,t)=>{let n=0,r=e.length-1;for(;n<=r;){let i=vo((n+r)/2),a=e[i],o=a.clock;if(o<=t){if(t<o+a.len)return i;n=i+1}else r=i-1}return null},Nu=(e,t)=>{let n=e.clients.get(t.client);return n!==void 0&&Mu(n,t.clock)!==null},Pu=e=>{e.clients.forEach(e=>{e.sort((e,t)=>e.clock-t.clock);let t,n;for(t=1,n=1;t<e.length;t++){let r=e[n-1],i=e[t];r.clock+r.len>=i.clock?e[n-1]=new ku(r.clock,xo(r.len,i.clock+i.len-r.clock)):(n<t&&(e[n]=i),n++)}e.length=n})},Fu=e=>{let t=new Au;for(let n=0;n<e.length;n++)e[n].clients.forEach((r,i)=>{if(!t.clients.has(i)){let a=r.slice();for(let t=n+1;t<e.length;t++)lo(a,e[t].clients.get(i)||[]);t.clients.set(i,a)}});return Pu(t),t},Iu=(e,t,n,r)=>{io(e.clients,t,()=>[]).push(new ku(n,r))},Lu=()=>new Au,Ru=e=>{let t=Lu();return e.clients.forEach((e,n)=>{let r=[];for(let t=0;t<e.length;t++){let n=e[t];if(n.deleted){let i=n.id.clock,a=n.length;if(t+1<e.length)for(let n=e[t+1];t+1<e.length&&n.deleted;n=e[++t+1])a+=n.length;r.push(new ku(i,a))}}r.length>0&&t.clients.set(n,r)}),t},zu=(e,t)=>{is(e.restEncoder,t.clients.size),uo(t.clients.entries()).sort((e,t)=>t[0]-e[0]).forEach(([t,n])=>{e.resetDsCurVal(),is(e.restEncoder,t);let r=n.length;is(e.restEncoder,r);for(let t=0;t<r;t++){let r=n[t];e.writeDsClock(r.clock),e.writeDsLen(r.len)}})},Bu=e=>{let t=new Au,n=X(e.restDecoder);for(let r=0;r<n;r++){e.resetDsCurVal();let n=X(e.restDecoder),r=X(e.restDecoder);if(r>0){let i=io(t.clients,n,()=>[]);for(let t=0;t<r;t++)i.push(new ku(e.readDsClock(),e.readDsLen()))}}return t},Vu=(e,t,n)=>{let r=new Au,i=X(e.restDecoder);for(let a=0;a<i;a++){e.resetDsCurVal();let i=X(e.restDecoder),a=X(e.restDecoder),o=n.clients.get(i)||[],s=Vd(n,i);for(let n=0;n<a;n++){let n=e.readDsClock(),a=n+e.readDsLen();if(n<s){s<a&&Iu(r,i,s,a-s);let e=Ud(o,n),c=o[e];for(!c.deleted&&c.id.clock<n&&(o.splice(e+1,0,pm(t,c,n-c.id.clock)),e++);e<o.length&&(c=o[e++],c.id.clock<a);)c.deleted||(a<c.id.clock+c.length&&o.splice(e,0,pm(t,c,a-c.id.clock)),c.delete(t))}else Iu(r,i,n,a-n)}}if(r.clients.size>0){let e=new Zu;return is(e.restEncoder,0),zu(e,r),e.toUint8Array()}return null},Hu=Ks,Uu=class e extends go{constructor({guid:e=Ys(),collectionid:t=null,gc:n=!0,gcFilter:r=()=>!0,meta:i=null,autoLoad:a=!1,shouldLoad:o=!0}={}){super(),this.gc=n,this.gcFilter=r,this.clientID=Hu(),this.guid=e,this.collectionid=t,this.share=new Map,this.store=new zd,this._transaction=null,this._transactionCleanups=[],this.subdocs=new Set,this._item=null,this.shouldLoad=o,this.autoLoad=a,this.meta=i,this.isLoaded=!1,this.isSynced=!1,this.isDestroyed=!1,this.whenLoaded=Zs(e=>{this.on(`load`,()=>{this.isLoaded=!0,e(this)})});let s=()=>Zs(e=>{let t=n=>{(n===void 0||n===!0)&&(this.off(`sync`,t),e())};this.on(`sync`,t)});this.on(`sync`,e=>{e===!1&&this.isSynced&&(this.whenSynced=s()),this.isSynced=e===void 0||e===!0,this.isSynced&&!this.isLoaded&&this.emit(`load`,[this])}),this.whenSynced=s()}load(){let e=this._item;e!==null&&!this.shouldLoad&&rf(e.parent.doc,e=>{e.subdocsLoaded.add(this)},null,!0),this.shouldLoad=!0}getSubdocs(){return this.subdocs}getSubdocGuids(){return new Set(uo(this.subdocs).map(e=>e.guid))}transact(e,t=null){return rf(this,e,t)}get(e,t=Pf){let n=io(this.share,e,()=>{let e=new t;return e._integrate(this,null),e}),r=n.constructor;if(t!==Pf&&r!==t)if(r===Pf){let r=new t;r._map=n._map,n._map.forEach(e=>{for(;e!==null;e=e.left)e.parent=r}),r._start=n._start;for(let e=r._start;e!==null;e=e.right)e.parent=r;return r._length=n._length,this.share.set(e,r),r._integrate(this,null),r}else throw Error(`Type with the name ${e} has already been defined with a different constructor`);return n}getArray(e=``){return this.get(e,tp)}getText(e=``){return this.get(e,Sp)}getMap(e=``){return this.get(e,ip)}getXmlElement(e=``){return this.get(e,Dp)}getXmlFragment(e=``){return this.get(e,Tp)}toJSON(){let e={};return this.share.forEach((t,n)=>{e[n]=t.toJSON()}),e}destroy(){this.isDestroyed=!0,uo(this.subdocs).forEach(e=>e.destroy());let t=this._item;if(t!==null){this._item=null;let n=t.content;n.doc=new e({guid:this.guid,...n.opts,shouldLoad:!1}),n.doc._item=t,rf(t.parent.doc,e=>{let r=n.doc;t.deleted||e.subdocsAdded.add(r),e.subdocsRemoved.add(this)},null,!0)}this.emit(`destroyed`,[!0]),this.emit(`destroy`,[this]),super.destroy()}},Wu=class{constructor(e){this.restDecoder=e}resetDsCurVal(){}readDsClock(){return X(this.restDecoder)}readDsLen(){return X(this.restDecoder)}},Gu=class extends Wu{readLeftID(){return Z(X(this.restDecoder),X(this.restDecoder))}readRightID(){return Z(X(this.restDecoder),X(this.restDecoder))}readClient(){return X(this.restDecoder)}readInfo(){return Ps(this.restDecoder)}readString(){return Is(this.restDecoder)}readParentInfo(){return X(this.restDecoder)===1}readTypeRef(){return X(this.restDecoder)}readLen(){return X(this.restDecoder)}readAny(){return zs(this.restDecoder)}readBuf(){return Ac(Ns(this.restDecoder))}readJSON(){return JSON.parse(Is(this.restDecoder))}readKey(){return Is(this.restDecoder)}},Ku=class{constructor(e){this.dsCurrVal=0,this.restDecoder=e}resetDsCurVal(){this.dsCurrVal=0}readDsClock(){return this.dsCurrVal+=X(this.restDecoder),this.dsCurrVal}readDsLen(){let e=X(this.restDecoder)+1;return this.dsCurrVal+=e,e}},qu=class extends Ku{constructor(e){super(e),this.keys=[],X(e),this.keyClockDecoder=new Hs(Ns(e)),this.clientDecoder=new Vs(Ns(e)),this.leftClockDecoder=new Hs(Ns(e)),this.rightClockDecoder=new Hs(Ns(e)),this.infoDecoder=new Bs(Ns(e),Ps),this.stringDecoder=new Us(Ns(e)),this.parentInfoDecoder=new Bs(Ns(e),Ps),this.typeRefDecoder=new Vs(Ns(e)),this.lenDecoder=new Vs(Ns(e))}readLeftID(){return new bd(this.clientDecoder.read(),this.leftClockDecoder.read())}readRightID(){return new bd(this.clientDecoder.read(),this.rightClockDecoder.read())}readClient(){return this.clientDecoder.read()}readInfo(){return this.infoDecoder.read()}readString(){return this.stringDecoder.read()}readParentInfo(){return this.parentInfoDecoder.read()===1}readTypeRef(){return this.typeRefDecoder.read()}readLen(){return this.lenDecoder.read()}readAny(){return zs(this.restDecoder)}readBuf(){return Ns(this.restDecoder)}readJSON(){return zs(this.restDecoder)}readKey(){let e=this.keyClockDecoder.read();if(e<this.keys.length)return this.keys[e];{let e=this.stringDecoder.read();return this.keys.push(e),e}}},Ju=class{constructor(){this.restEncoder=Zo()}toUint8Array(){return es(this.restEncoder)}resetDsCurVal(){}writeDsClock(e){is(this.restEncoder,e)}writeDsLen(e){is(this.restEncoder,e)}},Yu=class extends Ju{writeLeftID(e){is(this.restEncoder,e.client),is(this.restEncoder,e.clock)}writeRightID(e){is(this.restEncoder,e.client),is(this.restEncoder,e.clock)}writeClient(e){is(this.restEncoder,e)}writeInfo(e){rs(this.restEncoder,e)}writeString(e){cs(this.restEncoder,e)}writeParentInfo(e){is(this.restEncoder,+!!e)}writeTypeRef(e){is(this.restEncoder,e)}writeLen(e){is(this.restEncoder,e)}writeAny(e){_s(this.restEncoder,e)}writeBuf(e){us(this.restEncoder,e)}writeJSON(e){cs(this.restEncoder,JSON.stringify(e))}writeKey(e){cs(this.restEncoder,e)}},Xu=class{constructor(){this.restEncoder=Zo(),this.dsCurrVal=0}toUint8Array(){return es(this.restEncoder)}resetDsCurVal(){this.dsCurrVal=0}writeDsClock(e){let t=e-this.dsCurrVal;this.dsCurrVal=e,is(this.restEncoder,t)}writeDsLen(e){e===0&&Es(),is(this.restEncoder,e-1),this.dsCurrVal+=e}},Zu=class extends Xu{constructor(){super(),this.keyMap=new Map,this.keyClock=0,this.keyClockEncoder=new Ss,this.clientEncoder=new bs,this.leftClockEncoder=new Ss,this.rightClockEncoder=new Ss,this.infoEncoder=new vs(rs),this.stringEncoder=new Cs,this.parentInfoEncoder=new vs(rs),this.typeRefEncoder=new bs,this.lenEncoder=new bs}toUint8Array(){let e=Zo();return is(e,0),us(e,this.keyClockEncoder.toUint8Array()),us(e,this.clientEncoder.toUint8Array()),us(e,this.leftClockEncoder.toUint8Array()),us(e,this.rightClockEncoder.toUint8Array()),us(e,es(this.infoEncoder)),us(e,this.stringEncoder.toUint8Array()),us(e,es(this.parentInfoEncoder)),us(e,this.typeRefEncoder.toUint8Array()),us(e,this.lenEncoder.toUint8Array()),ls(e,es(this.restEncoder)),es(e)}writeLeftID(e){this.clientEncoder.write(e.client),this.leftClockEncoder.write(e.clock)}writeRightID(e){this.clientEncoder.write(e.client),this.rightClockEncoder.write(e.clock)}writeClient(e){this.clientEncoder.write(e)}writeInfo(e){this.infoEncoder.write(e)}writeString(e){this.stringEncoder.write(e)}writeParentInfo(e){this.parentInfoEncoder.write(+!!e)}writeTypeRef(e){this.typeRefEncoder.write(e)}writeLen(e){this.lenEncoder.write(e)}writeAny(e){_s(this.restEncoder,e)}writeBuf(e){us(this.restEncoder,e)}writeJSON(e){_s(this.restEncoder,e)}writeKey(e){let t=this.keyMap.get(e);t===void 0?(this.keyClockEncoder.write(this.keyClock++),this.stringEncoder.write(e)):this.keyClockEncoder.write(t)}},Qu=(e,t,n,r)=>{r=xo(r,t[0].id.clock);let i=Ud(t,r);is(e.restEncoder,t.length-i),e.writeClient(n),is(e.restEncoder,r);let a=t[i];a.write(e,r-a.id.clock);for(let n=i+1;n<t.length;n++)t[n].write(e,0)},$u=(e,t,n)=>{let r=new Map;n.forEach((e,n)=>{Vd(t,n)>e&&r.set(n,e)}),Bd(t).forEach((e,t)=>{n.has(t)||r.set(t,0)}),is(e.restEncoder,r.size),uo(r.entries()).sort((e,t)=>t[0]-e[0]).forEach(([n,r])=>{Qu(e,t.clients.get(n),n,r)})},ed=(e,t)=>{let n=no(),r=X(e.restDecoder);for(let i=0;i<r;i++){let r=X(e.restDecoder),i=Array(r),a=e.readClient(),o=X(e.restDecoder);n.set(a,{i:0,refs:i});for(let n=0;n<r;n++){let r=e.readInfo();switch(31&r){case 0:{let t=e.readLen();i[n]=new Ip(Z(a,o),t),o+=t;break}case 10:{let t=X(e.restDecoder);i[n]=new bm(Z(a,o),t),o+=t;break}default:{let s=(r&192)==0,c=new gm(Z(a,o),null,(r&128)==128?e.readLeftID():null,null,(r&64)==64?e.readRightID():null,s?e.readParentInfo()?t.get(e.readString()):e.readLeftID():null,s&&(r&32)==32?e.readString():null,_m(e,r));i[n]=c,o+=c.length}}}}return n},td=(e,t,n)=>{let r=[],i=uo(n.keys()).sort((e,t)=>e-t);if(i.length===0)return null;let a=()=>{if(i.length===0)return null;let e=n.get(i[i.length-1]);for(;e.refs.length===e.i;)if(i.pop(),i.length>0)e=n.get(i[i.length-1]);else return null;return e},o=a();if(o===null)return null;let s=new zd,c=new Map,l=(e,t)=>{let n=c.get(e);(n==null||n>t)&&c.set(e,t)},u=o.refs[o.i++],d=new Map,f=()=>{for(let e of r){let t=e.id.client,r=n.get(t);r?(r.i--,s.clients.set(t,r.refs.slice(r.i)),n.delete(t),r.i=0,r.refs=[]):s.clients.set(t,[e]),i=i.filter(e=>e!==t)}r.length=0};for(;;){if(u.constructor!==bm){let i=io(d,u.id.client,()=>Vd(t,u.id.client))-u.id.clock;if(i<0)r.push(u),l(u.id.client,u.id.clock-1),f();else{let a=u.getMissing(e,t);if(a!==null){r.push(u);let e=n.get(a)||{refs:[],i:0};if(e.refs.length===e.i)l(a,Vd(t,a)),f();else{u=e.refs[e.i++];continue}}else (i===0||i<u.length)&&(u.integrate(e,i),d.set(u.id.client,u.id.clock+u.length))}}if(r.length>0)u=r.pop();else if(o!==null&&o.i<o.refs.length)u=o.refs[o.i++];else{if(o=a(),o===null)break;u=o.refs[o.i++]}}if(s.clients.size>0){let e=new Zu;return $u(e,s,new Map),is(e.restEncoder,0),{missing:c,update:e.toUint8Array()}}return null},nd=(e,t)=>$u(e,t.doc.store,t.beforeState),rd=(e,t,n,r=new qu(e))=>rf(t,e=>{e.local=!1;let t=!1,n=e.doc,i=n.store,a=td(e,i,ed(r,n)),o=i.pendingStructs;if(o){for(let[e,n]of o.missing)if(n<Vd(i,e)){t=!0;break}if(a){for(let[e,t]of a.missing){let n=o.missing.get(e);(n==null||n>t)&&o.missing.set(e,t)}o.update=mf([o.update,a.update])}}else i.pendingStructs=a;let s=Vu(r,e,i);if(i.pendingDs){let t=new qu(As(i.pendingDs));X(t.restDecoder);let n=Vu(t,e,i);s&&n?i.pendingDs=mf([s,n]):i.pendingDs=s||n}else i.pendingDs=s;if(t){let t=i.pendingStructs.update;i.pendingStructs=null,id(e.doc,t)}},n,!1),id=(e,t,n,r=qu)=>{let i=As(t);rd(i,e,n,new r(i))},ad=(e,t,n)=>id(e,t,n,Gu),od=(e,t,n=new Map)=>{$u(e,t.store,n),zu(e,Ru(t.store))},sd=(e,t=new Uint8Array([0]),n=new Zu)=>{od(n,e,ud(t));let r=[n.toUint8Array()];if(e.store.pendingDs&&r.push(e.store.pendingDs),e.store.pendingStructs&&r.push(hf(e.store.pendingStructs.update,t)),r.length>1){if(n.constructor===Yu)return ff(r.map((e,t)=>t===0?e:bf(e)));if(n.constructor===Zu)return mf(r)}return r[0]},cd=(e,t)=>sd(e,t,new Yu),ld=e=>{let t=new Map,n=X(e.restDecoder);for(let r=0;r<n;r++){let n=X(e.restDecoder),r=X(e.restDecoder);t.set(n,r)}return t},ud=e=>ld(new Wu(As(e))),dd=(e,t)=>(is(e.restEncoder,t.size),uo(t.entries()).sort((e,t)=>t[0]-e[0]).forEach(([t,n])=>{is(e.restEncoder,t),is(e.restEncoder,n)}),e),fd=(e,t)=>dd(e,Bd(t.store)),pd=(e,t=new Xu)=>(e instanceof Map?dd(t,e):fd(t,e),t.toUint8Array()),md=e=>pd(e,new Ju),hd=class{constructor(){this.l=[]}},gd=()=>new hd,_d=(e,t)=>e.l.push(t),vd=(e,t)=>{let n=e.l,r=n.length;e.l=n.filter(e=>t!==e),r===e.l.length&&console.error(`[yjs] Tried to remove event handler that doesn't exist.`)},yd=(e,t,n)=>mc(e.l,[t,n]),bd=class{constructor(e,t){this.client=e,this.clock=t}},xd=(e,t)=>e===t||e!==null&&t!==null&&e.client===t.client&&e.clock===t.clock,Z=(e,t)=>new bd(e,t),Sd=e=>{for(let[t,n]of e.doc.share.entries())if(n===e)return t;throw Es()},Cd=(e,t)=>{for(;t!==null;){if(t.parent===e)return!0;t=t.parent._item}return!1},wd=class{constructor(e,t,n,r=0){this.type=e,this.tname=t,this.item=n,this.assoc=r}},Td=e=>{let t={};return e.type&&(t.type=e.type),e.tname&&(t.tname=e.tname),e.item&&(t.item=e.item),e.assoc!=null&&(t.assoc=e.assoc),t},Ed=e=>new wd(e.type==null?null:Z(e.type.client,e.type.clock),e.tname??null,e.item==null?null:Z(e.item.client,e.item.clock),e.assoc==null?0:e.assoc),Dd=class{constructor(e,t,n=0){this.type=e,this.index=t,this.assoc=n}},Od=(e,t,n=0)=>new Dd(e,t,n),kd=(e,t,n)=>{let r=null,i=null;return e._item===null?i=Sd(e):r=Z(e._item.id.client,e._item.id.clock),new wd(r,i,t,n)},Ad=(e,t,n=0)=>{let r=e._start;if(n<0){if(t===0)return kd(e,null,n);t--}for(;r!==null;){if(!r.deleted&&r.countable){if(r.length>t)return kd(e,Z(r.id.client,r.id.clock+t),n);t-=r.length}if(r.right===null&&n<0)return kd(e,r.lastId,n);r=r.right}return kd(e,null,n)},jd=(e,t)=>{let n=Wd(e,t);return{item:n,diff:t.clock-n.id.clock}},Md=(e,t,n=!0)=>{let r=t.store,i=e.item,a=e.type,o=e.tname,s=e.assoc,c=null,l=0;if(i!==null){if(Vd(r,i.client)<=i.clock)return null;let e=n?dm(r,i):jd(r,i),t=e.item;if(!(t instanceof gm))return null;if(c=t.parent,c._item===null||!c._item.deleted){l=t.deleted||!t.countable?0:e.diff+(s>=0?0:1);let n=t.left;for(;n!==null;)!n.deleted&&n.countable&&(l+=n.length),n=n.left}}else{if(o!==null)c=t.get(o);else if(a!==null){if(Vd(r,a.client)<=a.clock)return null;let{item:e}=n?dm(r,a):{item:Wd(r,a)};if(e instanceof gm&&e.content instanceof lm)c=e.content.type;else return null}else throw Es();l=s>=0?c._length:0}return Od(c,l,e.assoc)},Nd=(e,t)=>e===t||e!==null&&t!==null&&e.tname===t.tname&&xd(e.item,t.item)&&xd(e.type,t.type)&&e.assoc===t.assoc,Pd=class{constructor(e,t){this.ds=e,this.sv=t}},Fd=(e,t)=>new Pd(e,t);Fd(Lu(),new Map);var Id=e=>Fd(Ru(e.store),Bd(e.store)),Ld=(e,t)=>t===void 0?!e.deleted:t.sv.has(e.id.client)&&(t.sv.get(e.id.client)||0)>e.id.clock&&!Nu(t.ds,e.id),Rd=(e,t)=>{let n=io(e.meta,Rd,so),r=e.doc.store;n.has(t)||(t.sv.forEach((t,n)=>{t<Vd(r,n)&&Kd(e,Z(n,t))}),ju(e,t.ds,e=>{}),n.add(t))},zd=class{constructor(){this.clients=new Map,this.pendingStructs=null,this.pendingDs=null}},Bd=e=>{let t=new Map;return e.clients.forEach((e,n)=>{let r=e[e.length-1];t.set(n,r.id.clock+r.length)}),t},Vd=(e,t)=>{let n=e.clients.get(t);if(n===void 0)return 0;let r=n[n.length-1];return r.id.clock+r.length},Hd=(e,t)=>{let n=e.clients.get(t.id.client);if(n===void 0)n=[],e.clients.set(t.id.client,n);else{let e=n[n.length-1];if(e.id.clock+e.length!==t.id.clock)throw Es()}n.push(t)},Ud=(e,t)=>{let n=0,r=e.length-1,i=e[r],a=i.id.clock;if(a===t)return r;let o=vo(t/(a+i.length-1)*r);for(;n<=r;){if(i=e[o],a=i.id.clock,a<=t){if(t<a+i.length)return o;n=o+1}else r=o-1;o=vo((n+r)/2)}throw Es()},Wd=(e,t)=>{let n=e.clients.get(t.client);return n[Ud(n,t.clock)]},Gd=(e,t,n)=>{let r=Ud(t,n),i=t[r];return i.id.clock<n&&i instanceof gm?(t.splice(r+1,0,pm(e,i,n-i.id.clock)),r+1):r},Kd=(e,t)=>{let n=e.doc.store.clients.get(t.client);return n[Gd(e,n,t.clock)]},qd=(e,t,n)=>{let r=t.clients.get(n.client),i=Ud(r,n.clock),a=r[i];return n.clock!==a.id.clock+a.length-1&&a.constructor!==Ip&&r.splice(i+1,0,pm(e,a,n.clock-a.id.clock+1)),a},Jd=(e,t,n)=>{let r=e.clients.get(t.id.client);r[Ud(r,t.id.clock)]=n},Yd=(e,t,n,r,i)=>{if(r===0)return;let a=n+r,o=Gd(e,t,n),s;do s=t[o++],a<s.id.clock+s.length&&Gd(e,t,a),i(s);while(o<t.length&&t[o].id.clock<a)},Xd=class{constructor(e,t,n){this.doc=e,this.deleteSet=new Au,this.beforeState=Bd(e.store),this.afterState=new Map,this.changed=new Map,this.changedParentTypes=new Map,this._mergeStructs=[],this.origin=t,this.meta=new Map,this.local=n,this.subdocsAdded=new Set,this.subdocsRemoved=new Set,this.subdocsLoaded=new Set,this._needFormattingCleanup=!1}},Zd=(e,t)=>t.deleteSet.clients.size===0&&!oo(t.afterState,(e,n)=>t.beforeState.get(n)!==e)?!1:(Pu(t.deleteSet),nd(e,t),zu(e,t.deleteSet),!0),Qd=(e,t,n)=>{let r=t._item;(r===null||r.id.clock<(e.beforeState.get(r.id.client)||0)&&!r.deleted)&&io(e.changed,t,so).add(n)},$d=(e,t)=>{let n=e[t],r=e[t-1],i=t;for(;i>0;n=r,r=e[--i-1]){if(r.deleted===n.deleted&&r.constructor===n.constructor&&r.mergeWith(n)){n instanceof gm&&n.parentSub!==null&&n.parent._map.get(n.parentSub)===n&&n.parent._map.set(n.parentSub,r);continue}break}let a=t-i;return a&&e.splice(t+1-a,a),a},ef=(e,t,n)=>{for(let[r,i]of e.clients.entries()){let e=t.clients.get(r);for(let r=i.length-1;r>=0;r--){let a=i[r],o=a.clock+a.len;for(let r=Ud(e,a.clock),i=e[r];r<e.length&&i.id.clock<o;i=e[++r]){let i=e[r];if(a.clock+a.len<=i.id.clock)break;i instanceof gm&&i.deleted&&!i.keep&&n(i)&&i.gc(t,!1)}}}},tf=(e,t)=>{e.clients.forEach((e,n)=>{let r=t.clients.get(n);for(let t=e.length-1;t>=0;t--){let n=e[t],i=bo(r.length-1,1+Ud(r,n.clock+n.len-1));for(let e=i,t=r[e];e>0&&t.id.clock>=n.clock;t=r[e])e-=1+$d(r,e)}})},nf=(e,t)=>{if(t<e.length){let n=e[t],r=n.doc,i=r.store,a=n.deleteSet,o=n._mergeStructs;try{Pu(a),n.afterState=Bd(n.doc.store),r.emit(`beforeObserverCalls`,[n,r]);let e=[];n.changed.forEach((t,r)=>e.push(()=>{(r._item===null||!r._item.deleted)&&r._callObserver(n,t)})),e.push(()=>{n.changedParentTypes.forEach((t,r)=>{r._dEH.l.length>0&&(r._item===null||!r._item.deleted)&&(t=t.filter(e=>e.target._item===null||!e.target._item.deleted),t.forEach(e=>{e.currentTarget=r,e._path=null}),t.sort((e,t)=>e.path.length-t.path.length),e.push(()=>{yd(r._dEH,t,n)}))}),e.push(()=>r.emit(`afterTransaction`,[n,r])),e.push(()=>{n._needFormattingCleanup&&yp(n)})}),mc(e,[])}finally{r.gc&&ef(a,i,r.gcFilter),tf(a,i),n.afterState.forEach((e,t)=>{let r=n.beforeState.get(t)||0;if(r!==e){let e=i.clients.get(t),n=xo(Ud(e,r),1);for(let t=e.length-1;t>=n;)t-=1+$d(e,t)}});for(let e=o.length-1;e>=0;e--){let{client:t,clock:n}=o[e].id,r=i.clients.get(t),a=Ud(r,n);a+1<r.length&&$d(r,a+1)>1||a>0&&$d(r,a)}if(!n.local&&n.afterState.get(r.clientID)!==n.beforeState.get(r.clientID)&&(Cu(vu,du,`[yjs] `,fu,gu,`Changed the client-id because another client seems to be using it.`),r.clientID=Hu()),r.emit(`afterTransactionCleanup`,[n,r]),r._observers.has(`update`)){let e=new Yu;Zd(e,n)&&r.emit(`update`,[e.toUint8Array(),n.origin,r,n])}if(r._observers.has(`updateV2`)){let e=new Zu;Zd(e,n)&&r.emit(`updateV2`,[e.toUint8Array(),n.origin,r,n])}let{subdocsAdded:s,subdocsLoaded:c,subdocsRemoved:l}=n;(s.size>0||l.size>0||c.size>0)&&(s.forEach(e=>{e.clientID=r.clientID,e.collectionid??=r.collectionid,r.subdocs.add(e)}),l.forEach(e=>r.subdocs.delete(e)),r.emit(`subdocs`,[{loaded:c,added:s,removed:l},r,n]),l.forEach(e=>e.destroy())),e.length<=t+1?(r._transactionCleanups=[],r.emit(`afterAllTransactions`,[r,e])):nf(e,t+1)}}},rf=(e,t,n=null,r=!0)=>{let i=e._transactionCleanups,a=!1,o=null;e._transaction===null&&(a=!0,e._transaction=new Xd(e,n,r),i.push(e._transaction),i.length===1&&e.emit(`beforeAllTransactions`,[e]),e.emit(`beforeTransaction`,[e._transaction,e]));try{o=t(e._transaction)}finally{if(a){let t=e._transaction===i[0];e._transaction=null,t&&nf(i,0)}}return o},af=class{constructor(e,t){this.insertions=t,this.deletions=e,this.meta=new Map}},of=(e,t,n)=>{ju(e,n.deletions,n=>{n instanceof gm&&t.scope.some(t=>t===e.doc||Cd(t,n))&&fm(n,!1)})},sf=(e,t,n)=>{let r=null,i=e.doc,a=e.scope;rf(i,n=>{for(;t.length>0&&e.currStackItem===null;){let r=i.store,o=t.pop(),s=new Set,c=[],l=!1;ju(n,o.insertions,e=>{if(e instanceof gm){if(e.redone!==null){let{item:t,diff:i}=dm(r,e.id);i>0&&(t=Kd(n,Z(t.id.client,t.id.clock+i))),e=t}!e.deleted&&a.some(t=>t===n.doc||Cd(t,e))&&c.push(e)}}),ju(n,o.deletions,e=>{e instanceof gm&&a.some(t=>t===n.doc||Cd(t,e))&&!Nu(o.insertions,e.id)&&s.add(e)}),s.forEach(t=>{l=hm(n,t,s,o.insertions,e.ignoreRemoteMapChanges,e)!==null||l});for(let t=c.length-1;t>=0;t--){let r=c[t];e.deleteFilter(r)&&(r.delete(n),l=!0)}e.currStackItem=l?o:null}n.changed.forEach((e,t)=>{e.has(null)&&t._searchMarker&&(t._searchMarker.length=0)}),r=n},e);let o=e.currStackItem;if(o!=null){let t=r.changedParentTypes;e.emit(`stack-item-popped`,[{stackItem:o,type:n,changedParentTypes:t,origin:e},e]),e.currStackItem=null}return o},cf=class extends go{constructor(e,{captureTimeout:t=500,captureTransaction:n=e=>!0,deleteFilter:r=()=>!0,trackedOrigins:i=new Set([null]),ignoreRemoteMapChanges:a=!1,doc:o=ho(e)?e[0].doc:e instanceof Uu?e:e.doc}={}){super(),this.scope=[],this.doc=o,this.addToScope(e),this.deleteFilter=r,i.add(this),this.trackedOrigins=i,this.captureTransaction=n,this.undoStack=[],this.redoStack=[],this.undoing=!1,this.redoing=!1,this.currStackItem=null,this.lastChange=0,this.ignoreRemoteMapChanges=a,this.captureTimeout=t,this.afterTransactionHandler=e=>{if(!this.captureTransaction(e)||!this.scope.some(t=>e.changedParentTypes.has(t)||t===this.doc)||!this.trackedOrigins.has(e.origin)&&(!e.origin||!this.trackedOrigins.has(e.origin.constructor)))return;let t=this.undoing,n=this.redoing,r=t?this.redoStack:this.undoStack;t?this.stopCapturing():n||this.clear(!1,!0);let i=new Au;e.afterState.forEach((t,n)=>{let r=e.beforeState.get(n)||0,a=t-r;a>0&&Iu(i,n,r,a)});let a=Xs(),o=!1;if(this.lastChange>0&&a-this.lastChange<this.captureTimeout&&r.length>0&&!t&&!n){let t=r[r.length-1];t.deletions=Fu([t.deletions,e.deleteSet]),t.insertions=Fu([t.insertions,i])}else r.push(new af(e.deleteSet,i)),o=!0;!t&&!n&&(this.lastChange=a),ju(e,e.deleteSet,t=>{t instanceof gm&&this.scope.some(n=>n===e.doc||Cd(n,t))&&fm(t,!0)});let s=[{stackItem:r[r.length-1],origin:e.origin,type:t?`redo`:`undo`,changedParentTypes:e.changedParentTypes},this];o?this.emit(`stack-item-added`,s):this.emit(`stack-item-updated`,s)},this.doc.on(`afterTransaction`,this.afterTransactionHandler),this.doc.on(`destroy`,()=>{this.destroy()})}addToScope(e){let t=new Set(this.scope);e=ho(e)?e:[e],e.forEach(e=>{t.has(e)||(t.add(e),(e instanceof Pf?e.doc!==this.doc:e!==this.doc)&&wu(`[yjs#509] Not same Y.Doc`),this.scope.push(e))})}addTrackedOrigin(e){this.trackedOrigins.add(e)}removeTrackedOrigin(e){this.trackedOrigins.delete(e)}clear(e=!0,t=!0){(e&&this.canUndo()||t&&this.canRedo())&&this.doc.transact(n=>{e&&(this.undoStack.forEach(e=>of(n,this,e)),this.undoStack=[]),t&&(this.redoStack.forEach(e=>of(n,this,e)),this.redoStack=[]),this.emit(`stack-cleared`,[{undoStackCleared:e,redoStackCleared:t}])})}stopCapturing(){this.lastChange=0}undo(){this.undoing=!0;let e;try{e=sf(this,this.undoStack,`undo`)}finally{this.undoing=!1}return e}redo(){this.redoing=!0;let e;try{e=sf(this,this.redoStack,`redo`)}finally{this.redoing=!1}return e}canUndo(){return this.undoStack.length>0}canRedo(){return this.redoStack.length>0}destroy(){this.trackedOrigins.delete(this),this.doc.off(`afterTransaction`,this.afterTransactionHandler),super.destroy()}};function*lf(e){let t=X(e.restDecoder);for(let n=0;n<t;n++){let t=X(e.restDecoder),n=e.readClient(),r=X(e.restDecoder);for(let i=0;i<t;i++){let t=e.readInfo();if(t===10){let t=X(e.restDecoder);yield new bm(Z(n,r),t),r+=t}else if(31&t){let i=(t&192)==0,a=new gm(Z(n,r),null,(t&128)==128?e.readLeftID():null,null,(t&64)==64?e.readRightID():null,i?e.readParentInfo()?e.readString():e.readLeftID():null,i&&(t&32)==32?e.readString():null,_m(e,t));yield a,r+=a.length}else{let t=e.readLen();yield new Ip(Z(n,r),t),r+=t}}}}var uf=class{constructor(e,t){this.gen=lf(e),this.curr=null,this.done=!1,this.filterSkips=t,this.next()}next(){do this.curr=this.gen.next().value||null;while(this.filterSkips&&this.curr!==null&&this.curr.constructor===bm);return this.curr}},df=class{constructor(e){this.currClient=0,this.startClock=0,this.written=0,this.encoder=e,this.clientStructs=[]}},ff=e=>mf(e,Gu,Yu),pf=(e,t)=>{if(e.constructor===Ip){let{client:n,clock:r}=e.id;return new Ip(Z(n,r+t),e.length-t)}else if(e.constructor===bm){let{client:n,clock:r}=e.id;return new bm(Z(n,r+t),e.length-t)}else{let n=e,{client:r,clock:i}=n.id;return new gm(Z(r,i+t),null,Z(r,i+t-1),null,n.rightOrigin,n.parent,n.parentSub,n.content.splice(t))}},mf=(e,t=qu,n=Zu)=>{if(e.length===1)return e[0];let r=e.map(e=>new t(As(e))),i=r.map(e=>new uf(e,!0)),a=null,o=new n,s=new df(o);for(;i=i.filter(e=>e.curr!==null),i.sort((e,t)=>{if(e.curr.id.client===t.curr.id.client){let n=e.curr.id.clock-t.curr.id.clock;return n===0?e.curr.constructor===t.curr.constructor?0:e.curr.constructor===bm?1:-1:n}else return t.curr.id.client-e.curr.id.client}),i.length!==0;){let e=i[0],t=e.curr.id.client;if(a!==null){let n=e.curr,r=!1;for(;n!==null&&n.id.clock+n.length<=a.struct.id.clock+a.struct.length&&n.id.client>=a.struct.id.client;)n=e.next(),r=!0;if(n===null||n.id.client!==t||r&&n.id.clock>a.struct.id.clock+a.struct.length)continue;if(t!==a.struct.id.client)_f(s,a.struct,a.offset),a={struct:n,offset:0},e.next();else if(a.struct.id.clock+a.struct.length<n.id.clock)if(a.struct.constructor===bm)a.struct.length=n.id.clock+n.length-a.struct.id.clock;else{_f(s,a.struct,a.offset);let e=n.id.clock-a.struct.id.clock-a.struct.length;a={struct:new bm(Z(t,a.struct.id.clock+a.struct.length),e),offset:0}}else{let t=a.struct.id.clock+a.struct.length-n.id.clock;t>0&&(a.struct.constructor===bm?a.struct.length-=t:n=pf(n,t)),a.struct.mergeWith(n)||(_f(s,a.struct,a.offset),a={struct:n,offset:0},e.next())}}else a={struct:e.curr,offset:0},e.next();for(let n=e.curr;n!==null&&n.id.client===t&&n.id.clock===a.struct.id.clock+a.struct.length&&n.constructor!==bm;n=e.next())_f(s,a.struct,a.offset),a={struct:n,offset:0}}return a!==null&&(_f(s,a.struct,a.offset),a=null),vf(s),zu(o,Fu(r.map(e=>Bu(e)))),o.toUint8Array()},hf=(e,t,n=qu,r=Zu)=>{let i=ud(t),a=new r,o=new df(a),s=new n(As(e)),c=new uf(s,!1);for(;c.curr;){let e=c.curr,t=e.id.client,n=i.get(t)||0;if(c.curr.constructor===bm){c.next();continue}if(e.id.clock+e.length>n)for(_f(o,e,xo(n-e.id.clock,0)),c.next();c.curr&&c.curr.id.client===t;)_f(o,c.curr,0),c.next();else for(;c.curr&&c.curr.id.client===t&&c.curr.id.clock+c.curr.length<=n;)c.next()}return vf(o),zu(a,Bu(s)),a.toUint8Array()},gf=e=>{e.written>0&&(e.clientStructs.push({written:e.written,restEncoder:es(e.encoder.restEncoder)}),e.encoder.restEncoder=Zo(),e.written=0)},_f=(e,t,n)=>{e.written>0&&e.currClient!==t.id.client&&gf(e),e.written===0&&(e.currClient=t.id.client,e.encoder.writeClient(t.id.client),is(e.encoder.restEncoder,t.id.clock+n)),t.write(e.encoder,n),e.written++},vf=e=>{gf(e);let t=e.encoder.restEncoder;is(t,e.clientStructs.length);for(let n=0;n<e.clientStructs.length;n++){let r=e.clientStructs[n];is(t,r.written),ls(t,r.restEncoder)}},yf=(e,t,n,r)=>{let i=new n(As(e)),a=new uf(i,!1),o=new r,s=new df(o);for(let e=a.curr;e!==null;e=a.next())_f(s,t(e),0);return vf(s),zu(o,Bu(i)),o.toUint8Array()},bf=e=>yf(e,hc,qu,Yu),xf=`You must not compute changes after the event-handler fired.`,Sf=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||=Cf(this.currentTarget,this.target)}deletes(e){return Nu(this.transaction.deleteSet,e.id)}get keys(){if(this._keys===null){if(this.transaction.doc._transactionCleanups.length===0)throw ws(xf);let e=new Map,t=this.target;this.transaction.changed.get(t).forEach(n=>{if(n!==null){let r=t._map.get(n),i,a;if(this.adds(r)){let e=r.left;for(;e!==null&&this.adds(e);)e=e.left;if(this.deletes(r))if(e!==null&&this.deletes(e))i=`delete`,a=co(e.content.getContent());else return;else e!==null&&this.deletes(e)?(i=`update`,a=co(e.content.getContent())):(i=`add`,a=void 0)}else if(this.deletes(r))i=`delete`,a=co(r.content.getContent());else return;e.set(n,{action:i,oldValue:a})}}),this._keys=e}return this._keys}get delta(){return this.changes.delta}adds(e){return e.id.clock>=(this.transaction.beforeState.get(e.id.client)||0)}get changes(){let e=this._changes;if(e===null){if(this.transaction.doc._transactionCleanups.length===0)throw ws(xf);let t=this.target,n=so(),r=so(),i=[];if(e={added:n,deleted:r,delta:i,keys:this.keys},this.transaction.changed.get(t).has(null)){let e=null,a=()=>{e&&i.push(e)};for(let i=t._start;i!==null;i=i.right)i.deleted?this.deletes(i)&&!this.adds(i)&&((e===null||e.delete===void 0)&&(a(),e={delete:0}),e.delete+=i.length,r.add(i)):this.adds(i)?((e===null||e.insert===void 0)&&(a(),e={insert:[]}),e.insert=e.insert.concat(i.content.getContent()),n.add(i)):((e===null||e.retain===void 0)&&(a(),e={retain:0}),e.retain+=i.length);e!==null&&e.retain===void 0&&a()}this._changes=e}return e}},Cf=(e,t)=>{let n=[];for(;t._item!==null&&t!==e;){if(t._item.parentSub!==null)n.unshift(t._item.parentSub);else{let e=0,r=t._item.parent._start;for(;r!==t._item&&r!==null;)!r.deleted&&r.countable&&(e+=r.length),r=r.right;n.unshift(e)}t=t._item.parent}return n},wf=()=>{wu(`Invalid access: Add Yjs type to a document before reading data.`)},Tf=80,Ef=0,Df=class{constructor(e,t){e.marker=!0,this.p=e,this.index=t,this.timestamp=Ef++}},Of=e=>{e.timestamp=Ef++},kf=(e,t,n)=>{e.p.marker=!1,e.p=t,t.marker=!0,e.index=n,e.timestamp=Ef++},Af=(e,t,n)=>{if(e.length>=Tf){let r=e.reduce((e,t)=>e.timestamp<t.timestamp?e:t);return kf(r,t,n),r}else{let r=new Df(t,n);return e.push(r),r}},jf=(e,t)=>{if(e._start===null||t===0||e._searchMarker===null)return null;let n=e._searchMarker.length===0?null:e._searchMarker.reduce((e,n)=>yo(t-e.index)<yo(t-n.index)?e:n),r=e._start,i=0;for(n!==null&&(r=n.p,i=n.index,Of(n));r.right!==null&&i<t;){if(!r.deleted&&r.countable){if(t<i+r.length)break;i+=r.length}r=r.right}for(;r.left!==null&&i>t;)r=r.left,!r.deleted&&r.countable&&(i-=r.length);for(;r.left!==null&&r.left.id.client===r.id.client&&r.left.id.clock+r.left.length===r.id.clock;)r=r.left,!r.deleted&&r.countable&&(i-=r.length);return n!==null&&yo(n.index-i)<r.parent.length/Tf?(kf(n,r,i),n):Af(e._searchMarker,r,i)},Mf=(e,t,n)=>{for(let r=e.length-1;r>=0;r--){let i=e[r];if(n>0){let t=i.p;for(t.marker=!1;t&&(t.deleted||!t.countable);)t=t.left,t&&!t.deleted&&t.countable&&(i.index-=t.length);if(t===null||t.marker===!0){e.splice(r,1);continue}i.p=t,t.marker=!0}(t<i.index||n>0&&t===i.index)&&(i.index=xo(t,i.index+n))}},Nf=(e,t,n)=>{let r=e,i=t.changedParentTypes;for(;io(i,e,()=>[]).push(n),e._item!==null;)e=e._item.parent;yd(r._eH,n,t)},Pf=class{constructor(){this._item=null,this._map=new Map,this._start=null,this.doc=null,this._length=0,this._eH=gd(),this._dEH=gd(),this._searchMarker=null}get parent(){return this._item?this._item.parent:null}_integrate(e,t){this.doc=e,this._item=t}_copy(){throw Ts()}clone(){throw Ts()}_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){_d(this._eH,e)}observeDeep(e){_d(this._dEH,e)}unobserve(e){vd(this._eH,e)}unobserveDeep(e){vd(this._dEH,e)}toJSON(){}},Ff=(e,t,n)=>{e.doc??wf(),t<0&&(t=e._length+t),n<0&&(n=e._length+n);let r=n-t,i=[],a=e._start;for(;a!==null&&r>0;){if(a.countable&&!a.deleted){let e=a.content.getContent();if(e.length<=t)t-=e.length;else{for(let n=t;n<e.length&&r>0;n++)i.push(e[n]),r--;t=0}}a=a.right}return i},If=e=>{e.doc??wf();let t=[],n=e._start;for(;n!==null;){if(n.countable&&!n.deleted){let e=n.content.getContent();for(let n=0;n<e.length;n++)t.push(e[n])}n=n.right}return t},Lf=(e,t)=>{let n=[],r=e._start;for(;r!==null;){if(r.countable&&Ld(r,t)){let e=r.content.getContent();for(let t=0;t<e.length;t++)n.push(e[t])}r=r.right}return n},Rf=(e,t)=>{let n=0,r=e._start;for(e.doc??wf();r!==null;){if(r.countable&&!r.deleted){let i=r.content.getContent();for(let r=0;r<i.length;r++)t(i[r],n++,e)}r=r.right}},zf=(e,t)=>{let n=[];return Rf(e,(r,i)=>{n.push(t(r,i,e))}),n},Bf=e=>{let t=e._start,n=null,r=0;return{[Symbol.iterator](){return this},next:()=>{if(n===null){for(;t!==null&&t.deleted;)t=t.right;if(t===null)return{done:!0,value:void 0};n=t.content.getContent(),r=0,t=t.right}let e=n[r++];return n.length<=r&&(n=null),{done:!1,value:e}}}},Vf=(e,t)=>{e.doc??wf();let n=jf(e,t),r=e._start;for(n!==null&&(r=n.p,t-=n.index);r!==null;r=r.right)if(!r.deleted&&r.countable){if(t<r.length)return r.content.getContent()[t];t-=r.length}},Hf=(e,t,n,r)=>{let i=n,a=e.doc,o=a.clientID,s=a.store,c=n===null?t._start:n.right,l=[],u=()=>{l.length>0&&(i=new gm(Z(o,Vd(s,o)),i,i&&i.lastId,c,c&&c.id,t,null,new Zp(l)),i.integrate(e,0),l=[])};r.forEach(n=>{if(n===null)l.push(n);else switch(n.constructor){case Number:case Object:case Boolean:case Array:case String:l.push(n);break;default:switch(u(),n.constructor){case Uint8Array:case ArrayBuffer:i=new gm(Z(o,Vd(s,o)),i,i&&i.lastId,c,c&&c.id,t,null,new Lp(new Uint8Array(n))),i.integrate(e,0);break;case Uu:i=new gm(Z(o,Vd(s,o)),i,i&&i.lastId,c,c&&c.id,t,null,new Hp(n)),i.integrate(e,0);break;default:if(n instanceof Pf)i=new gm(Z(o,Vd(s,o)),i,i&&i.lastId,c,c&&c.id,t,null,new lm(n)),i.integrate(e,0);else throw Error(`Unexpected content type in insert operation`)}}}),u()},Uf=()=>ws(`Length exceeded!`),Wf=(e,t,n,r)=>{if(n>t._length)throw Uf();if(n===0)return t._searchMarker&&Mf(t._searchMarker,n,r.length),Hf(e,t,null,r);let i=n,a=jf(t,n),o=t._start;for(a!==null&&(o=a.p,n-=a.index,n===0&&(o=o.prev,n+=o&&o.countable&&!o.deleted?o.length:0));o!==null;o=o.right)if(!o.deleted&&o.countable){if(n<=o.length){n<o.length&&Kd(e,Z(o.id.client,o.id.clock+n));break}n-=o.length}return t._searchMarker&&Mf(t._searchMarker,i,r.length),Hf(e,t,o,r)},Gf=(e,t,n)=>{let r=(t._searchMarker||[]).reduce((e,t)=>t.index>e.index?t:e,{index:0,p:t._start}).p;if(r)for(;r.right;)r=r.right;return Hf(e,t,r,n)},Kf=(e,t,n,r)=>{if(r===0)return;let i=n,a=r,o=jf(t,n),s=t._start;for(o!==null&&(s=o.p,n-=o.index);s!==null&&n>0;s=s.right)!s.deleted&&s.countable&&(n<s.length&&Kd(e,Z(s.id.client,s.id.clock+n)),n-=s.length);for(;r>0&&s!==null;)s.deleted||(r<s.length&&Kd(e,Z(s.id.client,s.id.clock+r)),s.delete(e),r-=s.length),s=s.right;if(r>0)throw Uf();t._searchMarker&&Mf(t._searchMarker,i,-a+r)},qf=(e,t,n)=>{let r=t._map.get(n);r!==void 0&&r.delete(e)},Jf=(e,t,n,r)=>{let i=t._map.get(n)||null,a=e.doc,o=a.clientID,s;if(r==null)s=new Zp([r]);else switch(r.constructor){case Number:case Object:case Boolean:case Array:case String:case Date:case BigInt:s=new Zp([r]);break;case Uint8Array:s=new Lp(r);break;case Uu:s=new Hp(r);break;default:if(r instanceof Pf)s=new lm(r);else throw Error(`Unexpected content type`)}new gm(Z(o,Vd(a.store,o)),i,i&&i.lastId,null,null,t,n,s).integrate(e,0)},Yf=(e,t)=>{e.doc??wf();let n=e._map.get(t);return n!==void 0&&!n.deleted?n.content.getContent()[n.length-1]:void 0},Xf=e=>{let t={};return e.doc??wf(),e._map.forEach((e,n)=>{e.deleted||(t[n]=e.content.getContent()[e.length-1])}),t},Zf=(e,t)=>{e.doc??wf();let n=e._map.get(t);return n!==void 0&&!n.deleted},Qf=(e,t)=>{let n={};return e._map.forEach((e,r)=>{let i=e;for(;i!==null&&(!t.sv.has(i.id.client)||i.id.clock>=(t.sv.get(i.id.client)||0));)i=i.left;i!==null&&Ld(i,t)&&(n[r]=i.content.getContent()[i.length-1])}),n},$f=e=>(e.doc??wf(),Du(e._map.entries(),e=>!e[1].deleted)),ep=class extends Sf{},tp=class e extends Pf{constructor(){super(),this._prelimContent=[],this._searchMarker=[]}static from(t){let n=new e;return n.push(t),n}_integrate(e,t){super._integrate(e,t),this.insert(0,this._prelimContent),this._prelimContent=null}_copy(){return new e}clone(){let t=new e;return t.insert(0,this.toArray().map(e=>e instanceof Pf?e.clone():e)),t}get length(){return this.doc??wf(),this._length}_callObserver(e,t){super._callObserver(e,t),Nf(this,e,new ep(this,e))}insert(e,t){this.doc===null?this._prelimContent.splice(e,0,...t):rf(this.doc,n=>{Wf(n,this,e,t)})}push(e){this.doc===null?this._prelimContent.push(...e):rf(this.doc,t=>{Gf(t,this,e)})}unshift(e){this.insert(0,e)}delete(e,t=1){this.doc===null?this._prelimContent.splice(e,t):rf(this.doc,n=>{Kf(n,this,e,t)})}get(e){return Vf(this,e)}toArray(){return If(this)}slice(e=0,t=this.length){return Ff(this,e,t)}toJSON(){return this.map(e=>e instanceof Pf?e.toJSON():e)}map(e){return zf(this,e)}forEach(e){Rf(this,e)}[Symbol.iterator](){return Bf(this)}_write(e){e.writeTypeRef(nm)}},np=e=>new tp,rp=class extends Sf{constructor(e,t,n){super(e,t),this.keysChanged=n}},ip=class e extends Pf{constructor(e){super(),this._prelimContent=null,e===void 0?this._prelimContent=new Map:this._prelimContent=new Map(e)}_integrate(e,t){super._integrate(e,t),this._prelimContent.forEach((e,t)=>{this.set(t,e)}),this._prelimContent=null}_copy(){return new e}clone(){let t=new e;return this.forEach((e,n)=>{t.set(n,e instanceof Pf?e.clone():e)}),t}_callObserver(e,t){Nf(this,e,new rp(this,e,t))}toJSON(){this.doc??wf();let e={};return this._map.forEach((t,n)=>{if(!t.deleted){let r=t.content.getContent()[t.length-1];e[n]=r instanceof Pf?r.toJSON():r}}),e}get size(){return[...$f(this)].length}keys(){return Ou($f(this),e=>e[0])}values(){return Ou($f(this),e=>e[1].content.getContent()[e[1].length-1])}entries(){return Ou($f(this),e=>[e[0],e[1].content.getContent()[e[1].length-1]])}forEach(e){this.doc??wf(),this._map.forEach((t,n)=>{t.deleted||e(t.content.getContent()[t.length-1],n,this)})}[Symbol.iterator](){return this.entries()}delete(e){this.doc===null?this._prelimContent.delete(e):rf(this.doc,t=>{qf(t,this,e)})}set(e,t){return this.doc===null?this._prelimContent.set(e,t):rf(this.doc,n=>{Jf(n,this,e,t)}),t}get(e){return Yf(this,e)}has(e){return Zf(this,e)}clear(){this.doc===null?this._prelimContent.clear():rf(this.doc,e=>{this.forEach(function(t,n,r){qf(e,r,n)})})}_write(e){e.writeTypeRef(rm)}},ap=e=>new ip,op=(e,t)=>e===t||typeof e==`object`&&typeof t==`object`&&e&&t&&dc(e,t),sp=class{constructor(e,t,n,r){this.left=e,this.right=t,this.index=n,this.currentAttributes=r}forward(){switch(this.right===null&&Es(),this.right.content.constructor){case Kp:this.right.deleted||dp(this.currentAttributes,this.right.content);break;default:this.right.deleted||(this.index+=this.right.length);break}this.left=this.right,this.right=this.right.right}},cp=(e,t,n)=>{for(;t.right!==null&&n>0;){switch(t.right.content.constructor){case Kp:t.right.deleted||dp(t.currentAttributes,t.right.content);break;default:t.right.deleted||(n<t.right.length&&Kd(e,Z(t.right.id.client,t.right.id.clock+n)),t.index+=t.right.length,n-=t.right.length);break}t.left=t.right,t.right=t.right.right}return t},lp=(e,t,n,r)=>{let i=new Map,a=r?jf(t,n):null;return a?cp(e,new sp(a.p.left,a.p,a.index,i),n-a.index):cp(e,new sp(null,t._start,0,i),n)},up=(e,t,n,r)=>{for(;n.right!==null&&(n.right.deleted===!0||n.right.content.constructor===Kp&&op(r.get(n.right.content.key),n.right.content.value));)n.right.deleted||r.delete(n.right.content.key),n.forward();let i=e.doc,a=i.clientID;r.forEach((r,o)=>{let s=n.left,c=n.right,l=new gm(Z(a,Vd(i.store,a)),s,s&&s.lastId,c,c&&c.id,t,null,new Kp(o,r));l.integrate(e,0),n.right=l,n.forward()})},dp=(e,t)=>{let{key:n,value:r}=t;r===null?e.delete(n):e.set(n,r)},fp=(e,t)=>{for(;e.right!==null&&(e.right.deleted||e.right.content.constructor===Kp&&op(t[e.right.content.key]??null,e.right.content.value));)e.forward()},pp=(e,t,n,r)=>{let i=e.doc,a=i.clientID,o=new Map;for(let s in r){let c=r[s],l=n.currentAttributes.get(s)??null;if(!op(l,c)){o.set(s,l);let{left:r,right:u}=n;n.right=new gm(Z(a,Vd(i.store,a)),r,r&&r.lastId,u,u&&u.id,t,null,new Kp(s,c)),n.right.integrate(e,0),n.forward()}}return o},mp=(e,t,n,r,i)=>{n.currentAttributes.forEach((e,t)=>{i[t]===void 0&&(i[t]=null)});let a=e.doc,o=a.clientID;fp(n,i);let s=pp(e,t,n,i),c=r.constructor===String?new $p(r):r instanceof Pf?new lm(r):new Wp(r),{left:l,right:u,index:d}=n;t._searchMarker&&Mf(t._searchMarker,n.index,c.getLength()),u=new gm(Z(o,Vd(a.store,o)),l,l&&l.lastId,u,u&&u.id,t,null,c),u.integrate(e,0),n.right=u,n.index=d,n.forward(),up(e,t,n,s)},hp=(e,t,n,r,i)=>{let a=e.doc,o=a.clientID;fp(n,i);let s=pp(e,t,n,i);iterationLoop:for(;n.right!==null&&(r>0||s.size>0&&(n.right.deleted||n.right.content.constructor===Kp));){if(!n.right.deleted)switch(n.right.content.constructor){case Kp:{let{key:t,value:a}=n.right.content,o=i[t];if(o!==void 0){if(op(o,a))s.delete(t);else{if(r===0)break iterationLoop;s.set(t,a)}n.right.delete(e)}else n.currentAttributes.set(t,a);break}default:r<n.right.length&&Kd(e,Z(n.right.id.client,n.right.id.clock+r)),r-=n.right.length;break}n.forward()}if(r>0){let i=``;for(;r>0;r--)i+=`
4
4
  `;n.right=new gm(Z(o,Vd(a.store,o)),n.left,n.left&&n.left.lastId,n.right,n.right&&n.right.id,t,null,new $p(i)),n.right.integrate(e,0),n.forward()}up(e,t,n,s)},gp=(e,t,n,r,i)=>{let a=t,o=no();for(;a&&(!a.countable||a.deleted);){if(!a.deleted&&a.content.constructor===Kp){let e=a.content;o.set(e.key,e)}a=a.right}let s=0,c=!1;for(;t!==a;){if(n===t&&(c=!0),!t.deleted){let n=t.content;switch(n.constructor){case Kp:{let{key:a,value:l}=n,u=r.get(a)??null;(o.get(a)!==n||u===l)&&(t.delete(e),s++,!c&&(i.get(a)??null)===l&&u!==l&&(u===null?i.delete(a):i.set(a,u))),!c&&!t.deleted&&dp(i,n);break}}}t=t.right}return s},_p=(e,t)=>{for(;t&&t.right&&(t.right.deleted||!t.right.countable);)t=t.right;let n=new Set;for(;t&&(t.deleted||!t.countable);){if(!t.deleted&&t.content.constructor===Kp){let r=t.content.key;n.has(r)?t.delete(e):n.add(r)}t=t.left}},vp=e=>{let t=0;return rf(e.doc,n=>{let r=e._start,i=e._start,a=no(),o=ro(a);for(;i;){if(i.deleted===!1)switch(i.content.constructor){case Kp:dp(o,i.content);break;default:t+=gp(n,r,i,a,o),a=ro(o),r=i;break}i=i.right}}),t},yp=e=>{let t=new Set,n=e.doc;for(let[r,i]of e.afterState.entries()){let a=e.beforeState.get(r)||0;i!==a&&Yd(e,n.store.clients.get(r),a,i,e=>{!e.deleted&&e.content.constructor===Kp&&e.constructor!==Ip&&t.add(e.parent)})}rf(n,n=>{ju(e,e.deleteSet,e=>{if(e instanceof Ip||!e.parent._hasFormatting||t.has(e.parent))return;let r=e.parent;e.content.constructor===Kp?t.add(r):_p(n,e)});for(let e of t)vp(e)})},bp=(e,t,n)=>{let r=n,i=ro(t.currentAttributes),a=t.right;for(;n>0&&t.right!==null;){if(t.right.deleted===!1)switch(t.right.content.constructor){case lm:case Wp:case $p:n<t.right.length&&Kd(e,Z(t.right.id.client,t.right.id.clock+n)),n-=t.right.length,t.right.delete(e);break}t.forward()}a&&gp(e,a,t.right,i,t.currentAttributes);let o=(t.left||t.right).parent;return o._searchMarker&&Mf(o._searchMarker,t.index,-r+n),t},xp=class extends Sf{constructor(e,t,n){super(e,t),this.childListChanged=!1,this.keysChanged=new Set,n.forEach(e=>{e===null?this.childListChanged=!0:this.keysChanged.add(e)})}get changes(){return this._changes===null&&(this._changes={keys:this.keys,delta:this.delta,added:new Set,deleted:new Set}),this._changes}get delta(){if(this._delta===null){let e=this.target.doc,t=[];rf(e,e=>{let n=new Map,r=new Map,i=this.target._start,a=null,o={},s=``,c=0,l=0,u=()=>{if(a!==null){let e=null;switch(a){case`delete`:l>0&&(e={delete:l}),l=0;break;case`insert`:(typeof s==`object`||s.length>0)&&(e={insert:s},n.size>0&&(e.attributes={},n.forEach((t,n)=>{t!==null&&(e.attributes[n]=t)}))),s=``;break;case`retain`:c>0&&(e={retain:c},cc(o)||(e.attributes=ic({},o))),c=0;break}e&&t.push(e),a=null}};for(;i!==null;){switch(i.content.constructor){case lm:case Wp:this.adds(i)?this.deletes(i)||(u(),a=`insert`,s=i.content.getContent()[0],u()):this.deletes(i)?(a!==`delete`&&(u(),a=`delete`),l+=1):i.deleted||(a!==`retain`&&(u(),a=`retain`),c+=1);break;case $p:this.adds(i)?this.deletes(i)||(a!==`insert`&&(u(),a=`insert`),s+=i.content.str):this.deletes(i)?(a!==`delete`&&(u(),a=`delete`),l+=i.length):i.deleted||(a!==`retain`&&(u(),a=`retain`),c+=i.length);break;case Kp:{let{key:t,value:s}=i.content;if(this.adds(i))this.deletes(i)||(op(n.get(t)??null,s)?s!==null&&i.delete(e):(a===`retain`&&u(),op(s,r.get(t)??null)?delete o[t]:o[t]=s));else if(this.deletes(i)){r.set(t,s);let e=n.get(t)??null;op(e,s)||(a===`retain`&&u(),o[t]=e)}else if(!i.deleted){r.set(t,s);let n=o[t];n!==void 0&&(op(n,s)?n!==null&&i.delete(e):(a===`retain`&&u(),s===null?delete o[t]:o[t]=s))}i.deleted||(a===`insert`&&u(),dp(n,i.content));break}}i=i.right}for(u();t.length>0;){let e=t[t.length-1];if(e.retain!==void 0&&e.attributes===void 0)t.pop();else break}}),this._delta=t}return this._delta}},Sp=class e extends Pf{constructor(e){super(),this._pending=e===void 0?[]:[()=>this.insert(0,e)],this._searchMarker=[],this._hasFormatting=!1}get length(){return this.doc??wf(),this._length}_integrate(e,t){super._integrate(e,t);try{this._pending.forEach(e=>e())}catch(e){console.error(e)}this._pending=null}_copy(){return new e}clone(){let t=new e;return t.applyDelta(this.toDelta()),t}_callObserver(e,t){super._callObserver(e,t);let n=new xp(this,e,t);Nf(this,e,n),!e.local&&this._hasFormatting&&(e._needFormattingCleanup=!0)}toString(){this.doc??wf();let e=``,t=this._start;for(;t!==null;)!t.deleted&&t.countable&&t.content.constructor===$p&&(e+=t.content.str),t=t.right;return e}toJSON(){return this.toString()}applyDelta(e,{sanitize:t=!0}={}){this.doc===null?this._pending.push(()=>this.applyDelta(e)):rf(this.doc,n=>{let r=new sp(null,this._start,0,new Map);for(let i=0;i<e.length;i++){let a=e[i];if(a.insert!==void 0){let o=!t&&typeof a.insert==`string`&&i===e.length-1&&r.right===null&&a.insert.slice(-1)===`
5
5
  `?a.insert.slice(0,-1):a.insert;(typeof o!=`string`||o.length>0)&&mp(n,this,r,o,a.attributes||{})}else a.retain===void 0?a.delete!==void 0&&bp(n,r,a.delete):hp(n,this,r,a.retain,a.attributes||{})}})}toDelta(e,t,n){this.doc??wf();let r=[],i=new Map,a=this.doc,o=``,s=this._start;function c(){if(o.length>0){let e={},t=!1;i.forEach((n,r)=>{t=!0,e[r]=n});let n={insert:o};t&&(n.attributes=e),r.push(n),o=``}}let l=()=>{for(;s!==null;){if(Ld(s,e)||t!==void 0&&Ld(s,t))switch(s.content.constructor){case $p:{let r=i.get(`ychange`);e!==void 0&&!Ld(s,e)?(r===void 0||r.user!==s.id.client||r.type!==`removed`)&&(c(),i.set(`ychange`,n?n(`removed`,s.id):{type:`removed`})):t!==void 0&&!Ld(s,t)?(r===void 0||r.user!==s.id.client||r.type!==`added`)&&(c(),i.set(`ychange`,n?n(`added`,s.id):{type:`added`})):r!==void 0&&(c(),i.delete(`ychange`)),o+=s.content.str;break}case lm:case Wp:{c();let e={insert:s.content.getContent()[0]};if(i.size>0){let t={};e.attributes=t,i.forEach((e,n)=>{t[n]=e})}r.push(e);break}case Kp:Ld(s,e)&&(c(),dp(i,s.content));break}s=s.right}c()};return e||t?rf(a,n=>{e&&Rd(n,e),t&&Rd(n,t),l()},`cleanup`):l(),r}insert(e,t,n){if(t.length<=0)return;let r=this.doc;r===null?this._pending.push(()=>this.insert(e,t,n)):rf(r,r=>{let i=lp(r,this,e,!n);n||(n={},i.currentAttributes.forEach((e,t)=>{n[t]=e})),mp(r,this,i,t,n)})}insertEmbed(e,t,n){let r=this.doc;r===null?this._pending.push(()=>this.insertEmbed(e,t,n||{})):rf(r,r=>{let i=lp(r,this,e,!n);mp(r,this,i,t,n||{})})}delete(e,t){if(t===0)return;let n=this.doc;n===null?this._pending.push(()=>this.delete(e,t)):rf(n,n=>{bp(n,lp(n,this,e,!0),t)})}format(e,t,n){if(t===0)return;let r=this.doc;r===null?this._pending.push(()=>this.format(e,t,n)):rf(r,r=>{let i=lp(r,this,e,!1);i.right!==null&&hp(r,this,i,t,n)})}removeAttribute(e){this.doc===null?this._pending.push(()=>this.removeAttribute(e)):rf(this.doc,t=>{qf(t,this,e)})}setAttribute(e,t){this.doc===null?this._pending.push(()=>this.setAttribute(e,t)):rf(this.doc,n=>{Jf(n,this,e,t)})}getAttribute(e){return Yf(this,e)}getAttributes(){return Xf(this)}_write(e){e.writeTypeRef(im)}},Cp=e=>new Sp,wp=class{constructor(e,t=()=>!0){this._filter=t,this._root=e,this._currentNode=e._start,this._firstCall=!0,e.doc??wf()}[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===Dp||t.constructor===Tp)&&t._start!==null)e=t._start;else for(;e!==null;){let t=e.next;if(t!==null){e=t;break}else e=e.parent===this._root?null:e.parent._item}while(e!==null&&(e.deleted||!this._filter(e.content.type)));return this._firstCall=!1,e===null?{value:void 0,done:!0}:(this._currentNode=e,{value:e.content.type,done:!1})}},Tp=class e extends Pf{constructor(){super(),this._prelimContent=[]}get firstChild(){let e=this._first;return e?e.content.getContent()[0]:null}_integrate(e,t){super._integrate(e,t),this.insert(0,this._prelimContent),this._prelimContent=null}_copy(){return new e}clone(){let t=new e;return t.insert(0,this.toArray().map(e=>e instanceof Pf?e.clone():e)),t}get length(){return this.doc??wf(),this._prelimContent===null?this._length:this._prelimContent.length}createTreeWalker(e){return new wp(this,e)}querySelector(e){e=e.toUpperCase();let t=new wp(this,t=>t.nodeName&&t.nodeName.toUpperCase()===e).next();return t.done?null:t.value}querySelectorAll(e){return e=e.toUpperCase(),uo(new wp(this,t=>t.nodeName&&t.nodeName.toUpperCase()===e))}_callObserver(e,t){Nf(this,e,new kp(this,t,e))}toString(){return zf(this,e=>e.toString()).join(``)}toJSON(){return this.toString()}toDOM(e=document,t={},n){let r=e.createDocumentFragment();return n!==void 0&&n._createAssociation(r,this),Rf(this,i=>{r.insertBefore(i.toDOM(e,t,n),null)}),r}insert(e,t){this.doc===null?this._prelimContent.splice(e,0,...t):rf(this.doc,n=>{Wf(n,this,e,t)})}insertAfter(e,t){if(this.doc!==null)rf(this.doc,n=>{let r=e&&e instanceof Pf?e._item:e;Hf(n,this,r,t)});else{let n=this._prelimContent,r=e===null?0:n.findIndex(t=>t===e)+1;if(r===0&&e!==null)throw ws(`Reference item not found`);n.splice(r,0,...t)}}delete(e,t=1){this.doc===null?this._prelimContent.splice(e,t):rf(this.doc,n=>{Kf(n,this,e,t)})}toArray(){return If(this)}push(e){this.insert(this.length,e)}unshift(e){this.insert(0,e)}get(e){return Vf(this,e)}slice(e=0,t=this.length){return Ff(this,e,t)}forEach(e){Rf(this,e)}_write(e){e.writeTypeRef(om)}},Ep=e=>new Tp,Dp=class e extends Tp{constructor(e=`UNDEFINED`){super(),this.nodeName=e,this._prelimAttrs=new Map}get nextSibling(){let e=this._item?this._item.next:null;return e?e.content.type:null}get prevSibling(){let e=this._item?this._item.prev:null;return e?e.content.type:null}_integrate(e,t){super._integrate(e,t),this._prelimAttrs.forEach((e,t)=>{this.setAttribute(t,e)}),this._prelimAttrs=null}_copy(){return new e(this.nodeName)}clone(){let t=new e(this.nodeName);return oc(this.getAttributes(),(e,n)=>{t.setAttribute(n,e)}),t.insert(0,this.toArray().map(e=>e instanceof Pf?e.clone():e)),t}toString(){let e=this.getAttributes(),t=[],n=[];for(let t in e)n.push(t);n.sort();let r=n.length;for(let i=0;i<r;i++){let r=n[i];t.push(r+`="`+e[r]+`"`)}let i=this.nodeName.toLocaleLowerCase();return`<${i}${t.length>0?` `+t.join(` `):``}>${super.toString()}</${i}>`}removeAttribute(e){this.doc===null?this._prelimAttrs.delete(e):rf(this.doc,t=>{qf(t,this,e)})}setAttribute(e,t){this.doc===null?this._prelimAttrs.set(e,t):rf(this.doc,n=>{Jf(n,this,e,t)})}getAttribute(e){return Yf(this,e)}hasAttribute(e){return Zf(this,e)}getAttributes(e){return e?Qf(this,e):Xf(this)}toDOM(e=document,t={},n){let r=e.createElement(this.nodeName),i=this.getAttributes();for(let e in i){let t=i[e];typeof t==`string`&&r.setAttribute(e,t)}return Rf(this,i=>{r.appendChild(i.toDOM(e,t,n))}),n!==void 0&&n._createAssociation(r,this),r}_write(e){e.writeTypeRef(am),e.writeKey(this.nodeName)}},Op=e=>new Dp(e.readKey()),kp=class extends Sf{constructor(e,t,n){super(e,n),this.childListChanged=!1,this.attributesChanged=new Set,t.forEach(e=>{e===null?this.childListChanged=!0:this.attributesChanged.add(e)})}},Ap=class e extends ip{constructor(e){super(),this.hookName=e}_copy(){return new e(this.hookName)}clone(){let t=new e(this.hookName);return this.forEach((e,n)=>{t.set(n,e)}),t}toDOM(e=document,t={},n){let r=t[this.hookName],i;return i=r===void 0?document.createElement(this.hookName):r.createDom(this),i.setAttribute(`data-yjs-hook`,this.hookName),n!==void 0&&n._createAssociation(i,this),i}_write(e){e.writeTypeRef(sm),e.writeKey(this.hookName)}},jp=e=>new Ap(e.readKey()),Mp=class e extends Sp{get nextSibling(){let e=this._item?this._item.next:null;return e?e.content.type:null}get prevSibling(){let e=this._item?this._item.prev:null;return e?e.content.type:null}_copy(){return new e}clone(){let t=new e;return t.applyDelta(this.toDelta()),t}toDOM(e=document,t,n){let r=e.createTextNode(this.toString());return n!==void 0&&n._createAssociation(r,this),r}toString(){return this.toDelta().map(e=>{let t=[];for(let n in e.attributes){let r=[];for(let t in e.attributes[n])r.push({key:t,value:e.attributes[n][t]});r.sort((e,t)=>e.key<t.key?-1:1),t.push({nodeName:n,attrs:r})}t.sort((e,t)=>e.nodeName<t.nodeName?-1:1);let n=``;for(let e=0;e<t.length;e++){let r=t[e];n+=`<${r.nodeName}`;for(let e=0;e<r.attrs.length;e++){let t=r.attrs[e];n+=` ${t.key}="${t.value}"`}n+=`>`}n+=e.insert;for(let e=t.length-1;e>=0;e--)n+=`</${t[e].nodeName}>`;return n}).join(``)}toJSON(){return this.toString()}_write(e){e.writeTypeRef(cm)}},Np=e=>new Mp,Pp=class{constructor(e,t){this.id=e,this.length=t}get deleted(){throw Ts()}mergeWith(e){return!1}write(e,t,n){throw Ts()}integrate(e,t){throw Ts()}},Fp=0,Ip=class extends Pp{get deleted(){return!0}delete(){}mergeWith(e){return this.constructor===e.constructor?(this.length+=e.length,!0):!1}integrate(e,t){t>0&&(this.id.clock+=t,this.length-=t),Hd(e.doc.store,this)}write(e,t){e.writeInfo(Fp),e.writeLen(this.length-t)}getMissing(e,t){return null}},Lp=class e{constructor(e){this.content=e}getLength(){return 1}getContent(){return[this.content]}isCountable(){return!0}copy(){return new e(this.content)}splice(e){throw Ts()}mergeWith(e){return!1}integrate(e,t){}delete(e){}gc(e){}write(e,t){e.writeBuf(this.content)}getRef(){return 3}},Rp=e=>new Lp(e.readBuf()),zp=class e{constructor(e){this.len=e}getLength(){return this.len}getContent(){return[]}isCountable(){return!1}copy(){return new e(this.len)}splice(t){let n=new e(this.len-t);return this.len=t,n}mergeWith(e){return this.len+=e.len,!0}integrate(e,t){Iu(e.deleteSet,t.id.client,t.id.clock,this.len),t.markDeleted()}delete(e){}gc(e){}write(e,t){e.writeLen(this.len-t)}getRef(){return 1}},Bp=e=>new zp(e.readLen()),Vp=(e,t)=>new Uu({guid:e,...t,shouldLoad:t.shouldLoad||t.autoLoad||!1}),Hp=class e{constructor(e){e._item&&console.error(`This document was already integrated as a sub-document. You should create a second instance instead with the same guid.`),this.doc=e;let t={};this.opts=t,e.gc||(t.gc=!1),e.autoLoad&&(t.autoLoad=!0),e.meta!==null&&(t.meta=e.meta)}getLength(){return 1}getContent(){return[this.doc]}isCountable(){return!0}copy(){return new e(Vp(this.doc.guid,this.opts))}splice(e){throw Ts()}mergeWith(e){return!1}integrate(e,t){this.doc._item=t,e.subdocsAdded.add(this.doc),this.doc.shouldLoad&&e.subdocsLoaded.add(this.doc)}delete(e){e.subdocsAdded.has(this.doc)?e.subdocsAdded.delete(this.doc):e.subdocsRemoved.add(this.doc)}gc(e){}write(e,t){e.writeString(this.doc.guid),e.writeAny(this.opts)}getRef(){return 9}},Up=e=>new Hp(Vp(e.readString(),e.readAny())),Wp=class e{constructor(e){this.embed=e}getLength(){return 1}getContent(){return[this.embed]}isCountable(){return!0}copy(){return new e(this.embed)}splice(e){throw Ts()}mergeWith(e){return!1}integrate(e,t){}delete(e){}gc(e){}write(e,t){e.writeJSON(this.embed)}getRef(){return 5}},Gp=e=>new Wp(e.readJSON()),Kp=class e{constructor(e,t){this.key=e,this.value=t}getLength(){return 1}getContent(){return[]}isCountable(){return!1}copy(){return new e(this.key,this.value)}splice(e){throw Ts()}mergeWith(e){return!1}integrate(e,t){let n=t.parent;n._searchMarker=null,n._hasFormatting=!0}delete(e){}gc(e){}write(e,t){e.writeKey(this.key),e.writeJSON(this.value)}getRef(){return 6}},qp=e=>new Kp(e.readKey(),e.readJSON()),Jp=class e{constructor(e){this.arr=e}getLength(){return this.arr.length}getContent(){return this.arr}isCountable(){return!0}copy(){return new e(this.arr)}splice(t){let n=new e(this.arr.slice(t));return this.arr=this.arr.slice(0,t),n}mergeWith(e){return this.arr=this.arr.concat(e.arr),!0}integrate(e,t){}delete(e){}gc(e){}write(e,t){let n=this.arr.length;e.writeLen(n-t);for(let r=t;r<n;r++){let t=this.arr[r];e.writeString(t===void 0?`undefined`:JSON.stringify(t))}}getRef(){return 2}},Yp=e=>{let t=e.readLen(),n=[];for(let r=0;r<t;r++){let t=e.readString();t===`undefined`?n.push(void 0):n.push(JSON.parse(t))}return new Jp(n)},Xp=wc(`node_env`)===`development`,Zp=class e{constructor(e){this.arr=e,Xp&&pc(e)}getLength(){return this.arr.length}getContent(){return this.arr}isCountable(){return!0}copy(){return new e(this.arr)}splice(t){let n=new e(this.arr.slice(t));return this.arr=this.arr.slice(0,t),n}mergeWith(e){return this.arr=this.arr.concat(e.arr),!0}integrate(e,t){}delete(e){}gc(e){}write(e,t){let n=this.arr.length;e.writeLen(n-t);for(let r=t;r<n;r++){let t=this.arr[r];e.writeAny(t)}}getRef(){return 8}},Qp=e=>{let t=e.readLen(),n=[];for(let r=0;r<t;r++)n.push(e.readAny());return new Zp(n)},$p=class e{constructor(e){this.str=e}getLength(){return this.str.length}getContent(){return this.str.split(``)}isCountable(){return!0}copy(){return new e(this.str)}splice(t){let n=new e(this.str.slice(t));this.str=this.str.slice(0,t);let r=this.str.charCodeAt(t-1);return r>=55296&&r<=56319&&(this.str=this.str.slice(0,t-1)+`�`,n.str=`�`+n.str.slice(1)),n}mergeWith(e){return this.str+=e.str,!0}integrate(e,t){}delete(e){}gc(e){}write(e,t){e.writeString(t===0?this.str:this.str.slice(t))}getRef(){return 4}},em=e=>new $p(e.readString()),tm=[np,ap,Cp,Op,Ep,jp,Np],nm=0,rm=1,im=2,am=3,om=4,sm=5,cm=6,lm=class e{constructor(e){this.type=e}getLength(){return 1}getContent(){return[this.type]}isCountable(){return!0}copy(){return new e(this.type._copy())}splice(e){throw Ts()}mergeWith(e){return!1}integrate(e,t){this.type._integrate(e.doc,t)}delete(e){let t=this.type._start;for(;t!==null;)t.deleted?t.id.clock<(e.beforeState.get(t.id.client)||0)&&e._mergeStructs.push(t):t.delete(e),t=t.right;this.type._map.forEach(t=>{t.deleted?t.id.clock<(e.beforeState.get(t.id.client)||0)&&e._mergeStructs.push(t):t.delete(e)}),e.changed.delete(this.type)}gc(e){let t=this.type._start;for(;t!==null;)t.gc(e,!0),t=t.right;this.type._start=null,this.type._map.forEach(t=>{for(;t!==null;)t.gc(e,!0),t=t.left}),this.type._map=new Map}write(e,t){this.type._write(e)}getRef(){return 7}},um=e=>new lm(tm[e.readTypeRef()](e)),dm=(e,t)=>{let n=t,r=0,i;do r>0&&(n=Z(n.client,n.clock+r)),i=Wd(e,n),r=n.clock-i.id.clock,n=i.redone;while(n!==null&&i instanceof gm);return{item:i,diff:r}},fm=(e,t)=>{for(;e!==null&&e.keep!==t;)e.keep=t,e=e.parent._item},pm=(e,t,n)=>{let{client:r,clock:i}=t.id,a=new gm(Z(r,i+n),t,Z(r,i+n-1),t.right,t.rightOrigin,t.parent,t.parentSub,t.content.splice(n));return t.deleted&&a.markDeleted(),t.keep&&(a.keep=!0),t.redone!==null&&(a.redone=Z(t.redone.client,t.redone.clock+n)),t.right=a,a.right!==null&&(a.right.left=a),e._mergeStructs.push(a),a.parentSub!==null&&a.right===null&&a.parent._map.set(a.parentSub,a),t.length=n,a},mm=(e,t)=>po(e,e=>Nu(e.deletions,t)),hm=(e,t,n,r,i,a)=>{let o=e.doc,s=o.store,c=o.clientID,l=t.redone;if(l!==null)return Kd(e,l);let u=t.parent._item,d=null,f;if(u!==null&&u.deleted===!0){if(u.redone===null&&(!n.has(u)||hm(e,u,n,r,i,a)===null))return null;for(;u.redone!==null;)u=Kd(e,u.redone)}let p=u===null?t.parent:u.content.type;if(t.parentSub===null){for(d=t.left,f=t;d!==null;){let t=d;for(;t!==null&&t.parent._item!==u;)t=t.redone===null?null:Kd(e,t.redone);if(t!==null&&t.parent._item===u){d=t;break}d=d.left}for(;f!==null;){let t=f;for(;t!==null&&t.parent._item!==u;)t=t.redone===null?null:Kd(e,t.redone);if(t!==null&&t.parent._item===u){f=t;break}f=f.right}}else if(f=null,t.right&&!i){for(d=t;d!==null&&d.right!==null&&(d.right.redone||Nu(r,d.right.id)||mm(a.undoStack,d.right.id)||mm(a.redoStack,d.right.id));)for(d=d.right;d.redone;)d=Kd(e,d.redone);if(d&&d.right!==null)return null}else d=p._map.get(t.parentSub)||null;let m=Z(c,Vd(s,c)),h=new gm(m,d,d&&d.lastId,f,f&&f.id,p,t.parentSub,t.content.copy());return t.redone=m,fm(h,!0),h.integrate(e,0),h},gm=class e extends Pp{constructor(e,t,n,r,i,a,o,s){super(e,s.getLength()),this.origin=n,this.left=t,this.right=r,this.rightOrigin=i,this.parent=a,this.parentSub=o,this.redone=null,this.content=s,this.info=this.content.isCountable()?2:0}set marker(e){(this.info&8)>0!==e&&(this.info^=8)}get marker(){return(this.info&8)>0}get keep(){return(this.info&1)>0}set keep(e){this.keep!==e&&(this.info^=1)}get countable(){return(this.info&2)>0}get deleted(){return(this.info&4)>0}set deleted(e){this.deleted!==e&&(this.info^=4)}markDeleted(){this.info|=4}getMissing(t,n){if(this.origin&&this.origin.client!==this.id.client&&this.origin.clock>=Vd(n,this.origin.client))return this.origin.client;if(this.rightOrigin&&this.rightOrigin.client!==this.id.client&&this.rightOrigin.clock>=Vd(n,this.rightOrigin.client))return this.rightOrigin.client;if(this.parent&&this.parent.constructor===bd&&this.id.client!==this.parent.client&&this.parent.clock>=Vd(n,this.parent.client))return this.parent.client;if(this.origin&&=(this.left=qd(t,n,this.origin),this.left.lastId),this.rightOrigin&&=(this.right=Kd(t,this.rightOrigin),this.right.id),this.left&&this.left.constructor===Ip||this.right&&this.right.constructor===Ip)this.parent=null;else if(!this.parent)this.left&&this.left.constructor===e?(this.parent=this.left.parent,this.parentSub=this.left.parentSub):this.right&&this.right.constructor===e&&(this.parent=this.right.parent,this.parentSub=this.right.parentSub);else if(this.parent.constructor===bd){let e=Wd(n,this.parent);e.constructor===Ip?this.parent=null:this.parent=e.content.type}return null}integrate(e,t){if(t>0&&(this.id.clock+=t,this.left=qd(e,e.doc.store,Z(this.id.client,this.id.clock-1)),this.origin=this.left.lastId,this.content=this.content.splice(t),this.length-=t),this.parent){if(!this.left&&(!this.right||this.right.left!==null)||this.left&&this.left.right!==this.right){let t=this.left,n;if(t!==null)n=t.right;else if(this.parentSub!==null)for(n=this.parent._map.get(this.parentSub)||null;n!==null&&n.left!==null;)n=n.left;else n=this.parent._start;let r=new Set,i=new Set;for(;n!==null&&n!==this.right;){if(i.add(n),r.add(n),xd(this.origin,n.origin)){if(n.id.client<this.id.client)t=n,r.clear();else if(xd(this.rightOrigin,n.rightOrigin))break}else if(n.origin!==null&&i.has(Wd(e.doc.store,n.origin)))r.has(Wd(e.doc.store,n.origin))||(t=n,r.clear());else break;n=n.right}this.left=t}if(this.left!==null)this.right=this.left.right,this.left.right=this;else{let e;if(this.parentSub!==null)for(e=this.parent._map.get(this.parentSub)||null;e!==null&&e.left!==null;)e=e.left;else e=this.parent._start,this.parent._start=this;this.right=e}this.right===null?this.parentSub!==null&&(this.parent._map.set(this.parentSub,this),this.left!==null&&this.left.delete(e)):this.right.left=this,this.parentSub===null&&this.countable&&!this.deleted&&(this.parent._length+=this.length),Hd(e.doc.store,this),this.content.integrate(e,this),Qd(e,this.parent,this.parentSub),(this.parent._item!==null&&this.parent._item.deleted||this.parentSub!==null&&this.right!==null)&&this.delete(e)}else new Ip(this.id,this.length).integrate(e,0)}get next(){let e=this.right;for(;e!==null&&e.deleted;)e=e.right;return e}get prev(){let e=this.left;for(;e!==null&&e.deleted;)e=e.left;return e}get lastId(){return this.length===1?this.id:Z(this.id.client,this.id.clock+this.length-1)}mergeWith(e){if(this.constructor===e.constructor&&xd(e.origin,this.lastId)&&this.right===e&&xd(this.rightOrigin,e.rightOrigin)&&this.id.client===e.id.client&&this.id.clock+this.length===e.id.clock&&this.deleted===e.deleted&&this.redone===null&&e.redone===null&&this.content.constructor===e.content.constructor&&this.content.mergeWith(e.content)){let t=this.parent._searchMarker;return t&&t.forEach(t=>{t.p===e&&(t.p=this,!this.deleted&&this.countable&&(t.index-=this.length))}),e.keep&&(this.keep=!0),this.right=e.right,this.right!==null&&(this.right.left=this),this.length+=e.length,!0}return!1}delete(e){if(!this.deleted){let t=this.parent;this.countable&&this.parentSub===null&&(t._length-=this.length),this.markDeleted(),Iu(e.deleteSet,this.id.client,this.id.clock,this.length),Qd(e,t,this.parentSub),this.content.delete(e)}}gc(e,t){if(!this.deleted)throw Es();this.content.gc(e),t?Jd(e,this,new Ip(this.id,this.length)):this.content=new zp(this.length)}write(e,t){let n=t>0?Z(this.id.client,this.id.clock+t-1):this.origin,r=this.rightOrigin,i=this.parentSub,a=this.content.getRef()&31|(n===null?0:128)|(r===null?0:64)|(i===null?0:32);if(e.writeInfo(a),n!==null&&e.writeLeftID(n),r!==null&&e.writeRightID(r),n===null&&r===null){let t=this.parent;if(t._item!==void 0){let n=t._item;if(n===null){let n=Sd(t);e.writeParentInfo(!0),e.writeString(n)}else e.writeParentInfo(!1),e.writeLeftID(n.id)}else t.constructor===String?(e.writeParentInfo(!0),e.writeString(t)):t.constructor===bd?(e.writeParentInfo(!1),e.writeLeftID(t)):Es();i!==null&&e.writeString(i)}this.content.write(e,t)}},_m=(e,t)=>vm[t&31](e),vm=[()=>{Es()},Bp,Yp,Rp,em,Gp,qp,um,Qp,Up,()=>{Es()}],ym=10,bm=class extends Pp{get deleted(){return!0}delete(){}mergeWith(e){return this.constructor===e.constructor?(this.length+=e.length,!0):!1}integrate(e,t){Es()}write(e,t){e.writeInfo(ym),is(e.restEncoder,this.length-t)}getMissing(e,t){return null}},xm=typeof globalThis<`u`?globalThis:typeof window<`u`?window:typeof global<`u`?global:{},Sm=`__ $YJS$ __`;xm[Sm]===!0&&console.error(`Yjs was already imported. This breaks constructor checks and will lead to issues! - https://github.com/yjs/yjs/issues/438`),xm[Sm]=!0;var Cm=()=>{let e=!0;return(t,n)=>{if(e){e=!1;try{t()}finally{e=!0}}else n!==void 0&&n()}},wm=/[\uD800-\uDBFF]/,Tm=/[\uDC00-\uDFFF]/,Em=(e,t)=>{let n=0,r=0;for(;n<e.length&&n<t.length&&e[n]===t[n];)n++;for(n>0&&wm.test(e[n-1])&&n--;r+n<e.length&&r+n<t.length&&e[e.length-r-1]===t[t.length-r-1];)r++;return r>0&&Tm.test(e[e.length-r])&&r--,{index:n,remove:e.length-n-r,insert:t.slice(n,t.length-r)}},Dm=(e,t)=>e>>>t|e<<32-t,Om=e=>Dm(e,2)^Dm(e,13)^Dm(e,22),km=e=>Dm(e,6)^Dm(e,11)^Dm(e,25),Am=e=>Dm(e,7)^Dm(e,18)^e>>>3,jm=e=>Dm(e,17)^Dm(e,19)^e>>>10,Mm=new Uint32Array([1116352408,1899447441,3049323471,3921009573,961987163,1508970993,2453635748,2870763221,3624381080,310598401,607225278,1426881987,1925078388,2162078206,2614888103,3248222580,3835390401,4022224774,264347078,604807628,770255983,1249150122,1555081692,1996064986,2554220882,2821834349,2952996808,3210313671,3336571891,3584528711,113926993,338241895,666307205,773529912,1294757372,1396182291,1695183700,1986661051,2177026350,2456956037,2730485921,2820302411,3259730800,3345764771,3516065817,3600352804,4094571909,275423344,430227734,506948616,659060556,883997877,958139571,1322822218,1537002063,1747873779,1955562222,2024104815,2227730452,2361852424,2428436474,2756734187,3204031479,3329325298]),Nm=new Uint32Array([1779033703,3144134277,1013904242,2773480762,1359893119,2600822924,528734635,1541459225]),Pm=class{constructor(){let e=new ArrayBuffer(320);this._H=new Uint32Array(e,0,8),this._H.set(Nm),this._W=new Uint32Array(e,64,64)}_updateHash(){let e=this._H,t=this._W;for(let e=16;e<64;e++)t[e]=jm(t[e-2])+t[e-7]+Am(t[e-15])+t[e-16];let n=e[0],r=e[1],i=e[2],a=e[3],o=e[4],s=e[5],c=e[6],l=e[7];for(let e=0,u,d;e<64;e++)u=l+km(o)+(o&s^~o&c)+Mm[e]+t[e]>>>0,d=Om(n)+(n&r^n&i^r&i)>>>0,l=c,c=s,s=o,o=a+u>>>0,a=i,i=r,r=n,n=u+d>>>0;e[0]+=n,e[1]+=r,e[2]+=i,e[3]+=a,e[4]+=o,e[5]+=s,e[6]+=c,e[7]+=l}digest(e){let t=0;for(;t+56<=e.length;){let n=0;for(;n<16&&t+3<e.length;n++)this._W[n]=e[t++]<<24|e[t++]<<16|e[t++]<<8|e[t++];if(t%64!=0){for(this._W.fill(0,n,16);t<e.length;)this._W[n]|=e[t]<<(3-t%4)*8,t++;this._W[n]|=128<<(3-t%4)*8}this._updateHash()}let n=t%64!=0;this._W.fill(0,0,16);let r=0;for(;t<e.length;r++)for(let n=3;n>=0&&t<e.length;n--)this._W[r]|=e[t++]<<n*8;n||(this._W[r-(t%4==0?0:1)]|=128<<(3-t%4)*8),this._W[14]=e.byteLength/Fo,this._W[15]=e.byteLength*8,this._updateHash();let i=new Uint8Array(32);for(let e=0;e<this._H.length;e++)for(let t=0;t<4;t++)i[e*4+t]=this._H[e]>>>(3-t)*8;return i}},Fm=e=>new Pm().digest(e),Im=new Te(`y-sync`),Lm=new Te(`y-undo`),Rm=new Te(`yjs-cursor`),zm=e=>{for(let t=6;t<e.length;t++)e[t%6]=e[t%6]^e[t];return e.slice(0,6)},Bm=e=>kc(zm(Fm(jc(e)))),Vm=(e,t)=>t===void 0?!e.deleted:t.sv.has(e.id.client)&&t.sv.get(e.id.client)>e.id.clock&&!Nu(t.ds,e.id),Hm=[{light:`#ecd44433`,dark:`#ecd444`}],Um=(e,t,n)=>{if(!e.has(n)){if(e.size<t.length){let n=so();e.forEach(e=>n.add(e)),t=t.filter(e=>!n.has(e))}e.set(n,qs(t))}return e.get(n)},Wm=(e,{colors:t=Hm,colorMapping:n=new Map,permanentUserData:r=null,onFirstRender:i=()=>{},mapping:a}={})=>{let o=!1,s=new Jm(e,a),c=new Fe({props:{editable:e=>{let t=Im.getState(e);return t.snapshot==null&&t.prevSnapshot==null}},key:Im,state:{init:(i,a)=>({type:e,doc:e.doc,binding:s,snapshot:null,prevSnapshot:null,isChangeOrigin:!1,isUndoRedoOperation:!1,addToHistory:!0,colors:t,colorMapping:n,permanentUserData:r}),apply:(e,t)=>{let n=e.getMeta(Im);if(n!==void 0){t=Object.assign({},t);for(let e in n)t[e]=n[e]}return t.addToHistory=e.getMeta(`addToHistory`)!==!1,t.isChangeOrigin=n!==void 0&&!!n.isChangeOrigin,t.isUndoRedoOperation=n!==void 0&&!!n.isChangeOrigin&&!!n.isUndoRedoOperation,s.prosemirrorView!==null&&n!==void 0&&(n.snapshot!=null||n.prevSnapshot!=null)&&lu(0,()=>{s.prosemirrorView!=null&&(n.restore==null?s._renderSnapshot(n.snapshot,n.prevSnapshot,t):(s._renderSnapshot(n.snapshot,n.snapshot,t),delete t.restore,delete t.snapshot,delete t.prevSnapshot,s.mux(()=>{s._prosemirrorChanged(s.prosemirrorView.state.doc)})))}),t}},view:e=>(s.initView(e),a??s._forceRerender(),i(),{update:()=>{let t=c.getState(e.state);if(t.snapshot==null&&t.prevSnapshot==null&&(o||e.state.doc.content.findDiffStart(e.state.doc.type.createAndFill().content)!==null)){if(o=!0,t.addToHistory===!1&&!t.isChangeOrigin){let t=Lm.getState(e.state),n=t&&t.undoManager;n&&n.stopCapturing()}s.mux(()=>{t.doc.transact(n=>{n.meta.set(`addToHistory`,t.addToHistory),s._prosemirrorChanged(e.state.doc)},Im)})}},destroy:()=>{s.destroy()}})});return c},Gm=(e,t,n)=>{if(t!==null&&t.anchor!==null&&t.head!==null)if(t.type===`all`)e.setSelection(new be(e.doc));else if(t.type===`node`){let r=Ch(n.doc,n.type,t.anchor,n.mapping);e.setSelection(Km(e,r))}else{let r=Ch(n.doc,n.type,t.anchor,n.mapping),i=Ch(n.doc,n.type,t.head,n.mapping);r!==null&&i!==null&&e.setSelection(Je.between(e.doc.resolve(r),e.doc.resolve(i)))}},Km=(e,t)=>{let n=e.doc.resolve(t);return n.nodeAfter?Le.create(e.doc,t):Je.near(n)},qm=(e,t)=>({type:t.selection.jsonID,anchor:xh(t.selection.anchor,e.type,e.mapping),head:xh(t.selection.head,e.type,e.mapping)}),Jm=class{constructor(e,t=new Map){this.type=e,this.prosemirrorView=null,this.mux=Cm(),this.mapping=t,this.isOMark=new Map,this._observeFunction=this._typeChanged.bind(this),this.doc=e.doc,this.beforeTransactionSelection=null,this.beforeAllTransactions=()=>{this.beforeTransactionSelection===null&&this.prosemirrorView!=null&&(this.beforeTransactionSelection=qm(this,this.prosemirrorView.state))},this.afterAllTransactions=()=>{this.beforeTransactionSelection=null},this._domSelectionInView=null}get _tr(){return this.prosemirrorView.state.tr.setMeta(`addToHistory`,!1)}_isLocalCursorInView(){return this.prosemirrorView.hasFocus()?(yc&&this._domSelectionInView===null&&(lu(0,()=>{this._domSelectionInView=null}),this._domSelectionInView=this._isDomSelectionInView()),this._domSelectionInView):!1}_isDomSelectionInView(){let e=this.prosemirrorView._root.getSelection();if(e==null||e.anchorNode==null)return!1;let t=this.prosemirrorView._root.createRange();t.setStart(e.anchorNode,e.anchorOffset),t.setEnd(e.focusNode,e.focusOffset),t.getClientRects().length===0&&t.startContainer&&t.collapsed&&t.selectNodeContents(t.startContainer);let n=t.getBoundingClientRect(),r=ql.documentElement;return n.bottom>=0&&n.right>=0&&n.left<=(window.innerWidth||r.clientWidth||0)&&n.top<=(window.innerHeight||r.clientHeight||0)}renderSnapshot(e,t){t||=Fd(Lu(),new Map),this.prosemirrorView.dispatch(this._tr.setMeta(Im,{snapshot:e,prevSnapshot:t}))}unrenderSnapshot(){this.mapping.clear(),this.mux(()=>{let e=this.type.toArray().map(e=>Xm(e,this.prosemirrorView.state.schema,this)).filter(e=>e!==null),t=this._tr.replace(0,this.prosemirrorView.state.doc.content.size,new h(Ze.from(e),0,0));t.setMeta(Im,{snapshot:null,prevSnapshot:null}),this.prosemirrorView.dispatch(t)})}_forceRerender(){this.mapping.clear(),this.mux(()=>{let e=this.beforeTransactionSelection===null?this.prosemirrorView.state.selection:null,t=this.type.toArray().map(e=>Xm(e,this.prosemirrorView.state.schema,this)).filter(e=>e!==null),n=this._tr.replace(0,this.prosemirrorView.state.doc.content.size,new h(Ze.from(t),0,0));if(e){let t=bo(xo(e.anchor,0),n.doc.content.size),r=bo(xo(e.head,0),n.doc.content.size);n.setSelection(Je.create(n.doc,t,r))}this.prosemirrorView.dispatch(n.setMeta(Im,{isChangeOrigin:!0,binding:this}))})}_renderSnapshot(e,t,n){let r=this.doc,i=this.type;if(e||=Id(this.doc),e instanceof Uint8Array||t instanceof Uint8Array)if((!(e instanceof Uint8Array)||!(t instanceof Uint8Array))&&Es(),r=new Uu({gc:!1}),id(r,t),t=Id(r),id(r,e),e=Id(r),i._item===null){let e=Array.from(this.doc.share.keys()).find(e=>this.doc.share.get(e)===this.type);i=r.getXmlFragment(e)}else{let e=r.store.clients.get(i._item.id.client)??[];i=e[Ud(e,i._item.id.clock)].content.type}this.mapping.clear(),this.mux(()=>{r.transact(r=>{let a=n.permanentUserData;a&&a.dss.forEach(e=>{ju(r,e,e=>{})});let o=(e,t)=>{let r=e===`added`?a.getUserByClientId(t.client):a.getUserByDeletedId(t);return{user:r,type:e,color:Um(n.colorMapping,n.colors,r)}},s=Lf(i,new Pd(t.ds,e.sv)).map(n=>!n._item.deleted||Vm(n._item,e)||Vm(n._item,t)?Xm(n,this.prosemirrorView.state.schema,{mapping:new Map,isOMark:new Map},e,t,o):null).filter(e=>e!==null),c=this._tr.replace(0,this.prosemirrorView.state.doc.content.size,new h(Ze.from(s),0,0));this.prosemirrorView.dispatch(c.setMeta(Im,{isChangeOrigin:!0}))},Im)})}_typeChanged(e,t){if(this.prosemirrorView==null)return;let n=Im.getState(this.prosemirrorView.state);if(e.length===0||n.snapshot!=null||n.prevSnapshot!=null){this.renderSnapshot(n.snapshot,n.prevSnapshot);return}this.mux(()=>{let e=(e,t)=>this.mapping.delete(t);ju(t,t.deleteSet,e=>{if(e.constructor===gm){let t=e.content.type;t&&this.mapping.delete(t)}}),t.changed.forEach(e),t.changedParentTypes.forEach(e);let n=this.type.toArray().map(e=>Ym(e,this.prosemirrorView.state.schema,this)).filter(e=>e!==null),r=this._tr.replace(0,this.prosemirrorView.state.doc.content.size,new h(Ze.from(n),0,0));Gm(r,this.beforeTransactionSelection,this),r=r.setMeta(Im,{isChangeOrigin:!0,isUndoRedoOperation:t.origin instanceof cf}),this.beforeTransactionSelection!==null&&this._isLocalCursorInView()&&r.scrollIntoView(),this.prosemirrorView.dispatch(r)})}_prosemirrorChanged(e){this.doc.transact(()=>{mh(this.doc,this.type,e,this),this.beforeTransactionSelection=qm(this,this.prosemirrorView.state)},Im)}initView(e){this.prosemirrorView!=null&&this.destroy(),this.prosemirrorView=e,this.doc.on(`beforeAllTransactions`,this.beforeAllTransactions),this.doc.on(`afterAllTransactions`,this.afterAllTransactions),this.type.observeDeep(this._observeFunction)}destroy(){this.prosemirrorView!=null&&(this.prosemirrorView=null,this.type.unobserveDeep(this._observeFunction),this.doc.off(`beforeAllTransactions`,this.beforeAllTransactions),this.doc.off(`afterAllTransactions`,this.afterAllTransactions))}},Ym=(e,t,n,r,i,a)=>{let o=n.mapping.get(e);if(o===void 0){if(e instanceof Dp)return Xm(e,t,n,r,i,a);throw Ts()}return o},Xm=(e,t,n,r,i,a)=>{let o=[],s=e=>{if(e instanceof Dp){let s=Ym(e,t,n,r,i,a);s!==null&&o.push(s)}else{let s=e._item.right?.content?.type;s instanceof Sp&&!s._item.deleted&&s._item.id.client===s.doc.clientID&&(e.applyDelta([{retain:e.length},...s.toDelta()]),s.doc.transact(e=>{s._item.delete(e)}));let c=Zm(e,t,n,r,i,a);c!==null&&c.forEach(e=>{e!==null&&o.push(e)})}};r===void 0||i===void 0?e.toArray().forEach(s):Lf(e,new Pd(i.ds,r.sv)).forEach(s);try{let s=e.getAttributes(r);r!==void 0&&(Vm(e._item,r)?Vm(e._item,i)||(s.ychange=a?a(`added`,e._item.id):{type:`added`}):s.ychange=a?a(`removed`,e._item.id):{type:`removed`});let c=t.node(e.nodeName,s,o);return n.mapping.set(e,c),c}catch(r){console.warn(`[y-prosemirror] schema.node(`+e.nodeName+`) threw:`,String(r&&r.message||r));let i=globalThis.__okYpsCounters=globalThis.__okYpsCounters||{block:0,inline:0};if(t.nodes[e.nodeName]&&t.nodes[e.nodeName].spec&&t.nodes[e.nodeName].spec.inline)i.inline++;else if(i.block++,t.nodes.rawMdxFallback)try{let i=t.node(`rawMdxFallback`,{reason:String(r&&r.message||r)},[t.text(e.nodeName)]);return n.mapping.set(e,i),i}catch(e){console.warn(`[y-prosemirror] rawMdxFallback substitution also failed:`,String(e&&e.message||e))}return n.mapping.delete(e),null}},Zm=(e,t,n,r,i,a)=>{let o=[],s=e.toDelta(r,i,a);try{for(let e=0;e<s.length;e++){let n=s[e];o.push(t.text(n.insert,fh(n.attributes,t)))}}catch(e){console.warn(`[y-prosemirror] schema.text() threw:`,String(e&&e.message||e));let t=globalThis.__okYpsCounters=globalThis.__okYpsCounters||{block:0,inline:0};return t.inline++,null}return o},Qm=(e,t)=>{let n=new Mp,r=e.map(e=>({insert:e.text,attributes:ph(e.marks,t)}));return n.applyDelta(r),t.mapping.set(n,e),n},$m=(e,t)=>{let n=new Dp(e.type.name);for(let t in e.attrs){let r=e.attrs[t];r!==null&&t!==`ychange`&&n.setAttribute(t,r)}return n.insert(0,rh(e).map(e=>eh(e,t))),t.mapping.set(n,e),n},eh=(e,t)=>e instanceof Array?Qm(e,t):$m(e,t),th=e=>typeof e==`object`&&!!e,nh=(e,t)=>{let n=Object.keys(e).filter(t=>e[t]!==null),r=n.length===Object.keys(t).filter(e=>t[e]!==null).length;for(let i=0;i<n.length&&r;i++){let a=n[i],o=e[a],s=t[a];r=a===`ychange`||o===s||th(o)&&th(s)&&nh(o,s)}return r},rh=e=>{let t=e.content.content,n=[];for(let e=0;e<t.length;e++){let r=t[e];if(r.isText){let r=[];for(let n=t[e];e<t.length&&n.isText;n=t[++e])r.push(n);e--,n.push(r)}else n.push(r)}return n},ih=(e,t)=>{let n=e.toDelta();return n.length===t.length&&n.every((e,n)=>e.insert===t[n].text&&ac(e.attributes||{}).length===t[n].marks.length&&lc(e.attributes,(e,r)=>{let i=dh(r),a=t[n].marks;return a.find(e=>e.type.name===i)?nh(e,a.find(e=>e.type.name===i)?.attrs):!1}))},ah=(e,t)=>{if(e instanceof Dp&&!(t instanceof Array)&&hh(e,t)){let n=rh(t);return e._length===n.length&&nh(e.getAttributes(),t.attrs)&&e.toArray().every((e,t)=>ah(e,n[t]))}return e instanceof Mp&&t instanceof Array&&ih(e,t)},oh=(e,t)=>e===t||e instanceof Array&&t instanceof Array&&e.length===t.length&&e.every((e,n)=>t[n]===e),sh=(e,t,n)=>{let r=e.toArray(),i=rh(t),a=i.length,o=r.length,s=bo(o,a),c=0,l=0,u=!1;for(;c<s;c++){let e=r[c],t=i[c];if(oh(n.mapping.get(e),t))u=!0;else if(!ah(e,t))break}for(;c+l<s;l++){let e=r[o-l-1],t=i[a-l-1];if(oh(n.mapping.get(e),t))u=!0;else if(!ah(e,t))break}return{equalityFactor:c+l,foundMappedChild:u}},ch=e=>{let t=``,n=e._start,r={};for(;n!==null;)n.deleted||(n.countable&&n.content instanceof $p?t+=n.content.str:n.content instanceof Kp&&(r[n.content.key]=null)),n=n.right;return{str:t,nAttrs:r}},lh=(e,t,n)=>{n.mapping.set(e,t);let{nAttrs:r,str:i}=ch(e),a=t.map(e=>({insert:e.text,attributes:Object.assign({},r,ph(e.marks,n))})),{insert:o,remove:s,index:c}=Em(i,a.map(e=>e.insert).join(``));e.delete(c,s),e.insert(c,o),e.applyDelta(a.map(e=>({retain:e.insert.length,attributes:e.attributes})))},uh=/(.*)(--[a-zA-Z0-9+/=]{8})$/,dh=e=>uh.exec(e)?.[1]??e,fh=(e,t)=>{let n=[];for(let r in e)n.push(t.mark(dh(r),e[r]));return n},ph=(e,t)=>{let n={};return e.forEach(e=>{if(e.type.name!==`ychange`){let r=io(t.isOMark,e.type,()=>!e.type.excludes(e.type));n[r?`${e.type.name}--${Bm(e.toJSON())}`:e.type.name]=e.attrs}}),n},mh=(e,t,n,r)=>{if(t instanceof Dp&&t.nodeName!==n.type.name)throw Error(`node name mismatch!`);if(r.mapping.set(t,n),t instanceof Dp){let e=t.getAttributes(),r=n.attrs;for(let n in r)r[n]===null?t.removeAttribute(n):e[n]!==r[n]&&n!==`ychange`&&t.setAttribute(n,r[n]);for(let n in e)r[n]===void 0&&t.removeAttribute(n)}let i=rh(n),a=i.length,o=t.toArray(),s=o.length,c=bo(a,s),l=0,u=0;for(;l<c;l++){let e=o[l],t=i[l];if(!oh(r.mapping.get(e),t))if(ah(e,t))r.mapping.set(e,t);else break}for(;u+l+1<c;u++){let e=o[s-u-1],t=i[a-u-1];if(!oh(r.mapping.get(e),t))if(ah(e,t))r.mapping.set(e,t);else break}e.transact(()=>{for(;s-l-u>0&&a-l-u>0;){let n=o[l],c=i[l],d=o[s-u-1],f=i[a-u-1];if(n instanceof Mp&&c instanceof Array)ih(n,c)||lh(n,c,r),l+=1;else{let i=n instanceof Dp&&hh(n,c),a=d instanceof Dp&&hh(d,f);if(i&&a){let e=sh(n,c,r),t=sh(d,f,r);e.foundMappedChild&&!t.foundMappedChild?a=!1:!e.foundMappedChild&&t.foundMappedChild||e.equalityFactor<t.equalityFactor?i=!1:a=!1}i?(mh(e,n,c,r),l+=1):a?(mh(e,d,f,r),u+=1):(r.mapping.delete(t.get(l)),t.delete(l,1),t.insert(l,[eh(c,r)]),l+=1)}}let n=s-l-u;if(s===1&&a===0&&o[0]instanceof Mp?(r.mapping.delete(o[0]),o[0].delete(0,o[0].length)):n>0&&(t.slice(l,l+n).forEach(e=>r.mapping.delete(e)),t.delete(l,n)),l+u<a){let e=[];for(let t=l;t<a-u;t++)e.push(eh(i[t],r));t.insert(l,e)}},Im)},hh=(e,t)=>!(t instanceof Array)&&e.nodeName===t.type.name,gh=null,_h=class{constructor(e,t,n){this.view=e,this.key=t,this.value=n}apply(){let e=Im.getState(this.view.state);if(e&&e.binding&&!e.binding.isDestroyed){let e=this.view.state.tr;e.setMeta(this.key,this.value),this.view.dispatch(e)}}},vh=class e{constructor(e=[]){this.entries=e}getFirst(){return this.entries[0]}dequeueFirst(){return this.entries.shift()}isEmpty(){return this.entries.length===0}static fromViewsToUpdate(){let t=gh;gh=null;let n=[];return t.forEach((e,t)=>{e.forEach((e,r)=>{n.push(new _h(t,r,e))})}),new e(n)}},yh=(e=vh.fromViewsToUpdate(),t=!1)=>{let n=!0;for(;!e.isEmpty();){let r=e.getFirst();try{r.apply()}catch(r){if(r instanceof RangeError){t&&n&&e.dequeueFirst(),e.isEmpty()||lu(0,()=>yh(e,!0));return}throw r}n=!1,e.dequeueFirst()}},bh=(e,t,n)=>{gh||(gh=new Map,lu(0,yh)),io(gh,e,no).set(t,n)},xh=(e,t,n)=>{if(e===0)return Ad(t,0,-1);let r=t._first===null?null:t._first.content.type;for(;r!==null&&t!==r;){if(r instanceof Mp){if(r._length>=e)return Ad(r,e,-1);if(e-=r._length,r._item!==null&&r._item.next!==null)r=r._item.next.content.type;else{do r=r._item===null?null:r._item.parent,e--;while(r!==t&&r!==null&&r._item!==null&&r._item.next===null);r!==null&&r!==t&&(r=r._item===null?null:r._item.next.content.type)}}else{let i=(n.get(r)||{nodeSize:0}).nodeSize;if(r._first!==null&&e<i)r=r._first.content.type,e--;else{if(e===1&&r._length===0&&i>1)return new wd(r._item===null?null:r._item.id,r._item===null?Sd(r):null,null);if(e-=i,r._item!==null&&r._item.next!==null)r=r._item.next.content.type;else{if(e===0)return r=r._item===null?r:r._item.parent,new wd(r._item===null?null:r._item.id,r._item===null?Sd(r):null,null);do r=r._item.parent,e--;while(r!==t&&r._item.next===null);r!==t&&(r=r._item.next.content.type)}}}if(r===null)throw Es();if(e===0&&r.constructor!==Mp&&r!==t)return Sh(r._item.parent,r._item)}return Ad(t,t._length,-1)},Sh=(e,t)=>{let n=null,r=null;return e._item===null?r=Sd(e):n=Z(e._item.id.client,e._item.id.clock),new wd(n,r,t.id)},Ch=(e,t,n,r)=>{let i=Md(n,e);if(i===null||i.type!==t&&!Cd(t,i.type._item))return null;let a=i.type,o=0;if(a.constructor===Mp)o=i.index;else if(a._item===null||!a._item.deleted){let e=a._first,t=0;for(;t<a._length&&t<i.index&&e!==null;){if(!e.deleted){let n=e.content.type;t++,n instanceof Mp?o+=n._length:o+=r.get(n).nodeSize}e=e.right}o+=1}for(;a!==t&&a._item!==null;){let e=a._item.parent;if(e._item===null||!e._item.deleted){o+=1;let t=e._first;for(;t!==null;){let e=t.content.type;if(e===a)break;t.deleted||(e instanceof Mp?o+=e._length:o+=r.get(e).nodeSize),t=t.right}}a=e}return o-1},wh=(e,t,n)=>e!==t,Th=e=>{let t=document.createElement(`span`);t.classList.add(`ProseMirror-yjs-cursor`),t.setAttribute(`style`,`border-color: ${e.color}`);let n=document.createElement(`div`);n.setAttribute(`style`,`background-color: ${e.color}`),n.insertBefore(document.createTextNode(e.name),null);let r=document.createTextNode(`⁠`),i=document.createTextNode(`⁠`);return t.insertBefore(r,null),t.insertBefore(n,null),t.insertBefore(i,null),t},Eh=e=>({style:`background-color: ${e.color}70`,class:`ProseMirror-yjs-selection`}),Dh=/^#[0-9a-fA-F]{6}$/,Oh=(e,t,n,r,i)=>{let a=Im.getState(e);if(a==null||a.doc==null||a.binding==null)return ge.create(e.doc,[]);let o=a.doc,s=[];return a.snapshot!=null||a.prevSnapshot!=null||a.binding.mapping.size===0?ge.create(e.doc,[]):(t.getStates().forEach((t,c)=>{if(n(o.clientID,c,t)&&t.cursor!=null){let n=t.user||{};n.color==null?n.color=`#ffa500`:Dh.test(n.color)||console.warn(`A user uses an unsupported color format`,n),n.name??=`User: ${c}`;let l=Ch(o,a.type,Ed(t.cursor.anchor),a.binding.mapping),u=Ch(o,a.type,Ed(t.cursor.head),a.binding.mapping);if(l!==null&&u!==null){let t=xo(e.doc.content.size-1,0);l=bo(l,t),u=bo(u,t),s.push(Ke.widget(u,()=>r(n,c),{key:c+``,side:10}));let a=bo(l,u),o=xo(l,u);s.push(Ke.inline(a,o,i(n,c),{inclusiveEnd:!0,inclusiveStart:!1}))}}}),ge.create(e.doc,s))},kh=(e,{awarenessStateFilter:t=wh,cursorBuilder:n=Th,selectionBuilder:r=Eh,getSelection:i=e=>e.selection}={},a=`cursor`)=>new Fe({key:Rm,state:{init(i,a){return Oh(a,e,t,n,r)},apply(i,a,o,s){let c=Im.getState(s),l=i.getMeta(Rm);return c&&c.isChangeOrigin||l&&l.awarenessUpdated?Oh(s,e,t,n,r):a.map(i.mapping,i.doc)}},props:{decorations:e=>Rm.getState(e)},view:t=>{let n=()=>{t.docView&&bh(t,Rm,{awarenessUpdated:!0})},r=()=>{let n=Im.getState(t.state),r=e.getLocalState()||{};if(t.hasFocus()){let o=i(t.state),s=xh(o.anchor,n.type,n.binding.mapping),c=xh(o.head,n.type,n.binding.mapping);(r.cursor==null||!Nd(Ed(r.cursor.anchor),s)||!Nd(Ed(r.cursor.head),c))&&e.setLocalStateField(a,{anchor:s,head:c})}else r.cursor!=null&&Ch(n.doc,n.type,Ed(r.cursor.anchor),n.binding.mapping)!==null&&e.setLocalStateField(a,null)};return e.on(`change`,n),t.dom.addEventListener(`focusin`,r),t.dom.addEventListener(`focusout`,r),{update:r,destroy:()=>{t.dom.removeEventListener(`focusin`,r),t.dom.removeEventListener(`focusout`,r),e.off(`change`,n),e.setLocalStateField(a,null)}}}}),Ah=e=>{let t=Lm.getState(e).undoManager;if(t!=null)return t.undo(),!0},jh=e=>{let t=Lm.getState(e).undoManager;if(t!=null)return t.redo(),!0},Mh=new Set([`paragraph`]),Nh=(e,t)=>!(e instanceof gm)||!(e.content instanceof lm)||!(e.content.type instanceof Sp||e.content.type instanceof Dp&&t.has(e.content.type.nodeName))||e.content.type._length===0,Ph=({protectedNodes:e=Mh,trackedOrigins:t=[],undoManager:n=null}={})=>new Fe({key:Lm,state:{init:(r,i)=>{let a=Im.getState(i),o=n||new cf(a.type,{trackedOrigins:new Set([Im].concat(t)),deleteFilter:t=>Nh(t,e),captureTransaction:e=>e.meta.get(`addToHistory`)!==!1});return{undoManager:o,prevSel:null,hasUndoOps:o.undoStack.length>0,hasRedoOps:o.redoStack.length>0}},apply:(e,t,n,r)=>{let i=Im.getState(r).binding,a=t.undoManager,o=a.undoStack.length>0,s=a.redoStack.length>0;return i?{undoManager:a,prevSel:qm(i,n),hasUndoOps:o,hasRedoOps:s}:o!==t.hasUndoOps||s!==t.hasRedoOps?Object.assign({},t,{hasUndoOps:a.undoStack.length>0,hasRedoOps:a.redoStack.length>0}):t}},view:e=>{let t=Im.getState(e.state),n=Lm.getState(e.state).undoManager;return n.on(`stack-item-added`,({stackItem:n})=>{let r=t.binding;r&&n.meta.set(r,Lm.getState(e.state).prevSel)}),n.on(`stack-item-popped`,({stackItem:e})=>{let n=t.binding;n&&(n.beforeTransactionSelection=e.meta.get(n)||n.beforeTransactionSelection)}),{destroy:()=>{n.destroy()}}}});D({event:S(`ok-branch-switched-clear-failed`),branch:ze(),docName:ze(),reason:ze()});async function Fh(e,t){let n=[];for(let[r,i]of e.entries)i.kind===`active`&&i.persistence!==null&&n.push(i.persistence.clearData().catch(e=>{let n={event:`ok-branch-switched-clear-failed`,docName:r,branch:t,reason:e instanceof Error?e.message:String(e)};console.warn(JSON.stringify(n))}));await Promise.all(n),e.clearBufferedUpdates(),e.recycleAllEntries()}function Ih(e){let t=!1;return()=>{t?e():t=!0}}function Lh(e){let t=atob(e),n=new Uint8Array(t.length);for(let e=0;e<t.length;e++)n[e]=t.charCodeAt(e);return n}async function Rh(e,t=``){let n;try{n=await fetch(`${t}/api/server-info`,{signal:AbortSignal.timeout(5e3)})}catch{return}if(!n.ok)return;let r;try{r=await n.json()}catch{return}let i=d.safeParse(r);if(!i.success){console.warn(JSON.stringify({event:`ok-server-info-schema-mismatch`,issues:i.error.issues}));return}if(e.setExpectedServerInstanceId(i.data.serverInstanceId),i.data.currentBranch!==void 0&&e.compareAndUpdateObservedBranch(i.data.currentBranch)&&Fh(e,i.data.currentBranch),i.data.currentDiskAckSVs!==void 0){let t={};for(let[e,n]of Object.entries(i.data.currentDiskAckSVs))try{t[e]=Lh(n)}catch{}e.observeDiskAckBatch(t)}}async function zh(e){let t;try{t=await fetch(`/api/config`,{signal:e,headers:{Accept:`application/json`}})}catch(e){if(e.name===`AbortError`)throw e;return{status:`error`,code:`network`}}if(t.status===404||t.status===501)return{status:`absent`};if(!t.ok)return{status:`error`,code:t.status};let n;try{n=await t.json()}catch{return{status:`error`,code:`invalid-body`}}if(typeof n!=`object`||!n||Array.isArray(n))return{status:`error`,code:`invalid-body`};let r=n;return{status:`ok`,config:{collabUrl:typeof r.collabUrl==`string`?r.collabUrl:null,previewUrl:typeof r.previewUrl==`string`?r.previewUrl:null,port:typeof r.port==`number`?r.port:0}}}function Bh(e){return qh(e,Xe)}function Vh(e){return qh(e,m)}function Hh(e){return qh(e,$e)}function Uh(e){return qh(e,ue)}function Wh(e){let t=qh(e,z);if(!t)return null;try{return{docName:t.docName,sv:Gh(t.sv)}}catch{return null}}function Gh(e){let t=atob(e),n=new Uint8Array(t.length);for(let e=0;e<t.length;e++)n[e]=t.charCodeAt(e);return n}function Kh(e,t){let n=Vh(e);if(n){t.onServerInfo?.(n);return}let r=Hh(e);if(r){t.onBranchSwitched?.(r);return}let i=Wh(e);if(i){t.onDiskAck?.(i);return}let a=Bh(e);if(a){t.onDerivedView?.(a);return}let o=Uh(e);if(o){t.onConfigValidationRejected?.(o);return}t.onUnknown?.(e)}function qh(e,t){let n;try{n=JSON.parse(e)}catch{return null}let r=t.safeParse(n);return r.success?r.data:null}function Jh(){return typeof location>`u`?`ws://localhost/collab`:`${location.protocol===`https:`?`wss`:`ws`}://${location.host}/collab`}function Yh(e){if(e===void 0)return null;let t=e.okDesktop;return!t||!t.config.collabUrl||t.config.collabUrl.length===0?null:t}function Xh(e){return{collabUrl:e.collabUrl,attempts:0,terminal:!1,lastError:null}}var Zh=2e3,Qh=15e3;function $h(e){let t=e.terminalAfterMs??3e4,n=e.initialDelayMs??Zh,r=e.maxDelayMs??Qh,i=e.log??{info:console.info,warn:console.warn},a=new AbortController,o=null,s=n,c=0,l=!1,u=!1,d=null,f=e.now(),p=async()=>{c+=1;let n=null;try{let t=await e.fetchConfig(a.signal);t.status===`absent`?(n=e.fallbackUrl(),d=null):t.status===`ok`&&t.config.collabUrl!==null?(n=t.config.collabUrl,d=null):t.status===`ok`?(u||(u=!0,i.info(`[collab-url] ok ui responded but server.lock has no port yet — retrying`)),d={kind:`null-collab`}):t.status===`error`&&(i.warn(`[collab-url] /api/config error (${t.code}) — retrying in ${s}ms`),d={kind:`error`,code:t.code})}catch(e){if(e.name===`AbortError`)return;d={kind:`error`,code:`network`}}if(!l){if(n!==null){e.onStateChange({collabUrl:n,attempts:c,terminal:!1,lastError:null});return}if(e.now()-f>=t){e.onStateChange({collabUrl:null,attempts:c,terminal:!0,lastError:d});return}e.onStateChange({collabUrl:null,attempts:c,terminal:!1,lastError:d}),o=e.setTimeout(()=>{p()},s),s=Math.min(s*2,r)}};return p(),{cancel:()=>{l=!0,a.abort(),o!==null&&(e.clearTimeout(o),o=null)}}}function eg(){let e=(0,J.c)(8),t;e[0]===Symbol.for(`react.memo_cache_sentinel`)?(t={collabUrl:null,attempts:0,terminal:!1,lastError:null},e[0]=t):t=e[0];let[n,r]=(0,K.useState)(t),i;e[1]===Symbol.for(`react.memo_cache_sentinel`)?(i={token:0},e[1]=i):i=e[1];let a=(0,K.useRef)(i),[o,s]=(0,K.useState)(0),c;e[2]===Symbol.for(`react.memo_cache_sentinel`)?(c=()=>{let e=a.current.token=a.current.token+1,t=Yh(typeof window<`u`?window:void 0);if(t){r(Xh(t.config));let n=t.onProjectSwitched(t=>{e===a.current.token&&r(Xh(t))});return()=>{n()}}let n=$h({fetchConfig:zh,fallbackUrl:Jh,now:Date.now,setTimeout:ig,clearTimeout:rg,onStateChange:t=>{e===a.current.token&&r(t)}});return()=>{n.cancel()}},e[2]=c):c=e[2];let l;e[3]===o?l=e[4]:(l=[o],e[3]=o,e[4]=l),(0,K.useEffect)(c,l);let u;e[5]===Symbol.for(`react.memo_cache_sentinel`)?(u=()=>{a.current.token=a.current.token+1,r(ng),s(tg)},e[5]=u):u=e[5];let d=u,f;return e[6]===n?f=e[7]:(f={...n,retry:d},e[6]=n,e[7]=f),f}function tg(e){return e+1}function ng(e){return{...e,terminal:!1,lastError:null}}function rg(e){return globalThis.clearTimeout(e)}function ig(e,t){return globalThis.setTimeout(e,t)}function ag(e){return!(e.viewCount>0&&e.viewCount>=50||e.bytes>5e5)}var og=new Map,sg=new Map,cg=[],lg=[],ug=new Set,dg=null;function fg(){if(dg)return dg;if(typeof document>`u`||typeof document.createElement!=`function`)return null;let e=document.createElement(`div`);return e.setAttribute(`data-ok-editor-parking`,``),e.style.display=`none`,e.style.position=`absolute`,e.style.left=`-99999px`,dg=e,e}function pg(e){let{docName:t,container:n,factory:r,sizeStats:i}=e;if(i&&!ag(i)){let e=r(n);return Y(`ok/cache/miss`,{docName:t,viewCount:i?.viewCount??-1,bytes:i?.bytes??-1,reason:`size-gate`}),{editor:e.editor,ydoc:e.ydoc,ytext:e.ytext,provider:e.provider,scrollTop:0,hadFocus:!1,activeMountKey:t,__uncached:!0}}let a=og.get(t);if(a){if(xg(a,n),a.activeMountKey=t,Cg(cg,t),n.scrollTop=a.scrollTop,a.hadFocus)try{a.editor.commands.focus()}catch{}return Y(`ok/cache/hit`,{docName:t,kind:`tiptap`}),i&&Y(`ok/cold/editor-mount-stats`,{docName:t,viewCount:i.viewCount,bytes:i.bytes,cacheHit:!0,kind:`tiptap`}),a}for(;og.size>=10;){let e=wg(cg,t);if(!e)break;hg(e)}let o=r(n),s={editor:o.editor,ydoc:o.ydoc,ytext:o.ytext,provider:o.provider,scrollTop:0,hadFocus:!1,activeMountKey:t};return og.set(t,s),Cg(cg,t),Y(`ok/cache/miss`,{docName:t,viewCount:i?.viewCount??-1,bytes:i?.bytes??-1,reason:`cold`,kind:`tiptap`}),i&&Y(`ok/cold/editor-mount-stats`,{docName:t,viewCount:i.viewCount,bytes:i.bytes,cacheHit:!1,kind:`tiptap`}),s}function mg(e){if(e.__uncached){try{e.editor.destroy()}catch{}e.activeMountKey=null;return}let t=yg(e.editor);if(t){e.hadFocus=bg(t.dom),e.scrollTop=(t.scrollDOM??t.dom.parentElement??t.dom).scrollTop??0;let n=t.dom.parentElement;n&&n.removeChild(t.dom);let r=fg();r&&r.appendChild(t.dom)}e.activeMountKey=null}function hg(e){let t=og.get(e);if(!t)return!1;try{t.editor.destroy()}catch(t){Y(`ok/cache/evict-failed`,{docName:e,kind:`tiptap`,stage:`editor`,message:t instanceof Error?t.message:String(t)})}try{t.provider.destroy()}catch(t){Y(`ok/cache/evict-failed`,{docName:e,kind:`tiptap`,stage:`provider`,message:t instanceof Error?t.message:String(t)})}try{t.ydoc.destroy()}catch(t){Y(`ok/cache/evict-failed`,{docName:e,kind:`tiptap`,stage:`ydoc`,message:t instanceof Error?t.message:String(t)})}og.delete(e);let n=cg.indexOf(e);return n!==-1&&cg.splice(n,1),Y(`ok/cache/evict`,{docName:e,kind:`tiptap`}),!0}function gg(e){let{docName:t,container:n,factory:r,sizeStats:i}=e;if(i&&!ag(i)){let e=r(n);return Y(`ok/cache/miss`,{docName:t,viewCount:i?.viewCount??-1,bytes:i?.bytes??-1,reason:`size-gate`,kind:`cm`}),{view:e.view,ydoc:e.ydoc,ytext:e.ytext,provider:e.provider,scrollTop:0,hadFocus:!1,activeMountKey:t,__uncached:!0}}let a=sg.get(t);if(a){if(Sg(a,n),a.activeMountKey=t,Cg(lg,t),n.scrollTop=a.scrollTop,a.hadFocus)try{a.view.focus()}catch{}return Y(`ok/cache/hit`,{docName:t,kind:`cm`}),i&&Y(`ok/cold/editor-mount-stats`,{docName:t,viewCount:i.viewCount,bytes:i.bytes,cacheHit:!0,kind:`cm`}),a}for(;sg.size>=10;){let e=wg(lg,t);if(!e)break;vg(e)}let o=r(n),s={view:o.view,ydoc:o.ydoc,ytext:o.ytext,provider:o.provider,scrollTop:0,hadFocus:!1,activeMountKey:t};return sg.set(t,s),Cg(lg,t),Y(`ok/cache/miss`,{docName:t,viewCount:i?.viewCount??-1,bytes:i?.bytes??-1,reason:`cold`,kind:`cm`}),i&&Y(`ok/cold/editor-mount-stats`,{docName:t,viewCount:i.viewCount,bytes:i.bytes,cacheHit:!1,kind:`cm`}),s}function _g(e){if(e.__uncached){try{e.view.destroy()}catch{}e.activeMountKey=null;return}let t=e.view.dom;e.hadFocus=bg(t),e.scrollTop=(e.view.scrollDOM??t).scrollTop??0;let n=t.parentElement;n&&n.removeChild(t);let r=fg();r&&r.appendChild(t),e.activeMountKey=null}function vg(e){let t=sg.get(e);if(!t)return!1;try{t.view.destroy()}catch(t){Y(`ok/cache/evict-failed`,{docName:e,kind:`cm`,stage:`view`,message:t instanceof Error?t.message:String(t)})}try{t.provider.destroy()}catch(t){Y(`ok/cache/evict-failed`,{docName:e,kind:`cm`,stage:`provider`,message:t instanceof Error?t.message:String(t)})}try{t.ydoc.destroy()}catch(t){Y(`ok/cache/evict-failed`,{docName:e,kind:`cm`,stage:`ydoc`,message:t instanceof Error?t.message:String(t)})}sg.delete(e);let n=lg.indexOf(e);return n!==-1&&lg.splice(n,1),Y(`ok/cache/evict`,{docName:e,kind:`cm`}),!0}function yg(e){return e.editorView??null}function bg(e){if(typeof document>`u`)return!1;let t=document.activeElement;return t?t===e?!0:e.contains(t):!1}function xg(e,t){let n=yg(e.editor);if(!n)return;let r=n.dom,i=r.parentElement;i&&i!==t&&i.removeChild(r),r.parentElement!==t&&t.appendChild(r)}function Sg(e,t){let n=e.view.dom,r=n.parentElement;r&&r!==t&&r.removeChild(n),n.parentElement!==t&&t.appendChild(n)}function Cg(e,t){let n=e.indexOf(t);n!==-1&&e.splice(n,1),e.push(t)}function wg(e,t){for(let n of e)if(n!==t&&!ug.has(n))return n;Y(`ok/cache/evict-fallback-activity-saturated`,{mountingDocName:t,lruLength:e.length,activityMountCount:ug.size});for(let n of e)if(n!==t)return n;return null}function Tg(e){let t=ug,n=new Set(e);for(let e of t){if(n.has(e))continue;let t=Eg(e);if(t)try{t.disconnect(),Y(`ok/cache/disconnect`,{docName:e})}catch(t){Y(`ok/cache/disconnect-failed`,{docName:e,message:t instanceof Error?t.message:String(t)})}}for(let e of n){if(t.has(e))continue;let n=Eg(e);if(!n)continue;let r=t=>{Y(`ok/cache/connect-failed`,{docName:e,message:t instanceof Error?t.message:String(t)})};try{let t=n.connect();t&&typeof t.then==`function`?t.then(()=>Y(`ok/cache/connect`,{docName:e}),e=>r(e)):Y(`ok/cache/connect`,{docName:e})}catch(e){r(e)}}ug=n}function Eg(e){let t=og.get(e);if(t)return t.provider;let n=sg.get(e);return n?n.provider:null}function Dg(e){return e.onEvict(e=>{hg(e),vg(e)})}var Og=Math.floor,kg=(e,t)=>e<t?e:t,Ag=(e,t)=>e>t?e:t;Number.isNaN;var jg=128,Mg=1<<17,Ng=1<<18,Pg=1<<19,Fg=1<<20,Ig=1<<21,Lg=1<<22,Rg=1<<23,zg=1<<24,Bg=1<<25,Vg=1<<26,Hg=1<<27,Ug=1<<28,Wg=1<<29,Gg=1<<30,Kg=127;Mg-1,Ng-1,Pg-1,Fg-1,Ig-1,Lg-1,Rg-1,zg-1,Bg-1,Vg-1,Hg-1,Ug-1,Wg-1,Gg-1;var qg=2**53-1;Number.isInteger,Number.isNaN,Number.parseInt;var Jg=String.fromCharCode;String.fromCodePoint,Jg(65535);var Yg=e=>{let t=unescape(encodeURIComponent(e)),n=t.length,r=new Uint8Array(n);for(let e=0;e<n;e++)r[e]=t.codePointAt(e);return r},Xg=typeof TextEncoder<`u`?new TextEncoder:null,Zg=Xg?e=>Xg.encode(e):Yg,Qg=typeof TextDecoder>`u`?null:new TextDecoder(`utf-8`,{fatal:!0,ignoreBOM:!0});Qg&&Qg.decode(new Uint8Array).length===1&&(Qg=null);var $g=(e,t)=>{let n=e.cbuf.length;e.cpos===n&&(e.bufs.push(e.cbuf),e.cbuf=new Uint8Array(n*2),e.cpos=0),e.cbuf[e.cpos++]=t},e_=(e,t)=>{for(;t>Kg;)$g(e,jg|Kg&t),t=Og(t/128);$g(e,Kg&t)},t_=new Uint8Array(3e4),n_=t_.length/3,r_=Xg&&Xg.encodeInto?(e,t)=>{if(t.length<n_){let n=Xg.encodeInto(t,t_).written||0;e_(e,n);for(let t=0;t<n;t++)$g(e,t_[t])}else a_(e,Zg(t))}:(e,t)=>{let n=unescape(encodeURIComponent(t)),r=n.length;e_(e,r);for(let t=0;t<r;t++)$g(e,n.codePointAt(t))},i_=(e,t)=>{let n=e.cbuf.length,r=e.cpos,i=kg(n-r,t.length),a=t.length-i;e.cbuf.set(t.subarray(0,i),r),e.cpos+=i,a>0&&(e.bufs.push(e.cbuf),e.cbuf=new Uint8Array(Ag(n*2,a)),e.cbuf.set(t.subarray(i)),e.cpos=a)},a_=(e,t)=>{e_(e,t.byteLength),i_(e,t)},o_=e=>Error(e),s_=o_(`Unexpected end of array`),c_=o_(`Integer out of Range`),l_=(e,t)=>{let n=new Uint8Array(e.arr.buffer,e.pos+e.arr.byteOffset,t);return e.pos+=t,n},u_=e=>l_(e,f_(e)),d_=e=>e.arr[e.pos++],f_=e=>{let t=0,n=1,r=e.arr.length;for(;e.pos<r;){let r=e.arr[e.pos++];if(t+=(r&Kg)*n,n*=128,r<jg)return t;if(t>qg)throw c_}throw s_},p_=Qg?e=>Qg.decode(u_(e)):e=>{let t=f_(e);if(t===0)return``;{let n=String.fromCodePoint(d_(e));if(--t<100)for(;t--;)n+=String.fromCodePoint(d_(e));else for(;t>0;){let r=t<1e4?t:1e4,i=e.arr.subarray(e.pos,e.pos+r);e.pos+=r,n+=String.fromCodePoint.apply(null,i),t-=r}return decodeURIComponent(escape(n))}},m_=function(e){return e[e.Token=0]=`Token`,e[e.PermissionDenied=1]=`PermissionDenied`,e[e.Authenticated=2]=`Authenticated`,e}({}),h_=(e,t)=>{e_(e,m_.Token),r_(e,t)},g_=(e,t,n,r)=>{switch(f_(e)){case m_.Token:t();break;case m_.PermissionDenied:n(p_(e));break;case m_.Authenticated:r(p_(e));break;default:}},__=e=>Array.from(e.entries()).map(([e,t])=>({clientId:e,...t})),v_=`\0`;function y_(e,t){return e+v_+t}function b_(e){let t=e.indexOf(v_);return t===-1?{documentName:e,sessionId:null}:{documentName:e.substring(0,t),sessionId:e.substring(t+1)}}var x_=function(e){return e[e.Connecting=0]=`Connecting`,e[e.Open=1]=`Open`,e[e.Closing=2]=`Closing`,e[e.Closed=3]=`Closed`,e}({});function S_(e){return e||={},{delay:e.delay===void 0?200:e.delay,initialDelay:e.initialDelay===void 0?0:e.initialDelay,minDelay:e.minDelay===void 0?0:e.minDelay,maxDelay:e.maxDelay===void 0?0:e.maxDelay,factor:e.factor===void 0?0:e.factor,maxAttempts:e.maxAttempts===void 0?3:e.maxAttempts,timeout:e.timeout===void 0?0:e.timeout,jitter:e.jitter===!0,initialJitter:e.initialJitter===!0,handleError:e.handleError===void 0?null:e.handleError,handleTimeout:e.handleTimeout===void 0?null:e.handleTimeout,beforeAttempt:e.beforeAttempt===void 0?null:e.beforeAttempt,calculateDelay:e.calculateDelay===void 0?null:e.calculateDelay}}async function C_(e){return new Promise(t=>setTimeout(t,e))}function w_(e,t){let n=t.delay;if(n===0)return 0;if(t.factor&&(n*=t.factor**(e.attemptNum-1),t.maxDelay!==0&&(n=Math.min(n,t.maxDelay))),t.jitter){let e=Math.ceil(t.minDelay);n=Math.floor(Math.random()*(Math.floor(n)-e+1))+e}return Math.round(n)}async function T_(e,t){let n=S_(t);for(let e of[`delay`,`initialDelay`,`minDelay`,`maxDelay`,`maxAttempts`,`timeout`]){let t=n[e];if(!Number.isInteger(t)||t<0)throw Error(`Value for ${e} must be an integer greater than or equal to 0`)}if(n.factor.constructor!==Number||n.factor<0)throw Error(`Value for factor must be a number greater than or equal to 0`);if(n.delay<n.minDelay)throw Error(`delay cannot be less than minDelay (delay: ${n.delay}, minDelay: ${n.minDelay}`);let r={attemptNum:0,attemptsRemaining:n.maxAttempts?n.maxAttempts:-1,aborted:!1,abort(){r.aborted=!0}},i=n.calculateDelay||w_;async function a(){if(n.beforeAttempt&&n.beforeAttempt(r,n),r.aborted){let e=Error(`Attempt aborted`);throw e.code=`ATTEMPT_ABORTED`,e}let t=async e=>{if(n.handleError&&await n.handleError(e,r,n),r.aborted||r.attemptsRemaining===0)throw e;r.attemptNum++;let t=i(r,n);return t&&await C_(t),a()};return r.attemptsRemaining>0&&r.attemptsRemaining--,n.timeout?new Promise((i,a)=>{let o=setTimeout(()=>{if(n.handleTimeout)try{i(n.handleTimeout(r,n))}catch(e){a(e)}else{let e=Error(`Retry timeout (attemptNum: ${r.attemptNum}, timeout: ${n.timeout})`);e.code=`ATTEMPT_TIMEOUT`,a(e)}},n.timeout);e(r,n).then(e=>{clearTimeout(o),i(e)}).catch(e=>{clearTimeout(o),t(e).then(i).catch(a)})}):e(r,n).catch(t)}let o=n.calculateDelay?n.calculateDelay(r,n):n.initialDelay;if(o&&await C_(o),r.attemptNum<1&&n.initialJitter){let e=i(r,n);e&&await C_(e)}return a()}var E_=Math.floor,D_=(e,t)=>e<t?e:t,O_=(e,t)=>e>t?e:t;Number.isNaN;var k_=64,A_=128,j_=1<<17,M_=1<<18,N_=1<<19,P_=1<<20,F_=1<<21,I_=1<<22,L_=1<<23,R_=1<<24,z_=1<<25,B_=1<<26,V_=1<<27,H_=1<<28,U_=1<<29,W_=1<<30,G_=63,K_=127;j_-1,M_-1,N_-1,P_-1,F_-1,I_-1,L_-1,R_-1,z_-1,B_-1,V_-1,H_-1,U_-1,W_-1;var q_=2**53-1;Number.isInteger,Number.isNaN,Number.parseInt;var J_=()=>new Set,Y_=Array.from;Array.isArray;var X_=String.fromCharCode;String.fromCodePoint,X_(65535);var Z_=e=>{let t=unescape(encodeURIComponent(e)),n=t.length,r=new Uint8Array(n);for(let e=0;e<n;e++)r[e]=t.codePointAt(e);return r},Q_=typeof TextEncoder<`u`?new TextEncoder:null,$_=Q_?e=>Q_.encode(e):Z_,ev=typeof TextDecoder>`u`?null:new TextDecoder(`utf-8`,{fatal:!0,ignoreBOM:!0});ev&&ev.decode(new Uint8Array).length===1&&(ev=null);var tv=class{constructor(){this.cpos=0,this.cbuf=new Uint8Array(100),this.bufs=[]}},nv=()=>new tv,rv=e=>{let t=e.cpos;for(let n=0;n<e.bufs.length;n++)t+=e.bufs[n].length;return t},iv=e=>{let t=new Uint8Array(rv(e)),n=0;for(let r=0;r<e.bufs.length;r++){let i=e.bufs[r];t.set(i,n),n+=i.length}return t.set(new Uint8Array(e.cbuf.buffer,0,e.cpos),n),t},av=(e,t)=>{let n=e.cbuf.length;e.cpos===n&&(e.bufs.push(e.cbuf),e.cbuf=new Uint8Array(n*2),e.cpos=0),e.cbuf[e.cpos++]=t},ov=(e,t)=>{for(;t>K_;)av(e,A_|K_&t),t=E_(t/128);av(e,K_&t)},sv=new Uint8Array(3e4),cv=sv.length/3,lv=Q_&&Q_.encodeInto?(e,t)=>{if(t.length<cv){let n=Q_.encodeInto(t,sv).written||0;ov(e,n);for(let t=0;t<n;t++)av(e,sv[t])}else dv(e,$_(t))}:(e,t)=>{let n=unescape(encodeURIComponent(t)),r=n.length;ov(e,r);for(let t=0;t<r;t++)av(e,n.codePointAt(t))},uv=(e,t)=>{let n=e.cbuf.length,r=e.cpos,i=D_(n-r,t.length),a=t.length-i;e.cbuf.set(t.subarray(0,i),r),e.cpos+=i,a>0&&(e.bufs.push(e.cbuf),e.cbuf=new Uint8Array(O_(n*2,a)),e.cbuf.set(t.subarray(i)),e.cpos=a)},dv=(e,t)=>{ov(e,t.byteLength),uv(e,t)},fv=e=>Error(e),pv=fv(`Unexpected end of array`),mv=fv(`Integer out of Range`),hv=class{constructor(e){this.arr=e,this.pos=0}},gv=e=>new hv(e),_v=(e,t)=>{let n=new Uint8Array(e.arr.buffer,e.pos+e.arr.byteOffset,t);return e.pos+=t,n},vv=e=>_v(e,bv(e)),yv=e=>e.arr[e.pos++],bv=e=>{let t=0,n=1,r=e.arr.length;for(;e.pos<r;){let r=e.arr[e.pos++];if(t+=(r&K_)*n,n*=128,r<A_)return t;if(t>q_)throw mv}throw pv},xv=e=>{let t=e.arr[e.pos++],n=t&G_,r=64,i=(t&k_)>0?-1:1;if((t&A_)===0)return i*n;let a=e.arr.length;for(;e.pos<a;){if(t=e.arr[e.pos++],n+=(t&K_)*r,r*=128,t<A_)return i*n;if(n>q_)throw mv}throw pv},Sv=ev?e=>ev.decode(vv(e)):e=>{let t=bv(e);if(t===0)return``;{let n=String.fromCodePoint(yv(e));if(--t<100)for(;t--;)n+=String.fromCodePoint(yv(e));else for(;t>0;){let r=t<1e4?t:1e4,i=e.arr.subarray(e.pos,e.pos+r);e.pos+=r,n+=String.fromCodePoint.apply(null,i),t-=r}return decodeURIComponent(escape(n))}},Cv=e=>{let t=e.pos,n=Sv(e);return e.pos=t,n},wv=Date.now,Tv=()=>new Map,Ev=(e,t,n)=>{let r=e.get(t);return r===void 0&&e.set(t,r=n()),r},Dv=class{constructor(){this._observers=Tv()}on(e,t){Ev(this._observers,e,J_).add(t)}once(e,t){let n=(...r)=>{this.off(e,n),t(...r)};this.on(e,n)}off(e,t){let n=this._observers.get(e);n!==void 0&&(n.delete(t),n.size===0&&this._observers.delete(e))}emit(e,t){return Y_((this._observers.get(e)||Tv()).values()).forEach(e=>e(...t))}destroy(){this._observers=Tv()}},Ov=Symbol(`Equality`),kv=Object.keys,Av=e=>kv(e).length,jv=(e,t)=>Object.prototype.hasOwnProperty.call(e,t),Mv=(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[Ov]!=null)return e[Ov](t);switch(e.constructor){case ArrayBuffer:e=new Uint8Array(e),t=new Uint8Array(t);case Uint8Array:if(e.byteLength!==t.byteLength)return!1;for(let n=0;n<e.length;n++)if(e[n]!==t[n])return!1;break;case Set:if(e.size!==t.size)return!1;for(let n of e)if(!t.has(n))return!1;break;case Map:if(e.size!==t.size)return!1;for(let n of e.keys())if(!t.has(n)||!Mv(e.get(n),t.get(n)))return!1;break;case void 0:case Object:if(Av(e)!==Av(t))return!1;for(let n in e)if(!jv(e,n)||!Mv(e[n],t[n]))return!1;break;case Array:if(e.length!==t.length)return!1;for(let n=0;n<e.length;n++)if(!Mv(e[n],t[n]))return!1;break;default:return!1}return!0},Nv=3e4,Pv=class extends Dv{constructor(e){super(),this.doc=e,this.clientID=e.clientID,this.states=new Map,this.meta=new Map,this._checkInterval=setInterval(()=>{let e=wv();this.getLocalState()!==null&&Nv/2<=e-this.meta.get(this.clientID).lastUpdated&&this.setLocalState(this.getLocalState());let t=[];this.meta.forEach((n,r)=>{r!==this.clientID&&Nv<=e-n.lastUpdated&&this.states.has(r)&&t.push(r)}),t.length>0&&Fv(this,t,`timeout`)},E_(Nv/10)),e.on(`destroy`,()=>{this.destroy()}),this.setLocalState({})}destroy(){this.emit(`destroy`,[this]),this.setLocalState(null),super.destroy(),clearInterval(this._checkInterval)}getLocalState(){return this.states.get(this.clientID)||null}setLocalState(e){let t=this.clientID,n=this.meta.get(t),r=n===void 0?0:n.clock+1,i=this.states.get(t);e===null?this.states.delete(t):this.states.set(t,e),this.meta.set(t,{clock:r,lastUpdated:wv()});let a=[],o=[],s=[],c=[];e===null?c.push(t):i==null?e!=null&&a.push(t):(o.push(t),Mv(i,e)||s.push(t)),(a.length>0||s.length>0||c.length>0)&&this.emit(`change`,[{added:a,updated:s,removed:c},`local`]),this.emit(`update`,[{added:a,updated:o,removed:c},`local`])}setLocalStateField(e,t){let n=this.getLocalState();n!==null&&this.setLocalState({...n,[e]:t})}getStates(){return this.states}},Fv=(e,t,n)=>{let r=[];for(let n=0;n<t.length;n++){let i=t[n];if(e.states.has(i)){if(e.states.delete(i),i===e.clientID){let t=e.meta.get(i);e.meta.set(i,{clock:t.clock+1,lastUpdated:wv()})}r.push(i)}}r.length>0&&(e.emit(`change`,[{added:[],updated:[],removed:r},n]),e.emit(`update`,[{added:[],updated:[],removed:r},n]))},Iv=(e,t,n=e.states)=>{let r=t.length,i=nv();ov(i,r);for(let a=0;a<r;a++){let r=t[a],o=n.get(r)||null,s=e.meta.get(r).clock;ov(i,r),ov(i,s),lv(i,JSON.stringify(o))}return iv(i)},Lv=(e,t,n)=>{let r=gv(t),i=wv(),a=[],o=[],s=[],c=[],l=bv(r);for(let t=0;t<l;t++){let t=bv(r),n=bv(r),l=JSON.parse(Sv(r)),u=e.meta.get(t),d=e.states.get(t),f=u===void 0?0:u.clock;(f<n||f===n&&l===null&&e.states.has(t))&&(l===null?t===e.clientID&&e.getLocalState()!=null?n++:e.states.delete(t):e.states.set(t,l),e.meta.set(t,{clock:n,lastUpdated:i}),u===void 0&&l!==null?a.push(t):u!==void 0&&l===null?c.push(t):l!==null&&(Mv(l,d)||s.push(t),o.push(t)))}(a.length>0||s.length>0||c.length>0)&&e.emit(`change`,[{added:a,updated:s,removed:c},n]),(a.length>0||o.length>0||c.length>0)&&e.emit(`update`,[{added:a,updated:o,removed:c},n])},Rv=class{constructor(){this.callbacks={}}on(e,t){return this.callbacks[e]||(this.callbacks[e]=[]),this.callbacks[e].push(t),this}emit(e,...t){let n=this.callbacks[e];return n&&n.forEach(e=>e.apply(this,t)),this}off(e,t){let n=this.callbacks[e];return n&&(t?this.callbacks[e]=n.filter(e=>e!==t):delete this.callbacks[e]),this}removeAllListeners(){this.callbacks={}}},zv=class{constructor(e){this.data=e,this.encoder=nv(),this.decoder=gv(new Uint8Array(this.data))}peekVarString(){return Cv(this.decoder)}readVarUint(){return bv(this.decoder)}readVarString(){return Sv(this.decoder)}readVarUint8Array(){return vv(this.decoder)}writeVarUint(e){return ov(this.encoder,e)}writeVarString(e){return lv(this.encoder,e)}writeVarUint8Array(e){return dv(this.encoder,e)}length(){return rv(this.encoder)}},Bv=function(e){return e[e.Sync=0]=`Sync`,e[e.Awareness=1]=`Awareness`,e[e.Auth=2]=`Auth`,e[e.QueryAwareness=3]=`QueryAwareness`,e[e.Stateless=5]=`Stateless`,e[e.CLOSE=7]=`CLOSE`,e[e.SyncStatus=8]=`SyncStatus`,e[e.Ping=9]=`Ping`,e[e.Pong=10]=`Pong`,e}({}),Vv=function(e){return e.Connecting=`connecting`,e.Connected=`connected`,e.Disconnected=`disconnected`,e}({}),Hv=class{constructor(){this.encoder=nv()}get(e){return e.encoder}toUint8Array(){return iv(this.encoder)}},Uv=class extends Hv{constructor(...e){super(...e),this.type=Bv.CLOSE,this.description=`Ask the server to close the connection`}get(e){return lv(this.encoder,e.documentName),ov(this.encoder,this.type),this.encoder}},Wv=class e extends Rv{static{this.DEDUPLICATABLE_TYPES=new Set([Bv.Awareness,Bv.QueryAwareness])}constructor(e){super(),this.messageQueue=[],this.configuration={url:``,autoConnect:!0,preserveTrailingSlash:!1,document:void 0,WebSocketPolyfill:void 0,messageReconnectTimeout:3e4,delay:1e3,initialDelay:0,factor:2,maxAttempts:0,minDelay:1e3,maxDelay:3e4,jitter:!0,timeout:0,onOpen:()=>null,onConnect:()=>null,onMessage:()=>null,onOutgoingMessage:()=>null,onStatus:()=>null,onDisconnect:()=>null,onClose:()=>null,onDestroy:()=>null,onAwarenessUpdate:()=>null,onAwarenessChange:()=>null,handleTimeout:null,providerMap:new Map},this.webSocket=null,this.webSocketHandlers={},this.shouldConnect=!0,this.status=Vv.Disconnected,this.lastMessageReceived=0,this.identifier=0,this.intervals={connectionChecker:null},this.connectionAttempt=null,this.receivedOnOpenPayload=void 0,this.closeTries=0,this.setConfiguration(e),this.configuration.WebSocketPolyfill=e.WebSocketPolyfill?e.WebSocketPolyfill:WebSocket,this.on(`open`,this.configuration.onOpen),this.on(`open`,this.onOpen.bind(this)),this.on(`connect`,this.configuration.onConnect),this.on(`message`,this.configuration.onMessage),this.on(`outgoingMessage`,this.configuration.onOutgoingMessage),this.on(`status`,this.configuration.onStatus),this.on(`disconnect`,this.configuration.onDisconnect),this.on(`close`,this.configuration.onClose),this.on(`destroy`,this.configuration.onDestroy),this.on(`awarenessUpdate`,this.configuration.onAwarenessUpdate),this.on(`awarenessChange`,this.configuration.onAwarenessChange),this.on(`close`,this.onClose.bind(this)),this.on(`message`,this.onMessage.bind(this)),this.intervals.connectionChecker=setInterval(this.checkConnection.bind(this),this.configuration.messageReconnectTimeout/10),this.shouldConnect&&this.connect()}async onOpen(e){this.status=Vv.Connected,this.emit(`status`,{status:Vv.Connected}),this.cancelWebsocketRetry=void 0,this.receivedOnOpenPayload=e}attach(e){let t=e.effectiveName,n=this.configuration.providerMap.get(t);if(n&&n!==e&&n.isAuthenticated)throw Error(`Cannot attach two providers with the same effective name "${t}". Use sessionAwareness: true to multiplex providers with the same document name.`);this.configuration.providerMap.set(t,e),this.status===Vv.Disconnected&&this.shouldConnect&&this.connect(),this.receivedOnOpenPayload&&this.status===Vv.Connected&&e.onOpen(this.receivedOnOpenPayload)}detach(e){let t=e.effectiveName;this.configuration.providerMap.has(t)&&(e.send(Uv,{documentName:t}),this.configuration.providerMap.delete(t))}setConfiguration(e={}){this.configuration={...this.configuration,...e},this.configuration.autoConnect||(this.shouldConnect=!1)}async connect(){if(this.status===Vv.Connected)return;this.cancelWebsocketRetry&&=(this.cancelWebsocketRetry(),void 0),this.receivedOnOpenPayload=void 0,this.shouldConnect=!0;let{retryPromise:e,cancelFunc:t}=(()=>{let e=!1;return{retryPromise:T_(this.createWebSocketConnection.bind(this),{delay:this.configuration.delay,initialDelay:this.configuration.initialDelay,factor:this.configuration.factor,maxAttempts:this.configuration.maxAttempts,minDelay:this.configuration.minDelay,maxDelay:this.configuration.maxDelay,jitter:this.configuration.jitter,timeout:this.configuration.timeout,handleTimeout:this.configuration.handleTimeout,beforeAttempt:t=>{(!this.shouldConnect||e)&&t.abort()}}).catch(e=>{if(e&&e.code!==`ATTEMPT_ABORTED`)throw e}),cancelFunc:()=>{e=!0}}})();return this.cancelWebsocketRetry=t,e}attachWebSocketListeners(e,t){let{identifier:n}=e,r=e=>this.emit(`message`,e),i=e=>this.emit(`close`,{event:e}),a=e=>this.emit(`open`,e),o=e=>{t(e)};this.webSocketHandlers[n]={message:r,close:i,open:a,error:o};let s=this.webSocketHandlers[e.identifier];Object.keys(s).forEach(t=>{e.addEventListener(t,s[t])})}cleanupWebSocket(){if(!this.webSocket)return;let{identifier:e}=this.webSocket,t=this.webSocketHandlers[e];Object.keys(t).forEach(n=>{this.webSocket?.removeEventListener(n,t[n]),delete this.webSocketHandlers[e]}),this.webSocket.close(),this.webSocket=null}createWebSocketConnection(){return new Promise((e,t)=>{this.webSocket&&(this.messageQueue=[],this.cleanupWebSocket()),this.lastMessageReceived=0,this.identifier+=1;let n=new this.configuration.WebSocketPolyfill(this.url);n.binaryType=`arraybuffer`,n.identifier=this.identifier,this.attachWebSocketListeners(n,t),this.webSocket=n,this.status=Vv.Connecting,this.emit(`status`,{status:Vv.Connecting}),this.connectionAttempt={resolve:e,reject:t}})}onMessage(e){this.resolveConnectionAttempt(),this.lastMessageReceived=wv();let t=new Uint8Array(e.data);if(t.length===1&&t[0]===Bv.Ping){this.sendPong();return}let n=new zv(t).peekVarString();this.configuration.providerMap.get(n)?.onMessage(e)}sendPong(){let e=nv();ov(e,Bv.Pong),this.send(iv(e))}resolveConnectionAttempt(){this.connectionAttempt&&(this.connectionAttempt.resolve(),this.connectionAttempt=null,this.status=Vv.Connected,this.emit(`status`,{status:Vv.Connected}),this.emit(`connect`),this.messageQueue.forEach(e=>this.send(e)),this.messageQueue=[])}stopConnectionAttempt(){this.connectionAttempt=null}rejectConnectionAttempt(){this.connectionAttempt?.reject(),this.connectionAttempt=null}checkConnection(){this.status===Vv.Connected&&this.lastMessageReceived&&(this.configuration.messageReconnectTimeout>=wv()-this.lastMessageReceived||(this.closeTries+=1,this.closeTries>2?(this.onClose({event:{code:4408,reason:`forced`}}),this.closeTries=0):(this.webSocket?.close(),this.messageQueue=[])))}get serverUrl(){if(this.configuration.preserveTrailingSlash)return this.configuration.url;let e=this.configuration.url;for(;e[e.length-1]===`/`;)e=e.slice(0,e.length-1);return e}get url(){return this.serverUrl}disconnect(){if(this.shouldConnect=!1,this.webSocket!==null)try{this.webSocket.close(),this.messageQueue=[]}catch(e){console.error(e)}}parseQueuedMessage(e){try{let t=gv(e);return{documentName:Sv(t),messageType:bv(t)}}catch{return null}}addToQueue(t){if(t instanceof Uint8Array){let n=this.parseQueuedMessage(t);n&&e.DEDUPLICATABLE_TYPES.has(n.messageType)&&(this.messageQueue=this.messageQueue.filter(e=>{if(!(e instanceof Uint8Array))return!0;let t=this.parseQueuedMessage(e);return t?!(t.documentName===n.documentName&&t.messageType===n.messageType):!0}))}this.messageQueue.push(t)}send(e){this.webSocket?.readyState===x_.Open?this.webSocket.send(e):this.addToQueue(e)}onClose({event:e}){this.closeTries=0,this.cleanupWebSocket(),this.connectionAttempt&&this.rejectConnectionAttempt(),this.status=Vv.Disconnected,this.emit(`status`,{status:Vv.Disconnected}),this.emit(`disconnect`,{event:e}),!this.cancelWebsocketRetry&&this.shouldConnect&&setTimeout(()=>{this.connect()},this.configuration.delay)}destroy(){this.emit(`destroy`),clearInterval(this.intervals.connectionChecker),this.stopConnectionAttempt(),this.disconnect(),this.removeAllListeners(),this.cleanupWebSocket()}},Gv=0,Kv=1,qv=2,Jv=(e,t)=>{ov(e,Gv),dv(e,md(t))},Yv=(e,t,n)=>{ov(e,Kv),dv(e,cd(t,n))},Xv=(e,t,n)=>Yv(t,n,vv(e)),Zv=(e,t,n,r)=>{try{ad(t,vv(e),n)}catch(e){r?.(e),console.error(`Caught error while handling a Yjs update`,e)}},Qv=(e,t)=>{ov(e,qv),dv(e,t)},$v=Zv,ey=(e,t,n,r,i)=>{let a=bv(e);switch(a){case Gv:Xv(e,t,n);break;case Kv:Zv(e,n,r,i);break;case qv:$v(e,n,r,i);break;default:throw Error(`Unknown message type`)}return a},ty=class{constructor(e){this.message=e}apply(e,t){let{message:n}=this,r=n.readVarUint(),i=n.length();switch(r){case Bv.Sync:this.applySyncMessage(e,t);break;case Bv.Awareness:this.applyAwarenessMessage(e);break;case Bv.Auth:this.applyAuthMessage(e);break;case Bv.QueryAwareness:this.applyQueryAwarenessMessage(e);break;case Bv.Stateless:e.receiveStateless(Sv(n.decoder));break;case Bv.SyncStatus:this.applySyncStatusMessage(e,xv(n.decoder)===1);break;case Bv.CLOSE:let i={code:1e3,reason:Sv(n.decoder)};e.onClose(),e.configuration.onClose({event:i}),e.forwardClose({event:i});break;default:console.error(`Can’t apply message of unknown type: ${r}`)}n.length()>i+1&&e.send(Hv,{encoder:n.encoder})}applySyncMessage(e,t){let{message:n}=this;n.writeVarUint(Bv.Sync);let r=ey(n.decoder,n.encoder,e.document,e);t&&r===Kv&&(e.synced=!0)}applySyncStatusMessage(e,t){t&&e.decrementUnsyncedChanges()}applyAwarenessMessage(e){if(!e.awareness)return;let{message:t}=this;Lv(e.awareness,t.readVarUint8Array(),e)}applyAuthMessage(e){let{message:t}=this;g_(t.decoder,e.sendToken.bind(e),e.permissionDeniedHandler.bind(e),e.authenticatedHandler.bind(e))}applyQueryAwarenessMessage(e){if(!e.awareness)return;let{message:t}=this;t.writeVarUint(Bv.Awareness),t.writeVarUint8Array(Iv(e.awareness,Array.from(e.awareness.getStates().keys())))}},ny=class{constructor(e,t={}){this.message=new e,this.encoder=this.message.get(t)}create(){return iv(this.encoder)}send(e){e?.send(this.create())}},ry=`4.0.0-rc.1`,iy=class extends Hv{constructor(...e){super(...e),this.type=Bv.Auth,this.description=`Authentication`}get(e){if(e.token===void 0)throw Error("The authentication message requires `token` as an argument.");return lv(this.encoder,e.documentName),ov(this.encoder,this.type),h_(this.encoder,e.token),lv(this.encoder,ry),this.encoder}},ay=class extends Hv{constructor(...e){super(...e),this.type=Bv.Awareness,this.description=`Awareness states update`}get(e){if(e.awareness===void 0)throw Error(`The awareness message requires awareness as an argument`);if(e.clients===void 0)throw Error(`The awareness message requires clients as an argument`);lv(this.encoder,e.documentName),ov(this.encoder,this.type);let t;return t=e.states===void 0?Iv(e.awareness,e.clients):Iv(e.awareness,e.clients,e.states),dv(this.encoder,t),this.encoder}},oy=class extends Hv{constructor(...e){super(...e),this.type=Bv.Stateless,this.description=`A stateless message`}get(e){return lv(this.encoder,e.documentName),ov(this.encoder,this.type),lv(this.encoder,e.payload??``),this.encoder}},sy=class extends Hv{constructor(...e){super(...e),this.type=Bv.Sync,this.description=`First sync step`}get(e){if(e.document===void 0)throw Error(`The sync step one message requires document as an argument`);return lv(this.encoder,e.documentName),ov(this.encoder,this.type),Jv(this.encoder,e.document),this.encoder}},cy=class extends Hv{constructor(...e){super(...e),this.type=Bv.Sync,this.description=`A document update`}get(e){return lv(this.encoder,e.documentName),ov(this.encoder,this.type),Qv(this.encoder,e.update),this.encoder}},ly=class extends Error{constructor(...e){super(...e),this.code=1001}},uy=class extends Rv{get effectiveName(){return this.configuration.sessionAwareness?y_(this.configuration.name,this.sessionId):this.configuration.name}constructor(e){super(),this.configuration={name:``,document:void 0,awareness:void 0,token:null,sessionAwareness:!0,forceSyncInterval:!1,onAuthenticated:()=>null,onAuthenticationFailed:()=>null,onOpen:()=>null,onConnect:()=>null,onMessage:()=>null,onOutgoingMessage:()=>null,onSynced:()=>null,onStatus:()=>null,onDisconnect:()=>null,onClose:()=>null,onDestroy:()=>null,onAwarenessUpdate:()=>null,onAwarenessChange:()=>null,onStateless:()=>null,onUnsyncedChanges:()=>null},this.isSynced=!1,this.unsyncedChanges=0,this.isAuthenticated=!1,this.authorizedScope=void 0,this.manageSocket=!1,this._isAttached=!1,this.sessionId=Math.random().toString(36).slice(2),this.intervals={forceSync:null},this.boundDocumentUpdateHandler=this.documentUpdateHandler.bind(this),this.boundAwarenessUpdateHandler=this.awarenessUpdateHandler.bind(this),this.boundPageHide=this.pageHide.bind(this),this.boundOnOpen=this.onOpen.bind(this),this.boundOnClose=this.onClose.bind(this),this.forwardConnect=()=>this.emit(`connect`),this.forwardStatus=e=>this.emit(`status`,e),this.forwardClose=e=>this.emit(`close`,e),this.forwardDisconnect=e=>this.emit(`disconnect`,e),this.forwardDestroy=()=>this.emit(`destroy`),this.setConfiguration(e),this.configuration.document=e.document?e.document:new Uu,this.configuration.awareness=e.awareness===void 0?new Pv(this.document):e.awareness,this.on(`open`,this.configuration.onOpen),this.on(`message`,this.configuration.onMessage),this.on(`outgoingMessage`,this.configuration.onOutgoingMessage),this.on(`synced`,this.configuration.onSynced),this.on(`destroy`,this.configuration.onDestroy),this.on(`awarenessUpdate`,this.configuration.onAwarenessUpdate),this.on(`awarenessChange`,this.configuration.onAwarenessChange),this.on(`stateless`,this.configuration.onStateless),this.on(`unsyncedChanges`,this.configuration.onUnsyncedChanges),this.on(`authenticated`,this.configuration.onAuthenticated),this.on(`authenticationFailed`,this.configuration.onAuthenticationFailed),this.awareness?.on(`update`,()=>{this.emit(`awarenessUpdate`,{states:__(this.awareness.getStates())})}),this.awareness?.on(`change`,()=>{this.emit(`awarenessChange`,{states:__(this.awareness.getStates())})}),this.document.on(`update`,this.boundDocumentUpdateHandler),this.awareness?.on(`update`,this.boundAwarenessUpdateHandler),this.registerEventListeners(),this.configuration.forceSyncInterval&&typeof this.configuration.forceSyncInterval==`number`&&(this.intervals.forceSync=setInterval(this.forceSync.bind(this),this.configuration.forceSyncInterval)),this.manageSocket&&this.attach()}setConfiguration(e={}){e.websocketProvider||(this.manageSocket=!0,this.configuration.websocketProvider=new Wv(e)),this.configuration={...this.configuration,...e}}get document(){return this.configuration.document}get isAttached(){return this._isAttached}get awareness(){return this.configuration.awareness}get hasUnsyncedChanges(){return this.unsyncedChanges>0}resetUnsyncedChanges(){this.unsyncedChanges=1,this.emit(`unsyncedChanges`,{number:this.unsyncedChanges})}incrementUnsyncedChanges(){this.unsyncedChanges+=1,this.emit(`unsyncedChanges`,{number:this.unsyncedChanges})}decrementUnsyncedChanges(){this.unsyncedChanges>0&&--this.unsyncedChanges,this.unsyncedChanges===0&&(this.synced=!0),this.emit(`unsyncedChanges`,{number:this.unsyncedChanges})}forceSync(){this.resetUnsyncedChanges(),this.send(sy,{document:this.document,documentName:this.effectiveName})}pageHide(){this.awareness&&Fv(this.awareness,[this.document.clientID],`page hide`)}registerEventListeners(){typeof window>`u`||!(`addEventListener`in window)||window.addEventListener(`pagehide`,this.boundPageHide)}sendStateless(e){this.send(oy,{documentName:this.effectiveName,payload:e})}async sendToken(){let e;try{e=await this.getToken()}catch(e){this.permissionDeniedHandler(`Failed to get token during sendToken(): ${e}`);return}this.send(iy,{token:e??``,documentName:this.effectiveName})}documentUpdateHandler(e,t){t!==this&&(this.incrementUnsyncedChanges(),this.send(cy,{update:e,documentName:this.effectiveName}))}awarenessUpdateHandler({added:e,updated:t,removed:n},r){let i=e.concat(t).concat(n);this.send(ay,{awareness:this.awareness,clients:i,documentName:this.effectiveName})}get synced(){return this.isSynced}set synced(e){this.isSynced!==e&&(this.isSynced=e,e&&this.emit(`synced`,{state:e}))}receiveStateless(e){this.emit(`stateless`,{payload:e})}async connect(){if(this.manageSocket)return this.configuration.websocketProvider.connect();console.warn(`HocuspocusProvider::connect() is deprecated and does not do anything. Please connect/disconnect on the websocketProvider, or attach/deattach providers.`)}disconnect(){if(this.manageSocket)return this.configuration.websocketProvider.disconnect();console.warn(`HocuspocusProvider::disconnect() is deprecated and does not do anything. Please connect/disconnect on the websocketProvider, or attach/deattach providers.`)}async onOpen(e){this.isAuthenticated=!1,this.emit(`open`,{event:e}),await this.sendToken(),this.startSync()}async getToken(){return typeof this.configuration.token==`function`?await this.configuration.token():this.configuration.token}startSync(){this.resetUnsyncedChanges(),this.send(sy,{document:this.document,documentName:this.effectiveName}),this.awareness&&this.awareness.getLocalState()!==null&&this.send(ay,{awareness:this.awareness,clients:[this.document.clientID],documentName:this.effectiveName})}send(e,t){if(!this._isAttached)return;let n=new ny(e,t);this.emit(`outgoingMessage`,{message:n.message}),n.send(this.configuration.websocketProvider)}onMessage(e){let t=new zv(e.data),{documentName:n}=b_(t.readVarString());t.writeVarString(this.effectiveName),this.emit(`message`,{event:e,message:new zv(e.data)}),new ty(t).apply(this,!0)}onClose(){this.isAuthenticated=!1,this.synced=!1,this.awareness&&Fv(this.awareness,Array.from(this.awareness.getStates().keys()).filter(e=>e!==this.document.clientID),this)}destroy(){this.emit(`destroy`),this.intervals.forceSync&&clearInterval(this.intervals.forceSync),this.awareness&&(Fv(this.awareness,[this.document.clientID],`provider destroy`),this.awareness.off(`update`,this.boundAwarenessUpdateHandler),this.awareness.destroy()),this.document.off(`update`,this.boundDocumentUpdateHandler),this.removeAllListeners(),this.detach(),this.manageSocket&&this.configuration.websocketProvider.destroy(),!(typeof window>`u`||!(`removeEventListener`in window))&&window.removeEventListener(`pagehide`,this.boundPageHide)}detach(){this.configuration.websocketProvider.off(`connect`,this.configuration.onConnect),this.configuration.websocketProvider.off(`connect`,this.forwardConnect),this.configuration.websocketProvider.off(`status`,this.forwardStatus),this.configuration.websocketProvider.off(`status`,this.configuration.onStatus),this.configuration.websocketProvider.off(`open`,this.boundOnOpen),this.configuration.websocketProvider.off(`close`,this.boundOnClose),this.configuration.websocketProvider.off(`close`,this.configuration.onClose),this.configuration.websocketProvider.off(`close`,this.forwardClose),this.configuration.websocketProvider.off(`disconnect`,this.configuration.onDisconnect),this.configuration.websocketProvider.off(`disconnect`,this.forwardDisconnect),this.configuration.websocketProvider.off(`destroy`,this.configuration.onDestroy),this.configuration.websocketProvider.off(`destroy`,this.forwardDestroy),this.configuration.websocketProvider.detach(this),this._isAttached=!1}attach(){this._isAttached||=(this.configuration.websocketProvider.on(`connect`,this.configuration.onConnect),this.configuration.websocketProvider.on(`connect`,this.forwardConnect),this.configuration.websocketProvider.on(`status`,this.configuration.onStatus),this.configuration.websocketProvider.on(`status`,this.forwardStatus),this.configuration.websocketProvider.on(`open`,this.boundOnOpen),this.configuration.websocketProvider.on(`close`,this.boundOnClose),this.configuration.websocketProvider.on(`close`,this.configuration.onClose),this.configuration.websocketProvider.on(`close`,this.forwardClose),this.configuration.websocketProvider.on(`disconnect`,this.configuration.onDisconnect),this.configuration.websocketProvider.on(`disconnect`,this.forwardDisconnect),this.configuration.websocketProvider.on(`destroy`,this.configuration.onDestroy),this.configuration.websocketProvider.on(`destroy`,this.forwardDestroy),this.configuration.websocketProvider.attach(this),!0)}permissionDeniedHandler(e){this.emit(`authenticationFailed`,{reason:e}),this.isAuthenticated=!1}authenticatedHandler(e){this.isAuthenticated=!0,this.authorizedScope=e,this.emit(`authenticated`,{scope:e})}setAwarenessField(e,t){if(!this.awareness)throw new ly(`Cannot set awareness field "${e}" to ${JSON.stringify(t)}. You have disabled Awareness for this provider by explicitly passing awareness: null in the provider configuration.`);this.awareness.setLocalStateField(e,t)}},dy=e=>Zs((t,n)=>{e.onerror=e=>n(Error(e.target.error)),e.onsuccess=e=>t(e.target.result)}),fy=(e,t)=>Zs((n,r)=>{let i=indexedDB.open(e);i.onupgradeneeded=e=>t(e.target.result),i.onerror=e=>r(ws(e.target.error)),i.onsuccess=e=>{let t=e.target.result;t.onversionchange=()=>{t.close()},n(t)}}),py=e=>dy(indexedDB.deleteDatabase(e)),my=(e,t)=>t.forEach(t=>e.createObjectStore.apply(e,t)),hy=(e,t,n=`readwrite`)=>{let r=e.transaction(t,n);return t.map(e=>Ey(r,e))},gy=(e,t)=>dy(e.count(t)),_y=(e,t)=>dy(e.get(t)),vy=(e,t)=>dy(e.delete(t)),yy=(e,t,n)=>dy(e.put(t,n)),by=(e,t)=>dy(e.add(t)),xy=(e,t,n)=>dy(e.getAll(t,n)),Sy=(e,t,n)=>{let r=null;return Ty(e,t,e=>(r=e,!1),n).then(()=>r)},Cy=(e,t=null)=>Sy(e,t,`prev`),wy=(e,t)=>Zs((n,r)=>{e.onerror=r,e.onsuccess=async e=>{let r=e.target.result;if(r===null||await t(r)===!1)return n();r.continue()}}),Ty=(e,t,n,r=`next`)=>wy(e.openKeyCursor(t,r),e=>n(e.key)),Ey=(e,t)=>e.objectStore(t),Dy=(e,t)=>IDBKeyRange.upperBound(e,t),Oy=(e,t)=>IDBKeyRange.lowerBound(e,t),ky=`custom`,Ay=`updates`,jy=(e,t=()=>{},n=()=>{})=>{let[r]=hy(e.db,[Ay]);return xy(r,Oy(e._dbref,!1)).then(i=>{e._destroyed||(t(r),rf(e.doc,()=>{i.forEach(t=>ad(e.doc,t))},e,!1),n(r))}).then(()=>Cy(r).then(t=>{e._dbref=t+1})).then(()=>gy(r).then(t=>{e._dbsize=t})).then(()=>r)},My=(e,t=!0)=>jy(e).then(n=>{(t||e._dbsize>=500)&&by(n,cd(e.doc)).then(()=>vy(n,Dy(e._dbref,!0))).then(()=>gy(n).then(t=>{e._dbsize=t}))}),Ny=class extends _o{constructor(e,t){super(),this.doc=t,this.name=e,this._dbref=0,this._dbsize=0,this._destroyed=!1,this.db=null,this.synced=!1,this._db=fy(e,e=>my(e,[[`updates`,{autoIncrement:!0}],[`custom`]])),this.whenSynced=Zs(e=>this.on(`synced`,()=>e(this))),this._db.then(e=>{this.db=e,jy(this,async e=>{await gy(e)>0&&by(e,cd(t))},()=>{if(this._destroyed)return this;this.synced=!0,this.emit(`synced`,[this])})}),this._storeTimeout=1e3,this._storeTimeoutId=null,this._storeUpdate=(e,t)=>{if(this.db&&t!==this){let[t]=hy(this.db,[Ay]);by(t,e).catch(e=>{globalThis.__okYdbWriteWarned||(globalThis.__okYdbWriteWarned=!0,console.warn(JSON.stringify({event:`ok-ydb-write-failed`,cause:e?.name??`unknown`,message:e?.message??String(e)})))}),++this._dbsize>=500&&(this._storeTimeoutId!==null&&clearTimeout(this._storeTimeoutId),this._storeTimeoutId=setTimeout(()=>{My(this,!1),this._storeTimeoutId=null},this._storeTimeout))}},t.on(`update`,this._storeUpdate),this.destroy=this.destroy.bind(this),t.on(`destroy`,this.destroy)}destroy(){return this._storeTimeoutId&&clearTimeout(this._storeTimeoutId),this.doc.off(`update`,this._storeUpdate),this.doc.off(`destroy`,this.destroy),this._destroyed=!0,this._db.then(e=>{e.close()})}clearData(){return this.destroy().then(()=>{py(this.name)})}get(e){return this._db.then(t=>{let[n]=hy(t,[ky],`readonly`);return _y(n,e)})}set(e,t){return this._db.then(n=>{let[r]=hy(n,[ky]);return yy(r,t,e)})}del(e){return this._db.then(t=>{let[n]=hy(t,[ky]);return vy(n,e)})}},Py=class{_idb;_dbName;whenSynced;constructor({branch:e,serverInstanceId:t,docName:n,doc:r}){if(typeof t!=`string`||t.length===0)throw Error(`createClientPersistence: serverInstanceId is required and must be non-empty`);this._dbName=`ok-ydoc:${e}:${t}:${n}`,this._idb=new Ny(this._dbName,r),this.whenSynced=this._idb.whenSynced.then(()=>this)}get synced(){return this._idb.synced}async destroy(){await this._idb.destroy()}async clearData(){await this._idb.destroy();let e=this._dbName;await new Promise((t,n)=>{let r=indexedDB.deleteDatabase(e);r.onsuccess=()=>t(),r.onerror=()=>n(r.error),r.onblocked=()=>{console.warn(JSON.stringify({event:`ok-client-persistence-clear-blocked`,dbName:e})),n(Error(`idb-clear-blocked: ${e}`))}})}};function Fy(e){return new Py(e)}function Iy(e){return md(e)}function Ly(e,t){return t===null?cd(e):cd(e,t)}function Ry(e,t){if(e===null)return t;if(t===null)return e;let n=ud(e),r=ud(t),i=new Map;for(let[e,t]of n)i.set(e,t);for(let[e,t]of r){let n=i.get(e);(n===void 0||t>n)&&i.set(e,t)}return md(i)}function zy(e){let t={};if(i.inject(r.active(),t),!t.traceparent)return e;let n=e.includes(`?`)?`&`:`?`,a=[`traceparent=${encodeURIComponent(t.traceparent)}`];return t.tracestate&&a.push(`tracestate=${encodeURIComponent(t.tracestate)}`),`${e}${n}${a.join(`&`)}`}var By=({key:e,editor:t,onPaste:n,onDrop:r,allowedMimeTypes:i})=>new Fe({key:e||new Te(`fileHandler`),props:{handleDrop(e,n){if(!r||!n.dataTransfer?.files.length)return!1;let a=e.posAtCoords({left:n.clientX,top:n.clientY}),o=Array.from(n.dataTransfer.files);return i&&(o=o.filter(e=>i.includes(e.type))),o.length===0?!1:(n.preventDefault(),n.stopPropagation(),r(t,o,a?.pos||0),!0)},handlePaste(e,r){if(!n||!r.clipboardData?.files.length)return!1;let a=Array.from(r.clipboardData.files),o=r.clipboardData.getData(`text/html`);return i&&(a=a.filter(e=>i.includes(e.type))),!(a.length===0||(r.preventDefault(),r.stopPropagation(),n(t,a,o),o.length>0))}}}),Vy=W.create({name:`fileHandler`,addOptions(){return{onPaste:void 0,onDrop:void 0,allowedMimeTypes:void 0}},addProseMirrorPlugins(){return[By({key:new Te(this.name),editor:this.editor,allowedMimeTypes:this.options.allowedMimeTypes,onDrop:this.options.onDrop,onPaste:this.options.onPaste})]}}),Hy=W.create({name:`keyboardNav`,priority:50,addKeyboardShortcuts(){return{Escape:({editor:e})=>{let{state:t}=e;if(t.selection instanceof Le){let n=t.selection.from+t.selection.node.nodeSize,r=t.doc.resolve(Math.min(n,t.doc.content.size)),i=Je.near(r);return e.view.dispatch(t.tr.setSelection(i)),!0}return t.selection instanceof Je?e.commands.selectParentNode():!1},ArrowUp:({editor:e})=>{let{state:t}=e;if(!(t.selection instanceof Le))return!1;let n=t.selection.from,r=t.doc.resolve(n);if(r.index(r.depth)===0)return!1;let i=r.before(r.depth);if(i<=0)return!1;let a=t.doc.resolve(i-1).nodeBefore;if(!a||i-1-a.nodeSize+1<0)return!1;try{let n=Le.create(t.doc,i-a.nodeSize);return e.view.dispatch(t.tr.setSelection(n).scrollIntoView()),!0}catch{return!1}},ArrowDown:({editor:e})=>{let{state:t}=e;if(!(t.selection instanceof Le))return!1;let n=t.selection.from+t.selection.node.nodeSize;if(n>=t.doc.content.size)return!1;try{if(!t.doc.nodeAt(n))return!1;let r=Le.create(t.doc,n);return e.view.dispatch(t.tr.setSelection(r).scrollIntoView()),!0}catch{return!1}},Enter:({editor:e})=>{let{state:t}=e;if(!(t.selection instanceof Je)||!t.selection.empty)return!1;let n=t.selection.$from,r=n.parent;if(r.type.name!==`paragraph`||r.textContent!==``||n.depth<2)return!1;let i=-1;for(let e=n.depth-1;e>=1;e--)if(n.node(e).type.name===`jsxComponent`){i=e;break}if(i<0)return!1;let a=n.node(i);if(n.index(i)!==a.childCount-1)return!1;let o=n.after(i);if(o>t.doc.content.size)return!1;let s=t.tr,c=n.before(n.depth),l=n.after(n.depth);s.delete(c,l);let u=o-(l-c),d=t.schema.nodes.paragraph.create();s.insert(u,d);let f=u+1;return s.setSelection(Je.create(s.doc,f)),e.view.dispatch(s.scrollIntoView()),!0}}}}),Uy=new WeakMap;function Wy(e,t){if(t===null){Uy.delete(e);return}Uy.set(e,t)}function Gy(e){return Uy.get(e)??null}function Ky(e){return`pagesBySlug`in e}function qy(e){return Ky(e)?e.pages:e}function Jy(e,t){let n=p(e);if(n){if(Ky(t))return t.pagesBySlug.get(n);for(let e of t)if(p(e)===n)return e}}function Yy(e){let t=e.trim();if(!t)return null;let n=p(t);return n?{target:n,alias:n===t?null:t,anchor:null}:null}function Xy(e){let t=e.trim();if(!t)return[];let n=p(t);return n.length>0&&n!==t?[n]:[]}function Zy(e,t){let n=e.trim();if(!n)return!1;let r=qy(t);return r.has(n)||Xy(n).some(e=>r.has(e))?!0:Jy(n,t)!==void 0}var Qy={ChevronRight:Bn};function $y(e){if(!e||!e.startsWith(`lucide:`))return null;let t=e.slice(7);return Object.hasOwn(Qy,t)?Qy[t]:null}function eb(e){let t=(0,J.c)(23),n;t[0]===e.icon?n=t[1]:(n=$y(e.icon),t[0]=e.icon,t[1]=n);let r=n,i=r?`custom`:void 0,a;t[2]===r?a=t[3]:(a=r?(0,q.jsx)(r,{size:16,className:`accordion-icon`,"aria-hidden":`true`}):null,t[2]=r,t[3]=a);let o=e.title??`Accordion`,s;t[4]===o?s=t[5]:(s=(0,q.jsx)(`span`,{className:`accordion-title`,children:o}),t[4]=o,t[5]=s);let c;t[6]===e.description?c=t[7]:(c=e.description?(0,q.jsx)(`span`,{className:`accordion-description`,children:e.description}):null,t[6]=e.description,t[7]=c);let l;t[8]!==s||t[9]!==c?(l=(0,q.jsxs)(`span`,{className:`accordion-title-group`,children:[s,c]}),t[8]=s,t[9]=c,t[10]=l):l=t[10];let u;t[11]!==a||t[12]!==l?(u=(0,q.jsxs)(`summary`,{className:`accordion-summary`,contentEditable:!1,children:[a,l]}),t[11]=a,t[12]=l,t[13]=u):u=t[13];let d;t[14]===e.children?d=t[15]:(d=(0,q.jsx)(`div`,{className:`accordion-body`,children:e.children}),t[14]=e.children,t[15]=d);let f;return t[16]!==e.defaultOpen||t[17]!==e.id||t[18]!==e.name||t[19]!==i||t[20]!==u||t[21]!==d?(f=(0,q.jsxs)(`details`,{className:`accordion`,"data-accordion-icon":i,open:e.defaultOpen,id:e.id,name:e.name,children:[u,d]}),t[16]=e.defaultOpen,t[17]=e.id,t[18]=e.name,t[19]=i,t[20]=u,t[21]=d,t[22]=f):f=t[22],f}function tb(e){return e!==!1}function nb(e){let t=(0,J.c)(10),n=e.src,r=e.title,i;t[0]===e.controls?i=t[1]:(i=tb(e.controls),t[0]=e.controls,t[1]=i);let a;return t[2]!==e.autoplay||t[3]!==e.loop||t[4]!==e.muted||t[5]!==e.preload||t[6]!==e.src||t[7]!==e.title||t[8]!==i?(a=(0,q.jsx)(`audio`,{className:`ok-audio`,src:n,title:r,controls:i,autoPlay:e.autoplay,loop:e.loop,muted:e.muted,preload:e.preload}),t[2]=e.autoplay,t[3]=e.loop,t[4]=e.muted,t[5]=e.preload,t[6]=e.src,t[7]=e.title,t[8]=i,t[9]=a):a=t[9],a}var rb={note:Zn,tip:Qn,important:rr,warning:x,caution:ar},ib={Info:Zn,Lightbulb:Qn,MessageSquareWarning:rr,AlertTriangle:x,AlertOctagon:ar};function ab(e,t){if(!e||!e.startsWith(`lucide:`))return rb[t];let n=e.slice(7);return Object.hasOwn(ib,n)?ib[n]:rb[t]}function ob(e){return e===`note`||e===`tip`||e===`important`||e===`warning`||e===`caution`?e:`note`}function sb(e){let t=(0,J.c)(28),n,r;t[0]!==e.icon||t[1]!==e.type?(r=ob(e.type),n=ab(e.icon,r),t[0]=e.icon,t[1]=e.type,t[2]=n,t[3]=r):(n=t[2],r=t[3]);let i=n,a;t[4]===e.color?a=t[5]:(a=e.color?{"--callout-type-color":e.color}:{},t[4]=e.color,t[5]=a);let o=a,s;t[6]!==i||t[7]!==e.title?(s=e.title||i?(0,q.jsxs)(`span`,{className:`callout-header`,contentEditable:!1,children:[(0,q.jsx)(i,{size:16,className:`callout-icon`,"aria-hidden":`true`}),e.title?(0,q.jsx)(`span`,{className:`callout-title`,children:e.title}):null]}):null,t[6]=i,t[7]=e.title,t[8]=s):s=t[8];let c=s;if(e.collapsible){let n=e.defaultOpen??!0,i;t[9]===c?i=t[10]:(i=c??(0,q.jsx)(`span`,{className:`callout-title`,children:`Details`}),t[9]=c,t[10]=i);let a;t[11]===i?a=t[12]:(a=(0,q.jsx)(`summary`,{className:`callout-summary`,contentEditable:!1,children:i}),t[11]=i,t[12]=a);let s;t[13]===e.children?s=t[14]:(s=(0,q.jsx)(`div`,{className:`callout-body`,children:e.children}),t[13]=e.children,t[14]=s);let l;return t[15]!==n||t[16]!==o||t[17]!==a||t[18]!==s||t[19]!==r?(l=(0,q.jsxs)(`details`,{className:`callout callout-collapsible`,"data-callout-type":r,open:n,style:o,children:[a,s]}),t[15]=n,t[16]=o,t[17]=a,t[18]=s,t[19]=r,t[20]=l):l=t[20],l}let l;t[21]===e.children?l=t[22]:(l=(0,q.jsx)(`div`,{className:`callout-body`,children:e.children}),t[21]=e.children,t[22]=l);let u;return t[23]!==c||t[24]!==o||t[25]!==l||t[26]!==r?(u=(0,q.jsxs)(`div`,{className:`callout callout-static`,"data-callout-type":r,style:o,children:[c,l]}),t[23]=c,t[24]=o,t[25]=l,t[26]=r,t[27]=u):u=t[27],u}function cb(){return K.createElement(`svg`,{"aria-hidden":`true`,"data-rmiz-btn-unzoom-icon":!0,fill:`currentColor`,focusable:`false`,viewBox:`0 0 16 16`,xmlns:`http://www.w3.org/2000/svg`},K.createElement(`path`,{d:`M 14.144531 1.148438 L 9 6.292969 L 9 3 L 8 3 L 8 8 L 13 8 L 13 7 L 9.707031 7 L 14.855469 1.851563 Z M 8 8 L 3 8 L 3 9 L 6.292969 9 L 1.148438 14.144531 L 1.851563 14.855469 L 7 9.707031 L 7 13 L 8 13 Z`}))}function lb(){return K.createElement(`svg`,{"aria-hidden":`true`,"data-rmiz-btn-zoom-icon":!0,fill:`currentColor`,focusable:`false`,viewBox:`0 0 16 16`,xmlns:`http://www.w3.org/2000/svg`},K.createElement(`path`,{d:`M 9 1 L 9 2 L 12.292969 2 L 2 12.292969 L 2 9 L 1 9 L 1 14 L 6 14 L 6 13 L 2.707031 13 L 13 2.707031 L 13 6 L 14 6 L 14 1 Z`}))}function ub(e){return typeof Element>`u`?!1:e instanceof Element}var db=(e,t)=>ub(t)&&t.tagName.toUpperCase()===e,fb=e=>db(`DIV`,e)||db(`SPAN`,e),pb=e=>db(`IMG`,e),mb=e=>e.complete&&e.naturalHeight!==0,hb=e=>db(`SVG`,e),gb=({height:e,offset:t,width:n})=>Math.min((window.innerWidth-t*2)/n,(window.innerHeight-t*2)/e),_b=({containerHeight:e,containerWidth:t,offset:n,targetHeight:r,targetWidth:i})=>{let a=gb({height:r,offset:n,width:i}),o=i>r?i/t:r/e;return a>1?o:a*o},vb=({containerHeight:e,containerWidth:t,hasScalableSrc:n,offset:r,targetHeight:i,targetWidth:a})=>e===0||t===0?1:!n&&i!==0&&a!==0?_b({containerHeight:e,containerWidth:t,offset:r,targetHeight:i,targetWidth:a}):gb({height:e,offset:r,width:t}),yb=/url(?:\(['"]?)(?<url>.*?)(?:['"]?\))/,bb=e=>{if(e!==null){if(pb(e))return e.currentSrc===``?void 0:e.currentSrc;if(fb(e)){let{backgroundImage:t}=window.getComputedStyle(e);if(t!==``)return yb.exec(t)?.[1]}}},xb=e=>{if(e!==null)return pb(e)?e.alt:e.getAttribute(`aria-label`)??void 0},Sb=({containerHeight:e,containerLeft:t,containerTop:n,containerWidth:r,hasScalableSrc:i,offset:a,targetHeight:o,targetWidth:s})=>{let c=vb({containerHeight:e,containerWidth:r,hasScalableSrc:i,offset:a,targetHeight:o,targetWidth:s});return{top:n,left:t,width:r*c,height:e*c,transform:`translate(0,0) scale(${1/c})`}},Cb=({position:e,relativeNum:t})=>{let n=parseFloat(e);return e.endsWith(`%`)?t*n/100:n},wb=({containerHeight:e,containerLeft:t,containerTop:n,containerWidth:r,hasScalableSrc:i,objectFit:a,objectPosition:o,offset:s,targetHeight:c,targetWidth:l})=>{let u=a;if(u===`scale-down`&&(u=l<=r&&c<=e?`none`:`contain`),u===`cover`||u===`contain`){let a=r/l,d=e/c,f=u===`cover`?Math.max(a,d):Math.min(a,d),[p=`50%`,m=`50%`]=o.split(` `),h=Cb({position:p,relativeNum:r-l*f}),g=Cb({position:m,relativeNum:e-c*f}),_=vb({containerHeight:c*f,containerWidth:l*f,hasScalableSrc:i,offset:s,targetHeight:c,targetWidth:l});return{top:n+g,left:t+h,width:l*f*_,height:c*f*_,transform:`translate(0,0) scale(${1/_})`}}else if(u===`none`){let[a=`50%`,u=`50%`]=o.split(` `),d=Cb({position:a,relativeNum:r-l}),f=Cb({position:u,relativeNum:e-c}),p=vb({containerHeight:c,containerWidth:l,hasScalableSrc:i,offset:s,targetHeight:c,targetWidth:l});return{top:n+f,left:t+d,width:l*p,height:c*p,transform:`translate(0,0) scale(${1/p})`}}else if(u===`fill`){let t=r/l,n=e/c,a=Math.max(t,n),o=vb({containerHeight:c*a,containerWidth:l*a,hasScalableSrc:i,offset:s,targetHeight:c,targetWidth:l});return{width:r*o,height:e*o,transform:`translate(0,0) scale(${1/o})`}}else return{}},Tb=({backgroundPosition:e,backgroundSize:t,containerHeight:n,containerLeft:r,containerTop:i,containerWidth:a,hasScalableSrc:o,offset:s,targetHeight:c,targetWidth:l})=>{if(t===`cover`||t===`contain`){let u=a/l,d=n/c,f=t===`cover`?Math.max(u,d):Math.min(u,d),[p=`50%`,m=`50%`]=e.split(` `),h=Cb({position:p,relativeNum:a-l*f}),g=Cb({position:m,relativeNum:n-c*f}),_=vb({containerHeight:c*f,containerWidth:l*f,hasScalableSrc:o,offset:s,targetHeight:c,targetWidth:l});return{top:i+g,left:r+h,width:l*f*_,height:c*f*_,transform:`translate(0,0) scale(${1/_})`}}else if(t===`auto`){let[t=`50%`,u=`50%`]=e.split(` `),d=Cb({position:t,relativeNum:a-l}),f=Cb({position:u,relativeNum:n-c}),p=vb({containerHeight:c,containerWidth:l,hasScalableSrc:o,offset:s,targetHeight:c,targetWidth:l});return{top:i+f,left:r+d,width:l*p,height:c*p,transform:`translate(0,0) scale(${1/p})`}}else{let[u=`50%`,d=`50%`]=t.split(` `),f=Cb({position:u,relativeNum:a}),p=Cb({position:d,relativeNum:n}),m=f/l,h=p/c,g=Math.min(m,h),[_=`50%`,v=`50%`]=e.split(` `),y=Cb({position:_,relativeNum:a-l*g}),b=Cb({position:v,relativeNum:n-c*g}),x=vb({containerHeight:c*g,containerWidth:l*g,hasScalableSrc:o,offset:s,targetHeight:c,targetWidth:l});return{top:i+b,left:r+y,width:l*g*x,height:c*g*x,transform:`translate(0,0) scale(${1/x})`}}},Eb=/\.svg$/i,Db=({hasZoomImg:e,imgSrc:t,isSvg:n,isZoomed:r,loadedImgEl:i,offset:a,shouldRefresh:o,targetEl:s})=>{let c=n||t?.slice(0,18)===`data:image/svg+xml`||e||t!==void 0&&Eb.test(t),l=s.getBoundingClientRect(),u=window.getComputedStyle(s),d=i!=null&&fb(s),f=i!=null&&!d,p=i!=null&&i.naturalHeight!==0?i.naturalHeight:l.height,m=i!=null&&i.naturalWidth!==0?i.naturalWidth:l.width,h=Sb({containerHeight:l.height,containerLeft:l.left,containerTop:l.top,containerWidth:l.width,hasScalableSrc:c,offset:a,targetHeight:p,targetWidth:m}),g=f?wb({containerHeight:l.height,containerLeft:l.left,containerTop:l.top,containerWidth:l.width,hasScalableSrc:c,objectFit:u.objectFit,objectPosition:u.objectPosition,offset:a,targetHeight:p,targetWidth:m}):void 0,_=d?Tb({backgroundPosition:u.backgroundPosition,backgroundSize:u.backgroundSize,containerHeight:l.height,containerLeft:l.left,containerTop:l.top,containerWidth:l.width,hasScalableSrc:c,offset:a,targetHeight:p,targetWidth:m}):void 0,v={...h,...g,..._};if(r){let e=window.innerWidth/2,t=window.innerHeight/2,n=parseFloat(String(v.left??0))+parseFloat(String(v.width??0))/2,r=parseFloat(String(v.top??0))+parseFloat(String(v.height??0))/2,i=e-n,a=t-r;o&&(v.transitionDuration=`0.01ms`),v.transform=`translate(${i}px,${a}px) scale(1)`}return v},Ob=e=>{if(e==null)return{};if(hb(e)){let{parentElement:t}=e,n=e.getBoundingClientRect();if(t==null)return{height:n.height,left:n.left,width:n.width,top:n.top};{let e=t.getBoundingClientRect();return{height:n.height,left:e.left-n.left,top:e.top-n.top,width:n.width}}}else return{height:e.offsetHeight,left:e.offsetLeft,width:e.offsetWidth,top:e.offsetTop}},kb=e=>{let t=`-zoom`,n=[`clip-path`,`fill`,`mask`,`marker-start`,`marker-mid`,`marker-end`],r=new Map;if(e.hasAttribute(`id`)){let{id:n}=e,i=n+t;r.set(n,i);let a=e;a.id=i}e.querySelectorAll(`[id]`).forEach(e=>{let{id:n}=e,i=n+t;r.set(n,i);let a=e;a.id=i}),r.forEach((t,r)=>{let i=`url(#${r})`,a=`url(#${t})`,o=n.map(e=>`[${e}="${i}"]`).join(`, `);e.querySelectorAll(o).forEach(e=>{n.forEach(t=>{e.getAttribute(t)===i&&e.setAttribute(t,a)})})}),e.querySelectorAll(`style`).forEach(e=>{r.forEach((t,n)=>{let{textContent:r}=e;if(r!==``){let i=e;i.textContent=r.replaceAll(`#${n}`,`#${t}`)}})})},Ab=[`img`,`svg`,`[role="img"]`,`[data-zoom]`].map(e=>`${e}:not([aria-hidden="true"])`).join(`,`),jb={overflow:``,width:``};function Mb(){let e=document.querySelector(`[data-rmiz-portal]`);if(e!=null)return e;let t=document.createElement(`div`);return t.setAttribute(`data-rmiz-portal`,``),document.body.appendChild(t),t}function Nb(e){e.preventDefault()}function Pb(e){return K.createElement(Fb,{...e})}var Fb=class extends K.Component{constructor(){super(...arguments),this.state={id:``,isZoomImgLoaded:!1,loadedImgEl:void 0,modalState:`UNLOADED`,shouldRefresh:!1,styleGhost:{}},this.refContent=K.createRef(),this.refDialog=K.createRef(),this.refModalContent=K.createRef(),this.refModalImg=K.createRef(),this.refWrap=K.createRef(),this.imgEl=null,this.isScaling=!1,this.prevBodyAttrs=jb,this.styleModalImg={},this.handleModalStateChange=e=>{let{state:{modalState:t}}=this;e!==`LOADING`&&t===`LOADING`?(this.loadZoomImg(),window.addEventListener(`resize`,this.handleResize,{passive:!0}),window.addEventListener(`touchstart`,this.handleTouchStart,{passive:!0}),window.addEventListener(`touchmove`,this.handleTouchMove,{passive:!0}),window.addEventListener(`touchend`,this.handleTouchEnd,{passive:!0}),window.addEventListener(`touchcancel`,this.handleTouchCancel,{passive:!0}),document.addEventListener(`keydown`,this.handleKeyDown,!0)):e!==`LOADED`&&t===`LOADED`?window.addEventListener(`wheel`,this.handleWheel,{passive:!0}):e!==`UNLOADING`&&t===`UNLOADING`?(this.ensureImgTransitionEnd(),window.removeEventListener(`wheel`,this.handleWheel),window.removeEventListener(`touchstart`,this.handleTouchStart),window.removeEventListener(`touchmove`,this.handleTouchMove),window.removeEventListener(`touchend`,this.handleTouchEnd),window.removeEventListener(`touchcancel`,this.handleTouchCancel),document.removeEventListener(`keydown`,this.handleKeyDown,!0)):e!==`UNLOADED`&&t===`UNLOADED`&&(this.bodyScrollEnable(),window.removeEventListener(`resize`,this.handleResize),this.refModalImg.current?.removeEventListener(`transitionend`,this.handleImgTransitionEnd),this.refDialog.current?.close())},this.setId=()=>{let e=()=>Math.random().toString(16).slice(-4);this.setState({id:e()+e()+e()})},this.setAndTrackImg=()=>{let{refContent:{current:e}}=this;e!=null&&(this.imgEl=e.querySelector(Ab),this.imgEl===null?this.contentNotFoundChangeObserver??(this.contentNotFoundChangeObserver=new MutationObserver(this.setAndTrackImg),this.contentNotFoundChangeObserver.observe(e,{childList:!0,subtree:!0})):(this.contentNotFoundChangeObserver?.disconnect(),this.imgEl.addEventListener(`load`,this.handleImgLoad),this.imgEl.addEventListener(`click`,this.handleZoom),this.state.loadedImgEl??this.handleImgLoad(),this.imgElResizeObserver=new ResizeObserver(e=>{let[t]=e;t?.target!==void 0&&(this.imgEl=t.target,this.setState({styleGhost:Ob(this.imgEl)}))}),this.imgElResizeObserver.observe(this.imgEl),this.contentChangeObserver??(this.contentChangeObserver=new MutationObserver(()=>{this.setState({styleGhost:Ob(this.imgEl)})}),this.contentChangeObserver.observe(e,{attributes:!0,childList:!0,subtree:!0}))))},this.handleIfZoomChanged=e=>{let{props:{isZoomed:t}}=this;!e&&t?this.zoom():e&&!t&&this.unzoom()},this.handleImgLoad=()=>{let e=bb(this.imgEl);if(e==null||e===``)return;let t=new Image,{imgEl:n}=this;if(pb(n)){let{sizes:e,srcset:r,crossOrigin:i}=n;t.sizes=e,t.srcset=r,t.crossOrigin=i}t.src=e;let r=()=>{this.setState({loadedImgEl:t,styleGhost:Ob(this.imgEl)})};t.decode().then(r).catch(()=>{if(mb(t)){r();return}t.onload=r})},this.handleZoom=e=>{this.props.isDisabled!==!0&&this.hasImage()&&this.props.onZoomChange?.(!0,{event:e})},this.handleUnzoom=e=>{this.props.isDisabled!==!0&&this.props.onZoomChange?.(!1,{event:e})},this.handleBtnUnzoomClick=e=>{e.preventDefault(),e.stopPropagation(),this.handleUnzoom(e)},this.handleDialogClick=e=>{(e.target===this.refModalContent.current||e.target===this.refModalImg.current)&&(e.stopPropagation(),this.handleUnzoom(e))},this.handleDialogClose=e=>{e.stopPropagation(),this.handleUnzoom(e)},this.handleKeyDown=e=>{e.key===`Escape`&&(e.preventDefault(),e.stopPropagation(),this.handleUnzoom(e))},this.handleWheel=e=>{e.ctrlKey||(e.stopPropagation(),queueMicrotask(()=>{this.handleUnzoom(e)}))},this.handleTouchStart=e=>{if(e.touches.length>1){this.isScaling=!0;return}let{changedTouches:t}=e,[n]=t;if(t.length===1&&n!==void 0){let{screenY:e}=n;this.touchYStart=e}},this.handleTouchMove=e=>{let t=window.visualViewport?.scale??1,{changedTouches:n}=e,[r]=n;if(this.props.canSwipeToUnzoom&&!this.isScaling&&t<=1&&this.touchYStart!=null&&r!==void 0){let{screenY:t}=r;this.touchYEnd=t;let n=Math.max(this.touchYStart,this.touchYEnd),i=Math.min(this.touchYStart,this.touchYEnd);Math.abs(n-i)>this.props.swipeToUnzoomThreshold&&(this.touchYStart=void 0,this.touchYEnd=void 0,this.handleUnzoom(e))}},this.handleTouchEnd=()=>{this.isScaling=!1,this.touchYStart=void 0,this.touchYEnd=void 0},this.handleTouchCancel=()=>{this.isScaling=!1,this.touchYStart=void 0,this.touchYEnd=void 0},this.handleResize=()=>{this.setState({shouldRefresh:!0})},this.hasImage=()=>this.imgEl!==null&&(this.state.loadedImgEl!==void 0||hb(this.imgEl))&&window.getComputedStyle(this.imgEl).display!==`none`,this.zoom=()=>{this.bodyScrollDisable(),this.refDialog.current?.showModal(),this.refModalImg.current?.addEventListener(`transitionend`,this.handleImgTransitionEnd),this.setState({modalState:`LOADING`})},this.unzoom=()=>{this.setState({modalState:`UNLOADING`})},this.handleImgTransitionEnd=()=>{clearTimeout(this.timeoutTransitionEnd),this.state.modalState===`LOADING`?this.setState({modalState:`LOADED`}):this.state.modalState===`UNLOADING`&&this.setState({shouldRefresh:!1,modalState:`UNLOADED`})},this.ensureImgTransitionEnd=()=>{if(this.refModalImg.current!==null){let{transitionDuration:e}=window.getComputedStyle(this.refModalImg.current),t=parseFloat(e);if(t!==0&&!Number.isNaN(t)){let n=t*(e.endsWith(`ms`)?1:1e3)+50;this.timeoutTransitionEnd=setTimeout(this.handleImgTransitionEnd,n)}}},this.bodyScrollDisable=()=>{this.prevBodyAttrs={overflow:document.body.style.overflow,width:document.body.style.width};let{body:{clientWidth:e}}=document;document.body.style.overflow=`hidden`,document.body.style.width=`${e}px`},this.bodyScrollEnable=()=>{let{prevBodyAttrs:{overflow:e,width:t}}=this;document.body.style.width=t,document.body.style.overflow=e,this.prevBodyAttrs=jb},this.loadZoomImg=()=>{let{props:{zoomImg:e}}=this;if(e==null)return;let{src:t}=e;if(t!==void 0&&t!==``){let n=new Image;n.sizes=e.sizes??``,n.srcset=e.srcSet??``,n.crossOrigin=e.crossOrigin??void 0,n.src=t;let r=()=>{this.setState({isZoomImgLoaded:!0})};n.decode().then(r).catch(()=>{if(mb(n)){r();return}n.onload=r})}},this.UNSAFE_handleSvg=()=>{let{imgEl:e,refModalImg:t,styleModalImg:n}=this;if(hb(e)){let r=e.cloneNode(!0);kb(r),r.style.width=`${n.width??0}px`,r.style.height=`${n.height??0}px`,r.addEventListener(`click`,this.handleUnzoom),t.current?.firstChild?.remove(),t.current?.appendChild(r)}}}render(){let{handleBtnUnzoomClick:e,handleDialogClick:t,handleDialogClose:n,handleUnzoom:r,handleZoom:i,imgEl:a,props:{a11yNameButtonUnzoom:o,a11yNameButtonZoom:s,children:c,classDialog:l,IconUnzoom:u,IconZoom:d,isZoomed:f,wrapElement:p,ZoomContent:m,zoomImg:h,zoomMargin:g},refContent:_,refDialog:v,refModalContent:y,refModalImg:b,refWrap:x,state:{id:S,isZoomImgLoaded:C,loadedImgEl:w,modalState:T,shouldRefresh:E,styleGhost:D}}=this,O=`rmiz-modal-${S}`,k=`rmiz-modal-img-${S}`,A=fb(a),j=pb(a),M=hb(a),N=xb(a),P=bb(a),F=j?a.sizes:void 0,I=j?a.srcset:void 0,L=j?a.crossOrigin:void 0,R=h?.src!==void 0&&h.src!==``,z=this.hasImage(),B=N!==void 0&&N!==``?`${s}: ${N}`:s,V=T===`LOADING`||T===`LOADED`,H=z?`found`:`not-found`,U=T===`UNLOADED`||T===`UNLOADING`?`hidden`:`visible`,ee={visibility:T===`UNLOADED`?`visible`:`hidden`};this.styleModalImg=z&&a!==null?Db({hasZoomImg:R,imgSrc:P,isSvg:M,isZoomed:f&&V,loadedImgEl:w,offset:g,shouldRefresh:E,targetEl:a}):{};let te=null;if(z){let t=j||A?K.createElement(`img`,{alt:N,crossOrigin:L,sizes:F,src:P,srcSet:I,...C&&T===`LOADED`?h:{},"data-rmiz-modal-img":``,height:this.styleModalImg.height??void 0,id:k,ref:b,style:this.styleModalImg,width:this.styleModalImg.width??void 0}):M?K.createElement(`div`,{"data-rmiz-modal-img":!0,ref:b,style:this.styleModalImg}):null,n=K.createElement(`button`,{"aria-label":o,"data-rmiz-btn-unzoom":``,onClick:e,type:`button`},K.createElement(u,null));te=m==null?K.createElement(K.Fragment,null,t,n):K.createElement(m,{buttonUnzoom:n,modalState:T,img:t,isZoomImgLoaded:C,onUnzoom:r})}return K.createElement(p,{"aria-owns":O,"data-rmiz":``,ref:x},K.createElement(p,{"data-rmiz-content":H,ref:_,style:ee},c),z&&K.createElement(p,{"data-rmiz-ghost":``,style:D},K.createElement(`button`,{"aria-label":B,"data-rmiz-btn-zoom":``,onClick:i,type:`button`},K.createElement(d,null))),z&&Si.createPortal(K.createElement(`dialog`,{"aria-labelledby":k,"aria-modal":`true`,className:l,"data-rmiz-modal":``,id:O,onClick:t,onClose:n,onCancel:Nb,ref:v,role:`dialog`},K.createElement(`div`,{"data-rmiz-modal-overlay":U}),K.createElement(`div`,{"data-rmiz-modal-content":``,ref:y},te)),Mb()))}componentDidMount(){this.setId(),this.setAndTrackImg(),this.handleImgLoad(),this.UNSAFE_handleSvg()}componentWillUnmount(){this.state.modalState!==`UNLOADED`&&this.bodyScrollEnable(),this.contentChangeObserver?.disconnect(),this.contentNotFoundChangeObserver?.disconnect(),this.imgElResizeObserver?.disconnect(),this.imgEl?.removeEventListener(`load`,this.handleImgLoad),this.imgEl?.removeEventListener(`click`,this.handleZoom),this.refModalImg.current?.removeEventListener(`transitionend`,this.handleImgTransitionEnd),window.removeEventListener(`wheel`,this.handleWheel),window.removeEventListener(`touchstart`,this.handleTouchStart),window.removeEventListener(`touchmove`,this.handleTouchMove),window.removeEventListener(`touchend`,this.handleTouchEnd),window.removeEventListener(`touchcancel`,this.handleTouchCancel),window.removeEventListener(`resize`,this.handleResize),document.removeEventListener(`keydown`,this.handleKeyDown,!0)}componentDidUpdate(e,t){this.handleModalStateChange(t.modalState),this.UNSAFE_handleSvg(),this.handleIfZoomChanged(e.isZoomed)}};Fb.defaultProps={a11yNameButtonUnzoom:`Minimize image`,a11yNameButtonZoom:`Expand image`,canSwipeToUnzoom:!0,IconUnzoom:cb,IconZoom:lb,isDisabled:!1,swipeToUnzoomThreshold:10,wrapElement:`div`,zoomMargin:0};function Ib({onZoomChange:e,...t}){let[n,r]=K.useState(!1),i=K.useCallback((t,{event:n})=>{r(t),e?.(t,{event:n})},[e]);return K.createElement(Pb,{...t,isZoomed:n,onZoomChange:i})}function Lb(e){return e??`lazy`}function Rb(e){let t=(0,J.c)(15),n=e.src,r=e.alt??``,i=e.width,a=e.height,o=e.title,s;t[0]===e.loading?s=t[1]:(s=Lb(e.loading),t[0]=e.loading,t[1]=s);let c;return t[2]!==e.crossorigin||t[3]!==e.decoding||t[4]!==e.fetchpriority||t[5]!==e.height||t[6]!==e.referrerpolicy||t[7]!==e.sizes||t[8]!==e.src||t[9]!==e.srcset||t[10]!==e.title||t[11]!==e.width||t[12]!==r||t[13]!==s?(c=(0,q.jsx)(`img`,{src:n,alt:r,width:i,height:a,title:o,loading:s,srcSet:e.srcset,sizes:e.sizes,decoding:e.decoding,fetchPriority:e.fetchpriority,crossOrigin:e.crossorigin,referrerPolicy:e.referrerpolicy}),t[2]=e.crossorigin,t[3]=e.decoding,t[4]=e.fetchpriority,t[5]=e.height,t[6]=e.referrerpolicy,t[7]=e.sizes,t[8]=e.src,t[9]=e.srcset,t[10]=e.title,t[11]=e.width,t[12]=r,t[13]=s,t[14]=c):c=t[14],c}function zb(e){let t=(0,J.c)(3),n;t[0]===Symbol.for(`react.memo_cache_sentinel`)?(n={sizes:void 0},t[0]=n):n=t[0];let r;return t[1]===e?r=t[2]:(r=(0,q.jsx)(Ib,{wrapElement:`span`,zoomMargin:20,zoomImg:n,children:(0,q.jsx)(Rb,{...e})}),t[1]=e,t[2]=r),r}function Bb(e){return e!==!1}function Vb(e){let t=(0,J.c)(14),n=e.src,r=e.title,i;t[0]===e.controls?i=t[1]:(i=Bb(e.controls),t[0]=e.controls,t[1]=i);let a;return t[2]!==e.autoplay||t[3]!==e.height||t[4]!==e.loop||t[5]!==e.muted||t[6]!==e.playsinline||t[7]!==e.poster||t[8]!==e.preload||t[9]!==e.src||t[10]!==e.title||t[11]!==e.width||t[12]!==i?(a=(0,q.jsx)(`video`,{className:`ok-video`,src:n,title:r,controls:i,autoPlay:e.autoplay,muted:e.muted,loop:e.loop,playsInline:e.playsinline,poster:e.poster,preload:e.preload,width:e.width,height:e.height}),t[2]=e.autoplay,t[3]=e.height,t[4]=e.loop,t[5]=e.muted,t[6]=e.playsinline,t[7]=e.poster,t[8]=e.preload,t[9]=e.src,t[10]=e.title,t[11]=e.width,t[12]=i,t[13]=a):a=t[13],a}function Hb(e){let t=(0,J.c)(2),n;return t[0]===e.children?n=t[1]:(n=(0,q.jsx)(`div`,{className:`prose-no-margin`,children:e.children}),t[0]=e.children,t[1]=n),n}var Ub={Callout:sb,img:zb,video:Vb,audio:nb,Accordion:eb,"*":Hb};function Wb(e){let t=new Set;for(let n of e)n.type===`reactnode`&&t.add(n.name);return t}var Gb=le(),Kb=new Map;function qb(e){if(e.surface===`compat`){let t=Ub[e.rendersAs];if(!t)throw Error(`Compat descriptor '${e.name}' declares rendersAs: '${e.rendersAs}', but no React component is registered under that name in componentMap. Add the canonical component before registering the compat descriptor.`);return{Component:t,reactNodePropNames:Wb(e.props)}}let t=Ub[e.name];return t?{Component:t,reactNodePropNames:Wb(e.props)}:null}for(let[e,t]of Gb.entries()){let n=qb(t);n&&Kb.set(e,n)}function Jb(e,t){return{...e,Component:t.Component,reactNodePropNames:t.reactNodePropNames}}function Yb(e){let t=Gb.getOrWildcard(e),n=Kb.get(t.name)??Kb.get(`*`);if(!n)throw Error(`No React component registered for ${t.name} (and no '*' wildcard)`);return Jb(t,n)}function Xb(){let e=[];for(let[t,n]of Gb.entries()){if(t===`*`)continue;let r=Kb.get(t);r&&e.push(Jb(n,r))}return e}var Zb={ChevronRight:Bn,Image:Xn,MessageSquareWarning:rr,SquarePlay:lr,Volume2:pr};function Qb(e){return e&&Object.hasOwn(Zb,e)?Zb[e]:Rn}var $b=``+new URL(`image-preview-BJSGEOo4.png`,import.meta.url).href,ex=``+new URL(`video-preview-vLovc_Vy.png`,import.meta.url).href,tx={Callout:{description:`Highlight tips, warnings, and notes.`,props:{type:`note`,title:`Heads up`},children:`Callouts draw attention to key information.`},Accordion:{description:`Collapsible section with a clickable summary.`,props:{title:`Click to expand`,defaultOpen:!0},children:`Hidden content goes here.`},img:{description:`Embed an image with optional alt text.`,props:{src:$b,alt:`Sample image`}},video:{description:`Embed a video with native player controls.`,props:{controls:!0,poster:ex}},audio:{description:`Embed an audio file with native player controls.`,props:{controls:!0}}};function nx(e){let t={};for(let n of e.props)n.type!==`reactnode`&&`defaultValue`in n&&n.defaultValue!==void 0&&(t[n.name]=n.defaultValue);return t}function rx(e){let t=Yb(e),n=nx(t);return{type:`jsxComponent`,attrs:{componentName:t.name,kind:`element`,attributes:[],sourceRaw:``,sourceDirty:!0,props:n},content:t.hasChildren?[{type:`paragraph`}]:void 0}}var ix=new Set;function ax(e){ix.add(e)}function ox(e){if(typeof e==`number`)return ix.delete(e);let t=ix.values().next();return t.done?!1:(ix.delete(t.value),!0)}function sx(e,t,n){n.props.some(e=>!(`hidden`in e&&e.hidden)&&e.type!==`reactnode`)?(ax(t),requestAnimationFrame(()=>{e.commands.setNodeSelection(t)})):n.hasChildren&&e.commands.setTextSelection(t+2)}function cx(e){return t=>{let n=new WeakSet;t.state.doc.descendants(t=>{t.type.name===`jsxComponent`&&t.attrs.componentName===e.name&&n.add(t)}),t.chain().focus().insertContent(rx(e.name)).run();let r=-1;t.state.doc.descendants((t,i)=>{if(r>=0)return!1;t.type.name===`jsxComponent`&&t.attrs.componentName===e.name&&!n.has(t)&&(r=i)}),!(r<0)&&sx(t,r,e)}}function lx(){return Xb().filter(e=>e.surface===`canonical`).map(e=>{let t=tx[e.name],n=e.Component,r=t?{description:t.description,render:()=>(0,q.jsx)(n,{...t.props,children:t.children})}:void 0;return{name:`component-${e.name}`,label:e.displayName??e.name,icon:Qb(e.icon),category:e.category??`content`,command:cx(e),aliases:e.searchTerms,description:e.description,preview:r}})}var ux=new Te(`imageUpload`);function dx(e){let t=document.createElement(`div`);return t.className=`image-upload-skeleton w-full h-40 rounded-md bg-muted animate-pulse motion-reduce:animate-none my-2`,t.setAttribute(`data-upload-widget`,`loading`),t.setAttribute(`role`,`status`),t.setAttribute(`aria-label`,e?.name?`Uploading ${e.name}…`:`Uploading file…`),t}var fx=new Fe({key:ux,state:{init(){return{decorations:ge.empty,uploads:new Map}},apply(e,t){let n=t.decorations.map(e.mapping,e.doc),r=new Map;for(let[n,i]of t.uploads)r.set(n,e.mapping.map(i));let i=e.getMeta(ux);if(!i)return{decorations:n,uploads:r};if(i.type===`add`){let t=Ke.widget(i.pos,i.widget,{id:i.id,stopEvent:()=>!0}),a=n.add(e.doc,[t]),o=new Map(r);return o.set(i.id,e.mapping.map(i.pos)),{decorations:a,uploads:o}}if(i.type===`remove`){let e=n.find(void 0,void 0,e=>e.id===i.id),t=n.remove(e),a=new Map(r);return a.delete(i.id),{decorations:t,uploads:a}}return{decorations:n,uploads:r}}},props:{decorations(e){return ux.getState(e)?.decorations??ge.empty}}});function px(e){let t=e.lastIndexOf(`/`);return t===-1?``:e.slice(0,t)}function mx(e){let t=e.lastIndexOf(`/`);return t===-1?e:e.slice(t+1)}function hx(e){return e.split(`/`).filter(e=>e!==``)}function gx(e,t){let n=px(e),r=px(t),i=mx(e);if(n===r)return i;let a=hx(r),o=hx(n),s=0;for(;s<a.length&&s<o.length&&a[s]===o[s];)s++;let c=a.length-s,l=o.slice(s);return c===0?`./${[...l,i].join(`/`)}`:[...Array(c).fill(`..`),...l,i].join(`/`)}function _x(e){return Gy(e)}function vx(e,t){return{type:`jsxComponent`,attrs:{componentName:e===`jsx-img`?`img`:e===`jsx-video`?`video`:`audio`,kind:`element`,attributes:[],sourceRaw:``,sourceDirty:!0,props:e===`jsx-img`?{src:t,alt:``}:{src:t,controls:!0}}}}function yx(e){let t=me(e);return t===`md`||t===`mdx`?{kind:`wiki-link`,ext:t}:k.has(t)?{kind:`jsx-img`,ext:t}:ee.has(t)?{kind:`jsx-video`,ext:t}:qe.has(t)?{kind:`jsx-audio`,ext:t}:C.has(t)?{kind:`wikiembed`,ext:t}:{kind:`markdown-link`,ext:t}}async function bx(e,t,n){let r=_x(t),i=r?`${r}.md`:``;if(!i){Lt.error(`Cannot upload: no document is open`);return}let a=crypto.randomUUID(),o=dx(e);t.view.dispatch(t.state.tr.setMeta(ux,{type:`add`,id:a,pos:n,widget:o}));let s=new FormData;s.append(`file`,e),s.append(`parentDocName`,i);let c;try{c=await fetch(`/api/upload`,{method:`POST`,body:s})}catch(e){console.error(`[uploadAndInsert] Network error:`,e),xx(t,a);return}let l={};try{l=await c.json()}catch{}if(!c.ok){let e=l.message??l.error??`Upload failed (${c.status})`;console.error(`[uploadAndInsert] Server error:`,e),xx(t,a,e);return}if(typeof l.src!=`string`){console.error(`[uploadAndInsert] Response missing src:`,l),xx(t,a);return}let u=l.src,d=l.deduped===!0,f=px(i),p=typeof l.path==`string`&&l.path.length>0?l.path:f?`${f}/${u}`:u;d&&Lt.info(`Already at ${p} — reusing.`);let m=yx(e.name),{state:h}=t,g=ux.getState(h)?.uploads.get(a)??n,_=h.tr.setMeta(ux,{type:`remove`,id:a}),v=gx(p,i),y=`/${p}`;if(m.kind===`jsx-img`||m.kind===`jsx-video`||m.kind===`jsx-audio`){if(!h.schema.nodes.jsxComponent){console.error(`[uploadAndInsert] jsxComponent node missing from schema`),xx(t,a);return}let e=vx(m.kind,y),n=e.attrs.componentName;t.chain().command(({tr:e})=>(e.setMeta(ux,{type:`remove`,id:a}),!0)).focus().insertContentAt(g,e).run(),sx(t,g,Yb(n));return}if(m.kind===`wikiembed`){let e=h.schema.nodes.wikiLinkEmbed;if(!e){console.error(`[uploadAndInsert] wikiLinkEmbed node missing from schema`),xx(t,a);return}_.insert(g,e.create({target:u,alias:null,anchor:null,resolvedSrc:y}))}else if(m.kind===`wiki-link`){let n=h.schema.nodes.wikiLink;if(!n){console.error(`[uploadAndInsert] wikiLink node missing from schema`),xx(t,a);return}let r=Yy(e.name.replace(/\.(md|mdx)$/i,``));r?_.insert(g,n.create(r)):_.insert(g,h.schema.text(e.name))}else{let t=h.schema.marks.link;if(t){let n=h.schema.text(e.name,[t.create({href:v})]);_.insert(g,n)}else _.insert(g,h.schema.text(e.name))}t.view.dispatch(_)}function xx(e,t,n){e.view.dispatch(e.state.tr.setMeta(ux,{type:`remove`,id:t})),Lt.error(n??`Upload failed`)}var Sx=[{name:`heading1`,label:`Heading 1`,icon:qn,category:`basic`,command:e=>e.chain().focus().toggleHeading({level:1}).run(),aliases:[`h1`],preview:{description:`Big section heading.`,render:()=>(0,q.jsx)(`h1`,{className:`text-2xl font-semibold tracking-tight`,children:`Heading 1`})}},{name:`heading2`,label:`Heading 2`,icon:Jn,category:`basic`,command:e=>e.chain().focus().toggleHeading({level:2}).run(),aliases:[`h2`],preview:{description:`Medium section heading.`,render:()=>(0,q.jsx)(`h2`,{className:`text-xl font-semibold tracking-tight`,children:`Heading 2`})}},{name:`heading3`,label:`Heading 3`,icon:Yn,category:`basic`,command:e=>e.chain().focus().toggleHeading({level:3}).run(),aliases:[`h3`],preview:{description:`Small section heading.`,render:()=>(0,q.jsx)(`h3`,{className:`text-base font-semibold tracking-tight`,children:`Heading 3`})}},{name:`bulletList`,label:`Bullet List`,icon:tr,category:`basic`,command:e=>e.chain().focus().toggleBulletList().run(),aliases:[`ul`,`unordered`],preview:{description:`Unordered list of items.`,render:()=>(0,q.jsxs)(`ul`,{className:`list-disc pl-5 text-sm leading-7`,children:[(0,q.jsx)(`li`,{children:`First item`}),(0,q.jsx)(`li`,{children:`Second item`})]})}},{name:`orderedList`,label:`Ordered List`,icon:$n,category:`basic`,command:e=>e.chain().focus().toggleOrderedList().run(),aliases:[`ol`,`numbered`],preview:{description:`Numbered list of items.`,render:()=>(0,q.jsxs)(`ol`,{className:`list-decimal pl-5 text-sm leading-7`,children:[(0,q.jsx)(`li`,{children:`First item`}),(0,q.jsx)(`li`,{children:`Second item`})]})}},{name:`taskList`,label:`Task List`,icon:er,category:`basic`,command:e=>e.chain().focus().toggleTaskList().run(),aliases:[`todo`,`checklist`,`checkbox`],preview:{description:`Checklist with checkboxes.`,render:()=>(0,q.jsxs)(`ul`,{className:`space-y-1.5 text-sm`,children:[(0,q.jsxs)(`li`,{className:`flex items-center gap-2`,children:[(0,q.jsx)(`input`,{type:`checkbox`,checked:!0,readOnly:!0,className:`size-3.5`}),(0,q.jsx)(`span`,{className:`text-muted-foreground line-through`,children:`Done`})]}),(0,q.jsxs)(`li`,{className:`flex items-center gap-2`,children:[(0,q.jsx)(`input`,{type:`checkbox`,readOnly:!0,className:`size-3.5`}),(0,q.jsx)(`span`,{children:`To do`})]})]})}},{name:`blockquote`,label:`Quote`,icon:sr,category:`basic`,command:e=>e.chain().focus().toggleBlockquote().run(),aliases:[`quote`],preview:{description:`Indented blockquote for citations.`,render:()=>(0,q.jsx)(`blockquote`,{className:`border-l-2 border-muted-foreground/40 pl-3 text-sm italic text-muted-foreground`,children:`A pull quote stands out from the surrounding text.`})}},{name:`codeBlock`,label:`Code Block`,icon:Hn,category:`basic`,command:e=>e.chain().focus().toggleCodeBlock().run(),aliases:[`code`,`fence`],preview:{description:`Fenced code block with monospace text.`,render:()=>(0,q.jsx)(`pre`,{className:`rounded-md bg-muted px-2.5 py-2 font-mono text-xs leading-5`,children:(0,q.jsx)(`code`,{children:`const greeting = "Hello";
6
- console.log(greeting);`})})}},{name:`table`,label:`Table`,icon:ur,category:`insert`,command:e=>e.chain().focus().insertTable({rows:3,cols:3,withHeaderRow:!0}).run(),aliases:[`grid`],preview:{description:`Grid of rows and columns with a header row.`,render:()=>(0,q.jsxs)(`table`,{className:`w-full border-collapse text-xs`,children:[(0,q.jsx)(`thead`,{children:(0,q.jsxs)(`tr`,{children:[(0,q.jsx)(`th`,{className:`border border-border bg-muted/50 px-2 py-1 text-left font-semibold`,children:`Name`}),(0,q.jsx)(`th`,{className:`border border-border bg-muted/50 px-2 py-1 text-left font-semibold`,children:`Role`})]})}),(0,q.jsxs)(`tbody`,{children:[(0,q.jsxs)(`tr`,{children:[(0,q.jsx)(`td`,{className:`border border-border px-2 py-1`,children:`Ada`}),(0,q.jsx)(`td`,{className:`border border-border px-2 py-1`,children:`Engineer`})]}),(0,q.jsxs)(`tr`,{children:[(0,q.jsx)(`td`,{className:`border border-border px-2 py-1`,children:`Grace`}),(0,q.jsx)(`td`,{className:`border border-border px-2 py-1`,children:`Admiral`})]})]})]})}},{name:`separator`,label:`Separator`,icon:ir,category:`insert`,command:e=>e.chain().focus().setHorizontalRule().run(),aliases:[`hr`,`divider`,`rule`],preview:{description:`Horizontal rule that divides sections.`,render:()=>(0,q.jsxs)(`div`,{className:`w-full`,children:[(0,q.jsx)(`p`,{className:`mb-2 text-xs text-muted-foreground`,children:`Above`}),(0,q.jsx)(`hr`,{className:`border-border`}),(0,q.jsx)(`p`,{className:`mt-2 text-xs text-muted-foreground`,children:`Below`})]})}}];function Cx(e,t){if(!t)return e;let n=t.toLowerCase();return e.filter(e=>e.label.toLowerCase().includes(n)||e.name.toLowerCase().includes(n)||e.aliases?.some(e=>e.toLowerCase().includes(n)))}function wx(e){let{$from:t}=e.selection;return t.depth===0?null:{from:t.before(1),to:t.after(1)}}function Tx(e,t){let n=wx(e);if(!n)return!1;let{from:r,to:i}=n;if(r===0)return!1;let a=e.doc.resolve(r-1);if(a.depth===0)return!1;let o=a.before(1),s=e.doc.slice(r,i).content,c=e.doc.slice(o,r).content;if(!t)return!0;let l=e.tr;l.replaceWith(o,i,s.append(c));let u=o+1,d=o+s.size,f=e.selection.from-r,p=Math.min(u+f,d);return l.setSelection(Je.near(l.doc.resolve(p))),l.scrollIntoView(),t(l),!0}function Ex(e,t){let n=wx(e);if(!n)return!1;let{from:r,to:i}=n;if(i>=e.doc.content.size)return!1;let a=e.doc.resolve(i+1);if(a.depth===0)return!1;let o=a.after(1),s=e.doc.slice(r,i).content,c=e.doc.slice(i,o).content;if(!t)return!0;let l=e.tr;l.replaceWith(r,o,c.append(s));let u=r+c.size+1,d=r+c.size+s.size,f=e.selection.from-r,p=Math.min(u+f,d);return l.setSelection(Je.near(l.doc.resolve(p))),l.scrollIntoView(),t(l),!0}var Dx=W.create({name:`blockMover`,addKeyboardShortcuts(){return{"Mod-Shift-ArrowUp":({editor:e})=>Tx(e.state,e.view.dispatch),"Mod-Shift-ArrowDown":({editor:e})=>Ex(e.state,e.view.dispatch)}}}),Ox=new Te(`y-sync`);new Te(`y-undo`),new Te(`yjs-cursor`);var kx=new Te(`bridgeId`);function Ax(e){let t=Ox.getState(e);return t?.binding?.mapping?t.binding.mapping:null}function jx(e){let t=Ax(e);if(!t)return null;let n=new Map;for(let[e,r]of t)r&&`nodeName`in e&&typeof e.getAttribute==`function`&&n.set(r,e);return n}function Mx(e,t){return e?e.get(t)??null:null}var Nx=W.create({name:`bridgeIdPlugin`,priority:1e3,addProseMirrorPlugins(){return[new Fe({key:kx,state:{init(e,t){let n={yElementToId:new WeakMap,posToId:new Map,counter:0},r=jx(t);return t.doc.descendants((e,t)=>{if(e.type.name!==`jsxComponent`)return;let i=Mx(r,e);if(i){let e=`b${++n.counter}`;n.yElementToId.set(i,e),n.posToId.set(t,e)}else{let e=`b${++n.counter}`;n.posToId.set(t,e)}}),n},apply(e,t,n,r){if(!e.docChanged){let n=new Map;for(let[i,a]of t.posToId){let t=e.mapping.map(i);r.doc.nodeAt(t)?.type.name===`jsxComponent`&&n.set(t,a)}return{...t,posToId:n}}let i=new Map,{counter:a}=t,{yElementToId:o}=t,s=jx(r);return r.doc.descendants((n,r)=>{if(n.type.name!==`jsxComponent`)return;let c=Mx(s,n);if(c){let e=o.get(c);if(e)i.set(r,e);else{let e=`b${++a}`;o.set(c,e),i.set(r,e)}}else{let n=!1;for(let[a,o]of t.posToId)if(e.mapping.map(a)===r){i.set(r,o),n=!0;break}if(!n){let e=`b${++a}`;i.set(r,e)}}}),{yElementToId:o,posToId:i,counter:a}}}})]}});function Px(e){return!!e.getMeta(Im)}function Fx(e,t){let n=Im.getState(e);return Ch(n.doc,n.type,t,n.binding.mapping)||0}function Ix(e,t){let n=Im.getState(e);return xh(t,n.type,n.binding.mapping)}var Lx=class e extends re{constructor(e,t){super(e),this.yRelativePosition=t}static fromJSON(t){return new e(t.position,t.yRelativePosition)}toJSON(){return{position:this.position,yRelativePosition:this.yRelativePosition}}};function Rx(e,t){return new Lx(e,Ix(t,e))}function zx(e,t,n){let r=e instanceof Lx?e.yRelativePosition:null;if(Px(t)&&r)return{position:new Lx(Fx(n,r),r),mapResult:null};let i=Oe(e,t),a=i.position.position;return{position:new Lx(a,r??Ix(n,a)),mapResult:i.mapResult}}var Bx=W.create({name:`collaboration`,priority:1e3,addOptions(){return{document:null,field:`default`,fragment:null,provider:null}},addStorage(){return{isDisabled:!1}},onCreate(){this.editor.extensionManager.extensions.find(e=>e.name===`undoRedo`)&&console.warn(`[tiptap warn]: "@tiptap/extension-collaboration" comes with its own history support and is not compatible with "@tiptap/extension-undo-redo".`)},onBeforeCreate(){this.editor.utils.getUpdatedPosition=(e,t)=>zx(e,t,this.editor.state),this.editor.utils.createMappablePosition=e=>Rx(e,this.editor.state)},addCommands(){return{undo:()=>({tr:e,state:t,dispatch:n})=>(e.setMeta(`preventDispatch`,!0),Lm.getState(t).undoManager.undoStack.length===0?!1:n?Ah(t):!0),redo:()=>({tr:e,state:t,dispatch:n})=>(e.setMeta(`preventDispatch`,!0),Lm.getState(t).undoManager.redoStack.length===0?!1:n?jh(t):!0)}},addKeyboardShortcuts(){return{"Mod-z":()=>this.editor.commands.undo(),"Mod-y":()=>this.editor.commands.redo(),"Shift-Mod-z":()=>this.editor.commands.redo()}},addProseMirrorPlugins(){let e=this.options.fragment?this.options.fragment:this.options.document.getXmlFragment(this.options.field),t=Ph(this.options.yUndoOptions),n=t.spec.view;return t.spec.view=e=>{let{undoManager:t}=Lm.getState(e.state);t.restore&&=(t.restore(),()=>{});let r=n?n(e):void 0;return{destroy:()=>{let e=t.trackedOrigins.has(t),n=t._observers;t.restore=()=>{e&&t.trackedOrigins.add(t),t.doc.on(`afterTransaction`,t.afterTransactionHandler),t._observers=n},r?.destroy&&r.destroy()}}},[Wm(e,{...this.options.ySyncOptions,onFirstRender:this.options.onFirstRender}),t,this.editor.options.enableContentCheck&&new Fe({key:new Te(`filterInvalidContent`),filterTransaction:t=>{if(!Px(t))return!0;if(this.storage.isDisabled)return!1;if(!t.docChanged)return!0;try{return t.doc.check(),!0}catch(t){return this.storage.isDisabled=!0,this.editor.emit(`contentError`,{error:t,editor:this.editor,disableCollaboration:()=>{var t;(t=e.doc)==null||t.destroy()}}),!1}}})].filter(Boolean)}});function Vx(e){if(!e.length)return ge.empty;let t=[],n=e[0].$from.node(0);return e.forEach(e=>{let n=e.$from.pos,r=e.$from.nodeAfter;r&&t.push(Ke.node(n,n+r.nodeSize,{class:`ProseMirror-selectednoderange`}))}),ge.create(n,t)}function Hx(e,t,n){let r=n.isText||n.isAtom?0:1;return{start:e+r,end:e+t-r}}function Ux(e,t,n,r={}){let i=[],a=e.node(0),{extendOnBoundaryOverlap:o=!0}=r;typeof n==`number`&&n>=0||(n=e.sameParent(t)?Math.max(0,e.sharedDepth(t.pos)-1):e.sharedDepth(t.pos));let s=new B(e,t,n),c=s.depth===0?0:a.resolve(s.start).posAtIndex(0);return s.parent.forEach((n,r)=>{let l=c+r,u=l+n.nodeSize,d=Hx(l,n.nodeSize,n),f=o?t.pos>=d.start&&e.pos<=d.end:t.pos>d.start&&e.pos<d.end;if(l<s.start||l>=s.end||!f)return;let p=new oe(a.resolve(l),a.resolve(u));i.push(p)}),i}var Wx=class e{constructor(e,t){this.anchor=e,this.head=t}map(t){return new e(t.map(this.anchor),t.map(this.head))}resolve(e){return new Gx(e.resolve(this.anchor),e.resolve(this.head))}},Gx=class e extends Se{constructor(e,t,n,r=1){let{doc:i}=e,a=e===t,o=e.pos===i.content.size&&t.pos===i.content.size,s=a&&!o?i.resolve(t.pos+(r>0?1:-1)):t,c=a&&o?i.resolve(e.pos-(r>0?1:-1)):e,l=Ux(c.min(s),c.max(s),n),u=s.pos>=e.pos?l[0].$from:l[l.length-1].$to,d=s.pos>=e.pos?l[l.length-1].$to:l[0].$from;super(u,d,l),this.depth=n}get $to(){return this.ranges[this.ranges.length-1].$to}eq(t){return t instanceof e&&t.$from.pos===this.$from.pos&&t.$to.pos===this.$to.pos}map(t,n){return new e(t.resolve(n.map(this.anchor)),t.resolve(n.map(this.head)))}toJSON(){return{type:`nodeRange`,anchor:this.anchor,head:this.head}}get isForwards(){return this.head>=this.anchor}get isBackwards(){return!this.isForwards}extendBackwards(){let{doc:t}=this.$from;if(this.isForwards&&this.ranges.length>1){let t=this.ranges.slice(0,-1),n=t[0].$from,r=t[t.length-1].$to;return new e(n,r,this.depth)}let n=this.ranges[0],r=t.resolve(Math.max(0,n.$from.pos-1));return new e(this.$anchor,r,this.depth)}extendForwards(){let{doc:t}=this.$from;if(this.isBackwards&&this.ranges.length>1){let t=this.ranges.slice(1),n=t[0].$from,r=t[t.length-1].$to;return new e(r,n,this.depth)}let n=this.ranges[this.ranges.length-1],r=t.resolve(Math.min(t.content.size,n.$to.pos+1));return new e(this.$anchor,r,this.depth)}static fromJSON(t,n){return new e(t.resolve(n.anchor),t.resolve(n.head))}static create(e,t,n,r,i=1){return new this(e.resolve(t),e.resolve(n),r,i)}getBookmark(){return new Wx(this.anchor,this.head)}};Gx.prototype.visible=!1;function Kx(e){return e instanceof Gx}W.create({name:`nodeRange`,addOptions(){return{depth:void 0,key:`Mod`}},addKeyboardShortcuts(){return{"Shift-ArrowUp":({editor:e})=>{let{depth:t}=this.options,{view:n,state:r}=e,{doc:i,selection:a,tr:o}=r,{anchor:s,head:c}=a;if(!Kx(a)){let e=Gx.create(i,s,c,t,-1);return o.setSelection(e),n.dispatch(o),!0}let l=a.extendBackwards();return o.setSelection(l),n.dispatch(o),!0},"Shift-ArrowDown":({editor:e})=>{let{depth:t}=this.options,{view:n,state:r}=e,{doc:i,selection:a,tr:o}=r,{anchor:s,head:c}=a;if(!Kx(a)){let e=Gx.create(i,s,c,t);return o.setSelection(e),n.dispatch(o),!0}let l=a.extendForwards();return o.setSelection(l),n.dispatch(o),!0},"Mod-a":({editor:e})=>{let{depth:t}=this.options,{view:n,state:r}=e,{doc:i,tr:a}=r,o=Gx.create(i,0,i.content.size,t);return a.setSelection(o),n.dispatch(a),!0}}},onSelectionUpdate(){let{selection:e}=this.editor.state;Kx(e)&&this.editor.view.dom.classList.add(`ProseMirror-noderangeselection`)},addProseMirrorPlugins(){let e=!1,t=!1;return[new Fe({key:new Te(`nodeRange`),props:{attributes:()=>e?{class:`ProseMirror-noderangeselection`}:{class:``},handleDOMEvents:{mousedown:(e,n)=>{let{key:r}=this.options,i=/Mac/.test(navigator.platform),a=!!n.shiftKey,o=!!n.ctrlKey,s=!!n.altKey,c=!!n.metaKey;return(r==null||r===`Shift`&&a||r===`Control`&&o||r===`Alt`&&s||r===`Meta`&&c||r===`Mod`&&(i?c:o))&&(t=!0),t&&document.addEventListener(`mouseup`,()=>{t=!1;let{state:n}=e,{doc:r,selection:i,tr:a}=n,{$anchor:o,$head:s}=i;if(o.sameParent(s))return;let c=Gx.create(r,o.pos,s.pos,this.options.depth);a.setSelection(c),e.dispatch(a)},{once:!0}),!1}},decorations:n=>{let{selection:r}=n,i=Kx(r);if(e=!1,!t)return i?(e=!0,Vx(r.ranges)):null;let{$from:a,$to:o}=r;if(!i&&a.sameParent(o))return null;let s=Ux(a,o,this.options.depth);return s.length?(e=!0,Vx(s)):null}}})]}});function qx(e){let t=``,n=getComputedStyle(e);for(let e=0;e<n.length;e+=1)t+=`${n[e]}:${n.getPropertyValue(n[e])};`;return t}function Jx(e){let t=e.cloneNode(!0),n=[e,...Array.from(e.getElementsByTagName(`*`))],r=[t,...Array.from(t.getElementsByTagName(`*`))];return n.forEach((e,t)=>{r[t].style.cssText=qx(e)}),t}var Yx=[{id:`listItemFirstChild`,evaluate:({parent:e,isFirst:t})=>t&&e&&[`listItem`,`taskItem`].includes(e.type.name)?1e3:0},{id:`listWrapperDeprioritize`,evaluate:({node:e})=>{let t=[`listItem`,`taskItem`],n=e.firstChild;return n&&t.includes(n.type.name)?1e3:0}},{id:`tableStructure`,evaluate:({node:e,parent:t})=>[`tableRow`,`tableCell`,`tableHeader`].includes(e.type.name)||t&&t.type.name===`tableHeader`?1e3:0},{id:`inlineContent`,evaluate:({node:e})=>e.isInline||e.isText?1e3:0}],Xx={edges:[`left`,`top`],threshold:12,strength:500};function Zx(e){return e===void 0||e===`left`?{...Xx}:e===`right`?{edges:[`right`,`top`],threshold:12,strength:500}:e===`both`?{edges:[`left`,`right`,`top`],threshold:12,strength:500}:e===`none`?{edges:[],threshold:0,strength:0}:{...Xx,...e}}function Qx(e,t,n){if(n.edges.length===0)return!1;let r=t.getBoundingClientRect(),{threshold:i,edges:a}=n;return a.some(t=>t===`left`?e.x-r.left<i:t===`right`?r.right-e.x<i:t===`top`?e.y-r.top<i:t===`bottom`?r.bottom-e.y<i:!1)}function $x(e,t,n,r){return!t||n.edges.length===0?0:Qx(e,t,n)?n.strength*r:0}var eS=1e3;function tS(e,t,n,r){let i=eS,a=!1;if(t.every(t=>{let n=t.evaluate(e);return i-=n,i<=0?(a=!0,!1):!0}),a)return-1;let o=e.view.nodeDOM(e.pos);return i-=$x(r,o,n,e.depth),i<=0?-1:i}function nS(e,t,n){return Array.from({length:t},(e,n)=>t-1-n).some(t=>n.includes(e.node(t).type.name))}function rS(e,t,n){if(!Number.isFinite(t.x)||!Number.isFinite(t.y))return null;let r=e.posAtCoords({left:t.x,top:t.y});if(!r)return null;let{doc:i}=e.state,a=i.resolve(r.pos),o=[];n.defaultRules&&o.push(...Yx),o.push(...n.rules);let s=Array.from({length:a.depth},(e,t)=>a.depth-t).map(r=>{let i=a.node(r),s=a.before(r);if(n.allowedContainers&&r>0&&!nS(a,r,n.allowedContainers))return null;let c=r>0?a.node(r-1):null,l=r>0?a.index(r-1):0,u=c?c.childCount:1,d=tS({node:i,pos:s,depth:r,parent:c,index:l,isFirst:l===0,isLast:l===u-1,$pos:a,view:e},o,n.edgeDetection,t);return d<0?null:{node:i,pos:s,depth:r,score:d,dom:e.nodeDOM(s)}}).filter(e=>e!==null),c=a.nodeAfter;if(c&&c.isAtom&&!c.isInline){let i=r.pos,l=a.depth+1,u=a.parent,d=a.index(),f=u.childCount,p=!0;if(n.allowedContainers&&(p=nS(a,l,n.allowedContainers)),p){let r=tS({node:c,pos:i,depth:l,parent:u,index:d,isFirst:d===0,isLast:d===f-1,$pos:a,view:e},o,n.edgeDetection,t);if(r>=0){let t=e.nodeDOM(i);t&&s.push({node:c,pos:i,depth:l,score:r,dom:t})}}}if(s.length===0)return null;s.sort((e,t)=>t.score===e.score?t.depth-e.depth:t.score-e.score);let l=s[0];return l.dom?{node:l.node,pos:l.pos,dom:l.dom}:null}function iS(e,t){let n=e;for(;n?.parentElement&&n.parentElement!==t.dom;)n=n.parentElement;return n?.parentElement===t.dom?n:void 0}function aS(e){return Number.isFinite(e.top)&&Number.isFinite(e.bottom)&&Number.isFinite(e.left)&&Number.isFinite(e.right)&&e.width>0&&e.height>0}function oS(e,t,n,r=5){if(!Number.isFinite(t)||!Number.isFinite(n))return null;let i=e.dom,a=i.firstElementChild,o=i.lastElementChild;if(!a||!o)return null;let s=a.getBoundingClientRect(),c=o.getBoundingClientRect();if(!aS(s)||!aS(c))return null;let l=Math.min(Math.max(s.top+r,n),c.bottom-r),u=.5,d=Math.abs(s.left-c.left)<u,f=Math.abs(s.right-c.right)<u,p=s;d&&f&&(p=s);let m=Math.min(Math.max(p.left+r,t),p.right-r);return!Number.isFinite(m)||!Number.isFinite(l)?null:{x:m,y:l}}var sS=e=>{let{x:t,y:n,editor:r,nestedOptions:i}=e,{view:a,state:o}=r,s=oS(a,t,n,5);if(!s)return{resultElement:null,resultNode:null,pos:null};let{x:c,y:l}=s;if(i?.enabled){let e=rS(a,{x:c,y:l},i);return e?{resultElement:e.dom,resultNode:e.node,pos:e.pos}:{resultElement:null,resultNode:null,pos:null}}let u=a.root.elementsFromPoint(c,l),d;if(Array.prototype.some.call(u,e=>{if(!a.dom.contains(e))return!1;let t=iS(e,a);return t?(d=t,!0):!1}),!d){let e=a.posAtCoords({left:c,top:l});if(e){let t=o.doc.resolve(e.pos),n=Math.min(t.depth,1),r=n>0?t.before(n):t.pos,i=o.doc.nodeAt(r);if(i){let e=a.nodeDOM(r);return{resultElement:e instanceof HTMLElement?e:null,resultNode:i,pos:r}}}return{resultElement:null,resultNode:null,pos:null}}let f;try{f=a.posAtDOM(d,0)}catch{return{resultElement:null,resultNode:null,pos:null}}let p=o.doc.nodeAt(f);if(!p){let e=o.doc.resolve(f),t=e.parent;return{resultElement:d,resultNode:t,pos:e.start()}}return{resultElement:d,resultNode:p,pos:f}};function cS(e,t){let n=null,r=e.nodeDOM(t);if(r instanceof Element)n=r;else{let{node:r,offset:i}=e.domAtPos(t),a=r.childNodes[i];a instanceof Element?n=a:r instanceof Element?n=r:r.nodeType===Node.TEXT_NODE&&r.parentElement&&(n=r.parentElement)}return(n?getComputedStyle(n).direction:getComputedStyle(e.dom).direction)||`ltr`}function lS(e){var t;(t=e.parentNode)==null||t.removeChild(e)}function uS(e,t,n,r){let{doc:i}=t.view.state;if(n?.enabled&&r?.node&&r.pos>=0){let e=r.pos,t=r.pos+r.node.nodeSize;return[{$from:i.resolve(e),$to:i.resolve(t)}]}let a=sS({editor:t,x:e.clientX,y:e.clientY,direction:`right`,nestedOptions:n});if(!a.resultNode||a.pos===null)return[];let o=a.resultNode.isText||a.resultNode.isAtom?0:-1;return Ux(i.resolve(a.pos),i.resolve(a.pos+a.resultNode.nodeSize+o),0,{extendOnBoundaryOverlap:!1})}function dS(e,t,n,r){let{view:i}=t;if(!e.dataTransfer)return;let{empty:a,$from:o,$to:s}=i.state.selection,c=uS(e,t,n,r),l=Ux(o,s,0,{extendOnBoundaryOverlap:!1}),u=l.some(e=>c.find(t=>t.$from===e.$from&&t.$to===e.$to)),d=a||!u?c:l;if(!d.length)return;let{tr:f}=i.state,p=document.createElement(`div`),m=d[0].$from.pos,h=d[d.length-1].$to.pos;p.setAttribute(`dir`,cS(i,m));let g=n?.enabled&&r?.node,_,v;g?(_=i.state.doc.slice(m,h),v=Le.create(i.state.doc,m)):(v=Gx.create(i.state.doc,m,h),_=v.content()),d.forEach(e=>{let t=Jx(i.nodeDOM(e.$from.pos));p.append(t)}),p.style.position=`absolute`,p.style.top=`-10000px`,document.body.append(p),e.dataTransfer.clearData();let y=p.getBoundingClientRect(),b=e.clientX-y.left;e.dataTransfer.setDragImage(p,Math.max(0,Math.min(b,y.width)),0);let x=!1,S=()=>{x||(x=!0,lS(p),document.removeEventListener(`drop`,S),document.removeEventListener(`dragend`,S))},C=v instanceof Le?v:void 0;i.dragging={slice:_,move:!0,node:C},f.setSelection(v),i.dispatch(f),document.addEventListener(`drop`,S),document.addEventListener(`dragend`,S)}var fS=(e,t)=>{let n=e.resolve(t),{depth:r}=n;return r===0?t:n.pos-n.parentOffset-1},pS=(e,t)=>{let n=e.nodeAt(t),r=e.resolve(t),{depth:i}=r,a=n;for(;i>0;){let e=r.node(i);--i,i===0&&(a=e)}return a},mS=(e,t)=>{let n=Im.getState(e);return n?xh(t,n.type,n.binding.mapping):null},hS=(e,t)=>{let n=Im.getState(e);return n?Ch(n.doc,n.type,t,n.binding.mapping)||0:-1},gS=(e,t)=>{let n=t;for(;n?.parentNode&&n.parentNode!==e.dom;)n=n.parentNode;return n},_S=new Te(`dragHandle`),vS=({pluginKey:e=_S,element:t,editor:n,computePositionConfig:r,getReferencedVirtualElement:i,onNodeChange:a,onElementDragStart:o,onElementDragEnd:s,nestedOptions:c})=>{let l=document.createElement(`div`),u=!1,d=null,f=-1,p,m=null,h=null;function g(){t&&(t.style.visibility=`hidden`,t.style.pointerEvents=`none`)}function _(){if(t){if(!n.isEditable){g();return}t.style.visibility=``,t.style.pointerEvents=`auto`}}function v(e){b(i?.()||{getBoundingClientRect:()=>e.getBoundingClientRect()},t,r).then(e=>{Object.assign(t.style,{position:e.strategy,left:`${e.x}px`,top:`${e.y}px`})})}function y(e){o?.(e),dS(e,n,c,{node:d,pos:f}),t&&(t.dataset.dragging=`true`),setTimeout(()=>{t&&(t.style.pointerEvents=`none`)},0)}function x(e){s?.(e),g(),t&&(t.style.pointerEvents=`auto`,t.dataset.dragging=`false`)}function S(){if(ce()){let e=n.view.dom;requestAnimationFrame(()=>{e.isContentEditable&&(e.contentEditable=`false`,e.contentEditable=`true`)})}}return l.appendChild(t),{unbind(){t.removeEventListener(`dragstart`,y),t.removeEventListener(`dragend`,x),document.removeEventListener(`drop`,S),m&&(cancelAnimationFrame(m),m=null,h=null)},plugin:new Fe({key:typeof e==`string`?new Te(e):e,state:{init(){return{locked:!1}},apply(e,r,i,o){let s=e.getMeta(`lockDragHandle`),c=e.getMeta(`hideDragHandle`);if(s!==void 0&&(u=s),c)return g(),u=!1,d=null,f=-1,a?.({editor:n,node:null,pos:-1}),r;if(e.docChanged&&f!==-1&&t)if(Px(e)){let e=hS(o,p);e!==f&&(f=e)}else{let t=e.mapping.map(f);t!==f&&(f=t,p=mS(o,f))}return r}},view:e=>{var r;return t.draggable=!0,t.style.pointerEvents=`auto`,t.dataset.dragging=`false`,(r=n.view.dom.parentElement)==null||r.appendChild(l),l.style.pointerEvents=`none`,l.style.position=`absolute`,l.style.top=`0`,l.style.left=`0`,t.addEventListener(`dragstart`,y),t.addEventListener(`dragend`,x),document.addEventListener(`drop`,S),{update(r,i){if(!t)return;if(!n.isEditable){g();return}if(u?t.draggable=!1:t.draggable=!0,e.state.doc.eq(i.doc)||f===-1)return;let o=e.nodeDOM(f);if(o=gS(e,o),o===e.dom||o?.nodeType!==1)return;let s=e.posAtDOM(o,0),c=pS(n.state.doc,s),l=fS(n.state.doc,s);d=c,f=l,p=mS(e.state,f),a?.({editor:n,node:d,pos:f}),v(o)},destroy(){t.removeEventListener(`dragstart`,y),t.removeEventListener(`dragend`,x),document.removeEventListener(`drop`,S),m&&(cancelAnimationFrame(m),m=null,h=null),t&&lS(l)}}},props:{handleDOMEvents:{keydown(e){return!t||u?!1:e.hasFocus()?(g(),d=null,f=-1,a?.({editor:n,node:null,pos:-1}),!1):!1},mouseleave(e,t){return u||t.target&&!l.contains(t.relatedTarget)&&(g(),d=null,f=-1,a?.({editor:n,node:null,pos:-1})),!1},mousemove(e,r){return!t||u||(h={x:r.clientX,y:r.clientY},m)||(m=requestAnimationFrame(()=>{if(m=null,!h)return;let{x:t,y:r}=h;h=null;let i=sS({x:t,y:r,direction:`right`,editor:n,nestedOptions:c});if(!i.resultElement)return;let o=i.resultElement,s=i.resultNode,l=i.pos;if(!c?.enabled){if(o=gS(e,o),o===e.dom||o?.nodeType!==1)return;let t=e.posAtDOM(o,0);s=pS(n.state.doc,t),l=fS(n.state.doc,t)}s!==d&&(d=s,f=l??-1,p=mS(e.state,f),a?.({editor:n,node:d,pos:f}),v(o),_())})),!1}}}})}};function yS(e){return e===!1||e===void 0?{enabled:!1,rules:[],defaultRules:!0,allowedContainers:void 0,edgeDetection:Zx(`none`)}:e===!0?{enabled:!0,rules:[],defaultRules:!0,allowedContainers:void 0,edgeDetection:Zx(`left`)}:{enabled:!0,rules:e.rules??[],defaultRules:e.defaultRules??!0,allowedContainers:e.allowedContainers,edgeDetection:Zx(e.edgeDetection)}}var bS={placement:`left-start`,strategy:`absolute`};W.create({name:`dragHandle`,addOptions(){return{render(){let e=document.createElement(`div`);return e.classList.add(`drag-handle`),e},computePositionConfig:{},locked:!1,onNodeChange:()=>null,onElementDragStart:void 0,onElementDragEnd:void 0,nested:!1}},addCommands(){return{lockDragHandle:()=>({editor:e})=>(this.options.locked=!0,e.commands.setMeta(`lockDragHandle`,this.options.locked)),unlockDragHandle:()=>({editor:e})=>(this.options.locked=!1,e.commands.setMeta(`lockDragHandle`,this.options.locked)),toggleDragHandle:()=>({editor:e})=>(this.options.locked=!this.options.locked,e.commands.setMeta(`lockDragHandle`,this.options.locked))}},addProseMirrorPlugins(){let e=this.options.render(),t=yS(this.options.nested);return[vS({computePositionConfig:{...bS,...this.options.computePositionConfig},getReferencedVirtualElement:this.options.getReferencedVirtualElement,element:e,editor:this.editor,onNodeChange:this.options.onNodeChange,onElementDragStart:this.options.onElementDragStart,onElementDragEnd:this.options.onElementDragEnd,nestedOptions:t}).plugin]}});var xS=20,SS=44,CS=28;function wS(){let e=document.createElement(`div`);e.className=`ok-block-controls`,e.style.visibility=`hidden`;let t=document.createElement(`button`);t.className=`ok-add-block-btn`,t.setAttribute(`aria-label`,`Add block below`),t.setAttribute(`type`,`button`),t.innerHTML=`<svg aria-hidden="true" xmlns="http://www.w3.org/2000/svg" width="16" height="16" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" class="lucide lucide-plus"><path d="M5 12h14"/><path d="M12 5v14"/></svg>`,t.addEventListener(`mousedown`,e=>{e.preventDefault(),e.stopPropagation()});let n=document.createElement(`div`);return n.className=`ok-drag-grip`,n.setAttribute(`aria-hidden`,`true`),n.innerHTML=`<svg xmlns="http://www.w3.org/2000/svg" width="16" height="16" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" class="lucide lucide-grip-vertical-icon lucide-grip-vertical"><circle cx="9" cy="12" r="1"/><circle cx="9" cy="5" r="1"/><circle cx="9" cy="19" r="1"/><circle cx="15" cy="12" r="1"/><circle cx="15" cy="5" r="1"/><circle cx="15" cy="19" r="1"/></svg>`,e.appendChild(t),e.appendChild(n),{container:e,addBtn:t}}function TS(e,t,n){let{state:r,view:i}=e;if(n.type.name===`jsxComponent`){let i=n.attrs.componentName??``;if(i){let a=Yb(i);if(a.emptyChildName){let i=t+1+n.content.size;if(i>r.doc.content.size)return;let o=a.emptyChildName;e.chain().focus().insertContentAt(i,rx(o)).run(),sx(e,i,Yb(o));return}}}let a=t+n.nodeSize;if(a>r.doc.content.size)return;let{tr:o}=r,s=r.schema.nodes.paragraph?.create();if(!s)return;o.insert(a,s);let c=Je.near(o.doc.resolve(a+1));o.setSelection(c).scrollIntoView(),i.dispatch(o),i.focus(),e.commands.insertContent(`/`)}var ES=W.create({name:`blockDragHandle`,addProseMirrorPlugins(){let e=this.editor,t=null,n=-1,{container:r,addBtn:i}=wS();return i.addEventListener(`click`,()=>{t&&n>=0&&TS(e,n,t)}),[vS({element:r,editor:e,onNodeChange({node:e,pos:r}){t=e,n=r??-1},computePositionConfig:{placement:`left-start`,strategy:`absolute`,middleware:[nt(({rects:e})=>({mainAxis:10,crossAxis:((e.reference.height<=SS?e.reference.height:CS)-xS)/2}))]},nestedOptions:yS(!1)}).plugin]}}),DS=W.create({name:`headingAnchors`,addProseMirrorPlugins(){return[new Fe({props:{decorations(e){let t=[],n=new Map;return e.doc.descendants((e,r)=>{if(e.type.name===`heading`){let i=xe(e.textContent,n);if(!i)return;t.push(Ke.node(r,r+e.nodeSize,{id:i}))}}),ge.create(e.doc,t)}}})]}}),OS=new class{byExt=new Map;register(e){for(let t of e.exts)this.byExt.set(t.toLowerCase(),e)}lookup(e){let t=this.byExt.get(e.toLowerCase());return t?{found:!0,viewer:t}:{found:!1}}clearForTests(){this.byExt.clear()}get size(){return this.byExt.size}};function kS(e){globalThis.window?.open(e,`_blank`,`noopener,noreferrer`)}async function AS(e,t={}){let n=t.registry??OS,r=`desktopBridge`in t?t.desktopBridge:globalThis.window?.okDesktop,i=t.openUrl??kS;if(!e.forceOsDelegation){let t=n.lookup(e.ext);if(t.found){t.viewer.render(e);return}}if(r){let t=await r.shell.openAsset(e.projectRelPath);t.ok||console.warn(`[asset-dispatch] openAsset refused:`,t.reason,{projectRelPath:e.projectRelPath,ext:e.ext});return}i(e.url)}var jS=new Set([`http:`,`https:`,`mailto:`,`tel:`]);function MS(e){try{let t=new URL(e);return jS.has(t.protocol)}catch{return!1}}function NS(e=window.location.hash){let t=e.match(/^#\/([^?#]+)/);return t?decodeURIComponent(t[1]):``}function PS(e,t=window.location.hash){return c(e,NS(t))}function FS({docName:e,anchor:t}){return t?`#/${e}?anchor=${encodeURIComponent(t)}`:`#/${e}`}function IS(e){e.startsWith(`#`)||MS(e)?window.open(e,`_blank`,`noopener,noreferrer`):console.warn(`[safe-nav] blocked non-safe scheme:`,e)}function LS(e){window.location.assign(FS(e))}function RS(e){IS(FS(e))}function zS(e){return e.metaKey||e.ctrlKey}function BS(e,t=window.location.hash){let n=NS(t);if(!n)return;let r=document.getElementById(e);r&&r.scrollIntoView({behavior:`smooth`,block:`start`}),window.location.assign(Ge(n,e))}function VS(e,t=window.location.hash){if(e.kind===`doc`){LS(e);return}if(e.kind===`anchor`){BS(e.anchor,t);return}IS(e.url)}function HS(e,t,n=window.location.hash){return ie(NS(n),e,t)}function US(e,t){let n=e;for(;n&&typeof n.hasAttribute==`function`;){if(n.hasAttribute(`data-wiki-embed`)){let e=n.getAttribute(`data-target`)??``;if(!e)return null;let r=E(e,t);return r?{kind:n.tagName===`IMG`?`image`:`asset`,relPath:r,title:r.split(`/`).pop()??e}:null}if(n.hasAttribute(`data-wiki-link`)){let e=n.getAttribute(`data-target`)??``;return e?{kind:`wiki-link`,relPath:`${e}.md`,title:e}:null}if(n.tagName===`A`&&n.hasAttribute(`href`)){let e=c(n.getAttribute(`href`)??``,t);if(e?.kind===`asset`){let n=E(e.url,t);return n?{kind:`asset`,relPath:n,title:n.split(`/`).pop()??e.url}:null}}if(n.tagName===`IMG`){let e=n.getAttribute(`src`)??``;if(e){let n=c(e,t);if(n?.kind===`asset`){let e=E(n.url,t);return e?{kind:`image`,relPath:e,title:e.split(`/`).pop()??n.url}:null}}}n=n.parentElement}return null}var WS=new Te(`asset-context-menu`);function GS(e){return new Fe({key:WS,view(t){let n=e.showAssetMenu??(e=>{let t=globalThis.window?.okDesktop;return t?t.shell.showAssetMenu({relPath:e.relPath,title:e.title,kind:e.kind}):Promise.resolve()}),r=t=>{if(!(t.target instanceof Element))return;let r=US(t.target,e.sourceDocName);r&&(t.preventDefault(),n(r))};return t.dom.addEventListener(`contextmenu`,r),{destroy(){t.dom.removeEventListener(`contextmenu`,r)}}}})}var KS=e=>{let t=(0,J.c)(17),{kind:n,ariaLabel:r,onDeactivate:i,children:a,triggerReference:o,layout:s,className:c,"data-slot":l}=e,u=s===void 0?`standard`:s,d=(0,K.useRef)(null),p,m;t[0]===o?(p=t[1],m=t[2]):(p=()=>{let e=d.current;if(e)return F(o,e,()=>{b(o,e,{placement:`bottom-start`,strategy:`fixed`,middleware:[nt(8),T(),f({padding:8})]}).then(t=>{let{x:n,y:r}=t;e.isConnected&&(e.style.left=`${n}px`,e.style.top=`${r}px`)}).catch(qS)})},m=[o],t[0]=o,t[1]=p,t[2]=m),(0,K.useLayoutEffect)(p,m);let h;t[3]===Symbol.for(`react.memo_cache_sentinel`)?(h={position:`fixed`,left:`-9999px`,top:`-9999px`},t[3]=h):h=t[3];let g=u===`wide`?`w-[min(720px,calc(100%-1rem))]`:`w-80`,_;t[4]!==c||t[5]!==g?(_=ht(`ok-interaction-prop-panel pointer-events-auto z-40 rounded-md border border-border bg-popover p-3 shadow-lg`,g,c),t[4]=c,t[5]=g,t[6]=_):_=t[6];let v;t[7]===Symbol.for(`react.memo_cache_sentinel`)?(v=(0,q.jsx)(bt,{className:`size-3.5`,"aria-hidden":`true`}),t[7]=v):v=t[7];let y;t[8]===i?y=t[9]:(y=(0,q.jsx)(_t,{type:`button`,variant:`ghost`,size:`icon`,"aria-label":`Close`,onClick:i,className:`absolute right-1 top-1 size-7`,children:v}),t[8]=i,t[9]=y);let x;return t[10]!==r||t[11]!==a||t[12]!==l||t[13]!==n||t[14]!==_||t[15]!==y?(x=(0,q.jsxs)(`div`,{ref:d,role:`dialog`,"aria-label":r,"data-ok-prop-panel":n,"data-slot":l,style:h,className:_,children:[a,y]}),t[10]=r,t[11]=a,t[12]=l,t[13]=n,t[14]=_,t[15]=y,t[16]=x):x=t[16],x};function qS(){}function JS(e,t){let n=[e,...t.fallbackTargets??[]],r=new Set,i=null;for(let e of n){if(r.has(e))continue;r.add(e);let n=ye(e,{pages:t.pages,folderPaths:t.folderPaths,pagesBySlug:t.pagesBySlug});if(n.kind===`missing`){i??=n;continue}return{kind:`navigate`,displayState:n.kind===`folder`?`folder`:`resolved`,resolvedTarget:n,hashDocName:n.target}}let a=i??ye(e,{pages:t.pages,folderPaths:t.folderPaths,pagesBySlug:t.pagesBySlug});if(a.kind!==`missing`)return{kind:`navigate`,displayState:a.kind===`folder`?`folder`:`resolved`,resolvedTarget:a,hashDocName:a.target};let o=t.createDialogSeed??Pe(a.target);return{kind:`create`,displayState:`missing`,resolvedTarget:a,initialDir:o.initialDir,suggestedName:o.suggestedName}}function YS(e){if(e.kind!==`navigate`||e.displayState!==`folder`)return null;let t=e.resolvedTarget;return`folderPath`in t?{initialDir:t.folderPath,suggestedName:`index.md`}:null}function XS(e){let t=(0,J.c)(10),n,r,i;t[0]===e?(n=t[1],r=t[2],i=t[3]):({className:n,type:i,...r}=e,t[0]=e,t[1]=n,t[2]=r,t[3]=i);let a;t[4]===n?a=t[5]:(a=ht(`h-8 w-full min-w-0 rounded-lg border border-input bg-transparent px-2.5 py-1 text-base transition-colors outline-none file:inline-flex file:h-6 file:border-0 file:bg-transparent file:text-sm file:font-medium file:text-foreground placeholder:text-muted-foreground focus-visible:border-ring focus-visible:ring-3 focus-visible:ring-ring/50 disabled:pointer-events-none disabled:cursor-not-allowed disabled:bg-input/50 disabled:opacity-50 aria-invalid:border-destructive aria-invalid:ring-3 aria-invalid:ring-destructive/20 md:text-sm dark:bg-input/30 dark:disabled:bg-input/80 dark:aria-invalid:border-destructive/50 dark:aria-invalid:ring-destructive/40`,n),t[4]=n,t[5]=a);let o;return t[6]!==r||t[7]!==a||t[8]!==i?(o=(0,q.jsx)(`input`,{type:i,"data-slot":`input`,className:a,...r}),t[6]=r,t[7]=a,t[8]=i,t[9]=o):o=t[9],o}var ZS=[`.md`,`.mdx`];function QS(e){let t=e.toLowerCase();for(let e of ZS)if(t.endsWith(e))return e;return null}function $S(e){let t=QS(e);return t?e.slice(0,-t.length):e}function eC(e){return e.trim()?e.includes(`..`)?`Path cannot contain ".."`:e.startsWith(`/`)?`Path cannot start with "/"`:e.includes(`\\`)?`Path cannot contain backslashes`:e.includes(`\0`)?`Path cannot contain null bytes`:null:`Name cannot be empty`}function tC(e){let t=e.fileName.trim(),n=QS(t)?t:`${t}${e.fileExtension??`.md`}`;if(e.kind===`folder`){let t=(e.folderName??``).trim();return`${e.initialDir?`${e.initialDir}/${t}`:t}/${n}`}return e.initialDir?`${e.initialDir}/${n}`:n}function nC(e){let t=e.target;return t?.tagName===`INPUT`||t?.tagName===`TEXTAREA`||t?.isContentEditable?!1:!!((e.metaKey||e.ctrlKey)&&e.altKey&&e.key.toLowerCase()===`n`)}function rC(e){let t=e.value.lastIndexOf(`.`);t>0?e.setSelectionRange(0,t):e.select()}function iC(e){let t=(0,J.c)(96),{open:n,onOpenChange:r,kind:i,initialDir:a,suggestedName:o,description:s,onCreated:c}=e,{addPage:l}=De(),[u,d]=(0,K.useState)(``),[f,p]=(0,K.useState)(``),[m,h]=(0,K.useState)(`.md`),[g,_]=(0,K.useState)(null),[v,y]=(0,K.useState)(!1),[b,x]=(0,K.useState)(null),S=(0,K.useId)(),C=(0,K.useId)(),w=(0,K.useId)(),T=(0,K.useRef)(null),E=(0,K.useRef)(null),D,O;t[0]!==i||t[1]!==n||t[2]!==o?(D=()=>{if(n){_(null),x(null),y(!1),p(``);let e=i===`file`?o??`untitled`:`index`,t=QS(e);h(t??`.md`),d(t?$S(e):e)}},O=[n,i,o],t[0]=i,t[1]=n,t[2]=o,t[3]=D,t[4]=O):(D=t[3],O=t[4]),(0,K.useEffect)(D,O);let k;t[5]===Symbol.for(`react.memo_cache_sentinel`)?(k=function(e){let t=QS(e);t?(h(t),d($S(e))):d(e),_(null)},t[5]=k):k=t[5];let A=k,j;t[6]!==m||t[7]!==u||t[8]!==f||t[9]!==a||t[10]!==i?(j=function(){return tC({kind:i,initialDir:a,fileName:u,fileExtension:m,folderName:f})},t[6]=m,t[7]=u,t[8]=f,t[9]=a,t[10]=i,t[11]=j):j=t[11];let M=j,N;t[12]!==u||t[13]!==f||t[14]!==i?(N=function(){if(i===`folder`){let e=eC(f.trim());if(e)return{message:`Folder name: ${e}`,field:`folder`}}let e=eC(u.trim());return e?{message:e,field:`file`}:null},t[12]=u,t[13]=f,t[14]=i,t[15]=N):N=t[15];let P=N,F;t[16]!==v||t[17]!==u||t[18]!==f||t[19]!==i?(F=v||!u.trim()||i===`folder`&&!f.trim(),t[16]=v,t[17]=u,t[18]=f,t[19]=i,t[20]=F):F=t[20];let I=F,L;t[21]!==l||t[22]!==M||t[23]!==P||t[24]!==i||t[25]!==c||t[26]!==r?(L=async function(){let e=P();if(e){_(e.message),x(e.field);return}y(!0),_(null),x(null);let t=M();try{let e=await fetch(`/api/create-page`,{method:`POST`,headers:{"Content-Type":`application/json`},body:JSON.stringify({path:t})});if(!e.ok){let t=`Server error (HTTP ${e.status})`;try{let n=await e.json();n?.error&&(t=n.error)}catch{}y(!1),_(t),x(`form`);return}let n=await e.json();if(y(!1),!n.ok){_(n.error??`Failed to create ${i}`),x(`form`);return}let a=n.docName??t.replace(/\.(mdx|md)$/,``);r(!1),window.location.hash=`#/${a}`,l(a),se([`files`,`backlinks`,`graph`]),c?.(a)}catch(e){console.warn(`[NewItemDialog] create failed:`,e),y(!1),_(`Network error — please try again`),x(`form`)}},t[21]=l,t[22]=M,t[23]=P,t[24]=i,t[25]=c,t[26]=r,t[27]=L):L=t[27];let R=L,z=a||`(root)`,B=i===`file`?`New file`:`New folder`,V;t[28]===B?V=t[29]:(V=(0,q.jsx)(Ct,{children:B}),t[28]=B,t[29]=V);let H;t[30]!==s||t[31]!==z?(H=s??(0,q.jsxs)(q.Fragment,{children:[`Create in `,(0,q.jsx)(`span`,{className:`font-medium text-foreground`,children:z})]}),t[30]=s,t[31]=z,t[32]=H):H=t[32];let U;t[33]===H?U=t[34]:(U=(0,q.jsx)(St,{children:H}),t[33]=H,t[34]=U);let ee;t[35]!==U||t[36]!==V?(ee=(0,q.jsxs)(Nt,{children:[V,U]}),t[35]=U,t[36]=V,t[37]=ee):ee=t[37];let te;t[38]!==g||t[39]!==b||t[40]!==S||t[41]!==C||t[42]!==f||t[43]!==i?(te=i===`folder`&&(0,q.jsxs)(`div`,{children:[(0,q.jsx)(`label`,{className:`mb-1.5 block text-sm font-medium`,htmlFor:C,children:`Folder name`}),(0,q.jsx)(XS,{ref:E,id:C,value:f,onChange:e=>{p(e.target.value),_(null)},placeholder:`folder-name`,autoFocus:!0,"aria-describedby":g&&(b===`folder`||b===`form`)?S:void 0,"aria-invalid":g&&(b===`folder`||b===`form`)?!0:void 0,onKeyDown:e=>{if(e.key===`Enter`){e.preventDefault();let t=eC(f.trim());if(t){_(`Folder name: ${t}`),x(`folder`);return}T.current?.focus()}}})]}),t[38]=g,t[39]=b,t[40]=S,t[41]=C,t[42]=f,t[43]=i,t[44]=te):te=t[44];let ne=i===`folder`?`First file name`:`File name`,re;t[45]!==w||t[46]!==ne?(re=(0,q.jsx)(`label`,{className:`mb-1.5 block text-sm font-medium`,htmlFor:w,children:ne}),t[45]=w,t[46]=ne,t[47]=re):re=t[47];let W;t[48]===Symbol.for(`react.memo_cache_sentinel`)?(W=e=>A(e.target.value),t[48]=W):W=t[48];let ie=i===`file`,ae=g&&(b===`file`||b===`form`)?S:void 0,oe=g&&(b===`file`||b===`form`)?!0:void 0,ce;t[49]!==R||t[50]!==I?(ce=e=>{e.key===`Enter`&&!I&&R()},t[49]=R,t[50]=I,t[51]=ce):ce=t[51];let le;t[52]!==w||t[53]!==u||t[54]!==ie||t[55]!==ae||t[56]!==oe||t[57]!==ce?(le=(0,q.jsx)(XS,{ref:T,id:w,value:u,onChange:W,placeholder:`my-note`,autoFocus:ie,"aria-describedby":ae,"aria-invalid":oe,onFocus:oC,onKeyDown:ce,className:`flex-1`}),t[52]=w,t[53]=u,t[54]=ie,t[55]=ae,t[56]=oe,t[57]=ce,t[58]=le):le=t[58];let ue;t[59]===Symbol.for(`react.memo_cache_sentinel`)?(ue=e=>{(e===`.md`||e===`.mdx`)&&h(e)},t[59]=ue):ue=t[59];let de;t[60]===Symbol.for(`react.memo_cache_sentinel`)?(de=ZS.map(aC),t[60]=de):de=t[60];let fe;t[61]===m?fe=t[62]:(fe=(0,q.jsx)(Ue,{type:`single`,value:m,onValueChange:ue,variant:`outline`,size:`sm`,"aria-label":`File extension`,className:`shrink-0`,children:de}),t[61]=m,t[62]=fe);let pe;t[63]!==le||t[64]!==fe?(pe=(0,q.jsxs)(`div`,{className:`flex items-stretch gap-2`,children:[le,fe]}),t[63]=le,t[64]=fe,t[65]=pe):pe=t[65];let me;t[66]!==g||t[67]!==S?(me=g&&(0,q.jsx)(`p`,{id:S,role:`alert`,className:`text-xs text-red-600 dark:text-red-400`,children:g}),t[66]=g,t[67]=S,t[68]=me):me=t[68];let he;t[69]!==re||t[70]!==pe||t[71]!==me?(he=(0,q.jsxs)(`div`,{children:[re,pe,me]}),t[69]=re,t[70]=pe,t[71]=me,t[72]=he):he=t[72];let ge;t[73]!==te||t[74]!==he?(ge=(0,q.jsx)(At,{children:(0,q.jsxs)(`div`,{className:`space-y-3`,children:[te,he]})}),t[73]=te,t[74]=he,t[75]=ge):ge=t[75];let _e;t[76]===r?_e=t[77]:(_e=()=>r(!1),t[76]=r,t[77]=_e);let ve;t[78]!==v||t[79]!==_e?(ve=(0,q.jsx)(_t,{variant:`outline`,className:`font-mono uppercase`,onClick:_e,disabled:v,children:`Cancel`}),t[78]=v,t[79]=_e,t[80]=ve):ve=t[80];let ye=v?`Creating...`:`Create`,be;t[81]!==R||t[82]!==I||t[83]!==ye?(be=(0,q.jsx)(_t,{onClick:R,disabled:I,children:ye}),t[81]=R,t[82]=I,t[83]=ye,t[84]=be):be=t[84];let xe;t[85]!==ve||t[86]!==be?(xe=(0,q.jsxs)(jt,{children:[ve,be]}),t[85]=ve,t[86]=be,t[87]=xe):xe=t[87];let Se;t[88]!==ee||t[89]!==ge||t[90]!==xe?(Se=(0,q.jsxs)(Ot,{className:`sm:max-w-md`,"data-ok-layer-spawned":``,children:[ee,ge,xe]}),t[88]=ee,t[89]=ge,t[90]=xe,t[91]=Se):Se=t[91];let Ce;return t[92]!==r||t[93]!==n||t[94]!==Se?(Ce=(0,q.jsx)(Pt,{open:n,onOpenChange:r,children:Se}),t[92]=r,t[93]=n,t[94]=Se,t[95]=Ce):Ce=t[95],Ce}function aC(e){return(0,q.jsx)(Ie,{value:e,"aria-label":`Use ${e} extension`,children:e},e)}function oC(e){return rC(e.currentTarget)}var sC=class{registry=new Map;_activeNodeId=null;listeners=new Set;_snapshot={activeNodeId:null,active:null};register(e){this.registry.set(e.nodeId,e),this._activeNodeId===e.nodeId&&this.refreshSnapshot()}deregister(e){this.registry.delete(e)&&this._activeNodeId===e&&(this._activeNodeId=null,this.refreshSnapshot())}setActiveNode(e){this._activeNodeId!==e&&(e!==null&&!this.registry.has(e)||(this._activeNodeId=e,this.refreshSnapshot()))}getActiveNode(){return this._activeNodeId}getRegistration(e){return this.registry.get(e)}hasRegistration(e){return this.registry.has(e)}clear(){this.registry.clear(),this._activeNodeId=null,this.refreshSnapshot()}getSnapshot=()=>this._snapshot;subscribe=e=>(this.listeners.add(e),()=>{this.listeners.delete(e)});refreshSnapshot(){let e=this._activeNodeId==null?null:this.registry.get(this._activeNodeId)??null;this._snapshot={activeNodeId:this._activeNodeId,active:e};for(let e of this.listeners)e()}};function cC(e,t){let n=e??null;for(;n&&typeof n==`object`;){let e=n.getAttribute;if(typeof e==`function`){let r=e.call(n,`data-mark-id`);if(r&&t.hasRegistration(r))return r;let i=e.call(n,`data-node-id`);if(i&&t.hasRegistration(i))return i}n=n.parentElement??null}return null}var lC=e=>{let t=(0,J.c)(18),{store:n}=e,r;t[0]===n?r=t[1]:(r=()=>n.getSnapshot(),t[0]=n,t[1]=r);let[i,a]=(0,K.useState)(r),o,s;t[2]===n?(o=t[3],s=t[4]):(o=()=>(a(n.getSnapshot()),n.subscribe(()=>{a(n.getSnapshot())})),s=[n],t[2]=n,t[3]=o,t[4]=s),(0,K.useEffect)(o,s);let{active:c}=i;if(!c)return null;let l;t[5]===n?l=t[6]:(l=()=>n.setActiveNode(null),t[5]=n,t[6]=l);let u,d,f;if(t[7]!==c.controls||t[8]!==c.nodeId||t[9]!==c.type||t[10]!==l){let e={nodeId:c.nodeId,type:c.type,deactivate:l};u=c.controls.propPanel?.(e),d=c.controls.toolbar?.(e),f=c.controls.breadcrumb?.(e),t[7]=c.controls,t[8]=c.nodeId,t[9]=c.type,t[10]=l,t[11]=u,t[12]=d,t[13]=f}else u=t[11],d=t[12],f=t[13];let p;return t[14]!==u||t[15]!==d||t[16]!==f?(p=(0,q.jsxs)(q.Fragment,{children:[u,d,f]}),t[14]=u,t[15]=d,t[16]=f,t[17]=p):p=t[17],p};function uC(e){return e.editorView?.dom??e.view?.dom??null}function dC(e,t){let n=e;for(;n;){if(n.getAttribute?.(`data-mark-id`)===t||n.getAttribute?.(`data-node-id`)===t)return!0;n=n.parentElement}return!1}function fC(e){let{editor:t}=e,n=new sC,r=uC(t),i=!1,a=null,o=n.subscribe(()=>{let e=n.getActiveNode();if(e!==null){if(typeof document<`u`){let t=document.activeElement;a=t&&dC(t,e)?t:null}return}if(typeof document>`u`)return;let i=a;if(a=null,i&&document.contains(i)&&typeof i.focus==`function`){try{i.focus({preventScroll:!0})}catch{}return}let o=r??uC(t);if(o&&typeof o.focus==`function`)try{o.focus({preventScroll:!0})}catch{}}),s=e=>{let t=e;if(t.button===2)return;if(t.metaKey||t.ctrlKey||t.button===1){t.button===1&&t.preventDefault?.();return}let r=cC(e.target,n);if(r===null)return;let i=n.getRegistration(r);i?.handlePrimary&&i.handlePrimary({nodeId:r,type:i.type,newTab:!1})||n.setActiveNode(r)},c=e=>{let t=e;if(t.button===2||t.type===`click`&&t.button===1||!(t.metaKey||t.ctrlKey||t.button===1))return;let r=cC(e.target,n);if(r===null)return;let i=n.getRegistration(r);i?.handlePrimary&&i.handlePrimary({nodeId:r,type:i.type,newTab:!0})&&t.preventDefault?.()},l=e=>{let t=e;if(t.key===`Escape`){n.getActiveNode()!==null&&(n.setActiveNode(null),t.preventDefault?.());return}if(t.key!==`Enter`&&t.key!==` `&&t.key!==`Spacebar`)return;let r=cC(e.target,n);if(r===null)return;let i=n.getRegistration(r);t.preventDefault?.(),!(i?.handlePrimary&&i.handlePrimary({nodeId:r,type:i.type,newTab:!1}))&&n.setActiveNode(r)},u=e=>{if(n.getActiveNode()===null)return;let t=e.target;t&&(r?.contains(t)||t instanceof Element&&(t.closest(`[data-ok-interaction-layer]`)||t.closest(`[data-ok-prop-panel]`)||t.closest(`[data-ok-layer-spawned]`))||n.setActiveNode(null))},d=()=>{i||(r=uC(t),r&&(r.addEventListener(`pointerdown`,s,!0),r.addEventListener(`click`,c,!0),r.addEventListener(`auxclick`,c,!0),r.addEventListener(`keydown`,l,!0),typeof document<`u`&&document.addEventListener(`pointerdown`,u,!0),i=!0))},f=()=>{i&&=(r?.removeEventListener(`pointerdown`,s,!0),r?.removeEventListener(`click`,c,!0),r?.removeEventListener(`auxclick`,c,!0),r?.removeEventListener(`keydown`,l,!0),typeof document<`u`&&document.removeEventListener(`pointerdown`,u,!0),!1)};return d(),{register(e){n.register(e),i||d()},deregister(e){n.deregister(e)},setActiveNode(e){n.setActiveNode(e)},getActiveNode(){return n.getActiveNode()},getRegistration(e){return n.getRegistration(e)},destroy(){f(),o(),n.clear()},store:n}}var pC=e=>{let t=(0,J.c)(2),{store:n}=e,r;return t[0]===n?r=t[1]:(r=(0,q.jsx)(`div`,{"data-ok-interaction-layer":``,className:`contents`,children:(0,q.jsx)(lC,{store:n})}),t[0]=n,t[1]=r),r},mC=new WeakMap;function hC(e){let t=mC.get(e);if(t)return t;let n=fC({editor:e});return mC.set(e,n),e.on(`destroy`,()=>{n.destroy(),mC.delete(e)}),n}var gC=new Te(`markIdentity`);function _C(){return{byId:new Map,counter:0}}function vC(e,t,n,r,i){let a=[];for(let e of t.byId.values()){let t=i?i.map(e.from,-1):e.from,n=i?i.map(e.to,1):e.to;n<=t||a.push({id:e.id,markType:e.markType,attrs:e.attrs,from:t,to:n})}let o=new Map,s=new Set,c=t.counter;return e.descendants((e,t)=>{if(!(!e.isInline||e.marks.length===0))for(let i of e.marks){if(!n.has(i.type.name)||r&&!r(i))continue;let l=null;for(let e of a)if(!s.has(e.id)&&e.markType===i.type.name&&yC(e.attrs,i.attrs)&&!(t<e.from||t>=e.to)){l=e.id;break}let u=l??`m${++c}`;s.add(u);let d=t,f=t+e.nodeSize,p=o.get(u);p?p.to=Math.max(p.to,f):o.set(u,{id:u,markType:i.type.name,attrs:i.attrs,from:d,to:f})}}),{byId:o,counter:c}}function yC(e,t){let n=Object.keys(e),r=Object.keys(t);if(n.length!==r.length)return!1;for(let r of n){let n=e[r],i=t[r];if(n!==i&&!(typeof n==`object`&&n&&typeof i==`object`&&i&&yC(n,i)))return!1}return!0}function bC(e,t,n,r){let i=new Set(t.byId.keys());for(let[r,i]of t.byId)e.has(r)||n?.(i);for(let t of e)i.has(t)||r?.(t);return i}function xC(e){let{markTypes:t,predicate:n,onRegister:r,onDeregister:i}=e,a=new Set(t);return new Fe({key:gC,state:{init(e,t){return vC(t.doc,_C(),a,n)},apply(e,t,r,i){return e.docChanged?vC(i.doc,t,a,n,e.mapping):t}},view(){let e=new Set;return{update(t){let n=gC.getState(t.state);n&&(e=bC(e,n,r,i))},destroy(){for(let t of e)i?.(t);e=new Set}}}})}function SC(e,t){return gC.getState(e)?.byId.get(t)??null}function CC(e){let{editor:t,layer:n,renderPropPanel:r,handlePrimary:i}=e;return{onRegister:e=>{n.register({type:e.markType,nodeId:e.id,controls:{propPanel:e=>r({editor:t,nodeId:e.nodeId,deactivate:e.deactivate})},handlePrimary:i?e=>i({editor:t,nodeId:e.nodeId,newTab:e.newTab}):void 0})},onDeregister:e=>{n.deregister(e)}}}function wC(e){let{editor:t,layer:n,markTypes:r,predicate:i,renderPropPanel:a,handlePrimary:o}=e,s=CC({editor:t,layer:n,renderPropPanel:a,handlePrimary:o});return xC({markTypes:[...r],predicate:i,onRegister:s.onRegister,onDeregister:s.onDeregister})}function TC(e){let t=hC(e.editor);return wC({...e,layer:t})}function EC(e){let{char:t,allowSpaces:n,allowToIncludeChar:r,allowedPrefixes:i,startOfLine:a,$position:o}=e,s=n&&!r,c=l(t),u=RegExp(`\\s${c}$`),d=a?`^`:``,f=r?``:c,p=RegExp(s?`${d}${c}.*?(?=\\s${f}|$)`:`${d}(?:^)?${c}[^\\s${f}]*`,`gm`),m=o.nodeBefore?.isText&&o.nodeBefore.text;if(!m)return null;let h=o.pos-m.length,g=Array.from(m.matchAll(p)).pop();if(!g||g.input===void 0||g.index===void 0)return null;let _=g.input.slice(Math.max(0,g.index-1),g.index),v=RegExp(`^[${i?.join(``)}\0]?$`).test(_);if(i!==null&&!v)return null;let y=h+g.index,b=y+g[0].length;return s&&u.test(m.slice(b-1,b+1))&&(g[0]+=` `,b+=1),y<o.pos&&b>=o.pos?{range:{from:y,to:b},query:g[0].slice(t.length),text:g[0]}:null}function DC(e){return e.docChanged?e.steps.some(e=>{let t=e.slice;if(!t?.content)return!1;let n=t.content.textBetween(0,t.content.size,`
6
+ console.log(greeting);`})})}},{name:`table`,label:`Table`,icon:ur,category:`insert`,command:e=>e.chain().focus().insertTable({rows:3,cols:3,withHeaderRow:!0}).run(),aliases:[`grid`],preview:{description:`Grid of rows and columns with a header row.`,render:()=>(0,q.jsxs)(`table`,{className:`w-full border-collapse text-xs`,children:[(0,q.jsx)(`thead`,{children:(0,q.jsxs)(`tr`,{children:[(0,q.jsx)(`th`,{className:`border border-border bg-muted/50 px-2 py-1 text-left font-semibold`,children:`Name`}),(0,q.jsx)(`th`,{className:`border border-border bg-muted/50 px-2 py-1 text-left font-semibold`,children:`Role`})]})}),(0,q.jsxs)(`tbody`,{children:[(0,q.jsxs)(`tr`,{children:[(0,q.jsx)(`td`,{className:`border border-border px-2 py-1`,children:`Ada`}),(0,q.jsx)(`td`,{className:`border border-border px-2 py-1`,children:`Engineer`})]}),(0,q.jsxs)(`tr`,{children:[(0,q.jsx)(`td`,{className:`border border-border px-2 py-1`,children:`Grace`}),(0,q.jsx)(`td`,{className:`border border-border px-2 py-1`,children:`Admiral`})]})]})]})}},{name:`separator`,label:`Separator`,icon:ir,category:`insert`,command:e=>e.chain().focus().setHorizontalRule().run(),aliases:[`hr`,`divider`,`rule`],preview:{description:`Horizontal rule that divides sections.`,render:()=>(0,q.jsxs)(`div`,{className:`w-full`,children:[(0,q.jsx)(`p`,{className:`mb-2 text-xs text-muted-foreground`,children:`Above`}),(0,q.jsx)(`hr`,{className:`border-border`}),(0,q.jsx)(`p`,{className:`mt-2 text-xs text-muted-foreground`,children:`Below`})]})}}];function Cx(e,t){if(!t)return e;let n=t.toLowerCase();return e.filter(e=>e.label.toLowerCase().includes(n)||e.name.toLowerCase().includes(n)||e.aliases?.some(e=>e.toLowerCase().includes(n)))}function wx(e){let{$from:t}=e.selection;return t.depth===0?null:{from:t.before(1),to:t.after(1)}}function Tx(e,t){let n=wx(e);if(!n)return!1;let{from:r,to:i}=n;if(r===0)return!1;let a=e.doc.resolve(r-1);if(a.depth===0)return!1;let o=a.before(1),s=e.doc.slice(r,i).content,c=e.doc.slice(o,r).content;if(!t)return!0;let l=e.tr;l.replaceWith(o,i,s.append(c));let u=o+1,d=o+s.size,f=e.selection.from-r,p=Math.min(u+f,d);return l.setSelection(Je.near(l.doc.resolve(p))),l.scrollIntoView(),t(l),!0}function Ex(e,t){let n=wx(e);if(!n)return!1;let{from:r,to:i}=n;if(i>=e.doc.content.size)return!1;let a=e.doc.resolve(i+1);if(a.depth===0)return!1;let o=a.after(1),s=e.doc.slice(r,i).content,c=e.doc.slice(i,o).content;if(!t)return!0;let l=e.tr;l.replaceWith(r,o,c.append(s));let u=r+c.size+1,d=r+c.size+s.size,f=e.selection.from-r,p=Math.min(u+f,d);return l.setSelection(Je.near(l.doc.resolve(p))),l.scrollIntoView(),t(l),!0}var Dx=W.create({name:`blockMover`,addKeyboardShortcuts(){return{"Mod-Shift-ArrowUp":({editor:e})=>Tx(e.state,e.view.dispatch),"Mod-Shift-ArrowDown":({editor:e})=>Ex(e.state,e.view.dispatch)}}}),Ox=new Te(`y-sync`);new Te(`y-undo`),new Te(`yjs-cursor`);var kx=new Te(`bridgeId`);function Ax(e){let t=Ox.getState(e);return t?.binding?.mapping?t.binding.mapping:null}function jx(e){let t=Ax(e);if(!t)return null;let n=new Map;for(let[e,r]of t)r&&`nodeName`in e&&typeof e.getAttribute==`function`&&n.set(r,e);return n}function Mx(e,t){return e?e.get(t)??null:null}var Nx=W.create({name:`bridgeIdPlugin`,priority:1e3,addProseMirrorPlugins(){return[new Fe({key:kx,state:{init(e,t){let n={yElementToId:new WeakMap,posToId:new Map,counter:0},r=jx(t);return t.doc.descendants((e,t)=>{if(e.type.name!==`jsxComponent`)return;let i=Mx(r,e);if(i){let e=`b${++n.counter}`;n.yElementToId.set(i,e),n.posToId.set(t,e)}else{let e=`b${++n.counter}`;n.posToId.set(t,e)}}),n},apply(e,t,n,r){if(!e.docChanged){let n=new Map;for(let[i,a]of t.posToId){let t=e.mapping.map(i);r.doc.nodeAt(t)?.type.name===`jsxComponent`&&n.set(t,a)}return{...t,posToId:n}}let i=new Map,{counter:a}=t,{yElementToId:o}=t,s=jx(r);return r.doc.descendants((n,r)=>{if(n.type.name!==`jsxComponent`)return;let c=Mx(s,n);if(c){let e=o.get(c);if(e)i.set(r,e);else{let e=`b${++a}`;o.set(c,e),i.set(r,e)}}else{let n=!1;for(let[a,o]of t.posToId)if(e.mapping.map(a)===r){i.set(r,o),n=!0;break}if(!n){let e=`b${++a}`;i.set(r,e)}}}),{yElementToId:o,posToId:i,counter:a}}}})]}});function Px(e){return!!e.getMeta(Im)}function Fx(e,t){let n=Im.getState(e);return Ch(n.doc,n.type,t,n.binding.mapping)||0}function Ix(e,t){let n=Im.getState(e);return xh(t,n.type,n.binding.mapping)}var Lx=class e extends re{constructor(e,t){super(e),this.yRelativePosition=t}static fromJSON(t){return new e(t.position,t.yRelativePosition)}toJSON(){return{position:this.position,yRelativePosition:this.yRelativePosition}}};function Rx(e,t){return new Lx(e,Ix(t,e))}function zx(e,t,n){let r=e instanceof Lx?e.yRelativePosition:null;if(Px(t)&&r)return{position:new Lx(Fx(n,r),r),mapResult:null};let i=Oe(e,t),a=i.position.position;return{position:new Lx(a,r??Ix(n,a)),mapResult:i.mapResult}}var Bx=W.create({name:`collaboration`,priority:1e3,addOptions(){return{document:null,field:`default`,fragment:null,provider:null}},addStorage(){return{isDisabled:!1}},onCreate(){this.editor.extensionManager.extensions.find(e=>e.name===`undoRedo`)&&console.warn(`[tiptap warn]: "@tiptap/extension-collaboration" comes with its own history support and is not compatible with "@tiptap/extension-undo-redo".`)},onBeforeCreate(){this.editor.utils.getUpdatedPosition=(e,t)=>zx(e,t,this.editor.state),this.editor.utils.createMappablePosition=e=>Rx(e,this.editor.state)},addCommands(){return{undo:()=>({tr:e,state:t,dispatch:n})=>(e.setMeta(`preventDispatch`,!0),Lm.getState(t).undoManager.undoStack.length===0?!1:n?Ah(t):!0),redo:()=>({tr:e,state:t,dispatch:n})=>(e.setMeta(`preventDispatch`,!0),Lm.getState(t).undoManager.redoStack.length===0?!1:n?jh(t):!0)}},addKeyboardShortcuts(){return{"Mod-z":()=>this.editor.commands.undo(),"Mod-y":()=>this.editor.commands.redo(),"Shift-Mod-z":()=>this.editor.commands.redo()}},addProseMirrorPlugins(){let e=this.options.fragment?this.options.fragment:this.options.document.getXmlFragment(this.options.field),t=Ph(this.options.yUndoOptions),n=t.spec.view;return t.spec.view=e=>{let{undoManager:t}=Lm.getState(e.state);t.restore&&=(t.restore(),()=>{});let r=n?n(e):void 0;return{destroy:()=>{let e=t.trackedOrigins.has(t),n=t._observers;t.restore=()=>{e&&t.trackedOrigins.add(t),t.doc.on(`afterTransaction`,t.afterTransactionHandler),t._observers=n},r?.destroy&&r.destroy()}}},[Wm(e,{...this.options.ySyncOptions,onFirstRender:this.options.onFirstRender}),t,this.editor.options.enableContentCheck&&new Fe({key:new Te(`filterInvalidContent`),filterTransaction:t=>{if(!Px(t))return!0;if(this.storage.isDisabled)return!1;if(!t.docChanged)return!0;try{return t.doc.check(),!0}catch(t){return this.storage.isDisabled=!0,this.editor.emit(`contentError`,{error:t,editor:this.editor,disableCollaboration:()=>{var t;(t=e.doc)==null||t.destroy()}}),!1}}})].filter(Boolean)}});function Vx(e){if(!e.length)return ge.empty;let t=[],n=e[0].$from.node(0);return e.forEach(e=>{let n=e.$from.pos,r=e.$from.nodeAfter;r&&t.push(Ke.node(n,n+r.nodeSize,{class:`ProseMirror-selectednoderange`}))}),ge.create(n,t)}function Hx(e,t,n){let r=n.isText||n.isAtom?0:1;return{start:e+r,end:e+t-r}}function Ux(e,t,n,r={}){let i=[],a=e.node(0),{extendOnBoundaryOverlap:o=!0}=r;typeof n==`number`&&n>=0||(n=e.sameParent(t)?Math.max(0,e.sharedDepth(t.pos)-1):e.sharedDepth(t.pos));let s=new B(e,t,n),c=s.depth===0?0:a.resolve(s.start).posAtIndex(0);return s.parent.forEach((n,r)=>{let l=c+r,u=l+n.nodeSize,d=Hx(l,n.nodeSize,n),f=o?t.pos>=d.start&&e.pos<=d.end:t.pos>d.start&&e.pos<d.end;if(l<s.start||l>=s.end||!f)return;let p=new oe(a.resolve(l),a.resolve(u));i.push(p)}),i}var Wx=class e{constructor(e,t){this.anchor=e,this.head=t}map(t){return new e(t.map(this.anchor),t.map(this.head))}resolve(e){return new Gx(e.resolve(this.anchor),e.resolve(this.head))}},Gx=class e extends Se{constructor(e,t,n,r=1){let{doc:i}=e,a=e===t,o=e.pos===i.content.size&&t.pos===i.content.size,s=a&&!o?i.resolve(t.pos+(r>0?1:-1)):t,c=a&&o?i.resolve(e.pos-(r>0?1:-1)):e,l=Ux(c.min(s),c.max(s),n),u=s.pos>=e.pos?l[0].$from:l[l.length-1].$to,d=s.pos>=e.pos?l[l.length-1].$to:l[0].$from;super(u,d,l),this.depth=n}get $to(){return this.ranges[this.ranges.length-1].$to}eq(t){return t instanceof e&&t.$from.pos===this.$from.pos&&t.$to.pos===this.$to.pos}map(t,n){return new e(t.resolve(n.map(this.anchor)),t.resolve(n.map(this.head)))}toJSON(){return{type:`nodeRange`,anchor:this.anchor,head:this.head}}get isForwards(){return this.head>=this.anchor}get isBackwards(){return!this.isForwards}extendBackwards(){let{doc:t}=this.$from;if(this.isForwards&&this.ranges.length>1){let t=this.ranges.slice(0,-1),n=t[0].$from,r=t[t.length-1].$to;return new e(n,r,this.depth)}let n=this.ranges[0],r=t.resolve(Math.max(0,n.$from.pos-1));return new e(this.$anchor,r,this.depth)}extendForwards(){let{doc:t}=this.$from;if(this.isBackwards&&this.ranges.length>1){let t=this.ranges.slice(1),n=t[0].$from,r=t[t.length-1].$to;return new e(r,n,this.depth)}let n=this.ranges[this.ranges.length-1],r=t.resolve(Math.min(t.content.size,n.$to.pos+1));return new e(this.$anchor,r,this.depth)}static fromJSON(t,n){return new e(t.resolve(n.anchor),t.resolve(n.head))}static create(e,t,n,r,i=1){return new this(e.resolve(t),e.resolve(n),r,i)}getBookmark(){return new Wx(this.anchor,this.head)}};Gx.prototype.visible=!1;function Kx(e){return e instanceof Gx}W.create({name:`nodeRange`,addOptions(){return{depth:void 0,key:`Mod`}},addKeyboardShortcuts(){return{"Shift-ArrowUp":({editor:e})=>{let{depth:t}=this.options,{view:n,state:r}=e,{doc:i,selection:a,tr:o}=r,{anchor:s,head:c}=a;if(!Kx(a)){let e=Gx.create(i,s,c,t,-1);return o.setSelection(e),n.dispatch(o),!0}let l=a.extendBackwards();return o.setSelection(l),n.dispatch(o),!0},"Shift-ArrowDown":({editor:e})=>{let{depth:t}=this.options,{view:n,state:r}=e,{doc:i,selection:a,tr:o}=r,{anchor:s,head:c}=a;if(!Kx(a)){let e=Gx.create(i,s,c,t);return o.setSelection(e),n.dispatch(o),!0}let l=a.extendForwards();return o.setSelection(l),n.dispatch(o),!0},"Mod-a":({editor:e})=>{let{depth:t}=this.options,{view:n,state:r}=e,{doc:i,tr:a}=r,o=Gx.create(i,0,i.content.size,t);return a.setSelection(o),n.dispatch(a),!0}}},onSelectionUpdate(){let{selection:e}=this.editor.state;Kx(e)&&this.editor.view.dom.classList.add(`ProseMirror-noderangeselection`)},addProseMirrorPlugins(){let e=!1,t=!1;return[new Fe({key:new Te(`nodeRange`),props:{attributes:()=>e?{class:`ProseMirror-noderangeselection`}:{class:``},handleDOMEvents:{mousedown:(e,n)=>{let{key:r}=this.options,i=/Mac/.test(navigator.platform),a=!!n.shiftKey,o=!!n.ctrlKey,s=!!n.altKey,c=!!n.metaKey;return(r==null||r===`Shift`&&a||r===`Control`&&o||r===`Alt`&&s||r===`Meta`&&c||r===`Mod`&&(i?c:o))&&(t=!0),t&&document.addEventListener(`mouseup`,()=>{t=!1;let{state:n}=e,{doc:r,selection:i,tr:a}=n,{$anchor:o,$head:s}=i;if(o.sameParent(s))return;let c=Gx.create(r,o.pos,s.pos,this.options.depth);a.setSelection(c),e.dispatch(a)},{once:!0}),!1}},decorations:n=>{let{selection:r}=n,i=Kx(r);if(e=!1,!t)return i?(e=!0,Vx(r.ranges)):null;let{$from:a,$to:o}=r;if(!i&&a.sameParent(o))return null;let s=Ux(a,o,this.options.depth);return s.length?(e=!0,Vx(s)):null}}})]}});function qx(e){let t=``,n=getComputedStyle(e);for(let e=0;e<n.length;e+=1)t+=`${n[e]}:${n.getPropertyValue(n[e])};`;return t}function Jx(e){let t=e.cloneNode(!0),n=[e,...Array.from(e.getElementsByTagName(`*`))],r=[t,...Array.from(t.getElementsByTagName(`*`))];return n.forEach((e,t)=>{r[t].style.cssText=qx(e)}),t}var Yx=[{id:`listItemFirstChild`,evaluate:({parent:e,isFirst:t})=>t&&e&&[`listItem`,`taskItem`].includes(e.type.name)?1e3:0},{id:`listWrapperDeprioritize`,evaluate:({node:e})=>{let t=[`listItem`,`taskItem`],n=e.firstChild;return n&&t.includes(n.type.name)?1e3:0}},{id:`tableStructure`,evaluate:({node:e,parent:t})=>[`tableRow`,`tableCell`,`tableHeader`].includes(e.type.name)||t&&t.type.name===`tableHeader`?1e3:0},{id:`inlineContent`,evaluate:({node:e})=>e.isInline||e.isText?1e3:0}],Xx={edges:[`left`,`top`],threshold:12,strength:500};function Zx(e){return e===void 0||e===`left`?{...Xx}:e===`right`?{edges:[`right`,`top`],threshold:12,strength:500}:e===`both`?{edges:[`left`,`right`,`top`],threshold:12,strength:500}:e===`none`?{edges:[],threshold:0,strength:0}:{...Xx,...e}}function Qx(e,t,n){if(n.edges.length===0)return!1;let r=t.getBoundingClientRect(),{threshold:i,edges:a}=n;return a.some(t=>t===`left`?e.x-r.left<i:t===`right`?r.right-e.x<i:t===`top`?e.y-r.top<i:t===`bottom`?r.bottom-e.y<i:!1)}function $x(e,t,n,r){return!t||n.edges.length===0?0:Qx(e,t,n)?n.strength*r:0}var eS=1e3;function tS(e,t,n,r){let i=eS,a=!1;if(t.every(t=>{let n=t.evaluate(e);return i-=n,i<=0?(a=!0,!1):!0}),a)return-1;let o=e.view.nodeDOM(e.pos);return i-=$x(r,o,n,e.depth),i<=0?-1:i}function nS(e,t,n){return Array.from({length:t},(e,n)=>t-1-n).some(t=>n.includes(e.node(t).type.name))}function rS(e,t,n){if(!Number.isFinite(t.x)||!Number.isFinite(t.y))return null;let r=e.posAtCoords({left:t.x,top:t.y});if(!r)return null;let{doc:i}=e.state,a=i.resolve(r.pos),o=[];n.defaultRules&&o.push(...Yx),o.push(...n.rules);let s=Array.from({length:a.depth},(e,t)=>a.depth-t).map(r=>{let i=a.node(r),s=a.before(r);if(n.allowedContainers&&r>0&&!nS(a,r,n.allowedContainers))return null;let c=r>0?a.node(r-1):null,l=r>0?a.index(r-1):0,u=c?c.childCount:1,d=tS({node:i,pos:s,depth:r,parent:c,index:l,isFirst:l===0,isLast:l===u-1,$pos:a,view:e},o,n.edgeDetection,t);return d<0?null:{node:i,pos:s,depth:r,score:d,dom:e.nodeDOM(s)}}).filter(e=>e!==null),c=a.nodeAfter;if(c&&c.isAtom&&!c.isInline){let i=r.pos,l=a.depth+1,u=a.parent,d=a.index(),f=u.childCount,p=!0;if(n.allowedContainers&&(p=nS(a,l,n.allowedContainers)),p){let r=tS({node:c,pos:i,depth:l,parent:u,index:d,isFirst:d===0,isLast:d===f-1,$pos:a,view:e},o,n.edgeDetection,t);if(r>=0){let t=e.nodeDOM(i);t&&s.push({node:c,pos:i,depth:l,score:r,dom:t})}}}if(s.length===0)return null;s.sort((e,t)=>t.score===e.score?t.depth-e.depth:t.score-e.score);let l=s[0];return l.dom?{node:l.node,pos:l.pos,dom:l.dom}:null}function iS(e,t){let n=e;for(;n?.parentElement&&n.parentElement!==t.dom;)n=n.parentElement;return n?.parentElement===t.dom?n:void 0}function aS(e){return Number.isFinite(e.top)&&Number.isFinite(e.bottom)&&Number.isFinite(e.left)&&Number.isFinite(e.right)&&e.width>0&&e.height>0}function oS(e,t,n,r=5){if(!Number.isFinite(t)||!Number.isFinite(n))return null;let i=e.dom,a=i.firstElementChild,o=i.lastElementChild;if(!a||!o)return null;let s=a.getBoundingClientRect(),c=o.getBoundingClientRect();if(!aS(s)||!aS(c))return null;let l=Math.min(Math.max(s.top+r,n),c.bottom-r),u=.5,d=Math.abs(s.left-c.left)<u,f=Math.abs(s.right-c.right)<u,p=s;d&&f&&(p=s);let m=Math.min(Math.max(p.left+r,t),p.right-r);return!Number.isFinite(m)||!Number.isFinite(l)?null:{x:m,y:l}}var sS=e=>{let{x:t,y:n,editor:r,nestedOptions:i}=e,{view:a,state:o}=r,s=oS(a,t,n,5);if(!s)return{resultElement:null,resultNode:null,pos:null};let{x:c,y:l}=s;if(i?.enabled){let e=rS(a,{x:c,y:l},i);return e?{resultElement:e.dom,resultNode:e.node,pos:e.pos}:{resultElement:null,resultNode:null,pos:null}}let u=a.root.elementsFromPoint(c,l),d;if(Array.prototype.some.call(u,e=>{if(!a.dom.contains(e))return!1;let t=iS(e,a);return t?(d=t,!0):!1}),!d){let e=a.posAtCoords({left:c,top:l});if(e){let t=o.doc.resolve(e.pos),n=Math.min(t.depth,1),r=n>0?t.before(n):t.pos,i=o.doc.nodeAt(r);if(i){let e=a.nodeDOM(r);return{resultElement:e instanceof HTMLElement?e:null,resultNode:i,pos:r}}}return{resultElement:null,resultNode:null,pos:null}}let f;try{f=a.posAtDOM(d,0)}catch{return{resultElement:null,resultNode:null,pos:null}}let p=o.doc.nodeAt(f);if(!p){let e=o.doc.resolve(f),t=e.parent;return{resultElement:d,resultNode:t,pos:e.start()}}return{resultElement:d,resultNode:p,pos:f}};function cS(e,t){let n=null,r=e.nodeDOM(t);if(r instanceof Element)n=r;else{let{node:r,offset:i}=e.domAtPos(t),a=r.childNodes[i];a instanceof Element?n=a:r instanceof Element?n=r:r.nodeType===Node.TEXT_NODE&&r.parentElement&&(n=r.parentElement)}return(n?getComputedStyle(n).direction:getComputedStyle(e.dom).direction)||`ltr`}function lS(e){var t;(t=e.parentNode)==null||t.removeChild(e)}function uS(e,t,n,r){let{doc:i}=t.view.state;if(n?.enabled&&r?.node&&r.pos>=0){let e=r.pos,t=r.pos+r.node.nodeSize;return[{$from:i.resolve(e),$to:i.resolve(t)}]}let a=sS({editor:t,x:e.clientX,y:e.clientY,direction:`right`,nestedOptions:n});if(!a.resultNode||a.pos===null)return[];let o=a.resultNode.isText||a.resultNode.isAtom?0:-1;return Ux(i.resolve(a.pos),i.resolve(a.pos+a.resultNode.nodeSize+o),0,{extendOnBoundaryOverlap:!1})}function dS(e,t,n,r){let{view:i}=t;if(!e.dataTransfer)return;let{empty:a,$from:o,$to:s}=i.state.selection,c=uS(e,t,n,r),l=Ux(o,s,0,{extendOnBoundaryOverlap:!1}),u=l.some(e=>c.find(t=>t.$from===e.$from&&t.$to===e.$to)),d=a||!u?c:l;if(!d.length)return;let{tr:f}=i.state,p=document.createElement(`div`),m=d[0].$from.pos,h=d[d.length-1].$to.pos;p.setAttribute(`dir`,cS(i,m));let g=n?.enabled&&r?.node,_,v;g?(_=i.state.doc.slice(m,h),v=Le.create(i.state.doc,m)):(v=Gx.create(i.state.doc,m,h),_=v.content()),d.forEach(e=>{let t=Jx(i.nodeDOM(e.$from.pos));p.append(t)}),p.style.position=`absolute`,p.style.top=`-10000px`,document.body.append(p),e.dataTransfer.clearData();let y=p.getBoundingClientRect(),b=e.clientX-y.left;e.dataTransfer.setDragImage(p,Math.max(0,Math.min(b,y.width)),0);let x=!1,S=()=>{x||(x=!0,lS(p),document.removeEventListener(`drop`,S),document.removeEventListener(`dragend`,S))},C=v instanceof Le?v:void 0;i.dragging={slice:_,move:!0,node:C},f.setSelection(v),i.dispatch(f),document.addEventListener(`drop`,S),document.addEventListener(`dragend`,S)}var fS=(e,t)=>{let n=e.resolve(t),{depth:r}=n;return r===0?t:n.pos-n.parentOffset-1},pS=(e,t)=>{let n=e.nodeAt(t),r=e.resolve(t),{depth:i}=r,a=n;for(;i>0;){let e=r.node(i);--i,i===0&&(a=e)}return a},mS=(e,t)=>{let n=Im.getState(e);return n?xh(t,n.type,n.binding.mapping):null},hS=(e,t)=>{let n=Im.getState(e);return n?Ch(n.doc,n.type,t,n.binding.mapping)||0:-1},gS=(e,t)=>{let n=t;for(;n?.parentNode&&n.parentNode!==e.dom;)n=n.parentNode;return n},_S=new Te(`dragHandle`),vS=({pluginKey:e=_S,element:t,editor:n,computePositionConfig:r,getReferencedVirtualElement:i,onNodeChange:a,onElementDragStart:o,onElementDragEnd:s,nestedOptions:c})=>{let l=document.createElement(`div`),u=!1,d=null,f=-1,p,m=null,h=null;function g(){t&&(t.style.visibility=`hidden`,t.style.pointerEvents=`none`)}function _(){if(t){if(!n.isEditable){g();return}t.style.visibility=``,t.style.pointerEvents=`auto`}}function v(e){b(i?.()||{getBoundingClientRect:()=>e.getBoundingClientRect()},t,r).then(e=>{Object.assign(t.style,{position:e.strategy,left:`${e.x}px`,top:`${e.y}px`})})}function y(e){o?.(e),dS(e,n,c,{node:d,pos:f}),t&&(t.dataset.dragging=`true`),setTimeout(()=>{t&&(t.style.pointerEvents=`none`)},0)}function x(e){s?.(e),g(),t&&(t.style.pointerEvents=`auto`,t.dataset.dragging=`false`)}function S(){if(ce()){let e=n.view.dom;requestAnimationFrame(()=>{e.isContentEditable&&(e.contentEditable=`false`,e.contentEditable=`true`)})}}return l.appendChild(t),{unbind(){t.removeEventListener(`dragstart`,y),t.removeEventListener(`dragend`,x),document.removeEventListener(`drop`,S),m&&(cancelAnimationFrame(m),m=null,h=null)},plugin:new Fe({key:typeof e==`string`?new Te(e):e,state:{init(){return{locked:!1}},apply(e,r,i,o){let s=e.getMeta(`lockDragHandle`),c=e.getMeta(`hideDragHandle`);if(s!==void 0&&(u=s),c)return g(),u=!1,d=null,f=-1,a?.({editor:n,node:null,pos:-1}),r;if(e.docChanged&&f!==-1&&t)if(Px(e)){let e=hS(o,p);e!==f&&(f=e)}else{let t=e.mapping.map(f);t!==f&&(f=t,p=mS(o,f))}return r}},view:e=>{var r;return t.draggable=!0,t.style.pointerEvents=`auto`,t.dataset.dragging=`false`,(r=n.view.dom.parentElement)==null||r.appendChild(l),l.style.pointerEvents=`none`,l.style.position=`absolute`,l.style.top=`0`,l.style.left=`0`,t.addEventListener(`dragstart`,y),t.addEventListener(`dragend`,x),document.addEventListener(`drop`,S),{update(r,i){if(!t)return;if(!n.isEditable){g();return}if(u?t.draggable=!1:t.draggable=!0,e.state.doc.eq(i.doc)||f===-1)return;let o=e.nodeDOM(f);if(o=gS(e,o),o===e.dom||o?.nodeType!==1)return;let s=e.posAtDOM(o,0),c=pS(n.state.doc,s),l=fS(n.state.doc,s);d=c,f=l,p=mS(e.state,f),a?.({editor:n,node:d,pos:f}),v(o)},destroy(){t.removeEventListener(`dragstart`,y),t.removeEventListener(`dragend`,x),document.removeEventListener(`drop`,S),m&&(cancelAnimationFrame(m),m=null,h=null),t&&lS(l)}}},props:{handleDOMEvents:{keydown(e){return!t||u?!1:e.hasFocus()?(g(),d=null,f=-1,a?.({editor:n,node:null,pos:-1}),!1):!1},mouseleave(e,t){return u||t.target&&!l.contains(t.relatedTarget)&&(g(),d=null,f=-1,a?.({editor:n,node:null,pos:-1})),!1},mousemove(e,r){return!t||u||(h={x:r.clientX,y:r.clientY},m)||(m=requestAnimationFrame(()=>{if(m=null,!h)return;let{x:t,y:r}=h;h=null;let i=sS({x:t,y:r,direction:`right`,editor:n,nestedOptions:c});if(!i.resultElement)return;let o=i.resultElement,s=i.resultNode,l=i.pos;if(!c?.enabled){if(o=gS(e,o),o===e.dom||o?.nodeType!==1)return;let t=e.posAtDOM(o,0);s=pS(n.state.doc,t),l=fS(n.state.doc,t)}s!==d&&(d=s,f=l??-1,p=mS(e.state,f),a?.({editor:n,node:d,pos:f}),v(o),_())})),!1}}}})}};function yS(e){return e===!1||e===void 0?{enabled:!1,rules:[],defaultRules:!0,allowedContainers:void 0,edgeDetection:Zx(`none`)}:e===!0?{enabled:!0,rules:[],defaultRules:!0,allowedContainers:void 0,edgeDetection:Zx(`left`)}:{enabled:!0,rules:e.rules??[],defaultRules:e.defaultRules??!0,allowedContainers:e.allowedContainers,edgeDetection:Zx(e.edgeDetection)}}var bS={placement:`left-start`,strategy:`absolute`};W.create({name:`dragHandle`,addOptions(){return{render(){let e=document.createElement(`div`);return e.classList.add(`drag-handle`),e},computePositionConfig:{},locked:!1,onNodeChange:()=>null,onElementDragStart:void 0,onElementDragEnd:void 0,nested:!1}},addCommands(){return{lockDragHandle:()=>({editor:e})=>(this.options.locked=!0,e.commands.setMeta(`lockDragHandle`,this.options.locked)),unlockDragHandle:()=>({editor:e})=>(this.options.locked=!1,e.commands.setMeta(`lockDragHandle`,this.options.locked)),toggleDragHandle:()=>({editor:e})=>(this.options.locked=!this.options.locked,e.commands.setMeta(`lockDragHandle`,this.options.locked))}},addProseMirrorPlugins(){let e=this.options.render(),t=yS(this.options.nested);return[vS({computePositionConfig:{...bS,...this.options.computePositionConfig},getReferencedVirtualElement:this.options.getReferencedVirtualElement,element:e,editor:this.editor,onNodeChange:this.options.onNodeChange,onElementDragStart:this.options.onElementDragStart,onElementDragEnd:this.options.onElementDragEnd,nestedOptions:t}).plugin]}});var xS=20,SS=44,CS=28;function wS(){let e=document.createElement(`div`);e.className=`ok-block-controls`,e.style.visibility=`hidden`;let t=document.createElement(`button`);t.className=`ok-add-block-btn`,t.setAttribute(`aria-label`,`Add block below`),t.setAttribute(`type`,`button`),t.innerHTML=`<svg aria-hidden="true" xmlns="http://www.w3.org/2000/svg" width="16" height="16" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" class="lucide lucide-plus"><path d="M5 12h14"/><path d="M12 5v14"/></svg>`,t.addEventListener(`mousedown`,e=>{e.preventDefault(),e.stopPropagation()});let n=document.createElement(`div`);return n.className=`ok-drag-grip`,n.setAttribute(`aria-hidden`,`true`),n.innerHTML=`<svg xmlns="http://www.w3.org/2000/svg" width="16" height="16" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" class="lucide lucide-grip-vertical-icon lucide-grip-vertical"><circle cx="9" cy="12" r="1"/><circle cx="9" cy="5" r="1"/><circle cx="9" cy="19" r="1"/><circle cx="15" cy="12" r="1"/><circle cx="15" cy="5" r="1"/><circle cx="15" cy="19" r="1"/></svg>`,e.appendChild(t),e.appendChild(n),{container:e,addBtn:t}}function TS(e,t,n){let{state:r,view:i}=e;if(n.type.name===`jsxComponent`){let i=n.attrs.componentName??``;if(i){let a=Yb(i);if(a.emptyChildName){let i=t+1+n.content.size;if(i>r.doc.content.size)return;let o=a.emptyChildName;e.chain().focus().insertContentAt(i,rx(o)).run(),sx(e,i,Yb(o));return}}}let a=t+n.nodeSize;if(a>r.doc.content.size)return;let{tr:o}=r,s=r.schema.nodes.paragraph?.create();if(!s)return;o.insert(a,s);let c=Je.near(o.doc.resolve(a+1));o.setSelection(c).scrollIntoView(),i.dispatch(o),i.focus(),e.commands.insertContent(`/`)}var ES=W.create({name:`blockDragHandle`,addProseMirrorPlugins(){let e=this.editor,t=null,n=-1,{container:r,addBtn:i}=wS();return i.addEventListener(`click`,()=>{t&&n>=0&&TS(e,n,t)}),[vS({element:r,editor:e,onNodeChange({node:e,pos:r}){t=e,n=r??-1},computePositionConfig:{placement:`left-start`,strategy:`absolute`,middleware:[nt(({rects:e})=>({mainAxis:10,crossAxis:((e.reference.height<=SS?e.reference.height:CS)-xS)/2}))]},nestedOptions:yS(!1)}).plugin]}}),DS=W.create({name:`headingAnchors`,addProseMirrorPlugins(){return[new Fe({props:{decorations(e){let t=[],n=new Map;return e.doc.descendants((e,r)=>{if(e.type.name===`heading`){let i=xe(e.textContent,n);if(!i)return;t.push(Ke.node(r,r+e.nodeSize,{id:i}))}}),ge.create(e.doc,t)}}})]}}),OS=new class{byExt=new Map;register(e){for(let t of e.exts)this.byExt.set(t.toLowerCase(),e)}lookup(e){let t=this.byExt.get(e.toLowerCase());return t?{found:!0,viewer:t}:{found:!1}}clearForTests(){this.byExt.clear()}get size(){return this.byExt.size}};function kS(e){globalThis.window?.open(e,`_blank`,`noopener,noreferrer`)}async function AS(e,t={}){let n=t.registry??OS,r=`desktopBridge`in t?t.desktopBridge:globalThis.window?.okDesktop,i=t.openUrl??kS;if(!e.forceOsDelegation){let t=n.lookup(e.ext);if(t.found){t.viewer.render(e);return}}if(r){let t=await r.shell.openAsset(e.projectRelPath);t.ok||console.warn(`[asset-dispatch] openAsset refused:`,t.reason,{projectRelPath:e.projectRelPath,ext:e.ext});return}i(e.url)}var jS=new Set([`http:`,`https:`,`mailto:`,`tel:`]);function MS(e){try{let t=new URL(e);return jS.has(t.protocol)}catch{return!1}}function NS(e=window.location.hash){let t=e.match(/^#\/([^?#]+)/);return t?decodeURIComponent(t[1]):``}function PS(e,t=window.location.hash){return c(e,NS(t))}function FS({docName:e,anchor:t}){return t?`#/${e}?anchor=${encodeURIComponent(t)}`:`#/${e}`}function IS(e){e.startsWith(`#`)||MS(e)?window.open(e,`_blank`,`noopener,noreferrer`):console.warn(`[safe-nav] blocked non-safe scheme:`,e)}function LS(e){window.location.assign(FS(e))}function RS(e){IS(FS(e))}function zS(e){return e.metaKey||e.ctrlKey}function BS(e,t=window.location.hash){let n=NS(t);if(!n)return;let r=document.getElementById(e);r&&r.scrollIntoView({behavior:`smooth`,block:`start`}),window.location.assign(Ge(n,e))}function VS(e,t=window.location.hash){if(e.kind===`doc`){LS(e);return}if(e.kind===`anchor`){BS(e.anchor,t);return}IS(e.url)}function HS(e,t,n=window.location.hash){return ie(NS(n),e,t)}function US(e,t){let n=e;for(;n&&typeof n.hasAttribute==`function`;){if(n.hasAttribute(`data-wiki-embed`)){let e=n.getAttribute(`data-target`)??``;if(!e)return null;let r=E(e,t);return r?{kind:n.tagName===`IMG`?`image`:`asset`,relPath:r,title:r.split(`/`).pop()??e}:null}if(n.hasAttribute(`data-wiki-link`)){let e=n.getAttribute(`data-target`)??``;return e?{kind:`wiki-link`,relPath:`${e}.md`,title:e}:null}if(n.tagName===`A`&&n.hasAttribute(`href`)){let e=c(n.getAttribute(`href`)??``,t);if(e?.kind===`asset`){let n=E(e.url,t);return n?{kind:`asset`,relPath:n,title:n.split(`/`).pop()??e.url}:null}}if(n.tagName===`IMG`){let e=n.getAttribute(`src`)??``;if(e){let n=c(e,t);if(n?.kind===`asset`){let e=E(n.url,t);return e?{kind:`image`,relPath:e,title:e.split(`/`).pop()??n.url}:null}}}n=n.parentElement}return null}var WS=new Te(`asset-context-menu`);function GS(e){return new Fe({key:WS,view(t){let n=e.showAssetMenu??(e=>{let t=globalThis.window?.okDesktop;return t?t.shell.showAssetMenu({relPath:e.relPath,title:e.title,kind:e.kind}):Promise.resolve()}),r=t=>{if(!(t.target instanceof Element))return;let r=US(t.target,e.sourceDocName);r&&(t.preventDefault(),n(r))};return t.dom.addEventListener(`contextmenu`,r),{destroy(){t.dom.removeEventListener(`contextmenu`,r)}}}})}var KS=e=>{let t=(0,J.c)(17),{kind:n,ariaLabel:r,onDeactivate:i,children:a,triggerReference:o,layout:s,className:c,"data-slot":l}=e,u=s===void 0?`standard`:s,d=(0,K.useRef)(null),p,m;t[0]===o?(p=t[1],m=t[2]):(p=()=>{let e=d.current;if(e)return F(o,e,()=>{b(o,e,{placement:`bottom-start`,strategy:`fixed`,middleware:[nt(8),T(),f({padding:8})]}).then(t=>{let{x:n,y:r}=t;e.isConnected&&(e.style.left=`${n}px`,e.style.top=`${r}px`)}).catch(qS)})},m=[o],t[0]=o,t[1]=p,t[2]=m),(0,K.useLayoutEffect)(p,m);let h;t[3]===Symbol.for(`react.memo_cache_sentinel`)?(h={position:`fixed`,left:`-9999px`,top:`-9999px`},t[3]=h):h=t[3];let g=u===`wide`?`w-[min(720px,calc(100%-1rem))]`:`w-80`,_;t[4]!==c||t[5]!==g?(_=ht(`ok-interaction-prop-panel pointer-events-auto z-40 rounded-md border border-border bg-popover p-3 shadow-lg`,g,c),t[4]=c,t[5]=g,t[6]=_):_=t[6];let v;t[7]===Symbol.for(`react.memo_cache_sentinel`)?(v=(0,q.jsx)(bt,{className:`size-3.5`,"aria-hidden":`true`}),t[7]=v):v=t[7];let y;t[8]===i?y=t[9]:(y=(0,q.jsx)(_t,{type:`button`,variant:`ghost`,size:`icon`,"aria-label":`Close`,onClick:i,className:`absolute right-1 top-1 size-7`,children:v}),t[8]=i,t[9]=y);let x;return t[10]!==r||t[11]!==a||t[12]!==l||t[13]!==n||t[14]!==_||t[15]!==y?(x=(0,q.jsxs)(`div`,{ref:d,role:`dialog`,"aria-label":r,"data-ok-prop-panel":n,"data-slot":l,style:h,className:_,children:[a,y]}),t[10]=r,t[11]=a,t[12]=l,t[13]=n,t[14]=_,t[15]=y,t[16]=x):x=t[16],x};function qS(){}function JS(e,t){let n=[e,...t.fallbackTargets??[]],r=new Set,i=null;for(let e of n){if(r.has(e))continue;r.add(e);let n=ye(e,{pages:t.pages,folderPaths:t.folderPaths,pagesBySlug:t.pagesBySlug});if(n.kind===`missing`){i??=n;continue}return{kind:`navigate`,displayState:n.kind===`folder`?`folder`:`resolved`,resolvedTarget:n,hashDocName:n.target}}let a=i??ye(e,{pages:t.pages,folderPaths:t.folderPaths,pagesBySlug:t.pagesBySlug});if(a.kind!==`missing`)return{kind:`navigate`,displayState:a.kind===`folder`?`folder`:`resolved`,resolvedTarget:a,hashDocName:a.target};let o=t.createDialogSeed??Pe(a.target);return{kind:`create`,displayState:`missing`,resolvedTarget:a,initialDir:o.initialDir,suggestedName:o.suggestedName}}function YS(e){if(e.kind!==`navigate`||e.displayState!==`folder`)return null;let t=e.resolvedTarget;return`folderPath`in t?{initialDir:t.folderPath,suggestedName:`index.md`}:null}function XS(e){let t=(0,J.c)(12),n,r,i,a;t[0]===e?(n=t[1],r=t[2],i=t[3],a=t[4]):({className:n,type:a,ref:i,...r}=e,t[0]=e,t[1]=n,t[2]=r,t[3]=i,t[4]=a);let o;t[5]===n?o=t[6]:(o=ht(`h-8 w-full min-w-0 rounded-lg border border-input bg-transparent px-2.5 py-1 text-base transition-colors outline-none file:inline-flex file:h-6 file:border-0 file:bg-transparent file:text-sm file:font-medium file:text-foreground placeholder:text-muted-foreground focus-visible:border-ring focus-visible:ring-3 focus-visible:ring-ring/50 disabled:pointer-events-none disabled:cursor-not-allowed disabled:bg-input/50 disabled:opacity-50 aria-invalid:border-destructive aria-invalid:ring-3 aria-invalid:ring-destructive/20 md:text-sm dark:bg-input/30 dark:disabled:bg-input/80 dark:aria-invalid:border-destructive/50 dark:aria-invalid:ring-destructive/40`,n),t[5]=n,t[6]=o);let s;return t[7]!==r||t[8]!==i||t[9]!==o||t[10]!==a?(s=(0,q.jsx)(`input`,{type:a,ref:i,"data-slot":`input`,className:o,...r}),t[7]=r,t[8]=i,t[9]=o,t[10]=a,t[11]=s):s=t[11],s}var ZS=[`.md`,`.mdx`];function QS(e){let t=e.toLowerCase();for(let e of ZS)if(t.endsWith(e))return e;return null}function $S(e){let t=QS(e);return t?e.slice(0,-t.length):e}function eC(e){return e.trim()?e.includes(`..`)?`Path cannot contain ".."`:e.startsWith(`/`)?`Path cannot start with "/"`:e.includes(`\\`)?`Path cannot contain backslashes`:e.includes(`\0`)?`Path cannot contain null bytes`:null:`Name cannot be empty`}function tC(e){let t=e.fileName.trim(),n=QS(t)?t:`${t}${e.fileExtension??`.md`}`;if(e.kind===`folder`){let t=(e.folderName??``).trim();return`${e.initialDir?`${e.initialDir}/${t}`:t}/${n}`}return e.initialDir?`${e.initialDir}/${n}`:n}function nC(e){let t=e.target;return t?.tagName===`INPUT`||t?.tagName===`TEXTAREA`||t?.isContentEditable?!1:!!((e.metaKey||e.ctrlKey)&&e.altKey&&e.key.toLowerCase()===`n`)}function rC(e){let t=e.value.lastIndexOf(`.`);t>0?e.setSelectionRange(0,t):e.select()}function iC(e){let t=(0,J.c)(96),{open:n,onOpenChange:r,kind:i,initialDir:a,suggestedName:o,description:s,onCreated:c}=e,{addPage:l}=De(),[u,d]=(0,K.useState)(``),[f,p]=(0,K.useState)(``),[m,h]=(0,K.useState)(`.md`),[g,_]=(0,K.useState)(null),[v,y]=(0,K.useState)(!1),[b,x]=(0,K.useState)(null),S=(0,K.useId)(),C=(0,K.useId)(),w=(0,K.useId)(),T=(0,K.useRef)(null),E=(0,K.useRef)(null),D,O;t[0]!==i||t[1]!==n||t[2]!==o?(D=()=>{if(n){_(null),x(null),y(!1),p(``);let e=i===`file`?o??`untitled`:`index`,t=QS(e);h(t??`.md`),d(t?$S(e):e)}},O=[n,i,o],t[0]=i,t[1]=n,t[2]=o,t[3]=D,t[4]=O):(D=t[3],O=t[4]),(0,K.useEffect)(D,O);let k;t[5]===Symbol.for(`react.memo_cache_sentinel`)?(k=function(e){let t=QS(e);t?(h(t),d($S(e))):d(e),_(null)},t[5]=k):k=t[5];let A=k,j;t[6]!==m||t[7]!==u||t[8]!==f||t[9]!==a||t[10]!==i?(j=function(){return tC({kind:i,initialDir:a,fileName:u,fileExtension:m,folderName:f})},t[6]=m,t[7]=u,t[8]=f,t[9]=a,t[10]=i,t[11]=j):j=t[11];let M=j,N;t[12]!==u||t[13]!==f||t[14]!==i?(N=function(){if(i===`folder`){let e=eC(f.trim());if(e)return{message:`Folder name: ${e}`,field:`folder`}}let e=eC(u.trim());return e?{message:e,field:`file`}:null},t[12]=u,t[13]=f,t[14]=i,t[15]=N):N=t[15];let P=N,F;t[16]!==v||t[17]!==u||t[18]!==f||t[19]!==i?(F=v||!u.trim()||i===`folder`&&!f.trim(),t[16]=v,t[17]=u,t[18]=f,t[19]=i,t[20]=F):F=t[20];let I=F,L;t[21]!==l||t[22]!==M||t[23]!==P||t[24]!==i||t[25]!==c||t[26]!==r?(L=async function(){let e=P();if(e){_(e.message),x(e.field);return}y(!0),_(null),x(null);let t=M();try{let e=await fetch(`/api/create-page`,{method:`POST`,headers:{"Content-Type":`application/json`},body:JSON.stringify({path:t})});if(!e.ok){let t=`Server error (HTTP ${e.status})`;try{let n=await e.json();n?.error&&(t=n.error)}catch{}y(!1),_(t),x(`form`);return}let n=await e.json();if(y(!1),!n.ok){_(n.error??`Failed to create ${i}`),x(`form`);return}let a=n.docName??t.replace(/\.(mdx|md)$/,``);r(!1),window.location.hash=`#/${a}`,l(a),se([`files`,`backlinks`,`graph`]),c?.(a)}catch(e){console.warn(`[NewItemDialog] create failed:`,e),y(!1),_(`Network error — please try again`),x(`form`)}},t[21]=l,t[22]=M,t[23]=P,t[24]=i,t[25]=c,t[26]=r,t[27]=L):L=t[27];let R=L,z=a||`(root)`,B=i===`file`?`New file`:`New folder`,V;t[28]===B?V=t[29]:(V=(0,q.jsx)(Ct,{children:B}),t[28]=B,t[29]=V);let H;t[30]!==s||t[31]!==z?(H=s??(0,q.jsxs)(q.Fragment,{children:[`Create in `,(0,q.jsx)(`span`,{className:`font-medium text-foreground`,children:z})]}),t[30]=s,t[31]=z,t[32]=H):H=t[32];let U;t[33]===H?U=t[34]:(U=(0,q.jsx)(St,{children:H}),t[33]=H,t[34]=U);let ee;t[35]!==U||t[36]!==V?(ee=(0,q.jsxs)(Nt,{children:[V,U]}),t[35]=U,t[36]=V,t[37]=ee):ee=t[37];let te;t[38]!==g||t[39]!==b||t[40]!==S||t[41]!==C||t[42]!==f||t[43]!==i?(te=i===`folder`&&(0,q.jsxs)(`div`,{children:[(0,q.jsx)(`label`,{className:`mb-1.5 block text-sm font-medium`,htmlFor:C,children:`Folder name`}),(0,q.jsx)(XS,{ref:E,id:C,value:f,onChange:e=>{p(e.target.value),_(null)},placeholder:`folder-name`,autoFocus:!0,"aria-describedby":g&&(b===`folder`||b===`form`)?S:void 0,"aria-invalid":g&&(b===`folder`||b===`form`)?!0:void 0,onKeyDown:e=>{if(e.key===`Enter`){e.preventDefault();let t=eC(f.trim());if(t){_(`Folder name: ${t}`),x(`folder`);return}T.current?.focus()}}})]}),t[38]=g,t[39]=b,t[40]=S,t[41]=C,t[42]=f,t[43]=i,t[44]=te):te=t[44];let ne=i===`folder`?`First file name`:`File name`,re;t[45]!==w||t[46]!==ne?(re=(0,q.jsx)(`label`,{className:`mb-1.5 block text-sm font-medium`,htmlFor:w,children:ne}),t[45]=w,t[46]=ne,t[47]=re):re=t[47];let W;t[48]===Symbol.for(`react.memo_cache_sentinel`)?(W=e=>A(e.target.value),t[48]=W):W=t[48];let ie=i===`file`,ae=g&&(b===`file`||b===`form`)?S:void 0,oe=g&&(b===`file`||b===`form`)?!0:void 0,ce;t[49]!==R||t[50]!==I?(ce=e=>{e.key===`Enter`&&!I&&R()},t[49]=R,t[50]=I,t[51]=ce):ce=t[51];let le;t[52]!==w||t[53]!==u||t[54]!==ie||t[55]!==ae||t[56]!==oe||t[57]!==ce?(le=(0,q.jsx)(XS,{ref:T,id:w,value:u,onChange:W,placeholder:`my-note`,autoFocus:ie,"aria-describedby":ae,"aria-invalid":oe,onFocus:oC,onKeyDown:ce,className:`flex-1`}),t[52]=w,t[53]=u,t[54]=ie,t[55]=ae,t[56]=oe,t[57]=ce,t[58]=le):le=t[58];let ue;t[59]===Symbol.for(`react.memo_cache_sentinel`)?(ue=e=>{(e===`.md`||e===`.mdx`)&&h(e)},t[59]=ue):ue=t[59];let de;t[60]===Symbol.for(`react.memo_cache_sentinel`)?(de=ZS.map(aC),t[60]=de):de=t[60];let fe;t[61]===m?fe=t[62]:(fe=(0,q.jsx)(Ue,{type:`single`,value:m,onValueChange:ue,variant:`outline`,size:`sm`,"aria-label":`File extension`,className:`shrink-0`,children:de}),t[61]=m,t[62]=fe);let pe;t[63]!==le||t[64]!==fe?(pe=(0,q.jsxs)(`div`,{className:`flex items-stretch gap-2`,children:[le,fe]}),t[63]=le,t[64]=fe,t[65]=pe):pe=t[65];let me;t[66]!==g||t[67]!==S?(me=g&&(0,q.jsx)(`p`,{id:S,role:`alert`,className:`text-xs text-red-600 dark:text-red-400`,children:g}),t[66]=g,t[67]=S,t[68]=me):me=t[68];let he;t[69]!==re||t[70]!==pe||t[71]!==me?(he=(0,q.jsxs)(`div`,{children:[re,pe,me]}),t[69]=re,t[70]=pe,t[71]=me,t[72]=he):he=t[72];let ge;t[73]!==te||t[74]!==he?(ge=(0,q.jsx)(At,{children:(0,q.jsxs)(`div`,{className:`space-y-3`,children:[te,he]})}),t[73]=te,t[74]=he,t[75]=ge):ge=t[75];let _e;t[76]===r?_e=t[77]:(_e=()=>r(!1),t[76]=r,t[77]=_e);let ve;t[78]!==v||t[79]!==_e?(ve=(0,q.jsx)(_t,{variant:`outline`,className:`font-mono uppercase`,onClick:_e,disabled:v,children:`Cancel`}),t[78]=v,t[79]=_e,t[80]=ve):ve=t[80];let ye=v?`Creating...`:`Create`,be;t[81]!==R||t[82]!==I||t[83]!==ye?(be=(0,q.jsx)(_t,{onClick:R,disabled:I,children:ye}),t[81]=R,t[82]=I,t[83]=ye,t[84]=be):be=t[84];let xe;t[85]!==ve||t[86]!==be?(xe=(0,q.jsxs)(jt,{children:[ve,be]}),t[85]=ve,t[86]=be,t[87]=xe):xe=t[87];let Se;t[88]!==ee||t[89]!==ge||t[90]!==xe?(Se=(0,q.jsxs)(Ot,{className:`sm:max-w-md`,"data-ok-layer-spawned":``,children:[ee,ge,xe]}),t[88]=ee,t[89]=ge,t[90]=xe,t[91]=Se):Se=t[91];let Ce;return t[92]!==r||t[93]!==n||t[94]!==Se?(Ce=(0,q.jsx)(Pt,{open:n,onOpenChange:r,children:Se}),t[92]=r,t[93]=n,t[94]=Se,t[95]=Ce):Ce=t[95],Ce}function aC(e){return(0,q.jsx)(Ie,{value:e,"aria-label":`Use ${e} extension`,children:e},e)}function oC(e){return rC(e.currentTarget)}var sC=class{registry=new Map;_activeNodeId=null;listeners=new Set;_snapshot={activeNodeId:null,active:null};register(e){this.registry.set(e.nodeId,e),this._activeNodeId===e.nodeId&&this.refreshSnapshot()}deregister(e){this.registry.delete(e)&&this._activeNodeId===e&&(this._activeNodeId=null,this.refreshSnapshot())}setActiveNode(e){this._activeNodeId!==e&&(e!==null&&!this.registry.has(e)||(this._activeNodeId=e,this.refreshSnapshot()))}getActiveNode(){return this._activeNodeId}getRegistration(e){return this.registry.get(e)}hasRegistration(e){return this.registry.has(e)}clear(){this.registry.clear(),this._activeNodeId=null,this.refreshSnapshot()}getSnapshot=()=>this._snapshot;subscribe=e=>(this.listeners.add(e),()=>{this.listeners.delete(e)});refreshSnapshot(){let e=this._activeNodeId==null?null:this.registry.get(this._activeNodeId)??null;this._snapshot={activeNodeId:this._activeNodeId,active:e};for(let e of this.listeners)e()}};function cC(e,t){let n=e??null;for(;n&&typeof n==`object`;){let e=n.getAttribute;if(typeof e==`function`){let r=e.call(n,`data-mark-id`);if(r&&t.hasRegistration(r))return r;let i=e.call(n,`data-node-id`);if(i&&t.hasRegistration(i))return i}n=n.parentElement??null}return null}var lC=e=>{let t=(0,J.c)(18),{store:n}=e,r;t[0]===n?r=t[1]:(r=()=>n.getSnapshot(),t[0]=n,t[1]=r);let[i,a]=(0,K.useState)(r),o,s;t[2]===n?(o=t[3],s=t[4]):(o=()=>(a(n.getSnapshot()),n.subscribe(()=>{a(n.getSnapshot())})),s=[n],t[2]=n,t[3]=o,t[4]=s),(0,K.useEffect)(o,s);let{active:c}=i;if(!c)return null;let l;t[5]===n?l=t[6]:(l=()=>n.setActiveNode(null),t[5]=n,t[6]=l);let u,d,f;if(t[7]!==c.controls||t[8]!==c.nodeId||t[9]!==c.type||t[10]!==l){let e={nodeId:c.nodeId,type:c.type,deactivate:l};u=c.controls.propPanel?.(e),d=c.controls.toolbar?.(e),f=c.controls.breadcrumb?.(e),t[7]=c.controls,t[8]=c.nodeId,t[9]=c.type,t[10]=l,t[11]=u,t[12]=d,t[13]=f}else u=t[11],d=t[12],f=t[13];let p;return t[14]!==u||t[15]!==d||t[16]!==f?(p=(0,q.jsxs)(q.Fragment,{children:[u,d,f]}),t[14]=u,t[15]=d,t[16]=f,t[17]=p):p=t[17],p};function uC(e){return e.editorView?.dom??e.view?.dom??null}function dC(e,t){let n=e;for(;n;){if(n.getAttribute?.(`data-mark-id`)===t||n.getAttribute?.(`data-node-id`)===t)return!0;n=n.parentElement}return!1}function fC(e){let{editor:t}=e,n=new sC,r=uC(t),i=!1,a=null,o=n.subscribe(()=>{let e=n.getActiveNode();if(e!==null){if(typeof document<`u`){let t=document.activeElement;a=t&&dC(t,e)?t:null}return}if(typeof document>`u`)return;let i=a;if(a=null,i&&document.contains(i)&&typeof i.focus==`function`){try{i.focus({preventScroll:!0})}catch{}return}let o=r??uC(t);if(o&&typeof o.focus==`function`)try{o.focus({preventScroll:!0})}catch{}}),s=e=>{let t=e;if(t.button===2)return;if(t.metaKey||t.ctrlKey||t.button===1){t.button===1&&t.preventDefault?.();return}let r=cC(e.target,n);if(r===null)return;let i=n.getRegistration(r);i?.handlePrimary&&i.handlePrimary({nodeId:r,type:i.type,newTab:!1})||n.setActiveNode(r)},c=e=>{let t=e;if(t.button===2||t.type===`click`&&t.button===1||!(t.metaKey||t.ctrlKey||t.button===1))return;let r=cC(e.target,n);if(r===null)return;let i=n.getRegistration(r);i?.handlePrimary&&i.handlePrimary({nodeId:r,type:i.type,newTab:!0})&&t.preventDefault?.()},l=e=>{let t=e;if(t.key===`Escape`){n.getActiveNode()!==null&&(n.setActiveNode(null),t.preventDefault?.());return}if(t.key!==`Enter`&&t.key!==` `&&t.key!==`Spacebar`)return;let r=cC(e.target,n);if(r===null)return;let i=n.getRegistration(r);t.preventDefault?.(),!(i?.handlePrimary&&i.handlePrimary({nodeId:r,type:i.type,newTab:!1}))&&n.setActiveNode(r)},u=e=>{if(n.getActiveNode()===null)return;let t=e.target;t&&(r?.contains(t)||t instanceof Element&&(t.closest(`[data-ok-interaction-layer]`)||t.closest(`[data-ok-prop-panel]`)||t.closest(`[data-ok-layer-spawned]`))||n.setActiveNode(null))},d=()=>{i||(r=uC(t),r&&(r.addEventListener(`pointerdown`,s,!0),r.addEventListener(`click`,c,!0),r.addEventListener(`auxclick`,c,!0),r.addEventListener(`keydown`,l,!0),typeof document<`u`&&document.addEventListener(`pointerdown`,u,!0),i=!0))},f=()=>{i&&=(r?.removeEventListener(`pointerdown`,s,!0),r?.removeEventListener(`click`,c,!0),r?.removeEventListener(`auxclick`,c,!0),r?.removeEventListener(`keydown`,l,!0),typeof document<`u`&&document.removeEventListener(`pointerdown`,u,!0),!1)};return d(),{register(e){n.register(e),i||d()},deregister(e){n.deregister(e)},setActiveNode(e){n.setActiveNode(e)},getActiveNode(){return n.getActiveNode()},getRegistration(e){return n.getRegistration(e)},destroy(){f(),o(),n.clear()},store:n}}var pC=e=>{let t=(0,J.c)(2),{store:n}=e,r;return t[0]===n?r=t[1]:(r=(0,q.jsx)(`div`,{"data-ok-interaction-layer":``,className:`contents`,children:(0,q.jsx)(lC,{store:n})}),t[0]=n,t[1]=r),r},mC=new WeakMap;function hC(e){let t=mC.get(e);if(t)return t;let n=fC({editor:e});return mC.set(e,n),e.on(`destroy`,()=>{n.destroy(),mC.delete(e)}),n}var gC=new Te(`markIdentity`);function _C(){return{byId:new Map,counter:0}}function vC(e,t,n,r,i){let a=[];for(let e of t.byId.values()){let t=i?i.map(e.from,-1):e.from,n=i?i.map(e.to,1):e.to;n<=t||a.push({id:e.id,markType:e.markType,attrs:e.attrs,from:t,to:n})}let o=new Map,s=new Set,c=t.counter;return e.descendants((e,t)=>{if(!(!e.isInline||e.marks.length===0))for(let i of e.marks){if(!n.has(i.type.name)||r&&!r(i))continue;let l=null;for(let e of a)if(!s.has(e.id)&&e.markType===i.type.name&&yC(e.attrs,i.attrs)&&!(t<e.from||t>=e.to)){l=e.id;break}let u=l??`m${++c}`;s.add(u);let d=t,f=t+e.nodeSize,p=o.get(u);p?p.to=Math.max(p.to,f):o.set(u,{id:u,markType:i.type.name,attrs:i.attrs,from:d,to:f})}}),{byId:o,counter:c}}function yC(e,t){let n=Object.keys(e),r=Object.keys(t);if(n.length!==r.length)return!1;for(let r of n){let n=e[r],i=t[r];if(n!==i&&!(typeof n==`object`&&n&&typeof i==`object`&&i&&yC(n,i)))return!1}return!0}function bC(e,t,n,r){let i=new Set(t.byId.keys());for(let[r,i]of t.byId)e.has(r)||n?.(i);for(let t of e)i.has(t)||r?.(t);return i}function xC(e){let{markTypes:t,predicate:n,onRegister:r,onDeregister:i}=e,a=new Set(t);return new Fe({key:gC,state:{init(e,t){return vC(t.doc,_C(),a,n)},apply(e,t,r,i){return e.docChanged?vC(i.doc,t,a,n,e.mapping):t}},view(){let e=new Set;return{update(t){let n=gC.getState(t.state);n&&(e=bC(e,n,r,i))},destroy(){for(let t of e)i?.(t);e=new Set}}}})}function SC(e,t){return gC.getState(e)?.byId.get(t)??null}function CC(e){let{editor:t,layer:n,renderPropPanel:r,handlePrimary:i}=e;return{onRegister:e=>{n.register({type:e.markType,nodeId:e.id,controls:{propPanel:e=>r({editor:t,nodeId:e.nodeId,deactivate:e.deactivate})},handlePrimary:i?e=>i({editor:t,nodeId:e.nodeId,newTab:e.newTab}):void 0})},onDeregister:e=>{n.deregister(e)}}}function wC(e){let{editor:t,layer:n,markTypes:r,predicate:i,renderPropPanel:a,handlePrimary:o}=e,s=CC({editor:t,layer:n,renderPropPanel:a,handlePrimary:o});return xC({markTypes:[...r],predicate:i,onRegister:s.onRegister,onDeregister:s.onDeregister})}function TC(e){let t=hC(e.editor);return wC({...e,layer:t})}function EC(e){let{char:t,allowSpaces:n,allowToIncludeChar:r,allowedPrefixes:i,startOfLine:a,$position:o}=e,s=n&&!r,c=l(t),u=RegExp(`\\s${c}$`),d=a?`^`:``,f=r?``:c,p=RegExp(s?`${d}${c}.*?(?=\\s${f}|$)`:`${d}(?:^)?${c}[^\\s${f}]*`,`gm`),m=o.nodeBefore?.isText&&o.nodeBefore.text;if(!m)return null;let h=o.pos-m.length,g=Array.from(m.matchAll(p)).pop();if(!g||g.input===void 0||g.index===void 0)return null;let _=g.input.slice(Math.max(0,g.index-1),g.index),v=RegExp(`^[${i?.join(``)}\0]?$`).test(_);if(i!==null&&!v)return null;let y=h+g.index,b=y+g[0].length;return s&&u.test(m.slice(b-1,b+1))&&(g[0]+=` `,b+=1),y<o.pos&&b>=o.pos?{range:{from:y,to:b},query:g[0].slice(t.length),text:g[0]}:null}function DC(e){return e.docChanged?e.steps.some(e=>{let t=e.slice;if(!t?.content)return!1;let n=t.content.textBetween(0,t.content.size,`
7
7
  `);return/\s/.test(n)}):!1}var OC=new Te(`suggestion`);function kC({pluginKey:e=OC,editor:t,char:n=`@`,allowSpaces:r=!1,allowToIncludeChar:i=!1,allowedPrefixes:a=[` `],startOfLine:o=!1,decorationTag:s=`span`,decorationClass:c=`suggestion`,decorationContent:l=``,decorationEmptyClass:u=`is-empty`,command:d=()=>null,items:f=()=>[],render:p=()=>({}),allow:m=()=>!0,findSuggestionMatch:h=EC,shouldShow:g,shouldResetDismissed:_}){let v,y=p?.(),b=r&&!i,x=()=>{let e=t.state.selection.$anchor.pos,{top:n,right:r,bottom:i,left:a}=t.view.coordsAtPos(e);try{return new DOMRect(a,n,r-a,i-n)}catch{return null}},S=(n,r)=>r?()=>{let r=e.getState(t.state)?.decorationId;return n.dom.querySelector(`[data-decoration-id="${r}"]`)?.getBoundingClientRect()||null}:x,C=({match:e,dismissedRange:n,state:r,transaction:i})=>_?.({editor:t,state:r,range:n,match:e,transaction:i,allowSpaces:b})?!1:b?e.range.from===n.from:e.range.from===n.from&&!DC(i);function w(n,r){var i;try{let r=e.getState(n.state),a=r?.decorationId?n.dom.querySelector(`[data-decoration-id="${r.decorationId}"]`):null,o={editor:t,range:r?.range||{from:0,to:0},query:r?.query||null,text:r?.text||null,items:[],command:e=>d({editor:t,range:r?.range||{from:0,to:0},props:e}),decorationNode:a,clientRect:S(n,a)};(i=y?.onExit)==null||i.call(y,o)}catch{}let a=n.state.tr.setMeta(r,{exit:!0});n.dispatch(a)}let T=new Fe({key:e,view(){return{update:async(e,n)=>{var r,i,a,o,s;let c=this.key?.getState(n),l=this.key?.getState(e.state),u=c.active&&l.active&&c.range.from!==l.range.from,p=!c.active&&l.active,m=c.active&&!l.active,h=!p&&!m&&c.query!==l.query,g=p||u&&h,_=h||u,b=m||u&&h;if(!g&&!_&&!b)return;let x=b&&!g?c:l,C=e.dom.querySelector(`[data-decoration-id="${x.decorationId}"]`);v={editor:t,range:x.range,query:x.query,text:x.text,items:[],command:e=>d({editor:t,range:x.range,props:e}),decorationNode:C,clientRect:S(e,C)},g&&((r=y?.onBeforeStart)==null||r.call(y,v)),_&&((i=y?.onBeforeUpdate)==null||i.call(y,v)),(_||g)&&(v.items=await f({editor:t,query:x.query})),b&&((a=y?.onExit)==null||a.call(y,v)),_&&((o=y?.onUpdate)==null||o.call(y,v)),g&&((s=y?.onStart)==null||s.call(y,v))},destroy:()=>{var e;v&&((e=y?.onExit)==null||e.call(y,v))}}},state:{init(){return{active:!1,range:{from:0,to:0},query:null,text:null,composing:!1,dismissedRange:null}},apply(s,c,l,u){let{isEditable:d}=t,{composing:f}=t.view,{selection:p}=s,{empty:_,from:v}=p,y={...c},b=s.getMeta(e);if(b&&b.exit)return y.active=!1,y.decorationId=null,y.range={from:0,to:0},y.query=null,y.text=null,y.dismissedRange=c.active?{...c.range}:c.dismissedRange,y;if(y.composing=f,s.docChanged&&y.dismissedRange!==null&&(y.dismissedRange={from:s.mapping.map(y.dismissedRange.from),to:s.mapping.map(y.dismissedRange.to)}),d&&(_||t.view.composing)){(v<c.range.from||v>c.range.to)&&!f&&!c.composing&&(y.active=!1);let e=h({char:n,allowSpaces:r,allowToIncludeChar:i,allowedPrefixes:a,startOfLine:o,$position:p.$from}),l=`id_${Math.floor(Math.random()*4294967295)}`;e&&m({editor:t,state:u,range:e.range,isActive:c.active})&&(!g||g({editor:t,range:e.range,query:e.query,text:e.text,transaction:s}))?(y.dismissedRange!==null&&!C({match:e,dismissedRange:y.dismissedRange,state:u,transaction:s})&&(y.dismissedRange=null),y.dismissedRange===null?(y.active=!0,y.decorationId=c.decorationId?c.decorationId:l,y.range=e.range,y.query=e.query,y.text=e.text):y.active=!1):(e||(y.dismissedRange=null),y.active=!1)}else y.active=!1;return y.active||(y.decorationId=null,y.range={from:0,to:0},y.query=null,y.text=null),y}},props:{handleKeyDown(t,n){var r;let{active:i,range:a}=T.getState(t.state);if(!i)return!1;if(n.key===`Escape`||n.key===`Esc`){let i=T.getState(t.state);return(r=y?.onKeyDown)==null||r.call(y,{view:t,event:n,range:i.range}),w(t,e),!0}return(y?.onKeyDown)?.call(y,{view:t,event:n,range:a})||!1},decorations(e){let{active:t,range:n,decorationId:r,query:i}=T.getState(e);if(!t)return null;let a=!i?.length,o=[c];return a&&o.push(u),ge.create(e.doc,[Ke.inline(n.from,n.to,{nodeName:s,class:o.join(` `),"data-decoration-id":r,"data-decoration-content":l})])}}});return T}var AC=kC,jC=e(t(((e,t)=>{((e,n)=>{typeof define==`function`&&define.amd?define([],n):typeof t==`object`&&t.exports?t.exports=n():e.fuzzysort=n()})(e,e=>{var t=(e,t)=>{if(!e||!t)return F;var n=p(e);j(t)||(t=f(t));var r=n.bitflags;return(r&t._bitflags)===r?h(n,t):F},n=(e,t,n)=>{if(!e)return n?.all?m(t,n):P;var r=p(e),i=r.bitflags,a=r.containsSpace,o=u(n?.threshold||0),c=n?.limit||M,l=0,d=0,g=t.length;function _(e){l<c?(L.add(e),++l):(++d,e._score>L.peek()._score&&L.replaceTop(e))}if(n?.key)for(var v=n.key,y=0;y<g;++y){var b=t[y],x=A(b,v);if(x&&(j(x)||(x=f(x)),(i&x._bitflags)===i)){var S=h(r,x);S!==F&&(S._score<o||(S.obj=b,_(S)))}}else if(n?.keys){var C=n.keys,w=C.length;outer:for(var y=0;y<g;++y){for(var b=t[y],T=0,R=0;R<w;++R){var v=C[R],x=A(b,v);if(!x){O[R]=I;continue}j(x)||(x=f(x)),O[R]=x,T|=x._bitflags}if((i&T)===i){if(a)for(let e=0;e<r.spaceSearches.length;e++)E[e]=N;for(var R=0;R<w;++R){if(x=O[R],x===I){k[R]=I;continue}if(k[R]=h(r,x,!1,a),k[R]===F){k[R]=I;continue}if(a)for(let e=0;e<r.spaceSearches.length;e++){if(D[e]>-1e3&&E[e]>N){var z=(E[e]+D[e])/4;z>E[e]&&(E[e]=z)}D[e]>E[e]&&(E[e]=D[e])}}if(a){for(let e=0;e<r.spaceSearches.length;e++)if(E[e]===N)continue outer}else{var B=!1;for(let e=0;e<w;e++)if(k[e]._score!==N){B=!0;break}if(!B)continue}var V=new s(w);for(let e=0;e<w;e++)V[e]=k[e];if(a){var H=0;for(let e=0;e<r.spaceSearches.length;e++)H+=E[e]}else{var H=N;for(let e=0;e<w;e++){var S=V[e];if(S._score>-1e3&&H>N){var z=(H+S._score)/4;z>H&&(H=z)}S._score>H&&(H=S._score)}}if(V.obj=b,V._score=H,n?.scoreFn){if(H=n.scoreFn(V),!H)continue;H=u(H),V._score=H}H<o||_(V)}}}else for(var y=0;y<g;++y){var x=t[y];if(x&&(j(x)||(x=f(x)),(i&x._bitflags)===i)){var S=h(r,x);S!==F&&(S._score<o||_(S))}}if(l===0)return P;for(var U=Array(l),y=l-1;y>=0;--y)U[y]=L.poll();return U.total=l+d,U},r=(e,t=`<b>`,n=`</b>`)=>{for(var r=typeof t==`function`?t:void 0,i=e.target,a=i.length,o=e.indexes,s=``,c=0,l=0,u=!1,d=[],f=0;f<a;++f){var p=i[f];if(o[l]===f){if(++l,u||(u=!0,r?(d.push(s),s=``):s+=t),l===o.length){r?(s+=p,d.push(r(s,c++)),s=``,d.push(i.substr(f+1))):s+=p+n+i.substr(f+1);break}}else u&&(u=!1,r?(d.push(r(s,c++)),s=``):s+=n);s+=p}return r?d:s},i=e=>{typeof e==`number`?e=``+e:typeof e!=`string`&&(e=``);var t=v(e);return c(e,{_targetLower:t._lower,_targetLowerCodes:t.lowerCodes,_bitflags:t.bitflags})},a=()=>{x.clear(),S.clear()};class o{get indexes(){return this._indexes.slice(0,this._indexes.len).sort((e,t)=>e-t)}set indexes(e){return this._indexes=e}highlight(e,t){return r(this,e,t)}get score(){return l(this._score)}set score(e){this._score=u(e)}}class s extends Array{get score(){return l(this._score)}set score(e){this._score=u(e)}}var c=(e,t)=>{let n=new o;return n.target=e,n.obj=t.obj??F,n._score=t._score??N,n._indexes=t._indexes??[],n._targetLower=t._targetLower??``,n._targetLowerCodes=t._targetLowerCodes??F,n._nextBeginningIndexes=t._nextBeginningIndexes??F,n._bitflags=t._bitflags??0,n},l=e=>e===N?0:e>1?e:Math.E**(((-e+1)**.04307-1)*-2),u=e=>e===0?N:e>1?e:1-(Math.log(e)/-2+1)**(1/.04307),d=e=>{typeof e==`number`?e=``+e:typeof e!=`string`&&(e=``),e=e.trim();var t=v(e),n=[];if(t.containsSpace){var r=e.split(/\s+/);r=[...new Set(r)];for(var i=0;i<r.length;i++)if(r[i]!==``){var a=v(r[i]);n.push({lowerCodes:a.lowerCodes,_lower:r[i].toLowerCase(),containsSpace:!1})}}return{lowerCodes:t.lowerCodes,_lower:t._lower,containsSpace:t.containsSpace,bitflags:t.bitflags,spaceSearches:n}},f=e=>{if(e.length>999)return i(e);var t=x.get(e);return t===void 0?(t=i(e),x.set(e,t),t):t},p=e=>{if(e.length>999)return d(e);var t=S.get(e);return t===void 0?(t=d(e),S.set(e,t),t):t},m=(e,t)=>{var n=[];n.total=e.length;var r=t?.limit||M;if(t?.key)for(var i=0;i<e.length;i++){var a=e[i],o=A(a,t.key);if(o!=F){j(o)||(o=f(o));var l=c(o.target,{_score:o._score,obj:a});if(n.push(l),n.length>=r)return n}}else if(t?.keys)for(var i=0;i<e.length;i++){for(var a=e[i],u=new s(t.keys.length),d=t.keys.length-1;d>=0;--d){var o=A(a,t.keys[d]);if(!o){u[d]=I;continue}j(o)||(o=f(o)),o._score=N,o._indexes.len=0,u[d]=o}if(u.obj=a,u._score=N,n.push(u),n.length>=r)return n}else for(var i=0;i<e.length;i++){var o=e[i];if(o!=F&&(j(o)||(o=f(o)),o._score=N,o._indexes.len=0,n.push(o),n.length>=r))return n}return n},h=(e,t,n=!1,r=!1)=>{if(n===!1&&e.containsSpace)return g(e,t,r);for(var i=e._lower,a=e.lowerCodes,s=a[0],c=t._targetLowerCodes,l=a.length,u=c.length,d=0,f=0,p=0;;){var m=s===c[f];if(m){if(C[p++]=f,++d,d===l)break;s=a[d]}if(++f,f>=u)return F}var d=0,h=!1,_=0,v=t._nextBeginningIndexes;v===F&&(v=t._nextBeginningIndexes=b(t.target)),f=C[0]===0?0:v[C[0]-1];var y=0;if(f!==u)for(;;)if(f>=u){if(d<=0||(++y,y>200))break;--d;var x=w[--_];f=v[x]}else{var m=a[d]===c[f];if(m){if(w[_++]=f,++d,d===l){h=!0;break}++f}else f=v[f]}var S=l<=1?-1:t._targetLower.indexOf(i,C[0]),T=!!~S,E=T?S===0||t._nextBeginningIndexes[S-1]===S:!1;if(T&&!E){for(var D=0;D<v.length;D=v[D])if(!(D<=S)){for(var O=0;O<l&&a[O]===t._targetLowerCodes[D+O];O++);if(O===l){S=D,E=!0;break}}}var k=e=>{for(var t=0,n=0,r=1;r<l;++r)e[r]-e[r-1]!==1&&(t-=e[r],++n);var i=e[l-1]-e[0]-(l-1);if(t-=(12+i)*n,e[0]!==0&&(t-=e[0]*e[0]*.2),!h)t*=1e3;else{for(var a=1,r=v[0];r<u;r=v[r])++a;a>24&&(t*=(a-24)*10)}return t-=(u-l)/2,T&&(t/=1+l*l*1),E&&(t/=1+l*l*1),t-=(u-l)/2,t};if(!h){if(T)for(var D=0;D<l;++D)C[D]=S+D;var A=C,j=k(A)}else if(E){for(var D=0;D<l;++D)C[D]=S+D;var A=C,j=k(C)}else var A=w,j=k(w);t._score=j;for(var D=0;D<l;++D)t._indexes[D]=A[D];t._indexes.len=l;let M=new o;return M.target=t.target,M._score=t._score,M._indexes=t._indexes,M},g=(e,t,n)=>{for(var r=new Set,i=0,a=F,o=0,s=e.spaceSearches,c=s.length,l=0,u=()=>{for(let e=l-1;e>=0;e--)t._nextBeginningIndexes[T[e*2+0]]=T[e*2+1]},d=!1,f=0;f<c;++f){D[f]=N;var p=s[f];if(a=h(p,t),n){if(a===F)continue;d=!0}else if(a===F)return u(),F;if(f!==c-1){var m=a._indexes,g=!0;for(let e=0;e<m.len-1;e++)if(m[e+1]-m[e]!==1){g=!1;break}if(g){var _=m[m.len-1]+1,v=t._nextBeginningIndexes[_-1];for(let e=_-1;e>=0&&v===t._nextBeginningIndexes[e];e--)t._nextBeginningIndexes[e]=_,T[l*2+0]=e,T[l*2+1]=v,l++}}i+=a._score/c,D[f]=a._score/c,a._indexes[0]<o&&(i-=(o-a._indexes[0])*2),o=a._indexes[0];for(var y=0;y<a._indexes.len;++y)r.add(a._indexes[y])}if(n&&!d)return F;u();var b=h(e,t,!0);if(b!==F&&b._score>i){if(n)for(var f=0;f<c;++f)D[f]=b._score/c;return b}n&&(a=t),a._score=i;var f=0;for(let e of r)a._indexes[f++]=e;return a._indexes.len=f,a},_=e=>e.replace(/\p{Script=Latin}+/gu,e=>e.normalize(`NFD`)).replace(/[\u0300-\u036f]/g,``),v=e=>{e=_(e);for(var t=e.length,n=e.toLowerCase(),r=[],i=0,a=!1,o=0;o<t;++o){var s=r[o]=n.charCodeAt(o);if(s===32){a=!0;continue}var c=s>=97&&s<=122?s-97:s>=48&&s<=57?26:s<=127?30:31;i|=1<<c}return{lowerCodes:r,bitflags:i,containsSpace:a,_lower:n}},y=e=>{for(var t=e.length,n=[],r=0,i=!1,a=!1,o=0;o<t;++o){var s=e.charCodeAt(o),c=s>=65&&s<=90,l=c||s>=97&&s<=122||s>=48&&s<=57,u=c&&!i||!a||!l;i=c,a=l,u&&(n[r++]=o)}return n},b=e=>{e=_(e);for(var t=e.length,n=y(e),r=[],i=n[0],a=0,o=0;o<t;++o)i>o?r[o]=i:(i=n[++a],r[o]=i===void 0?t:i);return r},x=new Map,S=new Map,C=[],w=[],T=[],E=[],D=[],O=[],k=[],A=(e,t)=>{var n=e[t];if(n!==void 0)return n;if(typeof t==`function`)return t(e);var r=t;Array.isArray(t)||(r=t.split(`.`));for(var i=r.length,a=-1;e&&++a<i;)e=e[r[a]];return e},j=e=>typeof e==`object`&&typeof e._bitflags==`number`,M=1/0,N=-M,P=[];P.total=0;var F=null,I=i(``),L=(e=>{var t=[],n=0,r={},i=e=>{for(var r=0,i=t[r],a=1;a<n;){var o=a+1;r=a,o<n&&t[o]._score<t[a]._score&&(r=o),t[r-1>>1]=t[r],a=1+(r<<1)}for(var s=r-1>>1;r>0&&i._score<t[s]._score;s=(r=s)-1>>1)t[r]=t[s];t[r]=i};return r.add=(e=>{var r=n;t[n++]=e;for(var i=r-1>>1;r>0&&e._score<t[i]._score;i=(r=i)-1>>1)t[r]=t[i];t[r]=e}),r.poll=(e=>{if(n!==0){var r=t[0];return t[0]=t[--n],i(),r}}),r.peek=(e=>{if(n!==0)return t[0]}),r.replaceTop=(e=>{t[0]=e,i()}),r})();return{single:t,go:n,prepare:i,cleanup:a}})}))(),1);function MC(e){return e.kind===`anchor`?`${e.docName}#${e.slug}`:e.docName}function NC(e){return e.kind===`anchor`?`Heading H${e.level}: ${e.text}`:e.kind===`create`?e.actionLabel:e.title}function PC(e){let t=(0,J.c)(41),{items:n,query:r,selectedIndex:i,onSelect:a,loading:o,error:s,mode:c,pageTarget:l,anchorQuery:u}=e,d=o===void 0?!1:o,f=s===void 0?null:s,p=c===void 0?`page`:c,m=l===void 0?``:l,h=u===void 0?``:u,g=(0,K.useRef)(null),_=(0,K.useId)(),v=i>=0&&i<n.length?`${_}-option-${i}`:void 0,y,b;t[0]===i?(y=t[1],b=t[2]):(y=()=>{let e=g.current;if(!e)return;let t=e.querySelectorAll(`[role="option"]`).item(i);t&&t.scrollIntoView({block:`nearest`})},b=[i],t[0]=i,t[1]=y,t[2]=b),(0,K.useEffect)(y,b);let x=FC;if(d){let e;t[3]===Symbol.for(`react.memo_cache_sentinel`)?(e={maxHeight:`var(--suggestion-menu-max-height, 40vh)`},t[3]=e):e=t[3];let n=p===`anchor`?`Loading headings for ${m}…`:`Loading pages…`,r;return t[4]===n?r=t[5]:(r=(0,q.jsx)(`div`,{ref:g,role:`status`,"aria-live":`polite`,className:`w-64 rounded-lg border bg-popover p-2 shadow-md text-sm text-muted-foreground`,style:e,onMouseDown:x,children:n}),t[4]=n,t[5]=r),r}if(n.length===0){let e;t[6]!==h||t[7]!==f||t[8]!==p||t[9]!==m||t[10]!==r?(e=f??(p===`anchor`?h.trim()?`No headings match "${h.trim()}"`:`No headings in ${m}`:r.trim()?`No pages found for "${r.trim()}"`:`No pages found`),t[6]=h,t[7]=f,t[8]=p,t[9]=m,t[10]=r,t[11]=e):e=t[11];let n=e,i;t[12]===Symbol.for(`react.memo_cache_sentinel`)?(i={maxHeight:`var(--suggestion-menu-max-height, 40vh)`},t[12]=i):i=t[12];let a;return t[13]===n?a=t[14]:(a=(0,q.jsx)(`div`,{ref:g,role:`status`,"aria-live":`polite`,className:`w-64 rounded-lg border bg-popover p-2 shadow-md text-sm text-muted-foreground`,style:i,onMouseDown:x,children:n}),t[13]=n,t[14]=a),a}let S=i>=0&&i<n.length?n[i]:null,C=p===`anchor`?`Heading suggestions`:`Wiki link suggestions`,w;t[15]===Symbol.for(`react.memo_cache_sentinel`)?(w={maxHeight:`var(--suggestion-menu-max-height, 40vh)`},t[15]=w):w=t[15];let T;t[16]===S?T=t[17]:(T=S?NC(S):``,t[16]=S,t[17]=T);let E;t[18]===T?E=t[19]:(E=(0,q.jsx)(`span`,{className:`sr-only`,"aria-live":`polite`,"aria-atomic":`true`,children:T}),t[18]=T,t[19]=E);let D;t[20]===f?D=t[21]:(D=f&&(0,q.jsx)(`div`,{className:`rounded-md px-2 py-1.5 text-xs text-amber-700 dark:text-amber-300`,children:f}),t[20]=f,t[21]=D);let O;t[22]!==p||t[23]!==m?(O=p===`anchor`&&(0,q.jsx)(`div`,{className:`px-2 py-1 text-[10px] font-medium uppercase tracking-wide text-muted-foreground`,children:m}),t[22]=p,t[23]=m,t[24]=O):O=t[24];let k;if(t[25]!==n||t[26]!==_||t[27]!==a||t[28]!==i){let e;t[30]!==_||t[31]!==a||t[32]!==i?(e=(e,t)=>{let n=t===i,r=MC(e);return e.kind===`anchor`?(0,q.jsxs)(`button`,{id:`${_}-option-${t}`,type:`button`,role:`option`,"aria-selected":n,"data-selected":n,className:`flex w-full items-center gap-2 rounded-md px-2 py-1.5 text-sm text-left ${n?`bg-accent text-accent-foreground`:``}`,style:{paddingLeft:`${(e.level-1)*10+8}px`},onMouseDown:t=>{t.preventDefault(),a(e)},children:[(0,q.jsxs)(`span`,{className:`w-6 shrink-0 font-mono text-[10px] text-muted-foreground`,children:[`H`,e.level]}),(0,q.jsx)(`span`,{className:`truncate font-medium`,children:e.text})]},r):(0,q.jsxs)(`button`,{id:`${_}-option-${t}`,type:`button`,role:`option`,"aria-selected":n,"data-selected":n,className:`flex w-full flex-col rounded-md px-2 py-1.5 text-sm text-left ${n?`bg-accent text-accent-foreground`:``}`,onMouseDown:t=>{t.preventDefault(),a(e)},children:[(0,q.jsx)(`span`,{className:`truncate font-medium`,children:e.kind===`create`?e.actionLabel:e.title}),e.kind===`page`&&e.title!==e.docName&&(0,q.jsx)(`span`,{className:`truncate text-xs text-muted-foreground`,children:e.docName}),e.kind===`create`&&(0,q.jsxs)(`span`,{className:`truncate text-xs text-muted-foreground`,children:[e.docName,`.md`]})]},r)},t[30]=_,t[31]=a,t[32]=i,t[33]=e):e=t[33],k=n.map(e),t[25]=n,t[26]=_,t[27]=a,t[28]=i,t[29]=k}else k=t[29];let A;return t[34]!==v||t[35]!==E||t[36]!==D||t[37]!==O||t[38]!==k||t[39]!==C?(A=(0,q.jsxs)(`div`,{ref:g,role:`listbox`,"aria-label":C,"aria-activedescendant":v,tabIndex:-1,onMouseDown:x,className:`w-64 overflow-y-auto subtle-scrollbar rounded-lg border bg-popover p-1 shadow-md`,style:w,children:[E,D,O,k]}),t[34]=v,t[35]=E,t[36]=D,t[37]=O,t[38]=k,t[39]=C,t[40]=A):A=t[40],A}function FC(e){return e.preventDefault()}function IC(e,t){let n=document.createElement(`div`);n.style.position=`fixed`,n.style.zIndex=`50`,n.style.visibility=`hidden`,document.body.appendChild(n);let r={getBoundingClientRect:()=>e()?.clientRect?.()??new DOMRect,get contextElement(){return e()?.editor.view.dom}},i=!1,a=!1,o=()=>{n.isConnected&&(n.style.removeProperty(`--suggestion-menu-max-height`),b(r,n,{placement:`bottom-start`,middleware:[nt(4),T(),f({padding:8}),te({apply({availableHeight:e}){n.isConnected&&n.style.setProperty(`--suggestion-menu-max-height`,`${Math.min(e,window.innerHeight*.4)}px`)}})]}).then(({x:e,y:t})=>{n.isConnected&&(n.style.left=`${e}px`,n.style.top=`${t}px`,i&&!a&&(n.style.removeProperty(`visibility`),a=!0))}).catch(e=>{n.isConnected&&console.warn(`[${t}] computePosition failed`,e)}))};return{popup:n,doPosition:o,startAutoUpdate:()=>F(r,n,o),reveal:()=>{a||(i=!0,o())}}}function LC(e){e.stopAutoUpdate?.(),e.stopAutoUpdate=null,e.popup?.remove(),e.popup=null}var RC=new Te(`wikiLinkSuggestion`),zC=8;function BC(e){let t=e.indexOf(`#`);return t>0?{mode:`anchor`,pageTarget:e.slice(0,t),anchorQuery:e.slice(t+1)}:{mode:`page`,pageTarget:``,anchorQuery:``}}function VC(e,t){return t?jC.default.go(t,e,{keys:[`title`,`docName`],threshold:-1e4}).map(e=>e.obj).slice(0,zC):e.slice(0,zC)}function HC(e,t){return t?jC.default.go(t,e,{key:`text`,threshold:-1e4}).map(e=>e.obj).slice(0,zC):e.slice(0,zC)}function UC(e,t){let n=VC(e,t);if(n.length>0)return n.map(e=>({kind:`page`,...e}));let r=Yy(t);return r?[{kind:`create`,docName:r.target,title:t.trim(),actionLabel:`Insert unresolved link "${t.trim()}"`}]:[]}function WC(e,t,n){return HC(t,n).map(t=>({kind:`anchor`,docName:e,level:t.level,text:t.text,slug:t.slug}))}function GC(e){let{mode:t,pageTarget:n,anchorQuery:r}=BC(e);return t===`anchor`&&n?{target:n,alias:null,anchor:r.trim()||null}:Yy(e)}function KC(e){let{$position:t}=e,n=t.parent.textBetween(0,t.parentOffset,void 0,``),r=n.match(/\[\[([^\]]*)$/);if(!r)return null;let i=r[1];return{range:{from:t.start()+n.lastIndexOf(`[[`),to:t.pos},query:i,text:r[0]}}async function qC(){let e=await fetch(`/api/pages`);if(!e.ok)throw Error(`/api/pages responded with ${e.status}`);let t=await e.json();return Array.isArray(t.pages)?t.pages:[]}async function JC(e){let t=await fetch(`/api/page-headings?docName=${encodeURIComponent(e)}`);if(!t.ok)throw Error(`/api/page-headings responded with ${t.status}`);let n=await t.json();return n.ok&&Array.isArray(n.headings)?n.headings:[]}function YC(e){let t=[],n=!1,r=!1,i=new Map,a=null,o=null,s=null;return AC({editor:e,pluginKey:RC,char:`[[`,allowedPrefixes:null,findSuggestionMatch:KC,items:async({query:e})=>{let{mode:c,pageTarget:l,anchorQuery:u}=BC(e);if(c===`anchor`){if(!i.has(l)&&a!==l){a=l;try{let e=await JC(l);i.set(l,e),s=null}catch(e){console.error(`[wiki-link-suggestion] Failed to fetch headings:`,e),i.set(l,[]),s=`Failed to load headings for ${l}. Press Escape and type [[ again to retry.`}finally{a=null}}return WC(l,i.get(l)??[],u)}if(!n&&!r){r=!0;try{t=await qC(),o=null}catch(e){console.error(`[wiki-link-suggestion] Failed to fetch pages:`,e),o=`Failed to load pages. Press Escape and type [[ again to retry, or continue typing to insert an unresolved link.`,t=[]}finally{n=!0,r=!1}}return UC(t,e)},command:({editor:e,range:t,props:n})=>{try{let r=null;if(n.kind===`page`?r={target:n.docName,alias:null,anchor:null}:n.kind===`anchor`?r={target:n.docName,alias:null,anchor:n.slug}:n.kind===`create`&&(r=Yy(n.title)),!r)return;e.chain().focus().deleteRange(t).insertContent({type:`wikiLink`,attrs:r}).run()}catch(e){console.error(`[wiki-link-suggestion] command failed`,{item:n,range:t},e)}},render:()=>{let e=null,c=null,l=0,u={popup:null,stopAutoUpdate:null},d=null,f=null,p=e=>{c?.command(e)};function m(e,t,r){let{mode:a,pageTarget:c,anchorQuery:u}=BC(e.query??``),d=t===null?a===`anchor`?!i.has(c):!n:t;return{items:e.items,query:e.query??``,selectedIndex:l,onSelect:r,loading:d,error:a===`page`?o:s,mode:a,pageTarget:c,anchorQuery:u}}let h=t=>{!e||!c||e.updateProps(m(c,t,p))},g=()=>{if(!c)return;let{editor:e,range:t}=c,n=GC(c.query??``);if(n)try{e.chain().focus().deleteRange(t).insertContent({type:`wikiLink`,attrs:n}).run()}catch(e){console.error(`[wiki-link-suggestion] fallback insert error:`,e)}};return{onBeforeStart(t){c=t,l=0;let n=IC(()=>c,`wiki-link-suggestion`);u.popup=n.popup,d=n.doPosition,f=n.reveal,e=new Ya(PC,{props:m(t,!0,p),editor:t.editor}),n.popup.appendChild(e.element),u.stopAutoUpdate=n.startAutoUpdate()},onBeforeUpdate(e){let t=c?BC(c.query??``).mode:null,n=BC(e.query??``).mode;c=e,t!==n&&(l=0,h(!0))},onStart(e){c=e,l=0,h(null),f?.()},onUpdate(e){c=e,l=Math.min(l,Math.max(0,e.items.length-1)),h(null),d?.()},onKeyDown({event:e}){if(!c)return!1;let t=c.items;if(e.key===`ArrowDown`)return t.length===0?!1:(l=(l+1)%t.length,h(null),!0);if(e.key===`ArrowUp`)return t.length===0?!1:(l=(l-1+t.length)%t.length,h(null),!0);if(e.key===`Enter`||e.key===`Tab`){let e=t[l];return e?c.command(e):g(),!0}return e.key,!1},onExit(){LC(u),d=null,f=null,e?.destroy(),e=null,c=null,l=0,t=[],i=new Map,o=null,s=null,n=!1,r=!1,a=null}}}})}function XC(e,t){let n=(0,J.c)(4),[r,i]=(0,K.useState)(null),a,o;return n[0]!==e||n[1]!==t?(a=()=>{if(!t||!e){i(null);return}let n=!1;return i(null),JC(e).then(e=>{n||i(e)}).catch(()=>{n||i([])}),()=>{n=!0}},o=[e,t],n[0]=e,n[1]=t,n[2]=a,n[3]=o):(a=n[2],o=n[3]),(0,K.useEffect)(a,o),r}function ZC(e,t){let n=e.trim();return n?n.startsWith(`#`)?`anchor`:n.startsWith(`/`)||N(n)?`external`:`doc`:t}function QC(e){return e?.kind===`doc`?`doc`:e?.kind===`anchor`?`anchor`:`external`}function $C(e){let t=(0,J.c)(64),{open:n,href:r,pages:i,onOpenChange:a,onSave:o}=e,[s,c]=(0,K.useState)(``),[l,u]=(0,K.useState)(``),[d,f]=(0,K.useState)(`doc`),p=(0,K.useId)(),m=(0,K.useId)(),h=(0,K.useId)(),g,_;t[0]!==r||t[1]!==n?(g=()=>{if(!n)return;let e=PS(r);if(f(QC(e)),e?.kind===`doc`){c(e.docName),u(e.anchor??``);return}if(e?.kind===`anchor`){c(`#${e.anchor}`),u(``);return}c(e?.kind===`external`?e.url:r),u(``)},_=[r,n],t[0]=r,t[1]=n,t[2]=g,t[3]=_):(g=t[2],_=t[3]),(0,K.useEffect)(g,_);let v,y,b;t[4]!==d||t[5]!==s||t[6]!==i?(v=we(s),y=d===`doc`,b=y&&Zy(v,i),t[4]=d,t[5]=s,t[6]=i,t[7]=v,t[8]=y,t[9]=b):(v=t[7],y=t[8],b=t[9]);let x=XC(v,b&&n),S=!!x?.length,C;t[10]!==v||t[11]!==y||t[12]!==l||t[13]!==s||t[14]!==a||t[15]!==o?(C=function(){let e=s.trim();e&&(o(y?HS(v,l.trim()||null):e),a(!1))},t[10]=v,t[11]=y,t[12]=l,t[13]=s,t[14]=a,t[15]=o,t[16]=C):C=t[16];let w=C,T;t[17]===w?T=t[18]:(T=function(e){e.key===`Enter`&&(e.preventDefault(),w())},t[17]=w,t[18]=T);let E=T,D;t[19]===Symbol.for(`react.memo_cache_sentinel`)?(D=(0,q.jsx)(Tt,{className:`fixed inset-0 z-50 bg-black/40 data-open:animate-in data-open:fade-in-0 data-closed:animate-out data-closed:fade-out-0`}),t[19]=D):D=t[19];let O,k;t[20]===Symbol.for(`react.memo_cache_sentinel`)?(O=(0,q.jsx)(Dt,{className:`mb-1 text-base font-semibold`,children:`Edit markdown link`}),k=(0,q.jsx)(wt,{className:`mb-4 text-sm text-muted-foreground`,children:`Update the destination and optional section anchor.`}),t[20]=O,t[21]=k):(O=t[20],k=t[21]);let A=y?`Page`:`Link target`,j;t[22]!==A||t[23]!==p?(j=(0,q.jsx)(`label`,{className:`mb-1.5 block text-sm font-medium`,htmlFor:p,children:A}),t[22]=A,t[23]=p,t[24]=j):j=t[24];let M;t[25]===Symbol.for(`react.memo_cache_sentinel`)?(M=e=>{let t=e.target.value;c(t),f(e=>ZC(t,e))},t[25]=M):M=t[25];let N;t[26]!==s||t[27]!==E||t[28]!==p?(N=(0,q.jsx)(XS,{id:p,value:s,onChange:M,placeholder:`guides/install or https://example.com`,autoFocus:!0,onKeyDown:E}),t[26]=s,t[27]=E,t[28]=p,t[29]=N):N=t[29];let P;t[30]===y?P=t[31]:(P=y?(0,q.jsx)(`p`,{className:`mt-1.5 text-xs text-muted-foreground`,children:`This changes the destination page. The visible link text stays editable inline in the document.`}):null,t[30]=y,t[31]=P);let F;t[32]!==j||t[33]!==N||t[34]!==P?(F=(0,q.jsxs)(`div`,{children:[j,N,P]}),t[32]=j,t[33]=N,t[34]=P,t[35]=F):F=t[35];let I;t[36]!==m||t[37]!==y||t[38]!==l||t[39]!==E||t[40]!==h||t[41]!==x||t[42]!==S?(I=y?(0,q.jsxs)(`div`,{children:[(0,q.jsxs)(`label`,{className:`mb-1.5 block text-sm font-medium`,htmlFor:m,children:[`Section`,` `,(0,q.jsx)(`span`,{className:`font-normal text-muted-foreground`,children:`(optional heading anchor)`})]}),(0,q.jsx)(XS,{id:m,value:l,onChange:e=>u(e.target.value),placeholder:`heading-slug`,"aria-controls":S?h:void 0,"aria-expanded":S?!0:void 0,"aria-haspopup":S?`listbox`:void 0,onKeyDown:E}),S?(0,q.jsx)(`div`,{role:`listbox`,id:h,"aria-label":`Heading anchors`,className:`mt-1.5 max-h-36 overflow-y-auto subtle-scrollbar rounded-md border border-border bg-muted/30`,children:x.map(e=>(0,q.jsxs)(`button`,{type:`button`,role:`option`,"aria-selected":l===e.slug,className:ht(`flex w-full items-center gap-2 px-2 py-1 text-left text-sm hover:bg-accent hover:text-accent-foreground`,l===e.slug&&`bg-accent text-accent-foreground`),style:{paddingLeft:`${(e.level-1)*12+8}px`},onClick:()=>u(l===e.slug?``:e.slug),children:[(0,q.jsxs)(`span`,{className:`w-7 shrink-0 font-mono text-[10px] text-muted-foreground`,children:[`H`,e.level]}),(0,q.jsx)(`span`,{className:`truncate`,children:e.text})]},`${e.slug}-${e.level}-${e.text}`))}):null]}):null,t[36]=m,t[37]=y,t[38]=l,t[39]=E,t[40]=h,t[41]=x,t[42]=S,t[43]=I):I=t[43];let L;t[44]!==F||t[45]!==I?(L=(0,q.jsxs)(`div`,{className:`mb-4 space-y-6`,children:[F,I]}),t[44]=F,t[45]=I,t[46]=L):L=t[46];let R;t[47]===a?R=t[48]:(R=(0,q.jsx)(_t,{variant:`outline`,onClick:()=>a(!1),children:`Cancel`}),t[47]=a,t[48]=R);let z;t[49]===s?z=t[50]:(z=s.trim(),t[49]=s,t[50]=z);let B=!z,V;t[51]!==w||t[52]!==B?(V=(0,q.jsx)(_t,{onClick:w,disabled:B,children:`Save`}),t[51]=w,t[52]=B,t[53]=V):V=t[53];let H;t[54]!==R||t[55]!==V?(H=(0,q.jsxs)(`div`,{className:`flex justify-end gap-2`,children:[R,V]}),t[54]=R,t[55]=V,t[56]=H):H=t[56];let U;t[57]!==L||t[58]!==H?(U=(0,q.jsxs)(Mt,{children:[D,(0,q.jsxs)(Ft,{"data-slot":`dialog-content`,"data-ok-layer-spawned":``,className:`fixed left-1/2 top-1/2 z-50 w-full max-w-md -translate-x-1/2 -translate-y-1/2 rounded-lg border border-border bg-background p-6 shadow-xl data-open:animate-in data-open:fade-in-0 data-open:zoom-in-95 data-closed:animate-out data-closed:fade-out-0 data-closed:zoom-out-95`,children:[O,k,L,H]})]}),t[57]=L,t[58]=H,t[59]=U):U=t[59];let ee;return t[60]!==a||t[61]!==n||t[62]!==U?(ee=(0,q.jsx)(kt,{open:n,onOpenChange:a,children:U}),t[60]=a,t[61]=n,t[62]=U,t[63]=ee):ee=t[63],ee}function ew(e){let t=(0,J.c)(90),{editor:n,nodeId:r,sourceDocName:i,onClose:a}=e,o=SC(n.state,r),s=o?.attrs?.href??``,[l,u]=(0,K.useState)(!1),[d,f]=(0,K.useState)(null),{folderPaths:p,pages:m,loading:h}=De();if(!o||!s)return null;let g=c(s,i),_=g?.kind===`doc`?`${g.docName}${g.anchor?`#${g.anchor}`:``}`:g?.kind===`anchor`?`#${g.anchor}`:g?.kind===`external`?g.url:s,v;t[0]!==n||t[1]!==r?(v=function(e){let t=SC(n.state,r);t&&n.chain().setTextSelection({from:t.from,to:t.to}).extendMarkRange(`link`).updateAttributes(`link`,{href:e}).run()},t[0]=n,t[1]=r,t[2]=v):v=t[2];let y=v,b;t[3]!==n||t[4]!==r||t[5]!==a?(b=function(){let e=SC(n.state,r);e&&(n.chain().focus().setTextSelection({from:e.from,to:e.to}).extendMarkRange(`link`).unsetLink().run(),a())},t[3]=n,t[4]=r,t[5]=a,t[6]=b):b=t[6];let x=b,S=function(e){if(g){if(g.kind===`asset`){let t=E(g.url,i);if(!t)return;AS({url:g.url,projectRelPath:t,ext:g.ext,title:t.split(`/`).pop()??g.url,forceOsDelegation:e.newTab??!1});return}if(g.kind===`external`){VS(g);return}if(g.kind===`anchor`||g.kind===`doc`){let t=g.kind===`doc`?g.docName:i,n=g.anchor??null;e.newTab?RS({docName:t,anchor:n}):window.location.assign(FS({docName:t,anchor:n}))}}},C=function(e){if(d!==`missing`)return;let t=SC(n.state,r);t&&n.chain().setTextSelection({from:t.from,to:t.to}).extendMarkRange(`link`).updateAttributes(`link`,{href:HS(e,g?.kind===`doc`?g.anchor??null:null)}).run()},w,T=!1,D=!1,O=null;if(h){let e;t[7]===Symbol.for(`react.memo_cache_sentinel`)?(e=(0,q.jsx)(nr,{className:`size-3.5 shrink-0 animate-spin`,"aria-hidden":`true`}),t[7]=e):e=t[7],w={icon:e,text:`Loading…`,className:`text-muted-foreground`}}else if(g?.kind===`asset`){let e;t[8]===Symbol.for(`react.memo_cache_sentinel`)?(e=(0,q.jsx)(Gn,{className:`size-3.5 shrink-0`,"aria-hidden":`true`}),t[8]=e):e=t[8],w={icon:e,text:`Asset reference`,className:`text-foreground`}}else if(g?.kind===`external`){let e;t[9]===Symbol.for(`react.memo_cache_sentinel`)?(e=(0,q.jsx)(Un,{className:`size-3.5 shrink-0`,"aria-hidden":`true`}),t[9]=e):e=t[9],w={icon:e,text:`External link`,className:`text-foreground`}}else if(g?.kind===`anchor`){let e;t[10]===Symbol.for(`react.memo_cache_sentinel`)?(e=(0,q.jsx)(Gn,{className:`size-3.5 shrink-0`,"aria-hidden":`true`}),t[10]=e):e=t[10],w={icon:e,text:`Anchor in this page`,className:`text-foreground`}}else if(g?.kind===`doc`){let e=JS(g.docName,{pages:m,folderPaths:p});if(O=YS(e),D=e.kind===`navigate`&&e.displayState===`folder`,T=e.kind===`create`,D){let e;t[11]===Symbol.for(`react.memo_cache_sentinel`)?(e=(0,q.jsx)(Kn,{className:`size-3.5 shrink-0`,"aria-hidden":`true`}),t[11]=e):e=t[11],w={icon:e,text:`Folder (no index)`,className:`text-foreground`}}else if(T){let e;t[12]===Symbol.for(`react.memo_cache_sentinel`)?(e=(0,q.jsx)(Vn,{className:`size-3.5 shrink-0`,"aria-hidden":`true`}),t[12]=e):e=t[12],w={icon:e,text:`Page not found`,className:`text-red-700 dark:text-red-300`}}else{let e;t[13]===Symbol.for(`react.memo_cache_sentinel`)?(e=(0,q.jsx)(Gn,{className:`size-3.5 shrink-0`,"aria-hidden":`true`}),t[13]=e):e=t[13],w={icon:e,text:`Page link`,className:`text-foreground`}}}else{let e;t[14]===Symbol.for(`react.memo_cache_sentinel`)?(e=(0,q.jsx)(Vn,{className:`size-3.5 shrink-0`,"aria-hidden":`true`}),t[14]=e):e=t[14],w={icon:e,text:`Unrecognized link`,className:`text-muted-foreground`}}let k;t[15]!==n.state||t[16]!==n.view||t[17]!==r?(k=()=>{let e=SC(n.state,r);if(!e)return new DOMRect;try{return pe(n.view,e.from,e.to)}catch{return new DOMRect}},t[15]=n.state,t[16]=n.view,t[17]=r,t[18]=k):k=t[18];let A;t[19]!==n.view.dom||t[20]!==k?(A={getBoundingClientRect:k,contextElement:n.view.dom},t[19]=n.view.dom,t[20]=k,t[21]=A):A=t[21];let j=A,M=ht(`text-sm font-medium`,w.className),N;t[22]!==w.text||t[23]!==M?(N=(0,q.jsx)(`div`,{className:M,children:w.text}),t[22]=w.text,t[23]=M,t[24]=N):N=t[24];let P;t[25]===_?P=t[26]:(P=(0,q.jsx)(`div`,{className:`truncate font-mono text-xs text-muted-foreground`,title:_,children:_}),t[25]=_,t[26]=P);let F;t[27]!==N||t[28]!==P?(F=(0,q.jsxs)(`div`,{className:`flex-1 min-w-0`,children:[N,P]}),t[27]=N,t[28]=P,t[29]=F):F=t[29];let I;t[30]!==S||t[31]!==T||t[32]!==a||t[33]!==g?.kind?(I=T?null:(0,q.jsx)(_t,{size:`sm`,variant:`default`,onClick:()=>{S({}),a()},children:g?.kind===`external`?`Open in new tab`:`Open`}),t[30]=S,t[31]=T,t[32]=a,t[33]=g?.kind,t[34]=I):I=t[34];let L;t[35]!==T||t[36]!==f?(L=T?(0,q.jsx)(_t,{size:`sm`,variant:`default`,onClick:()=>f(`missing`),children:`Create page`}):null,t[35]=T,t[36]=f,t[37]=L):L=t[37];let R;t[38]!==O||t[39]!==D||t[40]!==f?(R=D&&O?(0,q.jsxs)(_t,{size:`sm`,variant:`outline`,onClick:()=>f(`folder-index`),children:[(0,q.jsx)(Wn,{className:`size-3.5`,"aria-hidden":`true`}),`Create index`]}):null,t[38]=O,t[39]=D,t[40]=f,t[41]=R):R=t[41];let z;t[42]===Symbol.for(`react.memo_cache_sentinel`)?(z=(0,q.jsx)(`div`,{className:`flex-1`}),t[42]=z):z=t[42];let B;t[43]===u?B=t[44]:(B=()=>u(!0),t[43]=u,t[44]=B);let V;t[45]===Symbol.for(`react.memo_cache_sentinel`)?(V=(0,q.jsx)(or,{className:`size-3.5`,"aria-hidden":`true`}),t[45]=V):V=t[45];let H;t[46]===B?H=t[47]:(H=(0,q.jsxs)(_t,{size:`sm`,variant:`outline`,onClick:B,children:[V,`Edit`]}),t[46]=B,t[47]=H);let U;t[48]===Symbol.for(`react.memo_cache_sentinel`)?(U=(0,q.jsx)(dr,{className:`size-3.5`,"aria-hidden":`true`}),t[48]=U):U=t[48];let ee;t[49]===x?ee=t[50]:(ee=(0,q.jsxs)(_t,{size:`sm`,variant:`destructive`,onClick:x,children:[U,`Remove`]}),t[49]=x,t[50]=ee);let te;t[51]!==I||t[52]!==L||t[53]!==R||t[54]!==H||t[55]!==ee?(te=(0,q.jsxs)(`div`,{className:`flex flex-wrap items-center gap-1.5`,children:[I,L,R,z,H,ee]}),t[51]=I,t[52]=L,t[53]=R,t[54]=H,t[55]=ee,t[56]=te):te=t[56];let ne=d!==null,re;t[57]===f?re=t[58]:(re=e=>{e||f(null)},t[57]=f,t[58]=re);let W;t[59]!==d||t[60]!==O||t[61]!==p||t[62]!==T||t[63]!==m||t[64]!==g?(W=d===`folder-index`&&O?O.initialDir:T&&g?.kind===`doc`&&JS(g.docName,{pages:m,folderPaths:p}).kind===`create`?JS(g.docName,{pages:m,folderPaths:p}).initialDir:``,t[59]=d,t[60]=O,t[61]=p,t[62]=T,t[63]=m,t[64]=g,t[65]=W):W=t[65];let ie;t[66]!==d||t[67]!==O||t[68]!==p||t[69]!==T||t[70]!==m||t[71]!==g?(ie=d===`folder-index`&&O?O.suggestedName:T&&g?.kind===`doc`&&JS(g.docName,{pages:m,folderPaths:p}).kind===`create`?JS(g.docName,{pages:m,folderPaths:p}).suggestedName:void 0,t[66]=d,t[67]=O,t[68]=p,t[69]=T,t[70]=m,t[71]=g,t[72]=ie):ie=t[72];let ae;t[73]!==d||t[74]!==O||t[75]!==g?(ae=d===`folder-index`&&O?(0,q.jsxs)(q.Fragment,{children:[`Create an index note for`,` `,(0,q.jsxs)(`span`,{className:`font-medium text-foreground`,children:[O.initialDir,`/`]})]}):(0,q.jsxs)(q.Fragment,{children:[`Create a page for`,` `,(0,q.jsx)(`span`,{className:`font-medium text-foreground`,children:g?.kind===`doc`?g.docName:``})]}),t[73]=d,t[74]=O,t[75]=g,t[76]=ae):ae=t[76];let oe;t[77]!==C||t[78]!==ne||t[79]!==re||t[80]!==W||t[81]!==ie||t[82]!==ae?(oe=(0,q.jsx)(iC,{open:ne,onOpenChange:re,kind:`file`,initialDir:W,suggestedName:ie,description:ae,onCreated:C}),t[77]=C,t[78]=ne,t[79]=re,t[80]=W,t[81]=ie,t[82]=ae,t[83]=oe):oe=t[83];let se;return t[84]!==l||t[85]!==y||t[86]!==s||t[87]!==m||t[88]!==u?(se=(0,q.jsx)($C,{open:l,href:s,pages:m,onOpenChange:u,onSave:y}),t[84]=l,t[85]=y,t[86]=s,t[87]=m,t[88]=u,t[89]=se):se=t[89],(0,q.jsxs)(q.Fragment,{children:[(0,q.jsxs)(KS,{kind:`internal-link`,ariaLabel:`Link options`,onDeactivate:a,triggerReference:j,children:[(0,q.jsxs)(`div`,{className:`mb-2 flex items-start gap-2 pr-8`,children:[(0,q.jsx)(`div`,{className:ht(`mt-0.5 flex shrink-0`,w.className),children:w.icon}),F]}),te]}),oe,se]})}function tw(e,t,n){let r=c(e,t);if(!r)return`unresolved`;if(r.kind===`external`)return`external`;if(r.kind===`anchor`)return`anchor`;if(r.kind===`asset`)return`asset`;if(n===null)return`loading`;let i=JS(r.docName,{pages:n.pages,folderPaths:n.folderPaths});return i.kind===`create`?`unresolved`:i.displayState}function nw(e,t,n){let r=e.attrs?.href;return typeof r!=`string`||r.length===0||e.attrs?.sourceForm===`wikiembed`?null:{"data-resolution-state":tw(r,n,t)}}function rw(e){return(t,n)=>nw(t,n,e)}var iw=new Te(`linkResolutionDecoration`);function aw(e,t,n,r,i){if(t.size===0)return null;let a=[];for(let e of t.values()){if(!n.has(e.markType))continue;let t=r(e,i);t!==null&&a.push(Ke.inline(e.from,e.to,t))}return a.length===0?null:ge.create(e,a)}function ow(e){let t=new Set(e.markTypes),{computeAttrs:n}=e;return new Fe({key:iw,state:{init:()=>({version:0}),apply(e,t){let n=e.getMeta(iw);return n&&typeof n==`object`&&n.refresh?{version:t.version+1}:t}},props:{decorations(e){let r=gC.getState(e);if(!r)return null;let i=Be();return aw(e.doc,r.byId,t,n,i)}},view(e){let t=fe(()=>{e.dispatch(e.state.tr.setMeta(iw,{refresh:!0}))});return{destroy(){t()}}}})}var sw=new Te(`markIdentityDecoration`),cw=`data-mark-id`;function lw(){return new Fe({key:sw,props:{decorations(e){let t=gC.getState(e);if(!t||t.byId.size===0)return null;let n=[];for(let e of t.byId.values())n.push(Ke.inline(e.from,e.to,{[cw]:e.id}));return ge.create(e.doc,n)}}})}var uw=P.extend({addOptions(){return{...this.parent?.(),docName:``}},renderHTML({HTMLAttributes:e}){let t=typeof e.href==`string`?e.href:``;return[`span`,Ve(e,{"data-link":``,role:`link`,tabindex:`0`,"aria-label":t?`Link: ${t}`:`Link`,style:`touch-action: manipulation;`}),0]},addProseMirrorPlugins(){let e=this.options.docName??``;return[TC({editor:this.editor,markTypes:[`link`],renderPropPanel:({editor:t,nodeId:n,deactivate:r})=>(0,K.createElement)(ew,{editor:t,nodeId:n,sourceDocName:e,onClose:r}),handlePrimary:({editor:t,nodeId:n,newTab:r})=>{let i=SC(t.state,n),a=i?.attrs?.href;if(typeof a!=`string`||!a)return!1;let o=i?.attrs?.sourceForm,s=c(a,e),l=Ne(a);if(s?.kind===`asset`||o===`wikiembed`&&l!==null){let t=s?.kind===`asset`?s.url:a,n=s?.kind===`asset`?s.ext:l??``,i=E(t,e);return i?(AS({url:t,projectRelPath:i,ext:n,title:i.split(`/`).pop()??t,forceOsDelegation:r}),!0):!1}return!r||!s?!1:s.kind===`doc`?(RS({docName:s.docName,anchor:s.anchor}),!0):s.kind===`anchor`?(RS({docName:e,anchor:s.anchor}),!0):MS(s.url)?(IS(s.url),!0):!1}}),lw(),ow({markTypes:[`link`],computeAttrs:rw(e)}),GS({sourceDocName:e})]}}),dw=(0,K.createContext)(null),fw={didCatch:!1,error:null},pw=class extends K.Component{constructor(e){super(e),this.resetErrorBoundary=this.resetErrorBoundary.bind(this),this.state=fw}static getDerivedStateFromError(e){return{didCatch:!0,error:e}}resetErrorBoundary(...e){let{error:t}=this.state;t!==null&&(this.props.onReset?.({args:e,reason:`imperative-api`}),this.setState(fw))}componentDidCatch(e,t){this.props.onError?.(e,t)}componentDidUpdate(e,t){let{didCatch:n}=this.state,{resetKeys:r}=this.props;n&&t.error!==null&&mw(e.resetKeys,r)&&(this.props.onReset?.({next:r,prev:e.resetKeys,reason:`keys`}),this.setState(fw))}render(){let{children:e,fallbackRender:t,FallbackComponent:n,fallback:r}=this.props,{didCatch:i,error:a}=this.state,o=e;if(i){let e={error:a,resetErrorBoundary:this.resetErrorBoundary};if(typeof t==`function`)o=t(e);else if(n)o=(0,K.createElement)(n,e);else if(r!==void 0)o=r;else throw a}return(0,K.createElement)(dw.Provider,{value:{didCatch:i,error:a,resetErrorBoundary:this.resetErrorBoundary}},o)}};function mw(e=[],t=[]){return e.length!==t.length||e.some((e,n)=>!Object.is(e,t[n]))}function hw(e){let t=(0,J.c)(4),n;t[0]===e?n=t[1]:({...n}=e,t[0]=e,t[1]=n);let r;return t[2]===n?r=t[3]:(r=(0,q.jsx)(ii,{"data-slot":`popover`,...n}),t[2]=n,t[3]=r),r}function gw(e){let t=(0,J.c)(4),n;t[0]===e?n=t[1]:({...n}=e,t[0]=e,t[1]=n);let r;return t[2]===n?r=t[3]:(r=(0,q.jsx)(oi,{"data-slot":`popover-trigger`,...n}),t[2]=n,t[3]=r),r}function _w(e){let t=(0,J.c)(12),n,r,i,a;t[0]===e?(n=t[1],r=t[2],i=t[3],a=t[4]):({className:n,align:i,sideOffset:a,...r}=e,t[0]=e,t[1]=n,t[2]=r,t[3]=i,t[4]=a);let o=i===void 0?`center`:i,s=a===void 0?4:a,c;t[5]===n?c=t[6]:(c=ht(`z-50 w-72 rounded-lg border bg-popover p-4 text-popover-foreground shadow-md outline-hidden data-[state=open]:animate-in data-[state=closed]:animate-out data-[state=closed]:fade-out-0 data-[state=open]:fade-in-0 data-[state=closed]:zoom-out-95 data-[state=open]:zoom-in-95 data-[side=bottom]:slide-in-from-top-2 data-[side=left]:slide-in-from-right-2 data-[side=right]:slide-in-from-left-2 data-[side=top]:slide-in-from-bottom-2`,n),t[5]=n,t[6]=c);let l;return t[7]!==o||t[8]!==r||t[9]!==s||t[10]!==c?(l=(0,q.jsx)(si,{children:(0,q.jsx)(ci,{"data-slot":`popover-content`,align:o,sideOffset:s,className:c,...r})}),t[7]=o,t[8]=r,t[9]=s,t[10]=c,t[11]=l):l=t[11],l}function vw(e){let t=(0,J.c)(4),n;t[0]===e?n=t[1]:({...n}=e,t[0]=e,t[1]=n);let r;return t[2]===n?r=t[3]:(r=(0,q.jsx)(ai,{"data-slot":`popover-anchor`,...n}),t[2]=n,t[3]=r),r}function yw(e){let t=(0,J.c)(23),n,r,i,a,o,s;t[0]===e?(n=t[1],r=t[2],i=t[3],a=t[4],o=t[5],s=t[6]):({label:i,Icon:n,onClick:a,selected:s,className:r,...o}=e,t[0]=e,t[1]=n,t[2]=r,t[3]=i,t[4]=a,t[5]=o,t[6]=s);let c=s?`true`:void 0,l;t[7]===a?l=t[8]:(l=e=>{(e.key===`Enter`||e.key===` `)&&(e.preventDefault(),a())},t[7]=a,t[8]=l);let u;t[9]===r?u=t[10]:(u=ht(`flex w-full items-center justify-center gap-2 rounded-md border border-dashed border-border bg-transparent px-3 py-2 text-center text-sm text-muted-foreground transition-colors hover:bg-muted/50 cursor-pointer outline-none focus-visible:ring-2 focus-visible:ring-ring focus-visible:ring-offset-2`,r),t[9]=r,t[10]=u);let d;t[11]===n?d=t[12]:(d=(0,q.jsx)(n,{size:16,"aria-hidden":`true`}),t[11]=n,t[12]=d);let f;t[13]===i?f=t[14]:(f=(0,q.jsx)(`span`,{children:i}),t[13]=i,t[14]=f);let p;return t[15]!==a||t[16]!==o||t[17]!==c||t[18]!==l||t[19]!==u||t[20]!==d||t[21]!==f?(p=(0,q.jsxs)(`div`,{...o,role:`button`,tabIndex:-1,contentEditable:!1,"data-descriptor-placeholder":``,"data-selected":c,onClick:a,onMouseDown:bw,onKeyDown:l,className:u,children:[d,f]}),t[15]=a,t[16]=o,t[17]=c,t[18]=l,t[19]=u,t[20]=d,t[21]=f,t[22]=p):p=t[22],p}function bw(e){e.preventDefault(),e.stopPropagation()}function xw(e){let t=(0,J.c)(4),n;t[0]===e?n=t[1]:({...n}=e,t[0]=e,t[1]=n);let r;return t[2]===n?r=t[3]:(r=(0,q.jsx)(Er,{"data-slot":`collapsible`,...n}),t[2]=n,t[3]=r),r}function Sw(e){let t=(0,J.c)(4),n;t[0]===e?n=t[1]:({...n}=e,t[0]=e,t[1]=n);let r;return t[2]===n?r=t[3]:(r=(0,q.jsx)(Dr,{"data-slot":`collapsible-trigger`,...n}),t[2]=n,t[3]=r),r}function Cw(e){let t=(0,J.c)(4),n;t[0]===e?n=t[1]:({...n}=e,t[0]=e,t[1]=n);let r;return t[2]===n?r=t[3]:(r=(0,q.jsx)(Or,{"data-slot":`collapsible-content`,...n}),t[2]=n,t[3]=r),r}function ww(e){let t=(0,J.c)(11),n,r,i;t[0]===e?(n=t[1],r=t[2],i=t[3]):({className:n,size:i,...r}=e,t[0]=e,t[1]=n,t[2]=r,t[3]=i);let a=i===void 0?`default`:i,o;t[4]===n?o=t[5]:(o=ht(`peer group/switch relative inline-flex shrink-0 items-center rounded-full border border-transparent transition-all outline-none after:absolute after:-inset-x-3 after:-inset-y-2 focus-visible:border-ring focus-visible:ring-3 focus-visible:ring-ring/50 aria-invalid:border-destructive aria-invalid:ring-3 aria-invalid:ring-destructive/20 data-[size=default]:h-[18.4px] data-[size=default]:w-[32px] data-[size=sm]:h-[14px] data-[size=sm]:w-[24px] dark:aria-invalid:border-destructive/50 dark:aria-invalid:ring-destructive/40 data-checked:bg-primary data-unchecked:bg-input dark:data-unchecked:bg-input/80 data-disabled:cursor-not-allowed data-disabled:opacity-50`,n),t[4]=n,t[5]=o);let s;t[6]===Symbol.for(`react.memo_cache_sentinel`)?(s=(0,q.jsx)(xi,{"data-slot":`switch-thumb`,className:`pointer-events-none block rounded-full bg-background ring-0 transition-transform group-data-[size=default]/switch:size-4 group-data-[size=sm]/switch:size-3 group-data-[size=default]/switch:data-checked:translate-x-[calc(100%-2px)] group-data-[size=sm]/switch:data-checked:translate-x-[calc(100%-2px)] dark:data-checked:bg-primary-foreground group-data-[size=default]/switch:data-unchecked:translate-x-0 group-data-[size=sm]/switch:data-unchecked:translate-x-0 dark:data-unchecked:bg-foreground`}),t[6]=s):s=t[6];let c;return t[7]!==r||t[8]!==a||t[9]!==o?(c=(0,q.jsx)(bi,{"data-slot":`switch`,"data-size":a,className:o,...r,children:s}),t[7]=r,t[8]=a,t[9]=o,t[10]=c):c=t[10],c}function Tw(){if(typeof window>`u`)return null;let e=window.location.hash.match(/^#\/([^?#]+)/);return e?decodeURIComponent(e[1]):null}var Ew=`/api/upload`;async function Dw(e,t,n={}){let r=n.fetch??globalThis.fetch,i=n.docName===void 0?Tw():n.docName;if(!i)throw Error(`No document is open`);let a=new FormData;a.append(`file`,e),a.append(`parentDocName`,i);let o;try{o=await r(Ew,{method:`POST`,body:a})}catch(e){let t=e instanceof Error?e.message:String(e);throw Error(`Upload failed: ${t}`)}if(!o.ok){let e=`Upload failed (${o.status})`;try{let t=await o.json();t.error&&(e=t.error)}catch{}throw Error(e)}let s;try{let e=await o.json(),t=e.path??e.src;if(typeof t!=`string`)throw Error(`Server response missing "path"/"src" field`);s=t.startsWith(`/`)?t:`/${t}`}catch(e){let t=e instanceof Error?e.message:String(e);throw Error(`Upload response parse error: ${t}`)}return{url:s}}var Ow=new Intl.PluralRules(`en-US`);function kw(e,t,n){return n<=0?`${e} (empty)`:`${e} with ${n} ${Ow.select(n)===`one`?`item`:`items`}`}var Aw=`Document`;function jw(e){for(let t of e)if(t.type===`string`&&t.hidden!==!0&&t.advanced!==!0&&t.autoFocus===!0)return t.name;return null}function Mw(e){if(!e)return e;let t=e.replace(/[_-]+/g,` `).replace(/([a-z0-9])([A-Z])/g,`$1 $2`).replace(/([A-Z]+)([A-Z][a-z])/g,`$1 $2`);return t.charAt(0).toUpperCase()+t.slice(1)}function Nw(e){return`ok.propPanel.advanced.${e}`}function Pw(e){try{return typeof localStorage>`u`?!1:localStorage.getItem(Nw(e))===`true`}catch{return!1}}function Fw(e,t){try{if(typeof localStorage>`u`)return;localStorage.setItem(Nw(e),t?`true`:`false`)}catch{}}function Iw(e,t){let n=0;for(let r of e){let e=t[r.name],i=`defaultValue`in r?r.defaultValue:void 0;e!==void 0&&e!==i&&(n+=1)}return n}async function Lw(e,t,n){try{let{url:r}=await Dw(e,t);n(r)}catch(e){let t=e instanceof Error?e.message:String(e);Lt.error(`Upload failed: ${t}`)}}function Rw(e){let t=(0,J.c)(11),{descriptor:n,values:r,onChange:i}=e,a=n.props.filter(Vw),o=a.filter(Bw),s=a.filter(zw),c=Iw(s,r),l;t[0]===n.props?l=t[1]:(l=jw(n.props),t[0]=n.props,t[1]=l);let u=l,d;t[2]===n.name?d=t[3]:(d=()=>Pw(n.name),t[2]=n.name,t[3]=d);let[f,p]=(0,K.useState)(d);if(a.length===0)return null;let m;t[4]!==u||t[5]!==i||t[6]!==r?(m=e=>(0,q.jsx)(Uw,{propDef:e,value:r[e.name],onChange:t=>i(e.name,t),isAutoFocused:e.name===u},e.name),t[4]=u,t[5]=i,t[6]=r,t[7]=m):m=t[7];let h=o.map(m),g=s.length>0&&(0,q.jsxs)(q.Fragment,{children:[(0,q.jsx)(`div`,{className:`my-1 border-t border-border`}),(0,q.jsxs)(xw,{open:f,onOpenChange:e=>{p(e),Fw(n.name,e)},children:[(0,q.jsxs)(Sw,{"data-prop-panel-advanced-trigger":``,className:`group flex w-full items-center justify-between rounded px-1 py-1 text-xs text-muted-foreground hover:bg-muted hover:text-foreground`,children:[(0,q.jsxs)(`span`,{className:`flex items-center gap-1.5`,children:[(0,q.jsx)(zn,{className:`size-3 transition-transform group-data-[state=closed]:-rotate-90`}),`Advanced`]}),c>0&&(0,q.jsx)(Ti,{variant:`secondary`,"data-prop-panel-advanced-count":``,children:c})]}),(0,q.jsx)(Cw,{className:`flex flex-col gap-2 pt-2`,children:s.map(e=>(0,q.jsx)(Uw,{propDef:e,value:r[e.name],onChange:t=>i(e.name,t),isAutoFocused:e.name===u},e.name))})]})]}),_;return t[8]!==h||t[9]!==g?(_=(0,q.jsxs)(`div`,{"data-prop-panel":``,className:`flex flex-col gap-2 p-3 text-sm`,children:[h,g]}),t[8]=h,t[9]=g,t[10]=_):_=t[10],_}function zw(e){return`advanced`in e&&e.advanced}function Bw(e){return!(`advanced`in e&&e.advanced)}function Vw(e){return!(`hidden`in e&&e.hidden)&&e.type!==`reactnode`}function Hw(e){throw Error(`PropPanel: unhandled PropDef type ${JSON.stringify(e)}`)}function Uw(e){let t=(0,J.c)(71),{propDef:n,value:r,onChange:i,isAutoFocused:a}=e;switch(n.type){case`reactnode`:return null;case`string`:{let e=`prop-${n.name}`,o=n.accept,s=o!==void 0&&o.length>0,c=!n.required&&n.defaultValue===void 0,l;t[0]===n.name?l=t[1]:(l=Mw(n.name),t[0]=n.name,t[1]=l);let u;t[2]!==e||t[3]!==l?(u=(0,q.jsx)(`label`,{htmlFor:e,className:`text-xs text-muted-foreground`,children:l}),t[2]=e,t[3]=l,t[4]=u):u=t[4];let d=r??``,f;t[5]!==i||t[6]!==c?(f=e=>{let t=e.target.value;if(t===``&&c){i(void 0);return}i(t)},t[5]=i,t[6]=c,t[7]=f):f=t[7];let p=a?``:void 0,m;t[8]!==a||t[9]!==e||t[10]!==d||t[11]!==f||t[12]!==p?(m=(0,q.jsx)(XS,{id:e,type:`text`,value:d,onChange:f,autoFocus:a,"data-prop-autofocus":p,className:`h-7 text-sm`}),t[8]=a,t[9]=e,t[10]=d,t[11]=f,t[12]=p,t[13]=m):m=t[13];let h;t[14]!==o||t[15]!==i||t[16]!==s?(h=s&&(0,q.jsx)(Gw,{accept:o,onUploaded:e=>i(e)}),t[14]=o,t[15]=i,t[16]=s,t[17]=h):h=t[17];let g;t[18]!==m||t[19]!==h?(g=(0,q.jsxs)(`div`,{className:`flex gap-1`,children:[m,h]}),t[18]=m,t[19]=h,t[20]=g):g=t[20];let _;return t[21]!==u||t[22]!==g?(_=(0,q.jsxs)(`div`,{className:`flex flex-col gap-1`,children:[u,g]}),t[21]=u,t[22]=g,t[23]=_):_=t[23],_}case`boolean`:{let e=`prop-${n.name}`,a;t[24]===n.name?a=t[25]:(a=Mw(n.name),t[24]=n.name,t[25]=a);let o=a,s;t[26]!==e||t[27]!==o?(s=(0,q.jsx)(`label`,{htmlFor:e,className:`text-xs text-muted-foreground`,children:o}),t[26]=e,t[27]=o,t[28]=s):s=t[28];let c=!!r,l;t[29]===i?l=t[30]:(l=e=>i(e),t[29]=i,t[30]=l);let u;t[31]!==e||t[32]!==c||t[33]!==l?(u=(0,q.jsx)(ww,{id:e,checked:c,onCheckedChange:l}),t[31]=e,t[32]=c,t[33]=l,t[34]=u):u=t[34];let d;return t[35]!==s||t[36]!==u?(d=(0,q.jsxs)(`div`,{className:`flex items-center justify-between gap-2`,children:[s,u]}),t[35]=s,t[36]=u,t[37]=d):d=t[37],d}case`enum`:{let e=`prop-${n.name}`,a;t[38]===n.name?a=t[39]:(a=Mw(n.name),t[38]=n.name,t[39]=a);let o;t[40]!==e||t[41]!==a?(o=(0,q.jsx)(`label`,{htmlFor:e,className:`text-xs text-muted-foreground`,children:a}),t[40]=e,t[41]=a,t[42]=o):o=t[42];let s=r??n.enumValues[0]??``,c;t[43]===i?c=t[44]:(c=e=>i(e.target.value),t[43]=i,t[44]=c);let l;t[45]===n.enumValues?l=t[46]:(l=n.enumValues.map(Ww),t[45]=n.enumValues,t[46]=l);let u;t[47]!==e||t[48]!==s||t[49]!==c||t[50]!==l?(u=(0,q.jsx)(`select`,{id:e,value:s,onChange:c,className:`h-7 rounded border border-input bg-background px-2 text-sm`,children:l}),t[47]=e,t[48]=s,t[49]=c,t[50]=l,t[51]=u):u=t[51];let d;return t[52]!==o||t[53]!==u?(d=(0,q.jsxs)(`div`,{className:`flex flex-col gap-1`,children:[o,u]}),t[52]=o,t[53]=u,t[54]=d):d=t[54],d}case`number`:{let e=`prop-${n.name}`,a;t[55]===n.name?a=t[56]:(a=Mw(n.name),t[55]=n.name,t[56]=a);let o;t[57]!==e||t[58]!==a?(o=(0,q.jsx)(`label`,{htmlFor:e,className:`text-xs text-muted-foreground`,children:a}),t[57]=e,t[58]=a,t[59]=o):o=t[59];let s=r==null?``:String(r),c;t[60]===i?c=t[61]:(c=e=>{let t=e.target.value;if(t===``){i(void 0);return}if(t===`-`)return;let n=Number(t);Number.isNaN(n)||i(n)},t[60]=i,t[61]=c);let l;t[62]!==e||t[63]!==s||t[64]!==c?(l=(0,q.jsx)(XS,{id:e,type:`number`,inputMode:`numeric`,value:s,onChange:c,className:`h-7 text-sm`}),t[62]=e,t[63]=s,t[64]=c,t[65]=l):l=t[65];let u;return t[66]!==o||t[67]!==l?(u=(0,q.jsxs)(`div`,{className:`flex flex-col gap-1`,children:[o,l]}),t[66]=o,t[67]=l,t[68]=u):u=t[68],u}default:{let e;return t[69]===n?e=t[70]:(e=Hw(n),t[69]=n,t[70]=e),e}}}function Ww(e){return(0,q.jsx)(`option`,{value:e,children:e},e)}function Gw(e){let t=(0,J.c)(17),{accept:n,onUploaded:r}=e,[i,a]=(0,K.useState)(!1),o=(0,K.useRef)(null),s;t[0]===n?s=t[1]:(s=n.join(`,`),t[0]=n,t[1]=s);let c;t[2]!==n||t[3]!==r?(c=async e=>{let t=e.target.files?.[0];if(t){a(!0);try{await Lw(t,n,r)}catch{}a(!1),o.current&&(o.current.value=``)}},t[2]=n,t[3]=r,t[4]=c):c=t[4];let l;t[5]!==s||t[6]!==c?(l=(0,q.jsx)(`input`,{ref:o,type:`file`,accept:s,className:`hidden`,"data-prop-upload-input":``,onChange:c}),t[5]=s,t[6]=c,t[7]=l):l=t[7];let u;t[8]===Symbol.for(`react.memo_cache_sentinel`)?(u=()=>o.current?.click(),t[8]=u):u=t[8];let d;t[9]===i?d=t[10]:(d=i?(0,q.jsx)(nr,{className:`size-3.5 animate-spin`}):(0,q.jsx)(fr,{className:`size-3.5`}),t[9]=i,t[10]=d);let f;t[11]!==d||t[12]!==i?(f=(0,q.jsx)(_t,{type:`button`,variant:`outline`,size:`sm`,disabled:i,"aria-label":`Upload file`,"data-prop-upload-trigger":``,className:`h-7 px-2`,onClick:u,children:d}),t[11]=d,t[12]=i,t[13]=f):f=t[13];let p;return t[14]!==l||t[15]!==f?(p=(0,q.jsxs)(q.Fragment,{children:[l,f]}),t[14]=l,t[15]=f,t[16]=p):p=t[16],p}var Kw=`selectionStatePlugin/origin`,qw=`selectionStatePlugin/refresh`,Jw=new Te(`selectionState`),Yw={selectedBlockId:null,ancestorChain:[],selectionOrigin:`programmatic`,isDragging:!1};function Xw(e){return Jw.getState(e.state)??Yw}function Zw(e,t){let n=[],{$from:r}=t;for(let t=1;t<=r.depth;t++){let i=r.node(t);if(i.type.name!==`jsxComponent`)continue;let a=r.before(t);n.push(Qw(e,i,a))}if(t instanceof Le){let r=t.node;r.type.name===`jsxComponent`&&n.push(Qw(e,r,t.from))}return n}function Qw(e,t,n){let r=t.attrs.componentName??`unknown`;return{bridgeId:$w(e,n),componentName:r,pos:n}}function $w(e,t){return kx.getState(e)?.posToId.get(t)??`pos-${t}`}function eT(e,t,n={}){let r=Zw(e,e.selection),i={selectedBlockId:r[r.length-1]?.bridgeId??null,ancestorChain:r,selectionOrigin:n.origin??t.selectionOrigin,isDragging:n.isDragging??t.isDragging};return tT(t,i)?t:i}function tT(e,t){if(e===t)return!0;if(e.selectedBlockId!==t.selectedBlockId||e.selectionOrigin!==t.selectionOrigin||e.isDragging!==t.isDragging||e.ancestorChain.length!==t.ancestorChain.length)return!1;for(let n=0;n<e.ancestorChain.length;n++){let r=e.ancestorChain[n],i=t.ancestorChain[n];if(r.bridgeId!==i.bridgeId||r.componentName!==i.componentName||r.pos!==i.pos)return!1}return!0}var nT=new WeakMap;function rT(e,t,n,r){let i=r?.isDragging??t.isDragging,a=!!e.getMeta(qw),o=e.selectionSet&&!a,s=e.getMeta(Kw),c=o?r?.pendingOrigin??null:null,l=s??c??t.selectionOrigin;return o&&r&&(r.pendingOrigin=null),eT(n,t,{origin:l,isDragging:i})}var iT=W.create({name:`selectionStatePlugin`,addProseMirrorPlugins(){let e=this.editor,t=new Fe({key:Jw,state:{init(e,t){return eT(t,Yw)},apply(e,n,r,i){return rT(e,n,i,nT.get(t))}},props:{handleDOMEvents:{mousedown:()=>{let e=nT.get(t);return e&&(e.pendingOrigin=`pointer`),!1},pointerdown:()=>{let e=nT.get(t);return e&&(e.pendingOrigin=`pointer`),!1}},handleKeyDown:(e,n)=>{if(aT(n.key)){let e=nT.get(t);e&&(e.pendingOrigin=`keyboard`)}return!1}},view(n){nT.set(t,{pendingOrigin:null,isDragging:!1});let r=()=>{let n=nT.get(t);n&&(n.isDragging=!0,oT(e))},i=()=>{let n=nT.get(t);n&&(n.isDragging=!1,oT(e))};return n.dom.addEventListener(`dragstart`,r,!0),n.dom.addEventListener(`dragend`,i,!0),n.dom.addEventListener(`drop`,i,!0),{destroy:()=>{n.dom.removeEventListener(`dragstart`,r,!0),n.dom.removeEventListener(`dragend`,i,!0),n.dom.removeEventListener(`drop`,i,!0),nT.delete(t)}}}});return[t]}});function aT(e){return e===`ArrowUp`||e===`ArrowDown`||e===`ArrowLeft`||e===`ArrowRight`||e===`Tab`||e===`Escape`||e===`Enter`||e===`Home`||e===`End`||e===`PageUp`||e===`PageDown`}function oT(e){queueMicrotask(()=>{if(!e.isDestroyed)try{let t=e.state.tr.setMeta(qw,!0);e.view.dispatch(t)}catch{}})}function sT(e){let t=(0,J.c)(5),n;t[0]===e?n=t[1]:(n=()=>e?Xw(e):null,t[0]=e,t[1]=n);let[r,i]=(0,K.useState)(n),a,o;return t[2]===e?(a=t[3],o=t[4]):(a=()=>{if(!e){i(null);return}i(Xw(e));let t=()=>{i(Xw(e))};return e.on(`transaction`,t),e.on(`selectionUpdate`,t),()=>{e.off(`transaction`,t),e.off(`selectionUpdate`,t)}},o=[e],t[2]=e,t[3]=a,t[4]=o),(0,K.useEffect)(a,o),r}function cT(){}function lT(e){let{xmlFragment:t,ytext:n}=e,r=(e,t)=>{},i=(e,t)=>{};return t.observeDeep(r),n.observe(i),()=>{t.unobserveDeep(r),n.unobserve(i)}}function uT(e,t){if(e.hasChildren)return!1;let n=jw(e.props);return n===null?!1:t[n]===``}function dT(e){let t=e.placeholder?.label,n=`Add ${(e.displayName??e.name).toLowerCase()}`;return{label:t??n,Icon:Qb(e.placeholder?.icon??e.icon)}}var fT=null;function pT(){return fT||=new y({extensions:R}),fT}function mT(e){if(!e.attrs.sourceDirty&&e.attrs.sourceRaw)return e.attrs.sourceRaw;let t=pT(),n=e.type.schema.node(`doc`,null,[e]);return t.serialize(n.toJSON()).trim()}var hT=new Set([`http:`,`https:`,`mailto:`,`tel:`,`ftp:`,`sms:`]),gT=6e4,_T=10,vT=new Map;function yT(e,t){let n=t.toLowerCase();g(n);let r=Date.now(),i=vT.get(n);if(!i||r-i.windowStart>=gT)vT.set(n,{windowStart:r,count:1});else if(i.count+=1,i.count>_T)return;typeof console<`u`&&typeof console.warn==`function`&&console.warn(JSON.stringify({event:`jsx-prop-dropped`,reason:e,prop:t}))}var bT=new Set([`href`,`src`,`action`,`formaction`,`poster`,`cite`,`data`,`manifest`,`background`,`ping`,`xlinkhref`,`xlinkactuate`,`xlinkrole`,`xlinkarcrole`,`xlinkshow`,`url`,`link`]),xT=new Set([`dangerouslysetinnerhtml`,`ref`,`key`,`defaultvalue`,`defaultchecked`,`__proto__`,`constructor`,`prototype`]),ST=1e4;function CT(e){let t=e.toLowerCase();return!!(xT.has(t)||t.length>=3&&t.startsWith(`on`))}function wT(e){return bT.has(e.toLowerCase())}function TT(e){if(typeof e!=`string`)return e;let t=e.trim();if(!t||t.startsWith(`#`)||t.startsWith(`//`))return e;let n=t.indexOf(`:`);if(n===-1||n>[t.indexOf(`/`),t.indexOf(`?`),t.indexOf(`#`)].filter(e=>e!==-1).reduce((e,t)=>Math.min(e,t),1/0))return e;let r=t.slice(0,n+1).toLowerCase();return hT.has(r)?e:`#`}function ET(e){if(e.length>ST)return``;let t=e.toLowerCase();return/url\s*\(\s*['"]?\s*(?:javascript|vbscript|data)\s*:/.test(t)||/\bexpression\s*\(/.test(t)?``:e}function DT(e){if(e==null)return e;if(Array.isArray(e)){let t=!1,n=Array(e.length);for(let r=0;r<e.length;r++){let i=DT(e[r]);n[r]=i,i!==e[r]&&(t=!0)}return t?n:e}if(typeof e!=`object`)return e;let t=Object.getPrototypeOf(e);if(t!==Object.prototype&&t!==null)return e;let n=e,r=!1,i={};for(let[e,t]of Object.entries(n)){if(CT(e)){yT(`dangerous-prop-name-nested`,e),r=!0;continue}if(wT(e)&&typeof t==`string`){let n=TT(t);n!==t&&(r=!0),i[e]=n}else{let n=DT(t);n!==t&&(r=!0),i[e]=n}}return r?i:e}function OT(e){let t=!1,n={};for(let[r,i]of Object.entries(e)){if(CT(r)){yT(`dangerous-prop-name`,r),t=!0;continue}if(wT(r)){let e=TT(i);e!==i&&(t=!0),n[r]=e;continue}if(r===`style`){if(typeof i==`string`){let e=ET(i);e!==i&&(t=!0),n[r]=e}else t=!0;continue}let e=DT(i);e!==i&&(t=!0),n[r]=e}return t?n:e}function kT(e){let t=(0,J.c)(2),{children:n}=e,r;return t[0]===n?r=t[1]:(r=(0,q.jsx)(`div`,{className:`jsx-component-error-fallback`,children:n}),t[0]=n,t[1]=r),r}function AT(e){let t=(0,J.c)(13),{children:n,resetKey:r,onError:i,descriptorName:a,rawComponentName:o}=e,s;t[0]===r?s=t[1]:(s=[r],t[0]=r,t[1]=s);let c;t[2]!==a||t[3]!==i||t[4]!==o?(c=(e,t)=>{let n=e instanceof Error?e:Error(String(e));console.warn(JSON.stringify({event:`jsx-render-failure`,component:a,rawComponentName:String(o??``).slice(0,200),error:String(n),stack:t.componentStack})),Ye(a),i(n)},t[2]=a,t[3]=i,t[4]=o,t[5]=c):c=t[5];let l;t[6]===n?l=t[7]:(l=e=>(0,q.jsx)(kT,{...e,children:n}),t[6]=n,t[7]=l);let u;return t[8]!==n||t[9]!==s||t[10]!==c||t[11]!==l?(u=(0,q.jsx)(pw,{resetKeys:s,onError:c,fallbackRender:l,children:n}),t[8]=n,t[9]=s,t[10]=c,t[11]=l,t[12]=u):u=t[12],u}function jT(e){if(typeof e!=`object`||!e)return JSON.stringify(e);if(Array.isArray(e))return`[${e.map(jT).join(`,`)}]`;let t=Object.entries(e);return t.sort(([e],[t])=>e<t?-1:+(e>t)),`{${t.map(([e,t])=>`${JSON.stringify(e)}:${jT(t)}`).join(`,`)}}`}function MT(e,t){let n=e.props??{},r={};for(let[e,i]of Object.entries(n))t.has(e)||(r[e]=i);return OT(r)}var NT=3;function PT(e){let t=(0,J.c)(152),{node:n,editor:r,getPos:i,selected:a}=e,o=Yb(n.attrs.componentName),[s,c]=(0,K.useState)(null),[l,u]=(0,K.useState)(!1),d=(0,K.useRef)(!1),f=typeof i==`function`?i():void 0,p=!1,m=0,h=1;try{if(f!==void 0){let e=r.state.doc.resolve(f);e.depth>0&&e.parent.type.name===`jsxComponent`&&(p=!0,m=e.index(e.depth),h=e.parent.childCount)}}catch(e){let t=e;if(!(t instanceof RangeError))throw t}let g=p&&m>0,_=p&&m<h-1,y=sT(r),b=typeof f==`number`?$w(r.state,f):null,x=b!==null&&y?.selectedBlockId===b,S=b!==null&&!x&&(y?.ancestorChain.some(e=>e.bridgeId===b)??!1),C=x&&y?y.selectionOrigin:void 0,w=x&&(y?.isDragging??!1),T=o.props.some(RT),E=n.attrs.props??{},D=T&&o.props.some(e=>e.type!==`string`||`hidden`in e&&e.hidden?!1:E[e.name]===``),O=uT(o,E),k=O?dT(o):null,A=!o.hasChildren||!!o.isSelfClosing;(0,K.useEffect)(()=>{a&&!d.current&&T&&ox(f)&&u(!0),d.current=a},[a,T,f]);let j=MT(n.attrs,o.reactNodePropNames),M=o.surface===`compat`?o.translateProps(j):j,N=`${o.name}::${jT(j)}`,P;t[0]!==i||t[1]!==n.content.size?(P=()=>(typeof i==`function`?i()??0:0)+1+n.content.size,t[0]=i,t[1]=n.content.size,t[2]=P):P=t[2];let F=P,I=o.name===`*`||s!==null,L=(0,K.useRef)(!1),R=(0,K.useRef)(0),[z,B]=(0,K.useState)(!1),U;t[3]!==o.displayName||t[4]!==o.name||t[5]!==r||t[6]!==i||t[7]!==I||t[8]!==n||t[9]!==s?.message||t[10]!==z?(U=()=>{if(!I||L.current||z)return;let e=typeof i==`function`?i():void 0;if(typeof e!=`number`)return;let t=mT(n),a=o.name===`*`?`Unregistered component: ${n.attrs.componentName}`:`Render error in <${o.displayName??o.name}>: ${s?.message??`unknown`}`,c=n.type.schema.nodes.rawMdxFallback.create({reason:a},n.type.schema.text(t)),l=!1,u,d=()=>{if(!l)try{r.view.dispatch(r.state.tr.replaceWith(e,e+n.nodeSize,c)),L.current=!0,Qe(o.name===`*`?`wildcard`:o.name)}catch(e){let t=e,r=o.name===`*`?`wildcard`:o.name;if(console.warn(JSON.stringify({event:`jsx-component-auto-convert-failed`,component:r,rawComponentName:String(n.attrs.componentName??``).slice(0,200),reason:t instanceof Error?t.message.slice(0,500):String(t).slice(0,500),retry:R.current})),de(r),R.current+=1,R.current<NT){let e=50*(2**R.current-1);u=setTimeout(()=>{l||d()},e)}else l||B(!0)}},f=requestAnimationFrame(d);return()=>{l=!0,cancelAnimationFrame(f),u!==void 0&&clearTimeout(u)}},t[3]=o.displayName,t[4]=o.name,t[5]=r,t[6]=i,t[7]=I,t[8]=n,t[9]=s?.message,t[10]=z,t[11]=U):U=t[11];let ee;if(t[12]!==o||t[13]!==r||t[14]!==i||t[15]!==I||t[16]!==n||t[17]!==s||t[18]!==z?(ee=[I,n,r,i,o,s,z],t[12]=o,t[13]=r,t[14]=i,t[15]=I,t[16]=n,t[17]=s,t[18]=z,t[19]=ee):ee=t[19],(0,K.useEffect)(U,ee),z){let e=o.name===`*`?`<${n.attrs.componentName}> isn't a known component. Copy the source to use it elsewhere, or delete the block.`:`<${o.displayName??o.name}> failed to render (likely a bad prop). Copy the source to see what went wrong, or delete the block.`,a;t[20]!==o.name||t[21]!==n?(a=()=>{try{let e=mT(n);typeof navigator<`u`&&navigator.clipboard?.writeText&&navigator.clipboard.writeText(e)}catch(e){let t=e;H(o.name),console.warn(JSON.stringify({event:`jsx-component-stuck-copy-failed`,component:o.name,rawComponentName:String(n.attrs.componentName??``).slice(0,200),reason:t instanceof Error?t.message.slice(0,500):String(t).slice(0,500)}))}},t[20]=o.name,t[21]=n,t[22]=a):a=t[22];let s=a,c;t[23]!==o.name||t[24]!==r||t[25]!==i||t[26]!==n.attrs.componentName?(c=()=>{let e=typeof i==`function`?i():void 0;if(typeof e==`number`)try{r.chain().focus().setNodeSelection(e).deleteSelection().run()}catch(e){let t=e;if(!(t instanceof RangeError))throw t;v(o.name),console.warn(JSON.stringify({event:`jsx-component-stuck-delete-failed`,component:o.name,rawComponentName:String(n.attrs.componentName??``).slice(0,200),reason:t.message.slice(0,500)}))}},t[23]=o.name,t[24]=r,t[25]=i,t[26]=n.attrs.componentName,t[27]=c):c=t[27];let l=c,u;t[28]===e?u=t[29]:(u=(0,q.jsx)(`span`,{className:`flex-1`,children:e}),t[28]=e,t[29]=u);let d;t[30]===s?d=t[31]:(d=(0,q.jsx)(`button`,{type:`button`,className:`text-xs underline hover:no-underline`,onClick:s,children:`Copy source`}),t[30]=s,t[31]=d);let f;t[32]===l?f=t[33]:(f=(0,q.jsx)(`button`,{type:`button`,className:`text-xs underline hover:no-underline`,onClick:l,children:`Delete`}),t[32]=l,t[33]=f);let p;t[34]!==u||t[35]!==d||t[36]!==f?(p=(0,q.jsxs)(`div`,{className:`text-xs font-mono text-muted-foreground px-2 py-2 border border-destructive/40 rounded bg-destructive/5 flex items-center gap-2`,contentEditable:!1,children:[u,d,f]}),t[34]=u,t[35]=d,t[36]=f,t[37]=p):p=t[37];let m;t[38]===Symbol.for(`react.memo_cache_sentinel`)?(m=(0,q.jsx)(Ha,{className:`component-children`}),t[38]=m):m=t[38];let h;return t[39]===p?h=t[40]:(h=(0,q.jsxs)(Ua,{className:`jsx-component-wrapper my-2`,children:[p,m]}),t[39]=p,t[40]=h),h}if(I){let e=o.name===`*`?`Unknown component: ${n.attrs.componentName} — source editable below`:`${o.displayName??o.name} — render error, source editable below`,r;t[41]===e?r=t[42]:(r=(0,q.jsx)(`div`,{className:`text-xs font-mono text-muted-foreground px-2 py-1`,contentEditable:!1,children:e}),t[41]=e,t[42]=r);let i;t[43]===Symbol.for(`react.memo_cache_sentinel`)?(i=(0,q.jsx)(Ha,{className:`component-children`}),t[43]=i):i=t[43];let a;return t[44]===r?a=t[45]:(a=(0,q.jsxs)(Ua,{className:`jsx-component-wrapper my-2`,children:[r,i]}),t[44]=r,t[45]=a),a}let te=o.Component,ne;t[46]!==r||t[47]!==A||t[48]!==f||t[49]!==O?(ne=e=>{if(O||!A)return;let t=e.target;if(!e.currentTarget.contains(t)||t.closest(`.jsx-component-chrome`)||t.closest(`.jsx-add-child-pill, .jsx-empty-child-placeholder`)||typeof f!=`number`)return;let n=r.state.doc.nodeAt(f);if(!n)return;let i=f+n.nodeSize,a=r.state.selection.from;a<f||a>=i||r.chain().focus().setNodeSelection(f).run()},t[46]=r,t[47]=A,t[48]=f,t[49]=O,t[50]=ne):ne=t[50];let re=ne,W;t[51]!==r||t[52]!==i||t[53]!==u?(W=()=>{let e=typeof i==`function`?i():void 0;typeof e==`number`&&(r.chain().focus().setNodeSelection(e).run(),u(!0))},t[51]=r,t[52]=i,t[53]=u,t[54]=W):W=t[54];let ie=W,ae=o.displayName??o.name,oe=!!o.emptyChildName,se;t[55]!==ae||t[56]!==o.emptyChildName||t[57]!==oe||t[58]!==n.childCount?(se=oe?kw(ae,o.emptyChildName,n.childCount):void 0,t[55]=ae,t[56]=o.emptyChildName,t[57]=oe,t[58]=n.childCount,t[59]=se):se=t[59];let ce=se,le;t[60]!==T||t[61]!==a||t[62]!==u?(le=e=>{if(e.key!==`Enter`&&e.key!==` `||!a||!T)return;let t=e.target;t.closest(`.jsx-component-chrome`)||t.closest(`input, textarea, select, button`)||(e.preventDefault(),u(!0))},t[60]=T,t[61]=a,t[62]=u,t[63]=le):le=t[63];let ue=le,fe;t[64]!==r||t[65]!==i||t[66]!==A||t[67]!==u?(fe=e=>{u(e),!e&&A&&requestAnimationFrame(()=>{let e=typeof i==`function`?i():void 0;if(typeof e!=`number`)return;let t=r.state.doc.nodeAt(e);if(!t)return;let n=e+t.nodeSize,a=r.state.selection.from;if(a<e||a>=n)return;let o=r.state.doc.resolve(Math.min(n,r.state.doc.content.size)),s=Je.near(o,1);r.view.dispatch(r.state.tr.setSelection(s).scrollIntoView())})},t[64]=r,t[65]=i,t[66]=A,t[67]=u,t[68]=fe):fe=t[68];let pe=fe,me;t[69]===o.name?me=t[70]:(me=o.name.toLowerCase(),t[69]=o.name,t[70]=me);let he=x?`true`:void 0,ge=S?`true`:void 0,_e=w?`true`:void 0,ve=D?`true`:void 0,ye=oe?`group`:void 0,be=x?0:-1,xe;t[71]===p?xe=t[72]:(xe=p?{draggable:`false`,onDragStart:LT}:{"data-drag-handle":``,draggable:`true`},t[71]=p,t[72]=xe);let Se;t[73]!==g||t[74]!==o.name||t[75]!==r||t[76]!==n.attrs.componentName||t[77]!==n.nodeSize||t[78]!==f?(Se=g&&(0,q.jsx)(`button`,{type:`button`,className:`jsx-chrome-btn`,"aria-label":`Move up`,onClick:()=>{try{if(typeof f!=`number`)return;let e=r.state.doc.resolve(f),t=e.index(e.depth);if(t===0)return;let i=f-e.node(e.depth).child(t-1).nodeSize,a=f+n.nodeSize,o=r.state.tr,s=r.state.doc.slice(f,f+n.nodeSize),c=r.state.doc.slice(i,f);o.replaceWith(i,a,s.content.append(c.content)),r.view.dispatch(o.scrollIntoView())}catch(e){let t=e;if(!(t instanceof RangeError))throw t;V(`up`),console.warn(JSON.stringify({event:`jsx-component-move-failed`,direction:`up`,component:o.name,rawComponentName:String(n.attrs.componentName??``).slice(0,200),reason:t.message.slice(0,500)}))}},children:(0,q.jsx)(Ln,{size:12,"aria-hidden":`true`})}),t[73]=g,t[74]=o.name,t[75]=r,t[76]=n.attrs.componentName,t[77]=n.nodeSize,t[78]=f,t[79]=Se):Se=t[79];let Ce;t[80]!==_||t[81]!==o.name||t[82]!==r||t[83]!==n.attrs.componentName||t[84]!==n.nodeSize||t[85]!==f?(Ce=_&&(0,q.jsx)(`button`,{type:`button`,className:`jsx-chrome-btn`,"aria-label":`Move down`,onClick:()=>{try{if(typeof f!=`number`)return;let e=r.state.doc.resolve(f),t=e.index(e.depth),i=e.node(e.depth);if(t>=i.childCount-1)return;let a=i.child(t+1),o=f,s=f+n.nodeSize+a.nodeSize,c=r.state.tr,l=r.state.doc.slice(f,f+n.nodeSize),u=r.state.doc.slice(f+n.nodeSize,s);c.replaceWith(o,s,u.content.append(l.content)),r.view.dispatch(c.scrollIntoView())}catch(e){let t=e;if(!(t instanceof RangeError))throw t;V(`down`),console.warn(JSON.stringify({event:`jsx-component-move-failed`,direction:`down`,component:o.name,rawComponentName:String(n.attrs.componentName??``).slice(0,200),reason:t.message.slice(0,500)}))}},children:(0,q.jsx)(In,{size:12,"aria-hidden":`true`})}),t[80]=_,t[81]=o.name,t[82]=r,t[83]=n.attrs.componentName,t[84]=n.nodeSize,t[85]=f,t[86]=Ce):Ce=t[86];let we=`Delete ${o.displayName??o.name}`,Te;t[87]!==r||t[88]!==f?(Te=()=>{typeof f==`number`&&r.chain().focus().setNodeSelection(f).deleteSelection().run()},t[87]=r,t[88]=f,t[89]=Te):Te=t[89];let Ee;t[90]===Symbol.for(`react.memo_cache_sentinel`)?(Ee=(0,q.jsx)(dr,{size:12,"aria-hidden":`true`}),t[90]=Ee):Ee=t[90];let De;t[91]!==we||t[92]!==Te?(De=(0,q.jsx)(`button`,{type:`button`,className:`jsx-chrome-btn jsx-chrome-btn--delete`,"aria-label":we,onClick:Te,children:Ee}),t[91]=we,t[92]=Te,t[93]=De):De=t[93];let Oe;t[94]!==o.displayName||t[95]!==o.name||t[96]!==T?(Oe=T&&(0,q.jsx)(gw,{asChild:!0,children:(0,q.jsx)(`button`,{type:`button`,className:`jsx-chrome-btn`,"aria-label":`${o.displayName??o.name} properties`,children:(0,q.jsx)(cr,{size:12,"aria-hidden":`true`})})}),t[94]=o.displayName,t[95]=o.name,t[96]=T,t[97]=Oe):Oe=t[97];let ke;t[98]!==Se||t[99]!==Ce||t[100]!==De||t[101]!==Oe?(ke=(0,q.jsxs)(`div`,{className:`jsx-component-chrome`,contentEditable:!1,onMouseDown:IT,children:[Se,Ce,De,Oe]}),t[98]=Se,t[99]=Ce,t[100]=De,t[101]=Oe,t[102]=ke):ke=t[102];let Ae;t[103]!==te||t[104]!==o.hasChildren||t[105]!==o.isSelfClosing||t[106]!==o.name||t[107]!==x||t[108]!==n.attrs.componentName||t[109]!==n.childCount||t[110]!==ie||t[111]!==M||t[112]!==N||t[113]!==k||t[114]!==c||t[115]!==O?(Ae=O&&k?(0,q.jsx)(vw,{asChild:!0,children:(0,q.jsx)(yw,{label:k.label,Icon:k.Icon,onClick:ie,selected:x})}):(0,q.jsx)(AT,{resetKey:N,onError:c,descriptorName:o.name===`*`?`wildcard`:o.name,rawComponentName:n.attrs.componentName??``,children:(0,q.jsx)(te,{...M,children:(0,q.jsx)(Ha,{className:`component-children ${!o.hasChildren&&n.childCount===0?`min-h-0 m-0 p-0`:``}`,...!o.hasChildren||o.isSelfClosing?{contentEditable:!1}:{}})})}),t[103]=te,t[104]=o.hasChildren,t[105]=o.isSelfClosing,t[106]=o.name,t[107]=x,t[108]=n.attrs.componentName,t[109]=n.childCount,t[110]=ie,t[111]=M,t[112]=N,t[113]=k,t[114]=c,t[115]=O,t[116]=Ae):Ae=t[116];let je;t[117]!==o.emptyChildName||t[118]!==r||t[119]!==F||t[120]!==n.childCount?(je=o.emptyChildName&&(0,q.jsx)(`button`,{type:`button`,contentEditable:!1,className:n.childCount===0?`jsx-empty-child-placeholder`:`jsx-add-child-pill`,onMouseDown:FT,onClick:()=>{let e=o.emptyChildName,t=rx(e),n=F();r.chain().focus().insertContentAt(n,t).run(),sx(r,n,Yb(e))},children:(0,q.jsxs)(`span`,{children:[`+ Add `,o.emptyChildName]})}),t[117]=o.emptyChildName,t[118]=r,t[119]=F,t[120]=n.childCount,t[121]=je):je=t[121];let Me;t[122]!==o.name||t[123]!==ce||t[124]!==re||t[125]!==ue||t[126]!==C||t[127]!==me||t[128]!==he||t[129]!==ge||t[130]!==_e||t[131]!==ve||t[132]!==ye||t[133]!==be||t[134]!==xe||t[135]!==ke||t[136]!==Ae||t[137]!==je?(Me=(0,q.jsxs)(Ua,{className:`jsx-component-wrapper my-2`,"data-jsx-component":``,"data-component-type":me,"data-selected":he,"data-has-child-selected":ge,"data-selection-origin":C,"data-dragging":_e,"data-needs-config":ve,role:ye,"aria-label":ce,tabIndex:be,...xe,"data-component-name":o.name,onClick:re,onKeyDown:ue,children:[ke,Ae,je]}),t[122]=o.name,t[123]=ce,t[124]=re,t[125]=ue,t[126]=C,t[127]=me,t[128]=he,t[129]=ge,t[130]=_e,t[131]=ve,t[132]=ye,t[133]=be,t[134]=xe,t[135]=ke,t[136]=Ae,t[137]=je,t[138]=Me):Me=t[138];let Ne;t[139]!==o||t[140]!==r||t[141]!==i||t[142]!==T||t[143]!==A||t[144]!==j||t[145]!==O?(Ne=T&&(0,q.jsxs)(_w,{side:O?`bottom`:`right`,align:O?`center`:`start`,sideOffset:O?-4:8,className:`w-64 p-3 z-[60]`,onCloseAutoFocus:A?e=>{e.preventDefault(),r.view.focus()}:void 0,children:[(0,q.jsxs)(`div`,{className:`text-xs font-medium text-muted-foreground mb-2`,children:[o.displayName??o.name,` Properties`]}),(0,q.jsx)(Rw,{descriptor:o,values:j,onChange:(e,t)=>{let n=typeof i==`function`?i():void 0;if(typeof n!=`number`)return;let a=r.state.doc.nodeAt(n);if(!a||a.attrs.kind!==`element`)return;let o={...a.attrs.props??{}},s=Array.isArray(a.attrs.attributes)?a.attrs.attributes:[],c=s;t===void 0?(delete o[e],c=s.filter(t=>!(typeof t==`object`&&t&&t.type===`mdxJsxAttribute`&&t.name===e))):o[e]=t,r.view.dispatch(r.state.tr.setNodeMarkup(n,null,{...a.attrs,attributes:c,props:o,sourceDirty:!0}))}})]}),t[139]=o,t[140]=r,t[141]=i,t[142]=T,t[143]=A,t[144]=j,t[145]=O,t[146]=Ne):Ne=t[146];let Pe;return t[147]!==pe||t[148]!==l||t[149]!==Me||t[150]!==Ne?(Pe=(0,q.jsxs)(hw,{open:l,onOpenChange:pe,children:[Me,Ne]}),t[147]=pe,t[148]=l,t[149]=Me,t[150]=Ne,t[151]=Pe):Pe=t[151],Pe}function FT(e){return e.stopPropagation()}function IT(e){return e.stopPropagation()}function LT(e){return e.preventDefault()}function RT(e){return!(`hidden`in e&&e.hidden)&&e.type!==`reactnode`}var zT=A.extend({addNodeView(){return Za(PT)}});function BT(e){return e.editorView}function VT(e){if(!e.isDestroyed)return e.extensionManager.extensions.find(e=>e.name===`collaboration`)?.options?.document}function HT(e){return e?e.startsWith(`Unregistered component:`)?`info`:e.startsWith(`Render error in`)?`warn`:`error`:`error`}var UT={info:{wrapperClass:`border-muted-foreground/30 bg-muted/30`,badgeClass:`text-muted-foreground bg-muted`,label:`unknown`},warn:{wrapperClass:`border-amber-400/60 dark:border-amber-500/40 bg-amber-50/50 dark:bg-amber-900/10`,badgeClass:`text-amber-600 dark:text-amber-400 bg-amber-100 dark:bg-amber-900/30`,label:`render error`},error:{wrapperClass:`border-destructive/60 bg-destructive/5`,badgeClass:`text-destructive bg-destructive/10`,label:`parse error`}},WT=class e{static create(t,n,r,i,a){return new e(t,n,r,i+(i<<8)+t+(n<<4)|0,a,[],[])}constructor(e,t,n,r,i,a,o){this.type=e,this.value=t,this.from=n,this.hash=r,this.end=i,this.children=a,this.positions=o,this.hashProp=[[zt.contextHash,r]]}addChild(e,t){e.prop(zt.contextHash)!=this.hash&&(e=new Ut(e.type,e.children,e.positions,e.length,this.hashProp)),this.children.push(e),this.positions.push(t)}toTree(e,t=this.end){let n=this.children.length-1;return n>=0&&(t=Math.max(t,this.positions[n]+this.children[n].length+this.from)),new Ut(e.types[this.type],this.children,this.positions,t-this.from).balance({makeTree:(e,t,n)=>new Ut(Wt.none,e,t,n,this.hashProp)})}},Q;(function(e){e[e.Document=1]=`Document`,e[e.CodeBlock=2]=`CodeBlock`,e[e.FencedCode=3]=`FencedCode`,e[e.Blockquote=4]=`Blockquote`,e[e.HorizontalRule=5]=`HorizontalRule`,e[e.BulletList=6]=`BulletList`,e[e.OrderedList=7]=`OrderedList`,e[e.ListItem=8]=`ListItem`,e[e.ATXHeading1=9]=`ATXHeading1`,e[e.ATXHeading2=10]=`ATXHeading2`,e[e.ATXHeading3=11]=`ATXHeading3`,e[e.ATXHeading4=12]=`ATXHeading4`,e[e.ATXHeading5=13]=`ATXHeading5`,e[e.ATXHeading6=14]=`ATXHeading6`,e[e.SetextHeading1=15]=`SetextHeading1`,e[e.SetextHeading2=16]=`SetextHeading2`,e[e.HTMLBlock=17]=`HTMLBlock`,e[e.LinkReference=18]=`LinkReference`,e[e.Paragraph=19]=`Paragraph`,e[e.CommentBlock=20]=`CommentBlock`,e[e.ProcessingInstructionBlock=21]=`ProcessingInstructionBlock`,e[e.Escape=22]=`Escape`,e[e.Entity=23]=`Entity`,e[e.HardBreak=24]=`HardBreak`,e[e.Emphasis=25]=`Emphasis`,e[e.StrongEmphasis=26]=`StrongEmphasis`,e[e.Link=27]=`Link`,e[e.Image=28]=`Image`,e[e.InlineCode=29]=`InlineCode`,e[e.HTMLTag=30]=`HTMLTag`,e[e.Comment=31]=`Comment`,e[e.ProcessingInstruction=32]=`ProcessingInstruction`,e[e.Autolink=33]=`Autolink`,e[e.HeaderMark=34]=`HeaderMark`,e[e.QuoteMark=35]=`QuoteMark`,e[e.ListMark=36]=`ListMark`,e[e.LinkMark=37]=`LinkMark`,e[e.EmphasisMark=38]=`EmphasisMark`,e[e.CodeMark=39]=`CodeMark`,e[e.CodeText=40]=`CodeText`,e[e.CodeInfo=41]=`CodeInfo`,e[e.LinkTitle=42]=`LinkTitle`,e[e.LinkLabel=43]=`LinkLabel`,e[e.URL=44]=`URL`})(Q||={});var GT=class{constructor(e,t){this.start=e,this.content=t,this.marks=[],this.parsers=[]}},KT=class{constructor(){this.text=``,this.baseIndent=0,this.basePos=0,this.depth=0,this.markers=[],this.pos=0,this.indent=0,this.next=-1}forward(){this.basePos>this.pos&&this.forwardInner()}forwardInner(){let e=this.skipSpace(this.basePos);this.indent=this.countIndent(e,this.pos,this.indent),this.pos=e,this.next=e==this.text.length?-1:this.text.charCodeAt(e)}skipSpace(e){return XT(this.text,e)}reset(e){for(this.text=e,this.baseIndent=this.basePos=this.pos=this.indent=0,this.forwardInner(),this.depth=1;this.markers.length;)this.markers.pop()}moveBase(e){this.basePos=e,this.baseIndent=this.countIndent(e,this.pos,this.indent)}moveBaseColumn(e){this.baseIndent=e,this.basePos=this.findColumn(e)}addMarker(e){this.markers.push(e)}countIndent(e,t=0,n=0){for(let r=t;r<e;r++)n+=this.text.charCodeAt(r)==9?4-n%4:1;return n}findColumn(e){let t=0;for(let n=0;t<this.text.length&&n<e;t++)n+=this.text.charCodeAt(t)==9?4-n%4:1;return t}scrub(){if(!this.baseIndent)return this.text;let e=``;for(let t=0;t<this.basePos;t++)e+=` `;return e+this.text.slice(this.basePos)}};function qT(e,t,n){if(n.pos==n.text.length||e!=t.block&&n.indent>=t.stack[n.depth+1].value+n.baseIndent)return!0;if(n.indent>=n.baseIndent+4)return!1;let r=(e.type==Q.OrderedList?rE:nE)(n,t,!1);return r>0&&(e.type!=Q.BulletList||eE(n,t,!1)<0)&&n.text.charCodeAt(n.pos+r-1)==e.value}var JT={[Q.Blockquote](e,t,n){return n.next==62?(n.markers.push(jE(Q.QuoteMark,t.lineStart+n.pos,t.lineStart+n.pos+1)),n.moveBase(n.pos+(YT(n.text.charCodeAt(n.pos+1))?2:1)),e.end=t.lineStart+n.text.length,!0):!1},[Q.ListItem](e,t,n){return n.indent<n.baseIndent+e.value&&n.next>-1?!1:(n.moveBaseColumn(n.baseIndent+e.value),!0)},[Q.OrderedList]:qT,[Q.BulletList]:qT,[Q.Document](){return!0}};function YT(e){return e==32||e==9||e==10||e==13}function XT(e,t=0){for(;t<e.length&&YT(e.charCodeAt(t));)t++;return t}function ZT(e,t,n){for(;t>n&&YT(e.charCodeAt(t-1));)t--;return t}function QT(e){if(e.next!=96&&e.next!=126)return-1;let t=e.pos+1;for(;t<e.text.length&&e.text.charCodeAt(t)==e.next;)t++;if(t<e.pos+3)return-1;if(e.next==96){for(let n=t;n<e.text.length;n++)if(e.text.charCodeAt(n)==96)return-1}return t}function $T(e){return e.next==62?e.text.charCodeAt(e.pos+1)==32?2:1:-1}function eE(e,t,n){if(e.next!=42&&e.next!=45&&e.next!=95)return-1;let r=1;for(let t=e.pos+1;t<e.text.length;t++){let n=e.text.charCodeAt(t);if(n==e.next)r++;else if(!YT(n))return-1}return n&&e.next==45&&aE(e)>-1&&e.depth==t.stack.length&&t.parser.leafBlockParsers.indexOf(_E.SetextHeading)>-1||r<3?-1:1}function tE(e,t){for(let n=e.stack.length-1;n>=0;n--)if(e.stack[n].type==t)return!0;return!1}function nE(e,t,n){return(e.next==45||e.next==43||e.next==42)&&(e.pos==e.text.length-1||YT(e.text.charCodeAt(e.pos+1)))&&(!n||tE(t,Q.BulletList)||e.skipSpace(e.pos+2)<e.text.length)?1:-1}function rE(e,t,n){let r=e.pos,i=e.next;for(;i>=48&&i<=57;){if(r++,r==e.text.length)return-1;i=e.text.charCodeAt(r)}return r==e.pos||r>e.pos+9||i!=46&&i!=41||r<e.text.length-1&&!YT(e.text.charCodeAt(r+1))||n&&!tE(t,Q.OrderedList)&&(e.skipSpace(r+1)==e.text.length||r>e.pos+1||e.next!=49)?-1:r+1-e.pos}function iE(e){if(e.next!=35)return-1;let t=e.pos+1;for(;t<e.text.length&&e.text.charCodeAt(t)==35;)t++;if(t<e.text.length&&e.text.charCodeAt(t)!=32)return-1;let n=t-e.pos;return n>6?-1:n}function aE(e){if(e.next!=45&&e.next!=61||e.indent>=e.baseIndent+4)return-1;let t=e.pos+1;for(;t<e.text.length&&e.text.charCodeAt(t)==e.next;)t++;let n=t;for(;t<e.text.length&&YT(e.text.charCodeAt(t));)t++;return t==e.text.length?n:-1}var oE=/^[ \t]*$/,sE=/-->/,cE=/\?>/,lE=[[/^<(?:script|pre|style)(?:\s|>|$)/i,/<\/(?:script|pre|style)>/i],[/^\s*<!--/,sE],[/^\s*<\?/,cE],[/^\s*<![A-Z]/,/>/],[/^\s*<!\[CDATA\[/,/\]\]>/],[/^\s*<\/?(?:address|article|aside|base|basefont|blockquote|body|caption|center|col|colgroup|dd|details|dialog|dir|div|dl|dt|fieldset|figcaption|figure|footer|form|frame|frameset|h1|h2|h3|h4|h5|h6|head|header|hr|html|iframe|legend|li|link|main|menu|menuitem|nav|noframes|ol|optgroup|option|p|param|section|source|summary|table|tbody|td|tfoot|th|thead|title|tr|track|ul)(?:\s|\/?>|$)/i,oE],[/^\s*(?:<\/[a-z][\w-]*\s*>|<[a-z][\w-]*(\s+[a-z:_][\w-.]*(?:\s*=\s*(?:[^\s"'=<>`]+|'[^']*'|"[^"]*"))?)*\s*>)\s*$/i,oE]];function uE(e,t,n){if(e.next!=60)return-1;let r=e.text.slice(e.pos);for(let e=0,t=lE.length-+!!n;e<t;e++)if(lE[e][0].test(r))return e;return-1}function dE(e,t){let n=e.countIndent(t,e.pos,e.indent),r=e.countIndent(e.skipSpace(t),t,n);return r>=n+5?n+1:r}function fE(e,t,n){let r=e.length-1;r>=0&&e[r].to==t&&e[r].type==Q.CodeText?e[r].to=n:e.push(jE(Q.CodeText,t,n))}var pE={LinkReference:void 0,IndentedCode(e,t){let n=t.baseIndent+4;if(t.indent<n)return!1;let r=t.findColumn(n),i=e.lineStart+r,a=e.lineStart+t.text.length,o=[],s=[];for(fE(o,i,a);e.nextLine()&&t.depth>=e.stack.length;)if(t.pos==t.text.length){fE(s,e.lineStart-1,e.lineStart);for(let e of t.markers)s.push(e)}else if(t.indent<n)break;else{if(s.length){for(let e of s)e.type==Q.CodeText?fE(o,e.from,e.to):o.push(e);s=[]}fE(o,e.lineStart-1,e.lineStart);for(let e of t.markers)o.push(e);a=e.lineStart+t.text.length;let n=e.lineStart+t.findColumn(t.baseIndent+4);n<a&&fE(o,n,a)}return s.length&&(s=s.filter(e=>e.type!=Q.CodeText),s.length&&(t.markers=s.concat(t.markers))),e.addNode(e.buffer.writeElements(o,-i).finish(Q.CodeBlock,a-i),i),!0},FencedCode(e,t){let n=QT(t);if(n<0)return!1;let r=e.lineStart+t.pos,i=t.next,a=n-t.pos,o=t.skipSpace(n),s=ZT(t.text,t.text.length,o),c=[jE(Q.CodeMark,r,r+a)];o<s&&c.push(jE(Q.CodeInfo,e.lineStart+o,e.lineStart+s));for(let n=!0,r=!0,o=!1;e.nextLine()&&t.depth>=e.stack.length;n=!1){let s=t.pos;if(t.indent-t.baseIndent<4)for(;s<t.text.length&&t.text.charCodeAt(s)==i;)s++;if(s-t.pos>=a&&t.skipSpace(s)==t.text.length){for(let e of t.markers)c.push(e);r&&o&&fE(c,e.lineStart-1,e.lineStart),c.push(jE(Q.CodeMark,e.lineStart+t.pos,e.lineStart+s)),e.nextLine();break}else{o=!0,n||(fE(c,e.lineStart-1,e.lineStart),r=!1);for(let e of t.markers)c.push(e);let i=e.lineStart+t.basePos,a=e.lineStart+t.text.length;i<a&&(fE(c,i,a),r=!1)}}return e.addNode(e.buffer.writeElements(c,-r).finish(Q.FencedCode,e.prevLineEnd()-r),r),!0},Blockquote(e,t){let n=$T(t);return n<0?!1:(e.startContext(Q.Blockquote,t.pos),e.addNode(Q.QuoteMark,e.lineStart+t.pos,e.lineStart+t.pos+1),t.moveBase(t.pos+n),null)},HorizontalRule(e,t){if(eE(t,e,!1)<0)return!1;let n=e.lineStart+t.pos;return e.nextLine(),e.addNode(Q.HorizontalRule,n),!0},BulletList(e,t){let n=nE(t,e,!1);if(n<0)return!1;e.block.type!=Q.BulletList&&e.startContext(Q.BulletList,t.basePos,t.next);let r=dE(t,t.pos+1);return e.startContext(Q.ListItem,t.basePos,r-t.baseIndent),e.addNode(Q.ListMark,e.lineStart+t.pos,e.lineStart+t.pos+n),t.moveBaseColumn(r),null},OrderedList(e,t){let n=rE(t,e,!1);if(n<0)return!1;e.block.type!=Q.OrderedList&&e.startContext(Q.OrderedList,t.basePos,t.text.charCodeAt(t.pos+n-1));let r=dE(t,t.pos+n);return e.startContext(Q.ListItem,t.basePos,r-t.baseIndent),e.addNode(Q.ListMark,e.lineStart+t.pos,e.lineStart+t.pos+n),t.moveBaseColumn(r),null},ATXHeading(e,t){let n=iE(t);if(n<0)return!1;let r=t.pos,i=e.lineStart+r,a=ZT(t.text,t.text.length,r),o=a;for(;o>r&&t.text.charCodeAt(o-1)==t.next;)o--;(o==a||o==r||!YT(t.text.charCodeAt(o-1)))&&(o=t.text.length);let s=e.buffer.write(Q.HeaderMark,0,n).writeElements(e.parser.parseInline(t.text.slice(r+n+1,o),i+n+1),-i);o<t.text.length&&s.write(Q.HeaderMark,o-r,a-r);let c=s.finish(Q.ATXHeading1-1+n,t.text.length-r);return e.nextLine(),e.addNode(c,i),!0},HTMLBlock(e,t){let n=uE(t,e,!1);if(n<0)return!1;let r=e.lineStart+t.pos,i=lE[n][1],a=[],o=i!=oE;for(;!i.test(t.text)&&e.nextLine();){if(t.depth<e.stack.length){o=!1;break}for(let e of t.markers)a.push(e)}o&&e.nextLine();let s=i==sE?Q.CommentBlock:i==cE?Q.ProcessingInstructionBlock:Q.HTMLBlock,c=e.prevLineEnd();return e.addNode(e.buffer.writeElements(a,-r).finish(s,c-r),r),!0},SetextHeading:void 0},mE=class{constructor(e){this.stage=0,this.elts=[],this.pos=0,this.start=e.start,this.advance(e.content)}nextLine(e,t,n){if(this.stage==-1)return!1;let r=n.content+`
8
8
  `+t.scrub(),i=this.advance(r);return i>-1&&i<r.length?this.complete(e,n,i):!1}finish(e,t){return(this.stage==2||this.stage==3)&&XT(t.content,this.pos)==t.content.length?this.complete(e,t,t.content.length):!1}complete(e,t,n){return e.addLeafElement(t,jE(Q.LinkReference,this.start,this.start+n,this.elts)),!0}nextStage(e){return e?(this.pos=e.to-this.start,this.elts.push(e),this.stage++,!0):(e===!1&&(this.stage=-1),!1)}advance(e){for(;;)if(this.stage==-1)return-1;else if(this.stage==0){if(!this.nextStage(UE(e,this.pos,this.start,!0)))return-1;if(e.charCodeAt(this.pos)!=58)return this.stage=-1;this.elts.push(jE(Q.LinkMark,this.pos+this.start,this.pos+this.start+1)),this.pos++}else if(this.stage==1){if(!this.nextStage(VE(e,XT(e,this.pos),this.start)))return-1}else if(this.stage==2){let t=XT(e,this.pos),n=0;if(t>this.pos){let r=HE(e,t,this.start);if(r){let t=hE(e,r.to-this.start);t>0&&(this.nextStage(r),n=t)}}return n||=hE(e,this.pos),n>0&&n<e.length?n:-1}else return hE(e,this.pos)}};function hE(e,t){for(;t<e.length;t++){let n=e.charCodeAt(t);if(n==10)break;if(!YT(n))return-1}return t}var gE=class{nextLine(e,t,n){let r=t.depth<e.stack.length?-1:aE(t),i=t.next;if(r<0)return!1;let a=jE(Q.HeaderMark,e.lineStart+t.pos,e.lineStart+r);return e.nextLine(),e.addLeafElement(n,jE(i==61?Q.SetextHeading1:Q.SetextHeading2,n.start,e.prevLineEnd(),[...e.parser.parseInline(n.content,n.start),a])),!0}finish(){return!1}},_E={LinkReference(e,t){return t.content.charCodeAt(0)==91?new mE(t):null},SetextHeading(){return new gE}},vE=[(e,t)=>iE(t)>=0,(e,t)=>QT(t)>=0,(e,t)=>$T(t)>=0,(e,t)=>nE(t,e,!0)>=0,(e,t)=>rE(t,e,!0)>=0,(e,t)=>eE(t,e,!0)>=0,(e,t)=>uE(t,e,!0)>=0],yE={text:``,end:0},bE=class{constructor(e,t,n,r){this.parser=e,this.input=t,this.ranges=r,this.line=new KT,this.atEnd=!1,this.reusePlaceholders=new Map,this.stoppedAt=null,this.rangeI=0,this.to=r[r.length-1].to,this.lineStart=this.absoluteLineStart=this.absoluteLineEnd=r[0].from,this.block=WT.create(Q.Document,0,this.lineStart,0,0),this.stack=[this.block],this.fragments=n.length?new qE(n,t):null,this.readLine()}get parsedPos(){return this.absoluteLineStart}advance(){if(this.stoppedAt!=null&&this.absoluteLineStart>this.stoppedAt)return this.finish();let{line:e}=this;for(;;){for(let t=0;;){let n=e.depth<this.stack.length?this.stack[this.stack.length-1]:null;for(;t<e.markers.length&&(!n||e.markers[t].from<n.end);){let n=e.markers[t++];this.addNode(n.type,n.from,n.to)}if(!n)break;this.finishContext()}if(e.pos<e.text.length)break;if(!this.nextLine())return this.finish()}if(this.fragments&&this.reuseFragment(e.basePos))return null;start:for(;;){for(let t of this.parser.blockParsers)if(t){let n=t(this,e);if(n!=0){if(n==1)return null;e.forward();continue start}}break}let t=new GT(this.lineStart+e.pos,e.text.slice(e.pos));for(let e of this.parser.leafBlockParsers)if(e){let n=e(this,t);n&&t.parsers.push(n)}lines:for(;this.nextLine()&&e.pos!=e.text.length;){if(e.indent<e.baseIndent+4){for(let n of this.parser.endLeafBlock)if(n(this,e,t))break lines}for(let n of t.parsers)if(n.nextLine(this,e,t))return null;t.content+=`
9
9
  `+e.scrub();for(let n of e.markers)t.marks.push(n)}return this.finishLeaf(t),null}stopAt(e){if(this.stoppedAt!=null&&this.stoppedAt<e)throw RangeError(`Can't move stoppedAt forward`);this.stoppedAt=e}reuseFragment(e){if(!this.fragments.moveTo(this.absoluteLineStart+e,this.absoluteLineStart)||!this.fragments.matches(this.block.hash))return!1;let t=this.fragments.takeNodes(this);return t?(this.absoluteLineStart+=t,this.lineStart=JE(this.absoluteLineStart,this.ranges),this.moveRangeI(),this.absoluteLineStart<this.to?(this.lineStart++,this.absoluteLineStart++,this.readLine()):(this.atEnd=!0,this.readLine()),!0):!1}get depth(){return this.stack.length}parentType(e=this.depth-1){return this.parser.nodeSet.types[this.stack[e].type]}nextLine(){return this.lineStart+=this.line.text.length,this.absoluteLineEnd>=this.to?(this.absoluteLineStart=this.absoluteLineEnd,this.atEnd=!0,this.readLine(),!1):(this.lineStart++,this.absoluteLineStart=this.absoluteLineEnd+1,this.moveRangeI(),this.readLine(),!0)}peekLine(){return this.scanLine(this.absoluteLineEnd+1).text}moveRangeI(){for(;this.rangeI<this.ranges.length-1&&this.absoluteLineStart>=this.ranges[this.rangeI].to;)this.rangeI++,this.absoluteLineStart=Math.max(this.absoluteLineStart,this.ranges[this.rangeI].from)}scanLine(e){let t=yE;if(t.end=e,e>=this.to)t.text=``;else if(t.text=this.lineChunkAt(e),t.end+=t.text.length,this.ranges.length>1){let e=this.absoluteLineStart,n=this.rangeI;for(;this.ranges[n].to<t.end;){n++;let r=this.ranges[n].from,i=this.lineChunkAt(r);t.end=r+i.length,t.text=t.text.slice(0,this.ranges[n-1].to-e)+i,e=t.end-t.text.length}}return t}readLine(){let{line:e}=this,{text:t,end:n}=this.scanLine(this.absoluteLineStart);for(this.absoluteLineEnd=n,e.reset(t);e.depth<this.stack.length;e.depth++){let t=this.stack[e.depth],n=this.parser.skipContextMarkup[t.type];if(!n)throw Error(`Unhandled block context `+Q[t.type]);let r=this.line.markers.length;if(!n(t,this,e)){this.line.markers.length>r&&(t.end=this.line.markers[this.line.markers.length-1].to),e.forward();break}e.forward()}}lineChunkAt(e){let t=this.input.chunk(e),n;if(this.input.lineChunks)n=t==`