@inkeep/open-knowledge 0.0.0-dev-20260423231521 → 0.0.0-dev-20260424010642
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.
- package/dist/cli.mjs +4 -4
- package/dist/constants-Cs463jly.mjs +2 -0
- package/dist/index.mjs +1 -1
- package/dist/init-2VnOB85F.mjs +1 -0
- package/dist/init-CCx9nR5M.mjs +1 -0
- package/dist/{init-CODC0Drd.mjs → init-DgjpYMQB.mjs} +2 -2
- package/dist/{init-DysAQtCG.mjs → init-Xod4U7aY.mjs} +3 -3
- package/dist/loader-Cm1Bwe2n.mjs +1 -0
- package/dist/{loader-DfTFnc2z.mjs → loader-Dw_7CMz3.mjs} +2 -2
- package/dist/{paths-B9hXoumv.mjs → paths-BQwE2DU0.mjs} +2 -2
- package/dist/paths-a8wNIBFD.mjs +1 -0
- package/dist/{preview-jDZwLSul.mjs → preview-Bn5MTCPO.mjs} +2 -2
- package/dist/preview-_ahVwbF3.mjs +1 -0
- package/dist/public/assets/{GraphPanel-nbYklZ9C.js → GraphPanel-CdNqMYNB.js} +2 -2
- package/dist/public/assets/McpConsentDialogBody-Bgy0eAJw.js +1 -0
- package/dist/public/assets/{SourceEditor-CEqBKP5f.js → SourceEditor-DFAP44AB.js} +2 -2
- package/dist/public/assets/{clipboard-ZQ-AEssh.js → clipboard-Bau-T9ly.js} +6 -6
- package/dist/public/assets/{dialog-C2kd-BJI.js → dialog-XDohhbSr.js} +3 -3
- package/dist/public/assets/index-CVv4yIuY.css +1 -0
- package/dist/public/assets/index-Dpc5ZsZ1.js +27 -0
- package/dist/public/assets/{panel-CnHxXki4.js → panel-B3Oezbzt.js} +1 -1
- package/dist/public/assets/toggle-group-DRnV5hAP.js +1 -0
- package/dist/public/index.html +6 -6
- package/dist/{src-rqPIkHTi.mjs → src-C1Um6yPF.mjs} +3 -3
- package/dist/{src-DHnGx64r.mjs → src-C445dwsE.mjs} +1 -1
- package/dist/src-DblXU7Ud.mjs +1 -0
- package/dist/start-C-cNVeh0.mjs +1 -0
- package/dist/{start-DAAnFlO5.mjs → start-z2CFfZyW.mjs} +2 -2
- package/package.json +1 -1
- package/dist/constants-DA7Qh-Kl.mjs +0 -2
- package/dist/init-CFVYH-16.mjs +0 -1
- package/dist/init-DQNJ_f3z.mjs +0 -1
- package/dist/loader-89zKhhvs.mjs +0 -1
- package/dist/paths-BhmQnYL9.mjs +0 -1
- package/dist/preview-CULBnUoI.mjs +0 -1
- package/dist/public/assets/McpConsentDialogBody-BTLTOjWM.js +0 -1
- package/dist/public/assets/index-CGTgnYOo.css +0 -1
- package/dist/public/assets/index-DUIfxmm6.js +0 -21
- package/dist/public/assets/toggle-group-BNTPJpXY.js +0 -1
- package/dist/src-CBVTx8JJ.mjs +0 -1
- package/dist/start-D0wsbZmD.mjs +0 -1
|
@@ -1,8 +1,8 @@
|
|
|
1
|
-
import{C as e,E as t,O as n,S as r,T as i,n as a,t as o,w as s,x as c}from"./button-BuHZQnlF.js";import{$ as l,A as u,At as d,Bt as f,Ct as p,D as m,Dt as h,E as g,Et as _,F as v,Ft as y,G as b,Gt as x,H as S,I as C,It as w,J as T,L as E,M as D,Mt as O,N as k,Nt as A,O as j,Ot as M,P as N,Pt as P,Q as F,Qt as I,R as ee,Tt as L,U as R,V as z,Vt as B,Xt as V,_ as te,a as ne,dt as re,f as ie,ft as ae,g as oe,h as se,ht as ce,i as le,j as ue,jt as de,k as fe,kt as H,l as pe,lt as me,mt as he,n as ge,o as _e,ot as ve,p as ye,pt as be,qt as xe,r as Se,s as Ce,st as we,t as Te,u as Ee,ut as De,v as Oe,vt as ke,wt as Ae,xt as je,y as Me,yt as Ne,zt as Pe}from"./panel-CnHxXki4.js";import{a as Fe,b as Ie,d as Le,f as Re,i as ze,l as Be,m as Ve,o as He,p as Ue,r as We,s as Ge,t as Ke,u as qe,x as Je}from"./dialog-C2kd-BJI.js";import{$ as Ye,A as Xe,B as Ze,Bt as Qe,Ct as $e,D as et,Dt as tt,E as nt,Et as rt,Ft as it,G as at,H as ot,Ht as st,I as ct,It as lt,J as ut,K as dt,L as U,Lt as ft,M as pt,N as mt,Nt as ht,P as gt,Pt as _t,Q as vt,Rt as yt,S as bt,St as xt,T as St,Tt as W,U as Ct,V as wt,Vt as Tt,W as Et,Y as Dt,Z as Ot,_ as kt,a as At,at as jt,b as Mt,bt as Nt,c as Pt,ct as Ft,d as It,et as Lt,f as Rt,g as zt,gt as Bt,h as Vt,ht as Ht,i as Ut,j as Wt,jt as Gt,k as Kt,kt as qt,l as Jt,lt as Yt,mt as Xt,n as Zt,nt as Qt,o as $t,ot as en,p as tn,pt as nn,q as rn,r as an,s as on,st as sn,t as cn,tt as ln,u as un,ut as dn,v as fn,vt as pn,w as mn,x as hn,xt as gn,y as _n,z as vn,zt as yn}from"./dist-1RA1Ivz5.js";import{a as bn,c as xn,i as Sn,n as Cn,o as wn,r as Tn,s as En,t as Dn}from"./dist-B90Tbt-G.js";import{i as On,n as kn,r as An,t as jn}from"./dist-BJa-wTjR.js";var Mn=c(`circle-alert`,[[`circle`,{cx:`12`,cy:`12`,r:`10`,key:`1mglay`}],[`line`,{x1:`12`,x2:`12`,y1:`8`,y2:`12`,key:`1pkeuh`}],[`line`,{x1:`12`,x2:`12.01`,y1:`16`,y2:`16`,key:`4dfq90`}]]),Nn=c(`code-xml`,[[`path`,{d:`m18 16 4-4-4-4`,key:`1inbqp`}],[`path`,{d:`m6 8-4 4 4 4`,key:`15zrgr`}],[`path`,{d:`m14.5 4-5 16`,key:`e7oirm`}]]),Pn=c(`external-link`,[[`path`,{d:`M15 3h6v6`,key:`1q9fwt`}],[`path`,{d:`M10 14 21 3`,key:`gplh6r`}],[`path`,{d:`M18 13v6a2 2 0 0 1-2 2H5a2 2 0 0 1-2-2V8a2 2 0 0 1 2-2h6`,key:`a6xqqp`}]]),Fn=c(`file-plus-corner`,[[`path`,{d:`M11.35 22H6a2 2 0 0 1-2-2V4a2 2 0 0 1 2-2h8a2.4 2.4 0 0 1 1.706.706l3.588 3.588A2.4 2.4 0 0 1 20 8v5.35`,key:`17jvcc`}],[`path`,{d:`M14 2v5a1 1 0 0 0 1 1h5`,key:`wfsgrz`}],[`path`,{d:`M14 19h6`,key:`bvotb8`}],[`path`,{d:`M17 16v6`,key:`18yu1i`}]]),In=c(`file`,[[`path`,{d:`M6 22a2 2 0 0 1-2-2V4a2 2 0 0 1 2-2h8a2.4 2.4 0 0 1 1.704.706l3.588 3.588A2.4 2.4 0 0 1 20 8v12a2 2 0 0 1-2 2z`,key:`1oefj6`}],[`path`,{d:`M14 2v5a1 1 0 0 0 1 1h5`,key:`wfsgrz`}]]),Ln=c(`folder-open`,[[`path`,{d:`m6 14 1.5-2.9A2 2 0 0 1 9.24 10H20a2 2 0 0 1 1.94 2.5l-1.54 6a2 2 0 0 1-1.95 1.5H4a2 2 0 0 1-2-2V5a2 2 0 0 1 2-2h3.9a2 2 0 0 1 1.69.9l.81 1.2a2 2 0 0 0 1.67.9H18a2 2 0 0 1 2 2v2`,key:`usdka0`}]]),Rn=c(`heading-1`,[[`path`,{d:`M4 12h8`,key:`17cfdx`}],[`path`,{d:`M4 18V6`,key:`1rz3zl`}],[`path`,{d:`M12 18V6`,key:`zqpxq5`}],[`path`,{d:`m17 12 3-2v8`,key:`1hhhft`}]]),zn=c(`heading-2`,[[`path`,{d:`M4 12h8`,key:`17cfdx`}],[`path`,{d:`M4 18V6`,key:`1rz3zl`}],[`path`,{d:`M12 18V6`,key:`zqpxq5`}],[`path`,{d:`M21 18h-4c0-4 4-3 4-6 0-1.5-2-2.5-4-1`,key:`9jr5yi`}]]),Bn=c(`heading-3`,[[`path`,{d:`M4 12h8`,key:`17cfdx`}],[`path`,{d:`M4 18V6`,key:`1rz3zl`}],[`path`,{d:`M12 18V6`,key:`zqpxq5`}],[`path`,{d:`M17.5 10.5c1.7-1 3.5 0 3.5 1.5a2 2 0 0 1-2 2`,key:`68ncm8`}],[`path`,{d:`M17 17.5c2 1.5 4 .3 4-1.5a2 2 0 0 0-2-2`,key:`1ejuhz`}]]),Vn=c(`image`,[[`rect`,{width:`18`,height:`18`,x:`3`,y:`3`,rx:`2`,ry:`2`,key:`1m3agn`}],[`circle`,{cx:`9`,cy:`9`,r:`2`,key:`af1f0g`}],[`path`,{d:`m21 15-3.086-3.086a2 2 0 0 0-2.828 0L6 21`,key:`1xmnt7`}]]),Hn=c(`list-ordered`,[[`path`,{d:`M11 5h10`,key:`1cz7ny`}],[`path`,{d:`M11 12h10`,key:`1438ji`}],[`path`,{d:`M11 19h10`,key:`11t30w`}],[`path`,{d:`M4 4h1v5`,key:`10yrso`}],[`path`,{d:`M4 9h2`,key:`r1h2o0`}],[`path`,{d:`M6.5 20H3.4c0-1 2.6-1.925 2.6-3.5a1.5 1.5 0 0 0-2.6-1.02`,key:`xtkcd5`}]]),Un=c(`list-todo`,[[`path`,{d:`M13 5h8`,key:`a7qcls`}],[`path`,{d:`M13 12h8`,key:`h98zly`}],[`path`,{d:`M13 19h8`,key:`c3s6r1`}],[`path`,{d:`m3 17 2 2 4-4`,key:`1jhpwq`}],[`rect`,{x:`3`,y:`4`,width:`6`,height:`6`,rx:`1`,key:`cif1o7`}]]),Wn=c(`list`,[[`path`,{d:`M3 5h.01`,key:`18ugdj`}],[`path`,{d:`M3 12h.01`,key:`nlz23k`}],[`path`,{d:`M3 19h.01`,key:`noohij`}],[`path`,{d:`M8 5h13`,key:`1pao27`}],[`path`,{d:`M8 12h13`,key:`1za7za`}],[`path`,{d:`M8 19h13`,key:`m83p4d`}]]),Gn=c(`loader-circle`,[[`path`,{d:`M21 12a9 9 0 1 1-6.219-8.56`,key:`13zald`}]]),Kn=c(`minus`,[[`path`,{d:`M5 12h14`,key:`1ays0h`}]]),qn=c(`pencil`,[[`path`,{d:`M21.174 6.812a1 1 0 0 0-3.986-3.987L3.842 16.174a2 2 0 0 0-.5.83l-1.321 4.352a.5.5 0 0 0 .623.622l4.353-1.32a2 2 0 0 0 .83-.497z`,key:`1a8usu`}],[`path`,{d:`m15 5 4 4`,key:`1mk7zo`}]]),Jn=c(`quote`,[[`path`,{d:`M16 3a2 2 0 0 0-2 2v6a2 2 0 0 0 2 2 1 1 0 0 1 1 1v1a2 2 0 0 1-2 2 1 1 0 0 0-1 1v2a1 1 0 0 0 1 1 6 6 0 0 0 6-6V5a2 2 0 0 0-2-2z`,key:`rib7q0`}],[`path`,{d:`M5 3a2 2 0 0 0-2 2v6a2 2 0 0 0 2 2 1 1 0 0 1 1 1v1a2 2 0 0 1-2 2 1 1 0 0 0-1 1v2a1 1 0 0 0 1 1 6 6 0 0 0 6-6V5a2 2 0 0 0-2-2z`,key:`1ymkrd`}]]),Yn=c(`table-2`,[[`path`,{d:`M9 3H5a2 2 0 0 0-2 2v4m6-6h10a2 2 0 0 1 2 2v4M9 3v18m0 0h10a2 2 0 0 0 2-2V9M9 21H5a2 2 0 0 1-2-2V9m0 0h18`,key:`gugj83`}]]),Xn=c(`trash-2`,[[`path`,{d:`M10 11v6`,key:`nco0om`}],[`path`,{d:`M14 11v6`,key:`outv1u`}],[`path`,{d:`M19 6v14a2 2 0 0 1-2 2H7a2 2 0 0 1-2-2V6`,key:`miytrc`}],[`path`,{d:`M3 6h18`,key:`d0wm0j`}],[`path`,{d:`M8 6V4a2 2 0 0 1 2-2h4a2 2 0 0 1 2 2v2`,key:`e791ji`}]]),Zn=t((e=>{var t=i();function n(e,t){return e===t&&(e!==0||1/e==1/t)||e!==e&&t!==t}var r=typeof Object.is==`function`?Object.is:n,a=t.useState,o=t.useEffect,s=t.useLayoutEffect,c=t.useDebugValue;function l(e,t){var n=t(),r=a({inst:{value:n,getSnapshot:t}}),i=r[0].inst,l=r[1];return s(function(){i.value=n,i.getSnapshot=t,u(i)&&l({inst:i})},[e,n,t]),o(function(){return u(i)&&l({inst:i}),e(function(){u(i)&&l({inst:i})})},[e]),c(n),n}function u(e){var t=e.getSnapshot;e=e.value;try{var n=t();return!r(e,n)}catch{return!0}}function d(e,t){return t()}var f=typeof window>`u`||window.document===void 0||window.document.createElement===void 0?d:l;e.useSyncExternalStore=t.useSyncExternalStore===void 0?f:t.useSyncExternalStore})),Qn=t(((e,t)=>{t.exports=Zn()})),$n=`modulepreload`,er=function(e){return`/`+e},tr={},nr=function(e,t,n){let r=Promise.resolve();if(t&&t.length>0){let e=document.getElementsByTagName(`link`),i=document.querySelector(`meta[property=csp-nonce]`),a=i?.nonce||i?.getAttribute(`nonce`);function o(e){return Promise.all(e.map(e=>Promise.resolve(e).then(e=>({status:`fulfilled`,value:e}),e=>({status:`rejected`,reason:e}))))}r=o(t.map(t=>{if(t=er(t,n),t in tr)return;tr[t]=!0;let r=t.endsWith(`.css`),i=r?`[rel="stylesheet"]`:``;if(n)for(let n=e.length-1;n>=0;n--){let i=e[n];if(i.href===t&&(!r||i.rel===`stylesheet`))return}else if(document.querySelector(`link[href="${t}"]${i}`))return;let o=document.createElement(`link`);if(o.rel=r?`stylesheet`:$n,r||(o.as=`script`),o.crossOrigin=``,o.href=t,a&&o.setAttribute(`nonce`,a),document.head.appendChild(o),r)return new Promise((e,n)=>{o.addEventListener(`load`,e),o.addEventListener(`error`,()=>n(Error(`Unable to preload CSS for ${t}`)))})}))}function i(e){let t=new Event(`vite:preloadError`,{cancelable:!0});if(t.payload=e,window.dispatchEvent(t),!t.defaultPrevented)throw e}return r.then(t=>{for(let e of t||[])e.status===`rejected`&&i(e.reason);return e().catch(i)})},G=n(i(),1),rr=r();function ir(e){let t=e.split(`/`);return t.length<2?`ok`:`${t[0]}/${t[1]}`}function ar(e){if(!e)return;let t=Object.entries(e);if(t.length!==0)return t.map(([e,t])=>{if(t==null)return[e,String(t)];if(typeof t==`string`)return[e,t];if(typeof t==`number`||typeof t==`boolean`)return[e,String(t)];try{return[e,JSON.stringify(t)]}catch{return[e,`[unserializable]`]}})}function K(e,t,n){if(typeof performance>`u`||!performance.measure)return;let r=ir(e),i=ar(t),a={devtools:{dataType:`track-entry`,track:r,...i?{properties:i}:{},...n?.tooltipText?{tooltipText:n.tooltipText}:{}}},o=performance.now(),s=n?.startTime??o,c=n?.duration??Math.max(0,o-s);try{performance.measure(e,{start:s,duration:c,detail:a})}catch{}({...t?{properties:t}:{}})}var q=s();function or(e){let t=(0,rr.c)(3),{name:n,children:r}=e,i;return t[0]!==r||t[1]!==n?(i=(0,q.jsx)(G.Profiler,{id:n,onRender:sr,children:r}),t[0]=r,t[1]=n,t[2]=i):i=t[2],i}var sr=(e,t,n,r,i,a)=>{K(`ok/render/${e}`,{phase:t,actualDuration:Math.round(n*1e3)/1e3,baseDuration:Math.round(r*1e3)/1e3},{startTime:i,duration:Math.max(0,a-i)})},cr=n(e(),1),lr=Qn(),{getOwnPropertyNames:ur,getOwnPropertySymbols:dr}=Object,{hasOwnProperty:fr}=Object.prototype;function pr(e,t){return function(n,r,i){return e(n,r,i)&&t(n,r,i)}}function mr(e){return function(t,n,r){if(!t||!n||typeof t!=`object`||typeof n!=`object`)return e(t,n,r);let{cache:i}=r,a=i.get(t),o=i.get(n);if(a&&o)return a===n&&o===t;i.set(t,n),i.set(n,t);let s=e(t,n,r);return i.delete(t),i.delete(n),s}}function hr(e){return e?.[Symbol.toStringTag]}function gr(e){return ur(e).concat(dr(e))}var _r=Object.hasOwn||((e,t)=>fr.call(e,t));function vr(e,t){return e===t||!e&&!t&&e!==e&&t!==t}var yr=`__v`,br=`__o`,xr=`_owner`,{getOwnPropertyDescriptor:Sr,keys:Cr}=Object;function wr(e,t){return e.byteLength===t.byteLength&&Lr(new Uint8Array(e),new Uint8Array(t))}function Tr(e,t,n){let r=e.length;if(t.length!==r)return!1;for(;r-- >0;)if(!n.equals(e[r],t[r],r,r,e,t,n))return!1;return!0}function Er(e,t){return e.byteLength===t.byteLength&&Lr(new Uint8Array(e.buffer,e.byteOffset,e.byteLength),new Uint8Array(t.buffer,t.byteOffset,t.byteLength))}function Dr(e,t){return vr(e.getTime(),t.getTime())}function Or(e,t){return e.name===t.name&&e.message===t.message&&e.cause===t.cause&&e.stack===t.stack}function kr(e,t){return e===t}function Ar(e,t,n){let r=e.size;if(r!==t.size)return!1;if(!r)return!0;let i=Array(r),a=e.entries(),o,s,c=0;for(;(o=a.next())&&!o.done;){let r=t.entries(),a=!1,l=0;for(;(s=r.next())&&!s.done;){if(i[l]){l++;continue}let r=o.value,u=s.value;if(n.equals(r[0],u[0],c,l,e,t,n)&&n.equals(r[1],u[1],r[0],u[0],e,t,n)){a=i[l]=!0;break}l++}if(!a)return!1;c++}return!0}var jr=vr;function Mr(e,t,n){let r=Cr(e),i=r.length;if(Cr(t).length!==i)return!1;for(;i-- >0;)if(!zr(e,t,n,r[i]))return!1;return!0}function Nr(e,t,n){let r=gr(e),i=r.length;if(gr(t).length!==i)return!1;let a,o,s;for(;i-- >0;)if(a=r[i],!zr(e,t,n,a)||(o=Sr(e,a),s=Sr(t,a),(o||s)&&(!o||!s||o.configurable!==s.configurable||o.enumerable!==s.enumerable||o.writable!==s.writable)))return!1;return!0}function Pr(e,t){return vr(e.valueOf(),t.valueOf())}function Fr(e,t){return e.source===t.source&&e.flags===t.flags}function Ir(e,t,n){let r=e.size;if(r!==t.size)return!1;if(!r)return!0;let i=Array(r),a=e.values(),o,s;for(;(o=a.next())&&!o.done;){let r=t.values(),a=!1,c=0;for(;(s=r.next())&&!s.done;){if(!i[c]&&n.equals(o.value,s.value,o.value,s.value,e,t,n)){a=i[c]=!0;break}c++}if(!a)return!1}return!0}function Lr(e,t){let n=e.byteLength;if(t.byteLength!==n||e.byteOffset!==t.byteOffset)return!1;for(;n-- >0;)if(e[n]!==t[n])return!1;return!0}function Rr(e,t){return e.hostname===t.hostname&&e.pathname===t.pathname&&e.protocol===t.protocol&&e.port===t.port&&e.hash===t.hash&&e.username===t.username&&e.password===t.password}function zr(e,t,n,r){return(r===xr||r===br||r===yr)&&(e.$$typeof||t.$$typeof)?!0:_r(t,r)&&n.equals(e[r],t[r],r,r,e,t,n)}var Br=`[object ArrayBuffer]`,Vr=`[object Arguments]`,Hr=`[object Boolean]`,Ur=`[object DataView]`,Wr=`[object Date]`,Gr=`[object Error]`,Kr=`[object Map]`,qr=`[object Number]`,Jr=`[object Object]`,Yr=`[object RegExp]`,Xr=`[object Set]`,Zr=`[object String]`,Qr={"[object Int8Array]":!0,"[object Uint8Array]":!0,"[object Uint8ClampedArray]":!0,"[object Int16Array]":!0,"[object Uint16Array]":!0,"[object Int32Array]":!0,"[object Uint32Array]":!0,"[object Float16Array]":!0,"[object Float32Array]":!0,"[object Float64Array]":!0,"[object BigInt64Array]":!0,"[object BigUint64Array]":!0},$r=`[object URL]`,ei=Object.prototype.toString;function ti({areArrayBuffersEqual:e,areArraysEqual:t,areDataViewsEqual:n,areDatesEqual:r,areErrorsEqual:i,areFunctionsEqual:a,areMapsEqual:o,areNumbersEqual:s,areObjectsEqual:c,arePrimitiveWrappersEqual:l,areRegExpsEqual:u,areSetsEqual:d,areTypedArraysEqual:f,areUrlsEqual:p,unknownTagComparators:m}){return function(h,g,_){if(h===g)return!0;if(h==null||g==null)return!1;let v=typeof h;if(v!==typeof g)return!1;if(v!==`object`)return v===`number`?s(h,g,_):v===`function`?a(h,g,_):!1;let y=h.constructor;if(y!==g.constructor)return!1;if(y===Object)return c(h,g,_);if(Array.isArray(h))return t(h,g,_);if(y===Date)return r(h,g,_);if(y===RegExp)return u(h,g,_);if(y===Map)return o(h,g,_);if(y===Set)return d(h,g,_);let b=ei.call(h);if(b===Wr)return r(h,g,_);if(b===Yr)return u(h,g,_);if(b===Kr)return o(h,g,_);if(b===Xr)return d(h,g,_);if(b===Jr)return typeof h.then!=`function`&&typeof g.then!=`function`&&c(h,g,_);if(b===$r)return p(h,g,_);if(b===Gr)return i(h,g,_);if(b===Vr)return c(h,g,_);if(Qr[b])return f(h,g,_);if(b===Br)return e(h,g,_);if(b===Ur)return n(h,g,_);if(b===Hr||b===qr||b===Zr)return l(h,g,_);if(m){let e=m[b];if(!e){let t=hr(h);t&&(e=m[t])}if(e)return e(h,g,_)}return!1}}function ni({circular:e,createCustomConfig:t,strict:n}){let r={areArrayBuffersEqual:wr,areArraysEqual:n?Nr:Tr,areDataViewsEqual:Er,areDatesEqual:Dr,areErrorsEqual:Or,areFunctionsEqual:kr,areMapsEqual:n?pr(Ar,Nr):Ar,areNumbersEqual:jr,areObjectsEqual:n?Nr:Mr,arePrimitiveWrappersEqual:Pr,areRegExpsEqual:Fr,areSetsEqual:n?pr(Ir,Nr):Ir,areTypedArraysEqual:n?pr(Lr,Nr):Lr,areUrlsEqual:Rr,unknownTagComparators:void 0};if(t&&(r=Object.assign({},r,t(r))),e){let e=mr(r.areArraysEqual),t=mr(r.areMapsEqual),n=mr(r.areObjectsEqual),i=mr(r.areSetsEqual);r=Object.assign({},r,{areArraysEqual:e,areMapsEqual:t,areObjectsEqual:n,areSetsEqual:i})}return r}function ri(e){return function(t,n,r,i,a,o,s){return e(t,n,s)}}function ii({circular:e,comparator:t,createState:n,equals:r,strict:i}){if(n)return function(a,o){let{cache:s=e?new WeakMap:void 0,meta:c}=n();return t(a,o,{cache:s,equals:r,meta:c,strict:i})};if(e)return function(e,n){return t(e,n,{cache:new WeakMap,equals:r,meta:void 0,strict:i})};let a={cache:void 0,equals:r,meta:void 0,strict:i};return function(e,n){return t(e,n,a)}}var ai=oi();oi({strict:!0}),oi({circular:!0}),oi({circular:!0,strict:!0}),oi({createInternalComparator:()=>vr}),oi({strict:!0,createInternalComparator:()=>vr}),oi({circular:!0,createInternalComparator:()=>vr}),oi({circular:!0,createInternalComparator:()=>vr,strict:!0});function oi(e={}){let{circular:t=!1,createInternalComparator:n,createState:r,strict:i=!1}=e,a=ti(ni(e));return ii({circular:t,comparator:a,createState:r,equals:n?n(a):ri(a),strict:i})}var si=t((e=>{var t=i(),n=Qn();function r(e,t){return e===t&&(e!==0||1/e==1/t)||e!==e&&t!==t}var a=typeof Object.is==`function`?Object.is:r,o=n.useSyncExternalStore,s=t.useRef,c=t.useEffect,l=t.useMemo,u=t.useDebugValue;e.useSyncExternalStoreWithSelector=function(e,t,n,r,i){var d=s(null);if(d.current===null){var f={hasValue:!1,value:null};d.current=f}else f=d.current;d=l(function(){function e(e){if(!o){if(o=!0,s=e,e=r(e),i!==void 0&&f.hasValue){var t=f.value;if(i(t,e))return c=t}return c=e}if(t=c,a(s,e))return t;var n=r(e);return i!==void 0&&i(t,n)?(s=e,t):(s=e,c=n)}var o=!1,s,c,l=n===void 0?null:n;return[function(){return e(t())},l===null?void 0:function(){return e(l())}]},[t,n,r,i]);var p=o(e,d[0],d[1]);return c(function(){f.hasValue=!0,f.value=p},[p]),u(p),p}})),ci=t(((e,t)=>{t.exports=si()}))(),li=(...e)=>t=>{e.forEach(e=>{typeof e==`function`?e(t):e&&(e.current=t)})},ui=({contentComponent:e})=>{let t=(0,lr.useSyncExternalStore)(e.subscribe,e.getSnapshot,e.getServerSnapshot);return(0,q.jsx)(q.Fragment,{children:Object.values(t)})};function di(){let e=new Set,t={};return{subscribe(t){return e.add(t),()=>{e.delete(t)}},getSnapshot(){return t},getServerSnapshot(){return t},setRenderer(n,r){t={...t,[n]:cr.createPortal(r.reactElement,r.element,n)},e.forEach(e=>e())},removeRenderer(n){let r={...t};delete r[n],t=r,e.forEach(e=>e())}}}var fi=class extends G.Component{constructor(e){super(e),this.editorContentRef=G.createRef()}componentDidMount(){this.init()}componentDidUpdate(){this.init()}init(){let e=this.props.editor;if(e&&!e.isDestroyed&&e.view.dom?.parentNode){if(e.contentComponent)return;let t=this.editorContentRef.current;t.append(...e.view.dom.parentNode.childNodes),e.setOptions({element:t}),e.contentComponent=di(),e.createNodeViews(),e.isEditorContentInitialized=!0,this.forceUpdate()}}componentWillUnmount(){let e=this.props.editor;if(e){e.isEditorContentInitialized=!1,e.isDestroyed||e.view.setProps({nodeViews:{}}),e.contentComponent=null;try{if(!e.view.dom?.parentNode)return;let t=document.createElement(`div`);t.append(...e.view.dom.parentNode.childNodes),e.setOptions({element:t})}catch{}}}render(){let{editor:e,innerRef:t,...n}=this.props;return(0,q.jsxs)(q.Fragment,{children:[(0,q.jsx)(`div`,{ref:li(t,this.editorContentRef),...n}),e?.contentComponent&&(0,q.jsx)(ui,{contentComponent:e.contentComponent})]})}},pi=(0,G.forwardRef)((e,t)=>{let n=G.useMemo(()=>Math.floor(Math.random()*4294967295).toString(),[e.editor]);return G.createElement(fi,{key:n,innerRef:t,...e})}),mi=G.memo(pi),hi=typeof window<`u`?G.useLayoutEffect:G.useEffect,gi=class{constructor(e){this.transactionNumber=0,this.lastTransactionNumber=0,this.subscribers=new Set,this.editor=e,this.lastSnapshot={editor:e,transactionNumber:0},this.getSnapshot=this.getSnapshot.bind(this),this.getServerSnapshot=this.getServerSnapshot.bind(this),this.watch=this.watch.bind(this),this.subscribe=this.subscribe.bind(this)}getSnapshot(){return this.transactionNumber===this.lastTransactionNumber?this.lastSnapshot:(this.lastTransactionNumber=this.transactionNumber,this.lastSnapshot={editor:this.editor,transactionNumber:this.transactionNumber},this.lastSnapshot)}getServerSnapshot(){return{editor:null,transactionNumber:0}}subscribe(e){return this.subscribers.add(e),()=>{this.subscribers.delete(e)}}watch(e){if(this.editor=e,this.editor){let e=()=>{this.transactionNumber+=1,this.subscribers.forEach(e=>e())},t=this.editor;return t.on(`transaction`,e),()=>{t.off(`transaction`,e)}}}};function _i(e){let[t]=(0,G.useState)(()=>new gi(e.editor)),n=(0,ci.useSyncExternalStoreWithSelector)(t.subscribe,t.getSnapshot,t.getServerSnapshot,e.selector,e.equalityFn??ai);return hi(()=>t.watch(e.editor),[e.editor,t]),(0,G.useDebugValue)(n),n}typeof window>`u`||typeof window<`u`&&window.next;var vi=(0,G.createContext)({editor:null});vi.Consumer;var yi=()=>(0,G.useContext)(vi),bi=(0,G.createContext)({onDragStart:()=>{},nodeViewContentChildren:void 0,nodeViewContentRef:()=>{}}),xi=()=>(0,G.useContext)(bi),Si=G.forwardRef((e,t)=>{let{onDragStart:n}=xi();return(0,q.jsx)(e.as||`div`,{...e,ref:t,"data-node-view-wrapper":``,onDragStart:n,style:{whiteSpace:`normal`,...e.style}})});function Ci(e){return!!(typeof e==`function`&&e.prototype&&e.prototype.isReactComponent)}function wi(e){return!!(typeof e==`object`&&e.$$typeof&&(e.$$typeof.toString()===`Symbol(react.forward_ref)`||e.$$typeof.description===`react.forward_ref`))}function Ti(e){return!!(typeof e==`object`&&e.$$typeof&&(e.$$typeof.toString()===`Symbol(react.memo)`||e.$$typeof.description===`react.memo`))}function Ei(e){if(Ci(e)||wi(e))return!0;if(Ti(e)){let t=e.type;if(t)return Ci(t)||wi(t)}return!1}function Di(){try{if(G.version)return parseInt(G.version.split(`.`)[0],10)>=19}catch{}return!1}var Oi=class{constructor(e,{editor:t,props:n={},as:r=`div`,className:i=``}){this.ref=null,this.destroyed=!1,this.id=Math.floor(Math.random()*4294967295).toString(),this.component=e,this.editor=t,this.props=n,this.element=document.createElement(r),this.element.classList.add(`react-renderer`),i&&this.element.classList.add(...i.split(` `)),this.editor.isEditorContentInitialized?(0,cr.flushSync)(()=>{this.render()}):queueMicrotask(()=>{this.destroyed||this.render()})}render(){var e;if(this.destroyed)return;let t=this.component,n=this.props,r=this.editor,i=Di(),a=Ei(t),o={...n};o.ref&&!(i||a)&&delete o.ref,!o.ref&&(i||a)&&(o.ref=e=>{this.ref=e}),this.reactElement=(0,q.jsx)(t,{...o}),(e=r?.contentComponent)==null||e.setRenderer(this.id,this)}updateProps(e={}){this.destroyed||(this.props={...this.props,...e},this.render())}destroy(){var e;this.destroyed=!0,(e=this.editor?.contentComponent)==null||e.removeRenderer(this.id);try{this.element&&this.element.parentNode&&this.element.parentNode.removeChild(this.element)}catch{}}updateAttributes(e){Object.keys(e).forEach(t=>{this.element.setAttribute(t,e[t])})}};G.createContext({markViewContentRef:()=>{}});var ki=class extends re{constructor(e,t,n){if(super(e,t,n),this.selectionRafId=null,this.positionCheckCallback=null,this.cachedExtensionWithSyncedStorage=null,!this.node.isLeaf){this.options.contentDOMElementTag?this.contentDOMElement=document.createElement(this.options.contentDOMElementTag):this.contentDOMElement=document.createElement(this.node.isInline?`span`:`div`),this.contentDOMElement.dataset.nodeViewContentReact=``,this.contentDOMElement.dataset.nodeViewWrapper=``,this.contentDOMElement.style.whiteSpace=`inherit`;let e=this.dom.querySelector(`[data-node-view-content]`);if(!e)return;e.appendChild(this.contentDOMElement)}}get extensionWithSyncedStorage(){if(!this.cachedExtensionWithSyncedStorage){let e=this.editor,t=this.extension;this.cachedExtensionWithSyncedStorage=new Proxy(t,{get(n,r,i){return r===`storage`?e.storage[t.name]??{}:Reflect.get(n,r,i)}})}return this.cachedExtensionWithSyncedStorage}mount(){let e={editor:this.editor,node:this.node,decorations:this.decorations,innerDecorations:this.innerDecorations,view:this.view,selected:!1,extension:this.extensionWithSyncedStorage,HTMLAttributes:this.HTMLAttributes,getPos:()=>this.getPos(),updateAttributes:(e={})=>this.updateAttributes(e),deleteNode:()=>this.deleteNode(),ref:(0,G.createRef)()};if(!this.component.displayName){let e=e=>e.charAt(0).toUpperCase()+e.substring(1);this.component.displayName=e(this.extension.name)}let t={onDragStart:this.onDragStart.bind(this),nodeViewContentRef:e=>{e&&this.contentDOMElement&&e.firstChild!==this.contentDOMElement&&(e.hasAttribute(`data-node-view-wrapper`)&&e.removeAttribute(`data-node-view-wrapper`),e.appendChild(this.contentDOMElement))}},n=this.component,r=(0,G.memo)(e=>(0,q.jsx)(bi.Provider,{value:t,children:(0,G.createElement)(n,e)}));r.displayName=`ReactNodeView`;let i=this.node.isInline?`span`:`div`;this.options.as&&(i=this.options.as);let{className:a=``}=this.options;this.handleSelectionUpdate=this.handleSelectionUpdate.bind(this),this.renderer=new Oi(r,{editor:this.editor,props:e,as:i,className:`node-${this.node.type.name} ${a}`.trim()}),this.editor.on(`selectionUpdate`,this.handleSelectionUpdate),this.updateElementAttributes(),this.currentPos=this.getPos(),this.positionCheckCallback=()=>{let e=this.getPos();typeof e!=`number`||e===this.currentPos||(this.currentPos=e,this.renderer.updateProps({getPos:()=>this.getPos()}),typeof this.options.attrs==`function`&&this.updateElementAttributes())},p(this.editor,this.positionCheckCallback)}get dom(){if(this.renderer.element.firstElementChild&&!this.renderer.element.firstElementChild?.hasAttribute(`data-node-view-wrapper`))throw Error(`Please use the NodeViewWrapper component for your node view.`);return this.renderer.element}get contentDOM(){return this.node.isLeaf?null:this.contentDOMElement}handleSelectionUpdate(){this.selectionRafId&&=(cancelAnimationFrame(this.selectionRafId),null),this.selectionRafId=requestAnimationFrame(()=>{this.selectionRafId=null;let{from:e,to:t}=this.editor.state.selection,n=this.currentPos;if(typeof n==`number`)if(e<=n&&t>=n+this.node.nodeSize){if(this.renderer.props.selected)return;this.selectNode()}else{if(!this.renderer.props.selected)return;this.deselectNode()}})}update(e,t,n){let r=e=>{this.renderer.updateProps(e),typeof this.options.attrs==`function`&&this.updateElementAttributes()};if(e.type!==this.node.type)return!1;if(typeof this.options.update==`function`){let i=this.node,a=this.decorations,o=this.innerDecorations;return this.node=e,this.decorations=t,this.innerDecorations=n,this.currentPos=this.getPos(),this.options.update({oldNode:i,oldDecorations:a,newNode:e,newDecorations:t,oldInnerDecorations:o,innerDecorations:n,updateProps:()=>r({node:e,decorations:t,innerDecorations:n,extension:this.extensionWithSyncedStorage})})}let i=this.getPos();return e===this.node&&this.decorations===t&&this.innerDecorations===n?i===this.currentPos?!0:(this.currentPos=i,r({node:e,decorations:t,innerDecorations:n,extension:this.extensionWithSyncedStorage,getPos:()=>this.getPos()}),!0):(this.node=e,this.decorations=t,this.innerDecorations=n,this.currentPos=i,r({node:e,decorations:t,innerDecorations:n,extension:this.extensionWithSyncedStorage}),!0)}selectNode(){this.renderer.updateProps({selected:!0}),this.renderer.element.classList.add(`ProseMirror-selectednode`)}deselectNode(){this.renderer.updateProps({selected:!1}),this.renderer.element.classList.remove(`ProseMirror-selectednode`)}destroy(){this.renderer.destroy(),this.editor.off(`selectionUpdate`,this.handleSelectionUpdate),this.positionCheckCallback&&=(ae(this.editor,this.positionCheckCallback),null),this.contentDOMElement=null,this.selectionRafId&&=(cancelAnimationFrame(this.selectionRafId),null)}updateElementAttributes(){if(this.options.attrs){let e={};if(typeof this.options.attrs==`function`){let t=this.editor.extensionManager.attributes,n=he(this.node,t);e=this.options.attrs({node:this.node,HTMLAttributes:n})}else e=this.options.attrs;this.renderer.updateAttributes(e)}}};function Ai(e,t){return n=>n.editor.contentComponent?new ki(e,n,t):{}}var ji=(0,G.createContext)({get editor(){throw Error(`useTiptap must be used within a <Tiptap> provider`)}});ji.displayName=`TiptapContext`;var Mi=()=>(0,G.useContext)(ji);function Ni({editor:e,instance:t,children:n}){let r=e??t;if(!r)throw Error("Tiptap: An editor instance is required. Pass a non-null `editor` prop.");let i=(0,G.useMemo)(()=>({editor:r}),[r]),a=(0,G.useMemo)(()=>({editor:r}),[r]);return(0,q.jsx)(vi.Provider,{value:a,children:(0,q.jsx)(ji.Provider,{value:i,children:n})})}Ni.displayName=`Tiptap`;function Pi({...e}){let{editor:t}=Mi();return(0,q.jsx)(mi,{editor:t,...e})}Pi.displayName=`Tiptap.Content`,Object.assign(Ni,{Content:Pi});var Fi=()=>new Map,Ii=e=>{let t=Fi();return e.forEach((e,n)=>{t.set(n,e)}),t},Li=(e,t,n)=>{let r=e.get(t);return r===void 0&&e.set(t,r=n()),r},Ri=(e,t)=>{let n=[];for(let[r,i]of e)n.push(t(i,r));return n},zi=(e,t)=>{for(let[n,r]of e)if(t(r,n))return!0;return!1},Bi=()=>new Set,Vi=e=>e[e.length-1],Hi=(e,t)=>{for(let n=0;n<t.length;n++)e.push(t[n])},Ui=Array.from,Wi=(e,t)=>{for(let n=0;n<e.length;n++)if(!t(e[n],n,e))return!1;return!0},Gi=(e,t)=>{for(let n=0;n<e.length;n++)if(t(e[n],n,e))return!0;return!1},Ki=(e,t)=>{let n=Array(e);for(let r=0;r<e;r++)n[r]=t(r,n);return n},qi=Array.isArray,Ji=class{constructor(){this._observers=Fi()}on(e,t){return Li(this._observers,e,Bi).add(t),t}once(e,t){let n=(...r)=>{this.off(e,n),t(...r)};this.on(e,n)}off(e,t){let n=this._observers.get(e);n!==void 0&&(n.delete(t),n.size===0&&this._observers.delete(e))}emit(e,t){return Ui((this._observers.get(e)||Fi()).values()).forEach(e=>e(...t))}destroy(){this._observers=Fi()}},Yi=Math.floor,Xi=Math.abs,Zi=(e,t)=>e<t?e:t,Qi=(e,t)=>e>t?e:t;Number.isNaN;var $i=e=>e===0?1/e<0:e<0,ea=1<<17,ta=1<<18,na=1<<19,ra=1<<20,ia=1<<21,aa=1<<22,oa=1<<23,sa=1<<24,ca=1<<25,la=1<<26,ua=1<<27,da=1<<28,fa=1<<29;ea-1,ta-1,na-1,ra-1,ia-1,aa-1,oa-1,sa-1,ca-1,la-1,ua-1,da-1,fa-1;var pa=2**53-1,ma=-(2**53-1),ha=Number.isInteger||(e=>typeof e==`number`&&isFinite(e)&&Yi(e)===e);Number.isNaN,Number.parseInt;var ga=String.fromCharCode;String.fromCodePoint,ga(65535);var _a=e=>e.toLowerCase(),va=/^\s*/g,ya=e=>e.replace(va,``),ba=/([A-Z])/g,xa=(e,t)=>ya(e.replace(ba,e=>`${t}${_a(e)}`)),Sa=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},Ca=typeof TextEncoder<`u`?new TextEncoder:null,wa=Ca?e=>Ca.encode(e):Sa,Ta=typeof TextDecoder>`u`?null:new TextDecoder(`utf-8`,{fatal:!0,ignoreBOM:!0});Ta&&Ta.decode(new Uint8Array).length===1&&(Ta=null);var Ea=(e,t)=>Ki(t,()=>e).join(``),Da=class{constructor(){this.cpos=0,this.cbuf=new Uint8Array(100),this.bufs=[]}},Oa=()=>new Da,ka=e=>{let t=Oa();return e(t),ja(t)},Aa=e=>{let t=e.cpos;for(let n=0;n<e.bufs.length;n++)t+=e.bufs[n].length;return t},ja=e=>{let t=new Uint8Array(Aa(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},Ma=(e,t)=>{let n=e.cbuf.length;n-e.cpos<t&&(e.bufs.push(new Uint8Array(e.cbuf.buffer,0,e.cpos)),e.cbuf=new Uint8Array(Qi(n,t)*2),e.cpos=0)},Na=(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},Pa=Na,J=(e,t)=>{for(;t>127;)Na(e,128|127&t),t=Yi(t/128);Na(e,127&t)},Fa=(e,t)=>{let n=$i(t);for(n&&(t=-t),Na(e,(t>63?128:0)|(n?64:0)|63&t),t=Yi(t/64);t>0;)Na(e,(t>127?128:0)|127&t),t=Yi(t/128)},Ia=new Uint8Array(3e4),La=Ia.length/3,Ra=Ca&&Ca.encodeInto?(e,t)=>{if(t.length<La){let n=Ca.encodeInto(t,Ia).written||0;J(e,n);for(let t=0;t<n;t++)Na(e,Ia[t])}else Ba(e,wa(t))}:(e,t)=>{let n=unescape(encodeURIComponent(t)),r=n.length;J(e,r);for(let t=0;t<r;t++)Na(e,n.codePointAt(t))},za=(e,t)=>{let n=e.cbuf.length,r=e.cpos,i=Zi(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(Qi(n*2,a)),e.cbuf.set(t.subarray(i)),e.cpos=a)},Ba=(e,t)=>{J(e,t.byteLength),za(e,t)},Va=(e,t)=>{Ma(e,t);let n=new DataView(e.cbuf.buffer,e.cpos,t);return e.cpos+=t,n},Ha=(e,t)=>Va(e,4).setFloat32(0,t,!1),Ua=(e,t)=>Va(e,8).setFloat64(0,t,!1),Wa=(e,t)=>Va(e,8).setBigInt64(0,t,!1),Ga=new DataView(new ArrayBuffer(4)),Ka=e=>(Ga.setFloat32(0,e),Ga.getFloat32(0)===e),qa=(e,t)=>{switch(typeof t){case`string`:Na(e,119),Ra(e,t);break;case`number`:ha(t)&&Xi(t)<=2147483647?(Na(e,125),Fa(e,t)):Ka(t)?(Na(e,124),Ha(e,t)):(Na(e,123),Ua(e,t));break;case`bigint`:Na(e,122),Wa(e,t);break;case`object`:if(t===null)Na(e,126);else if(qi(t)){Na(e,117),J(e,t.length);for(let n=0;n<t.length;n++)qa(e,t[n])}else if(t instanceof Uint8Array)Na(e,116),Ba(e,t);else{Na(e,118);let n=Object.keys(t);J(e,n.length);for(let r=0;r<n.length;r++){let i=n[r];Ra(e,i),qa(e,t[i])}}break;case`boolean`:Na(e,t?120:121);break;default:Na(e,127)}},Ja=class extends Da{constructor(e){super(),this.w=e,this.s=null,this.count=0}write(e){this.s===e?this.count++:(this.count>0&&J(this,this.count-1),this.count=1,this.w(this,e),this.s=e)}},Ya=e=>{e.count>0&&(Fa(e.encoder,e.count===1?e.s:-e.s),e.count>1&&J(e.encoder,e.count-2))},Xa=class{constructor(){this.encoder=new Da,this.s=0,this.count=0}write(e){this.s===e?this.count++:(Ya(this),this.count=1,this.s=e)}toUint8Array(){return Ya(this),ja(this.encoder)}},Za=e=>{if(e.count>0){let t=e.diff*2+(e.count===1?0:1);Fa(e.encoder,t),e.count>1&&J(e.encoder,e.count-2)}},Qa=class{constructor(){this.encoder=new Da,this.s=0,this.count=0,this.diff=0}write(e){this.diff===e-this.s?(this.s=e,this.count++):(Za(this),this.count=1,this.diff=e-this.s,this.s=e)}toUint8Array(){return Za(this),ja(this.encoder)}},$a=class{constructor(){this.sarr=[],this.s=``,this.lensE=new Xa}write(e){this.s+=e,this.s.length>19&&(this.sarr.push(this.s),this.s=``),this.lensE.write(e.length)}toUint8Array(){let e=new Da;return this.sarr.push(this.s),this.s=``,Ra(e,this.sarr.join(``)),za(e,this.lensE.toUint8Array()),ja(e)}},eo=e=>Error(e),to=()=>{throw eo(`Method unimplemented`)},no=()=>{throw eo(`Unexpected case`)},ro=eo(`Unexpected end of array`),io=eo(`Integer out of Range`),ao=class{constructor(e){this.arr=e,this.pos=0}},oo=e=>new ao(e),so=e=>e.pos!==e.arr.length,co=(e,t)=>{let n=new Uint8Array(e.arr.buffer,e.pos+e.arr.byteOffset,t);return e.pos+=t,n},lo=e=>co(e,Y(e)),uo=e=>e.arr[e.pos++],Y=e=>{let t=0,n=1,r=e.arr.length;for(;e.pos<r;){let r=e.arr[e.pos++];if(t+=(r&127)*n,n*=128,r<128)return t;if(t>pa)throw io}throw ro},fo=e=>{let t=e.arr[e.pos++],n=t&63,r=64,i=(t&64)>0?-1:1;if(!(t&128))return i*n;let a=e.arr.length;for(;e.pos<a;){if(t=e.arr[e.pos++],n+=(t&127)*r,r*=128,t<128)return i*n;if(n>pa)throw io}throw ro},po=Ta?e=>Ta.decode(lo(e)):e=>{let t=Y(e);if(t===0)return``;{let n=String.fromCodePoint(uo(e));if(--t<100)for(;t--;)n+=String.fromCodePoint(uo(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))}},mo=(e,t)=>{let n=new DataView(e.arr.buffer,e.arr.byteOffset+e.pos,t);return e.pos+=t,n},ho=[e=>void 0,e=>null,fo,e=>mo(e,4).getFloat32(0,!1),e=>mo(e,8).getFloat64(0,!1),e=>mo(e,8).getBigInt64(0,!1),e=>!1,e=>!0,po,e=>{let t=Y(e),n={};for(let r=0;r<t;r++){let t=po(e);n[t]=go(e)}return n},e=>{let t=Y(e),n=[];for(let r=0;r<t;r++)n.push(go(e));return n},lo],go=e=>ho[127-uo(e)](e),_o=class extends ao{constructor(e,t){super(e),this.reader=t,this.s=null,this.count=0}read(){return this.count===0&&(this.s=this.reader(this),so(this)?this.count=Y(this)+1:this.count=-1),this.count--,this.s}},vo=class extends ao{constructor(e){super(e),this.s=0,this.count=0}read(){if(this.count===0){this.s=fo(this);let e=$i(this.s);this.count=1,e&&(this.s=-this.s,this.count=Y(this)+2)}return this.count--,this.s}},yo=class extends ao{constructor(e){super(e),this.s=0,this.count=0,this.diff=0}read(){if(this.count===0){let e=fo(this),t=e&1;this.diff=Yi(e/2),this.count=1,t&&(this.count=Y(this)+2)}return this.s+=this.diff,this.count--,this.s}},bo=class{constructor(e){this.decoder=new vo(e),this.str=po(this.decoder),this.spos=0}read(){let e=this.spos+this.decoder.read(),t=this.str.slice(this.spos,e);return this.spos=e,t}};crypto.subtle;var xo=crypto.getRandomValues.bind(crypto),So=Math.random,Co=()=>xo(new Uint32Array(1))[0],wo=e=>e[Yi(So()*e.length)],To=`10000000-1000-4000-8000-100000000000`,Eo=()=>To.replace(/[018]/g,e=>(e^Co()&15>>e/4).toString(16)),Do=Date.now,Oo=e=>new Promise(e);Promise.all.bind(Promise);var ko=e=>e===void 0?null:e,Ao=new class{constructor(){this.map=new Map}setItem(e,t){this.map.set(e,t)}getItem(e){return this.map.get(e)}};try{typeof localStorage<`u`&&localStorage&&(Ao=localStorage)}catch{}var jo=Ao,Mo=Symbol(`Equality`),No=(e,t)=>e===t||!!e?.[Mo]?.(t)||!1,Po=e=>typeof e==`object`,Fo=Object.assign,Io=Object.keys,Lo=(e,t)=>{for(let n in e)t(e[n],n)},Ro=e=>Io(e).length,zo=e=>{for(let t in e)return!1;return!0},Bo=(e,t)=>{for(let n in e)if(!t(e[n],n))return!1;return!0},Vo=(e,t)=>Object.prototype.hasOwnProperty.call(e,t),Ho=(e,t)=>e===t||Ro(e)===Ro(t)&&Bo(e,(e,n)=>(e!==void 0||Vo(t,n))&&No(t[n],e)),Uo=Object.freeze,Wo=e=>{for(let t in e){let n=e[t];(typeof n==`object`||typeof n==`function`)&&Wo(e[t])}return Uo(e)},Go=(e,t,n=0)=>{try{for(;n<e.length;n++)e[n](...t)}finally{n<e.length&&Go(e,t,n+1)}},Ko=e=>e,qo=(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[Mo]!=null)return e[Mo](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)||!qo(e.get(n),t.get(n)))return!1;break;case void 0:case Object:if(Ro(e)!==Ro(t))return!1;for(let n in e)if(!Vo(e,n)||!qo(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(!qo(e[n],t[n]))return!1;break;default:return!1}return!0},Jo=(e,t)=>t.includes(e),Yo=typeof process<`u`&&process.release&&/node|io\.js/.test(process.release.name)&&Object.prototype.toString.call(typeof process<`u`?process:0)===`[object process]`,Xo=typeof window<`u`&&typeof document<`u`&&!Yo;typeof navigator<`u`&&/Mac/.test(navigator.platform);var Zo,Qo=[],$o=()=>{if(Zo===void 0)if(Yo){Zo=Fi();let e=process.argv,t=null;for(let n=0;n<e.length;n++){let r=e[n];r[0]===`-`?(t!==null&&Zo.set(t,``),t=r):t===null?Qo.push(r):(Zo.set(t,r),t=null)}t!==null&&Zo.set(t,``)}else typeof location==`object`?(Zo=Fi(),(location.search||`?`).slice(1).split(`&`).forEach(e=>{if(e.length!==0){let[t,n]=e.split(`=`);Zo.set(`--${xa(t,`-`)}`,n),Zo.set(`-${xa(t,`-`)}`,n)}})):Zo=Fi();return Zo},es=e=>$o().has(e),ts=e=>ko(Yo?{}[e.toUpperCase().replaceAll(`-`,`_`)]:jo.getItem(e)),ns=e=>es(`--`+e)||ts(e)!==null,rs=ns(`production`),is=Yo&&Jo({}.FORCE_COLOR,[`true`,`1`,`2`])||!es(`--no-colors`)&&!ns(`no-color`)&&(!Yo||process.stdout.isTTY)&&(!Yo||es(`--color`)||ts(`COLORTERM`)!==null||(ts(`TERM`)||``).includes(`color`)),as=e=>new Uint8Array(e),os=Xo?e=>{let t=``;for(let n=0;n<e.byteLength;n++)t+=ga(e[n]);return btoa(t)}:e=>Buffer.from(e.buffer,e.byteOffset,e.byteLength).toString(`base64`),ss=e=>{let t=as(e.byteLength);return t.set(e),t},cs=e=>ka(t=>qa(t,e)),ls=class{constructor(e,t){this.left=e,this.right=t}},us=(e,t)=>new ls(e,t),ds=(e,t)=>e.forEach(e=>t(e.left,e.right)),fs=e=>e.next()>=.5,ps=(e,t,n)=>Yi(e.next()*(n+1-t)+t),ms=(e,t,n)=>Yi(e.next()*(n+1-t)+t),hs=(e,t,n)=>ms(e,t,n),gs=e=>ga(hs(e,97,122)),_s=(e,t=0,n=20)=>{let r=hs(e,t,n),i=``;for(let t=0;t<r;t++)i+=gs(e);return i},vs=(e,t)=>t[hs(e,0,t.length-1)],ys=Symbol(`0schema`),bs=class{constructor(){this._rerrs=[]}extend(e,t,n,r=null){this._rerrs.push({path:e,expected:t,has:n,message:r})}toString(){let e=[];for(let t=this._rerrs.length-1;t>0;t--){let n=this._rerrs[t];e.push(Ea(` `,(this._rerrs.length-t)*2)+`${n.path==null?``:`[${n.path}] `}${n.has} doesn't match ${n.expected}. ${n.message}`)}return e.join(`
|
|
1
|
+
import{C as e,E as t,O as n,S as r,T as i,n as a,t as o,w as s,x as c}from"./button-BuHZQnlF.js";import{$ as l,$t as u,A as d,At as f,Bt as p,D as m,Dt as h,Et as g,F as _,Ft as v,H as y,Ht as b,I as x,It as S,Jt as C,K as w,Kt as T,L as E,Lt as D,M as O,Mt as k,N as A,Nt as j,O as M,Ot as N,P,Pt as F,R as I,St as L,Tt as R,U as z,Vt as B,W as V,Y as H,Zt as ee,_ as te,a as ne,bt as re,ct as ie,dt as ae,et as oe,f as se,ft as ce,g as le,gt as ue,h as de,ht as fe,i as pe,j as me,jt as he,k as ge,kt as _e,l as ve,mt as ye,n as be,o as xe,p as Se,pt as Ce,r as we,s as Te,st as Ee,t as De,u as Oe,ut as ke,v as Ae,wt as je,y as Me,yt as Ne,z as Pe}from"./panel-B3Oezbzt.js";import{C as Fe,a as Ie,d as Le,f as Re,i as ze,l as Be,m as Ve,o as He,p as Ue,r as We,s as Ge,t as Ke,u as qe,w as Je}from"./dialog-XDohhbSr.js";import{$ as Ye,A as Xe,B as Ze,Bt as Qe,Ct as $e,D as et,Dt as tt,E as nt,Et as rt,Ft as it,G as at,H as ot,Ht as st,I as ct,It as lt,J as ut,K as dt,L as U,Lt as ft,M as pt,N as mt,Nt as ht,P as gt,Pt as _t,Q as vt,Rt as yt,S as bt,St as xt,T as St,Tt as W,U as Ct,V as wt,Vt as Tt,W as Et,Y as Dt,Z as Ot,_ as kt,a as At,at as jt,b as Mt,bt as Nt,c as Pt,ct as Ft,d as It,et as Lt,f as Rt,g as zt,gt as Bt,h as Vt,ht as Ht,i as Ut,j as Wt,jt as Gt,k as Kt,kt as qt,l as Jt,lt as Yt,mt as Xt,n as Zt,nt as Qt,o as $t,ot as en,p as tn,pt as nn,q as rn,r as an,s as on,st as sn,t as cn,tt as ln,u as un,ut as dn,v as fn,vt as pn,w as mn,x as hn,xt as gn,y as _n,z as vn,zt as yn}from"./dist-1RA1Ivz5.js";import{a as bn,c as xn,i as Sn,n as Cn,o as wn,r as Tn,s as En,t as Dn}from"./dist-B90Tbt-G.js";import{i as On,n as kn,r as An,t as jn}from"./dist-BJa-wTjR.js";var Mn=c(`circle-alert`,[[`circle`,{cx:`12`,cy:`12`,r:`10`,key:`1mglay`}],[`line`,{x1:`12`,x2:`12`,y1:`8`,y2:`12`,key:`1pkeuh`}],[`line`,{x1:`12`,x2:`12.01`,y1:`16`,y2:`16`,key:`4dfq90`}]]),Nn=c(`code-xml`,[[`path`,{d:`m18 16 4-4-4-4`,key:`1inbqp`}],[`path`,{d:`m6 8-4 4 4 4`,key:`15zrgr`}],[`path`,{d:`m14.5 4-5 16`,key:`e7oirm`}]]),Pn=c(`external-link`,[[`path`,{d:`M15 3h6v6`,key:`1q9fwt`}],[`path`,{d:`M10 14 21 3`,key:`gplh6r`}],[`path`,{d:`M18 13v6a2 2 0 0 1-2 2H5a2 2 0 0 1-2-2V8a2 2 0 0 1 2-2h6`,key:`a6xqqp`}]]),Fn=c(`file-plus-corner`,[[`path`,{d:`M11.35 22H6a2 2 0 0 1-2-2V4a2 2 0 0 1 2-2h8a2.4 2.4 0 0 1 1.706.706l3.588 3.588A2.4 2.4 0 0 1 20 8v5.35`,key:`17jvcc`}],[`path`,{d:`M14 2v5a1 1 0 0 0 1 1h5`,key:`wfsgrz`}],[`path`,{d:`M14 19h6`,key:`bvotb8`}],[`path`,{d:`M17 16v6`,key:`18yu1i`}]]),In=c(`file`,[[`path`,{d:`M6 22a2 2 0 0 1-2-2V4a2 2 0 0 1 2-2h8a2.4 2.4 0 0 1 1.704.706l3.588 3.588A2.4 2.4 0 0 1 20 8v12a2 2 0 0 1-2 2z`,key:`1oefj6`}],[`path`,{d:`M14 2v5a1 1 0 0 0 1 1h5`,key:`wfsgrz`}]]),Ln=c(`folder-open`,[[`path`,{d:`m6 14 1.5-2.9A2 2 0 0 1 9.24 10H20a2 2 0 0 1 1.94 2.5l-1.54 6a2 2 0 0 1-1.95 1.5H4a2 2 0 0 1-2-2V5a2 2 0 0 1 2-2h3.9a2 2 0 0 1 1.69.9l.81 1.2a2 2 0 0 0 1.67.9H18a2 2 0 0 1 2 2v2`,key:`usdka0`}]]),Rn=c(`heading-1`,[[`path`,{d:`M4 12h8`,key:`17cfdx`}],[`path`,{d:`M4 18V6`,key:`1rz3zl`}],[`path`,{d:`M12 18V6`,key:`zqpxq5`}],[`path`,{d:`m17 12 3-2v8`,key:`1hhhft`}]]),zn=c(`heading-2`,[[`path`,{d:`M4 12h8`,key:`17cfdx`}],[`path`,{d:`M4 18V6`,key:`1rz3zl`}],[`path`,{d:`M12 18V6`,key:`zqpxq5`}],[`path`,{d:`M21 18h-4c0-4 4-3 4-6 0-1.5-2-2.5-4-1`,key:`9jr5yi`}]]),Bn=c(`heading-3`,[[`path`,{d:`M4 12h8`,key:`17cfdx`}],[`path`,{d:`M4 18V6`,key:`1rz3zl`}],[`path`,{d:`M12 18V6`,key:`zqpxq5`}],[`path`,{d:`M17.5 10.5c1.7-1 3.5 0 3.5 1.5a2 2 0 0 1-2 2`,key:`68ncm8`}],[`path`,{d:`M17 17.5c2 1.5 4 .3 4-1.5a2 2 0 0 0-2-2`,key:`1ejuhz`}]]),Vn=c(`image`,[[`rect`,{width:`18`,height:`18`,x:`3`,y:`3`,rx:`2`,ry:`2`,key:`1m3agn`}],[`circle`,{cx:`9`,cy:`9`,r:`2`,key:`af1f0g`}],[`path`,{d:`m21 15-3.086-3.086a2 2 0 0 0-2.828 0L6 21`,key:`1xmnt7`}]]),Hn=c(`list-ordered`,[[`path`,{d:`M11 5h10`,key:`1cz7ny`}],[`path`,{d:`M11 12h10`,key:`1438ji`}],[`path`,{d:`M11 19h10`,key:`11t30w`}],[`path`,{d:`M4 4h1v5`,key:`10yrso`}],[`path`,{d:`M4 9h2`,key:`r1h2o0`}],[`path`,{d:`M6.5 20H3.4c0-1 2.6-1.925 2.6-3.5a1.5 1.5 0 0 0-2.6-1.02`,key:`xtkcd5`}]]),Un=c(`list-todo`,[[`path`,{d:`M13 5h8`,key:`a7qcls`}],[`path`,{d:`M13 12h8`,key:`h98zly`}],[`path`,{d:`M13 19h8`,key:`c3s6r1`}],[`path`,{d:`m3 17 2 2 4-4`,key:`1jhpwq`}],[`rect`,{x:`3`,y:`4`,width:`6`,height:`6`,rx:`1`,key:`cif1o7`}]]),Wn=c(`list`,[[`path`,{d:`M3 5h.01`,key:`18ugdj`}],[`path`,{d:`M3 12h.01`,key:`nlz23k`}],[`path`,{d:`M3 19h.01`,key:`noohij`}],[`path`,{d:`M8 5h13`,key:`1pao27`}],[`path`,{d:`M8 12h13`,key:`1za7za`}],[`path`,{d:`M8 19h13`,key:`m83p4d`}]]),Gn=c(`loader-circle`,[[`path`,{d:`M21 12a9 9 0 1 1-6.219-8.56`,key:`13zald`}]]),Kn=c(`minus`,[[`path`,{d:`M5 12h14`,key:`1ays0h`}]]),qn=c(`pencil`,[[`path`,{d:`M21.174 6.812a1 1 0 0 0-3.986-3.987L3.842 16.174a2 2 0 0 0-.5.83l-1.321 4.352a.5.5 0 0 0 .623.622l4.353-1.32a2 2 0 0 0 .83-.497z`,key:`1a8usu`}],[`path`,{d:`m15 5 4 4`,key:`1mk7zo`}]]),Jn=c(`quote`,[[`path`,{d:`M16 3a2 2 0 0 0-2 2v6a2 2 0 0 0 2 2 1 1 0 0 1 1 1v1a2 2 0 0 1-2 2 1 1 0 0 0-1 1v2a1 1 0 0 0 1 1 6 6 0 0 0 6-6V5a2 2 0 0 0-2-2z`,key:`rib7q0`}],[`path`,{d:`M5 3a2 2 0 0 0-2 2v6a2 2 0 0 0 2 2 1 1 0 0 1 1 1v1a2 2 0 0 1-2 2 1 1 0 0 0-1 1v2a1 1 0 0 0 1 1 6 6 0 0 0 6-6V5a2 2 0 0 0-2-2z`,key:`1ymkrd`}]]),Yn=c(`table-2`,[[`path`,{d:`M9 3H5a2 2 0 0 0-2 2v4m6-6h10a2 2 0 0 1 2 2v4M9 3v18m0 0h10a2 2 0 0 0 2-2V9M9 21H5a2 2 0 0 1-2-2V9m0 0h18`,key:`gugj83`}]]),Xn=c(`trash-2`,[[`path`,{d:`M10 11v6`,key:`nco0om`}],[`path`,{d:`M14 11v6`,key:`outv1u`}],[`path`,{d:`M19 6v14a2 2 0 0 1-2 2H7a2 2 0 0 1-2-2V6`,key:`miytrc`}],[`path`,{d:`M3 6h18`,key:`d0wm0j`}],[`path`,{d:`M8 6V4a2 2 0 0 1 2-2h4a2 2 0 0 1 2 2v2`,key:`e791ji`}]]),Zn=t((e=>{var t=i();function n(e,t){return e===t&&(e!==0||1/e==1/t)||e!==e&&t!==t}var r=typeof Object.is==`function`?Object.is:n,a=t.useState,o=t.useEffect,s=t.useLayoutEffect,c=t.useDebugValue;function l(e,t){var n=t(),r=a({inst:{value:n,getSnapshot:t}}),i=r[0].inst,l=r[1];return s(function(){i.value=n,i.getSnapshot=t,u(i)&&l({inst:i})},[e,n,t]),o(function(){return u(i)&&l({inst:i}),e(function(){u(i)&&l({inst:i})})},[e]),c(n),n}function u(e){var t=e.getSnapshot;e=e.value;try{var n=t();return!r(e,n)}catch{return!0}}function d(e,t){return t()}var f=typeof window>`u`||window.document===void 0||window.document.createElement===void 0?d:l;e.useSyncExternalStore=t.useSyncExternalStore===void 0?f:t.useSyncExternalStore})),Qn=t(((e,t)=>{t.exports=Zn()})),$n=`modulepreload`,er=function(e){return`/`+e},tr={},nr=function(e,t,n){let r=Promise.resolve();if(t&&t.length>0){let e=document.getElementsByTagName(`link`),i=document.querySelector(`meta[property=csp-nonce]`),a=i?.nonce||i?.getAttribute(`nonce`);function o(e){return Promise.all(e.map(e=>Promise.resolve(e).then(e=>({status:`fulfilled`,value:e}),e=>({status:`rejected`,reason:e}))))}r=o(t.map(t=>{if(t=er(t,n),t in tr)return;tr[t]=!0;let r=t.endsWith(`.css`),i=r?`[rel="stylesheet"]`:``;if(n)for(let n=e.length-1;n>=0;n--){let i=e[n];if(i.href===t&&(!r||i.rel===`stylesheet`))return}else if(document.querySelector(`link[href="${t}"]${i}`))return;let o=document.createElement(`link`);if(o.rel=r?`stylesheet`:$n,r||(o.as=`script`),o.crossOrigin=``,o.href=t,a&&o.setAttribute(`nonce`,a),document.head.appendChild(o),r)return new Promise((e,n)=>{o.addEventListener(`load`,e),o.addEventListener(`error`,()=>n(Error(`Unable to preload CSS for ${t}`)))})}))}function i(e){let t=new Event(`vite:preloadError`,{cancelable:!0});if(t.payload=e,window.dispatchEvent(t),!t.defaultPrevented)throw e}return r.then(t=>{for(let e of t||[])e.status===`rejected`&&i(e.reason);return e().catch(i)})},G=n(i(),1),rr=r();function ir(e){let t=e.split(`/`);return t.length<2?`ok`:`${t[0]}/${t[1]}`}function ar(e){if(!e)return;let t=Object.entries(e);if(t.length!==0)return t.map(([e,t])=>{if(t==null)return[e,String(t)];if(typeof t==`string`)return[e,t];if(typeof t==`number`||typeof t==`boolean`)return[e,String(t)];try{return[e,JSON.stringify(t)]}catch{return[e,`[unserializable]`]}})}function K(e,t,n){if(typeof performance>`u`||!performance.measure)return;let r=ir(e),i=ar(t),a={devtools:{dataType:`track-entry`,track:r,...i?{properties:i}:{},...n?.tooltipText?{tooltipText:n.tooltipText}:{}}},o=performance.now(),s=n?.startTime??o,c=n?.duration??Math.max(0,o-s);try{performance.measure(e,{start:s,duration:c,detail:a})}catch{}({...t?{properties:t}:{}})}var q=s();function or(e){let t=(0,rr.c)(3),{name:n,children:r}=e,i;return t[0]!==r||t[1]!==n?(i=(0,q.jsx)(G.Profiler,{id:n,onRender:sr,children:r}),t[0]=r,t[1]=n,t[2]=i):i=t[2],i}var sr=(e,t,n,r,i,a)=>{K(`ok/render/${e}`,{phase:t,actualDuration:Math.round(n*1e3)/1e3,baseDuration:Math.round(r*1e3)/1e3},{startTime:i,duration:Math.max(0,a-i)})},cr=n(e(),1),lr=Qn(),{getOwnPropertyNames:ur,getOwnPropertySymbols:dr}=Object,{hasOwnProperty:fr}=Object.prototype;function pr(e,t){return function(n,r,i){return e(n,r,i)&&t(n,r,i)}}function mr(e){return function(t,n,r){if(!t||!n||typeof t!=`object`||typeof n!=`object`)return e(t,n,r);let{cache:i}=r,a=i.get(t),o=i.get(n);if(a&&o)return a===n&&o===t;i.set(t,n),i.set(n,t);let s=e(t,n,r);return i.delete(t),i.delete(n),s}}function hr(e){return e?.[Symbol.toStringTag]}function gr(e){return ur(e).concat(dr(e))}var _r=Object.hasOwn||((e,t)=>fr.call(e,t));function vr(e,t){return e===t||!e&&!t&&e!==e&&t!==t}var yr=`__v`,br=`__o`,xr=`_owner`,{getOwnPropertyDescriptor:Sr,keys:Cr}=Object;function wr(e,t){return e.byteLength===t.byteLength&&Lr(new Uint8Array(e),new Uint8Array(t))}function Tr(e,t,n){let r=e.length;if(t.length!==r)return!1;for(;r-- >0;)if(!n.equals(e[r],t[r],r,r,e,t,n))return!1;return!0}function Er(e,t){return e.byteLength===t.byteLength&&Lr(new Uint8Array(e.buffer,e.byteOffset,e.byteLength),new Uint8Array(t.buffer,t.byteOffset,t.byteLength))}function Dr(e,t){return vr(e.getTime(),t.getTime())}function Or(e,t){return e.name===t.name&&e.message===t.message&&e.cause===t.cause&&e.stack===t.stack}function kr(e,t){return e===t}function Ar(e,t,n){let r=e.size;if(r!==t.size)return!1;if(!r)return!0;let i=Array(r),a=e.entries(),o,s,c=0;for(;(o=a.next())&&!o.done;){let r=t.entries(),a=!1,l=0;for(;(s=r.next())&&!s.done;){if(i[l]){l++;continue}let r=o.value,u=s.value;if(n.equals(r[0],u[0],c,l,e,t,n)&&n.equals(r[1],u[1],r[0],u[0],e,t,n)){a=i[l]=!0;break}l++}if(!a)return!1;c++}return!0}var jr=vr;function Mr(e,t,n){let r=Cr(e),i=r.length;if(Cr(t).length!==i)return!1;for(;i-- >0;)if(!zr(e,t,n,r[i]))return!1;return!0}function Nr(e,t,n){let r=gr(e),i=r.length;if(gr(t).length!==i)return!1;let a,o,s;for(;i-- >0;)if(a=r[i],!zr(e,t,n,a)||(o=Sr(e,a),s=Sr(t,a),(o||s)&&(!o||!s||o.configurable!==s.configurable||o.enumerable!==s.enumerable||o.writable!==s.writable)))return!1;return!0}function Pr(e,t){return vr(e.valueOf(),t.valueOf())}function Fr(e,t){return e.source===t.source&&e.flags===t.flags}function Ir(e,t,n){let r=e.size;if(r!==t.size)return!1;if(!r)return!0;let i=Array(r),a=e.values(),o,s;for(;(o=a.next())&&!o.done;){let r=t.values(),a=!1,c=0;for(;(s=r.next())&&!s.done;){if(!i[c]&&n.equals(o.value,s.value,o.value,s.value,e,t,n)){a=i[c]=!0;break}c++}if(!a)return!1}return!0}function Lr(e,t){let n=e.byteLength;if(t.byteLength!==n||e.byteOffset!==t.byteOffset)return!1;for(;n-- >0;)if(e[n]!==t[n])return!1;return!0}function Rr(e,t){return e.hostname===t.hostname&&e.pathname===t.pathname&&e.protocol===t.protocol&&e.port===t.port&&e.hash===t.hash&&e.username===t.username&&e.password===t.password}function zr(e,t,n,r){return(r===xr||r===br||r===yr)&&(e.$$typeof||t.$$typeof)?!0:_r(t,r)&&n.equals(e[r],t[r],r,r,e,t,n)}var Br=`[object ArrayBuffer]`,Vr=`[object Arguments]`,Hr=`[object Boolean]`,Ur=`[object DataView]`,Wr=`[object Date]`,Gr=`[object Error]`,Kr=`[object Map]`,qr=`[object Number]`,Jr=`[object Object]`,Yr=`[object RegExp]`,Xr=`[object Set]`,Zr=`[object String]`,Qr={"[object Int8Array]":!0,"[object Uint8Array]":!0,"[object Uint8ClampedArray]":!0,"[object Int16Array]":!0,"[object Uint16Array]":!0,"[object Int32Array]":!0,"[object Uint32Array]":!0,"[object Float16Array]":!0,"[object Float32Array]":!0,"[object Float64Array]":!0,"[object BigInt64Array]":!0,"[object BigUint64Array]":!0},$r=`[object URL]`,ei=Object.prototype.toString;function ti({areArrayBuffersEqual:e,areArraysEqual:t,areDataViewsEqual:n,areDatesEqual:r,areErrorsEqual:i,areFunctionsEqual:a,areMapsEqual:o,areNumbersEqual:s,areObjectsEqual:c,arePrimitiveWrappersEqual:l,areRegExpsEqual:u,areSetsEqual:d,areTypedArraysEqual:f,areUrlsEqual:p,unknownTagComparators:m}){return function(h,g,_){if(h===g)return!0;if(h==null||g==null)return!1;let v=typeof h;if(v!==typeof g)return!1;if(v!==`object`)return v===`number`?s(h,g,_):v===`function`?a(h,g,_):!1;let y=h.constructor;if(y!==g.constructor)return!1;if(y===Object)return c(h,g,_);if(Array.isArray(h))return t(h,g,_);if(y===Date)return r(h,g,_);if(y===RegExp)return u(h,g,_);if(y===Map)return o(h,g,_);if(y===Set)return d(h,g,_);let b=ei.call(h);if(b===Wr)return r(h,g,_);if(b===Yr)return u(h,g,_);if(b===Kr)return o(h,g,_);if(b===Xr)return d(h,g,_);if(b===Jr)return typeof h.then!=`function`&&typeof g.then!=`function`&&c(h,g,_);if(b===$r)return p(h,g,_);if(b===Gr)return i(h,g,_);if(b===Vr)return c(h,g,_);if(Qr[b])return f(h,g,_);if(b===Br)return e(h,g,_);if(b===Ur)return n(h,g,_);if(b===Hr||b===qr||b===Zr)return l(h,g,_);if(m){let e=m[b];if(!e){let t=hr(h);t&&(e=m[t])}if(e)return e(h,g,_)}return!1}}function ni({circular:e,createCustomConfig:t,strict:n}){let r={areArrayBuffersEqual:wr,areArraysEqual:n?Nr:Tr,areDataViewsEqual:Er,areDatesEqual:Dr,areErrorsEqual:Or,areFunctionsEqual:kr,areMapsEqual:n?pr(Ar,Nr):Ar,areNumbersEqual:jr,areObjectsEqual:n?Nr:Mr,arePrimitiveWrappersEqual:Pr,areRegExpsEqual:Fr,areSetsEqual:n?pr(Ir,Nr):Ir,areTypedArraysEqual:n?pr(Lr,Nr):Lr,areUrlsEqual:Rr,unknownTagComparators:void 0};if(t&&(r=Object.assign({},r,t(r))),e){let e=mr(r.areArraysEqual),t=mr(r.areMapsEqual),n=mr(r.areObjectsEqual),i=mr(r.areSetsEqual);r=Object.assign({},r,{areArraysEqual:e,areMapsEqual:t,areObjectsEqual:n,areSetsEqual:i})}return r}function ri(e){return function(t,n,r,i,a,o,s){return e(t,n,s)}}function ii({circular:e,comparator:t,createState:n,equals:r,strict:i}){if(n)return function(a,o){let{cache:s=e?new WeakMap:void 0,meta:c}=n();return t(a,o,{cache:s,equals:r,meta:c,strict:i})};if(e)return function(e,n){return t(e,n,{cache:new WeakMap,equals:r,meta:void 0,strict:i})};let a={cache:void 0,equals:r,meta:void 0,strict:i};return function(e,n){return t(e,n,a)}}var ai=oi();oi({strict:!0}),oi({circular:!0}),oi({circular:!0,strict:!0}),oi({createInternalComparator:()=>vr}),oi({strict:!0,createInternalComparator:()=>vr}),oi({circular:!0,createInternalComparator:()=>vr}),oi({circular:!0,createInternalComparator:()=>vr,strict:!0});function oi(e={}){let{circular:t=!1,createInternalComparator:n,createState:r,strict:i=!1}=e,a=ti(ni(e));return ii({circular:t,comparator:a,createState:r,equals:n?n(a):ri(a),strict:i})}var si=t((e=>{var t=i(),n=Qn();function r(e,t){return e===t&&(e!==0||1/e==1/t)||e!==e&&t!==t}var a=typeof Object.is==`function`?Object.is:r,o=n.useSyncExternalStore,s=t.useRef,c=t.useEffect,l=t.useMemo,u=t.useDebugValue;e.useSyncExternalStoreWithSelector=function(e,t,n,r,i){var d=s(null);if(d.current===null){var f={hasValue:!1,value:null};d.current=f}else f=d.current;d=l(function(){function e(e){if(!o){if(o=!0,s=e,e=r(e),i!==void 0&&f.hasValue){var t=f.value;if(i(t,e))return c=t}return c=e}if(t=c,a(s,e))return t;var n=r(e);return i!==void 0&&i(t,n)?(s=e,t):(s=e,c=n)}var o=!1,s,c,l=n===void 0?null:n;return[function(){return e(t())},l===null?void 0:function(){return e(l())}]},[t,n,r,i]);var p=o(e,d[0],d[1]);return c(function(){f.hasValue=!0,f.value=p},[p]),u(p),p}})),ci=t(((e,t)=>{t.exports=si()}))(),li=(...e)=>t=>{e.forEach(e=>{typeof e==`function`?e(t):e&&(e.current=t)})},ui=({contentComponent:e})=>{let t=(0,lr.useSyncExternalStore)(e.subscribe,e.getSnapshot,e.getServerSnapshot);return(0,q.jsx)(q.Fragment,{children:Object.values(t)})};function di(){let e=new Set,t={};return{subscribe(t){return e.add(t),()=>{e.delete(t)}},getSnapshot(){return t},getServerSnapshot(){return t},setRenderer(n,r){t={...t,[n]:cr.createPortal(r.reactElement,r.element,n)},e.forEach(e=>e())},removeRenderer(n){let r={...t};delete r[n],t=r,e.forEach(e=>e())}}}var fi=class extends G.Component{constructor(e){super(e),this.editorContentRef=G.createRef()}componentDidMount(){this.init()}componentDidUpdate(){this.init()}init(){let e=this.props.editor;if(e&&!e.isDestroyed&&e.view.dom?.parentNode){if(e.contentComponent)return;let t=this.editorContentRef.current;t.append(...e.view.dom.parentNode.childNodes),e.setOptions({element:t}),e.contentComponent=di(),e.createNodeViews(),e.isEditorContentInitialized=!0,this.forceUpdate()}}componentWillUnmount(){let e=this.props.editor;if(e){e.isEditorContentInitialized=!1,e.isDestroyed||e.view.setProps({nodeViews:{}}),e.contentComponent=null;try{if(!e.view.dom?.parentNode)return;let t=document.createElement(`div`);t.append(...e.view.dom.parentNode.childNodes),e.setOptions({element:t})}catch{}}}render(){let{editor:e,innerRef:t,...n}=this.props;return(0,q.jsxs)(q.Fragment,{children:[(0,q.jsx)(`div`,{ref:li(t,this.editorContentRef),...n}),e?.contentComponent&&(0,q.jsx)(ui,{contentComponent:e.contentComponent})]})}},pi=(0,G.forwardRef)((e,t)=>{let n=G.useMemo(()=>Math.floor(Math.random()*4294967295).toString(),[e.editor]);return G.createElement(fi,{key:n,innerRef:t,...e})}),mi=G.memo(pi),hi=typeof window<`u`?G.useLayoutEffect:G.useEffect,gi=class{constructor(e){this.transactionNumber=0,this.lastTransactionNumber=0,this.subscribers=new Set,this.editor=e,this.lastSnapshot={editor:e,transactionNumber:0},this.getSnapshot=this.getSnapshot.bind(this),this.getServerSnapshot=this.getServerSnapshot.bind(this),this.watch=this.watch.bind(this),this.subscribe=this.subscribe.bind(this)}getSnapshot(){return this.transactionNumber===this.lastTransactionNumber?this.lastSnapshot:(this.lastTransactionNumber=this.transactionNumber,this.lastSnapshot={editor:this.editor,transactionNumber:this.transactionNumber},this.lastSnapshot)}getServerSnapshot(){return{editor:null,transactionNumber:0}}subscribe(e){return this.subscribers.add(e),()=>{this.subscribers.delete(e)}}watch(e){if(this.editor=e,this.editor){let e=()=>{this.transactionNumber+=1,this.subscribers.forEach(e=>e())},t=this.editor;return t.on(`transaction`,e),()=>{t.off(`transaction`,e)}}}};function _i(e){let[t]=(0,G.useState)(()=>new gi(e.editor)),n=(0,ci.useSyncExternalStoreWithSelector)(t.subscribe,t.getSnapshot,t.getServerSnapshot,e.selector,e.equalityFn??ai);return hi(()=>t.watch(e.editor),[e.editor,t]),(0,G.useDebugValue)(n),n}typeof window>`u`||typeof window<`u`&&window.next;var vi=(0,G.createContext)({editor:null});vi.Consumer;var yi=()=>(0,G.useContext)(vi),bi=(0,G.createContext)({onDragStart:()=>{},nodeViewContentChildren:void 0,nodeViewContentRef:()=>{}}),xi=()=>(0,G.useContext)(bi),Si=G.forwardRef((e,t)=>{let{onDragStart:n}=xi();return(0,q.jsx)(e.as||`div`,{...e,ref:t,"data-node-view-wrapper":``,onDragStart:n,style:{whiteSpace:`normal`,...e.style}})});function Ci(e){return!!(typeof e==`function`&&e.prototype&&e.prototype.isReactComponent)}function wi(e){return!!(typeof e==`object`&&e.$$typeof&&(e.$$typeof.toString()===`Symbol(react.forward_ref)`||e.$$typeof.description===`react.forward_ref`))}function Ti(e){return!!(typeof e==`object`&&e.$$typeof&&(e.$$typeof.toString()===`Symbol(react.memo)`||e.$$typeof.description===`react.memo`))}function Ei(e){if(Ci(e)||wi(e))return!0;if(Ti(e)){let t=e.type;if(t)return Ci(t)||wi(t)}return!1}function Di(){try{if(G.version)return parseInt(G.version.split(`.`)[0],10)>=19}catch{}return!1}var Oi=class{constructor(e,{editor:t,props:n={},as:r=`div`,className:i=``}){this.ref=null,this.destroyed=!1,this.id=Math.floor(Math.random()*4294967295).toString(),this.component=e,this.editor=t,this.props=n,this.element=document.createElement(r),this.element.classList.add(`react-renderer`),i&&this.element.classList.add(...i.split(` `)),this.editor.isEditorContentInitialized?(0,cr.flushSync)(()=>{this.render()}):queueMicrotask(()=>{this.destroyed||this.render()})}render(){var e;if(this.destroyed)return;let t=this.component,n=this.props,r=this.editor,i=Di(),a=Ei(t),o={...n};o.ref&&!(i||a)&&delete o.ref,!o.ref&&(i||a)&&(o.ref=e=>{this.ref=e}),this.reactElement=(0,q.jsx)(t,{...o}),(e=r?.contentComponent)==null||e.setRenderer(this.id,this)}updateProps(e={}){this.destroyed||(this.props={...this.props,...e},this.render())}destroy(){var e;this.destroyed=!0,(e=this.editor?.contentComponent)==null||e.removeRenderer(this.id);try{this.element&&this.element.parentNode&&this.element.parentNode.removeChild(this.element)}catch{}}updateAttributes(e){Object.keys(e).forEach(t=>{this.element.setAttribute(t,e[t])})}};G.createContext({markViewContentRef:()=>{}});var ki=class extends ce{constructor(e,t,n){if(super(e,t,n),this.selectionRafId=null,this.positionCheckCallback=null,this.cachedExtensionWithSyncedStorage=null,!this.node.isLeaf){this.options.contentDOMElementTag?this.contentDOMElement=document.createElement(this.options.contentDOMElementTag):this.contentDOMElement=document.createElement(this.node.isInline?`span`:`div`),this.contentDOMElement.dataset.nodeViewContentReact=``,this.contentDOMElement.dataset.nodeViewWrapper=``,this.contentDOMElement.style.whiteSpace=`inherit`;let e=this.dom.querySelector(`[data-node-view-content]`);if(!e)return;e.appendChild(this.contentDOMElement)}}get extensionWithSyncedStorage(){if(!this.cachedExtensionWithSyncedStorage){let e=this.editor,t=this.extension;this.cachedExtensionWithSyncedStorage=new Proxy(t,{get(n,r,i){return r===`storage`?e.storage[t.name]??{}:Reflect.get(n,r,i)}})}return this.cachedExtensionWithSyncedStorage}mount(){let e={editor:this.editor,node:this.node,decorations:this.decorations,innerDecorations:this.innerDecorations,view:this.view,selected:!1,extension:this.extensionWithSyncedStorage,HTMLAttributes:this.HTMLAttributes,getPos:()=>this.getPos(),updateAttributes:(e={})=>this.updateAttributes(e),deleteNode:()=>this.deleteNode(),ref:(0,G.createRef)()};if(!this.component.displayName){let e=e=>e.charAt(0).toUpperCase()+e.substring(1);this.component.displayName=e(this.extension.name)}let t={onDragStart:this.onDragStart.bind(this),nodeViewContentRef:e=>{e&&this.contentDOMElement&&e.firstChild!==this.contentDOMElement&&(e.hasAttribute(`data-node-view-wrapper`)&&e.removeAttribute(`data-node-view-wrapper`),e.appendChild(this.contentDOMElement))}},n=this.component,r=(0,G.memo)(e=>(0,q.jsx)(bi.Provider,{value:t,children:(0,G.createElement)(n,e)}));r.displayName=`ReactNodeView`;let i=this.node.isInline?`span`:`div`;this.options.as&&(i=this.options.as);let{className:a=``}=this.options;this.handleSelectionUpdate=this.handleSelectionUpdate.bind(this),this.renderer=new Oi(r,{editor:this.editor,props:e,as:i,className:`node-${this.node.type.name} ${a}`.trim()}),this.editor.on(`selectionUpdate`,this.handleSelectionUpdate),this.updateElementAttributes(),this.currentPos=this.getPos(),this.positionCheckCallback=()=>{let e=this.getPos();typeof e!=`number`||e===this.currentPos||(this.currentPos=e,this.renderer.updateProps({getPos:()=>this.getPos()}),typeof this.options.attrs==`function`&&this.updateElementAttributes())},je(this.editor,this.positionCheckCallback)}get dom(){if(this.renderer.element.firstElementChild&&!this.renderer.element.firstElementChild?.hasAttribute(`data-node-view-wrapper`))throw Error(`Please use the NodeViewWrapper component for your node view.`);return this.renderer.element}get contentDOM(){return this.node.isLeaf?null:this.contentDOMElement}handleSelectionUpdate(){this.selectionRafId&&=(cancelAnimationFrame(this.selectionRafId),null),this.selectionRafId=requestAnimationFrame(()=>{this.selectionRafId=null;let{from:e,to:t}=this.editor.state.selection,n=this.currentPos;if(typeof n==`number`)if(e<=n&&t>=n+this.node.nodeSize){if(this.renderer.props.selected)return;this.selectNode()}else{if(!this.renderer.props.selected)return;this.deselectNode()}})}update(e,t,n){let r=e=>{this.renderer.updateProps(e),typeof this.options.attrs==`function`&&this.updateElementAttributes()};if(e.type!==this.node.type)return!1;if(typeof this.options.update==`function`){let i=this.node,a=this.decorations,o=this.innerDecorations;return this.node=e,this.decorations=t,this.innerDecorations=n,this.currentPos=this.getPos(),this.options.update({oldNode:i,oldDecorations:a,newNode:e,newDecorations:t,oldInnerDecorations:o,innerDecorations:n,updateProps:()=>r({node:e,decorations:t,innerDecorations:n,extension:this.extensionWithSyncedStorage})})}let i=this.getPos();return e===this.node&&this.decorations===t&&this.innerDecorations===n?i===this.currentPos?!0:(this.currentPos=i,r({node:e,decorations:t,innerDecorations:n,extension:this.extensionWithSyncedStorage,getPos:()=>this.getPos()}),!0):(this.node=e,this.decorations=t,this.innerDecorations=n,this.currentPos=i,r({node:e,decorations:t,innerDecorations:n,extension:this.extensionWithSyncedStorage}),!0)}selectNode(){this.renderer.updateProps({selected:!0}),this.renderer.element.classList.add(`ProseMirror-selectednode`)}deselectNode(){this.renderer.updateProps({selected:!1}),this.renderer.element.classList.remove(`ProseMirror-selectednode`)}destroy(){this.renderer.destroy(),this.editor.off(`selectionUpdate`,this.handleSelectionUpdate),this.positionCheckCallback&&=(Ce(this.editor,this.positionCheckCallback),null),this.contentDOMElement=null,this.selectionRafId&&=(cancelAnimationFrame(this.selectionRafId),null)}updateElementAttributes(){if(this.options.attrs){let e={};if(typeof this.options.attrs==`function`){let t=this.editor.extensionManager.attributes,n=fe(this.node,t);e=this.options.attrs({node:this.node,HTMLAttributes:n})}else e=this.options.attrs;this.renderer.updateAttributes(e)}}};function Ai(e,t){return n=>n.editor.contentComponent?new ki(e,n,t):{}}var ji=(0,G.createContext)({get editor(){throw Error(`useTiptap must be used within a <Tiptap> provider`)}});ji.displayName=`TiptapContext`;var Mi=()=>(0,G.useContext)(ji);function Ni({editor:e,instance:t,children:n}){let r=e??t;if(!r)throw Error("Tiptap: An editor instance is required. Pass a non-null `editor` prop.");let i=(0,G.useMemo)(()=>({editor:r}),[r]),a=(0,G.useMemo)(()=>({editor:r}),[r]);return(0,q.jsx)(vi.Provider,{value:a,children:(0,q.jsx)(ji.Provider,{value:i,children:n})})}Ni.displayName=`Tiptap`;function Pi({...e}){let{editor:t}=Mi();return(0,q.jsx)(mi,{editor:t,...e})}Pi.displayName=`Tiptap.Content`,Object.assign(Ni,{Content:Pi});var Fi=()=>new Map,Ii=e=>{let t=Fi();return e.forEach((e,n)=>{t.set(n,e)}),t},Li=(e,t,n)=>{let r=e.get(t);return r===void 0&&e.set(t,r=n()),r},Ri=(e,t)=>{let n=[];for(let[r,i]of e)n.push(t(i,r));return n},zi=(e,t)=>{for(let[n,r]of e)if(t(r,n))return!0;return!1},Bi=()=>new Set,Vi=e=>e[e.length-1],Hi=(e,t)=>{for(let n=0;n<t.length;n++)e.push(t[n])},Ui=Array.from,Wi=(e,t)=>{for(let n=0;n<e.length;n++)if(!t(e[n],n,e))return!1;return!0},Gi=(e,t)=>{for(let n=0;n<e.length;n++)if(t(e[n],n,e))return!0;return!1},Ki=(e,t)=>{let n=Array(e);for(let r=0;r<e;r++)n[r]=t(r,n);return n},qi=Array.isArray,Ji=class{constructor(){this._observers=Fi()}on(e,t){return Li(this._observers,e,Bi).add(t),t}once(e,t){let n=(...r)=>{this.off(e,n),t(...r)};this.on(e,n)}off(e,t){let n=this._observers.get(e);n!==void 0&&(n.delete(t),n.size===0&&this._observers.delete(e))}emit(e,t){return Ui((this._observers.get(e)||Fi()).values()).forEach(e=>e(...t))}destroy(){this._observers=Fi()}},Yi=Math.floor,Xi=Math.abs,Zi=(e,t)=>e<t?e:t,Qi=(e,t)=>e>t?e:t;Number.isNaN;var $i=e=>e===0?1/e<0:e<0,ea=1<<17,ta=1<<18,na=1<<19,ra=1<<20,ia=1<<21,aa=1<<22,oa=1<<23,sa=1<<24,ca=1<<25,la=1<<26,ua=1<<27,da=1<<28,fa=1<<29;ea-1,ta-1,na-1,ra-1,ia-1,aa-1,oa-1,sa-1,ca-1,la-1,ua-1,da-1,fa-1;var pa=2**53-1,ma=-(2**53-1),ha=Number.isInteger||(e=>typeof e==`number`&&isFinite(e)&&Yi(e)===e);Number.isNaN,Number.parseInt;var ga=String.fromCharCode;String.fromCodePoint,ga(65535);var _a=e=>e.toLowerCase(),va=/^\s*/g,ya=e=>e.replace(va,``),ba=/([A-Z])/g,xa=(e,t)=>ya(e.replace(ba,e=>`${t}${_a(e)}`)),Sa=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},Ca=typeof TextEncoder<`u`?new TextEncoder:null,wa=Ca?e=>Ca.encode(e):Sa,Ta=typeof TextDecoder>`u`?null:new TextDecoder(`utf-8`,{fatal:!0,ignoreBOM:!0});Ta&&Ta.decode(new Uint8Array).length===1&&(Ta=null);var Ea=(e,t)=>Ki(t,()=>e).join(``),Da=class{constructor(){this.cpos=0,this.cbuf=new Uint8Array(100),this.bufs=[]}},Oa=()=>new Da,ka=e=>{let t=Oa();return e(t),ja(t)},Aa=e=>{let t=e.cpos;for(let n=0;n<e.bufs.length;n++)t+=e.bufs[n].length;return t},ja=e=>{let t=new Uint8Array(Aa(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},Ma=(e,t)=>{let n=e.cbuf.length;n-e.cpos<t&&(e.bufs.push(new Uint8Array(e.cbuf.buffer,0,e.cpos)),e.cbuf=new Uint8Array(Qi(n,t)*2),e.cpos=0)},Na=(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},Pa=Na,J=(e,t)=>{for(;t>127;)Na(e,128|127&t),t=Yi(t/128);Na(e,127&t)},Fa=(e,t)=>{let n=$i(t);for(n&&(t=-t),Na(e,(t>63?128:0)|(n?64:0)|63&t),t=Yi(t/64);t>0;)Na(e,(t>127?128:0)|127&t),t=Yi(t/128)},Ia=new Uint8Array(3e4),La=Ia.length/3,Ra=Ca&&Ca.encodeInto?(e,t)=>{if(t.length<La){let n=Ca.encodeInto(t,Ia).written||0;J(e,n);for(let t=0;t<n;t++)Na(e,Ia[t])}else Ba(e,wa(t))}:(e,t)=>{let n=unescape(encodeURIComponent(t)),r=n.length;J(e,r);for(let t=0;t<r;t++)Na(e,n.codePointAt(t))},za=(e,t)=>{let n=e.cbuf.length,r=e.cpos,i=Zi(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(Qi(n*2,a)),e.cbuf.set(t.subarray(i)),e.cpos=a)},Ba=(e,t)=>{J(e,t.byteLength),za(e,t)},Va=(e,t)=>{Ma(e,t);let n=new DataView(e.cbuf.buffer,e.cpos,t);return e.cpos+=t,n},Ha=(e,t)=>Va(e,4).setFloat32(0,t,!1),Ua=(e,t)=>Va(e,8).setFloat64(0,t,!1),Wa=(e,t)=>Va(e,8).setBigInt64(0,t,!1),Ga=new DataView(new ArrayBuffer(4)),Ka=e=>(Ga.setFloat32(0,e),Ga.getFloat32(0)===e),qa=(e,t)=>{switch(typeof t){case`string`:Na(e,119),Ra(e,t);break;case`number`:ha(t)&&Xi(t)<=2147483647?(Na(e,125),Fa(e,t)):Ka(t)?(Na(e,124),Ha(e,t)):(Na(e,123),Ua(e,t));break;case`bigint`:Na(e,122),Wa(e,t);break;case`object`:if(t===null)Na(e,126);else if(qi(t)){Na(e,117),J(e,t.length);for(let n=0;n<t.length;n++)qa(e,t[n])}else if(t instanceof Uint8Array)Na(e,116),Ba(e,t);else{Na(e,118);let n=Object.keys(t);J(e,n.length);for(let r=0;r<n.length;r++){let i=n[r];Ra(e,i),qa(e,t[i])}}break;case`boolean`:Na(e,t?120:121);break;default:Na(e,127)}},Ja=class extends Da{constructor(e){super(),this.w=e,this.s=null,this.count=0}write(e){this.s===e?this.count++:(this.count>0&&J(this,this.count-1),this.count=1,this.w(this,e),this.s=e)}},Ya=e=>{e.count>0&&(Fa(e.encoder,e.count===1?e.s:-e.s),e.count>1&&J(e.encoder,e.count-2))},Xa=class{constructor(){this.encoder=new Da,this.s=0,this.count=0}write(e){this.s===e?this.count++:(Ya(this),this.count=1,this.s=e)}toUint8Array(){return Ya(this),ja(this.encoder)}},Za=e=>{if(e.count>0){let t=e.diff*2+(e.count===1?0:1);Fa(e.encoder,t),e.count>1&&J(e.encoder,e.count-2)}},Qa=class{constructor(){this.encoder=new Da,this.s=0,this.count=0,this.diff=0}write(e){this.diff===e-this.s?(this.s=e,this.count++):(Za(this),this.count=1,this.diff=e-this.s,this.s=e)}toUint8Array(){return Za(this),ja(this.encoder)}},$a=class{constructor(){this.sarr=[],this.s=``,this.lensE=new Xa}write(e){this.s+=e,this.s.length>19&&(this.sarr.push(this.s),this.s=``),this.lensE.write(e.length)}toUint8Array(){let e=new Da;return this.sarr.push(this.s),this.s=``,Ra(e,this.sarr.join(``)),za(e,this.lensE.toUint8Array()),ja(e)}},eo=e=>Error(e),to=()=>{throw eo(`Method unimplemented`)},no=()=>{throw eo(`Unexpected case`)},ro=eo(`Unexpected end of array`),io=eo(`Integer out of Range`),ao=class{constructor(e){this.arr=e,this.pos=0}},oo=e=>new ao(e),so=e=>e.pos!==e.arr.length,co=(e,t)=>{let n=new Uint8Array(e.arr.buffer,e.pos+e.arr.byteOffset,t);return e.pos+=t,n},lo=e=>co(e,Y(e)),uo=e=>e.arr[e.pos++],Y=e=>{let t=0,n=1,r=e.arr.length;for(;e.pos<r;){let r=e.arr[e.pos++];if(t+=(r&127)*n,n*=128,r<128)return t;if(t>pa)throw io}throw ro},fo=e=>{let t=e.arr[e.pos++],n=t&63,r=64,i=(t&64)>0?-1:1;if(!(t&128))return i*n;let a=e.arr.length;for(;e.pos<a;){if(t=e.arr[e.pos++],n+=(t&127)*r,r*=128,t<128)return i*n;if(n>pa)throw io}throw ro},po=Ta?e=>Ta.decode(lo(e)):e=>{let t=Y(e);if(t===0)return``;{let n=String.fromCodePoint(uo(e));if(--t<100)for(;t--;)n+=String.fromCodePoint(uo(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))}},mo=(e,t)=>{let n=new DataView(e.arr.buffer,e.arr.byteOffset+e.pos,t);return e.pos+=t,n},ho=[e=>void 0,e=>null,fo,e=>mo(e,4).getFloat32(0,!1),e=>mo(e,8).getFloat64(0,!1),e=>mo(e,8).getBigInt64(0,!1),e=>!1,e=>!0,po,e=>{let t=Y(e),n={};for(let r=0;r<t;r++){let t=po(e);n[t]=go(e)}return n},e=>{let t=Y(e),n=[];for(let r=0;r<t;r++)n.push(go(e));return n},lo],go=e=>ho[127-uo(e)](e),_o=class extends ao{constructor(e,t){super(e),this.reader=t,this.s=null,this.count=0}read(){return this.count===0&&(this.s=this.reader(this),so(this)?this.count=Y(this)+1:this.count=-1),this.count--,this.s}},vo=class extends ao{constructor(e){super(e),this.s=0,this.count=0}read(){if(this.count===0){this.s=fo(this);let e=$i(this.s);this.count=1,e&&(this.s=-this.s,this.count=Y(this)+2)}return this.count--,this.s}},yo=class extends ao{constructor(e){super(e),this.s=0,this.count=0,this.diff=0}read(){if(this.count===0){let e=fo(this),t=e&1;this.diff=Yi(e/2),this.count=1,t&&(this.count=Y(this)+2)}return this.s+=this.diff,this.count--,this.s}},bo=class{constructor(e){this.decoder=new vo(e),this.str=po(this.decoder),this.spos=0}read(){let e=this.spos+this.decoder.read(),t=this.str.slice(this.spos,e);return this.spos=e,t}};crypto.subtle;var xo=crypto.getRandomValues.bind(crypto),So=Math.random,Co=()=>xo(new Uint32Array(1))[0],wo=e=>e[Yi(So()*e.length)],To=`10000000-1000-4000-8000-100000000000`,Eo=()=>To.replace(/[018]/g,e=>(e^Co()&15>>e/4).toString(16)),Do=Date.now,Oo=e=>new Promise(e);Promise.all.bind(Promise);var ko=e=>e===void 0?null:e,Ao=new class{constructor(){this.map=new Map}setItem(e,t){this.map.set(e,t)}getItem(e){return this.map.get(e)}};try{typeof localStorage<`u`&&localStorage&&(Ao=localStorage)}catch{}var jo=Ao,Mo=Symbol(`Equality`),No=(e,t)=>e===t||!!e?.[Mo]?.(t)||!1,Po=e=>typeof e==`object`,Fo=Object.assign,Io=Object.keys,Lo=(e,t)=>{for(let n in e)t(e[n],n)},Ro=e=>Io(e).length,zo=e=>{for(let t in e)return!1;return!0},Bo=(e,t)=>{for(let n in e)if(!t(e[n],n))return!1;return!0},Vo=(e,t)=>Object.prototype.hasOwnProperty.call(e,t),Ho=(e,t)=>e===t||Ro(e)===Ro(t)&&Bo(e,(e,n)=>(e!==void 0||Vo(t,n))&&No(t[n],e)),Uo=Object.freeze,Wo=e=>{for(let t in e){let n=e[t];(typeof n==`object`||typeof n==`function`)&&Wo(e[t])}return Uo(e)},Go=(e,t,n=0)=>{try{for(;n<e.length;n++)e[n](...t)}finally{n<e.length&&Go(e,t,n+1)}},Ko=e=>e,qo=(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[Mo]!=null)return e[Mo](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)||!qo(e.get(n),t.get(n)))return!1;break;case void 0:case Object:if(Ro(e)!==Ro(t))return!1;for(let n in e)if(!Vo(e,n)||!qo(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(!qo(e[n],t[n]))return!1;break;default:return!1}return!0},Jo=(e,t)=>t.includes(e),Yo=typeof process<`u`&&process.release&&/node|io\.js/.test(process.release.name)&&Object.prototype.toString.call(typeof process<`u`?process:0)===`[object process]`,Xo=typeof window<`u`&&typeof document<`u`&&!Yo;typeof navigator<`u`&&/Mac/.test(navigator.platform);var Zo,Qo=[],$o=()=>{if(Zo===void 0)if(Yo){Zo=Fi();let e=process.argv,t=null;for(let n=0;n<e.length;n++){let r=e[n];r[0]===`-`?(t!==null&&Zo.set(t,``),t=r):t===null?Qo.push(r):(Zo.set(t,r),t=null)}t!==null&&Zo.set(t,``)}else typeof location==`object`?(Zo=Fi(),(location.search||`?`).slice(1).split(`&`).forEach(e=>{if(e.length!==0){let[t,n]=e.split(`=`);Zo.set(`--${xa(t,`-`)}`,n),Zo.set(`-${xa(t,`-`)}`,n)}})):Zo=Fi();return Zo},es=e=>$o().has(e),ts=e=>ko(Yo?{}[e.toUpperCase().replaceAll(`-`,`_`)]:jo.getItem(e)),ns=e=>es(`--`+e)||ts(e)!==null,rs=ns(`production`),is=Yo&&Jo({}.FORCE_COLOR,[`true`,`1`,`2`])||!es(`--no-colors`)&&!ns(`no-color`)&&(!Yo||process.stdout.isTTY)&&(!Yo||es(`--color`)||ts(`COLORTERM`)!==null||(ts(`TERM`)||``).includes(`color`)),as=e=>new Uint8Array(e),os=Xo?e=>{let t=``;for(let n=0;n<e.byteLength;n++)t+=ga(e[n]);return btoa(t)}:e=>Buffer.from(e.buffer,e.byteOffset,e.byteLength).toString(`base64`),ss=e=>{let t=as(e.byteLength);return t.set(e),t},cs=e=>ka(t=>qa(t,e)),ls=class{constructor(e,t){this.left=e,this.right=t}},us=(e,t)=>new ls(e,t),ds=(e,t)=>e.forEach(e=>t(e.left,e.right)),fs=e=>e.next()>=.5,ps=(e,t,n)=>Yi(e.next()*(n+1-t)+t),ms=(e,t,n)=>Yi(e.next()*(n+1-t)+t),hs=(e,t,n)=>ms(e,t,n),gs=e=>ga(hs(e,97,122)),_s=(e,t=0,n=20)=>{let r=hs(e,t,n),i=``;for(let t=0;t<r;t++)i+=gs(e);return i},vs=(e,t)=>t[hs(e,0,t.length-1)],ys=Symbol(`0schema`),bs=class{constructor(){this._rerrs=[]}extend(e,t,n,r=null){this._rerrs.push({path:e,expected:t,has:n,message:r})}toString(){let e=[];for(let t=this._rerrs.length-1;t>0;t--){let n=this._rerrs[t];e.push(Ea(` `,(this._rerrs.length-t)*2)+`${n.path==null?``:`[${n.path}] `}${n.has} doesn't match ${n.expected}. ${n.message}`)}return e.join(`
|
|
2
2
|
`)}},xs=(e,t)=>e===t?!0:e==null||t==null||e.constructor!==t.constructor?!1:e[Mo]?No(e,t):qi(e)?Wi(e,e=>Gi(t,t=>xs(e,t))):Po(e)?Bo(e,(e,n)=>xs(e,t[n])):!1,Ss=class{static _dilutes=!1;extends(e){let[t,n]=[this.shape,e.shape];return this.constructor._dilutes&&([n,t]=[t,n]),xs(t,n)}equals(e){return this.constructor===e.constructor&&qo(this.shape,e.shape)}[ys](){return!0}[Mo](e){return this.equals(e)}validate(e){return this.check(e)}check(e,t){to()}get nullable(){return tc(this,gc)}get optional(){return new Ns(this)}cast(e){return bc(e,this),e}expect(e){return bc(e,this),e}},Cs=class extends Ss{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}},ws=(e,t=null)=>new Cs(e,t);ws(Cs);var Ts=class extends Ss{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}},Es=e=>new Ts(e);ws(Ts);var Ds=class extends Ss{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}},Os=(...e)=>new Ds(e),ks=ws(Ds),As=RegExp.escape||(e=>e.replace(/[().|&,$^[\]]/g,e=>`\\`+e)),js=e=>{if(dc.check(e))return[As(e)];if(ks.check(e))return e.shape.map(e=>e+``);if(uc.check(e))return[`[+-]?\\d+.?\\d*`];if(fc.check(e))return[`.*`];if(nc.check(e))return e.shape.map(js).flat(1);no()};ws(class extends Ss{constructor(e){super(),this.shape=e,this._r=RegExp(`^`+e.map(js).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 Ms=Symbol(`optional`),Ns=class extends Ss{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[Ms](){return!0}},Ps=ws(Ns),Fs=class extends Ss{check(e,t){return t?.extend(null,`never`,typeof e),!1}};new Fs,ws(Fs);var Is=class e extends Ss{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):Bo(this.shape,(n,r)=>{let i=this._isPartial&&!Vo(e,r)||n.check(e[r],t);return!i&&t?.extend(r.toString(),n.toString(),typeof e[r],`Object property does not match`),i})}},Ls=e=>new Is(e),Rs=ws(Is),zs=Es(e=>e!=null&&(e.constructor===Object||e.constructor==null)),Bs=class extends Ss{constructor(e,t){super(),this.shape={keys:e,values:t}}check(e,t){return e!=null&&Bo(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)})}},Vs=(e,t)=>new Bs(e,t),Hs=ws(Bs),Us=class extends Ss{constructor(e){super(),this.shape=e}check(e,t){return e!=null&&Bo(this.shape,(n,r)=>{let i=n.check(e[r],t);return!i&&t?.extend(r.toString(),`Tuple`,typeof n),i})}},Ws=(...e)=>new Us(e);ws(Us);var Gs=class extends Ss{constructor(e){super(),this.shape=e.length===1?e[0]:new ec(e)}check(e,t){let n=qi(e)&&Wi(e,e=>this.shape.check(e));return!n&&t?.extend(null,`Array`,``),n}},Ks=(...e)=>new Gs(e),qs=ws(Gs),Js=Es(e=>qi(e)),Ys=class extends Ss{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}},Xs=(e,t=null)=>new Ys(e,t);ws(Ys);var Zs=Xs(Ss),Qs=ws(class extends Ss{constructor(e){super(),this.len=e.length-1,this.args=Ws(...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}}),$s=Es(e=>typeof e==`function`);ws(class extends Ss{constructor(e){super(),this.shape=e}check(e,t){let n=Wi(this.shape,n=>n.check(e,t));return!n&&t?.extend(null,`Intersectinon`,typeof e),n}},e=>e.shape.length>0);var ec=class extends Ss{static _dilutes=!0;constructor(e){super(),this.shape=e}check(e,t){let n=Gi(this.shape,n=>n.check(e,t));return t?.extend(null,`Union`,typeof e),n}},tc=(...e)=>e.findIndex(e=>nc.check(e))>=0?tc(...e.map(e=>yc(e)).map(e=>nc.check(e)?e.shape:[e]).flat(1)):e.length===1?e[0]:new ec(e),nc=ws(ec),rc=()=>!0,ic=Es(rc),ac=ws(Ts,e=>e.shape===rc),oc=Es(e=>typeof e==`bigint`),sc=Es(e=>e===oc),cc=Es(e=>typeof e==`symbol`);Es(e=>e===cc);var lc=Es(e=>typeof e==`number`),uc=Es(e=>e===lc),dc=Es(e=>typeof e==`string`),fc=Es(e=>e===dc),pc=Es(e=>typeof e==`boolean`),mc=Es(e=>e===pc),hc=Os(void 0);ws(Ds,e=>e.shape.length===1&&e.shape[0]===void 0),Os(void 0);var gc=Os(null),_c=ws(Ds,e=>e.shape.length===1&&e.shape[0]===null);ws(Uint8Array),ws(Cs,e=>e.shape===Uint8Array);var vc=tc(lc,dc,gc,hc,oc,pc,cc);(()=>{let e=Ks(ic),t=Vs(dc,ic),n=tc(lc,dc,gc,pc,e,t);return e.shape=n,t.shape.values=n,n})();var yc=e=>{if(Zs.check(e))return e;if(zs.check(e)){let t={};for(let n in e)t[n]=yc(e[n]);return Ls(t)}else if(Js.check(e))return tc(...e.map(yc));else if(vc.check(e))return Os(e);else if($s.check(e))return ws(e);no()},bc=rs?()=>{}:(e,t)=>{let n=new bs;if(!t.check(e,n))throw eo(`Expected value to be of type ${t.constructor.name}.\n${n.toString()}`)},xc=class{constructor(e){this.patterns=[],this.$state=e}if(e,t){return this.patterns.push({if:yc(e),h:t}),this}else(e){return this.if(ic,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 eo(`Unhandled pattern`)}}},Sc=(e=>new xc(e))(ic).if(uc,(e,t)=>ps(t,ma,pa)).if(fc,(e,t)=>_s(t)).if(mc,(e,t)=>fs(t)).if(sc,(e,t)=>BigInt(ps(t,ma,pa))).if(nc,(e,t)=>Cc(t,vs(t,e.shape))).if(Rs,(e,t)=>{let n={};for(let r in e.shape){let i=e.shape[r];if(Ps.check(i)){if(fs(t))continue;i=i.shape}n[r]=Sc(i,t)}return n}).if(qs,(e,t)=>{let n=[],r=ms(t,0,42);for(let i=0;i<r;i++)n.push(Cc(t,e.shape));return n}).if(ks,(e,t)=>vs(t,e.shape)).if(_c,(e,t)=>null).if(Qs,(e,t)=>{let n=Cc(t,e.res);return()=>n}).if(ac,(e,t)=>Cc(t,vs(t,[lc,dc,gc,hc,oc,pc,Ks(lc),Vs(tc(`a`,`b`,`c`),lc)]))).if(Hs,(e,t)=>{let n={},r=ps(t,0,3);for(let i=0;i<r;i++){let r=Cc(t,e.shape.keys);n[r]=Cc(t,e.shape.values)}return n}).done(),Cc=(e,t)=>Sc(yc(t),e),wc=typeof document<`u`?document:{},Tc=e=>wc.createElement(e),Ec=()=>wc.createDocumentFragment();Es(e=>e.nodeType===Rc);var Dc=e=>wc.createTextNode(e);typeof DOMParser<`u`&&new DOMParser;var Oc=(e,t)=>(ds(t,(t,n)=>{n===!1?e.removeAttribute(t):n===!0?e.setAttribute(t,``):e.setAttribute(t,n)}),e),kc=e=>{let t=Ec();for(let n=0;n<e.length;n++)Pc(t,e[n]);return t},Ac=(e,t)=>(Pc(e,kc(t)),e),jc=(e,t=[],n=[])=>Ac(Oc(Tc(e),t),n);Es(e=>e.nodeType===Fc);var Mc=Dc;Es(e=>e.nodeType===Ic);var Nc=e=>Ri(e,(e,t)=>`${t}:${e};`).join(``),Pc=(e,t)=>e.appendChild(t),Fc=wc.ELEMENT_NODE,Ic=wc.TEXT_NODE;wc.CDATA_SECTION_NODE,wc.COMMENT_NODE;var Lc=wc.DOCUMENT_NODE;wc.DOCUMENT_TYPE_NODE;var Rc=wc.DOCUMENT_FRAGMENT_NODE;Es(e=>e.nodeType===Lc);var zc=(e=>class{constructor(e){this._=e}destroy(){e(this._)}})(clearTimeout),Bc=(e,t)=>new zc(setTimeout(t,e)),Vc=Symbol,Hc=Vc(),Uc=Vc(),Wc=Vc(),Gc=Vc(),Kc=Vc(),qc=Vc(),Jc=Vc(),Yc=Vc(),Xc=Vc(),Zc=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};Do();var Qc={[Hc]:us(`font-weight`,`bold`),[Uc]:us(`font-weight`,`normal`),[Wc]:us(`color`,`blue`),[Kc]:us(`color`,`green`),[Gc]:us(`color`,`grey`),[qc]:us(`color`,`red`),[Jc]:us(`color`,`purple`),[Yc]:us(`color`,`orange`),[Xc]:us(`color`,`black`)},$c=is?e=>{e.length===1&&e[0]?.constructor===Function&&(e=e[0]());let t=[],n=[],r=Fi(),i=[],a=0;for(;a<e.length;a++){let i=e[a],o=Qc[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=Nc(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}:Zc,el=(...e)=>{console.log(...$c(e)),nl.forEach(t=>t.print(e))},tl=(...e)=>{console.warn(...$c(e)),e.unshift(Yc),nl.forEach(t=>t.print(e))},nl=Bi(),rl=e=>({[Symbol.iterator](){return this},next:e}),il=(e,t)=>rl(()=>{let n;do n=e.next();while(!n.done&&!t(n.value));return n}),al=(e,t)=>rl(()=>{let{done:n,value:r}=e.next();return{done:n,value:n?void 0:t(r)}}),ol=class{constructor(e,t){this.clock=e,this.len=t}},sl=class{constructor(){this.clients=new Map}},cl=(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])Eu(e,i,o.clock,o.len,n)}}),ll=(e,t)=>{let n=0,r=e.length-1;for(;n<=r;){let i=Yi((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},ul=(e,t)=>{let n=e.clients.get(t.client);return n!==void 0&&ll(n,t.clock)!==null},dl=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 ol(r.clock,Qi(r.len,i.clock+i.len-r.clock)):(n<t&&(e[n]=i),n++)}e.length=n})},fl=e=>{let t=new sl;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++)Hi(a,e[t].clients.get(i)||[]);t.clients.set(i,a)}});return dl(t),t},pl=(e,t,n,r)=>{Li(e.clients,t,()=>[]).push(new ol(n,r))},ml=()=>new sl,hl=e=>{let t=ml();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 ol(i,a))}}r.length>0&&t.clients.set(n,r)}),t},gl=(e,t)=>{J(e.restEncoder,t.clients.size),Ui(t.clients.entries()).sort((e,t)=>t[0]-e[0]).forEach(([t,n])=>{e.resetDsCurVal(),J(e.restEncoder,t);let r=n.length;J(e.restEncoder,r);for(let t=0;t<r;t++){let r=n[t];e.writeDsClock(r.clock),e.writeDsLen(r.len)}})},_l=e=>{let t=new sl,n=Y(e.restDecoder);for(let r=0;r<n;r++){e.resetDsCurVal();let n=Y(e.restDecoder),r=Y(e.restDecoder);if(r>0){let i=Li(t.clients,n,()=>[]);for(let t=0;t<r;t++)i.push(new ol(e.readDsClock(),e.readDsLen()))}}return t},vl=(e,t,n)=>{let r=new sl,i=Y(e.restDecoder);for(let a=0;a<i;a++){e.resetDsCurVal();let i=Y(e.restDecoder),a=Y(e.restDecoder),o=n.clients.get(i)||[],s=vu(n,i);for(let n=0;n<a;n++){let n=e.readDsClock(),a=n+e.readDsLen();if(n<s){s<a&&pl(r,i,s,a-s);let e=bu(o,n),c=o[e];for(!c.deleted&&c.id.clock<n&&(o.splice(e+1,0,Wf(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,Wf(t,c,a-c.id.clock)),c.delete(t))}else pl(r,i,n,a-n)}}if(r.clients.size>0){let e=new Ol;return J(e.restEncoder,0),gl(e,r),e.toUint8Array()}return null},yl=Co,bl=class e extends Ji{constructor({guid:e=Eo(),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=yl(),this.guid=e,this.collectionid=t,this.share=new Map,this.store=new gu,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=Oo(e=>{this.on(`load`,()=>{this.isLoaded=!0,e(this)})});let s=()=>Oo(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&&Pu(e.parent.doc,e=>{e.subdocsLoaded.add(this)},null,!0),this.shouldLoad=!0}getSubdocs(){return this.subdocs}getSubdocGuids(){return new Set(Ui(this.subdocs).map(e=>e.guid))}transact(e,t=null){return Pu(this,e,t)}get(e,t=ud){let n=Li(this.share,e,()=>{let e=new t;return e._integrate(this,null),e}),r=n.constructor;if(t!==ud&&r!==t)if(r===ud){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,jd)}getText(e=``){return this.get(e,Qd)}getMap(e=``){return this.get(e,Pd)}getXmlElement(e=``){return this.get(e,rf)}getXmlFragment(e=``){return this.get(e,tf)}toJSON(){let e={};return this.share.forEach((t,n)=>{e[n]=t.toJSON()}),e}destroy(){this.isDestroyed=!0,Ui(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,Pu(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()}},xl=class{constructor(e){this.restDecoder=e}resetDsCurVal(){}readDsClock(){return Y(this.restDecoder)}readDsLen(){return Y(this.restDecoder)}},Sl=class extends xl{readLeftID(){return X(Y(this.restDecoder),Y(this.restDecoder))}readRightID(){return X(Y(this.restDecoder),Y(this.restDecoder))}readClient(){return Y(this.restDecoder)}readInfo(){return uo(this.restDecoder)}readString(){return po(this.restDecoder)}readParentInfo(){return Y(this.restDecoder)===1}readTypeRef(){return Y(this.restDecoder)}readLen(){return Y(this.restDecoder)}readAny(){return go(this.restDecoder)}readBuf(){return ss(lo(this.restDecoder))}readJSON(){return JSON.parse(po(this.restDecoder))}readKey(){return po(this.restDecoder)}},Cl=class{constructor(e){this.dsCurrVal=0,this.restDecoder=e}resetDsCurVal(){this.dsCurrVal=0}readDsClock(){return this.dsCurrVal+=Y(this.restDecoder),this.dsCurrVal}readDsLen(){let e=Y(this.restDecoder)+1;return this.dsCurrVal+=e,e}},wl=class extends Cl{constructor(e){super(e),this.keys=[],Y(e),this.keyClockDecoder=new yo(lo(e)),this.clientDecoder=new vo(lo(e)),this.leftClockDecoder=new yo(lo(e)),this.rightClockDecoder=new yo(lo(e)),this.infoDecoder=new _o(lo(e),uo),this.stringDecoder=new bo(lo(e)),this.parentInfoDecoder=new _o(lo(e),uo),this.typeRefDecoder=new vo(lo(e)),this.lenDecoder=new vo(lo(e))}readLeftID(){return new Zl(this.clientDecoder.read(),this.leftClockDecoder.read())}readRightID(){return new Zl(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 go(this.restDecoder)}readBuf(){return lo(this.restDecoder)}readJSON(){return go(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}}},Tl=class{constructor(){this.restEncoder=Oa()}toUint8Array(){return ja(this.restEncoder)}resetDsCurVal(){}writeDsClock(e){J(this.restEncoder,e)}writeDsLen(e){J(this.restEncoder,e)}},El=class extends Tl{writeLeftID(e){J(this.restEncoder,e.client),J(this.restEncoder,e.clock)}writeRightID(e){J(this.restEncoder,e.client),J(this.restEncoder,e.clock)}writeClient(e){J(this.restEncoder,e)}writeInfo(e){Pa(this.restEncoder,e)}writeString(e){Ra(this.restEncoder,e)}writeParentInfo(e){J(this.restEncoder,+!!e)}writeTypeRef(e){J(this.restEncoder,e)}writeLen(e){J(this.restEncoder,e)}writeAny(e){qa(this.restEncoder,e)}writeBuf(e){Ba(this.restEncoder,e)}writeJSON(e){Ra(this.restEncoder,JSON.stringify(e))}writeKey(e){Ra(this.restEncoder,e)}},Dl=class{constructor(){this.restEncoder=Oa(),this.dsCurrVal=0}toUint8Array(){return ja(this.restEncoder)}resetDsCurVal(){this.dsCurrVal=0}writeDsClock(e){let t=e-this.dsCurrVal;this.dsCurrVal=e,J(this.restEncoder,t)}writeDsLen(e){e===0&&no(),J(this.restEncoder,e-1),this.dsCurrVal+=e}},Ol=class extends Dl{constructor(){super(),this.keyMap=new Map,this.keyClock=0,this.keyClockEncoder=new Qa,this.clientEncoder=new Xa,this.leftClockEncoder=new Qa,this.rightClockEncoder=new Qa,this.infoEncoder=new Ja(Pa),this.stringEncoder=new $a,this.parentInfoEncoder=new Ja(Pa),this.typeRefEncoder=new Xa,this.lenEncoder=new Xa}toUint8Array(){let e=Oa();return J(e,0),Ba(e,this.keyClockEncoder.toUint8Array()),Ba(e,this.clientEncoder.toUint8Array()),Ba(e,this.leftClockEncoder.toUint8Array()),Ba(e,this.rightClockEncoder.toUint8Array()),Ba(e,ja(this.infoEncoder)),Ba(e,this.stringEncoder.toUint8Array()),Ba(e,ja(this.parentInfoEncoder)),Ba(e,this.typeRefEncoder.toUint8Array()),Ba(e,this.lenEncoder.toUint8Array()),za(e,ja(this.restEncoder)),ja(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){qa(this.restEncoder,e)}writeBuf(e){Ba(this.restEncoder,e)}writeJSON(e){qa(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)}},kl=(e,t,n,r)=>{r=Qi(r,t[0].id.clock);let i=bu(t,r);J(e.restEncoder,t.length-i),e.writeClient(n),J(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)},Al=(e,t,n)=>{let r=new Map;n.forEach((e,n)=>{vu(t,n)>e&&r.set(n,e)}),_u(t).forEach((e,t)=>{n.has(t)||r.set(t,0)}),J(e.restEncoder,r.size),Ui(r.entries()).sort((e,t)=>t[0]-e[0]).forEach(([n,r])=>{kl(e,t.clients.get(n),n,r)})},jl=(e,t)=>{let n=Fi(),r=Y(e.restDecoder);for(let i=0;i<r;i++){let r=Y(e.restDecoder),i=Array(r),a=e.readClient(),o=Y(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 pf(X(a,o),t),o+=t;break}case 10:{let t=Y(e.restDecoder);i[n]=new Zf(X(a,o),t),o+=t;break}default:{let s=(r&192)==0,c=new qf(X(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,Jf(e,r));i[n]=c,o+=c.length}}}}return n},Ml=(e,t,n)=>{let r=[],i=Ui(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 gu,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!==Zf){let i=Li(d,u.id.client,()=>vu(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,vu(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 Ol;return Al(e,s,new Map),J(e.restEncoder,0),{missing:c,update:e.toUint8Array()}}return null},Nl=(e,t)=>Al(e,t.doc.store,t.beforeState),Pl=(e,t,n,r=new wl(e))=>Pu(t,e=>{e.local=!1;let t=!1,n=e.doc,i=n.store,a=Ml(e,i,jl(r,n)),o=i.pendingStructs;if(o){for(let[e,n]of o.missing)if(n<vu(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=Wu([o.update,a.update])}}else i.pendingStructs=a;let s=vl(r,e,i);if(i.pendingDs){let t=new wl(oo(i.pendingDs));Y(t.restDecoder);let n=vl(t,e,i);s&&n?i.pendingDs=Wu([s,n]):i.pendingDs=s||n}else i.pendingDs=s;if(t){let t=i.pendingStructs.update;i.pendingStructs=null,Fl(e.doc,t)}},n,!1),Fl=(e,t,n,r=wl)=>{let i=oo(t);Pl(i,e,n,new r(i))},Il=(e,t,n)=>Fl(e,t,n,Sl),Ll=(e,t,n=new Map)=>{Al(e,t.store,n),gl(e,hl(t.store))},Rl=(e,t=new Uint8Array([0]),n=new Ol)=>{Ll(n,e,Vl(t));let r=[n.toUint8Array()];if(e.store.pendingDs&&r.push(e.store.pendingDs),e.store.pendingStructs&&r.push(Gu(e.store.pendingStructs.update,t)),r.length>1){if(n.constructor===El)return Hu(r.map((e,t)=>t===0?e:Xu(e)));if(n.constructor===Ol)return Wu(r)}return r[0]},zl=(e,t)=>Rl(e,t,new El),Bl=e=>{let t=new Map,n=Y(e.restDecoder);for(let r=0;r<n;r++){let n=Y(e.restDecoder),r=Y(e.restDecoder);t.set(n,r)}return t},Vl=e=>Bl(new xl(oo(e))),Hl=(e,t)=>(J(e.restEncoder,t.size),Ui(t.entries()).sort((e,t)=>t[0]-e[0]).forEach(([t,n])=>{J(e.restEncoder,t),J(e.restEncoder,n)}),e),Ul=(e,t)=>Hl(e,_u(t.store)),Wl=(e,t=new Dl)=>(e instanceof Map?Hl(t,e):Ul(t,e),t.toUint8Array()),Gl=e=>Wl(e,new Tl),Kl=class{constructor(){this.l=[]}},ql=()=>new Kl,Jl=(e,t)=>e.l.push(t),Yl=(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.`)},Xl=(e,t,n)=>Go(e.l,[t,n]),Zl=class{constructor(e,t){this.client=e,this.clock=t}},Ql=(e,t)=>e===t||e!==null&&t!==null&&e.client===t.client&&e.clock===t.clock,X=(e,t)=>new Zl(e,t),$l=e=>{for(let[t,n]of e.doc.share.entries())if(n===e)return t;throw no()},eu=(e,t)=>{for(;t!==null;){if(t.parent===e)return!0;t=t.parent._item}return!1},tu=class{constructor(e,t,n,r=0){this.type=e,this.tname=t,this.item=n,this.assoc=r}},nu=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},ru=e=>new tu(e.type==null?null:X(e.type.client,e.type.clock),e.tname??null,e.item==null?null:X(e.item.client,e.item.clock),e.assoc==null?0:e.assoc),iu=class{constructor(e,t,n=0){this.type=e,this.index=t,this.assoc=n}},au=(e,t,n=0)=>new iu(e,t,n),ou=(e,t,n)=>{let r=null,i=null;return e._item===null?i=$l(e):r=X(e._item.id.client,e._item.id.clock),new tu(r,i,t,n)},su=(e,t,n=0)=>{let r=e._start;if(n<0){if(t===0)return ou(e,null,n);t--}for(;r!==null;){if(!r.deleted&&r.countable){if(r.length>t)return ou(e,X(r.id.client,r.id.clock+t),n);t-=r.length}if(r.right===null&&n<0)return ou(e,r.lastId,n);r=r.right}return ou(e,null,n)},cu=(e,t)=>{let n=xu(e,t);return{item:n,diff:t.clock-n.id.clock}},lu=(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(vu(r,i.client)<=i.clock)return null;let e=n?Hf(r,i):cu(r,i),t=e.item;if(!(t instanceof qf))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(vu(r,a.client)<=a.clock)return null;let{item:e}=n?Hf(r,a):{item:xu(r,a)};if(e instanceof qf&&e.content instanceof Bf)c=e.content.type;else return null}else throw no();l=s>=0?c._length:0}return au(c,l,e.assoc)},uu=(e,t)=>e===t||e!==null&&t!==null&&e.tname===t.tname&&Ql(e.item,t.item)&&Ql(e.type,t.type)&&e.assoc===t.assoc,du=class{constructor(e,t){this.ds=e,this.sv=t}},fu=(e,t)=>new du(e,t);fu(ml(),new Map);var pu=e=>fu(hl(e.store),_u(e.store)),mu=(e,t)=>t===void 0?!e.deleted:t.sv.has(e.id.client)&&(t.sv.get(e.id.client)||0)>e.id.clock&&!ul(t.ds,e.id),hu=(e,t)=>{let n=Li(e.meta,hu,Bi),r=e.doc.store;n.has(t)||(t.sv.forEach((t,n)=>{t<vu(r,n)&&Cu(e,X(n,t))}),cl(e,t.ds,e=>{}),n.add(t))},gu=class{constructor(){this.clients=new Map,this.pendingStructs=null,this.pendingDs=null}},_u=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},vu=(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},yu=(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 no()}n.push(t)},bu=(e,t)=>{let n=0,r=e.length-1,i=e[r],a=i.id.clock;if(a===t)return r;let o=Yi(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=Yi((n+r)/2)}throw no()},xu=(e,t)=>{let n=e.clients.get(t.client);return n[bu(n,t.clock)]},Su=(e,t,n)=>{let r=bu(t,n),i=t[r];return i.id.clock<n&&i instanceof qf?(t.splice(r+1,0,Wf(e,i,n-i.id.clock)),r+1):r},Cu=(e,t)=>{let n=e.doc.store.clients.get(t.client);return n[Su(e,n,t.clock)]},wu=(e,t,n)=>{let r=t.clients.get(n.client),i=bu(r,n.clock),a=r[i];return n.clock!==a.id.clock+a.length-1&&a.constructor!==pf&&r.splice(i+1,0,Wf(e,a,n.clock-a.id.clock+1)),a},Tu=(e,t,n)=>{let r=e.clients.get(t.id.client);r[bu(r,t.id.clock)]=n},Eu=(e,t,n,r,i)=>{if(r===0)return;let a=n+r,o=Su(e,t,n),s;do s=t[o++],a<s.id.clock+s.length&&Su(e,t,a),i(s);while(o<t.length&&t[o].id.clock<a)},Du=class{constructor(e,t,n){this.doc=e,this.deleteSet=new sl,this.beforeState=_u(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}},Ou=(e,t)=>t.deleteSet.clients.size===0&&!zi(t.afterState,(e,n)=>t.beforeState.get(n)!==e)?!1:(dl(t.deleteSet),Nl(e,t),gl(e,t.deleteSet),!0),ku=(e,t,n)=>{let r=t._item;(r===null||r.id.clock<(e.beforeState.get(r.id.client)||0)&&!r.deleted)&&Li(e.changed,t,Bi).add(n)},Au=(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 qf&&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},ju=(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=bu(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 qf&&i.deleted&&!i.keep&&n(i)&&i.gc(t,!1)}}}},Mu=(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=Zi(r.length-1,1+bu(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+Au(r,e)}})},Nu=(e,t)=>{if(t<e.length){let n=e[t],r=n.doc,i=r.store,a=n.deleteSet,o=n._mergeStructs;try{dl(a),n.afterState=_u(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(()=>{Xl(r._dEH,t,n)}))}),e.push(()=>r.emit(`afterTransaction`,[n,r])),e.push(()=>{n._needFormattingCleanup&&Yd(n)})}),Go(e,[])}finally{r.gc&&ju(a,i,r.gcFilter),Mu(a,i),n.afterState.forEach((e,t)=>{let r=n.beforeState.get(t)||0;if(r!==e){let e=i.clients.get(t),n=Qi(bu(e,r),1);for(let t=e.length-1;t>=n;)t-=1+Au(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=bu(r,n);a+1<r.length&&Au(r,a+1)>1||a>0&&Au(r,a)}if(!n.local&&n.afterState.get(r.clientID)!==n.beforeState.get(r.clientID)&&(el(Yc,Hc,`[yjs] `,Uc,qc,`Changed the client-id because another client seems to be using it.`),r.clientID=yl()),r.emit(`afterTransactionCleanup`,[n,r]),r._observers.has(`update`)){let e=new El;Ou(e,n)&&r.emit(`update`,[e.toUint8Array(),n.origin,r,n])}if(r._observers.has(`updateV2`)){let e=new Ol;Ou(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])):Nu(e,t+1)}}},Pu=(e,t,n=null,r=!0)=>{let i=e._transactionCleanups,a=!1,o=null;e._transaction===null&&(a=!0,e._transaction=new Du(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&&Nu(i,0)}}return o},Fu=class{constructor(e,t){this.insertions=t,this.deletions=e,this.meta=new Map}},Iu=(e,t,n)=>{cl(e,n.deletions,n=>{n instanceof qf&&t.scope.some(t=>t===e.doc||eu(t,n))&&Uf(n,!1)})},Lu=(e,t,n)=>{let r=null,i=e.doc,a=e.scope;Pu(i,n=>{for(;t.length>0&&e.currStackItem===null;){let r=i.store,o=t.pop(),s=new Set,c=[],l=!1;cl(n,o.insertions,e=>{if(e instanceof qf){if(e.redone!==null){let{item:t,diff:i}=Hf(r,e.id);i>0&&(t=Cu(n,X(t.id.client,t.id.clock+i))),e=t}!e.deleted&&a.some(t=>t===n.doc||eu(t,e))&&c.push(e)}}),cl(n,o.deletions,e=>{e instanceof qf&&a.some(t=>t===n.doc||eu(t,e))&&!ul(o.insertions,e.id)&&s.add(e)}),s.forEach(t=>{l=Kf(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},Ru=class extends Ji{constructor(e,{captureTimeout:t=500,captureTransaction:n=e=>!0,deleteFilter:r=()=>!0,trackedOrigins:i=new Set([null]),ignoreRemoteMapChanges:a=!1,doc:o=qi(e)?e[0].doc:e instanceof bl?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 sl;e.afterState.forEach((t,n)=>{let r=e.beforeState.get(n)||0,a=t-r;a>0&&pl(i,n,r,a)});let a=Do(),o=!1;if(this.lastChange>0&&a-this.lastChange<this.captureTimeout&&r.length>0&&!t&&!n){let t=r[r.length-1];t.deletions=fl([t.deletions,e.deleteSet]),t.insertions=fl([t.insertions,i])}else r.push(new Fu(e.deleteSet,i)),o=!0;!t&&!n&&(this.lastChange=a),cl(e,e.deleteSet,t=>{t instanceof qf&&this.scope.some(n=>n===e.doc||eu(n,t))&&Uf(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=qi(e)?e:[e],e.forEach(e=>{t.has(e)||(t.add(e),(e instanceof ud?e.doc!==this.doc:e!==this.doc)&&tl(`[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=>Iu(n,this,e)),this.undoStack=[]),t&&(this.redoStack.forEach(e=>Iu(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=Lu(this,this.undoStack,`undo`)}finally{this.undoing=!1}return e}redo(){this.redoing=!0;let e;try{e=Lu(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*zu(e){let t=Y(e.restDecoder);for(let n=0;n<t;n++){let t=Y(e.restDecoder),n=e.readClient(),r=Y(e.restDecoder);for(let i=0;i<t;i++){let t=e.readInfo();if(t===10){let t=Y(e.restDecoder);yield new Zf(X(n,r),t),r+=t}else if(31&t){let i=(t&192)==0,a=new qf(X(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,Jf(e,t));yield a,r+=a.length}else{let t=e.readLen();yield new pf(X(n,r),t),r+=t}}}}var Bu=class{constructor(e,t){this.gen=zu(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===Zf);return this.curr}},Vu=class{constructor(e){this.currClient=0,this.startClock=0,this.written=0,this.encoder=e,this.clientStructs=[]}},Hu=e=>Wu(e,Sl,El),Uu=(e,t)=>{if(e.constructor===pf){let{client:n,clock:r}=e.id;return new pf(X(n,r+t),e.length-t)}else if(e.constructor===Zf){let{client:n,clock:r}=e.id;return new Zf(X(n,r+t),e.length-t)}else{let n=e,{client:r,clock:i}=n.id;return new qf(X(r,i+t),null,X(r,i+t-1),null,n.rightOrigin,n.parent,n.parentSub,n.content.splice(t))}},Wu=(e,t=wl,n=Ol)=>{if(e.length===1)return e[0];let r=e.map(e=>new t(oo(e))),i=r.map(e=>new Bu(e,!0)),a=null,o=new n,s=new Vu(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===Zf?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)qu(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===Zf)a.struct.length=n.id.clock+n.length-a.struct.id.clock;else{qu(s,a.struct,a.offset);let e=n.id.clock-a.struct.id.clock-a.struct.length;a={struct:new Zf(X(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===Zf?a.struct.length-=t:n=Uu(n,t)),a.struct.mergeWith(n)||(qu(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!==Zf;n=e.next())qu(s,a.struct,a.offset),a={struct:n,offset:0}}return a!==null&&(qu(s,a.struct,a.offset),a=null),Ju(s),gl(o,fl(r.map(e=>_l(e)))),o.toUint8Array()},Gu=(e,t,n=wl,r=Ol)=>{let i=Vl(t),a=new r,o=new Vu(a),s=new n(oo(e)),c=new Bu(s,!1);for(;c.curr;){let e=c.curr,t=e.id.client,n=i.get(t)||0;if(c.curr.constructor===Zf){c.next();continue}if(e.id.clock+e.length>n)for(qu(o,e,Qi(n-e.id.clock,0)),c.next();c.curr&&c.curr.id.client===t;)qu(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 Ju(o),gl(a,_l(s)),a.toUint8Array()},Ku=e=>{e.written>0&&(e.clientStructs.push({written:e.written,restEncoder:ja(e.encoder.restEncoder)}),e.encoder.restEncoder=Oa(),e.written=0)},qu=(e,t,n)=>{e.written>0&&e.currClient!==t.id.client&&Ku(e),e.written===0&&(e.currClient=t.id.client,e.encoder.writeClient(t.id.client),J(e.encoder.restEncoder,t.id.clock+n)),t.write(e.encoder,n),e.written++},Ju=e=>{Ku(e);let t=e.encoder.restEncoder;J(t,e.clientStructs.length);for(let n=0;n<e.clientStructs.length;n++){let r=e.clientStructs[n];J(t,r.written),za(t,r.restEncoder)}},Yu=(e,t,n,r)=>{let i=new n(oo(e)),a=new Bu(i,!1),o=new r,s=new Vu(o);for(let e=a.curr;e!==null;e=a.next())qu(s,t(e),0);return Ju(s),gl(o,_l(i)),o.toUint8Array()},Xu=e=>Yu(e,Ko,wl,El),Zu=`You must not compute changes after the event-handler fired.`,Qu=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||=$u(this.currentTarget,this.target)}deletes(e){return ul(this.transaction.deleteSet,e.id)}get keys(){if(this._keys===null){if(this.transaction.doc._transactionCleanups.length===0)throw eo(Zu);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=Vi(e.content.getContent());else return;else e!==null&&this.deletes(e)?(i=`update`,a=Vi(e.content.getContent())):(i=`add`,a=void 0)}else if(this.deletes(r))i=`delete`,a=Vi(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 eo(Zu);let t=this.target,n=Bi(),r=Bi(),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}},$u=(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},ed=()=>{tl(`Invalid access: Add Yjs type to a document before reading data.`)},td=80,nd=0,rd=class{constructor(e,t){e.marker=!0,this.p=e,this.index=t,this.timestamp=nd++}},id=e=>{e.timestamp=nd++},ad=(e,t,n)=>{e.p.marker=!1,e.p=t,t.marker=!0,e.index=n,e.timestamp=nd++},od=(e,t,n)=>{if(e.length>=td){let r=e.reduce((e,t)=>e.timestamp<t.timestamp?e:t);return ad(r,t,n),r}else{let r=new rd(t,n);return e.push(r),r}},sd=(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)=>Xi(t-e.index)<Xi(t-n.index)?e:n),r=e._start,i=0;for(n!==null&&(r=n.p,i=n.index,id(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&&Xi(n.index-i)<r.parent.length/td?(ad(n,r,i),n):od(e._searchMarker,r,i)},cd=(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=Qi(t,i.index+n))}},ld=(e,t,n)=>{let r=e,i=t.changedParentTypes;for(;Li(i,e,()=>[]).push(n),e._item!==null;)e=e._item.parent;Xl(r._eH,n,t)},ud=class{constructor(){this._item=null,this._map=new Map,this._start=null,this.doc=null,this._length=0,this._eH=ql(),this._dEH=ql(),this._searchMarker=null}get parent(){return this._item?this._item.parent:null}_integrate(e,t){this.doc=e,this._item=t}_copy(){throw to()}clone(){throw to()}_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){Jl(this._eH,e)}observeDeep(e){Jl(this._dEH,e)}unobserve(e){Yl(this._eH,e)}unobserveDeep(e){Yl(this._dEH,e)}toJSON(){}},dd=(e,t,n)=>{e.doc??ed(),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},fd=e=>{e.doc??ed();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},pd=(e,t)=>{let n=[],r=e._start;for(;r!==null;){if(r.countable&&mu(r,t)){let e=r.content.getContent();for(let t=0;t<e.length;t++)n.push(e[t])}r=r.right}return n},md=(e,t)=>{let n=0,r=e._start;for(e.doc??ed();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}},hd=(e,t)=>{let n=[];return md(e,(r,i)=>{n.push(t(r,i,e))}),n},gd=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}}}},_d=(e,t)=>{e.doc??ed();let n=sd(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}},vd=(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 qf(X(o,vu(s,o)),i,i&&i.lastId,c,c&&c.id,t,null,new Of(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 qf(X(o,vu(s,o)),i,i&&i.lastId,c,c&&c.id,t,null,new mf(new Uint8Array(n))),i.integrate(e,0);break;case bl:i=new qf(X(o,vu(s,o)),i,i&&i.lastId,c,c&&c.id,t,null,new yf(n)),i.integrate(e,0);break;default:if(n instanceof ud)i=new qf(X(o,vu(s,o)),i,i&&i.lastId,c,c&&c.id,t,null,new Bf(n)),i.integrate(e,0);else throw Error(`Unexpected content type in insert operation`)}}}),u()},yd=()=>eo(`Length exceeded!`),bd=(e,t,n,r)=>{if(n>t._length)throw yd();if(n===0)return t._searchMarker&&cd(t._searchMarker,n,r.length),vd(e,t,null,r);let i=n,a=sd(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&&Cu(e,X(o.id.client,o.id.clock+n));break}n-=o.length}return t._searchMarker&&cd(t._searchMarker,i,r.length),vd(e,t,o,r)},xd=(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 vd(e,t,r,n)},Sd=(e,t,n,r)=>{if(r===0)return;let i=n,a=r,o=sd(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&&Cu(e,X(s.id.client,s.id.clock+n)),n-=s.length);for(;r>0&&s!==null;)s.deleted||(r<s.length&&Cu(e,X(s.id.client,s.id.clock+r)),s.delete(e),r-=s.length),s=s.right;if(r>0)throw yd();t._searchMarker&&cd(t._searchMarker,i,-a+r)},Cd=(e,t,n)=>{let r=t._map.get(n);r!==void 0&&r.delete(e)},wd=(e,t,n,r)=>{let i=t._map.get(n)||null,a=e.doc,o=a.clientID,s;if(r==null)s=new Of([r]);else switch(r.constructor){case Number:case Object:case Boolean:case Array:case String:case Date:case BigInt:s=new Of([r]);break;case Uint8Array:s=new mf(r);break;case bl:s=new yf(r);break;default:if(r instanceof ud)s=new Bf(r);else throw Error(`Unexpected content type`)}new qf(X(o,vu(a.store,o)),i,i&&i.lastId,null,null,t,n,s).integrate(e,0)},Td=(e,t)=>{e.doc??ed();let n=e._map.get(t);return n!==void 0&&!n.deleted?n.content.getContent()[n.length-1]:void 0},Ed=e=>{let t={};return e.doc??ed(),e._map.forEach((e,n)=>{e.deleted||(t[n]=e.content.getContent()[e.length-1])}),t},Dd=(e,t)=>{e.doc??ed();let n=e._map.get(t);return n!==void 0&&!n.deleted},Od=(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&&mu(i,t)&&(n[r]=i.content.getContent()[i.length-1])}),n},kd=e=>(e.doc??ed(),il(e._map.entries(),e=>!e[1].deleted)),Ad=class extends Qu{},jd=class e extends ud{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 ud?e.clone():e)),t}get length(){return this.doc??ed(),this._length}_callObserver(e,t){super._callObserver(e,t),ld(this,e,new Ad(this,e))}insert(e,t){this.doc===null?this._prelimContent.splice(e,0,...t):Pu(this.doc,n=>{bd(n,this,e,t)})}push(e){this.doc===null?this._prelimContent.push(...e):Pu(this.doc,t=>{xd(t,this,e)})}unshift(e){this.insert(0,e)}delete(e,t=1){this.doc===null?this._prelimContent.splice(e,t):Pu(this.doc,n=>{Sd(n,this,e,t)})}get(e){return _d(this,e)}toArray(){return fd(this)}slice(e=0,t=this.length){return dd(this,e,t)}toJSON(){return this.map(e=>e instanceof ud?e.toJSON():e)}map(e){return hd(this,e)}forEach(e){md(this,e)}[Symbol.iterator](){return gd(this)}_write(e){e.writeTypeRef(Nf)}},Md=e=>new jd,Nd=class extends Qu{constructor(e,t,n){super(e,t),this.keysChanged=n}},Pd=class e extends ud{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 ud?e.clone():e)}),t}_callObserver(e,t){ld(this,e,new Nd(this,e,t))}toJSON(){this.doc??ed();let e={};return this._map.forEach((t,n)=>{if(!t.deleted){let r=t.content.getContent()[t.length-1];e[n]=r instanceof ud?r.toJSON():r}}),e}get size(){return[...kd(this)].length}keys(){return al(kd(this),e=>e[0])}values(){return al(kd(this),e=>e[1].content.getContent()[e[1].length-1])}entries(){return al(kd(this),e=>[e[0],e[1].content.getContent()[e[1].length-1]])}forEach(e){this.doc??ed(),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):Pu(this.doc,t=>{Cd(t,this,e)})}set(e,t){return this.doc===null?this._prelimContent.set(e,t):Pu(this.doc,n=>{wd(n,this,e,t)}),t}get(e){return Td(this,e)}has(e){return Dd(this,e)}clear(){this.doc===null?this._prelimContent.clear():Pu(this.doc,e=>{this.forEach(function(t,n,r){Cd(e,r,n)})})}_write(e){e.writeTypeRef(Pf)}},Fd=e=>new Pd,Id=(e,t)=>e===t||typeof e==`object`&&typeof t==`object`&&e&&t&&Ho(e,t),Ld=class{constructor(e,t,n,r){this.left=e,this.right=t,this.index=n,this.currentAttributes=r}forward(){switch(this.right===null&&no(),this.right.content.constructor){case Cf:this.right.deleted||Vd(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}},Rd=(e,t,n)=>{for(;t.right!==null&&n>0;){switch(t.right.content.constructor){case Cf:t.right.deleted||Vd(t.currentAttributes,t.right.content);break;default:t.right.deleted||(n<t.right.length&&Cu(e,X(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},zd=(e,t,n,r)=>{let i=new Map,a=r?sd(t,n):null;return a?Rd(e,new Ld(a.p.left,a.p,a.index,i),n-a.index):Rd(e,new Ld(null,t._start,0,i),n)},Bd=(e,t,n,r)=>{for(;n.right!==null&&(n.right.deleted===!0||n.right.content.constructor===Cf&&Id(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 qf(X(a,vu(i.store,a)),s,s&&s.lastId,c,c&&c.id,t,null,new Cf(o,r));l.integrate(e,0),n.right=l,n.forward()})},Vd=(e,t)=>{let{key:n,value:r}=t;r===null?e.delete(n):e.set(n,r)},Hd=(e,t)=>{for(;e.right!==null&&(e.right.deleted||e.right.content.constructor===Cf&&Id(t[e.right.content.key]??null,e.right.content.value));)e.forward()},Ud=(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(!Id(l,c)){o.set(s,l);let{left:r,right:u}=n;n.right=new qf(X(a,vu(i.store,a)),r,r&&r.lastId,u,u&&u.id,t,null,new Cf(s,c)),n.right.integrate(e,0),n.forward()}}return o},Wd=(e,t,n,r,i)=>{n.currentAttributes.forEach((e,t)=>{i[t]===void 0&&(i[t]=null)});let a=e.doc,o=a.clientID;Hd(n,i);let s=Ud(e,t,n,i),c=r.constructor===String?new Af(r):r instanceof ud?new Bf(r):new xf(r),{left:l,right:u,index:d}=n;t._searchMarker&&cd(t._searchMarker,n.index,c.getLength()),u=new qf(X(o,vu(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(),Bd(e,t,n,s)},Gd=(e,t,n,r,i)=>{let a=e.doc,o=a.clientID;Hd(n,i);let s=Ud(e,t,n,i);iterationLoop:for(;n.right!==null&&(r>0||s.size>0&&(n.right.deleted||n.right.content.constructor===Cf));){if(!n.right.deleted)switch(n.right.content.constructor){case Cf:{let{key:t,value:a}=n.right.content,o=i[t];if(o!==void 0){if(Id(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&&Cu(e,X(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+=`
|
|
3
3
|
`;n.right=new qf(X(o,vu(a.store,o)),n.left,n.left&&n.left.lastId,n.right,n.right&&n.right.id,t,null,new Af(i)),n.right.integrate(e,0),n.forward()}Bd(e,t,n,s)},Kd=(e,t,n,r,i)=>{let a=t,o=Fi();for(;a&&(!a.countable||a.deleted);){if(!a.deleted&&a.content.constructor===Cf){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 Cf:{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&&Vd(i,n);break}}}t=t.right}return s},qd=(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===Cf){let r=t.content.key;n.has(r)?t.delete(e):n.add(r)}t=t.left}},Jd=e=>{let t=0;return Pu(e.doc,n=>{let r=e._start,i=e._start,a=Fi(),o=Ii(a);for(;i;){if(i.deleted===!1)switch(i.content.constructor){case Cf:Vd(o,i.content);break;default:t+=Kd(n,r,i,a,o),a=Ii(o),r=i;break}i=i.right}}),t},Yd=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&&Eu(e,n.store.clients.get(r),a,i,e=>{!e.deleted&&e.content.constructor===Cf&&e.constructor!==pf&&t.add(e.parent)})}Pu(n,n=>{cl(e,e.deleteSet,e=>{if(e instanceof pf||!e.parent._hasFormatting||t.has(e.parent))return;let r=e.parent;e.content.constructor===Cf?t.add(r):qd(n,e)});for(let e of t)Jd(e)})},Xd=(e,t,n)=>{let r=n,i=Ii(t.currentAttributes),a=t.right;for(;n>0&&t.right!==null;){if(t.right.deleted===!1)switch(t.right.content.constructor){case Bf:case xf:case Af:n<t.right.length&&Cu(e,X(t.right.id.client,t.right.id.clock+n)),n-=t.right.length,t.right.delete(e);break}t.forward()}a&&Kd(e,a,t.right,i,t.currentAttributes);let o=(t.left||t.right).parent;return o._searchMarker&&cd(o._searchMarker,t.index,-r+n),t},Zd=class extends Qu{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=[];Pu(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},zo(o)||(e.attributes=Fo({},o))),c=0;break}e&&t.push(e),a=null}};for(;i!==null;){switch(i.content.constructor){case Bf:case xf: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 Af: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 Cf:{let{key:t,value:s}=i.content;if(this.adds(i))this.deletes(i)||(Id(n.get(t)??null,s)?s!==null&&i.delete(e):(a===`retain`&&u(),Id(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;Id(e,s)||(a===`retain`&&u(),o[t]=e)}else if(!i.deleted){r.set(t,s);let n=o[t];n!==void 0&&(Id(n,s)?n!==null&&i.delete(e):(a===`retain`&&u(),s===null?delete o[t]:o[t]=s))}i.deleted||(a===`insert`&&u(),Vd(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}},Qd=class e extends ud{constructor(e){super(),this._pending=e===void 0?[]:[()=>this.insert(0,e)],this._searchMarker=[],this._hasFormatting=!1}get length(){return this.doc??ed(),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 Zd(this,e,t);ld(this,e,n),!e.local&&this._hasFormatting&&(e._needFormattingCleanup=!0)}toString(){this.doc??ed();let e=``,t=this._start;for(;t!==null;)!t.deleted&&t.countable&&t.content.constructor===Af&&(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)):Pu(this.doc,n=>{let r=new Ld(null,this._start,0,new Map);for(let i=0;i<e.length;i++){let a=e[i];if(a.insert!==void 0){let o=!t&&typeof a.insert==`string`&&i===e.length-1&&r.right===null&&a.insert.slice(-1)===`
|
|
4
|
-
`?a.insert.slice(0,-1):a.insert;(typeof o!=`string`||o.length>0)&&Wd(n,this,r,o,a.attributes||{})}else a.retain===void 0?a.delete!==void 0&&Xd(n,r,a.delete):Gd(n,this,r,a.retain,a.attributes||{})}})}toDelta(e,t,n){this.doc??ed();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(mu(s,e)||t!==void 0&&mu(s,t))switch(s.content.constructor){case Af:{let r=i.get(`ychange`);e!==void 0&&!mu(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&&!mu(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 Bf:case xf:{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 Cf:mu(s,e)&&(c(),Vd(i,s.content));break}s=s.right}c()};return e||t?Pu(a,n=>{e&&hu(n,e),t&&hu(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)):Pu(r,r=>{let i=zd(r,this,e,!n);n||(n={},i.currentAttributes.forEach((e,t)=>{n[t]=e})),Wd(r,this,i,t,n)})}insertEmbed(e,t,n){let r=this.doc;r===null?this._pending.push(()=>this.insertEmbed(e,t,n||{})):Pu(r,r=>{let i=zd(r,this,e,!n);Wd(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)):Pu(n,n=>{Xd(n,zd(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)):Pu(r,r=>{let i=zd(r,this,e,!1);i.right!==null&&Gd(r,this,i,t,n)})}removeAttribute(e){this.doc===null?this._pending.push(()=>this.removeAttribute(e)):Pu(this.doc,t=>{Cd(t,this,e)})}setAttribute(e,t){this.doc===null?this._pending.push(()=>this.setAttribute(e,t)):Pu(this.doc,n=>{wd(n,this,e,t)})}getAttribute(e){return Td(this,e)}getAttributes(){return Ed(this)}_write(e){e.writeTypeRef(Ff)}},$d=e=>new Qd,ef=class{constructor(e,t=()=>!0){this._filter=t,this._root=e,this._currentNode=e._start,this._firstCall=!0,e.doc??ed()}[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===rf||t.constructor===tf)&&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})}},tf=class e extends ud{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 ud?e.clone():e)),t}get length(){return this.doc??ed(),this._prelimContent===null?this._length:this._prelimContent.length}createTreeWalker(e){return new ef(this,e)}querySelector(e){e=e.toUpperCase();let t=new ef(this,t=>t.nodeName&&t.nodeName.toUpperCase()===e).next();return t.done?null:t.value}querySelectorAll(e){return e=e.toUpperCase(),Ui(new ef(this,t=>t.nodeName&&t.nodeName.toUpperCase()===e))}_callObserver(e,t){ld(this,e,new of(this,t,e))}toString(){return hd(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),md(this,i=>{r.insertBefore(i.toDOM(e,t,n),null)}),r}insert(e,t){this.doc===null?this._prelimContent.splice(e,0,...t):Pu(this.doc,n=>{bd(n,this,e,t)})}insertAfter(e,t){if(this.doc!==null)Pu(this.doc,n=>{let r=e&&e instanceof ud?e._item:e;vd(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 eo(`Reference item not found`);n.splice(r,0,...t)}}delete(e,t=1){this.doc===null?this._prelimContent.splice(e,t):Pu(this.doc,n=>{Sd(n,this,e,t)})}toArray(){return fd(this)}push(e){this.insert(this.length,e)}unshift(e){this.insert(0,e)}get(e){return _d(this,e)}slice(e=0,t=this.length){return dd(this,e,t)}forEach(e){md(this,e)}_write(e){e.writeTypeRef(Lf)}},nf=e=>new tf,rf=class e extends tf{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 Lo(this.getAttributes(),(e,n)=>{t.setAttribute(n,e)}),t.insert(0,this.toArray().map(e=>e instanceof ud?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):Pu(this.doc,t=>{Cd(t,this,e)})}setAttribute(e,t){this.doc===null?this._prelimAttrs.set(e,t):Pu(this.doc,n=>{wd(n,this,e,t)})}getAttribute(e){return Td(this,e)}hasAttribute(e){return Dd(this,e)}getAttributes(e){return e?Od(this,e):Ed(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 md(this,i=>{r.appendChild(i.toDOM(e,t,n))}),n!==void 0&&n._createAssociation(r,this),r}_write(e){e.writeTypeRef(If),e.writeKey(this.nodeName)}},af=e=>new rf(e.readKey()),of=class extends Qu{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)})}},sf=class e extends Pd{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(Rf),e.writeKey(this.hookName)}},cf=e=>new sf(e.readKey()),lf=class e extends Qd{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(zf)}},uf=e=>new lf,df=class{constructor(e,t){this.id=e,this.length=t}get deleted(){throw to()}mergeWith(e){return!1}write(e,t,n){throw to()}integrate(e,t){throw to()}},ff=0,pf=class extends df{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),yu(e.doc.store,this)}write(e,t){e.writeInfo(ff),e.writeLen(this.length-t)}getMissing(e,t){return null}},mf=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 to()}mergeWith(e){return!1}integrate(e,t){}delete(e){}gc(e){}write(e,t){e.writeBuf(this.content)}getRef(){return 3}},hf=e=>new mf(e.readBuf()),gf=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){pl(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}},_f=e=>new gf(e.readLen()),vf=(e,t)=>new bl({guid:e,...t,shouldLoad:t.shouldLoad||t.autoLoad||!1}),yf=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(vf(this.doc.guid,this.opts))}splice(e){throw to()}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}},bf=e=>new yf(vf(e.readString(),e.readAny())),xf=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 to()}mergeWith(e){return!1}integrate(e,t){}delete(e){}gc(e){}write(e,t){e.writeJSON(this.embed)}getRef(){return 5}},Sf=e=>new xf(e.readJSON()),Cf=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 to()}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}},wf=e=>new Cf(e.readKey(),e.readJSON()),Tf=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}},Ef=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 Tf(n)},Df=ts(`node_env`)===`development`,Of=class e{constructor(e){this.arr=e,Df&&Wo(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}},kf=e=>{let t=e.readLen(),n=[];for(let r=0;r<t;r++)n.push(e.readAny());return new Of(n)},Af=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}},jf=e=>new Af(e.readString()),Mf=[Md,Fd,$d,af,nf,cf,uf],Nf=0,Pf=1,Ff=2,If=3,Lf=4,Rf=5,zf=6,Bf=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 to()}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}},Vf=e=>new Bf(Mf[e.readTypeRef()](e)),Hf=(e,t)=>{let n=t,r=0,i;do r>0&&(n=X(n.client,n.clock+r)),i=xu(e,n),r=n.clock-i.id.clock,n=i.redone;while(n!==null&&i instanceof qf);return{item:i,diff:r}},Uf=(e,t)=>{for(;e!==null&&e.keep!==t;)e.keep=t,e=e.parent._item},Wf=(e,t,n)=>{let{client:r,clock:i}=t.id,a=new qf(X(r,i+n),t,X(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=X(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},Gf=(e,t)=>Gi(e,e=>ul(e.deletions,t)),Kf=(e,t,n,r,i,a)=>{let o=e.doc,s=o.store,c=o.clientID,l=t.redone;if(l!==null)return Cu(e,l);let u=t.parent._item,d=null,f;if(u!==null&&u.deleted===!0){if(u.redone===null&&(!n.has(u)||Kf(e,u,n,r,i,a)===null))return null;for(;u.redone!==null;)u=Cu(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:Cu(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:Cu(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||ul(r,d.right.id)||Gf(a.undoStack,d.right.id)||Gf(a.redoStack,d.right.id));)for(d=d.right;d.redone;)d=Cu(e,d.redone);if(d&&d.right!==null)return null}else d=p._map.get(t.parentSub)||null;let m=X(c,vu(s,c)),h=new qf(m,d,d&&d.lastId,f,f&&f.id,p,t.parentSub,t.content.copy());return t.redone=m,Uf(h,!0),h.integrate(e,0),h},qf=class e extends df{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>=vu(n,this.origin.client))return this.origin.client;if(this.rightOrigin&&this.rightOrigin.client!==this.id.client&&this.rightOrigin.clock>=vu(n,this.rightOrigin.client))return this.rightOrigin.client;if(this.parent&&this.parent.constructor===Zl&&this.id.client!==this.parent.client&&this.parent.clock>=vu(n,this.parent.client))return this.parent.client;if(this.origin&&=(this.left=wu(t,n,this.origin),this.left.lastId),this.rightOrigin&&=(this.right=Cu(t,this.rightOrigin),this.right.id),this.left&&this.left.constructor===pf||this.right&&this.right.constructor===pf)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===Zl){let e=xu(n,this.parent);e.constructor===pf?this.parent=null:this.parent=e.content.type}return null}integrate(e,t){if(t>0&&(this.id.clock+=t,this.left=wu(e,e.doc.store,X(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),Ql(this.origin,n.origin)){if(n.id.client<this.id.client)t=n,r.clear();else if(Ql(this.rightOrigin,n.rightOrigin))break}else if(n.origin!==null&&i.has(xu(e.doc.store,n.origin)))r.has(xu(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),yu(e.doc.store,this),this.content.integrate(e,this),ku(e,this.parent,this.parentSub),(this.parent._item!==null&&this.parent._item.deleted||this.parentSub!==null&&this.right!==null)&&this.delete(e)}else new pf(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:X(this.id.client,this.id.clock+this.length-1)}mergeWith(e){if(this.constructor===e.constructor&&Ql(e.origin,this.lastId)&&this.right===e&&Ql(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(),pl(e.deleteSet,this.id.client,this.id.clock,this.length),ku(e,t,this.parentSub),this.content.delete(e)}}gc(e,t){if(!this.deleted)throw no();this.content.gc(e),t?Tu(e,this,new pf(this.id,this.length)):this.content=new gf(this.length)}write(e,t){let n=t>0?X(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=$l(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===Zl?(e.writeParentInfo(!1),e.writeLeftID(t)):no();i!==null&&e.writeString(i)}this.content.write(e,t)}},Jf=(e,t)=>Yf[t&31](e),Yf=[()=>{no()},_f,Ef,hf,jf,Sf,wf,Vf,kf,bf,()=>{no()}],Xf=10,Zf=class extends df{get deleted(){return!0}delete(){}mergeWith(e){return this.constructor===e.constructor?(this.length+=e.length,!0):!1}integrate(e,t){no()}write(e,t){e.writeInfo(Xf),J(e.restEncoder,this.length-t)}getMissing(e,t){return null}},Qf=typeof globalThis<`u`?globalThis:typeof window<`u`?window:typeof global<`u`?global:{},$f=`__ $YJS$ __`;Qf[$f]===!0&&console.error(`Yjs was already imported. This breaks constructor checks and will lead to issues! - https://github.com/yjs/yjs/issues/438`),Qf[$f]=!0;var ep=()=>{let e=!0;return(t,n)=>{if(e){e=!1;try{t()}finally{e=!0}}else n!==void 0&&n()}},tp=/[\uD800-\uDBFF]/,np=/[\uDC00-\uDFFF]/,rp=(e,t)=>{let n=0,r=0;for(;n<e.length&&n<t.length&&e[n]===t[n];)n++;for(n>0&&tp.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&&np.test(e[e.length-r])&&r--,{index:n,remove:e.length-n-r,insert:t.slice(n,t.length-r)}},ip=(e,t)=>e>>>t|e<<32-t,ap=e=>ip(e,2)^ip(e,13)^ip(e,22),op=e=>ip(e,6)^ip(e,11)^ip(e,25),sp=e=>ip(e,7)^ip(e,18)^e>>>3,cp=e=>ip(e,17)^ip(e,19)^e>>>10,lp=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]),up=new Uint32Array([1779033703,3144134277,1013904242,2773480762,1359893119,2600822924,528734635,1541459225]),dp=class{constructor(){let e=new ArrayBuffer(320);this._H=new Uint32Array(e,0,8),this._H.set(up),this._W=new Uint32Array(e,64,64)}_updateHash(){let e=this._H,t=this._W;for(let e=16;e<64;e++)t[e]=cp(t[e-2])+t[e-7]+sp(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+op(o)+(o&s^~o&c)+lp[e]+t[e]>>>0,d=ap(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/fa,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}},fp=e=>new dp().digest(e),pp=new H(`y-sync`),mp=new H(`y-undo`),hp=new H(`yjs-cursor`),gp=e=>{for(let t=6;t<e.length;t++)e[t%6]=e[t%6]^e[t];return e.slice(0,6)},_p=e=>os(gp(fp(cs(e)))),vp=(e,t)=>t===void 0?!e.deleted:t.sv.has(e.id.client)&&t.sv.get(e.id.client)>e.id.clock&&!ul(t.ds,e.id),yp=[{light:`#ecd44433`,dark:`#ecd444`}],bp=(e,t,n)=>{if(!e.has(n)){if(e.size<t.length){let n=Bi();e.forEach(e=>n.add(e)),t=t.filter(e=>!n.has(e))}e.set(n,wo(t))}return e.get(n)},xp=(e,{colors:t=yp,colorMapping:n=new Map,permanentUserData:r=null,onFirstRender:i=()=>{},mapping:a}={})=>{let o=!1,s=new Tp(e,a),c=new M({props:{editable:e=>{let t=pp.getState(e);return t.snapshot==null&&t.prevSnapshot==null}},key:pp,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(pp);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)&&Bc(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=mp.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)},pp)})}},destroy:()=>{s.destroy()}})});return c},Sp=(e,t,n)=>{if(t!==null&&t.anchor!==null&&t.head!==null)if(t.type===`all`)e.setSelection(new _(e.doc));else if(t.type===`node`){let r=em(n.doc,n.type,t.anchor,n.mapping);e.setSelection(Cp(e,r))}else{let r=em(n.doc,n.type,t.anchor,n.mapping),i=em(n.doc,n.type,t.head,n.mapping);r!==null&&i!==null&&e.setSelection(O.between(e.doc.resolve(r),e.doc.resolve(i)))}},Cp=(e,t)=>{let n=e.doc.resolve(t);return n.nodeAfter?h.create(e.doc,t):O.near(n)},wp=(e,t)=>({type:t.selection.jsonID,anchor:Qp(t.selection.anchor,e.type,e.mapping),head:Qp(t.selection.head,e.type,e.mapping)}),Tp=class{constructor(e,t=new Map){this.type=e,this.prosemirrorView=null,this.mux=ep(),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=wp(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()?(Xo&&this._domSelectionInView===null&&(Bc(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=wc.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||=fu(ml(),new Map),this.prosemirrorView.dispatch(this._tr.setMeta(pp,{snapshot:e,prevSnapshot:t}))}unrenderSnapshot(){this.mapping.clear(),this.mux(()=>{let e=this.type.toArray().map(e=>Dp(e,this.prosemirrorView.state.schema,this)).filter(e=>e!==null),t=this._tr.replace(0,this.prosemirrorView.state.doc.content.size,new w(P.from(e),0,0));t.setMeta(pp,{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=>Dp(e,this.prosemirrorView.state.schema,this)).filter(e=>e!==null),n=this._tr.replace(0,this.prosemirrorView.state.doc.content.size,new w(P.from(t),0,0));if(e){let t=Zi(Qi(e.anchor,0),n.doc.content.size),r=Zi(Qi(e.head,0),n.doc.content.size);n.setSelection(O.create(n.doc,t,r))}this.prosemirrorView.dispatch(n.setMeta(pp,{isChangeOrigin:!0,binding:this}))})}_renderSnapshot(e,t,n){let r=this.doc,i=this.type;if(e||=pu(this.doc),e instanceof Uint8Array||t instanceof Uint8Array)if((!(e instanceof Uint8Array)||!(t instanceof Uint8Array))&&no(),r=new bl({gc:!1}),Fl(r,t),t=pu(r),Fl(r,e),e=pu(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[bu(e,i._item.id.clock)].content.type}this.mapping.clear(),this.mux(()=>{r.transact(r=>{let a=n.permanentUserData;a&&a.dss.forEach(e=>{cl(r,e,e=>{})});let o=(e,t)=>{let r=e===`added`?a.getUserByClientId(t.client):a.getUserByDeletedId(t);return{user:r,type:e,color:bp(n.colorMapping,n.colors,r)}},s=pd(i,new du(t.ds,e.sv)).map(n=>!n._item.deleted||vp(n._item,e)||vp(n._item,t)?Dp(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 w(P.from(s),0,0));this.prosemirrorView.dispatch(c.setMeta(pp,{isChangeOrigin:!0}))},pp)})}_typeChanged(e,t){if(this.prosemirrorView==null)return;let n=pp.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);cl(t,t.deleteSet,e=>{if(e.constructor===qf){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=>Ep(e,this.prosemirrorView.state.schema,this)).filter(e=>e!==null),r=this._tr.replace(0,this.prosemirrorView.state.doc.content.size,new w(P.from(n),0,0));Sp(r,this.beforeTransactionSelection,this),r=r.setMeta(pp,{isChangeOrigin:!0,isUndoRedoOperation:t.origin instanceof Ru}),this.beforeTransactionSelection!==null&&this._isLocalCursorInView()&&r.scrollIntoView(),this.prosemirrorView.dispatch(r)})}_prosemirrorChanged(e){this.doc.transact(()=>{Gp(this.doc,this.type,e,this),this.beforeTransactionSelection=wp(this,this.prosemirrorView.state)},pp)}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))}},Ep=(e,t,n,r,i,a)=>{let o=n.mapping.get(e);if(o===void 0){if(e instanceof rf)return Dp(e,t,n,r,i,a);throw to()}return o},Dp=(e,t,n,r,i,a)=>{let o=[],s=e=>{if(e instanceof rf){let s=Ep(e,t,n,r,i,a);s!==null&&o.push(s)}else{let s=e._item.right?.content?.type;s instanceof Qd&&!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=Op(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):pd(e,new du(i.ds,r.sv)).forEach(s);try{let s=e.getAttributes(r);r!==void 0&&(vp(e._item,r)?vp(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}},Op=(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,Up(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},kp=(e,t)=>{let n=new lf,r=e.map(e=>({insert:e.text,attributes:Wp(e.marks,t)}));return n.applyDelta(r),t.mapping.set(n,e),n},Ap=(e,t)=>{let n=new rf(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,Pp(e).map(e=>jp(e,t))),t.mapping.set(n,e),n},jp=(e,t)=>e instanceof Array?kp(e,t):Ap(e,t),Mp=e=>typeof e==`object`&&!!e,Np=(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||Mp(o)&&Mp(s)&&Np(o,s)}return r},Pp=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},Fp=(e,t)=>{let n=e.toDelta();return n.length===t.length&&n.every((e,n)=>e.insert===t[n].text&&Io(e.attributes||{}).length===t[n].marks.length&&Bo(e.attributes,(e,r)=>{let i=Hp(r),a=t[n].marks;return a.find(e=>e.type.name===i)?Np(e,a.find(e=>e.type.name===i)?.attrs):!1}))},Ip=(e,t)=>{if(e instanceof rf&&!(t instanceof Array)&&Kp(e,t)){let n=Pp(t);return e._length===n.length&&Np(e.getAttributes(),t.attrs)&&e.toArray().every((e,t)=>Ip(e,n[t]))}return e instanceof lf&&t instanceof Array&&Fp(e,t)},Lp=(e,t)=>e===t||e instanceof Array&&t instanceof Array&&e.length===t.length&&e.every((e,n)=>t[n]===e),Rp=(e,t,n)=>{let r=e.toArray(),i=Pp(t),a=i.length,o=r.length,s=Zi(o,a),c=0,l=0,u=!1;for(;c<s;c++){let e=r[c],t=i[c];if(Lp(n.mapping.get(e),t))u=!0;else if(!Ip(e,t))break}for(;c+l<s;l++){let e=r[o-l-1],t=i[a-l-1];if(Lp(n.mapping.get(e),t))u=!0;else if(!Ip(e,t))break}return{equalityFactor:c+l,foundMappedChild:u}},zp=e=>{let t=``,n=e._start,r={};for(;n!==null;)n.deleted||(n.countable&&n.content instanceof Af?t+=n.content.str:n.content instanceof Cf&&(r[n.content.key]=null)),n=n.right;return{str:t,nAttrs:r}},Bp=(e,t,n)=>{n.mapping.set(e,t);let{nAttrs:r,str:i}=zp(e),a=t.map(e=>({insert:e.text,attributes:Object.assign({},r,Wp(e.marks,n))})),{insert:o,remove:s,index:c}=rp(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})))},Vp=/(.*)(--[a-zA-Z0-9+/=]{8})$/,Hp=e=>Vp.exec(e)?.[1]??e,Up=(e,t)=>{let n=[];for(let r in e)n.push(t.mark(Hp(r),e[r]));return n},Wp=(e,t)=>{let n={};return e.forEach(e=>{if(e.type.name!==`ychange`){let r=Li(t.isOMark,e.type,()=>!e.type.excludes(e.type));n[r?`${e.type.name}--${_p(e.toJSON())}`:e.type.name]=e.attrs}}),n},Gp=(e,t,n,r)=>{if(t instanceof rf&&t.nodeName!==n.type.name)throw Error(`node name mismatch!`);if(r.mapping.set(t,n),t instanceof rf){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=Pp(n),a=i.length,o=t.toArray(),s=o.length,c=Zi(a,s),l=0,u=0;for(;l<c;l++){let e=o[l],t=i[l];if(!Lp(r.mapping.get(e),t))if(Ip(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(!Lp(r.mapping.get(e),t))if(Ip(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 lf&&c instanceof Array)Fp(n,c)||Bp(n,c,r),l+=1;else{let i=n instanceof rf&&Kp(n,c),a=d instanceof rf&&Kp(d,f);if(i&&a){let e=Rp(n,c,r),t=Rp(d,f,r);e.foundMappedChild&&!t.foundMappedChild?a=!1:!e.foundMappedChild&&t.foundMappedChild||e.equalityFactor<t.equalityFactor?i=!1:a=!1}i?(Gp(e,n,c,r),l+=1):a?(Gp(e,d,f,r),u+=1):(r.mapping.delete(t.get(l)),t.delete(l,1),t.insert(l,[jp(c,r)]),l+=1)}}let n=s-l-u;if(s===1&&a===0&&o[0]instanceof lf?(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(jp(i[t],r));t.insert(l,e)}},pp)},Kp=(e,t)=>!(t instanceof Array)&&e.nodeName===t.type.name,qp=null,Jp=class{constructor(e,t,n){this.view=e,this.key=t,this.value=n}apply(){let e=pp.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)}}},Yp=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=qp;qp=null;let n=[];return t.forEach((e,t)=>{e.forEach((e,r)=>{n.push(new Jp(t,r,e))})}),new e(n)}},Xp=(e=Yp.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()||Bc(0,()=>Xp(e,!0));return}throw r}n=!1,e.dequeueFirst()}},Zp=(e,t,n)=>{qp||(qp=new Map,Bc(0,Xp)),Li(qp,e,Fi).set(t,n)},Qp=(e,t,n)=>{if(e===0)return su(t,0,-1);let r=t._first===null?null:t._first.content.type;for(;r!==null&&t!==r;){if(r instanceof lf){if(r._length>=e)return su(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 tu(r._item===null?null:r._item.id,r._item===null?$l(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 tu(r._item===null?null:r._item.id,r._item===null?$l(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 no();if(e===0&&r.constructor!==lf&&r!==t)return $p(r._item.parent,r._item)}return su(t,t._length,-1)},$p=(e,t)=>{let n=null,r=null;return e._item===null?r=$l(e):n=X(e._item.id.client,e._item.id.clock),new tu(n,r,t.id)},em=(e,t,n,r)=>{let i=lu(n,e);if(i===null||i.type!==t&&!eu(t,i.type._item))return null;let a=i.type,o=0;if(a.constructor===lf)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 lf?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 lf?o+=e._length:o+=r.get(e).nodeSize),t=t.right}}a=e}return o-1},tm=(e,t,n)=>e!==t,nm=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},rm=e=>({style:`background-color: ${e.color}70`,class:`ProseMirror-yjs-selection`}),im=/^#[0-9a-fA-F]{6}$/,am=(e,t,n,r,i)=>{let a=pp.getState(e);if(a==null||a.doc==null||a.binding==null)return L.create(e.doc,[]);let o=a.doc,s=[];return a.snapshot!=null||a.prevSnapshot!=null||a.binding.mapping.size===0?L.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`:im.test(n.color)||console.warn(`A user uses an unsupported color format`,n),n.name??=`User: ${c}`;let l=em(o,a.type,ru(t.cursor.anchor),a.binding.mapping),u=em(o,a.type,ru(t.cursor.head),a.binding.mapping);if(l!==null&&u!==null){let t=Qi(e.doc.content.size-1,0);l=Zi(l,t),u=Zi(u,t),s.push(Ae.widget(u,()=>r(n,c),{key:c+``,side:10}));let a=Zi(l,u),o=Qi(l,u);s.push(Ae.inline(a,o,i(n,c),{inclusiveEnd:!0,inclusiveStart:!1}))}}}),L.create(e.doc,s))},om=(e,{awarenessStateFilter:t=tm,cursorBuilder:n=nm,selectionBuilder:r=rm,getSelection:i=e=>e.selection}={},a=`cursor`)=>new M({key:hp,state:{init(i,a){return am(a,e,t,n,r)},apply(i,a,o,s){let c=pp.getState(s),l=i.getMeta(hp);return c&&c.isChangeOrigin||l&&l.awarenessUpdated?am(s,e,t,n,r):a.map(i.mapping,i.doc)}},props:{decorations:e=>hp.getState(e)},view:t=>{let n=()=>{t.docView&&Zp(t,hp,{awarenessUpdated:!0})},r=()=>{let n=pp.getState(t.state),r=e.getLocalState()||{};if(t.hasFocus()){let o=i(t.state),s=Qp(o.anchor,n.type,n.binding.mapping),c=Qp(o.head,n.type,n.binding.mapping);(r.cursor==null||!uu(ru(r.cursor.anchor),s)||!uu(ru(r.cursor.head),c))&&e.setLocalStateField(a,{anchor:s,head:c})}else r.cursor!=null&&em(n.doc,n.type,ru(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)}}}}),sm=e=>{let t=mp.getState(e).undoManager;if(t!=null)return t.undo(),!0},cm=e=>{let t=mp.getState(e).undoManager;if(t!=null)return t.redo(),!0},lm=new Set([`paragraph`]),um=(e,t)=>!(e instanceof qf)||!(e.content instanceof Bf)||!(e.content.type instanceof Qd||e.content.type instanceof rf&&t.has(e.content.type.nodeName))||e.content.type._length===0,dm=({protectedNodes:e=lm,trackedOrigins:t=[],undoManager:n=null}={})=>new M({key:mp,state:{init:(r,i)=>{let a=pp.getState(i),o=n||new Ru(a.type,{trackedOrigins:new Set([pp].concat(t)),deleteFilter:t=>um(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=pp.getState(r).binding,a=t.undoManager,o=a.undoStack.length>0,s=a.redoStack.length>0;return i?{undoManager:a,prevSel:wp(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=pp.getState(e.state),n=mp.getState(e.state).undoManager;return n.on(`stack-item-added`,({stackItem:n})=>{let r=t.binding;r&&n.meta.set(r,mp.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()}}}});async function fm(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 pm(e){return typeof e==`object`&&!!e}function mm(e){return e===`files`||e===`backlinks`||e===`graph`||e===`sync-status`}function hm(e){let t;try{t=JSON.parse(e)}catch{return null}return!pm(t)||t.v!==1||!mm(t.ch)||typeof t.seq!=`number`?null:{v:1,ch:t.ch,seq:t.seq}}function gm(){return typeof location>`u`?`ws://localhost/collab`:`${location.protocol===`https:`?`wss`:`ws`}://${location.host}/collab`}function _m(e){if(e===void 0)return null;let t=e.okDesktop;return!t||!t.config.collabUrl||t.config.collabUrl.length===0?null:t}function vm(e){return{collabUrl:e.collabUrl,attempts:0,terminal:!1,lastError:null}}var ym=2e3,bm=15e3;function xm(e){let t=e.terminalAfterMs??3e4,n=e.initialDelayMs??ym,r=e.maxDelayMs??bm,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 Sm(){let e=(0,rr.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,G.useState)(t),i;e[1]===Symbol.for(`react.memo_cache_sentinel`)?(i={token:0},e[1]=i):i=e[1];let a=(0,G.useRef)(i),[o,s]=(0,G.useState)(0),c;e[2]===Symbol.for(`react.memo_cache_sentinel`)?(c=()=>{let e=a.current.token=a.current.token+1,t=_m(typeof window<`u`?window:void 0);if(t){r(vm(t.config));let n=t.onProjectSwitched(t=>{e===a.current.token&&r(vm(t))});return()=>{n()}}let n=xm({fetchConfig:fm,fallbackUrl:gm,now:Date.now,setTimeout:Em,clearTimeout:Tm,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,G.useEffect)(c,l);let u;e[5]===Symbol.for(`react.memo_cache_sentinel`)?(u=()=>{a.current.token=a.current.token+1,r(wm),s(Cm)},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 Cm(e){return e+1}function wm(e){return{...e,terminal:!1,lastError:null}}function Tm(e){return globalThis.clearTimeout(e)}function Em(e,t){return globalThis.setTimeout(e,t)}var Dm=Math.floor,Om=(e,t)=>e<t?e:t,km=(e,t)=>e>t?e:t;Number.isNaN;var Am=128,jm=1<<17,Mm=1<<18,Nm=1<<19,Pm=1<<20,Fm=1<<21,Im=1<<22,Lm=1<<23,Rm=1<<24,zm=1<<25,Bm=1<<26,Vm=1<<27,Hm=1<<28,Um=1<<29,Wm=1<<30,Gm=127;jm-1,Mm-1,Nm-1,Pm-1,Fm-1,Im-1,Lm-1,Rm-1,zm-1,Bm-1,Vm-1,Hm-1,Um-1,Wm-1;var Km=2**53-1;Number.isInteger,Number.isNaN,Number.parseInt;var qm=String.fromCharCode;String.fromCodePoint,qm(65535);var Jm=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},Ym=typeof TextEncoder<`u`?new TextEncoder:null,Xm=Ym?e=>Ym.encode(e):Jm,Zm=typeof TextDecoder>`u`?null:new TextDecoder(`utf-8`,{fatal:!0,ignoreBOM:!0});Zm&&Zm.decode(new Uint8Array).length===1&&(Zm=null);var Qm=(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},$m=(e,t)=>{for(;t>Gm;)Qm(e,Am|Gm&t),t=Dm(t/128);Qm(e,Gm&t)},eh=new Uint8Array(3e4),th=eh.length/3,nh=Ym&&Ym.encodeInto?(e,t)=>{if(t.length<th){let n=Ym.encodeInto(t,eh).written||0;$m(e,n);for(let t=0;t<n;t++)Qm(e,eh[t])}else ih(e,Xm(t))}:(e,t)=>{let n=unescape(encodeURIComponent(t)),r=n.length;$m(e,r);for(let t=0;t<r;t++)Qm(e,n.codePointAt(t))},rh=(e,t)=>{let n=e.cbuf.length,r=e.cpos,i=Om(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(km(n*2,a)),e.cbuf.set(t.subarray(i)),e.cpos=a)},ih=(e,t)=>{$m(e,t.byteLength),rh(e,t)},ah=e=>Error(e),oh=ah(`Unexpected end of array`),sh=ah(`Integer out of Range`),ch=(e,t)=>{let n=new Uint8Array(e.arr.buffer,e.pos+e.arr.byteOffset,t);return e.pos+=t,n},lh=e=>ch(e,dh(e)),uh=e=>e.arr[e.pos++],dh=e=>{let t=0,n=1,r=e.arr.length;for(;e.pos<r;){let r=e.arr[e.pos++];if(t+=(r&Gm)*n,n*=128,r<Am)return t;if(t>Km)throw sh}throw oh},fh=Zm?e=>Zm.decode(lh(e)):e=>{let t=dh(e);if(t===0)return``;{let n=String.fromCodePoint(uh(e));if(--t<100)for(;t--;)n+=String.fromCodePoint(uh(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))}},ph=function(e){return e[e.Token=0]=`Token`,e[e.PermissionDenied=1]=`PermissionDenied`,e[e.Authenticated=2]=`Authenticated`,e}({}),mh=(e,t)=>{$m(e,ph.Token),nh(e,t)},hh=(e,t,n,r)=>{switch(dh(e)){case ph.Token:t();break;case ph.PermissionDenied:n(fh(e));break;case ph.Authenticated:r(fh(e));break;default:}},gh=e=>Array.from(e.entries()).map(([e,t])=>({clientId:e,...t})),_h=`\0`;function vh(e,t){return e+_h+t}function yh(e){let t=e.indexOf(_h);return t===-1?{documentName:e,sessionId:null}:{documentName:e.substring(0,t),sessionId:e.substring(t+1)}}var bh=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 xh(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 Sh(e){return new Promise(t=>setTimeout(t,e))}function Ch(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 wh(e,t){let n=xh(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||Ch;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 Sh(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 Sh(o),r.attemptNum<1&&n.initialJitter){let e=i(r,n);e&&await Sh(e)}return a()}var Th=Math.floor,Eh=(e,t)=>e<t?e:t,Dh=(e,t)=>e>t?e:t;Number.isNaN;var Oh=64,kh=128,Ah=1<<17,jh=1<<18,Mh=1<<19,Nh=1<<20,Ph=1<<21,Fh=1<<22,Ih=1<<23,Lh=1<<24,Rh=1<<25,zh=1<<26,Bh=1<<27,Vh=1<<28,Hh=1<<29,Uh=1<<30,Wh=63,Gh=127;Ah-1,jh-1,Mh-1,Nh-1,Ph-1,Fh-1,Ih-1,Lh-1,Rh-1,zh-1,Bh-1,Vh-1,Hh-1,Uh-1;var Kh=2**53-1;Number.isInteger,Number.isNaN,Number.parseInt;var qh=()=>new Set,Jh=Array.from;Array.isArray;var Yh=String.fromCharCode;String.fromCodePoint,Yh(65535);var Xh=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},Zh=typeof TextEncoder<`u`?new TextEncoder:null,Qh=Zh?e=>Zh.encode(e):Xh,$h=typeof TextDecoder>`u`?null:new TextDecoder(`utf-8`,{fatal:!0,ignoreBOM:!0});$h&&$h.decode(new Uint8Array).length===1&&($h=null);var eg=class{constructor(){this.cpos=0,this.cbuf=new Uint8Array(100),this.bufs=[]}},tg=()=>new eg,ng=e=>{let t=e.cpos;for(let n=0;n<e.bufs.length;n++)t+=e.bufs[n].length;return t},rg=e=>{let t=new Uint8Array(ng(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},ig=(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},ag=(e,t)=>{for(;t>Gh;)ig(e,kh|Gh&t),t=Th(t/128);ig(e,Gh&t)},og=new Uint8Array(3e4),sg=og.length/3,cg=Zh&&Zh.encodeInto?(e,t)=>{if(t.length<sg){let n=Zh.encodeInto(t,og).written||0;ag(e,n);for(let t=0;t<n;t++)ig(e,og[t])}else ug(e,Qh(t))}:(e,t)=>{let n=unescape(encodeURIComponent(t)),r=n.length;ag(e,r);for(let t=0;t<r;t++)ig(e,n.codePointAt(t))},lg=(e,t)=>{let n=e.cbuf.length,r=e.cpos,i=Eh(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(Dh(n*2,a)),e.cbuf.set(t.subarray(i)),e.cpos=a)},ug=(e,t)=>{ag(e,t.byteLength),lg(e,t)},dg=e=>Error(e),fg=dg(`Unexpected end of array`),pg=dg(`Integer out of Range`),mg=class{constructor(e){this.arr=e,this.pos=0}},hg=e=>new mg(e),gg=(e,t)=>{let n=new Uint8Array(e.arr.buffer,e.pos+e.arr.byteOffset,t);return e.pos+=t,n},_g=e=>gg(e,yg(e)),vg=e=>e.arr[e.pos++],yg=e=>{let t=0,n=1,r=e.arr.length;for(;e.pos<r;){let r=e.arr[e.pos++];if(t+=(r&Gh)*n,n*=128,r<kh)return t;if(t>Kh)throw pg}throw fg},bg=e=>{let t=e.arr[e.pos++],n=t&Wh,r=64,i=(t&Oh)>0?-1:1;if((t&kh)===0)return i*n;let a=e.arr.length;for(;e.pos<a;){if(t=e.arr[e.pos++],n+=(t&Gh)*r,r*=128,t<kh)return i*n;if(n>Kh)throw pg}throw fg},xg=$h?e=>$h.decode(_g(e)):e=>{let t=yg(e);if(t===0)return``;{let n=String.fromCodePoint(vg(e));if(--t<100)for(;t--;)n+=String.fromCodePoint(vg(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))}},Sg=e=>{let t=e.pos,n=xg(e);return e.pos=t,n},Cg=Date.now,wg=()=>new Map,Tg=(e,t,n)=>{let r=e.get(t);return r===void 0&&e.set(t,r=n()),r},Eg=class{constructor(){this._observers=wg()}on(e,t){Tg(this._observers,e,qh).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 Jh((this._observers.get(e)||wg()).values()).forEach(e=>e(...t))}destroy(){this._observers=wg()}},Dg=Symbol(`Equality`),Og=Object.keys,kg=e=>Og(e).length,Ag=(e,t)=>Object.prototype.hasOwnProperty.call(e,t),jg=(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[Dg]!=null)return e[Dg](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)||!jg(e.get(n),t.get(n)))return!1;break;case void 0:case Object:if(kg(e)!==kg(t))return!1;for(let n in e)if(!Ag(e,n)||!jg(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(!jg(e[n],t[n]))return!1;break;default:return!1}return!0},Mg=3e4,Ng=class extends Eg{constructor(e){super(),this.doc=e,this.clientID=e.clientID,this.states=new Map,this.meta=new Map,this._checkInterval=setInterval(()=>{let e=Cg();this.getLocalState()!==null&&Mg/2<=e-this.meta.get(this.clientID).lastUpdated&&this.setLocalState(this.getLocalState());let t=[];this.meta.forEach((n,r)=>{r!==this.clientID&&Mg<=e-n.lastUpdated&&this.states.has(r)&&t.push(r)}),t.length>0&&Pg(this,t,`timeout`)},Th(Mg/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:Cg()});let a=[],o=[],s=[],c=[];e===null?c.push(t):i==null?e!=null&&a.push(t):(o.push(t),jg(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}},Pg=(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:Cg()})}r.push(i)}}r.length>0&&(e.emit(`change`,[{added:[],updated:[],removed:r},n]),e.emit(`update`,[{added:[],updated:[],removed:r},n]))},Fg=(e,t,n=e.states)=>{let r=t.length,i=tg();ag(i,r);for(let a=0;a<r;a++){let r=t[a],o=n.get(r)||null,s=e.meta.get(r).clock;ag(i,r),ag(i,s),cg(i,JSON.stringify(o))}return rg(i)},Ig=(e,t,n)=>{let r=hg(t),i=Cg(),a=[],o=[],s=[],c=[],l=yg(r);for(let t=0;t<l;t++){let t=yg(r),n=yg(r),l=JSON.parse(xg(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&&(jg(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])},Lg=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={}}},Rg=class{constructor(e){this.data=e,this.encoder=tg(),this.decoder=hg(new Uint8Array(this.data))}peekVarString(){return Sg(this.decoder)}readVarUint(){return yg(this.decoder)}readVarString(){return xg(this.decoder)}readVarUint8Array(){return _g(this.decoder)}writeVarUint(e){return ag(this.encoder,e)}writeVarString(e){return cg(this.encoder,e)}writeVarUint8Array(e){return ug(this.encoder,e)}length(){return ng(this.encoder)}},zg=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}({}),Bg=function(e){return e.Connecting=`connecting`,e.Connected=`connected`,e.Disconnected=`disconnected`,e}({}),Vg=class{constructor(){this.encoder=tg()}get(e){return e.encoder}toUint8Array(){return rg(this.encoder)}},Hg=class extends Vg{constructor(...e){super(...e),this.type=zg.CLOSE,this.description=`Ask the server to close the connection`}get(e){return cg(this.encoder,e.documentName),ag(this.encoder,this.type),this.encoder}},Ug=class e extends Lg{static{this.DEDUPLICATABLE_TYPES=new Set([zg.Awareness,zg.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=Bg.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=Bg.Connected,this.emit(`status`,{status:Bg.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===Bg.Disconnected&&this.shouldConnect&&this.connect(),this.receivedOnOpenPayload&&this.status===Bg.Connected&&e.onOpen(this.receivedOnOpenPayload)}detach(e){let t=e.effectiveName;this.configuration.providerMap.has(t)&&(e.send(Hg,{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===Bg.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:wh(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=Bg.Connecting,this.emit(`status`,{status:Bg.Connecting}),this.connectionAttempt={resolve:e,reject:t}})}onMessage(e){this.resolveConnectionAttempt(),this.lastMessageReceived=Cg();let t=new Uint8Array(e.data);if(t.length===1&&t[0]===zg.Ping){this.sendPong();return}let n=new Rg(t).peekVarString();this.configuration.providerMap.get(n)?.onMessage(e)}sendPong(){let e=tg();ag(e,zg.Pong),this.send(rg(e))}resolveConnectionAttempt(){this.connectionAttempt&&(this.connectionAttempt.resolve(),this.connectionAttempt=null,this.status=Bg.Connected,this.emit(`status`,{status:Bg.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===Bg.Connected&&this.lastMessageReceived&&(this.configuration.messageReconnectTimeout>=Cg()-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=hg(e);return{documentName:xg(t),messageType:yg(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===bh.Open?this.webSocket.send(e):this.addToQueue(e)}onClose({event:e}){this.closeTries=0,this.cleanupWebSocket(),this.connectionAttempt&&this.rejectConnectionAttempt(),this.status=Bg.Disconnected,this.emit(`status`,{status:Bg.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()}},Wg=0,Gg=1,Kg=2,qg=(e,t)=>{ag(e,Wg),ug(e,Gl(t))},Jg=(e,t,n)=>{ag(e,Gg),ug(e,zl(t,n))},Yg=(e,t,n)=>Jg(t,n,_g(e)),Xg=(e,t,n,r)=>{try{Il(t,_g(e),n)}catch(e){r?.(e),console.error(`Caught error while handling a Yjs update`,e)}},Zg=(e,t)=>{ag(e,Kg),ug(e,t)},Qg=Xg,$g=(e,t,n,r,i)=>{let a=yg(e);switch(a){case Wg:Yg(e,t,n);break;case Gg:Xg(e,n,r,i);break;case Kg:Qg(e,n,r,i);break;default:throw Error(`Unknown message type`)}return a},e_=class{constructor(e){this.message=e}apply(e,t){let{message:n}=this,r=n.readVarUint(),i=n.length();switch(r){case zg.Sync:this.applySyncMessage(e,t);break;case zg.Awareness:this.applyAwarenessMessage(e);break;case zg.Auth:this.applyAuthMessage(e);break;case zg.QueryAwareness:this.applyQueryAwarenessMessage(e);break;case zg.Stateless:e.receiveStateless(xg(n.decoder));break;case zg.SyncStatus:this.applySyncStatusMessage(e,bg(n.decoder)===1);break;case zg.CLOSE:let i={code:1e3,reason:xg(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(Vg,{encoder:n.encoder})}applySyncMessage(e,t){let{message:n}=this;n.writeVarUint(zg.Sync);let r=$g(n.decoder,n.encoder,e.document,e);t&&r===Gg&&(e.synced=!0)}applySyncStatusMessage(e,t){t&&e.decrementUnsyncedChanges()}applyAwarenessMessage(e){if(!e.awareness)return;let{message:t}=this;Ig(e.awareness,t.readVarUint8Array(),e)}applyAuthMessage(e){let{message:t}=this;hh(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(zg.Awareness),t.writeVarUint8Array(Fg(e.awareness,Array.from(e.awareness.getStates().keys())))}},t_=class{constructor(e,t={}){this.message=new e,this.encoder=this.message.get(t)}create(){return rg(this.encoder)}send(e){e?.send(this.create())}},n_=`4.0.0-rc.1`,r_=class extends Vg{constructor(...e){super(...e),this.type=zg.Auth,this.description=`Authentication`}get(e){if(e.token===void 0)throw Error("The authentication message requires `token` as an argument.");return cg(this.encoder,e.documentName),ag(this.encoder,this.type),mh(this.encoder,e.token),cg(this.encoder,n_),this.encoder}},i_=class extends Vg{constructor(...e){super(...e),this.type=zg.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`);cg(this.encoder,e.documentName),ag(this.encoder,this.type);let t;return t=e.states===void 0?Fg(e.awareness,e.clients):Fg(e.awareness,e.clients,e.states),ug(this.encoder,t),this.encoder}},a_=class extends Vg{constructor(...e){super(...e),this.type=zg.Stateless,this.description=`A stateless message`}get(e){return cg(this.encoder,e.documentName),ag(this.encoder,this.type),cg(this.encoder,e.payload??``),this.encoder}},o_=class extends Vg{constructor(...e){super(...e),this.type=zg.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 cg(this.encoder,e.documentName),ag(this.encoder,this.type),qg(this.encoder,e.document),this.encoder}},s_=class extends Vg{constructor(...e){super(...e),this.type=zg.Sync,this.description=`A document update`}get(e){return cg(this.encoder,e.documentName),ag(this.encoder,this.type),Zg(this.encoder,e.update),this.encoder}},c_=class extends Error{constructor(...e){super(...e),this.code=1001}},l_=class extends Lg{get effectiveName(){return this.configuration.sessionAwareness?vh(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 bl,this.configuration.awareness=e.awareness===void 0?new Ng(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:gh(this.awareness.getStates())})}),this.awareness?.on(`change`,()=>{this.emit(`awarenessChange`,{states:gh(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 Ug(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(o_,{document:this.document,documentName:this.effectiveName})}pageHide(){this.awareness&&Pg(this.awareness,[this.document.clientID],`page hide`)}registerEventListeners(){typeof window>`u`||!(`addEventListener`in window)||window.addEventListener(`pagehide`,this.boundPageHide)}sendStateless(e){this.send(a_,{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(r_,{token:e??``,documentName:this.effectiveName})}documentUpdateHandler(e,t){t!==this&&(this.incrementUnsyncedChanges(),this.send(s_,{update:e,documentName:this.effectiveName}))}awarenessUpdateHandler({added:e,updated:t,removed:n},r){let i=e.concat(t).concat(n);this.send(i_,{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(o_,{document:this.document,documentName:this.effectiveName}),this.awareness&&this.awareness.getLocalState()!==null&&this.send(i_,{awareness:this.awareness,clients:[this.document.clientID],documentName:this.effectiveName})}send(e,t){if(!this._isAttached)return;let n=new t_(e,t);this.emit(`outgoingMessage`,{message:n.message}),n.send(this.configuration.websocketProvider)}onMessage(e){let t=new Rg(e.data),{documentName:n}=yh(t.readVarString());t.writeVarString(this.effectiveName),this.emit(`message`,{event:e,message:new Rg(e.data)}),new e_(t).apply(this,!0)}onClose(){this.isAuthenticated=!1,this.synced=!1,this.awareness&&Pg(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&&(Pg(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 c_(`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)}};function u_(e){return!(e.viewCount>0&&e.viewCount>=50||e.bytes>5e5)}var d_=new Map,f_=new Map,p_=[],m_=[],h_=new Set,g_=null;function __(){if(g_)return g_;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`,g_=e,e}function v_(e){let{docName:t,container:n,factory:r,sizeStats:i}=e;if(i&&!u_(i)){let e=r(n);return K(`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=d_.get(t);if(a){if(E_(a,n),a.activeMountKey=t,O_(p_,t),n.scrollTop=a.scrollTop,a.hadFocus)try{a.editor.commands.focus()}catch{}return K(`ok/cache/hit`,{docName:t,kind:`tiptap`}),i&&K(`ok/cold/editor-mount-stats`,{docName:t,viewCount:i.viewCount,bytes:i.bytes,cacheHit:!0,kind:`tiptap`}),a}for(;d_.size>=10;){let e=k_(p_,t);if(!e)break;b_(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 d_.set(t,s),O_(p_,t),K(`ok/cache/miss`,{docName:t,viewCount:i?.viewCount??-1,bytes:i?.bytes??-1,reason:`cold`,kind:`tiptap`}),i&&K(`ok/cold/editor-mount-stats`,{docName:t,viewCount:i.viewCount,bytes:i.bytes,cacheHit:!1,kind:`tiptap`}),s}function y_(e){if(e.__uncached){try{e.editor.destroy()}catch{}e.activeMountKey=null;return}let t=w_(e.editor);if(t){e.hadFocus=T_(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=__();r&&r.appendChild(t.dom)}e.activeMountKey=null}function b_(e){let t=d_.get(e);if(!t)return!1;try{t.editor.destroy()}catch(t){K(`ok/cache/evict-failed`,{docName:e,kind:`tiptap`,stage:`editor`,message:t instanceof Error?t.message:String(t)})}try{t.provider.destroy()}catch(t){K(`ok/cache/evict-failed`,{docName:e,kind:`tiptap`,stage:`provider`,message:t instanceof Error?t.message:String(t)})}try{t.ydoc.destroy()}catch(t){K(`ok/cache/evict-failed`,{docName:e,kind:`tiptap`,stage:`ydoc`,message:t instanceof Error?t.message:String(t)})}d_.delete(e);let n=p_.indexOf(e);return n!==-1&&p_.splice(n,1),K(`ok/cache/evict`,{docName:e,kind:`tiptap`}),!0}function x_(e){let{docName:t,container:n,factory:r,sizeStats:i}=e;if(i&&!u_(i)){let e=r(n);return K(`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=f_.get(t);if(a){if(D_(a,n),a.activeMountKey=t,O_(m_,t),n.scrollTop=a.scrollTop,a.hadFocus)try{a.view.focus()}catch{}return K(`ok/cache/hit`,{docName:t,kind:`cm`}),i&&K(`ok/cold/editor-mount-stats`,{docName:t,viewCount:i.viewCount,bytes:i.bytes,cacheHit:!0,kind:`cm`}),a}for(;f_.size>=10;){let e=k_(m_,t);if(!e)break;C_(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 f_.set(t,s),O_(m_,t),K(`ok/cache/miss`,{docName:t,viewCount:i?.viewCount??-1,bytes:i?.bytes??-1,reason:`cold`,kind:`cm`}),i&&K(`ok/cold/editor-mount-stats`,{docName:t,viewCount:i.viewCount,bytes:i.bytes,cacheHit:!1,kind:`cm`}),s}function S_(e){if(e.__uncached){try{e.view.destroy()}catch{}e.activeMountKey=null;return}let t=e.view.dom;e.hadFocus=T_(t),e.scrollTop=(e.view.scrollDOM??t).scrollTop??0;let n=t.parentElement;n&&n.removeChild(t);let r=__();r&&r.appendChild(t),e.activeMountKey=null}function C_(e){let t=f_.get(e);if(!t)return!1;try{t.view.destroy()}catch(t){K(`ok/cache/evict-failed`,{docName:e,kind:`cm`,stage:`view`,message:t instanceof Error?t.message:String(t)})}try{t.provider.destroy()}catch(t){K(`ok/cache/evict-failed`,{docName:e,kind:`cm`,stage:`provider`,message:t instanceof Error?t.message:String(t)})}try{t.ydoc.destroy()}catch(t){K(`ok/cache/evict-failed`,{docName:e,kind:`cm`,stage:`ydoc`,message:t instanceof Error?t.message:String(t)})}f_.delete(e);let n=m_.indexOf(e);return n!==-1&&m_.splice(n,1),K(`ok/cache/evict`,{docName:e,kind:`cm`}),!0}function w_(e){return e.editorView??null}function T_(e){if(typeof document>`u`)return!1;let t=document.activeElement;return t?t===e?!0:e.contains(t):!1}function E_(e,t){let n=w_(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 D_(e,t){let n=e.view.dom,r=n.parentElement;r&&r!==t&&r.removeChild(n),n.parentElement!==t&&t.appendChild(n)}function O_(e,t){let n=e.indexOf(t);n!==-1&&e.splice(n,1),e.push(t)}function k_(e,t){for(let n of e)if(n!==t&&!h_.has(n))return n;K(`ok/cache/evict-fallback-activity-saturated`,{mountingDocName:t,lruLength:e.length,activityMountCount:h_.size});for(let n of e)if(n!==t)return n;return null}function A_(e){let t=h_,n=new Set(e);for(let e of t){if(n.has(e))continue;let t=j_(e);if(t)try{t.disconnect(),K(`ok/cache/disconnect`,{docName:e})}catch(t){K(`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=j_(e);if(!n)continue;let r=t=>{K(`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(()=>K(`ok/cache/connect`,{docName:e}),e=>r(e)):K(`ok/cache/connect`,{docName:e})}catch(e){r(e)}}h_=n}function j_(e){let t=d_.get(e);if(t)return t.provider;let n=f_.get(e);return n?n.provider:null}var M_=({key:e,editor:t,onPaste:n,onDrop:r,allowedMimeTypes:i})=>new M({key:e||new H(`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))}}}),N_=me.create({name:`fileHandler`,addOptions(){return{onPaste:void 0,onDrop:void 0,allowedMimeTypes:void 0}},addProseMirrorPlugins(){return[M_({key:new H(this.name),editor:this.editor,allowedMimeTypes:this.options.allowedMimeTypes,onDrop:this.options.onDrop,onPaste:this.options.onPaste})]}}),P_=new H(`imageUpload`);function F_(){let e=document.createElement(`div`);return e.className=`image-upload-skeleton w-full h-40 rounded-md bg-muted animate-pulse motion-reduce:animate-none my-2`,e.setAttribute(`data-upload-widget`,`loading`),e.setAttribute(`role`,`status`),e.setAttribute(`aria-label`,`Uploading image...`),e}var I_=new M({key:P_,state:{init(){return{decorations:L.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(P_);if(!i)return{decorations:n,uploads:r};if(i.type===`add`){let t=Ae.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 P_.getState(e)?.decorations??L.empty}}}),L_=null;function R_(e){L_=e}async function z_(e,t,n){let r=L_?`${L_}.md`:``;if(!r){Ie.error(`Cannot upload: no document is open`);return}let i=crypto.randomUUID(),a=F_();t.view.dispatch(t.state.tr.setMeta(P_,{type:`add`,id:i,pos:n,widget:a}));let o=new FormData;o.append(`file`,e),o.append(`parentDocName`,r);let s;try{s=await fetch(`/api/upload-image`,{method:`POST`,body:o})}catch(e){console.error(`[uploadAndInsert] Network error:`,e),B_(t,i);return}if(!s.ok){let e=`Upload failed (${s.status})`;try{let t=await s.json();t.error&&(e=t.error)}catch{}console.error(`[uploadAndInsert] Server error:`,e),B_(t,i,e);return}let c;try{let e=await s.json();if(typeof e.src!=`string`)throw Error(`missing src in response`);c=e.src}catch(e){console.error(`[uploadAndInsert] Response parse error:`,e),B_(t,i);return}let l=e.name.replace(/\.[^.]+$/,``),{state:u}=t,d=P_.getState(u)?.uploads.get(i)??n,f=u.schema.nodes.image;if(!f){console.error(`[uploadAndInsert] Image node type not found in schema`),B_(t,i);return}let p=u.tr.setMeta(P_,{type:`remove`,id:i}).insert(d,f.create({src:c,alt:l}));t.view.dispatch(p)}function B_(e,t,n){e.view.dispatch(e.state.tr.setMeta(P_,{type:`remove`,id:t})),Ie.error(n??`Upload failed`)}function V_(e){let{$from:t}=e.selection;return t.depth===0?null:{from:t.before(1),to:t.after(1)}}function H_(e,t){let n=V_(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(O.near(l.doc.resolve(p))),l.scrollIntoView(),t(l),!0}function U_(e,t){let n=V_(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(O.near(l.doc.resolve(p))),l.scrollIntoView(),t(l),!0}var W_=me.create({name:`blockMover`,addKeyboardShortcuts(){return{"Mod-Shift-ArrowUp":({editor:e})=>H_(e.state,e.view.dispatch),"Mod-Shift-ArrowDown":({editor:e})=>U_(e.state,e.view.dispatch)}}});function G_(e){return!!e.getMeta(pp)}function K_(e,t){let n=pp.getState(e);return em(n.doc,n.type,t,n.binding.mapping)||0}function q_(e,t){let n=pp.getState(e);return Qp(t,n.type,n.binding.mapping)}var J_=class e extends De{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 Y_(e,t){return new J_(e,q_(t,e))}function X_(e,t,n){let r=e instanceof J_?e.yRelativePosition:null;if(G_(t)&&r)return{position:new J_(K_(n,r),r),mapResult:null};let i=ke(e,t),a=i.position.position;return{position:new J_(a,r??q_(n,a)),mapResult:i.mapResult}}var Z_=me.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)=>X_(e,t,this.editor.state),this.editor.utils.createMappablePosition=e=>Y_(e,this.editor.state)},addCommands(){return{undo:()=>({tr:e,state:t,dispatch:n})=>(e.setMeta(`preventDispatch`,!0),mp.getState(t).undoManager.undoStack.length===0?!1:n?sm(t):!0),redo:()=>({tr:e,state:t,dispatch:n})=>(e.setMeta(`preventDispatch`,!0),mp.getState(t).undoManager.redoStack.length===0?!1:n?cm(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=dm(this.options.yUndoOptions),n=t.spec.view;return t.spec.view=e=>{let{undoManager:t}=mp.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()}}},[xp(e,{...this.options.ySyncOptions,onFirstRender:this.options.onFirstRender}),t,this.editor.options.enableContentCheck&&new M({key:new H(`filterInvalidContent`),filterTransaction:t=>{if(!G_(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 Q_(e){if(!e.length)return L.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(Ae.node(n,n+r.nodeSize,{class:`ProseMirror-selectednoderange`}))}),L.create(n,t)}function $_(e,t,n){let r=n.isText||n.isAtom?0:1;return{start:e+r,end:e+t-r}}function ev(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 y(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=$_(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 de(a.resolve(l),a.resolve(u));i.push(p)}),i}var tv=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 nv(e.resolve(this.anchor),e.resolve(this.head))}},nv=class e extends d{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=ev(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 tv(this.anchor,this.head)}};nv.prototype.visible=!1;function rv(e){return e instanceof nv}me.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(!rv(a)){let e=nv.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(!rv(a)){let e=nv.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=nv.create(i,0,i.content.size,t);return a.setSelection(o),n.dispatch(a),!0}}},onSelectionUpdate(){let{selection:e}=this.editor.state;rv(e)&&this.editor.view.dom.classList.add(`ProseMirror-noderangeselection`)},addProseMirrorPlugins(){let e=!1,t=!1;return[new M({key:new H(`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=nv.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=rv(r);if(e=!1,!t)return i?(e=!0,Q_(r.ranges)):null;let{$from:a,$to:o}=r;if(!i&&a.sameParent(o))return null;let s=ev(a,o,this.options.depth);return s.length?(e=!0,Q_(s)):null}}})]}});function iv(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 av(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=iv(e)}),t}var ov=[{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}],sv={edges:[`left`,`top`],threshold:12,strength:500};function cv(e){return e===void 0||e===`left`?{...sv}: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}:{...sv,...e}}function lv(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 uv(e,t,n,r){return!t||n.edges.length===0?0:lv(e,t,n)?n.strength*r:0}var dv=1e3;function fv(e,t,n,r){let i=dv,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-=uv(r,o,n,e.depth),i<=0?-1:i}function pv(e,t,n){return Array.from({length:t},(e,n)=>t-1-n).some(t=>n.includes(e.node(t).type.name))}function mv(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(...ov),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&&!pv(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=fv({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=pv(a,l,n.allowedContainers)),p){let r=fv({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 hv(e,t){let n=e;for(;n?.parentElement&&n.parentElement!==t.dom;)n=n.parentElement;return n?.parentElement===t.dom?n:void 0}function gv(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 _v(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(!gv(s)||!gv(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 vv=e=>{let{x:t,y:n,editor:r,nestedOptions:i}=e,{view:a,state:o}=r,s=_v(a,t,n,5);if(!s)return{resultElement:null,resultNode:null,pos:null};let{x:c,y:l}=s;if(i?.enabled){let e=mv(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=hv(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 yv(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 bv(e){var t;(t=e.parentNode)==null||t.removeChild(e)}function xv(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=vv({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 ev(i.resolve(a.pos),i.resolve(a.pos+a.resultNode.nodeSize+o),0,{extendOnBoundaryOverlap:!1})}function Sv(e,t,n,r){let{view:i}=t;if(!e.dataTransfer)return;let{empty:a,$from:o,$to:s}=i.state.selection,c=xv(e,t,n,r),l=ev(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,g=d[d.length-1].$to.pos;p.setAttribute(`dir`,yv(i,m));let _=n?.enabled&&r?.node,v,y;_?(v=i.state.doc.slice(m,g),y=h.create(i.state.doc,m)):(y=nv.create(i.state.doc,m,g),v=y.content()),d.forEach(e=>{let t=av(i.nodeDOM(e.$from.pos));p.append(t)}),p.style.position=`absolute`,p.style.top=`-10000px`,document.body.append(p),e.dataTransfer.clearData();let b=p.getBoundingClientRect(),x=e.clientX-b.left;e.dataTransfer.setDragImage(p,Math.max(0,Math.min(x,b.width)),0);let S=!1,C=()=>{S||(S=!0,bv(p),document.removeEventListener(`drop`,C),document.removeEventListener(`dragend`,C))},w=y instanceof h?y:void 0;i.dragging={slice:v,move:!0,node:w},f.setSelection(y),i.dispatch(f),document.addEventListener(`drop`,C),document.addEventListener(`dragend`,C)}var Cv=(e,t)=>{let n=e.resolve(t),{depth:r}=n;return r===0?t:n.pos-n.parentOffset-1},wv=(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},Tv=(e,t)=>{let n=pp.getState(e);return n?Qp(t,n.type,n.binding.mapping):null},Ev=(e,t)=>{let n=pp.getState(e);return n?em(n.doc,n.type,t,n.binding.mapping)||0:-1},Dv=(e,t)=>{let n=t;for(;n?.parentNode&&n.parentNode!==e.dom;)n=n.parentNode;return n},Ov=new H(`dragHandle`),kv=({pluginKey:e=Ov,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,p=-1,m,h=null,g=null;function _(){t&&(t.style.visibility=`hidden`,t.style.pointerEvents=`none`)}function v(){if(t){if(!n.isEditable){_();return}t.style.visibility=``,t.style.pointerEvents=`auto`}}function y(e){f(i?.()||{getBoundingClientRect:()=>e.getBoundingClientRect()},t,r).then(e=>{Object.assign(t.style,{position:e.strategy,left:`${e.x}px`,top:`${e.y}px`})})}function b(e){o?.(e),Sv(e,n,c,{node:d,pos:p}),t&&(t.dataset.dragging=`true`),setTimeout(()=>{t&&(t.style.pointerEvents=`none`)},0)}function x(e){s?.(e),_(),t&&(t.style.pointerEvents=`auto`,t.dataset.dragging=`false`)}function S(){if(Ne()){let e=n.view.dom;requestAnimationFrame(()=>{e.isContentEditable&&(e.contentEditable=`false`,e.contentEditable=`true`)})}}return l.appendChild(t),{unbind(){t.removeEventListener(`dragstart`,b),t.removeEventListener(`dragend`,x),document.removeEventListener(`drop`,S),h&&(cancelAnimationFrame(h),h=null,g=null)},plugin:new M({key:typeof e==`string`?new H(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 _(),u=!1,d=null,p=-1,a?.({editor:n,node:null,pos:-1}),r;if(e.docChanged&&p!==-1&&t)if(G_(e)){let e=Ev(o,m);e!==p&&(p=e)}else{let t=e.mapping.map(p);t!==p&&(p=t,m=Tv(o,p))}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`,b),t.addEventListener(`dragend`,x),document.addEventListener(`drop`,S),{update(r,i){if(!t)return;if(!n.isEditable){_();return}if(u?t.draggable=!1:t.draggable=!0,e.state.doc.eq(i.doc)||p===-1)return;let o=e.nodeDOM(p);if(o=Dv(e,o),o===e.dom||o?.nodeType!==1)return;let s=e.posAtDOM(o,0),c=wv(n.state.doc,s),l=Cv(n.state.doc,s);d=c,p=l,m=Tv(e.state,p),a?.({editor:n,node:d,pos:p}),y(o)},destroy(){t.removeEventListener(`dragstart`,b),t.removeEventListener(`dragend`,x),document.removeEventListener(`drop`,S),h&&(cancelAnimationFrame(h),h=null,g=null),t&&bv(l)}}},props:{handleDOMEvents:{keydown(e){return!t||u?!1:e.hasFocus()?(_(),d=null,p=-1,a?.({editor:n,node:null,pos:-1}),!1):!1},mouseleave(e,t){return u||t.target&&!l.contains(t.relatedTarget)&&(_(),d=null,p=-1,a?.({editor:n,node:null,pos:-1})),!1},mousemove(e,r){return!t||u||(g={x:r.clientX,y:r.clientY},h)||(h=requestAnimationFrame(()=>{if(h=null,!g)return;let{x:t,y:r}=g;g=null;let i=vv({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=Dv(e,o),o===e.dom||o?.nodeType!==1)return;let t=e.posAtDOM(o,0);s=wv(n.state.doc,t),l=Cv(n.state.doc,t)}s!==d&&(d=s,p=l??-1,m=Tv(e.state,p),a?.({editor:n,node:d,pos:p}),y(o),v())})),!1}}}})}};function Av(e){return e===!1||e===void 0?{enabled:!1,rules:[],defaultRules:!0,allowedContainers:void 0,edgeDetection:cv(`none`)}:e===!0?{enabled:!0,rules:[],defaultRules:!0,allowedContainers:void 0,edgeDetection:cv(`left`)}:{enabled:!0,rules:e.rules??[],defaultRules:e.defaultRules??!0,allowedContainers:e.allowedContainers,edgeDetection:cv(e.edgeDetection)}}var jv={placement:`left-start`,strategy:`absolute`};me.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=Av(this.options.nested);return[kv({computePositionConfig:{...jv,...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 Mv=20,Nv=44,Pv=28;function Fv(){let e=document.createElement(`div`);e.className=`ok-block-controls`,e.style.visibility=`hidden`;let t=document.createElement(`button`);t.className=`ok-add-block-btn`,t.setAttribute(`aria-label`,`Add block below`),t.setAttribute(`type`,`button`),t.innerHTML=`<svg aria-hidden="true" xmlns="http://www.w3.org/2000/svg" width="16" height="16" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" class="lucide lucide-plus"><path d="M5 12h14"/><path d="M12 5v14"/></svg>`,t.addEventListener(`mousedown`,e=>{e.preventDefault(),e.stopPropagation()});let n=document.createElement(`div`);return n.className=`ok-drag-grip`,n.setAttribute(`aria-hidden`,`true`),n.innerHTML=`<svg xmlns="http://www.w3.org/2000/svg" width="16" height="16" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" class="lucide lucide-grip-vertical-icon lucide-grip-vertical"><circle cx="9" cy="12" r="1"/><circle cx="9" cy="5" r="1"/><circle cx="9" cy="19" r="1"/><circle cx="15" cy="12" r="1"/><circle cx="15" cy="5" r="1"/><circle cx="15" cy="19" r="1"/></svg>`,e.appendChild(t),e.appendChild(n),{container:e,addBtn:t}}function Iv(e,t,n){let{state:r,view:i}=e,a=t+n.nodeSize;if(a>r.doc.content.size)return;let{tr:o}=r,s=r.schema.nodes.paragraph?.create();if(!s)return;o.insert(a,s);let c=O.near(o.doc.resolve(a+1));o.setSelection(c).scrollIntoView(),i.dispatch(o),i.focus(),e.commands.insertContent(`/`)}var Lv=me.create({name:`blockDragHandle`,addProseMirrorPlugins(){let e=this.editor,t=null,n=-1,{container:r,addBtn:i}=Fv();return i.addEventListener(`click`,()=>{t&&n>=0&&Iv(e,n,t)}),[kv({element:r,editor:e,onNodeChange({node:e,pos:r}){t=e,n=r??-1},computePositionConfig:{placement:`left-start`,strategy:`absolute`,middleware:[x(({rects:e})=>({mainAxis:10,crossAxis:((e.reference.height<=Nv?e.reference.height:Pv)-Mv)/2}))]},nestedOptions:Av(!1)}).plugin]}});function Rv(e){let t=e.trim();if(!t)return null;let n=u(t);return n?{target:n,alias:n===t?null:t,anchor:null}:null}function zv(e){let t=e.trim();if(!t)return[];let n=u(t);return n.length>0&&n!==t?[n]:[]}function Bv(e,t){let n=e.trim();return n?t.has(n)?!0:zv(n).some(e=>t.has(e)):!1}var Vv=me.create({name:`headingAnchors`,addProseMirrorPlugins(){return[new M({props:{decorations(e){let t=[],n=new Map;return e.doc.descendants((e,r)=>{if(e.type.name===`heading`){let i=fe(e.textContent,n);if(!i)return;t.push(Ae.node(r,r+e.nodeSize,{id:i}))}}),L.create(e.doc,t)}}})]}}),Hv=new Set([`http:`,`https:`,`mailto:`,`tel:`]);function Uv(e){try{let t=new URL(e);return Hv.has(t.protocol)}catch{return!1}}function Wv(e=window.location.hash){let t=e.match(/^#\/([^?#]+)/);return t?decodeURIComponent(t[1]):``}function Gv(e,t=window.location.hash){return te(e,Wv(t))}function Kv({docName:e,anchor:t}){return t?`#/${e}?anchor=${encodeURIComponent(t)}`:`#/${e}`}function qv(e){e.startsWith(`#`)||Uv(e)?window.open(e,`_blank`,`noopener,noreferrer`):console.warn(`[safe-nav] blocked non-safe scheme:`,e)}function Jv(e){window.location.assign(Kv(e))}function Yv(e){qv(Kv(e))}function Xv(e){return e.metaKey||e.ctrlKey}function Zv(e,t=window.location.hash){let n=Wv(t);if(!n)return;let r=document.getElementById(e);r&&r.scrollIntoView({behavior:`smooth`,block:`start`}),window.location.assign(se(n,e))}function Qv(e,t=window.location.hash){if(e.kind===`doc`){Jv(e);return}if(e.kind===`anchor`){Zv(e.anchor,t);return}qv(e.url)}function $v(e,t,n=window.location.hash){return oe(Wv(n),e,t)}var ey=e=>{let t=(0,rr.c)(13),{kind:n,ariaLabel:r,onDeactivate:i,children:s,layout:c,className:l,"data-slot":u}=e,d=(c===void 0?`standard`:c)===`wide`?`w-[min(720px,calc(100%-1rem))]`:`w-80`,f;t[0]!==l||t[1]!==d?(f=a(`ok-interaction-prop-panel pointer-events-auto absolute left-1/2 top-2 z-40 -translate-x-1/2 rounded-md border border-border bg-popover p-3 shadow-lg`,d,l),t[0]=l,t[1]=d,t[2]=f):f=t[2];let p;t[3]===Symbol.for(`react.memo_cache_sentinel`)?(p=(0,q.jsx)(Je,{className:`size-3.5`,"aria-hidden":`true`}),t[3]=p):p=t[3];let m;t[4]===i?m=t[5]:(m=(0,q.jsx)(o,{type:`button`,variant:`ghost`,size:`icon`,"aria-label":`Close`,onClick:i,className:`absolute right-1 top-1 size-7`,children:p}),t[4]=i,t[5]=m);let h;return t[6]!==r||t[7]!==s||t[8]!==u||t[9]!==n||t[10]!==f||t[11]!==m?(h=(0,q.jsxs)(`div`,{role:`dialog`,"aria-label":r,"data-ok-prop-panel":n,"data-slot":u,className:f,children:[s,m]}),t[6]=r,t[7]=s,t[8]=u,t[9]=n,t[10]=f,t[11]=m,t[12]=h):h=t[12],h};function ty(e,t){let n=[e,...t.fallbackTargets??[]],r=new Set,i=null;for(let e of n){if(r.has(e))continue;r.add(e);let n=l(e,{pages:t.pages,folderPaths:t.folderPaths});if(n.kind===`missing`){i??=n;continue}return{kind:`navigate`,displayState:n.kind===`folder`?`folder`:`resolved`,resolvedTarget:n,hashDocName:n.target}}let a=i??l(e,{pages:t.pages,folderPaths:t.folderPaths});if(a.kind!==`missing`)return{kind:`navigate`,displayState:a.kind===`folder`?`folder`:`resolved`,resolvedTarget:a,hashDocName:a.target};let o=t.createDialogSeed??ve(a.target);return{kind:`create`,displayState:`missing`,resolvedTarget:a,initialDir:o.initialDir,suggestedName:o.suggestedName}}function ny(e){if(e.kind!==`navigate`||e.displayState!==`folder`)return null;let t=e.resolvedTarget;return`folderPath`in t?{initialDir:t.folderPath,suggestedName:`index.md`}:null}function ry(e){let t=(0,rr.c)(10),n,r,i;t[0]===e?(n=t[1],r=t[2],i=t[3]):({className:n,type:i,...r}=e,t[0]=e,t[1]=n,t[2]=r,t[3]=i);let o;t[4]===n?o=t[5]:(o=a(`h-8 w-full min-w-0 rounded-lg border border-input bg-transparent px-2.5 py-1 text-base transition-colors outline-none file:inline-flex file:h-6 file:border-0 file:bg-transparent file:text-sm file:font-medium file:text-foreground placeholder:text-muted-foreground focus-visible:border-ring focus-visible:ring-3 focus-visible:ring-ring/50 disabled:pointer-events-none disabled:cursor-not-allowed disabled:bg-input/50 disabled:opacity-50 aria-invalid:border-destructive aria-invalid:ring-3 aria-invalid:ring-destructive/20 md:text-sm dark:bg-input/30 dark:disabled:bg-input/80 dark:aria-invalid:border-destructive/50 dark:aria-invalid:ring-destructive/40`,n),t[4]=n,t[5]=o);let s;return t[6]!==r||t[7]!==o||t[8]!==i?(s=(0,q.jsx)(`input`,{type:i,"data-slot":`input`,className:o,...r}),t[6]=r,t[7]=o,t[8]=i,t[9]=s):s=t[9],s}function iy(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 ay(e){return e.endsWith(`.md`)?e:`${e}.md`}function oy(e){let t=ay(e.fileName.trim());if(e.kind===`folder`){let n=(e.folderName??``).trim();return`${e.initialDir?`${e.initialDir}/${n}`:n}/${t}`}return e.initialDir?`${e.initialDir}/${t}`:t}function sy(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 cy(e){let t=e.value.lastIndexOf(`.`);t>0?e.setSelectionRange(0,t):e.select()}function ly(e){let t=(0,rr.c)(87),{open:n,onOpenChange:r,kind:i,initialDir:a,suggestedName:s,description:c,onCreated:l}=e,{addPage:u}=pe(),[d,f]=(0,G.useState)(``),[p,m]=(0,G.useState)(``),[h,g]=(0,G.useState)(null),[_,v]=(0,G.useState)(!1),[y,b]=(0,G.useState)(null),x=(0,G.useId)(),S=(0,G.useId)(),C=(0,G.useId)(),w=(0,G.useRef)(null),T=(0,G.useRef)(null),E,D;t[0]!==i||t[1]!==n||t[2]!==s?(E=()=>{n&&(g(null),b(null),v(!1),m(``),f(i===`file`?s??`untitled.md`:`index.md`))},D=[n,i,s],t[0]=i,t[1]=n,t[2]=s,t[3]=E,t[4]=D):(E=t[3],D=t[4]),(0,G.useEffect)(E,D);let O;t[5]!==d||t[6]!==p||t[7]!==a||t[8]!==i?(O=function(){return oy({kind:i,initialDir:a,fileName:d,folderName:p})},t[5]=d,t[6]=p,t[7]=a,t[8]=i,t[9]=O):O=t[9];let k=O,A;t[10]!==d||t[11]!==p||t[12]!==i?(A=function(){if(i===`folder`){let e=iy(p.trim());if(e)return{message:`Folder name: ${e}`,field:`folder`}}let e=iy(d.trim());return e?{message:e,field:`file`}:null},t[10]=d,t[11]=p,t[12]=i,t[13]=A):A=t[13];let j=A,M;t[14]!==_||t[15]!==d||t[16]!==p||t[17]!==i?(M=_||!d.trim()||i===`folder`&&!p.trim(),t[14]=_,t[15]=d,t[16]=p,t[17]=i,t[18]=M):M=t[18];let N=M,P;t[19]!==u||t[20]!==k||t[21]!==j||t[22]!==i||t[23]!==l||t[24]!==r?(P=async function(){let e=j();if(e){g(e.message),b(e.field);return}v(!0),g(null),b(null);let t=k();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{}v(!1),g(t),b(`form`);return}let n=await e.json();if(v(!1),!n.ok){g(n.error??`Failed to create ${i}`),b(`form`);return}let a=n.docName??t.replace(/\.md$/,``);r(!1),window.location.hash=`#/${a}`,u(a),Ee([`files`,`backlinks`,`graph`]),l?.(a)}catch(e){console.warn(`[NewItemDialog] create failed:`,e),v(!1),g(`Network error — please try again`),b(`form`)}},t[19]=u,t[20]=k,t[21]=j,t[22]=i,t[23]=l,t[24]=r,t[25]=P):P=t[25];let F=P,I=a||`(root)`,ee=i===`file`?`New file`:`New folder`,L;t[26]===ee?L=t[27]:(L=(0,q.jsx)(Ge,{children:ee}),t[26]=ee,t[27]=L);let R;t[28]!==c||t[29]!==I?(R=c??(0,q.jsxs)(q.Fragment,{children:[`Create in `,(0,q.jsx)(`span`,{className:`font-medium text-foreground`,children:I})]}),t[28]=c,t[29]=I,t[30]=R):R=t[30];let z;t[31]===R?z=t[32]:(z=(0,q.jsx)(ze,{children:R}),t[31]=R,t[32]=z);let B;t[33]!==L||t[34]!==z?(B=(0,q.jsxs)(He,{children:[L,z]}),t[33]=L,t[34]=z,t[35]=B):B=t[35];let V;t[36]!==h||t[37]!==y||t[38]!==x||t[39]!==S||t[40]!==p||t[41]!==i?(V=i===`folder`&&(0,q.jsxs)(`div`,{children:[(0,q.jsx)(`label`,{className:`mb-1.5 block text-sm font-medium`,htmlFor:S,children:`Folder name`}),(0,q.jsx)(ry,{ref:T,id:S,value:p,onChange:e=>{m(e.target.value),g(null)},placeholder:`folder-name`,autoFocus:!0,"aria-describedby":h&&(y===`folder`||y===`form`)?x:void 0,"aria-invalid":h&&(y===`folder`||y===`form`)?!0:void 0,onKeyDown:e=>{if(e.key===`Enter`){e.preventDefault();let t=iy(p.trim());if(t){g(`Folder name: ${t}`),b(`folder`);return}w.current?.focus()}}})]}),t[36]=h,t[37]=y,t[38]=x,t[39]=S,t[40]=p,t[41]=i,t[42]=V):V=t[42];let te=i===`folder`?`First file name`:`File name`,ne;t[43]!==C||t[44]!==te?(ne=(0,q.jsx)(`label`,{className:`mb-1.5 block text-sm font-medium`,htmlFor:C,children:te}),t[43]=C,t[44]=te,t[45]=ne):ne=t[45];let re;t[46]===Symbol.for(`react.memo_cache_sentinel`)?(re=e=>{f(e.target.value),g(null)},t[46]=re):re=t[46];let ie=i===`file`,ae=h&&(y===`file`||y===`form`)?x:void 0,oe=h&&(y===`file`||y===`form`)?!0:void 0,se;t[47]!==F||t[48]!==N?(se=e=>{e.key===`Enter`&&!N&&F()},t[47]=F,t[48]=N,t[49]=se):se=t[49];let ce;t[50]!==C||t[51]!==d||t[52]!==ie||t[53]!==ae||t[54]!==oe||t[55]!==se?(ce=(0,q.jsx)(ry,{ref:w,id:C,value:d,onChange:re,placeholder:`my-note.md`,autoFocus:ie,"aria-describedby":ae,"aria-invalid":oe,onFocus:uy,onKeyDown:se}),t[50]=C,t[51]=d,t[52]=ie,t[53]=ae,t[54]=oe,t[55]=se,t[56]=ce):ce=t[56];let le;t[57]!==ne||t[58]!==ce?(le=(0,q.jsxs)(`div`,{children:[ne,ce]}),t[57]=ne,t[58]=ce,t[59]=le):le=t[59];let ue;t[60]!==h||t[61]!==x?(ue=h&&(0,q.jsx)(`p`,{id:x,role:`alert`,className:`text-xs text-red-600 dark:text-red-400`,children:h}),t[60]=h,t[61]=x,t[62]=ue):ue=t[62];let de;t[63]!==V||t[64]!==le||t[65]!==ue?(de=(0,q.jsxs)(`div`,{className:`space-y-3`,children:[V,le,ue]}),t[63]=V,t[64]=le,t[65]=ue,t[66]=de):de=t[66];let fe;t[67]===r?fe=t[68]:(fe=()=>r(!1),t[67]=r,t[68]=fe);let H;t[69]!==_||t[70]!==fe?(H=(0,q.jsx)(o,{variant:`outline`,className:`font-mono uppercase`,onClick:fe,disabled:_,children:`Cancel`}),t[69]=_,t[70]=fe,t[71]=H):H=t[71];let me=_?`Creating...`:`Create`,he;t[72]!==F||t[73]!==N||t[74]!==me?(he=(0,q.jsx)(o,{onClick:F,disabled:N,children:me}),t[72]=F,t[73]=N,t[74]=me,t[75]=he):he=t[75];let ge;t[76]!==H||t[77]!==he?(ge=(0,q.jsxs)(Fe,{children:[H,he]}),t[76]=H,t[77]=he,t[78]=ge):ge=t[78];let _e;t[79]!==B||t[80]!==de||t[81]!==ge?(_e=(0,q.jsxs)(We,{className:`sm:max-w-md`,"data-ok-layer-spawned":``,children:[B,de,ge]}),t[79]=B,t[80]=de,t[81]=ge,t[82]=_e):_e=t[82];let ve;return t[83]!==r||t[84]!==n||t[85]!==_e?(ve=(0,q.jsx)(Ke,{open:n,onOpenChange:r,children:_e}),t[83]=r,t[84]=n,t[85]=_e,t[86]=ve):ve=t[86],ve}function uy(e){return cy(e.currentTarget)}var dy=class{registry=new Map;_activeNodeId=null;listeners=new Set;_snapshot={activeNodeId:null,active:null};register(e){this.registry.set(e.nodeId,e),this._activeNodeId===e.nodeId&&this.refreshSnapshot()}deregister(e){this.registry.delete(e)&&this._activeNodeId===e&&(this._activeNodeId=null,this.refreshSnapshot())}setActiveNode(e){this._activeNodeId!==e&&(e!==null&&!this.registry.has(e)||(this._activeNodeId=e,this.refreshSnapshot()))}getActiveNode(){return this._activeNodeId}getRegistration(e){return this.registry.get(e)}hasRegistration(e){return this.registry.has(e)}clear(){this.registry.clear(),this._activeNodeId=null,this.refreshSnapshot()}getSnapshot=()=>this._snapshot;subscribe=e=>(this.listeners.add(e),()=>{this.listeners.delete(e)});refreshSnapshot(){let e=this._activeNodeId==null?null:this.registry.get(this._activeNodeId)??null;this._snapshot={activeNodeId:this._activeNodeId,active:e};for(let e of this.listeners)e()}};function fy(e,t){let n=e??null;for(;n&&typeof n==`object`;){let e=n.getAttribute;if(typeof e==`function`){let r=e.call(n,`data-mark-id`);if(r&&t.hasRegistration(r))return r;let i=e.call(n,`data-node-id`);if(i&&t.hasRegistration(i))return i}n=n.parentElement??null}return null}var py=e=>{let t=(0,rr.c)(18),{store:n}=e,r;t[0]===n?r=t[1]:(r=()=>n.getSnapshot(),t[0]=n,t[1]=r);let[i,a]=(0,G.useState)(r),o,s;t[2]===n?(o=t[3],s=t[4]):(o=()=>(a(n.getSnapshot()),n.subscribe(()=>{a(n.getSnapshot())})),s=[n],t[2]=n,t[3]=o,t[4]=s),(0,G.useEffect)(o,s);let{active:c}=i;if(!c)return null;let l;t[5]===n?l=t[6]:(l=()=>n.setActiveNode(null),t[5]=n,t[6]=l);let u,d,f;if(t[7]!==c.controls||t[8]!==c.nodeId||t[9]!==c.type||t[10]!==l){let e={nodeId:c.nodeId,type:c.type,deactivate:l};u=c.controls.propPanel?.(e),d=c.controls.toolbar?.(e),f=c.controls.breadcrumb?.(e),t[7]=c.controls,t[8]=c.nodeId,t[9]=c.type,t[10]=l,t[11]=u,t[12]=d,t[13]=f}else u=t[11],d=t[12],f=t[13];let p;return t[14]!==u||t[15]!==d||t[16]!==f?(p=(0,q.jsxs)(q.Fragment,{children:[u,d,f]}),t[14]=u,t[15]=d,t[16]=f,t[17]=p):p=t[17],p};function my(e){return e.editorView?.dom??e.view?.dom??null}function hy(e,t){let n=e;for(;n;){if(n.getAttribute?.(`data-mark-id`)===t||n.getAttribute?.(`data-node-id`)===t)return!0;n=n.parentElement}return!1}function gy(e){let{editor:t}=e,n=new dy,r=my(t),i=!1,a=null,o=n.subscribe(()=>{let e=n.getActiveNode();if(e!==null){if(typeof document<`u`){let t=document.activeElement;a=t&&hy(t,e)?t:null}return}if(typeof document>`u`)return;let i=a;if(a=null,i&&document.contains(i)&&typeof i.focus==`function`){try{i.focus({preventScroll:!0})}catch{}return}let o=r??my(t);if(o&&typeof o.focus==`function`)try{o.focus({preventScroll:!0})}catch{}}),s=e=>{let t=e;if(t.button===2)return;if(t.metaKey||t.ctrlKey||t.button===1){t.button===1&&t.preventDefault?.();return}let r=fy(e.target,n);if(r===null)return;let i=n.getRegistration(r);i?.handlePrimary&&i.handlePrimary({nodeId:r,type:i.type,newTab:!1})||n.setActiveNode(r)},c=e=>{let t=e;if(t.button===2||t.type===`click`&&t.button===1||!(t.metaKey||t.ctrlKey||t.button===1))return;let r=fy(e.target,n);if(r===null)return;let i=n.getRegistration(r);i?.handlePrimary&&i.handlePrimary({nodeId:r,type:i.type,newTab:!0})&&t.preventDefault?.()},l=e=>{let t=e;if(t.key===`Escape`){n.getActiveNode()!==null&&(n.setActiveNode(null),t.preventDefault?.());return}if(t.key!==`Enter`&&t.key!==` `&&t.key!==`Spacebar`)return;let r=fy(e.target,n);if(r===null)return;let i=n.getRegistration(r);t.preventDefault?.(),!(i?.handlePrimary&&i.handlePrimary({nodeId:r,type:i.type,newTab:!1}))&&n.setActiveNode(r)},u=e=>{if(n.getActiveNode()===null)return;let t=e.target;t&&(r?.contains(t)||t instanceof Element&&(t.closest(`[data-ok-interaction-layer]`)||t.closest(`[data-ok-prop-panel]`)||t.closest(`[data-ok-layer-spawned]`))||n.setActiveNode(null))},d=()=>{i||(r=my(t),r&&(r.addEventListener(`pointerdown`,s,!0),r.addEventListener(`click`,c,!0),r.addEventListener(`auxclick`,c,!0),r.addEventListener(`keydown`,l,!0),typeof document<`u`&&document.addEventListener(`pointerdown`,u,!0),i=!0))},f=()=>{i&&=(r?.removeEventListener(`pointerdown`,s,!0),r?.removeEventListener(`click`,c,!0),r?.removeEventListener(`auxclick`,c,!0),r?.removeEventListener(`keydown`,l,!0),typeof document<`u`&&document.removeEventListener(`pointerdown`,u,!0),!1)};return d(),{register(e){n.register(e),i||d()},deregister(e){n.deregister(e)},setActiveNode(e){n.setActiveNode(e)},getActiveNode(){return n.getActiveNode()},getRegistration(e){return n.getRegistration(e)},destroy(){f(),o(),n.clear()},store:n}}var _y=e=>{let t=(0,rr.c)(2),{store:n}=e,r;return t[0]===n?r=t[1]:(r=(0,q.jsx)(`div`,{"data-ok-interaction-layer":``,className:`contents`,children:(0,q.jsx)(py,{store:n})}),t[0]=n,t[1]=r),r},vy=new WeakMap;function yy(e){let t=vy.get(e);if(t)return t;let n=gy({editor:e});return vy.set(e,n),e.on(`destroy`,()=>{n.destroy(),vy.delete(e)}),n}var by=new H(`markIdentity`);function xy(){return{byId:new Map,counter:0}}function Sy(e,t,n,r,i){let a=[];for(let e of t.byId.values()){let t=i?i.map(e.from,-1):e.from,n=i?i.map(e.to,1):e.to;n<=t||a.push({id:e.id,markType:e.markType,attrs:e.attrs,from:t,to:n})}let o=new Map,s=new Set,c=t.counter;return e.descendants((e,t)=>{if(!(!e.isInline||e.marks.length===0))for(let i of e.marks){if(!n.has(i.type.name)||r&&!r(i))continue;let l=null;for(let e of a)if(!s.has(e.id)&&e.markType===i.type.name&&Cy(e.attrs,i.attrs)&&!(t<e.from||t>=e.to)){l=e.id;break}let u=l??`m${++c}`;s.add(u);let d=t,f=t+e.nodeSize,p=o.get(u);p?p.to=Math.max(p.to,f):o.set(u,{id:u,markType:i.type.name,attrs:i.attrs,from:d,to:f})}}),{byId:o,counter:c}}function Cy(e,t){let n=Object.keys(e),r=Object.keys(t);if(n.length!==r.length)return!1;for(let r of n){let n=e[r],i=t[r];if(n!==i&&!(typeof n==`object`&&n&&typeof i==`object`&&i&&Cy(n,i)))return!1}return!0}function wy(e,t,n,r){let i=new Set(t.byId.keys());for(let[r,i]of t.byId)e.has(r)||n?.(i);for(let t of e)i.has(t)||r?.(t);return i}function Ty(e){let{markTypes:t,predicate:n,onRegister:r,onDeregister:i}=e,a=new Set(t);return new M({key:by,state:{init(e,t){return Sy(t.doc,xy(),a,n)},apply(e,t,r,i){return e.docChanged?Sy(i.doc,t,a,n,e.mapping):t}},view(){let e=new Set;return{update(t){let n=by.getState(t.state);n&&(e=wy(e,n,r,i))},destroy(){for(let t of e)i?.(t);e=new Set}}}})}function Ey(e,t){return by.getState(e)?.byId.get(t)??null}function Dy(e){let{editor:t,layer:n,renderPropPanel:r,handlePrimary:i}=e;return{onRegister:e=>{n.register({type:e.markType,nodeId:e.id,controls:{propPanel:e=>r({editor:t,nodeId:e.nodeId,deactivate:e.deactivate})},handlePrimary:i?e=>i({editor:t,nodeId:e.nodeId,newTab:e.newTab}):void 0})},onDeregister:e=>{n.deregister(e)}}}function Oy(e){let{editor:t,layer:n,markTypes:r,predicate:i,renderPropPanel:a,handlePrimary:o}=e,s=Dy({editor:t,layer:n,renderPropPanel:a,handlePrimary:o});return Ty({markTypes:[...r],predicate:i,onRegister:s.onRegister,onDeregister:s.onDeregister})}function ky(e){let t=yy(e.editor);return Oy({...e,layer:t})}function Ay(e){let{char:t,allowSpaces:n,allowToIncludeChar:r,allowedPrefixes:i,startOfLine:a,$position:o}=e,s=n&&!r,c=be(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 jy(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,`
|
|
5
|
-
`);return/\s/.test(n)}):!1}var My=new H(`suggestion`);function Ny({pluginKey:e=My,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=Ay,shouldShow:g,shouldResetDismissed:_}){let v,y=p?.(),b=r&&!i,x=()=>{let e=t.state.selection.$anchor.pos,{top:n,right:r,bottom:i,left:a}=t.view.coordsAtPos(e);try{return new DOMRect(a,n,r-a,i-n)}catch{return null}},S=(n,r)=>r?()=>{let r=e.getState(t.state)?.decorationId;return n.dom.querySelector(`[data-decoration-id="${r}"]`)?.getBoundingClientRect()||null}:x,C=({match:e,dismissedRange:n,state:r,transaction:i})=>_?.({editor:t,state:r,range:n,match:e,transaction:i,allowSpaces:b})?!1:b?e.range.from===n.from:e.range.from===n.from&&!jy(i);function w(n,r){var i;try{let r=e.getState(n.state),a=r?.decorationId?n.dom.querySelector(`[data-decoration-id="${r.decorationId}"]`):null,o={editor:t,range:r?.range||{from:0,to:0},query:r?.query||null,text:r?.text||null,items:[],command:e=>d({editor:t,range:r?.range||{from:0,to:0},props:e}),decorationNode:a,clientRect:S(n,a)};(i=y?.onExit)==null||i.call(y,o)}catch{}let a=n.state.tr.setMeta(r,{exit:!0});n.dispatch(a)}let T=new M({key:e,view(){return{update:async(e,n)=>{var r,i,a,o,s;let c=this.key?.getState(n),l=this.key?.getState(e.state),u=c.active&&l.active&&c.range.from!==l.range.from,p=!c.active&&l.active,m=c.active&&!l.active,h=!p&&!m&&c.query!==l.query,g=p||u&&h,_=h||u,b=m||u&&h;if(!g&&!_&&!b)return;let x=b&&!g?c:l,C=e.dom.querySelector(`[data-decoration-id="${x.decorationId}"]`);v={editor:t,range:x.range,query:x.query,text:x.text,items:[],command:e=>d({editor:t,range:x.range,props:e}),decorationNode:C,clientRect:S(e,C)},g&&((r=y?.onBeforeStart)==null||r.call(y,v)),_&&((i=y?.onBeforeUpdate)==null||i.call(y,v)),(_||g)&&(v.items=await f({editor:t,query:x.query})),b&&((a=y?.onExit)==null||a.call(y,v)),_&&((o=y?.onUpdate)==null||o.call(y,v)),g&&((s=y?.onStart)==null||s.call(y,v))},destroy:()=>{var e;v&&((e=y?.onExit)==null||e.call(y,v))}}},state:{init(){return{active:!1,range:{from:0,to:0},query:null,text:null,composing:!1,dismissedRange:null}},apply(s,c,l,u){let{isEditable:d}=t,{composing:f}=t.view,{selection:p}=s,{empty:_,from:v}=p,y={...c},b=s.getMeta(e);if(b&&b.exit)return y.active=!1,y.decorationId=null,y.range={from:0,to:0},y.query=null,y.text=null,y.dismissedRange=c.active?{...c.range}:c.dismissedRange,y;if(y.composing=f,s.docChanged&&y.dismissedRange!==null&&(y.dismissedRange={from:s.mapping.map(y.dismissedRange.from),to:s.mapping.map(y.dismissedRange.to)}),d&&(_||t.view.composing)){(v<c.range.from||v>c.range.to)&&!f&&!c.composing&&(y.active=!1);let e=h({char:n,allowSpaces:r,allowToIncludeChar:i,allowedPrefixes:a,startOfLine:o,$position:p.$from}),l=`id_${Math.floor(Math.random()*4294967295)}`;e&&m({editor:t,state:u,range:e.range,isActive:c.active})&&(!g||g({editor:t,range:e.range,query:e.query,text:e.text,transaction:s}))?(y.dismissedRange!==null&&!C({match:e,dismissedRange:y.dismissedRange,state:u,transaction:s})&&(y.dismissedRange=null),y.dismissedRange===null?(y.active=!0,y.decorationId=c.decorationId?c.decorationId:l,y.range=e.range,y.query=e.query,y.text=e.text):y.active=!1):(e||(y.dismissedRange=null),y.active=!1)}else y.active=!1;return y.active||(y.decorationId=null,y.range={from:0,to:0},y.query=null,y.text=null),y}},props:{handleKeyDown(t,n){var r;let{active:i,range:a}=T.getState(t.state);if(!i)return!1;if(n.key===`Escape`||n.key===`Esc`){let i=T.getState(t.state);return(r=y?.onKeyDown)==null||r.call(y,{view:t,event:n,range:i.range}),w(t,e),!0}return(y?.onKeyDown)?.call(y,{view:t,event:n,range:a})||!1},decorations(e){let{active:t,range:n,decorationId:r,query:i}=T.getState(e);if(!t)return null;let a=!i?.length,o=[c];return a&&o.push(u),L.create(e.doc,[Ae.inline(n.from,n.to,{nodeName:s,class:o.join(` `),"data-decoration-id":r,"data-decoration-content":l})])}}});return T}var Py=Ny,Fy=n(t(((e,t)=>{((e,n)=>{typeof define==`function`&&define.amd?define([],n):typeof t==`object`&&t.exports?t.exports=n():e.fuzzysort=n()})(e,e=>{var t=(e,t)=>{if(!e||!t)return F;var n=p(e);j(t)||(t=f(t));var r=n.bitflags;return(r&t._bitflags)===r?h(n,t):F},n=(e,t,n)=>{if(!e)return n?.all?m(t,n):P;var r=p(e),i=r.bitflags,a=r.containsSpace,o=u(n?.threshold||0),c=n?.limit||M,l=0,d=0,g=t.length;function _(e){l<c?(ee.add(e),++l):(++d,e._score>ee.peek()._score&&ee.replaceTop(e))}if(n?.key)for(var v=n.key,y=0;y<g;++y){var b=t[y],x=A(b,v);if(x&&(j(x)||(x=f(x)),(i&x._bitflags)===i)){var S=h(r,x);S!==F&&(S._score<o||(S.obj=b,_(S)))}}else if(n?.keys){var C=n.keys,w=C.length;outer:for(var y=0;y<g;++y){for(var b=t[y],T=0,L=0;L<w;++L){var v=C[L],x=A(b,v);if(!x){O[L]=I;continue}j(x)||(x=f(x)),O[L]=x,T|=x._bitflags}if((i&T)===i){if(a)for(let e=0;e<r.spaceSearches.length;e++)E[e]=N;for(var L=0;L<w;++L){if(x=O[L],x===I){k[L]=I;continue}if(k[L]=h(r,x,!1,a),k[L]===F){k[L]=I;continue}if(a)for(let e=0;e<r.spaceSearches.length;e++){if(D[e]>-1e3&&E[e]>N){var R=(E[e]+D[e])/4;R>E[e]&&(E[e]=R)}D[e]>E[e]&&(E[e]=D[e])}}if(a){for(let e=0;e<r.spaceSearches.length;e++)if(E[e]===N)continue outer}else{var z=!1;for(let e=0;e<w;e++)if(k[e]._score!==N){z=!0;break}if(!z)continue}var B=new s(w);for(let e=0;e<w;e++)B[e]=k[e];if(a){var V=0;for(let e=0;e<r.spaceSearches.length;e++)V+=E[e]}else{var V=N;for(let e=0;e<w;e++){var S=B[e];if(S._score>-1e3&&V>N){var R=(V+S._score)/4;R>V&&(V=R)}S._score>V&&(V=S._score)}}if(B.obj=b,B._score=V,n?.scoreFn){if(V=n.scoreFn(B),!V)continue;V=u(V),B._score=V}V<o||_(B)}}}else for(var y=0;y<g;++y){var x=t[y];if(x&&(j(x)||(x=f(x)),(i&x._bitflags)===i)){var S=h(r,x);S!==F&&(S._score<o||_(S))}}if(l===0)return P;for(var te=Array(l),y=l-1;y>=0;--y)te[y]=ee.poll();return te.total=l+d,te},r=(e,t=`<b>`,n=`</b>`)=>{for(var r=typeof t==`function`?t:void 0,i=e.target,a=i.length,o=e.indexes,s=``,c=0,l=0,u=!1,d=[],f=0;f<a;++f){var p=i[f];if(o[l]===f){if(++l,u||(u=!0,r?(d.push(s),s=``):s+=t),l===o.length){r?(s+=p,d.push(r(s,c++)),s=``,d.push(i.substr(f+1))):s+=p+n+i.substr(f+1);break}}else u&&(u=!1,r?(d.push(r(s,c++)),s=``):s+=n);s+=p}return r?d:s},i=e=>{typeof e==`number`?e=``+e:typeof e!=`string`&&(e=``);var t=v(e);return c(e,{_targetLower:t._lower,_targetLowerCodes:t.lowerCodes,_bitflags:t.bitflags})},a=()=>{x.clear(),S.clear()};class o{get indexes(){return this._indexes.slice(0,this._indexes.len).sort((e,t)=>e-t)}set indexes(e){return this._indexes=e}highlight(e,t){return r(this,e,t)}get score(){return l(this._score)}set score(e){this._score=u(e)}}class s extends Array{get score(){return l(this._score)}set score(e){this._score=u(e)}}var c=(e,t)=>{let n=new o;return n.target=e,n.obj=t.obj??F,n._score=t._score??N,n._indexes=t._indexes??[],n._targetLower=t._targetLower??``,n._targetLowerCodes=t._targetLowerCodes??F,n._nextBeginningIndexes=t._nextBeginningIndexes??F,n._bitflags=t._bitflags??0,n},l=e=>e===N?0:e>1?e:Math.E**(((-e+1)**.04307-1)*-2),u=e=>e===0?N:e>1?e:1-(Math.log(e)/-2+1)**(1/.04307),d=e=>{typeof e==`number`?e=``+e:typeof e!=`string`&&(e=``),e=e.trim();var t=v(e),n=[];if(t.containsSpace){var r=e.split(/\s+/);r=[...new Set(r)];for(var i=0;i<r.length;i++)if(r[i]!==``){var a=v(r[i]);n.push({lowerCodes:a.lowerCodes,_lower:r[i].toLowerCase(),containsSpace:!1})}}return{lowerCodes:t.lowerCodes,_lower:t._lower,containsSpace:t.containsSpace,bitflags:t.bitflags,spaceSearches:n}},f=e=>{if(e.length>999)return i(e);var t=x.get(e);return t===void 0?(t=i(e),x.set(e,t),t):t},p=e=>{if(e.length>999)return d(e);var t=S.get(e);return t===void 0?(t=d(e),S.set(e,t),t):t},m=(e,t)=>{var n=[];n.total=e.length;var r=t?.limit||M;if(t?.key)for(var i=0;i<e.length;i++){var a=e[i],o=A(a,t.key);if(o!=F){j(o)||(o=f(o));var l=c(o.target,{_score:o._score,obj:a});if(n.push(l),n.length>=r)return n}}else if(t?.keys)for(var i=0;i<e.length;i++){for(var a=e[i],u=new s(t.keys.length),d=t.keys.length-1;d>=0;--d){var o=A(a,t.keys[d]);if(!o){u[d]=I;continue}j(o)||(o=f(o)),o._score=N,o._indexes.len=0,u[d]=o}if(u.obj=a,u._score=N,n.push(u),n.length>=r)return n}else for(var i=0;i<e.length;i++){var o=e[i];if(o!=F&&(j(o)||(o=f(o)),o._score=N,o._indexes.len=0,n.push(o),n.length>=r))return n}return n},h=(e,t,n=!1,r=!1)=>{if(n===!1&&e.containsSpace)return g(e,t,r);for(var i=e._lower,a=e.lowerCodes,s=a[0],c=t._targetLowerCodes,l=a.length,u=c.length,d=0,f=0,p=0;;){var m=s===c[f];if(m){if(C[p++]=f,++d,d===l)break;s=a[d]}if(++f,f>=u)return F}var d=0,h=!1,_=0,v=t._nextBeginningIndexes;v===F&&(v=t._nextBeginningIndexes=b(t.target)),f=C[0]===0?0:v[C[0]-1];var y=0;if(f!==u)for(;;)if(f>=u){if(d<=0||(++y,y>200))break;--d;var x=w[--_];f=v[x]}else{var m=a[d]===c[f];if(m){if(w[_++]=f,++d,d===l){h=!0;break}++f}else f=v[f]}var S=l<=1?-1:t._targetLower.indexOf(i,C[0]),T=!!~S,E=T?S===0||t._nextBeginningIndexes[S-1]===S:!1;if(T&&!E){for(var D=0;D<v.length;D=v[D])if(!(D<=S)){for(var O=0;O<l&&a[O]===t._targetLowerCodes[D+O];O++);if(O===l){S=D,E=!0;break}}}var k=e=>{for(var t=0,n=0,r=1;r<l;++r)e[r]-e[r-1]!==1&&(t-=e[r],++n);var i=e[l-1]-e[0]-(l-1);if(t-=(12+i)*n,e[0]!==0&&(t-=e[0]*e[0]*.2),!h)t*=1e3;else{for(var a=1,r=v[0];r<u;r=v[r])++a;a>24&&(t*=(a-24)*10)}return t-=(u-l)/2,T&&(t/=1+l*l*1),E&&(t/=1+l*l*1),t-=(u-l)/2,t};if(!h){if(T)for(var D=0;D<l;++D)C[D]=S+D;var A=C,j=k(A)}else if(E){for(var D=0;D<l;++D)C[D]=S+D;var A=C,j=k(C)}else var A=w,j=k(w);t._score=j;for(var D=0;D<l;++D)t._indexes[D]=A[D];t._indexes.len=l;let M=new o;return M.target=t.target,M._score=t._score,M._indexes=t._indexes,M},g=(e,t,n)=>{for(var r=new Set,i=0,a=F,o=0,s=e.spaceSearches,c=s.length,l=0,u=()=>{for(let e=l-1;e>=0;e--)t._nextBeginningIndexes[T[e*2+0]]=T[e*2+1]},d=!1,f=0;f<c;++f){D[f]=N;var p=s[f];if(a=h(p,t),n){if(a===F)continue;d=!0}else if(a===F)return u(),F;if(f!==c-1){var m=a._indexes,g=!0;for(let e=0;e<m.len-1;e++)if(m[e+1]-m[e]!==1){g=!1;break}if(g){var _=m[m.len-1]+1,v=t._nextBeginningIndexes[_-1];for(let e=_-1;e>=0&&v===t._nextBeginningIndexes[e];e--)t._nextBeginningIndexes[e]=_,T[l*2+0]=e,T[l*2+1]=v,l++}}i+=a._score/c,D[f]=a._score/c,a._indexes[0]<o&&(i-=(o-a._indexes[0])*2),o=a._indexes[0];for(var y=0;y<a._indexes.len;++y)r.add(a._indexes[y])}if(n&&!d)return F;u();var b=h(e,t,!0);if(b!==F&&b._score>i){if(n)for(var f=0;f<c;++f)D[f]=b._score/c;return b}n&&(a=t),a._score=i;var f=0;for(let e of r)a._indexes[f++]=e;return a._indexes.len=f,a},_=e=>e.replace(/\p{Script=Latin}+/gu,e=>e.normalize(`NFD`)).replace(/[\u0300-\u036f]/g,``),v=e=>{e=_(e);for(var t=e.length,n=e.toLowerCase(),r=[],i=0,a=!1,o=0;o<t;++o){var s=r[o]=n.charCodeAt(o);if(s===32){a=!0;continue}var c=s>=97&&s<=122?s-97:s>=48&&s<=57?26:s<=127?30:31;i|=1<<c}return{lowerCodes:r,bitflags:i,containsSpace:a,_lower:n}},y=e=>{for(var t=e.length,n=[],r=0,i=!1,a=!1,o=0;o<t;++o){var s=e.charCodeAt(o),c=s>=65&&s<=90,l=c||s>=97&&s<=122||s>=48&&s<=57,u=c&&!i||!a||!l;i=c,a=l,u&&(n[r++]=o)}return n},b=e=>{e=_(e);for(var t=e.length,n=y(e),r=[],i=n[0],a=0,o=0;o<t;++o)i>o?r[o]=i:(i=n[++a],r[o]=i===void 0?t:i);return r},x=new Map,S=new Map,C=[],w=[],T=[],E=[],D=[],O=[],k=[],A=(e,t)=>{var n=e[t];if(n!==void 0)return n;if(typeof t==`function`)return t(e);var r=t;Array.isArray(t)||(r=t.split(`.`));for(var i=r.length,a=-1;e&&++a<i;)e=e[r[a]];return e},j=e=>typeof e==`object`&&typeof e._bitflags==`number`,M=1/0,N=-M,P=[];P.total=0;var F=null,I=i(``),ee=(e=>{var t=[],n=0,r={},i=e=>{for(var r=0,i=t[r],a=1;a<n;){var o=a+1;r=a,o<n&&t[o]._score<t[a]._score&&(r=o),t[r-1>>1]=t[r],a=1+(r<<1)}for(var s=r-1>>1;r>0&&i._score<t[s]._score;s=(r=s)-1>>1)t[r]=t[s];t[r]=i};return r.add=(e=>{var r=n;t[n++]=e;for(var i=r-1>>1;r>0&&e._score<t[i]._score;i=(r=i)-1>>1)t[r]=t[i];t[r]=e}),r.poll=(e=>{if(n!==0){var r=t[0];return t[0]=t[--n],i(),r}}),r.peek=(e=>{if(n!==0)return t[0]}),r.replaceTop=(e=>{t[0]=e,i()}),r})();return{single:t,go:n,prepare:i,cleanup:a}})}))(),1);function Iy(e){return e.kind===`anchor`?`${e.docName}#${e.slug}`:e.docName}function Ly(e){return e.kind===`anchor`?`Heading H${e.level}: ${e.text}`:e.kind===`create`?e.actionLabel:e.title}function Ry(e){let t=(0,rr.c)(41),{items:n,query:r,selectedIndex:i,onSelect:a,loading:o,error:s,mode:c,pageTarget:l,anchorQuery:u}=e,d=o===void 0?!1:o,f=s===void 0?null:s,p=c===void 0?`page`:c,m=l===void 0?``:l,h=u===void 0?``:u,g=(0,G.useRef)(null),_=(0,G.useId)(),v=i>=0&&i<n.length?`${_}-option-${i}`:void 0,y,b;t[0]===i?(y=t[1],b=t[2]):(y=()=>{let e=g.current;if(!e)return;let t=e.querySelectorAll(`[role="option"]`).item(i);t&&t.scrollIntoView({block:`nearest`})},b=[i],t[0]=i,t[1]=y,t[2]=b),(0,G.useEffect)(y,b);let x=zy;if(d){let e;t[3]===Symbol.for(`react.memo_cache_sentinel`)?(e={maxHeight:`var(--suggestion-menu-max-height, 40vh)`},t[3]=e):e=t[3];let n=p===`anchor`?`Loading headings for ${m}…`:`Loading pages…`,r;return t[4]===n?r=t[5]:(r=(0,q.jsx)(`div`,{ref:g,role:`status`,"aria-live":`polite`,className:`w-64 rounded-lg border bg-popover p-2 shadow-md text-sm text-muted-foreground`,style:e,onMouseDown:x,children:n}),t[4]=n,t[5]=r),r}if(n.length===0){let e;t[6]!==h||t[7]!==f||t[8]!==p||t[9]!==m||t[10]!==r?(e=f??(p===`anchor`?h.trim()?`No headings match "${h.trim()}"`:`No headings in ${m}`:r.trim()?`No pages found for "${r.trim()}"`:`No pages found`),t[6]=h,t[7]=f,t[8]=p,t[9]=m,t[10]=r,t[11]=e):e=t[11];let n=e,i;t[12]===Symbol.for(`react.memo_cache_sentinel`)?(i={maxHeight:`var(--suggestion-menu-max-height, 40vh)`},t[12]=i):i=t[12];let a;return t[13]===n?a=t[14]:(a=(0,q.jsx)(`div`,{ref:g,role:`status`,"aria-live":`polite`,className:`w-64 rounded-lg border bg-popover p-2 shadow-md text-sm text-muted-foreground`,style:i,onMouseDown:x,children:n}),t[13]=n,t[14]=a),a}let S=i>=0&&i<n.length?n[i]:null,C=p===`anchor`?`Heading suggestions`:`Wiki link suggestions`,w;t[15]===Symbol.for(`react.memo_cache_sentinel`)?(w={maxHeight:`var(--suggestion-menu-max-height, 40vh)`},t[15]=w):w=t[15];let T;t[16]===S?T=t[17]:(T=S?Ly(S):``,t[16]=S,t[17]=T);let E;t[18]===T?E=t[19]:(E=(0,q.jsx)(`span`,{className:`sr-only`,"aria-live":`polite`,"aria-atomic":`true`,children:T}),t[18]=T,t[19]=E);let D;t[20]===f?D=t[21]:(D=f&&(0,q.jsx)(`div`,{className:`rounded-md px-2 py-1.5 text-xs text-amber-700 dark:text-amber-300`,children:f}),t[20]=f,t[21]=D);let O;t[22]!==p||t[23]!==m?(O=p===`anchor`&&(0,q.jsx)(`div`,{className:`px-2 py-1 text-[10px] font-medium uppercase tracking-wide text-muted-foreground`,children:m}),t[22]=p,t[23]=m,t[24]=O):O=t[24];let k;if(t[25]!==n||t[26]!==_||t[27]!==a||t[28]!==i){let e;t[30]!==_||t[31]!==a||t[32]!==i?(e=(e,t)=>{let n=t===i,r=Iy(e);return e.kind===`anchor`?(0,q.jsxs)(`button`,{id:`${_}-option-${t}`,type:`button`,role:`option`,"aria-selected":n,"data-selected":n,className:`flex w-full items-center gap-2 rounded-md px-2 py-1.5 text-sm text-left ${n?`bg-accent text-accent-foreground`:``}`,style:{paddingLeft:`${(e.level-1)*10+8}px`},onMouseDown:t=>{t.preventDefault(),a(e)},children:[(0,q.jsxs)(`span`,{className:`w-6 shrink-0 font-mono text-[10px] text-muted-foreground`,children:[`H`,e.level]}),(0,q.jsx)(`span`,{className:`truncate font-medium`,children:e.text})]},r):(0,q.jsxs)(`button`,{id:`${_}-option-${t}`,type:`button`,role:`option`,"aria-selected":n,"data-selected":n,className:`flex w-full flex-col rounded-md px-2 py-1.5 text-sm text-left ${n?`bg-accent text-accent-foreground`:``}`,onMouseDown:t=>{t.preventDefault(),a(e)},children:[(0,q.jsx)(`span`,{className:`truncate font-medium`,children:e.kind===`create`?e.actionLabel:e.title}),e.kind===`page`&&e.title!==e.docName&&(0,q.jsx)(`span`,{className:`truncate text-xs text-muted-foreground`,children:e.docName}),e.kind===`create`&&(0,q.jsxs)(`span`,{className:`truncate text-xs text-muted-foreground`,children:[e.docName,`.md`]})]},r)},t[30]=_,t[31]=a,t[32]=i,t[33]=e):e=t[33],k=n.map(e),t[25]=n,t[26]=_,t[27]=a,t[28]=i,t[29]=k}else k=t[29];let A;return t[34]!==v||t[35]!==E||t[36]!==D||t[37]!==O||t[38]!==k||t[39]!==C?(A=(0,q.jsxs)(`div`,{ref:g,role:`listbox`,"aria-label":C,"aria-activedescendant":v,tabIndex:-1,onMouseDown:x,className:`w-64 overflow-y-auto subtle-scrollbar rounded-lg border bg-popover p-1 shadow-md`,style:w,children:[E,D,O,k]}),t[34]=v,t[35]=E,t[36]=D,t[37]=O,t[38]=k,t[39]=C,t[40]=A):A=t[40],A}function zy(e){return e.preventDefault()}function By(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`),f(r,n,{placement:`bottom-start`,middleware:[x(4),B(),xe({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:()=>Pe(r,n,o),reveal:()=>{a||(i=!0,o())}}}function Vy(e){e.stopAutoUpdate?.(),e.stopAutoUpdate=null,e.popup?.remove(),e.popup=null}var Hy=new H(`wikiLinkSuggestion`),Uy=8;function Wy(e){let t=e.indexOf(`#`);return t>0?{mode:`anchor`,pageTarget:e.slice(0,t),anchorQuery:e.slice(t+1)}:{mode:`page`,pageTarget:``,anchorQuery:``}}function Gy(e,t){return t?Fy.default.go(t,e,{keys:[`title`,`docName`],threshold:-1e4}).map(e=>e.obj).slice(0,Uy):e.slice(0,Uy)}function Ky(e,t){return t?Fy.default.go(t,e,{key:`text`,threshold:-1e4}).map(e=>e.obj).slice(0,Uy):e.slice(0,Uy)}function qy(e,t){let n=Gy(e,t);if(n.length>0)return n.map(e=>({kind:`page`,...e}));let r=Rv(t);return r?[{kind:`create`,docName:r.target,title:t.trim(),actionLabel:`Insert unresolved link "${t.trim()}"`}]:[]}function Jy(e,t,n){return Ky(t,n).map(t=>({kind:`anchor`,docName:e,level:t.level,text:t.text,slug:t.slug}))}function Yy(e){let{mode:t,pageTarget:n,anchorQuery:r}=Wy(e);return t===`anchor`&&n?{target:n,alias:null,anchor:r.trim()||null}:Rv(e)}function Xy(e){let{$position:t}=e,n=t.parent.textBetween(0,t.parentOffset,void 0,``),r=n.match(/\[\[([^\]]*)$/);if(!r)return null;let i=r[1];return{range:{from:t.start()+n.lastIndexOf(`[[`),to:t.pos},query:i,text:r[0]}}async function Zy(){let e=await fetch(`/api/pages`);if(!e.ok)throw Error(`/api/pages responded with ${e.status}`);let t=await e.json();return Array.isArray(t.pages)?t.pages:[]}async function Qy(e){let t=await fetch(`/api/page-headings?docName=${encodeURIComponent(e)}`);if(!t.ok)throw Error(`/api/page-headings responded with ${t.status}`);let n=await t.json();return n.ok&&Array.isArray(n.headings)?n.headings:[]}function $y(e){let t=[],n=!1,r=!1,i=new Map,a=null,o=null,s=null;return Py({editor:e,pluginKey:Hy,char:`[[`,allowedPrefixes:null,findSuggestionMatch:Xy,items:async({query:e})=>{let{mode:c,pageTarget:l,anchorQuery:u}=Wy(e);if(c===`anchor`){if(!i.has(l)&&a!==l){a=l;try{let e=await Qy(l);i.set(l,e),s=null}catch(e){console.error(`[wiki-link-suggestion] Failed to fetch headings:`,e),i.set(l,[]),s=`Failed to load headings for ${l}. Press Escape and type [[ again to retry.`}finally{a=null}}return Jy(l,i.get(l)??[],u)}if(!n&&!r){r=!0;try{t=await Zy(),o=null}catch(e){console.error(`[wiki-link-suggestion] Failed to fetch pages:`,e),o=`Failed to load pages. Press Escape and type [[ again to retry, or continue typing to insert an unresolved link.`,t=[]}finally{n=!0,r=!1}}return qy(t,e)},command:({editor:e,range:t,props:n})=>{try{let r=null;if(n.kind===`page`?r={target:n.docName,alias:null,anchor:null}:n.kind===`anchor`?r={target:n.docName,alias:null,anchor:n.slug}:n.kind===`create`&&(r=Rv(n.title)),!r)return;e.chain().focus().deleteRange(t).insertContent({type:`wikiLink`,attrs:r}).run()}catch(e){console.error(`[wiki-link-suggestion] command failed`,{item:n,range:t},e)}},render:()=>{let e=null,c=null,l=0,u={popup:null,stopAutoUpdate:null},d=null,f=null,p=e=>{c?.command(e)};function m(e,t,r){let{mode:a,pageTarget:c,anchorQuery:u}=Wy(e.query??``),d=t===null?a===`anchor`?!i.has(c):!n:t;return{items:e.items,query:e.query??``,selectedIndex:l,onSelect:r,loading:d,error:a===`page`?o:s,mode:a,pageTarget:c,anchorQuery:u}}let h=t=>{!e||!c||e.updateProps(m(c,t,p))},g=()=>{if(!c)return;let{editor:e,range:t}=c,n=Yy(c.query??``);if(n)try{e.chain().focus().deleteRange(t).insertContent({type:`wikiLink`,attrs:n}).run()}catch(e){console.error(`[wiki-link-suggestion] fallback insert error:`,e)}};return{onBeforeStart(t){c=t,l=0;let n=By(()=>c,`wiki-link-suggestion`);u.popup=n.popup,d=n.doPosition,f=n.reveal,e=new Oi(Ry,{props:m(t,!0,p),editor:t.editor}),n.popup.appendChild(e.element),u.stopAutoUpdate=n.startAutoUpdate()},onBeforeUpdate(e){let t=c?Wy(c.query??``).mode:null,n=Wy(e.query??``).mode;c=e,t!==n&&(l=0,h(!0))},onStart(e){c=e,l=0,h(null),f?.()},onUpdate(e){c=e,l=Math.min(l,Math.max(0,e.items.length-1)),h(null),d?.()},onKeyDown({event:e}){if(!c)return!1;let t=c.items;if(e.key===`ArrowDown`)return t.length===0?!1:(l=(l+1)%t.length,h(null),!0);if(e.key===`ArrowUp`)return t.length===0?!1:(l=(l-1+t.length)%t.length,h(null),!0);if(e.key===`Enter`||e.key===`Tab`){let e=t[l];return e?c.command(e):g(),!0}return e.key,!1},onExit(){Vy(u),d=null,f=null,e?.destroy(),e=null,c=null,l=0,t=[],i=new Map,o=null,s=null,n=!1,r=!1,a=null}}}})}function eb(e,t){let n=(0,rr.c)(4),[r,i]=(0,G.useState)(null),a,o;return n[0]!==e||n[1]!==t?(a=()=>{if(!t||!e){i(null);return}let n=!1;return i(null),Qy(e).then(e=>{n||i(e)}).catch(()=>{n||i([])}),()=>{n=!0}},o=[e,t],n[0]=e,n[1]=t,n[2]=a,n[3]=o):(a=n[2],o=n[3]),(0,G.useEffect)(a,o),r}function tb(e,t){let n=e.trim();return n?n.startsWith(`#`)?`anchor`:n.startsWith(`/`)||Me(n)?`external`:`doc`:t}function nb(e){return e?.kind===`doc`?`doc`:e?.kind===`anchor`?`anchor`:`external`}function rb(e){let t=(0,rr.c)(64),{open:n,href:r,pages:i,onOpenChange:s,onSave:c}=e,[l,u]=(0,G.useState)(``),[d,f]=(0,G.useState)(``),[p,m]=(0,G.useState)(`doc`),h=(0,G.useId)(),g=(0,G.useId)(),_=(0,G.useId)(),v,y;t[0]!==r||t[1]!==n?(v=()=>{if(!n)return;let e=Gv(r);if(m(nb(e)),e?.kind===`doc`){u(e.docName),f(e.anchor??``);return}if(e?.kind===`anchor`){u(`#${e.anchor}`),f(``);return}u(e?.kind===`external`?e.url:r),f(``)},y=[r,n],t[0]=r,t[1]=n,t[2]=v,t[3]=y):(v=t[2],y=t[3]),(0,G.useEffect)(v,y);let b,x,S;t[4]!==p||t[5]!==l||t[6]!==i?(b=we(l),x=p===`doc`,S=x&&Bv(b,i),t[4]=p,t[5]=l,t[6]=i,t[7]=b,t[8]=x,t[9]=S):(b=t[7],x=t[8],S=t[9]);let C=eb(b,S&&n),w=!!C?.length,T;t[10]!==b||t[11]!==x||t[12]!==d||t[13]!==l||t[14]!==s||t[15]!==c?(T=function(){let e=l.trim();e&&(c(x?$v(b,d.trim()||null):e),s(!1))},t[10]=b,t[11]=x,t[12]=d,t[13]=l,t[14]=s,t[15]=c,t[16]=T):T=t[16];let E=T,D;t[17]===E?D=t[18]:(D=function(e){e.key===`Enter`&&(e.preventDefault(),E())},t[17]=E,t[18]=D);let O=D,k;t[19]===Symbol.for(`react.memo_cache_sentinel`)?(k=(0,q.jsx)(Le,{className:`fixed inset-0 z-50 bg-black/40 data-open:animate-in data-open:fade-in-0 data-closed:animate-out data-closed:fade-out-0`}),t[19]=k):k=t[19];let A,j;t[20]===Symbol.for(`react.memo_cache_sentinel`)?(A=(0,q.jsx)(Ve,{className:`mb-1 text-base font-semibold`,children:`Edit markdown link`}),j=(0,q.jsx)(qe,{className:`mb-4 text-sm text-muted-foreground`,children:`Update the destination and optional section anchor.`}),t[20]=A,t[21]=j):(A=t[20],j=t[21]);let M=x?`Page`:`Link target`,N;t[22]!==M||t[23]!==h?(N=(0,q.jsx)(`label`,{className:`mb-1.5 block text-sm font-medium`,htmlFor:h,children:M}),t[22]=M,t[23]=h,t[24]=N):N=t[24];let P;t[25]===Symbol.for(`react.memo_cache_sentinel`)?(P=e=>{let t=e.target.value;u(t),m(e=>tb(t,e))},t[25]=P):P=t[25];let F;t[26]!==l||t[27]!==O||t[28]!==h?(F=(0,q.jsx)(ry,{id:h,value:l,onChange:P,placeholder:`guides/install or https://example.com`,autoFocus:!0,onKeyDown:O}),t[26]=l,t[27]=O,t[28]=h,t[29]=F):F=t[29];let I;t[30]===x?I=t[31]:(I=x?(0,q.jsx)(`p`,{className:`mt-1.5 text-xs text-muted-foreground`,children:`This changes the destination page. The visible link text stays editable inline in the document.`}):null,t[30]=x,t[31]=I);let ee;t[32]!==N||t[33]!==F||t[34]!==I?(ee=(0,q.jsxs)(`div`,{children:[N,F,I]}),t[32]=N,t[33]=F,t[34]=I,t[35]=ee):ee=t[35];let L;t[36]!==g||t[37]!==x||t[38]!==d||t[39]!==O||t[40]!==_||t[41]!==C||t[42]!==w?(L=x?(0,q.jsxs)(`div`,{children:[(0,q.jsxs)(`label`,{className:`mb-1.5 block text-sm font-medium`,htmlFor:g,children:[`Section`,` `,(0,q.jsx)(`span`,{className:`font-normal text-muted-foreground`,children:`(optional heading anchor)`})]}),(0,q.jsx)(ry,{id:g,value:d,onChange:e=>f(e.target.value),placeholder:`heading-slug`,"aria-controls":w?_:void 0,"aria-expanded":w?!0:void 0,"aria-haspopup":w?`listbox`:void 0,onKeyDown:O}),w?(0,q.jsx)(`div`,{role:`listbox`,id:_,"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:C.map(e=>(0,q.jsxs)(`button`,{type:`button`,role:`option`,"aria-selected":d===e.slug,className:a(`flex w-full items-center gap-2 px-2 py-1 text-left text-sm hover:bg-accent hover:text-accent-foreground`,d===e.slug&&`bg-accent text-accent-foreground`),style:{paddingLeft:`${(e.level-1)*12+8}px`},onClick:()=>f(d===e.slug?``:e.slug),children:[(0,q.jsxs)(`span`,{className:`w-7 shrink-0 font-mono text-[10px] text-muted-foreground`,children:[`H`,e.level]}),(0,q.jsx)(`span`,{className:`truncate`,children:e.text})]},`${e.slug}-${e.level}-${e.text}`))}):null]}):null,t[36]=g,t[37]=x,t[38]=d,t[39]=O,t[40]=_,t[41]=C,t[42]=w,t[43]=L):L=t[43];let R;t[44]!==ee||t[45]!==L?(R=(0,q.jsxs)(`div`,{className:`mb-4 space-y-6`,children:[ee,L]}),t[44]=ee,t[45]=L,t[46]=R):R=t[46];let z;t[47]===s?z=t[48]:(z=(0,q.jsx)(o,{variant:`outline`,onClick:()=>s(!1),children:`Cancel`}),t[47]=s,t[48]=z);let B;t[49]===l?B=t[50]:(B=l.trim(),t[49]=l,t[50]=B);let V=!B,te;t[51]!==E||t[52]!==V?(te=(0,q.jsx)(o,{onClick:E,disabled:V,children:`Save`}),t[51]=E,t[52]=V,t[53]=te):te=t[53];let ne;t[54]!==z||t[55]!==te?(ne=(0,q.jsxs)(`div`,{className:`flex justify-end gap-2`,children:[z,te]}),t[54]=z,t[55]=te,t[56]=ne):ne=t[56];let re;t[57]!==R||t[58]!==ne?(re=(0,q.jsxs)(Re,{children:[k,(0,q.jsxs)(Be,{"data-slot":`dialog-content`,"data-ok-layer-spawned":``,className:`fixed left-1/2 top-1/2 z-50 w-full max-w-md -translate-x-1/2 -translate-y-1/2 rounded-lg border border-border bg-background p-6 shadow-xl data-open:animate-in data-open:fade-in-0 data-open:zoom-in-95 data-closed:animate-out data-closed:fade-out-0 data-closed:zoom-out-95`,children:[A,j,R,ne]})]}),t[57]=R,t[58]=ne,t[59]=re):re=t[59];let ie;return t[60]!==s||t[61]!==n||t[62]!==re?(ie=(0,q.jsx)(Ue,{open:n,onOpenChange:s,children:re}),t[60]=s,t[61]=n,t[62]=re,t[63]=ie):ie=t[63],ie}function ib(e){let t=(0,rr.c)(81),{editor:n,nodeId:r,sourceDocName:i,onClose:s}=e,c=Ey(n.state,r),l=c?.attrs?.href??``,[u,d]=(0,G.useState)(!1),[f,p]=(0,G.useState)(null),{folderPaths:m,pages:h,loading:g}=pe();if(!c||!l)return null;let _=te(l,i),v;t[0]!==n||t[1]!==r?(v=function(e){let t=Ey(n.state,r);t&&n.chain().setTextSelection({from:t.from,to:t.to}).extendMarkRange(`link`).updateAttributes(`link`,{href:e}).run()},t[0]=n,t[1]=r,t[2]=v):v=t[2];let y=v,b;t[3]!==n||t[4]!==r||t[5]!==s?(b=function(){let e=Ey(n.state,r);e&&(n.chain().focus().setTextSelection({from:e.from,to:e.to}).extendMarkRange(`link`).unsetLink().run(),s())},t[3]=n,t[4]=r,t[5]=s,t[6]=b):b=t[6];let x=b,S=function(e){if(_){if(_.kind===`external`){Qv(_);return}if(_.kind===`anchor`||_.kind===`doc`){let t=_.kind===`doc`?_.docName:i,n=_.anchor??null;e.newTab?Yv({docName:t,anchor:n}):window.location.assign(Kv({docName:t,anchor:n}))}}},C=function(e){if(f!==`missing`)return;let t=Ey(n.state,r);t&&n.chain().setTextSelection({from:t.from,to:t.to}).extendMarkRange(`link`).updateAttributes(`link`,{href:$v(e,_?.kind===`doc`?_.anchor??null:null)}).run()},w,T=!1,E=!1,D=null;if(g){let e;t[7]===Symbol.for(`react.memo_cache_sentinel`)?(e=(0,q.jsx)(Gn,{className:`size-3.5 shrink-0 animate-spin`,"aria-hidden":`true`}),t[7]=e):e=t[7],w={icon:e,text:`Loading…`,className:`text-muted-foreground`}}else if(_?.kind===`external`){let e;t[8]===Symbol.for(`react.memo_cache_sentinel`)?(e=(0,q.jsx)(Pn,{className:`size-3.5 shrink-0`,"aria-hidden":`true`}),t[8]=e):e=t[8],w={icon:e,text:`External link`,className:`text-foreground`}}else if(_?.kind===`anchor`){let e;t[9]===Symbol.for(`react.memo_cache_sentinel`)?(e=(0,q.jsx)(In,{className:`size-3.5 shrink-0`,"aria-hidden":`true`}),t[9]=e):e=t[9],w={icon:e,text:`Anchor in this page`,className:`text-foreground`}}else if(_?.kind===`doc`){let e=ty(_.docName,{pages:h,folderPaths:m});if(D=ny(e),E=e.kind===`navigate`&&e.displayState===`folder`,T=e.kind===`create`,E){let e;t[10]===Symbol.for(`react.memo_cache_sentinel`)?(e=(0,q.jsx)(Ln,{className:`size-3.5 shrink-0`,"aria-hidden":`true`}),t[10]=e):e=t[10],w={icon:e,text:`Folder (no index)`,className:`text-foreground`}}else if(T){let e;t[11]===Symbol.for(`react.memo_cache_sentinel`)?(e=(0,q.jsx)(Mn,{className:`size-3.5 shrink-0`,"aria-hidden":`true`}),t[11]=e):e=t[11],w={icon:e,text:`Page not found`,className:`text-red-700 dark:text-red-300`}}else{let e;t[12]===Symbol.for(`react.memo_cache_sentinel`)?(e=(0,q.jsx)(In,{className:`size-3.5 shrink-0`,"aria-hidden":`true`}),t[12]=e):e=t[12],w={icon:e,text:`Page link`,className:`text-foreground`}}}else{let e;t[13]===Symbol.for(`react.memo_cache_sentinel`)?(e=(0,q.jsx)(Mn,{className:`size-3.5 shrink-0`,"aria-hidden":`true`}),t[13]=e):e=t[13],w={icon:e,text:`Unrecognized link`,className:`text-muted-foreground`}}let O=a(`text-sm font-medium`,w.className),k;t[14]!==w.text||t[15]!==O?(k=(0,q.jsx)(`div`,{className:O,children:w.text}),t[14]=w.text,t[15]=O,t[16]=k):k=t[16];let A;t[17]===l?A=t[18]:(A=(0,q.jsx)(`div`,{className:`truncate text-xs text-muted-foreground`,title:l,children:l}),t[17]=l,t[18]=A);let j;t[19]!==k||t[20]!==A?(j=(0,q.jsxs)(`div`,{className:`flex-1 min-w-0`,children:[k,A]}),t[19]=k,t[20]=A,t[21]=j):j=t[21];let M;t[22]!==S||t[23]!==T||t[24]!==s||t[25]!==_?.kind?(M=T?null:(0,q.jsx)(o,{size:`sm`,variant:`default`,onClick:()=>{S({}),s()},children:_?.kind===`external`?`Open in new tab`:`Open`}),t[22]=S,t[23]=T,t[24]=s,t[25]=_?.kind,t[26]=M):M=t[26];let N;t[27]!==T||t[28]!==p?(N=T?(0,q.jsx)(o,{size:`sm`,variant:`default`,onClick:()=>p(`missing`),children:`Create page`}):null,t[27]=T,t[28]=p,t[29]=N):N=t[29];let P;t[30]!==D||t[31]!==E||t[32]!==p?(P=E&&D?(0,q.jsxs)(o,{size:`sm`,variant:`outline`,onClick:()=>p(`folder-index`),children:[(0,q.jsx)(Fn,{className:`size-3.5`,"aria-hidden":`true`}),`Create index`]}):null,t[30]=D,t[31]=E,t[32]=p,t[33]=P):P=t[33];let F;t[34]===d?F=t[35]:(F=()=>d(!0),t[34]=d,t[35]=F);let I;t[36]===Symbol.for(`react.memo_cache_sentinel`)?(I=(0,q.jsx)(qn,{className:`size-3.5`,"aria-hidden":`true`}),t[36]=I):I=t[36];let ee;t[37]===F?ee=t[38]:(ee=(0,q.jsxs)(o,{size:`sm`,variant:`outline`,onClick:F,children:[I,`Edit`]}),t[37]=F,t[38]=ee);let L;t[39]===Symbol.for(`react.memo_cache_sentinel`)?(L=(0,q.jsx)(Xn,{className:`size-3.5`,"aria-hidden":`true`}),t[39]=L):L=t[39];let R;t[40]===x?R=t[41]:(R=(0,q.jsxs)(o,{size:`sm`,variant:`outline`,className:`text-red-700 hover:bg-red-50 hover:text-red-800 dark:text-red-300 dark:hover:bg-red-100/10 dark:hover:text-red-200`,onClick:x,children:[L,`Remove`]}),t[40]=x,t[41]=R);let z;t[42]!==P||t[43]!==ee||t[44]!==R||t[45]!==M||t[46]!==N?(z=(0,q.jsxs)(`div`,{className:`flex flex-wrap gap-1.5`,children:[M,N,P,ee,R]}),t[42]=P,t[43]=ee,t[44]=R,t[45]=M,t[46]=N,t[47]=z):z=t[47];let B=f!==null,V;t[48]===p?V=t[49]:(V=e=>{e||p(null)},t[48]=p,t[49]=V);let ne;t[50]!==f||t[51]!==D||t[52]!==m||t[53]!==T||t[54]!==h||t[55]!==_?(ne=f===`folder-index`&&D?D.initialDir:T&&_?.kind===`doc`&&ty(_.docName,{pages:h,folderPaths:m}).kind===`create`?ty(_.docName,{pages:h,folderPaths:m}).initialDir:``,t[50]=f,t[51]=D,t[52]=m,t[53]=T,t[54]=h,t[55]=_,t[56]=ne):ne=t[56];let re;t[57]!==f||t[58]!==D||t[59]!==m||t[60]!==T||t[61]!==h||t[62]!==_?(re=f===`folder-index`&&D?D.suggestedName:T&&_?.kind===`doc`&&ty(_.docName,{pages:h,folderPaths:m}).kind===`create`?ty(_.docName,{pages:h,folderPaths:m}).suggestedName:void 0,t[57]=f,t[58]=D,t[59]=m,t[60]=T,t[61]=h,t[62]=_,t[63]=re):re=t[63];let ie;t[64]!==f||t[65]!==D||t[66]!==_?(ie=f===`folder-index`&&D?(0,q.jsxs)(q.Fragment,{children:[`Create an index note for`,` `,(0,q.jsxs)(`span`,{className:`font-medium text-foreground`,children:[D.initialDir,`/`]})]}):(0,q.jsxs)(q.Fragment,{children:[`Create a page for`,` `,(0,q.jsx)(`span`,{className:`font-medium text-foreground`,children:_?.kind===`doc`?_.docName:``})]}),t[64]=f,t[65]=D,t[66]=_,t[67]=ie):ie=t[67];let ae;t[68]!==C||t[69]!==B||t[70]!==V||t[71]!==ne||t[72]!==re||t[73]!==ie?(ae=(0,q.jsx)(ly,{open:B,onOpenChange:V,kind:`file`,initialDir:ne,suggestedName:re,description:ie,onCreated:C}),t[68]=C,t[69]=B,t[70]=V,t[71]=ne,t[72]=re,t[73]=ie,t[74]=ae):ae=t[74];let oe;return t[75]!==u||t[76]!==y||t[77]!==l||t[78]!==h||t[79]!==d?(oe=(0,q.jsx)(rb,{open:u,href:l,pages:h,onOpenChange:d,onSave:y}),t[75]=u,t[76]=y,t[77]=l,t[78]=h,t[79]=d,t[80]=oe):oe=t[80],(0,q.jsxs)(q.Fragment,{children:[(0,q.jsxs)(ey,{kind:`internal-link`,ariaLabel:`Link options`,onDeactivate:s,children:[(0,q.jsxs)(`div`,{className:`mb-2 flex items-start gap-2 pr-8`,children:[(0,q.jsx)(`div`,{className:a(`mt-0.5 flex shrink-0`,w.className),children:w.icon}),j]}),z]}),ae,oe]})}function ab(e,t,n){let r=te(e,t);if(!r)return`unresolved`;if(r.kind===`external`)return`external`;if(r.kind===`anchor`)return`anchor`;if(n===null)return`loading`;let i=ty(r.docName,{pages:n.pages,folderPaths:n.folderPaths});return i.kind===`create`?`unresolved`:i.displayState}function ob(e,t,n){let r=e.attrs?.href;return typeof r!=`string`||r.length===0?null:{"data-resolution-state":ab(r,n,t)}}function sb(e){return(t,n)=>ob(t,n,e)}var cb=new H(`linkResolutionDecoration`);function lb(e,t,n,r,i){if(t.size===0)return null;let a=[];for(let e of t.values()){if(!n.has(e.markType))continue;let t=r(e,i);t!==null&&a.push(Ae.inline(e.from,e.to,t))}return a.length===0?null:L.create(e,a)}function ub(e){let t=new Set(e.markTypes),{computeAttrs:n}=e;return new M({key:cb,state:{init:()=>({version:0}),apply(e,t){let n=e.getMeta(cb);return n&&typeof n==`object`&&n.refresh?{version:t.version+1}:t}},props:{decorations(e){let r=by.getState(e);if(!r)return null;let i=ie();return lb(e.doc,r.byId,t,n,i)}},view(e){let t=ye(()=>{e.dispatch(e.state.tr.setMeta(cb,{refresh:!0}))});return{destroy(){t()}}}})}var db=new H(`markIdentityDecoration`),fb=`data-mark-id`;function pb(){return new M({key:db,props:{decorations(e){let t=by.getState(e);if(!t||t.byId.size===0)return null;let n=[];for(let e of t.byId.values())n.push(Ae.inline(e.from,e.to,{[fb]:e.id}));return L.create(e.doc,n)}}})}var mb=S.extend({addOptions(){return{...this.parent?.(),docName:``}},renderHTML({HTMLAttributes:e}){let t=typeof e.href==`string`?e.href:``;return[`span`,je(e,{"data-link":``,role:`link`,tabindex:`0`,"aria-label":t?`Link: ${t}`:`Link`,style:`touch-action: manipulation;`}),0]},addProseMirrorPlugins(){let e=this.options.docName??``;return[ky({editor:this.editor,markTypes:[`link`],renderPropPanel:({editor:t,nodeId:n,deactivate:r})=>(0,G.createElement)(ib,{editor:t,nodeId:n,sourceDocName:e,onClose:r}),handlePrimary:({editor:t,nodeId:n,newTab:r})=>{if(!r)return!1;let i=Ey(t.state,n)?.attrs?.href;if(typeof i!=`string`||!i)return!1;let a=te(i,e);return a?a.kind===`doc`?(Yv({docName:a.docName,anchor:a.anchor}),!0):a.kind===`anchor`?(Yv({docName:e,anchor:a.anchor}),!0):Uv(a.url)?(qv(a.url),!0):!1:!1}}),pb(),ub({markTypes:[`link`],computeAttrs:sb(e)})]}}),hb={warning:`bg-amber-100 text-amber-900 dark:bg-amber-900/40 dark:text-amber-200`,info:`bg-sky-100 text-sky-900 dark:bg-sky-900/40 dark:text-sky-200`,error:`bg-red-100 text-red-900 dark:bg-red-900/40 dark:text-red-200`},gb={warning:`alert`,error:`alert`,info:`note`};function _b(e){let t=(0,rr.c)(11),{type:n,children:r}=e,i=gb[n]||`note`,o=hb[n]||`bg-muted text-foreground`,s;t[0]===o?s=t[1]:(s=a(`p-3 px-4 rounded-md`,o),t[0]=o,t[1]=s);let c;t[2]===n?c=t[3]:(c=n.toUpperCase(),t[2]=n,t[3]=c);let l;t[4]===c?l=t[5]:(l=(0,q.jsx)(`strong`,{children:c}),t[4]=c,t[5]=l);let u;return t[6]!==r||t[7]!==i||t[8]!==s||t[9]!==l?(u=(0,q.jsxs)(`div`,{role:i,className:s,children:[l,`: `,r]}),t[6]=r,t[7]=i,t[8]=s,t[9]=l,t[10]=u):u=t[10],u}function vb(e){let t=e.match(/<(\w+)/);return t?t[1]:`Unknown`}function yb(e){let t=(0,rr.c)(19),{editor:n,getPos:r,onDismiss:i}=e,a;if(t[0]!==n||t[1]!==r){let e=r();a=vb((typeof e==`number`?n.state.doc.nodeAt(e):null)?.attrs.content??``),t[0]=n,t[1]=r,t[2]=a}else a=t[2];let s=a,c;t[3]!==n||t[4]!==r||t[5]!==i?(c=function(){let e=r();if(typeof e!=`number`)return;let t=n.state.doc.nodeAt(e);t&&(n.chain().focus().deleteRange({from:e,to:e+t.nodeSize}).run(),i())},t[3]=n,t[4]=r,t[5]=i,t[6]=c):c=t[6];let l=c,u;t[7]===Symbol.for(`react.memo_cache_sentinel`)?(u=(0,q.jsx)(`span`,{className:`text-xs text-muted-foreground`,children:`Component`}),t[7]=u):u=t[7];let d;t[8]===s?d=t[9]:(d=(0,q.jsx)(`code`,{className:`rounded bg-muted px-1.5 py-0.5 text-xs font-mono`,children:s}),t[8]=s,t[9]=d);let f;t[10]===Symbol.for(`react.memo_cache_sentinel`)?(f=(0,q.jsx)(`div`,{className:`flex-1`}),t[10]=f):f=t[10];let p;t[11]===l?p=t[12]:(p=(0,q.jsx)(o,{variant:`outline`,size:`sm`,onClick:l,children:`Delete`}),t[11]=l,t[12]=p);let m;t[13]!==d||t[14]!==p?(m=(0,q.jsxs)(`div`,{className:`flex items-center gap-2 pr-8`,children:[u,d,f,p]}),t[13]=d,t[14]=p,t[15]=m):m=t[15];let h;return t[16]!==i||t[17]!==m?(h=(0,q.jsx)(ey,{kind:`jsx-component`,ariaLabel:`Component properties`,onDeactivate:i,children:m}),t[16]=i,t[17]=m,t[18]=h):h=t[18],h}var bb=0;function xb(){return`jsx-${++bb}`}function Sb(e){let t=e.match(/<(\w+)\s+type="([^"]*)">([\s\S]*?)<\/\1>/);return t?{component:t[1],type:t[2],children:t[3].trim()}:{component:`Unknown`,type:`info`,children:e.trim()}}function Cb(e){let t=(0,rr.c)(17),{node:n,editor:r,getPos:i}=e,a=n.attrs.content||``,o;t[0]===a?o=t[1]:(o=Sb(a),t[0]=a,t[1]=o);let s=o,[c]=(0,G.useState)(xb),l=(0,G.useRef)(i),u,d;t[2]===i?(u=t[3],d=t[4]):(u=()=>{l.current=i},d=[i],t[2]=i,t[3]=u,t[4]=d),(0,G.useEffect)(u,d);let f,p;t[5]!==r||t[6]!==c?(f=()=>{let e=yy(r),t=()=>{let e=l.current();return typeof e==`number`?e:void 0};return e.register({type:`jsxComponent`,nodeId:c,getPos:t,controls:{propPanel:e=>(0,q.jsx)(yb,{editor:r,getPos:t,onDismiss:e.deactivate})}}),()=>{e.deregister(c)}},p=[r,c],t[5]=r,t[6]=c,t[7]=f,t[8]=p):(f=t[7],p=t[8]),(0,G.useEffect)(f,p);let m;t[9]!==a||t[10]!==s.children||t[11]!==s.component||t[12]!==s.type?(m=s.component===`Callout`?(0,q.jsx)(_b,{type:s.type,children:s.children}):(0,q.jsxs)(`div`,{className:`bg-muted dark:bg-muted/40 p-3 px-4 rounded-md font-mono text-[13px]`,children:[(0,q.jsxs)(`strong`,{children:[`<`,s.component,`>`]}),(0,q.jsx)(`pre`,{className:`mt-2 whitespace-pre-wrap`,children:a})]}),t[9]=a,t[10]=s.children,t[11]=s.component,t[12]=s.type,t[13]=m):m=t[13];let h;return t[14]!==c||t[15]!==m?(h=(0,q.jsx)(Si,{className:`jsx-component-wrapper`,contentEditable:!1,"data-node-id":c,children:m}),t[14]=c,t[15]=m,t[16]=h):h=t[16],h}var wb=R.extend({addNodeView(){return Ai(Cb)}}),Tb=`raw-mdx-nav`,Eb=0;function Db(){return`raw-mdx-${++Eb}`}function Ob(e){let t=e.doc??(typeof document<`u`?document:{createElement:null}),n=t.createElement(`div`);n.setAttribute(`data-raw-mdx-fallback`,``),n.setAttribute(`data-raw-badge`,`raw`),n.setAttribute(`data-node-id`,e.nodeId),n.setAttribute(`contenteditable`,`false`),n.setAttribute(`role`,`button`),n.setAttribute(`tabindex`,`0`),n.setAttribute(`aria-label`,`${e.reason??`Parse failed`} — click to edit`),n.classList.add(`raw-mdx-fallback-wrapper`),e.reason&&n.setAttribute(`data-reason`,e.reason);let r=t.createElement(`span`);r.classList.add(`raw-mdx-fallback-badge`),r.textContent=`raw`,r.setAttribute(`aria-hidden`,`true`),n.appendChild(r);let i=t.createElement(`pre`);return i.classList.add(`raw-mdx-fallback-content`),i.setAttribute(`contenteditable`,`false`),n.appendChild(i),{dom:n,contentDOM:i}}var kb=z.extend({addNodeView(){return({editor:e,node:t,getPos:n,HTMLAttributes:r})=>{let i=Db(),{dom:a,contentDOM:o}=Ob({nodeId:i,reason:r.reason??t.attrs.reason}),s=()=>{let e=n();return typeof e==`number`?e:void 0},c=yy(e);return c.register({type:`rawMdxFallback`,nodeId:i,getPos:s,controls:{},handlePrimary:()=>{let t=s();if(typeof t!=`number`)return!1;let n=e.state.doc.nodeAt(t)?.attrs.originalSpan??{start:0,end:0};return window.dispatchEvent(new CustomEvent(Tb,{detail:{offset:n.start}})),!0}}),{dom:a,contentDOM:o,ignoreMutation:()=>!0,destroy:()=>{c.deregister(i)}}}}}),Ab=[{name:`heading1`,label:`Heading 1`,icon:Rn,category:`basic`,command:e=>e.chain().focus().toggleHeading({level:1}).run(),aliases:[`h1`]},{name:`heading2`,label:`Heading 2`,icon:zn,category:`basic`,command:e=>e.chain().focus().toggleHeading({level:2}).run(),aliases:[`h2`]},{name:`heading3`,label:`Heading 3`,icon:Bn,category:`basic`,command:e=>e.chain().focus().toggleHeading({level:3}).run(),aliases:[`h3`]},{name:`bulletList`,label:`Bullet List`,icon:Wn,category:`basic`,command:e=>e.chain().focus().toggleBulletList().run(),aliases:[`ul`,`unordered`]},{name:`orderedList`,label:`Ordered List`,icon:Hn,category:`basic`,command:e=>e.chain().focus().toggleOrderedList().run(),aliases:[`ol`,`numbered`]},{name:`taskList`,label:`Task List`,icon:Un,category:`basic`,command:e=>e.chain().focus().toggleTaskList().run(),aliases:[`todo`,`checklist`,`checkbox`]},{name:`blockquote`,label:`Quote`,icon:Jn,category:`basic`,command:e=>e.chain().focus().toggleBlockquote().run(),aliases:[`quote`]},{name:`codeBlock`,label:`Code Block`,icon:Nn,category:`basic`,command:e=>e.chain().focus().toggleCodeBlock().run(),aliases:[`code`,`fence`]},{name:`table`,label:`Table`,icon:Yn,category:`insert`,command:e=>e.chain().focus().insertTable({rows:3,cols:3,withHeaderRow:!0}).run(),aliases:[`grid`]},{name:`separator`,label:`Separator`,icon:Kn,category:`insert`,command:e=>e.chain().focus().setHorizontalRule().run(),aliases:[`hr`,`divider`,`rule`]},{name:`image`,label:`Image`,icon:Vn,category:`insert`,aliases:[`img`,`photo`],command:e=>{let t=document.createElement(`input`);t.type=`file`,t.accept=b.join(`,`),t.onchange=()=>{let n=t.files?.[0];if(n){let t=e.state.selection.from;z_(n,e,t)}},t.click()}}];function jb(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 Mb(e){let t=(0,rr.c)(14),{items:n,selectedIndex:r,categoryLabels:i,onSelect:a}=e,o=(0,G.useRef)(null),s=(0,G.useId)(),c=r>=0&&r<n.length?`${s}-option-${r}`:void 0,l=Nb,u,d;if(t[0]===r?(u=t[1],d=t[2]):(u=()=>{let e=o.current;if(!e)return;let t=e.querySelectorAll(`[role="option"]`).item(r);t&&t.scrollIntoView({block:`nearest`})},d=[r],t[0]=r,t[1]=u,t[2]=d),(0,G.useEffect)(u,d),n.length===0){let e;return t[3]===Symbol.for(`react.memo_cache_sentinel`)?(e=(0,q.jsx)(`div`,{ref:o,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:l,children:`No results`}),t[3]=e):e=t[3],e}let f;if(t[4]!==c||t[5]!==i||t[6]!==n||t[7]!==s||t[8]!==a||t[9]!==r){let e=[],u=0,d=new Map;for(let t of n){d.set(t,u++);let n=e.find(e=>e.key===t.category);n?n.items.push(t):e.push({key:t.category,items:[t]})}let p=r>=0&&r<n.length?n[r]:null,m;t[11]===Symbol.for(`react.memo_cache_sentinel`)?(m={maxHeight:`var(--suggestion-menu-max-height, 40vh)`},t[11]=m):m=t[11];let h=p?p.label:``,g;t[12]===h?g=t[13]:(g=(0,q.jsx)(`span`,{className:`sr-only`,"aria-live":`polite`,"aria-atomic":`true`,children:h}),t[12]=h,t[13]=g),f=(0,q.jsxs)(`div`,{ref:o,role:`listbox`,"aria-label":`Slash commands`,"aria-activedescendant":c,tabIndex:-1,onMouseDown:l,className:`w-56 overflow-y-auto subtle-scrollbar rounded-lg border bg-popover p-1 shadow-md`,style:m,children:[g,e.map(e=>(0,q.jsxs)(`div`,{role:`group`,"aria-labelledby":`${s}-group-${e.key}`,children:[(0,q.jsx)(`div`,{id:`${s}-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=d.get(e)??0,n=t===r,i=e.icon;return(0,q.jsxs)(`button`,{id:`${s}-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`:``}`,onMouseDown:t=>{t.preventDefault(),a(e)},children:[(0,q.jsx)(i,{className:`size-4 shrink-0 text-muted-foreground`}),(0,q.jsx)(`div`,{className:`flex flex-col min-w-0`,children:(0,q.jsx)(`span`,{className:`truncate`,children:e.label})})]},e.name)})]},e.key))]}),t[4]=c,t[5]=i,t[6]=n,t[7]=s,t[8]=a,t[9]=r,t[10]=f}else f=t[10];return f}function Nb(e){return e.preventDefault()}var Pb=new H(`slashCommand`),Fb=me.create({name:`slashCommand`,addOptions(){return{itemsSources:[()=>Ab],categoryLabels:{basic:`Basic blocks`,insert:`Insert`}}},addProseMirrorPlugins(){let e=this;return[Py({editor:this.editor,pluginKey:Pb,char:`/`,startOfLine:!1,items:({query:t})=>jb(e.options.itemsSources.flatMap(e=>{try{return e()}catch(e){return console.error(`[slash-command] item source threw an error`,e),[]}}),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=()=>{!t||!n||t.updateProps({items:n.items,selectedIndex:r,categoryLabels:e.options.categoryLabels,onSelect:n.command})};return{onStart(o){n=o,r=0;let s=By(()=>n,`slash-command`);i.popup=s.popup,a=s.doPosition,t=new Oi(Mb,{props:{items:o.items,selectedIndex:r,categoryLabels:e.options.categoryLabels,onSelect:o.command},editor:o.editor}),s.popup.appendChild(t.element),i.stopAutoUpdate=s.startAutoUpdate(),s.reveal()},onUpdate(e){n=e,r=Math.min(r,Math.max(0,e.items.length-1)),o(),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,o(),!0;if(e.key===`ArrowUp`)return r=(r-1+t.length)%t.length,o(),!0;if(e.key===`Enter`||e.key===`Tab`){let e=t[r];return e&&n.command(e),!0}return e.key,!1},onExit(){Vy(i),a=null,t?.destroy(),t=null,n=null,r=0}}}})]}});function Ib(e){let t=(0,rr.c)(112),{open:n,target:r,alias:i,anchor:s,pages:c,onOpenChange:l,onSave:u}=e,[d,f]=(0,G.useState)(r),[p,m]=(0,G.useState)(i??``),[h,g]=(0,G.useState)(s??``),_=(0,G.useId)(),v=(0,G.useId)(),y=(0,G.useId)(),b=(0,G.useId)(),x;t[0]!==d||t[1]!==c?(x=Bv(d,c),t[0]=d,t[1]=c,t[2]=x):x=t[2];let S=eb(d,x&&n),C,w;t[3]!==i||t[4]!==s||t[5]!==n||t[6]!==r?(C=()=>{n&&(f(r),m(i??``),g(s??``))},w=[n,r,i,s],t[3]=i,t[4]=s,t[5]=n,t[6]=r,t[7]=C,t[8]=w):(C=t[7],w=t[8]),(0,G.useEffect)(C,w);let T;t[9]!==p||t[10]!==h||t[11]!==d||t[12]!==l||t[13]!==u?(T=function(){let e=d.trim();e&&(u(e,p.trim()||null,h.trim()||null),l(!1))},t[9]=p,t[10]=h,t[11]=d,t[12]=l,t[13]=u,t[14]=T):T=t[14];let E=T,D;t[15]===E?D=t[16]:(D=function(e){e.key===`Enter`&&E()},t[15]=E,t[16]=D);let O=D,k,A,j,M,N,P,F,I,ee,L,R,z,B,V,te,ne;if(t[17]!==v||t[18]!==h||t[19]!==d||t[20]!==O||t[21]!==b||t[22]!==S||t[23]!==l||t[24]!==n||t[25]!==_){let e=new Map,r=S?.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;j=Ue,R=n,z=l,A=Re,t[42]===Symbol.for(`react.memo_cache_sentinel`)?(L=(0,q.jsx)(Le,{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[42]=L):L=t[42],k=Be,N=`dialog-content`,P=``,F=`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[43]===Symbol.for(`react.memo_cache_sentinel`)?(I=(0,q.jsx)(Ve,{className:`mb-1 text-base font-semibold`,children:`Edit wiki link`}),ee=(0,q.jsx)(qe,{className:`mb-4 text-sm text-muted-foreground`,children:`Modify the link target, anchor, and display label.`}),t[43]=I,t[44]=ee):(I=t[43],ee=t[44]),ne=`mb-4 space-y-6`;let o;t[45]===Symbol.for(`react.memo_cache_sentinel`)?(o=(0,q.jsx)(`span`,{className:`text-red-500`,children:`*`}),t[45]=o):o=t[45];let s;t[46]===_?s=t[47]:(s=(0,q.jsxs)(`label`,{className:`mb-1.5 block text-sm font-medium`,htmlFor:_,children:[`Page `,o]}),t[46]=_,t[47]=s);let c;t[48]===Symbol.for(`react.memo_cache_sentinel`)?(c=e=>f(e.target.value),t[48]=c):c=t[48];let u;t[49]!==d||t[50]!==O||t[51]!==_?(u=(0,q.jsx)(ry,{id:_,value:d,onChange:c,placeholder:`page-name`,autoFocus:!0,"aria-required":`true`,onKeyDown:O}),t[49]=d,t[50]=O,t[51]=_,t[52]=u):u=t[52],t[53]!==s||t[54]!==u?(M=(0,q.jsxs)(`div`,{children:[s,u]}),t[53]=s,t[54]=u,t[55]=M):M=t[55];let p;t[56]===Symbol.for(`react.memo_cache_sentinel`)?(p=(0,q.jsx)(`span`,{className:`font-normal text-muted-foreground`,children:`(optional heading anchor)`}),t[56]=p):p=t[56],t[57]===v?B=t[58]:(B=(0,q.jsxs)(`label`,{className:`mb-1.5 block text-sm font-medium`,htmlFor:v,children:[`Section`,` `,p]}),t[57]=v,t[58]=B);let m;t[59]===Symbol.for(`react.memo_cache_sentinel`)?(m=e=>g(e.target.value),t[59]=m):m=t[59],t[60]!==v||t[61]!==h||t[62]!==O?(V=(0,q.jsx)(ry,{id:v,value:h,onChange:m,placeholder:`heading-slug`,onKeyDown:O}),t[60]=v,t[61]=h,t[62]=O,t[63]=V):V=t[63],te=i&&(0,q.jsx)(`div`,{role:`listbox`,id:b,"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,q.jsxs)(`button`,{type:`button`,role:`option`,"aria-selected":h===e.slug,className:a(`flex w-full items-center gap-2 px-2 py-1 text-left text-sm hover:bg-accent hover:text-accent-foreground`,h===e.slug&&`bg-accent text-accent-foreground`),style:{paddingLeft:`${(e.level-1)*12+8}px`},onClick:()=>g(h===e.slug?``:e.slug),children:[(0,q.jsxs)(`span`,{className:`w-7 shrink-0 font-mono text-[10px] text-muted-foreground`,children:[`H`,e.level]}),(0,q.jsx)(`span`,{className:`truncate`,children:e.text})]},e.reactKey))}),t[17]=v,t[18]=h,t[19]=d,t[20]=O,t[21]=b,t[22]=S,t[23]=l,t[24]=n,t[25]=_,t[26]=k,t[27]=A,t[28]=j,t[29]=M,t[30]=N,t[31]=P,t[32]=F,t[33]=I,t[34]=ee,t[35]=L,t[36]=R,t[37]=z,t[38]=B,t[39]=V,t[40]=te,t[41]=ne}else k=t[26],A=t[27],j=t[28],M=t[29],N=t[30],P=t[31],F=t[32],I=t[33],ee=t[34],L=t[35],R=t[36],z=t[37],B=t[38],V=t[39],te=t[40],ne=t[41];let re;t[64]!==B||t[65]!==V||t[66]!==te?(re=(0,q.jsxs)(`div`,{children:[B,V,te]}),t[64]=B,t[65]=V,t[66]=te,t[67]=re):re=t[67];let ie;t[68]===Symbol.for(`react.memo_cache_sentinel`)?(ie=(0,q.jsx)(`span`,{className:`font-normal text-muted-foreground`,children:`(optional display text)`}),t[68]=ie):ie=t[68];let ae;t[69]===y?ae=t[70]:(ae=(0,q.jsxs)(`label`,{className:`mb-1.5 block text-sm font-medium`,htmlFor:y,children:[`Label`,` `,ie]}),t[69]=y,t[70]=ae);let oe;t[71]===Symbol.for(`react.memo_cache_sentinel`)?(oe=e=>m(e.target.value),t[71]=oe):oe=t[71];let se;t[72]!==y||t[73]!==p||t[74]!==O?(se=(0,q.jsx)(ry,{id:y,value:p,onChange:oe,placeholder:`Custom display text`,onKeyDown:O}),t[72]=y,t[73]=p,t[74]=O,t[75]=se):se=t[75];let ce;t[76]!==ae||t[77]!==se?(ce=(0,q.jsxs)(`div`,{children:[ae,se]}),t[76]=ae,t[77]=se,t[78]=ce):ce=t[78];let le;t[79]!==M||t[80]!==re||t[81]!==ce||t[82]!==ne?(le=(0,q.jsxs)(`div`,{className:ne,children:[M,re,ce]}),t[79]=M,t[80]=re,t[81]=ce,t[82]=ne,t[83]=le):le=t[83];let ue;t[84]===l?ue=t[85]:(ue=(0,q.jsx)(o,{variant:`outline`,onClick:()=>l(!1),children:`Cancel`}),t[84]=l,t[85]=ue);let de;t[86]===d?de=t[87]:(de=d.trim(),t[86]=d,t[87]=de);let fe=!de,H;t[88]!==E||t[89]!==fe?(H=(0,q.jsx)(o,{onClick:E,disabled:fe,children:`Save`}),t[88]=E,t[89]=fe,t[90]=H):H=t[90];let pe;t[91]!==ue||t[92]!==H?(pe=(0,q.jsxs)(`div`,{className:`flex justify-end gap-2`,children:[ue,H]}),t[91]=ue,t[92]=H,t[93]=pe):pe=t[93];let me;t[94]!==k||t[95]!==N||t[96]!==P||t[97]!==F||t[98]!==I||t[99]!==ee||t[100]!==le||t[101]!==pe?(me=(0,q.jsxs)(k,{"data-slot":N,"data-ok-layer-spawned":P,className:F,children:[I,ee,le,pe]}),t[94]=k,t[95]=N,t[96]=P,t[97]=F,t[98]=I,t[99]=ee,t[100]=le,t[101]=pe,t[102]=me):me=t[102];let he;t[103]!==A||t[104]!==L||t[105]!==me?(he=(0,q.jsxs)(A,{children:[L,me]}),t[103]=A,t[104]=L,t[105]=me,t[106]=he):he=t[106];let ge;return t[107]!==j||t[108]!==R||t[109]!==z||t[110]!==he?(ge=(0,q.jsx)(j,{open:R,onOpenChange:z,children:he}),t[107]=j,t[108]=R,t[109]=z,t[110]=he,t[111]=ge):ge=t[111],ge}function Lb(e){let t=(0,rr.c)(112),{editor:n,getPos:r,onClose:i}=e,s=r(),c=s==null?null:n.state.doc.nodeAt(s),l=String(c?.attrs.target??``),u=ee(c?.attrs.alias),d=ee(c?.attrs.anchor),f=E({target:l,alias:u,anchor:d}),{folderPaths:p,pages:m,loading:h}=pe(),g=Oe(l,d),_=g?.kind===`external`?g:null,v=ty(l,{pages:m,folderPaths:p,fallbackTargets:zv(l)}),[y,b]=(0,G.useState)(!1),[x,S]=(0,G.useState)(null),C=ny(v);if(!c)return null;let w;t[0]!==n||t[1]!==r?(w=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,t[1]=r,t[2]=w):w=t[2];let T=w,D;t[3]!==n||t[4]!==r||t[5]!==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[3]=n,t[4]=r,t[5]=i,t[6]=D):D=t[6];let O=D,k;t[7]!==d||t[8]!==_||t[9]!==v||t[10]!==S?(k=function(e){if(_){Uv(_.url)?window.open(_.url,`_blank`,`noopener,noreferrer`):console.warn(`[safe-nav] blocked non-safe scheme:`,_.url);return}if(v.kind===`create`){S(`missing`);return}let t=v.hashDocName;if(e.newTab){Yv({docName:t,anchor:d});return}if(d){let e=window.location.hash.match(/^#\/([^?#/]+)/);if((e?decodeURIComponent(e[1]):null)===t){let e=document.getElementById(d);e&&e.scrollIntoView({behavior:`smooth`,block:`start`})}window.location.hash=`#/${t}?anchor=${encodeURIComponent(d)}`;return}window.location.hash=`#/${t}`},t[7]=d,t[8]=_,t[9]=v,t[10]=S,t[11]=k):k=t[11];let A=k,j;t[12]!==u||t[13]!==x||t[14]!==n||t[15]!==r||t[16]!==f||t[17]!==l?(j=function(e){if(x===`missing`&&e!==l){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:u??f}))}},t[12]=u,t[13]=x,t[14]=n,t[15]=r,t[16]=f,t[17]=l,t[18]=j):j=t[18];let M=j,N=!_&&!h&&v.kind===`navigate`&&v.displayState===`resolved`,P=!_&&!h&&v.kind===`navigate`&&v.displayState===`folder`,F=!_&&!h&&v.kind===`create`,I,L,R,z,B,V,te,ne,re;if(t[19]!==_||t[20]!==P||t[21]!==N||t[22]!==F||t[23]!==h||t[24]!==i){if(h){let e;t[34]===Symbol.for(`react.memo_cache_sentinel`)?(e=(0,q.jsx)(Gn,{className:`size-3.5 shrink-0 animate-spin`,"aria-hidden":`true`}),t[34]=e):e=t[34],L={icon:e,text:`Loading…`,className:`text-muted-foreground`}}else if(_){let e;t[35]===Symbol.for(`react.memo_cache_sentinel`)?(e=(0,q.jsx)(Pn,{className:`size-3.5 shrink-0`,"aria-hidden":`true`}),t[35]=e):e=t[35],L={icon:e,text:`External wiki link`,className:`text-foreground`}}else if(P){let e;t[36]===Symbol.for(`react.memo_cache_sentinel`)?(e=(0,q.jsx)(Ln,{className:`size-3.5 shrink-0`,"aria-hidden":`true`}),t[36]=e):e=t[36],L={icon:e,text:`Folder (no index)`,className:`text-foreground`}}else if(F){let e;t[37]===Symbol.for(`react.memo_cache_sentinel`)?(e=(0,q.jsx)(Mn,{className:`size-3.5 shrink-0`,"aria-hidden":`true`}),t[37]=e):e=t[37],L={icon:e,text:`Page not found`,className:`text-red-700 dark:text-red-300`}}else if(N){let e;t[38]===Symbol.for(`react.memo_cache_sentinel`)?(e=(0,q.jsx)(In,{className:`size-3.5 shrink-0`,"aria-hidden":`true`}),t[38]=e):e=t[38],L={icon:e,text:`Wiki link`,className:`text-foreground`}}else{let e;t[39]===Symbol.for(`react.memo_cache_sentinel`)?(e=(0,q.jsx)(Mn,{className:`size-3.5 shrink-0`,"aria-hidden":`true`}),t[39]=e):e=t[39],L={icon:e,text:`Unrecognized wiki link`,className:`text-muted-foreground`}}I=ey,re=`wiki-link`,R=`Wiki link options`,z=i,te=`mb-2 flex items-start gap-2 pr-8`,ne=(0,q.jsx)(`div`,{className:a(`mt-0.5 flex shrink-0`,L.className),children:L.icon}),V=`flex-1 min-w-0`,B=a(`text-sm font-medium`,L.className),t[19]=_,t[20]=P,t[21]=N,t[22]=F,t[23]=h,t[24]=i,t[25]=I,t[26]=L,t[27]=R,t[28]=z,t[29]=B,t[30]=V,t[31]=te,t[32]=ne,t[33]=re}else I=t[25],L=t[26],R=t[27],z=t[28],B=t[29],V=t[30],te=t[31],ne=t[32],re=t[33];let ie;t[40]!==L.text||t[41]!==B?(ie=(0,q.jsx)(`div`,{className:B,children:L.text}),t[40]=L.text,t[41]=B,t[42]=ie):ie=t[42];let ae=_?_.url:`[[${l}${d?`#${d}`:``}]]`,oe=_?_.url:`[[${l}${d?`#${d}`:``}]]`,se;t[43]!==ae||t[44]!==oe?(se=(0,q.jsx)(`div`,{className:`truncate text-xs text-muted-foreground`,title:ae,children:oe}),t[43]=ae,t[44]=oe,t[45]=se):se=t[45];let ce;t[46]!==ie||t[47]!==se||t[48]!==V?(ce=(0,q.jsxs)(`div`,{className:V,children:[ie,se]}),t[46]=ie,t[47]=se,t[48]=V,t[49]=ce):ce=t[49];let le;t[50]!==ce||t[51]!==te||t[52]!==ne?(le=(0,q.jsxs)(`div`,{className:te,children:[ne,ce]}),t[50]=ce,t[51]=te,t[52]=ne,t[53]=le):le=t[53];let ue;t[54]!==_||t[55]!==A||t[56]!==F||t[57]!==i?(ue=F?null:(0,q.jsx)(o,{size:`sm`,variant:`default`,onClick:()=>{A({}),i()},children:_?`Open in new tab`:`Open`}),t[54]=_,t[55]=A,t[56]=F,t[57]=i,t[58]=ue):ue=t[58];let de;t[59]!==F||t[60]!==S?(de=F?(0,q.jsx)(o,{size:`sm`,variant:`default`,onClick:()=>S(`missing`),children:`Create page`}):null,t[59]=F,t[60]=S,t[61]=de):de=t[61];let fe;t[62]!==C||t[63]!==P||t[64]!==S?(fe=P&&C?(0,q.jsxs)(o,{size:`sm`,variant:`outline`,onClick:()=>S(`folder-index`),children:[(0,q.jsx)(Fn,{className:`size-3.5`,"aria-hidden":`true`}),`Create index`]}):null,t[62]=C,t[63]=P,t[64]=S,t[65]=fe):fe=t[65];let H;t[66]===b?H=t[67]:(H=()=>b(!0),t[66]=b,t[67]=H);let me;t[68]===Symbol.for(`react.memo_cache_sentinel`)?(me=(0,q.jsx)(qn,{className:`size-3.5`,"aria-hidden":`true`}),t[68]=me):me=t[68];let he;t[69]===H?he=t[70]:(he=(0,q.jsxs)(o,{size:`sm`,variant:`outline`,onClick:H,children:[me,`Edit`]}),t[69]=H,t[70]=he);let ge;t[71]===Symbol.for(`react.memo_cache_sentinel`)?(ge=(0,q.jsx)(Xn,{className:`size-3.5`,"aria-hidden":`true`}),t[71]=ge):ge=t[71];let _e;t[72]===O?_e=t[73]:(_e=(0,q.jsxs)(o,{size:`sm`,variant:`outline`,className:`text-red-700 hover:bg-red-50 hover:text-red-800 dark:text-red-300 dark:hover:bg-red-100/10 dark:hover:text-red-200`,onClick:O,children:[ge,`Remove`]}),t[72]=O,t[73]=_e);let ve;t[74]!==ue||t[75]!==de||t[76]!==fe||t[77]!==he||t[78]!==_e?(ve=(0,q.jsxs)(`div`,{className:`flex flex-wrap gap-1.5`,children:[ue,de,fe,he,_e]}),t[74]=ue,t[75]=de,t[76]=fe,t[77]=he,t[78]=_e,t[79]=ve):ve=t[79];let ye;t[80]!==I||t[81]!==R||t[82]!==z||t[83]!==le||t[84]!==ve||t[85]!==re?(ye=(0,q.jsxs)(I,{kind:re,ariaLabel:R,onDeactivate:z,children:[le,ve]}),t[80]=I,t[81]=R,t[82]=z,t[83]=le,t[84]=ve,t[85]=re,t[86]=ye):ye=t[86];let be=x!==null,xe;t[87]===S?xe=t[88]:(xe=e=>{e||S(null)},t[87]=S,t[88]=xe);let Se=x===`folder-index`&&C?C.initialDir:v.kind===`create`?v.initialDir:``,Ce=x===`folder-index`&&C?C.suggestedName:v.kind===`create`?v.suggestedName:void 0,we;t[89]!==x||t[90]!==C||t[91]!==l?(we=x===`folder-index`&&C?(0,q.jsxs)(q.Fragment,{children:[`Create an index note for`,` `,(0,q.jsxs)(`span`,{className:`font-medium text-foreground`,children:[C.initialDir,`/`]})]}):(0,q.jsxs)(q.Fragment,{children:[`Create a page for `,(0,q.jsx)(`span`,{className:`font-medium text-foreground`,children:l})]}),t[89]=x,t[90]=C,t[91]=l,t[92]=we):we=t[92];let Te;t[93]!==M||t[94]!==be||t[95]!==xe||t[96]!==Se||t[97]!==Ce||t[98]!==we?(Te=(0,q.jsx)(ly,{open:be,onOpenChange:xe,kind:`file`,initialDir:Se,suggestedName:Ce,description:we,onCreated:M}),t[93]=M,t[94]=be,t[95]=xe,t[96]=Se,t[97]=Ce,t[98]=we,t[99]=Te):Te=t[99];let Ee;t[100]!==u||t[101]!==d||t[102]!==y||t[103]!==T||t[104]!==m||t[105]!==b||t[106]!==l?(Ee=(0,q.jsx)(Ib,{open:y,target:l,alias:u,anchor:d,pages:m,onOpenChange:b,onSave:T}),t[100]=u,t[101]=d,t[102]=y,t[103]=T,t[104]=m,t[105]=b,t[106]=l,t[107]=Ee):Ee=t[107];let De;return t[108]!==ye||t[109]!==Te||t[110]!==Ee?(De=(0,q.jsxs)(q.Fragment,{children:[ye,Te,Ee]}),t[108]=ye,t[109]=Te,t[110]=Ee,t[111]=De):De=t[111],De}var Rb=0;function zb(){return`wiki-link-${++Rb}`}function Bb(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 Vb=C.extend({priority:200,addNodeView(){return({editor:e,node:t,getPos:n})=>{let r=zb(),{dom:i}=Bb({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=yy(e);return s.register({type:`wikiLink`,nodeId:r,getPos:o,controls:{propPanel:t=>(0,G.createElement)(Lb,{editor:e,getPos:o,onClose:t.deactivate})},handlePrimary:({newTab:e})=>{if(!e)return!1;let t=a.attrs,n=typeof t.target==`string`?t.target:``;if(!n)return!1;let r=Oe(n,typeof t.anchor==`string`?t.anchor:null);return r?r.kind===`doc`?(Yv({docName:r.docName,anchor:r.anchor}),!0):Uv(r.url)?(qv(r.url),!0):!1:!1}}),{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(Hy.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(Hy.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[$y(this.editor)]}}),Hb=[...v.map(e=>e.name===`jsxComponent`?wb:e.name===`rawMdxFallback`?kb:e.name===`wikiLink`?Vb:e.name===`link`?mb:e),Fb,N_.configure({allowedMimeTypes:[...b],onDrop(e,t,n){for(let r of t)z_(r,e,n)},onPaste(e,t,n){for(let n of t)z_(n,e,e.state.selection.from)}}),Vv,Lv,W_];function Ub(e){return e===T}var Wb=0;function Gb(){return Wb}function Kb(){Wb=Date.now()}function qb(e){let{xmlFragment:t,ytext:n}=e,r=(e,t)=>{},i=(e,t)=>{};return t.observeDeep(r),n.observe(i),()=>{t.unobserveDeep(r),n.unobserve(i)}}var Jb=3e4,Yb=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}},Xb=class extends Error{docName;constructor(e){super(`Provider disconnected before sync for "${e}"`),this.name=`PreSyncDisconnectError`,this.docName=e}},Zb=class extends Error{docName;constructor(e){super(`Document not found: "${e}"`),this.name=`DocumentNotFoundError`,this.docName=e}},Qb=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}},$b=new Map,ex=!1;function tx(){for(let e of $b.values())if(!e.settled)return!0;return!1}function nx(){typeof document>`u`||document.visibilityState===`visible`&&rx(Date.now())}function rx(e){let t=[];for(let[n,r]of $b){if(r.settled)continue;let i=e-r.createdAt;if(i<3e4)continue;r.settled=!0;let a=new Yb(n,i);sx(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 tx()||ax(),t.length}function ix(){ex||typeof document>`u`||(document.addEventListener(`visibilitychange`,nx),ex=!0)}function ax(){ex&&(typeof document>`u`||(document.removeEventListener(`visibilitychange`,nx),ex=!1))}var ox=new Map;function sx(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 cx(e,t){let n=$b.get(e);if(n)return n.promise;let r=ox.get(e);if(r!==void 0){ox.delete(e);let n=r===`timeout`?new Yb(e,0):new Xb(e);console.warn(`[syncPromise] ${e} rejected on creation (test hook, armed ${r}): ${n.message}`),K(`ok/sync/create`,{docName:e,warm:!1,armed:r}),K(`ok/sync/reject`,{docName:e,reason:`armed-${r}`});let i=ux(n);return $b.set(e,dx(i,t)),i}if(t.synced){console.log(`[syncPromise] ${e} resolved synchronously (warm provider)`),K(`ok/sync/create`,{docName:e,warm:!0}),K(`ok/sync/resolve`,{docName:e,elapsedMs:0,warm:!0});let n=Promise.resolve();return $b.set(e,lx(n,t)),n}let i=Date.now(),a=()=>{},o=()=>{},s=new Promise((e,t)=>{a=e,o=t}),c=()=>{let t=$b.get(e);if(!t||t.settled)return;t.settled=!0;let n=Date.now()-t.createdAt;console.log(`[syncPromise] ${e} resolved in ${n}ms`),K(`ok/sync/resolve`,{docName:e,elapsedMs:n,warm:!1}),sx(t),tx()||ax(),t.resolve()},l=t=>{let n=$b.get(e);if(!n||n.settled)return;n.settled=!0;let r=new Xb(e);console.warn(`[syncPromise] ${e} rejected: ${r.message}`),K(`ok/sync/reject`,{docName:e,reason:`pre-sync-disconnect`}),sx(n),tx()||ax(),n.reject(r)},u=setTimeout(()=>{let t=$b.get(e);if(!t||t.settled)return;t.settled=!0;let n=Date.now()-t.createdAt,r=new Yb(e,n);console.warn(`[syncPromise] ${e} rejected: ${r.message}`),K(`ok/sync/reject`,{docName:e,reason:`timeout`,elapsedMs:n}),sx(t),tx()||ax(),t.reject(r)},Jb),d={promise:s,resolve:a,reject:o,createdAt:i,timeoutHandle:u,provider:t,onSynced:c,onClose:l,settled:!1,detached:!1};return $b.set(e,d),t.on(`synced`,c),t.on(`close`,l),ix(),K(`ok/sync/create`,{docName:e,warm:!1}),s}function lx(e,t){return{promise:e,resolve:()=>{},reject:()=>{},createdAt:Date.now(),timeoutHandle:null,provider:t,onSynced:()=>{},onClose:()=>{},settled:!0,detached:!0}}function ux(e){let t=Promise.reject(e);t.catch(()=>{});let n=t;return n.status=`rejected`,n.reason=e,n}function dx(e,t){return{promise:e,resolve:()=>{},reject:()=>{},createdAt:Date.now(),timeoutHandle:null,provider:t,onSynced:()=>{},onClose:()=>{},settled:!0,detached:!0}}function fx(e){let t=$b.get(e);t&&(t.settled=!0,sx(t),$b.delete(e),tx()||ax())}function px(e,t){let n=$b.get(e);return!n||n.settled?!1:(n.settled=!0,console.warn(`[syncPromise] ${e} rejected: ${t.message}`),sx(n),tx()||ax(),n.reject(t),!0)}var mx=ce(Hb),hx=4e3,gx=5e3,_x=class{entries=new Map;lruOrder=[];activeDocName=null;maxSize;wsUrl;recycleDebounceMs;onChange=null;tabIdentity=null;constructor(e,t,n){this.maxSize=e,this.wsUrl=t,this.recycleDebounceMs=n??hx}setTabIdentity(e){this.tabIdentity=e}setOnChange(e){this.onChange=e}notify(){this.onChange?.()}touch(e){let t=this.lruOrder.indexOf(e);t!==-1&&this.lruOrder.splice(t,1),this.lruOrder.push(e)}open(e){if(Ub(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=new l_({url:this.wsUrl,name:e,forceSyncInterval:gx,...this.tabIdentity===null?{}:{token:JSON.stringify(this.tabIdentity)}}),r={provider:n,observerCleanup:null,syncState:`connecting`,docName:e,lastAccessedAt:Date.now(),hasSynced:!1,tearingDown:!1,pendingRecycleTimer:null,bridgeSetupFailed:!1};return n.on(`status`,({status:t})=>{r.tearingDown||this.entries.get(e)!==r||t===`disconnected`&&(r.syncState=`disconnected`,this.notify())}),n.on(`synced`,()=>{if(!(r.tearingDown||this.entries.get(e)!==r)&&(r.syncState=`synced`,r.hasSynced=!0,r.pendingRecycleTimer&&=(clearTimeout(r.pendingRecycleTimer),null),this.notify(),!r.observerCleanup))try{let t=n.document,i=new ue({extensions:Hb});r.observerCleanup=qb({doc:t,xmlFragment:t.getXmlFragment(`default`),ytext:t.getText(`source`),mdManager:i,schema:mx,onSyncError:(t,n)=>{console.warn(`[Sync] ${t} failed for ${e}:`,n.message)}})}catch(t){console.error(`[ProviderPool] setupObservers init failed for ${e}:`,t),r.bridgeSetupFailed=!0,px(e,new Qb(e,t))}}),n.on(`disconnect`,()=>{r.tearingDown||this.entries.get(e)!==r||(r.syncState=`disconnected`,this.notify(),r.hasSynced&&n.unsyncedChanges===0&&!r.pendingRecycleTimer&&(r.pendingRecycleTimer=setTimeout(()=>{r.pendingRecycleTimer=null,!(r.tearingDown||this.entries.get(e)!==r)&&this.recycleDisconnectedEntry(e)},this.recycleDebounceMs)))}),this.entries.set(e,r),this.touch(e),this.notify(),r}prewarm(e){if(Ub(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.activeDocName===e&&(this.activeDocName=null),this.notify())}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}evictLru(){for(let e of this.lruOrder)if(e!==this.activeDocName){K(`ok/pool/evict-lru`,{docName:e}),this.close(e);return}}destroyEntry(e){e.tearingDown=!0,e.pendingRecycleTimer&&=(clearTimeout(e.pendingRecycleTimer),null),fx(e.docName),b_(e.docName),C_(e.docName),e.observerCleanup?.(),e.observerCleanup=null;try{e.provider.destroy()}catch(t){console.warn(`[ProviderPool] Provider destroy failed for ${e.docName}:`,t)}}recycleDisconnectedEntry(e){let t=this.entries.get(e);if(!t||t.tearingDown)return;let n=this.activeDocName===e;if(K(`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()}},vx=crypto.randomUUID(),yx=`ok-pin-v1`,bx=!1;function xx(e){bx||(bx=!0,console.warn(`[DocumentContext] localStorage unavailable — pinned doc will not persist across tabs/reloads.`,e))}function Sx(){if(typeof window>`u`)return null;try{return window.localStorage.getItem(yx)}catch(e){return xx(e),null}}function Cx(e){if(!(typeof window>`u`))try{e===null?window.localStorage.removeItem(yx):window.localStorage.setItem(yx,e)}catch(e){xx(e)}}var wx=(0,G.createContext)(null),Tx=null;function Ex(e){return Tx||=new _x(10,e),Tx}var Dx={activeDocName:null,activeProvider:null,syncState:`connecting`,poolEntries:[]};function Ox(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`,poolEntries:n}}function kx(e){let t=(0,rr.c)(43),{children:n}=e,[r,i]=(0,G.useState)(Dx),[a,o]=(0,G.useState)(null),[s,c]=(0,G.useState)(null),[l,u]=(0,G.useState)(null),{collabUrl:d,terminal:f,lastError:p,retry:m}=Sm(),h,g;t[0]===d?(h=t[1],g=t[2]):(h=()=>{if(d===null)return;let e=Ex(d);i(Ox(e)),e.setOnChange(()=>i(Ox(e)));let t=Sx();return t!==null&&c(t),fetch(`/api/principal`).then(jx).then(t=>{t&&typeof t.id==`string`&&e.setTabIdentity({principalId:t.id,tabSessionId:vx})}).catch(Ax),()=>{e.setOnChange(null)}},g=[d],t[0]=d,t[1]=h,t[2]=g),(0,G.useEffect)(h,g);let _,v;t[3]===Symbol.for(`react.memo_cache_sentinel`)?(_=()=>{},v=[],t[3]=_,t[4]=v):(_=t[3],v=t[4]),(0,G.useEffect)(_,v);let y;t[5]===d?y=t[6]:(y=e=>{if(K(`ok/nav/open-document`,{docName:e,transition:!1}),d===null)return;let t=Ex(d);t.open(e)&&(t.setActive(e),o({kind:`doc`,target:e,docName:e}))},t[5]=d,t[6]=y);let b=y,x;t[7]===b?x=t[8]:(x=e=>{K(`ok/nav/open-document`,{docName:e,transition:!1}),b(e)},t[7]=b,t[8]=x);let S=x,C;t[9]===d?C=t[10]:(C=e=>{if(d===null)return;let t=Ex(d),n=F(e);n?(t.open(n),t.setActive(n)):t.clearActive(),o(e)},t[9]=d,t[10]=C);let w=C,T;t[11]===w?T=t[12]:(T=e=>{K(`ok/nav/open-target`,{docName:F(e),kind:e.kind,transition:!1}),w(e)},t[11]=w,t[12]=T);let E=T,D,O,k,A;t[13]===d?(D=t[14],O=t[15],k=t[16],A=t[17]):(A=()=>{if(d===null){o(null);return}Ex(d).clearActive(),o(null)},D=e=>{d!==null&&(Ex(d).close(e),o(t=>t&&(F(t)===e?null:t)))},O=e=>{d!==null&&Ex(d).recycle(e)},k=e=>{d!==null&&Ex(d).prewarm(e)},t[13]=d,t[14]=D,t[15]=O,t[16]=k,t[17]=A);let j,M;t[18]===Symbol.for(`react.memo_cache_sentinel`)?(j=e=>{c(e),Cx(e)},M=()=>{c(null),Cx(null)},t[18]=j,t[19]=M):(j=t[18],M=t[19]);let N;t[20]!==a||t[21]!==p||t[22]!==f||t[23]!==d||t[24]!==b||t[25]!==S||t[26]!==w||t[27]!==E||t[28]!==s||t[29]!==m||t[30]!==r.activeDocName||t[31]!==r.activeProvider||t[32]!==r.poolEntries||t[33]!==r.syncState||t[34]!==l||t[35]!==D||t[36]!==O||t[37]!==k||t[38]!==A?(N={activeTarget:a,activeDocName:r.activeDocName,activeProvider:r.activeProvider,syncState:r.syncState,poolEntries:r.poolEntries,openDocument:b,openDocumentTransition:S,openTarget:w,openTargetTransition:E,clearTarget:A,closeDocument:D,recycleDocument:O,prewarm:k,pinnedDoc:s,pin:j,unpin:M,systemProvider:l,setSystemProvider:u,collabUrl:d,collabTerminal:f,collabLastError:p,retryCollab:m},t[20]=a,t[21]=p,t[22]=f,t[23]=d,t[24]=b,t[25]=S,t[26]=w,t[27]=E,t[28]=s,t[29]=m,t[30]=r.activeDocName,t[31]=r.activeProvider,t[32]=r.poolEntries,t[33]=r.syncState,t[34]=l,t[35]=D,t[36]=O,t[37]=k,t[38]=A,t[39]=N):N=t[39];let P=N,I;return t[40]!==n||t[41]!==P?(I=(0,q.jsx)(wx,{value:P,children:n}),t[40]=n,t[41]=P,t[42]=I):I=t[42],I}function Ax(){}function jx(e){return e.ok?e.json():null}function Mx(){let e=(0,G.use)(wx);if(!e)throw Error(`useDocumentContext must be used within <DocumentProvider />`);return e}function Nx(){let e=(0,rr.c)(3),{openDocumentTransition:t,openTargetTransition:n}=Mx(),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}var Px=new Map;function Fx(e,t){Px.set(e,t)}function Ix(e){let t=Px.get(e)??null;return Px.delete(e),t}function Lx(e){Px.delete(e)}var Rx=class e{static create(t,n,r,i,a){return new e(t,n,r,i+(i<<8)+t+(n<<4)|0,a,[],[])}constructor(e,t,n,r,i,a,o){this.type=e,this.value=t,this.from=n,this.hash=r,this.end=i,this.children=a,this.positions=o,this.hashProp=[[Ze.contextHash,r]]}addChild(e,t){e.prop(Ze.contextHash)!=this.hash&&(e=new at(e.type,e.children,e.positions,e.length,this.hashProp)),this.children.push(e),this.positions.push(t)}toTree(e,t=this.end){let n=this.children.length-1;return n>=0&&(t=Math.max(t,this.positions[n]+this.children[n].length+this.from)),new at(e.types[this.type],this.children,this.positions,t-this.from).balance({makeTree:(e,t,n)=>new at(ot.none,e,t,n,this.hashProp)})}},Z;(function(e){e[e.Document=1]=`Document`,e[e.CodeBlock=2]=`CodeBlock`,e[e.FencedCode=3]=`FencedCode`,e[e.Blockquote=4]=`Blockquote`,e[e.HorizontalRule=5]=`HorizontalRule`,e[e.BulletList=6]=`BulletList`,e[e.OrderedList=7]=`OrderedList`,e[e.ListItem=8]=`ListItem`,e[e.ATXHeading1=9]=`ATXHeading1`,e[e.ATXHeading2=10]=`ATXHeading2`,e[e.ATXHeading3=11]=`ATXHeading3`,e[e.ATXHeading4=12]=`ATXHeading4`,e[e.ATXHeading5=13]=`ATXHeading5`,e[e.ATXHeading6=14]=`ATXHeading6`,e[e.SetextHeading1=15]=`SetextHeading1`,e[e.SetextHeading2=16]=`SetextHeading2`,e[e.HTMLBlock=17]=`HTMLBlock`,e[e.LinkReference=18]=`LinkReference`,e[e.Paragraph=19]=`Paragraph`,e[e.CommentBlock=20]=`CommentBlock`,e[e.ProcessingInstructionBlock=21]=`ProcessingInstructionBlock`,e[e.Escape=22]=`Escape`,e[e.Entity=23]=`Entity`,e[e.HardBreak=24]=`HardBreak`,e[e.Emphasis=25]=`Emphasis`,e[e.StrongEmphasis=26]=`StrongEmphasis`,e[e.Link=27]=`Link`,e[e.Image=28]=`Image`,e[e.InlineCode=29]=`InlineCode`,e[e.HTMLTag=30]=`HTMLTag`,e[e.Comment=31]=`Comment`,e[e.ProcessingInstruction=32]=`ProcessingInstruction`,e[e.Autolink=33]=`Autolink`,e[e.HeaderMark=34]=`HeaderMark`,e[e.QuoteMark=35]=`QuoteMark`,e[e.ListMark=36]=`ListMark`,e[e.LinkMark=37]=`LinkMark`,e[e.EmphasisMark=38]=`EmphasisMark`,e[e.CodeMark=39]=`CodeMark`,e[e.CodeText=40]=`CodeText`,e[e.CodeInfo=41]=`CodeInfo`,e[e.LinkTitle=42]=`LinkTitle`,e[e.LinkLabel=43]=`LinkLabel`,e[e.URL=44]=`URL`})(Z||={});var zx=class{constructor(e,t){this.start=e,this.content=t,this.marks=[],this.parsers=[]}},Bx=class{constructor(){this.text=``,this.baseIndent=0,this.basePos=0,this.depth=0,this.markers=[],this.pos=0,this.indent=0,this.next=-1}forward(){this.basePos>this.pos&&this.forwardInner()}forwardInner(){let e=this.skipSpace(this.basePos);this.indent=this.countIndent(e,this.pos,this.indent),this.pos=e,this.next=e==this.text.length?-1:this.text.charCodeAt(e)}skipSpace(e){return Wx(this.text,e)}reset(e){for(this.text=e,this.baseIndent=this.basePos=this.pos=this.indent=0,this.forwardInner(),this.depth=1;this.markers.length;)this.markers.pop()}moveBase(e){this.basePos=e,this.baseIndent=this.countIndent(e,this.pos,this.indent)}moveBaseColumn(e){this.baseIndent=e,this.basePos=this.findColumn(e)}addMarker(e){this.markers.push(e)}countIndent(e,t=0,n=0){for(let r=t;r<e;r++)n+=this.text.charCodeAt(r)==9?4-n%4:1;return n}findColumn(e){let t=0;for(let n=0;t<this.text.length&&n<e;t++)n+=this.text.charCodeAt(t)==9?4-n%4:1;return t}scrub(){if(!this.baseIndent)return this.text;let e=``;for(let t=0;t<this.basePos;t++)e+=` `;return e+this.text.slice(this.basePos)}};function Vx(e,t,n){if(n.pos==n.text.length||e!=t.block&&n.indent>=t.stack[n.depth+1].value+n.baseIndent)return!0;if(n.indent>=n.baseIndent+4)return!1;let r=(e.type==Z.OrderedList?Zx:Xx)(n,t,!1);return r>0&&(e.type!=Z.BulletList||Jx(n,t,!1)<0)&&n.text.charCodeAt(n.pos+r-1)==e.value}var Hx={[Z.Blockquote](e,t,n){return n.next==62?(n.markers.push(Q(Z.QuoteMark,t.lineStart+n.pos,t.lineStart+n.pos+1)),n.moveBase(n.pos+(Ux(n.text.charCodeAt(n.pos+1))?2:1)),e.end=t.lineStart+n.text.length,!0):!1},[Z.ListItem](e,t,n){return n.indent<n.baseIndent+e.value&&n.next>-1?!1:(n.moveBaseColumn(n.baseIndent+e.value),!0)},[Z.OrderedList]:Vx,[Z.BulletList]:Vx,[Z.Document](){return!0}};function Ux(e){return e==32||e==9||e==10||e==13}function Wx(e,t=0){for(;t<e.length&&Ux(e.charCodeAt(t));)t++;return t}function Gx(e,t,n){for(;t>n&&Ux(e.charCodeAt(t-1));)t--;return t}function Kx(e){if(e.next!=96&&e.next!=126)return-1;let t=e.pos+1;for(;t<e.text.length&&e.text.charCodeAt(t)==e.next;)t++;if(t<e.pos+3)return-1;if(e.next==96){for(let n=t;n<e.text.length;n++)if(e.text.charCodeAt(n)==96)return-1}return t}function qx(e){return e.next==62?e.text.charCodeAt(e.pos+1)==32?2:1:-1}function Jx(e,t,n){if(e.next!=42&&e.next!=45&&e.next!=95)return-1;let r=1;for(let t=e.pos+1;t<e.text.length;t++){let n=e.text.charCodeAt(t);if(n==e.next)r++;else if(!Ux(n))return-1}return n&&e.next==45&&$x(e)>-1&&e.depth==t.stack.length&&t.parser.leafBlockParsers.indexOf(dS.SetextHeading)>-1||r<3?-1:1}function Yx(e,t){for(let n=e.stack.length-1;n>=0;n--)if(e.stack[n].type==t)return!0;return!1}function Xx(e,t,n){return(e.next==45||e.next==43||e.next==42)&&(e.pos==e.text.length-1||Ux(e.text.charCodeAt(e.pos+1)))&&(!n||Yx(t,Z.BulletList)||e.skipSpace(e.pos+2)<e.text.length)?1:-1}function Zx(e,t,n){let r=e.pos,i=e.next;for(;i>=48&&i<=57;){if(r++,r==e.text.length)return-1;i=e.text.charCodeAt(r)}return r==e.pos||r>e.pos+9||i!=46&&i!=41||r<e.text.length-1&&!Ux(e.text.charCodeAt(r+1))||n&&!Yx(t,Z.OrderedList)&&(e.skipSpace(r+1)==e.text.length||r>e.pos+1||e.next!=49)?-1:r+1-e.pos}function Qx(e){if(e.next!=35)return-1;let t=e.pos+1;for(;t<e.text.length&&e.text.charCodeAt(t)==35;)t++;if(t<e.text.length&&e.text.charCodeAt(t)!=32)return-1;let n=t-e.pos;return n>6?-1:n}function $x(e){if(e.next!=45&&e.next!=61||e.indent>=e.baseIndent+4)return-1;let t=e.pos+1;for(;t<e.text.length&&e.text.charCodeAt(t)==e.next;)t++;let n=t;for(;t<e.text.length&&Ux(e.text.charCodeAt(t));)t++;return t==e.text.length?n:-1}var eS=/^[ \t]*$/,tS=/-->/,nS=/\?>/,rS=[[/^<(?:script|pre|style)(?:\s|>|$)/i,/<\/(?:script|pre|style)>/i],[/^\s*<!--/,tS],[/^\s*<\?/,nS],[/^\s*<![A-Z]/,/>/],[/^\s*<!\[CDATA\[/,/\]\]>/],[/^\s*<\/?(?:address|article|aside|base|basefont|blockquote|body|caption|center|col|colgroup|dd|details|dialog|dir|div|dl|dt|fieldset|figcaption|figure|footer|form|frame|frameset|h1|h2|h3|h4|h5|h6|head|header|hr|html|iframe|legend|li|link|main|menu|menuitem|nav|noframes|ol|optgroup|option|p|param|section|source|summary|table|tbody|td|tfoot|th|thead|title|tr|track|ul)(?:\s|\/?>|$)/i,eS],[/^\s*(?:<\/[a-z][\w-]*\s*>|<[a-z][\w-]*(\s+[a-z:_][\w-.]*(?:\s*=\s*(?:[^\s"'=<>`]+|'[^']*'|"[^"]*"))?)*\s*>)\s*$/i,eS]];function iS(e,t,n){if(e.next!=60)return-1;let r=e.text.slice(e.pos);for(let e=0,t=rS.length-+!!n;e<t;e++)if(rS[e][0].test(r))return e;return-1}function aS(e,t){let n=e.countIndent(t,e.pos,e.indent),r=e.countIndent(e.skipSpace(t),t,n);return r>=n+5?n+1:r}function oS(e,t,n){let r=e.length-1;r>=0&&e[r].to==t&&e[r].type==Z.CodeText?e[r].to=n:e.push(Q(Z.CodeText,t,n))}var sS={LinkReference:void 0,IndentedCode(e,t){let n=t.baseIndent+4;if(t.indent<n)return!1;let r=t.findColumn(n),i=e.lineStart+r,a=e.lineStart+t.text.length,o=[],s=[];for(oS(o,i,a);e.nextLine()&&t.depth>=e.stack.length;)if(t.pos==t.text.length){oS(s,e.lineStart-1,e.lineStart);for(let e of t.markers)s.push(e)}else if(t.indent<n)break;else{if(s.length){for(let e of s)e.type==Z.CodeText?oS(o,e.from,e.to):o.push(e);s=[]}oS(o,e.lineStart-1,e.lineStart);for(let e of t.markers)o.push(e);a=e.lineStart+t.text.length;let n=e.lineStart+t.findColumn(t.baseIndent+4);n<a&&oS(o,n,a)}return s.length&&(s=s.filter(e=>e.type!=Z.CodeText),s.length&&(t.markers=s.concat(t.markers))),e.addNode(e.buffer.writeElements(o,-i).finish(Z.CodeBlock,a-i),i),!0},FencedCode(e,t){let n=Kx(t);if(n<0)return!1;let r=e.lineStart+t.pos,i=t.next,a=n-t.pos,o=t.skipSpace(n),s=Gx(t.text,t.text.length,o),c=[Q(Z.CodeMark,r,r+a)];o<s&&c.push(Q(Z.CodeInfo,e.lineStart+o,e.lineStart+s));for(let n=!0,r=!0,o=!1;e.nextLine()&&t.depth>=e.stack.length;n=!1){let s=t.pos;if(t.indent-t.baseIndent<4)for(;s<t.text.length&&t.text.charCodeAt(s)==i;)s++;if(s-t.pos>=a&&t.skipSpace(s)==t.text.length){for(let e of t.markers)c.push(e);r&&o&&oS(c,e.lineStart-1,e.lineStart),c.push(Q(Z.CodeMark,e.lineStart+t.pos,e.lineStart+s)),e.nextLine();break}else{o=!0,n||(oS(c,e.lineStart-1,e.lineStart),r=!1);for(let e of t.markers)c.push(e);let i=e.lineStart+t.basePos,a=e.lineStart+t.text.length;i<a&&(oS(c,i,a),r=!1)}}return e.addNode(e.buffer.writeElements(c,-r).finish(Z.FencedCode,e.prevLineEnd()-r),r),!0},Blockquote(e,t){let n=qx(t);return n<0?!1:(e.startContext(Z.Blockquote,t.pos),e.addNode(Z.QuoteMark,e.lineStart+t.pos,e.lineStart+t.pos+1),t.moveBase(t.pos+n),null)},HorizontalRule(e,t){if(Jx(t,e,!1)<0)return!1;let n=e.lineStart+t.pos;return e.nextLine(),e.addNode(Z.HorizontalRule,n),!0},BulletList(e,t){let n=Xx(t,e,!1);if(n<0)return!1;e.block.type!=Z.BulletList&&e.startContext(Z.BulletList,t.basePos,t.next);let r=aS(t,t.pos+1);return e.startContext(Z.ListItem,t.basePos,r-t.baseIndent),e.addNode(Z.ListMark,e.lineStart+t.pos,e.lineStart+t.pos+n),t.moveBaseColumn(r),null},OrderedList(e,t){let n=Zx(t,e,!1);if(n<0)return!1;e.block.type!=Z.OrderedList&&e.startContext(Z.OrderedList,t.basePos,t.text.charCodeAt(t.pos+n-1));let r=aS(t,t.pos+n);return e.startContext(Z.ListItem,t.basePos,r-t.baseIndent),e.addNode(Z.ListMark,e.lineStart+t.pos,e.lineStart+t.pos+n),t.moveBaseColumn(r),null},ATXHeading(e,t){let n=Qx(t);if(n<0)return!1;let r=t.pos,i=e.lineStart+r,a=Gx(t.text,t.text.length,r),o=a;for(;o>r&&t.text.charCodeAt(o-1)==t.next;)o--;(o==a||o==r||!Ux(t.text.charCodeAt(o-1)))&&(o=t.text.length);let s=e.buffer.write(Z.HeaderMark,0,n).writeElements(e.parser.parseInline(t.text.slice(r+n+1,o),i+n+1),-i);o<t.text.length&&s.write(Z.HeaderMark,o-r,a-r);let c=s.finish(Z.ATXHeading1-1+n,t.text.length-r);return e.nextLine(),e.addNode(c,i),!0},HTMLBlock(e,t){let n=iS(t,e,!1);if(n<0)return!1;let r=e.lineStart+t.pos,i=rS[n][1],a=[],o=i!=eS;for(;!i.test(t.text)&&e.nextLine();){if(t.depth<e.stack.length){o=!1;break}for(let e of t.markers)a.push(e)}o&&e.nextLine();let s=i==tS?Z.CommentBlock:i==nS?Z.ProcessingInstructionBlock:Z.HTMLBlock,c=e.prevLineEnd();return e.addNode(e.buffer.writeElements(a,-r).finish(s,c-r),r),!0},SetextHeading:void 0},cS=class{constructor(e){this.stage=0,this.elts=[],this.pos=0,this.start=e.start,this.advance(e.content)}nextLine(e,t,n){if(this.stage==-1)return!1;let r=n.content+`
|
|
4
|
+
`?a.insert.slice(0,-1):a.insert;(typeof o!=`string`||o.length>0)&&Wd(n,this,r,o,a.attributes||{})}else a.retain===void 0?a.delete!==void 0&&Xd(n,r,a.delete):Gd(n,this,r,a.retain,a.attributes||{})}})}toDelta(e,t,n){this.doc??ed();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(mu(s,e)||t!==void 0&&mu(s,t))switch(s.content.constructor){case Af:{let r=i.get(`ychange`);e!==void 0&&!mu(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&&!mu(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 Bf:case xf:{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 Cf:mu(s,e)&&(c(),Vd(i,s.content));break}s=s.right}c()};return e||t?Pu(a,n=>{e&&hu(n,e),t&&hu(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)):Pu(r,r=>{let i=zd(r,this,e,!n);n||(n={},i.currentAttributes.forEach((e,t)=>{n[t]=e})),Wd(r,this,i,t,n)})}insertEmbed(e,t,n){let r=this.doc;r===null?this._pending.push(()=>this.insertEmbed(e,t,n||{})):Pu(r,r=>{let i=zd(r,this,e,!n);Wd(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)):Pu(n,n=>{Xd(n,zd(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)):Pu(r,r=>{let i=zd(r,this,e,!1);i.right!==null&&Gd(r,this,i,t,n)})}removeAttribute(e){this.doc===null?this._pending.push(()=>this.removeAttribute(e)):Pu(this.doc,t=>{Cd(t,this,e)})}setAttribute(e,t){this.doc===null?this._pending.push(()=>this.setAttribute(e,t)):Pu(this.doc,n=>{wd(n,this,e,t)})}getAttribute(e){return Td(this,e)}getAttributes(){return Ed(this)}_write(e){e.writeTypeRef(Ff)}},$d=e=>new Qd,ef=class{constructor(e,t=()=>!0){this._filter=t,this._root=e,this._currentNode=e._start,this._firstCall=!0,e.doc??ed()}[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===rf||t.constructor===tf)&&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})}},tf=class e extends ud{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 ud?e.clone():e)),t}get length(){return this.doc??ed(),this._prelimContent===null?this._length:this._prelimContent.length}createTreeWalker(e){return new ef(this,e)}querySelector(e){e=e.toUpperCase();let t=new ef(this,t=>t.nodeName&&t.nodeName.toUpperCase()===e).next();return t.done?null:t.value}querySelectorAll(e){return e=e.toUpperCase(),Ui(new ef(this,t=>t.nodeName&&t.nodeName.toUpperCase()===e))}_callObserver(e,t){ld(this,e,new of(this,t,e))}toString(){return hd(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),md(this,i=>{r.insertBefore(i.toDOM(e,t,n),null)}),r}insert(e,t){this.doc===null?this._prelimContent.splice(e,0,...t):Pu(this.doc,n=>{bd(n,this,e,t)})}insertAfter(e,t){if(this.doc!==null)Pu(this.doc,n=>{let r=e&&e instanceof ud?e._item:e;vd(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 eo(`Reference item not found`);n.splice(r,0,...t)}}delete(e,t=1){this.doc===null?this._prelimContent.splice(e,t):Pu(this.doc,n=>{Sd(n,this,e,t)})}toArray(){return fd(this)}push(e){this.insert(this.length,e)}unshift(e){this.insert(0,e)}get(e){return _d(this,e)}slice(e=0,t=this.length){return dd(this,e,t)}forEach(e){md(this,e)}_write(e){e.writeTypeRef(Lf)}},nf=e=>new tf,rf=class e extends tf{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 Lo(this.getAttributes(),(e,n)=>{t.setAttribute(n,e)}),t.insert(0,this.toArray().map(e=>e instanceof ud?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):Pu(this.doc,t=>{Cd(t,this,e)})}setAttribute(e,t){this.doc===null?this._prelimAttrs.set(e,t):Pu(this.doc,n=>{wd(n,this,e,t)})}getAttribute(e){return Td(this,e)}hasAttribute(e){return Dd(this,e)}getAttributes(e){return e?Od(this,e):Ed(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 md(this,i=>{r.appendChild(i.toDOM(e,t,n))}),n!==void 0&&n._createAssociation(r,this),r}_write(e){e.writeTypeRef(If),e.writeKey(this.nodeName)}},af=e=>new rf(e.readKey()),of=class extends Qu{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)})}},sf=class e extends Pd{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(Rf),e.writeKey(this.hookName)}},cf=e=>new sf(e.readKey()),lf=class e extends Qd{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(zf)}},uf=e=>new lf,df=class{constructor(e,t){this.id=e,this.length=t}get deleted(){throw to()}mergeWith(e){return!1}write(e,t,n){throw to()}integrate(e,t){throw to()}},ff=0,pf=class extends df{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),yu(e.doc.store,this)}write(e,t){e.writeInfo(ff),e.writeLen(this.length-t)}getMissing(e,t){return null}},mf=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 to()}mergeWith(e){return!1}integrate(e,t){}delete(e){}gc(e){}write(e,t){e.writeBuf(this.content)}getRef(){return 3}},hf=e=>new mf(e.readBuf()),gf=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){pl(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}},_f=e=>new gf(e.readLen()),vf=(e,t)=>new bl({guid:e,...t,shouldLoad:t.shouldLoad||t.autoLoad||!1}),yf=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(vf(this.doc.guid,this.opts))}splice(e){throw to()}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}},bf=e=>new yf(vf(e.readString(),e.readAny())),xf=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 to()}mergeWith(e){return!1}integrate(e,t){}delete(e){}gc(e){}write(e,t){e.writeJSON(this.embed)}getRef(){return 5}},Sf=e=>new xf(e.readJSON()),Cf=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 to()}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}},wf=e=>new Cf(e.readKey(),e.readJSON()),Tf=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}},Ef=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 Tf(n)},Df=ts(`node_env`)===`development`,Of=class e{constructor(e){this.arr=e,Df&&Wo(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}},kf=e=>{let t=e.readLen(),n=[];for(let r=0;r<t;r++)n.push(e.readAny());return new Of(n)},Af=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}},jf=e=>new Af(e.readString()),Mf=[Md,Fd,$d,af,nf,cf,uf],Nf=0,Pf=1,Ff=2,If=3,Lf=4,Rf=5,zf=6,Bf=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 to()}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}},Vf=e=>new Bf(Mf[e.readTypeRef()](e)),Hf=(e,t)=>{let n=t,r=0,i;do r>0&&(n=X(n.client,n.clock+r)),i=xu(e,n),r=n.clock-i.id.clock,n=i.redone;while(n!==null&&i instanceof qf);return{item:i,diff:r}},Uf=(e,t)=>{for(;e!==null&&e.keep!==t;)e.keep=t,e=e.parent._item},Wf=(e,t,n)=>{let{client:r,clock:i}=t.id,a=new qf(X(r,i+n),t,X(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=X(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},Gf=(e,t)=>Gi(e,e=>ul(e.deletions,t)),Kf=(e,t,n,r,i,a)=>{let o=e.doc,s=o.store,c=o.clientID,l=t.redone;if(l!==null)return Cu(e,l);let u=t.parent._item,d=null,f;if(u!==null&&u.deleted===!0){if(u.redone===null&&(!n.has(u)||Kf(e,u,n,r,i,a)===null))return null;for(;u.redone!==null;)u=Cu(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:Cu(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:Cu(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||ul(r,d.right.id)||Gf(a.undoStack,d.right.id)||Gf(a.redoStack,d.right.id));)for(d=d.right;d.redone;)d=Cu(e,d.redone);if(d&&d.right!==null)return null}else d=p._map.get(t.parentSub)||null;let m=X(c,vu(s,c)),h=new qf(m,d,d&&d.lastId,f,f&&f.id,p,t.parentSub,t.content.copy());return t.redone=m,Uf(h,!0),h.integrate(e,0),h},qf=class e extends df{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>=vu(n,this.origin.client))return this.origin.client;if(this.rightOrigin&&this.rightOrigin.client!==this.id.client&&this.rightOrigin.clock>=vu(n,this.rightOrigin.client))return this.rightOrigin.client;if(this.parent&&this.parent.constructor===Zl&&this.id.client!==this.parent.client&&this.parent.clock>=vu(n,this.parent.client))return this.parent.client;if(this.origin&&=(this.left=wu(t,n,this.origin),this.left.lastId),this.rightOrigin&&=(this.right=Cu(t,this.rightOrigin),this.right.id),this.left&&this.left.constructor===pf||this.right&&this.right.constructor===pf)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===Zl){let e=xu(n,this.parent);e.constructor===pf?this.parent=null:this.parent=e.content.type}return null}integrate(e,t){if(t>0&&(this.id.clock+=t,this.left=wu(e,e.doc.store,X(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),Ql(this.origin,n.origin)){if(n.id.client<this.id.client)t=n,r.clear();else if(Ql(this.rightOrigin,n.rightOrigin))break}else if(n.origin!==null&&i.has(xu(e.doc.store,n.origin)))r.has(xu(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),yu(e.doc.store,this),this.content.integrate(e,this),ku(e,this.parent,this.parentSub),(this.parent._item!==null&&this.parent._item.deleted||this.parentSub!==null&&this.right!==null)&&this.delete(e)}else new pf(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:X(this.id.client,this.id.clock+this.length-1)}mergeWith(e){if(this.constructor===e.constructor&&Ql(e.origin,this.lastId)&&this.right===e&&Ql(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(),pl(e.deleteSet,this.id.client,this.id.clock,this.length),ku(e,t,this.parentSub),this.content.delete(e)}}gc(e,t){if(!this.deleted)throw no();this.content.gc(e),t?Tu(e,this,new pf(this.id,this.length)):this.content=new gf(this.length)}write(e,t){let n=t>0?X(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=$l(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===Zl?(e.writeParentInfo(!1),e.writeLeftID(t)):no();i!==null&&e.writeString(i)}this.content.write(e,t)}},Jf=(e,t)=>Yf[t&31](e),Yf=[()=>{no()},_f,Ef,hf,jf,Sf,wf,Vf,kf,bf,()=>{no()}],Xf=10,Zf=class extends df{get deleted(){return!0}delete(){}mergeWith(e){return this.constructor===e.constructor?(this.length+=e.length,!0):!1}integrate(e,t){no()}write(e,t){e.writeInfo(Xf),J(e.restEncoder,this.length-t)}getMissing(e,t){return null}},Qf=typeof globalThis<`u`?globalThis:typeof window<`u`?window:typeof global<`u`?global:{},$f=`__ $YJS$ __`;Qf[$f]===!0&&console.error(`Yjs was already imported. This breaks constructor checks and will lead to issues! - https://github.com/yjs/yjs/issues/438`),Qf[$f]=!0;var ep=()=>{let e=!0;return(t,n)=>{if(e){e=!1;try{t()}finally{e=!0}}else n!==void 0&&n()}},tp=/[\uD800-\uDBFF]/,np=/[\uDC00-\uDFFF]/,rp=(e,t)=>{let n=0,r=0;for(;n<e.length&&n<t.length&&e[n]===t[n];)n++;for(n>0&&tp.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&&np.test(e[e.length-r])&&r--,{index:n,remove:e.length-n-r,insert:t.slice(n,t.length-r)}},ip=(e,t)=>e>>>t|e<<32-t,ap=e=>ip(e,2)^ip(e,13)^ip(e,22),op=e=>ip(e,6)^ip(e,11)^ip(e,25),sp=e=>ip(e,7)^ip(e,18)^e>>>3,cp=e=>ip(e,17)^ip(e,19)^e>>>10,lp=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]),up=new Uint32Array([1779033703,3144134277,1013904242,2773480762,1359893119,2600822924,528734635,1541459225]),dp=class{constructor(){let e=new ArrayBuffer(320);this._H=new Uint32Array(e,0,8),this._H.set(up),this._W=new Uint32Array(e,64,64)}_updateHash(){let e=this._H,t=this._W;for(let e=16;e<64;e++)t[e]=cp(t[e-2])+t[e-7]+sp(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+op(o)+(o&s^~o&c)+lp[e]+t[e]>>>0,d=ap(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/fa,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}},fp=e=>new dp().digest(e),pp=new f(`y-sync`),mp=new f(`y-undo`),hp=new f(`yjs-cursor`),gp=e=>{for(let t=6;t<e.length;t++)e[t%6]=e[t%6]^e[t];return e.slice(0,6)},_p=e=>os(gp(fp(cs(e)))),vp=(e,t)=>t===void 0?!e.deleted:t.sv.has(e.id.client)&&t.sv.get(e.id.client)>e.id.clock&&!ul(t.ds,e.id),yp=[{light:`#ecd44433`,dark:`#ecd444`}],bp=(e,t,n)=>{if(!e.has(n)){if(e.size<t.length){let n=Bi();e.forEach(e=>n.add(e)),t=t.filter(e=>!n.has(e))}e.set(n,wo(t))}return e.get(n)},xp=(e,{colors:t=yp,colorMapping:n=new Map,permanentUserData:r=null,onFirstRender:i=()=>{},mapping:a}={})=>{let o=!1,s=new Tp(e,a),c=new _e({props:{editable:e=>{let t=pp.getState(e);return t.snapshot==null&&t.prevSnapshot==null}},key:pp,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(pp);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)&&Bc(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=mp.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)},pp)})}},destroy:()=>{s.destroy()}})});return c},Sp=(e,t,n)=>{if(t!==null&&t.anchor!==null&&t.head!==null)if(t.type===`all`)e.setSelection(new h(e.doc));else if(t.type===`node`){let r=em(n.doc,n.type,t.anchor,n.mapping);e.setSelection(Cp(e,r))}else{let r=em(n.doc,n.type,t.anchor,n.mapping),i=em(n.doc,n.type,t.head,n.mapping);r!==null&&i!==null&&e.setSelection(j.between(e.doc.resolve(r),e.doc.resolve(i)))}},Cp=(e,t)=>{let n=e.doc.resolve(t);return n.nodeAfter?N.create(e.doc,t):j.near(n)},wp=(e,t)=>({type:t.selection.jsonID,anchor:Qp(t.selection.anchor,e.type,e.mapping),head:Qp(t.selection.head,e.type,e.mapping)}),Tp=class{constructor(e,t=new Map){this.type=e,this.prosemirrorView=null,this.mux=ep(),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=wp(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()?(Xo&&this._domSelectionInView===null&&(Bc(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=wc.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||=fu(ml(),new Map),this.prosemirrorView.dispatch(this._tr.setMeta(pp,{snapshot:e,prevSnapshot:t}))}unrenderSnapshot(){this.mapping.clear(),this.mux(()=>{let e=this.type.toArray().map(e=>Dp(e,this.prosemirrorView.state.schema,this)).filter(e=>e!==null),t=this._tr.replace(0,this.prosemirrorView.state.doc.content.size,new D(v.from(e),0,0));t.setMeta(pp,{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=>Dp(e,this.prosemirrorView.state.schema,this)).filter(e=>e!==null),n=this._tr.replace(0,this.prosemirrorView.state.doc.content.size,new D(v.from(t),0,0));if(e){let t=Zi(Qi(e.anchor,0),n.doc.content.size),r=Zi(Qi(e.head,0),n.doc.content.size);n.setSelection(j.create(n.doc,t,r))}this.prosemirrorView.dispatch(n.setMeta(pp,{isChangeOrigin:!0,binding:this}))})}_renderSnapshot(e,t,n){let r=this.doc,i=this.type;if(e||=pu(this.doc),e instanceof Uint8Array||t instanceof Uint8Array)if((!(e instanceof Uint8Array)||!(t instanceof Uint8Array))&&no(),r=new bl({gc:!1}),Fl(r,t),t=pu(r),Fl(r,e),e=pu(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[bu(e,i._item.id.clock)].content.type}this.mapping.clear(),this.mux(()=>{r.transact(r=>{let a=n.permanentUserData;a&&a.dss.forEach(e=>{cl(r,e,e=>{})});let o=(e,t)=>{let r=e===`added`?a.getUserByClientId(t.client):a.getUserByDeletedId(t);return{user:r,type:e,color:bp(n.colorMapping,n.colors,r)}},s=pd(i,new du(t.ds,e.sv)).map(n=>!n._item.deleted||vp(n._item,e)||vp(n._item,t)?Dp(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 D(v.from(s),0,0));this.prosemirrorView.dispatch(c.setMeta(pp,{isChangeOrigin:!0}))},pp)})}_typeChanged(e,t){if(this.prosemirrorView==null)return;let n=pp.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);cl(t,t.deleteSet,e=>{if(e.constructor===qf){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=>Ep(e,this.prosemirrorView.state.schema,this)).filter(e=>e!==null),r=this._tr.replace(0,this.prosemirrorView.state.doc.content.size,new D(v.from(n),0,0));Sp(r,this.beforeTransactionSelection,this),r=r.setMeta(pp,{isChangeOrigin:!0,isUndoRedoOperation:t.origin instanceof Ru}),this.beforeTransactionSelection!==null&&this._isLocalCursorInView()&&r.scrollIntoView(),this.prosemirrorView.dispatch(r)})}_prosemirrorChanged(e){this.doc.transact(()=>{Gp(this.doc,this.type,e,this),this.beforeTransactionSelection=wp(this,this.prosemirrorView.state)},pp)}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))}},Ep=(e,t,n,r,i,a)=>{let o=n.mapping.get(e);if(o===void 0){if(e instanceof rf)return Dp(e,t,n,r,i,a);throw to()}return o},Dp=(e,t,n,r,i,a)=>{let o=[],s=e=>{if(e instanceof rf){let s=Ep(e,t,n,r,i,a);s!==null&&o.push(s)}else{let s=e._item.right?.content?.type;s instanceof Qd&&!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=Op(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):pd(e,new du(i.ds,r.sv)).forEach(s);try{let s=e.getAttributes(r);r!==void 0&&(vp(e._item,r)?vp(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}},Op=(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,Up(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},kp=(e,t)=>{let n=new lf,r=e.map(e=>({insert:e.text,attributes:Wp(e.marks,t)}));return n.applyDelta(r),t.mapping.set(n,e),n},Ap=(e,t)=>{let n=new rf(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,Pp(e).map(e=>jp(e,t))),t.mapping.set(n,e),n},jp=(e,t)=>e instanceof Array?kp(e,t):Ap(e,t),Mp=e=>typeof e==`object`&&!!e,Np=(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||Mp(o)&&Mp(s)&&Np(o,s)}return r},Pp=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},Fp=(e,t)=>{let n=e.toDelta();return n.length===t.length&&n.every((e,n)=>e.insert===t[n].text&&Io(e.attributes||{}).length===t[n].marks.length&&Bo(e.attributes,(e,r)=>{let i=Hp(r),a=t[n].marks;return a.find(e=>e.type.name===i)?Np(e,a.find(e=>e.type.name===i)?.attrs):!1}))},Ip=(e,t)=>{if(e instanceof rf&&!(t instanceof Array)&&Kp(e,t)){let n=Pp(t);return e._length===n.length&&Np(e.getAttributes(),t.attrs)&&e.toArray().every((e,t)=>Ip(e,n[t]))}return e instanceof lf&&t instanceof Array&&Fp(e,t)},Lp=(e,t)=>e===t||e instanceof Array&&t instanceof Array&&e.length===t.length&&e.every((e,n)=>t[n]===e),Rp=(e,t,n)=>{let r=e.toArray(),i=Pp(t),a=i.length,o=r.length,s=Zi(o,a),c=0,l=0,u=!1;for(;c<s;c++){let e=r[c],t=i[c];if(Lp(n.mapping.get(e),t))u=!0;else if(!Ip(e,t))break}for(;c+l<s;l++){let e=r[o-l-1],t=i[a-l-1];if(Lp(n.mapping.get(e),t))u=!0;else if(!Ip(e,t))break}return{equalityFactor:c+l,foundMappedChild:u}},zp=e=>{let t=``,n=e._start,r={};for(;n!==null;)n.deleted||(n.countable&&n.content instanceof Af?t+=n.content.str:n.content instanceof Cf&&(r[n.content.key]=null)),n=n.right;return{str:t,nAttrs:r}},Bp=(e,t,n)=>{n.mapping.set(e,t);let{nAttrs:r,str:i}=zp(e),a=t.map(e=>({insert:e.text,attributes:Object.assign({},r,Wp(e.marks,n))})),{insert:o,remove:s,index:c}=rp(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})))},Vp=/(.*)(--[a-zA-Z0-9+/=]{8})$/,Hp=e=>Vp.exec(e)?.[1]??e,Up=(e,t)=>{let n=[];for(let r in e)n.push(t.mark(Hp(r),e[r]));return n},Wp=(e,t)=>{let n={};return e.forEach(e=>{if(e.type.name!==`ychange`){let r=Li(t.isOMark,e.type,()=>!e.type.excludes(e.type));n[r?`${e.type.name}--${_p(e.toJSON())}`:e.type.name]=e.attrs}}),n},Gp=(e,t,n,r)=>{if(t instanceof rf&&t.nodeName!==n.type.name)throw Error(`node name mismatch!`);if(r.mapping.set(t,n),t instanceof rf){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=Pp(n),a=i.length,o=t.toArray(),s=o.length,c=Zi(a,s),l=0,u=0;for(;l<c;l++){let e=o[l],t=i[l];if(!Lp(r.mapping.get(e),t))if(Ip(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(!Lp(r.mapping.get(e),t))if(Ip(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 lf&&c instanceof Array)Fp(n,c)||Bp(n,c,r),l+=1;else{let i=n instanceof rf&&Kp(n,c),a=d instanceof rf&&Kp(d,f);if(i&&a){let e=Rp(n,c,r),t=Rp(d,f,r);e.foundMappedChild&&!t.foundMappedChild?a=!1:!e.foundMappedChild&&t.foundMappedChild||e.equalityFactor<t.equalityFactor?i=!1:a=!1}i?(Gp(e,n,c,r),l+=1):a?(Gp(e,d,f,r),u+=1):(r.mapping.delete(t.get(l)),t.delete(l,1),t.insert(l,[jp(c,r)]),l+=1)}}let n=s-l-u;if(s===1&&a===0&&o[0]instanceof lf?(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(jp(i[t],r));t.insert(l,e)}},pp)},Kp=(e,t)=>!(t instanceof Array)&&e.nodeName===t.type.name,qp=null,Jp=class{constructor(e,t,n){this.view=e,this.key=t,this.value=n}apply(){let e=pp.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)}}},Yp=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=qp;qp=null;let n=[];return t.forEach((e,t)=>{e.forEach((e,r)=>{n.push(new Jp(t,r,e))})}),new e(n)}},Xp=(e=Yp.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()||Bc(0,()=>Xp(e,!0));return}throw r}n=!1,e.dequeueFirst()}},Zp=(e,t,n)=>{qp||(qp=new Map,Bc(0,Xp)),Li(qp,e,Fi).set(t,n)},Qp=(e,t,n)=>{if(e===0)return su(t,0,-1);let r=t._first===null?null:t._first.content.type;for(;r!==null&&t!==r;){if(r instanceof lf){if(r._length>=e)return su(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 tu(r._item===null?null:r._item.id,r._item===null?$l(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 tu(r._item===null?null:r._item.id,r._item===null?$l(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 no();if(e===0&&r.constructor!==lf&&r!==t)return $p(r._item.parent,r._item)}return su(t,t._length,-1)},$p=(e,t)=>{let n=null,r=null;return e._item===null?r=$l(e):n=X(e._item.id.client,e._item.id.clock),new tu(n,r,t.id)},em=(e,t,n,r)=>{let i=lu(n,e);if(i===null||i.type!==t&&!eu(t,i.type._item))return null;let a=i.type,o=0;if(a.constructor===lf)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 lf?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 lf?o+=e._length:o+=r.get(e).nodeSize),t=t.right}}a=e}return o-1},tm=(e,t,n)=>e!==t,nm=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},rm=e=>({style:`background-color: ${e.color}70`,class:`ProseMirror-yjs-selection`}),im=/^#[0-9a-fA-F]{6}$/,am=(e,t,n,r,i)=>{let a=pp.getState(e);if(a==null||a.doc==null||a.binding==null)return g.create(e.doc,[]);let o=a.doc,s=[];return a.snapshot!=null||a.prevSnapshot!=null||a.binding.mapping.size===0?g.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`:im.test(n.color)||console.warn(`A user uses an unsupported color format`,n),n.name??=`User: ${c}`;let l=em(o,a.type,ru(t.cursor.anchor),a.binding.mapping),u=em(o,a.type,ru(t.cursor.head),a.binding.mapping);if(l!==null&&u!==null){let t=Qi(e.doc.content.size-1,0);l=Zi(l,t),u=Zi(u,t),s.push(R.widget(u,()=>r(n,c),{key:c+``,side:10}));let a=Zi(l,u),o=Qi(l,u);s.push(R.inline(a,o,i(n,c),{inclusiveEnd:!0,inclusiveStart:!1}))}}}),g.create(e.doc,s))},om=(e,{awarenessStateFilter:t=tm,cursorBuilder:n=nm,selectionBuilder:r=rm,getSelection:i=e=>e.selection}={},a=`cursor`)=>new _e({key:hp,state:{init(i,a){return am(a,e,t,n,r)},apply(i,a,o,s){let c=pp.getState(s),l=i.getMeta(hp);return c&&c.isChangeOrigin||l&&l.awarenessUpdated?am(s,e,t,n,r):a.map(i.mapping,i.doc)}},props:{decorations:e=>hp.getState(e)},view:t=>{let n=()=>{t.docView&&Zp(t,hp,{awarenessUpdated:!0})},r=()=>{let n=pp.getState(t.state),r=e.getLocalState()||{};if(t.hasFocus()){let o=i(t.state),s=Qp(o.anchor,n.type,n.binding.mapping),c=Qp(o.head,n.type,n.binding.mapping);(r.cursor==null||!uu(ru(r.cursor.anchor),s)||!uu(ru(r.cursor.head),c))&&e.setLocalStateField(a,{anchor:s,head:c})}else r.cursor!=null&&em(n.doc,n.type,ru(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)}}}}),sm=e=>{let t=mp.getState(e).undoManager;if(t!=null)return t.undo(),!0},cm=e=>{let t=mp.getState(e).undoManager;if(t!=null)return t.redo(),!0},lm=new Set([`paragraph`]),um=(e,t)=>!(e instanceof qf)||!(e.content instanceof Bf)||!(e.content.type instanceof Qd||e.content.type instanceof rf&&t.has(e.content.type.nodeName))||e.content.type._length===0,dm=({protectedNodes:e=lm,trackedOrigins:t=[],undoManager:n=null}={})=>new _e({key:mp,state:{init:(r,i)=>{let a=pp.getState(i),o=n||new Ru(a.type,{trackedOrigins:new Set([pp].concat(t)),deleteFilter:t=>um(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=pp.getState(r).binding,a=t.undoManager,o=a.undoStack.length>0,s=a.redoStack.length>0;return i?{undoManager:a,prevSel:wp(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=pp.getState(e.state),n=mp.getState(e.state).undoManager;return n.on(`stack-item-added`,({stackItem:n})=>{let r=t.binding;r&&n.meta.set(r,mp.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()}}}});async function fm(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 pm(e){return typeof e==`object`&&!!e}function mm(e){return e===`files`||e===`backlinks`||e===`graph`||e===`sync-status`}function hm(e){let t;try{t=JSON.parse(e)}catch{return null}return!pm(t)||t.v!==1||!mm(t.ch)||typeof t.seq!=`number`?null:{v:1,ch:t.ch,seq:t.seq}}function gm(){return typeof location>`u`?`ws://localhost/collab`:`${location.protocol===`https:`?`wss`:`ws`}://${location.host}/collab`}function _m(e){if(e===void 0)return null;let t=e.okDesktop;return!t||!t.config.collabUrl||t.config.collabUrl.length===0?null:t}function vm(e){return{collabUrl:e.collabUrl,attempts:0,terminal:!1,lastError:null}}var ym=2e3,bm=15e3;function xm(e){let t=e.terminalAfterMs??3e4,n=e.initialDelayMs??ym,r=e.maxDelayMs??bm,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 Sm(){let e=(0,rr.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,G.useState)(t),i;e[1]===Symbol.for(`react.memo_cache_sentinel`)?(i={token:0},e[1]=i):i=e[1];let a=(0,G.useRef)(i),[o,s]=(0,G.useState)(0),c;e[2]===Symbol.for(`react.memo_cache_sentinel`)?(c=()=>{let e=a.current.token=a.current.token+1,t=_m(typeof window<`u`?window:void 0);if(t){r(vm(t.config));let n=t.onProjectSwitched(t=>{e===a.current.token&&r(vm(t))});return()=>{n()}}let n=xm({fetchConfig:fm,fallbackUrl:gm,now:Date.now,setTimeout:Em,clearTimeout:Tm,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,G.useEffect)(c,l);let u;e[5]===Symbol.for(`react.memo_cache_sentinel`)?(u=()=>{a.current.token=a.current.token+1,r(wm),s(Cm)},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 Cm(e){return e+1}function wm(e){return{...e,terminal:!1,lastError:null}}function Tm(e){return globalThis.clearTimeout(e)}function Em(e,t){return globalThis.setTimeout(e,t)}var Dm=Math.floor,Om=(e,t)=>e<t?e:t,km=(e,t)=>e>t?e:t;Number.isNaN;var Am=128,jm=1<<17,Mm=1<<18,Nm=1<<19,Pm=1<<20,Fm=1<<21,Im=1<<22,Lm=1<<23,Rm=1<<24,zm=1<<25,Bm=1<<26,Vm=1<<27,Hm=1<<28,Um=1<<29,Wm=1<<30,Gm=127;jm-1,Mm-1,Nm-1,Pm-1,Fm-1,Im-1,Lm-1,Rm-1,zm-1,Bm-1,Vm-1,Hm-1,Um-1,Wm-1;var Km=2**53-1;Number.isInteger,Number.isNaN,Number.parseInt;var qm=String.fromCharCode;String.fromCodePoint,qm(65535);var Jm=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},Ym=typeof TextEncoder<`u`?new TextEncoder:null,Xm=Ym?e=>Ym.encode(e):Jm,Zm=typeof TextDecoder>`u`?null:new TextDecoder(`utf-8`,{fatal:!0,ignoreBOM:!0});Zm&&Zm.decode(new Uint8Array).length===1&&(Zm=null);var Qm=(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},$m=(e,t)=>{for(;t>Gm;)Qm(e,Am|Gm&t),t=Dm(t/128);Qm(e,Gm&t)},eh=new Uint8Array(3e4),th=eh.length/3,nh=Ym&&Ym.encodeInto?(e,t)=>{if(t.length<th){let n=Ym.encodeInto(t,eh).written||0;$m(e,n);for(let t=0;t<n;t++)Qm(e,eh[t])}else ih(e,Xm(t))}:(e,t)=>{let n=unescape(encodeURIComponent(t)),r=n.length;$m(e,r);for(let t=0;t<r;t++)Qm(e,n.codePointAt(t))},rh=(e,t)=>{let n=e.cbuf.length,r=e.cpos,i=Om(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(km(n*2,a)),e.cbuf.set(t.subarray(i)),e.cpos=a)},ih=(e,t)=>{$m(e,t.byteLength),rh(e,t)},ah=e=>Error(e),oh=ah(`Unexpected end of array`),sh=ah(`Integer out of Range`),ch=(e,t)=>{let n=new Uint8Array(e.arr.buffer,e.pos+e.arr.byteOffset,t);return e.pos+=t,n},lh=e=>ch(e,dh(e)),uh=e=>e.arr[e.pos++],dh=e=>{let t=0,n=1,r=e.arr.length;for(;e.pos<r;){let r=e.arr[e.pos++];if(t+=(r&Gm)*n,n*=128,r<Am)return t;if(t>Km)throw sh}throw oh},fh=Zm?e=>Zm.decode(lh(e)):e=>{let t=dh(e);if(t===0)return``;{let n=String.fromCodePoint(uh(e));if(--t<100)for(;t--;)n+=String.fromCodePoint(uh(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))}},ph=function(e){return e[e.Token=0]=`Token`,e[e.PermissionDenied=1]=`PermissionDenied`,e[e.Authenticated=2]=`Authenticated`,e}({}),mh=(e,t)=>{$m(e,ph.Token),nh(e,t)},hh=(e,t,n,r)=>{switch(dh(e)){case ph.Token:t();break;case ph.PermissionDenied:n(fh(e));break;case ph.Authenticated:r(fh(e));break;default:}},gh=e=>Array.from(e.entries()).map(([e,t])=>({clientId:e,...t})),_h=`\0`;function vh(e,t){return e+_h+t}function yh(e){let t=e.indexOf(_h);return t===-1?{documentName:e,sessionId:null}:{documentName:e.substring(0,t),sessionId:e.substring(t+1)}}var bh=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 xh(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 Sh(e){return new Promise(t=>setTimeout(t,e))}function Ch(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 wh(e,t){let n=xh(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||Ch;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 Sh(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 Sh(o),r.attemptNum<1&&n.initialJitter){let e=i(r,n);e&&await Sh(e)}return a()}var Th=Math.floor,Eh=(e,t)=>e<t?e:t,Dh=(e,t)=>e>t?e:t;Number.isNaN;var Oh=64,kh=128,Ah=1<<17,jh=1<<18,Mh=1<<19,Nh=1<<20,Ph=1<<21,Fh=1<<22,Ih=1<<23,Lh=1<<24,Rh=1<<25,zh=1<<26,Bh=1<<27,Vh=1<<28,Hh=1<<29,Uh=1<<30,Wh=63,Gh=127;Ah-1,jh-1,Mh-1,Nh-1,Ph-1,Fh-1,Ih-1,Lh-1,Rh-1,zh-1,Bh-1,Vh-1,Hh-1,Uh-1;var Kh=2**53-1;Number.isInteger,Number.isNaN,Number.parseInt;var qh=()=>new Set,Jh=Array.from;Array.isArray;var Yh=String.fromCharCode;String.fromCodePoint,Yh(65535);var Xh=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},Zh=typeof TextEncoder<`u`?new TextEncoder:null,Qh=Zh?e=>Zh.encode(e):Xh,$h=typeof TextDecoder>`u`?null:new TextDecoder(`utf-8`,{fatal:!0,ignoreBOM:!0});$h&&$h.decode(new Uint8Array).length===1&&($h=null);var eg=class{constructor(){this.cpos=0,this.cbuf=new Uint8Array(100),this.bufs=[]}},tg=()=>new eg,ng=e=>{let t=e.cpos;for(let n=0;n<e.bufs.length;n++)t+=e.bufs[n].length;return t},rg=e=>{let t=new Uint8Array(ng(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},ig=(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},ag=(e,t)=>{for(;t>Gh;)ig(e,kh|Gh&t),t=Th(t/128);ig(e,Gh&t)},og=new Uint8Array(3e4),sg=og.length/3,cg=Zh&&Zh.encodeInto?(e,t)=>{if(t.length<sg){let n=Zh.encodeInto(t,og).written||0;ag(e,n);for(let t=0;t<n;t++)ig(e,og[t])}else ug(e,Qh(t))}:(e,t)=>{let n=unescape(encodeURIComponent(t)),r=n.length;ag(e,r);for(let t=0;t<r;t++)ig(e,n.codePointAt(t))},lg=(e,t)=>{let n=e.cbuf.length,r=e.cpos,i=Eh(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(Dh(n*2,a)),e.cbuf.set(t.subarray(i)),e.cpos=a)},ug=(e,t)=>{ag(e,t.byteLength),lg(e,t)},dg=e=>Error(e),fg=dg(`Unexpected end of array`),pg=dg(`Integer out of Range`),mg=class{constructor(e){this.arr=e,this.pos=0}},hg=e=>new mg(e),gg=(e,t)=>{let n=new Uint8Array(e.arr.buffer,e.pos+e.arr.byteOffset,t);return e.pos+=t,n},_g=e=>gg(e,yg(e)),vg=e=>e.arr[e.pos++],yg=e=>{let t=0,n=1,r=e.arr.length;for(;e.pos<r;){let r=e.arr[e.pos++];if(t+=(r&Gh)*n,n*=128,r<kh)return t;if(t>Kh)throw pg}throw fg},bg=e=>{let t=e.arr[e.pos++],n=t&Wh,r=64,i=(t&Oh)>0?-1:1;if((t&kh)===0)return i*n;let a=e.arr.length;for(;e.pos<a;){if(t=e.arr[e.pos++],n+=(t&Gh)*r,r*=128,t<kh)return i*n;if(n>Kh)throw pg}throw fg},xg=$h?e=>$h.decode(_g(e)):e=>{let t=yg(e);if(t===0)return``;{let n=String.fromCodePoint(vg(e));if(--t<100)for(;t--;)n+=String.fromCodePoint(vg(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))}},Sg=e=>{let t=e.pos,n=xg(e);return e.pos=t,n},Cg=Date.now,wg=()=>new Map,Tg=(e,t,n)=>{let r=e.get(t);return r===void 0&&e.set(t,r=n()),r},Eg=class{constructor(){this._observers=wg()}on(e,t){Tg(this._observers,e,qh).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 Jh((this._observers.get(e)||wg()).values()).forEach(e=>e(...t))}destroy(){this._observers=wg()}},Dg=Symbol(`Equality`),Og=Object.keys,kg=e=>Og(e).length,Ag=(e,t)=>Object.prototype.hasOwnProperty.call(e,t),jg=(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[Dg]!=null)return e[Dg](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)||!jg(e.get(n),t.get(n)))return!1;break;case void 0:case Object:if(kg(e)!==kg(t))return!1;for(let n in e)if(!Ag(e,n)||!jg(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(!jg(e[n],t[n]))return!1;break;default:return!1}return!0},Mg=3e4,Ng=class extends Eg{constructor(e){super(),this.doc=e,this.clientID=e.clientID,this.states=new Map,this.meta=new Map,this._checkInterval=setInterval(()=>{let e=Cg();this.getLocalState()!==null&&Mg/2<=e-this.meta.get(this.clientID).lastUpdated&&this.setLocalState(this.getLocalState());let t=[];this.meta.forEach((n,r)=>{r!==this.clientID&&Mg<=e-n.lastUpdated&&this.states.has(r)&&t.push(r)}),t.length>0&&Pg(this,t,`timeout`)},Th(Mg/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:Cg()});let a=[],o=[],s=[],c=[];e===null?c.push(t):i==null?e!=null&&a.push(t):(o.push(t),jg(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}},Pg=(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:Cg()})}r.push(i)}}r.length>0&&(e.emit(`change`,[{added:[],updated:[],removed:r},n]),e.emit(`update`,[{added:[],updated:[],removed:r},n]))},Fg=(e,t,n=e.states)=>{let r=t.length,i=tg();ag(i,r);for(let a=0;a<r;a++){let r=t[a],o=n.get(r)||null,s=e.meta.get(r).clock;ag(i,r),ag(i,s),cg(i,JSON.stringify(o))}return rg(i)},Ig=(e,t,n)=>{let r=hg(t),i=Cg(),a=[],o=[],s=[],c=[],l=yg(r);for(let t=0;t<l;t++){let t=yg(r),n=yg(r),l=JSON.parse(xg(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&&(jg(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])},Lg=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={}}},Rg=class{constructor(e){this.data=e,this.encoder=tg(),this.decoder=hg(new Uint8Array(this.data))}peekVarString(){return Sg(this.decoder)}readVarUint(){return yg(this.decoder)}readVarString(){return xg(this.decoder)}readVarUint8Array(){return _g(this.decoder)}writeVarUint(e){return ag(this.encoder,e)}writeVarString(e){return cg(this.encoder,e)}writeVarUint8Array(e){return ug(this.encoder,e)}length(){return ng(this.encoder)}},zg=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}({}),Bg=function(e){return e.Connecting=`connecting`,e.Connected=`connected`,e.Disconnected=`disconnected`,e}({}),Vg=class{constructor(){this.encoder=tg()}get(e){return e.encoder}toUint8Array(){return rg(this.encoder)}},Hg=class extends Vg{constructor(...e){super(...e),this.type=zg.CLOSE,this.description=`Ask the server to close the connection`}get(e){return cg(this.encoder,e.documentName),ag(this.encoder,this.type),this.encoder}},Ug=class e extends Lg{static{this.DEDUPLICATABLE_TYPES=new Set([zg.Awareness,zg.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=Bg.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=Bg.Connected,this.emit(`status`,{status:Bg.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===Bg.Disconnected&&this.shouldConnect&&this.connect(),this.receivedOnOpenPayload&&this.status===Bg.Connected&&e.onOpen(this.receivedOnOpenPayload)}detach(e){let t=e.effectiveName;this.configuration.providerMap.has(t)&&(e.send(Hg,{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===Bg.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:wh(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=Bg.Connecting,this.emit(`status`,{status:Bg.Connecting}),this.connectionAttempt={resolve:e,reject:t}})}onMessage(e){this.resolveConnectionAttempt(),this.lastMessageReceived=Cg();let t=new Uint8Array(e.data);if(t.length===1&&t[0]===zg.Ping){this.sendPong();return}let n=new Rg(t).peekVarString();this.configuration.providerMap.get(n)?.onMessage(e)}sendPong(){let e=tg();ag(e,zg.Pong),this.send(rg(e))}resolveConnectionAttempt(){this.connectionAttempt&&(this.connectionAttempt.resolve(),this.connectionAttempt=null,this.status=Bg.Connected,this.emit(`status`,{status:Bg.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===Bg.Connected&&this.lastMessageReceived&&(this.configuration.messageReconnectTimeout>=Cg()-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=hg(e);return{documentName:xg(t),messageType:yg(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===bh.Open?this.webSocket.send(e):this.addToQueue(e)}onClose({event:e}){this.closeTries=0,this.cleanupWebSocket(),this.connectionAttempt&&this.rejectConnectionAttempt(),this.status=Bg.Disconnected,this.emit(`status`,{status:Bg.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()}},Wg=0,Gg=1,Kg=2,qg=(e,t)=>{ag(e,Wg),ug(e,Gl(t))},Jg=(e,t,n)=>{ag(e,Gg),ug(e,zl(t,n))},Yg=(e,t,n)=>Jg(t,n,_g(e)),Xg=(e,t,n,r)=>{try{Il(t,_g(e),n)}catch(e){r?.(e),console.error(`Caught error while handling a Yjs update`,e)}},Zg=(e,t)=>{ag(e,Kg),ug(e,t)},Qg=Xg,$g=(e,t,n,r,i)=>{let a=yg(e);switch(a){case Wg:Yg(e,t,n);break;case Gg:Xg(e,n,r,i);break;case Kg:Qg(e,n,r,i);break;default:throw Error(`Unknown message type`)}return a},e_=class{constructor(e){this.message=e}apply(e,t){let{message:n}=this,r=n.readVarUint(),i=n.length();switch(r){case zg.Sync:this.applySyncMessage(e,t);break;case zg.Awareness:this.applyAwarenessMessage(e);break;case zg.Auth:this.applyAuthMessage(e);break;case zg.QueryAwareness:this.applyQueryAwarenessMessage(e);break;case zg.Stateless:e.receiveStateless(xg(n.decoder));break;case zg.SyncStatus:this.applySyncStatusMessage(e,bg(n.decoder)===1);break;case zg.CLOSE:let i={code:1e3,reason:xg(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(Vg,{encoder:n.encoder})}applySyncMessage(e,t){let{message:n}=this;n.writeVarUint(zg.Sync);let r=$g(n.decoder,n.encoder,e.document,e);t&&r===Gg&&(e.synced=!0)}applySyncStatusMessage(e,t){t&&e.decrementUnsyncedChanges()}applyAwarenessMessage(e){if(!e.awareness)return;let{message:t}=this;Ig(e.awareness,t.readVarUint8Array(),e)}applyAuthMessage(e){let{message:t}=this;hh(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(zg.Awareness),t.writeVarUint8Array(Fg(e.awareness,Array.from(e.awareness.getStates().keys())))}},t_=class{constructor(e,t={}){this.message=new e,this.encoder=this.message.get(t)}create(){return rg(this.encoder)}send(e){e?.send(this.create())}},n_=`4.0.0-rc.1`,r_=class extends Vg{constructor(...e){super(...e),this.type=zg.Auth,this.description=`Authentication`}get(e){if(e.token===void 0)throw Error("The authentication message requires `token` as an argument.");return cg(this.encoder,e.documentName),ag(this.encoder,this.type),mh(this.encoder,e.token),cg(this.encoder,n_),this.encoder}},i_=class extends Vg{constructor(...e){super(...e),this.type=zg.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`);cg(this.encoder,e.documentName),ag(this.encoder,this.type);let t;return t=e.states===void 0?Fg(e.awareness,e.clients):Fg(e.awareness,e.clients,e.states),ug(this.encoder,t),this.encoder}},a_=class extends Vg{constructor(...e){super(...e),this.type=zg.Stateless,this.description=`A stateless message`}get(e){return cg(this.encoder,e.documentName),ag(this.encoder,this.type),cg(this.encoder,e.payload??``),this.encoder}},o_=class extends Vg{constructor(...e){super(...e),this.type=zg.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 cg(this.encoder,e.documentName),ag(this.encoder,this.type),qg(this.encoder,e.document),this.encoder}},s_=class extends Vg{constructor(...e){super(...e),this.type=zg.Sync,this.description=`A document update`}get(e){return cg(this.encoder,e.documentName),ag(this.encoder,this.type),Zg(this.encoder,e.update),this.encoder}},c_=class extends Error{constructor(...e){super(...e),this.code=1001}},l_=class extends Lg{get effectiveName(){return this.configuration.sessionAwareness?vh(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 bl,this.configuration.awareness=e.awareness===void 0?new Ng(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:gh(this.awareness.getStates())})}),this.awareness?.on(`change`,()=>{this.emit(`awarenessChange`,{states:gh(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 Ug(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(o_,{document:this.document,documentName:this.effectiveName})}pageHide(){this.awareness&&Pg(this.awareness,[this.document.clientID],`page hide`)}registerEventListeners(){typeof window>`u`||!(`addEventListener`in window)||window.addEventListener(`pagehide`,this.boundPageHide)}sendStateless(e){this.send(a_,{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(r_,{token:e??``,documentName:this.effectiveName})}documentUpdateHandler(e,t){t!==this&&(this.incrementUnsyncedChanges(),this.send(s_,{update:e,documentName:this.effectiveName}))}awarenessUpdateHandler({added:e,updated:t,removed:n},r){let i=e.concat(t).concat(n);this.send(i_,{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(o_,{document:this.document,documentName:this.effectiveName}),this.awareness&&this.awareness.getLocalState()!==null&&this.send(i_,{awareness:this.awareness,clients:[this.document.clientID],documentName:this.effectiveName})}send(e,t){if(!this._isAttached)return;let n=new t_(e,t);this.emit(`outgoingMessage`,{message:n.message}),n.send(this.configuration.websocketProvider)}onMessage(e){let t=new Rg(e.data),{documentName:n}=yh(t.readVarString());t.writeVarString(this.effectiveName),this.emit(`message`,{event:e,message:new Rg(e.data)}),new e_(t).apply(this,!0)}onClose(){this.isAuthenticated=!1,this.synced=!1,this.awareness&&Pg(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&&(Pg(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 c_(`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)}};function u_(e){return!(e.viewCount>0&&e.viewCount>=50||e.bytes>5e5)}var d_=new Map,f_=new Map,p_=[],m_=[],h_=new Set,g_=null;function __(){if(g_)return g_;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`,g_=e,e}function v_(e){let{docName:t,container:n,factory:r,sizeStats:i}=e;if(i&&!u_(i)){let e=r(n);return K(`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=d_.get(t);if(a){if(E_(a,n),a.activeMountKey=t,O_(p_,t),n.scrollTop=a.scrollTop,a.hadFocus)try{a.editor.commands.focus()}catch{}return K(`ok/cache/hit`,{docName:t,kind:`tiptap`}),i&&K(`ok/cold/editor-mount-stats`,{docName:t,viewCount:i.viewCount,bytes:i.bytes,cacheHit:!0,kind:`tiptap`}),a}for(;d_.size>=10;){let e=k_(p_,t);if(!e)break;b_(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 d_.set(t,s),O_(p_,t),K(`ok/cache/miss`,{docName:t,viewCount:i?.viewCount??-1,bytes:i?.bytes??-1,reason:`cold`,kind:`tiptap`}),i&&K(`ok/cold/editor-mount-stats`,{docName:t,viewCount:i.viewCount,bytes:i.bytes,cacheHit:!1,kind:`tiptap`}),s}function y_(e){if(e.__uncached){try{e.editor.destroy()}catch{}e.activeMountKey=null;return}let t=w_(e.editor);if(t){e.hadFocus=T_(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=__();r&&r.appendChild(t.dom)}e.activeMountKey=null}function b_(e){let t=d_.get(e);if(!t)return!1;try{t.editor.destroy()}catch(t){K(`ok/cache/evict-failed`,{docName:e,kind:`tiptap`,stage:`editor`,message:t instanceof Error?t.message:String(t)})}try{t.provider.destroy()}catch(t){K(`ok/cache/evict-failed`,{docName:e,kind:`tiptap`,stage:`provider`,message:t instanceof Error?t.message:String(t)})}try{t.ydoc.destroy()}catch(t){K(`ok/cache/evict-failed`,{docName:e,kind:`tiptap`,stage:`ydoc`,message:t instanceof Error?t.message:String(t)})}d_.delete(e);let n=p_.indexOf(e);return n!==-1&&p_.splice(n,1),K(`ok/cache/evict`,{docName:e,kind:`tiptap`}),!0}function x_(e){let{docName:t,container:n,factory:r,sizeStats:i}=e;if(i&&!u_(i)){let e=r(n);return K(`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=f_.get(t);if(a){if(D_(a,n),a.activeMountKey=t,O_(m_,t),n.scrollTop=a.scrollTop,a.hadFocus)try{a.view.focus()}catch{}return K(`ok/cache/hit`,{docName:t,kind:`cm`}),i&&K(`ok/cold/editor-mount-stats`,{docName:t,viewCount:i.viewCount,bytes:i.bytes,cacheHit:!0,kind:`cm`}),a}for(;f_.size>=10;){let e=k_(m_,t);if(!e)break;C_(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 f_.set(t,s),O_(m_,t),K(`ok/cache/miss`,{docName:t,viewCount:i?.viewCount??-1,bytes:i?.bytes??-1,reason:`cold`,kind:`cm`}),i&&K(`ok/cold/editor-mount-stats`,{docName:t,viewCount:i.viewCount,bytes:i.bytes,cacheHit:!1,kind:`cm`}),s}function S_(e){if(e.__uncached){try{e.view.destroy()}catch{}e.activeMountKey=null;return}let t=e.view.dom;e.hadFocus=T_(t),e.scrollTop=(e.view.scrollDOM??t).scrollTop??0;let n=t.parentElement;n&&n.removeChild(t);let r=__();r&&r.appendChild(t),e.activeMountKey=null}function C_(e){let t=f_.get(e);if(!t)return!1;try{t.view.destroy()}catch(t){K(`ok/cache/evict-failed`,{docName:e,kind:`cm`,stage:`view`,message:t instanceof Error?t.message:String(t)})}try{t.provider.destroy()}catch(t){K(`ok/cache/evict-failed`,{docName:e,kind:`cm`,stage:`provider`,message:t instanceof Error?t.message:String(t)})}try{t.ydoc.destroy()}catch(t){K(`ok/cache/evict-failed`,{docName:e,kind:`cm`,stage:`ydoc`,message:t instanceof Error?t.message:String(t)})}f_.delete(e);let n=m_.indexOf(e);return n!==-1&&m_.splice(n,1),K(`ok/cache/evict`,{docName:e,kind:`cm`}),!0}function w_(e){return e.editorView??null}function T_(e){if(typeof document>`u`)return!1;let t=document.activeElement;return t?t===e?!0:e.contains(t):!1}function E_(e,t){let n=w_(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 D_(e,t){let n=e.view.dom,r=n.parentElement;r&&r!==t&&r.removeChild(n),n.parentElement!==t&&t.appendChild(n)}function O_(e,t){let n=e.indexOf(t);n!==-1&&e.splice(n,1),e.push(t)}function k_(e,t){for(let n of e)if(n!==t&&!h_.has(n))return n;K(`ok/cache/evict-fallback-activity-saturated`,{mountingDocName:t,lruLength:e.length,activityMountCount:h_.size});for(let n of e)if(n!==t)return n;return null}function A_(e){let t=h_,n=new Set(e);for(let e of t){if(n.has(e))continue;let t=j_(e);if(t)try{t.disconnect(),K(`ok/cache/disconnect`,{docName:e})}catch(t){K(`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=j_(e);if(!n)continue;let r=t=>{K(`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(()=>K(`ok/cache/connect`,{docName:e}),e=>r(e)):K(`ok/cache/connect`,{docName:e})}catch(e){r(e)}}h_=n}function j_(e){let t=d_.get(e);if(t)return t.provider;let n=f_.get(e);return n?n.provider:null}var M_=({key:e,editor:t,onPaste:n,onDrop:r,allowedMimeTypes:i})=>new _e({key:e||new f(`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))}}}),N_=ke.create({name:`fileHandler`,addOptions(){return{onPaste:void 0,onDrop:void 0,allowedMimeTypes:void 0}},addProseMirrorPlugins(){return[M_({key:new f(this.name),editor:this.editor,allowedMimeTypes:this.options.allowedMimeTypes,onDrop:this.options.onDrop,onPaste:this.options.onPaste})]}}),P_=new f(`imageUpload`);function F_(){let e=document.createElement(`div`);return e.className=`image-upload-skeleton w-full h-40 rounded-md bg-muted animate-pulse motion-reduce:animate-none my-2`,e.setAttribute(`data-upload-widget`,`loading`),e.setAttribute(`role`,`status`),e.setAttribute(`aria-label`,`Uploading image...`),e}var I_=new _e({key:P_,state:{init(){return{decorations:g.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(P_);if(!i)return{decorations:n,uploads:r};if(i.type===`add`){let t=R.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 P_.getState(e)?.decorations??g.empty}}}),L_=null;function R_(e){L_=e}async function z_(e,t,n){let r=L_?`${L_}.md`:``;if(!r){Fe.error(`Cannot upload: no document is open`);return}let i=crypto.randomUUID(),a=F_();t.view.dispatch(t.state.tr.setMeta(P_,{type:`add`,id:i,pos:n,widget:a}));let o=new FormData;o.append(`file`,e),o.append(`parentDocName`,r);let s;try{s=await fetch(`/api/upload-image`,{method:`POST`,body:o})}catch(e){console.error(`[uploadAndInsert] Network error:`,e),B_(t,i);return}if(!s.ok){let e=`Upload failed (${s.status})`;try{let t=await s.json();t.error&&(e=t.error)}catch{}console.error(`[uploadAndInsert] Server error:`,e),B_(t,i,e);return}let c;try{let e=await s.json();if(typeof e.src!=`string`)throw Error(`missing src in response`);c=e.src}catch(e){console.error(`[uploadAndInsert] Response parse error:`,e),B_(t,i);return}let l=e.name.replace(/\.[^.]+$/,``),{state:u}=t,d=P_.getState(u)?.uploads.get(i)??n,f=u.schema.nodes.image;if(!f){console.error(`[uploadAndInsert] Image node type not found in schema`),B_(t,i);return}let p=u.tr.setMeta(P_,{type:`remove`,id:i}).insert(d,f.create({src:c,alt:l}));t.view.dispatch(p)}function B_(e,t,n){e.view.dispatch(e.state.tr.setMeta(P_,{type:`remove`,id:t})),Fe.error(n??`Upload failed`)}function V_(e){let{$from:t}=e.selection;return t.depth===0?null:{from:t.before(1),to:t.after(1)}}function H_(e,t){let n=V_(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(j.near(l.doc.resolve(p))),l.scrollIntoView(),t(l),!0}function U_(e,t){let n=V_(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(j.near(l.doc.resolve(p))),l.scrollIntoView(),t(l),!0}var W_=ke.create({name:`blockMover`,addKeyboardShortcuts(){return{"Mod-Shift-ArrowUp":({editor:e})=>H_(e.state,e.view.dispatch),"Mod-Shift-ArrowDown":({editor:e})=>U_(e.state,e.view.dispatch)}}});function G_(e){return!!e.getMeta(pp)}function K_(e,t){let n=pp.getState(e);return em(n.doc,n.type,t,n.binding.mapping)||0}function q_(e,t){let n=pp.getState(e);return Qp(t,n.type,n.binding.mapping)}var J_=class e extends ae{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 Y_(e,t){return new J_(e,q_(t,e))}function X_(e,t,n){let r=e instanceof J_?e.yRelativePosition:null;if(G_(t)&&r)return{position:new J_(K_(n,r),r),mapResult:null};let i=Ne(e,t),a=i.position.position;return{position:new J_(a,r??q_(n,a)),mapResult:i.mapResult}}var Z_=ke.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)=>X_(e,t,this.editor.state),this.editor.utils.createMappablePosition=e=>Y_(e,this.editor.state)},addCommands(){return{undo:()=>({tr:e,state:t,dispatch:n})=>(e.setMeta(`preventDispatch`,!0),mp.getState(t).undoManager.undoStack.length===0?!1:n?sm(t):!0),redo:()=>({tr:e,state:t,dispatch:n})=>(e.setMeta(`preventDispatch`,!0),mp.getState(t).undoManager.redoStack.length===0?!1:n?cm(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=dm(this.options.yUndoOptions),n=t.spec.view;return t.spec.view=e=>{let{undoManager:t}=mp.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()}}},[xp(e,{...this.options.ySyncOptions,onFirstRender:this.options.onFirstRender}),t,this.editor.options.enableContentCheck&&new _e({key:new f(`filterInvalidContent`),filterTransaction:t=>{if(!G_(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 Q_(e){if(!e.length)return g.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(R.node(n,n+r.nodeSize,{class:`ProseMirror-selectednoderange`}))}),g.create(n,t)}function $_(e,t,n){let r=n.isText||n.isAtom?0:1;return{start:e+r,end:e+t-r}}function ev(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 S(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=$_(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 k(a.resolve(l),a.resolve(u));i.push(p)}),i}var tv=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 nv(e.resolve(this.anchor),e.resolve(this.head))}},nv=class e extends he{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=ev(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 tv(this.anchor,this.head)}};nv.prototype.visible=!1;function rv(e){return e instanceof nv}ke.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(!rv(a)){let e=nv.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(!rv(a)){let e=nv.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=nv.create(i,0,i.content.size,t);return a.setSelection(o),n.dispatch(a),!0}}},onSelectionUpdate(){let{selection:e}=this.editor.state;rv(e)&&this.editor.view.dom.classList.add(`ProseMirror-noderangeselection`)},addProseMirrorPlugins(){let e=!1,t=!1;return[new _e({key:new f(`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=nv.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=rv(r);if(e=!1,!t)return i?(e=!0,Q_(r.ranges)):null;let{$from:a,$to:o}=r;if(!i&&a.sameParent(o))return null;let s=ev(a,o,this.options.depth);return s.length?(e=!0,Q_(s)):null}}})]}});function iv(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 av(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=iv(e)}),t}var ov=[{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}],sv={edges:[`left`,`top`],threshold:12,strength:500};function cv(e){return e===void 0||e===`left`?{...sv}: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}:{...sv,...e}}function lv(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 uv(e,t,n,r){return!t||n.edges.length===0?0:lv(e,t,n)?n.strength*r:0}var dv=1e3;function fv(e,t,n,r){let i=dv,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-=uv(r,o,n,e.depth),i<=0?-1:i}function pv(e,t,n){return Array.from({length:t},(e,n)=>t-1-n).some(t=>n.includes(e.node(t).type.name))}function mv(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(...ov),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&&!pv(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=fv({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=pv(a,l,n.allowedContainers)),p){let r=fv({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 hv(e,t){let n=e;for(;n?.parentElement&&n.parentElement!==t.dom;)n=n.parentElement;return n?.parentElement===t.dom?n:void 0}function gv(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 _v(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(!gv(s)||!gv(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 vv=e=>{let{x:t,y:n,editor:r,nestedOptions:i}=e,{view:a,state:o}=r,s=_v(a,t,n,5);if(!s)return{resultElement:null,resultNode:null,pos:null};let{x:c,y:l}=s;if(i?.enabled){let e=mv(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=hv(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 yv(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 bv(e){var t;(t=e.parentNode)==null||t.removeChild(e)}function xv(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=vv({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 ev(i.resolve(a.pos),i.resolve(a.pos+a.resultNode.nodeSize+o),0,{extendOnBoundaryOverlap:!1})}function Sv(e,t,n,r){let{view:i}=t;if(!e.dataTransfer)return;let{empty:a,$from:o,$to:s}=i.state.selection,c=xv(e,t,n,r),l=ev(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`,yv(i,m));let g=n?.enabled&&r?.node,_,v;g?(_=i.state.doc.slice(m,h),v=N.create(i.state.doc,m)):(v=nv.create(i.state.doc,m,h),_=v.content()),d.forEach(e=>{let t=av(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,bv(p),document.removeEventListener(`drop`,S),document.removeEventListener(`dragend`,S))},C=v instanceof N?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 Cv=(e,t)=>{let n=e.resolve(t),{depth:r}=n;return r===0?t:n.pos-n.parentOffset-1},wv=(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},Tv=(e,t)=>{let n=pp.getState(e);return n?Qp(t,n.type,n.binding.mapping):null},Ev=(e,t)=>{let n=pp.getState(e);return n?em(n.doc,n.type,t,n.binding.mapping)||0:-1},Dv=(e,t)=>{let n=t;for(;n?.parentNode&&n.parentNode!==e.dom;)n=n.parentNode;return n},Ov=new f(`dragHandle`),kv=({pluginKey:e=Ov,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,p=-1,m,h=null,g=null;function _(){t&&(t.style.visibility=`hidden`,t.style.pointerEvents=`none`)}function v(){if(t){if(!n.isEditable){_();return}t.style.visibility=``,t.style.pointerEvents=`auto`}}function y(e){B(i?.()||{getBoundingClientRect:()=>e.getBoundingClientRect()},t,r).then(e=>{Object.assign(t.style,{position:e.strategy,left:`${e.x}px`,top:`${e.y}px`})})}function b(e){o?.(e),Sv(e,n,c,{node:d,pos:p}),t&&(t.dataset.dragging=`true`),setTimeout(()=>{t&&(t.style.pointerEvents=`none`)},0)}function x(e){s?.(e),_(),t&&(t.style.pointerEvents=`auto`,t.dataset.dragging=`false`)}function S(){if(re()){let e=n.view.dom;requestAnimationFrame(()=>{e.isContentEditable&&(e.contentEditable=`false`,e.contentEditable=`true`)})}}return l.appendChild(t),{unbind(){t.removeEventListener(`dragstart`,b),t.removeEventListener(`dragend`,x),document.removeEventListener(`drop`,S),h&&(cancelAnimationFrame(h),h=null,g=null)},plugin:new _e({key:typeof e==`string`?new f(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 _(),u=!1,d=null,p=-1,a?.({editor:n,node:null,pos:-1}),r;if(e.docChanged&&p!==-1&&t)if(G_(e)){let e=Ev(o,m);e!==p&&(p=e)}else{let t=e.mapping.map(p);t!==p&&(p=t,m=Tv(o,p))}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`,b),t.addEventListener(`dragend`,x),document.addEventListener(`drop`,S),{update(r,i){if(!t)return;if(!n.isEditable){_();return}if(u?t.draggable=!1:t.draggable=!0,e.state.doc.eq(i.doc)||p===-1)return;let o=e.nodeDOM(p);if(o=Dv(e,o),o===e.dom||o?.nodeType!==1)return;let s=e.posAtDOM(o,0),c=wv(n.state.doc,s),l=Cv(n.state.doc,s);d=c,p=l,m=Tv(e.state,p),a?.({editor:n,node:d,pos:p}),y(o)},destroy(){t.removeEventListener(`dragstart`,b),t.removeEventListener(`dragend`,x),document.removeEventListener(`drop`,S),h&&(cancelAnimationFrame(h),h=null,g=null),t&&bv(l)}}},props:{handleDOMEvents:{keydown(e){return!t||u?!1:e.hasFocus()?(_(),d=null,p=-1,a?.({editor:n,node:null,pos:-1}),!1):!1},mouseleave(e,t){return u||t.target&&!l.contains(t.relatedTarget)&&(_(),d=null,p=-1,a?.({editor:n,node:null,pos:-1})),!1},mousemove(e,r){return!t||u||(g={x:r.clientX,y:r.clientY},h)||(h=requestAnimationFrame(()=>{if(h=null,!g)return;let{x:t,y:r}=g;g=null;let i=vv({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=Dv(e,o),o===e.dom||o?.nodeType!==1)return;let t=e.posAtDOM(o,0);s=wv(n.state.doc,t),l=Cv(n.state.doc,t)}s!==d&&(d=s,p=l??-1,m=Tv(e.state,p),a?.({editor:n,node:d,pos:p}),y(o),v())})),!1}}}})}};function Av(e){return e===!1||e===void 0?{enabled:!1,rules:[],defaultRules:!0,allowedContainers:void 0,edgeDetection:cv(`none`)}:e===!0?{enabled:!0,rules:[],defaultRules:!0,allowedContainers:void 0,edgeDetection:cv(`left`)}:{enabled:!0,rules:e.rules??[],defaultRules:e.defaultRules??!0,allowedContainers:e.allowedContainers,edgeDetection:cv(e.edgeDetection)}}var jv={placement:`left-start`,strategy:`absolute`};ke.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=Av(this.options.nested);return[kv({computePositionConfig:{...jv,...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 Mv=20,Nv=44,Pv=28;function Fv(){let e=document.createElement(`div`);e.className=`ok-block-controls`,e.style.visibility=`hidden`;let t=document.createElement(`button`);t.className=`ok-add-block-btn`,t.setAttribute(`aria-label`,`Add block below`),t.setAttribute(`type`,`button`),t.innerHTML=`<svg aria-hidden="true" xmlns="http://www.w3.org/2000/svg" width="16" height="16" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" class="lucide lucide-plus"><path d="M5 12h14"/><path d="M12 5v14"/></svg>`,t.addEventListener(`mousedown`,e=>{e.preventDefault(),e.stopPropagation()});let n=document.createElement(`div`);return n.className=`ok-drag-grip`,n.setAttribute(`aria-hidden`,`true`),n.innerHTML=`<svg xmlns="http://www.w3.org/2000/svg" width="16" height="16" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" class="lucide lucide-grip-vertical-icon lucide-grip-vertical"><circle cx="9" cy="12" r="1"/><circle cx="9" cy="5" r="1"/><circle cx="9" cy="19" r="1"/><circle cx="15" cy="12" r="1"/><circle cx="15" cy="5" r="1"/><circle cx="15" cy="19" r="1"/></svg>`,e.appendChild(t),e.appendChild(n),{container:e,addBtn:t}}function Iv(e,t,n){let{state:r,view:i}=e,a=t+n.nodeSize;if(a>r.doc.content.size)return;let{tr:o}=r,s=r.schema.nodes.paragraph?.create();if(!s)return;o.insert(a,s);let c=j.near(o.doc.resolve(a+1));o.setSelection(c).scrollIntoView(),i.dispatch(o),i.focus(),e.commands.insertContent(`/`)}var Lv=ke.create({name:`blockDragHandle`,addProseMirrorPlugins(){let e=this.editor,t=null,n=-1,{container:r,addBtn:i}=Fv();return i.addEventListener(`click`,()=>{t&&n>=0&&Iv(e,n,t)}),[kv({element:r,editor:e,onNodeChange({node:e,pos:r}){t=e,n=r??-1},computePositionConfig:{placement:`left-start`,strategy:`absolute`,middleware:[T(({rects:e})=>({mainAxis:10,crossAxis:((e.reference.height<=Nv?e.reference.height:Pv)-Mv)/2}))]},nestedOptions:Av(!1)}).plugin]}});function Rv(e){let t=e.trim();if(!t)return null;let n=me(t);return n?{target:n,alias:n===t?null:t,anchor:null}:null}function zv(e){let t=e.trim();if(!t)return[];let n=me(t);return n.length>0&&n!==t?[n]:[]}function Bv(e,t){let n=e.trim();return n?t.has(n)?!0:zv(n).some(e=>t.has(e)):!1}var Vv=ke.create({name:`headingAnchors`,addProseMirrorPlugins(){return[new _e({props:{decorations(e){let t=[],n=new Map;return e.doc.descendants((e,r)=>{if(e.type.name===`heading`){let i=d(e.textContent,n);if(!i)return;t.push(R.node(r,r+e.nodeSize,{id:i}))}}),g.create(e.doc,t)}}})]}}),Hv=new Set([`http:`,`https:`,`mailto:`,`tel:`]);function Uv(e){try{let t=new URL(e);return Hv.has(t.protocol)}catch{return!1}}function Wv(e=window.location.hash){let t=e.match(/^#\/([^?#]+)/);return t?decodeURIComponent(t[1]):``}function Gv(e,t=window.location.hash){return te(e,Wv(t))}function Kv({docName:e,anchor:t}){return t?`#/${e}?anchor=${encodeURIComponent(t)}`:`#/${e}`}function qv(e){e.startsWith(`#`)||Uv(e)?window.open(e,`_blank`,`noopener,noreferrer`):console.warn(`[safe-nav] blocked non-safe scheme:`,e)}function Jv(e){window.location.assign(Kv(e))}function Yv(e){qv(Kv(e))}function Xv(e){return e.metaKey||e.ctrlKey}function Zv(e,t=window.location.hash){let n=Wv(t);if(!n)return;let r=document.getElementById(e);r&&r.scrollIntoView({behavior:`smooth`,block:`start`}),window.location.assign(de(n,e))}function Qv(e,t=window.location.hash){if(e.kind===`doc`){Jv(e);return}if(e.kind===`anchor`){Zv(e.anchor,t);return}qv(e.url)}function $v(e,t,n=window.location.hash){return le(Wv(n),e,t)}var ey=e=>{let t=(0,rr.c)(13),{kind:n,ariaLabel:r,onDeactivate:i,children:s,layout:c,className:l,"data-slot":u}=e,d=(c===void 0?`standard`:c)===`wide`?`w-[min(720px,calc(100%-1rem))]`:`w-80`,f;t[0]!==l||t[1]!==d?(f=a(`ok-interaction-prop-panel pointer-events-auto absolute left-1/2 top-2 z-40 -translate-x-1/2 rounded-md border border-border bg-popover p-3 shadow-lg`,d,l),t[0]=l,t[1]=d,t[2]=f):f=t[2];let p;t[3]===Symbol.for(`react.memo_cache_sentinel`)?(p=(0,q.jsx)(Je,{className:`size-3.5`,"aria-hidden":`true`}),t[3]=p):p=t[3];let m;t[4]===i?m=t[5]:(m=(0,q.jsx)(o,{type:`button`,variant:`ghost`,size:`icon`,"aria-label":`Close`,onClick:i,className:`absolute right-1 top-1 size-7`,children:p}),t[4]=i,t[5]=m);let h;return t[6]!==r||t[7]!==s||t[8]!==u||t[9]!==n||t[10]!==f||t[11]!==m?(h=(0,q.jsxs)(`div`,{role:`dialog`,"aria-label":r,"data-ok-prop-panel":n,"data-slot":u,className:f,children:[s,m]}),t[6]=r,t[7]=s,t[8]=u,t[9]=n,t[10]=f,t[11]=m,t[12]=h):h=t[12],h};function ty(e,t){let n=[e,...t.fallbackTargets??[]],r=new Set,i=null;for(let e of n){if(r.has(e))continue;r.add(e);let n=oe(e,{pages:t.pages,folderPaths:t.folderPaths});if(n.kind===`missing`){i??=n;continue}return{kind:`navigate`,displayState:n.kind===`folder`?`folder`:`resolved`,resolvedTarget:n,hashDocName:n.target}}let a=i??oe(e,{pages:t.pages,folderPaths:t.folderPaths});if(a.kind!==`missing`)return{kind:`navigate`,displayState:a.kind===`folder`?`folder`:`resolved`,resolvedTarget:a,hashDocName:a.target};let o=t.createDialogSeed??Ee(a.target);return{kind:`create`,displayState:`missing`,resolvedTarget:a,initialDir:o.initialDir,suggestedName:o.suggestedName}}function ny(e){if(e.kind!==`navigate`||e.displayState!==`folder`)return null;let t=e.resolvedTarget;return`folderPath`in t?{initialDir:t.folderPath,suggestedName:`index.md`}:null}function ry(e){let t=(0,rr.c)(10),n,r,i;t[0]===e?(n=t[1],r=t[2],i=t[3]):({className:n,type:i,...r}=e,t[0]=e,t[1]=n,t[2]=r,t[3]=i);let o;t[4]===n?o=t[5]:(o=a(`h-8 w-full min-w-0 rounded-lg border border-input bg-transparent px-2.5 py-1 text-base transition-colors outline-none file:inline-flex file:h-6 file:border-0 file:bg-transparent file:text-sm file:font-medium file:text-foreground placeholder:text-muted-foreground focus-visible:border-ring focus-visible:ring-3 focus-visible:ring-ring/50 disabled:pointer-events-none disabled:cursor-not-allowed disabled:bg-input/50 disabled:opacity-50 aria-invalid:border-destructive aria-invalid:ring-3 aria-invalid:ring-destructive/20 md:text-sm dark:bg-input/30 dark:disabled:bg-input/80 dark:aria-invalid:border-destructive/50 dark:aria-invalid:ring-destructive/40`,n),t[4]=n,t[5]=o);let s;return t[6]!==r||t[7]!==o||t[8]!==i?(s=(0,q.jsx)(`input`,{type:i,"data-slot":`input`,className:o,...r}),t[6]=r,t[7]=o,t[8]=i,t[9]=s):s=t[9],s}function iy(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 ay(e){return e.endsWith(`.md`)?e:`${e}.md`}function oy(e){let t=ay(e.fileName.trim());if(e.kind===`folder`){let n=(e.folderName??``).trim();return`${e.initialDir?`${e.initialDir}/${n}`:n}/${t}`}return e.initialDir?`${e.initialDir}/${t}`:t}function sy(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 cy(e){let t=e.value.lastIndexOf(`.`);t>0?e.setSelectionRange(0,t):e.select()}function ly(e){let t=(0,rr.c)(87),{open:n,onOpenChange:r,kind:i,initialDir:a,suggestedName:s,description:c,onCreated:l}=e,{addPage:u}=ve(),[d,f]=(0,G.useState)(``),[p,m]=(0,G.useState)(``),[h,g]=(0,G.useState)(null),[_,v]=(0,G.useState)(!1),[y,b]=(0,G.useState)(null),x=(0,G.useId)(),S=(0,G.useId)(),C=(0,G.useId)(),w=(0,G.useRef)(null),T=(0,G.useRef)(null),E,D;t[0]!==i||t[1]!==n||t[2]!==s?(E=()=>{n&&(g(null),b(null),v(!1),m(``),f(i===`file`?s??`untitled.md`:`index.md`))},D=[n,i,s],t[0]=i,t[1]=n,t[2]=s,t[3]=E,t[4]=D):(E=t[3],D=t[4]),(0,G.useEffect)(E,D);let O;t[5]!==d||t[6]!==p||t[7]!==a||t[8]!==i?(O=function(){return oy({kind:i,initialDir:a,fileName:d,folderName:p})},t[5]=d,t[6]=p,t[7]=a,t[8]=i,t[9]=O):O=t[9];let k=O,A;t[10]!==d||t[11]!==p||t[12]!==i?(A=function(){if(i===`folder`){let e=iy(p.trim());if(e)return{message:`Folder name: ${e}`,field:`folder`}}let e=iy(d.trim());return e?{message:e,field:`file`}:null},t[10]=d,t[11]=p,t[12]=i,t[13]=A):A=t[13];let j=A,M;t[14]!==_||t[15]!==d||t[16]!==p||t[17]!==i?(M=_||!d.trim()||i===`folder`&&!p.trim(),t[14]=_,t[15]=d,t[16]=p,t[17]=i,t[18]=M):M=t[18];let N=M,P;t[19]!==u||t[20]!==k||t[21]!==j||t[22]!==i||t[23]!==l||t[24]!==r?(P=async function(){let e=j();if(e){g(e.message),b(e.field);return}v(!0),g(null),b(null);let t=k();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{}v(!1),g(t),b(`form`);return}let n=await e.json();if(v(!1),!n.ok){g(n.error??`Failed to create ${i}`),b(`form`);return}let a=n.docName??t.replace(/\.md$/,``);r(!1),window.location.hash=`#/${a}`,u(a),Oe([`files`,`backlinks`,`graph`]),l?.(a)}catch(e){console.warn(`[NewItemDialog] create failed:`,e),v(!1),g(`Network error — please try again`),b(`form`)}},t[19]=u,t[20]=k,t[21]=j,t[22]=i,t[23]=l,t[24]=r,t[25]=P):P=t[25];let F=P,I=a||`(root)`,L=i===`file`?`New file`:`New folder`,R;t[26]===L?R=t[27]:(R=(0,q.jsx)(Ge,{children:L}),t[26]=L,t[27]=R);let z;t[28]!==c||t[29]!==I?(z=c??(0,q.jsxs)(q.Fragment,{children:[`Create in `,(0,q.jsx)(`span`,{className:`font-medium text-foreground`,children:I})]}),t[28]=c,t[29]=I,t[30]=z):z=t[30];let B;t[31]===z?B=t[32]:(B=(0,q.jsx)(ze,{children:z}),t[31]=z,t[32]=B);let V;t[33]!==R||t[34]!==B?(V=(0,q.jsxs)(He,{children:[R,B]}),t[33]=R,t[34]=B,t[35]=V):V=t[35];let H;t[36]!==h||t[37]!==y||t[38]!==x||t[39]!==S||t[40]!==p||t[41]!==i?(H=i===`folder`&&(0,q.jsxs)(`div`,{children:[(0,q.jsx)(`label`,{className:`mb-1.5 block text-sm font-medium`,htmlFor:S,children:`Folder name`}),(0,q.jsx)(ry,{ref:T,id:S,value:p,onChange:e=>{m(e.target.value),g(null)},placeholder:`folder-name`,autoFocus:!0,"aria-describedby":h&&(y===`folder`||y===`form`)?x:void 0,"aria-invalid":h&&(y===`folder`||y===`form`)?!0:void 0,onKeyDown:e=>{if(e.key===`Enter`){e.preventDefault();let t=iy(p.trim());if(t){g(`Folder name: ${t}`),b(`folder`);return}w.current?.focus()}}})]}),t[36]=h,t[37]=y,t[38]=x,t[39]=S,t[40]=p,t[41]=i,t[42]=H):H=t[42];let ee=i===`folder`?`First file name`:`File name`,te;t[43]!==C||t[44]!==ee?(te=(0,q.jsx)(`label`,{className:`mb-1.5 block text-sm font-medium`,htmlFor:C,children:ee}),t[43]=C,t[44]=ee,t[45]=te):te=t[45];let ne;t[46]===Symbol.for(`react.memo_cache_sentinel`)?(ne=e=>{f(e.target.value),g(null)},t[46]=ne):ne=t[46];let re=i===`file`,ie=h&&(y===`file`||y===`form`)?x:void 0,ae=h&&(y===`file`||y===`form`)?!0:void 0,oe;t[47]!==F||t[48]!==N?(oe=e=>{e.key===`Enter`&&!N&&F()},t[47]=F,t[48]=N,t[49]=oe):oe=t[49];let se;t[50]!==C||t[51]!==d||t[52]!==re||t[53]!==ie||t[54]!==ae||t[55]!==oe?(se=(0,q.jsx)(ry,{ref:w,id:C,value:d,onChange:ne,placeholder:`my-note.md`,autoFocus:re,"aria-describedby":ie,"aria-invalid":ae,onFocus:uy,onKeyDown:oe}),t[50]=C,t[51]=d,t[52]=re,t[53]=ie,t[54]=ae,t[55]=oe,t[56]=se):se=t[56];let ce;t[57]!==te||t[58]!==se?(ce=(0,q.jsxs)(`div`,{children:[te,se]}),t[57]=te,t[58]=se,t[59]=ce):ce=t[59];let le;t[60]!==h||t[61]!==x?(le=h&&(0,q.jsx)(`p`,{id:x,role:`alert`,className:`text-xs text-red-600 dark:text-red-400`,children:h}),t[60]=h,t[61]=x,t[62]=le):le=t[62];let ue;t[63]!==H||t[64]!==ce||t[65]!==le?(ue=(0,q.jsxs)(`div`,{className:`space-y-3`,children:[H,ce,le]}),t[63]=H,t[64]=ce,t[65]=le,t[66]=ue):ue=t[66];let de;t[67]===r?de=t[68]:(de=()=>r(!1),t[67]=r,t[68]=de);let fe;t[69]!==_||t[70]!==de?(fe=(0,q.jsx)(o,{variant:`outline`,className:`font-mono uppercase`,onClick:de,disabled:_,children:`Cancel`}),t[69]=_,t[70]=de,t[71]=fe):fe=t[71];let pe=_?`Creating...`:`Create`,me;t[72]!==F||t[73]!==N||t[74]!==pe?(me=(0,q.jsx)(o,{onClick:F,disabled:N,children:pe}),t[72]=F,t[73]=N,t[74]=pe,t[75]=me):me=t[75];let he;t[76]!==fe||t[77]!==me?(he=(0,q.jsxs)(Ie,{children:[fe,me]}),t[76]=fe,t[77]=me,t[78]=he):he=t[78];let ge;t[79]!==V||t[80]!==ue||t[81]!==he?(ge=(0,q.jsxs)(We,{className:`sm:max-w-md`,"data-ok-layer-spawned":``,children:[V,ue,he]}),t[79]=V,t[80]=ue,t[81]=he,t[82]=ge):ge=t[82];let _e;return t[83]!==r||t[84]!==n||t[85]!==ge?(_e=(0,q.jsx)(Ke,{open:n,onOpenChange:r,children:ge}),t[83]=r,t[84]=n,t[85]=ge,t[86]=_e):_e=t[86],_e}function uy(e){return cy(e.currentTarget)}var dy=class{registry=new Map;_activeNodeId=null;listeners=new Set;_snapshot={activeNodeId:null,active:null};register(e){this.registry.set(e.nodeId,e),this._activeNodeId===e.nodeId&&this.refreshSnapshot()}deregister(e){this.registry.delete(e)&&this._activeNodeId===e&&(this._activeNodeId=null,this.refreshSnapshot())}setActiveNode(e){this._activeNodeId!==e&&(e!==null&&!this.registry.has(e)||(this._activeNodeId=e,this.refreshSnapshot()))}getActiveNode(){return this._activeNodeId}getRegistration(e){return this.registry.get(e)}hasRegistration(e){return this.registry.has(e)}clear(){this.registry.clear(),this._activeNodeId=null,this.refreshSnapshot()}getSnapshot=()=>this._snapshot;subscribe=e=>(this.listeners.add(e),()=>{this.listeners.delete(e)});refreshSnapshot(){let e=this._activeNodeId==null?null:this.registry.get(this._activeNodeId)??null;this._snapshot={activeNodeId:this._activeNodeId,active:e};for(let e of this.listeners)e()}};function fy(e,t){let n=e??null;for(;n&&typeof n==`object`;){let e=n.getAttribute;if(typeof e==`function`){let r=e.call(n,`data-mark-id`);if(r&&t.hasRegistration(r))return r;let i=e.call(n,`data-node-id`);if(i&&t.hasRegistration(i))return i}n=n.parentElement??null}return null}var py=e=>{let t=(0,rr.c)(18),{store:n}=e,r;t[0]===n?r=t[1]:(r=()=>n.getSnapshot(),t[0]=n,t[1]=r);let[i,a]=(0,G.useState)(r),o,s;t[2]===n?(o=t[3],s=t[4]):(o=()=>(a(n.getSnapshot()),n.subscribe(()=>{a(n.getSnapshot())})),s=[n],t[2]=n,t[3]=o,t[4]=s),(0,G.useEffect)(o,s);let{active:c}=i;if(!c)return null;let l;t[5]===n?l=t[6]:(l=()=>n.setActiveNode(null),t[5]=n,t[6]=l);let u,d,f;if(t[7]!==c.controls||t[8]!==c.nodeId||t[9]!==c.type||t[10]!==l){let e={nodeId:c.nodeId,type:c.type,deactivate:l};u=c.controls.propPanel?.(e),d=c.controls.toolbar?.(e),f=c.controls.breadcrumb?.(e),t[7]=c.controls,t[8]=c.nodeId,t[9]=c.type,t[10]=l,t[11]=u,t[12]=d,t[13]=f}else u=t[11],d=t[12],f=t[13];let p;return t[14]!==u||t[15]!==d||t[16]!==f?(p=(0,q.jsxs)(q.Fragment,{children:[u,d,f]}),t[14]=u,t[15]=d,t[16]=f,t[17]=p):p=t[17],p};function my(e){return e.editorView?.dom??e.view?.dom??null}function hy(e,t){let n=e;for(;n;){if(n.getAttribute?.(`data-mark-id`)===t||n.getAttribute?.(`data-node-id`)===t)return!0;n=n.parentElement}return!1}function gy(e){let{editor:t}=e,n=new dy,r=my(t),i=!1,a=null,o=n.subscribe(()=>{let e=n.getActiveNode();if(e!==null){if(typeof document<`u`){let t=document.activeElement;a=t&&hy(t,e)?t:null}return}if(typeof document>`u`)return;let i=a;if(a=null,i&&document.contains(i)&&typeof i.focus==`function`){try{i.focus({preventScroll:!0})}catch{}return}let o=r??my(t);if(o&&typeof o.focus==`function`)try{o.focus({preventScroll:!0})}catch{}}),s=e=>{let t=e;if(t.button===2)return;if(t.metaKey||t.ctrlKey||t.button===1){t.button===1&&t.preventDefault?.();return}let r=fy(e.target,n);if(r===null)return;let i=n.getRegistration(r);i?.handlePrimary&&i.handlePrimary({nodeId:r,type:i.type,newTab:!1})||n.setActiveNode(r)},c=e=>{let t=e;if(t.button===2||t.type===`click`&&t.button===1||!(t.metaKey||t.ctrlKey||t.button===1))return;let r=fy(e.target,n);if(r===null)return;let i=n.getRegistration(r);i?.handlePrimary&&i.handlePrimary({nodeId:r,type:i.type,newTab:!0})&&t.preventDefault?.()},l=e=>{let t=e;if(t.key===`Escape`){n.getActiveNode()!==null&&(n.setActiveNode(null),t.preventDefault?.());return}if(t.key!==`Enter`&&t.key!==` `&&t.key!==`Spacebar`)return;let r=fy(e.target,n);if(r===null)return;let i=n.getRegistration(r);t.preventDefault?.(),!(i?.handlePrimary&&i.handlePrimary({nodeId:r,type:i.type,newTab:!1}))&&n.setActiveNode(r)},u=e=>{if(n.getActiveNode()===null)return;let t=e.target;t&&(r?.contains(t)||t instanceof Element&&(t.closest(`[data-ok-interaction-layer]`)||t.closest(`[data-ok-prop-panel]`)||t.closest(`[data-ok-layer-spawned]`))||n.setActiveNode(null))},d=()=>{i||(r=my(t),r&&(r.addEventListener(`pointerdown`,s,!0),r.addEventListener(`click`,c,!0),r.addEventListener(`auxclick`,c,!0),r.addEventListener(`keydown`,l,!0),typeof document<`u`&&document.addEventListener(`pointerdown`,u,!0),i=!0))},f=()=>{i&&=(r?.removeEventListener(`pointerdown`,s,!0),r?.removeEventListener(`click`,c,!0),r?.removeEventListener(`auxclick`,c,!0),r?.removeEventListener(`keydown`,l,!0),typeof document<`u`&&document.removeEventListener(`pointerdown`,u,!0),!1)};return d(),{register(e){n.register(e),i||d()},deregister(e){n.deregister(e)},setActiveNode(e){n.setActiveNode(e)},getActiveNode(){return n.getActiveNode()},getRegistration(e){return n.getRegistration(e)},destroy(){f(),o(),n.clear()},store:n}}var _y=e=>{let t=(0,rr.c)(2),{store:n}=e,r;return t[0]===n?r=t[1]:(r=(0,q.jsx)(`div`,{"data-ok-interaction-layer":``,className:`contents`,children:(0,q.jsx)(py,{store:n})}),t[0]=n,t[1]=r),r},vy=new WeakMap;function yy(e){let t=vy.get(e);if(t)return t;let n=gy({editor:e});return vy.set(e,n),e.on(`destroy`,()=>{n.destroy(),vy.delete(e)}),n}var by=new f(`markIdentity`);function xy(){return{byId:new Map,counter:0}}function Sy(e,t,n,r,i){let a=[];for(let e of t.byId.values()){let t=i?i.map(e.from,-1):e.from,n=i?i.map(e.to,1):e.to;n<=t||a.push({id:e.id,markType:e.markType,attrs:e.attrs,from:t,to:n})}let o=new Map,s=new Set,c=t.counter;return e.descendants((e,t)=>{if(!(!e.isInline||e.marks.length===0))for(let i of e.marks){if(!n.has(i.type.name)||r&&!r(i))continue;let l=null;for(let e of a)if(!s.has(e.id)&&e.markType===i.type.name&&Cy(e.attrs,i.attrs)&&!(t<e.from||t>=e.to)){l=e.id;break}let u=l??`m${++c}`;s.add(u);let d=t,f=t+e.nodeSize,p=o.get(u);p?p.to=Math.max(p.to,f):o.set(u,{id:u,markType:i.type.name,attrs:i.attrs,from:d,to:f})}}),{byId:o,counter:c}}function Cy(e,t){let n=Object.keys(e),r=Object.keys(t);if(n.length!==r.length)return!1;for(let r of n){let n=e[r],i=t[r];if(n!==i&&!(typeof n==`object`&&n&&typeof i==`object`&&i&&Cy(n,i)))return!1}return!0}function wy(e,t,n,r){let i=new Set(t.byId.keys());for(let[r,i]of t.byId)e.has(r)||n?.(i);for(let t of e)i.has(t)||r?.(t);return i}function Ty(e){let{markTypes:t,predicate:n,onRegister:r,onDeregister:i}=e,a=new Set(t);return new _e({key:by,state:{init(e,t){return Sy(t.doc,xy(),a,n)},apply(e,t,r,i){return e.docChanged?Sy(i.doc,t,a,n,e.mapping):t}},view(){let e=new Set;return{update(t){let n=by.getState(t.state);n&&(e=wy(e,n,r,i))},destroy(){for(let t of e)i?.(t);e=new Set}}}})}function Ey(e,t){return by.getState(e)?.byId.get(t)??null}function Dy(e){let{editor:t,layer:n,renderPropPanel:r,handlePrimary:i}=e;return{onRegister:e=>{n.register({type:e.markType,nodeId:e.id,controls:{propPanel:e=>r({editor:t,nodeId:e.nodeId,deactivate:e.deactivate})},handlePrimary:i?e=>i({editor:t,nodeId:e.nodeId,newTab:e.newTab}):void 0})},onDeregister:e=>{n.deregister(e)}}}function Oy(e){let{editor:t,layer:n,markTypes:r,predicate:i,renderPropPanel:a,handlePrimary:o}=e,s=Dy({editor:t,layer:n,renderPropPanel:a,handlePrimary:o});return Ty({markTypes:[...r],predicate:i,onRegister:s.onRegister,onDeregister:s.onDeregister})}function ky(e){let t=yy(e.editor);return Oy({...e,layer:t})}function Ay(e){let{char:t,allowSpaces:n,allowToIncludeChar:r,allowedPrefixes:i,startOfLine:a,$position:o}=e,s=n&&!r,c=ye(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 jy(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,`
|
|
5
|
+
`);return/\s/.test(n)}):!1}var My=new f(`suggestion`);function Ny({pluginKey:e=My,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=Ay,shouldShow:_,shouldResetDismissed:v}){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})=>v?.({editor:t,state:r,range:n,match:e,transaction:i,allowSpaces:x})?!1:x?e.range.from===n.from:e.range.from===n.from&&!jy(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 _e({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:g,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&&(g||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})&&(!_||_({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),g.create(e.doc,[R.inline(n.from,n.to,{nodeName:s,class:o.join(` `),"data-decoration-id":r,"data-decoration-content":l})])}}});return E}var Py=Ny,Fy=n(t(((e,t)=>{((e,n)=>{typeof define==`function`&&define.amd?define([],n):typeof t==`object`&&t.exports?t.exports=n():e.fuzzysort=n()})(e,e=>{var t=(e,t)=>{if(!e||!t)return F;var n=p(e);j(t)||(t=f(t));var r=n.bitflags;return(r&t._bitflags)===r?h(n,t):F},n=(e,t,n)=>{if(!e)return n?.all?m(t,n):P;var r=p(e),i=r.bitflags,a=r.containsSpace,o=u(n?.threshold||0),c=n?.limit||M,l=0,d=0,g=t.length;function _(e){l<c?(L.add(e),++l):(++d,e._score>L.peek()._score&&L.replaceTop(e))}if(n?.key)for(var v=n.key,y=0;y<g;++y){var b=t[y],x=A(b,v);if(x&&(j(x)||(x=f(x)),(i&x._bitflags)===i)){var S=h(r,x);S!==F&&(S._score<o||(S.obj=b,_(S)))}}else if(n?.keys){var C=n.keys,w=C.length;outer:for(var y=0;y<g;++y){for(var b=t[y],T=0,R=0;R<w;++R){var v=C[R],x=A(b,v);if(!x){O[R]=I;continue}j(x)||(x=f(x)),O[R]=x,T|=x._bitflags}if((i&T)===i){if(a)for(let e=0;e<r.spaceSearches.length;e++)E[e]=N;for(var R=0;R<w;++R){if(x=O[R],x===I){k[R]=I;continue}if(k[R]=h(r,x,!1,a),k[R]===F){k[R]=I;continue}if(a)for(let e=0;e<r.spaceSearches.length;e++){if(D[e]>-1e3&&E[e]>N){var z=(E[e]+D[e])/4;z>E[e]&&(E[e]=z)}D[e]>E[e]&&(E[e]=D[e])}}if(a){for(let e=0;e<r.spaceSearches.length;e++)if(E[e]===N)continue outer}else{var B=!1;for(let e=0;e<w;e++)if(k[e]._score!==N){B=!0;break}if(!B)continue}var V=new s(w);for(let e=0;e<w;e++)V[e]=k[e];if(a){var H=0;for(let e=0;e<r.spaceSearches.length;e++)H+=E[e]}else{var H=N;for(let e=0;e<w;e++){var S=V[e];if(S._score>-1e3&&H>N){var z=(H+S._score)/4;z>H&&(H=z)}S._score>H&&(H=S._score)}}if(V.obj=b,V._score=H,n?.scoreFn){if(H=n.scoreFn(V),!H)continue;H=u(H),V._score=H}H<o||_(V)}}}else for(var y=0;y<g;++y){var x=t[y];if(x&&(j(x)||(x=f(x)),(i&x._bitflags)===i)){var S=h(r,x);S!==F&&(S._score<o||_(S))}}if(l===0)return P;for(var ee=Array(l),y=l-1;y>=0;--y)ee[y]=L.poll();return ee.total=l+d,ee},r=(e,t=`<b>`,n=`</b>`)=>{for(var r=typeof t==`function`?t:void 0,i=e.target,a=i.length,o=e.indexes,s=``,c=0,l=0,u=!1,d=[],f=0;f<a;++f){var p=i[f];if(o[l]===f){if(++l,u||(u=!0,r?(d.push(s),s=``):s+=t),l===o.length){r?(s+=p,d.push(r(s,c++)),s=``,d.push(i.substr(f+1))):s+=p+n+i.substr(f+1);break}}else u&&(u=!1,r?(d.push(r(s,c++)),s=``):s+=n);s+=p}return r?d:s},i=e=>{typeof e==`number`?e=``+e:typeof e!=`string`&&(e=``);var t=v(e);return c(e,{_targetLower:t._lower,_targetLowerCodes:t.lowerCodes,_bitflags:t.bitflags})},a=()=>{x.clear(),S.clear()};class o{get indexes(){return this._indexes.slice(0,this._indexes.len).sort((e,t)=>e-t)}set indexes(e){return this._indexes=e}highlight(e,t){return r(this,e,t)}get score(){return l(this._score)}set score(e){this._score=u(e)}}class s extends Array{get score(){return l(this._score)}set score(e){this._score=u(e)}}var c=(e,t)=>{let n=new o;return n.target=e,n.obj=t.obj??F,n._score=t._score??N,n._indexes=t._indexes??[],n._targetLower=t._targetLower??``,n._targetLowerCodes=t._targetLowerCodes??F,n._nextBeginningIndexes=t._nextBeginningIndexes??F,n._bitflags=t._bitflags??0,n},l=e=>e===N?0:e>1?e:Math.E**(((-e+1)**.04307-1)*-2),u=e=>e===0?N:e>1?e:1-(Math.log(e)/-2+1)**(1/.04307),d=e=>{typeof e==`number`?e=``+e:typeof e!=`string`&&(e=``),e=e.trim();var t=v(e),n=[];if(t.containsSpace){var r=e.split(/\s+/);r=[...new Set(r)];for(var i=0;i<r.length;i++)if(r[i]!==``){var a=v(r[i]);n.push({lowerCodes:a.lowerCodes,_lower:r[i].toLowerCase(),containsSpace:!1})}}return{lowerCodes:t.lowerCodes,_lower:t._lower,containsSpace:t.containsSpace,bitflags:t.bitflags,spaceSearches:n}},f=e=>{if(e.length>999)return i(e);var t=x.get(e);return t===void 0?(t=i(e),x.set(e,t),t):t},p=e=>{if(e.length>999)return d(e);var t=S.get(e);return t===void 0?(t=d(e),S.set(e,t),t):t},m=(e,t)=>{var n=[];n.total=e.length;var r=t?.limit||M;if(t?.key)for(var i=0;i<e.length;i++){var a=e[i],o=A(a,t.key);if(o!=F){j(o)||(o=f(o));var l=c(o.target,{_score:o._score,obj:a});if(n.push(l),n.length>=r)return n}}else if(t?.keys)for(var i=0;i<e.length;i++){for(var a=e[i],u=new s(t.keys.length),d=t.keys.length-1;d>=0;--d){var o=A(a,t.keys[d]);if(!o){u[d]=I;continue}j(o)||(o=f(o)),o._score=N,o._indexes.len=0,u[d]=o}if(u.obj=a,u._score=N,n.push(u),n.length>=r)return n}else for(var i=0;i<e.length;i++){var o=e[i];if(o!=F&&(j(o)||(o=f(o)),o._score=N,o._indexes.len=0,n.push(o),n.length>=r))return n}return n},h=(e,t,n=!1,r=!1)=>{if(n===!1&&e.containsSpace)return g(e,t,r);for(var i=e._lower,a=e.lowerCodes,s=a[0],c=t._targetLowerCodes,l=a.length,u=c.length,d=0,f=0,p=0;;){var m=s===c[f];if(m){if(C[p++]=f,++d,d===l)break;s=a[d]}if(++f,f>=u)return F}var d=0,h=!1,_=0,v=t._nextBeginningIndexes;v===F&&(v=t._nextBeginningIndexes=b(t.target)),f=C[0]===0?0:v[C[0]-1];var y=0;if(f!==u)for(;;)if(f>=u){if(d<=0||(++y,y>200))break;--d;var x=w[--_];f=v[x]}else{var m=a[d]===c[f];if(m){if(w[_++]=f,++d,d===l){h=!0;break}++f}else f=v[f]}var S=l<=1?-1:t._targetLower.indexOf(i,C[0]),T=!!~S,E=T?S===0||t._nextBeginningIndexes[S-1]===S:!1;if(T&&!E){for(var D=0;D<v.length;D=v[D])if(!(D<=S)){for(var O=0;O<l&&a[O]===t._targetLowerCodes[D+O];O++);if(O===l){S=D,E=!0;break}}}var k=e=>{for(var t=0,n=0,r=1;r<l;++r)e[r]-e[r-1]!==1&&(t-=e[r],++n);var i=e[l-1]-e[0]-(l-1);if(t-=(12+i)*n,e[0]!==0&&(t-=e[0]*e[0]*.2),!h)t*=1e3;else{for(var a=1,r=v[0];r<u;r=v[r])++a;a>24&&(t*=(a-24)*10)}return t-=(u-l)/2,T&&(t/=1+l*l*1),E&&(t/=1+l*l*1),t-=(u-l)/2,t};if(!h){if(T)for(var D=0;D<l;++D)C[D]=S+D;var A=C,j=k(A)}else if(E){for(var D=0;D<l;++D)C[D]=S+D;var A=C,j=k(C)}else var A=w,j=k(w);t._score=j;for(var D=0;D<l;++D)t._indexes[D]=A[D];t._indexes.len=l;let M=new o;return M.target=t.target,M._score=t._score,M._indexes=t._indexes,M},g=(e,t,n)=>{for(var r=new Set,i=0,a=F,o=0,s=e.spaceSearches,c=s.length,l=0,u=()=>{for(let e=l-1;e>=0;e--)t._nextBeginningIndexes[T[e*2+0]]=T[e*2+1]},d=!1,f=0;f<c;++f){D[f]=N;var p=s[f];if(a=h(p,t),n){if(a===F)continue;d=!0}else if(a===F)return u(),F;if(f!==c-1){var m=a._indexes,g=!0;for(let e=0;e<m.len-1;e++)if(m[e+1]-m[e]!==1){g=!1;break}if(g){var _=m[m.len-1]+1,v=t._nextBeginningIndexes[_-1];for(let e=_-1;e>=0&&v===t._nextBeginningIndexes[e];e--)t._nextBeginningIndexes[e]=_,T[l*2+0]=e,T[l*2+1]=v,l++}}i+=a._score/c,D[f]=a._score/c,a._indexes[0]<o&&(i-=(o-a._indexes[0])*2),o=a._indexes[0];for(var y=0;y<a._indexes.len;++y)r.add(a._indexes[y])}if(n&&!d)return F;u();var b=h(e,t,!0);if(b!==F&&b._score>i){if(n)for(var f=0;f<c;++f)D[f]=b._score/c;return b}n&&(a=t),a._score=i;var f=0;for(let e of r)a._indexes[f++]=e;return a._indexes.len=f,a},_=e=>e.replace(/\p{Script=Latin}+/gu,e=>e.normalize(`NFD`)).replace(/[\u0300-\u036f]/g,``),v=e=>{e=_(e);for(var t=e.length,n=e.toLowerCase(),r=[],i=0,a=!1,o=0;o<t;++o){var s=r[o]=n.charCodeAt(o);if(s===32){a=!0;continue}var c=s>=97&&s<=122?s-97:s>=48&&s<=57?26:s<=127?30:31;i|=1<<c}return{lowerCodes:r,bitflags:i,containsSpace:a,_lower:n}},y=e=>{for(var t=e.length,n=[],r=0,i=!1,a=!1,o=0;o<t;++o){var s=e.charCodeAt(o),c=s>=65&&s<=90,l=c||s>=97&&s<=122||s>=48&&s<=57,u=c&&!i||!a||!l;i=c,a=l,u&&(n[r++]=o)}return n},b=e=>{e=_(e);for(var t=e.length,n=y(e),r=[],i=n[0],a=0,o=0;o<t;++o)i>o?r[o]=i:(i=n[++a],r[o]=i===void 0?t:i);return r},x=new Map,S=new Map,C=[],w=[],T=[],E=[],D=[],O=[],k=[],A=(e,t)=>{var n=e[t];if(n!==void 0)return n;if(typeof t==`function`)return t(e);var r=t;Array.isArray(t)||(r=t.split(`.`));for(var i=r.length,a=-1;e&&++a<i;)e=e[r[a]];return e},j=e=>typeof e==`object`&&typeof e._bitflags==`number`,M=1/0,N=-M,P=[];P.total=0;var F=null,I=i(``),L=(e=>{var t=[],n=0,r={},i=e=>{for(var r=0,i=t[r],a=1;a<n;){var o=a+1;r=a,o<n&&t[o]._score<t[a]._score&&(r=o),t[r-1>>1]=t[r],a=1+(r<<1)}for(var s=r-1>>1;r>0&&i._score<t[s]._score;s=(r=s)-1>>1)t[r]=t[s];t[r]=i};return r.add=(e=>{var r=n;t[n++]=e;for(var i=r-1>>1;r>0&&e._score<t[i]._score;i=(r=i)-1>>1)t[r]=t[i];t[r]=e}),r.poll=(e=>{if(n!==0){var r=t[0];return t[0]=t[--n],i(),r}}),r.peek=(e=>{if(n!==0)return t[0]}),r.replaceTop=(e=>{t[0]=e,i()}),r})();return{single:t,go:n,prepare:i,cleanup:a}})}))(),1);function Iy(e){return e.kind===`anchor`?`${e.docName}#${e.slug}`:e.docName}function Ly(e){return e.kind===`anchor`?`Heading H${e.level}: ${e.text}`:e.kind===`create`?e.actionLabel:e.title}function Ry(e){let t=(0,rr.c)(41),{items:n,query:r,selectedIndex:i,onSelect:a,loading:o,error:s,mode:c,pageTarget:l,anchorQuery:u}=e,d=o===void 0?!1:o,f=s===void 0?null:s,p=c===void 0?`page`:c,m=l===void 0?``:l,h=u===void 0?``:u,g=(0,G.useRef)(null),_=(0,G.useId)(),v=i>=0&&i<n.length?`${_}-option-${i}`:void 0,y,b;t[0]===i?(y=t[1],b=t[2]):(y=()=>{let e=g.current;if(!e)return;let t=e.querySelectorAll(`[role="option"]`).item(i);t&&t.scrollIntoView({block:`nearest`})},b=[i],t[0]=i,t[1]=y,t[2]=b),(0,G.useEffect)(y,b);let x=zy;if(d){let e;t[3]===Symbol.for(`react.memo_cache_sentinel`)?(e={maxHeight:`var(--suggestion-menu-max-height, 40vh)`},t[3]=e):e=t[3];let n=p===`anchor`?`Loading headings for ${m}…`:`Loading pages…`,r;return t[4]===n?r=t[5]:(r=(0,q.jsx)(`div`,{ref:g,role:`status`,"aria-live":`polite`,className:`w-64 rounded-lg border bg-popover p-2 shadow-md text-sm text-muted-foreground`,style:e,onMouseDown:x,children:n}),t[4]=n,t[5]=r),r}if(n.length===0){let e;t[6]!==h||t[7]!==f||t[8]!==p||t[9]!==m||t[10]!==r?(e=f??(p===`anchor`?h.trim()?`No headings match "${h.trim()}"`:`No headings in ${m}`:r.trim()?`No pages found for "${r.trim()}"`:`No pages found`),t[6]=h,t[7]=f,t[8]=p,t[9]=m,t[10]=r,t[11]=e):e=t[11];let n=e,i;t[12]===Symbol.for(`react.memo_cache_sentinel`)?(i={maxHeight:`var(--suggestion-menu-max-height, 40vh)`},t[12]=i):i=t[12];let a;return t[13]===n?a=t[14]:(a=(0,q.jsx)(`div`,{ref:g,role:`status`,"aria-live":`polite`,className:`w-64 rounded-lg border bg-popover p-2 shadow-md text-sm text-muted-foreground`,style:i,onMouseDown:x,children:n}),t[13]=n,t[14]=a),a}let S=i>=0&&i<n.length?n[i]:null,C=p===`anchor`?`Heading suggestions`:`Wiki link suggestions`,w;t[15]===Symbol.for(`react.memo_cache_sentinel`)?(w={maxHeight:`var(--suggestion-menu-max-height, 40vh)`},t[15]=w):w=t[15];let T;t[16]===S?T=t[17]:(T=S?Ly(S):``,t[16]=S,t[17]=T);let E;t[18]===T?E=t[19]:(E=(0,q.jsx)(`span`,{className:`sr-only`,"aria-live":`polite`,"aria-atomic":`true`,children:T}),t[18]=T,t[19]=E);let D;t[20]===f?D=t[21]:(D=f&&(0,q.jsx)(`div`,{className:`rounded-md px-2 py-1.5 text-xs text-amber-700 dark:text-amber-300`,children:f}),t[20]=f,t[21]=D);let O;t[22]!==p||t[23]!==m?(O=p===`anchor`&&(0,q.jsx)(`div`,{className:`px-2 py-1 text-[10px] font-medium uppercase tracking-wide text-muted-foreground`,children:m}),t[22]=p,t[23]=m,t[24]=O):O=t[24];let k;if(t[25]!==n||t[26]!==_||t[27]!==a||t[28]!==i){let e;t[30]!==_||t[31]!==a||t[32]!==i?(e=(e,t)=>{let n=t===i,r=Iy(e);return e.kind===`anchor`?(0,q.jsxs)(`button`,{id:`${_}-option-${t}`,type:`button`,role:`option`,"aria-selected":n,"data-selected":n,className:`flex w-full items-center gap-2 rounded-md px-2 py-1.5 text-sm text-left ${n?`bg-accent text-accent-foreground`:``}`,style:{paddingLeft:`${(e.level-1)*10+8}px`},onMouseDown:t=>{t.preventDefault(),a(e)},children:[(0,q.jsxs)(`span`,{className:`w-6 shrink-0 font-mono text-[10px] text-muted-foreground`,children:[`H`,e.level]}),(0,q.jsx)(`span`,{className:`truncate font-medium`,children:e.text})]},r):(0,q.jsxs)(`button`,{id:`${_}-option-${t}`,type:`button`,role:`option`,"aria-selected":n,"data-selected":n,className:`flex w-full flex-col rounded-md px-2 py-1.5 text-sm text-left ${n?`bg-accent text-accent-foreground`:``}`,onMouseDown:t=>{t.preventDefault(),a(e)},children:[(0,q.jsx)(`span`,{className:`truncate font-medium`,children:e.kind===`create`?e.actionLabel:e.title}),e.kind===`page`&&e.title!==e.docName&&(0,q.jsx)(`span`,{className:`truncate text-xs text-muted-foreground`,children:e.docName}),e.kind===`create`&&(0,q.jsxs)(`span`,{className:`truncate text-xs text-muted-foreground`,children:[e.docName,`.md`]})]},r)},t[30]=_,t[31]=a,t[32]=i,t[33]=e):e=t[33],k=n.map(e),t[25]=n,t[26]=_,t[27]=a,t[28]=i,t[29]=k}else k=t[29];let A;return t[34]!==v||t[35]!==E||t[36]!==D||t[37]!==O||t[38]!==k||t[39]!==C?(A=(0,q.jsxs)(`div`,{ref:g,role:`listbox`,"aria-label":C,"aria-activedescendant":v,tabIndex:-1,onMouseDown:x,className:`w-64 overflow-y-auto subtle-scrollbar rounded-lg border bg-popover p-1 shadow-md`,style:w,children:[E,D,O,k]}),t[34]=v,t[35]=E,t[36]=D,t[37]=O,t[38]=k,t[39]=C,t[40]=A):A=t[40],A}function zy(e){return e.preventDefault()}function By(e,t){let n=document.createElement(`div`);n.style.position=`fixed`,n.style.zIndex=`50`,n.style.visibility=`hidden`,document.body.appendChild(n);let r={getBoundingClientRect:()=>e()?.clientRect?.()??new DOMRect,get contextElement(){return e()?.editor.view.dom}},i=!1,a=!1,o=()=>{n.isConnected&&(n.style.removeProperty(`--suggestion-menu-max-height`),B(r,n,{placement:`bottom-start`,middleware:[T(4),b(),C({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:()=>p(r,n,o),reveal:()=>{a||(i=!0,o())}}}function Vy(e){e.stopAutoUpdate?.(),e.stopAutoUpdate=null,e.popup?.remove(),e.popup=null}var Hy=new f(`wikiLinkSuggestion`),Uy=8;function Wy(e){let t=e.indexOf(`#`);return t>0?{mode:`anchor`,pageTarget:e.slice(0,t),anchorQuery:e.slice(t+1)}:{mode:`page`,pageTarget:``,anchorQuery:``}}function Gy(e,t){return t?Fy.default.go(t,e,{keys:[`title`,`docName`],threshold:-1e4}).map(e=>e.obj).slice(0,Uy):e.slice(0,Uy)}function Ky(e,t){return t?Fy.default.go(t,e,{key:`text`,threshold:-1e4}).map(e=>e.obj).slice(0,Uy):e.slice(0,Uy)}function qy(e,t){let n=Gy(e,t);if(n.length>0)return n.map(e=>({kind:`page`,...e}));let r=Rv(t);return r?[{kind:`create`,docName:r.target,title:t.trim(),actionLabel:`Insert unresolved link "${t.trim()}"`}]:[]}function Jy(e,t,n){return Ky(t,n).map(t=>({kind:`anchor`,docName:e,level:t.level,text:t.text,slug:t.slug}))}function Yy(e){let{mode:t,pageTarget:n,anchorQuery:r}=Wy(e);return t===`anchor`&&n?{target:n,alias:null,anchor:r.trim()||null}:Rv(e)}function Xy(e){let{$position:t}=e,n=t.parent.textBetween(0,t.parentOffset,void 0,``),r=n.match(/\[\[([^\]]*)$/);if(!r)return null;let i=r[1];return{range:{from:t.start()+n.lastIndexOf(`[[`),to:t.pos},query:i,text:r[0]}}async function Zy(){let e=await fetch(`/api/pages`);if(!e.ok)throw Error(`/api/pages responded with ${e.status}`);let t=await e.json();return Array.isArray(t.pages)?t.pages:[]}async function Qy(e){let t=await fetch(`/api/page-headings?docName=${encodeURIComponent(e)}`);if(!t.ok)throw Error(`/api/page-headings responded with ${t.status}`);let n=await t.json();return n.ok&&Array.isArray(n.headings)?n.headings:[]}function $y(e){let t=[],n=!1,r=!1,i=new Map,a=null,o=null,s=null;return Py({editor:e,pluginKey:Hy,char:`[[`,allowedPrefixes:null,findSuggestionMatch:Xy,items:async({query:e})=>{let{mode:c,pageTarget:l,anchorQuery:u}=Wy(e);if(c===`anchor`){if(!i.has(l)&&a!==l){a=l;try{let e=await Qy(l);i.set(l,e),s=null}catch(e){console.error(`[wiki-link-suggestion] Failed to fetch headings:`,e),i.set(l,[]),s=`Failed to load headings for ${l}. Press Escape and type [[ again to retry.`}finally{a=null}}return Jy(l,i.get(l)??[],u)}if(!n&&!r){r=!0;try{t=await Zy(),o=null}catch(e){console.error(`[wiki-link-suggestion] Failed to fetch pages:`,e),o=`Failed to load pages. Press Escape and type [[ again to retry, or continue typing to insert an unresolved link.`,t=[]}finally{n=!0,r=!1}}return qy(t,e)},command:({editor:e,range:t,props:n})=>{try{let r=null;if(n.kind===`page`?r={target:n.docName,alias:null,anchor:null}:n.kind===`anchor`?r={target:n.docName,alias:null,anchor:n.slug}:n.kind===`create`&&(r=Rv(n.title)),!r)return;e.chain().focus().deleteRange(t).insertContent({type:`wikiLink`,attrs:r}).run()}catch(e){console.error(`[wiki-link-suggestion] command failed`,{item:n,range:t},e)}},render:()=>{let e=null,c=null,l=0,u={popup:null,stopAutoUpdate:null},d=null,f=null,p=e=>{c?.command(e)};function m(e,t,r){let{mode:a,pageTarget:c,anchorQuery:u}=Wy(e.query??``),d=t===null?a===`anchor`?!i.has(c):!n:t;return{items:e.items,query:e.query??``,selectedIndex:l,onSelect:r,loading:d,error:a===`page`?o:s,mode:a,pageTarget:c,anchorQuery:u}}let h=t=>{!e||!c||e.updateProps(m(c,t,p))},g=()=>{if(!c)return;let{editor:e,range:t}=c,n=Yy(c.query??``);if(n)try{e.chain().focus().deleteRange(t).insertContent({type:`wikiLink`,attrs:n}).run()}catch(e){console.error(`[wiki-link-suggestion] fallback insert error:`,e)}};return{onBeforeStart(t){c=t,l=0;let n=By(()=>c,`wiki-link-suggestion`);u.popup=n.popup,d=n.doPosition,f=n.reveal,e=new Oi(Ry,{props:m(t,!0,p),editor:t.editor}),n.popup.appendChild(e.element),u.stopAutoUpdate=n.startAutoUpdate()},onBeforeUpdate(e){let t=c?Wy(c.query??``).mode:null,n=Wy(e.query??``).mode;c=e,t!==n&&(l=0,h(!0))},onStart(e){c=e,l=0,h(null),f?.()},onUpdate(e){c=e,l=Math.min(l,Math.max(0,e.items.length-1)),h(null),d?.()},onKeyDown({event:e}){if(!c)return!1;let t=c.items;if(e.key===`ArrowDown`)return t.length===0?!1:(l=(l+1)%t.length,h(null),!0);if(e.key===`ArrowUp`)return t.length===0?!1:(l=(l-1+t.length)%t.length,h(null),!0);if(e.key===`Enter`||e.key===`Tab`){let e=t[l];return e?c.command(e):g(),!0}return e.key,!1},onExit(){Vy(u),d=null,f=null,e?.destroy(),e=null,c=null,l=0,t=[],i=new Map,o=null,s=null,n=!1,r=!1,a=null}}}})}function eb(e,t){let n=(0,rr.c)(4),[r,i]=(0,G.useState)(null),a,o;return n[0]!==e||n[1]!==t?(a=()=>{if(!t||!e){i(null);return}let n=!1;return i(null),Qy(e).then(e=>{n||i(e)}).catch(()=>{n||i([])}),()=>{n=!0}},o=[e,t],n[0]=e,n[1]=t,n[2]=a,n[3]=o):(a=n[2],o=n[3]),(0,G.useEffect)(a,o),r}function tb(e,t){let n=e.trim();return n?n.startsWith(`#`)?`anchor`:n.startsWith(`/`)||Me(n)?`external`:`doc`:t}function nb(e){return e?.kind===`doc`?`doc`:e?.kind===`anchor`?`anchor`:`external`}function rb(e){let t=(0,rr.c)(64),{open:n,href:r,pages:i,onOpenChange:s,onSave:c}=e,[l,u]=(0,G.useState)(``),[d,f]=(0,G.useState)(``),[p,m]=(0,G.useState)(`doc`),h=(0,G.useId)(),g=(0,G.useId)(),_=(0,G.useId)(),v,y;t[0]!==r||t[1]!==n?(v=()=>{if(!n)return;let e=Gv(r);if(m(nb(e)),e?.kind===`doc`){u(e.docName),f(e.anchor??``);return}if(e?.kind===`anchor`){u(`#${e.anchor}`),f(``);return}u(e?.kind===`external`?e.url:r),f(``)},y=[r,n],t[0]=r,t[1]=n,t[2]=v,t[3]=y):(v=t[2],y=t[3]),(0,G.useEffect)(v,y);let b,x,S;t[4]!==p||t[5]!==l||t[6]!==i?(b=ie(l),x=p===`doc`,S=x&&Bv(b,i),t[4]=p,t[5]=l,t[6]=i,t[7]=b,t[8]=x,t[9]=S):(b=t[7],x=t[8],S=t[9]);let C=eb(b,S&&n),w=!!C?.length,T;t[10]!==b||t[11]!==x||t[12]!==d||t[13]!==l||t[14]!==s||t[15]!==c?(T=function(){let e=l.trim();e&&(c(x?$v(b,d.trim()||null):e),s(!1))},t[10]=b,t[11]=x,t[12]=d,t[13]=l,t[14]=s,t[15]=c,t[16]=T):T=t[16];let E=T,D;t[17]===E?D=t[18]:(D=function(e){e.key===`Enter`&&(e.preventDefault(),E())},t[17]=E,t[18]=D);let O=D,k;t[19]===Symbol.for(`react.memo_cache_sentinel`)?(k=(0,q.jsx)(Le,{className:`fixed inset-0 z-50 bg-black/40 data-open:animate-in data-open:fade-in-0 data-closed:animate-out data-closed:fade-out-0`}),t[19]=k):k=t[19];let A,j;t[20]===Symbol.for(`react.memo_cache_sentinel`)?(A=(0,q.jsx)(Ve,{className:`mb-1 text-base font-semibold`,children:`Edit markdown link`}),j=(0,q.jsx)(qe,{className:`mb-4 text-sm text-muted-foreground`,children:`Update the destination and optional section anchor.`}),t[20]=A,t[21]=j):(A=t[20],j=t[21]);let M=x?`Page`:`Link target`,N;t[22]!==M||t[23]!==h?(N=(0,q.jsx)(`label`,{className:`mb-1.5 block text-sm font-medium`,htmlFor:h,children:M}),t[22]=M,t[23]=h,t[24]=N):N=t[24];let P;t[25]===Symbol.for(`react.memo_cache_sentinel`)?(P=e=>{let t=e.target.value;u(t),m(e=>tb(t,e))},t[25]=P):P=t[25];let F;t[26]!==l||t[27]!==O||t[28]!==h?(F=(0,q.jsx)(ry,{id:h,value:l,onChange:P,placeholder:`guides/install or https://example.com`,autoFocus:!0,onKeyDown:O}),t[26]=l,t[27]=O,t[28]=h,t[29]=F):F=t[29];let I;t[30]===x?I=t[31]:(I=x?(0,q.jsx)(`p`,{className:`mt-1.5 text-xs text-muted-foreground`,children:`This changes the destination page. The visible link text stays editable inline in the document.`}):null,t[30]=x,t[31]=I);let L;t[32]!==N||t[33]!==F||t[34]!==I?(L=(0,q.jsxs)(`div`,{children:[N,F,I]}),t[32]=N,t[33]=F,t[34]=I,t[35]=L):L=t[35];let R;t[36]!==g||t[37]!==x||t[38]!==d||t[39]!==O||t[40]!==_||t[41]!==C||t[42]!==w?(R=x?(0,q.jsxs)(`div`,{children:[(0,q.jsxs)(`label`,{className:`mb-1.5 block text-sm font-medium`,htmlFor:g,children:[`Section`,` `,(0,q.jsx)(`span`,{className:`font-normal text-muted-foreground`,children:`(optional heading anchor)`})]}),(0,q.jsx)(ry,{id:g,value:d,onChange:e=>f(e.target.value),placeholder:`heading-slug`,"aria-controls":w?_:void 0,"aria-expanded":w?!0:void 0,"aria-haspopup":w?`listbox`:void 0,onKeyDown:O}),w?(0,q.jsx)(`div`,{role:`listbox`,id:_,"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:C.map(e=>(0,q.jsxs)(`button`,{type:`button`,role:`option`,"aria-selected":d===e.slug,className:a(`flex w-full items-center gap-2 px-2 py-1 text-left text-sm hover:bg-accent hover:text-accent-foreground`,d===e.slug&&`bg-accent text-accent-foreground`),style:{paddingLeft:`${(e.level-1)*12+8}px`},onClick:()=>f(d===e.slug?``:e.slug),children:[(0,q.jsxs)(`span`,{className:`w-7 shrink-0 font-mono text-[10px] text-muted-foreground`,children:[`H`,e.level]}),(0,q.jsx)(`span`,{className:`truncate`,children:e.text})]},`${e.slug}-${e.level}-${e.text}`))}):null]}):null,t[36]=g,t[37]=x,t[38]=d,t[39]=O,t[40]=_,t[41]=C,t[42]=w,t[43]=R):R=t[43];let z;t[44]!==L||t[45]!==R?(z=(0,q.jsxs)(`div`,{className:`mb-4 space-y-6`,children:[L,R]}),t[44]=L,t[45]=R,t[46]=z):z=t[46];let B;t[47]===s?B=t[48]:(B=(0,q.jsx)(o,{variant:`outline`,onClick:()=>s(!1),children:`Cancel`}),t[47]=s,t[48]=B);let V;t[49]===l?V=t[50]:(V=l.trim(),t[49]=l,t[50]=V);let H=!V,ee;t[51]!==E||t[52]!==H?(ee=(0,q.jsx)(o,{onClick:E,disabled:H,children:`Save`}),t[51]=E,t[52]=H,t[53]=ee):ee=t[53];let te;t[54]!==B||t[55]!==ee?(te=(0,q.jsxs)(`div`,{className:`flex justify-end gap-2`,children:[B,ee]}),t[54]=B,t[55]=ee,t[56]=te):te=t[56];let ne;t[57]!==z||t[58]!==te?(ne=(0,q.jsxs)(Re,{children:[k,(0,q.jsxs)(Be,{"data-slot":`dialog-content`,"data-ok-layer-spawned":``,className:`fixed left-1/2 top-1/2 z-50 w-full max-w-md -translate-x-1/2 -translate-y-1/2 rounded-lg border border-border bg-background p-6 shadow-xl data-open:animate-in data-open:fade-in-0 data-open:zoom-in-95 data-closed:animate-out data-closed:fade-out-0 data-closed:zoom-out-95`,children:[A,j,z,te]})]}),t[57]=z,t[58]=te,t[59]=ne):ne=t[59];let re;return t[60]!==s||t[61]!==n||t[62]!==ne?(re=(0,q.jsx)(Ue,{open:n,onOpenChange:s,children:ne}),t[60]=s,t[61]=n,t[62]=ne,t[63]=re):re=t[63],re}function ib(e){let t=(0,rr.c)(81),{editor:n,nodeId:r,sourceDocName:i,onClose:s}=e,c=Ey(n.state,r),l=c?.attrs?.href??``,[u,d]=(0,G.useState)(!1),[f,p]=(0,G.useState)(null),{folderPaths:m,pages:h,loading:g}=ve();if(!c||!l)return null;let _=te(l,i),v;t[0]!==n||t[1]!==r?(v=function(e){let t=Ey(n.state,r);t&&n.chain().setTextSelection({from:t.from,to:t.to}).extendMarkRange(`link`).updateAttributes(`link`,{href:e}).run()},t[0]=n,t[1]=r,t[2]=v):v=t[2];let y=v,b;t[3]!==n||t[4]!==r||t[5]!==s?(b=function(){let e=Ey(n.state,r);e&&(n.chain().focus().setTextSelection({from:e.from,to:e.to}).extendMarkRange(`link`).unsetLink().run(),s())},t[3]=n,t[4]=r,t[5]=s,t[6]=b):b=t[6];let x=b,S=function(e){if(_){if(_.kind===`external`){Qv(_);return}if(_.kind===`anchor`||_.kind===`doc`){let t=_.kind===`doc`?_.docName:i,n=_.anchor??null;e.newTab?Yv({docName:t,anchor:n}):window.location.assign(Kv({docName:t,anchor:n}))}}},C=function(e){if(f!==`missing`)return;let t=Ey(n.state,r);t&&n.chain().setTextSelection({from:t.from,to:t.to}).extendMarkRange(`link`).updateAttributes(`link`,{href:$v(e,_?.kind===`doc`?_.anchor??null:null)}).run()},w,T=!1,E=!1,D=null;if(g){let e;t[7]===Symbol.for(`react.memo_cache_sentinel`)?(e=(0,q.jsx)(Gn,{className:`size-3.5 shrink-0 animate-spin`,"aria-hidden":`true`}),t[7]=e):e=t[7],w={icon:e,text:`Loading…`,className:`text-muted-foreground`}}else if(_?.kind===`external`){let e;t[8]===Symbol.for(`react.memo_cache_sentinel`)?(e=(0,q.jsx)(Pn,{className:`size-3.5 shrink-0`,"aria-hidden":`true`}),t[8]=e):e=t[8],w={icon:e,text:`External link`,className:`text-foreground`}}else if(_?.kind===`anchor`){let e;t[9]===Symbol.for(`react.memo_cache_sentinel`)?(e=(0,q.jsx)(In,{className:`size-3.5 shrink-0`,"aria-hidden":`true`}),t[9]=e):e=t[9],w={icon:e,text:`Anchor in this page`,className:`text-foreground`}}else if(_?.kind===`doc`){let e=ty(_.docName,{pages:h,folderPaths:m});if(D=ny(e),E=e.kind===`navigate`&&e.displayState===`folder`,T=e.kind===`create`,E){let e;t[10]===Symbol.for(`react.memo_cache_sentinel`)?(e=(0,q.jsx)(Ln,{className:`size-3.5 shrink-0`,"aria-hidden":`true`}),t[10]=e):e=t[10],w={icon:e,text:`Folder (no index)`,className:`text-foreground`}}else if(T){let e;t[11]===Symbol.for(`react.memo_cache_sentinel`)?(e=(0,q.jsx)(Mn,{className:`size-3.5 shrink-0`,"aria-hidden":`true`}),t[11]=e):e=t[11],w={icon:e,text:`Page not found`,className:`text-red-700 dark:text-red-300`}}else{let e;t[12]===Symbol.for(`react.memo_cache_sentinel`)?(e=(0,q.jsx)(In,{className:`size-3.5 shrink-0`,"aria-hidden":`true`}),t[12]=e):e=t[12],w={icon:e,text:`Page link`,className:`text-foreground`}}}else{let e;t[13]===Symbol.for(`react.memo_cache_sentinel`)?(e=(0,q.jsx)(Mn,{className:`size-3.5 shrink-0`,"aria-hidden":`true`}),t[13]=e):e=t[13],w={icon:e,text:`Unrecognized link`,className:`text-muted-foreground`}}let O=a(`text-sm font-medium`,w.className),k;t[14]!==w.text||t[15]!==O?(k=(0,q.jsx)(`div`,{className:O,children:w.text}),t[14]=w.text,t[15]=O,t[16]=k):k=t[16];let A;t[17]===l?A=t[18]:(A=(0,q.jsx)(`div`,{className:`truncate text-xs text-muted-foreground`,title:l,children:l}),t[17]=l,t[18]=A);let j;t[19]!==k||t[20]!==A?(j=(0,q.jsxs)(`div`,{className:`flex-1 min-w-0`,children:[k,A]}),t[19]=k,t[20]=A,t[21]=j):j=t[21];let M;t[22]!==S||t[23]!==T||t[24]!==s||t[25]!==_?.kind?(M=T?null:(0,q.jsx)(o,{size:`sm`,variant:`default`,onClick:()=>{S({}),s()},children:_?.kind===`external`?`Open in new tab`:`Open`}),t[22]=S,t[23]=T,t[24]=s,t[25]=_?.kind,t[26]=M):M=t[26];let N;t[27]!==T||t[28]!==p?(N=T?(0,q.jsx)(o,{size:`sm`,variant:`default`,onClick:()=>p(`missing`),children:`Create page`}):null,t[27]=T,t[28]=p,t[29]=N):N=t[29];let P;t[30]!==D||t[31]!==E||t[32]!==p?(P=E&&D?(0,q.jsxs)(o,{size:`sm`,variant:`outline`,onClick:()=>p(`folder-index`),children:[(0,q.jsx)(Fn,{className:`size-3.5`,"aria-hidden":`true`}),`Create index`]}):null,t[30]=D,t[31]=E,t[32]=p,t[33]=P):P=t[33];let F;t[34]===d?F=t[35]:(F=()=>d(!0),t[34]=d,t[35]=F);let I;t[36]===Symbol.for(`react.memo_cache_sentinel`)?(I=(0,q.jsx)(qn,{className:`size-3.5`,"aria-hidden":`true`}),t[36]=I):I=t[36];let L;t[37]===F?L=t[38]:(L=(0,q.jsxs)(o,{size:`sm`,variant:`outline`,onClick:F,children:[I,`Edit`]}),t[37]=F,t[38]=L);let R;t[39]===Symbol.for(`react.memo_cache_sentinel`)?(R=(0,q.jsx)(Xn,{className:`size-3.5`,"aria-hidden":`true`}),t[39]=R):R=t[39];let z;t[40]===x?z=t[41]:(z=(0,q.jsxs)(o,{size:`sm`,variant:`outline`,className:`text-red-700 hover:bg-red-50 hover:text-red-800 dark:text-red-300 dark:hover:bg-red-100/10 dark:hover:text-red-200`,onClick:x,children:[R,`Remove`]}),t[40]=x,t[41]=z);let B;t[42]!==P||t[43]!==L||t[44]!==z||t[45]!==M||t[46]!==N?(B=(0,q.jsxs)(`div`,{className:`flex flex-wrap gap-1.5`,children:[M,N,P,L,z]}),t[42]=P,t[43]=L,t[44]=z,t[45]=M,t[46]=N,t[47]=B):B=t[47];let V=f!==null,H;t[48]===p?H=t[49]:(H=e=>{e||p(null)},t[48]=p,t[49]=H);let ee;t[50]!==f||t[51]!==D||t[52]!==m||t[53]!==T||t[54]!==h||t[55]!==_?(ee=f===`folder-index`&&D?D.initialDir:T&&_?.kind===`doc`&&ty(_.docName,{pages:h,folderPaths:m}).kind===`create`?ty(_.docName,{pages:h,folderPaths:m}).initialDir:``,t[50]=f,t[51]=D,t[52]=m,t[53]=T,t[54]=h,t[55]=_,t[56]=ee):ee=t[56];let ne;t[57]!==f||t[58]!==D||t[59]!==m||t[60]!==T||t[61]!==h||t[62]!==_?(ne=f===`folder-index`&&D?D.suggestedName:T&&_?.kind===`doc`&&ty(_.docName,{pages:h,folderPaths:m}).kind===`create`?ty(_.docName,{pages:h,folderPaths:m}).suggestedName:void 0,t[57]=f,t[58]=D,t[59]=m,t[60]=T,t[61]=h,t[62]=_,t[63]=ne):ne=t[63];let re;t[64]!==f||t[65]!==D||t[66]!==_?(re=f===`folder-index`&&D?(0,q.jsxs)(q.Fragment,{children:[`Create an index note for`,` `,(0,q.jsxs)(`span`,{className:`font-medium text-foreground`,children:[D.initialDir,`/`]})]}):(0,q.jsxs)(q.Fragment,{children:[`Create a page for`,` `,(0,q.jsx)(`span`,{className:`font-medium text-foreground`,children:_?.kind===`doc`?_.docName:``})]}),t[64]=f,t[65]=D,t[66]=_,t[67]=re):re=t[67];let ie;t[68]!==C||t[69]!==V||t[70]!==H||t[71]!==ee||t[72]!==ne||t[73]!==re?(ie=(0,q.jsx)(ly,{open:V,onOpenChange:H,kind:`file`,initialDir:ee,suggestedName:ne,description:re,onCreated:C}),t[68]=C,t[69]=V,t[70]=H,t[71]=ee,t[72]=ne,t[73]=re,t[74]=ie):ie=t[74];let ae;return t[75]!==u||t[76]!==y||t[77]!==l||t[78]!==h||t[79]!==d?(ae=(0,q.jsx)(rb,{open:u,href:l,pages:h,onOpenChange:d,onSave:y}),t[75]=u,t[76]=y,t[77]=l,t[78]=h,t[79]=d,t[80]=ae):ae=t[80],(0,q.jsxs)(q.Fragment,{children:[(0,q.jsxs)(ey,{kind:`internal-link`,ariaLabel:`Link options`,onDeactivate:s,children:[(0,q.jsxs)(`div`,{className:`mb-2 flex items-start gap-2 pr-8`,children:[(0,q.jsx)(`div`,{className:a(`mt-0.5 flex shrink-0`,w.className),children:w.icon}),j]}),B]}),ie,ae]})}function ab(e,t,n){let r=te(e,t);if(!r)return`unresolved`;if(r.kind===`external`)return`external`;if(r.kind===`anchor`)return`anchor`;if(n===null)return`loading`;let i=ty(r.docName,{pages:n.pages,folderPaths:n.folderPaths});return i.kind===`create`?`unresolved`:i.displayState}function ob(e,t,n){let r=e.attrs?.href;return typeof r!=`string`||r.length===0?null:{"data-resolution-state":ab(r,n,t)}}function sb(e){return(t,n)=>ob(t,n,e)}var cb=new f(`linkResolutionDecoration`);function lb(e,t,n,r,i){if(t.size===0)return null;let a=[];for(let e of t.values()){if(!n.has(e.markType))continue;let t=r(e,i);t!==null&&a.push(R.inline(e.from,e.to,t))}return a.length===0?null:g.create(e,a)}function ub(e){let t=new Set(e.markTypes),{computeAttrs:n}=e;return new _e({key:cb,state:{init:()=>({version:0}),apply(e,t){let n=e.getMeta(cb);return n&&typeof n==`object`&&n.refresh?{version:t.version+1}:t}},props:{decorations(e){let r=by.getState(e);if(!r)return null;let i=se();return lb(e.doc,r.byId,t,n,i)}},view(e){let t=Se(()=>{e.dispatch(e.state.tr.setMeta(cb,{refresh:!0}))});return{destroy(){t()}}}})}var db=new f(`markIdentityDecoration`),fb=`data-mark-id`;function pb(){return new _e({key:db,props:{decorations(e){let t=by.getState(e);if(!t||t.byId.size===0)return null;let n=[];for(let e of t.byId.values())n.push(R.inline(e.from,e.to,{[fb]:e.id}));return g.create(e.doc,n)}}})}var mb=z.extend({addOptions(){return{...this.parent?.(),docName:``}},renderHTML({HTMLAttributes:e}){let t=typeof e.href==`string`?e.href:``;return[`span`,L(e,{"data-link":``,role:`link`,tabindex:`0`,"aria-label":t?`Link: ${t}`:`Link`,style:`touch-action: manipulation;`}),0]},addProseMirrorPlugins(){let e=this.options.docName??``;return[ky({editor:this.editor,markTypes:[`link`],renderPropPanel:({editor:t,nodeId:n,deactivate:r})=>(0,G.createElement)(ib,{editor:t,nodeId:n,sourceDocName:e,onClose:r}),handlePrimary:({editor:t,nodeId:n,newTab:r})=>{if(!r)return!1;let i=Ey(t.state,n)?.attrs?.href;if(typeof i!=`string`||!i)return!1;let a=te(i,e);return a?a.kind===`doc`?(Yv({docName:a.docName,anchor:a.anchor}),!0):a.kind===`anchor`?(Yv({docName:e,anchor:a.anchor}),!0):Uv(a.url)?(qv(a.url),!0):!1:!1}}),pb(),ub({markTypes:[`link`],computeAttrs:sb(e)})]}}),hb={warning:`bg-amber-100 text-amber-900 dark:bg-amber-900/40 dark:text-amber-200`,info:`bg-sky-100 text-sky-900 dark:bg-sky-900/40 dark:text-sky-200`,error:`bg-red-100 text-red-900 dark:bg-red-900/40 dark:text-red-200`},gb={warning:`alert`,error:`alert`,info:`note`};function _b(e){let t=(0,rr.c)(11),{type:n,children:r}=e,i=gb[n]||`note`,o=hb[n]||`bg-muted text-foreground`,s;t[0]===o?s=t[1]:(s=a(`p-3 px-4 rounded-md`,o),t[0]=o,t[1]=s);let c;t[2]===n?c=t[3]:(c=n.toUpperCase(),t[2]=n,t[3]=c);let l;t[4]===c?l=t[5]:(l=(0,q.jsx)(`strong`,{children:c}),t[4]=c,t[5]=l);let u;return t[6]!==r||t[7]!==i||t[8]!==s||t[9]!==l?(u=(0,q.jsxs)(`div`,{role:i,className:s,children:[l,`: `,r]}),t[6]=r,t[7]=i,t[8]=s,t[9]=l,t[10]=u):u=t[10],u}function vb(e){let t=e.match(/<(\w+)/);return t?t[1]:`Unknown`}function yb(e){let t=(0,rr.c)(19),{editor:n,getPos:r,onDismiss:i}=e,a;if(t[0]!==n||t[1]!==r){let e=r();a=vb((typeof e==`number`?n.state.doc.nodeAt(e):null)?.attrs.content??``),t[0]=n,t[1]=r,t[2]=a}else a=t[2];let s=a,c;t[3]!==n||t[4]!==r||t[5]!==i?(c=function(){let e=r();if(typeof e!=`number`)return;let t=n.state.doc.nodeAt(e);t&&(n.chain().focus().deleteRange({from:e,to:e+t.nodeSize}).run(),i())},t[3]=n,t[4]=r,t[5]=i,t[6]=c):c=t[6];let l=c,u;t[7]===Symbol.for(`react.memo_cache_sentinel`)?(u=(0,q.jsx)(`span`,{className:`text-xs text-muted-foreground`,children:`Component`}),t[7]=u):u=t[7];let d;t[8]===s?d=t[9]:(d=(0,q.jsx)(`code`,{className:`rounded bg-muted px-1.5 py-0.5 text-xs font-mono`,children:s}),t[8]=s,t[9]=d);let f;t[10]===Symbol.for(`react.memo_cache_sentinel`)?(f=(0,q.jsx)(`div`,{className:`flex-1`}),t[10]=f):f=t[10];let p;t[11]===l?p=t[12]:(p=(0,q.jsx)(o,{variant:`outline`,size:`sm`,onClick:l,children:`Delete`}),t[11]=l,t[12]=p);let m;t[13]!==d||t[14]!==p?(m=(0,q.jsxs)(`div`,{className:`flex items-center gap-2 pr-8`,children:[u,d,f,p]}),t[13]=d,t[14]=p,t[15]=m):m=t[15];let h;return t[16]!==i||t[17]!==m?(h=(0,q.jsx)(ey,{kind:`jsx-component`,ariaLabel:`Component properties`,onDeactivate:i,children:m}),t[16]=i,t[17]=m,t[18]=h):h=t[18],h}var bb=0;function xb(){return`jsx-${++bb}`}function Sb(e){let t=e.match(/<(\w+)\s+type="([^"]*)">([\s\S]*?)<\/\1>/);return t?{component:t[1],type:t[2],children:t[3].trim()}:{component:`Unknown`,type:`info`,children:e.trim()}}function Cb(e){let t=(0,rr.c)(17),{node:n,editor:r,getPos:i}=e,a=n.attrs.content||``,o;t[0]===a?o=t[1]:(o=Sb(a),t[0]=a,t[1]=o);let s=o,[c]=(0,G.useState)(xb),l=(0,G.useRef)(i),u,d;t[2]===i?(u=t[3],d=t[4]):(u=()=>{l.current=i},d=[i],t[2]=i,t[3]=u,t[4]=d),(0,G.useEffect)(u,d);let f,p;t[5]!==r||t[6]!==c?(f=()=>{let e=yy(r),t=()=>{let e=l.current();return typeof e==`number`?e:void 0};return e.register({type:`jsxComponent`,nodeId:c,getPos:t,controls:{propPanel:e=>(0,q.jsx)(yb,{editor:r,getPos:t,onDismiss:e.deactivate})}}),()=>{e.deregister(c)}},p=[r,c],t[5]=r,t[6]=c,t[7]=f,t[8]=p):(f=t[7],p=t[8]),(0,G.useEffect)(f,p);let m;t[9]!==a||t[10]!==s.children||t[11]!==s.component||t[12]!==s.type?(m=s.component===`Callout`?(0,q.jsx)(_b,{type:s.type,children:s.children}):(0,q.jsxs)(`div`,{className:`bg-muted dark:bg-muted/40 p-3 px-4 rounded-md font-mono text-[13px]`,children:[(0,q.jsxs)(`strong`,{children:[`<`,s.component,`>`]}),(0,q.jsx)(`pre`,{className:`mt-2 whitespace-pre-wrap`,children:a})]}),t[9]=a,t[10]=s.children,t[11]=s.component,t[12]=s.type,t[13]=m):m=t[13];let h;return t[14]!==c||t[15]!==m?(h=(0,q.jsx)(Si,{className:`jsx-component-wrapper`,contentEditable:!1,"data-node-id":c,children:m}),t[14]=c,t[15]=m,t[16]=h):h=t[16],h}var wb=V.extend({addNodeView(){return Ai(Cb)}}),Tb=`raw-mdx-nav`,Eb=0;function Db(){return`raw-mdx-${++Eb}`}function Ob(e){let t=e.doc??(typeof document<`u`?document:{createElement:null}),n=t.createElement(`div`);n.setAttribute(`data-raw-mdx-fallback`,``),n.setAttribute(`data-raw-badge`,`raw`),n.setAttribute(`data-node-id`,e.nodeId),n.setAttribute(`contenteditable`,`false`),n.setAttribute(`role`,`button`),n.setAttribute(`tabindex`,`0`),n.setAttribute(`aria-label`,`${e.reason??`Parse failed`} — click to edit`),n.classList.add(`raw-mdx-fallback-wrapper`),e.reason&&n.setAttribute(`data-reason`,e.reason);let r=t.createElement(`span`);r.classList.add(`raw-mdx-fallback-badge`),r.textContent=`raw`,r.setAttribute(`aria-hidden`,`true`),n.appendChild(r);let i=t.createElement(`pre`);return i.classList.add(`raw-mdx-fallback-content`),i.setAttribute(`contenteditable`,`false`),n.appendChild(i),{dom:n,contentDOM:i}}var kb=y.extend({addNodeView(){return({editor:e,node:t,getPos:n,HTMLAttributes:r})=>{let i=Db(),{dom:a,contentDOM:o}=Ob({nodeId:i,reason:r.reason??t.attrs.reason}),s=()=>{let e=n();return typeof e==`number`?e:void 0},c=yy(e);return c.register({type:`rawMdxFallback`,nodeId:i,getPos:s,controls:{},handlePrimary:()=>{let t=s();if(typeof t!=`number`)return!1;let n=e.state.doc.nodeAt(t)?.attrs.originalSpan??{start:0,end:0};return window.dispatchEvent(new CustomEvent(Tb,{detail:{offset:n.start}})),!0}}),{dom:a,contentDOM:o,ignoreMutation:()=>!0,destroy:()=>{c.deregister(i)}}}}}),Ab=[{name:`heading1`,label:`Heading 1`,icon:Rn,category:`basic`,command:e=>e.chain().focus().toggleHeading({level:1}).run(),aliases:[`h1`]},{name:`heading2`,label:`Heading 2`,icon:zn,category:`basic`,command:e=>e.chain().focus().toggleHeading({level:2}).run(),aliases:[`h2`]},{name:`heading3`,label:`Heading 3`,icon:Bn,category:`basic`,command:e=>e.chain().focus().toggleHeading({level:3}).run(),aliases:[`h3`]},{name:`bulletList`,label:`Bullet List`,icon:Wn,category:`basic`,command:e=>e.chain().focus().toggleBulletList().run(),aliases:[`ul`,`unordered`]},{name:`orderedList`,label:`Ordered List`,icon:Hn,category:`basic`,command:e=>e.chain().focus().toggleOrderedList().run(),aliases:[`ol`,`numbered`]},{name:`taskList`,label:`Task List`,icon:Un,category:`basic`,command:e=>e.chain().focus().toggleTaskList().run(),aliases:[`todo`,`checklist`,`checkbox`]},{name:`blockquote`,label:`Quote`,icon:Jn,category:`basic`,command:e=>e.chain().focus().toggleBlockquote().run(),aliases:[`quote`]},{name:`codeBlock`,label:`Code Block`,icon:Nn,category:`basic`,command:e=>e.chain().focus().toggleCodeBlock().run(),aliases:[`code`,`fence`]},{name:`table`,label:`Table`,icon:Yn,category:`insert`,command:e=>e.chain().focus().insertTable({rows:3,cols:3,withHeaderRow:!0}).run(),aliases:[`grid`]},{name:`separator`,label:`Separator`,icon:Kn,category:`insert`,command:e=>e.chain().focus().setHorizontalRule().run(),aliases:[`hr`,`divider`,`rule`]},{name:`image`,label:`Image`,icon:Vn,category:`insert`,aliases:[`img`,`photo`],command:e=>{let t=document.createElement(`input`);t.type=`file`,t.accept=w.join(`,`),t.onchange=()=>{let n=t.files?.[0];if(n){let t=e.state.selection.from;z_(n,e,t)}},t.click()}}];function jb(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 Mb(e){let t=(0,rr.c)(14),{items:n,selectedIndex:r,categoryLabels:i,onSelect:a}=e,o=(0,G.useRef)(null),s=(0,G.useId)(),c=r>=0&&r<n.length?`${s}-option-${r}`:void 0,l=Nb,u,d;if(t[0]===r?(u=t[1],d=t[2]):(u=()=>{let e=o.current;if(!e)return;let t=e.querySelectorAll(`[role="option"]`).item(r);t&&t.scrollIntoView({block:`nearest`})},d=[r],t[0]=r,t[1]=u,t[2]=d),(0,G.useEffect)(u,d),n.length===0){let e;return t[3]===Symbol.for(`react.memo_cache_sentinel`)?(e=(0,q.jsx)(`div`,{ref:o,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:l,children:`No results`}),t[3]=e):e=t[3],e}let f;if(t[4]!==c||t[5]!==i||t[6]!==n||t[7]!==s||t[8]!==a||t[9]!==r){let e=[],u=0,d=new Map;for(let t of n){d.set(t,u++);let n=e.find(e=>e.key===t.category);n?n.items.push(t):e.push({key:t.category,items:[t]})}let p=r>=0&&r<n.length?n[r]:null,m;t[11]===Symbol.for(`react.memo_cache_sentinel`)?(m={maxHeight:`var(--suggestion-menu-max-height, 40vh)`},t[11]=m):m=t[11];let h=p?p.label:``,g;t[12]===h?g=t[13]:(g=(0,q.jsx)(`span`,{className:`sr-only`,"aria-live":`polite`,"aria-atomic":`true`,children:h}),t[12]=h,t[13]=g),f=(0,q.jsxs)(`div`,{ref:o,role:`listbox`,"aria-label":`Slash commands`,"aria-activedescendant":c,tabIndex:-1,onMouseDown:l,className:`w-56 overflow-y-auto subtle-scrollbar rounded-lg border bg-popover p-1 shadow-md`,style:m,children:[g,e.map(e=>(0,q.jsxs)(`div`,{role:`group`,"aria-labelledby":`${s}-group-${e.key}`,children:[(0,q.jsx)(`div`,{id:`${s}-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=d.get(e)??0,n=t===r,i=e.icon;return(0,q.jsxs)(`button`,{id:`${s}-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`:``}`,onMouseDown:t=>{t.preventDefault(),a(e)},children:[(0,q.jsx)(i,{className:`size-4 shrink-0 text-muted-foreground`}),(0,q.jsx)(`div`,{className:`flex flex-col min-w-0`,children:(0,q.jsx)(`span`,{className:`truncate`,children:e.label})})]},e.name)})]},e.key))]}),t[4]=c,t[5]=i,t[6]=n,t[7]=s,t[8]=a,t[9]=r,t[10]=f}else f=t[10];return f}function Nb(e){return e.preventDefault()}var Pb=new f(`slashCommand`),Fb=ke.create({name:`slashCommand`,addOptions(){return{itemsSources:[()=>Ab],categoryLabels:{basic:`Basic blocks`,insert:`Insert`}}},addProseMirrorPlugins(){let e=this;return[Py({editor:this.editor,pluginKey:Pb,char:`/`,startOfLine:!1,items:({query:t})=>jb(e.options.itemsSources.flatMap(e=>{try{return e()}catch(e){return console.error(`[slash-command] item source threw an error`,e),[]}}),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=()=>{!t||!n||t.updateProps({items:n.items,selectedIndex:r,categoryLabels:e.options.categoryLabels,onSelect:n.command})};return{onStart(o){n=o,r=0;let s=By(()=>n,`slash-command`);i.popup=s.popup,a=s.doPosition,t=new Oi(Mb,{props:{items:o.items,selectedIndex:r,categoryLabels:e.options.categoryLabels,onSelect:o.command},editor:o.editor}),s.popup.appendChild(t.element),i.stopAutoUpdate=s.startAutoUpdate(),s.reveal()},onUpdate(e){n=e,r=Math.min(r,Math.max(0,e.items.length-1)),o(),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,o(),!0;if(e.key===`ArrowUp`)return r=(r-1+t.length)%t.length,o(),!0;if(e.key===`Enter`||e.key===`Tab`){let e=t[r];return e&&n.command(e),!0}return e.key,!1},onExit(){Vy(i),a=null,t?.destroy(),t=null,n=null,r=0}}}})]}});function Ib(e){let t=(0,rr.c)(112),{open:n,target:r,alias:i,anchor:s,pages:c,onOpenChange:l,onSave:u}=e,[d,f]=(0,G.useState)(r),[p,m]=(0,G.useState)(i??``),[h,g]=(0,G.useState)(s??``),_=(0,G.useId)(),v=(0,G.useId)(),y=(0,G.useId)(),b=(0,G.useId)(),x;t[0]!==d||t[1]!==c?(x=Bv(d,c),t[0]=d,t[1]=c,t[2]=x):x=t[2];let S=eb(d,x&&n),C,w;t[3]!==i||t[4]!==s||t[5]!==n||t[6]!==r?(C=()=>{n&&(f(r),m(i??``),g(s??``))},w=[n,r,i,s],t[3]=i,t[4]=s,t[5]=n,t[6]=r,t[7]=C,t[8]=w):(C=t[7],w=t[8]),(0,G.useEffect)(C,w);let T;t[9]!==p||t[10]!==h||t[11]!==d||t[12]!==l||t[13]!==u?(T=function(){let e=d.trim();e&&(u(e,p.trim()||null,h.trim()||null),l(!1))},t[9]=p,t[10]=h,t[11]=d,t[12]=l,t[13]=u,t[14]=T):T=t[14];let E=T,D;t[15]===E?D=t[16]:(D=function(e){e.key===`Enter`&&E()},t[15]=E,t[16]=D);let O=D,k,A,j,M,N,P,F,I,L,R,z,B,V,H,ee,te;if(t[17]!==v||t[18]!==h||t[19]!==d||t[20]!==O||t[21]!==b||t[22]!==S||t[23]!==l||t[24]!==n||t[25]!==_){let e=new Map,r=S?.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;j=Ue,z=n,B=l,A=Re,t[42]===Symbol.for(`react.memo_cache_sentinel`)?(R=(0,q.jsx)(Le,{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[42]=R):R=t[42],k=Be,N=`dialog-content`,P=``,F=`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[43]===Symbol.for(`react.memo_cache_sentinel`)?(I=(0,q.jsx)(Ve,{className:`mb-1 text-base font-semibold`,children:`Edit wiki link`}),L=(0,q.jsx)(qe,{className:`mb-4 text-sm text-muted-foreground`,children:`Modify the link target, anchor, and display label.`}),t[43]=I,t[44]=L):(I=t[43],L=t[44]),te=`mb-4 space-y-6`;let o;t[45]===Symbol.for(`react.memo_cache_sentinel`)?(o=(0,q.jsx)(`span`,{className:`text-red-500`,children:`*`}),t[45]=o):o=t[45];let s;t[46]===_?s=t[47]:(s=(0,q.jsxs)(`label`,{className:`mb-1.5 block text-sm font-medium`,htmlFor:_,children:[`Page `,o]}),t[46]=_,t[47]=s);let c;t[48]===Symbol.for(`react.memo_cache_sentinel`)?(c=e=>f(e.target.value),t[48]=c):c=t[48];let u;t[49]!==d||t[50]!==O||t[51]!==_?(u=(0,q.jsx)(ry,{id:_,value:d,onChange:c,placeholder:`page-name`,autoFocus:!0,"aria-required":`true`,onKeyDown:O}),t[49]=d,t[50]=O,t[51]=_,t[52]=u):u=t[52],t[53]!==s||t[54]!==u?(M=(0,q.jsxs)(`div`,{children:[s,u]}),t[53]=s,t[54]=u,t[55]=M):M=t[55];let p;t[56]===Symbol.for(`react.memo_cache_sentinel`)?(p=(0,q.jsx)(`span`,{className:`font-normal text-muted-foreground`,children:`(optional heading anchor)`}),t[56]=p):p=t[56],t[57]===v?V=t[58]:(V=(0,q.jsxs)(`label`,{className:`mb-1.5 block text-sm font-medium`,htmlFor:v,children:[`Section`,` `,p]}),t[57]=v,t[58]=V);let m;t[59]===Symbol.for(`react.memo_cache_sentinel`)?(m=e=>g(e.target.value),t[59]=m):m=t[59],t[60]!==v||t[61]!==h||t[62]!==O?(H=(0,q.jsx)(ry,{id:v,value:h,onChange:m,placeholder:`heading-slug`,onKeyDown:O}),t[60]=v,t[61]=h,t[62]=O,t[63]=H):H=t[63],ee=i&&(0,q.jsx)(`div`,{role:`listbox`,id:b,"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,q.jsxs)(`button`,{type:`button`,role:`option`,"aria-selected":h===e.slug,className:a(`flex w-full items-center gap-2 px-2 py-1 text-left text-sm hover:bg-accent hover:text-accent-foreground`,h===e.slug&&`bg-accent text-accent-foreground`),style:{paddingLeft:`${(e.level-1)*12+8}px`},onClick:()=>g(h===e.slug?``:e.slug),children:[(0,q.jsxs)(`span`,{className:`w-7 shrink-0 font-mono text-[10px] text-muted-foreground`,children:[`H`,e.level]}),(0,q.jsx)(`span`,{className:`truncate`,children:e.text})]},e.reactKey))}),t[17]=v,t[18]=h,t[19]=d,t[20]=O,t[21]=b,t[22]=S,t[23]=l,t[24]=n,t[25]=_,t[26]=k,t[27]=A,t[28]=j,t[29]=M,t[30]=N,t[31]=P,t[32]=F,t[33]=I,t[34]=L,t[35]=R,t[36]=z,t[37]=B,t[38]=V,t[39]=H,t[40]=ee,t[41]=te}else k=t[26],A=t[27],j=t[28],M=t[29],N=t[30],P=t[31],F=t[32],I=t[33],L=t[34],R=t[35],z=t[36],B=t[37],V=t[38],H=t[39],ee=t[40],te=t[41];let ne;t[64]!==V||t[65]!==H||t[66]!==ee?(ne=(0,q.jsxs)(`div`,{children:[V,H,ee]}),t[64]=V,t[65]=H,t[66]=ee,t[67]=ne):ne=t[67];let re;t[68]===Symbol.for(`react.memo_cache_sentinel`)?(re=(0,q.jsx)(`span`,{className:`font-normal text-muted-foreground`,children:`(optional display text)`}),t[68]=re):re=t[68];let ie;t[69]===y?ie=t[70]:(ie=(0,q.jsxs)(`label`,{className:`mb-1.5 block text-sm font-medium`,htmlFor:y,children:[`Label`,` `,re]}),t[69]=y,t[70]=ie);let ae;t[71]===Symbol.for(`react.memo_cache_sentinel`)?(ae=e=>m(e.target.value),t[71]=ae):ae=t[71];let oe;t[72]!==y||t[73]!==p||t[74]!==O?(oe=(0,q.jsx)(ry,{id:y,value:p,onChange:ae,placeholder:`Custom display text`,onKeyDown:O}),t[72]=y,t[73]=p,t[74]=O,t[75]=oe):oe=t[75];let se;t[76]!==ie||t[77]!==oe?(se=(0,q.jsxs)(`div`,{children:[ie,oe]}),t[76]=ie,t[77]=oe,t[78]=se):se=t[78];let ce;t[79]!==M||t[80]!==ne||t[81]!==se||t[82]!==te?(ce=(0,q.jsxs)(`div`,{className:te,children:[M,ne,se]}),t[79]=M,t[80]=ne,t[81]=se,t[82]=te,t[83]=ce):ce=t[83];let le;t[84]===l?le=t[85]:(le=(0,q.jsx)(o,{variant:`outline`,onClick:()=>l(!1),children:`Cancel`}),t[84]=l,t[85]=le);let ue;t[86]===d?ue=t[87]:(ue=d.trim(),t[86]=d,t[87]=ue);let de=!ue,fe;t[88]!==E||t[89]!==de?(fe=(0,q.jsx)(o,{onClick:E,disabled:de,children:`Save`}),t[88]=E,t[89]=de,t[90]=fe):fe=t[90];let pe;t[91]!==le||t[92]!==fe?(pe=(0,q.jsxs)(`div`,{className:`flex justify-end gap-2`,children:[le,fe]}),t[91]=le,t[92]=fe,t[93]=pe):pe=t[93];let me;t[94]!==k||t[95]!==N||t[96]!==P||t[97]!==F||t[98]!==I||t[99]!==L||t[100]!==ce||t[101]!==pe?(me=(0,q.jsxs)(k,{"data-slot":N,"data-ok-layer-spawned":P,className:F,children:[I,L,ce,pe]}),t[94]=k,t[95]=N,t[96]=P,t[97]=F,t[98]=I,t[99]=L,t[100]=ce,t[101]=pe,t[102]=me):me=t[102];let he;t[103]!==A||t[104]!==R||t[105]!==me?(he=(0,q.jsxs)(A,{children:[R,me]}),t[103]=A,t[104]=R,t[105]=me,t[106]=he):he=t[106];let ge;return t[107]!==j||t[108]!==z||t[109]!==B||t[110]!==he?(ge=(0,q.jsx)(j,{open:z,onOpenChange:B,children:he}),t[107]=j,t[108]=z,t[109]=B,t[110]=he,t[111]=ge):ge=t[111],ge}function Lb(e){let t=(0,rr.c)(112),{editor:n,getPos:r,onClose:i}=e,s=r(),c=s==null?null:n.state.doc.nodeAt(s),l=String(c?.attrs.target??``),u=Pe(c?.attrs.alias),d=Pe(c?.attrs.anchor),f=I({target:l,alias:u,anchor:d}),{folderPaths:p,pages:m,loading:h}=ve(),g=Ae(l,d),_=g?.kind===`external`?g:null,v=ty(l,{pages:m,folderPaths:p,fallbackTargets:zv(l)}),[y,b]=(0,G.useState)(!1),[x,S]=(0,G.useState)(null),C=ny(v);if(!c)return null;let w;t[0]!==n||t[1]!==r?(w=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,t[1]=r,t[2]=w):w=t[2];let T=w,E;t[3]!==n||t[4]!==r||t[5]!==i?(E=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[3]=n,t[4]=r,t[5]=i,t[6]=E):E=t[6];let D=E,O;t[7]!==d||t[8]!==_||t[9]!==v||t[10]!==S?(O=function(e){if(_){Uv(_.url)?window.open(_.url,`_blank`,`noopener,noreferrer`):console.warn(`[safe-nav] blocked non-safe scheme:`,_.url);return}if(v.kind===`create`){S(`missing`);return}let t=v.hashDocName;if(e.newTab){Yv({docName:t,anchor:d});return}if(d){let e=window.location.hash.match(/^#\/([^?#/]+)/);if((e?decodeURIComponent(e[1]):null)===t){let e=document.getElementById(d);e&&e.scrollIntoView({behavior:`smooth`,block:`start`})}window.location.hash=`#/${t}?anchor=${encodeURIComponent(d)}`;return}window.location.hash=`#/${t}`},t[7]=d,t[8]=_,t[9]=v,t[10]=S,t[11]=O):O=t[11];let k=O,A;t[12]!==u||t[13]!==x||t[14]!==n||t[15]!==r||t[16]!==f||t[17]!==l?(A=function(e){if(x===`missing`&&e!==l){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:u??f}))}},t[12]=u,t[13]=x,t[14]=n,t[15]=r,t[16]=f,t[17]=l,t[18]=A):A=t[18];let j=A,M=!_&&!h&&v.kind===`navigate`&&v.displayState===`resolved`,N=!_&&!h&&v.kind===`navigate`&&v.displayState===`folder`,P=!_&&!h&&v.kind===`create`,F,L,R,z,B,V,H,ee,te;if(t[19]!==_||t[20]!==N||t[21]!==M||t[22]!==P||t[23]!==h||t[24]!==i){if(h){let e;t[34]===Symbol.for(`react.memo_cache_sentinel`)?(e=(0,q.jsx)(Gn,{className:`size-3.5 shrink-0 animate-spin`,"aria-hidden":`true`}),t[34]=e):e=t[34],L={icon:e,text:`Loading…`,className:`text-muted-foreground`}}else if(_){let e;t[35]===Symbol.for(`react.memo_cache_sentinel`)?(e=(0,q.jsx)(Pn,{className:`size-3.5 shrink-0`,"aria-hidden":`true`}),t[35]=e):e=t[35],L={icon:e,text:`External wiki link`,className:`text-foreground`}}else if(N){let e;t[36]===Symbol.for(`react.memo_cache_sentinel`)?(e=(0,q.jsx)(Ln,{className:`size-3.5 shrink-0`,"aria-hidden":`true`}),t[36]=e):e=t[36],L={icon:e,text:`Folder (no index)`,className:`text-foreground`}}else if(P){let e;t[37]===Symbol.for(`react.memo_cache_sentinel`)?(e=(0,q.jsx)(Mn,{className:`size-3.5 shrink-0`,"aria-hidden":`true`}),t[37]=e):e=t[37],L={icon:e,text:`Page not found`,className:`text-red-700 dark:text-red-300`}}else if(M){let e;t[38]===Symbol.for(`react.memo_cache_sentinel`)?(e=(0,q.jsx)(In,{className:`size-3.5 shrink-0`,"aria-hidden":`true`}),t[38]=e):e=t[38],L={icon:e,text:`Wiki link`,className:`text-foreground`}}else{let e;t[39]===Symbol.for(`react.memo_cache_sentinel`)?(e=(0,q.jsx)(Mn,{className:`size-3.5 shrink-0`,"aria-hidden":`true`}),t[39]=e):e=t[39],L={icon:e,text:`Unrecognized wiki link`,className:`text-muted-foreground`}}F=ey,te=`wiki-link`,R=`Wiki link options`,z=i,H=`mb-2 flex items-start gap-2 pr-8`,ee=(0,q.jsx)(`div`,{className:a(`mt-0.5 flex shrink-0`,L.className),children:L.icon}),V=`flex-1 min-w-0`,B=a(`text-sm font-medium`,L.className),t[19]=_,t[20]=N,t[21]=M,t[22]=P,t[23]=h,t[24]=i,t[25]=F,t[26]=L,t[27]=R,t[28]=z,t[29]=B,t[30]=V,t[31]=H,t[32]=ee,t[33]=te}else F=t[25],L=t[26],R=t[27],z=t[28],B=t[29],V=t[30],H=t[31],ee=t[32],te=t[33];let ne;t[40]!==L.text||t[41]!==B?(ne=(0,q.jsx)(`div`,{className:B,children:L.text}),t[40]=L.text,t[41]=B,t[42]=ne):ne=t[42];let re=_?_.url:`[[${l}${d?`#${d}`:``}]]`,ie=_?_.url:`[[${l}${d?`#${d}`:``}]]`,ae;t[43]!==re||t[44]!==ie?(ae=(0,q.jsx)(`div`,{className:`truncate text-xs text-muted-foreground`,title:re,children:ie}),t[43]=re,t[44]=ie,t[45]=ae):ae=t[45];let oe;t[46]!==ne||t[47]!==ae||t[48]!==V?(oe=(0,q.jsxs)(`div`,{className:V,children:[ne,ae]}),t[46]=ne,t[47]=ae,t[48]=V,t[49]=oe):oe=t[49];let se;t[50]!==oe||t[51]!==H||t[52]!==ee?(se=(0,q.jsxs)(`div`,{className:H,children:[ee,oe]}),t[50]=oe,t[51]=H,t[52]=ee,t[53]=se):se=t[53];let ce;t[54]!==_||t[55]!==k||t[56]!==P||t[57]!==i?(ce=P?null:(0,q.jsx)(o,{size:`sm`,variant:`default`,onClick:()=>{k({}),i()},children:_?`Open in new tab`:`Open`}),t[54]=_,t[55]=k,t[56]=P,t[57]=i,t[58]=ce):ce=t[58];let le;t[59]!==P||t[60]!==S?(le=P?(0,q.jsx)(o,{size:`sm`,variant:`default`,onClick:()=>S(`missing`),children:`Create page`}):null,t[59]=P,t[60]=S,t[61]=le):le=t[61];let ue;t[62]!==C||t[63]!==N||t[64]!==S?(ue=N&&C?(0,q.jsxs)(o,{size:`sm`,variant:`outline`,onClick:()=>S(`folder-index`),children:[(0,q.jsx)(Fn,{className:`size-3.5`,"aria-hidden":`true`}),`Create index`]}):null,t[62]=C,t[63]=N,t[64]=S,t[65]=ue):ue=t[65];let de;t[66]===b?de=t[67]:(de=()=>b(!0),t[66]=b,t[67]=de);let fe;t[68]===Symbol.for(`react.memo_cache_sentinel`)?(fe=(0,q.jsx)(qn,{className:`size-3.5`,"aria-hidden":`true`}),t[68]=fe):fe=t[68];let pe;t[69]===de?pe=t[70]:(pe=(0,q.jsxs)(o,{size:`sm`,variant:`outline`,onClick:de,children:[fe,`Edit`]}),t[69]=de,t[70]=pe);let me;t[71]===Symbol.for(`react.memo_cache_sentinel`)?(me=(0,q.jsx)(Xn,{className:`size-3.5`,"aria-hidden":`true`}),t[71]=me):me=t[71];let he;t[72]===D?he=t[73]:(he=(0,q.jsxs)(o,{size:`sm`,variant:`outline`,className:`text-red-700 hover:bg-red-50 hover:text-red-800 dark:text-red-300 dark:hover:bg-red-100/10 dark:hover:text-red-200`,onClick:D,children:[me,`Remove`]}),t[72]=D,t[73]=he);let ge;t[74]!==ce||t[75]!==le||t[76]!==ue||t[77]!==pe||t[78]!==he?(ge=(0,q.jsxs)(`div`,{className:`flex flex-wrap gap-1.5`,children:[ce,le,ue,pe,he]}),t[74]=ce,t[75]=le,t[76]=ue,t[77]=pe,t[78]=he,t[79]=ge):ge=t[79];let _e;t[80]!==F||t[81]!==R||t[82]!==z||t[83]!==se||t[84]!==ge||t[85]!==te?(_e=(0,q.jsxs)(F,{kind:te,ariaLabel:R,onDeactivate:z,children:[se,ge]}),t[80]=F,t[81]=R,t[82]=z,t[83]=se,t[84]=ge,t[85]=te,t[86]=_e):_e=t[86];let ye=x!==null,be;t[87]===S?be=t[88]:(be=e=>{e||S(null)},t[87]=S,t[88]=be);let xe=x===`folder-index`&&C?C.initialDir:v.kind===`create`?v.initialDir:``,Se=x===`folder-index`&&C?C.suggestedName:v.kind===`create`?v.suggestedName:void 0,Ce;t[89]!==x||t[90]!==C||t[91]!==l?(Ce=x===`folder-index`&&C?(0,q.jsxs)(q.Fragment,{children:[`Create an index note for`,` `,(0,q.jsxs)(`span`,{className:`font-medium text-foreground`,children:[C.initialDir,`/`]})]}):(0,q.jsxs)(q.Fragment,{children:[`Create a page for `,(0,q.jsx)(`span`,{className:`font-medium text-foreground`,children:l})]}),t[89]=x,t[90]=C,t[91]=l,t[92]=Ce):Ce=t[92];let we;t[93]!==j||t[94]!==ye||t[95]!==be||t[96]!==xe||t[97]!==Se||t[98]!==Ce?(we=(0,q.jsx)(ly,{open:ye,onOpenChange:be,kind:`file`,initialDir:xe,suggestedName:Se,description:Ce,onCreated:j}),t[93]=j,t[94]=ye,t[95]=be,t[96]=xe,t[97]=Se,t[98]=Ce,t[99]=we):we=t[99];let Te;t[100]!==u||t[101]!==d||t[102]!==y||t[103]!==T||t[104]!==m||t[105]!==b||t[106]!==l?(Te=(0,q.jsx)(Ib,{open:y,target:l,alias:u,anchor:d,pages:m,onOpenChange:b,onSave:T}),t[100]=u,t[101]=d,t[102]=y,t[103]=T,t[104]=m,t[105]=b,t[106]=l,t[107]=Te):Te=t[107];let Ee;return t[108]!==_e||t[109]!==we||t[110]!==Te?(Ee=(0,q.jsxs)(q.Fragment,{children:[_e,we,Te]}),t[108]=_e,t[109]=we,t[110]=Te,t[111]=Ee):Ee=t[111],Ee}var Rb=0;function zb(){return`wiki-link-${++Rb}`}function Bb(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 Vb=E.extend({priority:200,addNodeView(){return({editor:e,node:t,getPos:n})=>{let r=zb(),{dom:i}=Bb({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=yy(e);return s.register({type:`wikiLink`,nodeId:r,getPos:o,controls:{propPanel:t=>(0,G.createElement)(Lb,{editor:e,getPos:o,onClose:t.deactivate})},handlePrimary:({newTab:e})=>{if(!e)return!1;let t=a.attrs,n=typeof t.target==`string`?t.target:``;if(!n)return!1;let r=Ae(n,typeof t.anchor==`string`?t.anchor:null);return r?r.kind===`doc`?(Yv({docName:r.docName,anchor:r.anchor}),!0):Uv(r.url)?(qv(r.url),!0):!1:!1}}),{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(Hy.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(Hy.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[$y(this.editor)]}}),Hb=[...x.map(e=>e.name===`jsxComponent`?wb:e.name===`rawMdxFallback`?kb:e.name===`wikiLink`?Vb:e.name===`link`?mb:e),Fb,N_.configure({allowedMimeTypes:[...w],onDrop(e,t,n){for(let r of t)z_(r,e,n)},onPaste(e,t,n){for(let n of t)z_(n,e,e.state.selection.from)}}),Vv,Lv,W_];function Ub(e){return e===H}var Wb=0;function Gb(){return Wb}function Kb(){Wb=Date.now()}function qb(e){let{xmlFragment:t,ytext:n}=e,r=(e,t)=>{},i=(e,t)=>{};return t.observeDeep(r),n.observe(i),()=>{t.unobserveDeep(r),n.unobserve(i)}}var Jb=3e4,Yb=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}},Xb=class extends Error{docName;constructor(e){super(`Provider disconnected before sync for "${e}"`),this.name=`PreSyncDisconnectError`,this.docName=e}},Zb=class extends Error{docName;constructor(e){super(`Document not found: "${e}"`),this.name=`DocumentNotFoundError`,this.docName=e}},Qb=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}},$b=new Map,ex=!1;function tx(){for(let e of $b.values())if(!e.settled)return!0;return!1}function nx(){typeof document>`u`||document.visibilityState===`visible`&&rx(Date.now())}function rx(e){let t=[];for(let[n,r]of $b){if(r.settled)continue;let i=e-r.createdAt;if(i<3e4)continue;r.settled=!0;let a=new Yb(n,i);sx(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 tx()||ax(),t.length}function ix(){ex||typeof document>`u`||(document.addEventListener(`visibilitychange`,nx),ex=!0)}function ax(){ex&&(typeof document>`u`||(document.removeEventListener(`visibilitychange`,nx),ex=!1))}var ox=new Map;function sx(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 cx(e,t){let n=$b.get(e);if(n)return n.promise;let r=ox.get(e);if(r!==void 0){ox.delete(e);let n=r===`timeout`?new Yb(e,0):new Xb(e);console.warn(`[syncPromise] ${e} rejected on creation (test hook, armed ${r}): ${n.message}`),K(`ok/sync/create`,{docName:e,warm:!1,armed:r}),K(`ok/sync/reject`,{docName:e,reason:`armed-${r}`});let i=ux(n);return $b.set(e,dx(i,t)),i}if(t.synced){console.log(`[syncPromise] ${e} resolved synchronously (warm provider)`),K(`ok/sync/create`,{docName:e,warm:!0}),K(`ok/sync/resolve`,{docName:e,elapsedMs:0,warm:!0});let n=Promise.resolve();return $b.set(e,lx(n,t)),n}let i=Date.now(),a=()=>{},o=()=>{},s=new Promise((e,t)=>{a=e,o=t}),c=()=>{let t=$b.get(e);if(!t||t.settled)return;t.settled=!0;let n=Date.now()-t.createdAt;console.log(`[syncPromise] ${e} resolved in ${n}ms`),K(`ok/sync/resolve`,{docName:e,elapsedMs:n,warm:!1}),sx(t),tx()||ax(),t.resolve()},l=t=>{let n=$b.get(e);if(!n||n.settled)return;n.settled=!0;let r=new Xb(e);console.warn(`[syncPromise] ${e} rejected: ${r.message}`),K(`ok/sync/reject`,{docName:e,reason:`pre-sync-disconnect`}),sx(n),tx()||ax(),n.reject(r)},u=setTimeout(()=>{let t=$b.get(e);if(!t||t.settled)return;t.settled=!0;let n=Date.now()-t.createdAt,r=new Yb(e,n);console.warn(`[syncPromise] ${e} rejected: ${r.message}`),K(`ok/sync/reject`,{docName:e,reason:`timeout`,elapsedMs:n}),sx(t),tx()||ax(),t.reject(r)},Jb),d={promise:s,resolve:a,reject:o,createdAt:i,timeoutHandle:u,provider:t,onSynced:c,onClose:l,settled:!1,detached:!1};return $b.set(e,d),t.on(`synced`,c),t.on(`close`,l),ix(),K(`ok/sync/create`,{docName:e,warm:!1}),s}function lx(e,t){return{promise:e,resolve:()=>{},reject:()=>{},createdAt:Date.now(),timeoutHandle:null,provider:t,onSynced:()=>{},onClose:()=>{},settled:!0,detached:!0}}function ux(e){let t=Promise.reject(e);t.catch(()=>{});let n=t;return n.status=`rejected`,n.reason=e,n}function dx(e,t){return{promise:e,resolve:()=>{},reject:()=>{},createdAt:Date.now(),timeoutHandle:null,provider:t,onSynced:()=>{},onClose:()=>{},settled:!0,detached:!0}}function fx(e){let t=$b.get(e);t&&(t.settled=!0,sx(t),$b.delete(e),tx()||ax())}function px(e,t){let n=$b.get(e);return!n||n.settled?!1:(n.settled=!0,console.warn(`[syncPromise] ${e} rejected: ${t.message}`),sx(n),tx()||ax(),n.reject(t),!0)}var mx=ue(Hb),hx=4e3,gx=5e3,_x=class{entries=new Map;lruOrder=[];activeDocName=null;maxSize;wsUrl;recycleDebounceMs;onChange=null;tabIdentity=null;constructor(e,t,n){this.maxSize=e,this.wsUrl=t,this.recycleDebounceMs=n??hx}setTabIdentity(e){this.tabIdentity=e}setOnChange(e){this.onChange=e}notify(){this.onChange?.()}touch(e){let t=this.lruOrder.indexOf(e);t!==-1&&this.lruOrder.splice(t,1),this.lruOrder.push(e)}open(e){if(Ub(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=new l_({url:this.wsUrl,name:e,forceSyncInterval:gx,...this.tabIdentity===null?{}:{token:JSON.stringify(this.tabIdentity)}}),r={provider:n,observerCleanup:null,syncState:`connecting`,docName:e,lastAccessedAt:Date.now(),hasSynced:!1,tearingDown:!1,pendingRecycleTimer:null,bridgeSetupFailed:!1};return n.on(`status`,({status:t})=>{r.tearingDown||this.entries.get(e)!==r||t===`disconnected`&&(r.syncState=`disconnected`,this.notify())}),n.on(`synced`,()=>{if(!(r.tearingDown||this.entries.get(e)!==r)&&(r.syncState=`synced`,r.hasSynced=!0,r.pendingRecycleTimer&&=(clearTimeout(r.pendingRecycleTimer),null),this.notify(),!r.observerCleanup))try{let t=n.document,i=new O({extensions:Hb});r.observerCleanup=qb({doc:t,xmlFragment:t.getXmlFragment(`default`),ytext:t.getText(`source`),mdManager:i,schema:mx,onSyncError:(t,n)=>{console.warn(`[Sync] ${t} failed for ${e}:`,n.message)}})}catch(t){console.error(`[ProviderPool] setupObservers init failed for ${e}:`,t),r.bridgeSetupFailed=!0,px(e,new Qb(e,t))}}),n.on(`disconnect`,()=>{r.tearingDown||this.entries.get(e)!==r||(r.syncState=`disconnected`,this.notify(),r.hasSynced&&n.unsyncedChanges===0&&!r.pendingRecycleTimer&&(r.pendingRecycleTimer=setTimeout(()=>{r.pendingRecycleTimer=null,!(r.tearingDown||this.entries.get(e)!==r)&&this.recycleDisconnectedEntry(e)},this.recycleDebounceMs)))}),this.entries.set(e,r),this.touch(e),this.notify(),r}prewarm(e){if(Ub(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.activeDocName===e&&(this.activeDocName=null),this.notify())}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}evictLru(){for(let e of this.lruOrder)if(e!==this.activeDocName){K(`ok/pool/evict-lru`,{docName:e}),this.close(e);return}}destroyEntry(e){e.tearingDown=!0,e.pendingRecycleTimer&&=(clearTimeout(e.pendingRecycleTimer),null),fx(e.docName),b_(e.docName),C_(e.docName),e.observerCleanup?.(),e.observerCleanup=null;try{e.provider.destroy()}catch(t){console.warn(`[ProviderPool] Provider destroy failed for ${e.docName}:`,t)}}recycleDisconnectedEntry(e){let t=this.entries.get(e);if(!t||t.tearingDown)return;let n=this.activeDocName===e;if(K(`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()}},vx=crypto.randomUUID(),yx=`ok-pin-v1`,bx=!1;function xx(e){bx||(bx=!0,console.warn(`[DocumentContext] localStorage unavailable — pinned doc will not persist across tabs/reloads.`,e))}function Sx(){if(typeof window>`u`)return null;try{return window.localStorage.getItem(yx)}catch(e){return xx(e),null}}function Cx(e){if(!(typeof window>`u`))try{e===null?window.localStorage.removeItem(yx):window.localStorage.setItem(yx,e)}catch(e){xx(e)}}var wx=(0,G.createContext)(null),Tx=null;function Ex(e){return Tx||=new _x(10,e),Tx}var Dx={activeDocName:null,activeProvider:null,syncState:`connecting`,poolEntries:[]};function Ox(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`,poolEntries:n}}function kx(e){let t=(0,rr.c)(43),{children:n}=e,[r,i]=(0,G.useState)(Dx),[a,o]=(0,G.useState)(null),[s,c]=(0,G.useState)(null),[u,d]=(0,G.useState)(null),{collabUrl:f,terminal:p,lastError:m,retry:h}=Sm(),g,_;t[0]===f?(g=t[1],_=t[2]):(g=()=>{if(f===null)return;let e=Ex(f);i(Ox(e)),e.setOnChange(()=>i(Ox(e)));let t=Sx();return t!==null&&c(t),fetch(`/api/principal`).then(jx).then(t=>{t&&typeof t.id==`string`&&e.setTabIdentity({principalId:t.id,tabSessionId:vx})}).catch(Ax),()=>{e.setOnChange(null)}},_=[f],t[0]=f,t[1]=g,t[2]=_),(0,G.useEffect)(g,_);let v,y;t[3]===Symbol.for(`react.memo_cache_sentinel`)?(v=()=>{},y=[],t[3]=v,t[4]=y):(v=t[3],y=t[4]),(0,G.useEffect)(v,y);let b;t[5]===f?b=t[6]:(b=e=>{if(K(`ok/nav/open-document`,{docName:e,transition:!1}),f===null)return;let t=Ex(f);t.open(e)&&(t.setActive(e),o({kind:`doc`,target:e,docName:e}))},t[5]=f,t[6]=b);let x=b,S;t[7]===x?S=t[8]:(S=e=>{K(`ok/nav/open-document`,{docName:e,transition:!1}),x(e)},t[7]=x,t[8]=S);let C=S,w;t[9]===f?w=t[10]:(w=e=>{if(f===null)return;let t=Ex(f),n=l(e);n?(t.open(n),t.setActive(n)):t.clearActive(),o(e)},t[9]=f,t[10]=w);let T=w,E;t[11]===T?E=t[12]:(E=e=>{K(`ok/nav/open-target`,{docName:l(e),kind:e.kind,transition:!1}),T(e)},t[11]=T,t[12]=E);let D=E,O,k,A,j;t[13]===f?(O=t[14],k=t[15],A=t[16],j=t[17]):(j=()=>{if(f===null){o(null);return}Ex(f).clearActive(),o(null)},O=e=>{f!==null&&(Ex(f).close(e),o(t=>t&&(l(t)===e?null:t)))},k=e=>{f!==null&&Ex(f).recycle(e)},A=e=>{f!==null&&Ex(f).prewarm(e)},t[13]=f,t[14]=O,t[15]=k,t[16]=A,t[17]=j);let M,N;t[18]===Symbol.for(`react.memo_cache_sentinel`)?(M=e=>{c(e),Cx(e)},N=()=>{c(null),Cx(null)},t[18]=M,t[19]=N):(M=t[18],N=t[19]);let P;t[20]!==a||t[21]!==m||t[22]!==p||t[23]!==f||t[24]!==x||t[25]!==C||t[26]!==T||t[27]!==D||t[28]!==s||t[29]!==h||t[30]!==r.activeDocName||t[31]!==r.activeProvider||t[32]!==r.poolEntries||t[33]!==r.syncState||t[34]!==u||t[35]!==O||t[36]!==k||t[37]!==A||t[38]!==j?(P={activeTarget:a,activeDocName:r.activeDocName,activeProvider:r.activeProvider,syncState:r.syncState,poolEntries:r.poolEntries,openDocument:x,openDocumentTransition:C,openTarget:T,openTargetTransition:D,clearTarget:j,closeDocument:O,recycleDocument:k,prewarm:A,pinnedDoc:s,pin:M,unpin:N,systemProvider:u,setSystemProvider:d,collabUrl:f,collabTerminal:p,collabLastError:m,retryCollab:h},t[20]=a,t[21]=m,t[22]=p,t[23]=f,t[24]=x,t[25]=C,t[26]=T,t[27]=D,t[28]=s,t[29]=h,t[30]=r.activeDocName,t[31]=r.activeProvider,t[32]=r.poolEntries,t[33]=r.syncState,t[34]=u,t[35]=O,t[36]=k,t[37]=A,t[38]=j,t[39]=P):P=t[39];let F=P,I;return t[40]!==n||t[41]!==F?(I=(0,q.jsx)(wx,{value:F,children:n}),t[40]=n,t[41]=F,t[42]=I):I=t[42],I}function Ax(){}function jx(e){return e.ok?e.json():null}function Mx(){let e=(0,G.use)(wx);if(!e)throw Error(`useDocumentContext must be used within <DocumentProvider />`);return e}function Nx(){let e=(0,rr.c)(3),{openDocumentTransition:t,openTargetTransition:n}=Mx(),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}var Px=new Map;function Fx(e,t){Px.set(e,t)}function Ix(e){let t=Px.get(e)??null;return Px.delete(e),t}function Lx(e){Px.delete(e)}var Rx=class e{static create(t,n,r,i,a){return new e(t,n,r,i+(i<<8)+t+(n<<4)|0,a,[],[])}constructor(e,t,n,r,i,a,o){this.type=e,this.value=t,this.from=n,this.hash=r,this.end=i,this.children=a,this.positions=o,this.hashProp=[[Ze.contextHash,r]]}addChild(e,t){e.prop(Ze.contextHash)!=this.hash&&(e=new at(e.type,e.children,e.positions,e.length,this.hashProp)),this.children.push(e),this.positions.push(t)}toTree(e,t=this.end){let n=this.children.length-1;return n>=0&&(t=Math.max(t,this.positions[n]+this.children[n].length+this.from)),new at(e.types[this.type],this.children,this.positions,t-this.from).balance({makeTree:(e,t,n)=>new at(ot.none,e,t,n,this.hashProp)})}},Z;(function(e){e[e.Document=1]=`Document`,e[e.CodeBlock=2]=`CodeBlock`,e[e.FencedCode=3]=`FencedCode`,e[e.Blockquote=4]=`Blockquote`,e[e.HorizontalRule=5]=`HorizontalRule`,e[e.BulletList=6]=`BulletList`,e[e.OrderedList=7]=`OrderedList`,e[e.ListItem=8]=`ListItem`,e[e.ATXHeading1=9]=`ATXHeading1`,e[e.ATXHeading2=10]=`ATXHeading2`,e[e.ATXHeading3=11]=`ATXHeading3`,e[e.ATXHeading4=12]=`ATXHeading4`,e[e.ATXHeading5=13]=`ATXHeading5`,e[e.ATXHeading6=14]=`ATXHeading6`,e[e.SetextHeading1=15]=`SetextHeading1`,e[e.SetextHeading2=16]=`SetextHeading2`,e[e.HTMLBlock=17]=`HTMLBlock`,e[e.LinkReference=18]=`LinkReference`,e[e.Paragraph=19]=`Paragraph`,e[e.CommentBlock=20]=`CommentBlock`,e[e.ProcessingInstructionBlock=21]=`ProcessingInstructionBlock`,e[e.Escape=22]=`Escape`,e[e.Entity=23]=`Entity`,e[e.HardBreak=24]=`HardBreak`,e[e.Emphasis=25]=`Emphasis`,e[e.StrongEmphasis=26]=`StrongEmphasis`,e[e.Link=27]=`Link`,e[e.Image=28]=`Image`,e[e.InlineCode=29]=`InlineCode`,e[e.HTMLTag=30]=`HTMLTag`,e[e.Comment=31]=`Comment`,e[e.ProcessingInstruction=32]=`ProcessingInstruction`,e[e.Autolink=33]=`Autolink`,e[e.HeaderMark=34]=`HeaderMark`,e[e.QuoteMark=35]=`QuoteMark`,e[e.ListMark=36]=`ListMark`,e[e.LinkMark=37]=`LinkMark`,e[e.EmphasisMark=38]=`EmphasisMark`,e[e.CodeMark=39]=`CodeMark`,e[e.CodeText=40]=`CodeText`,e[e.CodeInfo=41]=`CodeInfo`,e[e.LinkTitle=42]=`LinkTitle`,e[e.LinkLabel=43]=`LinkLabel`,e[e.URL=44]=`URL`})(Z||={});var zx=class{constructor(e,t){this.start=e,this.content=t,this.marks=[],this.parsers=[]}},Bx=class{constructor(){this.text=``,this.baseIndent=0,this.basePos=0,this.depth=0,this.markers=[],this.pos=0,this.indent=0,this.next=-1}forward(){this.basePos>this.pos&&this.forwardInner()}forwardInner(){let e=this.skipSpace(this.basePos);this.indent=this.countIndent(e,this.pos,this.indent),this.pos=e,this.next=e==this.text.length?-1:this.text.charCodeAt(e)}skipSpace(e){return Wx(this.text,e)}reset(e){for(this.text=e,this.baseIndent=this.basePos=this.pos=this.indent=0,this.forwardInner(),this.depth=1;this.markers.length;)this.markers.pop()}moveBase(e){this.basePos=e,this.baseIndent=this.countIndent(e,this.pos,this.indent)}moveBaseColumn(e){this.baseIndent=e,this.basePos=this.findColumn(e)}addMarker(e){this.markers.push(e)}countIndent(e,t=0,n=0){for(let r=t;r<e;r++)n+=this.text.charCodeAt(r)==9?4-n%4:1;return n}findColumn(e){let t=0;for(let n=0;t<this.text.length&&n<e;t++)n+=this.text.charCodeAt(t)==9?4-n%4:1;return t}scrub(){if(!this.baseIndent)return this.text;let e=``;for(let t=0;t<this.basePos;t++)e+=` `;return e+this.text.slice(this.basePos)}};function Vx(e,t,n){if(n.pos==n.text.length||e!=t.block&&n.indent>=t.stack[n.depth+1].value+n.baseIndent)return!0;if(n.indent>=n.baseIndent+4)return!1;let r=(e.type==Z.OrderedList?Zx:Xx)(n,t,!1);return r>0&&(e.type!=Z.BulletList||Jx(n,t,!1)<0)&&n.text.charCodeAt(n.pos+r-1)==e.value}var Hx={[Z.Blockquote](e,t,n){return n.next==62?(n.markers.push(Q(Z.QuoteMark,t.lineStart+n.pos,t.lineStart+n.pos+1)),n.moveBase(n.pos+(Ux(n.text.charCodeAt(n.pos+1))?2:1)),e.end=t.lineStart+n.text.length,!0):!1},[Z.ListItem](e,t,n){return n.indent<n.baseIndent+e.value&&n.next>-1?!1:(n.moveBaseColumn(n.baseIndent+e.value),!0)},[Z.OrderedList]:Vx,[Z.BulletList]:Vx,[Z.Document](){return!0}};function Ux(e){return e==32||e==9||e==10||e==13}function Wx(e,t=0){for(;t<e.length&&Ux(e.charCodeAt(t));)t++;return t}function Gx(e,t,n){for(;t>n&&Ux(e.charCodeAt(t-1));)t--;return t}function Kx(e){if(e.next!=96&&e.next!=126)return-1;let t=e.pos+1;for(;t<e.text.length&&e.text.charCodeAt(t)==e.next;)t++;if(t<e.pos+3)return-1;if(e.next==96){for(let n=t;n<e.text.length;n++)if(e.text.charCodeAt(n)==96)return-1}return t}function qx(e){return e.next==62?e.text.charCodeAt(e.pos+1)==32?2:1:-1}function Jx(e,t,n){if(e.next!=42&&e.next!=45&&e.next!=95)return-1;let r=1;for(let t=e.pos+1;t<e.text.length;t++){let n=e.text.charCodeAt(t);if(n==e.next)r++;else if(!Ux(n))return-1}return n&&e.next==45&&$x(e)>-1&&e.depth==t.stack.length&&t.parser.leafBlockParsers.indexOf(dS.SetextHeading)>-1||r<3?-1:1}function Yx(e,t){for(let n=e.stack.length-1;n>=0;n--)if(e.stack[n].type==t)return!0;return!1}function Xx(e,t,n){return(e.next==45||e.next==43||e.next==42)&&(e.pos==e.text.length-1||Ux(e.text.charCodeAt(e.pos+1)))&&(!n||Yx(t,Z.BulletList)||e.skipSpace(e.pos+2)<e.text.length)?1:-1}function Zx(e,t,n){let r=e.pos,i=e.next;for(;i>=48&&i<=57;){if(r++,r==e.text.length)return-1;i=e.text.charCodeAt(r)}return r==e.pos||r>e.pos+9||i!=46&&i!=41||r<e.text.length-1&&!Ux(e.text.charCodeAt(r+1))||n&&!Yx(t,Z.OrderedList)&&(e.skipSpace(r+1)==e.text.length||r>e.pos+1||e.next!=49)?-1:r+1-e.pos}function Qx(e){if(e.next!=35)return-1;let t=e.pos+1;for(;t<e.text.length&&e.text.charCodeAt(t)==35;)t++;if(t<e.text.length&&e.text.charCodeAt(t)!=32)return-1;let n=t-e.pos;return n>6?-1:n}function $x(e){if(e.next!=45&&e.next!=61||e.indent>=e.baseIndent+4)return-1;let t=e.pos+1;for(;t<e.text.length&&e.text.charCodeAt(t)==e.next;)t++;let n=t;for(;t<e.text.length&&Ux(e.text.charCodeAt(t));)t++;return t==e.text.length?n:-1}var eS=/^[ \t]*$/,tS=/-->/,nS=/\?>/,rS=[[/^<(?:script|pre|style)(?:\s|>|$)/i,/<\/(?:script|pre|style)>/i],[/^\s*<!--/,tS],[/^\s*<\?/,nS],[/^\s*<![A-Z]/,/>/],[/^\s*<!\[CDATA\[/,/\]\]>/],[/^\s*<\/?(?:address|article|aside|base|basefont|blockquote|body|caption|center|col|colgroup|dd|details|dialog|dir|div|dl|dt|fieldset|figcaption|figure|footer|form|frame|frameset|h1|h2|h3|h4|h5|h6|head|header|hr|html|iframe|legend|li|link|main|menu|menuitem|nav|noframes|ol|optgroup|option|p|param|section|source|summary|table|tbody|td|tfoot|th|thead|title|tr|track|ul)(?:\s|\/?>|$)/i,eS],[/^\s*(?:<\/[a-z][\w-]*\s*>|<[a-z][\w-]*(\s+[a-z:_][\w-.]*(?:\s*=\s*(?:[^\s"'=<>`]+|'[^']*'|"[^"]*"))?)*\s*>)\s*$/i,eS]];function iS(e,t,n){if(e.next!=60)return-1;let r=e.text.slice(e.pos);for(let e=0,t=rS.length-+!!n;e<t;e++)if(rS[e][0].test(r))return e;return-1}function aS(e,t){let n=e.countIndent(t,e.pos,e.indent),r=e.countIndent(e.skipSpace(t),t,n);return r>=n+5?n+1:r}function oS(e,t,n){let r=e.length-1;r>=0&&e[r].to==t&&e[r].type==Z.CodeText?e[r].to=n:e.push(Q(Z.CodeText,t,n))}var sS={LinkReference:void 0,IndentedCode(e,t){let n=t.baseIndent+4;if(t.indent<n)return!1;let r=t.findColumn(n),i=e.lineStart+r,a=e.lineStart+t.text.length,o=[],s=[];for(oS(o,i,a);e.nextLine()&&t.depth>=e.stack.length;)if(t.pos==t.text.length){oS(s,e.lineStart-1,e.lineStart);for(let e of t.markers)s.push(e)}else if(t.indent<n)break;else{if(s.length){for(let e of s)e.type==Z.CodeText?oS(o,e.from,e.to):o.push(e);s=[]}oS(o,e.lineStart-1,e.lineStart);for(let e of t.markers)o.push(e);a=e.lineStart+t.text.length;let n=e.lineStart+t.findColumn(t.baseIndent+4);n<a&&oS(o,n,a)}return s.length&&(s=s.filter(e=>e.type!=Z.CodeText),s.length&&(t.markers=s.concat(t.markers))),e.addNode(e.buffer.writeElements(o,-i).finish(Z.CodeBlock,a-i),i),!0},FencedCode(e,t){let n=Kx(t);if(n<0)return!1;let r=e.lineStart+t.pos,i=t.next,a=n-t.pos,o=t.skipSpace(n),s=Gx(t.text,t.text.length,o),c=[Q(Z.CodeMark,r,r+a)];o<s&&c.push(Q(Z.CodeInfo,e.lineStart+o,e.lineStart+s));for(let n=!0,r=!0,o=!1;e.nextLine()&&t.depth>=e.stack.length;n=!1){let s=t.pos;if(t.indent-t.baseIndent<4)for(;s<t.text.length&&t.text.charCodeAt(s)==i;)s++;if(s-t.pos>=a&&t.skipSpace(s)==t.text.length){for(let e of t.markers)c.push(e);r&&o&&oS(c,e.lineStart-1,e.lineStart),c.push(Q(Z.CodeMark,e.lineStart+t.pos,e.lineStart+s)),e.nextLine();break}else{o=!0,n||(oS(c,e.lineStart-1,e.lineStart),r=!1);for(let e of t.markers)c.push(e);let i=e.lineStart+t.basePos,a=e.lineStart+t.text.length;i<a&&(oS(c,i,a),r=!1)}}return e.addNode(e.buffer.writeElements(c,-r).finish(Z.FencedCode,e.prevLineEnd()-r),r),!0},Blockquote(e,t){let n=qx(t);return n<0?!1:(e.startContext(Z.Blockquote,t.pos),e.addNode(Z.QuoteMark,e.lineStart+t.pos,e.lineStart+t.pos+1),t.moveBase(t.pos+n),null)},HorizontalRule(e,t){if(Jx(t,e,!1)<0)return!1;let n=e.lineStart+t.pos;return e.nextLine(),e.addNode(Z.HorizontalRule,n),!0},BulletList(e,t){let n=Xx(t,e,!1);if(n<0)return!1;e.block.type!=Z.BulletList&&e.startContext(Z.BulletList,t.basePos,t.next);let r=aS(t,t.pos+1);return e.startContext(Z.ListItem,t.basePos,r-t.baseIndent),e.addNode(Z.ListMark,e.lineStart+t.pos,e.lineStart+t.pos+n),t.moveBaseColumn(r),null},OrderedList(e,t){let n=Zx(t,e,!1);if(n<0)return!1;e.block.type!=Z.OrderedList&&e.startContext(Z.OrderedList,t.basePos,t.text.charCodeAt(t.pos+n-1));let r=aS(t,t.pos+n);return e.startContext(Z.ListItem,t.basePos,r-t.baseIndent),e.addNode(Z.ListMark,e.lineStart+t.pos,e.lineStart+t.pos+n),t.moveBaseColumn(r),null},ATXHeading(e,t){let n=Qx(t);if(n<0)return!1;let r=t.pos,i=e.lineStart+r,a=Gx(t.text,t.text.length,r),o=a;for(;o>r&&t.text.charCodeAt(o-1)==t.next;)o--;(o==a||o==r||!Ux(t.text.charCodeAt(o-1)))&&(o=t.text.length);let s=e.buffer.write(Z.HeaderMark,0,n).writeElements(e.parser.parseInline(t.text.slice(r+n+1,o),i+n+1),-i);o<t.text.length&&s.write(Z.HeaderMark,o-r,a-r);let c=s.finish(Z.ATXHeading1-1+n,t.text.length-r);return e.nextLine(),e.addNode(c,i),!0},HTMLBlock(e,t){let n=iS(t,e,!1);if(n<0)return!1;let r=e.lineStart+t.pos,i=rS[n][1],a=[],o=i!=eS;for(;!i.test(t.text)&&e.nextLine();){if(t.depth<e.stack.length){o=!1;break}for(let e of t.markers)a.push(e)}o&&e.nextLine();let s=i==tS?Z.CommentBlock:i==nS?Z.ProcessingInstructionBlock:Z.HTMLBlock,c=e.prevLineEnd();return e.addNode(e.buffer.writeElements(a,-r).finish(s,c-r),r),!0},SetextHeading:void 0},cS=class{constructor(e){this.stage=0,this.elts=[],this.pos=0,this.start=e.start,this.advance(e.content)}nextLine(e,t,n){if(this.stage==-1)return!1;let r=n.content+`
|
|
6
6
|
`+t.scrub(),i=this.advance(r);return i>-1&&i<r.length?this.complete(e,n,i):!1}finish(e,t){return(this.stage==2||this.stage==3)&&Wx(t.content,this.pos)==t.content.length?this.complete(e,t,t.content.length):!1}complete(e,t,n){return e.addLeafElement(t,Q(Z.LinkReference,this.start,this.start+n,this.elts)),!0}nextStage(e){return e?(this.pos=e.to-this.start,this.elts.push(e),this.stage++,!0):(e===!1&&(this.stage=-1),!1)}advance(e){for(;;)if(this.stage==-1)return-1;else if(this.stage==0){if(!this.nextStage(IS(e,this.pos,this.start,!0)))return-1;if(e.charCodeAt(this.pos)!=58)return this.stage=-1;this.elts.push(Q(Z.LinkMark,this.pos+this.start,this.pos+this.start+1)),this.pos++}else if(this.stage==1){if(!this.nextStage(PS(e,Wx(e,this.pos),this.start)))return-1}else if(this.stage==2){let t=Wx(e,this.pos),n=0;if(t>this.pos){let r=FS(e,t,this.start);if(r){let t=lS(e,r.to-this.start);t>0&&(this.nextStage(r),n=t)}}return n||=lS(e,this.pos),n>0&&n<e.length?n:-1}else return lS(e,this.pos)}};function lS(e,t){for(;t<e.length;t++){let n=e.charCodeAt(t);if(n==10)break;if(!Ux(n))return-1}return t}var uS=class{nextLine(e,t,n){let r=t.depth<e.stack.length?-1:$x(t),i=t.next;if(r<0)return!1;let a=Q(Z.HeaderMark,e.lineStart+t.pos,e.lineStart+r);return e.nextLine(),e.addLeafElement(n,Q(i==61?Z.SetextHeading1:Z.SetextHeading2,n.start,e.prevLineEnd(),[...e.parser.parseInline(n.content,n.start),a])),!0}finish(){return!1}},dS={LinkReference(e,t){return t.content.charCodeAt(0)==91?new cS(t):null},SetextHeading(){return new uS}},fS=[(e,t)=>Qx(t)>=0,(e,t)=>Kx(t)>=0,(e,t)=>qx(t)>=0,(e,t)=>Xx(t,e,!0)>=0,(e,t)=>Zx(t,e,!0)>=0,(e,t)=>Jx(t,e,!0)>=0,(e,t)=>iS(t,e,!0)>=0],pS={text:``,end:0},mS=class{constructor(e,t,n,r){this.parser=e,this.input=t,this.ranges=r,this.line=new Bx,this.atEnd=!1,this.reusePlaceholders=new Map,this.stoppedAt=null,this.rangeI=0,this.to=r[r.length-1].to,this.lineStart=this.absoluteLineStart=this.absoluteLineEnd=r[0].from,this.block=Rx.create(Z.Document,0,this.lineStart,0,0),this.stack=[this.block],this.fragments=n.length?new BS(n,t):null,this.readLine()}get parsedPos(){return this.absoluteLineStart}advance(){if(this.stoppedAt!=null&&this.absoluteLineStart>this.stoppedAt)return this.finish();let{line:e}=this;for(;;){for(let t=0;;){let n=e.depth<this.stack.length?this.stack[this.stack.length-1]:null;for(;t<e.markers.length&&(!n||e.markers[t].from<n.end);){let n=e.markers[t++];this.addNode(n.type,n.from,n.to)}if(!n)break;this.finishContext()}if(e.pos<e.text.length)break;if(!this.nextLine())return this.finish()}if(this.fragments&&this.reuseFragment(e.basePos))return null;start:for(;;){for(let t of this.parser.blockParsers)if(t){let n=t(this,e);if(n!=0){if(n==1)return null;e.forward();continue start}}break}let t=new zx(this.lineStart+e.pos,e.text.slice(e.pos));for(let e of this.parser.leafBlockParsers)if(e){let n=e(this,t);n&&t.parsers.push(n)}lines:for(;this.nextLine()&&e.pos!=e.text.length;){if(e.indent<e.baseIndent+4){for(let n of this.parser.endLeafBlock)if(n(this,e,t))break lines}for(let n of t.parsers)if(n.nextLine(this,e,t))return null;t.content+=`
|
|
7
7
|
`+e.scrub();for(let n of e.markers)t.marks.push(n)}return this.finishLeaf(t),null}stopAt(e){if(this.stoppedAt!=null&&this.stoppedAt<e)throw RangeError(`Can't move stoppedAt forward`);this.stoppedAt=e}reuseFragment(e){if(!this.fragments.moveTo(this.absoluteLineStart+e,this.absoluteLineStart)||!this.fragments.matches(this.block.hash))return!1;let t=this.fragments.takeNodes(this);return t?(this.absoluteLineStart+=t,this.lineStart=VS(this.absoluteLineStart,this.ranges),this.moveRangeI(),this.absoluteLineStart<this.to?(this.lineStart++,this.absoluteLineStart++,this.readLine()):(this.atEnd=!0,this.readLine()),!0):!1}get depth(){return this.stack.length}parentType(e=this.depth-1){return this.parser.nodeSet.types[this.stack[e].type]}nextLine(){return this.lineStart+=this.line.text.length,this.absoluteLineEnd>=this.to?(this.absoluteLineStart=this.absoluteLineEnd,this.atEnd=!0,this.readLine(),!1):(this.lineStart++,this.absoluteLineStart=this.absoluteLineEnd+1,this.moveRangeI(),this.readLine(),!0)}peekLine(){return this.scanLine(this.absoluteLineEnd+1).text}moveRangeI(){for(;this.rangeI<this.ranges.length-1&&this.absoluteLineStart>=this.ranges[this.rangeI].to;)this.rangeI++,this.absoluteLineStart=Math.max(this.absoluteLineStart,this.ranges[this.rangeI].from)}scanLine(e){let t=pS;if(t.end=e,e>=this.to)t.text=``;else if(t.text=this.lineChunkAt(e),t.end+=t.text.length,this.ranges.length>1){let e=this.absoluteLineStart,n=this.rangeI;for(;this.ranges[n].to<t.end;){n++;let r=this.ranges[n].from,i=this.lineChunkAt(r);t.end=r+i.length,t.text=t.text.slice(0,this.ranges[n-1].to-e)+i,e=t.end-t.text.length}}return t}readLine(){let{line:e}=this,{text:t,end:n}=this.scanLine(this.absoluteLineStart);for(this.absoluteLineEnd=n,e.reset(t);e.depth<this.stack.length;e.depth++){let t=this.stack[e.depth],n=this.parser.skipContextMarkup[t.type];if(!n)throw Error(`Unhandled block context `+Z[t.type]);let r=this.line.markers.length;if(!n(t,this,e)){this.line.markers.length>r&&(t.end=this.line.markers[this.line.markers.length-1].to),e.forward();break}e.forward()}}lineChunkAt(e){let t=this.input.chunk(e),n;if(this.input.lineChunks)n=t==`
|
|
8
8
|
`?``:t;else{let e=t.indexOf(`
|
|
@@ -30,7 +30,7 @@ import{C as e,E as t,O as n,S as r,T as i,n as a,t as o,w as s,x as c}from"./but
|
|
|
30
30
|
}`,{label:`interface`,detail:`definition`,type:`keyword`}),xn("type ${name} = ${type}",{label:`type`,detail:`definition`,type:`keyword`}),xn(`enum \${name} {
|
|
31
31
|
\${}
|
|
32
32
|
}`,{label:`enum`,detail:`definition`,type:`keyword`})]),oE=new Ct,sE=new Set([`Script`,`Block`,`FunctionExpression`,`FunctionDeclaration`,`ArrowFunction`,`MethodDeclaration`,`ForStatement`]);function cE(e){return(t,n)=>{let r=t.node.getChild(`VariableDefinition`);return r&&n(r,e),!0}}var lE=[`FunctionDeclaration`],uE={FunctionDeclaration:cE(`function`),ClassDeclaration:cE(`class`),ClassExpression:()=>!0,EnumDeclaration:cE(`constant`),TypeAliasDeclaration:cE(`type`),NamespaceDeclaration:cE(`namespace`),VariableDefinition(e,t){e.matchContext(lE)||t(e,`variable`)},TypeDefinition(e,t){t(e,`type`)},__proto__:null};function dE(e,t){let n=oE.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(vn.IncludeAnonymous).iterate(t=>{if(i)i=!1;else if(t.name){let e=uE[t.name];if(e&&e(t,a)||sE.has(t.name))return!1}else if(t.to-t.from>8192){for(let n of dE(e,t.node))r.push(n);return!1}}),oE.set(t,r),r}var fE=/^[\w$\xa1-\uffff][\w$\d\xa1-\uffff]*$/,pE=[`TemplateString`,`String`,`RegExp`,`LineComment`,`BlockComment`,`VariableDefinition`,`TypeDefinition`,`Label`,`PropertyDefinition`,`PropertyName`,`PrivatePropertyDefinition`,`PrivatePropertyName`,`JSXText`,`JSXAttributeValue`,`JSXOpenTag`,`JSXCloseTag`,`JSXSelfClosingTag`,`.`,`?.`];function mE(e){let t=mt(e.state).resolveInner(e.pos,-1);if(pE.indexOf(t.name)>-1)return null;let n=t.name==`VariableName`||t.to-t.from<20&&fE.test(e.state.sliceDoc(t.from,t.to));if(!n&&!e.explicit)return null;let r=[];for(let n=t;n;n=n.parent)sE.has(n.name)&&(r=r.concat(dE(e.state.doc,n)));return{options:r,from:n?t.from:e.pos,validFor:fE}}var hE=an.define({name:`javascript`,parser:rE.configure({props:[mn.add({IfStatement:un({except:/^\s*({|else\b)/}),TryStatement:un({except:/^\s*({|catch\b|finally\b)/}),LabeledStatement:Vt,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:tn({closing:`}`}),ArrowFunction:e=>e.baseIndent+e.unit,"TemplateString BlockComment":()=>null,"Statement Property":un({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":kt,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:`$`}}),gE={test:e=>/^JSX/.test(e.name),facet:Rt({commentTokens:{block:{open:`{/*`,close:`*/}`}}})},_E=hE.configure({dialect:`ts`},`typescript`),vE=hE.configure({dialect:`jsx`,props:[Wt.add(e=>e.isTop?[gE]:void 0)]}),yE=hE.configure({dialect:`jsx ts`,props:[Wt.add(e=>e.isTop?[gE]:void 0)]},`typescript`),bE=e=>({label:e,type:`keyword`}),xE=`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(bE),SE=xE.concat([`declare`,`implements`,`private`,`protected`,`public`].map(bE));function CE(e={}){let t=e.jsx?e.typescript?yE:vE:e.typescript?_E:hE,n=e.typescript?aE.concat(SE):iE.concat(xE);return new $t(t,[hE.data.of({autocomplete:En(pE,bn(n))}),hE.data.of({autocomplete:mE}),e.jsx?DE:[]])}function wE(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 TE(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 EE=typeof navigator==`object`&&/Android\b/.test(navigator.userAgent),DE=Dt.inputHandler.of((e,t,n,r,i)=>{if((EE?e.composing:e.compositionStarted)||e.state.readOnly||t!=n||r!=`>`&&r!=`/`||!hE.isActiveAt(e.state,t,-1))return!1;let a=i(),{state:o}=a,s=o.changeByRange(e=>{let{head:t}=e,n=mt(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=TE(o.doc,r.firstChild,t))||r.firstChild?.name==`JSXFragmentTag`)){let e=`${i}>`;return{range:W.cursor(t+e.length,-1),changes:{from:t,insert:e}}}}else if(r==`>`){let r=wE(n);if(r&&r.name==`JSXOpenTag`&&!/^\/?>|^<\//.test(o.doc.sliceString(t,t+2))&&(i=TE(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)}),OE=[`_blank`,`_self`,`_top`,`_parent`],kE=[`ascii`,`utf-8`,`utf-16`,`latin1`,`latin1`],AE=[`get`,`post`,`put`,`delete`],jE=[`application/x-www-form-urlencoded`,`multipart/form-data`,`text/plain`],ME=[`true`,`false`],$={},NE={a:{attrs:{href:null,ping:null,type:null,media:null,target:OE,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:OE}},bdi:$,bdo:$,blockquote:{attrs:{cite:null}},body:$,br:$,button:{attrs:{form:null,formaction:null,name:null,value:null,autofocus:[`autofocus`],disabled:[`autofocus`],formenctype:jE,formmethod:AE,formnovalidate:[`novalidate`],formtarget:OE,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":kE,autocomplete:[`on`,`off`],enctype:jE,method:AE,novalidate:[`novalidate`],target:OE}},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:jE,formmethod:AE,formnovalidate:[`novalidate`],formtarget:OE,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:kE,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:kE}},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:$},PE={accesskey:null,class:null,contenteditable:ME,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:ME,autocorrect:ME,autocapitalize:ME,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":ME,"aria-autocomplete":[`inline`,`list`,`both`,`none`],"aria-busy":ME,"aria-checked":[`true`,`false`,`mixed`,`undefined`],"aria-controls":null,"aria-describedby":null,"aria-disabled":ME,"aria-dropeffect":null,"aria-expanded":[`true`,`false`,`undefined`],"aria-flowto":null,"aria-grabbed":[`true`,`false`,`undefined`],"aria-haspopup":ME,"aria-hidden":ME,"aria-invalid":[`true`,`false`,`grammar`,`spelling`],"aria-label":null,"aria-labelledby":null,"aria-level":null,"aria-live":[`off`,`polite`,`assertive`],"aria-multiline":ME,"aria-multiselectable":ME,"aria-owns":null,"aria-posinset":null,"aria-pressed":[`true`,`false`,`mixed`,`undefined`],"aria-readonly":ME,"aria-relevant":null,"aria-required":ME,"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},FE=`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 FE)PE[e]=null;var IE=class{constructor(e,t){this.tags={...NE,...e},this.globalAttrs={...PE,...t},this.allTags=Object.keys(this.tags),this.globalAttrNames=Object.keys(this.globalAttrs)}};IE.default=new IE;function LE(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 RE(e,t=!1){for(;e;e=e.parent)if(e.name==`Element`)if(t)t=!1;else return e;return null}function zE(e,t,n){return n.tags[LE(e,RE(t))]?.children||n.allTags}function BE(e,t){let n=[];for(let r=RE(t);r&&!r.type.isTop;r=RE(r.parent)){let i=LE(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 VE=/^[:\-\.\w\u00b7-\uffff]*$/;function HE(e,t,n,r,i){let a=/\s*>/.test(e.sliceDoc(i,i+5))?``:`>`,o=RE(n,n.name==`StartTag`||n.name==`TagName`);return{from:r,to:i,options:zE(e.doc,o,t).map(e=>({label:e,type:`type`})).concat(BE(e.doc,n).map((e,t)=>({label:`/`+e,apply:`/`+e+a,type:`type`,boost:99-t}))),validFor:/^\/?[:\-\.\w\u00b7-\uffff]*$/}}function UE(e,t,n,r){let i=/\s*>/.test(e.sliceDoc(r,r+5))?``:`>`;return{from:n,to:r,options:BE(e.doc,t).map((e,t)=>({label:e,apply:e+i,type:`type`,boost:99-t})),validFor:VE}}function WE(e,t,n,r){let i=[],a=0;for(let r of zE(e.doc,n,t))i.push({label:`<`+r,type:`type`});for(let t of BE(e.doc,n))i.push({label:`</`+t+`>`,type:`type`,boost:99-a++});return{from:r,to:r,options:i,validFor:/^<\/?[:\-\.\w\u00b7-\uffff]*$/}}function GE(e,t,n,r,i){let a=RE(n),o=a?t.tags[LE(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:VE}}function KE(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=RE(n),i=r?t.tags[LE(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 qE(e,t){let{state:n,pos:r}=t,i=mt(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)?UE(n,i,i.from,r):HE(n,e,i,i.from,r):i.name==`StartTag`||i.name==`IncompleteTag`?HE(n,e,i,r,r):i.name==`StartCloseTag`||i.name==`IncompleteCloseTag`?UE(n,i,r,r):i.name==`OpenTag`||i.name==`SelfClosingTag`||i.name==`AttributeName`?GE(n,e,i,i.name==`AttributeName`?i.from:r,r):i.name==`Is`||i.name==`AttributeValue`||i.name==`UnquotedAttributeValue`?KE(n,e,i,i.name==`Is`?r:i.from,r):t.explicit&&(a.name==`Element`||a.name==`Text`||a.name==`Document`)?WE(n,e,i,r):null}function JE(e){return qE(IE.default,e)}function YE(e){let{extraTags:t,extraGlobalAttributes:n}=e,r=n||t?new IE(t,n):IE.default;return e=>qE(r,e)}var XE=hE.parser.configure({top:`SingleExpression`}),ZE=[{tag:`script`,attrs:e=>e.type==`text/typescript`||e.lang==`ts`,parser:_E.parser},{tag:`script`,attrs:e=>e.type==`text/babel`||e.type==`text/jsx`,parser:vE.parser},{tag:`script`,attrs:e=>e.type==`text/typescript-jsx`,parser:yE.parser},{tag:`script`,attrs(e){return/^(importmap|speculationrules|application\/(.+\+)?json)$/i.test(e.type)},parser:XE},{tag:`script`,attrs(e){return!e.type||/^(?:text|application)\/(?:x-)?(?:java|ecma)script$|^module$|^$/i.test(e.type)},parser:hE.parser},{tag:`style`,attrs(e){return(!e.lang||e.lang==`css`)&&(!e.type||/^(text\/)?(x-)?(stylesheet|css)$/i.test(e.type))},parser:bT.parser}],QE=[{name:`style`,parser:bT.parser.configure({top:`Styles`})}].concat(FE.map(e=>({name:e,parser:hE.parser}))),$E=an.define({name:`html`,parser:yw.configure({props:[mn.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}}}),Jt.add({"OpenTag CloseTag":e=>e.getChild(`TagName`)})]}),languageData:{commentTokens:{block:{open:`<!--`,close:`-->`}},indentOnInput:/^\s*<\/\w+\W$/,wordChars:`-_`}}),eD=$E.configure({wrap:Cw(ZE,QE)});function tD(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=Cw((e.nestedLanguages||[]).concat(ZE),(e.nestedAttributes||[]).concat(QE))),new $t(n?$E.configure({wrap:n,dialect:t}):t?eD.configure({dialect:t}):eD,[eD.data.of({autocomplete:YE(e)}),e.autoCloseTags===!1?[]:rD,CE().support,xT().support])}var nD=new Set(`area base br col command embed frame hr img input keygen link meta param source track wbr menuitem`.split(` `)),rD=Dt.inputHandler.of((e,t,n,r,i)=>{if(e.composing||e.state.readOnly||t!=n||r!=`>`&&r!=`/`||!eD.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=mt(o).resolveInner(n,-1),a;if(t&&r==`>`&&i.name==`EndTag`){let t=i.parent;if(t.parent?.lastChild?.name!=`CloseTag`&&(a=LE(o.doc,t.parent,n))&&!nD.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=LE(o.doc,e,n))&&!nD.has(a)){let e=n+ +(o.doc.sliceString(n,n+1)===`>`),t=`${a}>`;return{range:W.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)}),iD=Rt({commentTokens:{block:{open:`<!--`,close:`-->`}}}),aD=new Ze,oD=US.configure({props:[_n.add(e=>!e.is(`Block`)||e.is(`Document`)||sD(e)!=null||cD(e)?void 0:(e,t)=>({from:t.doc.lineAt(e.from).to,to:e.to})),aD.add(sD),mn.add({Document:()=>null}),Kt.add({Document:iD})]});function sD(e){let t=/^(?:ATX|Setext)Heading(\d)$/.exec(e.name);return t?+t[1]:void 0}function cD(e){return e.name==`OrderedList`||e.name==`BulletList`}function lD(e,t){let n=e;for(;;){let e=n.nextSibling,r;if(!e||(r=sD(e.type))!=null&&r<=t)break;n=e}return n.to}var uD=Mt.of((e,t,n)=>{for(let r=mt(e).resolveInner(n,-1);r&&!(r.from<t);r=r.parent){let e=r.type.prop(aD);if(e==null)continue;let t=lD(r,e);if(t>n)return{from:n,to:t}}return null});function dD(e){return new Ut(iD,e,[],`markdown`)}var fD=dD(oD),pD=dD(oD.configure([lC,fC,dC,pC,{props:[_n.add({Table:(e,t)=>({from:t.doc.lineAt(e.from).to,to:e.to})})]}]));function mD(e,t){return n=>{if(n&&e){let t=null;if(n=/\S*/.exec(n)[0],t=typeof e==`function`?e(n):At.matchLanguageName(e,n,!0),t instanceof At)return t.support?t.support.language.parser:on.getSkippingParser(t.load());if(t)return t.parser}return t?t.parser:null}}var hD=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(+_D(this.item,e)[2]+t):``;return this.spaceBefore+n+this.type+this.spaceAfter}};function gD(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 hD(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 hD(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 hD(i.parent,s,s+t,a[1],e,n,i))}}return r}function _D(e,t){return/^(\s*)(\d+)(?=[.)])/.exec(t.sliceString(e.from,e.from+10))}function vD(e,t,n,r=0){for(let i=-1,a=e;;){if(a.name==`ListItem`){let e=_D(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 yD(e,t){let n=/^[ \t]*/.exec(e)[0].length;if(!n||t.facet(et)!=` `)return e;let r=Qe(e,4,n),i=``;for(let e=r;e>0;)e>=4?(i+=` `,e-=4):(i+=` `,e--);return i+e.slice(n)}var bD=((e={})=>({state:t,dispatch:n})=>{let r=mt(t),{doc:i}=t,a=null,o=t.changeByRange(n=>{if(!n.empty||!pD.isActiveAt(t,n.from,-1)&&!pD.isActiveAt(t,n.from,1))return a={range:n};let o=n.from,s=i.lineAt(o),c=gD(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`&&vD(l.item,i,r,-2),e&&e.node.name==`OrderedList`&&vD(e.item,i,r),{range:W.cursor(t+n.length),changes:r}}else{let e=CD(c,t,s);return{range:W.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`&&vD(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?Qe(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=yD(p,t),SD(l.node,t.doc)&&(p=CD(c,t,s)+t.lineBreak+p),d.push({from:m,to:o,insert:t.lineBreak+p}),{range:W.cursor(m+p.length+1),changes:d}});return a?!1:(n(t.update(o,{scrollIntoView:!0,userEvent:`input`})),!0)})();function xD(e){return e.name==`QuoteMark`||e.name==`ListMark`}function SD(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 CD(e,t,n){let r=``;for(let t=0,i=e.length-2;t<=i;t++)r+=e[t].blank(t<i?Qe(n.text,4,e[t+1].from)-r.length:null,t<i);return yD(r,t)}function wD(e,t){let n=e.resolveInner(t,-1),r=t;xD(n)&&(r=n.from,n=n.parent);for(let e;e=n.childBefore(r);)if(xD(e))r=e.from;else if(e.name==`OrderedList`||e.name==`BulletList`)n=e.lastChild,r=n.to;else break;return n}var TD=[{key:`Enter`,run:bD},{key:`Backspace`,run:({state:e,dispatch:t})=>{let n=mt(e),r=null,i=e.changeByRange(t=>{let i=t.from,{doc:a}=e;if(t.empty&&pD.isActiveAt(e,t.from)){let t=a.lineAt(i),r=gD(wD(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:W.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(Qe(t.text,4,n.to)-Qe(t.text,4,n.from));return r==t.from&&(i=yD(i,e)),{range:W.cursor(r+i.length),changes:{from:r,to:t.from+n.to,insert:i}}}if(r<i)return{range:W.cursor(r),changes:{from:r,to:i}}}}}return r={range:t}});return r?!1:(t(e.update(i,{scrollIntoView:!0,userEvent:`delete`})),!0)}}],ED=tD({matchClosingTags:!1});function DD(e={}){let{codeLanguages:t,defaultCodeLanguage:n,addKeymap:r=!0,base:{parser:i}=fD,completeHTMLTags:a=!0,pasteURLAsLink:o=!0,htmlTagLanguage:s=ED}=e;if(!(i instanceof gS))throw RangeError("Base parser provided to `markdown` should be a Markdown parser");let c=e.extensions?[e.extensions]:[],l=[s.support,uD],u;o&&l.push(MD),n instanceof $t?(l.push(n.support),u=n.language):n&&(u=n);let d=t||u?mD(t,u):void 0;c.push(GS({codeParser:d,htmlParser:s.language.parser})),r&&l.push(qt.high(Yt.of(TD)));let f=dD(i.configure(c));return a&&l.push(f.data.of({autocomplete:OD})),new $t(f,l)}function OD(e){let{state:t,pos:n}=e,r=/<[:\-\.\w\u00b7-\uffff]*$/.exec(t.sliceDoc(n-25,n));if(!r)return null;let i=mt(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:AD(),validFor:/^<[:\-\.\w\u00b7-\uffff]*$/}}var kD=null;function AD(){if(kD)return kD;let e=JE(new Dn(rt.create({extensions:ED}),0,!0));return kD=e?e.options:[]}var jD=/code|horizontalrule|html|link|comment|processing|escape|entity|image|mark|url/i,MD=Dt.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),!pD.isActiveAt(t.state,n.from,1)))return!1;let i=mt(t.state),a=!1;return i.iterate({from:n.from,to:n.to,enter:e=>{(e.from>n.from||jD.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 ND(){return ND=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},ND.apply(null,arguments)}var PD=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}),[Dt.theme(i,{dark:t===`dark`}),pt(cn.define(r))]},FD={background:`#2E3235`,foreground:`#DDDDDD`,caret:`#DDDDDD`,selection:`#202325`,selectionMatch:`#202325`,gutterBackground:`#292d30`,gutterForeground:`#808080`,gutterBorder:`1px solid #ffffff10`,lineHighlight:`#B9D2FF30`},ID=[{tag:U.keyword,color:`#fda331`},{tag:[U.name,U.deleted,U.character,U.propertyName,U.macroName],color:`#b5bd68`},{tag:[U.variableName],color:`#6fb3d2`},{tag:[U.function(U.variableName)],color:`#fda331`},{tag:[U.labelName],color:`#fc6d24`},{tag:[U.color,U.constant(U.name),U.standard(U.name)],color:`#fda331`},{tag:[U.definition(U.name),U.separator],color:`#cc99cc`},{tag:[U.brace],color:`#cc99cc`},{tag:[U.annotation],color:`#fc6d24`},{tag:[U.number,U.changed,U.annotation,U.modifier,U.self,U.namespace],color:`#fda331`},{tag:[U.typeName,U.className],color:`#6fb3d2`},{tag:[U.operator,U.operatorKeyword],color:`#cc99cc`},{tag:[U.tagName],color:`#fda331`},{tag:[U.squareBracket],color:`#cc99cc`},{tag:[U.angleBracket],color:`#cc99cc`},{tag:[U.attributeName],color:`#6fb3d2`},{tag:[U.regexp],color:`#fda331`},{tag:[U.quote],color:`#DDDDDD`},{tag:[U.string],color:`#b5bd68`},{tag:U.link,color:`#6987AF`,textDecoration:`underline`,textUnderlinePosition:`under`},{tag:[U.url,U.escape,U.special(U.string)],color:`#8abeb7`},{tag:[U.meta],color:`#A54543`},{tag:[U.comment],color:`#808080`,fontStyle:`italic`},{tag:U.monospace,color:`#DDDDDD`},{tag:U.strong,fontWeight:`bold`,color:`#fda331`},{tag:U.emphasis,fontStyle:`italic`,color:`#6fb3d2`},{tag:U.strikethrough,textDecoration:`line-through`},{tag:U.heading,fontWeight:`bold`,color:`#DDDDDD`},{tag:U.special(U.heading1),fontWeight:`bold`,color:`#DDDDDD`},{tag:U.heading1,fontWeight:`bold`,color:`#DDDDDD`},{tag:[U.heading2,U.heading3,U.heading4],fontWeight:`bold`,color:`#DDDDDD`},{tag:[U.heading5,U.heading6],color:`#DDDDDD`},{tag:[U.atom,U.bool,U.special(U.variableName)],color:`#8abeb7`},{tag:[U.processingInstruction,U.inserted],color:`#8abeb7`},{tag:[U.contentSeparator],color:`#6fb3d2`},{tag:U.invalid,color:`#B9D2FF`,borderBottom:`1px dotted #fc6d24`}],LD=e=>{var{theme:t=`dark`,settings:n={},styles:r=[]}=e||{};return PD({theme:t,settings:ND({},FD,n),styles:[...ID,...r]})};LD();var RD={background:`#ffffff`,foreground:`#2e3440`,caret:`#3b4252`,selection:`#eceff4`,selectionMatch:`#e5e9f0`,gutterBackground:`#eceff4`,gutterForeground:`#2e3440`,gutterBorder:`none`,lineHighlight:`#02255f11`},zD=[{tag:U.keyword,color:`#5e81ac`},{tag:[U.name,U.deleted,U.character,U.propertyName,U.macroName],color:`#d08770`},{tag:[U.variableName],color:`#d08770`},{tag:[U.function(U.variableName)],color:`#5e81ac`},{tag:[U.labelName],color:`#81a1c1`},{tag:[U.color,U.constant(U.name),U.standard(U.name)],color:`#5e81ac`},{tag:[U.definition(U.name),U.separator],color:`#a3be8c`},{tag:[U.brace],color:`#8fbcbb`},{tag:[U.annotation],color:`#d30102`},{tag:[U.number,U.changed,U.annotation,U.modifier,U.self,U.namespace],color:`#88c0d0`},{tag:[U.typeName,U.className],color:`#ebcb8b`},{tag:[U.operator,U.operatorKeyword],color:`#a3be8c`},{tag:[U.tagName],color:`#b48ead`},{tag:[U.squareBracket],color:`#bf616a`},{tag:[U.angleBracket],color:`#d08770`},{tag:[U.attributeName],color:`#ebcb8b`},{tag:[U.regexp],color:`#5e81ac`},{tag:[U.quote],color:`#3b4252`},{tag:[U.string],color:`#d08770`},{tag:U.link,color:`#8fbcbb`,textDecoration:`underline`,textUnderlinePosition:`under`},{tag:[U.url,U.escape,U.special(U.string)],color:`#d08770`},{tag:[U.meta],color:`#88c0d0`},{tag:[U.comment],color:`#434c5e`,fontStyle:`italic`},{tag:U.strong,fontWeight:`bold`,color:`#5e81ac`},{tag:U.emphasis,fontStyle:`italic`,color:`#5e81ac`},{tag:U.strikethrough,textDecoration:`line-through`},{tag:U.heading,fontWeight:`bold`,color:`#5e81ac`},{tag:U.special(U.heading1),fontWeight:`bold`,color:`#5e81ac`},{tag:U.heading1,fontWeight:`bold`,color:`#5e81ac`},{tag:[U.heading2,U.heading3,U.heading4],fontWeight:`bold`,color:`#5e81ac`},{tag:[U.heading5,U.heading6],color:`#5e81ac`},{tag:[U.atom,U.bool,U.special(U.variableName)],color:`#d08770`},{tag:[U.processingInstruction,U.inserted],color:`#8fbcbb`},{tag:[U.contentSeparator],color:`#ebcb8b`},{tag:U.invalid,color:`#434c5e`,borderBottom:`1px dotted #d30102`}],BD=e=>{var{theme:t=`light`,settings:n={},styles:r=[]}=e||{};return PD({theme:t,settings:ND({},RD,n),styles:[...zD,...r]})};BD();var VD=e=>{let{state:t}=e,n=t.doc.lineAt(t.selection.main.from),r=KD(e.state,n.from);return r.line?UD(e):r.block?GD(e):!1};function HD(e,t){return({state:n,dispatch:r})=>{if(n.readOnly)return!1;let i=e(t,n);return i?(r(n.update(i)),!0):!1}}var UD=HD(ZD,0),WD=HD(XD,0),GD=HD((e,t)=>XD(e,t,YD(t)),0);function KD(e,t){let n=e.languageDataAt(`commentTokens`,t,1);return n.length?n[0]:{}}var qD=50;function JD(e,{open:t,close:n},r,i){let a=e.sliceDoc(r-qD,r),o=e.sliceDoc(i,i+qD),s=/\s*$/.exec(a)[0].length,c=/^\s*/.exec(o)[0].length,l=a.length-s;if(a.slice(l-t.length,l)==t&&o.slice(c,c+n.length)==n)return{open:{pos:r-s,margin:s&&1},close:{pos:i+c,margin:c&&1}};let u,d;i-r<=2*qD?u=d=e.sliceDoc(r,i):(u=e.sliceDoc(r,r+qD),d=e.sliceDoc(i-qD,i));let f=/^\s*/.exec(u)[0].length,p=/\s*$/.exec(d)[0].length,m=d.length-p-n.length;return u.slice(f,f+t.length)==t&&d.slice(m,m+n.length)==n?{open:{pos:r+f+t.length,margin:+!!/\s/.test(u.charAt(f+t.length))},close:{pos:i-p-n.length,margin:+!!/\s/.test(d.charAt(m-1))}}:null}function YD(e){let t=[];for(let n of e.selection.ranges){let r=e.doc.lineAt(n.from),i=n.to<=r.to?r:e.doc.lineAt(n.to);i.from>r.from&&i.from==n.to&&(i=n.to==r.to+1?r:e.doc.lineAt(n.to-1));let a=t.length-1;a>=0&&t[a].to>r.from?t[a].to=i.to:t.push({from:r.from+/^\s*/.exec(r.text)[0].length,to:i.to})}return t}function XD(e,t,n=t.selection.ranges){let r=n.map(e=>KD(t,e.from).block);if(!r.every(e=>e))return null;let i=n.map((e,n)=>JD(t,r[n],e.from,e.to));if(e!=2&&!i.every(e=>e))return{changes:t.changes(n.map((e,t)=>i[t]?[]:[{from:e.from,insert:r[t].open+` `},{from:e.to,insert:` `+r[t].close}]))};if(e!=1&&i.some(e=>e)){let e=[];for(let t=0,n;t<i.length;t++)if(n=i[t]){let i=r[t],{open:a,close:o}=n;e.push({from:a.pos-i.open.length,to:a.pos+a.margin},{from:o.pos-o.margin,to:o.pos+i.close.length})}return{changes:e}}return null}function ZD(e,t,n=t.selection.ranges){let r=[],i=-1;ranges:for(let{from:e,to:a}of n){let n=r.length,o=1e9,s;for(let n=e;n<=a;){let c=t.doc.lineAt(n);if(s==null&&(s=KD(t,c.from).line,!s))continue ranges;if(c.from>i&&(e==a||a>c.from)){i=c.from;let e=/^\s*/.exec(c.text)[0].length,t=e==c.length,n=c.text.slice(e,e+s.length)==s?e:-1;e<c.text.length&&e<o&&(o=e),r.push({line:c,comment:n,token:s,indent:e,empty:t,single:!1})}n=c.to+1}if(o<1e9)for(let e=n;e<r.length;e++)r[e].indent<r[e].line.text.length&&(r[e].indent=o);r.length==n+1&&(r[n].single=!0)}if(e!=2&&r.some(e=>e.comment<0&&(!e.empty||e.single))){let e=[];for(let{line:t,token:n,indent:i,empty:a,single:o}of r)(o||!a)&&e.push({from:t.from+i,insert:n+` `});let n=t.changes(e);return{changes:n,selection:t.selection.map(n,1)}}else if(e!=1&&r.some(e=>e.comment>=0)){let e=[];for(let{line:t,comment:n,token:i}of r)if(n>=0){let r=t.from+n,a=r+i.length;t.text[a-t.from]==` `&&a++,e.push({from:r,to:a})}return{changes:e}}return null}var QD=Nt.define(),$D=Nt.define(),eO=tt.define(),tO=tt.define({combine(e){return yn(e,{minDepth:100,newGroupDelay:500,joinToEvent:(e,t)=>t},{minDepth:Math.max,newGroupDelay:Math.min,joinToEvent:(e,t)=>(n,r)=>e(n,r)||t(n,r)})}}),nO=_t.define({create(){return xO.empty},update(e,t){let n=t.state.facet(tO),r=t.annotation(QD);if(r){let i=lO.fromTransaction(t,r.selection),a=r.side,o=a==0?e.undone:e.done;return o=i?uO(o,o.length,n.minDepth,i):gO(o,t.startState.selection),new xO(a==0?r.rest:o,a==0?o:r.rest)}let i=t.annotation($D);if((i==`full`||i==`before`)&&(e=e.isolate()),t.annotation(lt.addToHistory)===!1)return t.changes.empty?e:e.addMapping(t.changes.desc);let a=lO.fromTransaction(t),o=t.annotation(lt.time),s=t.annotation(lt.userEvent);return a?e=e.addChanges(a,o,s,n,t):t.selection&&(e=e.addSelection(t.startState.selection,o,s,n.newGroupDelay)),(i==`full`||i==`after`)&&(e=e.isolate()),e},toJSON(e){return{done:e.done.map(e=>e.toJSON()),undone:e.undone.map(e=>e.toJSON())}},fromJSON(e){return new xO(e.done.map(lO.fromJSON),e.undone.map(lO.fromJSON))}});function rO(e={}){return[nO,tO.of(e),Dt.domEventHandlers({beforeinput(e,t){let n=e.inputType==`historyUndo`?aO:e.inputType==`historyRedo`?oO:null;return n?(e.preventDefault(),n(t)):!1}})]}function iO(e,t){return function({state:n,dispatch:r}){if(!t&&n.readOnly)return!1;let i=n.field(nO,!1);if(!i)return!1;let a=i.pop(e,n,t);return a?(r(a),!0):!1}}var aO=iO(0,!1),oO=iO(1,!1),sO=iO(0,!0),cO=iO(1,!0),lO=class e{constructor(e,t,n,r,i){this.changes=e,this.effects=t,this.mapped=n,this.startSelection=r,this.selectionsAfter=i}setSelAfter(t){return new e(this.changes,this.effects,this.mapped,this.startSelection,t)}toJSON(){return{changes:this.changes?.toJSON(),mapped:this.mapped?.toJSON(),startSelection:this.startSelection?.toJSON(),selectionsAfter:this.selectionsAfter.map(e=>e.toJSON())}}static fromJSON(t){return new e(t.changes&&xt.fromJSON(t.changes),[],t.mapped&&gn.fromJSON(t.mapped),t.startSelection&&W.fromJSON(t.startSelection),t.selectionsAfter.map(W.fromJSON))}static fromTransaction(t,n){let r=mO;for(let e of t.startState.facet(eO)){let n=e(t);n.length&&(r=r.concat(n))}return!r.length&&t.changes.empty?null:new e(t.changes.invert(t.startState.doc),r,void 0,n||t.startState.selection,mO)}static selection(t){return new e(void 0,mO,void 0,void 0,t)}};function uO(e,t,n,r){let i=t+1>n+20?t-n-1:0,a=e.slice(i,t);return a.push(r),a}function dO(e,t){let n=[],r=!1;return e.iterChangedRanges((e,t)=>n.push(e,t)),t.iterChangedRanges((e,t,i,a)=>{for(let e=0;e<n.length;){let t=n[e++],o=n[e++];a>=t&&i<=o&&(r=!0)}}),r}function fO(e,t){return e.ranges.length==t.ranges.length&&e.ranges.filter((e,n)=>e.empty!=t.ranges[n].empty).length===0}function pO(e,t){return e.length?t.length?e.concat(t):e:t}var mO=[],hO=200;function gO(e,t){if(e.length){let n=e[e.length-1],r=n.selectionsAfter.slice(Math.max(0,n.selectionsAfter.length-hO));return r.length&&r[r.length-1].eq(t)?e:(r.push(t),uO(e,e.length-1,1e9,n.setSelAfter(r)))}else return[lO.selection([t])]}function _O(e){let t=e[e.length-1],n=e.slice();return n[e.length-1]=t.setSelAfter(t.selectionsAfter.slice(0,t.selectionsAfter.length-1)),n}function vO(e,t){if(!e.length)return e;let n=e.length,r=mO;for(;n;){let i=yO(e[n-1],t,r);if(i.changes&&!i.changes.empty||i.effects.length){let t=e.slice(0,n);return t[n-1]=i,t}else t=i.mapped,n--,r=i.selectionsAfter}return r.length?[lO.selection(r)]:mO}function yO(e,t,n){let r=pO(e.selectionsAfter.length?e.selectionsAfter.map(e=>e.map(t)):mO,n);if(!e.changes)return lO.selection(r);let i=e.changes.map(t),a=t.mapDesc(e.changes,!0),o=e.mapped?e.mapped.composeDesc(a):a;return new lO(i,ht.mapEffects(e.effects,t),o,e.startSelection.map(a),r)}var bO=/^(input\.type|delete)($|\.)/,xO=class e{constructor(e,t,n=0,r=void 0){this.done=e,this.undone=t,this.prevTime=n,this.prevUserEvent=r}isolate(){return this.prevTime?new e(this.done,this.undone):this}addChanges(t,n,r,i,a){let o=this.done,s=o[o.length-1];return o=s&&s.changes&&!s.changes.empty&&t.changes&&(!r||bO.test(r))&&(!s.selectionsAfter.length&&n-this.prevTime<i.newGroupDelay&&i.joinToEvent(a,dO(s.changes,t.changes))||r==`input.type.compose`)?uO(o,o.length-1,i.minDepth,new lO(t.changes.compose(s.changes),pO(ht.mapEffects(t.effects,s.changes),s.effects),s.mapped,s.startSelection,mO)):uO(o,o.length,i.minDepth,t),new e(o,mO,n,r)}addSelection(t,n,r,i){let a=this.done.length?this.done[this.done.length-1].selectionsAfter:mO;return a.length>0&&n-this.prevTime<i&&r==this.prevUserEvent&&r&&/^select($|\.)/.test(r)&&fO(a[a.length-1],t)?this:new e(gO(this.done,t),this.undone,n,r)}addMapping(t){return new e(vO(this.done,t),vO(this.undone,t),this.prevTime,this.prevUserEvent)}pop(e,t,n){let r=e==0?this.done:this.undone;if(r.length==0)return null;let i=r[r.length-1],a=i.selectionsAfter[0]||(i.startSelection?i.startSelection.map(i.changes.invertedDesc,1):t.selection);if(n&&i.selectionsAfter.length)return t.update({selection:i.selectionsAfter[i.selectionsAfter.length-1],annotations:QD.of({side:e,rest:_O(r),selection:a}),userEvent:e==0?`select.undo`:`select.redo`,scrollIntoView:!0});if(i.changes){let n=r.length==1?mO:r.slice(0,r.length-1);return i.mapped&&(n=vO(n,i.mapped)),t.update({changes:i.changes,selection:i.startSelection,effects:i.effects,annotations:QD.of({side:e,rest:n,selection:a}),filter:!1,userEvent:e==0?`undo`:`redo`,scrollIntoView:!0})}else return null}};xO.empty=new xO(mO,mO);var SO=[{key:`Mod-z`,run:aO,preventDefault:!0},{key:`Mod-y`,mac:`Mod-Shift-z`,run:oO,preventDefault:!0},{linux:`Ctrl-Shift-z`,run:oO,preventDefault:!0},{key:`Mod-u`,run:sO,preventDefault:!0},{key:`Alt-u`,mac:`Mod-Shift-u`,run:cO,preventDefault:!0}];function CO(e,t){return W.create(e.ranges.map(t),e.mainIndex)}function wO(e,t){return e.update({selection:t,scrollIntoView:!0,userEvent:`select`})}function TO({state:e,dispatch:t},n){let r=CO(e.selection,n);return r.eq(e.selection,!0)?!1:(t(wO(e,r)),!0)}function EO(e,t){return W.cursor(t?e.to:e.from)}function DO(e,t){return TO(e,n=>n.empty?e.moveByChar(n,t):EO(n,t))}function OO(e){return e.textDirectionAt(e.state.selection.main.head)==ut.LTR}var kO=e=>DO(e,!OO(e)),AO=e=>DO(e,OO(e));function jO(e,t){return TO(e,n=>n.empty?e.moveByGroup(n,t):EO(n,t))}var MO=e=>jO(e,!OO(e)),NO=e=>jO(e,OO(e));typeof Intl<`u`&&Intl.Segmenter;function PO(e,t,n){if(t.type.prop(n))return!0;let r=t.to-t.from;return r&&(r>2||/[^\s,.;:]/.test(e.sliceDoc(t.from,t.to)))||t.firstChild}function FO(e,t,n){let r=mt(e).resolveInner(t.head),i=n?Ze.closedBy:Ze.openedBy;for(let a=t.head;;){let t=n?r.childAfter(a):r.childBefore(a);if(!t)break;PO(e,t,i)?r=t:a=n?t.to:t.from}let a=r.type.prop(i),o,s;return s=a&&(o=n?Xe(e,r.from,1):Xe(e,r.to,-1))&&o.matched?n?o.end.to:o.end.from:n?r.to:r.from,W.cursor(s,n?-1:1)}var IO=e=>TO(e,t=>FO(e.state,t,!OO(e))),LO=e=>TO(e,t=>FO(e.state,t,OO(e)));function RO(e,t){return TO(e,n=>{if(!n.empty)return EO(n,t);let r=e.moveVertically(n,t);return r.head==n.head?e.moveToLineBoundary(n,t):r})}var zO=e=>RO(e,!1),BO=e=>RO(e,!0);function VO(e){let t=e.scrollDOM.clientHeight<e.scrollDOM.scrollHeight-2,n=0,r=0,i;if(t){for(let t of e.state.facet(Dt.scrollMargins)){let i=t(e);i?.top&&(n=Math.max(i?.top,n)),i?.bottom&&(r=Math.max(i?.bottom,r))}i=e.scrollDOM.clientHeight-n-r}else i=(e.dom.ownerDocument.defaultView||window).innerHeight;return{marginTop:n,marginBottom:r,selfScroll:t,height:Math.max(e.defaultLineHeight,i-5)}}function HO(e,t){let n=VO(e),{state:r}=e,i=CO(r.selection,r=>r.empty?e.moveVertically(r,t,n.height):EO(r,t));if(i.eq(r.selection))return!1;let a;if(n.selfScroll){let t=e.coordsAtPos(r.selection.main.head),o=e.scrollDOM.getBoundingClientRect(),s=o.top+n.marginTop,c=o.bottom-n.marginBottom;t&&t.top>s&&t.bottom<c&&(a=Dt.scrollIntoView(i.main.head,{y:`start`,yMargin:t.top-s}))}return e.dispatch(wO(r,i),{effects:a}),!0}var UO=e=>HO(e,!1),WO=e=>HO(e,!0);function GO(e,t,n){let r=e.lineBlockAt(t.head),i=e.moveToLineBoundary(t,n);if(i.head==t.head&&i.head!=(n?r.to:r.from)&&(i=e.moveToLineBoundary(t,n,!1)),!n&&i.head==r.from&&r.length){let n=/^\s*/.exec(e.state.sliceDoc(r.from,Math.min(r.from+100,r.to)))[0].length;n&&t.head!=r.from+n&&(i=W.cursor(r.from+n))}return i}var KO=e=>TO(e,t=>GO(e,t,!0)),qO=e=>TO(e,t=>GO(e,t,!1)),JO=e=>TO(e,t=>GO(e,t,!OO(e))),YO=e=>TO(e,t=>GO(e,t,OO(e))),XO=e=>TO(e,t=>W.cursor(e.lineBlockAt(t.head).from,1)),ZO=e=>TO(e,t=>W.cursor(e.lineBlockAt(t.head).to,-1));function QO(e,t,n){let r=!1,i=CO(e.selection,t=>{let i=Xe(e,t.head,-1)||Xe(e,t.head,1)||t.head>0&&Xe(e,t.head-1,1)||t.head<e.doc.length&&Xe(e,t.head+1,-1);if(!i||!i.end)return t;r=!0;let a=i.start.from==t.head?i.end.to:i.end.from;return n?W.range(t.anchor,a):W.cursor(a)});return r?(t(wO(e,i)),!0):!1}var $O=({state:e,dispatch:t})=>QO(e,t,!1);function ek(e,t){let n=CO(e.state.selection,e=>{let n=t(e);return W.range(e.anchor,n.head,n.goalColumn,n.bidiLevel||void 0,n.assoc)});return n.eq(e.state.selection)?!1:(e.dispatch(wO(e.state,n)),!0)}function tk(e,t){return ek(e,n=>e.moveByChar(n,t))}var nk=e=>tk(e,!OO(e)),rk=e=>tk(e,OO(e));function ik(e,t){return ek(e,n=>e.moveByGroup(n,t))}var ak=e=>ik(e,!OO(e)),ok=e=>ik(e,OO(e)),sk=e=>ek(e,t=>FO(e.state,t,!OO(e))),ck=e=>ek(e,t=>FO(e.state,t,OO(e)));function lk(e,t){return ek(e,n=>e.moveVertically(n,t))}var uk=e=>lk(e,!1),dk=e=>lk(e,!0);function fk(e,t){return ek(e,n=>e.moveVertically(n,t,VO(e).height))}var pk=e=>fk(e,!1),mk=e=>fk(e,!0),hk=e=>ek(e,t=>GO(e,t,!0)),gk=e=>ek(e,t=>GO(e,t,!1)),_k=e=>ek(e,t=>GO(e,t,!OO(e))),vk=e=>ek(e,t=>GO(e,t,OO(e))),yk=e=>ek(e,t=>W.cursor(e.lineBlockAt(t.head).from)),bk=e=>ek(e,t=>W.cursor(e.lineBlockAt(t.head).to)),xk=({state:e,dispatch:t})=>(t(wO(e,{anchor:0})),!0),Sk=({state:e,dispatch:t})=>(t(wO(e,{anchor:e.doc.length})),!0),Ck=({state:e,dispatch:t})=>(t(wO(e,{anchor:e.selection.main.anchor,head:0})),!0),wk=({state:e,dispatch:t})=>(t(wO(e,{anchor:e.selection.main.anchor,head:e.doc.length})),!0),Tk=({state:e,dispatch:t})=>(t(e.update({selection:{anchor:0,head:e.doc.length},userEvent:`select`})),!0),Ek=({state:e,dispatch:t})=>{let n=Gk(e).map(({from:t,to:n})=>W.range(t,Math.min(n+1,e.doc.length)));return t(e.update({selection:W.create(n),userEvent:`select`})),!0},Dk=({state:e,dispatch:t})=>{let n=CO(e.selection,t=>{let n=mt(e),r=n.resolveStack(t.from,1);if(t.empty){let e=n.resolveStack(t.from,-1);e.node.from>=r.node.from&&e.node.to<=r.node.to&&(r=e)}for(let e=r;e;e=e.next){let{node:n}=e;if((n.from<t.from&&n.to>=t.to||n.to>t.to&&n.from<=t.from)&&e.next)return W.range(n.to,n.from)}return t});return n.eq(e.selection)?!1:(t(wO(e,n)),!0)};function Ok(e,t){let{state:n}=e,r=n.selection,i=n.selection.ranges.slice();for(let r of n.selection.ranges){let a=n.doc.lineAt(r.head);if(t?a.to<e.state.doc.length:a.from>0)for(let n=r;;){let r=e.moveVertically(n,t);if(r.head<a.from||r.head>a.to){i.some(e=>e.head==r.head)||i.push(r);break}else if(r.head==n.head)break;else n=r}}return i.length==r.ranges.length?!1:(e.dispatch(wO(n,W.create(i,i.length-1))),!0)}var kk=e=>Ok(e,!1),Ak=e=>Ok(e,!0),jk=({state:e,dispatch:t})=>{let n=e.selection,r=null;return n.ranges.length>1?r=W.create([n.main]):n.main.empty||(r=W.create([W.cursor(n.main.head)])),r?(t(wO(e,r)),!0):!1};function Mk(e,t){if(e.state.readOnly)return!1;let n=`delete.selection`,{state:r}=e,i=r.changeByRange(r=>{let{from:i,to:a}=r;if(i==a){let o=t(r);o<i?(n=`delete.backward`,o=Nk(e,o,!1)):o>i&&(n=`delete.forward`,o=Nk(e,o,!0)),i=Math.min(i,o),a=Math.max(a,o)}else i=Nk(e,i,!1),a=Nk(e,a,!0);return i==a?{range:r}:{changes:{from:i,to:a},range:W.cursor(i,i<r.head?-1:1)}});return i.changes.empty?!1:(e.dispatch(r.update(i,{scrollIntoView:!0,userEvent:n,effects:n==`delete.selection`?Dt.announce.of(r.phrase(`Selection deleted`)):void 0})),!0)}function Nk(e,t,n){if(e instanceof Dt)for(let r of e.state.facet(Dt.atomicRanges).map(t=>t(e)))r.between(t,t,(e,r)=>{e<t&&r>t&&(t=n?r:e)});return t}var Pk=(e,t,n)=>Mk(e,r=>{let i=r.from,{state:a}=e,o=a.doc.lineAt(i),s,c;if(n&&!t&&i>o.from&&i<o.from+200&&!/[^ \t]/.test(s=o.text.slice(0,i-o.from))){if(s[s.length-1]==` `)return i-1;let e=Qe(s,a.tabSize)%hn(a)||hn(a);for(let t=0;t<e&&s[s.length-1-t]==` `;t++)i--;c=i}else c=Tt(o.text,i-o.from,t,t)+o.from,c==i&&o.number!=(t?a.doc.lines:1)?c+=t?1:-1:!t&&/[\ufe00-\ufe0f]/.test(o.text.slice(c-o.from,i-o.from))&&(c=Tt(o.text,c-o.from,!1,!1)+o.from);return c}),Fk=e=>Pk(e,!1,!0),Ik=e=>Pk(e,!0,!1),Lk=(e,t)=>Mk(e,n=>{let r=n.head,{state:i}=e,a=i.doc.lineAt(r),o=i.charCategorizer(r);for(let e=null;;){if(r==(t?a.to:a.from)){r==n.head&&a.number!=(t?i.doc.lines:1)&&(r+=t?1:-1);break}let s=Tt(a.text,r-a.from,t)+a.from,c=a.text.slice(Math.min(r,s)-a.from,Math.max(r,s)-a.from),l=o(c);if(e!=null&&l!=e)break;(c!=` `||r!=n.head)&&(e=l),r=s}return r}),Rk=e=>Lk(e,!1),zk=e=>Lk(e,!0),Bk=e=>Mk(e,t=>{let n=e.lineBlockAt(t.head).to;return t.head<n?n:Math.min(e.state.doc.length,t.head+1)}),Vk=e=>Mk(e,t=>{let n=e.moveToLineBoundary(t,!1).head;return t.head>n?n:Math.max(0,t.head-1)}),Hk=e=>Mk(e,t=>{let n=e.moveToLineBoundary(t,!0).head;return t.head<n?n:Math.min(e.state.doc.length,t.head+1)}),Uk=({state:e,dispatch:t})=>{if(e.readOnly)return!1;let n=e.changeByRange(e=>({changes:{from:e.from,to:e.to,insert:it.of([``,``])},range:W.cursor(e.from)}));return t(e.update(n,{scrollIntoView:!0,userEvent:`input`})),!0},Wk=({state:e,dispatch:t})=>{if(e.readOnly)return!1;let n=e.changeByRange(t=>{if(!t.empty||t.from==0||t.from==e.doc.length)return{range:t};let n=t.from,r=e.doc.lineAt(n),i=n==r.from?n-1:Tt(r.text,n-r.from,!1)+r.from,a=n==r.to?n+1:Tt(r.text,n-r.from,!0)+r.from;return{changes:{from:i,to:a,insert:e.doc.slice(n,a).append(e.doc.slice(i,n))},range:W.cursor(a)}});return n.changes.empty?!1:(t(e.update(n,{scrollIntoView:!0,userEvent:`move.character`})),!0)};function Gk(e){let t=[],n=-1;for(let r of e.selection.ranges){let i=e.doc.lineAt(r.from),a=e.doc.lineAt(r.to);if(!r.empty&&r.to==a.from&&(a=e.doc.lineAt(r.to-1)),n>=i.number){let e=t[t.length-1];e.to=a.to,e.ranges.push(r)}else t.push({from:i.from,to:a.to,ranges:[r]});n=a.number+1}return t}function Kk(e,t,n){if(e.readOnly)return!1;let r=[],i=[];for(let t of Gk(e)){if(n?t.to==e.doc.length:t.from==0)continue;let a=e.doc.lineAt(n?t.to+1:t.from-1),o=a.length+1;if(n){r.push({from:t.to,to:a.to},{from:t.from,insert:a.text+e.lineBreak});for(let n of t.ranges)i.push(W.range(Math.min(e.doc.length,n.anchor+o),Math.min(e.doc.length,n.head+o)))}else{r.push({from:a.from,to:t.from},{from:t.to,insert:e.lineBreak+a.text});for(let e of t.ranges)i.push(W.range(e.anchor-o,e.head-o))}}return r.length?(t(e.update({changes:r,scrollIntoView:!0,selection:W.create(i,e.selection.mainIndex),userEvent:`move.line`})),!0):!1}var qk=({state:e,dispatch:t})=>Kk(e,t,!1),Jk=({state:e,dispatch:t})=>Kk(e,t,!0);function Yk(e,t,n){if(e.readOnly)return!1;let r=[];for(let t of Gk(e))n?r.push({from:t.from,insert:e.doc.slice(t.from,t.to)+e.lineBreak}):r.push({from:t.to,insert:e.lineBreak+e.doc.slice(t.from,t.to)});let i=e.changes(r);return t(e.update({changes:i,selection:e.selection.map(i,n?1:-1),scrollIntoView:!0,userEvent:`input.copyline`})),!0}var Xk=({state:e,dispatch:t})=>Yk(e,t,!1),Zk=({state:e,dispatch:t})=>Yk(e,t,!0),Qk=e=>{if(e.state.readOnly)return!1;let{state:t}=e,n=t.changes(Gk(t).map(({from:e,to:n})=>(e>0?e--:n<t.doc.length&&n++,{from:e,to:n}))),r=CO(t.selection,t=>{let n;if(e.lineWrapping){let r=e.lineBlockAt(t.head),i=e.coordsAtPos(t.head,t.assoc||1);i&&(n=r.bottom+e.documentTop-i.bottom+e.defaultLineHeight/2)}return e.moveVertically(t,!0,n)}).map(n);return e.dispatch({changes:n,selection:r,scrollIntoView:!0,userEvent:`delete.line`}),!0};function $k(e,t){if(/\(\)|\[\]|\{\}/.test(e.sliceDoc(t-1,t+1)))return{from:t,to:t};let n=mt(e).resolveInner(t),r=n.childBefore(t),i=n.childAfter(t),a;return r&&i&&r.to<=t&&i.from>=t&&(a=r.type.prop(Ze.closedBy))&&a.indexOf(i.name)>-1&&e.doc.lineAt(r.to).from==e.doc.lineAt(i.from).from&&!/\S/.test(e.sliceDoc(r.to,i.from))?{from:r.to,to:i.from}:null}var eA=nA(!1),tA=nA(!0);function nA(e){return({state:t,dispatch:n})=>{if(t.readOnly)return!1;let r=t.changeByRange(n=>{let{from:r,to:i}=n,a=t.doc.lineAt(r),o=!e&&r==i&&$k(t,r);e&&(r=i=(i<=a.to?a:t.doc.lineAt(i)).to);let s=new Zt(t,{simulateBreak:r,simulateDoubleBreak:!!o}),c=bt(s,r);for(c??=Qe(/^\s*/.exec(t.doc.lineAt(r).text)[0],t.tabSize);i<a.to&&/\s/.test(a.text[i-a.from]);)i++;o?{from:r,to:i}=o:r>a.from&&r<a.from+100&&!/\S/.test(a.text.slice(0,r))&&(r=a.from);let l=[``,nt(t,c)];return o&&l.push(nt(t,s.lineIndent(a.from,-1))),{changes:{from:r,to:i,insert:it.of(l)},range:W.cursor(r+1+l[1].length)}});return n(t.update(r,{scrollIntoView:!0,userEvent:`input`})),!0}}function rA(e,t){let n=-1;return e.changeByRange(r=>{let i=[];for(let a=r.from;a<=r.to;){let o=e.doc.lineAt(a);o.number>n&&(r.empty||r.to>o.from)&&(t(o,i,r),n=o.number),a=o.to+1}let a=e.changes(i);return{changes:i,range:W.range(a.mapPos(r.anchor,1),a.mapPos(r.head,1))}})}var iA=({state:e,dispatch:t})=>{if(e.readOnly)return!1;let n=Object.create(null),r=new Zt(e,{overrideIndentation:e=>n[e]??-1}),i=rA(e,(t,i,a)=>{let o=bt(r,t.from);if(o==null)return;/\S/.test(t.text)||(o=0);let s=/^\s*/.exec(t.text)[0],c=nt(e,o);(s!=c||a.from<t.from+s.length)&&(n[t.from]=o,i.push({from:t.from,to:t.from+s.length,insert:c}))});return i.changes.empty||t(e.update(i,{userEvent:`indent`})),!0},aA=({state:e,dispatch:t})=>e.readOnly?!1:(t(e.update(rA(e,(t,n)=>{n.push({from:t.from,insert:e.facet(et)})}),{userEvent:`input.indent`})),!0),oA=({state:e,dispatch:t})=>e.readOnly?!1:(t(e.update(rA(e,(t,n)=>{let r=/^\s*/.exec(t.text)[0];if(!r)return;let i=Qe(r,e.tabSize),a=0,o=nt(e,Math.max(0,i-hn(e)));for(;a<r.length&&a<o.length&&r.charCodeAt(a)==o.charCodeAt(a);)a++;n.push({from:t.from+a,to:t.from+r.length,insert:o.slice(a)})}),{userEvent:`delete.dedent`})),!0),sA=e=>(e.setTabFocusMode(),!0),cA=[{key:`Ctrl-b`,run:kO,shift:nk,preventDefault:!0},{key:`Ctrl-f`,run:AO,shift:rk},{key:`Ctrl-p`,run:zO,shift:uk},{key:`Ctrl-n`,run:BO,shift:dk},{key:`Ctrl-a`,run:XO,shift:yk},{key:`Ctrl-e`,run:ZO,shift:bk},{key:`Ctrl-d`,run:Ik},{key:`Ctrl-h`,run:Fk},{key:`Ctrl-k`,run:Bk},{key:`Ctrl-Alt-h`,run:Rk},{key:`Ctrl-o`,run:Uk},{key:`Ctrl-t`,run:Wk},{key:`Ctrl-v`,run:WO}],lA=[{key:`ArrowLeft`,run:kO,shift:nk,preventDefault:!0},{key:`Mod-ArrowLeft`,mac:`Alt-ArrowLeft`,run:MO,shift:ak,preventDefault:!0},{mac:`Cmd-ArrowLeft`,run:JO,shift:_k,preventDefault:!0},{key:`ArrowRight`,run:AO,shift:rk,preventDefault:!0},{key:`Mod-ArrowRight`,mac:`Alt-ArrowRight`,run:NO,shift:ok,preventDefault:!0},{mac:`Cmd-ArrowRight`,run:YO,shift:vk,preventDefault:!0},{key:`ArrowUp`,run:zO,shift:uk,preventDefault:!0},{mac:`Cmd-ArrowUp`,run:xk,shift:Ck},{mac:`Ctrl-ArrowUp`,run:UO,shift:pk},{key:`ArrowDown`,run:BO,shift:dk,preventDefault:!0},{mac:`Cmd-ArrowDown`,run:Sk,shift:wk},{mac:`Ctrl-ArrowDown`,run:WO,shift:mk},{key:`PageUp`,run:UO,shift:pk},{key:`PageDown`,run:WO,shift:mk},{key:`Home`,run:qO,shift:gk,preventDefault:!0},{key:`Mod-Home`,run:xk,shift:Ck},{key:`End`,run:KO,shift:hk,preventDefault:!0},{key:`Mod-End`,run:Sk,shift:wk},{key:`Enter`,run:eA,shift:eA},{key:`Mod-a`,run:Tk},{key:`Backspace`,run:Fk,shift:Fk,preventDefault:!0},{key:`Delete`,run:Ik,preventDefault:!0},{key:`Mod-Backspace`,mac:`Alt-Backspace`,run:Rk,preventDefault:!0},{key:`Mod-Delete`,mac:`Alt-Delete`,run:zk,preventDefault:!0},{mac:`Mod-Backspace`,run:Vk,preventDefault:!0},{mac:`Mod-Delete`,run:Hk,preventDefault:!0}].concat(cA.map(e=>({mac:e.key,run:e.run,shift:e.shift}))),uA=[{key:`Alt-ArrowLeft`,mac:`Ctrl-ArrowLeft`,run:IO,shift:sk},{key:`Alt-ArrowRight`,mac:`Ctrl-ArrowRight`,run:LO,shift:ck},{key:`Alt-ArrowUp`,run:qk},{key:`Shift-Alt-ArrowUp`,run:Xk},{key:`Alt-ArrowDown`,run:Jk},{key:`Shift-Alt-ArrowDown`,run:Zk},{key:`Mod-Alt-ArrowUp`,run:kk},{key:`Mod-Alt-ArrowDown`,run:Ak},{key:`Escape`,run:jk},{key:`Mod-Enter`,run:tA},{key:`Alt-l`,mac:`Ctrl-l`,run:Ek},{key:`Mod-i`,run:Dk,preventDefault:!0},{key:`Mod-[`,run:oA},{key:`Mod-]`,run:aA},{key:`Mod-Alt-\\`,run:iA},{key:`Shift-Mod-k`,run:Qk},{key:`Shift-Mod-\\`,run:$O},{key:`Mod-/`,run:VD},{key:`Alt-A`,run:WD},{key:`Ctrl-m`,mac:`Shift-Alt-m`,run:sA}].concat(lA),dA={key:`Tab`,run:aA,shift:oA},fA=typeof String.prototype.normalize==`function`?e=>e.normalize(`NFKD`):e=>e,pA=class{constructor(e,t,n=0,r=e.length,i,a){this.test=a,this.value={from:0,to:0},this.done=!1,this.matches=[],this.buffer=``,this.bufferPos=0,this.iter=e.iterRange(n,r),this.bufferStart=n,this.normalize=i?e=>i(fA(e)):fA,this.query=this.normalize(t)}peek(){if(this.bufferPos==this.buffer.length){if(this.bufferStart+=this.buffer.length,this.iter.next(),this.iter.done)return-1;this.bufferPos=0,this.buffer=this.iter.value}return ft(this.buffer,this.bufferPos)}next(){for(;this.matches.length;)this.matches.pop();return this.nextOverlapping()}nextOverlapping(){for(;;){let e=this.peek();if(e<0)return this.done=!0,this;let t=st(e),n=this.bufferStart+this.bufferPos;this.bufferPos+=yt(e);let r=this.normalize(t);if(r.length)for(let e=0,i=n;;e++){let a=r.charCodeAt(e),o=this.match(a,i,this.bufferPos+this.bufferStart);if(e==r.length-1){if(o)return this.value=o,this;break}i==n&&e<t.length&&t.charCodeAt(e)==a&&i++}}}match(e,t,n){let r=null;for(let t=0;t<this.matches.length;t+=2){let i=this.matches[t],a=!1;this.query.charCodeAt(i)==e&&(i==this.query.length-1?r={from:this.matches[t+1],to:n}:(this.matches[t]++,a=!0)),a||(this.matches.splice(t,2),t-=2)}return this.query.charCodeAt(0)==e&&(this.query.length==1?r={from:t,to:n}:this.matches.push(1,t)),r&&this.test&&!this.test(r.from,r.to,this.buffer,this.bufferStart)&&(r=null),r}};typeof Symbol<`u`&&(pA.prototype[Symbol.iterator]=function(){return this});var mA={from:-1,to:-1,match:/.*/.exec(``)},hA=`gm`+(/x/.unicode==null?``:`u`),gA=class{constructor(e,t,n,r=0,i=e.length){if(this.text=e,this.to=i,this.curLine=``,this.done=!1,this.value=mA,/\\[sWDnr]|\n|\r|\[\^/.test(t))return new yA(e,t,n,r,i);this.re=new RegExp(t,hA+(n?.ignoreCase?`i`:``)),this.test=n?.test,this.iter=e.iter(),this.curLineStart=e.lineAt(r).from,this.matchPos=xA(e,r),this.getLine(this.curLineStart)}getLine(e){this.iter.next(e),this.iter.lineBreak?this.curLine=``:(this.curLine=this.iter.value,this.curLineStart+this.curLine.length>this.to&&(this.curLine=this.curLine.slice(0,this.to-this.curLineStart)),this.iter.next())}nextLine(){this.curLineStart=this.curLineStart+this.curLine.length+1,this.curLineStart>this.to?this.curLine=``:this.getLine(0)}next(){for(let e=this.matchPos-this.curLineStart;;){this.re.lastIndex=e;let t=this.matchPos<=this.to&&this.re.exec(this.curLine);if(t){let n=this.curLineStart+t.index,r=n+t[0].length;if(this.matchPos=xA(this.text,r+ +(n==r)),n==this.curLineStart+this.curLine.length&&this.nextLine(),(n<r||n>this.value.to)&&(!this.test||this.test(n,r,t)))return this.value={from:n,to:r,match:t},this;e=this.matchPos-this.curLineStart}else if(this.curLineStart+this.curLine.length<this.to)this.nextLine(),e=0;else return this.done=!0,this}}},_A=new WeakMap,vA=class e{constructor(e,t){this.from=e,this.text=t}get to(){return this.from+this.text.length}static get(t,n,r){let i=_A.get(t);if(!i||i.from>=r||i.to<=n){let i=new e(n,t.sliceString(n,r));return _A.set(t,i),i}if(i.from==n&&i.to==r)return i;let{text:a,from:o}=i;return o>n&&(a=t.sliceString(n,o)+a,o=n),i.to<r&&(a+=t.sliceString(i.to,r)),_A.set(t,new e(o,a)),new e(n,a.slice(n-o,r-o))}},yA=class{constructor(e,t,n,r,i){this.text=e,this.to=i,this.done=!1,this.value=mA,this.matchPos=xA(e,r),this.re=new RegExp(t,hA+(n?.ignoreCase?`i`:``)),this.test=n?.test,this.flat=vA.get(e,r,this.chunkEnd(r+5e3))}chunkEnd(e){return e>=this.to?this.to:this.text.lineAt(e).to}next(){for(;;){let e=this.re.lastIndex=this.matchPos-this.flat.from,t=this.re.exec(this.flat.text);if(t&&!t[0]&&t.index==e&&(this.re.lastIndex=e+1,t=this.re.exec(this.flat.text)),t){let e=this.flat.from+t.index,n=e+t[0].length;if((this.flat.to>=this.to||t.index+t[0].length<=this.flat.text.length-10)&&(!this.test||this.test(e,n,t)))return this.value={from:e,to:n,match:t},this.matchPos=xA(this.text,n+ +(e==n)),this}if(this.flat.to==this.to)return this.done=!0,this;this.flat=vA.get(this.text,this.flat.from,this.chunkEnd(this.flat.from+this.flat.text.length*2))}}};typeof Symbol<`u`&&(gA.prototype[Symbol.iterator]=yA.prototype[Symbol.iterator]=function(){return this});function bA(e){try{return new RegExp(e,hA),!0}catch{return!1}}function xA(e,t){if(t>=e.length)return t;let n=e.lineAt(t),r;for(;t<n.to&&(r=n.text.charCodeAt(t-n.from))>=56320&&r<57344;)t++;return t}var SA=e=>{let{state:t}=e,n=String(t.doc.lineAt(e.state.selection.main.head).number),{close:r,result:i}=Ht(e,{label:t.phrase(`Go to line`),input:{type:`text`,name:`line`,value:n},focus:!0,submitLabel:t.phrase(`go`)});return i.then(n=>{let i=n&&/^([+-])?(\d+)?(:\d+)?(%)?$/.exec(n.elements.line.value);if(!i){e.dispatch({effects:r});return}let a=t.doc.lineAt(t.selection.main.head),[,o,s,c,l]=i,u=c?+c.slice(1):0,d=s?+s:a.number;if(s&&l){let e=d/100;o&&(e=e*(o==`-`?-1:1)+a.number/t.doc.lines),d=Math.round(t.doc.lines*e)}else s&&o&&(d=d*(o==`-`?-1:1)+a.number);let f=t.doc.line(Math.max(1,Math.min(t.doc.lines,d))),p=W.cursor(f.from+Math.max(0,Math.min(u,f.length)));e.dispatch({effects:[r,Dt.scrollIntoView(p.from,{y:`center`})],selection:p})}),!0},CA={highlightWordAroundCursor:!1,minSelectionLength:1,maxMatches:100,wholeWords:!1},wA=tt.define({combine(e){return yn(e,CA,{highlightWordAroundCursor:(e,t)=>e||t,minSelectionLength:Math.min,maxMatches:Math.min})}});function TA(e){let t=[jA,AA];return e&&t.push(wA.of(e)),t}var EA=rn.mark({class:`cm-selectionMatch`}),DA=rn.mark({class:`cm-selectionMatch cm-selectionMatch-main`});function OA(e,t,n,r){return(n==0||e(t.sliceDoc(n-1,n))!=$e.Word)&&(r==t.doc.length||e(t.sliceDoc(r,r+1))!=$e.Word)}function kA(e,t,n,r){return e(t.sliceDoc(n,n+1))==$e.Word&&e(t.sliceDoc(r-1,r))==$e.Word}var AA=Ot.fromClass(class{constructor(e){this.decorations=this.getDeco(e)}update(e){(e.selectionSet||e.docChanged||e.viewportChanged)&&(this.decorations=this.getDeco(e.view))}getDeco(e){let t=e.state.facet(wA),{state:n}=e,r=n.selection;if(r.ranges.length>1)return rn.none;let i=r.main,a,o=null;if(i.empty){if(!t.highlightWordAroundCursor)return rn.none;let e=n.wordAt(i.head);if(!e)return rn.none;o=n.charCategorizer(i.head),a=n.sliceDoc(e.from,e.to)}else{let e=i.to-i.from;if(e<t.minSelectionLength||e>200)return rn.none;if(t.wholeWords){if(a=n.sliceDoc(i.from,i.to),o=n.charCategorizer(i.head),!(OA(o,n,i.from,i.to)&&kA(o,n,i.from,i.to)))return rn.none}else if(a=n.sliceDoc(i.from,i.to),!a)return rn.none}let s=[];for(let r of e.visibleRanges){let e=new pA(n.doc,a,r.from,r.to);for(;!e.next().done;){let{from:r,to:a}=e.value;if((!o||OA(o,n,r,a))&&(i.empty&&r<=i.from&&a>=i.to?s.push(DA.range(r,a)):(r>=i.to||a<=i.from)&&s.push(EA.range(r,a)),s.length>t.maxMatches))return rn.none}}return rn.set(s)}},{decorations:e=>e.decorations}),jA=Dt.baseTheme({".cm-selectionMatch":{backgroundColor:`#99ff7780`},".cm-searchMatch .cm-selectionMatch":{backgroundColor:`transparent`}}),MA=({state:e,dispatch:t})=>{let{selection:n}=e,r=W.create(n.ranges.map(t=>e.wordAt(t.head)||W.cursor(t.head)),n.mainIndex);return r.eq(n)?!1:(t(e.update({selection:r})),!0)};function NA(e,t){let{main:n,ranges:r}=e.selection,i=e.wordAt(n.head),a=i&&i.from==n.from&&i.to==n.to;for(let n=!1,i=new pA(e.doc,t,r[r.length-1].to);;)if(i.next(),i.done){if(n)return null;i=new pA(e.doc,t,0,Math.max(0,r[r.length-1].from-1)),n=!0}else{if(n&&r.some(e=>e.from==i.value.from))continue;if(a){let t=e.wordAt(i.value.from);if(!t||t.from!=i.value.from||t.to!=i.value.to)continue}return i.value}}var PA=({state:e,dispatch:t})=>{let{ranges:n}=e.selection;if(n.some(e=>e.from===e.to))return MA({state:e,dispatch:t});let r=e.sliceDoc(n[0].from,n[0].to);if(e.selection.ranges.some(t=>e.sliceDoc(t.from,t.to)!=r))return!1;let i=NA(e,r);return i?(t(e.update({selection:e.selection.addRange(W.range(i.from,i.to),!1),effects:Dt.scrollIntoView(i.to)})),!0):!1},FA=tt.define({combine(e){return yn(e,{top:!1,caseSensitive:!1,literal:!1,regexp:!1,wholeWord:!1,createPanel:e=>new hj(e),scrollToMatch:e=>Dt.scrollIntoView(e)})}}),IA=class{constructor(e){this.search=e.search,this.caseSensitive=!!e.caseSensitive,this.literal=!!e.literal,this.regexp=!!e.regexp,this.replace=e.replace||``,this.valid=!!this.search&&(!this.regexp||bA(this.search)),this.unquoted=this.unquote(this.search),this.wholeWord=!!e.wholeWord,this.test=e.test}unquote(e){return this.literal?e:e.replace(/\\([nrt\\])/g,(e,t)=>t==`n`?`
|
|
33
|
-
`:t==`r`?`\r`:t==`t`?` `:`\\`)}eq(e){return this.search==e.search&&this.replace==e.replace&&this.caseSensitive==e.caseSensitive&&this.regexp==e.regexp&&this.wholeWord==e.wholeWord&&this.test==e.test}create(){return this.regexp?new qA(this):new VA(this)}getCursor(e,t=0,n){let r=e.doc?e:rt.create({doc:e});return n??=r.doc.length,this.regexp?UA(this,r,t,n):zA(this,r,t,n)}},LA=class{constructor(e){this.spec=e}};function RA(e,t,n){return(r,i,a,o)=>n&&!n(r,i,a,o)?!1:e(r>=o&&i<=o+a.length?a.slice(r-o,i-o):t.doc.sliceString(r,i),t,r,i)}function zA(e,t,n,r){let i;return e.wholeWord&&(i=BA(t.doc,t.charCategorizer(t.selection.main.head))),e.test&&(i=RA(e.test,t,i)),new pA(t.doc,e.unquoted,n,r,e.caseSensitive?void 0:e=>e.toLowerCase(),i)}function BA(e,t){return(n,r,i,a)=>((a>n||a+i.length<r)&&(a=Math.max(0,n-2),i=e.sliceString(a,Math.min(e.length,r+2))),(t(WA(i,n-a))!=$e.Word||t(GA(i,n-a))!=$e.Word)&&(t(GA(i,r-a))!=$e.Word||t(WA(i,r-a))!=$e.Word))}var VA=class extends LA{constructor(e){super(e)}nextMatch(e,t,n){let r=zA(this.spec,e,n,e.doc.length).nextOverlapping();if(r.done){let n=Math.min(e.doc.length,t+this.spec.unquoted.length);r=zA(this.spec,e,0,n).nextOverlapping()}return r.done||r.value.from==t&&r.value.to==n?null:r.value}prevMatchInRange(e,t,n){for(let r=n;;){let n=Math.max(t,r-1e4-this.spec.unquoted.length),i=zA(this.spec,e,n,r),a=null;for(;!i.nextOverlapping().done;)a=i.value;if(a)return a;if(n==t)return null;r-=1e4}}prevMatch(e,t,n){let r=this.prevMatchInRange(e,0,t);return r||=this.prevMatchInRange(e,Math.max(0,n-this.spec.unquoted.length),e.doc.length),r&&(r.from!=t||r.to!=n)?r:null}getReplacement(e){return this.spec.unquote(this.spec.replace)}matchAll(e,t){let n=zA(this.spec,e,0,e.doc.length),r=[];for(;!n.next().done;){if(r.length>=t)return null;r.push(n.value)}return r}highlight(e,t,n,r){let i=zA(this.spec,e,Math.max(0,t-this.spec.unquoted.length),Math.min(n+this.spec.unquoted.length,e.doc.length));for(;!i.next().done;)r(i.value.from,i.value.to)}};function HA(e,t,n){return(r,i,a)=>(!n||n(r,i,a))&&e(a[0],t,r,i)}function UA(e,t,n,r){let i;return e.wholeWord&&(i=KA(t.charCategorizer(t.selection.main.head))),e.test&&(i=HA(e.test,t,i)),new gA(t.doc,e.search,{ignoreCase:!e.caseSensitive,test:i},n,r)}function WA(e,t){return e.slice(Tt(e,t,!1),t)}function GA(e,t){return e.slice(t,Tt(e,t))}function KA(e){return(t,n,r)=>!r[0].length||(e(WA(r.input,r.index))!=$e.Word||e(GA(r.input,r.index))!=$e.Word)&&(e(GA(r.input,r.index+r[0].length))!=$e.Word||e(WA(r.input,r.index+r[0].length))!=$e.Word)}var qA=class extends LA{nextMatch(e,t,n){let r=UA(this.spec,e,n,e.doc.length).next();return r.done&&(r=UA(this.spec,e,0,t).next()),r.done?null:r.value}prevMatchInRange(e,t,n){for(let r=1;;r++){let i=Math.max(t,n-r*1e4),a=UA(this.spec,e,i,n),o=null;for(;!a.next().done;)o=a.value;if(o&&(i==t||o.from>i+10))return o;if(i==t)return null}}prevMatch(e,t,n){return this.prevMatchInRange(e,0,t)||this.prevMatchInRange(e,n,e.doc.length)}getReplacement(e){return this.spec.unquote(this.spec.replace).replace(/\$([$&]|\d+)/g,(t,n)=>{if(n==`&`)return e.match[0];if(n==`$`)return`$`;for(let t=n.length;t>0;t--){let r=+n.slice(0,t);if(r>0&&r<e.match.length)return e.match[r]+n.slice(t)}return t})}matchAll(e,t){let n=UA(this.spec,e,0,e.doc.length),r=[];for(;!n.next().done;){if(r.length>=t)return null;r.push(n.value)}return r}highlight(e,t,n,r){let i=UA(this.spec,e,Math.max(0,t-250),Math.min(n+250,e.doc.length));for(;!i.next().done;)r(i.value.from,i.value.to)}},JA=ht.define(),YA=ht.define(),XA=_t.define({create(e){return new ZA(lj(e).create(),null)},update(e,t){for(let n of t.effects)n.is(JA)?e=new ZA(n.value.create(),e.panel):n.is(YA)&&(e=new ZA(e.query,n.value?cj:null));return e},provide:e=>Bt.from(e,e=>e.panel)}),ZA=class{constructor(e,t){this.query=e,this.panel=t}},QA=rn.mark({class:`cm-searchMatch`}),$A=rn.mark({class:`cm-searchMatch cm-searchMatch-selected`}),ej=Ot.fromClass(class{constructor(e){this.view=e,this.decorations=this.highlight(e.state.field(XA))}update(e){let t=e.state.field(XA);(t!=e.startState.field(XA)||e.docChanged||e.selectionSet||e.viewportChanged)&&(this.decorations=this.highlight(t))}highlight({query:e,panel:t}){if(!t||!e.spec.valid)return rn.none;let{view:n}=this,r=new Gt;for(let t=0,i=n.visibleRanges,a=i.length;t<a;t++){let{from:o,to:s}=i[t];for(;t<a-1&&s>i[t+1].from-500;)s=i[++t].to;e.highlight(n.state,o,s,(e,t)=>{let i=n.state.selection.ranges.some(n=>n.from==e&&n.to==t);r.add(e,t,i?$A:QA)})}return r.finish()}},{decorations:e=>e.decorations});function tj(e){return t=>{let n=t.state.field(XA,!1);return n&&n.query.spec.valid?e(t,n):fj(t)}}var nj=tj((e,{query:t})=>{let{to:n}=e.state.selection.main,r=t.nextMatch(e.state,n,n);if(!r)return!1;let i=W.single(r.from,r.to),a=e.state.facet(FA);return e.dispatch({selection:i,effects:[yj(e,r),a.scrollToMatch(i.main,e)],userEvent:`select.search`}),dj(e),!0}),rj=tj((e,{query:t})=>{let{state:n}=e,{from:r}=n.selection.main,i=t.prevMatch(n,r,r);if(!i)return!1;let a=W.single(i.from,i.to),o=e.state.facet(FA);return e.dispatch({selection:a,effects:[yj(e,i),o.scrollToMatch(a.main,e)],userEvent:`select.search`}),dj(e),!0}),ij=tj((e,{query:t})=>{let n=t.matchAll(e.state,1e3);return!n||!n.length?!1:(e.dispatch({selection:W.create(n.map(e=>W.range(e.from,e.to))),userEvent:`select.search.matches`}),!0)}),aj=({state:e,dispatch:t})=>{let n=e.selection;if(n.ranges.length>1||n.main.empty)return!1;let{from:r,to:i}=n.main,a=[],o=0;for(let t=new pA(e.doc,e.sliceDoc(r,i));!t.next().done;){if(a.length>1e3)return!1;t.value.from==r&&(o=a.length),a.push(W.range(t.value.from,t.value.to))}return t(e.update({selection:W.create(a,o),userEvent:`select.search.matches`})),!0},oj=tj((e,{query:t})=>{let{state:n}=e,{from:r,to:i}=n.selection.main;if(n.readOnly)return!1;let a=t.nextMatch(n,r,r);if(!a)return!1;let o=a,s=[],c,l,u=[];o.from==r&&o.to==i&&(l=n.toText(t.getReplacement(o)),s.push({from:o.from,to:o.to,insert:l}),o=t.nextMatch(n,o.from,o.to),u.push(Dt.announce.of(n.phrase(`replaced match on line $`,n.doc.lineAt(r).number)+`.`)));let d=e.state.changes(s);return o&&(c=W.single(o.from,o.to).map(d),u.push(yj(e,o)),u.push(n.facet(FA).scrollToMatch(c.main,e))),e.dispatch({changes:d,selection:c,effects:u,userEvent:`input.replace`}),!0}),sj=tj((e,{query:t})=>{if(e.state.readOnly)return!1;let n=t.matchAll(e.state,1e9).map(e=>{let{from:n,to:r}=e;return{from:n,to:r,insert:t.getReplacement(e)}});if(!n.length)return!1;let r=e.state.phrase(`replaced $ matches`,n.length)+`.`;return e.dispatch({changes:n,effects:Dt.announce.of(r),userEvent:`input.replace.all`}),!0});function cj(e){return e.state.facet(FA).createPanel(e)}function lj(e,t){let n=e.selection.main,r=n.empty||n.to>n.from+100?``:e.sliceDoc(n.from,n.to);if(t&&!r)return t;let i=e.facet(FA);return new IA({search:t?.literal??i.literal?r:r.replace(/\n/g,`\\n`),caseSensitive:t?.caseSensitive??i.caseSensitive,literal:t?.literal??i.literal,regexp:t?.regexp??i.regexp,wholeWord:t?.wholeWord??i.wholeWord})}function uj(e){let t=Qt(e,cj);return t&&t.dom.querySelector(`[main-field]`)}function dj(e){let t=uj(e);t&&t==e.root.activeElement&&t.select()}var fj=e=>{let t=e.state.field(XA,!1);if(t&&t.panel){let n=uj(e);if(n&&n!=e.root.activeElement){let r=lj(e.state,t.query.spec);r.valid&&e.dispatch({effects:JA.of(r)}),n.focus(),n.select()}}else e.dispatch({effects:[YA.of(!0),t?JA.of(lj(e.state,t.query.spec)):ht.appendConfig.of(xj)]});return!0},pj=e=>{let t=e.state.field(XA,!1);if(!t||!t.panel)return!1;let n=Qt(e,cj);return n&&n.dom.contains(e.root.activeElement)&&e.focus(),e.dispatch({effects:YA.of(!1)}),!0},mj=[{key:`Mod-f`,run:fj,scope:`editor search-panel`},{key:`F3`,run:nj,shift:rj,scope:`editor search-panel`,preventDefault:!0},{key:`Mod-g`,run:nj,shift:rj,scope:`editor search-panel`,preventDefault:!0},{key:`Escape`,run:pj,scope:`editor search-panel`},{key:`Mod-Shift-l`,run:aj},{key:`Mod-Alt-g`,run:SA},{key:`Mod-d`,run:PA,preventDefault:!0}],hj=class{constructor(e){this.view=e;let t=this.query=e.state.field(XA).query.spec;this.commit=this.commit.bind(this),this.searchField=pn(`input`,{value:t.search,placeholder:gj(e,`Find`),"aria-label":gj(e,`Find`),class:`cm-textfield`,name:`search`,form:``,"main-field":`true`,onchange:this.commit,onkeyup:this.commit}),this.replaceField=pn(`input`,{value:t.replace,placeholder:gj(e,`Replace`),"aria-label":gj(e,`Replace`),class:`cm-textfield`,name:`replace`,form:``,onchange:this.commit,onkeyup:this.commit}),this.caseField=pn(`input`,{type:`checkbox`,name:`case`,form:``,checked:t.caseSensitive,onchange:this.commit}),this.reField=pn(`input`,{type:`checkbox`,name:`re`,form:``,checked:t.regexp,onchange:this.commit}),this.wordField=pn(`input`,{type:`checkbox`,name:`word`,form:``,checked:t.wholeWord,onchange:this.commit});function n(e,t,n){return pn(`button`,{class:`cm-button`,name:e,onclick:t,type:`button`},n)}this.dom=pn(`div`,{onkeydown:e=>this.keydown(e),class:`cm-search`},[this.searchField,n(`next`,()=>nj(e),[gj(e,`next`)]),n(`prev`,()=>rj(e),[gj(e,`previous`)]),n(`select`,()=>ij(e),[gj(e,`all`)]),pn(`label`,null,[this.caseField,gj(e,`match case`)]),pn(`label`,null,[this.reField,gj(e,`regexp`)]),pn(`label`,null,[this.wordField,gj(e,`by word`)]),...e.state.readOnly?[]:[pn(`br`),this.replaceField,n(`replace`,()=>oj(e),[gj(e,`replace`)]),n(`replaceAll`,()=>sj(e),[gj(e,`replace all`)])],pn(`button`,{name:`close`,onclick:()=>pj(e),"aria-label":gj(e,`close`),type:`button`},[`×`])])}commit(){let e=new IA({search:this.searchField.value,caseSensitive:this.caseField.checked,regexp:this.reField.checked,wholeWord:this.wordField.checked,replace:this.replaceField.value});e.eq(this.query)||(this.query=e,this.view.dispatch({effects:JA.of(e)}))}keydown(e){Xt(this.view,e,`search-panel`)?e.preventDefault():e.keyCode==13&&e.target==this.searchField?(e.preventDefault(),(e.shiftKey?rj:nj)(this.view)):e.keyCode==13&&e.target==this.replaceField&&(e.preventDefault(),oj(this.view))}update(e){for(let t of e.transactions)for(let e of t.effects)e.is(JA)&&!e.value.eq(this.query)&&this.setQuery(e.value)}setQuery(e){this.query=e,this.searchField.value=e.search,this.replaceField.value=e.replace,this.caseField.checked=e.caseSensitive,this.reField.checked=e.regexp,this.wordField.checked=e.wholeWord}mount(){this.searchField.select()}get pos(){return 80}get top(){return this.view.state.facet(FA).top}};function gj(e,t){return e.state.phrase(t)}var _j=30,vj=/[\s\.,:;?!]/;function yj(e,{from:t,to:n}){let r=e.state.doc.lineAt(t),i=e.state.doc.lineAt(n).to,a=Math.max(r.from,t-_j),o=Math.min(i,n+_j),s=e.state.sliceDoc(a,o);if(a!=r.from){for(let e=0;e<_j;e++)if(!vj.test(s[e+1])&&vj.test(s[e])){s=s.slice(e);break}}if(o!=i){for(let e=s.length-1;e>s.length-_j;e--)if(!vj.test(s[e-1])&&vj.test(s[e])){s=s.slice(0,e);break}}return Dt.announce.of(`${e.state.phrase(`current match`)}. ${s} ${e.state.phrase(`on line`)} ${r.number}.`)}var bj=Dt.baseTheme({".cm-panel.cm-search":{padding:`2px 6px 4px`,position:`relative`,"& [name=close]":{position:`absolute`,top:`0`,right:`4px`,backgroundColor:`inherit`,border:`none`,font:`inherit`,padding:0,margin:0},"& input, & button, & label":{margin:`.2em .6em .2em 0`},"& input[type=checkbox]":{marginRight:`.2em`},"& label":{fontSize:`80%`,whiteSpace:`pre`}},"&light .cm-searchMatch":{backgroundColor:`#ffff0054`},"&dark .cm-searchMatch":{backgroundColor:`#00ffff8a`},"&light .cm-searchMatch-selected":{backgroundColor:`#ff6a0054`},"&dark .cm-searchMatch-selected":{backgroundColor:`#ff00ff8a`}}),xj=[XA,qt.low(ej),bj],Sj=class{constructor(e,t,n){this.from=e,this.to=t,this.diagnostic=n}},Cj=class e{constructor(e,t,n){this.diagnostics=e,this.panel=t,this.selected=n}static init(t,n,r){let i=r.facet(Lj).markerFilter;i&&(t=i(t,r));let a=t.slice().sort((e,t)=>e.from-t.from||e.to-t.to),o=new Gt,s=[],c=0,l=r.doc.iter(),u=0,d=r.doc.length;for(let e=0;;){let t=e==a.length?null:a[e];if(!t&&!s.length)break;let n,r;if(s.length)n=c,r=s.reduce((e,t)=>Math.min(e,t.to),t&&t.from>n?t.from:1e8);else{if(n=t.from,n>d)break;r=t.to,s.push(t),e++}for(;e<a.length;){let t=a[e];if(t.from==n&&(t.to>t.from||t.to==n))s.push(t),e++,r=Math.min(t.to,r);else{r=Math.min(t.from,r);break}}r=Math.min(r,d);let i=!1;if(s.some(e=>e.from==n&&(e.to==r||r==d))&&(i=n==r,!i&&r-n<10)){let e=n-(u+l.value.length);e>0&&(l.next(e),u=n);for(let e=n;;){if(e>=r){i=!0;break}if(!l.lineBreak&&u+l.value.length>e)break;e=u+l.value.length,u+=l.value.length,l.next()}}let f=Jj(s);if(i)o.add(n,n,rn.widget({widget:new Vj(f),diagnostics:s.slice()}));else{let e=s.reduce((e,t)=>t.markClass?e+` `+t.markClass:e,``);o.add(n,r,rn.mark({class:`cm-lintRange cm-lintRange-`+f+e,diagnostics:s.slice(),inclusiveEnd:s.some(e=>e.to>r)}))}if(c=r,c==d)break;for(let e=0;e<s.length;e++)s[e].to<=c&&s.splice(e--,1)}let f=o.finish();return new e(f,n,wj(f))}};function wj(e,t=null,n=0){let r=null;return e.between(n,1e9,(e,n,{spec:i})=>{if(!(t&&i.diagnostics.indexOf(t)<0))if(!r)r=new Sj(e,n,t||i.diagnostics[0]);else if(i.diagnostics.indexOf(r.diagnostic)<0)return!1;else r=new Sj(r.from,n,r.diagnostic)}),r}function Tj(e,t){let n=t.pos,r=t.end||n,i=e.state.facet(Lj).hideOn(e,n,r);if(i!=null)return i;let a=e.startState.doc.lineAt(t.pos);return!!(e.effects.some(e=>e.is(Dj))||e.changes.touchesRange(a.from,Math.max(a.to,r)))}function Ej(e,t){return e.field(Aj,!1)?t:t.concat(ht.appendConfig.of(Yj))}var Dj=ht.define(),Oj=ht.define(),kj=ht.define(),Aj=_t.define({create(){return new Cj(rn.none,null,null)},update(e,t){if(t.docChanged&&e.diagnostics.size){let n=e.diagnostics.map(t.changes),r=null,i=e.panel;if(e.selected){let i=t.changes.mapPos(e.selected.from,1);r=wj(n,e.selected.diagnostic,i)||wj(n,null,i)}!n.size&&i&&t.state.facet(Lj).autoPanel&&(i=null),e=new Cj(n,i,r)}for(let n of t.effects)if(n.is(Dj)){let r=t.state.facet(Lj).autoPanel?n.value.length?Uj.open:null:e.panel;e=Cj.init(n.value,r,t.state)}else n.is(Oj)?e=new Cj(e.diagnostics,n.value?Uj.open:null,e.selected):n.is(kj)&&(e=new Cj(e.diagnostics,e.panel,n.value));return e},provide:e=>[Bt.from(e,e=>e.panel),Dt.decorations.from(e,e=>e.diagnostics)]}),jj=rn.mark({class:`cm-lintRange cm-lintRange-active`});function Mj(e,t,n){let{diagnostics:r}=e.state.field(Aj),i,a=-1,o=-1;r.between(t-+(n<0),t+ +(n>0),(e,r,{spec:s})=>{if(t>=e&&t<=r&&(e==r||(t>e||n>0)&&(t<r||n<0)))return i=s.diagnostics,a=e,o=r,!1});let s=e.state.facet(Lj).tooltipFilter;return i&&s&&(i=s(i,e.state)),i?{pos:a,end:o,above:e.state.doc.lineAt(a).to<o,create(){return{dom:Nj(e,i)}}}:null}function Nj(e,t){return pn(`ul`,{class:`cm-tooltip-lint`},t.map(t=>Bj(e,t,!1)))}var Pj=e=>{let t=e.state.field(Aj,!1);(!t||!t.panel)&&e.dispatch({effects:Ej(e.state,[Oj.of(!0)])});let n=Qt(e,Uj.open);return n&&n.dom.querySelector(`.cm-panel-lint ul`).focus(),!0},Fj=e=>{let t=e.state.field(Aj,!1);return!t||!t.panel?!1:(e.dispatch({effects:Oj.of(!1)}),!0)},Ij=[{key:`Mod-Shift-m`,run:Pj,preventDefault:!0},{key:`F8`,run:e=>{let t=e.state.field(Aj,!1);if(!t)return!1;let n=e.state.selection.main,r=wj(t.diagnostics,null,n.to+1);return!r&&(r=wj(t.diagnostics,null,0),!r||r.from==n.from&&r.to==n.to)?!1:(e.dispatch({selection:{anchor:r.from,head:r.to},scrollIntoView:!0}),!0)}}],Lj=tt.define({combine(e){return{sources:e.map(e=>e.source).filter(e=>e!=null),...yn(e.map(e=>e.config),{delay:750,markerFilter:null,tooltipFilter:null,needsRefresh:null,hideOn:()=>null},{delay:Math.max,markerFilter:Rj,tooltipFilter:Rj,needsRefresh:(e,t)=>e?t?n=>e(n)||t(n):e:t,hideOn:(e,t)=>e?t?(n,r,i)=>e(n,r,i)||t(n,r,i):e:t,autoPanel:(e,t)=>e||t})}}});function Rj(e,t){return e?t?(n,r)=>t(e(n,r),r):e:t}function zj(e){let t=[];if(e)actions:for(let{name:n}of e){for(let e=0;e<n.length;e++){let r=n[e];if(/[a-zA-Z]/.test(r)&&!t.some(e=>e.toLowerCase()==r.toLowerCase())){t.push(r);continue actions}}t.push(``)}return t}function Bj(e,t,n){let r=n?zj(t.actions):[];return pn(`li`,{class:`cm-diagnostic cm-diagnostic-`+t.severity},pn(`span`,{class:`cm-diagnosticText`},t.renderMessage?t.renderMessage(e):t.message),t.actions?.map((n,i)=>{let a=!1,o=r=>{if(r.preventDefault(),a)return;a=!0;let i=wj(e.state.field(Aj).diagnostics,t);i&&n.apply(e,i.from,i.to)},{name:s}=n,c=r[i]?s.indexOf(r[i]):-1,l=c<0?s:[s.slice(0,c),pn(`u`,s.slice(c,c+1)),s.slice(c+1)];return pn(`button`,{type:`button`,class:`cm-diagnosticAction`+(n.markClass?` `+n.markClass:``),onclick:o,onmousedown:o,"aria-label":` Action: ${s}${c<0?``:` (access key "${r[i]})"`}.`},l)}),t.source&&pn(`div`,{class:`cm-diagnosticSource`},t.source))}var Vj=class extends vt{constructor(e){super(),this.sev=e}eq(e){return e.sev==this.sev}toDOM(){return pn(`span`,{class:`cm-lintPoint cm-lintPoint-`+this.sev})}},Hj=class{constructor(e,t){this.diagnostic=t,this.id=`item_`+Math.floor(Math.random()*4294967295).toString(16),this.dom=Bj(e,t,!0),this.dom.id=this.id,this.dom.setAttribute(`role`,`option`)}},Uj=class e{constructor(e){this.view=e,this.items=[],this.list=pn(`ul`,{tabIndex:0,role:`listbox`,"aria-label":this.view.state.phrase(`Diagnostics`),onkeydown:t=>{if(!(t.ctrlKey||t.altKey||t.metaKey)){if(t.keyCode==27)Fj(this.view),this.view.focus();else if(t.keyCode==38||t.keyCode==33)this.moveSelection((this.selectedIndex-1+this.items.length)%this.items.length);else if(t.keyCode==40||t.keyCode==34)this.moveSelection((this.selectedIndex+1)%this.items.length);else if(t.keyCode==36)this.moveSelection(0);else if(t.keyCode==35)this.moveSelection(this.items.length-1);else if(t.keyCode==13)this.view.focus();else if(t.keyCode>=65&&t.keyCode<=90&&this.selectedIndex>=0){let{diagnostic:n}=this.items[this.selectedIndex],r=zj(n.actions);for(let i=0;i<r.length;i++)if(r[i].toUpperCase().charCodeAt(0)==t.keyCode){let t=wj(this.view.state.field(Aj).diagnostics,n);t&&n.actions[i].apply(e,t.from,t.to)}}else return;t.preventDefault()}},onclick:e=>{for(let t=0;t<this.items.length;t++)this.items[t].dom.contains(e.target)&&this.moveSelection(t)}}),this.dom=pn(`div`,{class:`cm-panel-lint`},this.list,pn(`button`,{type:`button`,name:`close`,"aria-label":this.view.state.phrase(`close`),onclick:()=>Fj(this.view)},`×`)),this.update()}get selectedIndex(){let e=this.view.state.field(Aj).selected;if(!e)return-1;for(let t=0;t<this.items.length;t++)if(this.items[t].diagnostic==e.diagnostic)return t;return-1}update(){let{diagnostics:e,selected:t}=this.view.state.field(Aj),n=0,r=!1,i=null,a=new Set;for(e.between(0,this.view.state.doc.length,(e,o,{spec:s})=>{for(let e of s.diagnostics){if(a.has(e))continue;a.add(e);let o=-1,s;for(let t=n;t<this.items.length;t++)if(this.items[t].diagnostic==e){o=t;break}o<0?(s=new Hj(this.view,e),this.items.splice(n,0,s),r=!0):(s=this.items[o],o>n&&(this.items.splice(n,o-n),r=!0)),t&&s.diagnostic==t.diagnostic?s.dom.hasAttribute(`aria-selected`)||(s.dom.setAttribute(`aria-selected`,`true`),i=s):s.dom.hasAttribute(`aria-selected`)&&s.dom.removeAttribute(`aria-selected`),n++}});n<this.items.length&&!(this.items.length==1&&this.items[0].diagnostic.from<0);)r=!0,this.items.pop();this.items.length==0&&(this.items.push(new Hj(this.view,{from:-1,to:-1,severity:`info`,message:this.view.state.phrase(`No diagnostics`)})),r=!0),i?(this.list.setAttribute(`aria-activedescendant`,i.id),this.view.requestMeasure({key:this,read:()=>({sel:i.dom.getBoundingClientRect(),panel:this.list.getBoundingClientRect()}),write:({sel:e,panel:t})=>{let n=t.height/this.list.offsetHeight;e.top<t.top?this.list.scrollTop-=(t.top-e.top)/n:e.bottom>t.bottom&&(this.list.scrollTop+=(e.bottom-t.bottom)/n)}})):this.selectedIndex<0&&this.list.removeAttribute(`aria-activedescendant`),r&&this.sync()}sync(){let e=this.list.firstChild;function t(){let t=e;e=t.nextSibling,t.remove()}for(let n of this.items)if(n.dom.parentNode==this.list){for(;e!=n.dom;)t();e=n.dom.nextSibling}else this.list.insertBefore(n.dom,e);for(;e;)t()}moveSelection(e){if(this.selectedIndex<0)return;let t=wj(this.view.state.field(Aj).diagnostics,this.items[e].diagnostic);t&&this.view.dispatch({selection:{anchor:t.from,head:t.to},scrollIntoView:!0,effects:kj.of(t)})}static open(t){return new e(t)}};function Wj(e,t=`viewBox="0 0 40 40"`){return`url('data:image/svg+xml,<svg xmlns="http://www.w3.org/2000/svg" ${t}>${encodeURIComponent(e)}</svg>')`}function Gj(e){return Wj(`<path d="m0 2.5 l2 -1.5 l1 0 l2 1.5 l1 0" stroke="${e}" fill="none" stroke-width=".7"/>`,`width="6" height="3"`)}var Kj=Dt.baseTheme({".cm-diagnostic":{padding:`3px 6px 3px 8px`,marginLeft:`-1px`,display:`block`,whiteSpace:`pre-wrap`},".cm-diagnostic-error":{borderLeft:`5px solid #d11`},".cm-diagnostic-warning":{borderLeft:`5px solid orange`},".cm-diagnostic-info":{borderLeft:`5px solid #999`},".cm-diagnostic-hint":{borderLeft:`5px solid #66d`},".cm-diagnosticAction":{font:`inherit`,border:`none`,padding:`2px 4px`,backgroundColor:`#444`,color:`white`,borderRadius:`3px`,marginLeft:`8px`,cursor:`pointer`},".cm-diagnosticSource":{fontSize:`70%`,opacity:.7},".cm-lintRange":{backgroundPosition:`left bottom`,backgroundRepeat:`repeat-x`,paddingBottom:`0.7px`},".cm-lintRange-error":{backgroundImage:Gj(`#d11`)},".cm-lintRange-warning":{backgroundImage:Gj(`orange`)},".cm-lintRange-info":{backgroundImage:Gj(`#999`)},".cm-lintRange-hint":{backgroundImage:Gj(`#66d`)},".cm-lintRange-active":{backgroundColor:`#ffdd9980`},".cm-tooltip-lint":{padding:0,margin:0},".cm-lintPoint":{position:`relative`,"&:after":{content:`""`,position:`absolute`,bottom:0,left:`-2px`,borderLeft:`3px solid transparent`,borderRight:`3px solid transparent`,borderBottom:`4px solid #d11`}},".cm-lintPoint-warning":{"&:after":{borderBottomColor:`orange`}},".cm-lintPoint-info":{"&:after":{borderBottomColor:`#999`}},".cm-lintPoint-hint":{"&:after":{borderBottomColor:`#66d`}},".cm-panel.cm-panel-lint":{position:`relative`,"& ul":{maxHeight:`100px`,overflowY:`auto`,"& [aria-selected]":{backgroundColor:`#ddd`,"& u":{textDecoration:`underline`}},"&:focus [aria-selected]":{background_fallback:`#bdf`,backgroundColor:`Highlight`,color_fallback:`white`,color:`HighlightText`},"& u":{textDecoration:`none`},padding:0,margin:0},"& [name=close]":{position:`absolute`,top:`0`,right:`2px`,background:`inherit`,border:`none`,font:`inherit`,padding:0,margin:0}},"&dark .cm-lintRange-active":{backgroundColor:`#86714a80`},"&dark .cm-panel.cm-panel-lint ul":{"& [aria-selected]":{backgroundColor:`#2e343e`}}});function qj(e){return e==`error`?4:e==`warning`?3:e==`info`?2:1}function Jj(e){let t=`hint`,n=1;for(let r of e){let e=qj(r.severity);e>n&&(n=e,t=r.severity)}return t}var Yj=[Aj,Dt.decorations.compute([Aj],e=>{let{selected:t,panel:n}=e.field(Aj);return!t||!n||t.from==t.to?rn.none:rn.set([jj.range(t.from,t.to)])}),Ft(Mj,{hideOn:Tj}),Kj],Xj=[dn(),en(),sn(),rO(),zt(),Lt(),ln(),rt.allowMultipleSelections.of(!0),St(),pt(It,{fallback:!0}),Pt(),Tn(),Cn(),nn(),Ye(),jt(),TA(),Yt.of([...Sn,...uA,...mj,...SO,...fn,...wn,...Ij])];sn(),rO(),Lt(),pt(It,{fallback:!0}),Yt.of([...uA,...SO]);function Zj(e,t){let n=(0,rr.c)(4),r=t===void 0?!1:t,[i,a]=(0,G.useState)(void 0),o=(0,G.useRef)(null),s,c;return n[0]!==r||n[1]!==e?(s=()=>{if(r||e.length===0){a(void 0);return}let t=function(){let t=window.innerHeight/2,n,r;for(let i of e){let e=document.getElementById(i);if(!e)continue;let a=e.getBoundingClientRect().top;a<0?n=i:r===void 0&&a<t&&(r=i)}a(r??n??e[0])},n=function(){o.current===null&&(o.current=requestAnimationFrame(()=>{o.current=null,t()}))};return document.addEventListener(`scroll`,n,{capture:!0,passive:!0}),t(),()=>{document.removeEventListener(`scroll`,n,{capture:!0}),o.current!==null&&(cancelAnimationFrame(o.current),o.current=null)}},c=[e,r],n[0]=r,n[1]=e,n[2]=s,n[3]=c):(s=n[2],c=n[3]),(0,G.useEffect)(s,c),i}var Qj=300;async function $j(e){let t=await fetch(`/api/page-headings?docName=${encodeURIComponent(e)}`);if(!t.ok)throw Error(`Server error: ${t.status} ${t.statusText}`);let n=await t.json();if(!n.ok)throw Error(n.error??`Failed to load headings`);return n.headings??[]}var eM=32,tM=6,nM=6,rM=8;function iM(e){return(e-1)*rM+.5}function aM(e){if(e.length===0)return``;let t=[];for(let n=0;n<e.length;n++){let r=iM(e[n].level),i=n*eM+tM,a=n*eM+eM-nM;t.push(`${n===0?`M`:`L`}${r} ${i}`),t.push(`L${r} ${a}`)}return t.join(` `)}var oM=`open-knowledge:outline-nav`;function sM(e){let t=(0,rr.c)(2),n;return t[0]===e?n=t[1]:(n=(0,q.jsx)(or,{name:`outline-panel`,children:(0,q.jsx)(cM,{...e})}),t[0]=e,t[1]=n),n}function cM(e){let t=(0,rr.c)(54),{docName:n,isSourceMode:r,className:i}=e,o=i===void 0?``:i,{pages:s,loading:c}=pe(),l=I(),{activeProvider:u,activeDocName:d}=Mx(),f,p;t[0]===n?(f=t[1],p=t[2]):(f=[`page-headings`,n],p=()=>$j(n),t[0]=n,t[1]=f,t[2]=p);let m;t[3]!==n||t[4]!==c||t[5]!==s?(m=!c&&s.has(n),t[3]=n,t[4]=c,t[5]=s,t[6]=m):m=t[6];let h;t[7]!==f||t[8]!==p||t[9]!==m?(h={queryKey:f,queryFn:p,enabled:m,staleTime:1/0},t[7]=f,t[8]=p,t[9]=m,t[10]=h):h=t[10];let{data:g,isLoading:_,error:v}=V(h),y;t[11]===g?y=t[12]:(y=g===void 0?[]:g,t[11]=g,t[12]=y);let b=y,x,S;t[13]!==d||t[14]!==u||t[15]!==n||t[16]!==l?(x=()=>{if(!u||d!==n)return;let e=u.document,t=null,r=()=>{t!==null&&clearTimeout(t),t=setTimeout(()=>{t=null,l.invalidateQueries({queryKey:[`page-headings`,n]})},Qj)};return e.on(`update`,r),()=>{e.off(`update`,r),t!==null&&clearTimeout(t)}},S=[u,d,n,l],t[13]=d,t[14]=u,t[15]=n,t[16]=l,t[17]=x,t[18]=S):(x=t[17],S=t[18]),(0,G.useEffect)(x,S);let C;t[19]===b?C=t[20]:(C=b.map(uM),t[19]=b,t[20]=C);let w=Zj(C,r),T;t[21]!==w||t[22]!==b?(T=w?b.findIndex(e=>e.slug===w):-1,t[21]=w,t[22]=b,t[23]=T):T=t[23];let E=T,D;t[24]!==n||t[25]!==r?(D=function(e,t){let i={index:e,slug:t,mode:r?`source`:`wysiwyg`};i.mode===`source`&&Fx(n,{kind:`outline`,detail:i}),window.dispatchEvent(new CustomEvent(oM,{detail:i}))},t[24]=n,t[25]=r,t[26]=D):D=t[26];let O=D,k=(b.reduce(lM,1)-1)*rM+1,A=b.length*eM,j;t[27]===b?j=t[28]:(j=aM(b),t[27]=b,t[28]=j);let M=j,N=M?`url("data:image/svg+xml,${encodeURIComponent(`<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 ${k} ${A}"><path d="${M}" stroke="black" stroke-width="2" fill="none" /></svg>`)}")`:void 0,P=E>=0?E*eM+tM:0,F=E>=0?eM-tM-nM:0,ee;t[29]===Symbol.for(`react.memo_cache_sentinel`)?(ee=(0,q.jsx)(Ce,{children:`Outline`}),t[29]=ee):ee=t[29];let L;t[30]!==b.length||t[31]!==_?(L=!_&&(0,q.jsx)(Se,{children:b.length}),t[30]=b.length,t[31]=_,t[32]=L):L=t[32];let R;t[33]===L?R=t[34]:(R=(0,q.jsxs)(_e,{children:[ee,L]}),t[33]=L,t[34]=R);let z;t[35]!==w||t[36]!==v||t[37]!==O||t[38]!==b||t[39]!==_||t[40]!==M||t[41]!==N||t[42]!==A||t[43]!==k||t[44]!==F||t[45]!==P?(z=v?(0,q.jsx)(ne,{className:`px-2`,children:v instanceof Error?v.message:`Failed to load headings`}):b.length===0&&!_?(0,q.jsx)(le,{className:`px-2`,children:`No headings yet.`}):(0,q.jsxs)(`nav`,{"aria-label":`Document outline`,className:`relative`,children:[(0,q.jsx)(`svg`,{width:k,height:A,className:`pointer-events-none absolute left-0 top-0`,"aria-hidden":`true`,children:(0,q.jsx)(`path`,{d:M,fill:`none`,strokeWidth:`1`,style:{stroke:`var(--border)`}})}),N&&(0,q.jsx)(`div`,{className:`pointer-events-none absolute left-0 top-0`,style:{width:k,height:A,maskImage:N,WebkitMaskImage:N},children:(0,q.jsx)(`div`,{className:`w-full motion-safe:[transition:transform_0.25s_var(--ease-out-strong),height_0.1s_var(--ease-out-strong)]`,style:{transform:`translateY(${P}px)`,height:F,backgroundColor:`var(--primary)`}})}),b.map((e,t)=>{let n=e.slug===w;return(0,q.jsx)(`button`,{type:`button`,"aria-current":n?`location`:void 0,onClick:()=>O(t,e.slug),className:a(`w-full cursor-pointer truncate py-1.5 pe-2 text-left text-sm transition-colors`,n?`font-medium text-primary`:`text-muted-foreground hover:text-foreground`),style:{paddingLeft:`${(e.level-1)*rM+16}px`},title:e.text,children:e.text},t)})]}),t[35]=w,t[36]=v,t[37]=O,t[38]=b,t[39]=_,t[40]=M,t[41]=N,t[42]=A,t[43]=k,t[44]=F,t[45]=P,t[46]=z):z=t[46];let B;t[47]!==_||t[48]!==z?(B=(0,q.jsx)(ge,{className:`px-3 py-2`,"aria-busy":_,children:z}),t[47]=_,t[48]=z,t[49]=B):B=t[49];let te;return t[50]!==o||t[51]!==R||t[52]!==B?(te=(0,q.jsxs)(Te,{className:o,children:[R,B]}),t[50]=o,t[51]=R,t[52]=B,t[53]=te):te=t[53],te}function lM(e,t){return Math.max(e,t.level)}function uM(e){return e.slug}function dM(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 fM=250,pM=100;function mM(e,t){let n=performance.now()-e;n<(t.op===`paste`?fM:pM)||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 hM(e){console.warn(JSON.stringify({event:`clipboard-source-detected`,view:e.view,source:e.source,branch:e.branch}))}function gM(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 _M(e){console.warn(JSON.stringify({event:`clipboard-serialize-failed`,view:e.view,kind:e.kind,reason:e.reason}))}function vM(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 yM(e){if(e instanceof D)return`HtmlPayloadTooLargeError`;if(e instanceof g)return`ChunkedInsertError`;if(e instanceof Error&&e.name&&e.name!==`Error`)return e.name}var bM=/^```/m,xM=/^#{1,6} /m,SM=/^[-*+] /m,CM=/^\d+[.)] /m,wM=/\[[^\]\n]+\]\([^)\n]+\)/,TM=/^\|.*\|$/m,EM=/^\|?\s*(:?-+:?)(\s*\|\s*:?-+:?)+\s*\|?$/m,DM=/\$\$[\s\S]+?\$\$/;function OM(e){if(!e)return!1;let t=0;bM.test(e)&&t++,xM.test(e)&&t++,SM.test(e)&&t++,CM.test(e)&&t++,wM.test(e)&&t++,TM.test(e)&&EM.test(e)&&t++,DM.test(e)&&t++;let n=e.split(`
|
|
34
|
-
`).length,r=Math.min(3,Math.floor(n/5));return t>=Math.max(1,r)}var kM=3e3,AM=new Map;function jM(e,t=`Pasted as plain text — some formatting could not be converted.`){let n=Date.now();return n-(AM.get(e)??0)<kM?!1:(AM.set(e,n),
|
|
33
|
+
`:t==`r`?`\r`:t==`t`?` `:`\\`)}eq(e){return this.search==e.search&&this.replace==e.replace&&this.caseSensitive==e.caseSensitive&&this.regexp==e.regexp&&this.wholeWord==e.wholeWord&&this.test==e.test}create(){return this.regexp?new qA(this):new VA(this)}getCursor(e,t=0,n){let r=e.doc?e:rt.create({doc:e});return n??=r.doc.length,this.regexp?UA(this,r,t,n):zA(this,r,t,n)}},LA=class{constructor(e){this.spec=e}};function RA(e,t,n){return(r,i,a,o)=>n&&!n(r,i,a,o)?!1:e(r>=o&&i<=o+a.length?a.slice(r-o,i-o):t.doc.sliceString(r,i),t,r,i)}function zA(e,t,n,r){let i;return e.wholeWord&&(i=BA(t.doc,t.charCategorizer(t.selection.main.head))),e.test&&(i=RA(e.test,t,i)),new pA(t.doc,e.unquoted,n,r,e.caseSensitive?void 0:e=>e.toLowerCase(),i)}function BA(e,t){return(n,r,i,a)=>((a>n||a+i.length<r)&&(a=Math.max(0,n-2),i=e.sliceString(a,Math.min(e.length,r+2))),(t(WA(i,n-a))!=$e.Word||t(GA(i,n-a))!=$e.Word)&&(t(GA(i,r-a))!=$e.Word||t(WA(i,r-a))!=$e.Word))}var VA=class extends LA{constructor(e){super(e)}nextMatch(e,t,n){let r=zA(this.spec,e,n,e.doc.length).nextOverlapping();if(r.done){let n=Math.min(e.doc.length,t+this.spec.unquoted.length);r=zA(this.spec,e,0,n).nextOverlapping()}return r.done||r.value.from==t&&r.value.to==n?null:r.value}prevMatchInRange(e,t,n){for(let r=n;;){let n=Math.max(t,r-1e4-this.spec.unquoted.length),i=zA(this.spec,e,n,r),a=null;for(;!i.nextOverlapping().done;)a=i.value;if(a)return a;if(n==t)return null;r-=1e4}}prevMatch(e,t,n){let r=this.prevMatchInRange(e,0,t);return r||=this.prevMatchInRange(e,Math.max(0,n-this.spec.unquoted.length),e.doc.length),r&&(r.from!=t||r.to!=n)?r:null}getReplacement(e){return this.spec.unquote(this.spec.replace)}matchAll(e,t){let n=zA(this.spec,e,0,e.doc.length),r=[];for(;!n.next().done;){if(r.length>=t)return null;r.push(n.value)}return r}highlight(e,t,n,r){let i=zA(this.spec,e,Math.max(0,t-this.spec.unquoted.length),Math.min(n+this.spec.unquoted.length,e.doc.length));for(;!i.next().done;)r(i.value.from,i.value.to)}};function HA(e,t,n){return(r,i,a)=>(!n||n(r,i,a))&&e(a[0],t,r,i)}function UA(e,t,n,r){let i;return e.wholeWord&&(i=KA(t.charCategorizer(t.selection.main.head))),e.test&&(i=HA(e.test,t,i)),new gA(t.doc,e.search,{ignoreCase:!e.caseSensitive,test:i},n,r)}function WA(e,t){return e.slice(Tt(e,t,!1),t)}function GA(e,t){return e.slice(t,Tt(e,t))}function KA(e){return(t,n,r)=>!r[0].length||(e(WA(r.input,r.index))!=$e.Word||e(GA(r.input,r.index))!=$e.Word)&&(e(GA(r.input,r.index+r[0].length))!=$e.Word||e(WA(r.input,r.index+r[0].length))!=$e.Word)}var qA=class extends LA{nextMatch(e,t,n){let r=UA(this.spec,e,n,e.doc.length).next();return r.done&&(r=UA(this.spec,e,0,t).next()),r.done?null:r.value}prevMatchInRange(e,t,n){for(let r=1;;r++){let i=Math.max(t,n-r*1e4),a=UA(this.spec,e,i,n),o=null;for(;!a.next().done;)o=a.value;if(o&&(i==t||o.from>i+10))return o;if(i==t)return null}}prevMatch(e,t,n){return this.prevMatchInRange(e,0,t)||this.prevMatchInRange(e,n,e.doc.length)}getReplacement(e){return this.spec.unquote(this.spec.replace).replace(/\$([$&]|\d+)/g,(t,n)=>{if(n==`&`)return e.match[0];if(n==`$`)return`$`;for(let t=n.length;t>0;t--){let r=+n.slice(0,t);if(r>0&&r<e.match.length)return e.match[r]+n.slice(t)}return t})}matchAll(e,t){let n=UA(this.spec,e,0,e.doc.length),r=[];for(;!n.next().done;){if(r.length>=t)return null;r.push(n.value)}return r}highlight(e,t,n,r){let i=UA(this.spec,e,Math.max(0,t-250),Math.min(n+250,e.doc.length));for(;!i.next().done;)r(i.value.from,i.value.to)}},JA=ht.define(),YA=ht.define(),XA=_t.define({create(e){return new ZA(lj(e).create(),null)},update(e,t){for(let n of t.effects)n.is(JA)?e=new ZA(n.value.create(),e.panel):n.is(YA)&&(e=new ZA(e.query,n.value?cj:null));return e},provide:e=>Bt.from(e,e=>e.panel)}),ZA=class{constructor(e,t){this.query=e,this.panel=t}},QA=rn.mark({class:`cm-searchMatch`}),$A=rn.mark({class:`cm-searchMatch cm-searchMatch-selected`}),ej=Ot.fromClass(class{constructor(e){this.view=e,this.decorations=this.highlight(e.state.field(XA))}update(e){let t=e.state.field(XA);(t!=e.startState.field(XA)||e.docChanged||e.selectionSet||e.viewportChanged)&&(this.decorations=this.highlight(t))}highlight({query:e,panel:t}){if(!t||!e.spec.valid)return rn.none;let{view:n}=this,r=new Gt;for(let t=0,i=n.visibleRanges,a=i.length;t<a;t++){let{from:o,to:s}=i[t];for(;t<a-1&&s>i[t+1].from-500;)s=i[++t].to;e.highlight(n.state,o,s,(e,t)=>{let i=n.state.selection.ranges.some(n=>n.from==e&&n.to==t);r.add(e,t,i?$A:QA)})}return r.finish()}},{decorations:e=>e.decorations});function tj(e){return t=>{let n=t.state.field(XA,!1);return n&&n.query.spec.valid?e(t,n):fj(t)}}var nj=tj((e,{query:t})=>{let{to:n}=e.state.selection.main,r=t.nextMatch(e.state,n,n);if(!r)return!1;let i=W.single(r.from,r.to),a=e.state.facet(FA);return e.dispatch({selection:i,effects:[yj(e,r),a.scrollToMatch(i.main,e)],userEvent:`select.search`}),dj(e),!0}),rj=tj((e,{query:t})=>{let{state:n}=e,{from:r}=n.selection.main,i=t.prevMatch(n,r,r);if(!i)return!1;let a=W.single(i.from,i.to),o=e.state.facet(FA);return e.dispatch({selection:a,effects:[yj(e,i),o.scrollToMatch(a.main,e)],userEvent:`select.search`}),dj(e),!0}),ij=tj((e,{query:t})=>{let n=t.matchAll(e.state,1e3);return!n||!n.length?!1:(e.dispatch({selection:W.create(n.map(e=>W.range(e.from,e.to))),userEvent:`select.search.matches`}),!0)}),aj=({state:e,dispatch:t})=>{let n=e.selection;if(n.ranges.length>1||n.main.empty)return!1;let{from:r,to:i}=n.main,a=[],o=0;for(let t=new pA(e.doc,e.sliceDoc(r,i));!t.next().done;){if(a.length>1e3)return!1;t.value.from==r&&(o=a.length),a.push(W.range(t.value.from,t.value.to))}return t(e.update({selection:W.create(a,o),userEvent:`select.search.matches`})),!0},oj=tj((e,{query:t})=>{let{state:n}=e,{from:r,to:i}=n.selection.main;if(n.readOnly)return!1;let a=t.nextMatch(n,r,r);if(!a)return!1;let o=a,s=[],c,l,u=[];o.from==r&&o.to==i&&(l=n.toText(t.getReplacement(o)),s.push({from:o.from,to:o.to,insert:l}),o=t.nextMatch(n,o.from,o.to),u.push(Dt.announce.of(n.phrase(`replaced match on line $`,n.doc.lineAt(r).number)+`.`)));let d=e.state.changes(s);return o&&(c=W.single(o.from,o.to).map(d),u.push(yj(e,o)),u.push(n.facet(FA).scrollToMatch(c.main,e))),e.dispatch({changes:d,selection:c,effects:u,userEvent:`input.replace`}),!0}),sj=tj((e,{query:t})=>{if(e.state.readOnly)return!1;let n=t.matchAll(e.state,1e9).map(e=>{let{from:n,to:r}=e;return{from:n,to:r,insert:t.getReplacement(e)}});if(!n.length)return!1;let r=e.state.phrase(`replaced $ matches`,n.length)+`.`;return e.dispatch({changes:n,effects:Dt.announce.of(r),userEvent:`input.replace.all`}),!0});function cj(e){return e.state.facet(FA).createPanel(e)}function lj(e,t){let n=e.selection.main,r=n.empty||n.to>n.from+100?``:e.sliceDoc(n.from,n.to);if(t&&!r)return t;let i=e.facet(FA);return new IA({search:t?.literal??i.literal?r:r.replace(/\n/g,`\\n`),caseSensitive:t?.caseSensitive??i.caseSensitive,literal:t?.literal??i.literal,regexp:t?.regexp??i.regexp,wholeWord:t?.wholeWord??i.wholeWord})}function uj(e){let t=Qt(e,cj);return t&&t.dom.querySelector(`[main-field]`)}function dj(e){let t=uj(e);t&&t==e.root.activeElement&&t.select()}var fj=e=>{let t=e.state.field(XA,!1);if(t&&t.panel){let n=uj(e);if(n&&n!=e.root.activeElement){let r=lj(e.state,t.query.spec);r.valid&&e.dispatch({effects:JA.of(r)}),n.focus(),n.select()}}else e.dispatch({effects:[YA.of(!0),t?JA.of(lj(e.state,t.query.spec)):ht.appendConfig.of(xj)]});return!0},pj=e=>{let t=e.state.field(XA,!1);if(!t||!t.panel)return!1;let n=Qt(e,cj);return n&&n.dom.contains(e.root.activeElement)&&e.focus(),e.dispatch({effects:YA.of(!1)}),!0},mj=[{key:`Mod-f`,run:fj,scope:`editor search-panel`},{key:`F3`,run:nj,shift:rj,scope:`editor search-panel`,preventDefault:!0},{key:`Mod-g`,run:nj,shift:rj,scope:`editor search-panel`,preventDefault:!0},{key:`Escape`,run:pj,scope:`editor search-panel`},{key:`Mod-Shift-l`,run:aj},{key:`Mod-Alt-g`,run:SA},{key:`Mod-d`,run:PA,preventDefault:!0}],hj=class{constructor(e){this.view=e;let t=this.query=e.state.field(XA).query.spec;this.commit=this.commit.bind(this),this.searchField=pn(`input`,{value:t.search,placeholder:gj(e,`Find`),"aria-label":gj(e,`Find`),class:`cm-textfield`,name:`search`,form:``,"main-field":`true`,onchange:this.commit,onkeyup:this.commit}),this.replaceField=pn(`input`,{value:t.replace,placeholder:gj(e,`Replace`),"aria-label":gj(e,`Replace`),class:`cm-textfield`,name:`replace`,form:``,onchange:this.commit,onkeyup:this.commit}),this.caseField=pn(`input`,{type:`checkbox`,name:`case`,form:``,checked:t.caseSensitive,onchange:this.commit}),this.reField=pn(`input`,{type:`checkbox`,name:`re`,form:``,checked:t.regexp,onchange:this.commit}),this.wordField=pn(`input`,{type:`checkbox`,name:`word`,form:``,checked:t.wholeWord,onchange:this.commit});function n(e,t,n){return pn(`button`,{class:`cm-button`,name:e,onclick:t,type:`button`},n)}this.dom=pn(`div`,{onkeydown:e=>this.keydown(e),class:`cm-search`},[this.searchField,n(`next`,()=>nj(e),[gj(e,`next`)]),n(`prev`,()=>rj(e),[gj(e,`previous`)]),n(`select`,()=>ij(e),[gj(e,`all`)]),pn(`label`,null,[this.caseField,gj(e,`match case`)]),pn(`label`,null,[this.reField,gj(e,`regexp`)]),pn(`label`,null,[this.wordField,gj(e,`by word`)]),...e.state.readOnly?[]:[pn(`br`),this.replaceField,n(`replace`,()=>oj(e),[gj(e,`replace`)]),n(`replaceAll`,()=>sj(e),[gj(e,`replace all`)])],pn(`button`,{name:`close`,onclick:()=>pj(e),"aria-label":gj(e,`close`),type:`button`},[`×`])])}commit(){let e=new IA({search:this.searchField.value,caseSensitive:this.caseField.checked,regexp:this.reField.checked,wholeWord:this.wordField.checked,replace:this.replaceField.value});e.eq(this.query)||(this.query=e,this.view.dispatch({effects:JA.of(e)}))}keydown(e){Xt(this.view,e,`search-panel`)?e.preventDefault():e.keyCode==13&&e.target==this.searchField?(e.preventDefault(),(e.shiftKey?rj:nj)(this.view)):e.keyCode==13&&e.target==this.replaceField&&(e.preventDefault(),oj(this.view))}update(e){for(let t of e.transactions)for(let e of t.effects)e.is(JA)&&!e.value.eq(this.query)&&this.setQuery(e.value)}setQuery(e){this.query=e,this.searchField.value=e.search,this.replaceField.value=e.replace,this.caseField.checked=e.caseSensitive,this.reField.checked=e.regexp,this.wordField.checked=e.wholeWord}mount(){this.searchField.select()}get pos(){return 80}get top(){return this.view.state.facet(FA).top}};function gj(e,t){return e.state.phrase(t)}var _j=30,vj=/[\s\.,:;?!]/;function yj(e,{from:t,to:n}){let r=e.state.doc.lineAt(t),i=e.state.doc.lineAt(n).to,a=Math.max(r.from,t-_j),o=Math.min(i,n+_j),s=e.state.sliceDoc(a,o);if(a!=r.from){for(let e=0;e<_j;e++)if(!vj.test(s[e+1])&&vj.test(s[e])){s=s.slice(e);break}}if(o!=i){for(let e=s.length-1;e>s.length-_j;e--)if(!vj.test(s[e-1])&&vj.test(s[e])){s=s.slice(0,e);break}}return Dt.announce.of(`${e.state.phrase(`current match`)}. ${s} ${e.state.phrase(`on line`)} ${r.number}.`)}var bj=Dt.baseTheme({".cm-panel.cm-search":{padding:`2px 6px 4px`,position:`relative`,"& [name=close]":{position:`absolute`,top:`0`,right:`4px`,backgroundColor:`inherit`,border:`none`,font:`inherit`,padding:0,margin:0},"& input, & button, & label":{margin:`.2em .6em .2em 0`},"& input[type=checkbox]":{marginRight:`.2em`},"& label":{fontSize:`80%`,whiteSpace:`pre`}},"&light .cm-searchMatch":{backgroundColor:`#ffff0054`},"&dark .cm-searchMatch":{backgroundColor:`#00ffff8a`},"&light .cm-searchMatch-selected":{backgroundColor:`#ff6a0054`},"&dark .cm-searchMatch-selected":{backgroundColor:`#ff00ff8a`}}),xj=[XA,qt.low(ej),bj],Sj=class{constructor(e,t,n){this.from=e,this.to=t,this.diagnostic=n}},Cj=class e{constructor(e,t,n){this.diagnostics=e,this.panel=t,this.selected=n}static init(t,n,r){let i=r.facet(Lj).markerFilter;i&&(t=i(t,r));let a=t.slice().sort((e,t)=>e.from-t.from||e.to-t.to),o=new Gt,s=[],c=0,l=r.doc.iter(),u=0,d=r.doc.length;for(let e=0;;){let t=e==a.length?null:a[e];if(!t&&!s.length)break;let n,r;if(s.length)n=c,r=s.reduce((e,t)=>Math.min(e,t.to),t&&t.from>n?t.from:1e8);else{if(n=t.from,n>d)break;r=t.to,s.push(t),e++}for(;e<a.length;){let t=a[e];if(t.from==n&&(t.to>t.from||t.to==n))s.push(t),e++,r=Math.min(t.to,r);else{r=Math.min(t.from,r);break}}r=Math.min(r,d);let i=!1;if(s.some(e=>e.from==n&&(e.to==r||r==d))&&(i=n==r,!i&&r-n<10)){let e=n-(u+l.value.length);e>0&&(l.next(e),u=n);for(let e=n;;){if(e>=r){i=!0;break}if(!l.lineBreak&&u+l.value.length>e)break;e=u+l.value.length,u+=l.value.length,l.next()}}let f=Jj(s);if(i)o.add(n,n,rn.widget({widget:new Vj(f),diagnostics:s.slice()}));else{let e=s.reduce((e,t)=>t.markClass?e+` `+t.markClass:e,``);o.add(n,r,rn.mark({class:`cm-lintRange cm-lintRange-`+f+e,diagnostics:s.slice(),inclusiveEnd:s.some(e=>e.to>r)}))}if(c=r,c==d)break;for(let e=0;e<s.length;e++)s[e].to<=c&&s.splice(e--,1)}let f=o.finish();return new e(f,n,wj(f))}};function wj(e,t=null,n=0){let r=null;return e.between(n,1e9,(e,n,{spec:i})=>{if(!(t&&i.diagnostics.indexOf(t)<0))if(!r)r=new Sj(e,n,t||i.diagnostics[0]);else if(i.diagnostics.indexOf(r.diagnostic)<0)return!1;else r=new Sj(r.from,n,r.diagnostic)}),r}function Tj(e,t){let n=t.pos,r=t.end||n,i=e.state.facet(Lj).hideOn(e,n,r);if(i!=null)return i;let a=e.startState.doc.lineAt(t.pos);return!!(e.effects.some(e=>e.is(Dj))||e.changes.touchesRange(a.from,Math.max(a.to,r)))}function Ej(e,t){return e.field(Aj,!1)?t:t.concat(ht.appendConfig.of(Yj))}var Dj=ht.define(),Oj=ht.define(),kj=ht.define(),Aj=_t.define({create(){return new Cj(rn.none,null,null)},update(e,t){if(t.docChanged&&e.diagnostics.size){let n=e.diagnostics.map(t.changes),r=null,i=e.panel;if(e.selected){let i=t.changes.mapPos(e.selected.from,1);r=wj(n,e.selected.diagnostic,i)||wj(n,null,i)}!n.size&&i&&t.state.facet(Lj).autoPanel&&(i=null),e=new Cj(n,i,r)}for(let n of t.effects)if(n.is(Dj)){let r=t.state.facet(Lj).autoPanel?n.value.length?Uj.open:null:e.panel;e=Cj.init(n.value,r,t.state)}else n.is(Oj)?e=new Cj(e.diagnostics,n.value?Uj.open:null,e.selected):n.is(kj)&&(e=new Cj(e.diagnostics,e.panel,n.value));return e},provide:e=>[Bt.from(e,e=>e.panel),Dt.decorations.from(e,e=>e.diagnostics)]}),jj=rn.mark({class:`cm-lintRange cm-lintRange-active`});function Mj(e,t,n){let{diagnostics:r}=e.state.field(Aj),i,a=-1,o=-1;r.between(t-+(n<0),t+ +(n>0),(e,r,{spec:s})=>{if(t>=e&&t<=r&&(e==r||(t>e||n>0)&&(t<r||n<0)))return i=s.diagnostics,a=e,o=r,!1});let s=e.state.facet(Lj).tooltipFilter;return i&&s&&(i=s(i,e.state)),i?{pos:a,end:o,above:e.state.doc.lineAt(a).to<o,create(){return{dom:Nj(e,i)}}}:null}function Nj(e,t){return pn(`ul`,{class:`cm-tooltip-lint`},t.map(t=>Bj(e,t,!1)))}var Pj=e=>{let t=e.state.field(Aj,!1);(!t||!t.panel)&&e.dispatch({effects:Ej(e.state,[Oj.of(!0)])});let n=Qt(e,Uj.open);return n&&n.dom.querySelector(`.cm-panel-lint ul`).focus(),!0},Fj=e=>{let t=e.state.field(Aj,!1);return!t||!t.panel?!1:(e.dispatch({effects:Oj.of(!1)}),!0)},Ij=[{key:`Mod-Shift-m`,run:Pj,preventDefault:!0},{key:`F8`,run:e=>{let t=e.state.field(Aj,!1);if(!t)return!1;let n=e.state.selection.main,r=wj(t.diagnostics,null,n.to+1);return!r&&(r=wj(t.diagnostics,null,0),!r||r.from==n.from&&r.to==n.to)?!1:(e.dispatch({selection:{anchor:r.from,head:r.to},scrollIntoView:!0}),!0)}}],Lj=tt.define({combine(e){return{sources:e.map(e=>e.source).filter(e=>e!=null),...yn(e.map(e=>e.config),{delay:750,markerFilter:null,tooltipFilter:null,needsRefresh:null,hideOn:()=>null},{delay:Math.max,markerFilter:Rj,tooltipFilter:Rj,needsRefresh:(e,t)=>e?t?n=>e(n)||t(n):e:t,hideOn:(e,t)=>e?t?(n,r,i)=>e(n,r,i)||t(n,r,i):e:t,autoPanel:(e,t)=>e||t})}}});function Rj(e,t){return e?t?(n,r)=>t(e(n,r),r):e:t}function zj(e){let t=[];if(e)actions:for(let{name:n}of e){for(let e=0;e<n.length;e++){let r=n[e];if(/[a-zA-Z]/.test(r)&&!t.some(e=>e.toLowerCase()==r.toLowerCase())){t.push(r);continue actions}}t.push(``)}return t}function Bj(e,t,n){let r=n?zj(t.actions):[];return pn(`li`,{class:`cm-diagnostic cm-diagnostic-`+t.severity},pn(`span`,{class:`cm-diagnosticText`},t.renderMessage?t.renderMessage(e):t.message),t.actions?.map((n,i)=>{let a=!1,o=r=>{if(r.preventDefault(),a)return;a=!0;let i=wj(e.state.field(Aj).diagnostics,t);i&&n.apply(e,i.from,i.to)},{name:s}=n,c=r[i]?s.indexOf(r[i]):-1,l=c<0?s:[s.slice(0,c),pn(`u`,s.slice(c,c+1)),s.slice(c+1)];return pn(`button`,{type:`button`,class:`cm-diagnosticAction`+(n.markClass?` `+n.markClass:``),onclick:o,onmousedown:o,"aria-label":` Action: ${s}${c<0?``:` (access key "${r[i]})"`}.`},l)}),t.source&&pn(`div`,{class:`cm-diagnosticSource`},t.source))}var Vj=class extends vt{constructor(e){super(),this.sev=e}eq(e){return e.sev==this.sev}toDOM(){return pn(`span`,{class:`cm-lintPoint cm-lintPoint-`+this.sev})}},Hj=class{constructor(e,t){this.diagnostic=t,this.id=`item_`+Math.floor(Math.random()*4294967295).toString(16),this.dom=Bj(e,t,!0),this.dom.id=this.id,this.dom.setAttribute(`role`,`option`)}},Uj=class e{constructor(e){this.view=e,this.items=[],this.list=pn(`ul`,{tabIndex:0,role:`listbox`,"aria-label":this.view.state.phrase(`Diagnostics`),onkeydown:t=>{if(!(t.ctrlKey||t.altKey||t.metaKey)){if(t.keyCode==27)Fj(this.view),this.view.focus();else if(t.keyCode==38||t.keyCode==33)this.moveSelection((this.selectedIndex-1+this.items.length)%this.items.length);else if(t.keyCode==40||t.keyCode==34)this.moveSelection((this.selectedIndex+1)%this.items.length);else if(t.keyCode==36)this.moveSelection(0);else if(t.keyCode==35)this.moveSelection(this.items.length-1);else if(t.keyCode==13)this.view.focus();else if(t.keyCode>=65&&t.keyCode<=90&&this.selectedIndex>=0){let{diagnostic:n}=this.items[this.selectedIndex],r=zj(n.actions);for(let i=0;i<r.length;i++)if(r[i].toUpperCase().charCodeAt(0)==t.keyCode){let t=wj(this.view.state.field(Aj).diagnostics,n);t&&n.actions[i].apply(e,t.from,t.to)}}else return;t.preventDefault()}},onclick:e=>{for(let t=0;t<this.items.length;t++)this.items[t].dom.contains(e.target)&&this.moveSelection(t)}}),this.dom=pn(`div`,{class:`cm-panel-lint`},this.list,pn(`button`,{type:`button`,name:`close`,"aria-label":this.view.state.phrase(`close`),onclick:()=>Fj(this.view)},`×`)),this.update()}get selectedIndex(){let e=this.view.state.field(Aj).selected;if(!e)return-1;for(let t=0;t<this.items.length;t++)if(this.items[t].diagnostic==e.diagnostic)return t;return-1}update(){let{diagnostics:e,selected:t}=this.view.state.field(Aj),n=0,r=!1,i=null,a=new Set;for(e.between(0,this.view.state.doc.length,(e,o,{spec:s})=>{for(let e of s.diagnostics){if(a.has(e))continue;a.add(e);let o=-1,s;for(let t=n;t<this.items.length;t++)if(this.items[t].diagnostic==e){o=t;break}o<0?(s=new Hj(this.view,e),this.items.splice(n,0,s),r=!0):(s=this.items[o],o>n&&(this.items.splice(n,o-n),r=!0)),t&&s.diagnostic==t.diagnostic?s.dom.hasAttribute(`aria-selected`)||(s.dom.setAttribute(`aria-selected`,`true`),i=s):s.dom.hasAttribute(`aria-selected`)&&s.dom.removeAttribute(`aria-selected`),n++}});n<this.items.length&&!(this.items.length==1&&this.items[0].diagnostic.from<0);)r=!0,this.items.pop();this.items.length==0&&(this.items.push(new Hj(this.view,{from:-1,to:-1,severity:`info`,message:this.view.state.phrase(`No diagnostics`)})),r=!0),i?(this.list.setAttribute(`aria-activedescendant`,i.id),this.view.requestMeasure({key:this,read:()=>({sel:i.dom.getBoundingClientRect(),panel:this.list.getBoundingClientRect()}),write:({sel:e,panel:t})=>{let n=t.height/this.list.offsetHeight;e.top<t.top?this.list.scrollTop-=(t.top-e.top)/n:e.bottom>t.bottom&&(this.list.scrollTop+=(e.bottom-t.bottom)/n)}})):this.selectedIndex<0&&this.list.removeAttribute(`aria-activedescendant`),r&&this.sync()}sync(){let e=this.list.firstChild;function t(){let t=e;e=t.nextSibling,t.remove()}for(let n of this.items)if(n.dom.parentNode==this.list){for(;e!=n.dom;)t();e=n.dom.nextSibling}else this.list.insertBefore(n.dom,e);for(;e;)t()}moveSelection(e){if(this.selectedIndex<0)return;let t=wj(this.view.state.field(Aj).diagnostics,this.items[e].diagnostic);t&&this.view.dispatch({selection:{anchor:t.from,head:t.to},scrollIntoView:!0,effects:kj.of(t)})}static open(t){return new e(t)}};function Wj(e,t=`viewBox="0 0 40 40"`){return`url('data:image/svg+xml,<svg xmlns="http://www.w3.org/2000/svg" ${t}>${encodeURIComponent(e)}</svg>')`}function Gj(e){return Wj(`<path d="m0 2.5 l2 -1.5 l1 0 l2 1.5 l1 0" stroke="${e}" fill="none" stroke-width=".7"/>`,`width="6" height="3"`)}var Kj=Dt.baseTheme({".cm-diagnostic":{padding:`3px 6px 3px 8px`,marginLeft:`-1px`,display:`block`,whiteSpace:`pre-wrap`},".cm-diagnostic-error":{borderLeft:`5px solid #d11`},".cm-diagnostic-warning":{borderLeft:`5px solid orange`},".cm-diagnostic-info":{borderLeft:`5px solid #999`},".cm-diagnostic-hint":{borderLeft:`5px solid #66d`},".cm-diagnosticAction":{font:`inherit`,border:`none`,padding:`2px 4px`,backgroundColor:`#444`,color:`white`,borderRadius:`3px`,marginLeft:`8px`,cursor:`pointer`},".cm-diagnosticSource":{fontSize:`70%`,opacity:.7},".cm-lintRange":{backgroundPosition:`left bottom`,backgroundRepeat:`repeat-x`,paddingBottom:`0.7px`},".cm-lintRange-error":{backgroundImage:Gj(`#d11`)},".cm-lintRange-warning":{backgroundImage:Gj(`orange`)},".cm-lintRange-info":{backgroundImage:Gj(`#999`)},".cm-lintRange-hint":{backgroundImage:Gj(`#66d`)},".cm-lintRange-active":{backgroundColor:`#ffdd9980`},".cm-tooltip-lint":{padding:0,margin:0},".cm-lintPoint":{position:`relative`,"&:after":{content:`""`,position:`absolute`,bottom:0,left:`-2px`,borderLeft:`3px solid transparent`,borderRight:`3px solid transparent`,borderBottom:`4px solid #d11`}},".cm-lintPoint-warning":{"&:after":{borderBottomColor:`orange`}},".cm-lintPoint-info":{"&:after":{borderBottomColor:`#999`}},".cm-lintPoint-hint":{"&:after":{borderBottomColor:`#66d`}},".cm-panel.cm-panel-lint":{position:`relative`,"& ul":{maxHeight:`100px`,overflowY:`auto`,"& [aria-selected]":{backgroundColor:`#ddd`,"& u":{textDecoration:`underline`}},"&:focus [aria-selected]":{background_fallback:`#bdf`,backgroundColor:`Highlight`,color_fallback:`white`,color:`HighlightText`},"& u":{textDecoration:`none`},padding:0,margin:0},"& [name=close]":{position:`absolute`,top:`0`,right:`2px`,background:`inherit`,border:`none`,font:`inherit`,padding:0,margin:0}},"&dark .cm-lintRange-active":{backgroundColor:`#86714a80`},"&dark .cm-panel.cm-panel-lint ul":{"& [aria-selected]":{backgroundColor:`#2e343e`}}});function qj(e){return e==`error`?4:e==`warning`?3:e==`info`?2:1}function Jj(e){let t=`hint`,n=1;for(let r of e){let e=qj(r.severity);e>n&&(n=e,t=r.severity)}return t}var Yj=[Aj,Dt.decorations.compute([Aj],e=>{let{selected:t,panel:n}=e.field(Aj);return!t||!n||t.from==t.to?rn.none:rn.set([jj.range(t.from,t.to)])}),Ft(Mj,{hideOn:Tj}),Kj],Xj=[dn(),en(),sn(),rO(),zt(),Lt(),ln(),rt.allowMultipleSelections.of(!0),St(),pt(It,{fallback:!0}),Pt(),Tn(),Cn(),nn(),Ye(),jt(),TA(),Yt.of([...Sn,...uA,...mj,...SO,...fn,...wn,...Ij])];sn(),rO(),Lt(),pt(It,{fallback:!0}),Yt.of([...uA,...SO]);function Zj(e,t){let n=(0,rr.c)(4),r=t===void 0?!1:t,[i,a]=(0,G.useState)(void 0),o=(0,G.useRef)(null),s,c;return n[0]!==r||n[1]!==e?(s=()=>{if(r||e.length===0){a(void 0);return}let t=function(){let t=window.innerHeight/2,n,r;for(let i of e){let e=document.getElementById(i);if(!e)continue;let a=e.getBoundingClientRect().top;a<0?n=i:r===void 0&&a<t&&(r=i)}a(r??n??e[0])},n=function(){o.current===null&&(o.current=requestAnimationFrame(()=>{o.current=null,t()}))};return document.addEventListener(`scroll`,n,{capture:!0,passive:!0}),t(),()=>{document.removeEventListener(`scroll`,n,{capture:!0}),o.current!==null&&(cancelAnimationFrame(o.current),o.current=null)}},c=[e,r],n[0]=r,n[1]=e,n[2]=s,n[3]=c):(s=n[2],c=n[3]),(0,G.useEffect)(s,c),i}var Qj=300;async function $j(e){let t=await fetch(`/api/page-headings?docName=${encodeURIComponent(e)}`);if(!t.ok)throw Error(`Server error: ${t.status} ${t.statusText}`);let n=await t.json();if(!n.ok)throw Error(n.error??`Failed to load headings`);return n.headings??[]}var eM=32,tM=6,nM=6,rM=8;function iM(e){return(e-1)*rM+.5}function aM(e){if(e.length===0)return``;let t=[];for(let n=0;n<e.length;n++){let r=iM(e[n].level),i=n*eM+tM,a=n*eM+eM-nM;t.push(`${n===0?`M`:`L`}${r} ${i}`),t.push(`L${r} ${a}`)}return t.join(` `)}var oM=`open-knowledge:outline-nav`;function sM(e){let t=(0,rr.c)(2),n;return t[0]===e?n=t[1]:(n=(0,q.jsx)(or,{name:`outline-panel`,children:(0,q.jsx)(cM,{...e})}),t[0]=e,t[1]=n),n}function cM(e){let t=(0,rr.c)(54),{docName:n,isSourceMode:r,className:i}=e,o=i===void 0?``:i,{pages:s,loading:c}=ve(),l=u(),{activeProvider:d,activeDocName:f}=Mx(),p,m;t[0]===n?(p=t[1],m=t[2]):(p=[`page-headings`,n],m=()=>$j(n),t[0]=n,t[1]=p,t[2]=m);let h;t[3]!==n||t[4]!==c||t[5]!==s?(h=!c&&s.has(n),t[3]=n,t[4]=c,t[5]=s,t[6]=h):h=t[6];let g;t[7]!==p||t[8]!==m||t[9]!==h?(g={queryKey:p,queryFn:m,enabled:h,staleTime:1/0},t[7]=p,t[8]=m,t[9]=h,t[10]=g):g=t[10];let{data:_,isLoading:v,error:y}=ee(g),b;t[11]===_?b=t[12]:(b=_===void 0?[]:_,t[11]=_,t[12]=b);let x=b,S,C;t[13]!==f||t[14]!==d||t[15]!==n||t[16]!==l?(S=()=>{if(!d||f!==n)return;let e=d.document,t=null,r=()=>{t!==null&&clearTimeout(t),t=setTimeout(()=>{t=null,l.invalidateQueries({queryKey:[`page-headings`,n]})},Qj)};return e.on(`update`,r),()=>{e.off(`update`,r),t!==null&&clearTimeout(t)}},C=[d,f,n,l],t[13]=f,t[14]=d,t[15]=n,t[16]=l,t[17]=S,t[18]=C):(S=t[17],C=t[18]),(0,G.useEffect)(S,C);let w;t[19]===x?w=t[20]:(w=x.map(uM),t[19]=x,t[20]=w);let T=Zj(w,r),E;t[21]!==T||t[22]!==x?(E=T?x.findIndex(e=>e.slug===T):-1,t[21]=T,t[22]=x,t[23]=E):E=t[23];let D=E,O;t[24]!==n||t[25]!==r?(O=function(e,t){let i={index:e,slug:t,mode:r?`source`:`wysiwyg`};i.mode===`source`&&Fx(n,{kind:`outline`,detail:i}),window.dispatchEvent(new CustomEvent(oM,{detail:i}))},t[24]=n,t[25]=r,t[26]=O):O=t[26];let k=O,A=(x.reduce(lM,1)-1)*rM+1,j=x.length*eM,M;t[27]===x?M=t[28]:(M=aM(x),t[27]=x,t[28]=M);let N=M,P=N?`url("data:image/svg+xml,${encodeURIComponent(`<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 ${A} ${j}"><path d="${N}" stroke="black" stroke-width="2" fill="none" /></svg>`)}")`:void 0,F=D>=0?D*eM+tM:0,I=D>=0?eM-tM-nM:0,L;t[29]===Symbol.for(`react.memo_cache_sentinel`)?(L=(0,q.jsx)(Te,{children:`Outline`}),t[29]=L):L=t[29];let R;t[30]!==x.length||t[31]!==v?(R=!v&&(0,q.jsx)(we,{children:x.length}),t[30]=x.length,t[31]=v,t[32]=R):R=t[32];let z;t[33]===R?z=t[34]:(z=(0,q.jsxs)(xe,{children:[L,R]}),t[33]=R,t[34]=z);let B;t[35]!==T||t[36]!==y||t[37]!==k||t[38]!==x||t[39]!==v||t[40]!==N||t[41]!==P||t[42]!==j||t[43]!==A||t[44]!==I||t[45]!==F?(B=y?(0,q.jsx)(ne,{className:`px-2`,children:y instanceof Error?y.message:`Failed to load headings`}):x.length===0&&!v?(0,q.jsx)(pe,{className:`px-2`,children:`No headings yet.`}):(0,q.jsxs)(`nav`,{"aria-label":`Document outline`,className:`relative`,children:[(0,q.jsx)(`svg`,{width:A,height:j,className:`pointer-events-none absolute left-0 top-0`,"aria-hidden":`true`,children:(0,q.jsx)(`path`,{d:N,fill:`none`,strokeWidth:`1`,style:{stroke:`var(--border)`}})}),P&&(0,q.jsx)(`div`,{className:`pointer-events-none absolute left-0 top-0`,style:{width:A,height:j,maskImage:P,WebkitMaskImage:P},children:(0,q.jsx)(`div`,{className:`w-full motion-safe:[transition:transform_0.25s_var(--ease-out-strong),height_0.1s_var(--ease-out-strong)]`,style:{transform:`translateY(${F}px)`,height:I,backgroundColor:`var(--primary)`}})}),x.map((e,t)=>{let n=e.slug===T;return(0,q.jsx)(`button`,{type:`button`,"aria-current":n?`location`:void 0,onClick:()=>k(t,e.slug),className:a(`w-full cursor-pointer truncate py-1.5 pe-2 text-left text-sm transition-colors`,n?`font-medium text-primary`:`text-muted-foreground hover:text-foreground`),style:{paddingLeft:`${(e.level-1)*rM+16}px`},title:e.text,children:e.text},t)})]}),t[35]=T,t[36]=y,t[37]=k,t[38]=x,t[39]=v,t[40]=N,t[41]=P,t[42]=j,t[43]=A,t[44]=I,t[45]=F,t[46]=B):B=t[46];let V;t[47]!==v||t[48]!==B?(V=(0,q.jsx)(be,{className:`px-3 py-2`,"aria-busy":v,children:B}),t[47]=v,t[48]=B,t[49]=V):V=t[49];let H;return t[50]!==o||t[51]!==z||t[52]!==V?(H=(0,q.jsxs)(De,{className:o,children:[z,V]}),t[50]=o,t[51]=z,t[52]=V,t[53]=H):H=t[53],H}function lM(e,t){return Math.max(e,t.level)}function uM(e){return e.slug}function dM(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 fM=250,pM=100;function mM(e,t){let n=performance.now()-e;n<(t.op===`paste`?fM:pM)||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 hM(e){console.warn(JSON.stringify({event:`clipboard-source-detected`,view:e.view,source:e.source,branch:e.branch}))}function gM(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 _M(e){console.warn(JSON.stringify({event:`clipboard-serialize-failed`,view:e.view,kind:e.kind,reason:e.reason}))}function vM(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 yM(e){if(e instanceof A)return`HtmlPayloadTooLargeError`;if(e instanceof m)return`ChunkedInsertError`;if(e instanceof Error&&e.name&&e.name!==`Error`)return e.name}var bM=/^```/m,xM=/^#{1,6} /m,SM=/^[-*+] /m,CM=/^\d+[.)] /m,wM=/\[[^\]\n]+\]\([^)\n]+\)/,TM=/^\|.*\|$/m,EM=/^\|?\s*(:?-+:?)(\s*\|\s*:?-+:?)+\s*\|?$/m,DM=/\$\$[\s\S]+?\$\$/;function OM(e){if(!e)return!1;let t=0;bM.test(e)&&t++,xM.test(e)&&t++,SM.test(e)&&t++,CM.test(e)&&t++,wM.test(e)&&t++,TM.test(e)&&EM.test(e)&&t++,DM.test(e)&&t++;let n=e.split(`
|
|
34
|
+
`).length,r=Math.min(3,Math.floor(n/5));return t>=Math.max(1,r)}var kM=3e3,AM=new Map;function jM(e,t=`Pasted as plain text — some formatting could not be converted.`){let n=Date.now();return n-(AM.get(e)??0)<kM?!1:(AM.set(e,n),Fe.error(t),!0)}var MM=!1,NM=!1;function PM(e){MM=e.shiftKey}function FM(e){(e.key===`Shift`||!e.shiftKey)&&(MM=!1)}function IM(){MM=!1}function LM(){NM||typeof window>`u`||(window.addEventListener(`keydown`,PM,!0),window.addEventListener(`keyup`,FM,!0),window.addEventListener(`blur`,IM,!0),NM=!0)}function RM(){LM()}function zM(){return LM(),MM}function BM(e){return zM()?!0:e.shiftKey===!0}function VM(e){return(t,n)=>{let r=n.clipboardData;if(!r||r.types.length===0)return!1;let i=performance.now(),a=dM(r),o=r.getData(`text/plain`),s=r.getData(`text/html`);if(BM(n))return o&&UM(t,o),hM({view:`wysiwyg`,branch:`shift`,source:a}),mM(i,{op:`paste`,view:`wysiwyg`,branch:`shift`,source:a}),!0;if(HM(t))return o&&UM(t,o),hM({view:`wysiwyg`,branch:`codeblock`,source:a}),mM(i,{op:`paste`,view:`wysiwyg`,branch:`codeblock`,source:a}),!0;let c=r.getData(`vscode-editor-data`);if(c&&o&&GM(t,c,o,a))return hM({view:`wysiwyg`,branch:`A`,source:a}),mM(i,{op:`paste`,view:`wysiwyg`,branch:`A`,source:a}),!0;let l=r.getData(`text/x-gfm`);return l&&KM(t,l,e,`B`,a)?(hM({view:`wysiwyg`,branch:`B`,source:a}),mM(i,{op:`paste`,view:`wysiwyg`,branch:`B`,source:a}),!0):s&&/data-pm-slice/i.test(s)?(hM({view:`wysiwyg`,branch:`C`,source:a}),mM(i,{op:`paste`,view:`wysiwyg`,branch:`C`,source:a}),!1):o&&s&&OM(o)&&KM(t,o,e,`B`,a)?(hM({view:`wysiwyg`,branch:`B`,source:a}),mM(i,{op:`paste`,view:`wysiwyg`,branch:`B`,source:a}),!0):s&&qM(t,s,e,a)?(hM({view:`wysiwyg`,branch:`D`,source:a}),mM(i,{op:`paste`,view:`wysiwyg`,branch:`D`,source:a,htmlBytes:s.length}),!0):o?OM(o)&&KM(t,o,e,`E`,`markdown-text`)?(hM({view:`wysiwyg`,branch:`E`,source:`markdown-text`}),mM(i,{op:`paste`,view:`wysiwyg`,branch:`E`,source:`markdown-text`}),!0):(UM(t,o),hM({view:`wysiwyg`,branch:`E`,source:`plaintext`}),mM(i,{op:`paste`,view:`wysiwyg`,branch:`E`,source:`plaintext`}),!0):!1}}function HM(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 UM(e,t){let{schema:n,tr:r}=e.state;t&&e.dispatch(r.replaceSelectionWith(n.text(t)).scrollIntoView())}var WM=/^[A-Za-z0-9_+-]+$/;function GM(e,t,n,r){try{let r=JSON.parse(t),i=typeof r.mode==`string`?r.mode:``,a=WM.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 gM({view:`wysiwyg`,stage:`branchA`,source:r,branch:`A`,reason:e?.message??`unknown`,errorClass:yM(e)}),!1}}function KM(e,t,n,r,i){let a;try{a=n.mdManager.parse(t)}catch(e){return gM({view:`wysiwyg`,stage:`mdManagerParse`,source:i,branch:r,reason:e?.message??`unknown`,errorClass:yM(e)}),!1}return JM(e,a,i,r)}function qM(e,t,n,r){let i;try{i=P(t)}catch(e){return gM({view:`wysiwyg`,stage:`htmlToMdast`,source:r,branch:`D`,reason:e?.message??`unknown`,errorClass:yM(e),htmlBytes:t.length}),jM(`wysiwyg`),!1}let a;try{a=_(i)}catch(e){return gM({view:`wysiwyg`,stage:`mdastToMarkdown`,source:r,branch:`D`,reason:e?.message??`unknown`,errorClass:yM(e),htmlBytes:t.length}),jM(`wysiwyg`),!1}let o;try{o=n.mdManager.parse(a)}catch(e){return gM({view:`wysiwyg`,stage:`mdManagerParse`,source:r,branch:`D`,reason:e?.message??`unknown`,errorClass:yM(e),htmlBytes:t.length}),jM(`wysiwyg`),!1}return JM(e,o,r,`D`,t.length)}function JM(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 gM({view:`wysiwyg`,stage:`applyJsonSlice`,source:n,branch:r,reason:e?.message??`unknown`,errorClass:yM(e),...i==null?{}:{htmlBytes:i}}),!1}}function YM(e){return(t,n)=>{try{return QM(t,n.state.schema,e.mdManager)}catch(e){return console.warn(`[clipboard] text serialize fell through — PM default textBetween`,e),t.content.textBetween(0,t.content.size,`
|
|
35
35
|
|
|
36
|
-
`)}}}var XM=class extends
|
|
36
|
+
`)}}}var XM=class extends F{mdManager;constructor(e){super({},{}),this.mdManager=e}serializeFragment(e,t,n){try{let t=e.firstChild?.type.schema;if(!t)return n??document.createDocumentFragment();let r=tN($M(e,t,this.mdManager));if(n){for(let e of Array.from(r.childNodes))n.appendChild(e);return n}return r}catch(e){return console.warn(`[clipboard] HTML serialize fell through — PM default DOMSerializer`,e),n??document.createDocumentFragment()}}};function ZM(e){return new XM(e.mdManager)}function QM(e,t,n){return n.serialize(eN(e,t))}function $M(e,t,n){return ge(QM(new D(e,0,0),t,n))}function eN(e,t){let n=t.topNodeType.createAndFill(null,e.content);if(!n){let e=t.topNodeType.createAndFill();if(!e)throw Error(`[clipboard] schema cannot fill topNodeType`);return e.toJSON()}return n.toJSON()}function tN(e){let t=new DOMParser().parseFromString(e,`text/html`),n=document.createDocumentFragment();for(let e of Array.from(t.body.childNodes))n.appendChild(e);return n}function nN(e){return RM(),Dt.domEventHandlers({copy:(e,t)=>rN(e,t,`copy`),cut:(e,t)=>rN(e,t,`cut`),paste:(t,n)=>iN(t,n,e)})}function rN(e,t,n){let{from:r,to:i}=t.state.selection.main;if(r===i)return e.preventDefault(),!0;let a=e.clipboardData;if(!a)return!1;let o=performance.now();try{let s=t.state.sliceDoc(r,i);a.setData(`text/plain`,s);try{a.setData(`text/html`,ge(s))}catch(e){_M({view:`source`,kind:`html`,reason:e?.message??`unknown`})}return e.preventDefault(),n===`cut`&&t.dispatch({changes:{from:r,to:i,insert:``}}),mM(o,{op:n,view:`source`,branch:`serialize`,source:`local`}),!0}catch(e){return _M({view:`source`,kind:`text`,reason:e?.message??`unknown`}),!1}}function iN(e,t,n){let r=e.clipboardData;if(!r||r.types.length===0)return!1;let i=performance.now(),a=dM(r),o=r.getData(`text/plain`),s=r.getData(`text/html`);if(BM(e))return hM({view:`source`,branch:`shift`,source:a}),mM(i,{op:`paste`,view:`source`,branch:`shift`,source:a}),!1;let c=r.getData(`vscode-editor-data`);return c&&o&&oN(t,c,o,a)?(e.preventDefault(),hM({view:`source`,branch:`A`,source:a}),mM(i,{op:`paste`,view:`source`,branch:`A`,source:a}),!0):s&&/data-pm-slice/i.test(s)?(hM({view:`source`,branch:`C`,source:a}),mM(i,{op:`paste`,view:`source`,branch:`C`,source:a}),!1):s&&sN(t,s,n,a)?(e.preventDefault(),hM({view:`source`,branch:`D`,source:a}),mM(i,{op:`paste`,view:`source`,branch:`D`,source:a,htmlBytes:s.length}),!0):(hM({view:`source`,branch:`E`,source:a}),mM(i,{op:`paste`,view:`source`,branch:`E`,source:a}),!1)}var aN=/^[A-Za-z0-9_+-]+$/;function oN(e,t,n,r){try{let r=JSON.parse(t),i=typeof r.mode==`string`?r.mode:``,a=`\`\`\`${aN.test(i)?i:``}\n${n}\n\`\`\`\n`,{from:o,to:s}=e.state.selection.main;return e.dispatch({changes:{from:o,to:s,insert:a},selection:{anchor:o+a.length}}),!0}catch(e){return gM({view:`source`,stage:`branchA`,source:r,branch:`A`,reason:e?.message??`unknown`,errorClass:yM(e)}),!1}}function sN(e,t,n,r){let i;try{i=P(t)}catch(e){return gM({view:`source`,stage:`htmlToMdast`,source:r,branch:`D`,reason:e?.message??`unknown`,errorClass:yM(e),htmlBytes:t.length}),!1}let a;try{a=_(i)}catch(e){return gM({view:`source`,stage:`mdastToMarkdown`,source:r,branch:`D`,reason:e?.message??`unknown`,errorClass:yM(e),htmlBytes:t.length}),!1}let{from:o,to:s}=e.state.selection.main;if(!(a.length>500*1024))return e.dispatch({changes:{from:o,to:s,insert:a},selection:{anchor:o+a.length}}),!0;let c=o===s?``:e.state.sliceDoc(o,s);o!==s&&e.dispatch({changes:{from:o,to:s,insert:``}});let l=o,u=su(n.ytext,l);return M(n.ydoc,n.ytext,l,a,{resolveOffset:e=>{let t=lu(u,n.ydoc);return t==null?e:t.index+(e-l)}}).catch(i=>{cN({view:e,source:r,html:t,restoreText:c,anchorIndex:l,anchorRelPos:u,ydoc:n.ydoc,err:i})}),!0}function cN(e){let{view:t,source:n,html:r,restoreText:i,anchorIndex:a,anchorRelPos:o,ydoc:s,err:c}=e;if(c instanceof m&&c.bytesWritten>0){let e=o&&s?lu(o,s)?.index??a:a,n=Math.min(e+c.bytesWritten,t.state.doc.length);try{t.dispatch({changes:{from:e,to:n,insert:i}})}catch(e){console.warn(`[clipboard] partial-chunk rollback dispatch failed`,e)}}else if(i.length>0)try{t.dispatch({changes:{from:a,to:a,insert:i}})}catch(e){console.warn(`[clipboard] selection-restore dispatch failed`,e)}if(c instanceof m){vM({view:`source`,chunksCompleted:c.chunksCompleted,totalChunks:c.totalChunks,bytesWritten:c.bytesWritten,bytesRemaining:c.bytesRemaining,reason:c.message}),Fe.error(`Paste was incomplete — ${c.chunksCompleted} of ${c.totalChunks} chunks landed. Your selection has been restored.`);return}gM({view:`source`,stage:`chunkedYTextInsert`,source:n,branch:`D`,reason:c?.message??`unknown`,errorClass:yM(c),htmlBytes:r.length}),Fe.error(`Paste failed. Your selection has been restored.`)}export{v_ as $,Kb as A,Un as At,ly as B,Qb as C,K as Ct,fx as D,qn as Dt,Yb as E,Jn as Et,Zy as F,Ln as Ft,Gv as G,ry as H,Ky as I,In as It,Xv as J,Qv as K,Gy as L,Fn as Lt,Hb as M,Bn as Mt,Tb as N,zn as Nt,cx as O,Gn as Ot,Qy as P,Rn as Pt,x_ as Q,yy as R,Nx as S,or as St,Xb as T,Xn as Tt,ny as U,sy as V,ty as W,R_ as X,Z_ as Y,I_ as Z,Lx as _,Qi as _t,oM as a,om as at,kx as b,yi as bt,dA as c,Ru as ct,DD as d,ru as dt,S_ as et,pD as f,su as ft,lC as g,us as gt,xT as h,Mc as ht,VM as i,hm as it,Ub as j,Hn as jt,Gb as k,Wn as kt,BD as l,uu as lt,CE as m,jc as mt,ZM as n,A_ as nt,sM as o,ep as ot,tD as p,nu as pt,Yv as q,YM as r,l_ as rt,Xj as s,bl as st,nN as t,y_ as tt,LD as u,lu as ut,Ix as v,Zi as vt,Zb as w,nr as wt,Mx as x,_i as xt,Fx as y,mi as yt,_y as z};
|