@meowdown/core 0.57.0 → 0.57.2
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/README.md +1 -1
- package/dist/index.js +24 -20
- package/dist/style.css +4 -1
- package/package.json +3 -3
package/README.md
CHANGED
|
@@ -130,7 +130,7 @@ GFM table column alignment (`| :-: |` in the delimiter row) is kept as an `align
|
|
|
130
130
|
|
|
131
131
|
Pasting a lone tweet or YouTube link can auto-embed it: [`defineEmbedPaste`](https://npmx.dev/package-docs/@meowdown%2Fcore#function-defineEmbedPaste) (`@meowdown/react`'s `embedPaste` prop, on by default).
|
|
132
132
|
|
|
133
|
-
The clipboard pipeline ships inside `defineEditorExtension`. Copying writes two flavors: `text/html` is standard semantic HTML (`<h3>`, `<ol><li>`, `<strong>`, real `<table>`) with the Markdown source preserved in `data-md` attributes so meowdown-to-meowdown pastes stay byte-exact, and `text/plain` is Markdown, where
|
|
133
|
+
The clipboard pipeline ships inside `defineEditorExtension`. Copying writes two flavors: `text/html` is standard semantic HTML (`<h3>`, `<ol><li>`, `<strong>`, real `<table>`) with the Markdown source preserved in `data-md` attributes so meowdown-to-meowdown pastes stay byte-exact, and `text/plain` is Markdown, where opening markers such as ATX heading and blockquote prefixes are kept when the selection includes the block's content start, while fenced code blocks and tables keep their markers only when selected completely; the mark mode decides the inline layer (hide strips the syntax characters, focus and show keep the full source). Pasting picks a path by flavor: meowdown's own HTML (stamped `data-meowdown`) parses natively; foreign rich-text HTML, including other ProseMirror editors, converts to Markdown through the unified (rehype / remark) pipeline; plain text follows Markdown newline semantics (a blank line separates paragraphs without inserting an empty one, a single newline stays a soft break) while a Shift-paste keeps ProseMirror's line-per-paragraph behavior; a paste landing in a code block stays plain text.
|
|
134
134
|
|
|
135
135
|
Enter at the end of the document's first heading (the title line) can start a fresh empty bullet instead of a plain paragraph: [`defineBulletAfterHeading`](https://npmx.dev/package-docs/@meowdown%2Fcore#function-defineBulletAfterHeading) (`@meowdown/react`'s `bulletAfterHeading` prop). Not part of `defineEditorExtension`.
|
|
136
136
|
|
package/dist/index.js
CHANGED
|
@@ -1,34 +1,38 @@
|
|
|
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,defineHistory as c,defineKeymap as l,defineMarkSpec as u,defineMarkView as d,defineNodeAttr as f,defineNodeSpec as p,definePlugin as m,getMarkRange as h,getMarkType as ee,getNodeType as te,isAllSelection as ne,isApple as re,isAtBlockStart as ie,isNodeSelection as ae,isTextSelection as g,setBlockType as oe,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{LEZER_NODE_IDS as y,collectInlineElements as _e,getAutolinkHref as ve,gfmBlockOnlyParser as ye,isSpaceChar as b,parseInline as be}from"@meowdown/markdown";import{isElementLike as xe,isHTMLElement as Se,isObject as Ce,once as we}from"@ocavue/utils";import{defineBlockquote as Te}from"@prosekit/extensions/blockquote";import{defineDoc as Ee}from"@prosekit/extensions/doc";import{defineGapCursor as De}from"@prosekit/extensions/gap-cursor";import{defineModClickPrevention as Oe}from"@prosekit/extensions/mod-click-prevention";import{defineText as ke}from"@prosekit/extensions/text";import{defineVirtualSelection as Ae}from"@prosekit/extensions/virtual-selection";import{NodeSelection as je,Plugin as x,PluginKey as S,Selection as Me,TextSelection as C}from"@prosekit/pm/state";import{Decoration as Ne,DecorationSet as w}from"@prosekit/pm/view";import{defaultHandlers as Pe}from"hast-util-to-mdast";import{defaultHandlers as Fe}from"mdast-util-to-markdown";import Ie from"rehype-parse";import Le from"rehype-remark";import Re from"remark-gfm";import ze from"remark-stringify";import{unified as Be}from"unified";import{DOMParser as Ve,DOMSerializer as He,Fragment as T,Mark as Ue,Slice as E}from"@prosekit/pm/model";import{defineHeadingCommands as We,defineHeadingInputRule as Ge,defineHeadingSpec as Ke}from"@prosekit/extensions/heading";import{defineParagraphCommands as qe,defineParagraphKeymap as Je}from"@prosekit/extensions/paragraph";import{LanguageDescription as Ye}from"@codemirror/language";import{languages as Xe}from"@codemirror/language-data";import{classHighlighter as Ze,highlightTree as Qe}from"@lezer/highlight";import{createParser as $e}from"prosemirror-highlight/lezer";import{defineEnterRule as et,defineTextBlockEnterRule as tt}from"@prosekit/extensions/enter-rule";import{defineInputRule as nt,defineTextBlockInputRule as rt}from"@prosekit/extensions/input-rule";import{triggerAutocomplete as it}from"@prosekit/extensions/autocomplete";import{defineListCommands as at,defineListDropIndicator as ot,defineListKeymap as st,defineListSpec as ct,moveList as lt,toggleList as ut,unwrapList as dt,wrapInList as D}from"@prosekit/extensions/list";import{chainCommands as ft,lift as pt}from"@prosekit/pm/commands";import{defineHorizontalRule as mt}from"@prosekit/extensions/horizontal-rule";import{AddMarkStep as ht,AddNodeMarkStep as gt,RemoveMarkStep as _t,RemoveNodeMarkStep as vt,ReplaceStep as yt,Step as bt,StepResult as xt,Transform as St}from"@prosekit/pm/transform";import{createListRenderingPlugin as Ct,createSafariInputMethodWorkaroundPlugin as wt,createToggleCollapsedCommand as Tt,defaultAttributesGetter as Et,findCheckboxInListItem as Dt,handleListMarkerMouseDown as Ot,joinListElements as kt,listToDOM as At,unwrapListSlice as jt,wrappingListInputRule as Mt}from"prosemirror-flat-list";import{defineTableCellSpec as Nt,defineTableCommands as Pt,defineTableDropIndicator as Ft,defineTableEditingPlugin as It,defineTableHeaderCellSpec as Lt,defineTableRowSpec as Rt,defineTableSpec as zt,deleteTable as Bt,isCellSelection as Vt}from"@prosekit/extensions/table";import{closeHistory as Ht}from"@prosekit/pm/history";import{registerResizableHandleElement as Ut,registerResizableRootElement as Wt}from"@prosekit/web/resizable";import{InputRule as Gt}from"@prosekit/pm/inputrules";function O(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 h(a,n,r)}const k=new S(`mark-mode`);function Kt(e){return k.getState(e)}function qt(e){return new x({key:k,state:{init:()=>e,apply:(e,t)=>e.getMeta(k)??t},props:{attributes:t=>({"data-mark-mode":Kt(t)??e}),decorations:e=>{let t=Kt(e);if(t===`focus`)return Xt(e);if(t===`hide`)return Zt(e)}}})}function Jt(e){return(t,n)=>A(t)===e?!1:(n?.(t.tr.setMeta(k,e)),!0)}function Yt(e){return _(m(qt(e)),s({setMarkMode:Jt}))}function A(e){return k.getState(e)}function Xt(e){return Qt(e,void 0)}function Zt(e){return Qt(e,{key:`math`})}function Qt(e,t){let{selection:n}=e;if(!n.empty)return w.empty;let r=n.$head,{parent:i}=r;if(!i.isTextblock||i.type.spec.code)return w.empty;let a=h(r,ee(e.schema,`mdPack`),t);return a?w.create(e.doc,[Ne.inline(a.from,a.to,{class:`show`})]):w.empty}const $t=[`mdImage`,`mdWikilink`,`mdFile`];function j(e,t){let n=A(t);return n?e.flatMap(e=>e.modes.includes(n)?[e.name]:[]):[]}function en(e,t,n){for(let r of n){let n=O(e,t,r);if(n)return n}}function M(e,t,n){let r=en(e,t,n);return r&&r.to===t?r:void 0}function N(e,t,n){let r=en(e,t,n);return r&&r.from===t?r:void 0}function tn(e,t){let{from:n,to:r,empty:i}=e.selection;if(i)return;let a=en(e,n,t);return a&&a.from===n&&a.to===r?a:void 0}function nn(e,t){return C.create(e.doc,t.from,t.to)}function rn(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?N(e,t,n):M(e,t,n),o=r===-1?i.before():i.after(),s=Me.findFrom(e.doc.resolve(o),r);if(!s)return;let c=g(s)?r===-1?M(e,s.head,n):N(e,s.head,n):void 0;if(!(a==null&&c==null))return s}function an(e){return(t,n)=>{let r=j(e,t);if(r.length===0||!g(t.selection))return!1;let i=t.selection;if(i.empty){let e=N(t,i.from,r);if(e)return n?.(t.tr.setSelection(nn(t,e))),!0;if(M(t,i.from,r)&&i.from<t.doc.resolve(i.from).end())return n?.(t.tr.setSelection(C.create(t.doc,i.from+1))),!0;let a=rn(t,i.from,r,1);return a?(n?.(t.tr.setSelection(a).scrollIntoView()),!0):!1}let a=tn(t,r);return a?(n?.(t.tr.setSelection(C.create(t.doc,a.to))),!0):!1}}function on(e){return(t,n)=>{let r=j(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(nn(t,e))),!0;let a=rn(t,i.from,r,-1);return a?(n?.(t.tr.setSelection(a).scrollIntoView()),!0):!1}let a=tn(t,r);return a?(n?.(t.tr.setSelection(C.create(t.doc,a.from))),!0):!1}}function sn(e,t){return(n,r)=>{let i=j(e,n);if(i.length===0||!g(n.selection))return!1;let{anchor:a,head:o}=n.selection,s=t===-1?M(n,o,i):N(n,o,i);if(s){let e=t===-1?s.from:s.to;return r?.(n.tr.setSelection(C.create(n.doc,a,e)).scrollIntoView()),!0}let c=rn(n,o,i,t);return!c||!g(c)?!1:(r?.(n.tr.setSelection(C.create(n.doc,a,c.head)).scrollIntoView()),!0)}}function cn(e){return(t,n)=>{let r=j(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):!N(t,i,r)||i<=t.doc.resolve(i).start()?!1:(n?.(t.tr.delete(i-1,i)),!0)}}function ln(e){return(t,n)=>{let r=j(e,t);if(r.length===0||!t.selection.empty)return!1;let i=t.selection.from,a=N(t,i,r);return a?(n?.(t.tr.delete(a.from,a.to)),!0):!M(t,i,r)||i>=t.doc.resolve(i).end()?!1:(n?.(t.tr.delete(i,i+1)),!0)}}const un=`md-atom-selected`;function dn(e){return new x({key:new S(`atom-mark-selection`),props:{decorations:t=>{let n=j(e,t);if(n.length===0||ae(t.selection))return;let r=tn(t,n);if(r)return w.create(t.doc,[Ne.inline(r.from,r.to,{class:un})]);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(Ne.inline(t,t+e.nodeSize,{class:un}))}),w.create(t.doc,s)}}})}function fn({marks:e}){return _(v(l({ArrowRight:an(e),ArrowLeft:on(e),"Shift-ArrowRight":sn(e,1),"Shift-ArrowLeft":sn(e,-1),Backspace:cn(e),Delete:ln(e)}),t.high),m(dn(e)))}const pn=(e,t)=>{let n={type:`highlight`,children:e.all(t)};return e.patch(t,n),n},mn=(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 hn(e){return e.tagName===`input`&&e.properties.type===`checkbox`}function gn(e){for(let t of e.children){if(t.type!==`element`)continue;if(hn(t))return t;let e=gn(t);if(e)return e}}function _n(e){let t=e.properties.dataChecked,n=gn(e);if(!(t!=null||e.properties.dataType===`taskItem`||e.properties.dataTaskListItem!=null||n!==void 0))return;let r=typeof t==`string`?t!==`false`:!!n?.properties.checked,i=e.children.filter(e=>e.type!==`element`||!(hn(e)||e.tagName===`label`&&gn(e)));for(let e of[`div`,`p`]){let t=i.length===1&&i[0].type===`element`?i[0]:void 0;t?.tagName===e&&(i=t.children)}let a={type:`element`,tagName:`input`,properties:{type:`checkbox`,checked:r},children:[]};return{...e,children:[a,...i]}}const vn=(e,t)=>Pe.li(e,_n(t)??t);function yn(e){return e.filter(e=>e.character!==`[`&&e.character!==`~`?!0:e.atBreak?e.character===`~`:!(Array.isArray(e.inConstruct)?e.inConstruct:e.inConstruct?[e.inConstruct]:[]).includes(`phrasing`))}const bn=(e,t,n,r)=>Fe.text(e,t,{...n,unsafe:yn(n.unsafe)},r);function xn(){return Be().use(Ie).use(Le,{handlers:{mark:pn,li:vn}}).use(Re).use(ze,{bullet:`-`,emphasis:`*`,strong:`*`,fence:"`",fences:!0,rule:`-`,ruleRepetition:3,listItemIndent:`one`,handlers:{highlight:mn,text:bn}}).freeze()}const Sn=we(xn);function Cn(e){return String(Sn().processSync(e))}function wn(e){if(e==null)return;let t=Number.parseInt(e,10);return Number.isSafeInteger(t)?t:void 0}function P(e){let t=wn(e);return t!=null&&t>0?t:void 0}function Tn(e,t){return e.type.name===t}const En=new Set([`mdMark`,`mdLinkUri`,`mdLinkTitle`]),Dn=new Set([`mdWikilink`,`mdImage`,`mdFile`,`mdMath`]);function On(e){return e.find(e=>Dn.has(e.type.name))}function kn(e){return e.some(e=>En.has(e.type.name))}function An(e){let t=[];return e.forEach(e=>{if(!e.isText||!e.text)return;let n=On(e.marks),r=t.at(-1);if(n!=null&&r!=null&&r.atom===n){r.text+=e.text,r.children.push(e);return}t.push({atom:n,text:e.text,children:[e]})}),t}const jn={mdStrong:`strong`,mdEm:`em`,mdCode:`code`,mdDel:`del`,mdHighlight:`mark`,mdLinkText:`a`};function Mn(e,t,n={}){let r=document.createElement(e);r.setAttribute(`data-md`,t.textContent);for(let[e,t]of Object.entries(n))t!=null&&r.setAttribute(e,t);return Pn(t,r),r}function Nn(e,t,n){return{tag:`${e}[data-md]`,node:t,priority:100,getAttrs:n,getContent:(e,t)=>{let n=(Se(e)?e:void 0)?.getAttribute(`data-md`)??``;return n?T.from(t.text(n)):T.empty}}}function Pn(e,t){let n=[];for(let r of An(e)){if(r.atom!=null){n.length=0,t.append(Ln(r.atom,r.text));continue}for(let e of r.children)kn(e.marks)||(Fn(n,e.marks.filter(e=>jn[e.type.name]),t),In(n.at(-1)?.element??t,e.text??``))}}function Fn(e,t,n){let r=0;for(;r<e.length&&r<t.length&&t[r].eq(e[r].mark);)r++;e.length=r;for(let i=r;i<t.length;i++){let r=t[i],a=document.createElement(jn[r.type.name]??`span`);Tn(r,`mdLinkText`)&&a.setAttribute(`href`,r.attrs.href),(e.at(-1)?.element??n).append(a),e.push({mark:r,element:a})}}function In(e,t){let n=t.split(`
|
|
2
|
-
`);for(let[t,r]of n.entries())t>0&&e.append(document.createElement(`br`)),r&&e.append(document.createTextNode(r))}function Ln(e,t){switch(e.type.name){case`mdImage`:{let t=e.attrs,n=document.createElement(`img`);return n.setAttribute(`src`,t.src),t.alt&&n.setAttribute(`alt`,t.alt),t.title&&n.setAttribute(`title`,t.title),t.width!=null&&n.setAttribute(`width`,String(t.width)),t.height!=null&&n.setAttribute(`height`,String(t.height)),n}case`mdWikilink`:{let t=e.attrs;return document.createTextNode(t.display||t.target)}case`mdFile`:{let t=e.attrs,n=document.createElement(`a`);return n.setAttribute(`href`,t.href),n.append(document.createTextNode(t.name||t.href)),n}default:return document.createTextNode(t)}}function
|
|
3
|
-
|
|
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,defineHistory as c,defineKeymap as l,defineMarkSpec as u,defineMarkView as d,defineNodeAttr as f,defineNodeSpec as p,definePlugin as m,getMarkRange as h,getMarkType as ee,getNodeType as te,isAllSelection as ne,isApple as re,isAtBlockStart as ie,isNodeSelection as ae,isTextSelection as g,setBlockType as oe,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{LEZER_NODE_IDS as y,collectInlineElements as _e,getAutolinkHref as ve,gfmBlockOnlyParser as ye,isSpaceChar as b,parseInline as x}from"@meowdown/markdown";import{isElementLike as be,isHTMLElement as xe,isObject as Se,once as Ce}from"@ocavue/utils";import{defineBlockquote as we}from"@prosekit/extensions/blockquote";import{defineDoc as Te}from"@prosekit/extensions/doc";import{defineGapCursor as Ee}from"@prosekit/extensions/gap-cursor";import{defineModClickPrevention as De}from"@prosekit/extensions/mod-click-prevention";import{defineText as Oe}from"@prosekit/extensions/text";import{defineVirtualSelection as ke}from"@prosekit/extensions/virtual-selection";import{NodeSelection as Ae,Plugin as S,PluginKey as C,Selection as je,TextSelection as w}from"@prosekit/pm/state";import{Decoration as Me,DecorationSet as T}from"@prosekit/pm/view";import{NO_BREAK_SPACE as Ne}from"unicode-by-name";import{defaultHandlers as Pe}from"hast-util-to-mdast";import{defaultHandlers as Fe}from"mdast-util-to-markdown";import Ie from"rehype-parse";import Le from"rehype-remark";import Re from"remark-gfm";import ze from"remark-stringify";import{unified as Be}from"unified";import{DOMParser as Ve,DOMSerializer as He,Fragment as E,Mark as Ue,Slice as D}from"@prosekit/pm/model";import{defineHeadingCommands as We,defineHeadingInputRule as Ge,defineHeadingSpec as Ke}from"@prosekit/extensions/heading";import{defineParagraphCommands as qe,defineParagraphKeymap as Je}from"@prosekit/extensions/paragraph";import{LanguageDescription as Ye}from"@codemirror/language";import{languages as Xe}from"@codemirror/language-data";import{classHighlighter as Ze,highlightTree as Qe}from"@lezer/highlight";import{createParser as $e}from"prosemirror-highlight/lezer";import{defineEnterRule as et,defineTextBlockEnterRule as tt}from"@prosekit/extensions/enter-rule";import{defineInputRule as nt,defineTextBlockInputRule as rt}from"@prosekit/extensions/input-rule";import{triggerAutocomplete as it}from"@prosekit/extensions/autocomplete";import{defineListCommands as at,defineListDropIndicator as ot,defineListKeymap as st,defineListSpec as ct,moveList as lt,toggleList as ut,unwrapList as dt,wrapInList as O}from"@prosekit/extensions/list";import{chainCommands as ft,lift as pt}from"@prosekit/pm/commands";import{defineHorizontalRule as mt}from"@prosekit/extensions/horizontal-rule";import{AddMarkStep as ht,AddNodeMarkStep as gt,RemoveMarkStep as _t,RemoveNodeMarkStep as vt,ReplaceStep as yt,Step as bt,StepResult as xt,Transform as St}from"@prosekit/pm/transform";import{createListRenderingPlugin as Ct,createSafariInputMethodWorkaroundPlugin as wt,createToggleCollapsedCommand as Tt,defaultAttributesGetter as Et,findCheckboxInListItem as Dt,handleListMarkerMouseDown as Ot,joinListElements as kt,listToDOM as At,unwrapListSlice as jt,wrappingListInputRule as Mt}from"prosemirror-flat-list";import{defineTableCellSpec as Nt,defineTableCommands as Pt,defineTableDropIndicator as Ft,defineTableEditingPlugin as It,defineTableHeaderCellSpec as Lt,defineTableRowSpec as Rt,defineTableSpec as zt,deleteTable as Bt,isCellSelection as Vt}from"@prosekit/extensions/table";import{closeHistory as Ht}from"@prosekit/pm/history";import{registerResizableHandleElement as Ut,registerResizableRootElement as Wt}from"@prosekit/web/resizable";import{InputRule as Gt}from"@prosekit/pm/inputrules";function k(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 h(a,n,r)}const A=new C(`mark-mode`);function Kt(e){return A.getState(e)}function qt(e){return new S({key:A,state:{init:()=>e,apply:(e,t)=>e.getMeta(A)??t},props:{attributes:t=>({"data-mark-mode":Kt(t)??e}),decorations:e=>{let t=Kt(e);if(t===`focus`)return Xt(e);if(t===`hide`)return Zt(e)}}})}function Jt(e){return(t,n)=>j(t)===e?!1:(n?.(t.tr.setMeta(A,e)),!0)}function Yt(e){return _(m(qt(e)),s({setMarkMode:Jt}))}function j(e){return A.getState(e)}function Xt(e){return Qt(e,void 0)}function Zt(e){return Qt(e,{key:`math`})}function Qt(e,t){let{selection:n}=e;if(!n.empty)return T.empty;let r=n.$head,{parent:i}=r;if(!i.isTextblock||i.type.spec.code)return T.empty;let a=h(r,ee(e.schema,`mdPack`),t);return a?T.create(e.doc,[Me.inline(a.from,a.to,{class:`show`})]):T.empty}const $t=[`mdImage`,`mdWikilink`,`mdFile`];function M(e,t){let n=j(t);return n?e.flatMap(e=>e.modes.includes(n)?[e.name]:[]):[]}function en(e,t,n){for(let r of n){let n=k(e,t,r);if(n)return n}}function N(e,t,n){let r=en(e,t,n);return r&&r.to===t?r:void 0}function P(e,t,n){let r=en(e,t,n);return r&&r.from===t?r:void 0}function tn(e,t){let{from:n,to:r,empty:i}=e.selection;if(i)return;let a=en(e,n,t);return a&&a.from===n&&a.to===r?a:void 0}function nn(e,t){return w.create(e.doc,t.from,t.to)}function rn(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?P(e,t,n):N(e,t,n),o=r===-1?i.before():i.after(),s=je.findFrom(e.doc.resolve(o),r);if(!s)return;let c=g(s)?r===-1?N(e,s.head,n):P(e,s.head,n):void 0;if(!(a==null&&c==null))return s}function an(e){return(t,n)=>{let r=M(e,t);if(r.length===0||!g(t.selection))return!1;let i=t.selection;if(i.empty){let e=P(t,i.from,r);if(e)return n?.(t.tr.setSelection(nn(t,e))),!0;if(N(t,i.from,r)&&i.from<t.doc.resolve(i.from).end())return n?.(t.tr.setSelection(w.create(t.doc,i.from+1))),!0;let a=rn(t,i.from,r,1);return a?(n?.(t.tr.setSelection(a).scrollIntoView()),!0):!1}let a=tn(t,r);return a?(n?.(t.tr.setSelection(w.create(t.doc,a.to))),!0):!1}}function on(e){return(t,n)=>{let r=M(e,t);if(r.length===0||!g(t.selection))return!1;let i=t.selection;if(i.empty){let e=N(t,i.from,r);if(e)return n?.(t.tr.setSelection(nn(t,e))),!0;let a=rn(t,i.from,r,-1);return a?(n?.(t.tr.setSelection(a).scrollIntoView()),!0):!1}let a=tn(t,r);return a?(n?.(t.tr.setSelection(w.create(t.doc,a.from))),!0):!1}}function sn(e,t){return(n,r)=>{let i=M(e,n);if(i.length===0||!g(n.selection))return!1;let{anchor:a,head:o}=n.selection,s=t===-1?N(n,o,i):P(n,o,i);if(s){let e=t===-1?s.from:s.to;return r?.(n.tr.setSelection(w.create(n.doc,a,e)).scrollIntoView()),!0}let c=rn(n,o,i,t);return!c||!g(c)?!1:(r?.(n.tr.setSelection(w.create(n.doc,a,c.head)).scrollIntoView()),!0)}}function cn(e){return(t,n)=>{let r=M(e,t);if(r.length===0||!t.selection.empty)return!1;let i=t.selection.from,a=N(t,i,r);return a?(n?.(t.tr.delete(a.from,a.to)),!0):!P(t,i,r)||i<=t.doc.resolve(i).start()?!1:(n?.(t.tr.delete(i-1,i)),!0)}}function ln(e){return(t,n)=>{let r=M(e,t);if(r.length===0||!t.selection.empty)return!1;let i=t.selection.from,a=P(t,i,r);return a?(n?.(t.tr.delete(a.from,a.to)),!0):!N(t,i,r)||i>=t.doc.resolve(i).end()?!1:(n?.(t.tr.delete(i,i+1)),!0)}}const un=`md-atom-selected`;function dn(e){return new S({key:new C(`atom-mark-selection`),props:{decorations:t=>{let n=M(e,t);if(n.length===0||ae(t.selection))return;let r=tn(t,n);if(r)return T.create(t.doc,[Me.inline(r.from,r.to,{class:un})]);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(Me.inline(t,t+e.nodeSize,{class:un}))}),T.create(t.doc,s)}}})}function fn({marks:e}){return _(v(l({ArrowRight:an(e),ArrowLeft:on(e),"Shift-ArrowRight":sn(e,1),"Shift-ArrowLeft":sn(e,-1),Backspace:cn(e),Delete:ln(e)}),t.high),m(dn(e)))}const pn=(e,t)=>{let n={type:`highlight`,children:e.all(t)};return e.patch(t,n),n},mn=(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 hn(e){return e.tagName===`input`&&e.properties.type===`checkbox`}function gn(e){for(let t of e.children){if(t.type!==`element`)continue;if(hn(t))return t;if(t.tagName===`ul`||t.tagName===`ol`)continue;let e=gn(t);if(e)return e}}function _n(e){let t=e.properties.dataChecked,n=gn(e);if(!(t!=null||e.properties.dataType===`taskItem`||e.properties.dataTaskListItem!=null||n!==void 0))return;let r=typeof t==`string`?t!==`false`:!!n?.properties.checked,i=e.children.filter(e=>e.type!==`element`||!(hn(e)||e.tagName===`label`&&gn(e)));for(let e of[`div`,`p`]){let t=i.length===1&&i[0].type===`element`?i[0]:void 0;t?.tagName===e&&(i=t.children)}let a={type:`element`,tagName:`input`,properties:{type:`checkbox`,checked:r},children:[]};return{...e,children:[a,...i]}}const vn=(e,t)=>Pe.li(e,_n(t)??t);function yn(e){return e.filter(e=>e.character!==`[`&&e.character!==`~`?!0:e.atBreak?e.character===`~`:!(Array.isArray(e.inConstruct)?e.inConstruct:e.inConstruct?[e.inConstruct]:[]).includes(`phrasing`))}const bn=(e,t,n,r)=>Fe.text(e,t,{...n,unsafe:yn(n.unsafe)},r);function xn(){return Be().use(Ie).use(Le,{handlers:{mark:pn,li:vn}}).use(Re).use(ze,{bullet:`-`,emphasis:`*`,strong:`*`,fence:"`",fences:!0,rule:`-`,ruleRepetition:3,listItemIndent:`one`,handlers:{highlight:mn,text:bn}}).freeze()}const Sn=Ce(xn);function Cn(e){return String(Sn().processSync(e))}function wn(e){if(e==null)return;let t=Number.parseInt(e,10);return Number.isSafeInteger(t)?t:void 0}function F(e){let t=wn(e);return t!=null&&t>0?t:void 0}function Tn(e,t){return e.type.name===t}const En=new Set([`mdMark`,`mdLinkUri`,`mdLinkTitle`]),Dn=new Set([`mdWikilink`,`mdImage`,`mdFile`,`mdMath`]);function On(e){return e.find(e=>Dn.has(e.type.name))}function kn(e){return e.some(e=>En.has(e.type.name))}function An(e){let t=[];return e.forEach(e=>{if(!e.isText||!e.text)return;let n=On(e.marks),r=t.at(-1);if(n!=null&&r!=null&&r.atom===n){r.text+=e.text,r.children.push(e);return}t.push({atom:n,text:e.text,children:[e]})}),t}const jn={mdStrong:`strong`,mdEm:`em`,mdCode:`code`,mdDel:`del`,mdHighlight:`mark`,mdLinkText:`a`};function Mn(e,t,n={}){let r=document.createElement(e);r.setAttribute(`data-md`,t.textContent);for(let[e,t]of Object.entries(n))t!=null&&r.setAttribute(e,t);return Pn(t,r),r}function Nn(e,t,n){return{tag:`${e}[data-md]`,node:t,priority:100,getAttrs:n,getContent:(e,t)=>{let n=(xe(e)?e:void 0)?.getAttribute(`data-md`)??``;return n?E.from(t.text(n)):E.empty}}}function Pn(e,t){let n=[];for(let r of An(e)){if(r.atom!=null){n.length=0,t.append(Ln(r.atom,r.text));continue}for(let e of r.children)kn(e.marks)||(Fn(n,e.marks.filter(e=>jn[e.type.name]),t),In(n.at(-1)?.element??t,e.text??``))}}function Fn(e,t,n){let r=0;for(;r<e.length&&r<t.length&&t[r].eq(e[r].mark);)r++;e.length=r;for(let i=r;i<t.length;i++){let r=t[i],a=document.createElement(jn[r.type.name]??`span`);Tn(r,`mdLinkText`)&&a.setAttribute(`href`,r.attrs.href),(e.at(-1)?.element??n).append(a),e.push({mark:r,element:a})}}function In(e,t){let n=t.split(`
|
|
2
|
+
`);for(let[t,r]of n.entries())t>0&&e.append(document.createElement(`br`)),r&&e.append(document.createTextNode(r))}function Ln(e,t){switch(e.type.name){case`mdImage`:{let t=e.attrs,n=document.createElement(`img`);return n.setAttribute(`src`,t.src),t.alt&&n.setAttribute(`alt`,t.alt),t.title&&n.setAttribute(`title`,t.title),t.width!=null&&n.setAttribute(`width`,String(t.width)),t.height!=null&&n.setAttribute(`height`,String(t.height)),n}case`mdWikilink`:{let t=e.attrs;return document.createTextNode(t.display||t.target)}case`mdFile`:{let t=e.attrs,n=document.createElement(`a`);return n.setAttribute(`href`,t.href),n.append(document.createTextNode(t.name||t.href)),n}default:return document.createTextNode(t)}}function I(e,t){return e.type.name===t}function Rn(){return p({name:`heading`,whitespace:`pre`})}function zn(e){let t=e.attrs;return Mn(`h${t.level}`,e,{"data-setext-underline":t.setextUnderline==null?void 0:String(t.setextUnderline),"data-closing-hashes":t.closingHashes==null?void 0:String(t.closingHashes)})}function Bn(){return[1,2,3,4,5,6].map(e=>Nn(`h${e}`,`heading`,t=>({level:e,setextUnderline:F(t.getAttribute(`data-setext-underline`))??null,closingHashes:F(t.getAttribute(`data-closing-hashes`))??null})))}function Vn(){return f({type:`heading`,attr:`setextUnderline`,default:null,toDOM:e=>e==null?null:[`data-setext-underline`,String(e)],parseDOM:e=>F(e.getAttribute(`data-setext-underline`))??null})}function Hn(){return f({type:`heading`,attr:`closingHashes`,default:null,toDOM:e=>e==null?null:[`data-closing-hashes`,String(e)],parseDOM:e=>F(e.getAttribute(`data-closing-hashes`))??null})}function L(e){return ue(se({type:`heading`,attrs:{level:e}}))}const Un=(e,t,n)=>{let r=ie(e,n);return r!=null&&I(r.parent,`heading`)?ce()(e,t,n):!1};function Wn(){return l({"Mod-1":L(1),"Mod-2":L(2),"Mod-3":L(3),"Mod-4":L(4),"Mod-5":L(5),"Mod-6":L(6),Backspace:Un})}function Gn(){return _(Ke(),Rn(),Vn(),Hn(),Ge(),We(),Wn())}function Kn(){return p({name:`paragraph`,content:`inline*`,group:`block`,whitespace:`pre`,parseDOM:[{tag:`p`}],toDOM(){return[`p`,0]}})}function qn(e){return Mn(`p`,e)}function Jn(){return[Nn(`p`,`paragraph`)]}function Yn(){return _(v(Kn(),t.highest),qe(),Je())}function Xn(e){return{...e,paragraph:e=>({dom:qn(e)}),heading:e=>({dom:zn(e)})}}function Zn(){return o({serializeFragmentWrapper:e=>(...t)=>{let n=e(...t);for(let e of n.children)e.setAttribute(`data-meowdown`,``);return n},nodesFromSchemaWrapper:e=>(...t)=>Xn(e(...t))})}const Qn=new WeakMap;function $n(e){let t=Qn.get(e);return t??(t=new He(Xn(He.nodesFromSchema(e)),He.marksFromSchema(e)),Qn.set(e,t)),t}const er=new C(`meowdown-html-paste`);function tr(e){return e.includes(`data-meowdown`)?!0:e.includes(`data-pm-slice`)&&e.includes(`md-mark`)}const nr=new Set([`html`,`head`,`body`,`meta`,`style`,`title`,`div`,`span`,`p`,`br`,`font`,`wbr`]);function rr(e){let t=new window.DOMParser().parseFromString(e,`text/html`),n={chunks:[],hasContent:!1,trailingNewlines:0,hasStyledLine:!1};if(or(t.documentElement,n,!1)&&n.hasStyledLine)return n.chunks.join(``).replaceAll(Ne,` `)}function ir(e,t){!e.hasContent||e.trailingNewlines>=t||ar(e,`
|
|
3
|
+
`.repeat(t-e.trailingNewlines))}function ar(e,t){if(!t)return;e.chunks.push(t);let n=t.length;for(;n>0&&t.charCodeAt(n-1)===10;)n--;n===0?e.trailingNewlines+=t.length:(e.hasContent=!0,e.trailingNewlines=t.length-n)}function or(e,t,n){if(e.nodeType===Node.TEXT_NODE)return ar(t,e.nodeValue??``),!0;if(e.nodeType!==Node.ELEMENT_NODE)return!0;let r=e,i=r.tagName;if(!nr.has(i.toLowerCase()))return!1;if(n||=i===`DIV`,n&&r.getAttribute(`style`)?.trim()&&(t.hasStyledLine=!0),i===`BR`)return ar(t,`
|
|
4
|
+
`),!0;if(i===`STYLE`||i===`TITLE`)return!0;let a=i===`DIV`?1:i===`P`?2:0;a&&ir(t,a);for(let r of e.childNodes)if(!or(r,t,n))return!1;return a&&ir(t,a),!0}function sr(){return m(new S({key:er,props:{transformPastedHTML:(e,t)=>{if(tr(e))return e;let n=t.state.selection.$from.parent;if(!n.inlineContent||n.type.spec.code)return e;let r=rr(e)??Cn(e);if(!r.trim())return e;let i=X(r,{nodes:cc(t.state.schema)}),a=$n(t.state.schema),o=document.createElement(`div`);return o.append(a.serializeFragment(i.content)),o.innerHTML}}}))}function cr(e){return new Ve(e,[...Jn(),...Bn(),...Ve.fromSchema(e).rules])}const lr=new C(`meowdown-clipboard-parser`);function ur(){return m(({schema:e})=>new S({key:lr,props:{clipboardParser:cr(e)}}))}function dr(e,t){let n=t.replaceAll(/\r\n?/g,`
|
|
5
|
+
`).replace(/^\n+/,``).replace(/\n+$/,``);if(!n)return D.empty;let r=X(n,{nodes:cc(e)}),i=te(e,`paragraph`),a=+(r.childCount>0&&r.child(0).type===i),o=+(r.childCount>0&&r.child(r.childCount-1).type===i);return new D(r.content,a,o)}function fr(e,t,n){let r=n.marks(),i=He.fromSchema(e),a=document.createElement(`div`);for(let n of t.split(/(?:\r\n?|\n)+/)){let t=a.appendChild(document.createElement(`p`));n&&t.appendChild(i.serializeNode(e.text(n,r)))}return Ve.fromSchema(e).parseSlice(a,{preserveWhitespace:!0,context:n})}function pr(){let e;return m(new S({key:new C(`meowdown-plain-paste`),props:{clipboardTextParser:(t,n,r,i)=>{let{schema:a}=i.state;return r?fr(a,t,n):e=dr(a,t)},transformPasted:t=>{if(e==null)return t;let n=e;return e=void 0,n}}}))}function mr(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 hr(e,t=0){return mr(e,96,t)}function gr(e,t={}){let n=new br;return t.frontmatter&&_r(e.attrs.frontmatter,n),xr(e,n),n.finish()}function _r(e,t){e!==null&&(t.write(`---`),t.write(`
|
|
4
6
|
`),e!==``&&(t.write(e),t.write(`
|
|
5
|
-
`)),t.write(`---`),t.closeBlock())}const
|
|
6
|
-
`+i.repeat(Math.max(1,r))),t.closeBlock();return}t.write(
|
|
7
|
+
`)),t.write(`---`),t.closeBlock())}const vr=[``,`# `,`## `,`### `,`#### `,`##### `,`###### `];function yr(e,t){let n=e.attrs,r=n.setextUnderline;if(r!=null&&e.content.size>0&&n.level<=2){Tr(e,t);let i=n.level===1?`=`:`-`;t.write(`
|
|
8
|
+
`+i.repeat(Math.max(1,r))),t.closeBlock();return}t.write(vr[n.level]??`# `),Tr(e,t);let i=n.closingHashes;i!=null&&i>0&&t.write(` `+`#`.repeat(i)),t.closeBlock()}var br=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(`
|
|
7
9
|
`)){this.parts.push(e);return}let t=e.split(`
|
|
8
10
|
`);for(let e=0;e<t.length;e++)e>0&&this.parts.push(`
|
|
9
11
|
`,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(`
|
|
10
12
|
`),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+$/,``)+`
|
|
11
13
|
`}emitDeferredBlankLine(){let e=this.deferredBlankPrefix;e!==null&&(this.parts.push(e.trimEnd(),`
|
|
12
|
-
`),this.deferredBlankPrefix=null)}};function
|
|
14
|
+
`),this.deferredBlankPrefix=null)}};function xr(e,t){switch(e.type.name){case`doc`:Sr(e,t);return;case`paragraph`:if(e.childCount===0){t.closeEmptyBlock();return}Tr(e,t),t.closeBlock();return;case`heading`:yr(e,t);return;case`blockquote`:t.withPrefix(`> `,`> `,()=>Sr(e,t)),t.closeBlock();return;case`list`:Er(e,t,wr(e));return;case`codeBlock`:Dr(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`:Ar(e,t);return;case`text`:e.text&&t.write(e.text);return}}function Sr(e,t,n=!1){let r=e.childCount,i=0;for(;i<r;){let a=e.child(i);if(!I(a,`list`)){n&&i>0&&t.suppressBlank(),xr(a,t),i++;continue}let o=i+1;for(;o<r&&I(e.child(o),`list`);)o++;let s=Cr(e,i,o);for(let r=i;r<o;r++)(r===i?n&&i>0:s)&&t.suppressBlank(),Er(e.child(r),t,s);i=o}}function Cr(e,t,n){for(let r=t;r<n;r++)if(!wr(e.child(r)))return!1;return!0}function wr(e){let t=e.childCount;for(let n=0;n<t;n++){let t=e.child(n).type.name;if(t!==`list`&&!(t===`paragraph`&&n===0))return!1}return!0}function Tr(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 Er(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,()=>Sr(e,t,n)),t.closeBlock()}function Dr(e,t){let n=e.attrs,r=n.language||``,i=e.textContent;if(n.fenceStyle===`indented`&&!r){let e=Or(i);if(e!=null){t.write(e),t.closeBlock();return}}if(n.fenceStyle===`dollar`&&r===`math`&&!kr(i)){t.write(`$$`),t.write(`
|
|
13
15
|
`),i&&(t.write(i),t.write(`
|
|
14
|
-
`)),t.write(`$$`),t.closeBlock();return}let a=n.fenceStyle===`tilde`,o=
|
|
16
|
+
`)),t.write(`$$`),t.closeBlock();return}let a=n.fenceStyle===`tilde`,o=mr(i,a?126:96,2)+1,s=(a?`~`:"`").repeat(Math.max(n.fenceLength??0,o));t.write(s),r&&t.write(r),t.write(`
|
|
15
17
|
`),i&&(t.write(i),t.write(`
|
|
16
|
-
`)),t.write(s),t.closeBlock()}function
|
|
18
|
+
`)),t.write(s),t.closeBlock()}function Or(e){if(e===``)return;let t=e.split(`
|
|
17
19
|
`);if(!(t[0]===``||t[t.length-1]===``)){for(let e=0;e<t.length;e++)t[e]!==``&&(t[e]=` ${t[e]}`);return t.join(`
|
|
18
|
-
`)}}function
|
|
19
|
-
`).some(e=>e.trim()===`$$`)}function
|
|
20
|
+
`)}}function kr(e){return e.split(`
|
|
21
|
+
`).some(e=>e.trim()===`$$`)}function Ar(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);I(t,`tableHeaderCell`)&&(s=!0),o.push(Nr(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(jr(n))}let c=`| `+s.join(` | `)+` |`,l=a>=0?r[a]:Array(i).fill(``);t.write(Mr(l,i)),t.write(`
|
|
20
22
|
`),t.write(c);for(let e=0;e<n;e++)e!==a&&(t.write(`
|
|
21
|
-
`),t.write(
|
|
23
|
+
`),t.write(Mr(r[e],i)));t.closeBlock()}function jr(e){switch(e){case`left`:return`:--`;case`center`:return`:-:`;case`right`:return`--:`;default:return`---`}}function Mr(e,t){let n=`|`;for(let r=0;r<t;r++)n+=` `+(e[r]??``)+` |`;return n}function Nr(e){let t=e.textContent.trim();return!t.includes(`|`)&&!t.includes(`
|
|
22
24
|
`)?t:t.replaceAll(`|`,String.raw`\|`).replaceAll(`
|
|
23
|
-
`,` `)}function
|
|
25
|
+
`,` `)}function Pr(e){if(e.depth===0)return!0;if(e.parentOffset!==0)return!1;for(let t=1;t<e.depth;t++)if(e.index(t)!==0)return!1;return!0}function Fr(e){if(e.depth===0)return!0;if(e.parentOffset!==e.parent.content.size)return!1;for(let t=1;t<e.depth;t++)if(e.indexAfter(t)!==e.node(t).childCount)return!1;return!0}function Ir(e,t,n){let r=Lr(e,t,n),i;try{i=e.topNodeType.createAndFill(void 0,r)??void 0}catch{i=void 0}return i?gr(i).replace(/\n+$/,``):r.textBetween(0,r.size,`
|
|
24
26
|
`,`
|
|
25
|
-
`)}function Ar(){return m(new x({key:new S(`meowdown-plain-text-copy`),props:{clipboardTextSerializer:(e,t)=>{let n=A(t.state)===`hide`?jr(e):e;return kr(t.state.schema,n)}}}))}function jr(e){return new E(Mr(e.content),e.openStart,e.openEnd)}function Mr(e){let t=[];return e.forEach(e=>{t.push(e.isTextblock?Pr(e):Nr(e))}),T.from(t)}function Nr(e){return e.childCount>0?e.copy(Mr(e.content)):e}function Pr(e){let t=e.type.schema,n=[];for(let r of An(e)){let e=r.atom;if(e!=null){if(Tn(e,`mdWikilink`)){let r=e.attrs,i=r.display||r.target;i&&n.push(t.text(i))}else n.push(...r.children);continue}for(let e of r.children)kn(e.marks)||n.push(e)}return e.copy(T.from(n))}function Fr(){return _(Zn(),Ar(),ar(),nr(),cr())}const L=new Map,Ir=new Map,Lr={math:`latex`};async function Rr(e){let t=L.get(e);if(t!==void 0)return t;let n=Ye.matchLanguageName(Xe,Lr[e]??e,!0);if(!n)return L.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),L.set(e,null),null}return L.set(e,r),r}function zr(e,t){let n=Ir.get(e);if(n)return n;let r=$e({parse:e=>t.language.parser.parse(e.content),highlighter:Ze});return Ir.set(e,r),r}const Br=e=>{let t=e.language?.trim();if(!t)return[];let n=L.get(t);return n===null?[]:n?zr(t,n)(e):Rr(t).then(()=>void 0)};function Vr(){return fe({parser:Br,nodeTypes:[`codeBlock`]})}function Hr(e,t){let n=t.language.parser.parse(e),r=[];return Qe(n,Ze,(e,t,n)=>{r.push([e,t,n])}),r}function Ur(e,t){let n=t.trim();if(!n)return[];let r=L.get(n);return r===null?[]:r?Hr(e,r):Rr(n).then(t=>t?Hr(e,t):[])}function Wr(){return f({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 Gr(){return f({type:`codeBlock`,attr:`fenceLength`,default:null,toDOM:e=>e==null?null:[`data-fence-length`,String(e)],parseDOM:e=>{let t=wn(e.getAttribute(`data-fence-length`));return t!=null&&t>3?t:null}})}function Kr(e){return{language:e[1]||``,fenceStyle:`tilde`}}function qr(){return rt({regex:/^~~~(\S*)\s$/,type:`codeBlock`,attrs:Kr})}function Jr(){return tt({regex:/^~~~(\S*)$/,type:`codeBlock`,attrs:Kr})}function Yr(){return tt({regex:/^\$\$$/,type:`codeBlock`,attrs:()=>({language:`math`,fenceStyle:`dollar`})})}function Xr(){return _(de(),Wr(),Gr(),qr(),Jr(),Yr())}function Zr(e,t){return(n,r)=>{if(r){let i=C.create(n.doc,e,t);r(n.tr.setSelection(i))}return!0}}function Qr(e,t,n){return(r,i)=>{if(i){let a=C.between(e,t,n);i(r.tr.setSelection(a))}return!0}}function $r(e){return(t,n)=>{if(!e.trim())return!1;let r=Y(e,{nodes:Zs(t.schema)}).content;if(r.childCount===0)return!1;let i=r.childCount===1&&F(r.child(0),`paragraph`)?new E(r,1,1):new E(r,0,E.maxOpen(r).openEnd);if(n){let e=t.tr,r=e.selection;(!g(r)||!r.empty)&&e.setSelection(C.near(r.$from)),n(e.replaceSelection(i).scrollIntoView())}return!0}}function ei(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);it(s),n(s.scrollIntoView())}return!0}}function ti(){return ft(oe({type:`paragraph`}),dt(),pt)}function ni(){return(e,t)=>(t&&t(e.tr.scrollIntoView()),!0)}function ri(){return s({insertMarkdown:$r,insertTrigger:ei,scrollIntoView:ni,selectText:Zr,selectTextBetween:Qr,turnIntoText:ti})}const ii=(e,t,n)=>{let{selection:r}=e;return r.empty||n?.composing?!1:(t?.(e.tr.setSelection(C.near(r.$head))),!0)};function ai(){return v(l({Escape:ii}),t.low)}function oi(){return f({type:`doc`,attr:`frontmatter`,default:null})}function si(e,t){return t(e.state,e.dispatch,e)}function ci(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 R(e,t){let n=ci(e,t);return n!=null&&n.some(e=>En.has(e.type.name))}function li(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 z(e,t){if(!li(e,t))return;let n=e.doc.resolve(t).start(),r=t;for(;r>n&&R(e,r-1);)r--;return r<t?{from:r,to:t}:void 0}function B(e,t){if(!li(e,t))return;let n=e.doc.resolve(t).end(),r=t;for(;r<n&&R(e,r);)r++;return r>t?{from:t,to:r}:void 0}function ui(e,t){return R(e,t-1)&&R(e,t)}function di(e,t){if(!ui(e,t))return;let n=z(e,t);if(!n)return;let r=B(e,t);if(r)return{from:n.from,to:r.to}}function fi(e,t,n){let r=ci(e,t);return r!=null&&n.isInSet(r)}function pi(e,t){let n=ci(e,t);if(n==null)return;let r=ee(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&&fi(e,r-1,n);)r--;let i=t+1;for(;i<s&&fi(e,i,n);)i++;(c==null||i-r<c.to-c.from)&&(c={from:r,to:i})}return c}function mi(e,t,n){let r=pi(e,n===`from`?t.from:t.to-1);return r==null?!1:n===`from`?r.from===t.from:r.to===t.to}function hi(e,t,n){let r=mi(e,t,`from`),i=mi(e,t,`to`);return r&&!i?t.from:i&&!r?t.to:n-t.from<=t.to-n?t.from:t.to}function gi(e,t,n,r){if(!li(e,n))return n;let i=di(e,n);if(i!=null)return r?hi(e,i,n):n>=t?i.to:i.from;if(!r)return n;let a=z(e,n);if(a!=null&&mi(e,a,`from`))return a.from;let o=B(e,n);return o!=null&&mi(e,o,`to`)?o.to:n}function _i(e,t){if(!li(e,t))return;let n=R(e,t-1),r=R(e,t);if(n!==r)return r?`left`:`right`}function vi(e,t){let n=pi(e,t);if(n==null)return[];let r=B(e,n.from),i=z(e,n.to),a=[];return i!=null&&a.push(i),r!=null&&(i==null||r.from!==i.from)&&a.push(r),a}const yi=new S(`meowdown-hidden-run-snap`),bi=new S(`meowdown-hidden-run-beforeinput`);function xi(){let e=!1;return new x({key:yi,props:{handleDOMEvents:{compositionstart:()=>(e=!0,!1),compositionend:()=>(e=!1,!1)}},appendTransaction:(t,n,r)=>{if(e||A(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=gi(r,n.selection.head,i.head,a);return e===i.head?null:r.tr.setSelection(C.create(r.doc,e))}let o=di(r,i.from)?.from??i.from,s=di(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(C.create(r.doc,c,l))}})}const Si=(e,t)=>{if(A(e)!==`hide`)return!1;let n=e.selection;if(!g(n)||!n.empty)return!1;let r=gi(e,n.head,n.head,!0);return r===n.head||t?.(e.tr.setSelection(C.create(e.doc,r))),!1};function Ci(e){return(t,n)=>{if(A(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?z(t,r.head):B(t,r.head);if(a==null)return!1;let o=vi(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 wi=Ci(-1),Ti=Ci(1);function Ei(){return new x({key:bi,props:{handleDOMEvents:{beforeinput:(e,t)=>{if(e.composing)return!1;let n=t.inputType===`deleteContentBackward`?wi:t.inputType===`deleteContentForward`?Ti:void 0;return n==null||!si(e,n)?!1:(t.preventDefault(),!0)}}}})}function Di(){return _(m(xi()),m(Ei()),v(l({Enter:Si,Backspace:wi,Delete:Ti}),t.highest))}function Oi(){return f({type:`horizontalRule`,attr:`marker`,default:null,toDOM:e=>e?[`data-hr-marker`,e]:null,parseDOM:e=>e.getAttribute(`data-hr-marker`)})}function ki(){return _(mt(),Oi())}function Ai(){return p({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 ji(e){let[t,n,r]=e;return[t,n,r.map(e=>e.toJSON())]}function Mi(e,t){let[n,r,i]=t;return[n,r,i.map(t=>Ue.fromJSON(e,t))]}function Ni(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 Pi=class e extends bt{constructor(e){super(),this.chunks=e}apply(e){if(this.chunks.length===0)return xt.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=Ue.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(Ni(l,c))return!1;n??=new St(e);for(let e of l)n.removeMark(i,a,e);for(let e of c)n.addMark(i,a,e);return!1})}return xt.ok(n?n.doc:e)}invert(e){if(this.chunks.length===0)return Fi;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 yt(i,a,e.slice(i,a),!1)}map(e){return null}toJSON(){return{stepType:`batchSetMark`,chunks:this.chunks.map(ji)}}static fromJSON(t,n){let r=n.chunks;return new e(r.map(e=>Mi(t,e)))}};bt.jsonID(`batchSetMark`,Pi);const Fi=new Pi([]),Ii=/^<!--\s*(\{[^}]*\})\s*-->$/,Li=/<!--\s*\{[^}]*\}\s*-->$/;function Ri(e){let t=Ii.exec(e.trim());if(!t)return;let n;try{n=JSON.parse(t[1])}catch{return}if(!Ce(n))return;let r=zi(n);return Object.keys(r).length>0?r:void 0}function zi(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 Bi(e){return`<!-- ${JSON.stringify(e)} -->`}function Vi(e){return e.replace(Li,``)}const Hi=/^(\d+)(?:x(\d+))?$/i;function Ui(e){if(!e)return null;let t=Number.parseInt(e,10);return Number.isSafeInteger(t)&&t>0?t:null}function Wi(e){let t=e.replace(/^!\[\[/,``).replace(/\]\]$/,``),n=t.lastIndexOf(`|`);if(n<0)return{target:t.trim(),display:``,width:null,height:null};let r=t.slice(0,n).trim(),i=t.slice(n+1).trim(),a=Hi.exec(i);if(!a)return{target:r,display:i,width:null,height:null};let o=Ui(a[1]),s=Ui(a[2]);return o==null||a[2]&&s==null?{target:r,display:i,width:null,height:null}:{target:r,display:``,width:o,height:s}}function Gi(e,t,n){return`![[${e}|${Math.round(t)}x${Math.round(n)}]]`}function Ki(e){let t=e.split(/[?#]/,1)[0],n=t.split(/[/\\]/).findLast(Boolean)??t;try{return decodeURIComponent(n)}catch{return n}}function qi(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 Ji(){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 Yi(){return d({name:`mdWikilink`,constructor:Ji()})}const Xi=new Map([[y.Emphasis,`mdEm`],[y.StrongEmphasis,`mdStrong`],[y.InlineCode,`mdCode`],[y.Strikethrough,`mdDel`],[y.Highlight,`mdHighlight`],[y.EmphasisMark,`mdMark`],[y.CodeMark,`mdMark`],[y.LinkMark,`mdMark`],[y.StrikethroughMark,`mdMark`],[y.HighlightMark,`mdMark`],[y.URL,`mdLinkUri`],[y.LinkTitle,`mdLinkTitle`],[y.Hashtag,`mdTag`],[y.WikilinkMark,`mdMark`]]);function Zi(e,t,n){let r=be(t),i=[];return $i(r,[],0,t.length,t,e,i,n),i}function Qi(e){return e.slice(1,-1).replaceAll(/\\(.)/g,`$1`)}function $i(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&&V(o,c,r.from,t);let l=r.type;if(l===y.Link)if(!ea(r))$i(r.children.filter(e=>e.type!==y.LinkMark&&e.type!==y.LinkLabel),t,r.from,r.to,i,a,o,s);else{let e=ra(r,t,i,a,s);e?V(o,r.from,r.to,e):ia(r,t,i,a,o,s)}else if(l===y.Image){let s=aa(r,e[n+1],i);oa(r,t,i,a,o,s),s&&n++,c=s?s.to:r.to;continue}else if(l===y.Wikilink)ca(r,t,i,a,o);else if(l===y.WikiEmbed)la(r,t,i,a,o,s);else if(l===y.InlineMath)sa(r,t,i,a,o);else if(l===y.URL){let e=ve(i.slice(r.from,r.to)),n=e?a.mdLinkText.create({href:e}):a.mdLinkUri.create();V(o,r.from,r.to,[...t,n])}else{let e;l===y.Emphasis?e=`italic`:l===y.StrongEmphasis?e=`bold`:l===y.InlineCode?e=`code`:l===y.Strikethrough?e=`strike`:l===y.Highlight?e=`highlight`:l===y.Autolink&&(e=`autolink`);let n=e?[...t,a.mdPack.create({key:e})]:t,c=Xi.get(l),u=c?[...n,a[c].create()]:n;r.children.length===0?V(o,r.from,r.to,u):$i(r.children,u,r.from,r.to,i,a,o,s)}c=r.to}c<r&&V(o,c,r,t)}function ea(e){let t=0;for(let n of e.children)n.type===y.LinkMark&&t++;return t>=3}function ta(e){let t=-1,n=-1,r=null,i=null,a=0;for(let o of e.children){let e=o.type;e===y.LinkMark?(a++,a===1&&(t=o.to),a===2&&(n=o.from)):r==null&&e===y.URL?r=o:i==null&&e===y.LinkTitle&&(i=o)}return{labelFrom:t,labelTo:n,urlNode:r,titleNode:i}}function na(e){let t=e.split(/[?#]/,1)[0],n=t.split(/[/\\]/).findLast(Boolean)??t;try{return decodeURIComponent(n)}catch{return n}}function ra(e,t,n,r,i){let a=i?.resolveFileLink;if(!a)return;let{labelFrom:o,labelTo:s,urlNode:c,titleNode:l}=ta(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?Qi(n.slice(l.from,l.to)):``;if(!a({href:u,label:d,title:f}))return;let p=d||na(u);return[...t,r.mdFile.create({href:u,name:p,title:f})]}function ia(e,t,n,r,i,a){let{labelTo:o,urlNode:s,titleNode:c}=ta(e),l=s?n.slice(s.from,s.to):``,u=c?Qi(n.slice(c.from,c.to)):``,d=l?r.mdLinkText.create({href:l}):null,f=e=>o>=0&&e<o&&d!==null,p=r.mdPack.create({key:`link`,data:{href:l,title:u}}),m=[...t,p],h=e.from;for(let t of e.children){if(t.from>h){let e=f(h)?[...m,d]:m;V(i,h,t.from,e)}let e=f(t.from)?[...m,d]:m;if(t.type===y.Wikilink){ca(t,e,n,r,i),h=t.to;continue}if(t.type===y.WikiEmbed){la(t,e,n,r,i,a),h=t.to;continue}let o=Xi.get(t.type),s=o?[...e,r[o].create()]:e;t.children.length===0?V(i,t.from,t.to,s):$i(t.children,s,t.from,t.to,n,r,i,a),h=t.to}h<e.to&&V(i,h,e.to,m)}function aa(e,t,n){if(!t||t.type!==y.Comment||t.from!==e.to)return;let r=Ri(n.slice(t.from,t.to));if(r)return{magic:r,to:t.to}}function oa(e,t,n,r,i,a){let o=e.children.find(e=>e.type===y.URL);if(!o){ia(e,t,n,r,i,void 0);return}let s=e.children.filter(e=>e.type===y.LinkMark),c=e.children.find(e=>e.type===y.LinkTitle),l=n.slice(o.from,o.to),u=s.length>=2?n.slice(s[0].to,s[1].from):``,d=c?Qi(n.slice(c.from,c.to)):``,f=a?.magic.width??null,p=a?.magic.height??null,m=a?.to??e.to;V(i,e.from,m,[...t,r.mdImage.create({src:l,alt:u,title:d,width:f,height:p,syntax:null,wikiTarget:null})])}function sa(e,t,n,r,i){let a=e.children.filter(e=>e.type===y.InlineMathMark);if(a.length<2){V(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})];V(i,e.from,a[0].to,[...s,r.mdMark.create()]),V(i,a[0].to,a[1].from,s),V(i,a[1].from,e.to,[...s,r.mdMark.create()])}function ca(e,t,n,r,i){let{target:a,display:o}=qi(n.slice(e.from,e.to));V(i,e.from,e.to,[...t,r.mdWikilink.create({target:a,display:o})])}function la(e,t,n,r,i,a){let o=Wi(n.slice(e.from,e.to)),s=a?.resolveWikiEmbed?.(o);if(!s){V(i,e.from,e.to,t);return}if(s.kind===`image`){let n=s.src??o.target,a=(s.alt??o.display)||Ki(o.target);V(i,e.from,e.to,[...t,r.mdImage.create({src:n,alt:a,title:``,width:o.width,height:o.height,syntax:`wikiEmbed`,wikiTarget:o.target})]);return}if(s.kind===`file`){let n=s.href??o.target,a=(s.name??o.display)||Ki(o.target);V(i,e.from,e.to,[...t,r.mdFile.create({href:n,name:a,title:s.title??``})]);return}let c=s.target??o.target,l=s.display??o.display;V(i,e.from,e.to,[...t,r.mdWikilink.create({target:c,display:l})])}function V(e,t,n,r){if(t>=n)return;let i=e.at(-1);if(i&&i[1]===t&&Ni(i[2],r)){e[e.length-1]=[i[0],n,i[2]];return}e.push([t,n,r])}const ua=`inline-marks-applied`;let da=0,fa=0;function pa(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 ma(e){let t=new WeakMap;function n(n,r,i){let a=t.get(n);if(a?fa++:(da++,a=Zi(Ys(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 x({key:new S(`inline-mark`),appendTransaction(e,t,n){for(let t of e)if(t.getMeta(ua))return null;let i=r(n,pa(e,n));if(i.length===0)return null;let a=n.tr.step(new Pi(i));return a.setMeta(ua,!0),a.setMeta(`addToHistory`,!1),a},view(e){return e.dispatch(ha(e.state)),{}}})}function ha(e){return e.tr.setMeta(`inline-marks-trigger`,!0)}function ga(e){return m(ma(e))}function _a(){return u({name:`mdImage`,inclusive:!1,attrs:{src:{default:``},alt:{default:``},title:{default:``},width:{default:null},height:{default:null},syntax:{default:null},wikiTarget:{default:null}},toDOM:()=>[`span`,{class:`md-image`},0],parseDOM:[{tag:`span.md-image`}]})}function va(){return u({name:`mdMark`,inclusive:!1,toDOM:()=>[`span`,{class:`md-mark`},0],parseDOM:[{tag:`span.md-mark`}]})}function ya(){return u({name:`mdEm`,toDOM:()=>[`em`,0],parseDOM:[{tag:`em`}]})}function ba(){return u({name:`mdStrong`,toDOM:()=>[`strong`,0],parseDOM:[{tag:`strong`}]})}function xa(){return u({name:`mdCode`,toDOM:()=>[`code`,0],parseDOM:[{tag:`code`}]})}function Sa(){return u({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 Ca(){return u({name:`mdLinkUri`,inclusive:!1,toDOM:()=>[`span`,{class:`md-link-uri`},0],parseDOM:[{tag:`span.md-link-uri`}]})}function wa(){return u({name:`mdLinkTitle`,inclusive:!1,toDOM:()=>[`span`,{class:`md-link-title`},0],parseDOM:[{tag:`span.md-link-title`}]})}function Ta(){return u({name:`mdDel`,toDOM:()=>[`del`,0],parseDOM:[{tag:`del`}]})}function Ea(){return u({name:`mdHighlight`,toDOM:()=>[`mark`,0],parseDOM:[{tag:`mark`}]})}function Da(){return u({name:`mdTag`,toDOM:()=>[`span`,{class:`md-tag`},0],parseDOM:[{tag:`span.md-tag`}]})}function Oa(){return u({name:`mdWikilink`,inclusive:!1,attrs:{target:{default:``},display:{default:``}},toDOM:()=>[`span`,{class:`md-wikilink`},0],parseDOM:[{tag:`span.md-wikilink`}]})}function ka(){return u({name:`mdFile`,inclusive:!1,attrs:{href:{default:``},name:{default:``},title:{default:``}},toDOM:()=>[`span`,{class:`md-file`},0],parseDOM:[{tag:`span.md-file`}]})}function Aa(){return u({name:`mdMath`,inclusive:!1,attrs:{formula:{default:``}},toDOM:()=>[`span`,{class:`md-math`},0],parseDOM:[{tag:`span.md-math`}]})}function ja(){return u({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 Ma(){return _(va(),ya(),ba(),xa(),Sa(),Ca(),wa(),Ta(),Ea(),Da(),Oa(),_a(),ka(),Aa(),ja())}const H={em:{node:y.Emphasis,delim:`*`},strong:{node:y.StrongEmphasis,delim:`**`},code:{node:y.InlineCode,delim:"`"},del:{node:y.Strikethrough,delim:`~~`},highlight:{node:y.Highlight,delim:`==`}},Na=new Set([y.EmphasisMark,y.CodeMark,y.LinkMark,y.StrikethroughMark,y.HighlightMark]);function Pa(e){return[e.children[0],e.children.at(-1)]}function Fa(e){let{type:t,children:n}=e;if(t===y.Emphasis||t===y.StrongEmphasis||t===y.Strikethrough||t===y.Highlight)return[n[0].to,n.at(-1).from];if(t===y.Link||t===y.Image){let e=n.find((e,t)=>t>0&&e.type===y.LinkMark);return e?[n[0].to,e.from]:null}return null}function Ia(e,t,n){for(let r of e){if(r.to<=t||r.from>=n||t<=r.from&&r.to<=n)continue;let i=Fa(r);return i&&i[0]<=t&&n<=i[1]?Ia(r.children,t,n):Ia(e,Math.min(t,r.from),Math.max(n,r.to))}return[t,n]}function La(e,t,n){for(let r of e)if(!(r.to<=t||r.from>=n)&&(t>r.from||r.to>n))return La(e,Math.min(t,r.from),Math.max(n,r.to));return[t,n]}function Ra(e,t,n){for(;t<n&&b(e.charCodeAt(t));)t++;for(;n>t&&b(e.charCodeAt(n-1));)n--;return[t,n]}function za(e,t,n,r){let i=_e(be(e),e=>e.type===r.node||Na.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 Ba(e,t,n,r,i){let a=be(e),o=_e(a,e=>e.type===r.node);return i?Ua(e,o,t,n):Va(e,a,o,t,n,r)}function Va(e,t,n,r,i,a){for(let e=0;e!==i-r;){e=i-r,[r,i]=Ia(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]=Pa(e);o.push({from:t.from,to:t.to,insert:``}),o.push({from:n.from,to:n.to,insert:``})}let[s,c]=Ha(e,r,i,o,a);return o.push({from:r,to:r,insert:s},{from:i,to:i,insert:c}),o}function Ha(e,t,n,r,i){if(i.node!==y.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(ur(a)+1),s=a.startsWith("`")||a.endsWith("`")?` `:``;return[o+s,s+o]}function Ua(e,t,n,r){let i=[];for(let a of t){if(a.to<=n||a.from>=r)continue;let[t,o]=Pa(a),s=Math.max(n,t.to),c=Math.min(r,o.from);for(s>=c&&([s,c]=[t.to,o.from]),[s,c]=La(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 Wa(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=be(e),o=_e(a,e=>e.type===n.node).findLast(e=>e.from<=t&&t<=e.to);if(o){let[e,n]=Pa(o);return{kind:`move`,pos:t===o.from?e.to:t===o.to?n.from:o.to}}return Ga(a,t)||e[t-1]===r[0]||e[t]===r[0]?null:{kind:`insert`,pos:t}}function Ga(e,t){for(let n of e)if(n.from<t&&t<n.to){let e=Fa(n);return!e||t<e[0]||t>e[1]||Ga(n.children,t)}return!1}function U(e){return(t,n)=>{if(t.selection.empty)return Ka(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]=Ra(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:za(a,c,l,e)}),!1});let c=s.length>0&&s.every(e=>e.active),l=s.filter(e=>c||!e.active).flatMap(t=>Ba(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(C.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 Ka(e,t,n){let{$from:r}=t.selection,i=r.parent;if(!i.isTextblock||i.type.spec.code)return!1;let a=Wa(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(C.create(o.doc,i+a.pos)),a.kind===`insert`&&(o.insertText(e.delim+e.delim,i+a.pos),o.setSelection(C.create(o.doc,i+a.pos+e.delim.length))),n(o.scrollIntoView())}return!0}function qa(){return s({toggleEm:()=>U(H.em),toggleStrong:()=>U(H.strong),toggleCode:()=>U(H.code),toggleDel:()=>U(H.del),toggleHighlight:()=>U(H.highlight)})}function Ja(){return l({"Mod-b":U(H.strong),"Mod-i":U(H.em),"Mod-e":U(H.code),"Mod-Shift-x":U(H.del),"Mod-Shift-h":U(H.highlight)})}function Ya(){return _(qa(),Ja())}function Xa(e,t,n){let r;return e.doc.nodesBetween(t.from,t.to,(e,i)=>(e.isText&&e.marks.some(e=>Tn(e,n))&&(r={from:Math.max(i,t.from),to:Math.min(i+e.nodeSize,t.to)}),!0)),r}function W(e,t){let n=O(e,t,`mdLinkText`),r=O(e,t,`mdPack`,{key:`link`})??O(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`?Xa(e,t,`mdLinkText`)??{from:i.from+1,to:i.to-1}:t,href:o,title:``}}let s=Xa(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 Za(e){let t=e.trim();return t?ve(t)??t:``}function Qa(e,t){return e+(t?` "${t.replaceAll(/(["\\])/g,String.raw`\$1`)}"`:``)}function $a(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]=Ra(a.textContent,n.parentOffset,r.parentOffset);if(!(s>=c))return{from:o+s,to:o+c}}function eo({href:e,title:t,wrapText:n=!0}={}){return(r,i)=>{let a=$a(r);if(!a)return!1;if(i){let{from:o,to:s}=a,c=r.tr,l=`](${Qa(Za(e??``),t??``)})`;c.insertText(l,s).insertText(`[`,o);let u=s+1+l.length;c.setSelection(n?C.create(c.doc,o,u):C.create(c.doc,u)),c.scrollIntoView(),i(c)}return!0}}function to(e){return(t,n)=>{let r=W(t,t.selection.from);if(!r?.dest)return!1;let i=Qa(Za(e.href??r.href),e.title??r.title);return n&&n(t.tr.insertText(i,r.dest.from,r.dest.to).scrollIntoView()),!0}}function no(){return(e,t)=>{let n=W(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 ro(){return s({insertLink:eo,updateLink:to,removeLink:no})}function io(e){return(t,n,r)=>{let i=W(t,t.selection.from);if(i){if(n&&r){let{unit:{from:a,to:o}}=i;n(t.tr.setSelection(C.create(t.doc,a,o)).scrollIntoView()),r.focus(),e({from:a,to:o,link:i})}return!0}let a=$a(t);if(a){if(n&&r){let{from:i,to:o}=a;n(t.tr.setSelection(C.create(t.doc,i,o)).scrollIntoView()),r.focus(),e({from:i,to:o,link:void 0})}return!0}return!1}}function ao(e){return l({"Mod-k":io(e)})}function oo(e){return e===`)`||e===`*`||e===`+`?e:void 0}function so(e){return e===`X`?e:void 0}function co(e){return fo(e)?String(e):void 0}function lo(){return f({type:`list`,attr:`marker`,default:null,splittable:!0,toDOM:e=>{let t=oo(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 uo(){return f({type:`list`,attr:`taskMarker`,default:null,splittable:!0,toDOM:e=>{let t=so(e);return t==null?null:[`data-list-task-marker`,t]},parseDOM:e=>e.getAttribute(`data-list-task-marker`)===`X`?`X`:null})}function fo(e){return e===2||e===3||e===4}function po(){return f({type:`list`,attr:`markerGap`,default:1,splittable:!0,toDOM:e=>{let t=co(e);return t==null?null:[`data-list-marker-gap`,t]},parseDOM:e=>{let t=Number.parseInt(e.getAttribute(`data-list-marker-gap`)??``,10);return fo(t)?t:1}})}function mo(e){let t=e.attrs;return{...Et(e),"data-list-marker":oo(t.marker),"data-list-task-marker":so(t.taskMarker),"data-list-marker-gap":co(t.markerGap)}}function ho(){return o({serializeFragmentWrapper:e=>(...t)=>go(kt(e(...t))),serializeNodeWrapper:e=>(...t)=>{let n=e(...t);return xe(n)?go(kt(n)):n},nodesFromSchemaWrapper:e=>(...t)=>({...e(...t),list:e=>At({node:e,nativeList:!0,getAttributes:mo})})})}function go(e){xe(e)&&_o(e);for(let t of e.children)go(t);return e}function _o(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=Dt(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 vo=[Mt(/^\s?([*-])\s$/,{kind:`bullet`,collapsed:!1}),Mt(/^\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}}),Mt(/^\s?\[([\sX]?)\]\s$/i,({match:e})=>({kind:`task`,checked:[`x`,`X`].includes(e[1]),collapsed:!1})),Mt(/^\s?\+\s$/,{kind:`task`,marker:`+`,checked:!1,collapsed:!1})];function yo(){return _(vo.map(nt))}function bo(){return D({kind:`task`,marker:`+`})}function xo(){return D({kind:`task`,marker:null})}function So(e){let{$from:t}=e.selection;for(let e=t.depth;e>0;e--){let n=t.node(e);if(F(n,`list`))return n.attrs}return null}function Co(){return(e,t,n)=>{let r=So(e);return(r?.kind===`task`?r.marker===`+`?xo():bo():D({kind:`task`,marker:null,checked:!1}))(e,t,n)}}function wo(){return s({cycleCheckableList:Co,wrapInCircleTask:bo,wrapInSquareTask:xo})}function To(){return(e,t,n)=>{let r=So(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},D(a)(e,t,n)}}function Eo(){return(e,t,n)=>{let r=So(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},D(a)(e,t,n)}}function Do(e){return F(e,`list`)&&e.attrs.kind===`bullet`&&e.childCount>=2&&e.firstChild?.type!==e.type}const Oo=e=>{let t=e.attrs;return t.kind===`task`?{...t,checked:!t.checked}:Do(e)?{...t,collapsed:!t.collapsed}:t};function ko(){return m(()=>[new x({props:{handleDOMEvents:{mousedown:(e,t)=>Ot({view:e,event:t,onListClick:Oo})}}}),Ct(),new x({props:{transformCopied:jt}}),wt()])}function Ao(){return s({toggleListCollapsed:()=>Tt({isToggleable:Do})})}function jo(){return l({"Mod-Enter":To(),"Mod-Shift-Enter":Eo(),"Mod-.":Tt({isToggleable:Do}),"Mod-Shift-7":ut({kind:`ordered`,collapsed:!1}),"Mod-Shift-8":ut({kind:`bullet`,collapsed:!1}),"Mod-Shift-9":ut({kind:`task`,checked:!1,collapsed:!1})})}function Mo(){return _(ct(),ko(),st(),at(),ho(),ot(),yo(),jo(),lo(),uo(),po(),wo(),Ao())}let No;function Po(){return No??=import(`./katex-chunk-Ch7kgbXr.js`).then(e=>e.render),No}function Fo(e,t,n,r){try{e(n,t,{displayMode:r,throwOnError:!1,output:`mathml`})}catch(e){t.textContent=String(e)}}var Io=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=C.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;Po().then(t=>{e===this.#r&&Fo(t,this.#n,e,!1)})}};function Lo(){return d({name:`mdMath`,constructor:(e,t)=>new Io(e,t)})}function Ro(e){return e===`left`||e===`center`||e===`right`?e:null}function zo(){return f({type:`tableCell`,attr:`align`,default:null,toDOM:e=>e?[`data-align`,e]:null,parseDOM:e=>Ro(e.getAttribute(`data-align`))})}function Bo(){return f({type:`tableHeaderCell`,attr:`align`,default:null,toDOM:e=>e?[`data-align`,e]:null,parseDOM:e=>Ro(e.getAttribute(`data-align`))})}function Vo(e){for(let t=0;t<e.childCount;t++){let n=e.child(t);for(let e=0;e<n.childCount;e++)if(F(n.child(e),`tableHeaderCell`))return t}return 0}function Ho(e){return e.child(Vo(e))}function Uo(e,t){return t>=e.childCount?null:e.child(t).attrs.align??null}function Wo(e,t,n){if(e.childCount===0)return;let r=Ho(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=Uo(r,e);(t.attrs.align??null)!==i&&n.setNodeMarkup(o,void 0,{...t.attrs,align:i}),o+=t.nodeSize}i+=a.nodeSize}}function Go(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 Ko(){return new x({key:new S(`table-align-sync`),appendTransaction(e,t,n){if(!e.some(e=>e.docChanged))return;let r=Go(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)=>F(e,`table`)?(s??=n.tr,Wo(e,t,s),!1):!0),s?.docChanged?s:void 0}})}function qo(){return m(Ko())}function Jo(e){let{selection:t}=e;if(Vt(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 Yo(e){return(t,n)=>{let r=Jo(t);if(!r||r.table.childCount===0)return!1;if(n){let{table:i,tablePos:a,firstColumn:o,lastColumn:s}=r,c=Vo(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 Xo(e){let t=Jo(e);if(!(!t||t.table.childCount===0))return Uo(Ho(t.table),t.lastColumn)??void 0}function Zo(){return s({setTableColumnAlign:Yo})}function Qo(){return _(zo(),Bo(),qo(),Zo())}function $o(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 es=`paragraph`;function ts(){return _(p({name:`tableCell`,content:es}),p({name:`tableHeaderCell`,content:es}))}const ns=(e,t)=>{let{selection:n}=e;return!Vt(n)||!n.isColSelection()||!n.isRowSelection()?!1:Bt(e,t)};function rs(){return v(l({Backspace:ns,Delete:ns}),t.high)}function is(){return _(zt(),Rt(),Nt(),Lt(),ts(),Qo(),It({allowTableNodeSelection:!0}),Pt(),Ft(),rs())}function as(e){let{selection:t}=e,{$from:n,$to:r}=t;if(ae(t)&&n.depth===0||n.depth>0&&r.depth>0&&n.index(0)===r.index(0))return n.index(0)}function os(e){return(t,n)=>{if($o(t))return!1;let r=as(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=ae(a)?je.create(u.doc,a.from+d):C.create(u.doc,a.anchor+d,a.head+d);u.setSelection(f),n(u.scrollIntoView())}return!0}}function ss(e){return(t,n,r)=>lt(e)(t,n,r)||os(e===`up`?-1:1)(t,n,r)}function cs(){return l({"Alt-ArrowUp":ss(`up`),"Alt-ArrowDown":ss(`down`)})}const G=new S(`meowdownPendingReplacement`);function K(e){return G.getState(e)?.pending??null}function ls(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 us=new x({key:G,state:{init:()=>({pending:null}),apply:(e,t)=>{let n=e.getMeta(G);if(n)return ls(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=K(e);return!t||t.from>=t.to?null:w.create(e.doc,[Ne.inline(t.from,t.to,{class:`md-pending-replacement`})])}}});function ds(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(G,{type:`start`,from:r,to:i,mode:a})),!0)}}function fs(e){return(t,n)=>K(t)?(n?.(t.tr.setMeta(G,{type:`append`,text:e})),!0):!1}function ps(){return(e,t)=>K(e)?(t?.(e.tr.setMeta(G,{type:`discard`})),!0):!1}function ms(e={}){return(t,n)=>{let r=K(t);if(!r||!r.text.trim())return!1;if(n){let i=e.mode??r.mode,a=Zs(t.schema),o=Y(r.text,{nodes:a}),s=t.tr;if(s.setMeta(G,{type:`accept`}),i===`append`){let e=t.doc.resolve(r.to).after(1);s.insert(e,o.content),s.setSelection(C.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!=null&&F(i,`paragraph`)&&e.sameParent(n)&&e.parent.isTextblock?(s.replaceWith(r.from,r.to,i.content),s.setSelection(C.near(s.doc.resolve(r.from+i.content.size),-1))):(s.replaceRange(r.from,r.to,new E(o.content,0,0)),s.setSelection(C.near(s.doc.resolve(s.mapping.map(r.to)),-1)))}n(s.scrollIntoView())}return!0}}function hs(){return s({startPendingReplacement:ds,appendPendingReplacementText:fs,acceptPendingReplacement:ms,discardPendingReplacement:ps})}function gs(){return l({"Mod-Enter":ms(),Escape:ps()})}function _s(){return _(m(us),hs(),gs())}function vs(e){return m(new x({view:()=>({update:(t,n)=>{let r=G.getState(n),i=G.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 ys(e){return e.left===e.right&&e.top===e.bottom}function q(e,t,n){if(t<0||t>e.state.doc.content.size)return;let r;try{r=e.coordsAtPos(t,n)}catch{return}return ys(r)?void 0:r}function bs(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 xs(e){let t=e.state,n=t.selection.head,r=z(t,n),i=B(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=q(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 Ss(e){let t=e.state,n=t.selection.head;for(let r of $t){let i=O(t,n,r);if(i==null||i.from!==n&&i.to!==n)continue;let a=ws(e,i.from+1);if(a==null)continue;let o=Array.from(a.getClientRects()).filter(e=>e.height>0);if(o.length===0)continue;let s=i.to===n,c=s?o[o.length-1]:o[0];return{left:s?c.right:c.left,top:c.top,height:c.height}}}function Cs(e,t,n){let r=e.state;for(let i of $t){let a=O(r,t,i);if(a==null)continue;let o=ws(e,a.from+1);if(o==null)continue;let s=Array.from(o.getClientRects()).filter(e=>e.height>0);if(s.length!==0)return n===1?s[0]:s[s.length-1]}}function ws(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 Ts(e){return xs(e)??Ss(e)}const Es=new S(`meowdown-scroll-to-selection`);function Ds(e){let t=e.state.selection;if(!g(t)||q(e,t.head,1)!=null)return!1;let n=Ts(e);if(n==null)return!1;let r=e.domAtPos(t.head).node;return js(e,{left:n.left,right:n.left,top:n.top,bottom:n.top+n.height},r),!0}function J(e,t){return typeof e==`number`?e:e[t]}function Os(e){let t=e.assignedSlot??e.parentNode;return t?.nodeType===11?t.host:t}function ks(e){let t=e.defaultView?.visualViewport;return t?{left:0,right:t.width,top:0,bottom:t.height}:{left:0,right:e.documentElement.clientWidth,top:0,bottom:e.documentElement.clientHeight}}function As(e){let t=e.getBoundingClientRect(),n=t.width/e.offsetWidth||1,r=t.height/e.offsetHeight||1;return{left:t.left,right:t.left+e.clientWidth*n,top:t.top,bottom:t.top+e.clientHeight*r}}function js(e,t,n){let r=e.someProp(`scrollThreshold`)??0,i=e.someProp(`scrollMargin`)??5,a=e.dom.ownerDocument;for(let e=n;e;){if(e.nodeType!==1){e=Os(e);continue}let n=e,o=n===a.body,s=o?ks(a):As(n),c=0,l=0;if(t.top<s.top+J(r,`top`)?l=-(s.top-t.top+J(i,`top`)):t.bottom>s.bottom-J(r,`bottom`)&&(l=t.bottom-t.top>s.bottom-s.top?t.top+J(i,`top`)-s.top:t.bottom-s.bottom+J(i,`bottom`)),t.left<s.left+J(r,`left`)?c=-(s.left-t.left+J(i,`left`)):t.right>s.right-J(r,`right`)&&(c=t.right-s.right+J(i,`right`)),c||l)if(o)a.defaultView?.scrollBy(c,l);else{let e=n.scrollLeft,r=n.scrollTop;l&&(n.scrollTop+=l),c&&(n.scrollLeft+=c);let i=n.scrollLeft-e,a=n.scrollTop-r;t={left:t.left-i,top:t.top-a,right:t.right-i,bottom:t.bottom-a}}let u=o?`fixed`:getComputedStyle(n).position;if(/^(?:fixed|sticky)$/.test(u))break;e=u===`absolute`?n.offsetParent:Os(n)}}function Ms(){return m(new x({key:Es,props:{handleScrollToSelection:Ds}}))}function Ns(e,t){return(n,r)=>{let i=e<0?Me.atStart(n.doc):Me.atEnd(n.doc),a=t?C.between(n.selection.$anchor,i.$head):i;return n.selection.eq(a)||r?.(n.tr.setSelection(a).scrollIntoView()),!0}}function Ps(){return l({"Meta-ArrowUp":Ns(-1,!1),"Meta-ArrowDown":Ns(1,!1),"Shift-Meta-ArrowUp":Ns(-1,!0),"Shift-Meta-ArrowDown":Ns(1,!0)})}function Fs(e){e.offsetWidth}const Is=new S(`meowdown-virtual-caret`),Ls=[`md-virtual-caret-blink`,`md-virtual-caret-blink2`];function Rs(e){let t=e.height*.19999999999999996;return{left:e.left,top:e.top-t/2,height:e.height+t}}function zs(e){let t=bs(e)??xs(e);return t==null?Ss(e):Rs(t)}function Bs(e,t){return e==null||t==null?e===t:e.left===t.left&&e.top===t.top&&e.height===t.height}var Vs=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=Ls[this.#s]}#l=()=>{let e=this.#e;if(e.isDestroyed)return;let t=e.state,n=t.selection,r=g(n)&&n.empty?zs(e):void 0,i=r!=null&&A(t)===`hide`?_i(t,n.head):void 0;if(Bs(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&&(Fs(this.#n),this.#n.style.transitionProperty=``)}};function Hs(){return m(new x({key:Is,view:e=>new Vs(e)}))}function Us(e){return _(Yn(),Ee(),oi(),ke(),Te(),Mo(),Gn(),is(),Xr(),ki(),Ai(),Ma(),Vr(),ai(),cs(),Ps(),ga(e),Ya(),ro(),Yi(),Lo(),Yt(e.markMode??`focus`),Fr(),Hs(),Ms(),Di(),fn({marks:$t.map(e=>({name:e,modes:[`hide`,`focus`,`show`]}))}),a(),i(),c(),De(),Ae(),Oe(),ri(),_s())}function Ws(e={}){return Us(e)}const Gs=we(()=>{let e=Ws().schema;if(e==null)throw Error(`Unexpected empty schema`);return e}),Ks=we(()=>r(Gs())),qs=we(()=>n(Gs())),Js=`meowdown_mark_builders`;function Ys(e){let t=e.cached[Js];if(t)return t;let r=n(e);return e.cached[Js]=r,r}const Xs=`meowdown_node_builders`;function Zs(e){let t=e.cached[Xs];if(t)return t;let n=r(e);return e.cached[Xs]=n,n}function Y(e,t={}){let{nodes:n=Ks(),frontmatter:r=!1}=t,i,a=e;if(r){let[t,n]=$s(e);i=t,n&&(a=e.slice(n))}let o=ec(n,ye.parse(a).cursor(),a);return n.doc(i===void 0?{}:{frontmatter:i},o)}const Qs=/^---[ \t]*\r?\n([\s\S]*?\n)?---[ \t]*(?:\r?\n|$)/;function $s(e){let t=Qs.exec(e);return t?[(t[1]??``).replace(/\r?\n$/,``),t[0].length]:[]}function ec(e,t,n){let r=[];if(!t.firstChild())return r;let i;do i!=null&&tc(r,e,n,i,t.from),i=t.to,r.push(...nc(e,t,n));while(t.nextSibling());return t.parent(),r}function tc(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 nc(e,t,n){switch(t.type.id){case y.ATXHeading1:return[X(e,t,n,1,!1)];case y.ATXHeading2:return[X(e,t,n,2,!1)];case y.ATXHeading3:return[X(e,t,n,3,!1)];case y.ATXHeading4:return[X(e,t,n,4,!1)];case y.ATXHeading5:return[X(e,t,n,5,!1)];case y.ATXHeading6:return[X(e,t,n,6,!1)];case y.SetextHeading1:return[X(e,t,n,1,!0)];case y.SetextHeading2:return[X(e,t,n,2,!0)];case y.Paragraph:return[Q(e,t,n)];case y.CommentBlock:return[cc(e,t,n)];case y.HTMLBlock:case y.ProcessingInstructionBlock:return[Q(e,t,n)];case y.Blockquote:return[lc(e,t,n)];case y.BulletList:return uc(e,t,n,`bullet`);case y.OrderedList:return uc(e,t,n,`ordered`);case y.FencedCode:case y.CodeBlock:return[fc(e,t,n)];case y.BlockMath:return[pc(e,t,n)];case y.HorizontalRule:{let r=n.slice(t.from,t.to).trimEnd();return[e.horizontalRule({marker:r===`---`?null:r})]}case y.Table:return[mc(e,t,n)];case y.Task:return[Q(e,t,n)];default:return n.slice(t.from,t.to).trim()===``?[]:(console.warn(`[meowdown] unsupported lezer block "${t.type.name}"`),[Q(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===y.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===y.HeaderMark&&n>o&&(s=n,c=n,l=r),t.parent()}let u=oc(n.slice(o,s),Z(n,o)).trim(),d=i?rc(n,c,l)||1:null,f=!i&&c>=0&&ic(n,c,l)||null;return e.heading({level:r,setextUnderline:d,closingHashes:f},u)}function rc(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 ic(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(`
|
|
26
|
-
|
|
27
|
+
`)}function Lr(e,t,n){let{content:r,openStart:i,openEnd:a}=t;if(r.childCount===0||i===0&&a===0)return r;let o=g(n)&&Pr(n.$from),s=g(n)&&Fr(n.$to),c=r.childCount-1,l=[];return r.forEach((t,n,r)=>{r===0&&i>0&&!o?l.push(zr(e,t)):r===c&&a>0&&!s?l.push(Rr(e,t,a)):l.push(t)}),E.from(l)}function Rr(e,t,n){if(I(t,`codeBlock`)||I(t,`table`))return zr(e,t);if(I(t,`heading`)){let n=t.attrs;if(n.setextUnderline!=null)return zr(e,t);if(n.closingHashes!=null)return t.type.create({...n,closingHashes:null},t.content,t.marks)}if(n<=1||t.childCount===0)return t;let r=t.childCount-1,i=t.child(r),a=Rr(e,i,n-1);return a===i?t:t.copy(t.content.replaceChild(r,a))}function zr(e,t){let n=te(e,`paragraph`),r=t.textBetween(0,t.content.size,`
|
|
28
|
+
`,`
|
|
29
|
+
`);return n.create(void 0,r?e.text(r):void 0)}function Br(){return m(new S({key:new C(`meowdown-plain-text-copy`),props:{clipboardTextSerializer:(e,t)=>{let n=j(t.state)===`hide`?Vr(e):e;return Ir(t.state.schema,n,t.state.selection)}}}))}function Vr(e){return new D(Hr(e.content),e.openStart,e.openEnd)}function Hr(e){let t=[];return e.forEach(e=>{t.push(e.isTextblock?Wr(e):Ur(e))}),E.from(t)}function Ur(e){return e.childCount>0?e.copy(Hr(e.content)):e}function Wr(e){let t=e.type.schema,n=[];for(let r of An(e)){let e=r.atom;if(e!=null){if(Tn(e,`mdWikilink`)){let r=e.attrs,i=r.display||r.target;i&&n.push(t.text(i))}else n.push(...r.children);continue}for(let e of r.children)kn(e.marks)||n.push(e)}return e.copy(E.from(n))}function Gr(){return _(Zn(),Br(),ur(),sr(),pr())}const R=new Map,Kr=new Map,qr={math:`latex`};async function Jr(e){let t=R.get(e);if(t!==void 0)return t;let n=Ye.matchLanguageName(Xe,qr[e]??e,!0);if(!n)return R.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),R.set(e,null),null}return R.set(e,r),r}function Yr(e,t){let n=Kr.get(e);if(n)return n;let r=$e({parse:e=>t.language.parser.parse(e.content),highlighter:Ze});return Kr.set(e,r),r}const Xr=e=>{let t=e.language?.trim();if(!t)return[];let n=R.get(t);return n===null?[]:n?Yr(t,n)(e):Jr(t).then(()=>void 0)};function Zr(){return fe({parser:Xr,nodeTypes:[`codeBlock`]})}function Qr(e,t){let n=t.language.parser.parse(e),r=[];return Qe(n,Ze,(e,t,n)=>{r.push([e,t,n])}),r}function $r(e,t){let n=t.trim();if(!n)return[];let r=R.get(n);return r===null?[]:r?Qr(e,r):Jr(n).then(t=>t?Qr(e,t):[])}function ei(){return f({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 ti(){return f({type:`codeBlock`,attr:`fenceLength`,default:null,toDOM:e=>e==null?null:[`data-fence-length`,String(e)],parseDOM:e=>{let t=wn(e.getAttribute(`data-fence-length`));return t!=null&&t>3?t:null}})}function ni(e){return{language:e[1]||``,fenceStyle:`tilde`}}function ri(){return rt({regex:/^~~~(\S*)\s$/,type:`codeBlock`,attrs:ni})}function ii(){return tt({regex:/^~~~(\S*)$/,type:`codeBlock`,attrs:ni})}function ai(){return tt({regex:/^\$\$$/,type:`codeBlock`,attrs:()=>({language:`math`,fenceStyle:`dollar`})})}function oi(){return _(de(),ei(),ti(),ri(),ii(),ai())}function si(e,t){return(n,r)=>{if(r){let i=w.create(n.doc,e,t);r(n.tr.setSelection(i))}return!0}}function ci(e,t,n){return(r,i)=>{if(i){let a=w.between(e,t,n);i(r.tr.setSelection(a))}return!0}}function li(e){return(t,n)=>{if(!e.trim())return!1;let r=X(e,{nodes:cc(t.schema)}).content;if(r.childCount===0)return!1;let i=r.childCount===1&&I(r.child(0),`paragraph`)?new D(r,1,1):new D(r,0,D.maxOpen(r).openEnd);if(n){let e=t.tr,r=e.selection;(!g(r)||!r.empty)&&e.setSelection(w.near(r.$from)),n(e.replaceSelection(i).scrollIntoView())}return!0}}function ui(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);it(s),n(s.scrollIntoView())}return!0}}function di(){return ft(oe({type:`paragraph`}),dt(),pt)}function fi(){return(e,t)=>(t&&t(e.tr.scrollIntoView()),!0)}function pi(){return s({insertMarkdown:li,insertTrigger:ui,scrollIntoView:fi,selectText:si,selectTextBetween:ci,turnIntoText:di})}const mi=(e,t,n)=>{let{selection:r}=e;return r.empty||n?.composing?!1:(t?.(e.tr.setSelection(w.near(r.$head))),!0)};function hi(){return v(l({Escape:mi}),t.low)}function gi(){return f({type:`doc`,attr:`frontmatter`,default:null})}function _i(e,t){return t(e.state,e.dispatch,e)}function vi(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 z(e,t){let n=vi(e,t);return n!=null&&n.some(e=>En.has(e.type.name))}function yi(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 B(e,t){if(!yi(e,t))return;let n=e.doc.resolve(t).start(),r=t;for(;r>n&&z(e,r-1);)r--;return r<t?{from:r,to:t}:void 0}function V(e,t){if(!yi(e,t))return;let n=e.doc.resolve(t).end(),r=t;for(;r<n&&z(e,r);)r++;return r>t?{from:t,to:r}:void 0}function bi(e,t){return z(e,t-1)&&z(e,t)}function xi(e,t){if(!bi(e,t))return;let n=B(e,t);if(!n)return;let r=V(e,t);if(r)return{from:n.from,to:r.to}}function Si(e,t,n){let r=vi(e,t);return r!=null&&n.isInSet(r)}function Ci(e,t){let n=vi(e,t);if(n==null)return;let r=ee(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&&Si(e,r-1,n);)r--;let i=t+1;for(;i<s&&Si(e,i,n);)i++;(c==null||i-r<c.to-c.from)&&(c={from:r,to:i})}return c}function wi(e,t,n){let r=Ci(e,n===`from`?t.from:t.to-1);return r==null?!1:n===`from`?r.from===t.from:r.to===t.to}function Ti(e,t,n){let r=wi(e,t,`from`),i=wi(e,t,`to`);return r&&!i?t.from:i&&!r?t.to:n-t.from<=t.to-n?t.from:t.to}function Ei(e,t,n,r){if(!yi(e,n))return n;let i=xi(e,n);if(i!=null)return r?Ti(e,i,n):n>=t?i.to:i.from;if(!r)return n;let a=B(e,n);if(a!=null&&wi(e,a,`from`))return a.from;let o=V(e,n);return o!=null&&wi(e,o,`to`)?o.to:n}function Di(e,t){if(!yi(e,t))return;let n=z(e,t-1),r=z(e,t);if(n!==r)return r?`left`:`right`}function Oi(e,t){let n=Ci(e,t);if(n==null)return[];let r=V(e,n.from),i=B(e,n.to),a=[];return i!=null&&a.push(i),r!=null&&(i==null||r.from!==i.from)&&a.push(r),a}const ki=new C(`meowdown-hidden-run-snap`),Ai=new C(`meowdown-hidden-run-beforeinput`);function ji(){let e=!1;return new S({key:ki,props:{handleDOMEvents:{compositionstart:()=>(e=!0,!1),compositionend:()=>(e=!1,!1)}},appendTransaction:(t,n,r)=>{if(e||j(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=Ei(r,n.selection.head,i.head,a);return e===i.head?null:r.tr.setSelection(w.create(r.doc,e))}let o=xi(r,i.from)?.from??i.from,s=xi(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(w.create(r.doc,c,l))}})}const Mi=(e,t)=>{if(j(e)!==`hide`)return!1;let n=e.selection;if(!g(n)||!n.empty)return!1;let r=Ei(e,n.head,n.head,!0);return r===n.head||t?.(e.tr.setSelection(w.create(e.doc,r))),!1};function Ni(e){return(t,n)=>{if(j(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?B(t,r.head):V(t,r.head);if(a==null)return!1;let o=Oi(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 Pi=Ni(-1),Fi=Ni(1);function Ii(){return new S({key:Ai,props:{handleDOMEvents:{beforeinput:(e,t)=>{if(e.composing)return!1;let n=t.inputType===`deleteContentBackward`?Pi:t.inputType===`deleteContentForward`?Fi:void 0;return n==null||!_i(e,n)?!1:(t.preventDefault(),!0)}}}})}function Li(){return _(m(ji()),m(Ii()),v(l({Enter:Mi,Backspace:Pi,Delete:Fi}),t.highest))}function Ri(){return f({type:`horizontalRule`,attr:`marker`,default:null,toDOM:e=>e?[`data-hr-marker`,e]:null,parseDOM:e=>e.getAttribute(`data-hr-marker`)})}function zi(){return _(mt(),Ri())}function Bi(){return p({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 Vi(e){let[t,n,r]=e;return[t,n,r.map(e=>e.toJSON())]}function Hi(e,t){let[n,r,i]=t;return[n,r,i.map(t=>Ue.fromJSON(e,t))]}function Ui(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 Wi=class e extends bt{constructor(e){super(),this.chunks=e}apply(e){if(this.chunks.length===0)return xt.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=Ue.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(Ui(l,c))return!1;n??=new St(e);for(let e of l)n.removeMark(i,a,e);for(let e of c)n.addMark(i,a,e);return!1})}return xt.ok(n?n.doc:e)}invert(e){if(this.chunks.length===0)return Gi;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 yt(i,a,e.slice(i,a),!1)}map(e){return null}toJSON(){return{stepType:`batchSetMark`,chunks:this.chunks.map(Vi)}}static fromJSON(t,n){let r=n.chunks;return new e(r.map(e=>Hi(t,e)))}};bt.jsonID(`batchSetMark`,Wi);const Gi=new Wi([]),Ki=/^<!--\s*(\{[^}]*\})\s*-->$/,qi=/<!--\s*\{[^}]*\}\s*-->$/;function Ji(e){let t=Ki.exec(e.trim());if(!t)return;let n;try{n=JSON.parse(t[1])}catch{return}if(!Se(n))return;let r=Yi(n);return Object.keys(r).length>0?r:void 0}function Yi(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 Xi(e){return`<!-- ${JSON.stringify(e)} -->`}function Zi(e){return e.replace(qi,``)}const Qi=/^(\d+)(?:x(\d+))?$/i;function $i(e){if(!e)return null;let t=Number.parseInt(e,10);return Number.isSafeInteger(t)&&t>0?t:null}function ea(e){let t=e.replace(/^!\[\[/,``).replace(/\]\]$/,``),n=t.lastIndexOf(`|`);if(n<0)return{target:t.trim(),display:``,width:null,height:null};let r=t.slice(0,n).trim(),i=t.slice(n+1).trim(),a=Qi.exec(i);if(!a)return{target:r,display:i,width:null,height:null};let o=$i(a[1]),s=$i(a[2]);return o==null||a[2]&&s==null?{target:r,display:i,width:null,height:null}:{target:r,display:``,width:o,height:s}}function ta(e,t,n){return`![[${e}|${Math.round(t)}x${Math.round(n)}]]`}function na(e){let t=e.split(/[?#]/,1)[0],n=t.split(/[/\\]/).findLast(Boolean)??t;try{return decodeURIComponent(n)}catch{return n}}function ra(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 ia(){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 aa(){return d({name:`mdWikilink`,constructor:ia()})}const oa=new Map([[y.Emphasis,`mdEm`],[y.StrongEmphasis,`mdStrong`],[y.InlineCode,`mdCode`],[y.Strikethrough,`mdDel`],[y.Highlight,`mdHighlight`],[y.EmphasisMark,`mdMark`],[y.CodeMark,`mdMark`],[y.LinkMark,`mdMark`],[y.StrikethroughMark,`mdMark`],[y.HighlightMark,`mdMark`],[y.URL,`mdLinkUri`],[y.LinkTitle,`mdLinkTitle`],[y.Hashtag,`mdTag`],[y.WikilinkMark,`mdMark`]]);function sa(e,t,n){let r=x(t),i=[];return la(r,[],0,t.length,t,e,i,n),i}function ca(e){return e.slice(1,-1).replaceAll(/\\(.)/g,`$1`)}function la(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===y.Link)if(!ua(r))la(r.children.filter(e=>e.type!==y.LinkMark&&e.type!==y.LinkLabel),t,r.from,r.to,i,a,o,s);else{let e=pa(r,t,i,a,s);e?H(o,r.from,r.to,e):ma(r,t,i,a,o,s)}else if(l===y.Image){let s=ha(r,e[n+1],i);ga(r,t,i,a,o,s),s&&n++,c=s?s.to:r.to;continue}else if(l===y.Wikilink)va(r,t,i,a,o);else if(l===y.WikiEmbed)ya(r,t,i,a,o,s);else if(l===y.InlineMath)_a(r,t,i,a,o);else if(l===y.URL){let e=ve(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===y.Emphasis?e=`italic`:l===y.StrongEmphasis?e=`bold`:l===y.InlineCode?e=`code`:l===y.Strikethrough?e=`strike`:l===y.Highlight?e=`highlight`:l===y.Autolink&&(e=`autolink`);let n=e?[...t,a.mdPack.create({key:e})]:t,c=oa.get(l),u=c?[...n,a[c].create()]:n;r.children.length===0?H(o,r.from,r.to,u):la(r.children,u,r.from,r.to,i,a,o,s)}c=r.to}c<r&&H(o,c,r,t)}function ua(e){let t=0;for(let n of e.children)n.type===y.LinkMark&&t++;return t>=3}function da(e){let t=-1,n=-1,r=null,i=null,a=0;for(let o of e.children){let e=o.type;e===y.LinkMark?(a++,a===1&&(t=o.to),a===2&&(n=o.from)):r==null&&e===y.URL?r=o:i==null&&e===y.LinkTitle&&(i=o)}return{labelFrom:t,labelTo:n,urlNode:r,titleNode:i}}function fa(e){let t=e.split(/[?#]/,1)[0],n=t.split(/[/\\]/).findLast(Boolean)??t;try{return decodeURIComponent(n)}catch{return n}}function pa(e,t,n,r,i){let a=i?.resolveFileLink;if(!a)return;let{labelFrom:o,labelTo:s,urlNode:c,titleNode:l}=da(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?ca(n.slice(l.from,l.to)):``;if(!a({href:u,label:d,title:f}))return;let p=d||fa(u);return[...t,r.mdFile.create({href:u,name:p,title:f})]}function ma(e,t,n,r,i,a){let{labelTo:o,urlNode:s,titleNode:c}=da(e),l=s?n.slice(s.from,s.to):``,u=c?ca(n.slice(c.from,c.to)):``,d=l?r.mdLinkText.create({href:l}):null,f=e=>o>=0&&e<o&&d!==null,p=r.mdPack.create({key:`link`,data:{href:l,title:u}}),m=[...t,p],h=e.from;for(let t of e.children){if(t.from>h){let e=f(h)?[...m,d]:m;H(i,h,t.from,e)}let e=f(t.from)?[...m,d]:m;if(t.type===y.Wikilink){va(t,e,n,r,i),h=t.to;continue}if(t.type===y.WikiEmbed){ya(t,e,n,r,i,a),h=t.to;continue}let o=oa.get(t.type),s=o?[...e,r[o].create()]:e;t.children.length===0?H(i,t.from,t.to,s):la(t.children,s,t.from,t.to,n,r,i,a),h=t.to}h<e.to&&H(i,h,e.to,m)}function ha(e,t,n){if(!t||t.type!==y.Comment||t.from!==e.to)return;let r=Ji(n.slice(t.from,t.to));if(r)return{magic:r,to:t.to}}function ga(e,t,n,r,i,a){let o=e.children.find(e=>e.type===y.URL);if(!o){ma(e,t,n,r,i,void 0);return}let s=e.children.filter(e=>e.type===y.LinkMark),c=e.children.find(e=>e.type===y.LinkTitle),l=n.slice(o.from,o.to),u=s.length>=2?n.slice(s[0].to,s[1].from):``,d=c?ca(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,syntax:null,wikiTarget:null})])}function _a(e,t,n,r,i){let a=e.children.filter(e=>e.type===y.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 va(e,t,n,r,i){let{target:a,display:o}=ra(n.slice(e.from,e.to));H(i,e.from,e.to,[...t,r.mdWikilink.create({target:a,display:o})])}function ya(e,t,n,r,i,a){let o=ea(n.slice(e.from,e.to)),s=a?.resolveWikiEmbed?.(o);if(!s){H(i,e.from,e.to,t);return}if(s.kind===`image`){let n=s.src??o.target,a=(s.alt??o.display)||na(o.target);H(i,e.from,e.to,[...t,r.mdImage.create({src:n,alt:a,title:``,width:o.width,height:o.height,syntax:`wikiEmbed`,wikiTarget:o.target})]);return}if(s.kind===`file`){let n=s.href??o.target,a=(s.name??o.display)||na(o.target);H(i,e.from,e.to,[...t,r.mdFile.create({href:n,name:a,title:s.title??``})]);return}let c=s.target??o.target,l=s.display??o.display;H(i,e.from,e.to,[...t,r.mdWikilink.create({target:c,display:l})])}function H(e,t,n,r){if(t>=n)return;let i=e.at(-1);if(i&&i[1]===t&&Ui(i[2],r)){e[e.length-1]=[i[0],n,i[2]];return}e.push([t,n,r])}const ba=`inline-marks-applied`;let xa=0,Sa=0;function Ca(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 wa(e){let t=new WeakMap;function n(n,r,i){let a=t.get(n);if(a?Sa++:(xa++,a=sa(oc(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 S({key:new C(`inline-mark`),appendTransaction(e,t,n){for(let t of e)if(t.getMeta(ba))return null;let i=r(n,Ca(e,n));if(i.length===0)return null;let a=n.tr.step(new Wi(i));return a.setMeta(ba,!0),a.setMeta(`addToHistory`,!1),a},view(e){return e.dispatch(Ta(e.state)),{}}})}function Ta(e){return e.tr.setMeta(`inline-marks-trigger`,!0)}function Ea(e){return m(wa(e))}function Da(){return u({name:`mdImage`,inclusive:!1,attrs:{src:{default:``},alt:{default:``},title:{default:``},width:{default:null},height:{default:null},syntax:{default:null},wikiTarget:{default:null}},toDOM:()=>[`span`,{class:`md-image`},0],parseDOM:[{tag:`span.md-image`}]})}function Oa(){return u({name:`mdMark`,inclusive:!1,toDOM:()=>[`span`,{class:`md-mark`},0],parseDOM:[{tag:`span.md-mark`}]})}function ka(){return u({name:`mdEm`,toDOM:()=>[`em`,0],parseDOM:[{tag:`em`}]})}function Aa(){return u({name:`mdStrong`,toDOM:()=>[`strong`,0],parseDOM:[{tag:`strong`}]})}function ja(){return u({name:`mdCode`,toDOM:()=>[`code`,0],parseDOM:[{tag:`code`}]})}function Ma(){return u({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 Na(){return u({name:`mdLinkUri`,inclusive:!1,toDOM:()=>[`span`,{class:`md-link-uri`},0],parseDOM:[{tag:`span.md-link-uri`}]})}function Pa(){return u({name:`mdLinkTitle`,inclusive:!1,toDOM:()=>[`span`,{class:`md-link-title`},0],parseDOM:[{tag:`span.md-link-title`}]})}function Fa(){return u({name:`mdDel`,toDOM:()=>[`del`,0],parseDOM:[{tag:`del`}]})}function Ia(){return u({name:`mdHighlight`,toDOM:()=>[`mark`,0],parseDOM:[{tag:`mark`}]})}function La(){return u({name:`mdTag`,toDOM:()=>[`span`,{class:`md-tag`},0],parseDOM:[{tag:`span.md-tag`}]})}function Ra(){return u({name:`mdWikilink`,inclusive:!1,attrs:{target:{default:``},display:{default:``}},toDOM:()=>[`span`,{class:`md-wikilink`},0],parseDOM:[{tag:`span.md-wikilink`}]})}function za(){return u({name:`mdFile`,inclusive:!1,attrs:{href:{default:``},name:{default:``},title:{default:``}},toDOM:()=>[`span`,{class:`md-file`},0],parseDOM:[{tag:`span.md-file`}]})}function Ba(){return u({name:`mdMath`,inclusive:!1,attrs:{formula:{default:``}},toDOM:()=>[`span`,{class:`md-math`},0],parseDOM:[{tag:`span.md-math`}]})}function Va(){return u({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 Ha(){return _(Oa(),ka(),Aa(),ja(),Ma(),Na(),Pa(),Fa(),Ia(),La(),Ra(),Da(),za(),Ba(),Va())}const U={em:{node:y.Emphasis,delim:`*`},strong:{node:y.StrongEmphasis,delim:`**`},code:{node:y.InlineCode,delim:"`"},del:{node:y.Strikethrough,delim:`~~`},highlight:{node:y.Highlight,delim:`==`}},Ua=new Set([y.EmphasisMark,y.CodeMark,y.LinkMark,y.StrikethroughMark,y.HighlightMark]);function Wa(e){return[e.children[0],e.children.at(-1)]}function Ga(e){let{type:t,children:n}=e;if(t===y.Emphasis||t===y.StrongEmphasis||t===y.Strikethrough||t===y.Highlight)return[n[0].to,n.at(-1).from];if(t===y.Link||t===y.Image){let e=n.find((e,t)=>t>0&&e.type===y.LinkMark);return e?[n[0].to,e.from]:null}return null}function Ka(e,t,n){for(let r of e){if(r.to<=t||r.from>=n||t<=r.from&&r.to<=n)continue;let i=Ga(r);return i&&i[0]<=t&&n<=i[1]?Ka(r.children,t,n):Ka(e,Math.min(t,r.from),Math.max(n,r.to))}return[t,n]}function qa(e,t,n){for(let r of e)if(!(r.to<=t||r.from>=n)&&(t>r.from||r.to>n))return qa(e,Math.min(t,r.from),Math.max(n,r.to));return[t,n]}function Ja(e,t,n){for(;t<n&&b(e.charCodeAt(t));)t++;for(;n>t&&b(e.charCodeAt(n-1));)n--;return[t,n]}function Ya(e,t,n,r){let i=_e(x(e),e=>e.type===r.node||Ua.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 Xa(e,t,n,r,i){let a=x(e),o=_e(a,e=>e.type===r.node);return i?$a(e,o,t,n):Za(e,a,o,t,n,r)}function Za(e,t,n,r,i,a){for(let e=0;e!==i-r;){e=i-r,[r,i]=Ka(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]=Wa(e);o.push({from:t.from,to:t.to,insert:``}),o.push({from:n.from,to:n.to,insert:``})}let[s,c]=Qa(e,r,i,o,a);return o.push({from:r,to:r,insert:s},{from:i,to:i,insert:c}),o}function Qa(e,t,n,r,i){if(i.node!==y.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(hr(a)+1),s=a.startsWith("`")||a.endsWith("`")?` `:``;return[o+s,s+o]}function $a(e,t,n,r){let i=[];for(let a of t){if(a.to<=n||a.from>=r)continue;let[t,o]=Wa(a),s=Math.max(n,t.to),c=Math.min(r,o.from);for(s>=c&&([s,c]=[t.to,o.from]),[s,c]=qa(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 eo(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=x(e),o=_e(a,e=>e.type===n.node).findLast(e=>e.from<=t&&t<=e.to);if(o){let[e,n]=Wa(o);return{kind:`move`,pos:t===o.from?e.to:t===o.to?n.from:o.to}}return to(a,t)||e[t-1]===r[0]||e[t]===r[0]?null:{kind:`insert`,pos:t}}function to(e,t){for(let n of e)if(n.from<t&&t<n.to){let e=Ga(n);return!e||t<e[0]||t>e[1]||to(n.children,t)}return!1}function W(e){return(t,n)=>{if(t.selection.empty)return no(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]=Ja(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:Ya(a,c,l,e)}),!1});let c=s.length>0&&s.every(e=>e.active),l=s.filter(e=>c||!e.active).flatMap(t=>Xa(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(w.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 no(e,t,n){let{$from:r}=t.selection,i=r.parent;if(!i.isTextblock||i.type.spec.code)return!1;let a=eo(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(w.create(o.doc,i+a.pos)),a.kind===`insert`&&(o.insertText(e.delim+e.delim,i+a.pos),o.setSelection(w.create(o.doc,i+a.pos+e.delim.length))),n(o.scrollIntoView())}return!0}function ro(){return s({toggleEm:()=>W(U.em),toggleStrong:()=>W(U.strong),toggleCode:()=>W(U.code),toggleDel:()=>W(U.del),toggleHighlight:()=>W(U.highlight)})}function io(){return l({"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 ao(){return _(ro(),io())}function oo(e,t,n){let r;return e.doc.nodesBetween(t.from,t.to,(e,i)=>(e.isText&&e.marks.some(e=>Tn(e,n))&&(r={from:Math.max(i,t.from),to:Math.min(i+e.nodeSize,t.to)}),!0)),r}function G(e,t){let n=k(e,t,`mdLinkText`),r=k(e,t,`mdPack`,{key:`link`})??k(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`?oo(e,t,`mdLinkText`)??{from:i.from+1,to:i.to-1}:t,href:o,title:``}}let s=oo(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 so(e){let t=e.trim();return t?ve(t)??t:``}function co(e,t){return e+(t?` "${t.replaceAll(/(["\\])/g,String.raw`\$1`)}"`:``)}function lo(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]=Ja(a.textContent,n.parentOffset,r.parentOffset);if(!(s>=c))return{from:o+s,to:o+c}}function uo({href:e,title:t,wrapText:n=!0}={}){return(r,i)=>{let a=lo(r);if(!a)return!1;if(i){let{from:o,to:s}=a,c=r.tr,l=`](${co(so(e??``),t??``)})`;c.insertText(l,s).insertText(`[`,o);let u=s+1+l.length;c.setSelection(n?w.create(c.doc,o,u):w.create(c.doc,u)),c.scrollIntoView(),i(c)}return!0}}function fo(e){return(t,n)=>{let r=G(t,t.selection.from);if(!r?.dest)return!1;let i=co(so(e.href??r.href),e.title??r.title);return n&&n(t.tr.insertText(i,r.dest.from,r.dest.to).scrollIntoView()),!0}}function po(){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 mo(){return s({insertLink:uo,updateLink:fo,removeLink:po})}function ho(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(w.create(t.doc,a,o)).scrollIntoView()),r.focus(),e({from:a,to:o,link:i})}return!0}let a=lo(t);if(a){if(n&&r){let{from:i,to:o}=a;n(t.tr.setSelection(w.create(t.doc,i,o)).scrollIntoView()),r.focus(),e({from:i,to:o,link:void 0})}return!0}return!1}}function go(e){return l({"Mod-k":ho(e)})}function _o(e){return e===`)`||e===`*`||e===`+`?e:void 0}function vo(e){return e===`X`?e:void 0}function yo(e){return So(e)?String(e):void 0}function bo(){return f({type:`list`,attr:`marker`,default:null,splittable:!0,toDOM:e=>{let t=_o(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 xo(){return f({type:`list`,attr:`taskMarker`,default:null,splittable:!0,toDOM:e=>{let t=vo(e);return t==null?null:[`data-list-task-marker`,t]},parseDOM:e=>e.getAttribute(`data-list-task-marker`)===`X`?`X`:null})}function So(e){return e===2||e===3||e===4}function Co(){return f({type:`list`,attr:`markerGap`,default:1,splittable:!0,toDOM:e=>{let t=yo(e);return t==null?null:[`data-list-marker-gap`,t]},parseDOM:e=>{let t=Number.parseInt(e.getAttribute(`data-list-marker-gap`)??``,10);return So(t)?t:1}})}function wo(e){let t=e.attrs;return{...Et(e),"data-list-marker":_o(t.marker),"data-list-task-marker":vo(t.taskMarker),"data-list-marker-gap":yo(t.markerGap)}}function To(){return o({serializeFragmentWrapper:e=>(...t)=>Eo(kt(e(...t))),serializeNodeWrapper:e=>(...t)=>{let n=e(...t);return be(n)?Eo(kt(n)):n},nodesFromSchemaWrapper:e=>(...t)=>({...e(...t),list:e=>At({node:e,nativeList:!0,getAttributes:wo})})})}function Eo(e){be(e)&&Do(e);for(let t of e.children)Eo(t);return e}function Do(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=Dt(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 Oo=[Mt(/^\s?([*-])\s$/,{kind:`bullet`,collapsed:!1}),Mt(/^\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}}),Mt(/^\s?\[([\sX]?)\]\s$/i,({match:e})=>({kind:`task`,checked:[`x`,`X`].includes(e[1]),collapsed:!1})),Mt(/^\s?\+\s$/,{kind:`task`,marker:`+`,checked:!1,collapsed:!1})];function ko(){return _(Oo.map(nt))}function Ao(){return O({kind:`task`,marker:`+`})}function jo(){return O({kind:`task`,marker:null})}function Mo(e){let{$from:t}=e.selection;for(let e=t.depth;e>0;e--){let n=t.node(e);if(I(n,`list`))return n.attrs}return null}function No(){return(e,t,n)=>{let r=Mo(e);return(r?.kind===`task`?r.marker===`+`?jo():Ao():O({kind:`task`,marker:null,checked:!1}))(e,t,n)}}function Po(){return s({cycleCheckableList:No,wrapInCircleTask:Ao,wrapInSquareTask:jo})}function Fo(){return(e,t,n)=>{let r=Mo(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},O(a)(e,t,n)}}function Io(){return(e,t,n)=>{let r=Mo(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},O(a)(e,t,n)}}function Lo(e){return I(e,`list`)&&e.attrs.kind===`bullet`&&e.childCount>=2&&e.firstChild?.type!==e.type}const Ro=e=>{let t=e.attrs;return t.kind===`task`?{...t,checked:!t.checked}:Lo(e)?{...t,collapsed:!t.collapsed}:t};function zo(){return m(()=>[new S({props:{handleDOMEvents:{mousedown:(e,t)=>Ot({view:e,event:t,onListClick:Ro})}}}),Ct(),new S({props:{transformCopied:jt}}),wt()])}function Bo(){return s({toggleListCollapsed:()=>Tt({isToggleable:Lo})})}function Vo(){return l({"Mod-Enter":Fo(),"Mod-Shift-Enter":Io(),"Mod-.":Tt({isToggleable:Lo}),"Mod-Shift-7":ut({kind:`ordered`,collapsed:!1}),"Mod-Shift-8":ut({kind:`bullet`,collapsed:!1}),"Mod-Shift-9":ut({kind:`task`,checked:!1,collapsed:!1})})}function Ho(){return _(ct(),zo(),st(),at(),To(),ot(),ko(),Vo(),bo(),xo(),Co(),Po(),Bo())}let Uo;function Wo(){return Uo??=import(`./katex-chunk-Ch7kgbXr.js`).then(e=>e.render),Uo}function Go(e,t,n,r){try{e(n,t,{displayMode:r,throwOnError:!1,output:`mathml`})}catch(e){t.textContent=String(e)}}var Ko=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=w.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;Wo().then(t=>{e===this.#r&&Go(t,this.#n,e,!1)})}};function qo(){return d({name:`mdMath`,constructor:(e,t)=>new Ko(e,t)})}function Jo(e){return e===`left`||e===`center`||e===`right`?e:null}function Yo(){return f({type:`tableCell`,attr:`align`,default:null,toDOM:e=>e?[`data-align`,e]:null,parseDOM:e=>Jo(e.getAttribute(`data-align`))})}function Xo(){return f({type:`tableHeaderCell`,attr:`align`,default:null,toDOM:e=>e?[`data-align`,e]:null,parseDOM:e=>Jo(e.getAttribute(`data-align`))})}function Zo(e){for(let t=0;t<e.childCount;t++){let n=e.child(t);for(let e=0;e<n.childCount;e++)if(I(n.child(e),`tableHeaderCell`))return t}return 0}function Qo(e){return e.child(Zo(e))}function $o(e,t){return t>=e.childCount?null:e.child(t).attrs.align??null}function es(e,t,n){if(e.childCount===0)return;let r=Qo(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=$o(r,e);(t.attrs.align??null)!==i&&n.setNodeMarkup(o,void 0,{...t.attrs,align:i}),o+=t.nodeSize}i+=a.nodeSize}}function ts(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 ns(){return new S({key:new C(`table-align-sync`),appendTransaction(e,t,n){if(!e.some(e=>e.docChanged))return;let r=ts(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)=>I(e,`table`)?(s??=n.tr,es(e,t,s),!1):!0),s?.docChanged?s:void 0}})}function rs(){return m(ns())}function is(e){let{selection:t}=e;if(Vt(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 as(e){return(t,n)=>{let r=is(t);if(!r||r.table.childCount===0)return!1;if(n){let{table:i,tablePos:a,firstColumn:o,lastColumn:s}=r,c=Zo(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 os(e){let t=is(e);if(!(!t||t.table.childCount===0))return $o(Qo(t.table),t.lastColumn)??void 0}function ss(){return s({setTableColumnAlign:as})}function cs(){return _(Yo(),Xo(),rs(),ss())}function ls(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 us=`paragraph`;function ds(){return _(p({name:`tableCell`,content:us}),p({name:`tableHeaderCell`,content:us}))}const fs=(e,t)=>{let{selection:n}=e;return!Vt(n)||!n.isColSelection()||!n.isRowSelection()?!1:Bt(e,t)};function ps(){return v(l({Backspace:fs,Delete:fs}),t.high)}function ms(){return _(zt(),Rt(),Nt(),Lt(),ds(),cs(),It({allowTableNodeSelection:!0}),Pt(),Ft(),ps())}function hs(e){let{selection:t}=e,{$from:n,$to:r}=t;if(ae(t)&&n.depth===0||n.depth>0&&r.depth>0&&n.index(0)===r.index(0))return n.index(0)}function gs(e){return(t,n)=>{if(ls(t))return!1;let r=hs(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=ae(a)?Ae.create(u.doc,a.from+d):w.create(u.doc,a.anchor+d,a.head+d);u.setSelection(f),n(u.scrollIntoView())}return!0}}function _s(e){return(t,n,r)=>lt(e)(t,n,r)||gs(e===`up`?-1:1)(t,n,r)}function vs(){return l({"Alt-ArrowUp":_s(`up`),"Alt-ArrowDown":_s(`down`)})}const K=new C(`meowdownPendingReplacement`);function q(e){return K.getState(e)?.pending??null}function ys(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 bs=new S({key:K,state:{init:()=>({pending:null}),apply:(e,t)=>{let n=e.getMeta(K);if(n)return ys(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:T.create(e.doc,[Me.inline(t.from,t.to,{class:`md-pending-replacement`})])}}});function xs(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 Ss(e){return(t,n)=>q(t)?(n?.(t.tr.setMeta(K,{type:`append`,text:e})),!0):!1}function Cs(){return(e,t)=>q(e)?(t?.(e.tr.setMeta(K,{type:`discard`})),!0):!1}function ws(e={}){return(t,n)=>{let r=q(t);if(!r||!r.text.trim())return!1;if(n){let i=e.mode??r.mode,a=cc(t.schema),o=X(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(w.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!=null&&I(i,`paragraph`)&&e.sameParent(n)&&e.parent.isTextblock?(s.replaceWith(r.from,r.to,i.content),s.setSelection(w.near(s.doc.resolve(r.from+i.content.size),-1))):(s.replaceRange(r.from,r.to,new D(o.content,0,0)),s.setSelection(w.near(s.doc.resolve(s.mapping.map(r.to)),-1)))}n(s.scrollIntoView())}return!0}}function Ts(){return s({startPendingReplacement:xs,appendPendingReplacementText:Ss,acceptPendingReplacement:ws,discardPendingReplacement:Cs})}function Es(){return l({"Mod-Enter":ws(),Escape:Cs()})}function Ds(){return _(m(bs),Ts(),Es())}function Os(e){return m(new S({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 ks(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 ks(r)?void 0:r}function As(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 js(e){let t=e.state,n=t.selection.head,r=B(t,n),i=V(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 Ms(e){let t=e.state,n=t.selection.head;for(let r of $t){let i=k(t,n,r);if(i==null||i.from!==n&&i.to!==n)continue;let a=Ps(e,i.from+1);if(a==null)continue;let o=Array.from(a.getClientRects()).filter(e=>e.height>0);if(o.length===0)continue;let s=i.to===n,c=s?o[o.length-1]:o[0];return{left:s?c.right:c.left,top:c.top,height:c.height}}}function Ns(e,t,n){let r=e.state;for(let i of $t){let a=k(r,t,i);if(a==null)continue;let o=Ps(e,a.from+1);if(o==null)continue;let s=Array.from(o.getClientRects()).filter(e=>e.height>0);if(s.length!==0)return n===1?s[0]:s[s.length-1]}}function Ps(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 Fs(e){return js(e)??Ms(e)}const Is=new C(`meowdown-scroll-to-selection`);function Ls(e){let t=e.state.selection;if(!g(t)||J(e,t.head,1)!=null)return!1;let n=Fs(e);if(n==null)return!1;let r=e.domAtPos(t.head).node;return Vs(e,{left:n.left,right:n.left,top:n.top,bottom:n.top+n.height},r),!0}function Y(e,t){return typeof e==`number`?e:e[t]}function Rs(e){let t=e.assignedSlot??e.parentNode;return t?.nodeType===11?t.host:t}function zs(e){let t=e.defaultView?.visualViewport;return t?{left:0,right:t.width,top:0,bottom:t.height}:{left:0,right:e.documentElement.clientWidth,top:0,bottom:e.documentElement.clientHeight}}function Bs(e){let t=e.getBoundingClientRect(),n=t.width/e.offsetWidth||1,r=t.height/e.offsetHeight||1;return{left:t.left,right:t.left+e.clientWidth*n,top:t.top,bottom:t.top+e.clientHeight*r}}function Vs(e,t,n){let r=e.someProp(`scrollThreshold`)??0,i=e.someProp(`scrollMargin`)??5,a=e.dom.ownerDocument;for(let e=n;e;){if(e.nodeType!==1){e=Rs(e);continue}let n=e,o=n===a.body,s=o?zs(a):Bs(n),c=0,l=0;if(t.top<s.top+Y(r,`top`)?l=-(s.top-t.top+Y(i,`top`)):t.bottom>s.bottom-Y(r,`bottom`)&&(l=t.bottom-t.top>s.bottom-s.top?t.top+Y(i,`top`)-s.top:t.bottom-s.bottom+Y(i,`bottom`)),t.left<s.left+Y(r,`left`)?c=-(s.left-t.left+Y(i,`left`)):t.right>s.right-Y(r,`right`)&&(c=t.right-s.right+Y(i,`right`)),c||l)if(o)a.defaultView?.scrollBy(c,l);else{let e=n.scrollLeft,r=n.scrollTop;l&&(n.scrollTop+=l),c&&(n.scrollLeft+=c);let i=n.scrollLeft-e,a=n.scrollTop-r;t={left:t.left-i,top:t.top-a,right:t.right-i,bottom:t.bottom-a}}let u=o?`fixed`:getComputedStyle(n).position;if(/^(?:fixed|sticky)$/.test(u))break;e=u===`absolute`?n.offsetParent:Rs(n)}}function Hs(){return m(new S({key:Is,props:{handleScrollToSelection:Ls}}))}function Us(e,t){return(n,r)=>{let i=e<0?je.atStart(n.doc):je.atEnd(n.doc),a=t?w.between(n.selection.$anchor,i.$head):i;return n.selection.eq(a)||r?.(n.tr.setSelection(a).scrollIntoView()),!0}}function Ws(){return l({"Meta-ArrowUp":Us(-1,!1),"Meta-ArrowDown":Us(1,!1),"Shift-Meta-ArrowUp":Us(-1,!0),"Shift-Meta-ArrowDown":Us(1,!0)})}function Gs(e){e.offsetWidth}const Ks=new C(`meowdown-virtual-caret`),qs=[`md-virtual-caret-blink`,`md-virtual-caret-blink2`],Js=`data-meowdown-virtual-caret`;function Ys(e){let t=e.height*.19999999999999996;return{left:e.left,top:e.top-t/2,height:e.height+t}}function Xs(e){let t=As(e)??js(e);return t==null?Ms(e):Ys(t)}function Zs(e,t){return e==null||t==null?e===t:e.left===t.left&&e.top===t.top&&e.height===t.height}var Qs=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=qs[this.#s]}#l=()=>{let e=this.#e;if(e.isDestroyed)return;let t=e.state,n=t.selection,r=g(n)&&n.empty?Xs(e):void 0,i=r!=null&&j(t)===`hide`?Di(t,n.head):void 0;if(Zs(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`,e.dom.removeAttribute(Js);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`,e.dom.setAttribute(Js,``),a&&(Gs(this.#n),this.#n.style.transitionProperty=``)}};function $s(){return m(new S({key:Ks,view:e=>new Qs(e)}))}function ec(e){return _(Yn(),Te(),gi(),Oe(),we(),Ho(),Gn(),ms(),oi(),zi(),Bi(),Ha(),Zr(),hi(),vs(),Ws(),Ea(e),ao(),mo(),aa(),qo(),Yt(e.markMode??`focus`),Gr(),$s(),Hs(),Li(),fn({marks:$t.map(e=>({name:e,modes:[`hide`,`focus`,`show`]}))}),a(),i(),c(),Ee(),ke(),De(),pi(),Ds())}function tc(e={}){return ec(e)}const nc=Ce(()=>{let e=tc().schema;if(e==null)throw Error(`Unexpected empty schema`);return e}),rc=Ce(()=>r(nc())),ic=Ce(()=>n(nc())),ac=`meowdown_mark_builders`;function oc(e){let t=e.cached[ac];if(t)return t;let r=n(e);return e.cached[ac]=r,r}const sc=`meowdown_node_builders`;function cc(e){let t=e.cached[sc];if(t)return t;let n=r(e);return e.cached[sc]=n,n}function X(e,t={}){let{nodes:n=rc(),frontmatter:r=!1}=t,i,a=e;if(r){let[t,n]=uc(e);i=t,n&&(a=e.slice(n))}let o=dc(n,ye.parse(a).cursor(),a);return n.doc(i===void 0?{}:{frontmatter:i},o)}const lc=/^---[ \t]*\r?\n([\s\S]*?\n)?---[ \t]*(?:\r?\n|$)/;function uc(e){let t=lc.exec(e);return t?[(t[1]??``).replace(/\r?\n$/,``),t[0].length]:[]}function dc(e,t,n){let r=[];if(!t.firstChild())return r;let i;do i!=null&&fc(r,e,n,i,t.from),i=t.to,r.push(...pc(e,t,n));while(t.nextSibling());return t.parent(),r}function fc(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 pc(e,t,n){switch(t.type.id){case y.ATXHeading1:return[Z(e,t,n,1,!1)];case y.ATXHeading2:return[Z(e,t,n,2,!1)];case y.ATXHeading3:return[Z(e,t,n,3,!1)];case y.ATXHeading4:return[Z(e,t,n,4,!1)];case y.ATXHeading5:return[Z(e,t,n,5,!1)];case y.ATXHeading6:return[Z(e,t,n,6,!1)];case y.SetextHeading1:return[Z(e,t,n,1,!0)];case y.SetextHeading2:return[Z(e,t,n,2,!0)];case y.Paragraph:return[yc(e,t,n)];case y.CommentBlock:return[bc(e,t,n)];case y.HTMLBlock:case y.ProcessingInstructionBlock:return[yc(e,t,n)];case y.Blockquote:return[xc(e,t,n)];case y.BulletList:return Sc(e,t,n,`bullet`);case y.OrderedList:return Sc(e,t,n,`ordered`);case y.FencedCode:case y.CodeBlock:return[wc(e,t,n)];case y.BlockMath:return[Tc(e,t,n)];case y.HorizontalRule:{let r=n.slice(t.from,t.to).trimEnd();return[e.horizontalRule({marker:r===`---`?null:r})]}case y.Table:return[Ec(e,t,n)];case y.Task:return[yc(e,t,n)];default:return n.slice(t.from,t.to).trim()===``?[]:(console.warn(`[meowdown] unsupported lezer block "${t.type.name}"`),[yc(e,t,n)])}}function Z(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===y.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===y.HeaderMark&&n>o&&(s=n,c=n,l=r),t.parent()}let u=_c(n.slice(o,s),Q(n,o)).trim(),d=i?mc(n,c,l)||1:null,f=!i&&c>=0&&hc(n,c,l)||null;return e.heading({level:r,setextUnderline:d,closingHashes:f},u)}function mc(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 hc(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 Q(e,t){let n=e.lastIndexOf(`
|
|
30
|
+
`,t-1)+1,r=0;for(let i=n;i<t;i++)r+=e.charCodeAt(i)===9?4-r%4:1;return r}function gc(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 _c(e,t){return t===0||!e.includes(`
|
|
27
31
|
`)?e:e.split(`
|
|
28
|
-
`).map((e,n)=>n===0?e:
|
|
29
|
-
`)}function
|
|
30
|
-
`).filter(e=>!
|
|
31
|
-
`)}const Wc=new S(`meowdown-embed-paste`);function Gc(e){let t=e.trim();if(!(!t||/\s/.test(t)))return Hc(t)?t:void 0}function Kc(e,t){let{from:n,to:r}=e.state.selection;e.dispatch(Ht(e.state.tr.insertText(t,n,r)));let i=e.state.tr.insertText(``,n,n+t.length);e.dispatch(Ht(i))}function qc(){return m(new x({key:Wc,props:{handlePaste:(e,t,n)=>{let r=e.state.selection.$from.parent;if(!r.inlineContent||r.type.spec.code)return!1;let i=Uc(t,n);if(!i)return!1;let a=Gc(i);return a?(Kc(e,a),!0):!1}}}))}const Jc=new S(`meowdown-exit-boundary`);function Yc(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&&Me.findFrom(a,t))}function Xc(e,t){let{state:n}=e,{selection:r}=n;return g(r)&&!r.empty||ne(r)||r.$from.parent.inlineContent&&!e.endOfTextblock(t<0?`up`:`down`)?!0:Yc(n,t)}function Zc(e){return new x({key:Jc,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||Xc(t,r)||e({direction:r<0?`up`:`down`,event:n})===!1)}}})}function Qc(e){return v(m(Zc(e)),t.low)}const $c=new Set([`avif`,`bmp`,`gif`,`jpeg`,`jpg`,`png`,`svg`,`webp`]);function el(e){if(e.type?.startsWith(`image/`))return!0;let t=e.name.lastIndexOf(`.`);if(t===-1)return!1;let n=e.name.slice(t+1).toLowerCase();return $c.has(n)}function tl(e,t){return el(e)?``:`[${il(e.name)}](${t})`}function nl(e,t){return!e||!t.onFilePaste?[]:Array.from(e.files)}const rl=e=>{console.error(`[meowdown] failed to save pasted file:`,e)};function il(e){return e.replaceAll(/[\\[\]]/g,String.raw`\$&`)}async function al(e,t,n,r){let{onFilePaste:i}=n;if(!i)return;let a=n.onFileSaveError??rl,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=tl(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 ol(e){return new x({key:new S(`file-paste`),props:{handlePaste:(t,n)=>{let r=nl(n.clipboardData,e);return r.length===0?!1:(al(t,r,e),!0)},handleDrop:(t,n)=>{let r=nl(n.dataTransfer,e);return r.length===0?!1:(al(t,r,e,t.posAtCoords({left:n.clientX,top:n.clientY})?.pos),!0)}}})}function sl(e={}){return v(m(ol(e)),t.high)}const cl=new S(`meowdown-file-click`);function ll(e,t){let n=O(e,t,`mdFile`);if(!n)return;let{href:r,name:i}=n.mark.attrs;return{href:r,name:i}}function ul(e){return m(new x({key:cl,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=ll(t.state,t.posAtDOM(a,0));return o?(e({href:o.href,name:o.name,event:r}),!0):!1}}}))}const dl=[`KB`,`MB`,`GB`,`TB`];function fl(e){let t=e,n=`B`;for(let e of dl){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 pl=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 ml(e){let t=e.split(/[?#]/,1)[0],n=t.lastIndexOf(`.`);if(n<0)return`generic`;let r=t.slice(n+1).toLowerCase();return pl.get(r)??`generic`}const hl=`http://www.w3.org/2000/svg`;function gl(){let e=document.createElementNS(hl,`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(hl,`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 _l=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=ml(this.#a.href),this.#n.title=this.#a.name,this.#e.appendChild(this.#n),this.#n.appendChild(gl()),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=fl(n))}};function vl(e={}){return d({name:`mdFile`,constructor:t=>new _l(t,e)})}function yl(e){return m(new x({key:e.key,props:{handleClick:(t,n,r)=>{let i=r.target?.closest?.(e.selector);if(!i)return!1;let a=e.findPayloadForElement?e.findPayloadForElement(t,i):e.findPayloadAt(t.state,n);return a==null?!1:(e.preventDefault&&r.preventDefault(),e.onClick(a,r),!0)}}}))}const bl=new S(`meowdown-tag-click`);function xl(e,t){let n=O(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 Sl(e){return yl({key:bl,selector:`.md-tag`,preventDefault:!1,findPayloadAt:(e,t)=>xl(e,t)?.tag,onClick:(t,n)=>e({tag:t,event:n})})}const Cl=new S(`meowdown-wikilink-click`);function wl(e,t){let n=O(e,t,`mdWikilink`);if(!n)return;let{target:r}=n.mark.attrs;return{from:n.from,to:n.to,target:r}}function Tl(e,t){let n=t.closest(`.md-wikilink-view`)?.querySelector(`.md-wikilink-view-content`);if(n)return wl(e.state,e.posAtDOM(n,0))}function El(e){return yl({key:Cl,selector:`.md-wikilink-view-preview`,preventDefault:!1,findPayloadAt:(e,t)=>wl(e,t)?.target,findPayloadForElement:(e,t)=>Tl(e,t)?.target,onClick:(t,n)=>e({target:t,event:n})})}const Dl=new S(`meowdown-follow-link`);function Ol(e){return e.key!==`Enter`||e.shiftKey||e.altKey?!1:re?e.metaKey&&!e.ctrlKey:e.ctrlKey&&!e.metaKey}function kl(e){return new x({key:Dl,props:{handleKeyDown:(t,n)=>{if(!Ol(n))return!1;let{state:r}=t,i=r.selection.head,a=e.onWikilinkClick&&wl(r,i);if(a)return e.onWikilinkClick?.({target:a.target,event:n}),!0;let o=e.onTagClick&&xl(r,i);if(o)return e.onTagClick?.({tag:o.tag,event:n}),!0;let s=e.onFileClick&&ll(r,i);if(s)return e.onFileClick?.({href:s.href,name:s.name,event:n}),!0;let c=e.onLinkClick&&W(r,i);return c?(e.onLinkClick?.({href:c.href,event:n}),!0):!1}}})}function Al(e){return v(m(kl(e)),t.high)}const jl=new S(`meowdown-image-click`);function Ml(e){return e instanceof HTMLElement&&e.closest(`.md-image-view-preview`)}function Nl(e,t){let n=O(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 Pl(e,t){let n=t.closest(`.md-image-view`)?.querySelector(`.md-image-view-content`);if(n)return Nl(e.state,e.posAtDOM(n,0))}function Fl(e,t){return Array.from(e).find(e=>e.identifier===t)}function Il(e,t){return Math.abs(t.clientX-e.clientX)<=10&&Math.abs(t.clientY-e.clientY)<=10}function Ll(e){let t=new WeakMap;return m(new x({key:jl,props:{handleDOMEvents:{pointerdown:(e,t)=>(Ml(t.target)&&t.pointerType!==`mouse`&&t.preventDefault(),!1),touchstart:(e,n)=>{if(t.delete(e),n.touches.length!==1||!Ml(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=Fl(n.changedTouches,r.identifier);return i&&!Il(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=Fl(r.changedTouches,i.identifier);if(!a||!Il(i,a))return!1;let o=Ml(r.target);if(!o)return!1;r.preventDefault();let s=Pl(n,o);return s&&e({src:s.src,alt:s.alt,event:r}),!0}},handleClick:(t,n,r)=>{let i=Ml(r.target);if(!i)return!1;let a=Pl(t,i);return a?(e({src:a.src,alt:a.alt,event:r}),!0):!1}}}))}function Rl(e){return/^https?:\/\//i.test(e)?e:void 0}function zl(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`&&Fc(t),t}function Bl(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 Vl(e,t,n,r){let i=e.posAtDOM(t,0),a=O(e.state,i,`mdImage`);if(!a)return;let o=e.state.doc.textBetween(a.from,a.to),s=a.mark.attrs;if(s.syntax===`wikiEmbed`){let t=s.wikiTarget||Wi(o).target;if(!t)return;let i=Gi(t,n,r);i!==o&&e.dispatch(e.state.tr.insertText(i,a.from,a.to));return}let c=Vi(o),l=a.from+c.length,u=o.slice(c.length),d=Bi({...Ri(u)??{},width:Math.round(n),height:Math.round(r)});d!==u&&e.dispatch(e.state.tr.insertText(d,l,a.to))}var Hl=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)&&Bl(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=Hc(e);if(t){let e=document.createElement(`span`);return e.className=`md-image-view-preview md-atom-view-preview`,e.appendChild(zl(t)),e}let n=(this.#n.resolveImageUrl??Rl)(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){Wt(),Ut();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,Bl(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)),Bl(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;Vl(this.#r,this.#t,t,n)}),this.#a=t,this.#o=n,t}};function Ul(e={}){return d({name:`mdImage`,constructor:(t,n)=>new Hl(t,n,e)})}const Wl={"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`},Gl=new S(`meowdown-link-click`);function Kl(e){return yl({key:Gl,selector:`.md-link`,preventDefault:!0,findPayloadAt:(e,t)=>W(e,t)?.href,onClick:(t,n)=>e({href:t,event:n})})}function ql(e){let t,n=(t,n)=>e.findPayloadForElement?e.findPayloadForElement(t,n):e.findPayloadAt(t.state,t.posAtDOM(n,0)),r=()=>{t&&(t=void 0,e.onHoverChange(void 0))},i=(i,a)=>{let o=a.target;if(!o||!xe(o))return;let s=o.closest(e.selector);if(!s||!i.dom.contains(s)||s===t?.element)return;r();let c=n(i,s);c!=null&&(t={payload:c,element:s},e.onHoverChange(t))},a=e=>{if(!t)return;let n=e.relatedTarget;n instanceof Node&&t.element.contains(n)||r()};return m(new x({key:e.key,props:{handleDOMEvents:{mouseover:(e,t)=>(i(e,t),!1),mouseout:(e,t)=>(a(t),!1)}},view:()=>({update:i=>{if(!t)return;if(!t.element.isConnected||!i.dom.contains(t.element)){r();return}let a=n(i,t.element);if(a==null||!e.isSamePayload(t.payload,a)){r();return}t={...t,payload:a}},destroy:r})}))}const Jl=new S(`meowdown-link-hover`);function Yl(e){return ql({key:Jl,selector:`.md-link`,findPayloadAt:(e,t)=>W(e,t),isSamePayload:(e,t)=>e.href===t.href&&e.title===t.title,onHoverChange:e})}const Xl=new S(`meowdown-link-paste`);function Zl(e){let t=e.trim();if(!(!t||/\s/.test(t)))return ve(t)}function Ql(){return v(m(new x({key:Xl,props:{handlePaste:(e,t,n)=>{let r=Uc(t,n);if(!r)return!1;let i=Zl(r);return i?si(e,eo({href:i,wrapText:!1})):!1}}})),t.high)}const $l=[[/<-/,`←`],[/(?<!-)->/,`→`],[/\(c\)/,`©`],[/\(r\)/,`®`],[/1\/2/,`½`],[/\+\/-/,`±`],[/!=/,`≠`],[/<</,`«`],[/>>/,`»`],[/(?<!<!)(?<!^(?:-[ \t]*)+)--/,`—`]],$=new S(`meowdown-substitution-undo`);function eu(e,t,n){let r=ee(e.schema,`mdCode`);return e.doc.rangeHasMark(t,n,r)}function tu(e,t,n,r,i){if(eu(e,t,n))return null;let[,a]=r,o=i==null?a:`${a} `,s=e.tr.replaceWith(t,n,e.schema.text(o));return i!=null&&s.setMeta($,{from:t,to:t+o.length,before:i,after:o}),s}function nu(){return _($l.map(e=>nt(new Gt(new RegExp(String.raw`(?:${e[0].source})\s$`),(t,n,r,i)=>tu(t,r,i,e,n[0])))))}function ru(){return m(new x({key:$,state:{init:()=>null,apply:(e,t)=>{let n=e.getMeta($);if(n!==void 0)return n;if(!t)return null;let r=e.mapping.map(t.from),i=e.mapping.map(t.to);return e.selection.empty&&e.selection.from===i&&e.doc.textBetween(r,i)===t.after?{...t,from:r,to:i}:null}}}))}function iu(){return v(l({Backspace:(e,t)=>{let n=$.getState(e);return n?(t?.(e.tr.replaceWith(n.from,n.to,e.schema.text(n.before)).setMeta($,null)),!0):!1}}),t.highest)}function au(){return _(ru(),iu())}function ou(){return _($l.map(e=>et({regex:RegExp(`(?:${e[0].source})$`),handler:({state:t,from:n,to:r})=>tu(t,n,r,e)})))}function su(){return _(nu(),au(),ou())}const cu=new S(`meowdown-wikilink-hover`);function lu(e){return ql({key:cu,selector:`.md-wikilink-view-preview`,findPayloadAt:wl,findPayloadForElement:Tl,isSamePayload:(e,t)=>e.target===t.target,onHoverChange:t=>{e(t?{...t.payload,element:t.element}:void 0)}})}function uu(e,t={}){let n=[];return e.content.forEach(e=>{let r=[];e.descendants(e=>{if(!e.isText||!e.text)return!0;let n=e.marks.map(e=>e.type.name);return n.some(e=>En.has(e))&&!(t.preserveMathSource&&n.includes(`mdMath`))||r.push(e.text),!1}),n.push(r.join(``))}),n.join(`
|
|
32
|
-
`)}function
|
|
32
|
+
`).map((e,n)=>n===0?e:gc(e,t)).join(`
|
|
33
|
+
`)}function vc(e,t,n){return e.paragraph(_c(t,n))}function yc(e,t,n){let r=t.from,i=t.to,a=Q(n,r);if(t.firstChild()){let o=``,s=r;do t.type.id===y.QuoteMark&&(o+=n.slice(s,t.from),s=t.to,b(n.charCodeAt(s))&&(s+=1));while(t.nextSibling());return t.parent(),o+=n.slice(s,i),vc(e,o,a)}return vc(e,n.slice(r,i),a)}function bc(e,t,n){let r=Q(n,t.from),i=_c(n.slice(t.from,t.to),r);return e.htmlComment({content:i})}function xc(e,t,n){let r=[];if(t.firstChild()){let i;do{if(t.type.id===y.QuoteMark)continue;i!=null&&fc(r,e,n,i,t.from),i=t.to,r.push(...pc(e,t,n))}while(t.nextSibling());t.parent()}return e.blockquote(r)}function Sc(e,t,n,r){let i=[];if(t.firstChild()){do t.type.id===y.ListItem&&i.push(Cc(e,t,n,r));while(t.nextSibling());t.parent()}return i}function Cc(e,t,n,r){let i=[],a,o,s,c,l,u;if(t.firstChild()){do{if(t.type.id!==y.ListMark&&u==null&&(u=Q(n,t.from)),t.type.id===y.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=Q(n,t.to);continue}if(r===`bullet`&&t.type.id===y.Task){let r=t.from,s=t.to;if(a=!1,t.firstChild()){if(t.type.id===y.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()}b(n.charCodeAt(r))&&(r+=1);let c=n.slice(r,s);i.push(vc(e,c,Q(n,r)));continue}i.push(...pc(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 wc(e,t,n){let r=t.type.id===y.CodeBlock,i=``,a=``,o=r?`indented`:null,s=null,c=!1;if(t.firstChild()){do switch(t.type.id){case y.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 y.CodeInfo:i=n.slice(t.from,t.to);break;case y.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 Tc(e,t,n){let r=``;if(t.firstChild()){do t.type.id===y.CodeText&&(r+=n.slice(t.from,t.to));while(t.nextSibling());t.parent()}return e.codeBlock({language:`math`,fenceStyle:`dollar`,fenceLength:null},r)}function Ec(e,t,n){let r=[];if(t.firstChild()){do t.type.id===y.TableDelimiter&&(r=Dc(n.slice(t.from,t.to)));while(t.nextSibling());t.parent()}let i=[];if(t.firstChild()){do{let a=t.type.id;a===y.TableHeader?i.push(Oc(e,t,n,!0,r)):a===y.TableRow&&i.push(Oc(e,t,n,!1,r))}while(t.nextSibling());t.parent()}return e.table(i)}function Dc(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 Oc(e,t,n,r,i){let a=i.length,o=Array(a).fill(``);if(t.firstChild()){let e=t.type.id===y.TableDelimiter,r=0;do if(t.type.id===y.TableDelimiter)r++;else if(t.type.id===y.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 kc(e){return e.replace(/\n+$/u,``)}function Ac(e){return/^[\s>]*$/u.test(e)}function jc(e){return e.split(`
|
|
34
|
+
`).filter(e=>!Ac(e))}function Mc(e){return e.trim().replaceAll(/\s+/gu,` `)}const Nc=/^:?-+:?$/u;function Pc(e){let t=e.startsWith(`:`),n=e.endsWith(`:`);return t&&n?`:-:`:t?`:--`:n?`--:`:`---`}function Fc(e){if(!e.includes(`|`))return;let t=/^[\s>]*/u.exec(e)?.[0]??``,n=e.slice(t.length).trim().replace(/^\|/u,``).replace(/\|$/u,``).split(`|`).map(e=>Mc(e));return Mc(`${t} | ${(n.every(e=>Nc.test(e))?n.map(Pc):n).join(` | `)} |`)}function Ic(e){return Fc(e)??Mc(e)}function Lc(e,t={}){let n=gr(X(e,{frontmatter:t.frontmatter}),{frontmatter:t.frontmatter});if(kc(n)===kc(e))return`exact`;let r=jc(e),i=jc(n);return r.length===i.length&&r.every((e,t)=>Ic(e)===Ic(i[t]))?`normalizing`:`lossy`}const Rc=(e,t)=>{let{$from:n,empty:r}=e.selection;if(!r||n.depth!==1||n.index(0)!==0||!I(n.parent,`heading`)||n.parentOffset!==n.parent.content.size)return!1;if(t){let r=te(e.schema,`list`),i=te(e.schema,`paragraph`),a=r.create({kind:`bullet`},i.create()),o=n.after(),s=e.tr.insert(o,a);s.setSelection(w.create(s.doc,o+2)),t(s.scrollIntoView())}return!0};function zc(){return v(l({Enter:Rc}),t.high)}const Bc=new Set([`MscGen`,`Xù`,`MsGenny`,`Angular Template`,`Brainfuck`,`Esper`,`Oz`,`Factor`,`Squirrel`,`Yacas`,`mIRC`,`FCL`,`ECL`,`MUMPS`,`Pig`,`Asterisk`,`Z80`,`Mathematica`]),Vc=Xe.map(e=>({label:e.name,value:e.name.toLowerCase()})).filter(e=>!Bc.has(e.label)).concat([{label:`Plain text`,value:``},{label:`Math`,value:`math`},{label:`Mermaid`,value:`mermaid`}]).sort((e,t)=>e.label.localeCompare(t.label));function Hc(){return typeof window>`u`?!1:window.matchMedia(`(prefers-color-scheme: dark)`).matches}const Uc=/^(?:www\.|mobile\.)?(?:twitter\.com|x\.com)$/i,Wc=/\/status(?:es)?\/(\d+)/;function Gc(e){let t;try{t=new URL(e)}catch{return}if(Uc.test(t.hostname))return Wc.exec(t.pathname)?.[1]}const Kc=e=>{let t=Gc(e);if(!t)return;let n=Hc()?`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 qc(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 Jc=/^(?:www\.|m\.)?(?:youtube\.com|youtube-nocookie\.com)$/i,Yc=/^(?:www\.)?youtu\.be$/i,Xc=/^[\w-]{11}$/;function Zc(e){let t;try{t=new URL(e)}catch{return}let n=null;if(Yc.test(t.hostname))n=t.pathname.slice(1);else if(Jc.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||!Xc.test(n))return;let r=t.searchParams.get(`start`)??t.searchParams.get(`t`),i=r?Qc(r):void 0;return{videoId:n,startSeconds:i}}function Qc(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 $c=[e=>{let t=Zc(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}},Kc];function el(e){for(let t of $c){let n=t(e);if(n)return n}}function tl(e,t){return e.clipboardData?.getData(`text/plain`)||t.content.textBetween(0,t.content.size,`
|
|
35
|
+
`)}const nl=new C(`meowdown-embed-paste`);function rl(e){let t=e.trim();if(!(!t||/\s/.test(t)))return el(t)?t:void 0}function il(e,t){let{from:n,to:r}=e.state.selection;e.dispatch(Ht(e.state.tr.insertText(t,n,r)));let i=e.state.tr.insertText(``,n,n+t.length);e.dispatch(Ht(i))}function al(){return m(new S({key:nl,props:{handlePaste:(e,t,n)=>{let r=e.state.selection.$from.parent;if(!r.inlineContent||r.type.spec.code)return!1;let i=tl(t,n);if(!i)return!1;let a=rl(i);return a?(il(e,a),!0):!1}}}))}const ol=new C(`meowdown-exit-boundary`);function sl(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&&je.findFrom(a,t))}function cl(e,t){let{state:n}=e,{selection:r}=n;return g(r)&&!r.empty||ne(r)||r.$from.parent.inlineContent&&!e.endOfTextblock(t<0?`up`:`down`)?!0:sl(n,t)}function ll(e){return new S({key:ol,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||cl(t,r)||e({direction:r<0?`up`:`down`,event:n})===!1)}}})}function ul(e){return v(m(ll(e)),t.low)}const dl=new Set([`avif`,`bmp`,`gif`,`jpeg`,`jpg`,`png`,`svg`,`webp`]);function fl(e){if(e.type?.startsWith(`image/`))return!0;let t=e.name.lastIndexOf(`.`);if(t===-1)return!1;let n=e.name.slice(t+1).toLowerCase();return dl.has(n)}function pl(e,t){return fl(e)?``:`[${gl(e.name)}](${t})`}function ml(e,t){return!e||!t.onFilePaste?[]:Array.from(e.files)}const hl=e=>{console.error(`[meowdown] failed to save pasted file:`,e)};function gl(e){return e.replaceAll(/[\\[\]]/g,String.raw`\$&`)}async function _l(e,t,n,r){let{onFilePaste:i}=n;if(!i)return;let a=n.onFileSaveError??hl,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=pl(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 vl(e){return new S({key:new C(`file-paste`),props:{handlePaste:(t,n)=>{let r=ml(n.clipboardData,e);return r.length===0?!1:(_l(t,r,e),!0)},handleDrop:(t,n)=>{let r=ml(n.dataTransfer,e);return r.length===0?!1:(_l(t,r,e,t.posAtCoords({left:n.clientX,top:n.clientY})?.pos),!0)}}})}function yl(e={}){return v(m(vl(e)),t.high)}const bl=new C(`meowdown-file-click`);function xl(e,t){let n=k(e,t,`mdFile`);if(!n)return;let{href:r,name:i}=n.mark.attrs;return{href:r,name:i}}function Sl(e){return m(new S({key:bl,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=xl(t.state,t.posAtDOM(a,0));return o?(e({href:o.href,name:o.name,event:r}),!0):!1}}}))}const Cl=[`KB`,`MB`,`GB`,`TB`];function wl(e){let t=e,n=`B`;for(let e of Cl){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 Tl=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 El(e){let t=e.split(/[?#]/,1)[0],n=t.lastIndexOf(`.`);if(n<0)return`generic`;let r=t.slice(n+1).toLowerCase();return Tl.get(r)??`generic`}const Dl=`http://www.w3.org/2000/svg`;function Ol(){let e=document.createElementNS(Dl,`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(Dl,`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 kl=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=El(this.#a.href),this.#n.title=this.#a.name,this.#e.appendChild(this.#n),this.#n.appendChild(Ol()),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=wl(n))}};function Al(e={}){return d({name:`mdFile`,constructor:t=>new kl(t,e)})}function jl(e){return m(new S({key:e.key,props:{handleClick:(t,n,r)=>{let i=r.target?.closest?.(e.selector);if(!i)return!1;let a=e.findPayloadForElement?e.findPayloadForElement(t,i):e.findPayloadAt(t.state,n);return a==null?!1:(e.preventDefault&&r.preventDefault(),e.onClick(a,r),!0)}}}))}const Ml=new C(`meowdown-tag-click`);function Nl(e,t){let n=k(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 Pl(e){return jl({key:Ml,selector:`.md-tag`,preventDefault:!1,findPayloadAt:(e,t)=>Nl(e,t)?.tag,onClick:(t,n)=>e({tag:t,event:n})})}const Fl=new C(`meowdown-wikilink-click`);function Il(e,t){let n=k(e,t,`mdWikilink`);if(!n)return;let{target:r}=n.mark.attrs;return{from:n.from,to:n.to,target:r}}function Ll(e,t){let n=t.closest(`.md-wikilink-view`)?.querySelector(`.md-wikilink-view-content`);if(n)return Il(e.state,e.posAtDOM(n,0))}function Rl(e){return jl({key:Fl,selector:`.md-wikilink-view-preview`,preventDefault:!1,findPayloadAt:(e,t)=>Il(e,t)?.target,findPayloadForElement:(e,t)=>Ll(e,t)?.target,onClick:(t,n)=>e({target:t,event:n})})}const zl=new C(`meowdown-follow-link`);function Bl(e){return e.key!==`Enter`||e.shiftKey||e.altKey?!1:re?e.metaKey&&!e.ctrlKey:e.ctrlKey&&!e.metaKey}function Vl(e){return new S({key:zl,props:{handleKeyDown:(t,n)=>{if(!Bl(n))return!1;let{state:r}=t,i=r.selection.head,a=e.onWikilinkClick&&Il(r,i);if(a)return e.onWikilinkClick?.({target:a.target,event:n}),!0;let o=e.onTagClick&&Nl(r,i);if(o)return e.onTagClick?.({tag:o.tag,event:n}),!0;let s=e.onFileClick&&xl(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 Hl(e){return v(m(Vl(e)),t.high)}const Ul=new C(`meowdown-image-click`);function Wl(e){return e instanceof HTMLElement&&e.closest(`.md-image-view-preview`)}function Gl(e,t){let n=k(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 Kl(e,t){let n=t.closest(`.md-image-view`)?.querySelector(`.md-image-view-content`);if(n)return Gl(e.state,e.posAtDOM(n,0))}function ql(e,t){return Array.from(e).find(e=>e.identifier===t)}function Jl(e,t){return Math.abs(t.clientX-e.clientX)<=10&&Math.abs(t.clientY-e.clientY)<=10}function Yl(e){let t=new WeakMap;return m(new S({key:Ul,props:{handleDOMEvents:{pointerdown:(e,t)=>(Wl(t.target)&&t.pointerType!==`mouse`&&t.preventDefault(),!1),touchstart:(e,n)=>{if(t.delete(e),n.touches.length!==1||!Wl(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=ql(n.changedTouches,r.identifier);return i&&!Jl(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=ql(r.changedTouches,i.identifier);if(!a||!Jl(i,a))return!1;let o=Wl(r.target);if(!o)return!1;r.preventDefault();let s=Kl(n,o);return s&&e({src:s.src,alt:s.alt,event:r}),!0}},handleClick:(t,n,r)=>{let i=Wl(r.target);if(!i)return!1;let a=Kl(t,i);return a?(e({src:a.src,alt:a.alt,event:r}),!0):!1}}}))}function Xl(e){return/^https?:\/\//i.test(e)?e:void 0}function Zl(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`&&qc(t),t}function Ql(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 $l(e,t,n,r){let i=e.posAtDOM(t,0),a=k(e.state,i,`mdImage`);if(!a)return;let o=e.state.doc.textBetween(a.from,a.to),s=a.mark.attrs;if(s.syntax===`wikiEmbed`){let t=s.wikiTarget||ea(o).target;if(!t)return;let i=ta(t,n,r);i!==o&&e.dispatch(e.state.tr.insertText(i,a.from,a.to));return}let c=Zi(o),l=a.from+c.length,u=o.slice(c.length),d=Xi({...Ji(u)??{},width:Math.round(n),height:Math.round(r)});d!==u&&e.dispatch(e.state.tr.insertText(d,l,a.to))}var eu=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)&&Ql(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=el(e);if(t){let e=document.createElement(`span`);return e.className=`md-image-view-preview md-atom-view-preview`,e.appendChild(Zl(t)),e}let n=(this.#n.resolveImageUrl??Xl)(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){Wt(),Ut();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,Ql(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)),Ql(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;$l(this.#r,this.#t,t,n)}),this.#a=t,this.#o=n,t}};function tu(e={}){return d({name:`mdImage`,constructor:(t,n)=>new eu(t,n,e)})}const nu={"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`},ru=new C(`meowdown-link-click`);function iu(e){return jl({key:ru,selector:`.md-link`,preventDefault:!0,findPayloadAt:(e,t)=>G(e,t)?.href,onClick:(t,n)=>e({href:t,event:n})})}function au(e){let t,n=(t,n)=>e.findPayloadForElement?e.findPayloadForElement(t,n):e.findPayloadAt(t.state,t.posAtDOM(n,0)),r=()=>{t&&(t=void 0,e.onHoverChange(void 0))},i=(i,a)=>{let o=a.target;if(!o||!be(o))return;let s=o.closest(e.selector);if(!s||!i.dom.contains(s)||s===t?.element)return;r();let c=n(i,s);c!=null&&(t={payload:c,element:s},e.onHoverChange(t))},a=e=>{if(!t)return;let n=e.relatedTarget;n instanceof Node&&t.element.contains(n)||r()};return m(new S({key:e.key,props:{handleDOMEvents:{mouseover:(e,t)=>(i(e,t),!1),mouseout:(e,t)=>(a(t),!1)}},view:()=>({update:i=>{if(!t)return;if(!t.element.isConnected||!i.dom.contains(t.element)){r();return}let a=n(i,t.element);if(a==null||!e.isSamePayload(t.payload,a)){r();return}t={...t,payload:a}},destroy:r})}))}const ou=new C(`meowdown-link-hover`);function su(e){return au({key:ou,selector:`.md-link`,findPayloadAt:(e,t)=>G(e,t),isSamePayload:(e,t)=>e.href===t.href&&e.title===t.title,onHoverChange:e})}const cu=new C(`meowdown-link-paste`);function lu(e){let t=e.trim();if(!(!t||/\s/.test(t)))return ve(t)}function uu(){return v(m(new S({key:cu,props:{handlePaste:(e,t,n)=>{let r=tl(t,n);if(!r)return!1;let i=lu(r);return i?_i(e,uo({href:i,wrapText:!1})):!1}}})),t.high)}const du=[[/<-/,`←`],[/(?<!-)->/,`→`],[/\(c\)/,`©`],[/\(r\)/,`®`],[/1\/2/,`½`],[/\+\/-/,`±`],[/!=/,`≠`],[/<</,`«`],[/>>/,`»`],[/(?<!<!)(?<!^(?:-[ \t]*)+)--/,`—`]],$=new C(`meowdown-substitution-undo`);function fu(e,t,n){let r=ee(e.schema,`mdCode`);return e.doc.rangeHasMark(t,n,r)}function pu(e,t,n,r,i){if(fu(e,t,n))return null;let[,a]=r,o=i==null?a:`${a} `,s=e.tr.replaceWith(t,n,e.schema.text(o));return i!=null&&s.setMeta($,{from:t,to:t+o.length,before:i,after:o}),s}function mu(){return _(du.map(e=>nt(new Gt(new RegExp(String.raw`(?:${e[0].source})\s$`),(t,n,r,i)=>pu(t,r,i,e,n[0])))))}function hu(){return m(new S({key:$,state:{init:()=>null,apply:(e,t)=>{let n=e.getMeta($);if(n!==void 0)return n;if(!t)return null;let r=e.mapping.map(t.from),i=e.mapping.map(t.to);return e.selection.empty&&e.selection.from===i&&e.doc.textBetween(r,i)===t.after?{...t,from:r,to:i}:null}}}))}function gu(){return v(l({Backspace:(e,t)=>{let n=$.getState(e);return n?(t?.(e.tr.replaceWith(n.from,n.to,e.schema.text(n.before)).setMeta($,null)),!0):!1}}),t.highest)}function _u(){return _(hu(),gu())}function vu(){return _(du.map(e=>et({regex:RegExp(`(?:${e[0].source})$`),handler:({state:t,from:n,to:r})=>pu(t,n,r,e)})))}function yu(){return _(mu(),_u(),vu())}const bu=new C(`meowdown-wikilink-hover`);function xu(e){return au({key:bu,selector:`.md-wikilink-view-preview`,findPayloadAt:Il,findPayloadForElement:Ll,isSamePayload:(e,t)=>e.target===t.target,onHoverChange:t=>{e(t?{...t.payload,element:t.element}:void 0)}})}function Su(e,t={}){let n=[];return e.content.forEach(e=>{let r=[];e.descendants(e=>{if(!e.isText||!e.text)return!0;let n=e.marks.map(e=>e.type.name);return n.some(e=>En.has(e))&&!(t.preserveMathSource&&n.includes(`mdMath`))||r.push(e.text),!1}),n.push(r.join(``))}),n.join(`
|
|
36
|
+
`)}function Cu({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=Su(r.content());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(w.create(e.doc,r.from+a.length)),it(e),n(e.scrollIntoView())}return!0}}function wu(){return l({"Mod-Shift-k":Cu({allowEmpty:!0}),"[":Cu({allowEmpty:!1})})}function Tu(e){switch(e.type.name){case`mdWikilink`:{let t=e.attrs;return t.display||t.target}case`mdImage`:return e.attrs.alt;case`mdFile`:return e.attrs.name;case`mdMath`:return e.attrs.formula;default:return``}}function Eu(e){let t=``;for(let n of An(e)){if(n.atom!=null){t+=Tu(n.atom);continue}for(let e of n.children)kn(e.marks)||(t+=e.text??``)}return t}function Du(e){let{selection:t,schema:n}=e;if(t.empty)return``;let r=t.content().content;try{return gr(n.topNodeType.create(null,r)).replace(/\n+$/,``)}catch{return e.doc.textBetween(t.from,t.to,`
|
|
33
37
|
|
|
34
|
-
`)}}function
|
|
38
|
+
`)}}function Ou(e,t,n){if(n===1){let r=V(e.state,t);return r&&J(e,r.to,n)}else{let n=B(e.state,t);return n&&J(e,n.from,-1)}}function ku(e,t){let n=new DOMRect(0,0,0,0),r=()=>{if(e.isDestroyed)return n;let r=J(e,t.from,1)??Ns(e,t.from,1)??Ou(e,t.from,1)??J(e,t.from,-1);if(r==null)return n;let i=J(e,t.to,-1)??Ns(e,t.to,-1)??Ou(e,t.to,-1)??J(e,t.to,1);if(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 Au(e){return e instanceof ht||e instanceof gt||e instanceof _t||e instanceof vt||e instanceof Wi}function ju(e){for(let t of e)for(let e of t.steps)if(!Au(e))return!0;return!1}function Mu(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){ju(e)&&o()},view(e){return t=e,{destroy(){t=void 0}}}}}function Nu(e){let t=new C(`spell-check`);return new S({key:t,state:{init:()=>Mu(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 Pu(e){return m(Nu(e))}export{nu as EDITOR_KEY_BINDINGS,e as Priority,pl as buildFileMarkdown,Lc as checkRoundTrip,Vc as codeBlockLanguages,Xl as defaultResolveImageUrl,zc as defineBulletAfterHeading,pe as defineCodeBlockPreviewPlugin,Zr as defineCodeBlockSyntaxHighlight,tc as defineEditorExtension,al as defineEmbedPaste,ul as defineExitBoundaryHandler,Sl as defineFileClickHandler,yl as defineFilePaste,Al as defineFileView,Hl as defineFollowLinkHandler,Bi as defineHTMLComment,tu as defineImage,Yl as defineImageClickHandler,iu as defineLinkClickHandler,mo as defineLinkCommands,go as defineLinkEditKeymap,su as defineLinkHoverHandler,uu as defineLinkPaste,qo as defineMath,Os as definePendingReplacementHandler,he as definePlaceholder,ge as defineReadonly,Pu as defineSpellCheckPlugin,yu as defineSubstitution,Pl as defineTagClickHandler,Rl as defineWikilinkClickHandler,xu as defineWikilinkHoverHandler,wu as defineWikilinkTrigger,gr as docToMarkdown,wl as formatFileSize,ta as formatSizedWikiEmbed,$r as getCodeTokens,El as getFileKind,G as getLinkUnitAt,ic as getMarkBuilders,q as getPendingReplacement,Du as getSelectedText,os as getTableColumnAlign,Eu as getTextblockDisplayText,ku as getVirtualElementFromRange,sa as inlineTextToMarkChunks,uo as insertLink,me as isCodeBlockPreviewHiddenDecoration,Tn as isMarkOfType,I as isNodeOfType,ls as isSelectionInTableCell,qc as listenForTweetHeight,Wo as loadKaTeX,X as markdownToDoc,el as matchEmbed,ea as parseWikiEmbed,po as removeLink,Go as renderMathInto,fo as updateLink,na as wikiEmbedBasename,le as withPriority};
|
package/dist/style.css
CHANGED
|
@@ -207,11 +207,14 @@
|
|
|
207
207
|
.ProseMirror {
|
|
208
208
|
box-sizing: border-box;
|
|
209
209
|
color: var(--meowdown-text);
|
|
210
|
-
caret-color: #0000;
|
|
211
210
|
-webkit-font-smoothing: antialiased;
|
|
212
211
|
outline: none;
|
|
213
212
|
font-size: 1.0625rem;
|
|
214
213
|
line-height: 1.7;
|
|
214
|
+
|
|
215
|
+
&[data-meowdown-virtual-caret] {
|
|
216
|
+
caret-color: #0000;
|
|
217
|
+
}
|
|
215
218
|
}
|
|
216
219
|
|
|
217
220
|
.md-virtual-caret-layer {
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@meowdown/core",
|
|
3
3
|
"type": "module",
|
|
4
|
-
"version": "0.57.
|
|
4
|
+
"version": "0.57.2",
|
|
5
5
|
"license": "MIT",
|
|
6
6
|
"repository": {
|
|
7
7
|
"type": "git",
|
|
@@ -39,8 +39,9 @@
|
|
|
39
39
|
"rehype-remark": "^10.0.1",
|
|
40
40
|
"remark-gfm": "^4.0.1",
|
|
41
41
|
"remark-stringify": "^11.0.0",
|
|
42
|
+
"unicode-by-name": "^0.2.0",
|
|
42
43
|
"unified": "^11.0.5",
|
|
43
|
-
"@meowdown/markdown": "^0.57.
|
|
44
|
+
"@meowdown/markdown": "^0.57.2"
|
|
44
45
|
},
|
|
45
46
|
"devDependencies": {
|
|
46
47
|
"@ocavue/tsconfig": "^0.7.1",
|
|
@@ -51,7 +52,6 @@
|
|
|
51
52
|
"dedent": "^1.7.2",
|
|
52
53
|
"diffable-html-snapshot": "^0.3.0",
|
|
53
54
|
"tsdown": "^0.22.8",
|
|
54
|
-
"unicode-by-name": "^0.2.0",
|
|
55
55
|
"vitest": "^4.1.10",
|
|
56
56
|
"@meowdown/vitest": "0.0.0"
|
|
57
57
|
},
|