@meowdown/core 0.43.1 → 0.44.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.d.ts +1 -0
- package/dist/index.js +18 -18
- package/package.json +1 -1
package/dist/index.d.ts
CHANGED
package/dist/index.js
CHANGED
|
@@ -1,32 +1,32 @@
|
|
|
1
|
-
import{Priority as e,Priority as t,createMarkBuilders as n,createNodeBuilders as r,defineBaseCommands as i,defineBaseKeymap as a,defineClipboardSerializer as o,defineCommands as s,defineDOMEventHandler as c,defineHistory as l,defineKeymap as u,defineMarkSpec as d,defineMarkView as f,defineNodeAttr as p,defineNodeSpec as m,definePlugin as h,getMarkRange as ee,getMarkType as te,getNodeType as ne,isAllSelection as re,isApple as ie,isAtBlockStart as ae,isNodeSelection as oe,isTextSelection as g,toggleNode as se,union as _,unsetBlockType as ce,withPriority as le,withPriority as v,withSkipCodeBlock as ue}from"@prosekit/core";import{defineCodeBlock as de,defineCodeBlockHighlight as fe,defineCodeBlockPreviewPlugin as pe,isCodeBlockPreviewHiddenDecoration as me}from"@prosekit/extensions/code-block";import{definePlaceholder as he}from"@prosekit/extensions/placeholder";import{defineReadonly as ge}from"@prosekit/extensions/readonly";import{isElementLike as _e,once as ve}from"@ocavue/utils";import{defineBlockquote as ye}from"@prosekit/extensions/blockquote";import{defineDoc as be}from"@prosekit/extensions/doc";import{defineGapCursor as xe}from"@prosekit/extensions/gap-cursor";import{defineModClickPrevention as Se}from"@prosekit/extensions/mod-click-prevention";import{defineText as Ce}from"@prosekit/extensions/text";import{defineVirtualSelection as we}from"@prosekit/extensions/virtual-selection";import{NodeSelection as Te,Plugin as y,PluginKey as b,Selection as Ee,TextSelection as x}from"@prosekit/pm/state";import{Decoration as
|
|
2
|
-
`)}function zt(e){return Vt(e,void 0)}function Bt(e){return Vt(e,{key:`math`})}function Vt(e,t){let{selection:n}=e;if(!n.empty)return C.empty;let r=n.$head,{parent:i}=r;if(!i.isTextblock||i.type.spec.code)return C.empty;let a=ee(r,te(e.schema,`mdPack`),t);return a?C.create(e.doc,[S.inline(a.from,a.to,{class:`show`})]):C.empty}const Ht=[`mdImage`,`mdWikilink`,`mdFile`];function A(e,t){let n=k(t);return n?e.flatMap(e=>e.modes.includes(n)?[e.name]:[]):[]}function Ut(e,t,n){for(let r of n){let n=D(e,t,r);if(n)return n}}function j(e,t,n){let r=Ut(e,t,n);return r&&r.to===t?r:void 0}function M(e,t,n){let r=Ut(e,t,n);return r&&r.from===t?r:void 0}function Wt(e,t){let{from:n,to:r,empty:i}=e.selection;if(i)return;let a=Ut(e,n,t);return a&&a.from===n&&a.to===r?a:void 0}function Gt(e,t){return x.create(e.doc,t.from,t.to)}function Kt(e,t,n,r){let i=e.doc.resolve(t);if(!(r===-1?i.parentOffset===0:i.parentOffset===i.parent.content.size)||i.depth===0)return;let a=r===-1?M(e,t,n):j(e,t,n),o=r===-1?i.before():i.after(),s=Ee.findFrom(e.doc.resolve(o),r);if(!s)return;let c=g(s)?r===-1?j(e,s.head,n):M(e,s.head,n):void 0;if(!(a==null&&c==null))return s}function qt(e){return(t,n)=>{let r=A(e,t);if(r.length===0||!g(t.selection))return!1;let i=t.selection;if(i.empty){let e=M(t,i.from,r);if(e)return n?.(t.tr.setSelection(Gt(t,e))),!0;if(j(t,i.from,r)&&i.from<t.doc.resolve(i.from).end())return n?.(t.tr.setSelection(x.create(t.doc,i.from+1))),!0;let a=Kt(t,i.from,r,1);return a?(n?.(t.tr.setSelection(a).scrollIntoView()),!0):!1}let a=Wt(t,r);return a?(n?.(t.tr.setSelection(x.create(t.doc,a.to))),!0):!1}}function Jt(e){return(t,n)=>{let r=A(e,t);if(r.length===0||!g(t.selection))return!1;let i=t.selection;if(i.empty){let e=j(t,i.from,r);if(e)return n?.(t.tr.setSelection(Gt(t,e))),!0;let a=Kt(t,i.from,r,-1);return a?(n?.(t.tr.setSelection(a).scrollIntoView()),!0):!1}let a=Wt(t,r);return a?(n?.(t.tr.setSelection(x.create(t.doc,a.from))),!0):!1}}function Yt(e,t){return(n,r)=>{let i=A(e,n);if(i.length===0||!g(n.selection))return!1;let{anchor:a,head:o}=n.selection,s=t===-1?j(n,o,i):M(n,o,i);if(s){let e=t===-1?s.from:s.to;return r?.(n.tr.setSelection(x.create(n.doc,a,e)).scrollIntoView()),!0}let c=Kt(n,o,i,t);return!c||!g(c)?!1:(r?.(n.tr.setSelection(x.create(n.doc,a,c.head)).scrollIntoView()),!0)}}function Xt(e){return(t,n)=>{let r=A(e,t);if(r.length===0||!t.selection.empty)return!1;let i=t.selection.from,a=j(t,i,r);return a?(n?.(t.tr.delete(a.from,a.to)),!0):!M(t,i,r)||i<=t.doc.resolve(i).start()?!1:(n?.(t.tr.delete(i-1,i)),!0)}}function Zt(e){return(t,n)=>{let r=A(e,t);if(r.length===0||!t.selection.empty)return!1;let i=t.selection.from,a=M(t,i,r);return a?(n?.(t.tr.delete(a.from,a.to)),!0):!j(t,i,r)||i>=t.doc.resolve(i).end()?!1:(n?.(t.tr.delete(i,i+1)),!0)}}const Qt=`md-atom-selected`;function $t(e){return new y({key:new b(`atom-mark-selection`),props:{decorations:t=>{let n=A(e,t);if(n.length===0||oe(t.selection))return;let r=Wt(t,n);if(r)return C.create(t.doc,[S.inline(r.from,r.to,{class:Qt})]);let{from:i,to:a,empty:o}=t.selection;if(o)return null;let s=[];return t.doc.nodesBetween(i,a,(e,t)=>{e.marks.some(e=>n.includes(e.type.name))&&s.push(S.inline(t,t+e.nodeSize,{class:Qt}))}),C.create(t.doc,s)}}})}function en({marks:e}){return _(v(u({ArrowRight:qt(e),ArrowLeft:Jt(e),"Shift-ArrowRight":Yt(e,1),"Shift-ArrowLeft":Yt(e,-1),Backspace:Xt(e),Delete:Zt(e)}),t.high),h($t(e)))}const N=new Map,tn=new Map,nn={math:`latex`};async function rn(e){let t=N.get(e);if(t!==void 0)return t;let n=De.matchLanguageName(Oe,nn[e]??e,!0);if(!n)return N.set(e,null),null;let r=n.support;if(!r)try{r=await n.load()}catch(t){return console.error(`[meowdown] Failed to load language "${e}":`,t),N.set(e,null),null}return N.set(e,r),r}function an(e,t){let n=tn.get(e);if(n)return n;let r=je({parse:e=>t.language.parser.parse(e.content),highlighter:ke});return tn.set(e,r),r}const on=e=>{let t=e.language?.trim();if(!t)return[];let n=N.get(t);return n===null?[]:n?an(t,n)(e):rn(t).then(()=>void 0)};function sn(){return fe({parser:on,nodeTypes:[`codeBlock`]})}function cn(e,t){let n=t.language.parser.parse(e),r=[];return Ae(n,ke,(e,t,n)=>{r.push([e,t,n])}),r}function ln(e,t){let n=t.trim();if(!n)return[];let r=N.get(n);return r===null?[]:r?cn(e,r):rn(n).then(t=>t?cn(e,t):[])}function un(){return p({type:`codeBlock`,attr:`fenceStyle`,default:null,toDOM:e=>e==null?null:[`data-fence-style`,e],parseDOM:e=>{let t=e.getAttribute(`data-fence-style`);return t===`tilde`||t===`indented`||t===`dollar`?t:null}})}function dn(){return p({type:`codeBlock`,attr:`fenceLength`,default:null,toDOM:e=>e==null?null:[`data-fence-length`,String(e)],parseDOM:e=>{let t=e.getAttribute(`data-fence-length`);if(t==null)return null;let n=Number.parseInt(t,10);return Number.isSafeInteger(n)&&n>3?n:null}})}function fn(e){return{language:e[1]||``,fenceStyle:`tilde`}}function pn(){return Pe({regex:/^~~~(\S*)\s$/,type:`codeBlock`,attrs:fn})}function mn(){return Me({regex:/^~~~(\S*)$/,type:`codeBlock`,attrs:fn})}function hn(){return Me({regex:/^\$\$$/,type:`codeBlock`,attrs:()=>({language:`math`,fenceStyle:`dollar`})})}function gn(){return _(de(),un(),dn(),pn(),mn(),hn())}function _n(e,t){return(n,r)=>{if(r){let i=x.create(n.doc,e,t);r(n.tr.setSelection(i))}return!0}}function vn(e,t,n){return(r,i)=>{if(i){let a=x.between(e,t,n);i(r.tr.setSelection(a))}return!0}}function yn(e){return(t,n)=>{if(!e.trim())return!1;let r=Z(e,{nodes:Lo(t.schema)}).content;if(r.childCount===0)return!1;let i=r.childCount===1&&r.child(0).type.name===`paragraph`?new w(r,1,1):new w(r,0,w.maxOpen(r).openEnd);if(n){let e=t.tr,r=e.selection;(!g(r)||!r.empty)&&e.setSelection(x.near(r.$from)),n(e.replaceSelection(i).scrollIntoView())}return!0}}function bn(e){return(t,n)=>{if(!e)return!1;let r=t.selection.$from;if(r.parent.type.spec.code)return!1;if(n){let i=r.parentOffset,a=i===0?``:r.parent.textBetween(i-1,i),o=a!==``&&!/\s/u.test(a),s=t.tr.insertText(o?` ${e}`:e);Fe(s),n(s.scrollIntoView())}return!0}}function xn(){return(e,t)=>(t&&t(e.tr.scrollIntoView()),!0)}function Sn(){return s({insertMarkdown:yn,insertTrigger:bn,scrollIntoView:xn,selectText:_n,selectTextBetween:vn})}const Cn=(e,t,n)=>{let{selection:r}=e;return r.empty||n?.composing?!1:(t?.(e.tr.setSelection(x.near(r.$head))),!0)};function wn(){return v(u({Escape:Cn}),t.low)}function Tn(){return p({type:`doc`,attr:`frontmatter`,default:null})}function En(){return m({name:`heading`,whitespace:`pre`})}function Dn(){return p({type:`heading`,attr:`setextUnderline`,default:null,toDOM:e=>e==null?null:[`data-setext-underline`,String(e)],parseDOM:e=>{let t=e.getAttribute(`data-setext-underline`);if(t==null)return null;let n=Number.parseInt(t,10);return Number.isSafeInteger(n)&&n>0?n:null}})}function On(){return p({type:`heading`,attr:`closingHashes`,default:null,toDOM:e=>e==null?null:[`data-closing-hashes`,String(e)],parseDOM:e=>{let t=e.getAttribute(`data-closing-hashes`);if(t==null)return null;let n=Number.parseInt(t,10);return Number.isSafeInteger(n)&&n>0?n:null}})}function P(e){return ue(se({type:`heading`,attrs:{level:e}}))}const kn=(e,t,n)=>ae(e,n)?.parent.type.name===`heading`&&ce()(e,t,n);function An(){return u({"Mod-1":P(1),"Mod-2":P(2),"Mod-3":P(3),"Mod-4":P(4),"Mod-5":P(5),"Mod-6":P(6),Backspace:kn})}function jn(){return _(Be(),En(),Dn(),On(),ze(),Re(),An())}function Mn(e,t){return t(e.state,e.dispatch,e)}const Nn=new Set([`mdMark`,`mdLinkUri`,`mdLinkTitle`]);function Pn(e,t){if(t<0||t+1>e.doc.content.size)return;let n=e.doc.resolve(t),r=n.parent.maybeChild(n.index());if(!(r==null||!r.isText))return r.marks}function F(e,t){let n=Pn(e,t);return n!=null&&n.some(e=>Nn.has(e.type.name))}function Fn(e,t){if(t<0||t>e.doc.content.size)return!1;let n=e.doc.resolve(t);return n.parent.isTextblock&&!n.parent.type.spec.code}function I(e,t){if(!Fn(e,t))return;let n=e.doc.resolve(t).start(),r=t;for(;r>n&&F(e,r-1);)r--;return r<t?{from:r,to:t}:void 0}function L(e,t){if(!Fn(e,t))return;let n=e.doc.resolve(t).end(),r=t;for(;r<n&&F(e,r);)r++;return r>t?{from:t,to:r}:void 0}function In(e,t){return F(e,t-1)&&F(e,t)}function Ln(e,t){if(!In(e,t))return;let n=I(e,t),r=L(e,t);if(!(n==null||r==null))return{from:n.from,to:r.to}}function Rn(e,t,n){let r=Pn(e,t);return r!=null&&n.isInSet(r)}function zn(e,t){let n=Pn(e,t);if(n==null)return;let r=te(e.schema,`mdPack`),i=n.filter(e=>e.type===r);if(i.length===0)return;let a=e.doc.resolve(t),o=a.start(),s=a.end(),c;for(let n of i){let r=t;for(;r>o&&Rn(e,r-1,n);)r--;let i=t+1;for(;i<s&&Rn(e,i,n);)i++;(c==null||i-r<c.to-c.from)&&(c={from:r,to:i})}return c}function R(e,t,n){let r=zn(e,n===`from`?t.from:t.to-1);return r==null?!1:n===`from`?r.from===t.from:r.to===t.to}function Bn(e,t,n){let r=R(e,t,`from`),i=R(e,t,`to`);return r&&!i?t.from:i&&!r?t.to:n-t.from<=t.to-n?t.from:t.to}function Vn(e,t,n,r){if(!Fn(e,n))return n;let i=Ln(e,n);if(i!=null)return r?Bn(e,i,n):n>=t?i.to:i.from;if(!r)return n;let a=I(e,n);if(a!=null&&R(e,a,`from`))return a.from;let o=L(e,n);return o!=null&&R(e,o,`to`)?o.to:n}function Hn(e,t){if(!Fn(e,t))return;let n=F(e,t-1),r=F(e,t);if(n!==r)return r?`left`:`right`}function Un(e,t){let n=zn(e,t);if(n==null)return[];let r=L(e,n.from),i=I(e,n.to),a=[];return i!=null&&a.push(i),r!=null&&(i==null||r.from!==i.from)&&a.push(r),a}const Wn=new b(`meowdown-hidden-run-snap`),Gn=new b(`meowdown-hidden-run-beforeinput`);function Kn(){let e=!1;return new y({key:Wn,props:{handleDOMEvents:{compositionstart:()=>(e=!0,!1),compositionend:()=>(e=!1,!1)}},appendTransaction:(t,n,r)=>{if(e||k(r)!==`hide`)return null;let i=r.selection;if(!g(i))return null;let a=t.some(e=>e.getMeta(`pointer`)!=null);if(i.empty){let e=Vn(r,n.selection.head,i.head,a);return e===i.head?null:r.tr.setSelection(x.create(r.doc,e))}let o=Ln(r,i.from)?.from??i.from,s=Ln(r,i.to)?.to??i.to;if(o===i.from&&s===i.to)return null;let c=i.anchor===i.from?o:s,l=i.head===i.from?o:s;return r.tr.setSelection(x.create(r.doc,c,l))}})}const qn=(e,t)=>{if(k(e)!==`hide`)return!1;let n=e.selection;if(!g(n)||!n.empty)return!1;let r=Vn(e,n.head,n.head,!0);return r===n.head||t?.(e.tr.setSelection(x.create(e.doc,r))),!1};function Jn(e){return(t,n)=>{if(k(t)!==`hide`)return!1;let r=t.selection;if(!g(r)||!r.empty)return!1;let i=r.$head;if(!i.parent.isTextblock||i.parent.type.spec.code)return!1;let a=e===-1?I(t,r.head):L(t,r.head);if(a==null)return!1;let o=Un(t,e===-1?a.to-1:a.from),s=t.tr;if(o.length===0)s.delete(a.from,a.to);else for(let e of o)s.delete(e.from,e.to);return n?.(s),!0}}const Yn=Jn(-1),Xn=Jn(1);function Zn(){return new y({key:Gn,props:{handleDOMEvents:{beforeinput:(e,t)=>{if(e.composing)return!1;let n=t.inputType===`deleteContentBackward`?Yn:t.inputType===`deleteContentForward`?Xn:void 0;return n==null||!Mn(e,n)?!1:(t.preventDefault(),!0)}}}})}function Qn(){return _(h(Kn()),h(Zn()),v(u({Enter:qn,Backspace:Yn,Delete:Xn}),t.highest))}function $n(){return p({type:`horizontalRule`,attr:`marker`,default:null,toDOM:e=>e?[`data-hr-marker`,e]:null,parseDOM:e=>e.getAttribute(`data-hr-marker`)})}function er(){return _(Ve(),$n())}function tr(){return m({name:`htmlComment`,group:`block`,atom:!0,selectable:!1,attrs:{content:{default:``}},toDOM:e=>[`div`,{"data-html-comment":e.attrs.content,style:`display: none`}],parseDOM:[{tag:`div[data-html-comment]`,getAttrs:e=>({content:e.getAttribute(`data-html-comment`)??``})}]})}function nr(e){let[t,n,r]=e;return[t,n,r.map(e=>e.toJSON())]}function rr(e,t){let[n,r,i]=t;return[n,r,i.map(t=>Le.fromJSON(e,t))]}function ir(e,t){if(e===t)return!0;if(e.length!==t.length)return!1;for(let n=0;n<e.length;n++)if(!e[n].eq(t[n]))return!1;return!0}var z=class e extends qe{constructor(e){super(),this.chunks=e}apply(e){if(this.chunks.length===0)return Je.ok(e);let t=e.content.size,n;for(let[r,i,a]of this.chunks){if(r>=i)continue;let o=Math.max(0,Math.min(r,t)),s=Math.max(o,Math.min(i,t));if(o>=s)continue;let c=Le.setFrom(a);e.nodesBetween(o,s,(t,r)=>{if(!t.isText)return!0;let i=Math.max(o,r),a=Math.min(s,r+t.nodeSize);if(i>=a)return!1;let l=t.marks;if(ir(l,c))return!1;n??=new Ye(e);for(let e of l)n.removeMark(i,a,e);for(let e of c)n.addMark(i,a,e);return!1})}return Je.ok(n?n.doc:e)}invert(e){if(this.chunks.length===0)return ar;let t=this.chunks[0][0],n=this.chunks[0][1];for(let[,e]of this.chunks)e>n&&(n=e);let r=e.content.size,i=Math.max(0,Math.min(t,r)),a=Math.max(i,Math.min(n,r));return new Ke(i,a,e.slice(i,a),!1)}map(e){return null}toJSON(){return{stepType:`batchSetMark`,chunks:this.chunks.map(nr)}}static fromJSON(t,n){let r=n.chunks;return new e(r.map(e=>rr(t,e)))}};qe.jsonID(`batchSetMark`,z);const ar=new z([]),or=new Set([`com`,`br`,`net`,`jp`,`org`,`in`,`de`,`ru`,`it`,`fr`]),sr=/^[a-z0-9](?:[a-z0-9-]*[a-z0-9])?$/i;function cr(e){let t=e.indexOf(`/`);return t===-1?e:e.slice(0,t)}function lr(e){let t=e.split(`.`);if(t.length<2)return!1;let n=t[t.length-1].toLowerCase();if(!or.has(n)||t[t.length-2].length<3)return!1;for(let e of t)if(e.length>63||!sr.test(e))return!1;return!0}function ur(e){if(/^[a-z][a-z0-9+.-]*:/i.test(e))return e;if(/^[^\s@]+@[^\s@]+$/.test(e))return`mailto:${e}`;if(/^www\./i.test(e)||lr(cr(e)))return`https://${e}`}function B(e){return e===32||e===9||e===10||e===13}const dr=/^[a-z0-9-]+(?:\.[a-z0-9-]+)+(?:\/[^\s<]*)?/i,fr=/[\s(*_~]/;function pr(e){return e>=48&&e<=57||e>=65&&e<=90||e>=97&&e<=122||e===45}function mr(e,t,n){let r=0;for(let i=0;i<t;i++)e[i]===n&&r++;return r}function hr(e){let t=e.length;for(;;){let n=e[t-1];if(/[?!.,:*_~]/.test(n)||n===`)`&&mr(e,t,`)`)>mr(e,t,`(`))t--;else if(n===`;`){let n=/&(?:#\d+|#x[a-f\d]+|\w+);$/.exec(e.slice(0,t));if(!n)break;t=n.index}else break}return t}const gr={parseInline:[{name:`BareAutolink`,before:`Link`,parse(e,t,n){if(!pr(t)||e.hasOpenLink)return-1;let r=e.slice(n-1,n);if(r!==``&&!fr.test(r))return-1;let i=dr.exec(e.slice(n,e.end));if(!i)return-1;let a=hr(i[0]);return a===0||!lr(cr(i[0].slice(0,a)))?-1:e.addElement(e.elt(`URL`,n,n+a))}}]};function _r(e){return e>=48&&e<=57||e>=65&&e<=90||e>=97&&e<=122||e===45||e===95||e>127&&/[\p{L}\p{N}]/u.test(String.fromCharCode(e))}function vr(e){return e>=65&&e<=90||e>=97&&e<=122||e>127&&/\p{L}/u.test(String.fromCharCode(e))}const yr={defineNodes:[{name:`Hashtag`}],parseInline:[{name:`Hashtag`,parse(e,t,n){if(t!==35||!/\s|^$/.test(e.slice(n-1,n)))return-1;let r=n+1,i=!1;for(;r<e.end;){let t=e.char(r);if(!_r(t))break;i||=vr(t),r++}return i?e.addElement(e.elt(`Hashtag`,n,r)):-1}}]},br={resolve:`Highlight`,mark:`HighlightMark`},xr=/[!"#$%&'()*+,\-./:;<=>?@[\\\]^_`{|}~\u{A1}\u{2010}-\u{2027}]/u,Sr={defineNodes:[{name:`Highlight`},{name:`HighlightMark`}],parseInline:[{name:`Highlight`,after:`Emphasis`,parse(e,t,n){if(t!==61||e.char(n+1)!==61||e.char(n+2)===61)return-1;let r=e.slice(n-1,n),i=e.slice(n+2,n+3),a=/\s|^$/.test(r),o=/\s|^$/.test(i),s=xr.test(r),c=xr.test(i);return e.addDelimiter(br,n,n+2,!o&&(!c||a||s),!a&&(!s||o||c))}}]};function Cr(e){return e>=48&&e<=57}function wr(e){return e.next!==36||e.text.charCodeAt(e.pos+1)!==36||e.text.charCodeAt(e.pos+2)===36?!1:e.skipSpace(e.pos+2)===e.text.length}function Tr(e){let t=e.depth;return typeof t==`number`?t:2**53-1}const Er={defineNodes:[{name:`InlineMath`},{name:`InlineMathMark`},{name:`BlockMath`,block:!0},{name:`BlockMathMark`}],parseBlock:[{name:`BlockMath`,before:`FencedCode`,parse(e,t){if(!wr(t))return!1;let n=e.lineStart+t.pos,r=[e.elt(`BlockMathMark`,n,n+2)];for(let n=!0,i=!0,a=!1;!(!e.nextLine()||Tr(t)<e.depth);n=!1){if(wr(t)){i&&a&&r.push(e.elt(`CodeText`,e.lineStart-1,e.lineStart)),r.push(e.elt(`BlockMathMark`,e.lineStart+t.pos,e.lineStart+t.pos+2)),e.nextLine();break}a=!0,n||(r.push(e.elt(`CodeText`,e.lineStart-1,e.lineStart)),i=!1);let o=e.lineStart+t.basePos,s=e.lineStart+t.text.length;o<s&&(r.push(e.elt(`CodeText`,o,s)),i=!1)}return e.addElement(e.elt(`BlockMath`,n,e.prevLineEnd(),r)),!0},endLeaf(e,t){return wr(t)}}],parseInline:[{name:`InlineMath`,after:`InlineCode`,parse(e,t,n){if(t!==36||e.char(n-1)===36)return-1;let r=e.char(n+1)===36?2:1;if(e.char(n+r)===36)return-1;let i=n+r;if(B(e.char(i)))return-1;for(let t=i;t<e.end;t++){let a=e.char(t);if(a===10)return-1;if(a===92){t++;continue}if(a!==36)continue;let o=1;for(;e.char(t+o)===36;)o++;if(o!==r||B(e.char(t-1))||Cr(e.char(t+o)))return-1;let s=t+o;return e.addElement(e.elt(`InlineMath`,n,s,[e.elt(`InlineMathMark`,n,i),e.elt(`InlineMathMark`,t,s)]))}return-1}}]},Dr=/^[a-z][a-z0-9+.-]*:\/\/[^\s<]+/i;function Or(e){return e>=65&&e<=90||e>=97&&e<=122}const kr={parseInline:[{name:`SchemeAutolink`,after:`Autolink`,parse(e,t,n){if(!Or(t)||e.hasOpenLink)return-1;let r=e.slice(n-1,n);if(r!==``&&!fr.test(r))return-1;let i=Dr.exec(e.slice(n,e.end));if(!i)return-1;let a=hr(i[0]);return a<=i[0].indexOf(`://`)+3?-1:e.addElement(e.elt(`URL`,n,n+a))}}]},Ar={defineNodes:[{name:`Wikilink`},{name:`WikilinkMark`}],parseInline:[{name:`Wikilink`,before:`Link`,parse(e,t,n){if(t!==91||e.char(n+1)!==91)return-1;let r=!1;for(let t=n+2;t<e.end-1;t++){let i=e.char(t);if(i===93){if(e.char(t+1)!==93||!r)return-1;let i=t+2;return e.addElement(e.elt(`Wikilink`,n,i,[e.elt(`WikilinkMark`,n,n+2),e.elt(`WikilinkMark`,t,i)]))}if(i===91||i===10)return-1;i!==32&&i!==9&&(r=!0)}return-1}}]};function jr(e){return e.end}const Mr=Ze.configure([Xe,yr,Ar,gr,kr,Sr,Er]),Nr=Mr.configure({parseInline:[{name:`SkipInline`,before:`Escape`,parse:jr}]});function V(e){return Mr.parseInline(e,0)}function H(e,t,n=[]){for(let r of e)t(r)&&n.push(r),H(r.children,t,n);return n}function Pr(e){let t={};for(let n of e.nodeSet.types)t[n.name]=n.id;return t}const U=Pr(Mr),Fr=/^<!--\s*(\{[^}]*\})\s*-->$/,Ir=/<!--\s*\{[^}]*\}\s*-->$/;function Lr(e){let t=Fr.exec(e.trim());if(!t)return;let n;try{n=JSON.parse(t[1])}catch{return}if(typeof n!=`object`||!n)return;let r=Rr(n);return Object.keys(r).length>0?r:void 0}function Rr(e){let t={},{width:n,height:r}=e;return typeof n==`number`&&Number.isFinite(n)&&n>0&&(t.width=Math.round(n)),typeof r==`number`&&Number.isFinite(r)&&r>0&&(t.height=Math.round(r)),t}function zr(e){return`<!-- ${JSON.stringify(e)} -->`}function Br(e){return e.replace(Ir,``)}function Vr(e){let t=e.replace(/^\[\[/,``).replace(/\]\]$/,``),n=t.indexOf(`|`);return n<0?{target:t.trim(),display:``}:{target:t.slice(0,n).trim(),display:t.slice(n+1).trim()}}function Hr(){return e=>{let t=e.attrs,n=document.createElement(`span`);n.className=`md-wikilink-view md-atom-view`;let r=document.createElement(`span`);r.className=`md-wikilink-view-preview md-atom-view-preview`,r.contentEditable=`false`,r.dataset.testid=`wikilink`,n.appendChild(r);let i=document.createElement(`span`);i.className=`md-wikilink-view-label`,i.contentEditable=`false`,i.textContent=t.display||t.target,r.appendChild(i);let a=document.createElement(`span`);return a.className=`md-wikilink-view-content md-atom-view-content`,n.appendChild(a),{dom:n,contentDOM:a,ignoreMutation:e=>!a.contains(e.target)}}}function Ur(){return f({name:`mdWikilink`,constructor:Hr()})}const Wr=new Map([[U.Emphasis,`mdEm`],[U.StrongEmphasis,`mdStrong`],[U.InlineCode,`mdCode`],[U.Strikethrough,`mdDel`],[U.Highlight,`mdHighlight`],[U.EmphasisMark,`mdMark`],[U.CodeMark,`mdMark`],[U.LinkMark,`mdMark`],[U.StrikethroughMark,`mdMark`],[U.HighlightMark,`mdMark`],[U.URL,`mdLinkUri`],[U.LinkTitle,`mdLinkTitle`],[U.Hashtag,`mdTag`],[U.WikilinkMark,`mdMark`]]);function Gr(e,t,n){let r=V(t),i=[];return qr(r,[],0,t.length,t,e,i,n),i}function Kr(e){return e.slice(1,-1).replaceAll(/\\(.)/g,`$1`)}function qr(e,t,n,r,i,a,o,s){let c=n;for(let n=0;n<e.length;n++){let r=e[n];r.from>c&&W(o,c,r.from,t);let l=r.type;if(l===U.Link){let e=Xr(r,t,i,a,s);e?W(o,r.from,r.to,e):Zr(r,t,i,a,o)}else if(l===U.Image){let s=Qr(r,e[n+1],i);$r(r,t,i,a,o,s),s&&n++,c=s?s.to:r.to;continue}else if(l===U.Wikilink)ti(r,t,i,a,o);else if(l===U.InlineMath)ei(r,t,i,a,o);else if(l===U.URL){let e=ur(i.slice(r.from,r.to)),n=e?a.mdLinkText.create({href:e}):a.mdLinkUri.create();W(o,r.from,r.to,[...t,n])}else{let e;l===U.Emphasis?e=`italic`:l===U.StrongEmphasis?e=`bold`:l===U.InlineCode?e=`code`:l===U.Strikethrough?e=`strike`:l===U.Highlight?e=`highlight`:l===U.Autolink&&(e=`autolink`);let n=e?[...t,a.mdPack.create({key:e})]:t,c=Wr.get(l),u=c?[...n,a[c].create()]:n;r.children.length===0?W(o,r.from,r.to,u):qr(r.children,u,r.from,r.to,i,a,o,s)}c=r.to}c<r&&W(o,c,r,t)}function Jr(e){let t=-1,n=-1,r=null,i=null,a=0;for(let o of e.children)o.type===U.LinkMark?(a++,a===1&&(t=o.to),a===2&&(n=o.from)):o.type===U.URL&&r===null?r=o:o.type===U.LinkTitle&&i===null&&(i=o);return{labelFrom:t,labelTo:n,urlNode:r,titleNode:i}}function Yr(e){let t=e.split(/[?#]/,1)[0],n=t.split(/[/\\]/).findLast(Boolean)??t;try{return decodeURIComponent(n)}catch{return n}}function Xr(e,t,n,r,i){let a=i?.resolveFileLink;if(!a)return;let{labelFrom:o,labelTo:s,urlNode:c,titleNode:l}=Jr(e);if(o<0||s<0||!c)return;let u=n.slice(c.from,c.to);if(!u)return;let d=n.slice(o,s),f=l?Kr(n.slice(l.from,l.to)):``;if(!a({href:u,label:d,title:f}))return;let p=d||Yr(u);return[...t,r.mdFile.create({href:u,name:p,title:f})]}function Zr(e,t,n,r,i){let{labelTo:a,urlNode:o,titleNode:s}=Jr(e),c=o?n.slice(o.from,o.to):``,l=s?Kr(n.slice(s.from,s.to)):``,u=c?r.mdLinkText.create({href:c}):null,d=e=>a>=0&&e<a&&u!==null,f=r.mdPack.create({key:`link`,data:{href:c,title:l}}),p=[...t,f],m=e.from;for(let t of e.children){if(t.from>m){let e=d(m)?[...p,u]:p;W(i,m,t.from,e)}let e=d(t.from)?[...p,u]:p;if(t.type===U.Wikilink){ti(t,e,n,r,i),m=t.to;continue}let a=Wr.get(t.type),o=a?[...e,r[a].create()]:e;t.children.length===0?W(i,t.from,t.to,o):qr(t.children,o,t.from,t.to,n,r,i,void 0),m=t.to}m<e.to&&W(i,m,e.to,p)}function Qr(e,t,n){if(!t||t.type!==U.Comment||t.from!==e.to)return;let r=Lr(n.slice(t.from,t.to));if(r)return{magic:r,to:t.to}}function $r(e,t,n,r,i,a){let o=e.children.find(e=>e.type===U.URL);if(!o){Zr(e,t,n,r,i);return}let s=e.children.filter(e=>e.type===U.LinkMark),c=e.children.find(e=>e.type===U.LinkTitle),l=n.slice(o.from,o.to),u=s.length>=2?n.slice(s[0].to,s[1].from):``,d=c?Kr(n.slice(c.from,c.to)):``,f=a?.magic.width??null,p=a?.magic.height??null,m=a?.to??e.to;W(i,e.from,m,[...t,r.mdImage.create({src:l,alt:u,title:d,width:f,height:p})])}function ei(e,t,n,r,i){let a=e.children.filter(e=>e.type===U.InlineMathMark);if(a.length<2){W(i,e.from,e.to,t);return}let o=n.slice(a[0].to,a[1].from),s=[...t,r.mdPack.create({key:`math`}),r.mdMath.create({formula:o})];W(i,e.from,a[0].to,[...s,r.mdMark.create()]),W(i,a[0].to,a[1].from,s),W(i,a[1].from,e.to,[...s,r.mdMark.create()])}function ti(e,t,n,r,i){let{target:a,display:o}=Vr(n.slice(e.from,e.to));W(i,e.from,e.to,[...t,r.mdWikilink.create({target:a,display:o})])}function W(e,t,n,r){if(t>=n)return;let i=e.at(-1);if(i&&i[1]===t&&ir(i[2],r)){e[e.length-1]=[i[0],n,i[2]];return}e.push([t,n,r])}const ni=`inline-marks-applied`;let ri=0,ii=0;function ai(e,t){let n=1/0,r=-1/0;for(let t of e)for(let e of t.mapping.maps)e.forEach((e,t,i,a)=>{i<n&&(n=i),a>r&&(r=a)});let i=t.doc.content.size;return n>r?{from:0,to:i}:{from:Math.max(0,n),to:Math.min(i,r)}}function oi(e){let t=new WeakMap;function n(n,r,i){let a=t.get(n);if(a?ii++:(ri++,a=Gr(Fo(i),n.textContent,e),t.set(n,a)),r===0)return a;let o=[];for(let[e,t,n]of a)o.push([e+r,t+r,n]);return o}function r(e,t){let r=[];return e.doc.nodesBetween(t.from,t.to,(t,i)=>{if(t.type.spec.code)return!1;if(!t.isTextblock)return!0;if(t.childCount===0)return!1;let a=n(t,i+1,e.schema);return a.length>0&&r.push(...a),!1}),r}return new y({key:new b(`inline-mark`),appendTransaction(e,t,n){for(let t of e)if(t.getMeta(ni))return null;let i=r(n,ai(e,n));if(i.length===0)return null;let a=n.tr.step(new z(i));return a.setMeta(ni,!0),a.setMeta(`addToHistory`,!1),a},view(e){return e.dispatch(si(e.state)),{}}})}function si(e){return e.tr.setMeta(`inline-marks-trigger`,!0)}function ci(e){return h(oi(e))}function li(){return d({name:`mdImage`,inclusive:!1,attrs:{src:{default:``},alt:{default:``},title:{default:``},width:{default:null},height:{default:null}},toDOM:()=>[`span`,{class:`md-image`},0],parseDOM:[{tag:`span.md-image`}]})}function ui(){return d({name:`mdMark`,inclusive:!1,toDOM:()=>[`span`,{class:`md-mark`},0],parseDOM:[{tag:`span.md-mark`}]})}function di(){return d({name:`mdEm`,toDOM:()=>[`em`,0],parseDOM:[{tag:`em`}]})}function fi(){return d({name:`mdStrong`,toDOM:()=>[`strong`,0],parseDOM:[{tag:`strong`}]})}function pi(){return d({name:`mdCode`,toDOM:()=>[`code`,0],parseDOM:[{tag:`code`}]})}function mi(){return d({name:`mdLinkText`,inclusive:!1,attrs:{href:{default:``}},toDOM:e=>[`a`,{class:`md-link`,href:e.attrs.href},0],parseDOM:[{tag:`a`,getAttrs:e=>({href:e.getAttribute(`href`)??``})}]})}function hi(){return d({name:`mdLinkUri`,inclusive:!1,toDOM:()=>[`span`,{class:`md-link-uri`},0],parseDOM:[{tag:`span.md-link-uri`}]})}function gi(){return d({name:`mdLinkTitle`,inclusive:!1,toDOM:()=>[`span`,{class:`md-link-title`},0],parseDOM:[{tag:`span.md-link-title`}]})}function _i(){return d({name:`mdDel`,toDOM:()=>[`del`,0],parseDOM:[{tag:`del`}]})}function vi(){return d({name:`mdHighlight`,toDOM:()=>[`mark`,0],parseDOM:[{tag:`mark`}]})}function yi(){return d({name:`mdTag`,toDOM:()=>[`span`,{class:`md-tag`},0],parseDOM:[{tag:`span.md-tag`}]})}function bi(){return d({name:`mdWikilink`,inclusive:!1,attrs:{target:{default:``},display:{default:``}},toDOM:()=>[`span`,{class:`md-wikilink`},0],parseDOM:[{tag:`span.md-wikilink`}]})}function xi(){return d({name:`mdFile`,inclusive:!1,attrs:{href:{default:``},name:{default:``},title:{default:``}},toDOM:()=>[`span`,{class:`md-file`},0],parseDOM:[{tag:`span.md-file`}]})}function Si(){return d({name:`mdMath`,inclusive:!1,attrs:{formula:{default:``}},toDOM:()=>[`span`,{class:`md-math`},0],parseDOM:[{tag:`span.md-math`}]})}function Ci(){return d({name:`mdPack`,excludes:``,inclusive:!1,attrs:{key:{},data:{default:null}},toDOM:e=>[`span`,{class:`md-pack`,"data-key":e.attrs.key},0],parseDOM:[{tag:`span.md-pack`}]})}function wi(){return _(ui(),di(),fi(),pi(),mi(),hi(),gi(),_i(),vi(),yi(),bi(),li(),xi(),Si(),Ci())}function Ti(e,t,n=0){let r=n,i=0;for(let n=0;n<e.length;n++)e.charCodeAt(n)===t?(i++,i>r&&(r=i)):i=0;return r}function Ei(e,t=0){return Ti(e,96,t)}const G={em:{node:U.Emphasis,delim:`*`},strong:{node:U.StrongEmphasis,delim:`**`},code:{node:U.InlineCode,delim:"`"},del:{node:U.Strikethrough,delim:`~~`},highlight:{node:U.Highlight,delim:`==`}},Di=new Set([U.EmphasisMark,U.CodeMark,U.LinkMark,U.StrikethroughMark,U.HighlightMark]);function Oi(e){return[e.children[0],e.children.at(-1)]}function ki(e){let{type:t,children:n}=e;if(t===U.Emphasis||t===U.StrongEmphasis||t===U.Strikethrough||t===U.Highlight)return[n[0].to,n.at(-1).from];if(t===U.Link||t===U.Image){let e=n.find((e,t)=>t>0&&e.type===U.LinkMark);return e?[n[0].to,e.from]:null}return null}function Ai(e,t,n){for(let r of e){if(r.to<=t||r.from>=n||t<=r.from&&r.to<=n)continue;let i=ki(r);return i&&i[0]<=t&&n<=i[1]?Ai(r.children,t,n):Ai(e,Math.min(t,r.from),Math.max(n,r.to))}return[t,n]}function ji(e,t,n){for(let r of e)if(!(r.to<=t||r.from>=n)&&(t>r.from||r.to>n))return ji(e,Math.min(t,r.from),Math.max(n,r.to));return[t,n]}function Mi(e,t,n){for(;t<n&&B(e.charCodeAt(t));)t++;for(;n>t&&B(e.charCodeAt(n-1));)n--;return[t,n]}function Ni(e,t,n,r){let i=H(V(e),e=>e.type===r.node||Di.has(e.type));for(let r=t;r<n;r++)if(!B(e.charCodeAt(r))&&i.every(e=>!(e.from<=r&&r<e.to)))return!1;return!0}function Pi(e,t,n,r,i){let a=V(e),o=H(a,e=>e.type===r.node);return i?Li(e,o,t,n):Fi(e,a,o,t,n,r)}function Fi(e,t,n,r,i,a){for(let e=0;e!==i-r;){e=i-r,[r,i]=Ai(t,r,i);for(let e of n)e.to===r&&(r=e.from),e.from===i&&(i=e.to)}let o=[];for(let e of n)if(r<=e.from&&e.to<=i){let[t,n]=Oi(e);o.push({from:t.from,to:t.to,insert:``}),o.push({from:n.from,to:n.to,insert:``})}let[s,c]=Ii(e,r,i,o,a);return o.push({from:r,to:r,insert:s},{from:i,to:i,insert:c}),o}function Ii(e,t,n,r,i){if(i.node!==U.InlineCode)return[i.delim,i.delim];let a=e.slice(t,n);for(let e of[...r].sort((e,t)=>t.from-e.from))a=a.slice(0,e.from-t)+a.slice(e.to-t);let o="`".repeat(Ei(a)+1),s=a.startsWith("`")||a.endsWith("`")?` `:``;return[o+s,s+o]}function Li(e,t,n,r){let i=[];for(let a of t){if(a.to<=n||a.from>=r)continue;let[t,o]=Oi(a),s=Math.max(n,t.to),c=Math.min(r,o.from);for(s>=c&&([s,c]=[t.to,o.from]),[s,c]=ji(a.children.slice(1,-1),s,c);s>t.to&&B(e.charCodeAt(s-1));)s--;for(;c<o.from&&B(e.charCodeAt(c));)c++;s>t.to?i.push({from:s,to:s,insert:e.slice(o.from,o.to)}):i.push({from:t.from,to:t.to,insert:``}),c<o.from?i.push({from:c,to:c,insert:e.slice(t.from,t.to)}):i.push({from:o.from,to:o.to,insert:``})}return i}function Ri(e,t,n){let{delim:r}=n,i=r.length;if(e.slice(t-i,t)===r&&e.startsWith(r,t)&&e[t-i-1]!==r[0]&&e[t+i]!==r[0])return{kind:`unwrap`,from:t-i,to:t+i};let a=V(e),o=H(a,e=>e.type===n.node).findLast(e=>e.from<=t&&t<=e.to);if(o){let[e,n]=Oi(o);return{kind:`move`,pos:t===o.from?e.to:t===o.to?n.from:o.to}}return zi(a,t)||e[t-1]===r[0]||e[t]===r[0]?null:{kind:`insert`,pos:t}}function zi(e,t){for(let n of e)if(n.from<t&&t<n.to){let e=ki(n);return!e||t<e[0]||t>e[1]||zi(n.children,t)}return!1}function K(e){return(t,n)=>{if(t.selection.empty)return Bi(e,t,n);let{from:r,to:i,anchor:a,head:o}=t.selection,s=[];t.doc.nodesBetween(r,i,(t,n)=>{if(t.type.spec.code)return!1;if(!t.isTextblock)return!0;let a=t.textContent,o=n+1,[c,l]=Mi(a,Math.max(r-o,0),Math.min(i-o,a.length));return c<l&&s.push({text:a,base:o,from:c,to:l,active:Ni(a,c,l,e)}),!1});let c=s.length>0&&s.every(e=>e.active),l=s.filter(e=>c||!e.active).flatMap(t=>Pi(t.text,t.from,t.to,e,c).map(e=>({from:e.from+t.base,to:e.to+t.base,insert:e.insert})));if(l.length===0)return!1;if(n){let e=t.tr;l.sort((e,t)=>t.from-e.from||t.to-e.to);for(let t of l)t.insert?e.insertText(t.insert,t.from,t.to):e.delete(t.from,t.to);e.setSelection(x.create(e.doc,e.mapping.map(a,a<=o?1:-1),e.mapping.map(o,o<a?1:-1))),n(e.scrollIntoView())}return!0}}function Bi(e,t,n){let{$from:r}=t.selection,i=r.parent;if(!i.isTextblock||i.type.spec.code)return!1;let a=Ri(i.textContent,r.parentOffset,e);if(!a)return!1;if(n){let i=r.start(),o=t.tr;a.kind===`unwrap`&&o.delete(i+a.from,i+a.to),a.kind===`move`&&o.setSelection(x.create(o.doc,i+a.pos)),a.kind===`insert`&&(o.insertText(e.delim+e.delim,i+a.pos),o.setSelection(x.create(o.doc,i+a.pos+e.delim.length))),n(o.scrollIntoView())}return!0}function Vi(){return s({toggleEm:()=>K(G.em),toggleStrong:()=>K(G.strong),toggleCode:()=>K(G.code),toggleDel:()=>K(G.del),toggleHighlight:()=>K(G.highlight)})}function Hi(){return u({"Mod-b":K(G.strong),"Mod-i":K(G.em),"Mod-e":K(G.code),"Mod-Shift-x":K(G.del),"Mod-Shift-h":K(G.highlight)})}function Ui(){return _(Vi(),Hi())}function Wi(e,t,n){let r;return e.doc.nodesBetween(t.from,t.to,(e,i)=>(e.isText&&e.marks.some(e=>e.type.name===n)&&(r={from:Math.max(i,t.from),to:Math.min(i+e.nodeSize,t.to)}),!0)),r}function q(e,t){let n=D(e,t,`mdLinkText`),r=D(e,t,`mdPack`,{key:`link`})??D(e,t,`mdPack`,{key:`autolink`}),i=r??n;if(!i)return;let a=r?.mark.attrs,o=n?.mark.attrs?.href??``;if(!r||a?.key!==`link`){let t={from:i.from,to:i.to};return{unit:t,text:a?.key===`autolink`?Wi(e,t,`mdLinkText`)??{from:i.from+1,to:i.to-1}:t,href:o,title:``}}let s=Wi(e,i,`mdLinkUri`),c=s?s.from-2:i.to-3,l=s?s.from:i.to-1,u={from:i.from+1,to:c};return{unit:{from:i.from,to:i.to},text:u,label:u,dest:{from:l,to:i.to-1},href:a.data.href,title:a.data.title}}function Gi(e){let t=e.trim();return t?ur(t)??t:``}function Ki(e,t){return e+(t?` "${t.replaceAll(/(["\\])/g,String.raw`\$1`)}"`:``)}function qi(e){let{selection:t}=e,{$from:n,$to:r,empty:i}=t;if(i||!n.sameParent(r)||!g(t))return;let a=n.parent;if(!a.isTextblock||a.type.spec.code)return;let o=n.start(),[s,c]=Mi(a.textContent,n.parentOffset,r.parentOffset);if(!(s>=c))return{from:o+s,to:o+c}}function Ji({href:e,title:t,wrapText:n=!0}={}){return(r,i)=>{let a=qi(r);if(!a)return!1;if(i){let{from:o,to:s}=a,c=r.tr,l=`](${Ki(Gi(e??``),t??``)})`;c.insertText(l,s).insertText(`[`,o);let u=s+1+l.length;c.setSelection(n?x.create(c.doc,o,u):x.create(c.doc,u)),c.scrollIntoView(),i(c)}return!0}}function Yi(e){return(t,n)=>{let r=q(t,t.selection.from);if(!r?.dest)return!1;let i=Ki(Gi(e.href??r.href),e.title??r.title);return n&&n(t.tr.insertText(i,r.dest.from,r.dest.to).scrollIntoView()),!0}}function Xi(){return(e,t)=>{let n=q(e,e.selection.from);return n?.label?(t&&t(e.tr.delete(n.label.to,n.unit.to).delete(n.unit.from,n.label.from).scrollIntoView()),!0):!1}}function Zi(){return s({insertLink:Ji,updateLink:Yi,removeLink:Xi})}function Qi(e){return(t,n,r)=>{let i=q(t,t.selection.from);if(i){if(n&&r){let{unit:{from:a,to:o}}=i;n(t.tr.setSelection(x.create(t.doc,a,o)).scrollIntoView()),r.focus(),e({from:a,to:o,link:i})}return!0}let a=qi(t);if(a){if(n&&r){let{from:i,to:o}=a;n(t.tr.setSelection(x.create(t.doc,i,o)).scrollIntoView()),r.focus(),e({from:i,to:o,link:void 0})}return!0}return!1}}function $i(e){return u({"Mod-k":Qi(e)})}function ea(e){return e===`)`||e===`*`||e===`+`?e:void 0}function ta(e){return e===`X`?e:void 0}function na(e){return aa(e)?String(e):void 0}function ra(){return p({type:`list`,attr:`marker`,default:null,splittable:!0,toDOM:e=>{let t=ea(e);return t==null?null:[`data-list-marker`,t]},parseDOM:e=>{let t=e.getAttribute(`data-list-marker`);return t===`)`||t===`*`||t===`+`?t:null}})}function ia(){return p({type:`list`,attr:`taskMarker`,default:null,splittable:!0,toDOM:e=>{let t=ta(e);return t==null?null:[`data-list-task-marker`,t]},parseDOM:e=>e.getAttribute(`data-list-task-marker`)===`X`?`X`:null})}function aa(e){return e===2||e===3||e===4}function oa(){return p({type:`list`,attr:`markerGap`,default:1,splittable:!0,toDOM:e=>{let t=na(e);return t==null?null:[`data-list-marker-gap`,t]},parseDOM:e=>{let t=Number.parseInt(e.getAttribute(`data-list-marker-gap`)??``,10);return aa(t)?t:1}})}function sa(e){let t=e.attrs;return{...st(e),"data-list-marker":ea(t.marker),"data-list-task-marker":ta(t.taskMarker),"data-list-marker-gap":na(t.markerGap)}}function ca(){return o({serializeFragmentWrapper:e=>(...t)=>la(ut(e(...t))),serializeNodeWrapper:e=>(...t)=>{let n=e(...t);return _e(n)?la(ut(n)):n},nodesFromSchemaWrapper:e=>(...t)=>({...e(...t),list:e=>dt({node:e,nativeList:!0,getAttributes:sa})})})}function la(e){_e(e)&&ua(e);for(let t of e.children)la(t);return e}function ua(e){if(!e.classList.contains(`prosemirror-flat-list`)||e.getAttribute(`data-list-kind`)!==`task`||e.children.length!==2)return;let t=e.children.item(0);if(!t||!t.classList.contains(`list-marker`))return;let n=ct(t);if(!n)return;let r=e.children.item(1);if(!r||!r.classList.contains(`list-content`))return;let i=r.children.item(0);!i||![`P`,`H1`,`H2`,`H3`,`H4`,`H5`,`H6`].includes(i.tagName)||(e.replaceChildren(...r.children),i.prepend(n))}const da=[E(/^\s?([*-])\s$/,{kind:`bullet`,collapsed:!1}),E(/^\s?(\d+)\.\s$/,({match:e})=>{let t=e[1],n=t?parseInt(t,10):void 0;return{kind:`ordered`,collapsed:!1,order:n&&n>=2&&Number.isSafeInteger(n)?n:null}}),E(/^\s?\[([\sX]?)\]\s$/i,({match:e})=>({kind:`task`,checked:[`x`,`X`].includes(e[1]),collapsed:!1})),E(/^\s?\+\s$/,{kind:`task`,marker:`+`,checked:!1,collapsed:!1})];function fa(){return _(da.map(Ne))}function pa(){return T({kind:`task`,marker:`+`})}function ma(){return T({kind:`task`,marker:null})}function ha(){return s({wrapInCircleTask:pa,wrapInSquareTask:ma})}function ga(e){let{$from:t}=e.selection;for(let e=t.depth;e>0;e--){let n=t.node(e);if(n.type.name===`list`)return n.attrs}return null}function _a(){return(e,t,n)=>{let r=ga(e),i=r?.kind===`task`&&r.marker!==`+`,a;return a=i&&!r?.checked?{kind:`task`,marker:r?.marker??null,checked:!0}:i&&r?.checked?{kind:`bullet`,marker:null,checked:!1}:{kind:`task`,marker:null,checked:!1},T(a)(e,t,n)}}function va(){return(e,t,n)=>{let r=ga(e),i=r?.kind===`task`&&r.marker===`+`,a;return a=i&&!r?.checked?{kind:`task`,marker:`+`,checked:!0}:i&&r?.checked?{kind:`bullet`,marker:null,checked:!1}:{kind:`task`,marker:`+`,checked:!1},T(a)(e,t,n)}}function ya(e){return e.type.name===`list`&&e.attrs.kind===`bullet`&&e.childCount>=2&&e.firstChild?.type!==e.type}const ba=e=>{let t=e.attrs;return t.kind===`task`?{...t,checked:!t.checked}:ya(e)?{...t,collapsed:!t.collapsed}:t};function xa(){return h(()=>[new y({props:{handleDOMEvents:{mousedown:(e,t)=>lt({view:e,event:t,onListClick:ba})}}}),it(),new y({props:{transformCopied:ft}}),at()])}function Sa(){return s({toggleListCollapsed:()=>ot({isToggleable:ya})})}function Ca(){return u({"Mod-Enter":_a(),"Mod-Shift-Enter":va(),"Mod-.":ot({isToggleable:ya}),"Mod-Shift-7":rt({kind:`ordered`,collapsed:!1}),"Mod-Shift-8":rt({kind:`bullet`,collapsed:!1}),"Mod-Shift-9":rt({kind:`task`,checked:!1,collapsed:!1})})}function wa(){return _(tt(),xa(),et(),Qe(),ca(),$e(),fa(),Ca(),ra(),ia(),oa(),ha(),Sa())}let Ta;function Ea(){return Ta??=import(`katex`).then(e=>e.render),Ta}function Da(e,t,n,r){try{e(n,t,{displayMode:r,throwOnError:!1,output:`mathml`})}catch(e){t.textContent=String(e)}}var Oa=class{#e;#t;#n;#r;constructor(e,t){this.#r=e.attrs.formula,this.#e=document.createElement(`span`),this.#e.className=`md-math-view`,this.#n=document.createElement(`span`),this.#n.className=`md-math-view-preview`,this.#n.dataset.testid=`math-preview`,this.#n.contentEditable=`false`,this.#n.addEventListener(`mousedown`,e=>{e.preventDefault();let n=t.posAtDOM(this.#t,0);if(n<0)return;let r=x.near(t.state.doc.resolve(n),1);t.dispatch(t.state.tr.setSelection(r)),t.focus()}),this.#t=document.createElement(`span`),this.#t.className=`md-math-view-content`,this.#e.appendChild(this.#n),this.#e.appendChild(this.#t),this.#i()}get dom(){return this.#e}get contentDOM(){return this.#t}update(e){let t=e.attrs.formula;return t!==this.#r&&(this.#r=t,this.#i()),!0}ignoreMutation(e){return!this.#t.contains(e.target)}#i(){let e=this.#r;Ea().then(t=>{e===this.#r&&Da(t,this.#n,e,!1)})}};function ka(){return f({name:`mdMath`,constructor:(e,t)=>new Oa(e,t)})}function Aa(e){return e===`left`||e===`center`||e===`right`?e:null}function ja(){return p({type:`tableCell`,attr:`align`,default:null,toDOM:e=>e?[`data-align`,e]:null,parseDOM:e=>Aa(e.getAttribute(`data-align`))})}function Ma(){return p({type:`tableHeaderCell`,attr:`align`,default:null,toDOM:e=>e?[`data-align`,e]:null,parseDOM:e=>Aa(e.getAttribute(`data-align`))})}function Na(e){for(let t=0;t<e.childCount;t++){let n=e.child(t);for(let e=0;e<n.childCount;e++)if(n.child(e).type.name===`tableHeaderCell`)return t}return 0}function Pa(e){return e.child(Na(e))}function Fa(e,t){return t>=e.childCount?null:e.child(t).attrs.align??null}function Ia(e,t,n){if(e.childCount===0)return;let r=Pa(e),i=t+1;for(let t=0;t<e.childCount;t++){let a=e.child(t),o=i+1;for(let e=0;e<a.childCount;e++){let t=a.child(e),i=Fa(r,e);(t.attrs.align??null)!==i&&n.setNodeMarkup(o,void 0,{...t.attrs,align:i}),o+=t.nodeSize}i+=a.nodeSize}}function La(e){let t,n;for(let r of e){if(!r.docChanged)continue;t!=null&&n!=null&&(t=r.mapping.map(t,-1),n=r.mapping.map(n,1));let e=r.mapping;for(let[r,i]of e.maps.entries()){let a=e.slice(r+1);i.forEach((e,r,i,o)=>{let s=a.map(i,-1),c=a.map(o,1);t=t==null?s:Math.min(t,s),n=n==null?c:Math.max(n,c)})}}if(!(t==null||n==null))return{from:t,to:n}}function Ra(){return new y({key:new b(`table-align-sync`),appendTransaction(e,t,n){if(!e.some(e=>e.docChanged))return;let r=La(e);if(!r)return;let i=n.doc,a=Math.max(0,Math.min(r.from,i.content.size)),o=Math.max(a,Math.min(r.to,i.content.size)),s;return i.nodesBetween(a,o,(e,t)=>e.type.name===`table`?(s??=n.tr,Ia(e,t,s),!1):!0),s?.docChanged?s:void 0}})}function za(){return h(Ra())}function Ba(e){let{selection:t}=e;if(xt(t)){let{$anchorCell:e,$headCell:n}=t,r=e.depth-1,i=e.index(),a=n.index();return{table:e.node(r),tablePos:e.before(r),firstColumn:Math.min(i,a),lastColumn:Math.max(i,a)}}let{$from:n}=t;for(let e=n.depth;e>2;e--){let t=n.node(e).type.name;if(t===`tableCell`||t===`tableHeaderCell`){let t=n.index(e-1);return{table:n.node(e-2),tablePos:n.before(e-2),firstColumn:t,lastColumn:t}}}}function Va(e){return(t,n)=>{let r=Ba(t);if(!r||r.table.childCount===0)return!1;if(n){let{table:i,tablePos:a,firstColumn:o,lastColumn:s}=r,c=Na(i),l=a+1;for(let e=0;e<c;e++)l+=i.child(e).nodeSize;let u=i.child(c),d=t.tr,f=l+1;for(let t=0;t<u.childCount;t++){let n=u.child(t);t>=o&&t<=s&&(n.attrs.align??null)!==e&&d.setNodeMarkup(f,void 0,{...n.attrs,align:e}),f+=n.nodeSize}n(d)}return!0}}function Ha(e){let t=Ba(e);if(!(!t||t.table.childCount===0))return Fa(Pa(t.table),t.lastColumn)??void 0}function Ua(){return s({setTableColumnAlign:Va})}function Wa(){return _(ja(),Ma(),za(),Ua())}function Ga(e){let{$from:t}=e.selection;for(let e=t.depth;e>0;e--){let n=t.node(e).type.name;if(n===`tableCell`||n===`tableHeaderCell`)return!0}return!1}const Ka=`paragraph`;function qa(){return _(m({name:`tableCell`,content:Ka}),m({name:`tableHeaderCell`,content:Ka}))}const Ja=(e,t)=>{let{selection:n}=e;return!xt(n)||!n.isColSelection()||!n.isRowSelection()?!1:bt(e,t)};function Ya(){return v(u({Backspace:Ja,Delete:Ja}),t.high)}function Xa(){return _(yt(),vt(),pt(),_t(),qa(),Wa(),gt({allowTableNodeSelection:!0}),mt(),ht(),Ya())}function Za(e){let{selection:t}=e,{$from:n,$to:r}=t;if(oe(t)&&n.depth===0||n.depth>0&&r.depth>0&&n.index(0)===r.index(0))return n.index(0)}function Qa(e){return(t,n)=>{if(Ga(t))return!1;let r=Za(t);if(r==null)return!1;let i=r+e;if(i<0||i>=t.doc.childCount)return!1;if(n){let{selection:a}=t,o=Math.min(r,i),s=a.$from.posAtIndex(o,0),c=t.doc.child(o),l=t.doc.child(o+1),u=t.tr.replaceWith(s,s+c.nodeSize+l.nodeSize,[l,c]),d=e===-1?-c.nodeSize:l.nodeSize,f=oe(a)?Te.create(u.doc,a.from+d):x.create(u.doc,a.anchor+d,a.head+d);u.setSelection(f),n(u.scrollIntoView())}return!0}}function $a(e){return(t,n,r)=>nt(e)(t,n,r)||Qa(e===`up`?-1:1)(t,n,r)}function eo(){return u({"Alt-ArrowUp":$a(`up`),"Alt-ArrowDown":$a(`down`)})}function to(){return m({name:`paragraph`,content:`inline*`,group:`block`,whitespace:`pre`,parseDOM:[{tag:`p`}],toDOM(){return[`p`,0]}})}function no(){return _(v(to(),t.highest),St(),Ct())}const J=new b(`meowdownPendingReplacement`);function Y(e){return J.getState(e)?.pending??null}function ro(e,t){switch(e.type){case`start`:return{pending:{from:e.from,to:e.to,mode:e.mode,text:``}};case`append`:return t.pending?{pending:{...t.pending,text:t.pending.text+e.text}}:t;case`accept`:return t.pending?{pending:null,ended:{pending:t.pending,outcome:`accepted`}}:t;case`discard`:return t.pending?{pending:null,ended:{pending:t.pending,outcome:`discarded`}}:t}}const io=new y({key:J,state:{init:()=>({pending:null}),apply:(e,t)=>{let n=e.getMeta(J);if(n)return ro(n,t);if(e.docChanged&&t.pending){let n=e.mapping.mapResult(t.pending.from,1),r=e.mapping.mapResult(t.pending.to,-1),i=Math.min(n.pos,r.pos),a=Math.max(n.pos,r.pos);return(n.deletedAfter&&r.deletedBefore||i>=a)&&t.pending.mode===`replace`?{pending:null,ended:{pending:t.pending,outcome:`discarded`}}:{pending:{...t.pending,from:i,to:a}}}return t}},props:{decorations:e=>{let t=Y(e);return!t||t.from>=t.to?null:C.create(e.doc,[S.inline(t.from,t.to,{class:`md-pending-replacement`})])}}});function ao(e){return(t,n)=>{let{from:r,to:i,mode:a}=e;return r<0||i>t.doc.content.size||r>i||r===i&&a===`replace`?!1:(n?.(t.tr.setMeta(J,{type:`start`,from:r,to:i,mode:a})),!0)}}function oo(e){return(t,n)=>Y(t)?(n?.(t.tr.setMeta(J,{type:`append`,text:e})),!0):!1}function so(){return(e,t)=>Y(e)?(t?.(e.tr.setMeta(J,{type:`discard`})),!0):!1}function co(e={}){return(t,n)=>{let r=Y(t);if(!r||!r.text.trim())return!1;if(n){let i=e.mode??r.mode,a=Lo(t.schema),o=Z(r.text,{nodes:a}),s=t.tr;if(s.setMeta(J,{type:`accept`}),i===`append`){let e=t.doc.resolve(r.to).after(1);s.insert(e,o.content),s.setSelection(x.near(s.doc.resolve(e+o.content.size),-1))}else{let e=t.doc.resolve(r.from),n=t.doc.resolve(r.to),i=o.childCount===1?o.firstChild:null;i?.type.name===`paragraph`&&e.sameParent(n)&&e.parent.isTextblock?(s.replaceWith(r.from,r.to,i.content),s.setSelection(x.near(s.doc.resolve(r.from+i.content.size),-1))):(s.replaceRange(r.from,r.to,new w(o.content,0,0)),s.setSelection(x.near(s.doc.resolve(s.mapping.map(r.to)),-1)))}n(s.scrollIntoView())}return!0}}function lo(){return s({startPendingReplacement:ao,appendPendingReplacementText:oo,acceptPendingReplacement:co,discardPendingReplacement:so})}function uo(){return u({"Mod-Enter":co(),Escape:so()})}function fo(){return _(h(io),lo(),uo())}function po(e){return h(new y({view:()=>({update:(t,n)=>{let r=J.getState(n),i=J.getState(t.state);!i||r===i||(i.pending?i.pending!==r?.pending&&e({type:`update`,pending:i.pending}):i.ended&&i.ended!==r?.ended&&e({type:`ended`,pending:i.ended.pending,outcome:i.ended.outcome}))}})}))}function mo(e,t){return(n,r)=>{let i=e<0?Ee.atStart(n.doc):Ee.atEnd(n.doc),a=t?x.between(n.selection.$anchor,i.$head):i;return n.selection.eq(a)||r?.(n.tr.setSelection(a).scrollIntoView()),!0}}function ho(){return u({"Meta-ArrowUp":mo(-1,!1),"Meta-ArrowDown":mo(1,!1),"Shift-Meta-ArrowUp":mo(-1,!0),"Shift-Meta-ArrowDown":mo(1,!0)})}function go(e){return e.left===e.right&&e.top===e.bottom}function X(e,t,n){if(t<0||t>e.state.doc.content.size)return;let r;try{r=e.coordsAtPos(t,n)}catch{return}return go(r)?void 0:r}function _o(e){e.offsetWidth}const vo=new b(`meowdown-virtual-caret`),yo=[`md-virtual-caret-blink`,`md-virtual-caret-blink2`];function bo(e){let t=e.dom.ownerDocument.getSelection();if(t==null||t.rangeCount===0||!e.dom.contains(t.anchorNode))return;let n=t.getRangeAt(0).cloneRange();n.collapse(!0);let r=Array.from(n.getClientRects()).filter(e=>e.height>0);if(r.length===0)return;let i=r[r.length-1];return{left:i.left,top:i.top,height:i.height}}function xo(e){let t=e.state,n=t.selection.head,r=I(t,n),i=L(t,n),a=r==null,o=[[n,a],[n,!a]];r!=null&&o.push([r.from,!0]),i!=null&&o.push([i.to,!1]);for(let[t,n]of o){let r=X(e,t,n?-1:1);if(r!=null&&r.bottom>r.top)return{left:r.left,top:r.top,height:r.bottom-r.top}}}function So(e){let t=e.state,n=t.selection.head;for(let r of Ht){let i=D(t,n,r);if(i==null||i.from!==n&&i.to!==n)continue;let a=Co(e,i.from+1);if(a==null)continue;let o=a.getBoundingClientRect();if(o.height!==0)return{left:i.to===n?o.right:o.left,top:o.top,height:o.height}}}function Co(e,t){let{node:n}=e.domAtPos(t,0);return(n instanceof Element?n:n.parentElement)?.closest(`.md-atom-view`)?.querySelector(`.md-atom-view-preview`)??void 0}function wo(e){let t=e.height*.19999999999999996;return{left:e.left,top:e.top-t/2,height:e.height+t}}function To(e){let t=bo(e)??xo(e);return t==null?So(e):wo(t)}function Eo(e,t){return e==null||t==null?e===t:e.left===t.left&&e.top===t.top&&e.height===t.height}var Do=class{#e;#t;#n;#r;#i;#a;#o;#s=0;constructor(e){this.#e=e,this.#r=e.dom.ownerDocument,this.#t=this.#r.createElement(`div`),this.#t.className=`md-virtual-caret-layer`,this.#n=this.#t.appendChild(this.#r.createElement(`div`)),this.#n.className=`md-virtual-caret`,this.#n.dataset.testid=`virtual-caret`,e.dom.insertAdjacentElement(`afterend`,this.#t),this.#r.addEventListener(`selectionchange`,this.#l),typeof ResizeObserver<`u`&&(this.#i=new ResizeObserver(this.#l),this.#i.observe(e.dom)),this.#l()}update(e,t){e.state.selection.eq(t.selection)||this.#c(),this.#l()}destroy(){this.#r.removeEventListener(`selectionchange`,this.#l),this.#i?.disconnect(),this.#t.remove()}#c(){this.#s=1-this.#s,this.#n.style.animationName=yo[this.#s]}#l=()=>{let e=this.#e;if(e.isDestroyed)return;let t=e.state,n=t.selection,r=g(n)&&n.empty?To(e):void 0,i=r!=null&&k(t)===`hide`?Hn(t,n.head):void 0;if(Eo(r,this.#a)&&i===this.#o)return;let a=this.#a==null;if(this.#a=r,this.#o=i,i==null?delete this.#n.dataset.tail:this.#n.dataset.tail=i,r==null){this.#n.style.visibility=`hidden`;return}let o=this.#t.getBoundingClientRect();a&&(this.#n.style.transitionProperty=`none`),this.#n.style.visibility=``,this.#n.style.left=`${r.left-o.left}px`,this.#n.style.top=`${r.top-o.top}px`,this.#n.style.height=`${r.height}px`,a&&(_o(this.#n),this.#n.style.transitionProperty=``)}};function Oo(){return h(new y({key:vo,view:e=>new Do(e)}))}function ko(e){return _(no(),be(),Tn(),Ce(),ye(),wa(),jn(),Xa(),gn(),er(),tr(),wi(),sn(),wn(),eo(),ho(),ci(e),Ui(),Zi(),Ur(),ka(),Lt(e.markMode??`focus`),Oo(),Qn(),en({marks:Ht.map(e=>({name:e,modes:[`hide`,`focus`,`show`]}))}),a(),i(),l(),xe(),we(),Se(),Sn(),fo())}function Ao(e={}){return ko(e)}const jo=ve(()=>{let e=Ao().schema;if(e==null)throw Error(`Unexpected empty schema`);return e}),Mo=ve(()=>r(jo())),No=ve(()=>n(jo())),Po=`meowdown_mark_builders`;function Fo(e){let t=e.cached[Po];if(t)return t;let r=n(e);return e.cached[Po]=r,r}const Io=`meowdown_node_builders`;function Lo(e){let t=e.cached[Io];if(t)return t;let n=r(e);return e.cached[Io]=n,n}function Z(e,t={}){let{nodes:n=Mo(),frontmatter:r=!1}=t,i,a=e;if(r){let[t,n]=zo(e);i=t,n&&(a=e.slice(n))}let o=Bo(n,Nr.parse(a).cursor(),a);return n.doc(i===void 0?{}:{frontmatter:i},o)}const Ro=/^---[ \t]*\r?\n([\s\S]*?\n)?---[ \t]*(?:\r?\n|$)/;function zo(e){let t=Ro.exec(e);return t?[(t[1]??``).replace(/\r?\n$/,``),t[0].length]:[]}function Bo(e,t,n){let r=[];if(!t.firstChild())return r;let i;do i!=null&&Vo(r,e,n,i,t.from),i=t.to,r.push(...Ho(e,t,n));while(t.nextSibling());return t.parent(),r}function Vo(e,t,n,r,i){let a=0;for(let e=r;e<i;e++)n.charCodeAt(e)===10&&a++;for(let n=2;n<a;n++)e.push(t.paragraph())}function Ho(e,t,n){switch(t.type.id){case U.ATXHeading1:return[Q(e,t,n,1,!1)];case U.ATXHeading2:return[Q(e,t,n,2,!1)];case U.ATXHeading3:return[Q(e,t,n,3,!1)];case U.ATXHeading4:return[Q(e,t,n,4,!1)];case U.ATXHeading5:return[Q(e,t,n,5,!1)];case U.ATXHeading6:return[Q(e,t,n,6,!1)];case U.SetextHeading1:return[Q(e,t,n,1,!0)];case U.SetextHeading2:return[Q(e,t,n,2,!0)];case U.Paragraph:return[Jo(e,t,n)];case U.CommentBlock:return[Yo(e,t,n)];case U.HTMLBlock:case U.ProcessingInstructionBlock:return[Jo(e,t,n)];case U.Blockquote:return[Xo(e,t,n)];case U.BulletList:return Zo(e,t,n,`bullet`);case U.OrderedList:return Zo(e,t,n,`ordered`);case U.FencedCode:case U.CodeBlock:return[$o(e,t,n)];case U.BlockMath:return[es(e,t,n)];case U.HorizontalRule:{let r=n.slice(t.from,t.to).trimEnd();return[e.horizontalRule({marker:r===`---`?null:r})]}case U.Table:return[ts(e,t,n)];case U.Task:return[Jo(e,t,n)];default:return n.slice(t.from,t.to).trim()===``?[]:(console.warn(`[meowdown] unsupported lezer block "${t.type.name}"`),[Jo(e,t,n)])}}function Q(e,t,n,r,i){let a=t.from,o=t.from,s=t.to,c=-1,l=-1;if(t.firstChild()){t.type.id===U.HeaderMark&&t.from===a&&(o=t.to);let e=-1,n=-1,r=-1;do e=t.type.id,n=t.from,r=t.to;while(t.nextSibling());e===U.HeaderMark&&n>o&&(s=n,c=n,l=r),t.parent()}let u=Ko(n.slice(o,s),$(n,o)).trim(),d=i?Uo(n,c,l)||1:null,f=!i&&c>=0&&Wo(n,c,l)||null;return e.heading({level:r,setextUnderline:d,closingHashes:f},u)}function Uo(e,t,n){if(t<0)return 0;let r=0;for(let i=t;i<n;i++){let t=e.charCodeAt(i);(t===61||t===45)&&r++}return r}function Wo(e,t,n){if(t<0)return 0;let r=0;for(let i=t;i<n;i++)e.charCodeAt(i)===35&&r++;return r}function $(e,t){let n=e.lastIndexOf(`
|
|
3
|
-
`,t-1)+1,r=0;for(let i=n;i<t;i++)r+=e.charCodeAt(i)===9?4-r%4:1;return r}function
|
|
1
|
+
import{Priority as e,Priority as t,createMarkBuilders as n,createNodeBuilders as r,defineBaseCommands as i,defineBaseKeymap as a,defineClipboardSerializer as o,defineCommands as s,defineDOMEventHandler as c,defineHistory as l,defineKeymap as u,defineMarkSpec as d,defineMarkView as f,defineNodeAttr as p,defineNodeSpec as m,definePlugin as h,getMarkRange as ee,getMarkType as te,getNodeType as ne,isAllSelection as re,isApple as ie,isAtBlockStart as ae,isNodeSelection as oe,isTextSelection as g,toggleNode as se,union as _,unsetBlockType as ce,withPriority as le,withPriority as v,withSkipCodeBlock as ue}from"@prosekit/core";import{defineCodeBlock as de,defineCodeBlockHighlight as fe,defineCodeBlockPreviewPlugin as pe,isCodeBlockPreviewHiddenDecoration as me}from"@prosekit/extensions/code-block";import{definePlaceholder as he}from"@prosekit/extensions/placeholder";import{defineReadonly as ge}from"@prosekit/extensions/readonly";import{isElementLike as _e,once as ve}from"@ocavue/utils";import{defineBlockquote as ye}from"@prosekit/extensions/blockquote";import{defineDoc as be}from"@prosekit/extensions/doc";import{defineGapCursor as xe}from"@prosekit/extensions/gap-cursor";import{defineModClickPrevention as Se}from"@prosekit/extensions/mod-click-prevention";import{defineText as Ce}from"@prosekit/extensions/text";import{defineVirtualSelection as we}from"@prosekit/extensions/virtual-selection";import{NodeSelection as Te,Plugin as y,PluginKey as b,Selection as Ee,TextSelection as x}from"@prosekit/pm/state";import{Decoration as De,DecorationSet as S}from"@prosekit/pm/view";import{LanguageDescription as Oe}from"@codemirror/language";import{languages as ke}from"@codemirror/language-data";import{classHighlighter as Ae,highlightTree as je}from"@lezer/highlight";import{createParser as Me}from"prosemirror-highlight/lezer";import{defineTextBlockEnterRule as Ne}from"@prosekit/extensions/enter-rule";import{defineInputRule as Pe,defineTextBlockInputRule as Fe}from"@prosekit/extensions/input-rule";import{triggerAutocomplete as Ie}from"@prosekit/extensions/autocomplete";import{DOMSerializer as Le,Mark as Re,Slice as ze}from"@prosekit/pm/model";import{defineHeadingCommands as Be,defineHeadingInputRule as Ve,defineHeadingSpec as He}from"@prosekit/extensions/heading";import{defineHorizontalRule as Ue}from"@prosekit/extensions/horizontal-rule";import{AddMarkStep as We,AddNodeMarkStep as Ge,RemoveMarkStep as Ke,RemoveNodeMarkStep as qe,ReplaceStep as Je,Step as Ye,StepResult as Xe,Transform as Ze}from"@prosekit/pm/transform";import{GFM as Qe,parser as $e}from"@lezer/markdown";import{defineListCommands as et,defineListDropIndicator as tt,defineListKeymap as nt,defineListSpec as rt,moveList as it,toggleList as at,wrapInList as C}from"@prosekit/extensions/list";import{createListRenderingPlugin as ot,createSafariInputMethodWorkaroundPlugin as st,createToggleCollapsedCommand as ct,defaultAttributesGetter as lt,findCheckboxInListItem as ut,handleListMarkerMouseDown as dt,joinListElements as ft,listToDOM as pt,unwrapListSlice as mt,wrappingListInputRule as w}from"prosemirror-flat-list";import{defineTableCellSpec as ht,defineTableCommands as gt,defineTableDropIndicator as _t,defineTableEditingPlugin as vt,defineTableHeaderCellSpec as yt,defineTableRowSpec as bt,defineTableSpec as xt,deleteTable as St,isCellSelection as Ct}from"@prosekit/extensions/table";import{defineParagraphCommands as wt,defineParagraphKeymap as Tt}from"@prosekit/extensions/paragraph";import{closeHistory as Et}from"@prosekit/pm/history";import Dt from"rehype-parse";import Ot from"rehype-remark";import kt from"remark-gfm";import At from"remark-stringify";import{unified as jt}from"unified";import{registerResizableHandleElement as Mt,registerResizableRootElement as Nt}from"@prosekit/web/resizable";function T(e,t,n,r){let i=e.doc.content.size;if(t<0||t>i)return;let a=e.doc.resolve(t);if(!(!a.parent.isTextblock||a.parent.type.spec.code))return ee(a,n,r)}const Pt=new Set([`mdMark`,`mdLinkUri`,`mdLinkTitle`]),Ft=new Set([`mdMath`]),E=new b(`mark-mode`);function It(e){return E.getState(e)}function Lt(e){return new y({key:E,state:{init:()=>e,apply:(e,t)=>e.getMeta(E)??t},props:{attributes:t=>({"data-mark-mode":It(t)??e}),decorations:e=>{let t=It(e);if(t===`focus`)return Vt(e);if(t===`hide`)return Ht(e)},clipboardTextSerializer:(e,t)=>It(t.state)===`show`?``:Bt(e)}})}function Rt(e){return(t,n)=>D(t)===e?!1:(n?.(t.tr.setMeta(E,e)),!0)}function zt(e){return _(h(Lt(e)),s({setMarkMode:Rt}))}function D(e){return E.getState(e)}function Bt(e){let t=[];return e.content.forEach(e=>{let n=[];e.descendants(e=>{if(!e.isText||!e.text)return!0;let t=e.marks.map(e=>e.type.name);return t.some(e=>Pt.has(e))&&!t.some(e=>Ft.has(e))||n.push(e.text),!1}),t.push(n.join(``))}),t.join(`
|
|
2
|
+
`)}function Vt(e){return Ut(e,void 0)}function Ht(e){return Ut(e,{key:`math`})}function Ut(e,t){let{selection:n}=e;if(!n.empty)return S.empty;let r=n.$head,{parent:i}=r;if(!i.isTextblock||i.type.spec.code)return S.empty;let a=ee(r,te(e.schema,`mdPack`),t);return a?S.create(e.doc,[De.inline(a.from,a.to,{class:`show`})]):S.empty}const Wt=[`mdImage`,`mdWikilink`,`mdFile`];function O(e,t){let n=D(t);return n?e.flatMap(e=>e.modes.includes(n)?[e.name]:[]):[]}function Gt(e,t,n){for(let r of n){let n=T(e,t,r);if(n)return n}}function k(e,t,n){let r=Gt(e,t,n);return r&&r.to===t?r:void 0}function A(e,t,n){let r=Gt(e,t,n);return r&&r.from===t?r:void 0}function Kt(e,t){let{from:n,to:r,empty:i}=e.selection;if(i)return;let a=Gt(e,n,t);return a&&a.from===n&&a.to===r?a:void 0}function qt(e,t){return x.create(e.doc,t.from,t.to)}function Jt(e,t,n,r){let i=e.doc.resolve(t);if(!(r===-1?i.parentOffset===0:i.parentOffset===i.parent.content.size)||i.depth===0)return;let a=r===-1?A(e,t,n):k(e,t,n),o=r===-1?i.before():i.after(),s=Ee.findFrom(e.doc.resolve(o),r);if(!s)return;let c=g(s)?r===-1?k(e,s.head,n):A(e,s.head,n):void 0;if(!(a==null&&c==null))return s}function Yt(e){return(t,n)=>{let r=O(e,t);if(r.length===0||!g(t.selection))return!1;let i=t.selection;if(i.empty){let e=A(t,i.from,r);if(e)return n?.(t.tr.setSelection(qt(t,e))),!0;if(k(t,i.from,r)&&i.from<t.doc.resolve(i.from).end())return n?.(t.tr.setSelection(x.create(t.doc,i.from+1))),!0;let a=Jt(t,i.from,r,1);return a?(n?.(t.tr.setSelection(a).scrollIntoView()),!0):!1}let a=Kt(t,r);return a?(n?.(t.tr.setSelection(x.create(t.doc,a.to))),!0):!1}}function Xt(e){return(t,n)=>{let r=O(e,t);if(r.length===0||!g(t.selection))return!1;let i=t.selection;if(i.empty){let e=k(t,i.from,r);if(e)return n?.(t.tr.setSelection(qt(t,e))),!0;let a=Jt(t,i.from,r,-1);return a?(n?.(t.tr.setSelection(a).scrollIntoView()),!0):!1}let a=Kt(t,r);return a?(n?.(t.tr.setSelection(x.create(t.doc,a.from))),!0):!1}}function Zt(e,t){return(n,r)=>{let i=O(e,n);if(i.length===0||!g(n.selection))return!1;let{anchor:a,head:o}=n.selection,s=t===-1?k(n,o,i):A(n,o,i);if(s){let e=t===-1?s.from:s.to;return r?.(n.tr.setSelection(x.create(n.doc,a,e)).scrollIntoView()),!0}let c=Jt(n,o,i,t);return!c||!g(c)?!1:(r?.(n.tr.setSelection(x.create(n.doc,a,c.head)).scrollIntoView()),!0)}}function Qt(e){return(t,n)=>{let r=O(e,t);if(r.length===0||!t.selection.empty)return!1;let i=t.selection.from,a=k(t,i,r);return a?(n?.(t.tr.delete(a.from,a.to)),!0):!A(t,i,r)||i<=t.doc.resolve(i).start()?!1:(n?.(t.tr.delete(i-1,i)),!0)}}function $t(e){return(t,n)=>{let r=O(e,t);if(r.length===0||!t.selection.empty)return!1;let i=t.selection.from,a=A(t,i,r);return a?(n?.(t.tr.delete(a.from,a.to)),!0):!k(t,i,r)||i>=t.doc.resolve(i).end()?!1:(n?.(t.tr.delete(i,i+1)),!0)}}const en=`md-atom-selected`;function tn(e){return new y({key:new b(`atom-mark-selection`),props:{decorations:t=>{let n=O(e,t);if(n.length===0||oe(t.selection))return;let r=Kt(t,n);if(r)return S.create(t.doc,[De.inline(r.from,r.to,{class:en})]);let{from:i,to:a,empty:o}=t.selection;if(o)return null;let s=[];return t.doc.nodesBetween(i,a,(e,t)=>{e.marks.some(e=>n.includes(e.type.name))&&s.push(De.inline(t,t+e.nodeSize,{class:en}))}),S.create(t.doc,s)}}})}function nn({marks:e}){return _(v(u({ArrowRight:Yt(e),ArrowLeft:Xt(e),"Shift-ArrowRight":Zt(e,1),"Shift-ArrowLeft":Zt(e,-1),Backspace:Qt(e),Delete:$t(e)}),t.high),h(tn(e)))}const j=new Map,rn=new Map,an={math:`latex`};async function on(e){let t=j.get(e);if(t!==void 0)return t;let n=Oe.matchLanguageName(ke,an[e]??e,!0);if(!n)return j.set(e,null),null;let r=n.support;if(!r)try{r=await n.load()}catch(t){return console.error(`[meowdown] Failed to load language "${e}":`,t),j.set(e,null),null}return j.set(e,r),r}function sn(e,t){let n=rn.get(e);if(n)return n;let r=Me({parse:e=>t.language.parser.parse(e.content),highlighter:Ae});return rn.set(e,r),r}const cn=e=>{let t=e.language?.trim();if(!t)return[];let n=j.get(t);return n===null?[]:n?sn(t,n)(e):on(t).then(()=>void 0)};function ln(){return fe({parser:cn,nodeTypes:[`codeBlock`]})}function un(e,t){let n=t.language.parser.parse(e),r=[];return je(n,Ae,(e,t,n)=>{r.push([e,t,n])}),r}function dn(e,t){let n=t.trim();if(!n)return[];let r=j.get(n);return r===null?[]:r?un(e,r):on(n).then(t=>t?un(e,t):[])}function fn(){return p({type:`codeBlock`,attr:`fenceStyle`,default:null,toDOM:e=>e==null?null:[`data-fence-style`,e],parseDOM:e=>{let t=e.getAttribute(`data-fence-style`);return t===`tilde`||t===`indented`||t===`dollar`?t:null}})}function pn(){return p({type:`codeBlock`,attr:`fenceLength`,default:null,toDOM:e=>e==null?null:[`data-fence-length`,String(e)],parseDOM:e=>{let t=e.getAttribute(`data-fence-length`);if(t==null)return null;let n=Number.parseInt(t,10);return Number.isSafeInteger(n)&&n>3?n:null}})}function mn(e){return{language:e[1]||``,fenceStyle:`tilde`}}function hn(){return Fe({regex:/^~~~(\S*)\s$/,type:`codeBlock`,attrs:mn})}function gn(){return Ne({regex:/^~~~(\S*)$/,type:`codeBlock`,attrs:mn})}function _n(){return Ne({regex:/^\$\$$/,type:`codeBlock`,attrs:()=>({language:`math`,fenceStyle:`dollar`})})}function vn(){return _(de(),fn(),pn(),hn(),gn(),_n())}function yn(e,t){return(n,r)=>{if(r){let i=x.create(n.doc,e,t);r(n.tr.setSelection(i))}return!0}}function bn(e,t,n){return(r,i)=>{if(i){let a=x.between(e,t,n);i(r.tr.setSelection(a))}return!0}}function xn(e){return(t,n)=>{if(!e.trim())return!1;let r=Y(e,{nodes:Bo(t.schema)}).content;if(r.childCount===0)return!1;let i=r.childCount===1&&r.child(0).type.name===`paragraph`?new ze(r,1,1):new ze(r,0,ze.maxOpen(r).openEnd);if(n){let e=t.tr,r=e.selection;(!g(r)||!r.empty)&&e.setSelection(x.near(r.$from)),n(e.replaceSelection(i).scrollIntoView())}return!0}}function Sn(e){return(t,n)=>{if(!e)return!1;let r=t.selection.$from;if(r.parent.type.spec.code)return!1;if(n){let i=r.parentOffset,a=i===0?``:r.parent.textBetween(i-1,i),o=a!==``&&!/\s/u.test(a),s=t.tr.insertText(o?` ${e}`:e);Ie(s),n(s.scrollIntoView())}return!0}}function Cn(){return(e,t)=>(t&&t(e.tr.scrollIntoView()),!0)}function wn(){return s({insertMarkdown:xn,insertTrigger:Sn,scrollIntoView:Cn,selectText:yn,selectTextBetween:bn})}const Tn=(e,t,n)=>{let{selection:r}=e;return r.empty||n?.composing?!1:(t?.(e.tr.setSelection(x.near(r.$head))),!0)};function En(){return v(u({Escape:Tn}),t.low)}function Dn(){return p({type:`doc`,attr:`frontmatter`,default:null})}function On(){return m({name:`heading`,whitespace:`pre`})}function kn(){return p({type:`heading`,attr:`setextUnderline`,default:null,toDOM:e=>e==null?null:[`data-setext-underline`,String(e)],parseDOM:e=>{let t=e.getAttribute(`data-setext-underline`);if(t==null)return null;let n=Number.parseInt(t,10);return Number.isSafeInteger(n)&&n>0?n:null}})}function An(){return p({type:`heading`,attr:`closingHashes`,default:null,toDOM:e=>e==null?null:[`data-closing-hashes`,String(e)],parseDOM:e=>{let t=e.getAttribute(`data-closing-hashes`);if(t==null)return null;let n=Number.parseInt(t,10);return Number.isSafeInteger(n)&&n>0?n:null}})}function M(e){return ue(se({type:`heading`,attrs:{level:e}}))}const jn=(e,t,n)=>ae(e,n)?.parent.type.name===`heading`&&ce()(e,t,n);function Mn(){return u({"Mod-1":M(1),"Mod-2":M(2),"Mod-3":M(3),"Mod-4":M(4),"Mod-5":M(5),"Mod-6":M(6),Backspace:jn})}function Nn(){return _(He(),On(),kn(),An(),Ve(),Be(),Mn())}function Pn(e,t){return t(e.state,e.dispatch,e)}const Fn=new Set([`mdMark`,`mdLinkUri`,`mdLinkTitle`]);function In(e,t){if(t<0||t+1>e.doc.content.size)return;let n=e.doc.resolve(t),r=n.parent.maybeChild(n.index());if(!(r==null||!r.isText))return r.marks}function N(e,t){let n=In(e,t);return n!=null&&n.some(e=>Fn.has(e.type.name))}function Ln(e,t){if(t<0||t>e.doc.content.size)return!1;let n=e.doc.resolve(t);return n.parent.isTextblock&&!n.parent.type.spec.code}function P(e,t){if(!Ln(e,t))return;let n=e.doc.resolve(t).start(),r=t;for(;r>n&&N(e,r-1);)r--;return r<t?{from:r,to:t}:void 0}function F(e,t){if(!Ln(e,t))return;let n=e.doc.resolve(t).end(),r=t;for(;r<n&&N(e,r);)r++;return r>t?{from:t,to:r}:void 0}function Rn(e,t){return N(e,t-1)&&N(e,t)}function zn(e,t){if(!Rn(e,t))return;let n=P(e,t),r=F(e,t);if(!(n==null||r==null))return{from:n.from,to:r.to}}function Bn(e,t,n){let r=In(e,t);return r!=null&&n.isInSet(r)}function Vn(e,t){let n=In(e,t);if(n==null)return;let r=te(e.schema,`mdPack`),i=n.filter(e=>e.type===r);if(i.length===0)return;let a=e.doc.resolve(t),o=a.start(),s=a.end(),c;for(let n of i){let r=t;for(;r>o&&Bn(e,r-1,n);)r--;let i=t+1;for(;i<s&&Bn(e,i,n);)i++;(c==null||i-r<c.to-c.from)&&(c={from:r,to:i})}return c}function I(e,t,n){let r=Vn(e,n===`from`?t.from:t.to-1);return r==null?!1:n===`from`?r.from===t.from:r.to===t.to}function Hn(e,t,n){let r=I(e,t,`from`),i=I(e,t,`to`);return r&&!i?t.from:i&&!r?t.to:n-t.from<=t.to-n?t.from:t.to}function Un(e,t,n,r){if(!Ln(e,n))return n;let i=zn(e,n);if(i!=null)return r?Hn(e,i,n):n>=t?i.to:i.from;if(!r)return n;let a=P(e,n);if(a!=null&&I(e,a,`from`))return a.from;let o=F(e,n);return o!=null&&I(e,o,`to`)?o.to:n}function Wn(e,t){if(!Ln(e,t))return;let n=N(e,t-1),r=N(e,t);if(n!==r)return r?`left`:`right`}function Gn(e,t){let n=Vn(e,t);if(n==null)return[];let r=F(e,n.from),i=P(e,n.to),a=[];return i!=null&&a.push(i),r!=null&&(i==null||r.from!==i.from)&&a.push(r),a}const Kn=new b(`meowdown-hidden-run-snap`),qn=new b(`meowdown-hidden-run-beforeinput`);function Jn(){let e=!1;return new y({key:Kn,props:{handleDOMEvents:{compositionstart:()=>(e=!0,!1),compositionend:()=>(e=!1,!1)}},appendTransaction:(t,n,r)=>{if(e||D(r)!==`hide`)return null;let i=r.selection;if(!g(i))return null;let a=t.some(e=>e.getMeta(`pointer`)!=null);if(i.empty){let e=Un(r,n.selection.head,i.head,a);return e===i.head?null:r.tr.setSelection(x.create(r.doc,e))}let o=zn(r,i.from)?.from??i.from,s=zn(r,i.to)?.to??i.to;if(o===i.from&&s===i.to)return null;let c=i.anchor===i.from?o:s,l=i.head===i.from?o:s;return r.tr.setSelection(x.create(r.doc,c,l))}})}const Yn=(e,t)=>{if(D(e)!==`hide`)return!1;let n=e.selection;if(!g(n)||!n.empty)return!1;let r=Un(e,n.head,n.head,!0);return r===n.head||t?.(e.tr.setSelection(x.create(e.doc,r))),!1};function Xn(e){return(t,n)=>{if(D(t)!==`hide`)return!1;let r=t.selection;if(!g(r)||!r.empty)return!1;let i=r.$head;if(!i.parent.isTextblock||i.parent.type.spec.code)return!1;let a=e===-1?P(t,r.head):F(t,r.head);if(a==null)return!1;let o=Gn(t,e===-1?a.to-1:a.from),s=t.tr;if(o.length===0)s.delete(a.from,a.to);else for(let e of o)s.delete(e.from,e.to);return n?.(s),!0}}const Zn=Xn(-1),Qn=Xn(1);function $n(){return new y({key:qn,props:{handleDOMEvents:{beforeinput:(e,t)=>{if(e.composing)return!1;let n=t.inputType===`deleteContentBackward`?Zn:t.inputType===`deleteContentForward`?Qn:void 0;return n==null||!Pn(e,n)?!1:(t.preventDefault(),!0)}}}})}function er(){return _(h(Jn()),h($n()),v(u({Enter:Yn,Backspace:Zn,Delete:Qn}),t.highest))}function tr(){return p({type:`horizontalRule`,attr:`marker`,default:null,toDOM:e=>e?[`data-hr-marker`,e]:null,parseDOM:e=>e.getAttribute(`data-hr-marker`)})}function nr(){return _(Ue(),tr())}function rr(){return m({name:`htmlComment`,group:`block`,atom:!0,selectable:!1,attrs:{content:{default:``}},toDOM:e=>[`div`,{"data-html-comment":e.attrs.content,style:`display: none`}],parseDOM:[{tag:`div[data-html-comment]`,getAttrs:e=>({content:e.getAttribute(`data-html-comment`)??``})}]})}function ir(e){let[t,n,r]=e;return[t,n,r.map(e=>e.toJSON())]}function ar(e,t){let[n,r,i]=t;return[n,r,i.map(t=>Re.fromJSON(e,t))]}function or(e,t){if(e===t)return!0;if(e.length!==t.length)return!1;for(let n=0;n<e.length;n++)if(!e[n].eq(t[n]))return!1;return!0}var L=class e extends Ye{constructor(e){super(),this.chunks=e}apply(e){if(this.chunks.length===0)return Xe.ok(e);let t=e.content.size,n;for(let[r,i,a]of this.chunks){if(r>=i)continue;let o=Math.max(0,Math.min(r,t)),s=Math.max(o,Math.min(i,t));if(o>=s)continue;let c=Re.setFrom(a);e.nodesBetween(o,s,(t,r)=>{if(!t.isText)return!0;let i=Math.max(o,r),a=Math.min(s,r+t.nodeSize);if(i>=a)return!1;let l=t.marks;if(or(l,c))return!1;n??=new Ze(e);for(let e of l)n.removeMark(i,a,e);for(let e of c)n.addMark(i,a,e);return!1})}return Xe.ok(n?n.doc:e)}invert(e){if(this.chunks.length===0)return sr;let t=this.chunks[0][0],n=this.chunks[0][1];for(let[,e]of this.chunks)e>n&&(n=e);let r=e.content.size,i=Math.max(0,Math.min(t,r)),a=Math.max(i,Math.min(n,r));return new Je(i,a,e.slice(i,a),!1)}map(e){return null}toJSON(){return{stepType:`batchSetMark`,chunks:this.chunks.map(ir)}}static fromJSON(t,n){let r=n.chunks;return new e(r.map(e=>ar(t,e)))}};Ye.jsonID(`batchSetMark`,L);const sr=new L([]),cr=new Set([`com`,`br`,`net`,`jp`,`org`,`in`,`de`,`ru`,`it`,`fr`]),lr=/^[a-z0-9](?:[a-z0-9-]*[a-z0-9])?$/i;function ur(e){let t=e.indexOf(`/`);return t===-1?e:e.slice(0,t)}function dr(e){let t=e.split(`.`);if(t.length<2)return!1;let n=t[t.length-1].toLowerCase();if(!cr.has(n)||t[t.length-2].length<3)return!1;for(let e of t)if(e.length>63||!lr.test(e))return!1;return!0}function fr(e){if(/^[a-z][a-z0-9+.-]*:/i.test(e))return e;if(/^[^\s@]+@[^\s@]+$/.test(e))return`mailto:${e}`;if(/^www\./i.test(e)||dr(ur(e)))return`https://${e}`}function R(e){return e===32||e===9||e===10||e===13}const pr=/^[a-z0-9-]+(?:\.[a-z0-9-]+)+(?:\/[^\s<]*)?/i,mr=/[\s(*_~]/;function hr(e){return e>=48&&e<=57||e>=65&&e<=90||e>=97&&e<=122||e===45}function gr(e,t,n){let r=0;for(let i=0;i<t;i++)e[i]===n&&r++;return r}function _r(e){let t=e.length;for(;;){let n=e[t-1];if(/[?!.,:*_~]/.test(n)||n===`)`&&gr(e,t,`)`)>gr(e,t,`(`))t--;else if(n===`;`){let n=/&(?:#\d+|#x[a-f\d]+|\w+);$/.exec(e.slice(0,t));if(!n)break;t=n.index}else break}return t}const vr={parseInline:[{name:`BareAutolink`,before:`Link`,parse(e,t,n){if(!hr(t)||e.hasOpenLink)return-1;let r=e.slice(n-1,n);if(r!==``&&!mr.test(r))return-1;let i=pr.exec(e.slice(n,e.end));if(!i)return-1;let a=_r(i[0]);return a===0||!dr(ur(i[0].slice(0,a)))?-1:e.addElement(e.elt(`URL`,n,n+a))}}]};function yr(e){return e>=48&&e<=57||e>=65&&e<=90||e>=97&&e<=122||e===45||e===95||e>127&&/[\p{L}\p{N}]/u.test(String.fromCharCode(e))}function br(e){return e>=65&&e<=90||e>=97&&e<=122||e>127&&/\p{L}/u.test(String.fromCharCode(e))}const xr={defineNodes:[{name:`Hashtag`}],parseInline:[{name:`Hashtag`,parse(e,t,n){if(t!==35||!/\s|^$/.test(e.slice(n-1,n)))return-1;let r=n+1,i=!1;for(;r<e.end;){let t=e.char(r);if(!yr(t))break;i||=br(t),r++}return i?e.addElement(e.elt(`Hashtag`,n,r)):-1}}]},Sr={resolve:`Highlight`,mark:`HighlightMark`},Cr=/[!"#$%&'()*+,\-./:;<=>?@[\\\]^_`{|}~\u{A1}\u{2010}-\u{2027}]/u,wr={defineNodes:[{name:`Highlight`},{name:`HighlightMark`}],parseInline:[{name:`Highlight`,after:`Emphasis`,parse(e,t,n){if(t!==61||e.char(n+1)!==61||e.char(n+2)===61)return-1;let r=e.slice(n-1,n),i=e.slice(n+2,n+3),a=/\s|^$/.test(r),o=/\s|^$/.test(i),s=Cr.test(r),c=Cr.test(i);return e.addDelimiter(Sr,n,n+2,!o&&(!c||a||s),!a&&(!s||o||c))}}]};function Tr(e){return e>=48&&e<=57}function Er(e){return e.next!==36||e.text.charCodeAt(e.pos+1)!==36||e.text.charCodeAt(e.pos+2)===36?!1:e.skipSpace(e.pos+2)===e.text.length}function Dr(e){let t=e.depth;return typeof t==`number`?t:2**53-1}const Or={defineNodes:[{name:`InlineMath`},{name:`InlineMathMark`},{name:`BlockMath`,block:!0},{name:`BlockMathMark`}],parseBlock:[{name:`BlockMath`,before:`FencedCode`,parse(e,t){if(!Er(t))return!1;let n=e.lineStart+t.pos,r=[e.elt(`BlockMathMark`,n,n+2)];for(let n=!0,i=!0,a=!1;!(!e.nextLine()||Dr(t)<e.depth);n=!1){if(Er(t)){i&&a&&r.push(e.elt(`CodeText`,e.lineStart-1,e.lineStart)),r.push(e.elt(`BlockMathMark`,e.lineStart+t.pos,e.lineStart+t.pos+2)),e.nextLine();break}a=!0,n||(r.push(e.elt(`CodeText`,e.lineStart-1,e.lineStart)),i=!1);let o=e.lineStart+t.basePos,s=e.lineStart+t.text.length;o<s&&(r.push(e.elt(`CodeText`,o,s)),i=!1)}return e.addElement(e.elt(`BlockMath`,n,e.prevLineEnd(),r)),!0},endLeaf(e,t){return Er(t)}}],parseInline:[{name:`InlineMath`,after:`InlineCode`,parse(e,t,n){if(t!==36||e.char(n-1)===36)return-1;let r=e.char(n+1)===36?2:1;if(e.char(n+r)===36)return-1;let i=n+r;if(R(e.char(i)))return-1;for(let t=i;t<e.end;t++){let a=e.char(t);if(a===10)return-1;if(a===92){t++;continue}if(a!==36)continue;let o=1;for(;e.char(t+o)===36;)o++;if(o!==r||R(e.char(t-1))||Tr(e.char(t+o)))return-1;let s=t+o;return e.addElement(e.elt(`InlineMath`,n,s,[e.elt(`InlineMathMark`,n,i),e.elt(`InlineMathMark`,t,s)]))}return-1}}]},kr=/^[a-z][a-z0-9+.-]*:\/\/[^\s<]+/i;function Ar(e){return e>=65&&e<=90||e>=97&&e<=122}const jr={parseInline:[{name:`SchemeAutolink`,after:`Autolink`,parse(e,t,n){if(!Ar(t)||e.hasOpenLink)return-1;let r=e.slice(n-1,n);if(r!==``&&!mr.test(r))return-1;let i=kr.exec(e.slice(n,e.end));if(!i)return-1;let a=_r(i[0]);return a<=i[0].indexOf(`://`)+3?-1:e.addElement(e.elt(`URL`,n,n+a))}}]},Mr={defineNodes:[{name:`Wikilink`},{name:`WikilinkMark`}],parseInline:[{name:`Wikilink`,before:`Link`,parse(e,t,n){if(t!==91||e.char(n+1)!==91)return-1;let r=!1;for(let t=n+2;t<e.end-1;t++){let i=e.char(t);if(i===93){if(e.char(t+1)!==93||!r)return-1;let i=t+2;return e.addElement(e.elt(`Wikilink`,n,i,[e.elt(`WikilinkMark`,n,n+2),e.elt(`WikilinkMark`,t,i)]))}if(i===91||i===10)return-1;i!==32&&i!==9&&(r=!0)}return-1}}]};function Nr(e){return e.end}const Pr=$e.configure([Qe,xr,Mr,vr,jr,wr,Or]),Fr=Pr.configure({parseInline:[{name:`SkipInline`,before:`Escape`,parse:Nr}]});function z(e){return Pr.parseInline(e,0)}function B(e,t,n=[]){for(let r of e)t(r)&&n.push(r),B(r.children,t,n);return n}function Ir(e){let t={};for(let n of e.nodeSet.types)t[n.name]=n.id;return t}const V=Ir(Pr),Lr=/^<!--\s*(\{[^}]*\})\s*-->$/,Rr=/<!--\s*\{[^}]*\}\s*-->$/;function zr(e){let t=Lr.exec(e.trim());if(!t)return;let n;try{n=JSON.parse(t[1])}catch{return}if(typeof n!=`object`||!n)return;let r=Br(n);return Object.keys(r).length>0?r:void 0}function Br(e){let t={},{width:n,height:r}=e;return typeof n==`number`&&Number.isFinite(n)&&n>0&&(t.width=Math.round(n)),typeof r==`number`&&Number.isFinite(r)&&r>0&&(t.height=Math.round(r)),t}function Vr(e){return`<!-- ${JSON.stringify(e)} -->`}function Hr(e){return e.replace(Rr,``)}function Ur(e){let t=e.replace(/^\[\[/,``).replace(/\]\]$/,``),n=t.indexOf(`|`);return n<0?{target:t.trim(),display:``}:{target:t.slice(0,n).trim(),display:t.slice(n+1).trim()}}function Wr(){return e=>{let t=e.attrs,n=document.createElement(`span`);n.className=`md-wikilink-view md-atom-view`;let r=document.createElement(`span`);r.className=`md-wikilink-view-preview md-atom-view-preview`,r.contentEditable=`false`,r.dataset.testid=`wikilink`,n.appendChild(r);let i=document.createElement(`span`);i.className=`md-wikilink-view-label`,i.contentEditable=`false`,i.textContent=t.display||t.target,r.appendChild(i);let a=document.createElement(`span`);return a.className=`md-wikilink-view-content md-atom-view-content`,n.appendChild(a),{dom:n,contentDOM:a,ignoreMutation:e=>!a.contains(e.target)}}}function Gr(){return f({name:`mdWikilink`,constructor:Wr()})}const Kr=new Map([[V.Emphasis,`mdEm`],[V.StrongEmphasis,`mdStrong`],[V.InlineCode,`mdCode`],[V.Strikethrough,`mdDel`],[V.Highlight,`mdHighlight`],[V.EmphasisMark,`mdMark`],[V.CodeMark,`mdMark`],[V.LinkMark,`mdMark`],[V.StrikethroughMark,`mdMark`],[V.HighlightMark,`mdMark`],[V.URL,`mdLinkUri`],[V.LinkTitle,`mdLinkTitle`],[V.Hashtag,`mdTag`],[V.WikilinkMark,`mdMark`]]);function qr(e,t,n){let r=z(t),i=[];return Yr(r,[],0,t.length,t,e,i,n),i}function Jr(e){return e.slice(1,-1).replaceAll(/\\(.)/g,`$1`)}function Yr(e,t,n,r,i,a,o,s){let c=n;for(let n=0;n<e.length;n++){let r=e[n];r.from>c&&H(o,c,r.from,t);let l=r.type;if(l===V.Link){let e=Qr(r,t,i,a,s);e?H(o,r.from,r.to,e):$r(r,t,i,a,o)}else if(l===V.Image){let s=ei(r,e[n+1],i);ti(r,t,i,a,o,s),s&&n++,c=s?s.to:r.to;continue}else if(l===V.Wikilink)ri(r,t,i,a,o);else if(l===V.InlineMath)ni(r,t,i,a,o);else if(l===V.URL){let e=fr(i.slice(r.from,r.to)),n=e?a.mdLinkText.create({href:e}):a.mdLinkUri.create();H(o,r.from,r.to,[...t,n])}else{let e;l===V.Emphasis?e=`italic`:l===V.StrongEmphasis?e=`bold`:l===V.InlineCode?e=`code`:l===V.Strikethrough?e=`strike`:l===V.Highlight?e=`highlight`:l===V.Autolink&&(e=`autolink`);let n=e?[...t,a.mdPack.create({key:e})]:t,c=Kr.get(l),u=c?[...n,a[c].create()]:n;r.children.length===0?H(o,r.from,r.to,u):Yr(r.children,u,r.from,r.to,i,a,o,s)}c=r.to}c<r&&H(o,c,r,t)}function Xr(e){let t=-1,n=-1,r=null,i=null,a=0;for(let o of e.children)o.type===V.LinkMark?(a++,a===1&&(t=o.to),a===2&&(n=o.from)):o.type===V.URL&&r===null?r=o:o.type===V.LinkTitle&&i===null&&(i=o);return{labelFrom:t,labelTo:n,urlNode:r,titleNode:i}}function Zr(e){let t=e.split(/[?#]/,1)[0],n=t.split(/[/\\]/).findLast(Boolean)??t;try{return decodeURIComponent(n)}catch{return n}}function Qr(e,t,n,r,i){let a=i?.resolveFileLink;if(!a)return;let{labelFrom:o,labelTo:s,urlNode:c,titleNode:l}=Xr(e);if(o<0||s<0||!c)return;let u=n.slice(c.from,c.to);if(!u)return;let d=n.slice(o,s),f=l?Jr(n.slice(l.from,l.to)):``;if(!a({href:u,label:d,title:f}))return;let p=d||Zr(u);return[...t,r.mdFile.create({href:u,name:p,title:f})]}function $r(e,t,n,r,i){let{labelTo:a,urlNode:o,titleNode:s}=Xr(e),c=o?n.slice(o.from,o.to):``,l=s?Jr(n.slice(s.from,s.to)):``,u=c?r.mdLinkText.create({href:c}):null,d=e=>a>=0&&e<a&&u!==null,f=r.mdPack.create({key:`link`,data:{href:c,title:l}}),p=[...t,f],m=e.from;for(let t of e.children){if(t.from>m){let e=d(m)?[...p,u]:p;H(i,m,t.from,e)}let e=d(t.from)?[...p,u]:p;if(t.type===V.Wikilink){ri(t,e,n,r,i),m=t.to;continue}let a=Kr.get(t.type),o=a?[...e,r[a].create()]:e;t.children.length===0?H(i,t.from,t.to,o):Yr(t.children,o,t.from,t.to,n,r,i,void 0),m=t.to}m<e.to&&H(i,m,e.to,p)}function ei(e,t,n){if(!t||t.type!==V.Comment||t.from!==e.to)return;let r=zr(n.slice(t.from,t.to));if(r)return{magic:r,to:t.to}}function ti(e,t,n,r,i,a){let o=e.children.find(e=>e.type===V.URL);if(!o){$r(e,t,n,r,i);return}let s=e.children.filter(e=>e.type===V.LinkMark),c=e.children.find(e=>e.type===V.LinkTitle),l=n.slice(o.from,o.to),u=s.length>=2?n.slice(s[0].to,s[1].from):``,d=c?Jr(n.slice(c.from,c.to)):``,f=a?.magic.width??null,p=a?.magic.height??null,m=a?.to??e.to;H(i,e.from,m,[...t,r.mdImage.create({src:l,alt:u,title:d,width:f,height:p})])}function ni(e,t,n,r,i){let a=e.children.filter(e=>e.type===V.InlineMathMark);if(a.length<2){H(i,e.from,e.to,t);return}let o=n.slice(a[0].to,a[1].from),s=[...t,r.mdPack.create({key:`math`}),r.mdMath.create({formula:o})];H(i,e.from,a[0].to,[...s,r.mdMark.create()]),H(i,a[0].to,a[1].from,s),H(i,a[1].from,e.to,[...s,r.mdMark.create()])}function ri(e,t,n,r,i){let{target:a,display:o}=Ur(n.slice(e.from,e.to));H(i,e.from,e.to,[...t,r.mdWikilink.create({target:a,display:o})])}function H(e,t,n,r){if(t>=n)return;let i=e.at(-1);if(i&&i[1]===t&&or(i[2],r)){e[e.length-1]=[i[0],n,i[2]];return}e.push([t,n,r])}const ii=`inline-marks-applied`;let ai=0,oi=0;function si(e,t){let n=1/0,r=-1/0;for(let t of e)for(let e of t.mapping.maps)e.forEach((e,t,i,a)=>{i<n&&(n=i),a>r&&(r=a)});let i=t.doc.content.size;return n>r?{from:0,to:i}:{from:Math.max(0,n),to:Math.min(i,r)}}function ci(e){let t=new WeakMap;function n(n,r,i){let a=t.get(n);if(a?oi++:(ai++,a=qr(Ro(i),n.textContent,e),t.set(n,a)),r===0)return a;let o=[];for(let[e,t,n]of a)o.push([e+r,t+r,n]);return o}function r(e,t){let r=[];return e.doc.nodesBetween(t.from,t.to,(t,i)=>{if(t.type.spec.code)return!1;if(!t.isTextblock)return!0;if(t.childCount===0)return!1;let a=n(t,i+1,e.schema);return a.length>0&&r.push(...a),!1}),r}return new y({key:new b(`inline-mark`),appendTransaction(e,t,n){for(let t of e)if(t.getMeta(ii))return null;let i=r(n,si(e,n));if(i.length===0)return null;let a=n.tr.step(new L(i));return a.setMeta(ii,!0),a.setMeta(`addToHistory`,!1),a},view(e){return e.dispatch(li(e.state)),{}}})}function li(e){return e.tr.setMeta(`inline-marks-trigger`,!0)}function ui(e){return h(ci(e))}function di(){return d({name:`mdImage`,inclusive:!1,attrs:{src:{default:``},alt:{default:``},title:{default:``},width:{default:null},height:{default:null}},toDOM:()=>[`span`,{class:`md-image`},0],parseDOM:[{tag:`span.md-image`}]})}function fi(){return d({name:`mdMark`,inclusive:!1,toDOM:()=>[`span`,{class:`md-mark`},0],parseDOM:[{tag:`span.md-mark`}]})}function pi(){return d({name:`mdEm`,toDOM:()=>[`em`,0],parseDOM:[{tag:`em`}]})}function mi(){return d({name:`mdStrong`,toDOM:()=>[`strong`,0],parseDOM:[{tag:`strong`}]})}function hi(){return d({name:`mdCode`,toDOM:()=>[`code`,0],parseDOM:[{tag:`code`}]})}function gi(){return d({name:`mdLinkText`,inclusive:!1,attrs:{href:{default:``}},toDOM:e=>[`a`,{class:`md-link`,href:e.attrs.href},0],parseDOM:[{tag:`a`,getAttrs:e=>({href:e.getAttribute(`href`)??``})}]})}function _i(){return d({name:`mdLinkUri`,inclusive:!1,toDOM:()=>[`span`,{class:`md-link-uri`},0],parseDOM:[{tag:`span.md-link-uri`}]})}function vi(){return d({name:`mdLinkTitle`,inclusive:!1,toDOM:()=>[`span`,{class:`md-link-title`},0],parseDOM:[{tag:`span.md-link-title`}]})}function yi(){return d({name:`mdDel`,toDOM:()=>[`del`,0],parseDOM:[{tag:`del`}]})}function bi(){return d({name:`mdHighlight`,toDOM:()=>[`mark`,0],parseDOM:[{tag:`mark`}]})}function xi(){return d({name:`mdTag`,toDOM:()=>[`span`,{class:`md-tag`},0],parseDOM:[{tag:`span.md-tag`}]})}function Si(){return d({name:`mdWikilink`,inclusive:!1,attrs:{target:{default:``},display:{default:``}},toDOM:()=>[`span`,{class:`md-wikilink`},0],parseDOM:[{tag:`span.md-wikilink`}]})}function Ci(){return d({name:`mdFile`,inclusive:!1,attrs:{href:{default:``},name:{default:``},title:{default:``}},toDOM:()=>[`span`,{class:`md-file`},0],parseDOM:[{tag:`span.md-file`}]})}function wi(){return d({name:`mdMath`,inclusive:!1,attrs:{formula:{default:``}},toDOM:()=>[`span`,{class:`md-math`},0],parseDOM:[{tag:`span.md-math`}]})}function Ti(){return d({name:`mdPack`,excludes:``,inclusive:!1,attrs:{key:{},data:{default:null}},toDOM:e=>[`span`,{class:`md-pack`,"data-key":e.attrs.key},0],parseDOM:[{tag:`span.md-pack`}]})}function Ei(){return _(fi(),pi(),mi(),hi(),gi(),_i(),vi(),yi(),bi(),xi(),Si(),di(),Ci(),wi(),Ti())}function Di(e,t,n=0){let r=n,i=0;for(let n=0;n<e.length;n++)e.charCodeAt(n)===t?(i++,i>r&&(r=i)):i=0;return r}function Oi(e,t=0){return Di(e,96,t)}const U={em:{node:V.Emphasis,delim:`*`},strong:{node:V.StrongEmphasis,delim:`**`},code:{node:V.InlineCode,delim:"`"},del:{node:V.Strikethrough,delim:`~~`},highlight:{node:V.Highlight,delim:`==`}},ki=new Set([V.EmphasisMark,V.CodeMark,V.LinkMark,V.StrikethroughMark,V.HighlightMark]);function Ai(e){return[e.children[0],e.children.at(-1)]}function ji(e){let{type:t,children:n}=e;if(t===V.Emphasis||t===V.StrongEmphasis||t===V.Strikethrough||t===V.Highlight)return[n[0].to,n.at(-1).from];if(t===V.Link||t===V.Image){let e=n.find((e,t)=>t>0&&e.type===V.LinkMark);return e?[n[0].to,e.from]:null}return null}function Mi(e,t,n){for(let r of e){if(r.to<=t||r.from>=n||t<=r.from&&r.to<=n)continue;let i=ji(r);return i&&i[0]<=t&&n<=i[1]?Mi(r.children,t,n):Mi(e,Math.min(t,r.from),Math.max(n,r.to))}return[t,n]}function Ni(e,t,n){for(let r of e)if(!(r.to<=t||r.from>=n)&&(t>r.from||r.to>n))return Ni(e,Math.min(t,r.from),Math.max(n,r.to));return[t,n]}function Pi(e,t,n){for(;t<n&&R(e.charCodeAt(t));)t++;for(;n>t&&R(e.charCodeAt(n-1));)n--;return[t,n]}function Fi(e,t,n,r){let i=B(z(e),e=>e.type===r.node||ki.has(e.type));for(let r=t;r<n;r++)if(!R(e.charCodeAt(r))&&i.every(e=>!(e.from<=r&&r<e.to)))return!1;return!0}function Ii(e,t,n,r,i){let a=z(e),o=B(a,e=>e.type===r.node);return i?zi(e,o,t,n):Li(e,a,o,t,n,r)}function Li(e,t,n,r,i,a){for(let e=0;e!==i-r;){e=i-r,[r,i]=Mi(t,r,i);for(let e of n)e.to===r&&(r=e.from),e.from===i&&(i=e.to)}let o=[];for(let e of n)if(r<=e.from&&e.to<=i){let[t,n]=Ai(e);o.push({from:t.from,to:t.to,insert:``}),o.push({from:n.from,to:n.to,insert:``})}let[s,c]=Ri(e,r,i,o,a);return o.push({from:r,to:r,insert:s},{from:i,to:i,insert:c}),o}function Ri(e,t,n,r,i){if(i.node!==V.InlineCode)return[i.delim,i.delim];let a=e.slice(t,n);for(let e of[...r].sort((e,t)=>t.from-e.from))a=a.slice(0,e.from-t)+a.slice(e.to-t);let o="`".repeat(Oi(a)+1),s=a.startsWith("`")||a.endsWith("`")?` `:``;return[o+s,s+o]}function zi(e,t,n,r){let i=[];for(let a of t){if(a.to<=n||a.from>=r)continue;let[t,o]=Ai(a),s=Math.max(n,t.to),c=Math.min(r,o.from);for(s>=c&&([s,c]=[t.to,o.from]),[s,c]=Ni(a.children.slice(1,-1),s,c);s>t.to&&R(e.charCodeAt(s-1));)s--;for(;c<o.from&&R(e.charCodeAt(c));)c++;s>t.to?i.push({from:s,to:s,insert:e.slice(o.from,o.to)}):i.push({from:t.from,to:t.to,insert:``}),c<o.from?i.push({from:c,to:c,insert:e.slice(t.from,t.to)}):i.push({from:o.from,to:o.to,insert:``})}return i}function Bi(e,t,n){let{delim:r}=n,i=r.length;if(e.slice(t-i,t)===r&&e.startsWith(r,t)&&e[t-i-1]!==r[0]&&e[t+i]!==r[0])return{kind:`unwrap`,from:t-i,to:t+i};let a=z(e),o=B(a,e=>e.type===n.node).findLast(e=>e.from<=t&&t<=e.to);if(o){let[e,n]=Ai(o);return{kind:`move`,pos:t===o.from?e.to:t===o.to?n.from:o.to}}return Vi(a,t)||e[t-1]===r[0]||e[t]===r[0]?null:{kind:`insert`,pos:t}}function Vi(e,t){for(let n of e)if(n.from<t&&t<n.to){let e=ji(n);return!e||t<e[0]||t>e[1]||Vi(n.children,t)}return!1}function W(e){return(t,n)=>{if(t.selection.empty)return Hi(e,t,n);let{from:r,to:i,anchor:a,head:o}=t.selection,s=[];t.doc.nodesBetween(r,i,(t,n)=>{if(t.type.spec.code)return!1;if(!t.isTextblock)return!0;let a=t.textContent,o=n+1,[c,l]=Pi(a,Math.max(r-o,0),Math.min(i-o,a.length));return c<l&&s.push({text:a,base:o,from:c,to:l,active:Fi(a,c,l,e)}),!1});let c=s.length>0&&s.every(e=>e.active),l=s.filter(e=>c||!e.active).flatMap(t=>Ii(t.text,t.from,t.to,e,c).map(e=>({from:e.from+t.base,to:e.to+t.base,insert:e.insert})));if(l.length===0)return!1;if(n){let e=t.tr;l.sort((e,t)=>t.from-e.from||t.to-e.to);for(let t of l)t.insert?e.insertText(t.insert,t.from,t.to):e.delete(t.from,t.to);e.setSelection(x.create(e.doc,e.mapping.map(a,a<=o?1:-1),e.mapping.map(o,o<a?1:-1))),n(e.scrollIntoView())}return!0}}function Hi(e,t,n){let{$from:r}=t.selection,i=r.parent;if(!i.isTextblock||i.type.spec.code)return!1;let a=Bi(i.textContent,r.parentOffset,e);if(!a)return!1;if(n){let i=r.start(),o=t.tr;a.kind===`unwrap`&&o.delete(i+a.from,i+a.to),a.kind===`move`&&o.setSelection(x.create(o.doc,i+a.pos)),a.kind===`insert`&&(o.insertText(e.delim+e.delim,i+a.pos),o.setSelection(x.create(o.doc,i+a.pos+e.delim.length))),n(o.scrollIntoView())}return!0}function Ui(){return s({toggleEm:()=>W(U.em),toggleStrong:()=>W(U.strong),toggleCode:()=>W(U.code),toggleDel:()=>W(U.del),toggleHighlight:()=>W(U.highlight)})}function Wi(){return u({"Mod-b":W(U.strong),"Mod-i":W(U.em),"Mod-e":W(U.code),"Mod-Shift-x":W(U.del),"Mod-Shift-h":W(U.highlight)})}function Gi(){return _(Ui(),Wi())}function Ki(e,t,n){let r;return e.doc.nodesBetween(t.from,t.to,(e,i)=>(e.isText&&e.marks.some(e=>e.type.name===n)&&(r={from:Math.max(i,t.from),to:Math.min(i+e.nodeSize,t.to)}),!0)),r}function G(e,t){let n=T(e,t,`mdLinkText`),r=T(e,t,`mdPack`,{key:`link`})??T(e,t,`mdPack`,{key:`autolink`}),i=r??n;if(!i)return;let a=r?.mark.attrs,o=n?.mark.attrs?.href??``;if(!r||a?.key!==`link`){let t={from:i.from,to:i.to};return{unit:t,text:a?.key===`autolink`?Ki(e,t,`mdLinkText`)??{from:i.from+1,to:i.to-1}:t,href:o,title:``}}let s=Ki(e,i,`mdLinkUri`),c=s?s.from-2:i.to-3,l=s?s.from:i.to-1,u={from:i.from+1,to:c};return{unit:{from:i.from,to:i.to},text:u,label:u,dest:{from:l,to:i.to-1},href:a.data.href,title:a.data.title}}function qi(e){let t=e.trim();return t?fr(t)??t:``}function Ji(e,t){return e+(t?` "${t.replaceAll(/(["\\])/g,String.raw`\$1`)}"`:``)}function Yi(e){let{selection:t}=e,{$from:n,$to:r,empty:i}=t;if(i||!n.sameParent(r)||!g(t))return;let a=n.parent;if(!a.isTextblock||a.type.spec.code)return;let o=n.start(),[s,c]=Pi(a.textContent,n.parentOffset,r.parentOffset);if(!(s>=c))return{from:o+s,to:o+c}}function Xi({href:e,title:t,wrapText:n=!0}={}){return(r,i)=>{let a=Yi(r);if(!a)return!1;if(i){let{from:o,to:s}=a,c=r.tr,l=`](${Ji(qi(e??``),t??``)})`;c.insertText(l,s).insertText(`[`,o);let u=s+1+l.length;c.setSelection(n?x.create(c.doc,o,u):x.create(c.doc,u)),c.scrollIntoView(),i(c)}return!0}}function Zi(e){return(t,n)=>{let r=G(t,t.selection.from);if(!r?.dest)return!1;let i=Ji(qi(e.href??r.href),e.title??r.title);return n&&n(t.tr.insertText(i,r.dest.from,r.dest.to).scrollIntoView()),!0}}function Qi(){return(e,t)=>{let n=G(e,e.selection.from);return n?.label?(t&&t(e.tr.delete(n.label.to,n.unit.to).delete(n.unit.from,n.label.from).scrollIntoView()),!0):!1}}function $i(){return s({insertLink:Xi,updateLink:Zi,removeLink:Qi})}function ea(e){return(t,n,r)=>{let i=G(t,t.selection.from);if(i){if(n&&r){let{unit:{from:a,to:o}}=i;n(t.tr.setSelection(x.create(t.doc,a,o)).scrollIntoView()),r.focus(),e({from:a,to:o,link:i})}return!0}let a=Yi(t);if(a){if(n&&r){let{from:i,to:o}=a;n(t.tr.setSelection(x.create(t.doc,i,o)).scrollIntoView()),r.focus(),e({from:i,to:o,link:void 0})}return!0}return!1}}function ta(e){return u({"Mod-k":ea(e)})}function na(e){return e===`)`||e===`*`||e===`+`?e:void 0}function ra(e){return e===`X`?e:void 0}function ia(e){return sa(e)?String(e):void 0}function aa(){return p({type:`list`,attr:`marker`,default:null,splittable:!0,toDOM:e=>{let t=na(e);return t==null?null:[`data-list-marker`,t]},parseDOM:e=>{let t=e.getAttribute(`data-list-marker`);return t===`)`||t===`*`||t===`+`?t:null}})}function oa(){return p({type:`list`,attr:`taskMarker`,default:null,splittable:!0,toDOM:e=>{let t=ra(e);return t==null?null:[`data-list-task-marker`,t]},parseDOM:e=>e.getAttribute(`data-list-task-marker`)===`X`?`X`:null})}function sa(e){return e===2||e===3||e===4}function ca(){return p({type:`list`,attr:`markerGap`,default:1,splittable:!0,toDOM:e=>{let t=ia(e);return t==null?null:[`data-list-marker-gap`,t]},parseDOM:e=>{let t=Number.parseInt(e.getAttribute(`data-list-marker-gap`)??``,10);return sa(t)?t:1}})}function la(e){let t=e.attrs;return{...lt(e),"data-list-marker":na(t.marker),"data-list-task-marker":ra(t.taskMarker),"data-list-marker-gap":ia(t.markerGap)}}function ua(){return o({serializeFragmentWrapper:e=>(...t)=>da(ft(e(...t))),serializeNodeWrapper:e=>(...t)=>{let n=e(...t);return _e(n)?da(ft(n)):n},nodesFromSchemaWrapper:e=>(...t)=>({...e(...t),list:e=>pt({node:e,nativeList:!0,getAttributes:la})})})}function da(e){_e(e)&&fa(e);for(let t of e.children)da(t);return e}function fa(e){if(!e.classList.contains(`prosemirror-flat-list`)||e.getAttribute(`data-list-kind`)!==`task`||e.children.length!==2)return;let t=e.children.item(0);if(!t||!t.classList.contains(`list-marker`))return;let n=ut(t);if(!n)return;let r=e.children.item(1);if(!r||!r.classList.contains(`list-content`))return;let i=r.children.item(0);!i||![`P`,`H1`,`H2`,`H3`,`H4`,`H5`,`H6`].includes(i.tagName)||(e.replaceChildren(...r.children),i.prepend(n))}const pa=[w(/^\s?([*-])\s$/,{kind:`bullet`,collapsed:!1}),w(/^\s?(\d+)\.\s$/,({match:e})=>{let t=e[1],n=t?parseInt(t,10):void 0;return{kind:`ordered`,collapsed:!1,order:n&&n>=2&&Number.isSafeInteger(n)?n:null}}),w(/^\s?\[([\sX]?)\]\s$/i,({match:e})=>({kind:`task`,checked:[`x`,`X`].includes(e[1]),collapsed:!1})),w(/^\s?\+\s$/,{kind:`task`,marker:`+`,checked:!1,collapsed:!1})];function ma(){return _(pa.map(Pe))}function ha(){return C({kind:`task`,marker:`+`})}function ga(){return C({kind:`task`,marker:null})}function _a(e){let{$from:t}=e.selection;for(let e=t.depth;e>0;e--){let n=t.node(e);if(n.type.name===`list`)return n.attrs}return null}function va(){return(e,t,n)=>{let r=_a(e);return(r?.kind===`task`?r.marker===`+`?ga():ha():C({kind:`task`,marker:null,checked:!1}))(e,t,n)}}function ya(){return s({cycleCheckableList:va,wrapInCircleTask:ha,wrapInSquareTask:ga})}function ba(){return(e,t,n)=>{let r=_a(e),i=r?.kind===`task`&&r.marker!==`+`,a;return a=i&&!r?.checked?{kind:`task`,marker:r?.marker??null,checked:!0}:i&&r?.checked?{kind:`bullet`,marker:null,checked:!1}:{kind:`task`,marker:null,checked:!1},C(a)(e,t,n)}}function xa(){return(e,t,n)=>{let r=_a(e),i=r?.kind===`task`&&r.marker===`+`,a;return a=i&&!r?.checked?{kind:`task`,marker:`+`,checked:!0}:i&&r?.checked?{kind:`bullet`,marker:null,checked:!1}:{kind:`task`,marker:`+`,checked:!1},C(a)(e,t,n)}}function Sa(e){return e.type.name===`list`&&e.attrs.kind===`bullet`&&e.childCount>=2&&e.firstChild?.type!==e.type}const Ca=e=>{let t=e.attrs;return t.kind===`task`?{...t,checked:!t.checked}:Sa(e)?{...t,collapsed:!t.collapsed}:t};function wa(){return h(()=>[new y({props:{handleDOMEvents:{mousedown:(e,t)=>dt({view:e,event:t,onListClick:Ca})}}}),ot(),new y({props:{transformCopied:mt}}),st()])}function Ta(){return s({toggleListCollapsed:()=>ct({isToggleable:Sa})})}function Ea(){return u({"Mod-Enter":ba(),"Mod-Shift-Enter":xa(),"Mod-.":ct({isToggleable:Sa}),"Mod-Shift-7":at({kind:`ordered`,collapsed:!1}),"Mod-Shift-8":at({kind:`bullet`,collapsed:!1}),"Mod-Shift-9":at({kind:`task`,checked:!1,collapsed:!1})})}function Da(){return _(rt(),wa(),nt(),et(),ua(),tt(),ma(),Ea(),aa(),oa(),ca(),ya(),Ta())}let Oa;function ka(){return Oa??=import(`katex`).then(e=>e.render),Oa}function Aa(e,t,n,r){try{e(n,t,{displayMode:r,throwOnError:!1,output:`mathml`})}catch(e){t.textContent=String(e)}}var ja=class{#e;#t;#n;#r;constructor(e,t){this.#r=e.attrs.formula,this.#e=document.createElement(`span`),this.#e.className=`md-math-view`,this.#n=document.createElement(`span`),this.#n.className=`md-math-view-preview`,this.#n.dataset.testid=`math-preview`,this.#n.contentEditable=`false`,this.#n.addEventListener(`mousedown`,e=>{e.preventDefault();let n=t.posAtDOM(this.#t,0);if(n<0)return;let r=x.near(t.state.doc.resolve(n),1);t.dispatch(t.state.tr.setSelection(r)),t.focus()}),this.#t=document.createElement(`span`),this.#t.className=`md-math-view-content`,this.#e.appendChild(this.#n),this.#e.appendChild(this.#t),this.#i()}get dom(){return this.#e}get contentDOM(){return this.#t}update(e){let t=e.attrs.formula;return t!==this.#r&&(this.#r=t,this.#i()),!0}ignoreMutation(e){return!this.#t.contains(e.target)}#i(){let e=this.#r;ka().then(t=>{e===this.#r&&Aa(t,this.#n,e,!1)})}};function Ma(){return f({name:`mdMath`,constructor:(e,t)=>new ja(e,t)})}function Na(e){return e===`left`||e===`center`||e===`right`?e:null}function Pa(){return p({type:`tableCell`,attr:`align`,default:null,toDOM:e=>e?[`data-align`,e]:null,parseDOM:e=>Na(e.getAttribute(`data-align`))})}function Fa(){return p({type:`tableHeaderCell`,attr:`align`,default:null,toDOM:e=>e?[`data-align`,e]:null,parseDOM:e=>Na(e.getAttribute(`data-align`))})}function Ia(e){for(let t=0;t<e.childCount;t++){let n=e.child(t);for(let e=0;e<n.childCount;e++)if(n.child(e).type.name===`tableHeaderCell`)return t}return 0}function La(e){return e.child(Ia(e))}function Ra(e,t){return t>=e.childCount?null:e.child(t).attrs.align??null}function za(e,t,n){if(e.childCount===0)return;let r=La(e),i=t+1;for(let t=0;t<e.childCount;t++){let a=e.child(t),o=i+1;for(let e=0;e<a.childCount;e++){let t=a.child(e),i=Ra(r,e);(t.attrs.align??null)!==i&&n.setNodeMarkup(o,void 0,{...t.attrs,align:i}),o+=t.nodeSize}i+=a.nodeSize}}function Ba(e){let t,n;for(let r of e){if(!r.docChanged)continue;t!=null&&n!=null&&(t=r.mapping.map(t,-1),n=r.mapping.map(n,1));let e=r.mapping;for(let[r,i]of e.maps.entries()){let a=e.slice(r+1);i.forEach((e,r,i,o)=>{let s=a.map(i,-1),c=a.map(o,1);t=t==null?s:Math.min(t,s),n=n==null?c:Math.max(n,c)})}}if(!(t==null||n==null))return{from:t,to:n}}function Va(){return new y({key:new b(`table-align-sync`),appendTransaction(e,t,n){if(!e.some(e=>e.docChanged))return;let r=Ba(e);if(!r)return;let i=n.doc,a=Math.max(0,Math.min(r.from,i.content.size)),o=Math.max(a,Math.min(r.to,i.content.size)),s;return i.nodesBetween(a,o,(e,t)=>e.type.name===`table`?(s??=n.tr,za(e,t,s),!1):!0),s?.docChanged?s:void 0}})}function Ha(){return h(Va())}function Ua(e){let{selection:t}=e;if(Ct(t)){let{$anchorCell:e,$headCell:n}=t,r=e.depth-1,i=e.index(),a=n.index();return{table:e.node(r),tablePos:e.before(r),firstColumn:Math.min(i,a),lastColumn:Math.max(i,a)}}let{$from:n}=t;for(let e=n.depth;e>2;e--){let t=n.node(e).type.name;if(t===`tableCell`||t===`tableHeaderCell`){let t=n.index(e-1);return{table:n.node(e-2),tablePos:n.before(e-2),firstColumn:t,lastColumn:t}}}}function Wa(e){return(t,n)=>{let r=Ua(t);if(!r||r.table.childCount===0)return!1;if(n){let{table:i,tablePos:a,firstColumn:o,lastColumn:s}=r,c=Ia(i),l=a+1;for(let e=0;e<c;e++)l+=i.child(e).nodeSize;let u=i.child(c),d=t.tr,f=l+1;for(let t=0;t<u.childCount;t++){let n=u.child(t);t>=o&&t<=s&&(n.attrs.align??null)!==e&&d.setNodeMarkup(f,void 0,{...n.attrs,align:e}),f+=n.nodeSize}n(d)}return!0}}function Ga(e){let t=Ua(e);if(!(!t||t.table.childCount===0))return Ra(La(t.table),t.lastColumn)??void 0}function Ka(){return s({setTableColumnAlign:Wa})}function qa(){return _(Pa(),Fa(),Ha(),Ka())}function Ja(e){let{$from:t}=e.selection;for(let e=t.depth;e>0;e--){let n=t.node(e).type.name;if(n===`tableCell`||n===`tableHeaderCell`)return!0}return!1}const Ya=`paragraph`;function Xa(){return _(m({name:`tableCell`,content:Ya}),m({name:`tableHeaderCell`,content:Ya}))}const Za=(e,t)=>{let{selection:n}=e;return!Ct(n)||!n.isColSelection()||!n.isRowSelection()?!1:St(e,t)};function Qa(){return v(u({Backspace:Za,Delete:Za}),t.high)}function $a(){return _(xt(),bt(),ht(),yt(),Xa(),qa(),vt({allowTableNodeSelection:!0}),gt(),_t(),Qa())}function eo(e){let{selection:t}=e,{$from:n,$to:r}=t;if(oe(t)&&n.depth===0||n.depth>0&&r.depth>0&&n.index(0)===r.index(0))return n.index(0)}function to(e){return(t,n)=>{if(Ja(t))return!1;let r=eo(t);if(r==null)return!1;let i=r+e;if(i<0||i>=t.doc.childCount)return!1;if(n){let{selection:a}=t,o=Math.min(r,i),s=a.$from.posAtIndex(o,0),c=t.doc.child(o),l=t.doc.child(o+1),u=t.tr.replaceWith(s,s+c.nodeSize+l.nodeSize,[l,c]),d=e===-1?-c.nodeSize:l.nodeSize,f=oe(a)?Te.create(u.doc,a.from+d):x.create(u.doc,a.anchor+d,a.head+d);u.setSelection(f),n(u.scrollIntoView())}return!0}}function no(e){return(t,n,r)=>it(e)(t,n,r)||to(e===`up`?-1:1)(t,n,r)}function ro(){return u({"Alt-ArrowUp":no(`up`),"Alt-ArrowDown":no(`down`)})}function io(){return m({name:`paragraph`,content:`inline*`,group:`block`,whitespace:`pre`,parseDOM:[{tag:`p`}],toDOM(){return[`p`,0]}})}function ao(){return _(v(io(),t.highest),wt(),Tt())}const K=new b(`meowdownPendingReplacement`);function q(e){return K.getState(e)?.pending??null}function oo(e,t){switch(e.type){case`start`:return{pending:{from:e.from,to:e.to,mode:e.mode,text:``}};case`append`:return t.pending?{pending:{...t.pending,text:t.pending.text+e.text}}:t;case`accept`:return t.pending?{pending:null,ended:{pending:t.pending,outcome:`accepted`}}:t;case`discard`:return t.pending?{pending:null,ended:{pending:t.pending,outcome:`discarded`}}:t}}const so=new y({key:K,state:{init:()=>({pending:null}),apply:(e,t)=>{let n=e.getMeta(K);if(n)return oo(n,t);if(e.docChanged&&t.pending){let n=e.mapping.mapResult(t.pending.from,1),r=e.mapping.mapResult(t.pending.to,-1),i=Math.min(n.pos,r.pos),a=Math.max(n.pos,r.pos);return(n.deletedAfter&&r.deletedBefore||i>=a)&&t.pending.mode===`replace`?{pending:null,ended:{pending:t.pending,outcome:`discarded`}}:{pending:{...t.pending,from:i,to:a}}}return t}},props:{decorations:e=>{let t=q(e);return!t||t.from>=t.to?null:S.create(e.doc,[De.inline(t.from,t.to,{class:`md-pending-replacement`})])}}});function co(e){return(t,n)=>{let{from:r,to:i,mode:a}=e;return r<0||i>t.doc.content.size||r>i||r===i&&a===`replace`?!1:(n?.(t.tr.setMeta(K,{type:`start`,from:r,to:i,mode:a})),!0)}}function lo(e){return(t,n)=>q(t)?(n?.(t.tr.setMeta(K,{type:`append`,text:e})),!0):!1}function uo(){return(e,t)=>q(e)?(t?.(e.tr.setMeta(K,{type:`discard`})),!0):!1}function fo(e={}){return(t,n)=>{let r=q(t);if(!r||!r.text.trim())return!1;if(n){let i=e.mode??r.mode,a=Bo(t.schema),o=Y(r.text,{nodes:a}),s=t.tr;if(s.setMeta(K,{type:`accept`}),i===`append`){let e=t.doc.resolve(r.to).after(1);s.insert(e,o.content),s.setSelection(x.near(s.doc.resolve(e+o.content.size),-1))}else{let e=t.doc.resolve(r.from),n=t.doc.resolve(r.to),i=o.childCount===1?o.firstChild:null;i?.type.name===`paragraph`&&e.sameParent(n)&&e.parent.isTextblock?(s.replaceWith(r.from,r.to,i.content),s.setSelection(x.near(s.doc.resolve(r.from+i.content.size),-1))):(s.replaceRange(r.from,r.to,new ze(o.content,0,0)),s.setSelection(x.near(s.doc.resolve(s.mapping.map(r.to)),-1)))}n(s.scrollIntoView())}return!0}}function po(){return s({startPendingReplacement:co,appendPendingReplacementText:lo,acceptPendingReplacement:fo,discardPendingReplacement:uo})}function mo(){return u({"Mod-Enter":fo(),Escape:uo()})}function ho(){return _(h(so),po(),mo())}function go(e){return h(new y({view:()=>({update:(t,n)=>{let r=K.getState(n),i=K.getState(t.state);!i||r===i||(i.pending?i.pending!==r?.pending&&e({type:`update`,pending:i.pending}):i.ended&&i.ended!==r?.ended&&e({type:`ended`,pending:i.ended.pending,outcome:i.ended.outcome}))}})}))}function _o(e,t){return(n,r)=>{let i=e<0?Ee.atStart(n.doc):Ee.atEnd(n.doc),a=t?x.between(n.selection.$anchor,i.$head):i;return n.selection.eq(a)||r?.(n.tr.setSelection(a).scrollIntoView()),!0}}function vo(){return u({"Meta-ArrowUp":_o(-1,!1),"Meta-ArrowDown":_o(1,!1),"Shift-Meta-ArrowUp":_o(-1,!0),"Shift-Meta-ArrowDown":_o(1,!0)})}function yo(e){return e.left===e.right&&e.top===e.bottom}function J(e,t,n){if(t<0||t>e.state.doc.content.size)return;let r;try{r=e.coordsAtPos(t,n)}catch{return}return yo(r)?void 0:r}function bo(e){e.offsetWidth}const xo=new b(`meowdown-virtual-caret`),So=[`md-virtual-caret-blink`,`md-virtual-caret-blink2`];function Co(e){let t=e.dom.ownerDocument.getSelection();if(t==null||t.rangeCount===0||!e.dom.contains(t.anchorNode))return;let n=t.getRangeAt(0).cloneRange();n.collapse(!0);let r=Array.from(n.getClientRects()).filter(e=>e.height>0);if(r.length===0)return;let i=r[r.length-1];return{left:i.left,top:i.top,height:i.height}}function wo(e){let t=e.state,n=t.selection.head,r=P(t,n),i=F(t,n),a=r==null,o=[[n,a],[n,!a]];r!=null&&o.push([r.from,!0]),i!=null&&o.push([i.to,!1]);for(let[t,n]of o){let r=J(e,t,n?-1:1);if(r!=null&&r.bottom>r.top)return{left:r.left,top:r.top,height:r.bottom-r.top}}}function To(e){let t=e.state,n=t.selection.head;for(let r of Wt){let i=T(t,n,r);if(i==null||i.from!==n&&i.to!==n)continue;let a=Eo(e,i.from+1);if(a==null)continue;let o=a.getBoundingClientRect();if(o.height!==0)return{left:i.to===n?o.right:o.left,top:o.top,height:o.height}}}function Eo(e,t){let{node:n}=e.domAtPos(t,0);return(n instanceof Element?n:n.parentElement)?.closest(`.md-atom-view`)?.querySelector(`.md-atom-view-preview`)??void 0}function Do(e){let t=e.height*.19999999999999996;return{left:e.left,top:e.top-t/2,height:e.height+t}}function Oo(e){let t=Co(e)??wo(e);return t==null?To(e):Do(t)}function ko(e,t){return e==null||t==null?e===t:e.left===t.left&&e.top===t.top&&e.height===t.height}var Ao=class{#e;#t;#n;#r;#i;#a;#o;#s=0;constructor(e){this.#e=e,this.#r=e.dom.ownerDocument,this.#t=this.#r.createElement(`div`),this.#t.className=`md-virtual-caret-layer`,this.#n=this.#t.appendChild(this.#r.createElement(`div`)),this.#n.className=`md-virtual-caret`,this.#n.dataset.testid=`virtual-caret`,e.dom.insertAdjacentElement(`afterend`,this.#t),this.#r.addEventListener(`selectionchange`,this.#l),typeof ResizeObserver<`u`&&(this.#i=new ResizeObserver(this.#l),this.#i.observe(e.dom)),this.#l()}update(e,t){e.state.selection.eq(t.selection)||this.#c(),this.#l()}destroy(){this.#r.removeEventListener(`selectionchange`,this.#l),this.#i?.disconnect(),this.#t.remove()}#c(){this.#s=1-this.#s,this.#n.style.animationName=So[this.#s]}#l=()=>{let e=this.#e;if(e.isDestroyed)return;let t=e.state,n=t.selection,r=g(n)&&n.empty?Oo(e):void 0,i=r!=null&&D(t)===`hide`?Wn(t,n.head):void 0;if(ko(r,this.#a)&&i===this.#o)return;let a=this.#a==null;if(this.#a=r,this.#o=i,i==null?delete this.#n.dataset.tail:this.#n.dataset.tail=i,r==null){this.#n.style.visibility=`hidden`;return}let o=this.#t.getBoundingClientRect();a&&(this.#n.style.transitionProperty=`none`),this.#n.style.visibility=``,this.#n.style.left=`${r.left-o.left}px`,this.#n.style.top=`${r.top-o.top}px`,this.#n.style.height=`${r.height}px`,a&&(bo(this.#n),this.#n.style.transitionProperty=``)}};function jo(){return h(new y({key:xo,view:e=>new Ao(e)}))}function Mo(e){return _(ao(),be(),Dn(),Ce(),ye(),Da(),Nn(),$a(),vn(),nr(),rr(),Ei(),ln(),En(),ro(),vo(),ui(e),Gi(),$i(),Gr(),Ma(),zt(e.markMode??`focus`),jo(),er(),nn({marks:Wt.map(e=>({name:e,modes:[`hide`,`focus`,`show`]}))}),a(),i(),l(),xe(),we(),Se(),wn(),ho())}function No(e={}){return Mo(e)}const Po=ve(()=>{let e=No().schema;if(e==null)throw Error(`Unexpected empty schema`);return e}),Fo=ve(()=>r(Po())),Io=ve(()=>n(Po())),Lo=`meowdown_mark_builders`;function Ro(e){let t=e.cached[Lo];if(t)return t;let r=n(e);return e.cached[Lo]=r,r}const zo=`meowdown_node_builders`;function Bo(e){let t=e.cached[zo];if(t)return t;let n=r(e);return e.cached[zo]=n,n}function Y(e,t={}){let{nodes:n=Fo(),frontmatter:r=!1}=t,i,a=e;if(r){let[t,n]=Ho(e);i=t,n&&(a=e.slice(n))}let o=Uo(n,Fr.parse(a).cursor(),a);return n.doc(i===void 0?{}:{frontmatter:i},o)}const Vo=/^---[ \t]*\r?\n([\s\S]*?\n)?---[ \t]*(?:\r?\n|$)/;function Ho(e){let t=Vo.exec(e);return t?[(t[1]??``).replace(/\r?\n$/,``),t[0].length]:[]}function Uo(e,t,n){let r=[];if(!t.firstChild())return r;let i;do i!=null&&Wo(r,e,n,i,t.from),i=t.to,r.push(...Go(e,t,n));while(t.nextSibling());return t.parent(),r}function Wo(e,t,n,r,i){let a=0;for(let e=r;e<i;e++)n.charCodeAt(e)===10&&a++;for(let n=2;n<a;n++)e.push(t.paragraph())}function Go(e,t,n){switch(t.type.id){case V.ATXHeading1:return[X(e,t,n,1,!1)];case V.ATXHeading2:return[X(e,t,n,2,!1)];case V.ATXHeading3:return[X(e,t,n,3,!1)];case V.ATXHeading4:return[X(e,t,n,4,!1)];case V.ATXHeading5:return[X(e,t,n,5,!1)];case V.ATXHeading6:return[X(e,t,n,6,!1)];case V.SetextHeading1:return[X(e,t,n,1,!0)];case V.SetextHeading2:return[X(e,t,n,2,!0)];case V.Paragraph:return[Zo(e,t,n)];case V.CommentBlock:return[Qo(e,t,n)];case V.HTMLBlock:case V.ProcessingInstructionBlock:return[Zo(e,t,n)];case V.Blockquote:return[$o(e,t,n)];case V.BulletList:return es(e,t,n,`bullet`);case V.OrderedList:return es(e,t,n,`ordered`);case V.FencedCode:case V.CodeBlock:return[ns(e,t,n)];case V.BlockMath:return[rs(e,t,n)];case V.HorizontalRule:{let r=n.slice(t.from,t.to).trimEnd();return[e.horizontalRule({marker:r===`---`?null:r})]}case V.Table:return[is(e,t,n)];case V.Task:return[Zo(e,t,n)];default:return n.slice(t.from,t.to).trim()===``?[]:(console.warn(`[meowdown] unsupported lezer block "${t.type.name}"`),[Zo(e,t,n)])}}function X(e,t,n,r,i){let a=t.from,o=t.from,s=t.to,c=-1,l=-1;if(t.firstChild()){t.type.id===V.HeaderMark&&t.from===a&&(o=t.to);let e=-1,n=-1,r=-1;do e=t.type.id,n=t.from,r=t.to;while(t.nextSibling());e===V.HeaderMark&&n>o&&(s=n,c=n,l=r),t.parent()}let u=Yo(n.slice(o,s),Z(n,o)).trim(),d=i?Ko(n,c,l)||1:null,f=!i&&c>=0&&qo(n,c,l)||null;return e.heading({level:r,setextUnderline:d,closingHashes:f},u)}function Ko(e,t,n){if(t<0)return 0;let r=0;for(let i=t;i<n;i++){let t=e.charCodeAt(i);(t===61||t===45)&&r++}return r}function qo(e,t,n){if(t<0)return 0;let r=0;for(let i=t;i<n;i++)e.charCodeAt(i)===35&&r++;return r}function Z(e,t){let n=e.lastIndexOf(`
|
|
3
|
+
`,t-1)+1,r=0;for(let i=n;i<t;i++)r+=e.charCodeAt(i)===9?4-r%4:1;return r}function Jo(e,t){let n=0,r=0;for(;r<e.length&&n<t;){let t=e.charCodeAt(r);if(t===32)n+=1;else if(t===9)n+=4-n%4;else break;r++}return e.slice(r)}function Yo(e,t){return t===0||!e.includes(`
|
|
4
4
|
`)?e:e.split(`
|
|
5
|
-
`).map((e,n)=>n===0?e:
|
|
6
|
-
`)}function
|
|
5
|
+
`).map((e,n)=>n===0?e:Jo(e,t)).join(`
|
|
6
|
+
`)}function Xo(e,t,n){return e.paragraph(Yo(t,n))}function Zo(e,t,n){let r=t.from,i=t.to,a=Z(n,r);if(t.firstChild()){let o=``,s=r;do t.type.id===V.QuoteMark&&(o+=n.slice(s,t.from),s=t.to,R(n.charCodeAt(s))&&(s+=1));while(t.nextSibling());return t.parent(),o+=n.slice(s,i),Xo(e,o,a)}return Xo(e,n.slice(r,i),a)}function Qo(e,t,n){let r=Z(n,t.from),i=Yo(n.slice(t.from,t.to),r);return e.htmlComment({content:i})}function $o(e,t,n){let r=[];if(t.firstChild()){let i;do{if(t.type.id===V.QuoteMark)continue;i!=null&&Wo(r,e,n,i,t.from),i=t.to,r.push(...Go(e,t,n))}while(t.nextSibling());t.parent()}return e.blockquote(r)}function es(e,t,n,r){let i=[];if(t.firstChild()){do t.type.id===V.ListItem&&i.push(ts(e,t,n,r));while(t.nextSibling());t.parent()}return i}function ts(e,t,n,r){let i=[],a,o,s,c,l,u;if(t.firstChild()){do{if(t.type.id!==V.ListMark&&u==null&&(u=Z(n,t.from)),t.type.id===V.ListMark){if(r===`ordered`){let e=n.charCodeAt(t.to-1);e===41?c=`)`:e===46&&(c=`.`);let r=Number.parseInt(n.slice(t.from,t.to),10);s=Number.isFinite(r)?r:1}else{let e=n.charCodeAt(t.from);c=e===42?`*`:e===43?`+`:`-`}l=Z(n,t.to);continue}if(r===`bullet`&&t.type.id===V.Task){let r=t.from,s=t.to;if(a=!1,t.firstChild()){if(t.type.id===V.TaskMarker){let e=n.charCodeAt(t.from+1);e===120?(a=!0,o=`x`):e===88&&(a=!0,o=`X`),r=t.to}t.parent()}R(n.charCodeAt(r))&&(r+=1);let c=n.slice(r,s);i.push(Xo(e,c,Z(n,r)));continue}i.push(...Go(e,t,n))}while(t.nextSibling());t.parent()}let d=u!=null&&l!=null?u-l:1,f=a!=null,p=!f&&r===`bullet`&&c===`+`;return e.list({kind:f?`task`:r,order:r===`ordered`?s??1:null,checked:a??!1,collapsed:p,marker:p?null:c,taskMarker:o,markerGap:d>=2&&d<=4?d:1},i)}function ns(e,t,n){let r=t.type.id===V.CodeBlock,i=``,a=``,o=r?`indented`:null,s=null,c=!1;if(t.firstChild()){do switch(t.type.id){case V.CodeMark:{if(c)break;c=!0,n.charCodeAt(t.from)===126&&(o=`tilde`);let e=t.to-t.from;e>3&&(s=e);break}case V.CodeInfo:i=n.slice(t.from,t.to);break;case V.CodeText:a+=n.slice(t.from,t.to);break}while(t.nextSibling());t.parent()}return e.codeBlock({language:i,fenceStyle:o,fenceLength:s},a)}function rs(e,t,n){let r=``;if(t.firstChild()){do t.type.id===V.CodeText&&(r+=n.slice(t.from,t.to));while(t.nextSibling());t.parent()}return e.codeBlock({language:`math`,fenceStyle:`dollar`,fenceLength:null},r)}function is(e,t,n){let r=[];if(t.firstChild()){do t.type.id===V.TableDelimiter&&(r=as(n.slice(t.from,t.to)));while(t.nextSibling());t.parent()}let i=[];if(t.firstChild()){do{let a=t.type.id;a===V.TableHeader?i.push(os(e,t,n,!0,r)):a===V.TableRow&&i.push(os(e,t,n,!1,r))}while(t.nextSibling());t.parent()}return e.table(i)}function as(e){return e.split(`|`).map(e=>e.trim()).filter(e=>e!==``).map(e=>{let t=e.startsWith(`:`),n=e.endsWith(`:`);return t&&n?`center`:t?`left`:n?`right`:null})}function os(e,t,n,r,i){let a=i.length,o=Array(a).fill(``);if(t.firstChild()){let e=t.type.id===V.TableDelimiter,r=0;do if(t.type.id===V.TableDelimiter)r++;else if(t.type.id===V.TableCell){let i=r-+!!e;i>=0&&i<a&&(o[i]=n.slice(t.from,t.to).trim().replaceAll(String.raw`\|`,`|`))}while(t.nextSibling());t.parent()}let s=o.map((t,n)=>{let a=e.paragraph(t),o={align:i[n]};return r?e.tableHeaderCell(o,a):e.tableCell(o,a)});return e.tableRow(s)}function Q(e,t={}){let n=new us;return t.frontmatter&&ss(e.attrs.frontmatter,n),ds(e,n),n.finish()}function ss(e,t){e!==null&&(t.write(`---`),t.write(`
|
|
7
7
|
`),e!==``&&(t.write(e),t.write(`
|
|
8
|
-
`)),t.write(`---`),t.closeBlock())}const
|
|
9
|
-
`+i.repeat(Math.max(1,r))),t.closeBlock();return}t.write(
|
|
8
|
+
`)),t.write(`---`),t.closeBlock())}const cs=[``,`# `,`## `,`### `,`#### `,`##### `,`###### `];function ls(e,t){let n=e.attrs,r=n.setextUnderline;if(r!=null&&e.content.size>0&&n.level<=2){hs(e,t);let i=n.level===1?`=`:`-`;t.write(`
|
|
9
|
+
`+i.repeat(Math.max(1,r))),t.closeBlock();return}t.write(cs[n.level]??`# `),hs(e,t);let i=n.closingHashes;i!=null&&i>0&&t.write(` `+`#`.repeat(i)),t.closeBlock()}var us=class{constructor(){this.parts=[],this.linePrefix=``,this.pendingFirst=null,this.atLineStart=!0,this.deferredBlankPrefix=null}write(e){if(e===``)return;if(this.emitDeferredBlankLine(),this.atLineStart&&=(this.parts.push(this.pendingFirst??this.linePrefix),this.pendingFirst=null,!1),!e.includes(`
|
|
10
10
|
`)){this.parts.push(e);return}let t=e.split(`
|
|
11
11
|
`);for(let e=0;e<t.length;e++)e>0&&this.parts.push(`
|
|
12
12
|
`,this.linePrefix),t[e]!==``&&this.parts.push(t[e])}closeEmptyBlock(){if(!this.atLineStart||this.pendingFirst!==null){this.closeBlock();return}this.parts.length!==0&&(this.emitDeferredBlankLine(),this.deferredBlankPrefix=this.linePrefix)}closeBlock(){this.atLineStart&&this.pendingFirst!==null&&(this.emitDeferredBlankLine(),this.parts.push(this.pendingFirst.trimEnd()),this.pendingFirst=null,this.atLineStart=!1),this.atLineStart||this.parts.push(`
|
|
13
13
|
`),this.atLineStart=!0,this.deferredBlankPrefix=this.linePrefix}suppressBlank(){this.deferredBlankPrefix=null}withPrefix(e,t,n){let r=this.linePrefix,i=this.pendingFirst;if(this.linePrefix=r+e,t!==null){let e=i??r;this.pendingFirst=e+t}n(),this.linePrefix=r,this.pendingFirst=t===null?i:null}finish(){return this.parts.join(``).replace(/\s+$/,``)+`
|
|
14
14
|
`}emitDeferredBlankLine(){let e=this.deferredBlankPrefix;e!==null&&(this.parts.push(e.trimEnd(),`
|
|
15
|
-
`),this.deferredBlankPrefix=null)}};function
|
|
15
|
+
`),this.deferredBlankPrefix=null)}};function ds(e,t){switch(e.type.name){case`doc`:fs(e,t);return;case`paragraph`:if(e.childCount===0){t.closeEmptyBlock();return}hs(e,t),t.closeBlock();return;case`heading`:ls(e,t);return;case`blockquote`:t.withPrefix(`> `,`> `,()=>fs(e,t)),t.closeBlock();return;case`list`:gs(e,t,ms(e));return;case`codeBlock`:_s(e,t);return;case`horizontalRule`:{let{marker:n}=e.attrs;t.write(n||`---`),t.closeBlock();return}case`htmlComment`:{let{content:n}=e.attrs;t.write(n),t.closeBlock();return}case`table`:bs(e,t);return;case`text`:e.text&&t.write(e.text);return}}function fs(e,t,n=!1){let r=e.childCount,i=0;for(;i<r;){let a=e.child(i);if(a.type.name!==`list`){n&&i>0&&t.suppressBlank(),ds(a,t),i++;continue}let o=i+1;for(;o<r&&e.child(o).type.name===`list`;)o++;let s=ps(e,i,o);for(let r=i;r<o;r++)(r===i?n&&i>0:s)&&t.suppressBlank(),gs(e.child(r),t,s);i=o}}function ps(e,t,n){for(let r=t;r<n;r++)if(!ms(e.child(r)))return!1;return!0}function ms(e){let t=e.childCount;for(let n=0;n<t;n++){let t=e.child(n);if(t.type.name!==`list`&&!(t.type.name===`paragraph`&&n===0))return!1}return!0}function hs(e,t){let n=e.childCount;for(let r=0;r<n;r++){let n=e.child(r);n.isText&&n.text&&t.write(n.text)}}function gs(e,t,n){let{kind:r,marker:i,order:a,taskMarker:o,collapsed:s,markerGap:c,checked:l}=e.attrs,u=r===`task`?i===`+`?`+`:i===`*`?`*`:`-`:s?`+`:i===`*`?`*`:`-`,d=i===`)`?`)`:`.`,f=o===`X`?`X`:`x`,p=Math.min(Math.max(c??1,1),4),m=`${r===`ordered`?`${a??1}${d}`:u}${` `.repeat(p)}`,h=r===`task`?`${m}[${l?f:` `}] `:m,ee=` `.repeat(m.length);t.withPrefix(ee,h,()=>fs(e,t,n)),t.closeBlock()}function _s(e,t){let n=e.attrs,r=n.language||``,i=e.textContent;if(n.fenceStyle===`indented`&&!r){let e=vs(i);if(e!=null){t.write(e),t.closeBlock();return}}if(n.fenceStyle===`dollar`&&r===`math`&&!ys(i)){t.write(`$$`),t.write(`
|
|
16
16
|
`),i&&(t.write(i),t.write(`
|
|
17
|
-
`)),t.write(`$$`),t.closeBlock();return}let a=n.fenceStyle===`tilde`,o=
|
|
17
|
+
`)),t.write(`$$`),t.closeBlock();return}let a=n.fenceStyle===`tilde`,o=Di(i,a?126:96,2)+1,s=(a?`~`:"`").repeat(Math.max(n.fenceLength??0,o));t.write(s),r&&t.write(r),t.write(`
|
|
18
18
|
`),i&&(t.write(i),t.write(`
|
|
19
|
-
`)),t.write(s),t.closeBlock()}function
|
|
19
|
+
`)),t.write(s),t.closeBlock()}function vs(e){if(e===``)return;let t=e.split(`
|
|
20
20
|
`);if(!(t[0]===``||t[t.length-1]===``)){for(let e=0;e<t.length;e++)t[e]!==``&&(t[e]=` ${t[e]}`);return t.join(`
|
|
21
|
-
`)}}function
|
|
22
|
-
`).some(e=>e.trim()===`$$`)}function
|
|
21
|
+
`)}}function ys(e){return e.split(`
|
|
22
|
+
`).some(e=>e.trim()===`$$`)}function bs(e,t){let n=e.childCount;if(n===0)return;let r=[],i=0,a=-1;for(let t=0;t<n;t++){let n=e.child(t),o=[],s=!1;for(let e=0;e<n.childCount;e++){let t=n.child(e);t.type.name===`tableHeaderCell`&&(s=!0),o.push(Cs(t))}s&&a<0&&(a=t),o.length>i&&(i=o.length),r.push(o)}if(i===0)return;let o=e.child(a>=0?a:0),s=[];for(let e=0;e<i;e++){let t=e<o.childCount?o.child(e):void 0,n=t?t.attrs.align:void 0;s.push(xs(n))}let c=`| `+s.join(` | `)+` |`,l=a>=0?r[a]:Array(i).fill(``);t.write(Ss(l,i)),t.write(`
|
|
23
23
|
`),t.write(c);for(let e=0;e<n;e++)e!==a&&(t.write(`
|
|
24
|
-
`),t.write(
|
|
24
|
+
`),t.write(Ss(r[e],i)));t.closeBlock()}function xs(e){switch(e){case`left`:return`:--`;case`center`:return`:-:`;case`right`:return`--:`;default:return`---`}}function Ss(e,t){let n=`|`;for(let r=0;r<t;r++)n+=` `+(e[r]??``)+` |`;return n}function Cs(e){let t=e.textContent.trim();return!t.includes(`|`)&&!t.includes(`
|
|
25
25
|
`)?t:t.replaceAll(`|`,String.raw`\|`).replaceAll(`
|
|
26
|
-
`,` `)}function
|
|
27
|
-
`).filter(e=>!
|
|
28
|
-
`)}const Gs=new b(`meowdown-embed-paste`);function Ks(e){let t=e.trim();if(!(!t||/\s/.test(t)))return Us(t)?t:void 0}function qs(e,t){let{from:n,to:r}=e.state.selection;e.dispatch(wt(e.state.tr.insertText(t,n,r)));let i=e.state.tr.insertText(``,n,n+t.length);e.dispatch(wt(i))}function Js(){return h(new y({key:Gs,props:{handlePaste:(e,t,n)=>{let r=e.state.selection.$from.parent;if(!r.inlineContent||r.type.spec.code)return!1;let i=Ws(t,n);if(!i)return!1;let a=Ks(i);return a?(qs(e,a),!0):!1}}}))}const Ys=new b(`meowdown-exit-boundary`);function Xs(e,t){let{$anchor:n,$head:r}=e.selection,i=t>0?n.max(r):n.min(r),a=i.parent.inlineContent?i.depth?e.doc.resolve(t>0?i.after():i.before()):void 0:i;return!!(a&&Ee.findFrom(a,t))}function Zs(e,t){let{state:n}=e,{selection:r}=n;return g(r)&&!r.empty||re(r)||r.$from.parent.inlineContent&&!e.endOfTextblock(t<0?`up`:`down`)?!0:Xs(n,t)}function Qs(e){return new y({key:Ys,props:{handleKeyDown:(t,n)=>{if(n.shiftKey||n.altKey||n.ctrlKey||n.metaKey)return!1;let r=n.key===`ArrowUp`?-1:n.key===`ArrowDown`?1:void 0;return!(!r||Zs(t,r)||e({direction:r<0?`up`:`down`,event:n})===!1)}}})}function $s(e){return v(h(Qs(e)),t.low)}function ec(e){return!!e.type?.startsWith(`image/`)}function tc(e,t){return ec(e)?``:`[${ic(e.name)}](${t})`}function nc(e,t){return!e||!t.onFilePaste?[]:Array.from(e.files)}const rc=e=>{console.error(`[meowdown] failed to save pasted file:`,e)};function ic(e){return e.replaceAll(/[\\[\]]/g,String.raw`\$&`)}async function ac(e,t,n,r){let{onFilePaste:i}=n;if(!i)return;let a=n.onFileSaveError??rc,o=r,s=!1;for(let n of t){let t;try{t=await i(n)}catch(e){a(e,n);continue}if(!t||e.isDestroyed)continue;let r=tc(n,t),c=s?`\n${r}`:r,l=o==null?e.state.tr.insertText(c):e.state.tr.insertText(c,o);e.dispatch(l),s=!0,o!=null&&(o+=c.length)}}function oc(e){return new y({key:new b(`file-paste`),props:{handlePaste:(t,n)=>{let r=nc(n.clipboardData,e);return r.length===0?!1:(ac(t,r,e),!0)},handleDrop:(t,n)=>{let r=nc(n.dataTransfer,e);return r.length===0?!1:(ac(t,r,e,t.posAtCoords({left:n.clientX,top:n.clientY})?.pos),!0)}}})}function sc(e={}){return v(h(oc(e)),t.high)}const cc=new b(`meowdown-file-click`);function lc(e,t){let n=D(e,t,`mdFile`);if(!n)return;let{href:r,name:i}=n.mark.attrs;return{href:r,name:i}}function uc(e){return h(new y({key:cc,props:{handleClick:(t,n,r)=>{let i=r.target?.closest?.(`.md-file-view-preview`);if(!i)return!1;let a=i.closest(`.md-file-view`)?.querySelector(`.md-file-view-content`);if(!a)return!1;let o=lc(t.state,t.posAtDOM(a,0));return o?(e({href:o.href,name:o.name,event:r}),!0):!1}}}))}const dc=[`KB`,`MB`,`GB`,`TB`];function fc(e){let t=e,n=`B`;for(let e of dc){if(t<999.5)break;t/=1e3,n=e}return n===`B`?`${Math.round(t)} B`:`${t<9.95?Math.round(t*10)/10:Math.round(t)} ${n}`}const pc=new Map([[`pdf`,`pdf`],[`zip`,`archive`],[`tar`,`archive`],[`gz`,`archive`],[`tgz`,`archive`],[`rar`,`archive`],[`7z`,`archive`],[`doc`,`doc`],[`docx`,`doc`],[`pages`,`doc`],[`xls`,`sheet`],[`xlsx`,`sheet`],[`csv`,`sheet`],[`numbers`,`sheet`],[`ppt`,`slides`],[`pptx`,`slides`],[`key`,`slides`],[`mp3`,`audio`],[`wav`,`audio`],[`m4a`,`audio`],[`flac`,`audio`],[`ogg`,`audio`],[`mp4`,`video`],[`mov`,`video`],[`mkv`,`video`],[`webm`,`video`],[`txt`,`text`],[`md`,`text`]]);function mc(e){let t=e.split(/[?#]/,1)[0],n=t.lastIndexOf(`.`);if(n<0)return`generic`;let r=t.slice(n+1).toLowerCase();return pc.get(r)??`generic`}const hc=`http://www.w3.org/2000/svg`;function gc(){let e=document.createElementNS(hc,`svg`);e.setAttribute(`class`,`md-file-view-icon`),e.setAttribute(`viewBox`,`0 0 24 24`),e.setAttribute(`aria-hidden`,`true`);for(let t of[`M15 2H6a2 2 0 0 0-2 2v16a2 2 0 0 0 2 2h12a2 2 0 0 0 2-2V7Z`,`M14 2v4a2 2 0 0 0 2 2h4`]){let n=document.createElementNS(hc,`path`);n.setAttribute(`d`,t),n.setAttribute(`fill`,`none`),n.setAttribute(`stroke`,`currentColor`),n.setAttribute(`stroke-width`,`2`),n.setAttribute(`stroke-linecap`,`round`),n.setAttribute(`stroke-linejoin`,`round`),e.appendChild(n)}return e}var _c=class{#e;#t;#n;#r;#i;#a;#o=!1;constructor(e,t){this.#a=e.attrs,this.#e=document.createElement(`span`),this.#e.className=`md-file-view md-atom-view`,this.#n=document.createElement(`span`),this.#n.className=`md-file-view-preview md-atom-view-preview`,this.#n.contentEditable=`false`,this.#n.dataset.testid=`file-pill`,this.#n.dataset.fileKind=mc(this.#a.href),this.#n.title=this.#a.name,this.#e.appendChild(this.#n),this.#n.appendChild(gc()),this.#r=document.createElement(`span`),this.#r.className=`md-file-view-name`,this.#r.textContent=this.#a.name,this.#n.appendChild(this.#r),this.#i=document.createElement(`span`),this.#i.className=`md-file-view-size`,this.#i.dataset.testid=`file-pill-size`,this.#n.appendChild(this.#i),this.#t=document.createElement(`span`),this.#t.className=`md-file-view-content md-atom-view-content`,this.#e.appendChild(this.#t),this.#s(t.resolveFileInfo)}get dom(){return this.#e}get contentDOM(){return this.#t}update(e){let t=e.attrs,n=this.#a;return t.href===n.href?(this.#a=t,t.name!==n.name&&(this.#r.textContent=t.name,this.#n.title=t.name),!0):!1}ignoreMutation(e){return!this.#t.contains(e.target)}destroy(){this.#o=!0}async#s(e){if(!e)return;let t;try{t=await e(this.#a.href)}catch(e){console.error(`[meowdown] resolveFileInfo failed:`,e);return}if(this.#o||!t)return;let{size:n}=t;n==null||!Number.isFinite(n)||n<0||(this.#i.textContent=fc(n))}};function vc(e={}){return f({name:`mdFile`,constructor:t=>new _c(t,e)})}function yc(e){return h(new y({key:e.key,props:{handleClick:(t,n,r)=>{if(!r.target?.closest?.(e.selector))return!1;let i=e.findPayloadAt(t.state,n);return i==null?!1:(e.preventDefault&&r.preventDefault(),e.onClick(i,r),!0)}}}))}const bc=new b(`meowdown-tag-click`);function xc(e,t){let n=D(e,t,`mdTag`);if(!n)return;let r=e.doc.textBetween(n.from,n.to),i=r.startsWith(`#`)?r.slice(1):r;return{from:n.from,to:n.to,tag:i}}function Sc(e){return yc({key:bc,selector:`.md-tag`,preventDefault:!1,findPayloadAt:(e,t)=>xc(e,t)?.tag,onClick:(t,n)=>e({tag:t,event:n})})}const Cc=new b(`meowdown-wikilink-click`);function wc(e,t){let n=D(e,t,`mdWikilink`);if(!n)return;let{target:r}=n.mark.attrs;return{from:n.from,to:n.to,target:r}}function Tc(e){return yc({key:Cc,selector:`.md-wikilink-view-preview`,preventDefault:!1,findPayloadAt:(e,t)=>wc(e,t)?.target,onClick:(t,n)=>e({target:t,event:n})})}const Ec=new b(`meowdown-follow-link`);function Dc(e){return e.key!==`Enter`||e.shiftKey||e.altKey?!1:ie?e.metaKey&&!e.ctrlKey:e.ctrlKey&&!e.metaKey}function Oc(e){return new y({key:Ec,props:{handleKeyDown:(t,n)=>{if(!Dc(n))return!1;let{state:r}=t,i=r.selection.head,a=e.onWikilinkClick&&wc(r,i);if(a)return e.onWikilinkClick?.({target:a.target,event:n}),!0;let o=e.onTagClick&&xc(r,i);if(o)return e.onTagClick?.({tag:o.tag,event:n}),!0;let s=e.onFileClick&&lc(r,i);if(s)return e.onFileClick?.({href:s.href,name:s.name,event:n}),!0;let c=e.onLinkClick&&q(r,i);return c?(e.onLinkClick?.({href:c.href,event:n}),!0):!1}}})}function kc(e){return v(h(Oc(e)),t.high)}const Ac=(e,t)=>{let n={type:`highlight`,children:e.all(t)};return e.patch(t,n),n},jc=(e,t,n,r)=>{let i=e,a=n.createTracker(r),o=a.move(`==`);return o+=a.move(n.containerPhrasing(i,{...a.current(),before:o,after:`=`})),o+=a.move(`==`),o};function Mc(){return kt().use(Tt).use(Et,{handlers:{mark:Ac}}).use(Dt).use(Ot,{bullet:`-`,emphasis:`*`,strong:`*`,fence:"`",fences:!0,rule:`-`,ruleRepetition:3,listItemIndent:`one`,handlers:{highlight:jc}}).freeze()}const Nc=ve(Mc);function Pc(e){return String(Nc().processSync(e))}const Fc=new b(`meowdown-html-paste`);function Ic(){return h(new y({key:Fc,props:{transformPastedHTML:(e,t)=>{if(e.includes(`data-pm-slice`))return e;let n=t.state.selection.$from.parent;if(!n.inlineContent||n.type.spec.code)return e;let r=Pc(e);if(!r.trim())return e;let i=Z(r,{nodes:Lo(t.state.schema)}),a=Ie.fromSchema(t.state.schema),o=document.createElement(`div`);return o.append(a.serializeFragment(i.content)),o.innerHTML}}}))}const Lc=new b(`meowdown-image-click`);function Rc(e){return e instanceof HTMLElement&&e.closest(`.md-image-view-preview`)}function zc(e,t){let n=D(e,t,`mdImage`);if(!n)return;let{src:r,alt:i}=n.mark.attrs;return{from:n.from,to:n.to,src:r,alt:i}}function Bc(e,t){let n=t.closest(`.md-image-view`)?.querySelector(`.md-image-view-content`);if(n)return zc(e.state,e.posAtDOM(n,0))}function Vc(e,t){return Array.from(e).find(e=>e.identifier===t)}function Hc(e,t){return Math.abs(t.clientX-e.clientX)<=10&&Math.abs(t.clientY-e.clientY)<=10}function Uc(e){let t=new WeakMap;return h(new y({key:Lc,props:{handleDOMEvents:{pointerdown:(e,t)=>(Rc(t.target)&&t.pointerType!==`mouse`&&t.preventDefault(),!1),touchstart:(e,n)=>{if(t.delete(e),n.touches.length!==1||!Rc(n.target)||n.target instanceof HTMLElement&&n.target.closest(`.md-image-resize-handle`))return!1;let r=n.changedTouches[0];return r&&t.set(e,{identifier:r.identifier,clientX:r.clientX,clientY:r.clientY}),!1},touchmove:(e,n)=>{let r=t.get(e);if(!r)return!1;let i=Vc(n.changedTouches,r.identifier);return i&&!Hc(r,i)&&t.delete(e),!1},touchcancel:e=>(t.delete(e),!1),touchend:(n,r)=>{let i=t.get(n);if(t.delete(n),!i||r.touches.length>0)return!1;let a=Vc(r.changedTouches,i.identifier);if(!a||!Hc(i,a))return!1;let o=Rc(r.target);if(!o)return!1;r.preventDefault();let s=Bc(n,o);return s&&e({src:s.src,alt:s.alt,event:r}),!0}},handleClick:(t,n,r)=>{let i=Rc(r.target);if(!i)return!1;let a=Bc(t,i);return a?(e({src:a.src,alt:a.alt,event:r}),!0):!1}}}))}function Wc(e){return/^https?:\/\//i.test(e)?e:void 0}function Gc(e){let t=document.createElement(`iframe`);return t.src=e.src,t.title=e.title,t.className=e.className,t.dataset.testid=e.testid,t.loading=`lazy`,t.referrerPolicy=`strict-origin-when-cross-origin`,t.setAttribute(`frameborder`,`0`),e.allow&&(t.allow=e.allow),e.allowFullscreen&&(t.allowFullscreen=!0),e.kind===`tweet`&&Is(t),t}function Kc(e,t,n,r){if(n!=null&&r!=null){e.setAttribute(`data-width`,String(n)),e.setAttribute(`data-height`,String(r));return}let i=t.naturalWidth/t.naturalHeight;if(!Number.isFinite(i)||i<=0){n!=null&&e.setAttribute(`data-width`,String(n)),r!=null&&e.setAttribute(`data-height`,String(r));return}let a=n==null?Math.min(t.naturalHeight,500):n/i,o=n??a*i;e.setAttribute(`data-width`,String(Math.round(o))),e.setAttribute(`data-height`,String(Math.round(a)))}function qc(e,t,n,r){let i=e.posAtDOM(t,0),a=D(e.state,i,`mdImage`);if(!a)return;let o=e.state.doc.textBetween(a.from,a.to),s=Br(o),c=a.from+s.length,l=o.slice(s.length),u=zr({...Lr(l)??{},width:Math.round(n),height:Math.round(r)});u!==l&&e.dispatch(e.state.tr.insertText(u,c,a.to))}var Jc=class{#e;#t;#n;#r;#i;#a;#o;constructor(e,t,n){this.#i=e.attrs,this.#n=n,this.#r=t,this.#e=document.createElement(`span`),this.#e.className=`md-image-view md-atom-view`,this.#t=document.createElement(`span`),this.#t.className=`md-image-view-content md-atom-view-content`;let r=this.#s();r&&(r.contentEditable=`false`,this.#e.appendChild(r)),this.#e.appendChild(this.#t)}get dom(){return this.#e}get contentDOM(){return this.#t}update(e){let t=e.attrs,n=this.#i;return t.src===n.src?(this.#i=t,this.#o&&t.alt!==n.alt&&(this.#o.alt=t.alt),this.#a&&this.#o&&(t.width!==n.width||t.height!==n.height)&&Kc(this.#a,this.#o,t.width,t.height),!0):!1}ignoreMutation(e){return!this.#t.contains(e.target)}#s(){let{src:e}=this.#i,t=Us(e);if(t){let e=document.createElement(`span`);return e.className=`md-image-view-preview md-atom-view-preview`,e.appendChild(Gc(t)),e}let n=(this.#n.resolveImageUrl??Wc)(e);if(!n)return;let r=document.createElement(`span`);return r.className=`md-image-view-preview md-atom-view-preview`,r.dataset.testid=`image-preview`,r.appendChild(this.#c(n)),r}#c(e){jt(),At();let t=document.createElement(`prosekit-resizable-root`);t.className=`md-image-resizable`,t.dataset.testid=`image-resizable`,t.setAttribute(`data-loading`,``);let n=document.createElement(`img`);n.src=e,n.alt=this.#i.alt,n.draggable=!1,Kc(t,n,this.#i.width,this.#i.height),n.addEventListener(`load`,()=>{t.removeAttribute(`data-loading`);let e=n.naturalWidth/n.naturalHeight;!Number.isFinite(e)||e<=0||(t.setAttribute(`data-aspect-ratio`,String(e)),Kc(t,n,this.#i.width,this.#i.height))}),n.addEventListener(`error`,()=>{t.removeAttribute(`data-loading`)}),t.appendChild(n);let r=document.createElement(`prosekit-resizable-handle`);return r.className=`md-image-resize-handle`,r.setAttribute(`position`,`bottom-right`),r.addEventListener(`click`,e=>e.stopPropagation()),t.appendChild(r),t.addEventListener(`resizeEnd`,e=>{let{width:t,height:n}=e.detail;qc(this.#r,this.#t,t,n)}),this.#a=t,this.#o=n,t}};function Yc(e={}){return f({name:`mdImage`,constructor:(t,n)=>new Jc(t,n,e)})}const Xc={"Mod-b":`Bold`,"Mod-i":`Italic`,"Mod-e":`Inline code`,"Mod-Shift-x":`Strikethrough`,"Mod-Shift-h":`Highlight`,"Mod-k":`Link`,"Mod-Shift-k":`Insert a wikilink`,"Mod-1":`Heading 1`,"Mod-2":`Heading 2`,"Mod-3":`Heading 3`,"Mod-4":`Heading 4`,"Mod-5":`Heading 5`,"Mod-6":`Heading 6`,"Mod-.":`Fold or unfold a bullet`,"Mod-Enter":`Follow the link under the caret, or cycle a checkbox task`,"Mod-Shift-Enter":`Cycle a circle checkbox task`,"Mod-Shift-7":`Ordered list`,"Mod-Shift-8":`Bullet list`,"Mod-Shift-9":`Checkbox task list`,"Alt-ArrowUp":`Move the block or list item up`,"Alt-ArrowDown":`Move the block or list item down`,"Meta-ArrowUp":`Move the caret to the document start`,"Meta-ArrowDown":`Move the caret to the document end`,"Shift-Meta-ArrowUp":`Select to the document start`,"Shift-Meta-ArrowDown":`Select to the document end`,Escape:`Collapse the selection`},Zc=new b(`meowdown-link-click`);function Qc(e){return yc({key:Zc,selector:`.md-link`,preventDefault:!0,findPayloadAt:(e,t)=>q(e,t)?.href,onClick:(t,n)=>e({href:t,event:n})})}function $c(e){let t,n=(n,r)=>{let i=r.target;if(!i||!_e(i))return;let a=i.closest(e.selector);if(!a||a===t)return;let o=n.posAtDOM(a,0),s=e.findPayloadAt(n.state,o);s!=null&&(t=a,e.onHoverChange({payload:s,element:a}))},r=n=>{if(!t)return;let r=n.relatedTarget;r&&t.contains(r)||(t=void 0,e.onHoverChange(void 0))};return _(c(`mouseover`,(e,t)=>n(e,t)),c(`mouseout`,(e,t)=>r(t)))}function el(e){return $c({selector:`.md-link`,findPayloadAt:(e,t)=>q(e,t),onHoverChange:e})}const tl=new b(`meowdown-link-paste`);function nl(e){let t=e.trim();if(!(!t||/\s/.test(t)))return ur(t)}function rl(){return v(h(new y({key:tl,props:{handlePaste:(e,t,n)=>{let r=Ws(t,n);if(!r)return!1;let i=nl(r);return i?Mn(e,Ji({href:i,wrapText:!1})):!1}}})),t.high)}const il=new b(`meowdown-markdown-copy`);function al(){return h(new y({key:il,props:{clipboardTextSerializer:(e,t)=>{let n=e.content,r;try{r=t.state.schema.topNodeType.createAndFill(void 0,n)??void 0}catch{r=void 0}return r?is(r).replace(/\n+$/,``):n.textBetween(0,n.size,`
|
|
26
|
+
`,` `)}function ws(e){return e.replace(/\n+$/u,``)}function Ts(e){return/^[\s>]*$/u.test(e)}function Es(e){return e.split(`
|
|
27
|
+
`).filter(e=>!Ts(e))}function Ds(e){return e.trim().replaceAll(/\s+/gu,` `)}function Os(e,t={}){let n=Q(Y(e,{frontmatter:t.frontmatter}),{frontmatter:t.frontmatter});if(ws(n)===ws(e))return`exact`;let r=Es(e),i=Es(n);return r.length===i.length&&r.every((e,t)=>Ds(e)===Ds(i[t]))?`normalizing`:`lossy`}const ks=(e,t)=>{let{$from:n,empty:r}=e.selection;if(!r||n.depth!==1||n.index(0)!==0||n.parent.type.name!==`heading`||n.parentOffset!==n.parent.content.size)return!1;if(t){let r=ne(e.schema,`list`),i=ne(e.schema,`paragraph`),a=r.create({kind:`bullet`},i.create()),o=n.after(),s=e.tr.insert(o,a);s.setSelection(x.create(s.doc,o+2)),t(s.scrollIntoView())}return!0};function As(){return v(u({Enter:ks}),t.high)}const js=new Set([`MscGen`,`Xù`,`MsGenny`,`Angular Template`,`Brainfuck`,`Esper`,`Oz`,`Factor`,`Squirrel`,`Yacas`,`mIRC`,`FCL`,`ECL`,`MUMPS`,`Pig`,`Asterisk`,`Z80`,`Mathematica`]),Ms=ke.map(e=>({label:e.name,value:e.name.toLowerCase()})).filter(e=>!js.has(e.label)).concat([{label:`Plain text`,value:``},{label:`Math`,value:`math`}]).sort((e,t)=>e.label.localeCompare(t.label));function Ns(){return typeof window>`u`?!1:window.matchMedia(`(prefers-color-scheme: dark)`).matches}const Ps=/^(?:www\.|mobile\.)?(?:twitter\.com|x\.com)$/i,Fs=/\/status(?:es)?\/(\d+)/;function Is(e){let t;try{t=new URL(e)}catch{return}if(Ps.test(t.hostname))return Fs.exec(t.pathname)?.[1]}const Ls=e=>{let t=Is(e);if(!t)return;let n=Ns()?`dark`:`light`;return{kind:`tweet`,key:`tweet:${t}`,src:`https://platform.twitter.com/embed/Tweet.html?id=${t}&theme=${n}&dnt=true`,title:`Tweet`,className:`md-embed md-embed-tweet`,testid:`tweet-embed`}};function Rs(e){let t=t=>{if(t.source===e.contentWindow)try{let n=t.data?.[`twttr.embed`]?.params?.[0]?.height;typeof n==`number`&&(e.style.height=`${n}px`)}catch(e){console.warn(`[meowdown] failed to parse tweet resize message:`,e)}};window.addEventListener(`message`,t);let n=!1,r=()=>{n||(n=!0,window.removeEventListener(`message`,t),i.disconnect())},i=new MutationObserver(()=>{e.isConnected||r()});return i.observe(document.body,{childList:!0,subtree:!0}),r}const zs=/^(?:www\.|m\.)?(?:youtube\.com|youtube-nocookie\.com)$/i,Bs=/^(?:www\.)?youtu\.be$/i,Vs=/^[\w-]{11}$/;function Hs(e){let t;try{t=new URL(e)}catch{return}let n=null;if(Bs.test(t.hostname))n=t.pathname.slice(1);else if(zs.test(t.hostname)){let[,e,r]=t.pathname.split(`/`);t.pathname===`/watch`?n=t.searchParams.get(`v`):(e===`shorts`||e===`embed`||e===`live`)&&(n=r??null)}if(!n||!Vs.test(n))return;let r=t.searchParams.get(`start`)??t.searchParams.get(`t`),i=r?Us(r):void 0;return{videoId:n,startSeconds:i}}function Us(e){if(/^\d+$/.test(e))return Number(e);let t=/^(?:(\d+)h)?(?:(\d+)m)?(?:(\d+)s)?$/.exec(e);if(!(!t||!t[1]&&!t[2]&&!t[3]))return Number(t[1]??0)*3600+Number(t[2]??0)*60+Number(t[3]??0)}const Ws=[e=>{let t=Hs(e);if(!t)return;let n=t.startSeconds?`?start=${t.startSeconds}`:``;return{kind:`youtube`,key:`youtube:${t.videoId}:${t.startSeconds??0}`,src:`https://www.youtube-nocookie.com/embed/${t.videoId}${n}`,title:`YouTube video`,className:`md-embed md-embed-youtube`,testid:`youtube-embed`,allow:`accelerometer; autoplay; clipboard-write; encrypted-media; gyroscope; picture-in-picture; web-share; fullscreen`,allowFullscreen:!0}},Ls];function Gs(e){for(let t of Ws){let n=t(e);if(n)return n}}function Ks(e,t){return e.clipboardData?.getData(`text/plain`)||t.content.textBetween(0,t.content.size,`
|
|
28
|
+
`)}const qs=new b(`meowdown-embed-paste`);function Js(e){let t=e.trim();if(!(!t||/\s/.test(t)))return Gs(t)?t:void 0}function Ys(e,t){let{from:n,to:r}=e.state.selection;e.dispatch(Et(e.state.tr.insertText(t,n,r)));let i=e.state.tr.insertText(``,n,n+t.length);e.dispatch(Et(i))}function Xs(){return h(new y({key:qs,props:{handlePaste:(e,t,n)=>{let r=e.state.selection.$from.parent;if(!r.inlineContent||r.type.spec.code)return!1;let i=Ks(t,n);if(!i)return!1;let a=Js(i);return a?(Ys(e,a),!0):!1}}}))}const Zs=new b(`meowdown-exit-boundary`);function Qs(e,t){let{$anchor:n,$head:r}=e.selection,i=t>0?n.max(r):n.min(r),a=i.parent.inlineContent?i.depth?e.doc.resolve(t>0?i.after():i.before()):void 0:i;return!!(a&&Ee.findFrom(a,t))}function $s(e,t){let{state:n}=e,{selection:r}=n;return g(r)&&!r.empty||re(r)||r.$from.parent.inlineContent&&!e.endOfTextblock(t<0?`up`:`down`)?!0:Qs(n,t)}function ec(e){return new y({key:Zs,props:{handleKeyDown:(t,n)=>{if(n.shiftKey||n.altKey||n.ctrlKey||n.metaKey)return!1;let r=n.key===`ArrowUp`?-1:n.key===`ArrowDown`?1:void 0;return!(!r||$s(t,r)||e({direction:r<0?`up`:`down`,event:n})===!1)}}})}function tc(e){return v(h(ec(e)),t.low)}function nc(e){return!!e.type?.startsWith(`image/`)}function rc(e,t){return nc(e)?``:`[${oc(e.name)}](${t})`}function ic(e,t){return!e||!t.onFilePaste?[]:Array.from(e.files)}const ac=e=>{console.error(`[meowdown] failed to save pasted file:`,e)};function oc(e){return e.replaceAll(/[\\[\]]/g,String.raw`\$&`)}async function sc(e,t,n,r){let{onFilePaste:i}=n;if(!i)return;let a=n.onFileSaveError??ac,o=r,s=!1;for(let n of t){let t;try{t=await i(n)}catch(e){a(e,n);continue}if(!t||e.isDestroyed)continue;let r=rc(n,t),c=s?`\n${r}`:r,l=o==null?e.state.tr.insertText(c):e.state.tr.insertText(c,o);e.dispatch(l),s=!0,o!=null&&(o+=c.length)}}function cc(e){return new y({key:new b(`file-paste`),props:{handlePaste:(t,n)=>{let r=ic(n.clipboardData,e);return r.length===0?!1:(sc(t,r,e),!0)},handleDrop:(t,n)=>{let r=ic(n.dataTransfer,e);return r.length===0?!1:(sc(t,r,e,t.posAtCoords({left:n.clientX,top:n.clientY})?.pos),!0)}}})}function lc(e={}){return v(h(cc(e)),t.high)}const uc=new b(`meowdown-file-click`);function dc(e,t){let n=T(e,t,`mdFile`);if(!n)return;let{href:r,name:i}=n.mark.attrs;return{href:r,name:i}}function fc(e){return h(new y({key:uc,props:{handleClick:(t,n,r)=>{let i=r.target?.closest?.(`.md-file-view-preview`);if(!i)return!1;let a=i.closest(`.md-file-view`)?.querySelector(`.md-file-view-content`);if(!a)return!1;let o=dc(t.state,t.posAtDOM(a,0));return o?(e({href:o.href,name:o.name,event:r}),!0):!1}}}))}const pc=[`KB`,`MB`,`GB`,`TB`];function mc(e){let t=e,n=`B`;for(let e of pc){if(t<999.5)break;t/=1e3,n=e}return n===`B`?`${Math.round(t)} B`:`${t<9.95?Math.round(t*10)/10:Math.round(t)} ${n}`}const hc=new Map([[`pdf`,`pdf`],[`zip`,`archive`],[`tar`,`archive`],[`gz`,`archive`],[`tgz`,`archive`],[`rar`,`archive`],[`7z`,`archive`],[`doc`,`doc`],[`docx`,`doc`],[`pages`,`doc`],[`xls`,`sheet`],[`xlsx`,`sheet`],[`csv`,`sheet`],[`numbers`,`sheet`],[`ppt`,`slides`],[`pptx`,`slides`],[`key`,`slides`],[`mp3`,`audio`],[`wav`,`audio`],[`m4a`,`audio`],[`flac`,`audio`],[`ogg`,`audio`],[`mp4`,`video`],[`mov`,`video`],[`mkv`,`video`],[`webm`,`video`],[`txt`,`text`],[`md`,`text`]]);function gc(e){let t=e.split(/[?#]/,1)[0],n=t.lastIndexOf(`.`);if(n<0)return`generic`;let r=t.slice(n+1).toLowerCase();return hc.get(r)??`generic`}const _c=`http://www.w3.org/2000/svg`;function vc(){let e=document.createElementNS(_c,`svg`);e.setAttribute(`class`,`md-file-view-icon`),e.setAttribute(`viewBox`,`0 0 24 24`),e.setAttribute(`aria-hidden`,`true`);for(let t of[`M15 2H6a2 2 0 0 0-2 2v16a2 2 0 0 0 2 2h12a2 2 0 0 0 2-2V7Z`,`M14 2v4a2 2 0 0 0 2 2h4`]){let n=document.createElementNS(_c,`path`);n.setAttribute(`d`,t),n.setAttribute(`fill`,`none`),n.setAttribute(`stroke`,`currentColor`),n.setAttribute(`stroke-width`,`2`),n.setAttribute(`stroke-linecap`,`round`),n.setAttribute(`stroke-linejoin`,`round`),e.appendChild(n)}return e}var yc=class{#e;#t;#n;#r;#i;#a;#o=!1;constructor(e,t){this.#a=e.attrs,this.#e=document.createElement(`span`),this.#e.className=`md-file-view md-atom-view`,this.#n=document.createElement(`span`),this.#n.className=`md-file-view-preview md-atom-view-preview`,this.#n.contentEditable=`false`,this.#n.dataset.testid=`file-pill`,this.#n.dataset.fileKind=gc(this.#a.href),this.#n.title=this.#a.name,this.#e.appendChild(this.#n),this.#n.appendChild(vc()),this.#r=document.createElement(`span`),this.#r.className=`md-file-view-name`,this.#r.textContent=this.#a.name,this.#n.appendChild(this.#r),this.#i=document.createElement(`span`),this.#i.className=`md-file-view-size`,this.#i.dataset.testid=`file-pill-size`,this.#n.appendChild(this.#i),this.#t=document.createElement(`span`),this.#t.className=`md-file-view-content md-atom-view-content`,this.#e.appendChild(this.#t),this.#s(t.resolveFileInfo)}get dom(){return this.#e}get contentDOM(){return this.#t}update(e){let t=e.attrs,n=this.#a;return t.href===n.href?(this.#a=t,t.name!==n.name&&(this.#r.textContent=t.name,this.#n.title=t.name),!0):!1}ignoreMutation(e){return!this.#t.contains(e.target)}destroy(){this.#o=!0}async#s(e){if(!e)return;let t;try{t=await e(this.#a.href)}catch(e){console.error(`[meowdown] resolveFileInfo failed:`,e);return}if(this.#o||!t)return;let{size:n}=t;n==null||!Number.isFinite(n)||n<0||(this.#i.textContent=mc(n))}};function bc(e={}){return f({name:`mdFile`,constructor:t=>new yc(t,e)})}function xc(e){return h(new y({key:e.key,props:{handleClick:(t,n,r)=>{if(!r.target?.closest?.(e.selector))return!1;let i=e.findPayloadAt(t.state,n);return i==null?!1:(e.preventDefault&&r.preventDefault(),e.onClick(i,r),!0)}}}))}const Sc=new b(`meowdown-tag-click`);function Cc(e,t){let n=T(e,t,`mdTag`);if(!n)return;let r=e.doc.textBetween(n.from,n.to),i=r.startsWith(`#`)?r.slice(1):r;return{from:n.from,to:n.to,tag:i}}function wc(e){return xc({key:Sc,selector:`.md-tag`,preventDefault:!1,findPayloadAt:(e,t)=>Cc(e,t)?.tag,onClick:(t,n)=>e({tag:t,event:n})})}const Tc=new b(`meowdown-wikilink-click`);function Ec(e,t){let n=T(e,t,`mdWikilink`);if(!n)return;let{target:r}=n.mark.attrs;return{from:n.from,to:n.to,target:r}}function Dc(e){return xc({key:Tc,selector:`.md-wikilink-view-preview`,preventDefault:!1,findPayloadAt:(e,t)=>Ec(e,t)?.target,onClick:(t,n)=>e({target:t,event:n})})}const Oc=new b(`meowdown-follow-link`);function kc(e){return e.key!==`Enter`||e.shiftKey||e.altKey?!1:ie?e.metaKey&&!e.ctrlKey:e.ctrlKey&&!e.metaKey}function Ac(e){return new y({key:Oc,props:{handleKeyDown:(t,n)=>{if(!kc(n))return!1;let{state:r}=t,i=r.selection.head,a=e.onWikilinkClick&&Ec(r,i);if(a)return e.onWikilinkClick?.({target:a.target,event:n}),!0;let o=e.onTagClick&&Cc(r,i);if(o)return e.onTagClick?.({tag:o.tag,event:n}),!0;let s=e.onFileClick&&dc(r,i);if(s)return e.onFileClick?.({href:s.href,name:s.name,event:n}),!0;let c=e.onLinkClick&&G(r,i);return c?(e.onLinkClick?.({href:c.href,event:n}),!0):!1}}})}function jc(e){return v(h(Ac(e)),t.high)}const Mc=(e,t)=>{let n={type:`highlight`,children:e.all(t)};return e.patch(t,n),n},Nc=(e,t,n,r)=>{let i=e,a=n.createTracker(r),o=a.move(`==`);return o+=a.move(n.containerPhrasing(i,{...a.current(),before:o,after:`=`})),o+=a.move(`==`),o};function Pc(){return jt().use(Dt).use(Ot,{handlers:{mark:Mc}}).use(kt).use(At,{bullet:`-`,emphasis:`*`,strong:`*`,fence:"`",fences:!0,rule:`-`,ruleRepetition:3,listItemIndent:`one`,handlers:{highlight:Nc}}).freeze()}const Fc=ve(Pc);function Ic(e){return String(Fc().processSync(e))}const Lc=new b(`meowdown-html-paste`);function Rc(){return h(new y({key:Lc,props:{transformPastedHTML:(e,t)=>{if(e.includes(`data-pm-slice`))return e;let n=t.state.selection.$from.parent;if(!n.inlineContent||n.type.spec.code)return e;let r=Ic(e);if(!r.trim())return e;let i=Y(r,{nodes:Bo(t.state.schema)}),a=Le.fromSchema(t.state.schema),o=document.createElement(`div`);return o.append(a.serializeFragment(i.content)),o.innerHTML}}}))}const zc=new b(`meowdown-image-click`);function $(e){return e instanceof HTMLElement&&e.closest(`.md-image-view-preview`)}function Bc(e,t){let n=T(e,t,`mdImage`);if(!n)return;let{src:r,alt:i}=n.mark.attrs;return{from:n.from,to:n.to,src:r,alt:i}}function Vc(e,t){let n=t.closest(`.md-image-view`)?.querySelector(`.md-image-view-content`);if(n)return Bc(e.state,e.posAtDOM(n,0))}function Hc(e,t){return Array.from(e).find(e=>e.identifier===t)}function Uc(e,t){return Math.abs(t.clientX-e.clientX)<=10&&Math.abs(t.clientY-e.clientY)<=10}function Wc(e){let t=new WeakMap;return h(new y({key:zc,props:{handleDOMEvents:{pointerdown:(e,t)=>($(t.target)&&t.pointerType!==`mouse`&&t.preventDefault(),!1),touchstart:(e,n)=>{if(t.delete(e),n.touches.length!==1||!$(n.target)||n.target instanceof HTMLElement&&n.target.closest(`.md-image-resize-handle`))return!1;let r=n.changedTouches[0];return r&&t.set(e,{identifier:r.identifier,clientX:r.clientX,clientY:r.clientY}),!1},touchmove:(e,n)=>{let r=t.get(e);if(!r)return!1;let i=Hc(n.changedTouches,r.identifier);return i&&!Uc(r,i)&&t.delete(e),!1},touchcancel:e=>(t.delete(e),!1),touchend:(n,r)=>{let i=t.get(n);if(t.delete(n),!i||r.touches.length>0)return!1;let a=Hc(r.changedTouches,i.identifier);if(!a||!Uc(i,a))return!1;let o=$(r.target);if(!o)return!1;r.preventDefault();let s=Vc(n,o);return s&&e({src:s.src,alt:s.alt,event:r}),!0}},handleClick:(t,n,r)=>{let i=$(r.target);if(!i)return!1;let a=Vc(t,i);return a?(e({src:a.src,alt:a.alt,event:r}),!0):!1}}}))}function Gc(e){return/^https?:\/\//i.test(e)?e:void 0}function Kc(e){let t=document.createElement(`iframe`);return t.src=e.src,t.title=e.title,t.className=e.className,t.dataset.testid=e.testid,t.loading=`lazy`,t.referrerPolicy=`strict-origin-when-cross-origin`,t.setAttribute(`frameborder`,`0`),e.allow&&(t.allow=e.allow),e.allowFullscreen&&(t.allowFullscreen=!0),e.kind===`tweet`&&Rs(t),t}function qc(e,t,n,r){if(n!=null&&r!=null){e.setAttribute(`data-width`,String(n)),e.setAttribute(`data-height`,String(r));return}let i=t.naturalWidth/t.naturalHeight;if(!Number.isFinite(i)||i<=0){n!=null&&e.setAttribute(`data-width`,String(n)),r!=null&&e.setAttribute(`data-height`,String(r));return}let a=n==null?Math.min(t.naturalHeight,500):n/i,o=n??a*i;e.setAttribute(`data-width`,String(Math.round(o))),e.setAttribute(`data-height`,String(Math.round(a)))}function Jc(e,t,n,r){let i=e.posAtDOM(t,0),a=T(e.state,i,`mdImage`);if(!a)return;let o=e.state.doc.textBetween(a.from,a.to),s=Hr(o),c=a.from+s.length,l=o.slice(s.length),u=Vr({...zr(l)??{},width:Math.round(n),height:Math.round(r)});u!==l&&e.dispatch(e.state.tr.insertText(u,c,a.to))}var Yc=class{#e;#t;#n;#r;#i;#a;#o;constructor(e,t,n){this.#i=e.attrs,this.#n=n,this.#r=t,this.#e=document.createElement(`span`),this.#e.className=`md-image-view md-atom-view`,this.#t=document.createElement(`span`),this.#t.className=`md-image-view-content md-atom-view-content`;let r=this.#s();r&&(r.contentEditable=`false`,this.#e.appendChild(r)),this.#e.appendChild(this.#t)}get dom(){return this.#e}get contentDOM(){return this.#t}update(e){let t=e.attrs,n=this.#i;return t.src===n.src?(this.#i=t,this.#o&&t.alt!==n.alt&&(this.#o.alt=t.alt),this.#a&&this.#o&&(t.width!==n.width||t.height!==n.height)&&qc(this.#a,this.#o,t.width,t.height),!0):!1}ignoreMutation(e){return!this.#t.contains(e.target)}#s(){let{src:e}=this.#i,t=Gs(e);if(t){let e=document.createElement(`span`);return e.className=`md-image-view-preview md-atom-view-preview`,e.appendChild(Kc(t)),e}let n=(this.#n.resolveImageUrl??Gc)(e);if(!n)return;let r=document.createElement(`span`);return r.className=`md-image-view-preview md-atom-view-preview`,r.dataset.testid=`image-preview`,r.appendChild(this.#c(n)),r}#c(e){Nt(),Mt();let t=document.createElement(`prosekit-resizable-root`);t.className=`md-image-resizable`,t.dataset.testid=`image-resizable`,t.setAttribute(`data-loading`,``);let n=document.createElement(`img`);n.src=e,n.alt=this.#i.alt,n.draggable=!1,qc(t,n,this.#i.width,this.#i.height),n.addEventListener(`load`,()=>{t.removeAttribute(`data-loading`);let e=n.naturalWidth/n.naturalHeight;!Number.isFinite(e)||e<=0||(t.setAttribute(`data-aspect-ratio`,String(e)),qc(t,n,this.#i.width,this.#i.height))}),n.addEventListener(`error`,()=>{t.removeAttribute(`data-loading`)}),t.appendChild(n);let r=document.createElement(`prosekit-resizable-handle`);return r.className=`md-image-resize-handle`,r.setAttribute(`position`,`bottom-right`),r.addEventListener(`click`,e=>e.stopPropagation()),t.appendChild(r),t.addEventListener(`resizeEnd`,e=>{let{width:t,height:n}=e.detail;Jc(this.#r,this.#t,t,n)}),this.#a=t,this.#o=n,t}};function Xc(e={}){return f({name:`mdImage`,constructor:(t,n)=>new Yc(t,n,e)})}const Zc={"Mod-b":`Bold`,"Mod-i":`Italic`,"Mod-e":`Inline code`,"Mod-Shift-x":`Strikethrough`,"Mod-Shift-h":`Highlight`,"Mod-k":`Link`,"Mod-Shift-k":`Insert a wikilink`,"Mod-1":`Heading 1`,"Mod-2":`Heading 2`,"Mod-3":`Heading 3`,"Mod-4":`Heading 4`,"Mod-5":`Heading 5`,"Mod-6":`Heading 6`,"Mod-.":`Fold or unfold a bullet`,"Mod-Enter":`Follow the link under the caret, or cycle a checkbox task`,"Mod-Shift-Enter":`Cycle a circle checkbox task`,"Mod-Shift-7":`Ordered list`,"Mod-Shift-8":`Bullet list`,"Mod-Shift-9":`Checkbox task list`,"Alt-ArrowUp":`Move the block or list item up`,"Alt-ArrowDown":`Move the block or list item down`,"Meta-ArrowUp":`Move the caret to the document start`,"Meta-ArrowDown":`Move the caret to the document end`,"Shift-Meta-ArrowUp":`Select to the document start`,"Shift-Meta-ArrowDown":`Select to the document end`,Escape:`Collapse the selection`},Qc=new b(`meowdown-link-click`);function $c(e){return xc({key:Qc,selector:`.md-link`,preventDefault:!0,findPayloadAt:(e,t)=>G(e,t)?.href,onClick:(t,n)=>e({href:t,event:n})})}function el(e){let t,n=(n,r)=>{let i=r.target;if(!i||!_e(i))return;let a=i.closest(e.selector);if(!a||a===t)return;let o=n.posAtDOM(a,0),s=e.findPayloadAt(n.state,o);s!=null&&(t=a,e.onHoverChange({payload:s,element:a}))},r=n=>{if(!t)return;let r=n.relatedTarget;r&&t.contains(r)||(t=void 0,e.onHoverChange(void 0))};return _(c(`mouseover`,(e,t)=>n(e,t)),c(`mouseout`,(e,t)=>r(t)))}function tl(e){return el({selector:`.md-link`,findPayloadAt:(e,t)=>G(e,t),onHoverChange:e})}const nl=new b(`meowdown-link-paste`);function rl(e){let t=e.trim();if(!(!t||/\s/.test(t)))return fr(t)}function il(){return v(h(new y({key:nl,props:{handlePaste:(e,t,n)=>{let r=Ks(t,n);if(!r)return!1;let i=rl(r);return i?Pn(e,Xi({href:i,wrapText:!1})):!1}}})),t.high)}const al=new b(`meowdown-markdown-copy`);function ol(){return h(new y({key:al,props:{clipboardTextSerializer:(e,t)=>{let n=e.content,r;try{r=t.state.schema.topNodeType.createAndFill(void 0,n)??void 0}catch{r=void 0}return r?Q(r).replace(/\n+$/,``):n.textBetween(0,n.size,`
|
|
29
29
|
`,`
|
|
30
|
-
`)}}}))}function
|
|
30
|
+
`)}}}))}function sl({allowEmpty:e}){return(t,n)=>{let{selection:r}=t;if(!g(r)||!e&&r.empty||!r.$head.sameParent(r.$anchor)||r.$head.parent.type.spec.code)return!1;let i=t.doc.textBetween(r.from,r.to);if(i.startsWith(`[[`))return!1;i.startsWith(`[`)&&(i=i.slice(1));let a=`[[`+i;if(n){let e=t.tr.insertText(a,r.from,r.to);e.setSelection(x.create(e.doc,r.from+a.length)),Ie(e),n(e.scrollIntoView())}return!0}}function cl(){return u({"Mod-Shift-k":sl({allowEmpty:!0}),"[":sl({allowEmpty:!1})})}function ll(e){let{selection:t,schema:n}=e;if(t.empty)return``;let r=t.content().content;try{return Q(n.topNodeType.create(null,r)).replace(/\n+$/,``)}catch{return e.doc.textBetween(t.from,t.to,`
|
|
31
31
|
|
|
32
|
-
`)}}function
|
|
32
|
+
`)}}function ul(e,t){let n=new DOMRect(0,0,0,0),r=()=>{if(e.isDestroyed)return n;let r=J(e,t.from,1)??J(e,t.from,-1),i=J(e,t.to,-1)??J(e,t.to,1);if(r==null||i==null)return n;let a=Math.min(r.left,i.left),o=Math.max(r.right,i.right),s=Math.min(r.top,i.top),c=Math.max(r.bottom,i.bottom);return n=new DOMRect(a,s,o-a,c-s),n};return{getBoundingClientRect:r,getClientRects:()=>[r()]}}function dl(e){return e instanceof We||e instanceof Ge||e instanceof Ke||e instanceof qe||e instanceof L}function fl(e){for(let t of e)for(let e of t.steps)if(!dl(e))return!0;return!1}function pl(e){let t,n,r=!1,i,a=()=>{let n=t&&!t.isDestroyed&&t.dom;if(!n)return;let a=e&&!r;a!==i&&(i=a,n.spellcheck=a)},o=()=>{n&&clearTimeout(n),r=!0,a(),n=setTimeout(()=>{r=!1,a()},1200)};return{pause:o,apply(e){fl(e)&&o()},view(e){return t=e,{destroy(){t=void 0}}}}}function ml(e){let t=new b(`spell-check`);return new y({key:t,state:{init:()=>pl(e),apply:(e,t)=>t},view(e){return t.getState(e.state)?.view(e)||{}},props:{handleDOMEvents:{beforeinput:e=>{t.getState(e.state)?.pause()}}},appendTransaction(e,n){t.getState(n)?.apply(e)}})}function hl(e){return h(ml(e))}export{Zc as EDITOR_KEY_BINDINGS,e as Priority,rc as buildFileMarkdown,Os as checkRoundTrip,Ms as codeBlockLanguages,Gc as defaultResolveImageUrl,As as defineBulletAfterHeading,pe as defineCodeBlockPreviewPlugin,ln as defineCodeBlockSyntaxHighlight,No as defineEditorExtension,Xs as defineEmbedPaste,tc as defineExitBoundaryHandler,fc as defineFileClickHandler,lc as defineFilePaste,bc as defineFileView,jc as defineFollowLinkHandler,rr as defineHTMLComment,Rc as defineHTMLPaste,Xc as defineImage,Wc as defineImageClickHandler,$c as defineLinkClickHandler,$i as defineLinkCommands,ta as defineLinkEditKeymap,tl as defineLinkHoverHandler,il as defineLinkPaste,ol as defineMarkdownCopy,Ma as defineMath,go as definePendingReplacementHandler,he as definePlaceholder,ge as defineReadonly,hl as defineSpellCheckPlugin,wc as defineTagClickHandler,Dc as defineWikilinkClickHandler,cl as defineWikilinkTrigger,Q as docToMarkdown,dn as getCodeTokens,G as getLinkUnitAt,Io as getMarkBuilders,q as getPendingReplacement,ll as getSelectedText,Ga as getTableColumnAlign,ul as getVirtualElementFromRange,qr as inlineTextToMarkChunks,Xi as insertLink,me as isCodeBlockPreviewHiddenDecoration,Ja as isSelectionInTableCell,Rs as listenForTweetHeight,ka as loadKaTeX,Y as markdownToDoc,Gs as matchEmbed,Qi as removeLink,Aa as renderMathInto,Zi as updateLink,le as withPriority};
|