@usememos/editor 26.10.30 → 26.11.1

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/index.js CHANGED
@@ -1,39 +1,39 @@
1
- var Ya=Object.defineProperty;var Ja=(o,e)=>{for(var t in e)Ya(o,t,{get:e[t],enumerable:!0})};var wi={};Ja(wi,{activeLink:()=>Qe,addColumn:()=>ti,addRow:()=>Jt,appendParagraph:()=>oi,applyAutolinkInputRule:()=>ki,applyBlockInputRules:()=>fi,applyInlineInputRules:()=>mi,applyTokenInputRules:()=>gi,balanceSections:()=>li,clampListIndents:()=>yi,cloneBlock:()=>dt,closeSections:()=>rn,convertibleBlocks:()=>zn,deleteBackward:()=>nn,deleteBlock:()=>Bt,deleteBlocks:()=>jn,deleteForward:()=>_n,deleteRange:()=>ye,deleteSelection:()=>J,dropBrokenTokens:()=>bi,duplicateBlock:()=>di,duplicateBlocks:()=>ui,exitBlock:()=>on,indentCode:()=>ln,indentListItems:()=>Wn,insertBlock:()=>Rt,insertBlocks:()=>Xn,insertFragment:()=>cn,insertLineBreak:()=>ii,insertText:()=>ue,insertToken:()=>ni,isMarkActive:()=>Vn,moveCell:()=>hi,nextGrapheme:()=>tn,previousGrapheme:()=>en,quoteRun:()=>Nt,replaceBlocks:()=>Gn,sectionEnd:()=>At,sectionTitle:()=>si,selectAll:()=>xi,selectImage:()=>je,selectedBlocks:()=>vi,selectedImage:()=>De,selectedImageBlock:()=>ke,setBlockType:()=>Ge,setCallout:()=>sn,setCodeLanguage:()=>ci,setLink:()=>ut,spanBlocks:()=>an,splitBlock:()=>Kn,splitCollapsedTitle:()=>ri,tableAction:()=>Zn,toggleBlockType:()=>ht,toggleMark:()=>We,toggleTask:()=>Qn,updateImage:()=>Un});var et=["bold","italic","strike","code","html"],Ke="\uFFFC",tt=5,Ve=["note","tip","important","warning","caution"],Wr=0,ec=Math.random().toString(36).slice(2,7);function ee(){return Wr+=1,`${ec}${Wr.toString(36)}`}function O(o=[],e=ee()){return{id:e,type:"paragraph",content:G(o)}}function nt(o,e=[],t=ee()){return{id:t,type:"heading",level:o,content:G(e)}}function Ue(o,e=[],t={}){let n={id:t.id??ee(),type:"listItem",listType:o,indent:Math.max(0,Math.min(5,t.indent??0)),checked:o==="task"?t.checked??!1:!1,content:G(e)},i=o==="ordered"&&t.start!==void 0&&t.start!==1?{...n,start:t.start}:n;return t.quote?U(i,t.quote):i}function Ne(o=[],e=ee(),t){let n={id:e,type:"quote",content:G(o)};return t?{...n,callout:t}:n}function Ee(o="",e="",t=ee()){return{id:t,type:"code",language:o,content:ge(e)}}function ot(o,e="",t=ee()){return{id:t,type:"raw",syntax:o,content:ge(e)}}function Dn(o="",e=ee()){return ot("html",o,e)}function zt(o,e,t=ee()){return{id:t,type:"table",align:o,rows:e.map(n=>o.map((i,r)=>G(n[r]??[])))}}function Qr(o=3,e=3,t=ee()){return zt(Array.from({length:e},()=>null),Array.from({length:o},()=>Array.from({length:e},()=>[])),t)}function it(o=ee()){return{id:o,type:"divider"}}function St(o=[],e={}){return{id:e.id??ee(),type:"details",open:e.open??!1,content:Ct(o)}}function Tt(o=ee()){return{id:o,type:"detailsEnd"}}function ge(o){return o?[{text:o,marks:[]}]:[]}function Wt(o){return o.type!=="paragraph"&&o.type!=="quote"&&o.type!=="details"&&o.type!=="detailsEnd"}function M(o){return o&&(o.type==="quote"||Wt(o)&&o.quote)?o.callout??"quote":null}function oe(o,e){let t=M(o);return t!==null&&t===M(e)&&!Et(e)}function Et(o){return M(o)!==null&&o.quoteStart===!0}function Qt(o){return M(o)===null||Et(o)?o:{...o,quoteStart:!0}}function On(o){if(!Et(o))return o;let{quoteStart:e,...t}=o;return t}function Re(o,e){return Et(o)?Qt(e):e}function U(o,e){if(M(o)===e)return o;if(o.type==="paragraph")return e?Ne(o.content,o.id,e==="quote"?void 0:e):o;if(o.type==="quote"){if(!e)return O(o.content,o.id);let{callout:l,...a}=o;return e==="quote"?a:{...a,callout:e}}if(!Wt(o))return o;let{quote:t,callout:n,quoteStart:i,...r}=o;if(!e)return r;let s=e==="quote"?{...r,quote:!0}:{...r,quote:!0,callout:e};return i?{...s,quoteStart:i}:s}function Mt(o){return U(o,null)}function q(o){return o.type!=="table"&&o.type!=="divider"&&o.type!=="detailsEnd"}function Z(o){return o.type==="divider"||o.type==="detailsEnd"}function Q(o){return o.type==="code"||o.type==="raw"||o.type==="details"}function Y(o){if(o.type!=="paragraph")return null;let e=null,t=0;for(let n of o.content){if(n.image){if(e!==null||n.link||n.marks.length>0)return null;e=t}else if(n.token||n.link||!/^[ \t]*$/.test(n.text))return null;t+=n.text.length}return e}function jr(o){return Y(o)!==null}function F(o,e){return o.type==="table"?e?o.rows[e.row]?.[e.col]??null:null:Z(o)?null:o.content}function ze(o,e,t){if(o.type==="table"){if(!e)return o;let n=o.rows.map((i,r)=>r===e.row?i.map((s,l)=>l===e.col?G(t):s):i);return{...o,rows:n}}return Z(o)?o:z(o,t)}function z(o,e){let t=Q(o)?Ct(e):G(e);return{...o,content:t}}function Ct(o){return ge(o.map(e=>e.image?e.image.alt:e.text).join(""))}function rt(o){let e=new Set(o);return et.filter(t=>e.has(t))}function jt(o,e){return o.length===e.length&&o.every((t,n)=>t===e[n])}function tc(o,e){return!o.image&&!e.image&&ae(o,e)&&o.token===e.token&&jt(o.marks,e.marks)}function ae(o,e){return o.link===e?.link&&o.linkTitle===e?.linkTitle}function I(o){return o.map(e=>e.text).join("")}function B(o){let e=0;for(let t of o)e+=t.text.length;return e}function Mf(o){let e=[[]];for(let t of o){let n=t.text.split(`
2
- `);for(let i=0;i<n.length;i++){i>0&&e.push([]);let r=n[i];r&&e[e.length-1].push(r===t.text?t:{...t,text:r})}}return e}function G(o){let e=[];for(let t of o){if(t.text.length===0)continue;let n=e[e.length-1];n&&tc(n,t)?e[e.length-1]={...n,text:n.text+t.text}:e.push(t)}return e}function C(o,e,t=1/0){let n=[],i=0;for(let r of o){let s=i+r.text.length,l=Math.max(e,i),a=Math.min(t,s);l<a&&n.push(l===i&&a===s?r:{...r,text:r.text.slice(l-i,a-i)}),i=s}return n}function ce(...o){return G(o.flat())}function wt(o,e){let t=0;for(let n of o){let i=t+n.text.length;if(e>=t&&e<i)return n;t=i}}function nc(o,e){let t=e>0?wt(o,e-1):wt(o,0);return t&&!t.image?t.marks:[]}function Gt(o,e){let t=nc(o,e),n=e>0?wt(o,e-1):void 0,i=wt(o,e),r=n?.link&&ae(n,i)?n:void 0,s=n?.token&&n.token===i?.token?n.token:void 0,l=r?{marks:t,...Qo(r)}:{marks:t};return s?{...l,token:s}:l}function Qo(o){return o.link?o.linkTitle===void 0?{link:o.link}:{link:o.link,linkTitle:o.linkTitle}:{}}function Gr(o,e,t,n){let i={text:t,marks:n.marks,...Qo(n)};return n.token&&(i={...i,token:n.token}),ce(C(o,0,e),[i],C(o,e))}function st(o,e,t){return ce(C(o,0,e),C(o,t))}function jo(o,e,t,n){let i=C(o,e,t).filter(r=>!r.image);return i.length>0&&i.every(r=>r.marks.includes(n))}function Zt(o,e,t,n,i){let r=C(o,e,t).map(s=>s.image?s:{...s,marks:i?rt([...s.marks,n]):s.marks.filter(l=>l!==n)});return ce(C(o,0,e),r,C(o,t))}function Zr(o,e,t,n){let i=C(o,e,t).map(r=>({...r,token:n}));return ce(C(o,0,e),i,C(o,t))}function Go(o,e,t,n){let i=C(o,e,t),r=i.find(l=>l.link!==void 0&&!l.image)?.linkTitle,s=i.map(l=>{if(l.image)return l;let{link:a,linkTitle:d,...u}=l;return n?{...u,...Qo({link:n,linkTitle:r})}:u});return ce(C(o,0,e),s,C(o,t))}function Xr(o,e){let t=[],n=0;for(let i of o){if(n>e)break;let r=n+i.text.length;i.token&&e<=r&&t.push({token:i.token,from:n}),n=r}return t}function Xt(o,e){let t=wt(o,e)??(e>0?wt(o,e-1):void 0);if(!t?.link)return null;let n=t.link,i=0,r=[];for(let l of o){let a=i+l.text.length;if(ae(l,t)){let d=r[r.length-1];d&&d.to===i?d.to=a:r.push({from:i,to:a})}i=a}let s=r.find(l=>e>=l.from&&e<=l.to);return s?{href:n,from:s.from,to:s.to}:null}function L(o,e){return o.blocks.findIndex(t=>t.id===e)}function N(o,e){let t=o.blocks.find(n=>n.id===e);if(!t)throw new Error(`Unknown block ${e}`);return t}function de(o,e){return o?.row===e?.row&&o?.col===e?.col}function be(o,e){return o.blockId===e.blockId&&o.offset===e.offset&&de(o.cell,e.cell)}function oc(o,e,t){return e.blockId!==t.blockId?L(o,e.blockId)-L(o,t.blockId):e.cell&&t.cell&&!de(e.cell,t.cell)?e.cell.row-t.cell.row||e.cell.col-t.cell.col:e.offset-t.offset}function R(o){return be(o.anchor,o.focus)}function Me(o,e){return oc(o,e.anchor,e.focus)<=0?{from:e.anchor,to:e.focus}:{from:e.focus,to:e.anchor}}function $(o,e,t){let n=t?{blockId:o,offset:e,cell:t}:{blockId:o,offset:e};return{anchor:n,focus:n}}function V(o){return o.type==="table"?{blockId:o.id,offset:0,cell:{row:0,col:0}}:{blockId:o.id,offset:0}}function P(o){if(o.type==="table"){let e=o.rows.length-1,t=o.align.length-1;return{blockId:o.id,offset:B(o.rows[e][t]),cell:{row:e,col:t}}}return Z(o)?{blockId:o.id,offset:0}:{blockId:o.id,offset:B(o.content)}}function te(o,e){let t=n=>{let i=o.blocks.find(s=>s.id===n.blockId);if(!i)return V(o.blocks[0]);let r=F(i,n.cell);return{...n,offset:Math.min(n.offset,r?B(r):0)}};return{anchor:t(e.anchor),focus:t(e.focus)}}function Hn(o){let e=o.blocks.length>0?o.blocks:[O()],t=e.find(q)??e[0],n=V(t);return{doc:{blocks:e},selection:{anchor:n,focus:n},storedMarks:null}}var Zo=/(?:https?|ftp):\/\//iy,Xo=/[A-Za-z0-9]/,ic=`?!.,:*_~'"`;function It(o,e){return o===void 0?!0:e?/[ \t\n\r*_~(]/.test(o):!/[A-Za-z]/.test(o)}function rc(o,e,t){let n=0,i=0,r=0,s=e+1;for(;s<o.length-1;s++){o[s]==="\\"&&s<o.length-2&&s++;let l=o[s];if(l==="_")r++;else if(l===".")i=r,r=0,n++;else if(!Xo.test(l)&&l!=="-")break}return(i>0||r>0)&&n<=10||t&&n===0?-1:s}function sc(o,e,t){let n=0,i=0;for(let r=e;r<t;r++)o[r]==="("?n++:o[r]===")"&&i++;for(;t>e;){let r=o[t-1];if(ic.includes(r))t--;else if(r===")"){if(i<=n)return t;i--,t--}else if(r===";"){let s=t-2;for(;s>e&&/[A-Za-z]/.test(o[s]);)s--;t=s<t-2&&o[s]==="&"?s:t-1}else return t}return t}function lt(o,e){let t,n=o.slice(e,e+4).toLowerCase()==="www.";if(n)t=e;else if(Zo.lastIndex=e,!Zo.test(o)||(t=Zo.lastIndex,!/[\p{L}\p{N}]/u.test(o[t]??"")))return null;let i=rc(o,t,n);if(i<0)return null;let r=i;for(;r<o.length&&!/[ \t\n\r<]/.test(o[r]);)r++;if(r=sc(o,e,r),r<=t)return null;let s=o.slice(e,r);return{end:r,href:n?"http://"+s:s}}function at(o){let e=[],t=0;for(let n=o.indexOf("@");n!==-1;n=o.indexOf("@",n+1)){let i=n;for(;i>t&&/[A-Za-z0-9.+\-_]/.test(o[i-1]);)i--;if(i===n)continue;let r=n,s=0,l=0;for(;r<o.length;r++){let a=o[r];if(!Xo.test(a)){if(a==="@"){if(++s>1)break}else if(a==="."&&Xo.test(o[r+1]??""))l++;else if(a!=="-"&&a!=="_")break}}r-n<2||s!==1||l===0||!/[A-Za-z]/.test(o[r-1])||(e.push({from:i,to:r}),t=r,n=r-1)}return e}function Yr(o){let e=lt(o,0);if(e)return e.end===o.length?e.href:null;let t=at(o);return t.length===1&&t[0].from===0&&t[0].to===o.length?"mailto:"+o:null}function lc(o){let e=[],t=0;for(let n of o){let i=t+n.text.length;if(ct(n)){let r=e[e.length-1];r&&r.to===t?r.to=i:e.push({from:t,to:i})}t=i}return e}function ct(o){return!!o.link||!!o.image||!!o.token||o.marks.includes("code")||o.marks.includes("html")}function Pn(o,e,t){return{block:o,cell:t,content:e,text:I(e),excluded:lc(e)}}function es(o,e,t){let n=0,i=t.length;for(;n<i;){let s=n+i>>1;t[s].to<=o?n=s+1:i=s}let r=t[n];return r!==void 0&&e>r.from}function ac(o,e){return o.from===e.from&&o.to===e.to&&o.class===e.class&&cc(o.attributes,e.attributes)}function $n(o,e){if(o.length!==e.length)return!1;for(let t=0;t<o.length;t++)if(!ac(o[t],e[t]))return!1;return!0}function cc(o,e){if(o===e)return!0;if(!o||!e)return!1;let t=Object.keys(o);return t.length===Object.keys(e).length&&t.every(n=>o[n]===e[n])}function Yo(o,e,t){let n=e.filter(c=>c.to>c.from);if(n.length===0){let c=0;return o.map(h=>{let f={span:h,decorations:[],atomic:!!t?.(h,c)};return c+=h.text.length,f})}let i=[...new Set(n.flatMap(c=>[c.from,c.to]))].sort((c,h)=>c-h),r=n.map((c,h)=>({d:c,index:h})).sort((c,h)=>c.d.from-h.d.from),s=0,l=[],a=(c,h)=>{for(;s<r.length&&r[s].d.from<=c;)l.push(r[s++]);for(let f=l.length-1;f>=0;f--)l[f].d.to<=c&&l.splice(f,1);return l.filter(f=>f.d.to>=h).sort((f,p)=>f.index-p.index).map(f=>f.d)},d=[],u=0;for(let c of o){let h=u+c.text.length,f=!!t?.(c,u),p=c.image||f?[]:i.slice(Jr(i,u),Jr(i,h-1)),m=u;for(let y of[...p,h]){let g=m===u&&y===h?c:{...c,text:c.text.slice(m-u,y-u)};d.push({span:g,decorations:a(m,y),atomic:f}),m=y}u=h}return d}function Jr(o,e){let t=0,n=o.length;for(;t<n;){let i=t+n>>1;o[i]<=e?t=i+1:n=i}return t}function D(o,e,t,...n){let i=o.doc.blocks.slice();return i.splice(e,t,...n),i}function H(o,e,t=o.selection){return{doc:{blocks:e},selection:t,storedMarks:null}}function j(o,e,t){let n=L(o.doc,e.id);return H(o,D(o,n,1,e),t)}function dt(o){return{...o,id:ee()}}function Ce(o,e){return F(o,e)??[]}function Fn(o){return o.type==="listItem"?Ue(o.listType,[],{indent:o.indent,quote:M(o)}):U(O(),M(o))}function ye(o,e,t){let n=L(o.doc,e.blockId),i=L(o.doc,t.blockId),r=o.doc.blocks[n],s=o.doc.blocks[i];if(n===i){if(Z(r))return o;if(r.type==="table")return dc(o,r,e,t);let c=st(r.content,e.offset,t.offset);return j(o,z(r,c),$(e.blockId,e.offset))}let l=q(r)?z(r,C(r.content,0,e.offset)):null,a=q(s)?C(s.content,t.offset):null,d,u;if(l)d=[a?z(l,ce(l.content,a)):l],u=$(l.id,e.offset);else if(a&&q(s))d=[z(s,a)],u=$(s.id,0);else{let c=O();d=[c],u=$(c.id,0)}return H(o,D(o,n,i-n+1,...d),u)}function dc(o,e,t,n){let i=t.cell??{row:0,col:0},r=n.cell??{row:e.rows.length-1,col:e.align.length-1},s=e.align.length,l=i.row*s+i.col,a=r.row*s+r.col,d=e.rows.map((u,c)=>u.map((h,f)=>{let p=c*s+f;if(p<l||p>a)return h;let m=p===l?t.offset:0,y=p===a?n.offset:B(h);return st(h,m,y)}));return j(o,{...e,rows:d},$(e.id,t.offset,i))}function J(o){if(R(o.selection))return o;let{from:e,to:t}=Me(o.doc,o.selection);return ye(o,e,t)}var qn=typeof Intl<"u"&&"Segmenter"in Intl?new Intl.Segmenter:null;function en(o,e){if(!qn)return Math.max(0,e-1);let t=0;for(let{index:n}of qn.segment(o)){if(n>=e)break;t=n}return t}function tn(o,e){if(!qn)return Math.min(o.length,e+1);for(let{index:t,segment:n}of qn.segment(o))if(t+n.length>e)return t+n.length;return o.length}function nn(o){if(!R(o.selection)){let s=ke(o);return s?Lt(o,L(o.doc,s.pos.blockId),-1):J(o)}let e=o.selection.focus,t=L(o.doc,e.blockId),n=o.doc.blocks[t];if(Z(n))return Lt(o,t,-1);if(e.offset>0){let s=I(Ce(n,e.cell)),l=en(s,e.offset);return ye(o,{...e,offset:l},e)}if(n.type==="table"){let s=e.cell,l=s.col>0?{row:s.row,col:s.col-1}:s.row>0?{row:s.row-1,col:n.align.length-1}:null;return l?{...o,selection:$(n.id,B(Ce(n,l)),l)}:o}if(n.type==="listItem"&&n.indent>0)return j(o,{...n,indent:n.indent-1});if(n.type!=="paragraph"){let s=n.type==="quote"?null:M(n);return j(o,Re(n,U(O(n.content,n.id),s)))}let i=o.doc.blocks[t-1];if(!i)return o;if(i.type==="detailsEnd"){let s=os(o.doc.blocks,t);if(!s)return o;let l={anchor:s,focus:s};return B(n.content)===0?H(o,D(o,t,1),l):{...o,selection:l,storedMarks:null}}if(i.type==="divider")return H(o,D(o,t-1,1));let r=Y(i);if(r!==null){let s=rs(i.id,r);return B(n.content)===0?H(o,D(o,t,1),s):{...o,selection:s,storedMarks:null}}if(i.type==="table"){let s=P(i),l={anchor:s,focus:s};return B(n.content)===0?H(o,D(o,t,1),l):{...o,selection:l}}return ye(o,P(i),{blockId:n.id,offset:0})}function _n(o){if(!R(o.selection)){let l=ke(o);return l?Lt(o,L(o.doc,l.pos.blockId),1):J(o)}let e=o.selection.focus,t=L(o.doc,e.blockId),n=o.doc.blocks[t];if(Z(n))return Lt(o,t,1);let i=I(Ce(n,e.cell));if(e.offset<i.length)return ye(o,e,{...e,offset:tn(i,e.offset)});if(n.type==="table")return o;let r=o.doc.blocks[t+1];if(!r||r.type==="table"||r.type==="detailsEnd")return o;if(r.type==="details")return B(Ce(n))===0?Lt(o,t,1):o;if(r.type==="divider")return H(o,D(o,t+1,1));let s=Y(r);if(s!==null){let l=rs(r.id,s);return n.type==="paragraph"&&B(n.content)===0?H(o,D(o,t,1),l):{...o,selection:l,storedMarks:null}}return ye(o,e,{blockId:r.id,offset:0})}function os(o,e){for(let t=e-1;t>=0;t--)if(!Z(o[t]))return P(o[t]);return null}function Lt(o,e,t){let n=D(o,e,1);if(n.length===0){let a=O();return H(o,[a],$(a.id,0))}let i=n[e-1],r=n[e],s=t===-1?i??r:r??i,l=s===i?P(s):V(s);return H(o,n,{anchor:l,focus:l})}function ue(o,e){let t=o.storedMarks,n=J(o),i=n.selection.focus,r=N(n.doc,i.blockId),s=F(r,i.cell);if(s===null)return o;let l=e;(r.type==="table"||r.type==="details")&&(l=l.replace(/\r?\n/g," "));let a=Q(r)?{marks:[]}:t?{marks:t}:Gt(s,i.offset),d=Gr(s,i.offset,l,a);return j(n,ze(r,i.cell,d),$(r.id,i.offset+l.length,i.cell))}function ni(o,e){let t=o.selection.focus,n=F(N(o.doc,t.blockId),t.cell);if(n===null)return o;let i=I(n),r=t.offset>0&&!/\s/.test(i[t.offset-1])?" ":"",s=i[t.offset]===" "||i[t.offset]===" ",l=ue({...o,selection:{anchor:t,focus:t}},r+e+(s?"":" "));if(!s)return l;let a={...l.selection.focus,offset:l.selection.focus.offset+1};return{...l,selection:{anchor:a,focus:a}}}function on(o,e){let t=ke(o);if(!R(o.selection)&&!t)return o;let n=t?.pos??o.selection.focus,i=L(o.doc,n.blockId),r=o.doc.blocks[i];if(r.type!=="code"&&r.type!=="table"&&r.type!=="divider"&&!t||i!==(e===1?o.doc.blocks.length-1:0))return o;if(r.type==="table"){if((n.cell?.row??-1)!==(e===1?r.rows.length-1:0))return o}else if(r.type==="code"){let l=I(r.content);if((e===1?l.slice(n.offset):l.slice(0,n.offset)).includes(`
3
- `))return o}let s=O();return H(o,D(o,e===1?i+1:0,0,s),$(s.id,0))}function oi(o){let e=O();return H(o,[...o.doc.blocks,e],$(e.id,0))}function ii(o){let e=N(o.doc,o.selection.focus.blockId);return e.type==="table"||Z(e)||e.type==="details"?o:ue(o,`
4
- `)}function Kn(o){let e=J(o),t=e.selection.focus,n=L(e.doc,t.blockId),i=e.doc.blocks[n];if(Z(i)){let c=O();return H(e,D(e,n+1,0,c),$(c.id,0))}if(i.type==="table")return uc(e,i,t);if(i.type==="details")return is(e,i,n,t.offset);let r=I(i.content),s=r.length;if(Q(i)){if(t.offset===s&&r.endsWith(`
1
+ var Ja=Object.defineProperty;var ec=(o,e)=>{for(var t in e)Ja(o,t,{get:e[t],enumerable:!0})};var wi={};ec(wi,{activeLink:()=>Qe,addColumn:()=>ti,addRow:()=>Jt,appendParagraph:()=>oi,applyAutolinkInputRule:()=>ki,applyBlockInputRules:()=>fi,applyInlineInputRules:()=>mi,applyTokenInputRules:()=>gi,balanceSections:()=>li,clampListIndents:()=>yi,cloneBlock:()=>dt,closeSections:()=>rn,convertibleBlocks:()=>zn,deleteBackward:()=>nn,deleteBlock:()=>Bt,deleteBlocks:()=>jn,deleteForward:()=>_n,deleteRange:()=>ye,deleteSelection:()=>J,dropBrokenTokens:()=>bi,duplicateBlock:()=>di,duplicateBlocks:()=>ui,exitBlock:()=>on,indentCode:()=>ln,indentListItems:()=>Wn,insertBlock:()=>Rt,insertBlocks:()=>Xn,insertFragment:()=>cn,insertLineBreak:()=>ii,insertText:()=>ue,insertToken:()=>ni,isMarkActive:()=>Vn,moveCell:()=>hi,nextGrapheme:()=>tn,previousGrapheme:()=>en,quoteRun:()=>Nt,replaceBlocks:()=>Gn,sectionEnd:()=>At,sectionTitle:()=>si,selectAll:()=>xi,selectImage:()=>je,selectedBlocks:()=>vi,selectedImage:()=>De,selectedImageBlock:()=>ke,setBlockType:()=>Ge,setCallout:()=>sn,setCodeLanguage:()=>ci,setLink:()=>ut,spanBlocks:()=>an,splitBlock:()=>Kn,splitCollapsedTitle:()=>ri,tableAction:()=>Zn,toggleBlockType:()=>ht,toggleMark:()=>We,toggleTask:()=>Qn,updateImage:()=>Un});var et=["bold","italic","strike","code","html"],Ke="\uFFFC",tt=5,Ve=["note","tip","important","warning","caution"],Wr=0,tc=Math.random().toString(36).slice(2,7);function ee(){return Wr+=1,`${tc}${Wr.toString(36)}`}function D(o=[],e=ee()){return{id:e,type:"paragraph",content:G(o)}}function nt(o,e=[],t=ee()){return{id:t,type:"heading",level:o,content:G(e)}}function Ue(o,e=[],t={}){let n={id:t.id??ee(),type:"listItem",listType:o,indent:Math.max(0,Math.min(5,t.indent??0)),checked:o==="task"?t.checked??!1:!1,content:G(e)},i=o==="ordered"&&t.start!==void 0&&t.start!==1?{...n,start:t.start}:n;return t.quote?U(i,t.quote):i}function Ne(o=[],e=ee(),t){let n={id:e,type:"quote",content:G(o)};return t?{...n,callout:t}:n}function Ee(o="",e="",t=ee()){return{id:t,type:"code",language:o,content:ge(e)}}function ot(o,e="",t=ee()){return{id:t,type:"raw",syntax:o,content:ge(e)}}function Dn(o="",e=ee()){return ot("html",o,e)}function zt(o,e,t=ee()){return{id:t,type:"table",align:o,rows:e.map(n=>o.map((i,r)=>G(n[r]??[])))}}function Qr(o=3,e=3,t=ee()){return zt(Array.from({length:e},()=>null),Array.from({length:o},()=>Array.from({length:e},()=>[])),t)}function it(o=ee()){return{id:o,type:"divider"}}function St(o=[],e={}){return{id:e.id??ee(),type:"details",open:e.open??!1,content:Ct(o)}}function Tt(o=ee()){return{id:o,type:"detailsEnd"}}function ge(o){return o?[{text:o,marks:[]}]:[]}function Wt(o){return o.type!=="paragraph"&&o.type!=="quote"&&o.type!=="details"&&o.type!=="detailsEnd"}function M(o){return o&&(o.type==="quote"||Wt(o)&&o.quote)?o.callout??"quote":null}function oe(o,e){let t=M(o);return t!==null&&t===M(e)&&!Et(e)}function Et(o){return M(o)!==null&&o.quoteStart===!0}function Qt(o){return M(o)===null||Et(o)?o:{...o,quoteStart:!0}}function On(o){if(!Et(o))return o;let{quoteStart:e,...t}=o;return t}function Re(o,e){return Et(o)?Qt(e):e}function U(o,e){if(M(o)===e)return o;if(o.type==="paragraph")return e?Ne(o.content,o.id,e==="quote"?void 0:e):o;if(o.type==="quote"){if(!e)return D(o.content,o.id);let{callout:l,...a}=o;return e==="quote"?a:{...a,callout:e}}if(!Wt(o))return o;let{quote:t,callout:n,quoteStart:i,...r}=o;if(!e)return r;let s=e==="quote"?{...r,quote:!0}:{...r,quote:!0,callout:e};return i?{...s,quoteStart:i}:s}function Mt(o){return U(o,null)}function q(o){return o.type!=="table"&&o.type!=="divider"&&o.type!=="detailsEnd"}function Z(o){return o.type==="divider"||o.type==="detailsEnd"}function Q(o){return o.type==="code"||o.type==="raw"||o.type==="details"}function Y(o){if(o.type!=="paragraph")return null;let e=null,t=0;for(let n of o.content){if(n.image){if(e!==null||n.link||n.marks.length>0)return null;e=t}else if(n.token||n.link||!/^[ \t]*$/.test(n.text))return null;t+=n.text.length}return e}function jr(o){return Y(o)!==null}function F(o,e){return o.type==="table"?e?o.rows[e.row]?.[e.col]??null:null:Z(o)?null:o.content}function ze(o,e,t){if(o.type==="table"){if(!e)return o;let n=o.rows.map((i,r)=>r===e.row?i.map((s,l)=>l===e.col?G(t):s):i);return{...o,rows:n}}return Z(o)?o:z(o,t)}function z(o,e){let t=Q(o)?Ct(e):G(e);return{...o,content:t}}function Ct(o){return ge(o.map(e=>e.image?e.image.alt:e.text).join(""))}function rt(o){let e=new Set(o);return et.filter(t=>e.has(t))}function jt(o,e){return o.length===e.length&&o.every((t,n)=>t===e[n])}function nc(o,e){return!o.image&&!e.image&&ae(o,e)&&o.token===e.token&&jt(o.marks,e.marks)}function ae(o,e){return o.link===e?.link&&o.linkTitle===e?.linkTitle}function I(o){return o.map(e=>e.text).join("")}function B(o){let e=0;for(let t of o)e+=t.text.length;return e}function Cf(o){let e=[[]];for(let t of o){let n=t.text.split(`
2
+ `);for(let i=0;i<n.length;i++){i>0&&e.push([]);let r=n[i];r&&e[e.length-1].push(r===t.text?t:{...t,text:r})}}return e}function G(o){let e=[];for(let t of o){if(t.text.length===0)continue;let n=e[e.length-1];n&&nc(n,t)?e[e.length-1]={...n,text:n.text+t.text}:e.push(t)}return e}function C(o,e,t=1/0){let n=[],i=0;for(let r of o){let s=i+r.text.length,l=Math.max(e,i),a=Math.min(t,s);l<a&&n.push(l===i&&a===s?r:{...r,text:r.text.slice(l-i,a-i)}),i=s}return n}function ce(...o){return G(o.flat())}function wt(o,e){let t=0;for(let n of o){let i=t+n.text.length;if(e>=t&&e<i)return n;t=i}}function oc(o,e){let t=e>0?wt(o,e-1):wt(o,0);return t&&!t.image?t.marks:[]}function Gt(o,e){let t=oc(o,e),n=e>0?wt(o,e-1):void 0,i=wt(o,e),r=n?.link&&ae(n,i)?n:void 0,s=n?.token&&n.token===i?.token?n.token:void 0,l=r?{marks:t,...Qo(r)}:{marks:t};return s?{...l,token:s}:l}function Qo(o){return o.link?o.linkTitle===void 0?{link:o.link}:{link:o.link,linkTitle:o.linkTitle}:{}}function Gr(o,e,t,n){let i={text:t,marks:n.marks,...Qo(n)};return n.token&&(i={...i,token:n.token}),ce(C(o,0,e),[i],C(o,e))}function st(o,e,t){return ce(C(o,0,e),C(o,t))}function jo(o,e,t,n){let i=C(o,e,t).filter(r=>!r.image);return i.length>0&&i.every(r=>r.marks.includes(n))}function Zt(o,e,t,n,i){let r=C(o,e,t).map(s=>s.image?s:{...s,marks:i?rt([...s.marks,n]):s.marks.filter(l=>l!==n)});return ce(C(o,0,e),r,C(o,t))}function Zr(o,e,t,n){let i=C(o,e,t).map(r=>({...r,token:n}));return ce(C(o,0,e),i,C(o,t))}function Go(o,e,t,n){let i=C(o,e,t),r=i.find(l=>l.link!==void 0&&!l.image)?.linkTitle,s=i.map(l=>{if(l.image)return l;let{link:a,linkTitle:d,...u}=l;return n?{...u,...Qo({link:n,linkTitle:r})}:u});return ce(C(o,0,e),s,C(o,t))}function Xr(o,e){let t=[],n=0;for(let i of o){if(n>e)break;let r=n+i.text.length;i.token&&e<=r&&t.push({token:i.token,from:n}),n=r}return t}function Xt(o,e){let t=wt(o,e)??(e>0?wt(o,e-1):void 0);if(!t?.link)return null;let n=t.link,i=0,r=[];for(let l of o){let a=i+l.text.length;if(ae(l,t)){let d=r[r.length-1];d&&d.to===i?d.to=a:r.push({from:i,to:a})}i=a}let s=r.find(l=>e>=l.from&&e<=l.to);return s?{href:n,from:s.from,to:s.to}:null}function L(o,e){return o.blocks.findIndex(t=>t.id===e)}function N(o,e){let t=o.blocks.find(n=>n.id===e);if(!t)throw new Error(`Unknown block ${e}`);return t}function de(o,e){return o?.row===e?.row&&o?.col===e?.col}function be(o,e){return o.blockId===e.blockId&&o.offset===e.offset&&de(o.cell,e.cell)}function ic(o,e,t){return e.blockId!==t.blockId?L(o,e.blockId)-L(o,t.blockId):e.cell&&t.cell&&!de(e.cell,t.cell)?e.cell.row-t.cell.row||e.cell.col-t.cell.col:e.offset-t.offset}function R(o){return be(o.anchor,o.focus)}function Me(o,e){return ic(o,e.anchor,e.focus)<=0?{from:e.anchor,to:e.focus}:{from:e.focus,to:e.anchor}}function $(o,e,t){let n=t?{blockId:o,offset:e,cell:t}:{blockId:o,offset:e};return{anchor:n,focus:n}}function V(o){return o.type==="table"?{blockId:o.id,offset:0,cell:{row:0,col:0}}:{blockId:o.id,offset:0}}function P(o){if(o.type==="table"){let e=o.rows.length-1,t=o.align.length-1;return{blockId:o.id,offset:B(o.rows[e][t]),cell:{row:e,col:t}}}return Z(o)?{blockId:o.id,offset:0}:{blockId:o.id,offset:B(o.content)}}function te(o,e){let t=n=>{let i=o.blocks.find(s=>s.id===n.blockId);if(!i)return V(o.blocks[0]);let r=F(i,n.cell);return{...n,offset:Math.min(n.offset,r?B(r):0)}};return{anchor:t(e.anchor),focus:t(e.focus)}}function Hn(o){let e=o.blocks.length>0?o.blocks:[D()],t=e.find(q)??e[0],n=V(t);return{doc:{blocks:e},selection:{anchor:n,focus:n},storedMarks:null}}var Zo=/(?:https?|ftp):\/\//iy,Xo=/[A-Za-z0-9]/,rc=`?!.,:*_~'"`;function It(o,e){return o===void 0?!0:e?/[ \t\n\r*_~(]/.test(o):!/[A-Za-z]/.test(o)}function sc(o,e,t){let n=0,i=0,r=0,s=e+1;for(;s<o.length-1;s++){o[s]==="\\"&&s<o.length-2&&s++;let l=o[s];if(l==="_")r++;else if(l===".")i=r,r=0,n++;else if(!Xo.test(l)&&l!=="-")break}return(i>0||r>0)&&n<=10||t&&n===0?-1:s}function lc(o,e,t){let n=0,i=0;for(let r=e;r<t;r++)o[r]==="("?n++:o[r]===")"&&i++;for(;t>e;){let r=o[t-1];if(rc.includes(r))t--;else if(r===")"){if(i<=n)return t;i--,t--}else if(r===";"){let s=t-2;for(;s>e&&/[A-Za-z]/.test(o[s]);)s--;t=s<t-2&&o[s]==="&"?s:t-1}else return t}return t}function lt(o,e){let t,n=o.slice(e,e+4).toLowerCase()==="www.";if(n)t=e;else if(Zo.lastIndex=e,!Zo.test(o)||(t=Zo.lastIndex,!/[\p{L}\p{N}]/u.test(o[t]??"")))return null;let i=sc(o,t,n);if(i<0)return null;let r=i;for(;r<o.length&&!/[ \t\n\r<]/.test(o[r]);)r++;if(r=lc(o,e,r),r<=t)return null;let s=o.slice(e,r);return{end:r,href:n?"http://"+s:s}}function at(o){let e=[],t=0;for(let n=o.indexOf("@");n!==-1;n=o.indexOf("@",n+1)){let i=n;for(;i>t&&/[A-Za-z0-9.+\-_]/.test(o[i-1]);)i--;if(i===n)continue;let r=n,s=0,l=0;for(;r<o.length;r++){let a=o[r];if(!Xo.test(a)){if(a==="@"){if(++s>1)break}else if(a==="."&&Xo.test(o[r+1]??""))l++;else if(a!=="-"&&a!=="_")break}}r-n<2||s!==1||l===0||!/[A-Za-z]/.test(o[r-1])||(e.push({from:i,to:r}),t=r,n=r-1)}return e}function Yr(o){let e=lt(o,0);if(e)return e.end===o.length?e.href:null;let t=at(o);return t.length===1&&t[0].from===0&&t[0].to===o.length?"mailto:"+o:null}function ac(o){let e=[],t=0;for(let n of o){let i=t+n.text.length;if(ct(n)){let r=e[e.length-1];r&&r.to===t?r.to=i:e.push({from:t,to:i})}t=i}return e}function ct(o){return!!o.link||!!o.image||!!o.token||o.marks.includes("code")||o.marks.includes("html")}function Pn(o,e,t){return{block:o,cell:t,content:e,text:I(e),excluded:ac(e)}}function es(o,e,t){let n=0,i=t.length;for(;n<i;){let s=n+i>>1;t[s].to<=o?n=s+1:i=s}let r=t[n];return r!==void 0&&e>r.from}function cc(o,e){return o.from===e.from&&o.to===e.to&&o.class===e.class&&dc(o.attributes,e.attributes)}function $n(o,e){if(o.length!==e.length)return!1;for(let t=0;t<o.length;t++)if(!cc(o[t],e[t]))return!1;return!0}function dc(o,e){if(o===e)return!0;if(!o||!e)return!1;let t=Object.keys(o);return t.length===Object.keys(e).length&&t.every(n=>o[n]===e[n])}function Yo(o,e,t){let n=e.filter(c=>c.to>c.from);if(n.length===0){let c=0;return o.map(h=>{let f={span:h,decorations:[],atomic:!!t?.(h,c)};return c+=h.text.length,f})}let i=[...new Set(n.flatMap(c=>[c.from,c.to]))].sort((c,h)=>c-h),r=n.map((c,h)=>({d:c,index:h})).sort((c,h)=>c.d.from-h.d.from),s=0,l=[],a=(c,h)=>{for(;s<r.length&&r[s].d.from<=c;)l.push(r[s++]);for(let f=l.length-1;f>=0;f--)l[f].d.to<=c&&l.splice(f,1);return l.filter(f=>f.d.to>=h).sort((f,p)=>f.index-p.index).map(f=>f.d)},d=[],u=0;for(let c of o){let h=u+c.text.length,f=!!t?.(c,u),p=c.image||f?[]:i.slice(Jr(i,u),Jr(i,h-1)),m=u;for(let y of[...p,h]){let g=m===u&&y===h?c:{...c,text:c.text.slice(m-u,y-u)};d.push({span:g,decorations:a(m,y),atomic:f}),m=y}u=h}return d}function Jr(o,e){let t=0,n=o.length;for(;t<n;){let i=t+n>>1;o[i]<=e?t=i+1:n=i}return t}function O(o,e,t,...n){let i=o.doc.blocks.slice();return i.splice(e,t,...n),i}function H(o,e,t=o.selection){return{doc:{blocks:e},selection:t,storedMarks:null}}function j(o,e,t){let n=L(o.doc,e.id);return H(o,O(o,n,1,e),t)}function dt(o){return{...o,id:ee()}}function Ce(o,e){return F(o,e)??[]}function Fn(o){return o.type==="listItem"?Ue(o.listType,[],{indent:o.indent,quote:M(o)}):U(D(),M(o))}function ye(o,e,t){let n=L(o.doc,e.blockId),i=L(o.doc,t.blockId),r=o.doc.blocks[n],s=o.doc.blocks[i];if(n===i){if(Z(r))return o;if(r.type==="table")return uc(o,r,e,t);let c=st(r.content,e.offset,t.offset);return j(o,z(r,c),$(e.blockId,e.offset))}let l=q(r)?z(r,C(r.content,0,e.offset)):null,a=q(s)?C(s.content,t.offset):null,d,u;if(l)d=[a?z(l,ce(l.content,a)):l],u=$(l.id,e.offset);else if(a&&q(s))d=[z(s,a)],u=$(s.id,0);else{let c=D();d=[c],u=$(c.id,0)}return H(o,O(o,n,i-n+1,...d),u)}function uc(o,e,t,n){let i=t.cell??{row:0,col:0},r=n.cell??{row:e.rows.length-1,col:e.align.length-1},s=e.align.length,l=i.row*s+i.col,a=r.row*s+r.col,d=e.rows.map((u,c)=>u.map((h,f)=>{let p=c*s+f;if(p<l||p>a)return h;let m=p===l?t.offset:0,y=p===a?n.offset:B(h);return st(h,m,y)}));return j(o,{...e,rows:d},$(e.id,t.offset,i))}function J(o){if(R(o.selection))return o;let{from:e,to:t}=Me(o.doc,o.selection);return ye(o,e,t)}var qn=typeof Intl<"u"&&"Segmenter"in Intl?new Intl.Segmenter:null;function en(o,e){if(!qn)return Math.max(0,e-1);let t=0;for(let{index:n}of qn.segment(o)){if(n>=e)break;t=n}return t}function tn(o,e){if(!qn)return Math.min(o.length,e+1);for(let{index:t,segment:n}of qn.segment(o))if(t+n.length>e)return t+n.length;return o.length}function nn(o){if(!R(o.selection)){let s=ke(o);return s?Lt(o,L(o.doc,s.pos.blockId),-1):J(o)}let e=o.selection.focus,t=L(o.doc,e.blockId),n=o.doc.blocks[t];if(Z(n))return Lt(o,t,-1);if(e.offset>0){let s=I(Ce(n,e.cell)),l=en(s,e.offset);return ye(o,{...e,offset:l},e)}if(n.type==="table"){let s=e.cell,l=s.col>0?{row:s.row,col:s.col-1}:s.row>0?{row:s.row-1,col:n.align.length-1}:null;return l?{...o,selection:$(n.id,B(Ce(n,l)),l)}:o}if(n.type==="listItem"&&n.indent>0)return j(o,{...n,indent:n.indent-1});if(n.type!=="paragraph"){let s=n.type==="quote"?null:M(n);return j(o,Re(n,U(D(n.content,n.id),s)))}let i=o.doc.blocks[t-1];if(!i)return o;if(i.type==="detailsEnd"){let s=os(o.doc.blocks,t);if(!s)return o;let l={anchor:s,focus:s};return B(n.content)===0?H(o,O(o,t,1),l):{...o,selection:l,storedMarks:null}}if(i.type==="divider")return H(o,O(o,t-1,1));let r=Y(i);if(r!==null){let s=rs(i.id,r);return B(n.content)===0?H(o,O(o,t,1),s):{...o,selection:s,storedMarks:null}}if(i.type==="table"){let s=P(i),l={anchor:s,focus:s};return B(n.content)===0?H(o,O(o,t,1),l):{...o,selection:l}}return ye(o,P(i),{blockId:n.id,offset:0})}function _n(o){if(!R(o.selection)){let l=ke(o);return l?Lt(o,L(o.doc,l.pos.blockId),1):J(o)}let e=o.selection.focus,t=L(o.doc,e.blockId),n=o.doc.blocks[t];if(Z(n))return Lt(o,t,1);let i=I(Ce(n,e.cell));if(e.offset<i.length)return ye(o,e,{...e,offset:tn(i,e.offset)});if(n.type==="table")return o;let r=o.doc.blocks[t+1];if(!r||r.type==="table"||r.type==="detailsEnd")return o;if(r.type==="details")return B(Ce(n))===0?Lt(o,t,1):o;if(r.type==="divider")return H(o,O(o,t+1,1));let s=Y(r);if(s!==null){let l=rs(r.id,s);return n.type==="paragraph"&&B(n.content)===0?H(o,O(o,t,1),l):{...o,selection:l,storedMarks:null}}return ye(o,e,{blockId:r.id,offset:0})}function os(o,e){for(let t=e-1;t>=0;t--)if(!Z(o[t]))return P(o[t]);return null}function Lt(o,e,t){let n=O(o,e,1);if(n.length===0){let a=D();return H(o,[a],$(a.id,0))}let i=n[e-1],r=n[e],s=t===-1?i??r:r??i,l=s===i?P(s):V(s);return H(o,n,{anchor:l,focus:l})}function ue(o,e){let t=o.storedMarks,n=J(o),i=n.selection.focus,r=N(n.doc,i.blockId),s=F(r,i.cell);if(s===null)return o;let l=e;(r.type==="table"||r.type==="details")&&(l=l.replace(/\r?\n/g," "));let a=Q(r)?{marks:[]}:t?{marks:t}:Gt(s,i.offset),d=Gr(s,i.offset,l,a);return j(n,ze(r,i.cell,d),$(r.id,i.offset+l.length,i.cell))}function ni(o,e){let t=o.selection.focus,n=F(N(o.doc,t.blockId),t.cell);if(n===null)return o;let i=I(n),r=t.offset>0&&!/\s/.test(i[t.offset-1])?" ":"",s=i[t.offset]===" "||i[t.offset]===" ",l=ue({...o,selection:{anchor:t,focus:t}},r+e+(s?"":" "));if(!s)return l;let a={...l.selection.focus,offset:l.selection.focus.offset+1};return{...l,selection:{anchor:a,focus:a}}}function on(o,e){let t=ke(o);if(!R(o.selection)&&!t)return o;let n=t?.pos??o.selection.focus,i=L(o.doc,n.blockId),r=o.doc.blocks[i];if(r.type!=="code"&&r.type!=="table"&&r.type!=="divider"&&!t||i!==(e===1?o.doc.blocks.length-1:0))return o;if(r.type==="table"){if((n.cell?.row??-1)!==(e===1?r.rows.length-1:0))return o}else if(r.type==="code"){let l=I(r.content);if((e===1?l.slice(n.offset):l.slice(0,n.offset)).includes(`
3
+ `))return o}let s=D();return H(o,O(o,e===1?i+1:0,0,s),$(s.id,0))}function oi(o){let e=D();return H(o,[...o.doc.blocks,e],$(e.id,0))}function ii(o){let e=N(o.doc,o.selection.focus.blockId);return e.type==="table"||Z(e)||e.type==="details"?o:ue(o,`
4
+ `)}function Kn(o){let e=J(o),t=e.selection.focus,n=L(e.doc,t.blockId),i=e.doc.blocks[n];if(Z(i)){let c=D();return H(e,O(e,n+1,0,c),$(c.id,0))}if(i.type==="table")return hc(e,i,t);if(i.type==="details")return is(e,i,n,t.offset);let r=I(i.content),s=r.length;if(Q(i)){if(t.offset===s&&r.endsWith(`
5
5
 
6
- `)){let c=z(i,C(i.content,0,s-2)),h=U(O(),M(i));return H(e,D(e,n,1,c,h),$(h.id,0))}return ue(e,`
7
- `)}let l=(i.type==="paragraph"||i.type==="quote")&&t.offset===s?/^```([^`\s]*)$/.exec(r):null;if(l){let c=Re(i,U(Ee(l[1],"",i.id),M(i)));return j(e,c,$(c.id,0))}if(s===0&&i.type==="listItem"){let c=i.indent>0?{...i,indent:i.indent-1}:i.quote?Re(i,Ne([],i.id,i.callout)):O([],i.id);return j(e,c)}if(s===0&&i.type==="quote")return j(e,O([],i.id));if(s===0&&i.type==="paragraph"&&e.doc.blocks[n+1]?.type==="detailsEnd"){let c=e.doc.blocks.slice();return c.splice(n,1),c.splice(n+1,0,i),H(e,c,e.selection)}if(t.offset===0&&s>0)return Et(i)?H(e,D(e,n,1,Re(i,Fn(i)),On(i)),e.selection):H(e,D(e,n,0,Fn(i)),e.selection);let a=z(i,C(i.content,0,t.offset)),d=C(i.content,t.offset),u;return i.type==="heading"?u=U(d.length>0?nt(i.level,d):O(),M(i)):u=z(Fn(i),d),H(e,D(e,n,1,a,u),$(u.id,0))}function is(o,e,t,n,i=!1){let r=B(e.content);if(n===0&&r>0)return H(o,D(o,t,0,O()),o.selection);let s=o.doc.blocks[t+1];if(!i&&n===r&&s?.type==="paragraph"&&B(s.content)===0)return{...o,selection:$(s.id,0),storedMarks:null};let l=z(e,C(e.content,0,n)),a=O(C(e.content,n)),d=o.doc.blocks.slice();return d[t]=l,d.splice(i?(At(d,t)??t)+1:t+1,0,a),H(o,d,$(a.id,0))}function ri(o){let e=J(o),t=e.selection.focus,n=L(e.doc,t.blockId),i=e.doc.blocks[n];return i.type==="details"?is(e,i,n,t.offset,!0):Kn(o)}function At(o,e){let t=0;for(let n=e;n<o.length;n++){let i=o[n].type;if(i==="details")t++;else if(i==="detailsEnd"&&--t===0)return n}return null}function si(o,e){let t=0;for(let n=e;n>=0;n--){let i=o[n].type;if(i==="detailsEnd")t++;else if(i==="details"&&--t===0)return n}return null}function rn(o){if(!o.some(r=>r.type==="details"||r.type==="detailsEnd"))return o;let e=[],t=new Set;if(o.forEach((r,s)=>{r.type==="details"?e.push(s):r.type==="detailsEnd"&&e.pop()===void 0&&t.add(s)}),t.size===0&&e.length===0)return o;let n=new Set(e),i=[];return o.forEach((r,s)=>{t.has(s)||i.push(n.has(s)&&r.type==="details"?O(r.content,r.id):r)}),i.length>0?i:[O()]}function li(o){if(!o.doc.blocks.some(l=>l.type==="details"||l.type==="detailsEnd"))return o;let e=rn(o.doc.blocks),t=o;if(e!==o.doc.blocks){let l={blocks:e};t={...o,doc:l,selection:te(l,o.selection)}}let n=l=>t.doc.blocks.find(a=>a.id===l.blockId)?.type==="detailsEnd",{anchor:i,focus:r}=t.selection;if(!n(i)&&!n(r))return t;let s=l=>n(l)?os(t.doc.blocks,L(t.doc,l.blockId))??l:l;return{...t,selection:{anchor:s(i),focus:s(r)}}}function uc(o,e,t){let n=t.cell,i=e;n.row===e.rows.length-1&&(i=Jt(e,n.row+1));let r={row:n.row+1,col:n.col};return j(o,i,$(i.id,0,r))}function ai(o,e,t,n){let i=L(o.doc,e.blockId),r=L(o.doc,t.blockId),s=o.doc.blocks.slice(i,r+1).map(l=>{if(Z(l)||Q(l))return l;if(l.type==="table"){let c=l.align.length,h=l.id===e.blockId&&e.cell?e.cell.row*c+e.cell.col:0,f=l.id===t.blockId&&t.cell?t.cell.row*c+t.cell.col:1/0,p=l.rows.map((m,y)=>m.map((g,x)=>{let b=y*c+x;if(b<h||b>f)return g;let w=b===h&&l.id===e.blockId?e.offset:0,k=b===f&&l.id===t.blockId?t.offset:B(g);return w<k?ts(g,n(g,w,k)):g}));return p.every((m,y)=>m.every((g,x)=>g===l.rows[y][x]))?l:{...l,rows:p}}let a=l.id===e.blockId?e.offset:0,d=l.id===t.blockId?t.offset:B(l.content);if(a>=d)return l;let u=ts(l.content,n(l.content,a,d));return u===l.content?l:z(l,u)});return D(o,i,s.length,...s)}function ts(o,e){if(o.length!==e.length)return e;for(let t=0;t<o.length;t++){let n=o[t],i=e[t];if(n.text!==i.text||!ae(n,i)||n.token!==i.token||n.image!==i.image||!jt(n.marks,i.marks))return e}return o}function Vn(o,e){if(R(o.selection)){let r=o.selection.focus,s=N(o.doc,r.blockId);return(o.storedMarks??Gt(Ce(s,r.cell),r.offset).marks).includes(e)}let{from:t,to:n}=Me(o.doc,o.selection),i=[];return ai(o,t,n,(r,s,l)=>(i.push(jo(r,s,l,e)),r)),i.length>0&&i.every(Boolean)}function We(o,e){let{from:t,to:n}=Me(o.doc,o.selection);if(R(o.selection)){let s=N(o.doc,t.blockId);if(Q(s))return o;let l=o.storedMarks??Gt(Ce(s,t.cell),t.offset).marks,a=l.includes(e)?l.filter(d=>d!==e):rt([...l,e]);return{...o,storedMarks:a}}let i=!Vn(o,e),r=ai(o,t,n,(s,l,a)=>Zt(s,l,a,e,i));return{...o,doc:{blocks:r},storedMarks:null}}function Qe(o){let{from:e}=Me(o.doc,o.selection),t=N(o.doc,e.blockId),n=F(t,e.cell);if(!n)return null;let i=Xt(n,e.offset);return i?{...i,pos:e}:null}function ut(o,e){let t,n;if(R(o.selection)){let r=Qe(o);if(!r)return o;t={...r.pos,offset:r.from},n={...r.pos,offset:r.to}}else({from:t,to:n}=Me(o.doc,o.selection));let i=ai(o,t,n,(r,s,l)=>Go(r,s,l,e));return{...o,doc:{blocks:i},storedMarks:null}}function De(o){let{anchor:e,focus:t}=o.selection;if(e.blockId!==t.blockId||!de(e.cell,t.cell)||Math.abs(e.offset-t.offset)!==1)return null;let n=Math.min(e.offset,t.offset),i=F(N(o.doc,e.blockId),e.cell),r=i?C(i,n,n+1)[0]?.image:void 0;return r?{pos:{...e,offset:n},image:r}:null}function rs(o,e){return{anchor:{blockId:o,offset:e},focus:{blockId:o,offset:e+1}}}function ke(o){let e=De(o);return!e||e.pos.cell?null:Y(N(o.doc,e.pos.blockId))===e.pos.offset?e:null}function je(o,e){let t=o.doc.blocks.find(i=>i.id===e.blockId),n=t&&F(t,e.cell);return!n||!C(n,e.offset,e.offset+1)[0]?.image?o:{...o,selection:{anchor:e,focus:{...e,offset:e.offset+1}},storedMarks:null}}function Un(o,e,t){let n=o.doc.blocks.find(b=>b.id===e.blockId),i=n&&F(n,e.cell),r=i?C(i,e.offset,e.offset+1)[0]:void 0;if(!n||!i||!r?.image)return o;let{title:s,align:l,width:a,height:d,...u}=r.image,c=r.image.title;t.title!==void 0&&(c=t.title||void 0);let h=t.align!==void 0?t.align??void 0:r.image.align,f=r.image.width,p=r.image.height;t.width!==void 0&&(f=t.width===null?void 0:Math.max(1,Math.min(99999,Math.round(t.width))),f!==r.image.width&&(p=void 0));let m={...u,...t.alt!==void 0?{alt:t.alt}:{},...c?{title:c}:{},...h?{align:h}:{},...f?{width:f}:{},...f&&p?{height:p}:{}},y=je(o,e).selection;if(m.alt===r.image.alt&&m.title===r.image.title&&m.align===r.image.align&&m.width===r.image.width&&m.height===r.image.height)return y===o.selection?o:{...o,selection:y,storedMarks:null};let x=ce(C(i,0,e.offset),[{...r,text:"\uFFFC",image:m}],C(i,e.offset+1));return j(o,ze(n,e.cell,x),y)}function ss(o,e){return Re(o,hc(o,e))}function hc(o,e){let t=M(o);if(e.type==="quote")return U(o,e.callout??t??"quote");let n=o.content,i;switch(e.type){case"paragraph":if(i=O(n,o.id),o.type==="quote")return i;break;case"heading":i=nt(e.level,n,o.id);break;case"listItem":i=Ue(e.listType,n,{id:o.id,indent:o.type==="listItem"?o.indent:0,checked:o.type==="listItem"?o.checked:!1,start:o.type==="listItem"&&o.listType===e.listType?o.start:void 0});break;case"code":i=Ee(e.language??(o.type==="code"?o.language:""),I(Ct(n)),o.id);break;default:return o}return U(i,t)}function Yt(o){return q(o)&&o.type!=="raw"}function Ge(o,e){return e.type==="table"||e.type==="divider"||e.type==="details"?Rt(o,e):ls(o,e,t=>ss(t,e))}function ls(o,e,t){let{from:n,to:i}=Me(o.doc,o.selection),r=L(o.doc,n.blockId),s=L(o.doc,i.blockId),l=o.doc.blocks.slice(r,s+1);if(e.type==="code"&&l.filter(Yt).length>1)return fc(o,r,l,e.language);let a=l.map(u=>Yt(u)?t(u):u),d={blocks:D(o,r,a.length,...a)};return{doc:d,selection:te(d,o.selection),storedMarks:null}}function fc(o,e,t,n){let i=[],r=[],s=[],l=()=>{let d=s[0];if(!d)return;let u=s.map(h=>I(Ct(h.content))).join(`
8
- `),c=U(Ee(n??(d.type==="code"?d.language:""),u,d.id),M(d));i.push(c),r.push(c),s=[]};for(let d of t)Yt(d)?s.push(d):(l(),i.push(d));l();let a={anchor:V(r[0]),focus:P(r[r.length-1])};return{doc:{blocks:D(o,e,t.length,...i)},selection:a,storedMarks:null}}function Nt(o,e){let t=o.doc.blocks,n=L(o.doc,e),i=t[n];if(M(i)===null)return null;let r=n,s=n;for(;oe(t[r-1],t[r]);)r--;for(;oe(t[s],t[s+1]);)s++;return{start:r,end:s}}function sn(o,e,t){let n=Nt(o,e);if(!n)return o;let i=o.doc.blocks.slice(n.start,n.end+1);if(i.every(l=>M(l)===(t??"quote")))return o;let r=i.map(l=>U(l,t??"quote"));return{doc:{blocks:D(o,n.start,r.length,...r)},selection:o.selection,storedMarks:o.storedMarks}}function zn(o){let{from:e,to:t}=Me(o.doc,o.selection);return o.doc.blocks.slice(L(o.doc,e.blockId),L(o.doc,t.blockId)+1).filter(Yt)}function pc(o,e){switch(e.type){case"heading":return o.type==="heading"&&o.level===e.level;case"listItem":return o.type==="listItem"&&o.listType===e.listType;case"code":return o.type==="code";case"quote":{let t=M(o);return t!==null&&(!e.callout||t===e.callout)}default:return o.type===e.type}}function ht(o,e){let t=zn(o);if(t.length===0)return o;if(!t.every(r=>pc(r,e)))return Ge(o,e);let i={type:"paragraph"};return ls(o,i,r=>e.type==="quote"?U(r,null):ss(r,i))}function Rt(o,e){let t=o.selection.focus,n=L(o.doc,t.blockId),i=o.doc.blocks[n];if(e.type==="details")return mc(o,n);if(e.type!=="table"&&e.type!=="divider")return Ge(o,e);let r=q(i)&&B(i.content)===0,s=M(i),l=U(e.type==="table"?Qr(e.rows??3,e.cols??3):it(),s),a=[r?Re(i,l):l],d=l;if(l.type==="divider"){let h=o.doc.blocks[n+1];h&&q(h)?d=h:(d=U(O(),s),a.push(d))}let u=V(d),c=r?n:n+1;return H(o,D(o,c,r?1:0,...a),{anchor:u,focus:u})}function mc(o,e){let t=o.doc.blocks[e],n=Yt(t)&&t.type!=="details",i=St(n?t.content:[],n?{id:t.id}:{}),r=O(),s=n?e:e+1,l=D(o,s,n?1:0,i,r,Tt()),a=B(i.content)===0?$(i.id,0):$(r.id,0);return H(o,l,a)}function Wn(o,e){let{from:t,to:n}=Me(o.doc,o.selection),i=L(o.doc,t.blockId),r=L(o.doc,n.blockId),s=!1,l=o.doc.blocks.slice();for(let a=i;a<=r;a++){let d=l[a];if(d.type!=="listItem")continue;let u=as(l[a-1],d),c=Math.max(0,Math.min(u,d.indent+e));c!==d.indent&&(l[a]={...d,indent:c},s=!0)}return s?H(o,l):o}var Jo=" ";function ln(o,e){let{anchor:t,focus:n}=o.selection;if(t.blockId!==n.blockId)return o;let i=N(o.doc,n.blockId);if(i.type!=="code")return o;if(e===1&&R(o.selection))return ue(o,Jo);let r=I(i.content),s=Math.min(t.offset,n.offset),l=Math.max(t.offset,n.offset),a=[];for(let f=r.lastIndexOf(`
6
+ `)){let c=z(i,C(i.content,0,s-2)),h=U(D(),M(i));return H(e,O(e,n,1,c,h),$(h.id,0))}return ue(e,`
7
+ `)}let l=(i.type==="paragraph"||i.type==="quote")&&t.offset===s?/^```([^`\s]*)$/.exec(r):null;if(l){let c=Re(i,U(Ee(l[1],"",i.id),M(i)));return j(e,c,$(c.id,0))}if(s===0&&i.type==="listItem"){let c=i.indent>0?{...i,indent:i.indent-1}:i.quote?Re(i,Ne([],i.id,i.callout)):D([],i.id);return j(e,c)}if(s===0&&i.type==="quote")return j(e,D([],i.id));if(s===0&&i.type==="paragraph"&&e.doc.blocks[n+1]?.type==="detailsEnd"){let c=e.doc.blocks.slice();return c.splice(n,1),c.splice(n+1,0,i),H(e,c,e.selection)}if(t.offset===0&&s>0)return Et(i)?H(e,O(e,n,1,Re(i,Fn(i)),On(i)),e.selection):H(e,O(e,n,0,Fn(i)),e.selection);let a=z(i,C(i.content,0,t.offset)),d=C(i.content,t.offset),u;return i.type==="heading"?u=U(d.length>0?nt(i.level,d):D(),M(i)):u=z(Fn(i),d),H(e,O(e,n,1,a,u),$(u.id,0))}function is(o,e,t,n,i=!1){let r=B(e.content);if(n===0&&r>0)return H(o,O(o,t,0,D()),o.selection);let s=o.doc.blocks[t+1];if(!i&&n===r&&s?.type==="paragraph"&&B(s.content)===0)return{...o,selection:$(s.id,0),storedMarks:null};let l=z(e,C(e.content,0,n)),a=D(C(e.content,n)),d=o.doc.blocks.slice();return d[t]=l,d.splice(i?(At(d,t)??t)+1:t+1,0,a),H(o,d,$(a.id,0))}function ri(o){let e=J(o),t=e.selection.focus,n=L(e.doc,t.blockId),i=e.doc.blocks[n];return i.type==="details"?is(e,i,n,t.offset,!0):Kn(o)}function At(o,e){let t=0;for(let n=e;n<o.length;n++){let i=o[n].type;if(i==="details")t++;else if(i==="detailsEnd"&&--t===0)return n}return null}function si(o,e){let t=0;for(let n=e;n>=0;n--){let i=o[n].type;if(i==="detailsEnd")t++;else if(i==="details"&&--t===0)return n}return null}function rn(o){if(!o.some(r=>r.type==="details"||r.type==="detailsEnd"))return o;let e=[],t=new Set;if(o.forEach((r,s)=>{r.type==="details"?e.push(s):r.type==="detailsEnd"&&e.pop()===void 0&&t.add(s)}),t.size===0&&e.length===0)return o;let n=new Set(e),i=[];return o.forEach((r,s)=>{t.has(s)||i.push(n.has(s)&&r.type==="details"?D(r.content,r.id):r)}),i.length>0?i:[D()]}function li(o){if(!o.doc.blocks.some(l=>l.type==="details"||l.type==="detailsEnd"))return o;let e=rn(o.doc.blocks),t=o;if(e!==o.doc.blocks){let l={blocks:e};t={...o,doc:l,selection:te(l,o.selection)}}let n=l=>t.doc.blocks.find(a=>a.id===l.blockId)?.type==="detailsEnd",{anchor:i,focus:r}=t.selection;if(!n(i)&&!n(r))return t;let s=l=>n(l)?os(t.doc.blocks,L(t.doc,l.blockId))??l:l;return{...t,selection:{anchor:s(i),focus:s(r)}}}function hc(o,e,t){let n=t.cell,i=e;n.row===e.rows.length-1&&(i=Jt(e,n.row+1));let r={row:n.row+1,col:n.col};return j(o,i,$(i.id,0,r))}function ai(o,e,t,n){let i=L(o.doc,e.blockId),r=L(o.doc,t.blockId),s=o.doc.blocks.slice(i,r+1).map(l=>{if(Z(l)||Q(l))return l;if(l.type==="table"){let c=l.align.length,h=l.id===e.blockId&&e.cell?e.cell.row*c+e.cell.col:0,f=l.id===t.blockId&&t.cell?t.cell.row*c+t.cell.col:1/0,p=l.rows.map((m,y)=>m.map((g,v)=>{let b=y*c+v;if(b<h||b>f)return g;let w=b===h&&l.id===e.blockId?e.offset:0,k=b===f&&l.id===t.blockId?t.offset:B(g);return w<k?ts(g,n(g,w,k)):g}));return p.every((m,y)=>m.every((g,v)=>g===l.rows[y][v]))?l:{...l,rows:p}}let a=l.id===e.blockId?e.offset:0,d=l.id===t.blockId?t.offset:B(l.content);if(a>=d)return l;let u=ts(l.content,n(l.content,a,d));return u===l.content?l:z(l,u)});return O(o,i,s.length,...s)}function ts(o,e){if(o.length!==e.length)return e;for(let t=0;t<o.length;t++){let n=o[t],i=e[t];if(n.text!==i.text||!ae(n,i)||n.token!==i.token||n.image!==i.image||!jt(n.marks,i.marks))return e}return o}function Vn(o,e){if(R(o.selection)){let r=o.selection.focus,s=N(o.doc,r.blockId);return(o.storedMarks??Gt(Ce(s,r.cell),r.offset).marks).includes(e)}let{from:t,to:n}=Me(o.doc,o.selection),i=[];return ai(o,t,n,(r,s,l)=>(i.push(jo(r,s,l,e)),r)),i.length>0&&i.every(Boolean)}function We(o,e){let{from:t,to:n}=Me(o.doc,o.selection);if(R(o.selection)){let s=N(o.doc,t.blockId);if(Q(s))return o;let l=o.storedMarks??Gt(Ce(s,t.cell),t.offset).marks,a=l.includes(e)?l.filter(d=>d!==e):rt([...l,e]);return{...o,storedMarks:a}}let i=!Vn(o,e),r=ai(o,t,n,(s,l,a)=>Zt(s,l,a,e,i));return{...o,doc:{blocks:r},storedMarks:null}}function Qe(o){let{from:e}=Me(o.doc,o.selection),t=N(o.doc,e.blockId),n=F(t,e.cell);if(!n)return null;let i=Xt(n,e.offset);return i?{...i,pos:e}:null}function ut(o,e){let t,n;if(R(o.selection)){let r=Qe(o);if(!r)return o;t={...r.pos,offset:r.from},n={...r.pos,offset:r.to}}else({from:t,to:n}=Me(o.doc,o.selection));let i=ai(o,t,n,(r,s,l)=>Go(r,s,l,e));return{...o,doc:{blocks:i},storedMarks:null}}function De(o){let{anchor:e,focus:t}=o.selection;if(e.blockId!==t.blockId||!de(e.cell,t.cell)||Math.abs(e.offset-t.offset)!==1)return null;let n=Math.min(e.offset,t.offset),i=F(N(o.doc,e.blockId),e.cell),r=i?C(i,n,n+1)[0]?.image:void 0;return r?{pos:{...e,offset:n},image:r}:null}function rs(o,e){return{anchor:{blockId:o,offset:e},focus:{blockId:o,offset:e+1}}}function ke(o){let e=De(o);return!e||e.pos.cell?null:Y(N(o.doc,e.pos.blockId))===e.pos.offset?e:null}function je(o,e){let t=o.doc.blocks.find(i=>i.id===e.blockId),n=t&&F(t,e.cell);return!n||!C(n,e.offset,e.offset+1)[0]?.image?o:{...o,selection:{anchor:e,focus:{...e,offset:e.offset+1}},storedMarks:null}}function Un(o,e,t){let n=o.doc.blocks.find(b=>b.id===e.blockId),i=n&&F(n,e.cell),r=i?C(i,e.offset,e.offset+1)[0]:void 0;if(!n||!i||!r?.image)return o;let{title:s,align:l,width:a,height:d,...u}=r.image,c=r.image.title;t.title!==void 0&&(c=t.title||void 0);let h=t.align!==void 0?t.align??void 0:r.image.align,f=r.image.width,p=r.image.height;t.width!==void 0&&(f=t.width===null?void 0:Math.max(1,Math.min(99999,Math.round(t.width))),f!==r.image.width&&(p=void 0));let m={...u,...t.alt!==void 0?{alt:t.alt}:{},...c?{title:c}:{},...h?{align:h}:{},...f?{width:f}:{},...f&&p?{height:p}:{}},y=je(o,e).selection;if(m.alt===r.image.alt&&m.title===r.image.title&&m.align===r.image.align&&m.width===r.image.width&&m.height===r.image.height)return y===o.selection?o:{...o,selection:y,storedMarks:null};let v=ce(C(i,0,e.offset),[{...r,text:"\uFFFC",image:m}],C(i,e.offset+1));return j(o,ze(n,e.cell,v),y)}function ss(o,e){return Re(o,fc(o,e))}function fc(o,e){let t=M(o);if(e.type==="quote")return U(o,e.callout??t??"quote");let n=o.content,i;switch(e.type){case"paragraph":if(i=D(n,o.id),o.type==="quote")return i;break;case"heading":i=nt(e.level,n,o.id);break;case"listItem":i=Ue(e.listType,n,{id:o.id,indent:o.type==="listItem"?o.indent:0,checked:o.type==="listItem"?o.checked:!1,start:o.type==="listItem"&&o.listType===e.listType?o.start:void 0});break;case"code":i=Ee(e.language??(o.type==="code"?o.language:""),I(Ct(n)),o.id);break;default:return o}return U(i,t)}function Yt(o){return q(o)&&o.type!=="raw"}function Ge(o,e){return e.type==="table"||e.type==="divider"||e.type==="details"?Rt(o,e):ls(o,e,t=>ss(t,e))}function ls(o,e,t){let{from:n,to:i}=Me(o.doc,o.selection),r=L(o.doc,n.blockId),s=L(o.doc,i.blockId),l=o.doc.blocks.slice(r,s+1);if(e.type==="code"&&l.filter(Yt).length>1)return pc(o,r,l,e.language);let a=l.map(u=>Yt(u)?t(u):u),d={blocks:O(o,r,a.length,...a)};return{doc:d,selection:te(d,o.selection),storedMarks:null}}function pc(o,e,t,n){let i=[],r=[],s=[],l=()=>{let d=s[0];if(!d)return;let u=s.map(h=>I(Ct(h.content))).join(`
8
+ `),c=U(Ee(n??(d.type==="code"?d.language:""),u,d.id),M(d));i.push(c),r.push(c),s=[]};for(let d of t)Yt(d)?s.push(d):(l(),i.push(d));l();let a={anchor:V(r[0]),focus:P(r[r.length-1])};return{doc:{blocks:O(o,e,t.length,...i)},selection:a,storedMarks:null}}function Nt(o,e){let t=o.doc.blocks,n=L(o.doc,e),i=t[n];if(M(i)===null)return null;let r=n,s=n;for(;oe(t[r-1],t[r]);)r--;for(;oe(t[s],t[s+1]);)s++;return{start:r,end:s}}function sn(o,e,t){let n=Nt(o,e);if(!n)return o;let i=o.doc.blocks.slice(n.start,n.end+1);if(i.every(l=>M(l)===(t??"quote")))return o;let r=i.map(l=>U(l,t??"quote"));return{doc:{blocks:O(o,n.start,r.length,...r)},selection:o.selection,storedMarks:o.storedMarks}}function zn(o){let{from:e,to:t}=Me(o.doc,o.selection);return o.doc.blocks.slice(L(o.doc,e.blockId),L(o.doc,t.blockId)+1).filter(Yt)}function mc(o,e){switch(e.type){case"heading":return o.type==="heading"&&o.level===e.level;case"listItem":return o.type==="listItem"&&o.listType===e.listType;case"code":return o.type==="code";case"quote":{let t=M(o);return t!==null&&(!e.callout||t===e.callout)}default:return o.type===e.type}}function ht(o,e){let t=zn(o);if(t.length===0)return o;if(!t.every(r=>mc(r,e)))return Ge(o,e);let i={type:"paragraph"};return ls(o,i,r=>e.type==="quote"?U(r,null):ss(r,i))}function Rt(o,e){let t=o.selection.focus,n=L(o.doc,t.blockId),i=o.doc.blocks[n];if(e.type==="details")return gc(o,n);if(e.type!=="table"&&e.type!=="divider")return Ge(o,e);let r=q(i)&&B(i.content)===0,s=M(i),l=U(e.type==="table"?Qr(e.rows??3,e.cols??3):it(),s),a=[r?Re(i,l):l],d=l;if(l.type==="divider"){let h=o.doc.blocks[n+1];h&&q(h)?d=h:(d=U(D(),s),a.push(d))}let u=V(d),c=r?n:n+1;return H(o,O(o,c,r?1:0,...a),{anchor:u,focus:u})}function gc(o,e){let t=o.doc.blocks[e],n=Yt(t)&&t.type!=="details",i=St(n?t.content:[],n?{id:t.id}:{}),r=D(),s=n?e:e+1,l=O(o,s,n?1:0,i,r,Tt()),a=B(i.content)===0?$(i.id,0):$(r.id,0);return H(o,l,a)}function Wn(o,e){let{from:t,to:n}=Me(o.doc,o.selection),i=L(o.doc,t.blockId),r=L(o.doc,n.blockId),s=!1,l=o.doc.blocks.slice();for(let a=i;a<=r;a++){let d=l[a];if(d.type!=="listItem")continue;let u=as(l[a-1],d),c=Math.max(0,Math.min(u,d.indent+e));c!==d.indent&&(l[a]={...d,indent:c},s=!0)}return s?H(o,l):o}var Jo=" ";function ln(o,e){let{anchor:t,focus:n}=o.selection;if(t.blockId!==n.blockId)return o;let i=N(o.doc,n.blockId);if(i.type!=="code")return o;if(e===1&&R(o.selection))return ue(o,Jo);let r=I(i.content),s=Math.min(t.offset,n.offset),l=Math.max(t.offset,n.offset),a=[];for(let f=r.lastIndexOf(`
9
9
  `,s-1)+1;;){let p=/^(?: {1,2}|\t)/.exec(r.slice(f))?.[0].length??0;a.push({at:f,remove:e===1?0:p});let m=r.indexOf(`
10
- `,f);if(m<0||m>=l)break;f=m+1}if(e===-1&&a.every(f=>f.remove===0))return o;let d="",u=0;for(let f of a)d+=r.slice(u,f.at)+(e===1?Jo:""),u=f.at+f.remove;d+=r.slice(u);let c=f=>{let p=0;for(let m of a){if(m.at>f)break;p+=e===1?Jo.length:-Math.min(m.remove,f-m.at)}return f+p},h=z(i,ge(d));return j(o,h,{anchor:{...t,offset:c(t.offset)},focus:{...n,offset:c(n.offset)}})}function Qn(o,e){let t=N(o.doc,e);if(t.type!=="listItem"||t.listType!=="task")return o;let n={...t,checked:!t.checked};return j(o,n)}function ci(o,e,t){let n=N(o.doc,e);return n.type!=="code"||n.language===t?o:j(o,{...n,language:t})}function di(o,e){let t=L(o.doc,e),n=dt(o.doc.blocks[t]),i=V(n);return H(o,D(o,t+1,0,n),{anchor:i,focus:i})}function Bt(o,e){return Lt(o,L(o.doc,e),-1)}function an(o,e){return{anchor:V(o[e.from]),focus:P(o[e.to])}}function as(o,e){return o?.type==="listItem"&&M(o)===M(e)?Math.min(5,o.indent+1):0}function ei(o,e){for(let t=Math.max(0,e);t<o.length;t++){let n=o[t];if(n.type!=="listItem")return;let i=as(o[t-1],n);if(n.indent<=i)return;o[t]={...n,indent:i}}}function jn(o,e){return Gn(o,e,[])}function ui(o,e){let t=o.doc.blocks.slice(e.from,e.to+1).map(dt),n=D(o,e.to+1,0,...t);ei(n,e.to+1);let i={from:e.to+1,to:e.to+t.length};return H(o,n,an(n,i))}function Gn(o,e,t){let n=D(o,e.from,e.to-e.from+1,...t);if(n.length===0){let r=O();return H(o,[r],$(r.id,0))}ei(n,e.from),ei(n,e.from+t.length);let i;return t.length>0?i=P(n[e.from+t.length-1]):e.from>0?i=P(n[e.from-1]):i=V(n[0]),H(o,n,{anchor:i,focus:i})}function Jt(o,e){let t=o.rows.slice();return t.splice(Math.max(1,e),0,o.align.map(()=>[])),{...o,rows:t}}function ti(o,e){let t=o.align.slice();t.splice(e,0,null);let n=o.rows.map(i=>{let r=i.slice();return r.splice(e,0,[]),r});return{...o,align:t,rows:n}}function Zn(o,e){let t=o.selection.focus,n=N(o.doc,t.blockId);if(n.type!=="table"||!t.cell)return o;let{row:i,col:r}=t.cell,s=n,l=t.cell;switch(e.kind){case"addRowAbove":s=Jt(n,i===0?1:i),l={row:i===0?1:i,col:r};break;case"addRowBelow":s=Jt(n,i+1),l={row:i+1,col:r};break;case"addColumnLeft":s=ti(n,r);break;case"addColumnRight":s=ti(n,r+1),l={row:i,col:r+1};break;case"deleteRow":if(n.rows.length<=1)return Bt(o,n.id);s={...n,rows:n.rows.filter((d,u)=>u!==i)},l={row:Math.min(i,s.rows.length-1),col:r};break;case"deleteColumn":{if(n.align.length<=1)return Bt(o,n.id);s={...n,align:n.align.filter((d,u)=>u!==r),rows:n.rows.map(d=>d.filter((u,c)=>c!==r))},l={row:i,col:Math.min(r,s.align.length-1)};break}case"align":s={...n,align:n.align.map((d,u)=>u===r?e.align:d)};break}let a=Math.min(t.offset,B(Ce(s,l)));return j(o,s,$(s.id,l===t.cell?a:0,l))}function hi(o,e){let t=o.selection.focus,n=N(o.doc,t.blockId);if(n.type!=="table"||!t.cell)return o;let i=n.align.length,r=t.cell.row*i+t.cell.col+e;if(r<0)return o;let s=n;r>=n.rows.length*i&&(s=Jt(n,n.rows.length));let l={row:Math.floor(r/i),col:r%i},a=Ce(s,l),d={anchor:{blockId:n.id,offset:0,cell:l},focus:{blockId:n.id,offset:B(a),cell:l}};return s===n?{...o,selection:d}:H(o,D(o,L(o.doc,n.id),1,s),d)}var gc=[[/^(#{1,6}) $/,o=>({type:"heading",level:o[1].length})],[/^[-*+] $/,()=>({type:"listItem",listType:"bullet"})],[/^\d{1,9}[.)] $/,()=>({type:"listItem",listType:"ordered"})],[/^\[[ xX]?\] $/,()=>({type:"listItem",listType:"task"})],[/^> $/,()=>({type:"quote"})],[new RegExp(`^\\[!(${Ve.join("|")})\\] $`,"i"),o=>({type:"quote",callout:o[1].toLowerCase()})],[/^```([^`\s]*) $/,o=>({type:"code",language:o[1]})],[/^>>> $/,()=>({type:"details"})]];function fi(o,e={}){if(!R(o.selection))return null;let t=o.selection.focus,n=N(o.doc,t.blockId);if(!q(n)||t.cell)return null;let i=I(n.content).slice(0,t.offset);if((n.type==="paragraph"||n.type==="quote")&&i==="---"){let s=L(o.doc,n.id),l=On(z(n,C(n.content,t.offset))),a=Re(n,U(it(),M(n)));return H(o,D(o,s,1,a,l),$(l.id,0))}if(!(n.type==="paragraph"||n.type==="quote"||n.type==="listItem"&&n.listType==="bullet"))return null;for(let[s,l]of gc){let a=s.exec(i);if(!a)continue;let d=l(a);if(d.type==="quote"&&d.callout&&e.callouts===!1||d.type==="details"&&e.details===!1||n.type==="listItem"&&!(d.type==="listItem"&&d.listType==="task"))continue;if(n.type==="quote"){if(d.type==="quote"&&d.callout)return sn(ye(o,{blockId:n.id,offset:0},t),n.id,d.callout);if(d.type==="quote"||d.type==="details")continue}let u=ye(o,{blockId:n.id,offset:0},t),c=Ge(u,d),h=N(c.doc,n.id);if(h.type==="listItem"){let f=/^(\d{1,9})/.exec(i),p=/^\[[xX]\]/.test(i),m=Ue(h.listType,h.content,{id:h.id,indent:h.indent,checked:p,start:h.listType==="ordered"&&f?Number(f[1]):void 0,quote:M(h)});c=j(c,Re(h,m),c.selection)}return c}return null}function pi(o){if(!R(o.selection))return null;let e=o.selection.focus,t=N(o.doc,e.blockId);if(Q(t))return null;let n=F(t,e.cell);return n?{pos:e,block:t,content:n}:null}var bc=[{re:/(?:^|[^*])\*\*([^*\s](?:[^*]*[^*\s])?)\*\*$/,mark:"bold",delim:2},{re:/(?:^|[^_\p{L}\p{N}])__([^_\s](?:[^_]*[^_\s])?)__$/u,mark:"bold",delim:2},{re:/~~([^~\s](?:[^~]*[^~\s])?)~~$/,mark:"strike",delim:2},{re:/(?:^|[^*])\*([^*\s](?:[^*]*[^*\s])?)\*$/,mark:"italic",delim:1},{re:/(?:^|[^_\p{L}\p{N}])_([^_\s](?:[^_]*[^_\s])?)_$/u,mark:"italic",delim:1},{re:/`([^`]+)`$/,mark:"code",delim:1}];function mi(o){let e=pi(o);if(!e)return null;let{pos:t,block:n,content:i}=e,r=I(i).slice(0,t.offset);for(let s of bc){let l=s.re.exec(r);if(!l)continue;let a=l[1],d=t.offset,u=d-s.delim,c=u-a.length,h=c-s.delim;if(ns(r,h)||s.mark!=="code"&&ns(r,u)||jo(i,h,d,"code")||C(i,h,d).some(x=>x.image))continue;let f=Zt(i,c,u,s.mark,!0);f=st(f,u,d),f=st(f,h,c);let p=u-s.delim,m=ze(n,t.cell,f),y=j(o,m,$(n.id,p,t.cell)),g=Gt(f,p).marks.filter(x=>x!==s.mark);return{...y,storedMarks:g}}return null}function ns(o,e){let t=0;for(;e-t-1>=0&&o[e-t-1]==="\\";)t++;return t%2===1}function gi(o,e){let t=e.length>0?pi(o):null;if(!t)return null;let{pos:n,block:i,content:r}=t,s=I(r),l=n.offset,a=Math.max(s.lastIndexOf(`
11
- `,l-1)+1,l-1e3);for(let d=l-1;d>=a;d--)for(let u of e){if(!u.triggers.includes(s[d])||u.match(s,d)!==l||!C(r,d,l).every(f=>!f.token&&!f.image&&!f.marks.includes("code")&&!f.marks.includes("html")))continue;let h=ze(i,n.cell,Zr(r,d,l,u.name));return j(o,h,o.selection)}return null}function bi(o,e,t){if(t.length===0||o.doc===e.doc)return o;let n=new Set(e.doc.blocks),i=null;return o.doc.blocks.forEach((r,s)=>{if(n.has(r)||r.type==="divider")return;let l=r.type==="table"?r.rows.flatMap((d,u)=>d.map((c,h)=>({row:u,col:h}))):[void 0],a=r;for(let d of l){let u=F(a,d);if(!u?.some(h=>h.token))continue;let c=yc(u,t);c!==u&&(a=ze(a,d,c))}a!==r&&((i??=[...o.doc.blocks])[s]=a)}),i?{...o,doc:{...o.doc,blocks:i}}:o}function yi(o,e){if(o.doc===e.doc)return o;let t=null,n=0;return o.doc.blocks.forEach((i,r)=>{(i.type!=="listItem"||M(i)!==M(o.doc.blocks[r-1]))&&(n=0),i.type==="listItem"&&(i.indent>n&&((t??=[...o.doc.blocks])[r]={...i,indent:n}),n=Math.min(i.indent,n)+1)}),t?{...o,doc:{...o.doc,blocks:t}}:o}function yc(o,e){let t=I(o),n=o,i=0;for(let r of o){let s=i,l=i+=r.text.length;if(!r.token)continue;let a=r.marks.includes("code")?void 0:e.find(h=>h.name===r.token),d=s;for(;a&&d<l;){let h=a.match(t,d);if(h<=d||h>l)break;d=h}if(d===l)continue;let{token:u,...c}=r;n=ce(C(n,0,s),[c],C(n,l))}return n}function ki(o){let e=pi(o);if(!e)return null;let{pos:t,block:n,content:i}=e,r=I(i),s=t.offset-1;if(s<=0||!/\s/.test(r[s]))return null;let l=s;for(;l>0&&!/\s/.test(r[l-1]);)l--;let a=r.slice(l,s),d=null;for(let c of a.matchAll(/www\.|(?:https?|ftp):\/\//gi)){if(!It(c.index===0?void 0:a[c.index-1],c[0].toLowerCase()==="www."))continue;let h=lt(a,c.index);if(h){d={from:l+c.index,to:l+h.end,href:h.href};break}}if(!d){let c=at(a)[0];c&&(d={from:l+c.from,to:l+c.to,href:"mailto:"+a.slice(c.from,c.to)})}if(!d||C(i,d.from,d.to).some(ct))return null;let u=ze(n,t.cell,Go(i,d.from,d.to,d.href));return j(o,u,o.selection)}function vi(o){let{from:e,to:t}=Me(o.doc,o.selection),n=L(o.doc,e.blockId),i=L(o.doc,t.blockId);if(n===i){let r=o.doc.blocks[n];if(q(r))return[O(C(r.content,e.offset,t.offset))];if(r.type==="table"&&e.cell&&de(e.cell,t.cell))return[O(C(Ce(r,e.cell),e.offset,t.offset))]}return o.doc.blocks.slice(n,i+1).map(r=>{if(!q(r))return dt(r);let s=r.id===e.blockId?e.offset:0,l=r.id===t.blockId?t.offset:1/0;return dt(z(r,C(r.content,s,l)))})}function Xn(o,e){if(e.length===0)return J(o);let t=J(o),n=t.selection.focus,i=L(t.doc,n.blockId),r=t.doc.blocks[i];if(!q(r)||Q(r)){let f=e[0];if(r.type==="table"&&e.length===1&&q(f)&&!Q(f)){let m=Ce(r,n.cell),y=f.content.map(b=>({...b,text:b.text.replace(/\n/g," ")})),g=ce(C(m,0,n.offset),y,C(m,n.offset)),x=n.offset+B(y);return j(t,ze(r,n.cell,g),$(r.id,x,n.cell))}let p=e.map(m=>q(m)?I(Ct(m.content)):"").filter(Boolean).join(`
12
- `);return ue(t,p)}let s=C(r.content,0,n.offset),l=C(r.content,n.offset),a=e[0];if(e.length===1&&q(a)&&!(Q(a)&&B(r.content)>0)){let f=B(r.content)===0?{...a,id:r.id}:r,p=ce(s,a.content,l);return j(t,z(f,p),$(r.id,n.offset+B(a.content)))}let d=[],u=e.slice();s.length>0?q(a)&&!Q(a)?(d.push(z(r,ce(s,a.content))),u=u.slice(1)):d.push(z(r,s)):q(a)&&(d.push({...a,id:r.id}),u=u.slice(1)),d.push(...u);let c=d[d.length-1],h;if(q(c)&&!Q(c))h={blockId:c.id,offset:B(c.content)},l.length>0&&(d[d.length-1]=z(c,ce(c.content,l)));else{let f=z(Fn(r),l);d.push(f),h={blockId:f.id,offset:0}}return H(t,D(t,i,1,...d),{anchor:h,focus:h})}function xi(o){let e=o.doc.blocks,t={anchor:V(e[0]),focus:P(e[e.length-1])};return{...o,selection:t,storedMarks:null}}function cn(o,e,t={}){if(e.length===0)return o;let n=t.at??"selection",i=o,r;if(n==="selection")i=J(o),r=i.selection.focus;else if(n==="end"){let u=o.doc.blocks[o.doc.blocks.length-1];r=P(u)}else r=te(o.doc,{anchor:n,focus:n}).focus;let s,l;if(t.block||n==="end"?{state:s,after:l}=kc(i,e,r):(s=Xn({...i,selection:{anchor:r,focus:r}},e),l=s.selection.focus),t.select!=="keep")return s;let a=u=>u.blockId===r.blockId&&de(u.cell,r.cell)&&u.offset>r.offset?{...l,offset:l.offset+u.offset-r.offset}:u,d=te(s.doc,{anchor:a(i.selection.anchor),focus:a(i.selection.focus)});return{...s,selection:d}}function kc(o,e,t){let n=L(o.doc,t.blockId),i=o.doc.blocks[n],r=(d,u,c)=>{let h=P(u);return{state:H(o,d,{anchor:h,focus:h}),after:c}},s=e[e.length-1];if(i.type==="paragraph"&&B(i.content)===0)return r(D(o,n,1,...e),s,P(s));if(!q(i)||Q(i)||t.offset>=B(i.content))return r(D(o,n+1,0,...e),s,t);if(t.offset===0)return r(D(o,n,0,...e),s,V(i));let l=z(i,C(i.content,0,t.offset)),a={...z(i,C(i.content,t.offset)),id:ee()};return a.type==="listItem"&&a.start!==void 0&&(a={...a,start:void 0}),a=On(a),r(D(o,n,1,l,...e,a),s,V(a))}function dn(o){let e="",t=o.blocks,n=0;for(;n<t.length;){let i=t[n],r=M(i);if(r){let s=n+1;for(;s<t.length&&oe(i,t[s]);)s++;e+=xc(r==="quote"?void 0:r,dn({blocks:t.slice(n,s).map(Mt)})),n=s}else if(i.type==="listItem"){let s=n;for(;s<t.length&&t[s].type==="listItem"&&M(t[s])===null;)s++;e+=wc(t.slice(n,s)),n=s}else e+=vc(i),n++}return e}function vc(o){switch(o.type){case"paragraph":{let e=Y(o),t=e===null?void 0:C(o.content,e,e+1)[0]?.image?.align;return`<p${t?` style="text-align:${t}"`:""}>${Yn(o.content)}</p>`}case"heading":return`<h${o.level}>${Yn(o.content)}</h${o.level}>`;case"code":return`<pre><code${o.language?` class="language-${Ie(o.language)}"`:""}>${Ie(I(o.content))}</code></pre>`;case"raw":return o.syntax==="html"?I(o.content):`<pre>${Ie(I(o.content))}</pre>`;case"divider":return"<hr>";case"details":return`<details${o.open?" open":""}><summary>${Ie(I(o.content))}</summary>`;case"detailsEnd":return"</details>";case"table":{let e=(r,s,l)=>{let a=o.align[l];return`<${r}${a?` style="text-align: ${a}"`:""}>${Yn(s)}</${r}>`},[t,...n]=o.rows,i="<table>";return t&&(i+=`<thead><tr>${t.map((r,s)=>e("th",r,s)).join("")}</tr></thead>`),n.length>0&&(i+=`<tbody>${n.map(r=>`<tr>${r.map((s,l)=>e("td",s,l)).join("")}</tr>`).join("")}</tbody>`),i+"</table>"}case"listItem":case"quote":return dn({blocks:[o]})}}function xc(o,e){if(!o)return`<blockquote>${e}</blockquote>`;let t=o[0].toUpperCase()+o.slice(1);return`<blockquote class="markdown-alert markdown-alert-${o}"><p class="markdown-alert-title"><strong>${t}</strong></p>${e}</blockquote>`}function wc(o){let e="",t=[],n=i=>{for(;t.length>i;){let r=t.pop();r.liOpen&&(e+="</li>"),e+=`</${r.tag}>`}};for(let i of o){let r=i.listType==="ordered"?"ol":"ul",s=Math.min(i.indent,t.length);n(s+1);let l=t[s];if(l&&l.tag!==r&&n(s),!t[s]){let u=i.listType==="ordered"&&i.start!==void 0?` start="${i.start}"`:"";e+=`<${r}${u}>`,t.push({tag:r,liOpen:!1})}let a=t[s];a.liOpen&&(e+="</li>");let d=i.listType==="task"?`<input type="checkbox" disabled${i.checked?" checked":""}> `:"";e+=`<li>${d}${Yn(i.content)}`,a.liOpen=!0}return n(0),e}function Ie(o){return o.replace(/[&<>"]/g,e=>e==="&"?"&amp;":e==="<"?"&lt;":e===">"?"&gt;":"&quot;")}function Yn(o){let e="",t=0;for(;t<o.length;){let{link:n,linkTitle:i}=o[t],r=t,s="";for(;r<o.length&&ae(o[r],o[t]);)s+=Sc(o[r++]);let l=i?` title="${Ie(i)}"`:"";e+=n===void 0?s:`<a href="${Ie(n)}"${l}>${s}</a>`,t=r}return e}function Sc(o){let e;if(o.image){let{src:t,alt:n,title:i,width:r,height:s}=o.image;e=`<img src="${Ie(t)}" alt="${Ie(n)}"${i?` title="${Ie(i)}"`:""}`,r&&(e+=` width="${r}"${s?` height="${s}"`:""}`),e+=">"}else o.marks.includes("html")?e=o.text:e=Ie(o.text).replace(/\n/g,"<br>");return o.marks.includes("code")&&(e=`<code>${e}</code>`),o.marks.includes("strike")&&(e=`<s>${e}</s>`),o.marks.includes("italic")&&(e=`<em>${e}</em>`),o.marks.includes("bold")&&(e=`<strong>${e}</strong>`),e}function no(o,e){let t=e??(typeof DOMParser>"u"?null:new DOMParser);if(!t)throw new Error("htmlToDoc needs a DOMParser (pass one in outside the browser)");let n=t.parseFromString(o,"text/html"),i=new Ei;return i.blocks(n.body,Cc),{blocks:i.finish()}}var Tc=new Set(["html","body","meta","div","span","br","font"]),Ec=/font-weight\s*:\s*(?:bold|[6-9]00)|font-style\s*:\s*italic|text-decoration[^;"']*line-through/i;function ds(o){let e=o.replace(/<!--[\s\S]*?-->/g,"").replace(/<(style|script|head|title)\b[\s\S]*?<\/\1\s*>/gi,"");for(let t of e.matchAll(/<([A-Za-z][A-Za-z0-9-]*)\b([^>]*)>/g))if(!Tc.has(t[1].toLowerCase())||Ec.test(t[2]))return!1;return!0}var Jn=1,eo=3,to=new Set(["script","style","head","title","meta","link","template","noscript","iframe","object","embed","svg","canvas","audio","video","select","textarea","button","input","colgroup"]),un=new Set(["address","article","aside","blockquote","body","center","dd","details","dialog","dir","div","dl","dt","fieldset","figcaption","figure","footer","form","h1","h2","h3","h4","h5","h6","header","hgroup","hr","li","main","menu","nav","ol","p","pre","section","summary","table","ul","caption","thead","tbody","tfoot","tr","td","th"]),Mc=[...un].join(",");function ve(o){return o.tagName.toLowerCase()}function Si(o){return o==="ul"||o==="ol"||o==="menu"||o==="dir"}function us(o){let e=new Map,t=o.getAttribute("style");if(!t)return e;for(let n of t.split(";")){let i=n.indexOf(":");i<0||e.set(n.slice(0,i).trim().toLowerCase(),n.slice(i+1).trim().toLowerCase())}return e}var Cc={marks:[],whiteSpace:"normal"},Ic=/monospace|courier|consolas|menlo|monaco|source code|roboto mono|fira code/;function Dt(o,e){let t=ve(o),n=new Set(e.marks),i=e.link,r=e.whiteSpace;if((t==="b"||t==="strong")&&n.add("bold"),(t==="i"||t==="em"||t==="cite"||t==="dfn"||t==="var")&&n.add("italic"),(t==="s"||t==="del"||t==="strike")&&n.add("strike"),(t==="code"||t==="kbd"||t==="samp"||t==="tt")&&n.add("code"),t==="pre"&&(r="pre"),t==="a"){let c=o.getAttribute("href")?.trim();c&&!/^(?:javascript|vbscript|data):/i.test(c)&&(i=c)}let s=us(o),l=s.get("font-weight");l!==void 0&&(/^(?:bold|bolder|[6-9]00)$/.test(l)?n.add("bold"):/^(?:normal|lighter|[1-5]00)$/.test(l)&&n.delete("bold"));let a=s.get("font-style");a!==void 0&&(/^(?:italic|oblique)/.test(a)?n.add("italic"):a==="normal"&&n.delete("italic")),/line-through/.test(s.get("text-decoration")??s.get("text-decoration-line")??"")&&n.add("strike"),Ic.test(s.get("font-family")??"")&&n.add("code");let d=s.get("white-space");d!==void 0&&(r=/^(?:pre|pre-wrap|break-spaces)$/.test(d)?"pre":d==="pre-line"?"pre-line":"normal");let u=rt(n);return i===void 0?{marks:u,whiteSpace:r}:{marks:u,link:i,whiteSpace:r}}function cs(o){let t=/(?:^|\s)markdown-alert-([a-z]+)(?:\s|$)/.exec(o.getAttribute("class")??"")?.[1];return t&&Ve.includes(t)?t:void 0}function Lc(o,e){return(o.getAttribute("class")??"").split(/\s+/).includes(e)}var Ei=class o{out=[];spans=[];finish(){return this.flush(),this.out}blocks(e,t,n){for(let i of Array.from(e.childNodes))i.nodeType===eo?this.text(i.nodeValue??"",t):i.nodeType===Jn&&!n?.(i)&&this.element(i,t)}element(e,t){let n=ve(e);if(to.has(n))return;let i=Dt(e,t);if(/^h[1-6]$/.test(n)){this.flush();let r=this.inlineOf(e,i);this.out.push(nt(Number(n[1]),r))}else if(Si(n))this.flush(),this.list(e,0,i);else if(n==="li")this.flush(),this.listItem(e,"bullet",0,void 0,i);else if(n==="details"){this.flush();let r=Array.from(e.children).find(l=>ve(l)==="summary"),s=(r?.textContent??"").replace(/\s+/g," ").trim();this.out.push(St(ge(s),{open:e.hasAttribute("open")})),this.blocks(e,i,l=>l===r),this.flush(),this.out.push(Tt())}else n==="blockquote"||cs(e)?(this.flush(),this.blockquote(e,i)):n==="pre"?(this.flush(),this.out.push(Ee(Bc(e),Ac(e)))):n==="table"?(this.flush(),this.table(e,i)):n==="hr"?(this.flush(),this.out.push(it())):un.has(n)?(this.flush(),this.blocks(e,i),this.flush()):e.querySelector(Mc)?this.blocks(e,i):this.inline(e,t)}push(e,t,n){let i=t.link===void 0?{text:e,marks:t.marks}:{text:e,marks:t.marks,link:t.link};this.spans.push(n?{...i,...n}:i)}atLineStart(){let e=this.lastChar();return e===""||e===`
10
+ `,f);if(m<0||m>=l)break;f=m+1}if(e===-1&&a.every(f=>f.remove===0))return o;let d="",u=0;for(let f of a)d+=r.slice(u,f.at)+(e===1?Jo:""),u=f.at+f.remove;d+=r.slice(u);let c=f=>{let p=0;for(let m of a){if(m.at>f)break;p+=e===1?Jo.length:-Math.min(m.remove,f-m.at)}return f+p},h=z(i,ge(d));return j(o,h,{anchor:{...t,offset:c(t.offset)},focus:{...n,offset:c(n.offset)}})}function Qn(o,e){let t=N(o.doc,e);if(t.type!=="listItem"||t.listType!=="task")return o;let n={...t,checked:!t.checked};return j(o,n)}function ci(o,e,t){let n=N(o.doc,e);return n.type!=="code"||n.language===t?o:j(o,{...n,language:t})}function di(o,e){let t=L(o.doc,e),n=dt(o.doc.blocks[t]),i=V(n);return H(o,O(o,t+1,0,n),{anchor:i,focus:i})}function Bt(o,e){return Lt(o,L(o.doc,e),-1)}function an(o,e){return{anchor:V(o[e.from]),focus:P(o[e.to])}}function as(o,e){return o?.type==="listItem"&&M(o)===M(e)?Math.min(5,o.indent+1):0}function ei(o,e){for(let t=Math.max(0,e);t<o.length;t++){let n=o[t];if(n.type!=="listItem")return;let i=as(o[t-1],n);if(n.indent<=i)return;o[t]={...n,indent:i}}}function jn(o,e){return Gn(o,e,[])}function ui(o,e){let t=o.doc.blocks.slice(e.from,e.to+1).map(dt),n=O(o,e.to+1,0,...t);ei(n,e.to+1);let i={from:e.to+1,to:e.to+t.length};return H(o,n,an(n,i))}function Gn(o,e,t){let n=O(o,e.from,e.to-e.from+1,...t);if(n.length===0){let r=D();return H(o,[r],$(r.id,0))}ei(n,e.from),ei(n,e.from+t.length);let i;return t.length>0?i=P(n[e.from+t.length-1]):e.from>0?i=P(n[e.from-1]):i=V(n[0]),H(o,n,{anchor:i,focus:i})}function Jt(o,e){let t=o.rows.slice();return t.splice(Math.max(1,e),0,o.align.map(()=>[])),{...o,rows:t}}function ti(o,e){let t=o.align.slice();t.splice(e,0,null);let n=o.rows.map(i=>{let r=i.slice();return r.splice(e,0,[]),r});return{...o,align:t,rows:n}}function Zn(o,e){let t=o.selection.focus,n=N(o.doc,t.blockId);if(n.type!=="table"||!t.cell)return o;let{row:i,col:r}=t.cell,s=n,l=t.cell;switch(e.kind){case"addRowAbove":s=Jt(n,i===0?1:i),l={row:i===0?1:i,col:r};break;case"addRowBelow":s=Jt(n,i+1),l={row:i+1,col:r};break;case"addColumnLeft":s=ti(n,r);break;case"addColumnRight":s=ti(n,r+1),l={row:i,col:r+1};break;case"deleteRow":if(n.rows.length<=1)return Bt(o,n.id);s={...n,rows:n.rows.filter((d,u)=>u!==i)},l={row:Math.min(i,s.rows.length-1),col:r};break;case"deleteColumn":{if(n.align.length<=1)return Bt(o,n.id);s={...n,align:n.align.filter((d,u)=>u!==r),rows:n.rows.map(d=>d.filter((u,c)=>c!==r))},l={row:i,col:Math.min(r,s.align.length-1)};break}case"align":s={...n,align:n.align.map((d,u)=>u===r?e.align:d)};break}let a=Math.min(t.offset,B(Ce(s,l)));return j(o,s,$(s.id,l===t.cell?a:0,l))}function hi(o,e){let t=o.selection.focus,n=N(o.doc,t.blockId);if(n.type!=="table"||!t.cell)return o;let i=n.align.length,r=t.cell.row*i+t.cell.col+e;if(r<0)return o;let s=n;r>=n.rows.length*i&&(s=Jt(n,n.rows.length));let l={row:Math.floor(r/i),col:r%i},a=Ce(s,l),d={anchor:{blockId:n.id,offset:0,cell:l},focus:{blockId:n.id,offset:B(a),cell:l}};return s===n?{...o,selection:d}:H(o,O(o,L(o.doc,n.id),1,s),d)}var bc=[[/^(#{1,6}) $/,o=>({type:"heading",level:o[1].length})],[/^[-*+] $/,()=>({type:"listItem",listType:"bullet"})],[/^\d{1,9}[.)] $/,()=>({type:"listItem",listType:"ordered"})],[/^\[[ xX]?\] $/,()=>({type:"listItem",listType:"task"})],[/^> $/,()=>({type:"quote"})],[new RegExp(`^\\[!(${Ve.join("|")})\\] $`,"i"),o=>({type:"quote",callout:o[1].toLowerCase()})],[/^```([^`\s]*) $/,o=>({type:"code",language:o[1]})],[/^>>> $/,()=>({type:"details"})]];function fi(o,e={}){if(!R(o.selection))return null;let t=o.selection.focus,n=N(o.doc,t.blockId);if(!q(n)||t.cell)return null;let i=I(n.content).slice(0,t.offset);if((n.type==="paragraph"||n.type==="quote")&&i==="---"){let s=L(o.doc,n.id),l=On(z(n,C(n.content,t.offset))),a=Re(n,U(it(),M(n)));return H(o,O(o,s,1,a,l),$(l.id,0))}if(!(n.type==="paragraph"||n.type==="quote"||n.type==="listItem"&&n.listType==="bullet"))return null;for(let[s,l]of bc){let a=s.exec(i);if(!a)continue;let d=l(a);if(d.type==="quote"&&d.callout&&e.callouts===!1||d.type==="details"&&e.details===!1||n.type==="listItem"&&!(d.type==="listItem"&&d.listType==="task"))continue;if(n.type==="quote"){if(d.type==="quote"&&d.callout)return sn(ye(o,{blockId:n.id,offset:0},t),n.id,d.callout);if(d.type==="quote"||d.type==="details")continue}let u=ye(o,{blockId:n.id,offset:0},t),c=Ge(u,d),h=N(c.doc,n.id);if(h.type==="listItem"){let f=/^(\d{1,9})/.exec(i),p=/^\[[xX]\]/.test(i),m=Ue(h.listType,h.content,{id:h.id,indent:h.indent,checked:p,start:h.listType==="ordered"&&f?Number(f[1]):void 0,quote:M(h)});c=j(c,Re(h,m),c.selection)}return c}return null}function pi(o){if(!R(o.selection))return null;let e=o.selection.focus,t=N(o.doc,e.blockId);if(Q(t))return null;let n=F(t,e.cell);return n?{pos:e,block:t,content:n}:null}var yc=[{re:/(?:^|[^*])\*\*([^*\s](?:[^*]*[^*\s])?)\*\*$/,mark:"bold",delim:2},{re:/(?:^|[^_\p{L}\p{N}])__([^_\s](?:[^_]*[^_\s])?)__$/u,mark:"bold",delim:2},{re:/~~([^~\s](?:[^~]*[^~\s])?)~~$/,mark:"strike",delim:2},{re:/(?:^|[^*])\*([^*\s](?:[^*]*[^*\s])?)\*$/,mark:"italic",delim:1},{re:/(?:^|[^_\p{L}\p{N}])_([^_\s](?:[^_]*[^_\s])?)_$/u,mark:"italic",delim:1},{re:/`([^`]+)`$/,mark:"code",delim:1}];function mi(o){let e=pi(o);if(!e)return null;let{pos:t,block:n,content:i}=e,r=I(i).slice(0,t.offset);for(let s of yc){let l=s.re.exec(r);if(!l)continue;let a=l[1],d=t.offset,u=d-s.delim,c=u-a.length,h=c-s.delim;if(ns(r,h)||s.mark!=="code"&&ns(r,u)||jo(i,h,d,"code")||C(i,h,d).some(v=>v.image))continue;let f=Zt(i,c,u,s.mark,!0);f=st(f,u,d),f=st(f,h,c);let p=u-s.delim,m=ze(n,t.cell,f),y=j(o,m,$(n.id,p,t.cell)),g=Gt(f,p).marks.filter(v=>v!==s.mark);return{...y,storedMarks:g}}return null}function ns(o,e){let t=0;for(;e-t-1>=0&&o[e-t-1]==="\\";)t++;return t%2===1}function gi(o,e){let t=e.length>0?pi(o):null;if(!t)return null;let{pos:n,block:i,content:r}=t,s=I(r),l=n.offset,a=Math.max(s.lastIndexOf(`
11
+ `,l-1)+1,l-1e3);for(let d=l-1;d>=a;d--)for(let u of e){if(!u.triggers.includes(s[d])||u.match(s,d)!==l||!C(r,d,l).every(f=>!f.token&&!f.image&&!f.marks.includes("code")&&!f.marks.includes("html")))continue;let h=ze(i,n.cell,Zr(r,d,l,u.name));return j(o,h,o.selection)}return null}function bi(o,e,t){if(t.length===0||o.doc===e.doc)return o;let n=new Set(e.doc.blocks),i=null;return o.doc.blocks.forEach((r,s)=>{if(n.has(r)||r.type==="divider")return;let l=r.type==="table"?r.rows.flatMap((d,u)=>d.map((c,h)=>({row:u,col:h}))):[void 0],a=r;for(let d of l){let u=F(a,d);if(!u?.some(h=>h.token))continue;let c=kc(u,t);c!==u&&(a=ze(a,d,c))}a!==r&&((i??=[...o.doc.blocks])[s]=a)}),i?{...o,doc:{...o.doc,blocks:i}}:o}function yi(o,e){if(o.doc===e.doc)return o;let t=null,n=0;return o.doc.blocks.forEach((i,r)=>{(i.type!=="listItem"||M(i)!==M(o.doc.blocks[r-1]))&&(n=0),i.type==="listItem"&&(i.indent>n&&((t??=[...o.doc.blocks])[r]={...i,indent:n}),n=Math.min(i.indent,n)+1)}),t?{...o,doc:{...o.doc,blocks:t}}:o}function kc(o,e){let t=I(o),n=o,i=0;for(let r of o){let s=i,l=i+=r.text.length;if(!r.token)continue;let a=r.marks.includes("code")?void 0:e.find(h=>h.name===r.token),d=s;for(;a&&d<l;){let h=a.match(t,d);if(h<=d||h>l)break;d=h}if(d===l)continue;let{token:u,...c}=r;n=ce(C(n,0,s),[c],C(n,l))}return n}function ki(o){let e=pi(o);if(!e)return null;let{pos:t,block:n,content:i}=e,r=I(i),s=t.offset-1;if(s<=0||!/\s/.test(r[s]))return null;let l=s;for(;l>0&&!/\s/.test(r[l-1]);)l--;let a=r.slice(l,s),d=null;for(let c of a.matchAll(/www\.|(?:https?|ftp):\/\//gi)){if(!It(c.index===0?void 0:a[c.index-1],c[0].toLowerCase()==="www."))continue;let h=lt(a,c.index);if(h){d={from:l+c.index,to:l+h.end,href:h.href};break}}if(!d){let c=at(a)[0];c&&(d={from:l+c.from,to:l+c.to,href:"mailto:"+a.slice(c.from,c.to)})}if(!d||C(i,d.from,d.to).some(ct))return null;let u=ze(n,t.cell,Go(i,d.from,d.to,d.href));return j(o,u,o.selection)}function vi(o){let{from:e,to:t}=Me(o.doc,o.selection),n=L(o.doc,e.blockId),i=L(o.doc,t.blockId);if(n===i){let r=o.doc.blocks[n];if(q(r))return[D(C(r.content,e.offset,t.offset))];if(r.type==="table"&&e.cell&&de(e.cell,t.cell))return[D(C(Ce(r,e.cell),e.offset,t.offset))]}return o.doc.blocks.slice(n,i+1).map(r=>{if(!q(r))return dt(r);let s=r.id===e.blockId?e.offset:0,l=r.id===t.blockId?t.offset:1/0;return dt(z(r,C(r.content,s,l)))})}function Xn(o,e){if(e.length===0)return J(o);let t=J(o),n=t.selection.focus,i=L(t.doc,n.blockId),r=t.doc.blocks[i];if(!q(r)||Q(r)){let f=e[0];if(r.type==="table"&&e.length===1&&q(f)&&!Q(f)){let m=Ce(r,n.cell),y=f.content.map(b=>({...b,text:b.text.replace(/\n/g," ")})),g=ce(C(m,0,n.offset),y,C(m,n.offset)),v=n.offset+B(y);return j(t,ze(r,n.cell,g),$(r.id,v,n.cell))}let p=e.map(m=>q(m)?I(Ct(m.content)):"").filter(Boolean).join(`
12
+ `);return ue(t,p)}let s=C(r.content,0,n.offset),l=C(r.content,n.offset),a=e[0];if(e.length===1&&q(a)&&!(Q(a)&&B(r.content)>0)){let f=B(r.content)===0?{...a,id:r.id}:r,p=ce(s,a.content,l);return j(t,z(f,p),$(r.id,n.offset+B(a.content)))}let d=[],u=e.slice();s.length>0?q(a)&&!Q(a)?(d.push(z(r,ce(s,a.content))),u=u.slice(1)):d.push(z(r,s)):q(a)&&(d.push({...a,id:r.id}),u=u.slice(1)),d.push(...u);let c=d[d.length-1],h;if(q(c)&&!Q(c))h={blockId:c.id,offset:B(c.content)},l.length>0&&(d[d.length-1]=z(c,ce(c.content,l)));else{let f=z(Fn(r),l);d.push(f),h={blockId:f.id,offset:0}}return H(t,O(t,i,1,...d),{anchor:h,focus:h})}function xi(o){let e=o.doc.blocks,t={anchor:V(e[0]),focus:P(e[e.length-1])};return{...o,selection:t,storedMarks:null}}function cn(o,e,t={}){if(e.length===0)return o;let n=t.at??"selection",i=o,r;if(n==="selection")i=J(o),r=i.selection.focus;else if(n==="end"){let u=o.doc.blocks[o.doc.blocks.length-1];r=P(u)}else r=te(o.doc,{anchor:n,focus:n}).focus;let s,l;if(t.block||n==="end"?{state:s,after:l}=vc(i,e,r):(s=Xn({...i,selection:{anchor:r,focus:r}},e),l=s.selection.focus),t.select!=="keep")return s;let a=u=>u.blockId===r.blockId&&de(u.cell,r.cell)&&u.offset>r.offset?{...l,offset:l.offset+u.offset-r.offset}:u,d=te(s.doc,{anchor:a(i.selection.anchor),focus:a(i.selection.focus)});return{...s,selection:d}}function vc(o,e,t){let n=L(o.doc,t.blockId),i=o.doc.blocks[n],r=(d,u,c)=>{let h=P(u);return{state:H(o,d,{anchor:h,focus:h}),after:c}},s=e[e.length-1];if(i.type==="paragraph"&&B(i.content)===0)return r(O(o,n,1,...e),s,P(s));if(!q(i)||Q(i)||t.offset>=B(i.content))return r(O(o,n+1,0,...e),s,t);if(t.offset===0)return r(O(o,n,0,...e),s,V(i));let l=z(i,C(i.content,0,t.offset)),a={...z(i,C(i.content,t.offset)),id:ee()};return a.type==="listItem"&&a.start!==void 0&&(a={...a,start:void 0}),a=On(a),r(O(o,n,1,l,...e,a),s,V(a))}function dn(o){let e="",t=o.blocks,n=0;for(;n<t.length;){let i=t[n],r=M(i);if(r){let s=n+1;for(;s<t.length&&oe(i,t[s]);)s++;e+=wc(r==="quote"?void 0:r,dn({blocks:t.slice(n,s).map(Mt)})),n=s}else if(i.type==="listItem"){let s=n;for(;s<t.length&&t[s].type==="listItem"&&M(t[s])===null;)s++;e+=Sc(t.slice(n,s)),n=s}else e+=xc(i),n++}return e}function xc(o){switch(o.type){case"paragraph":{let e=Y(o),t=e===null?void 0:C(o.content,e,e+1)[0]?.image?.align;return`<p${t?` style="text-align:${t}"`:""}>${Yn(o.content)}</p>`}case"heading":return`<h${o.level}>${Yn(o.content)}</h${o.level}>`;case"code":return`<pre><code${o.language?` class="language-${Ie(o.language)}"`:""}>${Ie(I(o.content))}</code></pre>`;case"raw":return o.syntax==="html"?I(o.content):`<pre>${Ie(I(o.content))}</pre>`;case"divider":return"<hr>";case"details":return`<details${o.open?" open":""}><summary>${Ie(I(o.content))}</summary>`;case"detailsEnd":return"</details>";case"table":{let e=(r,s,l)=>{let a=o.align[l];return`<${r}${a?` style="text-align: ${a}"`:""}>${Yn(s)}</${r}>`},[t,...n]=o.rows,i="<table>";return t&&(i+=`<thead><tr>${t.map((r,s)=>e("th",r,s)).join("")}</tr></thead>`),n.length>0&&(i+=`<tbody>${n.map(r=>`<tr>${r.map((s,l)=>e("td",s,l)).join("")}</tr>`).join("")}</tbody>`),i+"</table>"}case"listItem":case"quote":return dn({blocks:[o]})}}function wc(o,e){if(!o)return`<blockquote>${e}</blockquote>`;let t=o[0].toUpperCase()+o.slice(1);return`<blockquote class="markdown-alert markdown-alert-${o}"><p class="markdown-alert-title"><strong>${t}</strong></p>${e}</blockquote>`}function Sc(o){let e="",t=[],n=i=>{for(;t.length>i;){let r=t.pop();r.liOpen&&(e+="</li>"),e+=`</${r.tag}>`}};for(let i of o){let r=i.listType==="ordered"?"ol":"ul",s=Math.min(i.indent,t.length);n(s+1);let l=t[s];if(l&&l.tag!==r&&n(s),!t[s]){let u=i.listType==="ordered"&&i.start!==void 0?` start="${i.start}"`:"";e+=`<${r}${u}>`,t.push({tag:r,liOpen:!1})}let a=t[s];a.liOpen&&(e+="</li>");let d=i.listType==="task"?`<input type="checkbox" disabled${i.checked?" checked":""}> `:"";e+=`<li>${d}${Yn(i.content)}`,a.liOpen=!0}return n(0),e}function Ie(o){return o.replace(/[&<>"]/g,e=>e==="&"?"&amp;":e==="<"?"&lt;":e===">"?"&gt;":"&quot;")}function Yn(o){let e="",t=0;for(;t<o.length;){let{link:n,linkTitle:i}=o[t],r=t,s="";for(;r<o.length&&ae(o[r],o[t]);)s+=Tc(o[r++]);let l=i?` title="${Ie(i)}"`:"";e+=n===void 0?s:`<a href="${Ie(n)}"${l}>${s}</a>`,t=r}return e}function Tc(o){let e;if(o.image){let{src:t,alt:n,title:i,width:r,height:s}=o.image;e=`<img src="${Ie(t)}" alt="${Ie(n)}"${i?` title="${Ie(i)}"`:""}`,r&&(e+=` width="${r}"${s?` height="${s}"`:""}`),e+=">"}else o.marks.includes("html")?e=o.text:e=Ie(o.text).replace(/\n/g,"<br>");return o.marks.includes("code")&&(e=`<code>${e}</code>`),o.marks.includes("strike")&&(e=`<s>${e}</s>`),o.marks.includes("italic")&&(e=`<em>${e}</em>`),o.marks.includes("bold")&&(e=`<strong>${e}</strong>`),e}function no(o,e){let t=e??(typeof DOMParser>"u"?null:new DOMParser);if(!t)throw new Error("htmlToDoc needs a DOMParser (pass one in outside the browser)");let n=t.parseFromString(o,"text/html"),i=new Ei;return i.blocks(n.body,Ic),{blocks:i.finish()}}var Ec=new Set(["html","body","meta","div","span","br","font"]),Mc=/font-weight\s*:\s*(?:bold|[6-9]00)|font-style\s*:\s*italic|text-decoration[^;"']*line-through/i;function ds(o){let e=o.replace(/<!--[\s\S]*?-->/g,"").replace(/<(style|script|head|title)\b[\s\S]*?<\/\1\s*>/gi,"");for(let t of e.matchAll(/<([A-Za-z][A-Za-z0-9-]*)\b([^>]*)>/g))if(!Ec.has(t[1].toLowerCase())||Mc.test(t[2]))return!1;return!0}var Jn=1,eo=3,to=new Set(["script","style","head","title","meta","link","template","noscript","iframe","object","embed","svg","canvas","audio","video","select","textarea","button","input","colgroup"]),un=new Set(["address","article","aside","blockquote","body","center","dd","details","dialog","dir","div","dl","dt","fieldset","figcaption","figure","footer","form","h1","h2","h3","h4","h5","h6","header","hgroup","hr","li","main","menu","nav","ol","p","pre","section","summary","table","ul","caption","thead","tbody","tfoot","tr","td","th"]),Cc=[...un].join(",");function ve(o){return o.tagName.toLowerCase()}function Si(o){return o==="ul"||o==="ol"||o==="menu"||o==="dir"}function us(o){let e=new Map,t=o.getAttribute("style");if(!t)return e;for(let n of t.split(";")){let i=n.indexOf(":");i<0||e.set(n.slice(0,i).trim().toLowerCase(),n.slice(i+1).trim().toLowerCase())}return e}var Ic={marks:[],whiteSpace:"normal"},Lc=/monospace|courier|consolas|menlo|monaco|source code|roboto mono|fira code/;function Dt(o,e){let t=ve(o),n=new Set(e.marks),i=e.link,r=e.whiteSpace;if((t==="b"||t==="strong")&&n.add("bold"),(t==="i"||t==="em"||t==="cite"||t==="dfn"||t==="var")&&n.add("italic"),(t==="s"||t==="del"||t==="strike")&&n.add("strike"),(t==="code"||t==="kbd"||t==="samp"||t==="tt")&&n.add("code"),t==="pre"&&(r="pre"),t==="a"){let c=o.getAttribute("href")?.trim();c&&!/^(?:javascript|vbscript|data):/i.test(c)&&(i=c)}let s=us(o),l=s.get("font-weight");l!==void 0&&(/^(?:bold|bolder|[6-9]00)$/.test(l)?n.add("bold"):/^(?:normal|lighter|[1-5]00)$/.test(l)&&n.delete("bold"));let a=s.get("font-style");a!==void 0&&(/^(?:italic|oblique)/.test(a)?n.add("italic"):a==="normal"&&n.delete("italic")),/line-through/.test(s.get("text-decoration")??s.get("text-decoration-line")??"")&&n.add("strike"),Lc.test(s.get("font-family")??"")&&n.add("code");let d=s.get("white-space");d!==void 0&&(r=/^(?:pre|pre-wrap|break-spaces)$/.test(d)?"pre":d==="pre-line"?"pre-line":"normal");let u=rt(n);return i===void 0?{marks:u,whiteSpace:r}:{marks:u,link:i,whiteSpace:r}}function cs(o){let t=/(?:^|\s)markdown-alert-([a-z]+)(?:\s|$)/.exec(o.getAttribute("class")??"")?.[1];return t&&Ve.includes(t)?t:void 0}function Bc(o,e){return(o.getAttribute("class")??"").split(/\s+/).includes(e)}var Ei=class o{out=[];spans=[];finish(){return this.flush(),this.out}blocks(e,t,n){for(let i of Array.from(e.childNodes))i.nodeType===eo?this.text(i.nodeValue??"",t):i.nodeType===Jn&&!n?.(i)&&this.element(i,t)}element(e,t){let n=ve(e);if(to.has(n))return;let i=Dt(e,t);if(/^h[1-6]$/.test(n)){this.flush();let r=this.inlineOf(e,i);this.out.push(nt(Number(n[1]),r))}else if(Si(n))this.flush(),this.list(e,0,i);else if(n==="li")this.flush(),this.listItem(e,"bullet",0,void 0,i);else if(n==="details"){this.flush();let r=Array.from(e.children).find(l=>ve(l)==="summary"),s=(r?.textContent??"").replace(/\s+/g," ").trim();this.out.push(St(ge(s),{open:e.hasAttribute("open")})),this.blocks(e,i,l=>l===r),this.flush(),this.out.push(Tt())}else n==="blockquote"||cs(e)?(this.flush(),this.blockquote(e,i)):n==="pre"?(this.flush(),this.out.push(Ee(Ac(e),Nc(e)))):n==="table"?(this.flush(),this.table(e,i)):n==="hr"?(this.flush(),this.out.push(it())):un.has(n)?(this.flush(),this.blocks(e,i),this.flush()):e.querySelector(Cc)?this.blocks(e,i):this.inline(e,t)}push(e,t,n){let i=t.link===void 0?{text:e,marks:t.marks}:{text:e,marks:t.marks,link:t.link};this.spans.push(n?{...i,...n}:i)}atLineStart(){let e=this.lastChar();return e===""||e===`
13
13
  `}lastChar(){for(let e=this.spans.length-1;e>=0;e--){let t=this.spans[e].text;if(t)return t[t.length-1]}return""}text(e,t){let n=e.replace(/\r\n?/g,`
14
14
  `);if(t.whiteSpace==="normal"?n=n.replace(/[ \t\n\f]+/g," "):t.whiteSpace==="pre-line"&&(n=n.replace(/[ \t\f]+/g," ").replace(/ ?\n ?/g,`
15
15
  `)),t.whiteSpace!=="pre"){let i=this.lastChar();n.startsWith(" ")&&(i===""||i===" "||i===`
16
16
  `)&&(n=n.slice(1))}n=n.replace(/\u00a0/g," "),n&&this.push(n,t)}lineBreak(e){this.trimTrailingSpace(),this.push(`
17
- `,e)}trimTrailingSpace(){let e=this.spans[this.spans.length-1];e&&!e.image&&e.text.endsWith(" ")&&!e.marks.includes("code")&&(this.spans[this.spans.length-1]={...e,text:e.text.replace(/ +$/,"")})}inline(e,t){let n=ve(e);if(to.has(n))return;let i=Dt(e,t);if(n==="br"){this.lineBreak(i);return}if(n==="img"){let s=e.getAttribute("src")??"";if(!s||/^(?:javascript|vbscript):/i.test(s))return;let l=e.getAttribute("alt")??"",a=e.getAttribute("title"),d=f=>{let p=e.getAttribute(f)?.trim()??"";return/^[1-9][0-9]{0,4}$/.test(p)?Number(p):0},u=d("width"),c=u?d("height"):0,h={src:s,alt:l,...a?{title:a}:{},...u?{width:u}:{},...c?{height:c}:{}};this.push("\uFFFC",i,{image:h});return}let r=un.has(n);r&&!this.atLineStart()&&this.lineBreak(i),this.inlineChildren(e,i),r&&!this.atLineStart()&&this.lineBreak(i)}inlineChildren(e,t){for(let n of Array.from(e.childNodes))n.nodeType===eo?this.text(n.nodeValue??"",t):n.nodeType===Jn&&this.inline(n,t)}inlineOf(e,t){let n=this.spans;this.spans=[],this.inlineChildren(e,t);let i=Ti(this.spans);return this.spans=n,i}flush(){let e=Ti(this.spans);this.spans=[],e.length>0&&this.out.push(O(e))}list(e,t,n){let i=ve(e)==="ol",r=e.getAttribute("start"),s=i&&r&&/^\d+$/.test(r)?Number(r):void 0;for(let l of Array.from(e.children)){let a=ve(l);a==="li"?(this.listItem(l,i?"ordered":"bullet",t,s,n),s=void 0):Si(a)?this.list(l,t+1,Dt(l,n)):to.has(a)||(this.element(l,n),this.flush())}}listItem(e,t,n,i,r){let s=Dt(e,r),l=Number(e.getAttribute("aria-level")),a=Math.min(5,l>=1?l-1:n),d=t,u=!1,c=Array.from(e.querySelectorAll("input")).find(m=>m.getAttribute("type")?.toLowerCase()==="checkbox"&&m.closest("li")===e);c?(d="task",u=c.hasAttribute("checked")):e.getAttribute("role")==="checkbox"&&(d="task",u=e.getAttribute("aria-checked")==="true");let h=this.spans;this.spans=[];let f=!1,p=()=>{if(f)return;f=!0;let m=Ti(this.spans);this.spans=[],this.out.push(Ue(d,m,{indent:a,checked:u,start:i}))};for(let m of Array.from(e.childNodes)){if(m.nodeType===eo){this.text(m.nodeValue??"",s);continue}if(m.nodeType!==Jn)continue;let y=m,g=ve(y);Si(g)?(p(),this.list(y,a+1,Dt(y,s))):g==="p"||g==="div"||!un.has(g)||/^h[1-6]$/.test(g)?(!f&&un.has(g)&&!this.atLineStart()&&this.lineBreak(s),this.inline(y,s)):(p(),this.element(y,s))}f?this.flush():p(),this.spans=h}blockquote(e,t){let n=cs(e),i=new o;i.blocks(e,t,n?a=>Lc(a,"markdown-alert-title"):void 0);let r=i.finish(),s=this.out.length;for(let a of r)switch(a.type){case"paragraph":case"quote":this.out.push(Ne(a.content,void 0,n));break;case"details":case"detailsEnd":this.out.push(a);break;default:this.out.push(U(a,n??"quote"))}let l=this.out[s];l&&M(l)!==null&&M(this.out[s-1])===M(l)&&(this.out[s]=Qt(l))}table(e,t){let i=Array.from(e.querySelectorAll("tr")).filter(a=>a.closest("table")===e).map(a=>Array.from(a.children).filter(d=>ve(d)==="td"||ve(d)==="th")),r=Math.max(0,...i.map(a=>a.length));if(r===0)return;let s=Array.from({length:r},(a,d)=>Nc(i[0]?.[d])),l=i.map(a=>Array.from({length:r},(d,u)=>{let c=a[u];return c?this.inlineOf(c,Dt(c,t)):[]}));this.out.push(zt(s,l))}};function Ti(o){let e=G(o);for(;e.length>0;){let t=e[0];if(t.image||t.marks.includes("code"))break;let n=t.text.replace(/^[ \n]+/,"");if(n){e[0]={...t,text:n};break}e.shift()}for(;e.length>0;){let t=e[e.length-1];if(t.image||t.marks.includes("code"))break;let n=t.text.replace(/[ \n]+$/,"");if(n){e[e.length-1]={...t,text:n};break}e.pop()}return e}function Bc(o){let e=[o.getAttribute("class")??"",o.querySelector("code")?.getAttribute("class")??""].join(" ");return/(?:^|\s)(?:language|lang)-([^\s]+)/.exec(e)?.[1]??o.getAttribute("data-language")??""}function Ac(o){let e="",t=n=>{if(n.nodeType===eo)e+=n.nodeValue??"";else if(n.nodeType===Jn){let i=n;ve(i)==="br"?e+=`
17
+ `,e)}trimTrailingSpace(){let e=this.spans[this.spans.length-1];e&&!e.image&&e.text.endsWith(" ")&&!e.marks.includes("code")&&(this.spans[this.spans.length-1]={...e,text:e.text.replace(/ +$/,"")})}inline(e,t){let n=ve(e);if(to.has(n))return;let i=Dt(e,t);if(n==="br"){this.lineBreak(i);return}if(n==="img"){let s=e.getAttribute("src")??"";if(!s||/^(?:javascript|vbscript):/i.test(s))return;let l=e.getAttribute("alt")??"",a=e.getAttribute("title"),d=f=>{let p=e.getAttribute(f)?.trim()??"";return/^[1-9][0-9]{0,4}$/.test(p)?Number(p):0},u=d("width"),c=u?d("height"):0,h={src:s,alt:l,...a?{title:a}:{},...u?{width:u}:{},...c?{height:c}:{}};this.push("\uFFFC",i,{image:h});return}let r=un.has(n);r&&!this.atLineStart()&&this.lineBreak(i),this.inlineChildren(e,i),r&&!this.atLineStart()&&this.lineBreak(i)}inlineChildren(e,t){for(let n of Array.from(e.childNodes))n.nodeType===eo?this.text(n.nodeValue??"",t):n.nodeType===Jn&&this.inline(n,t)}inlineOf(e,t){let n=this.spans;this.spans=[],this.inlineChildren(e,t);let i=Ti(this.spans);return this.spans=n,i}flush(){let e=Ti(this.spans);this.spans=[],e.length>0&&this.out.push(D(e))}list(e,t,n){let i=ve(e)==="ol",r=e.getAttribute("start"),s=i&&r&&/^\d+$/.test(r)?Number(r):void 0;for(let l of Array.from(e.children)){let a=ve(l);a==="li"?(this.listItem(l,i?"ordered":"bullet",t,s,n),s=void 0):Si(a)?this.list(l,t+1,Dt(l,n)):to.has(a)||(this.element(l,n),this.flush())}}listItem(e,t,n,i,r){let s=Dt(e,r),l=Number(e.getAttribute("aria-level")),a=Math.min(5,l>=1?l-1:n),d=t,u=!1,c=Array.from(e.querySelectorAll("input")).find(m=>m.getAttribute("type")?.toLowerCase()==="checkbox"&&m.closest("li")===e);c?(d="task",u=c.hasAttribute("checked")):e.getAttribute("role")==="checkbox"&&(d="task",u=e.getAttribute("aria-checked")==="true");let h=this.spans;this.spans=[];let f=!1,p=()=>{if(f)return;f=!0;let m=Ti(this.spans);this.spans=[],this.out.push(Ue(d,m,{indent:a,checked:u,start:i}))};for(let m of Array.from(e.childNodes)){if(m.nodeType===eo){this.text(m.nodeValue??"",s);continue}if(m.nodeType!==Jn)continue;let y=m,g=ve(y);Si(g)?(p(),this.list(y,a+1,Dt(y,s))):g==="p"||g==="div"||!un.has(g)||/^h[1-6]$/.test(g)?(!f&&un.has(g)&&!this.atLineStart()&&this.lineBreak(s),this.inline(y,s)):(p(),this.element(y,s))}f?this.flush():p(),this.spans=h}blockquote(e,t){let n=cs(e),i=new o;i.blocks(e,t,n?a=>Bc(a,"markdown-alert-title"):void 0);let r=i.finish(),s=this.out.length;for(let a of r)switch(a.type){case"paragraph":case"quote":this.out.push(Ne(a.content,void 0,n));break;case"details":case"detailsEnd":this.out.push(a);break;default:this.out.push(U(a,n??"quote"))}let l=this.out[s];l&&M(l)!==null&&M(this.out[s-1])===M(l)&&(this.out[s]=Qt(l))}table(e,t){let i=Array.from(e.querySelectorAll("tr")).filter(a=>a.closest("table")===e).map(a=>Array.from(a.children).filter(d=>ve(d)==="td"||ve(d)==="th")),r=Math.max(0,...i.map(a=>a.length));if(r===0)return;let s=Array.from({length:r},(a,d)=>Rc(i[0]?.[d])),l=i.map(a=>Array.from({length:r},(d,u)=>{let c=a[u];return c?this.inlineOf(c,Dt(c,t)):[]}));this.out.push(zt(s,l))}};function Ti(o){let e=G(o);for(;e.length>0;){let t=e[0];if(t.image||t.marks.includes("code"))break;let n=t.text.replace(/^[ \n]+/,"");if(n){e[0]={...t,text:n};break}e.shift()}for(;e.length>0;){let t=e[e.length-1];if(t.image||t.marks.includes("code"))break;let n=t.text.replace(/[ \n]+$/,"");if(n){e[e.length-1]={...t,text:n};break}e.pop()}return e}function Ac(o){let e=[o.getAttribute("class")??"",o.querySelector("code")?.getAttribute("class")??""].join(" ");return/(?:^|\s)(?:language|lang)-([^\s]+)/.exec(e)?.[1]??o.getAttribute("data-language")??""}function Nc(o){let e="",t=n=>{if(n.nodeType===eo)e+=n.nodeValue??"";else if(n.nodeType===Jn){let i=n;ve(i)==="br"?e+=`
18
18
  `:to.has(ve(i))||i.childNodes.forEach(t)}};return o.childNodes.forEach(t),e.replace(/\r\n?/g,`
19
- `).replace(/\n$/,"")}function Nc(o){if(!o)return null;let e=[o,...Array.from(o.children).slice(0,1)];for(let t of e){let n=(us(t).get("text-align")??t.getAttribute("align")??"").toLowerCase();if(n==="left"||n==="start")return"left";if(n==="center")return"center";if(n==="right"||n==="end")return"right"}return null}var oo=class{constructor(e){this.source=e}undoStack=[];redoStack=[];lastKind=null;lastTime=0;record(e,t,n=Date.now()){t==="typing"&&this.lastKind==="typing"&&n-this.lastTime<1e3||(this.undoStack.push({doc:e.doc,selection:e.selection,source:this.source()}),this.undoStack.length>500&&this.undoStack.shift()),this.redoStack=[],this.lastKind=t,this.lastTime=n}clear(){this.undoStack=[],this.redoStack=[],this.lastKind=null}breakGroup(){this.lastKind=null}undo(e){return this.step(e,this.undoStack,this.redoStack)}redo(e){return this.step(e,this.redoStack,this.undoStack)}step(e,t,n){let i=t.pop();return i?(n.push({doc:e.doc,selection:e.selection,source:this.source()}),this.lastKind=null,{state:{doc:i.doc,selection:i.selection,storedMarks:null},source:i.source}):null}};var Mi={text:"Text",heading1:"Heading 1",heading2:"Heading 2",heading3:"Heading 3",heading4:"Heading 4",bulletList:"Bulleted list",numberedList:"Numbered list",todoList:"To-do list",task:"Task",footnotes:"Footnotes",backToReference:"Back to reference",quote:"Quote",callout:"Callout",calloutNote:"Note",calloutTip:"Tip",calloutImportant:"Important",calloutWarning:"Warning",calloutCaution:"Caution",code:"Code block",details:"Collapsible section",detailsHint:"Title",expandSection:"Expand",collapseSection:"Collapse",table:"Table",divider:"Divider",noResults:"No results",suggestions:"Suggestions",commands:"Commands",loading:"Loading\u2026",duplicate:"Duplicate",delete:"Delete",bold:"Bold",italic:"Italic",strike:"Strikethrough",inlineCode:"Code",link:"Link",textStyle:"Text style",list:"List",linkPlaceholder:"Paste or type a link\u2026",removeLink:"Remove link",openLink:"Open link",copyLink:"Copy link",editLink:"Edit link",slashHint:"Type '/' for commands",blockHandle:"Open block menu",listHint:"List",quoteHint:"Quote",language:"Language",plainText:"text",copyCode:"Copy code",copied:"Copied",addRowAbove:"Add row above",addRowBelow:"Add row below",addColumnLeft:"Add column left",addColumnRight:"Add column right",deleteRow:"Delete row",deleteColumn:"Delete column",align:"Align",alignLeft:"Left",alignCenter:"Center",alignRight:"Right",tableSection:"Table",imageSection:"Image",imageAlignLeft:"Align left",imageAlignCenter:"Align center",imageAlignRight:"Align right",resetImageSize:"Reset size",altText:"Alt text",altTextPlaceholder:"Describe the image\u2026",imageUnavailable:"Image unavailable",resizeImage:"Resize image"};var Ci=["M10 11v6","M14 11v6","M19 6v14a2 2 0 0 1-2 2H7a2 2 0 0 1-2-2V6","M3 6h18","M8 6V4a2 2 0 0 1 2-2h4a2 2 0 0 1 2 2v2"],Rc={text:["M12 4v16","M4 7V5a1 1 0 0 1 1-1h14a1 1 0 0 1 1 1v2","M9 20h6"],heading1:["M4 12h8","M4 18V6","M12 18V6","m17 12 3-2v8"],heading2:["M4 12h8","M4 18V6","M12 18V6","M21 18h-4c0-4 4-3 4-6 0-1.5-2-2.5-4-1"],heading3:["M4 12h8","M4 18V6","M12 18V6","M17.5 10.5c1.7-1 3.5 0 3.5 1.5a2 2 0 0 1-2 2","M17 17.5c2 1.5 4 .3 4-1.5a2 2 0 0 0-2-2"],heading4:["M12 18V6","M17 10v3a1 1 0 0 0 1 1h3","M21 10v8","M4 12h8","M4 18V6"],bulletList:["M3 5h.01","M3 12h.01","M3 19h.01","M8 5h13","M8 12h13","M8 19h13"],numberedList:["M11 5h10","M11 12h10","M11 19h10","M4 4h1v5","M4 9h2","M6.5 20H3.4c0-1 2.6-1.925 2.6-3.5a1.5 1.5 0 0 0-2.6-1.02"],todoList:["M13 5h8","M13 12h8","M13 19h8","m3 17 2 2 4-4",["rect",{x:"3",y:"4",width:"6",height:"6",rx:"1"}]],quote:["M17 5H3","M21 12H8","M21 19H8","M3 12v7"],callout:[["circle",{cx:"12",cy:"12",r:"10"}],"M12 16v-4","M12 8h.01"],calloutNote:[["circle",{cx:"12",cy:"12",r:"10"}],"M12 16v-4","M12 8h.01"],calloutTip:["M15 14c.2-1 .7-1.7 1.5-2.5 1-.9 1.5-2.2 1.5-3.5A6 6 0 0 0 6 8c0 1 .2 2.2 1.5 3.5.7.7 1.3 1.5 1.5 2.5","M9 18h6","M10 22h4"],calloutImportant:["M22 17a2 2 0 0 1-2 2H6.828a2 2 0 0 0-1.414.586l-2.202 2.202A.71.71 0 0 1 2 21.286V5a2 2 0 0 1 2-2h16a2 2 0 0 1 2 2z","M12 15h.01","M12 7v4"],calloutWarning:["m21.73 18-8-14a2 2 0 0 0-3.48 0l-8 14A2 2 0 0 0 4 21h16a2 2 0 0 0 1.73-3","M12 9v4","M12 17h.01"],calloutCaution:["M12 16h.01","M12 8v4","M15.312 2a2 2 0 0 1 1.414.586l4.688 4.688A2 2 0 0 1 22 8.688v6.624a2 2 0 0 1-.586 1.414l-4.688 4.688a2 2 0 0 1-1.414.586H8.688a2 2 0 0 1-1.414-.586l-4.688-4.688A2 2 0 0 1 2 15.312V8.688a2 2 0 0 1 .586-1.414l4.688-4.688A2 2 0 0 1 8.688 2z"],details:["M10 5h11","M10 12h11","M10 19h11","m3 10 3-3-3-3","m3 20 3-3-3-3"],code:["m10 9-3 3 3 3","m14 15 3-3-3-3",["rect",{x:"3",y:"3",width:"18",height:"18",rx:"2"}]],table:["M12 3v18",["rect",{width:"18",height:"18",x:"3",y:"3",rx:"2"}],"M3 9h18","M3 15h18"],divider:["M5 12h14"],duplicate:[["rect",{width:"14",height:"14",x:"8",y:"8",rx:"2",ry:"2"}],"M4 16c-1.1 0-2-.9-2-2V4c0-1.1.9-2 2-2h10c1.1 0 2 .9 2 2"],copyCode:[["rect",{width:"14",height:"14",x:"8",y:"8",rx:"2",ry:"2"}],"M4 16c-1.1 0-2-.9-2-2V4c0-1.1.9-2 2-2h10c1.1 0 2 .9 2 2"],copied:["M20 6 9 17l-5-5"],delete:Ci,addRowAbove:["m5 12 7-7 7 7","M12 19V5"],backToReference:["m5 12 7-7 7 7","M12 19V5"],addRowBelow:["M12 5v14","m19 12-7 7-7-7"],addColumnLeft:["m12 19-7-7 7-7","M19 12H5"],addColumnRight:["M5 12h14","m12 5 7 7-7 7"],align:["M21 5H3","M15 12H3","M17 19H3"],alignLeft:["M21 5H3","M15 12H3","M17 19H3"],alignCenter:["M21 5H3","M17 12H7","M19 19H5"],alignRight:["M21 5H3","M21 12H9","M21 19H7"],imageAlignLeft:[["rect",{width:"9",height:"6",x:"6",y:"14",rx:"2"}],["rect",{width:"16",height:"6",x:"6",y:"4",rx:"2"}],"M2 2v20"],imageAlignCenter:["M12 2v20","M8 10H4a2 2 0 0 1-2-2V6c0-1.1.9-2 2-2h4","M16 10h4a2 2 0 0 0 2-2V6a2 2 0 0 0-2-2h-4","M8 20H7a2 2 0 0 1-2-2v-2c0-1.1.9-2 2-2h1","M16 14h1a2 2 0 0 1 2 2v2a2 2 0 0 1-2 2h-1"],imageAlignRight:[["rect",{width:"16",height:"6",x:"2",y:"4",rx:"2"}],["rect",{width:"9",height:"6",x:"9",y:"14",rx:"2"}],"M22 22V2"],resetImageSize:["M3 12a9 9 0 1 0 9-9 9.75 9.75 0 0 0-6.74 2.74L3 8","M3 3v5h5"],altText:["M12 20h-1a2 2 0 0 1-2-2 2 2 0 0 1-2 2H6","M13 8h7a2 2 0 0 1 2 2v4a2 2 0 0 1-2 2h-7","M5 16H4a2 2 0 0 1-2-2v-4a2 2 0 0 1 2-2h1","M6 4h1a2 2 0 0 1 2 2 2 2 0 0 1 2-2h1","M9 6v12"],deleteRow:Ci,deleteColumn:Ci,bold:["M6 12h9a4 4 0 0 1 0 8H7a1 1 0 0 1-1-1V5a1 1 0 0 1 1-1h7a4 4 0 0 1 0 8"],italic:[["line",{x1:"19",x2:"10",y1:"4",y2:"4"}],["line",{x1:"14",x2:"5",y1:"20",y2:"20"}],["line",{x1:"15",x2:"9",y1:"4",y2:"20"}]],strike:["M16 4H9a3 3 0 0 0-2.83 4","M14 12a4 4 0 0 1 0 8H6",["line",{x1:"4",x2:"20",y1:"12",y2:"12"}]],inlineCode:["m16 18 6-6-6-6","m8 6-6 6 6 6"],openLink:["M15 3h6v6","M10 14 21 3","M18 13v6a2 2 0 0 1-2 2H5a2 2 0 0 1-2-2V8a2 2 0 0 1 2-2h6"],copyLink:[["rect",{width:"14",height:"14",x:"8",y:"8",rx:"2",ry:"2"}],"M4 16c-1.1 0-2-.9-2-2V4c0-1.1.9-2 2-2h10c1.1 0 2 .9 2 2"],editLink:["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","m15 5 4 4"],removeLink:["m18.84 12.25 1.72-1.71h-.02a5.004 5.004 0 0 0-.12-7.07 5.006 5.006 0 0 0-6.95 0l-1.72 1.71","m5.17 11.75-1.71 1.71a5.004 5.004 0 0 0 .12 7.07 5.006 5.006 0 0 0 6.95 0l1.71-1.71","M8 2v3","M2 8h3","M16 19v3","M19 16h3"],link:["M10 13a5 5 0 0 0 7.54.54l3-3a5 5 0 0 0-7.07-7.07l-1.72 1.71","M14 11a5 5 0 0 0-7.54-.54l-3 3a5 5 0 0 0 7.07 7.07l1.71-1.71"],imageUnavailable:[["line",{x1:"2",x2:"22",y1:"2",y2:"22"}],"M10.41 10.41a2 2 0 1 1-2.83-2.83",["line",{x1:"13.5",x2:"6",y1:"13.5",y2:"21"}],["line",{x1:"18",x2:"21",y1:"12",y2:"15"}],"M3.59 3.59A1.99 1.99 0 0 0 3 5v14a2 2 0 0 0 2 2h14c.55 0 1.052-.22 1.41-.59","M21 15V5a2 2 0 0 0-2-2H9"],chevronDown:["m6 9 6 6 6-6"],selected:["M20 6 9 17l-5-5"],chevronRight:["m9 18 6-6-6-6"],blockHandle:[["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"}]]},hs="http://www.w3.org/2000/svg",Dc={viewBox:"0 0 24 24",fill:"none",stroke:"currentColor","stroke-width":"2","stroke-linecap":"round","stroke-linejoin":"round","aria-hidden":"true",focusable:"false"};function fs(o,e){let t=o.createElementNS(hs,"svg");t.setAttribute("class","mbe-icon");for(let[n,i]of Object.entries(Dc))t.setAttribute(n,i);for(let n of Rc[e]){let[i,r]=typeof n=="string"?["path",{d:n}]:n,s=o.createElementNS(hs,i);for(let[l,a]of Object.entries(r))s.setAttribute(l,a);t.appendChild(s)}return t}function X(o,e){return e===void 0||e===""?null:typeof e=="string"?o.createTextNode(e):o.importNode(e,!0)}function ft(o){return o.at+o.to-o.from}var Oc=/\|([1-9][0-9]{0,4})(?:x([1-9][0-9]{0,4}))?$/,Hc=/\|(left|center|right)(?:\|([1-9][0-9]{0,4})(?:x([1-9][0-9]{0,4}))?)?$/,ps=o=>/(^|[^\\])(\\\\)*\\$/.test(o);function io(o,e=!0){let t=Hc.exec(o);if(t&&!(e&&ps(o.slice(0,t.index))))return{align:t[1],...t[2]?{width:Number(t[2])}:{},...t[3]?{height:Number(t[3])}:{},index:t.index};let n=Oc.exec(o);return n&&!(e&&ps(o.slice(0,n.index)))?{width:Number(n[1]),...n[2]?{height:Number(n[2])}:{},index:n.index}:null}function hn(o){let e=o.width?`|${o.width}${o.height?`x${o.height}`:""}`:"";return(o.align?`|${o.align}`:"")+e}function ro(o,e){let t="";for(let n of o)switch(n.type){case"text":case"code":case"html":case"token":t+=n.value;break;case"softBreak":t+=e;break;case"hardBreak":t+=`
20
- `;break;default:t+=ro(n.children,e)}return t}import{lookupEntity as Vc}from"#entities";var pe={breaks:!1,setext:!0,autolinks:!0,callouts:!0,details:!0,syntax:[],inline:[],block:[],escape:""},ms=new WeakMap;function Ze(o){if(!o)return pe;let e=ms.get(o);if(!e){let t=o.syntax??[];e={breaks:o.breaks??!1,setext:o.setext??!0,autolinks:o.autolinks??!0,callouts:o.callouts??!0,details:o.details??!0,syntax:t,inline:t.flatMap(n=>n.inline??[]),block:t.flatMap(n=>n.block??[]),escape:[...new Set(t.map(n=>n.escape??"").join(""))].join("")},ms.set(o,e)}return e}function pt(o){let e=[o.charCodeAt(0)===65279?1:0],t=[],n=/\r\n|\n|\r/g;for(let i=n.exec(o);i;i=n.exec(o))t.push(i.index),e.push(i.index+i[0].length);return t.push(o.length),{starts:e,ends:t}}function gs(o,e,t){return{from:o,to:e,srcFrom:t,srcTo:t+(e-o),linear:!0}}var xe=class{constructor(e,t){this.content=e;this.table=t}segments=[];at=0;record(e,t){let{pos:n}=e,i=this.at;if(this.at+=t,!n)return;if(e.type==="text"&&e.pieces){let s=0,l=n.from;for(let a of e.pieces)a.at>s&&this.atomic(i+s,i+a.at,l,a.from),this.linear(i+a.at,a.from,a.to),s=ft(a),l=a.to;s<t&&this.atomic(i+s,i+t,l,n.to);return}let r=e.type==="code"?e.content:e.type==="text"||e.type==="html"||e.type==="token"?n:null;r&&r.to-r.from===t?this.linear(i,r.from,r.to):this.atomic(i,i+t,n.from,n.to)}linear(e,t,n){let{lines:i,start:r}=this.content,{starts:s,ends:l}=this.table,a=t+r,d=n+r,u=e;for(;a<d;){let c=this.lineIndex(a),h=i[c];if(!h)return;let f=s[h.line-1]??0,p=l[h.line-1]??f,m=a-h.at;if(m<h.pad){let b=Math.min(h.pad-m,d-a);this.push({from:u,to:u+b,srcFrom:f+h.offset-1,srcTo:f+h.offset,linear:!1}),a+=b,u+=b;continue}let y=m-h.pad,g=p-f-h.offset;if(y<g){let b=i[c+1],w=Math.min(g-y,d-a,b?b.at-a:1/0);this.push({from:u,to:u+w,srcFrom:f+h.offset+y,srcTo:f+h.offset+y+w,linear:!0}),a+=w,u+=w;continue}let x=s[h.line]??p;this.push({from:u,to:u+1,srcFrom:y===g?p:x,srcTo:x,linear:!1}),a+=1,u+=1}}atomic(e,t,n,i){let r={from:e,to:t,srcFrom:this.source(n),srcTo:this.source(i),linear:!1},{lines:s,start:l}=this.content,a=this.lineIndex(i+l),d=a>this.lineIndex(n+l)?this.table.starts[s[a].line-1]:void 0;this.push(d===void 0?r:{...r,nextLine:d})}source(e){let{lines:t,start:n}=this.content,{starts:i,ends:r}=this.table,s=e+n,l=t[this.lineIndex(s)];if(!l)return 0;let a=i[l.line-1]??0,d=r[l.line-1]??a,u=s-l.at;if(u<l.pad)return a+l.offset-1;let c=u-l.pad,h=d-a-l.offset;return c<=h?a+l.offset+c:i[l.line]??d}lineIndex(e){let{lines:t}=this.content,n=0,i=t.length-1;for(;n<i;){let r=n+i+1>>1;t[r].at<=e?n=r:i=r-1}return n}push(e){if(e.to<=e.from&&e.srcTo<=e.srcFrom)return;let t=this.segments[this.segments.length-1];if(t&&t.linear&&e.linear&&t.to===e.from&&t.srcTo===e.srcFrom){this.segments[this.segments.length-1]={...t,to:e.to,srcTo:e.srcTo};return}this.segments.push(e)}};function bs(o,e,t,n){let i=new xe(o,e);return i.linear(0,t,n),i.segments.filter(r=>r.linear).map(r=>({from:r.srcFrom,to:r.srcTo}))}function ys(o,e,t){let n=0,i=o.length-1;for(;n<i;){let r=n+i+1>>1;o[r][e]<=t?n=r:i=r-1}return n}function ks(o,e){if(o.length===0)return 0;let t=ys(o,"from",e),n=o[t];return e<n.from?n.srcFrom:e>=n.to?e===n.to||t===o.length-1?n.srcTo:o[t+1].srcFrom:n.linear?n.srcFrom+(e-n.from):n.srcFrom}function vs(o,e){if(o.length===0)return 0;let t=ys(o,"srcFrom",e),n=o[t];return e<n.srcFrom?n.from:e>=n.srcTo?e===n.srcTo||t===o.length-1?n.to:o[t+1].from:n.linear?n.from+(e-n.srcFrom):n.nextLine!==void 0&&e>=n.nextLine?n.to:n.from}function xs(o){return!o||o.length===0?null:{from:o[0].srcFrom,to:o[o.length-1].srcTo}}function co(o){return{text:o,lines:pt(o)}}function Ss(o,e,t,n,i){return fn(o,e,n,void 0,i)??[ot("markdown",t)]}function fn(o,e,t,n,i){if(!so(o,0,i!==void 0))return null;let r=[];Es(o,r,e,n,void 0,i);let s=r[0];if(o.type==="blockQuote"&&s&&M(s)!==null&&M(t)===M(s)){let l=Qt(s);r[0]=l;let a=n?.maps.get(s);a&&n.maps.set(l,a)}return r}function so(o,e,t=!1){switch(o.type){case"blockQuote":return t||o.children.every(n=>n.type!=="blockQuote"&&(n.type!=="list"||so(n,0)));case"list":return e<=5&&o.items.every(n=>n.children.every((i,r)=>i.type==="paragraph"&&r===0||i.type==="list"&&so(i,e+1)));default:return!0}}function uo(o,e=pe,t){let n=[];return Li(o,[],{},n,e.breaks?`
21
- `:" ",t),G(n)}function lo(o,e,t,n){let i=n&&t?new xe(t,n.lines):void 0;return{content:uo(o,e,i),map:i}}function ao(o,e,t){return e&&t&&t.maps.set(o,e.segments),o}function Ii(o,e,t,n){if(n&&t){let i=new xe(t,n.lines);i.linear(0,0,e.length),n.maps.set(o,i.segments)}return o}var Pc={emphasis:"italic",strong:"bold",strike:"strike"};function Li(o,e,t,n,i,r){let s=(l,a)=>{r?.record(a,l.text.length),n.push(t.link===void 0?l:{...l,...t})};for(let l of o)switch(l.type){case"text":s({text:l.value,marks:e},l);break;case"softBreak":s({text:i,marks:e},l);break;case"hardBreak":s({text:`
22
- `,marks:e},l);break;case"code":case"html":s({text:l.value,marks:ws(e,l.type)},l);break;case"token":s({text:l.value,marks:e,token:l.name},l);break;case"emphasis":case"strong":case"strike":Li(l.children,ws(e,Pc[l.type]),t,n,i,r);break;case"link":Li(l.children,e,l.title?{link:l.destination,linkTitle:l.title}:{link:l.destination},n,i,r);break;case"image":s({text:"\uFFFC",marks:e,image:$c(l)},l);break}}function $c(o){let e=ro(o.children," "),t=hn(o);return t&&e.endsWith(t)&&(e=e.slice(0,-t.length)),{src:o.destination,alt:e,...o.title?{title:o.title}:{},...o.align?{align:o.align}:{},...o.width?{width:o.width}:{},...o.height?{height:o.height}:{}}}function ws(o,e){return o.includes(e)?o:rt([...o,e])}function Ts(o){let e=o.length===1?o[0]:null;return e!==null&&e.text==="\xA0"&&e.marks.length===0&&!e.link&&!e.image}function Es(o,e,t,n,i,r){let s=l=>i?U(l,i):l;switch(o.type){case"paragraph":{let{content:l,map:a}=lo(o.children,t,o.source,n);Ts(l)?e.push(O()):(l.length>0||o.children.length>0)&&e.push(ao(O(l),a,n));break}case"heading":{let{content:l,map:a}=lo(o.children,t,o.source,n);e.push(ao(s(nt(o.level,l)),a,n));break}case"thematicBreak":e.push(s(it()));break;case"blockQuote":qc(o,e,t,n,r);break;case"list":Ai(o,0,e,t,i,n);break;case"codeBlock":{let l=o.value.replace(/\n$/,"");e.push(Ii(s(Ee(Bi(o.info),l)),l,o.source,n));break}case"htmlBlock":e.push(Ii(s(Dn(o.value)),o.value,o.source,n));break;case"raw":e.push(Ii(s(ot(o.name,o.value)),o.value,o.source,n));break;case"table":e.push(s(zt(o.align,o.rows.map(l=>l.map(a=>uo(a,t))))));break}}function Bi(o){return o.trim().split(/\s+/)[0]??""}function Fc(o,e){return e.task?"task":o.ordered?"ordered":"bullet"}function Ai(o,e,t,n,i,r){o.items.forEach((s,l)=>{let a=s.children[0],d=Fc(o,s),{content:u,map:c}=a?.type==="paragraph"?lo(a.children,n,a.source,r):{content:[]};t.push(ao(Ue(d,u,{indent:Math.min(e,5),checked:s.checked,start:l===0&&d==="ordered"?o.start:void 0,quote:i}),c,r));for(let h of s.children)h.type==="list"&&Ai(h,e+1,t,n,i,r)})}function qc(o,e,t,n,i){let r=o.children,s=t.callouts===!1?null:Ni(r),l=s?.type,a=l??"quote",d=c=>{i&&e.push(U(ot("markdown",_c(c,i)),a))},u=e.length;r.forEach((c,h)=>{let f=e.length;switch(c.type){case"paragraph":{let p=h===0&&s?s.rest:c.children,{content:m,map:y}=lo(p,t,c.source,n);Ts(m)?e.push(Ne([],void 0,l)):(m.length>0||p.length>0)&&e.push(ao(Ne(m,void 0,l),y,n));break}case"list":so(c,0)?Ai(c,0,e,t,a,n):c.lines&&d(c.lines);break;case"blockQuote":c.lines&&d(c.lines);break;default:Es(c,e,t,n,a,i)}i?.onQuoteChild?.(c,e.slice(f))}),l&&e.length===u&&e.push(Ne([],void 0,l))}function _c(o,e){let t=[];for(let n=o.start;n<=o.end;n++){let i=e.lines.starts[n-1],r=e.lines.ends[n-1];if(i===void 0||r===void 0)break;t.push(ho(e.text.slice(i,Math.max(i,r))))}for(;t.length>1&&/^[ \t]*$/.test(t[t.length-1]);)t.pop();return t.join(`
23
- `)}function ho(o){let e=/^ {0,3}>/.exec(o);if(!e)return o;let t=e[0].length,n=t;for(;n<o.length&&(o[n]===" "||o[n]===" ");)t+=o[n]===" "?4-t%4:1,n++;return" ".repeat(Math.max(0,t-(e[0].length+1)))+o.slice(n)}var Kc=new RegExp(`^\\[!(${Ve.join("|")})\\]$`,"i");function Ni(o){let e=o[0];if(e?.type!=="paragraph")return null;let[t,n]=e.children,i=t?.type==="text"?Kc.exec(t.value):null;return!i||n&&n.type!=="softBreak"&&n.type!=="hardBreak"?null:{type:i[1].toLowerCase(),rest:e.children.slice(2)}}function mn(o,e){let t=Ze(e);return uo(gn(o,new Map,t.inline,t.autolinks),e)}function gn(o,e,t=[],n=!1){if(Wc(o,t,n))return o?[{type:"text",value:o,pos:{from:0,to:o.length}}]:[];let i=new bo(o,e,t,n).parse();return n?Fs(i):i}var Uc=/^[^\n`[\]\\!<&*_~]*$/,zc=/www\.|:\/\/|@/i;function Wc(o,e,t){if(!Uc.test(o)||t&&zc.test(o))return!1;for(let n of e)for(let i of n.triggers)if(o.includes(i))return!1;return!0}function Fs(o){let e=!1,t=[];for(let n of o)if(n.type==="text"){let i=at(n.value);if(i.length===0){t.push(n);continue}e=!0;let r=0;for(let{from:s,to:l}of i){s>r&&t.push(Ri(n,r,s));let a=Ri(n,s,l),d={type:"link",destination:"mailto:"+a.value,title:"",children:[a]};t.push(a.pos?{...d,pos:a.pos,syntax:[{kind:"dest",...a.pos}]}:d),r=l}r<n.value.length&&t.push(Ri(n,r,n.value.length))}else if(n.type==="emphasis"||n.type==="strong"||n.type==="strike"){let i=Fs(n.children);i!==n.children&&(e=!0),t.push(i===n.children?n:{...n,children:i})}else t.push(n);return e?t:o}function Ri(o,e,t){let n=o.value.slice(e,t);if(!o.pos)return{type:"text",value:n};if(!o.pieces)return{type:"text",value:n,pos:{from:o.pos.from+e,to:o.pos.from+t}};let i=[];for(let s=qs(o.pieces,e);s<o.pieces.length&&o.pieces[s].at<t;s++){let l=o.pieces[s],a=Math.max(l.at,e),d=Math.min(ft(l),t);d>a&&i.push({at:a-e,from:l.from+(a-l.at),to:l.from+(d-l.at)})}let r={from:Ms(o,e),to:Ms(o,t)};return{type:"text",value:n,pos:r,..._s(i,n,r)?{}:{pieces:i}}}function qs(o,e){let t=0,n=o.length;for(;t<n;){let i=t+n>>1;ft(o[i])<e?t=i+1:n=i}return t}function Ms(o,e){let t=o.pieces[qs(o.pieces,e)];return t?e<t.at?t.from:t.from+(e-t.at):o.pos.to}function _s(o,e,t){let n=o[0];return o.length===1&&n.at===0&&n.from===t.from&&n.to===t.to&&e.length===t.to-t.from}function Qc(o,e,t){for(let n of e){let i=n.at+t,r=o[o.length-1];r&&ft(r)===i&&r.to===n.from?o[o.length-1]={...r,to:n.to}:o.push({at:i,from:n.from,to:n.to})}}var jc=9,Cs=10,Gc=32,Zc=33,Xc=38,Is=40,Di=41,Yc=42,Jc=58,Ls=60,Oi=91,Bs=92,ed=93,As=95,td=96,mt=126,Ks="[!\"#$%&'()*+,./:;<=>?@[\\\\\\]^_`{|}~-]",Ns=new RegExp("^"+Ks),Hi="&(?:#[xX][0-9a-fA-F]{1,6}|#[0-9]{1,7}|[A-Za-z][A-Za-z0-9]{1,31});",nd=new RegExp(Hi,"y"),od=new RegExp("\\\\"+Ks+"|"+Hi,"g"),Vs="[A-Za-z][A-Za-z0-9-]*",id="[a-zA-Z_:][a-zA-Z0-9:._-]*",rd="[^\"'=<>`\\x00-\\x20]+",sd=`(?:${rd}|'[^']*'|"[^"]*")`,ld=`(?:[ \\t\\n]+${id}(?:[ \\t\\n]*=[ \\t\\n]*${sd})?)`,Pi=`<${Vs}${ld}*[ \\t\\n]*/?>`,$i=`</${Vs}[ \\t\\n]*>`,ad="<!-->|<!--->|<!--[\\s\\S]*?-->",cd="<\\?[\\s\\S]*?\\?>",dd="<![A-Za-z][^>]*>",ud="<!\\[CDATA\\[[\\s\\S]*?\\]\\]>",hd=new RegExp(`(?:${Pi}|${$i}|${ad}|${cd}|${dd}|${ud})`,"y"),Fi="[A-Za-z][A-Za-z0-9.+-]{1,31}:[^<>\\x00-\\x20]*",qi="[a-zA-Z0-9.!#$%&'*+/=?^_`{|}~-]+@[a-zA-Z0-9](?:[a-zA-Z0-9-]{0,61}[a-zA-Z0-9])?(?:\\.[a-zA-Z0-9](?:[a-zA-Z0-9-]{0,61}[a-zA-Z0-9])?)*",fd=new RegExp(`<(${Fi})>`,"y"),pd=new RegExp(`<(${qi})>`,"y"),md=/"(?:\\[\s\S]|[^\\"\x00])*"|'(?:\\[\s\S]|[^\\'\x00])*'|\((?:\\[\s\S]|[^\\()\x00])*\)/y,gd=/<(?:[^<>\n\\\x00]|\\.)*>/y,bd=/\[(?:[^\\[\]]|\\[\s\S]){0,1000}\]/y,yd=/[ \t]*(?:\n[ \t]*)?/y,Rs=/[ \t]*(?:\n|$)/y,Ds=/[^\n`[\]\\!<&*_~]+/y,Os=/`+/y,kd=/[\t\n\f\r\p{Zs}]/u,vd=/[\p{P}\p{S}]/u;function mo(o){return kd.test(o)}function go(o){return vd.test(o)}function _i(o){if(o[1]==="#"){let e=o[2]==="x"||o[2]==="X",t=parseInt(o.slice(e?3:2,-1),e?16:10);return t===0||t>1114111||t>=55296&&t<=57343?"\uFFFD":String.fromCodePoint(t)}return Vc(o.slice(1,-1))??null}var xd=new RegExp(Hi,"g");function Us(o){return o.includes("&")?o.replace(xd,e=>_i(e)??e):o}function pn(o){return!o.includes("\\")&&!o.includes("&")?o:o.replace(od,e=>e[0]==="\\"?e[1]:_i(e)??e)}function Hs(o){return o.slice(1,-1).replace(/^[ \t\r\n]+|[ \t\r\n]+$/g,"").replace(/[ \t\r\n]+/g," ").toLowerCase().toUpperCase()}var _=class{constructor(e,t=0,n=t,i=""){this.type=e;this.value=i,this.from=t,this.to=n}value="";name="";depth=0;destination="";title="";align="";width=0;height=0;apart=!1;from;to;escaped=!1;syntax=null;content=null;parent=null;first=null;last=null;prev=null;next=null;append(e){e.unlink(),e.parent=this,e.depth>=this.depth&&(this.depth=e.depth+1),this.last?(this.last.next=e,e.prev=this.last,this.last=e):this.first=this.last=e}insertAfter(e){e.unlink(),e.next=this.next,e.next&&(e.next.prev=e),e.prev=this,this.next=e,e.parent=this.parent,this.parent&&!e.next&&(this.parent.last=e)}unlink(){this.prev?this.prev.next=this.next:this.parent&&(this.parent.first=this.next),this.next?this.next.prev=this.prev:this.parent&&(this.parent.last=this.prev),this.parent=this.prev=this.next=null}},fo=100;function Ps(o,e){let t=0;for(let n=o.next;n&&n!==e&&t<fo;n=n.next)n.depth>=t&&(t=n.depth+1);return t}function $s(o,e,t){let n=new _("text",e,t,o);return n.escaped=!0,n.apart=o==="@",n}function gt(o,e){let t=e;return t.pos={from:o.from,to:o.to},o.syntax&&(t.syntax=o.syntax),t}function wd(o){let e={from:o.from,to:o.to};return o.escaped?{type:"text",value:o.value,pos:e,pieces:[]}:{type:"text",value:o.value,pos:e}}function Sd(o,e){let t=o.value+e.value,n={from:o.pos.from,to:e.to};if(!o.pieces&&!e.escaped&&o.pos.to===e.from&&e.value.length===e.to-e.from)return{type:"text",value:t,pos:n};let i=o.pieces??[{at:0,from:o.pos.from,to:o.pos.to}];return Qc(i,e.escaped?[]:[{at:0,from:e.from,to:e.to}],o.value.length),_s(i,t,n)?{type:"text",value:t,pos:n}:{type:"text",value:t,pos:n,pieces:i}}function po(o){let e=[],t=!1;for(let n=o.first;n;n=n.next)switch(n.type){case"text":{if(n.value==="")break;let i=e[e.length-1];i?.type==="text"&&!t&&!n.apart?e[e.length-1]=Sd(i,n):e.push(wd(n)),t=n.apart;break}case"softBreak":case"hardBreak":e.push(gt(n,{type:n.type}));break;case"code":e.push(gt(n,n.content?{type:n.type,value:n.value,content:n.content}:{type:n.type,value:n.value}));break;case"html":e.push(gt(n,{type:n.type,value:n.value}));break;case"token":e.push(gt(n,{type:"token",name:n.name,value:n.value}));break;case"emphasis":case"strong":case"strike":e.push(gt(n,{type:n.type,children:po(n)}));break;case"link":e.push(gt(n,{type:n.type,destination:n.destination,title:n.title,children:po(n)}));break;case"image":{e.push(gt(n,{type:n.type,destination:n.destination,title:n.title,children:po(n),...n.align?{align:n.align}:{},...n.width?{width:n.width}:{},...n.width&&n.height?{height:n.height}:{}}));break}case"root":break}return e}var bo=class{constructor(e,t,n,i=!1){this.subject=e;this.refs=t;this.autolinks=i;for(let r of n)for(let s of r.triggers){let l=s.charCodeAt(0);this.triggers.set(l,[...this.triggers.get(l)??[],r])}if(this.triggers.size>0){let r=[...this.triggers.keys()].map(s=>"\\u"+s.toString(16).padStart(4,"0")).join("");this.reText=new RegExp(Ds.source.replace(/\]\+$/,r+"]+"),"y")}}pos=0;delimiters=null;brackets=null;backticksAfter=new Map;titleFailedFrom=new Map;lastEnds=new Map;destRange=null;titleRange=null;triggers=new Map;reText=Ds;parse(){let e=new _("root");for(;this.pos<this.subject.length;)this.parseOne(e);return this.processEmphasis(null),po(e)}peek(e=0){let t=this.subject.charCodeAt(this.pos+e);return Number.isNaN(t)?-1:t}match(e){e.lastIndex=this.pos;let t=e.exec(this.subject);return t&&(this.pos=e.lastIndex),t}text(e,t){return new _("text",e,t,this.subject.slice(e,t))}parseOne(e){let t=this.peek();if(this.triggers.size>0&&this.parseToken(t,e))return;let n=!1;switch(t){case Cs:n=this.parseNewline(e);break;case Bs:n=this.parseBackslash(e);break;case td:n=this.parseBackticks(e);break;case Yc:case As:case mt:n=this.handleDelim(t,e);break;case Oi:n=this.parseOpenBracket(e);break;case Zc:n=this.parseBang(e);break;case ed:n=this.parseCloseBracket(e);break;case Ls:n=this.parseAutolink(e)||this.parseHtmlTag(e);break;case Xc:n=this.parseEntity(e);break;default:n=this.parseString(e)}n||(this.pos+=1,e.append(new _("text",this.pos-1,this.pos,String.fromCharCode(t))))}parseToken(e,t){let n=this.triggers.get(e);if(!n)return!1;for(let i of n){let r=i.match(this.subject,this.pos);if(r>this.pos){let s=new _("token",this.pos,r,this.subject.slice(this.pos,r));return s.name=i.name,t.append(s),this.pos=r,!0}}return!1}parseString(e){let t=this.pos,n=this.match(this.reText);if(!n)return!1;if(this.autolinks&&!this.brackets&&/www\.|:\/\//i.test(n[0])){let i=/www\.|(?:https?|ftp):\/\//gi;for(let r of n[0].matchAll(i)){let s=t+r.index;if(!It(this.subject[s-1],r[0].toLowerCase()==="www."))continue;let l=lt(this.subject,s);if(!l)continue;s>t&&e.append(this.text(t,s));let a=new _("link",s,l.end);return a.destination=l.href,a.syntax=[{kind:"dest",from:s,to:l.end}],a.append(this.text(s,l.end)),e.append(a),this.pos=l.end,!0}}return e.append(new _("text",t,this.pos,n[0])),!0}parseNewline(e){let t=this.pos;this.pos+=1;let n=e.last,i=!1;if(n&&n.type==="text"&&n.value.endsWith(" ")){i=n.value.endsWith(" ");let s=n.value.replace(/ +$/,""),l=n.value.length-s.length;n.value=s,n.escaped||(n.to-=l,t=n.to)}let r=new _(i?"hardBreak":"softBreak",t);return e.append(r),this.skipLineStart(),r.to=this.pos,!0}skipLineStart(){let e=this.peek();for(;e===Gc||e===jc;)this.pos+=1,e=this.peek()}parseBackslash(e){let t=this.pos;this.pos+=1;let n=this.peek();if(n===Cs){this.pos+=1;let i=new _("hardBreak",t);e.append(i),this.skipLineStart(),i.to=this.pos}else n!==-1&&Ns.test(this.subject[this.pos])?(e.append($s(this.subject[this.pos],t,t+2)),this.pos+=1):e.append(new _("text",t,t+1,"\\"));return!0}parseBackticks(e){let t=this.pos,i=this.match(Os)[0].length,r=this.pos,s=this.backticksAfter.get(i);if(s===void 0||r<s){let l;for(;(l=this.match(Os))||this.findNextBacktick();)if(l&&l[0].length===i){let a=this.pos-i,d=this.subject.slice(r,a).replace(/\n/g," "),u=0;d.length>2&&d[0]===" "&&d[d.length-1]===" "&&/[^ ]/.test(d)&&(d=d.slice(1,-1),u=1);let c=new _("code",t,this.pos,d);return c.syntax=[{kind:"open",from:t,to:r},{kind:"close",from:a,to:this.pos}],c.content={from:r+u,to:a-u},e.append(c),!0}this.backticksAfter.set(i,r)}return this.pos=r,e.append(this.text(t,r)),!0}findNextBacktick(){let e=this.subject.indexOf("`",this.pos);return e<0?(this.pos=this.subject.length,!1):(this.pos=e,!0)}parseAutolink(e){let t=this.pos,n=this.match(pd);return n?(this.autolink(e,t,"mailto:"+n[1]),!0):(n=this.match(fd),n?(this.autolink(e,t,n[1]),!0):!1)}autolink(e,t,n){let i=new _("link",t,this.pos);i.destination=n,i.syntax=[{kind:"open",from:t,to:t+1},{kind:"dest",from:t+1,to:this.pos-1},{kind:"close",from:this.pos-1,to:this.pos}],i.append(this.text(t+1,this.pos-1)),e.append(i)}parseHtmlTag(e){let t=this.subject,n=this.pos;if(t.startsWith("<!--",n)){if(this.lastEnd("-->")<n+2)return!1}else if(t.startsWith("<?",n)){if(this.lastEnd("?>")<n+1)return!1}else if(t.startsWith("<![CDATA[",n)){if(this.lastEnd("]]>")<n+9)return!1}else if(t.startsWith("<!",n)&&this.lastEnd(">")<n)return!1;let i=this.match(hd);return i?(e.append(new _("html",n,this.pos,i[0])),!0):!1}lastEnd(e){let t=this.lastEnds.get(e);return t===void 0&&(t=this.subject.lastIndexOf(e),this.lastEnds.set(e,t)),t}parseEntity(e){let t=this.pos,n=this.match(nd);if(n){let i=_i(n[0]);if(i!==null)return e.append($s(i,t,this.pos)),!0;this.pos=t}return!1}handleDelim(e,t){let n=this.pos;for(;this.peek()===e;)this.pos+=1;let i=this.pos-n,r=n===0?`
24
- `:Td(this.subject,n),s=this.pos>=this.subject.length?`
25
- `:Ed(this.subject,this.pos),l=mo(s),a=go(s),d=mo(r),u=go(r),c=!l&&(!a||d||u),h=!d&&(!u||l||a),f=c,p=h;if(e!==mt&&(s==="~"&&(f=!0),r==="~"&&(p=!0)),e===As){let y=f;f=y&&(d||u||!p),p=p&&(l||a||!y)}e===mt&&i>2&&(f=p=!1);let m=this.text(n,this.pos);if(t.append(m),f||p){let y={cc:e,count:i,origCount:i,node:m,canOpen:f,canClose:p,prev:this.delimiters,next:null};y.prev&&(y.prev.next=y),this.delimiters=y}return!0}removeDelimiter(e){e.prev&&(e.prev.next=e.next),e.next?e.next.prev=e.prev:this.delimiters=e.prev}processEmphasis(e){let t=new Map,n=this.delimiters;for(;n&&n!==e&&n.prev!==e;)n=n.prev;for(n===e&&(n=null);n;){if(!n.canClose){n=n.next;continue}let i=n.cc===mt?100+n.count:n.cc*10+(n.canOpen?3:0)+n.origCount%3,r=t.has(i)?t.get(i):e,s=n.prev,l=!1;for(;s&&s!==e&&s!==r;){if(s.cc===n.cc&&s.canOpen){if(n.cc===mt){if(s.count===n.count){l=!0;break}}else if(!((n.canOpen||s.canClose)&&n.origCount%3!==0&&(s.origCount+n.origCount)%3===0)){l=!0;break}}s=s.prev}let a=n;if(l&&s){let d=n.cc===mt?n.count:n.count>=2&&s.count>=2?2:1,u=n.cc===mt?"strike":d===1?"emphasis":"strong",c=s.node,h=n.node;s.count-=d,n.count-=d;let f=Ps(c,h)>=fo;if(f)c.depth=h.depth=fo;else{c.value=c.value.slice(0,c.value.length-d),h.value=h.value.slice(0,h.value.length-d),c.to-=d,h.from+=d;let p=new _(u,c.to,h.from);p.syntax=[{kind:"open",from:p.from,to:p.from+d},{kind:"close",from:p.to-d,to:p.to}];let m=c.next;for(;m&&m!==h;){let y=m.next;p.append(m),m=y}c.insertAfter(p)}if(s.next!==n&&(s.next=n,n.prev=s),s.count===0&&(f||c.unlink(),this.removeDelimiter(s)),n.count===0){f||h.unlink();let p=n.next;this.removeDelimiter(n),n=p}}else n=n.next,t.set(i,a.prev),a.canOpen||this.removeDelimiter(a)}for(;this.delimiters&&this.delimiters!==e;)this.removeDelimiter(this.delimiters)}pushBracket(e,t,n){this.brackets&&(this.brackets.bracketAfter=!0),this.brackets={node:e,prev:this.brackets,prevDelimiter:this.delimiters,index:t,image:n,active:!0,bracketAfter:!1}}parseOpenBracket(e){let t=this.pos;this.pos+=1;let n=new _("text",t,t+1,"[");return e.append(n),this.pushBracket(n,t,!1),!0}parseBang(e){let t=this.pos;if(this.pos+=1,this.peek()===Oi){this.pos+=1;let n=new _("text",t,t+2,"![");e.append(n),this.pushBracket(n,t+1,!0)}else e.append(new _("text",t,t+1,"!"));return!0}parseCloseBracket(e){this.pos+=1;let t=this.pos,n=this.brackets;if(!n)return e.append(new _("text",t-1,t,"]")),!0;if(!n.active)return e.append(new _("text",t-1,t,"]")),this.brackets=n.prev,!0;let i=null,r=null,s=null,l=null,a=!1;if(this.peek()===Is){if(this.pos+=1,this.spnl(),i=this.parseLinkDestination(),i!==null){let h=this.pos;this.spnl(),this.pos!==h&&(r=this.parseLinkTitle()),this.spnl(),this.peek()===Di&&(this.pos+=1,a=!0,s=this.destRange,r!==null&&(l=this.titleRange))}a||(this.pos=t)}if(!a){let h=this.pos,f=this.parseLinkLabel(),p=null;if(f>2?p=this.subject.slice(h,h+f):n.bracketAfter||(p=this.subject.slice(n.index,t)),f===0&&(this.pos=t),p!==null&&p.length<=1001){let m=this.refs.get(Hs(p));m&&(i=m.destination,r=m.title,a=!0)}}if(!a||Ps(n.node,null)>=fo)return this.brackets=n.prev,this.pos=t,e.append(new _("text",t-1,t,"]")),!0;let d=new _(n.image?"image":"link",n.node.from,this.pos);d.destination=i??"",d.title=r??"";let u=[{kind:"open",from:n.node.from,to:n.node.to},{kind:"close",from:t-1,to:t}];if(this.pos>t&&u.push({kind:"tail",from:t,to:this.pos}),s&&u.push({kind:"dest",...s}),l&&u.push({kind:"title",...l}),d.syntax=u,n.image){let h=io(this.subject.slice(n.index+1,t-1));h&&(d.align=h.align??"",d.width=h.width??0,d.height=h.height??0)}let c=n.node.next;for(;c;){let h=c.next;d.append(c),c=h}if(e.append(d),this.processEmphasis(n.prevDelimiter),this.brackets=n.prev,n.node.unlink(),!n.image)for(let h=this.brackets;h;h=h.prev)h.image||(h.active=!1);return!0}spnl(){this.match(yd)}parseLinkDestination(){let e=this.pos,t=this.match(gd);if(t)return this.destRange={from:e+1,to:this.pos-1},pn(t[0].slice(1,-1));if(this.peek()===Ls)return null;let n=this.pos,i=0;for(;;){let r=this.peek();if(r===-1)break;if(r===Bs&&Ns.test(this.subject[this.pos+1]??""))this.pos+=2;else if(r===Is){if(this.pos+=1,i+=1,i>32)return null}else if(r===Di){if(i<1)break;this.pos+=1,i-=1}else{if(r<=32||r===127)break;this.pos+=1}}return this.pos===n&&this.peek()!==Di||i!==0?null:(this.destRange={from:n,to:this.pos},pn(this.subject.slice(n,this.pos)))}parseLinkTitle(){let e=this.pos,t=this.subject[e],n=t===void 0?void 0:this.titleFailedFrom.get(t);if(n!==void 0&&e>=n)return null;let i=this.match(md);return i?(this.titleRange={from:e,to:this.pos},pn(i[0].slice(1,-1))):((t==='"'||t==="'")&&this.titleFailedFrom.set(t,e),null)}parseLinkLabel(){let e=this.pos,t=this.match(bd);return!t||t[0].length>1001?(this.pos=e,0):t[0].length}parseReference(){let e=this.parseLinkLabel();if(e===0)return 0;let t=this.subject.slice(0,e);if(this.peek()!==Jc)return 0;this.pos+=1,this.spnl();let n=this.parseLinkDestination();if(n===null)return 0;let i=this.pos;this.spnl();let r=null;if(this.pos!==i&&(r=this.parseLinkTitle()),r===null&&(this.pos=i),!this.match(Rs)&&(r===null||(r=null,this.pos=i,!this.match(Rs))))return 0;let s=Hs(t);return s===""?0:(this.refs.has(s)||this.refs.set(s,{destination:n,title:r??""}),this.pos)}};function zs(o,e){for(;o.charCodeAt(0)===Oi;){let t=new bo(o,e,[]).parseReference();if(t===0)break;o=o.slice(t)}return o}function Td(o,e){let t=o.charCodeAt(e-1);if(t>=56320&&t<=57343&&e>=2){let n=o.charCodeAt(e-2);if(n>=55296&&n<=56319)return o.slice(e-2,e)}return o[e-1]}function Ed(o,e){return String.fromCodePoint(o.codePointAt(e))}function he(o,e=pe){return new Vi(Ze(e)).parse(o)}var yo=4,Md=100,Cd=65536,Gs=[/^$/,/^<(?:script|pre|textarea|style)(?:[ \t>]|$)/i,/^<!--/,/^<[?]/,/^<![A-Za-z]/,/^<!\[CDATA\[/,/^<[/]?(?: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|h[123456]|head|header|hr|html|iframe|legend|li|link|main|menu|menuitem|nav|noframes|ol|optgroup|option|p|param|search|section|summary|table|tbody|td|tfoot|th|thead|title|tr|track|ul)(?:[ \t]|[/]?>|$)/i,new RegExp(`^(?:${Pi}|${$i})[ \\t]*$`,"i")];function Zs(o){for(let e=1;e<=6;e++)if(Gs[e].test(o))return!0;return!1}var Id=[/^$/,/<\/(?:script|pre|textarea|style)>/i,/-->/,/\?>/,/>/,/\]\]>/],Ld=/^(?:\*[ \t]*){3,}$|^(?:_[ \t]*){3,}$|^(?:-[ \t]*){3,}$/,Bd=/^[#`~*+_=<>0-9|:-]/,Ki=/[^ \t\f\v\r\n]/,Ad=/^[*+-]/,Nd=/^(\d{1,9})([.)])/,Rd=/^#{1,6}(?:[ \t]+|$)/,Dd=/^(?:`{3,}|~{3,})(?=[ \t]*$)/,Ws=/^(?:=+|-+)[ \t]*$/,Od=/^:?-+:?$/,Hd=/^\[([ \t\nxX])\](?:[ \t\n]+|$)/,yn=class{constructor(e,t){this.type=e;this.startLine=t}parent=null;children=[];depth=0;open=!0;endLine=0;content="";lines=[];contentStart=0;level=0;setext=!1;fenced=!1;fenceChar="";fenceLength=0;fenceOffset=0;info="";htmlType=0;syntax="";matcher=null;list=null;tight=!0;align=[];rows=[];get lastChild(){return this.children[this.children.length-1]}append(e){e.parent=this,e.depth=this.depth+1,this.children.push(e)}remove(){if(!this.parent)return;let e=this.parent.children,t=e.lastIndexOf(this);t>=0&&e.splice(t,1),this.parent=null}};function Qs(o){return o==="paragraph"||o==="codeBlock"||o==="htmlBlock"||o==="rawBlock"}function Pd(o,e){switch(o){case"document":case"blockQuote":case"item":return e!=="item";case"list":return e==="item";default:return!1}}function Oe(o){return o===" "||o===" "}var Vi=class{constructor(e){this.options=e}doc=new yn("document",1);tip=this.doc;oldTip=this.doc;lastMatchedContainer=this.doc;refs=new Map;definitions=[];filledCells=0;maxFilledCells=0;line="";lineNumber=0;offset=0;column=0;nextNonspace=0;nextNonspaceColumn=0;indent=0;indented=!1;blank=!1;partiallyConsumedTab=!1;allClosed=!0;parse(e){let t=(e.charCodeAt(0)===65279?e.slice(1):e).split(/\r\n|\n|\r/);this.maxFilledCells=Math.max(Cd,e.length);let n=t.length;(e.endsWith(`
19
+ `).replace(/\n$/,"")}function Rc(o){if(!o)return null;let e=[o,...Array.from(o.children).slice(0,1)];for(let t of e){let n=(us(t).get("text-align")??t.getAttribute("align")??"").toLowerCase();if(n==="left"||n==="start")return"left";if(n==="center")return"center";if(n==="right"||n==="end")return"right"}return null}var oo=class{constructor(e){this.source=e}undoStack=[];redoStack=[];lastKind=null;lastTime=0;record(e,t,n=Date.now()){t==="typing"&&this.lastKind==="typing"&&n-this.lastTime<1e3||(this.undoStack.push({doc:e.doc,selection:e.selection,source:this.source()}),this.undoStack.length>500&&this.undoStack.shift()),this.redoStack=[],this.lastKind=t,this.lastTime=n}clear(){this.undoStack=[],this.redoStack=[],this.lastKind=null}breakGroup(){this.lastKind=null}undo(e){return this.step(e,this.undoStack,this.redoStack)}redo(e){return this.step(e,this.redoStack,this.undoStack)}step(e,t,n){let i=t.pop();return i?(n.push({doc:e.doc,selection:e.selection,source:this.source()}),this.lastKind=null,{state:{doc:i.doc,selection:i.selection,storedMarks:null},source:i.source}):null}};var Mi={text:"Text",heading1:"Heading 1",heading2:"Heading 2",heading3:"Heading 3",heading4:"Heading 4",bulletList:"Bulleted list",numberedList:"Numbered list",todoList:"To-do list",task:"Task",footnotes:"Footnotes",backToReference:"Back to reference",quote:"Quote",callout:"Callout",calloutNote:"Note",calloutTip:"Tip",calloutImportant:"Important",calloutWarning:"Warning",calloutCaution:"Caution",code:"Code block",details:"Collapsible section",detailsHint:"Title",expandSection:"Expand",collapseSection:"Collapse",table:"Table",divider:"Divider",noResults:"No results",suggestions:"Suggestions",commands:"Commands",loading:"Loading\u2026",duplicate:"Duplicate",delete:"Delete",bold:"Bold",italic:"Italic",strike:"Strikethrough",inlineCode:"Code",link:"Link",textStyle:"Text style",list:"List",linkPlaceholder:"Paste or type a link\u2026",removeLink:"Remove link",openLink:"Open link",copyLink:"Copy link",editLink:"Edit link",slashHint:"Type '/' for commands",blockHandle:"Open block menu",listHint:"List",quoteHint:"Quote",language:"Language",plainText:"text",copyCode:"Copy code",copied:"Copied",addRowAbove:"Add row above",addRowBelow:"Add row below",addColumnLeft:"Add column left",addColumnRight:"Add column right",deleteRow:"Delete row",deleteColumn:"Delete column",align:"Align",alignLeft:"Left",alignCenter:"Center",alignRight:"Right",tableSection:"Table",imageSection:"Image",imageAlignLeft:"Align left",imageAlignCenter:"Align center",imageAlignRight:"Align right",resetImageSize:"Reset size",altText:"Alt text",altTextPlaceholder:"Describe the image\u2026",imageUnavailable:"Image unavailable",resizeImage:"Resize image"};var Ci=["M10 11v6","M14 11v6","M19 6v14a2 2 0 0 1-2 2H7a2 2 0 0 1-2-2V6","M3 6h18","M8 6V4a2 2 0 0 1 2-2h4a2 2 0 0 1 2 2v2"],Dc={text:["M12 4v16","M4 7V5a1 1 0 0 1 1-1h14a1 1 0 0 1 1 1v2","M9 20h6"],heading1:["M4 12h8","M4 18V6","M12 18V6","m17 12 3-2v8"],heading2:["M4 12h8","M4 18V6","M12 18V6","M21 18h-4c0-4 4-3 4-6 0-1.5-2-2.5-4-1"],heading3:["M4 12h8","M4 18V6","M12 18V6","M17.5 10.5c1.7-1 3.5 0 3.5 1.5a2 2 0 0 1-2 2","M17 17.5c2 1.5 4 .3 4-1.5a2 2 0 0 0-2-2"],heading4:["M12 18V6","M17 10v3a1 1 0 0 0 1 1h3","M21 10v8","M4 12h8","M4 18V6"],bulletList:["M3 5h.01","M3 12h.01","M3 19h.01","M8 5h13","M8 12h13","M8 19h13"],numberedList:["M11 5h10","M11 12h10","M11 19h10","M4 4h1v5","M4 9h2","M6.5 20H3.4c0-1 2.6-1.925 2.6-3.5a1.5 1.5 0 0 0-2.6-1.02"],todoList:["M13 5h8","M13 12h8","M13 19h8","m3 17 2 2 4-4",["rect",{x:"3",y:"4",width:"6",height:"6",rx:"1"}]],quote:["M17 5H3","M21 12H8","M21 19H8","M3 12v7"],callout:[["circle",{cx:"12",cy:"12",r:"10"}],"M12 16v-4","M12 8h.01"],calloutNote:[["circle",{cx:"12",cy:"12",r:"10"}],"M12 16v-4","M12 8h.01"],calloutTip:["M15 14c.2-1 .7-1.7 1.5-2.5 1-.9 1.5-2.2 1.5-3.5A6 6 0 0 0 6 8c0 1 .2 2.2 1.5 3.5.7.7 1.3 1.5 1.5 2.5","M9 18h6","M10 22h4"],calloutImportant:["M22 17a2 2 0 0 1-2 2H6.828a2 2 0 0 0-1.414.586l-2.202 2.202A.71.71 0 0 1 2 21.286V5a2 2 0 0 1 2-2h16a2 2 0 0 1 2 2z","M12 15h.01","M12 7v4"],calloutWarning:["m21.73 18-8-14a2 2 0 0 0-3.48 0l-8 14A2 2 0 0 0 4 21h16a2 2 0 0 0 1.73-3","M12 9v4","M12 17h.01"],calloutCaution:["M12 16h.01","M12 8v4","M15.312 2a2 2 0 0 1 1.414.586l4.688 4.688A2 2 0 0 1 22 8.688v6.624a2 2 0 0 1-.586 1.414l-4.688 4.688a2 2 0 0 1-1.414.586H8.688a2 2 0 0 1-1.414-.586l-4.688-4.688A2 2 0 0 1 2 15.312V8.688a2 2 0 0 1 .586-1.414l4.688-4.688A2 2 0 0 1 8.688 2z"],details:["M10 5h11","M10 12h11","M10 19h11","m3 10 3-3-3-3","m3 20 3-3-3-3"],code:["m10 9-3 3 3 3","m14 15 3-3-3-3",["rect",{x:"3",y:"3",width:"18",height:"18",rx:"2"}]],table:["M12 3v18",["rect",{width:"18",height:"18",x:"3",y:"3",rx:"2"}],"M3 9h18","M3 15h18"],divider:["M5 12h14"],duplicate:[["rect",{width:"14",height:"14",x:"8",y:"8",rx:"2",ry:"2"}],"M4 16c-1.1 0-2-.9-2-2V4c0-1.1.9-2 2-2h10c1.1 0 2 .9 2 2"],copyCode:[["rect",{width:"14",height:"14",x:"8",y:"8",rx:"2",ry:"2"}],"M4 16c-1.1 0-2-.9-2-2V4c0-1.1.9-2 2-2h10c1.1 0 2 .9 2 2"],copied:["M20 6 9 17l-5-5"],delete:Ci,addRowAbove:["m5 12 7-7 7 7","M12 19V5"],backToReference:["m5 12 7-7 7 7","M12 19V5"],addRowBelow:["M12 5v14","m19 12-7 7-7-7"],addColumnLeft:["m12 19-7-7 7-7","M19 12H5"],addColumnRight:["M5 12h14","m12 5 7 7-7 7"],align:["M21 5H3","M15 12H3","M17 19H3"],alignLeft:["M21 5H3","M15 12H3","M17 19H3"],alignCenter:["M21 5H3","M17 12H7","M19 19H5"],alignRight:["M21 5H3","M21 12H9","M21 19H7"],imageAlignLeft:[["rect",{width:"9",height:"6",x:"6",y:"14",rx:"2"}],["rect",{width:"16",height:"6",x:"6",y:"4",rx:"2"}],"M2 2v20"],imageAlignCenter:["M12 2v20","M8 10H4a2 2 0 0 1-2-2V6c0-1.1.9-2 2-2h4","M16 10h4a2 2 0 0 0 2-2V6a2 2 0 0 0-2-2h-4","M8 20H7a2 2 0 0 1-2-2v-2c0-1.1.9-2 2-2h1","M16 14h1a2 2 0 0 1 2 2v2a2 2 0 0 1-2 2h-1"],imageAlignRight:[["rect",{width:"16",height:"6",x:"2",y:"4",rx:"2"}],["rect",{width:"9",height:"6",x:"9",y:"14",rx:"2"}],"M22 22V2"],resetImageSize:["M3 12a9 9 0 1 0 9-9 9.75 9.75 0 0 0-6.74 2.74L3 8","M3 3v5h5"],altText:["M12 20h-1a2 2 0 0 1-2-2 2 2 0 0 1-2 2H6","M13 8h7a2 2 0 0 1 2 2v4a2 2 0 0 1-2 2h-7","M5 16H4a2 2 0 0 1-2-2v-4a2 2 0 0 1 2-2h1","M6 4h1a2 2 0 0 1 2 2 2 2 0 0 1 2-2h1","M9 6v12"],deleteRow:Ci,deleteColumn:Ci,bold:["M6 12h9a4 4 0 0 1 0 8H7a1 1 0 0 1-1-1V5a1 1 0 0 1 1-1h7a4 4 0 0 1 0 8"],italic:[["line",{x1:"19",x2:"10",y1:"4",y2:"4"}],["line",{x1:"14",x2:"5",y1:"20",y2:"20"}],["line",{x1:"15",x2:"9",y1:"4",y2:"20"}]],strike:["M16 4H9a3 3 0 0 0-2.83 4","M14 12a4 4 0 0 1 0 8H6",["line",{x1:"4",x2:"20",y1:"12",y2:"12"}]],inlineCode:["m16 18 6-6-6-6","m8 6-6 6 6 6"],openLink:["M15 3h6v6","M10 14 21 3","M18 13v6a2 2 0 0 1-2 2H5a2 2 0 0 1-2-2V8a2 2 0 0 1 2-2h6"],copyLink:[["rect",{width:"14",height:"14",x:"8",y:"8",rx:"2",ry:"2"}],"M4 16c-1.1 0-2-.9-2-2V4c0-1.1.9-2 2-2h10c1.1 0 2 .9 2 2"],editLink:["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","m15 5 4 4"],removeLink:["m18.84 12.25 1.72-1.71h-.02a5.004 5.004 0 0 0-.12-7.07 5.006 5.006 0 0 0-6.95 0l-1.72 1.71","m5.17 11.75-1.71 1.71a5.004 5.004 0 0 0 .12 7.07 5.006 5.006 0 0 0 6.95 0l1.71-1.71","M8 2v3","M2 8h3","M16 19v3","M19 16h3"],link:["M10 13a5 5 0 0 0 7.54.54l3-3a5 5 0 0 0-7.07-7.07l-1.72 1.71","M14 11a5 5 0 0 0-7.54-.54l-3 3a5 5 0 0 0 7.07 7.07l1.71-1.71"],imageUnavailable:[["line",{x1:"2",x2:"22",y1:"2",y2:"22"}],"M10.41 10.41a2 2 0 1 1-2.83-2.83",["line",{x1:"13.5",x2:"6",y1:"13.5",y2:"21"}],["line",{x1:"18",x2:"21",y1:"12",y2:"15"}],"M3.59 3.59A1.99 1.99 0 0 0 3 5v14a2 2 0 0 0 2 2h14c.55 0 1.052-.22 1.41-.59","M21 15V5a2 2 0 0 0-2-2H9"],chevronDown:["m6 9 6 6 6-6"],selected:["M20 6 9 17l-5-5"],chevronRight:["m9 18 6-6-6-6"],blockHandle:[["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"}]]},hs="http://www.w3.org/2000/svg",Oc={viewBox:"0 0 24 24",fill:"none",stroke:"currentColor","stroke-width":"2","stroke-linecap":"round","stroke-linejoin":"round","aria-hidden":"true",focusable:"false"};function fs(o,e){let t=o.createElementNS(hs,"svg");t.setAttribute("class","mbe-icon");for(let[n,i]of Object.entries(Oc))t.setAttribute(n,i);for(let n of Dc[e]){let[i,r]=typeof n=="string"?["path",{d:n}]:n,s=o.createElementNS(hs,i);for(let[l,a]of Object.entries(r))s.setAttribute(l,a);t.appendChild(s)}return t}function X(o,e){return e===void 0||e===""?null:typeof e=="string"?o.createTextNode(e):o.importNode(e,!0)}function ft(o){return o.at+o.to-o.from}var Hc=/\|([1-9][0-9]{0,4})(?:x([1-9][0-9]{0,4}))?$/,Pc=/\|(left|center|right)(?:\|([1-9][0-9]{0,4})(?:x([1-9][0-9]{0,4}))?)?$/,ps=o=>/(^|[^\\])(\\\\)*\\$/.test(o);function io(o,e=!0){let t=Pc.exec(o);if(t&&!(e&&ps(o.slice(0,t.index))))return{align:t[1],...t[2]?{width:Number(t[2])}:{},...t[3]?{height:Number(t[3])}:{},index:t.index};let n=Hc.exec(o);return n&&!(e&&ps(o.slice(0,n.index)))?{width:Number(n[1]),...n[2]?{height:Number(n[2])}:{},index:n.index}:null}function hn(o){let e=o.width?`|${o.width}${o.height?`x${o.height}`:""}`:"";return(o.align?`|${o.align}`:"")+e}function ro(o,e){let t="";for(let n of o)switch(n.type){case"text":case"code":case"html":case"token":t+=n.value;break;case"softBreak":t+=e;break;case"hardBreak":t+=`
20
+ `;break;default:t+=ro(n.children,e)}return t}import{lookupEntity as Uc}from"#entities";var pe={breaks:!1,setext:!0,autolinks:!0,callouts:!0,details:!0,syntax:[],inline:[],block:[],escape:""},ms=new WeakMap;function Ze(o){if(!o)return pe;let e=ms.get(o);if(!e){let t=o.syntax??[];e={breaks:o.breaks??!1,setext:o.setext??!0,autolinks:o.autolinks??!0,callouts:o.callouts??!0,details:o.details??!0,syntax:t,inline:t.flatMap(n=>n.inline??[]),block:t.flatMap(n=>n.block??[]),escape:[...new Set(t.map(n=>n.escape??"").join(""))].join("")},ms.set(o,e)}return e}function pt(o){let e=[o.charCodeAt(0)===65279?1:0],t=[],n=/\r\n|\n|\r/g;for(let i=n.exec(o);i;i=n.exec(o))t.push(i.index),e.push(i.index+i[0].length);return t.push(o.length),{starts:e,ends:t}}function gs(o,e,t){return{from:o,to:e,srcFrom:t,srcTo:t+(e-o),linear:!0}}var xe=class{constructor(e,t){this.content=e;this.table=t}segments=[];at=0;record(e,t){let{pos:n}=e,i=this.at;if(this.at+=t,!n)return;if(e.type==="text"&&e.pieces){let s=0,l=n.from;for(let a of e.pieces)a.at>s&&this.atomic(i+s,i+a.at,l,a.from),this.linear(i+a.at,a.from,a.to),s=ft(a),l=a.to;s<t&&this.atomic(i+s,i+t,l,n.to);return}let r=e.type==="code"?e.content:e.type==="text"||e.type==="html"||e.type==="token"?n:null;r&&r.to-r.from===t?this.linear(i,r.from,r.to):this.atomic(i,i+t,n.from,n.to)}linear(e,t,n){let{lines:i,start:r}=this.content,{starts:s,ends:l}=this.table,a=t+r,d=n+r,u=e;for(;a<d;){let c=this.lineIndex(a),h=i[c];if(!h)return;let f=s[h.line-1]??0,p=l[h.line-1]??f,m=a-h.at;if(m<h.pad){let b=Math.min(h.pad-m,d-a);this.push({from:u,to:u+b,srcFrom:f+h.offset-1,srcTo:f+h.offset,linear:!1}),a+=b,u+=b;continue}let y=m-h.pad,g=p-f-h.offset;if(y<g){let b=i[c+1],w=Math.min(g-y,d-a,b?b.at-a:1/0);this.push({from:u,to:u+w,srcFrom:f+h.offset+y,srcTo:f+h.offset+y+w,linear:!0}),a+=w,u+=w;continue}let v=s[h.line]??p;this.push({from:u,to:u+1,srcFrom:y===g?p:v,srcTo:v,linear:!1}),a+=1,u+=1}}atomic(e,t,n,i){let r={from:e,to:t,srcFrom:this.source(n),srcTo:this.source(i),linear:!1},{lines:s,start:l}=this.content,a=this.lineIndex(i+l),d=a>this.lineIndex(n+l)?this.table.starts[s[a].line-1]:void 0;this.push(d===void 0?r:{...r,nextLine:d})}source(e){let{lines:t,start:n}=this.content,{starts:i,ends:r}=this.table,s=e+n,l=t[this.lineIndex(s)];if(!l)return 0;let a=i[l.line-1]??0,d=r[l.line-1]??a,u=s-l.at;if(u<l.pad)return a+l.offset-1;let c=u-l.pad,h=d-a-l.offset;return c<=h?a+l.offset+c:i[l.line]??d}lineIndex(e){let{lines:t}=this.content,n=0,i=t.length-1;for(;n<i;){let r=n+i+1>>1;t[r].at<=e?n=r:i=r-1}return n}push(e){if(e.to<=e.from&&e.srcTo<=e.srcFrom)return;let t=this.segments[this.segments.length-1];if(t&&t.linear&&e.linear&&t.to===e.from&&t.srcTo===e.srcFrom){this.segments[this.segments.length-1]={...t,to:e.to,srcTo:e.srcTo};return}this.segments.push(e)}};function bs(o,e,t,n){let i=new xe(o,e);return i.linear(0,t,n),i.segments.filter(r=>r.linear).map(r=>({from:r.srcFrom,to:r.srcTo}))}function ys(o,e,t){let n=0,i=o.length-1;for(;n<i;){let r=n+i+1>>1;o[r][e]<=t?n=r:i=r-1}return n}function ks(o,e){if(o.length===0)return 0;let t=ys(o,"from",e),n=o[t];return e<n.from?n.srcFrom:e>=n.to?e===n.to||t===o.length-1?n.srcTo:o[t+1].srcFrom:n.linear?n.srcFrom+(e-n.from):n.srcFrom}function vs(o,e){if(o.length===0)return 0;let t=ys(o,"srcFrom",e),n=o[t];return e<n.srcFrom?n.from:e>=n.srcTo?e===n.srcTo||t===o.length-1?n.to:o[t+1].from:n.linear?n.from+(e-n.srcFrom):n.nextLine!==void 0&&e>=n.nextLine?n.to:n.from}function xs(o){return!o||o.length===0?null:{from:o[0].srcFrom,to:o[o.length-1].srcTo}}function co(o){return{text:o,lines:pt(o)}}function Ss(o,e,t,n,i){return fn(o,e,n,void 0,i)??[ot("markdown",t)]}function fn(o,e,t,n,i){if(!so(o,0,i!==void 0))return null;let r=[];Es(o,r,e,n,void 0,i);let s=r[0];if(o.type==="blockQuote"&&s&&M(s)!==null&&M(t)===M(s)){let l=Qt(s);r[0]=l;let a=n?.maps.get(s);a&&n.maps.set(l,a)}return r}function so(o,e,t=!1){switch(o.type){case"blockQuote":return t||o.children.every(n=>n.type!=="blockQuote"&&(n.type!=="list"||so(n,0)));case"list":return e<=5&&o.items.every(n=>n.children.every((i,r)=>i.type==="paragraph"&&r===0||i.type==="list"&&so(i,e+1)));default:return!0}}function uo(o,e=pe,t){let n=[];return Li(o,[],{},n,e.breaks?`
21
+ `:" ",t),G(n)}function lo(o,e,t,n){let i=n&&t?new xe(t,n.lines):void 0;return{content:uo(o,e,i),map:i}}function ao(o,e,t){return e&&t&&t.maps.set(o,e.segments),o}function Ii(o,e,t,n){if(n&&t){let i=new xe(t,n.lines);i.linear(0,0,e.length),n.maps.set(o,i.segments)}return o}var $c={emphasis:"italic",strong:"bold",strike:"strike"};function Li(o,e,t,n,i,r){let s=(l,a)=>{r?.record(a,l.text.length),n.push(t.link===void 0?l:{...l,...t})};for(let l of o)switch(l.type){case"text":s({text:l.value,marks:e},l);break;case"softBreak":s({text:i,marks:e},l);break;case"hardBreak":s({text:`
22
+ `,marks:e},l);break;case"code":case"html":s({text:l.value,marks:ws(e,l.type)},l);break;case"token":s({text:l.value,marks:e,token:l.name},l);break;case"emphasis":case"strong":case"strike":Li(l.children,ws(e,$c[l.type]),t,n,i,r);break;case"link":Li(l.children,e,l.title?{link:l.destination,linkTitle:l.title}:{link:l.destination},n,i,r);break;case"image":s({text:"\uFFFC",marks:e,image:Fc(l)},l);break}}function Fc(o){let e=ro(o.children," "),t=hn(o);return t&&e.endsWith(t)&&(e=e.slice(0,-t.length)),{src:o.destination,alt:e,...o.title?{title:o.title}:{},...o.align?{align:o.align}:{},...o.width?{width:o.width}:{},...o.height?{height:o.height}:{}}}function ws(o,e){return o.includes(e)?o:rt([...o,e])}function Ts(o){let e=o.length===1?o[0]:null;return e!==null&&e.text==="\xA0"&&e.marks.length===0&&!e.link&&!e.image}function Es(o,e,t,n,i,r){let s=l=>i?U(l,i):l;switch(o.type){case"paragraph":{let{content:l,map:a}=lo(o.children,t,o.source,n);Ts(l)?e.push(D()):(l.length>0||o.children.length>0)&&e.push(ao(D(l),a,n));break}case"heading":{let{content:l,map:a}=lo(o.children,t,o.source,n);e.push(ao(s(nt(o.level,l)),a,n));break}case"thematicBreak":e.push(s(it()));break;case"blockQuote":_c(o,e,t,n,r);break;case"list":Ai(o,0,e,t,i,n);break;case"codeBlock":{let l=o.value.replace(/\n$/,"");e.push(Ii(s(Ee(Bi(o.info),l)),l,o.source,n));break}case"htmlBlock":e.push(Ii(s(Dn(o.value)),o.value,o.source,n));break;case"raw":e.push(Ii(s(ot(o.name,o.value)),o.value,o.source,n));break;case"table":e.push(s(zt(o.align,o.rows.map(l=>l.map(a=>uo(a,t))))));break}}function Bi(o){return o.trim().split(/\s+/)[0]??""}function qc(o,e){return e.task?"task":o.ordered?"ordered":"bullet"}function Ai(o,e,t,n,i,r){o.items.forEach((s,l)=>{let a=s.children[0],d=qc(o,s),{content:u,map:c}=a?.type==="paragraph"?lo(a.children,n,a.source,r):{content:[]};t.push(ao(Ue(d,u,{indent:Math.min(e,5),checked:s.checked,start:l===0&&d==="ordered"?o.start:void 0,quote:i}),c,r));for(let h of s.children)h.type==="list"&&Ai(h,e+1,t,n,i,r)})}function _c(o,e,t,n,i){let r=o.children,s=t.callouts===!1?null:Ni(r),l=s?.type,a=l??"quote",d=c=>{i&&e.push(U(ot("markdown",Kc(c,i)),a))},u=e.length;r.forEach((c,h)=>{let f=e.length;switch(c.type){case"paragraph":{let p=h===0&&s?s.rest:c.children,{content:m,map:y}=lo(p,t,c.source,n);Ts(m)?e.push(Ne([],void 0,l)):(m.length>0||p.length>0)&&e.push(ao(Ne(m,void 0,l),y,n));break}case"list":so(c,0)?Ai(c,0,e,t,a,n):c.lines&&d(c.lines);break;case"blockQuote":c.lines&&d(c.lines);break;default:Es(c,e,t,n,a,i)}i?.onQuoteChild?.(c,e.slice(f))}),l&&e.length===u&&e.push(Ne([],void 0,l))}function Kc(o,e){let t=[];for(let n=o.start;n<=o.end;n++){let i=e.lines.starts[n-1],r=e.lines.ends[n-1];if(i===void 0||r===void 0)break;t.push(ho(e.text.slice(i,Math.max(i,r))))}for(;t.length>1&&/^[ \t]*$/.test(t[t.length-1]);)t.pop();return t.join(`
23
+ `)}function ho(o){let e=/^ {0,3}>/.exec(o);if(!e)return o;let t=e[0].length,n=t;for(;n<o.length&&(o[n]===" "||o[n]===" ");)t+=o[n]===" "?4-t%4:1,n++;return" ".repeat(Math.max(0,t-(e[0].length+1)))+o.slice(n)}var Vc=new RegExp(`^\\[!(${Ve.join("|")})\\]$`,"i");function Ni(o){let e=o[0];if(e?.type!=="paragraph")return null;let[t,n]=e.children,i=t?.type==="text"?Vc.exec(t.value):null;return!i||n&&n.type!=="softBreak"&&n.type!=="hardBreak"?null:{type:i[1].toLowerCase(),rest:e.children.slice(2)}}function mn(o,e){let t=Ze(e);return uo(gn(o,new Map,t.inline,t.autolinks),e)}function gn(o,e,t=[],n=!1){if(Qc(o,t,n))return o?[{type:"text",value:o,pos:{from:0,to:o.length}}]:[];let i=new bo(o,e,t,n).parse();return n?Fs(i):i}var zc=/^[^\n`[\]\\!<&*_~]*$/,Wc=/www\.|:\/\/|@/i;function Qc(o,e,t){if(!zc.test(o)||t&&Wc.test(o))return!1;for(let n of e)for(let i of n.triggers)if(o.includes(i))return!1;return!0}function Fs(o){let e=!1,t=[];for(let n of o)if(n.type==="text"){let i=at(n.value);if(i.length===0){t.push(n);continue}e=!0;let r=0;for(let{from:s,to:l}of i){s>r&&t.push(Ri(n,r,s));let a=Ri(n,s,l),d={type:"link",destination:"mailto:"+a.value,title:"",children:[a]};t.push(a.pos?{...d,pos:a.pos,syntax:[{kind:"dest",...a.pos}]}:d),r=l}r<n.value.length&&t.push(Ri(n,r,n.value.length))}else if(n.type==="emphasis"||n.type==="strong"||n.type==="strike"){let i=Fs(n.children);i!==n.children&&(e=!0),t.push(i===n.children?n:{...n,children:i})}else t.push(n);return e?t:o}function Ri(o,e,t){let n=o.value.slice(e,t);if(!o.pos)return{type:"text",value:n};if(!o.pieces)return{type:"text",value:n,pos:{from:o.pos.from+e,to:o.pos.from+t}};let i=[];for(let s=qs(o.pieces,e);s<o.pieces.length&&o.pieces[s].at<t;s++){let l=o.pieces[s],a=Math.max(l.at,e),d=Math.min(ft(l),t);d>a&&i.push({at:a-e,from:l.from+(a-l.at),to:l.from+(d-l.at)})}let r={from:Ms(o,e),to:Ms(o,t)};return{type:"text",value:n,pos:r,..._s(i,n,r)?{}:{pieces:i}}}function qs(o,e){let t=0,n=o.length;for(;t<n;){let i=t+n>>1;ft(o[i])<e?t=i+1:n=i}return t}function Ms(o,e){let t=o.pieces[qs(o.pieces,e)];return t?e<t.at?t.from:t.from+(e-t.at):o.pos.to}function _s(o,e,t){let n=o[0];return o.length===1&&n.at===0&&n.from===t.from&&n.to===t.to&&e.length===t.to-t.from}function jc(o,e,t){for(let n of e){let i=n.at+t,r=o[o.length-1];r&&ft(r)===i&&r.to===n.from?o[o.length-1]={...r,to:n.to}:o.push({at:i,from:n.from,to:n.to})}}var Gc=9,Cs=10,Zc=32,Xc=33,Yc=38,Is=40,Di=41,Jc=42,ed=58,Ls=60,Oi=91,Bs=92,td=93,As=95,nd=96,mt=126,Ks="[!\"#$%&'()*+,./:;<=>?@[\\\\\\]^_`{|}~-]",Ns=new RegExp("^"+Ks),Hi="&(?:#[xX][0-9a-fA-F]{1,6}|#[0-9]{1,7}|[A-Za-z][A-Za-z0-9]{1,31});",od=new RegExp(Hi,"y"),id=new RegExp("\\\\"+Ks+"|"+Hi,"g"),Vs="[A-Za-z][A-Za-z0-9-]*",rd="[a-zA-Z_:][a-zA-Z0-9:._-]*",sd="[^\"'=<>`\\x00-\\x20]+",ld=`(?:${sd}|'[^']*'|"[^"]*")`,ad=`(?:[ \\t\\n]+${rd}(?:[ \\t\\n]*=[ \\t\\n]*${ld})?)`,Pi=`<${Vs}${ad}*[ \\t\\n]*/?>`,$i=`</${Vs}[ \\t\\n]*>`,cd="<!-->|<!--->|<!--[\\s\\S]*?-->",dd="<\\?[\\s\\S]*?\\?>",ud="<![A-Za-z][^>]*>",hd="<!\\[CDATA\\[[\\s\\S]*?\\]\\]>",fd=new RegExp(`(?:${Pi}|${$i}|${cd}|${dd}|${ud}|${hd})`,"y"),Fi="[A-Za-z][A-Za-z0-9.+-]{1,31}:[^<>\\x00-\\x20]*",qi="[a-zA-Z0-9.!#$%&'*+/=?^_`{|}~-]+@[a-zA-Z0-9](?:[a-zA-Z0-9-]{0,61}[a-zA-Z0-9])?(?:\\.[a-zA-Z0-9](?:[a-zA-Z0-9-]{0,61}[a-zA-Z0-9])?)*",pd=new RegExp(`<(${Fi})>`,"y"),md=new RegExp(`<(${qi})>`,"y"),gd=/"(?:\\[\s\S]|[^\\"\x00])*"|'(?:\\[\s\S]|[^\\'\x00])*'|\((?:\\[\s\S]|[^\\()\x00])*\)/y,bd=/<(?:[^<>\n\\\x00]|\\.)*>/y,yd=/\[(?:[^\\[\]]|\\[\s\S]){0,1000}\]/y,kd=/[ \t]*(?:\n[ \t]*)?/y,Rs=/[ \t]*(?:\n|$)/y,Ds=/[^\n`[\]\\!<&*_~]+/y,Os=/`+/y,vd=/[\t\n\f\r\p{Zs}]/u,xd=/[\p{P}\p{S}]/u;function mo(o){return vd.test(o)}function go(o){return xd.test(o)}function _i(o){if(o[1]==="#"){let e=o[2]==="x"||o[2]==="X",t=parseInt(o.slice(e?3:2,-1),e?16:10);return t===0||t>1114111||t>=55296&&t<=57343?"\uFFFD":String.fromCodePoint(t)}return Uc(o.slice(1,-1))??null}var wd=new RegExp(Hi,"g");function Us(o){return o.includes("&")?o.replace(wd,e=>_i(e)??e):o}function pn(o){return!o.includes("\\")&&!o.includes("&")?o:o.replace(id,e=>e[0]==="\\"?e[1]:_i(e)??e)}function Hs(o){return o.slice(1,-1).replace(/^[ \t\r\n]+|[ \t\r\n]+$/g,"").replace(/[ \t\r\n]+/g," ").toLowerCase().toUpperCase()}var _=class{constructor(e,t=0,n=t,i=""){this.type=e;this.value=i,this.from=t,this.to=n}value="";name="";depth=0;destination="";title="";align="";width=0;height=0;apart=!1;from;to;escaped=!1;syntax=null;content=null;parent=null;first=null;last=null;prev=null;next=null;append(e){e.unlink(),e.parent=this,e.depth>=this.depth&&(this.depth=e.depth+1),this.last?(this.last.next=e,e.prev=this.last,this.last=e):this.first=this.last=e}insertAfter(e){e.unlink(),e.next=this.next,e.next&&(e.next.prev=e),e.prev=this,this.next=e,e.parent=this.parent,this.parent&&!e.next&&(this.parent.last=e)}unlink(){this.prev?this.prev.next=this.next:this.parent&&(this.parent.first=this.next),this.next?this.next.prev=this.prev:this.parent&&(this.parent.last=this.prev),this.parent=this.prev=this.next=null}},fo=100;function Ps(o,e){let t=0;for(let n=o.next;n&&n!==e&&t<fo;n=n.next)n.depth>=t&&(t=n.depth+1);return t}function $s(o,e,t){let n=new _("text",e,t,o);return n.escaped=!0,n.apart=o==="@",n}function gt(o,e){let t=e;return t.pos={from:o.from,to:o.to},o.syntax&&(t.syntax=o.syntax),t}function Sd(o){let e={from:o.from,to:o.to};return o.escaped?{type:"text",value:o.value,pos:e,pieces:[]}:{type:"text",value:o.value,pos:e}}function Td(o,e){let t=o.value+e.value,n={from:o.pos.from,to:e.to};if(!o.pieces&&!e.escaped&&o.pos.to===e.from&&e.value.length===e.to-e.from)return{type:"text",value:t,pos:n};let i=o.pieces??[{at:0,from:o.pos.from,to:o.pos.to}];return jc(i,e.escaped?[]:[{at:0,from:e.from,to:e.to}],o.value.length),_s(i,t,n)?{type:"text",value:t,pos:n}:{type:"text",value:t,pos:n,pieces:i}}function po(o){let e=[],t=!1;for(let n=o.first;n;n=n.next)switch(n.type){case"text":{if(n.value==="")break;let i=e[e.length-1];i?.type==="text"&&!t&&!n.apart?e[e.length-1]=Td(i,n):e.push(Sd(n)),t=n.apart;break}case"softBreak":case"hardBreak":e.push(gt(n,{type:n.type}));break;case"code":e.push(gt(n,n.content?{type:n.type,value:n.value,content:n.content}:{type:n.type,value:n.value}));break;case"html":e.push(gt(n,{type:n.type,value:n.value}));break;case"token":e.push(gt(n,{type:"token",name:n.name,value:n.value}));break;case"emphasis":case"strong":case"strike":e.push(gt(n,{type:n.type,children:po(n)}));break;case"link":e.push(gt(n,{type:n.type,destination:n.destination,title:n.title,children:po(n)}));break;case"image":{e.push(gt(n,{type:n.type,destination:n.destination,title:n.title,children:po(n),...n.align?{align:n.align}:{},...n.width?{width:n.width}:{},...n.width&&n.height?{height:n.height}:{}}));break}case"root":break}return e}var bo=class{constructor(e,t,n,i=!1){this.subject=e;this.refs=t;this.autolinks=i;for(let r of n)for(let s of r.triggers){let l=s.charCodeAt(0);this.triggers.set(l,[...this.triggers.get(l)??[],r])}if(this.triggers.size>0){let r=[...this.triggers.keys()].map(s=>"\\u"+s.toString(16).padStart(4,"0")).join("");this.reText=new RegExp(Ds.source.replace(/\]\+$/,r+"]+"),"y")}}pos=0;delimiters=null;brackets=null;backticksAfter=new Map;titleFailedFrom=new Map;lastEnds=new Map;destRange=null;titleRange=null;triggers=new Map;reText=Ds;parse(){let e=new _("root");for(;this.pos<this.subject.length;)this.parseOne(e);return this.processEmphasis(null),po(e)}peek(e=0){let t=this.subject.charCodeAt(this.pos+e);return Number.isNaN(t)?-1:t}match(e){e.lastIndex=this.pos;let t=e.exec(this.subject);return t&&(this.pos=e.lastIndex),t}text(e,t){return new _("text",e,t,this.subject.slice(e,t))}parseOne(e){let t=this.peek();if(this.triggers.size>0&&this.parseToken(t,e))return;let n=!1;switch(t){case Cs:n=this.parseNewline(e);break;case Bs:n=this.parseBackslash(e);break;case nd:n=this.parseBackticks(e);break;case Jc:case As:case mt:n=this.handleDelim(t,e);break;case Oi:n=this.parseOpenBracket(e);break;case Xc:n=this.parseBang(e);break;case td:n=this.parseCloseBracket(e);break;case Ls:n=this.parseAutolink(e)||this.parseHtmlTag(e);break;case Yc:n=this.parseEntity(e);break;default:n=this.parseString(e)}n||(this.pos+=1,e.append(new _("text",this.pos-1,this.pos,String.fromCharCode(t))))}parseToken(e,t){let n=this.triggers.get(e);if(!n)return!1;for(let i of n){let r=i.match(this.subject,this.pos);if(r>this.pos){let s=new _("token",this.pos,r,this.subject.slice(this.pos,r));return s.name=i.name,t.append(s),this.pos=r,!0}}return!1}parseString(e){let t=this.pos,n=this.match(this.reText);if(!n)return!1;if(this.autolinks&&!this.brackets&&/www\.|:\/\//i.test(n[0])){let i=/www\.|(?:https?|ftp):\/\//gi;for(let r of n[0].matchAll(i)){let s=t+r.index;if(!It(this.subject[s-1],r[0].toLowerCase()==="www."))continue;let l=lt(this.subject,s);if(!l)continue;s>t&&e.append(this.text(t,s));let a=new _("link",s,l.end);return a.destination=l.href,a.syntax=[{kind:"dest",from:s,to:l.end}],a.append(this.text(s,l.end)),e.append(a),this.pos=l.end,!0}}return e.append(new _("text",t,this.pos,n[0])),!0}parseNewline(e){let t=this.pos;this.pos+=1;let n=e.last,i=!1;if(n&&n.type==="text"&&n.value.endsWith(" ")){i=n.value.endsWith(" ");let s=n.value.replace(/ +$/,""),l=n.value.length-s.length;n.value=s,n.escaped||(n.to-=l,t=n.to)}let r=new _(i?"hardBreak":"softBreak",t);return e.append(r),this.skipLineStart(),r.to=this.pos,!0}skipLineStart(){let e=this.peek();for(;e===Zc||e===Gc;)this.pos+=1,e=this.peek()}parseBackslash(e){let t=this.pos;this.pos+=1;let n=this.peek();if(n===Cs){this.pos+=1;let i=new _("hardBreak",t);e.append(i),this.skipLineStart(),i.to=this.pos}else n!==-1&&Ns.test(this.subject[this.pos])?(e.append($s(this.subject[this.pos],t,t+2)),this.pos+=1):e.append(new _("text",t,t+1,"\\"));return!0}parseBackticks(e){let t=this.pos,i=this.match(Os)[0].length,r=this.pos,s=this.backticksAfter.get(i);if(s===void 0||r<s){let l;for(;(l=this.match(Os))||this.findNextBacktick();)if(l&&l[0].length===i){let a=this.pos-i,d=this.subject.slice(r,a).replace(/\n/g," "),u=0;d.length>2&&d[0]===" "&&d[d.length-1]===" "&&/[^ ]/.test(d)&&(d=d.slice(1,-1),u=1);let c=new _("code",t,this.pos,d);return c.syntax=[{kind:"open",from:t,to:r},{kind:"close",from:a,to:this.pos}],c.content={from:r+u,to:a-u},e.append(c),!0}this.backticksAfter.set(i,r)}return this.pos=r,e.append(this.text(t,r)),!0}findNextBacktick(){let e=this.subject.indexOf("`",this.pos);return e<0?(this.pos=this.subject.length,!1):(this.pos=e,!0)}parseAutolink(e){let t=this.pos,n=this.match(md);return n?(this.autolink(e,t,"mailto:"+n[1]),!0):(n=this.match(pd),n?(this.autolink(e,t,n[1]),!0):!1)}autolink(e,t,n){let i=new _("link",t,this.pos);i.destination=n,i.syntax=[{kind:"open",from:t,to:t+1},{kind:"dest",from:t+1,to:this.pos-1},{kind:"close",from:this.pos-1,to:this.pos}],i.append(this.text(t+1,this.pos-1)),e.append(i)}parseHtmlTag(e){let t=this.subject,n=this.pos;if(t.startsWith("<!--",n)){if(this.lastEnd("-->")<n+2)return!1}else if(t.startsWith("<?",n)){if(this.lastEnd("?>")<n+1)return!1}else if(t.startsWith("<![CDATA[",n)){if(this.lastEnd("]]>")<n+9)return!1}else if(t.startsWith("<!",n)&&this.lastEnd(">")<n)return!1;let i=this.match(fd);return i?(e.append(new _("html",n,this.pos,i[0])),!0):!1}lastEnd(e){let t=this.lastEnds.get(e);return t===void 0&&(t=this.subject.lastIndexOf(e),this.lastEnds.set(e,t)),t}parseEntity(e){let t=this.pos,n=this.match(od);if(n){let i=_i(n[0]);if(i!==null)return e.append($s(i,t,this.pos)),!0;this.pos=t}return!1}handleDelim(e,t){let n=this.pos;for(;this.peek()===e;)this.pos+=1;let i=this.pos-n,r=n===0?`
24
+ `:Ed(this.subject,n),s=this.pos>=this.subject.length?`
25
+ `:Md(this.subject,this.pos),l=mo(s),a=go(s),d=mo(r),u=go(r),c=!l&&(!a||d||u),h=!d&&(!u||l||a),f=c,p=h;if(e!==mt&&(s==="~"&&(f=!0),r==="~"&&(p=!0)),e===As){let y=f;f=y&&(d||u||!p),p=p&&(l||a||!y)}e===mt&&i>2&&(f=p=!1);let m=this.text(n,this.pos);if(t.append(m),f||p){let y={cc:e,count:i,origCount:i,node:m,canOpen:f,canClose:p,prev:this.delimiters,next:null};y.prev&&(y.prev.next=y),this.delimiters=y}return!0}removeDelimiter(e){e.prev&&(e.prev.next=e.next),e.next?e.next.prev=e.prev:this.delimiters=e.prev}processEmphasis(e){let t=new Map,n=this.delimiters;for(;n&&n!==e&&n.prev!==e;)n=n.prev;for(n===e&&(n=null);n;){if(!n.canClose){n=n.next;continue}let i=n.cc===mt?100+n.count:n.cc*10+(n.canOpen?3:0)+n.origCount%3,r=t.has(i)?t.get(i):e,s=n.prev,l=!1;for(;s&&s!==e&&s!==r;){if(s.cc===n.cc&&s.canOpen){if(n.cc===mt){if(s.count===n.count){l=!0;break}}else if(!((n.canOpen||s.canClose)&&n.origCount%3!==0&&(s.origCount+n.origCount)%3===0)){l=!0;break}}s=s.prev}let a=n;if(l&&s){let d=n.cc===mt?n.count:n.count>=2&&s.count>=2?2:1,u=n.cc===mt?"strike":d===1?"emphasis":"strong",c=s.node,h=n.node;s.count-=d,n.count-=d;let f=Ps(c,h)>=fo;if(f)c.depth=h.depth=fo;else{c.value=c.value.slice(0,c.value.length-d),h.value=h.value.slice(0,h.value.length-d),c.to-=d,h.from+=d;let p=new _(u,c.to,h.from);p.syntax=[{kind:"open",from:p.from,to:p.from+d},{kind:"close",from:p.to-d,to:p.to}];let m=c.next;for(;m&&m!==h;){let y=m.next;p.append(m),m=y}c.insertAfter(p)}if(s.next!==n&&(s.next=n,n.prev=s),s.count===0&&(f||c.unlink(),this.removeDelimiter(s)),n.count===0){f||h.unlink();let p=n.next;this.removeDelimiter(n),n=p}}else n=n.next,t.set(i,a.prev),a.canOpen||this.removeDelimiter(a)}for(;this.delimiters&&this.delimiters!==e;)this.removeDelimiter(this.delimiters)}pushBracket(e,t,n){this.brackets&&(this.brackets.bracketAfter=!0),this.brackets={node:e,prev:this.brackets,prevDelimiter:this.delimiters,index:t,image:n,active:!0,bracketAfter:!1}}parseOpenBracket(e){let t=this.pos;this.pos+=1;let n=new _("text",t,t+1,"[");return e.append(n),this.pushBracket(n,t,!1),!0}parseBang(e){let t=this.pos;if(this.pos+=1,this.peek()===Oi){this.pos+=1;let n=new _("text",t,t+2,"![");e.append(n),this.pushBracket(n,t+1,!0)}else e.append(new _("text",t,t+1,"!"));return!0}parseCloseBracket(e){this.pos+=1;let t=this.pos,n=this.brackets;if(!n)return e.append(new _("text",t-1,t,"]")),!0;if(!n.active)return e.append(new _("text",t-1,t,"]")),this.brackets=n.prev,!0;let i=null,r=null,s=null,l=null,a=!1;if(this.peek()===Is){if(this.pos+=1,this.spnl(),i=this.parseLinkDestination(),i!==null){let h=this.pos;this.spnl(),this.pos!==h&&(r=this.parseLinkTitle()),this.spnl(),this.peek()===Di&&(this.pos+=1,a=!0,s=this.destRange,r!==null&&(l=this.titleRange))}a||(this.pos=t)}if(!a){let h=this.pos,f=this.parseLinkLabel(),p=null;if(f>2?p=this.subject.slice(h,h+f):n.bracketAfter||(p=this.subject.slice(n.index,t)),f===0&&(this.pos=t),p!==null&&p.length<=1001){let m=this.refs.get(Hs(p));m&&(i=m.destination,r=m.title,a=!0)}}if(!a||Ps(n.node,null)>=fo)return this.brackets=n.prev,this.pos=t,e.append(new _("text",t-1,t,"]")),!0;let d=new _(n.image?"image":"link",n.node.from,this.pos);d.destination=i??"",d.title=r??"";let u=[{kind:"open",from:n.node.from,to:n.node.to},{kind:"close",from:t-1,to:t}];if(this.pos>t&&u.push({kind:"tail",from:t,to:this.pos}),s&&u.push({kind:"dest",...s}),l&&u.push({kind:"title",...l}),d.syntax=u,n.image){let h=io(this.subject.slice(n.index+1,t-1));h&&(d.align=h.align??"",d.width=h.width??0,d.height=h.height??0)}let c=n.node.next;for(;c;){let h=c.next;d.append(c),c=h}if(e.append(d),this.processEmphasis(n.prevDelimiter),this.brackets=n.prev,n.node.unlink(),!n.image)for(let h=this.brackets;h;h=h.prev)h.image||(h.active=!1);return!0}spnl(){this.match(kd)}parseLinkDestination(){let e=this.pos,t=this.match(bd);if(t)return this.destRange={from:e+1,to:this.pos-1},pn(t[0].slice(1,-1));if(this.peek()===Ls)return null;let n=this.pos,i=0;for(;;){let r=this.peek();if(r===-1)break;if(r===Bs&&Ns.test(this.subject[this.pos+1]??""))this.pos+=2;else if(r===Is){if(this.pos+=1,i+=1,i>32)return null}else if(r===Di){if(i<1)break;this.pos+=1,i-=1}else{if(r<=32||r===127)break;this.pos+=1}}return this.pos===n&&this.peek()!==Di||i!==0?null:(this.destRange={from:n,to:this.pos},pn(this.subject.slice(n,this.pos)))}parseLinkTitle(){let e=this.pos,t=this.subject[e],n=t===void 0?void 0:this.titleFailedFrom.get(t);if(n!==void 0&&e>=n)return null;let i=this.match(gd);return i?(this.titleRange={from:e,to:this.pos},pn(i[0].slice(1,-1))):((t==='"'||t==="'")&&this.titleFailedFrom.set(t,e),null)}parseLinkLabel(){let e=this.pos,t=this.match(yd);return!t||t[0].length>1001?(this.pos=e,0):t[0].length}parseReference(){let e=this.parseLinkLabel();if(e===0)return 0;let t=this.subject.slice(0,e);if(this.peek()!==ed)return 0;this.pos+=1,this.spnl();let n=this.parseLinkDestination();if(n===null)return 0;let i=this.pos;this.spnl();let r=null;if(this.pos!==i&&(r=this.parseLinkTitle()),r===null&&(this.pos=i),!this.match(Rs)&&(r===null||(r=null,this.pos=i,!this.match(Rs))))return 0;let s=Hs(t);return s===""?0:(this.refs.has(s)||this.refs.set(s,{destination:n,title:r??""}),this.pos)}};function zs(o,e){for(;o.charCodeAt(0)===Oi;){let t=new bo(o,e,[]).parseReference();if(t===0)break;o=o.slice(t)}return o}function Ed(o,e){let t=o.charCodeAt(e-1);if(t>=56320&&t<=57343&&e>=2){let n=o.charCodeAt(e-2);if(n>=55296&&n<=56319)return o.slice(e-2,e)}return o[e-1]}function Md(o,e){return String.fromCodePoint(o.codePointAt(e))}function he(o,e=pe){return new Vi(Ze(e)).parse(o)}var yo=4,Cd=100,Id=65536,Gs=[/^$/,/^<(?:script|pre|textarea|style)(?:[ \t>]|$)/i,/^<!--/,/^<[?]/,/^<![A-Za-z]/,/^<!\[CDATA\[/,/^<[/]?(?: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|h[123456]|head|header|hr|html|iframe|legend|li|link|main|menu|menuitem|nav|noframes|ol|optgroup|option|p|param|search|section|summary|table|tbody|td|tfoot|th|thead|title|tr|track|ul)(?:[ \t]|[/]?>|$)/i,new RegExp(`^(?:${Pi}|${$i})[ \\t]*$`,"i")];function Zs(o){for(let e=1;e<=6;e++)if(Gs[e].test(o))return!0;return!1}var Ld=[/^$/,/<\/(?:script|pre|textarea|style)>/i,/-->/,/\?>/,/>/,/\]\]>/],Bd=/^(?:\*[ \t]*){3,}$|^(?:_[ \t]*){3,}$|^(?:-[ \t]*){3,}$/,Ad=/^[#`~*+_=<>0-9|:-]/,Ki=/[^ \t\f\v\r\n]/,Nd=/^[*+-]/,Rd=/^(\d{1,9})([.)])/,Dd=/^#{1,6}(?:[ \t]+|$)/,Od=/^(?:`{3,}|~{3,})(?=[ \t]*$)/,Ws=/^(?:=+|-+)[ \t]*$/,Hd=/^:?-+:?$/,Pd=/^\[([ \t\nxX])\](?:[ \t\n]+|$)/,yn=class{constructor(e,t){this.type=e;this.startLine=t}parent=null;children=[];depth=0;open=!0;endLine=0;content="";lines=[];contentStart=0;level=0;setext=!1;fenced=!1;fenceChar="";fenceLength=0;fenceOffset=0;info="";htmlType=0;syntax="";matcher=null;list=null;tight=!0;align=[];rows=[];get lastChild(){return this.children[this.children.length-1]}append(e){e.parent=this,e.depth=this.depth+1,this.children.push(e)}remove(){if(!this.parent)return;let e=this.parent.children,t=e.lastIndexOf(this);t>=0&&e.splice(t,1),this.parent=null}};function Qs(o){return o==="paragraph"||o==="codeBlock"||o==="htmlBlock"||o==="rawBlock"}function $d(o,e){switch(o){case"document":case"blockQuote":case"item":return e!=="item";case"list":return e==="item";default:return!1}}function Oe(o){return o===" "||o===" "}var Vi=class{constructor(e){this.options=e}doc=new yn("document",1);tip=this.doc;oldTip=this.doc;lastMatchedContainer=this.doc;refs=new Map;definitions=[];filledCells=0;maxFilledCells=0;line="";lineNumber=0;offset=0;column=0;nextNonspace=0;nextNonspaceColumn=0;indent=0;indented=!1;blank=!1;partiallyConsumedTab=!1;allClosed=!0;parse(e){let t=(e.charCodeAt(0)===65279?e.slice(1):e).split(/\r\n|\n|\r/);this.maxFilledCells=Math.max(Id,e.length);let n=t.length;(e.endsWith(`
26
26
  `)||e.endsWith("\r"))&&(n-=1);for(let s=0;s<n;s++)this.incorporateLine(t[s]);for(;this.tip!==this.doc;)this.finalize(this.tip,n);this.finalize(this.doc,n);let i=[],r=[];for(let s of this.doc.children)for(let l of this.toAst(s))i.push(l),r.push({start:s.startLine,end:s.endLine});return{type:"root",children:i,lines:r,definitions:this.definitions}}extractReferences(e){let t=e.content,n=zs(t,this.refs);n.length<t.length&&this.definitions.push(t.slice(0,t.length-n.length).replace(/\n$/,"")),e.contentStart+=t.length-n.length,e.content=n}findNextNonspace(){let e=this.line,t=this.offset,n=this.column,i;for(;(i=e[t])!==void 0;)if(i===" ")t++,n++;else if(i===" ")t++,n+=4-n%4;else break;this.blank=i===void 0,this.nextNonspace=t,this.nextNonspaceColumn=n,this.indent=n-this.column,this.indented=this.indent>=yo}advanceNextNonspace(){this.offset=this.nextNonspace,this.column=this.nextNonspaceColumn,this.partiallyConsumedTab=!1}advanceOffset(e,t){let n=this.line,i;for(;e>0&&(i=n[this.offset])!==void 0;)if(i===" "){let r=4-this.column%4;if(t){this.partiallyConsumedTab=r>e;let s=r>e?e:r;this.column+=s,this.offset+=this.partiallyConsumedTab?0:1,e-=s}else this.partiallyConsumedTab=!1,this.column+=r,this.offset+=1,e-=1}else this.partiallyConsumedTab=!1,this.offset+=1,this.column+=1,e-=1}addLine(){let e=0;this.partiallyConsumedTab&&(this.offset+=1,e=4-this.column%4,this.tip.content+=" ".repeat(e)),this.tip.lines.push({at:this.tip.content.length-e,line:this.lineNumber,offset:this.offset,pad:e}),this.tip.content+=this.line.slice(this.offset)+`
27
- `}addChild(e){for(;!Pd(this.tip.type,e);)this.finalize(this.tip,this.lineNumber-1);let t=new yn(e,this.lineNumber);return this.tip.append(t),this.tip=t,t}closeUnmatchedBlocks(){if(!this.allClosed){for(;this.oldTip!==this.lastMatchedContainer;){let e=this.oldTip.parent;this.finalize(this.oldTip,this.lineNumber-1),this.oldTip=e}this.allClosed=!0}}incorporateLine(e){let t=this.doc;this.oldTip=this.tip,this.offset=0,this.column=0,this.blank=!1,this.partiallyConsumedTab=!1,this.lineNumber+=1,this.line=e.includes("\0")?e.replace(/\0/g,"\uFFFD"):e;let n;for(;(n=t.lastChild)&&n.open;){t=n,this.findNextNonspace();let r=this.continueBlock(t);if(r===2)return;if(r===1){t=t.parent;break}}this.allClosed=t===this.oldTip,this.lastMatchedContainer=t;let i=t.type!=="paragraph"&&Qs(t.type);for(;!i;){if(this.findNextNonspace(),!this.indented&&this.options.block.length===0&&!Bd.test(this.line.charAt(this.nextNonspace))){this.advanceNextNonspace();break}let r=this.tryStarts(t);if(r===0){this.advanceNextNonspace();break}t=this.tip,r===2&&(i=!0)}if(!this.allClosed&&!this.blank&&this.tip.type==="paragraph")this.addLine();else{this.closeUnmatchedBlocks();let r=t.type;if(Qs(r))this.addLine(),r==="htmlBlock"&&t.htmlType>=1&&t.htmlType<=5&&Id[t.htmlType].test(this.line.slice(this.offset))&&this.finalize(t,this.lineNumber);else if(r==="table"){if(!this.blank&&this.offset<this.line.length){let s=zi(this.line.slice(this.offset),this.lineNumber,this.offset),l=Math.max(0,t.align.length-s.length);this.filledCells+l<=this.maxFilledCells?(this.filledCells+=l,t.rows.push(Kd(s,t.align.length))):(this.finalize(t,this.lineNumber-1),this.addChild("paragraph"),this.advanceNextNonspace(),this.addLine())}}else this.offset<this.line.length&&!this.blank&&(this.addChild("paragraph"),this.advanceNextNonspace(),this.addLine())}}continueBlock(e){let t=this.line;switch(e.type){case"document":case"list":return 0;case"blockQuote":return!this.indented&&t[this.nextNonspace]===">"?(this.advanceNextNonspace(),this.advanceOffset(1,!1),Oe(t[this.offset])&&this.advanceOffset(1,!0),0):1;case"item":{let n=e.list;if(this.blank){if(e.children.length===0)return 1;this.advanceOffset(Math.min(this.indent,n.markerOffset+n.padding),!0)}else if(this.indent>=n.markerOffset+n.padding)this.advanceOffset(n.markerOffset+n.padding,!0);else return 1;return 0}case"heading":case"thematicBreak":return 1;case"codeBlock":if(e.fenced){let n=this.indent<=3&&t[this.nextNonspace]===e.fenceChar?Dd.exec(t.slice(this.nextNonspace)):null;if(n&&n[0].length>=e.fenceLength)return this.finalize(e,this.lineNumber),2;let i=e.fenceOffset;for(;i>0&&Oe(t[this.offset]);)this.advanceOffset(1,!0),i--;return 0}if(this.indent>=yo)this.advanceOffset(yo,!0);else if(this.blank)this.advanceNextNonspace();else return 1;return 0;case"htmlBlock":return this.blank&&(e.htmlType===6||e.htmlType===7)?1:0;case"rawBlock":{let n=e.matcher.next(t.slice(this.offset));return n==="end"?1:n==="close"?(this.addLine(),this.finalize(e,this.lineNumber),2):0}case"paragraph":case"table":return this.blank?1:0}}finalize(e,t){let n=e.parent;switch(e.open=!1,e.endLine=t,e.type){case"paragraph":this.extractReferences(e),Ki.test(e.content)||e.remove();break;case"codeBlock":if(e.fenced){let i=e.content.indexOf(`
27
+ `}addChild(e){for(;!$d(this.tip.type,e);)this.finalize(this.tip,this.lineNumber-1);let t=new yn(e,this.lineNumber);return this.tip.append(t),this.tip=t,t}closeUnmatchedBlocks(){if(!this.allClosed){for(;this.oldTip!==this.lastMatchedContainer;){let e=this.oldTip.parent;this.finalize(this.oldTip,this.lineNumber-1),this.oldTip=e}this.allClosed=!0}}incorporateLine(e){let t=this.doc;this.oldTip=this.tip,this.offset=0,this.column=0,this.blank=!1,this.partiallyConsumedTab=!1,this.lineNumber+=1,this.line=e.includes("\0")?e.replace(/\0/g,"\uFFFD"):e;let n;for(;(n=t.lastChild)&&n.open;){t=n,this.findNextNonspace();let r=this.continueBlock(t);if(r===2)return;if(r===1){t=t.parent;break}}this.allClosed=t===this.oldTip,this.lastMatchedContainer=t;let i=t.type!=="paragraph"&&Qs(t.type);for(;!i;){if(this.findNextNonspace(),!this.indented&&this.options.block.length===0&&!Ad.test(this.line.charAt(this.nextNonspace))){this.advanceNextNonspace();break}let r=this.tryStarts(t);if(r===0){this.advanceNextNonspace();break}t=this.tip,r===2&&(i=!0)}if(!this.allClosed&&!this.blank&&this.tip.type==="paragraph")this.addLine();else{this.closeUnmatchedBlocks();let r=t.type;if(Qs(r))this.addLine(),r==="htmlBlock"&&t.htmlType>=1&&t.htmlType<=5&&Ld[t.htmlType].test(this.line.slice(this.offset))&&this.finalize(t,this.lineNumber);else if(r==="table"){if(!this.blank&&this.offset<this.line.length){let s=zi(this.line.slice(this.offset),this.lineNumber,this.offset),l=Math.max(0,t.align.length-s.length);this.filledCells+l<=this.maxFilledCells?(this.filledCells+=l,t.rows.push(Vd(s,t.align.length))):(this.finalize(t,this.lineNumber-1),this.addChild("paragraph"),this.advanceNextNonspace(),this.addLine())}}else this.offset<this.line.length&&!this.blank&&(this.addChild("paragraph"),this.advanceNextNonspace(),this.addLine())}}continueBlock(e){let t=this.line;switch(e.type){case"document":case"list":return 0;case"blockQuote":return!this.indented&&t[this.nextNonspace]===">"?(this.advanceNextNonspace(),this.advanceOffset(1,!1),Oe(t[this.offset])&&this.advanceOffset(1,!0),0):1;case"item":{let n=e.list;if(this.blank){if(e.children.length===0)return 1;this.advanceOffset(Math.min(this.indent,n.markerOffset+n.padding),!0)}else if(this.indent>=n.markerOffset+n.padding)this.advanceOffset(n.markerOffset+n.padding,!0);else return 1;return 0}case"heading":case"thematicBreak":return 1;case"codeBlock":if(e.fenced){let n=this.indent<=3&&t[this.nextNonspace]===e.fenceChar?Od.exec(t.slice(this.nextNonspace)):null;if(n&&n[0].length>=e.fenceLength)return this.finalize(e,this.lineNumber),2;let i=e.fenceOffset;for(;i>0&&Oe(t[this.offset]);)this.advanceOffset(1,!0),i--;return 0}if(this.indent>=yo)this.advanceOffset(yo,!0);else if(this.blank)this.advanceNextNonspace();else return 1;return 0;case"htmlBlock":return this.blank&&(e.htmlType===6||e.htmlType===7)?1:0;case"rawBlock":{let n=e.matcher.next(t.slice(this.offset));return n==="end"?1:n==="close"?(this.addLine(),this.finalize(e,this.lineNumber),2):0}case"paragraph":case"table":return this.blank?1:0}}finalize(e,t){let n=e.parent;switch(e.open=!1,e.endLine=t,e.type){case"paragraph":this.extractReferences(e),Ki.test(e.content)||e.remove();break;case"codeBlock":if(e.fenced){let i=e.content.indexOf(`
28
28
  `);e.info=pn(e.content.slice(0,i).trim()),e.content=e.content.slice(i+1),e.contentStart+=i+1}else{let i=e.content.split(`
29
29
  `);for(;i.length>0&&/^[ \t]*$/.test(i[i.length-1]);)i.pop();e.content=i.join(`
30
30
  `)+`
31
31
  `,e.endLine=e.startLine+i.length-1}break;case"htmlBlock":e.content=e.content.replace(/(\n *)+$/,"");break;case"rawBlock":{let i=e.content.replace(/\n$/,"").split(`
32
32
  `);for(;i.length>1&&/^[ \t]*$/.test(i[i.length-1]);)i.pop();e.content=i.join(`
33
- `),e.endLine=e.startLine+i.length-1;break}case"item":e.endLine=e.lastChild?e.lastChild.endLine:e.startLine;break;case"list":e.tight=Fd(e),e.lastChild&&(e.endLine=e.lastChild.endLine);break;default:break}this.tip=n??this.doc}tryStarts(e){let t=this.line.slice(this.nextNonspace),n=e.depth<Md;return n&&this.startBlockQuote(t)||this.startAtxHeading(t)||this.startSyntaxBlock(e,t)||this.startFencedCode(t)||this.startHtmlBlock(e,t)||this.startSetextHeading(e,t)||this.startThematicBreak(t)||n&&this.startListItem(e,t)||this.startTable(e,t)||this.startIndentedCode()}startBlockQuote(e){return this.indented||e[0]!==">"?0:(this.advanceNextNonspace(),this.advanceOffset(1,!1),Oe(this.line[this.offset])&&this.advanceOffset(1,!0),this.closeUnmatchedBlocks(),this.addChild("blockQuote"),1)}startAtxHeading(e){if(this.indented||e[0]!=="#")return 0;let t=Rd.exec(e);if(!t)return 0;this.advanceNextNonspace(),this.advanceOffset(t[0].length,!1),this.closeUnmatchedBlocks();let n=this.addChild("heading");return n.level=t[0].trim().length,n.lines.push({at:0,line:this.lineNumber,offset:this.offset,pad:0}),n.content=this.line.slice(this.offset).replace(/^[ \t]*#+[ \t]*$/,"").replace(/[ \t]+#+[ \t]*$/,""),this.advanceOffset(this.line.length-this.offset,!1),2}inParagraph(e){return e.type==="paragraph"||!this.allClosed&&!this.blank&&this.tip.type==="paragraph"}startSyntaxBlock(e,t){if(this.indented||this.options.block.length===0)return 0;let n=this.inParagraph(e);for(let i of this.options.block){if(n&&!i.interruptsParagraph)continue;let r=i.open(t);if(!r)continue;this.closeUnmatchedBlocks();let s=this.addChild("rawBlock");return s.syntax=i.name,s.matcher=r,2}return 0}startFencedCode(e){let t=e[0];if(this.indented||t!=="`"&&t!=="~")return 0;let n=1;for(;e[n]===t;)n++;if(n<3||t==="`"&&e.includes("`",n))return 0;this.closeUnmatchedBlocks();let i=this.addChild("codeBlock");return i.fenced=!0,i.fenceLength=n,i.fenceChar=t,i.fenceOffset=this.indent,this.advanceNextNonspace(),this.advanceOffset(n,!1),2}startHtmlBlock(e,t){if(this.indented||t[0]!=="<")return 0;let n=this.inParagraph(e);for(let i=1;i<=7;i++)if(Gs[i].test(t)&&(i<7||!n)){this.closeUnmatchedBlocks();let r=this.addChild("htmlBlock");return r.htmlType=i,2}return 0}startSetextHeading(e,t){if(!this.options.setext||this.indented||e.type!=="paragraph")return 0;let n=Ws.exec(t);if(!n||(this.closeUnmatchedBlocks(),this.extractReferences(e),e.content.length===0))return 0;let i=new yn("heading",e.startLine);i.level=n[0][0]==="="?1:2,i.setext=!0,i.content=e.content,i.lines=e.lines,i.contentStart=e.contentStart;let r=e.parent;return r.children[r.children.lastIndexOf(e)]=i,i.parent=r,e.parent=null,this.tip=i,this.advanceOffset(this.line.length-this.offset,!1),2}startTable(e,t){if(this.indented||e.type!=="paragraph"||!t.includes("|")&&Ws.test(t))return 0;let n=Vd(t);if(!n)return 0;this.extractReferences(e);let i=e.content.split(`
33
+ `),e.endLine=e.startLine+i.length-1;break}case"item":e.endLine=e.lastChild?e.lastChild.endLine:e.startLine;break;case"list":e.tight=qd(e),e.lastChild&&(e.endLine=e.lastChild.endLine);break;default:break}this.tip=n??this.doc}tryStarts(e){let t=this.line.slice(this.nextNonspace),n=e.depth<Cd;return n&&this.startBlockQuote(t)||this.startAtxHeading(t)||this.startSyntaxBlock(e,t)||this.startFencedCode(t)||this.startHtmlBlock(e,t)||this.startSetextHeading(e,t)||this.startThematicBreak(t)||n&&this.startListItem(e,t)||this.startTable(e,t)||this.startIndentedCode()}startBlockQuote(e){return this.indented||e[0]!==">"?0:(this.advanceNextNonspace(),this.advanceOffset(1,!1),Oe(this.line[this.offset])&&this.advanceOffset(1,!0),this.closeUnmatchedBlocks(),this.addChild("blockQuote"),1)}startAtxHeading(e){if(this.indented||e[0]!=="#")return 0;let t=Dd.exec(e);if(!t)return 0;this.advanceNextNonspace(),this.advanceOffset(t[0].length,!1),this.closeUnmatchedBlocks();let n=this.addChild("heading");return n.level=t[0].trim().length,n.lines.push({at:0,line:this.lineNumber,offset:this.offset,pad:0}),n.content=this.line.slice(this.offset).replace(/^[ \t]*#+[ \t]*$/,"").replace(/[ \t]+#+[ \t]*$/,""),this.advanceOffset(this.line.length-this.offset,!1),2}inParagraph(e){return e.type==="paragraph"||!this.allClosed&&!this.blank&&this.tip.type==="paragraph"}startSyntaxBlock(e,t){if(this.indented||this.options.block.length===0)return 0;let n=this.inParagraph(e);for(let i of this.options.block){if(n&&!i.interruptsParagraph)continue;let r=i.open(t);if(!r)continue;this.closeUnmatchedBlocks();let s=this.addChild("rawBlock");return s.syntax=i.name,s.matcher=r,2}return 0}startFencedCode(e){let t=e[0];if(this.indented||t!=="`"&&t!=="~")return 0;let n=1;for(;e[n]===t;)n++;if(n<3||t==="`"&&e.includes("`",n))return 0;this.closeUnmatchedBlocks();let i=this.addChild("codeBlock");return i.fenced=!0,i.fenceLength=n,i.fenceChar=t,i.fenceOffset=this.indent,this.advanceNextNonspace(),this.advanceOffset(n,!1),2}startHtmlBlock(e,t){if(this.indented||t[0]!=="<")return 0;let n=this.inParagraph(e);for(let i=1;i<=7;i++)if(Gs[i].test(t)&&(i<7||!n)){this.closeUnmatchedBlocks();let r=this.addChild("htmlBlock");return r.htmlType=i,2}return 0}startSetextHeading(e,t){if(!this.options.setext||this.indented||e.type!=="paragraph")return 0;let n=Ws.exec(t);if(!n||(this.closeUnmatchedBlocks(),this.extractReferences(e),e.content.length===0))return 0;let i=new yn("heading",e.startLine);i.level=n[0][0]==="="?1:2,i.setext=!0,i.content=e.content,i.lines=e.lines,i.contentStart=e.contentStart;let r=e.parent;return r.children[r.children.lastIndexOf(e)]=i,i.parent=r,e.parent=null,this.tip=i,this.advanceOffset(this.line.length-this.offset,!1),2}startTable(e,t){if(this.indented||e.type!=="paragraph"||!t.includes("|")&&Ws.test(t))return 0;let n=Ud(t);if(!n)return 0;this.extractReferences(e);let i=e.content.split(`
34
34
  `);i.pop();let r=i.pop();if(r===void 0)return 0;let s=e.lines[e.lines.length-1],l=zi(r,s.line,s.offset,s.pad);if(l.length!==n.length)return 0;this.closeUnmatchedBlocks();let a=e.parent;i.length>0?(e.content=i.join(`
35
35
  `)+`
36
- `,this.finalize(e,this.lineNumber-2)):(e.remove(),this.tip=a);let d=this.addChild("table");return d.startLine=this.lineNumber-1,d.align=n,d.rows.push(l),this.advanceOffset(this.line.length-this.offset,!1),2}startThematicBreak(e){return this.indented||!Ld.test(e)?0:(this.closeUnmatchedBlocks(),this.addChild("thematicBreak"),this.advanceOffset(this.line.length-this.offset,!1),2)}startListItem(e,t){if(this.indented&&e.type!=="list")return 0;let n=this.parseListMarker(e,t);if(!n)return 0;if(this.closeUnmatchedBlocks(),this.tip.type!=="list"||!$d(e.list,n)){let r=this.addChild("list");r.list=n}let i=this.addChild("item");return i.list=n,1}startIndentedCode(){return!this.indented||this.tip.type==="paragraph"||this.blank?0:(this.advanceOffset(yo,!0),this.closeUnmatchedBlocks(),this.addChild("codeBlock"),2)}parseListMarker(e,t){if(this.indent>=4)return null;let n={type:"bullet",bulletChar:"",start:1,delimiter:"",padding:0,markerOffset:this.indent},i,r=Ad.exec(t),s=r?null:Nd.exec(t);if(r)n.bulletChar=r[0],i=1;else if(s&&(e.type!=="paragraph"||parseInt(s[1],10)===1))n.type="ordered",n.start=parseInt(s[1],10),n.delimiter=s[2],i=s[0].length;else return null;let l=this.line[this.nextNonspace+i];if(l!==void 0&&l!==" "&&l!==" "||e.type==="paragraph"&&!Ki.test(this.line.slice(this.nextNonspace+i)))return null;this.advanceNextNonspace(),this.advanceOffset(i,!0);let a=this.column,d=this.offset;do this.advanceOffset(1,!0);while(this.column-a<5&&Oe(this.line[this.offset]));let u=this.line[this.offset]===void 0,c=this.column-a;return c>=5||c<1||u?(n.padding=i+1,this.column=a,this.offset=d,Oe(this.line[this.offset])&&this.advanceOffset(1,!0)):n.padding=i+c,n}toAst(e){switch(e.type){case"paragraph":return[{type:"paragraph",children:gn(js(e.content),this.refs,this.options.inline,this.options.autolinks),source:bn(e,Ui(e.content))}];case"heading":return[{type:"heading",level:e.level,setext:e.setext,children:gn(js(e.content),this.refs,this.options.inline,this.options.autolinks),source:bn(e,Ui(e.content))}];case"thematicBreak":return[{type:"thematicBreak",lines:Ot(e)}];case"codeBlock":return[{type:"codeBlock",fenced:e.fenced,info:e.info,value:e.content,source:bn(e),lines:Ot(e)}];case"htmlBlock":return[{type:"htmlBlock",value:e.content,source:bn(e)}];case"rawBlock":return[{type:"raw",name:e.syntax,value:e.content,source:bn(e)}];case"blockQuote":return[{type:"blockQuote",children:e.children.flatMap(t=>this.toAst(t)),lines:Ot(e)}];case"list":{let t=e.list;return[{type:"list",ordered:t.type==="ordered",start:t.start,marker:t.type==="ordered"?t.delimiter:t.bulletChar,tight:e.tight,items:e.children.map(n=>this.itemToAst(n)),lines:Ot(e)}]}case"table":return[{type:"table",align:e.align,rows:e.rows.map(t=>t.map(n=>gn(n.text,this.refs,this.options.inline,this.options.autolinks))),sources:e.rows.map(t=>t.map(n=>n.source)),lines:Ot(e)}];default:return[]}}itemToAst(e){let t=!1,n=!1,i=e.children[0];if(i?.type==="paragraph"){let s=Hd.exec(i.content);s&&(t=!0,n=s[1]==="x"||s[1]==="X",i.content=i.content.slice(s[0].length),i.contentStart+=s[0].length)}let r=e.children.filter(s=>!(t&&s===i&&!Ki.test(s.content))).flatMap(s=>this.toAst(s));return{type:"listItem",task:t,checked:n,children:r,lines:Ot(e)}}};function js(o){let e=Ui(o),t=o.length;for(;t>e&&Xs(o.charCodeAt(t-1));)t--;return e===0&&t===o.length?o:o.slice(e,t)}function Ui(o){let e=0;for(;e<o.length&&Xs(o.charCodeAt(e));)e++;return e}function bn(o,e=0){return{lines:o.lines,start:o.contentStart+e}}function Ot(o){return{start:o.startLine,end:Math.max(o.startLine,o.endLine)}}function Xs(o){return o===32||o===9||o===10}function $d(o,e){return o!==null&&o.type===e.type&&o.delimiter===e.delimiter&&o.bulletChar===e.bulletChar}function Fd(o){let e=(t,n)=>n!==void 0&&t.endLine!==n.startLine-1;for(let t=0;t<o.children.length;t++){let n=o.children[t];if(e(n,o.children[t+1]))return!1;for(let i=0;i<n.children.length;i++)if(e(n.children[i],n.children[i+1]))return!1}return!0}var qd={text:"",source:{lines:[],start:0}};function zi(o,e=0,t=0,n=0){let i=0,r=o.length;for(;i<r&&Oe(o[i]);)i++;for(;r>i&&Oe(o[r-1]);)r--;let s=[],l="",a=[],d=h=>a.push({at:l.length,line:e,offset:t+h-n,pad:0}),u=()=>{s.push(_d(l,a)),l="",a=[]},c=!1;d(i);for(let h=i;h<r;h++){let f=o[h];c=!1,f==="\\"&&h+1<r?(o[h+1]==="|"?(d(h+1),l+="|"):l+=f+o[h+1],h++):f==="|"?(u(),d(h+1),c=!0):l+=f}return(!c||s.length===0)&&u(),o[i]==="|"&&s.shift(),s}function _d(o,e){let t=0,n=o.length;for(;t<n&&Oe(o[t]);)t++;for(;n>t&&Oe(o[n-1]);)n--;let i=[];return e.forEach((r,s)=>{if((e[s+1]?.at??o.length)<=t)return;let l=Math.max(0,t-r.at);i.push({...r,at:r.at-t+l,offset:r.offset+l})}),{text:o.slice(t,n),source:{lines:i,start:0}}}function Kd(o,e){let t=o.slice(0,e);for(;t.length<e;)t.push(qd);return t}function Vd(o){let e=zi(o);if(e.length===0)return null;let t=[];for(let{text:n}of e){if(!Od.test(n))return null;let i=n.startsWith(":"),r=n.endsWith(":");t.push(i&&r?"center":r?"right":i?"left":null)}return t}var Ud=new Set(["area","base","br","col","embed","hr","img","input","keygen","link","meta","param","source","track","wbr"]),zd=/<!--[\s\S]*?-->|<(script|style|textarea|pre)\b[^>]*>[\s\S]*?<\/\1\s*>/gi,Wi=/<(\/?)([A-Za-z][A-Za-z0-9-]*)\b(?:[^>"']|"[^"]*"|'[^']*')*?(\/?)>/g;function Qi(o,e){let t=o.replace(zd,"");Wi.lastIndex=0;for(let n=Wi.exec(t);n;n=Wi.exec(t)){let i=n[2].toLowerCase();if(!n[1]){!n[3]&&!Ud.has(i)&&e.push(i);continue}let r=e.lastIndexOf(i);r>=0&&(e.length=r)}}function Ys(o,e){let t=o[e];if(t.type!=="htmlBlock")return e;let n=[];if(Qi(t.value,n),n.length===0)return e;for(let i=e+1;i<o.length;i++){let r=o[i];if(r.type==="htmlBlock"&&(Qi(r.value,n),n.length===0))return i}return e}var Wd=/^<details(\s+open(?:\s*=\s*(?:""|''|"open"|'open'|open))?)?\s*>\s*<summary>([^<]*)<\/summary>\s*$/i,Qd=/^<\/details>\s*$/i;function Js(o){let e=new Map,t=[];return o.forEach((n,i)=>{if(n.type!=="htmlBlock")return;let r=Wd.exec(n.value);if(r)t.push({index:i,block:St(ge(Us(r[2].trim())),{open:!!r[1]})});else if(Qd.test(n.value)){let s=t.pop();if(!s)return;e.set(s.index,s.block),e.set(i,Tt())}else{let s=[];Qi(n.value,s),s.length>0&&(t.length=0)}}),e}var ko=o=>`\uE000${o}\uE001`,el=/(\d+)/g;function tl(o,e=pe){let t=he(o,e);if(t.children.every(a=>a.type==="htmlBlock"))return null;let n=co(o),i=a=>{let d=t.lines[a],u=n.lines.starts[d.start-1]??o.length,c=n.lines.ends[Math.max(d.start,d.end)-1]??o.length;return o.slice(u,Math.max(u,c))},r=[],s=[],l=null;return t.children.forEach((a,d)=>{if(a.type==="htmlBlock"){l=null,r.push(i(d));return}l||(l=[],s.push(l),r.push(`
36
+ `,this.finalize(e,this.lineNumber-2)):(e.remove(),this.tip=a);let d=this.addChild("table");return d.startLine=this.lineNumber-1,d.align=n,d.rows.push(l),this.advanceOffset(this.line.length-this.offset,!1),2}startThematicBreak(e){return this.indented||!Bd.test(e)?0:(this.closeUnmatchedBlocks(),this.addChild("thematicBreak"),this.advanceOffset(this.line.length-this.offset,!1),2)}startListItem(e,t){if(this.indented&&e.type!=="list")return 0;let n=this.parseListMarker(e,t);if(!n)return 0;if(this.closeUnmatchedBlocks(),this.tip.type!=="list"||!Fd(e.list,n)){let r=this.addChild("list");r.list=n}let i=this.addChild("item");return i.list=n,1}startIndentedCode(){return!this.indented||this.tip.type==="paragraph"||this.blank?0:(this.advanceOffset(yo,!0),this.closeUnmatchedBlocks(),this.addChild("codeBlock"),2)}parseListMarker(e,t){if(this.indent>=4)return null;let n={type:"bullet",bulletChar:"",start:1,delimiter:"",padding:0,markerOffset:this.indent},i,r=Nd.exec(t),s=r?null:Rd.exec(t);if(r)n.bulletChar=r[0],i=1;else if(s&&(e.type!=="paragraph"||parseInt(s[1],10)===1))n.type="ordered",n.start=parseInt(s[1],10),n.delimiter=s[2],i=s[0].length;else return null;let l=this.line[this.nextNonspace+i];if(l!==void 0&&l!==" "&&l!==" "||e.type==="paragraph"&&!Ki.test(this.line.slice(this.nextNonspace+i)))return null;this.advanceNextNonspace(),this.advanceOffset(i,!0);let a=this.column,d=this.offset;do this.advanceOffset(1,!0);while(this.column-a<5&&Oe(this.line[this.offset]));let u=this.line[this.offset]===void 0,c=this.column-a;return c>=5||c<1||u?(n.padding=i+1,this.column=a,this.offset=d,Oe(this.line[this.offset])&&this.advanceOffset(1,!0)):n.padding=i+c,n}toAst(e){switch(e.type){case"paragraph":return[{type:"paragraph",children:gn(js(e.content),this.refs,this.options.inline,this.options.autolinks),source:bn(e,Ui(e.content))}];case"heading":return[{type:"heading",level:e.level,setext:e.setext,children:gn(js(e.content),this.refs,this.options.inline,this.options.autolinks),source:bn(e,Ui(e.content))}];case"thematicBreak":return[{type:"thematicBreak",lines:Ot(e)}];case"codeBlock":return[{type:"codeBlock",fenced:e.fenced,info:e.info,value:e.content,source:bn(e),lines:Ot(e)}];case"htmlBlock":return[{type:"htmlBlock",value:e.content,source:bn(e)}];case"rawBlock":return[{type:"raw",name:e.syntax,value:e.content,source:bn(e)}];case"blockQuote":return[{type:"blockQuote",children:e.children.flatMap(t=>this.toAst(t)),lines:Ot(e)}];case"list":{let t=e.list;return[{type:"list",ordered:t.type==="ordered",start:t.start,marker:t.type==="ordered"?t.delimiter:t.bulletChar,tight:e.tight,items:e.children.map(n=>this.itemToAst(n)),lines:Ot(e)}]}case"table":return[{type:"table",align:e.align,rows:e.rows.map(t=>t.map(n=>gn(n.text,this.refs,this.options.inline,this.options.autolinks))),sources:e.rows.map(t=>t.map(n=>n.source)),lines:Ot(e)}];default:return[]}}itemToAst(e){let t=!1,n=!1,i=e.children[0];if(i?.type==="paragraph"){let s=Pd.exec(i.content);s&&(t=!0,n=s[1]==="x"||s[1]==="X",i.content=i.content.slice(s[0].length),i.contentStart+=s[0].length)}let r=e.children.filter(s=>!(t&&s===i&&!Ki.test(s.content))).flatMap(s=>this.toAst(s));return{type:"listItem",task:t,checked:n,children:r,lines:Ot(e)}}};function js(o){let e=Ui(o),t=o.length;for(;t>e&&Xs(o.charCodeAt(t-1));)t--;return e===0&&t===o.length?o:o.slice(e,t)}function Ui(o){let e=0;for(;e<o.length&&Xs(o.charCodeAt(e));)e++;return e}function bn(o,e=0){return{lines:o.lines,start:o.contentStart+e}}function Ot(o){return{start:o.startLine,end:Math.max(o.startLine,o.endLine)}}function Xs(o){return o===32||o===9||o===10}function Fd(o,e){return o!==null&&o.type===e.type&&o.delimiter===e.delimiter&&o.bulletChar===e.bulletChar}function qd(o){let e=(t,n)=>n!==void 0&&t.endLine!==n.startLine-1;for(let t=0;t<o.children.length;t++){let n=o.children[t];if(e(n,o.children[t+1]))return!1;for(let i=0;i<n.children.length;i++)if(e(n.children[i],n.children[i+1]))return!1}return!0}var _d={text:"",source:{lines:[],start:0}};function zi(o,e=0,t=0,n=0){let i=0,r=o.length;for(;i<r&&Oe(o[i]);)i++;for(;r>i&&Oe(o[r-1]);)r--;let s=[],l="",a=[],d=h=>a.push({at:l.length,line:e,offset:t+h-n,pad:0}),u=()=>{s.push(Kd(l,a)),l="",a=[]},c=!1;d(i);for(let h=i;h<r;h++){let f=o[h];c=!1,f==="\\"&&h+1<r?(o[h+1]==="|"?(d(h+1),l+="|"):l+=f+o[h+1],h++):f==="|"?(u(),d(h+1),c=!0):l+=f}return(!c||s.length===0)&&u(),o[i]==="|"&&s.shift(),s}function Kd(o,e){let t=0,n=o.length;for(;t<n&&Oe(o[t]);)t++;for(;n>t&&Oe(o[n-1]);)n--;let i=[];return e.forEach((r,s)=>{if((e[s+1]?.at??o.length)<=t)return;let l=Math.max(0,t-r.at);i.push({...r,at:r.at-t+l,offset:r.offset+l})}),{text:o.slice(t,n),source:{lines:i,start:0}}}function Vd(o,e){let t=o.slice(0,e);for(;t.length<e;)t.push(_d);return t}function Ud(o){let e=zi(o);if(e.length===0)return null;let t=[];for(let{text:n}of e){if(!Hd.test(n))return null;let i=n.startsWith(":"),r=n.endsWith(":");t.push(i&&r?"center":r?"right":i?"left":null)}return t}var zd=new Set(["area","base","br","col","embed","hr","img","input","keygen","link","meta","param","source","track","wbr"]),Wd=/<!--[\s\S]*?-->|<(script|style|textarea|pre)\b[^>]*>[\s\S]*?<\/\1\s*>/gi,Wi=/<(\/?)([A-Za-z][A-Za-z0-9-]*)\b(?:[^>"']|"[^"]*"|'[^']*')*?(\/?)>/g;function Qi(o,e){let t=o.replace(Wd,"");Wi.lastIndex=0;for(let n=Wi.exec(t);n;n=Wi.exec(t)){let i=n[2].toLowerCase();if(!n[1]){!n[3]&&!zd.has(i)&&e.push(i);continue}let r=e.lastIndexOf(i);r>=0&&(e.length=r)}}function Ys(o,e){let t=o[e];if(t.type!=="htmlBlock")return e;let n=[];if(Qi(t.value,n),n.length===0)return e;for(let i=e+1;i<o.length;i++){let r=o[i];if(r.type==="htmlBlock"&&(Qi(r.value,n),n.length===0))return i}return e}var Qd=/^<details(\s+open(?:\s*=\s*(?:""|''|"open"|'open'|open))?)?\s*>\s*<summary>([^<]*)<\/summary>\s*$/i,jd=/^<\/details>\s*$/i;function Js(o){let e=new Map,t=[];return o.forEach((n,i)=>{if(n.type!=="htmlBlock")return;let r=Qd.exec(n.value);if(r)t.push({index:i,block:St(ge(Us(r[2].trim())),{open:!!r[1]})});else if(jd.test(n.value)){let s=t.pop();if(!s)return;e.set(s.index,s.block),e.set(i,Tt())}else{let s=[];Qi(n.value,s),s.length>0&&(t.length=0)}}),e}var ko=o=>`\uE000${o}\uE001`,el=/(\d+)/g;function tl(o,e=pe){let t=he(o,e);if(t.children.every(a=>a.type==="htmlBlock"))return null;let n=co(o),i=a=>{let d=t.lines[a],u=n.lines.starts[d.start-1]??o.length,c=n.lines.ends[Math.max(d.start,d.end)-1]??o.length;return o.slice(u,Math.max(u,c))},r=[],s=[],l=null;return t.children.forEach((a,d)=>{if(a.type==="htmlBlock"){l=null,r.push(i(d));return}l||(l=[],s.push(l),r.push(`
37
37
  ${ko(s.length-1)}
38
38
  `)),l.push(...Ss(a,e,i(d),l[l.length-1],n))}),{html:r.join(`
39
39
  `),slots:s}}function Pt(o,e={}){if(e.source)return pl(o.blocks,e.source,e);let t=o.blocks.length;for(;t>0&&er(o.blocks[t-1]);)t--;let n=Pe(o.blocks.slice(0,t),e);return n?n+`
@@ -41,62 +41,62 @@ ${ko(s.length-1)}
41
41
 
42
42
  `,u=M(l);if(u){let c=s+1;for(;c<o.length&&oe(l,o[c]);)c++;let h=o.slice(s,c).map(Mt),f=Pe(h,e);u!=="quote"&&(f=`[!${u.toUpperCase()}]
43
43
  ${Ji(h[0])?"":`
44
- `}${f}`),n&&(n+=d),n+=tr(f,"> ",">"),i=o[c-1],s=c-1;continue}switch(l.type){case"paragraph":a=l.content.length===0?"&nbsp;":kn(l.content,t.paragraph);break;case"quote":continue;case"heading":a=jd(l.level,l.content,t.heading);break;case"listItem":{let c=i?.type==="listItem"&&!i.quote?i:null,h=r.next(l,c);a=h.text,c&&!h.blankLineBefore&&(d=`
45
- `);break}case"code":a=Gd(l.language,I(l.content));break;case"raw":a=I(l.content);break;case"table":a=Zd(l.align,l.rows,t.cell);break;case"divider":a="---";break;case"details":{let c=I(l.content).replace(/[&<>]/g,h=>h==="&"?"&amp;":h==="<"?"&lt;":"&gt;");a=`<details${l.open?" open":""}>
44
+ `}${f}`),n&&(n+=d),n+=tr(f,"> ",">"),i=o[c-1],s=c-1;continue}switch(l.type){case"paragraph":a=l.content.length===0?"&nbsp;":kn(l.content,t.paragraph);break;case"quote":continue;case"heading":a=Gd(l.level,l.content,t.heading);break;case"listItem":{let c=i?.type==="listItem"&&!i.quote?i:null,h=r.next(l,c);a=h.text,c&&!h.blankLineBefore&&(d=`
45
+ `);break}case"code":a=Zd(l.language,I(l.content));break;case"raw":a=I(l.content);break;case"table":a=Xd(l.align,l.rows,t.cell);break;case"divider":a="---";break;case"details":{let c=I(l.content).replace(/[&<>]/g,h=>h==="&"?"&amp;":h==="<"?"&lt;":"&gt;");a=`<details${l.open?" open":""}>
46
46
  <summary>${c}</summary>`;break}case"detailsEnd":a="</details>";break}n&&(n+=d),n+=a,i=l}return n}function Ji(o){return o.type==="divider"?!1:o.type!=="listItem"||o.listType==="task"?!0:o.content.length>0&&(o.start??1)===1}function er(o){return o.type==="paragraph"&&o.content.length===0}function tr(o,e,t){return o.split(`
47
47
  `).map(n=>n?e+n:t).join(`
48
- `)}function jd(o,e,t){let n=kn(e,t);return n=n.replace(/(^|[ \t])(#+)$/,(i,r,s)=>`${r}\\${s}`),"#".repeat(o)+(n?" "+n:"")}function sl(o,e){let t=0,n=0;for(let i of o)n=i===e?n+1:0,n>t&&(t=n);return t}function Gd(o,e){let t=o.includes("`")?"~":"`",n=t.repeat(Math.max(3,sl(e,t)+1)),i=vo(o.replace(/\\(?=[!-/:-@[-`{-~]|$)/g,"\\\\"));return`${n}${i}
48
+ `)}function Gd(o,e,t){let n=kn(e,t);return n=n.replace(/(^|[ \t])(#+)$/,(i,r,s)=>`${r}\\${s}`),"#".repeat(o)+(n?" "+n:"")}function sl(o,e){let t=0,n=0;for(let i of o)n=i===e?n+1:0,n>t&&(t=n);return t}function Zd(o,e){let t=o.includes("`")?"~":"`",n=t.repeat(Math.max(3,sl(e,t)+1)),i=vo(o.replace(/\\(?=[!-/:-@[-`{-~]|$)/g,"\\\\"));return`${n}${i}
49
49
  ${e?e+`
50
- `:""}${n}`}function Zd(o,e,t){let n=l=>"| "+l.map(a=>kn(Jd(a),t).replace(/\|/g,"\\|")).join(" | ")+" |",i="| "+o.map(l=>l==="left"?":--":l==="center"?":-:":l==="right"?"--:":"---").join(" | ")+" |",[r,...s]=e;return[n(r??o.map(()=>[])),i,...s.map(n)].join(`
50
+ `:""}${n}`}function Xd(o,e,t){let n=l=>"| "+l.map(a=>kn(eu(a),t).replace(/\|/g,"\\|")).join(" | ")+" |",i="| "+o.map(l=>l==="left"?":--":l==="center"?":-:":l==="right"?"--:":"---").join(" | ")+" |",[r,...s]=e;return[n(r??o.map(()=>[])),i,...s.map(n)].join(`
51
51
  `)}var Xi=class{constructor(e){this.ctx=e}levels=[];next(e,t){t||(this.levels=[]);let n=this.levels.length-1,i=Math.min(e.indent,this.levels.length),r=e.listType==="ordered",s=i===0?0:this.levels[i-1].column,l=this.levels[i],a=r&&l?.ordered?l.number+1:e.start??1,d=r?`${a}.`:"-",u=s+d.length+1;this.levels.length=i,this.levels.push({column:u,ordered:r,number:a});let c=" ".repeat(s)+d;e.listType==="task"&&(c+=e.checked?" [x]":" [ ]");let h=kn(e.content,this.ctx).split(`
52
- `),f=h.shift();f&&(c+=" "+f);let p=[c,...h.map(x=>x&&" ".repeat(u)+x)].join(`
53
- `),m=t!==null&&(t.content.length>0||t.listType==="task"),y=r&&a!==1||e.content.length===0&&e.listType!=="task",g=i>n&&m&&y;return{text:p,blankLineBefore:g}}};function ll(o){let e=Ze(o),t={lineStart:!1,newline:"entity",options:e};return{paragraph:{lineStart:!0,newline:e.breaks?"soft":"break",options:e},heading:t,cell:t}}function Xd(o,e){return kn(o,ll(e).paragraph)}var nr=["bold","italic","strike"],al=o=>nr.includes(o);function kn(o,e){let t=eu(o);if(e.options.autolinks&&t.some(ul))for(let i of ji){let r=Zi(t,e,i,!0);if(Gi(mn(r,e.options),t))return r}let n=Zi(t,e,ji[0]);if(!t.some(i=>i.marks.some(al))||Gi(mn(n,e.options),t))return n;for(let i of ji.slice(1)){let r=Zi(t,e,i);if(Gi(mn(r,e.options),t))return r}return n}var ji=[{italic:"*",encodeAll:!1},{italic:"_",encodeAll:!1},{italic:"_",encodeAll:!0},{italic:"*",encodeAll:!0}];function Gi(o,e){return o.length===e.length&&o.every((t,n)=>{let i=e[n];return t.text===i.text&&ae(t,i)&&jt(t.marks,i.marks)&&t.image?.src===i.image?.src&&t.image?.alt===i.image?.alt&&t.image?.title===i.image?.title&&t.image?.align===i.image?.align&&t.image?.width===i.image?.width&&t.image?.height===i.image?.height})}var Yd=/^[\t\n\f\r\p{Zs}]+|[\t\n\f\r\p{Zs}]+$/gu,nl=/(?<!\\)(?:\\\\)*\\\|/;function Jd(o){return o.some(e=>e.marks.includes("code")&&nl.test(e.text))?G(o.flatMap(e=>{if(!e.marks.includes("code"))return[e];let t=e.marks.filter(r=>r!=="code"),n=[],i=0;for(let r of e.text.matchAll(new RegExp(nl,"g"))){let s=r.index+r[0].length-1;n.push({...e,text:e.text.slice(i,s)},{...e,text:"|",marks:t}),i=s+1}return n.push({...e,text:e.text.slice(i)}),n.filter(r=>r.text!=="")})):o}function eu(o){let e=G(o.flatMap(t=>{if(!t.marks.includes("code")||!t.text.includes(`
52
+ `),f=h.shift();f&&(c+=" "+f);let p=[c,...h.map(v=>v&&" ".repeat(u)+v)].join(`
53
+ `),m=t!==null&&(t.content.length>0||t.listType==="task"),y=r&&a!==1||e.content.length===0&&e.listType!=="task",g=i>n&&m&&y;return{text:p,blankLineBefore:g}}};function ll(o){let e=Ze(o),t={lineStart:!1,newline:"entity",options:e};return{paragraph:{lineStart:!0,newline:e.breaks?"soft":"break",options:e},heading:t,cell:t}}function Yd(o,e){return kn(o,ll(e).paragraph)}var nr=["bold","italic","strike"],al=o=>nr.includes(o);function kn(o,e){let t=tu(o);if(e.options.autolinks&&t.some(ul))for(let i of ji){let r=Zi(t,e,i,!0);if(Gi(mn(r,e.options),t))return r}let n=Zi(t,e,ji[0]);if(!t.some(i=>i.marks.some(al))||Gi(mn(n,e.options),t))return n;for(let i of ji.slice(1)){let r=Zi(t,e,i);if(Gi(mn(r,e.options),t))return r}return n}var ji=[{italic:"*",encodeAll:!1},{italic:"_",encodeAll:!1},{italic:"_",encodeAll:!0},{italic:"*",encodeAll:!0}];function Gi(o,e){return o.length===e.length&&o.every((t,n)=>{let i=e[n];return t.text===i.text&&ae(t,i)&&jt(t.marks,i.marks)&&t.image?.src===i.image?.src&&t.image?.alt===i.image?.alt&&t.image?.title===i.image?.title&&t.image?.align===i.image?.align&&t.image?.width===i.image?.width&&t.image?.height===i.image?.height})}var Jd=/^[\t\n\f\r\p{Zs}]+|[\t\n\f\r\p{Zs}]+$/gu,nl=/(?<!\\)(?:\\\\)*\\\|/;function eu(o){return o.some(e=>e.marks.includes("code")&&nl.test(e.text))?G(o.flatMap(e=>{if(!e.marks.includes("code"))return[e];let t=e.marks.filter(r=>r!=="code"),n=[],i=0;for(let r of e.text.matchAll(new RegExp(nl,"g"))){let s=r.index+r[0].length-1;n.push({...e,text:e.text.slice(i,s)},{...e,text:"|",marks:t}),i=s+1}return n.push({...e,text:e.text.slice(i)}),n.filter(r=>r.text!=="")})):o}function tu(o){let e=G(o.flatMap(t=>{if(!t.marks.includes("code")||!t.text.includes(`
54
54
  `))return[t];let n=t.marks.filter(i=>i!=="code");return t.text.split(/(\n)/).map(i=>i===`
55
- `?{...t,text:i,marks:n}:{...t,text:i})}));for(let t of nr){let n=[],i=0,r=-1,s="",l=()=>{r<0||(s.replace(Yd,(a,d)=>(n.push([r+d,r+d+a.length]),a)),r=-1,s="")};for(let a of e)a.marks.includes(t)?(r<0&&(r=i),s+=a.marks.includes("code")?"x".repeat(a.text.length):a.text):l(),i+=a.text.length;l();for(let[a,d]of n)e=Zt(e,a,d,t,!1)}return nu(e)}var tu=o=>!o.link&&!o.image&&!o.token&&!o.marks.includes("code")&&!o.marks.includes("html");function nu(o){let e=o.map(s=>s.text).join("");if(!/[ \t](\n|$)|(^|\n)[ \t]/.test(e))return o;let t=[];for(let s of o)for(let l=0;l<s.text.length;l++)t.push(tu(s));let n=[],i=0;for(let s=0;s<=e.length;s++){if(s<e.length&&e[s]!==`
56
- `)continue;let l=u=>(e[u]===" "||e[u]===" ")&&t[u],a=i;for(;a<s&&l(a);)a++;let d=s;for(;d>i&&l(d-1);)d--;a<d&&(a>i&&n.push([i,a]),d<s&&n.push([d,s])),i=s+1}let r=o;for(let s=n.length-1;s>=0;s--)r=st(r,n[s][0],n[s][1]);return G(r)}function ou(o){return o.marks.filter(al)}function iu(o,e,t,n){let i=[],r=[],s=h=>{for(let f=r.length-1;f>=h;f--)i.push({kind:"delim",ch:r[f].ch,count:r[f].count,open:!1});r.length=h},l=(h,f,p)=>{let m=f;for(;m<p&&o[m].marks.includes(h);)m++;return m},a=(h,f,p)=>{let m=h.filter(y=>!r.some(g=>g.mark===y));m.sort((y,g)=>l(g,f,p)-l(y,f,p)||et.indexOf(y)-et.indexOf(g));for(let y of m){let g=y==="strike"?"~":y==="italic"?t:"*",x=i[i.length-1];g!=="~"&&x?.kind==="delim"&&!x.open&&x.ch===g&&(g=g==="*"?"_":"*");let b=y==="italic"?1:2;i.push({kind:"delim",ch:g,count:b,open:!0}),r.push({mark:y,ch:g,count:b})}},d=(h,f)=>{let p=f;for(;p<r.length&&h.includes(r[p].mark);)p++;s(p)},u=(h,f,p,m,y=!1)=>{let g=ou(h);d(g,f),a(g,p,m),h.image?i.push({kind:"raw",text:mu(h.image,e)}):h.marks.includes("html")||h.token?i.push({kind:"raw",text:h.text}):h.marks.includes("code")?i.push({kind:"raw",text:uu(h.text)}):i.push({kind:"text",text:h.text,encodeFirst:!1,encodeLast:!1,inLink:y})},c=0;for(;c<o.length;){let h=o[c];if(h.link===void 0){u(h,0,c,o.length),c++;continue}let f=c;for(;f<o.length&&ae(o[f],h);)f++;let p=nr.filter(y=>o.slice(c,f).every(g=>g.marks.includes(y)));d(p,0),a(p,c,o.length);let m=f===c+1?n&&ul(h)?h.text:pu(h):null;if(m)i.push({kind:"raw",text:m});else{i.push({kind:"raw",text:"["});let y=r.length;for(let g=c;g<f;g++)u(o[g],y,g,f,!0);s(y),i.push({kind:"raw",text:`](${hl(h.link)}${fl(h.linkTitle)})`})}c=f}return s(0),i}function Ht(o){return o===void 0||mo(o)?"space":go(o)?"punct":"other"}function cl(o){return String.fromCodePoint(o.codePointAt(0))}function Yi(o){let e=o.charCodeAt(o.length-1);return e>=56320&&e<=57343&&o.length>1?o.slice(-2):o.slice(-1)}function He(o,e){if(o)return o.kind==="delim"?o.ch:o.kind==="raw"?e==="first"?o.text[0]:o.text[o.text.length-1]:e==="first"?o.encodeFirst?"&":cl(o.text):o.encodeLast?";":Yi(o.text)}function ru(o,e){let t=0;for(;t<o.length;){let n=o[t];if(n.kind!=="delim"){t++;continue}let i=t;for(;i<o.length;){let d=o[i];if(d.kind!=="delim"||d.ch!==n.ch)break;i++}let r=o[t-1],s=o[i],l=o.slice(t,i).some(d=>d.kind==="delim"&&d.open),a=o.slice(t,i).some(d=>d.kind==="delim"&&!d.open);if(l&&s?.kind==="text"&&Ht(He(s,"first"))==="space"&&(s.encodeFirst=!0),a&&r?.kind==="text"&&Ht(He(r,"last"))==="space"&&(r.encodeLast=!0),e)r?.kind==="text"&&Ht(He(r,"last"))==="other"&&(r.encodeLast=!0),s?.kind==="text"&&Ht(He(s,"first"))==="other"&&(s.encodeFirst=!0);else{let d=ol(n.ch,He(r,"last"),He(s,"first"));l&&!d.canOpen&&r?.kind==="text"&&(r.encodeLast=!0,d=ol(n.ch,He(r,"last"),He(s,"first"))),a&&!d.canClose&&s?.kind==="text"&&(s.encodeFirst=!0)}t=i}}function ol(o,e,t){let n=Ht(e),i=Ht(t),r=i!=="space"&&(i!=="punct"||n!=="other"),s=n!=="space"&&(n!=="punct"||i!=="other");return o==="_"?{canOpen:r&&(!s||n==="punct"),canClose:s&&(!r||i==="punct")}:{canOpen:r,canClose:s}}function Zi(o,e,t,n=!1){let i=iu(o,e,t.italic,n);ru(i,t.encodeAll);let r=[],s,l=a=>{a!==""&&(r.push(a),s=a[a.length-1])};return i.forEach((a,d)=>{a.kind==="delim"?l(a.ch.repeat(a.count)):a.kind==="raw"?(e.lineStart&&s===`
55
+ `?{...t,text:i,marks:n}:{...t,text:i})}));for(let t of nr){let n=[],i=0,r=-1,s="",l=()=>{r<0||(s.replace(Jd,(a,d)=>(n.push([r+d,r+d+a.length]),a)),r=-1,s="")};for(let a of e)a.marks.includes(t)?(r<0&&(r=i),s+=a.marks.includes("code")?"x".repeat(a.text.length):a.text):l(),i+=a.text.length;l();for(let[a,d]of n)e=Zt(e,a,d,t,!1)}return ou(e)}var nu=o=>!o.link&&!o.image&&!o.token&&!o.marks.includes("code")&&!o.marks.includes("html");function ou(o){let e=o.map(s=>s.text).join("");if(!/[ \t](\n|$)|(^|\n)[ \t]/.test(e))return o;let t=[];for(let s of o)for(let l=0;l<s.text.length;l++)t.push(nu(s));let n=[],i=0;for(let s=0;s<=e.length;s++){if(s<e.length&&e[s]!==`
56
+ `)continue;let l=u=>(e[u]===" "||e[u]===" ")&&t[u],a=i;for(;a<s&&l(a);)a++;let d=s;for(;d>i&&l(d-1);)d--;a<d&&(a>i&&n.push([i,a]),d<s&&n.push([d,s])),i=s+1}let r=o;for(let s=n.length-1;s>=0;s--)r=st(r,n[s][0],n[s][1]);return G(r)}function iu(o){return o.marks.filter(al)}function ru(o,e,t,n){let i=[],r=[],s=h=>{for(let f=r.length-1;f>=h;f--)i.push({kind:"delim",ch:r[f].ch,count:r[f].count,open:!1});r.length=h},l=(h,f,p)=>{let m=f;for(;m<p&&o[m].marks.includes(h);)m++;return m},a=(h,f,p)=>{let m=h.filter(y=>!r.some(g=>g.mark===y));m.sort((y,g)=>l(g,f,p)-l(y,f,p)||et.indexOf(y)-et.indexOf(g));for(let y of m){let g=y==="strike"?"~":y==="italic"?t:"*",v=i[i.length-1];g!=="~"&&v?.kind==="delim"&&!v.open&&v.ch===g&&(g=g==="*"?"_":"*");let b=y==="italic"?1:2;i.push({kind:"delim",ch:g,count:b,open:!0}),r.push({mark:y,ch:g,count:b})}},d=(h,f)=>{let p=f;for(;p<r.length&&h.includes(r[p].mark);)p++;s(p)},u=(h,f,p,m,y=!1)=>{let g=iu(h);d(g,f),a(g,p,m),h.image?i.push({kind:"raw",text:gu(h.image,e)}):h.marks.includes("html")||h.token?i.push({kind:"raw",text:h.text}):h.marks.includes("code")?i.push({kind:"raw",text:hu(h.text)}):i.push({kind:"text",text:h.text,encodeFirst:!1,encodeLast:!1,inLink:y})},c=0;for(;c<o.length;){let h=o[c];if(h.link===void 0){u(h,0,c,o.length),c++;continue}let f=c;for(;f<o.length&&ae(o[f],h);)f++;let p=nr.filter(y=>o.slice(c,f).every(g=>g.marks.includes(y)));d(p,0),a(p,c,o.length);let m=f===c+1?n&&ul(h)?h.text:mu(h):null;if(m)i.push({kind:"raw",text:m});else{i.push({kind:"raw",text:"["});let y=r.length;for(let g=c;g<f;g++)u(o[g],y,g,f,!0);s(y),i.push({kind:"raw",text:`](${hl(h.link)}${fl(h.linkTitle)})`})}c=f}return s(0),i}function Ht(o){return o===void 0||mo(o)?"space":go(o)?"punct":"other"}function cl(o){return String.fromCodePoint(o.codePointAt(0))}function Yi(o){let e=o.charCodeAt(o.length-1);return e>=56320&&e<=57343&&o.length>1?o.slice(-2):o.slice(-1)}function He(o,e){if(o)return o.kind==="delim"?o.ch:o.kind==="raw"?e==="first"?o.text[0]:o.text[o.text.length-1]:e==="first"?o.encodeFirst?"&":cl(o.text):o.encodeLast?";":Yi(o.text)}function su(o,e){let t=0;for(;t<o.length;){let n=o[t];if(n.kind!=="delim"){t++;continue}let i=t;for(;i<o.length;){let d=o[i];if(d.kind!=="delim"||d.ch!==n.ch)break;i++}let r=o[t-1],s=o[i],l=o.slice(t,i).some(d=>d.kind==="delim"&&d.open),a=o.slice(t,i).some(d=>d.kind==="delim"&&!d.open);if(l&&s?.kind==="text"&&Ht(He(s,"first"))==="space"&&(s.encodeFirst=!0),a&&r?.kind==="text"&&Ht(He(r,"last"))==="space"&&(r.encodeLast=!0),e)r?.kind==="text"&&Ht(He(r,"last"))==="other"&&(r.encodeLast=!0),s?.kind==="text"&&Ht(He(s,"first"))==="other"&&(s.encodeFirst=!0);else{let d=ol(n.ch,He(r,"last"),He(s,"first"));l&&!d.canOpen&&r?.kind==="text"&&(r.encodeLast=!0,d=ol(n.ch,He(r,"last"),He(s,"first"))),a&&!d.canClose&&s?.kind==="text"&&(s.encodeFirst=!0)}t=i}}function ol(o,e,t){let n=Ht(e),i=Ht(t),r=i!=="space"&&(i!=="punct"||n!=="other"),s=n!=="space"&&(n!=="punct"||i!=="other");return o==="_"?{canOpen:r&&(!s||n==="punct"),canClose:s&&(!r||i==="punct")}:{canOpen:r,canClose:s}}function Zi(o,e,t,n=!1){let i=ru(o,e,t.italic,n);su(i,t.encodeAll);let r=[],s,l=a=>{a!==""&&(r.push(a),s=a[a.length-1])};return i.forEach((a,d)=>{a.kind==="delim"?l(a.ch.repeat(a.count)):a.kind==="raw"?(e.lineStart&&s===`
57
57
  `&&Zs(a.text)&&l(" "),l(a.text)):l(dl(a,e,{before:s,after:He(i[d+1],"first"),lineStart:s===void 0||s===`
58
- `,atEnd:d===i.length-1}))}),r.join("")}var il=/[\p{L}\p{N}]/u,su=/[!-/:-@[-`{-~]/,lu=/^&(?:#[0-9]{1,7}|#[xX][0-9a-fA-F]{1,6}|[A-Za-z][A-Za-z0-9]{1,31});/;function rl(o){return`&#${o.codePointAt(0)};`}function dl(o,e,t){let n=o.text.split(`
58
+ `,atEnd:d===i.length-1}))}),r.join("")}var il=/[\p{L}\p{N}]/u,lu=/[!-/:-@[-`{-~]/,au=/^&(?:#[0-9]{1,7}|#[xX][0-9a-fA-F]{1,6}|[A-Za-z][A-Za-z0-9]{1,31});/;function rl(o){return`&#${o.codePointAt(0)};`}function dl(o,e,t){let n=o.text.split(`
59
59
  `),i=n.length-1,r=n.map((l,a)=>{if(a===0)return"";if(e.newline==="entity"||a===i&&l===""&&(t.atEnd||o.encodeLast)||a===1&&n[0]===""&&o.encodeFirst)return"&#10;";let u=a===1&&n[0]==="",c=u?t.lineStart?"":t.before??"":n[a-1];return e.newline==="soft"&&c!==""&&!(u?/[ \t;]$/:/[ \t]$/).test(c)?`
60
60
  `:`\\
61
- `}),s="";return n.forEach((l,a)=>{let d=a===0,u=a===n.length-1;s+=r[a];let c=!d||t.lineStart,h=!u||t.atEnd;s+=au(l,{before:d?t.before:void 0,after:u?t.after:r[a+1][0],encodeFirst:d&&o.encodeFirst,encodeLast:u&&o.encodeLast,startsLine:c,endsLine:h,blockSyntax:e.lineStart&&c,escape:e.options.escape,inline:e.options.inline,autolinks:e.options.autolinks&&!o.inLink})}),s}function au(o,e){if(o==="")return"";let t=a=>e.inline?.some(d=>d.triggers.includes("\\")&&d.match("\\"+a,0)===2)?rl(a):"\\"+a,n=o.length-Yi(o).length,i=new Set;(e.encodeFirst||e.startsLine&&(o[0]===" "||o[0]===" "))&&i.add(0),(e.encodeLast||e.endsLine&&(o[n]===" "||o[n]===" "))&&i.add(n);let r=e.blockSyntax&&!i.has(0)?du(o):-1,s=e.autolinks?cu(o,e.before,e.after):null,l="";for(let a=0;a<o.length;a++){if(i.has(a)){let h=a===n?Yi(o):cl(o.slice(a));l+=rl(h),a+=h.length-1;continue}let d=o[a],u=a>0?i.has(a-1)?";":o[a-1]:e.before,c=a<o.length-1?i.has(a+1)?"&":o[a+1]:e.after;if(a===r||s?.has(a)){l+=t(d);continue}switch(d){case"\\":l+=c===void 0||c===`
62
- `||su.test(c)?"\\\\":d;break;case"`":case"*":case"~":case"[":case"]":l+=t(d);break;case"_":{let h=u!==void 0&&c!==void 0&&il.test(u)&&il.test(c);l+=h?d:t("_");break}case"<":l+=c===void 0||/[A-Za-z/!?]/.test(c)?t("<"):d;break;case"&":l+=lu.test(o.slice(a,a+40))?t("&"):d;break;case"!":l+=c==="["?t("!"):d;break;default:l+=e.escape&&e.escape.includes(d)?t(d):d}}return l}function cu(o,e,t){let n=at(o);if(!n.length&&!/www\.|:\/\//i.test(o))return null;let i=new Set,r=o+(t??"");for(let s of o.matchAll(/www\.|(?:https?|ftp):\/\//gi)){let l=s.index,a=s[0].toLowerCase()==="www.";!It(l>0?o[l-1]:e,a)||!lt(r,l)||i.add(l+s[0].indexOf(a?".":":"))}for(let{from:s}of n)i.add(o.indexOf("@",s));return i}function du(o){if(/^#{1,6}(?:[ \t]|$)/.test(o)||o[0]===">"||/^[-+](?:[ \t]|$)/.test(o)||/^-+[ \t]*$/.test(o)||/^(?:-[ \t]*){3,}$/.test(o)||/^=+[ \t]*$/.test(o))return 0;let e=/^(\d{1,9})[.)](?:[ \t]|$)/.exec(o);return e?e[1].length:/^[|:\- \t]+$/.test(o)&&o.includes("|")&&o.includes("-")?o.indexOf("-"):-1}function uu(o){let e="`".repeat(sl(o,"`")+1);return o.startsWith("`")||o.endsWith("`")||o.startsWith(" ")&&o.endsWith(" ")&&/[^ ]/.test(o)?`${e} ${o} ${e}`:`${e}${o}${e}`}var hu=new RegExp(`^${Fi}$`),fu=new RegExp(`^${qi}$`);function ul(o){return o.link===void 0||o.linkTitle!==void 0||o.image||o.token||o.marks.includes("code")||o.marks.includes("html")?!1:Yr(o.text)===o.link}function pu(o){return o.image||o.marks.includes("code")||o.marks.includes("html")||o.link===void 0||o.linkTitle!==void 0?null:o.text===o.link&&hu.test(o.link)?`<${o.link}>`:o.link==="mailto:"+o.text&&fu.test(o.text)?`<${o.text}>`:null}function vo(o){return o.replace(/&(?=#?[A-Za-z0-9]+;)/g,"\\&")}function hl(o){if(o==="")return"<>";let e=(()=>{let t=0;for(let n of o)if(n==="(")t++;else if(n===")"&&--t<0)return!1;return t===0})();return/[\x00-\x20<>\x7f]/.test(o)||!e?"<"+vo(o.replace(/[\\<>]/g,"\\$&")).replace(/\n/g,"%0A")+">":vo(o.replace(/\\/g,"\\\\"))}function fl(o){return o?` "${vo(o.replace(/\n(?:[ \t]*\n)+/g,`
63
- `).replace(/["\\]/g,"\\$&"))}"`:""}function mu(o,e){let t=e.newline==="soft"?{...e,newline:"break"}:e,n=dl({text:o.alt,encodeFirst:!1,encodeLast:!1},t,{before:"[",after:"]",lineStart:!1,atEnd:!1}),i=fl(o.title),r=hn(o),s=io(n+r);return`![${((s?s.index===n.length&&hn(s)===r:!r)?n:n.replace(/\|(?=[^|]*$)/,"&#124;"))+r}](${hl(o.src)}${i})`}function Le(o,e,t=!0){let n=he(o,e),{lines:i}=co(o),{starts:r,ends:s}=i,l=[],a={text:o,lines:i,onQuoteChild:(y,g)=>l.push({node:y,blocks:g})},d=[],u=[],c=new WeakMap,h=new WeakMap,f=t?{lines:i,maps:h}:void 0,p=0,m=(e??pe).details===!1?null:Js(n.children);for(let y=0;y<n.children.length;y++){let g=n.children[y],x=m?.get(y),b=x?y:Ys(n.children,y),w=r[n.lines[y].start-1]??o.length,k=n.lines[b],S=s[Math.max(k.start,k.end)-1]??o.length,v=o.slice(w,S),T=Se=>(f&&h.set(Se,[gs(0,v.length,w)]),Se);l=[];let E=x?[x]:b>y?[T(Dn(v))]:fn(g,e??pe,d[d.length-1],f,a)??[T(ot("markdown",v))];if(y=b,d.push(...E),E.length===0||w<p||S<w)continue;p=S;let A=g.type==="codeBlock"&&g.fenced||g.type==="htmlBlock"?gu(v,e):!1,fe=g.type==="blockQuote"&&b===y?yu(l,E,k.end,o,i):void 0,me=fe?{index:u.length,from:w,to:S,blocks:E,open:A,quote:fe}:{index:u.length,from:w,to:S,blocks:E,open:A};u.push(me);for(let Se of E)c.set(Se,me)}return{doc:{blocks:d},source:{text:o,groups:u,groupOf:c,definitions:n.definitions,mapOf:h}}}function gu(o,e){return he(o+`
61
+ `}),s="";return n.forEach((l,a)=>{let d=a===0,u=a===n.length-1;s+=r[a];let c=!d||t.lineStart,h=!u||t.atEnd;s+=cu(l,{before:d?t.before:void 0,after:u?t.after:r[a+1][0],encodeFirst:d&&o.encodeFirst,encodeLast:u&&o.encodeLast,startsLine:c,endsLine:h,blockSyntax:e.lineStart&&c,escape:e.options.escape,inline:e.options.inline,autolinks:e.options.autolinks&&!o.inLink})}),s}function cu(o,e){if(o==="")return"";let t=a=>e.inline?.some(d=>d.triggers.includes("\\")&&d.match("\\"+a,0)===2)?rl(a):"\\"+a,n=o.length-Yi(o).length,i=new Set;(e.encodeFirst||e.startsLine&&(o[0]===" "||o[0]===" "))&&i.add(0),(e.encodeLast||e.endsLine&&(o[n]===" "||o[n]===" "))&&i.add(n);let r=e.blockSyntax&&!i.has(0)?uu(o):-1,s=e.autolinks?du(o,e.before,e.after):null,l="";for(let a=0;a<o.length;a++){if(i.has(a)){let h=a===n?Yi(o):cl(o.slice(a));l+=rl(h),a+=h.length-1;continue}let d=o[a],u=a>0?i.has(a-1)?";":o[a-1]:e.before,c=a<o.length-1?i.has(a+1)?"&":o[a+1]:e.after;if(a===r||s?.has(a)){l+=t(d);continue}switch(d){case"\\":l+=c===void 0||c===`
62
+ `||lu.test(c)?"\\\\":d;break;case"`":case"*":case"~":case"[":case"]":l+=t(d);break;case"_":{let h=u!==void 0&&c!==void 0&&il.test(u)&&il.test(c);l+=h?d:t("_");break}case"<":l+=c===void 0||/[A-Za-z/!?]/.test(c)?t("<"):d;break;case"&":l+=au.test(o.slice(a,a+40))?t("&"):d;break;case"!":l+=c==="["?t("!"):d;break;default:l+=e.escape&&e.escape.includes(d)?t(d):d}}return l}function du(o,e,t){let n=at(o);if(!n.length&&!/www\.|:\/\//i.test(o))return null;let i=new Set,r=o+(t??"");for(let s of o.matchAll(/www\.|(?:https?|ftp):\/\//gi)){let l=s.index,a=s[0].toLowerCase()==="www.";!It(l>0?o[l-1]:e,a)||!lt(r,l)||i.add(l+s[0].indexOf(a?".":":"))}for(let{from:s}of n)i.add(o.indexOf("@",s));return i}function uu(o){if(/^#{1,6}(?:[ \t]|$)/.test(o)||o[0]===">"||/^[-+](?:[ \t]|$)/.test(o)||/^-+[ \t]*$/.test(o)||/^(?:-[ \t]*){3,}$/.test(o)||/^=+[ \t]*$/.test(o))return 0;let e=/^(\d{1,9})[.)](?:[ \t]|$)/.exec(o);return e?e[1].length:/^[|:\- \t]+$/.test(o)&&o.includes("|")&&o.includes("-")?o.indexOf("-"):-1}function hu(o){let e="`".repeat(sl(o,"`")+1);return o.startsWith("`")||o.endsWith("`")||o.startsWith(" ")&&o.endsWith(" ")&&/[^ ]/.test(o)?`${e} ${o} ${e}`:`${e}${o}${e}`}var fu=new RegExp(`^${Fi}$`),pu=new RegExp(`^${qi}$`);function ul(o){return o.link===void 0||o.linkTitle!==void 0||o.image||o.token||o.marks.includes("code")||o.marks.includes("html")?!1:Yr(o.text)===o.link}function mu(o){return o.image||o.marks.includes("code")||o.marks.includes("html")||o.link===void 0||o.linkTitle!==void 0?null:o.text===o.link&&fu.test(o.link)?`<${o.link}>`:o.link==="mailto:"+o.text&&pu.test(o.text)?`<${o.text}>`:null}function vo(o){return o.replace(/&(?=#?[A-Za-z0-9]+;)/g,"\\&")}function hl(o){if(o==="")return"<>";let e=(()=>{let t=0;for(let n of o)if(n==="(")t++;else if(n===")"&&--t<0)return!1;return t===0})();return/[\x00-\x20<>\x7f]/.test(o)||!e?"<"+vo(o.replace(/[\\<>]/g,"\\$&")).replace(/\n/g,"%0A")+">":vo(o.replace(/\\/g,"\\\\"))}function fl(o){return o?` "${vo(o.replace(/\n(?:[ \t]*\n)+/g,`
63
+ `).replace(/["\\]/g,"\\$&"))}"`:""}function gu(o,e){let t=e.newline==="soft"?{...e,newline:"break"}:e,n=dl({text:o.alt,encodeFirst:!1,encodeLast:!1},t,{before:"[",after:"]",lineStart:!1,atEnd:!1}),i=fl(o.title),r=hn(o),s=io(n+r);return`![${((s?s.index===n.length&&hn(s)===r:!r)?n:n.replace(/\|(?=[^|]*$)/,"&#124;"))+r}](${hl(o.src)}${i})`}function Le(o,e,t=!0){let n=he(o,e),{lines:i}=co(o),{starts:r,ends:s}=i,l=[],a={text:o,lines:i,onQuoteChild:(y,g)=>l.push({node:y,blocks:g})},d=[],u=[],c=new WeakMap,h=new WeakMap,f=t?{lines:i,maps:h}:void 0,p=0,m=(e??pe).details===!1?null:Js(n.children);for(let y=0;y<n.children.length;y++){let g=n.children[y],v=m?.get(y),b=v?y:Ys(n.children,y),w=r[n.lines[y].start-1]??o.length,k=n.lines[b],S=s[Math.max(k.start,k.end)-1]??o.length,x=o.slice(w,S),T=Se=>(f&&h.set(Se,[gs(0,x.length,w)]),Se);l=[];let E=v?[v]:b>y?[T(Dn(x))]:fn(g,e??pe,d[d.length-1],f,a)??[T(ot("markdown",x))];if(y=b,d.push(...E),E.length===0||w<p||S<w)continue;p=S;let A=g.type==="codeBlock"&&g.fenced||g.type==="htmlBlock"?bu(x,e):!1,fe=g.type==="blockQuote"&&b===y?ku(l,E,k.end,o,i):void 0,me=fe?{index:u.length,from:w,to:S,blocks:E,open:A,quote:fe}:{index:u.length,from:w,to:S,blocks:E,open:A};u.push(me);for(let Se of E)c.set(Se,me)}return{doc:{blocks:d},source:{text:o,groups:u,groupOf:c,definitions:n.definitions,mapOf:h}}}function bu(o,e){return he(o+`
64
64
 
65
- x`,e).children.length<2}var bu=o=>/^[ \t]*$/.test(ho(o));function yu(o,e,t,n,i){let r=M(e[0]);if(r===null)return;let s=new Map(e.map(u=>[u.id,u])),l=[];for(let[u,{node:c,blocks:h}]of o.entries()){if(h.length===0)continue;let f=ku(c);if(f===null)return;l.push({start:u===0&&r!=="quote"?f+1:f,blocks:h.map(p=>s.get(p.id)??p)})}let a=u=>n.slice(i.starts[u-1]??n.length,i.ends[u-1]??n.length),d=[];return l.forEach(({start:u,blocks:c},h)=>{let f=i.starts[u-1]??n.length,p=l[h+1]?l[h+1].start-1:t;for(;p>u&&bu(a(p));)p--;let m=i.ends[p-1]??f;d.push({from:f,to:Math.max(f,m),blocks:c})}),{kind:r,children:d}}function ku(o){switch(o.type){case"paragraph":case"heading":case"htmlBlock":case"raw":return o.source?.lines[0]?.line??null;default:return o.lines?.start??null}}function ml(o,e){return M(o)!==null||M(e)!==null?oe(o,e):o?.type==="listItem"&&e?.type==="listItem"}function pl(o,e,t){let n=e.text,i,r,s=[];for(let b=0;b<o.length;){let w=o[b],k=e.groupOf.get(w);if(k&&k.blocks[0]===w&&k.blocks.every((E,A)=>o[b+A]===E)){let E=o[b+k.blocks.length];if(!(k.quote&&E&&oe(k.blocks[k.blocks.length-1],E))){s.push({group:k,blocks:[...k.blocks]}),b+=k.blocks.length;continue}}i??=new Map(e.groups.map(E=>[E.blocks[0].id,E]));let S=xu(o,b,i,e,t);if(S){s.push(S),b+=S.blocks.length;continue}r??=wu(e);let v=Su(o,b,r,e,t);if(v){s.push(v),b+=v.blocks.length;continue}let T=s[s.length-1];T&&!T.group?T.blocks.push(w):s.push({group:null,blocks:[w]}),b++}let l=(b,w)=>!!b&&(!b.group||!w.group||w.group.index!==b.group.index+1),a=b=>!!b.group&&/^[ \t]/.test(n.slice(b.group.from,b.group.to));for(let b=!0;b;){b=!1,s.forEach((w,k)=>{if(!w.group)return;let S=s[k-1],v=s[k+1],T=w.blocks[0],E=w.blocks[w.blocks.length-1],A=S?.blocks[S.blocks.length-1];(l(S,w)&&(ml(A,T)||A?.type==="listItem"&&a(w))||v&&l(w,v)&&ml(E,v.blocks[0])||w.group.open&&v)&&(w.group=null,b=!0)});for(let w=s.length-1;w>0;w--)!s[w].group&&!s[w-1].group&&(s[w-1].blocks.push(...s[w].blocks),s.splice(w,1))}let d=s[s.length-1];if(d&&!d.group){for(;d.blocks.length>0&&er(d.blocks[d.blocks.length-1]);)d.blocks.pop();d.blocks.length===0&&s.pop()}if(s.length===0&&e.groups.length===0)return n;let u=new Set;for(let b of s)b.group&&u.add(b.group.index);let c=(b,w)=>{if(!b||!w)return null;let k=n.slice(b.to,w.from);return/(?:\r\n|\n|\r)[ \t]*(?:\r\n|\n|\r)/.test(k)?k:null},h="",f;for(let b of s){let w=b.group?b.text??n.slice(b.group.from,b.group.to):Pe(b.blocks,t);if(w===""&&!b.group)continue;let k=b.group,S=f?.group;if(!f)k?.index===0&&(h+=n.slice(0,k.from));else if(S&&k&&k.index===S.index+1)h+=n.slice(S.to,k.from);else{let v=null;S&&!k&&!u.has(S.index+1)&&(v=c(S,e.groups[S.index+1])),k&&!S&&!u.has(k.index-1)&&(v=c(e.groups[k.index-1],k)),h+=v??`
65
+ x`,e).children.length<2}var yu=o=>/^[ \t]*$/.test(ho(o));function ku(o,e,t,n,i){let r=M(e[0]);if(r===null)return;let s=new Map(e.map(u=>[u.id,u])),l=[];for(let[u,{node:c,blocks:h}]of o.entries()){if(h.length===0)continue;let f=vu(c);if(f===null)return;l.push({start:u===0&&r!=="quote"?f+1:f,blocks:h.map(p=>s.get(p.id)??p)})}let a=u=>n.slice(i.starts[u-1]??n.length,i.ends[u-1]??n.length),d=[];return l.forEach(({start:u,blocks:c},h)=>{let f=i.starts[u-1]??n.length,p=l[h+1]?l[h+1].start-1:t;for(;p>u&&yu(a(p));)p--;let m=i.ends[p-1]??f;d.push({from:f,to:Math.max(f,m),blocks:c})}),{kind:r,children:d}}function vu(o){switch(o.type){case"paragraph":case"heading":case"htmlBlock":case"raw":return o.source?.lines[0]?.line??null;default:return o.lines?.start??null}}function ml(o,e){return M(o)!==null||M(e)!==null?oe(o,e):o?.type==="listItem"&&e?.type==="listItem"}function pl(o,e,t){let n=e.text,i,r,s=[];for(let b=0;b<o.length;){let w=o[b],k=e.groupOf.get(w);if(k&&k.blocks[0]===w&&k.blocks.every((E,A)=>o[b+A]===E)){let E=o[b+k.blocks.length];if(!(k.quote&&E&&oe(k.blocks[k.blocks.length-1],E))){s.push({group:k,blocks:[...k.blocks]}),b+=k.blocks.length;continue}}i??=new Map(e.groups.map(E=>[E.blocks[0].id,E]));let S=wu(o,b,i,e,t);if(S){s.push(S),b+=S.blocks.length;continue}r??=Su(e);let x=Tu(o,b,r,e,t);if(x){s.push(x),b+=x.blocks.length;continue}let T=s[s.length-1];T&&!T.group?T.blocks.push(w):s.push({group:null,blocks:[w]}),b++}let l=(b,w)=>!!b&&(!b.group||!w.group||w.group.index!==b.group.index+1),a=b=>!!b.group&&/^[ \t]/.test(n.slice(b.group.from,b.group.to));for(let b=!0;b;){b=!1,s.forEach((w,k)=>{if(!w.group)return;let S=s[k-1],x=s[k+1],T=w.blocks[0],E=w.blocks[w.blocks.length-1],A=S?.blocks[S.blocks.length-1];(l(S,w)&&(ml(A,T)||A?.type==="listItem"&&a(w))||x&&l(w,x)&&ml(E,x.blocks[0])||w.group.open&&x)&&(w.group=null,b=!0)});for(let w=s.length-1;w>0;w--)!s[w].group&&!s[w-1].group&&(s[w-1].blocks.push(...s[w].blocks),s.splice(w,1))}let d=s[s.length-1];if(d&&!d.group){for(;d.blocks.length>0&&er(d.blocks[d.blocks.length-1]);)d.blocks.pop();d.blocks.length===0&&s.pop()}if(s.length===0&&e.groups.length===0)return n;let u=new Set;for(let b of s)b.group&&u.add(b.group.index);let c=(b,w)=>{if(!b||!w)return null;let k=n.slice(b.to,w.from);return/(?:\r\n|\n|\r)[ \t]*(?:\r\n|\n|\r)/.test(k)?k:null},h="",f;for(let b of s){let w=b.group?b.text??n.slice(b.group.from,b.group.to):Pe(b.blocks,t);if(w===""&&!b.group)continue;let k=b.group,S=f?.group;if(!f)k?.index===0&&(h+=n.slice(0,k.from));else if(S&&k&&k.index===S.index+1)h+=n.slice(S.to,k.from);else{let x=null;S&&!k&&!u.has(S.index+1)&&(x=c(S,e.groups[S.index+1])),k&&!S&&!u.has(k.index-1)&&(x=c(e.groups[k.index-1],k)),h+=x??`
66
66
 
67
67
  `}h+=w,f=b}let p=f?.group,m=n===""||/[\r\n]$/.test(n)?`
68
- `:"",y=p&&p.index===e.groups.length-1?n.slice(p.to):h===""?"":m,g=gl(h+y),x=e.definitions.filter(b=>!g.includes(gl(b)));if(x.length>0){let b=h.replace(/[\r\n]+$/,"");h=(b?b+`
68
+ `:"",y=p&&p.index===e.groups.length-1?n.slice(p.to):h===""?"":m,g=gl(h+y),v=e.definitions.filter(b=>!g.includes(gl(b)));if(v.length>0){let b=h.replace(/[\r\n]+$/,"");h=(b?b+`
69
69
 
70
- `:"")+x.join(`
71
- `),y=m}return h+y}var vu=/^((?:[ \t]*>)*[ \t]*(?:[-+*]|\d{1,9}[.)])[ \t]+\[)([ xX])(?=\][ \t]|\]$)/gm;function xu(o,e,t,n,i){let r=t.get(o[e].id);if(!r||r.open)return null;let s=o.slice(e,e+r.blocks.length);if(s.length!==r.blocks.length)return null;let l=!1;for(let f=0;f<s.length;f++){let p=r.blocks[f],m=s[f];if(p!==m){if(!Tu(p,m))return null;l=!0}}if(!l)return null;let a=s.filter(f=>f.type==="listItem"&&f.listType==="task"),d=n.text.slice(r.from,r.to),u=0,c=d.replace(vu,(f,p,m)=>{let y=a[u++];return!y||y.type!=="listItem"||m!==" "===y.checked?f:p+(y.checked?"x":" ")});if(u!==a.length)return null;let h=Le(c,i,!1).doc.blocks;return Pe(h,i)!==Pe(s,i)?null:{group:r,blocks:s,text:c}}function wu(o){let e=new Map;for(let t of o.groups)t.quote?.children.forEach((n,i)=>{for(let r of n.blocks)e.set(r.id,{group:t,child:i})});return e}function Su(o,e,t,n,i){let r=M(o[e]);if(r===null)return null;let s=e+1;for(;s<o.length&&oe(o[s-1],o[s]);)s++;let l=o.slice(e,s),a=l.map(k=>t.get(k.id)?.group).find(k=>k!==void 0),d=a?.quote;if(!a||!d||d.kind!==r)return null;let u=n.text,c=[];for(let k=0;k<l.length;){let S=t.get(l[k].id);if(S&&S.group!==a)return null;let v=S?d.children[S.child]:null;if(v&&v.blocks.every((E,A)=>l[k+A]===E)){c.push({blocks:[...v.blocks],child:S.child}),k+=v.blocks.length;continue}let T=c[c.length-1];T&&T.child===null?T.blocks.push(l[k]):c.push({blocks:[l[k]],child:null}),k++}if(!c.some(k=>k.child!==null))return null;let h=k=>u.slice(d.children[k].from,d.children[k].to),f=(k,S)=>k.child!==null&&S.child!==null&&S.child===k.child+1,p=(k,S)=>k.blocks[k.blocks.length-1].type==="listItem"&&S.blocks[0].type==="listItem",m=k=>k.child!==null&&/^[ \t]/.test(ho(h(k.child).split(/\r\n|\n|\r/,1)[0])),y=new Map,g=k=>{if(k.child===null)return!1;let S=y.get(k.child);if(S===void 0){let v=he(`${h(k.child)}
70
+ `:"")+v.join(`
71
+ `),y=m}return h+y}var xu=/^((?:[ \t]*>)*[ \t]*(?:[-+*]|\d{1,9}[.)])[ \t]+\[)([ xX])(?=\][ \t]|\]$)/gm;function wu(o,e,t,n,i){let r=t.get(o[e].id);if(!r||r.open)return null;let s=o.slice(e,e+r.blocks.length);if(s.length!==r.blocks.length)return null;let l=!1;for(let f=0;f<s.length;f++){let p=r.blocks[f],m=s[f];if(p!==m){if(!Eu(p,m))return null;l=!0}}if(!l)return null;let a=s.filter(f=>f.type==="listItem"&&f.listType==="task"),d=n.text.slice(r.from,r.to),u=0,c=d.replace(xu,(f,p,m)=>{let y=a[u++];return!y||y.type!=="listItem"||m!==" "===y.checked?f:p+(y.checked?"x":" ")});if(u!==a.length)return null;let h=Le(c,i,!1).doc.blocks;return Pe(h,i)!==Pe(s,i)?null:{group:r,blocks:s,text:c}}function Su(o){let e=new Map;for(let t of o.groups)t.quote?.children.forEach((n,i)=>{for(let r of n.blocks)e.set(r.id,{group:t,child:i})});return e}function Tu(o,e,t,n,i){let r=M(o[e]);if(r===null)return null;let s=e+1;for(;s<o.length&&oe(o[s-1],o[s]);)s++;let l=o.slice(e,s),a=l.map(k=>t.get(k.id)?.group).find(k=>k!==void 0),d=a?.quote;if(!a||!d||d.kind!==r)return null;let u=n.text,c=[];for(let k=0;k<l.length;){let S=t.get(l[k].id);if(S&&S.group!==a)return null;let x=S?d.children[S.child]:null;if(x&&x.blocks.every((E,A)=>l[k+A]===E)){c.push({blocks:[...x.blocks],child:S.child}),k+=x.blocks.length;continue}let T=c[c.length-1];T&&T.child===null?T.blocks.push(l[k]):c.push({blocks:[l[k]],child:null}),k++}if(!c.some(k=>k.child!==null))return null;let h=k=>u.slice(d.children[k].from,d.children[k].to),f=(k,S)=>k.child!==null&&S.child!==null&&S.child===k.child+1,p=(k,S)=>k.blocks[k.blocks.length-1].type==="listItem"&&S.blocks[0].type==="listItem",m=k=>k.child!==null&&/^[ \t]/.test(ho(h(k.child).split(/\r\n|\n|\r/,1)[0])),y=new Map,g=k=>{if(k.child===null)return!1;let S=y.get(k.child);if(S===void 0){let x=he(`${h(k.child)}
72
72
  >
73
- > x`,i).children[0];S=v?.type==="blockQuote"&&v.children.length<2,y.set(k.child,S)}return S};for(let k=!0;k;){k=!1,c.forEach((S,v)=>{if(S.child===null)return;let T=c[v-1],E=c[v+1];(T&&!f(T,S)&&(p(T,S)||T.blocks[T.blocks.length-1].type==="listItem"&&m(S))||E&&!f(S,E)&&(p(S,E)||g(S)))&&(S.child=null,k=!0)});for(let S=c.length-1;S>0;S--)c[S].child===null&&c[S-1].child===null&&(c[S-1].blocks.push(...c[S].blocks),c.splice(S,1))}if(!c.some(k=>k.child!==null))return null;let x=d.children.length-1,b="";return c.forEach((k,S)=>{let v=c[S-1];v?f(v,k)?b+=u.slice(d.children[v.child].to,d.children[k.child].from):b+=`
73
+ > x`,i).children[0];S=x?.type==="blockQuote"&&x.children.length<2,y.set(k.child,S)}return S};for(let k=!0;k;){k=!1,c.forEach((S,x)=>{if(S.child===null)return;let T=c[x-1],E=c[x+1];(T&&!f(T,S)&&(p(T,S)||T.blocks[T.blocks.length-1].type==="listItem"&&m(S))||E&&!f(S,E)&&(p(S,E)||g(S)))&&(S.child=null,k=!0)});for(let S=c.length-1;S>0;S--)c[S].child===null&&c[S-1].child===null&&(c[S-1].blocks.push(...c[S].blocks),c.splice(S,1))}if(!c.some(k=>k.child!==null))return null;let v=d.children.length-1,b="";return c.forEach((k,S)=>{let x=c[S-1];x?f(x,k)?b+=u.slice(d.children[x.child].to,d.children[k.child].from):b+=`
74
74
  >
75
75
  `:k.child===0?b+=u.slice(a.from,d.children[0].from):r!=="quote"&&(b+=`> [!${r.toUpperCase()}]
76
76
  ${Ji(k.blocks[0])?"":`>
77
- `}`),b+=k.child!==null?h(k.child):tr(Pe(k.blocks.map(Mt),i),"> ",">")}),c[c.length-1].child===x&&(b+=u.slice(d.children[x].to,a.to)),{group:a,blocks:l,text:b}}function Tu(o,e){return o.type==="listItem"&&e.type==="listItem"&&o.listType==="task"&&e.listType==="task"&&o.id===e.id&&o.indent===e.indent&&o.content===e.content}function gl(o){return o.replace(/\s+/g," ").trim()}function bt(o,e){return Le(o,e,!1).doc}var Eu=["--mbe-font","--mbe-mono","--mbe-text","--mbe-muted","--mbe-bg","--mbe-popup-bg","--mbe-popup-border","--mbe-popup-shadow","--mbe-hover","--mbe-accent","--mbe-danger","--mbe-radius","--mbe-popup-z"],or=new WeakMap;function ir(o,e){e?or.set(o,e):or.delete(o)}function Mu(o){return or.get(o)??o.closest('dialog[open], [aria-modal="true"]')??o.ownerDocument.body}function $t(o,e){let t=Mu(e);o.parentElement!==t&&t.appendChild(o),o.style.left="0px",o.style.top="0px";let n=o.getBoundingClientRect();return{x:n.left,y:n.top}}function xo(o){let e=o.visualViewport;return e?{left:e.offsetLeft,top:e.offsetTop,width:e.width,height:e.height}:{left:0,top:0,width:o.innerWidth,height:o.innerHeight}}var ie=typeof navigator<"u"&&/Mac|iP(hone|ad|od)/.test(navigator.platform),bl=typeof navigator<"u"&&/AppleWebKit/.test(navigator.userAgent)&&!/Chrome|Chromium|CriOS|Edg|Android/.test(navigator.userAgent),Ft=()=>typeof matchMedia=="function"&&matchMedia("(pointer: coarse)").matches,we=class{constructor(e,t){this.owner=e;let n=e.ownerDocument;this.el=n.createElement("div"),this.el.className=`mbe-ui ${t}`,this.el.hidden=!0,this.el.addEventListener("mousedown",i=>{i.target instanceof HTMLInputElement||i.preventDefault()})}el;open=!1;placed="below";get isOpen(){return this.open}get side(){return this.placed}show(e,t="below",n=6,i="start"){let r=this.owner.ownerDocument;this.open||this.copyTheme(),this.el.hidden=!1,this.open=!0;let s=$t(this.el,this.owner),l=r.defaultView,a=xo(l),d=this.el.scrollTop;this.el.style.maxHeight="";let u=this.el.offsetWidth,c=this.el.offsetHeight,h=a.top+a.height-8-(e.bottom+n),f=e.top-n-8-a.top,p=t;p==="below"&&c>h&&f>h?p="above":p==="above"&&c>f&&h>f&&(p="below");let m=p==="below"?h:f;if(c>m){let b=l.getComputedStyle(this.el),w=b.boxSizing==="border-box"?0:["paddingTop","paddingBottom","borderTopWidth","borderBottomWidth"].reduce((k,S)=>k+parseFloat(b[S]),0);this.el.style.maxHeight=`${Math.max(Math.floor(m-w),80)}px`,c=this.el.offsetHeight,this.el.scrollTop=d}this.placed=p;let y=p==="below"?e.bottom+n:e.top-c-n,g=i==="end"?(e.right??e.left)-u:e.left,x=Math.max(a.left+8,Math.min(g,a.left+a.width-u-8));this.el.style.left=`${Math.round(x-s.x)}px`,this.el.style.top=`${Math.round(y-s.y)}px`}showBeside(e,t,n,i=4){let r=this.owner.ownerDocument;this.open||this.copyTheme(),this.el.hidden=!1,this.open=!0;let s=$t(this.el,this.owner),l=xo(r.defaultView);this.el.style.maxHeight="";let a=this.el.offsetWidth,d=this.el.offsetHeight,u=e.right+i;u+a>l.left+l.width-8&&e.left-i-a>=l.left+8&&(u=e.left-i-a),u=Math.max(l.left+8,Math.min(u,l.left+l.width-a-8));let c=Math.max(l.top+8,Math.min(t-n,l.top+l.height-d-8));this.el.style.left=`${Math.round(u-s.x)}px`,this.el.style.top=`${Math.round(c-s.y)}px`}hide(){this.open&&(this.open=!1,this.el.hidden=!0)}destroy(){this.el.remove()}copyTheme(){let e=this.owner.ownerDocument.defaultView.getComputedStyle(this.owner);for(let t of Eu){let n=e.getPropertyValue(t);n&&this.el.style.setProperty(t,n)}this.el.style.colorScheme=e.colorScheme}},Cu=0,Xe=class o{constructor(e,t,n="listbox"){this.owner=e;this.className=t;this.popup=new we(e,`mbe-menu ${t}`),this.popup.el.setAttribute("role",n),this.popup.el.id=this.id}popup;items=[];index=0;id=`mbe-menu-${++Cu}`;child=null;childIndex=-1;checkIcon;submenuIcon;onPicked=null;onHighlight=null;get el(){return this.popup.el}get isOpen(){return this.popup.isOpen}get activeDescendant(){return this.child?.isOpen?this.child.activeDescendant:this.items.length?`${this.id}-${this.index}`:null}get submenu(){return this.child?.isOpen?this.child:null}contains(e){return this.el.contains(e)||!!this.child?.contains(e)}openSubmenu(e=this.index){let t=this.items[e],n=this.el.querySelector(`#${this.id}-${e}`);if(!t?.submenu||!n)return!1;if(this.child?.isOpen&&this.childIndex===e)return!0;this.highlight(e),this.child||(this.child=new o(this.owner,`mbe-submenu ${this.className}-submenu`,"menu"),this.child.onPicked=()=>{this.closeSubmenu(),this.onPicked?.()},this.child.onHighlight=()=>this.onHighlight?.(this.index)),this.child.checkIcon=this.checkIcon,this.child.el.setAttribute("aria-label",t.submenu.title??t.label),this.child.setSections([t.submenu]);let i=t.submenu.items.find(d=>d.checked);i&&this.child.highlightId(i.id),this.childIndex=e,n.setAttribute("aria-expanded","true");let r=this.el.getBoundingClientRect(),s=n.getBoundingClientRect().top;this.child.popup.showBeside(r,s,0);let l=this.child.el.querySelector(".mbe-menu-item"),a=l?l.getBoundingClientRect().top-this.child.el.getBoundingClientRect().top:0;return a&&this.child.popup.showBeside(r,s,a),this.onHighlight?.(this.index),!0}closeSubmenu(){this.child?.isOpen&&(this.child.hide(),this.el.querySelector(`#${this.id}-${this.childIndex}`)?.setAttribute("aria-expanded","false"),this.childIndex=-1,this.onHighlight?.(this.index))}setSections(e,t){let n=this.el.ownerDocument;this.closeSubmenu(),this.el.replaceChildren(),this.items=[],this.index=0;for(let i of e)if(i.items.length!==0){if(i.title){let r=n.createElement("div");r.className="mbe-menu-title",r.textContent=i.title,r.setAttribute("role","presentation"),this.el.appendChild(r)}for(let r of i.items){let s=this.items.length;this.items.push(r);let l=n.createElement("div");l.className="mbe-menu-item",l.id=`${this.id}-${s}`;let a=this.el.getAttribute("role")==="menu"?r.checked===void 0?"menuitem":"menuitemradio":"option";l.setAttribute("role",a),r.checked!==void 0&&l.setAttribute("aria-checked",String(r.checked)),r.keyShortcuts&&l.setAttribute("aria-keyshortcuts",r.keyShortcuts),r.danger&&l.classList.add("mbe-danger");let d=n.createElement("span");d.className="mbe-menu-icon";let u=X(n,r.icon);u&&d.appendChild(u);let c=n.createElement("span");if(c.className=r.labelClass?`mbe-menu-label ${r.labelClass}`:"mbe-menu-label",Iu(c,r.label,r.mark),l.append(d,c),r.detail){let h=n.createElement("span");h.className="mbe-menu-detail",h.textContent=r.detail,l.appendChild(h)}if(r.checked){let h=n.createElement("span");h.className="mbe-menu-check";let f=X(n,this.checkIcon);f&&h.appendChild(f),l.appendChild(h)}if(r.submenu){l.setAttribute("aria-haspopup","menu"),l.setAttribute("aria-expanded","false");let h=n.createElement("span");h.className="mbe-menu-submenu";let f=X(n,this.submenuIcon);f&&h.appendChild(f),l.appendChild(h)}l.addEventListener("mousemove",()=>{(this.index!==s||!this.child?.isOpen)&&this.highlight(s),r.submenu?this.openSubmenu(s):this.closeSubmenu()}),l.addEventListener("click",()=>this.pick(s)),this.el.appendChild(l)}}if(this.items.length===0&&t){let i=n.createElement("div");i.className="mbe-menu-empty",i.textContent=t,this.el.appendChild(i)}this.highlight(0)}setMessage(e,t){let i=this.el.ownerDocument.createElement("div");i.className=t,i.textContent=e,this.el.replaceChildren(i),this.items=[],this.index=0}set busy(e){e?this.el.setAttribute("aria-busy","true"):this.el.removeAttribute("aria-busy")}get count(){return this.items.length}get activeId(){return this.items[this.index]?.id??null}highlightId(e){let t=this.items.findIndex(n=>n.id===e);return t<0?!1:(this.highlight(t),!0)}page(e){let t=this.el.querySelector(".mbe-menu-item"),n=t&&t.offsetHeight>0?Math.max(1,Math.floor(this.el.clientHeight/t.offsetHeight)-1):8;this.highlight(Math.max(0,Math.min(this.items.length-1,this.index+e*n)))}highlight(e){this.items.length!==0&&(this.index=(e+this.items.length)%this.items.length,this.el.querySelectorAll(".mbe-menu-item").forEach((t,n)=>{t.classList.toggle("mbe-highlighted",n===this.index),t.setAttribute("aria-selected",String(n===this.index))}),this.el.querySelector(`#${this.id}-${this.index}`)?.scrollIntoView?.({block:"nearest"}),this.onHighlight?.(this.index))}get activeIndex(){return this.items.length?this.index:-1}move(e){this.highlight(this.index+e)}pick(e=this.index){let t=this.items[e];if(t){if(t.submenu){this.openSubmenu(e);return}t.run(),this.onPicked?.()}}hide(){this.closeSubmenu(),this.popup.hide()}destroy(){this.child?.destroy(),this.popup.destroy()}};function Iu(o,e,t){let n=t?e.toLowerCase().indexOf(t.toLowerCase()):-1;if(n<0||e.toLowerCase().length!==e.length){o.textContent=e;return}let r=o.ownerDocument.createElement("mark");r.className="mbe-menu-match",r.textContent=e.slice(n,n+t.length),o.replaceChildren(e.slice(0,n),r,e.slice(n+t.length))}function yl(o,e){let t=e.trim().toLowerCase();return t?[o.label,...o.aliases??[]].map(i=>i.toLowerCase()).some(i=>i.includes(t)||i.replace(/\s+/g,"").includes(t.replace(/\s+/g,""))):!0}function rr(){let o={"Mod-b":({editor:e})=>e.commands.toggleBold(),"Mod-i":({editor:e})=>e.commands.toggleItalic(),"Mod-e":({editor:e})=>e.commands.toggleCode(),"Mod-Shift-x":({editor:e})=>e.commands.toggleStrike(),"Mod-Shift-s":({editor:e})=>e.commands.toggleStrike(),"Mod-k":({editor:e})=>e.openLinkPopover(),"Mod-Alt-0":({editor:e})=>e.commands.setParagraph()||!0,"Mod-Alt-1":({editor:e})=>e.commands.toggleHeading({level:1})||!0,"Mod-Alt-2":({editor:e})=>e.commands.toggleHeading({level:2})||!0,"Mod-Alt-3":({editor:e})=>e.commands.toggleHeading({level:3})||!0,"Mod-Alt-4":({editor:e})=>e.commands.toggleHeading({level:4})||!0,"Mod-Alt-c":({editor:e})=>e.commands.toggleCodeBlock()||!0,"Mod-Shift-7":({editor:e})=>e.commands.toggleOrderedList()||!0,"Mod-Shift-8":({editor:e})=>e.commands.toggleBulletList()||!0,"Mod-Shift-9":({editor:e})=>e.commands.toggleTaskList()||!0,"Mod-Shift-6":({editor:e})=>e.commands.toggleDetails()||!0,"Mod-a":({editor:e})=>Lu(e),"Mod-z":({editor:e})=>e.commands.undo()||!0,"Mod-Shift-z":({editor:e})=>e.commands.redo()||!0,"Mod-Enter":({editor:e})=>e.submit(),"Ctrl-Enter":({editor:e})=>e.submit(),Tab:({editor:e})=>kl(e,1),"Shift-Tab":({editor:e})=>kl(e,-1),Escape:({editor:e})=>e.commands.selectBlocks()||e.commands.blur(),"Ctrl-Space":({editor:e})=>e.suggestion.open()};return ie&&(o["Alt-Escape"]=({editor:e})=>e.suggestion.open()),ie||(o["Ctrl-y"]=({editor:e})=>e.commands.redo()||!0),{name:"defaultKeymap",keymap:o}}function kl(o,e){return o.isActive("table")?o.run(t=>hi(t,e)):o.isActive("codeBlock")?o.run(t=>ln(t,e)):e===1?o.commands.indent():o.commands.outdent(),!0}function Lu(o){let{doc:e,selection:t}=o.state,{anchor:n,focus:i}=t;if(n.blockId===i.blockId&&de(n.cell,i.cell)){let r=N(e,i.blockId),s=i.cell||r.type==="code"?F(r,i.cell):null;if(s){let l=B(s);if(Math.min(n.offset,i.offset)!==0||Math.max(n.offset,i.offset)!==l)return o.setSelection({anchor:{...i,offset:0},focus:{...i,offset:l}}),!0}}return o.commands.selectAll()}var xn="mbe-source";function Bu(o){return{blocks:[Ee("",o,xn)]}}function So(o){return o.blocks.length===1&&o.blocks[0].id===xn}function K(o){return I(o.blocks[0].content)}function vl(o){return{blockId:xn,offset:o}}function Fe(o,e,t=e){return{doc:Bu(o),selection:{anchor:vl(vn(e,o)),focus:vl(vn(t,o))},storedMarks:null}}function vn(o,e){return Math.max(0,Math.min(o,e.length))}function ne(o){let e=o.selection.anchor.offset,t=o.selection.focus.offset;return{from:Math.min(e,t),to:Math.max(e,t)}}function Be(o,e,t,n,i,r=i){let s=K(o.doc);return Fe(s.slice(0,e)+n+s.slice(t),i,r)}function Ae(o,e){let{from:t,to:n}=ne(o);return Be(o,t,n,e,t+e.length)}function To(o,e,t,n,i){let r=K(o.doc),s=vn(e,r),l=t;if(n&&(s>0&&r[s-1]!==`
77
+ `}`),b+=k.child!==null?h(k.child):tr(Pe(k.blocks.map(Mt),i),"> ",">")}),c[c.length-1].child===v&&(b+=u.slice(d.children[v].to,a.to)),{group:a,blocks:l,text:b}}function Eu(o,e){return o.type==="listItem"&&e.type==="listItem"&&o.listType==="task"&&e.listType==="task"&&o.id===e.id&&o.indent===e.indent&&o.content===e.content}function gl(o){return o.replace(/\s+/g," ").trim()}function bt(o,e){return Le(o,e,!1).doc}var Mu=["--mbe-font","--mbe-mono","--mbe-text","--mbe-muted","--mbe-bg","--mbe-popup-bg","--mbe-popup-border","--mbe-popup-shadow","--mbe-hover","--mbe-accent","--mbe-danger","--mbe-radius","--mbe-popup-z"],or=new WeakMap;function ir(o,e){e?or.set(o,e):or.delete(o)}function Cu(o){return or.get(o)??o.closest('dialog[open], [aria-modal="true"]')??o.ownerDocument.body}function $t(o,e){let t=Cu(e);o.parentElement!==t&&t.appendChild(o),o.style.left="0px",o.style.top="0px";let n=o.getBoundingClientRect();return{x:n.left,y:n.top}}function xo(o){let e=o.visualViewport;return e?{left:e.offsetLeft,top:e.offsetTop,width:e.width,height:e.height}:{left:0,top:0,width:o.innerWidth,height:o.innerHeight}}var ie=typeof navigator<"u"&&/Mac|iP(hone|ad|od)/.test(navigator.platform),bl=typeof navigator<"u"&&/AppleWebKit/.test(navigator.userAgent)&&!/Chrome|Chromium|CriOS|Edg|Android/.test(navigator.userAgent),Ft=()=>typeof matchMedia=="function"&&matchMedia("(pointer: coarse)").matches,we=class{constructor(e,t){this.owner=e;let n=e.ownerDocument;this.el=n.createElement("div"),this.el.className=`mbe-ui ${t}`,this.el.hidden=!0,this.el.addEventListener("mousedown",i=>{i.target instanceof HTMLInputElement||i.preventDefault()})}el;open=!1;placed="below";get isOpen(){return this.open}get side(){return this.placed}show(e,t="below",n=6,i="start"){let r=this.owner.ownerDocument;this.open||this.copyTheme(),this.el.hidden=!1,this.open=!0;let s=$t(this.el,this.owner),l=r.defaultView,a=xo(l),d=this.el.scrollTop;this.el.style.maxHeight="";let u=this.el.offsetWidth,c=this.el.offsetHeight,h=a.top+a.height-8-(e.bottom+n),f=e.top-n-8-a.top,p=t;p==="below"&&c>h&&f>h?p="above":p==="above"&&c>f&&h>f&&(p="below");let m=p==="below"?h:f;if(c>m){let b=l.getComputedStyle(this.el),w=b.boxSizing==="border-box"?0:["paddingTop","paddingBottom","borderTopWidth","borderBottomWidth"].reduce((k,S)=>k+parseFloat(b[S]),0);this.el.style.maxHeight=`${Math.max(Math.floor(m-w),80)}px`,c=this.el.offsetHeight,this.el.scrollTop=d}this.placed=p;let y=p==="below"?e.bottom+n:e.top-c-n,g=i==="end"?(e.right??e.left)-u:e.left,v=Math.max(a.left+8,Math.min(g,a.left+a.width-u-8));this.el.style.left=`${Math.round(v-s.x)}px`,this.el.style.top=`${Math.round(y-s.y)}px`}showBeside(e,t,n,i=4){let r=this.owner.ownerDocument;this.open||this.copyTheme(),this.el.hidden=!1,this.open=!0;let s=$t(this.el,this.owner),l=xo(r.defaultView);this.el.style.maxHeight="";let a=this.el.offsetWidth,d=this.el.offsetHeight,u=e.right+i;u+a>l.left+l.width-8&&e.left-i-a>=l.left+8&&(u=e.left-i-a),u=Math.max(l.left+8,Math.min(u,l.left+l.width-a-8));let c=Math.max(l.top+8,Math.min(t-n,l.top+l.height-d-8));this.el.style.left=`${Math.round(u-s.x)}px`,this.el.style.top=`${Math.round(c-s.y)}px`}hide(){this.open&&(this.open=!1,this.el.hidden=!0)}destroy(){this.el.remove()}copyTheme(){let e=this.owner.ownerDocument.defaultView.getComputedStyle(this.owner);for(let t of Mu){let n=e.getPropertyValue(t);n&&this.el.style.setProperty(t,n)}this.el.style.colorScheme=e.colorScheme}},Iu=0,Xe=class o{constructor(e,t,n="listbox"){this.owner=e;this.className=t;this.popup=new we(e,`mbe-menu ${t}`),this.popup.el.setAttribute("role",n),this.popup.el.id=this.id}popup;items=[];index=0;id=`mbe-menu-${++Iu}`;child=null;childIndex=-1;checkIcon;submenuIcon;onPicked=null;onHighlight=null;get el(){return this.popup.el}get isOpen(){return this.popup.isOpen}get activeDescendant(){return this.child?.isOpen?this.child.activeDescendant:this.items.length?`${this.id}-${this.index}`:null}get submenu(){return this.child?.isOpen?this.child:null}contains(e){return this.el.contains(e)||!!this.child?.contains(e)}openSubmenu(e=this.index){let t=this.items[e],n=this.el.querySelector(`#${this.id}-${e}`);if(!t?.submenu||!n)return!1;if(this.child?.isOpen&&this.childIndex===e)return!0;this.highlight(e),this.child||(this.child=new o(this.owner,`mbe-submenu ${this.className}-submenu`,"menu"),this.child.onPicked=()=>{this.closeSubmenu(),this.onPicked?.()},this.child.onHighlight=()=>this.onHighlight?.(this.index)),this.child.checkIcon=this.checkIcon,this.child.el.setAttribute("aria-label",t.submenu.title??t.label),this.child.setSections([t.submenu]);let i=t.submenu.items.find(d=>d.checked);i&&this.child.highlightId(i.id),this.childIndex=e,n.setAttribute("aria-expanded","true");let r=this.el.getBoundingClientRect(),s=n.getBoundingClientRect().top;this.child.popup.showBeside(r,s,0);let l=this.child.el.querySelector(".mbe-menu-item"),a=l?l.getBoundingClientRect().top-this.child.el.getBoundingClientRect().top:0;return a&&this.child.popup.showBeside(r,s,a),this.onHighlight?.(this.index),!0}closeSubmenu(){this.child?.isOpen&&(this.child.hide(),this.el.querySelector(`#${this.id}-${this.childIndex}`)?.setAttribute("aria-expanded","false"),this.childIndex=-1,this.onHighlight?.(this.index))}setSections(e,t){let n=this.el.ownerDocument;this.closeSubmenu(),this.el.replaceChildren(),this.items=[],this.index=0;for(let i of e)if(i.items.length!==0){if(i.title){let r=n.createElement("div");r.className="mbe-menu-title",r.textContent=i.title,r.setAttribute("role","presentation"),this.el.appendChild(r)}for(let r of i.items){let s=this.items.length;this.items.push(r);let l=n.createElement("div");l.className="mbe-menu-item",l.id=`${this.id}-${s}`;let a=this.el.getAttribute("role")==="menu"?r.checked===void 0?"menuitem":"menuitemradio":"option";l.setAttribute("role",a),r.checked!==void 0&&l.setAttribute("aria-checked",String(r.checked)),r.keyShortcuts&&l.setAttribute("aria-keyshortcuts",r.keyShortcuts),r.danger&&l.classList.add("mbe-danger");let d=n.createElement("span");d.className="mbe-menu-icon";let u=X(n,r.icon);u&&d.appendChild(u);let c=n.createElement("span");if(c.className=r.labelClass?`mbe-menu-label ${r.labelClass}`:"mbe-menu-label",Lu(c,r.label,r.mark),l.append(d,c),r.detail){let h=n.createElement("span");h.className="mbe-menu-detail",h.textContent=r.detail,l.appendChild(h)}if(r.checked){let h=n.createElement("span");h.className="mbe-menu-check";let f=X(n,this.checkIcon);f&&h.appendChild(f),l.appendChild(h)}if(r.submenu){l.setAttribute("aria-haspopup","menu"),l.setAttribute("aria-expanded","false");let h=n.createElement("span");h.className="mbe-menu-submenu";let f=X(n,this.submenuIcon);f&&h.appendChild(f),l.appendChild(h)}l.addEventListener("mousemove",()=>{(this.index!==s||!this.child?.isOpen)&&this.highlight(s),r.submenu?this.openSubmenu(s):this.closeSubmenu()}),l.addEventListener("click",()=>this.pick(s)),this.el.appendChild(l)}}if(this.items.length===0&&t){let i=n.createElement("div");i.className="mbe-menu-empty",i.textContent=t,this.el.appendChild(i)}this.highlight(0)}setMessage(e,t){let i=this.el.ownerDocument.createElement("div");i.className=t,i.textContent=e,this.el.replaceChildren(i),this.items=[],this.index=0}set busy(e){e?this.el.setAttribute("aria-busy","true"):this.el.removeAttribute("aria-busy")}get count(){return this.items.length}get activeId(){return this.items[this.index]?.id??null}highlightId(e){let t=this.items.findIndex(n=>n.id===e);return t<0?!1:(this.highlight(t),!0)}page(e){let t=this.el.querySelector(".mbe-menu-item"),n=t&&t.offsetHeight>0?Math.max(1,Math.floor(this.el.clientHeight/t.offsetHeight)-1):8;this.highlight(Math.max(0,Math.min(this.items.length-1,this.index+e*n)))}highlight(e){this.items.length!==0&&(this.index=(e+this.items.length)%this.items.length,this.el.querySelectorAll(".mbe-menu-item").forEach((t,n)=>{t.classList.toggle("mbe-highlighted",n===this.index),t.setAttribute("aria-selected",String(n===this.index))}),this.el.querySelector(`#${this.id}-${this.index}`)?.scrollIntoView?.({block:"nearest"}),this.onHighlight?.(this.index))}get activeIndex(){return this.items.length?this.index:-1}move(e){this.highlight(this.index+e)}pick(e=this.index){let t=this.items[e];if(t){if(t.submenu){this.openSubmenu(e);return}t.run(),this.onPicked?.()}}hide(){this.closeSubmenu(),this.popup.hide()}destroy(){this.child?.destroy(),this.popup.destroy()}};function Lu(o,e,t){let n=t?e.toLowerCase().indexOf(t.toLowerCase()):-1;if(n<0||e.toLowerCase().length!==e.length){o.textContent=e;return}let r=o.ownerDocument.createElement("mark");r.className="mbe-menu-match",r.textContent=e.slice(n,n+t.length),o.replaceChildren(e.slice(0,n),r,e.slice(n+t.length))}function yl(o,e){let t=e.trim().toLowerCase();return t?[o.label,...o.aliases??[]].map(i=>i.toLowerCase()).some(i=>i.includes(t)||i.replace(/\s+/g,"").includes(t.replace(/\s+/g,""))):!0}function rr(){let o={"Mod-b":({editor:e})=>e.commands.toggleBold(),"Mod-i":({editor:e})=>e.commands.toggleItalic(),"Mod-e":({editor:e})=>e.commands.toggleCode(),"Mod-Shift-x":({editor:e})=>e.commands.toggleStrike(),"Mod-Shift-s":({editor:e})=>e.commands.toggleStrike(),"Mod-k":({editor:e})=>e.openLinkPopover(),"Mod-Alt-0":({editor:e})=>e.commands.setParagraph()||!0,"Mod-Alt-1":({editor:e})=>e.commands.toggleHeading({level:1})||!0,"Mod-Alt-2":({editor:e})=>e.commands.toggleHeading({level:2})||!0,"Mod-Alt-3":({editor:e})=>e.commands.toggleHeading({level:3})||!0,"Mod-Alt-4":({editor:e})=>e.commands.toggleHeading({level:4})||!0,"Mod-Alt-c":({editor:e})=>e.commands.toggleCodeBlock()||!0,"Mod-Shift-7":({editor:e})=>e.commands.toggleOrderedList()||!0,"Mod-Shift-8":({editor:e})=>e.commands.toggleBulletList()||!0,"Mod-Shift-9":({editor:e})=>e.commands.toggleTaskList()||!0,"Mod-Shift-6":({editor:e})=>e.commands.toggleDetails()||!0,"Mod-a":({editor:e})=>Bu(e),"Mod-z":({editor:e})=>e.commands.undo()||!0,"Mod-Shift-z":({editor:e})=>e.commands.redo()||!0,"Mod-Enter":({editor:e})=>e.submit(),"Ctrl-Enter":({editor:e})=>e.submit(),Tab:({editor:e})=>kl(e,1),"Shift-Tab":({editor:e})=>kl(e,-1),Escape:({editor:e})=>e.commands.selectBlocks()||e.commands.blur(),"Ctrl-Space":({editor:e})=>e.suggestion.open()};return ie&&(o["Alt-Escape"]=({editor:e})=>e.suggestion.open()),ie||(o["Ctrl-y"]=({editor:e})=>e.commands.redo()||!0),{name:"defaultKeymap",keymap:o}}function kl(o,e){return o.isActive("table")?o.run(t=>hi(t,e)):o.isActive("codeBlock")?o.run(t=>ln(t,e)):e===1?o.commands.indent():o.commands.outdent(),!0}function Bu(o){let{doc:e,selection:t}=o.state,{anchor:n,focus:i}=t;if(n.blockId===i.blockId&&de(n.cell,i.cell)){let r=N(e,i.blockId),s=i.cell||r.type==="code"?F(r,i.cell):null;if(s){let l=B(s);if(Math.min(n.offset,i.offset)!==0||Math.max(n.offset,i.offset)!==l)return o.setSelection({anchor:{...i,offset:0},focus:{...i,offset:l}}),!0}}return o.commands.selectAll()}var xn="mbe-source";function Au(o){return{blocks:[Ee("",o,xn)]}}function So(o){return o.blocks.length===1&&o.blocks[0].id===xn}function K(o){return I(o.blocks[0].content)}function vl(o){return{blockId:xn,offset:o}}function Fe(o,e,t=e){return{doc:Au(o),selection:{anchor:vl(vn(e,o)),focus:vl(vn(t,o))},storedMarks:null}}function vn(o,e){return Math.max(0,Math.min(o,e.length))}function ne(o){let e=o.selection.anchor.offset,t=o.selection.focus.offset;return{from:Math.min(e,t),to:Math.max(e,t)}}function Be(o,e,t,n,i,r=i){let s=K(o.doc);return Fe(s.slice(0,e)+n+s.slice(t),i,r)}function Ae(o,e){let{from:t,to:n}=ne(o);return Be(o,t,n,e,t+e.length)}function To(o,e,t,n,i){let r=K(o.doc),s=vn(e,r),l=t;if(n&&(s>0&&r[s-1]!==`
78
78
  `&&(l=`
79
79
  `+l),s<r.length&&r[s]!==`
80
80
  `&&!l.endsWith(`
81
81
  `)&&(l+=`
82
82
  `)),i){let d=u=>u>=s?u+l.length:u;return Fe(r.slice(0,s)+l+r.slice(s),d(o.selection.anchor.offset),d(o.selection.focus.offset))}let a=s+l.length-(n&&l.endsWith(`
83
83
  `)&&!t.endsWith(`
84
- `)?1:0);return Fe(r.slice(0,s)+l+r.slice(s),a)}function ar(o,e){let{from:t,to:n}=ne(o);if(t!==n)return Be(o,t,n,"",t);if(t===0)return null;let i=e(K(o.doc),t);return Be(o,i,t,"",i)}function cr(o,e){let{from:t,to:n}=ne(o);if(t!==n)return Be(o,t,n,"",t);let i=K(o.doc);return t===i.length?null:Be(o,t,e(i,t),"",t)}var Ml=/^(?: {0,3}>[ \t]?)*/,Cl=/^(?:([-*+])|(\d{1,9})([.)]))(?=[ \t]|$)/,Au=/^([-*_])[ \t]*(?:\1[ \t]*){2,}$/,sr=/^(`{3,}|~{3,})(.*)$/;function Il(o,e=0){let t=e;for(let n of o)t=n===" "?t+4-t%4:t+1;return t-e}function Nu(o,e,t){if(Au.test(o))return null;let n=Cl.exec(o);if(!n)return null;let i=n[0].length,r=/^[ \t]*/.exec(o.slice(i))[0],s=Il(r,t+i);i+=r.length;let l=-1;return r&&/^\[[ xX]\](?=[ \t]|$)/.test(o.slice(i))&&(l=e+i,i+=3,i+=/^[ \t]*/.exec(o.slice(i))[0].length),{ordered:!n[1],char:n[1]??n[3],number:n[2]?Number(n[2]):0,from:e,to:e+n[0].length,spaced:r.length>0,box:l,content:e+i,column:t+n[0].length+(s>=1&&s<=4?s:1)}}function Ye(o){let e=[],t=null;for(let n=0;;){let i=o.indexOf(`
85
- `,n),r=i===-1?o.length:i,s=o.slice(n,r),l=Ml.exec(s)[0],a=/^[ \t]*/.exec(s.slice(l.length))[0],d=n+l.length+a.length,u=s.slice(l.length+a.length),c=Il(a),h=t?.line??-1,f=sr.exec(u);if(t?f&&f[1][0]===t.char&&f[1].length>=t.length&&f[2].trim()===""&&(t=null):f&&!(f[1][0]==="`"&&f[2].includes("`"))&&(t={char:f[1][0],length:f[1].length,line:e.length},h=e.length),e.push({from:n,to:r,depth:l.split(">").length-1,quoteEnd:n+l.length,indent:c,indentEnd:d,blank:u.trim()==="",item:h!==-1?null:Nu(u,d,c),fence:h}),i===-1)return e;n=i+1}}function Ll(o,e){let t=o.indexOf(`
84
+ `)?1:0);return Fe(r.slice(0,s)+l+r.slice(s),a)}function ar(o,e){let{from:t,to:n}=ne(o);if(t!==n)return Be(o,t,n,"",t);if(t===0)return null;let i=e(K(o.doc),t);return Be(o,i,t,"",i)}function cr(o,e){let{from:t,to:n}=ne(o);if(t!==n)return Be(o,t,n,"",t);let i=K(o.doc);return t===i.length?null:Be(o,t,e(i,t),"",t)}var Ml=/^(?: {0,3}>[ \t]?)*/,Cl=/^(?:([-*+])|(\d{1,9})([.)]))(?=[ \t]|$)/,Nu=/^([-*_])[ \t]*(?:\1[ \t]*){2,}$/,sr=/^(`{3,}|~{3,})(.*)$/;function Il(o,e=0){let t=e;for(let n of o)t=n===" "?t+4-t%4:t+1;return t-e}function Ru(o,e,t){if(Nu.test(o))return null;let n=Cl.exec(o);if(!n)return null;let i=n[0].length,r=/^[ \t]*/.exec(o.slice(i))[0],s=Il(r,t+i);i+=r.length;let l=-1;return r&&/^\[[ xX]\](?=[ \t]|$)/.test(o.slice(i))&&(l=e+i,i+=3,i+=/^[ \t]*/.exec(o.slice(i))[0].length),{ordered:!n[1],char:n[1]??n[3],number:n[2]?Number(n[2]):0,from:e,to:e+n[0].length,spaced:r.length>0,box:l,content:e+i,column:t+n[0].length+(s>=1&&s<=4?s:1)}}function Ye(o){let e=[],t=null;for(let n=0;;){let i=o.indexOf(`
85
+ `,n),r=i===-1?o.length:i,s=o.slice(n,r),l=Ml.exec(s)[0],a=/^[ \t]*/.exec(s.slice(l.length))[0],d=n+l.length+a.length,u=s.slice(l.length+a.length),c=Il(a),h=t?.line??-1,f=sr.exec(u);if(t?f&&f[1][0]===t.char&&f[1].length>=t.length&&f[2].trim()===""&&(t=null):f&&!(f[1][0]==="`"&&f[2].includes("`"))&&(t={char:f[1][0],length:f[1].length,line:e.length},h=e.length),e.push({from:n,to:r,depth:l.split(">").length-1,quoteEnd:n+l.length,indent:c,indentEnd:d,blank:u.trim()==="",item:h!==-1?null:Ru(u,d,c),fence:h}),i===-1)return e;n=i+1}}function Ll(o,e){let t=o.indexOf(`
86
86
  `,e),n=o.slice(o.lastIndexOf(`
87
- `,e-1)+1,t===-1?o.length:t);return Cl.test(n.replace(Ml,"").trimStart())}function qt(o,e){let t=0;for(;t+1<o.length&&o[t+1].from<=e;)t++;return t}function Ru(o,e){let t=o[e];for(let n=e-1;n>=0;n--){let i=o[n];if(!i.blank){if(i.depth!==t.depth)return-1;if(!(i.indent>t.indent))return i.item&&i.indent===t.indent?n:-1}}return-1}function Bl(o,e){let t=o[e];for(let n=e-1;n>=0;n--){let i=o[n];if(!i.blank){if(i.depth!==t.depth)return-1;if(i.indent<t.indent)return i.item?n:-1}}return-1}function Du(o,e){let t=o[e],n=t.item,i=s=>s.item!==null&&s.indent===t.indent&&s.item.ordered===n.ordered&&s.item.char===n.char,r=[e];for(let s of[-1,1])for(let l=e+s;l>=0&&l<o.length;l+=s){let a=o[l];if(!a.blank){if(a.depth!==t.depth)break;if(!(a.indent>t.indent)){if(!i(a))break;s<0?r.unshift(l):r.push(l)}}}return r}function Ou(o,e,t){let n=[],i=new Set;for(let r of e){if(!o[r]?.item?.ordered)continue;let s=Du(o,r);if(i.has(s[0]))continue;i.add(s[0]);let l=s.filter(u=>!t.has(u)).map(u=>o[u].item.number),a=l.length>=2&&l.every(u=>u===l[0]),d=t.has(s[0])?1:o[s[0]].item.number;s.forEach((u,c)=>{let h=o[u].item,f=a?t.has(u)?l[0]:h.number:d+c;f!==h.number&&n.push({from:h.from,to:h.to-1,insert:String(f)})})}return n}function $e(o,e){let t=0;for(let n of e){if(n.from>o||n.from===o&&n.to>n.from)break;if(o>=n.to)t+=n.insert.length-(n.to-n.from);else return n.from+t+Math.min(o-n.from,n.insert.length)}return o+t}function xl(o,e){let t="",n=0;for(let i of e)t+=o.slice(n,i.from)+i.insert,n=i.to;return t+o.slice(n)}function yt(o,e,t,n,i,r,s=!1){e.sort((h,f)=>h.from-f.from);let l=xl(o,e),a=s?t:$e(t,e),d=s?n:$e(n,e);if(i.length===0)return Fe(l,a,d);let u=Ye(l),c=Ou(u,i.map(h=>qt(u,h)),new Set(r.map(h=>qt(u,h))));return c.length&&(l=xl(l,c),a=$e(a,c),d=$e(d,c)),Fe(l,a,d)}function Al(o,e,t,n,i,r,s){let l=e[t],a=n;for(let f=n+1;f<e.length;f++){let p=e[f];if(!p.blank){if(p.depth!==l.depth||p.indent<=e[n].indent)break;a=f}}let d=[];for(let f=t;f<=a;f++){let p=e[f];p.blank||p.depth!==l.depth||d.push({from:p.quoteEnd,to:p.indentEnd,insert:" ".repeat(Math.max(0,p.indent+i))})}let u=-1;for(let f=a+1;f<e.length;f++){let p=e[f];if(!p.blank){p.depth===l.depth&&p.indent===l.indent&&p.item&&(u=f);break}}let c=$e(l.indentEnd,d),h=u===-1?[]:[$e(e[u].indentEnd,d)];return yt(o,d,r,s,[c,...h],[c,...i<0?h:[]])}function Nl(o){let{from:e,to:t}=ne(o),n=K(o.doc),i=n.slice(0,e)+n.slice(t);if(!Ll(i,e))return Ae(o,`
87
+ `,e-1)+1,t===-1?o.length:t);return Cl.test(n.replace(Ml,"").trimStart())}function qt(o,e){let t=0;for(;t+1<o.length&&o[t+1].from<=e;)t++;return t}function Du(o,e){let t=o[e];for(let n=e-1;n>=0;n--){let i=o[n];if(!i.blank){if(i.depth!==t.depth)return-1;if(!(i.indent>t.indent))return i.item&&i.indent===t.indent?n:-1}}return-1}function Bl(o,e){let t=o[e];for(let n=e-1;n>=0;n--){let i=o[n];if(!i.blank){if(i.depth!==t.depth)return-1;if(i.indent<t.indent)return i.item?n:-1}}return-1}function Ou(o,e){let t=o[e],n=t.item,i=s=>s.item!==null&&s.indent===t.indent&&s.item.ordered===n.ordered&&s.item.char===n.char,r=[e];for(let s of[-1,1])for(let l=e+s;l>=0&&l<o.length;l+=s){let a=o[l];if(!a.blank){if(a.depth!==t.depth)break;if(!(a.indent>t.indent)){if(!i(a))break;s<0?r.unshift(l):r.push(l)}}}return r}function Hu(o,e,t){let n=[],i=new Set;for(let r of e){if(!o[r]?.item?.ordered)continue;let s=Ou(o,r);if(i.has(s[0]))continue;i.add(s[0]);let l=s.filter(u=>!t.has(u)).map(u=>o[u].item.number),a=l.length>=2&&l.every(u=>u===l[0]),d=t.has(s[0])?1:o[s[0]].item.number;s.forEach((u,c)=>{let h=o[u].item,f=a?t.has(u)?l[0]:h.number:d+c;f!==h.number&&n.push({from:h.from,to:h.to-1,insert:String(f)})})}return n}function $e(o,e){let t=0;for(let n of e){if(n.from>o||n.from===o&&n.to>n.from)break;if(o>=n.to)t+=n.insert.length-(n.to-n.from);else return n.from+t+Math.min(o-n.from,n.insert.length)}return o+t}function xl(o,e){let t="",n=0;for(let i of e)t+=o.slice(n,i.from)+i.insert,n=i.to;return t+o.slice(n)}function yt(o,e,t,n,i,r,s=!1){e.sort((h,f)=>h.from-f.from);let l=xl(o,e),a=s?t:$e(t,e),d=s?n:$e(n,e);if(i.length===0)return Fe(l,a,d);let u=Ye(l),c=Hu(u,i.map(h=>qt(u,h)),new Set(r.map(h=>qt(u,h))));return c.length&&(l=xl(l,c),a=$e(a,c),d=$e(d,c)),Fe(l,a,d)}function Al(o,e,t,n,i,r,s){let l=e[t],a=n;for(let f=n+1;f<e.length;f++){let p=e[f];if(!p.blank){if(p.depth!==l.depth||p.indent<=e[n].indent)break;a=f}}let d=[];for(let f=t;f<=a;f++){let p=e[f];p.blank||p.depth!==l.depth||d.push({from:p.quoteEnd,to:p.indentEnd,insert:" ".repeat(Math.max(0,p.indent+i))})}let u=-1;for(let f=a+1;f<e.length;f++){let p=e[f];if(!p.blank){p.depth===l.depth&&p.indent===l.indent&&p.item&&(u=f);break}}let c=$e(l.indentEnd,d),h=u===-1?[]:[$e(e[u].indentEnd,d)];return yt(o,d,r,s,[c,...h],[c,...i<0?h:[]])}function Nl(o){let{from:e,to:t}=ne(o),n=K(o.doc),i=n.slice(0,e)+n.slice(t);if(!Ll(i,e))return Ae(o,`
88
88
  `);let r=Ye(i),s=qt(r,e),l=r[s],a=l.item;if(!a||!a.spaced||e<a.content)return Ae(o,`
89
- `);if(i.slice(a.content,l.to).trim()===""){let y=Bl(r,s);if(l.indent>0&&y!==-1)return Al(i,r,s,s,r[y].indent-l.indent,l.to,l.to);let g=r.findIndex((w,k)=>k>s&&!w.blank),x=[{from:l.quoteEnd,to:l.to,insert:""}],b=g===-1||!r[g].item?[]:[$e(r[g].indentEnd,x)];return yt(i,x,l.quoteEnd,l.quoteEnd,b,[])}let d=a.ordered?`${a.number+1}${a.char}`:a.char,u=i.slice(a.to,a.box===-1?a.content:a.box),c=a.box===-1?"":"[ ]"+(i.slice(a.box+3,a.content)||" "),h=i.slice(l.from,l.indentEnd)+d+u+c,f=e+/^[ \t]*/.exec(i.slice(e,l.to))[0].length,p=[{from:e,to:f,insert:`
90
- `+h}],m=e+1+h.length;return yt(i,p,m,m,[m],[m],!0)}function Rl(o,e){let{from:t,to:n}=ne(o),i=K(o.doc);if(!Ll(i,t))return null;let r=Ye(i),[s,l]=En(r,t,n),a=r[s];if(!a.item)return null;for(let u=s+1;u<=l;u++){let c=r[u];if(!c.blank&&(c.depth!==a.depth||!c.item&&c.indent<=a.indent))return null}let d;if(e===1){let u=Ru(r,s);if(u===-1)return o;d=r[u].item.column}else{if(a.indent===0)return o;let u=Bl(r,s);d=u===-1?0:r[u].indent}return d===a.indent?o:Al(i,r,s,l,d-a.indent,o.selection.anchor.offset,o.selection.focus.offset)}function dr(o,e){let t=0,n=Math.min(o.length,e.length);for(;t<n&&o.charCodeAt(t)===e.charCodeAt(t);)t++;let i=0;for(;i<n-t&&o.charCodeAt(o.length-1-i)===e.charCodeAt(e.length-1-i);)i++;return{from:t,toBefore:o.length-i,toAfter:e.length-i}}function Dl(o,e,t){if(e===t)return o;let{from:n,toBefore:i,toAfter:r}=dr(e,t);return o<=n?o:o>=i?o+(t.length-e.length):r}function ur(o){if(o.type==="table"||Z(o))return null;let e=F(o);return e?I(e):null}function wn(o){let e=o.source.text,t=[],n=0;for(let i of o.doc.blocks){let r=o.source.groupOf.get(i),s=ur(i),l=xs(o.source.mapOf.get(i)),a=l?o.source.mapOf.get(i):null;if(!r){t.push({start:n,end:n,text:s,segments:a,span:l});continue}let d=r.blocks[0]===i,u=d?r.from:Math.max(r.from,n);if(!d){let m=e.indexOf(`
89
+ `);if(i.slice(a.content,l.to).trim()===""){let y=Bl(r,s);if(l.indent>0&&y!==-1)return Al(i,r,s,s,r[y].indent-l.indent,l.to,l.to);let g=r.findIndex((w,k)=>k>s&&!w.blank),v=[{from:l.quoteEnd,to:l.to,insert:""}],b=g===-1||!r[g].item?[]:[$e(r[g].indentEnd,v)];return yt(i,v,l.quoteEnd,l.quoteEnd,b,[])}let d=a.ordered?`${a.number+1}${a.char}`:a.char,u=i.slice(a.to,a.box===-1?a.content:a.box),c=a.box===-1?"":"[ ]"+(i.slice(a.box+3,a.content)||" "),h=i.slice(l.from,l.indentEnd)+d+u+c,f=e+/^[ \t]*/.exec(i.slice(e,l.to))[0].length,p=[{from:e,to:f,insert:`
90
+ `+h}],m=e+1+h.length;return yt(i,p,m,m,[m],[m],!0)}function Rl(o,e){let{from:t,to:n}=ne(o),i=K(o.doc);if(!Ll(i,t))return null;let r=Ye(i),[s,l]=En(r,t,n),a=r[s];if(!a.item)return null;for(let u=s+1;u<=l;u++){let c=r[u];if(!c.blank&&(c.depth!==a.depth||!c.item&&c.indent<=a.indent))return null}let d;if(e===1){let u=Du(r,s);if(u===-1)return o;d=r[u].item.column}else{if(a.indent===0)return o;let u=Bl(r,s);d=u===-1?0:r[u].indent}return d===a.indent?o:Al(i,r,s,l,d-a.indent,o.selection.anchor.offset,o.selection.focus.offset)}function dr(o,e){let t=0,n=Math.min(o.length,e.length);for(;t<n&&o.charCodeAt(t)===e.charCodeAt(t);)t++;let i=0;for(;i<n-t&&o.charCodeAt(o.length-1-i)===e.charCodeAt(e.length-1-i);)i++;return{from:t,toBefore:o.length-i,toAfter:e.length-i}}function Dl(o,e,t){if(e===t)return o;let{from:n,toBefore:i,toAfter:r}=dr(e,t);return o<=n?o:o>=i?o+(t.length-e.length):r}function ur(o){if(o.type==="table"||Z(o))return null;let e=F(o);return e?I(e):null}function wn(o){let e=o.source.text,t=[],n=0;for(let i of o.doc.blocks){let r=o.source.groupOf.get(i),s=ur(i),l=xs(o.source.mapOf.get(i)),a=l?o.source.mapOf.get(i):null;if(!r){t.push({start:n,end:n,text:s,segments:a,span:l});continue}let d=r.blocks[0]===i,u=d?r.from:Math.max(r.from,n);if(!d){let m=e.indexOf(`
91
91
  `,u);m!==-1&&m<r.to&&(u=m+1)}let c=u,h=u;if(l)c=l.from,h=l.to;else if(s){let m=e.indexOf(s,u),y=e.indexOf(s.slice(0,Math.min(s.length,1)),u);m!==-1&&m<=r.to?c=m:y!==-1&&y<=r.to&&(c=y),h=c+s.length}else if(i.type!=="table"){let m=e.indexOf(`
92
92
  `,u);c=h=Math.min(m===-1?r.to:m,r.to)}let f=r.blocks[r.blocks.length-1]===i,p=r.to;if(!f){let m=e.indexOf(`
93
93
  `,h);p=m===-1||m>r.to?r.to:m}t.push({start:c,end:p,text:s,segments:a,span:l}),n=p}return t}function wl(o,e,t,n=wn(t)){let i=o.blocks.findIndex(c=>c.id===e.blockId),r=n[Math.max(0,Math.min(i,n.length-1))];if(!r)return 0;let s=o.blocks[i];if(!s||e.cell)return r.start;let l=ur(s);if(!l)return r.start;if(r.segments)return ks(r.segments,vn(e.offset,l));let a=l.slice(0,e.offset),d=t.source.text;if(d.startsWith(a,r.start))return r.start+a.length;let u=d.indexOf(a,r.start);return u!==-1&&u+a.length<=r.end?u+a.length:r.start}function wo(o,e,t=wn(e)){let n=e.doc.blocks,i=e.source.text,r=t.findIndex(u=>u.span!==null&&u.span.from<=o&&o<=u.span.to);if(r===-1){r=0;for(let u=0;u<t.length;u++){let c=t[u],h=e.source.groupOf.get(n[u]);if((h&&h.blocks[0]===n[u]?h.from:c.segments?i.lastIndexOf(`
94
- `,c.start-1)+1:c.start)<=o)r=u;else break}}let s=n[r],l=t[r],a=ur(s);if(s.type==="table")return{blockId:s.id,offset:0,cell:{row:0,col:0}};if(!l||!a)return{blockId:s.id,offset:0};if(l.segments)return{blockId:s.id,offset:vn(vs(l.segments,o),a)};if(o<=l.start)return{blockId:s.id,offset:0};let d=i.slice(l.start,o);return{blockId:s.id,offset:a.startsWith(d)?d.length:0}}function hr(o,e,t){let n=wn(t);return{anchor:wl(o,e.anchor,t,n),focus:wl(o,e.focus,t,n)}}function fr(o,e,t){let n=wn(t);return{anchor:wo(o,t,n),focus:wo(e,t,n)}}function Ol(o,e,t){let n=wn(t),i=o.blocks.findIndex(r=>r.id===e);return n[Math.max(0,Math.min(i,n.length-1))]?.end??t.source.text.length}var Sl=/[\p{L}\p{N}_]/u,Hl=/^(#{1,6})(?:[ \t]+|$)/,Hu=/^ {0,3}>[ \t]?/;function Tl(o,e,t){let n=0;for(;o[e-1-n]===t;)n++;return n}function El(o,e,t){let n=0;for(;o[e+n]===t;)n++;return n}function Sn(o){return[o.selection.anchor.offset,o.selection.focus.offset]}function lr(o,e,t){let[n,i]=Sn(o);return n>i?[t,e]:[e,t]}function Tn(o,e){let t=K(o.doc),{from:n,to:i}=ne(o),r=e[0];if(n===i){for(;n>0&&Sl.test(t[n-1]);)n--;for(;i<t.length&&Sl.test(t[i]);)i++;if(n===i)return Be(o,n,n,e+e,n+e.length)}else{for(;n<i&&/\s/.test(t[n]);)n++;for(;i>n&&/\s/.test(t[i-1]);)i--;if(n===i)return o}let s=Math.min(El(t,n,r),Tl(t,i,r),Math.floor((i-n-1)/2));n+=s,i-=s;let l=Tl(t,n,r),a=El(t,i,r),d=0;if(e==="`"?d=l>0&&l===a?l:0:e==="*"?d=l%2===1&&a%2===1?1:0:d=l>=2&&a>=2?2:0,d>0)return Be(o,n-d,i+d,t.slice(n,i),...lr(o,n-d,i-d));let u=e,c=e;if(e==="`"){let h=t.slice(n,i),f=0;for(let y of h.matchAll(/`+/g))f=Math.max(f,y[0].length);let p="`".repeat(f+1),m=h.startsWith("`")||h.endsWith("`")?" ":"";u=p+m,c=m+p}return Be(o,n,i,u+t.slice(n,i)+c,...lr(o,n+u.length,i+u.length))}function En(o,e,t){let n=qt(o,e),i=qt(o,t);return t>e&&i>n&&o[i].from===t&&i--,[n,i]}function Pl(o,e,t){return o.slice(e,t+1).filter(n=>n.fence===-1&&(!n.blank||e===t))}function $l(o,e){if(e.item)return e.item.content;let t=Hl.exec(o.slice(e.indentEnd,e.to));return e.indentEnd+(t?t[0].length:0)}function Pu(o,e){let t=e.item?null:Hl.exec(o.slice(e.indentEnd,e.to));return t?t[1].length:0}function pr(o,e){let t=K(o.doc),{from:n,to:i}=ne(o),r=Ye(t),s=Pl(r,...En(r,n,i));if(s.length===0)return null;let a=e>0&&s.every(u=>Pu(t,u)===e)||e===0?"":"#".repeat(e)+" ",d=s.map(u=>({from:u.indentEnd,to:$l(t,u),insert:a})).filter(u=>u.to>u.from||u.insert);return d.length?yt(t,d,...Sn(o),[],[]):null}function Eo(o,e){let t=K(o.doc),{from:n,to:i}=ne(o),r=Ye(t),s=Pl(r,...En(r,n,i));if(s.length===0)return null;let l=p=>!!p.item&&(e==="ordered"?p.item.ordered:e==="task"?p.item.box!==-1:!p.item.ordered&&p.item.box===-1),a=s.every(l),d=a?"":e==="bullet"?"- ":e==="ordered"?"1. ":"- [ ] ",u=a?s:s.filter(p=>!l(p)),c=u.map(p=>({from:p.indentEnd,to:$l(t,p),insert:d})),h=s.map(p=>$e(p.indentEnd,c)),f=e==="ordered"&&!a?u.map(p=>$e(p.indentEnd,c)):[];return yt(t,c,...Sn(o),h,f)}function Fl(o){let e=K(o.doc),{from:t,to:n}=ne(o),i=Ye(e),[r,s]=En(i,t,n),l=i.slice(r,s+1),d=l.some(u=>!u.blank)&&l.every(u=>u.blank||u.depth>0)?l.flatMap(u=>{let c=Hu.exec(e.slice(u.from,u.to));return c?[{from:u.from,to:u.from+c[0].length,insert:""}]:[]}):l.map(u=>({from:u.from,to:u.from,insert:u.blank?">":"> "}));return d.length?yt(e,d,...Sn(o),[],[]):null}function ql(o){let e=K(o.doc),{from:t,to:n}=ne(o),i=Ye(e),[r,s]=En(i,t,n),l=i.slice(r,s+1).find(f=>f.fence!==-1);if(l){let f=i[l.fence],p=l.fence;for(;p+1<i.length&&i[p+1].fence===l.fence;)p++;let m=[{from:f.from,to:Math.min(f.to+1,e.length),insert:""}],y=sr.exec(e.slice(f.indentEnd,f.to))[1],g=i[p],x=sr.exec(e.slice(g.indentEnd,g.to));return p>l.fence&&x&&x[1][0]===y[0]&&x[1].length>=y.length&&x[2].trim()===""&&m.push({from:g.from-1,to:g.to,insert:""}),yt(e,m,...Sn(o),[],[])}let a=i[r],d=i[s],u=e.slice(a.from,a.quoteEnd);if(r===s&&a.blank)return Be(o,a.quoteEnd,a.to,"```\n"+u+`
94
+ `,c.start-1)+1:c.start)<=o)r=u;else break}}let s=n[r],l=t[r],a=ur(s);if(s.type==="table")return{blockId:s.id,offset:0,cell:{row:0,col:0}};if(!l||!a)return{blockId:s.id,offset:0};if(l.segments)return{blockId:s.id,offset:vn(vs(l.segments,o),a)};if(o<=l.start)return{blockId:s.id,offset:0};let d=i.slice(l.start,o);return{blockId:s.id,offset:a.startsWith(d)?d.length:0}}function hr(o,e,t){let n=wn(t);return{anchor:wl(o,e.anchor,t,n),focus:wl(o,e.focus,t,n)}}function fr(o,e,t){let n=wn(t);return{anchor:wo(o,t,n),focus:wo(e,t,n)}}function Ol(o,e,t){let n=wn(t),i=o.blocks.findIndex(r=>r.id===e);return n[Math.max(0,Math.min(i,n.length-1))]?.end??t.source.text.length}var Sl=/[\p{L}\p{N}_]/u,Hl=/^(#{1,6})(?:[ \t]+|$)/,Pu=/^ {0,3}>[ \t]?/;function Tl(o,e,t){let n=0;for(;o[e-1-n]===t;)n++;return n}function El(o,e,t){let n=0;for(;o[e+n]===t;)n++;return n}function Sn(o){return[o.selection.anchor.offset,o.selection.focus.offset]}function lr(o,e,t){let[n,i]=Sn(o);return n>i?[t,e]:[e,t]}function Tn(o,e){let t=K(o.doc),{from:n,to:i}=ne(o),r=e[0];if(n===i){for(;n>0&&Sl.test(t[n-1]);)n--;for(;i<t.length&&Sl.test(t[i]);)i++;if(n===i)return Be(o,n,n,e+e,n+e.length)}else{for(;n<i&&/\s/.test(t[n]);)n++;for(;i>n&&/\s/.test(t[i-1]);)i--;if(n===i)return o}let s=Math.min(El(t,n,r),Tl(t,i,r),Math.floor((i-n-1)/2));n+=s,i-=s;let l=Tl(t,n,r),a=El(t,i,r),d=0;if(e==="`"?d=l>0&&l===a?l:0:e==="*"?d=l%2===1&&a%2===1?1:0:d=l>=2&&a>=2?2:0,d>0)return Be(o,n-d,i+d,t.slice(n,i),...lr(o,n-d,i-d));let u=e,c=e;if(e==="`"){let h=t.slice(n,i),f=0;for(let y of h.matchAll(/`+/g))f=Math.max(f,y[0].length);let p="`".repeat(f+1),m=h.startsWith("`")||h.endsWith("`")?" ":"";u=p+m,c=m+p}return Be(o,n,i,u+t.slice(n,i)+c,...lr(o,n+u.length,i+u.length))}function En(o,e,t){let n=qt(o,e),i=qt(o,t);return t>e&&i>n&&o[i].from===t&&i--,[n,i]}function Pl(o,e,t){return o.slice(e,t+1).filter(n=>n.fence===-1&&(!n.blank||e===t))}function $l(o,e){if(e.item)return e.item.content;let t=Hl.exec(o.slice(e.indentEnd,e.to));return e.indentEnd+(t?t[0].length:0)}function $u(o,e){let t=e.item?null:Hl.exec(o.slice(e.indentEnd,e.to));return t?t[1].length:0}function pr(o,e){let t=K(o.doc),{from:n,to:i}=ne(o),r=Ye(t),s=Pl(r,...En(r,n,i));if(s.length===0)return null;let a=e>0&&s.every(u=>$u(t,u)===e)||e===0?"":"#".repeat(e)+" ",d=s.map(u=>({from:u.indentEnd,to:$l(t,u),insert:a})).filter(u=>u.to>u.from||u.insert);return d.length?yt(t,d,...Sn(o),[],[]):null}function Eo(o,e){let t=K(o.doc),{from:n,to:i}=ne(o),r=Ye(t),s=Pl(r,...En(r,n,i));if(s.length===0)return null;let l=p=>!!p.item&&(e==="ordered"?p.item.ordered:e==="task"?p.item.box!==-1:!p.item.ordered&&p.item.box===-1),a=s.every(l),d=a?"":e==="bullet"?"- ":e==="ordered"?"1. ":"- [ ] ",u=a?s:s.filter(p=>!l(p)),c=u.map(p=>({from:p.indentEnd,to:$l(t,p),insert:d})),h=s.map(p=>$e(p.indentEnd,c)),f=e==="ordered"&&!a?u.map(p=>$e(p.indentEnd,c)):[];return yt(t,c,...Sn(o),h,f)}function Fl(o){let e=K(o.doc),{from:t,to:n}=ne(o),i=Ye(e),[r,s]=En(i,t,n),l=i.slice(r,s+1),d=l.some(u=>!u.blank)&&l.every(u=>u.blank||u.depth>0)?l.flatMap(u=>{let c=Pu.exec(e.slice(u.from,u.to));return c?[{from:u.from,to:u.from+c[0].length,insert:""}]:[]}):l.map(u=>({from:u.from,to:u.from,insert:u.blank?">":"> "}));return d.length?yt(e,d,...Sn(o),[],[]):null}function ql(o){let e=K(o.doc),{from:t,to:n}=ne(o),i=Ye(e),[r,s]=En(i,t,n),l=i.slice(r,s+1).find(f=>f.fence!==-1);if(l){let f=i[l.fence],p=l.fence;for(;p+1<i.length&&i[p+1].fence===l.fence;)p++;let m=[{from:f.from,to:Math.min(f.to+1,e.length),insert:""}],y=sr.exec(e.slice(f.indentEnd,f.to))[1],g=i[p],v=sr.exec(e.slice(g.indentEnd,g.to));return p>l.fence&&v&&v[1][0]===y[0]&&v[1].length>=y.length&&v[2].trim()===""&&m.push({from:g.from-1,to:g.to,insert:""}),yt(e,m,...Sn(o),[],[])}let a=i[r],d=i[s],u=e.slice(a.from,a.quoteEnd);if(r===s&&a.blank)return Be(o,a.quoteEnd,a.to,"```\n"+u+`
95
95
  `+u+"```",a.quoteEnd+4+u.length);let c=u+"```\n",h=`
96
96
  `+e.slice(d.from,d.quoteEnd)+"```";return Be(o,a.from,d.to,c+e.slice(a.from,d.to)+h,...lr(o,t+c.length,n+c.length))}function _l(o,e){let{from:t,to:n}=ne(o);return t===n?null:Ae(o,`[${K(o.doc).slice(t,n)}](${e})`)}function Kl(o){let e=K(o.doc),t=Ye(e);return t[qt(t,ne(o).from)].fence!==-1}function Vl(o,e,t,n){let i=e??o;if(!i||o&&n&&(o.bottom<=n.top||o.top>=n.bottom||o.right<n.left||o.left>n.right))return null;let r=o&&e&&Math.abs(o.top-e.top)<Math.max(1,Math.min(o.bottom-o.top,e.bottom-e.top)/2),s=o&&(r||!e)?o:i,l=t?s.right:s.left;return{rect:{left:l,right:l,top:i.top,bottom:i.bottom},align:t?"end":"start"}}function Ul(o){let e=o.ownerDocument.defaultView,t={left:0,top:0,right:e.innerWidth,bottom:e.innerHeight},n=o.ownerDocument.documentElement;for(let i=o;i&&i!==n&&i!==o.ownerDocument.body;i=i.parentElement){let r=e.getComputedStyle(i);if(r.overflowX==="visible"&&r.overflowY==="visible")continue;let s=i.getBoundingClientRect();t={left:Math.max(t.left,s.left),top:Math.max(t.top,s.top),right:Math.min(t.right,s.right),bottom:Math.min(t.bottom,s.bottom)}}return t}function mr({allowSpaces:o=!1,allowAnywhere:e=!1,maxLength:t=30}={}){let n=o?/\s\s|\n/:/\s/;return({text:i,caret:r,triggers:s})=>{let l=i.lastIndexOf(`
97
- `,r-1)+1,a=Math.max(0,...s.map(u=>u.length)),d=Math.max(l,r-t-a);for(let u=r-1;u>=d;u--){let c=Mn(i,u,s,r);if(!c)continue;let h=i.slice(u+c.length,r);if(h.length>t||n.test(h))return null;let f=i[u-1];if(!e&&f!==void 0&&!/\s/.test(f))continue;let p=r;if(!o)for(;p<i.length&&!/\s/.test(i[p]);)p++;return{from:u,to:p,query:h}}return null}}var Fu=/^[\p{M}\u200c\u200d\ufe00-\ufe0f\u{e0100}-\u{e01ef}]/u;function qu(o,{probe:e="a",maxLength:t=30}={}){return({text:n,caret:i,triggers:r})=>{let s=n.codePointAt(i);if(s!==void 0&&Fu.test(String.fromCodePoint(s)))return null;let l=n,a=r[0];if(a)for(let m of r)m!==a&&m.length===a.length&&(l=l.split(m).join(a));let d=l.slice(0,i)+e+l.slice(i),u=n.lastIndexOf(`
97
+ `,r-1)+1,a=Math.max(0,...s.map(u=>u.length)),d=Math.max(l,r-t-a);for(let u=r-1;u>=d;u--){let c=Mn(i,u,s,r);if(!c)continue;let h=i.slice(u+c.length,r);if(h.length>t||n.test(h))return null;let f=i[u-1];if(!e&&f!==void 0&&!/\s/.test(f))continue;let p=r;if(!o)for(;p<i.length&&!/\s/.test(i[p]);)p++;return{from:u,to:p,query:h}}return null}}var qu=/^[\p{M}\u200c\u200d\ufe00-\ufe0f\u{e0100}-\u{e01ef}]/u;function _u(o,{probe:e="a",maxLength:t=30}={}){return({text:n,caret:i,triggers:r})=>{let s=n.codePointAt(i);if(s!==void 0&&qu.test(String.fromCodePoint(s)))return null;let l=n,a=r[0];if(a)for(let m of r)m!==a&&m.length===a.length&&(l=l.split(m).join(a));let d=l.slice(0,i)+e+l.slice(i),u=n.lastIndexOf(`
98
98
  `,i-1)+1,c=n.indexOf(`
99
- `,i);c<0&&(c=n.length);let h=t+16,f=Math.max(u,i-h);for(;f>u&&!/\s/.test(n[f-1]);)f--;let p=Math.min(c+e.length,i+e.length+h);for(let m of o(d,f,p)){if(m.from>=i||m.to<i+e.length)continue;let y=Mn(n,m.from,r,i);if(!y)return null;let g=n.slice(m.from+y.length,i);return g.length>t?null:{from:m.from,to:m.to-e.length,query:g}}return null}}function Mn(o,e,t,n=o.length){let i=null;for(let r of t)r&&e+r.length<=n&&o.startsWith(r,e)&&(!i||r.length>i.length)&&(i=r);return i}function zl(o,e){let t=0;for(let n of o){let i=t+n.text.length;if(e<i)return ct(n);t=i}return!1}var Mo=class{request=0;controller=null;debounceTimer=null;loadingTimer=null;waiting=!1;get pending(){return this.waiting}run(e,t,n=0){this.cancel();let i=this.request;this.waiting=!0,this.loadingTimer=setTimeout(()=>{this.loadingTimer=null,i===this.request&&t.loading()},300);let r=l=>{i===this.request&&(this.settle(),t.show(l))},s=()=>{this.debounceTimer=null;let l=new AbortController;this.controller=l;let a;try{a=e(l.signal)}catch{r(null);return}_u(a)?a.then(r,()=>r(null)):r(a)};n>0?this.debounceTimer=setTimeout(s,n):s()}cancel(){this.request++,this.controller?.abort(),this.settle()}settle(){this.waiting=!1,this.controller=null,this.debounceTimer!==null&&clearTimeout(this.debounceTimer),this.loadingTimer!==null&&clearTimeout(this.loadingTimer),this.debounceTimer=this.loadingTimer=null}};function _u(o){return typeof o?.then=="function"}var Ku=75,Vu=/[\s.,;:!?)\]}>'"’”»)」』】、。,.:;!?]/,Uu=0,Co=class{constructor(e,t){this.host=e;this.entries=t.map(i=>{let r=null;return i.render!==!1&&(r=new Xe(e.root,`mbe-suggestion-menu ${i.className??""}`.trim(),"listbox"),r.el.setAttribute("aria-label",i.label??e.editor.labels.suggestions),r.el.setAttribute("aria-expanded","true"),r.onHighlight=s=>{this.session?.entry.menu!==r||this.active===s||(this.active=s,this.host.syncActiveDescendant(),this.report())}),{config:i,matcher:i.match??mr(i),triggers:typeof i.trigger=="string"?[i.trigger]:i.trigger,menu:r,listboxId:r?.el.id??`mbe-suggestion-${++Uu}`,source:new Mo}}),this.entries.length>0&&e.root.setAttribute("aria-autocomplete","list");let n=e.root.ownerDocument.defaultView;if(n&&this.entries.some(i=>i.menu)){let i=()=>this.schedule(),r=[n];n.visualViewport&&r.push(n.visualViewport);for(let s of r)for(let l of s===n?["resize"]:["resize","scroll"])s.addEventListener(l,i),this.cleanup.push(()=>s.removeEventListener(l,i))}}entries;session=null;dismissed=null;items=[];active=-1;message=null;side="below";frame=null;requestedComposing=!1;keysFrom=0;reported="";cleanup=[];get isActive(){return this.session!==null}get isOpen(){let e=this.session;return!e||!this.shown?!1:e.entry.menu?e.entry.menu.isOpen:!0}get activeDescendant(){return this.isOpen&&this.active>=0?`${this.session.entry.listboxId}-${this.active}`:null}get state(){let e=this.session;if(!e)return null;let{entry:t,blockId:n,cell:i,from:r,to:s,query:l}=e,a=u=>i?{blockId:n,offset:u,cell:i}:{blockId:n,offset:u},d=t.listboxId;return{name:t.config.name,query:l,range:{from:a(r),to:a(s)},items:this.items,active:this.active,loading:t.source.pending,listboxId:d,optionId:u=>`${d}-${u}`,anchorRect:()=>{if(this.session!==e)return null;let u=this.anchor();return u?new DOMRect(u.rect.left,u.rect.top,0,u.rect.bottom-u.rect.top):null}}}get shown(){return this.items.length>0||this.message!==null}get editor(){return this.host.editor}setConfigs(e){for(let t of e){let n=this.entries.find(i=>i.config.name===t.name);!n||n.config===t||(t.match!==n.config.match&&(n.matcher=t.match??mr(t)),n.config=t)}}typed(){if(this.entries.length===0||!this.editor.isEditable)return!1;let e=this.find(!1);if(!e)return!1;let t=this.dismissed;if(t&&t.blockId===e.blockId&&de(t.cell,e.cell)&&t.from===e.from)return!1;let n=this.session;return n&&n.entry===e.entry&&n.blockId===e.blockId&&de(n.cell,e.cell)&&n.from===e.from?!1:(this.close(),this.session={...e,explicit:!1},!0)}open(e){if(!this.editor.isEditable)return!1;let t=e===void 0?void 0:this.entries.find(i=>i.config.name===e);if(e!==void 0&&!t)return!1;let n=this.find(!0,t);return n?(this.close(),this.dismissed=null,this.session={...n,explicit:!0},this.host.refresh(),!0):!1}update(e){let t=this.dismissed;if(t){let s=e?this.find(!0):null;(!s||s.blockId!==t.blockId||!de(s.cell,t.cell)||s.from!==t.from)&&(this.dismissed=null)}let n=this.session;if(!n)return;let i=e&&this.editor.isEditable?this.find(n.explicit,n.entry):null;if(!(i&&i.blockId===n.blockId&&de(i.cell,n.cell)&&(i.from===n.from||i.text!==n.text))){this.close();return}this.session={...n,...i},this.refresh(),this.report()}close(){let e=this.session;e&&(e.entry.menu?.hide(),e.entry.menu&&(e.entry.menu.busy=!1),e.entry.source.cancel()),this.session=null,this.items=[],this.active=-1,this.message=null,this.requestedComposing=!1,this.side="below",this.keysFrom=0;for(let t of["aria-activedescendant","aria-controls","aria-haspopup"])this.host.root.removeAttribute(t);this.report()}move(e){!this.session||this.items.length===0||this.highlight(((this.active+e)%this.items.length+this.items.length)%this.items.length)}accept(e=this.active){let t=this.items[e];return!this.session||!t?!1:(this.pick(t),!0)}keydown(e){if(!this.isOpen)return!1;let t=!e.altKey&&!e.ctrlKey&&!e.metaKey&&!e.shiftKey;if(t&&e.key==="Escape")return this.dismiss(),!0;let n=ie&&e.ctrlKey&&!e.altKey&&!e.metaKey&&!e.shiftKey,i=e.key,r=null;if(t&&i==="ArrowDown"?r="down":t&&i==="ArrowUp"?r="up":n&&i.toLowerCase()==="n"?r="down":n&&i.toLowerCase()==="p"?r="up":t&&i==="PageDown"?r="pageDown":t&&i==="PageUp"?r="pageUp":t&&(i==="Enter"||i==="Tab")&&(r="accept"),!r||Date.now()<this.keysFrom)return!1;if(this.items.length===0)return i==="Enter"&&this.close(),!1;let s=this.session.entry.menu;return r==="down"?this.move(1):r==="up"?this.move(-1):r==="accept"?this.accept():s?s.page(r==="pageDown"?1:-1):this.highlight(Math.max(0,Math.min(this.items.length-1,this.active+(r==="pageDown"?8:-8)))),!0}dismiss(){let e=this.session;e&&(this.dismissed={blockId:e.blockId,cell:e.cell,from:e.from}),this.close()}reset(){this.dismissed=null,this.close()}reposition(){this.session&&this.shown&&this.place()}destroy(){this.close(),this.frame!==null&&cancelAnimationFrame(this.frame);for(let e of this.cleanup)e();for(let{menu:e}of this.entries)e?.destroy()}schedule(){this.frame!==null||!this.shown||(this.frame=requestAnimationFrame(()=>{this.frame=null,this.reposition()}))}highlight(e){let t=this.session?.entry.menu;t?t.highlight(e):this.active!==e&&(this.active=e,this.host.syncActiveDescendant(),this.report())}report(){let e=this.session,t=e?`${e.entry.config.name}
99
+ `,i);c<0&&(c=n.length);let h=t+16,f=Math.max(u,i-h);for(;f>u&&!/\s/.test(n[f-1]);)f--;let p=Math.min(c+e.length,i+e.length+h);for(let m of o(d,f,p)){if(m.from>=i||m.to<i+e.length)continue;let y=Mn(n,m.from,r,i);if(!y)return null;let g=n.slice(m.from+y.length,i);return g.length>t?null:{from:m.from,to:m.to-e.length,query:g}}return null}}function Mn(o,e,t,n=o.length){let i=null;for(let r of t)r&&e+r.length<=n&&o.startsWith(r,e)&&(!i||r.length>i.length)&&(i=r);return i}function zl(o,e){let t=0;for(let n of o){let i=t+n.text.length;if(e<i)return ct(n);t=i}return!1}var Mo=class{request=0;controller=null;debounceTimer=null;loadingTimer=null;waiting=!1;get pending(){return this.waiting}run(e,t,n=0){this.cancel();let i=this.request;this.waiting=!0,this.loadingTimer=setTimeout(()=>{this.loadingTimer=null,i===this.request&&t.loading()},300);let r=l=>{i===this.request&&(this.settle(),t.show(l))},s=()=>{this.debounceTimer=null;let l=new AbortController;this.controller=l;let a;try{a=e(l.signal)}catch{r(null);return}Ku(a)?a.then(r,()=>r(null)):r(a)};n>0?this.debounceTimer=setTimeout(s,n):s()}cancel(){this.request++,this.controller?.abort(),this.settle()}settle(){this.waiting=!1,this.controller=null,this.debounceTimer!==null&&clearTimeout(this.debounceTimer),this.loadingTimer!==null&&clearTimeout(this.loadingTimer),this.debounceTimer=this.loadingTimer=null}};function Ku(o){return typeof o?.then=="function"}var Vu=75,Uu=/[\s.,;:!?)\]}>'"’”»)」』】、。,.:;!?]/,zu=0,Co=class{constructor(e,t){this.host=e;this.entries=t.map(i=>{let r=null;return i.render!==!1&&(r=new Xe(e.root,`mbe-suggestion-menu ${i.className??""}`.trim(),"listbox"),r.el.setAttribute("aria-label",i.label??e.editor.labels.suggestions),r.el.setAttribute("aria-expanded","true"),r.onHighlight=s=>{this.session?.entry.menu!==r||this.active===s||(this.active=s,this.host.syncActiveDescendant(),this.report())}),{config:i,matcher:i.match??mr(i),triggers:typeof i.trigger=="string"?[i.trigger]:i.trigger,menu:r,listboxId:r?.el.id??`mbe-suggestion-${++zu}`,source:new Mo}}),this.entries.length>0&&e.root.setAttribute("aria-autocomplete","list");let n=e.root.ownerDocument.defaultView;if(n&&this.entries.some(i=>i.menu)){let i=()=>this.schedule(),r=[n];n.visualViewport&&r.push(n.visualViewport);for(let s of r)for(let l of s===n?["resize"]:["resize","scroll"])s.addEventListener(l,i),this.cleanup.push(()=>s.removeEventListener(l,i))}}entries;session=null;dismissed=null;items=[];active=-1;message=null;side="below";frame=null;requestedComposing=!1;keysFrom=0;reported="";cleanup=[];get isActive(){return this.session!==null}get isOpen(){let e=this.session;return!e||!this.shown?!1:e.entry.menu?e.entry.menu.isOpen:!0}get activeDescendant(){return this.isOpen&&this.active>=0?`${this.session.entry.listboxId}-${this.active}`:null}get state(){let e=this.session;if(!e)return null;let{entry:t,blockId:n,cell:i,from:r,to:s,query:l}=e,a=u=>i?{blockId:n,offset:u,cell:i}:{blockId:n,offset:u},d=t.listboxId;return{name:t.config.name,query:l,range:{from:a(r),to:a(s)},items:this.items,active:this.active,loading:t.source.pending,listboxId:d,optionId:u=>`${d}-${u}`,anchorRect:()=>{if(this.session!==e)return null;let u=this.anchor();return u?new DOMRect(u.rect.left,u.rect.top,0,u.rect.bottom-u.rect.top):null}}}get shown(){return this.items.length>0||this.message!==null}get editor(){return this.host.editor}setConfigs(e){for(let t of e){let n=this.entries.find(i=>i.config.name===t.name);!n||n.config===t||(t.match!==n.config.match&&(n.matcher=t.match??mr(t)),n.config=t)}}typed(){if(this.entries.length===0||!this.editor.isEditable)return!1;let e=this.find(!1);if(!e)return!1;let t=this.dismissed;if(t&&t.blockId===e.blockId&&de(t.cell,e.cell)&&t.from===e.from)return!1;let n=this.session;return n&&n.entry===e.entry&&n.blockId===e.blockId&&de(n.cell,e.cell)&&n.from===e.from?!1:(this.close(),this.session={...e,explicit:!1},!0)}open(e){if(!this.editor.isEditable)return!1;let t=e===void 0?void 0:this.entries.find(i=>i.config.name===e);if(e!==void 0&&!t)return!1;let n=this.find(!0,t);return n?(this.close(),this.dismissed=null,this.session={...n,explicit:!0},this.host.refresh(),!0):!1}update(e){let t=this.dismissed;if(t){let s=e?this.find(!0):null;(!s||s.blockId!==t.blockId||!de(s.cell,t.cell)||s.from!==t.from)&&(this.dismissed=null)}let n=this.session;if(!n)return;let i=e&&this.editor.isEditable?this.find(n.explicit,n.entry):null;if(!(i&&i.blockId===n.blockId&&de(i.cell,n.cell)&&(i.from===n.from||i.text!==n.text))){this.close();return}this.session={...n,...i},this.refresh(),this.report()}close(){let e=this.session;e&&(e.entry.menu?.hide(),e.entry.menu&&(e.entry.menu.busy=!1),e.entry.source.cancel()),this.session=null,this.items=[],this.active=-1,this.message=null,this.requestedComposing=!1,this.side="below",this.keysFrom=0;for(let t of["aria-activedescendant","aria-controls","aria-haspopup"])this.host.root.removeAttribute(t);this.report()}move(e){!this.session||this.items.length===0||this.highlight(((this.active+e)%this.items.length+this.items.length)%this.items.length)}accept(e=this.active){let t=this.items[e];return!this.session||!t?!1:(this.pick(t),!0)}keydown(e){if(!this.isOpen)return!1;let t=!e.altKey&&!e.ctrlKey&&!e.metaKey&&!e.shiftKey;if(t&&e.key==="Escape")return this.dismiss(),!0;let n=ie&&e.ctrlKey&&!e.altKey&&!e.metaKey&&!e.shiftKey,i=e.key,r=null;if(t&&i==="ArrowDown"?r="down":t&&i==="ArrowUp"?r="up":n&&i.toLowerCase()==="n"?r="down":n&&i.toLowerCase()==="p"?r="up":t&&i==="PageDown"?r="pageDown":t&&i==="PageUp"?r="pageUp":t&&(i==="Enter"||i==="Tab")&&(r="accept"),!r||Date.now()<this.keysFrom)return!1;if(this.items.length===0)return i==="Enter"&&this.close(),!1;let s=this.session.entry.menu;return r==="down"?this.move(1):r==="up"?this.move(-1):r==="accept"?this.accept():s?s.page(r==="pageDown"?1:-1):this.highlight(Math.max(0,Math.min(this.items.length-1,this.active+(r==="pageDown"?8:-8)))),!0}dismiss(){let e=this.session;e&&(this.dismissed={blockId:e.blockId,cell:e.cell,from:e.from}),this.close()}reset(){this.dismissed=null,this.close()}reposition(){this.session&&this.shown&&this.place()}destroy(){this.close(),this.frame!==null&&cancelAnimationFrame(this.frame);for(let e of this.cleanup)e();for(let{menu:e}of this.entries)e?.destroy()}schedule(){this.frame!==null||!this.shown||(this.frame=requestAnimationFrame(()=>{this.frame=null,this.reposition()}))}highlight(e){let t=this.session?.entry.menu;t?t.highlight(e):this.active!==e&&(this.active=e,this.host.syncActiveDescendant(),this.report())}report(){let e=this.session,t=e?`${e.entry.config.name}
100
100
  ${e.blockId}
101
101
  ${e.cell?.row},${e.cell?.col}
102
102
  ${e.from}
@@ -104,26 +104,26 @@ ${e.to}
104
104
  ${e.query}
105
105
  ${this.active}
106
106
  ${e.entry.source.pending}
107
- ${this.message}`:"";t===this.reported&&!(e&&this.itemsChanged)||(this.reported=t,this.itemsChanged=!1,this.host.changed(this.state))}itemsChanged=!1;find(e,t){let{doc:n,selection:i}=this.editor.state;if(!R(i))return null;let r=i.focus,s=n.blocks.find(p=>p.id===r.blockId);if(!s)return null;let l=So(n)&&s.type==="code"?s:null,a=l?this.editor.sourceSpans(l):null;if(!a&&Q(s))return null;let d=a??F(s,r.cell);if(!d)return null;let u=I(l?l.content:d),c=r.offset,h=a?"source":"rich",f=null;for(let p of t?[t]:this.entries){if(a&&p.config.richOnly)continue;let m=p.matcher({text:u,caret:c,content:d,triggers:p.triggers});if(!m||f&&m.from<=f.from||m.from<0||m.from>=c||m.to<c||m.to>u.length||!Mn(u,m.from,p.triggers,c)||m.query.length>(p.config.maxLength??30))continue;let y=zl(d,m.from),g=p.config.allow;(g?g({editor:this.editor,block:s,cell:r.cell,from:m.from,query:m.query,textBefore:u.slice(0,m.from),excluded:y,explicit:e,mode:h}):!y)&&(f={...m,entry:p,blockId:s.id,cell:r.cell,text:u,mode:h})}return f}refresh(){let e=this.session,{menu:t,source:n}=e.entry,i=e.query,r=this.editor.isComposing;if(e.requested===i&&!(this.requestedComposing&&!r)){this.shown&&this.place();return}this.session={...e,requested:i};let s=this.session,l=s.entry,a=()=>this.session?.entry===l&&this.session.requested===i,d=!0,u=h=>{if(!a())return;let f=l.config;t&&(t.busy=!1);let p=(h??[]).slice(0,f.limit??50);if(p.length===0&&r&&this.items.length>0)return this.report();let m=p.length===0&&(!f.emptyLabel||i.length>3);!m&&!d&&!this.isOpen&&(this.keysFrom=Date.now()+Ku);let y=this.items[this.active]?.id,g=y===void 0?-1:p.findIndex(b=>b.id===y),x=p.length===0?-1:Math.max(0,g);this.items=p,this.active=x,this.message=p.length===0&&!m?f.emptyLabel:null,this.itemsChanged=!0,t&&(m?t.hide():(t.setSections(Wu(p,i,b=>this.pick(b)),f.emptyLabel),t.highlight(x))),m?(this.host.root.removeAttribute("aria-haspopup"),this.host.root.removeAttribute("aria-controls"),this.host.syncActiveDescendant()):this.place(),this.report()},c=()=>{if(!a()||this.shown)return this.report();this.message=this.editor.labels.loading,t?.setMessage(this.message,"mbe-menu-loading"),this.place(),this.report()};this.requestedComposing=r,n.run(h=>l.config.items({query:i,editor:this.editor,explicit:s.explicit,composing:r,signal:h}),{show:u,loading:c},l.config.debounce??0),d=!1,n.pending&&t?.isOpen&&(t.busy=!0)}anchor(){let e=this.session,t=r=>e.cell?{blockId:e.blockId,offset:r,cell:e.cell}:{blockId:e.blockId,offset:r},n=e.from+(Mn(e.text,e.from,e.entry.triggers)?.length??1),i=this.editor.textRect(t(e.from),t(n));return Vl(i?.rect??null,this.editor.caretRect(),i?.rtl??!1,Ul(this.host.root))}place(){let e=this.session,{menu:t,listboxId:n}=e.entry,i=this.host.root,r=t?this.anchor():null;t&&r?t.popup.show(r.rect,this.side,4,r.align):t?.hide(),t&&(this.side=t.popup.side),this.isOpen?(i.setAttribute("aria-haspopup","listbox"),i.setAttribute("aria-controls",n)):(i.removeAttribute("aria-haspopup"),i.removeAttribute("aria-controls")),this.host.syncActiveDescendant()}pick(e){this.editor.isComposing&&this.host.endComposition();let t=this.session;if(!t)return;let{entry:n,blockId:i,cell:r,from:s,to:l,query:a,text:d,mode:u}=t,c=y=>r?{blockId:i,offset:y,cell:r}:{blockId:i,offset:y},h={from:c(s),to:c(l)};if(this.close(),n.config.command){n.config.command({editor:this.editor,range:h,item:e,query:a});return}let f=d[l],m=f!==void 0&&!(f===`
108
- `&&u==="source")&&Vu.test(f)?"":" ";this.editor.commands.insertText(n.triggers[0]+(e.value??e.id??e.label)+m,{range:h})}};function zu(o,e){return o.id??`${e}`}function Wu(o,e,t){let n=[];return o.forEach((i,r)=>{let s=n[n.length-1];(!s||i.section!==s.title)&&n.push(s={title:i.section,items:[]}),s.items.push({id:zu(i,r),label:i.label,detail:i.detail,icon:i.icon,mark:e,run:()=>t(i)})}),n}var kt=class{constructor(e,t,n,i){this.element=e;this.render=n;this.onRemove=i;this.blockId=t,this.paint()}blockId;offset=0;isRemoved=!1;cleanup=null;update(e){this.isRemoved||(e&&(this.render=e),this.paint())}remove(){this.isRemoved||(this.isRemoved=!0,this.cleanup?.(),this.cleanup=null,this.element.remove(),this.onRemove(this))}paint(){this.cleanup?.(),this.element.replaceChildren();let e=this.render(this.element);this.cleanup=typeof e=="function"?e:null}};function Wl(o,e,t){let n=o.split(/-(?!$)/),i=n.pop(),r=!1,s=!1,l=!1,a=!1;for(let d of n)if(/^(cmd|meta|m)$/i.test(d))a=!0;else if(/^a(lt)?$/i.test(d))s=!0;else if(/^(c|ctrl|control)$/i.test(d))r=!0;else if(/^s(hift)?$/i.test(d))l=!0;else if(/^mod$/i.test(d))t?a=!0:r=!0;else throw new Error(`Unrecognized modifier name: ${d}`);return i==="Space"&&(i=" "),{key:i.length===1?i.toLowerCase():i,ctrl:r,alt:s,shift:l,meta:a,handler:e}}function Qu(o){let e=/^(?:Key([A-Z])|Digit([0-9]))$/.exec(o.code);return e?(e[1]??e[2]).toLowerCase():null}function Ql(o,e){if(o.ctrl!==e.ctrlKey||o.alt!==e.altKey||o.meta!==e.metaKey)return!1;let t=e.key.length===1?e.key.toLowerCase():e.key;return t===o.key&&(o.shift===e.shiftKey||e.key.length===1&&!o.shift&&/[^a-z0-9]/.test(t))?!0:o.shift===e.shiftKey&&Qu(e)===o.key}var Zl=[["textStyle"],["bold","italic","strike","inlineCode","link"],["quote","codeBlock","list"]],Xl=Zl.flat(),ju=["textStyle","quote","codeBlock","list"],re=o=>`${ie?"Meta":"Control"}+${o}`,jl={bold:{mark:"bold",className:"mbe-tool-bold",keys:re("B")},italic:{mark:"italic",className:"mbe-tool-italic",keys:re("I")},strike:{mark:"strike",className:"mbe-tool-strike",keys:re("Shift+X")},inlineCode:{mark:"code",className:"mbe-tool-code",keys:re("E")}},Gu=[{id:"text",spec:{type:"paragraph"},keys:re("Alt+0")},{id:"heading1",spec:{type:"heading",level:1},keys:re("Alt+1")},{id:"heading2",spec:{type:"heading",level:2},keys:re("Alt+2")},{id:"heading3",spec:{type:"heading",level:3},keys:re("Alt+3")},{id:"heading4",spec:{type:"heading",level:4},keys:re("Alt+4")}],gr=[{id:"bulletList",listType:"bullet",keys:re("Shift+8")},{id:"numberedList",listType:"ordered",keys:re("Shift+7")},{id:"todoList",listType:"task",keys:re("Shift+9")}],Zu=500,Xu=300;function Gl(o){let e=zn(o.state),t=r=>r.type==="paragraph"?"text":r.type==="heading"&&r.level<=4?`heading${r.level}`:null,n=r=>{let s=e[0]?r(e[0]):null;return e.every(l=>r(l)===s)?s:null},i=e.length>0;return{style:n(t),allHeadings:i&&e.every(r=>r.type==="heading"),listType:n(r=>r.type==="listItem"?r.listType:null),allListItems:i&&e.every(r=>r.type==="listItem"),allQuotes:i&&e.every(r=>M(r)!==null)}}var Io=class{constructor(e,t=Xl){this.editor=e;let n=e.root.ownerDocument;this.popup=new we(e.root,"mbe-toolbar");let i=this.popup.el;i.setAttribute("role","toolbar"),this.tooltip=new we(e.root,"mbe-tooltip"),this.tooltip.el.setAttribute("aria-hidden","true");let r=e.labels,s=(d,u,c,h,f)=>{let p=n.createElement("button");p.type="button",p.className=`mbe-tool ${c}`;let m=X(n,e.icon(u));return m&&p.appendChild(m),p.setAttribute("aria-label",r[d==="codeBlock"?"code":d]),h&&p.setAttribute("aria-keyshortcuts",h),p.addEventListener("click",f),p.addEventListener("pointerenter",y=>{y.pointerType==="mouse"&&this.scheduleTooltip(p)}),p.addEventListener("pointerleave",()=>this.hideTooltip()),this.buttons.set(d,p),p},l=(d,u,c)=>{let h=s(d,d==="list"?"bulletList":"text",u,null,()=>this.toggleMenu(g));h.classList.add("mbe-tool-menu"),h.setAttribute("aria-haspopup","menu"),h.setAttribute("aria-expanded","false");let f=n.createElement("span");f.className="mbe-tool-icon",f.append(...h.childNodes);let p=n.createElement("span");p.className="mbe-tool-chevron";let m=X(n,e.icon("chevronDown"));m&&p.appendChild(m),h.append(f,p);let y=new Xe(e.root,c,"menu");y.el.setAttribute("aria-label",r[d]),y.checkIcon=e.icon("selected"),y.onPicked=()=>this.closeMenu(),y.onHighlight=()=>this.onMenuChange?.(),h.setAttribute("aria-controls",y.el.id);let g={button:h,icon:f,menu:y,iconName:d==="list"?"bulletList":"text"};return g},a=new Set(t);for(let d of Zl){let u=d.filter(c=>a.has(c));if(u.length!==0){if(this.buttons.size>0){let c=n.createElement("span");c.className="mbe-tool-sep",i.appendChild(c),this.separators.push(c)}for(let c of u){let h=jl[c],f;h?(f=s(c,c,h.className,h.keys,()=>this.apply(p=>We(p,h.mark))),f.setAttribute("aria-pressed","false")):c==="link"?(f=s(c,"link","mbe-tool-link",re("K"),()=>e.openLinkPopover()),f.setAttribute("aria-pressed","false")):c==="quote"?(f=s(c,"quote","mbe-tool-quote",null,()=>this.apply(p=>ht(p,{type:"quote"}))),f.setAttribute("aria-pressed","false")):c==="codeBlock"?f=s(c,"code","mbe-tool-code-block",re("Alt+C"),()=>this.apply(p=>ht(p,{type:"code"}))):c==="textStyle"?(this.textStyle=l(c,"mbe-tool-text-style","mbe-text-style-menu"),f=this.textStyle.button):(this.list=l("list","mbe-tool-list","mbe-list-menu"),f=this.list.button),i.appendChild(f)}}}}popup;tooltip;buttons=new Map;separators=[];textStyle=null;list=null;openTrigger=null;tooltipTimer;tooltipHiddenAt=0;onMenuChange=null;get isOpen(){return this.popup.isOpen}get menu(){return this.openTrigger?.menu??null}contains(e){return this.popup.el.contains(e)||!!this.openTrigger?.menu.el.contains(e)}show(){let e=this.editor.selectionRect();if(!e)return this.hide();this.update();let t=this.editor.root.ownerDocument.defaultView;this.popup.el.style.maxWidth=`${Math.max(xo(t).width-16,0)}px`,this.popup.show(e,Ft()?"below":"above",8),this.openTrigger&&this.placeMenu(this.openTrigger)}hide(){this.closeMenu(),this.hideTooltip(),this.popup.hide()}closeMenu(){let e=this.openTrigger;e&&(this.openTrigger=null,e.menu.hide(),e.button.classList.remove("mbe-open"),e.button.setAttribute("aria-expanded","false"),this.onMenuChange?.())}destroy(){clearTimeout(this.tooltipTimer),this.popup.destroy(),this.tooltip.destroy(),this.textStyle?.menu.destroy(),this.list?.menu.destroy()}apply(e){this.hideTooltip(),this.editor.run(e),this.isOpen&&this.update()}update(){let e=this.editor;for(let[a,d]of this.buttons){let u=jl[a];u&&br(d,e.isActive(u.mark))}let t=this.buttons.get("link");t&&br(t,e.isActive("link"));let{anchor:n,focus:i}=e.state.selection,r=!!i.cell&&n.blockId===i.blockId;for(let a of ju)this.buttons.get(a)?.toggleAttribute("hidden",r);r&&this.closeMenu();for(let a of this.separators){let d=(u,c)=>{for(let h=u;h&&!h.classList.contains("mbe-tool-sep");h=h[c])if(!h.hidden)return!0;return!1};a.hidden=!d(a.previousElementSibling,"previousElementSibling")||!d(a.nextElementSibling,"nextElementSibling")}if(r)return;let s=Gl(e),l=this.buttons.get("quote");if(l&&br(l,s.allQuotes),this.textStyle&&(this.setTriggerIcon(this.textStyle,s.style??"text"),this.textStyle.button.classList.toggle("mbe-active",s.allHeadings)),this.list){let a=gr.find(d=>d.listType===s.listType);this.setTriggerIcon(this.list,a?.id??"bulletList"),this.list.button.classList.toggle("mbe-active",s.allListItems)}}setTriggerIcon(e,t){if(e.iconName===t)return;e.iconName=t;let n=X(e.icon.ownerDocument,this.editor.icon(t));e.icon.replaceChildren(...n?[n]:[])}toggleMenu(e){let t=this.openTrigger===e;if(this.closeMenu(),this.hideTooltip(),t)return;let n=Gl(this.editor),i=this.editor.labels,r,s;e===this.textStyle?(s=n.style??void 0,r=Gu.map(({id:l,spec:a,keys:d})=>({id:l,label:i[l],icon:this.editor.icon(l),labelClass:`mbe-menu-${l}`,keyShortcuts:d,checked:l===s,run:()=>l!==s&&this.apply(u=>Ge(u,a))}))):(s=gr.find(l=>l.listType===n.listType)?.id,r=gr.map(({id:l,listType:a,keys:d})=>({id:l,label:i[l],icon:this.editor.icon(l),keyShortcuts:d,checked:l===s,run:()=>this.apply(u=>ht(u,{type:"listItem",listType:a}))}))),e.menu.setSections([{items:r}]),s&&e.menu.highlightId(s),this.openTrigger=e,e.button.classList.add("mbe-open"),e.button.setAttribute("aria-expanded","true"),this.placeMenu(e),this.onMenuChange?.()}placeMenu(e){let t=this.editor.root.ownerDocument.defaultView.getComputedStyle(this.editor.root).direction==="rtl";e.menu.popup.show(e.button.getBoundingClientRect(),this.popup.side,4,t?"end":"start")}scheduleTooltip(e){if(clearTimeout(this.tooltipTimer),this.openTrigger)return;let t=Date.now()-this.tooltipHiddenAt<Xu?0:Zu;this.tooltipTimer=setTimeout(()=>{if(!this.isOpen||this.openTrigger||!e.isConnected)return;this.tooltip.el.textContent=e.getAttribute("aria-label"),this.tooltip.show(e.getBoundingClientRect(),this.popup.side,6);let n=e.getBoundingClientRect(),i=this.tooltip.el.getBoundingClientRect(),r=this.editor.root.ownerDocument.defaultView,s=Math.max(8,Math.min(n.left+(n.width-i.width)/2,r.innerWidth-i.width-8));this.tooltip.el.style.left=`${parseFloat(this.tooltip.el.style.left)+s-i.left}px`},t)}hideTooltip(){clearTimeout(this.tooltipTimer),this.tooltip.isOpen&&(this.tooltip.hide(),this.tooltipHiddenAt=Date.now())}};function br(o,e){o.classList.toggle("mbe-active",e),o.setAttribute("aria-pressed",String(e))}var Lo=class{popup;input;removeButton;done=null;constructor(e){let t=e.root.ownerDocument;this.popup=new we(e.root,"mbe-input-popover"),this.input=t.createElement("input"),this.input.className="mbe-popover-input",this.removeButton=t.createElement("button"),this.removeButton.type="button",this.removeButton.className="mbe-tool",this.popup.el.append(this.input,this.removeButton),this.input.addEventListener("keydown",n=>{n.key==="Enter"?(n.preventDefault(),this.finish(this.input.value.trim())):n.key==="Escape"&&(n.preventDefault(),this.finish(null))}),this.input.addEventListener("blur",()=>{setTimeout(()=>{this.popup.isOpen&&t.activeElement!==this.input&&this.close()},150)}),this.removeButton.addEventListener("click",()=>this.finish(""))}get isOpen(){return this.popup.isOpen}contains(e){return this.popup.el.contains(e)}open(e,t,n){this.done=n,this.input.type=t.type,this.input.value=t.value,this.input.placeholder=t.placeholder,this.input.setAttribute("aria-label",t.label),this.removeButton.textContent=t.removeLabel??"",this.removeButton.hidden=!t.removeLabel||t.value==="",this.popup.show(e,"below"),this.input.focus(),this.input.select()}close(){this.done=null,this.popup.hide()}finish(e){let t=this.done;this.done=null,this.popup.hide(),t?.(e)}destroy(){this.popup.destroy()}};var Yl=24,Yu=8,Jl=16,Bo=class{constructor(e){this.editor=e;let t=e.root,n=t.ownerDocument,i=e.labels;this.frame=n.createElement("div"),this.frame.className="mbe-ui mbe-image-frame",this.frame.hidden=!0;let r=l=>{let a=n.createElement("div");return a.className=`mbe-resize-handle mbe-resize-handle-${l}`,a.dataset.side=l,a.title=i.resizeImage,a.setAttribute("aria-hidden","true"),this.frame.appendChild(a),a};this.handles={left:r("left"),right:r("right")};let s=(l,a,d)=>{l.addEventListener(a,d),this.cleanup.push(()=>l.removeEventListener(a,d))};s(t,"mouseover",l=>this.onOver(l)),s(t,"mouseleave",()=>this.scheduleUnhover());for(let l of[this.frame,this.handles.left,this.handles.right])s(l,"mouseenter",()=>this.cancelUnhover()),s(l,"mouseleave",()=>this.scheduleUnhover());s(this.frame,"mousedown",l=>l.preventDefault());for(let l of["left","right"])s(this.handles[l],"pointerdown",a=>this.startDrag(a,l));s(this.frame,"pointermove",l=>this.moveDrag(l)),s(this.frame,"pointerup",l=>this.endDrag(l,!0)),s(this.frame,"pointercancel",l=>this.endDrag(l,!1)),s(this.frame,"lostpointercapture",l=>this.endDrag(l,!0))}frame;handles;hovered=null;selected=null;framed=null;drag=null;hideTimer=null;cleanup=[];contains(e){return this.frame.contains(e)}get isDragging(){return this.drag!==null}update(e){this.selected=e,this.drag||this.placeFrame()}reposition(){this.drag||(this.selected&&!this.selected.el.isConnected&&(this.selected=null),this.placeFrame())}hide(){this.drag||(this.hovered=null,this.selected=null,this.placeFrame())}destroy(){this.cancelUnhover();for(let e of this.cleanup)e();this.frame.remove()}onOver(e){if(this.drag||!this.editor.isEditable)return;let t=e.target,n=t instanceof HTMLImageElement&&t.classList.contains("mbe-image")?t:null;n?(this.cancelUnhover(),this.hovered=n,this.placeFrame()):this.hovered&&this.scheduleUnhover()}scheduleUnhover(){this.cancelUnhover(),this.hideTimer=setTimeout(()=>{this.hideTimer=null,this.hovered=null,this.placeFrame()},250)}cancelUnhover(){this.hideTimer!==null&&clearTimeout(this.hideTimer),this.hideTimer=null}placeFrame(){let e=this.editor.isEditable,t=this.hovered?.isConnected?this.hovered:null,n=this.drag?.el??(e?t??this.selected?.el??null:null),i=n instanceof HTMLImageElement&&n.isConnected?n:null,r=i?.getBoundingClientRect();if(!i||!r||r.width===0||r.height===0){this.frame.hidden=!0,this.framed=null;return}this.framed!==i&&(this.framed=i,i.complete||i.addEventListener("load",()=>this.framed===i&&this.placeFrame(),{once:!0}));let s=yr(i,r);if(!s||s.width<Math.min(r.width,Jl)||s.height<Math.min(r.height,Jl)){this.frame.hidden=!0;return}this.frame.hidden=!1;let l=$t(this.frame,this.editor.root);this.frame.style.left=`${Math.round(s.left-l.x)}px`,this.frame.style.top=`${Math.round(s.top-l.y)}px`,this.frame.style.width=`${Math.round(s.width)}px`,this.frame.style.height=`${Math.round(s.height)}px`,this.frame.classList.toggle("mbe-image-frame-small",s.width<64||s.height<40)}startDrag(e,t){let n=this.framed;if(!n||this.drag||e.button!==0||!this.editor.isEditable)return;let i=this.editor.imageTarget(n);if(!i)return;e.preventDefault(),this.handles[t].setPointerCapture?.(e.pointerId);let r=n.getBoundingClientRect().width,s=Array.from(this.editor.root.querySelectorAll("img.mbe-image")).filter(d=>d!==n).map(d=>d.getBoundingClientRect().width).filter(d=>d>0),l=Math.max(Yl,Ju(n)),a=n.closest(".mbe-image-block")?.getAttribute("data-align")==="center"?2:1;this.drag={el:n,side:t,pointer:e.pointerId,startX:e.clientX,startWidth:r,max:l,snaps:[...s,l],width:r,factor:a},this.frame.classList.add("mbe-image-resizing"),this.editor.selectImageAt(i.pos)}moveDrag(e){let t=this.drag;if(!t||e.pointerId!==t.pointer)return;e.preventDefault();let n=(e.clientX-t.startX)*(t.side==="right"?1:-1)*t.factor,i=Math.min(t.max,Math.max(Yl,t.startWidth+n)),r=t.snaps.find(s=>Math.abs(s-i)<=Yu);r!==void 0&&(i=Math.min(t.max,r)),t.width=Math.round(i),t.el.style.width=`${t.width}px`,t.el.style.height="auto",this.placeFrame()}endDrag(e,t){let n=this.drag;if(!n||e.pointerId!==n.pointer)return;this.drag=null,this.frame.classList.remove("mbe-image-resizing"),this.handles[n.side].releasePointerCapture?.(e.pointerId),n.el.style.width="",n.el.style.height="";let i=n.el.isConnected?this.editor.imageTarget(n.el):null;t&&i&&Math.round(n.width)!==Math.round(n.startWidth)?this.editor.updateImageAt(i.pos,{width:n.width}):this.editor.refreshImageUi()}};function yr(o,e){let t=o.ownerDocument,n=t.defaultView,i=e.left,r=e.top,s=e.right,l=e.bottom,a=(d,u,c,h)=>{i=Math.max(i,d),r=Math.max(r,u),s=Math.min(s,c),l=Math.min(l,h)};for(let d=o.parentElement;d&&d!==t.body&&d!==t.documentElement;d=d.parentElement){let u=n?.getComputedStyle(d),c=d.scrollHeight>d.clientHeight&&/auto|scroll|overlay/.test(u?.overflowY??""),h=d.scrollWidth>d.clientWidth&&/auto|scroll|overlay/.test(u?.overflowX??"");if(!c&&!h)continue;let f=d.getBoundingClientRect(),p=f.left+d.clientLeft,m=f.top+d.clientTop;a(p,m,p+d.clientWidth,m+d.clientHeight)}return a(0,0,t.documentElement.clientWidth,t.documentElement.clientHeight),s<=i||l<=r?null:{left:i,top:r,width:s-i,height:l-r}}function Ju(o){let e=o.parentElement,t=o.ownerDocument.defaultView;for(;e&&t.getComputedStyle(e).display.startsWith("inline");)e=e.parentElement;if(!e)return o.getBoundingClientRect().width;let n=t.getComputedStyle(e);return e.clientWidth-parseFloat(n.paddingLeft||"0")-parseFloat(n.paddingRight||"0")}var eh=[{align:"left",icon:"imageAlignLeft"},{align:"center",icon:"imageAlignCenter"},{align:"right",icon:"imageAlignRight"}],Ao=class{constructor(e,t){this.editor=e;let n=e.root.ownerDocument,i=e.labels;this.popup=new we(e.root,"mbe-image-toolbar");let r=this.popup.el;r.setAttribute("role","toolbar"),r.setAttribute("aria-label",i.imageSection);let s=(a,d,u)=>{let c=n.createElement("button");c.type="button",c.className=`mbe-tool ${d}`;let h=X(n,e.icon(a));return h&&c.appendChild(h),c.setAttribute("aria-label",i[a]),c.title=i[a],c.addEventListener("click",()=>{this.target&&u()}),c};for(let{align:a,icon:d}of eh){let u=s(d,`mbe-tool-${d}`,()=>t.align(this.target,a));u.setAttribute("aria-pressed","false"),this.alignButtons.push({align:a,button:u}),r.appendChild(u)}this.alignSep=n.createElement("span"),this.alignSep.className="mbe-tool-sep",r.appendChild(this.alignSep),r.appendChild(s("altText","mbe-tool-altText",()=>t.altText(this.target))),this.resetButton=s("resetImageSize","mbe-tool-resetImageSize",()=>t.resetSize(this.target)),r.appendChild(this.resetButton);let l=n.createElement("span");l.className="mbe-tool-sep",r.appendChild(l),r.appendChild(s("delete","mbe-tool-delete",()=>t.remove(this.target)))}popup;alignButtons=[];alignSep;resetButton;target=null;get isOpen(){return this.popup.isOpen}contains(e){return this.popup.el.contains(e)}show(e,t){let n=yr(e.el,e.el.getBoundingClientRect());if(!n)return this.hide();this.target=e;let i=e.image.align??"left";for(let{align:d,button:u}of this.alignButtons)u.hidden=!t,u.classList.toggle("mbe-active",t&&d===i),u.setAttribute("aria-pressed",String(t&&d===i));this.alignSep.hidden=!t,this.resetButton.hidden=!e.image.width;let{left:r,top:s,width:l,height:a}=n;this.popup.show({left:r,top:s,right:r+l,bottom:s+a},Ft()?"below":"above",8)}hide(){this.target=null,this.popup.hide()}destroy(){this.popup.destroy()}};var W="data-block-id";function Cr(o){return`code:${o.trim().toLowerCase()}`}var Kt="data-content",In="mbe-source-text",Ir="mbe-source-line",$o="data-mbe-fill",xr="data-mbe-pending",ia="data-atom",ra="data-list-start",th="data-quote-joined",nh="data-quote-continued",oh="data-section-hidden",ih="data-collapsed",rh="data-in-section",sh={bold:["strong"],italic:["em"],strike:["s"],code:["code"],html:["span","mbe-raw-html"]},lh={};function qe(...o){return o.filter(Boolean).join(" ")}function ah(o,e){let t=ch(o,e);return Wt(o)&&o.quote?qe(t,e.blockquote)||void 0:t}function ch(o,e){switch(o.type){case"paragraph":return e.paragraph;case"heading":return e.heading?.[o.level];case"quote":return e.blockquote;case"listItem":return e[`${o.listType}List`];case"code":return e.codeBlock;case"table":return e.table;case"raw":return e.raw;case"divider":return;case"details":return e.details;case"detailsEnd":return}}var Ln=o=>{let e=o.replace(/^[\u0000- ]+|[\u0000- ]+$/g,"").replace(/[\t\n\r]/g,""),t=/^([a-z][a-z0-9+.-]*):/i.exec(e);return t?["http","https","mailto","tel"].includes(t[1].toLowerCase())?e:null:e},Je="block";function Cn(o,e){return o?`${o.row}:${o.col}@${e}`:`@${e}`}function Lr(o,e){if(o===e)return!0;if(!o||!e||o.size!==e.size)return!1;for(let t of o)if(!e.has(t))return!1;return!0}function Br(o){return`callout${o[0].toUpperCase()}${o.slice(1)}`}function dh(o,e){let t=Y(e);if(t===null)return;o.classList.add("mbe-image-block");let n=C(e.content,t,t+1)[0]?.image?.align;n&&(o.dataset.align=n)}function uh(o,e,t,n){let i=t.doc,r=i.createElement("blockquote");r.dir="auto",r.dataset.callout=e;let s=i.createElement("div");return s.className="mbe-content",vt(s,o.content,t,o,n),r.append(No(e,t),s),r}function No(o,e){let t=Br(o),n=e.doc.createElement("div");n.className="mbe-callout-icon",n.contentEditable="false",n.setAttribute("role","img"),n.setAttribute("aria-label",e.labels[t]);let i=e.icon?.(t);return i&&n.appendChild(i),n}function sa(o,e,t){let{doc:n,labels:i}=e,r=(c,h)=>{let f=n.createElement(c);return h&&(f.className=h),f},s,l=t?.has(Je)||e.source?null:e.blockView?.(o);if(l)s=r("div","mbe-view-block mbe-block-view"),s.contentEditable="false",s.appendChild(l);else switch(o.type){case"paragraph":case"heading":case"quote":if(o.type==="quote"&&o.callout){s=uh(o,o.callout,e,t);break}s=r(o.type==="paragraph"?"p":o.type==="quote"?"blockquote":`h${o.level}`),s.dir="auto",vt(s,o.content,e,o,t),o.type==="paragraph"&&dh(s,o);break;case"listItem":{s=r(o.quote?"blockquote":"div"),o.callout&&(s.dataset.callout=o.callout,s.appendChild(No(o.callout,e))),s.dir="auto",s.dataset.listType=o.listType,s.dataset.indent=String(o.indent);let c=r("span","mbe-marker");if(c.contentEditable="false",o.listType==="task"){let f=r("input","mbe-checkbox");f.type="checkbox",f.tabIndex=-1,f.checked=o.checked,c.appendChild(f)}let h=r("div","mbe-content");vt(h,o.content,e,o,t),s.append(c,h);break}case"code":{if(e.source){s=r("div"),s.spellcheck=!1;let y=r("div",In);y.setAttribute(Kt,""),aa(y,o,e),s.appendChild(y);break}let c=t?.has(Je)?null:e.view?.(Cr(o.language),I(o.content),"block");if(c){s=c,s.classList.add("mbe-view-block"),s.contentEditable="false",s.dataset.language=o.language;break}s=r("div"),s.dataset.language=o.language;let h=r("div","mbe-code-bar");h.contentEditable="false";let f=r("input","mbe-code-lang");f.value=o.language,f.spellcheck=!1,f.setAttribute("aria-label",i.language),f.placeholder=i.plainText,h.appendChild(f),e.codeCopy&&h.appendChild(bh(e));let p=r("pre"),m=r("code");m.spellcheck=!1,vt(m,o.content,e,o,void 0,void 0,!1),p.appendChild(m),s.append(h,p);break}case"raw":{let c=I(o.content),h=t?.has(Je)===!0,f=o.syntax==="html"&&!h&&e.views?.has("html")?tl(c,e.markdown):null,p=o.syntax==="footnote"&&!h&&e.views?.has("footnote")?da(c):null,m=o.syntax==="markdown"&&!h&&e.views?.get("markdown")===Nr,y=h?null:m?wh(c,e):p?ua(p,e):e.view?.(o.syntax,f?f.html:c,"block");y?(s=y,s.classList.add("mbe-view-block"),o.syntax==="html"&&s.classList.add("mbe-view-html"),s.contentEditable="false",f&&Ar(s,f.slots.length,g=>yh(f.slots[g],e),e.doc)):(s=r("pre"),s.spellcheck=!1,vt(s,o.content,e,o,void 0,void 0,!1)),s.dataset.syntax=o.syntax;break}case"divider":s=r("div"),s.contentEditable="false",s.appendChild(r("hr",e.classes.divider));break;case"details":{s=r("div"),s.dir="auto";let c=r("span","mbe-details-marker");c.contentEditable="false";let h=r("button","mbe-details-toggle");h.type="button",h.tabIndex=-1;let f=e.icon?.("chevronRight");f&&h.appendChild(f),c.appendChild(h);let p=r("div","mbe-content");vt(p,o.content,e,o,void 0,void 0,!1),s.append(c,p);break}case"detailsEnd":s=r("div"),s.contentEditable="false";break;case"table":{s=r("div"),s.contentEditable="false";let c=r("table"),h=r("tbody");o.rows.forEach((f,p)=>{let m=r("tr");f.forEach((y,g)=>{let x=r(p===0?"th":"td");x.contentEditable="true",x.dir="auto",x.dataset.row=String(p),x.dataset.col=String(g);let b=o.align[g];b&&(x.style.textAlign=b),vt(x,y,e,o,t,{row:p,col:g}),m.appendChild(x)}),h.appendChild(m)}),c.appendChild(h),s.appendChild(c);break}}if(!l&&!e.source&&o.type!=="listItem"&&Wt(o)&&o.quote){let c=s;s=r("blockquote"),o.type==="heading"&&(s.dir="auto"),o.callout&&(s.dataset.callout=o.callout,s.appendChild(No(o.callout,e))),c.classList.add("mbe-content"),c.contentEditable==="false"&&(s.contentEditable="false"),c.classList.contains("mbe-view-block")&&s.classList.add("mbe-view-block");for(let h of["language","syntax"])c.dataset[h]!==void 0&&(s.dataset[h]=c.dataset[h]);s.appendChild(c)}s.setAttribute(W,o.id);let a=o.type==="listItem"?"list-item":o.type==="detailsEnd"?"details-end":o.type==="code"&&e.source?"source":o.type,d=`${s.className?s.className+" ":""}mbe-block mbe-${a}`;o.type==="listItem"&&o.checked&&(d+=" mbe-checked"),"content"in o&&B(o.content)===0&&(d+=" mbe-empty");let u=ah(o,e.classes);return u&&(d+=" "+u),s.className=d,s}var wr=new WeakMap,hh=[];function fh(o,e){let t=e.map((s,l)=>({d:s,index:l})).filter(s=>s.d.to>s.d.from).sort((s,l)=>s.d.from-l.d.from),n=0,i=[],r=[];for(let s=0;;){let l=o.indexOf(`
109
- `,s),a=l===-1?o.length:l,d=i.filter(c=>c.d.to>s);for(;n<t.length&&t[n].d.from<a;){let c=t[n++];c.d.to>s&&d.push(c)}i=d.filter(c=>c.d.to>a),d.length>1&&d.sort((c,h)=>c.index-h.index);let u=d.length===0?hh:d.map(({d:c})=>({...c,from:Math.max(c.from,s)-s,to:Math.min(c.to,a)-s})).filter(c=>c.to>c.from);if(r.push({text:o.slice(s,a),decorations:u}),l===-1)return r;s=l+1}}function ea(o,e){return o.text===e.text&&$n(o.decorations,e.decorations)}function Ro(o){return o instanceof HTMLElement&&o.classList.contains(Ir)}function*la(o){let e=wr.get(o),t=e&&e.length===o.childElementCount?e:null,n=0;for(let i=o.firstChild;i;i=i.nextSibling)Ro(i)&&(yield[i,t?t[n].text.length:i.textContent.length],n++)}function aa(o,e,t){mh(o,I(e.content),t.decorateSource?.(e)??[],t)}function ph(o,e){let t=e.doc,n=t.createElement("div");if(n.className=Ir,n.dir="auto",o.text.length===0)n.appendChild(Tr(t));else if(o.decorations.length===0)n.appendChild(t.createTextNode(o.text));else for(let i of Yo([{text:o.text,marks:[]}],o.decorations))n.appendChild(fa(t.createTextNode(i.span.text),i.decorations,t));return n}function mh(o,e,t,n){let i=fh(e,t);o.classList.toggle("mbe-empty-content",e.length===0);let r=Array.from(o.childNodes).filter(Ro),s=wr.get(o)??[];r.length!==s.length&&(s=[],o.replaceChildren());let l=0;for(;l<s.length&&l<i.length&&ea(s[l],i[l]);)l++;let a=0;for(;a<s.length-l&&a<i.length-l&&ea(s[s.length-1-a],i[i.length-1-a]);)a++;let d=n.doc.createDocumentFragment();for(let c=l;c<i.length-a;c++)d.appendChild(ph(i[c],n));let u=a>0?r[s.length-a]:null;for(let c=l;c<s.length-a;c++)r[c].remove();if(o.insertBefore(d,u),o.childNodes.length!==i.length)for(let c of Array.from(o.childNodes))Ro(c)||c.remove();wr.set(o,i)}function gh(o){let e=[],t="";for(let n=o.firstChild;n;n=n.nextSibling)Ro(n)?(n!==o.firstChild&&e.push(t),t=Vt(n).map(Dr).join("")):t+=n.nodeType===3?n.data:n.hasAttribute($o)?"":n.textContent??"";return e.push(t),e.join(`
110
- `)}function vt(o,e,t,n,i,r,s=!0){let l=t.doc;if(o.setAttribute(Kt,""),B(e)===0){o.classList.add("mbe-empty-content"),o.appendChild(Tr(l));return}let a=n.type==="code"?t.decorateCode?.(n)??[]:s&&t.decorate?t.decorate(n,e,r):[],d=e.length===1?e[0]:null;d&&a.length===0&&d.marks.length===0&&!d.link&&!d.token&&!d.image?o.appendChild(l.createTextNode(d.text)):Ch(e,o,t,a,i,r);let u=e[e.length-1];u&&u.text.endsWith(`
111
- `)&&o.appendChild(Tr(l))}function bh(o){let e=o.doc.createElement("button");e.type="button",e.className="mbe-code-copy",e.tabIndex=-1,e.setAttribute("aria-label",o.labels.copyCode),e.title=o.labels.copyCode;let t=o.icon?.("copyCode");return t&&e.appendChild(t),e}function Ar(o,e,t,n){if(e===0)return;let i=[],r=n.createTreeWalker(o,4);for(let l=r.nextNode();l;l=r.nextNode())l.nodeValue.includes("\uE000")&&i.push(l);let s=new Set;for(let l of i){let a=l.nodeValue,d=n.createDocumentFragment(),u=0;for(let c of a.matchAll(el)){c.index>u&&d.append(a.slice(u,c.index));let h=Number(c[1]);h<e&&!s.has(h)&&(s.add(h),d.append(t(h))),u=c.index+c[0].length}u<a.length&&d.append(a.slice(u)),l.replaceWith(d)}if(!o.hasAttribute(xr))for(let l=0;l<e;l++)s.has(l)||o.appendChild(t(l))}function yh(o,e){let t=e.doc.createElement("div");return t.className="mbe-flow",Sr(t,o,e),Do(t),t}function Sr(o,e,t){let n=new Map,i=t.blockView?{...t,blockView:void 0}:t;for(let r of e){let s=sa(r,i);n.set(r.id,s),o.appendChild(s)}Er({blocks:e},r=>n.get(r),new WeakMap,new Set,t.labels)}var kh=/^(\[\^((?:[^\]\s\\]|\\.)+)\]:)[ \t]*(.*)$/,vh=/\[\^((?:[^\]\s\\]|\\.)+)\]/g,ca=o=>o.replace(/\\(.)/g,"$1");function da(o){let[e="",...t]=o.split(`
112
- `),n=kh.exec(e);if(!n)return null;let i=[n[3],...t.map(r=>r.replace(/^(?: {1,4}|\t)/,""))].join(`
113
- `);return{label:ca(n[2]),head:`${n[1]} `,body:i}}function ua(o,e){let t=e.view?.("footnote",o.head+ko(0),"block")??null;return t&&Ar(t,1,()=>xh(o.body,e),e.doc),t}function xh(o,e){let t=Fo(he(o,e.markdown).children,e),n=t.childNodes.length===1?t.firstElementChild:null;if(t.childNodes.length===0||n&&n.tagName==="P"){let i=e.doc.createElement("span");return n&&i.append(...Array.from(n.childNodes)),Do(i),i}return Do(t),t}var Nr=()=>!1;function wh(o,e){let t=e.doc.createElement("div");return t.classList.add("mbe-view-markdown"),t.appendChild(Fo(he(o,e.markdown).children,e)),Do(t),t}function Fo(o,e){let t=e.markdown??pe,n=e.doc.createElement("div");n.className="mbe-flow";let i=[];for(let r of o){let s=fn(r,t,i[i.length-1]);if(s){i.push(...s);continue}Sr(n,i,e),i=[],r.type==="blockQuote"?n.appendChild(Sh(r,e)):r.type==="list"&&r.items.forEach((l,a)=>n.appendChild(Th(r,l,a,e)))}return Sr(n,i,e),n}function Sh(o,e){let t=e.markdown?.callouts===!1?null:Ni(o.children),n=t?[...t.rest.length>0?[{type:"paragraph",children:[...t.rest]}]:[],...o.children.slice(1)]:o.children,i=e.doc.createElement("blockquote");return i.dir="auto",i.className=qe("mbe-block mbe-quote",e.classes.blockquote),t&&(i.dataset.callout=t.type,i.appendChild(No(t.type,e))),i.appendChild(Fo(n,e)),i}function Th(o,e,t,n){let i=e.task?"task":o.ordered?"ordered":"bullet",r=n.doc.createElement("div");r.dir="auto",r.className=qe("mbe-block mbe-list-item",n.classes[`${i}List`]),r.dataset.listType=i,r.dataset.indent="0",t===0&&r.setAttribute(ra,"");let s=n.doc.createElement("span");if(s.className="mbe-marker",e.task){let a=n.doc.createElement("input");a.className="mbe-checkbox",a.type="checkbox",a.checked=e.checked,s.appendChild(a)}else o.ordered&&(s.textContent=`${o.start+t}.`);let l=n.doc.createElement("div");return l.className="mbe-content",l.appendChild(Fo(e.children,n)),r.append(s,l),r}function Do(o){for(let e of Array.from(o.querySelectorAll(`[${W}], [${Kt}], [contenteditable], [data-row]`)))e.removeAttribute(W),e.removeAttribute(Kt),e.removeAttribute("contenteditable"),e.removeAttribute("data-row"),e.removeAttribute("data-col");for(let e of Array.from(o.querySelectorAll("input")))e.type==="checkbox"?e.disabled=!0:e.readOnly=!0,e.tabIndex=-1}function Tr(o){let e=o.createElement("br");return e.setAttribute($o,""),e}var Eh=new Set(["area","base","br","col","embed","hr","img","input","link","meta","source","track","wbr"]),Mh=/<!--[\s\S]*?-->|<[^<>]*>/g;function ha(o){if(!o.some(t=>t.marks.includes("html")))return o;let e=[];for(let t of G(o)){if(!t.marks.includes("html")){e.push(t);continue}let n=0;for(let i of t.text.matchAll(Mh))i.index>n&&e.push({...t,text:t.text.slice(n,i.index)}),e.push({...t,text:i[0]}),n=i.index+i[0].length;n<t.text.length&&e.push({...t,text:t.text.slice(n)})}return e}function Rr(o){let e=[],t=0;for(let r of ha(o))e.push({span:r,from:t,to:t+r.text.length}),t+=r.text.length;let n=r=>r.marks.includes("html"),i=[];for(let r=0;r<e.length;r++){let{span:s,from:l,to:a}=e[r];if(!n(s))continue;let d=/^<([A-Za-z][A-Za-z0-9-]*)\b[^>]*?(\/?)>$/.exec(s.text),u=r;if(d&&!d[2]&&!Eh.has(d[1].toLowerCase())){let c=d[1].toLowerCase(),h=0;for(let f=r+1;f<e.length;f++){let p=e[f].span;if(!n(p))continue;let m=/^<(\/?)([A-Za-z][A-Za-z0-9-]*)\b[^>]*?(\/?)>$/.exec(p.text);if(!(!m||m[2].toLowerCase()!==c||m[3]))if(!m[1])h++;else if(h>0)h--;else{u=f;break}}}i.push({from:l,to:u===r?a:e[u].to}),r=u}return i}function Ch(o,e,t,n,i,r){let s=t.doc,l=t.views,a=l?(v,T)=>!!v.token&&l.has(v.token)&&!i?.has(Cn(r,T)):void 0;l?.has("html")&&(o=ha(o));let d=l?.has("html")&&o.some(v=>v.marks.includes("html"))?Rr(o).filter(v=>!i?.has(Cn(r,v.from))):[],u=v=>d.some(T=>v>=T.from&&v<T.to),c=v=>v.marks.includes("html"),h=a||d.length>0?(v,T)=>!!a?.(v,T)||c(v)&&u(T):void 0,f=Yo(o,n,h),p=v=>fa(Ih(v.span,t,v.atomic&&!c(v.span)),v.decorations,s),m=new Map,y=0;for(let v of f)m.set(v,y),y+=v.span.text.length;let g=v=>{let T=s.createElement("a"),E=t.resolveUrl(v.link,"link");return E!==null&&T.setAttribute("href",E),T.dataset.href=v.link,v.linkTitle&&(T.title=v.linkTitle),T.className=qe("mbe-link",t.classes.link),T},x=v=>d.find(T=>T.from===m.get(f[v])),b=(v,T)=>{let E=v;for(;E<f.length&&m.get(f[E])<T.to;)E++;return E},w=(v,T)=>{let E=f[v].span;if(!E.link)return!1;for(let A=v+1,fe=b(v,T);A<fe;A++)if(!ae(f[A].span,E))return!1;return!0},k=(v,T,E,A)=>{let fe=[],me=[],Se=b(v,T);for(let le=v;le<Se;){let Vr=f[le];if(c(Vr.span)){fe.push(Vr.span.text),le++;continue}let Wo=s.createDocumentFragment(),Ur=zr=>zr>=Se||c(f[zr].span);if(A)for(;!Ur(le);le++)Wo.appendChild(p(f[le]));else le=S(le,Ur,Wo);me.push(Wo),fe.push(ko(me.length-1))}let Te=t.view?.("html",fe.join(""),"inline");if(!Te)return null;Ar(Te,me.length,le=>me[le],s);let Rn=I(C(o,T.from,T.to));return E.appendChild(Oo(Te,qe("mbe-view","mbe-view-html",t.classes.token?.html),Rn)),Se},S=(v,T,E)=>{for(;v<f.length&&!T(v);){let A=f[v].span,fe=x(v);if(fe&&!w(v,fe)){let Te=k(v,fe,E,!1);if(Te!==null){v=Te;continue}}if(!A.link){E.appendChild(p(f[v])),v++;continue}let me=g(A),Se=v;for(;v<f.length&&!T(v)&&ae(f[v].span,A);){let Te=x(v);if(Te){let Rn=w(v,Te);if(!Rn&&v>Se)break;let le=Rn?k(v,Te,me,!0):null;if(le!==null){v=le;continue}}me.appendChild(p(f[v])),v++}E.appendChild(me)}return v};S(0,()=>!1,e)}function fa(o,e,t){for(let n=e.length-1;n>=0;n--){let i=e[n],r=t.createElement("span");for(let[s,l]of Object.entries(i.attributes??{}))r.setAttribute(s,l);r.className=`mbe-deco ${i.class}`,r.appendChild(o),o=r}return o}function Oo(o,e,t){return o.classList.add(...e.split(/\s+/).filter(Boolean)),o.contentEditable="false",o.setAttribute(ia,""),t!==void 0&&(o.dataset.source=t),o}function Ih(o,e,t=!1){let n=e.doc,i=t?e.view?.(o.token,o.text,"inline"):null;if(i)return na(o,Oo(i,qe("mbe-view",`mbe-view-${o.token}`,e.classes.token?.[o.token]),o.text),e);if(o.image){let s=o.image,l=e.resolveUrl(s.src,"image");if(l===null)return ta(s,e);let a=e.loadedImage?.(l);if(!a){let d=n.createElement("img");d.setAttribute("loading","lazy"),d.setAttribute("decoding","async"),e.referrerPolicy&&d.setAttribute("referrerpolicy",e.referrerPolicy),d.src=l,d.addEventListener("error",()=>{d.parentNode&&(d.replaceWith(ta({src:l,alt:d.alt,title:d.title||void 0},e)),e.onImageError?.())}),a=d}return a.alt=s.alt,kr(a,"title",s.title),kr(a,"width",s.width?String(s.width):void 0),kr(a,"height",s.height?String(s.height):void 0),Oo(a,qe("mbe-image",e.classes.image))}let r=n.createTextNode(o.text);if(o.token){let s=n.createElement("span");s.className=qe("mbe-token",`mbe-token-${o.token}`,e.classes.token?.[o.token]),s.spellcheck=!1,s.appendChild(r),r=s}return na(o,r,e)}function kr(o,e,t){t===void 0?o.removeAttribute(e):o.setAttribute(e,t)}function ta(o,e){let t=e.doc,n=t.createElement("span"),i=o.alt||e.labels.imageUnavailable;n.setAttribute("role","img"),n.setAttribute("aria-label",i),o.title&&(n.title=o.title);let r=e.icon?.("imageUnavailable");r&&n.appendChild(r);let s=t.createElement("span");return s.className="mbe-image-alt",s.textContent=i,n.appendChild(s),Oo(n,qe("mbe-image","mbe-image-unavailable",e.classes.image))}function na(o,e,t){for(let n=et.length-1;n>=0;n--){let i=et[n];if(!o.marks.includes(i))continue;let[r,s]=sh[i],l=t.doc.createElement(r),a=i==="html"?s:t.classes[i];a&&(l.className=a),l.appendChild(e),e=l}return e}var Ho=class{constructor(e,t){this.root=e;this.labels=t}rendered=new Map;numbers=new WeakMap;resolveUrl=Ln;referrerPolicy;decorate;decorateCode;decorateSource;onViewSettled;widgetsAfter;views;collectFootnotes=!1;footnotes;viewContext;blockViews=[];hosted=new Map;markdown;classes=lh;icon;codeCopy=!1;source=!1;onImageError;collapsed=new Set;revealed=new Map;viewCache=new Map;pendingViews=new Map;failedViews=new Set;viewBlocks=new Map;renderingBlock="";loadedImages=new Map;context(){return{doc:this.root.ownerDocument,labels:this.labels,resolveUrl:this.resolveUrl,referrerPolicy:this.referrerPolicy,decorate:this.decorate,decorateCode:this.decorateCode,decorateSource:this.decorateSource,views:this.views,view:this.views&&((e,t,n)=>this.renderView(e,t,n)),blockView:this.blockViews.length>0?e=>this.renderBlockView(e):void 0,markdown:this.markdown,classes:this.classes,icon:this.icon,codeCopy:this.codeCopy,source:this.source,onImageError:this.onImageError,loadedImage:e=>this.loadedImages.get(e)?.shift()}}renderView(e,t,n){let i=this.views?.get(e);if(!i||!this.viewContext)return null;let r=`${n}\0${e}\0${t}`;if(this.failedViews.has(r))return this.noteViewBlock(r),null;let s=this.viewCache.get(r);if(s)this.viewCache.delete(r);else{s=this.root.ownerDocument.createElement(n==="inline"?"span":"div");let l;try{l=i(t,s,n,this.viewContext)}catch{l=!1}if(l===!1)return this.noteViewBlock(r),null;if(l&&typeof l.then=="function"&&(s.setAttribute(xr,""),this.awaitView(r,l)),this.viewCache.size>=500){let a=this.viewCache.keys().next().value;this.viewCache.delete(a),this.viewBlocks.delete(a)}}return this.pendingViews.get(r)?.add(this.renderingBlock),this.noteViewBlock(r),this.viewCache.set(r,s),s.cloneNode(!0)}isHosted(e){return this.blockViews.some(({view:t})=>t.match(e))}renderBlockView(e){let t=this.hosted.get(e.id);if(t&&t.block===e)return t.after?null:t.el;t&&this.disposeHosted(e.id);let n=this.viewContext;if(!n)return null;let i=null;for(let{name:r,view:s}of this.blockViews){if(!s.match(e))continue;i=r;let l=this.root.ownerDocument.createElement("div"),a;try{a=s.render(e,l,n)}catch{a=!1}if(a===!1)continue;let d=typeof a=="function"?a:void 0;if(s.placement!=="after")return this.hosted.set(e.id,{block:e,name:r,el:l,dispose:d}),l;let u=this.root.ownerDocument.createElement("div");return u.className="mbe-block-view mbe-block-after",u.contentEditable="false",u.appendChild(l),this.hosted.set(e.id,{block:e,name:r,el:l,after:u,dispose:d}),null}return i!==null&&this.hosted.set(e.id,{block:e,name:i,el:null}),null}afterView(e,t){if(t?.has(Je)||this.source)return;let n=this.hosted.get(e.id);return n?.block===e?n.after:void 0}disposeHosted(e){let t=this.hosted.get(e);if(t){this.hosted.delete(e);try{t.dispose?.()}catch{}}}destroy(){for(let e of[...this.hosted.keys()])this.disposeHosted(e)}noteViewBlock(e){let t=this.viewBlocks.get(e);t||(this.viewBlocks.size>=1e3&&this.viewBlocks.delete(this.viewBlocks.keys().next().value),this.viewBlocks.set(e,t=new Set)),t.add(this.renderingBlock)}awaitView(e,t){let n=new Set;this.pendingViews.set(e,n);let i=r=>{this.pendingViews.get(e)===n&&(this.pendingViews.delete(e),this.viewCache.get(e)?.removeAttribute(xr),r||(this.failedViews.add(e),this.viewCache.delete(e)),n.size>0&&this.onViewSettled?.([...n]))};t.then(r=>i(r!==!1),()=>i(!1))}dropViews(e){let t=i=>e===void 0||i.split("\0",3)[1]===e;for(let i of[...this.viewCache.keys()])t(i)&&this.viewCache.delete(i);for(let i of[...this.failedViews])t(i)&&this.failedViews.delete(i);for(let i of[...this.pendingViews.keys()])t(i)&&this.pendingViews.delete(i);let n=new Set;for(let[i,r]of[...this.viewBlocks])if(t(i)){this.viewBlocks.delete(i);for(let s of r)this.rendered.has(s)&&n.add(s)}for(let[i,r]of[...this.hosted])e!==void 0&&r.name!==e||(this.disposeHosted(i),this.rendered.has(i)&&n.add(i));return[...n]}render(e,t=!1,n=!1){let i=this.context(),r=new Set;for(let u of e.blocks){let c=this.rendered.get(u.id);!t&&c&&c.block===u&&c.el.parentNode===this.root&&Lr(c.reveal,this.revealed.get(u.id))&&r.add(c.el)}if(!t){for(let{el:u}of this.rendered.values())if(!r.has(u))for(let c of Array.from(u.querySelectorAll("img.mbe-image"))){let h=c.getAttribute("src");if(h===null||!c.complete||c.naturalWidth===0)continue;let f=this.loadedImages.get(h);f?f.push(c):this.loadedImages.set(h,[c])}}let s=new Map;for(let u of e.blocks){this.renderingBlock=u.id;let c=this.rendered.get(u.id),h=this.revealed.get(u.id),f=c&&r.has(c.el)?c.el:null;!f&&i.source&&u.type==="code"&&c?.block.type==="code"&&c.el.parentNode===this.root&&this.patchSource(c.el,u,i)&&(f=c.el),f||(f=sa(u,i,h),c&&u.type==="raw"&&Bh(c.el,f)),s.set(u.id,{block:u,el:f,reveal:h})}this.loadedImages.clear();for(let[u,c]of[...this.hosted])s.get(u)?.block!==c.block&&this.disposeHosted(u);let l=this.collectFootnotes&&this.views?.has("footnote")===!0;for(let{block:u,el:c}of s.values())u.type==="raw"&&u.syntax==="footnote"&&c.classList.toggle("mbe-footnote-collected",l);let a=l?this.footnoteSection(e,s,i,t):null;l||(this.footnotes=void 0);let d=[];for(let[u,{block:c,el:h,reveal:f}]of s){d.push(h);let p=this.afterView(c,f);p&&d.push(p);let m=this.widgetsAfter?.(u);m&&d.push(...m)}if(a&&d.push(a),t||this.rendered.size===0){let u=this.root.ownerDocument.createDocumentFragment();for(let c of d)n&&c.hasAttribute(W)&&c.classList.add("mbe-lazy"),u.appendChild(c);this.root.replaceChildren(u)}else{let u=this.root.firstChild,c=!1;for(let h of d)h===u?u=u.nextSibling:(this.root.insertBefore(h,u),c=!0);if(c||u!==null||this.root.childNodes.length!==d.length){let h=new Set(d);for(let f of Array.from(this.root.childNodes))h.has(f)||f.remove()}}this.rendered=s,Er(e,u=>s.get(u)?.el,this.numbers,this.collapsed,this.labels)}footnoteSection(e,t,n,i){let r=new Map;for(let u of e.blocks){if(u.type!=="raw"||u.syntax!=="footnote")continue;let c=da(I(u.content));c&&!r.has(c.label)&&r.set(c.label,c)}if(r.size===0)return null;let s=[],l=new Map;for(let u of e.blocks){let c=t.get(u.id)?.el;if(c)for(let h of Array.from(c.querySelectorAll(".mbe-view-footnote")))for(let f of(h.dataset.source??"").matchAll(vh)){let p=ca(f[1]);if(!r.has(p))continue;let m=(l.get(p)??0)+1;l.set(p,m),m===1&&s.push(p)}}if(s.length===0)return null;let a=JSON.stringify(s.map(u=>[u,r.get(u).body,l.get(u)]));if(!i&&this.footnotes?.key===a)return this.footnotes.el;let d=n.doc.createElement("section");d.className="mbe-footnotes",d.contentEditable="false",d.setAttribute("aria-label",this.labels.footnotes);for(let u of s){let c=ua(r.get(u),n);if(!c)continue;let h=c.lastElementChild??c,f=h.querySelector(":scope > .mbe-flow");if(f){let p=f.lastElementChild;p?.tagName==="P"?h=p:(h=n.doc.createElement("p"),h.className="mbe-block mbe-paragraph",f.appendChild(h))}for(let p=1;p<=l.get(u);p++){let m=n.doc.createElement("button");m.type="button",m.className="mbe-footnote-backref",m.dataset.label=u,m.dataset.ref=String(p),m.setAttribute("aria-label",`${this.labels.backToReference} ${u}${p>1?` ${p}`:""}`);let y=n.icon?.("backToReference");if(y?m.appendChild(y):m.textContent="\u2191",p>1){let g=n.doc.createElement("sup");g.textContent=String(p),m.appendChild(g)}h.appendChild(m)}d.appendChild(c)}return this.footnotes={key:a,el:d},d}updateSections(e){Er(e,t=>this.rendered.get(t)?.el,this.numbers,this.collapsed,this.labels)}elementFor(e){return this.rendered.get(e)?.el}adopt(e){let t=this.rendered.get(e.id);t&&(this.rendered.set(e.id,{...t,block:e}),"content"in e&&t.el.classList.toggle("mbe-empty",B(e.content)===0))}invalidate(e){this.rendered.delete(e)}patchSource(e,t,n=this.context()){let i=se(e);return i?(aa(i,t,n),e.classList.toggle("mbe-empty",B(t.content)===0),!0):!1}refreshSource(e){let t=this.rendered.get(e.id);t&&t.el.parentNode===this.root&&this.patchSource(t.el,e)}};function Lh(o,e,t,n,i){let r=e>0?String(e):"";if(o.style.getPropertyValue("--mbe-section-depth")!==r&&(r?o.style.setProperty("--mbe-section-depth",r):o.style.removeProperty("--mbe-section-depth")),_t(o,rh,e>0),_t(o,oh,t),n===null)return;_t(o,ih,n);let s=o.querySelector(".mbe-details-toggle"),l=String(!n);s&&s.getAttribute("aria-expanded")!==l&&(s.setAttribute("aria-expanded",l),s.setAttribute("aria-label",n?i.expandSection:i.collapseSection))}function Er(o,e,t,n,i){let r=[],s,l=[];o.blocks.forEach((a,d)=>{let u=o.blocks[d-1],c=e(a.id);if(a.type==="detailsEnd"&&l.pop(),c&&Lh(c,l.length,l.includes(!0),a.type==="details"?n.has(a.id):null,i),a.type==="details"&&l.push(n.has(a.id)),M(a)!==null&&(_t(c,th,oe(u,a)),_t(c,nh,oe(a,o.blocks[d+1]))),(a.type!=="listItem"||u?.type!=="listItem"||M(u)!==M(a))&&(r.length=0,s=void 0),a.type!=="listItem")return;let h=a.listType==="ordered";if(_t(c,ra,r.length===0||a.indent===0&&s!==void 0&&h!==s),a.indent===0&&(s=h),r.length=a.indent+1,!h){r[a.indent]=void 0;return}let f=r[a.indent]===void 0?a.start??1:r[a.indent]+1;if(r[a.indent]=f,!c||t.get(c)===f)return;let p=c.querySelector(".mbe-marker");p&&(p.textContent=`${f}.`),t.set(c,f)})}function Bh(o,e){let t=o.querySelectorAll("details");if(t.length===0)return;let n=e.querySelectorAll("details");n.length===t.length&&t.forEach((i,r)=>{n[r].open=i.open})}function _t(o,e,t){o&&o.hasAttribute(e)!==t&&o.toggleAttribute(e,t)}function Ah(o,e){let t=e;for(;t&&t.parentNode!==o;)t=t.parentNode;return t instanceof HTMLElement&&t.hasAttribute(W)?t:null}function se(o,e){return e?o.querySelector(`[data-row="${e.row}"][data-col="${e.col}"]`):o.hasAttribute(Kt)?o:o.querySelector(`[${Kt}]`)}function Vt(o){let e=[],t=n=>{for(let i=n.firstChild;i;i=i.nextSibling)i.nodeType===3?e.push(i):i instanceof HTMLElement&&(i.hasAttribute(ia)?e.push(i):i.hasAttribute($o)||t(i))};return t(o),e}function Dr(o){return o.nodeType===3?o.data:o.dataset.source??"\uFFFC"}function Po(o){return Dr(o).length}function xt(o){return Array.prototype.indexOf.call(o.parentNode.childNodes,o)}function Or(o){return o.classList.contains(In)?gh(o):Vt(o).map(Dr).join("")}function oa(o,e){let t=0;for(let[n,i]of la(o)){if(n===e)return t;t+=i+1}return e===null&&t>0?t-1:t}function Mr(o,e,t){if(!o.contains(e))return e.compareDocumentPosition(o)&Node.DOCUMENT_POSITION_FOLLOWING?0:Vt(o).reduce((l,a)=>l+Po(a),0);if(o.classList.contains(In)){if(e===o)return oa(o,o.childNodes[t]??null);let s=(e instanceof Element?e:e.parentElement)?.closest(`.${Ir}`);if(s?.parentNode===o)return oa(o,s)+Mr(s,e,t)}let n=o.ownerDocument,i=n.createRange();i.setStart(e,t);let r=0;for(let s of Vt(o)){let l=Po(s);if(s===e)return r+Math.min(t,l);if(s.contains(e))return r;let a=n.createRange();if(s.nodeType===3?a.setStart(s,l):a.setStartAfter(s),a.compareBoundaryPoints(Range.START_TO_START,i)<=0)r+=l;else return r}return r}function _e(o,e,t){let n=e,i=t;if(e===o){let a=o.childNodes[Math.min(t,o.childNodes.length-1)];if(!a)return null;let d=t>=o.childNodes.length;if(n=a,i=d?a.childNodes.length:0,d){let u=a,c=u.hasAttribute?.(W)?se(u):null;if(c)return{blockId:u.getAttribute(W),offset:Or(c).length}}}let r=Ah(o,n);if(!r)return null;let s=r.getAttribute(W);if(r.classList.contains("mbe-divider"))return{blockId:s,offset:0};if(r.classList.contains("mbe-table")){let a=(n instanceof Element?n:n.parentElement)?.closest("[data-row]");if(!a||!r.contains(a))return{blockId:s,offset:0,cell:{row:0,col:0}};let d={row:Number(a.dataset.row),col:Number(a.dataset.col)};return{blockId:s,offset:Mr(a,n,i),cell:d}}let l=se(r);return l?{blockId:s,offset:Mr(l,n,i)}:{blockId:s,offset:0}}function pa(o,e){let t=se(o,e.cell);if(!t||t.classList.contains(In))return null;let n=0;for(let i of Vt(t)){if(n===e.offset&&i.nodeType!==3)return i;if(n+=Po(i),n>e.offset)return null}return null}function ma(o,e){let t=se(o,e.cell);if(!t)return{node:o.parentNode,offset:xt(o)};if(t.classList.contains(In)){let n=0,i=null;for(let r of la(t)){let[s,l]=r;if(e.offset<=n+l)return vr(s,e.offset-n);n+=l+1,i=r}return i?vr(i[0],i[1]):{node:t,offset:0}}return vr(t,e.offset)}function vr(o,e){let t=0,n=Vt(o);for(let r of n){let s=Po(r);if(r.nodeType===3){let l=r;if(t+s>=e){let a=e-t;if(a===s&&r===n[n.length-1]&&l.data.endsWith(`
114
- `)){let d=o.querySelector(`[${$o}]`);if(d)return{node:d.parentNode,offset:xt(d)}}return{node:l,offset:a}}}else if(e<t+s)return{node:r.parentNode,offset:xt(r)+(t===e?0:1)};t+=s}let i=n[n.length-1];return i?i.nodeType===3?{node:i,offset:i.length}:{node:i.parentNode,offset:xt(i)+1}:{node:o,offset:0}}var qo=class{constructor(e){this.editor=e;let t=e.root,n=t.ownerDocument;this.el=n.createElement("button"),this.el.type="button",this.el.className="mbe-ui mbe-block-handle";let i=X(n,e.icon("blockHandle"));i&&this.el.appendChild(i),this.el.setAttribute("aria-label",e.labels.blockHandle),this.el.setAttribute("aria-haspopup","menu"),this.el.tabIndex=-1,this.el.hidden=!0;let r=(s,l,a)=>{s.addEventListener(l,a),this.cleanup.push(()=>s.removeEventListener(l,a))};r(t,"mousemove",s=>this.onMove(s)),r(t,"mouseleave",()=>this.scheduleHide()),r(this.el,"mouseenter",()=>this.cancelHide()),r(this.el,"mouseleave",()=>this.scheduleHide()),r(this.el,"mousedown",s=>s.preventDefault()),r(this.el,"click",()=>{this.blockId&&e.openBlockMenu(this.blockId,this.el.getBoundingClientRect())})}el;blockId=null;hideTimer=null;cleanup=[];onMove(e){if(!this.editor.isEditable)return;let n=e.target;for(;n&&n.parentElement!==this.editor.root;)n=n.parentElement;if(!n||!n.hasAttribute(W))return;let i=this.editor.blockMenuOwner(n.getAttribute(W));i?this.showFor(i):this.blockId!==null&&this.scheduleHide()}showFor(e){this.cancelHide();let t=this.editor.blockElement(e);if(!t)return this.hide();let n=this.editor.root.ownerDocument;this.blockId=e,this.el.hidden=!1;let i=$t(this.el,this.editor.root),r=t.getBoundingClientRect(),l=t.querySelector(":scope > .mbe-callout-icon")?.getBoundingClientRect(),a=parseFloat(n.defaultView.getComputedStyle(t).lineHeight)||24,d=l?.height?l.top+l.height/2:r.top+Math.min(r.height,a)/2,u=this.el.offsetHeight||22;this.el.style.left=`${Math.round(r.left-(this.el.offsetWidth||20)-6-i.x)}px`,this.el.style.top=`${Math.round(d-u/2-i.y)}px`}contains(e){return this.el.contains(e)}hide(){this.cancelHide(),this.el.hidden=!0,this.blockId=null}scheduleHide(){this.cancelHide(),this.hideTimer=setTimeout(()=>this.hide(),250)}cancelHide(){this.hideTimer!==null&&clearTimeout(this.hideTimer),this.hideTimer=null}destroy(){this.cancelHide();for(let e of this.cleanup)e();this.el.remove()}};var Nh=300,Rh=250,_o=class{constructor(e,t){this.editor=e;this.actions=t;let n=e.root.ownerDocument,i=e.labels;this.popup=new we(e.root,"mbe-link-card");let r=this.popup.el;r.setAttribute("role","toolbar"),r.setAttribute("aria-label",i.link),this.url=n.createElement("a"),this.url.className="mbe-link-card-url",this.url.target="_blank",this.url.rel="noopener noreferrer",this.url.addEventListener("click",f=>{f.preventDefault(),this.target&&t.open(this.target,f)});let s=(f,p)=>{let m=n.createElement("button");return m.type="button",m.className=`mbe-tool mbe-link-card-${f}`,ga(m,e,f),m.setAttribute("aria-label",i[f]),m.title=i[f],m.addEventListener("click",y=>{this.target&&p(y)}),m},l=s("openLink",f=>t.open(this.target,f));this.copyButton=s("copyLink",()=>this.copy());let a=s("editLink",()=>{let f=this.target;this.hide(),t.edit(f)}),d=s("removeLink",()=>{let f=this.target;this.hide(),t.remove(f)}),u=n.createElement("span");u.className="mbe-tool-sep",r.append(this.url,u,l,this.copyButton,a,d);let c=e.root,h=(f,p,m)=>{f.addEventListener(p,m),this.cleanup.push(()=>f.removeEventListener(p,m))};h(c,"mouseover",f=>this.onOver(f)),h(c,"mouseout",f=>this.onOut(f)),h(r,"mouseenter",()=>this.cancelHide()),h(r,"mouseleave",()=>{this.hovered&&this.scheduleHide()})}popup;url;copyButton;target=null;hovered=null;caret=null;showTimer=null;hideTimer=null;copiedTimer=null;cleanup=[];get isOpen(){return this.popup.isOpen}contains(e){return this.popup.el.contains(e)}setCaret(e){this.caret=e,this.hovered&&!this.hovered.el.isConnected&&(this.hovered=null),this.render()}reposition(){if(this.target){if(!this.target.el.isConnected)return this.hide();this.place(this.target)}}hide(){this.clearTimers(),this.hovered=null,this.caret=null,this.target=null,this.popup.hide()}destroy(){this.clearTimers(),this.copiedTimer!==null&&clearTimeout(this.copiedTimer);for(let e of this.cleanup)e();this.popup.destroy()}onOver(e){if(!this.editor.isEditable||e.buttons!==0)return;let t=e.target?.closest?.("a.mbe-link");!t||!this.editor.root.contains(t)||(this.cancelHide(),this.hovered?.el!==t&&(this.showTimer!==null&&clearTimeout(this.showTimer),this.showTimer=setTimeout(()=>{this.showTimer=null;let n=this.actions.targetOf(t);!n||!this.editor.isEditable||(this.hovered=n,this.render())},this.popup.isOpen?0:Nh)))}onOut(e){let t=e.target?.closest?.("a.mbe-link");if(!t)return;let n=e.relatedTarget;n&&(t.contains(n)||this.popup.el.contains(n))||(this.showTimer!==null&&(clearTimeout(this.showTimer),this.showTimer=null),this.hovered&&this.scheduleHide())}render(){let e=this.hovered??this.caret;if(!e){this.target=null,this.popup.hide();return}if(this.target?.el!==e.el||this.target.href!==e.href){this.target=e,this.url.textContent=e.href,this.url.title=e.href;let t=e.el.getAttribute("href");t?this.url.href=t:this.url.removeAttribute("href");let n=this.popup.el.querySelector(".mbe-link-card-openLink");n&&(n.disabled=!t),this.showCopied(!1)}this.place(e)}place(e){let t=e.el.getClientRects(),n=t.length>0?t[t.length-1]:e.el.getBoundingClientRect();this.popup.show(n,"below",4)}copy(){let e=this.target.href,t=()=>this.showCopied(!0),n=this.editor.root.ownerDocument.defaultView?.navigator.clipboard;n&&n.writeText(e).then(t,()=>{})}showCopied(e){this.copiedTimer!==null&&clearTimeout(this.copiedTimer),this.copiedTimer=null;let t=this.copyButton,n=e?"copied":"copyLink";ga(t,this.editor,n),t.setAttribute("aria-label",this.editor.labels[n]),t.title=this.editor.labels[n],e&&(this.copiedTimer=setTimeout(()=>this.showCopied(!1),1500))}scheduleHide(){this.cancelHide(),this.hideTimer=setTimeout(()=>{this.hideTimer=null,this.hovered=null,this.render()},Rh)}cancelHide(){this.hideTimer!==null&&clearTimeout(this.hideTimer),this.hideTimer=null}clearTimers(){this.cancelHide(),this.showTimer!==null&&clearTimeout(this.showTimer),this.showTimer=null}};function ga(o,e,t){let n=X(o.ownerDocument,e.icon(t));o.replaceChildren(...n?[n]:[])}function Hr(o,e,t,n){let i=new Map;if(!t)return i;let{anchor:r,focus:s}=o.selection,l=N(o.doc,s.blockId),a=r.blockId===s.blockId?l:N(o.doc,r.blockId);for(let[d,u]of[[s,l],[r,a]]){let c=i.get(u.id)??new Set;if(n?.(u)&&c.add(Je),u.type==="raw")e.has(u.syntax)&&c.add(Je);else if(u.type==="code")e.has(Cr(u.language))&&c.add(Je);else{let h=F(u,d.cell)??[];for(let{token:f,from:p}of Xr(h,d.offset))e.has(f)&&c.add(Cn(d.cell,p));if(e.has("html")&&h.some(f=>f.marks.includes("html")))for(let f of Rr(h))f.from<=d.offset&&d.offset<=f.to&&c.add(Cn(d.cell,f.from))}c.size>0&&i.set(u.id,c)}return i}function ba(o,e){return o.size===e.size&&[...o].every(([t,n])=>Lr(n,e.get(t)))}function Bn(o,e){if(o.type==="table"){let i=e?0:o.rows.length-1;return{blockId:o.id,offset:e?0:B(o.rows[i][0]),cell:{row:i,col:0}}}if(o.type!=="raw"&&o.type!=="code")return e?V(o):P(o);let t=I(o.content);if(o.type==="code"||o.syntax==="markdown")return{blockId:o.id,offset:e?0:t.length};if(e){let i=t.indexOf(`
107
+ ${this.message}`:"";t===this.reported&&!(e&&this.itemsChanged)||(this.reported=t,this.itemsChanged=!1,this.host.changed(this.state))}itemsChanged=!1;find(e,t){let{doc:n,selection:i}=this.editor.state;if(!R(i))return null;let r=i.focus,s=n.blocks.find(p=>p.id===r.blockId);if(!s)return null;let l=So(n)&&s.type==="code"?s:null,a=l?this.editor.sourceSpans(l):null;if(!a&&Q(s))return null;let d=a??F(s,r.cell);if(!d)return null;let u=I(l?l.content:d),c=r.offset,h=a?"source":"rich",f=null;for(let p of t?[t]:this.entries){if(a&&p.config.richOnly)continue;let m=p.matcher({text:u,caret:c,content:d,triggers:p.triggers});if(!m||f&&m.from<=f.from||m.from<0||m.from>=c||m.to<c||m.to>u.length||!Mn(u,m.from,p.triggers,c)||m.query.length>(p.config.maxLength??30))continue;let y=zl(d,m.from),g=p.config.allow;(g?g({editor:this.editor,block:s,cell:r.cell,from:m.from,query:m.query,textBefore:u.slice(0,m.from),excluded:y,explicit:e,mode:h}):!y)&&(f={...m,entry:p,blockId:s.id,cell:r.cell,text:u,mode:h})}return f}refresh(){let e=this.session,{menu:t,source:n}=e.entry,i=e.query,r=this.editor.isComposing;if(e.requested===i&&!(this.requestedComposing&&!r)){this.shown&&this.place();return}this.session={...e,requested:i};let s=this.session,l=s.entry,a=()=>this.session?.entry===l&&this.session.requested===i,d=!0,u=h=>{if(!a())return;let f=l.config;t&&(t.busy=!1);let p=(h??[]).slice(0,f.limit??50);if(p.length===0&&r&&this.items.length>0)return this.report();let m=p.length===0&&(!f.emptyLabel||i.length>3);!m&&!d&&!this.isOpen&&(this.keysFrom=Date.now()+Vu);let y=this.items[this.active]?.id,g=y===void 0?-1:p.findIndex(b=>b.id===y),v=p.length===0?-1:Math.max(0,g);this.items=p,this.active=v,this.message=p.length===0&&!m?f.emptyLabel:null,this.itemsChanged=!0,t&&(m?t.hide():(t.setSections(Qu(p,i,b=>this.pick(b)),f.emptyLabel),t.highlight(v))),m?(this.host.root.removeAttribute("aria-haspopup"),this.host.root.removeAttribute("aria-controls"),this.host.syncActiveDescendant()):this.place(),this.report()},c=()=>{if(!a()||this.shown)return this.report();this.message=this.editor.labels.loading,t?.setMessage(this.message,"mbe-menu-loading"),this.place(),this.report()};this.requestedComposing=r,n.run(h=>l.config.items({query:i,editor:this.editor,explicit:s.explicit,composing:r,signal:h}),{show:u,loading:c},l.config.debounce??0),d=!1,n.pending&&t?.isOpen&&(t.busy=!0)}anchor(){let e=this.session,t=r=>e.cell?{blockId:e.blockId,offset:r,cell:e.cell}:{blockId:e.blockId,offset:r},n=e.from+(Mn(e.text,e.from,e.entry.triggers)?.length??1),i=this.editor.textRect(t(e.from),t(n));return Vl(i?.rect??null,this.editor.caretRect(),i?.rtl??!1,Ul(this.host.root))}place(){let e=this.session,{menu:t,listboxId:n}=e.entry,i=this.host.root,r=t?this.anchor():null;t&&r?t.popup.show(r.rect,this.side,4,r.align):t?.hide(),t&&(this.side=t.popup.side),this.isOpen?(i.setAttribute("aria-haspopup","listbox"),i.setAttribute("aria-controls",n)):(i.removeAttribute("aria-haspopup"),i.removeAttribute("aria-controls")),this.host.syncActiveDescendant()}pick(e){this.editor.isComposing&&this.host.endComposition();let t=this.session;if(!t)return;let{entry:n,blockId:i,cell:r,from:s,to:l,query:a,text:d,mode:u}=t,c=y=>r?{blockId:i,offset:y,cell:r}:{blockId:i,offset:y},h={from:c(s),to:c(l)};if(this.close(),n.config.command){n.config.command({editor:this.editor,range:h,item:e,query:a});return}let f=d[l],m=f!==void 0&&!(f===`
108
+ `&&u==="source")&&Uu.test(f)?"":" ";this.editor.commands.insertText(n.triggers[0]+(e.value??e.id??e.label)+m,{range:h})}};function Wu(o,e){return o.id??`${e}`}function Qu(o,e,t){let n=[];return o.forEach((i,r)=>{let s=n[n.length-1];(!s||i.section!==s.title)&&n.push(s={title:i.section,items:[]}),s.items.push({id:Wu(i,r),label:i.label,detail:i.detail,icon:i.icon,mark:e,run:()=>t(i)})}),n}var kt=class{constructor(e,t,n,i){this.element=e;this.render=n;this.onRemove=i;this.blockId=t,this.paint()}blockId;offset=0;isRemoved=!1;cleanup=null;update(e){this.isRemoved||(e&&(this.render=e),this.paint())}remove(){this.isRemoved||(this.isRemoved=!0,this.cleanup?.(),this.cleanup=null,this.element.remove(),this.onRemove(this))}paint(){this.cleanup?.(),this.element.replaceChildren();let e=this.render(this.element);this.cleanup=typeof e=="function"?e:null}};function Wl(o,e,t){let n=o.split(/-(?!$)/),i=n.pop(),r=!1,s=!1,l=!1,a=!1;for(let d of n)if(/^(cmd|meta|m)$/i.test(d))a=!0;else if(/^a(lt)?$/i.test(d))s=!0;else if(/^(c|ctrl|control)$/i.test(d))r=!0;else if(/^s(hift)?$/i.test(d))l=!0;else if(/^mod$/i.test(d))t?a=!0:r=!0;else throw new Error(`Unrecognized modifier name: ${d}`);return i==="Space"&&(i=" "),{key:i.length===1?i.toLowerCase():i,ctrl:r,alt:s,shift:l,meta:a,handler:e}}function ju(o){let e=/^(?:Key([A-Z])|Digit([0-9]))$/.exec(o.code);return e?(e[1]??e[2]).toLowerCase():null}function Ql(o,e){if(o.ctrl!==e.ctrlKey||o.alt!==e.altKey||o.meta!==e.metaKey)return!1;let t=e.key.length===1?e.key.toLowerCase():e.key;return t===o.key&&(o.shift===e.shiftKey||e.key.length===1&&!o.shift&&/[^a-z0-9]/.test(t))?!0:o.shift===e.shiftKey&&ju(e)===o.key}var Zl=[["textStyle"],["bold","italic","strike","inlineCode","link"],["quote","codeBlock","list"]],Xl=Zl.flat(),Gu=["textStyle","quote","codeBlock","list"],re=o=>`${ie?"Meta":"Control"}+${o}`,jl={bold:{mark:"bold",className:"mbe-tool-bold",keys:re("B")},italic:{mark:"italic",className:"mbe-tool-italic",keys:re("I")},strike:{mark:"strike",className:"mbe-tool-strike",keys:re("Shift+X")},inlineCode:{mark:"code",className:"mbe-tool-code",keys:re("E")}},Zu=[{id:"text",spec:{type:"paragraph"},keys:re("Alt+0")},{id:"heading1",spec:{type:"heading",level:1},keys:re("Alt+1")},{id:"heading2",spec:{type:"heading",level:2},keys:re("Alt+2")},{id:"heading3",spec:{type:"heading",level:3},keys:re("Alt+3")},{id:"heading4",spec:{type:"heading",level:4},keys:re("Alt+4")}],gr=[{id:"bulletList",listType:"bullet",keys:re("Shift+8")},{id:"numberedList",listType:"ordered",keys:re("Shift+7")},{id:"todoList",listType:"task",keys:re("Shift+9")}],Xu=500,Yu=300;function Gl(o){let e=zn(o.state),t=r=>r.type==="paragraph"?"text":r.type==="heading"&&r.level<=4?`heading${r.level}`:null,n=r=>{let s=e[0]?r(e[0]):null;return e.every(l=>r(l)===s)?s:null},i=e.length>0;return{style:n(t),allHeadings:i&&e.every(r=>r.type==="heading"),listType:n(r=>r.type==="listItem"?r.listType:null),allListItems:i&&e.every(r=>r.type==="listItem"),allQuotes:i&&e.every(r=>M(r)!==null)}}var Io=class{constructor(e,t=Xl){this.editor=e;let n=e.root.ownerDocument;this.popup=new we(e.root,"mbe-toolbar");let i=this.popup.el;i.setAttribute("role","toolbar"),this.tooltip=new we(e.root,"mbe-tooltip"),this.tooltip.el.setAttribute("aria-hidden","true");let r=e.labels,s=(d,u,c,h,f)=>{let p=n.createElement("button");p.type="button",p.className=`mbe-tool ${c}`;let m=X(n,e.icon(u));return m&&p.appendChild(m),p.setAttribute("aria-label",r[d==="codeBlock"?"code":d]),h&&p.setAttribute("aria-keyshortcuts",h),p.addEventListener("click",f),p.addEventListener("pointerenter",y=>{y.pointerType==="mouse"&&this.scheduleTooltip(p)}),p.addEventListener("pointerleave",()=>this.hideTooltip()),this.buttons.set(d,p),p},l=(d,u,c)=>{let h=s(d,d==="list"?"bulletList":"text",u,null,()=>this.toggleMenu(g));h.classList.add("mbe-tool-menu"),h.setAttribute("aria-haspopup","menu"),h.setAttribute("aria-expanded","false");let f=n.createElement("span");f.className="mbe-tool-icon",f.append(...h.childNodes);let p=n.createElement("span");p.className="mbe-tool-chevron";let m=X(n,e.icon("chevronDown"));m&&p.appendChild(m),h.append(f,p);let y=new Xe(e.root,c,"menu");y.el.setAttribute("aria-label",r[d]),y.checkIcon=e.icon("selected"),y.onPicked=()=>this.closeMenu(),y.onHighlight=()=>this.onMenuChange?.(),h.setAttribute("aria-controls",y.el.id);let g={button:h,icon:f,menu:y,iconName:d==="list"?"bulletList":"text"};return g},a=new Set(t);for(let d of Zl){let u=d.filter(c=>a.has(c));if(u.length!==0){if(this.buttons.size>0){let c=n.createElement("span");c.className="mbe-tool-sep",i.appendChild(c),this.separators.push(c)}for(let c of u){let h=jl[c],f;h?(f=s(c,c,h.className,h.keys,()=>this.apply(p=>We(p,h.mark))),f.setAttribute("aria-pressed","false")):c==="link"?(f=s(c,"link","mbe-tool-link",re("K"),()=>e.openLinkPopover()),f.setAttribute("aria-pressed","false")):c==="quote"?(f=s(c,"quote","mbe-tool-quote",null,()=>this.apply(p=>ht(p,{type:"quote"}))),f.setAttribute("aria-pressed","false")):c==="codeBlock"?f=s(c,"code","mbe-tool-code-block",re("Alt+C"),()=>this.apply(p=>ht(p,{type:"code"}))):c==="textStyle"?(this.textStyle=l(c,"mbe-tool-text-style","mbe-text-style-menu"),f=this.textStyle.button):(this.list=l("list","mbe-tool-list","mbe-list-menu"),f=this.list.button),i.appendChild(f)}}}}popup;tooltip;buttons=new Map;separators=[];textStyle=null;list=null;openTrigger=null;tooltipTimer;tooltipHiddenAt=0;onMenuChange=null;get isOpen(){return this.popup.isOpen}get menu(){return this.openTrigger?.menu??null}contains(e){return this.popup.el.contains(e)||!!this.openTrigger?.menu.el.contains(e)}show(){let e=this.editor.selectionRect();if(!e)return this.hide();this.update();let t=this.editor.root.ownerDocument.defaultView;this.popup.el.style.maxWidth=`${Math.max(xo(t).width-16,0)}px`,this.popup.show(e,Ft()?"below":"above",8),this.openTrigger&&this.placeMenu(this.openTrigger)}hide(){this.closeMenu(),this.hideTooltip(),this.popup.hide()}closeMenu(){let e=this.openTrigger;e&&(this.openTrigger=null,e.menu.hide(),e.button.classList.remove("mbe-open"),e.button.setAttribute("aria-expanded","false"),this.onMenuChange?.())}destroy(){clearTimeout(this.tooltipTimer),this.popup.destroy(),this.tooltip.destroy(),this.textStyle?.menu.destroy(),this.list?.menu.destroy()}apply(e){this.hideTooltip(),this.editor.run(e),this.isOpen&&this.update()}update(){let e=this.editor;for(let[a,d]of this.buttons){let u=jl[a];u&&br(d,e.isActive(u.mark))}let t=this.buttons.get("link");t&&br(t,e.isActive("link"));let{anchor:n,focus:i}=e.state.selection,r=!!i.cell&&n.blockId===i.blockId;for(let a of Gu)this.buttons.get(a)?.toggleAttribute("hidden",r);r&&this.closeMenu();for(let a of this.separators){let d=(u,c)=>{for(let h=u;h&&!h.classList.contains("mbe-tool-sep");h=h[c])if(!h.hidden)return!0;return!1};a.hidden=!d(a.previousElementSibling,"previousElementSibling")||!d(a.nextElementSibling,"nextElementSibling")}if(r)return;let s=Gl(e),l=this.buttons.get("quote");if(l&&br(l,s.allQuotes),this.textStyle&&(this.setTriggerIcon(this.textStyle,s.style??"text"),this.textStyle.button.classList.toggle("mbe-active",s.allHeadings)),this.list){let a=gr.find(d=>d.listType===s.listType);this.setTriggerIcon(this.list,a?.id??"bulletList"),this.list.button.classList.toggle("mbe-active",s.allListItems)}}setTriggerIcon(e,t){if(e.iconName===t)return;e.iconName=t;let n=X(e.icon.ownerDocument,this.editor.icon(t));e.icon.replaceChildren(...n?[n]:[])}toggleMenu(e){let t=this.openTrigger===e;if(this.closeMenu(),this.hideTooltip(),t)return;let n=Gl(this.editor),i=this.editor.labels,r,s;e===this.textStyle?(s=n.style??void 0,r=Zu.map(({id:l,spec:a,keys:d})=>({id:l,label:i[l],icon:this.editor.icon(l),labelClass:`mbe-menu-${l}`,keyShortcuts:d,checked:l===s,run:()=>l!==s&&this.apply(u=>Ge(u,a))}))):(s=gr.find(l=>l.listType===n.listType)?.id,r=gr.map(({id:l,listType:a,keys:d})=>({id:l,label:i[l],icon:this.editor.icon(l),keyShortcuts:d,checked:l===s,run:()=>this.apply(u=>ht(u,{type:"listItem",listType:a}))}))),e.menu.setSections([{items:r}]),s&&e.menu.highlightId(s),this.openTrigger=e,e.button.classList.add("mbe-open"),e.button.setAttribute("aria-expanded","true"),this.placeMenu(e),this.onMenuChange?.()}placeMenu(e){let t=this.editor.root.ownerDocument.defaultView.getComputedStyle(this.editor.root).direction==="rtl";e.menu.popup.show(e.button.getBoundingClientRect(),this.popup.side,4,t?"end":"start")}scheduleTooltip(e){if(clearTimeout(this.tooltipTimer),this.openTrigger)return;let t=Date.now()-this.tooltipHiddenAt<Yu?0:Xu;this.tooltipTimer=setTimeout(()=>{if(!this.isOpen||this.openTrigger||!e.isConnected)return;this.tooltip.el.textContent=e.getAttribute("aria-label"),this.tooltip.show(e.getBoundingClientRect(),this.popup.side,6);let n=e.getBoundingClientRect(),i=this.tooltip.el.getBoundingClientRect(),r=this.editor.root.ownerDocument.defaultView,s=Math.max(8,Math.min(n.left+(n.width-i.width)/2,r.innerWidth-i.width-8));this.tooltip.el.style.left=`${parseFloat(this.tooltip.el.style.left)+s-i.left}px`},t)}hideTooltip(){clearTimeout(this.tooltipTimer),this.tooltip.isOpen&&(this.tooltip.hide(),this.tooltipHiddenAt=Date.now())}};function br(o,e){o.classList.toggle("mbe-active",e),o.setAttribute("aria-pressed",String(e))}var Lo=class{popup;input;removeButton;done=null;constructor(e){let t=e.root.ownerDocument;this.popup=new we(e.root,"mbe-input-popover"),this.input=t.createElement("input"),this.input.className="mbe-popover-input",this.removeButton=t.createElement("button"),this.removeButton.type="button",this.removeButton.className="mbe-tool",this.popup.el.append(this.input,this.removeButton),this.input.addEventListener("keydown",n=>{n.key==="Enter"?(n.preventDefault(),this.finish(this.input.value.trim())):n.key==="Escape"&&(n.preventDefault(),this.finish(null))}),this.input.addEventListener("blur",()=>{setTimeout(()=>{this.popup.isOpen&&t.activeElement!==this.input&&this.close()},150)}),this.removeButton.addEventListener("click",()=>this.finish(""))}get isOpen(){return this.popup.isOpen}contains(e){return this.popup.el.contains(e)}open(e,t,n){this.done=n,this.input.type=t.type,this.input.value=t.value,this.input.placeholder=t.placeholder,this.input.setAttribute("aria-label",t.label),this.removeButton.textContent=t.removeLabel??"",this.removeButton.hidden=!t.removeLabel||t.value==="",this.popup.show(e,"below"),this.input.focus(),this.input.select()}close(){this.done=null,this.popup.hide()}finish(e){let t=this.done;this.done=null,this.popup.hide(),t?.(e)}destroy(){this.popup.destroy()}};var Yl=24,Ju=8,Jl=16,Bo=class{constructor(e){this.editor=e;let t=e.root,n=t.ownerDocument,i=e.labels;this.frame=n.createElement("div"),this.frame.className="mbe-ui mbe-image-frame",this.frame.hidden=!0;let r=l=>{let a=n.createElement("div");return a.className=`mbe-resize-handle mbe-resize-handle-${l}`,a.dataset.side=l,a.title=i.resizeImage,a.setAttribute("aria-hidden","true"),this.frame.appendChild(a),a};this.handles={left:r("left"),right:r("right")};let s=(l,a,d)=>{l.addEventListener(a,d),this.cleanup.push(()=>l.removeEventListener(a,d))};s(t,"mouseover",l=>this.onOver(l)),s(t,"mouseleave",()=>this.scheduleUnhover());for(let l of[this.frame,this.handles.left,this.handles.right])s(l,"mouseenter",()=>this.cancelUnhover()),s(l,"mouseleave",()=>this.scheduleUnhover());s(this.frame,"mousedown",l=>l.preventDefault());for(let l of["left","right"])s(this.handles[l],"pointerdown",a=>this.startDrag(a,l));s(this.frame,"pointermove",l=>this.moveDrag(l)),s(this.frame,"pointerup",l=>this.endDrag(l,!0)),s(this.frame,"pointercancel",l=>this.endDrag(l,!1)),s(this.frame,"lostpointercapture",l=>this.endDrag(l,!0))}frame;handles;hovered=null;selected=null;framed=null;drag=null;hideTimer=null;cleanup=[];contains(e){return this.frame.contains(e)}get isDragging(){return this.drag!==null}update(e){this.selected=e,this.drag||this.placeFrame()}reposition(){this.drag||(this.selected&&!this.selected.el.isConnected&&(this.selected=null),this.placeFrame())}hide(){this.drag||(this.hovered=null,this.selected=null,this.placeFrame())}destroy(){this.cancelUnhover();for(let e of this.cleanup)e();this.frame.remove()}onOver(e){if(this.drag||!this.editor.isEditable)return;let t=e.target,n=t instanceof HTMLImageElement&&t.classList.contains("mbe-image")?t:null;n?(this.cancelUnhover(),this.hovered=n,this.placeFrame()):this.hovered&&this.scheduleUnhover()}scheduleUnhover(){this.cancelUnhover(),this.hideTimer=setTimeout(()=>{this.hideTimer=null,this.hovered=null,this.placeFrame()},250)}cancelUnhover(){this.hideTimer!==null&&clearTimeout(this.hideTimer),this.hideTimer=null}placeFrame(){let e=this.editor.isEditable,t=this.hovered?.isConnected?this.hovered:null,n=this.drag?.el??(e?t??this.selected?.el??null:null),i=n instanceof HTMLImageElement&&n.isConnected?n:null,r=i?.getBoundingClientRect();if(!i||!r||r.width===0||r.height===0){this.frame.hidden=!0,this.framed=null;return}this.framed!==i&&(this.framed=i,i.complete||i.addEventListener("load",()=>this.framed===i&&this.placeFrame(),{once:!0}));let s=yr(i,r);if(!s||s.width<Math.min(r.width,Jl)||s.height<Math.min(r.height,Jl)){this.frame.hidden=!0;return}this.frame.hidden=!1;let l=$t(this.frame,this.editor.root);this.frame.style.left=`${Math.round(s.left-l.x)}px`,this.frame.style.top=`${Math.round(s.top-l.y)}px`,this.frame.style.width=`${Math.round(s.width)}px`,this.frame.style.height=`${Math.round(s.height)}px`,this.frame.classList.toggle("mbe-image-frame-small",s.width<64||s.height<40)}startDrag(e,t){let n=this.framed;if(!n||this.drag||e.button!==0||!this.editor.isEditable)return;let i=this.editor.imageTarget(n);if(!i)return;e.preventDefault(),this.handles[t].setPointerCapture?.(e.pointerId);let r=n.getBoundingClientRect().width,s=Array.from(this.editor.root.querySelectorAll("img.mbe-image")).filter(d=>d!==n).map(d=>d.getBoundingClientRect().width).filter(d=>d>0),l=Math.max(Yl,eh(n)),a=n.closest(".mbe-image-block")?.getAttribute("data-align")==="center"?2:1;this.drag={el:n,side:t,pointer:e.pointerId,startX:e.clientX,startWidth:r,max:l,snaps:[...s,l],width:r,factor:a},this.frame.classList.add("mbe-image-resizing"),this.editor.selectImageAt(i.pos)}moveDrag(e){let t=this.drag;if(!t||e.pointerId!==t.pointer)return;e.preventDefault();let n=(e.clientX-t.startX)*(t.side==="right"?1:-1)*t.factor,i=Math.min(t.max,Math.max(Yl,t.startWidth+n)),r=t.snaps.find(s=>Math.abs(s-i)<=Ju);r!==void 0&&(i=Math.min(t.max,r)),t.width=Math.round(i),t.el.style.width=`${t.width}px`,t.el.style.height="auto",this.placeFrame()}endDrag(e,t){let n=this.drag;if(!n||e.pointerId!==n.pointer)return;this.drag=null,this.frame.classList.remove("mbe-image-resizing"),this.handles[n.side].releasePointerCapture?.(e.pointerId),n.el.style.width="",n.el.style.height="";let i=n.el.isConnected?this.editor.imageTarget(n.el):null;t&&i&&Math.round(n.width)!==Math.round(n.startWidth)?this.editor.updateImageAt(i.pos,{width:n.width}):this.editor.refreshImageUi()}};function yr(o,e){let t=o.ownerDocument,n=t.defaultView,i=e.left,r=e.top,s=e.right,l=e.bottom,a=(d,u,c,h)=>{i=Math.max(i,d),r=Math.max(r,u),s=Math.min(s,c),l=Math.min(l,h)};for(let d=o.parentElement;d&&d!==t.body&&d!==t.documentElement;d=d.parentElement){let u=n?.getComputedStyle(d),c=d.scrollHeight>d.clientHeight&&/auto|scroll|overlay/.test(u?.overflowY??""),h=d.scrollWidth>d.clientWidth&&/auto|scroll|overlay/.test(u?.overflowX??"");if(!c&&!h)continue;let f=d.getBoundingClientRect(),p=f.left+d.clientLeft,m=f.top+d.clientTop;a(p,m,p+d.clientWidth,m+d.clientHeight)}return a(0,0,t.documentElement.clientWidth,t.documentElement.clientHeight),s<=i||l<=r?null:{left:i,top:r,width:s-i,height:l-r}}function eh(o){let e=o.parentElement,t=o.ownerDocument.defaultView;for(;e&&t.getComputedStyle(e).display.startsWith("inline");)e=e.parentElement;if(!e)return o.getBoundingClientRect().width;let n=t.getComputedStyle(e);return e.clientWidth-parseFloat(n.paddingLeft||"0")-parseFloat(n.paddingRight||"0")}var th=[{align:"left",icon:"imageAlignLeft"},{align:"center",icon:"imageAlignCenter"},{align:"right",icon:"imageAlignRight"}],Ao=class{constructor(e,t){this.editor=e;let n=e.root.ownerDocument,i=e.labels;this.popup=new we(e.root,"mbe-image-toolbar");let r=this.popup.el;r.setAttribute("role","toolbar"),r.setAttribute("aria-label",i.imageSection);let s=(a,d,u)=>{let c=n.createElement("button");c.type="button",c.className=`mbe-tool ${d}`;let h=X(n,e.icon(a));return h&&c.appendChild(h),c.setAttribute("aria-label",i[a]),c.title=i[a],c.addEventListener("click",()=>{this.target&&u()}),c};for(let{align:a,icon:d}of th){let u=s(d,`mbe-tool-${d}`,()=>t.align(this.target,a));u.setAttribute("aria-pressed","false"),this.alignButtons.push({align:a,button:u}),r.appendChild(u)}this.alignSep=n.createElement("span"),this.alignSep.className="mbe-tool-sep",r.appendChild(this.alignSep),r.appendChild(s("altText","mbe-tool-altText",()=>t.altText(this.target))),this.resetButton=s("resetImageSize","mbe-tool-resetImageSize",()=>t.resetSize(this.target)),r.appendChild(this.resetButton);let l=n.createElement("span");l.className="mbe-tool-sep",r.appendChild(l),r.appendChild(s("delete","mbe-tool-delete",()=>t.remove(this.target)))}popup;alignButtons=[];alignSep;resetButton;target=null;get isOpen(){return this.popup.isOpen}contains(e){return this.popup.el.contains(e)}show(e,t){let n=yr(e.el,e.el.getBoundingClientRect());if(!n)return this.hide();this.target=e;let i=e.image.align??"left";for(let{align:d,button:u}of this.alignButtons)u.hidden=!t,u.classList.toggle("mbe-active",t&&d===i),u.setAttribute("aria-pressed",String(t&&d===i));this.alignSep.hidden=!t,this.resetButton.hidden=!e.image.width;let{left:r,top:s,width:l,height:a}=n;this.popup.show({left:r,top:s,right:r+l,bottom:s+a},Ft()?"below":"above",8)}hide(){this.target=null,this.popup.hide()}destroy(){this.popup.destroy()}};var W="data-block-id";function Cr(o){return`code:${o.trim().toLowerCase()}`}var Kt="data-content",In="mbe-source-text",Ir="mbe-source-line",$o="data-mbe-fill",xr="data-mbe-pending",ia="data-atom",ra="data-list-start",nh="data-quote-joined",oh="data-quote-continued",ih="data-section-hidden",rh="data-collapsed",sh="data-in-section",lh={bold:["strong"],italic:["em"],strike:["s"],code:["code"],html:["span","mbe-raw-html"]},ah={};function qe(...o){return o.filter(Boolean).join(" ")}function ch(o,e){let t=dh(o,e);return Wt(o)&&o.quote?qe(t,e.blockquote)||void 0:t}function dh(o,e){switch(o.type){case"paragraph":return e.paragraph;case"heading":return e.heading?.[o.level];case"quote":return e.blockquote;case"listItem":return e[`${o.listType}List`];case"code":return e.codeBlock;case"table":return e.table;case"raw":return e.raw;case"divider":return;case"details":return e.details;case"detailsEnd":return}}var Ln=o=>{let e=o.replace(/^[\u0000- ]+|[\u0000- ]+$/g,"").replace(/[\t\n\r]/g,""),t=/^([a-z][a-z0-9+.-]*):/i.exec(e);return t?["http","https","mailto","tel"].includes(t[1].toLowerCase())?e:null:e},Je="block";function Cn(o,e){return o?`${o.row}:${o.col}@${e}`:`@${e}`}function Lr(o,e){if(o===e)return!0;if(!o||!e||o.size!==e.size)return!1;for(let t of o)if(!e.has(t))return!1;return!0}function Br(o){return`callout${o[0].toUpperCase()}${o.slice(1)}`}function uh(o,e){let t=Y(e);if(t===null)return;o.classList.add("mbe-image-block");let n=C(e.content,t,t+1)[0]?.image?.align;n&&(o.dataset.align=n)}function hh(o,e,t,n){let i=t.doc,r=i.createElement("blockquote");r.dir="auto",r.dataset.callout=e;let s=i.createElement("div");return s.className="mbe-content",vt(s,o.content,t,o,n),r.append(No(e,t),s),r}function No(o,e){let t=Br(o),n=e.doc.createElement("div");n.className="mbe-callout-icon",n.contentEditable="false",n.setAttribute("role","img"),n.setAttribute("aria-label",e.labels[t]);let i=e.icon?.(t);return i&&n.appendChild(i),n}function sa(o,e,t){let{doc:n,labels:i}=e,r=(c,h)=>{let f=n.createElement(c);return h&&(f.className=h),f},s,l=t?.has(Je)||e.source?null:e.blockView?.(o);if(l)s=r("div","mbe-view-block mbe-block-view"),s.contentEditable="false",s.appendChild(l);else switch(o.type){case"paragraph":case"heading":case"quote":if(o.type==="quote"&&o.callout){s=hh(o,o.callout,e,t);break}s=r(o.type==="paragraph"?"p":o.type==="quote"?"blockquote":`h${o.level}`),s.dir="auto",vt(s,o.content,e,o,t),o.type==="paragraph"&&uh(s,o);break;case"listItem":{s=r(o.quote?"blockquote":"div"),o.callout&&(s.dataset.callout=o.callout,s.appendChild(No(o.callout,e))),s.dir="auto",s.dataset.listType=o.listType,s.dataset.indent=String(o.indent);let c=r("span","mbe-marker");if(c.contentEditable="false",o.listType==="task"){let f=r("input","mbe-checkbox");f.type="checkbox",f.tabIndex=-1,f.checked=o.checked,c.appendChild(f)}let h=r("div","mbe-content");vt(h,o.content,e,o,t),s.append(c,h);break}case"code":{if(e.source){s=r("div"),s.spellcheck=!1;let y=r("div",In);y.setAttribute(Kt,""),aa(y,o,e),s.appendChild(y);break}let c=t?.has(Je)?null:e.view?.(Cr(o.language),I(o.content),"block");if(c){s=c,s.classList.add("mbe-view-block"),s.contentEditable="false",s.dataset.language=o.language;break}s=r("div"),s.dataset.language=o.language;let h=r("div","mbe-code-bar");h.contentEditable="false";let f=r("input","mbe-code-lang");f.value=o.language,f.spellcheck=!1,f.setAttribute("aria-label",i.language),f.placeholder=i.plainText,h.appendChild(f),e.codeCopy&&h.appendChild(yh(e));let p=r("pre"),m=r("code");m.spellcheck=!1,vt(m,o.content,e,o,void 0,void 0,!1),p.appendChild(m),s.append(h,p);break}case"raw":{let c=I(o.content),h=t?.has(Je)===!0,f=o.syntax==="html"&&!h&&e.views?.has("html")?tl(c,e.markdown):null,p=o.syntax==="footnote"&&!h&&e.views?.has("footnote")?da(c):null,m=o.syntax==="markdown"&&!h&&e.views?.get("markdown")===Nr,y=h?null:m?Sh(c,e):p?ua(p,e):e.view?.(o.syntax,f?f.html:c,"block");y?(s=y,s.classList.add("mbe-view-block"),o.syntax==="html"&&s.classList.add("mbe-view-html"),s.contentEditable="false",f&&Ar(s,f.slots.length,g=>kh(f.slots[g],e),e.doc)):(s=r("pre"),s.spellcheck=!1,vt(s,o.content,e,o,void 0,void 0,!1)),s.dataset.syntax=o.syntax;break}case"divider":s=r("div"),s.contentEditable="false",s.appendChild(r("hr",e.classes.divider));break;case"details":{s=r("div"),s.dir="auto";let c=r("span","mbe-details-marker");c.contentEditable="false";let h=r("button","mbe-details-toggle");h.type="button",h.tabIndex=-1;let f=e.icon?.("chevronRight");f&&h.appendChild(f),c.appendChild(h);let p=r("div","mbe-content");vt(p,o.content,e,o,void 0,void 0,!1),s.append(c,p);break}case"detailsEnd":s=r("div"),s.contentEditable="false";break;case"table":{s=r("div"),s.contentEditable="false";let c=r("table"),h=r("tbody");o.rows.forEach((f,p)=>{let m=r("tr");f.forEach((y,g)=>{let v=r(p===0?"th":"td");v.contentEditable="true",v.dir="auto",v.dataset.row=String(p),v.dataset.col=String(g);let b=o.align[g];b&&(v.style.textAlign=b),vt(v,y,e,o,t,{row:p,col:g}),m.appendChild(v)}),h.appendChild(m)}),c.appendChild(h),s.appendChild(c);break}}if(!l&&!e.source&&o.type!=="listItem"&&Wt(o)&&o.quote){let c=s;s=r("blockquote"),o.type==="heading"&&(s.dir="auto"),o.callout&&(s.dataset.callout=o.callout,s.appendChild(No(o.callout,e))),c.classList.add("mbe-content"),c.contentEditable==="false"&&(s.contentEditable="false"),c.classList.contains("mbe-view-block")&&s.classList.add("mbe-view-block");for(let h of["language","syntax"])c.dataset[h]!==void 0&&(s.dataset[h]=c.dataset[h]);s.appendChild(c)}s.setAttribute(W,o.id);let a=o.type==="listItem"?"list-item":o.type==="detailsEnd"?"details-end":o.type==="code"&&e.source?"source":o.type,d=`${s.className?s.className+" ":""}mbe-block mbe-${a}`;o.type==="listItem"&&o.checked&&(d+=" mbe-checked"),"content"in o&&B(o.content)===0&&(d+=" mbe-empty");let u=ch(o,e.classes);return u&&(d+=" "+u),s.className=d,s}var wr=new WeakMap,fh=[];function ph(o,e){let t=e.map((s,l)=>({d:s,index:l})).filter(s=>s.d.to>s.d.from).sort((s,l)=>s.d.from-l.d.from),n=0,i=[],r=[];for(let s=0;;){let l=o.indexOf(`
109
+ `,s),a=l===-1?o.length:l,d=i.filter(c=>c.d.to>s);for(;n<t.length&&t[n].d.from<a;){let c=t[n++];c.d.to>s&&d.push(c)}i=d.filter(c=>c.d.to>a),d.length>1&&d.sort((c,h)=>c.index-h.index);let u=d.length===0?fh:d.map(({d:c})=>({...c,from:Math.max(c.from,s)-s,to:Math.min(c.to,a)-s})).filter(c=>c.to>c.from);if(r.push({text:o.slice(s,a),decorations:u}),l===-1)return r;s=l+1}}function ea(o,e){return o.text===e.text&&$n(o.decorations,e.decorations)}function Ro(o){return o instanceof HTMLElement&&o.classList.contains(Ir)}function*la(o){let e=wr.get(o),t=e&&e.length===o.childElementCount?e:null,n=0;for(let i=o.firstChild;i;i=i.nextSibling)Ro(i)&&(yield[i,t?t[n].text.length:i.textContent.length],n++)}function aa(o,e,t){gh(o,I(e.content),t.decorateSource?.(e)??[],t)}function mh(o,e){let t=e.doc,n=t.createElement("div");if(n.className=Ir,n.dir="auto",o.text.length===0)n.appendChild(Tr(t));else if(o.decorations.length===0)n.appendChild(t.createTextNode(o.text));else for(let i of Yo([{text:o.text,marks:[]}],o.decorations))n.appendChild(fa(t.createTextNode(i.span.text),i.decorations,t));return n}function gh(o,e,t,n){let i=ph(e,t);o.classList.toggle("mbe-empty-content",e.length===0);let r=Array.from(o.childNodes).filter(Ro),s=wr.get(o)??[];r.length!==s.length&&(s=[],o.replaceChildren());let l=0;for(;l<s.length&&l<i.length&&ea(s[l],i[l]);)l++;let a=0;for(;a<s.length-l&&a<i.length-l&&ea(s[s.length-1-a],i[i.length-1-a]);)a++;let d=n.doc.createDocumentFragment();for(let c=l;c<i.length-a;c++)d.appendChild(mh(i[c],n));let u=a>0?r[s.length-a]:null;for(let c=l;c<s.length-a;c++)r[c].remove();if(o.insertBefore(d,u),o.childNodes.length!==i.length)for(let c of Array.from(o.childNodes))Ro(c)||c.remove();wr.set(o,i)}function bh(o){let e=[],t="";for(let n=o.firstChild;n;n=n.nextSibling)Ro(n)?(n!==o.firstChild&&e.push(t),t=Vt(n).map(Dr).join("")):t+=n.nodeType===3?n.data:n.hasAttribute($o)?"":n.textContent??"";return e.push(t),e.join(`
110
+ `)}function vt(o,e,t,n,i,r,s=!0){let l=t.doc;if(o.setAttribute(Kt,""),B(e)===0){o.classList.add("mbe-empty-content"),o.appendChild(Tr(l));return}let a=n.type==="code"?t.decorateCode?.(n)??[]:s&&t.decorate?t.decorate(n,e,r):[],d=e.length===1?e[0]:null;d&&a.length===0&&d.marks.length===0&&!d.link&&!d.token&&!d.image?o.appendChild(l.createTextNode(d.text)):Ih(e,o,t,a,i,r);let u=e[e.length-1];u&&u.text.endsWith(`
111
+ `)&&o.appendChild(Tr(l))}function yh(o){let e=o.doc.createElement("button");e.type="button",e.className="mbe-code-copy",e.tabIndex=-1,e.setAttribute("aria-label",o.labels.copyCode),e.title=o.labels.copyCode;let t=o.icon?.("copyCode");return t&&e.appendChild(t),e}function Ar(o,e,t,n){if(e===0)return;let i=[],r=n.createTreeWalker(o,4);for(let l=r.nextNode();l;l=r.nextNode())l.nodeValue.includes("\uE000")&&i.push(l);let s=new Set;for(let l of i){let a=l.nodeValue,d=n.createDocumentFragment(),u=0;for(let c of a.matchAll(el)){c.index>u&&d.append(a.slice(u,c.index));let h=Number(c[1]);h<e&&!s.has(h)&&(s.add(h),d.append(t(h))),u=c.index+c[0].length}u<a.length&&d.append(a.slice(u)),l.replaceWith(d)}if(!o.hasAttribute(xr))for(let l=0;l<e;l++)s.has(l)||o.appendChild(t(l))}function kh(o,e){let t=e.doc.createElement("div");return t.className="mbe-flow",Sr(t,o,e),Do(t),t}function Sr(o,e,t){let n=new Map,i=t.blockView?{...t,blockView:void 0}:t;for(let r of e){let s=sa(r,i);n.set(r.id,s),o.appendChild(s)}Er({blocks:e},r=>n.get(r),new WeakMap,new Set,t.labels)}var vh=/^(\[\^((?:[^\]\s\\]|\\.)+)\]:)[ \t]*(.*)$/,xh=/\[\^((?:[^\]\s\\]|\\.)+)\]/g,ca=o=>o.replace(/\\(.)/g,"$1");function da(o){let[e="",...t]=o.split(`
112
+ `),n=vh.exec(e);if(!n)return null;let i=[n[3],...t.map(r=>r.replace(/^(?: {1,4}|\t)/,""))].join(`
113
+ `);return{label:ca(n[2]),head:`${n[1]} `,body:i}}function ua(o,e){let t=e.view?.("footnote",o.head+ko(0),"block")??null;return t&&Ar(t,1,()=>wh(o.body,e),e.doc),t}function wh(o,e){let t=Fo(he(o,e.markdown).children,e),n=t.childNodes.length===1?t.firstElementChild:null;if(t.childNodes.length===0||n&&n.tagName==="P"){let i=e.doc.createElement("span");return n&&i.append(...Array.from(n.childNodes)),Do(i),i}return Do(t),t}var Nr=()=>!1;function Sh(o,e){let t=e.doc.createElement("div");return t.classList.add("mbe-view-markdown"),t.appendChild(Fo(he(o,e.markdown).children,e)),Do(t),t}function Fo(o,e){let t=e.markdown??pe,n=e.doc.createElement("div");n.className="mbe-flow";let i=[];for(let r of o){let s=fn(r,t,i[i.length-1]);if(s){i.push(...s);continue}Sr(n,i,e),i=[],r.type==="blockQuote"?n.appendChild(Th(r,e)):r.type==="list"&&r.items.forEach((l,a)=>n.appendChild(Eh(r,l,a,e)))}return Sr(n,i,e),n}function Th(o,e){let t=e.markdown?.callouts===!1?null:Ni(o.children),n=t?[...t.rest.length>0?[{type:"paragraph",children:[...t.rest]}]:[],...o.children.slice(1)]:o.children,i=e.doc.createElement("blockquote");return i.dir="auto",i.className=qe("mbe-block mbe-quote",e.classes.blockquote),t&&(i.dataset.callout=t.type,i.appendChild(No(t.type,e))),i.appendChild(Fo(n,e)),i}function Eh(o,e,t,n){let i=e.task?"task":o.ordered?"ordered":"bullet",r=n.doc.createElement("div");r.dir="auto",r.className=qe("mbe-block mbe-list-item",n.classes[`${i}List`]),r.dataset.listType=i,r.dataset.indent="0",t===0&&r.setAttribute(ra,"");let s=n.doc.createElement("span");if(s.className="mbe-marker",e.task){let a=n.doc.createElement("input");a.className="mbe-checkbox",a.type="checkbox",a.checked=e.checked,s.appendChild(a)}else o.ordered&&(s.textContent=`${o.start+t}.`);let l=n.doc.createElement("div");return l.className="mbe-content",l.appendChild(Fo(e.children,n)),r.append(s,l),r}function Do(o){for(let e of Array.from(o.querySelectorAll(`[${W}], [${Kt}], [contenteditable], [data-row]`)))e.removeAttribute(W),e.removeAttribute(Kt),e.removeAttribute("contenteditable"),e.removeAttribute("data-row"),e.removeAttribute("data-col");for(let e of Array.from(o.querySelectorAll("input")))e.type==="checkbox"?e.disabled=!0:e.readOnly=!0,e.tabIndex=-1}function Tr(o){let e=o.createElement("br");return e.setAttribute($o,""),e}var Mh=new Set(["area","base","br","col","embed","hr","img","input","link","meta","source","track","wbr"]),Ch=/<!--[\s\S]*?-->|<[^<>]*>/g;function ha(o){if(!o.some(t=>t.marks.includes("html")))return o;let e=[];for(let t of G(o)){if(!t.marks.includes("html")){e.push(t);continue}let n=0;for(let i of t.text.matchAll(Ch))i.index>n&&e.push({...t,text:t.text.slice(n,i.index)}),e.push({...t,text:i[0]}),n=i.index+i[0].length;n<t.text.length&&e.push({...t,text:t.text.slice(n)})}return e}function Rr(o){let e=[],t=0;for(let r of ha(o))e.push({span:r,from:t,to:t+r.text.length}),t+=r.text.length;let n=r=>r.marks.includes("html"),i=[];for(let r=0;r<e.length;r++){let{span:s,from:l,to:a}=e[r];if(!n(s))continue;let d=/^<([A-Za-z][A-Za-z0-9-]*)\b[^>]*?(\/?)>$/.exec(s.text),u=r;if(d&&!d[2]&&!Mh.has(d[1].toLowerCase())){let c=d[1].toLowerCase(),h=0;for(let f=r+1;f<e.length;f++){let p=e[f].span;if(!n(p))continue;let m=/^<(\/?)([A-Za-z][A-Za-z0-9-]*)\b[^>]*?(\/?)>$/.exec(p.text);if(!(!m||m[2].toLowerCase()!==c||m[3]))if(!m[1])h++;else if(h>0)h--;else{u=f;break}}}i.push({from:l,to:u===r?a:e[u].to}),r=u}return i}function Ih(o,e,t,n,i,r){let s=t.doc,l=t.views,a=l?(x,T)=>!!x.token&&l.has(x.token)&&!i?.has(Cn(r,T)):void 0;l?.has("html")&&(o=ha(o));let d=l?.has("html")&&o.some(x=>x.marks.includes("html"))?Rr(o).filter(x=>!i?.has(Cn(r,x.from))):[],u=x=>d.some(T=>x>=T.from&&x<T.to),c=x=>x.marks.includes("html"),h=a||d.length>0?(x,T)=>!!a?.(x,T)||c(x)&&u(T):void 0,f=Yo(o,n,h),p=x=>fa(Lh(x.span,t,x.atomic&&!c(x.span)),x.decorations,s),m=new Map,y=0;for(let x of f)m.set(x,y),y+=x.span.text.length;let g=x=>{let T=s.createElement("a"),E=t.resolveUrl(x.link,"link");return E!==null&&T.setAttribute("href",E),T.dataset.href=x.link,x.linkTitle&&(T.title=x.linkTitle),T.className=qe("mbe-link",t.classes.link),T},v=x=>d.find(T=>T.from===m.get(f[x])),b=(x,T)=>{let E=x;for(;E<f.length&&m.get(f[E])<T.to;)E++;return E},w=(x,T)=>{let E=f[x].span;if(!E.link)return!1;for(let A=x+1,fe=b(x,T);A<fe;A++)if(!ae(f[A].span,E))return!1;return!0},k=(x,T,E,A)=>{let fe=[],me=[],Se=b(x,T);for(let le=x;le<Se;){let Vr=f[le];if(c(Vr.span)){fe.push(Vr.span.text),le++;continue}let Wo=s.createDocumentFragment(),Ur=zr=>zr>=Se||c(f[zr].span);if(A)for(;!Ur(le);le++)Wo.appendChild(p(f[le]));else le=S(le,Ur,Wo);me.push(Wo),fe.push(ko(me.length-1))}let Te=t.view?.("html",fe.join(""),"inline");if(!Te)return null;Ar(Te,me.length,le=>me[le],s);let Rn=I(C(o,T.from,T.to));return E.appendChild(Oo(Te,qe("mbe-view","mbe-view-html",t.classes.token?.html),Rn)),Se},S=(x,T,E)=>{for(;x<f.length&&!T(x);){let A=f[x].span,fe=v(x);if(fe&&!w(x,fe)){let Te=k(x,fe,E,!1);if(Te!==null){x=Te;continue}}if(!A.link){E.appendChild(p(f[x])),x++;continue}let me=g(A),Se=x;for(;x<f.length&&!T(x)&&ae(f[x].span,A);){let Te=v(x);if(Te){let Rn=w(x,Te);if(!Rn&&x>Se)break;let le=Rn?k(x,Te,me,!0):null;if(le!==null){x=le;continue}}me.appendChild(p(f[x])),x++}E.appendChild(me)}return x};S(0,()=>!1,e)}function fa(o,e,t){for(let n=e.length-1;n>=0;n--){let i=e[n],r=t.createElement("span");for(let[s,l]of Object.entries(i.attributes??{}))r.setAttribute(s,l);r.className=`mbe-deco ${i.class}`,r.appendChild(o),o=r}return o}function Oo(o,e,t){return o.classList.add(...e.split(/\s+/).filter(Boolean)),o.contentEditable="false",o.setAttribute(ia,""),t!==void 0&&(o.dataset.source=t),o}function Lh(o,e,t=!1){let n=e.doc,i=t?e.view?.(o.token,o.text,"inline"):null;if(i)return na(o,Oo(i,qe("mbe-view",`mbe-view-${o.token}`,e.classes.token?.[o.token]),o.text),e);if(o.image){let s=o.image,l=e.resolveUrl(s.src,"image");if(l===null)return ta(s,e);let a=e.loadedImage?.(l);if(!a){let d=n.createElement("img");d.setAttribute("loading","lazy"),d.setAttribute("decoding","async"),e.referrerPolicy&&d.setAttribute("referrerpolicy",e.referrerPolicy),d.src=l,d.addEventListener("error",()=>{d.parentNode&&(d.replaceWith(ta({src:l,alt:d.alt,title:d.title||void 0},e)),e.onImageError?.())}),a=d}return a.alt=s.alt,kr(a,"title",s.title),kr(a,"width",s.width?String(s.width):void 0),kr(a,"height",s.height?String(s.height):void 0),Oo(a,qe("mbe-image",e.classes.image))}let r=n.createTextNode(o.text);if(o.token){let s=n.createElement("span");s.className=qe("mbe-token",`mbe-token-${o.token}`,e.classes.token?.[o.token]),s.spellcheck=!1,s.appendChild(r),r=s}return na(o,r,e)}function kr(o,e,t){t===void 0?o.removeAttribute(e):o.setAttribute(e,t)}function ta(o,e){let t=e.doc,n=t.createElement("span"),i=o.alt||e.labels.imageUnavailable;n.setAttribute("role","img"),n.setAttribute("aria-label",i),o.title&&(n.title=o.title);let r=e.icon?.("imageUnavailable");r&&n.appendChild(r);let s=t.createElement("span");return s.className="mbe-image-alt",s.textContent=i,n.appendChild(s),Oo(n,qe("mbe-image","mbe-image-unavailable",e.classes.image))}function na(o,e,t){for(let n=et.length-1;n>=0;n--){let i=et[n];if(!o.marks.includes(i))continue;let[r,s]=lh[i],l=t.doc.createElement(r),a=i==="html"?s:t.classes[i];a&&(l.className=a),l.appendChild(e),e=l}return e}var Ho=class{constructor(e,t){this.root=e;this.labels=t}rendered=new Map;numbers=new WeakMap;resolveUrl=Ln;referrerPolicy;decorate;decorateCode;decorateSource;onViewSettled;widgetsAfter;views;collectFootnotes=!1;footnotes;viewContext;blockViews=[];hosted=new Map;markdown;classes=ah;icon;codeCopy=!1;source=!1;onImageError;collapsed=new Set;revealed=new Map;viewCache=new Map;pendingViews=new Map;failedViews=new Set;viewBlocks=new Map;renderingBlock="";loadedImages=new Map;context(){return{doc:this.root.ownerDocument,labels:this.labels,resolveUrl:this.resolveUrl,referrerPolicy:this.referrerPolicy,decorate:this.decorate,decorateCode:this.decorateCode,decorateSource:this.decorateSource,views:this.views,view:this.views&&((e,t,n)=>this.renderView(e,t,n)),blockView:this.blockViews.length>0?e=>this.renderBlockView(e):void 0,markdown:this.markdown,classes:this.classes,icon:this.icon,codeCopy:this.codeCopy,source:this.source,onImageError:this.onImageError,loadedImage:e=>this.loadedImages.get(e)?.shift()}}renderView(e,t,n){let i=this.views?.get(e);if(!i||!this.viewContext)return null;let r=`${n}\0${e}\0${t}`;if(this.failedViews.has(r))return this.noteViewBlock(r),null;let s=this.viewCache.get(r);if(s)this.viewCache.delete(r);else{s=this.root.ownerDocument.createElement(n==="inline"?"span":"div");let l;try{l=i(t,s,n,this.viewContext)}catch{l=!1}if(l===!1)return this.noteViewBlock(r),null;if(l&&typeof l.then=="function"&&(s.setAttribute(xr,""),this.awaitView(r,l)),this.viewCache.size>=500){let a=this.viewCache.keys().next().value;this.viewCache.delete(a),this.viewBlocks.delete(a)}}return this.pendingViews.get(r)?.add(this.renderingBlock),this.noteViewBlock(r),this.viewCache.set(r,s),s.cloneNode(!0)}isHosted(e){return this.blockViews.some(({view:t})=>t.match(e))}renderBlockView(e){let t=this.hosted.get(e.id);if(t&&t.block===e)return t.after?null:t.el;t&&this.disposeHosted(e.id);let n=this.viewContext;if(!n)return null;let i=null;for(let{name:r,view:s}of this.blockViews){if(!s.match(e))continue;i=r;let l=this.root.ownerDocument.createElement("div"),a;try{a=s.render(e,l,n)}catch{a=!1}if(a===!1)continue;let d=typeof a=="function"?a:void 0;if(s.placement!=="after")return this.hosted.set(e.id,{block:e,name:r,el:l,dispose:d}),l;let u=this.root.ownerDocument.createElement("div");return u.className="mbe-block-view mbe-block-after",u.contentEditable="false",u.appendChild(l),this.hosted.set(e.id,{block:e,name:r,el:l,after:u,dispose:d}),null}return i!==null&&this.hosted.set(e.id,{block:e,name:i,el:null}),null}afterView(e,t){if(t?.has(Je)||this.source)return;let n=this.hosted.get(e.id);return n?.block===e?n.after:void 0}disposeHosted(e){let t=this.hosted.get(e);if(t){this.hosted.delete(e);try{t.dispose?.()}catch{}}}destroy(){for(let e of[...this.hosted.keys()])this.disposeHosted(e)}noteViewBlock(e){let t=this.viewBlocks.get(e);t||(this.viewBlocks.size>=1e3&&this.viewBlocks.delete(this.viewBlocks.keys().next().value),this.viewBlocks.set(e,t=new Set)),t.add(this.renderingBlock)}awaitView(e,t){let n=new Set;this.pendingViews.set(e,n);let i=r=>{this.pendingViews.get(e)===n&&(this.pendingViews.delete(e),this.viewCache.get(e)?.removeAttribute(xr),r||(this.failedViews.add(e),this.viewCache.delete(e)),n.size>0&&this.onViewSettled?.([...n]))};t.then(r=>i(r!==!1),()=>i(!1))}dropViews(e){let t=i=>e===void 0||i.split("\0",3)[1]===e;for(let i of[...this.viewCache.keys()])t(i)&&this.viewCache.delete(i);for(let i of[...this.failedViews])t(i)&&this.failedViews.delete(i);for(let i of[...this.pendingViews.keys()])t(i)&&this.pendingViews.delete(i);let n=new Set;for(let[i,r]of[...this.viewBlocks])if(t(i)){this.viewBlocks.delete(i);for(let s of r)this.rendered.has(s)&&n.add(s)}for(let[i,r]of[...this.hosted])e!==void 0&&r.name!==e||(this.disposeHosted(i),this.rendered.has(i)&&n.add(i));return[...n]}render(e,t=!1,n=!1){let i=this.context(),r=new Set;for(let u of e.blocks){let c=this.rendered.get(u.id);!t&&c&&c.block===u&&c.el.parentNode===this.root&&Lr(c.reveal,this.revealed.get(u.id))&&r.add(c.el)}if(!t){for(let{el:u}of this.rendered.values())if(!r.has(u))for(let c of Array.from(u.querySelectorAll("img.mbe-image"))){let h=c.getAttribute("src");if(h===null||!c.complete||c.naturalWidth===0)continue;let f=this.loadedImages.get(h);f?f.push(c):this.loadedImages.set(h,[c])}}let s=new Map;for(let u of e.blocks){this.renderingBlock=u.id;let c=this.rendered.get(u.id),h=this.revealed.get(u.id),f=c&&r.has(c.el)?c.el:null;!f&&i.source&&u.type==="code"&&c?.block.type==="code"&&c.el.parentNode===this.root&&this.patchSource(c.el,u,i)&&(f=c.el),f||(f=sa(u,i,h),c&&u.type==="raw"&&Ah(c.el,f)),s.set(u.id,{block:u,el:f,reveal:h})}this.loadedImages.clear();for(let[u,c]of[...this.hosted])s.get(u)?.block!==c.block&&this.disposeHosted(u);let l=this.collectFootnotes&&this.views?.has("footnote")===!0;for(let{block:u,el:c}of s.values())u.type==="raw"&&u.syntax==="footnote"&&c.classList.toggle("mbe-footnote-collected",l);let a=l?this.footnoteSection(e,s,i,t):null;l||(this.footnotes=void 0);let d=[];for(let[u,{block:c,el:h,reveal:f}]of s){d.push(h);let p=this.afterView(c,f);p&&d.push(p);let m=this.widgetsAfter?.(u);m&&d.push(...m)}if(a&&d.push(a),t||this.rendered.size===0){let u=this.root.ownerDocument.createDocumentFragment();for(let c of d)n&&c.hasAttribute(W)&&c.classList.add("mbe-lazy"),u.appendChild(c);this.root.replaceChildren(u)}else{let u=this.root.firstChild,c=!1;for(let h of d)h===u?u=u.nextSibling:(this.root.insertBefore(h,u),c=!0);if(c||u!==null||this.root.childNodes.length!==d.length){let h=new Set(d);for(let f of Array.from(this.root.childNodes))h.has(f)||f.remove()}}this.rendered=s,Er(e,u=>s.get(u)?.el,this.numbers,this.collapsed,this.labels)}footnoteSection(e,t,n,i){let r=new Map;for(let u of e.blocks){if(u.type!=="raw"||u.syntax!=="footnote")continue;let c=da(I(u.content));c&&!r.has(c.label)&&r.set(c.label,c)}if(r.size===0)return null;let s=[],l=new Map;for(let u of e.blocks){let c=t.get(u.id)?.el;if(c)for(let h of Array.from(c.querySelectorAll(".mbe-view-footnote")))for(let f of(h.dataset.source??"").matchAll(xh)){let p=ca(f[1]);if(!r.has(p))continue;let m=(l.get(p)??0)+1;l.set(p,m),m===1&&s.push(p)}}if(s.length===0)return null;let a=JSON.stringify(s.map(u=>[u,r.get(u).body,l.get(u)]));if(!i&&this.footnotes?.key===a)return this.footnotes.el;let d=n.doc.createElement("section");d.className="mbe-footnotes",d.contentEditable="false",d.setAttribute("aria-label",this.labels.footnotes);for(let u of s){let c=ua(r.get(u),n);if(!c)continue;let h=c.lastElementChild??c,f=h.querySelector(":scope > .mbe-flow");if(f){let p=f.lastElementChild;p?.tagName==="P"?h=p:(h=n.doc.createElement("p"),h.className="mbe-block mbe-paragraph",f.appendChild(h))}for(let p=1;p<=l.get(u);p++){let m=n.doc.createElement("button");m.type="button",m.className="mbe-footnote-backref",m.dataset.label=u,m.dataset.ref=String(p),m.setAttribute("aria-label",`${this.labels.backToReference} ${u}${p>1?` ${p}`:""}`);let y=n.icon?.("backToReference");if(y?m.appendChild(y):m.textContent="\u2191",p>1){let g=n.doc.createElement("sup");g.textContent=String(p),m.appendChild(g)}h.appendChild(m)}d.appendChild(c)}return this.footnotes={key:a,el:d},d}updateSections(e){Er(e,t=>this.rendered.get(t)?.el,this.numbers,this.collapsed,this.labels)}elementFor(e){return this.rendered.get(e)?.el}adopt(e){let t=this.rendered.get(e.id);t&&(this.rendered.set(e.id,{...t,block:e}),"content"in e&&t.el.classList.toggle("mbe-empty",B(e.content)===0))}invalidate(e){this.rendered.delete(e)}patchSource(e,t,n=this.context()){let i=se(e);return i?(aa(i,t,n),e.classList.toggle("mbe-empty",B(t.content)===0),!0):!1}refreshSource(e){let t=this.rendered.get(e.id);t&&t.el.parentNode===this.root&&this.patchSource(t.el,e)}};function Bh(o,e,t,n,i){let r=e>0?String(e):"";if(o.style.getPropertyValue("--mbe-section-depth")!==r&&(r?o.style.setProperty("--mbe-section-depth",r):o.style.removeProperty("--mbe-section-depth")),_t(o,sh,e>0),_t(o,ih,t),n===null)return;_t(o,rh,n);let s=o.querySelector(".mbe-details-toggle"),l=String(!n);s&&s.getAttribute("aria-expanded")!==l&&(s.setAttribute("aria-expanded",l),s.setAttribute("aria-label",n?i.expandSection:i.collapseSection))}function Er(o,e,t,n,i){let r=[],s,l=[];o.blocks.forEach((a,d)=>{let u=o.blocks[d-1],c=e(a.id);if(a.type==="detailsEnd"&&l.pop(),c&&Bh(c,l.length,l.includes(!0),a.type==="details"?n.has(a.id):null,i),a.type==="details"&&l.push(n.has(a.id)),M(a)!==null&&(_t(c,nh,oe(u,a)),_t(c,oh,oe(a,o.blocks[d+1]))),(a.type!=="listItem"||u?.type!=="listItem"||M(u)!==M(a))&&(r.length=0,s=void 0),a.type!=="listItem")return;let h=a.listType==="ordered";if(_t(c,ra,r.length===0||a.indent===0&&s!==void 0&&h!==s),a.indent===0&&(s=h),r.length=a.indent+1,!h){r[a.indent]=void 0;return}let f=r[a.indent]===void 0?a.start??1:r[a.indent]+1;if(r[a.indent]=f,!c||t.get(c)===f)return;let p=c.querySelector(".mbe-marker");p&&(p.textContent=`${f}.`),t.set(c,f)})}function Ah(o,e){let t=o.querySelectorAll("details");if(t.length===0)return;let n=e.querySelectorAll("details");n.length===t.length&&t.forEach((i,r)=>{n[r].open=i.open})}function _t(o,e,t){o&&o.hasAttribute(e)!==t&&o.toggleAttribute(e,t)}function Nh(o,e){let t=e;for(;t&&t.parentNode!==o;)t=t.parentNode;return t instanceof HTMLElement&&t.hasAttribute(W)?t:null}function se(o,e){return e?o.querySelector(`[data-row="${e.row}"][data-col="${e.col}"]`):o.hasAttribute(Kt)?o:o.querySelector(`[${Kt}]`)}function Vt(o){let e=[],t=n=>{for(let i=n.firstChild;i;i=i.nextSibling)i.nodeType===3?e.push(i):i instanceof HTMLElement&&(i.hasAttribute(ia)?e.push(i):i.hasAttribute($o)||t(i))};return t(o),e}function Dr(o){return o.nodeType===3?o.data:o.dataset.source??"\uFFFC"}function Po(o){return Dr(o).length}function xt(o){return Array.prototype.indexOf.call(o.parentNode.childNodes,o)}function Or(o){return o.classList.contains(In)?bh(o):Vt(o).map(Dr).join("")}function pa(o){let e="";for(let t=o.firstChild;t;t=t.nextSibling)t.nodeType===3&&(e+=t.data);return e}function oa(o,e){let t=0;for(let[n,i]of la(o)){if(n===e)return t;t+=i+1}return e===null&&t>0?t-1:t}function Mr(o,e,t){if(!o.contains(e))return e.compareDocumentPosition(o)&Node.DOCUMENT_POSITION_FOLLOWING?0:Vt(o).reduce((l,a)=>l+Po(a),0);if(o.classList.contains(In)){if(e===o)return oa(o,o.childNodes[t]??null);let s=(e instanceof Element?e:e.parentElement)?.closest(`.${Ir}`);if(s?.parentNode===o)return oa(o,s)+Mr(s,e,t)}let n=o.ownerDocument,i=n.createRange();i.setStart(e,t);let r=0;for(let s of Vt(o)){let l=Po(s);if(s===e)return r+Math.min(t,l);if(s.contains(e))return r;let a=n.createRange();if(s.nodeType===3?a.setStart(s,l):a.setStartAfter(s),a.compareBoundaryPoints(Range.START_TO_START,i)<=0)r+=l;else return r}return r}function _e(o,e,t){let n=e,i=t;if(e===o){let a=o.childNodes[Math.min(t,o.childNodes.length-1)];if(!a)return null;let d=t>=o.childNodes.length;if(n=a,i=d?a.childNodes.length:0,d){let u=a,c=u.hasAttribute?.(W)?se(u):null;if(c)return{blockId:u.getAttribute(W),offset:Or(c).length}}}let r=Nh(o,n);if(!r)return null;let s=r.getAttribute(W);if(r.classList.contains("mbe-divider"))return{blockId:s,offset:0};if(r.classList.contains("mbe-table")){let a=(n instanceof Element?n:n.parentElement)?.closest("[data-row]");if(!a||!r.contains(a))return{blockId:s,offset:0,cell:{row:0,col:0}};let d={row:Number(a.dataset.row),col:Number(a.dataset.col)};return{blockId:s,offset:Mr(a,n,i),cell:d}}let l=se(r);return l?{blockId:s,offset:Mr(l,n,i)}:{blockId:s,offset:0}}function ma(o,e){let t=se(o,e.cell);if(!t||t.classList.contains(In))return null;let n=0;for(let i of Vt(t)){if(n===e.offset&&i.nodeType!==3)return i;if(n+=Po(i),n>e.offset)return null}return null}function ga(o,e){let t=se(o,e.cell);if(!t)return{node:o.parentNode,offset:xt(o)};if(t.classList.contains(In)){let n=0,i=null;for(let r of la(t)){let[s,l]=r;if(e.offset<=n+l)return vr(s,e.offset-n);n+=l+1,i=r}return i?vr(i[0],i[1]):{node:t,offset:0}}return vr(t,e.offset)}function vr(o,e){let t=0,n=Vt(o);for(let r of n){let s=Po(r);if(r.nodeType===3){let l=r;if(t+s>=e){let a=e-t;if(a===s&&r===n[n.length-1]&&l.data.endsWith(`
114
+ `)){let d=o.querySelector(`[${$o}]`);if(d)return{node:d.parentNode,offset:xt(d)}}return{node:l,offset:a}}}else if(e<t+s)return{node:r.parentNode,offset:xt(r)+(t===e?0:1)};t+=s}let i=n[n.length-1];return i?i.nodeType===3?{node:i,offset:i.length}:{node:i.parentNode,offset:xt(i)+1}:{node:o,offset:0}}var qo=class{constructor(e){this.editor=e;let t=e.root,n=t.ownerDocument;this.el=n.createElement("button"),this.el.type="button",this.el.className="mbe-ui mbe-block-handle";let i=X(n,e.icon("blockHandle"));i&&this.el.appendChild(i),this.el.setAttribute("aria-label",e.labels.blockHandle),this.el.setAttribute("aria-haspopup","menu"),this.el.tabIndex=-1,this.el.hidden=!0;let r=(s,l,a)=>{s.addEventListener(l,a),this.cleanup.push(()=>s.removeEventListener(l,a))};r(t,"mousemove",s=>this.onMove(s)),r(t,"mouseleave",()=>this.scheduleHide()),r(this.el,"mouseenter",()=>this.cancelHide()),r(this.el,"mouseleave",()=>this.scheduleHide()),r(this.el,"mousedown",s=>s.preventDefault()),r(this.el,"click",()=>{this.blockId&&e.openBlockMenu(this.blockId,this.el.getBoundingClientRect())})}el;blockId=null;hideTimer=null;cleanup=[];onMove(e){if(!this.editor.isEditable)return;let n=e.target;for(;n&&n.parentElement!==this.editor.root;)n=n.parentElement;if(!n||!n.hasAttribute(W))return;let i=this.editor.blockMenuOwner(n.getAttribute(W));i?this.showFor(i):this.blockId!==null&&this.scheduleHide()}showFor(e){this.cancelHide();let t=this.editor.blockElement(e);if(!t)return this.hide();let n=this.editor.root.ownerDocument;this.blockId=e,this.el.hidden=!1;let i=$t(this.el,this.editor.root),r=t.getBoundingClientRect(),l=t.querySelector(":scope > .mbe-callout-icon")?.getBoundingClientRect(),a=parseFloat(n.defaultView.getComputedStyle(t).lineHeight)||24,d=l?.height?l.top+l.height/2:r.top+Math.min(r.height,a)/2,u=this.el.offsetHeight||22;this.el.style.left=`${Math.round(r.left-(this.el.offsetWidth||20)-6-i.x)}px`,this.el.style.top=`${Math.round(d-u/2-i.y)}px`}contains(e){return this.el.contains(e)}hide(){this.cancelHide(),this.el.hidden=!0,this.blockId=null}scheduleHide(){this.cancelHide(),this.hideTimer=setTimeout(()=>this.hide(),250)}cancelHide(){this.hideTimer!==null&&clearTimeout(this.hideTimer),this.hideTimer=null}destroy(){this.cancelHide();for(let e of this.cleanup)e();this.el.remove()}};var Rh=300,Dh=250,_o=class{constructor(e,t){this.editor=e;this.actions=t;let n=e.root.ownerDocument,i=e.labels;this.popup=new we(e.root,"mbe-link-card");let r=this.popup.el;r.setAttribute("role","toolbar"),r.setAttribute("aria-label",i.link),this.url=n.createElement("a"),this.url.className="mbe-link-card-url",this.url.target="_blank",this.url.rel="noopener noreferrer",this.url.addEventListener("click",f=>{f.preventDefault(),this.target&&t.open(this.target,f)});let s=(f,p)=>{let m=n.createElement("button");return m.type="button",m.className=`mbe-tool mbe-link-card-${f}`,ba(m,e,f),m.setAttribute("aria-label",i[f]),m.title=i[f],m.addEventListener("click",y=>{this.target&&p(y)}),m},l=s("openLink",f=>t.open(this.target,f));this.copyButton=s("copyLink",()=>this.copy());let a=s("editLink",()=>{let f=this.target;this.hide(),t.edit(f)}),d=s("removeLink",()=>{let f=this.target;this.hide(),t.remove(f)}),u=n.createElement("span");u.className="mbe-tool-sep",r.append(this.url,u,l,this.copyButton,a,d);let c=e.root,h=(f,p,m)=>{f.addEventListener(p,m),this.cleanup.push(()=>f.removeEventListener(p,m))};h(c,"mouseover",f=>this.onOver(f)),h(c,"mouseout",f=>this.onOut(f)),h(r,"mouseenter",()=>this.cancelHide()),h(r,"mouseleave",()=>{this.hovered&&this.scheduleHide()})}popup;url;copyButton;target=null;hovered=null;caret=null;showTimer=null;hideTimer=null;copiedTimer=null;cleanup=[];get isOpen(){return this.popup.isOpen}contains(e){return this.popup.el.contains(e)}setCaret(e){this.caret=e,this.hovered&&!this.hovered.el.isConnected&&(this.hovered=null),this.render()}reposition(){if(this.target){if(!this.target.el.isConnected)return this.hide();this.place(this.target)}}hide(){this.clearTimers(),this.hovered=null,this.caret=null,this.target=null,this.popup.hide()}destroy(){this.clearTimers(),this.copiedTimer!==null&&clearTimeout(this.copiedTimer);for(let e of this.cleanup)e();this.popup.destroy()}onOver(e){if(!this.editor.isEditable||e.buttons!==0)return;let t=e.target?.closest?.("a.mbe-link");!t||!this.editor.root.contains(t)||(this.cancelHide(),this.hovered?.el!==t&&(this.showTimer!==null&&clearTimeout(this.showTimer),this.showTimer=setTimeout(()=>{this.showTimer=null;let n=this.actions.targetOf(t);!n||!this.editor.isEditable||(this.hovered=n,this.render())},this.popup.isOpen?0:Rh)))}onOut(e){let t=e.target?.closest?.("a.mbe-link");if(!t)return;let n=e.relatedTarget;n&&(t.contains(n)||this.popup.el.contains(n))||(this.showTimer!==null&&(clearTimeout(this.showTimer),this.showTimer=null),this.hovered&&this.scheduleHide())}render(){let e=this.hovered??this.caret;if(!e){this.target=null,this.popup.hide();return}if(this.target?.el!==e.el||this.target.href!==e.href){this.target=e,this.url.textContent=e.href,this.url.title=e.href;let t=e.el.getAttribute("href");t?this.url.href=t:this.url.removeAttribute("href");let n=this.popup.el.querySelector(".mbe-link-card-openLink");n&&(n.disabled=!t),this.showCopied(!1)}this.place(e)}place(e){let t=e.el.getClientRects(),n=t.length>0?t[t.length-1]:e.el.getBoundingClientRect();this.popup.show(n,"below",4)}copy(){let e=this.target.href,t=()=>this.showCopied(!0),n=this.editor.root.ownerDocument.defaultView?.navigator.clipboard;n&&n.writeText(e).then(t,()=>{})}showCopied(e){this.copiedTimer!==null&&clearTimeout(this.copiedTimer),this.copiedTimer=null;let t=this.copyButton,n=e?"copied":"copyLink";ba(t,this.editor,n),t.setAttribute("aria-label",this.editor.labels[n]),t.title=this.editor.labels[n],e&&(this.copiedTimer=setTimeout(()=>this.showCopied(!1),1500))}scheduleHide(){this.cancelHide(),this.hideTimer=setTimeout(()=>{this.hideTimer=null,this.hovered=null,this.render()},Dh)}cancelHide(){this.hideTimer!==null&&clearTimeout(this.hideTimer),this.hideTimer=null}clearTimers(){this.cancelHide(),this.showTimer!==null&&clearTimeout(this.showTimer),this.showTimer=null}};function ba(o,e,t){let n=X(o.ownerDocument,e.icon(t));o.replaceChildren(...n?[n]:[])}function Hr(o,e,t,n){let i=new Map;if(!t)return i;let{anchor:r,focus:s}=o.selection,l=N(o.doc,s.blockId),a=r.blockId===s.blockId?l:N(o.doc,r.blockId);for(let[d,u]of[[s,l],[r,a]]){let c=i.get(u.id)??new Set;if(n?.(u)&&c.add(Je),u.type==="raw")e.has(u.syntax)&&c.add(Je);else if(u.type==="code")e.has(Cr(u.language))&&c.add(Je);else{let h=F(u,d.cell)??[];for(let{token:f,from:p}of Xr(h,d.offset))e.has(f)&&c.add(Cn(d.cell,p));if(e.has("html")&&h.some(f=>f.marks.includes("html")))for(let f of Rr(h))f.from<=d.offset&&d.offset<=f.to&&c.add(Cn(d.cell,f.from))}c.size>0&&i.set(u.id,c)}return i}function ya(o,e){return o.size===e.size&&[...o].every(([t,n])=>Lr(n,e.get(t)))}function Bn(o,e){if(o.type==="table"){let i=e?0:o.rows.length-1;return{blockId:o.id,offset:e?0:B(o.rows[i][0]),cell:{row:i,col:0}}}if(o.type!=="raw"&&o.type!=="code")return e?V(o):P(o);let t=I(o.content);if(o.type==="code"||o.syntax==="markdown")return{blockId:o.id,offset:e?0:t.length};if(e){let i=t.indexOf(`
115
115
  `);return{blockId:o.id,offset:i>=0&&i<t.length-1?i+1:0}}let n=t.lastIndexOf(`
116
- `);return{blockId:o.id,offset:n>0?n:t.length}}var Dh=o=>typeof o?.then=="function";function ya(o){return(e,t,n,i)=>{let r=t.ownerDocument.createElement("template");r.innerHTML=e;let s=a=>{if(!a)return!1;t.replaceChildren(a)},l=o(r.content,{editor:i.editor,kind:n});return Dh(l)?l.then(s):s(l)}}function Pr(o,e){let t=o.ownerDocument,n=t.defaultView,i=e.top,r=e.bottom,s=e.left,l=e.right;for(let c=o;c&&c!==t.body&&c!==t.documentElement;c=c.parentElement){let h=n?.getComputedStyle(c),f=c.scrollHeight>c.clientHeight&&/auto|scroll|overlay/.test(h?.overflowY??""),p=c.scrollWidth>c.clientWidth&&/auto|scroll|overlay/.test(h?.overflowX??"");if(!f&&!p)continue;let m=c.getBoundingClientRect(),y=m.top+c.clientTop,g=m.left+c.clientLeft,x=f?Ko(i,r,y,y+c.clientHeight):0,b=p?Ko(s,l,g,g+c.clientWidth):0;if(!x&&!b)continue;let w=c.scrollTop,k=c.scrollLeft;c.scrollTop+=x,c.scrollLeft+=b,i-=c.scrollTop-w,r-=c.scrollTop-w,s-=c.scrollLeft-k,l-=c.scrollLeft-k}if(!n)return;let a=t.documentElement,d=Ko(i,r,0,a.clientHeight),u=Ko(s,l,0,a.clientWidth);(d||u)&&n.scrollBy(u,d)}function Ko(o,e,t,n){return o<t+8?o-t-8:e>n-8?Math.min(e-n+8,o-t-8):0}function ka(o){let e={};for(let t of o)for(let[n,i]of Object.entries(t??{}))i!==void 0&&(e[n]=typeof i=="object"?{...e[n],...i}:i);return e}var Oh={text:"--mbe-text",muted:"--mbe-muted",background:"--mbe-bg",accent:"--mbe-accent",link:"--mbe-link",codeBackground:"--mbe-code-bg",border:"--mbe-border",popupBackground:"--mbe-popup-bg",popupBorder:"--mbe-popup-border",hover:"--mbe-hover",danger:"--mbe-danger",highlight:"--mbe-highlight",calloutNote:"--mbe-callout-note",calloutTip:"--mbe-callout-tip",calloutImportant:"--mbe-callout-important",calloutWarning:"--mbe-callout-warning",calloutCaution:"--mbe-callout-caution"},An={font:"--mbe-font",mono:"--mbe-mono",sourceFont:"--mbe-source-font",fontSize:"--mbe-font-size",lineHeight:"--mbe-line-height",radius:"--mbe-radius",blockGap:"--mbe-block-gap"},va=[An.font,An.mono,An.fontSize,An.lineHeight];function $r(o){let e=new Map;if(!o)return e;for(let t of["light","dark"])for(let[n,i]of Object.entries(Oh)){let r=o[t]?.[n]??o.colors?.[n];r&&e.set(`${i}-${t}`,r)}for(let[t,n]of Object.entries(An)){let i=o[t];i!==void 0&&i!==""&&e.set(n,typeof i=="number"?`${i}px`:i)}return e}var xa=/^(?:[ \t]*>[ \t]?)*/,Ut=/[ \t]*(?:[-*+]|\d{1,9}[.)])(?=[ \t\n\r]|$)/y,Hh=/^(`{3,}|~{3,})/,Ph=/^\[[ \t\nxX]\](?=[ \t\n]|$)/;function wa(o,e){let t=he(o,e),n=pt(o),i=[],r=[],s=(g,x,b)=>{b>x&&i.push({from:x,to:b,kind:g})},l=g=>({from:n.starts[g-1]??o.length,to:n.ends[g-1]??o.length}),a=(g,x,b,w)=>{for(let k of bs(g,n,x,b))s(w,k.from,k.to)},d=(g,x)=>{for(let b=g;b<x;b++){let w=o[b];if(w===">")s("marker",b,b+1);else if(w==="-"||w==="*"||w==="+"||w>="0"&&w<="9"){Ut.lastIndex=b;let k=Ut.exec(o);k&&k.index===b&&(s("marker",b+k[0].length-k[0].trimStart().length,b+k[0].length),b+=k[0].length-1)}}},u=g=>{let x=xa.exec(o.slice(g.from,g.to))[0];d(g.from,g.from+x.length),Ut.lastIndex=g.from+x.length;let b=g.from+x.length;for(let w=Ut.exec(o);w&&w.index===b;w=Ut.exec(o))s("marker",b+w[0].length-w[0].trimStart().length,b+w[0].length),b+=w[0].length,Ut.lastIndex=b;return b},c=g=>{for(let x of g.lines){let b=n.starts[x.line-1]??o.length;d(b,b+x.offset)}},h=(g,x)=>{for(let b=g;b<x;b++)o[b]==="\\"&&b+1<x?(o[b+1]==="|"&&s("escape",b,b+2),b++):o[b]==="|"&&s("marker",b,b+1)},f=(g,x,b)=>{g&&(c(g),b&&x.length>0&&a(g,0,Math.max(...x.map(w=>w.pos?.to??0)),b),p(g,x))},p=(g,x)=>{let b=w=>{for(let k of w){let{pos:S}=k;if(S)switch(k.type){case"text":if(k.pieces){let v=S.from;for(let T of k.pieces)a(g,v,T.from,"escape"),v=T.to;a(g,v,S.to,"escape")}break;case"hardBreak":{let v=new xe(g,n).source(S.from);o[v]==="\\"&&s("marker",v,v+1);break}case"code":{for(let v of k.syntax??[])a(g,v.from,v.to,"marker");k.content&&a(g,k.content.from,k.content.to,"code");break}case"html":a(g,S.from,S.to,"html");break;case"token":a(g,S.from,S.to,"token");break;case"emphasis":case"strong":case"strike":{let v=k.syntax?.find(E=>E.kind==="open"),T=k.syntax?.find(E=>E.kind==="close");for(let E of k.syntax??[])a(g,E.from,E.to,"marker");a(g,v?.to??S.from,T?.from??S.to,k.type==="emphasis"?"em":k.type),b(k.children);break}case"link":case"image":{let v=k.syntax?.find(A=>A.kind==="open"),T=k.syntax?.find(A=>A.kind==="close"),E=k.syntax?.find(A=>A.kind==="dest");for(let A of k.syntax??[])A.kind==="dest"?a(g,A.from,A.to,"url"):A.kind==="tail"&&E&&E.from>=A.from&&E.to<=A.to?(a(g,A.from,E.from,"marker"),a(g,E.to,A.to,"marker")):A.kind!=="title"&&a(g,A.from,A.to,"marker");v&&T&&!(E&&E.from===v.to&&E.to===T.from)&&a(g,v.to,T.from,"link"),b(k.children);break}default:break}}};b(x)},m=g=>{switch(g.type){case"paragraph":case"heading":case"htmlBlock":case"raw":return g.source?.lines[0]?.line??0;case"codeBlock":case"thematicBreak":case"table":return g.lines?.start??0;case"blockQuote":case"listItem":return g.children[0]?m(g.children[0]):0;case"list":return g.items[0]?m(g.items[0]):0}},y=g=>{switch(g.type){case"paragraph":f(g.source,g.children);break;case"heading":{f(g.source,g.children,"heading");let x=g.source?.lines[0];if(!x)break;if(g.setext){let b=l(x.line+(g.source?.lines.length??1)),w=xa.exec(o.slice(b.from,b.to))[0];d(b.from,b.from+w.length),s("marker",b.from+w.length,b.to)}else{let b=l(x.line),w=o.slice(b.from,b.from+x.offset),k=/#{1,6}[ \t]*$/.exec(w);k&&s("marker",b.from+k.index,b.from+k.index+k[0].trimEnd().length);let S=o.slice(b.from+x.offset,b.to),v=/(?:^|[ \t]+)(#+)[ \t]*$/.exec(S);v&&s("marker",b.from+x.offset+v.index+v[0].indexOf("#"),b.from+x.offset+v.index+v[0].trimEnd().length)}break}case"thematicBreak":if(g.lines){let x=l(g.lines.start);s("marker",u(x),x.to)}break;case"blockQuote":g.children.forEach(y);break;case"list":for(let x of g.items){if(x.lines&&m(x)!==x.lines.start&&u(l(x.lines.start)),x.task){let b=x.children[0],k=(b?.type==="paragraph"?b.source:void 0)?.lines[0];if(k){let S=(n.starts[k.line-1]??0)+k.offset;Ph.test(o.slice(S,n.ends[k.line-1]))&&s("marker",S,S+3)}}x.children.forEach(y)}break;case"codeBlock":{if(!g.source||!g.lines)break;let x=g.source.lines;if(g.fenced){let b=l(g.lines.start),w=u(b),k=o.slice(w,b.to),S=k.trimStart(),v=w+k.length-S.length,T=Hh.exec(S);T&&(s("marker",v,v+T[1].length),s("lang",v+T[1].length,b.to));let E=x[x.length-1]?.line??g.lines.start;if(g.lines.end>E){let A=l(g.lines.end);s("marker",u(A),A.to)}}if(c(g.source),x.length>0){let b=g.value.replace(/\n$/,"").length;a(g.source,0,b,"code");let w=new xe(g.source,n);r.push({from:w.source(0),to:w.source(b),language:Bi(g.info)})}break}case"htmlBlock":case"raw":g.source&&(c(g.source),a(g.source,0,g.value.length,g.type==="raw"?"token":"html"));break;case"table":if(g.lines){for(let x=g.lines.start;x<=g.lines.end;x++){let b=l(x),w=u(b);x===g.lines.start+1?s("marker",w,b.to):h(w,b.to)}g.sources?.forEach((x,b)=>x.forEach((w,k)=>p(w,g.rows[b]?.[k]??[])))}break}};return t.children.forEach(y),i.sort((g,x)=>g.from-x.from||x.to-g.to),{ranges:i,code:r}}var Sa={marker:"mbe-src-marker",heading:"mbe-src-heading",em:"mbe-src-em",strong:"mbe-src-strong",strike:"mbe-src-strike",code:"mbe-src-code",link:"mbe-src-link",url:"mbe-src-url",html:"mbe-src-html",token:"mbe-src-token",escape:"mbe-src-escape",lang:"mbe-src-lang"},$h=new Set(["marker","code","url","html","token","escape","lang"]),Ta=2e4,Ea=1e3,Fh=80;function qh(o,e,t,n){let i=n.highlight?_h(t,n.classes):[];if(n.decorators.length>0){let r=Pn(o,La(e,t));for(let s of n.decorators)i.push(...s(r))}if(n.codeDecorators.length>0)for(let r of t.code){let s={block:o,text:e.slice(r.from,r.to),language:r.language};for(let l of n.codeDecorators.flatMap(a=>a(s))){let a=r.from+Math.max(0,l.from),d=r.from+Math.min(r.to-r.from,l.to);d>a&&i.push({...l,from:a,to:d})}}return i}var Vo=class{constructor(e,t,n){this.options=e;this.config=t;this.onReady=n}last=null;markupFor=null;spansFor=null;pending=null;markup(e){return this.markupFor?.text!==e&&(this.markupFor={text:e,markup:wa(e,this.options)}),this.markupFor.markup}spans(e){let t=this.markupFor?.text===e?this.markupFor.markup:null;if(this.spansFor?.text===e&&(!t||this.spansFor.markup===t))return this.spansFor.spans;let n=t;if(!n&&this.markupFor&&e.length>Ta){let r=Ma(this.markupFor.markup.ranges,this.markupFor.text,e);r&&(n={ranges:r,code:this.markupFor.markup.code})}n??=this.markup(e);let i=La(e,n);return this.spansFor={text:e,markup:n,spans:i},i}decorations(e){let t=I(e.content),n=this.last;if(n&&n.text===t)return n.decorations;if(n&&t.length>Ta){let i=Ma(n.decorations,n.text,t);if(i)return this.last={text:t,decorations:i},this.schedule(e),i}return this.read(e,t)}reset(){this.last=null}destroy(){this.pending!==null&&clearTimeout(this.pending),this.pending=null}read(e,t){this.destroy();let n=qh(e,t,this.markup(t),this.config());return this.last={text:t,decorations:n},n}schedule(e){this.destroy(),this.pending=setTimeout(()=>{this.pending=null;let t=this.last;if(!t)return;let n=this.read(e,t.text);$n(t.decorations,n)||this.onReady()},Fh)}};function Ma(o,e,t){let{from:n,toBefore:i,toAfter:r}=dr(e,t);if(i-n>Ea||r-n>Ea)return null;let s=t.length-e.length,l=[];for(let a of o){let d=a.from<n?a.from:a.from>=i?a.from+s:n,u=a.to<=n?a.to:a.to>=i?a.to+s:n;u>d&&l.push(d===a.from&&u===a.to?a:{...a,from:d,to:u})}return l}function _h(o,e){return o.ranges.map(t=>{let n=e?.[t.kind];return{from:t.from,to:t.to,class:n?`${Sa[t.kind]} ${n}`:Sa[t.kind]}})}var Ca=["code"],Ia=[];function La(o,e){let t=[],n=(s,l,a)=>{l>s&&t.push({text:o.slice(s,l),marks:a})},i=0,r=0;for(let s of e.ranges)$h.has(s.kind)&&(s.from>r&&(n(i,r,Ca),n(r,s.from,Ia),i=s.from),r=Math.max(r,s.to));return n(i,r,Ca),n(r,o.length,Ia),t}var Pa=["text","heading1","heading2","heading3","heading4","bulletList","numberedList","todoList","quote","callout","details","code","table","divider"],Kh=[{id:"text",aliases:["paragraph","plain"],spec:{type:"paragraph"}},{id:"heading1",aliases:["h1","title"],spec:{type:"heading",level:1}},{id:"heading2",aliases:["h2","subtitle"],spec:{type:"heading",level:2}},{id:"heading3",aliases:["h3"],spec:{type:"heading",level:3}},{id:"heading4",aliases:["h4"],spec:{type:"heading",level:4}},{id:"bulletList",aliases:["ul","unordered","bullet"],spec:{type:"listItem",listType:"bullet"}},{id:"numberedList",aliases:["ol","ordered"],spec:{type:"listItem",listType:"ordered"}},{id:"todoList",aliases:["task","checkbox","checklist"],spec:{type:"listItem",listType:"task"}},{id:"quote",aliases:["blockquote","citation"],spec:{type:"quote"}},{id:"callout",aliases:["alert","admonition","note","tip","important","warning","caution"],spec:{type:"quote",callout:"note"}},{id:"details",aliases:["toggle","collapse","collapsible","summary","spoiler","fold"],spec:{type:"details"}},{id:"code",aliases:["pre","snippet","fence"],spec:{type:"code"}},{id:"table",aliases:["grid"],spec:{type:"table"}},{id:"divider",aliases:["hr","separator","line","rule"],spec:{type:"divider"}}],Vh=[{id:"addRowAbove",action:{kind:"addRowAbove"}},{id:"addRowBelow",action:{kind:"addRowBelow"}},{id:"addColumnLeft",action:{kind:"addColumnLeft"}},{id:"addColumnRight",action:{kind:"addColumnRight"}},{id:"deleteRow",action:{kind:"deleteRow"}},{id:"deleteColumn",action:{kind:"deleteColumn"}}],Uh=[{id:"alignLeft",align:"left",image:"imageAlignLeft"},{id:"alignCenter",align:"center",image:"imageAlignCenter"},{id:"alignRight",align:"right",image:"imageAlignRight"}],zh=["/","\uFF0F"],Ba=".mbe-widget, .mbe-block-after",Aa=/^(Arrow(Up|Down|Left|Right)|Home|End|PageUp|PageDown)$/,Na=new Set(["insertCompositionText","deleteCompositionText","insertFromComposition","deleteByComposition"]),Fr=class{root;labels;commands;suggestion;current;source;markdown;history=new oo(()=>this.source);modeValue="rich";pendingMode=null;renderer;composing=!1;composition=null;compositionEndedAt=0;shortcut=null;unsettled=new Set;settleFrame=null;readOnly;wasReadOnly=!1;taskToggle;smartLists;sourceHighlighting;sourceHighlighter;options;extensions;bindings;runtime;classesKey="{}";tokenNames=[];listeners=new Map;cleanup=[];widgets=[];changeFrame=null;plainPasteNext=!1;destroyed=!1;focused=!1;pointerDown=!1;toolbarClosedFor=null;typing=0;caretKey=null;suggestions;blockMenu;toolbar;imageToolbar;inputPopover;blockHandle;collapsed=new Set;linkCard;resizeHandles;selectedImageEl=null;hintEl=null;blockSel=null;selectedEls=[];headingIdsFor=null;redecoratePending=!1;viewFrame=0;constructor(e){let t=e.element;this.root=t,this.options=e,this.runtime={},this.labels={...Mi,...e.labels},this.readOnly=e.editable===!1,this.taskToggle=e.taskToggle===!0,this.smartLists=e.smartLists!==!1,this.sourceHighlighting=e.sourceHighlighting!==!1;let n=e.extensions??[];this.extensions=n.some(c=>c.name==="defaultKeymap")?n:[...n,rr()],this.bindings=this.extensions.flatMap(c=>Object.entries(c.keymap??{}).map(([h,f])=>Wl(h,f,ie)));let i=n.flatMap(c=>c.markdown?[c.markdown]:[]);this.markdown=Ze({...e.markdown,syntax:[...e.markdown?.syntax??[],...i]});let r=Le(e.content??"",this.markdown);this.source=r.source,this.current=Hn(r.doc),this.renderer=new Ho(t,this.labels),this.renderer.collapsed=this.collapsed,this.collapseClosedSections(this.current.doc),this.renderer.widgetsAfter=c=>{if(this.widgets.length===0)return;let h=this.widgets.filter(f=>f.blockId===c).map(f=>f.element);return h.length?h:void 0};let s=[["markdown",Nr]];e.sanitizeHtml&&s.push(["html",ya(e.sanitizeHtml)]),this.renderer.views=new Map([...s,...this.extensions.flatMap(c=>Object.entries(c.views??{}).filter(([h])=>h!=="html"))]),this.renderer.viewContext={editor:this},this.renderer.blockViews=this.extensions.flatMap(c=>c.blockView?[{name:c.name,view:c.blockView}]:[]),this.renderer.markdown=this.markdown,this.renderer.onViewSettled=c=>this.viewsSettled(c);let l=this.extensions.flatMap(c=>c.codeDecorations?[c.codeDecorations]:[]);l.length>0&&(this.renderer.decorateCode=c=>{let h={block:c,text:I(c.content),language:c.language};return l.flatMap(f=>f(h))});let a=this.extensions.flatMap(c=>c.decorations?[c.decorations]:[]);a.length>0&&(this.renderer.decorate=(c,h,f)=>{let p=Pn(c,h,f);return a.flatMap(m=>m(p))}),this.sourceHighlighter=new Vo(this.markdown,()=>({highlight:this.sourceHighlighting,classes:this.renderer.classes.source,decorators:a,codeDecorators:l}),()=>this.refreshSource()),this.renderer.decorateSource=c=>this.sourceHighlighter.decorations(c),this.commands=this.createCommands(),t.classList.add("mbe-root"),t.setAttribute("role","textbox"),t.setAttribute("aria-multiline","true"),t.spellcheck=!0,t.translate=!1,t.style.setProperty("--mbe-slash-hint",JSON.stringify(this.labels.slashHint)),this.applyRuntime({placeholder:e.placeholder,attributes:e.attributes}),this.runtime={...this.runtime,resolveUrl:e.resolveUrl,onLinkClick:e.onLinkClick},this.renderer.resolveUrl=e.resolveUrl??Ln,this.renderer.referrerPolicy=e.referrerPolicy,this.renderer.codeCopy=e.codeCopy!==!1,this.renderer.icon=c=>X(t.ownerDocument,this.icon(c)),this.applyTheme(e.theme),ir(t,e.popupContainer);let d=this.extensions.flatMap(c=>c.suggestion?[c.suggestion]:[]);e.slashMenu!==!1&&d.push(this.slashSuggestion()),this.suggestions=new Co({editor:this,root:t,syncActiveDescendant:()=>this.syncActiveDescendant(),refresh:()=>this.updateUi(),endComposition:()=>this.endComposition(),changed:c=>this.emit("suggestionChange",{editor:this,state:c})},d);let u=this.suggestions;this.suggestion={get state(){return u.state},open:c=>!this.destroyed&&(this.refreshSelection(),u.open(c)),close:()=>u.dismiss(),move:c=>u.move(c),accept:c=>!this.destroyed&&u.accept(c)},this.blockMenu=new Xe(t,"mbe-block-menu","menu"),this.blockMenu.onPicked=()=>this.blockMenu.hide(),this.blockMenu.onHighlight=()=>this.syncActiveDescendant(),this.blockMenu.checkIcon=this.icon("selected"),this.blockMenu.submenuIcon=this.icon("chevronRight"),this.inputPopover=new Lo(this),this.toolbar=e.toolbar===!1?null:new Io(this,typeof e.toolbar=="object"?e.toolbar.items:void 0),this.toolbar&&(this.toolbar.onMenuChange=()=>this.syncActiveDescendant()),this.imageToolbar=e.toolbar===!1?null:new Ao(this,{align:(c,h)=>this.updateImageAt(c.pos,{align:h==="left"?null:h}),altText:c=>this.editAltText(c.pos,c.image.alt),resetSize:c=>this.updateImageAt(c.pos,{width:null}),remove:c=>this.deleteImageAt(c.pos)}),this.blockHandle=new qo(this),this.linkCard=e.linkCard===!1?null:new _o(this,{open:(c,h)=>this.openHref(c.el.getAttribute("href"),h),edit:c=>this.editLink(c),remove:c=>this.removeLink(c),targetOf:c=>this.linkTargetOf(c)}),this.resizeHandles=new Bo(this),this.renderer.onImageError=()=>{this.destroyed||(this.composing||this.syncDomSelection(),this.updateUi())},this.listen(t,"beforeinput",this.typed(c=>this.onBeforeInput(c))),this.listen(t,"input",this.typed(c=>this.onInput(c))),this.listen(t,"compositionstart",c=>this.onCompositionStart(c)),this.listen(t,"compositionend",this.typed(c=>this.onCompositionEnd(c))),this.listen(t,"keydown",this.typed(c=>this.onKeyDown(c))),this.listen(t,"copy",c=>this.onCopy(c,!1)),this.listen(t,"cut",this.typed(c=>this.onCopy(c,!0))),this.listen(t,"paste",this.typed(c=>this.onPaste(c))),this.listen(t,"dragstart",c=>c.preventDefault()),this.listen(t,"dragover",c=>{this.readOnly||c.preventDefault()}),this.listen(t,"drop",this.typed(c=>this.onDrop(c))),this.listen(t,"mousedown",c=>this.onMouseDown(c)),this.listen(t,"click",c=>this.onClick(c)),this.listen(t,"change",c=>this.onControlChange(c)),this.listen(t,"focusin",c=>this.onFocusIn(c)),this.listen(t,"focusout",c=>this.onFocusOut(c)),this.listen(t.ownerDocument,"selectionchange",()=>this.onSelectionChange()),this.listen(t.ownerDocument,"mouseup",()=>this.onMouseUp()),this.listen(t.ownerDocument,"scroll",()=>this.onScroll(),!0),this.listen(t.ownerDocument,"pointerdown",c=>this.onDocumentPointerDown(c),!0),e.mode==="source"&&this.enterSource(),this.paint(!0,!0),this.afterRender();for(let c of this.extensions){let h=c.onCreate?.({editor:this});typeof h=="function"&&this.cleanup.push(h)}e.autofocus&&this.commands.focus(e.autofocus==="end"?"end":"start")}getMarkdown(){return this.modeValue==="source"?K(this.current.doc):Pt(this.current.doc,{...this.markdown,source:this.source})}setMarkdown(e,t={}){if(this.destroyed)return;if(t.history==="keep"?this.history.record(this.current,"other"):this.history.clear(),this.modeValue==="source"){this.suggestions.reset(),this.current=Fe(e,0);for(let r of this.widgets)r.offset=Math.min(r.offset,e.length);this.paint(!0,!0),this.afterRender(),this.emit("selectionChange",{editor:this});return}let n=Le(e,this.markdown);this.source=n.source,this.blockSel=null,this.suggestions.reset();let i=Hn(n.doc);this.collapsed.clear(),this.collapseClosedSections(i.doc),this.relocateWidgets(this.current.doc,i.doc,!0),this.current=i,this.paint(!0,!0),this.afterRender(),this.emit("selectionChange",{editor:this})}get isEmpty(){return this.modeValue==="source"?K(this.current.doc)==="":this.current.doc.blocks.every(e=>e.type==="paragraph"&&B(e.content)===0)}get state(){return this.current}get isComposing(){return this.composing}get mode(){return this.pendingMode??this.modeValue}get isEditable(){return!this.readOnly&&!this.destroyed}get isDestroyed(){return this.destroyed}isActive(e,t){if(this.modeValue==="source")return!1;let n=this.current;switch(e){case"bold":case"italic":case"strike":case"code":return Vn(n,e);case"link":return Qe(n)!==null;case"image":{let s=De(n);if(!s||!t)return s!==null;let l={...s.image,block:ke(n)!==null};return Object.entries(t).every(([a,d])=>l[a]===d)}}let i=N(n.doc,n.selection.focus.blockId);if(Da(i)!==e&&!(e==="blockquote"&&M(i)))return!1;if(!t)return!0;let r=this.getAttributes(e);return Object.entries(t).every(([s,l])=>r[s]===l)}getAttributes(e){if(this.modeValue==="source")return{};let t=this.current;if(e==="link"){let r=Qe(t);return r?{href:r.href}:{}}if(e==="image"){let r=De(t);return r?{...r.image,block:ke(t)!==null}:{}}let n=N(t.doc,t.selection.focus.blockId),i=M(n);if(e==="blockquote"&&i)return i==="quote"?{}:{callout:i};if(Da(n)!==e)return{};switch(n.type){case"heading":return{level:n.level};case"code":return{language:n.language};case"listItem":return n.listType==="task"?{checked:n.checked,indent:n.indent}:{indent:n.indent};case"raw":return{syntax:n.syntax};case"quote":return n.callout?{callout:n.callout}:{};case"details":return{open:n.open,collapsed:this.collapsed.has(n.id)};default:return{}}}getSelection(){return this.current.selection}setSelection(e){if(this.destroyed)return!1;let t=jh(e)?te(this.current.doc,e):Gh(this.current.doc,e);return t?(this.dropBlockSelection(),this.current={...this.current,selection:t,storedMarks:null},this.history.breakGroup(),this.refreshRevealed(),this.syncDomSelection(),this.updateUi(),this.emit("selectionChange",{editor:this}),!0):!1}selectionToJSON(){let e=this.current.doc,t=n=>{let i=L(e,n.blockId);return n.cell?{block:i,offset:n.offset,cell:{row:n.cell.row,col:n.cell.col}}:{block:i,offset:n.offset}};return{anchor:t(this.current.selection.anchor),focus:t(this.current.selection.focus)}}hasFocus(){let e=this.root.ownerDocument.activeElement;return!!e&&this.root.contains(e)&&!(e instanceof HTMLInputElement)&&!e.closest(Ba)}addWidget(e){if(this.destroyed){let l=new kt(this.root.ownerDocument.createElement("div"),"",()=>{},()=>{});return l.remove(),l}let t=this.current.doc.blocks,n=e.at==="end"?P(t[t.length-1]):e.at,i=te(this.current.doc,{anchor:n,focus:n}).focus.blockId,r=this.root.ownerDocument.createElement("div");r.className="mbe-widget",r.contentEditable="false";let s=new kt(r,i,e.render,l=>{this.widgets=this.widgets.filter(a=>a!==l)});return this.modeValue==="source"&&(s.offset=e.at==="end"?K(this.current.doc).length:n.offset),this.widgets.push(s),this.paint(),s}relocateWidgets(e,t,n){if(this.widgets.length===0)return;let i=new Set(t.blocks.map(r=>r.id));for(let r of this.widgets){if(i.has(r.blockId))continue;let s=e.blocks.findIndex(a=>a.id===r.blockId),l;if(n)l=t.blocks[Math.max(0,Math.min(s,t.blocks.length-1))].id;else{for(let a=s-1;a>=0&&!l;a--)i.has(e.blocks[a].id)&&(l=e.blocks[a].id);for(let a=s+1;a<e.blocks.length&&!l&&s>=0;a++)i.has(e.blocks[a].id)&&(l=e.blocks[a].id)}r.blockId=l??t.blocks[0].id}}focus(){if(this.destroyed)return;let e=this.current.selection.focus,t=this.renderer.elementFor(e.blockId);((e.cell&&t?se(t,e.cell):this.root)??this.root).focus({preventScroll:!0}),this.syncDomSelection(!0)}blur(){this.hasFocus()&&this.root.ownerDocument.activeElement?.blur()}setOptions(e){if(this.destroyed)return;e.extensions&&this.suggestions.setConfigs(e.extensions.flatMap(n=>n.suggestion?[n.suggestion]:[]));let t=e.taskToggle!==void 0&&e.taskToggle!==this.taskToggle;t&&(this.taskToggle=e.taskToggle===!0),e.editable!==void 0&&e.editable===this.readOnly?(this.readOnly=!e.editable,this.renderer.views?.has("footnote")?this.paint():this.refreshRevealed(),this.applyReadOnly(),this.hideUi()):t&&this.applyReadOnly(),this.applyRuntime(e),e.mode!==void 0&&this.setMode(e.mode)}setMode(e){if(e!=="rich"&&e!=="source")return;if(this.composing||this.composition){this.pendingMode=e===this.modeValue?null:e;return}if(this.pendingMode=null,e===this.modeValue)return;let t=this.hasFocus(),n=this.caretRect()?.top;this.blockSel=null,this.shortcut=null,this.suggestions.reset(),this.hideUi(),this.closeBlockMenu(),this.history.breakGroup(),e==="source"?this.enterSource():this.leaveSource(),this.paint(!0,!1,t),this.afterRender();let i=this.caretRect()?.top;n!==void 0&&i!==void 0&&Math.abs(i-n)>1&&Xh(this.root,i-n),this.emit("selectionChange",{editor:this})}enterSource(){let{doc:e,selection:t}=this.current,n=this.getMarkdown(),i=Le(n,this.markdown),r=hr(e,t,i);for(let s of this.widgets)s.offset=Ol(e,s.blockId,i),s.blockId=xn;this.collapsed.clear(),this.current=Fe(n,r.anchor,r.focus),this.modeValue="source",this.renderer.source=!0,this.root.classList.add("mbe-source-mode")}leaveSource(){let{anchor:e,focus:t}=this.current.selection,n=this.loadSource(K(this.current.doc));for(let r of this.widgets)r.blockId=wo(r.offset,n).blockId;let i=fr(e.offset,t.offset,n);this.current={doc:n.doc,selection:te(n.doc,i),storedMarks:null},this.modeValue="rich",this.renderer.source=!1,this.root.classList.remove("mbe-source-mode")}loadSource(e){let t=Le(e,this.markdown),n=Hn(t.doc).doc;return this.source=t.source,this.collapsed.clear(),this.collapseClosedSections(n),{doc:n,source:t.source}}restore(e){let{state:t}=e,n=So(t.doc);if(this.modeValue==="source"){if(n)return t;let s=Pt(t.doc,{...this.markdown,source:e.source}),l=hr(t.doc,t.selection,Le(s,this.markdown));return Fe(s,l.anchor,l.focus)}if(!n)return this.source=e.source,t;let i=this.loadSource(K(t.doc)),r=fr(t.selection.anchor.offset,t.selection.focus.offset,i);return{doc:i.doc,selection:te(i.doc,r),storedMarks:null}}on(e,t){let n=this.listeners.get(e);return n||this.listeners.set(e,n=new Set),n.add(t),()=>void n.delete(t)}emit(e,t){let n=this.listeners.get(e);if(n)for(let i of[...n])i(t)}applyRuntime(e){let t=this.root;if("placeholder"in e&&(e.placeholder?(t.style.setProperty("--mbe-placeholder",JSON.stringify(e.placeholder)),t.setAttribute("aria-placeholder",e.placeholder)):(t.style.removeProperty("--mbe-placeholder"),t.removeAttribute("aria-placeholder")),this.runtime={...this.runtime,placeholder:e.placeholder}),"attributes"in e){for(let n of Object.keys(this.runtime.attributes??{}))t.removeAttribute(n);for(let[n,i]of Object.entries(e.attributes??{}))t.setAttribute(n,i);this.runtime={...this.runtime,attributes:e.attributes}}"resolveUrl"in e&&e.resolveUrl!==this.runtime.resolveUrl&&(this.runtime={...this.runtime,resolveUrl:e.resolveUrl},this.renderer.resolveUrl=e.resolveUrl??Ln,this.paint(!0)),"onLinkClick"in e&&(this.runtime={...this.runtime,onLinkClick:e.onLinkClick}),"theme"in e&&this.applyTheme(e.theme)&&this.paint(!0)}applyTheme(e){let t=$r(this.runtime.theme?.tokens);this.runtime={...this.runtime,theme:e};let n=this.root.style,i=$r(e?.tokens);for(let a of this.tokenNames)i.has(a)||n.removeProperty(a);for(let[a,d]of i)n.setProperty(a,d);this.tokenNames=[...i.keys()];let r=e?.colorScheme??"auto";n.colorScheme=r==="auto"?"":r,va.some(a=>t.get(a)!==i.get(a))&&this.renderBlocksAgain(this.renderer.dropViews());let s=ka([...this.extensions.map(a=>a.theme?.classes).reverse(),e?.classes]),l=JSON.stringify(s);return l===this.classesKey?!1:(this.classesKey=l,this.renderer.classes=s,!0)}run(e,t="other"){if(this.readOnly||this.destroyed)return!1;let n=e(this.current);return!n||n===this.current||(n=bi(n,this.current,this.markdown.inline),n=yi(n,this.current),n=li(n),n.doc!==this.current.doc&&Qh(n.doc,this.current.doc)&&(n={...n,doc:this.current.doc}),n.doc===this.current.doc&&n.selection===this.current.selection&&n.storedMarks===this.current.storedMarks)?!1:(this.apply(n,t),!0)}createCommands(){let e=l=>this.run(l),t=l=>e(a=>ht(a,l)),n={toggleBold:()=>e(l=>We(l,"bold")),toggleItalic:()=>e(l=>We(l,"italic")),toggleStrike:()=>e(l=>We(l,"strike")),toggleCode:()=>e(l=>We(l,"code")),setParagraph:()=>e(l=>Ge(l,{type:"paragraph"})),toggleHeading:({level:l})=>t({type:"heading",level:l}),toggleBulletList:()=>t({type:"listItem",listType:"bullet"}),toggleOrderedList:()=>t({type:"listItem",listType:"ordered"}),toggleTaskList:()=>t({type:"listItem",listType:"task"}),toggleBlockquote:()=>t({type:"quote"}),toggleCallout:(l={})=>this.markdown.callouts&&t({type:"quote",callout:l.type??"note"}),toggleDetails:()=>this.markdown.details&&t({type:"details"}),setCallout:({type:l})=>(this.markdown.callouts||l===null)&&e(a=>sn(a,a.selection.focus.blockId,l)),toggleCodeBlock:(l={})=>t({type:"code",language:l.language}),setLink:({href:l})=>e(a=>ut(a,l)),unsetLink:()=>e(l=>ut(l,null)),updateImage:l=>e(a=>{let d=De(a);return d?Un(a,d.pos,l):null}),insertText:(l,a={})=>e(d=>{let u=a.range;if(!u)return ue(d,l);let c=te(d.doc,{anchor:u.from,focus:u.to});return ue({...d,selection:c,storedMarks:null},l)}),insertToken:l=>!this.composing&&e(a=>ni(a,l)),insertMarkdown:(l,a={})=>{let d=bt(l,this.markdown).blocks,u=a.at;if(u instanceof kt){if(u.isRemoved)return!1;let c=N(this.current.doc,u.blockId);return e(h=>cn(h,d,{...a,at:P(c),block:!0}))}return e(c=>cn(c,d,a))},insertTable:(l={})=>e(a=>Rt(a,{type:"table",rows:l.rows,cols:l.cols})),insertDivider:()=>e(l=>Rt(l,{type:"divider"})),indent:()=>e(l=>Wn(l,1)),outdent:()=>e(l=>Wn(l,-1)),undo:()=>this.undo(),redo:()=>this.redo(),selectAll:()=>(this.setSelection(xi(this.current).selection),!0),selectBlocks:()=>{if(this.readOnly)return!1;this.hasFocus()||this.root.focus({preventScroll:!0});let{anchor:l,focus:a}=this.current.selection;return this.selectBlockRange(l.blockId,a.blockId),!0},focus:l=>{if(l!==void 0){let a=this.current.doc.blocks,d=l==="start"?V(a[0]):l==="end"?P(a[a.length-1]):l;this.current={...this.current,selection:te(this.current.doc,{anchor:d,focus:d})}}return this.focus(),this.emit("selectionChange",{editor:this}),!0},blur:()=>{let l=this.hasFocus();return this.blur(),l},scrollIntoView:()=>{let l=this.caretRect();return l?(Pr(this.root,l),!0):!1}},i={...n},r=(l,a)=>{let d=i[l];n[l]=(...u)=>this.modeValue==="source"?a?a(...u):!1:d(...u)},s=l=>e(a=>(this.smartLists?Rl(a,l):null)??ln(a,l));r("indent",()=>s(1)),r("outdent",()=>s(-1)),r("insertMarkdown",(l,a={})=>this.insertSourceMarkdown(l,a)),r("toggleBold",()=>e(l=>Tn(l,"**"))),r("toggleItalic",()=>e(l=>Tn(l,"*"))),r("toggleStrike",()=>e(l=>Tn(l,"~~"))),r("toggleCode",()=>e(l=>Tn(l,"`"))),r("setParagraph",()=>e(l=>pr(l,0))),r("toggleHeading",({level:l})=>e(a=>pr(a,l))),r("toggleBulletList",()=>e(l=>Eo(l,"bullet"))),r("toggleOrderedList",()=>e(l=>Eo(l,"ordered"))),r("toggleTaskList",()=>e(l=>Eo(l,"task"))),r("toggleBlockquote",()=>e(l=>Fl(l))),r("toggleCodeBlock",()=>e(l=>ql(l)));for(let l of["toggleCallout","setCallout","toggleDetails","setLink","unsetLink","updateImage","insertTable","insertDivider","selectBlocks"])r(l,null);for(let l of Object.keys(n)){let a=n[l];n[l]=(...d)=>!this.destroyed&&a(...d)}return n}insertSourceMarkdown(e,t){let n=t.at??"selection",i=t.select==="keep",r=t.block===!0;return n instanceof kt?n.isRemoved?!1:this.run(s=>To(s,n.offset,e,!0,i)):n==="selection"&&!r&&!i?this.run(s=>Ae(s,e)):this.run(s=>{let l=s,a;if(n==="selection"){let{from:d,to:u}=ne(s);d!==u&&(l=Ae(s,"")),a=d}else a=n==="end"?K(s.doc).length:n.offset;return To(l,a,e,r,i)})}undo(){if(this.readOnly)return!1;let e=this.history.undo(this.current);return e?(this.commit(this.restore(e)),!0):!1}redo(){if(this.readOnly)return!1;let e=this.history.redo(this.current);return e?(this.commit(this.restore(e)),!0):!1}selectionRect(){let e=this.root.ownerDocument.getSelection();if(!e||e.rangeCount===0)return null;let t=e.getRangeAt(0),n=t.getClientRects(),i=n.length?R(this.current.selection)?n[n.length-1]:t.getBoundingClientRect():null;return i&&(i.width>0||i.height>0)?i:this.emptyRect(this.current.selection.focus,e.focusNode)}caretRect(){let e=this.current.selection.focus,t=this.toDom(e);if(t){let n=this.root.ownerDocument.createRange();n.setStart(t.node,t.offset);let i=n.getClientRects(),r=i[i.length-1];if(r&&r.height>0)return r}return this.emptyRect(e,t?.node??null)}emptyRect(e,t){let n=this.renderer.elementFor(e.blockId),i=(n&&se(n,e.cell))??n,r=t?.nodeType===1?t:t?.parentElement??null;if(i&&r&&r!==i&&i.contains(r)){let s=r.getBoundingClientRect();if(s.height>0)return s}return i?.getBoundingClientRect()??null}textRect(e,t){let n=this.toDom(e),i=this.toDom(t);if(!n||!i)return null;let r=this.root.ownerDocument.createRange();r.setStart(n.node,n.offset),r.setEnd(i.node,i.offset);let s=r.getClientRects()[0];if(!s)return null;let l=n.node.nodeType===1?n.node:n.node.parentElement,a=!!l&&this.root.ownerDocument.defaultView.getComputedStyle(l).direction==="rtl";return{rect:s,rtl:a}}scrollCaretIntoView(){let e=this.caretRect();e&&Pr(this.root,e)}blockElement(e){return this.renderer.elementFor(e)}destroy(){if(!this.destroyed){this.destroyed=!0,this.changeFrame!==null&&cancelAnimationFrame(this.changeFrame),this.settleFrame!==null&&cancelAnimationFrame(this.settleFrame),this.sourceHighlighter.destroy();for(let e of this.cleanup)e();this.suggestions.destroy();for(let e of[...this.widgets])e.remove();this.blockMenu.destroy(),this.toolbar?.destroy(),this.imageToolbar?.destroy(),this.inputPopover.destroy(),this.blockHandle.destroy(),this.linkCard?.destroy(),this.resizeHandles.destroy(),this.renderer.destroy(),ir(this.root,void 0);for(let e of Object.keys(this.runtime.attributes??{}))this.root.removeAttribute(e);for(let e of this.tokenNames)this.root.style.removeProperty(e);this.root.style.colorScheme="",this.root.contentEditable="false",this.root.classList.remove("mbe-root"),this.root.replaceChildren(),this.listeners.clear()}}apply(e,t){e.doc!==this.state.doc&&this.history.record(this.state,t),this.commit(e)}commit(e){let t=e.doc!==this.state.doc,n=e.selection!==this.state.selection,i=this.hasFocus();if(t&&this.modeValue==="source"){let r=K(this.current.doc),s=K(e.doc);for(let l of this.widgets)l.offset=Dl(l.offset,r,s)}else t&&this.relocateWidgets(this.current.doc,e.doc,!1);if(this.current=e,this.blockSel){let r=this.blockRange();r?this.current={...e,selection:an(e.doc.blocks,r)}:this.blockSel=null}this.paint(!1,!1,i),this.afterRender(),n&&i&&this.typing>0&&this.scrollCaretIntoView(),t&&this.scheduleChange(),this.emit("selectionChange",{editor:this})}flushChange(){this.changeFrame!==null&&(cancelAnimationFrame(this.changeFrame),this.changeFrame=null,this.emitChange())}scheduleChange(){if(this.changeFrame!==null||!this.options.onChange&&!this.listeners.get("change")?.size)return;let e=()=>{this.changeFrame=null,this.destroyed||this.emitChange()};typeof requestAnimationFrame=="function"?this.changeFrame=requestAnimationFrame(e):e()}emitChange(){this.options.onChange&&this.options.onChange(this.getMarkdown(),this),this.emit("change",{editor:this})}submit(){return this.destroyed||!this.options.onSubmit&&!this.listeners.get("submit")?.size?!1:(this.flushChange(),this.options.onSubmit?.(this.getMarkdown(),this),this.emit("submit",{editor:this}),!0)}applyReadOnly(){let e=this.readOnly?"false":"true";if(this.root.contentEditable!==e&&(this.root.contentEditable=e),!this.readOnly&&!this.wasReadOnly)return;this.wasReadOnly=this.readOnly;let t=this.ticking;this.root.classList.toggle("mbe-readonly",this.readOnly),this.root.classList.toggle("mbe-tasks",t),this.root.setAttribute("aria-readonly",String(this.readOnly)),this.root.querySelectorAll("[data-row]").forEach(n=>{n.contentEditable=this.readOnly?"false":"true"}),this.root.querySelectorAll("input").forEach(n=>{let i=n.classList.contains("mbe-checkbox");n.disabled=this.readOnly&&!(i&&t),i&&(n.tabIndex=t?0:-1,t?n.setAttribute("aria-label",Zh(n,this.labels.task)):n.removeAttribute("aria-label"))})}get ticking(){return this.readOnly&&this.taskToggle}toggleTaskAt(e){let t=e.closest("[data-block-id]");if(!t)return;let n=t.dataset.blockId,i=e===this.root.ownerDocument.activeElement;if(!this.readOnly)this.run(r=>Qn(r,n));else if(this.ticking&&this.current.doc.blocks.some(r=>r.id===n))this.apply(Qn(this.current,n),"other");else return;i&&this.root.querySelector(`[data-block-id="${n}"] .mbe-checkbox`)?.focus({preventScroll:!0})}afterRender(){for(let e of this.state.doc.blocks){let t=this.renderer.elementFor(e.id);if(!t||!t.classList.contains("mbe-empty"))continue;let n="";e.type==="heading"?n=this.labels[`heading${Math.min(e.level,4)}`]:e.type==="listItem"?n=this.labels.listHint:e.type==="quote"&&!e.callout?n=this.labels.quoteHint:e.type==="details"&&(n=this.labels.detailsHint),n&&t.dataset.hint!==n&&(t.dataset.hint=n)}this.updateUi()}syncDomSelection(e=!1){let t=this.root.ownerDocument.getSelection();if(!t||!e&&!this.hasFocus())return;let n=this.parkedCaret(),i=n?{anchor:n,focus:n}:this.state.selection,r=this.toDom(i.anchor),s=R(i)?r:this.toDom(i.focus);if(!(!r||!s)&&!(t.anchorNode===r.node&&t.anchorOffset===r.offset&&t.focusNode===s.node&&t.focusOffset===s.offset)){if(i.focus.cell){let l=(s.node instanceof Element?s.node:s.node.parentElement)?.closest("[data-row]");l&&this.root.ownerDocument.activeElement!==l&&l.focus({preventScroll:!0})}else this.root.ownerDocument.activeElement!==this.root&&this.hasFocus()&&this.root.focus({preventScroll:!0});t.setBaseAndExtent(r.node,r.offset,s.node,s.offset)}}toDom(e){let t=this.renderer.elementFor(e.blockId);return t?ma(t,e):null}readDomSelection(){let e=this.root.ownerDocument.getSelection();if(!e||!e.anchorNode||!e.focusNode||!this.root.contains(e.anchorNode)||!this.root.contains(e.focusNode))return null;let t=_e(this.root,e.anchorNode,e.anchorOffset),i=e.anchorNode===e.focusNode&&e.anchorOffset===e.focusOffset?t:_e(this.root,e.focusNode,e.focusOffset);return!t||!i?null:{anchor:t,focus:i}}onSelectionChange(){if(this.composing||this.destroyed)return;let e=this.readDomSelection();if(!e){this.hasFocus()||this.updateUi();return}let t=this.caretKey;if(this.caretKey=null,this.blockSel){this.updateUi();return}let n=this.state.selection;if(be(e.anchor,n.anchor)&&be(e.focus,n.focus)){this.updateUi();return}this.shortcut=null;let i=t?.vertical?this.skippedBlock(t.from,t.vertical,t.x,e.focus):null,r=this.imageBlockAt(i?{anchor:i,focus:i}:e);r?!be(r.anchor,n.anchor)||!be(r.focus,n.focus)?this.setSelection(r):this.updateUi():i?this.setSelection({anchor:i,focus:i}):(this.current={...this.state,selection:e,storedMarks:null},this.history.breakGroup(),this.pointerDown||this.refreshRevealed(),this.updateUi(),this.emit("selectionChange",{editor:this})),t&&this.scrollCaretIntoView()}imageBlockAt(e){if(!R(e)||e.focus.cell)return null;let t=this.state.doc.blocks.find(i=>i.id===e.focus.blockId),n=t?Y(t):null;return n===null?null:{anchor:{blockId:t.id,offset:n},focus:{blockId:t.id,offset:n+1}}}skippedBlock(e,t,n,i){let r=this.state.doc.blocks,s=L(this.state.doc,i.blockId);for(let l=e+t;(s-l)*t>0;l+=t){let a=r[l];if(!this.skipsCaret(a))return this.blockEntry(a,t===1,n)}return null}blockEntry(e,t,n){let i=this.renderer.elementFor(e.id),r=this.viewBlock(e);if(r)return Bn(r,t);if(i){let s=i.ownerDocument.createRange();s.selectNodeContents(se(i)??i);let l=Array.from(s.getClientRects()).filter(u=>u.height>0),a=t?l[0]:l[l.length-1],d=a?this.positionAtPoint(n,a.top+a.height/2):null;if(d?.blockId===e.id)return d}if(e.type==="table"){let s=t?0:e.rows.length-1;return{blockId:e.id,offset:t?0:B(e.rows[s][0]),cell:{row:s,col:0}}}return t?V(e):P(e)}paint(e=!1,t=!1,n=this.hasFocus()){let i=this.renderer.views;i&&!this.pointerDown&&!this.composing&&(this.renderer.revealed=Hr(this.state,i,!this.readOnly&&n,this.hosted)),this.renderer.collectFootnotes=this.readOnly,this.renderer.render(this.state.doc,e,t),this.applyHeadingIds(),this.applyReadOnly(),this.paintBlockSelection(),this.composing||this.syncDomSelection(n)}sourceSpans(e){return this.sourceHighlighter.spans(I(e.content))}refreshSource(){if(this.destroyed||this.modeValue!=="source"||this.composing||this.composition)return;let e=this.current.doc.blocks[0];if(e?.type!=="code")return;let t=this.hasFocus();this.renderer.refreshSource(e),this.pointerDown||this.syncDomSelection(t)}applyHeadingIds(){let e=this.options.headingIds;if(!e)return;let t=this.state.doc;if(this.headingIdsFor?.doc!==t){let n=t.blocks.filter(r=>r.type==="heading"),i=e(n.map(r=>({text:I(r.content),level:r.level})));this.headingIdsFor={doc:t,ids:new Map(n.map((r,s)=>[r.id,i[s]]))}}for(let[n,i]of this.headingIdsFor.ids){let r=this.renderer.elementFor(n);r&&(i?r.id!==i&&(r.id=i):r.id&&r.removeAttribute("id"))}}redecorate(){if(!this.destroyed){if(this.composing||this.composition){this.redecoratePending=!0;return}this.redecoratePending=!1,this.sourceHighlighter.reset(),this.paint(!0),this.afterRender()}}refreshViews(e){this.destroyed||this.renderBlocksAgain(this.renderer.dropViews(e))}renderBlocksAgain(e){if(e.length!==0){if(this.composing||this.composition){for(let t of e)this.unsettled.add(t);return}for(let t of e)this.renderer.invalidate(t);this.paint(),this.afterRender()}}viewsSettled(e){if(!this.destroyed){if(this.composing||this.composition){for(let t of e)this.unsettled.add(t);return}for(let t of e)this.renderer.invalidate(t);this.viewFrame||=requestAnimationFrame(()=>{this.viewFrame=0,!(this.destroyed||this.composing||this.composition)&&(this.paint(),this.afterRender())})}}viewBlock(e){return e&&this.renderer.elementFor(e.id)?.classList.contains("mbe-view-block")?e:null}refreshRevealed(){let e=this.renderer.views;if(!e||this.pointerDown)return;let t=Hr(this.state,e,!this.readOnly&&this.hasFocus(),this.hosted);ba(t,this.renderer.revealed)||this.paint()}hosted=e=>this.renderer.isHosted(e);onMouseUp(){this.pointerDown&&(this.pointerDown=!1,!this.destroyed&&!this.composing&&this.refreshRevealed())}blockPast(e){let t=this.state.selection;if(!R(t)||t.focus.cell)return null;let n=t.focus,i=this.state.doc.blocks,r=L(this.state.doc,n.blockId),s=e==="ArrowDown"||e==="ArrowRight",l=i[r+(s?1:-1)],a=this.viewBlock(l);if(!l||!a&&l.type!=="table")return null;let d=i[r];if(!q(d)||e==="ArrowRight"&&n.offset!==P(d).offset||e==="ArrowLeft"&&n.offset!==0)return null;if(e==="ArrowDown"||e==="ArrowUp"){let u=se(this.renderer.elementFor(d.id));if(u&&!this.onEdgeLine(u,s))return null}return Bn(l,s)}imageBlockStep(e){let t=this.state.selection,n=this.state.doc.blocks,i=e==="ArrowDown"||e==="ArrowRight",r=ke(this.state);if(r){let u=L(this.state.doc,r.pos.blockId);for(let c=u+(i?1:-1);c>=0&&c<n.length;c+=i?1:-1){let h=n[c];if(this.skipsCaret(h))continue;let f=Y(h);if(f!==null)return{anchor:{blockId:h.id,offset:f},focus:{blockId:h.id,offset:f+1}};let m=e==="ArrowDown"||e==="ArrowUp"?this.blockEntry(h,i,this.selectionRect()?.left??0):i?V(h):P(h);return{anchor:m,focus:m}}return t}if(!R(t)||t.focus.cell)return null;let s=L(this.state.doc,t.focus.blockId),l=n[s],a=n[s+(i?1:-1)],d=a?Y(a):null;if(!a||d===null||!q(l)||e==="ArrowRight"&&t.focus.offset!==P(l).offset||e==="ArrowLeft"&&t.focus.offset!==0)return null;if(e==="ArrowDown"||e==="ArrowUp"){let u=se(this.renderer.elementFor(l.id));if(u&&!this.onEdgeLine(u,i))return null}return{anchor:{blockId:a.id,offset:d},focus:{blockId:a.id,offset:d+1}}}tableCellPast(e){let t=this.state.selection,n=t.focus;if(!R(t)||!n.cell)return null;let i=this.state.doc.blocks,r=L(this.state.doc,n.blockId),s=i[r];if(s?.type!=="table")return null;let l=se(this.renderer.elementFor(s.id),n.cell);if(l&&!this.onEdgeLine(l,e===1))return null;let{row:a,col:d}=n.cell,u=s.rows[a+e];if(u){let c=Math.min(n.offset,B(u[d]));return{blockId:s.id,offset:c,cell:{row:a+e,col:d}}}for(let c=r+e;c>=0&&c<i.length;c+=e){let h=i[c];if(this.skipsCaret(h))continue;if(h.type==="table"){let p=e===1?0:h.rows.length-1,m=Math.min(d,h.align.length-1);return{blockId:h.id,offset:e===1?0:B(h.rows[p][m]),cell:{row:p,col:m}}}let f=this.viewBlock(h);return f?Bn(f,e===1):e===1?V(h):P(h)}return null}onEdgeLine(e,t){let n=this.selectionRect();if(!n||n.height===0)return!0;let i=e.ownerDocument.createRange();i.selectNodeContents(e);let r=Array.from(i.getClientRects()).filter(l=>l.height>0);if(r.length===0)return!0;let s=n.height/2;return t?Math.max(...r.map(l=>l.bottom))-n.bottom<=s:n.top-Math.min(...r.map(l=>l.top))<=s}revealView(e){let t=e.hasAttribute(W)?N(this.state.doc,e.getAttribute(W)):null,n=t?Bn(t,!1):_e(this.root,e.parentNode,xt(e)+1);n&&(this.root.focus({preventScroll:!0}),this.setSelection({anchor:n,focus:n}))}refreshSelection(){if(this.blockSel)return;let e=this.readDomSelection();e&&(this.current={...this.state,selection:e})}targetRange(e){let t=e.getTargetRanges?.()[0];if(!t)return null;let n=_e(this.root,t.startContainer,t.startOffset),i=_e(this.root,t.endContainer,t.endOffset);return n&&i?{anchor:n,focus:i}:null}fromControl(e){return e.target instanceof HTMLInputElement||!!e.target?.closest?.(Ba)}onBeforeInput(e){if(this.fromControl(e)||this.composing||e.isComposing)return;let t=e.inputType;if(!Na.has(t)&&!(!e.cancelable&&this.browserApplies(e))&&(e.preventDefault(),!this.readOnly)){if(this.blockSel){t.startsWith("delete")?this.deleteSelectedBlocks():t==="historyUndo"?this.undo():t==="historyRedo"&&this.redo();return}if(this.refreshSelection(),!((t==="insertText"||t==="insertReplacementText")&&ke(this.state))&&!(this.modeValue==="source"&&this.onSourceInput(t)))switch(t){case"insertText":{let n=e.data??"",i=R(this.state.selection)?this.targetRange(e):null;i&&!R(i)&&(this.current={...this.state,selection:i}),n?this.typeText(n):i&&!R(i)&&this.run(J,"typing");return}case"insertReplacementText":{let n=e.dataTransfer?.getData("text/plain")??e.data??"",i=this.targetRange(e);this.run(r=>ue(i?{...r,selection:i}:r,n));return}case"insertParagraph":{if(this.suggestions.isOpen&&this.suggestions.accept())return;this.run(n=>this.collapsed.has(n.selection.focus.blockId)?ri(n):Kn(n));return}case"insertLineBreak":this.run(ii);return;case"deleteContentBackward":this.undoShortcut()||this.run(nn);return;case"deleteContentForward":this.run(_n);return;case"deleteWordBackward":case"deleteWordForward":case"deleteSoftLineBackward":case"deleteSoftLineForward":case"deleteHardLineBackward":case"deleteHardLineForward":case"deleteEntireSoftLine":{if(!R(this.state.selection)){this.run(J);return}let n=this.targetRange(e);n&&!R(n)&&n.anchor.blockId===n.focus.blockId?this.run(i=>J({...i,selection:n})):this.run(this.modeValue==="source"?t.endsWith("Backward")?i=>ar(i,en):i=>cr(i,tn):t.endsWith("Backward")?nn:_n);return}case"historyUndo":this.undo();return;case"historyRedo":this.redo();return;case"formatBold":this.commands.toggleBold();return;case"formatItalic":this.commands.toggleItalic();return;case"formatStrikeThrough":this.commands.toggleStrike();return;default:return}}}onSourceInput(e){switch(e){case"insertParagraph":return this.run(t=>this.smartLists?Nl(t):Ae(t,`
116
+ `);return{blockId:o.id,offset:n>0?n:t.length}}var Oh=o=>typeof o?.then=="function";function ka(o){return(e,t,n,i)=>{let r=t.ownerDocument.createElement("template");r.innerHTML=e;let s=a=>{if(!a)return!1;t.replaceChildren(a)},l=o(r.content,{editor:i.editor,kind:n});return Oh(l)?l.then(s):s(l)}}function Pr(o,e){let t=o.ownerDocument,n=t.defaultView,i=e.top,r=e.bottom,s=e.left,l=e.right;for(let c=o;c&&c!==t.body&&c!==t.documentElement;c=c.parentElement){let h=n?.getComputedStyle(c),f=c.scrollHeight>c.clientHeight&&/auto|scroll|overlay/.test(h?.overflowY??""),p=c.scrollWidth>c.clientWidth&&/auto|scroll|overlay/.test(h?.overflowX??"");if(!f&&!p)continue;let m=c.getBoundingClientRect(),y=m.top+c.clientTop,g=m.left+c.clientLeft,v=f?Ko(i,r,y,y+c.clientHeight):0,b=p?Ko(s,l,g,g+c.clientWidth):0;if(!v&&!b)continue;let w=c.scrollTop,k=c.scrollLeft;c.scrollTop+=v,c.scrollLeft+=b,i-=c.scrollTop-w,r-=c.scrollTop-w,s-=c.scrollLeft-k,l-=c.scrollLeft-k}if(!n)return;let a=t.documentElement,d=Ko(i,r,0,a.clientHeight),u=Ko(s,l,0,a.clientWidth);(d||u)&&n.scrollBy(u,d)}function Ko(o,e,t,n){return o<t+8?o-t-8:e>n-8?Math.min(e-n+8,o-t-8):0}function va(o){let e={};for(let t of o)for(let[n,i]of Object.entries(t??{}))i!==void 0&&(e[n]=typeof i=="object"?{...e[n],...i}:i);return e}var Hh={text:"--mbe-text",muted:"--mbe-muted",background:"--mbe-bg",accent:"--mbe-accent",link:"--mbe-link",codeBackground:"--mbe-code-bg",border:"--mbe-border",popupBackground:"--mbe-popup-bg",popupBorder:"--mbe-popup-border",hover:"--mbe-hover",danger:"--mbe-danger",highlight:"--mbe-highlight",calloutNote:"--mbe-callout-note",calloutTip:"--mbe-callout-tip",calloutImportant:"--mbe-callout-important",calloutWarning:"--mbe-callout-warning",calloutCaution:"--mbe-callout-caution"},An={font:"--mbe-font",mono:"--mbe-mono",sourceFont:"--mbe-source-font",fontSize:"--mbe-font-size",lineHeight:"--mbe-line-height",radius:"--mbe-radius",blockGap:"--mbe-block-gap"},xa=[An.font,An.mono,An.fontSize,An.lineHeight];function $r(o){let e=new Map;if(!o)return e;for(let t of["light","dark"])for(let[n,i]of Object.entries(Hh)){let r=o[t]?.[n]??o.colors?.[n];r&&e.set(`${i}-${t}`,r)}for(let[t,n]of Object.entries(An)){let i=o[t];i!==void 0&&i!==""&&e.set(n,typeof i=="number"?`${i}px`:i)}return e}var wa=/^(?:[ \t]*>[ \t]?)*/,Ut=/[ \t]*(?:[-*+]|\d{1,9}[.)])(?=[ \t\n\r]|$)/y,Ph=/^(`{3,}|~{3,})/,$h=/^\[[ \t\nxX]\](?=[ \t\n]|$)/;function Sa(o,e){let t=he(o,e),n=pt(o),i=[],r=[],s=(g,v,b)=>{b>v&&i.push({from:v,to:b,kind:g})},l=g=>({from:n.starts[g-1]??o.length,to:n.ends[g-1]??o.length}),a=(g,v,b,w)=>{for(let k of bs(g,n,v,b))s(w,k.from,k.to)},d=(g,v)=>{for(let b=g;b<v;b++){let w=o[b];if(w===">")s("marker",b,b+1);else if(w==="-"||w==="*"||w==="+"||w>="0"&&w<="9"){Ut.lastIndex=b;let k=Ut.exec(o);k&&k.index===b&&(s("marker",b+k[0].length-k[0].trimStart().length,b+k[0].length),b+=k[0].length-1)}}},u=g=>{let v=wa.exec(o.slice(g.from,g.to))[0];d(g.from,g.from+v.length),Ut.lastIndex=g.from+v.length;let b=g.from+v.length;for(let w=Ut.exec(o);w&&w.index===b;w=Ut.exec(o))s("marker",b+w[0].length-w[0].trimStart().length,b+w[0].length),b+=w[0].length,Ut.lastIndex=b;return b},c=g=>{for(let v of g.lines){let b=n.starts[v.line-1]??o.length;d(b,b+v.offset)}},h=(g,v)=>{for(let b=g;b<v;b++)o[b]==="\\"&&b+1<v?(o[b+1]==="|"&&s("escape",b,b+2),b++):o[b]==="|"&&s("marker",b,b+1)},f=(g,v,b)=>{g&&(c(g),b&&v.length>0&&a(g,0,Math.max(...v.map(w=>w.pos?.to??0)),b),p(g,v))},p=(g,v)=>{let b=w=>{for(let k of w){let{pos:S}=k;if(S)switch(k.type){case"text":if(k.pieces){let x=S.from;for(let T of k.pieces)a(g,x,T.from,"escape"),x=T.to;a(g,x,S.to,"escape")}break;case"hardBreak":{let x=new xe(g,n).source(S.from);o[x]==="\\"&&s("marker",x,x+1);break}case"code":{for(let x of k.syntax??[])a(g,x.from,x.to,"marker");k.content&&a(g,k.content.from,k.content.to,"code");break}case"html":a(g,S.from,S.to,"html");break;case"token":a(g,S.from,S.to,"token");break;case"emphasis":case"strong":case"strike":{let x=k.syntax?.find(E=>E.kind==="open"),T=k.syntax?.find(E=>E.kind==="close");for(let E of k.syntax??[])a(g,E.from,E.to,"marker");a(g,x?.to??S.from,T?.from??S.to,k.type==="emphasis"?"em":k.type),b(k.children);break}case"link":case"image":{let x=k.syntax?.find(A=>A.kind==="open"),T=k.syntax?.find(A=>A.kind==="close"),E=k.syntax?.find(A=>A.kind==="dest");for(let A of k.syntax??[])A.kind==="dest"?a(g,A.from,A.to,"url"):A.kind==="tail"&&E&&E.from>=A.from&&E.to<=A.to?(a(g,A.from,E.from,"marker"),a(g,E.to,A.to,"marker")):A.kind!=="title"&&a(g,A.from,A.to,"marker");x&&T&&!(E&&E.from===x.to&&E.to===T.from)&&a(g,x.to,T.from,"link"),b(k.children);break}default:break}}};b(v)},m=g=>{switch(g.type){case"paragraph":case"heading":case"htmlBlock":case"raw":return g.source?.lines[0]?.line??0;case"codeBlock":case"thematicBreak":case"table":return g.lines?.start??0;case"blockQuote":case"listItem":return g.children[0]?m(g.children[0]):0;case"list":return g.items[0]?m(g.items[0]):0}},y=g=>{switch(g.type){case"paragraph":f(g.source,g.children);break;case"heading":{f(g.source,g.children,"heading");let v=g.source?.lines[0];if(!v)break;if(g.setext){let b=l(v.line+(g.source?.lines.length??1)),w=wa.exec(o.slice(b.from,b.to))[0];d(b.from,b.from+w.length),s("marker",b.from+w.length,b.to)}else{let b=l(v.line),w=o.slice(b.from,b.from+v.offset),k=/#{1,6}[ \t]*$/.exec(w);k&&s("marker",b.from+k.index,b.from+k.index+k[0].trimEnd().length);let S=o.slice(b.from+v.offset,b.to),x=/(?:^|[ \t]+)(#+)[ \t]*$/.exec(S);x&&s("marker",b.from+v.offset+x.index+x[0].indexOf("#"),b.from+v.offset+x.index+x[0].trimEnd().length)}break}case"thematicBreak":if(g.lines){let v=l(g.lines.start);s("marker",u(v),v.to)}break;case"blockQuote":g.children.forEach(y);break;case"list":for(let v of g.items){if(v.lines&&m(v)!==v.lines.start&&u(l(v.lines.start)),v.task){let b=v.children[0],k=(b?.type==="paragraph"?b.source:void 0)?.lines[0];if(k){let S=(n.starts[k.line-1]??0)+k.offset;$h.test(o.slice(S,n.ends[k.line-1]))&&s("marker",S,S+3)}}v.children.forEach(y)}break;case"codeBlock":{if(!g.source||!g.lines)break;let v=g.source.lines;if(g.fenced){let b=l(g.lines.start),w=u(b),k=o.slice(w,b.to),S=k.trimStart(),x=w+k.length-S.length,T=Ph.exec(S);T&&(s("marker",x,x+T[1].length),s("lang",x+T[1].length,b.to));let E=v[v.length-1]?.line??g.lines.start;if(g.lines.end>E){let A=l(g.lines.end);s("marker",u(A),A.to)}}if(c(g.source),v.length>0){let b=g.value.replace(/\n$/,"").length;a(g.source,0,b,"code");let w=new xe(g.source,n);r.push({from:w.source(0),to:w.source(b),language:Bi(g.info)})}break}case"htmlBlock":case"raw":g.source&&(c(g.source),a(g.source,0,g.value.length,g.type==="raw"?"token":"html"));break;case"table":if(g.lines){for(let v=g.lines.start;v<=g.lines.end;v++){let b=l(v),w=u(b);v===g.lines.start+1?s("marker",w,b.to):h(w,b.to)}g.sources?.forEach((v,b)=>v.forEach((w,k)=>p(w,g.rows[b]?.[k]??[])))}break}};return t.children.forEach(y),i.sort((g,v)=>g.from-v.from||v.to-g.to),{ranges:i,code:r}}var Ta={marker:"mbe-src-marker",heading:"mbe-src-heading",em:"mbe-src-em",strong:"mbe-src-strong",strike:"mbe-src-strike",code:"mbe-src-code",link:"mbe-src-link",url:"mbe-src-url",html:"mbe-src-html",token:"mbe-src-token",escape:"mbe-src-escape",lang:"mbe-src-lang"},Fh=new Set(["marker","code","url","html","token","escape","lang"]),Ea=2e4,Ma=1e3,qh=80;function _h(o,e,t,n){let i=n.highlight?Kh(t,n.classes):[];if(n.decorators.length>0){let r=Pn(o,Ba(e,t));for(let s of n.decorators)i.push(...s(r))}if(n.codeDecorators.length>0)for(let r of t.code){let s={block:o,text:e.slice(r.from,r.to),language:r.language};for(let l of n.codeDecorators.flatMap(a=>a(s))){let a=r.from+Math.max(0,l.from),d=r.from+Math.min(r.to-r.from,l.to);d>a&&i.push({...l,from:a,to:d})}}return i}var Vo=class{constructor(e,t,n){this.options=e;this.config=t;this.onReady=n}last=null;markupFor=null;spansFor=null;pending=null;markup(e){return this.markupFor?.text!==e&&(this.markupFor={text:e,markup:Sa(e,this.options)}),this.markupFor.markup}spans(e){let t=this.markupFor?.text===e?this.markupFor.markup:null;if(this.spansFor?.text===e&&(!t||this.spansFor.markup===t))return this.spansFor.spans;let n=t;if(!n&&this.markupFor&&e.length>Ea){let r=Ca(this.markupFor.markup.ranges,this.markupFor.text,e);r&&(n={ranges:r,code:this.markupFor.markup.code})}n??=this.markup(e);let i=Ba(e,n);return this.spansFor={text:e,markup:n,spans:i},i}decorations(e){let t=I(e.content),n=this.last;if(n&&n.text===t)return n.decorations;if(n&&t.length>Ea){let i=Ca(n.decorations,n.text,t);if(i)return this.last={text:t,decorations:i},this.schedule(e),i}return this.read(e,t)}reset(){this.last=null}destroy(){this.pending!==null&&clearTimeout(this.pending),this.pending=null}read(e,t){this.destroy();let n=_h(e,t,this.markup(t),this.config());return this.last={text:t,decorations:n},n}schedule(e){this.destroy(),this.pending=setTimeout(()=>{this.pending=null;let t=this.last;if(!t)return;let n=this.read(e,t.text);$n(t.decorations,n)||this.onReady()},qh)}};function Ca(o,e,t){let{from:n,toBefore:i,toAfter:r}=dr(e,t);if(i-n>Ma||r-n>Ma)return null;let s=t.length-e.length,l=[];for(let a of o){let d=a.from<n?a.from:a.from>=i?a.from+s:n,u=a.to<=n?a.to:a.to>=i?a.to+s:n;u>d&&l.push(d===a.from&&u===a.to?a:{...a,from:d,to:u})}return l}function Kh(o,e){return o.ranges.map(t=>{let n=e?.[t.kind];return{from:t.from,to:t.to,class:n?`${Ta[t.kind]} ${n}`:Ta[t.kind]}})}var Ia=["code"],La=[];function Ba(o,e){let t=[],n=(s,l,a)=>{l>s&&t.push({text:o.slice(s,l),marks:a})},i=0,r=0;for(let s of e.ranges)Fh.has(s.kind)&&(s.from>r&&(n(i,r,Ia),n(r,s.from,La),i=s.from),r=Math.max(r,s.to));return n(i,r,Ia),n(r,o.length,La),t}var $a=["text","heading1","heading2","heading3","heading4","bulletList","numberedList","todoList","quote","callout","details","code","table","divider"],Vh=[{id:"text",aliases:["paragraph","plain"],spec:{type:"paragraph"}},{id:"heading1",aliases:["h1","title"],spec:{type:"heading",level:1}},{id:"heading2",aliases:["h2","subtitle"],spec:{type:"heading",level:2}},{id:"heading3",aliases:["h3"],spec:{type:"heading",level:3}},{id:"heading4",aliases:["h4"],spec:{type:"heading",level:4}},{id:"bulletList",aliases:["ul","unordered","bullet"],spec:{type:"listItem",listType:"bullet"}},{id:"numberedList",aliases:["ol","ordered"],spec:{type:"listItem",listType:"ordered"}},{id:"todoList",aliases:["task","checkbox","checklist"],spec:{type:"listItem",listType:"task"}},{id:"quote",aliases:["blockquote","citation"],spec:{type:"quote"}},{id:"callout",aliases:["alert","admonition","note","tip","important","warning","caution"],spec:{type:"quote",callout:"note"}},{id:"details",aliases:["toggle","collapse","collapsible","summary","spoiler","fold"],spec:{type:"details"}},{id:"code",aliases:["pre","snippet","fence"],spec:{type:"code"}},{id:"table",aliases:["grid"],spec:{type:"table"}},{id:"divider",aliases:["hr","separator","line","rule"],spec:{type:"divider"}}],Uh=[{id:"addRowAbove",action:{kind:"addRowAbove"}},{id:"addRowBelow",action:{kind:"addRowBelow"}},{id:"addColumnLeft",action:{kind:"addColumnLeft"}},{id:"addColumnRight",action:{kind:"addColumnRight"}},{id:"deleteRow",action:{kind:"deleteRow"}},{id:"deleteColumn",action:{kind:"deleteColumn"}}],zh=[{id:"alignLeft",align:"left",image:"imageAlignLeft"},{id:"alignCenter",align:"center",image:"imageAlignCenter"},{id:"alignRight",align:"right",image:"imageAlignRight"}],Wh=["/","\uFF0F"],Aa=".mbe-widget, .mbe-block-after",Na=/^(Arrow(Up|Down|Left|Right)|Home|End|PageUp|PageDown)$/,Ra=new Set(["insertCompositionText","deleteCompositionText","insertFromComposition","deleteByComposition"]),Fr=class{root;labels;commands;suggestion;current;source;markdown;history=new oo(()=>this.source);modeValue="rich";pendingMode=null;renderer;composing=!1;composition=null;compositionEndedAt=0;shortcut=null;unsettled=new Set;settleFrame=null;readOnly;wasReadOnly=!1;taskToggle;smartLists;sourceHighlighting;sourceHighlighter;options;extensions;bindings;runtime;classesKey="{}";tokenNames=[];listeners=new Map;cleanup=[];widgets=[];changeFrame=null;plainPasteNext=!1;destroyed=!1;focused=!1;pointerDown=!1;toolbarClosedFor=null;typing=0;caretKey=null;suggestions;blockMenu;toolbar;imageToolbar;inputPopover;blockHandle;collapsed=new Set;linkCard;resizeHandles;selectedImageEl=null;hintEl=null;blockSel=null;selectedEls=[];headingIdsFor=null;redecoratePending=!1;viewFrame=0;constructor(e){let t=e.element;this.root=t,this.options=e,this.runtime={},this.labels={...Mi,...e.labels},this.readOnly=e.editable===!1,this.taskToggle=e.taskToggle===!0,this.smartLists=e.smartLists!==!1,this.sourceHighlighting=e.sourceHighlighting!==!1;let n=e.extensions??[];this.extensions=n.some(c=>c.name==="defaultKeymap")?n:[...n,rr()],this.bindings=this.extensions.flatMap(c=>Object.entries(c.keymap??{}).map(([h,f])=>Wl(h,f,ie)));let i=n.flatMap(c=>c.markdown?[c.markdown]:[]);this.markdown=Ze({...e.markdown,syntax:[...e.markdown?.syntax??[],...i]});let r=Le(e.content??"",this.markdown);this.source=r.source,this.current=Hn(r.doc),this.renderer=new Ho(t,this.labels),this.renderer.collapsed=this.collapsed,this.collapseClosedSections(this.current.doc),this.renderer.widgetsAfter=c=>{if(this.widgets.length===0)return;let h=this.widgets.filter(f=>f.blockId===c).map(f=>f.element);return h.length?h:void 0};let s=[["markdown",Nr]];e.sanitizeHtml&&s.push(["html",ka(e.sanitizeHtml)]),this.renderer.views=new Map([...s,...this.extensions.flatMap(c=>Object.entries(c.views??{}).filter(([h])=>h!=="html"))]),this.renderer.viewContext={editor:this},this.renderer.blockViews=this.extensions.flatMap(c=>c.blockView?[{name:c.name,view:c.blockView}]:[]),this.renderer.markdown=this.markdown,this.renderer.onViewSettled=c=>this.viewsSettled(c);let l=this.extensions.flatMap(c=>c.codeDecorations?[c.codeDecorations]:[]);l.length>0&&(this.renderer.decorateCode=c=>{let h={block:c,text:I(c.content),language:c.language};return l.flatMap(f=>f(h))});let a=this.extensions.flatMap(c=>c.decorations?[c.decorations]:[]);a.length>0&&(this.renderer.decorate=(c,h,f)=>{let p=Pn(c,h,f);return a.flatMap(m=>m(p))}),this.sourceHighlighter=new Vo(this.markdown,()=>({highlight:this.sourceHighlighting,classes:this.renderer.classes.source,decorators:a,codeDecorators:l}),()=>this.refreshSource()),this.renderer.decorateSource=c=>this.sourceHighlighter.decorations(c),this.commands=this.createCommands(),t.classList.add("mbe-root"),t.setAttribute("role","textbox"),t.setAttribute("aria-multiline","true"),t.spellcheck=!0,t.translate=!1,t.style.setProperty("--mbe-slash-hint",JSON.stringify(this.labels.slashHint)),this.applyRuntime({placeholder:e.placeholder,attributes:e.attributes}),this.runtime={...this.runtime,resolveUrl:e.resolveUrl,onLinkClick:e.onLinkClick},this.renderer.resolveUrl=e.resolveUrl??Ln,this.renderer.referrerPolicy=e.referrerPolicy,this.renderer.codeCopy=e.codeCopy!==!1,this.renderer.icon=c=>X(t.ownerDocument,this.icon(c)),this.applyTheme(e.theme),ir(t,e.popupContainer);let d=this.extensions.flatMap(c=>c.suggestion?[c.suggestion]:[]);e.slashMenu!==!1&&d.push(this.slashSuggestion()),this.suggestions=new Co({editor:this,root:t,syncActiveDescendant:()=>this.syncActiveDescendant(),refresh:()=>this.updateUi(),endComposition:()=>this.endComposition(),changed:c=>this.emit("suggestionChange",{editor:this,state:c})},d);let u=this.suggestions;this.suggestion={get state(){return u.state},open:c=>!this.destroyed&&(this.refreshSelection(),u.open(c)),close:()=>u.dismiss(),move:c=>u.move(c),accept:c=>!this.destroyed&&u.accept(c)},this.blockMenu=new Xe(t,"mbe-block-menu","menu"),this.blockMenu.onPicked=()=>this.blockMenu.hide(),this.blockMenu.onHighlight=()=>this.syncActiveDescendant(),this.blockMenu.checkIcon=this.icon("selected"),this.blockMenu.submenuIcon=this.icon("chevronRight"),this.inputPopover=new Lo(this),this.toolbar=e.toolbar===!1?null:new Io(this,typeof e.toolbar=="object"?e.toolbar.items:void 0),this.toolbar&&(this.toolbar.onMenuChange=()=>this.syncActiveDescendant()),this.imageToolbar=e.toolbar===!1?null:new Ao(this,{align:(c,h)=>this.updateImageAt(c.pos,{align:h==="left"?null:h}),altText:c=>this.editAltText(c.pos,c.image.alt),resetSize:c=>this.updateImageAt(c.pos,{width:null}),remove:c=>this.deleteImageAt(c.pos)}),this.blockHandle=new qo(this),this.linkCard=e.linkCard===!1?null:new _o(this,{open:(c,h)=>this.openHref(c.el.getAttribute("href"),h),edit:c=>this.editLink(c),remove:c=>this.removeLink(c),targetOf:c=>this.linkTargetOf(c)}),this.resizeHandles=new Bo(this),this.renderer.onImageError=()=>{this.destroyed||(this.composing||this.syncDomSelection(),this.updateUi())},this.listen(t,"beforeinput",this.typed(c=>this.onBeforeInput(c))),this.listen(t,"input",this.typed(c=>this.onInput(c))),this.listen(t,"compositionstart",c=>this.onCompositionStart(c)),this.listen(t,"compositionend",this.typed(c=>this.onCompositionEnd(c))),this.listen(t,"keydown",this.typed(c=>this.onKeyDown(c))),this.listen(t,"copy",c=>this.onCopy(c,!1)),this.listen(t,"cut",this.typed(c=>this.onCopy(c,!0))),this.listen(t,"paste",this.typed(c=>this.onPaste(c))),this.listen(t,"dragstart",c=>c.preventDefault()),this.listen(t,"dragover",c=>{this.readOnly||c.preventDefault()}),this.listen(t,"drop",this.typed(c=>this.onDrop(c))),this.listen(t,"mousedown",c=>this.onMouseDown(c)),this.listen(t,"click",c=>this.onClick(c)),this.listen(t,"change",c=>this.onControlChange(c)),this.listen(t,"focusin",c=>this.onFocusIn(c)),this.listen(t,"focusout",c=>this.onFocusOut(c)),this.listen(t.ownerDocument,"selectionchange",()=>this.onSelectionChange()),this.listen(t.ownerDocument,"mouseup",()=>this.onMouseUp()),this.listen(t.ownerDocument,"scroll",()=>this.onScroll(),!0),this.listen(t.ownerDocument,"pointerdown",c=>this.onDocumentPointerDown(c),!0),e.mode==="source"&&this.enterSource(),this.paint(!0,!0),this.afterRender();for(let c of this.extensions){let h=c.onCreate?.({editor:this});typeof h=="function"&&this.cleanup.push(h)}e.autofocus&&this.commands.focus(e.autofocus==="end"?"end":"start")}getMarkdown(){return this.modeValue==="source"?K(this.current.doc):Pt(this.current.doc,{...this.markdown,source:this.source})}setMarkdown(e,t={}){if(this.destroyed)return;if(t.history==="keep"?this.history.record(this.current,"other"):this.history.clear(),this.modeValue==="source"){this.suggestions.reset(),this.current=Fe(e,0);for(let r of this.widgets)r.offset=Math.min(r.offset,e.length);this.paint(!0,!0),this.afterRender(),this.emit("selectionChange",{editor:this});return}let n=Le(e,this.markdown);this.source=n.source,this.blockSel=null,this.suggestions.reset();let i=Hn(n.doc);this.collapsed.clear(),this.collapseClosedSections(i.doc),this.relocateWidgets(this.current.doc,i.doc,!0),this.current=i,this.paint(!0,!0),this.afterRender(),this.emit("selectionChange",{editor:this})}get isEmpty(){return this.modeValue==="source"?K(this.current.doc)==="":this.current.doc.blocks.every(e=>e.type==="paragraph"&&B(e.content)===0)}get state(){return this.current}get isComposing(){return this.composing}get mode(){return this.pendingMode??this.modeValue}get isEditable(){return!this.readOnly&&!this.destroyed}get isDestroyed(){return this.destroyed}isActive(e,t){if(this.modeValue==="source")return!1;let n=this.current;switch(e){case"bold":case"italic":case"strike":case"code":return Vn(n,e);case"link":return Qe(n)!==null;case"image":{let s=De(n);if(!s||!t)return s!==null;let l={...s.image,block:ke(n)!==null};return Object.entries(t).every(([a,d])=>l[a]===d)}}let i=N(n.doc,n.selection.focus.blockId);if(Oa(i)!==e&&!(e==="blockquote"&&M(i)))return!1;if(!t)return!0;let r=this.getAttributes(e);return Object.entries(t).every(([s,l])=>r[s]===l)}getAttributes(e){if(this.modeValue==="source")return{};let t=this.current;if(e==="link"){let r=Qe(t);return r?{href:r.href}:{}}if(e==="image"){let r=De(t);return r?{...r.image,block:ke(t)!==null}:{}}let n=N(t.doc,t.selection.focus.blockId),i=M(n);if(e==="blockquote"&&i)return i==="quote"?{}:{callout:i};if(Oa(n)!==e)return{};switch(n.type){case"heading":return{level:n.level};case"code":return{language:n.language};case"listItem":return n.listType==="task"?{checked:n.checked,indent:n.indent}:{indent:n.indent};case"raw":return{syntax:n.syntax};case"quote":return n.callout?{callout:n.callout}:{};case"details":return{open:n.open,collapsed:this.collapsed.has(n.id)};default:return{}}}getSelection(){return this.current.selection}setSelection(e){if(this.destroyed)return!1;let t=Gh(e)?te(this.current.doc,e):Zh(this.current.doc,e);return t?(this.dropBlockSelection(),this.current={...this.current,selection:t,storedMarks:null},this.history.breakGroup(),this.refreshRevealed(),this.syncDomSelection(),this.updateUi(),this.emit("selectionChange",{editor:this}),!0):!1}selectionToJSON(){let e=this.current.doc,t=n=>{let i=L(e,n.blockId);return n.cell?{block:i,offset:n.offset,cell:{row:n.cell.row,col:n.cell.col}}:{block:i,offset:n.offset}};return{anchor:t(this.current.selection.anchor),focus:t(this.current.selection.focus)}}hasFocus(){let e=this.root.ownerDocument.activeElement;return!!e&&this.root.contains(e)&&!(e instanceof HTMLInputElement)&&!e.closest(Aa)}addWidget(e){if(this.destroyed){let l=new kt(this.root.ownerDocument.createElement("div"),"",()=>{},()=>{});return l.remove(),l}let t=this.current.doc.blocks,n=e.at==="end"?P(t[t.length-1]):e.at,i=te(this.current.doc,{anchor:n,focus:n}).focus.blockId,r=this.root.ownerDocument.createElement("div");r.className="mbe-widget",r.contentEditable="false";let s=new kt(r,i,e.render,l=>{this.widgets=this.widgets.filter(a=>a!==l)});return this.modeValue==="source"&&(s.offset=e.at==="end"?K(this.current.doc).length:n.offset),this.widgets.push(s),this.paint(),s}relocateWidgets(e,t,n){if(this.widgets.length===0)return;let i=new Set(t.blocks.map(r=>r.id));for(let r of this.widgets){if(i.has(r.blockId))continue;let s=e.blocks.findIndex(a=>a.id===r.blockId),l;if(n)l=t.blocks[Math.max(0,Math.min(s,t.blocks.length-1))].id;else{for(let a=s-1;a>=0&&!l;a--)i.has(e.blocks[a].id)&&(l=e.blocks[a].id);for(let a=s+1;a<e.blocks.length&&!l&&s>=0;a++)i.has(e.blocks[a].id)&&(l=e.blocks[a].id)}r.blockId=l??t.blocks[0].id}}focus(){if(this.destroyed)return;let e=this.current.selection.focus,t=this.renderer.elementFor(e.blockId);((e.cell&&t?se(t,e.cell):this.root)??this.root).focus({preventScroll:!0}),this.syncDomSelection(!0)}blur(){this.hasFocus()&&this.root.ownerDocument.activeElement?.blur()}setOptions(e){if(this.destroyed)return;e.extensions&&this.suggestions.setConfigs(e.extensions.flatMap(n=>n.suggestion?[n.suggestion]:[]));let t=e.taskToggle!==void 0&&e.taskToggle!==this.taskToggle;t&&(this.taskToggle=e.taskToggle===!0),e.editable!==void 0&&e.editable===this.readOnly?(this.readOnly=!e.editable,this.renderer.views?.has("footnote")?this.paint():this.refreshRevealed(),this.applyReadOnly(),this.hideUi()):t&&this.applyReadOnly(),this.applyRuntime(e),e.mode!==void 0&&this.setMode(e.mode)}setMode(e){if(e!=="rich"&&e!=="source")return;if(this.composing||this.composition){this.pendingMode=e===this.modeValue?null:e;return}if(this.pendingMode=null,e===this.modeValue)return;let t=this.hasFocus(),n=this.caretRect()?.top;this.blockSel=null,this.shortcut=null,this.suggestions.reset(),this.hideUi(),this.closeBlockMenu(),this.history.breakGroup(),e==="source"?this.enterSource():this.leaveSource(),this.paint(!0,!1,t),this.afterRender();let i=this.caretRect()?.top;n!==void 0&&i!==void 0&&Math.abs(i-n)>1&&Yh(this.root,i-n),this.emit("selectionChange",{editor:this})}enterSource(){let{doc:e,selection:t}=this.current,n=this.getMarkdown(),i=Le(n,this.markdown),r=hr(e,t,i);for(let s of this.widgets)s.offset=Ol(e,s.blockId,i),s.blockId=xn;this.collapsed.clear(),this.current=Fe(n,r.anchor,r.focus),this.modeValue="source",this.renderer.source=!0,this.root.classList.add("mbe-source-mode")}leaveSource(){let{anchor:e,focus:t}=this.current.selection,n=this.loadSource(K(this.current.doc));for(let r of this.widgets)r.blockId=wo(r.offset,n).blockId;let i=fr(e.offset,t.offset,n);this.current={doc:n.doc,selection:te(n.doc,i),storedMarks:null},this.modeValue="rich",this.renderer.source=!1,this.root.classList.remove("mbe-source-mode")}loadSource(e){let t=Le(e,this.markdown),n=Hn(t.doc).doc;return this.source=t.source,this.collapsed.clear(),this.collapseClosedSections(n),{doc:n,source:t.source}}restore(e){let{state:t}=e,n=So(t.doc);if(this.modeValue==="source"){if(n)return t;let s=Pt(t.doc,{...this.markdown,source:e.source}),l=hr(t.doc,t.selection,Le(s,this.markdown));return Fe(s,l.anchor,l.focus)}if(!n)return this.source=e.source,t;let i=this.loadSource(K(t.doc)),r=fr(t.selection.anchor.offset,t.selection.focus.offset,i);return{doc:i.doc,selection:te(i.doc,r),storedMarks:null}}on(e,t){let n=this.listeners.get(e);return n||this.listeners.set(e,n=new Set),n.add(t),()=>void n.delete(t)}emit(e,t){let n=this.listeners.get(e);if(n)for(let i of[...n])i(t)}applyRuntime(e){let t=this.root;if("placeholder"in e&&(e.placeholder?(t.style.setProperty("--mbe-placeholder",JSON.stringify(e.placeholder)),t.setAttribute("aria-placeholder",e.placeholder)):(t.style.removeProperty("--mbe-placeholder"),t.removeAttribute("aria-placeholder")),this.runtime={...this.runtime,placeholder:e.placeholder}),"attributes"in e){for(let n of Object.keys(this.runtime.attributes??{}))t.removeAttribute(n);for(let[n,i]of Object.entries(e.attributes??{}))t.setAttribute(n,i);this.runtime={...this.runtime,attributes:e.attributes}}"resolveUrl"in e&&e.resolveUrl!==this.runtime.resolveUrl&&(this.runtime={...this.runtime,resolveUrl:e.resolveUrl},this.renderer.resolveUrl=e.resolveUrl??Ln,this.paint(!0)),"onLinkClick"in e&&(this.runtime={...this.runtime,onLinkClick:e.onLinkClick}),"theme"in e&&this.applyTheme(e.theme)&&this.paint(!0)}applyTheme(e){let t=$r(this.runtime.theme?.tokens);this.runtime={...this.runtime,theme:e};let n=this.root.style,i=$r(e?.tokens);for(let a of this.tokenNames)i.has(a)||n.removeProperty(a);for(let[a,d]of i)n.setProperty(a,d);this.tokenNames=[...i.keys()];let r=e?.colorScheme??"auto";n.colorScheme=r==="auto"?"":r,xa.some(a=>t.get(a)!==i.get(a))&&this.renderBlocksAgain(this.renderer.dropViews());let s=va([...this.extensions.map(a=>a.theme?.classes).reverse(),e?.classes]),l=JSON.stringify(s);return l===this.classesKey?!1:(this.classesKey=l,this.renderer.classes=s,!0)}run(e,t="other"){if(this.readOnly||this.destroyed)return!1;let n=e(this.current);return!n||n===this.current||(n=bi(n,this.current,this.markdown.inline),n=yi(n,this.current),n=li(n),n.doc!==this.current.doc&&jh(n.doc,this.current.doc)&&(n={...n,doc:this.current.doc}),n.doc===this.current.doc&&n.selection===this.current.selection&&n.storedMarks===this.current.storedMarks)?!1:(this.apply(n,t),!0)}createCommands(){let e=l=>this.run(l),t=l=>e(a=>ht(a,l)),n={toggleBold:()=>e(l=>We(l,"bold")),toggleItalic:()=>e(l=>We(l,"italic")),toggleStrike:()=>e(l=>We(l,"strike")),toggleCode:()=>e(l=>We(l,"code")),setParagraph:()=>e(l=>Ge(l,{type:"paragraph"})),toggleHeading:({level:l})=>t({type:"heading",level:l}),toggleBulletList:()=>t({type:"listItem",listType:"bullet"}),toggleOrderedList:()=>t({type:"listItem",listType:"ordered"}),toggleTaskList:()=>t({type:"listItem",listType:"task"}),toggleBlockquote:()=>t({type:"quote"}),toggleCallout:(l={})=>this.markdown.callouts&&t({type:"quote",callout:l.type??"note"}),toggleDetails:()=>this.markdown.details&&t({type:"details"}),setCallout:({type:l})=>(this.markdown.callouts||l===null)&&e(a=>sn(a,a.selection.focus.blockId,l)),toggleCodeBlock:(l={})=>t({type:"code",language:l.language}),setLink:({href:l})=>e(a=>ut(a,l)),unsetLink:()=>e(l=>ut(l,null)),updateImage:l=>e(a=>{let d=De(a);return d?Un(a,d.pos,l):null}),insertText:(l,a={})=>e(d=>{let u=a.range;if(!u)return ue(d,l);let c=te(d.doc,{anchor:u.from,focus:u.to});return ue({...d,selection:c,storedMarks:null},l)}),insertToken:l=>!this.composing&&e(a=>ni(a,l)),insertMarkdown:(l,a={})=>{let d=bt(l,this.markdown).blocks,u=a.at;if(u instanceof kt){if(u.isRemoved)return!1;let c=N(this.current.doc,u.blockId);return e(h=>cn(h,d,{...a,at:P(c),block:!0}))}return e(c=>cn(c,d,a))},insertTable:(l={})=>e(a=>Rt(a,{type:"table",rows:l.rows,cols:l.cols})),insertDivider:()=>e(l=>Rt(l,{type:"divider"})),indent:()=>e(l=>Wn(l,1)),outdent:()=>e(l=>Wn(l,-1)),undo:()=>this.undo(),redo:()=>this.redo(),selectAll:()=>(this.setSelection(xi(this.current).selection),!0),selectBlocks:()=>{if(this.readOnly)return!1;this.hasFocus()||this.root.focus({preventScroll:!0});let{anchor:l,focus:a}=this.current.selection;return this.selectBlockRange(l.blockId,a.blockId),!0},focus:l=>{if(l!==void 0){let a=this.current.doc.blocks,d=l==="start"?V(a[0]):l==="end"?P(a[a.length-1]):l;this.current={...this.current,selection:te(this.current.doc,{anchor:d,focus:d})}}return this.focus(),this.emit("selectionChange",{editor:this}),!0},blur:()=>{let l=this.hasFocus();return this.blur(),l},scrollIntoView:()=>{let l=this.caretRect();return l?(Pr(this.root,l),!0):!1}},i={...n},r=(l,a)=>{let d=i[l];n[l]=(...u)=>this.modeValue==="source"?a?a(...u):!1:d(...u)},s=l=>e(a=>(this.smartLists?Rl(a,l):null)??ln(a,l));r("indent",()=>s(1)),r("outdent",()=>s(-1)),r("insertMarkdown",(l,a={})=>this.insertSourceMarkdown(l,a)),r("toggleBold",()=>e(l=>Tn(l,"**"))),r("toggleItalic",()=>e(l=>Tn(l,"*"))),r("toggleStrike",()=>e(l=>Tn(l,"~~"))),r("toggleCode",()=>e(l=>Tn(l,"`"))),r("setParagraph",()=>e(l=>pr(l,0))),r("toggleHeading",({level:l})=>e(a=>pr(a,l))),r("toggleBulletList",()=>e(l=>Eo(l,"bullet"))),r("toggleOrderedList",()=>e(l=>Eo(l,"ordered"))),r("toggleTaskList",()=>e(l=>Eo(l,"task"))),r("toggleBlockquote",()=>e(l=>Fl(l))),r("toggleCodeBlock",()=>e(l=>ql(l)));for(let l of["toggleCallout","setCallout","toggleDetails","setLink","unsetLink","updateImage","insertTable","insertDivider","selectBlocks"])r(l,null);for(let l of Object.keys(n)){let a=n[l];n[l]=(...d)=>!this.destroyed&&a(...d)}return n}insertSourceMarkdown(e,t){let n=t.at??"selection",i=t.select==="keep",r=t.block===!0;return n instanceof kt?n.isRemoved?!1:this.run(s=>To(s,n.offset,e,!0,i)):n==="selection"&&!r&&!i?this.run(s=>Ae(s,e)):this.run(s=>{let l=s,a;if(n==="selection"){let{from:d,to:u}=ne(s);d!==u&&(l=Ae(s,"")),a=d}else a=n==="end"?K(s.doc).length:n.offset;return To(l,a,e,r,i)})}undo(){if(this.readOnly)return!1;let e=this.history.undo(this.current);return e?(this.commit(this.restore(e)),!0):!1}redo(){if(this.readOnly)return!1;let e=this.history.redo(this.current);return e?(this.commit(this.restore(e)),!0):!1}selectionRect(){let e=this.root.ownerDocument.getSelection();if(!e||e.rangeCount===0)return null;let t=e.getRangeAt(0),n=t.getClientRects(),i=n.length?R(this.current.selection)?n[n.length-1]:t.getBoundingClientRect():null;return i&&(i.width>0||i.height>0)?i:this.emptyRect(this.current.selection.focus,e.focusNode)}caretRect(){let e=this.current.selection.focus,t=this.toDom(e);if(t){let n=this.root.ownerDocument.createRange();n.setStart(t.node,t.offset);let i=n.getClientRects(),r=i[i.length-1];if(r&&r.height>0)return r}return this.emptyRect(e,t?.node??null)}emptyRect(e,t){let n=this.renderer.elementFor(e.blockId),i=(n&&se(n,e.cell))??n,r=t?.nodeType===1?t:t?.parentElement??null;if(i&&r&&r!==i&&i.contains(r)){let s=r.getBoundingClientRect();if(s.height>0)return s}return i?.getBoundingClientRect()??null}textRect(e,t){let n=this.toDom(e),i=this.toDom(t);if(!n||!i)return null;let r=this.root.ownerDocument.createRange();r.setStart(n.node,n.offset),r.setEnd(i.node,i.offset);let s=r.getClientRects()[0];if(!s)return null;let l=n.node.nodeType===1?n.node:n.node.parentElement,a=!!l&&this.root.ownerDocument.defaultView.getComputedStyle(l).direction==="rtl";return{rect:s,rtl:a}}scrollCaretIntoView(){let e=this.caretRect();e&&Pr(this.root,e)}blockElement(e){return this.renderer.elementFor(e)}destroy(){if(!this.destroyed){this.destroyed=!0,this.changeFrame!==null&&cancelAnimationFrame(this.changeFrame),this.settleFrame!==null&&cancelAnimationFrame(this.settleFrame),this.sourceHighlighter.destroy();for(let e of this.cleanup)e();this.suggestions.destroy();for(let e of[...this.widgets])e.remove();this.blockMenu.destroy(),this.toolbar?.destroy(),this.imageToolbar?.destroy(),this.inputPopover.destroy(),this.blockHandle.destroy(),this.linkCard?.destroy(),this.resizeHandles.destroy(),this.renderer.destroy(),ir(this.root,void 0);for(let e of Object.keys(this.runtime.attributes??{}))this.root.removeAttribute(e);for(let e of this.tokenNames)this.root.style.removeProperty(e);this.root.style.colorScheme="",this.root.contentEditable="false",this.root.classList.remove("mbe-root"),this.root.replaceChildren(),this.listeners.clear()}}apply(e,t){e.doc!==this.state.doc&&this.history.record(this.state,t),this.commit(e)}commit(e){let t=e.doc!==this.state.doc,n=e.selection!==this.state.selection,i=this.hasFocus();if(t&&this.modeValue==="source"){let r=K(this.current.doc),s=K(e.doc);for(let l of this.widgets)l.offset=Dl(l.offset,r,s)}else t&&this.relocateWidgets(this.current.doc,e.doc,!1);if(this.current=e,this.blockSel){let r=this.blockRange();r?this.current={...e,selection:an(e.doc.blocks,r)}:this.blockSel=null}this.paint(!1,!1,i),this.afterRender(),n&&i&&this.typing>0&&this.scrollCaretIntoView(),t&&this.scheduleChange(),this.emit("selectionChange",{editor:this})}flushChange(){this.changeFrame!==null&&(cancelAnimationFrame(this.changeFrame),this.changeFrame=null,this.emitChange())}scheduleChange(){if(this.changeFrame!==null||!this.options.onChange&&!this.listeners.get("change")?.size)return;let e=()=>{this.changeFrame=null,this.destroyed||this.emitChange()};typeof requestAnimationFrame=="function"?this.changeFrame=requestAnimationFrame(e):e()}emitChange(){this.options.onChange&&this.options.onChange(this.getMarkdown(),this),this.emit("change",{editor:this})}submit(){return this.destroyed||!this.options.onSubmit&&!this.listeners.get("submit")?.size?!1:(this.flushChange(),this.options.onSubmit?.(this.getMarkdown(),this),this.emit("submit",{editor:this}),!0)}applyReadOnly(){let e=this.readOnly?"false":"true";if(this.root.contentEditable!==e&&(this.root.contentEditable=e),!this.readOnly&&!this.wasReadOnly)return;this.wasReadOnly=this.readOnly;let t=this.ticking;this.root.classList.toggle("mbe-readonly",this.readOnly),this.root.classList.toggle("mbe-tasks",t),this.root.setAttribute("aria-readonly",String(this.readOnly)),this.root.querySelectorAll("[data-row]").forEach(n=>{n.contentEditable=this.readOnly?"false":"true"}),this.root.querySelectorAll("input").forEach(n=>{let i=n.classList.contains("mbe-checkbox");n.disabled=this.readOnly&&!(i&&t),i&&(n.tabIndex=t?0:-1,t?n.setAttribute("aria-label",Xh(n,this.labels.task)):n.removeAttribute("aria-label"))})}get ticking(){return this.readOnly&&this.taskToggle}toggleTaskAt(e){let t=e.closest("[data-block-id]");if(!t)return;let n=t.dataset.blockId,i=e===this.root.ownerDocument.activeElement;if(!this.readOnly)this.run(r=>Qn(r,n));else if(this.ticking&&this.current.doc.blocks.some(r=>r.id===n))this.apply(Qn(this.current,n),"other");else return;i&&this.root.querySelector(`[data-block-id="${n}"] .mbe-checkbox`)?.focus({preventScroll:!0})}afterRender(){for(let e of this.state.doc.blocks){let t=this.renderer.elementFor(e.id);if(!t||!t.classList.contains("mbe-empty"))continue;let n="";e.type==="heading"?n=this.labels[`heading${Math.min(e.level,4)}`]:e.type==="listItem"?n=this.labels.listHint:e.type==="quote"&&!e.callout?n=this.labels.quoteHint:e.type==="details"&&(n=this.labels.detailsHint),n&&t.dataset.hint!==n&&(t.dataset.hint=n)}this.updateUi()}syncDomSelection(e=!1){let t=this.root.ownerDocument.getSelection();if(!t||!e&&!this.hasFocus())return;let n=this.parkedCaret(),i=n?{anchor:n,focus:n}:this.state.selection,r=this.toDom(i.anchor),s=R(i)?r:this.toDom(i.focus);if(!(!r||!s)&&!(t.anchorNode===r.node&&t.anchorOffset===r.offset&&t.focusNode===s.node&&t.focusOffset===s.offset)){if(i.focus.cell){let l=(s.node instanceof Element?s.node:s.node.parentElement)?.closest("[data-row]");l&&this.root.ownerDocument.activeElement!==l&&l.focus({preventScroll:!0})}else this.root.ownerDocument.activeElement!==this.root&&this.hasFocus()&&this.root.focus({preventScroll:!0});t.setBaseAndExtent(r.node,r.offset,s.node,s.offset)}}toDom(e){let t=this.renderer.elementFor(e.blockId);return t?ga(t,e):null}readDomSelection(){let e=this.root.ownerDocument.getSelection();if(!e||!e.anchorNode||!e.focusNode||!this.root.contains(e.anchorNode)||!this.root.contains(e.focusNode))return null;let t=_e(this.root,e.anchorNode,e.anchorOffset),i=e.anchorNode===e.focusNode&&e.anchorOffset===e.focusOffset?t:_e(this.root,e.focusNode,e.focusOffset);return!t||!i?null:{anchor:t,focus:i}}onSelectionChange(){if(this.composing||this.destroyed)return;let e=this.readDomSelection();if(!e){this.hasFocus()||this.updateUi();return}let t=this.caretKey;if(this.caretKey=null,this.blockSel){this.updateUi();return}let n=this.state.selection;if(be(e.anchor,n.anchor)&&be(e.focus,n.focus)){this.updateUi();return}this.shortcut=null;let i=t?.vertical?this.skippedBlock(t.from,t.vertical,t.x,e.focus):null,r=this.imageBlockAt(i?{anchor:i,focus:i}:e);r?!be(r.anchor,n.anchor)||!be(r.focus,n.focus)?this.setSelection(r):this.updateUi():i?this.setSelection({anchor:i,focus:i}):(this.current={...this.state,selection:e,storedMarks:null},this.history.breakGroup(),this.pointerDown||this.refreshRevealed(),this.updateUi(),this.emit("selectionChange",{editor:this})),t&&this.scrollCaretIntoView()}imageBlockAt(e){if(!R(e)||e.focus.cell)return null;let t=this.state.doc.blocks.find(i=>i.id===e.focus.blockId),n=t?Y(t):null;return n===null?null:{anchor:{blockId:t.id,offset:n},focus:{blockId:t.id,offset:n+1}}}skippedBlock(e,t,n,i){let r=this.state.doc.blocks,s=L(this.state.doc,i.blockId);for(let l=e+t;(s-l)*t>0;l+=t){let a=r[l];if(!this.skipsCaret(a))return this.blockEntry(a,t===1,n)}return null}blockEntry(e,t,n){let i=this.renderer.elementFor(e.id),r=this.viewBlock(e);if(r)return Bn(r,t);if(i){let s=i.ownerDocument.createRange();s.selectNodeContents(se(i)??i);let l=Array.from(s.getClientRects()).filter(u=>u.height>0),a=t?l[0]:l[l.length-1],d=a?this.positionAtPoint(n,a.top+a.height/2):null;if(d?.blockId===e.id)return d}if(e.type==="table"){let s=t?0:e.rows.length-1;return{blockId:e.id,offset:t?0:B(e.rows[s][0]),cell:{row:s,col:0}}}return t?V(e):P(e)}paint(e=!1,t=!1,n=this.hasFocus()){let i=this.renderer.views;i&&!this.pointerDown&&!this.composing&&(this.renderer.revealed=Hr(this.state,i,!this.readOnly&&n,this.hosted)),this.renderer.collectFootnotes=this.readOnly,this.renderer.render(this.state.doc,e,t),this.applyHeadingIds(),this.applyReadOnly(),this.paintBlockSelection(),this.composing||this.syncDomSelection(n)}sourceSpans(e){return this.sourceHighlighter.spans(I(e.content))}refreshSource(){if(this.destroyed||this.modeValue!=="source"||this.composing||this.composition)return;let e=this.current.doc.blocks[0];if(e?.type!=="code")return;let t=this.hasFocus();this.renderer.refreshSource(e),this.pointerDown||this.syncDomSelection(t)}applyHeadingIds(){let e=this.options.headingIds;if(!e)return;let t=this.state.doc;if(this.headingIdsFor?.doc!==t){let n=t.blocks.filter(r=>r.type==="heading"),i=e(n.map(r=>({text:I(r.content),level:r.level})));this.headingIdsFor={doc:t,ids:new Map(n.map((r,s)=>[r.id,i[s]]))}}for(let[n,i]of this.headingIdsFor.ids){let r=this.renderer.elementFor(n);r&&(i?r.id!==i&&(r.id=i):r.id&&r.removeAttribute("id"))}}redecorate(){if(!this.destroyed){if(this.composing||this.composition){this.redecoratePending=!0;return}this.redecoratePending=!1,this.sourceHighlighter.reset(),this.paint(!0),this.afterRender()}}refreshViews(e){this.destroyed||this.renderBlocksAgain(this.renderer.dropViews(e))}renderBlocksAgain(e){if(e.length!==0){if(this.composing||this.composition){for(let t of e)this.unsettled.add(t);return}for(let t of e)this.renderer.invalidate(t);this.paint(),this.afterRender()}}viewsSettled(e){if(!this.destroyed){if(this.composing||this.composition){for(let t of e)this.unsettled.add(t);return}for(let t of e)this.renderer.invalidate(t);this.viewFrame||=requestAnimationFrame(()=>{this.viewFrame=0,!(this.destroyed||this.composing||this.composition)&&(this.paint(),this.afterRender())})}}viewBlock(e){return e&&this.renderer.elementFor(e.id)?.classList.contains("mbe-view-block")?e:null}refreshRevealed(){let e=this.renderer.views;if(!e||this.pointerDown)return;let t=Hr(this.state,e,!this.readOnly&&this.hasFocus(),this.hosted);ya(t,this.renderer.revealed)||this.paint()}hosted=e=>this.renderer.isHosted(e);onMouseUp(){this.pointerDown&&(this.pointerDown=!1,!this.destroyed&&!this.composing&&this.refreshRevealed())}blockPast(e){let t=this.state.selection;if(!R(t)||t.focus.cell)return null;let n=t.focus,i=this.state.doc.blocks,r=L(this.state.doc,n.blockId),s=e==="ArrowDown"||e==="ArrowRight",l=i[r+(s?1:-1)],a=this.viewBlock(l);if(!l||!a&&l.type!=="table")return null;let d=i[r];if(!q(d)||e==="ArrowRight"&&n.offset!==P(d).offset||e==="ArrowLeft"&&n.offset!==0)return null;if(e==="ArrowDown"||e==="ArrowUp"){let u=se(this.renderer.elementFor(d.id));if(u&&!this.onEdgeLine(u,s))return null}return Bn(l,s)}imageBlockStep(e){let t=this.state.selection,n=this.state.doc.blocks,i=e==="ArrowDown"||e==="ArrowRight",r=ke(this.state);if(r){let u=L(this.state.doc,r.pos.blockId);for(let c=u+(i?1:-1);c>=0&&c<n.length;c+=i?1:-1){let h=n[c];if(this.skipsCaret(h))continue;let f=Y(h);if(f!==null)return{anchor:{blockId:h.id,offset:f},focus:{blockId:h.id,offset:f+1}};let m=e==="ArrowDown"||e==="ArrowUp"?this.blockEntry(h,i,this.selectionRect()?.left??0):i?V(h):P(h);return{anchor:m,focus:m}}return t}if(!R(t)||t.focus.cell)return null;let s=L(this.state.doc,t.focus.blockId),l=n[s],a=n[s+(i?1:-1)],d=a?Y(a):null;if(!a||d===null||!q(l)||e==="ArrowRight"&&t.focus.offset!==P(l).offset||e==="ArrowLeft"&&t.focus.offset!==0)return null;if(e==="ArrowDown"||e==="ArrowUp"){let u=se(this.renderer.elementFor(l.id));if(u&&!this.onEdgeLine(u,i))return null}return{anchor:{blockId:a.id,offset:d},focus:{blockId:a.id,offset:d+1}}}tableCellPast(e){let t=this.state.selection,n=t.focus;if(!R(t)||!n.cell)return null;let i=this.state.doc.blocks,r=L(this.state.doc,n.blockId),s=i[r];if(s?.type!=="table")return null;let l=se(this.renderer.elementFor(s.id),n.cell);if(l&&!this.onEdgeLine(l,e===1))return null;let{row:a,col:d}=n.cell,u=s.rows[a+e];if(u){let c=Math.min(n.offset,B(u[d]));return{blockId:s.id,offset:c,cell:{row:a+e,col:d}}}for(let c=r+e;c>=0&&c<i.length;c+=e){let h=i[c];if(this.skipsCaret(h))continue;if(h.type==="table"){let p=e===1?0:h.rows.length-1,m=Math.min(d,h.align.length-1);return{blockId:h.id,offset:e===1?0:B(h.rows[p][m]),cell:{row:p,col:m}}}let f=this.viewBlock(h);return f?Bn(f,e===1):e===1?V(h):P(h)}return null}onEdgeLine(e,t){let n=this.selectionRect();if(!n||n.height===0)return!0;let i=e.ownerDocument.createRange();i.selectNodeContents(e);let r=Array.from(i.getClientRects()).filter(l=>l.height>0);if(r.length===0)return!0;let s=n.height/2;return t?Math.max(...r.map(l=>l.bottom))-n.bottom<=s:n.top-Math.min(...r.map(l=>l.top))<=s}revealView(e){let t=e.hasAttribute(W)?N(this.state.doc,e.getAttribute(W)):null,n=t?Bn(t,!1):_e(this.root,e.parentNode,xt(e)+1);n&&(this.root.focus({preventScroll:!0}),this.setSelection({anchor:n,focus:n}))}refreshSelection(){if(this.blockSel)return;let e=this.readDomSelection();e&&(this.current={...this.state,selection:e})}targetRange(e){let t=e.getTargetRanges?.()[0];if(!t)return null;let n=_e(this.root,t.startContainer,t.startOffset),i=_e(this.root,t.endContainer,t.endOffset);return n&&i?{anchor:n,focus:i}:null}fromControl(e){return e.target instanceof HTMLInputElement||!!e.target?.closest?.(Aa)}onBeforeInput(e){if(this.fromControl(e)||this.composing||e.isComposing)return;let t=e.inputType;if(!Ra.has(t)&&!(!e.cancelable&&this.browserApplies(e))&&(e.preventDefault(),!this.readOnly)){if(this.blockSel){t.startsWith("delete")?this.deleteSelectedBlocks():t==="historyUndo"?this.undo():t==="historyRedo"&&this.redo();return}if(this.refreshSelection(),!((t==="insertText"||t==="insertReplacementText")&&ke(this.state))&&!(this.modeValue==="source"&&this.onSourceInput(t)))switch(t){case"insertText":{let n=e.data??"",i=R(this.state.selection)?this.targetRange(e):null;i&&!R(i)&&(this.current={...this.state,selection:i}),n?this.typeText(n):i&&!R(i)&&this.run(J,"typing");return}case"insertReplacementText":{let n=e.dataTransfer?.getData("text/plain")??e.data??"",i=this.targetRange(e);this.run(r=>ue(i?{...r,selection:i}:r,n));return}case"insertParagraph":{if(this.suggestions.isOpen&&this.suggestions.accept())return;this.run(n=>this.collapsed.has(n.selection.focus.blockId)?ri(n):Kn(n));return}case"insertLineBreak":this.run(ii);return;case"deleteContentBackward":this.undoShortcut()||this.run(nn);return;case"deleteContentForward":this.run(_n);return;case"deleteWordBackward":case"deleteWordForward":case"deleteSoftLineBackward":case"deleteSoftLineForward":case"deleteHardLineBackward":case"deleteHardLineForward":case"deleteEntireSoftLine":{if(!R(this.state.selection)){this.run(J);return}let n=this.targetRange(e);n&&!R(n)&&n.anchor.blockId===n.focus.blockId?this.run(i=>J({...i,selection:n})):this.run(this.modeValue==="source"?t.endsWith("Backward")?i=>ar(i,en):i=>cr(i,tn):t.endsWith("Backward")?nn:_n);return}case"historyUndo":this.undo();return;case"historyRedo":this.redo();return;case"formatBold":this.commands.toggleBold();return;case"formatItalic":this.commands.toggleItalic();return;case"formatStrikeThrough":this.commands.toggleStrike();return;default:return}}}onSourceInput(e){switch(e){case"insertParagraph":return this.run(t=>this.smartLists?Nl(t):Ae(t,`
117
117
  `)),!0;case"insertLineBreak":return this.run(t=>Ae(t,`
118
118
  `)),!0;case"deleteContentBackward":return this.run(t=>ar(t,en)),!0;case"deleteContentForward":return this.run(t=>cr(t,tn)),!0;default:return!1}}typeText(e){this.run(t=>ue(t,e),"typing"),this.afterTyping(e)}browserApplies(e){let t=e.inputType;if(t==="insertText"||t==="insertReplacementText")return!0;if(!t.startsWith("delete"))return!1;let n=this.targetRange(e);return!!n&&!R(n)&&n.anchor.blockId===n.focus.blockId&&n.anchor.cell?.row===n.focus.cell?.row&&n.anchor.cell?.col===n.focus.cell?.col}afterTyping(e){if(this.modeValue==="source")this.shortcut=null;else{let t=this.state;(e===" "||e==="-")&&this.run(n=>fi(n,this.markdown)),e.length===1&&"*_`~".includes(e)&&this.run(n=>mi(n)),this.markdown.inline.length>0&&this.run(n=>gi(n,this.markdown.inline)??n),e===" "&&this.markdown.autolinks&&this.run(n=>ki(n)??n),this.shortcut=this.state.doc!==t.doc?{typed:t,applied:this.state}:null}e.includes(`
119
- `)||this.typedForSuggestion()}undoShortcut(){let e=this.shortcut;this.shortcut=null;let{doc:t,selection:n}=this.state;return!e||t!==e.applied.doc||!R(n)||!be(n.focus,e.applied.selection.focus)?!1:this.run(()=>e.typed)}onCompositionStart(e){this.fromControl(e)||(this.dropBlockSelection(),this.refreshSelection(),R(this.state.selection)||this.run(J),this.composing=!0,this.composition={blockId:this.state.selection.focus.blockId,marks:this.state.storedMarks,recorded:!1},this.toolbar?.hide(),this.imageToolbar?.hide())}onCompositionEnd(e){if(!this.fromControl(e)){if(!this.composition){this.composing=!1,this.reconcileFromDom("other");return}if(this.syncComposition(),this.composing=!1,bl&&(this.compositionEndedAt=Date.now()),this.unsettled.add(this.composition.blockId),this.settleFrame===null){let t=()=>{this.settleFrame=null,this.settleComposition()};typeof requestAnimationFrame=="function"?this.settleFrame=requestAnimationFrame(t):this.settleComposition()}}}settleComposition(){if(this.composing||this.destroyed)return;let e=this.composition?.recorded;this.composition=null;for(let t of this.unsettled)this.renderer.invalidate(t);this.unsettled.clear(),this.paint(this.redecoratePending),this.redecoratePending=!1,this.afterRender(),e&&this.typedForSuggestion(),this.pendingMode&&this.setMode(this.pendingMode)}onInput(e){if(this.fromControl(e))return;if(this.composing||this.composition&&Na.has(e.inputType)){let n=this.composedLength();this.syncComposition(),this.composing&&this.composedLength()>n&&this.typedForSuggestion();return}if(e.isComposing)return;let t=this.state;this.reconcileFromDom("typing"),e.inputType==="insertText"&&e.data&&this.state!==t&&this.afterTyping(e.data)}composedLength(){let e=this.state.selection.focus,t=this.state.doc.blocks.find(i=>i.id===this.composition?.blockId),n=t&&F(t,t.id===e.blockId?e.cell:void 0);return n?B(n):0}endComposition(){!this.composing||!this.composition||(this.syncComposition(),this.composing=!1,this.unsettled.add(this.composition.blockId),this.settleFrame!==null&&cancelAnimationFrame(this.settleFrame),this.settleFrame=null,this.settleComposition())}syncComposition(){let e=this.composition;if(!e||this.readOnly)return;let t=this.state,n=this.readDom(t,e.marks,e.blockId);if(!n)return;e.recorded||(this.history.record(t,"other"),e.recorded=!0);let i=n.doc.blocks.find(s=>s.id===e.blockId);i&&this.renderer.adopt(i);let r=this.readDomSelection();this.commit(r?{...n,selection:te(n.doc,r)}:n)}reconcileFromDom(e){let t=this.readDom(this.state,this.state.storedMarks);if(!t){this.paint(!0);return}for(let i of t.doc.blocks)i!==N(this.state.doc,i.id)&&this.renderer.invalidate(i.id);let n=this.readDomSelection()??t.selection;this.apply({...t,selection:te(t.doc,n)},e)}readDom(e,t,n){let i=e,r=!1;for(let s of e.doc.blocks){if(n!==void 0&&s.id!==n)continue;let l=this.renderer.elementFor(s.id);if(!l||!l.isConnected)continue;let a=s.type==="table"?s.rows.flatMap((d,u)=>d.map((c,h)=>({cell:{row:u,col:h}}))):Z(s)?[]:[{}];for(let{cell:d}of a){let u=se(l,d),c=F(N(i.doc,s.id),d);if(!u||!c)continue;let h=I(c),f=Or(u);if(h===f)continue;let p=0;for(;p<h.length&&p<f.length&&h[p]===f[p];)p++;let m=h.length,y=f.length;for(;m>p&&y>p&&h[m-1]===f[y-1];)m--,y--;let g=f.slice(p,y),x=d?{blockId:s.id,offset:p,cell:d}:{blockId:s.id,offset:p};i=ye(i,x,{...x,offset:m}),g&&(i=ue({...i,storedMarks:t},g)),r=!0}}return r?i:null}onKeyDown(e){if(this.caretKey=null,this.fromControl(e)||e.isComposing||e.keyCode===229)return;Aa.test(e.key)&&(this.shortcut=null);let t=ie?e.metaKey:e.ctrlKey,n=e.key.toLowerCase(),i=a=>{e.preventDefault(),this.refreshSelection(),a()},r=Date.now()-this.compositionEndedAt<100;if(this.compositionEndedAt=0,this.suggestions.isOpen&&!r&&(this.refreshSelection(),this.suggestions.keydown(e))){e.preventDefault();return}let s=this.blockMenu.isOpen?this.blockMenu:this.toolbar?.menu??null;if(s){let a=s.submenu;if(a){if(e.key==="ArrowLeft"||e.key==="Escape")return i(()=>s.closeSubmenu());if(e.key==="ArrowDown"||e.key==="Tab"&&!e.shiftKey)return i(()=>this.moveMenu(a,1));if(e.key==="ArrowUp"||e.key==="Tab"&&e.shiftKey)return i(()=>this.moveMenu(a,-1));if(e.key==="Enter"&&a.count>0)return i(()=>a.pick())}if(e.key==="ArrowRight"&&s.openSubmenu())return i(()=>this.syncActiveDescendant());if(e.key==="ArrowDown"||e.key==="Tab"&&!e.shiftKey)return i(()=>this.moveMenu(s,1));if(e.key==="ArrowUp"||e.key==="Tab"&&e.shiftKey)return i(()=>this.moveMenu(s,-1));if(e.key==="Enter"&&s.count>0)return i(()=>s.pick());if(e.key==="Escape")return i(()=>s===this.blockMenu?this.closeBlockMenu():this.toolbar.closeMenu())}if(e.key==="Escape"&&(this.toolbar?.isOpen||this.imageToolbar?.isOpen))return i(()=>{this.toolbarClosedFor=this.state.selection,this.toolbar?.hide(),this.imageToolbar?.hide()});if(this.readOnly)return;if(this.blockSel&&this.onBlockKey(e)){e.preventDefault();return}if(e.key==="Enter"&&!t&&!e.altKey){this.refreshSelection();let a=De(this.state);if(a){let d={...a.pos,offset:a.pos.offset+1};this.setSelection({anchor:d,focus:d})}}let l=!1;for(let a of this.bindings)if(Ql(a,e)&&(l||this.refreshSelection(),l=!0,a.handler({editor:this}))){e.preventDefault();return}if(e.key==="Backspace"&&!e.ctrlKey&&!e.metaKey&&!e.altKey){if(this.refreshSelection(),this.undoShortcut()){e.preventDefault();return}let{selection:a}=this.state;if(R(a)&&a.focus.offset===0){e.preventDefault(),this.modeValue!=="source"&&this.run(nn);return}}if(t&&!e.altKey){if(e.key==="/"&&!e.shiftKey&&this.refreshSelection(),e.key==="/"&&!e.shiftKey&&this.hasBlockMenu(this.state.selection.focus.blockId))return i(()=>this.openBlockMenu(this.state.selection.focus.blockId));if(n==="v"&&e.shiftKey){this.plainPasteNext=!0;return}}if(e.key.startsWith("Arrow")&&!t&&!e.shiftKey&&!e.altKey&&this.modeValue==="rich"){this.refreshSelection();let a=this.blockPast(e.key);if(a){e.preventDefault(),this.setSelection({anchor:a,focus:a});return}let d=this.imageBlockStep(e.key);if(d){e.preventDefault(),d!==this.state.selection?this.setSelection(d):(e.key==="ArrowDown"||e.key==="ArrowUp")&&this.run(f=>on(f,e.key==="ArrowDown"?1:-1));return}let u=e.key==="ArrowDown"?1:e.key==="ArrowUp"?-1:0,c=u?this.tableCellPast(u):null;if(c){e.preventDefault(),this.setSelection({anchor:c,focus:c});return}let h=u?on(this.state,u):this.state;if(h!==this.state){e.preventDefault(),this.run(()=>h);return}}if(Aa.test(e.key)){this.refreshSelection();let d=!t&&!e.shiftKey&&!e.altKey?e.key==="ArrowDown"?1:e.key==="ArrowUp"?-1:0:0,c={from:L(this.state.doc,this.state.selection.focus.blockId),x:this.selectionRect()?.left??0,vertical:d};this.caretKey=c,d&&this.unlessCaretMoves(c)}}unlessCaretMoves(e){let t=this.state.selection.focus;if(t.cell||!R(this.state.selection))return;let n=se(this.renderer.elementFor(t.blockId)??this.root);!n||!this.onEdgeLine(n,e.vertical===1)||setTimeout(()=>{if(this.destroyed||this.caretKey!==e)return;let i=this.readDomSelection();if(!i||!be(i.focus,t))return;let r=this.state.doc.blocks;for(let s=e.from+e.vertical;s>=0&&s<r.length;s+=e.vertical){let l=r[s];if(this.skipsCaret(l))continue;this.caretKey=null;let a=e.vertical===1?0:l.type==="table"?l.rows.length-1:0,d=l.type==="table"?{blockId:l.id,offset:e.vertical===1?0:B(l.rows[a][0]),cell:{row:a,col:0}}:this.blockEntry(l,e.vertical===1,e.x);this.setSelection({anchor:d,focus:d}),this.scrollCaretIntoView();return}e.vertical===1&&r[r.length-1].type==="detailsEnd"&&(this.caretKey=null,this.run(s=>oi(s)))})}selectBlockText(e){let t=e.closest?.(`[${W}]`);if(!t||!this.root.contains(t))return!1;let n=N(this.state.doc,t.getAttribute(W)),i=e.closest("[data-row]"),r=n.type==="table"&&i?{row:Number(i.dataset.row),col:Number(i.dataset.col)}:void 0,s=F(n,r);if(!s||t.classList.contains("mbe-view-block"))return!1;let l=a=>r?{blockId:n.id,offset:a,cell:r}:{blockId:n.id,offset:a};return this.setSelection({anchor:l(0),focus:l(B(s))}),!0}moveMenu(e,t){e.move(t),this.syncActiveDescendant()}onMouseDown(e){this.caretKey=null;let t=e.target;if(t.closest?.(".mbe-code-copy")){e.preventDefault();return}let n=e.button===0?t.closest?.(".mbe-details-toggle"):null,i=n?.closest(`[${W}]`)?.getAttribute(W);if(i&&this.root.contains(n)){e.preventDefault(),this.setSectionCollapsed(i,!this.collapsed.has(i));return}if(this.dropBlockSelection(),t===this.root&&e.button===0&&!this.readOnly&&this.modeValue==="rich"&&this.clickBelowLastBlock(e))return;let r=e.button===0&&!e.shiftKey&&!this.readOnly?t.closest?.(".mbe-image"):null,s=r&&this.root.contains(r)?this.imageTarget(r):null;if(s){e.preventDefault(),this.selectImageAt(s.pos);return}let l=e.button===0&&!this.readOnly?t.closest?.(".mbe-view, .mbe-view-block"):null;if(l&&this.root.contains(l)){e.preventDefault(),this.revealView(l);return}if(e.button===0&&e.detail===3&&!this.readOnly&&this.modeValue==="rich"&&this.selectBlockText(t)){e.preventDefault();return}let a=e.button===0&&!this.readOnly?t.closest?.(".mbe-callout-icon"):null,d=a?.parentElement?.getAttribute(W);if(a&&d&&a.parentElement.parentElement===this.root){e.preventDefault(),this.openBlockMenu(d,a.getBoundingClientRect());return}e.button===0&&(this.pointerDown=!0),t.classList?.contains("mbe-checkbox")&&(e.preventDefault(),e.button===0&&this.toggleTaskAt(t))}clickBelowLastBlock(e){let t=this.state.doc.blocks,n=t[t.length-1],i=n?Y(n):null;if(!n||n.type!=="code"&&n.type!=="table"&&!Z(n)&&i===null)return!1;let r=this.root.querySelector(`:scope > [data-block-id="${n.id}"]`);if(!r||e.clientY<=r.getBoundingClientRect().bottom)return!1;e.preventDefault(),this.root.focus({preventScroll:!0});let s=P(n),l=i!==null?{anchor:{blockId:n.id,offset:i},focus:{blockId:n.id,offset:i+1}}:{anchor:s,focus:s};return this.run(a=>on({...a,selection:l},1)),!0}onClick(e){let t=e.target;if(t.classList?.contains("mbe-checkbox")){e.preventDefault(),e.detail===0&&this.toggleTaskAt(t);return}let n=t.closest?.(".mbe-code-copy");if(n){e.preventDefault(),this.copyCode(n);return}let i=t.closest?.("a.mbe-link");i&&(e.preventDefault(),(this.readOnly||(ie?e.metaKey:e.ctrlKey))&&this.openHref(i.getAttribute("href"),e))}openHref(e,t){!e||this.runtime.onLinkClick?.({editor:this,href:e,event:t})||this.root.ownerDocument.defaultView?.open(e,"_blank","noopener,noreferrer")}copyCode(e){let t=e.closest(`[${W}]`),n=t&&this.state.doc.blocks.find(u=>u.id===t.getAttribute(W)),i=n?.type==="code"?I(n.content):e.closest(".mbe-flow .mbe-code")?.querySelector("code")?.textContent;if(i==null)return;let r=this.root.ownerDocument,s=u=>{let c=X(r,this.icon(u));e.replaceChildren(...c?[c]:[]),e.setAttribute("aria-label",this.labels[u]),e.title=this.labels[u],e.classList.toggle("mbe-copied",u==="copied")},l=()=>{s("copied"),setTimeout(()=>e.isConnected&&s("copyCode"),1500)},a=()=>{let u=r.createElement("textarea");u.value=i,u.style.cssText="position:fixed;top:0;left:0;opacity:0",r.body.appendChild(u),u.select();let c=r.execCommand("copy");u.remove(),this.syncDomSelection(this.hasFocus()),c&&l()},d=r.defaultView?.navigator.clipboard;d?.writeText?d.writeText(i).then(l,a):a()}onControlChange(e){let t=e.target;if(!(t instanceof HTMLInputElement)||!t.classList.contains("mbe-code-lang"))return;let n=t.closest("[data-block-id]");n&&this.run(i=>ci(i,n.dataset.blockId,t.value.trim()))}onFocusIn(e){this.focused||!this.hasFocus()||(this.focused=!0,this.root.classList.add("mbe-focused"),this.pointerDown||this.refreshRevealed(),this.options.onFocus?.(this),this.emit("focus",{editor:this,event:e}),this.updateUi())}onFocusOut(e){let t=e.relatedTarget;t&&(this.root.contains(t)||this.inputPopover.contains(t))||queueMicrotask(()=>{this.hasFocus()||this.inputPopover.isOpen||this.focused&&(this.focused=!1,this.root.classList.remove("mbe-focused"),this.refreshRevealed(),this.hideUi(),this.flushChange(),this.options.onBlur?.(this),this.emit("blur",{editor:this,event:e}))})}onScroll(){this.blockHandle.hide(),this.linkCard?.reposition(),this.resizeHandles.reposition(),(this.suggestions.isActive||this.toolbar?.isOpen||this.imageToolbar?.isOpen||this.blockMenu.isOpen)&&this.updateUi()}onCopy(e,t){if(this.fromControl(e))return;if(this.modeValue==="source"){if(this.refreshSelection(),R(this.state.selection)||!e.clipboardData)return;e.preventDefault();let{from:d,to:u}=ne(this.state);e.clipboardData.setData("text/plain",K(this.state.doc).slice(d,u)),t&&!this.readOnly&&this.run(c=>Ae(c,""));return}let n=this.blockRange();if(n){if(!e.clipboardData)return;e.preventDefault();let d={blocks:rn(this.state.doc.blocks.slice(n.from,n.to+1).map(dt))};Oa(e.clipboardData,d,Pe(d.blocks,this.markdown)),t&&!this.readOnly&&this.deleteSelectedBlocks();return}if(this.refreshSelection(),R(this.state.selection)||!e.clipboardData)return;e.preventDefault();let i=vi(this.state),r={blocks:rn(i)},s=Pt(r,this.markdown).replace(/\n$/,""),l=i.length===1&&i[0].type==="paragraph"?i[0]:null,a=l&&Q(N(this.state.doc,this.state.selection.focus.blockId));Oa(e.clipboardData,r,s,a?I(l.content):s),t&&!this.readOnly&&this.run(J)}onPaste(e){if(this.fromControl(e)||(e.preventDefault(),this.readOnly))return;this.refreshSelection();for(let c of this.extensions)if(c.handlePaste?.({editor:this,event:e}))return;let t=e.clipboardData;if(!t)return;let n=t.getData("text/plain"),i=t.getData("text/html"),r=t.types.includes("vscode-editor-data")||ds(i)?"":i,s=this.plainPasteNext;if(this.plainPasteNext=!1,this.modeValue==="source"){let c=this.pastedUrl(n,s);if(c!==null){this.run(f=>_l(f,c));return}let h=this.pastedMarkdown(n,r,s);h&&this.run(f=>Ae(f,h.replace(/\r\n?/g,`
120
- `)));return}let l=this.blockRange();if(l){let c=this.pastedBlocks(n,r,s);this.blockSel=null,this.run(h=>Gn(h,l,c));return}let a=N(this.state.doc,this.state.selection.focus.blockId);if(Q(a)){this.run(c=>ue(c,n));return}let d=this.pastedUrl(n,s);if(d!==null){this.run(c=>ut(c,d));return}let u=this.pastedBlocks(n,r,s);this.run(c=>Xn(c,u))}pastedMarkdown(e,t,n){return n||!t||Kl(this.state)?e:Ha(t)??(Pt({blocks:no(t).blocks},this.markdown).replace(/\n$/,"")||e)}pastedUrl(e,t){let n=e.trim();return!t&&!R(this.state.selection)&&Wh.test(n)?n:null}pastedBlocks(e,t,n){if(n)return e.replace(/\r\n?/g,`
119
+ `)||this.typedForSuggestion()}undoShortcut(){let e=this.shortcut;this.shortcut=null;let{doc:t,selection:n}=this.state;return!e||t!==e.applied.doc||!R(n)||!be(n.focus,e.applied.selection.focus)?!1:this.run(()=>e.typed)}onCompositionStart(e){this.fromControl(e)||(this.dropBlockSelection(),this.refreshSelection(),R(this.state.selection)||this.run(J),this.composing=!0,this.composition={blockId:this.state.selection.focus.blockId,marks:this.state.storedMarks,recorded:!1},this.toolbar?.hide(),this.imageToolbar?.hide())}onCompositionEnd(e){if(!this.fromControl(e)){if(!this.composition){this.composing=!1,this.reconcileFromDom("other");return}if(this.syncComposition(!0),this.composing=!1,bl&&(this.compositionEndedAt=Date.now()),this.unsettled.add(this.composition.blockId),this.settleFrame===null){let t=()=>{this.settleFrame=null,this.settleComposition()};typeof requestAnimationFrame=="function"?this.settleFrame=requestAnimationFrame(t):this.settleComposition()}}}settleComposition(){if(this.composing||this.destroyed)return;let e=this.composition?.recorded;this.composition=null;for(let t of this.unsettled)this.renderer.invalidate(t);this.unsettled.clear(),this.paint(this.redecoratePending),this.redecoratePending=!1,this.afterRender(),e&&this.typedForSuggestion(),this.pendingMode&&this.setMode(this.pendingMode)}onInput(e){if(this.fromControl(e))return;if(this.composing||this.composition&&Ra.has(e.inputType)){let n=this.composedLength();this.syncComposition(),this.composing&&this.composedLength()>n&&this.typedForSuggestion();return}if(e.isComposing)return;let t=this.state;this.reconcileFromDom("typing"),e.inputType==="insertText"&&e.data&&this.state!==t&&this.afterTyping(e.data)}composedLength(){let e=this.state.selection.focus,t=this.state.doc.blocks.find(i=>i.id===this.composition?.blockId),n=t&&F(t,t.id===e.blockId?e.cell:void 0);return n?B(n):0}endComposition(){!this.composing||!this.composition||(this.syncComposition(),this.composing=!1,this.unsettled.add(this.composition.blockId),this.settleFrame!==null&&cancelAnimationFrame(this.settleFrame),this.settleFrame=null,this.settleComposition())}syncComposition(e=!1){let t=this.composition;if(!t||this.readOnly)return;let n=this.state,i=this.readDom(n,t.marks,t.blockId,e);if(!i)return;t.recorded||(this.history.record(n,"other"),t.recorded=!0);let r=i.doc.blocks.find(l=>l.id===t.blockId);r&&this.renderer.adopt(r);let s=this.readDomSelection()?.focus;this.commit(s?{...i,selection:te(i.doc,{anchor:s,focus:s})}:i)}reconcileFromDom(e){let t=this.readDom(this.state,this.state.storedMarks);if(!t){this.paint(!0);return}for(let i of t.doc.blocks)i!==N(this.state.doc,i.id)&&this.renderer.invalidate(i.id);let n=this.readDomSelection()??t.selection;this.apply({...t,selection:te(t.doc,n)},e)}readDom(e,t,n,i=!1){let r=e,s=!1;for(let l of e.doc.blocks){if(n!==void 0&&l.id!==n)continue;let a=this.renderer.elementFor(l.id);if(!a)continue;let d=!a.isConnected;if(d&&(n===void 0||l.type==="table"))continue;let u=l.type==="table"?l.rows.flatMap((c,h)=>c.map((f,p)=>({cell:{row:h,col:p}}))):Z(l)?[]:[{}];for(let{cell:c}of u){let h=d?null:se(a,c),f=F(N(r.doc,l.id),c);if(!h&&!d||!f)continue;let p=I(f),m=h?Or(h):pa(this.root);if(p===m||d&&!m&&!i)continue;let y=0;for(;y<p.length&&y<m.length&&p[y]===m[y];)y++;let g=p.length,v=m.length;for(;g>y&&v>y&&p[g-1]===m[v-1];)g--,v--;let b=m.slice(y,v),w=c?{blockId:l.id,offset:y,cell:c}:{blockId:l.id,offset:y};r=ye(r,w,{...w,offset:g}),b&&(r=ue({...r,storedMarks:t},b)),s=!0}}return s?r:null}onKeyDown(e){if(this.caretKey=null,this.fromControl(e)||e.isComposing||e.keyCode===229)return;Na.test(e.key)&&(this.shortcut=null);let t=ie?e.metaKey:e.ctrlKey,n=e.key.toLowerCase(),i=a=>{e.preventDefault(),this.refreshSelection(),a()},r=Date.now()-this.compositionEndedAt<100;if(this.compositionEndedAt=0,this.suggestions.isOpen&&!r&&(this.refreshSelection(),this.suggestions.keydown(e))){e.preventDefault();return}let s=this.blockMenu.isOpen?this.blockMenu:this.toolbar?.menu??null;if(s){let a=s.submenu;if(a){if(e.key==="ArrowLeft"||e.key==="Escape")return i(()=>s.closeSubmenu());if(e.key==="ArrowDown"||e.key==="Tab"&&!e.shiftKey)return i(()=>this.moveMenu(a,1));if(e.key==="ArrowUp"||e.key==="Tab"&&e.shiftKey)return i(()=>this.moveMenu(a,-1));if(e.key==="Enter"&&a.count>0)return i(()=>a.pick())}if(e.key==="ArrowRight"&&s.openSubmenu())return i(()=>this.syncActiveDescendant());if(e.key==="ArrowDown"||e.key==="Tab"&&!e.shiftKey)return i(()=>this.moveMenu(s,1));if(e.key==="ArrowUp"||e.key==="Tab"&&e.shiftKey)return i(()=>this.moveMenu(s,-1));if(e.key==="Enter"&&s.count>0)return i(()=>s.pick());if(e.key==="Escape")return i(()=>s===this.blockMenu?this.closeBlockMenu():this.toolbar.closeMenu())}if(e.key==="Escape"&&(this.toolbar?.isOpen||this.imageToolbar?.isOpen))return i(()=>{this.toolbarClosedFor=this.state.selection,this.toolbar?.hide(),this.imageToolbar?.hide()});if(this.readOnly)return;if(this.blockSel&&this.onBlockKey(e)){e.preventDefault();return}if(e.key==="Enter"&&!t&&!e.altKey){this.refreshSelection();let a=De(this.state);if(a){let d={...a.pos,offset:a.pos.offset+1};this.setSelection({anchor:d,focus:d})}}let l=!1;for(let a of this.bindings)if(Ql(a,e)&&(l||this.refreshSelection(),l=!0,a.handler({editor:this}))){e.preventDefault();return}if(e.key==="Backspace"&&!e.ctrlKey&&!e.metaKey&&!e.altKey){if(this.refreshSelection(),this.undoShortcut()){e.preventDefault();return}let{selection:a}=this.state;if(R(a)&&a.focus.offset===0){e.preventDefault(),this.modeValue!=="source"&&this.run(nn);return}}if(t&&!e.altKey){if(e.key==="/"&&!e.shiftKey&&this.refreshSelection(),e.key==="/"&&!e.shiftKey&&this.hasBlockMenu(this.state.selection.focus.blockId))return i(()=>this.openBlockMenu(this.state.selection.focus.blockId));if(n==="v"&&e.shiftKey){this.plainPasteNext=!0;return}}if(e.key.startsWith("Arrow")&&!t&&!e.shiftKey&&!e.altKey&&this.modeValue==="rich"){this.refreshSelection();let a=this.blockPast(e.key);if(a){e.preventDefault(),this.setSelection({anchor:a,focus:a});return}let d=this.imageBlockStep(e.key);if(d){e.preventDefault(),d!==this.state.selection?this.setSelection(d):(e.key==="ArrowDown"||e.key==="ArrowUp")&&this.run(f=>on(f,e.key==="ArrowDown"?1:-1));return}let u=e.key==="ArrowDown"?1:e.key==="ArrowUp"?-1:0,c=u?this.tableCellPast(u):null;if(c){e.preventDefault(),this.setSelection({anchor:c,focus:c});return}let h=u?on(this.state,u):this.state;if(h!==this.state){e.preventDefault(),this.run(()=>h);return}}if(Na.test(e.key)){this.refreshSelection();let d=!t&&!e.shiftKey&&!e.altKey?e.key==="ArrowDown"?1:e.key==="ArrowUp"?-1:0:0,c={from:L(this.state.doc,this.state.selection.focus.blockId),x:this.selectionRect()?.left??0,vertical:d};this.caretKey=c,d&&this.unlessCaretMoves(c)}}unlessCaretMoves(e){let t=this.state.selection.focus;if(t.cell||!R(this.state.selection))return;let n=se(this.renderer.elementFor(t.blockId)??this.root);!n||!this.onEdgeLine(n,e.vertical===1)||setTimeout(()=>{if(this.destroyed||this.caretKey!==e)return;let i=this.readDomSelection();if(!i||!be(i.focus,t))return;let r=this.state.doc.blocks;for(let s=e.from+e.vertical;s>=0&&s<r.length;s+=e.vertical){let l=r[s];if(this.skipsCaret(l))continue;this.caretKey=null;let a=e.vertical===1?0:l.type==="table"?l.rows.length-1:0,d=l.type==="table"?{blockId:l.id,offset:e.vertical===1?0:B(l.rows[a][0]),cell:{row:a,col:0}}:this.blockEntry(l,e.vertical===1,e.x);this.setSelection({anchor:d,focus:d}),this.scrollCaretIntoView();return}e.vertical===1&&r[r.length-1].type==="detailsEnd"&&(this.caretKey=null,this.run(s=>oi(s)))})}selectBlockText(e){let t=e.closest?.(`[${W}]`);if(!t||!this.root.contains(t))return!1;let n=N(this.state.doc,t.getAttribute(W)),i=e.closest("[data-row]"),r=n.type==="table"&&i?{row:Number(i.dataset.row),col:Number(i.dataset.col)}:void 0,s=F(n,r);if(!s||t.classList.contains("mbe-view-block"))return!1;let l=a=>r?{blockId:n.id,offset:a,cell:r}:{blockId:n.id,offset:a};return this.setSelection({anchor:l(0),focus:l(B(s))}),!0}moveMenu(e,t){e.move(t),this.syncActiveDescendant()}onMouseDown(e){this.caretKey=null;let t=e.target;if(t.closest?.(".mbe-code-copy")){e.preventDefault();return}let n=e.button===0?t.closest?.(".mbe-details-toggle"):null,i=n?.closest(`[${W}]`)?.getAttribute(W);if(i&&this.root.contains(n)){e.preventDefault(),this.setSectionCollapsed(i,!this.collapsed.has(i));return}if(this.dropBlockSelection(),t===this.root&&e.button===0&&!this.readOnly&&this.modeValue==="rich"&&this.clickBelowLastBlock(e))return;let r=e.button===0&&!e.shiftKey&&!this.readOnly?t.closest?.(".mbe-image"):null,s=r&&this.root.contains(r)?this.imageTarget(r):null;if(s){e.preventDefault(),this.selectImageAt(s.pos);return}let l=e.button===0&&!this.readOnly?t.closest?.(".mbe-view, .mbe-view-block"):null;if(l&&this.root.contains(l)){e.preventDefault(),this.revealView(l);return}if(e.button===0&&e.detail===3&&!this.readOnly&&this.modeValue==="rich"&&this.selectBlockText(t)){e.preventDefault();return}let a=e.button===0&&!this.readOnly?t.closest?.(".mbe-callout-icon"):null,d=a?.parentElement?.getAttribute(W);if(a&&d&&a.parentElement.parentElement===this.root){e.preventDefault(),this.openBlockMenu(d,a.getBoundingClientRect());return}e.button===0&&(this.pointerDown=!0),t.classList?.contains("mbe-checkbox")&&(e.preventDefault(),e.button===0&&this.toggleTaskAt(t))}clickBelowLastBlock(e){let t=this.state.doc.blocks,n=t[t.length-1],i=n?Y(n):null;if(!n||n.type!=="code"&&n.type!=="table"&&!Z(n)&&i===null)return!1;let r=this.root.querySelector(`:scope > [data-block-id="${n.id}"]`);if(!r||e.clientY<=r.getBoundingClientRect().bottom)return!1;e.preventDefault(),this.root.focus({preventScroll:!0});let s=P(n),l=i!==null?{anchor:{blockId:n.id,offset:i},focus:{blockId:n.id,offset:i+1}}:{anchor:s,focus:s};return this.run(a=>on({...a,selection:l},1)),!0}onClick(e){let t=e.target;if(t.classList?.contains("mbe-checkbox")){e.preventDefault(),e.detail===0&&this.toggleTaskAt(t);return}let n=t.closest?.(".mbe-code-copy");if(n){e.preventDefault(),this.copyCode(n);return}let i=t.closest?.("a.mbe-link");i&&(e.preventDefault(),(this.readOnly||(ie?e.metaKey:e.ctrlKey))&&this.openHref(i.getAttribute("href"),e))}openHref(e,t){!e||this.runtime.onLinkClick?.({editor:this,href:e,event:t})||this.root.ownerDocument.defaultView?.open(e,"_blank","noopener,noreferrer")}copyCode(e){let t=e.closest(`[${W}]`),n=t&&this.state.doc.blocks.find(u=>u.id===t.getAttribute(W)),i=n?.type==="code"?I(n.content):e.closest(".mbe-flow .mbe-code")?.querySelector("code")?.textContent;if(i==null)return;let r=this.root.ownerDocument,s=u=>{let c=X(r,this.icon(u));e.replaceChildren(...c?[c]:[]),e.setAttribute("aria-label",this.labels[u]),e.title=this.labels[u],e.classList.toggle("mbe-copied",u==="copied")},l=()=>{s("copied"),setTimeout(()=>e.isConnected&&s("copyCode"),1500)},a=()=>{let u=r.createElement("textarea");u.value=i,u.style.cssText="position:fixed;top:0;left:0;opacity:0",r.body.appendChild(u),u.select();let c=r.execCommand("copy");u.remove(),this.syncDomSelection(this.hasFocus()),c&&l()},d=r.defaultView?.navigator.clipboard;d?.writeText?d.writeText(i).then(l,a):a()}onControlChange(e){let t=e.target;if(!(t instanceof HTMLInputElement)||!t.classList.contains("mbe-code-lang"))return;let n=t.closest("[data-block-id]");n&&this.run(i=>ci(i,n.dataset.blockId,t.value.trim()))}onFocusIn(e){this.focused||!this.hasFocus()||(this.focused=!0,this.root.classList.add("mbe-focused"),this.pointerDown||this.refreshRevealed(),this.options.onFocus?.(this),this.emit("focus",{editor:this,event:e}),this.updateUi())}onFocusOut(e){let t=e.relatedTarget;t&&(this.root.contains(t)||this.inputPopover.contains(t))||queueMicrotask(()=>{this.hasFocus()||this.inputPopover.isOpen||this.focused&&(this.focused=!1,this.root.classList.remove("mbe-focused"),this.refreshRevealed(),this.hideUi(),this.flushChange(),this.options.onBlur?.(this),this.emit("blur",{editor:this,event:e}))})}onScroll(){this.blockHandle.hide(),this.linkCard?.reposition(),this.resizeHandles.reposition(),(this.suggestions.isActive||this.toolbar?.isOpen||this.imageToolbar?.isOpen||this.blockMenu.isOpen)&&this.updateUi()}onCopy(e,t){if(this.fromControl(e))return;if(this.modeValue==="source"){if(this.refreshSelection(),R(this.state.selection)||!e.clipboardData)return;e.preventDefault();let{from:d,to:u}=ne(this.state);e.clipboardData.setData("text/plain",K(this.state.doc).slice(d,u)),t&&!this.readOnly&&this.run(c=>Ae(c,""));return}let n=this.blockRange();if(n){if(!e.clipboardData)return;e.preventDefault();let d={blocks:rn(this.state.doc.blocks.slice(n.from,n.to+1).map(dt))};Ha(e.clipboardData,d,Pe(d.blocks,this.markdown)),t&&!this.readOnly&&this.deleteSelectedBlocks();return}if(this.refreshSelection(),R(this.state.selection)||!e.clipboardData)return;e.preventDefault();let i=vi(this.state),r={blocks:rn(i)},s=Pt(r,this.markdown).replace(/\n$/,""),l=i.length===1&&i[0].type==="paragraph"?i[0]:null,a=l&&Q(N(this.state.doc,this.state.selection.focus.blockId));Ha(e.clipboardData,r,s,a?I(l.content):s),t&&!this.readOnly&&this.run(J)}onPaste(e){if(this.fromControl(e)||(e.preventDefault(),this.readOnly))return;this.refreshSelection();for(let c of this.extensions)if(c.handlePaste?.({editor:this,event:e}))return;let t=e.clipboardData;if(!t)return;let n=t.getData("text/plain"),i=t.getData("text/html"),r=t.types.includes("vscode-editor-data")||ds(i)?"":i,s=this.plainPasteNext;if(this.plainPasteNext=!1,this.modeValue==="source"){let c=this.pastedUrl(n,s);if(c!==null){this.run(f=>_l(f,c));return}let h=this.pastedMarkdown(n,r,s);h&&this.run(f=>Ae(f,h.replace(/\r\n?/g,`
120
+ `)));return}let l=this.blockRange();if(l){let c=this.pastedBlocks(n,r,s);this.blockSel=null,this.run(h=>Gn(h,l,c));return}let a=N(this.state.doc,this.state.selection.focus.blockId);if(Q(a)){this.run(c=>ue(c,n));return}let d=this.pastedUrl(n,s);if(d!==null){this.run(c=>ut(c,d));return}let u=this.pastedBlocks(n,r,s);this.run(c=>Xn(c,u))}pastedMarkdown(e,t,n){return n||!t||Kl(this.state)?e:Pa(t)??(Pt({blocks:no(t).blocks},this.markdown).replace(/\n$/,"")||e)}pastedUrl(e,t){return!t&&!R(this.state.selection)?this.linkableUrl(e):null}linkableUrl(e){let t=e.trim();return Qh.test(t)&&this.renderer.resolveUrl(t,"link")!==null?t:null}pastedBlocks(e,t,n){if(n)return e.replace(/\r\n?/g,`
121
121
  `).split(`
122
- `).map(s=>O(ge(s)));let i,r=Ha(t);return r!==null?i=bt(r,this.markdown).blocks:t?i=no(t).blocks:i=bt(e,this.markdown).blocks,i.length===0&&e&&(i=bt(e,this.markdown).blocks),i}onDrop(e){if(e.preventDefault(),this.readOnly)return;let t=this.positionAtPoint(e.clientX,e.clientY);for(let r of this.extensions)if(r.handleDrop?.({editor:this,event:e,position:t}))return;let n=e.dataTransfer?.getData("text/plain");if(!n||!t)return;if(this.modeValue==="source"){this.focus(),this.run(r=>To(r,t.offset,n.replace(/\r\n?/g,`
123
- `),!1,!1));return}let i=bt(n,this.markdown).blocks;this.focus(),this.run(r=>cn(r,i,{at:t}))}positionAtPoint(e,t){let n=this.root.ownerDocument,i=null,r=0,s=n.caretPositionFromPoint?.(e,t);if(s)i=s.offsetNode,r=s.offset;else{let l=n.caretRangeFromPoint?.(e,t);l&&(i=l.startContainer,r=l.startOffset)}return!i||!this.root.contains(i)?null:_e(this.root,i,r)}typedForSuggestion(){this.suggestions.typed()&&this.updateUi()}slashSuggestion(){let t=(this.options.slashMenu||Pa).map(n=>Kh.find(i=>i.id===n)).filter(n=>!!n&&(n.id!=="callout"||this.markdown.callouts)&&(n.id!=="details"||this.markdown.details)).map(n=>({id:n.id,label:this.labels[n.id],icon:this.icon(n.id),aliases:n.aliases,spec:n.spec}));return{name:"slash",trigger:zh,allowSpaces:!0,richOnly:!0,emptyLabel:this.labels.noResults,label:this.labels.commands,className:"mbe-slash-menu",items:({query:n})=>t.filter(i=>yl(i,n)),command:({range:n,item:i})=>{let r=n.from.blockId,s=N(this.current.doc,r),l=q(s)?I(s.content):"",a=n.to.offset,d=a===l.length&&l[n.from.offset-1]===" "?n.from.offset-1:n.from.offset;this.run(u=>{let c=ye(u,{blockId:r,offset:d},{blockId:r,offset:a});return Rt(c,i.spec)})}}}get selectedBlocks(){let e=this.blockRange();return e?this.current.doc.blocks.slice(e.from,e.to+1):[]}blockRange(){if(!this.blockSel)return null;let e=this.current.doc,t=L(e,this.blockSel.anchor),n=L(e,this.blockSel.head);return t<0||n<0?null:this.wholeSections({from:Math.min(t,n),to:Math.max(t,n)})}wholeSections(e){let t=this.current.doc.blocks,{from:n,to:i}=e;if(!t.some(r=>r.type==="details"))return e;for(let r=!0;r;){r=!1;for(let s=n;s<=i;s++){let l=t[s];if(l.type==="details"){let a=At(t,s)??s;a>i&&(i=a,r=!0)}else if(l.type==="detailsEnd"){let a=si(t,s);a!==null&&a<n&&(n=a,r=!0)}}}return{from:n,to:i}}nextSelectable(e,t){let n=this.current.doc.blocks;for(let i=e+t;i>=0&&i<n.length;i+=t){let r=n[i];if(r.type!=="detailsEnd"&&!this.renderer.elementFor(r.id)?.hasAttribute("data-section-hidden"))return r.id}return n[e].id}selectBlockRange(e,t){this.blockSel={anchor:e,head:t},this.current={...this.current,selection:an(this.current.doc.blocks,this.blockRange()),storedMarks:null},this.history.breakGroup(),this.suggestions.close(),this.toolbar?.hide(),this.imageToolbar?.hide(),this.blockMenu.hide(),this.refreshRevealed(),this.paintBlockSelection(),this.syncDomSelection(!0),this.updateUi(),this.emit("selectionChange",{editor:this})}dropBlockSelection(){let e=this.parkedCaret();e&&(this.blockSel=null,this.current={...this.current,selection:{anchor:e,focus:e},storedMarks:null},this.paintBlockSelection())}exitBlockSelection(e){this.blockSel=null,this.paintBlockSelection(),this.setSelection({anchor:e,focus:e})}parkedCaret(){if(!this.blockSel)return null;let e=this.current.doc.blocks.find(t=>t.id===this.blockSel.head);return e?V(e):null}paintBlockSelection(){let e=this.blockRange(),t=[];if(e)for(let n of this.current.doc.blocks.slice(e.from,e.to+1)){let i=this.renderer.elementFor(n.id);i&&t.push(i)}for(let n of this.selectedEls)t.includes(n)||n.classList.remove("mbe-block-selected");for(let n of t)n.classList.add("mbe-block-selected");this.selectedEls=t,this.root.classList.toggle("mbe-block-selecting",t.length>0)}deleteSelectedBlocks(){let e=this.blockRange();e&&(this.blockSel=null,this.run(t=>jn(t,e)))}onBlockKey(e){let t=this.blockRange();if(!t)return!1;let n=this.state.doc.blocks,i=!e.metaKey&&!e.ctrlKey&&!e.altKey,r=ie?e.metaKey:e.ctrlKey;switch(e.key){case"Escape":return!i||e.shiftKey?!1:(this.dropBlockSelection(),this.blur(),!0);case"ArrowUp":case"ArrowDown":{if(!i)return!1;let s=e.key==="ArrowUp";if(e.shiftKey){let l=L(this.current.doc,this.blockSel.head);!s&&n[l]?.type==="details"&&(l=At(n,l)??l),this.selectBlockRange(this.blockSel.anchor,this.nextSelectable(l,s?-1:1))}else{let l=this.nextSelectable(s?t.from:t.to,s?-1:1);this.selectBlockRange(l,l)}return!0}case"ArrowLeft":case"ArrowRight":return!i||e.shiftKey?!1:(this.exitBlockSelection(e.key==="ArrowLeft"?V(n[t.from]):P(n[t.to])),!0);case"Enter":return!i||e.shiftKey?!1:(this.exitBlockSelection(P(n[t.to])),!0);case"Backspace":case"Delete":return i?(this.deleteSelectedBlocks(),!0):!1}if(r&&!e.altKey&&!e.shiftKey){let s=e.key.toLowerCase();if(s==="a")return this.selectBlockRange(n[0].id,n[n.length-1].id),!0;if(s==="d"){let l=t.to-t.from+1;if(this.run(a=>ui(a,t))){let a=this.current.doc.blocks;this.selectBlockRange(a[t.to+1].id,a[t.to+l].id)}return!0}}return!1}icon(e){return this.options.icons?.[e]??fs(this.root.ownerDocument,e)}blockMenuSections(e){let t=N(this.state.doc,e),n=[],i=this.state.selection.focus.cell;if(t.type==="table"&&this.state.selection.focus.blockId===e&&i){let l=Vh.map(({id:d,action:u})=>({id:d,label:this.labels[d],icon:this.icon(d),run:()=>this.run(c=>Zn(c,u))})),a=t.align[i.col]??"left";l.splice(4,0,this.alignMenuItem("align",a,d=>({icon:this.icon(d.id),run:()=>this.run(u=>Zn(u,{kind:"align",align:d.align}))}))),n.push({title:this.labels.tableSection,items:l})}let r=M(t);if(r&&r!=="quote"){let l=r,a=Ve.map(d=>{let u=Br(d);return{id:u,label:this.labels[u],icon:this.icon(u),checked:d===l,run:()=>this.run(c=>sn(c,e,d))}});return n.push({title:this.labels.callout,items:a}),n.push({items:[{id:"delete",label:this.labels.delete,icon:this.icon("delete"),danger:!0,run:()=>this.run(d=>{let u=Nt(d,e);return u?jn(d,{from:u.start,to:u.end}):null})}]}),n}let s=Y(t);if(s!==null){let l={blockId:e,offset:s},a=C(t.content,s,s+1)[0].image,d=[this.alignMenuItem("imageAlignLeft",a.align??"left",u=>({icon:this.icon(u.image),run:()=>this.updateImageAt(l,{align:u.align==="left"?null:u.align})})),{id:"altText",label:this.labels.altText,icon:this.icon("altText"),run:()=>this.editAltText(l,a.alt)}];a.width&&d.push({id:"resetImageSize",label:this.labels.resetImageSize,icon:this.icon("resetImageSize"),run:()=>this.updateImageAt(l,{width:null})}),n.push({title:this.labels.imageSection,items:d})}return n.push({items:[{id:"duplicate",label:this.labels.duplicate,icon:this.icon("duplicate"),run:()=>this.run(l=>di(l,e))},{id:"delete",label:this.labels.delete,icon:this.icon("delete"),danger:!0,run:()=>this.run(l=>Bt(l,e))}]}),n}alignMenuItem(e,t,n){return{id:"align",label:this.labels.align,icon:this.icon(e),run:()=>{},submenu:{title:this.labels.align,items:Uh.map(i=>({id:i.id,label:this.labels[i.id],checked:t===i.align,...n(i)}))}}}hasBlockMenu(e){if(this.modeValue==="source")return!1;let t=this.state.doc.blocks.find(n=>n.id===e);return t?.type==="table"||t?.type==="code"||Ra(t)||!!t&&jr(t)}blockMenuOwner(e){if(!this.hasBlockMenu(e))return null;let t=Nt(this.state,e);return t?this.state.doc.blocks[t.start].id:e}openBlockMenu(e,t){if(this.readOnly||!this.hasBlockMenu(e))return;this.dropBlockSelection(),this.suggestions.close(),this.toolbar?.hide(),this.imageToolbar?.hide();let n=Y(N(this.state.doc,e));if(n!==null)this.current=je(this.state,{blockId:e,offset:n}),this.hasFocus()||this.focus();else if(this.state.selection.focus.blockId!==e&&!this.inSameCallout(this.state.selection.focus.blockId,e)){let r=N(this.state.doc,e),s=V(r);this.current={...this.state,selection:{anchor:s,focus:s}},this.focus()}else this.hasFocus()||this.focus();this.blockMenu.setSections(this.blockMenuSections(e));let i=t??this.blockElement(e)?.getBoundingClientRect();i&&this.blockMenu.popup.show(i,"below"),this.syncActiveDescendant()}inSameCallout(e,t){let n=N(this.state.doc,t),i=Ra(n)?Nt(this.state,t):null;if(!i)return!1;let r=L(this.state.doc,e);return r>=i.start&&r<=i.end}closeBlockMenu(){this.blockMenu.hide(),this.updateUi()}onDocumentPointerDown(e){let t=e.target;this.toolbar?.menu&&!(t&&this.toolbar.contains(t))&&this.toolbar.closeMenu(),this.blockMenu.isOpen&&(t&&(this.blockMenu.contains(t)||this.blockHandle.contains(t))||this.closeBlockMenu())}openLinkPopover(){if(this.readOnly||this.modeValue==="source")return!1;let e=N(this.state.doc,this.state.selection.focus.blockId);if(Q(e)||R(this.state.selection)&&!Qe(this.state))return!1;let t=this.selectionRect();if(!t)return!1;this.toolbar?.hide();let n=this.state.selection,i=Qe(this.current)?.href??"",{labels:r}=this,s={value:i,label:r.link,placeholder:r.linkPlaceholder,type:"url",removeLabel:r.removeLink};return this.inputPopover.open(t,s,l=>{this.current={...this.state,selection:n},l!==null&&this.run(a=>ut(a,l===""?null:l)),this.focus()}),!0}updateUi(){if(this.destroyed)return;this.expandAroundSelection();let e=this.hasFocus(),t=this.state.selection.focus,n=e&&!this.blockSel&&R(this.state.selection)?this.renderer.elementFor(t.blockId):void 0,i=!!this.options.placeholder&&this.state.doc.blocks.length===1,l=!!this.options.slashHint&&this.options.slashMenu!==!1&&n&&n.classList.contains("mbe-paragraph")&&n.classList.contains("mbe-empty")&&!this.readOnly&&!i?n:null;this.hintEl!==l&&(this.hintEl?.classList.remove("mbe-show-hint"),l?.classList.add("mbe-show-hint"),this.hintEl=l),this.suggestions.update(e);let a=e&&!this.readOnly&&!this.blockSel?this.imageTargetAt(this.state):null;this.paintSelectedImage(a?.el??null),this.resizeHandles.update(a);let d=this.toolbarClosedFor;if(d&&!(be(d.anchor,this.state.selection.anchor)&&be(d.focus,t))&&(this.toolbarClosedFor=null),this.imageToolbar&&(a&&!this.toolbarClosedFor&&!this.composing&&!this.suggestions.isActive&&!this.blockMenu.isOpen&&!this.inputPopover.isOpen&&!this.resizeHandles.isDragging?this.imageToolbar.show(a,ke(this.state)!==null):this.imageToolbar.hide()),this.toolbar){let u=this.state.doc.blocks.find(h=>h.id===t.blockId);!this.toolbarClosedFor&&e&&!this.readOnly&&!this.composing&&!R(this.state.selection)&&!this.blockSel&&!a&&!this.suggestions.isActive&&!this.blockMenu.isOpen&&!!u&&!Q(u)&&u.type!=="divider"?this.toolbar.show():this.toolbar.hide()}if(e&&!this.readOnly&&Ft()){let u=this.blockMenuOwner(t.blockId);u?this.blockHandle.showFor(u):this.blockHandle.hide()}!e&&this.blockMenu.isOpen&&!this.root.ownerDocument.activeElement?.closest?.(".mbe-ui")&&this.blockMenu.hide(),this.linkCard&&(this.readOnly?this.linkCard.hide():this.linkCard.setCaret(e&&!this.composing&&!this.blockSel&&!this.suggestions.isActive&&!this.blockMenu.isOpen&&!this.inputPopover.isOpen?this.caretLink():null)),this.syncActiveDescendant()}setSectionCollapsed(e,t){if(this.destroyed)return!1;let n=this.state.doc,i=L(n,e);if(n.blocks[i]?.type!=="details")return!1;if(this.collapsed.has(e)===t)return!0;if(t?this.collapsed.add(e):this.collapsed.delete(e),t){let r=At(n.blocks,i)??i,s=d=>{let u=L(n,d.blockId);return u>i&&u<=r},{anchor:l,focus:a}=this.state.selection;if(s(l)||s(a)){let d=P(n.blocks[i]);this.dropBlockSelection(),this.current={...this.current,selection:{anchor:d,focus:d},storedMarks:null},this.syncDomSelection()}}return this.renderer.updateSections(n),this.updateUi(),!0}isSectionCollapsed(e){return this.collapsed.has(e)}collapseClosedSections(e){for(let t of e.blocks)t.type==="details"&&!t.open&&this.collapsed.add(t.id)}expandAroundSelection(){if(this.collapsed.size===0)return;let e=this.state.selection.focus.blockId;if(!this.renderer.elementFor(e)?.hasAttribute("data-section-hidden"))return;let t=[];for(let n of this.state.doc.blocks){if(n.id===e)break;n.type==="details"?t.push(n.id):n.type==="detailsEnd"&&t.pop()}for(let n of t)this.collapsed.delete(n);this.renderer.updateSections(this.state.doc)}skipsCaret(e){return Z(e)||!!this.renderer.elementFor(e.id)?.hasAttribute("data-section-hidden")}caretLink(){if(!R(this.state.selection))return null;let e=Qe(this.state);if(!e||e.pos.offset<=e.from||e.pos.offset>=e.to)return null;let t=this.renderer.elementFor(e.pos.blockId);if(!t)return null;let n={...e.pos,offset:e.from};for(let i of t.querySelectorAll("a.mbe-link")){let r=this.linkStart(i);if(r&&be(r,n))return this.linkTargetOf(i)}return null}linkStart(e){return _e(this.root,e,0)}linkTargetOf(e){if(e.closest(".mbe-flow"))return null;let t=this.linkStart(e);if(!t)return null;let n=this.state.doc.blocks.find(s=>s.id===t.blockId),i=n&&F(n,t.cell),r=i&&Xt(i,t.offset);return r&&r.from===t.offset?{el:e,href:r.href}:null}linkSelection(e){let t=this.linkStart(e.el);if(!t)return null;let n=N(this.state.doc,t.blockId),i=F(n,t.cell),r=i&&Xt(i,t.offset);return r?{anchor:t,focus:{...t,offset:r.to}}:null}editLink(e){let t=this.linkSelection(e);!t||this.readOnly||(this.focus(),this.setSelection(t),this.openLinkPopover())}removeLink(e){let t=this.linkSelection(e);!t||this.readOnly||this.run(n=>({...ut({...n,selection:t},null),selection:n.selection}))}paintSelectedImage(e){this.selectedImageEl!==e&&(this.selectedImageEl?.classList.remove("mbe-image-selected"),e?.classList.add("mbe-image-selected"),this.selectedImageEl=e),this.root.classList.toggle("mbe-image-selection",e!==null)}imageTargetAt(e){let t=De(e);if(!t)return null;let n=this.renderer.elementFor(t.pos.blockId),i=n?pa(n,t.pos):null;return i?.classList.contains("mbe-image")?{el:i,...t}:null}imageTarget(e){if(!e.parentNode||!this.root.contains(e))return null;let t=_e(this.root,e.parentNode,xt(e));if(!t)return null;let n=je(this.current,t),i=n===this.current?null:De(n);return i?{el:e,...i}:null}selectImageAt(e){if(this.readOnly||this.destroyed)return;let t=je(this.current,e);t!==this.current&&(this.hasFocus()||this.root.focus({preventScroll:!0}),this.setSelection(t.selection))}updateImageAt(e,t){this.run(n=>Un(n,e,t))}editAltText(e,t){let n=(this.imageTargetAt(this.state)?.el??this.blockElement(e.blockId))?.getBoundingClientRect();if(!n)return;this.imageToolbar?.hide();let{labels:i}=this,r={value:t,label:i.altText,placeholder:i.altTextPlaceholder,type:"text"};this.inputPopover.open(n,r,s=>{s!==null?this.updateImageAt(e,{alt:s}):this.current=je(this.state,e),this.focus()})}deleteImageAt(e){this.run(t=>{let n=je(t,e);return n===t?null:ke(n)?Bt(n,e.blockId):J(n)})}refreshImageUi(){this.updateUi()}syncActiveDescendant(){let e=this.blockMenu.isOpen?this.blockMenu:this.toolbar?.menu,t=this.suggestions.activeDescendant??e?.activeDescendant??null;t?this.root.setAttribute("aria-activedescendant",t):this.root.removeAttribute("aria-activedescendant")}hideUi(){this.dropBlockSelection(),this.suggestions.close(),this.blockMenu.hide(),this.toolbar?.hide(),this.imageToolbar?.hide(),this.blockHandle.hide(),this.linkCard?.setCaret(null),this.resizeHandles.hide(),this.paintSelectedImage(null),this.hintEl?.classList.remove("mbe-show-hint"),this.hintEl=null}typed(e){return t=>{this.typing++;try{e(t)}finally{this.typing--}}}listen(e,t,n,i=!1){e.addEventListener(t,n,i),this.cleanup.push(()=>e.removeEventListener(t,n,i))}};function Ra(o){let e=M(o);return e!==null&&e!=="quote"}function Da(o){switch(o.type){case"listItem":return o.listType==="bullet"?"bulletList":o.listType==="ordered"?"orderedList":"taskList";case"quote":return"blockquote";case"code":return"codeBlock";case"detailsEnd":return"details";default:return o.type}}function Oa(o,e,t,n=t){o.setData("text/plain",n),o.setData("text/html",`<meta charset="utf-8"><div data-mbe-markdown="${encodeURIComponent(t)}">${dn(e)}</div>`)}var Wh=/^(https?:\/\/|mailto:)\S+$/i;function Ha(o){let e=/data-mbe-markdown="([^"]*)"/.exec(o);return e?decodeURIComponent(e[1]):null}function Qh(o,e){return o.blocks.length===e.blocks.length&&o.blocks.every((t,n)=>t===e.blocks[n])}function jh(o){return typeof o.anchor?.blockId=="string"}function Gh(o,e){let t=r=>{if(!r||typeof r!="object")return null;let{block:s,offset:l,cell:a}=r;if(!Number.isInteger(s)||!Number.isInteger(l))return null;let d=Math.max(0,Math.min(s,o.blocks.length-1)),u=o.blocks[d];if(s>=o.blocks.length)return P(u);if(u.type==="table"){let c=a&&typeof a=="object"?a:{},h=Number.isInteger(c.row)?Math.max(0,Math.min(c.row,u.rows.length-1)):0,f=Number.isInteger(c.col)?Math.max(0,Math.min(c.col,u.rows[0].length-1)):0;return{blockId:u.id,offset:Math.max(0,l),cell:{row:h,col:f}}}return{blockId:u.id,offset:Math.max(0,l)}};if(!e||typeof e!="object")return null;let n=t(e.anchor),i=t(e.focus);return!n||!i?null:te(o,{anchor:n,focus:i})}function Zh(o,e){return o.closest("[data-block-id]")?.querySelector(".mbe-content")?.textContent?.trim()||e}function Xh(o,e){for(let t=o.parentElement;t;t=t.parentElement){let n=getComputedStyle(t).overflowY;if((n==="auto"||n==="scroll")&&t.scrollHeight>t.clientHeight){t.scrollTop+=e;return}}o.ownerDocument.defaultView?.scrollBy(0,e)}function $a(o){switch(o.type){case"root":case"blockQuote":case"listItem":case"paragraph":case"heading":case"emphasis":case"strong":case"strike":case"link":case"image":return o.children;case"list":return o.items;case"table":return o.rows.flatMap(e=>e.flat());default:return[]}}function Yh(o,e){let t=[],n=i=>{if(e(i,t)!==!1){t.push(i);for(let r of $a(i))n(r);t.pop()}};n(o)}function Jh(o,e,t){let n=typeof o=="string"?pt(o):o,i=new xe(e,n);return{from:i.source(t.from),to:i.source(t.to)}}function Fa(o){return o===void 0||/\s/.test(o)}function ef(o){return o!==void 0&&o>="0"&&o<="9"}function tf(o,e){let t=0;for(;o.charCodeAt(e-t-1)===92;)t++;return t%2===1}var nf={name:"math",triggers:"$",match(o,e){if(o.charCodeAt(e-1)===36&&!tf(o,e-1))return-1;let t=e;for(;o.charCodeAt(t)===36;)t++;let n=t-e;if(n===1&&Fa(o[t]))return-1;for(let i=t;i<o.length;){if(o.charCodeAt(i)!==36){i++;continue}let r=i+1;for(;o.charCodeAt(r)===36;)r++;if(r-i===n)return n===1&&(Fa(o[i-1])||ef(o[r]))?-1:r;i=r}return-1}};function of(o){let e=0;for(;o.charCodeAt(e)===36;)e++;return e>=2&&!o.includes("$",e)?e:0}var rf={name:"math",interruptsParagraph:!0,open(o){let e=of(o);return e?{next(t){let n=t.replace(/^[ \t]+/,""),i=0;for(;n.charCodeAt(i)===36;)i++;return i>=e&&/^[ \t]*$/.test(n.slice(i))?"close":"continue"}}:null}};function sf(o,e){if(e==="inline"){let i=0;for(;o.charCodeAt(i)===36;)i++;return o.slice(i,o.length-i)}let t=o.split(`
122
+ `).map(a=>D(ge(a)));let i,r=Pa(t);r!==null?i=bt(r,this.markdown).blocks:t?i=no(t).blocks:i=bt(e,this.markdown).blocks,i.length===0&&e&&(i=bt(e,this.markdown).blocks);let s=t?null:this.linkableUrl(e),l=i.length===1?i[0]:null;return s!==null&&l?.type==="paragraph"&&!l.content.some(a=>a.link!==void 0)&&(i=[D([{text:s,marks:[],link:s}])]),i}onDrop(e){if(e.preventDefault(),this.readOnly)return;let t=this.positionAtPoint(e.clientX,e.clientY);for(let r of this.extensions)if(r.handleDrop?.({editor:this,event:e,position:t}))return;let n=e.dataTransfer?.getData("text/plain");if(!n||!t)return;if(this.modeValue==="source"){this.focus(),this.run(r=>To(r,t.offset,n.replace(/\r\n?/g,`
123
+ `),!1,!1));return}let i=bt(n,this.markdown).blocks;this.focus(),this.run(r=>cn(r,i,{at:t}))}positionAtPoint(e,t){let n=this.root.ownerDocument,i=null,r=0,s=n.caretPositionFromPoint?.(e,t);if(s)i=s.offsetNode,r=s.offset;else{let l=n.caretRangeFromPoint?.(e,t);l&&(i=l.startContainer,r=l.startOffset)}return!i||!this.root.contains(i)?null:_e(this.root,i,r)}typedForSuggestion(){this.suggestions.typed()&&this.updateUi()}slashSuggestion(){let t=(this.options.slashMenu||$a).map(n=>Vh.find(i=>i.id===n)).filter(n=>!!n&&(n.id!=="callout"||this.markdown.callouts)&&(n.id!=="details"||this.markdown.details)).map(n=>({id:n.id,label:this.labels[n.id],icon:this.icon(n.id),aliases:n.aliases,spec:n.spec}));return{name:"slash",trigger:Wh,allowSpaces:!0,richOnly:!0,emptyLabel:this.labels.noResults,label:this.labels.commands,className:"mbe-slash-menu",items:({query:n})=>t.filter(i=>yl(i,n)),command:({range:n,item:i})=>{let r=n.from.blockId,s=N(this.current.doc,r),l=q(s)?I(s.content):"",a=n.to.offset,d=a===l.length&&l[n.from.offset-1]===" "?n.from.offset-1:n.from.offset;this.run(u=>{let c=ye(u,{blockId:r,offset:d},{blockId:r,offset:a});return Rt(c,i.spec)})}}}get selectedBlocks(){let e=this.blockRange();return e?this.current.doc.blocks.slice(e.from,e.to+1):[]}blockRange(){if(!this.blockSel)return null;let e=this.current.doc,t=L(e,this.blockSel.anchor),n=L(e,this.blockSel.head);return t<0||n<0?null:this.wholeSections({from:Math.min(t,n),to:Math.max(t,n)})}wholeSections(e){let t=this.current.doc.blocks,{from:n,to:i}=e;if(!t.some(r=>r.type==="details"))return e;for(let r=!0;r;){r=!1;for(let s=n;s<=i;s++){let l=t[s];if(l.type==="details"){let a=At(t,s)??s;a>i&&(i=a,r=!0)}else if(l.type==="detailsEnd"){let a=si(t,s);a!==null&&a<n&&(n=a,r=!0)}}}return{from:n,to:i}}nextSelectable(e,t){let n=this.current.doc.blocks;for(let i=e+t;i>=0&&i<n.length;i+=t){let r=n[i];if(r.type!=="detailsEnd"&&!this.renderer.elementFor(r.id)?.hasAttribute("data-section-hidden"))return r.id}return n[e].id}selectBlockRange(e,t){this.blockSel={anchor:e,head:t},this.current={...this.current,selection:an(this.current.doc.blocks,this.blockRange()),storedMarks:null},this.history.breakGroup(),this.suggestions.close(),this.toolbar?.hide(),this.imageToolbar?.hide(),this.blockMenu.hide(),this.refreshRevealed(),this.paintBlockSelection(),this.syncDomSelection(!0),this.updateUi(),this.emit("selectionChange",{editor:this})}dropBlockSelection(){let e=this.parkedCaret();e&&(this.blockSel=null,this.current={...this.current,selection:{anchor:e,focus:e},storedMarks:null},this.paintBlockSelection())}exitBlockSelection(e){this.blockSel=null,this.paintBlockSelection(),this.setSelection({anchor:e,focus:e})}parkedCaret(){if(!this.blockSel)return null;let e=this.current.doc.blocks.find(t=>t.id===this.blockSel.head);return e?V(e):null}paintBlockSelection(){let e=this.blockRange(),t=[];if(e)for(let n of this.current.doc.blocks.slice(e.from,e.to+1)){let i=this.renderer.elementFor(n.id);i&&t.push(i)}for(let n of this.selectedEls)t.includes(n)||n.classList.remove("mbe-block-selected");for(let n of t)n.classList.add("mbe-block-selected");this.selectedEls=t,this.root.classList.toggle("mbe-block-selecting",t.length>0)}deleteSelectedBlocks(){let e=this.blockRange();e&&(this.blockSel=null,this.run(t=>jn(t,e)))}onBlockKey(e){let t=this.blockRange();if(!t)return!1;let n=this.state.doc.blocks,i=!e.metaKey&&!e.ctrlKey&&!e.altKey,r=ie?e.metaKey:e.ctrlKey;switch(e.key){case"Escape":return!i||e.shiftKey?!1:(this.dropBlockSelection(),this.blur(),!0);case"ArrowUp":case"ArrowDown":{if(!i)return!1;let s=e.key==="ArrowUp";if(e.shiftKey){let l=L(this.current.doc,this.blockSel.head);!s&&n[l]?.type==="details"&&(l=At(n,l)??l),this.selectBlockRange(this.blockSel.anchor,this.nextSelectable(l,s?-1:1))}else{let l=this.nextSelectable(s?t.from:t.to,s?-1:1);this.selectBlockRange(l,l)}return!0}case"ArrowLeft":case"ArrowRight":return!i||e.shiftKey?!1:(this.exitBlockSelection(e.key==="ArrowLeft"?V(n[t.from]):P(n[t.to])),!0);case"Enter":return!i||e.shiftKey?!1:(this.exitBlockSelection(P(n[t.to])),!0);case"Backspace":case"Delete":return i?(this.deleteSelectedBlocks(),!0):!1}if(r&&!e.altKey&&!e.shiftKey){let s=e.key.toLowerCase();if(s==="a")return this.selectBlockRange(n[0].id,n[n.length-1].id),!0;if(s==="d"){let l=t.to-t.from+1;if(this.run(a=>ui(a,t))){let a=this.current.doc.blocks;this.selectBlockRange(a[t.to+1].id,a[t.to+l].id)}return!0}}return!1}icon(e){return this.options.icons?.[e]??fs(this.root.ownerDocument,e)}blockMenuSections(e){let t=N(this.state.doc,e),n=[],i=this.state.selection.focus.cell;if(t.type==="table"&&this.state.selection.focus.blockId===e&&i){let l=Uh.map(({id:d,action:u})=>({id:d,label:this.labels[d],icon:this.icon(d),run:()=>this.run(c=>Zn(c,u))})),a=t.align[i.col]??"left";l.splice(4,0,this.alignMenuItem("align",a,d=>({icon:this.icon(d.id),run:()=>this.run(u=>Zn(u,{kind:"align",align:d.align}))}))),n.push({title:this.labels.tableSection,items:l})}let r=M(t);if(r&&r!=="quote"){let l=r,a=Ve.map(d=>{let u=Br(d);return{id:u,label:this.labels[u],icon:this.icon(u),checked:d===l,run:()=>this.run(c=>sn(c,e,d))}});return n.push({title:this.labels.callout,items:a}),n.push({items:[{id:"delete",label:this.labels.delete,icon:this.icon("delete"),danger:!0,run:()=>this.run(d=>{let u=Nt(d,e);return u?jn(d,{from:u.start,to:u.end}):null})}]}),n}let s=Y(t);if(s!==null){let l={blockId:e,offset:s},a=C(t.content,s,s+1)[0].image,d=[this.alignMenuItem("imageAlignLeft",a.align??"left",u=>({icon:this.icon(u.image),run:()=>this.updateImageAt(l,{align:u.align==="left"?null:u.align})})),{id:"altText",label:this.labels.altText,icon:this.icon("altText"),run:()=>this.editAltText(l,a.alt)}];a.width&&d.push({id:"resetImageSize",label:this.labels.resetImageSize,icon:this.icon("resetImageSize"),run:()=>this.updateImageAt(l,{width:null})}),n.push({title:this.labels.imageSection,items:d})}return n.push({items:[{id:"duplicate",label:this.labels.duplicate,icon:this.icon("duplicate"),run:()=>this.run(l=>di(l,e))},{id:"delete",label:this.labels.delete,icon:this.icon("delete"),danger:!0,run:()=>this.run(l=>Bt(l,e))}]}),n}alignMenuItem(e,t,n){return{id:"align",label:this.labels.align,icon:this.icon(e),run:()=>{},submenu:{title:this.labels.align,items:zh.map(i=>({id:i.id,label:this.labels[i.id],checked:t===i.align,...n(i)}))}}}hasBlockMenu(e){if(this.modeValue==="source")return!1;let t=this.state.doc.blocks.find(n=>n.id===e);return t?.type==="table"||t?.type==="code"||Da(t)||!!t&&jr(t)}blockMenuOwner(e){if(!this.hasBlockMenu(e))return null;let t=Nt(this.state,e);return t?this.state.doc.blocks[t.start].id:e}openBlockMenu(e,t){if(this.readOnly||!this.hasBlockMenu(e))return;this.dropBlockSelection(),this.suggestions.close(),this.toolbar?.hide(),this.imageToolbar?.hide();let n=Y(N(this.state.doc,e));if(n!==null)this.current=je(this.state,{blockId:e,offset:n}),this.hasFocus()||this.focus();else if(this.state.selection.focus.blockId!==e&&!this.inSameCallout(this.state.selection.focus.blockId,e)){let r=N(this.state.doc,e),s=V(r);this.current={...this.state,selection:{anchor:s,focus:s}},this.focus()}else this.hasFocus()||this.focus();this.blockMenu.setSections(this.blockMenuSections(e));let i=t??this.blockElement(e)?.getBoundingClientRect();i&&this.blockMenu.popup.show(i,"below"),this.syncActiveDescendant()}inSameCallout(e,t){let n=N(this.state.doc,t),i=Da(n)?Nt(this.state,t):null;if(!i)return!1;let r=L(this.state.doc,e);return r>=i.start&&r<=i.end}closeBlockMenu(){this.blockMenu.hide(),this.updateUi()}onDocumentPointerDown(e){let t=e.target;this.toolbar?.menu&&!(t&&this.toolbar.contains(t))&&this.toolbar.closeMenu(),this.blockMenu.isOpen&&(t&&(this.blockMenu.contains(t)||this.blockHandle.contains(t))||this.closeBlockMenu())}openLinkPopover(){if(this.readOnly||this.modeValue==="source")return!1;let e=N(this.state.doc,this.state.selection.focus.blockId);if(Q(e)||R(this.state.selection)&&!Qe(this.state))return!1;let t=this.selectionRect();if(!t)return!1;this.toolbar?.hide();let n=this.state.selection,i=Qe(this.current)?.href??"",{labels:r}=this,s={value:i,label:r.link,placeholder:r.linkPlaceholder,type:"url",removeLabel:r.removeLink};return this.inputPopover.open(t,s,l=>{this.current={...this.state,selection:n},l!==null&&this.run(a=>ut(a,l===""?null:l)),this.focus()}),!0}updateUi(){if(this.destroyed)return;this.expandAroundSelection();let e=this.hasFocus(),t=this.state.selection.focus,n=e&&!this.blockSel&&R(this.state.selection)?this.renderer.elementFor(t.blockId):void 0,i=!!this.options.placeholder&&this.state.doc.blocks.length===1,l=!!this.options.slashHint&&this.options.slashMenu!==!1&&n&&n.classList.contains("mbe-paragraph")&&n.classList.contains("mbe-empty")&&!this.readOnly&&!i?n:null;this.hintEl!==l&&(this.hintEl?.classList.remove("mbe-show-hint"),l?.classList.add("mbe-show-hint"),this.hintEl=l),this.suggestions.update(e);let a=e&&!this.readOnly&&!this.blockSel?this.imageTargetAt(this.state):null;this.paintSelectedImage(a?.el??null),this.resizeHandles.update(a);let d=this.toolbarClosedFor;if(d&&!(be(d.anchor,this.state.selection.anchor)&&be(d.focus,t))&&(this.toolbarClosedFor=null),this.imageToolbar&&(a&&!this.toolbarClosedFor&&!this.composing&&!this.suggestions.isActive&&!this.blockMenu.isOpen&&!this.inputPopover.isOpen&&!this.resizeHandles.isDragging?this.imageToolbar.show(a,ke(this.state)!==null):this.imageToolbar.hide()),this.toolbar){let u=this.state.doc.blocks.find(h=>h.id===t.blockId);!this.toolbarClosedFor&&e&&!this.readOnly&&!this.composing&&!R(this.state.selection)&&!this.blockSel&&!a&&!this.suggestions.isActive&&!this.blockMenu.isOpen&&!!u&&!Q(u)&&u.type!=="divider"?this.toolbar.show():this.toolbar.hide()}if(e&&!this.readOnly&&Ft()){let u=this.blockMenuOwner(t.blockId);u?this.blockHandle.showFor(u):this.blockHandle.hide()}!e&&this.blockMenu.isOpen&&!this.root.ownerDocument.activeElement?.closest?.(".mbe-ui")&&this.blockMenu.hide(),this.linkCard&&(this.readOnly?this.linkCard.hide():this.linkCard.setCaret(e&&!this.composing&&!this.blockSel&&!this.suggestions.isActive&&!this.blockMenu.isOpen&&!this.inputPopover.isOpen?this.caretLink():null)),this.syncActiveDescendant()}setSectionCollapsed(e,t){if(this.destroyed)return!1;let n=this.state.doc,i=L(n,e);if(n.blocks[i]?.type!=="details")return!1;if(this.collapsed.has(e)===t)return!0;if(t?this.collapsed.add(e):this.collapsed.delete(e),t){let r=At(n.blocks,i)??i,s=d=>{let u=L(n,d.blockId);return u>i&&u<=r},{anchor:l,focus:a}=this.state.selection;if(s(l)||s(a)){let d=P(n.blocks[i]);this.dropBlockSelection(),this.current={...this.current,selection:{anchor:d,focus:d},storedMarks:null},this.syncDomSelection()}}return this.renderer.updateSections(n),this.updateUi(),!0}isSectionCollapsed(e){return this.collapsed.has(e)}collapseClosedSections(e){for(let t of e.blocks)t.type==="details"&&!t.open&&this.collapsed.add(t.id)}expandAroundSelection(){if(this.collapsed.size===0)return;let e=this.state.selection.focus.blockId;if(!this.renderer.elementFor(e)?.hasAttribute("data-section-hidden"))return;let t=[];for(let n of this.state.doc.blocks){if(n.id===e)break;n.type==="details"?t.push(n.id):n.type==="detailsEnd"&&t.pop()}for(let n of t)this.collapsed.delete(n);this.renderer.updateSections(this.state.doc)}skipsCaret(e){return Z(e)||!!this.renderer.elementFor(e.id)?.hasAttribute("data-section-hidden")}caretLink(){if(!R(this.state.selection))return null;let e=Qe(this.state);if(!e||e.pos.offset<=e.from||e.pos.offset>=e.to)return null;let t=this.renderer.elementFor(e.pos.blockId);if(!t)return null;let n={...e.pos,offset:e.from};for(let i of t.querySelectorAll("a.mbe-link")){let r=this.linkStart(i);if(r&&be(r,n))return this.linkTargetOf(i)}return null}linkStart(e){return _e(this.root,e,0)}linkTargetOf(e){if(e.closest(".mbe-flow"))return null;let t=this.linkStart(e);if(!t)return null;let n=this.state.doc.blocks.find(s=>s.id===t.blockId),i=n&&F(n,t.cell),r=i&&Xt(i,t.offset);return r&&r.from===t.offset?{el:e,href:r.href}:null}linkSelection(e){let t=this.linkStart(e.el);if(!t)return null;let n=N(this.state.doc,t.blockId),i=F(n,t.cell),r=i&&Xt(i,t.offset);return r?{anchor:t,focus:{...t,offset:r.to}}:null}editLink(e){let t=this.linkSelection(e);!t||this.readOnly||(this.focus(),this.setSelection(t),this.openLinkPopover())}removeLink(e){let t=this.linkSelection(e);!t||this.readOnly||this.run(n=>({...ut({...n,selection:t},null),selection:n.selection}))}paintSelectedImage(e){this.selectedImageEl!==e&&(this.selectedImageEl?.classList.remove("mbe-image-selected"),e?.classList.add("mbe-image-selected"),this.selectedImageEl=e),this.root.classList.toggle("mbe-image-selection",e!==null)}imageTargetAt(e){let t=De(e);if(!t)return null;let n=this.renderer.elementFor(t.pos.blockId),i=n?ma(n,t.pos):null;return i?.classList.contains("mbe-image")?{el:i,...t}:null}imageTarget(e){if(!e.parentNode||!this.root.contains(e))return null;let t=_e(this.root,e.parentNode,xt(e));if(!t)return null;let n=je(this.current,t),i=n===this.current?null:De(n);return i?{el:e,...i}:null}selectImageAt(e){if(this.readOnly||this.destroyed)return;let t=je(this.current,e);t!==this.current&&(this.hasFocus()||this.root.focus({preventScroll:!0}),this.setSelection(t.selection))}updateImageAt(e,t){this.run(n=>Un(n,e,t))}editAltText(e,t){let n=(this.imageTargetAt(this.state)?.el??this.blockElement(e.blockId))?.getBoundingClientRect();if(!n)return;this.imageToolbar?.hide();let{labels:i}=this,r={value:t,label:i.altText,placeholder:i.altTextPlaceholder,type:"text"};this.inputPopover.open(n,r,s=>{s!==null?this.updateImageAt(e,{alt:s}):this.current=je(this.state,e),this.focus()})}deleteImageAt(e){this.run(t=>{let n=je(t,e);return n===t?null:ke(n)?Bt(n,e.blockId):J(n)})}refreshImageUi(){this.updateUi()}syncActiveDescendant(){let e=this.blockMenu.isOpen?this.blockMenu:this.toolbar?.menu,t=this.suggestions.activeDescendant??e?.activeDescendant??null;t?this.root.setAttribute("aria-activedescendant",t):this.root.removeAttribute("aria-activedescendant")}hideUi(){this.dropBlockSelection(),this.suggestions.close(),this.blockMenu.hide(),this.toolbar?.hide(),this.imageToolbar?.hide(),this.blockHandle.hide(),this.linkCard?.setCaret(null),this.resizeHandles.hide(),this.paintSelectedImage(null),this.hintEl?.classList.remove("mbe-show-hint"),this.hintEl=null}typed(e){return t=>{this.typing++;try{e(t)}finally{this.typing--}}}listen(e,t,n,i=!1){e.addEventListener(t,n,i),this.cleanup.push(()=>e.removeEventListener(t,n,i))}};function Da(o){let e=M(o);return e!==null&&e!=="quote"}function Oa(o){switch(o.type){case"listItem":return o.listType==="bullet"?"bulletList":o.listType==="ordered"?"orderedList":"taskList";case"quote":return"blockquote";case"code":return"codeBlock";case"detailsEnd":return"details";default:return o.type}}function Ha(o,e,t,n=t){o.setData("text/plain",n),o.setData("text/html",`<meta charset="utf-8"><div data-mbe-markdown="${encodeURIComponent(t)}">${dn(e)}</div>`)}var Qh=/^(?:[a-z][a-z0-9+.-]*:\/\/|mailto:)\S+$/i;function Pa(o){let e=/data-mbe-markdown="([^"]*)"/.exec(o);return e?decodeURIComponent(e[1]):null}function jh(o,e){return o.blocks.length===e.blocks.length&&o.blocks.every((t,n)=>t===e.blocks[n])}function Gh(o){return typeof o.anchor?.blockId=="string"}function Zh(o,e){let t=r=>{if(!r||typeof r!="object")return null;let{block:s,offset:l,cell:a}=r;if(!Number.isInteger(s)||!Number.isInteger(l))return null;let d=Math.max(0,Math.min(s,o.blocks.length-1)),u=o.blocks[d];if(s>=o.blocks.length)return P(u);if(u.type==="table"){let c=a&&typeof a=="object"?a:{},h=Number.isInteger(c.row)?Math.max(0,Math.min(c.row,u.rows.length-1)):0,f=Number.isInteger(c.col)?Math.max(0,Math.min(c.col,u.rows[0].length-1)):0;return{blockId:u.id,offset:Math.max(0,l),cell:{row:h,col:f}}}return{blockId:u.id,offset:Math.max(0,l)}};if(!e||typeof e!="object")return null;let n=t(e.anchor),i=t(e.focus);return!n||!i?null:te(o,{anchor:n,focus:i})}function Xh(o,e){return o.closest("[data-block-id]")?.querySelector(".mbe-content")?.textContent?.trim()||e}function Yh(o,e){for(let t=o.parentElement;t;t=t.parentElement){let n=getComputedStyle(t).overflowY;if((n==="auto"||n==="scroll")&&t.scrollHeight>t.clientHeight){t.scrollTop+=e;return}}o.ownerDocument.defaultView?.scrollBy(0,e)}function Fa(o){switch(o.type){case"root":case"blockQuote":case"listItem":case"paragraph":case"heading":case"emphasis":case"strong":case"strike":case"link":case"image":return o.children;case"list":return o.items;case"table":return o.rows.flatMap(e=>e.flat());default:return[]}}function Jh(o,e){let t=[],n=i=>{if(e(i,t)!==!1){t.push(i);for(let r of Fa(i))n(r);t.pop()}};n(o)}function ef(o,e,t){let n=typeof o=="string"?pt(o):o,i=new xe(e,n);return{from:i.source(t.from),to:i.source(t.to)}}function qa(o){return o===void 0||/\s/.test(o)}function tf(o){return o!==void 0&&o>="0"&&o<="9"}function nf(o,e){let t=0;for(;o.charCodeAt(e-t-1)===92;)t++;return t%2===1}var of={name:"math",triggers:"$",match(o,e){if(o.charCodeAt(e-1)===36&&!nf(o,e-1))return-1;let t=e;for(;o.charCodeAt(t)===36;)t++;let n=t-e;if(n===1&&qa(o[t]))return-1;for(let i=t;i<o.length;){if(o.charCodeAt(i)!==36){i++;continue}let r=i+1;for(;o.charCodeAt(r)===36;)r++;if(r-i===n)return n===1&&(qa(o[i-1])||tf(o[r]))?-1:r;i=r}return-1}};function rf(o){let e=0;for(;o.charCodeAt(e)===36;)e++;return e>=2&&!o.includes("$",e)?e:0}var sf={name:"math",interruptsParagraph:!0,open(o){let e=rf(o);return e?{next(t){let n=t.replace(/^[ \t]+/,""),i=0;for(;n.charCodeAt(i)===36;)i++;return i>=e&&/^[ \t]*$/.test(n.slice(i))?"close":"continue"}}:null}};function lf(o,e){if(e==="inline"){let i=0;for(;o.charCodeAt(i)===36;)i++;return o.slice(i,o.length-i)}let t=o.split(`
124
124
  `),n=t.length>1&&/^[ \t]*\${2,}[ \t]*$/.test(t[t.length-1]);return t.slice(1,n?-1:void 0).join(`
125
- `)}function lf(o={}){let{render:e}=o;return{name:"math",markdown:{inline:[nf],block:[rf],escape:"$"},views:e&&{math(t,n,i){let r=sf(t,i);if(!r.trim())return!1;let s=e(r,n,{displayMode:i==="block"});if(s)return n.hasChildNodes()||(n.textContent=t),s}}}}var qr=/\[\^(?:[^\]\s\\]|\\.)+\]/y,qa=/^\[\^(?:[^\]\s\\]|\\.)+\]:/,af=/^(?:#{1,6}(?:[ \t]|$)|>|[-*+][ \t]|\d{1,9}[.)][ \t]|`{3,}|~{3,}|\$\$|<[A-Za-z/!?])/,_a={name:"footnote",triggers:"[",match(o,e){return qr.lastIndex=e,qr.test(o)?qr.lastIndex:-1}},Ka={name:"footnote",open(o){if(!qa.test(o))return null;let e=!1;return{next(t){if(/^[ \t]*$/.test(t))return e=!0,"continue";if(e)return e=!1,/^(?: {4}|\t)/.test(t)?"continue":"end";let n=t.replace(/^[ \t]+/,"");return qa.test(n)||af.test(n)?"end":"continue"}}}},Va=o=>/^\[\^((?:[^\]\\]|\\.)+)\]/.exec(o)?.[1]?.replace(/\\(.)/g,"$1")??"",cf=(o,e)=>{let t=Va(o),n=e.ownerDocument.createElement("sup");n.className="mbe-footnote-ref",n.dataset.label=t,n.textContent=t,e.appendChild(n)},df=(o,e)=>{let t=Va(o),n=e.ownerDocument;e.classList.add("mbe-footnote"),e.dataset.label=t;let i=n.createElement("sup");i.className="mbe-footnote-label",i.textContent=t;let r=n.createElement("span");r.textContent=o.replace(/^\[\^(?:[^\]\\]|\\.)+\]:[ \t]*/,"").split(`
126
- `).map(s=>s.trim()).filter(Boolean).join(" "),e.append(i,r)};function uf(o={}){return o.render===!1?{name:"footnotes",markdown:{inline:[_a],block:[Ka]}}:{name:"footnotes",markdown:{inline:[_a],block:[Ka]},views:{footnote:(e,t,n,i)=>(n==="inline"?cf:df)(e,t,n,i)},onCreate:({editor:e})=>{let t=n=>{if(e.isEditable)return;let i=n.target,r=i.closest?.(".mbe-footnote-ref"),s=r?null:i.closest?.(".mbe-footnote-backref");if(!r&&!s)return;let l=d=>d.closest(".mbe-footnotes")!==null,a;if(r){let d=[...e.root.querySelectorAll(".mbe-footnote")].filter(u=>u.dataset.label===r.dataset.label);a=d.find(l)??d[0]}else s&&(a=[...e.root.querySelectorAll(".mbe-footnote-ref")].filter(u=>u.dataset.label===s.dataset.label&&!l(u))[Number(s.dataset.ref)-1]);a&&(n.preventDefault(),a.scrollIntoView({block:"center",behavior:"smooth"}))};return e.root.addEventListener("click",t),()=>e.root.removeEventListener("click",t)}}}function hf(o){let e=o.pattern&&new RegExp(o.pattern.source,o.pattern.flags.includes("g")?o.pattern.flags:o.pattern.flags+"g");return{name:o.name??"textDecorator",decorations({text:t,excluded:n}){let i=[],r=(s,l,a=o.class,d=o.attributes)=>{l>s&&!es(s,l,n)&&i.push(d?{from:s,to:l,class:a,attributes:d}:{from:s,to:l,class:a})};if(e)for(let s of t.matchAll(e))r(s.index,s.index+s[0].length);if(o.scan)for(let s of o.scan(t))r(s.from,s.to,s.class,s.attributes??o.attributes);return i}}}var ja=/\p{XID_Continue}/u,_r=/\p{Default_Ignorable_Code_Point}/u,Kr=/[\p{Mn}\p{Mc}]/u,ff="\u3003\uFF5E\u301C\u05BE\u05F3\u05F4\u0F0B",Ua=String.raw`(?:\p{Emoji_Modifier_Base}\p{Emoji_Modifier}|(?![\p{Regional_Indicator}\p{Emoji_Modifier}])\p{Emoji_Presentation}\uFE0F?|(?![#*0-9])\p{Emoji}\uFE0F|(?!\p{Emoji})(?=\P{Assigned})\p{Extended_Pictographic})`,za=new RegExp(String.raw`[#*0-9]\uFE0F\u20E3|\p{Regional_Indicator}{2}|\u{1F3F4}[\u{E0020}-\u{E007E}]+\u{E007F}|${Ua}(?:\u200D${Ua})*`,"uy");function Uo(o,e){return String.fromCodePoint(o.codePointAt(e))}function zo(o,e,t){za.lastIndex=e;let n=za.exec(o);return n&&e+n[0].length<=t?n[0].length:0}var Nn=o=>ja.test(o)&&!_r.test(o),pf=o=>o==="-"||o==="+"||o==="&"||Nn(o)&&!Kr.test(o),mf=o=>o==="-"||o==="+"||o==="&"||ff.includes(o)||Nn(o);function Wa(o,e,t){let n=e;for(;;){if(n>=t)return-1;let r=zo(o,n,t);if(r>0){n+=r;break}let s=Uo(o,n);if(n+s.length>t)return-1;if(_r.test(s)||ja.test(s)&&Kr.test(s)){n+=s.length;continue}if(!pf(s))return-1;n+=s.length;break}let i=n>e&&Nn(bf(o,n));for(;n<t;){let r=zo(o,n,t);if(r>0){n+=r,i=!1;continue}let s=Uo(o,n);if(n+s.length>t)break;if(_r.test(s))n+=s.length,i=!1;else if((s==="'"||s==="\u2019")&&i&&gf(o,n+1,t))n+=1,i=!1;else if(mf(s))n+=s.length,i=Nn(s);else break}return n}function gf(o,e,t){if(e>=t||zo(o,e,t)>0)return!1;let n=Uo(o,e);return Nn(n)&&!Kr.test(n)}function bf(o,e){if(e<=0)return;let t=o.charCodeAt(e-1);return t>=56320&&t<=57343&&e>1?o.slice(e-2,e):o[e-1]}function*Ga(o,e=0,t=o.length){let n=e;for(;n<t;){let i=zo(o,n,t);if(i>0){n+=i;continue}if(o[n]!=="#"){n+=Uo(o,n).length;continue}let r=Wa(o,n+1,t);if(r<0){n++;continue}for(;o[r]==="/";){let s=Wa(o,r+1,t);if(s<0)break;r=s}yield{from:n,to:r},n=r}}var Qa=/[A-Za-z0-9-]/,yf=/[\u00c0-\u00d6\u00d8-\u00f6\u00f8-\u024f\u0253\u0254\u0256\u0257\u0259\u025b\u0263\u0268\u026f\u0272\u0289\u028b\u02bb\u0300-\u036f\u1e00-\u1eff]/;function*Za(o,e=0,t=o.length){for(let n=o.indexOf("@",e);n>=0&&n<t;n=o.indexOf("@",n+1)){if(n>e&&Qa.test(o[n-1]))continue;let i=n+1;for(;i<t&&Qa.test(o[i]);)i++;let r=o.slice(n+1,i);/^[A-Za-z0-9](?:[A-Za-z0-9-]{0,34}[A-Za-z0-9])?$/.test(r)&&!yf.test(o[i]??"")&&(yield{from:n,to:i}),i>n+1&&(n=i-1)}}function kf(o,e,t,n){return({text:i,content:r})=>{let s=[],l=0;for(let a of r){let d=l+a.text.length;if(!ct(a))for(let u of o(i,l,d)){let c=Math.max(u.from,l),h=Math.min(u.to,d);if(h<=c)continue;let f=i.slice(c,h),p=typeof e=="function"?e(f):e,m=typeof t=="function"?t(f):t,y=n?{...m,[n]:f}:m;s.push(y?{from:c,to:h,class:p,attributes:y}:{from:c,to:h,class:p})}l=d}return s}}function vf(o){return{name:"escape",triggers:"\\",match:(e,t)=>e[t+1]===o?t+2:-1}}function Xa(o,e,t,n,i,r){let s=r.onClick,l={name:o,markdown:{inline:[vf(e)]},decorations:kf(r.scan??t,r.class??n,r.attributes,s?i:void 0)};return s?{...l,onCreate:({editor:a})=>{let d=u=>{let c=u.target.closest?.(`[${i}]`);!c||!a.root.contains(c)||a.isEditable&&!(ie?u.metaKey:u.ctrlKey)||s({editor:a,match:c.getAttribute(i),event:u})&&(u.preventDefault(),u.stopPropagation())};return a.root.addEventListener("click",d),()=>a.root.removeEventListener("click",d)}}:l}function xf(o={}){return Xa("tags","#",Ga,"mbe-tag","data-mbe-tag",o)}function wf(o={}){return Xa("mentions","@",Za,"mbe-mention","data-mbe-mention",o)}function Sf(o){return{name:o.name,suggestion:o}}function Tf(o){let e=n=>{let i=o.accept;return i?typeof i=="function"?i(n):i.some(r=>r.endsWith("/*")?n.type.startsWith(r.slice(0,-1)):n.type===r):!0},t=n=>Array.from(n?.files??[]).filter(e);return{name:"fileHandler",handlePaste:({editor:n,event:i})=>{if(!o.onPaste||i.clipboardData?.getData("text/plain"))return!1;let r=t(i.clipboardData);return r.length===0?!1:(o.onPaste({editor:n,files:r,event:i}),!0)},handleDrop:({editor:n,event:i,position:r})=>{if(!o.onDrop)return!1;let s=t(i.dataTransfer);return s.length===0?!1:(o.onDrop({editor:n,files:s,event:i,position:r}),!0)}}}export{Ke as ATOM_CHAR,Ve as CALLOUT_TYPES,Mi as DEFAULT_LABELS,Fr as Editor,et as MARK_ORDER,tt as MAX_INDENT,Pa as SLASH_ITEM_IDS,Xl as TOOLBAR_ITEMS,L as blockIndex,$ as caret,te as clampSelection,Ee as codeBlock,wi as commands,oc as comparePositions,ce as concatInline,F as containerContent,ee as createId,Hn as createState,rr as defaultKeymap,Ln as defaultResolveUrl,st as deleteInline,St as details,Tt as detailsEnd,it as divider,dn as docToHtml,Qr as emptyTable,P as endOf,Tf as fileHandler,uf as footnotes,Gt as formatAt,N as getBlock,nt as heading,Dn as htmlBlock,no as htmlToDoc,Y as imageBlockOffset,B as inlineLength,Mf as inlineLines,ro as inlineNodesText,I as inlineText,Gr as insertInline,R as isCollapsed,jr as isImageBlock,Q as isPlainTextBlock,Wt as isQuotable,q as isTextBlock,Z as isTextless,Re as keepQuoteStart,pt as lineTable,Xt as linkAt,Ue as listItem,Le as loadMarkdown,nc as marksAt,qu as matchToken,lf as math,wf as mentions,$a as nodeChildren,G as normalizeInline,Me as orderedRange,O as paragraph,he as parseAst,mn as parseInline,bt as parseMarkdown,ft as pieceEnd,ge as plain,Ne as quote,M as quoteKind,jo as rangeHasMark,ot as rawBlock,de as sameCell,ae as sameLink,jt as sameMarks,be as samePosition,oe as sameQuote,Za as scanMentions,Ga as scanTags,Xd as serializeInline,Pt as serializeMarkdown,Go as setLinkInRange,Zt as setMarkInRange,Zr as setTokenInRange,C as sliceInline,rt as sortMarks,Jh as sourceRange,V as startOf,Et as startsQuote,Sf as suggestion,zt as table,xf as tags,hf as textDecorator,Ct as toPlain,Xr as tokensAt,Mt as unquote,Yh as visit,ze as withContainerContent,z as withContent,U as withQuote,Qt as withQuoteStart,On as withoutQuoteStart};
125
+ `)}function af(o={}){let{render:e}=o;return{name:"math",markdown:{inline:[of],block:[sf],escape:"$"},views:e&&{math(t,n,i){let r=lf(t,i);if(!r.trim())return!1;let s=e(r,n,{displayMode:i==="block"});if(s)return n.hasChildNodes()||(n.textContent=t),s}}}}var qr=/\[\^(?:[^\]\s\\]|\\.)+\]/y,_a=/^\[\^(?:[^\]\s\\]|\\.)+\]:/,cf=/^(?:#{1,6}(?:[ \t]|$)|>|[-*+][ \t]|\d{1,9}[.)][ \t]|`{3,}|~{3,}|\$\$|<[A-Za-z/!?])/,Ka={name:"footnote",triggers:"[",match(o,e){return qr.lastIndex=e,qr.test(o)?qr.lastIndex:-1}},Va={name:"footnote",open(o){if(!_a.test(o))return null;let e=!1;return{next(t){if(/^[ \t]*$/.test(t))return e=!0,"continue";if(e)return e=!1,/^(?: {4}|\t)/.test(t)?"continue":"end";let n=t.replace(/^[ \t]+/,"");return _a.test(n)||cf.test(n)?"end":"continue"}}}},Ua=o=>/^\[\^((?:[^\]\\]|\\.)+)\]/.exec(o)?.[1]?.replace(/\\(.)/g,"$1")??"",df=(o,e)=>{let t=Ua(o),n=e.ownerDocument.createElement("sup");n.className="mbe-footnote-ref",n.dataset.label=t,n.textContent=t,e.appendChild(n)},uf=(o,e)=>{let t=Ua(o),n=e.ownerDocument;e.classList.add("mbe-footnote"),e.dataset.label=t;let i=n.createElement("sup");i.className="mbe-footnote-label",i.textContent=t;let r=n.createElement("span");r.textContent=o.replace(/^\[\^(?:[^\]\\]|\\.)+\]:[ \t]*/,"").split(`
126
+ `).map(s=>s.trim()).filter(Boolean).join(" "),e.append(i,r)};function hf(o={}){return o.render===!1?{name:"footnotes",markdown:{inline:[Ka],block:[Va]}}:{name:"footnotes",markdown:{inline:[Ka],block:[Va]},views:{footnote:(e,t,n,i)=>(n==="inline"?df:uf)(e,t,n,i)},onCreate:({editor:e})=>{let t=n=>{if(e.isEditable)return;let i=n.target,r=i.closest?.(".mbe-footnote-ref"),s=r?null:i.closest?.(".mbe-footnote-backref");if(!r&&!s)return;let l=d=>d.closest(".mbe-footnotes")!==null,a;if(r){let d=[...e.root.querySelectorAll(".mbe-footnote")].filter(u=>u.dataset.label===r.dataset.label);a=d.find(l)??d[0]}else s&&(a=[...e.root.querySelectorAll(".mbe-footnote-ref")].filter(u=>u.dataset.label===s.dataset.label&&!l(u))[Number(s.dataset.ref)-1]);a&&(n.preventDefault(),a.scrollIntoView({block:"center",behavior:"smooth"}))};return e.root.addEventListener("click",t),()=>e.root.removeEventListener("click",t)}}}function ff(o){let e=o.pattern&&new RegExp(o.pattern.source,o.pattern.flags.includes("g")?o.pattern.flags:o.pattern.flags+"g");return{name:o.name??"textDecorator",decorations({text:t,excluded:n}){let i=[],r=(s,l,a=o.class,d=o.attributes)=>{l>s&&!es(s,l,n)&&i.push(d?{from:s,to:l,class:a,attributes:d}:{from:s,to:l,class:a})};if(e)for(let s of t.matchAll(e))r(s.index,s.index+s[0].length);if(o.scan)for(let s of o.scan(t))r(s.from,s.to,s.class,s.attributes??o.attributes);return i}}}var Ga=/\p{XID_Continue}/u,_r=/\p{Default_Ignorable_Code_Point}/u,Kr=/[\p{Mn}\p{Mc}]/u,pf="\u3003\uFF5E\u301C\u05BE\u05F3\u05F4\u0F0B",za=String.raw`(?:\p{Emoji_Modifier_Base}\p{Emoji_Modifier}|(?![\p{Regional_Indicator}\p{Emoji_Modifier}])\p{Emoji_Presentation}\uFE0F?|(?![#*0-9])\p{Emoji}\uFE0F|(?!\p{Emoji})(?=\P{Assigned})\p{Extended_Pictographic})`,Wa=new RegExp(String.raw`[#*0-9]\uFE0F\u20E3|\p{Regional_Indicator}{2}|\u{1F3F4}[\u{E0020}-\u{E007E}]+\u{E007F}|${za}(?:\u200D${za})*`,"uy");function Uo(o,e){return String.fromCodePoint(o.codePointAt(e))}function zo(o,e,t){Wa.lastIndex=e;let n=Wa.exec(o);return n&&e+n[0].length<=t?n[0].length:0}var Nn=o=>Ga.test(o)&&!_r.test(o),mf=o=>o==="-"||o==="+"||o==="&"||Nn(o)&&!Kr.test(o),gf=o=>o==="-"||o==="+"||o==="&"||pf.includes(o)||Nn(o);function Qa(o,e,t){let n=e;for(;;){if(n>=t)return-1;let r=zo(o,n,t);if(r>0){n+=r;break}let s=Uo(o,n);if(n+s.length>t)return-1;if(_r.test(s)||Ga.test(s)&&Kr.test(s)){n+=s.length;continue}if(!mf(s))return-1;n+=s.length;break}let i=n>e&&Nn(yf(o,n));for(;n<t;){let r=zo(o,n,t);if(r>0){n+=r,i=!1;continue}let s=Uo(o,n);if(n+s.length>t)break;if(_r.test(s))n+=s.length,i=!1;else if((s==="'"||s==="\u2019")&&i&&bf(o,n+1,t))n+=1,i=!1;else if(gf(s))n+=s.length,i=Nn(s);else break}return n}function bf(o,e,t){if(e>=t||zo(o,e,t)>0)return!1;let n=Uo(o,e);return Nn(n)&&!Kr.test(n)}function yf(o,e){if(e<=0)return;let t=o.charCodeAt(e-1);return t>=56320&&t<=57343&&e>1?o.slice(e-2,e):o[e-1]}function*Za(o,e=0,t=o.length){let n=e;for(;n<t;){let i=zo(o,n,t);if(i>0){n+=i;continue}if(o[n]!=="#"){n+=Uo(o,n).length;continue}let r=Qa(o,n+1,t);if(r<0){n++;continue}for(;o[r]==="/";){let s=Qa(o,r+1,t);if(s<0)break;r=s}yield{from:n,to:r},n=r}}var ja=/[A-Za-z0-9-]/,kf=/[\u00c0-\u00d6\u00d8-\u00f6\u00f8-\u024f\u0253\u0254\u0256\u0257\u0259\u025b\u0263\u0268\u026f\u0272\u0289\u028b\u02bb\u0300-\u036f\u1e00-\u1eff]/;function*Xa(o,e=0,t=o.length){for(let n=o.indexOf("@",e);n>=0&&n<t;n=o.indexOf("@",n+1)){if(n>e&&ja.test(o[n-1]))continue;let i=n+1;for(;i<t&&ja.test(o[i]);)i++;let r=o.slice(n+1,i);/^[A-Za-z0-9](?:[A-Za-z0-9-]{0,34}[A-Za-z0-9])?$/.test(r)&&!kf.test(o[i]??"")&&(yield{from:n,to:i}),i>n+1&&(n=i-1)}}function vf(o,e,t,n){return({text:i,content:r})=>{let s=[],l=0;for(let a of r){let d=l+a.text.length;if(!ct(a))for(let u of o(i,l,d)){let c=Math.max(u.from,l),h=Math.min(u.to,d);if(h<=c)continue;let f=i.slice(c,h),p=typeof e=="function"?e(f):e,m=typeof t=="function"?t(f):t,y=n?{...m,[n]:f}:m;s.push(y?{from:c,to:h,class:p,attributes:y}:{from:c,to:h,class:p})}l=d}return s}}function xf(o){return{name:"escape",triggers:"\\",match:(e,t)=>e[t+1]===o?t+2:-1}}function Ya(o,e,t,n,i,r){let s=r.onClick,l={name:o,markdown:{inline:[xf(e)]},decorations:vf(r.scan??t,r.class??n,r.attributes,s?i:void 0)};return s?{...l,onCreate:({editor:a})=>{let d=u=>{let c=u.target.closest?.(`[${i}]`);!c||!a.root.contains(c)||a.isEditable&&!(ie?u.metaKey:u.ctrlKey)||s({editor:a,match:c.getAttribute(i),event:u})&&(u.preventDefault(),u.stopPropagation())};return a.root.addEventListener("click",d),()=>a.root.removeEventListener("click",d)}}:l}function wf(o={}){return Ya("tags","#",Za,"mbe-tag","data-mbe-tag",o)}function Sf(o={}){return Ya("mentions","@",Xa,"mbe-mention","data-mbe-mention",o)}function Tf(o){return{name:o.name,suggestion:o}}function Ef(o){let e=n=>{let i=o.accept;return i?typeof i=="function"?i(n):i.some(r=>r.endsWith("/*")?n.type.startsWith(r.slice(0,-1)):n.type===r):!0},t=n=>Array.from(n?.files??[]).filter(e);return{name:"fileHandler",handlePaste:({editor:n,event:i})=>{if(!o.onPaste||i.clipboardData?.getData("text/plain"))return!1;let r=t(i.clipboardData);return r.length===0?!1:(o.onPaste({editor:n,files:r,event:i}),!0)},handleDrop:({editor:n,event:i,position:r})=>{if(!o.onDrop)return!1;let s=t(i.dataTransfer);return s.length===0?!1:(o.onDrop({editor:n,files:s,event:i,position:r}),!0)}}}export{Ke as ATOM_CHAR,Ve as CALLOUT_TYPES,Mi as DEFAULT_LABELS,Fr as Editor,et as MARK_ORDER,tt as MAX_INDENT,$a as SLASH_ITEM_IDS,Xl as TOOLBAR_ITEMS,L as blockIndex,$ as caret,te as clampSelection,Ee as codeBlock,wi as commands,ic as comparePositions,ce as concatInline,F as containerContent,ee as createId,Hn as createState,rr as defaultKeymap,Ln as defaultResolveUrl,st as deleteInline,St as details,Tt as detailsEnd,it as divider,dn as docToHtml,Qr as emptyTable,P as endOf,Ef as fileHandler,hf as footnotes,Gt as formatAt,N as getBlock,nt as heading,Dn as htmlBlock,no as htmlToDoc,Y as imageBlockOffset,B as inlineLength,Cf as inlineLines,ro as inlineNodesText,I as inlineText,Gr as insertInline,R as isCollapsed,jr as isImageBlock,Q as isPlainTextBlock,Wt as isQuotable,q as isTextBlock,Z as isTextless,Re as keepQuoteStart,pt as lineTable,Xt as linkAt,Ue as listItem,Le as loadMarkdown,oc as marksAt,_u as matchToken,af as math,Sf as mentions,Fa as nodeChildren,G as normalizeInline,Me as orderedRange,D as paragraph,he as parseAst,mn as parseInline,bt as parseMarkdown,ft as pieceEnd,ge as plain,Ne as quote,M as quoteKind,jo as rangeHasMark,ot as rawBlock,de as sameCell,ae as sameLink,jt as sameMarks,be as samePosition,oe as sameQuote,Xa as scanMentions,Za as scanTags,Yd as serializeInline,Pt as serializeMarkdown,Go as setLinkInRange,Zt as setMarkInRange,Zr as setTokenInRange,C as sliceInline,rt as sortMarks,ef as sourceRange,V as startOf,Et as startsQuote,Tf as suggestion,zt as table,wf as tags,ff as textDecorator,Ct as toPlain,Xr as tokensAt,Mt as unquote,Jh as visit,ze as withContainerContent,z as withContent,U as withQuote,Qt as withQuoteStart,On as withoutQuoteStart};
127
127
  /*! Icons from Lucide (lucide-static 1.55.0), https://lucide.dev
128
128
  * ISC License. Copyright (c) 2026 Lucide Icons and Contributors.
129
129
  * Permission to use, copy, modify, and/or distribute this software for any