@inkeep/open-knowledge 0.4.0-beta.16 → 0.4.0-beta.17

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 (32) hide show
  1. package/dist/assets/skills/open-knowledge/SKILL.md +1 -1
  2. package/dist/cli.mjs +5 -5
  3. package/dist/constants-lybG5gQZ.mjs +2 -0
  4. package/dist/{dist-6NbkHfCv.mjs → dist-D0H-ut9y.mjs} +1 -1
  5. package/dist/{dist-S85DS3Yx.mjs → dist-dNO-Udm_.mjs} +33 -22
  6. package/dist/index.mjs +1 -1
  7. package/dist/{init-CUdnzJpw.mjs → init-BO8sWy5q.mjs} +14 -3
  8. package/dist/init-Dlm__eWd.mjs +1 -0
  9. package/dist/{loader-DOpy4WUd.mjs → loader-fktLkWoO.mjs} +2 -2
  10. package/dist/loader-od_FoBBq.mjs +1 -0
  11. package/dist/preview-ByeyxmgX.mjs +1 -0
  12. package/dist/{preview-B1w6NlXO.mjs → preview-DOErzjxx.mjs} +2 -2
  13. package/dist/public/assets/{ActivityModeContent-BS-F_q5b.js → ActivityModeContent-WITVydyg.js} +1 -1
  14. package/dist/public/assets/{DocumentContext-CKgn09Wu.js → DocumentContext-FwLaR_pb.js} +2 -2
  15. package/dist/public/assets/{OutlinePanel-B1VwD6nb.js → OutlinePanel-DktI5hU_.js} +1 -1
  16. package/dist/public/assets/{SettingsPane-Byz_-VcF.js → SettingsPane-CEKKjs0_.js} +1 -1
  17. package/dist/public/assets/{SourceEditor-CF1C1jlS.js → SourceEditor-B7V3PE4E.js} +1 -1
  18. package/dist/public/assets/{config-validation-events-BX5T6Pv4.js → config-validation-events-ZEbhIRmP.js} +1 -1
  19. package/dist/public/assets/index-C-Lx_3XB.css +1 -0
  20. package/dist/public/assets/{index-CvOr_6Tp.js → index-uWtLvm2S.js} +4 -4
  21. package/dist/public/index.html +5 -5
  22. package/dist/src-Brc8KpdH.mjs +1 -0
  23. package/dist/start-H8MzEZdm.mjs +1 -0
  24. package/dist/{start-D6umc6Xl.mjs → start-jeIuSBq5.mjs} +2 -2
  25. package/package.json +1 -1
  26. package/dist/constants-E-JgnSlE.mjs +0 -2
  27. package/dist/init-CIC5YAj8.mjs +0 -1
  28. package/dist/loader-BFHJRanx.mjs +0 -1
  29. package/dist/preview-B4QANcNz.mjs +0 -1
  30. package/dist/public/assets/index-DFiz58v4.css +0 -1
  31. package/dist/src-Y_t6XEQE.mjs +0 -1
  32. package/dist/start-DbUs0oz5.mjs +0 -1
@@ -3,7 +3,7 @@ import{o as e,t}from"./chunk-CFjPhJqf.js";import{t as n}from"./preload-helper-2e
3
3
  `)}},sd=(e,t)=>e===t?!0:e==null||t==null||e.constructor!==t.constructor?!1:e[vu]?yu(e,t):jc(e)?Oc(e,e=>kc(t,t=>sd(e,t))):bu(e)?Eu(e,(e,n)=>sd(e,t[n])):!1,cd=class{static _dilutes=!1;extends(e){let[t,n]=[this.shape,e.shape];return this.constructor._dilutes&&([n,t]=[t,n]),sd(t,n)}equals(e){return this.constructor===e.constructor&&Nu(this.shape,e.shape)}[ad](){return!0}[vu](e){return this.equals(e)}validate(e){return this.check(e)}check(e,t){Vl()}get nullable(){return Vd(this,nf)}get optional(){return new yd(this)}cast(e){return sf(e,this),e}expect(e){return sf(e,this),e}},ld=class extends cd{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}},ud=(e,t=null)=>new ld(e,t);ud(ld);var dd=class extends cd{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}},fd=e=>new dd(e);ud(dd);var pd=class extends cd{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}},md=(...e)=>new pd(e),hd=ud(pd),gd=RegExp.escape||(e=>e.replace(/[().|&,$^[\]]/g,e=>`\\`+e)),_d=e=>{if(Zd.check(e))return[gd(e)];if(hd.check(e))return e.shape.map(e=>e+``);if(Xd.check(e))return[`[+-]?\\d+.?\\d*`];if(Qd.check(e))return[`.*`];if(Hd.check(e))return e.shape.map(_d).flat(1);Hl()};ud(class extends cd{constructor(e){super(),this.shape=e,this._r=RegExp(`^`+e.map(_d).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 vd=Symbol(`optional`),yd=class extends cd{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[vd](){return!0}},bd=ud(yd),xd=class extends cd{check(e,t){return t?.extend(null,`never`,typeof e),!1}};new xd,ud(xd);var Sd=class e extends cd{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):Eu(this.shape,(n,r)=>{let i=this._isPartial&&!Du(e,r)||n.check(e[r],t);return!i&&t?.extend(r.toString(),n.toString(),typeof e[r],`Object property does not match`),i})}},Cd=e=>new Sd(e),wd=ud(Sd),Td=fd(e=>e!=null&&(e.constructor===Object||e.constructor==null)),Ed=class extends cd{constructor(e,t){super(),this.shape={keys:e,values:t}}check(e,t){return e!=null&&Eu(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)})}},Dd=(e,t)=>new Ed(e,t),Od=ud(Ed),kd=class extends cd{constructor(e){super(),this.shape=e}check(e,t){return e!=null&&Eu(this.shape,(n,r)=>{let i=n.check(e[r],t);return!i&&t?.extend(r.toString(),`Tuple`,typeof n),i})}},Ad=(...e)=>new kd(e);ud(kd);var jd=class extends cd{constructor(e){super(),this.shape=e.length===1?e[0]:new Bd(e)}check(e,t){let n=jc(e)&&Oc(e,e=>this.shape.check(e));return!n&&t?.extend(null,`Array`,``),n}},Md=(...e)=>new jd(e),Nd=ud(jd),Pd=fd(e=>jc(e)),Fd=class extends cd{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}},Id=(e,t=null)=>new Fd(e,t);ud(Fd);var Ld=Id(cd),Rd=ud(class extends cd{constructor(e){super(),this.len=e.length-1,this.args=Ad(...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}}),zd=fd(e=>typeof e==`function`);ud(class extends cd{constructor(e){super(),this.shape=e}check(e,t){let n=Oc(this.shape,n=>n.check(e,t));return!n&&t?.extend(null,`Intersectinon`,typeof e),n}},e=>e.shape.length>0);var Bd=class extends cd{static _dilutes=!0;constructor(e){super(),this.shape=e}check(e,t){let n=kc(this.shape,n=>n.check(e,t));return t?.extend(null,`Union`,typeof e),n}},Vd=(...e)=>e.findIndex(e=>Hd.check(e))>=0?Vd(...e.map(e=>of(e)).map(e=>Hd.check(e)?e.shape:[e]).flat(1)):e.length===1?e[0]:new Bd(e),Hd=ud(Bd),Ud=()=>!0,Wd=fd(Ud),Gd=ud(dd,e=>e.shape===Ud),Kd=fd(e=>typeof e==`bigint`),qd=fd(e=>e===Kd),Jd=fd(e=>typeof e==`symbol`);fd(e=>e===Jd);var Yd=fd(e=>typeof e==`number`),Xd=fd(e=>e===Yd),Zd=fd(e=>typeof e==`string`),Qd=fd(e=>e===Zd),$d=fd(e=>typeof e==`boolean`),ef=fd(e=>e===$d),tf=md(void 0);ud(pd,e=>e.shape.length===1&&e.shape[0]===void 0),md(void 0);var nf=md(null),rf=ud(pd,e=>e.shape.length===1&&e.shape[0]===null);ud(Uint8Array),ud(ld,e=>e.shape===Uint8Array);var af=Vd(Yd,Zd,nf,tf,Kd,$d,Jd);(()=>{let e=Md(Wd),t=Dd(Zd,Wd),n=Vd(Yd,Zd,nf,$d,e,t);return e.shape=n,t.shape.values=n,n})();var of=e=>{if(Ld.check(e))return e;if(Td.check(e)){let t={};for(let n in e)t[n]=of(e[n]);return Cd(t)}else if(Pd.check(e))return Vd(...e.map(of));else if(af.check(e))return md(e);else if(zd.check(e))return ud(e);Hl()},sf=Uu?()=>{}:(e,t)=>{let n=new od;if(!t.check(e,n))throw Bl(`Expected value to be of type ${t.constructor.name}.\n${n.toString()}`)},cf=class{constructor(e){this.patterns=[],this.$state=e}if(e,t){return this.patterns.push({if:of(e),h:t}),this}else(e){return this.if(Wd,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 Bl(`Unhandled pattern`)}}},lf=(e=>new cf(e))(Wd).if(Xd,(e,t)=>$u(t,$c,Qc)).if(Qd,(e,t)=>rd(t)).if(ef,(e,t)=>Qu(t)).if(qd,(e,t)=>BigInt($u(t,$c,Qc))).if(Hd,(e,t)=>uf(t,id(t,e.shape))).if(wd,(e,t)=>{let n={};for(let r in e.shape){let i=e.shape[r];if(bd.check(i)){if(Qu(t))continue;i=i.shape}n[r]=lf(i,t)}return n}).if(Nd,(e,t)=>{let n=[],r=ed(t,0,42);for(let i=0;i<r;i++)n.push(uf(t,e.shape));return n}).if(hd,(e,t)=>id(t,e.shape)).if(rf,(e,t)=>null).if(Rd,(e,t)=>{let n=uf(t,e.res);return()=>n}).if(Gd,(e,t)=>uf(t,id(t,[Yd,Zd,nf,tf,Kd,$d,Md(Yd),Dd(Vd(`a`,`b`,`c`),Yd)]))).if(Od,(e,t)=>{let n={},r=$u(t,0,3);for(let i=0;i<r;i++){let r=uf(t,e.shape.keys);n[r]=uf(t,e.shape.values)}return n}).done(),uf=(e,t)=>lf(of(t),e),df=typeof document<`u`?document:{},ff=e=>df.createElement(e),pf=()=>df.createDocumentFragment();fd(e=>e.nodeType===Tf);var mf=e=>df.createTextNode(e);typeof DOMParser<`u`&&new DOMParser;var hf=(e,t)=>(Zu(t,(t,n)=>{n===!1?e.removeAttribute(t):n===!0?e.setAttribute(t,``):e.setAttribute(t,n)}),e),gf=e=>{let t=pf();for(let n=0;n<e.length;n++)xf(t,e[n]);return t},_f=(e,t)=>(xf(e,gf(t)),e),vf=(e,t=[],n=[])=>_f(hf(ff(e),t),n);fd(e=>e.nodeType===Sf);var yf=mf;fd(e=>e.nodeType===Cf);var bf=e=>Sc(e,(e,t)=>`${t}:${e};`).join(``),xf=(e,t)=>e.appendChild(t),Sf=df.ELEMENT_NODE,Cf=df.TEXT_NODE;df.CDATA_SECTION_NODE,df.COMMENT_NODE;var wf=df.DOCUMENT_NODE;df.DOCUMENT_TYPE_NODE;var Tf=df.DOCUMENT_FRAGMENT_NODE;fd(e=>e.nodeType===wf);var Ef=(e=>class{constructor(e){this._=e}destroy(){e(this._)}})(clearTimeout),Df=(e,t)=>new Ef(setTimeout(t,e)),Of=Symbol,kf=Of(),Af=Of(),jf=Of(),Mf=Of(),Nf=Of(),Pf=Of(),Ff=Of(),If=Of(),Lf=Of(),Rf=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};pu();var zf={[kf]:Xu(`font-weight`,`bold`),[Af]:Xu(`font-weight`,`normal`),[jf]:Xu(`color`,`blue`),[Nf]:Xu(`color`,`green`),[Mf]:Xu(`color`,`grey`),[Pf]:Xu(`color`,`red`),[Ff]:Xu(`color`,`purple`),[If]:Xu(`color`,`orange`),[Lf]:Xu(`color`,`black`)},Bf=Wu?e=>{e.length===1&&e[0]?.constructor===Function&&(e=e[0]());let t=[],n=[],r=yc(),i=[],a=0;for(;a<e.length;a++){let i=e[a],o=zf[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=bf(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}:Rf,Vf=(...e)=>{console.log(...Bf(e)),Uf.forEach(t=>t.print(e))},Hf=(...e)=>{console.warn(...Bf(e)),e.unshift(If),Uf.forEach(t=>t.print(e))},Uf=wc(),Wf=e=>({[Symbol.iterator](){return this},next:e}),Gf=(e,t)=>Wf(()=>{let n;do n=e.next();while(!n.done&&!t(n.value));return n}),Kf=(e,t)=>Wf(()=>{let{done:n,value:r}=e.next();return{done:n,value:n?void 0:t(r)}}),qf=class{constructor(e,t){this.clock=e,this.len=t}},Jf=class{constructor(){this.clients=new Map}},Yf=(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])pm(e,i,o.clock,o.len,n)}}),Xf=(e,t)=>{let n=0,r=e.length-1;for(;n<=r;){let i=Pc((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},Zf=(e,t)=>{let n=e.clients.get(t.client);return n!==void 0&&Xf(n,t.clock)!==null},Qf=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 qf(r.clock,Lc(r.len,i.clock+i.len-r.clock)):(n<t&&(e[n]=i),n++)}e.length=n})},$f=e=>{let t=new Jf;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++)Ec(a,e[t].clients.get(i)||[]);t.clients.set(i,a)}});return Qf(t),t},ep=(e,t,n,r)=>{xc(e.clients,t,()=>[]).push(new qf(n,r))},tp=()=>new Jf,np=e=>{let t=tp();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 qf(i,a))}}r.length>0&&t.clients.set(n,r)}),t},rp=(e,t)=>{bl(e.restEncoder,t.clients.size),Dc(t.clients.entries()).sort((e,t)=>t[0]-e[0]).forEach(([t,n])=>{e.resetDsCurVal(),bl(e.restEncoder,t);let r=n.length;bl(e.restEncoder,r);for(let t=0;t<r;t++){let r=n[t];e.writeDsClock(r.clock),e.writeDsLen(r.len)}})},ip=e=>{let t=new Jf,n=Zl(e.restDecoder);for(let r=0;r<n;r++){e.resetDsCurVal();let n=Zl(e.restDecoder),r=Zl(e.restDecoder);if(r>0){let i=xc(t.clients,n,()=>[]);for(let t=0;t<r;t++)i.push(new qf(e.readDsClock(),e.readDsLen()))}}return t},ap=(e,t,n)=>{let r=new Jf,i=Zl(e.restDecoder);for(let a=0;a<i;a++){e.resetDsCurVal();let i=Zl(e.restDecoder),a=Zl(e.restDecoder),o=n.clients.get(i)||[],s=am(n,i);for(let n=0;n<a;n++){let n=e.readDsClock(),a=n+e.readDsLen();if(n<s){s<a&&ep(r,i,s,a-s);let e=sm(o,n),c=o[e];for(!c.deleted&&c.id.clock<n&&(o.splice(e+1,0,Ag(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,Ag(t,c,a-c.id.clock)),c.delete(t))}else ep(r,i,n,a-n)}}if(r.clients.size>0){let e=new hp;return bl(e.restEncoder,0),rp(e,r),e.toUint8Array()}return null},op=lu,sp=class e extends Mc{constructor({guid:e=fu(),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=op(),this.guid=e,this.collectionid=t,this.share=new Map,this.store=new rm,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=mu(e=>{this.on(`load`,()=>{this.isLoaded=!0,e(this)})});let s=()=>mu(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&&xm(e.parent.doc,e=>{e.subdocsLoaded.add(this)},null,!0),this.shouldLoad=!0}getSubdocs(){return this.subdocs}getSubdocGuids(){return new Set(Dc(this.subdocs).map(e=>e.guid))}transact(e,t=null){return xm(this,e,t)}get(e,t=Zm){let n=xc(this.share,e,()=>{let e=new t;return e._integrate(this,null),e}),r=n.constructor;if(t!==Zm&&r!==t)if(r===Zm){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,vh)}getText(e=``){return this.get(e,zh)}getMap(e=``){return this.get(e,xh)}getXmlElement(e=``){return this.get(e,Wh)}getXmlFragment(e=``){return this.get(e,Hh)}toJSON(){let e={};return this.share.forEach((t,n)=>{e[n]=t.toJSON()}),e}destroy(){this.isDestroyed=!0,Dc(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,xm(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()}},cp=class{constructor(e){this.restDecoder=e}resetDsCurVal(){}readDsClock(){return Zl(this.restDecoder)}readDsLen(){return Zl(this.restDecoder)}},lp=class extends cp{readLeftID(){return Z(Zl(this.restDecoder),Zl(this.restDecoder))}readRightID(){return Z(Zl(this.restDecoder),Zl(this.restDecoder))}readClient(){return Zl(this.restDecoder)}readInfo(){return Xl(this.restDecoder)}readString(){return $l(this.restDecoder)}readParentInfo(){return Zl(this.restDecoder)===1}readTypeRef(){return Zl(this.restDecoder)}readLen(){return Zl(this.restDecoder)}readAny(){return nu(this.restDecoder)}readBuf(){return qu(Yl(this.restDecoder))}readJSON(){return JSON.parse($l(this.restDecoder))}readKey(){return $l(this.restDecoder)}},up=class{constructor(e){this.dsCurrVal=0,this.restDecoder=e}resetDsCurVal(){this.dsCurrVal=0}readDsClock(){return this.dsCurrVal+=Zl(this.restDecoder),this.dsCurrVal}readDsLen(){let e=Zl(this.restDecoder)+1;return this.dsCurrVal+=e,e}},dp=class extends up{constructor(e){super(e),this.keys=[],Zl(e),this.keyClockDecoder=new au(Yl(e)),this.clientDecoder=new iu(Yl(e)),this.leftClockDecoder=new au(Yl(e)),this.rightClockDecoder=new au(Yl(e)),this.infoDecoder=new ru(Yl(e),Xl),this.stringDecoder=new ou(Yl(e)),this.parentInfoDecoder=new ru(Yl(e),Xl),this.typeRefDecoder=new iu(Yl(e)),this.lenDecoder=new iu(Yl(e))}readLeftID(){return new Rp(this.clientDecoder.read(),this.leftClockDecoder.read())}readRightID(){return new Rp(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 nu(this.restDecoder)}readBuf(){return Yl(this.restDecoder)}readJSON(){return nu(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}}},fp=class{constructor(){this.restEncoder=pl()}toUint8Array(){return gl(this.restEncoder)}resetDsCurVal(){}writeDsClock(e){bl(this.restEncoder,e)}writeDsLen(e){bl(this.restEncoder,e)}},pp=class extends fp{writeLeftID(e){bl(this.restEncoder,e.client),bl(this.restEncoder,e.clock)}writeRightID(e){bl(this.restEncoder,e.client),bl(this.restEncoder,e.clock)}writeClient(e){bl(this.restEncoder,e)}writeInfo(e){yl(this.restEncoder,e)}writeString(e){wl(this.restEncoder,e)}writeParentInfo(e){bl(this.restEncoder,+!!e)}writeTypeRef(e){bl(this.restEncoder,e)}writeLen(e){bl(this.restEncoder,e)}writeAny(e){Nl(this.restEncoder,e)}writeBuf(e){El(this.restEncoder,e)}writeJSON(e){wl(this.restEncoder,JSON.stringify(e))}writeKey(e){wl(this.restEncoder,e)}},mp=class{constructor(){this.restEncoder=pl(),this.dsCurrVal=0}toUint8Array(){return gl(this.restEncoder)}resetDsCurVal(){this.dsCurrVal=0}writeDsClock(e){let t=e-this.dsCurrVal;this.dsCurrVal=e,bl(this.restEncoder,t)}writeDsLen(e){e===0&&Hl(),bl(this.restEncoder,e-1),this.dsCurrVal+=e}},hp=class extends mp{constructor(){super(),this.keyMap=new Map,this.keyClock=0,this.keyClockEncoder=new Rl,this.clientEncoder=new Il,this.leftClockEncoder=new Rl,this.rightClockEncoder=new Rl,this.infoEncoder=new Pl(yl),this.stringEncoder=new zl,this.parentInfoEncoder=new Pl(yl),this.typeRefEncoder=new Il,this.lenEncoder=new Il}toUint8Array(){let e=pl();return bl(e,0),El(e,this.keyClockEncoder.toUint8Array()),El(e,this.clientEncoder.toUint8Array()),El(e,this.leftClockEncoder.toUint8Array()),El(e,this.rightClockEncoder.toUint8Array()),El(e,gl(this.infoEncoder)),El(e,this.stringEncoder.toUint8Array()),El(e,gl(this.parentInfoEncoder)),El(e,this.typeRefEncoder.toUint8Array()),El(e,this.lenEncoder.toUint8Array()),Tl(e,gl(this.restEncoder)),gl(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){Nl(this.restEncoder,e)}writeBuf(e){El(this.restEncoder,e)}writeJSON(e){Nl(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)}},gp=(e,t,n,r)=>{r=Lc(r,t[0].id.clock);let i=sm(t,r);bl(e.restEncoder,t.length-i),e.writeClient(n),bl(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)},_p=(e,t,n)=>{let r=new Map;n.forEach((e,n)=>{am(t,n)>e&&r.set(n,e)}),im(t).forEach((e,t)=>{n.has(t)||r.set(t,0)}),bl(e.restEncoder,r.size),Dc(r.entries()).sort((e,t)=>t[0]-e[0]).forEach(([n,r])=>{gp(e,t.clients.get(n),n,r)})},vp=(e,t)=>{let n=yc(),r=Zl(e.restDecoder);for(let i=0;i<r;i++){let r=Zl(e.restDecoder),i=Array(r),a=e.readClient(),o=Zl(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 $h(Z(a,o),t),o+=t;break}case 10:{let t=Zl(e.restDecoder);i[n]=new Lg(Z(a,o),t),o+=t;break}default:{let s=(r&192)==0,c=new Ng(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,Pg(e,r));i[n]=c,o+=c.length}}}}return n},yp=(e,t,n)=>{let r=[],i=Dc(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 rm,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!==Lg){let i=xc(d,u.id.client,()=>am(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,am(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 hp;return _p(e,s,new Map),bl(e.restEncoder,0),{missing:c,update:e.toUint8Array()}}return null},bp=(e,t)=>_p(e,t.doc.store,t.beforeState),xp=(e,t,n,r=new dp(e))=>xm(t,e=>{e.local=!1;let t=!1,n=e.doc,i=n.store,a=yp(e,i,vp(r,n)),o=i.pendingStructs;if(o){for(let[e,n]of o.missing)if(n<am(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=jm([o.update,a.update])}}else i.pendingStructs=a;let s=ap(r,e,i);if(i.pendingDs){let t=new dp(Kl(i.pendingDs));Zl(t.restDecoder);let n=ap(t,e,i);s&&n?i.pendingDs=jm([s,n]):i.pendingDs=s||n}else i.pendingDs=s;if(t){let t=i.pendingStructs.update;i.pendingStructs=null,Sp(e.doc,t)}},n,!1),Sp=(e,t,n,r=dp)=>{let i=Kl(t);xp(i,e,n,new r(i))},Cp=(e,t,n)=>Sp(e,t,n,lp),wp=(e,t,n=new Map)=>{_p(e,t.store,n),rp(e,np(t.store))},Tp=(e,t=new Uint8Array([0]),n=new hp)=>{wp(n,e,Op(t));let r=[n.toUint8Array()];if(e.store.pendingDs&&r.push(e.store.pendingDs),e.store.pendingStructs&&r.push(Mm(e.store.pendingStructs.update,t)),r.length>1){if(n.constructor===pp)return km(r.map((e,t)=>t===0?e:Lm(e)));if(n.constructor===hp)return jm(r)}return r[0]},Ep=(e,t)=>Tp(e,t,new pp),Dp=e=>{let t=new Map,n=Zl(e.restDecoder);for(let r=0;r<n;r++){let n=Zl(e.restDecoder),r=Zl(e.restDecoder);t.set(n,r)}return t},Op=e=>Dp(new cp(Kl(e))),kp=(e,t)=>(bl(e.restEncoder,t.size),Dc(t.entries()).sort((e,t)=>t[0]-e[0]).forEach(([t,n])=>{bl(e.restEncoder,t),bl(e.restEncoder,n)}),e),Ap=(e,t)=>kp(e,im(t.store)),jp=(e,t=new mp)=>(e instanceof Map?kp(t,e):Ap(t,e),t.toUint8Array()),Mp=e=>jp(e,new fp),Np=class{constructor(){this.l=[]}},Pp=()=>new Np,Fp=(e,t)=>e.l.push(t),Ip=(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.`)},Lp=(e,t,n)=>ju(e.l,[t,n]),Rp=class{constructor(e,t){this.client=e,this.clock=t}},zp=(e,t)=>e===t||e!==null&&t!==null&&e.client===t.client&&e.clock===t.clock,Z=(e,t)=>new Rp(e,t),Bp=e=>{for(let[t,n]of e.doc.share.entries())if(n===e)return t;throw Hl()},Vp=(e,t)=>{for(;t!==null;){if(t.parent===e)return!0;t=t.parent._item}return!1},Hp=class{constructor(e,t,n,r=0){this.type=e,this.tname=t,this.item=n,this.assoc=r}},Up=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},Wp=e=>new Hp(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),Gp=class{constructor(e,t,n=0){this.type=e,this.index=t,this.assoc=n}},Kp=(e,t,n=0)=>new Gp(e,t,n),qp=(e,t,n)=>{let r=null,i=null;return e._item===null?i=Bp(e):r=Z(e._item.id.client,e._item.id.clock),new Hp(r,i,t,n)},Jp=(e,t,n=0)=>{let r=e._start;if(n<0){if(t===0)return qp(e,null,n);t--}for(;r!==null;){if(!r.deleted&&r.countable){if(r.length>t)return qp(e,Z(r.id.client,r.id.clock+t),n);t-=r.length}if(r.right===null&&n<0)return qp(e,r.lastId,n);r=r.right}return qp(e,null,n)},Yp=(e,t)=>{let n=cm(e,t);return{item:n,diff:t.clock-n.id.clock}},Xp=(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(am(r,i.client)<=i.clock)return null;let e=n?Og(r,i):Yp(r,i),t=e.item;if(!(t instanceof Ng))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(am(r,a.client)<=a.clock)return null;let{item:e}=n?Og(r,a):{item:cm(r,a)};if(e instanceof Ng&&e.content instanceof Eg)c=e.content.type;else return null}else throw Hl();l=s>=0?c._length:0}return Kp(c,l,e.assoc)},Zp=(e,t)=>e===t||e!==null&&t!==null&&e.tname===t.tname&&zp(e.item,t.item)&&zp(e.type,t.type)&&e.assoc===t.assoc,Qp=class{constructor(e,t){this.ds=e,this.sv=t}},$p=(e,t)=>new Qp(e,t);$p(tp(),new Map);var em=e=>$p(np(e.store),im(e.store)),tm=(e,t)=>t===void 0?!e.deleted:t.sv.has(e.id.client)&&(t.sv.get(e.id.client)||0)>e.id.clock&&!Zf(t.ds,e.id),nm=(e,t)=>{let n=xc(e.meta,nm,wc),r=e.doc.store;n.has(t)||(t.sv.forEach((t,n)=>{t<am(r,n)&&um(e,Z(n,t))}),Yf(e,t.ds,e=>{}),n.add(t))},rm=class{constructor(){this.clients=new Map,this.pendingStructs=null,this.pendingDs=null}},im=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},am=(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},om=(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 Hl()}n.push(t)},sm=(e,t)=>{let n=0,r=e.length-1,i=e[r],a=i.id.clock;if(a===t)return r;let o=Pc(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=Pc((n+r)/2)}throw Hl()},cm=(e,t)=>{let n=e.clients.get(t.client);return n[sm(n,t.clock)]},lm=(e,t,n)=>{let r=sm(t,n),i=t[r];return i.id.clock<n&&i instanceof Ng?(t.splice(r+1,0,Ag(e,i,n-i.id.clock)),r+1):r},um=(e,t)=>{let n=e.doc.store.clients.get(t.client);return n[lm(e,n,t.clock)]},dm=(e,t,n)=>{let r=t.clients.get(n.client),i=sm(r,n.clock),a=r[i];return n.clock!==a.id.clock+a.length-1&&a.constructor!==$h&&r.splice(i+1,0,Ag(e,a,n.clock-a.id.clock+1)),a},fm=(e,t,n)=>{let r=e.clients.get(t.id.client);r[sm(r,t.id.clock)]=n},pm=(e,t,n,r,i)=>{if(r===0)return;let a=n+r,o=lm(e,t,n),s;do s=t[o++],a<s.id.clock+s.length&&lm(e,t,a),i(s);while(o<t.length&&t[o].id.clock<a)},mm=class{constructor(e,t,n){this.doc=e,this.deleteSet=new Jf,this.beforeState=im(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}},hm=(e,t)=>t.deleteSet.clients.size===0&&!Cc(t.afterState,(e,n)=>t.beforeState.get(n)!==e)?!1:(Qf(t.deleteSet),bp(e,t),rp(e,t.deleteSet),!0),gm=(e,t,n)=>{let r=t._item;(r===null||r.id.clock<(e.beforeState.get(r.id.client)||0)&&!r.deleted)&&xc(e.changed,t,wc).add(n)},_m=(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 Ng&&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},vm=(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=sm(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 Ng&&i.deleted&&!i.keep&&n(i)&&i.gc(t,!1)}}}},ym=(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=Ic(r.length-1,1+sm(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+_m(r,e)}})},bm=(e,t)=>{if(t<e.length){let n=e[t],r=n.doc,i=r.store,a=n.deleteSet,o=n._mergeStructs;try{Qf(a),n.afterState=im(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(()=>{Lp(r._dEH,t,n)}))}),e.push(()=>r.emit(`afterTransaction`,[n,r])),e.push(()=>{n._needFormattingCleanup&&Ih(n)})}),ju(e,[])}finally{r.gc&&vm(a,i,r.gcFilter),ym(a,i),n.afterState.forEach((e,t)=>{let r=n.beforeState.get(t)||0;if(r!==e){let e=i.clients.get(t),n=Lc(sm(e,r),1);for(let t=e.length-1;t>=n;)t-=1+_m(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=sm(r,n);a+1<r.length&&_m(r,a+1)>1||a>0&&_m(r,a)}if(!n.local&&n.afterState.get(r.clientID)!==n.beforeState.get(r.clientID)&&(Vf(If,kf,`[yjs] `,Af,Pf,`Changed the client-id because another client seems to be using it.`),r.clientID=op()),r.emit(`afterTransactionCleanup`,[n,r]),r._observers.has(`update`)){let e=new pp;hm(e,n)&&r.emit(`update`,[e.toUint8Array(),n.origin,r,n])}if(r._observers.has(`updateV2`)){let e=new hp;hm(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])):bm(e,t+1)}}},xm=(e,t,n=null,r=!0)=>{let i=e._transactionCleanups,a=!1,o=null;e._transaction===null&&(a=!0,e._transaction=new mm(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&&bm(i,0)}}return o},Sm=class{constructor(e,t){this.insertions=t,this.deletions=e,this.meta=new Map}},Cm=(e,t,n)=>{Yf(e,n.deletions,n=>{n instanceof Ng&&t.scope.some(t=>t===e.doc||Vp(t,n))&&kg(n,!1)})},wm=(e,t,n)=>{let r=null,i=e.doc,a=e.scope;xm(i,n=>{for(;t.length>0&&e.currStackItem===null;){let r=i.store,o=t.pop(),s=new Set,c=[],l=!1;Yf(n,o.insertions,e=>{if(e instanceof Ng){if(e.redone!==null){let{item:t,diff:i}=Og(r,e.id);i>0&&(t=um(n,Z(t.id.client,t.id.clock+i))),e=t}!e.deleted&&a.some(t=>t===n.doc||Vp(t,e))&&c.push(e)}}),Yf(n,o.deletions,e=>{e instanceof Ng&&a.some(t=>t===n.doc||Vp(t,e))&&!Zf(o.insertions,e.id)&&s.add(e)}),s.forEach(t=>{l=Mg(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},Tm=class extends Mc{constructor(e,{captureTimeout:t=500,captureTransaction:n=e=>!0,deleteFilter:r=()=>!0,trackedOrigins:i=new Set([null]),ignoreRemoteMapChanges:a=!1,doc:o=jc(e)?e[0].doc:e instanceof sp?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 Jf;e.afterState.forEach((t,n)=>{let r=e.beforeState.get(n)||0,a=t-r;a>0&&ep(i,n,r,a)});let a=pu(),o=!1;if(this.lastChange>0&&a-this.lastChange<this.captureTimeout&&r.length>0&&!t&&!n){let t=r[r.length-1];t.deletions=$f([t.deletions,e.deleteSet]),t.insertions=$f([t.insertions,i])}else r.push(new Sm(e.deleteSet,i)),o=!0;!t&&!n&&(this.lastChange=a),Yf(e,e.deleteSet,t=>{t instanceof Ng&&this.scope.some(n=>n===e.doc||Vp(n,t))&&kg(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=jc(e)?e:[e],e.forEach(e=>{t.has(e)||(t.add(e),(e instanceof Zm?e.doc!==this.doc:e!==this.doc)&&Hf(`[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=>Cm(n,this,e)),this.undoStack=[]),t&&(this.redoStack.forEach(e=>Cm(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=wm(this,this.undoStack,`undo`)}finally{this.undoing=!1}return e}redo(){this.redoing=!0;let e;try{e=wm(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*Em(e){let t=Zl(e.restDecoder);for(let n=0;n<t;n++){let t=Zl(e.restDecoder),n=e.readClient(),r=Zl(e.restDecoder);for(let i=0;i<t;i++){let t=e.readInfo();if(t===10){let t=Zl(e.restDecoder);yield new Lg(Z(n,r),t),r+=t}else if(31&t){let i=(t&192)==0,a=new Ng(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,Pg(e,t));yield a,r+=a.length}else{let t=e.readLen();yield new $h(Z(n,r),t),r+=t}}}}var Dm=class{constructor(e,t){this.gen=Em(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===Lg);return this.curr}},Om=class{constructor(e){this.currClient=0,this.startClock=0,this.written=0,this.encoder=e,this.clientStructs=[]}},km=e=>jm(e,lp,pp),Am=(e,t)=>{if(e.constructor===$h){let{client:n,clock:r}=e.id;return new $h(Z(n,r+t),e.length-t)}else if(e.constructor===Lg){let{client:n,clock:r}=e.id;return new Lg(Z(n,r+t),e.length-t)}else{let n=e,{client:r,clock:i}=n.id;return new Ng(Z(r,i+t),null,Z(r,i+t-1),null,n.rightOrigin,n.parent,n.parentSub,n.content.splice(t))}},jm=(e,t=dp,n=hp)=>{if(e.length===1)return e[0];let r=e.map(e=>new t(Kl(e))),i=r.map(e=>new Dm(e,!0)),a=null,o=new n,s=new Om(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===Lg?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)Pm(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===Lg)a.struct.length=n.id.clock+n.length-a.struct.id.clock;else{Pm(s,a.struct,a.offset);let e=n.id.clock-a.struct.id.clock-a.struct.length;a={struct:new Lg(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===Lg?a.struct.length-=t:n=Am(n,t)),a.struct.mergeWith(n)||(Pm(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!==Lg;n=e.next())Pm(s,a.struct,a.offset),a={struct:n,offset:0}}return a!==null&&(Pm(s,a.struct,a.offset),a=null),Fm(s),rp(o,$f(r.map(e=>ip(e)))),o.toUint8Array()},Mm=(e,t,n=dp,r=hp)=>{let i=Op(t),a=new r,o=new Om(a),s=new n(Kl(e)),c=new Dm(s,!1);for(;c.curr;){let e=c.curr,t=e.id.client,n=i.get(t)||0;if(c.curr.constructor===Lg){c.next();continue}if(e.id.clock+e.length>n)for(Pm(o,e,Lc(n-e.id.clock,0)),c.next();c.curr&&c.curr.id.client===t;)Pm(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 Fm(o),rp(a,ip(s)),a.toUint8Array()},Nm=e=>{e.written>0&&(e.clientStructs.push({written:e.written,restEncoder:gl(e.encoder.restEncoder)}),e.encoder.restEncoder=pl(),e.written=0)},Pm=(e,t,n)=>{e.written>0&&e.currClient!==t.id.client&&Nm(e),e.written===0&&(e.currClient=t.id.client,e.encoder.writeClient(t.id.client),bl(e.encoder.restEncoder,t.id.clock+n)),t.write(e.encoder,n),e.written++},Fm=e=>{Nm(e);let t=e.encoder.restEncoder;bl(t,e.clientStructs.length);for(let n=0;n<e.clientStructs.length;n++){let r=e.clientStructs[n];bl(t,r.written),Tl(t,r.restEncoder)}},Im=(e,t,n,r)=>{let i=new n(Kl(e)),a=new Dm(i,!1),o=new r,s=new Om(o);for(let e=a.curr;e!==null;e=a.next())Pm(s,t(e),0);return Fm(s),rp(o,ip(i)),o.toUint8Array()},Lm=e=>Im(e,Mu,dp,pp),Rm=`You must not compute changes after the event-handler fired.`,zm=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||=Bm(this.currentTarget,this.target)}deletes(e){return Zf(this.transaction.deleteSet,e.id)}get keys(){if(this._keys===null){if(this.transaction.doc._transactionCleanups.length===0)throw Bl(Rm);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=Tc(e.content.getContent());else return;else e!==null&&this.deletes(e)?(i=`update`,a=Tc(e.content.getContent())):(i=`add`,a=void 0)}else if(this.deletes(r))i=`delete`,a=Tc(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 Bl(Rm);let t=this.target,n=wc(),r=wc(),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}},Bm=(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},Vm=()=>{Hf(`Invalid access: Add Yjs type to a document before reading data.`)},Hm=80,Um=0,Wm=class{constructor(e,t){e.marker=!0,this.p=e,this.index=t,this.timestamp=Um++}},Gm=e=>{e.timestamp=Um++},Km=(e,t,n)=>{e.p.marker=!1,e.p=t,t.marker=!0,e.index=n,e.timestamp=Um++},qm=(e,t,n)=>{if(e.length>=Hm){let r=e.reduce((e,t)=>e.timestamp<t.timestamp?e:t);return Km(r,t,n),r}else{let r=new Wm(t,n);return e.push(r),r}},Jm=(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)=>Fc(t-e.index)<Fc(t-n.index)?e:n),r=e._start,i=0;for(n!==null&&(r=n.p,i=n.index,Gm(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&&Fc(n.index-i)<r.parent.length/Hm?(Km(n,r,i),n):qm(e._searchMarker,r,i)},Ym=(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=Lc(t,i.index+n))}},Xm=(e,t,n)=>{let r=e,i=t.changedParentTypes;for(;xc(i,e,()=>[]).push(n),e._item!==null;)e=e._item.parent;Lp(r._eH,n,t)},Zm=class{constructor(){this._item=null,this._map=new Map,this._start=null,this.doc=null,this._length=0,this._eH=Pp(),this._dEH=Pp(),this._searchMarker=null}get parent(){return this._item?this._item.parent:null}_integrate(e,t){this.doc=e,this._item=t}_copy(){throw Vl()}clone(){throw Vl()}_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){Fp(this._eH,e)}observeDeep(e){Fp(this._dEH,e)}unobserve(e){Ip(this._eH,e)}unobserveDeep(e){Ip(this._dEH,e)}toJSON(){}},Qm=(e,t,n)=>{e.doc??Vm(),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},$m=e=>{e.doc??Vm();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},eh=(e,t)=>{let n=[],r=e._start;for(;r!==null;){if(r.countable&&tm(r,t)){let e=r.content.getContent();for(let t=0;t<e.length;t++)n.push(e[t])}r=r.right}return n},th=(e,t)=>{let n=0,r=e._start;for(e.doc??Vm();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}},nh=(e,t)=>{let n=[];return th(e,(r,i)=>{n.push(t(r,i,e))}),n},rh=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}}}},ih=(e,t)=>{e.doc??Vm();let n=Jm(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}},ah=(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 Ng(Z(o,am(s,o)),i,i&&i.lastId,c,c&&c.id,t,null,new mg(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 Ng(Z(o,am(s,o)),i,i&&i.lastId,c,c&&c.id,t,null,new eg(new Uint8Array(n))),i.integrate(e,0);break;case sp:i=new Ng(Z(o,am(s,o)),i,i&&i.lastId,c,c&&c.id,t,null,new ag(n)),i.integrate(e,0);break;default:if(n instanceof Zm)i=new Ng(Z(o,am(s,o)),i,i&&i.lastId,c,c&&c.id,t,null,new Eg(n)),i.integrate(e,0);else throw Error(`Unexpected content type in insert operation`)}}}),u()},oh=()=>Bl(`Length exceeded!`),sh=(e,t,n,r)=>{if(n>t._length)throw oh();if(n===0)return t._searchMarker&&Ym(t._searchMarker,n,r.length),ah(e,t,null,r);let i=n,a=Jm(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&&um(e,Z(o.id.client,o.id.clock+n));break}n-=o.length}return t._searchMarker&&Ym(t._searchMarker,i,r.length),ah(e,t,o,r)},ch=(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 ah(e,t,r,n)},lh=(e,t,n,r)=>{if(r===0)return;let i=n,a=r,o=Jm(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&&um(e,Z(s.id.client,s.id.clock+n)),n-=s.length);for(;r>0&&s!==null;)s.deleted||(r<s.length&&um(e,Z(s.id.client,s.id.clock+r)),s.delete(e),r-=s.length),s=s.right;if(r>0)throw oh();t._searchMarker&&Ym(t._searchMarker,i,-a+r)},uh=(e,t,n)=>{let r=t._map.get(n);r!==void 0&&r.delete(e)},dh=(e,t,n,r)=>{let i=t._map.get(n)||null,a=e.doc,o=a.clientID,s;if(r==null)s=new mg([r]);else switch(r.constructor){case Number:case Object:case Boolean:case Array:case String:case Date:case BigInt:s=new mg([r]);break;case Uint8Array:s=new eg(r);break;case sp:s=new ag(r);break;default:if(r instanceof Zm)s=new Eg(r);else throw Error(`Unexpected content type`)}new Ng(Z(o,am(a.store,o)),i,i&&i.lastId,null,null,t,n,s).integrate(e,0)},fh=(e,t)=>{e.doc??Vm();let n=e._map.get(t);return n!==void 0&&!n.deleted?n.content.getContent()[n.length-1]:void 0},ph=e=>{let t={};return e.doc??Vm(),e._map.forEach((e,n)=>{e.deleted||(t[n]=e.content.getContent()[e.length-1])}),t},mh=(e,t)=>{e.doc??Vm();let n=e._map.get(t);return n!==void 0&&!n.deleted},hh=(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&&tm(i,t)&&(n[r]=i.content.getContent()[i.length-1])}),n},gh=e=>(e.doc??Vm(),Gf(e._map.entries(),e=>!e[1].deleted)),_h=class extends zm{},vh=class e extends Zm{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 Zm?e.clone():e)),t}get length(){return this.doc??Vm(),this._length}_callObserver(e,t){super._callObserver(e,t),Xm(this,e,new _h(this,e))}insert(e,t){this.doc===null?this._prelimContent.splice(e,0,...t):xm(this.doc,n=>{sh(n,this,e,t)})}push(e){this.doc===null?this._prelimContent.push(...e):xm(this.doc,t=>{ch(t,this,e)})}unshift(e){this.insert(0,e)}delete(e,t=1){this.doc===null?this._prelimContent.splice(e,t):xm(this.doc,n=>{lh(n,this,e,t)})}get(e){return ih(this,e)}toArray(){return $m(this)}slice(e=0,t=this.length){return Qm(this,e,t)}toJSON(){return this.map(e=>e instanceof Zm?e.toJSON():e)}map(e){return nh(this,e)}forEach(e){th(this,e)}[Symbol.iterator](){return rh(this)}_write(e){e.writeTypeRef(yg)}},yh=e=>new vh,bh=class extends zm{constructor(e,t,n){super(e,t),this.keysChanged=n}},xh=class e extends Zm{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 Zm?e.clone():e)}),t}_callObserver(e,t){Xm(this,e,new bh(this,e,t))}toJSON(){this.doc??Vm();let e={};return this._map.forEach((t,n)=>{if(!t.deleted){let r=t.content.getContent()[t.length-1];e[n]=r instanceof Zm?r.toJSON():r}}),e}get size(){return[...gh(this)].length}keys(){return Kf(gh(this),e=>e[0])}values(){return Kf(gh(this),e=>e[1].content.getContent()[e[1].length-1])}entries(){return Kf(gh(this),e=>[e[0],e[1].content.getContent()[e[1].length-1]])}forEach(e){this.doc??Vm(),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):xm(this.doc,t=>{uh(t,this,e)})}set(e,t){return this.doc===null?this._prelimContent.set(e,t):xm(this.doc,n=>{dh(n,this,e,t)}),t}get(e){return fh(this,e)}has(e){return mh(this,e)}clear(){this.doc===null?this._prelimContent.clear():xm(this.doc,e=>{this.forEach(function(t,n,r){uh(e,r,n)})})}_write(e){e.writeTypeRef(bg)}},Sh=e=>new xh,Ch=(e,t)=>e===t||typeof e==`object`&&typeof t==`object`&&e&&t&&Ou(e,t),wh=class{constructor(e,t,n,r){this.left=e,this.right=t,this.index=n,this.currentAttributes=r}forward(){switch(this.right===null&&Hl(),this.right.content.constructor){case lg:this.right.deleted||Oh(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}},Th=(e,t,n)=>{for(;t.right!==null&&n>0;){switch(t.right.content.constructor){case lg:t.right.deleted||Oh(t.currentAttributes,t.right.content);break;default:t.right.deleted||(n<t.right.length&&um(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},Eh=(e,t,n,r)=>{let i=new Map,a=r?Jm(t,n):null;return a?Th(e,new wh(a.p.left,a.p,a.index,i),n-a.index):Th(e,new wh(null,t._start,0,i),n)},Dh=(e,t,n,r)=>{for(;n.right!==null&&(n.right.deleted===!0||n.right.content.constructor===lg&&Ch(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 Ng(Z(a,am(i.store,a)),s,s&&s.lastId,c,c&&c.id,t,null,new lg(o,r));l.integrate(e,0),n.right=l,n.forward()})},Oh=(e,t)=>{let{key:n,value:r}=t;r===null?e.delete(n):e.set(n,r)},kh=(e,t)=>{for(;e.right!==null&&(e.right.deleted||e.right.content.constructor===lg&&Ch(t[e.right.content.key]??null,e.right.content.value));)e.forward()},Ah=(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(!Ch(l,c)){o.set(s,l);let{left:r,right:u}=n;n.right=new Ng(Z(a,am(i.store,a)),r,r&&r.lastId,u,u&&u.id,t,null,new lg(s,c)),n.right.integrate(e,0),n.forward()}}return o},jh=(e,t,n,r,i)=>{n.currentAttributes.forEach((e,t)=>{i[t]===void 0&&(i[t]=null)});let a=e.doc,o=a.clientID;kh(n,i);let s=Ah(e,t,n,i),c=r.constructor===String?new gg(r):r instanceof Zm?new Eg(r):new sg(r),{left:l,right:u,index:d}=n;t._searchMarker&&Ym(t._searchMarker,n.index,c.getLength()),u=new Ng(Z(o,am(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(),Dh(e,t,n,s)},Mh=(e,t,n,r,i)=>{let a=e.doc,o=a.clientID;kh(n,i);let s=Ah(e,t,n,i);iterationLoop:for(;n.right!==null&&(r>0||s.size>0&&(n.right.deleted||n.right.content.constructor===lg));){if(!n.right.deleted)switch(n.right.content.constructor){case lg:{let{key:t,value:a}=n.right.content,o=i[t];if(o!==void 0){if(Ch(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&&um(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 Ng(Z(o,am(a.store,o)),n.left,n.left&&n.left.lastId,n.right,n.right&&n.right.id,t,null,new gg(i)),n.right.integrate(e,0),n.forward()}Dh(e,t,n,s)},Nh=(e,t,n,r,i)=>{let a=t,o=yc();for(;a&&(!a.countable||a.deleted);){if(!a.deleted&&a.content.constructor===lg){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 lg:{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&&Oh(i,n);break}}}t=t.right}return s},Ph=(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===lg){let r=t.content.key;n.has(r)?t.delete(e):n.add(r)}t=t.left}},Fh=e=>{let t=0;return xm(e.doc,n=>{let r=e._start,i=e._start,a=yc(),o=bc(a);for(;i;){if(i.deleted===!1)switch(i.content.constructor){case lg:Oh(o,i.content);break;default:t+=Nh(n,r,i,a,o),a=bc(o),r=i;break}i=i.right}}),t},Ih=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&&pm(e,n.store.clients.get(r),a,i,e=>{!e.deleted&&e.content.constructor===lg&&e.constructor!==$h&&t.add(e.parent)})}xm(n,n=>{Yf(e,e.deleteSet,e=>{if(e instanceof $h||!e.parent._hasFormatting||t.has(e.parent))return;let r=e.parent;e.content.constructor===lg?t.add(r):Ph(n,e)});for(let e of t)Fh(e)})},Lh=(e,t,n)=>{let r=n,i=bc(t.currentAttributes),a=t.right;for(;n>0&&t.right!==null;){if(t.right.deleted===!1)switch(t.right.content.constructor){case Eg:case sg:case gg:n<t.right.length&&um(e,Z(t.right.id.client,t.right.id.clock+n)),n-=t.right.length,t.right.delete(e);break}t.forward()}a&&Nh(e,a,t.right,i,t.currentAttributes);let o=(t.left||t.right).parent;return o._searchMarker&&Ym(o._searchMarker,t.index,-r+n),t},Rh=class extends zm{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=[];xm(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},Tu(o)||(e.attributes=xu({},o))),c=0;break}e&&t.push(e),a=null}};for(;i!==null;){switch(i.content.constructor){case Eg:case sg: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 gg: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 lg:{let{key:t,value:s}=i.content;if(this.adds(i))this.deletes(i)||(Ch(n.get(t)??null,s)?s!==null&&i.delete(e):(a===`retain`&&u(),Ch(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;Ch(e,s)||(a===`retain`&&u(),o[t]=e)}else if(!i.deleted){r.set(t,s);let n=o[t];n!==void 0&&(Ch(n,s)?n!==null&&i.delete(e):(a===`retain`&&u(),s===null?delete o[t]:o[t]=s))}i.deleted||(a===`insert`&&u(),Oh(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}},zh=class e extends Zm{constructor(e){super(),this._pending=e===void 0?[]:[()=>this.insert(0,e)],this._searchMarker=[],this._hasFormatting=!1}get length(){return this.doc??Vm(),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 Rh(this,e,t);Xm(this,e,n),!e.local&&this._hasFormatting&&(e._needFormattingCleanup=!0)}toString(){this.doc??Vm();let e=``,t=this._start;for(;t!==null;)!t.deleted&&t.countable&&t.content.constructor===gg&&(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)):xm(this.doc,n=>{let r=new wh(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)&&jh(n,this,r,o,a.attributes||{})}else a.retain===void 0?a.delete!==void 0&&Lh(n,r,a.delete):Mh(n,this,r,a.retain,a.attributes||{})}})}toDelta(e,t,n){this.doc??Vm();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(tm(s,e)||t!==void 0&&tm(s,t))switch(s.content.constructor){case gg:{let r=i.get(`ychange`);e!==void 0&&!tm(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&&!tm(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 Eg:case sg:{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 lg:tm(s,e)&&(c(),Oh(i,s.content));break}s=s.right}c()};return e||t?xm(a,n=>{e&&nm(n,e),t&&nm(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)):xm(r,r=>{let i=Eh(r,this,e,!n);n||(n={},i.currentAttributes.forEach((e,t)=>{n[t]=e})),jh(r,this,i,t,n)})}insertEmbed(e,t,n){let r=this.doc;r===null?this._pending.push(()=>this.insertEmbed(e,t,n||{})):xm(r,r=>{let i=Eh(r,this,e,!n);jh(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)):xm(n,n=>{Lh(n,Eh(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)):xm(r,r=>{let i=Eh(r,this,e,!1);i.right!==null&&Mh(r,this,i,t,n)})}removeAttribute(e){this.doc===null?this._pending.push(()=>this.removeAttribute(e)):xm(this.doc,t=>{uh(t,this,e)})}setAttribute(e,t){this.doc===null?this._pending.push(()=>this.setAttribute(e,t)):xm(this.doc,n=>{dh(n,this,e,t)})}getAttribute(e){return fh(this,e)}getAttributes(){return ph(this)}_write(e){e.writeTypeRef(xg)}},Bh=e=>new zh,Vh=class{constructor(e,t=()=>!0){this._filter=t,this._root=e,this._currentNode=e._start,this._firstCall=!0,e.doc??Vm()}[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===Wh||t.constructor===Hh)&&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})}},Hh=class e extends Zm{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 Zm?e.clone():e)),t}get length(){return this.doc??Vm(),this._prelimContent===null?this._length:this._prelimContent.length}createTreeWalker(e){return new Vh(this,e)}querySelector(e){e=e.toUpperCase();let t=new Vh(this,t=>t.nodeName&&t.nodeName.toUpperCase()===e).next();return t.done?null:t.value}querySelectorAll(e){return e=e.toUpperCase(),Dc(new Vh(this,t=>t.nodeName&&t.nodeName.toUpperCase()===e))}_callObserver(e,t){Xm(this,e,new Kh(this,t,e))}toString(){return nh(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),th(this,i=>{r.insertBefore(i.toDOM(e,t,n),null)}),r}insert(e,t){this.doc===null?this._prelimContent.splice(e,0,...t):xm(this.doc,n=>{sh(n,this,e,t)})}insertAfter(e,t){if(this.doc!==null)xm(this.doc,n=>{let r=e&&e instanceof Zm?e._item:e;ah(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 Bl(`Reference item not found`);n.splice(r,0,...t)}}delete(e,t=1){this.doc===null?this._prelimContent.splice(e,t):xm(this.doc,n=>{lh(n,this,e,t)})}toArray(){return $m(this)}push(e){this.insert(this.length,e)}unshift(e){this.insert(0,e)}get(e){return ih(this,e)}slice(e=0,t=this.length){return Qm(this,e,t)}forEach(e){th(this,e)}_write(e){e.writeTypeRef(Cg)}},Uh=e=>new Hh,Wh=class e extends Hh{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 Cu(this.getAttributes(),(e,n)=>{t.setAttribute(n,e)}),t.insert(0,this.toArray().map(e=>e instanceof Zm?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):xm(this.doc,t=>{uh(t,this,e)})}setAttribute(e,t){this.doc===null?this._prelimAttrs.set(e,t):xm(this.doc,n=>{dh(n,this,e,t)})}getAttribute(e){return fh(this,e)}hasAttribute(e){return mh(this,e)}getAttributes(e){return e?hh(this,e):ph(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 th(this,i=>{r.appendChild(i.toDOM(e,t,n))}),n!==void 0&&n._createAssociation(r,this),r}_write(e){e.writeTypeRef(Sg),e.writeKey(this.nodeName)}},Gh=e=>new Wh(e.readKey()),Kh=class extends zm{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)})}},qh=class e extends xh{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(wg),e.writeKey(this.hookName)}},Jh=e=>new qh(e.readKey()),Yh=class e extends zh{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(Tg)}},Xh=e=>new Yh,Zh=class{constructor(e,t){this.id=e,this.length=t}get deleted(){throw Vl()}mergeWith(e){return!1}write(e,t,n){throw Vl()}integrate(e,t){throw Vl()}},Qh=0,$h=class extends Zh{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),om(e.doc.store,this)}write(e,t){e.writeInfo(Qh),e.writeLen(this.length-t)}getMissing(e,t){return null}},eg=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 Vl()}mergeWith(e){return!1}integrate(e,t){}delete(e){}gc(e){}write(e,t){e.writeBuf(this.content)}getRef(){return 3}},tg=e=>new eg(e.readBuf()),ng=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){ep(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}},rg=e=>new ng(e.readLen()),ig=(e,t)=>new sp({guid:e,...t,shouldLoad:t.shouldLoad||t.autoLoad||!1}),ag=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(ig(this.doc.guid,this.opts))}splice(e){throw Vl()}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}},og=e=>new ag(ig(e.readString(),e.readAny())),sg=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 Vl()}mergeWith(e){return!1}integrate(e,t){}delete(e){}gc(e){}write(e,t){e.writeJSON(this.embed)}getRef(){return 5}},cg=e=>new sg(e.readJSON()),lg=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 Vl()}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}},ug=e=>new lg(e.readKey(),e.readJSON()),dg=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}},fg=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 dg(n)},pg=Vu(`node_env`)===`development`,mg=class e{constructor(e){this.arr=e,pg&&Au(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}},hg=e=>{let t=e.readLen(),n=[];for(let r=0;r<t;r++)n.push(e.readAny());return new mg(n)},gg=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}},_g=e=>new gg(e.readString()),vg=[yh,Sh,Bh,Gh,Uh,Jh,Xh],yg=0,bg=1,xg=2,Sg=3,Cg=4,wg=5,Tg=6,Eg=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 Vl()}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}},Dg=e=>new Eg(vg[e.readTypeRef()](e)),Og=(e,t)=>{let n=t,r=0,i;do r>0&&(n=Z(n.client,n.clock+r)),i=cm(e,n),r=n.clock-i.id.clock,n=i.redone;while(n!==null&&i instanceof Ng);return{item:i,diff:r}},kg=(e,t)=>{for(;e!==null&&e.keep!==t;)e.keep=t,e=e.parent._item},Ag=(e,t,n)=>{let{client:r,clock:i}=t.id,a=new Ng(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},jg=(e,t)=>kc(e,e=>Zf(e.deletions,t)),Mg=(e,t,n,r,i,a)=>{let o=e.doc,s=o.store,c=o.clientID,l=t.redone;if(l!==null)return um(e,l);let u=t.parent._item,d=null,f;if(u!==null&&u.deleted===!0){if(u.redone===null&&(!n.has(u)||Mg(e,u,n,r,i,a)===null))return null;for(;u.redone!==null;)u=um(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:um(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:um(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||Zf(r,d.right.id)||jg(a.undoStack,d.right.id)||jg(a.redoStack,d.right.id));)for(d=d.right;d.redone;)d=um(e,d.redone);if(d&&d.right!==null)return null}else d=p._map.get(t.parentSub)||null;let m=Z(c,am(s,c)),h=new Ng(m,d,d&&d.lastId,f,f&&f.id,p,t.parentSub,t.content.copy());return t.redone=m,kg(h,!0),h.integrate(e,0),h},Ng=class e extends Zh{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>=am(n,this.origin.client))return this.origin.client;if(this.rightOrigin&&this.rightOrigin.client!==this.id.client&&this.rightOrigin.clock>=am(n,this.rightOrigin.client))return this.rightOrigin.client;if(this.parent&&this.parent.constructor===Rp&&this.id.client!==this.parent.client&&this.parent.clock>=am(n,this.parent.client))return this.parent.client;if(this.origin&&=(this.left=dm(t,n,this.origin),this.left.lastId),this.rightOrigin&&=(this.right=um(t,this.rightOrigin),this.right.id),this.left&&this.left.constructor===$h||this.right&&this.right.constructor===$h)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===Rp){let e=cm(n,this.parent);e.constructor===$h?this.parent=null:this.parent=e.content.type}return null}integrate(e,t){if(t>0&&(this.id.clock+=t,this.left=dm(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),zp(this.origin,n.origin)){if(n.id.client<this.id.client)t=n,r.clear();else if(zp(this.rightOrigin,n.rightOrigin))break}else if(n.origin!==null&&i.has(cm(e.doc.store,n.origin)))r.has(cm(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),om(e.doc.store,this),this.content.integrate(e,this),gm(e,this.parent,this.parentSub),(this.parent._item!==null&&this.parent._item.deleted||this.parentSub!==null&&this.right!==null)&&this.delete(e)}else new $h(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&&zp(e.origin,this.lastId)&&this.right===e&&zp(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(),ep(e.deleteSet,this.id.client,this.id.clock,this.length),gm(e,t,this.parentSub),this.content.delete(e)}}gc(e,t){if(!this.deleted)throw Hl();this.content.gc(e),t?fm(e,this,new $h(this.id,this.length)):this.content=new ng(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=Bp(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===Rp?(e.writeParentInfo(!1),e.writeLeftID(t)):Hl();i!==null&&e.writeString(i)}this.content.write(e,t)}},Pg=(e,t)=>Fg[t&31](e),Fg=[()=>{Hl()},rg,fg,tg,_g,cg,ug,Dg,hg,og,()=>{Hl()}],Ig=10,Lg=class extends Zh{get deleted(){return!0}delete(){}mergeWith(e){return this.constructor===e.constructor?(this.length+=e.length,!0):!1}integrate(e,t){Hl()}write(e,t){e.writeInfo(Ig),bl(e.restEncoder,this.length-t)}getMissing(e,t){return null}},Rg=typeof globalThis<`u`?globalThis:typeof window<`u`?window:typeof global<`u`?global:{},zg=`__ $YJS$ __`;Rg[zg]===!0&&console.error(`Yjs was already imported. This breaks constructor checks and will lead to issues! - https://github.com/yjs/yjs/issues/438`),Rg[zg]=!0;var Bg=()=>{let e=!0;return(t,n)=>{if(e){e=!1;try{t()}finally{e=!0}}else n!==void 0&&n()}},Vg=/[\uD800-\uDBFF]/,Hg=/[\uDC00-\uDFFF]/,Ug=(e,t)=>{let n=0,r=0;for(;n<e.length&&n<t.length&&e[n]===t[n];)n++;for(n>0&&Vg.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&&Hg.test(e[e.length-r])&&r--,{index:n,remove:e.length-n-r,insert:t.slice(n,t.length-r)}},Wg=(e,t)=>e>>>t|e<<32-t,Gg=e=>Wg(e,2)^Wg(e,13)^Wg(e,22),Kg=e=>Wg(e,6)^Wg(e,11)^Wg(e,25),qg=e=>Wg(e,7)^Wg(e,18)^e>>>3,Jg=e=>Wg(e,17)^Wg(e,19)^e>>>10,Yg=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]),Xg=new Uint32Array([1779033703,3144134277,1013904242,2773480762,1359893119,2600822924,528734635,1541459225]),Zg=class{constructor(){let e=new ArrayBuffer(320);this._H=new Uint32Array(e,0,8),this._H.set(Xg),this._W=new Uint32Array(e,64,64)}_updateHash(){let e=this._H,t=this._W;for(let e=16;e<64;e++)t[e]=Jg(t[e-2])+t[e-7]+qg(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+Kg(o)+(o&s^~o&c)+Yg[e]+t[e]>>>0,d=Gg(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/Zc,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}},Qg=e=>new Zg().digest(e),$g=new T(`y-sync`),e_=new T(`y-undo`),t_=new T(`yjs-cursor`),n_=e=>{for(let t=6;t<e.length;t++)e[t%6]=e[t%6]^e[t];return e.slice(0,6)},r_=e=>Ku(n_(Qg(Ju(e)))),i_=(e,t)=>t===void 0?!e.deleted:t.sv.has(e.id.client)&&t.sv.get(e.id.client)>e.id.clock&&!Zf(t.ds,e.id),a_=[{light:`#ecd44433`,dark:`#ecd444`}],o_=(e,t,n)=>{if(!e.has(n)){if(e.size<t.length){let n=wc();e.forEach(e=>n.add(e)),t=t.filter(e=>!n.has(e))}e.set(n,uu(t))}return e.get(n)},s_=(e,{colors:t=a_,colorMapping:n=new Map,permanentUserData:r=null,onFirstRender:i=()=>{},mapping:a}={})=>{let o=!1,s=new d_(e,a),c=new v({props:{editable:e=>{let t=$g.getState(e);return t.snapshot==null&&t.prevSnapshot==null}},key:$g,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($g);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)&&Df(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=e_.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)},$g)})}},destroy:()=>{s.destroy()}})});return c},c_=(e,t,n)=>{if(t!==null&&t.anchor!==null&&t.head!==null)if(t.type===`all`)e.setSelection(new I(e.doc));else if(t.type===`node`){let r=B_(n.doc,n.type,t.anchor,n.mapping);e.setSelection(l_(e,r))}else{let r=B_(n.doc,n.type,t.anchor,n.mapping),i=B_(n.doc,n.type,t.head,n.mapping);r!==null&&i!==null&&e.setSelection(Ct.between(e.doc.resolve(r),e.doc.resolve(i)))}},l_=(e,t)=>{let n=e.doc.resolve(t);return n.nodeAfter?z.create(e.doc,t):Ct.near(n)},u_=(e,t)=>({type:t.selection.jsonID,anchor:R_(t.selection.anchor,e.type,e.mapping),head:R_(t.selection.head,e.type,e.mapping)}),d_=class{constructor(e,t=new Map){this.type=e,this.prosemirrorView=null,this.mux=Bg(),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=u_(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()?(Iu&&this._domSelectionInView===null&&(Df(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=df.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||=$p(tp(),new Map),this.prosemirrorView.dispatch(this._tr.setMeta($g,{snapshot:e,prevSnapshot:t}))}unrenderSnapshot(){this.mapping.clear(),this.mux(()=>{let e=this.type.toArray().map(e=>p_(e,this.prosemirrorView.state.schema,this)).filter(e=>e!==null),t=this._tr.replace(0,this.prosemirrorView.state.doc.content.size,new ue(S.from(e),0,0));t.setMeta($g,{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=>p_(e,this.prosemirrorView.state.schema,this)).filter(e=>e!==null),n=this._tr.replace(0,this.prosemirrorView.state.doc.content.size,new ue(S.from(t),0,0));if(e){let t=Ic(Lc(e.anchor,0),n.doc.content.size),r=Ic(Lc(e.head,0),n.doc.content.size);n.setSelection(Ct.create(n.doc,t,r))}this.prosemirrorView.dispatch(n.setMeta($g,{isChangeOrigin:!0,binding:this}))})}_renderSnapshot(e,t,n){let r=this.doc,i=this.type;if(e||=em(this.doc),e instanceof Uint8Array||t instanceof Uint8Array)if((!(e instanceof Uint8Array)||!(t instanceof Uint8Array))&&Hl(),r=new sp({gc:!1}),Sp(r,t),t=em(r),Sp(r,e),e=em(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[sm(e,i._item.id.clock)].content.type}this.mapping.clear(),this.mux(()=>{r.transact(r=>{let a=n.permanentUserData;a&&a.dss.forEach(e=>{Yf(r,e,e=>{})});let o=(e,t)=>{let r=e===`added`?a.getUserByClientId(t.client):a.getUserByDeletedId(t);return{user:r,type:e,color:o_(n.colorMapping,n.colors,r)}},s=eh(i,new Qp(t.ds,e.sv)).map(n=>!n._item.deleted||i_(n._item,e)||i_(n._item,t)?p_(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 ue(S.from(s),0,0));this.prosemirrorView.dispatch(c.setMeta($g,{isChangeOrigin:!0}))},$g)})}_typeChanged(e,t){if(this.prosemirrorView==null)return;let n=$g.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);Yf(t,t.deleteSet,e=>{if(e.constructor===Ng){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=>f_(e,this.prosemirrorView.state.schema,this)).filter(e=>e!==null),r=this._tr.replace(0,this.prosemirrorView.state.doc.content.size,new ue(S.from(n),0,0));c_(r,this.beforeTransactionSelection,this),r=r.setMeta($g,{isChangeOrigin:!0,isUndoRedoOperation:t.origin instanceof Tm}),this.beforeTransactionSelection!==null&&this._isLocalCursorInView()&&r.scrollIntoView(),this.prosemirrorView.dispatch(r)})}_prosemirrorChanged(e){this.doc.transact(()=>{j_(this.doc,this.type,e,this),this.beforeTransactionSelection=u_(this,this.prosemirrorView.state)},$g)}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))}},f_=(e,t,n,r,i,a)=>{let o=n.mapping.get(e);if(o===void 0){if(e instanceof Wh)return p_(e,t,n,r,i,a);throw Vl()}return o},p_=(e,t,n,r,i,a)=>{let o=[],s=e=>{if(e instanceof Wh){let s=f_(e,t,n,r,i,a);s!==null&&o.push(s)}else{let s=e._item.right?.content?.type;s instanceof zh&&!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=m_(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):eh(e,new Qp(i.ds,r.sv)).forEach(s);try{let s=e.getAttributes(r);r!==void 0&&(i_(e._item,r)?i_(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}},m_=(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,k_(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},h_=(e,t)=>{let n=new Yh,r=e.map(e=>({insert:e.text,attributes:A_(e.marks,t)}));return n.applyDelta(r),t.mapping.set(n,e),n},g_=(e,t)=>{let n=new Wh(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,b_(e).map(e=>__(e,t))),t.mapping.set(n,e),n},__=(e,t)=>e instanceof Array?h_(e,t):g_(e,t),v_=e=>typeof e==`object`&&!!e,y_=(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||v_(o)&&v_(s)&&y_(o,s)}return r},b_=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},x_=(e,t)=>{let n=e.toDelta();return n.length===t.length&&n.every((e,n)=>e.insert===t[n].text&&Su(e.attributes||{}).length===t[n].marks.length&&Eu(e.attributes,(e,r)=>{let i=O_(r),a=t[n].marks;return a.find(e=>e.type.name===i)?y_(e,a.find(e=>e.type.name===i)?.attrs):!1}))},S_=(e,t)=>{if(e instanceof Wh&&!(t instanceof Array)&&M_(e,t)){let n=b_(t);return e._length===n.length&&y_(e.getAttributes(),t.attrs)&&e.toArray().every((e,t)=>S_(e,n[t]))}return e instanceof Yh&&t instanceof Array&&x_(e,t)},C_=(e,t)=>e===t||e instanceof Array&&t instanceof Array&&e.length===t.length&&e.every((e,n)=>t[n]===e),w_=(e,t,n)=>{let r=e.toArray(),i=b_(t),a=i.length,o=r.length,s=Ic(o,a),c=0,l=0,u=!1;for(;c<s;c++){let e=r[c],t=i[c];if(C_(n.mapping.get(e),t))u=!0;else if(!S_(e,t))break}for(;c+l<s;l++){let e=r[o-l-1],t=i[a-l-1];if(C_(n.mapping.get(e),t))u=!0;else if(!S_(e,t))break}return{equalityFactor:c+l,foundMappedChild:u}},T_=e=>{let t=``,n=e._start,r={};for(;n!==null;)n.deleted||(n.countable&&n.content instanceof gg?t+=n.content.str:n.content instanceof lg&&(r[n.content.key]=null)),n=n.right;return{str:t,nAttrs:r}},E_=(e,t,n)=>{n.mapping.set(e,t);let{nAttrs:r,str:i}=T_(e),a=t.map(e=>({insert:e.text,attributes:Object.assign({},r,A_(e.marks,n))})),{insert:o,remove:s,index:c}=Ug(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})))},D_=/(.*)(--[a-zA-Z0-9+/=]{8})$/,O_=e=>D_.exec(e)?.[1]??e,k_=(e,t)=>{let n=[];for(let r in e)n.push(t.mark(O_(r),e[r]));return n},A_=(e,t)=>{let n={};return e.forEach(e=>{if(e.type.name!==`ychange`){let r=xc(t.isOMark,e.type,()=>!e.type.excludes(e.type));n[r?`${e.type.name}--${r_(e.toJSON())}`:e.type.name]=e.attrs}}),n},j_=(e,t,n,r)=>{if(t instanceof Wh&&t.nodeName!==n.type.name)throw Error(`node name mismatch!`);if(r.mapping.set(t,n),t instanceof Wh){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=b_(n),a=i.length,o=t.toArray(),s=o.length,c=Ic(a,s),l=0,u=0;for(;l<c;l++){let e=o[l],t=i[l];if(!C_(r.mapping.get(e),t))if(S_(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(!C_(r.mapping.get(e),t))if(S_(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 Yh&&c instanceof Array)x_(n,c)||E_(n,c,r),l+=1;else{let i=n instanceof Wh&&M_(n,c),a=d instanceof Wh&&M_(d,f);if(i&&a){let e=w_(n,c,r),t=w_(d,f,r);e.foundMappedChild&&!t.foundMappedChild?a=!1:!e.foundMappedChild&&t.foundMappedChild||e.equalityFactor<t.equalityFactor?i=!1:a=!1}i?(j_(e,n,c,r),l+=1):a?(j_(e,d,f,r),u+=1):(r.mapping.delete(t.get(l)),t.delete(l,1),t.insert(l,[__(c,r)]),l+=1)}}let n=s-l-u;if(s===1&&a===0&&o[0]instanceof Yh?(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(__(i[t],r));t.insert(l,e)}},$g)},M_=(e,t)=>!(t instanceof Array)&&e.nodeName===t.type.name,N_=null,P_=class{constructor(e,t,n){this.view=e,this.key=t,this.value=n}apply(){let e=$g.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)}}},F_=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=N_;N_=null;let n=[];return t.forEach((e,t)=>{e.forEach((e,r)=>{n.push(new P_(t,r,e))})}),new e(n)}},I_=(e=F_.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()||Df(0,()=>I_(e,!0));return}throw r}n=!1,e.dequeueFirst()}},L_=(e,t,n)=>{N_||(N_=new Map,Df(0,I_)),xc(N_,e,yc).set(t,n)},R_=(e,t,n)=>{if(e===0)return Jp(t,0,-1);let r=t._first===null?null:t._first.content.type;for(;r!==null&&t!==r;){if(r instanceof Yh){if(r._length>=e)return Jp(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 Hp(r._item===null?null:r._item.id,r._item===null?Bp(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 Hp(r._item===null?null:r._item.id,r._item===null?Bp(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 Hl();if(e===0&&r.constructor!==Yh&&r!==t)return z_(r._item.parent,r._item)}return Jp(t,t._length,-1)},z_=(e,t)=>{let n=null,r=null;return e._item===null?r=Bp(e):n=Z(e._item.id.client,e._item.id.clock),new Hp(n,r,t.id)},B_=(e,t,n,r)=>{let i=Xp(n,e);if(i===null||i.type!==t&&!Vp(t,i.type._item))return null;let a=i.type,o=0;if(a.constructor===Yh)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 Yh?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 Yh?o+=e._length:o+=r.get(e).nodeSize),t=t.right}}a=e}return o-1},V_=(e,t,n)=>e!==t,H_=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},U_=e=>({style:`background-color: ${e.color}70`,class:`ProseMirror-yjs-selection`}),W_=/^#[0-9a-fA-F]{6}$/,G_=(e,t,n,r,i)=>{let a=$g.getState(e);if(a==null||a.doc==null||a.binding==null)return P.create(e.doc,[]);let o=a.doc,s=[];return a.snapshot!=null||a.prevSnapshot!=null||a.binding.mapping.size===0?P.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`:W_.test(n.color)||console.warn(`A user uses an unsupported color format`,n),n.name??=`User: ${c}`;let l=B_(o,a.type,Wp(t.cursor.anchor),a.binding.mapping),u=B_(o,a.type,Wp(t.cursor.head),a.binding.mapping);if(l!==null&&u!==null){let t=Lc(e.doc.content.size-1,0);l=Ic(l,t),u=Ic(u,t),s.push(Be.widget(u,()=>r(n,c),{key:c+``,side:10}));let a=Ic(l,u),o=Lc(l,u);s.push(Be.inline(a,o,i(n,c),{inclusiveEnd:!0,inclusiveStart:!1}))}}}),P.create(e.doc,s))},K_=(e,{awarenessStateFilter:t=V_,cursorBuilder:n=H_,selectionBuilder:r=U_,getSelection:i=e=>e.selection}={},a=`cursor`)=>new v({key:t_,state:{init(i,a){return G_(a,e,t,n,r)},apply(i,a,o,s){let c=$g.getState(s),l=i.getMeta(t_);return c&&c.isChangeOrigin||l&&l.awarenessUpdated?G_(s,e,t,n,r):a.map(i.mapping,i.doc)}},props:{decorations:e=>t_.getState(e)},view:t=>{let n=()=>{t.docView&&L_(t,t_,{awarenessUpdated:!0})},r=()=>{let n=$g.getState(t.state),r=e.getLocalState()||{};if(t.hasFocus()){let o=i(t.state),s=R_(o.anchor,n.type,n.binding.mapping),c=R_(o.head,n.type,n.binding.mapping);(r.cursor==null||!Zp(Wp(r.cursor.anchor),s)||!Zp(Wp(r.cursor.head),c))&&e.setLocalStateField(a,{anchor:s,head:c})}else r.cursor!=null&&B_(n.doc,n.type,Wp(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)}}}}),q_=e=>{let t=e_.getState(e).undoManager;if(t!=null)return t.undo(),!0},J_=e=>{let t=e_.getState(e).undoManager;if(t!=null)return t.redo(),!0},Y_=new Set([`paragraph`]),X_=(e,t)=>!(e instanceof Ng)||!(e.content instanceof Eg)||!(e.content.type instanceof zh||e.content.type instanceof Wh&&t.has(e.content.type.nodeName))||e.content.type._length===0,Z_=({protectedNodes:e=Y_,trackedOrigins:t=[],undoManager:n=null}={})=>new v({key:e_,state:{init:(r,i)=>{let a=$g.getState(i),o=n||new Tm(a.type,{trackedOrigins:new Set([$g].concat(t)),deleteFilter:t=>X_(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=$g.getState(r).binding,a=t.undoManager,o=a.undoStack.length>0,s=a.redoStack.length>0;return i?{undoManager:a,prevSel:u_(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=$g.getState(e.state),n=e_.getState(e.state).undoManager;return n.on(`stack-item-added`,({stackItem:n})=>{let r=t.binding;r&&n.meta.set(r,e_.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()}}}});function Q_(e){let{char:t,allowSpaces:n,allowToIncludeChar:r,allowedPrefixes:i,startOfLine:a,$position:o}=e,s=n&&!r,c=Se(t),l=RegExp(`\\s${c}$`),u=a?`^`:``,d=r?``:c,f=RegExp(s?`${u}${c}.*?(?=\\s${d}|$)`:`${u}(?:^)?${c}[^\\s${d}]*`,`gm`),p=o.nodeBefore?.isText&&o.nodeBefore.text;if(!p)return null;let m=o.pos-p.length,h=Array.from(p.matchAll(f)).pop();if(!h||h.input===void 0||h.index===void 0)return null;let g=h.input.slice(Math.max(0,h.index-1),h.index),_=RegExp(`^[${i?.join(``)}\0]?$`).test(g);if(i!==null&&!_)return null;let v=m+h.index,y=v+h[0].length;return s&&l.test(p.slice(y-1,y+1))&&(h[0]+=` `,y+=1),v<o.pos&&y>=o.pos?{range:{from:v,to:y},query:h[0].slice(t.length),text:h[0]}:null}function $_(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
- `);return/\s/.test(n)}):!1}var ev=new T(`suggestion`);function tv({pluginKey:e=ev,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=Q_,shouldShow:g,shouldResetDismissed:_}){let y,b=p?.(),x=r&&!i,S=()=>{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}},C=(n,r)=>r?()=>{let r=e.getState(t.state)?.decorationId;return n.dom.querySelector(`[data-decoration-id="${r}"]`)?.getBoundingClientRect()||null}:S,w=({match:e,dismissedRange:n,state:r,transaction:i})=>_?.({editor:t,state:r,range:n,match:e,transaction:i,allowSpaces:x})?!1:x?e.range.from===n.from:e.range.from===n.from&&!$_(i);function T(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:C(n,a)};(i=b?.onExit)==null||i.call(b,o)}catch{}let a=n.state.tr.setMeta(r,{exit:!0});n.dispatch(a)}let E=new v({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,v=m||u&&h;if(!g&&!_&&!v)return;let x=v&&!g?c:l,S=e.dom.querySelector(`[data-decoration-id="${x.decorationId}"]`);y={editor:t,range:x.range,query:x.query,text:x.text,items:[],command:e=>d({editor:t,range:x.range,props:e}),decorationNode:S,clientRect:C(e,S)},g&&((r=b?.onBeforeStart)==null||r.call(b,y)),_&&((i=b?.onBeforeUpdate)==null||i.call(b,y)),(_||g)&&(y.items=await f({editor:t,query:x.query})),v&&((a=b?.onExit)==null||a.call(b,y)),_&&((o=b?.onUpdate)==null||o.call(b,y)),g&&((s=b?.onStart)==null||s.call(b,y))},destroy:()=>{var e;y&&((e=b?.onExit)==null||e.call(b,y))}}},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&&!w({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}=E.getState(t.state);if(!i)return!1;if(n.key===`Escape`||n.key===`Esc`){let i=E.getState(t.state);return(r=b?.onKeyDown)==null||r.call(b,{view:t,event:n,range:i.range}),T(t,e),!0}return(b?.onKeyDown)?.call(b,{view:t,event:n,range:a})||!1},decorations(e){let{active:t,range:n,decorationId:r,query:i}=E.getState(e);if(!t)return null;let a=!i?.length,o=[c];return a&&o.push(u),P.create(e.doc,[Be.inline(n.from,n.to,{nodeName:s,class:o.join(` `),"data-decoration-id":r,"data-decoration-content":l})])}}});return E}var nv=tv;function rv(e){return e.kind===`create`?`create:${e.value}`:`tag:${e.value}`}function iv(e){if(e.kind===`create`)return`Create new tag #${e.value}`;let t=e.count===1?`1 use`:`${e.count} uses`;return`Tag #${e.value}, ${t}`}function av(e){let t=(0,Y.c)(32),{items:n,query:r,selectedIndex:i,onSelect:a,onHover:o,loading:s,error:c}=e,l=s===void 0?!1:s,u=c===void 0?null:c,d=(0,q.useRef)(null),f=(0,q.useId)(),p=i>=0&&i<n.length?`${f}-option-${i}`:void 0,m,h;t[0]===i?(m=t[1],h=t[2]):(m=()=>{let e=d.current;if(!e)return;let t=e.querySelectorAll(`[role="option"]`).item(i);t&&t.scrollIntoView({block:`nearest`})},h=[i],t[0]=i,t[1]=m,t[2]=h),(0,q.useEffect)(m,h);let g=ov;if(l){let e;return t[3]===Symbol.for(`react.memo_cache_sentinel`)?(e=(0,J.jsx)(`div`,{ref:d,role:`status`,"aria-live":`polite`,className:`w-64 rounded-lg border bg-popover p-2 shadow-md text-sm text-muted-foreground`,style:{maxHeight:`var(--suggestion-menu-max-height, 40vh)`},onMouseDown:g,children:`Loading tags…`}),t[3]=e):e=t[3],e}if(n.length===0){let e;t[4]===r?e=t[5]:(e=r.trim(),t[4]=r,t[5]=e);let n=e,i=u??(n?`No tags match "${n}". Continue typing to create one.`:`No tags yet. Continue typing to create one.`),a;t[6]===Symbol.for(`react.memo_cache_sentinel`)?(a={maxHeight:`var(--suggestion-menu-max-height, 40vh)`},t[6]=a):a=t[6];let o;return t[7]===i?o=t[8]:(o=(0,J.jsx)(`div`,{ref:d,role:`status`,"aria-live":`polite`,className:`w-64 rounded-lg border bg-popover p-2 shadow-md text-sm text-muted-foreground`,style:a,onMouseDown:g,children:i}),t[7]=i,t[8]=o),o}let _=i>=0&&i<n.length?n[i]:null,v;t[9]===Symbol.for(`react.memo_cache_sentinel`)?(v={maxHeight:`var(--suggestion-menu-max-height, 40vh)`},t[9]=v):v=t[9];let y;t[10]===_?y=t[11]:(y=_?iv(_):``,t[10]=_,t[11]=y);let b;t[12]===y?b=t[13]:(b=(0,J.jsx)(`span`,{className:`sr-only`,"aria-live":`polite`,"aria-atomic":`true`,children:y}),t[12]=y,t[13]=b);let x;t[14]===u?x=t[15]:(x=u&&(0,J.jsx)(`div`,{className:`rounded-md px-2 py-1.5 text-xs text-amber-700 dark:text-amber-300`,children:u}),t[14]=u,t[15]=x);let S;if(t[16]!==n||t[17]!==f||t[18]!==o||t[19]!==a||t[20]!==i){let e;t[22]!==f||t[23]!==o||t[24]!==a||t[25]!==i?(e=(e,t)=>{let n=t===i,r=rv(e),s=e.kind===`create`;return(0,J.jsxs)(`button`,{id:`${f}-option-${t}`,type:`button`,role:`option`,"aria-selected":n,"data-selected":n,"data-testid":s?`tag-suggestion-create`:`tag-suggestion-tag-${e.value}`,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`:``}`,onMouseDown:t=>{t.preventDefault(),a(e)},onPointerMove:o?()=>o(t):void 0,children:[(0,J.jsx)(`span`,{"aria-hidden":`true`,className:`font-mono text-xs text-muted-foreground`,children:`#`}),(0,J.jsx)(`span`,{className:`truncate font-medium flex-1`,children:e.value}),s?(0,J.jsx)(`span`,{className:`shrink-0 rounded-sm bg-primary/10 px-1.5 py-0.5 text-[10px] font-medium uppercase tracking-wide text-primary`,children:`New`}):(0,J.jsx)(`span`,{className:`shrink-0 text-[11px] text-muted-foreground tabular-nums`,children:e.count})]},r)},t[22]=f,t[23]=o,t[24]=a,t[25]=i,t[26]=e):e=t[26],S=n.map(e),t[16]=n,t[17]=f,t[18]=o,t[19]=a,t[20]=i,t[21]=S}else S=t[21];let C;return t[27]!==p||t[28]!==b||t[29]!==x||t[30]!==S?(C=(0,J.jsxs)(`div`,{ref:d,role:`listbox`,"aria-label":`Tag suggestions`,"aria-activedescendant":p,tabIndex:-1,onMouseDown:g,className:`w-64 overflow-y-auto subtle-scrollbar rounded-lg border bg-popover p-1 shadow-md`,style:v,children:[b,x,S]}),t[27]=p,t[28]=b,t[29]=x,t[30]=S,t[31]=C):C=t[31],C}function ov(e){return e.preventDefault()}function sv(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`),Xe(r,n,{placement:`bottom-start`,middleware:[$e(4),st(),ct({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:()=>ut(r,n,o),reveal:()=>{a||(i=!0,o())}}}function cv(e){e.stopAutoUpdate?.(),e.stopAutoUpdate=null,e.popup?.remove(),e.popup=null}var lv=new T(`tagSuggestion`),uv=8,dv=/^[a-zA-Z][\w/-]*$/;async function fv(){let e=await fetch(`/api/tags`);if(!e.ok)throw Error(`/api/tags responded with ${e.status}`);let t=await e.json();return t.ok&&Array.isArray(t.tags)?t.tags:[]}function pv(e,t){let n=t.trim(),r=n.toLowerCase(),i=n===``?e.slice():e.filter(e=>e.name.toLowerCase().includes(r));return i.sort((e,t)=>{let n=+!e.name.toLowerCase().startsWith(r),i=+!t.name.toLowerCase().startsWith(r);return n===i?t.count===e.count?e.name.localeCompare(t.name):t.count-e.count:n-i}),i}function mv(e,t){let n=pv(e,t).slice(0,uv).map(e=>({kind:`tag`,value:e.name,count:e.count,isLeaf:e.isLeaf})),r=t.trim();return r&&dv.test(r)&&!e.some(e=>e.name===r)&&n.unshift({kind:`create`,value:r}),n}function hv(e){let{$position:t}=e,n=t.parent.textBetween(0,t.parentOffset,void 0,``).match(/(^|[\s])#([a-zA-Z][\w/-]*)?$/);if(!n)return null;let r=n[2]??``,i=t.start(),a=n[1].length;return{range:{from:i+((n.index??0)+a),to:t.pos},query:r,text:`#${r}`}}function gv(e){let t=[],n=!1,r=null,i=null;return nv({editor:e,pluginKey:lv,char:`#`,allowedPrefixes:null,findSuggestionMatch:hv,items:async({query:e})=>{if(!n){r||=fv();try{t=await r,i=null}catch(e){console.error(`[tag-suggestion] Failed to fetch tags:`,e),i=`Failed to load tags. Press Escape and type # again to retry, or continue typing to create a new tag.`,t=[]}finally{n=!0,r=null}}return mv(t,e)},command:({editor:e,range:t,props:n})=>{try{let r=n.value;if(!r||!dv.test(r))return;e.chain().focus().deleteRange(t).insertContent({type:`tag`,attrs:{value:r}}).insertContent(` `).run()}catch(e){console.error(`[tag-suggestion] command failed`,{item:n,range:t},e)}},render:()=>{let e=null,a=null,o=0,s={popup:null,stopAutoUpdate:null},c=null,l=null,u=e=>{a?.command(e)},d=e=>{o!==e&&(o=e,p(null))};function f(e,t,r){let a=t===null?!n:t;return{items:e.items,query:e.query??``,selectedIndex:o,onSelect:r,onHover:d,loading:a,error:i}}let p=t=>{!e||!a||e.updateProps(f(a,t,u))};return{onBeforeStart(t){a=t,o=0;let n=sv(()=>a,`tag-suggestion`);s.popup=n.popup,c=n.doPosition,l=n.reveal,e=new fc(av,{props:f(t,!0,u),editor:t.editor}),n.popup.appendChild(e.element),s.stopAutoUpdate=n.startAutoUpdate()},onStart(e){a=e,o=0,p(null),l?.()},onUpdate(e){a=e,o=Math.min(o,Math.max(0,e.items.length-1)),p(null),c?.()},onKeyDown({event:e}){if(!a)return!1;let t=a.items;if(e.key===`ArrowDown`)return t.length===0?!1:(o=(o+1)%t.length,p(null),!0);if(e.key===`ArrowUp`)return t.length===0?!1:(o=(o-1+t.length)%t.length,p(null),!0);if(e.key===`Enter`||e.key===`Tab`){let e=t[o];if(e)return a.command(e),!0;let n=(a.query??``).trim();return n&&dv.test(n)?(a.command({kind:`create`,value:n}),!0):!1}return e.key,!1},onExit(){cv(s),c=null,l=null,e?.destroy(),e=null,a=null,o=0,t=[],i=null,n=!1,r=null}}}})}var _v=[`.md`,`.mdx`];function vv(e){let t=e.toLowerCase();for(let e of _v)if(t.endsWith(e))return e;return null}function yv(e){let t=vv(e);return t?e.slice(0,-t.length):e}function bv(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 xv(e){let t=e.fileName.trim(),n=vv(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 Sv(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 Cv(e){let t=e.value.lastIndexOf(`.`);t>0?e.setSelectionRange(0,t):e.select()}function wv(e){let t=(0,Y.c)(96),{open:n,onOpenChange:r,kind:i,initialDir:a,suggestedName:o,description:s,onCreated:c}=e,{addPage:l}=we(),[u,d]=(0,q.useState)(``),[f,p]=(0,q.useState)(``),[m,h]=(0,q.useState)(`.md`),[g,_]=(0,q.useState)(null),[v,y]=(0,q.useState)(!1),[b,x]=(0,q.useState)(null),S=(0,q.useId)(),C=(0,q.useId)(),w=(0,q.useId)(),T=(0,q.useRef)(null),E=(0,q.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=vv(e);h(t??`.md`),d(t?yv(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,q.useEffect)(D,O);let k;t[5]===Symbol.for(`react.memo_cache_sentinel`)?(k=function(e){let t=vv(e);t?(h(t),d(yv(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 xv({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=bv(f.trim());if(e)return{message:`Folder name: ${e}`,field:`folder`}}let e=bv(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),et([`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,J.jsx)(Jt,{children:B}),t[28]=B,t[29]=V);let H;t[30]!==s||t[31]!==z?(H=s??(0,J.jsxs)(J.Fragment,{children:[`Create in `,(0,J.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,J.jsx)(Kt,{children:H}),t[33]=H,t[34]=U);let W;t[35]!==U||t[36]!==V?(W=(0,J.jsxs)(on,{children:[V,U]}),t[35]=U,t[36]=V,t[37]=W):W=t[37];let ee;t[38]!==g||t[39]!==b||t[40]!==S||t[41]!==C||t[42]!==f||t[43]!==i?(ee=i===`folder`&&(0,J.jsxs)(`div`,{children:[(0,J.jsx)(`label`,{className:`mb-1.5 block text-sm font-medium`,htmlFor:C,children:`Folder name`}),(0,J.jsx)(zo,{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=bv(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]=ee):ee=t[44];let te=i===`folder`?`First file name`:`File name`,ne;t[45]!==w||t[46]!==te?(ne=(0,J.jsx)(`label`,{className:`mb-1.5 block text-sm font-medium`,htmlFor:w,children:te}),t[45]=w,t[46]=te,t[47]=ne):ne=t[47];let re;t[48]===Symbol.for(`react.memo_cache_sentinel`)?(re=e=>A(e.target.value),t[48]=re):re=t[48];let ie=i===`file`,ae=g&&(b===`file`||b===`form`)?S:void 0,oe=g&&(b===`file`||b===`form`)?!0:void 0,se;t[49]!==R||t[50]!==I?(se=e=>{e.key===`Enter`&&!I&&R()},t[49]=R,t[50]=I,t[51]=se):se=t[51];let ce;t[52]!==w||t[53]!==u||t[54]!==ie||t[55]!==ae||t[56]!==oe||t[57]!==se?(ce=(0,J.jsx)(zo,{ref:T,id:w,value:u,onChange:re,placeholder:`my-note`,autoFocus:ie,"aria-describedby":ae,"aria-invalid":oe,onFocus:Ev,onKeyDown:se,className:`flex-1`}),t[52]=w,t[53]=u,t[54]=ie,t[55]=ae,t[56]=oe,t[57]=se,t[58]=ce):ce=t[58];let le;t[59]===Symbol.for(`react.memo_cache_sentinel`)?(le=e=>{(e===`.md`||e===`.mdx`)&&h(e)},t[59]=le):le=t[59];let ue;t[60]===Symbol.for(`react.memo_cache_sentinel`)?(ue=_v.map(Tv),t[60]=ue):ue=t[60];let de;t[61]===m?de=t[62]:(de=(0,J.jsx)(be,{type:`single`,value:m,onValueChange:le,variant:`outline`,size:`sm`,"aria-label":`File extension`,className:`shrink-0`,children:ue}),t[61]=m,t[62]=de);let fe;t[63]!==ce||t[64]!==de?(fe=(0,J.jsxs)(`div`,{className:`flex items-stretch gap-2`,children:[ce,de]}),t[63]=ce,t[64]=de,t[65]=fe):fe=t[65];let pe;t[66]!==g||t[67]!==S?(pe=g&&(0,J.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]=pe):pe=t[68];let me;t[69]!==ne||t[70]!==fe||t[71]!==pe?(me=(0,J.jsxs)(`div`,{children:[ne,fe,pe]}),t[69]=ne,t[70]=fe,t[71]=pe,t[72]=me):me=t[72];let he;t[73]!==ee||t[74]!==me?(he=(0,J.jsx)(nn,{children:(0,J.jsxs)(`div`,{className:`space-y-3`,children:[ee,me]})}),t[73]=ee,t[74]=me,t[75]=he):he=t[75];let ge;t[76]===r?ge=t[77]:(ge=()=>r(!1),t[76]=r,t[77]=ge);let _e;t[78]!==v||t[79]!==ge?(_e=(0,J.jsx)(zt,{variant:`outline`,className:`font-mono uppercase`,onClick:ge,disabled:v,children:`Cancel`}),t[78]=v,t[79]=ge,t[80]=_e):_e=t[80];let ve=v?`Creating...`:`Create`,ye;t[81]!==R||t[82]!==I||t[83]!==ve?(ye=(0,J.jsx)(zt,{onClick:R,disabled:I,children:ve}),t[81]=R,t[82]=I,t[83]=ve,t[84]=ye):ye=t[84];let xe;t[85]!==_e||t[86]!==ye?(xe=(0,J.jsxs)(rn,{children:[_e,ye]}),t[85]=_e,t[86]=ye,t[87]=xe):xe=t[87];let Se;t[88]!==W||t[89]!==he||t[90]!==xe?(Se=(0,J.jsxs)($t,{className:`sm:max-w-md`,"data-ok-layer-spawned":``,children:[W,he,xe]}),t[88]=W,t[89]=he,t[90]=xe,t[91]=Se):Se=t[91];let Ce;return t[92]!==r||t[93]!==n||t[94]!==Se?(Ce=(0,J.jsx)(sn,{open:n,onOpenChange:r,children:Se}),t[92]=r,t[93]=n,t[94]=Se,t[95]=Ce):Ce=t[95],Ce}function Tv(e){return(0,J.jsx)(Qe,{value:e,"aria-label":`Use ${e} extension`,children:e},e)}function Ev(e){return Cv(e.currentTarget)}tt({event:je(`ok-branch-switched-clear-failed`),branch:Ke(),docName:Ke(),reason:Ke()});async function Dv(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 Ov(e){let t=!1;return()=>{t?e():t=!0}}function kv(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 Av(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=ge.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)&&Dv(e,i.data.currentBranch),i.data.currentDiskAckSVs!==void 0){let t={};for(let[e,n]of Object.entries(i.data.currentDiskAckSVs))try{t[e]=kv(n)}catch{}e.observeDiskAckBatch(t)}}async function jv(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 Mv(e){return Bv(e,g)}function Nv(e){return Bv(e,L)}function Pv(e){return Bv(e,f)}function Fv(e){return Bv(e,re)}function Iv(e){return Bv(e,_t)}function Lv(e){let t=Bv(e,m);if(!t)return null;try{return{docName:t.docName,sv:Rv(t.sv)}}catch{return null}}function Rv(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 zv(e,t){let n=Nv(e);if(n){t.onServerInfo?.(n);return}let r=Pv(e);if(r){t.onBranchSwitched?.(r);return}let i=Lv(e);if(i){t.onDiskAck?.(i);return}let a=Mv(e);if(a){t.onDerivedView?.(a);return}let o=Fv(e);if(o){t.onConfigValidationRejected?.(o);return}let s=Iv(e);if(s){t.onConfigIgnoreNestedError?.(s);return}t.onUnknown?.(e)}function Bv(e,t){let n;try{n=JSON.parse(e)}catch{return null}let r=t.safeParse(n);return r.success?r.data:null}function Vv(){return typeof location>`u`?`ws://localhost/collab`:`${location.protocol===`https:`?`wss`:`ws`}://${location.host}/collab`}function Hv(e){if(e===void 0)return null;let t=e.okDesktop;return!t||!t.config.collabUrl||t.config.collabUrl.length===0?null:t}function Uv(e){return{collabUrl:e.collabUrl,attempts:0,terminal:!1,lastError:null}}var Wv=2e3,Gv=15e3;function Kv(e){let t=e.terminalAfterMs??3e4,n=e.initialDelayMs??Wv,r=e.maxDelayMs??Gv,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 qv(){let e=(0,Y.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,q.useState)(t),i;e[1]===Symbol.for(`react.memo_cache_sentinel`)?(i={token:0},e[1]=i):i=e[1];let a=(0,q.useRef)(i),[o,s]=(0,q.useState)(0),c;e[2]===Symbol.for(`react.memo_cache_sentinel`)?(c=()=>{let e=a.current.token=a.current.token+1,t=Hv(typeof window<`u`?window:void 0);if(t){r(Uv(t.config));let n=t.onProjectSwitched(t=>{e===a.current.token&&r(Uv(t))});return()=>{n()}}let n=Kv({fetchConfig:jv,fallbackUrl:Vv,now:Date.now,setTimeout:Zv,clearTimeout:Xv,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,q.useEffect)(c,l);let u;e[5]===Symbol.for(`react.memo_cache_sentinel`)?(u=()=>{a.current.token=a.current.token+1,r(Yv),s(Jv)},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 Jv(e){return e+1}function Yv(e){return{...e,terminal:!1,lastError:null}}function Xv(e){return globalThis.clearTimeout(e)}function Zv(e,t){return globalThis.setTimeout(e,t)}function Qv(e,t){return t}function $v(e){try{let t=e.state;return e_.getState(t)?.undoManager??null}catch{return null}}var ey=Qv(`MAX_CACHE`,10),ty=Qv(`VIEW_COUNT_CACHE_THRESHOLD`,50),ny=Qv(`BYTES_CACHE_THRESHOLD`,8e6);function ry(e){return!(e.viewCount>0&&e.viewCount>=ty||e.bytes>ny)}var iy=new Map,ay=new Map,oy=[],sy=[],cy=new Set,ly=null;function uy(){if(ly)return ly;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`,ly=e,e}function dy(e){let{docName:t,container:n,factory:r,sizeStats:i}=e;if(i&&!ry(i)){let e=r(n);return X(`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=iy.get(t);if(a){if(X(`ok/cache/reparent-start`,{docName:t,kind:`tiptap`,viewCount:i?.viewCount??-1,bytes:i?.bytes??-1}),yy(a,n),a.activeMountKey=t,xy(oy,t),n.scrollTop=a.scrollTop,a.hadFocus)try{a.editor.commands.focus()}catch{}return X(`ok/cache/reparent-end`,{docName:t,kind:`tiptap`,viewCount:i?.viewCount??-1,bytes:i?.bytes??-1}),X(`ok/cache/hit`,{docName:t,kind:`tiptap`}),i&&X(`ok/cold/editor-mount-stats`,{docName:t,viewCount:i.viewCount,bytes:i.bytes,cacheHit:!0,kind:`tiptap`}),a}for(;iy.size>=ey;){let e=Sy(oy,t);if(!e)break;py(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 iy.set(t,s),xy(oy,t),X(`ok/cache/miss`,{docName:t,viewCount:i?.viewCount??-1,bytes:i?.bytes??-1,reason:`cold`,kind:`tiptap`}),i&&X(`ok/cold/editor-mount-stats`,{docName:t,viewCount:i.viewCount,bytes:i.bytes,cacheHit:!1,kind:`tiptap`}),s}function fy(e){if(e.__uncached){let t=$v(e.editor);try{e.editor.destroy()}catch{}t&&(t.restore=void 0),e.activeMountKey=null;return}let t=_y(e.editor);if(t){e.hadFocus=vy(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=uy();r&&r.appendChild(t.dom)}e.activeMountKey=null}function py(e){let t=iy.get(e);if(!t)return!1;let n=$v(t.editor);try{t.editor.destroy()}catch(t){X(`ok/cache/evict-failed`,{docName:e,kind:`tiptap`,stage:`editor`,message:t instanceof Error?t.message:String(t)})}n&&(n.restore=void 0);try{t.provider.destroy()}catch(t){X(`ok/cache/evict-failed`,{docName:e,kind:`tiptap`,stage:`provider`,message:t instanceof Error?t.message:String(t)})}try{t.ydoc.destroy()}catch(t){X(`ok/cache/evict-failed`,{docName:e,kind:`tiptap`,stage:`ydoc`,message:t instanceof Error?t.message:String(t)})}iy.delete(e);let r=oy.indexOf(e);return r!==-1&&oy.splice(r,1),X(`ok/cache/evict`,{docName:e,kind:`tiptap`}),!0}function my(e){let{docName:t,container:n,factory:r,sizeStats:i}=e;if(i&&!ry(i)){let e=r(n);return X(`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=ay.get(t);if(a){if(X(`ok/cache/reparent-start`,{docName:t,kind:`cm`,viewCount:i?.viewCount??-1,bytes:i?.bytes??-1}),by(a,n),a.activeMountKey=t,xy(sy,t),n.scrollTop=a.scrollTop,a.hadFocus)try{a.view.focus()}catch{}return X(`ok/cache/reparent-end`,{docName:t,kind:`cm`,viewCount:i?.viewCount??-1,bytes:i?.bytes??-1}),X(`ok/cache/hit`,{docName:t,kind:`cm`}),i&&X(`ok/cold/editor-mount-stats`,{docName:t,viewCount:i.viewCount,bytes:i.bytes,cacheHit:!0,kind:`cm`}),a}for(;ay.size>=ey;){let e=Sy(sy,t);if(!e)break;gy(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 ay.set(t,s),xy(sy,t),X(`ok/cache/miss`,{docName:t,viewCount:i?.viewCount??-1,bytes:i?.bytes??-1,reason:`cold`,kind:`cm`}),i&&X(`ok/cold/editor-mount-stats`,{docName:t,viewCount:i.viewCount,bytes:i.bytes,cacheHit:!1,kind:`cm`}),s}function hy(e){if(e.__uncached){try{e.view.destroy()}catch{}e.activeMountKey=null;return}let t=e.view.dom;e.hadFocus=vy(t),e.scrollTop=(e.view.scrollDOM??t).scrollTop??0;let n=t.parentElement;n&&n.removeChild(t);let r=uy();r&&r.appendChild(t),e.activeMountKey=null}function gy(e){let t=ay.get(e);if(!t)return!1;try{t.view.destroy()}catch(t){X(`ok/cache/evict-failed`,{docName:e,kind:`cm`,stage:`view`,message:t instanceof Error?t.message:String(t)})}try{t.provider.destroy()}catch(t){X(`ok/cache/evict-failed`,{docName:e,kind:`cm`,stage:`provider`,message:t instanceof Error?t.message:String(t)})}try{t.ydoc.destroy()}catch(t){X(`ok/cache/evict-failed`,{docName:e,kind:`cm`,stage:`ydoc`,message:t instanceof Error?t.message:String(t)})}ay.delete(e);let n=sy.indexOf(e);return n!==-1&&sy.splice(n,1),X(`ok/cache/evict`,{docName:e,kind:`cm`}),!0}function _y(e){return e.editorView??null}function vy(e){if(typeof document>`u`)return!1;let t=document.activeElement;return t?t===e?!0:e.contains(t):!1}function yy(e,t){let n=_y(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 by(e,t){let n=e.view.dom,r=n.parentElement;r&&r!==t&&r.removeChild(n),n.parentElement!==t&&t.appendChild(n)}function xy(e,t){let n=e.indexOf(t);n!==-1&&e.splice(n,1),e.push(t)}function Sy(e,t){for(let n of e)if(n!==t&&!cy.has(n))return n;X(`ok/cache/evict-fallback-activity-saturated`,{mountingDocName:t,lruLength:e.length,activityMountCount:cy.size});for(let n of e)if(n!==t)return n;return null}function Cy(e){let t=cy,n=new Set(e);for(let e of t){if(n.has(e))continue;let t=Ty(e);if(t)try{t.disconnect(),X(`ok/cache/disconnect`,{docName:e})}catch(t){X(`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=Ty(e);if(!n)continue;let r=t=>{X(`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(()=>X(`ok/cache/connect`,{docName:e}),e=>r(e)):X(`ok/cache/connect`,{docName:e})}catch(e){r(e)}}cy=n}var wy=null;function Ty(e){let t=iy.get(e);if(t)return t.provider;let n=ay.get(e);if(n)return n.provider;if(wy){let t=wy.entries.get(e);if(t)return t.provider}return null}function Ey(e){wy=e;let t=e.onEvict(e=>{py(e),gy(e)});return()=>{t(),wy===e&&(wy=null)}}var Dy=`ok-editor-tabs-v1:`;function Oy(e){return typeof e==`string`&&e.length>0}function ky(e,t){if(!Array.isArray(e)||t<=0)return[];let n=[],r=new Set;for(let i of e)if(Oy(i)&&!r.has(i)&&(r.add(i),n.push(i),n.length>=t))break;return n}function Ay(e,t,n){let r=ky(e,n);if(!Oy(t)||r.includes(t))return r;let i=[...r,t];return i.length>n?i.slice(i.length-n):i}function jy(e,t){return e.filter(e=>e!==t)}function My(e,t,n){if(t.length===0)return ky(e,n);let r=new Map(t.map(e=>[e.fromDocName,e.toDocName])),i=[],a=new Set;for(let t of e){let e=r.get(t)??t;if(!a.has(e)&&(a.add(e),i.push(e),i.length>=n))break}return i}function Ny(e,t,n){if(t!==n)return t;let r=e.indexOf(n);return r<0?e[0]??null:e[r+1]??e[r-1]??null}function Py(e,t){if(typeof e!=`object`||!e)return{openTabs:[],activeDocName:null,updatedAt:null};let n=e,r=ky(n.openTabs,t);return{openTabs:r,activeDocName:typeof n.activeDocName==`string`&&r.includes(n.activeDocName)?n.activeDocName:null,updatedAt:typeof n.updatedAt==`string`?n.updatedAt:null}}function Fy(e,t,n=()=>new Date){let r=ky(e,2**53-1);return{openTabs:r,activeDocName:t&&r.includes(t)?t:null,updatedAt:n().toISOString()}}function Iy(e){return`${Dy}${e}`}function Ly(e,t,n){if(!e)return{openTabs:[],activeDocName:null,updatedAt:null};try{let r=e.getItem(t);return r?Py(JSON.parse(r),n):{openTabs:[],activeDocName:null,updatedAt:null}}catch(e){return console.warn(`[editor-tabs] failed to read local tab session:`,e),{openTabs:[],activeDocName:null,updatedAt:null}}}function Ry(e,t,n){if(e)try{e.setItem(t,JSON.stringify(n))}catch(e){console.warn(`[editor-tabs] failed to write local tab session:`,e)}}var zy=Math.floor,By=(e,t)=>e<t?e:t,Vy=(e,t)=>e>t?e:t;Number.isNaN;var Hy=128,Uy=1<<17,Wy=1<<18,Gy=1<<19,Ky=1<<20,qy=1<<21,Jy=1<<22,Yy=1<<23,Xy=1<<24,Zy=1<<25,Qy=1<<26,$y=1<<27,eb=1<<28,tb=1<<29,nb=1<<30,rb=127;Uy-1,Wy-1,Gy-1,Ky-1,qy-1,Jy-1,Yy-1,Xy-1,Zy-1,Qy-1,$y-1,eb-1,tb-1,nb-1;var ib=2**53-1;Number.isInteger,Number.isNaN,Number.parseInt;var ab=String.fromCharCode;String.fromCodePoint,ab(65535);var ob=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},sb=typeof TextEncoder<`u`?new TextEncoder:null,cb=sb?e=>sb.encode(e):ob,lb=typeof TextDecoder>`u`?null:new TextDecoder(`utf-8`,{fatal:!0,ignoreBOM:!0});lb&&lb.decode(new Uint8Array).length===1&&(lb=null);var ub=(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},db=(e,t)=>{for(;t>rb;)ub(e,Hy|rb&t),t=zy(t/128);ub(e,rb&t)},fb=new Uint8Array(3e4),pb=fb.length/3,mb=sb&&sb.encodeInto?(e,t)=>{if(t.length<pb){let n=sb.encodeInto(t,fb).written||0;db(e,n);for(let t=0;t<n;t++)ub(e,fb[t])}else gb(e,cb(t))}:(e,t)=>{let n=unescape(encodeURIComponent(t)),r=n.length;db(e,r);for(let t=0;t<r;t++)ub(e,n.codePointAt(t))},hb=(e,t)=>{let n=e.cbuf.length,r=e.cpos,i=By(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(Vy(n*2,a)),e.cbuf.set(t.subarray(i)),e.cpos=a)},gb=(e,t)=>{db(e,t.byteLength),hb(e,t)},_b=e=>Error(e),vb=_b(`Unexpected end of array`),yb=_b(`Integer out of Range`),bb=(e,t)=>{let n=new Uint8Array(e.arr.buffer,e.pos+e.arr.byteOffset,t);return e.pos+=t,n},xb=e=>bb(e,Cb(e)),Sb=e=>e.arr[e.pos++],Cb=e=>{let t=0,n=1,r=e.arr.length;for(;e.pos<r;){let r=e.arr[e.pos++];if(t+=(r&rb)*n,n*=128,r<Hy)return t;if(t>ib)throw yb}throw vb},wb=lb?e=>lb.decode(xb(e)):e=>{let t=Cb(e);if(t===0)return``;{let n=String.fromCodePoint(Sb(e));if(--t<100)for(;t--;)n+=String.fromCodePoint(Sb(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))}},Tb=function(e){return e[e.Token=0]=`Token`,e[e.PermissionDenied=1]=`PermissionDenied`,e[e.Authenticated=2]=`Authenticated`,e}({}),Eb=(e,t)=>{db(e,Tb.Token),mb(e,t)},Db=(e,t,n,r)=>{switch(Cb(e)){case Tb.Token:t();break;case Tb.PermissionDenied:n(wb(e));break;case Tb.Authenticated:r(wb(e));break;default:}},Ob=e=>Array.from(e.entries()).map(([e,t])=>({clientId:e,...t})),kb=`\0`;function Ab(e,t){return e+kb+t}function jb(e){let t=e.indexOf(kb);return t===-1?{documentName:e,sessionId:null}:{documentName:e.substring(0,t),sessionId:e.substring(t+1)}}var Mb=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 Nb(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 Pb(e){return new Promise(t=>setTimeout(t,e))}function Fb(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 Ib(e,t){let n=Nb(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||Fb;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 Pb(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 Pb(o),r.attemptNum<1&&n.initialJitter){let e=i(r,n);e&&await Pb(e)}return a()}var Lb=Math.floor,Rb=(e,t)=>e<t?e:t,zb=(e,t)=>e>t?e:t;Number.isNaN;var Bb=64,Vb=128,Hb=1<<17,Ub=1<<18,Wb=1<<19,Gb=1<<20,Kb=1<<21,qb=1<<22,Jb=1<<23,Yb=1<<24,Xb=1<<25,Zb=1<<26,Qb=1<<27,$b=1<<28,ex=1<<29,tx=1<<30,nx=63,rx=127;Hb-1,Ub-1,Wb-1,Gb-1,Kb-1,qb-1,Jb-1,Yb-1,Xb-1,Zb-1,Qb-1,$b-1,ex-1,tx-1;var ix=2**53-1;Number.isInteger,Number.isNaN,Number.parseInt;var ax=()=>new Set,ox=Array.from;Array.isArray;var sx=String.fromCharCode;String.fromCodePoint,sx(65535);var cx=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},lx=typeof TextEncoder<`u`?new TextEncoder:null,ux=lx?e=>lx.encode(e):cx,dx=typeof TextDecoder>`u`?null:new TextDecoder(`utf-8`,{fatal:!0,ignoreBOM:!0});dx&&dx.decode(new Uint8Array).length===1&&(dx=null);var fx=class{constructor(){this.cpos=0,this.cbuf=new Uint8Array(100),this.bufs=[]}},px=()=>new fx,mx=e=>{let t=e.cpos;for(let n=0;n<e.bufs.length;n++)t+=e.bufs[n].length;return t},hx=e=>{let t=new Uint8Array(mx(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},gx=(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},_x=(e,t)=>{for(;t>rx;)gx(e,Vb|rx&t),t=Lb(t/128);gx(e,rx&t)},vx=new Uint8Array(3e4),yx=vx.length/3,bx=lx&&lx.encodeInto?(e,t)=>{if(t.length<yx){let n=lx.encodeInto(t,vx).written||0;_x(e,n);for(let t=0;t<n;t++)gx(e,vx[t])}else Sx(e,ux(t))}:(e,t)=>{let n=unescape(encodeURIComponent(t)),r=n.length;_x(e,r);for(let t=0;t<r;t++)gx(e,n.codePointAt(t))},xx=(e,t)=>{let n=e.cbuf.length,r=e.cpos,i=Rb(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(zb(n*2,a)),e.cbuf.set(t.subarray(i)),e.cpos=a)},Sx=(e,t)=>{_x(e,t.byteLength),xx(e,t)},Cx=e=>Error(e),wx=Cx(`Unexpected end of array`),Tx=Cx(`Integer out of Range`),Ex=class{constructor(e){this.arr=e,this.pos=0}},Dx=e=>new Ex(e),Ox=(e,t)=>{let n=new Uint8Array(e.arr.buffer,e.pos+e.arr.byteOffset,t);return e.pos+=t,n},kx=e=>Ox(e,jx(e)),Ax=e=>e.arr[e.pos++],jx=e=>{let t=0,n=1,r=e.arr.length;for(;e.pos<r;){let r=e.arr[e.pos++];if(t+=(r&rx)*n,n*=128,r<Vb)return t;if(t>ix)throw Tx}throw wx},Mx=e=>{let t=e.arr[e.pos++],n=t&nx,r=64,i=(t&Bb)>0?-1:1;if((t&Vb)===0)return i*n;let a=e.arr.length;for(;e.pos<a;){if(t=e.arr[e.pos++],n+=(t&rx)*r,r*=128,t<Vb)return i*n;if(n>ix)throw Tx}throw wx},Nx=dx?e=>dx.decode(kx(e)):e=>{let t=jx(e);if(t===0)return``;{let n=String.fromCodePoint(Ax(e));if(--t<100)for(;t--;)n+=String.fromCodePoint(Ax(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))}},Px=e=>{let t=e.pos,n=Nx(e);return e.pos=t,n},Fx=Date.now,Ix=()=>new Map,Lx=(e,t,n)=>{let r=e.get(t);return r===void 0&&e.set(t,r=n()),r},Rx=class{constructor(){this._observers=Ix()}on(e,t){Lx(this._observers,e,ax).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 ox((this._observers.get(e)||Ix()).values()).forEach(e=>e(...t))}destroy(){this._observers=Ix()}},zx=Symbol(`Equality`),Bx=Object.keys,Vx=e=>Bx(e).length,Hx=(e,t)=>Object.prototype.hasOwnProperty.call(e,t),Ux=(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[zx]!=null)return e[zx](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)||!Ux(e.get(n),t.get(n)))return!1;break;case void 0:case Object:if(Vx(e)!==Vx(t))return!1;for(let n in e)if(!Hx(e,n)||!Ux(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(!Ux(e[n],t[n]))return!1;break;default:return!1}return!0},Wx=3e4,Gx=class extends Rx{constructor(e){super(),this.doc=e,this.clientID=e.clientID,this.states=new Map,this.meta=new Map,this._checkInterval=setInterval(()=>{let e=Fx();this.getLocalState()!==null&&Wx/2<=e-this.meta.get(this.clientID).lastUpdated&&this.setLocalState(this.getLocalState());let t=[];this.meta.forEach((n,r)=>{r!==this.clientID&&Wx<=e-n.lastUpdated&&this.states.has(r)&&t.push(r)}),t.length>0&&Kx(this,t,`timeout`)},Lb(Wx/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:Fx()});let a=[],o=[],s=[],c=[];e===null?c.push(t):i==null?e!=null&&a.push(t):(o.push(t),Ux(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}},Kx=(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:Fx()})}r.push(i)}}r.length>0&&(e.emit(`change`,[{added:[],updated:[],removed:r},n]),e.emit(`update`,[{added:[],updated:[],removed:r},n]))},qx=(e,t,n=e.states)=>{let r=t.length,i=px();_x(i,r);for(let a=0;a<r;a++){let r=t[a],o=n.get(r)||null,s=e.meta.get(r).clock;_x(i,r),_x(i,s),bx(i,JSON.stringify(o))}return hx(i)},Jx=(e,t,n)=>{let r=Dx(t),i=Fx(),a=[],o=[],s=[],c=[],l=jx(r);for(let t=0;t<l;t++){let t=jx(r),n=jx(r),l=JSON.parse(Nx(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&&(Ux(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])},Yx=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={}}},Xx=class{constructor(e){this.data=e,this.encoder=px(),this.decoder=Dx(new Uint8Array(this.data))}peekVarString(){return Px(this.decoder)}readVarUint(){return jx(this.decoder)}readVarString(){return Nx(this.decoder)}readVarUint8Array(){return kx(this.decoder)}writeVarUint(e){return _x(this.encoder,e)}writeVarString(e){return bx(this.encoder,e)}writeVarUint8Array(e){return Sx(this.encoder,e)}length(){return mx(this.encoder)}},Zx=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}({}),Qx=function(e){return e.Connecting=`connecting`,e.Connected=`connected`,e.Disconnected=`disconnected`,e}({}),$x=class{constructor(){this.encoder=px()}get(e){return e.encoder}toUint8Array(){return hx(this.encoder)}},eS=class extends $x{constructor(...e){super(...e),this.type=Zx.CLOSE,this.description=`Ask the server to close the connection`}get(e){return bx(this.encoder,e.documentName),_x(this.encoder,this.type),this.encoder}},tS=class e extends Yx{static{this.DEDUPLICATABLE_TYPES=new Set([Zx.Awareness,Zx.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=Qx.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=Qx.Connected,this.emit(`status`,{status:Qx.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===Qx.Disconnected&&this.shouldConnect&&this.connect(),this.receivedOnOpenPayload&&this.status===Qx.Connected&&e.onOpen(this.receivedOnOpenPayload)}detach(e){let t=e.effectiveName;this.configuration.providerMap.has(t)&&(e.send(eS,{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===Qx.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:Ib(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=Qx.Connecting,this.emit(`status`,{status:Qx.Connecting}),this.connectionAttempt={resolve:e,reject:t}})}onMessage(e){this.resolveConnectionAttempt(),this.lastMessageReceived=Fx();let t=new Uint8Array(e.data);if(t.length===1&&t[0]===Zx.Ping){this.sendPong();return}let n=new Xx(t).peekVarString();this.configuration.providerMap.get(n)?.onMessage(e)}sendPong(){let e=px();_x(e,Zx.Pong),this.send(hx(e))}resolveConnectionAttempt(){this.connectionAttempt&&(this.connectionAttempt.resolve(),this.connectionAttempt=null,this.status=Qx.Connected,this.emit(`status`,{status:Qx.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===Qx.Connected&&this.lastMessageReceived&&(this.configuration.messageReconnectTimeout>=Fx()-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=Dx(e);return{documentName:Nx(t),messageType:jx(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===Mb.Open?this.webSocket.send(e):this.addToQueue(e)}onClose({event:e}){this.closeTries=0,this.cleanupWebSocket(),this.connectionAttempt&&this.rejectConnectionAttempt(),this.status=Qx.Disconnected,this.emit(`status`,{status:Qx.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()}},nS=0,rS=1,iS=2,aS=(e,t)=>{_x(e,nS),Sx(e,Mp(t))},oS=(e,t,n)=>{_x(e,rS),Sx(e,Ep(t,n))},sS=(e,t,n)=>oS(t,n,kx(e)),cS=(e,t,n,r)=>{try{Cp(t,kx(e),n)}catch(e){r?.(e),console.error(`Caught error while handling a Yjs update`,e)}},lS=(e,t)=>{_x(e,iS),Sx(e,t)},uS=cS,dS=(e,t,n,r,i)=>{let a=jx(e);switch(a){case nS:sS(e,t,n);break;case rS:cS(e,n,r,i);break;case iS:uS(e,n,r,i);break;default:throw Error(`Unknown message type`)}return a},fS=class{constructor(e){this.message=e}apply(e,t){let{message:n}=this,r=n.readVarUint(),i=n.length();switch(r){case Zx.Sync:this.applySyncMessage(e,t);break;case Zx.Awareness:this.applyAwarenessMessage(e);break;case Zx.Auth:this.applyAuthMessage(e);break;case Zx.QueryAwareness:this.applyQueryAwarenessMessage(e);break;case Zx.Stateless:e.receiveStateless(Nx(n.decoder));break;case Zx.SyncStatus:this.applySyncStatusMessage(e,Mx(n.decoder)===1);break;case Zx.CLOSE:let i={code:1e3,reason:Nx(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($x,{encoder:n.encoder})}applySyncMessage(e,t){let{message:n}=this;n.writeVarUint(Zx.Sync);let r=dS(n.decoder,n.encoder,e.document,e);t&&r===rS&&(e.synced=!0)}applySyncStatusMessage(e,t){t&&e.decrementUnsyncedChanges()}applyAwarenessMessage(e){if(!e.awareness)return;let{message:t}=this;Jx(e.awareness,t.readVarUint8Array(),e)}applyAuthMessage(e){let{message:t}=this;Db(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(Zx.Awareness),t.writeVarUint8Array(qx(e.awareness,Array.from(e.awareness.getStates().keys())))}},pS=class{constructor(e,t={}){this.message=new e,this.encoder=this.message.get(t)}create(){return hx(this.encoder)}send(e){e?.send(this.create())}},mS=`4.0.0-rc.1`,hS=class extends $x{constructor(...e){super(...e),this.type=Zx.Auth,this.description=`Authentication`}get(e){if(e.token===void 0)throw Error("The authentication message requires `token` as an argument.");return bx(this.encoder,e.documentName),_x(this.encoder,this.type),Eb(this.encoder,e.token),bx(this.encoder,mS),this.encoder}},gS=class extends $x{constructor(...e){super(...e),this.type=Zx.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`);bx(this.encoder,e.documentName),_x(this.encoder,this.type);let t;return t=e.states===void 0?qx(e.awareness,e.clients):qx(e.awareness,e.clients,e.states),Sx(this.encoder,t),this.encoder}},_S=class extends $x{constructor(...e){super(...e),this.type=Zx.Stateless,this.description=`A stateless message`}get(e){return bx(this.encoder,e.documentName),_x(this.encoder,this.type),bx(this.encoder,e.payload??``),this.encoder}},vS=class extends $x{constructor(...e){super(...e),this.type=Zx.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 bx(this.encoder,e.documentName),_x(this.encoder,this.type),aS(this.encoder,e.document),this.encoder}},yS=class extends $x{constructor(...e){super(...e),this.type=Zx.Sync,this.description=`A document update`}get(e){return bx(this.encoder,e.documentName),_x(this.encoder,this.type),lS(this.encoder,e.update),this.encoder}},bS=class extends Error{constructor(...e){super(...e),this.code=1001}},xS=class extends Yx{get effectiveName(){return this.configuration.sessionAwareness?Ab(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 sp,this.configuration.awareness=e.awareness===void 0?new Gx(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:Ob(this.awareness.getStates())})}),this.awareness?.on(`change`,()=>{this.emit(`awarenessChange`,{states:Ob(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 tS(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(vS,{document:this.document,documentName:this.effectiveName})}pageHide(){this.awareness&&Kx(this.awareness,[this.document.clientID],`page hide`)}registerEventListeners(){typeof window>`u`||!(`addEventListener`in window)||window.addEventListener(`pagehide`,this.boundPageHide)}sendStateless(e){this.send(_S,{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(hS,{token:e??``,documentName:this.effectiveName})}documentUpdateHandler(e,t){t!==this&&(this.incrementUnsyncedChanges(),this.send(yS,{update:e,documentName:this.effectiveName}))}awarenessUpdateHandler({added:e,updated:t,removed:n},r){let i=e.concat(t).concat(n);this.send(gS,{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(vS,{document:this.document,documentName:this.effectiveName}),this.awareness&&this.awareness.getLocalState()!==null&&this.send(gS,{awareness:this.awareness,clients:[this.document.clientID],documentName:this.effectiveName})}send(e,t){if(!this._isAttached)return;let n=new pS(e,t);this.emit(`outgoingMessage`,{message:n.message}),n.send(this.configuration.websocketProvider)}onMessage(e){let t=new Xx(e.data),{documentName:n}=jb(t.readVarString());t.writeVarString(this.effectiveName),this.emit(`message`,{event:e,message:new Xx(e.data)}),new fS(t).apply(this,!0)}onClose(){this.isAuthenticated=!1,this.synced=!1,this.awareness&&Kx(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&&(Kx(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 bS(`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)}},SS=e=>mu((t,n)=>{e.onerror=e=>n(Error(e.target.error)),e.onsuccess=e=>t(e.target.result)}),CS=(e,t)=>mu((n,r)=>{let i=indexedDB.open(e);i.onupgradeneeded=e=>t(e.target.result),i.onerror=e=>r(Bl(e.target.error)),i.onsuccess=e=>{let t=e.target.result;t.onversionchange=()=>{t.close()},n(t)}}),wS=e=>SS(indexedDB.deleteDatabase(e)),TS=(e,t)=>t.forEach(t=>e.createObjectStore.apply(e,t)),ES=(e,t,n=`readwrite`)=>{let r=e.transaction(t,n);return t.map(e=>LS(r,e))},DS=(e,t)=>SS(e.count(t)),OS=(e,t)=>SS(e.get(t)),kS=(e,t)=>SS(e.delete(t)),AS=(e,t,n)=>SS(e.put(t,n)),jS=(e,t)=>SS(e.add(t)),MS=(e,t,n)=>SS(e.getAll(t,n)),NS=(e,t,n)=>{let r=null;return IS(e,t,e=>(r=e,!1),n).then(()=>r)},PS=(e,t=null)=>NS(e,t,`prev`),FS=(e,t)=>mu((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()}}),IS=(e,t,n,r=`next`)=>FS(e.openKeyCursor(t,r),e=>n(e.key)),LS=(e,t)=>e.objectStore(t),RS=(e,t)=>IDBKeyRange.upperBound(e,t),zS=(e,t)=>IDBKeyRange.lowerBound(e,t),BS=`custom`,VS=`updates`,HS=(e,t=()=>{},n=()=>{})=>{let[r]=ES(e.db,[VS]);return MS(r,zS(e._dbref,!1)).then(i=>{e._destroyed||(t(r),xm(e.doc,()=>{i.forEach(t=>Cp(e.doc,t))},e,!1),n(r))}).then(()=>PS(r).then(t=>{e._dbref=t+1})).then(()=>DS(r).then(t=>{e._dbsize=t})).then(()=>r)},US=(e,t=!0)=>HS(e).then(n=>{(t||e._dbsize>=500)&&jS(n,Ep(e.doc)).then(()=>kS(n,RS(e._dbref,!0))).then(()=>DS(n).then(t=>{e._dbsize=t}))}),WS=class extends Nc{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=CS(e,e=>TS(e,[[`updates`,{autoIncrement:!0}],[`custom`]])),this.whenSynced=mu(e=>this.on(`synced`,()=>e(this))),this._db.then(e=>{this.db=e,HS(this,async e=>{await DS(e)>0&&jS(e,Ep(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]=ES(this.db,[VS]);jS(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(()=>{US(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(()=>{wS(this.name)})}get(e){return this._db.then(t=>{let[n]=ES(t,[BS],`readonly`);return OS(n,e)})}set(e,t){return this._db.then(n=>{let[r]=ES(n,[BS]);return AS(r,t,e)})}del(e){return this._db.then(t=>{let[n]=ES(t,[BS]);return kS(n,e)})}};function GS(){return!0}var KS=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}`;let i=GS()?0:performance.now();this._idb=new WS(this._dbName,r),this.whenSynced=this._idb.whenSynced.then(()=>{if(!GS()){let e=performance.now();X(`ok/pool/idb-whensynced`,{docName:n,durationMs:Math.round((e-i)*1e3)/1e3},{startTime:i,duration:e-i})}return this})}get synced(){return this._idb.synced}async destroy(){let e=GS()?0:performance.now();try{await this._idb.destroy()}finally{if(!GS()){let t=performance.now();X(`ok/pool/idb-destroy`,{dbName:this._dbName,durationMs:Math.round((t-e)*1e3)/1e3},{startTime:e,duration:t-e})}}}async clearData(){let e=GS()?0:performance.now();try{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}`))}})}finally{if(!GS()){let t=performance.now();X(`ok/pool/idb-cleardata`,{dbName:this._dbName,durationMs:Math.round((t-e)*1e3)/1e3},{startTime:e,duration:t-e})}}}};function qS(e){return new KS(e)}function JS(e){return Mp(e)}function YS(e,t){return t===null?Ep(e):Ep(e,t)}function XS(e,t){if(e===null)return t;if(t===null)return e;let n=Op(e),r=Op(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 Mp(i)}function ZS(e){let t={};if(fn.inject(dn.active(),t),!t.traceparent)return e;let n=e.includes(`?`)?`&`:`?`,r=[`traceparent=${encodeURIComponent(t.traceparent)}`];return t.tracestate&&r.push(`tracestate=${encodeURIComponent(t.tracestate)}`),`${e}${n}${r.join(`&`)}`}var QS=({key:e,editor:t,onPaste:n,onDrop:r,allowedMimeTypes:i})=>new v({key:e||new T(`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))}}}),$S=Fe.create({name:`fileHandler`,addOptions(){return{onPaste:void 0,onDrop:void 0,allowedMimeTypes:void 0}},addProseMirrorPlugins(){return[QS({key:new T(this.name),editor:this.editor,allowedMimeTypes:this.options.allowedMimeTypes,onDrop:this.options.onDrop,onPaste:this.options.onPaste})]}}),eC=Fe.create({name:`keyboardNav`,priority:50,addKeyboardShortcuts(){return{Escape:({editor:e})=>{let{state:t}=e;if(t.selection instanceof z){let n=t.selection.from+t.selection.node.nodeSize,r=t.doc.resolve(Math.min(n,t.doc.content.size)),i=Ct.near(r);return e.view.dispatch(t.tr.setSelection(i)),!0}return t.selection instanceof Ct?e.commands.selectParentNode():!1},ArrowUp:({editor:e})=>{let{state:t}=e;if(!(t.selection instanceof z))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=z.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 z))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=z.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 Ct)||!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(Ct.create(s.doc,f)),e.view.dispatch(s.scrollIntoView()),!0}}}}),tC=new WeakMap;function nC(e,t){if(t===null){tC.delete(e);return}tC.set(e,t)}function rC(e){return tC.get(e)??null}function iC(e){return`pagesBySlug`in e}function aC(e){return iC(e)?e.pages:e}function oC(e,t){return iC(e)?e.assetPaths??new Set:t??new Set}function sC(e,t){let n=ze(e);if(n){if(iC(t))return t.pagesBySlug.get(n);for(let e of t)if(ze(e)===n)return e}}function cC(e){let t=e.trim();if(!t)return null;let n=ze(t);return n?{target:n,alias:n===t?null:t,anchor:null}:null}function lC(e){let t=e.trim();if(!t)return[];let n=ze(t);return n.length>0&&n!==t?[n]:[]}function uC(e){let t=((e.trim().split(`#`)[0]??``).trim().split(`?`)[0]??``).trim();return t.startsWith(`/`)?t.slice(1):t}function dC(e,t){let n=uC(e);if(!n)return null;if(t.has(n))return n;let r=n.toLowerCase();for(let e of t)if(e.toLowerCase()===r)return e;if(n.includes(`/`))return null;let i=[...t].filter(e=>{let t=e.lastIndexOf(`/`);return(t===-1?e:e.slice(t+1)).toLowerCase()===r});return i.length===0?null:i.sort((e,t)=>e.localeCompare(t))[0]??null}function fC(e,t,n){let r=e.trim();if(!r)return!1;if(dC(r,oC(t,n)))return!0;let i=aC(t);return i.has(r)||lC(r).some(e=>i.has(e))?!0:sC(r,t)!==void 0}var pC=new T(`imageUpload`);function mC(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 hC=new v({key:pC,state:{init(){return{decorations:P.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(pC);if(!i)return{decorations:n,uploads:r};if(i.type===`add`){let t=Be.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 pC.getState(e)?.decorations??P.empty}}});function gC(e){let t=e.lastIndexOf(`/`);return t===-1?``:e.slice(0,t)}function _C(e){let t=e.lastIndexOf(`/`);return t===-1?e:e.slice(t+1)}function vC(e){return e.split(`/`).filter(e=>e!==``)}function yC(e,t){let n=gC(e),r=gC(t),i=_C(e);if(n===r)return i;let a=vC(r),o=vC(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 bC(e){return rC(e)}function xC(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 SC(e){let t=p(e);return t===`md`||t===`mdx`?{kind:`wiki-link`,ext:t}:l.has(t)?{kind:`jsx-img`,ext:t}:o.has(t)?{kind:`jsx-video`,ext:t}:ee.has(t)?{kind:`jsx-audio`,ext:t}:ke.has(t)?{kind:`wikiembed`,ext:t}:{kind:`markdown-link`,ext:t}}async function CC(e,t,n){let r=bC(t),i=r?`${r}.md`:``;if(!i){Wt.error(`Cannot upload: no document is open`);return}let a=crypto.randomUUID(),o=mC(e);t.view.dispatch(t.state.tr.setMeta(pC,{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),wC(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),wC(t,a,e);return}if(typeof l.src!=`string`){console.error(`[uploadAndInsert] Response missing src:`,l),wC(t,a);return}let u=l.src,d=l.deduped===!0,f=gC(i),p=typeof l.path==`string`&&l.path.length>0?l.path:f?`${f}/${u}`:u;d&&Wt.info(`Already at ${p} — reusing.`);let m=SC(e.name),{state:h}=t,g=pC.getState(h)?.uploads.get(a)??n,_=h.tr.setMeta(pC,{type:`remove`,id:a}),v=yC(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`),wC(t,a);return}let e=xC(m.kind,y);t.chain().command(({tr:e})=>(e.setMeta(pC,{type:`remove`,id:a}),!0)).focus().insertContentAt(g,e).command(({tr:e,dispatch:t})=>{if(!t)return!0;let n=e.mapping.map(g);return e.doc.nodeAt(n)?.type.name===`jsxComponent`&&e.setSelection(z.create(e.doc,n)),!0}).run();return}if(m.kind===`wikiembed`){let e=h.schema.nodes.wikiLinkEmbed;if(!e){console.error(`[uploadAndInsert] wikiLinkEmbed node missing from schema`),wC(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`),wC(t,a);return}let r=cC(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 wC(e,t,n){e.view.dispatch(e.state.tr.setMeta(pC,{type:`remove`,id:t})),Wt.error(n??`Upload failed`)}var TC={ChevronRight:hr,Image:Mr,MessageSquareWarning:zr,Sigma:Kr,SquarePlay:qr,Volume2:$r,Workflow:ei};function EC(e){return e&&Object.hasOwn(TC,e)?TC[e]:fr}var DC={ChevronRight:hr};function OC(e){if(!e||!e.startsWith(`lucide:`))return null;let t=e.slice(7);return Object.hasOwn(DC,t)?DC[t]:null}function kC(e){let t=(0,Y.c)(24),n;t[0]===e.icon?n=t[1]:(n=OC(e.icon),t[0]=e.icon,t[1]=n);let r=n,i=r?`custom`:void 0,a;t[2]===Symbol.for(`react.memo_cache_sentinel`)?(a=(0,J.jsx)(hr,{size:14,className:`accordion-chevron`,"aria-hidden":`true`}),t[2]=a):a=t[2];let o;t[3]===r?o=t[4]:(o=r?(0,J.jsx)(r,{size:16,className:`accordion-icon`,"aria-hidden":`true`}):null,t[3]=r,t[4]=o);let s=e.title??`Accordion`,c;t[5]===s?c=t[6]:(c=(0,J.jsx)(`span`,{className:`accordion-title`,children:s}),t[5]=s,t[6]=c);let l;t[7]===e.description?l=t[8]:(l=e.description?(0,J.jsx)(`span`,{className:`accordion-description`,children:e.description}):null,t[7]=e.description,t[8]=l);let u;t[9]!==c||t[10]!==l?(u=(0,J.jsxs)(`span`,{className:`accordion-title-group`,children:[c,l]}),t[9]=c,t[10]=l,t[11]=u):u=t[11];let d;t[12]!==o||t[13]!==u?(d=(0,J.jsxs)(`summary`,{className:`accordion-summary`,contentEditable:!1,children:[a,o,u]}),t[12]=o,t[13]=u,t[14]=d):d=t[14];let f;t[15]===e.children?f=t[16]:(f=(0,J.jsx)(`div`,{className:`accordion-body`,children:e.children}),t[15]=e.children,t[16]=f);let p;return t[17]!==e.defaultOpen||t[18]!==e.id||t[19]!==e.name||t[20]!==i||t[21]!==d||t[22]!==f?(p=(0,J.jsxs)(`details`,{className:`accordion`,"data-accordion-icon":i,open:e.defaultOpen,id:e.id,name:e.name,children:[d,f]}),t[17]=e.defaultOpen,t[18]=e.id,t[19]=e.name,t[20]=i,t[21]=d,t[22]=f,t[23]=p):p=t[23],p}function AC(e){return e!==!1}function jC(e){let t=(0,Y.c)(10),n=e.src,r=e.title,i;t[0]===e.controls?i=t[1]:(i=AC(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,J.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 MC={note:Nr,tip:Pr,important:zr,warning:nt,caution:Vr,abstract:br,info:dr,todo:Ir,success:qe,question:vr,failure:yr,danger:ti,bug:pr,example:Er,quote:Wr},NC={Info:Nr,Lightbulb:Pr,MessageSquareWarning:zr,AlertTriangle:nt,AlertOctagon:Vr,ClipboardList:br,BookOpen:dr,ListTodo:Ir,CircleCheck:qe,CircleHelp:vr,CircleX:yr,Zap:ti,Bug:pr,FlaskConical:Er,Quote:Wr};function PC(e,t){if(!e||!e.startsWith(`lucide:`))return MC[t];let n=e.slice(7);return Object.hasOwn(NC,n)?NC[n]:MC[t]}var FC=new Set([`note`,`tip`,`important`,`warning`,`caution`,`abstract`,`info`,`todo`,`success`,`question`,`failure`,`danger`,`bug`,`example`,`quote`]);function IC(e){return typeof e==`string`&&FC.has(e)?e:`note`}function LC(e){let t=(0,Y.c)(29),n,r;t[0]!==e.icon||t[1]!==e.type?(r=IC(e.type),n=PC(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,J.jsxs)(`span`,{className:`callout-header`,contentEditable:!1,children:[(0,J.jsx)(i,{size:16,className:`callout-icon`,"aria-hidden":`true`}),e.title?(0,J.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,J.jsx)(`span`,{className:`callout-title`,children:`Details`}),t[9]=c,t[10]=i);let a;t[11]===Symbol.for(`react.memo_cache_sentinel`)?(a=(0,J.jsx)(mr,{size:16,className:`callout-chevron`,"aria-hidden":`true`}),t[11]=a):a=t[11];let s;t[12]===i?s=t[13]:(s=(0,J.jsxs)(`summary`,{className:`callout-summary`,contentEditable:!1,children:[i,a]}),t[12]=i,t[13]=s);let l;t[14]===e.children?l=t[15]:(l=(0,J.jsx)(`div`,{className:`callout-body`,children:e.children}),t[14]=e.children,t[15]=l);let u;return t[16]!==n||t[17]!==o||t[18]!==s||t[19]!==l||t[20]!==r?(u=(0,J.jsxs)(`details`,{className:`callout callout-collapsible`,"data-callout-type":r,open:n,style:o,children:[s,l]}),t[16]=n,t[17]=o,t[18]=s,t[19]=l,t[20]=r,t[21]=u):u=t[21],u}let l;t[22]===e.children?l=t[23]:(l=(0,J.jsx)(`div`,{className:`callout-body`,children:e.children}),t[22]=e.children,t[23]=l);let u;return t[24]!==c||t[25]!==o||t[26]!==l||t[27]!==r?(u=(0,J.jsxs)(`div`,{className:`callout callout-static`,"data-callout-type":r,style:o,children:[c,l]}),t[24]=c,t[25]=o,t[26]=l,t[27]=r,t[28]=u):u=t[28],u}function RC(){return q.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`},q.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 zC(){return q.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`},q.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 BC(e){return typeof Element>`u`?!1:e instanceof Element}var VC=(e,t)=>BC(t)&&t.tagName.toUpperCase()===e,HC=e=>VC(`DIV`,e)||VC(`SPAN`,e),UC=e=>VC(`IMG`,e),WC=e=>e.complete&&e.naturalHeight!==0,GC=e=>VC(`SVG`,e),KC=({height:e,offset:t,width:n})=>Math.min((window.innerWidth-t*2)/n,(window.innerHeight-t*2)/e),qC=({containerHeight:e,containerWidth:t,offset:n,targetHeight:r,targetWidth:i})=>{let a=KC({height:r,offset:n,width:i}),o=i>r?i/t:r/e;return a>1?o:a*o},JC=({containerHeight:e,containerWidth:t,hasScalableSrc:n,offset:r,targetHeight:i,targetWidth:a})=>e===0||t===0?1:!n&&i!==0&&a!==0?qC({containerHeight:e,containerWidth:t,offset:r,targetHeight:i,targetWidth:a}):KC({height:e,offset:r,width:t}),YC=/url(?:\(['"]?)(?<url>.*?)(?:['"]?\))/,XC=e=>{if(e!==null){if(UC(e))return e.currentSrc===``?void 0:e.currentSrc;if(HC(e)){let{backgroundImage:t}=window.getComputedStyle(e);if(t!==``)return YC.exec(t)?.[1]}}},ZC=e=>{if(e!==null)return UC(e)?e.alt:e.getAttribute(`aria-label`)??void 0},QC=({containerHeight:e,containerLeft:t,containerTop:n,containerWidth:r,hasScalableSrc:i,offset:a,targetHeight:o,targetWidth:s})=>{let c=JC({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})`}},$C=({position:e,relativeNum:t})=>{let n=parseFloat(e);return e.endsWith(`%`)?t*n/100:n},ew=({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=$C({position:p,relativeNum:r-l*f}),g=$C({position:m,relativeNum:e-c*f}),_=JC({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=$C({position:a,relativeNum:r-l}),f=$C({position:u,relativeNum:e-c}),p=JC({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=JC({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{}},tw=({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=$C({position:p,relativeNum:a-l*f}),g=$C({position:m,relativeNum:n-c*f}),_=JC({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=$C({position:t,relativeNum:a-l}),f=$C({position:u,relativeNum:n-c}),p=JC({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=$C({position:u,relativeNum:a}),p=$C({position:d,relativeNum:n}),m=f/l,h=p/c,g=Math.min(m,h),[_=`50%`,v=`50%`]=e.split(` `),y=$C({position:_,relativeNum:a-l*g}),b=$C({position:v,relativeNum:n-c*g}),x=JC({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})`}}},nw=/\.svg$/i,rw=({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&&nw.test(t),l=s.getBoundingClientRect(),u=window.getComputedStyle(s),d=i!=null&&HC(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=QC({containerHeight:l.height,containerLeft:l.left,containerTop:l.top,containerWidth:l.width,hasScalableSrc:c,offset:a,targetHeight:p,targetWidth:m}),g=f?ew({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?tw({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},iw=e=>{if(e==null)return{};if(GC(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}},aw=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}`)}})})},ow=[`img`,`svg`,`[role="img"]`,`[data-zoom]`].map(e=>`${e}:not([aria-hidden="true"])`).join(`,`),sw={overflow:``,width:``};function cw(){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 lw(e){e.preventDefault()}function uw(e){return q.createElement(dw,{...e})}var dw=class extends q.Component{constructor(){super(...arguments),this.state={id:``,isZoomImgLoaded:!1,loadedImgEl:void 0,modalState:`UNLOADED`,shouldRefresh:!1,styleGhost:{}},this.refContent=q.createRef(),this.refDialog=q.createRef(),this.refModalContent=q.createRef(),this.refModalImg=q.createRef(),this.refWrap=q.createRef(),this.imgEl=null,this.isScaling=!1,this.prevBodyAttrs=sw,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(ow),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:iw(this.imgEl)}))}),this.imgElResizeObserver.observe(this.imgEl),this.contentChangeObserver??(this.contentChangeObserver=new MutationObserver(()=>{this.setState({styleGhost:iw(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=XC(this.imgEl);if(e==null||e===``)return;let t=new Image,{imgEl:n}=this;if(UC(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:iw(this.imgEl)})};t.decode().then(r).catch(()=>{if(WC(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||GC(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=sw},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(WC(n)){r();return}n.onload=r})}},this.UNSAFE_handleSvg=()=>{let{imgEl:e,refModalImg:t,styleModalImg:n}=this;if(GC(e)){let r=e.cloneNode(!0);aw(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=HC(a),j=UC(a),M=GC(a),N=ZC(a),P=XC(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`,W={visibility:T===`UNLOADED`?`visible`:`hidden`};this.styleModalImg=z&&a!==null?rw({hasZoomImg:R,imgSrc:P,isSvg:M,isZoomed:f&&V,loadedImgEl:w,offset:g,shouldRefresh:E,targetEl:a}):{};let ee=null;if(z){let t=j||A?q.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?q.createElement(`div`,{"data-rmiz-modal-img":!0,ref:b,style:this.styleModalImg}):null,n=q.createElement(`button`,{"aria-label":o,"data-rmiz-btn-unzoom":``,onClick:e,type:`button`},q.createElement(u,null));ee=m==null?q.createElement(q.Fragment,null,t,n):q.createElement(m,{buttonUnzoom:n,modalState:T,img:t,isZoomImgLoaded:C,onUnzoom:r})}return q.createElement(p,{"aria-owns":z?O:void 0,"data-rmiz":``,ref:x},q.createElement(p,{"data-rmiz-content":H,ref:_,style:W},c),z&&q.createElement(p,{"data-rmiz-ghost":``,style:D},q.createElement(`button`,{"aria-label":B,"data-rmiz-btn-zoom":``,onClick:i,type:`button`},q.createElement(d,null))),z&&xi.createPortal(q.createElement(`dialog`,{"aria-labelledby":k,"aria-modal":`true`,className:l,"data-rmiz-modal":``,id:O,onClick:t,onClose:n,onCancel:lw,ref:v,role:`dialog`},q.createElement(`div`,{"data-rmiz-modal-overlay":U}),q.createElement(`div`,{"data-rmiz-modal-content":``,ref:y},ee)),cw()))}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)}};dw.defaultProps={a11yNameButtonUnzoom:`Minimize image`,a11yNameButtonZoom:`Expand image`,canSwipeToUnzoom:!0,IconUnzoom:RC,IconZoom:zC,isDisabled:!1,swipeToUnzoomThreshold:10,wrapElement:`div`,zoomMargin:0};function fw({onZoomChange:e,...t}){let[n,r]=q.useState(!1),i=q.useCallback((t,{event:n})=>{r(t),e?.(t,{event:n})},[e]);return q.createElement(uw,{...t,isZoomed:n,onZoomChange:i})}function pw(e){return e??`lazy`}function mw(e){let t=(0,Y.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=pw(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,J.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 hw(e){let t=(0,Y.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,J.jsx)(fw,{wrapElement:`span`,zoomMargin:20,zoomImg:n,children:(0,J.jsx)(mw,{...e})}),t[1]=e,t[2]=r),r}var gw=(0,q.lazy)(async()=>{let{default:e}=await n(async()=>{let{default:e}=await import(`./katex-DBuiuHex.js`);return{default:e}},[],import.meta.url);function t(t){let n=(0,Y.c)(7),r;n[0]===t.formula?r=n[1]:(r=e.renderToString(t.formula,{displayMode:!0,throwOnError:!1,strict:`ignore`,trust:!1}),n[0]=t.formula,n[1]=r);let i=r,a;n[2]===i?a=n[3]:(a={__html:i},n[2]=i,n[3]=a);let o;return n[4]!==t.id||n[5]!==a?(o=(0,J.jsx)(`div`,{className:`math math-display`,"data-component-type":`math`,id:t.id,dangerouslySetInnerHTML:a}),n[4]=t.id,n[5]=a,n[6]=o):o=n[6],o}return{default:t}});function _w(e){let t=(0,Y.c)(3),n=e.formula||`\xA0`,r;return t[0]!==e.id||t[1]!==n?(r=(0,J.jsx)(`div`,{className:`math math-placeholder`,"data-component-type":`math`,id:e.id,children:n}),t[0]=e.id,t[1]=n,t[2]=r):r=t[2],r}function vw(e){let t=(0,Y.c)(6),n=e.formula??``;if(!n){let r;return t[0]!==n||t[1]!==e.id?(r=(0,J.jsx)(_w,{formula:n,id:e.id}),t[0]=n,t[1]=e.id,t[2]=r):r=t[2],r}let r;return t[3]!==n||t[4]!==e.id?(r=(0,J.jsx)(q.Suspense,{fallback:(0,J.jsx)(_w,{formula:n,id:e.id}),children:(0,J.jsx)(gw,{formula:n,id:e.id})}),t[3]=n,t[4]=e.id,t[5]=r):r=t[5],r}var yw=null;function bw(){return yw||=n(()=>import(`./mermaid.core-4xgx5kDJ.js`).then(e=>{let t=e.default;return t.initialize({startOnLoad:!1,securityLevel:`strict`,theme:`default`,suppressErrorRendering:!0}),t}),__vite__mapDeps([0,1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19,20,21,22,23]),import.meta.url).catch(e=>{throw yw=null,e}),yw}function xw(e){let t=(0,Y.c)(26),n=e.chart??``,r=(0,q.useId)(),i;if(t[0]!==r){let e;t[2]===Symbol.for(`react.memo_cache_sentinel`)?(e=/:/g,t[2]=e):e=t[2],i=r.replace(e,`_`),t[0]=r,t[1]=i}else i=t[1];let a=`mermaid-${i}`,o;t[3]===Symbol.for(`react.memo_cache_sentinel`)?(o={status:`idle`,svg:``,error:``},t[3]=o):o=t[3];let[s,c]=(0,q.useState)(o),l,u;if(t[4]!==n||t[5]!==a?(l=()=>{if(!n.trim()){c({status:`idle`,svg:``,error:``});return}let e=!1;return c(Sw),bw().then(async t=>{try{let r=await t.render(a,n);e||c({status:`ready`,svg:r.svg,error:``})}catch(t){let n=t;e||c({status:`error`,svg:``,error:n instanceof Error?n.message:String(n)})}}).catch(t=>{e||c({status:`error`,svg:``,error:t instanceof Error?t.message:String(t)})}),()=>{e=!0}},u=[n,a],t[4]=n,t[5]=a,t[6]=l,t[7]=u):(l=t[6],u=t[7]),(0,q.useEffect)(l,u),!n.trim()){let n;t[8]===Symbol.for(`react.memo_cache_sentinel`)?(n=(0,J.jsx)(`span`,{className:`mermaid-empty`,children:` `}),t[8]=n):n=t[8];let r;return t[9]===e.id?r=t[10]:(r=(0,J.jsx)(`div`,{className:`mermaid mermaid-placeholder`,"data-component-type":`mermaid`,id:e.id,children:n}),t[9]=e.id,t[10]=r),r}if(s.status===`error`){let r;t[11]===n?r=t[12]:(r=(0,J.jsx)(`pre`,{className:`mermaid-error-source`,children:n}),t[11]=n,t[12]=r);let i;t[13]===s.error?i=t[14]:(i=(0,J.jsx)(`p`,{className:`mermaid-error-message`,children:s.error}),t[13]=s.error,t[14]=i);let a;return t[15]!==e.id||t[16]!==s.error||t[17]!==r||t[18]!==i?(a=(0,J.jsxs)(`div`,{className:`mermaid mermaid-error`,"data-component-type":`mermaid`,title:s.error,id:e.id,children:[r,i]}),t[15]=e.id,t[16]=s.error,t[17]=r,t[18]=i,t[19]=a):a=t[19],a}let d=`mermaid mermaid-${s.status}`,f;t[20]===s.svg?f=t[21]:(f={__html:s.svg},t[20]=s.svg,t[21]=f);let p;return t[22]!==e.id||t[23]!==d||t[24]!==f?(p=(0,J.jsx)(`div`,{className:d,"data-component-type":`mermaid`,id:e.id,dangerouslySetInnerHTML:f}),t[22]=e.id,t[23]=d,t[24]=f,t[25]=p):p=t[25],p}function Sw(e){return{...e,status:`rendering`}}var Cw=24,ww=24,Tw=12,Ew=.1;function Dw(e,t,n,r){if(n<=0&&(e===`fit-width`||e===`two-odd`||e===`two-even`)||r<=0&&e===`fit-height`)return 1;switch(e){case`fit-width`:return Math.max(Ew,(n-Cw)/t.naturalWidth);case`fit-height`:return Math.max(Ew,(r-ww)/t.naturalHeight);case`single`:return 1;case`two-odd`:case`two-even`:return Math.max(Ew,((n-Cw)/2-Tw)/t.naturalWidth)}}var Ow=600,kw=.5,Aw=3,jw=.25,Mw=null;function Nw(){return Mw||(Mw=(async()=>{let e=await n(()=>import(`./pdf-DaFpV-4n.js`),__vite__mapDeps([24,1]),import.meta.url);if(!e.GlobalWorkerOptions.workerSrc){let t=(await n(async()=>{let{default:e}=await import(`./pdf.worker-Cq62cyp3.js`);return{default:e}},[],import.meta.url)).default;e.GlobalWorkerOptions.workerSrc=t}return e})(),Mw.catch(()=>{Mw=null})),Mw}function Pw(e){return e instanceof Error&&e.name===`RenderingCancelledException`}function Fw(e){let t=(0,Y.c)(84),n,r;if(t[0]!==e.anchor){let{height:i,viewerFragment:a}=ve(e.anchor);n=i??Ow,r=Vw(a),t[0]=e.anchor,t[1]=n,t[2]=r}else n=t[1],r=t[2];let i=r,a=(0,q.useRef)(null),o;t[3]===Symbol.for(`react.memo_cache_sentinel`)?(o=[],t[3]=o):o=t[3];let s=(0,q.useRef)(o),c;t[4]===Symbol.for(`react.memo_cache_sentinel`)?(c=[],t[4]=c):c=t[4];let l=(0,q.useRef)(c),u=(0,q.useRef)(null),d;t[5]===Symbol.for(`react.memo_cache_sentinel`)?(d=[],t[5]=d):d=t[5];let[f,p]=(0,q.useState)(d),[m,h]=(0,q.useState)(!0),[g,_]=(0,q.useState)(null),[v,y]=(0,q.useState)(i??1),[b,x]=(0,q.useState)(String(i??1)),[S,C]=(0,q.useState)(1),[w,T]=(0,q.useState)(`fit-width`),[E,D]=(0,q.useState)(!1),[O,k]=(0,q.useState)(!1),[A,j]=(0,q.useState)(0),[M,N]=(0,q.useState)(0),P=f.length,F,I;t[6]===e.src?(F=t[7],I=t[8]):(F=()=>{if(!e.src){h(!1);return}let t=!1,n=null;return h(!0),_(null),(async()=>{try{let r=await(await Nw()).getDocument({url:e.src,isEvalSupported:!1}).promise;if(t){await r.destroy();return}n=r,u.current=r;let i=[];for(let e=1;e<=r.numPages;e++){if(t)return;let n=(await r.getPage(e)).getViewport({scale:1});i.push({pageNumber:e,naturalWidth:n.width,naturalHeight:n.height})}if(t)return;p(i)}catch(e){let n=e;if(t)return;_(n instanceof Error?n.message:`Failed to load PDF`),h(!1)}})(),()=>{t=!0,n&&=(n.destroy(),null),u.current=null}},I=[e.src],t[6]=e.src,t[7]=F,t[8]=I),(0,q.useEffect)(F,I);let L,R;t[9]===Symbol.for(`react.memo_cache_sentinel`)?(L=()=>{let e=a.current;if(!e)return;let t=()=>{j(e.clientWidth),N(e.clientHeight)};t();let n=new ResizeObserver(t);return n.observe(e),()=>n.disconnect()},R=[],t[9]=L,t[10]=R):(L=t[9],R=t[10]),(0,q.useEffect)(L,R);let z,B;t[11]!==M||t[12]!==A||t[13]!==w||t[14]!==f||t[15]!==S?(z=()=>{let e=u.current;if(!e||f.length===0||A===0)return;let t=!1,n=null;return(async()=>{try{let r=window.devicePixelRatio||1;for(let i of f){if(t)return;let a=s.current[i.pageNumber-1];if(!a)continue;let o=Dw(w,i,A,M)*S,c=await e.getPage(i.pageNumber);if(t)return;let l=c.getViewport({scale:o});a.width=Math.floor(l.width*r),a.height=Math.floor(l.height*r),a.style.width=`${l.width}px`,a.style.height=`${l.height}px`;let u=a.getContext(`2d`);u&&(u.setTransform(r,0,0,r,0,0),n=c.render({canvas:a,canvasContext:u,viewport:l}),await n.promise,n=null)}t||h(!1)}catch(e){let n=e;if(t||Pw(n))return;console.warn(`[Pdf] page render failed:`,n),_(n instanceof Error?n.message:`Failed to render PDF`),h(!1)}})(),()=>{if(t=!0,n){try{n.cancel()}catch{}n=null}}},B=[f,w,S,A,M],t[11]=M,t[12]=A,t[13]=w,t[14]=f,t[15]=S,t[16]=z,t[17]=B):(z=t[16],B=t[17]),(0,q.useEffect)(z,B);let V,H;t[18]!==f||t[19]!==E?(V=()=>{if(!E)return;let e=u.current;if(!e||f.length===0)return;let t=!1,n=null;return(async()=>{try{let r=window.devicePixelRatio||1;for(let i of f){if(t)return;let a=l.current[i.pageNumber-1];if(!a)continue;let o=120/i.naturalWidth,s=await e.getPage(i.pageNumber);if(t)return;let c=s.getViewport({scale:o});a.width=Math.floor(c.width*r),a.height=Math.floor(c.height*r),a.style.width=`${c.width}px`,a.style.height=`${c.height}px`;let u=a.getContext(`2d`);u&&(u.setTransform(r,0,0,r,0,0),n=s.render({canvas:a,canvasContext:u,viewport:c}),await n.promise,n=null)}}catch(e){let t=e;Pw(t)||console.warn(`[Pdf] thumbnail render failed:`,t)}})(),()=>{if(t=!0,n){try{n.cancel()}catch{}n=null}}},H=[E,f],t[18]=f,t[19]=E,t[20]=V,t[21]=H):(V=t[20],H=t[21]),(0,q.useEffect)(V,H);let U,W;t[22]!==m||t[23]!==i?(U=()=>{if(m||!i)return;let e=a.current,t=s.current[i-1];e&&t&&(e.scrollTop=t.offsetTop-e.offsetTop)},W=[m,i],t[22]=m,t[23]=i,t[24]=U,t[25]=W):(U=t[24],W=t[25]),(0,q.useEffect)(U,W);let ee,te;t[26]===f?(ee=t[27],te=t[28]):(ee=()=>{let e=a.current;if(!e||f.length===0)return;let t=!1,n=()=>{t||(t=!0,requestAnimationFrame(()=>{t=!1;let n=e.scrollTop,r=1;for(let t of f){let i=s.current[t.pageNumber-1];i&&i.offsetTop-e.offsetTop<=n+40&&(r=t.pageNumber)}y(r),x(String(r))}))};return e.addEventListener(`scroll`,n,{passive:!0}),()=>e.removeEventListener(`scroll`,n)},te=[f],t[26]=f,t[27]=ee,t[28]=te),(0,q.useEffect)(ee,te);let ne,re;t[29]===O?(ne=t[30],re=t[31]):(ne=()=>{if(!O)return;let e=e=>{let t=e.target,n=a.current?.closest(`.ok-pdf`);if(!n||!t||!n.contains(t)){k(!1);return}let r=n.querySelector(`.ok-pdf-layout-menu`);r&&!r.contains(t)&&k(!1)};return document.addEventListener(`mousedown`,e),()=>document.removeEventListener(`mousedown`,e)},re=[O],t[29]=O,t[30]=ne,t[31]=re),(0,q.useEffect)(ne,re);let ie;t[32]===P?ie=t[33]:(ie=e=>{let t=Math.max(1,Math.min(P||1,e));y(t),x(String(t));let n=a.current,r=s.current[t-1];n&&r&&n.scrollTo({top:r.offsetTop-n.offsetTop,behavior:`smooth`})},t[32]=P,t[33]=ie);let ae=ie,oe;t[34]!==v||t[35]!==ae||t[36]!==b?(oe=()=>{let e=Number.parseInt(b,10);if(Number.isNaN(e)){x(String(v));return}ae(e)},t[34]=v,t[35]=ae,t[36]=b,t[37]=oe):oe=t[37];let se=oe,ce;t[38]===Symbol.for(`react.memo_cache_sentinel`)?(ce=()=>C(zw),t[38]=ce):ce=t[38];let le=ce,ue;t[39]===Symbol.for(`react.memo_cache_sentinel`)?(ue=()=>C(Rw),t[39]=ue):ue=t[39];let de=ue,fe;t[40]===Symbol.for(`react.memo_cache_sentinel`)?(fe=e=>{T(e),k(!1),C(1)},t[40]=fe):fe=t[40];let pe=fe,me=`${n}px`,he;t[41]===me?he=t[42]:(he={height:me},t[41]=me,t[42]=he);let ge;t[43]===Symbol.for(`react.memo_cache_sentinel`)?(ge=()=>D(Lw),t[43]=ge):ge=t[43];let _e=E?`Hide thumbnails`:`Show thumbnails`,ye;t[44]===Symbol.for(`react.memo_cache_sentinel`)?(ye=(0,J.jsx)(Hr,{size:14,"aria-hidden":`true`}),t[44]=ye):ye=t[44];let be;t[45]!==E||t[46]!==_e?(be=(0,J.jsx)(`button`,{type:`button`,onClick:ge,"aria-label":_e,"aria-pressed":E,className:`ok-pdf-btn`,title:`Toggle thumbnails`,children:ye}),t[45]=E,t[46]=_e,t[47]=be):be=t[47];let xe=e.title??`PDF`,Se;t[48]===xe?Se=t[49]:(Se=(0,J.jsx)(`span`,{className:`ok-pdf-title`,children:xe}),t[48]=xe,t[49]=Se);let Ce;t[50]!==O||t[51]!==w||t[52]!==b||t[53]!==se||t[54]!==P||t[55]!==S?(Ce=P>0&&(0,J.jsxs)(`div`,{className:`ok-pdf-controls`,children:[(0,J.jsx)(`form`,{className:`ok-pdf-page-form`,onSubmit:e=>{e.preventDefault(),se()},children:(0,J.jsx)(`input`,{type:`text`,inputMode:`numeric`,pattern:`[0-9]*`,className:`ok-pdf-page-input`,value:b,onChange:e=>x(e.target.value.replace(/[^0-9]/g,``)),onBlur:se,"aria-label":`Page number`})}),(0,J.jsxs)(`span`,{className:`ok-pdf-page-of`,children:[`of `,P]}),(0,J.jsx)(`span`,{className:`ok-pdf-divider`,"aria-hidden":`true`}),(0,J.jsx)(`button`,{type:`button`,onClick:de,disabled:S<=kw,"aria-label":`Zoom out`,className:`ok-pdf-btn`,title:`Zoom out`,children:(0,J.jsx)(ri,{size:14,"aria-hidden":`true`})}),(0,J.jsxs)(`span`,{className:`ok-pdf-zoom-display`,"aria-live":`polite`,children:[Math.round(S*100),`%`]}),(0,J.jsx)(`button`,{type:`button`,onClick:le,disabled:S>=Aw,"aria-label":`Zoom in`,className:`ok-pdf-btn`,title:`Zoom in`,children:(0,J.jsx)(ni,{size:14,"aria-hidden":`true`})}),(0,J.jsx)(`span`,{className:`ok-pdf-divider`,"aria-hidden":`true`}),(0,J.jsxs)(`div`,{className:`ok-pdf-layout-menu`,children:[(0,J.jsx)(`button`,{type:`button`,onClick:()=>k(Iw),"aria-label":`Layout options`,"aria-haspopup":`menu`,"aria-expanded":O,className:`ok-pdf-btn`,title:`Layout`,children:(0,J.jsx)(mr,{size:14,"aria-hidden":`true`})}),O&&(0,J.jsxs)(`div`,{role:`menu`,className:`ok-pdf-menu`,children:[(0,J.jsx)(Bw,{label:`Fit width`,active:w===`fit-width`,onSelect:()=>pe(`fit-width`)}),(0,J.jsx)(Bw,{label:`Fit height`,active:w===`fit-height`,onSelect:()=>pe(`fit-height`)}),(0,J.jsx)(`hr`,{className:`ok-pdf-menu-divider`}),(0,J.jsx)(Bw,{label:`Single page`,active:w===`single`,onSelect:()=>pe(`single`)}),(0,J.jsx)(Bw,{label:`Two-page (odd)`,active:w===`two-odd`,onSelect:()=>pe(`two-odd`)}),(0,J.jsx)(Bw,{label:`Two-page (even)`,active:w===`two-even`,onSelect:()=>pe(`two-even`)})]})]})]}),t[50]=O,t[51]=w,t[52]=b,t[53]=se,t[54]=P,t[55]=S,t[56]=Ce):Ce=t[56];let we;t[57]!==be||t[58]!==Se||t[59]!==Ce?(we=(0,J.jsxs)(`div`,{className:`ok-pdf-toolbar`,contentEditable:!1,children:[be,Se,Ce]}),t[57]=be,t[58]=Se,t[59]=Ce,t[60]=we):we=t[60];let Te;t[61]!==v||t[62]!==ae||t[63]!==f||t[64]!==E?(Te=E&&(0,J.jsx)(`aside`,{className:`ok-pdf-sidebar`,"aria-label":`Page thumbnails`,children:f.map((e,t)=>(0,J.jsxs)(`button`,{type:`button`,className:`ok-pdf-thumb`,"data-active":v===e.pageNumber||void 0,onClick:()=>ae(e.pageNumber),"aria-label":`Jump to page ${e.pageNumber}`,children:[(0,J.jsx)(`canvas`,{ref:e=>{l.current[t]=e},className:`ok-pdf-thumb-canvas`}),(0,J.jsx)(`span`,{className:`ok-pdf-thumb-num`,children:e.pageNumber})]},e.pageNumber))}),t[61]=v,t[62]=ae,t[63]=f,t[64]=E,t[65]=Te):Te=t[65];let Ee;t[66]===m?Ee=t[67]:(Ee=m&&(0,J.jsx)(`div`,{className:`ok-pdf-loading`,children:`Loading PDF…`}),t[66]=m,t[67]=Ee);let De;t[68]===g?De=t[69]:(De=g&&(0,J.jsxs)(`div`,{className:`ok-pdf-error`,children:[`Failed to load PDF: `,g]}),t[68]=g,t[69]=De);let Oe;t[70]===P?Oe=t[71]:(Oe=Array.from({length:P},(e,t)=>{let n=t+1;return(0,J.jsx)(`canvas`,{ref:e=>{s.current[t]=e},className:`ok-pdf-page`,"aria-label":`Page ${n}`},n)}),t[70]=P,t[71]=Oe);let ke;t[72]!==w||t[73]!==Ee||t[74]!==De||t[75]!==Oe?(ke=(0,J.jsxs)(`div`,{className:`ok-pdf-pages`,ref:a,"data-layout":w,children:[Ee,De,Oe]}),t[72]=w,t[73]=Ee,t[74]=De,t[75]=Oe,t[76]=ke):ke=t[76];let Ae;t[77]!==Te||t[78]!==ke?(Ae=(0,J.jsxs)(`div`,{className:`ok-pdf-body`,children:[Te,ke]}),t[77]=Te,t[78]=ke,t[79]=Ae):Ae=t[79];let je;return t[80]!==he||t[81]!==we||t[82]!==Ae?(je=(0,J.jsxs)(`div`,{className:`ok-pdf`,style:he,children:[we,Ae]}),t[80]=he,t[81]=we,t[82]=Ae,t[83]=je):je=t[83],je}function Iw(e){return!e}function Lw(e){return!e}function Rw(e){return Math.max(kw,+(e-jw).toFixed(2))}function zw(e){return Math.min(Aw,+(e+jw).toFixed(2))}function Bw(e){let t=(0,Y.c)(8),n=e.active||void 0,r=e.active?`✓`:``,i;t[0]===r?i=t[1]:(i=(0,J.jsx)(`span`,{className:`ok-pdf-menu-check`,"aria-hidden":`true`,children:r}),t[0]=r,t[1]=i);let a;return t[2]!==e.active||t[3]!==e.label||t[4]!==e.onSelect||t[5]!==n||t[6]!==i?(a=(0,J.jsxs)(`button`,{type:`button`,role:`menuitemradio`,"aria-checked":e.active,className:`ok-pdf-menu-item`,"data-active":n,onClick:e.onSelect,children:[i,e.label]}),t[2]=e.active,t[3]=e.label,t[4]=e.onSelect,t[5]=n,t[6]=i,t[7]=a):a=t[7],a}function Vw(e){if(!e)return null;for(let t of e.split(`&`)){let e=t.indexOf(`=`);if(!(e<0)&&t.slice(0,e)===`page`){let n=Number.parseInt(t.slice(e+1),10);if(!Number.isNaN(n)&&n>=1)return n}}return null}function Hw(e){return e!==!1}function Uw(e){let t=(0,Y.c)(14),n=e.src,r=e.title,i;t[0]===e.controls?i=t[1]:(i=Hw(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,J.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 Ww(e){let t=(0,Y.c)(2),n;return t[0]===e.children?n=t[1]:(n=(0,J.jsx)(`div`,{className:`prose-no-margin`,children:e.children}),t[0]=e.children,t[1]=n),n}var Gw={Callout:LC,img:hw,video:Uw,audio:jC,Pdf:Fw,Accordion:kC,Math:vw,Mermaid:xw,"*":Ww};function Kw(e){let t=new Set;for(let n of e)n.type===`reactnode`&&t.add(n.name);return t}var qw=gt(),Jw=new Map;function Yw(e){if(e.surface===`compat`){let t=Gw[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:Kw(e.props)}}let t=Gw[e.name];return t?{Component:t,reactNodePropNames:Kw(e.props)}:null}for(let[e,t]of qw.entries()){let n=Yw(t);n&&Jw.set(e,n)}function Xw(e,t){return{...e,Component:t.Component,reactNodePropNames:t.reactNodePropNames}}function Zw(e){let t=qw.getOrWildcard(e),n=Jw.get(t.name)??Jw.get(`*`);if(!n)throw Error(`No React component registered for ${t.name} (and no '*' wildcard)`);return Xw(t,n)}function Qw(){let e=[];for(let[t,n]of qw.entries()){if(t===`*`)continue;let r=Jw.get(t);r&&e.push(Xw(n,r))}return e}var $w=``+new URL(`image-preview-BJSGEOo4.png`,import.meta.url).href,eT=``+new URL(`video-preview-vLovc_Vy.png`,import.meta.url).href,tT={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:$w,alt:`Sample image`}},video:{description:`Embed a video with native player controls.`,props:{controls:!0,poster:eT}},audio:{description:`Embed an audio file with native player controls.`,props:{controls:!0}},Math:{description:`Block math equation rendered with KaTeX from a LaTeX source string.`,props:{formula:`c = \\pm\\sqrt{a^2 + b^2}`}}};function nT(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 rT(e){let t=Zw(e),n=nT(t);return{type:`jsxComponent`,attrs:{componentName:t.name,kind:`element`,attributes:[],sourceRaw:``,sourceDirty:!0,props:n},content:t.hasChildren?[{type:`paragraph`}]:void 0}}var iT=new Set;function aT(e){iT.add(e)}function oT(e){if(typeof e==`number`)return iT.delete(e);let t=iT.values().next();return t.done?!1:(iT.delete(t.value),!0)}function sT(e,t,n){n.props.some(e=>!(`hidden`in e&&e.hidden)&&e.type!==`reactnode`)?(aT(t),requestAnimationFrame(()=>{e.commands.setNodeSelection(t)})):n.hasChildren&&e.commands.setTextSelection(t+2)}function cT(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(rT(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)&&sT(t,r,e)}}function lT(){return Qw().filter(e=>e.surface===`canonical`).map(e=>{let t=tT[e.name],n=e.Component,r=t?{description:t.description,render:()=>(0,J.jsx)(n,{...t.props,children:t.children})}:void 0;return{name:`component-${e.name}`,label:e.displayName??e.name,icon:EC(e.icon),category:e.category??`content`,command:cT(e),aliases:e.searchTerms,description:e.description,preview:r}})}function uT(){return[{name:`component-Tag`,label:`Tag`,icon:Or,category:`content`,aliases:[`#`,`hashtag`,`label`],description:"Inline tag (`#tagname`) for cross-doc linking",command:e=>{let t=new WeakSet;e.state.doc.descendants(e=>{e.type.name===`tag`&&t.add(e)}),e.chain().focus().insertTag(``).run();let n=-1;e.state.doc.descendants((e,r)=>{if(n>=0)return!1;e.type.name===`tag`&&!t.has(e)&&(n=r)}),!(n<0)&&(aT(n),requestAnimationFrame(()=>{e.commands.setNodeSelection(n)}))}}]}var dT=[{name:`heading1`,label:`Heading 1`,icon:kr,category:`basic`,command:e=>e.chain().focus().toggleHeading({level:1}).run(),aliases:[`h1`],preview:{description:`Big section heading.`,render:()=>(0,J.jsx)(`h1`,{className:`text-2xl font-semibold tracking-tight`,children:`Heading 1`})}},{name:`heading2`,label:`Heading 2`,icon:Ar,category:`basic`,command:e=>e.chain().focus().toggleHeading({level:2}).run(),aliases:[`h2`],preview:{description:`Medium section heading.`,render:()=>(0,J.jsx)(`h2`,{className:`text-xl font-semibold tracking-tight`,children:`Heading 2`})}},{name:`heading3`,label:`Heading 3`,icon:jr,category:`basic`,command:e=>e.chain().focus().toggleHeading({level:3}).run(),aliases:[`h3`],preview:{description:`Small section heading.`,render:()=>(0,J.jsx)(`h3`,{className:`text-base font-semibold tracking-tight`,children:`Heading 3`})}},{name:`bulletList`,label:`Bullet List`,icon:Lr,category:`basic`,command:e=>e.chain().focus().toggleBulletList().run(),aliases:[`ul`,`unordered`],preview:{description:`Unordered list of items.`,render:()=>(0,J.jsxs)(`ul`,{className:`list-disc pl-5 text-sm leading-7`,children:[(0,J.jsx)(`li`,{children:`First item`}),(0,J.jsx)(`li`,{children:`Second item`})]})}},{name:`orderedList`,label:`Ordered List`,icon:Fr,category:`basic`,command:e=>e.chain().focus().toggleOrderedList().run(),aliases:[`ol`,`numbered`],preview:{description:`Numbered list of items.`,render:()=>(0,J.jsxs)(`ol`,{className:`list-decimal pl-5 text-sm leading-7`,children:[(0,J.jsx)(`li`,{children:`First item`}),(0,J.jsx)(`li`,{children:`Second item`})]})}},{name:`taskList`,label:`Task List`,icon:Ir,category:`basic`,command:e=>e.chain().focus().toggleTaskList().run(),aliases:[`todo`,`checklist`,`checkbox`],preview:{description:`Checklist with checkboxes.`,render:()=>(0,J.jsxs)(`ul`,{className:`space-y-1.5 text-sm`,children:[(0,J.jsxs)(`li`,{className:`flex items-center gap-2`,children:[(0,J.jsx)(`input`,{type:`checkbox`,checked:!0,readOnly:!0,className:`size-3.5`}),(0,J.jsx)(`span`,{className:`text-muted-foreground line-through`,children:`Done`})]}),(0,J.jsxs)(`li`,{className:`flex items-center gap-2`,children:[(0,J.jsx)(`input`,{type:`checkbox`,readOnly:!0,className:`size-3.5`}),(0,J.jsx)(`span`,{children:`To do`})]})]})}},{name:`blockquote`,label:`Quote`,icon:Wr,category:`basic`,command:e=>e.chain().focus().toggleBlockquote().run(),aliases:[`quote`],preview:{description:`Indented blockquote for citations.`,render:()=>(0,J.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:xr,category:`basic`,command:e=>e.chain().focus().toggleCodeBlock().run(),aliases:[`code`,`fence`],preview:{description:`Fenced code block with monospace text.`,render:()=>(0,J.jsx)(`pre`,{className:`rounded-md bg-muted px-2.5 py-2 font-mono text-xs leading-5`,children:(0,J.jsx)(`code`,{children:`const greeting = "Hello";
6
+ `);return/\s/.test(n)}):!1}var ev=new T(`suggestion`);function tv({pluginKey:e=ev,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=Q_,shouldShow:g,shouldResetDismissed:_}){let y,b=p?.(),x=r&&!i,S=()=>{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}},C=(n,r)=>r?()=>{let r=e.getState(t.state)?.decorationId;return n.dom.querySelector(`[data-decoration-id="${r}"]`)?.getBoundingClientRect()||null}:S,w=({match:e,dismissedRange:n,state:r,transaction:i})=>_?.({editor:t,state:r,range:n,match:e,transaction:i,allowSpaces:x})?!1:x?e.range.from===n.from:e.range.from===n.from&&!$_(i);function T(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:C(n,a)};(i=b?.onExit)==null||i.call(b,o)}catch{}let a=n.state.tr.setMeta(r,{exit:!0});n.dispatch(a)}let E=new v({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,v=m||u&&h;if(!g&&!_&&!v)return;let x=v&&!g?c:l,S=e.dom.querySelector(`[data-decoration-id="${x.decorationId}"]`);y={editor:t,range:x.range,query:x.query,text:x.text,items:[],command:e=>d({editor:t,range:x.range,props:e}),decorationNode:S,clientRect:C(e,S)},g&&((r=b?.onBeforeStart)==null||r.call(b,y)),_&&((i=b?.onBeforeUpdate)==null||i.call(b,y)),(_||g)&&(y.items=await f({editor:t,query:x.query})),v&&((a=b?.onExit)==null||a.call(b,y)),_&&((o=b?.onUpdate)==null||o.call(b,y)),g&&((s=b?.onStart)==null||s.call(b,y))},destroy:()=>{var e;y&&((e=b?.onExit)==null||e.call(b,y))}}},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&&!w({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}=E.getState(t.state);if(!i)return!1;if(n.key===`Escape`||n.key===`Esc`){let i=E.getState(t.state);return(r=b?.onKeyDown)==null||r.call(b,{view:t,event:n,range:i.range}),T(t,e),!0}return(b?.onKeyDown)?.call(b,{view:t,event:n,range:a})||!1},decorations(e){let{active:t,range:n,decorationId:r,query:i}=E.getState(e);if(!t)return null;let a=!i?.length,o=[c];return a&&o.push(u),P.create(e.doc,[Be.inline(n.from,n.to,{nodeName:s,class:o.join(` `),"data-decoration-id":r,"data-decoration-content":l})])}}});return E}var nv=tv;function rv(e){return e.kind===`create`?`create:${e.value}`:`tag:${e.value}`}function iv(e){if(e.kind===`create`)return`Create new tag #${e.value}`;let t=e.count===1?`1 use`:`${e.count} uses`;return`Tag #${e.value}, ${t}`}function av(e){let t=(0,Y.c)(32),{items:n,query:r,selectedIndex:i,onSelect:a,onHover:o,loading:s,error:c}=e,l=s===void 0?!1:s,u=c===void 0?null:c,d=(0,q.useRef)(null),f=(0,q.useId)(),p=i>=0&&i<n.length?`${f}-option-${i}`:void 0,m,h;t[0]===i?(m=t[1],h=t[2]):(m=()=>{let e=d.current;if(!e)return;let t=e.querySelectorAll(`[role="option"]`).item(i);t&&t.scrollIntoView({block:`nearest`})},h=[i],t[0]=i,t[1]=m,t[2]=h),(0,q.useEffect)(m,h);let g=ov;if(l){let e;return t[3]===Symbol.for(`react.memo_cache_sentinel`)?(e=(0,J.jsx)(`div`,{ref:d,role:`status`,"aria-live":`polite`,className:`w-64 rounded-lg border bg-popover p-2 shadow-md text-sm text-muted-foreground`,style:{maxHeight:`var(--suggestion-menu-max-height, 40vh)`},onMouseDown:g,children:`Loading tags…`}),t[3]=e):e=t[3],e}if(n.length===0){let e;t[4]===r?e=t[5]:(e=r.trim(),t[4]=r,t[5]=e);let n=e,i=u??(n?`No tags match "${n}". Continue typing to create one.`:`No tags yet. Continue typing to create one.`),a;t[6]===Symbol.for(`react.memo_cache_sentinel`)?(a={maxHeight:`var(--suggestion-menu-max-height, 40vh)`},t[6]=a):a=t[6];let o;return t[7]===i?o=t[8]:(o=(0,J.jsx)(`div`,{ref:d,role:`status`,"aria-live":`polite`,className:`w-64 rounded-lg border bg-popover p-2 shadow-md text-sm text-muted-foreground`,style:a,onMouseDown:g,children:i}),t[7]=i,t[8]=o),o}let _=i>=0&&i<n.length?n[i]:null,v;t[9]===Symbol.for(`react.memo_cache_sentinel`)?(v={maxHeight:`var(--suggestion-menu-max-height, 40vh)`},t[9]=v):v=t[9];let y;t[10]===_?y=t[11]:(y=_?iv(_):``,t[10]=_,t[11]=y);let b;t[12]===y?b=t[13]:(b=(0,J.jsx)(`span`,{className:`sr-only`,"aria-live":`polite`,"aria-atomic":`true`,children:y}),t[12]=y,t[13]=b);let x;t[14]===u?x=t[15]:(x=u&&(0,J.jsx)(`div`,{className:`rounded-md px-2 py-1.5 text-xs text-amber-700 dark:text-amber-300`,children:u}),t[14]=u,t[15]=x);let S;if(t[16]!==n||t[17]!==f||t[18]!==o||t[19]!==a||t[20]!==i){let e;t[22]!==f||t[23]!==o||t[24]!==a||t[25]!==i?(e=(e,t)=>{let n=t===i,r=rv(e),s=e.kind===`create`;return(0,J.jsxs)(`button`,{id:`${f}-option-${t}`,type:`button`,role:`option`,"aria-selected":n,"data-selected":n,"data-testid":s?`tag-suggestion-create`:`tag-suggestion-tag-${e.value}`,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`:``}`,onMouseDown:t=>{t.preventDefault(),a(e)},onPointerMove:o?()=>o(t):void 0,children:[(0,J.jsx)(`span`,{"aria-hidden":`true`,className:`font-mono text-xs text-muted-foreground`,children:`#`}),(0,J.jsx)(`span`,{className:`truncate font-medium flex-1`,children:e.value}),s?(0,J.jsx)(`span`,{className:`shrink-0 rounded-sm bg-primary/10 px-1.5 py-0.5 text-[10px] font-medium uppercase tracking-wide text-primary`,children:`New`}):(0,J.jsx)(`span`,{className:`shrink-0 text-[11px] text-muted-foreground tabular-nums`,children:e.count})]},r)},t[22]=f,t[23]=o,t[24]=a,t[25]=i,t[26]=e):e=t[26],S=n.map(e),t[16]=n,t[17]=f,t[18]=o,t[19]=a,t[20]=i,t[21]=S}else S=t[21];let C;return t[27]!==p||t[28]!==b||t[29]!==x||t[30]!==S?(C=(0,J.jsxs)(`div`,{ref:d,role:`listbox`,"aria-label":`Tag suggestions`,"aria-activedescendant":p,tabIndex:-1,onMouseDown:g,className:`w-64 overflow-y-auto subtle-scrollbar rounded-lg border bg-popover p-1 shadow-md`,style:v,children:[b,x,S]}),t[27]=p,t[28]=b,t[29]=x,t[30]=S,t[31]=C):C=t[31],C}function ov(e){return e.preventDefault()}function sv(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`),Xe(r,n,{placement:`bottom-start`,middleware:[$e(4),st(),ct({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:()=>ut(r,n,o),reveal:()=>{a||(i=!0,o())}}}function cv(e){e.stopAutoUpdate?.(),e.stopAutoUpdate=null,e.popup?.remove(),e.popup=null}var lv=new T(`tagSuggestion`),uv=8,dv=/^[a-zA-Z][\w/-]*$/;async function fv(){let e=await fetch(`/api/tags`);if(!e.ok)throw Error(`/api/tags responded with ${e.status}`);let t=await e.json();return t.ok&&Array.isArray(t.tags)?t.tags:[]}function pv(e,t){let n=t.trim(),r=n.toLowerCase(),i=n===``?e.slice():e.filter(e=>e.name.toLowerCase().includes(r));return i.sort((e,t)=>{let n=+!e.name.toLowerCase().startsWith(r),i=+!t.name.toLowerCase().startsWith(r);return n===i?t.count===e.count?e.name.localeCompare(t.name):t.count-e.count:n-i}),i}function mv(e,t){let n=pv(e,t).slice(0,uv).map(e=>({kind:`tag`,value:e.name,count:e.count,isLeaf:e.isLeaf})),r=t.trim();return r&&dv.test(r)&&!e.some(e=>e.name===r)&&n.unshift({kind:`create`,value:r}),n}function hv(e){let{$position:t}=e,n=t.parent.textBetween(0,t.parentOffset,void 0,``).match(/(^|[\s])#([a-zA-Z][\w/-]*)?$/);if(!n)return null;let r=n[2]??``,i=t.start(),a=n[1].length;return{range:{from:i+((n.index??0)+a),to:t.pos},query:r,text:`#${r}`}}function gv(e){let t=[],n=!1,r=null,i=null;return nv({editor:e,pluginKey:lv,char:`#`,allowedPrefixes:null,findSuggestionMatch:hv,items:async({query:e})=>{if(!n){r||=fv();try{t=await r,i=null}catch(e){console.error(`[tag-suggestion] Failed to fetch tags:`,e),i=`Failed to load tags. Press Escape and type # again to retry, or continue typing to create a new tag.`,t=[]}finally{n=!0,r=null}}return mv(t,e)},command:({editor:e,range:t,props:n})=>{try{let r=n.value;if(!r||!dv.test(r))return;e.chain().focus().deleteRange(t).insertContent({type:`tag`,attrs:{value:r}}).insertContent(` `).run()}catch(e){console.error(`[tag-suggestion] command failed`,{item:n,range:t},e)}},render:()=>{let e=null,a=null,o=0,s={popup:null,stopAutoUpdate:null},c=null,l=null,u=e=>{a?.command(e)},d=e=>{o!==e&&(o=e,p(null))};function f(e,t,r){let a=t===null?!n:t;return{items:e.items,query:e.query??``,selectedIndex:o,onSelect:r,onHover:d,loading:a,error:i}}let p=t=>{!e||!a||e.updateProps(f(a,t,u))};return{onBeforeStart(t){a=t,o=0;let n=sv(()=>a,`tag-suggestion`);s.popup=n.popup,c=n.doPosition,l=n.reveal,e=new fc(av,{props:f(t,!0,u),editor:t.editor}),n.popup.appendChild(e.element),s.stopAutoUpdate=n.startAutoUpdate()},onStart(e){a=e,o=0,p(null),l?.()},onUpdate(e){a=e,o=Math.min(o,Math.max(0,e.items.length-1)),p(null),c?.()},onKeyDown({event:e}){if(!a)return!1;let t=a.items;if(e.key===`ArrowDown`)return t.length===0?!1:(o=(o+1)%t.length,p(null),!0);if(e.key===`ArrowUp`)return t.length===0?!1:(o=(o-1+t.length)%t.length,p(null),!0);if(e.key===`Enter`||e.key===`Tab`){let e=t[o];if(e)return a.command(e),!0;let n=(a.query??``).trim();return n&&dv.test(n)?(a.command({kind:`create`,value:n}),!0):!1}return e.key,!1},onExit(){cv(s),c=null,l=null,e?.destroy(),e=null,a=null,o=0,t=[],i=null,n=!1,r=null}}}})}var _v=[`.md`,`.mdx`];function vv(e){let t=e.toLowerCase();for(let e of _v)if(t.endsWith(e))return e;return null}function yv(e){let t=vv(e);return t?e.slice(0,-t.length):e}function bv(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 xv(e){let t=e.fileName.trim(),n=vv(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 Sv(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 Cv(e){let t=e.value.lastIndexOf(`.`);t>0?e.setSelectionRange(0,t):e.select()}function wv(e){let t=(0,Y.c)(96),{open:n,onOpenChange:r,kind:i,initialDir:a,suggestedName:o,description:s,onCreated:c}=e,{addPage:l}=we(),[u,d]=(0,q.useState)(``),[f,p]=(0,q.useState)(``),[m,h]=(0,q.useState)(`.md`),[g,_]=(0,q.useState)(null),[v,y]=(0,q.useState)(!1),[b,x]=(0,q.useState)(null),S=(0,q.useId)(),C=(0,q.useId)(),w=(0,q.useId)(),T=(0,q.useRef)(null),E=(0,q.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=vv(e);h(t??`.md`),d(t?yv(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,q.useEffect)(D,O);let k;t[5]===Symbol.for(`react.memo_cache_sentinel`)?(k=function(e){let t=vv(e);t?(h(t),d(yv(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 xv({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=bv(f.trim());if(e)return{message:`Folder name: ${e}`,field:`folder`}}let e=bv(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),et([`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,J.jsx)(Jt,{children:B}),t[28]=B,t[29]=V);let H;t[30]!==s||t[31]!==z?(H=s??(0,J.jsxs)(J.Fragment,{children:[`Create in `,(0,J.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,J.jsx)(Kt,{children:H}),t[33]=H,t[34]=U);let W;t[35]!==U||t[36]!==V?(W=(0,J.jsxs)(on,{children:[V,U]}),t[35]=U,t[36]=V,t[37]=W):W=t[37];let ee;t[38]!==g||t[39]!==b||t[40]!==S||t[41]!==C||t[42]!==f||t[43]!==i?(ee=i===`folder`&&(0,J.jsxs)(`div`,{children:[(0,J.jsx)(`label`,{className:`mb-1.5 block text-sm font-medium`,htmlFor:C,children:`Folder name`}),(0,J.jsx)(zo,{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=bv(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]=ee):ee=t[44];let te=i===`folder`?`First file name`:`File name`,ne;t[45]!==w||t[46]!==te?(ne=(0,J.jsx)(`label`,{className:`mb-1.5 block text-sm font-medium`,htmlFor:w,children:te}),t[45]=w,t[46]=te,t[47]=ne):ne=t[47];let re;t[48]===Symbol.for(`react.memo_cache_sentinel`)?(re=e=>A(e.target.value),t[48]=re):re=t[48];let ie=i===`file`,ae=g&&(b===`file`||b===`form`)?S:void 0,oe=g&&(b===`file`||b===`form`)?!0:void 0,se;t[49]!==R||t[50]!==I?(se=e=>{e.key===`Enter`&&!I&&R()},t[49]=R,t[50]=I,t[51]=se):se=t[51];let ce;t[52]!==w||t[53]!==u||t[54]!==ie||t[55]!==ae||t[56]!==oe||t[57]!==se?(ce=(0,J.jsx)(zo,{ref:T,id:w,value:u,onChange:re,placeholder:`my-note`,autoFocus:ie,"aria-describedby":ae,"aria-invalid":oe,onFocus:Ev,onKeyDown:se,className:`flex-1`}),t[52]=w,t[53]=u,t[54]=ie,t[55]=ae,t[56]=oe,t[57]=se,t[58]=ce):ce=t[58];let le;t[59]===Symbol.for(`react.memo_cache_sentinel`)?(le=e=>{(e===`.md`||e===`.mdx`)&&h(e)},t[59]=le):le=t[59];let ue;t[60]===Symbol.for(`react.memo_cache_sentinel`)?(ue=_v.map(Tv),t[60]=ue):ue=t[60];let de;t[61]===m?de=t[62]:(de=(0,J.jsx)(be,{type:`single`,value:m,onValueChange:le,variant:`outline`,size:`sm`,"aria-label":`File extension`,className:`shrink-0`,children:ue}),t[61]=m,t[62]=de);let fe;t[63]!==ce||t[64]!==de?(fe=(0,J.jsxs)(`div`,{className:`flex items-stretch gap-2`,children:[ce,de]}),t[63]=ce,t[64]=de,t[65]=fe):fe=t[65];let pe;t[66]!==g||t[67]!==S?(pe=g&&(0,J.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]=pe):pe=t[68];let me;t[69]!==ne||t[70]!==fe||t[71]!==pe?(me=(0,J.jsxs)(`div`,{children:[ne,fe,pe]}),t[69]=ne,t[70]=fe,t[71]=pe,t[72]=me):me=t[72];let he;t[73]!==ee||t[74]!==me?(he=(0,J.jsx)(nn,{children:(0,J.jsxs)(`div`,{className:`space-y-3`,children:[ee,me]})}),t[73]=ee,t[74]=me,t[75]=he):he=t[75];let ge;t[76]===r?ge=t[77]:(ge=()=>r(!1),t[76]=r,t[77]=ge);let _e;t[78]!==v||t[79]!==ge?(_e=(0,J.jsx)(zt,{variant:`outline`,className:`font-mono uppercase`,onClick:ge,disabled:v,children:`Cancel`}),t[78]=v,t[79]=ge,t[80]=_e):_e=t[80];let ve=v?`Creating...`:`Create`,ye;t[81]!==R||t[82]!==I||t[83]!==ve?(ye=(0,J.jsx)(zt,{onClick:R,disabled:I,children:ve}),t[81]=R,t[82]=I,t[83]=ve,t[84]=ye):ye=t[84];let xe;t[85]!==_e||t[86]!==ye?(xe=(0,J.jsxs)(rn,{children:[_e,ye]}),t[85]=_e,t[86]=ye,t[87]=xe):xe=t[87];let Se;t[88]!==W||t[89]!==he||t[90]!==xe?(Se=(0,J.jsxs)($t,{className:`sm:max-w-md`,"data-ok-layer-spawned":``,children:[W,he,xe]}),t[88]=W,t[89]=he,t[90]=xe,t[91]=Se):Se=t[91];let Ce;return t[92]!==r||t[93]!==n||t[94]!==Se?(Ce=(0,J.jsx)(sn,{open:n,onOpenChange:r,children:Se}),t[92]=r,t[93]=n,t[94]=Se,t[95]=Ce):Ce=t[95],Ce}function Tv(e){return(0,J.jsx)(Qe,{value:e,"aria-label":`Use ${e} extension`,children:e},e)}function Ev(e){return Cv(e.currentTarget)}tt({event:je(`ok-branch-switched-clear-failed`),branch:Ke(),docName:Ke(),reason:Ke()});async function Dv(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 Ov(e){let t=!1;return()=>{t?e():t=!0}}function kv(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 Av(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=ge.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)&&Dv(e,i.data.currentBranch),i.data.currentDiskAckSVs!==void 0){let t={};for(let[e,n]of Object.entries(i.data.currentDiskAckSVs))try{t[e]=kv(n)}catch{}e.observeDiskAckBatch(t)}}async function jv(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 Mv(e){return Bv(e,g)}function Nv(e){return Bv(e,L)}function Pv(e){return Bv(e,f)}function Fv(e){return Bv(e,re)}function Iv(e){return Bv(e,_t)}function Lv(e){let t=Bv(e,m);if(!t)return null;try{return{docName:t.docName,sv:Rv(t.sv)}}catch{return null}}function Rv(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 zv(e,t){let n=Nv(e);if(n){t.onServerInfo?.(n);return}let r=Pv(e);if(r){t.onBranchSwitched?.(r);return}let i=Lv(e);if(i){t.onDiskAck?.(i);return}let a=Mv(e);if(a){t.onDerivedView?.(a);return}let o=Fv(e);if(o){t.onConfigValidationRejected?.(o);return}let s=Iv(e);if(s){t.onConfigIgnoreNestedError?.(s);return}t.onUnknown?.(e)}function Bv(e,t){let n;try{n=JSON.parse(e)}catch{return null}let r=t.safeParse(n);return r.success?r.data:null}function Vv(){return typeof location>`u`?`ws://localhost/collab`:`${location.protocol===`https:`?`wss`:`ws`}://${location.host}/collab`}function Hv(e){if(e===void 0)return null;let t=e.okDesktop;return!t||!t.config.collabUrl||t.config.collabUrl.length===0?null:t}function Uv(e){return{collabUrl:e.collabUrl,attempts:0,terminal:!1,lastError:null}}var Wv=2e3,Gv=15e3;function Kv(e){let t=e.terminalAfterMs??3e4,n=e.initialDelayMs??Wv,r=e.maxDelayMs??Gv,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 qv(){let e=(0,Y.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,q.useState)(t),i;e[1]===Symbol.for(`react.memo_cache_sentinel`)?(i={token:0},e[1]=i):i=e[1];let a=(0,q.useRef)(i),[o,s]=(0,q.useState)(0),c;e[2]===Symbol.for(`react.memo_cache_sentinel`)?(c=()=>{let e=a.current.token=a.current.token+1,t=Hv(typeof window<`u`?window:void 0);if(t){r(Uv(t.config));let n=t.onProjectSwitched(t=>{e===a.current.token&&r(Uv(t))});return()=>{n()}}let n=Kv({fetchConfig:jv,fallbackUrl:Vv,now:Date.now,setTimeout:Zv,clearTimeout:Xv,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,q.useEffect)(c,l);let u;e[5]===Symbol.for(`react.memo_cache_sentinel`)?(u=()=>{a.current.token=a.current.token+1,r(Yv),s(Jv)},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 Jv(e){return e+1}function Yv(e){return{...e,terminal:!1,lastError:null}}function Xv(e){return globalThis.clearTimeout(e)}function Zv(e,t){return globalThis.setTimeout(e,t)}function Qv(e,t){return t}function $v(e){try{let t=e.state;return e_.getState(t)?.undoManager??null}catch{return null}}var ey=Qv(`MAX_CACHE`,10),ty=Qv(`VIEW_COUNT_CACHE_THRESHOLD`,50),ny=Qv(`BYTES_CACHE_THRESHOLD`,8e6);function ry(e){return!(e.viewCount>0&&e.viewCount>=ty||e.bytes>ny)}var iy=new Map,ay=new Map,oy=[],sy=[],cy=new Set,ly=null;function uy(){if(ly)return ly;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`,ly=e,e}function dy(e){let{docName:t,container:n,factory:r,sizeStats:i}=e;if(i&&!ry(i)){let e=r(n);return X(`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=iy.get(t);if(a){if(X(`ok/cache/reparent-start`,{docName:t,kind:`tiptap`,viewCount:i?.viewCount??-1,bytes:i?.bytes??-1}),yy(a,n),a.activeMountKey=t,xy(oy,t),n.scrollTop=a.scrollTop,a.hadFocus)try{a.editor.commands.focus()}catch{}return X(`ok/cache/reparent-end`,{docName:t,kind:`tiptap`,viewCount:i?.viewCount??-1,bytes:i?.bytes??-1}),X(`ok/cache/hit`,{docName:t,kind:`tiptap`}),i&&X(`ok/cold/editor-mount-stats`,{docName:t,viewCount:i.viewCount,bytes:i.bytes,cacheHit:!0,kind:`tiptap`}),a}for(;iy.size>=ey;){let e=Sy(oy,t);if(!e)break;py(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 iy.set(t,s),xy(oy,t),X(`ok/cache/miss`,{docName:t,viewCount:i?.viewCount??-1,bytes:i?.bytes??-1,reason:`cold`,kind:`tiptap`}),i&&X(`ok/cold/editor-mount-stats`,{docName:t,viewCount:i.viewCount,bytes:i.bytes,cacheHit:!1,kind:`tiptap`}),s}function fy(e){if(e.__uncached){let t=$v(e.editor);try{e.editor.destroy()}catch{}t&&(t.restore=void 0),e.activeMountKey=null;return}let t=_y(e.editor);if(t){e.hadFocus=vy(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=uy();r&&r.appendChild(t.dom)}e.activeMountKey=null}function py(e){let t=iy.get(e);if(!t)return!1;let n=$v(t.editor);try{t.editor.destroy()}catch(t){X(`ok/cache/evict-failed`,{docName:e,kind:`tiptap`,stage:`editor`,message:t instanceof Error?t.message:String(t)})}n&&(n.restore=void 0);try{t.provider.destroy()}catch(t){X(`ok/cache/evict-failed`,{docName:e,kind:`tiptap`,stage:`provider`,message:t instanceof Error?t.message:String(t)})}try{t.ydoc.destroy()}catch(t){X(`ok/cache/evict-failed`,{docName:e,kind:`tiptap`,stage:`ydoc`,message:t instanceof Error?t.message:String(t)})}iy.delete(e);let r=oy.indexOf(e);return r!==-1&&oy.splice(r,1),X(`ok/cache/evict`,{docName:e,kind:`tiptap`}),!0}function my(e){let{docName:t,container:n,factory:r,sizeStats:i}=e;if(i&&!ry(i)){let e=r(n);return X(`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=ay.get(t);if(a){if(X(`ok/cache/reparent-start`,{docName:t,kind:`cm`,viewCount:i?.viewCount??-1,bytes:i?.bytes??-1}),by(a,n),a.activeMountKey=t,xy(sy,t),n.scrollTop=a.scrollTop,a.hadFocus)try{a.view.focus()}catch{}return X(`ok/cache/reparent-end`,{docName:t,kind:`cm`,viewCount:i?.viewCount??-1,bytes:i?.bytes??-1}),X(`ok/cache/hit`,{docName:t,kind:`cm`}),i&&X(`ok/cold/editor-mount-stats`,{docName:t,viewCount:i.viewCount,bytes:i.bytes,cacheHit:!0,kind:`cm`}),a}for(;ay.size>=ey;){let e=Sy(sy,t);if(!e)break;gy(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 ay.set(t,s),xy(sy,t),X(`ok/cache/miss`,{docName:t,viewCount:i?.viewCount??-1,bytes:i?.bytes??-1,reason:`cold`,kind:`cm`}),i&&X(`ok/cold/editor-mount-stats`,{docName:t,viewCount:i.viewCount,bytes:i.bytes,cacheHit:!1,kind:`cm`}),s}function hy(e){if(e.__uncached){try{e.view.destroy()}catch{}e.activeMountKey=null;return}let t=e.view.dom;e.hadFocus=vy(t),e.scrollTop=(e.view.scrollDOM??t).scrollTop??0;let n=t.parentElement;n&&n.removeChild(t);let r=uy();r&&r.appendChild(t),e.activeMountKey=null}function gy(e){let t=ay.get(e);if(!t)return!1;try{t.view.destroy()}catch(t){X(`ok/cache/evict-failed`,{docName:e,kind:`cm`,stage:`view`,message:t instanceof Error?t.message:String(t)})}try{t.provider.destroy()}catch(t){X(`ok/cache/evict-failed`,{docName:e,kind:`cm`,stage:`provider`,message:t instanceof Error?t.message:String(t)})}try{t.ydoc.destroy()}catch(t){X(`ok/cache/evict-failed`,{docName:e,kind:`cm`,stage:`ydoc`,message:t instanceof Error?t.message:String(t)})}ay.delete(e);let n=sy.indexOf(e);return n!==-1&&sy.splice(n,1),X(`ok/cache/evict`,{docName:e,kind:`cm`}),!0}function _y(e){return e.editorView??null}function vy(e){if(typeof document>`u`)return!1;let t=document.activeElement;return t?t===e?!0:e.contains(t):!1}function yy(e,t){let n=_y(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 by(e,t){let n=e.view.dom,r=n.parentElement;r&&r!==t&&r.removeChild(n),n.parentElement!==t&&t.appendChild(n)}function xy(e,t){let n=e.indexOf(t);n!==-1&&e.splice(n,1),e.push(t)}function Sy(e,t){for(let n of e)if(n!==t&&!cy.has(n))return n;X(`ok/cache/evict-fallback-activity-saturated`,{mountingDocName:t,lruLength:e.length,activityMountCount:cy.size});for(let n of e)if(n!==t)return n;return null}function Cy(e){let t=cy,n=new Set(e);for(let e of t){if(n.has(e))continue;let t=Ty(e);if(t)try{t.disconnect(),X(`ok/cache/disconnect`,{docName:e})}catch(t){X(`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=Ty(e);if(!n)continue;let r=t=>{X(`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(()=>X(`ok/cache/connect`,{docName:e}),e=>r(e)):X(`ok/cache/connect`,{docName:e})}catch(e){r(e)}}cy=n}var wy=null;function Ty(e){let t=iy.get(e);if(t)return t.provider;let n=ay.get(e);if(n)return n.provider;if(wy){let t=wy.entries.get(e);if(t)return t.provider}return null}function Ey(e){wy=e;let t=e.onEvict(e=>{py(e),gy(e)});return()=>{t(),wy===e&&(wy=null)}}var Dy=`ok-editor-tabs-v1:`;function Oy(e){return typeof e==`string`&&e.length>0}function ky(e,t){if(!Array.isArray(e)||t<=0)return[];let n=[],r=new Set;for(let i of e)if(Oy(i)&&!r.has(i)&&(r.add(i),n.push(i),n.length>=t))break;return n}function Ay(e,t,n){let r=ky(e,n);if(!Oy(t)||r.includes(t))return r;let i=[...r,t];return i.length>n?i.slice(i.length-n):i}function jy(e,t){return e.filter(e=>e!==t)}function My(e,t,n){if(t.length===0)return ky(e,n);let r=new Map(t.map(e=>[e.fromDocName,e.toDocName])),i=[],a=new Set;for(let t of e){let e=r.get(t)??t;if(!a.has(e)&&(a.add(e),i.push(e),i.length>=n))break}return i}function Ny(e,t,n){if(t!==n)return t;let r=e.indexOf(n);return r<0?e[0]??null:e[r+1]??e[r-1]??null}function Py(e,t){if(typeof e!=`object`||!e)return{openTabs:[],activeDocName:null,updatedAt:null};let n=e,r=ky(n.openTabs,t);return{openTabs:r,activeDocName:typeof n.activeDocName==`string`&&r.includes(n.activeDocName)?n.activeDocName:null,updatedAt:typeof n.updatedAt==`string`?n.updatedAt:null}}function Fy(e,t,n=()=>new Date){let r=ky(e,2**53-1);return{openTabs:r,activeDocName:t&&r.includes(t)?t:null,updatedAt:n().toISOString()}}function Iy(e){return`${Dy}${e}`}function Ly(e,t,n){if(!e)return{openTabs:[],activeDocName:null,updatedAt:null};try{let r=e.getItem(t);return r?Py(JSON.parse(r),n):{openTabs:[],activeDocName:null,updatedAt:null}}catch(e){return console.warn(`[editor-tabs] failed to read local tab session:`,e),{openTabs:[],activeDocName:null,updatedAt:null}}}function Ry(e,t,n){if(e)try{e.setItem(t,JSON.stringify(n))}catch(e){console.warn(`[editor-tabs] failed to write local tab session:`,e)}}var zy=Math.floor,By=(e,t)=>e<t?e:t,Vy=(e,t)=>e>t?e:t;Number.isNaN;var Hy=128,Uy=1<<17,Wy=1<<18,Gy=1<<19,Ky=1<<20,qy=1<<21,Jy=1<<22,Yy=1<<23,Xy=1<<24,Zy=1<<25,Qy=1<<26,$y=1<<27,eb=1<<28,tb=1<<29,nb=1<<30,rb=127;Uy-1,Wy-1,Gy-1,Ky-1,qy-1,Jy-1,Yy-1,Xy-1,Zy-1,Qy-1,$y-1,eb-1,tb-1,nb-1;var ib=2**53-1;Number.isInteger,Number.isNaN,Number.parseInt;var ab=String.fromCharCode;String.fromCodePoint,ab(65535);var ob=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},sb=typeof TextEncoder<`u`?new TextEncoder:null,cb=sb?e=>sb.encode(e):ob,lb=typeof TextDecoder>`u`?null:new TextDecoder(`utf-8`,{fatal:!0,ignoreBOM:!0});lb&&lb.decode(new Uint8Array).length===1&&(lb=null);var ub=(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},db=(e,t)=>{for(;t>rb;)ub(e,Hy|rb&t),t=zy(t/128);ub(e,rb&t)},fb=new Uint8Array(3e4),pb=fb.length/3,mb=sb&&sb.encodeInto?(e,t)=>{if(t.length<pb){let n=sb.encodeInto(t,fb).written||0;db(e,n);for(let t=0;t<n;t++)ub(e,fb[t])}else gb(e,cb(t))}:(e,t)=>{let n=unescape(encodeURIComponent(t)),r=n.length;db(e,r);for(let t=0;t<r;t++)ub(e,n.codePointAt(t))},hb=(e,t)=>{let n=e.cbuf.length,r=e.cpos,i=By(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(Vy(n*2,a)),e.cbuf.set(t.subarray(i)),e.cpos=a)},gb=(e,t)=>{db(e,t.byteLength),hb(e,t)},_b=e=>Error(e),vb=_b(`Unexpected end of array`),yb=_b(`Integer out of Range`),bb=(e,t)=>{let n=new Uint8Array(e.arr.buffer,e.pos+e.arr.byteOffset,t);return e.pos+=t,n},xb=e=>bb(e,Cb(e)),Sb=e=>e.arr[e.pos++],Cb=e=>{let t=0,n=1,r=e.arr.length;for(;e.pos<r;){let r=e.arr[e.pos++];if(t+=(r&rb)*n,n*=128,r<Hy)return t;if(t>ib)throw yb}throw vb},wb=lb?e=>lb.decode(xb(e)):e=>{let t=Cb(e);if(t===0)return``;{let n=String.fromCodePoint(Sb(e));if(--t<100)for(;t--;)n+=String.fromCodePoint(Sb(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))}},Tb=function(e){return e[e.Token=0]=`Token`,e[e.PermissionDenied=1]=`PermissionDenied`,e[e.Authenticated=2]=`Authenticated`,e}({}),Eb=(e,t)=>{db(e,Tb.Token),mb(e,t)},Db=(e,t,n,r)=>{switch(Cb(e)){case Tb.Token:t();break;case Tb.PermissionDenied:n(wb(e));break;case Tb.Authenticated:r(wb(e));break;default:}},Ob=e=>Array.from(e.entries()).map(([e,t])=>({clientId:e,...t})),kb=`\0`;function Ab(e,t){return e+kb+t}function jb(e){let t=e.indexOf(kb);return t===-1?{documentName:e,sessionId:null}:{documentName:e.substring(0,t),sessionId:e.substring(t+1)}}var Mb=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 Nb(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 Pb(e){return new Promise(t=>setTimeout(t,e))}function Fb(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 Ib(e,t){let n=Nb(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||Fb;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 Pb(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 Pb(o),r.attemptNum<1&&n.initialJitter){let e=i(r,n);e&&await Pb(e)}return a()}var Lb=Math.floor,Rb=(e,t)=>e<t?e:t,zb=(e,t)=>e>t?e:t;Number.isNaN;var Bb=64,Vb=128,Hb=1<<17,Ub=1<<18,Wb=1<<19,Gb=1<<20,Kb=1<<21,qb=1<<22,Jb=1<<23,Yb=1<<24,Xb=1<<25,Zb=1<<26,Qb=1<<27,$b=1<<28,ex=1<<29,tx=1<<30,nx=63,rx=127;Hb-1,Ub-1,Wb-1,Gb-1,Kb-1,qb-1,Jb-1,Yb-1,Xb-1,Zb-1,Qb-1,$b-1,ex-1,tx-1;var ix=2**53-1;Number.isInteger,Number.isNaN,Number.parseInt;var ax=()=>new Set,ox=Array.from;Array.isArray;var sx=String.fromCharCode;String.fromCodePoint,sx(65535);var cx=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},lx=typeof TextEncoder<`u`?new TextEncoder:null,ux=lx?e=>lx.encode(e):cx,dx=typeof TextDecoder>`u`?null:new TextDecoder(`utf-8`,{fatal:!0,ignoreBOM:!0});dx&&dx.decode(new Uint8Array).length===1&&(dx=null);var fx=class{constructor(){this.cpos=0,this.cbuf=new Uint8Array(100),this.bufs=[]}},px=()=>new fx,mx=e=>{let t=e.cpos;for(let n=0;n<e.bufs.length;n++)t+=e.bufs[n].length;return t},hx=e=>{let t=new Uint8Array(mx(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},gx=(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},_x=(e,t)=>{for(;t>rx;)gx(e,Vb|rx&t),t=Lb(t/128);gx(e,rx&t)},vx=new Uint8Array(3e4),yx=vx.length/3,bx=lx&&lx.encodeInto?(e,t)=>{if(t.length<yx){let n=lx.encodeInto(t,vx).written||0;_x(e,n);for(let t=0;t<n;t++)gx(e,vx[t])}else Sx(e,ux(t))}:(e,t)=>{let n=unescape(encodeURIComponent(t)),r=n.length;_x(e,r);for(let t=0;t<r;t++)gx(e,n.codePointAt(t))},xx=(e,t)=>{let n=e.cbuf.length,r=e.cpos,i=Rb(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(zb(n*2,a)),e.cbuf.set(t.subarray(i)),e.cpos=a)},Sx=(e,t)=>{_x(e,t.byteLength),xx(e,t)},Cx=e=>Error(e),wx=Cx(`Unexpected end of array`),Tx=Cx(`Integer out of Range`),Ex=class{constructor(e){this.arr=e,this.pos=0}},Dx=e=>new Ex(e),Ox=(e,t)=>{let n=new Uint8Array(e.arr.buffer,e.pos+e.arr.byteOffset,t);return e.pos+=t,n},kx=e=>Ox(e,jx(e)),Ax=e=>e.arr[e.pos++],jx=e=>{let t=0,n=1,r=e.arr.length;for(;e.pos<r;){let r=e.arr[e.pos++];if(t+=(r&rx)*n,n*=128,r<Vb)return t;if(t>ix)throw Tx}throw wx},Mx=e=>{let t=e.arr[e.pos++],n=t&nx,r=64,i=(t&Bb)>0?-1:1;if((t&Vb)===0)return i*n;let a=e.arr.length;for(;e.pos<a;){if(t=e.arr[e.pos++],n+=(t&rx)*r,r*=128,t<Vb)return i*n;if(n>ix)throw Tx}throw wx},Nx=dx?e=>dx.decode(kx(e)):e=>{let t=jx(e);if(t===0)return``;{let n=String.fromCodePoint(Ax(e));if(--t<100)for(;t--;)n+=String.fromCodePoint(Ax(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))}},Px=e=>{let t=e.pos,n=Nx(e);return e.pos=t,n},Fx=Date.now,Ix=()=>new Map,Lx=(e,t,n)=>{let r=e.get(t);return r===void 0&&e.set(t,r=n()),r},Rx=class{constructor(){this._observers=Ix()}on(e,t){Lx(this._observers,e,ax).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 ox((this._observers.get(e)||Ix()).values()).forEach(e=>e(...t))}destroy(){this._observers=Ix()}},zx=Symbol(`Equality`),Bx=Object.keys,Vx=e=>Bx(e).length,Hx=(e,t)=>Object.prototype.hasOwnProperty.call(e,t),Ux=(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[zx]!=null)return e[zx](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)||!Ux(e.get(n),t.get(n)))return!1;break;case void 0:case Object:if(Vx(e)!==Vx(t))return!1;for(let n in e)if(!Hx(e,n)||!Ux(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(!Ux(e[n],t[n]))return!1;break;default:return!1}return!0},Wx=3e4,Gx=class extends Rx{constructor(e){super(),this.doc=e,this.clientID=e.clientID,this.states=new Map,this.meta=new Map,this._checkInterval=setInterval(()=>{let e=Fx();this.getLocalState()!==null&&Wx/2<=e-this.meta.get(this.clientID).lastUpdated&&this.setLocalState(this.getLocalState());let t=[];this.meta.forEach((n,r)=>{r!==this.clientID&&Wx<=e-n.lastUpdated&&this.states.has(r)&&t.push(r)}),t.length>0&&Kx(this,t,`timeout`)},Lb(Wx/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:Fx()});let a=[],o=[],s=[],c=[];e===null?c.push(t):i==null?e!=null&&a.push(t):(o.push(t),Ux(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}},Kx=(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:Fx()})}r.push(i)}}r.length>0&&(e.emit(`change`,[{added:[],updated:[],removed:r},n]),e.emit(`update`,[{added:[],updated:[],removed:r},n]))},qx=(e,t,n=e.states)=>{let r=t.length,i=px();_x(i,r);for(let a=0;a<r;a++){let r=t[a],o=n.get(r)||null,s=e.meta.get(r).clock;_x(i,r),_x(i,s),bx(i,JSON.stringify(o))}return hx(i)},Jx=(e,t,n)=>{let r=Dx(t),i=Fx(),a=[],o=[],s=[],c=[],l=jx(r);for(let t=0;t<l;t++){let t=jx(r),n=jx(r),l=JSON.parse(Nx(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&&(Ux(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])},Yx=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={}}},Xx=class{constructor(e){this.data=e,this.encoder=px(),this.decoder=Dx(new Uint8Array(this.data))}peekVarString(){return Px(this.decoder)}readVarUint(){return jx(this.decoder)}readVarString(){return Nx(this.decoder)}readVarUint8Array(){return kx(this.decoder)}writeVarUint(e){return _x(this.encoder,e)}writeVarString(e){return bx(this.encoder,e)}writeVarUint8Array(e){return Sx(this.encoder,e)}length(){return mx(this.encoder)}},Zx=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}({}),Qx=function(e){return e.Connecting=`connecting`,e.Connected=`connected`,e.Disconnected=`disconnected`,e}({}),$x=class{constructor(){this.encoder=px()}get(e){return e.encoder}toUint8Array(){return hx(this.encoder)}},eS=class extends $x{constructor(...e){super(...e),this.type=Zx.CLOSE,this.description=`Ask the server to close the connection`}get(e){return bx(this.encoder,e.documentName),_x(this.encoder,this.type),this.encoder}},tS=class e extends Yx{static{this.DEDUPLICATABLE_TYPES=new Set([Zx.Awareness,Zx.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=Qx.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=Qx.Connected,this.emit(`status`,{status:Qx.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===Qx.Disconnected&&this.shouldConnect&&this.connect(),this.receivedOnOpenPayload&&this.status===Qx.Connected&&e.onOpen(this.receivedOnOpenPayload)}detach(e){let t=e.effectiveName;this.configuration.providerMap.has(t)&&(e.send(eS,{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===Qx.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:Ib(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=Qx.Connecting,this.emit(`status`,{status:Qx.Connecting}),this.connectionAttempt={resolve:e,reject:t}})}onMessage(e){this.resolveConnectionAttempt(),this.lastMessageReceived=Fx();let t=new Uint8Array(e.data);if(t.length===1&&t[0]===Zx.Ping){this.sendPong();return}let n=new Xx(t).peekVarString();this.configuration.providerMap.get(n)?.onMessage(e)}sendPong(){let e=px();_x(e,Zx.Pong),this.send(hx(e))}resolveConnectionAttempt(){this.connectionAttempt&&(this.connectionAttempt.resolve(),this.connectionAttempt=null,this.status=Qx.Connected,this.emit(`status`,{status:Qx.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===Qx.Connected&&this.lastMessageReceived&&(this.configuration.messageReconnectTimeout>=Fx()-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=Dx(e);return{documentName:Nx(t),messageType:jx(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===Mb.Open?this.webSocket.send(e):this.addToQueue(e)}onClose({event:e}){this.closeTries=0,this.cleanupWebSocket(),this.connectionAttempt&&this.rejectConnectionAttempt(),this.status=Qx.Disconnected,this.emit(`status`,{status:Qx.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()}},nS=0,rS=1,iS=2,aS=(e,t)=>{_x(e,nS),Sx(e,Mp(t))},oS=(e,t,n)=>{_x(e,rS),Sx(e,Ep(t,n))},sS=(e,t,n)=>oS(t,n,kx(e)),cS=(e,t,n,r)=>{try{Cp(t,kx(e),n)}catch(e){r?.(e),console.error(`Caught error while handling a Yjs update`,e)}},lS=(e,t)=>{_x(e,iS),Sx(e,t)},uS=cS,dS=(e,t,n,r,i)=>{let a=jx(e);switch(a){case nS:sS(e,t,n);break;case rS:cS(e,n,r,i);break;case iS:uS(e,n,r,i);break;default:throw Error(`Unknown message type`)}return a},fS=class{constructor(e){this.message=e}apply(e,t){let{message:n}=this,r=n.readVarUint(),i=n.length();switch(r){case Zx.Sync:this.applySyncMessage(e,t);break;case Zx.Awareness:this.applyAwarenessMessage(e);break;case Zx.Auth:this.applyAuthMessage(e);break;case Zx.QueryAwareness:this.applyQueryAwarenessMessage(e);break;case Zx.Stateless:e.receiveStateless(Nx(n.decoder));break;case Zx.SyncStatus:this.applySyncStatusMessage(e,Mx(n.decoder)===1);break;case Zx.CLOSE:let i={code:1e3,reason:Nx(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($x,{encoder:n.encoder})}applySyncMessage(e,t){let{message:n}=this;n.writeVarUint(Zx.Sync);let r=dS(n.decoder,n.encoder,e.document,e);t&&r===rS&&(e.synced=!0)}applySyncStatusMessage(e,t){t&&e.decrementUnsyncedChanges()}applyAwarenessMessage(e){if(!e.awareness)return;let{message:t}=this;Jx(e.awareness,t.readVarUint8Array(),e)}applyAuthMessage(e){let{message:t}=this;Db(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(Zx.Awareness),t.writeVarUint8Array(qx(e.awareness,Array.from(e.awareness.getStates().keys())))}},pS=class{constructor(e,t={}){this.message=new e,this.encoder=this.message.get(t)}create(){return hx(this.encoder)}send(e){e?.send(this.create())}},mS=`4.0.0-rc.1`,hS=class extends $x{constructor(...e){super(...e),this.type=Zx.Auth,this.description=`Authentication`}get(e){if(e.token===void 0)throw Error("The authentication message requires `token` as an argument.");return bx(this.encoder,e.documentName),_x(this.encoder,this.type),Eb(this.encoder,e.token),bx(this.encoder,mS),this.encoder}},gS=class extends $x{constructor(...e){super(...e),this.type=Zx.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`);bx(this.encoder,e.documentName),_x(this.encoder,this.type);let t;return t=e.states===void 0?qx(e.awareness,e.clients):qx(e.awareness,e.clients,e.states),Sx(this.encoder,t),this.encoder}},_S=class extends $x{constructor(...e){super(...e),this.type=Zx.Stateless,this.description=`A stateless message`}get(e){return bx(this.encoder,e.documentName),_x(this.encoder,this.type),bx(this.encoder,e.payload??``),this.encoder}},vS=class extends $x{constructor(...e){super(...e),this.type=Zx.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 bx(this.encoder,e.documentName),_x(this.encoder,this.type),aS(this.encoder,e.document),this.encoder}},yS=class extends $x{constructor(...e){super(...e),this.type=Zx.Sync,this.description=`A document update`}get(e){return bx(this.encoder,e.documentName),_x(this.encoder,this.type),lS(this.encoder,e.update),this.encoder}},bS=class extends Error{constructor(...e){super(...e),this.code=1001}},xS=class extends Yx{get effectiveName(){return this.configuration.sessionAwareness?Ab(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 sp,this.configuration.awareness=e.awareness===void 0?new Gx(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:Ob(this.awareness.getStates())})}),this.awareness?.on(`change`,()=>{this.emit(`awarenessChange`,{states:Ob(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 tS(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(vS,{document:this.document,documentName:this.effectiveName})}pageHide(){this.awareness&&Kx(this.awareness,[this.document.clientID],`page hide`)}registerEventListeners(){typeof window>`u`||!(`addEventListener`in window)||window.addEventListener(`pagehide`,this.boundPageHide)}sendStateless(e){this.send(_S,{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(hS,{token:e??``,documentName:this.effectiveName})}documentUpdateHandler(e,t){t!==this&&(this.incrementUnsyncedChanges(),this.send(yS,{update:e,documentName:this.effectiveName}))}awarenessUpdateHandler({added:e,updated:t,removed:n},r){let i=e.concat(t).concat(n);this.send(gS,{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(vS,{document:this.document,documentName:this.effectiveName}),this.awareness&&this.awareness.getLocalState()!==null&&this.send(gS,{awareness:this.awareness,clients:[this.document.clientID],documentName:this.effectiveName})}send(e,t){if(!this._isAttached)return;let n=new pS(e,t);this.emit(`outgoingMessage`,{message:n.message}),n.send(this.configuration.websocketProvider)}onMessage(e){let t=new Xx(e.data),{documentName:n}=jb(t.readVarString());t.writeVarString(this.effectiveName),this.emit(`message`,{event:e,message:new Xx(e.data)}),new fS(t).apply(this,!0)}onClose(){this.isAuthenticated=!1,this.synced=!1,this.awareness&&Kx(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&&(Kx(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 bS(`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)}},SS=e=>mu((t,n)=>{e.onerror=e=>n(Error(e.target.error)),e.onsuccess=e=>t(e.target.result)}),CS=(e,t)=>mu((n,r)=>{let i=indexedDB.open(e);i.onupgradeneeded=e=>t(e.target.result),i.onerror=e=>r(Bl(e.target.error)),i.onsuccess=e=>{let t=e.target.result;t.onversionchange=()=>{t.close()},n(t)}}),wS=e=>SS(indexedDB.deleteDatabase(e)),TS=(e,t)=>t.forEach(t=>e.createObjectStore.apply(e,t)),ES=(e,t,n=`readwrite`)=>{let r=e.transaction(t,n);return t.map(e=>LS(r,e))},DS=(e,t)=>SS(e.count(t)),OS=(e,t)=>SS(e.get(t)),kS=(e,t)=>SS(e.delete(t)),AS=(e,t,n)=>SS(e.put(t,n)),jS=(e,t)=>SS(e.add(t)),MS=(e,t,n)=>SS(e.getAll(t,n)),NS=(e,t,n)=>{let r=null;return IS(e,t,e=>(r=e,!1),n).then(()=>r)},PS=(e,t=null)=>NS(e,t,`prev`),FS=(e,t)=>mu((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()}}),IS=(e,t,n,r=`next`)=>FS(e.openKeyCursor(t,r),e=>n(e.key)),LS=(e,t)=>e.objectStore(t),RS=(e,t)=>IDBKeyRange.upperBound(e,t),zS=(e,t)=>IDBKeyRange.lowerBound(e,t),BS=`custom`,VS=`updates`,HS=(e,t=()=>{},n=()=>{})=>{let[r]=ES(e.db,[VS]);return MS(r,zS(e._dbref,!1)).then(i=>{e._destroyed||(t(r),xm(e.doc,()=>{i.forEach(t=>Cp(e.doc,t))},e,!1),n(r))}).then(()=>PS(r).then(t=>{e._dbref=t+1})).then(()=>DS(r).then(t=>{e._dbsize=t})).then(()=>r)},US=(e,t=!0)=>HS(e).then(n=>{(t||e._dbsize>=500)&&jS(n,Ep(e.doc)).then(()=>kS(n,RS(e._dbref,!0))).then(()=>DS(n).then(t=>{e._dbsize=t}))}),WS=class extends Nc{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=CS(e,e=>TS(e,[[`updates`,{autoIncrement:!0}],[`custom`]])),this.whenSynced=mu(e=>this.on(`synced`,()=>e(this))),this._db.then(e=>{this.db=e,HS(this,async e=>{await DS(e)>0&&jS(e,Ep(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]=ES(this.db,[VS]);jS(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(()=>{US(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(()=>{wS(this.name)})}get(e){return this._db.then(t=>{let[n]=ES(t,[BS],`readonly`);return OS(n,e)})}set(e,t){return this._db.then(n=>{let[r]=ES(n,[BS]);return AS(r,t,e)})}del(e){return this._db.then(t=>{let[n]=ES(t,[BS]);return kS(n,e)})}};function GS(){return!0}var KS=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}`;let i=GS()?0:performance.now();this._idb=new WS(this._dbName,r),this.whenSynced=this._idb.whenSynced.then(()=>{if(!GS()){let e=performance.now();X(`ok/pool/idb-whensynced`,{docName:n,durationMs:Math.round((e-i)*1e3)/1e3},{startTime:i,duration:e-i})}return this})}get synced(){return this._idb.synced}async destroy(){let e=GS()?0:performance.now();try{await this._idb.destroy()}finally{if(!GS()){let t=performance.now();X(`ok/pool/idb-destroy`,{dbName:this._dbName,durationMs:Math.round((t-e)*1e3)/1e3},{startTime:e,duration:t-e})}}}async clearData(){let e=GS()?0:performance.now();try{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}`))}})}finally{if(!GS()){let t=performance.now();X(`ok/pool/idb-cleardata`,{dbName:this._dbName,durationMs:Math.round((t-e)*1e3)/1e3},{startTime:e,duration:t-e})}}}};function qS(e){return new KS(e)}function JS(e){return Mp(e)}function YS(e,t){return t===null?Ep(e):Ep(e,t)}function XS(e,t){if(e===null)return t;if(t===null)return e;let n=Op(e),r=Op(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 Mp(i)}function ZS(e){let t={};if(fn.inject(dn.active(),t),!t.traceparent)return e;let n=e.includes(`?`)?`&`:`?`,r=[`traceparent=${encodeURIComponent(t.traceparent)}`];return t.tracestate&&r.push(`tracestate=${encodeURIComponent(t.tracestate)}`),`${e}${n}${r.join(`&`)}`}var QS=({key:e,editor:t,onPaste:n,onDrop:r,allowedMimeTypes:i})=>new v({key:e||new T(`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))}}}),$S=Fe.create({name:`fileHandler`,addOptions(){return{onPaste:void 0,onDrop:void 0,allowedMimeTypes:void 0}},addProseMirrorPlugins(){return[QS({key:new T(this.name),editor:this.editor,allowedMimeTypes:this.options.allowedMimeTypes,onDrop:this.options.onDrop,onPaste:this.options.onPaste})]}}),eC=Fe.create({name:`keyboardNav`,priority:50,addKeyboardShortcuts(){return{Escape:({editor:e})=>{let{state:t}=e;if(t.selection instanceof z){let n=t.selection.from+t.selection.node.nodeSize,r=t.doc.resolve(Math.min(n,t.doc.content.size)),i=Ct.near(r);return e.view.dispatch(t.tr.setSelection(i)),!0}return t.selection instanceof Ct?e.commands.selectParentNode():!1},ArrowUp:({editor:e})=>{let{state:t}=e;if(!(t.selection instanceof z))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=z.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 z))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=z.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 Ct)||!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(Ct.create(s.doc,f)),e.view.dispatch(s.scrollIntoView()),!0}}}}),tC=new WeakMap;function nC(e,t){if(t===null){tC.delete(e);return}tC.set(e,t)}function rC(e){return tC.get(e)??null}function iC(e){return`pagesBySlug`in e}function aC(e){return iC(e)?e.pages:e}function oC(e,t){return iC(e)?e.assetPaths??new Set:t??new Set}function sC(e,t){let n=ze(e);if(n){if(iC(t))return t.pagesBySlug.get(n);for(let e of t)if(ze(e)===n)return e}}function cC(e){let t=e.trim();if(!t)return null;let n=ze(t);return n?{target:n,alias:n===t?null:t,anchor:null}:null}function lC(e){let t=e.trim();if(!t)return[];let n=ze(t);return n.length>0&&n!==t?[n]:[]}function uC(e){let t=((e.trim().split(`#`)[0]??``).trim().split(`?`)[0]??``).trim();return t.startsWith(`/`)?t.slice(1):t}function dC(e,t){let n=uC(e);if(!n)return null;if(t.has(n))return n;let r=n.toLowerCase();for(let e of t)if(e.toLowerCase()===r)return e;if(n.includes(`/`))return null;let i=[...t].filter(e=>{let t=e.lastIndexOf(`/`);return(t===-1?e:e.slice(t+1)).toLowerCase()===r});return i.length===0?null:i.sort((e,t)=>e.localeCompare(t))[0]??null}function fC(e,t,n){let r=e.trim();if(!r)return!1;if(dC(r,oC(t,n)))return!0;let i=aC(t);return i.has(r)||lC(r).some(e=>i.has(e))?!0:sC(r,t)!==void 0}var pC=new T(`imageUpload`);function mC(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 hC=new v({key:pC,state:{init(){return{decorations:P.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(pC);if(!i)return{decorations:n,uploads:r};if(i.type===`add`){let t=Be.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 pC.getState(e)?.decorations??P.empty}}});function gC(e){let t=e.lastIndexOf(`/`);return t===-1?``:e.slice(0,t)}function _C(e){let t=e.lastIndexOf(`/`);return t===-1?e:e.slice(t+1)}function vC(e){return e.split(`/`).filter(e=>e!==``)}function yC(e,t){let n=gC(e),r=gC(t),i=_C(e);if(n===r)return i;let a=vC(r),o=vC(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 bC(e){return rC(e)}function xC(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 SC(e){let t=p(e);return t===`md`||t===`mdx`?{kind:`wiki-link`,ext:t}:l.has(t)?{kind:`jsx-img`,ext:t}:o.has(t)?{kind:`jsx-video`,ext:t}:ee.has(t)?{kind:`jsx-audio`,ext:t}:ke.has(t)?{kind:`wikiembed`,ext:t}:{kind:`markdown-link`,ext:t}}async function CC(e,t,n){let r=bC(t),i=r?`${r}.md`:``;if(!i){Wt.error(`Cannot upload: no document is open`);return}let a=crypto.randomUUID(),o=mC(e);t.view.dispatch(t.state.tr.setMeta(pC,{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),wC(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),wC(t,a,e);return}if(typeof l.src!=`string`){console.error(`[uploadAndInsert] Response missing src:`,l),wC(t,a);return}let u=l.src,d=l.deduped===!0,f=gC(i),p=typeof l.path==`string`&&l.path.length>0?l.path:f?`${f}/${u}`:u;d&&Wt.info(`Already at ${p} — reusing.`);let m=SC(e.name),{state:h}=t,g=pC.getState(h)?.uploads.get(a)??n,_=h.tr.setMeta(pC,{type:`remove`,id:a}),v=yC(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`),wC(t,a);return}let e=xC(m.kind,y);t.chain().command(({tr:e})=>(e.setMeta(pC,{type:`remove`,id:a}),!0)).focus().insertContentAt(g,e).command(({tr:e,dispatch:t})=>{if(!t)return!0;let n=e.mapping.map(g);return e.doc.nodeAt(n)?.type.name===`jsxComponent`&&e.setSelection(z.create(e.doc,n)),!0}).run();return}if(m.kind===`wikiembed`){let e=h.schema.nodes.wikiLinkEmbed;if(!e){console.error(`[uploadAndInsert] wikiLinkEmbed node missing from schema`),wC(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`),wC(t,a);return}let r=cC(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 wC(e,t,n){e.view.dispatch(e.state.tr.setMeta(pC,{type:`remove`,id:t})),Wt.error(n??`Upload failed`)}var TC={ChevronRight:hr,Image:Mr,MessageSquareWarning:zr,Sigma:Kr,SquarePlay:qr,Volume2:$r,Workflow:ei};function EC(e){return e&&Object.hasOwn(TC,e)?TC[e]:fr}var DC={ChevronRight:hr};function OC(e){if(!e||!e.startsWith(`lucide:`))return null;let t=e.slice(7);return Object.hasOwn(DC,t)?DC[t]:null}function kC(e){let t=(0,Y.c)(24),n;t[0]===e.icon?n=t[1]:(n=OC(e.icon),t[0]=e.icon,t[1]=n);let r=n,i=r?`custom`:void 0,a;t[2]===Symbol.for(`react.memo_cache_sentinel`)?(a=(0,J.jsx)(hr,{size:14,className:`accordion-chevron`,"aria-hidden":`true`}),t[2]=a):a=t[2];let o;t[3]===r?o=t[4]:(o=r?(0,J.jsx)(r,{size:16,className:`accordion-icon`,"aria-hidden":`true`}):null,t[3]=r,t[4]=o);let s=e.title??`Accordion`,c;t[5]===s?c=t[6]:(c=(0,J.jsx)(`span`,{className:`accordion-title`,children:s}),t[5]=s,t[6]=c);let l;t[7]===e.description?l=t[8]:(l=e.description?(0,J.jsx)(`span`,{className:`accordion-description`,children:e.description}):null,t[7]=e.description,t[8]=l);let u;t[9]!==c||t[10]!==l?(u=(0,J.jsxs)(`span`,{className:`accordion-title-group`,children:[c,l]}),t[9]=c,t[10]=l,t[11]=u):u=t[11];let d;t[12]!==o||t[13]!==u?(d=(0,J.jsxs)(`summary`,{className:`accordion-summary`,contentEditable:!1,children:[a,o,u]}),t[12]=o,t[13]=u,t[14]=d):d=t[14];let f;t[15]===e.children?f=t[16]:(f=(0,J.jsx)(`div`,{className:`accordion-body`,children:e.children}),t[15]=e.children,t[16]=f);let p;return t[17]!==e.defaultOpen||t[18]!==e.id||t[19]!==e.name||t[20]!==i||t[21]!==d||t[22]!==f?(p=(0,J.jsxs)(`details`,{className:`accordion`,"data-accordion-icon":i,open:e.defaultOpen,id:e.id,name:e.name,children:[d,f]}),t[17]=e.defaultOpen,t[18]=e.id,t[19]=e.name,t[20]=i,t[21]=d,t[22]=f,t[23]=p):p=t[23],p}function AC(e){return e!==!1}function jC(e){let t=(0,Y.c)(10),n=e.src,r=e.title,i;t[0]===e.controls?i=t[1]:(i=AC(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,J.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 MC={note:Nr,tip:Pr,important:zr,warning:nt,caution:Vr,abstract:br,info:dr,todo:Ir,success:qe,question:vr,failure:yr,danger:ti,bug:pr,example:Er,quote:Wr},NC={Info:Nr,Lightbulb:Pr,MessageSquareWarning:zr,AlertTriangle:nt,AlertOctagon:Vr,ClipboardList:br,BookOpen:dr,ListTodo:Ir,CircleCheck:qe,CircleHelp:vr,CircleX:yr,Zap:ti,Bug:pr,FlaskConical:Er,Quote:Wr};function PC(e,t){if(!e||!e.startsWith(`lucide:`))return MC[t];let n=e.slice(7);return Object.hasOwn(NC,n)?NC[n]:MC[t]}var FC=new Set([`note`,`tip`,`important`,`warning`,`caution`,`abstract`,`info`,`todo`,`success`,`question`,`failure`,`danger`,`bug`,`example`,`quote`]);function IC(e){return typeof e==`string`&&FC.has(e)?e:`note`}function LC(e){let t=(0,Y.c)(29),n,r;t[0]!==e.icon||t[1]!==e.type?(r=IC(e.type),n=PC(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,J.jsxs)(`span`,{className:`callout-header`,contentEditable:!1,children:[(0,J.jsx)(i,{size:16,className:`callout-icon`,"aria-hidden":`true`}),e.title?(0,J.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,J.jsx)(`span`,{className:`callout-title`,children:`Details`}),t[9]=c,t[10]=i);let a;t[11]===Symbol.for(`react.memo_cache_sentinel`)?(a=(0,J.jsx)(mr,{size:16,className:`callout-chevron`,"aria-hidden":`true`}),t[11]=a):a=t[11];let s;t[12]===i?s=t[13]:(s=(0,J.jsxs)(`summary`,{className:`callout-summary`,contentEditable:!1,children:[i,a]}),t[12]=i,t[13]=s);let l;t[14]===e.children?l=t[15]:(l=(0,J.jsx)(`div`,{className:`callout-body`,children:e.children}),t[14]=e.children,t[15]=l);let u;return t[16]!==n||t[17]!==o||t[18]!==s||t[19]!==l||t[20]!==r?(u=(0,J.jsxs)(`details`,{className:`callout callout-collapsible`,"data-callout-type":r,open:n,style:o,children:[s,l]}),t[16]=n,t[17]=o,t[18]=s,t[19]=l,t[20]=r,t[21]=u):u=t[21],u}let l;t[22]===e.children?l=t[23]:(l=(0,J.jsx)(`div`,{className:`callout-body`,children:e.children}),t[22]=e.children,t[23]=l);let u;return t[24]!==c||t[25]!==o||t[26]!==l||t[27]!==r?(u=(0,J.jsxs)(`div`,{className:`callout callout-static`,"data-callout-type":r,style:o,children:[c,l]}),t[24]=c,t[25]=o,t[26]=l,t[27]=r,t[28]=u):u=t[28],u}function RC(){return q.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`},q.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 zC(){return q.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`},q.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 BC(e){return typeof Element>`u`?!1:e instanceof Element}var VC=(e,t)=>BC(t)&&t.tagName.toUpperCase()===e,HC=e=>VC(`DIV`,e)||VC(`SPAN`,e),UC=e=>VC(`IMG`,e),WC=e=>e.complete&&e.naturalHeight!==0,GC=e=>VC(`SVG`,e),KC=({height:e,offset:t,width:n})=>Math.min((window.innerWidth-t*2)/n,(window.innerHeight-t*2)/e),qC=({containerHeight:e,containerWidth:t,offset:n,targetHeight:r,targetWidth:i})=>{let a=KC({height:r,offset:n,width:i}),o=i>r?i/t:r/e;return a>1?o:a*o},JC=({containerHeight:e,containerWidth:t,hasScalableSrc:n,offset:r,targetHeight:i,targetWidth:a})=>e===0||t===0?1:!n&&i!==0&&a!==0?qC({containerHeight:e,containerWidth:t,offset:r,targetHeight:i,targetWidth:a}):KC({height:e,offset:r,width:t}),YC=/url(?:\(['"]?)(?<url>.*?)(?:['"]?\))/,XC=e=>{if(e!==null){if(UC(e))return e.currentSrc===``?void 0:e.currentSrc;if(HC(e)){let{backgroundImage:t}=window.getComputedStyle(e);if(t!==``)return YC.exec(t)?.[1]}}},ZC=e=>{if(e!==null)return UC(e)?e.alt:e.getAttribute(`aria-label`)??void 0},QC=({containerHeight:e,containerLeft:t,containerTop:n,containerWidth:r,hasScalableSrc:i,offset:a,targetHeight:o,targetWidth:s})=>{let c=JC({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})`}},$C=({position:e,relativeNum:t})=>{let n=parseFloat(e);return e.endsWith(`%`)?t*n/100:n},ew=({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=$C({position:p,relativeNum:r-l*f}),g=$C({position:m,relativeNum:e-c*f}),_=JC({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=$C({position:a,relativeNum:r-l}),f=$C({position:u,relativeNum:e-c}),p=JC({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=JC({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{}},tw=({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=$C({position:p,relativeNum:a-l*f}),g=$C({position:m,relativeNum:n-c*f}),_=JC({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=$C({position:t,relativeNum:a-l}),f=$C({position:u,relativeNum:n-c}),p=JC({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=$C({position:u,relativeNum:a}),p=$C({position:d,relativeNum:n}),m=f/l,h=p/c,g=Math.min(m,h),[_=`50%`,v=`50%`]=e.split(` `),y=$C({position:_,relativeNum:a-l*g}),b=$C({position:v,relativeNum:n-c*g}),x=JC({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})`}}},nw=/\.svg$/i,rw=({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&&nw.test(t),l=s.getBoundingClientRect(),u=window.getComputedStyle(s),d=i!=null&&HC(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=QC({containerHeight:l.height,containerLeft:l.left,containerTop:l.top,containerWidth:l.width,hasScalableSrc:c,offset:a,targetHeight:p,targetWidth:m}),g=f?ew({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?tw({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},iw=e=>{if(e==null)return{};if(GC(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}},aw=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}`)}})})},ow=[`img`,`svg`,`[role="img"]`,`[data-zoom]`].map(e=>`${e}:not([aria-hidden="true"])`).join(`,`),sw={overflow:``,width:``};function cw(){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 lw(e){e.preventDefault()}function uw(e){return q.createElement(dw,{...e})}var dw=class extends q.Component{constructor(){super(...arguments),this.state={id:``,isZoomImgLoaded:!1,loadedImgEl:void 0,modalState:`UNLOADED`,shouldRefresh:!1,styleGhost:{}},this.refContent=q.createRef(),this.refDialog=q.createRef(),this.refModalContent=q.createRef(),this.refModalImg=q.createRef(),this.refWrap=q.createRef(),this.imgEl=null,this.isScaling=!1,this.prevBodyAttrs=sw,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(ow),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:iw(this.imgEl)}))}),this.imgElResizeObserver.observe(this.imgEl),this.contentChangeObserver??(this.contentChangeObserver=new MutationObserver(()=>{this.setState({styleGhost:iw(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=XC(this.imgEl);if(e==null||e===``)return;let t=new Image,{imgEl:n}=this;if(UC(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:iw(this.imgEl)})};t.decode().then(r).catch(()=>{if(WC(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||GC(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=sw},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(WC(n)){r();return}n.onload=r})}},this.UNSAFE_handleSvg=()=>{let{imgEl:e,refModalImg:t,styleModalImg:n}=this;if(GC(e)){let r=e.cloneNode(!0);aw(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=HC(a),j=UC(a),M=GC(a),N=ZC(a),P=XC(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`,W={visibility:T===`UNLOADED`?`visible`:`hidden`};this.styleModalImg=z&&a!==null?rw({hasZoomImg:R,imgSrc:P,isSvg:M,isZoomed:f&&V,loadedImgEl:w,offset:g,shouldRefresh:E,targetEl:a}):{};let ee=null;if(z){let t=j||A?q.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?q.createElement(`div`,{"data-rmiz-modal-img":!0,ref:b,style:this.styleModalImg}):null,n=q.createElement(`button`,{"aria-label":o,"data-rmiz-btn-unzoom":``,onClick:e,type:`button`},q.createElement(u,null));ee=m==null?q.createElement(q.Fragment,null,t,n):q.createElement(m,{buttonUnzoom:n,modalState:T,img:t,isZoomImgLoaded:C,onUnzoom:r})}return q.createElement(p,{"aria-owns":z?O:void 0,"data-rmiz":``,ref:x},q.createElement(p,{"data-rmiz-content":H,ref:_,style:W},c),z&&q.createElement(p,{"data-rmiz-ghost":``,style:D},q.createElement(`button`,{"aria-label":B,"data-rmiz-btn-zoom":``,onClick:i,type:`button`},q.createElement(d,null))),z&&xi.createPortal(q.createElement(`dialog`,{"aria-labelledby":k,"aria-modal":`true`,className:l,"data-rmiz-modal":``,id:O,onClick:t,onClose:n,onCancel:lw,ref:v,role:`dialog`},q.createElement(`div`,{"data-rmiz-modal-overlay":U}),q.createElement(`div`,{"data-rmiz-modal-content":``,ref:y},ee)),cw()))}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)}};dw.defaultProps={a11yNameButtonUnzoom:`Minimize image`,a11yNameButtonZoom:`Expand image`,canSwipeToUnzoom:!0,IconUnzoom:RC,IconZoom:zC,isDisabled:!1,swipeToUnzoomThreshold:10,wrapElement:`div`,zoomMargin:0};function fw({onZoomChange:e,...t}){let[n,r]=q.useState(!1),i=q.useCallback((t,{event:n})=>{r(t),e?.(t,{event:n})},[e]);return q.createElement(uw,{...t,isZoomed:n,onZoomChange:i})}function pw(e){return e??`lazy`}function mw(e){let t=(0,Y.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=pw(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,J.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 hw(e){let t=(0,Y.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,J.jsx)(fw,{wrapElement:`span`,zoomMargin:20,zoomImg:n,children:(0,J.jsx)(mw,{...e})}),t[1]=e,t[2]=r),r}var gw=(0,q.lazy)(async()=>{let{default:e}=await n(async()=>{let{default:e}=await import(`./katex-DBuiuHex.js`);return{default:e}},[],import.meta.url);function t(t){let n=(0,Y.c)(7),r;n[0]===t.formula?r=n[1]:(r=e.renderToString(t.formula,{displayMode:!0,throwOnError:!1,strict:`ignore`,trust:!1}),n[0]=t.formula,n[1]=r);let i=r,a;n[2]===i?a=n[3]:(a={__html:i},n[2]=i,n[3]=a);let o;return n[4]!==t.id||n[5]!==a?(o=(0,J.jsx)(`div`,{className:`math math-display`,"data-component-type":`math`,id:t.id,dangerouslySetInnerHTML:a}),n[4]=t.id,n[5]=a,n[6]=o):o=n[6],o}return{default:t}});function _w(e){let t=(0,Y.c)(3),n=e.formula||`\xA0`,r;return t[0]!==e.id||t[1]!==n?(r=(0,J.jsx)(`div`,{className:`math math-placeholder`,"data-component-type":`math`,id:e.id,children:n}),t[0]=e.id,t[1]=n,t[2]=r):r=t[2],r}function vw(e){let t=(0,Y.c)(6),n=e.formula??``;if(!n){let r;return t[0]!==n||t[1]!==e.id?(r=(0,J.jsx)(_w,{formula:n,id:e.id}),t[0]=n,t[1]=e.id,t[2]=r):r=t[2],r}let r;return t[3]!==n||t[4]!==e.id?(r=(0,J.jsx)(q.Suspense,{fallback:(0,J.jsx)(_w,{formula:n,id:e.id}),children:(0,J.jsx)(gw,{formula:n,id:e.id})}),t[3]=n,t[4]=e.id,t[5]=r):r=t[5],r}var yw=null;function bw(){return yw||=n(()=>import(`./mermaid.core-4xgx5kDJ.js`).then(e=>{let t=e.default;return t.initialize({startOnLoad:!1,securityLevel:`strict`,theme:`default`,suppressErrorRendering:!0}),t}),__vite__mapDeps([0,1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19,20,21,22,23]),import.meta.url).catch(e=>{throw yw=null,e}),yw}function xw(e){let t=(0,Y.c)(26),n=e.chart??``,r=(0,q.useId)(),i;if(t[0]!==r){let e;t[2]===Symbol.for(`react.memo_cache_sentinel`)?(e=/:/g,t[2]=e):e=t[2],i=r.replace(e,`_`),t[0]=r,t[1]=i}else i=t[1];let a=`mermaid-${i}`,o;t[3]===Symbol.for(`react.memo_cache_sentinel`)?(o={status:`idle`,svg:``,error:``},t[3]=o):o=t[3];let[s,c]=(0,q.useState)(o),l,u;if(t[4]!==n||t[5]!==a?(l=()=>{if(!n.trim()){c({status:`idle`,svg:``,error:``});return}let e=!1;return c(Sw),bw().then(async t=>{try{let r=await t.render(a,n);e||c({status:`ready`,svg:r.svg,error:``})}catch(t){let n=t;e||c({status:`error`,svg:``,error:n instanceof Error?n.message:String(n)})}}).catch(t=>{e||c({status:`error`,svg:``,error:t instanceof Error?t.message:String(t)})}),()=>{e=!0}},u=[n,a],t[4]=n,t[5]=a,t[6]=l,t[7]=u):(l=t[6],u=t[7]),(0,q.useEffect)(l,u),!n.trim()){let n;t[8]===Symbol.for(`react.memo_cache_sentinel`)?(n=(0,J.jsx)(`span`,{className:`mermaid-empty`,children:` `}),t[8]=n):n=t[8];let r;return t[9]===e.id?r=t[10]:(r=(0,J.jsx)(`div`,{className:`mermaid mermaid-placeholder`,"data-component-type":`mermaid`,id:e.id,children:n}),t[9]=e.id,t[10]=r),r}if(s.status===`error`){let r;t[11]===n?r=t[12]:(r=(0,J.jsx)(`pre`,{className:`mermaid-error-source`,children:n}),t[11]=n,t[12]=r);let i;t[13]===s.error?i=t[14]:(i=(0,J.jsx)(`p`,{className:`mermaid-error-message`,children:s.error}),t[13]=s.error,t[14]=i);let a;return t[15]!==e.id||t[16]!==s.error||t[17]!==r||t[18]!==i?(a=(0,J.jsxs)(`div`,{className:`mermaid mermaid-error`,"data-component-type":`mermaid`,title:s.error,id:e.id,children:[r,i]}),t[15]=e.id,t[16]=s.error,t[17]=r,t[18]=i,t[19]=a):a=t[19],a}let d=`mermaid mermaid-${s.status}`,f;t[20]===s.svg?f=t[21]:(f={__html:s.svg},t[20]=s.svg,t[21]=f);let p;return t[22]!==e.id||t[23]!==d||t[24]!==f?(p=(0,J.jsx)(`div`,{className:d,"data-component-type":`mermaid`,id:e.id,dangerouslySetInnerHTML:f}),t[22]=e.id,t[23]=d,t[24]=f,t[25]=p):p=t[25],p}function Sw(e){return{...e,status:`rendering`}}var Cw=24,ww=24,Tw=12,Ew=.1;function Dw(e,t,n,r){if(n<=0&&(e===`fit-width`||e===`two-odd`||e===`two-even`)||r<=0&&e===`fit-height`)return 1;switch(e){case`fit-width`:return Math.max(Ew,(n-Cw)/t.naturalWidth);case`fit-height`:return Math.max(Ew,(r-ww)/t.naturalHeight);case`single`:return 1;case`two-odd`:case`two-even`:return Math.max(Ew,((n-Cw)/2-Tw)/t.naturalWidth)}}var Ow=600,kw=.5,Aw=3,jw=.25,Mw=null;function Nw(){return Mw||(Mw=(async()=>{let e=await n(()=>import(`./pdf-DaFpV-4n.js`),__vite__mapDeps([24,1]),import.meta.url);if(!e.GlobalWorkerOptions.workerSrc){let t=(await n(async()=>{let{default:e}=await import(`./pdf.worker-Cq62cyp3.js`);return{default:e}},[],import.meta.url)).default;e.GlobalWorkerOptions.workerSrc=t}return e})(),Mw.catch(()=>{Mw=null})),Mw}function Pw(e){return e instanceof Error&&e.name===`RenderingCancelledException`}function Fw(e){let t=(0,Y.c)(84),n,r;if(t[0]!==e.anchor){let{height:i,viewerFragment:a}=ve(e.anchor);n=i??Ow,r=Vw(a),t[0]=e.anchor,t[1]=n,t[2]=r}else n=t[1],r=t[2];let i=r,a=(0,q.useRef)(null),o;t[3]===Symbol.for(`react.memo_cache_sentinel`)?(o=[],t[3]=o):o=t[3];let s=(0,q.useRef)(o),c;t[4]===Symbol.for(`react.memo_cache_sentinel`)?(c=[],t[4]=c):c=t[4];let l=(0,q.useRef)(c),u=(0,q.useRef)(null),d;t[5]===Symbol.for(`react.memo_cache_sentinel`)?(d=[],t[5]=d):d=t[5];let[f,p]=(0,q.useState)(d),[m,h]=(0,q.useState)(!0),[g,_]=(0,q.useState)(null),[v,y]=(0,q.useState)(i??1),[b,x]=(0,q.useState)(String(i??1)),[S,C]=(0,q.useState)(1),[w,T]=(0,q.useState)(`fit-width`),[E,D]=(0,q.useState)(!1),[O,k]=(0,q.useState)(!1),[A,j]=(0,q.useState)(0),[M,N]=(0,q.useState)(0),P=f.length,F,I;t[6]===e.src?(F=t[7],I=t[8]):(F=()=>{if(!e.src){h(!1);return}let t=!1,n=null;return h(!0),_(null),(async()=>{try{let r=await(await Nw()).getDocument({url:e.src,isEvalSupported:!1}).promise;if(t){await r.destroy();return}n=r,u.current=r;let i=[];for(let e=1;e<=r.numPages;e++){if(t)return;let n=(await r.getPage(e)).getViewport({scale:1});i.push({pageNumber:e,naturalWidth:n.width,naturalHeight:n.height})}if(t)return;p(i)}catch(e){let n=e;if(t)return;_(n instanceof Error?n.message:`Failed to load PDF`),h(!1)}})(),()=>{t=!0,n&&=(n.destroy(),null),u.current=null}},I=[e.src],t[6]=e.src,t[7]=F,t[8]=I),(0,q.useEffect)(F,I);let L,R;t[9]===Symbol.for(`react.memo_cache_sentinel`)?(L=()=>{let e=a.current;if(!e)return;let t=()=>{j(e.clientWidth),N(e.clientHeight)};t();let n=new ResizeObserver(t);return n.observe(e),()=>n.disconnect()},R=[],t[9]=L,t[10]=R):(L=t[9],R=t[10]),(0,q.useEffect)(L,R);let z,B;t[11]!==M||t[12]!==A||t[13]!==w||t[14]!==f||t[15]!==S?(z=()=>{let e=u.current;if(!e||f.length===0||A===0)return;let t=!1,n=null;return(async()=>{try{let r=window.devicePixelRatio||1;for(let i of f){if(t)return;let a=s.current[i.pageNumber-1];if(!a)continue;let o=Dw(w,i,A,M)*S,c=await e.getPage(i.pageNumber);if(t)return;let l=c.getViewport({scale:o});a.width=Math.floor(l.width*r),a.height=Math.floor(l.height*r),a.style.width=`${l.width}px`,a.style.height=`${l.height}px`;let u=a.getContext(`2d`);u&&(u.setTransform(r,0,0,r,0,0),n=c.render({canvas:a,canvasContext:u,viewport:l}),await n.promise,n=null)}t||h(!1)}catch(e){let n=e;if(t||Pw(n))return;console.warn(`[Pdf] page render failed:`,n),_(n instanceof Error?n.message:`Failed to render PDF`),h(!1)}})(),()=>{if(t=!0,n){try{n.cancel()}catch{}n=null}}},B=[f,w,S,A,M],t[11]=M,t[12]=A,t[13]=w,t[14]=f,t[15]=S,t[16]=z,t[17]=B):(z=t[16],B=t[17]),(0,q.useEffect)(z,B);let V,H;t[18]!==f||t[19]!==E?(V=()=>{if(!E)return;let e=u.current;if(!e||f.length===0)return;let t=!1,n=null;return(async()=>{try{let r=window.devicePixelRatio||1;for(let i of f){if(t)return;let a=l.current[i.pageNumber-1];if(!a)continue;let o=120/i.naturalWidth,s=await e.getPage(i.pageNumber);if(t)return;let c=s.getViewport({scale:o});a.width=Math.floor(c.width*r),a.height=Math.floor(c.height*r),a.style.width=`${c.width}px`,a.style.height=`${c.height}px`;let u=a.getContext(`2d`);u&&(u.setTransform(r,0,0,r,0,0),n=s.render({canvas:a,canvasContext:u,viewport:c}),await n.promise,n=null)}}catch(e){let t=e;Pw(t)||console.warn(`[Pdf] thumbnail render failed:`,t)}})(),()=>{if(t=!0,n){try{n.cancel()}catch{}n=null}}},H=[E,f],t[18]=f,t[19]=E,t[20]=V,t[21]=H):(V=t[20],H=t[21]),(0,q.useEffect)(V,H);let U,W;t[22]!==m||t[23]!==i?(U=()=>{if(m||!i)return;let e=a.current,t=s.current[i-1];e&&t&&(e.scrollTop=t.offsetTop-e.offsetTop)},W=[m,i],t[22]=m,t[23]=i,t[24]=U,t[25]=W):(U=t[24],W=t[25]),(0,q.useEffect)(U,W);let ee,te;t[26]===f?(ee=t[27],te=t[28]):(ee=()=>{let e=a.current;if(!e||f.length===0)return;let t=!1,n=()=>{t||(t=!0,requestAnimationFrame(()=>{t=!1;let n=e.scrollTop,r=1;for(let t of f){let i=s.current[t.pageNumber-1];i&&i.offsetTop-e.offsetTop<=n+40&&(r=t.pageNumber)}y(r),x(String(r))}))};return e.addEventListener(`scroll`,n,{passive:!0}),()=>e.removeEventListener(`scroll`,n)},te=[f],t[26]=f,t[27]=ee,t[28]=te),(0,q.useEffect)(ee,te);let ne,re;t[29]===O?(ne=t[30],re=t[31]):(ne=()=>{if(!O)return;let e=e=>{let t=e.target,n=a.current?.closest(`.ok-pdf`);if(!n||!t||!n.contains(t)){k(!1);return}let r=n.querySelector(`.ok-pdf-layout-menu`);r&&!r.contains(t)&&k(!1)};return document.addEventListener(`mousedown`,e),()=>document.removeEventListener(`mousedown`,e)},re=[O],t[29]=O,t[30]=ne,t[31]=re),(0,q.useEffect)(ne,re);let ie;t[32]===P?ie=t[33]:(ie=e=>{let t=Math.max(1,Math.min(P||1,e));y(t),x(String(t));let n=a.current,r=s.current[t-1];n&&r&&n.scrollTo({top:r.offsetTop-n.offsetTop,behavior:`smooth`})},t[32]=P,t[33]=ie);let ae=ie,oe;t[34]!==v||t[35]!==ae||t[36]!==b?(oe=()=>{let e=Number.parseInt(b,10);if(Number.isNaN(e)){x(String(v));return}ae(e)},t[34]=v,t[35]=ae,t[36]=b,t[37]=oe):oe=t[37];let se=oe,ce;t[38]===Symbol.for(`react.memo_cache_sentinel`)?(ce=()=>C(zw),t[38]=ce):ce=t[38];let le=ce,ue;t[39]===Symbol.for(`react.memo_cache_sentinel`)?(ue=()=>C(Rw),t[39]=ue):ue=t[39];let de=ue,fe;t[40]===Symbol.for(`react.memo_cache_sentinel`)?(fe=e=>{T(e),k(!1),C(1)},t[40]=fe):fe=t[40];let pe=fe,me=`${n}px`,he;t[41]===me?he=t[42]:(he={height:me},t[41]=me,t[42]=he);let ge;t[43]===Symbol.for(`react.memo_cache_sentinel`)?(ge=()=>D(Lw),t[43]=ge):ge=t[43];let _e=E?`Hide thumbnails`:`Show thumbnails`,ye;t[44]===Symbol.for(`react.memo_cache_sentinel`)?(ye=(0,J.jsx)(Hr,{size:14,"aria-hidden":`true`}),t[44]=ye):ye=t[44];let be;t[45]!==E||t[46]!==_e?(be=(0,J.jsx)(`button`,{type:`button`,onClick:ge,"aria-label":_e,"aria-pressed":E,className:`ok-pdf-btn`,title:`Toggle thumbnails`,children:ye}),t[45]=E,t[46]=_e,t[47]=be):be=t[47];let xe=e.title??`PDF`,Se;t[48]===xe?Se=t[49]:(Se=(0,J.jsx)(`span`,{className:`ok-pdf-title`,children:xe}),t[48]=xe,t[49]=Se);let Ce;t[50]!==O||t[51]!==w||t[52]!==b||t[53]!==se||t[54]!==P||t[55]!==S?(Ce=P>0&&(0,J.jsxs)(`div`,{className:`ok-pdf-controls`,children:[(0,J.jsx)(`form`,{className:`ok-pdf-page-form`,onSubmit:e=>{e.preventDefault(),se()},children:(0,J.jsx)(`input`,{type:`text`,inputMode:`numeric`,pattern:`[0-9]*`,className:`ok-pdf-page-input`,value:b,onChange:e=>x(e.target.value.replace(/[^0-9]/g,``)),onBlur:se,"aria-label":`Page number`})}),(0,J.jsxs)(`span`,{className:`ok-pdf-page-of`,children:[`of `,P]}),(0,J.jsx)(`span`,{className:`ok-pdf-divider`,"aria-hidden":`true`}),(0,J.jsx)(`button`,{type:`button`,onClick:de,disabled:S<=kw,"aria-label":`Zoom out`,className:`ok-pdf-btn`,title:`Zoom out`,children:(0,J.jsx)(ri,{size:14,"aria-hidden":`true`})}),(0,J.jsxs)(`span`,{className:`ok-pdf-zoom-display`,"aria-live":`polite`,children:[Math.round(S*100),`%`]}),(0,J.jsx)(`button`,{type:`button`,onClick:le,disabled:S>=Aw,"aria-label":`Zoom in`,className:`ok-pdf-btn`,title:`Zoom in`,children:(0,J.jsx)(ni,{size:14,"aria-hidden":`true`})}),(0,J.jsx)(`span`,{className:`ok-pdf-divider`,"aria-hidden":`true`}),(0,J.jsxs)(`div`,{className:`ok-pdf-layout-menu`,children:[(0,J.jsx)(`button`,{type:`button`,onClick:()=>k(Iw),"aria-label":`Layout options`,"aria-haspopup":`menu`,"aria-expanded":O,className:`ok-pdf-btn`,title:`Layout`,children:(0,J.jsx)(mr,{size:14,"aria-hidden":`true`})}),O&&(0,J.jsxs)(`div`,{role:`menu`,className:`ok-pdf-menu`,children:[(0,J.jsx)(Bw,{label:`Fit width`,active:w===`fit-width`,onSelect:()=>pe(`fit-width`)}),(0,J.jsx)(Bw,{label:`Fit height`,active:w===`fit-height`,onSelect:()=>pe(`fit-height`)}),(0,J.jsx)(`hr`,{className:`ok-pdf-menu-divider`}),(0,J.jsx)(Bw,{label:`Single page`,active:w===`single`,onSelect:()=>pe(`single`)}),(0,J.jsx)(Bw,{label:`Two-page (odd)`,active:w===`two-odd`,onSelect:()=>pe(`two-odd`)}),(0,J.jsx)(Bw,{label:`Two-page (even)`,active:w===`two-even`,onSelect:()=>pe(`two-even`)})]})]})]}),t[50]=O,t[51]=w,t[52]=b,t[53]=se,t[54]=P,t[55]=S,t[56]=Ce):Ce=t[56];let we;t[57]!==be||t[58]!==Se||t[59]!==Ce?(we=(0,J.jsxs)(`div`,{className:`ok-pdf-toolbar`,contentEditable:!1,children:[be,Se,Ce]}),t[57]=be,t[58]=Se,t[59]=Ce,t[60]=we):we=t[60];let Te;t[61]!==v||t[62]!==ae||t[63]!==f||t[64]!==E?(Te=E&&(0,J.jsx)(`aside`,{className:`ok-pdf-sidebar`,"aria-label":`Page thumbnails`,children:f.map((e,t)=>(0,J.jsxs)(`button`,{type:`button`,className:`ok-pdf-thumb`,"data-active":v===e.pageNumber||void 0,onClick:()=>ae(e.pageNumber),"aria-label":`Jump to page ${e.pageNumber}`,children:[(0,J.jsx)(`canvas`,{ref:e=>{l.current[t]=e},className:`ok-pdf-thumb-canvas`}),(0,J.jsx)(`span`,{className:`ok-pdf-thumb-num`,children:e.pageNumber})]},e.pageNumber))}),t[61]=v,t[62]=ae,t[63]=f,t[64]=E,t[65]=Te):Te=t[65];let Ee;t[66]===m?Ee=t[67]:(Ee=m&&(0,J.jsx)(`div`,{className:`ok-pdf-loading`,children:`Loading PDF…`}),t[66]=m,t[67]=Ee);let De;t[68]===g?De=t[69]:(De=g&&(0,J.jsxs)(`div`,{className:`ok-pdf-error`,children:[`Failed to load PDF: `,g]}),t[68]=g,t[69]=De);let Oe;t[70]===P?Oe=t[71]:(Oe=Array.from({length:P},(e,t)=>{let n=t+1;return(0,J.jsx)(`canvas`,{ref:e=>{s.current[t]=e},className:`ok-pdf-page`,"aria-label":`Page ${n}`},n)}),t[70]=P,t[71]=Oe);let ke;t[72]!==w||t[73]!==Ee||t[74]!==De||t[75]!==Oe?(ke=(0,J.jsxs)(`div`,{className:`ok-pdf-pages`,ref:a,"data-layout":w,children:[Ee,De,Oe]}),t[72]=w,t[73]=Ee,t[74]=De,t[75]=Oe,t[76]=ke):ke=t[76];let Ae;t[77]!==Te||t[78]!==ke?(Ae=(0,J.jsxs)(`div`,{className:`ok-pdf-body`,children:[Te,ke]}),t[77]=Te,t[78]=ke,t[79]=Ae):Ae=t[79];let je;return t[80]!==he||t[81]!==we||t[82]!==Ae?(je=(0,J.jsxs)(`div`,{className:`ok-pdf`,style:he,children:[we,Ae]}),t[80]=he,t[81]=we,t[82]=Ae,t[83]=je):je=t[83],je}function Iw(e){return!e}function Lw(e){return!e}function Rw(e){return Math.max(kw,+(e-jw).toFixed(2))}function zw(e){return Math.min(Aw,+(e+jw).toFixed(2))}function Bw(e){let t=(0,Y.c)(8),n=e.active||void 0,r=e.active?`✓`:``,i;t[0]===r?i=t[1]:(i=(0,J.jsx)(`span`,{className:`ok-pdf-menu-check`,"aria-hidden":`true`,children:r}),t[0]=r,t[1]=i);let a;return t[2]!==e.active||t[3]!==e.label||t[4]!==e.onSelect||t[5]!==n||t[6]!==i?(a=(0,J.jsxs)(`button`,{type:`button`,role:`menuitemradio`,"aria-checked":e.active,className:`ok-pdf-menu-item`,"data-active":n,onClick:e.onSelect,children:[i,e.label]}),t[2]=e.active,t[3]=e.label,t[4]=e.onSelect,t[5]=n,t[6]=i,t[7]=a):a=t[7],a}function Vw(e){if(!e)return null;for(let t of e.split(`&`)){let e=t.indexOf(`=`);if(!(e<0)&&t.slice(0,e)===`page`){let n=Number.parseInt(t.slice(e+1),10);if(!Number.isNaN(n)&&n>=1)return n}}return null}function Hw(e){return e!==!1}function Uw(e){let t=(0,Y.c)(14),n=e.src,r=e.title,i;t[0]===e.controls?i=t[1]:(i=Hw(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,J.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 Ww(e){let t=(0,Y.c)(2),n;return t[0]===e.children?n=t[1]:(n=(0,J.jsx)(`div`,{className:`prose-no-margin`,children:e.children}),t[0]=e.children,t[1]=n),n}var Gw={Callout:LC,img:hw,video:Uw,audio:jC,Pdf:Fw,Accordion:kC,Math:vw,Mermaid:xw,"*":Ww};function Kw(e){let t=new Set;for(let n of e)n.type===`reactnode`&&t.add(n.name);return t}var qw=gt(),Jw=new Map;function Yw(e){if(e.surface===`compat`){let t=Gw[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:Kw(e.props)}}let t=Gw[e.name];return t?{Component:t,reactNodePropNames:Kw(e.props)}:null}for(let[e,t]of qw.entries()){let n=Yw(t);n&&Jw.set(e,n)}function Xw(e,t){return{...e,Component:t.Component,reactNodePropNames:t.reactNodePropNames}}function Zw(e){let t=qw.getOrWildcard(e),n=Jw.get(t.name)??Jw.get(`*`);if(!n)throw Error(`No React component registered for ${t.name} (and no '*' wildcard)`);return Xw(t,n)}function Qw(){let e=[];for(let[t,n]of qw.entries()){if(t===`*`)continue;let r=Jw.get(t);r&&e.push(Xw(n,r))}return e}var $w=``+new URL(`image-preview-BJSGEOo4.png`,import.meta.url).href,eT=``+new URL(`video-preview-vLovc_Vy.png`,import.meta.url).href,tT={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:$w,alt:`Sample image`}},video:{description:`Embed a video with native player controls.`,props:{controls:!0,poster:eT}},audio:{description:`Embed an audio file with native player controls.`,props:{controls:!0}},Math:{description:`Block math equation rendered with KaTeX from a LaTeX source string.`,props:{formula:`c = \\pm\\sqrt{a^2 + b^2}`}}};function nT(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 rT(e){let t=Zw(e),n=nT(t);return{type:`jsxComponent`,attrs:{componentName:t.name,kind:`element`,attributes:[],sourceRaw:``,sourceDirty:!0,props:n},content:t.hasChildren?[{type:`paragraph`}]:void 0}}var iT=new Set;function aT(e){iT.add(e)}function oT(e){if(typeof e==`number`)return iT.delete(e);let t=iT.values().next();return t.done?!1:(iT.delete(t.value),!0)}function sT(e,t,n){n.props.some(e=>!(`hidden`in e&&e.hidden)&&e.type!==`reactnode`)?(aT(t),requestAnimationFrame(()=>{e.commands.setNodeSelection(t)})):n.hasChildren&&e.commands.setTextSelection(t+2)}function cT(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(rT(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)&&sT(t,r,e)}}function lT(){return Qw().filter(e=>e.surface===`canonical`).map(e=>{let t=tT[e.name],n=e.Component,r=t?{description:t.description,render:()=>(0,J.jsx)(n,{...t.props,children:t.children})}:void 0;return{name:`component-${e.name}`,label:e.displayName??e.name,icon:EC(e.icon),category:e.category??`content`,command:cT(e),aliases:e.searchTerms,description:e.description,preview:r}})}function uT(){return[{name:`component-Tag`,label:`Tag`,icon:Or,category:`content`,aliases:[`#`,`hashtag`,`label`],description:"Inline tag (`#tagname`) for cross-doc linking",command:e=>{e.chain().insertTag(``).run()}}]}var dT=[{name:`heading1`,label:`Heading 1`,icon:kr,category:`basic`,command:e=>e.chain().focus().toggleHeading({level:1}).run(),aliases:[`h1`],preview:{description:`Big section heading.`,render:()=>(0,J.jsx)(`h1`,{className:`text-2xl font-semibold tracking-tight`,children:`Heading 1`})}},{name:`heading2`,label:`Heading 2`,icon:Ar,category:`basic`,command:e=>e.chain().focus().toggleHeading({level:2}).run(),aliases:[`h2`],preview:{description:`Medium section heading.`,render:()=>(0,J.jsx)(`h2`,{className:`text-xl font-semibold tracking-tight`,children:`Heading 2`})}},{name:`heading3`,label:`Heading 3`,icon:jr,category:`basic`,command:e=>e.chain().focus().toggleHeading({level:3}).run(),aliases:[`h3`],preview:{description:`Small section heading.`,render:()=>(0,J.jsx)(`h3`,{className:`text-base font-semibold tracking-tight`,children:`Heading 3`})}},{name:`bulletList`,label:`Bullet List`,icon:Lr,category:`basic`,command:e=>e.chain().focus().toggleBulletList().run(),aliases:[`ul`,`unordered`],preview:{description:`Unordered list of items.`,render:()=>(0,J.jsxs)(`ul`,{className:`list-disc pl-5 text-sm leading-7`,children:[(0,J.jsx)(`li`,{children:`First item`}),(0,J.jsx)(`li`,{children:`Second item`})]})}},{name:`orderedList`,label:`Ordered List`,icon:Fr,category:`basic`,command:e=>e.chain().focus().toggleOrderedList().run(),aliases:[`ol`,`numbered`],preview:{description:`Numbered list of items.`,render:()=>(0,J.jsxs)(`ol`,{className:`list-decimal pl-5 text-sm leading-7`,children:[(0,J.jsx)(`li`,{children:`First item`}),(0,J.jsx)(`li`,{children:`Second item`})]})}},{name:`taskList`,label:`Task List`,icon:Ir,category:`basic`,command:e=>e.chain().focus().toggleTaskList().run(),aliases:[`todo`,`checklist`,`checkbox`],preview:{description:`Checklist with checkboxes.`,render:()=>(0,J.jsxs)(`ul`,{className:`space-y-1.5 text-sm`,children:[(0,J.jsxs)(`li`,{className:`flex items-center gap-2`,children:[(0,J.jsx)(`input`,{type:`checkbox`,checked:!0,readOnly:!0,className:`size-3.5`}),(0,J.jsx)(`span`,{className:`text-muted-foreground line-through`,children:`Done`})]}),(0,J.jsxs)(`li`,{className:`flex items-center gap-2`,children:[(0,J.jsx)(`input`,{type:`checkbox`,readOnly:!0,className:`size-3.5`}),(0,J.jsx)(`span`,{children:`To do`})]})]})}},{name:`blockquote`,label:`Quote`,icon:Wr,category:`basic`,command:e=>e.chain().focus().toggleBlockquote().run(),aliases:[`quote`],preview:{description:`Indented blockquote for citations.`,render:()=>(0,J.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:xr,category:`basic`,command:e=>e.chain().focus().toggleCodeBlock().run(),aliases:[`code`,`fence`],preview:{description:`Fenced code block with monospace text.`,render:()=>(0,J.jsx)(`pre`,{className:`rounded-md bg-muted px-2.5 py-2 font-mono text-xs leading-5`,children:(0,J.jsx)(`code`,{children:`const greeting = "Hello";
7
7
  console.log(greeting);`})})}},{name:`table`,label:`Table`,icon:Yr,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,J.jsxs)(`table`,{className:`w-full border-collapse text-xs`,children:[(0,J.jsx)(`thead`,{children:(0,J.jsxs)(`tr`,{children:[(0,J.jsx)(`th`,{className:`border border-border bg-muted/50 px-2 py-1 text-left font-semibold`,children:`Name`}),(0,J.jsx)(`th`,{className:`border border-border bg-muted/50 px-2 py-1 text-left font-semibold`,children:`Role`})]})}),(0,J.jsxs)(`tbody`,{children:[(0,J.jsxs)(`tr`,{children:[(0,J.jsx)(`td`,{className:`border border-border px-2 py-1`,children:`Ada`}),(0,J.jsx)(`td`,{className:`border border-border px-2 py-1`,children:`Engineer`})]}),(0,J.jsxs)(`tr`,{children:[(0,J.jsx)(`td`,{className:`border border-border px-2 py-1`,children:`Grace`}),(0,J.jsx)(`td`,{className:`border border-border px-2 py-1`,children:`Admiral`})]})]})]})}},{name:`separator`,label:`Separator`,icon:Br,category:`insert`,command:e=>e.chain().focus().setHorizontalRule().run(),aliases:[`hr`,`divider`,`rule`],preview:{description:`Horizontal rule that divides sections.`,render:()=>(0,J.jsxs)(`div`,{className:`w-full`,children:[(0,J.jsx)(`p`,{className:`mb-2 text-xs text-muted-foreground`,children:`Above`}),(0,J.jsx)(`hr`,{className:`border-border`}),(0,J.jsx)(`p`,{className:`mt-2 text-xs text-muted-foreground`,children:`Below`})]})}},{name:`footnote`,label:`Footnote`,icon:Jr,category:`insert`,command:e=>{let t=0;e.state.doc.descendants(e=>{if(e.type.name===`footnoteDefinition`){let n=String(e.attrs.identifier??``),r=Number.parseInt(n,10);!Number.isNaN(r)&&r>t&&(t=r)}return!0});let n=String(t+1),r=e.state.doc.content.size;e.chain().focus().insertFootnoteReference(n).insertContentAt(r+1,{type:`footnoteDefinition`,attrs:{identifier:n,label:n},content:[{type:`paragraph`}]}).run()},aliases:[`fn`,`ref`,`[^`],preview:{description:`Insert a footnote reference + matching definition stub.`,render:()=>(0,J.jsxs)(`p`,{className:`text-sm leading-6`,children:[`A line with a footnote`,(0,J.jsx)(`sup`,{className:`footnote-ref`,children:(0,J.jsx)(`a`,{className:`footnote-ref-link`,href:`#fn-1`,children:`[1]`})}),` `,`and a definition shown below.`]})}},{name:`inlineMath`,label:`Inline Math`,icon:Kr,category:`insert`,command:e=>{let t=e.state.selection.from;e.chain().focus().insertMathInline(``).run(),aT(t),requestAnimationFrame(()=>{e.commands.setNodeSelection(t)})},aliases:[`math`,`latex`,`equation`,`formula`,`katex`,`inlinemath`]}];function fT(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 pT(e){let{$from:t}=e.selection;return t.depth===0?null:{from:t.before(1),to:t.after(1)}}function mT(e,t){let n=pT(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(Ct.near(l.doc.resolve(p))),l.scrollIntoView(),t(l),!0}function hT(e,t){let n=pT(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(Ct.near(l.doc.resolve(p))),l.scrollIntoView(),t(l),!0}var gT=Fe.create({name:`blockMover`,addKeyboardShortcuts(){return{"Mod-Shift-ArrowUp":({editor:e})=>mT(e.state,e.view.dispatch),"Mod-Shift-ArrowDown":({editor:e})=>hT(e.state,e.view.dispatch)}}}),_T=new T(`y-sync`);new T(`y-undo`),new T(`yjs-cursor`);var vT=new T(`bridgeId`);function yT(e){let t=_T.getState(e);return t?.binding?.mapping?t.binding.mapping:null}function bT(e){let t=yT(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 xT(e,t){return e?e.get(t)??null:null}var ST=Fe.create({name:`bridgeIdPlugin`,priority:1e3,addProseMirrorPlugins(){return[new v({key:vT,state:{init(e,t){let n={yElementToId:new WeakMap,posToId:new Map,counter:0},r=bT(t);return t.doc.descendants((e,t)=>{if(e.type.name!==`jsxComponent`)return;let i=xT(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=bT(r);return r.doc.descendants((n,r)=>{if(n.type.name!==`jsxComponent`)return;let c=xT(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}}}})]}}),CT=new T(`chunkWrapperDecoration`),wT=`ok-chunk-wrapper`,TT=!1;function ET(){return globalThis.CSS===void 0||typeof globalThis.CSS.supports!=`function`?!0:globalThis.CSS.supports(`content-visibility`,`auto`)}var DT=ET();function OT(){return DT?new v({key:CT,props:{decorations(e){let t=[];return e.doc.forEach((e,n)=>{e.isInline||t.push(Be.node(n,n+e.nodeSize,{class:wT}))}),t.length===0?null:(TT||(TT=!0,X(`ok/render/cv-auto-skip`,{chunkCount:t.length},{startTime:performance.now(),duration:0})),P.create(e.doc,t))}}}):new v({key:CT})}function kT(e){return!!e.getMeta($g)}function AT(e,t){let n=$g.getState(e);return B_(n.doc,n.type,t,n.binding.mapping)||0}function jT(e,t){let n=$g.getState(e);return R_(t,n.type,n.binding.mapping)}var MT=class e extends ye{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 NT(e,t){return new MT(e,jT(t,e))}function PT(e,t,n){let r=e instanceof MT?e.yRelativePosition:null;if(kT(t)&&r)return{position:new MT(AT(n,r),r),mapResult:null};let i=ie(e,t),a=i.position.position;return{position:new MT(a,r??jT(n,a)),mapResult:i.mapResult}}var FT=Fe.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)=>PT(e,t,this.editor.state),this.editor.utils.createMappablePosition=e=>NT(e,this.editor.state)},addCommands(){return{undo:()=>({tr:e,state:t,dispatch:n})=>(e.setMeta(`preventDispatch`,!0),e_.getState(t).undoManager.undoStack.length===0?!1:n?q_(t):!0),redo:()=>({tr:e,state:t,dispatch:n})=>(e.setMeta(`preventDispatch`,!0),e_.getState(t).undoManager.redoStack.length===0?!1:n?J_(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=Z_(this.options.yUndoOptions),n=t.spec.view;return t.spec.view=e=>{let{undoManager:t}=e_.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()}}},[s_(e,{...this.options.ySyncOptions,onFirstRender:this.options.onFirstRender}),t,this.editor.options.enableContentCheck&&new v({key:new T(`filterInvalidContent`),filterTransaction:t=>{if(!kT(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 IT(e){if(!e.length)return P.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(Be.node(n,n+r.nodeSize,{class:`ProseMirror-selectednoderange`}))}),P.create(n,t)}function LT(e,t,n){let r=n.isText||n.isAtom?0:1;return{start:e+r,end:e+t-r}}function RT(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 oe(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=LT(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 U(a.resolve(l),a.resolve(u));i.push(p)}),i}var zT=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 BT(e.resolve(this.anchor),e.resolve(this.head))}},BT=class e extends M{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=RT(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 zT(this.anchor,this.head)}};BT.prototype.visible=!1;function VT(e){return e instanceof BT}Fe.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(!VT(a)){let e=BT.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(!VT(a)){let e=BT.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=BT.create(i,0,i.content.size,t);return a.setSelection(o),n.dispatch(a),!0}}},onSelectionUpdate(){let{selection:e}=this.editor.state;VT(e)&&this.editor.view.dom.classList.add(`ProseMirror-noderangeselection`)},addProseMirrorPlugins(){let e=!1,t=!1;return[new v({key:new T(`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=BT.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=VT(r);if(e=!1,!t)return i?(e=!0,IT(r.ranges)):null;let{$from:a,$to:o}=r;if(!i&&a.sameParent(o))return null;let s=RT(a,o,this.options.depth);return s.length?(e=!0,IT(s)):null}}})]}});function HT(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 UT(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=HT(e)}),t}var WT=[{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}],GT={edges:[`left`,`top`],threshold:12,strength:500};function KT(e){return e===void 0||e===`left`?{...GT}: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}:{...GT,...e}}function qT(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 JT(e,t,n,r){return!t||n.edges.length===0?0:qT(e,t,n)?n.strength*r:0}var YT=1e3;function XT(e,t,n,r){let i=YT,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-=JT(r,o,n,e.depth),i<=0?-1:i}function ZT(e,t,n){return Array.from({length:t},(e,n)=>t-1-n).some(t=>n.includes(e.node(t).type.name))}function QT(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(...WT),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&&!ZT(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=XT({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=ZT(a,l,n.allowedContainers)),p){let r=XT({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 $T(e,t){let n=e;for(;n?.parentElement&&n.parentElement!==t.dom;)n=n.parentElement;return n?.parentElement===t.dom?n:void 0}function eE(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 tE(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(!eE(s)||!eE(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 nE=e=>{let{x:t,y:n,editor:r,nestedOptions:i}=e,{view:a,state:o}=r,s=tE(a,t,n,5);if(!s)return{resultElement:null,resultNode:null,pos:null};let{x:c,y:l}=s;if(i?.enabled){let e=QT(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=$T(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 rE(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 iE(e){var t;(t=e.parentNode)==null||t.removeChild(e)}function aE(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=nE({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 RT(i.resolve(a.pos),i.resolve(a.pos+a.resultNode.nodeSize+o),0,{extendOnBoundaryOverlap:!1})}function oE(e,t,n,r){let{view:i}=t;if(!e.dataTransfer)return;let{empty:a,$from:o,$to:s}=i.state.selection,c=aE(e,t,n,r),l=RT(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`,rE(i,m));let g=n?.enabled&&r?.node,_,v;g?(_=i.state.doc.slice(m,h),v=z.create(i.state.doc,m)):(v=BT.create(i.state.doc,m,h),_=v.content()),d.forEach(e=>{let t=UT(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,iE(p),document.removeEventListener(`drop`,S),document.removeEventListener(`dragend`,S))},C=v instanceof z?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 sE=(e,t)=>{let n=e.resolve(t),{depth:r}=n;return r===0?t:n.pos-n.parentOffset-1},cE=(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},lE=(e,t)=>{let n=$g.getState(e);return n?R_(t,n.type,n.binding.mapping):null},uE=(e,t)=>{let n=$g.getState(e);return n?B_(n.doc,n.type,t,n.binding.mapping)||0:-1},dE=(e,t)=>{let n=t;for(;n?.parentNode&&n.parentNode!==e.dom;)n=n.parentNode;return n},fE=new T(`dragHandle`),pE=({pluginKey:e=fE,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 y(){if(t){if(!n.isEditable){g();return}t.style.visibility=``,t.style.pointerEvents=`auto`}}function b(e){Xe(i?.()||{getBoundingClientRect:()=>e.getBoundingClientRect()},t,r).then(e=>{Object.assign(t.style,{position:e.strategy,left:`${e.x}px`,top:`${e.y}px`})})}function x(e){o?.(e),oE(e,n,c,{node:d,pos:f}),t&&(t.dataset.dragging=`true`),setTimeout(()=>{t&&(t.style.pointerEvents=`none`)},0)}function S(e){s?.(e),g(),t&&(t.style.pointerEvents=`auto`,t.dataset.dragging=`false`)}function C(){if(_()){let e=n.view.dom;requestAnimationFrame(()=>{e.isContentEditable&&(e.contentEditable=`false`,e.contentEditable=`true`)})}}return l.appendChild(t),{unbind(){t.removeEventListener(`dragstart`,x),t.removeEventListener(`dragend`,S),document.removeEventListener(`drop`,C),m&&(cancelAnimationFrame(m),m=null,h=null)},plugin:new v({key:typeof e==`string`?new T(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(kT(e)){let e=uE(o,p);e!==f&&(f=e)}else{let t=e.mapping.map(f);t!==f&&(f=t,p=lE(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`,x),t.addEventListener(`dragend`,S),document.addEventListener(`drop`,C),{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=dE(e,o),o===e.dom||o?.nodeType!==1)return;let s=e.posAtDOM(o,0),c=cE(n.state.doc,s),l=sE(n.state.doc,s);d=c,f=l,p=lE(e.state,f),a?.({editor:n,node:d,pos:f}),b(o)},destroy(){t.removeEventListener(`dragstart`,x),t.removeEventListener(`dragend`,S),document.removeEventListener(`drop`,C),m&&(cancelAnimationFrame(m),m=null,h=null),t&&iE(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=nE({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=dE(e,o),o===e.dom||o?.nodeType!==1)return;let t=e.posAtDOM(o,0);s=cE(n.state.doc,t),l=sE(n.state.doc,t)}s!==d&&(d=s,f=l??-1,p=lE(e.state,f),a?.({editor:n,node:d,pos:f}),b(o),y())})),!1}}}})}};function mE(e){return e===!1||e===void 0?{enabled:!1,rules:[],defaultRules:!0,allowedContainers:void 0,edgeDetection:KT(`none`)}:e===!0?{enabled:!0,rules:[],defaultRules:!0,allowedContainers:void 0,edgeDetection:KT(`left`)}:{enabled:!0,rules:e.rules??[],defaultRules:e.defaultRules??!0,allowedContainers:e.allowedContainers,edgeDetection:KT(e.edgeDetection)}}var hE={placement:`left-start`,strategy:`absolute`};Fe.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=mE(this.options.nested);return[pE({computePositionConfig:{...hE,...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 gE=e(t(((e,t)=>{(function(e){let n=`(0?\\d+|0x[a-f0-9]+)`,r={fourOctet:RegExp(`^${n}\\.${n}\\.${n}\\.${n}$`,`i`),threeOctet:RegExp(`^${n}\\.${n}\\.${n}$`,`i`),twoOctet:RegExp(`^${n}\\.${n}$`,`i`),longValue:RegExp(`^${n}$`,`i`)},i=RegExp(`^0[0-7]+$`,`i`),a=RegExp(`^0x[a-f0-9]+$`,`i`),o=`%[0-9a-z]{1,}`,s=`(?:[0-9a-f]+::?)+`,c={zoneIndex:new RegExp(o,`i`),native:RegExp(`^(::)?(${s})?([0-9a-f]+)?(::)?(${o})?$`,`i`),deprecatedTransitional:RegExp(`^(?:::)(${n}\\.${n}\\.${n}\\.${n}(${o})?)$`,`i`),transitional:RegExp(`^((?:${s})|(?:::)(?:${s})?)${n}\\.${n}\\.${n}\\.${n}(${o})?$`,`i`)};function l(e,t){if(e.indexOf(`::`)!==e.lastIndexOf(`::`))return null;let n=0,r=-1,i=(e.match(c.zoneIndex)||[])[0],a,o;for(i&&(i=i.substring(1),e=e.replace(/%.+$/,``));(r=e.indexOf(`:`,r+1))>=0;)n++;if(e.substr(0,2)===`::`&&n--,e.substr(-2,2)===`::`&&n--,n>t)return null;for(o=t-n,a=`:`;o--;)a+=`0:`;return e=e.replace(`::`,a),e[0]===`:`&&(e=e.slice(1)),e[e.length-1]===`:`&&(e=e.slice(0,-1)),t=(function(){let t=e.split(`:`),n=[];for(let e=0;e<t.length;e++)n.push(parseInt(t[e],16));return n})(),{parts:t,zoneId:i}}function u(e,t,n,r){if(e.length!==t.length)throw Error(`ipaddr: cannot match CIDR for objects with different lengths`);let i=0,a;for(;r>0;){if(a=n-r,a<0&&(a=0),e[i]>>a!==t[i]>>a)return!1;r-=n,i+=1}return!0}function d(e){if(a.test(e))return parseInt(e,16);if(e[0]===`0`&&!isNaN(parseInt(e[1],10))){if(i.test(e))return parseInt(e,8);throw Error(`ipaddr: cannot parse ${e} as octal`)}return parseInt(e,10)}function f(e,t){for(;e.length<t;)e=`0${e}`;return e}let p={};p.IPv4=(function(){function e(e){if(e.length!==4)throw Error(`ipaddr: ipv4 octet count should be 4`);let t,n;for(t=0;t<e.length;t++)if(n=e[t],!(0<=n&&n<=255))throw Error(`ipaddr: ipv4 octet should fit in 8 bits`);this.octets=e}return e.prototype.SpecialRanges={unspecified:[[new e([0,0,0,0]),8]],broadcast:[[new e([255,255,255,255]),32]],multicast:[[new e([224,0,0,0]),4]],linkLocal:[[new e([169,254,0,0]),16]],loopback:[[new e([127,0,0,0]),8]],carrierGradeNat:[[new e([100,64,0,0]),10]],private:[[new e([10,0,0,0]),8],[new e([172,16,0,0]),12],[new e([192,168,0,0]),16]],reserved:[[new e([192,0,0,0]),24],[new e([192,0,2,0]),24],[new e([192,88,99,0]),24],[new e([198,18,0,0]),15],[new e([198,51,100,0]),24],[new e([203,0,113,0]),24],[new e([240,0,0,0]),4]],as112:[[new e([192,175,48,0]),24],[new e([192,31,196,0]),24]],amt:[[new e([192,52,193,0]),24]]},e.prototype.kind=function(){return`ipv4`},e.prototype.match=function(e,t){let n;if(t===void 0&&(n=e,e=n[0],t=n[1]),e.kind()!==`ipv4`)throw Error(`ipaddr: cannot match ipv4 address with non-ipv4 one`);return u(this.octets,e.octets,8,t)},e.prototype.prefixLengthFromSubnetMask=function(){let e=0,t=!1,n={0:8,128:7,192:6,224:5,240:4,248:3,252:2,254:1,255:0},r,i,a;for(r=3;r>=0;--r)if(i=this.octets[r],i in n){if(a=n[i],t&&a!==0)return null;a!==8&&(t=!0),e+=a}else return null;return 32-e},e.prototype.range=function(){return p.subnetMatch(this,this.SpecialRanges)},e.prototype.toByteArray=function(){return this.octets.slice(0)},e.prototype.toIPv4MappedAddress=function(){return p.IPv6.parse(`::ffff:${this.toString()}`)},e.prototype.toNormalizedString=function(){return this.toString()},e.prototype.toString=function(){return this.octets.join(`.`)},e})(),p.IPv4.broadcastAddressFromCIDR=function(e){try{let t=this.parseCIDR(e),n=t[0].toByteArray(),r=this.subnetMaskFromPrefixLength(t[1]).toByteArray(),i=[],a=0;for(;a<4;)i.push(parseInt(n[a],10)|parseInt(r[a],10)^255),a++;return new this(i)}catch{throw Error(`ipaddr: the address does not have IPv4 CIDR format`)}},p.IPv4.isIPv4=function(e){return this.parser(e)!==null},p.IPv4.isValid=function(e){try{return new this(this.parser(e)),!0}catch{return!1}},p.IPv4.isValidCIDR=function(e){try{return this.parseCIDR(e),!0}catch{return!1}},p.IPv4.isValidFourPartDecimal=function(e){return!!(p.IPv4.isValid(e)&&e.match(/^(0|[1-9]\d*)(\.(0|[1-9]\d*)){3}$/))},p.IPv4.isValidCIDRFourPartDecimal=function(e){let t=e.match(/^(.+)\/(\d+)$/);return!p.IPv4.isValidCIDR(e)||!t?!1:p.IPv4.isValidFourPartDecimal(t[1])},p.IPv4.networkAddressFromCIDR=function(e){let t,n,r,i,a;try{for(t=this.parseCIDR(e),r=t[0].toByteArray(),a=this.subnetMaskFromPrefixLength(t[1]).toByteArray(),i=[],n=0;n<4;)i.push(parseInt(r[n],10)&parseInt(a[n],10)),n++;return new this(i)}catch{throw Error(`ipaddr: the address does not have IPv4 CIDR format`)}},p.IPv4.parse=function(e){let t=this.parser(e);if(t===null)throw Error(`ipaddr: string is not formatted like an IPv4 Address`);return new this(t)},p.IPv4.parseCIDR=function(e){let t;if(t=e.match(/^(.+)\/(\d+)$/)){let e=parseInt(t[2]);if(e>=0&&e<=32){let n=[this.parse(t[1]),e];return Object.defineProperty(n,`toString`,{value:function(){return this.join(`/`)}}),n}}throw Error(`ipaddr: string is not formatted like an IPv4 CIDR range`)},p.IPv4.parser=function(e){let t,n,i;if(t=e.match(r.fourOctet))return(function(){let e=t.slice(1,6),r=[];for(let t=0;t<e.length;t++)n=e[t],r.push(d(n));return r})();if(t=e.match(r.longValue)){if(i=d(t[1]),i>4294967295||i<0)throw Error(`ipaddr: address outside defined range`);return(function(){let e=[],t;for(t=0;t<=24;t+=8)e.push(i>>t&255);return e})().reverse()}else if(t=e.match(r.twoOctet))return(function(){let e=t.slice(1,4),n=[];if(i=d(e[1]),i>16777215||i<0)throw Error(`ipaddr: address outside defined range`);return n.push(d(e[0])),n.push(i>>16&255),n.push(i>>8&255),n.push(i&255),n})();else if(t=e.match(r.threeOctet))return(function(){let e=t.slice(1,5),n=[];if(i=d(e[2]),i>65535||i<0)throw Error(`ipaddr: address outside defined range`);return n.push(d(e[0])),n.push(d(e[1])),n.push(i>>8&255),n.push(i&255),n})();else return null},p.IPv4.subnetMaskFromPrefixLength=function(e){if(e=parseInt(e),e<0||e>32)throw Error(`ipaddr: invalid IPv4 prefix length`);let t=[0,0,0,0],n=0,r=Math.floor(e/8);for(;n<r;)t[n]=255,n++;return r<4&&(t[r]=2**(e%8)-1<<8-e%8),new this(t)},p.IPv6=(function(){function e(e,t){let n,r;if(e.length===16)for(this.parts=[],n=0;n<=14;n+=2)this.parts.push(e[n]<<8|e[n+1]);else if(e.length===8)this.parts=e;else throw Error(`ipaddr: ipv6 part count should be 8 or 16`);for(n=0;n<this.parts.length;n++)if(r=this.parts[n],!(0<=r&&r<=65535))throw Error(`ipaddr: ipv6 part should fit in 16 bits`);t&&(this.zoneId=t)}return e.prototype.SpecialRanges={unspecified:[new e([0,0,0,0,0,0,0,0]),128],linkLocal:[new e([65152,0,0,0,0,0,0,0]),10],multicast:[new e([65280,0,0,0,0,0,0,0]),8],loopback:[new e([0,0,0,0,0,0,0,1]),128],uniqueLocal:[new e([64512,0,0,0,0,0,0,0]),7],ipv4Mapped:[new e([0,0,0,0,0,65535,0,0]),96],deprecatedSiteLocal:[new e([65216,0,0,0,0,0,0,0]),10],discard:[new e([256,0,0,0,0,0,0,0]),64],rfc6145:[new e([0,0,0,0,65535,0,0,0]),96],rfc6052:[[new e([100,65435,0,0,0,0,0,0]),96],[new e([100,65435,1,0,0,0,0,0]),48]],"6to4":[new e([8194,0,0,0,0,0,0,0]),16],teredo:[new e([8193,0,0,0,0,0,0,0]),32],benchmarking:[new e([8193,2,0,0,0,0,0,0]),48],amt:[new e([8193,3,0,0,0,0,0,0]),32],as112v6:[[new e([8193,4,274,0,0,0,0,0]),48],[new e([9760,79,32768,0,0,0,0,0]),48]],deprecatedOrchid:[new e([8193,16,0,0,0,0,0,0]),28],orchid2:[new e([8193,32,0,0,0,0,0,0]),28],droneRemoteIdProtocolEntityTags:[new e([8193,48,0,0,0,0,0,0]),28],segmentRouting:[new e([24320,0,0,0,0,0,0,0]),16],reserved:[[new e([8193,0,0,0,0,0,0,0]),23],[new e([8193,3512,0,0,0,0,0,0]),32],[new e([16383,0,0,0,0,0,0,0]),20]]},e.prototype.isIPv4MappedAddress=function(){return this.range()===`ipv4Mapped`},e.prototype.kind=function(){return`ipv6`},e.prototype.match=function(e,t){let n;if(t===void 0&&(n=e,e=n[0],t=n[1]),e.kind()!==`ipv6`)throw Error(`ipaddr: cannot match ipv6 address with non-ipv6 one`);return u(this.parts,e.parts,16,t)},e.prototype.prefixLengthFromSubnetMask=function(){let e=0,t=!1,n={0:16,32768:15,49152:14,57344:13,61440:12,63488:11,64512:10,65024:9,65280:8,65408:7,65472:6,65504:5,65520:4,65528:3,65532:2,65534:1,65535:0},r,i;for(let a=7;a>=0;--a)if(r=this.parts[a],r in n){if(i=n[r],t&&i!==0)return null;i!==16&&(t=!0),e+=i}else return null;return 128-e},e.prototype.range=function(){return p.subnetMatch(this,this.SpecialRanges)},e.prototype.toByteArray=function(){let e,t=[],n=this.parts;for(let r=0;r<n.length;r++)e=n[r],t.push(e>>8),t.push(e&255);return t},e.prototype.toFixedLengthString=function(){let e=(function(){let e=[];for(let t=0;t<this.parts.length;t++)e.push(f(this.parts[t].toString(16),4));return e}).call(this).join(`:`),t=``;return this.zoneId&&(t=`%${this.zoneId}`),e+t},e.prototype.toIPv4Address=function(){if(!this.isIPv4MappedAddress())throw Error(`ipaddr: trying to convert a generic ipv6 address to ipv4`);let e=this.parts.slice(-2),t=e[0],n=e[1];return new p.IPv4([t>>8,t&255,n>>8,n&255])},e.prototype.toNormalizedString=function(){let e=(function(){let e=[];for(let t=0;t<this.parts.length;t++)e.push(this.parts[t].toString(16));return e}).call(this).join(`:`),t=``;return this.zoneId&&(t=`%${this.zoneId}`),e+t},e.prototype.toRFC5952String=function(){let e=/((^|:)(0(:|$)){2,})/g,t=this.toNormalizedString(),n=0,r=-1,i;for(;i=e.exec(t);)i[0].length>r&&(n=i.index,r=i[0].length);return r<0?t:`${t.substring(0,n)}::${t.substring(n+r)}`},e.prototype.toString=function(){return this.toRFC5952String()},e})(),p.IPv6.broadcastAddressFromCIDR=function(e){try{let t=this.parseCIDR(e),n=t[0].toByteArray(),r=this.subnetMaskFromPrefixLength(t[1]).toByteArray(),i=[],a=0;for(;a<16;)i.push(parseInt(n[a],10)|parseInt(r[a],10)^255),a++;return new this(i)}catch(e){throw Error(`ipaddr: the address does not have IPv6 CIDR format (${e})`)}},p.IPv6.isIPv6=function(e){return this.parser(e)!==null},p.IPv6.isValid=function(e){if(typeof e==`string`&&e.indexOf(`:`)===-1)return!1;try{let t=this.parser(e);return new this(t.parts,t.zoneId),!0}catch{return!1}},p.IPv6.isValidCIDR=function(e){if(typeof e==`string`&&e.indexOf(`:`)===-1)return!1;try{return this.parseCIDR(e),!0}catch{return!1}},p.IPv6.networkAddressFromCIDR=function(e){let t,n,r,i,a;try{for(t=this.parseCIDR(e),r=t[0].toByteArray(),a=this.subnetMaskFromPrefixLength(t[1]).toByteArray(),i=[],n=0;n<16;)i.push(parseInt(r[n],10)&parseInt(a[n],10)),n++;return new this(i)}catch(e){throw Error(`ipaddr: the address does not have IPv6 CIDR format (${e})`)}},p.IPv6.parse=function(e){let t=this.parser(e);if(t.parts===null)throw Error(`ipaddr: string is not formatted like an IPv6 Address`);return new this(t.parts,t.zoneId)},p.IPv6.parseCIDR=function(e){let t,n,r;if((n=e.match(/^(.+)\/(\d+)$/))&&(t=parseInt(n[2]),t>=0&&t<=128))return r=[this.parse(n[1]),t],Object.defineProperty(r,`toString`,{value:function(){return this.join(`/`)}}),r;throw Error(`ipaddr: string is not formatted like an IPv6 CIDR range`)},p.IPv6.parser=function(e){let t,n,r,i,a,o;if(r=e.match(c.deprecatedTransitional))return this.parser(`::ffff:${r[1]}`);if(c.native.test(e))return l(e,8);if((r=e.match(c.transitional))&&(o=r[6]||``,t=r[1],r[1].endsWith(`::`)||(t=t.slice(0,-1)),t=l(t+o,6),t.parts)){for(a=[parseInt(r[2]),parseInt(r[3]),parseInt(r[4]),parseInt(r[5])],n=0;n<a.length;n++)if(i=a[n],!(0<=i&&i<=255))return null;return t.parts.push(a[0]<<8|a[1]),t.parts.push(a[2]<<8|a[3]),{parts:t.parts,zoneId:t.zoneId}}return null},p.IPv6.subnetMaskFromPrefixLength=function(e){if(e=parseInt(e),e<0||e>128)throw Error(`ipaddr: invalid IPv6 prefix length`);let t=[0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0],n=0,r=Math.floor(e/8);for(;n<r;)t[n]=255,n++;return r<16&&(t[r]=2**(e%8)-1<<8-e%8),new this(t)},p.fromByteArray=function(e){let t=e.length;if(t===4)return new p.IPv4(e);if(t===16)return new p.IPv6(e);throw Error(`ipaddr: the binary input is neither an IPv6 nor IPv4 address`)},p.isValid=function(e){return p.IPv6.isValid(e)||p.IPv4.isValid(e)},p.isValidCIDR=function(e){return p.IPv6.isValidCIDR(e)||p.IPv4.isValidCIDR(e)},p.parse=function(e){if(p.IPv6.isValid(e))return p.IPv6.parse(e);if(p.IPv4.isValid(e))return p.IPv4.parse(e);throw Error(`ipaddr: the address has neither IPv6 nor IPv4 format`)},p.parseCIDR=function(e){try{return p.IPv6.parseCIDR(e)}catch{try{return p.IPv4.parseCIDR(e)}catch{throw Error(`ipaddr: the address has neither IPv6 nor IPv4 CIDR format`)}}},p.process=function(e){let t=this.parse(e);return t.kind()===`ipv6`&&t.isIPv4MappedAddress()?t.toIPv4Address():t},p.subnetMatch=function(e,t,n){let r,i,a,o;for(i in n??=`unicast`,t)if(Object.prototype.hasOwnProperty.call(t,i)){for(a=t[i],a[0]&&!(a[0]instanceof Array)&&(a=[a]),r=0;r<a.length;r++)if(o=a[r],e.kind()===o[0].kind()&&e.match.apply(e,o))return i}return n},t!==void 0&&t.exports?t.exports=p:e.ipaddr=p})(e)}))(),1),_E=new Set([`href`,`src`,`srcset`,`poster`,`formaction`,`xlink:href`]),vE=new Set([`aria-label`,`aria-description`,`title`]),yE=/(?:[a-zA-Z][a-zA-Z0-9+.-]*:\/\/[^\s"'<>]+|(?:javascript|vbscript|data|file|chrome-extension|moz-extension):[^\s"'<>]*)/gi,bE=/url\s*\(\s*['"]?\s*(?:javascript|vbscript|data)\s*:/i,xE=/\bexpression\s*\(/i,SE=/(oklch|oklab|lab|lch)\(\s*([^)]+)\s*\)/gi,CE=`data-clipboard-omit`;function wE(e){let t=e.trim();return t===``||me.test(t)?!0:b(t)}function TE(e){let t=e.split(`,`);for(let e of t){let t=e.trim();if(t!==``&&!wE(t.split(/\s+/)[0]??``))return!1}return!0}function EE(e,t){let n=!1,r=e.replace(yE,e=>wE(e)?e:(n=!0,`[blocked]`));return t?.reportNoChange&&!n?null:r}function DE(e){let t=e.toLowerCase();return t.length>=3&&t.startsWith(`on`)}function OE(e){return e.length>1e4||bE.test(e)||xE.test(e)?``:e}function kE(e){let t=e.indexOf(`/`),n=(t===-1?e:e.slice(0,t)).trim(),r=t===-1?null:e.slice(t+1).trim(),i=n.split(/[\s,]+/).filter(e=>e.length>0);if(i.length!==3)return null;let a=AE(i[0],1),o=AE(i[1],1),s=AE(i[2],1);if(Number.isNaN(a)||Number.isNaN(o)||Number.isNaN(s))return null;let c=null;if(r!==null){if(c=AE(r,1),Number.isNaN(c))return null;c=Math.max(0,Math.min(1,c))}return[a,o,s,c]}function AE(e,t){return e===`none`?0:e.endsWith(`%`)?Number.parseFloat(e.slice(0,-1))/100*t:Number.parseFloat(e)}function jE(e,t,n){let r=n*Math.PI/180;return[e,t*Math.cos(r),t*Math.sin(r)]}function ME(e,t,n){let r=e+.3963377774*t+.2158037573*n,i=e-.1055613458*t-.0638541728*n,a=e-.0894841775*t-1.291485548*n,o=r**3,s=i**3,c=a**3;return[4.0767416621*o-3.3077115913*s+.2309699292*c,-1.2684380046*o+2.6097574011*s-.3413193965*c,-.0041960863*o-.7034186147*s+1.707614701*c]}function NE(e){return e<=.0031308?12.92*e:1.055*e**(1/2.4)-.055}function PE(e){return Number.isFinite(e)?Math.max(0,Math.min(255,Math.round(e*255))):0}function FE(e,t,n,r){let i=e.toLowerCase(),a,o,s;i===`oklch`?[a,o,s]=jE(t,n,r):i===`oklab`?[a,o,s]=[t,n,r]:i===`lch`?[a,o,s]=jE(t/100,n/100,r):[a,o,s]=[t/100,n/100,r/100];let[c,l,u]=ME(a,o,s);return[PE(NE(c)),PE(NE(l)),PE(NE(u))]}function IE(e){if(e.length>1e4)return e;let t=e.toLowerCase();return!t.includes(`oklch`)&&!t.includes(`oklab`)&&!t.includes(`lab`)&&!t.includes(`lch`)?e:e.replace(SE,(e,t,n)=>{let r=kE(n);if(r===null)return e;let[i,a,o,s]=r,[c,l,u]=FE(t,i,a,o);return s===null?`rgb(${c}, ${l}, ${u})`:`rgba(${c}, ${l}, ${u}, ${s})`})}var LE=new Set([`mailto`,`tel`,`sms`,`ftp`,`ftps`]);function RE(e){let t=e.trim();if(t.startsWith(`#`))return{portable:!0};if(b(t))return t.startsWith(`/`)?{portable:!1,reason:`server-absolute`}:{portable:!1,reason:`relative`};let n=new URL(t),r=n.protocol.slice(0,-1).toLowerCase();if(LE.has(r))return{portable:!0};if(r!==`http`&&r!==`https`)return{portable:!1,reason:`other`};let i=n.hostname.toLowerCase();if(i===``)return{portable:!1,reason:`other`};let a=i.endsWith(`.`)?i.slice(0,-1):i;if(a===`localhost`||a.endsWith(`.localhost`))return{portable:!1,reason:`localhost`};let o=i.startsWith(`[`)&&i.endsWith(`]`)?i.slice(1,-1):i;return gE.IPv4.isValid(o)?gE.IPv4.parse(o).range()===`unicast`?{portable:!0}:{portable:!1,reason:`private-ip`}:gE.IPv6.isValid(o)?gE.IPv6.parse(o).range()===`unicast`?{portable:!0}:{portable:!1,reason:`private-ip`}:{portable:!0}}function zE(e){if(!e)return`plaintext`;if(e.types.includes(`vscode-editor-data`))return`vscode`;if(e.types.includes(`text/x-gfm`))return`gfm`;let t=e.getData(`text/html`);return t?/data-pm-slice/i.test(t)?`pm-origin`:/docs-internal-guid-/i.test(t)?`gdocs`:/xmlns:o="urn:schemas-microsoft-com:office/i.test(t)||/<meta[^>]*Generator[^>]*Microsoft Word/i.test(t)?`word`:/class="gmail_|class='gmail_/i.test(t)?`gmail`:/notionvc:/i.test(t)?`notion`:/Cocoa HTML Writer/i.test(t)?`apple`:/c-message_kit__|c-message__|c-compose/i.test(t)?`slack`:/google-sheets-html-origin/i.test(t)?`gsheets`:/data-hovercard-type=/i.test(t)?`github`:`generic`:`plaintext`}var BE=250,VE=100;function HE(e,t){let n=performance.now()-e;n<(t.op===`paste`||t.op===`drop`?BE:VE)||console.warn(JSON.stringify({event:`clipboard-slow-op`,op:t.op,view:t.view,elapsedMs:Math.round(n),branch:t.branch,source:t.source,...t.htmlBytes==null?{}:{htmlBytes:t.htmlBytes}}))}function UE(e){console.warn(JSON.stringify({event:`clipboard-source-detected`,view:e.view,source:e.source,branch:e.branch}))}function WE(e){console.warn(JSON.stringify({event:`clipboard-html-conversion-failed`,view:e.view,stage:e.stage,source:e.source,...e.branch==null?{}:{branch:e.branch},reason:e.reason,...e.errorClass==null?{}:{errorClass:e.errorClass},...e.htmlBytes==null?{}:{htmlBytes:e.htmlBytes}}))}function GE(e){console.warn(JSON.stringify({event:`clipboard-serialize-failed`,view:e.view,kind:e.kind,reason:e.reason}))}function KE(e){console.warn(JSON.stringify({event:`clipboard-walker-fallback-fired`,descriptor:e.descriptor,view:e.view}))}function qE(e){console.warn(JSON.stringify({event:`clipboard-walker-non-portable-render-source-emitted`,descriptor:e.descriptor,view:e.view}))}function JE(e){console.warn(JSON.stringify({event:`clipboard-walker-url-blocked`,view:e.view,attr:e.attr,reason:e.reason}))}function YE(e){console.warn(JSON.stringify({event:`clipboard-walker-url-source-emitted`,view:e.view,tag:e.tag,class:e.class,reason:e.reason}))}function XE(e){console.warn(JSON.stringify({event:`clipboard-walker-url-classifier-failed`,view:e.view,tag:e.tag,phase:e.phase,...e.errorClass==null?{}:{errorClass:e.errorClass}}))}var ZE=new Set;function QE(e){ZE.has(e.lucideClass)||(ZE.add(e.lucideClass),console.warn(JSON.stringify({event:`clipboard-walker-unmapped-lucide-detected`,view:e.view,lucideClass:e.lucideClass})))}function $E(e){console.warn(JSON.stringify({event:`clipboard-chunked-insert-failed`,view:e.view,chunksCompleted:e.chunksCompleted,totalChunks:e.totalChunks,bytesWritten:e.bytesWritten,bytesRemaining:e.bytesRemaining,reason:e.reason}))}function eD(e){if(e instanceof St)return`HtmlPayloadTooLargeError`;if(e instanceof F)return`ChunkedInsertError`;if(e instanceof Error&&e.name&&e.name!==`Error`)return e.name}var tD=/^```/m,nD=/^#{1,6} /m,rD=/^[-*+] /m,iD=/^\d+[.)] /m,aD=/\[[^\]\n]+\]\([^)\n]+\)/,oD=/^\|.*\|$/m,sD=/^\|?\s*(:?-+:?)(\s*\|\s*:?-+:?)+\s*\|?$/m,cD=/\$\$[\s\S]+?\$\$/,lD=/^> /m,uD=/`[^`\n]+`/,dD=/\*\*[^*\n]+\*\*/,fD=/__[^_\n]+__/,pD=/~~[^~\n]+~~/,mD=/<[A-Z]\w*[\s/>]/,hD=/<[a-z]+\s+\w+="[^"]*"/,gD=/<[a-z]+>[^<\n]*<\/[a-z]+>/,_D=/^.+\n[=-]+$/m,vD=/(^|\s)\*[^*\s\n][^*\n]*[^*\s\n]\*(\s|$)/m,yD=/(^|\s)_[^_\s\n][^_\n]*[^_\s\n]_(\s|$)/m,bD=/^~~~/m,xD=/\\[\\`*_{}[\]<>()#+\-.!|]/,SD=256*1024,CD=32*1024;function wD(e){return e.length<=SD?e:`${e.slice(0,CD)}\n${e.slice(-CD)}`}function TD(e){if(!e)return!1;let t=wD(e),n=0;tD.test(t)&&n++,nD.test(t)&&n++,rD.test(t)&&n++,iD.test(t)&&n++,aD.test(t)&&n++,oD.test(t)&&sD.test(t)&&n++,cD.test(t)&&n++,lD.test(t)&&n++,uD.test(t)&&n++,(dD.test(t)||fD.test(t)||pD.test(t))&&n++,mD.test(t)&&n++,hD.test(t)&&n++,gD.test(t)&&n++,_D.test(t)&&n++,vD.test(t)&&n++,yD.test(t)&&n++,bD.test(t)&&n++,xD.test(t)&&n++;let r=t.split(`
8
8
  `).length,i=Math.min(3,Math.floor(r/5));return n>=Math.max(1,i)}var ED=3e3,DD=new Map;function OD(e,t=`Pasted as plain text — some formatting could not be converted.`){let n=Date.now();return n-(DD.get(e)??0)<ED?!1:(DD.set(e,n),Wt.error(t),!0)}var kD=!1,AD=!1;function jD(e){kD=e.shiftKey}function MD(e){(e.key===`Shift`||!e.shiftKey)&&(kD=!1)}function ND(){kD=!1}function PD(){AD||typeof window>`u`||(window.addEventListener(`keydown`,jD,!0),window.addEventListener(`keyup`,MD,!0),window.addEventListener(`blur`,ND,!0),AD=!0)}function FD(){PD()}function ID(){return PD(),kD}function LD(e){return ID()?!0:e.shiftKey===!0}function RD(e){return(t,n)=>BD(t,n,`paste`,e)}function zD(e){return(t,n)=>n.dataTransfer?.files&&n.dataTransfer.files.length>0?!1:BD(t,n,`drop`,e)}function BD(e,t,n,r){let i=n===`paste`?t.clipboardData:t.dataTransfer;if(!i||i.types.length===0)return!1;let a=performance.now(),o=zE(i),s=i.getData(`text/plain`),c=i.getData(`text/html`);if(VD(t,n))return s&&UD(e,s),UE({view:`wysiwyg`,branch:`shift`,source:o}),HE(a,{op:n,view:`wysiwyg`,branch:`shift`,source:o}),!0;if(HD(e))return s&&UD(e,s),UE({view:`wysiwyg`,branch:`codeblock`,source:o}),HE(a,{op:n,view:`wysiwyg`,branch:`codeblock`,source:o}),!0;let l=i.getData(`vscode-editor-data`);if(l&&s&&GD(e,l,s,o))return UE({view:`wysiwyg`,branch:`A`,source:o}),HE(a,{op:n,view:`wysiwyg`,branch:`A`,source:o}),!0;let u=i.getData(`text/x-gfm`);return u&&KD(e,u,r,`B`,o)||s&&c&&TD(s)&&KD(e,s,r,`B`,o)?(UE({view:`wysiwyg`,branch:`B`,source:o}),HE(a,{op:n,view:`wysiwyg`,branch:`B`,source:o}),!0):c&&/data-pm-slice/i.test(c)?(UE({view:`wysiwyg`,branch:`C`,source:o}),HE(a,{op:n,view:`wysiwyg`,branch:`C`,source:o}),!1):c&&qD(e,c,r,o)?(UE({view:`wysiwyg`,branch:`D`,source:o}),HE(a,{op:n,view:`wysiwyg`,branch:`D`,source:o,htmlBytes:c.length}),!0):s?TD(s)&&KD(e,s,r,`E`,`markdown-text`)?(UE({view:`wysiwyg`,branch:`E`,source:`markdown-text`}),HE(a,{op:n,view:`wysiwyg`,branch:`E`,source:`markdown-text`}),!0):(UD(e,s),UE({view:`wysiwyg`,branch:`E`,source:`plaintext`}),HE(a,{op:n,view:`wysiwyg`,branch:`E`,source:`plaintext`}),!0):!1}function VD(e,t){return t===`paste`?LD(e):e.shiftKey===!0}function HD(e){let{$from:t}=e.state.selection;for(let e=t.depth;e>=0;e--)if(t.node(e).type.name===`codeBlock`)return!0;return!1}function UD(e,t){let{schema:n,tr:r}=e.state;t&&e.dispatch(r.replaceSelectionWith(n.text(t)).scrollIntoView())}var WD=/^[A-Za-z0-9_+-]+$/;function GD(e,t,n,r){try{let r=JSON.parse(t),i=typeof r.mode==`string`?r.mode:``,a=WD.test(i)?i:``,o=e.state.schema.nodes.codeBlock;if(!o)return!1;let s=o.create({language:a},n?e.state.schema.text(n):null);return e.dispatch(e.state.tr.replaceSelectionWith(s).scrollIntoView()),!0}catch(e){return WE({view:`wysiwyg`,stage:`branchA`,source:r,branch:`A`,reason:e?.message??`unknown`,errorClass:eD(e)}),!1}}function KD(e,t,n,r,i){let a;try{a=n.mdManager.parse(t)}catch(e){return WE({view:`wysiwyg`,stage:`mdManagerParse`,source:i,branch:r,reason:e?.message??`unknown`,errorClass:eD(e)}),!1}return JD(e,a,i,r)}function qD(e,t,n,r){let i;try{i=Ve(t)}catch(e){return WE({view:`wysiwyg`,stage:`htmlToMdast`,source:r,branch:`D`,reason:e?.message??`unknown`,errorClass:eD(e),htmlBytes:t.length}),OD(`wysiwyg`),!1}let a;try{a=at(i)}catch(e){return WE({view:`wysiwyg`,stage:`mdastToMarkdown`,source:r,branch:`D`,reason:e?.message??`unknown`,errorClass:eD(e),htmlBytes:t.length}),OD(`wysiwyg`),!1}let o;try{o=n.mdManager.parse(a)}catch(e){return WE({view:`wysiwyg`,stage:`mdManagerParse`,source:r,branch:`D`,reason:e?.message??`unknown`,errorClass:eD(e),htmlBytes:t.length}),OD(`wysiwyg`),!1}return JD(e,o,r,`D`,t.length)}function JD(e,t,n,r,i){try{let n=e.state.schema.nodeFromJSON(t);return e.dispatch(e.state.tr.replaceSelection(n.slice(0,n.content.size)).scrollIntoView()),!0}catch(e){return WE({view:`wysiwyg`,stage:`applyJsonSlice`,source:n,branch:r,reason:e?.message??`unknown`,errorClass:eD(e),...i==null?{}:{htmlBytes:i}}),!1}}function YD(e){if(e.type.name!==`jsxComponent`)return null;let t=e.attrs.componentName,n=e.attrs.props??{};switch(t){case`Math`:return{source:`$$\n${typeof n.formula==`string`?n.formula:``}\n$$`};case`Mermaid`:return{source:`\`\`\`mermaid\n${typeof n.chart==`string`?n.chart:``}\n\`\`\``};default:return null}}function XD(e,t){let n=YD(e);if(!n)return null;let r=t.createElement(`pre`);r.className=`mdx-component`;let i=t.createElement(`code`);return i.textContent=n.source,r.appendChild(i),r}var ZD={note:{color:`#0969da`,bg:`#dbeafe`},tip:{color:`#1f883d`,bg:`#dcfce7`},important:{color:`#8250df`,bg:`#f3e8ff`},warning:{color:`#9a6700`,bg:`#fef3c7`},caution:{color:`#cf222e`,bg:`#fee2e2`}};function QD(e){return Object.hasOwn(ZD,e)?ZD[e]:ZD.note}function $D(e){let t=typeof e.type==`string`?e.type:`note`,n=QD(t),r=document.createElement(`aside`);if(r.setAttribute(`class`,`callout callout-${t}`),r.setAttribute(`data-callout-type`,t),r.setAttribute(`style`,`border-left: 3px solid ${n.color}; background-color: ${n.bg}; padding: 0.5rem 0.75rem; border-radius: 0.25rem;`),typeof e.title==`string`&&e.title){let t=document.createElement(`strong`);t.textContent=e.title,r.appendChild(t)}return r}function eO(e){let t=document.createElement(`details`);e.defaultOpen===!0&&t.setAttribute(`open`,``),t.setAttribute(`class`,`accordion`);let n=document.createElement(`summary`);return n.textContent=typeof e.title==`string`?e.title:`Accordion`,t.appendChild(n),t}function tO(e){let t=RE(e);return t.portable?null:t.reason}function nO(e){let t=document.createElement(`pre`);t.className=`mdx-component`;let n=document.createElement(`code`);return n.textContent=e,t.appendChild(n),t}function rO(e,t,n){if(e===``)return null;let r;try{r=tO(e)}catch(e){let n=eD(e);return XE({view:`wysiwyg`,tag:t,phase:`classifier-throw`,...n===void 0?{}:{errorClass:n}}),null}return r===null?null:(YE({view:`wysiwyg`,tag:t,class:`mdx-component`,reason:r}),nO(n))}function iO(e){let t=typeof e.alt==`string`?e.alt:``,n=typeof e.src==`string`?e.src:``,r=rO(n,`img`,`![${t}](${n})`);if(r!==null)return r;let i=document.createElement(`img`);return n&&wE(n)&&i.setAttribute(`src`,n),typeof e.alt==`string`&&i.setAttribute(`alt`,e.alt),i}function aO(e,t){let n=document.createElement(e);return n.setAttribute(`src`,t),n.outerHTML}function oO(e){let t=typeof e.src==`string`?e.src:``,n=rO(t,`video`,aO(`video`,t));if(n!==null)return n;let r=document.createElement(`video`);return t&&wE(t)&&r.setAttribute(`src`,t),e.controls!==!1&&r.setAttribute(`controls`,``),r}function sO(e){let t=typeof e.src==`string`?e.src:``,n=rO(t,`audio`,aO(`audio`,t));if(n!==null)return n;let r=document.createElement(`audio`);return t&&wE(t)&&r.setAttribute(`src`,t),e.controls!==!1&&r.setAttribute(`controls`,``),r}function cO(e){if(e.type.name!==`jsxComponent`)return null;let t=e.attrs.componentName,n=e.attrs.props??{};switch(t){case`Callout`:case`GFMCallout`:return $D(n);case`Accordion`:case`HtmlDetailsAccordion`:return eO(n);case`img`:case`CommonMarkImage`:return iO(n);case`video`:return oO(n);case`audio`:return sO(n);case`Math`:case`Mermaid`:return XD(e,document);default:return null}}var lO=`color.background-color.background-image.border.border-top.border-right.border-bottom.border-left.border-color.border-width.border-style.border-radius.padding.padding-top.padding-right.padding-bottom.padding-left.margin.margin-top.margin-right.margin-bottom.margin-left.font-family.font-size.font-weight.font-style.text-decoration.text-align.line-height.list-style.list-style-type.list-style-position.vertical-align.white-space`.split(`.`),uO=new Set([`jsx-component-wrapper`,`selectedCell`,`is-empty`,`ProseMirror-selectednode`,`ProseMirror-trailingBreak`]),dO=new Set([`data-selected`,`data-has-child-selected`,`data-dragging`,`contenteditable`,`data-pm-slice`]),fO={getComputedStyle:e=>window.getComputedStyle(e)};function pO(e,t=lO){let n=``;for(let r of t){let t=e.getPropertyValue(r);t&&(t===`initial`||t===`normal`||(n+=`${r}: ${IE(t)}; `))}return n.trim()}function mO(e,t=uO){return e.split(/\s+/).filter(e=>e.length>0&&!t.has(e)).join(` `)||null}function hO(e,t,n){let r=!1;return e.nodesBetween(t,n,(i,a,o)=>(o===e&&(t>a||n<a+i.nodeSize)&&(r=!0),!1)),r}function gO(e,t,n=fO){let r=document.createDocumentFragment(),{from:i,to:a}=t.state.selection;return i===a||hO(t.state.doc,i,a)||t.state.doc.nodesBetween(i,a,(e,i,a)=>{if(a!==t.state.doc)return!1;let o=t.nodeDOM(i);if(o==null){KE({descriptor:e.type.name,view:`wysiwyg`});let t=cO(e);return t&&r.appendChild(t),!1}if(!(o instanceof Element)||o.getAttribute(`data-clipboard-omit`)===`true`)return!1;let s=XD(e,document);return s===null?(r.appendChild(_O(o,n)),!1):(r.appendChild(s),qE({view:`wysiwyg`,descriptor:e.attrs.componentName??e.type.name}),!1)}),r}function _O(e,t){let n=e.cloneNode(!0);return CO(e,n,t),wO(n),vO(n),IO(e,n,t),SO(n),n}function vO(e){let t=Array.from(e.querySelectorAll(`[data-component-type="math-inline"]`));for(let n of t){if(!n.parentNode)continue;let t=n.getAttribute(`data-formula`)??``,r=e.ownerDocument.createElement(`span`);r.className=`mdx-inline`,r.textContent=`$$${t}$$`,n.replaceWith(r),qE({view:`wysiwyg`,descriptor:`mathInline`})}let n=Array.from(e.querySelectorAll(`a[data-wiki-embed]`));for(let t of n){if(!t.parentNode)continue;let n=t.getAttribute(`data-target`)??``;if(!n)continue;let r=t.getAttribute(`data-alias`)||null,i=t.getAttribute(`data-anchor`)||null,a=e.ownerDocument.createElement(`span`);a.className=`mdx-inline`,a.textContent=yO(n,i,r),t.replaceWith(a),qE({view:`wysiwyg`,descriptor:`wikiLinkEmbed`})}}function yO(e,t,n){let r=e;return t&&(r+=`#${t}`),n&&(r+=`|${n}`),`![[${r}]]`}var bO={"lucide-chevron-right":`›`,"lucide-chevron-down":`⌄`,"lucide-info":`ℹ`,"lucide-lightbulb":`💡`,"lucide-message-square-warning":`❗`,"lucide-alert-triangle":`⚠`,"lucide-alert-octagon":`⛔`},xO=/(?:^|\s)(lucide-[a-z0-9-]+)(?:\s|$)/;function SO(e){let t=e.querySelectorAll(`svg`);for(let e of Array.from(t)){let t=(e.getAttribute(`class`)??``).match(xO);if(!t)continue;let n=t[1],r=bO[n];if(!r){QE({lucideClass:n,view:`wysiwyg`});continue}let i=e.ownerDocument.createElement(`span`);i.setAttribute(`aria-hidden`,`true`),i.textContent=r,e.replaceWith(i)}}function CO(e,t,n){let r=pO(n.getComputedStyle(e));if(r){let e=t.getAttribute(`style`);t.setAttribute(`style`,e?`${e}; ${r}`:r)}let i=t.getAttribute(`class`);if(i!==null){let e=mO(i);e?t.setAttribute(`class`,e):t.removeAttribute(`class`)}for(let e of Array.from(t.attributes)){if(dO.has(e.name)){t.removeAttribute(e.name);continue}if(DE(e.name)){t.removeAttribute(e.name),JE({attr:`on*`,reason:`event-handler`,view:`wysiwyg`});continue}if(e.name===`style`){let n=OE(e.value);n===``?(t.removeAttribute(`style`),JE({attr:`style`,reason:`unsafe-url-or-expression`,view:`wysiwyg`})):n!==e.value&&t.setAttribute(`style`,n);continue}if(_E.has(e.name)){(e.name===`srcset`?TE(e.value):wE(e.value))||(t.removeAttribute(e.name),JE({attr:e.name,reason:e.name===`srcset`?`srcset-candidate`:`scheme`,view:`wysiwyg`}));continue}if(vE.has(e.name)){let n=EE(e.value,{reportNoChange:!0});n!==null&&(t.setAttribute(e.name,n),JE({attr:e.name,reason:`embedded-url`,view:`wysiwyg`}))}}let a=Array.from(e.children),o=Array.from(t.children),s=Math.min(a.length,o.length);for(let e=0;e<s;e++){let t=a[e],r=o[e];if(t.getAttribute(`data-clipboard-omit`)===`true`){r.remove();continue}CO(t,r,n)}}function wO(e){let t=e.querySelectorAll(`span[data-wiki-link]`);for(let e of Array.from(t)){let t=e.getAttribute(`data-target`)??``;if(!t)continue;let n=pe(e.getAttribute(`data-anchor`)),r=pe(e.getAttribute(`data-alias`)),i=xe(t,n),a=e.ownerDocument.createElement(`a`);a.setAttribute(`class`,`wiki-link`),a.setAttribute(`href`,i),a.setAttribute(`data-target`,t),a.setAttribute(`data-anchor`,n??``),a.setAttribute(`data-alias`,r??``),a.textContent=e.textContent??``,e.replaceWith(a)}}var TO=new Set([`img`,`video`,`audio`,`source`,`a`]);function EO(e){return TO.has(e)}function DO(e){return e.closest(`p`)===null?`mdx-component`:`mdx-inline`}function OO(e,t,n){if(t===`mdx-component`){let t=e.createElement(`pre`);t.className=`mdx-component`;let r=e.createElement(`code`);return r.textContent=n,t.appendChild(r),t}let r=e.createElement(`span`);return r.className=`mdx-inline`,r.textContent=n,r}function kO(e){let t=RE(e);return t.portable?null:t.reason}function AO(e){for(let t of e.split(`,`)){let e=t.trim();if(e===``)continue;let n=kO(e.split(/\s+/)[0]??``);if(n!==null)return n}return null}function jO(e,t){switch(t){case`img`:case`source`:{let t=e.getAttribute(`src`);if(t!==null){let e=kO(t);if(e!==null)return e}let n=e.getAttribute(`srcset`);if(n!==null){let e=AO(n);if(e!==null)return e}return null}case`video`:case`audio`:{let t=e.getAttribute(`src`);return t===null?null:kO(t)}case`a`:{let t=e.getAttribute(`href`);return t===null?null:kO(t)}default:return null}}function MO(e){let t=e.querySelectorAll(`source, img`);for(let e of Array.from(t)){let t=e.tagName.toLowerCase();if(!EO(t))continue;let n=jO(e,t);if(n!==null)return n}return null}function NO(e,t,n,r){let i;try{i=jO(n,r)}catch(e){let t=eD(e);return XE({view:`wysiwyg`,tag:r,phase:`classifier-throw`,...t===void 0?{}:{errorClass:t}}),!1}return i===null?!1:FO(e,t,n,r,i)}function PO(e,t,n){let r;try{r=MO(n)}catch(e){let t=eD(e);return XE({view:`wysiwyg`,tag:`picture`,phase:`classifier-throw`,...t===void 0?{}:{errorClass:t}}),!1}return r===null?!1:FO(e,t,n,`picture`,r)}function FO(e,t,n,r,i){let a=e.serializeElementMarkdown?e.serializeElementMarkdown(t):{kind:`no-correspondence`};switch(a.kind){case`no-correspondence`:return XE({view:`wysiwyg`,tag:r,phase:`serializer-null`}),!1;case`failed`:{let e=a.errorClass;return XE({view:`wysiwyg`,tag:r,phase:`serializer-throw`,...e===void 0?{}:{errorClass:e}}),!1}case`ok`:{let e=DO(n),t=OO(n.ownerDocument,e,a.markdown);return n.replaceWith(t),YE({view:`wysiwyg`,tag:r,class:e,reason:i}),!0}default:return!1}}function IO(e,t,n){if(!n.serializeElementMarkdown)return;let r=t.tagName.toLowerCase();if(r===`picture`&&PO(n,e,t)||EO(r)&&NO(n,e,t,r))return;let i=Array.from(e.children),a=Array.from(t.children),o=[];for(let e of i)e.getAttribute(`data-clipboard-omit`)!==`true`&&o.push(e);let s=Math.min(o.length,a.length);for(let e=0;e<s;e++)IO(o[e],a[e],n)}function LO(e){return(t,n)=>{try{return BO(t,n.state.schema,e.mdManager)}catch(e){return GE({view:`wysiwyg`,kind:`text`,reason:e?.message??`unknown`}),t.content.textBetween(0,t.content.size,`
9
9
 
@@ -34,4 +34,4 @@ console.log(greeting);`})})}},{name:`table`,label:`Table`,icon:Yr,category:`inse
34
34
  \${}
35
35
  }`,{label:`interface`,detail:`definition`,type:`keyword`}),nr("type ${name} = ${type}",{label:`type`,detail:`definition`,type:`keyword`}),nr(`enum \${name} {
36
36
  \${}
37
- }`,{label:`enum`,detail:`definition`,type:`keyword`})]),KI=new Dn,qI=new Set([`Script`,`Block`,`FunctionExpression`,`FunctionDeclaration`,`ArrowFunction`,`MethodDeclaration`,`ForStatement`]);function JI(e){return(t,n)=>{let r=t.node.getChild(`VariableDefinition`);return r&&n(r,e),!0}}var YI=[`FunctionDeclaration`],XI={FunctionDeclaration:JI(`function`),ClassDeclaration:JI(`class`),ClassExpression:()=>!0,EnumDeclaration:JI(`constant`),TypeAliasDeclaration:JI(`type`),NamespaceDeclaration:JI(`namespace`),VariableDefinition(e,t){e.matchContext(YI)||t(e,`variable`)},TypeDefinition(e,t){t(e,`type`)},__proto__:null};function ZI(e,t){let n=KI.get(t);if(n)return n;let r=[],i=!0;function a(t,n){let i=e.sliceString(t.from,t.to);r.push({label:i,type:n})}return t.cursor(er.IncludeAnonymous).iterate(t=>{if(i)i=!1;else if(t.name){let e=XI[t.name];if(e&&e(t,a)||qI.has(t.name))return!1}else if(t.to-t.from>8192){for(let n of ZI(e,t.node))r.push(n);return!1}}),KI.set(t,r),r}var QI=/^[\w$\xa1-\uffff][\w$\d\xa1-\uffff]*$/,$I=[`TemplateString`,`String`,`RegExp`,`LineComment`,`BlockComment`,`VariableDefinition`,`TypeDefinition`,`Label`,`PropertyDefinition`,`PropertyName`,`PrivatePropertyDefinition`,`PrivatePropertyName`,`JSXText`,`JSXAttributeValue`,`JSXOpenTag`,`JSXCloseTag`,`JSXSelfClosingTag`,`.`,`?.`];function eL(e){let t=Sn(e.state).resolveInner(e.pos,-1);if($I.indexOf(t.name)>-1)return null;let n=t.name==`VariableName`||t.to-t.from<20&&QI.test(e.state.sliceDoc(t.from,t.to));if(!n&&!e.explicit)return null;let r=[];for(let n=t;n;n=n.parent)qI.has(n.name)&&(r=r.concat(ZI(e.state.doc,n)));return{options:r,from:n?t.from:e.pos,validFor:QI}}var tL=qn.define({name:`javascript`,parser:UI.configure({props:[Zn.add({IfStatement:Xn({except:/^\s*({|else\b)/}),TryStatement:Xn({except:/^\s*({|catch\b|finally\b)/}),LabeledStatement:In,SwitchBody:e=>{let t=e.textAfter,n=/^\s*\}/.test(t),r=/^\s*(case|default)\b/.test(t);return e.baseIndent+(n?0:r?1:2)*e.unit},Block:Gn({closing:`}`}),ArrowFunction:e=>e.baseIndent+e.unit,"TemplateString BlockComment":()=>null,"Statement Property":Xn({except:/^\s*{/}),JSXElement(e){let t=/^\s*<\//.test(e.textAfter);return e.lineIndent(e.node.from)+(t?0:e.unit)},JSXEscape(e){let t=/\s*\}/.test(e.textAfter);return e.lineIndent(e.node.from)+(t?0:e.unit)},"JSXOpenTag JSXSelfClosingTag"(e){return e.column(e.node.from)+e.unit}}),$n.add({"Block ClassBody SwitchBody EnumBody ObjectExpression ArrayExpression ObjectType":Mn,BlockComment(e){return{from:e.from+2,to:e.to-2}},JSXElement(e){let t=e.firstChild;if(!t||t.name==`JSXSelfClosingTag`)return null;let n=e.lastChild;return{from:t.to,to:n.type.isError?e.to:n.from}},"JSXSelfClosingTag JSXOpenTag"(e){let t=e.firstChild?.nextSibling,n=e.lastChild;return!t||t.type.isError?null:{from:t.to,to:n.type.isError?e.to:n.from}}})]}),languageData:{closeBrackets:{brackets:[`(`,`[`,`{`,`'`,`"`,"`"]},commentTokens:{line:`//`,block:{open:`/*`,close:`*/`}},indentOnInput:/^\s*(?:case |default:|\{|\}|<\/)$/,wordChars:`$`}}),nL={test:e=>/^JSX/.test(e.name),facet:Fn({commentTokens:{block:{open:`{/*`,close:`*/}`}}})},rL=tL.configure({dialect:`ts`},`typescript`),iL=tL.configure({dialect:`jsx`,props:[Rn.add(e=>e.isTop?[nL]:void 0)]}),aL=tL.configure({dialect:`jsx ts`,props:[Rn.add(e=>e.isTop?[nL]:void 0)]},`typescript`),oL=e=>({label:e,type:`keyword`}),sL=`break case const continue default delete export extends false finally in instanceof let new return static super switch this throw true typeof var yield`.split(` `).map(oL),cL=sL.concat([`declare`,`implements`,`private`,`protected`,`public`].map(oL));function lL(e={}){let t=e.jsx?e.typescript?aL:iL:e.typescript?rL:tL,n=e.typescript?GI.concat(cL):WI.concat(sL);return new Wn(t,[tL.data.of({autocomplete:rr($I,tr(n))}),tL.data.of({autocomplete:eL}),e.jsx?pL:[]])}function uL(e){for(;;){if(e.name==`JSXOpenTag`||e.name==`JSXSelfClosingTag`||e.name==`JSXFragmentTag`)return e;if(e.name==`JSXEscape`||!e.parent)return null;e=e.parent}}function dL(e,t,n=e.length){for(let r=t?.firstChild;r;r=r.nextSibling)if(r.name==`JSXIdentifier`||r.name==`JSXBuiltin`||r.name==`JSXNamespacedName`||r.name==`JSXMemberExpression`)return e.sliceString(r.from,Math.min(r.to,n));return``}var fL=typeof navigator==`object`&&/Android\b/.test(navigator.userAgent),pL=An.inputHandler.of((e,t,n,r,i)=>{if((fL?e.composing:e.compositionStarted)||e.state.readOnly||t!=n||r!=`>`&&r!=`/`||!tL.isActiveAt(e.state,t,-1))return!1;let a=i(),{state:o}=a,s=o.changeByRange(e=>{let{head:t}=e,n=Sn(o).resolveInner(t-1,-1),i;if(n.name==`JSXStartTag`&&(n=n.parent),!(o.doc.sliceString(t-1,t)!=r||n.name==`JSXAttributeValue`&&n.to>t)){if(r==`>`&&n.name==`JSXFragmentTag`)return{range:e,changes:{from:t,insert:`</>`}};if(r==`/`&&n.name==`JSXStartCloseTag`){let e=n.parent,r=e.parent;if(r&&e.from==t-2&&((i=dL(o.doc,r.firstChild,t))||r.firstChild?.name==`JSXFragmentTag`)){let e=`${i}>`;return{range:En.cursor(t+e.length,-1),changes:{from:t,insert:e}}}}else if(r==`>`){let r=uL(n);if(r&&r.name==`JSXOpenTag`&&!/^\/?>|^<\//.test(o.doc.sliceString(t,t+2))&&(i=dL(o.doc,r,t)))return{range:e,changes:{from:t,insert:`</${i}>`}}}}return{range:e}});return s.changes.empty?!1:(e.dispatch([a,o.update(s,{userEvent:`input.complete`,scrollIntoView:!0})]),!0)}),mL=[`_blank`,`_self`,`_top`,`_parent`],hL=[`ascii`,`utf-8`,`utf-16`,`latin1`,`latin1`],gL=[`get`,`post`,`put`,`delete`],_L=[`application/x-www-form-urlencoded`,`multipart/form-data`,`text/plain`],vL=[`true`,`false`],$={},yL={a:{attrs:{href:null,ping:null,type:null,media:null,target:mL,hreflang:null}},abbr:$,address:$,area:{attrs:{alt:null,coords:null,href:null,target:null,ping:null,media:null,hreflang:null,type:null,shape:[`default`,`rect`,`circle`,`poly`]}},article:$,aside:$,audio:{attrs:{src:null,mediagroup:null,crossorigin:[`anonymous`,`use-credentials`],preload:[`none`,`metadata`,`auto`],autoplay:[`autoplay`],loop:[`loop`],controls:[`controls`]}},b:$,base:{attrs:{href:null,target:mL}},bdi:$,bdo:$,blockquote:{attrs:{cite:null}},body:$,br:$,button:{attrs:{form:null,formaction:null,name:null,value:null,autofocus:[`autofocus`],disabled:[`autofocus`],formenctype:_L,formmethod:gL,formnovalidate:[`novalidate`],formtarget:mL,type:[`submit`,`reset`,`button`]}},canvas:{attrs:{width:null,height:null}},caption:$,center:$,cite:$,code:$,col:{attrs:{span:null}},colgroup:{attrs:{span:null}},command:{attrs:{type:[`command`,`checkbox`,`radio`],label:null,icon:null,radiogroup:null,command:null,title:null,disabled:[`disabled`],checked:[`checked`]}},data:{attrs:{value:null}},datagrid:{attrs:{disabled:[`disabled`],multiple:[`multiple`]}},datalist:{attrs:{data:null}},dd:$,del:{attrs:{cite:null,datetime:null}},details:{attrs:{open:[`open`]}},dfn:$,div:$,dl:$,dt:$,em:$,embed:{attrs:{src:null,type:null,width:null,height:null}},eventsource:{attrs:{src:null}},fieldset:{attrs:{disabled:[`disabled`],form:null,name:null}},figcaption:$,figure:$,footer:$,form:{attrs:{action:null,name:null,"accept-charset":hL,autocomplete:[`on`,`off`],enctype:_L,method:gL,novalidate:[`novalidate`],target:mL}},h1:$,h2:$,h3:$,h4:$,h5:$,h6:$,head:{children:[`title`,`base`,`link`,`style`,`meta`,`script`,`noscript`,`command`]},header:$,hgroup:$,hr:$,html:{attrs:{manifest:null}},i:$,iframe:{attrs:{src:null,srcdoc:null,name:null,width:null,height:null,sandbox:[`allow-top-navigation`,`allow-same-origin`,`allow-forms`,`allow-scripts`],seamless:[`seamless`]}},img:{attrs:{alt:null,src:null,ismap:null,usemap:null,width:null,height:null,crossorigin:[`anonymous`,`use-credentials`]}},input:{attrs:{alt:null,dirname:null,form:null,formaction:null,height:null,list:null,max:null,maxlength:null,min:null,name:null,pattern:null,placeholder:null,size:null,src:null,step:null,value:null,width:null,accept:[`audio/*`,`video/*`,`image/*`],autocomplete:[`on`,`off`],autofocus:[`autofocus`],checked:[`checked`],disabled:[`disabled`],formenctype:_L,formmethod:gL,formnovalidate:[`novalidate`],formtarget:mL,multiple:[`multiple`],readonly:[`readonly`],required:[`required`],type:[`hidden`,`text`,`search`,`tel`,`url`,`email`,`password`,`datetime`,`date`,`month`,`week`,`time`,`datetime-local`,`number`,`range`,`color`,`checkbox`,`radio`,`file`,`submit`,`image`,`reset`,`button`]}},ins:{attrs:{cite:null,datetime:null}},kbd:$,keygen:{attrs:{challenge:null,form:null,name:null,autofocus:[`autofocus`],disabled:[`disabled`],keytype:[`RSA`]}},label:{attrs:{for:null,form:null}},legend:$,li:{attrs:{value:null}},link:{attrs:{href:null,type:null,hreflang:null,media:null,sizes:[`all`,`16x16`,`16x16 32x32`,`16x16 32x32 64x64`]}},map:{attrs:{name:null}},mark:$,menu:{attrs:{label:null,type:[`list`,`context`,`toolbar`]}},meta:{attrs:{content:null,charset:hL,name:[`viewport`,`application-name`,`author`,`description`,`generator`,`keywords`],"http-equiv":[`content-language`,`content-type`,`default-style`,`refresh`]}},meter:{attrs:{value:null,min:null,low:null,high:null,max:null,optimum:null}},nav:$,noscript:$,object:{attrs:{data:null,type:null,name:null,usemap:null,form:null,width:null,height:null,typemustmatch:[`typemustmatch`]}},ol:{attrs:{reversed:[`reversed`],start:null,type:[`1`,`a`,`A`,`i`,`I`]},children:[`li`,`script`,`template`,`ul`,`ol`]},optgroup:{attrs:{disabled:[`disabled`],label:null}},option:{attrs:{disabled:[`disabled`],label:null,selected:[`selected`],value:null}},output:{attrs:{for:null,form:null,name:null}},p:$,param:{attrs:{name:null,value:null}},pre:$,progress:{attrs:{value:null,max:null}},q:{attrs:{cite:null}},rp:$,rt:$,ruby:$,samp:$,script:{attrs:{type:[`text/javascript`],src:null,async:[`async`],defer:[`defer`],charset:hL}},section:$,select:{attrs:{form:null,name:null,size:null,autofocus:[`autofocus`],disabled:[`disabled`],multiple:[`multiple`]}},slot:{attrs:{name:null}},small:$,source:{attrs:{src:null,type:null,media:null}},span:$,strong:$,style:{attrs:{type:[`text/css`],media:null,scoped:null}},sub:$,summary:$,sup:$,table:$,tbody:$,td:{attrs:{colspan:null,rowspan:null,headers:null}},template:$,textarea:{attrs:{dirname:null,form:null,maxlength:null,name:null,placeholder:null,rows:null,cols:null,autofocus:[`autofocus`],disabled:[`disabled`],readonly:[`readonly`],required:[`required`],wrap:[`soft`,`hard`]}},tfoot:$,th:{attrs:{colspan:null,rowspan:null,headers:null,scope:[`row`,`col`,`rowgroup`,`colgroup`]}},thead:$,time:{attrs:{datetime:null}},title:$,tr:$,track:{attrs:{src:null,label:null,default:null,kind:[`subtitles`,`captions`,`descriptions`,`chapters`,`metadata`],srclang:null}},ul:{children:[`li`,`script`,`template`,`ul`,`ol`]},var:$,video:{attrs:{src:null,poster:null,width:null,height:null,crossorigin:[`anonymous`,`use-credentials`],preload:[`auto`,`metadata`,`none`],autoplay:[`autoplay`],mediagroup:[`movie`],muted:[`muted`],controls:[`controls`]}},wbr:$},bL={accesskey:null,class:null,contenteditable:vL,contextmenu:null,dir:[`ltr`,`rtl`,`auto`],draggable:[`true`,`false`,`auto`],dropzone:[`copy`,`move`,`link`,`string:`,`file:`],hidden:[`hidden`],id:null,inert:[`inert`],itemid:null,itemprop:null,itemref:null,itemscope:[`itemscope`],itemtype:null,lang:[`ar`,`bn`,`de`,`en-GB`,`en-US`,`es`,`fr`,`hi`,`id`,`ja`,`pa`,`pt`,`ru`,`tr`,`zh`],spellcheck:vL,autocorrect:vL,autocapitalize:vL,style:null,tabindex:null,title:null,translate:[`yes`,`no`],rel:[`stylesheet`,`alternate`,`author`,`bookmark`,`help`,`license`,`next`,`nofollow`,`noreferrer`,`prefetch`,`prev`,`search`,`tag`],role:`alert application article banner button cell checkbox complementary contentinfo dialog document feed figure form grid gridcell heading img list listbox listitem main navigation region row rowgroup search switch tab table tabpanel textbox timer`.split(` `),"aria-activedescendant":null,"aria-atomic":vL,"aria-autocomplete":[`inline`,`list`,`both`,`none`],"aria-busy":vL,"aria-checked":[`true`,`false`,`mixed`,`undefined`],"aria-controls":null,"aria-describedby":null,"aria-disabled":vL,"aria-dropeffect":null,"aria-expanded":[`true`,`false`,`undefined`],"aria-flowto":null,"aria-grabbed":[`true`,`false`,`undefined`],"aria-haspopup":vL,"aria-hidden":vL,"aria-invalid":[`true`,`false`,`grammar`,`spelling`],"aria-label":null,"aria-labelledby":null,"aria-level":null,"aria-live":[`off`,`polite`,`assertive`],"aria-multiline":vL,"aria-multiselectable":vL,"aria-owns":null,"aria-posinset":null,"aria-pressed":[`true`,`false`,`mixed`,`undefined`],"aria-readonly":vL,"aria-relevant":null,"aria-required":vL,"aria-selected":[`true`,`false`,`undefined`],"aria-setsize":null,"aria-sort":[`ascending`,`descending`,`none`,`other`],"aria-valuemax":null,"aria-valuemin":null,"aria-valuenow":null,"aria-valuetext":null},xL=`beforeunload copy cut dragstart dragover dragleave dragenter dragend drag paste focus blur change click load mousedown mouseenter mouseleave mouseup keydown keyup resize scroll unload`.split(` `).map(e=>`on`+e);for(let e of xL)bL[e]=null;var SL=class{constructor(e,t){this.tags={...yL,...e},this.globalAttrs={...bL,...t},this.allTags=Object.keys(this.tags),this.globalAttrNames=Object.keys(this.globalAttrs)}};SL.default=new SL;function CL(e,t,n=e.length){if(!t)return``;let r=t.firstChild,i=r&&r.getChild(`TagName`);return i?e.sliceString(i.from,Math.min(i.to,n)):``}function wL(e,t=!1){for(;e;e=e.parent)if(e.name==`Element`)if(t)t=!1;else return e;return null}function TL(e,t,n){return n.tags[CL(e,wL(t))]?.children||n.allTags}function EL(e,t){let n=[];for(let r=wL(t);r&&!r.type.isTop;r=wL(r.parent)){let i=CL(e,r);if(i&&r.lastChild.name==`CloseTag`)break;i&&n.indexOf(i)<0&&(t.name==`EndTag`||t.from>=r.firstChild.to)&&n.push(i)}return n}var DL=/^[:\-\.\w\u00b7-\uffff]*$/;function OL(e,t,n,r,i){let a=/\s*>/.test(e.sliceDoc(i,i+5))?``:`>`,o=wL(n,n.name==`StartTag`||n.name==`TagName`);return{from:r,to:i,options:TL(e.doc,o,t).map(e=>({label:e,type:`type`})).concat(EL(e.doc,n).map((e,t)=>({label:`/`+e,apply:`/`+e+a,type:`type`,boost:99-t}))),validFor:/^\/?[:\-\.\w\u00b7-\uffff]*$/}}function kL(e,t,n,r){let i=/\s*>/.test(e.sliceDoc(r,r+5))?``:`>`;return{from:n,to:r,options:EL(e.doc,t).map((e,t)=>({label:e,apply:e+i,type:`type`,boost:99-t})),validFor:DL}}function AL(e,t,n,r){let i=[],a=0;for(let r of TL(e.doc,n,t))i.push({label:`<`+r,type:`type`});for(let t of EL(e.doc,n))i.push({label:`</`+t+`>`,type:`type`,boost:99-a++});return{from:r,to:r,options:i,validFor:/^<\/?[:\-\.\w\u00b7-\uffff]*$/}}function jL(e,t,n,r,i){let a=wL(n),o=a?t.tags[CL(e.doc,a)]:null,s=o&&o.attrs?Object.keys(o.attrs):[];return{from:r,to:i,options:(o&&o.globalAttrs===!1?s:s.length?s.concat(t.globalAttrNames):t.globalAttrNames).map(e=>({label:e,type:`property`})),validFor:DL}}function ML(e,t,n,r,i){let a=n.parent?.getChild(`AttributeName`),o=[],s;if(a){let c=e.sliceDoc(a.from,a.to),l=t.globalAttrs[c];if(!l){let r=wL(n),i=r?t.tags[CL(e.doc,r)]:null;l=i?.attrs&&i.attrs[c]}if(l){let t=e.sliceDoc(r,i).toLowerCase(),n=`"`,a=`"`;/^['"]/.test(t)?(s=t[0]==`"`?/^[^"]*$/:/^[^']*$/,n=``,a=e.sliceDoc(i,i+1)==t[0]?``:t[0],t=t.slice(1),r++):s=/^[^\s<>='"]*$/;for(let e of l)o.push({label:e,apply:n+e+a,type:`constant`})}}return{from:r,to:i,options:o,validFor:s}}function NL(e,t){let{state:n,pos:r}=t,i=Sn(n).resolveInner(r,-1),a=i.resolve(r);for(let e=r,t;a==i&&(t=i.childBefore(e));){let n=t.lastChild;if(!n||!n.type.isError||n.from<n.to)break;a=i=t,e=n.from}return i.name==`TagName`?i.parent&&/CloseTag$/.test(i.parent.name)?kL(n,i,i.from,r):OL(n,e,i,i.from,r):i.name==`StartTag`||i.name==`IncompleteTag`?OL(n,e,i,r,r):i.name==`StartCloseTag`||i.name==`IncompleteCloseTag`?kL(n,i,r,r):i.name==`OpenTag`||i.name==`SelfClosingTag`||i.name==`AttributeName`?jL(n,e,i,i.name==`AttributeName`?i.from:r,r):i.name==`Is`||i.name==`AttributeValue`||i.name==`UnquotedAttributeValue`?ML(n,e,i,i.name==`Is`?r:i.from,r):t.explicit&&(a.name==`Element`||a.name==`Text`||a.name==`Document`)?AL(n,e,i,r):null}function PL(e){return NL(SL.default,e)}function FL(e){let{extraTags:t,extraGlobalAttributes:n}=e,r=n||t?new SL(t,n):SL.default;return e=>NL(r,e)}var IL=tL.parser.configure({top:`SingleExpression`}),LL=[{tag:`script`,attrs:e=>e.type==`text/typescript`||e.lang==`ts`,parser:rL.parser},{tag:`script`,attrs:e=>e.type==`text/babel`||e.type==`text/jsx`,parser:iL.parser},{tag:`script`,attrs:e=>e.type==`text/typescript-jsx`,parser:aL.parser},{tag:`script`,attrs(e){return/^(importmap|speculationrules|application\/(.+\+)?json)$/i.test(e.type)},parser:IL},{tag:`script`,attrs(e){return!e.type||/^(?:text|application)\/(?:x-)?(?:java|ecma)script$|^module$|^$/i.test(e.type)},parser:tL.parser},{tag:`style`,attrs(e){return(!e.lang||e.lang==`css`)&&(!e.type||/^(text\/)?(x-)?(stylesheet|css)$/i.test(e.type))},parser:oI.parser}],RL=[{name:`style`,parser:oI.parser.configure({top:`Styles`})}].concat(xL.map(e=>({name:e,parser:tL.parser}))),zL=qn.define({name:`html`,parser:aF.configure({props:[Zn.add({Element(e){let t=/^(\s*)(<\/)?/.exec(e.textAfter);return e.node.to<=e.pos+t[0].length?e.continue():e.lineIndent(e.node.from)+(t[2]?0:e.unit)},"OpenTag CloseTag SelfClosingTag"(e){return e.column(e.node.from)+e.unit},Document(e){if(e.pos+/\s*/.exec(e.textAfter)[0].length<e.node.to)return e.continue();let t=null,n;for(let n=e.node;;){let e=n.lastChild;if(!e||e.name!=`Element`||e.to!=n.to)break;t=n=e}return t&&!((n=t.lastChild)&&(n.name==`CloseTag`||n.name==`SelfClosingTag`))?e.lineIndent(t.from)+e.unit:null}}),$n.add({Element(e){let t=e.firstChild,n=e.lastChild;return!t||t.name!=`OpenTag`?null:{from:t.to,to:n.name==`CloseTag`?n.from:e.to}}}),Hn.add({"OpenTag CloseTag":e=>e.getChild(`TagName`)})]}),languageData:{commentTokens:{block:{open:`<!--`,close:`-->`}},indentOnInput:/^\s*<\/\w+\W$/,wordChars:`-_`}}),BL=zL.configure({wrap:lF(LL,RL)});function VL(e={}){let t=``,n;return e.matchClosingTags===!1&&(t=`noMatch`),e.selfClosingTags===!0&&(t=(t?t+` `:``)+`selfClosing`),(e.nestedLanguages&&e.nestedLanguages.length||e.nestedAttributes&&e.nestedAttributes.length)&&(n=lF((e.nestedLanguages||[]).concat(LL),(e.nestedAttributes||[]).concat(RL))),new Wn(n?zL.configure({wrap:n,dialect:t}):t?BL.configure({dialect:t}):BL,[BL.data.of({autocomplete:FL(e)}),e.autoCloseTags===!1?[]:UL,lL().support,sI().support])}var HL=new Set(`area base br col command embed frame hr img input keygen link meta param source track wbr menuitem`.split(` `)),UL=An.inputHandler.of((e,t,n,r,i)=>{if(e.composing||e.state.readOnly||t!=n||r!=`>`&&r!=`/`||!BL.isActiveAt(e.state,t,-1))return!1;let a=i(),{state:o}=a,s=o.changeByRange(e=>{let t=o.doc.sliceString(e.from-1,e.to)==r,{head:n}=e,i=Sn(o).resolveInner(n,-1),a;if(t&&r==`>`&&i.name==`EndTag`){let t=i.parent;if(t.parent?.lastChild?.name!=`CloseTag`&&(a=CL(o.doc,t.parent,n))&&!HL.has(a))return{range:e,changes:{from:n,to:n+ +(o.doc.sliceString(n,n+1)===`>`),insert:`</${a}>`}}}else if(t&&r==`/`&&i.name==`IncompleteCloseTag`){let e=i.parent;if(i.from==n-2&&e.lastChild?.name!=`CloseTag`&&(a=CL(o.doc,e,n))&&!HL.has(a)){let e=n+ +(o.doc.sliceString(n,n+1)===`>`),t=`${a}>`;return{range:En.cursor(n+t.length,-1),changes:{from:n,to:e,insert:t}}}}return{range:e}});return s.changes.empty?!1:(e.dispatch([a,o.update(s,{userEvent:`input.complete`,scrollIntoView:!0})]),!0)}),WL=Fn({commentTokens:{block:{open:`<!--`,close:`-->`}}}),GL=new pn,KL=kN.configure({props:[$n.add(e=>!e.is(`Block`)||e.is(`Document`)||qL(e)!=null||JL(e)?void 0:(e,t)=>({from:t.doc.lineAt(e.from).to,to:e.to})),GL.add(qL),Zn.add({Document:()=>null}),Bn.add({Document:WL})]});function qL(e){let t=/^(?:ATX|Setext)Heading(\d)$/.exec(e.name);return t?+t[1]:void 0}function JL(e){return e.name==`OrderedList`||e.name==`BulletList`}function YL(e,t){let n=e;for(;;){let e=n.nextSibling,r;if(!e||(r=qL(e.type))!=null&&r<=t)break;n=e}return n.to}var XL=Pn.of((e,t,n)=>{for(let r=Sn(e).resolveInner(n,-1);r&&!(r.from<t);r=r.parent){let e=r.type.prop(GL);if(e==null)continue;let t=YL(r,e);if(t>n)return{from:n,to:t}}return null});function ZL(e){return new Ln(WL,e,[],`markdown`)}var QL=ZL(KL),$L=ZL(KL.configure([YN,QN,ZN,$N,{props:[$n.add({Table:(e,t)=>({from:t.doc.lineAt(e.from).to,to:e.to})})]}]));function eR(e,t){return n=>{if(n&&e){let t=null;if(n=/\S*/.exec(n)[0],t=typeof e==`function`?e(n):Nn.matchLanguageName(e,n,!0),t instanceof Nn)return t.support?t.support.language.parser:Jn.getSkippingParser(t.load());if(t)return t.parser}return t?t.parser:null}}var tR=class{constructor(e,t,n,r,i,a,o){this.node=e,this.from=t,this.to=n,this.spaceBefore=r,this.spaceAfter=i,this.type=a,this.item=o}blank(e,t=!0){let n=this.spaceBefore+(this.node.name==`Blockquote`?`>`:``);if(e!=null){for(;n.length<e;)n+=` `;return n}else{for(let e=this.to-this.from-n.length-this.spaceAfter.length;e>0;e--)n+=` `;return n+(t?this.spaceAfter:``)}}marker(e,t){let n=this.node.name==`OrderedList`?String(+rR(this.item,e)[2]+t):``;return this.spaceBefore+n+this.type+this.spaceAfter}};function nR(e,t){let n=[],r=[];for(let t=e;t;t=t.parent){if(t.name==`FencedCode`)return r;(t.name==`ListItem`||t.name==`Blockquote`)&&n.push(t)}for(let e=n.length-1;e>=0;e--){let i=n[e],a,o=t.lineAt(i.from),s=i.from-o.from;if(i.name==`Blockquote`&&(a=/^ *>( ?)/.exec(o.text.slice(s))))r.push(new tR(i,s,s+a[0].length,``,a[1],`>`,null));else if(i.name==`ListItem`&&i.parent.name==`OrderedList`&&(a=/^( *)\d+([.)])( *)/.exec(o.text.slice(s)))){let e=a[3],t=a[0].length;e.length>=4&&(e=e.slice(0,e.length-4),t-=4),r.push(new tR(i.parent,s,s+t,a[1],e,a[2],i))}else if(i.name==`ListItem`&&i.parent.name==`BulletList`&&(a=/^( *)([-+*])( {1,4}\[[ xX]\])?( +)/.exec(o.text.slice(s)))){let e=a[4],t=a[0].length;e.length>4&&(e=e.slice(0,e.length-4),t-=4);let n=a[2];a[3]&&(n+=a[3].replace(/[xX]/,` `)),r.push(new tR(i.parent,s,s+t,a[1],e,n,i))}}return r}function rR(e,t){return/^(\s*)(\d+)(?=[.)])/.exec(t.sliceString(e.from,e.from+10))}function iR(e,t,n,r=0){for(let i=-1,a=e;;){if(a.name==`ListItem`){let e=rR(a,t),o=+e[2];if(i>=0){if(o!=i+1)return;n.push({from:a.from+e[1].length,to:a.from+e[0].length,insert:String(i+2+r)})}i=o}let e=a.nextSibling;if(!e)break;a=e}}function aR(e,t){let n=/^[ \t]*/.exec(e)[0].length;if(!n||t.facet(hn)!=` `)return e;let r=mn(e,4,n),i=``;for(let e=r;e>0;)e>=4?(i+=` `,e-=4):(i+=` `,e--);return i+e.slice(n)}var oR=((e={})=>({state:t,dispatch:n})=>{let r=Sn(t),{doc:i}=t,a=null,o=t.changeByRange(n=>{if(!n.empty||!$L.isActiveAt(t,n.from,-1)&&!$L.isActiveAt(t,n.from,1))return a={range:n};let o=n.from,s=i.lineAt(o),c=nR(r.resolveInner(o,-1),i);for(;c.length&&c[c.length-1].from>o-s.from;)c.pop();if(!c.length)return a={range:n};let l=c[c.length-1];if(l.to-l.spaceAfter.length>o-s.from)return a={range:n};let u=o>=l.to-l.spaceAfter.length&&!/\S/.test(s.text.slice(l.to));if(l.item&&u){let n=l.node.firstChild,r=l.node.getChild(`ListItem`,`ListItem`);if(n.to>=o||r&&r.to<o||s.from>0&&!/[^\s>]/.test(i.lineAt(s.from-1).text)||e.nonTightLists===!1){let e=c.length>1?c[c.length-2]:null,t,n=``;e&&e.item?(t=s.from+e.from,n=e.marker(i,1)):t=s.from+(e?e.to:0);let r=[{from:t,to:o,insert:n}];return l.node.name==`OrderedList`&&iR(l.item,i,r,-2),e&&e.node.name==`OrderedList`&&iR(e.item,i,r),{range:En.cursor(t+n.length),changes:r}}else{let e=lR(c,t,s);return{range:En.cursor(o+e.length+1),changes:{from:s.from,insert:e+t.lineBreak}}}}if(l.node.name==`Blockquote`&&u&&s.from){let e=i.lineAt(s.from-1),r=/>\s*$/.exec(e.text);if(r&&r.index==l.from){let i=t.changes([{from:e.from+r.index,to:e.to},{from:s.from+l.from,to:s.to}]);return{range:n.map(i),changes:i}}}let d=[];l.node.name==`OrderedList`&&iR(l.item,i,d);let f=l.item&&l.item.from<s.from,p=``;if(!f||/^[\s\d.)\-+*>]*/.exec(s.text)[0].length>=l.to)for(let e=0,t=c.length-1;e<=t;e++)p+=e==t&&!f?c[e].marker(i,1):c[e].blank(e<t?mn(s.text,4,c[e+1].from)-p.length:null);let m=o;for(;m>s.from&&/\s/.test(s.text.charAt(m-s.from-1));)m--;return p=aR(p,t),cR(l.node,t.doc)&&(p=lR(c,t,s)+t.lineBreak+p),d.push({from:m,to:o,insert:t.lineBreak+p}),{range:En.cursor(m+p.length+1),changes:d}});return a?!1:(n(t.update(o,{scrollIntoView:!0,userEvent:`input`})),!0)})();function sR(e){return e.name==`QuoteMark`||e.name==`ListMark`}function cR(e,t){if(e.name!=`OrderedList`&&e.name!=`BulletList`)return!1;let n=e.firstChild,r=e.getChild(`ListItem`,`ListItem`);if(!r)return!1;let i=t.lineAt(n.to),a=t.lineAt(r.from),o=/^[\s>]*$/.test(i.text);return i.number+ +!o<a.number}function lR(e,t,n){let r=``;for(let t=0,i=e.length-2;t<=i;t++)r+=e[t].blank(t<i?mn(n.text,4,e[t+1].from)-r.length:null,t<i);return aR(r,t)}function uR(e,t){let n=e.resolveInner(t,-1),r=t;sR(n)&&(r=n.from,n=n.parent);for(let e;e=n.childBefore(r);)if(sR(e))r=e.from;else if(e.name==`OrderedList`||e.name==`BulletList`)n=e.lastChild,r=n.to;else break;return n}var dR=[{key:`Enter`,run:oR},{key:`Backspace`,run:({state:e,dispatch:t})=>{let n=Sn(e),r=null,i=e.changeByRange(t=>{let i=t.from,{doc:a}=e;if(t.empty&&$L.isActiveAt(e,t.from)){let t=a.lineAt(i),r=nR(uR(n,i),a);if(r.length){let n=r[r.length-1],a=n.to-n.spaceAfter.length+ +!!n.spaceAfter;if(i-t.from>a&&!/\S/.test(t.text.slice(a,i-t.from)))return{range:En.cursor(t.from+a),changes:{from:t.from+a,to:i}};if(i-t.from==a&&(!n.item||t.from<=n.item.from||!/\S/.test(t.text.slice(0,n.to)))){let r=t.from+n.from;if(n.item&&n.node.from<n.item.from&&/\S/.test(t.text.slice(n.from,n.to))){let i=n.blank(mn(t.text,4,n.to)-mn(t.text,4,n.from));return r==t.from&&(i=aR(i,e)),{range:En.cursor(r+i.length),changes:{from:r,to:t.from+n.to,insert:i}}}if(r<i)return{range:En.cursor(r),changes:{from:r,to:i}}}}}return r={range:t}});return r?!1:(t(e.update(i,{scrollIntoView:!0,userEvent:`delete`})),!0)}}],fR=VL({matchClosingTags:!1});function pR(e={}){let{codeLanguages:t,defaultCodeLanguage:n,addKeymap:r=!0,base:{parser:i}=QL,completeHTMLTags:a=!0,pasteURLAsLink:o=!0,htmlTagLanguage:s=fR}=e;if(!(i instanceof tN))throw RangeError("Base parser provided to `markdown` should be a Markdown parser");let c=e.extensions?[e.extensions]:[],l=[s.support,XL],u;o&&l.push(vR),n instanceof Wn?(l.push(n.support),u=n.language):n&&(u=n);let d=t||u?eR(t,u):void 0;c.push(jN({codeParser:d,htmlParser:s.language.parser})),r&&l.push(Vn.high(Un.of(dR)));let f=ZL(i.configure(c));return a&&l.push(f.data.of({autocomplete:mR})),new Wn(f,l)}function mR(e){let{state:t,pos:n}=e,r=/<[:\-\.\w\u00b7-\uffff]*$/.exec(t.sliceDoc(n-25,n));if(!r)return null;let i=Sn(t).resolveInner(n,-1);for(;i&&!i.type.isTop;){if(i.name==`CodeBlock`||i.name==`FencedCode`||i.name==`ProcessingInstructionBlock`||i.name==`CommentBlock`||i.name==`Link`||i.name==`Image`)return null;i=i.parent}return{from:n-r[0].length,to:n,options:gR(),validFor:/^<[:\-\.\w\u00b7-\uffff]*$/}}var hR=null;function gR(){if(hR)return hR;let e=PL(new ir(gn.create({extensions:fR}),0,!0));return hR=e?e.options:[]}var _R=/code|horizontalrule|html|link|comment|processing|escape|entity|image|mark|url/i,vR=An.domEventHandlers({paste:(e,t)=>{let{main:n}=t.state.selection;if(n.empty)return!1;let r=e.clipboardData?.getData(`text/plain`);if(!r||!/^(https?:\/\/|mailto:|xmpp:|www\.)/.test(r)||(/^www\./.test(r)&&(r=`https://`+r),!$L.isActiveAt(t.state,n.from,1)))return!1;let i=Sn(t.state),a=!1;return i.iterate({from:n.from,to:n.to,enter:e=>{(e.from>n.from||_R.test(e.name))&&(a=!0)},leave:e=>{e.to<n.to&&(a=!0)}}),a?!1:(t.dispatch({changes:[{from:n.from,insert:`[`},{from:n.to,insert:`](${r})`}],userEvent:`input.paste`,scrollIntoView:!0}),!0)}});function yR(){return yR=Object.assign?Object.assign.bind():function(e){for(var t=1;t<arguments.length;t++){var n=arguments[t];for(var r in n)({}).hasOwnProperty.call(n,r)&&(e[r]=n[r])}return e},yR.apply(null,arguments)}var bR=e=>{var{theme:t,settings:n={},styles:r=[]}=e,i={".cm-gutters":{}},a={};n.background&&(a.backgroundColor=n.background),n.backgroundImage&&(a.backgroundImage=n.backgroundImage),n.foreground&&(a.color=n.foreground),n.fontSize&&(a.fontSize=n.fontSize),(n.background||n.foreground)&&(i[`&`]=a),n.fontFamily&&(i[`&.cm-editor .cm-scroller`]={fontFamily:n.fontFamily}),n.gutterBackground&&(i[`.cm-gutters`].backgroundColor=n.gutterBackground),n.gutterForeground&&(i[`.cm-gutters`].color=n.gutterForeground),n.gutterBorder&&(i[`.cm-gutters`].borderRightColor=n.gutterBorder),n.caret&&(i[`.cm-content`]={caretColor:n.caret},i[`.cm-cursor, .cm-dropCursor`]={borderLeftColor:n.caret});var o={};return n.gutterActiveForeground&&(o.color=n.gutterActiveForeground),n.lineHighlight&&(i[`.cm-activeLine`]={backgroundColor:n.lineHighlight},o.backgroundColor=n.lineHighlight),i[`.cm-activeLineGutter`]=o,n.selection&&(i[`&.cm-focused .cm-selectionBackground, & .cm-line::selection, & .cm-selectionLayer .cm-selectionBackground, .cm-content ::selection`]={background:n.selection+` !important`}),n.selectionMatch&&(i[`& .cm-selectionMatch`]={backgroundColor:n.selectionMatch}),[An.theme(i,{dark:t===`dark`}),xn(Yn.define(r))]},xR={background:`#2E3235`,foreground:`#DDDDDD`,caret:`#DDDDDD`,selection:`#202325`,selectionMatch:`#202325`,gutterBackground:`#292d30`,gutterForeground:`#808080`,gutterBorder:`1px solid #ffffff10`,lineHighlight:`#B9D2FF30`},SR=[{tag:K.keyword,color:`#fda331`},{tag:[K.name,K.deleted,K.character,K.propertyName,K.macroName],color:`#b5bd68`},{tag:[K.variableName],color:`#6fb3d2`},{tag:[K.function(K.variableName)],color:`#fda331`},{tag:[K.labelName],color:`#fc6d24`},{tag:[K.color,K.constant(K.name),K.standard(K.name)],color:`#fda331`},{tag:[K.definition(K.name),K.separator],color:`#cc99cc`},{tag:[K.brace],color:`#cc99cc`},{tag:[K.annotation],color:`#fc6d24`},{tag:[K.number,K.changed,K.annotation,K.modifier,K.self,K.namespace],color:`#fda331`},{tag:[K.typeName,K.className],color:`#6fb3d2`},{tag:[K.operator,K.operatorKeyword],color:`#cc99cc`},{tag:[K.tagName],color:`#fda331`},{tag:[K.squareBracket],color:`#cc99cc`},{tag:[K.angleBracket],color:`#cc99cc`},{tag:[K.attributeName],color:`#6fb3d2`},{tag:[K.regexp],color:`#fda331`},{tag:[K.quote],color:`#DDDDDD`},{tag:[K.string],color:`#b5bd68`},{tag:K.link,color:`#6987AF`,textDecoration:`underline`,textUnderlinePosition:`under`},{tag:[K.url,K.escape,K.special(K.string)],color:`#8abeb7`},{tag:[K.meta],color:`#A54543`},{tag:[K.comment],color:`#808080`,fontStyle:`italic`},{tag:K.monospace,color:`#DDDDDD`},{tag:K.strong,fontWeight:`bold`,color:`#fda331`},{tag:K.emphasis,fontStyle:`italic`,color:`#6fb3d2`},{tag:K.strikethrough,textDecoration:`line-through`},{tag:K.heading,fontWeight:`bold`,color:`#DDDDDD`},{tag:K.special(K.heading1),fontWeight:`bold`,color:`#DDDDDD`},{tag:K.heading1,fontWeight:`bold`,color:`#DDDDDD`},{tag:[K.heading2,K.heading3,K.heading4],fontWeight:`bold`,color:`#DDDDDD`},{tag:[K.heading5,K.heading6],color:`#DDDDDD`},{tag:[K.atom,K.bool,K.special(K.variableName)],color:`#8abeb7`},{tag:[K.processingInstruction,K.inserted],color:`#8abeb7`},{tag:[K.contentSeparator],color:`#6fb3d2`},{tag:K.invalid,color:`#B9D2FF`,borderBottom:`1px dotted #fc6d24`}],CR=e=>{var{theme:t=`dark`,settings:n={},styles:r=[]}=e||{};return bR({theme:t,settings:yR({},xR,n),styles:[...SR,...r]})};CR();var wR={background:`#ffffff`,foreground:`#2e3440`,caret:`#3b4252`,selection:`#eceff4`,selectionMatch:`#e5e9f0`,gutterBackground:`#eceff4`,gutterForeground:`#2e3440`,gutterBorder:`none`,lineHighlight:`#02255f11`},TR=[{tag:K.keyword,color:`#5e81ac`},{tag:[K.name,K.deleted,K.character,K.propertyName,K.macroName],color:`#d08770`},{tag:[K.variableName],color:`#d08770`},{tag:[K.function(K.variableName)],color:`#5e81ac`},{tag:[K.labelName],color:`#81a1c1`},{tag:[K.color,K.constant(K.name),K.standard(K.name)],color:`#5e81ac`},{tag:[K.definition(K.name),K.separator],color:`#a3be8c`},{tag:[K.brace],color:`#8fbcbb`},{tag:[K.annotation],color:`#d30102`},{tag:[K.number,K.changed,K.annotation,K.modifier,K.self,K.namespace],color:`#88c0d0`},{tag:[K.typeName,K.className],color:`#ebcb8b`},{tag:[K.operator,K.operatorKeyword],color:`#a3be8c`},{tag:[K.tagName],color:`#b48ead`},{tag:[K.squareBracket],color:`#bf616a`},{tag:[K.angleBracket],color:`#d08770`},{tag:[K.attributeName],color:`#ebcb8b`},{tag:[K.regexp],color:`#5e81ac`},{tag:[K.quote],color:`#3b4252`},{tag:[K.string],color:`#d08770`},{tag:K.link,color:`#8fbcbb`,textDecoration:`underline`,textUnderlinePosition:`under`},{tag:[K.url,K.escape,K.special(K.string)],color:`#d08770`},{tag:[K.meta],color:`#88c0d0`},{tag:[K.comment],color:`#434c5e`,fontStyle:`italic`},{tag:K.strong,fontWeight:`bold`,color:`#5e81ac`},{tag:K.emphasis,fontStyle:`italic`,color:`#5e81ac`},{tag:K.strikethrough,textDecoration:`line-through`},{tag:K.heading,fontWeight:`bold`,color:`#5e81ac`},{tag:K.special(K.heading1),fontWeight:`bold`,color:`#5e81ac`},{tag:K.heading1,fontWeight:`bold`,color:`#5e81ac`},{tag:[K.heading2,K.heading3,K.heading4],fontWeight:`bold`,color:`#5e81ac`},{tag:[K.heading5,K.heading6],color:`#5e81ac`},{tag:[K.atom,K.bool,K.special(K.variableName)],color:`#d08770`},{tag:[K.processingInstruction,K.inserted],color:`#8fbcbb`},{tag:[K.contentSeparator],color:`#ebcb8b`},{tag:K.invalid,color:`#434c5e`,borderBottom:`1px dotted #d30102`}],ER=e=>{var{theme:t=`light`,settings:n={},styles:r=[]}=e||{};return bR({theme:t,settings:yR({},wR,n),styles:[...TR,...r]})};ER();var DR=[Nn.of({name:`javascript`,alias:[`js`,`jsx`],extensions:[`js`,`mjs`,`cjs`,`jsx`],load:async()=>lL({jsx:!0})}),Nn.of({name:`typescript`,alias:[`ts`,`tsx`],extensions:[`ts`,`mts`,`cts`,`tsx`],load:async()=>lL({typescript:!0,jsx:!0})}),Nn.of({name:`json`,alias:[`jsonc`],extensions:[`json`,`jsonc`],load:()=>n(()=>import(`./dist-Gvva1zQ6.js`).then(e=>e.json()),__vite__mapDeps([25,26,4,27,28]),import.meta.url)}),Nn.of({name:`yaml`,alias:[`yml`],extensions:[`yaml`,`yml`],load:()=>n(()=>import(`./dist-DVWct0HX.js`).then(e=>e.yaml()),__vite__mapDeps([29,26,4,27,28]),import.meta.url)}),Nn.of({name:`css`,alias:[`scss`,`less`],extensions:[`css`,`scss`,`less`],load:async()=>sI()}),Nn.of({name:`html`,alias:[`htm`],extensions:[`html`,`htm`],load:async()=>VL()}),Nn.of({name:`python`,alias:[`py`],extensions:[`py`,`pyw`],load:()=>n(()=>import(`./dist-CSfB7p8y.js`).then(e=>e.python()),__vite__mapDeps([30,31,26,4,27,28]),import.meta.url)}),Nn.of({name:`rust`,alias:[`rs`],extensions:[`rs`],load:()=>n(()=>import(`./dist-BJPjDIRr.js`).then(e=>e.rust()),__vite__mapDeps([32,26,4,27,28]),import.meta.url)}),Nn.of({name:`markdown`,alias:[`md`,`mdx`],extensions:[`md`,`mdx`,`markdown`],load:async()=>pR()}),Nn.of({name:`bash`,alias:[`sh`,`shell`,`zsh`],extensions:[`sh`,`bash`,`zsh`],load:async()=>{let[{StreamLanguage:e,LanguageSupport:t},{shell:r}]=await Promise.all([n(()=>import(`./dist-BEF_m-Pp.js`).then(e=>e.m),__vite__mapDeps([26,4,27]),import.meta.url),n(()=>import(`./shell-DT_H80Gx.js`),[],import.meta.url)]);return new t(e.define(r))}}),Nn.of({name:`go`,alias:[`golang`],extensions:[`go`],load:async()=>{let[{StreamLanguage:e,LanguageSupport:t},{go:r}]=await Promise.all([n(()=>import(`./dist-BEF_m-Pp.js`).then(e=>e.m),__vite__mapDeps([26,4,27]),import.meta.url),n(()=>import(`./go-BRhAdNMM.js`),[],import.meta.url)]);return new t(e.define(r))}}),Nn.of({name:`math`,alias:[`latex`,`tex`],extensions:[`tex`,`latex`],load:async()=>{let[{StreamLanguage:e,LanguageSupport:t},{stex:r}]=await Promise.all([n(()=>import(`./dist-BEF_m-Pp.js`).then(e=>e.m),__vite__mapDeps([26,4,27]),import.meta.url),n(()=>import(`./stex-DQW679lh.js`),[],import.meta.url)]);return new t(e.define(r))}})],OR=Cn.define(),kR=Cn.define(),AR=Kn.line({class:`agent-flash`}),jR=Tn.define({create(){return Kn.none},update(e,t){e=e.map(t.changes);for(let n of t.effects)if(n.is(OR)){let{from:r,to:i}=n.value,a=[];for(let e=r;e<=i;){let n=t.state.doc.lineAt(e);a.push(AR.range(n.from)),e=n.to+1}e=e.update({add:a,sort:!0})}else n.is(kR)&&(e=Kn.none);return e},provide:e=>An.decorations.from(e)});function MR(e){let t=e.getMap(`agent-flash`);return[jR,jn.define(e=>{let n=0,r=Date.now(),i=null,a=null,o=!1;function s(){let t=e.state.doc.length;t!==0&&(o||(e.dispatch({effects:OR.of({from:0,to:t})}),a&&clearTimeout(a),a=setTimeout(()=>{a=null,!o&&e.dispatch({effects:kR.of(null)})},w)))}let l=e=>{if(ne(t),!c(t,r))return;r=Date.now();let a=Date.now();if(a-n<500){if(!i){let e=500-(a-n);i=setTimeout(()=>{i=null,n=Date.now(),s()},e)}return}n=a,s()};t.observe(l);let u=()=>{document.visibilityState===`visible`?c(t,r)&&(r=Date.now(),n=Date.now(),s()):r=Date.now()};return document.addEventListener(`visibilitychange`,u),{update(e){},destroy(){o=!0,t.unobserve(l),document.removeEventListener(`visibilitychange`,u),i&&=(clearTimeout(i),null),a&&=(clearTimeout(a),null)}}})]}var NR=/\[([^\]\n]*)\]\((<[^>\n]+>|[^)\s\n]+)(?:\s+(?:"[^"\n]*"|'[^'\n]*'|\([^)\n]*\)))?\)/g,PR=Kn.mark({class:`cm-md-internal-link`});function FR(e,t){return t>0&&e[t-1]===`!`}function IR(e){let t=e[2]??``;return t.startsWith(`<`)&&t.endsWith(`>`)?t.slice(1,-1):t}function LR(e){let t=new zn;for(let{from:n,to:r}of e.visibleRanges){let i=e.state.doc.sliceString(n,r);NR.lastIndex=0;let a=NR.exec(i);for(;a!==null;){let e=FR(i,a.index)?null:hk(IR(a));e&&e.kind!==`external`&&t.add(n+a.index,n+a.index+a[0].length,PR),a=NR.exec(i)}}return t.finish()}var RR=jn.fromClass(class{decorations;constructor(e){this.decorations=LR(e)}update(e){(e.docChanged||e.viewportChanged)&&(this.decorations=LR(e.view))}},{decorations:e=>e.decorations}),zR=An.domEventHandlers({mousedown(e,t){if(!e.ctrlKey&&!e.metaKey)return!1;let n=t.posAtCoords({x:e.clientX,y:e.clientY});if(n===null)return!1;let r=t.state.doc.lineAt(n);NR.lastIndex=0;let i=NR.exec(r.text);for(;i!==null;){let t=r.from+i.index,a=t+i[0].length;if(n>=t&&n<=a){let t=FR(r.text,i.index)?null:hk(IR(i));if(t&&t.kind!==`external`)return e.preventDefault(),t.kind===`doc`&&bk(e)?(yk(t),!0):(Sk(t),!0)}i=NR.exec(r.text)}return!1}}),BR=An.theme({".cm-md-internal-link":{color:`oklch(52.7% 0.154 228.4)`,fontWeight:`500`},".cm-md-internal-link:hover":{textDecoration:`underline`,cursor:`pointer`}});function VR(){return[RR,zR,BR]}var HR=5e3,UR=null,WR=0,GR=null,KR=new Map;async function qR(){let e=Date.now();return UR&&e-WR<HR?UR:(UR=await pA(),WR=e,GR=$R(UR),UR)}async function JR(e){let t=Date.now(),n=KR.get(e);if(n!==void 0&&t-n.time<HR)return n.headings;try{let n=await mA(e);return KR.set(e,{headings:n,time:t}),n}catch(n){return console.warn(`[wiki-link-source] /api/page-headings fetch failed:`,n),KR.set(e,{headings:[],time:t}),[]}}var YR=/\[\[[^\]]*?\]\]/g,XR=Kn.mark({class:`cm-wiki-link`}),ZR=Kn.mark({class:`cm-wiki-link cm-wiki-link-broken`});function QR(e){let t=new Set;for(let n of e)if(t.add(n.docName.toLowerCase()),n.title&&t.add(n.title.toLowerCase()),n.kind===`asset`){let e=n.docName.replace(/^\//,``);t.add(e.toLowerCase());let r=e.lastIndexOf(`/`);t.add((r===-1?e:e.slice(r+1)).toLowerCase())}return t}function $R(e){let t=QR(e);for(let n of e){if(n.kind===`asset`)continue;let e=n.docName.split(`/`);e.pop();let r=``;for(let n of e)r=r?`${r}/${n}`:n,t.add(r.toLowerCase())}return t}function ez(e){return e.split(/[#|]/)[0].trim().toLowerCase()}function tz(e){let t=new zn,n=UR?GR:null;for(let{from:r,to:i}of e.visibleRanges){let a=e.state.doc.sliceString(r,i);YR.lastIndex=0;let o=YR.exec(a);for(;o!==null;){let e=XR;if(n){let t=ez(o[0].slice(2,-2));t&&!n.has(t)&&(e=ZR)}t.add(r+o.index,r+o.index+o[0].length,e),o=YR.exec(a)}}return t.finish()}var nz=jn.fromClass(class{decorations;cacheWarmAtBuild;constructor(e){this.cacheWarmAtBuild=UR!==null,this.decorations=tz(e),this.cacheWarmAtBuild||this.warmCache(e)}update(e){let t=UR!==null;(e.docChanged||e.viewportChanged||!this.cacheWarmAtBuild&&t)&&(this.cacheWarmAtBuild=t,this.decorations=tz(e.view))}warmCache(e){qR().then(()=>{try{e.dispatch({})}catch{}}).catch(e=>{console.warn(`[wiki-link-source] warmCache fetch failed:`,e)})}},{decorations:e=>e.decorations}),rz=/\[\[([^[\]|#]+?)(?:#([^\]|]+?))?(?:\|([^\]]+?))?\]\]/g,iz=An.domEventHandlers({mousedown(e,t){if(!e.ctrlKey&&!e.metaKey)return!1;let n=t.posAtCoords({x:e.clientX,y:e.clientY});if(n===null)return!1;let r=t.state.doc.lineAt(n);rz.lastIndex=0;let i=rz.exec(r.text);for(;i!==null;){let t=r.from+i.index,a=t+i[0].length;if(n>=t&&n<=a){let t=i[1]?.trim(),n=i[2]?.trim()||null;if(t){let r=rt(t,n);if(!r)return!1;if(e.preventDefault(),r.kind===`external`)_k(r.url);else if(r.kind===`asset`){let t=dC(r.url,new Set((UR??[]).filter(e=>e.kind===`asset`).map(e=>e.docName.replace(/^\//,``))))??r.url.replace(/^\//,``);bk(e)?window.open(ot(t),`_blank`,`noopener,noreferrer`):window.location.hash=ot(t)}else bk(e)?yk(r):window.location.hash=r.anchor?`#/${r.docName}?anchor=${encodeURIComponent(r.anchor)}`:`#/${r.docName}`}return!0}i=rz.exec(r.text)}return!1}});async function az(e){let t=e.state.doc.sliceString(0,e.pos).match(/\[\[([^\]]*)$/);if(!t)return null;let n=t[1],r=e.pos-n.length,i=n.indexOf(`#`);if(i>0){let e=n.slice(0,i),t=n.slice(i+1),a=r+i+1,o=await JR(e);if(!o.length)return null;let s=cA(o,t);return s.length?{from:a,filter:!1,options:s.map(e=>({label:e.text,detail:`H${e.level}`,apply(t,n,r,i){let a=t.state.doc.sliceString(i,i+2)===`]]`?``:`]]`;t.dispatch({changes:{from:r,to:i,insert:e.slug+a},selection:{anchor:r+e.slug.length+a.length}})}}))}:null}return{from:r,filter:!1,options:aA(await qR().catch(e=>(console.warn(`[wiki-link-source] Failed to fetch pages:`,e),[])),n).map(e=>({label:e.title,detail:e.title===e.docName?void 0:e.docName,apply(t,n,r,i){let a=t.state.doc.sliceString(i,i+2)===`]]`?``:`]]`,o=e.kind===`asset`?`${e.docName}|${e.title}${a}`:e.docName+a;t.dispatch({changes:{from:r,to:i,insert:o},selection:{anchor:r+o.length}})}}))}}var oz=An.theme({".cm-wiki-link":{color:`oklch(52.7% 0.154 228.4)`,fontWeight:`500`},".cm-wiki-link:hover":{textDecoration:`underline`,cursor:`pointer`}});function sz(){return[nz,iz,oz,$L.data.of({autocomplete:az})]}var cz=CR({settings:{background:`transparent`,gutterBackground:`transparent`}}),lz=ER({settings:{background:`transparent`,gutterBackground:`transparent`}});function uz(e){let{themeCompartment:t,resolvedTheme:n,ydoc:r}=e,i=n===`dark`?cz:lz;return[pR({base:$L,extensions:[YN],codeLanguages:DR}),sz(),VR(),...r?[MR(r)]:[],Un.of([]),t.of(i),An.lineWrapping,...e.extraKeymaps?[e.extraKeymaps]:[]]}function dz(e,t,n){let{state:r}=e,i=r.selection.main;if(!i.empty)return!1;if(t===`line`){let e=r.doc.lineAt(i.head);return n<0?e.from===0:e.to===r.doc.length}return n<0?i.head===0:i.head===r.doc.length}function fz(e){let{pmSel:t,nodePos:n,nodeSize:r,cmDocLen:i,cmSel:a,cmHasFocus:o}=e;if(t instanceof z&&t.from===n)return o?{kind:`noop`}:{kind:`focus`};let s=n+1,c=n+r-1;if(t.from>=s&&t.to<=c){let e=Math.max(0,Math.min(t.anchor-s,i)),n=Math.max(0,Math.min(t.head-s,i));return a.anchor===e&&a.head===n&&o?{kind:`noop`}:{kind:`selection`,anchor:e,head:n}}return{kind:`noop`}}function pz(e,t){let n=Rj().parseWithFallback(e),r;try{r=t.nodeFromJSON(n)}catch(e){return console.warn(JSON.stringify({event:`raw-mdx-upgrade-failure`,reason:e instanceof Error?e.message:String(e)})),null}if(r.childCount===0)return null;let i=[];for(let e=0;e<r.childCount;e++){let t=r.child(e);if(t.type.name===`rawMdxFallback`)return null;i.push(t)}return i}function mz(e,t){if(e===t)return null;let n=0,r=e.length,i=t.length;for(;n<r&&e.charCodeAt(n)===t.charCodeAt(n);)n++;for(;r>n&&i>n&&e.charCodeAt(r-1)===t.charCodeAt(i-1);)r--,i--;return{from:n,to:r,text:t.slice(n,i)}}var hz=`Unregistered component:`;function gz(e){if(!e.startsWith(hz))return null;let t=e.slice(23).trim();return t.length>0?t:null}function _z(e){let t=(0,Y.c)(49),{node:n,editor:r,getPos:i}=e,a=(0,q.useRef)(null),o=(0,q.useRef)(null),s=(0,q.useRef)(!1),c;t[0]===Symbol.for(`react.memo_cache_sentinel`)?(c=new Qn,t[0]=c):c=t[0];let l=(0,q.useRef)(c),{resolvedTheme:u}=Ie(),d=n.attrs.reason||`Parse failed`,f;t[1]===d?f=t[2]:(f=xM(d),t[1]=d,t[2]=f);let p=f,m=SM[p],h;t[3]!==d||t[4]!==p?(h=p===`info`?gz(d):null,t[3]=d,t[4]=p,t[5]=h):h=t[5];let g=h,_;t[6]!==r||t[7]!==i?(_=e=>{let t=typeof i==`function`?i():void 0;if(t===void 0)return;let n=yM(r);if(!n)return;let a=n.state.doc.nodeAt(t);if(!a||a.type.name!==`rawMdxFallback`)return;let o=t+1,c=t+a.nodeSize-1;s.current=!0;try{let t=n.state.tr;if(e.length===0)t.delete(o,c);else{let r=n.state.schema.text(e);t.replaceWith(o,c,r)}n.dispatch(t)}catch(e){let t=e;throw s.current=!1,t}s.current=!1},t[6]=r,t[7]=i,t[8]=_):_=t[8];let v=_,y;t[9]!==r||t[10]!==v||t[11]!==i||t[12]!==n.textContent||t[13]!==u?(y=()=>{let e=a.current;if(!e)return;let t=l.current,c=Un.of([{key:`Mod-z`,run:()=>(r.commands.undo(),!0)},{key:`Mod-y`,run:()=>(r.commands.redo(),!0)},{key:`Mod-Shift-z`,run:()=>(r.commands.redo(),!0)}]),d=e=>{let t=typeof i==`function`?i():void 0;if(typeof t!=`number`)return!1;let n=yM(r);if(!n)return!1;let a=n.state.doc.nodeAt(t);if(!a||a.type.name!==`rawMdxFallback`)return!1;let o=e<0?t:t+a.nodeSize,s=M.near(n.state.doc.resolve(o),e);return n.dispatch(n.state.tr.setSelection(s).scrollIntoView()),n.focus(),!0},f=Un.of([{key:`ArrowUp`,run:e=>dz(e,`line`,-1)?d(-1):!1},{key:`ArrowLeft`,run:e=>dz(e,`char`,-1)?d(-1):!1},{key:`ArrowDown`,run:e=>dz(e,`line`,1)?d(1):!1},{key:`ArrowRight`,run:e=>dz(e,`char`,1)?d(1):!1}]),p=uz({themeCompartment:t,resolvedTheme:u,ydoc:bM(r)??void 0,extraKeymaps:c});p.push(f),p.push(An.updateListener.of(e=>{if(e.docChanged&&!s.current&&v(e.state.doc.toString()),e.focusChanged&&e.view.hasFocus&&!s.current){let e=typeof i==`function`?i():void 0;if(typeof e!=`number`)return;let t=yM(r);if(!t)return;let n=t.state.selection;if(n instanceof z&&n.from===e)return;let a=t.state.doc.nodeAt(e);if(!a||a.type.name!==`rawMdxFallback`)return;s.current=!0;try{t.dispatch(t.state.tr.setSelection(z.create(t.state.doc,e)))}catch(e){let t=e;throw s.current=!1,t}s.current=!1}if(e.focusChanged&&!e.view.hasFocus&&!s.current){let t=typeof i==`function`?i():void 0;if(typeof t!=`number`)return;let n=yM(r);if(!n)return;let a=n.state.doc.nodeAt(t);if(!a||a.type.name!==`rawMdxFallback`)return;let o=pz(e.view.state.doc.toString(),n.state.schema);if(!o)return;s.current=!0;try{n.dispatch(n.state.tr.replaceWith(t,t+a.nodeSize,o))}catch(e){let t=e;throw s.current=!1,t}s.current=!1}}));let m=new An({doc:n.textContent,extensions:p,parent:e});o.current=m;let h=yz,g=m.contentDOM;g.addEventListener(`keydown`,h),g.addEventListener(`paste`,h),g.addEventListener(`drop`,h),g.addEventListener(`cut`,h);let _=()=>{g.removeEventListener(`keydown`,h),g.removeEventListener(`paste`,h),g.removeEventListener(`drop`,h),g.removeEventListener(`cut`,h)};return()=>{_(),m.destroy(),o.current=null}},t[9]=r,t[10]=v,t[11]=i,t[12]=n.textContent,t[13]=u,t[14]=y):y=t[14];let b;t[15]===Symbol.for(`react.memo_cache_sentinel`)?(b=[],t[15]=b):b=t[15],(0,q.useEffect)(y,b);let x,S;t[16]===u?(x=t[17],S=t[18]):(x=()=>{let e=o.current;if(!e)return;let t=u===`dark`?cz:lz;e.dispatch({effects:l.current.reconfigure(t)})},S=[u],t[16]=u,t[17]=x,t[18]=S),(0,q.useEffect)(x,S);let C,w;t[19]!==r||t[20]!==i?(w=()=>{let e=()=>{let e=typeof i==`function`?i():void 0;if(typeof e!=`number`)return;let t=o.current;if(!t||s.current)return;let n=yM(r);if(!n)return;let a=n.state.doc.nodeAt(e);if(!a)return;let c=fz({pmSel:n.state.selection,nodePos:e,nodeSize:a.nodeSize,cmDocLen:t.state.doc.length,cmSel:{anchor:t.state.selection.main.anchor,head:t.state.selection.main.head},cmHasFocus:t.hasFocus});if(c.kind!==`noop`){s.current=!0;try{c.kind===`selection`&&t.dispatch({selection:{anchor:c.anchor,head:c.head}}),t.hasFocus||t.focus()}catch(e){let t=e;throw s.current=!1,t}s.current=!1}};return r.on(`selectionUpdate`,e),()=>{r.off(`selectionUpdate`,e)}},C=[r,i],t[19]=r,t[20]=i,t[21]=C,t[22]=w):(C=t[21],w=t[22]),(0,q.useEffect)(w,C);let T=n.textContent,E,D;t[23]===T?(E=t[24],D=t[25]):(E=()=>{let e=o.current;if(!e||s.current)return;let t=mz(e.state.doc.toString(),T);if(t){s.current=!0;try{e.dispatch({changes:{from:t.from,to:t.to,insert:t.text}})}catch(e){let t=e;throw s.current=!1,t}s.current=!1}},D=[T],t[23]=T,t[24]=E,t[25]=D),(0,q.useEffect)(E,D);let O;t[26]!==r||t[27]!==i?(O=()=>{let e=typeof i==`function`?i():void 0;typeof e==`number`&&r.chain().focus().setNodeSelection(e).deleteSelection().run()},t[26]=r,t[27]=i,t[28]=O):O=t[28];let k=O,A=g?`raw-mdx-fallback-wrapper jsx-component-wrapper jsx-component-wrapper--unregistered relative my-2 py-2 rounded border border-dashed ${m.wrapperClass}`:`raw-mdx-fallback-wrapper relative my-2 py-2 rounded border border-dashed ${m.wrapperClass}`,j;t[29]===g?j=t[30]:(j=g?{"data-jsx-component":``,role:`group`,"aria-label":`Unknown component: ${g}`}:{},t[29]=g,t[30]=j);let N=j,P=`rounded px-1.5 py-0.5 text-[10px] font-semibold uppercase tracking-wider ${m.badgeClass}`,F;t[31]!==d||t[32]!==m.label||t[33]!==P?(F=(0,J.jsx)(`span`,{className:P,title:d,children:m.label}),t[31]=d,t[32]=m.label,t[33]=P,t[34]=F):F=t[34];let I;t[35]===Symbol.for(`react.memo_cache_sentinel`)?(I=(0,J.jsx)(Xr,{size:12}),t[35]=I):I=t[35];let L;t[36]===k?L=t[37]:(L=(0,J.jsx)(`button`,{type:`button`,className:`jsx-chrome-btn jsx-chrome-btn--delete`,"aria-label":`Delete block`,onClick:k,children:I}),t[36]=k,t[37]=L);let R;t[38]!==F||t[39]!==L?(R=(0,J.jsxs)(`div`,{className:`absolute top-1 right-1 z-10 flex items-center gap-1.5`,contentEditable:!1,onMouseDown:vz,children:[F,L]}),t[38]=F,t[39]=L,t[40]=R):R=t[40];let B=`Editing broken MDX source: ${d}`,V;t[41]===B?V=t[42]:(V=(0,J.jsx)(`div`,{ref:a,className:`raw-mdx-fallback-cm`,role:`group`,"aria-label":B}),t[41]=B,t[42]=V);let H;return t[43]!==p||t[44]!==R||t[45]!==V||t[46]!==N||t[47]!==A?(H=(0,J.jsxs)(oc,{className:A,contentEditable:!1,"data-drag-handle":``,draggable:`true`,"data-severity":p,...N,children:[R,V]}),t[43]=p,t[44]=R,t[45]=V,t[46]=N,t[47]=A,t[48]=H):H=t[48],H}function vz(e){return e.stopPropagation()}function yz(){}function bz(e,t){if(!e.selection.empty)return null;let n=t===`up`||t===`left`?-1:1,r=e.selection.$head,i=n>0?r.after():r.before();if(typeof i!=`number`)return null;let a=M.near(e.doc.resolve(i),n);return a.$head?.parent.type.name===`rawMdxFallback`?a:null}function xz(e,t){let{state:n,view:r}=e;if(!r.endOfTextblock(t))return!1;let i=bz(n,t);return i?(r.dispatch(n.tr.setSelection(i)),!0):!1}var Sz=it.extend({addKeyboardShortcuts(){return{ArrowLeft:({editor:e})=>xz(e,`left`),ArrowRight:({editor:e})=>xz(e,`right`),ArrowUp:({editor:e})=>xz(e,`up`),ArrowDown:({editor:e})=>xz(e,`down`)}},addNodeView(){return mc(_z,{stopEvent:()=>!0,ignoreMutation:()=>!0})}});function Cz(e){let t=(0,Y.c)(47),{items:n,selectedIndex:r,categoryLabels:i,onSelect:a,onHoverIndex:o}=e,s=(0,q.useRef)(null),c=(0,q.useId)(),l=r>=0&&r<n.length?`${c}-option-${r}`:void 0,u=Tz,d,f;if(t[0]===r?(d=t[1],f=t[2]):(d=()=>{let e=s.current;if(!e)return;let t=e.querySelectorAll(`[role="option"]`).item(r);t&&t.scrollIntoView({block:`nearest`})},f=[r],t[0]=r,t[1]=d,t[2]=f),(0,q.useEffect)(d,f),n.length===0){let e;return t[3]===Symbol.for(`react.memo_cache_sentinel`)?(e=(0,J.jsx)(`div`,{ref:s,role:`status`,"aria-live":`polite`,className:`w-56 rounded-lg border bg-popover p-2 shadow-md text-sm text-muted-foreground`,style:{maxHeight:`var(--suggestion-menu-max-height, 40vh)`},onMouseDown:u,children:`No results`}),t[3]=e):e=t[3],e}let p,m,h,g,_,v,y,b,x,S,C,w,T;if(t[4]!==l||t[5]!==i||t[6]!==n||t[7]!==c||t[8]!==o||t[9]!==a||t[10]!==r){let e=[],d=0,f=new Map;for(let t of n){f.set(t,d++);let n=e.find(e=>e.key===t.category);n?n.items.push(t):e.push({key:t.category,items:[t]})}m=r>=0&&r<n.length?n[r]:null;let E;t[24]===n?E=t[25]:(E=n.some(wz),t[24]=n,t[25]=E),p=E,v=`flex items-start gap-2`,y=s,b=`listbox`,x=`Slash commands`,S=l,C=-1,w=u,T=`w-56 overflow-y-auto subtle-scrollbar rounded-lg border bg-popover p-1 shadow-md`,t[26]===Symbol.for(`react.memo_cache_sentinel`)?(h={maxHeight:`var(--suggestion-menu-max-height, 40vh)`},t[26]=h):h=t[26];let D=m?`${m.label}${m.preview?`. ${m.preview.description}`:``}`:``;t[27]===D?g=t[28]:(g=(0,J.jsx)(`span`,{className:`sr-only`,"aria-live":`polite`,"aria-atomic":`true`,children:D}),t[27]=D,t[28]=g),_=e.map(e=>(0,J.jsxs)(`div`,{role:`group`,"aria-labelledby":`${c}-group-${e.key}`,children:[(0,J.jsx)(`div`,{id:`${c}-group-${e.key}`,className:`px-2 py-1.5 text-xs font-semibold text-muted-foreground`,children:i[e.key]??e.key}),e.items.map(e=>{let t=f.get(e)??0,n=t===r,i=e.icon;return(0,J.jsxs)(`button`,{id:`${c}-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`:``}`,onMouseEnter:()=>o?.(t),onMouseDown:t=>{t.preventDefault(),a(e)},children:[(0,J.jsx)(i,{className:`size-4 shrink-0 text-muted-foreground`}),(0,J.jsx)(`div`,{className:`flex flex-col min-w-0`,children:(0,J.jsx)(`span`,{className:`truncate`,children:e.label})})]},e.name)})]},e.key)),t[4]=l,t[5]=i,t[6]=n,t[7]=c,t[8]=o,t[9]=a,t[10]=r,t[11]=p,t[12]=m,t[13]=h,t[14]=g,t[15]=_,t[16]=v,t[17]=y,t[18]=b,t[19]=x,t[20]=S,t[21]=C,t[22]=w,t[23]=T}else p=t[11],m=t[12],h=t[13],g=t[14],_=t[15],v=t[16],y=t[17],b=t[18],x=t[19],S=t[20],C=t[21],w=t[22],T=t[23];let E;t[29]!==h||t[30]!==g||t[31]!==_||t[32]!==y||t[33]!==b||t[34]!==x||t[35]!==S||t[36]!==C||t[37]!==w||t[38]!==T?(E=(0,J.jsxs)(`div`,{ref:y,role:b,"aria-label":x,"aria-activedescendant":S,tabIndex:C,onMouseDown:w,className:T,style:h,children:[g,_]}),t[29]=h,t[30]=g,t[31]=_,t[32]=y,t[33]=b,t[34]=x,t[35]=S,t[36]=C,t[37]=w,t[38]=T,t[39]=E):E=t[39];let D;t[40]!==p||t[41]!==m?(D=p?(0,J.jsx)(`aside`,{"aria-hidden":`true`,onMouseDown:u,className:`w-64 rounded-lg border bg-popover p-2 shadow-md ${m?.preview?``:`invisible`}`,children:m?.preview?(0,J.jsxs)(J.Fragment,{children:[(0,J.jsx)(`div`,{className:`mb-2 flex aspect-5/3 items-center justify-center overflow-hidden rounded-md bg-muted/40 p-3 *:max-h-full *:max-w-full [&_img]:size-full [&_img]:rounded-md [&_img]:object-contain`,children:m.preview.render()}),(0,J.jsx)(`p`,{className:`px-1 pb-1 text-xs text-muted-foreground`,children:m.preview.description})]}):null}):null,t[40]=p,t[41]=m,t[42]=D):D=t[42];let O;return t[43]!==v||t[44]!==E||t[45]!==D?(O=(0,J.jsxs)(`div`,{className:v,children:[E,D]}),t[43]=v,t[44]=E,t[45]=D,t[46]=O):O=t[46],O}function wz(e){return e.preview}function Tz(e){return e.preventDefault()}var Ez=new T(`slashCommand`),Dz=Fe.create({name:`slashCommand`,addOptions(){return{itemsSources:[()=>dT],categoryLabels:{basic:`Basic blocks`,insert:`Insert`}}},addProseMirrorPlugins(){let e=this;return[nv({editor:this.editor,pluginKey:Ez,char:`/`,startOfLine:!1,items:({query:t})=>{let n=e.options.itemsSources.flatMap(e=>{try{return e()}catch(e){return console.error(`[slash-command] item source threw an error`,e),[]}}),r=Object.keys(e.options.categoryLabels),i=e=>{let t=r.indexOf(e);return t===-1?1/0:t};return fT(n.map((e,t)=>({item:e,i:t})).sort((e,t)=>{let n=i(e.item.category)-i(t.item.category);return n===0?e.i-t.i:n}).map(e=>e.item),t)},command:({editor:e,range:t,props:n})=>{try{e.chain().focus().deleteRange(t).run()}catch(e){console.error(`[slash-command] deleteRange failed for "${n.name}"`,e);return}try{n.command(e)}catch(e){console.error(`[slash-command] command "${n.name}" threw an error`,e)}},render:()=>{let t=null,n=null,r=0,i={popup:null,stopAutoUpdate:null},a=null,o=e=>{e!==r&&(r=e,s())},s=()=>{!t||!n||t.updateProps({items:n.items,selectedIndex:r,categoryLabels:e.options.categoryLabels,onSelect:n.command,onHoverIndex:o})};return{onStart(s){n=s,r=0;let c=sv(()=>n,`slash-command`);i.popup=c.popup,a=c.doPosition,t=new fc(Cz,{props:{items:s.items,selectedIndex:r,categoryLabels:e.options.categoryLabels,onSelect:s.command,onHoverIndex:o},editor:s.editor}),c.popup.appendChild(t.element),i.stopAutoUpdate=c.startAutoUpdate(),c.reveal()},onUpdate(e){n=e,r=Math.min(r,Math.max(0,e.items.length-1)),s(),a?.()},onKeyDown({event:e}){if(!n||n.items.length===0)return!1;let t=n.items;if(e.key===`ArrowDown`)return r=(r+1)%t.length,s(),!0;if(e.key===`ArrowUp`)return r=(r-1+t.length)%t.length,s(),!0;if(e.key===`Enter`||e.key===`Tab`){let e=t[r];return e&&n.command(e),!0}return e.key,!1},onExit(){cv(i),a=null,t?.destroy(),t=null,n=null,r=0}}}})]}}),Oz=new T(`sourceDirty`),kz=Fe.create({name:`sourceDirtyObserver`,addProseMirrorPlugins(){return[new v({key:Oz,appendTransaction(e,t,n){if(!e.some(e=>!e.getMeta(_T))||!e.some(e=>e.docChanged))return null;let r=new u;for(let t of e)r.appendMapping(t.mapping);let i=r.invert(),a=[];if(n.doc.descendants((e,n)=>{if(e.type.name!==`jsxComponent`||e.attrs.sourceDirty)return;let r=i.map(n),o=t.doc.nodeAt(r),s=!o||o.type.name!==`jsxComponent`,c=typeof e.attrs.sourceRaw==`string`&&e.attrs.sourceRaw.length>0;if(s&&c)return;if(!o){(e.content.size>0||Object.keys(e.attrs.props??{}).length>0)&&a.push({pos:n});return}if(o.type.name!==`jsxComponent`){a.push({pos:n});return}let l=!Az(o.attrs.props,e.attrs.props),u=!o.content.eq(e.content);(l||u)&&a.push({pos:n})}),a.length===0)return null;let o=n.tr;for(let{pos:e}of a)o.setNodeAttribute(e,`sourceDirty`,!0);return o}})]}});function Az(e,t){if(Object.is(e,t))return!0;if(e==null||t==null||typeof e!=typeof t||typeof e!=`object`)return!1;if(Array.isArray(e)){if(!Array.isArray(t)||e.length!==t.length)return!1;for(let n=0;n<e.length;n++)if(!Az(e[n],t[n]))return!1;return!0}let n=Object.keys(e),r=Object.keys(t);if(n.length!==r.length)return!1;for(let r of n)if(!Az(e[r],t[r]))return!1;return!0}var jz=`ok:tag-click`;function Mz(e){if(typeof document>`u`)return;let t={value:e};document.dispatchEvent(new CustomEvent(jz,{detail:t}))}function Nz(e){return e instanceof Element?e.closest(`a[data-tag]`):null}var Pz=Fe.create({name:`tagClick`,addProseMirrorPlugins(){return[new v({props:{handleDOMEvents:{click(e,t){let n=Nz(t.target);if(!n)return!1;let r=n.getAttribute(`data-tag`);return r?(t.preventDefault(),t.stopPropagation(),Mz(r),!0):!1}}}})]}}),Fz={name:`Tag`,surface:`canonical`,hasChildren:!1,isSelfClosing:!0,category:`content`,description:`Inline tag`,props:[{name:`value`,type:`string`,required:!0,autoFocus:!0,description:`Tag name (without #)`}]};function Iz(e){let t=(0,Y.c)(2),{hint:n}=e,r;return t[0]===n?r=t[1]:(r=(0,J.jsx)(`span`,{className:`tag tag-placeholder inline-flex items-center rounded-sm border border-dashed border-muted-foreground/40 bg-muted/30 px-1.5 py-0.5 text-xs italic text-muted-foreground hover:bg-muted/60 cursor-pointer`,"data-component-type":`tag-placeholder`,children:n}),t[0]=n,t[1]=r),r}function Lz(e){let t=(0,Y.c)(3),{value:n}=e,r=`#tag/${n}`,i;return t[0]!==r||t[1]!==n?(i=(0,J.jsxs)(`a`,{className:`tag`,"data-tag":n,href:r,children:[`#`,n]}),t[0]=r,t[1]=n,t[2]=i):i=t[2],i}function Rz(e){let t=(0,Y.c)(31),{node:n,selected:r,getPos:i,editor:a}=e,o=typeof n.attrs.value==`string`?n.attrs.value:``,[s,c]=(0,q.useState)(!1),l=(0,q.useRef)(!1),[u,d]=(0,q.useState)(null),f,p;t[0]!==i||t[1]!==r?(f=()=>{r&&!l.current?(oT(typeof i==`function`?i()??0:0),c(!0)):!r&&l.current&&(c(!1),d(null)),l.current=r},p=[r,i],t[0]=i,t[1]=r,t[2]=f,t[3]=p):(f=t[2],p=t[3]),(0,q.useEffect)(f,p);let m=r?`tag-inline-selected`:void 0,h;t[4]===o?h=t[5]:(h=(0,J.jsx)(PA,{asChild:!0,children:(0,J.jsx)(`span`,{className:`tag-inline-trigger`,"data-component-type":`tag-inline`,children:o?(0,J.jsx)(Lz,{value:o}):(0,J.jsx)(Iz,{hint:`#tag-name`})})}),t[4]=o,t[5]=h);let g;t[6]===a.view?g=t[7]:(g=e=>{e.preventDefault(),a.view.focus()},t[6]=a.view,t[7]=g);let _;t[8]===Symbol.for(`react.memo_cache_sentinel`)?(_=(0,J.jsx)(`div`,{className:`text-xs font-medium text-muted-foreground px-3 pt-2`,children:`Tag Properties`}),t[8]=_):_=t[8];let v;t[9]===o?v=t[10]:(v={value:o},t[9]=o,t[10]=v);let y;t[11]!==a.state||t[12]!==a.view||t[13]!==i?(y=(e,t)=>{if(e!==`value`)return;let n=typeof t==`string`?t:``;if(n!==``&&!j.test(n)){d(`Tag must match ${j.source} (letter then word/-//).`);return}d(null);let r=typeof i==`function`?i():void 0;if(typeof r!=`number`)return;let o=a.state.doc.nodeAt(r);if(!o||o.type.name!==`tag`)return;let s=a.state.tr.setNodeMarkup(r,null,{...o.attrs,value:n});s.setSelection(z.create(s.doc,r)),a.view.dispatch(s)},t[11]=a.state,t[12]=a.view,t[13]=i,t[14]=y):y=t[14];let b;t[15]!==v||t[16]!==y?(b=(0,J.jsx)(lj,{descriptor:Fz,values:v,onChange:y}),t[15]=v,t[16]=y,t[17]=b):b=t[17];let x;t[18]===u?x=t[19]:(x=u?(0,J.jsx)(`div`,{className:`px-3 pb-2 text-xs text-destructive`,"data-testid":`tag-validation-error`,role:`alert`,children:u}):null,t[18]=u,t[19]=x);let S;t[20]!==x||t[21]!==g||t[22]!==b?(S=(0,J.jsxs)(FA,{className:`z-60 w-72 p-0`,side:`bottom`,align:`start`,onOpenAutoFocus:zz,onCloseAutoFocus:g,children:[_,b,x]}),t[20]=x,t[21]=g,t[22]=b,t[23]=S):S=t[23];let C;t[24]!==s||t[25]!==S||t[26]!==h?(C=(0,J.jsxs)(NA,{open:s,onOpenChange:c,children:[h,S]}),t[24]=s,t[25]=S,t[26]=h,t[27]=C):C=t[27];let w;return t[28]!==C||t[29]!==m?(w=(0,J.jsx)(oc,{as:`span`,className:m,children:C}),t[28]=C,t[29]=m,t[30]=w):w=t[30],w}function zz(e){e.preventDefault()}var Bz=V.extend({priority:200,addNodeView(){return mc(Rz)},addKeyboardShortcuts(){return{Backspace:()=>{if(lv.getState(this.editor.state)?.active)return!1;let{selection:e}=this.editor.state;if(!e.empty)return!1;let t=e.$from.nodeBefore;if(t?.type.name===`tag`){let{state:n,view:r}=this.editor;return r.dispatch(n.tr.delete(e.from-t.nodeSize,e.from)),!0}return!1},Delete:()=>{if(lv.getState(this.editor.state)?.active)return!1;let{selection:e}=this.editor.state;if(!e.empty)return!1;let t=e.$from.nodeAfter;if(t?.type.name===`tag`){let{state:n,view:r}=this.editor;return r.dispatch(n.tr.delete(e.from,e.from+t.nodeSize)),!0}return!1}}},addProseMirrorPlugins(){return[gv(this.editor)]}});function Vz(e){let t=(0,Y.c)(116),{open:n,target:r,alias:i,anchor:a,pages:o,assetPaths:s,onOpenChange:c,onSave:l}=e,[u,d]=(0,q.useState)(r),[f,p]=(0,q.useState)(i??``),[m,h]=(0,q.useState)(a??``),g=(0,q.useId)(),_=(0,q.useId)(),v=(0,q.useId)(),y=(0,q.useId)(),b;t[0]!==s||t[1]!==u?(b=dC(u,s),t[0]=s,t[1]=u,t[2]=b):b=t[2];let x=b,S;t[3]!==s||t[4]!==u||t[5]!==o?(S=fC(u,o,s),t[3]=s,t[4]=u,t[5]=o,t[6]=S):S=t[6];let C=gA(u,S&&!x&&n),w,T;t[7]!==i||t[8]!==a||t[9]!==n||t[10]!==r?(w=()=>{n&&(d(r),p(i??``),h(a??``))},T=[n,r,i,a],t[7]=i,t[8]=a,t[9]=n,t[10]=r,t[11]=w,t[12]=T):(w=t[11],T=t[12]),(0,q.useEffect)(w,T);let E;t[13]!==f||t[14]!==m||t[15]!==u||t[16]!==c||t[17]!==l?(E=function(){let e=u.trim();e&&(l(e,f.trim()||null,m.trim()||null),c(!1))},t[13]=f,t[14]=m,t[15]=u,t[16]=c,t[17]=l,t[18]=E):E=t[18];let D=E,O;t[19]===D?O=t[20]:(O=function(e){e.key===`Enter`&&D()},t[19]=D,t[20]=O);let k=O,A,j,M,N,P,F,I,L,R,z,B,V,H,U,W,ee;if(t[21]!==_||t[22]!==m||t[23]!==u||t[24]!==k||t[25]!==y||t[26]!==C||t[27]!==c||t[28]!==n||t[29]!==g){let e=new Map,r=C?.map(t=>{let n=e.get(t.slug)??0;e.set(t.slug,n+1);let r=n===0?t.slug:`${t.slug}-${n}`;return{...t,reactKey:r}}),i=!!r?.length;M=Qt,V=n,H=c,j=tn,t[46]===Symbol.for(`react.memo_cache_sentinel`)?(B=(0,J.jsx)(an,{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[46]=B):B=t[46],A=Yt,F=`dialog-content`,I=``,L=`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`,t[47]===Symbol.for(`react.memo_cache_sentinel`)?(R=(0,J.jsx)(Zt,{className:`mb-1 text-base font-semibold`,children:`Edit wiki link`}),z=(0,J.jsx)(Xt,{className:`mb-4 text-sm text-muted-foreground`,children:`Modify the link target, anchor, and display label.`}),t[47]=R,t[48]=z):(R=t[47],z=t[48]),N=`mb-4 space-y-6`;let a;t[49]===Symbol.for(`react.memo_cache_sentinel`)?(a=(0,J.jsx)(`span`,{className:`text-red-500`,children:`*`}),t[49]=a):a=t[49];let o;t[50]===g?o=t[51]:(o=(0,J.jsxs)(`label`,{className:`mb-1.5 block text-sm font-medium`,htmlFor:g,children:[`Page `,a]}),t[50]=g,t[51]=o);let s;t[52]===Symbol.for(`react.memo_cache_sentinel`)?(s=e=>d(e.target.value),t[52]=s):s=t[52];let l;t[53]!==u||t[54]!==k||t[55]!==g?(l=(0,J.jsx)(zo,{id:g,value:u,onChange:s,placeholder:`page-name`,autoFocus:!0,"aria-required":`true`,onKeyDown:k}),t[53]=u,t[54]=k,t[55]=g,t[56]=l):l=t[56],t[57]!==o||t[58]!==l?(P=(0,J.jsxs)(`div`,{children:[o,l]}),t[57]=o,t[58]=l,t[59]=P):P=t[59];let f;t[60]===Symbol.for(`react.memo_cache_sentinel`)?(f=(0,J.jsx)(`span`,{className:`font-normal text-muted-foreground`,children:`(optional heading anchor)`}),t[60]=f):f=t[60],t[61]===_?U=t[62]:(U=(0,J.jsxs)(`label`,{className:`mb-1.5 block text-sm font-medium`,htmlFor:_,children:[`Section`,` `,f]}),t[61]=_,t[62]=U);let p;t[63]===Symbol.for(`react.memo_cache_sentinel`)?(p=e=>h(e.target.value),t[63]=p):p=t[63],t[64]!==_||t[65]!==m||t[66]!==k?(W=(0,J.jsx)(zo,{id:_,value:m,onChange:p,placeholder:`heading-slug`,onKeyDown:k}),t[64]=_,t[65]=m,t[66]=k,t[67]=W):W=t[67],ee=i&&(0,J.jsx)(`div`,{role:`listbox`,id:y,"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:r.map(e=>(0,J.jsxs)(`button`,{type:`button`,role:`option`,"aria-selected":m===e.slug,className:Lt(`flex w-full items-center gap-2 px-2 py-1 text-left text-sm hover:bg-accent hover:text-accent-foreground`,m===e.slug&&`bg-accent text-accent-foreground`),style:{paddingLeft:`${(e.level-1)*12+8}px`},onClick:()=>h(m===e.slug?``:e.slug),children:[(0,J.jsxs)(`span`,{className:`w-7 shrink-0 font-mono text-[10px] text-muted-foreground`,children:[`H`,e.level]}),(0,J.jsx)(`span`,{className:`truncate`,children:e.text})]},e.reactKey))}),t[21]=_,t[22]=m,t[23]=u,t[24]=k,t[25]=y,t[26]=C,t[27]=c,t[28]=n,t[29]=g,t[30]=A,t[31]=j,t[32]=M,t[33]=N,t[34]=P,t[35]=F,t[36]=I,t[37]=L,t[38]=R,t[39]=z,t[40]=B,t[41]=V,t[42]=H,t[43]=U,t[44]=W,t[45]=ee}else A=t[30],j=t[31],M=t[32],N=t[33],P=t[34],F=t[35],I=t[36],L=t[37],R=t[38],z=t[39],B=t[40],V=t[41],H=t[42],U=t[43],W=t[44],ee=t[45];let te;t[68]!==U||t[69]!==W||t[70]!==ee?(te=(0,J.jsxs)(`div`,{children:[U,W,ee]}),t[68]=U,t[69]=W,t[70]=ee,t[71]=te):te=t[71];let ne;t[72]===Symbol.for(`react.memo_cache_sentinel`)?(ne=(0,J.jsx)(`span`,{className:`font-normal text-muted-foreground`,children:`(optional display text)`}),t[72]=ne):ne=t[72];let re;t[73]===v?re=t[74]:(re=(0,J.jsxs)(`label`,{className:`mb-1.5 block text-sm font-medium`,htmlFor:v,children:[`Label`,` `,ne]}),t[73]=v,t[74]=re);let ie;t[75]===Symbol.for(`react.memo_cache_sentinel`)?(ie=e=>p(e.target.value),t[75]=ie):ie=t[75];let ae;t[76]!==v||t[77]!==f||t[78]!==k?(ae=(0,J.jsx)(zo,{id:v,value:f,onChange:ie,placeholder:`Custom display text`,onKeyDown:k}),t[76]=v,t[77]=f,t[78]=k,t[79]=ae):ae=t[79];let oe;t[80]!==re||t[81]!==ae?(oe=(0,J.jsxs)(`div`,{children:[re,ae]}),t[80]=re,t[81]=ae,t[82]=oe):oe=t[82];let se;t[83]!==N||t[84]!==P||t[85]!==te||t[86]!==oe?(se=(0,J.jsxs)(`div`,{className:N,children:[P,te,oe]}),t[83]=N,t[84]=P,t[85]=te,t[86]=oe,t[87]=se):se=t[87];let ce;t[88]===c?ce=t[89]:(ce=(0,J.jsx)(zt,{variant:`outline`,onClick:()=>c(!1),children:`Cancel`}),t[88]=c,t[89]=ce);let le;t[90]===u?le=t[91]:(le=u.trim(),t[90]=u,t[91]=le);let ue=!le,de;t[92]!==D||t[93]!==ue?(de=(0,J.jsx)(zt,{onClick:D,disabled:ue,children:`Save`}),t[92]=D,t[93]=ue,t[94]=de):de=t[94];let fe;t[95]!==ce||t[96]!==de?(fe=(0,J.jsxs)(`div`,{className:`flex justify-end gap-2`,children:[ce,de]}),t[95]=ce,t[96]=de,t[97]=fe):fe=t[97];let pe;t[98]!==A||t[99]!==F||t[100]!==I||t[101]!==L||t[102]!==R||t[103]!==z||t[104]!==se||t[105]!==fe?(pe=(0,J.jsxs)(A,{"data-slot":F,"data-ok-layer-spawned":I,className:L,children:[R,z,se,fe]}),t[98]=A,t[99]=F,t[100]=I,t[101]=L,t[102]=R,t[103]=z,t[104]=se,t[105]=fe,t[106]=pe):pe=t[106];let me;t[107]!==j||t[108]!==B||t[109]!==pe?(me=(0,J.jsxs)(j,{children:[B,pe]}),t[107]=j,t[108]=B,t[109]=pe,t[110]=me):me=t[110];let he;return t[111]!==M||t[112]!==V||t[113]!==H||t[114]!==me?(he=(0,J.jsx)(M,{open:V,onOpenChange:H,children:me}),t[111]=M,t[112]=V,t[113]=H,t[114]=me,t[115]=he):he=t[115],he}function Hz(e){let t=(0,Y.c)(135),{editor:n,getPos:r,onClose:i}=e,a=r(),o=a==null?null:n.state.doc.nodeAt(a),s=String(o?.attrs.target??``),c=pe(o?.attrs.alias),l=pe(o?.attrs.anchor),u=Ue({target:s,alias:c,anchor:l}),{assetPaths:d,folderPaths:f,pages:p,pagesBySlug:m,loading:h}=we(),g=rt(s,l),_=g?.kind===`external`?g:null,v=g?.kind===`asset`?dC(g.url,d):null,y=v?null:kk(s,{pages:p,folderPaths:f,pagesBySlug:m,fallbackTargets:lC(s)}),[b,x]=(0,q.useState)(!1),[S,C]=(0,q.useState)(null),w=y?Ak(y):null;if(!o)return null;let T;t[0]!==n.state||t[1]!==n.view||t[2]!==r?(T=function(e,t,i){let a=r();a!=null&&n.view.dispatch(n.state.tr.setNodeMarkup(a,void 0,{...n.state.doc.nodeAt(a)?.attrs,target:e,alias:t,anchor:i}))},t[0]=n.state,t[1]=n.view,t[2]=r,t[3]=T):T=t[3];let E=T,D;t[4]!==n.state||t[5]!==n.view||t[6]!==r||t[7]!==i?(D=function(){let e=r();if(e==null)return;let t=n.state.doc.nodeAt(e);t&&(n.view.dispatch(n.state.tr.delete(e,e+t.nodeSize)),i())},t[4]=n.state,t[5]=n.view,t[6]=r,t[7]=i,t[8]=D):D=t[8];let O=D,k;t[9]!==l||t[10]!==v||t[11]!==_||t[12]!==y||t[13]!==C?(k=function(e){if(_){pk(_.url)?window.open(_.url,`_blank`,`noopener,noreferrer`):console.warn(`[safe-nav] blocked non-safe scheme:`,_.url);return}if(v){let t=ot(v);e.newTab?window.open(t,`_blank`,`noopener,noreferrer`):window.location.hash=t;return}if(!y)return;if(y.kind===`create`){C(`missing`);return}let t=y.hashDocName;if(e.newTab){yk({docName:t,anchor:l});return}if(l){let e=window.location.hash.match(/^#\/([^?#/]+)/);if((e?decodeURIComponent(e[1]):null)===t){let e=document.getElementById(l);e&&e.scrollIntoView({behavior:`smooth`,block:`start`})}window.location.hash=`#/${t}?anchor=${encodeURIComponent(l)}`;return}window.location.hash=`#/${t}`},t[9]=l,t[10]=v,t[11]=_,t[12]=y,t[13]=C,t[14]=k):k=t[14];let A=k,j;t[15]!==c||t[16]!==S||t[17]!==n.state||t[18]!==n.view||t[19]!==r||t[20]!==u||t[21]!==s?(j=function(e){if(S===`missing`&&e!==s){let t=r();if(t==null)return;n.view.dispatch(n.state.tr.setNodeMarkup(t,void 0,{...n.state.doc.nodeAt(t)?.attrs,target:e,alias:c??u}))}},t[15]=c,t[16]=S,t[17]=n.state,t[18]=n.view,t[19]=r,t[20]=u,t[21]=s,t[22]=j):j=t[22];let M=j,N=!_&&!h&&v!==null,P=!_&&!h&&y?.kind===`navigate`&&y.displayState===`resolved`,F=!_&&!h&&y?.kind===`navigate`&&y.displayState===`folder`,I=!_&&!h&&!v&&y?.kind===`create`,L,R,z,B,V,H,U,W,ee,te;if(t[23]!==n.state||t[24]!==n.view||t[25]!==_||t[26]!==r||t[27]!==N||t[28]!==F||t[29]!==P||t[30]!==I||t[31]!==h||t[32]!==i){if(h){let e;t[43]===Symbol.for(`react.memo_cache_sentinel`)?(e=(0,J.jsx)(Rr,{className:`size-3.5 shrink-0 animate-spin`,"aria-hidden":`true`}),t[43]=e):e=t[43],R={icon:e,text:`Loading…`,className:`text-muted-foreground`}}else if(_){let e;t[44]===Symbol.for(`react.memo_cache_sentinel`)?(e=(0,J.jsx)(Sr,{className:`size-3.5 shrink-0`,"aria-hidden":`true`}),t[44]=e):e=t[44],R={icon:e,text:`External wiki link`,className:`text-foreground`}}else if(N){let e;t[45]===Symbol.for(`react.memo_cache_sentinel`)?(e=(0,J.jsx)(Cr,{className:`size-3.5 shrink-0`,"aria-hidden":`true`}),t[45]=e):e=t[45],R={icon:e,text:`Asset`,className:`text-foreground`}}else if(F){let e;t[46]===Symbol.for(`react.memo_cache_sentinel`)?(e=(0,J.jsx)(Dr,{className:`size-3.5 shrink-0`,"aria-hidden":`true`}),t[46]=e):e=t[46],R={icon:e,text:`Folder (no index)`,className:`text-foreground`}}else if(I){let e;t[47]===Symbol.for(`react.memo_cache_sentinel`)?(e=(0,J.jsx)(_r,{className:`size-3.5 shrink-0`,"aria-hidden":`true`}),t[47]=e):e=t[47],R={icon:e,text:`Page not found`,className:`text-red-700 dark:text-red-300`}}else if(P){let e;t[48]===Symbol.for(`react.memo_cache_sentinel`)?(e=(0,J.jsx)(Tr,{className:`size-3.5 shrink-0`,"aria-hidden":`true`}),t[48]=e):e=t[48],R={icon:e,text:`Wiki link`,className:`text-foreground`}}else{let e;t[49]===Symbol.for(`react.memo_cache_sentinel`)?(e=(0,J.jsx)(_r,{className:`size-3.5 shrink-0`,"aria-hidden":`true`}),t[49]=e):e=t[49],R={icon:e,text:`Unrecognized wiki link`,className:`text-muted-foreground`}}let e;t[50]!==n.state||t[51]!==n.view||t[52]!==r?(e=()=>{let e=r();if(typeof e!=`number`)return new DOMRect;let t=n.state.doc.nodeAt(e);if(!t)return new DOMRect;try{return He(n.view,e,e+t.nodeSize)}catch{return new DOMRect}},t[50]=n.state,t[51]=n.view,t[52]=r,t[53]=e):e=t[53];let a;t[54]!==n.view.dom||t[55]!==e?(a={getBoundingClientRect:e,contextElement:n.view.dom},t[54]=n.view.dom,t[55]=e,t[56]=a):a=t[56];let o=a;L=Dk,te=`wiki-link`,z=`Wiki link options`,B=i,V=o,W=`mb-2 flex items-start gap-2 pr-8`,ee=(0,J.jsx)(`div`,{className:Lt(`mt-0.5 flex shrink-0`,R.className),children:R.icon}),U=`flex-1 min-w-0`,H=Lt(`text-sm font-medium`,R.className),t[23]=n.state,t[24]=n.view,t[25]=_,t[26]=r,t[27]=N,t[28]=F,t[29]=P,t[30]=I,t[31]=h,t[32]=i,t[33]=L,t[34]=R,t[35]=z,t[36]=B,t[37]=V,t[38]=H,t[39]=U,t[40]=W,t[41]=ee,t[42]=te}else L=t[33],R=t[34],z=t[35],B=t[36],V=t[37],H=t[38],U=t[39],W=t[40],ee=t[41],te=t[42];let ne;t[57]!==R.text||t[58]!==H?(ne=(0,J.jsx)(`div`,{className:H,children:R.text}),t[57]=R.text,t[58]=H,t[59]=ne):ne=t[59];let re=v??(_?_.url:`${s}${l?`#${l}`:``}`),ie=v??(_?_.url:`${s}${l?`#${l}`:``}`),ae;t[60]!==re||t[61]!==ie?(ae=(0,J.jsx)(`div`,{className:`truncate font-mono text-xs text-muted-foreground`,title:re,children:ie}),t[60]=re,t[61]=ie,t[62]=ae):ae=t[62];let oe;t[63]!==ne||t[64]!==ae||t[65]!==U?(oe=(0,J.jsxs)(`div`,{className:U,children:[ne,ae]}),t[63]=ne,t[64]=ae,t[65]=U,t[66]=oe):oe=t[66];let se;t[67]!==oe||t[68]!==W||t[69]!==ee?(se=(0,J.jsxs)(`div`,{className:W,children:[ee,oe]}),t[67]=oe,t[68]=W,t[69]=ee,t[70]=se):se=t[70];let ce;t[71]!==_||t[72]!==A||t[73]!==I||t[74]!==i?(ce=I?null:(0,J.jsx)(zt,{size:`sm`,variant:`default`,onClick:()=>{A({}),i()},children:_?`Open in new tab`:`Open`}),t[71]=_,t[72]=A,t[73]=I,t[74]=i,t[75]=ce):ce=t[75];let le;t[76]!==I||t[77]!==C?(le=I?(0,J.jsx)(zt,{size:`sm`,variant:`default`,onClick:()=>C(`missing`),children:`Create page`}):null,t[76]=I,t[77]=C,t[78]=le):le=t[78];let ue;t[79]!==w||t[80]!==F||t[81]!==C?(ue=F&&w?(0,J.jsxs)(zt,{size:`sm`,variant:`outline`,onClick:()=>C(`folder-index`),children:[(0,J.jsx)(wr,{className:`size-3.5`,"aria-hidden":`true`}),`Create index`]}):null,t[79]=w,t[80]=F,t[81]=C,t[82]=ue):ue=t[82];let de;t[83]===Symbol.for(`react.memo_cache_sentinel`)?(de=(0,J.jsx)(`div`,{className:`flex-1`}),t[83]=de):de=t[83];let fe;t[84]===x?fe=t[85]:(fe=()=>x(!0),t[84]=x,t[85]=fe);let me;t[86]===Symbol.for(`react.memo_cache_sentinel`)?(me=(0,J.jsx)(Ur,{className:`size-3.5`,"aria-hidden":`true`}),t[86]=me):me=t[86];let he;t[87]===fe?he=t[88]:(he=(0,J.jsxs)(zt,{size:`sm`,variant:`outline`,onClick:fe,children:[me,`Edit`]}),t[87]=fe,t[88]=he);let ge;t[89]===I?ge=t[90]:(ge=I?(0,J.jsx)(Zr,{className:`size-3.5`,"aria-hidden":`true`}):(0,J.jsx)(Xr,{className:`size-3.5`,"aria-hidden":`true`}),t[89]=I,t[90]=ge);let _e=I?`Unlink`:`Remove`,ve;t[91]!==O||t[92]!==ge||t[93]!==_e?(ve=(0,J.jsxs)(zt,{size:`sm`,variant:`destructive`,onClick:O,children:[ge,_e]}),t[91]=O,t[92]=ge,t[93]=_e,t[94]=ve):ve=t[94];let ye;t[95]!==ce||t[96]!==le||t[97]!==ue||t[98]!==he||t[99]!==ve?(ye=(0,J.jsxs)(`div`,{className:`flex flex-wrap items-center gap-1.5`,children:[ce,le,ue,de,he,ve]}),t[95]=ce,t[96]=le,t[97]=ue,t[98]=he,t[99]=ve,t[100]=ye):ye=t[100];let be;t[101]!==L||t[102]!==z||t[103]!==B||t[104]!==V||t[105]!==se||t[106]!==ye||t[107]!==te?(be=(0,J.jsxs)(L,{kind:te,ariaLabel:z,onDeactivate:B,triggerReference:V,children:[se,ye]}),t[101]=L,t[102]=z,t[103]=B,t[104]=V,t[105]=se,t[106]=ye,t[107]=te,t[108]=be):be=t[108];let xe=S!==null,Se;t[109]===C?Se=t[110]:(Se=e=>{e||C(null)},t[109]=C,t[110]=Se);let Ce=S===`folder-index`&&w?w.initialDir:y?.kind===`create`?y.initialDir:``,Te=S===`folder-index`&&w?w.suggestedName:y?.kind===`create`?y.suggestedName:void 0,Ee;t[111]!==S||t[112]!==w||t[113]!==s?(Ee=S===`folder-index`&&w?(0,J.jsxs)(J.Fragment,{children:[`Create an index note for`,` `,(0,J.jsxs)(`span`,{className:`font-medium text-foreground`,children:[w.initialDir,`/`]})]}):(0,J.jsxs)(J.Fragment,{children:[`Create a page for `,(0,J.jsx)(`span`,{className:`font-medium text-foreground`,children:s})]}),t[111]=S,t[112]=w,t[113]=s,t[114]=Ee):Ee=t[114];let De;t[115]!==M||t[116]!==xe||t[117]!==Se||t[118]!==Ce||t[119]!==Te||t[120]!==Ee?(De=(0,J.jsx)(wv,{open:xe,onOpenChange:Se,kind:`file`,initialDir:Ce,suggestedName:Te,description:Ee,onCreated:M}),t[115]=M,t[116]=xe,t[117]=Se,t[118]=Ce,t[119]=Te,t[120]=Ee,t[121]=De):De=t[121];let Oe;t[122]!==c||t[123]!==l||t[124]!==d||t[125]!==b||t[126]!==E||t[127]!==p||t[128]!==x||t[129]!==s?(Oe=(0,J.jsx)(Vz,{open:b,target:s,alias:c,anchor:l,pages:p,assetPaths:d,onOpenChange:x,onSave:E}),t[122]=c,t[123]=l,t[124]=d,t[125]=b,t[126]=E,t[127]=p,t[128]=x,t[129]=s,t[130]=Oe):Oe=t[130];let ke;return t[131]!==be||t[132]!==De||t[133]!==Oe?(ke=(0,J.jsxs)(J.Fragment,{children:[be,De,Oe]}),t[131]=be,t[132]=De,t[133]=Oe,t[134]=ke):ke=t[134],ke}var Uz=0;function Wz(){return`wiki-link-${++Uz}`}function Gz(e){let t=e.doc??(typeof document<`u`?document:{createElement:null,createTextNode:null}),n=t.createElement(`span`);n.setAttribute(`data-wiki-link`,``),n.setAttribute(`data-node-id`,e.nodeId),n.setAttribute(`data-target`,e.target),n.setAttribute(`data-alias`,e.alias??``),n.setAttribute(`data-anchor`,e.anchor??``),n.setAttribute(`contenteditable`,`false`),n.setAttribute(`role`,`button`),n.setAttribute(`tabindex`,`0`),n.setAttribute(`aria-label`,`Wiki link: ${e.target}${e.anchor?`#${e.anchor}`:``}`),n.classList.add(`wiki-link-chip`),n.style.touchAction=`manipulation`;let r=e.alias??`${e.target}${e.anchor?`#${e.anchor}`:``}`,i=t.createTextNode(r);return n.appendChild(i),{dom:n}}var Kz=dt.extend({priority:200,addOptions(){return{...this.parent?.(),docName:``}},addNodeView(){return({editor:e,node:t,getPos:n})=>{let r=Wz(),{dom:i}=Gz({nodeId:r,target:String(t.attrs.target??``),alias:t.attrs.alias==null?null:String(t.attrs.alias),anchor:t.attrs.anchor==null?null:String(t.attrs.anchor)}),a=t,o=()=>{let e=n();return typeof e==`number`?e:void 0},s=zk(e);return s.register({type:`wikiLink`,nodeId:r,getPos:o,controls:{propPanel:t=>(0,q.createElement)(Hz,{editor:e,getPos:o,onClose:t.deactivate})},handlePrimary:({newTab:e})=>{let t=a.attrs,n=typeof t.target==`string`?t.target:``;if(!n)return!1;let r=rt(n,typeof t.anchor==`string`?t.anchor:null);if(!r)return!1;if(r.kind===`doc`)return e?(yk({docName:r.docName,anchor:r.anchor}),!0):!1;if(r.kind===`asset`){let t=dC(r.url,Le()?.assetPaths??new Set)??r.url.replace(/^\//,``);return e?_k(ot(t)):window.location.hash=ot(t),!0}return!e||!pk(r.url)?!1:(_k(r.url),!0)}}),{dom:i,ignoreMutation:()=>!0,update:e=>{if(e.type.name!==`wikiLink`)return!1;a=e;let t=String(e.attrs.target??``),n=e.attrs.alias==null?null:String(e.attrs.alias),r=e.attrs.anchor==null?null:String(e.attrs.anchor);return i.setAttribute(`data-target`,t),i.setAttribute(`data-alias`,n??``),i.setAttribute(`data-anchor`,r??``),i.setAttribute(`aria-label`,`Wiki link: ${t}${r?`#${r}`:``}`),i.textContent=n??`${t}${r?`#${r}`:``}`,!0},destroy:()=>{s.deregister(r)}}}},addKeyboardShortcuts(){return{Backspace:()=>{if(eA.getState(this.editor.state)?.active)return!1;let{selection:e}=this.editor.state;if(!e.empty)return!1;let t=e.$from.nodeBefore;if(t?.type.name===`wikiLink`){let{state:n,view:r}=this.editor;return r.dispatch(n.tr.delete(e.from-t.nodeSize,e.from)),!0}return!1},Delete:()=>{if(eA.getState(this.editor.state)?.active)return!1;let{selection:e}=this.editor.state;if(!e.empty)return!1;let t=e.$from.nodeAfter;if(t?.type.name===`wikiLink`){let{state:n,view:r}=this.editor;return r.dispatch(n.tr.delete(e.from,e.from+t.nodeSize)),!0}return!1}}},addProseMirrorPlugins(){return[hA(this.editor)]}}),qz=0;function Jz(){return`wiki-link-embed-${++qz}`}function Yz(e){let t=e.doc??(typeof document<`u`?document:{createElement:null,createTextNode:null}),n=t.createElement(`a`);n.setAttribute(`data-wiki-embed`,``),n.setAttribute(`data-node-id`,e.nodeId),n.setAttribute(`data-target`,e.target),n.setAttribute(`data-alias`,e.alias??``),n.setAttribute(`data-anchor`,e.anchor??``),n.setAttribute(`href`,e.href),n.setAttribute(`target`,`_blank`),n.setAttribute(`rel`,`noopener noreferrer`),n.setAttribute(`contenteditable`,`false`),n.setAttribute(`role`,`button`),n.setAttribute(`tabindex`,`0`),n.setAttribute(`aria-label`,`Embed: ${e.target}${e.anchor?`#${e.anchor}`:``}`),n.classList.add(`wiki-link-embed-chip`),n.style.touchAction=`manipulation`;let r=e.alias??`${e.target}${e.anchor?`#${e.anchor}`:``}`,i=t.createTextNode(r);return n.appendChild(i),{dom:n}}function Xz(e){let t=(e.doc??(typeof document<`u`?document:{createElement:null})).createElement(`img`);return t.setAttribute(`data-wiki-embed`,``),t.setAttribute(`data-node-id`,e.nodeId),t.setAttribute(`data-target`,e.target),t.setAttribute(`data-alias`,e.alias??``),t.setAttribute(`src`,e.src),t.setAttribute(`alt`,e.alias??e.target),{dom:t}}function Zz(e){let t=vt(e);return t!==null&&l.has(t)}var Qz=Ze.extend({addNodeView(){return({editor:e,node:t,getPos:n})=>{let r=Jz(),i=t,a=String(t.attrs.target??``),o=t.attrs.alias==null?null:String(t.attrs.alias),s=t.attrs.anchor==null?null:String(t.attrs.anchor),c=t.attrs.resolvedSrc==null?null:String(t.attrs.resolvedSrc);if(Zz(a)){let{dom:e}=Xz({nodeId:r,target:a,alias:o,src:c??a});return{dom:e,ignoreMutation:()=>!0,update:t=>{if(t.type.name!==`wikiLinkEmbed`)return!1;i=t;let n=String(t.attrs.target??``),r=t.attrs.alias==null?null:String(t.attrs.alias),a=t.attrs.resolvedSrc==null?null:String(t.attrs.resolvedSrc);if(!Zz(n))return!1;let o=a??n;return e.setAttribute(`data-target`,n),e.setAttribute(`data-alias`,r??``),e.setAttribute(`src`,o),e.setAttribute(`alt`,r??n),!0}}}let{dom:l}=Yz({nodeId:r,target:a,alias:o,anchor:s,href:c??a});l.addEventListener(`click`,e=>{e.preventDefault()});let u=()=>{let e=n();return typeof e==`number`?e:void 0},d=zk(e);return d.register({type:`wikiLinkEmbed`,nodeId:r,getPos:u,controls:{},handlePrimary:({newTab:e})=>{let t=i.attrs,n=typeof t.target==`string`?t.target:``;if(!n)return!1;let r=(typeof t.resolvedSrc==`string`&&t.resolvedSrc.length>0?t.resolvedSrc:null)??n,a=vt(n);if(a===null)return!1;let o=Oe(r,``)??n;return dk({url:r,projectRelPath:o,ext:a,title:o.split(`/`).pop()??r,forceOsDelegation:e}),!0}}),{dom:l,ignoreMutation:()=>!0,update:e=>{if(e.type.name!==`wikiLinkEmbed`)return!1;i=e;let t=String(e.attrs.target??``);if(Zz(t))return!1;let n=e.attrs.alias==null?null:String(e.attrs.alias),r=e.attrs.anchor==null?null:String(e.attrs.anchor),a=(e.attrs.resolvedSrc==null?null:String(e.attrs.resolvedSrc))??t;return l.setAttribute(`data-target`,t),l.setAttribute(`data-alias`,n??``),l.setAttribute(`data-anchor`,r??``),l.setAttribute(`href`,a),l.setAttribute(`aria-label`,`Embed: ${t}${r?`#${r}`:``}`),l.textContent=n??`${t}${r?`#${r}`:``}`,!0},destroy:()=>{d.deregister(r)}}}}}),$z=[...Ye.map(e=>e.name===`jsxComponent`?uM:e.name===`rawMdxFallback`?Sz:e.name===`wikiLink`?Kz:e.name===`wikiLinkEmbed`?Qz:e.name===`link`?OA:e.name===`mathInline`?vM:e.name===`tag`?Bz:e),Dz.configure({itemsSources:[()=>dT,lT,uT],categoryLabels:{content:`Components`,layout:`Layout`,media:`Media`,data:`Data`}}),$S.configure({onDrop(e,t,n){for(let r of t)CC(r,e,n)},onPaste(e,t,n){for(let n of t)CC(n,e,e.state.selection.from)}}),ck,Pz,sk,ak,gT,kz,eC,ST,kj,Fe.create({name:`chunkWrapperDecoration`,addProseMirrorPlugins(){return[OT()]}})];function eB(e){return e===de}var tB=3e4,nB=class extends Error{docName;elapsedMs;constructor(e,t){super(`Sync timed out for "${e}" after ${t}ms`),this.name=`SyncTimeoutError`,this.docName=e,this.elapsedMs=t}},rB=class extends Error{docName;constructor(e){super(`Provider disconnected before sync for "${e}"`),this.name=`PreSyncDisconnectError`,this.docName=e}},iB=class extends Error{docName;constructor(e){super(`Document not found: "${e}"`),this.name=`DocumentNotFoundError`,this.docName=e}},aB=class extends Error{docName;cause;constructor(e,t){let n=t instanceof Error?t.message:String(t??`unknown`);super(`Bridge setup failed for "${e}": ${n}`),this.name=`BridgeSetupError`,this.docName=e,this.cause=t}},oB=class extends Error{docName;missingCapability;constructor(e,t){super(`Server is missing capability "${t}" required to open "${e}".`),this.name=`ServerCapabilityMismatchError`,this.docName=e,this.missingCapability=t}},sB=new Map,cB=!1;function lB(){for(let e of sB.values())if(!e.settled)return!0;return!1}function uB(){typeof document>`u`||document.visibilityState===`visible`&&dB(Date.now())}function dB(e){let t=[];for(let[n,r]of sB){if(r.settled)continue;let i=e-r.createdAt;if(i<3e4)continue;r.settled=!0;let a=new nB(n,i);hB(r),r.reject(a),t.push({docName:n,elapsedMs:i})}if(t.length>0){let e=t.map(e=>`${e.docName} (${e.elapsedMs}ms)`).join(`, `);console.warn(`[syncPromise] reaped ${t.length} timed-out ${t.length===1?`entry`:`entries`} on visibility restore (tab-sleep recovered): ${e}`)}return lB()||pB(),t.length}function fB(){cB||typeof document>`u`||(document.addEventListener(`visibilitychange`,uB),cB=!0)}function pB(){cB&&(typeof document>`u`||(document.removeEventListener(`visibilitychange`,uB),cB=!1))}var mB=new Map;function hB(e){e.detached||(e.detached=!0,e.timeoutHandle!==null&&clearTimeout(e.timeoutHandle),e.provider.off(`synced`,e.onSynced),e.provider.off(`close`,e.onClose))}function gB(e,t){let n=sB.get(e);if(n)return n.promise;let r=mB.get(e);if(r!==void 0){mB.delete(e);let n=r===`timeout`?new nB(e,0):new rB(e);console.warn(`[syncPromise] ${e} rejected on creation (test hook, armed ${r}): ${n.message}`),X(`ok/sync/create`,{docName:e,warm:!1,armed:r}),X(`ok/sync/reject`,{docName:e,reason:`armed-${r}`});let i=vB(n);return sB.set(e,yB(i,t)),i}if(t.synced){console.log(`[syncPromise] ${e} resolved synchronously (warm provider)`),X(`ok/sync/create`,{docName:e,warm:!0}),X(`ok/sync/resolve`,{docName:e,elapsedMs:0,warm:!0});let n=Promise.resolve();return sB.set(e,_B(n,t)),n}let i=Date.now(),a=()=>{},o=()=>{},s=new Promise((e,t)=>{a=e,o=t}),c=()=>{let t=sB.get(e);if(!t||t.settled)return;t.settled=!0;let n=Date.now()-t.createdAt;console.log(`[syncPromise] ${e} resolved in ${n}ms`),X(`ok/sync/resolve`,{docName:e,elapsedMs:n,warm:!1}),hB(t),lB()||pB(),t.resolve()},l=t=>{let n=sB.get(e);if(!n||n.settled)return;n.settled=!0;let r=new rB(e);console.warn(`[syncPromise] ${e} rejected: ${r.message}`),X(`ok/sync/reject`,{docName:e,reason:`pre-sync-disconnect`}),hB(n),lB()||pB(),n.reject(r)},u=setTimeout(()=>{let t=sB.get(e);if(!t||t.settled)return;t.settled=!0;let n=Date.now()-t.createdAt,r=new nB(e,n);console.warn(`[syncPromise] ${e} rejected: ${r.message}`),X(`ok/sync/reject`,{docName:e,reason:`timeout`,elapsedMs:n}),hB(t),lB()||pB(),t.reject(r)},tB),d={promise:s,resolve:a,reject:o,createdAt:i,timeoutHandle:u,provider:t,onSynced:c,onClose:l,settled:!1,detached:!1};return sB.set(e,d),t.on(`synced`,c),t.on(`close`,l),fB(),X(`ok/sync/create`,{docName:e,warm:!1}),s}function _B(e,t){return{promise:e,resolve:()=>{},reject:()=>{},createdAt:Date.now(),timeoutHandle:null,provider:t,onSynced:()=>{},onClose:()=>{},settled:!0,detached:!0}}function vB(e){let t=Promise.reject(e);t.catch(()=>{});let n=t;return n.status=`rejected`,n.reason=e,n}function yB(e,t){return{promise:e,resolve:()=>{},reject:()=>{},createdAt:Date.now(),timeoutHandle:null,provider:t,onSynced:()=>{},onClose:()=>{},settled:!0,detached:!0}}function bB(e){let t=sB.get(e);t&&(t.settled=!0,hB(t),sB.delete(e),lB()||pB())}function xB(e,t){let n=sB.get(e);return!n||n.settled?!1:(n.settled=!0,console.warn(`[syncPromise] ${e} rejected: ${t.message}`),hB(n),lB()||pB(),n.reject(t),!0)}var SB=Object.freeze({kind:`tab-replay`}),CB=Object.freeze({kind:`idle`});function wB(e,t){return()=>{}}var TB=te($z),EB=4e3,DB=1e4,OB=class extends Error{constructor(e,t){super(`client persistence clearData timed out for ${e} after ${t}ms`),this.docName=e,this.timeoutMs=t,this.name=`ClientPersistenceClearTimeoutError`}},kB=`ok-last-observed-branch`,AB=5e3,jB=1*1024*1024,MB=Qv(`MAX_POOL`,10);function NB(e,t,n=null){let r={};if(e!==null&&(r.principalId=e.principalId,r.tabSessionId=e.tabSessionId),t!==null&&t.length>0&&(r.expectedServerInstanceId=t),n!==null&&n.length>0&&(r.expectedBranch=n),Object.keys(r).length!==0)return JSON.stringify(r)}var PB=class{_entries=new Map;get entries(){return this._entries}lruOrder=[];activeDocName=null;maxSize;wsUrl;recycleDebounceMs;clearDataTimeoutMs;onChange=null;tabIdentity=null;serverRestartRecoveryState=CB;cachedServerInstanceId=null;pendingServerInstanceKnown=null;recoveryMismatchStaleClaim;bufferedUpdates=new Map;persistenceFactory;storage;constructor(e,t,n){this.maxSize=e,this.wsUrl=t,this.recycleDebounceMs=n?.recycleDebounceMs??EB,this.clearDataTimeoutMs=n?.clearDataTimeoutMs??DB,this.persistenceFactory=n?.persistenceFactory??qS,n?.storage===void 0?this.storage=globalThis.localStorage===void 0?null:globalThis.localStorage:this.storage=n.storage}setTabIdentity(e){this.tabIdentity=e}setExpectedServerInstanceId(e){if(this.cachedServerInstanceId=e,!(e===null||e.length===0)){if(this.pendingServerInstanceKnown!==null){let t=this.pendingServerInstanceKnown;this.pendingServerInstanceKnown=null,t.resolve(e)}this.attachDeferredPersistence(e)}}whenServerInstanceKnown(){if(this.cachedServerInstanceId!==null&&this.cachedServerInstanceId.length>0)return Promise.resolve(this.cachedServerInstanceId);if(this.pendingServerInstanceKnown!==null)return this.pendingServerInstanceKnown.promise;let e,t=new Promise(t=>{e=t});return this.pendingServerInstanceKnown={promise:t,resolve:e},t}buildPersistence(e,t,n){return this.persistenceFactory({branch:this.getOrInitObservedBranch()??`_unknown_`,serverInstanceId:e,docName:t,doc:n})}attachDeferredPersistence(e){for(let t of this._entries.values())if(t.kind===`active`&&t.persistence===null)try{t.persistence=this.buildPersistence(e,t.docName,t.provider.document)}catch(e){let n=e instanceof Error?e.name:`non-error-throw`;this.emitStructuredClientRecoveryEvent({event:`ok-client-persistence-attach-failed`,...this.recoveryTelemetryBase(t.docName),errorName:n,errorMessage:e instanceof Error?e.message:String(e)})}}getServerRestartRecoveryState(){return this.serverRestartRecoveryState}observeDiskAck(e,t){let n=this.entries.get(e);!n||n.kind!==`active`||(n.lastDiskAckedSV=XS(n.lastDiskAckedSV,t))}observeDiskAckBatch(e){for(let[t,n]of Object.entries(e))this.observeDiskAck(t,n)}lastObservedBranch=null;lastObservedBranchInitialized=!1;getOrInitObservedBranch(){if(this.lastObservedBranchInitialized)return this.lastObservedBranch;this.lastObservedBranchInitialized=!0;try{let e=this.storage?.getItem(kB)??null;e!==null&&e.length>0&&(this.lastObservedBranch=e)}catch{}return this.lastObservedBranch}persistObservedBranch(e){this.lastObservedBranch=e,this.lastObservedBranchInitialized=!0;try{e===null||e.length===0?this.storage?.removeItem(kB):this.storage?.setItem(kB,e)}catch{}}withClearDataTimeout(e,t){return new Promise((n,r)=>{let i=setTimeout(()=>{r(new OB(e,this.clearDataTimeoutMs))},this.clearDataTimeoutMs);t.then(()=>{clearTimeout(i),n()},e=>{clearTimeout(i),r(e)})})}recoveryTelemetryBase(e,t){let n={docName:e,branch:this.getOrInitObservedBranch()??`_unknown_`},r=t===void 0?this.recoveryMismatchStaleClaim:t;return r!==void 0&&r.length>0&&(n.serverInstanceId=r),n}emitStructuredClientRecoveryEvent(e){console.warn(JSON.stringify(e))}clearRecoveryMismatchStaleClaimIfTerminal(){let e=this.serverRestartRecoveryState.kind;(e===`idle`||e===`failed`)&&(this.recoveryMismatchStaleClaim=void 0)}beginServerRestartRecovery(e,t){this.serverRestartRecoveryState={kind:`recovering`,phase:`clearing-local-cache`,docNames:e,failedDocNames:[],startedAt:t};for(let t of e)bB(t);this.notify()}enterServerRestartReconnect(e,t,n,r){if(e.length===0){this.serverRestartRecoveryState=t.length===0?CB:{kind:`failed`,reason:r,docNames:t,failedDocNames:t,startedAt:n},this.clearRecoveryMismatchStaleClaimIfTerminal(),this.notify();return}this.serverRestartRecoveryState={kind:`recovering`,phase:`reconnecting`,docNames:e,failedDocNames:t,startedAt:n,...t.length>0?{clearFailureReason:r}:{}},this.notify()}markServerRestartRecoverySynced(e){let t=this.serverRestartRecoveryState;if(t.kind!==`recovering`||t.phase!==`reconnecting`||!t.docNames.includes(e))return;let n=t.docNames.filter(t=>t!==e);if(n.length>0){this.serverRestartRecoveryState={...t,docNames:n};return}if(t.failedDocNames.length>0){this.serverRestartRecoveryState={kind:`failed`,reason:t.clearFailureReason??`clear-data-failed`,docNames:t.failedDocNames,failedDocNames:t.failedDocNames,startedAt:t.startedAt},this.clearRecoveryMismatchStaleClaimIfTerminal();return}this.serverRestartRecoveryState=CB,this.clearRecoveryMismatchStaleClaimIfTerminal()}setObservedBranch(e){this.persistObservedBranch(e)}compareAndUpdateObservedBranch(e){let t=this.getOrInitObservedBranch();return this.persistObservedBranch(e),t!==null&&t!==e}onBranchMismatch=null;branchMismatchInFlight=null;mismatchInFlight=null;setOnBranchMismatch(e){if(e===null){this.onBranchMismatch=null;return}this.onBranchMismatch=()=>{if(this.branchMismatchInFlight!==null)return;let t=Promise.resolve().then(e).finally(()=>{this.branchMismatchInFlight===t&&(this.branchMismatchInFlight=null)});this.branchMismatchInFlight=t}}setOnChange(e){this.onChange=e}notify(){this.onChange?.()}evictListeners=new Set;onEvict(e){return this.evictListeners.add(e),()=>{this.evictListeners.delete(e)}}fireEvict(e){for(let t of this.evictListeners)try{t(e)}catch(t){console.warn(`[ProviderPool] evict listener threw for ${e}:`,t)}}touch(e){let t=this.lruOrder.indexOf(e);t!==-1&&this.lruOrder.splice(t,1),this.lruOrder.push(e)}open(e){if(eB(e))return null;let t=this.entries.get(e);if(t)return t.lastAccessedAt=Date.now(),this.touch(e),this.notify(),t;this.entries.size>=this.maxSize&&this.evictLru();let n=this.cachedServerInstanceId,r=NB(this.tabIdentity,n,this.getOrInitObservedBranch()),i=new xS({url:ZS(this.wsUrl),name:e,forceSyncInterval:AB,...r===void 0?{}:{token:r}}),a=this.cachedServerInstanceId,o={kind:`active`,provider:i,persistence:a!==null&&a.length>0?this.buildPersistence(a,e,i.document):null,lastServerSyncedSV:null,lastDiskAckedSV:null,observerCleanup:null,observerFireCounterCleanup:wB(i.document,e),syncState:`connecting`,docName:e,lastAccessedAt:Date.now(),hasSynced:!1,pendingRecycleTimer:null,bridgeSetupFailed:!1};if(i.on(`status`,({status:t})=>{o.kind!==`active`||this.entries.get(e)!==o||t===`disconnected`&&(o.syncState=`disconnected`,this.notify())}),i.on(`synced`,()=>{if(!(o.kind!==`active`||this.entries.get(e)!==o)&&(o.syncState=`synced`,o.hasSynced=!0,o.lastServerSyncedSV=JS(i.document),o.pendingRecycleTimer&&=(clearTimeout(o.pendingRecycleTimer),null),this.markServerRestartRecoverySynced(e),this.notify(),!o.observerCleanup))try{let t=i.document,n=new ae({extensions:$z});o.observerCleanup=Pj({doc:t,xmlFragment:t.getXmlFragment(`default`),ytext:t.getText(`source`),mdManager:n,schema:TB,onSyncError:(t,n)=>{console.warn(`[Sync] ${t} failed for ${e}:`,n.message)}})}catch(t){console.error(`[ProviderPool] setupObservers init failed for ${e}:`,t),o.bridgeSetupFailed=!0,xB(e,new aB(e,t))}}),i.on(`disconnect`,()=>{o.kind!==`active`||this.entries.get(e)!==o||(o.syncState=`disconnected`,this.notify(),o.hasSynced&&i.unsyncedChanges===0&&!o.pendingRecycleTimer&&(o.pendingRecycleTimer=setTimeout(()=>{o.kind===`active`&&(o.pendingRecycleTimer=null,this.entries.get(e)===o&&this.recycleDisconnectedEntry(e))},this.recycleDebounceMs)))}),i.on(`authenticationFailed`,({reason:e})=>{if(![`server-instance-mismatch`,`branch-mismatch`].includes(e)){console.warn(JSON.stringify({event:`ok-auth-failed-unknown-reason`,reason:e}));return}let t=e;if(t===`server-instance-mismatch`){if(n===null||this.cachedServerInstanceId!==n)return;let e=n;this.cachedServerInstanceId=null,this.handleServerInstanceMismatch(e);return}if(t===`branch-mismatch`){this.onBranchMismatch?.();return}}),this.bufferedUpdates.get(e)!==void 0){let t=this.recoveryMismatchStaleClaim,n=()=>{if(i.off(`synced`,n),o.kind!==`active`||this.entries.get(e)!==o)return;let r=this.bufferedUpdates.get(e);if(r!==void 0){this.bufferedUpdates.delete(e);try{Cp(i.document,r,SB)}catch(n){let i=n instanceof Error?n.name:`non-error-throw`;this.emitStructuredClientRecoveryEvent({event:`ok-buffer-replay-failed`,...this.recoveryTelemetryBase(e,t),replayByteLength:r.byteLength,errorName:i,errorMessage:n instanceof Error?n.message:String(n)})}}};i.on(`synced`,n)}return this._entries.set(e,o),this.touch(e),this.notify(),o}handleServerInstanceMismatch(e){this.recoveryMismatchStaleClaim=e.length>0?e:void 0;let t=Array.from(this.entries.entries()),n=Date.now(),r=this.activeDocName,i=r!==null&&t.some(([e,t])=>e===r&&t.kind===`active`)?[r]:[],a=r??t.find(([,e])=>e.kind===`active`)?.[0]??``;a.length>0&&this.emitStructuredClientRecoveryEvent({event:`ok-client-cache-epoch-mismatch`,...this.recoveryTelemetryBase(a)}),this.beginServerRestartRecovery(i,n);for(let[e,n]of t)n.kind===`active`&&!i.includes(e)&&bB(e);for(let[e,n]of t){if(n.kind!==`active`)continue;let t=n.lastDiskAckedSV??n.lastServerSyncedSV;if(t===null){this.emitStructuredClientRecoveryEvent({event:`ok-buffer-replay-skipped-no-baseline`,...this.recoveryTelemetryBase(e),reason:`no-disk-ack-or-server-sync-vector`});continue}let r=YS(n.provider.document,t);if(r.byteLength>jB){X(`ok/pool/buffer-overflow`,{docName:e,bytes:r.byteLength});continue}r.byteLength>0&&this.bufferedUpdates.set(e,r)}let o=[];for(let[e,n]of t)n.kind===`active`&&n.persistence!==null&&o.push({docName:e,promise:this.withClearDataTimeout(e,n.persistence.clearData())});let s=Promise.allSettled(o.map(e=>e.promise)).then(e=>{let t=[],i=[],a=!1;e.forEach((e,n)=>{let r=o[n];if(!r)return;let s=r.docName;if(e.status===`rejected`){t.push(s);let n=e.reason instanceof OB;if(n&&(a=!0),n)this.emitStructuredClientRecoveryEvent({event:`ok-client-cache-clear-failed`,...this.recoveryTelemetryBase(s),failureKind:`timeout`});else{let t=e.reason instanceof Error?e.reason.name:`unknown`;this.emitStructuredClientRecoveryEvent({event:`ok-client-cache-clear-failed`,...this.recoveryTelemetryBase(s),failureKind:`rejected`,errorName:t,errorMessage:e.reason instanceof Error?e.reason.message:String(e.reason)})}}else i.push(s)});let s=i.filter(e=>e===r);if(t.length>0){let e=a?`clear-data-timeout`:`clear-data-failed`;console.warn(JSON.stringify({event:`ok-mismatch-recycle-partial-clears-failed`,failedDocs:t,clearedDocs:i})),this.enterServerRestartReconnect(s,t,n,e);for(let e of i)this.recycleDisconnectedEntry(e);return}this.enterServerRestartReconnect(s,[],n,`clear-data-failed`),this.recycleAllEntries()}).finally(()=>{this.mismatchInFlight===s&&(this.mismatchInFlight=null)});this.mismatchInFlight=s}awaitMismatchSettled(){return this.mismatchInFlight??Promise.resolve()}recycleAllEntries(){let e=Array.from(this.entries.keys());for(let t of e)this.recycleDisconnectedEntry(t)}prewarm(e){if(eB(e))return null;let t=this.entries.get(e);if(t)return t;let n=this.open(e);if(!n)return null;let r=this.lruOrder.indexOf(e);return r!==-1&&(this.lruOrder.splice(r,1),this.lruOrder.unshift(e)),n}close(e){let t=this.entries.get(e);t&&(this.destroyEntry(t),this._entries.delete(e),this.lruOrder=this.lruOrder.filter(t=>t!==e),this.bufferedUpdates.delete(e),this.activeDocName===e&&(this.activeDocName=null),this.notify())}async closeAndClearPersistence(e){let t=this.entries.get(e);if(t?.kind===`active`&&t.persistence!==null){try{await t.persistence.clearData()}catch(t){console.warn(`[ProviderPool] clearData on rename failed for ${e}:`,t)}this.close(e);return}t&&this.close(e);let n=this.getOrInitObservedBranch(),r=this.cachedServerInstanceId;if(n===null||r===null)return;let i=`ok-ydoc:${n}:${r}:${e}`;try{await new Promise((e,t)=>{let n=indexedDB.deleteDatabase(i);n.onsuccess=()=>e(),n.onerror=()=>t(n.error),n.onblocked=()=>{console.warn(`[ProviderPool] IDB delete blocked for ${i}`),t(Error(`idb-clear-blocked: ${i}`))}})}catch(e){console.warn(`[ProviderPool] IDB delete on rename failed for ${i}:`,e)}}clearBufferedUpdates(){this.bufferedUpdates.clear()}__test_seedBufferedUpdate(e,t){this.bufferedUpdates.set(e,t)}__test_bufferedUpdatesSize(){return this.bufferedUpdates.size}__test_hasBufferedUpdate(e){return this.bufferedUpdates.has(e)}__test_getBufferedUpdate(e){return this.bufferedUpdates.get(e)}setActive(e){let t=this.entries.get(e);if(!t)throw Error(`[ProviderPool] Cannot setActive — "${e}" is not open`);t.lastAccessedAt=Date.now(),this.touch(e),this.activeDocName=e,this.notify()}clearActive(){this.activeDocName!==null&&(this.activeDocName=null,this.notify())}getActive(){return this.activeDocName?this.entries.get(this.activeDocName)??null:null}getActiveDocName(){return this.activeDocName}has(e){return this.entries.has(e)}recycle(e){this.recycleDisconnectedEntry(e)}dispose(){for(let e of this._entries.values())this.destroyEntry(e);this._entries.clear(),this.lruOrder=[],this.activeDocName=null,this.onChange=null,this.bufferedUpdates.clear(),this.onBranchMismatch=null,this.branchMismatchInFlight=null,this.evictListeners.clear(),this.serverRestartRecoveryState=CB,this.cachedServerInstanceId=null,this.pendingServerInstanceKnown=null,this.tabIdentity=null,this.recoveryMismatchStaleClaim=void 0}evictLru(){for(let e of this.lruOrder)if(e!==this.activeDocName){X(`ok/pool/evict-lru`,{docName:e}),this.close(e);return}}destroyEntry(e){if(e.kind===`tearing-down`)return;let t=e.observerCleanup,n=e.observerFireCounterCleanup,r=e.persistence,i=e.pendingRecycleTimer,a=e.docName,o=e;o.kind=`tearing-down`,o.persistence=null,o.observerCleanup=null,o.observerFireCounterCleanup=null,o.pendingRecycleTimer=null,i&&clearTimeout(i),bB(a),this.fireEvict(a),t?.(),n?.(),r!==null&&r.destroy().catch(e=>{console.warn(`[ProviderPool] persistence destroy failed for ${a}:`,e)});try{o.provider.destroy()}catch(e){console.warn(`[ProviderPool] Provider destroy failed for ${a}:`,e)}}recycleDisconnectedEntry(e){let t=this.entries.get(e);if(!t||t.kind!==`active`)return;let n=this.activeDocName===e;if(X(`ok/pool/recycle-disconnected`,{docName:e,wasActive:n}),this.destroyEntry(t),this._entries.delete(e),this.lruOrder=this.lruOrder.filter(t=>t!==e),n){this.open(e)&&this.setActive(e);return}this.notify()}},FB=crypto.randomUUID(),IB=!1;function LB(e){IB||(IB=!0,console.warn(`[principal-fetch] failed to resolve principal — falling back to random identity.`,e))}var RB=(0,q.createContext)(null),zB=null;function BB(e){return zB||(zB=new PB(MB,e),Ey(zB)),zB}var VB={activeDocName:null,activeProvider:null,syncState:`connecting`,serverRestartRecovery:{kind:`idle`},poolEntries:[]};function HB(){if(typeof window>`u`)return null;let e=window.okDesktop;return e?.config.mode===`editor`?e:null}function UB(){return typeof window>`u`||window.okDesktop?.config.mode===`editor`?null:Iy(window.location.origin)}function WB(){if(typeof window>`u`)return[];let e=UB();return e?Ly(window.localStorage===void 0?null:window.localStorage,e,MB).openTabs:[]}function GB(e){let t=e.getActive(),n=[];for(let t of e.entries.values())n.push({docName:t.docName,provider:t.provider,lastAccessedAt:t.lastAccessedAt});return n.sort((e,t)=>t.lastAccessedAt-e.lastAccessedAt),{activeDocName:e.getActiveDocName(),activeProvider:t?.provider??null,syncState:t?.syncState??`connecting`,serverRestartRecovery:e.getServerRestartRecoveryState(),poolEntries:n}}function KB(e){let t=(0,Y.c)(81),{children:n}=e,[r,i]=(0,q.useState)(VB),[a,o]=(0,q.useState)(null),[s,c]=(0,q.useState)(WB),[l,u]=(0,q.useState)(!1),[d,f]=(0,q.useState)(!1),[p,m]=(0,q.useState)(null),[h,g]=(0,q.useState)(null),[_,v]=(0,q.useState)(`doc`),[y,b]=(0,q.useState)(null),[x,S]=(0,q.useState)(0),{collabUrl:C,terminal:w,lastError:T,retry:E}=qv(),D,O;t[0]!==C||t[1]!==d||t[2]!==l?(D=()=>{if(C===null||l||!d)return;let e=!1,t=HB(),n=UB(),r=typeof localStorage<`u`?localStorage:null;return(t?t.project.getSessionState():Promise.resolve(n?Ly(r,n,MB):{openTabs:[],activeDocName:null,updatedAt:null})).then(t=>{if(e)return;let n=Py(t,MB),r=BB(C);for(let e of n.openTabs)r.open(e);c(e=>{let t=n.openTabs;for(let n of e)t=Ay(t,n,MB);return t});let i=Je(window.location.hash)===null&&window.location.hash.length===0,a=n.activeDocName??n.openTabs[0]??null;i&&a&&(window.location.hash=Re(a))}).catch(XB).finally(()=>{e||u(!0)}),()=>{e=!0}},O=[C,d,l],t[0]=C,t[1]=d,t[2]=l,t[3]=D,t[4]=O):(D=t[3],O=t[4]),(0,q.useEffect)(D,O);let A,j;t[5]!==s||t[6]!==r.activeDocName||t[7]!==l?(A=()=>{if(!l)return;let e=Fy(s,r.activeDocName),t=HB();if(t){t.project.setSessionState(e).catch(YB);return}let n=UB();n&&Ry(typeof localStorage<`u`?localStorage:null,n,e)},j=[s,r.activeDocName,l],t[5]=s,t[6]=r.activeDocName,t[7]=l,t[8]=A,t[9]=j):(A=t[8],j=t[9]),(0,q.useEffect)(A,j);let M,N;t[10]===C?(M=t[11],N=t[12]):(M=()=>{if(C===null)return;let e=!1;f(!1);let t=BB(C);return i(GB(t)),t.setOnBranchMismatch(()=>Av(t)),t.setOnChange(()=>i(GB(t))),fetch(`/api/principal`).then(JB).then(n=>{if(e)return;let r=k.safeParse(n);r.success?(t.setTabIdentity({principalId:r.data.id,tabSessionId:FB}),m(r.data)):LB(r.error)}).catch(t=>{e||LB(t)}).finally(()=>{e||f(!0)}),Av(t),()=>{e=!0,t.setOnChange(null)}},N=[C],t[10]=C,t[11]=M,t[12]=N),(0,q.useEffect)(M,N);let P;t[13]===C?P=t[14]:(P=e=>{if(X(`ok/nav/open-document`,{docName:e,transition:!1}),C===null)return;let t=BB(C);t.open(e)&&(c(t=>Ay(t,e,MB)),t.setActive(e),o({kind:`doc`,target:e,docName:e}))},t[13]=C,t[14]=P);let F=P,I;t[15]===F?I=t[16]:(I=e=>{X(`ok/nav/open-document`,{docName:e,transition:!1}),F(e)},t[15]=F,t[16]=I);let L=I,R;t[17]===C?R=t[18]:(R=e=>{if(C===null)return;let t=BB(C),n=We(e);if(n){if(!t.open(n))return;c(e=>Ay(e,n,MB)),t.setActive(n)}else t.clearActive();o(e)},t[17]=C,t[18]=R);let z=R,B;t[19]===z?B=t[20]:(B=e=>{X(`ok/nav/open-target`,{docName:We(e),kind:e.kind,transition:!1}),z(e)},t[19]=z,t[20]=B);let V=B,H,U;t[21]===C?(H=t[22],U=t[23]):(H=()=>{if(C===null){o(null);return}BB(C).clearActive(),o(null)},U=e=>{C!==null&&(BB(C).close(e),c(t=>jy(t,e)),o(t=>t&&(We(t)===e?null:t)))},t[21]=C,t[22]=H,t[23]=U);let W;t[24]!==C||t[25]!==r.activeDocName?(W=e=>{let t=null;if(C!==null&&BB(C).close(e),c(n=>(t=Ny(n,r.activeDocName,e),jy(n,e))),r.activeDocName===e){if(t){window.location.hash=Re(t);return}C!==null&&BB(C).clearActive(),o(null),window.location.hash=``}},t[24]=C,t[25]=r.activeDocName,t[26]=W):W=t[26];let ee;t[27]!==C||t[28]!==s?(ee=e=>{let t=My(s,e,MB);if(C!==null){let e=BB(C);for(let n of t)e.open(n)}c(t)},t[27]=C,t[28]=s,t[29]=ee):ee=t[29];let te,ne,re;t[30]===C?(te=t[31],ne=t[32],re=t[33]):(te=async e=>{C!==null&&(await BB(C).closeAndClearPersistence(e),o(t=>t&&(We(t)===e?null:t)))},ne=e=>{C!==null&&BB(C).recycle(e)},re=e=>{C!==null&&BB(C).prewarm(e)},t[30]=C,t[31]=te,t[32]=ne,t[33]=re);let ie,ae,oe,se,ce;t[34]===C?(ie=t[35],ae=t[36],oe=t[37],se=t[38],ce=t[39]):(ie=e=>{C!==null&&BB(C).setExpectedServerInstanceId(e)},ae=async e=>{if(C===null)return;let t=BB(C);t.setObservedBranch(e),await Dv(t,e)},oe=async e=>{if(C===null)return;let t=BB(C);t.compareAndUpdateObservedBranch(e)&&await Dv(t,e)},se=(e,t)=>{C!==null&&BB(C).observeDiskAck(e,t)},ce=async()=>{C!==null&&await Av(BB(C))},t[34]=C,t[35]=ie,t[36]=ae,t[37]=oe,t[38]=se,t[39]=ce);let le;t[40]!==y||t[41]!==_?(le=e=>{if(_===`agent`&&y===e){v(`doc`);return}b(e),v(`agent`),S(qB)},t[40]=y,t[41]=_,t[42]=le):le=t[42];let ue;t[43]===Symbol.for(`react.memo_cache_sentinel`)?(ue=()=>{v(`doc`),b(null)},t[43]=ue):ue=t[43];let de;t[44]!==a||t[45]!==T||t[46]!==w||t[47]!==C||t[48]!==y||t[49]!==x||t[50]!==_||t[51]!==F||t[52]!==L||t[53]!==s||t[54]!==z||t[55]!==V||t[56]!==p||t[57]!==E||t[58]!==r.activeDocName||t[59]!==r.activeProvider||t[60]!==r.poolEntries||t[61]!==r.serverRestartRecovery||t[62]!==r.syncState||t[63]!==h||t[64]!==H||t[65]!==U||t[66]!==W||t[67]!==ee||t[68]!==te||t[69]!==ne||t[70]!==re||t[71]!==ie||t[72]!==ae||t[73]!==oe||t[74]!==se||t[75]!==ce||t[76]!==le?(de={principal:p,activeTarget:a,activeDocName:r.activeDocName,activeProvider:r.activeProvider,openTabs:s,syncState:r.syncState,serverRestartRecovery:r.serverRestartRecovery,poolEntries:r.poolEntries,openDocument:F,openDocumentTransition:L,openTarget:z,openTargetTransition:V,clearTarget:H,closeDocument:U,closeTab:W,remapTabsForRename:ee,closeAndClearForRename:te,recycleDocument:ne,prewarm:re,systemProvider:h,setSystemProvider:g,updateServerInstanceId:ie,onBranchSwitched:ae,observeBranch:oe,observeDiskAck:se,refreshServerInfo:ce,collabUrl:C,collabTerminal:w,collabLastError:T,retryCollab:E,docPanelMode:_,docPanelAgentId:y,docPanelExpandSignal:x,openActivityPanel:le,closeActivityPanel:ue},t[44]=a,t[45]=T,t[46]=w,t[47]=C,t[48]=y,t[49]=x,t[50]=_,t[51]=F,t[52]=L,t[53]=s,t[54]=z,t[55]=V,t[56]=p,t[57]=E,t[58]=r.activeDocName,t[59]=r.activeProvider,t[60]=r.poolEntries,t[61]=r.serverRestartRecovery,t[62]=r.syncState,t[63]=h,t[64]=H,t[65]=U,t[66]=W,t[67]=ee,t[68]=te,t[69]=ne,t[70]=re,t[71]=ie,t[72]=ae,t[73]=oe,t[74]=se,t[75]=ce,t[76]=le,t[77]=de):de=t[77];let fe=de,pe;return t[78]!==n||t[79]!==fe?(pe=(0,J.jsx)(RB,{value:fe,children:n}),t[78]=n,t[79]=fe,t[80]=pe):pe=t[80],pe}function qB(e){return e+1}function JB(e){return e.ok?e.json():Promise.reject(Error(`HTTP ${e.status}`))}function YB(e){console.warn(`[editor-tabs] failed to persist tab session:`,e)}function XB(e){console.warn(`[editor-tabs] failed to restore tab session:`,e)}function ZB(){let e=(0,q.use)(RB);if(!e)throw Error(`useDocumentContext must be used within <DocumentProvider />`);return e}function QB(){let e=(0,Y.c)(3),{openDocumentTransition:t,openTargetTransition:n}=ZB(),r;return e[0]!==t||e[1]!==n?(r={openDocumentTransition:t,openTargetTransition:n},e[0]=t,e[1]=n,e[2]=r):r=e[2],r}export{hy as $,lr as $t,BA as A,Xr as At,KO as B,Ar as Bt,Nj as C,Zs as Ct,YA as D,X as Dt,tj as E,Go as Et,zk as F,Lr as Ft,FT as G,wr as Gt,LO as H,Or as Ht,Lk as I,Ir as It,hC as J,_r as Jt,vT as K,Sr as Kt,Ak as L,Fr as Lt,FA as M,Ur as Mt,PA as N,Hr as Nt,zA as O,Ho as Ot,jA as P,Rr as Pt,dy as Q,ur as Qt,kk as R,Nr as Rt,Rj as S,Ic as St,_j as T,ec as Tt,zD as U,Dr as Ut,zO as V,kr as Vt,RD as W,Tr as Wt,xS as X,mr as Xt,nC as Y,hr as Yt,my as Z,dr as Zt,lz as _,Up as _t,iB as a,wv as at,pR as b,Xu as bt,nB as c,pv as ct,eB as d,sp as dt,fy as et,$z as f,Tm as ft,cz as g,Jp as gt,uz as h,Wp as ht,aB as i,Ov as it,NA as j,Wr as jt,VA as k,zo as kt,bB as l,K_ as lt,Mz as m,Xp as mt,ZB as n,Qv as nt,rB as o,Sv as ot,jz as p,Zp as pt,Zw as q,vr as qt,QB as r,zv as rt,oB as s,fv as st,KB as t,Cy as tt,gB as u,Bg as ut,ER as v,vf as vt,Mj as w,nc as wt,yM as x,Lc as xt,CR as y,yf as yt,_k as z,jr as zt};
37
+ }`,{label:`enum`,detail:`definition`,type:`keyword`})]),KI=new Dn,qI=new Set([`Script`,`Block`,`FunctionExpression`,`FunctionDeclaration`,`ArrowFunction`,`MethodDeclaration`,`ForStatement`]);function JI(e){return(t,n)=>{let r=t.node.getChild(`VariableDefinition`);return r&&n(r,e),!0}}var YI=[`FunctionDeclaration`],XI={FunctionDeclaration:JI(`function`),ClassDeclaration:JI(`class`),ClassExpression:()=>!0,EnumDeclaration:JI(`constant`),TypeAliasDeclaration:JI(`type`),NamespaceDeclaration:JI(`namespace`),VariableDefinition(e,t){e.matchContext(YI)||t(e,`variable`)},TypeDefinition(e,t){t(e,`type`)},__proto__:null};function ZI(e,t){let n=KI.get(t);if(n)return n;let r=[],i=!0;function a(t,n){let i=e.sliceString(t.from,t.to);r.push({label:i,type:n})}return t.cursor(er.IncludeAnonymous).iterate(t=>{if(i)i=!1;else if(t.name){let e=XI[t.name];if(e&&e(t,a)||qI.has(t.name))return!1}else if(t.to-t.from>8192){for(let n of ZI(e,t.node))r.push(n);return!1}}),KI.set(t,r),r}var QI=/^[\w$\xa1-\uffff][\w$\d\xa1-\uffff]*$/,$I=[`TemplateString`,`String`,`RegExp`,`LineComment`,`BlockComment`,`VariableDefinition`,`TypeDefinition`,`Label`,`PropertyDefinition`,`PropertyName`,`PrivatePropertyDefinition`,`PrivatePropertyName`,`JSXText`,`JSXAttributeValue`,`JSXOpenTag`,`JSXCloseTag`,`JSXSelfClosingTag`,`.`,`?.`];function eL(e){let t=Sn(e.state).resolveInner(e.pos,-1);if($I.indexOf(t.name)>-1)return null;let n=t.name==`VariableName`||t.to-t.from<20&&QI.test(e.state.sliceDoc(t.from,t.to));if(!n&&!e.explicit)return null;let r=[];for(let n=t;n;n=n.parent)qI.has(n.name)&&(r=r.concat(ZI(e.state.doc,n)));return{options:r,from:n?t.from:e.pos,validFor:QI}}var tL=qn.define({name:`javascript`,parser:UI.configure({props:[Zn.add({IfStatement:Xn({except:/^\s*({|else\b)/}),TryStatement:Xn({except:/^\s*({|catch\b|finally\b)/}),LabeledStatement:In,SwitchBody:e=>{let t=e.textAfter,n=/^\s*\}/.test(t),r=/^\s*(case|default)\b/.test(t);return e.baseIndent+(n?0:r?1:2)*e.unit},Block:Gn({closing:`}`}),ArrowFunction:e=>e.baseIndent+e.unit,"TemplateString BlockComment":()=>null,"Statement Property":Xn({except:/^\s*{/}),JSXElement(e){let t=/^\s*<\//.test(e.textAfter);return e.lineIndent(e.node.from)+(t?0:e.unit)},JSXEscape(e){let t=/\s*\}/.test(e.textAfter);return e.lineIndent(e.node.from)+(t?0:e.unit)},"JSXOpenTag JSXSelfClosingTag"(e){return e.column(e.node.from)+e.unit}}),$n.add({"Block ClassBody SwitchBody EnumBody ObjectExpression ArrayExpression ObjectType":Mn,BlockComment(e){return{from:e.from+2,to:e.to-2}},JSXElement(e){let t=e.firstChild;if(!t||t.name==`JSXSelfClosingTag`)return null;let n=e.lastChild;return{from:t.to,to:n.type.isError?e.to:n.from}},"JSXSelfClosingTag JSXOpenTag"(e){let t=e.firstChild?.nextSibling,n=e.lastChild;return!t||t.type.isError?null:{from:t.to,to:n.type.isError?e.to:n.from}}})]}),languageData:{closeBrackets:{brackets:[`(`,`[`,`{`,`'`,`"`,"`"]},commentTokens:{line:`//`,block:{open:`/*`,close:`*/`}},indentOnInput:/^\s*(?:case |default:|\{|\}|<\/)$/,wordChars:`$`}}),nL={test:e=>/^JSX/.test(e.name),facet:Fn({commentTokens:{block:{open:`{/*`,close:`*/}`}}})},rL=tL.configure({dialect:`ts`},`typescript`),iL=tL.configure({dialect:`jsx`,props:[Rn.add(e=>e.isTop?[nL]:void 0)]}),aL=tL.configure({dialect:`jsx ts`,props:[Rn.add(e=>e.isTop?[nL]:void 0)]},`typescript`),oL=e=>({label:e,type:`keyword`}),sL=`break case const continue default delete export extends false finally in instanceof let new return static super switch this throw true typeof var yield`.split(` `).map(oL),cL=sL.concat([`declare`,`implements`,`private`,`protected`,`public`].map(oL));function lL(e={}){let t=e.jsx?e.typescript?aL:iL:e.typescript?rL:tL,n=e.typescript?GI.concat(cL):WI.concat(sL);return new Wn(t,[tL.data.of({autocomplete:rr($I,tr(n))}),tL.data.of({autocomplete:eL}),e.jsx?pL:[]])}function uL(e){for(;;){if(e.name==`JSXOpenTag`||e.name==`JSXSelfClosingTag`||e.name==`JSXFragmentTag`)return e;if(e.name==`JSXEscape`||!e.parent)return null;e=e.parent}}function dL(e,t,n=e.length){for(let r=t?.firstChild;r;r=r.nextSibling)if(r.name==`JSXIdentifier`||r.name==`JSXBuiltin`||r.name==`JSXNamespacedName`||r.name==`JSXMemberExpression`)return e.sliceString(r.from,Math.min(r.to,n));return``}var fL=typeof navigator==`object`&&/Android\b/.test(navigator.userAgent),pL=An.inputHandler.of((e,t,n,r,i)=>{if((fL?e.composing:e.compositionStarted)||e.state.readOnly||t!=n||r!=`>`&&r!=`/`||!tL.isActiveAt(e.state,t,-1))return!1;let a=i(),{state:o}=a,s=o.changeByRange(e=>{let{head:t}=e,n=Sn(o).resolveInner(t-1,-1),i;if(n.name==`JSXStartTag`&&(n=n.parent),!(o.doc.sliceString(t-1,t)!=r||n.name==`JSXAttributeValue`&&n.to>t)){if(r==`>`&&n.name==`JSXFragmentTag`)return{range:e,changes:{from:t,insert:`</>`}};if(r==`/`&&n.name==`JSXStartCloseTag`){let e=n.parent,r=e.parent;if(r&&e.from==t-2&&((i=dL(o.doc,r.firstChild,t))||r.firstChild?.name==`JSXFragmentTag`)){let e=`${i}>`;return{range:En.cursor(t+e.length,-1),changes:{from:t,insert:e}}}}else if(r==`>`){let r=uL(n);if(r&&r.name==`JSXOpenTag`&&!/^\/?>|^<\//.test(o.doc.sliceString(t,t+2))&&(i=dL(o.doc,r,t)))return{range:e,changes:{from:t,insert:`</${i}>`}}}}return{range:e}});return s.changes.empty?!1:(e.dispatch([a,o.update(s,{userEvent:`input.complete`,scrollIntoView:!0})]),!0)}),mL=[`_blank`,`_self`,`_top`,`_parent`],hL=[`ascii`,`utf-8`,`utf-16`,`latin1`,`latin1`],gL=[`get`,`post`,`put`,`delete`],_L=[`application/x-www-form-urlencoded`,`multipart/form-data`,`text/plain`],vL=[`true`,`false`],$={},yL={a:{attrs:{href:null,ping:null,type:null,media:null,target:mL,hreflang:null}},abbr:$,address:$,area:{attrs:{alt:null,coords:null,href:null,target:null,ping:null,media:null,hreflang:null,type:null,shape:[`default`,`rect`,`circle`,`poly`]}},article:$,aside:$,audio:{attrs:{src:null,mediagroup:null,crossorigin:[`anonymous`,`use-credentials`],preload:[`none`,`metadata`,`auto`],autoplay:[`autoplay`],loop:[`loop`],controls:[`controls`]}},b:$,base:{attrs:{href:null,target:mL}},bdi:$,bdo:$,blockquote:{attrs:{cite:null}},body:$,br:$,button:{attrs:{form:null,formaction:null,name:null,value:null,autofocus:[`autofocus`],disabled:[`autofocus`],formenctype:_L,formmethod:gL,formnovalidate:[`novalidate`],formtarget:mL,type:[`submit`,`reset`,`button`]}},canvas:{attrs:{width:null,height:null}},caption:$,center:$,cite:$,code:$,col:{attrs:{span:null}},colgroup:{attrs:{span:null}},command:{attrs:{type:[`command`,`checkbox`,`radio`],label:null,icon:null,radiogroup:null,command:null,title:null,disabled:[`disabled`],checked:[`checked`]}},data:{attrs:{value:null}},datagrid:{attrs:{disabled:[`disabled`],multiple:[`multiple`]}},datalist:{attrs:{data:null}},dd:$,del:{attrs:{cite:null,datetime:null}},details:{attrs:{open:[`open`]}},dfn:$,div:$,dl:$,dt:$,em:$,embed:{attrs:{src:null,type:null,width:null,height:null}},eventsource:{attrs:{src:null}},fieldset:{attrs:{disabled:[`disabled`],form:null,name:null}},figcaption:$,figure:$,footer:$,form:{attrs:{action:null,name:null,"accept-charset":hL,autocomplete:[`on`,`off`],enctype:_L,method:gL,novalidate:[`novalidate`],target:mL}},h1:$,h2:$,h3:$,h4:$,h5:$,h6:$,head:{children:[`title`,`base`,`link`,`style`,`meta`,`script`,`noscript`,`command`]},header:$,hgroup:$,hr:$,html:{attrs:{manifest:null}},i:$,iframe:{attrs:{src:null,srcdoc:null,name:null,width:null,height:null,sandbox:[`allow-top-navigation`,`allow-same-origin`,`allow-forms`,`allow-scripts`],seamless:[`seamless`]}},img:{attrs:{alt:null,src:null,ismap:null,usemap:null,width:null,height:null,crossorigin:[`anonymous`,`use-credentials`]}},input:{attrs:{alt:null,dirname:null,form:null,formaction:null,height:null,list:null,max:null,maxlength:null,min:null,name:null,pattern:null,placeholder:null,size:null,src:null,step:null,value:null,width:null,accept:[`audio/*`,`video/*`,`image/*`],autocomplete:[`on`,`off`],autofocus:[`autofocus`],checked:[`checked`],disabled:[`disabled`],formenctype:_L,formmethod:gL,formnovalidate:[`novalidate`],formtarget:mL,multiple:[`multiple`],readonly:[`readonly`],required:[`required`],type:[`hidden`,`text`,`search`,`tel`,`url`,`email`,`password`,`datetime`,`date`,`month`,`week`,`time`,`datetime-local`,`number`,`range`,`color`,`checkbox`,`radio`,`file`,`submit`,`image`,`reset`,`button`]}},ins:{attrs:{cite:null,datetime:null}},kbd:$,keygen:{attrs:{challenge:null,form:null,name:null,autofocus:[`autofocus`],disabled:[`disabled`],keytype:[`RSA`]}},label:{attrs:{for:null,form:null}},legend:$,li:{attrs:{value:null}},link:{attrs:{href:null,type:null,hreflang:null,media:null,sizes:[`all`,`16x16`,`16x16 32x32`,`16x16 32x32 64x64`]}},map:{attrs:{name:null}},mark:$,menu:{attrs:{label:null,type:[`list`,`context`,`toolbar`]}},meta:{attrs:{content:null,charset:hL,name:[`viewport`,`application-name`,`author`,`description`,`generator`,`keywords`],"http-equiv":[`content-language`,`content-type`,`default-style`,`refresh`]}},meter:{attrs:{value:null,min:null,low:null,high:null,max:null,optimum:null}},nav:$,noscript:$,object:{attrs:{data:null,type:null,name:null,usemap:null,form:null,width:null,height:null,typemustmatch:[`typemustmatch`]}},ol:{attrs:{reversed:[`reversed`],start:null,type:[`1`,`a`,`A`,`i`,`I`]},children:[`li`,`script`,`template`,`ul`,`ol`]},optgroup:{attrs:{disabled:[`disabled`],label:null}},option:{attrs:{disabled:[`disabled`],label:null,selected:[`selected`],value:null}},output:{attrs:{for:null,form:null,name:null}},p:$,param:{attrs:{name:null,value:null}},pre:$,progress:{attrs:{value:null,max:null}},q:{attrs:{cite:null}},rp:$,rt:$,ruby:$,samp:$,script:{attrs:{type:[`text/javascript`],src:null,async:[`async`],defer:[`defer`],charset:hL}},section:$,select:{attrs:{form:null,name:null,size:null,autofocus:[`autofocus`],disabled:[`disabled`],multiple:[`multiple`]}},slot:{attrs:{name:null}},small:$,source:{attrs:{src:null,type:null,media:null}},span:$,strong:$,style:{attrs:{type:[`text/css`],media:null,scoped:null}},sub:$,summary:$,sup:$,table:$,tbody:$,td:{attrs:{colspan:null,rowspan:null,headers:null}},template:$,textarea:{attrs:{dirname:null,form:null,maxlength:null,name:null,placeholder:null,rows:null,cols:null,autofocus:[`autofocus`],disabled:[`disabled`],readonly:[`readonly`],required:[`required`],wrap:[`soft`,`hard`]}},tfoot:$,th:{attrs:{colspan:null,rowspan:null,headers:null,scope:[`row`,`col`,`rowgroup`,`colgroup`]}},thead:$,time:{attrs:{datetime:null}},title:$,tr:$,track:{attrs:{src:null,label:null,default:null,kind:[`subtitles`,`captions`,`descriptions`,`chapters`,`metadata`],srclang:null}},ul:{children:[`li`,`script`,`template`,`ul`,`ol`]},var:$,video:{attrs:{src:null,poster:null,width:null,height:null,crossorigin:[`anonymous`,`use-credentials`],preload:[`auto`,`metadata`,`none`],autoplay:[`autoplay`],mediagroup:[`movie`],muted:[`muted`],controls:[`controls`]}},wbr:$},bL={accesskey:null,class:null,contenteditable:vL,contextmenu:null,dir:[`ltr`,`rtl`,`auto`],draggable:[`true`,`false`,`auto`],dropzone:[`copy`,`move`,`link`,`string:`,`file:`],hidden:[`hidden`],id:null,inert:[`inert`],itemid:null,itemprop:null,itemref:null,itemscope:[`itemscope`],itemtype:null,lang:[`ar`,`bn`,`de`,`en-GB`,`en-US`,`es`,`fr`,`hi`,`id`,`ja`,`pa`,`pt`,`ru`,`tr`,`zh`],spellcheck:vL,autocorrect:vL,autocapitalize:vL,style:null,tabindex:null,title:null,translate:[`yes`,`no`],rel:[`stylesheet`,`alternate`,`author`,`bookmark`,`help`,`license`,`next`,`nofollow`,`noreferrer`,`prefetch`,`prev`,`search`,`tag`],role:`alert application article banner button cell checkbox complementary contentinfo dialog document feed figure form grid gridcell heading img list listbox listitem main navigation region row rowgroup search switch tab table tabpanel textbox timer`.split(` `),"aria-activedescendant":null,"aria-atomic":vL,"aria-autocomplete":[`inline`,`list`,`both`,`none`],"aria-busy":vL,"aria-checked":[`true`,`false`,`mixed`,`undefined`],"aria-controls":null,"aria-describedby":null,"aria-disabled":vL,"aria-dropeffect":null,"aria-expanded":[`true`,`false`,`undefined`],"aria-flowto":null,"aria-grabbed":[`true`,`false`,`undefined`],"aria-haspopup":vL,"aria-hidden":vL,"aria-invalid":[`true`,`false`,`grammar`,`spelling`],"aria-label":null,"aria-labelledby":null,"aria-level":null,"aria-live":[`off`,`polite`,`assertive`],"aria-multiline":vL,"aria-multiselectable":vL,"aria-owns":null,"aria-posinset":null,"aria-pressed":[`true`,`false`,`mixed`,`undefined`],"aria-readonly":vL,"aria-relevant":null,"aria-required":vL,"aria-selected":[`true`,`false`,`undefined`],"aria-setsize":null,"aria-sort":[`ascending`,`descending`,`none`,`other`],"aria-valuemax":null,"aria-valuemin":null,"aria-valuenow":null,"aria-valuetext":null},xL=`beforeunload copy cut dragstart dragover dragleave dragenter dragend drag paste focus blur change click load mousedown mouseenter mouseleave mouseup keydown keyup resize scroll unload`.split(` `).map(e=>`on`+e);for(let e of xL)bL[e]=null;var SL=class{constructor(e,t){this.tags={...yL,...e},this.globalAttrs={...bL,...t},this.allTags=Object.keys(this.tags),this.globalAttrNames=Object.keys(this.globalAttrs)}};SL.default=new SL;function CL(e,t,n=e.length){if(!t)return``;let r=t.firstChild,i=r&&r.getChild(`TagName`);return i?e.sliceString(i.from,Math.min(i.to,n)):``}function wL(e,t=!1){for(;e;e=e.parent)if(e.name==`Element`)if(t)t=!1;else return e;return null}function TL(e,t,n){return n.tags[CL(e,wL(t))]?.children||n.allTags}function EL(e,t){let n=[];for(let r=wL(t);r&&!r.type.isTop;r=wL(r.parent)){let i=CL(e,r);if(i&&r.lastChild.name==`CloseTag`)break;i&&n.indexOf(i)<0&&(t.name==`EndTag`||t.from>=r.firstChild.to)&&n.push(i)}return n}var DL=/^[:\-\.\w\u00b7-\uffff]*$/;function OL(e,t,n,r,i){let a=/\s*>/.test(e.sliceDoc(i,i+5))?``:`>`,o=wL(n,n.name==`StartTag`||n.name==`TagName`);return{from:r,to:i,options:TL(e.doc,o,t).map(e=>({label:e,type:`type`})).concat(EL(e.doc,n).map((e,t)=>({label:`/`+e,apply:`/`+e+a,type:`type`,boost:99-t}))),validFor:/^\/?[:\-\.\w\u00b7-\uffff]*$/}}function kL(e,t,n,r){let i=/\s*>/.test(e.sliceDoc(r,r+5))?``:`>`;return{from:n,to:r,options:EL(e.doc,t).map((e,t)=>({label:e,apply:e+i,type:`type`,boost:99-t})),validFor:DL}}function AL(e,t,n,r){let i=[],a=0;for(let r of TL(e.doc,n,t))i.push({label:`<`+r,type:`type`});for(let t of EL(e.doc,n))i.push({label:`</`+t+`>`,type:`type`,boost:99-a++});return{from:r,to:r,options:i,validFor:/^<\/?[:\-\.\w\u00b7-\uffff]*$/}}function jL(e,t,n,r,i){let a=wL(n),o=a?t.tags[CL(e.doc,a)]:null,s=o&&o.attrs?Object.keys(o.attrs):[];return{from:r,to:i,options:(o&&o.globalAttrs===!1?s:s.length?s.concat(t.globalAttrNames):t.globalAttrNames).map(e=>({label:e,type:`property`})),validFor:DL}}function ML(e,t,n,r,i){let a=n.parent?.getChild(`AttributeName`),o=[],s;if(a){let c=e.sliceDoc(a.from,a.to),l=t.globalAttrs[c];if(!l){let r=wL(n),i=r?t.tags[CL(e.doc,r)]:null;l=i?.attrs&&i.attrs[c]}if(l){let t=e.sliceDoc(r,i).toLowerCase(),n=`"`,a=`"`;/^['"]/.test(t)?(s=t[0]==`"`?/^[^"]*$/:/^[^']*$/,n=``,a=e.sliceDoc(i,i+1)==t[0]?``:t[0],t=t.slice(1),r++):s=/^[^\s<>='"]*$/;for(let e of l)o.push({label:e,apply:n+e+a,type:`constant`})}}return{from:r,to:i,options:o,validFor:s}}function NL(e,t){let{state:n,pos:r}=t,i=Sn(n).resolveInner(r,-1),a=i.resolve(r);for(let e=r,t;a==i&&(t=i.childBefore(e));){let n=t.lastChild;if(!n||!n.type.isError||n.from<n.to)break;a=i=t,e=n.from}return i.name==`TagName`?i.parent&&/CloseTag$/.test(i.parent.name)?kL(n,i,i.from,r):OL(n,e,i,i.from,r):i.name==`StartTag`||i.name==`IncompleteTag`?OL(n,e,i,r,r):i.name==`StartCloseTag`||i.name==`IncompleteCloseTag`?kL(n,i,r,r):i.name==`OpenTag`||i.name==`SelfClosingTag`||i.name==`AttributeName`?jL(n,e,i,i.name==`AttributeName`?i.from:r,r):i.name==`Is`||i.name==`AttributeValue`||i.name==`UnquotedAttributeValue`?ML(n,e,i,i.name==`Is`?r:i.from,r):t.explicit&&(a.name==`Element`||a.name==`Text`||a.name==`Document`)?AL(n,e,i,r):null}function PL(e){return NL(SL.default,e)}function FL(e){let{extraTags:t,extraGlobalAttributes:n}=e,r=n||t?new SL(t,n):SL.default;return e=>NL(r,e)}var IL=tL.parser.configure({top:`SingleExpression`}),LL=[{tag:`script`,attrs:e=>e.type==`text/typescript`||e.lang==`ts`,parser:rL.parser},{tag:`script`,attrs:e=>e.type==`text/babel`||e.type==`text/jsx`,parser:iL.parser},{tag:`script`,attrs:e=>e.type==`text/typescript-jsx`,parser:aL.parser},{tag:`script`,attrs(e){return/^(importmap|speculationrules|application\/(.+\+)?json)$/i.test(e.type)},parser:IL},{tag:`script`,attrs(e){return!e.type||/^(?:text|application)\/(?:x-)?(?:java|ecma)script$|^module$|^$/i.test(e.type)},parser:tL.parser},{tag:`style`,attrs(e){return(!e.lang||e.lang==`css`)&&(!e.type||/^(text\/)?(x-)?(stylesheet|css)$/i.test(e.type))},parser:oI.parser}],RL=[{name:`style`,parser:oI.parser.configure({top:`Styles`})}].concat(xL.map(e=>({name:e,parser:tL.parser}))),zL=qn.define({name:`html`,parser:aF.configure({props:[Zn.add({Element(e){let t=/^(\s*)(<\/)?/.exec(e.textAfter);return e.node.to<=e.pos+t[0].length?e.continue():e.lineIndent(e.node.from)+(t[2]?0:e.unit)},"OpenTag CloseTag SelfClosingTag"(e){return e.column(e.node.from)+e.unit},Document(e){if(e.pos+/\s*/.exec(e.textAfter)[0].length<e.node.to)return e.continue();let t=null,n;for(let n=e.node;;){let e=n.lastChild;if(!e||e.name!=`Element`||e.to!=n.to)break;t=n=e}return t&&!((n=t.lastChild)&&(n.name==`CloseTag`||n.name==`SelfClosingTag`))?e.lineIndent(t.from)+e.unit:null}}),$n.add({Element(e){let t=e.firstChild,n=e.lastChild;return!t||t.name!=`OpenTag`?null:{from:t.to,to:n.name==`CloseTag`?n.from:e.to}}}),Hn.add({"OpenTag CloseTag":e=>e.getChild(`TagName`)})]}),languageData:{commentTokens:{block:{open:`<!--`,close:`-->`}},indentOnInput:/^\s*<\/\w+\W$/,wordChars:`-_`}}),BL=zL.configure({wrap:lF(LL,RL)});function VL(e={}){let t=``,n;return e.matchClosingTags===!1&&(t=`noMatch`),e.selfClosingTags===!0&&(t=(t?t+` `:``)+`selfClosing`),(e.nestedLanguages&&e.nestedLanguages.length||e.nestedAttributes&&e.nestedAttributes.length)&&(n=lF((e.nestedLanguages||[]).concat(LL),(e.nestedAttributes||[]).concat(RL))),new Wn(n?zL.configure({wrap:n,dialect:t}):t?BL.configure({dialect:t}):BL,[BL.data.of({autocomplete:FL(e)}),e.autoCloseTags===!1?[]:UL,lL().support,sI().support])}var HL=new Set(`area base br col command embed frame hr img input keygen link meta param source track wbr menuitem`.split(` `)),UL=An.inputHandler.of((e,t,n,r,i)=>{if(e.composing||e.state.readOnly||t!=n||r!=`>`&&r!=`/`||!BL.isActiveAt(e.state,t,-1))return!1;let a=i(),{state:o}=a,s=o.changeByRange(e=>{let t=o.doc.sliceString(e.from-1,e.to)==r,{head:n}=e,i=Sn(o).resolveInner(n,-1),a;if(t&&r==`>`&&i.name==`EndTag`){let t=i.parent;if(t.parent?.lastChild?.name!=`CloseTag`&&(a=CL(o.doc,t.parent,n))&&!HL.has(a))return{range:e,changes:{from:n,to:n+ +(o.doc.sliceString(n,n+1)===`>`),insert:`</${a}>`}}}else if(t&&r==`/`&&i.name==`IncompleteCloseTag`){let e=i.parent;if(i.from==n-2&&e.lastChild?.name!=`CloseTag`&&(a=CL(o.doc,e,n))&&!HL.has(a)){let e=n+ +(o.doc.sliceString(n,n+1)===`>`),t=`${a}>`;return{range:En.cursor(n+t.length,-1),changes:{from:n,to:e,insert:t}}}}return{range:e}});return s.changes.empty?!1:(e.dispatch([a,o.update(s,{userEvent:`input.complete`,scrollIntoView:!0})]),!0)}),WL=Fn({commentTokens:{block:{open:`<!--`,close:`-->`}}}),GL=new pn,KL=kN.configure({props:[$n.add(e=>!e.is(`Block`)||e.is(`Document`)||qL(e)!=null||JL(e)?void 0:(e,t)=>({from:t.doc.lineAt(e.from).to,to:e.to})),GL.add(qL),Zn.add({Document:()=>null}),Bn.add({Document:WL})]});function qL(e){let t=/^(?:ATX|Setext)Heading(\d)$/.exec(e.name);return t?+t[1]:void 0}function JL(e){return e.name==`OrderedList`||e.name==`BulletList`}function YL(e,t){let n=e;for(;;){let e=n.nextSibling,r;if(!e||(r=qL(e.type))!=null&&r<=t)break;n=e}return n.to}var XL=Pn.of((e,t,n)=>{for(let r=Sn(e).resolveInner(n,-1);r&&!(r.from<t);r=r.parent){let e=r.type.prop(GL);if(e==null)continue;let t=YL(r,e);if(t>n)return{from:n,to:t}}return null});function ZL(e){return new Ln(WL,e,[],`markdown`)}var QL=ZL(KL),$L=ZL(KL.configure([YN,QN,ZN,$N,{props:[$n.add({Table:(e,t)=>({from:t.doc.lineAt(e.from).to,to:e.to})})]}]));function eR(e,t){return n=>{if(n&&e){let t=null;if(n=/\S*/.exec(n)[0],t=typeof e==`function`?e(n):Nn.matchLanguageName(e,n,!0),t instanceof Nn)return t.support?t.support.language.parser:Jn.getSkippingParser(t.load());if(t)return t.parser}return t?t.parser:null}}var tR=class{constructor(e,t,n,r,i,a,o){this.node=e,this.from=t,this.to=n,this.spaceBefore=r,this.spaceAfter=i,this.type=a,this.item=o}blank(e,t=!0){let n=this.spaceBefore+(this.node.name==`Blockquote`?`>`:``);if(e!=null){for(;n.length<e;)n+=` `;return n}else{for(let e=this.to-this.from-n.length-this.spaceAfter.length;e>0;e--)n+=` `;return n+(t?this.spaceAfter:``)}}marker(e,t){let n=this.node.name==`OrderedList`?String(+rR(this.item,e)[2]+t):``;return this.spaceBefore+n+this.type+this.spaceAfter}};function nR(e,t){let n=[],r=[];for(let t=e;t;t=t.parent){if(t.name==`FencedCode`)return r;(t.name==`ListItem`||t.name==`Blockquote`)&&n.push(t)}for(let e=n.length-1;e>=0;e--){let i=n[e],a,o=t.lineAt(i.from),s=i.from-o.from;if(i.name==`Blockquote`&&(a=/^ *>( ?)/.exec(o.text.slice(s))))r.push(new tR(i,s,s+a[0].length,``,a[1],`>`,null));else if(i.name==`ListItem`&&i.parent.name==`OrderedList`&&(a=/^( *)\d+([.)])( *)/.exec(o.text.slice(s)))){let e=a[3],t=a[0].length;e.length>=4&&(e=e.slice(0,e.length-4),t-=4),r.push(new tR(i.parent,s,s+t,a[1],e,a[2],i))}else if(i.name==`ListItem`&&i.parent.name==`BulletList`&&(a=/^( *)([-+*])( {1,4}\[[ xX]\])?( +)/.exec(o.text.slice(s)))){let e=a[4],t=a[0].length;e.length>4&&(e=e.slice(0,e.length-4),t-=4);let n=a[2];a[3]&&(n+=a[3].replace(/[xX]/,` `)),r.push(new tR(i.parent,s,s+t,a[1],e,n,i))}}return r}function rR(e,t){return/^(\s*)(\d+)(?=[.)])/.exec(t.sliceString(e.from,e.from+10))}function iR(e,t,n,r=0){for(let i=-1,a=e;;){if(a.name==`ListItem`){let e=rR(a,t),o=+e[2];if(i>=0){if(o!=i+1)return;n.push({from:a.from+e[1].length,to:a.from+e[0].length,insert:String(i+2+r)})}i=o}let e=a.nextSibling;if(!e)break;a=e}}function aR(e,t){let n=/^[ \t]*/.exec(e)[0].length;if(!n||t.facet(hn)!=` `)return e;let r=mn(e,4,n),i=``;for(let e=r;e>0;)e>=4?(i+=` `,e-=4):(i+=` `,e--);return i+e.slice(n)}var oR=((e={})=>({state:t,dispatch:n})=>{let r=Sn(t),{doc:i}=t,a=null,o=t.changeByRange(n=>{if(!n.empty||!$L.isActiveAt(t,n.from,-1)&&!$L.isActiveAt(t,n.from,1))return a={range:n};let o=n.from,s=i.lineAt(o),c=nR(r.resolveInner(o,-1),i);for(;c.length&&c[c.length-1].from>o-s.from;)c.pop();if(!c.length)return a={range:n};let l=c[c.length-1];if(l.to-l.spaceAfter.length>o-s.from)return a={range:n};let u=o>=l.to-l.spaceAfter.length&&!/\S/.test(s.text.slice(l.to));if(l.item&&u){let n=l.node.firstChild,r=l.node.getChild(`ListItem`,`ListItem`);if(n.to>=o||r&&r.to<o||s.from>0&&!/[^\s>]/.test(i.lineAt(s.from-1).text)||e.nonTightLists===!1){let e=c.length>1?c[c.length-2]:null,t,n=``;e&&e.item?(t=s.from+e.from,n=e.marker(i,1)):t=s.from+(e?e.to:0);let r=[{from:t,to:o,insert:n}];return l.node.name==`OrderedList`&&iR(l.item,i,r,-2),e&&e.node.name==`OrderedList`&&iR(e.item,i,r),{range:En.cursor(t+n.length),changes:r}}else{let e=lR(c,t,s);return{range:En.cursor(o+e.length+1),changes:{from:s.from,insert:e+t.lineBreak}}}}if(l.node.name==`Blockquote`&&u&&s.from){let e=i.lineAt(s.from-1),r=/>\s*$/.exec(e.text);if(r&&r.index==l.from){let i=t.changes([{from:e.from+r.index,to:e.to},{from:s.from+l.from,to:s.to}]);return{range:n.map(i),changes:i}}}let d=[];l.node.name==`OrderedList`&&iR(l.item,i,d);let f=l.item&&l.item.from<s.from,p=``;if(!f||/^[\s\d.)\-+*>]*/.exec(s.text)[0].length>=l.to)for(let e=0,t=c.length-1;e<=t;e++)p+=e==t&&!f?c[e].marker(i,1):c[e].blank(e<t?mn(s.text,4,c[e+1].from)-p.length:null);let m=o;for(;m>s.from&&/\s/.test(s.text.charAt(m-s.from-1));)m--;return p=aR(p,t),cR(l.node,t.doc)&&(p=lR(c,t,s)+t.lineBreak+p),d.push({from:m,to:o,insert:t.lineBreak+p}),{range:En.cursor(m+p.length+1),changes:d}});return a?!1:(n(t.update(o,{scrollIntoView:!0,userEvent:`input`})),!0)})();function sR(e){return e.name==`QuoteMark`||e.name==`ListMark`}function cR(e,t){if(e.name!=`OrderedList`&&e.name!=`BulletList`)return!1;let n=e.firstChild,r=e.getChild(`ListItem`,`ListItem`);if(!r)return!1;let i=t.lineAt(n.to),a=t.lineAt(r.from),o=/^[\s>]*$/.test(i.text);return i.number+ +!o<a.number}function lR(e,t,n){let r=``;for(let t=0,i=e.length-2;t<=i;t++)r+=e[t].blank(t<i?mn(n.text,4,e[t+1].from)-r.length:null,t<i);return aR(r,t)}function uR(e,t){let n=e.resolveInner(t,-1),r=t;sR(n)&&(r=n.from,n=n.parent);for(let e;e=n.childBefore(r);)if(sR(e))r=e.from;else if(e.name==`OrderedList`||e.name==`BulletList`)n=e.lastChild,r=n.to;else break;return n}var dR=[{key:`Enter`,run:oR},{key:`Backspace`,run:({state:e,dispatch:t})=>{let n=Sn(e),r=null,i=e.changeByRange(t=>{let i=t.from,{doc:a}=e;if(t.empty&&$L.isActiveAt(e,t.from)){let t=a.lineAt(i),r=nR(uR(n,i),a);if(r.length){let n=r[r.length-1],a=n.to-n.spaceAfter.length+ +!!n.spaceAfter;if(i-t.from>a&&!/\S/.test(t.text.slice(a,i-t.from)))return{range:En.cursor(t.from+a),changes:{from:t.from+a,to:i}};if(i-t.from==a&&(!n.item||t.from<=n.item.from||!/\S/.test(t.text.slice(0,n.to)))){let r=t.from+n.from;if(n.item&&n.node.from<n.item.from&&/\S/.test(t.text.slice(n.from,n.to))){let i=n.blank(mn(t.text,4,n.to)-mn(t.text,4,n.from));return r==t.from&&(i=aR(i,e)),{range:En.cursor(r+i.length),changes:{from:r,to:t.from+n.to,insert:i}}}if(r<i)return{range:En.cursor(r),changes:{from:r,to:i}}}}}return r={range:t}});return r?!1:(t(e.update(i,{scrollIntoView:!0,userEvent:`delete`})),!0)}}],fR=VL({matchClosingTags:!1});function pR(e={}){let{codeLanguages:t,defaultCodeLanguage:n,addKeymap:r=!0,base:{parser:i}=QL,completeHTMLTags:a=!0,pasteURLAsLink:o=!0,htmlTagLanguage:s=fR}=e;if(!(i instanceof tN))throw RangeError("Base parser provided to `markdown` should be a Markdown parser");let c=e.extensions?[e.extensions]:[],l=[s.support,XL],u;o&&l.push(vR),n instanceof Wn?(l.push(n.support),u=n.language):n&&(u=n);let d=t||u?eR(t,u):void 0;c.push(jN({codeParser:d,htmlParser:s.language.parser})),r&&l.push(Vn.high(Un.of(dR)));let f=ZL(i.configure(c));return a&&l.push(f.data.of({autocomplete:mR})),new Wn(f,l)}function mR(e){let{state:t,pos:n}=e,r=/<[:\-\.\w\u00b7-\uffff]*$/.exec(t.sliceDoc(n-25,n));if(!r)return null;let i=Sn(t).resolveInner(n,-1);for(;i&&!i.type.isTop;){if(i.name==`CodeBlock`||i.name==`FencedCode`||i.name==`ProcessingInstructionBlock`||i.name==`CommentBlock`||i.name==`Link`||i.name==`Image`)return null;i=i.parent}return{from:n-r[0].length,to:n,options:gR(),validFor:/^<[:\-\.\w\u00b7-\uffff]*$/}}var hR=null;function gR(){if(hR)return hR;let e=PL(new ir(gn.create({extensions:fR}),0,!0));return hR=e?e.options:[]}var _R=/code|horizontalrule|html|link|comment|processing|escape|entity|image|mark|url/i,vR=An.domEventHandlers({paste:(e,t)=>{let{main:n}=t.state.selection;if(n.empty)return!1;let r=e.clipboardData?.getData(`text/plain`);if(!r||!/^(https?:\/\/|mailto:|xmpp:|www\.)/.test(r)||(/^www\./.test(r)&&(r=`https://`+r),!$L.isActiveAt(t.state,n.from,1)))return!1;let i=Sn(t.state),a=!1;return i.iterate({from:n.from,to:n.to,enter:e=>{(e.from>n.from||_R.test(e.name))&&(a=!0)},leave:e=>{e.to<n.to&&(a=!0)}}),a?!1:(t.dispatch({changes:[{from:n.from,insert:`[`},{from:n.to,insert:`](${r})`}],userEvent:`input.paste`,scrollIntoView:!0}),!0)}});function yR(){return yR=Object.assign?Object.assign.bind():function(e){for(var t=1;t<arguments.length;t++){var n=arguments[t];for(var r in n)({}).hasOwnProperty.call(n,r)&&(e[r]=n[r])}return e},yR.apply(null,arguments)}var bR=e=>{var{theme:t,settings:n={},styles:r=[]}=e,i={".cm-gutters":{}},a={};n.background&&(a.backgroundColor=n.background),n.backgroundImage&&(a.backgroundImage=n.backgroundImage),n.foreground&&(a.color=n.foreground),n.fontSize&&(a.fontSize=n.fontSize),(n.background||n.foreground)&&(i[`&`]=a),n.fontFamily&&(i[`&.cm-editor .cm-scroller`]={fontFamily:n.fontFamily}),n.gutterBackground&&(i[`.cm-gutters`].backgroundColor=n.gutterBackground),n.gutterForeground&&(i[`.cm-gutters`].color=n.gutterForeground),n.gutterBorder&&(i[`.cm-gutters`].borderRightColor=n.gutterBorder),n.caret&&(i[`.cm-content`]={caretColor:n.caret},i[`.cm-cursor, .cm-dropCursor`]={borderLeftColor:n.caret});var o={};return n.gutterActiveForeground&&(o.color=n.gutterActiveForeground),n.lineHighlight&&(i[`.cm-activeLine`]={backgroundColor:n.lineHighlight},o.backgroundColor=n.lineHighlight),i[`.cm-activeLineGutter`]=o,n.selection&&(i[`&.cm-focused .cm-selectionBackground, & .cm-line::selection, & .cm-selectionLayer .cm-selectionBackground, .cm-content ::selection`]={background:n.selection+` !important`}),n.selectionMatch&&(i[`& .cm-selectionMatch`]={backgroundColor:n.selectionMatch}),[An.theme(i,{dark:t===`dark`}),xn(Yn.define(r))]},xR={background:`#2E3235`,foreground:`#DDDDDD`,caret:`#DDDDDD`,selection:`#202325`,selectionMatch:`#202325`,gutterBackground:`#292d30`,gutterForeground:`#808080`,gutterBorder:`1px solid #ffffff10`,lineHighlight:`#B9D2FF30`},SR=[{tag:K.keyword,color:`#fda331`},{tag:[K.name,K.deleted,K.character,K.propertyName,K.macroName],color:`#b5bd68`},{tag:[K.variableName],color:`#6fb3d2`},{tag:[K.function(K.variableName)],color:`#fda331`},{tag:[K.labelName],color:`#fc6d24`},{tag:[K.color,K.constant(K.name),K.standard(K.name)],color:`#fda331`},{tag:[K.definition(K.name),K.separator],color:`#cc99cc`},{tag:[K.brace],color:`#cc99cc`},{tag:[K.annotation],color:`#fc6d24`},{tag:[K.number,K.changed,K.annotation,K.modifier,K.self,K.namespace],color:`#fda331`},{tag:[K.typeName,K.className],color:`#6fb3d2`},{tag:[K.operator,K.operatorKeyword],color:`#cc99cc`},{tag:[K.tagName],color:`#fda331`},{tag:[K.squareBracket],color:`#cc99cc`},{tag:[K.angleBracket],color:`#cc99cc`},{tag:[K.attributeName],color:`#6fb3d2`},{tag:[K.regexp],color:`#fda331`},{tag:[K.quote],color:`#DDDDDD`},{tag:[K.string],color:`#b5bd68`},{tag:K.link,color:`#6987AF`,textDecoration:`underline`,textUnderlinePosition:`under`},{tag:[K.url,K.escape,K.special(K.string)],color:`#8abeb7`},{tag:[K.meta],color:`#A54543`},{tag:[K.comment],color:`#808080`,fontStyle:`italic`},{tag:K.monospace,color:`#DDDDDD`},{tag:K.strong,fontWeight:`bold`,color:`#fda331`},{tag:K.emphasis,fontStyle:`italic`,color:`#6fb3d2`},{tag:K.strikethrough,textDecoration:`line-through`},{tag:K.heading,fontWeight:`bold`,color:`#DDDDDD`},{tag:K.special(K.heading1),fontWeight:`bold`,color:`#DDDDDD`},{tag:K.heading1,fontWeight:`bold`,color:`#DDDDDD`},{tag:[K.heading2,K.heading3,K.heading4],fontWeight:`bold`,color:`#DDDDDD`},{tag:[K.heading5,K.heading6],color:`#DDDDDD`},{tag:[K.atom,K.bool,K.special(K.variableName)],color:`#8abeb7`},{tag:[K.processingInstruction,K.inserted],color:`#8abeb7`},{tag:[K.contentSeparator],color:`#6fb3d2`},{tag:K.invalid,color:`#B9D2FF`,borderBottom:`1px dotted #fc6d24`}],CR=e=>{var{theme:t=`dark`,settings:n={},styles:r=[]}=e||{};return bR({theme:t,settings:yR({},xR,n),styles:[...SR,...r]})};CR();var wR={background:`#ffffff`,foreground:`#2e3440`,caret:`#3b4252`,selection:`#eceff4`,selectionMatch:`#e5e9f0`,gutterBackground:`#eceff4`,gutterForeground:`#2e3440`,gutterBorder:`none`,lineHighlight:`#02255f11`},TR=[{tag:K.keyword,color:`#5e81ac`},{tag:[K.name,K.deleted,K.character,K.propertyName,K.macroName],color:`#d08770`},{tag:[K.variableName],color:`#d08770`},{tag:[K.function(K.variableName)],color:`#5e81ac`},{tag:[K.labelName],color:`#81a1c1`},{tag:[K.color,K.constant(K.name),K.standard(K.name)],color:`#5e81ac`},{tag:[K.definition(K.name),K.separator],color:`#a3be8c`},{tag:[K.brace],color:`#8fbcbb`},{tag:[K.annotation],color:`#d30102`},{tag:[K.number,K.changed,K.annotation,K.modifier,K.self,K.namespace],color:`#88c0d0`},{tag:[K.typeName,K.className],color:`#ebcb8b`},{tag:[K.operator,K.operatorKeyword],color:`#a3be8c`},{tag:[K.tagName],color:`#b48ead`},{tag:[K.squareBracket],color:`#bf616a`},{tag:[K.angleBracket],color:`#d08770`},{tag:[K.attributeName],color:`#ebcb8b`},{tag:[K.regexp],color:`#5e81ac`},{tag:[K.quote],color:`#3b4252`},{tag:[K.string],color:`#d08770`},{tag:K.link,color:`#8fbcbb`,textDecoration:`underline`,textUnderlinePosition:`under`},{tag:[K.url,K.escape,K.special(K.string)],color:`#d08770`},{tag:[K.meta],color:`#88c0d0`},{tag:[K.comment],color:`#434c5e`,fontStyle:`italic`},{tag:K.strong,fontWeight:`bold`,color:`#5e81ac`},{tag:K.emphasis,fontStyle:`italic`,color:`#5e81ac`},{tag:K.strikethrough,textDecoration:`line-through`},{tag:K.heading,fontWeight:`bold`,color:`#5e81ac`},{tag:K.special(K.heading1),fontWeight:`bold`,color:`#5e81ac`},{tag:K.heading1,fontWeight:`bold`,color:`#5e81ac`},{tag:[K.heading2,K.heading3,K.heading4],fontWeight:`bold`,color:`#5e81ac`},{tag:[K.heading5,K.heading6],color:`#5e81ac`},{tag:[K.atom,K.bool,K.special(K.variableName)],color:`#d08770`},{tag:[K.processingInstruction,K.inserted],color:`#8fbcbb`},{tag:[K.contentSeparator],color:`#ebcb8b`},{tag:K.invalid,color:`#434c5e`,borderBottom:`1px dotted #d30102`}],ER=e=>{var{theme:t=`light`,settings:n={},styles:r=[]}=e||{};return bR({theme:t,settings:yR({},wR,n),styles:[...TR,...r]})};ER();var DR=[Nn.of({name:`javascript`,alias:[`js`,`jsx`],extensions:[`js`,`mjs`,`cjs`,`jsx`],load:async()=>lL({jsx:!0})}),Nn.of({name:`typescript`,alias:[`ts`,`tsx`],extensions:[`ts`,`mts`,`cts`,`tsx`],load:async()=>lL({typescript:!0,jsx:!0})}),Nn.of({name:`json`,alias:[`jsonc`],extensions:[`json`,`jsonc`],load:()=>n(()=>import(`./dist-Gvva1zQ6.js`).then(e=>e.json()),__vite__mapDeps([25,26,4,27,28]),import.meta.url)}),Nn.of({name:`yaml`,alias:[`yml`],extensions:[`yaml`,`yml`],load:()=>n(()=>import(`./dist-DVWct0HX.js`).then(e=>e.yaml()),__vite__mapDeps([29,26,4,27,28]),import.meta.url)}),Nn.of({name:`css`,alias:[`scss`,`less`],extensions:[`css`,`scss`,`less`],load:async()=>sI()}),Nn.of({name:`html`,alias:[`htm`],extensions:[`html`,`htm`],load:async()=>VL()}),Nn.of({name:`python`,alias:[`py`],extensions:[`py`,`pyw`],load:()=>n(()=>import(`./dist-CSfB7p8y.js`).then(e=>e.python()),__vite__mapDeps([30,31,26,4,27,28]),import.meta.url)}),Nn.of({name:`rust`,alias:[`rs`],extensions:[`rs`],load:()=>n(()=>import(`./dist-BJPjDIRr.js`).then(e=>e.rust()),__vite__mapDeps([32,26,4,27,28]),import.meta.url)}),Nn.of({name:`markdown`,alias:[`md`,`mdx`],extensions:[`md`,`mdx`,`markdown`],load:async()=>pR()}),Nn.of({name:`bash`,alias:[`sh`,`shell`,`zsh`],extensions:[`sh`,`bash`,`zsh`],load:async()=>{let[{StreamLanguage:e,LanguageSupport:t},{shell:r}]=await Promise.all([n(()=>import(`./dist-BEF_m-Pp.js`).then(e=>e.m),__vite__mapDeps([26,4,27]),import.meta.url),n(()=>import(`./shell-DT_H80Gx.js`),[],import.meta.url)]);return new t(e.define(r))}}),Nn.of({name:`go`,alias:[`golang`],extensions:[`go`],load:async()=>{let[{StreamLanguage:e,LanguageSupport:t},{go:r}]=await Promise.all([n(()=>import(`./dist-BEF_m-Pp.js`).then(e=>e.m),__vite__mapDeps([26,4,27]),import.meta.url),n(()=>import(`./go-BRhAdNMM.js`),[],import.meta.url)]);return new t(e.define(r))}}),Nn.of({name:`math`,alias:[`latex`,`tex`],extensions:[`tex`,`latex`],load:async()=>{let[{StreamLanguage:e,LanguageSupport:t},{stex:r}]=await Promise.all([n(()=>import(`./dist-BEF_m-Pp.js`).then(e=>e.m),__vite__mapDeps([26,4,27]),import.meta.url),n(()=>import(`./stex-DQW679lh.js`),[],import.meta.url)]);return new t(e.define(r))}})],OR=Cn.define(),kR=Cn.define(),AR=Kn.line({class:`agent-flash`}),jR=Tn.define({create(){return Kn.none},update(e,t){e=e.map(t.changes);for(let n of t.effects)if(n.is(OR)){let{from:r,to:i}=n.value,a=[];for(let e=r;e<=i;){let n=t.state.doc.lineAt(e);a.push(AR.range(n.from)),e=n.to+1}e=e.update({add:a,sort:!0})}else n.is(kR)&&(e=Kn.none);return e},provide:e=>An.decorations.from(e)});function MR(e){let t=e.getMap(`agent-flash`);return[jR,jn.define(e=>{let n=0,r=Date.now(),i=null,a=null,o=!1;function s(){let t=e.state.doc.length;t!==0&&(o||(e.dispatch({effects:OR.of({from:0,to:t})}),a&&clearTimeout(a),a=setTimeout(()=>{a=null,!o&&e.dispatch({effects:kR.of(null)})},w)))}let l=e=>{if(ne(t),!c(t,r))return;r=Date.now();let a=Date.now();if(a-n<500){if(!i){let e=500-(a-n);i=setTimeout(()=>{i=null,n=Date.now(),s()},e)}return}n=a,s()};t.observe(l);let u=()=>{document.visibilityState===`visible`?c(t,r)&&(r=Date.now(),n=Date.now(),s()):r=Date.now()};return document.addEventListener(`visibilitychange`,u),{update(e){},destroy(){o=!0,t.unobserve(l),document.removeEventListener(`visibilitychange`,u),i&&=(clearTimeout(i),null),a&&=(clearTimeout(a),null)}}})]}var NR=/\[([^\]\n]*)\]\((<[^>\n]+>|[^)\s\n]+)(?:\s+(?:"[^"\n]*"|'[^'\n]*'|\([^)\n]*\)))?\)/g,PR=Kn.mark({class:`cm-md-internal-link`});function FR(e,t){return t>0&&e[t-1]===`!`}function IR(e){let t=e[2]??``;return t.startsWith(`<`)&&t.endsWith(`>`)?t.slice(1,-1):t}function LR(e){let t=new zn;for(let{from:n,to:r}of e.visibleRanges){let i=e.state.doc.sliceString(n,r);NR.lastIndex=0;let a=NR.exec(i);for(;a!==null;){let e=FR(i,a.index)?null:hk(IR(a));e&&e.kind!==`external`&&t.add(n+a.index,n+a.index+a[0].length,PR),a=NR.exec(i)}}return t.finish()}var RR=jn.fromClass(class{decorations;constructor(e){this.decorations=LR(e)}update(e){(e.docChanged||e.viewportChanged)&&(this.decorations=LR(e.view))}},{decorations:e=>e.decorations}),zR=An.domEventHandlers({mousedown(e,t){if(!e.ctrlKey&&!e.metaKey)return!1;let n=t.posAtCoords({x:e.clientX,y:e.clientY});if(n===null)return!1;let r=t.state.doc.lineAt(n);NR.lastIndex=0;let i=NR.exec(r.text);for(;i!==null;){let t=r.from+i.index,a=t+i[0].length;if(n>=t&&n<=a){let t=FR(r.text,i.index)?null:hk(IR(i));if(t&&t.kind!==`external`)return e.preventDefault(),t.kind===`doc`&&bk(e)?(yk(t),!0):(Sk(t),!0)}i=NR.exec(r.text)}return!1}}),BR=An.theme({".cm-md-internal-link":{color:`oklch(52.7% 0.154 228.4)`,fontWeight:`500`},".cm-md-internal-link:hover":{textDecoration:`underline`,cursor:`pointer`}});function VR(){return[RR,zR,BR]}var HR=5e3,UR=null,WR=0,GR=null,KR=new Map;async function qR(){let e=Date.now();return UR&&e-WR<HR?UR:(UR=await pA(),WR=e,GR=$R(UR),UR)}async function JR(e){let t=Date.now(),n=KR.get(e);if(n!==void 0&&t-n.time<HR)return n.headings;try{let n=await mA(e);return KR.set(e,{headings:n,time:t}),n}catch(n){return console.warn(`[wiki-link-source] /api/page-headings fetch failed:`,n),KR.set(e,{headings:[],time:t}),[]}}var YR=/\[\[[^\]]*?\]\]/g,XR=Kn.mark({class:`cm-wiki-link`}),ZR=Kn.mark({class:`cm-wiki-link cm-wiki-link-broken`});function QR(e){let t=new Set;for(let n of e)if(t.add(n.docName.toLowerCase()),n.title&&t.add(n.title.toLowerCase()),n.kind===`asset`){let e=n.docName.replace(/^\//,``);t.add(e.toLowerCase());let r=e.lastIndexOf(`/`);t.add((r===-1?e:e.slice(r+1)).toLowerCase())}return t}function $R(e){let t=QR(e);for(let n of e){if(n.kind===`asset`)continue;let e=n.docName.split(`/`);e.pop();let r=``;for(let n of e)r=r?`${r}/${n}`:n,t.add(r.toLowerCase())}return t}function ez(e){return e.split(/[#|]/)[0].trim().toLowerCase()}function tz(e){let t=new zn,n=UR?GR:null;for(let{from:r,to:i}of e.visibleRanges){let a=e.state.doc.sliceString(r,i);YR.lastIndex=0;let o=YR.exec(a);for(;o!==null;){let e=XR;if(n){let t=ez(o[0].slice(2,-2));t&&!n.has(t)&&(e=ZR)}t.add(r+o.index,r+o.index+o[0].length,e),o=YR.exec(a)}}return t.finish()}var nz=jn.fromClass(class{decorations;cacheWarmAtBuild;constructor(e){this.cacheWarmAtBuild=UR!==null,this.decorations=tz(e),this.cacheWarmAtBuild||this.warmCache(e)}update(e){let t=UR!==null;(e.docChanged||e.viewportChanged||!this.cacheWarmAtBuild&&t)&&(this.cacheWarmAtBuild=t,this.decorations=tz(e.view))}warmCache(e){qR().then(()=>{try{e.dispatch({})}catch{}}).catch(e=>{console.warn(`[wiki-link-source] warmCache fetch failed:`,e)})}},{decorations:e=>e.decorations}),rz=/\[\[([^[\]|#]+?)(?:#([^\]|]+?))?(?:\|([^\]]+?))?\]\]/g,iz=An.domEventHandlers({mousedown(e,t){if(!e.ctrlKey&&!e.metaKey)return!1;let n=t.posAtCoords({x:e.clientX,y:e.clientY});if(n===null)return!1;let r=t.state.doc.lineAt(n);rz.lastIndex=0;let i=rz.exec(r.text);for(;i!==null;){let t=r.from+i.index,a=t+i[0].length;if(n>=t&&n<=a){let t=i[1]?.trim(),n=i[2]?.trim()||null;if(t){let r=rt(t,n);if(!r)return!1;if(e.preventDefault(),r.kind===`external`)_k(r.url);else if(r.kind===`asset`){let t=dC(r.url,new Set((UR??[]).filter(e=>e.kind===`asset`).map(e=>e.docName.replace(/^\//,``))))??r.url.replace(/^\//,``);bk(e)?window.open(ot(t),`_blank`,`noopener,noreferrer`):window.location.hash=ot(t)}else bk(e)?yk(r):window.location.hash=r.anchor?`#/${r.docName}?anchor=${encodeURIComponent(r.anchor)}`:`#/${r.docName}`}return!0}i=rz.exec(r.text)}return!1}});async function az(e){let t=e.state.doc.sliceString(0,e.pos).match(/\[\[([^\]]*)$/);if(!t)return null;let n=t[1],r=e.pos-n.length,i=n.indexOf(`#`);if(i>0){let e=n.slice(0,i),t=n.slice(i+1),a=r+i+1,o=await JR(e);if(!o.length)return null;let s=cA(o,t);return s.length?{from:a,filter:!1,options:s.map(e=>({label:e.text,detail:`H${e.level}`,apply(t,n,r,i){let a=t.state.doc.sliceString(i,i+2)===`]]`?``:`]]`;t.dispatch({changes:{from:r,to:i,insert:e.slug+a},selection:{anchor:r+e.slug.length+a.length}})}}))}:null}return{from:r,filter:!1,options:aA(await qR().catch(e=>(console.warn(`[wiki-link-source] Failed to fetch pages:`,e),[])),n).map(e=>({label:e.title,detail:e.title===e.docName?void 0:e.docName,apply(t,n,r,i){let a=t.state.doc.sliceString(i,i+2)===`]]`?``:`]]`,o=e.kind===`asset`?`${e.docName}|${e.title}${a}`:e.docName+a;t.dispatch({changes:{from:r,to:i,insert:o},selection:{anchor:r+o.length}})}}))}}var oz=An.theme({".cm-wiki-link":{color:`oklch(52.7% 0.154 228.4)`,fontWeight:`500`},".cm-wiki-link:hover":{textDecoration:`underline`,cursor:`pointer`}});function sz(){return[nz,iz,oz,$L.data.of({autocomplete:az})]}var cz=CR({settings:{background:`transparent`,gutterBackground:`transparent`}}),lz=ER({settings:{background:`transparent`,gutterBackground:`transparent`},styles:[{tag:[K.brace,K.processingInstruction,K.inserted],color:`#3d6968`},{tag:K.link,color:`#3d6968`,textDecoration:`underline`,textUnderlinePosition:`under`},{tag:[K.keyword,K.function(K.variableName),K.regexp,K.color,K.constant(K.name),K.standard(K.name)],color:`#345575`},{tag:[K.heading,K.special(K.heading1),K.heading1,K.heading2,K.heading3,K.heading4],color:`#345575`,fontWeight:`bold`},{tag:[K.heading5,K.heading6],color:`#345575`},{tag:K.strong,color:`#345575`,fontWeight:`bold`},{tag:K.emphasis,color:`#345575`,fontStyle:`italic`},{tag:[K.name,K.deleted,K.character,K.propertyName,K.macroName,K.variableName,K.angleBracket,K.string,K.url,K.escape,K.special(K.string),K.atom,K.bool,K.special(K.variableName)],color:`#9a5739`},{tag:[K.number,K.changed,K.annotation,K.modifier,K.self,K.namespace,K.meta],color:`#3d6968`},{tag:[K.definition(K.name),K.separator,K.operator,K.operatorKeyword],color:`#4a6938`},{tag:[K.typeName,K.className,K.attributeName,K.contentSeparator],color:`#8b6500`},{tag:K.tagName,color:`#774d70`},{tag:K.squareBracket,color:`#964148`},{tag:K.labelName,color:`#3a5e85`}]});function uz(e){let{themeCompartment:t,resolvedTheme:n,ydoc:r}=e,i=n===`dark`?cz:lz;return[pR({base:$L,extensions:[YN],codeLanguages:DR}),sz(),VR(),...r?[MR(r)]:[],Un.of([]),t.of(i),An.lineWrapping,...e.extraKeymaps?[e.extraKeymaps]:[]]}function dz(e,t,n){let{state:r}=e,i=r.selection.main;if(!i.empty)return!1;if(t===`line`){let e=r.doc.lineAt(i.head);return n<0?e.from===0:e.to===r.doc.length}return n<0?i.head===0:i.head===r.doc.length}function fz(e){let{pmSel:t,nodePos:n,nodeSize:r,cmDocLen:i,cmSel:a,cmHasFocus:o}=e;if(t instanceof z&&t.from===n)return o?{kind:`noop`}:{kind:`focus`};let s=n+1,c=n+r-1;if(t.from>=s&&t.to<=c){let e=Math.max(0,Math.min(t.anchor-s,i)),n=Math.max(0,Math.min(t.head-s,i));return a.anchor===e&&a.head===n&&o?{kind:`noop`}:{kind:`selection`,anchor:e,head:n}}return{kind:`noop`}}function pz(e,t){let n=Rj().parseWithFallback(e),r;try{r=t.nodeFromJSON(n)}catch(e){return console.warn(JSON.stringify({event:`raw-mdx-upgrade-failure`,reason:e instanceof Error?e.message:String(e)})),null}if(r.childCount===0)return null;let i=[];for(let e=0;e<r.childCount;e++){let t=r.child(e);if(t.type.name===`rawMdxFallback`)return null;i.push(t)}return i}function mz(e,t){if(e===t)return null;let n=0,r=e.length,i=t.length;for(;n<r&&e.charCodeAt(n)===t.charCodeAt(n);)n++;for(;r>n&&i>n&&e.charCodeAt(r-1)===t.charCodeAt(i-1);)r--,i--;return{from:n,to:r,text:t.slice(n,i)}}var hz=`Unregistered component:`;function gz(e){if(!e.startsWith(hz))return null;let t=e.slice(23).trim();return t.length>0?t:null}function _z(e){let t=(0,Y.c)(49),{node:n,editor:r,getPos:i}=e,a=(0,q.useRef)(null),o=(0,q.useRef)(null),s=(0,q.useRef)(!1),c;t[0]===Symbol.for(`react.memo_cache_sentinel`)?(c=new Qn,t[0]=c):c=t[0];let l=(0,q.useRef)(c),{resolvedTheme:u}=Ie(),d=n.attrs.reason||`Parse failed`,f;t[1]===d?f=t[2]:(f=xM(d),t[1]=d,t[2]=f);let p=f,m=SM[p],h;t[3]!==d||t[4]!==p?(h=p===`info`?gz(d):null,t[3]=d,t[4]=p,t[5]=h):h=t[5];let g=h,_;t[6]!==r||t[7]!==i?(_=e=>{let t=typeof i==`function`?i():void 0;if(t===void 0)return;let n=yM(r);if(!n)return;let a=n.state.doc.nodeAt(t);if(!a||a.type.name!==`rawMdxFallback`)return;let o=t+1,c=t+a.nodeSize-1;s.current=!0;try{let t=n.state.tr;if(e.length===0)t.delete(o,c);else{let r=n.state.schema.text(e);t.replaceWith(o,c,r)}n.dispatch(t)}catch(e){let t=e;throw s.current=!1,t}s.current=!1},t[6]=r,t[7]=i,t[8]=_):_=t[8];let v=_,y;t[9]!==r||t[10]!==v||t[11]!==i||t[12]!==n.textContent||t[13]!==u?(y=()=>{let e=a.current;if(!e)return;let t=l.current,c=Un.of([{key:`Mod-z`,run:()=>(r.commands.undo(),!0)},{key:`Mod-y`,run:()=>(r.commands.redo(),!0)},{key:`Mod-Shift-z`,run:()=>(r.commands.redo(),!0)}]),d=e=>{let t=typeof i==`function`?i():void 0;if(typeof t!=`number`)return!1;let n=yM(r);if(!n)return!1;let a=n.state.doc.nodeAt(t);if(!a||a.type.name!==`rawMdxFallback`)return!1;let o=e<0?t:t+a.nodeSize,s=M.near(n.state.doc.resolve(o),e);return n.dispatch(n.state.tr.setSelection(s).scrollIntoView()),n.focus(),!0},f=Un.of([{key:`ArrowUp`,run:e=>dz(e,`line`,-1)?d(-1):!1},{key:`ArrowLeft`,run:e=>dz(e,`char`,-1)?d(-1):!1},{key:`ArrowDown`,run:e=>dz(e,`line`,1)?d(1):!1},{key:`ArrowRight`,run:e=>dz(e,`char`,1)?d(1):!1}]),p=uz({themeCompartment:t,resolvedTheme:u,ydoc:bM(r)??void 0,extraKeymaps:c});p.push(f),p.push(An.updateListener.of(e=>{if(e.docChanged&&!s.current&&v(e.state.doc.toString()),e.focusChanged&&e.view.hasFocus&&!s.current){let e=typeof i==`function`?i():void 0;if(typeof e!=`number`)return;let t=yM(r);if(!t)return;let n=t.state.selection;if(n instanceof z&&n.from===e)return;let a=t.state.doc.nodeAt(e);if(!a||a.type.name!==`rawMdxFallback`)return;s.current=!0;try{t.dispatch(t.state.tr.setSelection(z.create(t.state.doc,e)))}catch(e){let t=e;throw s.current=!1,t}s.current=!1}if(e.focusChanged&&!e.view.hasFocus&&!s.current){let t=typeof i==`function`?i():void 0;if(typeof t!=`number`)return;let n=yM(r);if(!n)return;let a=n.state.doc.nodeAt(t);if(!a||a.type.name!==`rawMdxFallback`)return;let o=pz(e.view.state.doc.toString(),n.state.schema);if(!o)return;s.current=!0;try{n.dispatch(n.state.tr.replaceWith(t,t+a.nodeSize,o))}catch(e){let t=e;throw s.current=!1,t}s.current=!1}}));let m=new An({doc:n.textContent,extensions:p,parent:e});o.current=m;let h=yz,g=m.contentDOM;g.addEventListener(`keydown`,h),g.addEventListener(`paste`,h),g.addEventListener(`drop`,h),g.addEventListener(`cut`,h);let _=()=>{g.removeEventListener(`keydown`,h),g.removeEventListener(`paste`,h),g.removeEventListener(`drop`,h),g.removeEventListener(`cut`,h)};return()=>{_(),m.destroy(),o.current=null}},t[9]=r,t[10]=v,t[11]=i,t[12]=n.textContent,t[13]=u,t[14]=y):y=t[14];let b;t[15]===Symbol.for(`react.memo_cache_sentinel`)?(b=[],t[15]=b):b=t[15],(0,q.useEffect)(y,b);let x,S;t[16]===u?(x=t[17],S=t[18]):(x=()=>{let e=o.current;if(!e)return;let t=u===`dark`?cz:lz;e.dispatch({effects:l.current.reconfigure(t)})},S=[u],t[16]=u,t[17]=x,t[18]=S),(0,q.useEffect)(x,S);let C,w;t[19]!==r||t[20]!==i?(w=()=>{let e=()=>{let e=typeof i==`function`?i():void 0;if(typeof e!=`number`)return;let t=o.current;if(!t||s.current)return;let n=yM(r);if(!n)return;let a=n.state.doc.nodeAt(e);if(!a)return;let c=fz({pmSel:n.state.selection,nodePos:e,nodeSize:a.nodeSize,cmDocLen:t.state.doc.length,cmSel:{anchor:t.state.selection.main.anchor,head:t.state.selection.main.head},cmHasFocus:t.hasFocus});if(c.kind!==`noop`){s.current=!0;try{c.kind===`selection`&&t.dispatch({selection:{anchor:c.anchor,head:c.head}}),t.hasFocus||t.focus()}catch(e){let t=e;throw s.current=!1,t}s.current=!1}};return r.on(`selectionUpdate`,e),()=>{r.off(`selectionUpdate`,e)}},C=[r,i],t[19]=r,t[20]=i,t[21]=C,t[22]=w):(C=t[21],w=t[22]),(0,q.useEffect)(w,C);let T=n.textContent,E,D;t[23]===T?(E=t[24],D=t[25]):(E=()=>{let e=o.current;if(!e||s.current)return;let t=mz(e.state.doc.toString(),T);if(t){s.current=!0;try{e.dispatch({changes:{from:t.from,to:t.to,insert:t.text}})}catch(e){let t=e;throw s.current=!1,t}s.current=!1}},D=[T],t[23]=T,t[24]=E,t[25]=D),(0,q.useEffect)(E,D);let O;t[26]!==r||t[27]!==i?(O=()=>{let e=typeof i==`function`?i():void 0;typeof e==`number`&&r.chain().focus().setNodeSelection(e).deleteSelection().run()},t[26]=r,t[27]=i,t[28]=O):O=t[28];let k=O,A=g?`raw-mdx-fallback-wrapper jsx-component-wrapper jsx-component-wrapper--unregistered relative my-2 py-2 rounded border border-dashed ${m.wrapperClass}`:`raw-mdx-fallback-wrapper relative my-2 py-2 rounded border border-dashed ${m.wrapperClass}`,j;t[29]===g?j=t[30]:(j=g?{"data-jsx-component":``,role:`group`,"aria-label":`Unknown component: ${g}`}:{},t[29]=g,t[30]=j);let N=j,P=`rounded px-1.5 py-0.5 text-[10px] font-semibold uppercase tracking-wider ${m.badgeClass}`,F;t[31]!==d||t[32]!==m.label||t[33]!==P?(F=(0,J.jsx)(`span`,{className:P,title:d,children:m.label}),t[31]=d,t[32]=m.label,t[33]=P,t[34]=F):F=t[34];let I;t[35]===Symbol.for(`react.memo_cache_sentinel`)?(I=(0,J.jsx)(Xr,{size:12}),t[35]=I):I=t[35];let L;t[36]===k?L=t[37]:(L=(0,J.jsx)(`button`,{type:`button`,className:`jsx-chrome-btn jsx-chrome-btn--delete`,"aria-label":`Delete block`,onClick:k,children:I}),t[36]=k,t[37]=L);let R;t[38]!==F||t[39]!==L?(R=(0,J.jsxs)(`div`,{className:`absolute top-1 right-1 z-10 flex items-center gap-1.5`,contentEditable:!1,onMouseDown:vz,children:[F,L]}),t[38]=F,t[39]=L,t[40]=R):R=t[40];let B=`Editing broken MDX source: ${d}`,V;t[41]===B?V=t[42]:(V=(0,J.jsx)(`div`,{ref:a,className:`raw-mdx-fallback-cm`,role:`group`,"aria-label":B}),t[41]=B,t[42]=V);let H;return t[43]!==p||t[44]!==R||t[45]!==V||t[46]!==N||t[47]!==A?(H=(0,J.jsxs)(oc,{className:A,contentEditable:!1,"data-drag-handle":``,draggable:`true`,"data-severity":p,...N,children:[R,V]}),t[43]=p,t[44]=R,t[45]=V,t[46]=N,t[47]=A,t[48]=H):H=t[48],H}function vz(e){return e.stopPropagation()}function yz(){}function bz(e,t){if(!e.selection.empty)return null;let n=t===`up`||t===`left`?-1:1,r=e.selection.$head,i=n>0?r.after():r.before();if(typeof i!=`number`)return null;let a=M.near(e.doc.resolve(i),n);return a.$head?.parent.type.name===`rawMdxFallback`?a:null}function xz(e,t){let{state:n,view:r}=e;if(!r.endOfTextblock(t))return!1;let i=bz(n,t);return i?(r.dispatch(n.tr.setSelection(i)),!0):!1}var Sz=it.extend({addKeyboardShortcuts(){return{ArrowLeft:({editor:e})=>xz(e,`left`),ArrowRight:({editor:e})=>xz(e,`right`),ArrowUp:({editor:e})=>xz(e,`up`),ArrowDown:({editor:e})=>xz(e,`down`)}},addNodeView(){return mc(_z,{stopEvent:()=>!0,ignoreMutation:()=>!0})}});function Cz(e){let t=(0,Y.c)(47),{items:n,selectedIndex:r,categoryLabels:i,onSelect:a,onHoverIndex:o}=e,s=(0,q.useRef)(null),c=(0,q.useId)(),l=r>=0&&r<n.length?`${c}-option-${r}`:void 0,u=Tz,d,f;if(t[0]===r?(d=t[1],f=t[2]):(d=()=>{let e=s.current;if(!e)return;let t=e.querySelectorAll(`[role="option"]`).item(r);t&&t.scrollIntoView({block:`nearest`})},f=[r],t[0]=r,t[1]=d,t[2]=f),(0,q.useEffect)(d,f),n.length===0){let e;return t[3]===Symbol.for(`react.memo_cache_sentinel`)?(e=(0,J.jsx)(`div`,{ref:s,role:`status`,"aria-live":`polite`,className:`w-56 rounded-lg border bg-popover p-2 shadow-md text-sm text-muted-foreground`,style:{maxHeight:`var(--suggestion-menu-max-height, 40vh)`},onMouseDown:u,children:`No results`}),t[3]=e):e=t[3],e}let p,m,h,g,_,v,y,b,x,S,C,w,T;if(t[4]!==l||t[5]!==i||t[6]!==n||t[7]!==c||t[8]!==o||t[9]!==a||t[10]!==r){let e=[],d=0,f=new Map;for(let t of n){f.set(t,d++);let n=e.find(e=>e.key===t.category);n?n.items.push(t):e.push({key:t.category,items:[t]})}m=r>=0&&r<n.length?n[r]:null;let E;t[24]===n?E=t[25]:(E=n.some(wz),t[24]=n,t[25]=E),p=E,v=`flex items-start gap-2`,y=s,b=`listbox`,x=`Slash commands`,S=l,C=-1,w=u,T=`w-56 overflow-y-auto subtle-scrollbar rounded-lg border bg-popover p-1 shadow-md`,t[26]===Symbol.for(`react.memo_cache_sentinel`)?(h={maxHeight:`var(--suggestion-menu-max-height, 40vh)`},t[26]=h):h=t[26];let D=m?`${m.label}${m.preview?`. ${m.preview.description}`:``}`:``;t[27]===D?g=t[28]:(g=(0,J.jsx)(`span`,{className:`sr-only`,"aria-live":`polite`,"aria-atomic":`true`,children:D}),t[27]=D,t[28]=g),_=e.map(e=>(0,J.jsxs)(`div`,{role:`group`,"aria-labelledby":`${c}-group-${e.key}`,children:[(0,J.jsx)(`div`,{id:`${c}-group-${e.key}`,className:`px-2 py-1.5 text-xs font-semibold text-muted-foreground`,children:i[e.key]??e.key}),e.items.map(e=>{let t=f.get(e)??0,n=t===r,i=e.icon;return(0,J.jsxs)(`button`,{id:`${c}-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`:``}`,onMouseEnter:()=>o?.(t),onMouseDown:t=>{t.preventDefault(),a(e)},children:[(0,J.jsx)(i,{className:`size-4 shrink-0 text-muted-foreground`}),(0,J.jsx)(`div`,{className:`flex flex-col min-w-0`,children:(0,J.jsx)(`span`,{className:`truncate`,children:e.label})})]},e.name)})]},e.key)),t[4]=l,t[5]=i,t[6]=n,t[7]=c,t[8]=o,t[9]=a,t[10]=r,t[11]=p,t[12]=m,t[13]=h,t[14]=g,t[15]=_,t[16]=v,t[17]=y,t[18]=b,t[19]=x,t[20]=S,t[21]=C,t[22]=w,t[23]=T}else p=t[11],m=t[12],h=t[13],g=t[14],_=t[15],v=t[16],y=t[17],b=t[18],x=t[19],S=t[20],C=t[21],w=t[22],T=t[23];let E;t[29]!==h||t[30]!==g||t[31]!==_||t[32]!==y||t[33]!==b||t[34]!==x||t[35]!==S||t[36]!==C||t[37]!==w||t[38]!==T?(E=(0,J.jsxs)(`div`,{ref:y,role:b,"aria-label":x,"aria-activedescendant":S,tabIndex:C,onMouseDown:w,className:T,style:h,children:[g,_]}),t[29]=h,t[30]=g,t[31]=_,t[32]=y,t[33]=b,t[34]=x,t[35]=S,t[36]=C,t[37]=w,t[38]=T,t[39]=E):E=t[39];let D;t[40]!==p||t[41]!==m?(D=p?(0,J.jsx)(`aside`,{"aria-hidden":`true`,onMouseDown:u,className:`w-64 rounded-lg border bg-popover p-2 shadow-md ${m?.preview?``:`invisible`}`,children:m?.preview?(0,J.jsxs)(J.Fragment,{children:[(0,J.jsx)(`div`,{className:`mb-2 flex aspect-5/3 items-center justify-center overflow-hidden rounded-md bg-muted/40 p-3 *:max-h-full *:max-w-full [&_img]:size-full [&_img]:rounded-md [&_img]:object-contain`,children:m.preview.render()}),(0,J.jsx)(`p`,{className:`px-1 pb-1 text-xs text-muted-foreground`,children:m.preview.description})]}):null}):null,t[40]=p,t[41]=m,t[42]=D):D=t[42];let O;return t[43]!==v||t[44]!==E||t[45]!==D?(O=(0,J.jsxs)(`div`,{className:v,children:[E,D]}),t[43]=v,t[44]=E,t[45]=D,t[46]=O):O=t[46],O}function wz(e){return e.preview}function Tz(e){return e.preventDefault()}var Ez=new T(`slashCommand`),Dz=Fe.create({name:`slashCommand`,addOptions(){return{itemsSources:[()=>dT],categoryLabels:{basic:`Basic blocks`,insert:`Insert`}}},addProseMirrorPlugins(){let e=this;return[nv({editor:this.editor,pluginKey:Ez,char:`/`,startOfLine:!1,items:({query:t})=>{let n=e.options.itemsSources.flatMap(e=>{try{return e()}catch(e){return console.error(`[slash-command] item source threw an error`,e),[]}}),r=Object.keys(e.options.categoryLabels),i=e=>{let t=r.indexOf(e);return t===-1?1/0:t};return fT(n.map((e,t)=>({item:e,i:t})).sort((e,t)=>{let n=i(e.item.category)-i(t.item.category);return n===0?e.i-t.i:n}).map(e=>e.item),t)},command:({editor:e,range:t,props:n})=>{try{e.chain().focus().deleteRange(t).run()}catch(e){console.error(`[slash-command] deleteRange failed for "${n.name}"`,e);return}try{n.command(e)}catch(e){console.error(`[slash-command] command "${n.name}" threw an error`,e)}},render:()=>{let t=null,n=null,r=0,i={popup:null,stopAutoUpdate:null},a=null,o=e=>{e!==r&&(r=e,s())},s=()=>{!t||!n||t.updateProps({items:n.items,selectedIndex:r,categoryLabels:e.options.categoryLabels,onSelect:n.command,onHoverIndex:o})};return{onStart(s){n=s,r=0;let c=sv(()=>n,`slash-command`);i.popup=c.popup,a=c.doPosition,t=new fc(Cz,{props:{items:s.items,selectedIndex:r,categoryLabels:e.options.categoryLabels,onSelect:s.command,onHoverIndex:o},editor:s.editor}),c.popup.appendChild(t.element),i.stopAutoUpdate=c.startAutoUpdate(),c.reveal()},onUpdate(e){n=e,r=Math.min(r,Math.max(0,e.items.length-1)),s(),a?.()},onKeyDown({event:e}){if(!n||n.items.length===0)return!1;let t=n.items;if(e.key===`ArrowDown`)return r=(r+1)%t.length,s(),!0;if(e.key===`ArrowUp`)return r=(r-1+t.length)%t.length,s(),!0;if(e.key===`Enter`||e.key===`Tab`){let e=t[r];return e&&n.command(e),!0}return e.key,!1},onExit(){cv(i),a=null,t?.destroy(),t=null,n=null,r=0}}}})]}}),Oz=new T(`sourceDirty`),kz=Fe.create({name:`sourceDirtyObserver`,addProseMirrorPlugins(){return[new v({key:Oz,appendTransaction(e,t,n){if(!e.some(e=>!e.getMeta(_T))||!e.some(e=>e.docChanged))return null;let r=new u;for(let t of e)r.appendMapping(t.mapping);let i=r.invert(),a=[];if(n.doc.descendants((e,n)=>{if(e.type.name!==`jsxComponent`||e.attrs.sourceDirty)return;let r=i.map(n),o=t.doc.nodeAt(r),s=!o||o.type.name!==`jsxComponent`,c=typeof e.attrs.sourceRaw==`string`&&e.attrs.sourceRaw.length>0;if(s&&c)return;if(!o){(e.content.size>0||Object.keys(e.attrs.props??{}).length>0)&&a.push({pos:n});return}if(o.type.name!==`jsxComponent`){a.push({pos:n});return}let l=!Az(o.attrs.props,e.attrs.props),u=!o.content.eq(e.content);(l||u)&&a.push({pos:n})}),a.length===0)return null;let o=n.tr;for(let{pos:e}of a)o.setNodeAttribute(e,`sourceDirty`,!0);return o}})]}});function Az(e,t){if(Object.is(e,t))return!0;if(e==null||t==null||typeof e!=typeof t||typeof e!=`object`)return!1;if(Array.isArray(e)){if(!Array.isArray(t)||e.length!==t.length)return!1;for(let n=0;n<e.length;n++)if(!Az(e[n],t[n]))return!1;return!0}let n=Object.keys(e),r=Object.keys(t);if(n.length!==r.length)return!1;for(let r of n)if(!Az(e[r],t[r]))return!1;return!0}var jz=`ok:tag-click`;function Mz(e){if(typeof document>`u`)return;let t={value:e};document.dispatchEvent(new CustomEvent(jz,{detail:t}))}function Nz(e){return e instanceof Element?e.closest(`a[data-tag]`):null}var Pz=Fe.create({name:`tagClick`,addProseMirrorPlugins(){return[new v({props:{handleDOMEvents:{click(e,t){let n=Nz(t.target);if(!n)return!1;let r=n.getAttribute(`data-tag`);return r?(t.preventDefault(),t.stopPropagation(),Mz(r),!0):!1}}}})]}});function Fz(e,t,n){if(typeof t!=`number`||!n||!j.test(n))return!1;let{state:r,view:i}=e,a=r.doc.nodeAt(t);if(!a||a.type.name!==`tag`)return!1;let o=r.tr.setNodeMarkup(t,null,{...a.attrs,value:n}),s=t+a.nodeSize;return o.insertText(` `,s),o.setSelection(Ct.create(o.doc,s+1)),i.dispatch(o),i.focus(),!0}function Iz(e,t){if(typeof t!=`number`)return;let{state:n,view:r}=e,i=n.doc.nodeAt(t);if(!i||i.type.name!==`tag`)return;let a=n.tr.delete(t,t+i.nodeSize);r.dispatch(a),r.focus()}function Lz(e){let t=(0,Y.c)(3),{value:n}=e,r=`#tag/${n}`,i;return t[0]!==r||t[1]!==n?(i=(0,J.jsxs)(`a`,{className:`tag`,"data-tag":n,href:r,children:[`#`,n]}),t[0]=r,t[1]=n,t[2]=i):i=t[2],i}function Rz(e){let t=(0,Y.c)(14),{initialDraft:n,onCommit:r,onCancel:i}=e,a=(0,q.useRef)(null),[o,s]=(0,q.useState)(n),c=(0,q.useRef)(!1),l,u;t[0]===Symbol.for(`react.memo_cache_sentinel`)?(l=()=>{let e=requestAnimationFrame(()=>{a.current?.focus()});return()=>cancelAnimationFrame(e)},u=[],t[0]=l,t[1]=u):(l=t[0],u=t[1]),(0,q.useEffect)(l,u);let d;t[2]===Symbol.for(`react.memo_cache_sentinel`)?(d=(0,J.jsx)(`span`,{"aria-hidden":`true`,className:`font-mono`,children:`#`}),t[2]=d):d=t[2];let f=Math.max(o.length,8),p;t[3]===Symbol.for(`react.memo_cache_sentinel`)?(p=e=>{let t=e.target.value;(t===``||j.test(t))&&s(t)},t[3]=p):p=t[3];let m,h;t[4]!==o||t[5]!==i||t[6]!==r?(m=e=>{e.key===`Enter`||e.key===` `?(e.preventDefault(),c.current=!0,r(o)||(c.current=!1,i())):(e.key===`Escape`||e.key===`Backspace`&&o===``)&&(e.preventDefault(),i())},h=()=>{if(!c.current){if(o===``){i();return}j.test(o)?r(o):i()}},t[4]=o,t[5]=i,t[6]=r,t[7]=m,t[8]=h):(m=t[7],h=t[8]);let g;return t[9]!==o||t[10]!==f||t[11]!==m||t[12]!==h?(g=(0,J.jsxs)(`span`,{className:`tag tag-placeholder inline-flex items-center rounded-sm border border-dashed border-muted-foreground/40 bg-muted/30 px-1.5 py-0.5 text-xs text-muted-foreground`,"data-component-type":`tag-placeholder`,children:[d,(0,J.jsx)(`input`,{ref:a,type:`text`,value:o,size:f,placeholder:`tag-name`,"aria-label":`Tag value`,spellCheck:!1,autoCorrect:`off`,autoCapitalize:`off`,className:`bg-transparent border-0 p-0 outline-none focus:outline-none focus:ring-0 text-inherit font-inherit`,onChange:p,onKeyDown:m,onBlur:h})]}),t[9]=o,t[10]=f,t[11]=m,t[12]=h,t[13]=g):g=t[13],g}function zz(e){let t=(0,Y.c)(5),{node:n,getPos:r,editor:i}=e,a=typeof n.attrs.value==`string`?n.attrs.value:``;if(a===``){let e;return t[0]!==i||t[1]!==r?(e=(0,J.jsx)(oc,{as:`span`,children:(0,J.jsx)(Rz,{initialDraft:``,onCommit:e=>Fz(i,typeof r==`function`?r():void 0,e),onCancel:()=>Iz(i,typeof r==`function`?r():void 0)})}),t[0]=i,t[1]=r,t[2]=e):e=t[2],e}let o;return t[3]===a?o=t[4]:(o=(0,J.jsx)(oc,{as:`span`,children:(0,J.jsx)(Lz,{value:a})}),t[3]=a,t[4]=o),o}var Bz=V.extend({priority:200,addNodeView(){return mc(zz)},addKeyboardShortcuts(){return{Backspace:()=>{if(lv.getState(this.editor.state)?.active)return!1;let{selection:e}=this.editor.state;if(!e.empty)return!1;let t=e.$from.nodeBefore;if(t?.type.name===`tag`){let{state:n,view:r}=this.editor;return r.dispatch(n.tr.delete(e.from-t.nodeSize,e.from)),!0}return!1},Delete:()=>{if(lv.getState(this.editor.state)?.active)return!1;let{selection:e}=this.editor.state;if(!e.empty)return!1;let t=e.$from.nodeAfter;if(t?.type.name===`tag`){let{state:n,view:r}=this.editor;return r.dispatch(n.tr.delete(e.from,e.from+t.nodeSize)),!0}return!1}}},addProseMirrorPlugins(){return[gv(this.editor)]}});function Vz(e){let t=(0,Y.c)(116),{open:n,target:r,alias:i,anchor:a,pages:o,assetPaths:s,onOpenChange:c,onSave:l}=e,[u,d]=(0,q.useState)(r),[f,p]=(0,q.useState)(i??``),[m,h]=(0,q.useState)(a??``),g=(0,q.useId)(),_=(0,q.useId)(),v=(0,q.useId)(),y=(0,q.useId)(),b;t[0]!==s||t[1]!==u?(b=dC(u,s),t[0]=s,t[1]=u,t[2]=b):b=t[2];let x=b,S;t[3]!==s||t[4]!==u||t[5]!==o?(S=fC(u,o,s),t[3]=s,t[4]=u,t[5]=o,t[6]=S):S=t[6];let C=gA(u,S&&!x&&n),w,T;t[7]!==i||t[8]!==a||t[9]!==n||t[10]!==r?(w=()=>{n&&(d(r),p(i??``),h(a??``))},T=[n,r,i,a],t[7]=i,t[8]=a,t[9]=n,t[10]=r,t[11]=w,t[12]=T):(w=t[11],T=t[12]),(0,q.useEffect)(w,T);let E;t[13]!==f||t[14]!==m||t[15]!==u||t[16]!==c||t[17]!==l?(E=function(){let e=u.trim();e&&(l(e,f.trim()||null,m.trim()||null),c(!1))},t[13]=f,t[14]=m,t[15]=u,t[16]=c,t[17]=l,t[18]=E):E=t[18];let D=E,O;t[19]===D?O=t[20]:(O=function(e){e.key===`Enter`&&D()},t[19]=D,t[20]=O);let k=O,A,j,M,N,P,F,I,L,R,z,B,V,H,U,W,ee;if(t[21]!==_||t[22]!==m||t[23]!==u||t[24]!==k||t[25]!==y||t[26]!==C||t[27]!==c||t[28]!==n||t[29]!==g){let e=new Map,r=C?.map(t=>{let n=e.get(t.slug)??0;e.set(t.slug,n+1);let r=n===0?t.slug:`${t.slug}-${n}`;return{...t,reactKey:r}}),i=!!r?.length;M=Qt,V=n,H=c,j=tn,t[46]===Symbol.for(`react.memo_cache_sentinel`)?(B=(0,J.jsx)(an,{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[46]=B):B=t[46],A=Yt,F=`dialog-content`,I=``,L=`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`,t[47]===Symbol.for(`react.memo_cache_sentinel`)?(R=(0,J.jsx)(Zt,{className:`mb-1 text-base font-semibold`,children:`Edit wiki link`}),z=(0,J.jsx)(Xt,{className:`mb-4 text-sm text-muted-foreground`,children:`Modify the link target, anchor, and display label.`}),t[47]=R,t[48]=z):(R=t[47],z=t[48]),N=`mb-4 space-y-6`;let a;t[49]===Symbol.for(`react.memo_cache_sentinel`)?(a=(0,J.jsx)(`span`,{className:`text-red-500`,children:`*`}),t[49]=a):a=t[49];let o;t[50]===g?o=t[51]:(o=(0,J.jsxs)(`label`,{className:`mb-1.5 block text-sm font-medium`,htmlFor:g,children:[`Page `,a]}),t[50]=g,t[51]=o);let s;t[52]===Symbol.for(`react.memo_cache_sentinel`)?(s=e=>d(e.target.value),t[52]=s):s=t[52];let l;t[53]!==u||t[54]!==k||t[55]!==g?(l=(0,J.jsx)(zo,{id:g,value:u,onChange:s,placeholder:`page-name`,autoFocus:!0,"aria-required":`true`,onKeyDown:k}),t[53]=u,t[54]=k,t[55]=g,t[56]=l):l=t[56],t[57]!==o||t[58]!==l?(P=(0,J.jsxs)(`div`,{children:[o,l]}),t[57]=o,t[58]=l,t[59]=P):P=t[59];let f;t[60]===Symbol.for(`react.memo_cache_sentinel`)?(f=(0,J.jsx)(`span`,{className:`font-normal text-muted-foreground`,children:`(optional heading anchor)`}),t[60]=f):f=t[60],t[61]===_?U=t[62]:(U=(0,J.jsxs)(`label`,{className:`mb-1.5 block text-sm font-medium`,htmlFor:_,children:[`Section`,` `,f]}),t[61]=_,t[62]=U);let p;t[63]===Symbol.for(`react.memo_cache_sentinel`)?(p=e=>h(e.target.value),t[63]=p):p=t[63],t[64]!==_||t[65]!==m||t[66]!==k?(W=(0,J.jsx)(zo,{id:_,value:m,onChange:p,placeholder:`heading-slug`,onKeyDown:k}),t[64]=_,t[65]=m,t[66]=k,t[67]=W):W=t[67],ee=i&&(0,J.jsx)(`div`,{role:`listbox`,id:y,"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:r.map(e=>(0,J.jsxs)(`button`,{type:`button`,role:`option`,"aria-selected":m===e.slug,className:Lt(`flex w-full items-center gap-2 px-2 py-1 text-left text-sm hover:bg-accent hover:text-accent-foreground`,m===e.slug&&`bg-accent text-accent-foreground`),style:{paddingLeft:`${(e.level-1)*12+8}px`},onClick:()=>h(m===e.slug?``:e.slug),children:[(0,J.jsxs)(`span`,{className:`w-7 shrink-0 font-mono text-[10px] text-muted-foreground`,children:[`H`,e.level]}),(0,J.jsx)(`span`,{className:`truncate`,children:e.text})]},e.reactKey))}),t[21]=_,t[22]=m,t[23]=u,t[24]=k,t[25]=y,t[26]=C,t[27]=c,t[28]=n,t[29]=g,t[30]=A,t[31]=j,t[32]=M,t[33]=N,t[34]=P,t[35]=F,t[36]=I,t[37]=L,t[38]=R,t[39]=z,t[40]=B,t[41]=V,t[42]=H,t[43]=U,t[44]=W,t[45]=ee}else A=t[30],j=t[31],M=t[32],N=t[33],P=t[34],F=t[35],I=t[36],L=t[37],R=t[38],z=t[39],B=t[40],V=t[41],H=t[42],U=t[43],W=t[44],ee=t[45];let te;t[68]!==U||t[69]!==W||t[70]!==ee?(te=(0,J.jsxs)(`div`,{children:[U,W,ee]}),t[68]=U,t[69]=W,t[70]=ee,t[71]=te):te=t[71];let ne;t[72]===Symbol.for(`react.memo_cache_sentinel`)?(ne=(0,J.jsx)(`span`,{className:`font-normal text-muted-foreground`,children:`(optional display text)`}),t[72]=ne):ne=t[72];let re;t[73]===v?re=t[74]:(re=(0,J.jsxs)(`label`,{className:`mb-1.5 block text-sm font-medium`,htmlFor:v,children:[`Label`,` `,ne]}),t[73]=v,t[74]=re);let ie;t[75]===Symbol.for(`react.memo_cache_sentinel`)?(ie=e=>p(e.target.value),t[75]=ie):ie=t[75];let ae;t[76]!==v||t[77]!==f||t[78]!==k?(ae=(0,J.jsx)(zo,{id:v,value:f,onChange:ie,placeholder:`Custom display text`,onKeyDown:k}),t[76]=v,t[77]=f,t[78]=k,t[79]=ae):ae=t[79];let oe;t[80]!==re||t[81]!==ae?(oe=(0,J.jsxs)(`div`,{children:[re,ae]}),t[80]=re,t[81]=ae,t[82]=oe):oe=t[82];let se;t[83]!==N||t[84]!==P||t[85]!==te||t[86]!==oe?(se=(0,J.jsxs)(`div`,{className:N,children:[P,te,oe]}),t[83]=N,t[84]=P,t[85]=te,t[86]=oe,t[87]=se):se=t[87];let ce;t[88]===c?ce=t[89]:(ce=(0,J.jsx)(zt,{variant:`outline`,onClick:()=>c(!1),children:`Cancel`}),t[88]=c,t[89]=ce);let le;t[90]===u?le=t[91]:(le=u.trim(),t[90]=u,t[91]=le);let ue=!le,de;t[92]!==D||t[93]!==ue?(de=(0,J.jsx)(zt,{onClick:D,disabled:ue,children:`Save`}),t[92]=D,t[93]=ue,t[94]=de):de=t[94];let fe;t[95]!==ce||t[96]!==de?(fe=(0,J.jsxs)(`div`,{className:`flex justify-end gap-2`,children:[ce,de]}),t[95]=ce,t[96]=de,t[97]=fe):fe=t[97];let pe;t[98]!==A||t[99]!==F||t[100]!==I||t[101]!==L||t[102]!==R||t[103]!==z||t[104]!==se||t[105]!==fe?(pe=(0,J.jsxs)(A,{"data-slot":F,"data-ok-layer-spawned":I,className:L,children:[R,z,se,fe]}),t[98]=A,t[99]=F,t[100]=I,t[101]=L,t[102]=R,t[103]=z,t[104]=se,t[105]=fe,t[106]=pe):pe=t[106];let me;t[107]!==j||t[108]!==B||t[109]!==pe?(me=(0,J.jsxs)(j,{children:[B,pe]}),t[107]=j,t[108]=B,t[109]=pe,t[110]=me):me=t[110];let he;return t[111]!==M||t[112]!==V||t[113]!==H||t[114]!==me?(he=(0,J.jsx)(M,{open:V,onOpenChange:H,children:me}),t[111]=M,t[112]=V,t[113]=H,t[114]=me,t[115]=he):he=t[115],he}function Hz(e){let t=(0,Y.c)(135),{editor:n,getPos:r,onClose:i}=e,a=r(),o=a==null?null:n.state.doc.nodeAt(a),s=String(o?.attrs.target??``),c=pe(o?.attrs.alias),l=pe(o?.attrs.anchor),u=Ue({target:s,alias:c,anchor:l}),{assetPaths:d,folderPaths:f,pages:p,pagesBySlug:m,loading:h}=we(),g=rt(s,l),_=g?.kind===`external`?g:null,v=g?.kind===`asset`?dC(g.url,d):null,y=v?null:kk(s,{pages:p,folderPaths:f,pagesBySlug:m,fallbackTargets:lC(s)}),[b,x]=(0,q.useState)(!1),[S,C]=(0,q.useState)(null),w=y?Ak(y):null;if(!o)return null;let T;t[0]!==n.state||t[1]!==n.view||t[2]!==r?(T=function(e,t,i){let a=r();a!=null&&n.view.dispatch(n.state.tr.setNodeMarkup(a,void 0,{...n.state.doc.nodeAt(a)?.attrs,target:e,alias:t,anchor:i}))},t[0]=n.state,t[1]=n.view,t[2]=r,t[3]=T):T=t[3];let E=T,D;t[4]!==n.state||t[5]!==n.view||t[6]!==r||t[7]!==i?(D=function(){let e=r();if(e==null)return;let t=n.state.doc.nodeAt(e);t&&(n.view.dispatch(n.state.tr.delete(e,e+t.nodeSize)),i())},t[4]=n.state,t[5]=n.view,t[6]=r,t[7]=i,t[8]=D):D=t[8];let O=D,k;t[9]!==l||t[10]!==v||t[11]!==_||t[12]!==y||t[13]!==C?(k=function(e){if(_){pk(_.url)?window.open(_.url,`_blank`,`noopener,noreferrer`):console.warn(`[safe-nav] blocked non-safe scheme:`,_.url);return}if(v){let t=ot(v);e.newTab?window.open(t,`_blank`,`noopener,noreferrer`):window.location.hash=t;return}if(!y)return;if(y.kind===`create`){C(`missing`);return}let t=y.hashDocName;if(e.newTab){yk({docName:t,anchor:l});return}if(l){let e=window.location.hash.match(/^#\/([^?#/]+)/);if((e?decodeURIComponent(e[1]):null)===t){let e=document.getElementById(l);e&&e.scrollIntoView({behavior:`smooth`,block:`start`})}window.location.hash=`#/${t}?anchor=${encodeURIComponent(l)}`;return}window.location.hash=`#/${t}`},t[9]=l,t[10]=v,t[11]=_,t[12]=y,t[13]=C,t[14]=k):k=t[14];let A=k,j;t[15]!==c||t[16]!==S||t[17]!==n.state||t[18]!==n.view||t[19]!==r||t[20]!==u||t[21]!==s?(j=function(e){if(S===`missing`&&e!==s){let t=r();if(t==null)return;n.view.dispatch(n.state.tr.setNodeMarkup(t,void 0,{...n.state.doc.nodeAt(t)?.attrs,target:e,alias:c??u}))}},t[15]=c,t[16]=S,t[17]=n.state,t[18]=n.view,t[19]=r,t[20]=u,t[21]=s,t[22]=j):j=t[22];let M=j,N=!_&&!h&&v!==null,P=!_&&!h&&y?.kind===`navigate`&&y.displayState===`resolved`,F=!_&&!h&&y?.kind===`navigate`&&y.displayState===`folder`,I=!_&&!h&&!v&&y?.kind===`create`,L,R,z,B,V,H,U,W,ee,te;if(t[23]!==n.state||t[24]!==n.view||t[25]!==_||t[26]!==r||t[27]!==N||t[28]!==F||t[29]!==P||t[30]!==I||t[31]!==h||t[32]!==i){if(h){let e;t[43]===Symbol.for(`react.memo_cache_sentinel`)?(e=(0,J.jsx)(Rr,{className:`size-3.5 shrink-0 animate-spin`,"aria-hidden":`true`}),t[43]=e):e=t[43],R={icon:e,text:`Loading…`,className:`text-muted-foreground`}}else if(_){let e;t[44]===Symbol.for(`react.memo_cache_sentinel`)?(e=(0,J.jsx)(Sr,{className:`size-3.5 shrink-0`,"aria-hidden":`true`}),t[44]=e):e=t[44],R={icon:e,text:`External wiki link`,className:`text-foreground`}}else if(N){let e;t[45]===Symbol.for(`react.memo_cache_sentinel`)?(e=(0,J.jsx)(Cr,{className:`size-3.5 shrink-0`,"aria-hidden":`true`}),t[45]=e):e=t[45],R={icon:e,text:`Asset`,className:`text-foreground`}}else if(F){let e;t[46]===Symbol.for(`react.memo_cache_sentinel`)?(e=(0,J.jsx)(Dr,{className:`size-3.5 shrink-0`,"aria-hidden":`true`}),t[46]=e):e=t[46],R={icon:e,text:`Folder (no index)`,className:`text-foreground`}}else if(I){let e;t[47]===Symbol.for(`react.memo_cache_sentinel`)?(e=(0,J.jsx)(_r,{className:`size-3.5 shrink-0`,"aria-hidden":`true`}),t[47]=e):e=t[47],R={icon:e,text:`Page not found`,className:`text-red-700 dark:text-red-300`}}else if(P){let e;t[48]===Symbol.for(`react.memo_cache_sentinel`)?(e=(0,J.jsx)(Tr,{className:`size-3.5 shrink-0`,"aria-hidden":`true`}),t[48]=e):e=t[48],R={icon:e,text:`Wiki link`,className:`text-foreground`}}else{let e;t[49]===Symbol.for(`react.memo_cache_sentinel`)?(e=(0,J.jsx)(_r,{className:`size-3.5 shrink-0`,"aria-hidden":`true`}),t[49]=e):e=t[49],R={icon:e,text:`Unrecognized wiki link`,className:`text-muted-foreground`}}let e;t[50]!==n.state||t[51]!==n.view||t[52]!==r?(e=()=>{let e=r();if(typeof e!=`number`)return new DOMRect;let t=n.state.doc.nodeAt(e);if(!t)return new DOMRect;try{return He(n.view,e,e+t.nodeSize)}catch{return new DOMRect}},t[50]=n.state,t[51]=n.view,t[52]=r,t[53]=e):e=t[53];let a;t[54]!==n.view.dom||t[55]!==e?(a={getBoundingClientRect:e,contextElement:n.view.dom},t[54]=n.view.dom,t[55]=e,t[56]=a):a=t[56];let o=a;L=Dk,te=`wiki-link`,z=`Wiki link options`,B=i,V=o,W=`mb-2 flex items-start gap-2 pr-8`,ee=(0,J.jsx)(`div`,{className:Lt(`mt-0.5 flex shrink-0`,R.className),children:R.icon}),U=`flex-1 min-w-0`,H=Lt(`text-sm font-medium`,R.className),t[23]=n.state,t[24]=n.view,t[25]=_,t[26]=r,t[27]=N,t[28]=F,t[29]=P,t[30]=I,t[31]=h,t[32]=i,t[33]=L,t[34]=R,t[35]=z,t[36]=B,t[37]=V,t[38]=H,t[39]=U,t[40]=W,t[41]=ee,t[42]=te}else L=t[33],R=t[34],z=t[35],B=t[36],V=t[37],H=t[38],U=t[39],W=t[40],ee=t[41],te=t[42];let ne;t[57]!==R.text||t[58]!==H?(ne=(0,J.jsx)(`div`,{className:H,children:R.text}),t[57]=R.text,t[58]=H,t[59]=ne):ne=t[59];let re=v??(_?_.url:`${s}${l?`#${l}`:``}`),ie=v??(_?_.url:`${s}${l?`#${l}`:``}`),ae;t[60]!==re||t[61]!==ie?(ae=(0,J.jsx)(`div`,{className:`truncate font-mono text-xs text-muted-foreground`,title:re,children:ie}),t[60]=re,t[61]=ie,t[62]=ae):ae=t[62];let oe;t[63]!==ne||t[64]!==ae||t[65]!==U?(oe=(0,J.jsxs)(`div`,{className:U,children:[ne,ae]}),t[63]=ne,t[64]=ae,t[65]=U,t[66]=oe):oe=t[66];let se;t[67]!==oe||t[68]!==W||t[69]!==ee?(se=(0,J.jsxs)(`div`,{className:W,children:[ee,oe]}),t[67]=oe,t[68]=W,t[69]=ee,t[70]=se):se=t[70];let ce;t[71]!==_||t[72]!==A||t[73]!==I||t[74]!==i?(ce=I?null:(0,J.jsx)(zt,{size:`sm`,variant:`default`,onClick:()=>{A({}),i()},children:_?`Open in new tab`:`Open`}),t[71]=_,t[72]=A,t[73]=I,t[74]=i,t[75]=ce):ce=t[75];let le;t[76]!==I||t[77]!==C?(le=I?(0,J.jsx)(zt,{size:`sm`,variant:`default`,onClick:()=>C(`missing`),children:`Create page`}):null,t[76]=I,t[77]=C,t[78]=le):le=t[78];let ue;t[79]!==w||t[80]!==F||t[81]!==C?(ue=F&&w?(0,J.jsxs)(zt,{size:`sm`,variant:`outline`,onClick:()=>C(`folder-index`),children:[(0,J.jsx)(wr,{className:`size-3.5`,"aria-hidden":`true`}),`Create index`]}):null,t[79]=w,t[80]=F,t[81]=C,t[82]=ue):ue=t[82];let de;t[83]===Symbol.for(`react.memo_cache_sentinel`)?(de=(0,J.jsx)(`div`,{className:`flex-1`}),t[83]=de):de=t[83];let fe;t[84]===x?fe=t[85]:(fe=()=>x(!0),t[84]=x,t[85]=fe);let me;t[86]===Symbol.for(`react.memo_cache_sentinel`)?(me=(0,J.jsx)(Ur,{className:`size-3.5`,"aria-hidden":`true`}),t[86]=me):me=t[86];let he;t[87]===fe?he=t[88]:(he=(0,J.jsxs)(zt,{size:`sm`,variant:`outline`,onClick:fe,children:[me,`Edit`]}),t[87]=fe,t[88]=he);let ge;t[89]===I?ge=t[90]:(ge=I?(0,J.jsx)(Zr,{className:`size-3.5`,"aria-hidden":`true`}):(0,J.jsx)(Xr,{className:`size-3.5`,"aria-hidden":`true`}),t[89]=I,t[90]=ge);let _e=I?`Unlink`:`Remove`,ve;t[91]!==O||t[92]!==ge||t[93]!==_e?(ve=(0,J.jsxs)(zt,{size:`sm`,variant:`destructive`,onClick:O,children:[ge,_e]}),t[91]=O,t[92]=ge,t[93]=_e,t[94]=ve):ve=t[94];let ye;t[95]!==ce||t[96]!==le||t[97]!==ue||t[98]!==he||t[99]!==ve?(ye=(0,J.jsxs)(`div`,{className:`flex flex-wrap items-center gap-1.5`,children:[ce,le,ue,de,he,ve]}),t[95]=ce,t[96]=le,t[97]=ue,t[98]=he,t[99]=ve,t[100]=ye):ye=t[100];let be;t[101]!==L||t[102]!==z||t[103]!==B||t[104]!==V||t[105]!==se||t[106]!==ye||t[107]!==te?(be=(0,J.jsxs)(L,{kind:te,ariaLabel:z,onDeactivate:B,triggerReference:V,children:[se,ye]}),t[101]=L,t[102]=z,t[103]=B,t[104]=V,t[105]=se,t[106]=ye,t[107]=te,t[108]=be):be=t[108];let xe=S!==null,Se;t[109]===C?Se=t[110]:(Se=e=>{e||C(null)},t[109]=C,t[110]=Se);let Ce=S===`folder-index`&&w?w.initialDir:y?.kind===`create`?y.initialDir:``,Te=S===`folder-index`&&w?w.suggestedName:y?.kind===`create`?y.suggestedName:void 0,Ee;t[111]!==S||t[112]!==w||t[113]!==s?(Ee=S===`folder-index`&&w?(0,J.jsxs)(J.Fragment,{children:[`Create an index note for`,` `,(0,J.jsxs)(`span`,{className:`font-medium text-foreground`,children:[w.initialDir,`/`]})]}):(0,J.jsxs)(J.Fragment,{children:[`Create a page for `,(0,J.jsx)(`span`,{className:`font-medium text-foreground`,children:s})]}),t[111]=S,t[112]=w,t[113]=s,t[114]=Ee):Ee=t[114];let De;t[115]!==M||t[116]!==xe||t[117]!==Se||t[118]!==Ce||t[119]!==Te||t[120]!==Ee?(De=(0,J.jsx)(wv,{open:xe,onOpenChange:Se,kind:`file`,initialDir:Ce,suggestedName:Te,description:Ee,onCreated:M}),t[115]=M,t[116]=xe,t[117]=Se,t[118]=Ce,t[119]=Te,t[120]=Ee,t[121]=De):De=t[121];let Oe;t[122]!==c||t[123]!==l||t[124]!==d||t[125]!==b||t[126]!==E||t[127]!==p||t[128]!==x||t[129]!==s?(Oe=(0,J.jsx)(Vz,{open:b,target:s,alias:c,anchor:l,pages:p,assetPaths:d,onOpenChange:x,onSave:E}),t[122]=c,t[123]=l,t[124]=d,t[125]=b,t[126]=E,t[127]=p,t[128]=x,t[129]=s,t[130]=Oe):Oe=t[130];let ke;return t[131]!==be||t[132]!==De||t[133]!==Oe?(ke=(0,J.jsxs)(J.Fragment,{children:[be,De,Oe]}),t[131]=be,t[132]=De,t[133]=Oe,t[134]=ke):ke=t[134],ke}var Uz=0;function Wz(){return`wiki-link-${++Uz}`}function Gz(e){let t=e.doc??(typeof document<`u`?document:{createElement:null,createTextNode:null}),n=t.createElement(`span`);n.setAttribute(`data-wiki-link`,``),n.setAttribute(`data-node-id`,e.nodeId),n.setAttribute(`data-target`,e.target),n.setAttribute(`data-alias`,e.alias??``),n.setAttribute(`data-anchor`,e.anchor??``),n.setAttribute(`contenteditable`,`false`),n.setAttribute(`role`,`button`),n.setAttribute(`tabindex`,`0`),n.setAttribute(`aria-label`,`Wiki link: ${e.target}${e.anchor?`#${e.anchor}`:``}`),n.classList.add(`wiki-link-chip`),n.style.touchAction=`manipulation`;let r=e.alias??`${e.target}${e.anchor?`#${e.anchor}`:``}`,i=t.createTextNode(r);return n.appendChild(i),{dom:n}}var Kz=dt.extend({priority:200,addOptions(){return{...this.parent?.(),docName:``}},addNodeView(){return({editor:e,node:t,getPos:n})=>{let r=Wz(),{dom:i}=Gz({nodeId:r,target:String(t.attrs.target??``),alias:t.attrs.alias==null?null:String(t.attrs.alias),anchor:t.attrs.anchor==null?null:String(t.attrs.anchor)}),a=t,o=()=>{let e=n();return typeof e==`number`?e:void 0},s=zk(e);return s.register({type:`wikiLink`,nodeId:r,getPos:o,controls:{propPanel:t=>(0,q.createElement)(Hz,{editor:e,getPos:o,onClose:t.deactivate})},handlePrimary:({newTab:e})=>{let t=a.attrs,n=typeof t.target==`string`?t.target:``;if(!n)return!1;let r=rt(n,typeof t.anchor==`string`?t.anchor:null);if(!r)return!1;if(r.kind===`doc`)return e?(yk({docName:r.docName,anchor:r.anchor}),!0):!1;if(r.kind===`asset`){let t=dC(r.url,Le()?.assetPaths??new Set)??r.url.replace(/^\//,``);return e?_k(ot(t)):window.location.hash=ot(t),!0}return!e||!pk(r.url)?!1:(_k(r.url),!0)}}),{dom:i,ignoreMutation:()=>!0,update:e=>{if(e.type.name!==`wikiLink`)return!1;a=e;let t=String(e.attrs.target??``),n=e.attrs.alias==null?null:String(e.attrs.alias),r=e.attrs.anchor==null?null:String(e.attrs.anchor);return i.setAttribute(`data-target`,t),i.setAttribute(`data-alias`,n??``),i.setAttribute(`data-anchor`,r??``),i.setAttribute(`aria-label`,`Wiki link: ${t}${r?`#${r}`:``}`),i.textContent=n??`${t}${r?`#${r}`:``}`,!0},destroy:()=>{s.deregister(r)}}}},addKeyboardShortcuts(){return{Backspace:()=>{if(eA.getState(this.editor.state)?.active)return!1;let{selection:e}=this.editor.state;if(!e.empty)return!1;let t=e.$from.nodeBefore;if(t?.type.name===`wikiLink`){let{state:n,view:r}=this.editor;return r.dispatch(n.tr.delete(e.from-t.nodeSize,e.from)),!0}return!1},Delete:()=>{if(eA.getState(this.editor.state)?.active)return!1;let{selection:e}=this.editor.state;if(!e.empty)return!1;let t=e.$from.nodeAfter;if(t?.type.name===`wikiLink`){let{state:n,view:r}=this.editor;return r.dispatch(n.tr.delete(e.from,e.from+t.nodeSize)),!0}return!1}}},addProseMirrorPlugins(){return[hA(this.editor)]}}),qz=0;function Jz(){return`wiki-link-embed-${++qz}`}function Yz(e){let t=e.doc??(typeof document<`u`?document:{createElement:null,createTextNode:null}),n=t.createElement(`a`);n.setAttribute(`data-wiki-embed`,``),n.setAttribute(`data-node-id`,e.nodeId),n.setAttribute(`data-target`,e.target),n.setAttribute(`data-alias`,e.alias??``),n.setAttribute(`data-anchor`,e.anchor??``),n.setAttribute(`href`,e.href),n.setAttribute(`target`,`_blank`),n.setAttribute(`rel`,`noopener noreferrer`),n.setAttribute(`contenteditable`,`false`),n.setAttribute(`role`,`button`),n.setAttribute(`tabindex`,`0`),n.setAttribute(`aria-label`,`Embed: ${e.target}${e.anchor?`#${e.anchor}`:``}`),n.classList.add(`wiki-link-embed-chip`),n.style.touchAction=`manipulation`;let r=e.alias??`${e.target}${e.anchor?`#${e.anchor}`:``}`,i=t.createTextNode(r);return n.appendChild(i),{dom:n}}function Xz(e){let t=(e.doc??(typeof document<`u`?document:{createElement:null})).createElement(`img`);return t.setAttribute(`data-wiki-embed`,``),t.setAttribute(`data-node-id`,e.nodeId),t.setAttribute(`data-target`,e.target),t.setAttribute(`data-alias`,e.alias??``),t.setAttribute(`src`,e.src),t.setAttribute(`alt`,e.alias??e.target),{dom:t}}function Zz(e){let t=vt(e);return t!==null&&l.has(t)}var Qz=Ze.extend({addNodeView(){return({editor:e,node:t,getPos:n})=>{let r=Jz(),i=t,a=String(t.attrs.target??``),o=t.attrs.alias==null?null:String(t.attrs.alias),s=t.attrs.anchor==null?null:String(t.attrs.anchor),c=t.attrs.resolvedSrc==null?null:String(t.attrs.resolvedSrc);if(Zz(a)){let{dom:e}=Xz({nodeId:r,target:a,alias:o,src:c??a});return{dom:e,ignoreMutation:()=>!0,update:t=>{if(t.type.name!==`wikiLinkEmbed`)return!1;i=t;let n=String(t.attrs.target??``),r=t.attrs.alias==null?null:String(t.attrs.alias),a=t.attrs.resolvedSrc==null?null:String(t.attrs.resolvedSrc);if(!Zz(n))return!1;let o=a??n;return e.setAttribute(`data-target`,n),e.setAttribute(`data-alias`,r??``),e.setAttribute(`src`,o),e.setAttribute(`alt`,r??n),!0}}}let{dom:l}=Yz({nodeId:r,target:a,alias:o,anchor:s,href:c??a});l.addEventListener(`click`,e=>{e.preventDefault()});let u=()=>{let e=n();return typeof e==`number`?e:void 0},d=zk(e);return d.register({type:`wikiLinkEmbed`,nodeId:r,getPos:u,controls:{},handlePrimary:({newTab:e})=>{let t=i.attrs,n=typeof t.target==`string`?t.target:``;if(!n)return!1;let r=(typeof t.resolvedSrc==`string`&&t.resolvedSrc.length>0?t.resolvedSrc:null)??n,a=vt(n);if(a===null)return!1;let o=Oe(r,``)??n;return dk({url:r,projectRelPath:o,ext:a,title:o.split(`/`).pop()??r,forceOsDelegation:e}),!0}}),{dom:l,ignoreMutation:()=>!0,update:e=>{if(e.type.name!==`wikiLinkEmbed`)return!1;i=e;let t=String(e.attrs.target??``);if(Zz(t))return!1;let n=e.attrs.alias==null?null:String(e.attrs.alias),r=e.attrs.anchor==null?null:String(e.attrs.anchor),a=(e.attrs.resolvedSrc==null?null:String(e.attrs.resolvedSrc))??t;return l.setAttribute(`data-target`,t),l.setAttribute(`data-alias`,n??``),l.setAttribute(`data-anchor`,r??``),l.setAttribute(`href`,a),l.setAttribute(`aria-label`,`Embed: ${t}${r?`#${r}`:``}`),l.textContent=n??`${t}${r?`#${r}`:``}`,!0},destroy:()=>{d.deregister(r)}}}}}),$z=[...Ye.map(e=>e.name===`jsxComponent`?uM:e.name===`rawMdxFallback`?Sz:e.name===`wikiLink`?Kz:e.name===`wikiLinkEmbed`?Qz:e.name===`link`?OA:e.name===`mathInline`?vM:e.name===`tag`?Bz:e),Dz.configure({itemsSources:[()=>dT,lT,uT],categoryLabels:{content:`Components`,layout:`Layout`,media:`Media`,data:`Data`}}),$S.configure({onDrop(e,t,n){for(let r of t)CC(r,e,n)},onPaste(e,t,n){for(let n of t)CC(n,e,e.state.selection.from)}}),ck,Pz,sk,ak,gT,kz,eC,ST,kj,Fe.create({name:`chunkWrapperDecoration`,addProseMirrorPlugins(){return[OT()]}})];function eB(e){return e===de}var tB=3e4,nB=class extends Error{docName;elapsedMs;constructor(e,t){super(`Sync timed out for "${e}" after ${t}ms`),this.name=`SyncTimeoutError`,this.docName=e,this.elapsedMs=t}},rB=class extends Error{docName;constructor(e){super(`Provider disconnected before sync for "${e}"`),this.name=`PreSyncDisconnectError`,this.docName=e}},iB=class extends Error{docName;constructor(e){super(`Document not found: "${e}"`),this.name=`DocumentNotFoundError`,this.docName=e}},aB=class extends Error{docName;cause;constructor(e,t){let n=t instanceof Error?t.message:String(t??`unknown`);super(`Bridge setup failed for "${e}": ${n}`),this.name=`BridgeSetupError`,this.docName=e,this.cause=t}},oB=class extends Error{docName;missingCapability;constructor(e,t){super(`Server is missing capability "${t}" required to open "${e}".`),this.name=`ServerCapabilityMismatchError`,this.docName=e,this.missingCapability=t}},sB=new Map,cB=!1;function lB(){for(let e of sB.values())if(!e.settled)return!0;return!1}function uB(){typeof document>`u`||document.visibilityState===`visible`&&dB(Date.now())}function dB(e){let t=[];for(let[n,r]of sB){if(r.settled)continue;let i=e-r.createdAt;if(i<3e4)continue;r.settled=!0;let a=new nB(n,i);hB(r),r.reject(a),t.push({docName:n,elapsedMs:i})}if(t.length>0){let e=t.map(e=>`${e.docName} (${e.elapsedMs}ms)`).join(`, `);console.warn(`[syncPromise] reaped ${t.length} timed-out ${t.length===1?`entry`:`entries`} on visibility restore (tab-sleep recovered): ${e}`)}return lB()||pB(),t.length}function fB(){cB||typeof document>`u`||(document.addEventListener(`visibilitychange`,uB),cB=!0)}function pB(){cB&&(typeof document>`u`||(document.removeEventListener(`visibilitychange`,uB),cB=!1))}var mB=new Map;function hB(e){e.detached||(e.detached=!0,e.timeoutHandle!==null&&clearTimeout(e.timeoutHandle),e.provider.off(`synced`,e.onSynced),e.provider.off(`close`,e.onClose))}function gB(e,t){let n=sB.get(e);if(n)return n.promise;let r=mB.get(e);if(r!==void 0){mB.delete(e);let n=r===`timeout`?new nB(e,0):new rB(e);console.warn(`[syncPromise] ${e} rejected on creation (test hook, armed ${r}): ${n.message}`),X(`ok/sync/create`,{docName:e,warm:!1,armed:r}),X(`ok/sync/reject`,{docName:e,reason:`armed-${r}`});let i=vB(n);return sB.set(e,yB(i,t)),i}if(t.synced){console.log(`[syncPromise] ${e} resolved synchronously (warm provider)`),X(`ok/sync/create`,{docName:e,warm:!0}),X(`ok/sync/resolve`,{docName:e,elapsedMs:0,warm:!0});let n=Promise.resolve();return sB.set(e,_B(n,t)),n}let i=Date.now(),a=()=>{},o=()=>{},s=new Promise((e,t)=>{a=e,o=t}),c=()=>{let t=sB.get(e);if(!t||t.settled)return;t.settled=!0;let n=Date.now()-t.createdAt;console.log(`[syncPromise] ${e} resolved in ${n}ms`),X(`ok/sync/resolve`,{docName:e,elapsedMs:n,warm:!1}),hB(t),lB()||pB(),t.resolve()},l=t=>{let n=sB.get(e);if(!n||n.settled)return;n.settled=!0;let r=new rB(e);console.warn(`[syncPromise] ${e} rejected: ${r.message}`),X(`ok/sync/reject`,{docName:e,reason:`pre-sync-disconnect`}),hB(n),lB()||pB(),n.reject(r)},u=setTimeout(()=>{let t=sB.get(e);if(!t||t.settled)return;t.settled=!0;let n=Date.now()-t.createdAt,r=new nB(e,n);console.warn(`[syncPromise] ${e} rejected: ${r.message}`),X(`ok/sync/reject`,{docName:e,reason:`timeout`,elapsedMs:n}),hB(t),lB()||pB(),t.reject(r)},tB),d={promise:s,resolve:a,reject:o,createdAt:i,timeoutHandle:u,provider:t,onSynced:c,onClose:l,settled:!1,detached:!1};return sB.set(e,d),t.on(`synced`,c),t.on(`close`,l),fB(),X(`ok/sync/create`,{docName:e,warm:!1}),s}function _B(e,t){return{promise:e,resolve:()=>{},reject:()=>{},createdAt:Date.now(),timeoutHandle:null,provider:t,onSynced:()=>{},onClose:()=>{},settled:!0,detached:!0}}function vB(e){let t=Promise.reject(e);t.catch(()=>{});let n=t;return n.status=`rejected`,n.reason=e,n}function yB(e,t){return{promise:e,resolve:()=>{},reject:()=>{},createdAt:Date.now(),timeoutHandle:null,provider:t,onSynced:()=>{},onClose:()=>{},settled:!0,detached:!0}}function bB(e){let t=sB.get(e);t&&(t.settled=!0,hB(t),sB.delete(e),lB()||pB())}function xB(e,t){let n=sB.get(e);return!n||n.settled?!1:(n.settled=!0,console.warn(`[syncPromise] ${e} rejected: ${t.message}`),hB(n),lB()||pB(),n.reject(t),!0)}var SB=Object.freeze({kind:`tab-replay`}),CB=Object.freeze({kind:`idle`});function wB(e,t){return()=>{}}var TB=te($z),EB=4e3,DB=1e4,OB=class extends Error{constructor(e,t){super(`client persistence clearData timed out for ${e} after ${t}ms`),this.docName=e,this.timeoutMs=t,this.name=`ClientPersistenceClearTimeoutError`}},kB=`ok-last-observed-branch`,AB=5e3,jB=1*1024*1024,MB=Qv(`MAX_POOL`,10);function NB(e,t,n=null){let r={};if(e!==null&&(r.principalId=e.principalId,r.tabSessionId=e.tabSessionId),t!==null&&t.length>0&&(r.expectedServerInstanceId=t),n!==null&&n.length>0&&(r.expectedBranch=n),Object.keys(r).length!==0)return JSON.stringify(r)}var PB=class{_entries=new Map;get entries(){return this._entries}lruOrder=[];activeDocName=null;maxSize;wsUrl;recycleDebounceMs;clearDataTimeoutMs;onChange=null;tabIdentity=null;serverRestartRecoveryState=CB;cachedServerInstanceId=null;pendingServerInstanceKnown=null;recoveryMismatchStaleClaim;bufferedUpdates=new Map;persistenceFactory;storage;constructor(e,t,n){this.maxSize=e,this.wsUrl=t,this.recycleDebounceMs=n?.recycleDebounceMs??EB,this.clearDataTimeoutMs=n?.clearDataTimeoutMs??DB,this.persistenceFactory=n?.persistenceFactory??qS,n?.storage===void 0?this.storage=globalThis.localStorage===void 0?null:globalThis.localStorage:this.storage=n.storage}setTabIdentity(e){this.tabIdentity=e}setExpectedServerInstanceId(e){if(this.cachedServerInstanceId=e,!(e===null||e.length===0)){if(this.pendingServerInstanceKnown!==null){let t=this.pendingServerInstanceKnown;this.pendingServerInstanceKnown=null,t.resolve(e)}this.attachDeferredPersistence(e)}}whenServerInstanceKnown(){if(this.cachedServerInstanceId!==null&&this.cachedServerInstanceId.length>0)return Promise.resolve(this.cachedServerInstanceId);if(this.pendingServerInstanceKnown!==null)return this.pendingServerInstanceKnown.promise;let e,t=new Promise(t=>{e=t});return this.pendingServerInstanceKnown={promise:t,resolve:e},t}buildPersistence(e,t,n){return this.persistenceFactory({branch:this.getOrInitObservedBranch()??`_unknown_`,serverInstanceId:e,docName:t,doc:n})}attachDeferredPersistence(e){for(let t of this._entries.values())if(t.kind===`active`&&t.persistence===null)try{t.persistence=this.buildPersistence(e,t.docName,t.provider.document)}catch(e){let n=e instanceof Error?e.name:`non-error-throw`;this.emitStructuredClientRecoveryEvent({event:`ok-client-persistence-attach-failed`,...this.recoveryTelemetryBase(t.docName),errorName:n,errorMessage:e instanceof Error?e.message:String(e)})}}getServerRestartRecoveryState(){return this.serverRestartRecoveryState}observeDiskAck(e,t){let n=this.entries.get(e);!n||n.kind!==`active`||(n.lastDiskAckedSV=XS(n.lastDiskAckedSV,t))}observeDiskAckBatch(e){for(let[t,n]of Object.entries(e))this.observeDiskAck(t,n)}lastObservedBranch=null;lastObservedBranchInitialized=!1;getOrInitObservedBranch(){if(this.lastObservedBranchInitialized)return this.lastObservedBranch;this.lastObservedBranchInitialized=!0;try{let e=this.storage?.getItem(kB)??null;e!==null&&e.length>0&&(this.lastObservedBranch=e)}catch{}return this.lastObservedBranch}persistObservedBranch(e){this.lastObservedBranch=e,this.lastObservedBranchInitialized=!0;try{e===null||e.length===0?this.storage?.removeItem(kB):this.storage?.setItem(kB,e)}catch{}}withClearDataTimeout(e,t){return new Promise((n,r)=>{let i=setTimeout(()=>{r(new OB(e,this.clearDataTimeoutMs))},this.clearDataTimeoutMs);t.then(()=>{clearTimeout(i),n()},e=>{clearTimeout(i),r(e)})})}recoveryTelemetryBase(e,t){let n={docName:e,branch:this.getOrInitObservedBranch()??`_unknown_`},r=t===void 0?this.recoveryMismatchStaleClaim:t;return r!==void 0&&r.length>0&&(n.serverInstanceId=r),n}emitStructuredClientRecoveryEvent(e){console.warn(JSON.stringify(e))}clearRecoveryMismatchStaleClaimIfTerminal(){let e=this.serverRestartRecoveryState.kind;(e===`idle`||e===`failed`)&&(this.recoveryMismatchStaleClaim=void 0)}beginServerRestartRecovery(e,t){this.serverRestartRecoveryState={kind:`recovering`,phase:`clearing-local-cache`,docNames:e,failedDocNames:[],startedAt:t};for(let t of e)bB(t);this.notify()}enterServerRestartReconnect(e,t,n,r){if(e.length===0){this.serverRestartRecoveryState=t.length===0?CB:{kind:`failed`,reason:r,docNames:t,failedDocNames:t,startedAt:n},this.clearRecoveryMismatchStaleClaimIfTerminal(),this.notify();return}this.serverRestartRecoveryState={kind:`recovering`,phase:`reconnecting`,docNames:e,failedDocNames:t,startedAt:n,...t.length>0?{clearFailureReason:r}:{}},this.notify()}markServerRestartRecoverySynced(e){let t=this.serverRestartRecoveryState;if(t.kind!==`recovering`||t.phase!==`reconnecting`||!t.docNames.includes(e))return;let n=t.docNames.filter(t=>t!==e);if(n.length>0){this.serverRestartRecoveryState={...t,docNames:n};return}if(t.failedDocNames.length>0){this.serverRestartRecoveryState={kind:`failed`,reason:t.clearFailureReason??`clear-data-failed`,docNames:t.failedDocNames,failedDocNames:t.failedDocNames,startedAt:t.startedAt},this.clearRecoveryMismatchStaleClaimIfTerminal();return}this.serverRestartRecoveryState=CB,this.clearRecoveryMismatchStaleClaimIfTerminal()}setObservedBranch(e){this.persistObservedBranch(e)}compareAndUpdateObservedBranch(e){let t=this.getOrInitObservedBranch();return this.persistObservedBranch(e),t!==null&&t!==e}onBranchMismatch=null;branchMismatchInFlight=null;mismatchInFlight=null;setOnBranchMismatch(e){if(e===null){this.onBranchMismatch=null;return}this.onBranchMismatch=()=>{if(this.branchMismatchInFlight!==null)return;let t=Promise.resolve().then(e).finally(()=>{this.branchMismatchInFlight===t&&(this.branchMismatchInFlight=null)});this.branchMismatchInFlight=t}}setOnChange(e){this.onChange=e}notify(){this.onChange?.()}evictListeners=new Set;onEvict(e){return this.evictListeners.add(e),()=>{this.evictListeners.delete(e)}}fireEvict(e){for(let t of this.evictListeners)try{t(e)}catch(t){console.warn(`[ProviderPool] evict listener threw for ${e}:`,t)}}touch(e){let t=this.lruOrder.indexOf(e);t!==-1&&this.lruOrder.splice(t,1),this.lruOrder.push(e)}open(e){if(eB(e))return null;let t=this.entries.get(e);if(t)return t.lastAccessedAt=Date.now(),this.touch(e),this.notify(),t;this.entries.size>=this.maxSize&&this.evictLru();let n=this.cachedServerInstanceId,r=NB(this.tabIdentity,n,this.getOrInitObservedBranch()),i=new xS({url:ZS(this.wsUrl),name:e,forceSyncInterval:AB,...r===void 0?{}:{token:r}}),a=this.cachedServerInstanceId,o={kind:`active`,provider:i,persistence:a!==null&&a.length>0?this.buildPersistence(a,e,i.document):null,lastServerSyncedSV:null,lastDiskAckedSV:null,observerCleanup:null,observerFireCounterCleanup:wB(i.document,e),syncState:`connecting`,docName:e,lastAccessedAt:Date.now(),hasSynced:!1,pendingRecycleTimer:null,bridgeSetupFailed:!1};if(i.on(`status`,({status:t})=>{o.kind!==`active`||this.entries.get(e)!==o||t===`disconnected`&&(o.syncState=`disconnected`,this.notify())}),i.on(`synced`,()=>{if(!(o.kind!==`active`||this.entries.get(e)!==o)&&(o.syncState=`synced`,o.hasSynced=!0,o.lastServerSyncedSV=JS(i.document),o.pendingRecycleTimer&&=(clearTimeout(o.pendingRecycleTimer),null),this.markServerRestartRecoverySynced(e),this.notify(),!o.observerCleanup))try{let t=i.document,n=new ae({extensions:$z});o.observerCleanup=Pj({doc:t,xmlFragment:t.getXmlFragment(`default`),ytext:t.getText(`source`),mdManager:n,schema:TB,onSyncError:(t,n)=>{console.warn(`[Sync] ${t} failed for ${e}:`,n.message)}})}catch(t){console.error(`[ProviderPool] setupObservers init failed for ${e}:`,t),o.bridgeSetupFailed=!0,xB(e,new aB(e,t))}}),i.on(`disconnect`,()=>{o.kind!==`active`||this.entries.get(e)!==o||(o.syncState=`disconnected`,this.notify(),o.hasSynced&&i.unsyncedChanges===0&&!o.pendingRecycleTimer&&(o.pendingRecycleTimer=setTimeout(()=>{o.kind===`active`&&(o.pendingRecycleTimer=null,this.entries.get(e)===o&&this.recycleDisconnectedEntry(e))},this.recycleDebounceMs)))}),i.on(`authenticationFailed`,({reason:e})=>{if(![`server-instance-mismatch`,`branch-mismatch`].includes(e)){console.warn(JSON.stringify({event:`ok-auth-failed-unknown-reason`,reason:e}));return}let t=e;if(t===`server-instance-mismatch`){if(n===null||this.cachedServerInstanceId!==n)return;let e=n;this.cachedServerInstanceId=null,this.handleServerInstanceMismatch(e);return}if(t===`branch-mismatch`){this.onBranchMismatch?.();return}}),this.bufferedUpdates.get(e)!==void 0){let t=this.recoveryMismatchStaleClaim,n=()=>{if(i.off(`synced`,n),o.kind!==`active`||this.entries.get(e)!==o)return;let r=this.bufferedUpdates.get(e);if(r!==void 0){this.bufferedUpdates.delete(e);try{Cp(i.document,r,SB)}catch(n){let i=n instanceof Error?n.name:`non-error-throw`;this.emitStructuredClientRecoveryEvent({event:`ok-buffer-replay-failed`,...this.recoveryTelemetryBase(e,t),replayByteLength:r.byteLength,errorName:i,errorMessage:n instanceof Error?n.message:String(n)})}}};i.on(`synced`,n)}return this._entries.set(e,o),this.touch(e),this.notify(),o}handleServerInstanceMismatch(e){this.recoveryMismatchStaleClaim=e.length>0?e:void 0;let t=Array.from(this.entries.entries()),n=Date.now(),r=this.activeDocName,i=r!==null&&t.some(([e,t])=>e===r&&t.kind===`active`)?[r]:[],a=r??t.find(([,e])=>e.kind===`active`)?.[0]??``;a.length>0&&this.emitStructuredClientRecoveryEvent({event:`ok-client-cache-epoch-mismatch`,...this.recoveryTelemetryBase(a)}),this.beginServerRestartRecovery(i,n);for(let[e,n]of t)n.kind===`active`&&!i.includes(e)&&bB(e);for(let[e,n]of t){if(n.kind!==`active`)continue;let t=n.lastDiskAckedSV??n.lastServerSyncedSV;if(t===null){this.emitStructuredClientRecoveryEvent({event:`ok-buffer-replay-skipped-no-baseline`,...this.recoveryTelemetryBase(e),reason:`no-disk-ack-or-server-sync-vector`});continue}let r=YS(n.provider.document,t);if(r.byteLength>jB){X(`ok/pool/buffer-overflow`,{docName:e,bytes:r.byteLength});continue}r.byteLength>0&&this.bufferedUpdates.set(e,r)}let o=[];for(let[e,n]of t)n.kind===`active`&&n.persistence!==null&&o.push({docName:e,promise:this.withClearDataTimeout(e,n.persistence.clearData())});let s=Promise.allSettled(o.map(e=>e.promise)).then(e=>{let t=[],i=[],a=!1;e.forEach((e,n)=>{let r=o[n];if(!r)return;let s=r.docName;if(e.status===`rejected`){t.push(s);let n=e.reason instanceof OB;if(n&&(a=!0),n)this.emitStructuredClientRecoveryEvent({event:`ok-client-cache-clear-failed`,...this.recoveryTelemetryBase(s),failureKind:`timeout`});else{let t=e.reason instanceof Error?e.reason.name:`unknown`;this.emitStructuredClientRecoveryEvent({event:`ok-client-cache-clear-failed`,...this.recoveryTelemetryBase(s),failureKind:`rejected`,errorName:t,errorMessage:e.reason instanceof Error?e.reason.message:String(e.reason)})}}else i.push(s)});let s=i.filter(e=>e===r);if(t.length>0){let e=a?`clear-data-timeout`:`clear-data-failed`;console.warn(JSON.stringify({event:`ok-mismatch-recycle-partial-clears-failed`,failedDocs:t,clearedDocs:i})),this.enterServerRestartReconnect(s,t,n,e);for(let e of i)this.recycleDisconnectedEntry(e);return}this.enterServerRestartReconnect(s,[],n,`clear-data-failed`),this.recycleAllEntries()}).finally(()=>{this.mismatchInFlight===s&&(this.mismatchInFlight=null)});this.mismatchInFlight=s}awaitMismatchSettled(){return this.mismatchInFlight??Promise.resolve()}recycleAllEntries(){let e=Array.from(this.entries.keys());for(let t of e)this.recycleDisconnectedEntry(t)}prewarm(e){if(eB(e))return null;let t=this.entries.get(e);if(t)return t;let n=this.open(e);if(!n)return null;let r=this.lruOrder.indexOf(e);return r!==-1&&(this.lruOrder.splice(r,1),this.lruOrder.unshift(e)),n}close(e){let t=this.entries.get(e);t&&(this.destroyEntry(t),this._entries.delete(e),this.lruOrder=this.lruOrder.filter(t=>t!==e),this.bufferedUpdates.delete(e),this.activeDocName===e&&(this.activeDocName=null),this.notify())}async closeAndClearPersistence(e){let t=this.entries.get(e);if(t?.kind===`active`&&t.persistence!==null){try{await t.persistence.clearData()}catch(t){console.warn(`[ProviderPool] clearData on rename failed for ${e}:`,t)}this.close(e);return}t&&this.close(e);let n=this.getOrInitObservedBranch(),r=this.cachedServerInstanceId;if(n===null||r===null)return;let i=`ok-ydoc:${n}:${r}:${e}`;try{await new Promise((e,t)=>{let n=indexedDB.deleteDatabase(i);n.onsuccess=()=>e(),n.onerror=()=>t(n.error),n.onblocked=()=>{console.warn(`[ProviderPool] IDB delete blocked for ${i}`),t(Error(`idb-clear-blocked: ${i}`))}})}catch(e){console.warn(`[ProviderPool] IDB delete on rename failed for ${i}:`,e)}}clearBufferedUpdates(){this.bufferedUpdates.clear()}__test_seedBufferedUpdate(e,t){this.bufferedUpdates.set(e,t)}__test_bufferedUpdatesSize(){return this.bufferedUpdates.size}__test_hasBufferedUpdate(e){return this.bufferedUpdates.has(e)}__test_getBufferedUpdate(e){return this.bufferedUpdates.get(e)}setActive(e){let t=this.entries.get(e);if(!t)throw Error(`[ProviderPool] Cannot setActive — "${e}" is not open`);t.lastAccessedAt=Date.now(),this.touch(e),this.activeDocName=e,this.notify()}clearActive(){this.activeDocName!==null&&(this.activeDocName=null,this.notify())}getActive(){return this.activeDocName?this.entries.get(this.activeDocName)??null:null}getActiveDocName(){return this.activeDocName}has(e){return this.entries.has(e)}recycle(e){this.recycleDisconnectedEntry(e)}dispose(){for(let e of this._entries.values())this.destroyEntry(e);this._entries.clear(),this.lruOrder=[],this.activeDocName=null,this.onChange=null,this.bufferedUpdates.clear(),this.onBranchMismatch=null,this.branchMismatchInFlight=null,this.evictListeners.clear(),this.serverRestartRecoveryState=CB,this.cachedServerInstanceId=null,this.pendingServerInstanceKnown=null,this.tabIdentity=null,this.recoveryMismatchStaleClaim=void 0}evictLru(){for(let e of this.lruOrder)if(e!==this.activeDocName){X(`ok/pool/evict-lru`,{docName:e}),this.close(e);return}}destroyEntry(e){if(e.kind===`tearing-down`)return;let t=e.observerCleanup,n=e.observerFireCounterCleanup,r=e.persistence,i=e.pendingRecycleTimer,a=e.docName,o=e;o.kind=`tearing-down`,o.persistence=null,o.observerCleanup=null,o.observerFireCounterCleanup=null,o.pendingRecycleTimer=null,i&&clearTimeout(i),bB(a),this.fireEvict(a),t?.(),n?.(),r!==null&&r.destroy().catch(e=>{console.warn(`[ProviderPool] persistence destroy failed for ${a}:`,e)});try{o.provider.destroy()}catch(e){console.warn(`[ProviderPool] Provider destroy failed for ${a}:`,e)}}recycleDisconnectedEntry(e){let t=this.entries.get(e);if(!t||t.kind!==`active`)return;let n=this.activeDocName===e;if(X(`ok/pool/recycle-disconnected`,{docName:e,wasActive:n}),this.destroyEntry(t),this._entries.delete(e),this.lruOrder=this.lruOrder.filter(t=>t!==e),n){this.open(e)&&this.setActive(e);return}this.notify()}},FB=crypto.randomUUID(),IB=!1;function LB(e){IB||(IB=!0,console.warn(`[principal-fetch] failed to resolve principal — falling back to random identity.`,e))}var RB=(0,q.createContext)(null),zB=null;function BB(e){return zB||(zB=new PB(MB,e),Ey(zB)),zB}var VB={activeDocName:null,activeProvider:null,syncState:`connecting`,serverRestartRecovery:{kind:`idle`},poolEntries:[]};function HB(){if(typeof window>`u`)return null;let e=window.okDesktop;return e?.config.mode===`editor`?e:null}function UB(){return typeof window>`u`||window.okDesktop?.config.mode===`editor`?null:Iy(window.location.origin)}function WB(){if(typeof window>`u`)return[];let e=UB();return e?Ly(window.localStorage===void 0?null:window.localStorage,e,MB).openTabs:[]}function GB(e){let t=e.getActive(),n=[];for(let t of e.entries.values())n.push({docName:t.docName,provider:t.provider,lastAccessedAt:t.lastAccessedAt});return n.sort((e,t)=>t.lastAccessedAt-e.lastAccessedAt),{activeDocName:e.getActiveDocName(),activeProvider:t?.provider??null,syncState:t?.syncState??`connecting`,serverRestartRecovery:e.getServerRestartRecoveryState(),poolEntries:n}}function KB(e){let t=(0,Y.c)(81),{children:n}=e,[r,i]=(0,q.useState)(VB),[a,o]=(0,q.useState)(null),[s,c]=(0,q.useState)(WB),[l,u]=(0,q.useState)(!1),[d,f]=(0,q.useState)(!1),[p,m]=(0,q.useState)(null),[h,g]=(0,q.useState)(null),[_,v]=(0,q.useState)(`doc`),[y,b]=(0,q.useState)(null),[x,S]=(0,q.useState)(0),{collabUrl:C,terminal:w,lastError:T,retry:E}=qv(),D,O;t[0]!==C||t[1]!==d||t[2]!==l?(D=()=>{if(C===null||l||!d)return;let e=!1,t=HB(),n=UB(),r=typeof localStorage<`u`?localStorage:null;return(t?t.project.getSessionState():Promise.resolve(n?Ly(r,n,MB):{openTabs:[],activeDocName:null,updatedAt:null})).then(t=>{if(e)return;let n=Py(t,MB),r=BB(C);for(let e of n.openTabs)r.open(e);c(e=>{let t=n.openTabs;for(let n of e)t=Ay(t,n,MB);return t});let i=Je(window.location.hash)===null&&window.location.hash.length===0,a=n.activeDocName??n.openTabs[0]??null;i&&a&&(window.location.hash=Re(a))}).catch(XB).finally(()=>{e||u(!0)}),()=>{e=!0}},O=[C,d,l],t[0]=C,t[1]=d,t[2]=l,t[3]=D,t[4]=O):(D=t[3],O=t[4]),(0,q.useEffect)(D,O);let A,j;t[5]!==s||t[6]!==r.activeDocName||t[7]!==l?(A=()=>{if(!l)return;let e=Fy(s,r.activeDocName),t=HB();if(t){t.project.setSessionState(e).catch(YB);return}let n=UB();n&&Ry(typeof localStorage<`u`?localStorage:null,n,e)},j=[s,r.activeDocName,l],t[5]=s,t[6]=r.activeDocName,t[7]=l,t[8]=A,t[9]=j):(A=t[8],j=t[9]),(0,q.useEffect)(A,j);let M,N;t[10]===C?(M=t[11],N=t[12]):(M=()=>{if(C===null)return;let e=!1;f(!1);let t=BB(C);return i(GB(t)),t.setOnBranchMismatch(()=>Av(t)),t.setOnChange(()=>i(GB(t))),fetch(`/api/principal`).then(JB).then(n=>{if(e)return;let r=k.safeParse(n);r.success?(t.setTabIdentity({principalId:r.data.id,tabSessionId:FB}),m(r.data)):LB(r.error)}).catch(t=>{e||LB(t)}).finally(()=>{e||f(!0)}),Av(t),()=>{e=!0,t.setOnChange(null)}},N=[C],t[10]=C,t[11]=M,t[12]=N),(0,q.useEffect)(M,N);let P;t[13]===C?P=t[14]:(P=e=>{if(X(`ok/nav/open-document`,{docName:e,transition:!1}),C===null)return;let t=BB(C);t.open(e)&&(c(t=>Ay(t,e,MB)),t.setActive(e),o({kind:`doc`,target:e,docName:e}))},t[13]=C,t[14]=P);let F=P,I;t[15]===F?I=t[16]:(I=e=>{X(`ok/nav/open-document`,{docName:e,transition:!1}),F(e)},t[15]=F,t[16]=I);let L=I,R;t[17]===C?R=t[18]:(R=e=>{if(C===null)return;let t=BB(C),n=We(e);if(n){if(!t.open(n))return;c(e=>Ay(e,n,MB)),t.setActive(n)}else t.clearActive();o(e)},t[17]=C,t[18]=R);let z=R,B;t[19]===z?B=t[20]:(B=e=>{X(`ok/nav/open-target`,{docName:We(e),kind:e.kind,transition:!1}),z(e)},t[19]=z,t[20]=B);let V=B,H,U;t[21]===C?(H=t[22],U=t[23]):(H=()=>{if(C===null){o(null);return}BB(C).clearActive(),o(null)},U=e=>{C!==null&&(BB(C).close(e),c(t=>jy(t,e)),o(t=>t&&(We(t)===e?null:t)))},t[21]=C,t[22]=H,t[23]=U);let W;t[24]!==C||t[25]!==r.activeDocName?(W=e=>{let t=null;if(C!==null&&BB(C).close(e),c(n=>(t=Ny(n,r.activeDocName,e),jy(n,e))),r.activeDocName===e){if(t){window.location.hash=Re(t);return}C!==null&&BB(C).clearActive(),o(null),window.location.hash=``}},t[24]=C,t[25]=r.activeDocName,t[26]=W):W=t[26];let ee;t[27]!==C||t[28]!==s?(ee=e=>{let t=My(s,e,MB);if(C!==null){let e=BB(C);for(let n of t)e.open(n)}c(t)},t[27]=C,t[28]=s,t[29]=ee):ee=t[29];let te,ne,re;t[30]===C?(te=t[31],ne=t[32],re=t[33]):(te=async e=>{C!==null&&(await BB(C).closeAndClearPersistence(e),o(t=>t&&(We(t)===e?null:t)))},ne=e=>{C!==null&&BB(C).recycle(e)},re=e=>{C!==null&&BB(C).prewarm(e)},t[30]=C,t[31]=te,t[32]=ne,t[33]=re);let ie,ae,oe,se,ce;t[34]===C?(ie=t[35],ae=t[36],oe=t[37],se=t[38],ce=t[39]):(ie=e=>{C!==null&&BB(C).setExpectedServerInstanceId(e)},ae=async e=>{if(C===null)return;let t=BB(C);t.setObservedBranch(e),await Dv(t,e)},oe=async e=>{if(C===null)return;let t=BB(C);t.compareAndUpdateObservedBranch(e)&&await Dv(t,e)},se=(e,t)=>{C!==null&&BB(C).observeDiskAck(e,t)},ce=async()=>{C!==null&&await Av(BB(C))},t[34]=C,t[35]=ie,t[36]=ae,t[37]=oe,t[38]=se,t[39]=ce);let le;t[40]!==y||t[41]!==_?(le=e=>{if(_===`agent`&&y===e){v(`doc`);return}b(e),v(`agent`),S(qB)},t[40]=y,t[41]=_,t[42]=le):le=t[42];let ue;t[43]===Symbol.for(`react.memo_cache_sentinel`)?(ue=()=>{v(`doc`),b(null)},t[43]=ue):ue=t[43];let de;t[44]!==a||t[45]!==T||t[46]!==w||t[47]!==C||t[48]!==y||t[49]!==x||t[50]!==_||t[51]!==F||t[52]!==L||t[53]!==s||t[54]!==z||t[55]!==V||t[56]!==p||t[57]!==E||t[58]!==r.activeDocName||t[59]!==r.activeProvider||t[60]!==r.poolEntries||t[61]!==r.serverRestartRecovery||t[62]!==r.syncState||t[63]!==h||t[64]!==H||t[65]!==U||t[66]!==W||t[67]!==ee||t[68]!==te||t[69]!==ne||t[70]!==re||t[71]!==ie||t[72]!==ae||t[73]!==oe||t[74]!==se||t[75]!==ce||t[76]!==le?(de={principal:p,activeTarget:a,activeDocName:r.activeDocName,activeProvider:r.activeProvider,openTabs:s,syncState:r.syncState,serverRestartRecovery:r.serverRestartRecovery,poolEntries:r.poolEntries,openDocument:F,openDocumentTransition:L,openTarget:z,openTargetTransition:V,clearTarget:H,closeDocument:U,closeTab:W,remapTabsForRename:ee,closeAndClearForRename:te,recycleDocument:ne,prewarm:re,systemProvider:h,setSystemProvider:g,updateServerInstanceId:ie,onBranchSwitched:ae,observeBranch:oe,observeDiskAck:se,refreshServerInfo:ce,collabUrl:C,collabTerminal:w,collabLastError:T,retryCollab:E,docPanelMode:_,docPanelAgentId:y,docPanelExpandSignal:x,openActivityPanel:le,closeActivityPanel:ue},t[44]=a,t[45]=T,t[46]=w,t[47]=C,t[48]=y,t[49]=x,t[50]=_,t[51]=F,t[52]=L,t[53]=s,t[54]=z,t[55]=V,t[56]=p,t[57]=E,t[58]=r.activeDocName,t[59]=r.activeProvider,t[60]=r.poolEntries,t[61]=r.serverRestartRecovery,t[62]=r.syncState,t[63]=h,t[64]=H,t[65]=U,t[66]=W,t[67]=ee,t[68]=te,t[69]=ne,t[70]=re,t[71]=ie,t[72]=ae,t[73]=oe,t[74]=se,t[75]=ce,t[76]=le,t[77]=de):de=t[77];let fe=de,pe;return t[78]!==n||t[79]!==fe?(pe=(0,J.jsx)(RB,{value:fe,children:n}),t[78]=n,t[79]=fe,t[80]=pe):pe=t[80],pe}function qB(e){return e+1}function JB(e){return e.ok?e.json():Promise.reject(Error(`HTTP ${e.status}`))}function YB(e){console.warn(`[editor-tabs] failed to persist tab session:`,e)}function XB(e){console.warn(`[editor-tabs] failed to restore tab session:`,e)}function ZB(){let e=(0,q.use)(RB);if(!e)throw Error(`useDocumentContext must be used within <DocumentProvider />`);return e}function QB(){let e=(0,Y.c)(3),{openDocumentTransition:t,openTargetTransition:n}=ZB(),r;return e[0]!==t||e[1]!==n?(r={openDocumentTransition:t,openTargetTransition:n},e[0]=t,e[1]=n,e[2]=r):r=e[2],r}export{hy as $,lr as $t,BA as A,Xr as At,KO as B,Ar as Bt,Nj as C,Zs as Ct,YA as D,X as Dt,tj as E,Go as Et,zk as F,Lr as Ft,FT as G,wr as Gt,LO as H,Or as Ht,Lk as I,Ir as It,hC as J,_r as Jt,vT as K,Sr as Kt,Ak as L,Fr as Lt,FA as M,Ur as Mt,PA as N,Hr as Nt,zA as O,Ho as Ot,jA as P,Rr as Pt,dy as Q,ur as Qt,kk as R,Nr as Rt,Rj as S,Ic as St,_j as T,ec as Tt,zD as U,Dr as Ut,zO as V,kr as Vt,RD as W,Tr as Wt,xS as X,mr as Xt,nC as Y,hr as Yt,my as Z,dr as Zt,lz as _,Up as _t,iB as a,wv as at,pR as b,Xu as bt,nB as c,pv as ct,eB as d,sp as dt,fy as et,$z as f,Tm as ft,cz as g,Jp as gt,uz as h,Wp as ht,aB as i,Ov as it,NA as j,Wr as jt,VA as k,zo as kt,bB as l,K_ as lt,Mz as m,Xp as mt,ZB as n,Qv as nt,rB as o,Sv as ot,jz as p,Zp as pt,Zw as q,vr as qt,QB as r,zv as rt,oB as s,fv as st,KB as t,Cy as tt,gB as u,Bg as ut,ER as v,vf as vt,Mj as w,nc as wt,yM as x,Lc as xt,CR as y,yf as yt,_k as z,jr as zt};