@meowdown/core 0.46.0 → 0.47.0

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 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
- Pasting rich-text HTML from a browser (a bullet list, **bold**, a link, ...) converts it to Markdown so the formatting survives instead of arriving as plain text: [`defineHTMLPaste`](https://npmx.dev/package-docs/@meowdown%2Fcore#function-defineHTMLPaste) rewrites the clipboard's `text/html` through the unified (rehype / remark) pipeline; meowdown's own clipboard (tagged `data-pm-slice`) and any paste landing in a code block are left to the default path. Going the other way, [`defineMarkdownCopy`](https://npmx.dev/package-docs/@meowdown%2Fcore#function-defineMarkdownCopy) serializes copied content to Markdown for the clipboard's `text/plain` flavor. Neither is part of `defineEditorExtension`; `@meowdown/react` applies both by default, a headless host adds them explicitly.
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 block markers always survive and 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.d.ts CHANGED
@@ -398,11 +398,11 @@ options?: FileLinkOptions): MarkChunk[];
398
398
  //#endregion
399
399
  //#region src/extensions/mark-mode.d.ts
400
400
  /**
401
- * Controls how markdown syntax characters are rendered and how the
402
- * editor serializes content to the clipboard.
401
+ * Controls how markdown syntax characters are rendered and how the clipboard's
402
+ * `text/plain` treats the inline layer (see `definePlainTextSerializer`).
403
403
  *
404
- * - 'hide': syntax chars never visible; copy strips them.
405
- * - 'focus': syntax chars hidden by default; revealed near cursor; copy strips them.
404
+ * - 'hide': syntax chars never visible; copy strips the inline syntax.
405
+ * - 'focus': syntax chars hidden by default; revealed near cursor; copy keeps them.
406
406
  * - 'show': syntax chars always visible (dim grey); copy keeps them.
407
407
  */
408
408
  type MarkMode = 'hide' | 'focus' | 'show';
@@ -572,7 +572,7 @@ declare function defineEditorExtensionImpl(options: EditorExtensionOptions): imp
572
572
  Commands: {
573
573
  setMarkMode: [mode: MarkMode];
574
574
  };
575
- }>]>, import("@prosekit/core").PlainExtension, import("@prosekit/core").PlainExtension, import("@prosekit/core").PlainExtension, import("@prosekit/core").PlainExtension, import("@prosekit/core").PlainExtension, import("@prosekit/core").BaseCommandsExtension, import("@prosekit/core").HistoryExtension, import("@prosekit/core").PlainExtension, import("@prosekit/core").PlainExtension, import("@prosekit/core").PlainExtension, import("@prosekit/core").Extension<{
575
+ }>]>, import("@prosekit/core").PlainExtension, import("@prosekit/core").PlainExtension, import("@prosekit/core").PlainExtension, import("@prosekit/core").PlainExtension, import("@prosekit/core").PlainExtension, import("@prosekit/core").PlainExtension, import("@prosekit/core").BaseCommandsExtension, import("@prosekit/core").HistoryExtension, import("@prosekit/core").PlainExtension, import("@prosekit/core").PlainExtension, import("@prosekit/core").PlainExtension, import("@prosekit/core").Extension<{
576
576
  Commands: {
577
577
  insertMarkdown: [markdown: string];
578
578
  insertTrigger: [text: string];
@@ -702,7 +702,7 @@ declare const codeBlockLanguages: ReadonlyArray<LanguageItem>;
702
702
  */
703
703
  declare function defineEmbedPaste(): PlainExtension;
704
704
  //#endregion
705
- //#region src/extensions/embed/types.d.ts
705
+ //#region src/extensions/embed-types.d.ts
706
706
  /**
707
707
  * A framework-agnostic description of an embed iframe. Both the editor's DOM
708
708
  * mark view and the static React renderer build their own `<iframe>` from it, so
@@ -730,7 +730,7 @@ interface EmbedDescriptor {
730
730
  readonly allowFullscreen?: boolean;
731
731
  }
732
732
  //#endregion
733
- //#region src/extensions/embed/tweet.d.ts
733
+ //#region src/extensions/tweet.d.ts
734
734
  /**
735
735
  * `Tweet.html` reports its rendered height via `postMessage`; size the iframe to
736
736
  * fit. Returns a cleanup that removes the listener. The cleanup also runs once
@@ -739,7 +739,7 @@ interface EmbedDescriptor {
739
739
  */
740
740
  declare function listenForTweetHeight(iframe: HTMLIFrameElement): () => void;
741
741
  //#endregion
742
- //#region src/extensions/embed/index.d.ts
742
+ //#region src/extensions/embed.d.ts
743
743
  /** Detect a tweet/YouTube embed in an image `src`, or `undefined` for a plain image. */
744
744
  declare function matchEmbed(src: string): EmbedDescriptor | undefined;
745
745
  //#endregion
@@ -896,17 +896,6 @@ interface FollowLinkHandlers {
896
896
  */
897
897
  declare function defineFollowLinkHandler(handlers: FollowLinkHandlers): PlainExtension;
898
898
  //#endregion
899
- //#region src/extensions/html-paste.d.ts
900
- /**
901
- * Paste foreign rich-text HTML as meowdown Markdown. Rewrites the clipboard's
902
- * `text/html` through `transformPastedHTML`: foreign HTML is converted to a
903
- * Markdown string, reparsed into meowdown nodes (literal source text, no marks),
904
- * and re-serialized to HTML so ProseMirror's own clipboard parser inserts it with
905
- * the right open depths. `<strong>bold</strong>` thus lands as the text `**bold**`,
906
- * which the inline-mark plugin renders.
907
- */
908
- declare function defineHTMLPaste(): PlainExtension;
909
- //#endregion
910
899
  //#region src/extensions/image-click.d.ts
911
900
  /** Payload for {@link ImageClickHandler}. */
912
901
  interface ImageClickPayload {
@@ -1029,18 +1018,6 @@ declare function defineLinkPaste(): PlainExtension;
1029
1018
  declare const MARK_NAMES: readonly ["mdWikilink", "mdImage", "mdFile", "mdMath", "mdMark", "mdEm", "mdStrong", "mdCode", "mdLinkText", "mdLinkUri", "mdLinkTitle", "mdDel", "mdHighlight", "mdTag", "mdPack"];
1030
1019
  type MarkName = (typeof MARK_NAMES)[number];
1031
1020
  //#endregion
1032
- //#region src/extensions/markdown-copy.d.ts
1033
- /**
1034
- * Serialize copied/cut content to Markdown for the clipboard's `text/plain`, so
1035
- * pasting meowdown content into a plain-text field yields real Markdown (`- `
1036
- * list markers, blank-line block separation) instead of bare `textContent`.
1037
- *
1038
- * The copied fragment is wrapped in a `doc` so the existing block serializer can
1039
- * walk it. A purely inline fragment (a partial-paragraph copy) does not fit
1040
- * `doc`'s `block+` content, so it falls back to the inline text.
1041
- */
1042
- declare function defineMarkdownCopy(): PlainExtension;
1043
- //#endregion
1044
1021
  //#region src/extensions/node-names.d.ts
1045
1022
  /**
1046
1023
  * Every ProseMirror node name the editor schema knows about.
@@ -1102,4 +1079,4 @@ declare function getVirtualElementFromRange(view: EditorView, range: PositionRan
1102
1079
  //#region src/extensions/spell-check.d.ts
1103
1080
  declare function defineSpellCheckPlugin(spellCheck: boolean): import("@prosekit/core").PlainExtension;
1104
1081
  //#endregion
1105
- export { type AcceptPendingReplacementOptions, type CheckRoundTripOptions, type CodeBlockAttrs, type CodeBlockFenceStyle, type CodeToken, type DocToMarkdownOptions, EDITOR_KEY_BINDINGS, type EditorExtension, type EditorExtensionOptions, type EmbedDescriptor, type ExitBoundaryHandler, type ExitBoundaryOptions, type FileClickHandler, type FileClickPayload, type FileInfo, type FileInfoResolver, type FileLinkOptions, type FileLinkPayload, type FileLinkResolver, type FilePasteHandler, type FilePasteOptions, type FileSaveErrorHandler, type FileViewOptions, type FollowLinkHandlers, type ImageClickHandler, type ImageClickPayload, type ImageOptions, type KaTeXRender, type LanguageItem, type LinkAttrs, type LinkClickHandler, type LinkClickPayload, type LinkCopyHandler, type LinkCopyPayload, type LinkEditHandler, type LinkEditOptions, type LinkHoverHandler, type LinkUnit, type ListMarker, type MarkChunk, type MarkMode, type MarkName, type MarkdownToDocOptions, type MdFileAttrs, type MdImageAttrs, type MdLinkTextAttrs, type MdMathAttrs, type MdWikilinkAttrs, type MeowdownCodeBlockAttrs, type MeowdownHTMLCommentAttrs, type MeowdownListAttrs, type MeowdownTableCellAttrs, type NodeName, type PendingReplacement, type PendingReplacementEvent, type PendingReplacementHandler, type PendingReplacementMode, type PendingReplacementOutcome, type PlaceholderOptions, type PositionRange, Priority, type RoundTripFidelity, type StartPendingReplacementOptions, type TableColumnAlign, type TagClickHandler, type TagClickPayload, type TypedEditor, type TypedMarkBuilders, type VirtualElement, type WikilinkClickHandler, type WikilinkClickPayload, type WikilinkHoverHandler, type WikilinkHoverHit, buildFileMarkdown, checkRoundTrip, codeBlockLanguages, defaultResolveImageUrl, defineBulletAfterHeading, defineCodeBlockPreviewPlugin, defineCodeBlockSyntaxHighlight, defineEditorExtension, defineEmbedPaste, defineExitBoundaryHandler, defineFileClickHandler, defineFilePaste, defineFileView, defineFollowLinkHandler, defineHTMLComment, defineHTMLPaste, defineImage, defineImageClickHandler, defineLinkClickHandler, defineLinkCommands, defineLinkEditKeymap, defineLinkHoverHandler, defineLinkPaste, defineMarkdownCopy, defineMath, definePendingReplacementHandler, definePlaceholder, defineReadonly, defineSpellCheckPlugin, defineTagClickHandler, defineWikilinkClickHandler, defineWikilinkHoverHandler, defineWikilinkTrigger, docToMarkdown, getCodeTokens, getLinkUnitAt, getMarkBuilders, getPendingReplacement, getSelectedText, getTableColumnAlign, getVirtualElementFromRange, inlineTextToMarkChunks, insertLink, isCodeBlockPreviewHiddenDecoration, isSelectionInTableCell, listenForTweetHeight, loadKaTeX, markdownToDoc, matchEmbed, removeLink, renderMathInto, updateLink, withPriority };
1082
+ export { type AcceptPendingReplacementOptions, type CheckRoundTripOptions, type CodeBlockAttrs, type CodeBlockFenceStyle, type CodeToken, type DocToMarkdownOptions, EDITOR_KEY_BINDINGS, type EditorExtension, type EditorExtensionOptions, type EmbedDescriptor, type ExitBoundaryHandler, type ExitBoundaryOptions, type FileClickHandler, type FileClickPayload, type FileInfo, type FileInfoResolver, type FileLinkOptions, type FileLinkPayload, type FileLinkResolver, type FilePasteHandler, type FilePasteOptions, type FileSaveErrorHandler, type FileViewOptions, type FollowLinkHandlers, type ImageClickHandler, type ImageClickPayload, type ImageOptions, type KaTeXRender, type LanguageItem, type LinkAttrs, type LinkClickHandler, type LinkClickPayload, type LinkCopyHandler, type LinkCopyPayload, type LinkEditHandler, type LinkEditOptions, type LinkHoverHandler, type LinkUnit, type ListMarker, type MarkChunk, type MarkMode, type MarkName, type MarkdownToDocOptions, type MdFileAttrs, type MdImageAttrs, type MdLinkTextAttrs, type MdMathAttrs, type MdWikilinkAttrs, type MeowdownCodeBlockAttrs, type MeowdownHTMLCommentAttrs, type MeowdownListAttrs, type MeowdownTableCellAttrs, type NodeName, type PendingReplacement, type PendingReplacementEvent, type PendingReplacementHandler, type PendingReplacementMode, type PendingReplacementOutcome, type PlaceholderOptions, type PositionRange, Priority, type RoundTripFidelity, type StartPendingReplacementOptions, type TableColumnAlign, type TagClickHandler, type TagClickPayload, type TypedEditor, type TypedMarkBuilders, type VirtualElement, type WikilinkClickHandler, type WikilinkClickPayload, type WikilinkHoverHandler, type WikilinkHoverHit, buildFileMarkdown, checkRoundTrip, codeBlockLanguages, defaultResolveImageUrl, defineBulletAfterHeading, defineCodeBlockPreviewPlugin, defineCodeBlockSyntaxHighlight, defineEditorExtension, defineEmbedPaste, defineExitBoundaryHandler, defineFileClickHandler, defineFilePaste, defineFileView, defineFollowLinkHandler, defineHTMLComment, defineImage, defineImageClickHandler, defineLinkClickHandler, defineLinkCommands, defineLinkEditKeymap, defineLinkHoverHandler, defineLinkPaste, defineMath, definePendingReplacementHandler, definePlaceholder, defineReadonly, defineSpellCheckPlugin, defineTagClickHandler, defineWikilinkClickHandler, defineWikilinkHoverHandler, defineWikilinkTrigger, docToMarkdown, getCodeTokens, getLinkUnitAt, getMarkBuilders, getPendingReplacement, getSelectedText, getTableColumnAlign, getVirtualElementFromRange, inlineTextToMarkChunks, insertLink, isCodeBlockPreviewHiddenDecoration, isSelectionInTableCell, listenForTweetHeight, loadKaTeX, markdownToDoc, matchEmbed, removeLink, renderMathInto, updateLink, withPriority };
package/dist/index.js CHANGED
@@ -1,32 +1,34 @@
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 ee,getMarkType as te,getNodeType as ne,isAllSelection as re,isApple as ie,isAtBlockStart as ae,isNodeSelection as oe,isTextSelection as h,toggleNode as se,union as g,unsetBlockType as ce,withPriority as le,withPriority as _,withSkipCodeBlock as ue}from"@prosekit/core";import{defineCodeBlock as de,defineCodeBlockHighlight as fe,defineCodeBlockPreviewPlugin as pe,isCodeBlockPreviewHiddenDecoration as me}from"@prosekit/extensions/code-block";import{definePlaceholder as he}from"@prosekit/extensions/placeholder";import{defineReadonly as ge}from"@prosekit/extensions/readonly";import{isElementLike as _e,once as ve}from"@ocavue/utils";import{defineBlockquote as ye}from"@prosekit/extensions/blockquote";import{defineDoc as be}from"@prosekit/extensions/doc";import{defineGapCursor as xe}from"@prosekit/extensions/gap-cursor";import{defineModClickPrevention as Se}from"@prosekit/extensions/mod-click-prevention";import{defineText as Ce}from"@prosekit/extensions/text";import{defineVirtualSelection as we}from"@prosekit/extensions/virtual-selection";import{NodeSelection as Te,Plugin as v,PluginKey as y,Selection as b,TextSelection as x}from"@prosekit/pm/state";import{Decoration as Ee,DecorationSet as S}from"@prosekit/pm/view";import{LanguageDescription as De}from"@codemirror/language";import{languages as Oe}from"@codemirror/language-data";import{classHighlighter as ke,highlightTree as Ae}from"@lezer/highlight";import{createParser as je}from"prosemirror-highlight/lezer";import{defineTextBlockEnterRule as Me}from"@prosekit/extensions/enter-rule";import{defineInputRule as Ne,defineTextBlockInputRule as Pe}from"@prosekit/extensions/input-rule";import{triggerAutocomplete as Fe}from"@prosekit/extensions/autocomplete";import{DOMSerializer as Ie,Mark as Le,Slice as C}from"@prosekit/pm/model";import{defineHeadingCommands as Re,defineHeadingInputRule as ze,defineHeadingSpec as Be}from"@prosekit/extensions/heading";import{defineHorizontalRule as Ve}from"@prosekit/extensions/horizontal-rule";import{AddMarkStep as He,AddNodeMarkStep as Ue,RemoveMarkStep as We,RemoveNodeMarkStep as Ge,ReplaceStep as Ke,Step as qe,StepResult as Je,Transform as Ye}from"@prosekit/pm/transform";import{GFM as Xe,parser as Ze}from"@lezer/markdown";import{defineListCommands as Qe,defineListDropIndicator as $e,defineListKeymap as et,defineListSpec as tt,moveList as nt,toggleList as rt,wrapInList as w}from"@prosekit/extensions/list";import{createListRenderingPlugin as it,createSafariInputMethodWorkaroundPlugin as at,createToggleCollapsedCommand as ot,defaultAttributesGetter as st,findCheckboxInListItem as ct,handleListMarkerMouseDown as lt,joinListElements as ut,listToDOM as dt,unwrapListSlice as ft,wrappingListInputRule as pt}from"prosemirror-flat-list";import{defineTableCellSpec as mt,defineTableCommands as ht,defineTableDropIndicator as gt,defineTableEditingPlugin as _t,defineTableHeaderCellSpec as vt,defineTableRowSpec as yt,defineTableSpec as bt,deleteTable as xt,isCellSelection as St}from"@prosekit/extensions/table";import{defineParagraphCommands as Ct,defineParagraphKeymap as wt}from"@prosekit/extensions/paragraph";import{closeHistory as Tt}from"@prosekit/pm/history";import Et from"rehype-parse";import Dt from"rehype-remark";import Ot from"remark-gfm";import kt from"remark-stringify";import{unified as At}from"unified";import{registerResizableHandleElement as jt,registerResizableRootElement as Mt}from"@prosekit/web/resizable";function T(e,t,n,r){let i=e.doc.content.size;if(t<0||t>i)return;let a=e.doc.resolve(t);if(!(!a.parent.isTextblock||a.parent.type.spec.code))return ee(a,n,r)}const Nt=new Set([`mdMark`,`mdLinkUri`,`mdLinkTitle`]);function Pt(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=>Nt.has(e))&&!(t.preserveMathSource&&n.includes(`mdMath`))||r.push(e.text),!1}),n.push(r.join(``))}),n.join(`
2
- `)}const E=new y(`mark-mode`);function Ft(e){return E.getState(e)}function It(e){return new v({key:E,state:{init:()=>e,apply:(e,t)=>e.getMeta(E)??t},props:{attributes:t=>({"data-mark-mode":Ft(t)??e}),decorations:e=>{let t=Ft(e);if(t===`focus`)return zt(e);if(t===`hide`)return Bt(e)},clipboardTextSerializer:(e,t)=>Ft(t.state)===`show`?``:Pt(e,{preserveMathSource:!0})}})}function Lt(e){return(t,n)=>D(t)===e?!1:(n?.(t.tr.setMeta(E,e)),!0)}function Rt(e){return g(m(It(e)),s({setMarkMode:Lt}))}function D(e){return E.getState(e)}function zt(e){return Vt(e,void 0)}function Bt(e){return Vt(e,{key:`math`})}function Vt(e,t){let{selection:n}=e;if(!n.empty)return S.empty;let r=n.$head,{parent:i}=r;if(!i.isTextblock||i.type.spec.code)return S.empty;let a=ee(r,te(e.schema,`mdPack`),t);return a?S.create(e.doc,[Ee.inline(a.from,a.to,{class:`show`})]):S.empty}const Ht=[`mdImage`,`mdWikilink`,`mdFile`];function O(e,t){let n=D(t);return n?e.flatMap(e=>e.modes.includes(n)?[e.name]:[]):[]}function Ut(e,t,n){for(let r of n){let n=T(e,t,r);if(n)return n}}function k(e,t,n){let r=Ut(e,t,n);return r&&r.to===t?r:void 0}function A(e,t,n){let r=Ut(e,t,n);return r&&r.from===t?r:void 0}function Wt(e,t){let{from:n,to:r,empty:i}=e.selection;if(i)return;let a=Ut(e,n,t);return a&&a.from===n&&a.to===r?a:void 0}function Gt(e,t){return x.create(e.doc,t.from,t.to)}function Kt(e,t,n,r){let i=e.doc.resolve(t);if(!(r===-1?i.parentOffset===0:i.parentOffset===i.parent.content.size)||i.depth===0)return;let a=r===-1?A(e,t,n):k(e,t,n),o=r===-1?i.before():i.after(),s=b.findFrom(e.doc.resolve(o),r);if(!s)return;let c=h(s)?r===-1?k(e,s.head,n):A(e,s.head,n):void 0;if(!(a==null&&c==null))return s}function qt(e){return(t,n)=>{let r=O(e,t);if(r.length===0||!h(t.selection))return!1;let i=t.selection;if(i.empty){let e=A(t,i.from,r);if(e)return n?.(t.tr.setSelection(Gt(t,e))),!0;if(k(t,i.from,r)&&i.from<t.doc.resolve(i.from).end())return n?.(t.tr.setSelection(x.create(t.doc,i.from+1))),!0;let a=Kt(t,i.from,r,1);return a?(n?.(t.tr.setSelection(a).scrollIntoView()),!0):!1}let a=Wt(t,r);return a?(n?.(t.tr.setSelection(x.create(t.doc,a.to))),!0):!1}}function Jt(e){return(t,n)=>{let r=O(e,t);if(r.length===0||!h(t.selection))return!1;let i=t.selection;if(i.empty){let e=k(t,i.from,r);if(e)return n?.(t.tr.setSelection(Gt(t,e))),!0;let a=Kt(t,i.from,r,-1);return a?(n?.(t.tr.setSelection(a).scrollIntoView()),!0):!1}let a=Wt(t,r);return a?(n?.(t.tr.setSelection(x.create(t.doc,a.from))),!0):!1}}function Yt(e,t){return(n,r)=>{let i=O(e,n);if(i.length===0||!h(n.selection))return!1;let{anchor:a,head:o}=n.selection,s=t===-1?k(n,o,i):A(n,o,i);if(s){let e=t===-1?s.from:s.to;return r?.(n.tr.setSelection(x.create(n.doc,a,e)).scrollIntoView()),!0}let c=Kt(n,o,i,t);return!c||!h(c)?!1:(r?.(n.tr.setSelection(x.create(n.doc,a,c.head)).scrollIntoView()),!0)}}function Xt(e){return(t,n)=>{let r=O(e,t);if(r.length===0||!t.selection.empty)return!1;let i=t.selection.from,a=k(t,i,r);return a?(n?.(t.tr.delete(a.from,a.to)),!0):!A(t,i,r)||i<=t.doc.resolve(i).start()?!1:(n?.(t.tr.delete(i-1,i)),!0)}}function Zt(e){return(t,n)=>{let r=O(e,t);if(r.length===0||!t.selection.empty)return!1;let i=t.selection.from,a=A(t,i,r);return a?(n?.(t.tr.delete(a.from,a.to)),!0):!k(t,i,r)||i>=t.doc.resolve(i).end()?!1:(n?.(t.tr.delete(i,i+1)),!0)}}const Qt=`md-atom-selected`;function $t(e){return new v({key:new y(`atom-mark-selection`),props:{decorations:t=>{let n=O(e,t);if(n.length===0||oe(t.selection))return;let r=Wt(t,n);if(r)return S.create(t.doc,[Ee.inline(r.from,r.to,{class:Qt})]);let{from:i,to:a,empty:o}=t.selection;if(o)return null;let s=[];return t.doc.nodesBetween(i,a,(e,t)=>{e.marks.some(e=>n.includes(e.type.name))&&s.push(Ee.inline(t,t+e.nodeSize,{class:Qt}))}),S.create(t.doc,s)}}})}function en({marks:e}){return g(_(l({ArrowRight:qt(e),ArrowLeft:Jt(e),"Shift-ArrowRight":Yt(e,1),"Shift-ArrowLeft":Yt(e,-1),Backspace:Xt(e),Delete:Zt(e)}),t.high),m($t(e)))}const j=new Map,tn=new Map,nn={math:`latex`};async function rn(e){let t=j.get(e);if(t!==void 0)return t;let n=De.matchLanguageName(Oe,nn[e]??e,!0);if(!n)return j.set(e,null),null;let r=n.support;if(!r)try{r=await n.load()}catch(t){return console.error(`[meowdown] Failed to load language "${e}":`,t),j.set(e,null),null}return j.set(e,r),r}function an(e,t){let n=tn.get(e);if(n)return n;let r=je({parse:e=>t.language.parser.parse(e.content),highlighter:ke});return tn.set(e,r),r}const on=e=>{let t=e.language?.trim();if(!t)return[];let n=j.get(t);return n===null?[]:n?an(t,n)(e):rn(t).then(()=>void 0)};function sn(){return fe({parser:on,nodeTypes:[`codeBlock`]})}function cn(e,t){let n=t.language.parser.parse(e),r=[];return Ae(n,ke,(e,t,n)=>{r.push([e,t,n])}),r}function ln(e,t){let n=t.trim();if(!n)return[];let r=j.get(n);return r===null?[]:r?cn(e,r):rn(n).then(t=>t?cn(e,t):[])}function un(){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 dn(){return f({type:`codeBlock`,attr:`fenceLength`,default:null,toDOM:e=>e==null?null:[`data-fence-length`,String(e)],parseDOM:e=>{let t=e.getAttribute(`data-fence-length`);if(t==null)return null;let n=Number.parseInt(t,10);return Number.isSafeInteger(n)&&n>3?n:null}})}function fn(e){return{language:e[1]||``,fenceStyle:`tilde`}}function pn(){return Pe({regex:/^~~~(\S*)\s$/,type:`codeBlock`,attrs:fn})}function mn(){return Me({regex:/^~~~(\S*)$/,type:`codeBlock`,attrs:fn})}function hn(){return Me({regex:/^\$\$$/,type:`codeBlock`,attrs:()=>({language:`math`,fenceStyle:`dollar`})})}function gn(){return g(de(),un(),dn(),pn(),mn(),hn())}function _n(e,t){return(n,r)=>{if(r){let i=x.create(n.doc,e,t);r(n.tr.setSelection(i))}return!0}}function vn(e,t,n){return(r,i)=>{if(i){let a=x.between(e,t,n);i(r.tr.setSelection(a))}return!0}}function yn(e){return(t,n)=>{if(!e.trim())return!1;let r=Z(e,{nodes:Go(t.schema)}).content;if(r.childCount===0)return!1;let i=r.childCount===1&&r.child(0).type.name===`paragraph`?new C(r,1,1):new C(r,0,C.maxOpen(r).openEnd);if(n){let e=t.tr,r=e.selection;(!h(r)||!r.empty)&&e.setSelection(x.near(r.$from)),n(e.replaceSelection(i).scrollIntoView())}return!0}}function bn(e){return(t,n)=>{if(!e)return!1;let r=t.selection.$from;if(r.parent.type.spec.code)return!1;if(n){let i=r.parentOffset,a=i===0?``:r.parent.textBetween(i-1,i),o=a!==``&&!/\s/u.test(a),s=t.tr.insertText(o?` ${e}`:e);Fe(s),n(s.scrollIntoView())}return!0}}function xn(){return(e,t)=>(t&&t(e.tr.scrollIntoView()),!0)}function Sn(){return s({insertMarkdown:yn,insertTrigger:bn,scrollIntoView:xn,selectText:_n,selectTextBetween:vn})}const Cn=(e,t,n)=>{let{selection:r}=e;return r.empty||n?.composing?!1:(t?.(e.tr.setSelection(x.near(r.$head))),!0)};function wn(){return _(l({Escape:Cn}),t.low)}function Tn(){return f({type:`doc`,attr:`frontmatter`,default:null})}function En(){return p({name:`heading`,whitespace:`pre`})}function Dn(){return f({type:`heading`,attr:`setextUnderline`,default:null,toDOM:e=>e==null?null:[`data-setext-underline`,String(e)],parseDOM:e=>{let t=e.getAttribute(`data-setext-underline`);if(t==null)return null;let n=Number.parseInt(t,10);return Number.isSafeInteger(n)&&n>0?n:null}})}function On(){return f({type:`heading`,attr:`closingHashes`,default:null,toDOM:e=>e==null?null:[`data-closing-hashes`,String(e)],parseDOM:e=>{let t=e.getAttribute(`data-closing-hashes`);if(t==null)return null;let n=Number.parseInt(t,10);return Number.isSafeInteger(n)&&n>0?n:null}})}function M(e){return ue(se({type:`heading`,attrs:{level:e}}))}const kn=(e,t,n)=>ae(e,n)?.parent.type.name===`heading`&&ce()(e,t,n);function An(){return l({"Mod-1":M(1),"Mod-2":M(2),"Mod-3":M(3),"Mod-4":M(4),"Mod-5":M(5),"Mod-6":M(6),Backspace:kn})}function jn(){return g(Be(),En(),Dn(),On(),ze(),Re(),An())}function Mn(e,t){return t(e.state,e.dispatch,e)}const Nn=new Set([`mdMark`,`mdLinkUri`,`mdLinkTitle`]);function Pn(e,t){if(t<0||t+1>e.doc.content.size)return;let n=e.doc.resolve(t),r=n.parent.maybeChild(n.index());if(!(r==null||!r.isText))return r.marks}function N(e,t){let n=Pn(e,t);return n!=null&&n.some(e=>Nn.has(e.type.name))}function P(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 F(e,t){if(!P(e,t))return;let n=e.doc.resolve(t).start(),r=t;for(;r>n&&N(e,r-1);)r--;return r<t?{from:r,to:t}:void 0}function I(e,t){if(!P(e,t))return;let n=e.doc.resolve(t).end(),r=t;for(;r<n&&N(e,r);)r++;return r>t?{from:t,to:r}:void 0}function Fn(e,t){return N(e,t-1)&&N(e,t)}function In(e,t){if(!Fn(e,t))return;let n=F(e,t),r=I(e,t);if(!(n==null||r==null))return{from:n.from,to:r.to}}function Ln(e,t,n){let r=Pn(e,t);return r!=null&&n.isInSet(r)}function Rn(e,t){let n=Pn(e,t);if(n==null)return;let r=te(e.schema,`mdPack`),i=n.filter(e=>e.type===r);if(i.length===0)return;let a=e.doc.resolve(t),o=a.start(),s=a.end(),c;for(let n of i){let r=t;for(;r>o&&Ln(e,r-1,n);)r--;let i=t+1;for(;i<s&&Ln(e,i,n);)i++;(c==null||i-r<c.to-c.from)&&(c={from:r,to:i})}return c}function L(e,t,n){let r=Rn(e,n===`from`?t.from:t.to-1);return r==null?!1:n===`from`?r.from===t.from:r.to===t.to}function zn(e,t,n){let r=L(e,t,`from`),i=L(e,t,`to`);return r&&!i?t.from:i&&!r?t.to:n-t.from<=t.to-n?t.from:t.to}function Bn(e,t,n,r){if(!P(e,n))return n;let i=In(e,n);if(i!=null)return r?zn(e,i,n):n>=t?i.to:i.from;if(!r)return n;let a=F(e,n);if(a!=null&&L(e,a,`from`))return a.from;let o=I(e,n);return o!=null&&L(e,o,`to`)?o.to:n}function Vn(e,t){if(!P(e,t))return;let n=N(e,t-1),r=N(e,t);if(n!==r)return r?`left`:`right`}function Hn(e,t){let n=Rn(e,t);if(n==null)return[];let r=I(e,n.from),i=F(e,n.to),a=[];return i!=null&&a.push(i),r!=null&&(i==null||r.from!==i.from)&&a.push(r),a}const Un=new y(`meowdown-hidden-run-snap`),Wn=new y(`meowdown-hidden-run-beforeinput`);function Gn(){let e=!1;return new v({key:Un,props:{handleDOMEvents:{compositionstart:()=>(e=!0,!1),compositionend:()=>(e=!1,!1)}},appendTransaction:(t,n,r)=>{if(e||D(r)!==`hide`)return null;let i=r.selection;if(!h(i))return null;let a=t.some(e=>e.getMeta(`pointer`)!=null);if(i.empty){let e=Bn(r,n.selection.head,i.head,a);return e===i.head?null:r.tr.setSelection(x.create(r.doc,e))}let o=In(r,i.from)?.from??i.from,s=In(r,i.to)?.to??i.to;if(o===i.from&&s===i.to)return null;let c=i.anchor===i.from?o:s,l=i.head===i.from?o:s;return r.tr.setSelection(x.create(r.doc,c,l))}})}const Kn=(e,t)=>{if(D(e)!==`hide`)return!1;let n=e.selection;if(!h(n)||!n.empty)return!1;let r=Bn(e,n.head,n.head,!0);return r===n.head||t?.(e.tr.setSelection(x.create(e.doc,r))),!1};function qn(e){return(t,n)=>{if(D(t)!==`hide`)return!1;let r=t.selection;if(!h(r)||!r.empty)return!1;let i=r.$head;if(!i.parent.isTextblock||i.parent.type.spec.code)return!1;let a=e===-1?F(t,r.head):I(t,r.head);if(a==null)return!1;let o=Hn(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 Jn=qn(-1),Yn=qn(1);function Xn(){return new v({key:Wn,props:{handleDOMEvents:{beforeinput:(e,t)=>{if(e.composing)return!1;let n=t.inputType===`deleteContentBackward`?Jn:t.inputType===`deleteContentForward`?Yn:void 0;return n==null||!Mn(e,n)?!1:(t.preventDefault(),!0)}}}})}function Zn(){return g(m(Gn()),m(Xn()),_(l({Enter:Kn,Backspace:Jn,Delete:Yn}),t.highest))}function Qn(){return f({type:`horizontalRule`,attr:`marker`,default:null,toDOM:e=>e?[`data-hr-marker`,e]:null,parseDOM:e=>e.getAttribute(`data-hr-marker`)})}function $n(){return g(Ve(),Qn())}function er(){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 tr(e){let[t,n,r]=e;return[t,n,r.map(e=>e.toJSON())]}function nr(e,t){let[n,r,i]=t;return[n,r,i.map(t=>Le.fromJSON(e,t))]}function rr(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 R=class e extends qe{constructor(e){super(),this.chunks=e}apply(e){if(this.chunks.length===0)return Je.ok(e);let t=e.content.size,n;for(let[r,i,a]of this.chunks){if(r>=i)continue;let o=Math.max(0,Math.min(r,t)),s=Math.max(o,Math.min(i,t));if(o>=s)continue;let c=Le.setFrom(a);e.nodesBetween(o,s,(t,r)=>{if(!t.isText)return!0;let i=Math.max(o,r),a=Math.min(s,r+t.nodeSize);if(i>=a)return!1;let l=t.marks;if(rr(l,c))return!1;n??=new Ye(e);for(let e of l)n.removeMark(i,a,e);for(let e of c)n.addMark(i,a,e);return!1})}return Je.ok(n?n.doc:e)}invert(e){if(this.chunks.length===0)return ir;let t=this.chunks[0][0],n=this.chunks[0][1];for(let[,e]of this.chunks)e>n&&(n=e);let r=e.content.size,i=Math.max(0,Math.min(t,r)),a=Math.max(i,Math.min(n,r));return new Ke(i,a,e.slice(i,a),!1)}map(e){return null}toJSON(){return{stepType:`batchSetMark`,chunks:this.chunks.map(tr)}}static fromJSON(t,n){let r=n.chunks;return new e(r.map(e=>nr(t,e)))}};qe.jsonID(`batchSetMark`,R);const ir=new R([]),ar=new Set([`com`,`br`,`net`,`jp`,`org`,`in`,`de`,`ru`,`it`,`fr`]),or=/^[a-z0-9](?:[a-z0-9-]*[a-z0-9])?$/i;function sr(e){let t=e.indexOf(`/`);return t===-1?e:e.slice(0,t)}function cr(e){let t=e.split(`.`);if(t.length<2)return!1;let n=t[t.length-1].toLowerCase();if(!ar.has(n)||t[t.length-2].length<3)return!1;for(let e of t)if(e.length>63||!or.test(e))return!1;return!0}function lr(e){if(/^[a-z][a-z0-9+.-]*:/i.test(e))return e;if(/^[^\s@]+@[^\s@]+$/.test(e))return`mailto:${e}`;if(/^www\./i.test(e)||cr(sr(e)))return`https://${e}`}function z(e){return e===32||e===9||e===10||e===13}const ur=/^[a-z0-9-]+(?:\.[a-z0-9-]+)+(?:\/[^\s<]*)?/i,dr=/[\s(*_~]/;function fr(e){return e>=48&&e<=57||e>=65&&e<=90||e>=97&&e<=122||e===45}function pr(e,t,n){let r=0;for(let i=0;i<t;i++)e[i]===n&&r++;return r}function mr(e){let t=e.length;for(;;){let n=e[t-1];if(/[?!.,:*_~]/.test(n)||n===`)`&&pr(e,t,`)`)>pr(e,t,`(`))t--;else if(n===`;`){let n=/&(?:#\d+|#x[a-f\d]+|\w+);$/.exec(e.slice(0,t));if(!n)break;t=n.index}else break}return t}const hr={parseInline:[{name:`BareAutolink`,before:`Link`,parse(e,t,n){if(!fr(t)||e.hasOpenLink)return-1;let r=e.slice(n-1,n);if(r!==``&&!dr.test(r))return-1;let i=ur.exec(e.slice(n,e.end));if(!i)return-1;let a=mr(i[0]);return a===0||!cr(sr(i[0].slice(0,a)))?-1:e.addElement(e.elt(`URL`,n,n+a))}}]};function gr(e){return e>=48&&e<=57||e>=65&&e<=90||e>=97&&e<=122||e===45||e===95||e>127&&/[\p{L}\p{N}]/u.test(String.fromCharCode(e))}function _r(e){return e>=65&&e<=90||e>=97&&e<=122||e>127&&/\p{L}/u.test(String.fromCharCode(e))}const vr={defineNodes:[{name:`Hashtag`}],parseInline:[{name:`Hashtag`,parse(e,t,n){if(t!==35||!/\s|^$/.test(e.slice(n-1,n)))return-1;let r=n+1,i=!1;for(;r<e.end;){let t=e.char(r);if(!gr(t))break;i||=_r(t),r++}return i?e.addElement(e.elt(`Hashtag`,n,r)):-1}}]},yr={resolve:`Highlight`,mark:`HighlightMark`},br=/[!"#$%&'()*+,\-./:;<=>?@[\\\]^_`{|}~\u{A1}\u{2010}-\u{2027}]/u,xr={defineNodes:[{name:`Highlight`},{name:`HighlightMark`}],parseInline:[{name:`Highlight`,after:`Emphasis`,parse(e,t,n){if(t!==61||e.char(n+1)!==61||e.char(n+2)===61)return-1;let r=e.slice(n-1,n),i=e.slice(n+2,n+3),a=/\s|^$/.test(r),o=/\s|^$/.test(i),s=br.test(r),c=br.test(i);return e.addDelimiter(yr,n,n+2,!o&&(!c||a||s),!a&&(!s||o||c))}}]};function Sr(e){return e>=48&&e<=57}function Cr(e){return e.next!==36||e.text.charCodeAt(e.pos+1)!==36||e.text.charCodeAt(e.pos+2)===36?!1:e.skipSpace(e.pos+2)===e.text.length}function wr(e){let t=e.depth;return typeof t==`number`?t:2**53-1}const Tr={defineNodes:[{name:`InlineMath`},{name:`InlineMathMark`},{name:`BlockMath`,block:!0},{name:`BlockMathMark`}],parseBlock:[{name:`BlockMath`,before:`FencedCode`,parse(e,t){if(!Cr(t))return!1;let n=e.lineStart+t.pos,r=[e.elt(`BlockMathMark`,n,n+2)];for(let n=!0,i=!0,a=!1;!(!e.nextLine()||wr(t)<e.depth);n=!1){if(Cr(t)){i&&a&&r.push(e.elt(`CodeText`,e.lineStart-1,e.lineStart)),r.push(e.elt(`BlockMathMark`,e.lineStart+t.pos,e.lineStart+t.pos+2)),e.nextLine();break}a=!0,n||(r.push(e.elt(`CodeText`,e.lineStart-1,e.lineStart)),i=!1);let o=e.lineStart+t.basePos,s=e.lineStart+t.text.length;o<s&&(r.push(e.elt(`CodeText`,o,s)),i=!1)}return e.addElement(e.elt(`BlockMath`,n,e.prevLineEnd(),r)),!0},endLeaf(e,t){return Cr(t)}}],parseInline:[{name:`InlineMath`,after:`InlineCode`,parse(e,t,n){if(t!==36||e.char(n-1)===36)return-1;let r=e.char(n+1)===36?2:1;if(e.char(n+r)===36)return-1;let i=n+r;if(z(e.char(i)))return-1;for(let t=i;t<e.end;t++){let a=e.char(t);if(a===10)return-1;if(a===92){t++;continue}if(a!==36)continue;let o=1;for(;e.char(t+o)===36;)o++;if(o!==r||z(e.char(t-1))||Sr(e.char(t+o)))return-1;let s=t+o;return e.addElement(e.elt(`InlineMath`,n,s,[e.elt(`InlineMathMark`,n,i),e.elt(`InlineMathMark`,t,s)]))}return-1}}]},Er=/^[a-z][a-z0-9+.-]*:\/\/[^\s<]+/i;function Dr(e){return e>=65&&e<=90||e>=97&&e<=122}const Or={parseInline:[{name:`SchemeAutolink`,after:`Autolink`,parse(e,t,n){if(!Dr(t)||e.hasOpenLink)return-1;let r=e.slice(n-1,n);if(r!==``&&!dr.test(r))return-1;let i=Er.exec(e.slice(n,e.end));if(!i)return-1;let a=mr(i[0]);return a<=i[0].indexOf(`://`)+3?-1:e.addElement(e.elt(`URL`,n,n+a))}}]},kr={defineNodes:[{name:`Wikilink`},{name:`WikilinkMark`}],parseInline:[{name:`Wikilink`,before:`Link`,parse(e,t,n){if(t!==91||e.char(n+1)!==91)return-1;let r=!1;for(let t=n+2;t<e.end-1;t++){let i=e.char(t);if(i===93){if(e.char(t+1)!==93||!r)return-1;let i=t+2;return e.addElement(e.elt(`Wikilink`,n,i,[e.elt(`WikilinkMark`,n,n+2),e.elt(`WikilinkMark`,t,i)]))}if(i===91||i===10)return-1;i!==32&&i!==9&&(r=!0)}return-1}}]};function Ar(e){return e.end}const jr=Ze.configure([Xe,vr,kr,hr,Or,xr,Tr]),Mr=jr.configure({parseInline:[{name:`SkipInline`,before:`Escape`,parse:Ar}]});function B(e){return jr.parseInline(e,0)}function V(e,t,n=[]){for(let r of e)t(r)&&n.push(r),V(r.children,t,n);return n}function Nr(e){let t={};for(let n of e.nodeSet.types)t[n.name]=n.id;return t}const H=Nr(jr),Pr=/^<!--\s*(\{[^}]*\})\s*-->$/,Fr=/<!--\s*\{[^}]*\}\s*-->$/;function Ir(e){let t=Pr.exec(e.trim());if(!t)return;let n;try{n=JSON.parse(t[1])}catch{return}if(typeof n!=`object`||!n)return;let r=Lr(n);return Object.keys(r).length>0?r:void 0}function Lr(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 Rr(e){return`<!-- ${JSON.stringify(e)} -->`}function zr(e){return e.replace(Fr,``)}function Br(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 Vr(){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 Hr(){return d({name:`mdWikilink`,constructor:Vr()})}const Ur=new Map([[H.Emphasis,`mdEm`],[H.StrongEmphasis,`mdStrong`],[H.InlineCode,`mdCode`],[H.Strikethrough,`mdDel`],[H.Highlight,`mdHighlight`],[H.EmphasisMark,`mdMark`],[H.CodeMark,`mdMark`],[H.LinkMark,`mdMark`],[H.StrikethroughMark,`mdMark`],[H.HighlightMark,`mdMark`],[H.URL,`mdLinkUri`],[H.LinkTitle,`mdLinkTitle`],[H.Hashtag,`mdTag`],[H.WikilinkMark,`mdMark`]]);function Wr(e,t,n){let r=B(t),i=[];return Kr(r,[],0,t.length,t,e,i,n),i}function Gr(e){return e.slice(1,-1).replaceAll(/\\(.)/g,`$1`)}function Kr(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&&U(o,c,r.from,t);let l=r.type;if(l===H.Link){let e=Yr(r,t,i,a,s);e?U(o,r.from,r.to,e):Xr(r,t,i,a,o)}else if(l===H.Image){let s=Zr(r,e[n+1],i);Qr(r,t,i,a,o,s),s&&n++,c=s?s.to:r.to;continue}else if(l===H.Wikilink)ei(r,t,i,a,o);else if(l===H.InlineMath)$r(r,t,i,a,o);else if(l===H.URL){let e=lr(i.slice(r.from,r.to)),n=e?a.mdLinkText.create({href:e}):a.mdLinkUri.create();U(o,r.from,r.to,[...t,n])}else{let e;l===H.Emphasis?e=`italic`:l===H.StrongEmphasis?e=`bold`:l===H.InlineCode?e=`code`:l===H.Strikethrough?e=`strike`:l===H.Highlight?e=`highlight`:l===H.Autolink&&(e=`autolink`);let n=e?[...t,a.mdPack.create({key:e})]:t,c=Ur.get(l),u=c?[...n,a[c].create()]:n;r.children.length===0?U(o,r.from,r.to,u):Kr(r.children,u,r.from,r.to,i,a,o,s)}c=r.to}c<r&&U(o,c,r,t)}function qr(e){let t=-1,n=-1,r=null,i=null,a=0;for(let o of e.children)o.type===H.LinkMark?(a++,a===1&&(t=o.to),a===2&&(n=o.from)):o.type===H.URL&&r===null?r=o:o.type===H.LinkTitle&&i===null&&(i=o);return{labelFrom:t,labelTo:n,urlNode:r,titleNode:i}}function Jr(e){let t=e.split(/[?#]/,1)[0],n=t.split(/[/\\]/).findLast(Boolean)??t;try{return decodeURIComponent(n)}catch{return n}}function Yr(e,t,n,r,i){let a=i?.resolveFileLink;if(!a)return;let{labelFrom:o,labelTo:s,urlNode:c,titleNode:l}=qr(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?Gr(n.slice(l.from,l.to)):``;if(!a({href:u,label:d,title:f}))return;let p=d||Jr(u);return[...t,r.mdFile.create({href:u,name:p,title:f})]}function Xr(e,t,n,r,i){let{labelTo:a,urlNode:o,titleNode:s}=qr(e),c=o?n.slice(o.from,o.to):``,l=s?Gr(n.slice(s.from,s.to)):``,u=c?r.mdLinkText.create({href:c}):null,d=e=>a>=0&&e<a&&u!==null,f=r.mdPack.create({key:`link`,data:{href:c,title:l}}),p=[...t,f],m=e.from;for(let t of e.children){if(t.from>m){let e=d(m)?[...p,u]:p;U(i,m,t.from,e)}let e=d(t.from)?[...p,u]:p;if(t.type===H.Wikilink){ei(t,e,n,r,i),m=t.to;continue}let a=Ur.get(t.type),o=a?[...e,r[a].create()]:e;t.children.length===0?U(i,t.from,t.to,o):Kr(t.children,o,t.from,t.to,n,r,i,void 0),m=t.to}m<e.to&&U(i,m,e.to,p)}function Zr(e,t,n){if(!t||t.type!==H.Comment||t.from!==e.to)return;let r=Ir(n.slice(t.from,t.to));if(r)return{magic:r,to:t.to}}function Qr(e,t,n,r,i,a){let o=e.children.find(e=>e.type===H.URL);if(!o){Xr(e,t,n,r,i);return}let s=e.children.filter(e=>e.type===H.LinkMark),c=e.children.find(e=>e.type===H.LinkTitle),l=n.slice(o.from,o.to),u=s.length>=2?n.slice(s[0].to,s[1].from):``,d=c?Gr(n.slice(c.from,c.to)):``,f=a?.magic.width??null,p=a?.magic.height??null,m=a?.to??e.to;U(i,e.from,m,[...t,r.mdImage.create({src:l,alt:u,title:d,width:f,height:p})])}function $r(e,t,n,r,i){let a=e.children.filter(e=>e.type===H.InlineMathMark);if(a.length<2){U(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})];U(i,e.from,a[0].to,[...s,r.mdMark.create()]),U(i,a[0].to,a[1].from,s),U(i,a[1].from,e.to,[...s,r.mdMark.create()])}function ei(e,t,n,r,i){let{target:a,display:o}=Br(n.slice(e.from,e.to));U(i,e.from,e.to,[...t,r.mdWikilink.create({target:a,display:o})])}function U(e,t,n,r){if(t>=n)return;let i=e.at(-1);if(i&&i[1]===t&&rr(i[2],r)){e[e.length-1]=[i[0],n,i[2]];return}e.push([t,n,r])}const ti=`inline-marks-applied`;let ni=0,ri=0;function ii(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 ai(e){let t=new WeakMap;function n(n,r,i){let a=t.get(n);if(a?ri++:(ni++,a=Wr(Uo(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 v({key:new y(`inline-mark`),appendTransaction(e,t,n){for(let t of e)if(t.getMeta(ti))return null;let i=r(n,ii(e,n));if(i.length===0)return null;let a=n.tr.step(new R(i));return a.setMeta(ti,!0),a.setMeta(`addToHistory`,!1),a},view(e){return e.dispatch(oi(e.state)),{}}})}function oi(e){return e.tr.setMeta(`inline-marks-trigger`,!0)}function si(e){return m(ai(e))}function ci(){return u({name:`mdImage`,inclusive:!1,attrs:{src:{default:``},alt:{default:``},title:{default:``},width:{default:null},height:{default:null}},toDOM:()=>[`span`,{class:`md-image`},0],parseDOM:[{tag:`span.md-image`}]})}function li(){return u({name:`mdMark`,inclusive:!1,toDOM:()=>[`span`,{class:`md-mark`},0],parseDOM:[{tag:`span.md-mark`}]})}function ui(){return u({name:`mdEm`,toDOM:()=>[`em`,0],parseDOM:[{tag:`em`}]})}function di(){return u({name:`mdStrong`,toDOM:()=>[`strong`,0],parseDOM:[{tag:`strong`}]})}function fi(){return u({name:`mdCode`,toDOM:()=>[`code`,0],parseDOM:[{tag:`code`}]})}function pi(){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 mi(){return u({name:`mdLinkUri`,inclusive:!1,toDOM:()=>[`span`,{class:`md-link-uri`},0],parseDOM:[{tag:`span.md-link-uri`}]})}function hi(){return u({name:`mdLinkTitle`,inclusive:!1,toDOM:()=>[`span`,{class:`md-link-title`},0],parseDOM:[{tag:`span.md-link-title`}]})}function gi(){return u({name:`mdDel`,toDOM:()=>[`del`,0],parseDOM:[{tag:`del`}]})}function _i(){return u({name:`mdHighlight`,toDOM:()=>[`mark`,0],parseDOM:[{tag:`mark`}]})}function vi(){return u({name:`mdTag`,toDOM:()=>[`span`,{class:`md-tag`},0],parseDOM:[{tag:`span.md-tag`}]})}function yi(){return u({name:`mdWikilink`,inclusive:!1,attrs:{target:{default:``},display:{default:``}},toDOM:()=>[`span`,{class:`md-wikilink`},0],parseDOM:[{tag:`span.md-wikilink`}]})}function bi(){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 xi(){return u({name:`mdMath`,inclusive:!1,attrs:{formula:{default:``}},toDOM:()=>[`span`,{class:`md-math`},0],parseDOM:[{tag:`span.md-math`}]})}function Si(){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 Ci(){return g(li(),ui(),di(),fi(),pi(),mi(),hi(),gi(),_i(),vi(),yi(),ci(),bi(),xi(),Si())}function wi(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 Ti(e,t=0){return wi(e,96,t)}const W={em:{node:H.Emphasis,delim:`*`},strong:{node:H.StrongEmphasis,delim:`**`},code:{node:H.InlineCode,delim:"`"},del:{node:H.Strikethrough,delim:`~~`},highlight:{node:H.Highlight,delim:`==`}},Ei=new Set([H.EmphasisMark,H.CodeMark,H.LinkMark,H.StrikethroughMark,H.HighlightMark]);function Di(e){return[e.children[0],e.children.at(-1)]}function Oi(e){let{type:t,children:n}=e;if(t===H.Emphasis||t===H.StrongEmphasis||t===H.Strikethrough||t===H.Highlight)return[n[0].to,n.at(-1).from];if(t===H.Link||t===H.Image){let e=n.find((e,t)=>t>0&&e.type===H.LinkMark);return e?[n[0].to,e.from]:null}return null}function ki(e,t,n){for(let r of e){if(r.to<=t||r.from>=n||t<=r.from&&r.to<=n)continue;let i=Oi(r);return i&&i[0]<=t&&n<=i[1]?ki(r.children,t,n):ki(e,Math.min(t,r.from),Math.max(n,r.to))}return[t,n]}function Ai(e,t,n){for(let r of e)if(!(r.to<=t||r.from>=n)&&(t>r.from||r.to>n))return Ai(e,Math.min(t,r.from),Math.max(n,r.to));return[t,n]}function ji(e,t,n){for(;t<n&&z(e.charCodeAt(t));)t++;for(;n>t&&z(e.charCodeAt(n-1));)n--;return[t,n]}function Mi(e,t,n,r){let i=V(B(e),e=>e.type===r.node||Ei.has(e.type));for(let r=t;r<n;r++)if(!z(e.charCodeAt(r))&&i.every(e=>!(e.from<=r&&r<e.to)))return!1;return!0}function Ni(e,t,n,r,i){let a=B(e),o=V(a,e=>e.type===r.node);return i?Ii(e,o,t,n):Pi(e,a,o,t,n,r)}function Pi(e,t,n,r,i,a){for(let e=0;e!==i-r;){e=i-r,[r,i]=ki(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]=Di(e);o.push({from:t.from,to:t.to,insert:``}),o.push({from:n.from,to:n.to,insert:``})}let[s,c]=Fi(e,r,i,o,a);return o.push({from:r,to:r,insert:s},{from:i,to:i,insert:c}),o}function Fi(e,t,n,r,i){if(i.node!==H.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(Ti(a)+1),s=a.startsWith("`")||a.endsWith("`")?` `:``;return[o+s,s+o]}function Ii(e,t,n,r){let i=[];for(let a of t){if(a.to<=n||a.from>=r)continue;let[t,o]=Di(a),s=Math.max(n,t.to),c=Math.min(r,o.from);for(s>=c&&([s,c]=[t.to,o.from]),[s,c]=Ai(a.children.slice(1,-1),s,c);s>t.to&&z(e.charCodeAt(s-1));)s--;for(;c<o.from&&z(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 Li(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=B(e),o=V(a,e=>e.type===n.node).findLast(e=>e.from<=t&&t<=e.to);if(o){let[e,n]=Di(o);return{kind:`move`,pos:t===o.from?e.to:t===o.to?n.from:o.to}}return Ri(a,t)||e[t-1]===r[0]||e[t]===r[0]?null:{kind:`insert`,pos:t}}function Ri(e,t){for(let n of e)if(n.from<t&&t<n.to){let e=Oi(n);return!e||t<e[0]||t>e[1]||Ri(n.children,t)}return!1}function G(e){return(t,n)=>{if(t.selection.empty)return zi(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]=ji(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:Mi(a,c,l,e)}),!1});let c=s.length>0&&s.every(e=>e.active),l=s.filter(e=>c||!e.active).flatMap(t=>Ni(t.text,t.from,t.to,e,c).map(e=>({from:e.from+t.base,to:e.to+t.base,insert:e.insert})));if(l.length===0)return!1;if(n){let e=t.tr;l.sort((e,t)=>t.from-e.from||t.to-e.to);for(let t of l)t.insert?e.insertText(t.insert,t.from,t.to):e.delete(t.from,t.to);e.setSelection(x.create(e.doc,e.mapping.map(a,a<=o?1:-1),e.mapping.map(o,o<a?1:-1))),n(e.scrollIntoView())}return!0}}function zi(e,t,n){let{$from:r}=t.selection,i=r.parent;if(!i.isTextblock||i.type.spec.code)return!1;let a=Li(i.textContent,r.parentOffset,e);if(!a)return!1;if(n){let i=r.start(),o=t.tr;a.kind===`unwrap`&&o.delete(i+a.from,i+a.to),a.kind===`move`&&o.setSelection(x.create(o.doc,i+a.pos)),a.kind===`insert`&&(o.insertText(e.delim+e.delim,i+a.pos),o.setSelection(x.create(o.doc,i+a.pos+e.delim.length))),n(o.scrollIntoView())}return!0}function Bi(){return s({toggleEm:()=>G(W.em),toggleStrong:()=>G(W.strong),toggleCode:()=>G(W.code),toggleDel:()=>G(W.del),toggleHighlight:()=>G(W.highlight)})}function Vi(){return l({"Mod-b":G(W.strong),"Mod-i":G(W.em),"Mod-e":G(W.code),"Mod-Shift-x":G(W.del),"Mod-Shift-h":G(W.highlight)})}function Hi(){return g(Bi(),Vi())}function Ui(e,t,n){let r;return e.doc.nodesBetween(t.from,t.to,(e,i)=>(e.isText&&e.marks.some(e=>e.type.name===n)&&(r={from:Math.max(i,t.from),to:Math.min(i+e.nodeSize,t.to)}),!0)),r}function K(e,t){let n=T(e,t,`mdLinkText`),r=T(e,t,`mdPack`,{key:`link`})??T(e,t,`mdPack`,{key:`autolink`}),i=r??n;if(!i)return;let a=r?.mark.attrs,o=n?.mark.attrs?.href??``;if(!r||a?.key!==`link`){let t={from:i.from,to:i.to};return{unit:t,text:a?.key===`autolink`?Ui(e,t,`mdLinkText`)??{from:i.from+1,to:i.to-1}:t,href:o,title:``}}let s=Ui(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 Wi(e){let t=e.trim();return t?lr(t)??t:``}function Gi(e,t){return e+(t?` "${t.replaceAll(/(["\\])/g,String.raw`\$1`)}"`:``)}function Ki(e){let{selection:t}=e,{$from:n,$to:r,empty:i}=t;if(i||!n.sameParent(r)||!h(t))return;let a=n.parent;if(!a.isTextblock||a.type.spec.code)return;let o=n.start(),[s,c]=ji(a.textContent,n.parentOffset,r.parentOffset);if(!(s>=c))return{from:o+s,to:o+c}}function qi({href:e,title:t,wrapText:n=!0}={}){return(r,i)=>{let a=Ki(r);if(!a)return!1;if(i){let{from:o,to:s}=a,c=r.tr,l=`](${Gi(Wi(e??``),t??``)})`;c.insertText(l,s).insertText(`[`,o);let u=s+1+l.length;c.setSelection(n?x.create(c.doc,o,u):x.create(c.doc,u)),c.scrollIntoView(),i(c)}return!0}}function Ji(e){return(t,n)=>{let r=K(t,t.selection.from);if(!r?.dest)return!1;let i=Gi(Wi(e.href??r.href),e.title??r.title);return n&&n(t.tr.insertText(i,r.dest.from,r.dest.to).scrollIntoView()),!0}}function Yi(){return(e,t)=>{let n=K(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 Xi(){return s({insertLink:qi,updateLink:Ji,removeLink:Yi})}function Zi(e){return(t,n,r)=>{let i=K(t,t.selection.from);if(i){if(n&&r){let{unit:{from:a,to:o}}=i;n(t.tr.setSelection(x.create(t.doc,a,o)).scrollIntoView()),r.focus(),e({from:a,to:o,link:i})}return!0}let a=Ki(t);if(a){if(n&&r){let{from:i,to:o}=a;n(t.tr.setSelection(x.create(t.doc,i,o)).scrollIntoView()),r.focus(),e({from:i,to:o,link:void 0})}return!0}return!1}}function Qi(e){return l({"Mod-k":Zi(e)})}function $i(e){return e===`)`||e===`*`||e===`+`?e:void 0}function ea(e){return e===`X`?e:void 0}function ta(e){return ia(e)?String(e):void 0}function na(){return f({type:`list`,attr:`marker`,default:null,splittable:!0,toDOM:e=>{let t=$i(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 ra(){return f({type:`list`,attr:`taskMarker`,default:null,splittable:!0,toDOM:e=>{let t=ea(e);return t==null?null:[`data-list-task-marker`,t]},parseDOM:e=>e.getAttribute(`data-list-task-marker`)===`X`?`X`:null})}function ia(e){return e===2||e===3||e===4}function aa(){return f({type:`list`,attr:`markerGap`,default:1,splittable:!0,toDOM:e=>{let t=ta(e);return t==null?null:[`data-list-marker-gap`,t]},parseDOM:e=>{let t=Number.parseInt(e.getAttribute(`data-list-marker-gap`)??``,10);return ia(t)?t:1}})}function oa(e){let t=e.attrs;return{...st(e),"data-list-marker":$i(t.marker),"data-list-task-marker":ea(t.taskMarker),"data-list-marker-gap":ta(t.markerGap)}}function sa(){return o({serializeFragmentWrapper:e=>(...t)=>ca(ut(e(...t))),serializeNodeWrapper:e=>(...t)=>{let n=e(...t);return _e(n)?ca(ut(n)):n},nodesFromSchemaWrapper:e=>(...t)=>({...e(...t),list:e=>dt({node:e,nativeList:!0,getAttributes:oa})})})}function ca(e){_e(e)&&la(e);for(let t of e.children)ca(t);return e}function la(e){if(!e.classList.contains(`prosemirror-flat-list`)||e.getAttribute(`data-list-kind`)!==`task`||e.children.length!==2)return;let t=e.children.item(0);if(!t||!t.classList.contains(`list-marker`))return;let n=ct(t);if(!n)return;let r=e.children.item(1);if(!r||!r.classList.contains(`list-content`))return;let i=r.children.item(0);!i||![`P`,`H1`,`H2`,`H3`,`H4`,`H5`,`H6`].includes(i.tagName)||(e.replaceChildren(...r.children),i.prepend(n))}const ua=[pt(/^\s?([*-])\s$/,{kind:`bullet`,collapsed:!1}),pt(/^\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}}),pt(/^\s?\[([\sX]?)\]\s$/i,({match:e})=>({kind:`task`,checked:[`x`,`X`].includes(e[1]),collapsed:!1})),pt(/^\s?\+\s$/,{kind:`task`,marker:`+`,checked:!1,collapsed:!1})];function da(){return g(ua.map(Ne))}function fa(){return w({kind:`task`,marker:`+`})}function pa(){return w({kind:`task`,marker:null})}function ma(e){let{$from:t}=e.selection;for(let e=t.depth;e>0;e--){let n=t.node(e);if(n.type.name===`list`)return n.attrs}return null}function ha(){return(e,t,n)=>{let r=ma(e);return(r?.kind===`task`?r.marker===`+`?pa():fa():w({kind:`task`,marker:null,checked:!1}))(e,t,n)}}function ga(){return s({cycleCheckableList:ha,wrapInCircleTask:fa,wrapInSquareTask:pa})}function _a(){return(e,t,n)=>{let r=ma(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},w(a)(e,t,n)}}function va(){return(e,t,n)=>{let r=ma(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},w(a)(e,t,n)}}function ya(e){return e.type.name===`list`&&e.attrs.kind===`bullet`&&e.childCount>=2&&e.firstChild?.type!==e.type}const ba=e=>{let t=e.attrs;return t.kind===`task`?{...t,checked:!t.checked}:ya(e)?{...t,collapsed:!t.collapsed}:t};function xa(){return m(()=>[new v({props:{handleDOMEvents:{mousedown:(e,t)=>lt({view:e,event:t,onListClick:ba})}}}),it(),new v({props:{transformCopied:ft}}),at()])}function Sa(){return s({toggleListCollapsed:()=>ot({isToggleable:ya})})}function Ca(){return l({"Mod-Enter":_a(),"Mod-Shift-Enter":va(),"Mod-.":ot({isToggleable:ya}),"Mod-Shift-7":rt({kind:`ordered`,collapsed:!1}),"Mod-Shift-8":rt({kind:`bullet`,collapsed:!1}),"Mod-Shift-9":rt({kind:`task`,checked:!1,collapsed:!1})})}function wa(){return g(tt(),xa(),et(),Qe(),sa(),$e(),da(),Ca(),na(),ra(),aa(),ga(),Sa())}let Ta;function Ea(){return Ta??=import(`katex`).then(e=>e.render),Ta}function Da(e,t,n,r){try{e(n,t,{displayMode:r,throwOnError:!1,output:`mathml`})}catch(e){t.textContent=String(e)}}var Oa=class{#e;#t;#n;#r;constructor(e,t){this.#r=e.attrs.formula,this.#e=document.createElement(`span`),this.#e.className=`md-math-view`,this.#n=document.createElement(`span`),this.#n.className=`md-math-view-preview`,this.#n.dataset.testid=`math-preview`,this.#n.contentEditable=`false`,this.#n.addEventListener(`mousedown`,e=>{e.preventDefault();let n=t.posAtDOM(this.#t,0);if(n<0)return;let r=x.near(t.state.doc.resolve(n),1);t.dispatch(t.state.tr.setSelection(r)),t.focus()}),this.#t=document.createElement(`span`),this.#t.className=`md-math-view-content`,this.#e.appendChild(this.#n),this.#e.appendChild(this.#t),this.#i()}get dom(){return this.#e}get contentDOM(){return this.#t}update(e){let t=e.attrs.formula;return t!==this.#r&&(this.#r=t,this.#i()),!0}ignoreMutation(e){return!this.#t.contains(e.target)}#i(){let e=this.#r;Ea().then(t=>{e===this.#r&&Da(t,this.#n,e,!1)})}};function ka(){return d({name:`mdMath`,constructor:(e,t)=>new Oa(e,t)})}function Aa(e){return e===`left`||e===`center`||e===`right`?e:null}function ja(){return f({type:`tableCell`,attr:`align`,default:null,toDOM:e=>e?[`data-align`,e]:null,parseDOM:e=>Aa(e.getAttribute(`data-align`))})}function Ma(){return f({type:`tableHeaderCell`,attr:`align`,default:null,toDOM:e=>e?[`data-align`,e]:null,parseDOM:e=>Aa(e.getAttribute(`data-align`))})}function Na(e){for(let t=0;t<e.childCount;t++){let n=e.child(t);for(let e=0;e<n.childCount;e++)if(n.child(e).type.name===`tableHeaderCell`)return t}return 0}function Pa(e){return e.child(Na(e))}function Fa(e,t){return t>=e.childCount?null:e.child(t).attrs.align??null}function Ia(e,t,n){if(e.childCount===0)return;let r=Pa(e),i=t+1;for(let t=0;t<e.childCount;t++){let a=e.child(t),o=i+1;for(let e=0;e<a.childCount;e++){let t=a.child(e),i=Fa(r,e);(t.attrs.align??null)!==i&&n.setNodeMarkup(o,void 0,{...t.attrs,align:i}),o+=t.nodeSize}i+=a.nodeSize}}function La(e){let t,n;for(let r of e){if(!r.docChanged)continue;t!=null&&n!=null&&(t=r.mapping.map(t,-1),n=r.mapping.map(n,1));let e=r.mapping;for(let[r,i]of e.maps.entries()){let a=e.slice(r+1);i.forEach((e,r,i,o)=>{let s=a.map(i,-1),c=a.map(o,1);t=t==null?s:Math.min(t,s),n=n==null?c:Math.max(n,c)})}}if(!(t==null||n==null))return{from:t,to:n}}function Ra(){return new v({key:new y(`table-align-sync`),appendTransaction(e,t,n){if(!e.some(e=>e.docChanged))return;let r=La(e);if(!r)return;let i=n.doc,a=Math.max(0,Math.min(r.from,i.content.size)),o=Math.max(a,Math.min(r.to,i.content.size)),s;return i.nodesBetween(a,o,(e,t)=>e.type.name===`table`?(s??=n.tr,Ia(e,t,s),!1):!0),s?.docChanged?s:void 0}})}function za(){return m(Ra())}function Ba(e){let{selection:t}=e;if(St(t)){let{$anchorCell:e,$headCell:n}=t,r=e.depth-1,i=e.index(),a=n.index();return{table:e.node(r),tablePos:e.before(r),firstColumn:Math.min(i,a),lastColumn:Math.max(i,a)}}let{$from:n}=t;for(let e=n.depth;e>2;e--){let t=n.node(e).type.name;if(t===`tableCell`||t===`tableHeaderCell`){let t=n.index(e-1);return{table:n.node(e-2),tablePos:n.before(e-2),firstColumn:t,lastColumn:t}}}}function Va(e){return(t,n)=>{let r=Ba(t);if(!r||r.table.childCount===0)return!1;if(n){let{table:i,tablePos:a,firstColumn:o,lastColumn:s}=r,c=Na(i),l=a+1;for(let e=0;e<c;e++)l+=i.child(e).nodeSize;let u=i.child(c),d=t.tr,f=l+1;for(let t=0;t<u.childCount;t++){let n=u.child(t);t>=o&&t<=s&&(n.attrs.align??null)!==e&&d.setNodeMarkup(f,void 0,{...n.attrs,align:e}),f+=n.nodeSize}n(d)}return!0}}function Ha(e){let t=Ba(e);if(!(!t||t.table.childCount===0))return Fa(Pa(t.table),t.lastColumn)??void 0}function Ua(){return s({setTableColumnAlign:Va})}function Wa(){return g(ja(),Ma(),za(),Ua())}function Ga(e){let{$from:t}=e.selection;for(let e=t.depth;e>0;e--){let n=t.node(e).type.name;if(n===`tableCell`||n===`tableHeaderCell`)return!0}return!1}const Ka=`paragraph`;function qa(){return g(p({name:`tableCell`,content:Ka}),p({name:`tableHeaderCell`,content:Ka}))}const Ja=(e,t)=>{let{selection:n}=e;return!St(n)||!n.isColSelection()||!n.isRowSelection()?!1:xt(e,t)};function Ya(){return _(l({Backspace:Ja,Delete:Ja}),t.high)}function Xa(){return g(bt(),yt(),mt(),vt(),qa(),Wa(),_t({allowTableNodeSelection:!0}),ht(),gt(),Ya())}function Za(e){let{selection:t}=e,{$from:n,$to:r}=t;if(oe(t)&&n.depth===0||n.depth>0&&r.depth>0&&n.index(0)===r.index(0))return n.index(0)}function Qa(e){return(t,n)=>{if(Ga(t))return!1;let r=Za(t);if(r==null)return!1;let i=r+e;if(i<0||i>=t.doc.childCount)return!1;if(n){let{selection:a}=t,o=Math.min(r,i),s=a.$from.posAtIndex(o,0),c=t.doc.child(o),l=t.doc.child(o+1),u=t.tr.replaceWith(s,s+c.nodeSize+l.nodeSize,[l,c]),d=e===-1?-c.nodeSize:l.nodeSize,f=oe(a)?Te.create(u.doc,a.from+d):x.create(u.doc,a.anchor+d,a.head+d);u.setSelection(f),n(u.scrollIntoView())}return!0}}function $a(e){return(t,n,r)=>nt(e)(t,n,r)||Qa(e===`up`?-1:1)(t,n,r)}function eo(){return l({"Alt-ArrowUp":$a(`up`),"Alt-ArrowDown":$a(`down`)})}function to(){return p({name:`paragraph`,content:`inline*`,group:`block`,whitespace:`pre`,parseDOM:[{tag:`p`}],toDOM(){return[`p`,0]}})}function no(){return g(_(to(),t.highest),Ct(),wt())}const q=new y(`meowdownPendingReplacement`);function J(e){return q.getState(e)?.pending??null}function ro(e,t){switch(e.type){case`start`:return{pending:{from:e.from,to:e.to,mode:e.mode,text:``}};case`append`:return t.pending?{pending:{...t.pending,text:t.pending.text+e.text}}:t;case`accept`:return t.pending?{pending:null,ended:{pending:t.pending,outcome:`accepted`}}:t;case`discard`:return t.pending?{pending:null,ended:{pending:t.pending,outcome:`discarded`}}:t}}const io=new v({key:q,state:{init:()=>({pending:null}),apply:(e,t)=>{let n=e.getMeta(q);if(n)return ro(n,t);if(e.docChanged&&t.pending){let n=e.mapping.mapResult(t.pending.from,1),r=e.mapping.mapResult(t.pending.to,-1),i=Math.min(n.pos,r.pos),a=Math.max(n.pos,r.pos);return(n.deletedAfter&&r.deletedBefore||i>=a)&&t.pending.mode===`replace`?{pending:null,ended:{pending:t.pending,outcome:`discarded`}}:{pending:{...t.pending,from:i,to:a}}}return t}},props:{decorations:e=>{let t=J(e);return!t||t.from>=t.to?null:S.create(e.doc,[Ee.inline(t.from,t.to,{class:`md-pending-replacement`})])}}});function ao(e){return(t,n)=>{let{from:r,to:i,mode:a}=e;return r<0||i>t.doc.content.size||r>i||r===i&&a===`replace`?!1:(n?.(t.tr.setMeta(q,{type:`start`,from:r,to:i,mode:a})),!0)}}function oo(e){return(t,n)=>J(t)?(n?.(t.tr.setMeta(q,{type:`append`,text:e})),!0):!1}function so(){return(e,t)=>J(e)?(t?.(e.tr.setMeta(q,{type:`discard`})),!0):!1}function co(e={}){return(t,n)=>{let r=J(t);if(!r||!r.text.trim())return!1;if(n){let i=e.mode??r.mode,a=Go(t.schema),o=Z(r.text,{nodes:a}),s=t.tr;if(s.setMeta(q,{type:`accept`}),i===`append`){let e=t.doc.resolve(r.to).after(1);s.insert(e,o.content),s.setSelection(x.near(s.doc.resolve(e+o.content.size),-1))}else{let e=t.doc.resolve(r.from),n=t.doc.resolve(r.to),i=o.childCount===1?o.firstChild:null;i?.type.name===`paragraph`&&e.sameParent(n)&&e.parent.isTextblock?(s.replaceWith(r.from,r.to,i.content),s.setSelection(x.near(s.doc.resolve(r.from+i.content.size),-1))):(s.replaceRange(r.from,r.to,new C(o.content,0,0)),s.setSelection(x.near(s.doc.resolve(s.mapping.map(r.to)),-1)))}n(s.scrollIntoView())}return!0}}function lo(){return s({startPendingReplacement:ao,appendPendingReplacementText:oo,acceptPendingReplacement:co,discardPendingReplacement:so})}function uo(){return l({"Mod-Enter":co(),Escape:so()})}function fo(){return g(m(io),lo(),uo())}function po(e){return m(new v({view:()=>({update:(t,n)=>{let r=q.getState(n),i=q.getState(t.state);!i||r===i||(i.pending?i.pending!==r?.pending&&e({type:`update`,pending:i.pending}):i.ended&&i.ended!==r?.ended&&e({type:`ended`,pending:i.ended.pending,outcome:i.ended.outcome}))}})}))}function mo(e){return e.left===e.right&&e.top===e.bottom}function Y(e,t,n){if(t<0||t>e.state.doc.content.size)return;let r;try{r=e.coordsAtPos(t,n)}catch{return}return mo(r)?void 0:r}function ho(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 go(e){let t=e.state,n=t.selection.head,r=F(t,n),i=I(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=Y(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 _o(e){let t=e.state,n=t.selection.head;for(let r of Ht){let i=T(t,n,r);if(i==null||i.from!==n&&i.to!==n)continue;let a=vo(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 vo(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 yo(e){return go(e)??_o(e)}const bo=new y(`meowdown-scroll-to-selection`);function xo(e){let t=e.state.selection;if(!h(t)||Y(e,t.head,1)!=null)return!1;let n=yo(e);if(n==null)return!1;let r=e.domAtPos(t.head).node;return To(e,{left:n.left,right:n.left,top:n.top,bottom:n.top+n.height},r),!0}function X(e,t){return typeof e==`number`?e:e[t]}function So(e){let t=e.assignedSlot??e.parentNode;return t?.nodeType===11?t.host:t}function Co(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 wo(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 To(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=So(e);continue}let n=e,o=n===a.body,s=o?Co(a):wo(n),c=0,l=0;if(t.top<s.top+X(r,`top`)?l=-(s.top-t.top+X(i,`top`)):t.bottom>s.bottom-X(r,`bottom`)&&(l=t.bottom-t.top>s.bottom-s.top?t.top+X(i,`top`)-s.top:t.bottom-s.bottom+X(i,`bottom`)),t.left<s.left+X(r,`left`)?c=-(s.left-t.left+X(i,`left`)):t.right>s.right-X(r,`right`)&&(c=t.right-s.right+X(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:So(n)}}function Eo(){return m(new v({key:bo,props:{handleScrollToSelection:xo}}))}function Do(e,t){return(n,r)=>{let i=e<0?b.atStart(n.doc):b.atEnd(n.doc),a=t?x.between(n.selection.$anchor,i.$head):i;return n.selection.eq(a)||r?.(n.tr.setSelection(a).scrollIntoView()),!0}}function Oo(){return l({"Meta-ArrowUp":Do(-1,!1),"Meta-ArrowDown":Do(1,!1),"Shift-Meta-ArrowUp":Do(-1,!0),"Shift-Meta-ArrowDown":Do(1,!0)})}function ko(e){e.offsetWidth}const Ao=new y(`meowdown-virtual-caret`),jo=[`md-virtual-caret-blink`,`md-virtual-caret-blink2`];function Mo(e){let t=e.height*.19999999999999996;return{left:e.left,top:e.top-t/2,height:e.height+t}}function No(e){let t=ho(e)??go(e);return t==null?_o(e):Mo(t)}function Po(e,t){return e==null||t==null?e===t:e.left===t.left&&e.top===t.top&&e.height===t.height}var Fo=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=jo[this.#s]}#l=()=>{let e=this.#e;if(e.isDestroyed)return;let t=e.state,n=t.selection,r=h(n)&&n.empty?No(e):void 0,i=r!=null&&D(t)===`hide`?Vn(t,n.head):void 0;if(Po(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&&(ko(this.#n),this.#n.style.transitionProperty=``)}};function Io(){return m(new v({key:Ao,view:e=>new Fo(e)}))}function Lo(e){return g(no(),be(),Tn(),Ce(),ye(),wa(),jn(),Xa(),gn(),$n(),er(),Ci(),sn(),wn(),eo(),Oo(),si(e),Hi(),Xi(),Hr(),ka(),Rt(e.markMode??`focus`),Io(),Eo(),Zn(),en({marks:Ht.map(e=>({name:e,modes:[`hide`,`focus`,`show`]}))}),a(),i(),c(),xe(),we(),Se(),Sn(),fo())}function Ro(e={}){return Lo(e)}const zo=ve(()=>{let e=Ro().schema;if(e==null)throw Error(`Unexpected empty schema`);return e}),Bo=ve(()=>r(zo())),Vo=ve(()=>n(zo())),Ho=`meowdown_mark_builders`;function Uo(e){let t=e.cached[Ho];if(t)return t;let r=n(e);return e.cached[Ho]=r,r}const Wo=`meowdown_node_builders`;function Go(e){let t=e.cached[Wo];if(t)return t;let n=r(e);return e.cached[Wo]=n,n}function Z(e,t={}){let{nodes:n=Bo(),frontmatter:r=!1}=t,i,a=e;if(r){let[t,n]=qo(e);i=t,n&&(a=e.slice(n))}let o=Jo(n,Mr.parse(a).cursor(),a);return n.doc(i===void 0?{}:{frontmatter:i},o)}const Ko=/^---[ \t]*\r?\n([\s\S]*?\n)?---[ \t]*(?:\r?\n|$)/;function qo(e){let t=Ko.exec(e);return t?[(t[1]??``).replace(/\r?\n$/,``),t[0].length]:[]}function Jo(e,t,n){let r=[];if(!t.firstChild())return r;let i;do i!=null&&Yo(r,e,n,i,t.from),i=t.to,r.push(...Xo(e,t,n));while(t.nextSibling());return t.parent(),r}function Yo(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 Xo(e,t,n){switch(t.type.id){case H.ATXHeading1:return[Q(e,t,n,1,!1)];case H.ATXHeading2:return[Q(e,t,n,2,!1)];case H.ATXHeading3:return[Q(e,t,n,3,!1)];case H.ATXHeading4:return[Q(e,t,n,4,!1)];case H.ATXHeading5:return[Q(e,t,n,5,!1)];case H.ATXHeading6:return[Q(e,t,n,6,!1)];case H.SetextHeading1:return[Q(e,t,n,1,!0)];case H.SetextHeading2:return[Q(e,t,n,2,!0)];case H.Paragraph:return[ns(e,t,n)];case H.CommentBlock:return[rs(e,t,n)];case H.HTMLBlock:case H.ProcessingInstructionBlock:return[ns(e,t,n)];case H.Blockquote:return[is(e,t,n)];case H.BulletList:return as(e,t,n,`bullet`);case H.OrderedList:return as(e,t,n,`ordered`);case H.FencedCode:case H.CodeBlock:return[ss(e,t,n)];case H.BlockMath:return[cs(e,t,n)];case H.HorizontalRule:{let r=n.slice(t.from,t.to).trimEnd();return[e.horizontalRule({marker:r===`---`?null:r})]}case H.Table:return[ls(e,t,n)];case H.Task:return[ns(e,t,n)];default:return n.slice(t.from,t.to).trim()===``?[]:(console.warn(`[meowdown] unsupported lezer block "${t.type.name}"`),[ns(e,t,n)])}}function Q(e,t,n,r,i){let a=t.from,o=t.from,s=t.to,c=-1,l=-1;if(t.firstChild()){t.type.id===H.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===H.HeaderMark&&n>o&&(s=n,c=n,l=r),t.parent()}let u=es(n.slice(o,s),$(n,o)).trim(),d=i?Zo(n,c,l)||1:null,f=!i&&c>=0&&Qo(n,c,l)||null;return e.heading({level:r,setextUnderline:d,closingHashes:f},u)}function Zo(e,t,n){if(t<0)return 0;let r=0;for(let i=t;i<n;i++){let t=e.charCodeAt(i);(t===61||t===45)&&r++}return r}function Qo(e,t,n){if(t<0)return 0;let r=0;for(let i=t;i<n;i++)e.charCodeAt(i)===35&&r++;return r}function $(e,t){let n=e.lastIndexOf(`
3
- `,t-1)+1,r=0;for(let i=n;i<t;i++)r+=e.charCodeAt(i)===9?4-r%4:1;return r}function $o(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 es(e,t){return t===0||!e.includes(`
4
- `)?e:e.split(`
5
- `).map((e,n)=>n===0?e:$o(e,t)).join(`
6
- `)}function ts(e,t,n){return e.paragraph(es(t,n))}function ns(e,t,n){let r=t.from,i=t.to,a=$(n,r);if(t.firstChild()){let o=``,s=r;do t.type.id===H.QuoteMark&&(o+=n.slice(s,t.from),s=t.to,z(n.charCodeAt(s))&&(s+=1));while(t.nextSibling());return t.parent(),o+=n.slice(s,i),ts(e,o,a)}return ts(e,n.slice(r,i),a)}function rs(e,t,n){let r=$(n,t.from),i=es(n.slice(t.from,t.to),r);return e.htmlComment({content:i})}function is(e,t,n){let r=[];if(t.firstChild()){let i;do{if(t.type.id===H.QuoteMark)continue;i!=null&&Yo(r,e,n,i,t.from),i=t.to,r.push(...Xo(e,t,n))}while(t.nextSibling());t.parent()}return e.blockquote(r)}function as(e,t,n,r){let i=[];if(t.firstChild()){do t.type.id===H.ListItem&&i.push(os(e,t,n,r));while(t.nextSibling());t.parent()}return i}function os(e,t,n,r){let i=[],a,o,s,c,l,u;if(t.firstChild()){do{if(t.type.id!==H.ListMark&&u==null&&(u=$(n,t.from)),t.type.id===H.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=$(n,t.to);continue}if(r===`bullet`&&t.type.id===H.Task){let r=t.from,s=t.to;if(a=!1,t.firstChild()){if(t.type.id===H.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()}z(n.charCodeAt(r))&&(r+=1);let c=n.slice(r,s);i.push(ts(e,c,$(n,r)));continue}i.push(...Xo(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 ss(e,t,n){let r=t.type.id===H.CodeBlock,i=``,a=``,o=r?`indented`:null,s=null,c=!1;if(t.firstChild()){do switch(t.type.id){case H.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 H.CodeInfo:i=n.slice(t.from,t.to);break;case H.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 cs(e,t,n){let r=``;if(t.firstChild()){do t.type.id===H.CodeText&&(r+=n.slice(t.from,t.to));while(t.nextSibling());t.parent()}return e.codeBlock({language:`math`,fenceStyle:`dollar`,fenceLength:null},r)}function ls(e,t,n){let r=[];if(t.firstChild()){do t.type.id===H.TableDelimiter&&(r=us(n.slice(t.from,t.to)));while(t.nextSibling());t.parent()}let i=[];if(t.firstChild()){do{let a=t.type.id;a===H.TableHeader?i.push(ds(e,t,n,!0,r)):a===H.TableRow&&i.push(ds(e,t,n,!1,r))}while(t.nextSibling());t.parent()}return e.table(i)}function us(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 ds(e,t,n,r,i){let a=i.length,o=Array(a).fill(``);if(t.firstChild()){let e=t.type.id===H.TableDelimiter,r=0;do if(t.type.id===H.TableDelimiter)r++;else if(t.type.id===H.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 fs(e,t={}){let n=new gs;return t.frontmatter&&ps(e.attrs.frontmatter,n),_s(e,n),n.finish()}function ps(e,t){e!==null&&(t.write(`---`),t.write(`
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 ee,getMarkType as te,getNodeType as ne,isAllSelection as re,isApple as ie,isAtBlockStart as ae,isNodeSelection as oe,isTextSelection as h,toggleNode as se,union as g,unsetBlockType as ce,withPriority as le,withPriority as _,withSkipCodeBlock as ue}from"@prosekit/core";import{defineCodeBlock as de,defineCodeBlockHighlight as fe,defineCodeBlockPreviewPlugin as pe,isCodeBlockPreviewHiddenDecoration as me}from"@prosekit/extensions/code-block";import{definePlaceholder as he}from"@prosekit/extensions/placeholder";import{defineReadonly as ge}from"@prosekit/extensions/readonly";import{isElementLike as _e,isHTMLElement as ve,once as ye}from"@ocavue/utils";import{defineBlockquote as be}from"@prosekit/extensions/blockquote";import{defineDoc as xe}from"@prosekit/extensions/doc";import{defineGapCursor as Se}from"@prosekit/extensions/gap-cursor";import{defineModClickPrevention as Ce}from"@prosekit/extensions/mod-click-prevention";import{defineText as we}from"@prosekit/extensions/text";import{defineVirtualSelection as Te}from"@prosekit/extensions/virtual-selection";import{NodeSelection as Ee,Plugin as v,PluginKey as y,Selection as b,TextSelection as x}from"@prosekit/pm/state";import{Decoration as De,DecorationSet as S}from"@prosekit/pm/view";import Oe from"rehype-parse";import ke from"rehype-remark";import Ae from"remark-gfm";import je from"remark-stringify";import{unified as Me}from"unified";import{DOMParser as Ne,DOMSerializer as Pe,Fragment as C,Mark as Fe,Slice as w}from"@prosekit/pm/model";import{defineHeadingCommands as Ie,defineHeadingInputRule as Le,defineHeadingSpec as Re}from"@prosekit/extensions/heading";import{defineParagraphCommands as ze,defineParagraphKeymap as Be}from"@prosekit/extensions/paragraph";import{LanguageDescription as Ve}from"@codemirror/language";import{languages as He}from"@codemirror/language-data";import{classHighlighter as Ue,highlightTree as We}from"@lezer/highlight";import{createParser as Ge}from"prosemirror-highlight/lezer";import{defineTextBlockEnterRule as Ke}from"@prosekit/extensions/enter-rule";import{defineInputRule as qe,defineTextBlockInputRule as Je}from"@prosekit/extensions/input-rule";import{triggerAutocomplete as Ye}from"@prosekit/extensions/autocomplete";import{defineHorizontalRule as Xe}from"@prosekit/extensions/horizontal-rule";import{AddMarkStep as Ze,AddNodeMarkStep as Qe,RemoveMarkStep as $e,RemoveNodeMarkStep as et,ReplaceStep as tt,Step as nt,StepResult as rt,Transform as it}from"@prosekit/pm/transform";import{GFM as at,parser as ot}from"@lezer/markdown";import{defineListCommands as st,defineListDropIndicator as ct,defineListKeymap as lt,defineListSpec as ut,moveList as dt,toggleList as ft,wrapInList as T}from"@prosekit/extensions/list";import{createListRenderingPlugin as pt,createSafariInputMethodWorkaroundPlugin as mt,createToggleCollapsedCommand as ht,defaultAttributesGetter as gt,findCheckboxInListItem as _t,handleListMarkerMouseDown as vt,joinListElements as yt,listToDOM as bt,unwrapListSlice as xt,wrappingListInputRule as St}from"prosemirror-flat-list";import{defineTableCellSpec as Ct,defineTableCommands as wt,defineTableDropIndicator as Tt,defineTableEditingPlugin as Et,defineTableHeaderCellSpec as Dt,defineTableRowSpec as Ot,defineTableSpec as kt,deleteTable as At,isCellSelection as jt}from"@prosekit/extensions/table";import{closeHistory as Mt}from"@prosekit/pm/history";import{registerResizableHandleElement as Nt,registerResizableRootElement as Pt}from"@prosekit/web/resizable";function E(e,t,n,r){let i=e.doc.content.size;if(t<0||t>i)return;let a=e.doc.resolve(t);if(!(!a.parent.isTextblock||a.parent.type.spec.code))return ee(a,n,r)}const D=new y(`mark-mode`);function Ft(e){return D.getState(e)}function It(e){return new v({key:D,state:{init:()=>e,apply:(e,t)=>e.getMeta(D)??t},props:{attributes:t=>({"data-mark-mode":Ft(t)??e}),decorations:e=>{let t=Ft(e);if(t===`focus`)return zt(e);if(t===`hide`)return Bt(e)}}})}function Lt(e){return(t,n)=>O(t)===e?!1:(n?.(t.tr.setMeta(D,e)),!0)}function Rt(e){return g(m(It(e)),s({setMarkMode:Lt}))}function O(e){return D.getState(e)}function zt(e){return Vt(e,void 0)}function Bt(e){return Vt(e,{key:`math`})}function Vt(e,t){let{selection:n}=e;if(!n.empty)return S.empty;let r=n.$head,{parent:i}=r;if(!i.isTextblock||i.type.spec.code)return S.empty;let a=ee(r,te(e.schema,`mdPack`),t);return a?S.create(e.doc,[De.inline(a.from,a.to,{class:`show`})]):S.empty}const Ht=[`mdImage`,`mdWikilink`,`mdFile`];function k(e,t){let n=O(t);return n?e.flatMap(e=>e.modes.includes(n)?[e.name]:[]):[]}function Ut(e,t,n){for(let r of n){let n=E(e,t,r);if(n)return n}}function A(e,t,n){let r=Ut(e,t,n);return r&&r.to===t?r:void 0}function j(e,t,n){let r=Ut(e,t,n);return r&&r.from===t?r:void 0}function Wt(e,t){let{from:n,to:r,empty:i}=e.selection;if(i)return;let a=Ut(e,n,t);return a&&a.from===n&&a.to===r?a:void 0}function Gt(e,t){return x.create(e.doc,t.from,t.to)}function Kt(e,t,n,r){let i=e.doc.resolve(t);if(!(r===-1?i.parentOffset===0:i.parentOffset===i.parent.content.size)||i.depth===0)return;let a=r===-1?j(e,t,n):A(e,t,n),o=r===-1?i.before():i.after(),s=b.findFrom(e.doc.resolve(o),r);if(!s)return;let c=h(s)?r===-1?A(e,s.head,n):j(e,s.head,n):void 0;if(!(a==null&&c==null))return s}function qt(e){return(t,n)=>{let r=k(e,t);if(r.length===0||!h(t.selection))return!1;let i=t.selection;if(i.empty){let e=j(t,i.from,r);if(e)return n?.(t.tr.setSelection(Gt(t,e))),!0;if(A(t,i.from,r)&&i.from<t.doc.resolve(i.from).end())return n?.(t.tr.setSelection(x.create(t.doc,i.from+1))),!0;let a=Kt(t,i.from,r,1);return a?(n?.(t.tr.setSelection(a).scrollIntoView()),!0):!1}let a=Wt(t,r);return a?(n?.(t.tr.setSelection(x.create(t.doc,a.to))),!0):!1}}function Jt(e){return(t,n)=>{let r=k(e,t);if(r.length===0||!h(t.selection))return!1;let i=t.selection;if(i.empty){let e=A(t,i.from,r);if(e)return n?.(t.tr.setSelection(Gt(t,e))),!0;let a=Kt(t,i.from,r,-1);return a?(n?.(t.tr.setSelection(a).scrollIntoView()),!0):!1}let a=Wt(t,r);return a?(n?.(t.tr.setSelection(x.create(t.doc,a.from))),!0):!1}}function Yt(e,t){return(n,r)=>{let i=k(e,n);if(i.length===0||!h(n.selection))return!1;let{anchor:a,head:o}=n.selection,s=t===-1?A(n,o,i):j(n,o,i);if(s){let e=t===-1?s.from:s.to;return r?.(n.tr.setSelection(x.create(n.doc,a,e)).scrollIntoView()),!0}let c=Kt(n,o,i,t);return!c||!h(c)?!1:(r?.(n.tr.setSelection(x.create(n.doc,a,c.head)).scrollIntoView()),!0)}}function Xt(e){return(t,n)=>{let r=k(e,t);if(r.length===0||!t.selection.empty)return!1;let i=t.selection.from,a=A(t,i,r);return a?(n?.(t.tr.delete(a.from,a.to)),!0):!j(t,i,r)||i<=t.doc.resolve(i).start()?!1:(n?.(t.tr.delete(i-1,i)),!0)}}function Zt(e){return(t,n)=>{let r=k(e,t);if(r.length===0||!t.selection.empty)return!1;let i=t.selection.from,a=j(t,i,r);return a?(n?.(t.tr.delete(a.from,a.to)),!0):!A(t,i,r)||i>=t.doc.resolve(i).end()?!1:(n?.(t.tr.delete(i,i+1)),!0)}}const Qt=`md-atom-selected`;function $t(e){return new v({key:new y(`atom-mark-selection`),props:{decorations:t=>{let n=k(e,t);if(n.length===0||oe(t.selection))return;let r=Wt(t,n);if(r)return S.create(t.doc,[De.inline(r.from,r.to,{class:Qt})]);let{from:i,to:a,empty:o}=t.selection;if(o)return null;let s=[];return t.doc.nodesBetween(i,a,(e,t)=>{e.marks.some(e=>n.includes(e.type.name))&&s.push(De.inline(t,t+e.nodeSize,{class:Qt}))}),S.create(t.doc,s)}}})}function en({marks:e}){return g(_(l({ArrowRight:qt(e),ArrowLeft:Jt(e),"Shift-ArrowRight":Yt(e,1),"Shift-ArrowLeft":Yt(e,-1),Backspace:Xt(e),Delete:Zt(e)}),t.high),m($t(e)))}const tn=(e,t)=>{let n={type:`highlight`,children:e.all(t)};return e.patch(t,n),n},nn=(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 rn(){return Me().use(Oe).use(ke,{handlers:{mark:tn}}).use(Ae).use(je,{bullet:`-`,emphasis:`*`,strong:`*`,fence:"`",fences:!0,rule:`-`,ruleRepetition:3,listItemIndent:`one`,handlers:{highlight:nn}}).freeze()}const an=ye(rn);function on(e){return String(an().processSync(e))}function sn(e){if(e==null)return;let t=Number.parseInt(e,10);return Number.isSafeInteger(t)?t:void 0}function cn(e){let t=sn(e);return t!=null&&t>0?t:void 0}const ln=new Set([`mdMark`,`mdLinkUri`,`mdLinkTitle`]),un=new Set([`mdImage`,`mdWikilink`,`mdMath`,`mdFile`]),dn={mdStrong:`strong`,mdEm:`em`,mdCode:`code`,mdDel:`del`,mdHighlight:`mark`,mdLinkText:`a`};function fn(e){return e.find(e=>un.has(e.type.name))}function pn(e){return e.some(e=>ln.has(e.type.name))}function mn(e){let t=[];return e.forEach(e=>{if(!e.isText||!e.text)return;let n=fn(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}function hn(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 _n(t,r),r}function gn(e,t,n){return{tag:`${e}[data-md]`,node:t,priority:100,getAttrs:n,getContent:(e,t)=>{let n=(ve(e)?e:void 0)?.getAttribute(`data-md`)??``;return n?C.from(t.text(n)):C.empty}}}function _n(e,t){let n=[];for(let r of mn(e)){if(r.atom!=null){n.length=0,t.append(bn(r.atom,r.text));continue}for(let e of r.children)pn(e.marks)||(vn(n,e.marks.filter(e=>dn[e.type.name]),t),yn(n.at(-1)?.element??t,e.text??``))}}function vn(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(dn[r.type.name]??`span`);r.type.name===`mdLinkText`&&a.setAttribute(`href`,r.attrs.href),(e.at(-1)?.element??n).append(a),e.push({mark:r,element:a})}}function yn(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 bn(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 xn(){return p({name:`heading`,whitespace:`pre`})}function Sn(e){let t=e.attrs;return hn(`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 Cn(){return[1,2,3,4,5,6].map(e=>gn(`h${e}`,`heading`,t=>({level:e,setextUnderline:cn(t.getAttribute(`data-setext-underline`))??null,closingHashes:cn(t.getAttribute(`data-closing-hashes`))??null})))}function wn(){return f({type:`heading`,attr:`setextUnderline`,default:null,toDOM:e=>e==null?null:[`data-setext-underline`,String(e)],parseDOM:e=>cn(e.getAttribute(`data-setext-underline`))??null})}function Tn(){return f({type:`heading`,attr:`closingHashes`,default:null,toDOM:e=>e==null?null:[`data-closing-hashes`,String(e)],parseDOM:e=>cn(e.getAttribute(`data-closing-hashes`))??null})}function M(e){return ue(se({type:`heading`,attrs:{level:e}}))}const En=(e,t,n)=>ae(e,n)?.parent.type.name===`heading`&&ce()(e,t,n);function Dn(){return l({"Mod-1":M(1),"Mod-2":M(2),"Mod-3":M(3),"Mod-4":M(4),"Mod-5":M(5),"Mod-6":M(6),Backspace:En})}function On(){return g(Re(),xn(),wn(),Tn(),Le(),Ie(),Dn())}function kn(){return p({name:`paragraph`,content:`inline*`,group:`block`,whitespace:`pre`,parseDOM:[{tag:`p`}],toDOM(){return[`p`,0]}})}function An(e){return hn(`p`,e)}function jn(){return[gn(`p`,`paragraph`)]}function Mn(){return g(_(kn(),t.highest),ze(),Be())}function Nn(e){return{...e,paragraph:e=>({dom:An(e)}),heading:e=>({dom:Sn(e)})}}function Pn(){return o({serializeFragmentWrapper:e=>(...t)=>{let n=e(...t);for(let e of n.children)e.setAttribute(`data-meowdown`,``);return n},nodesFromSchemaWrapper:e=>(...t)=>Nn(e(...t))})}const Fn=new WeakMap;function In(e){let t=Fn.get(e);return t??(t=new Pe(Nn(Pe.nodesFromSchema(e)),Pe.marksFromSchema(e)),Fn.set(e,t)),t}const Ln=new y(`meowdown-html-paste`);function Rn(e){return e.includes(`data-meowdown`)?!0:e.includes(`data-pm-slice`)&&e.includes(`md-mark`)}function zn(){return m(new v({key:Ln,props:{transformPastedHTML:(e,t)=>{if(Rn(e))return e;let n=t.state.selection.$from.parent;if(!n.inlineContent||n.type.spec.code)return e;let r=on(e);if(!r.trim())return e;let i=X(r,{nodes:ec(t.state.schema)}),a=In(t.state.schema),o=document.createElement(`div`);return o.append(a.serializeFragment(i.content)),o.innerHTML}}}))}function Bn(e){return new Ne(e,[...jn(),...Cn(),...Ne.fromSchema(e).rules])}const Vn=new y(`meowdown-clipboard-parser`);function Hn(){return m(({schema:e})=>new v({key:Vn,props:{clipboardParser:Bn(e)}}))}function Un(e,t){let n=t.replaceAll(/\r\n?/g,`
3
+ `).replace(/^\n+/,``).replace(/\n+$/,``);if(!n)return w.empty;let r=ne(e,`paragraph`),i=[],a=n.split(/(\n{2,})/);for(let t=0;t<a.length;t++){let n=a[t];if(t%2==0)i.push(r.create(null,n?e.text(n):void 0));else{let e=n.length-1;for(let t=1;t<e;t++)i.push(r.create())}}return w.maxOpen(C.from(i))}function Wn(e,t,n){let r=n.marks(),i=Pe.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 Ne.fromSchema(e).parseSlice(a,{preserveWhitespace:!0,context:n})}function Gn(){return m(new v({key:new y(`meowdown-plain-paste`),props:{clipboardTextParser:(e,t,n,r)=>{let{schema:i}=r.state;return n?Wn(i,e,t):Un(i,e)}}}))}function N(e){return e===32||e===9||e===10||e===13}function Kn(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 qn(e,t=0){return Kn(e,96,t)}function P(e,t={}){let n=new Zn;return t.frontmatter&&Jn(e.attrs.frontmatter,n),Qn(e,n),n.finish()}function Jn(e,t){e!==null&&(t.write(`---`),t.write(`
7
4
  `),e!==``&&(t.write(e),t.write(`
8
- `)),t.write(`---`),t.closeBlock())}const ms=[``,`# `,`## `,`### `,`#### `,`##### `,`###### `];function hs(e,t){let n=e.attrs,r=n.setextUnderline;if(r!=null&&e.content.size>0&&n.level<=2){xs(e,t);let i=n.level===1?`=`:`-`;t.write(`
9
- `+i.repeat(Math.max(1,r))),t.closeBlock();return}t.write(ms[n.level]??`# `),xs(e,t);let i=n.closingHashes;i!=null&&i>0&&t.write(` `+`#`.repeat(i)),t.closeBlock()}var gs=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(`
5
+ `)),t.write(`---`),t.closeBlock())}const Yn=[``,`# `,`## `,`### `,`#### `,`##### `,`###### `];function Xn(e,t){let n=e.attrs,r=n.setextUnderline;if(r!=null&&e.content.size>0&&n.level<=2){nr(e,t);let i=n.level===1?`=`:`-`;t.write(`
6
+ `+i.repeat(Math.max(1,r))),t.closeBlock();return}t.write(Yn[n.level]??`# `),nr(e,t);let i=n.closingHashes;i!=null&&i>0&&t.write(` `+`#`.repeat(i)),t.closeBlock()}var Zn=class{constructor(){this.parts=[],this.linePrefix=``,this.pendingFirst=null,this.atLineStart=!0,this.deferredBlankPrefix=null}write(e){if(e===``)return;if(this.emitDeferredBlankLine(),this.atLineStart&&=(this.parts.push(this.pendingFirst??this.linePrefix),this.pendingFirst=null,!1),!e.includes(`
10
7
  `)){this.parts.push(e);return}let t=e.split(`
11
8
  `);for(let e=0;e<t.length;e++)e>0&&this.parts.push(`
12
9
  `,this.linePrefix),t[e]!==``&&this.parts.push(t[e])}closeEmptyBlock(){if(!this.atLineStart||this.pendingFirst!==null){this.closeBlock();return}this.parts.length!==0&&(this.emitDeferredBlankLine(),this.deferredBlankPrefix=this.linePrefix)}closeBlock(){this.atLineStart&&this.pendingFirst!==null&&(this.emitDeferredBlankLine(),this.parts.push(this.pendingFirst.trimEnd()),this.pendingFirst=null,this.atLineStart=!1),this.atLineStart||this.parts.push(`
13
10
  `),this.atLineStart=!0,this.deferredBlankPrefix=this.linePrefix}suppressBlank(){this.deferredBlankPrefix=null}withPrefix(e,t,n){let r=this.linePrefix,i=this.pendingFirst;if(this.linePrefix=r+e,t!==null){let e=i??r;this.pendingFirst=e+t}n(),this.linePrefix=r,this.pendingFirst=t===null?i:null}finish(){return this.parts.join(``).replace(/\s+$/,``)+`
14
11
  `}emitDeferredBlankLine(){let e=this.deferredBlankPrefix;e!==null&&(this.parts.push(e.trimEnd(),`
15
- `),this.deferredBlankPrefix=null)}};function _s(e,t){switch(e.type.name){case`doc`:vs(e,t);return;case`paragraph`:if(e.childCount===0){t.closeEmptyBlock();return}xs(e,t),t.closeBlock();return;case`heading`:hs(e,t);return;case`blockquote`:t.withPrefix(`> `,`> `,()=>vs(e,t)),t.closeBlock();return;case`list`:Ss(e,t,bs(e));return;case`codeBlock`:Cs(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`:Es(e,t);return;case`text`:e.text&&t.write(e.text);return}}function vs(e,t,n=!1){let r=e.childCount,i=0;for(;i<r;){let a=e.child(i);if(a.type.name!==`list`){n&&i>0&&t.suppressBlank(),_s(a,t),i++;continue}let o=i+1;for(;o<r&&e.child(o).type.name===`list`;)o++;let s=ys(e,i,o);for(let r=i;r<o;r++)(r===i?n&&i>0:s)&&t.suppressBlank(),Ss(e.child(r),t,s);i=o}}function ys(e,t,n){for(let r=t;r<n;r++)if(!bs(e.child(r)))return!1;return!0}function bs(e){let t=e.childCount;for(let n=0;n<t;n++){let t=e.child(n);if(t.type.name!==`list`&&!(t.type.name===`paragraph`&&n===0))return!1}return!0}function xs(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 Ss(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)}`,ee=r===`task`?`${m}[${l?f:` `}] `:m,te=` `.repeat(m.length);t.withPrefix(te,ee,()=>vs(e,t,n)),t.closeBlock()}function Cs(e,t){let n=e.attrs,r=n.language||``,i=e.textContent;if(n.fenceStyle===`indented`&&!r){let e=ws(i);if(e!=null){t.write(e),t.closeBlock();return}}if(n.fenceStyle===`dollar`&&r===`math`&&!Ts(i)){t.write(`$$`),t.write(`
12
+ `),this.deferredBlankPrefix=null)}};function Qn(e,t){switch(e.type.name){case`doc`:$n(e,t);return;case`paragraph`:if(e.childCount===0){t.closeEmptyBlock();return}nr(e,t),t.closeBlock();return;case`heading`:Xn(e,t);return;case`blockquote`:t.withPrefix(`> `,`> `,()=>$n(e,t)),t.closeBlock();return;case`list`:rr(e,t,tr(e));return;case`codeBlock`:ir(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`:sr(e,t);return;case`text`:e.text&&t.write(e.text);return}}function $n(e,t,n=!1){let r=e.childCount,i=0;for(;i<r;){let a=e.child(i);if(a.type.name!==`list`){n&&i>0&&t.suppressBlank(),Qn(a,t),i++;continue}let o=i+1;for(;o<r&&e.child(o).type.name===`list`;)o++;let s=er(e,i,o);for(let r=i;r<o;r++)(r===i?n&&i>0:s)&&t.suppressBlank(),rr(e.child(r),t,s);i=o}}function er(e,t,n){for(let r=t;r<n;r++)if(!tr(e.child(r)))return!1;return!0}function tr(e){let t=e.childCount;for(let n=0;n<t;n++){let t=e.child(n);if(t.type.name!==`list`&&!(t.type.name===`paragraph`&&n===0))return!1}return!0}function nr(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 rr(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)}`,ee=r===`task`?`${m}[${l?f:` `}] `:m,te=` `.repeat(m.length);t.withPrefix(te,ee,()=>$n(e,t,n)),t.closeBlock()}function ir(e,t){let n=e.attrs,r=n.language||``,i=e.textContent;if(n.fenceStyle===`indented`&&!r){let e=ar(i);if(e!=null){t.write(e),t.closeBlock();return}}if(n.fenceStyle===`dollar`&&r===`math`&&!or(i)){t.write(`$$`),t.write(`
16
13
  `),i&&(t.write(i),t.write(`
17
- `)),t.write(`$$`),t.closeBlock();return}let a=n.fenceStyle===`tilde`,o=wi(i,a?126:96,2)+1,s=(a?`~`:"`").repeat(Math.max(n.fenceLength??0,o));t.write(s),r&&t.write(r),t.write(`
14
+ `)),t.write(`$$`),t.closeBlock();return}let a=n.fenceStyle===`tilde`,o=Kn(i,a?126:96,2)+1,s=(a?`~`:"`").repeat(Math.max(n.fenceLength??0,o));t.write(s),r&&t.write(r),t.write(`
18
15
  `),i&&(t.write(i),t.write(`
19
- `)),t.write(s),t.closeBlock()}function ws(e){if(e===``)return;let t=e.split(`
16
+ `)),t.write(s),t.closeBlock()}function ar(e){if(e===``)return;let t=e.split(`
20
17
  `);if(!(t[0]===``||t[t.length-1]===``)){for(let e=0;e<t.length;e++)t[e]!==``&&(t[e]=` ${t[e]}`);return t.join(`
21
- `)}}function Ts(e){return e.split(`
22
- `).some(e=>e.trim()===`$$`)}function Es(e,t){let n=e.childCount;if(n===0)return;let r=[],i=0,a=-1;for(let t=0;t<n;t++){let n=e.child(t),o=[],s=!1;for(let e=0;e<n.childCount;e++){let t=n.child(e);t.type.name===`tableHeaderCell`&&(s=!0),o.push(ks(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(Ds(n))}let c=`| `+s.join(` | `)+` |`,l=a>=0?r[a]:Array(i).fill(``);t.write(Os(l,i)),t.write(`
18
+ `)}}function or(e){return e.split(`
19
+ `).some(e=>e.trim()===`$$`)}function sr(e,t){let n=e.childCount;if(n===0)return;let r=[],i=0,a=-1;for(let t=0;t<n;t++){let n=e.child(t),o=[],s=!1;for(let e=0;e<n.childCount;e++){let t=n.child(e);t.type.name===`tableHeaderCell`&&(s=!0),o.push(ur(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(cr(n))}let c=`| `+s.join(` | `)+` |`,l=a>=0?r[a]:Array(i).fill(``);t.write(lr(l,i)),t.write(`
23
20
  `),t.write(c);for(let e=0;e<n;e++)e!==a&&(t.write(`
24
- `),t.write(Os(r[e],i)));t.closeBlock()}function Ds(e){switch(e){case`left`:return`:--`;case`center`:return`:-:`;case`right`:return`--:`;default:return`---`}}function Os(e,t){let n=`|`;for(let r=0;r<t;r++)n+=` `+(e[r]??``)+` |`;return n}function ks(e){let t=e.textContent.trim();return!t.includes(`|`)&&!t.includes(`
21
+ `),t.write(lr(r[e],i)));t.closeBlock()}function cr(e){switch(e){case`left`:return`:--`;case`center`:return`:-:`;case`right`:return`--:`;default:return`---`}}function lr(e,t){let n=`|`;for(let r=0;r<t;r++)n+=` `+(e[r]??``)+` |`;return n}function ur(e){let t=e.textContent.trim();return!t.includes(`|`)&&!t.includes(`
25
22
  `)?t:t.replaceAll(`|`,String.raw`\|`).replaceAll(`
26
- `,` `)}function As(e){return e.replace(/\n+$/u,``)}function js(e){return/^[\s>]*$/u.test(e)}function Ms(e){return e.split(`
27
- `).filter(e=>!js(e))}function Ns(e){return e.trim().replaceAll(/\s+/gu,` `)}function Ps(e,t={}){let n=fs(Z(e,{frontmatter:t.frontmatter}),{frontmatter:t.frontmatter});if(As(n)===As(e))return`exact`;let r=Ms(e),i=Ms(n);return r.length===i.length&&r.every((e,t)=>Ns(e)===Ns(i[t]))?`normalizing`:`lossy`}const Fs=(e,t)=>{let{$from:n,empty:r}=e.selection;if(!r||n.depth!==1||n.index(0)!==0||n.parent.type.name!==`heading`||n.parentOffset!==n.parent.content.size)return!1;if(t){let r=ne(e.schema,`list`),i=ne(e.schema,`paragraph`),a=r.create({kind:`bullet`},i.create()),o=n.after(),s=e.tr.insert(o,a);s.setSelection(x.create(s.doc,o+2)),t(s.scrollIntoView())}return!0};function Is(){return _(l({Enter:Fs}),t.high)}const Ls=new Set([`MscGen`,`Xù`,`MsGenny`,`Angular Template`,`Brainfuck`,`Esper`,`Oz`,`Factor`,`Squirrel`,`Yacas`,`mIRC`,`FCL`,`ECL`,`MUMPS`,`Pig`,`Asterisk`,`Z80`,`Mathematica`]),Rs=Oe.map(e=>({label:e.name,value:e.name.toLowerCase()})).filter(e=>!Ls.has(e.label)).concat([{label:`Plain text`,value:``},{label:`Math`,value:`math`}]).sort((e,t)=>e.label.localeCompare(t.label));function zs(){return typeof window>`u`?!1:window.matchMedia(`(prefers-color-scheme: dark)`).matches}const Bs=/^(?:www\.|mobile\.)?(?:twitter\.com|x\.com)$/i,Vs=/\/status(?:es)?\/(\d+)/;function Hs(e){let t;try{t=new URL(e)}catch{return}if(Bs.test(t.hostname))return Vs.exec(t.pathname)?.[1]}const Us=e=>{let t=Hs(e);if(!t)return;let n=zs()?`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 Ws(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 Gs=/^(?:www\.|m\.)?(?:youtube\.com|youtube-nocookie\.com)$/i,Ks=/^(?:www\.)?youtu\.be$/i,qs=/^[\w-]{11}$/;function Js(e){let t;try{t=new URL(e)}catch{return}let n=null;if(Ks.test(t.hostname))n=t.pathname.slice(1);else if(Gs.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||!qs.test(n))return;let r=t.searchParams.get(`start`)??t.searchParams.get(`t`),i=r?Ys(r):void 0;return{videoId:n,startSeconds:i}}function Ys(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 Xs=[e=>{let t=Js(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}},Us];function Zs(e){for(let t of Xs){let n=t(e);if(n)return n}}function Qs(e,t){return e.clipboardData?.getData(`text/plain`)||t.content.textBetween(0,t.content.size,`
28
- `)}const $s=new y(`meowdown-embed-paste`);function ec(e){let t=e.trim();if(!(!t||/\s/.test(t)))return Zs(t)?t:void 0}function tc(e,t){let{from:n,to:r}=e.state.selection;e.dispatch(Tt(e.state.tr.insertText(t,n,r)));let i=e.state.tr.insertText(`![](${t})`,n,n+t.length);e.dispatch(Tt(i))}function nc(){return m(new v({key:$s,props:{handlePaste:(e,t,n)=>{let r=e.state.selection.$from.parent;if(!r.inlineContent||r.type.spec.code)return!1;let i=Qs(t,n);if(!i)return!1;let a=ec(i);return a?(tc(e,a),!0):!1}}}))}const rc=new y(`meowdown-exit-boundary`);function ic(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&&b.findFrom(a,t))}function ac(e,t){let{state:n}=e,{selection:r}=n;return h(r)&&!r.empty||re(r)||r.$from.parent.inlineContent&&!e.endOfTextblock(t<0?`up`:`down`)?!0:ic(n,t)}function oc(e){return new v({key:rc,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||ac(t,r)||e({direction:r<0?`up`:`down`,event:n})===!1)}}})}function sc(e){return _(m(oc(e)),t.low)}function cc(e){return!!e.type?.startsWith(`image/`)}function lc(e,t){return cc(e)?`![](${t})`:`[${fc(e.name)}](${t})`}function uc(e,t){return!e||!t.onFilePaste?[]:Array.from(e.files)}const dc=e=>{console.error(`[meowdown] failed to save pasted file:`,e)};function fc(e){return e.replaceAll(/[\\[\]]/g,String.raw`\$&`)}async function pc(e,t,n,r){let{onFilePaste:i}=n;if(!i)return;let a=n.onFileSaveError??dc,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=lc(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 mc(e){return new v({key:new y(`file-paste`),props:{handlePaste:(t,n)=>{let r=uc(n.clipboardData,e);return r.length===0?!1:(pc(t,r,e),!0)},handleDrop:(t,n)=>{let r=uc(n.dataTransfer,e);return r.length===0?!1:(pc(t,r,e,t.posAtCoords({left:n.clientX,top:n.clientY})?.pos),!0)}}})}function hc(e={}){return _(m(mc(e)),t.high)}const gc=new y(`meowdown-file-click`);function _c(e,t){let n=T(e,t,`mdFile`);if(!n)return;let{href:r,name:i}=n.mark.attrs;return{href:r,name:i}}function vc(e){return m(new v({key:gc,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=_c(t.state,t.posAtDOM(a,0));return o?(e({href:o.href,name:o.name,event:r}),!0):!1}}}))}const yc=[`KB`,`MB`,`GB`,`TB`];function bc(e){let t=e,n=`B`;for(let e of yc){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 xc=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 Sc(e){let t=e.split(/[?#]/,1)[0],n=t.lastIndexOf(`.`);if(n<0)return`generic`;let r=t.slice(n+1).toLowerCase();return xc.get(r)??`generic`}const Cc=`http://www.w3.org/2000/svg`;function wc(){let e=document.createElementNS(Cc,`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(Cc,`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 Tc=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=Sc(this.#a.href),this.#n.title=this.#a.name,this.#e.appendChild(this.#n),this.#n.appendChild(wc()),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=bc(n))}};function Ec(e={}){return d({name:`mdFile`,constructor:t=>new Tc(t,e)})}function Dc(e){return m(new v({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 Oc=new y(`meowdown-tag-click`);function kc(e,t){let n=T(e,t,`mdTag`);if(!n)return;let r=e.doc.textBetween(n.from,n.to),i=r.startsWith(`#`)?r.slice(1):r;return{from:n.from,to:n.to,tag:i}}function Ac(e){return Dc({key:Oc,selector:`.md-tag`,preventDefault:!1,findPayloadAt:(e,t)=>kc(e,t)?.tag,onClick:(t,n)=>e({tag:t,event:n})})}const jc=new y(`meowdown-wikilink-click`);function Mc(e,t){let n=T(e,t,`mdWikilink`);if(!n)return;let{target:r}=n.mark.attrs;return{from:n.from,to:n.to,target:r}}function Nc(e,t){let n=t.closest(`.md-wikilink-view`)?.querySelector(`.md-wikilink-view-content`);if(n)return Mc(e.state,e.posAtDOM(n,0))}function Pc(e){return Dc({key:jc,selector:`.md-wikilink-view-preview`,preventDefault:!1,findPayloadAt:(e,t)=>Mc(e,t)?.target,findPayloadForElement:(e,t)=>Nc(e,t)?.target,onClick:(t,n)=>e({target:t,event:n})})}const Fc=new y(`meowdown-follow-link`);function Ic(e){return e.key!==`Enter`||e.shiftKey||e.altKey?!1:ie?e.metaKey&&!e.ctrlKey:e.ctrlKey&&!e.metaKey}function Lc(e){return new v({key:Fc,props:{handleKeyDown:(t,n)=>{if(!Ic(n))return!1;let{state:r}=t,i=r.selection.head,a=e.onWikilinkClick&&Mc(r,i);if(a)return e.onWikilinkClick?.({target:a.target,event:n}),!0;let o=e.onTagClick&&kc(r,i);if(o)return e.onTagClick?.({tag:o.tag,event:n}),!0;let s=e.onFileClick&&_c(r,i);if(s)return e.onFileClick?.({href:s.href,name:s.name,event:n}),!0;let c=e.onLinkClick&&K(r,i);return c?(e.onLinkClick?.({href:c.href,event:n}),!0):!1}}})}function Rc(e){return _(m(Lc(e)),t.high)}const zc=(e,t)=>{let n={type:`highlight`,children:e.all(t)};return e.patch(t,n),n},Bc=(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 Vc(){return At().use(Et).use(Dt,{handlers:{mark:zc}}).use(Ot).use(kt,{bullet:`-`,emphasis:`*`,strong:`*`,fence:"`",fences:!0,rule:`-`,ruleRepetition:3,listItemIndent:`one`,handlers:{highlight:Bc}}).freeze()}const Hc=ve(Vc);function Uc(e){return String(Hc().processSync(e))}const Wc=new y(`meowdown-html-paste`);function Gc(){return m(new v({key:Wc,props:{transformPastedHTML:(e,t)=>{if(e.includes(`data-pm-slice`))return e;let n=t.state.selection.$from.parent;if(!n.inlineContent||n.type.spec.code)return e;let r=Uc(e);if(!r.trim())return e;let i=Z(r,{nodes:Go(t.state.schema)}),a=Ie.fromSchema(t.state.schema),o=document.createElement(`div`);return o.append(a.serializeFragment(i.content)),o.innerHTML}}}))}const Kc=new y(`meowdown-image-click`);function qc(e){return e instanceof HTMLElement&&e.closest(`.md-image-view-preview`)}function Jc(e,t){let n=T(e,t,`mdImage`);if(!n)return;let{src:r,alt:i}=n.mark.attrs;return{from:n.from,to:n.to,src:r,alt:i}}function Yc(e,t){let n=t.closest(`.md-image-view`)?.querySelector(`.md-image-view-content`);if(n)return Jc(e.state,e.posAtDOM(n,0))}function Xc(e,t){return Array.from(e).find(e=>e.identifier===t)}function Zc(e,t){return Math.abs(t.clientX-e.clientX)<=10&&Math.abs(t.clientY-e.clientY)<=10}function Qc(e){let t=new WeakMap;return m(new v({key:Kc,props:{handleDOMEvents:{pointerdown:(e,t)=>(qc(t.target)&&t.pointerType!==`mouse`&&t.preventDefault(),!1),touchstart:(e,n)=>{if(t.delete(e),n.touches.length!==1||!qc(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=Xc(n.changedTouches,r.identifier);return i&&!Zc(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=Xc(r.changedTouches,i.identifier);if(!a||!Zc(i,a))return!1;let o=qc(r.target);if(!o)return!1;r.preventDefault();let s=Yc(n,o);return s&&e({src:s.src,alt:s.alt,event:r}),!0}},handleClick:(t,n,r)=>{let i=qc(r.target);if(!i)return!1;let a=Yc(t,i);return a?(e({src:a.src,alt:a.alt,event:r}),!0):!1}}}))}function $c(e){return/^https?:\/\//i.test(e)?e:void 0}function el(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`&&Ws(t),t}function tl(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 nl(e,t,n,r){let i=e.posAtDOM(t,0),a=T(e.state,i,`mdImage`);if(!a)return;let o=e.state.doc.textBetween(a.from,a.to),s=zr(o),c=a.from+s.length,l=o.slice(s.length),u=Rr({...Ir(l)??{},width:Math.round(n),height:Math.round(r)});u!==l&&e.dispatch(e.state.tr.insertText(u,c,a.to))}var rl=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)&&tl(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=Zs(e);if(t){let e=document.createElement(`span`);return e.className=`md-image-view-preview md-atom-view-preview`,e.appendChild(el(t)),e}let n=(this.#n.resolveImageUrl??$c)(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){Mt(),jt();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,tl(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)),tl(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;nl(this.#r,this.#t,t,n)}),this.#a=t,this.#o=n,t}};function il(e={}){return d({name:`mdImage`,constructor:(t,n)=>new rl(t,n,e)})}const al={"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`},ol=new y(`meowdown-link-click`);function sl(e){return Dc({key:ol,selector:`.md-link`,preventDefault:!0,findPayloadAt:(e,t)=>K(e,t)?.href,onClick:(t,n)=>e({href:t,event:n})})}function cl(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||!_e(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 v({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 ll=new y(`meowdown-link-hover`);function ul(e){return cl({key:ll,selector:`.md-link`,findPayloadAt:(e,t)=>K(e,t),isSamePayload:(e,t)=>e.href===t.href&&e.title===t.title,onHoverChange:e})}const dl=new y(`meowdown-link-paste`);function fl(e){let t=e.trim();if(!(!t||/\s/.test(t)))return lr(t)}function pl(){return _(m(new v({key:dl,props:{handlePaste:(e,t,n)=>{let r=Qs(t,n);if(!r)return!1;let i=fl(r);return i?Mn(e,qi({href:i,wrapText:!1})):!1}}})),t.high)}const ml=new y(`meowdown-markdown-copy`);function hl(){return m(new v({key:ml,props:{clipboardTextSerializer:(e,t)=>{let n=e.content,r;try{r=t.state.schema.topNodeType.createAndFill(void 0,n)??void 0}catch{r=void 0}return r?fs(r).replace(/\n+$/,``):n.textBetween(0,n.size,`
23
+ `,` `)}function dr(e,t){let n=t.content,r;try{r=e.topNodeType.createAndFill(void 0,n)??void 0}catch{r=void 0}return r?P(r).replace(/\n+$/,``):n.textBetween(0,n.size,`
29
24
  `,`
30
- `)}}}))}const gl=new y(`meowdown-wikilink-hover`);function _l(e){return cl({key:gl,selector:`.md-wikilink-view-preview`,findPayloadAt:Mc,findPayloadForElement:Nc,isSamePayload:(e,t)=>e.target===t.target,onHoverChange:t=>{e(t?{...t.payload,element:t.element}:void 0)}})}function vl({allowEmpty:e}){return(t,n)=>{let{selection:r}=t;if(!h(r)||!e&&r.empty||!r.$head.sameParent(r.$anchor)||r.$head.parent.type.spec.code)return!1;let i=Pt(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(x.create(e.doc,r.from+a.length)),Fe(e),n(e.scrollIntoView())}return!0}}function yl(){return l({"Mod-Shift-k":vl({allowEmpty:!0}),"[":vl({allowEmpty:!1})})}function bl(e){let{selection:t,schema:n}=e;if(t.empty)return``;let r=t.content().content;try{return fs(n.topNodeType.create(null,r)).replace(/\n+$/,``)}catch{return e.doc.textBetween(t.from,t.to,`
25
+ `)}function fr(){return m(new v({key:new y(`meowdown-plain-text-copy`),props:{clipboardTextSerializer:(e,t)=>{let n=O(t.state)===`hide`?pr(e):e;return dr(t.state.schema,n)}}}))}function pr(e){return new w(mr(e.content),e.openStart,e.openEnd)}function mr(e){let t=[];return e.forEach(e=>{t.push(e.isTextblock?gr(e):hr(e))}),C.from(t)}function hr(e){return e.childCount>0?e.copy(mr(e.content)):e}function gr(e){let t=e.type.schema,n=[];for(let r of mn(e)){let e=r.atom;if(e!=null){if(e.type.name===`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)pn(e.marks)||n.push(e)}return e.copy(C.from(n))}function _r(){return g(Pn(),fr(),Hn(),zn(),Gn())}const F=new Map,vr=new Map,yr={math:`latex`};async function br(e){let t=F.get(e);if(t!==void 0)return t;let n=Ve.matchLanguageName(He,yr[e]??e,!0);if(!n)return F.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),F.set(e,null),null}return F.set(e,r),r}function xr(e,t){let n=vr.get(e);if(n)return n;let r=Ge({parse:e=>t.language.parser.parse(e.content),highlighter:Ue});return vr.set(e,r),r}const Sr=e=>{let t=e.language?.trim();if(!t)return[];let n=F.get(t);return n===null?[]:n?xr(t,n)(e):br(t).then(()=>void 0)};function Cr(){return fe({parser:Sr,nodeTypes:[`codeBlock`]})}function wr(e,t){let n=t.language.parser.parse(e),r=[];return We(n,Ue,(e,t,n)=>{r.push([e,t,n])}),r}function Tr(e,t){let n=t.trim();if(!n)return[];let r=F.get(n);return r===null?[]:r?wr(e,r):br(n).then(t=>t?wr(e,t):[])}function Er(){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 Dr(){return f({type:`codeBlock`,attr:`fenceLength`,default:null,toDOM:e=>e==null?null:[`data-fence-length`,String(e)],parseDOM:e=>{let t=sn(e.getAttribute(`data-fence-length`));return t!=null&&t>3?t:null}})}function Or(e){return{language:e[1]||``,fenceStyle:`tilde`}}function kr(){return Je({regex:/^~~~(\S*)\s$/,type:`codeBlock`,attrs:Or})}function Ar(){return Ke({regex:/^~~~(\S*)$/,type:`codeBlock`,attrs:Or})}function jr(){return Ke({regex:/^\$\$$/,type:`codeBlock`,attrs:()=>({language:`math`,fenceStyle:`dollar`})})}function Mr(){return g(de(),Er(),Dr(),kr(),Ar(),jr())}function Nr(e,t){return(n,r)=>{if(r){let i=x.create(n.doc,e,t);r(n.tr.setSelection(i))}return!0}}function Pr(e,t,n){return(r,i)=>{if(i){let a=x.between(e,t,n);i(r.tr.setSelection(a))}return!0}}function Fr(e){return(t,n)=>{if(!e.trim())return!1;let r=X(e,{nodes:ec(t.schema)}).content;if(r.childCount===0)return!1;let i=r.childCount===1&&r.child(0).type.name===`paragraph`?new w(r,1,1):new w(r,0,w.maxOpen(r).openEnd);if(n){let e=t.tr,r=e.selection;(!h(r)||!r.empty)&&e.setSelection(x.near(r.$from)),n(e.replaceSelection(i).scrollIntoView())}return!0}}function Ir(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);Ye(s),n(s.scrollIntoView())}return!0}}function Lr(){return(e,t)=>(t&&t(e.tr.scrollIntoView()),!0)}function Rr(){return s({insertMarkdown:Fr,insertTrigger:Ir,scrollIntoView:Lr,selectText:Nr,selectTextBetween:Pr})}const zr=(e,t,n)=>{let{selection:r}=e;return r.empty||n?.composing?!1:(t?.(e.tr.setSelection(x.near(r.$head))),!0)};function Br(){return _(l({Escape:zr}),t.low)}function Vr(){return f({type:`doc`,attr:`frontmatter`,default:null})}function Hr(e,t){return t(e.state,e.dispatch,e)}const Ur=new Set([`mdMark`,`mdLinkUri`,`mdLinkTitle`]);function Wr(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 I(e,t){let n=Wr(e,t);return n!=null&&n.some(e=>Ur.has(e.type.name))}function L(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 R(e,t){if(!L(e,t))return;let n=e.doc.resolve(t).start(),r=t;for(;r>n&&I(e,r-1);)r--;return r<t?{from:r,to:t}:void 0}function z(e,t){if(!L(e,t))return;let n=e.doc.resolve(t).end(),r=t;for(;r<n&&I(e,r);)r++;return r>t?{from:t,to:r}:void 0}function Gr(e,t){return I(e,t-1)&&I(e,t)}function Kr(e,t){if(!Gr(e,t))return;let n=R(e,t),r=z(e,t);if(!(n==null||r==null))return{from:n.from,to:r.to}}function qr(e,t,n){let r=Wr(e,t);return r!=null&&n.isInSet(r)}function Jr(e,t){let n=Wr(e,t);if(n==null)return;let r=te(e.schema,`mdPack`),i=n.filter(e=>e.type===r);if(i.length===0)return;let a=e.doc.resolve(t),o=a.start(),s=a.end(),c;for(let n of i){let r=t;for(;r>o&&qr(e,r-1,n);)r--;let i=t+1;for(;i<s&&qr(e,i,n);)i++;(c==null||i-r<c.to-c.from)&&(c={from:r,to:i})}return c}function B(e,t,n){let r=Jr(e,n===`from`?t.from:t.to-1);return r==null?!1:n===`from`?r.from===t.from:r.to===t.to}function Yr(e,t,n){let r=B(e,t,`from`),i=B(e,t,`to`);return r&&!i?t.from:i&&!r?t.to:n-t.from<=t.to-n?t.from:t.to}function Xr(e,t,n,r){if(!L(e,n))return n;let i=Kr(e,n);if(i!=null)return r?Yr(e,i,n):n>=t?i.to:i.from;if(!r)return n;let a=R(e,n);if(a!=null&&B(e,a,`from`))return a.from;let o=z(e,n);return o!=null&&B(e,o,`to`)?o.to:n}function Zr(e,t){if(!L(e,t))return;let n=I(e,t-1),r=I(e,t);if(n!==r)return r?`left`:`right`}function Qr(e,t){let n=Jr(e,t);if(n==null)return[];let r=z(e,n.from),i=R(e,n.to),a=[];return i!=null&&a.push(i),r!=null&&(i==null||r.from!==i.from)&&a.push(r),a}const $r=new y(`meowdown-hidden-run-snap`),ei=new y(`meowdown-hidden-run-beforeinput`);function ti(){let e=!1;return new v({key:$r,props:{handleDOMEvents:{compositionstart:()=>(e=!0,!1),compositionend:()=>(e=!1,!1)}},appendTransaction:(t,n,r)=>{if(e||O(r)!==`hide`)return null;let i=r.selection;if(!h(i))return null;let a=t.some(e=>e.getMeta(`pointer`)!=null);if(i.empty){let e=Xr(r,n.selection.head,i.head,a);return e===i.head?null:r.tr.setSelection(x.create(r.doc,e))}let o=Kr(r,i.from)?.from??i.from,s=Kr(r,i.to)?.to??i.to;if(o===i.from&&s===i.to)return null;let c=i.anchor===i.from?o:s,l=i.head===i.from?o:s;return r.tr.setSelection(x.create(r.doc,c,l))}})}const ni=(e,t)=>{if(O(e)!==`hide`)return!1;let n=e.selection;if(!h(n)||!n.empty)return!1;let r=Xr(e,n.head,n.head,!0);return r===n.head||t?.(e.tr.setSelection(x.create(e.doc,r))),!1};function ri(e){return(t,n)=>{if(O(t)!==`hide`)return!1;let r=t.selection;if(!h(r)||!r.empty)return!1;let i=r.$head;if(!i.parent.isTextblock||i.parent.type.spec.code)return!1;let a=e===-1?R(t,r.head):z(t,r.head);if(a==null)return!1;let o=Qr(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 ii=ri(-1),ai=ri(1);function oi(){return new v({key:ei,props:{handleDOMEvents:{beforeinput:(e,t)=>{if(e.composing)return!1;let n=t.inputType===`deleteContentBackward`?ii:t.inputType===`deleteContentForward`?ai:void 0;return n==null||!Hr(e,n)?!1:(t.preventDefault(),!0)}}}})}function si(){return g(m(ti()),m(oi()),_(l({Enter:ni,Backspace:ii,Delete:ai}),t.highest))}function ci(){return f({type:`horizontalRule`,attr:`marker`,default:null,toDOM:e=>e?[`data-hr-marker`,e]:null,parseDOM:e=>e.getAttribute(`data-hr-marker`)})}function li(){return g(Xe(),ci())}function ui(){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 di(e){let[t,n,r]=e;return[t,n,r.map(e=>e.toJSON())]}function fi(e,t){let[n,r,i]=t;return[n,r,i.map(t=>Fe.fromJSON(e,t))]}function pi(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 mi=class e extends nt{constructor(e){super(),this.chunks=e}apply(e){if(this.chunks.length===0)return rt.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=Fe.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(pi(l,c))return!1;n??=new it(e);for(let e of l)n.removeMark(i,a,e);for(let e of c)n.addMark(i,a,e);return!1})}return rt.ok(n?n.doc:e)}invert(e){if(this.chunks.length===0)return hi;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 tt(i,a,e.slice(i,a),!1)}map(e){return null}toJSON(){return{stepType:`batchSetMark`,chunks:this.chunks.map(di)}}static fromJSON(t,n){let r=n.chunks;return new e(r.map(e=>fi(t,e)))}};nt.jsonID(`batchSetMark`,mi);const hi=new mi([]),gi=new Set([`com`,`br`,`net`,`jp`,`org`,`in`,`de`,`ru`,`it`,`fr`]),_i=/^[a-z0-9](?:[a-z0-9-]*[a-z0-9])?$/i;function vi(e){let t=e.indexOf(`/`);return t===-1?e:e.slice(0,t)}function yi(e){let t=e.split(`.`);if(t.length<2)return!1;let n=t[t.length-1].toLowerCase();if(!gi.has(n)||t[t.length-2].length<3)return!1;for(let e of t)if(e.length>63||!_i.test(e))return!1;return!0}function bi(e){if(/^[a-z][a-z0-9+.-]*:/i.test(e))return e;if(/^[^\s@]+@[^\s@]+$/.test(e))return`mailto:${e}`;if(/^www\./i.test(e)||yi(vi(e)))return`https://${e}`}const xi=/^[a-z0-9-]+(?:\.[a-z0-9-]+)+(?:\/[^\s<]*)?/i,Si=/[\s(*_~]/;function Ci(e){return e>=48&&e<=57||e>=65&&e<=90||e>=97&&e<=122||e===45}function wi(e,t,n){let r=0;for(let i=0;i<t;i++)e[i]===n&&r++;return r}function Ti(e){let t=e.length;for(;;){let n=e[t-1];if(/[?!.,:*_~]/.test(n)||n===`)`&&wi(e,t,`)`)>wi(e,t,`(`))t--;else if(n===`;`){let n=/&(?:#\d+|#x[a-f\d]+|\w+);$/.exec(e.slice(0,t));if(!n)break;t=n.index}else break}return t}const Ei={parseInline:[{name:`BareAutolink`,before:`Link`,parse(e,t,n){if(!Ci(t)||e.hasOpenLink)return-1;let r=e.slice(n-1,n);if(r!==``&&!Si.test(r))return-1;let i=xi.exec(e.slice(n,e.end));if(!i)return-1;let a=Ti(i[0]);return a===0||!yi(vi(i[0].slice(0,a)))?-1:e.addElement(e.elt(`URL`,n,n+a))}}]};function Di(e){return e>=48&&e<=57||e>=65&&e<=90||e>=97&&e<=122||e===45||e===95||e>127&&/[\p{L}\p{N}]/u.test(String.fromCharCode(e))}function Oi(e){return e>=65&&e<=90||e>=97&&e<=122||e>127&&/\p{L}/u.test(String.fromCharCode(e))}const ki={defineNodes:[{name:`Hashtag`}],parseInline:[{name:`Hashtag`,parse(e,t,n){if(t!==35||!/\s|^$/.test(e.slice(n-1,n)))return-1;let r=n+1,i=!1;for(;r<e.end;){let t=e.char(r);if(!Di(t))break;i||=Oi(t),r++}return i?e.addElement(e.elt(`Hashtag`,n,r)):-1}}]},Ai={resolve:`Highlight`,mark:`HighlightMark`},ji=/[!"#$%&'()*+,\-./:;<=>?@[\\\]^_`{|}~\u{A1}\u{2010}-\u{2027}]/u,Mi={defineNodes:[{name:`Highlight`},{name:`HighlightMark`}],parseInline:[{name:`Highlight`,after:`Emphasis`,parse(e,t,n){if(t!==61||e.char(n+1)!==61||e.char(n+2)===61)return-1;let r=e.slice(n-1,n),i=e.slice(n+2,n+3),a=/\s|^$/.test(r),o=/\s|^$/.test(i),s=ji.test(r),c=ji.test(i);return e.addDelimiter(Ai,n,n+2,!o&&(!c||a||s),!a&&(!s||o||c))}}]};function Ni(e){return e>=48&&e<=57}function Pi(e){return e.next!==36||e.text.charCodeAt(e.pos+1)!==36||e.text.charCodeAt(e.pos+2)===36?!1:e.skipSpace(e.pos+2)===e.text.length}function Fi(e){let t=e.depth;return typeof t==`number`?t:2**53-1}const Ii={defineNodes:[{name:`InlineMath`},{name:`InlineMathMark`},{name:`BlockMath`,block:!0},{name:`BlockMathMark`}],parseBlock:[{name:`BlockMath`,before:`FencedCode`,parse(e,t){if(!Pi(t))return!1;let n=e.lineStart+t.pos,r=[e.elt(`BlockMathMark`,n,n+2)];for(let n=!0,i=!0,a=!1;!(!e.nextLine()||Fi(t)<e.depth);n=!1){if(Pi(t)){i&&a&&r.push(e.elt(`CodeText`,e.lineStart-1,e.lineStart)),r.push(e.elt(`BlockMathMark`,e.lineStart+t.pos,e.lineStart+t.pos+2)),e.nextLine();break}a=!0,n||(r.push(e.elt(`CodeText`,e.lineStart-1,e.lineStart)),i=!1);let o=e.lineStart+t.basePos,s=e.lineStart+t.text.length;o<s&&(r.push(e.elt(`CodeText`,o,s)),i=!1)}return e.addElement(e.elt(`BlockMath`,n,e.prevLineEnd(),r)),!0},endLeaf(e,t){return Pi(t)}}],parseInline:[{name:`InlineMath`,after:`InlineCode`,parse(e,t,n){if(t!==36||e.char(n-1)===36)return-1;let r=e.char(n+1)===36?2:1;if(e.char(n+r)===36)return-1;let i=n+r;if(N(e.char(i)))return-1;for(let t=i;t<e.end;t++){let a=e.char(t);if(a===10)return-1;if(a===92){t++;continue}if(a!==36)continue;let o=1;for(;e.char(t+o)===36;)o++;if(o!==r||N(e.char(t-1))||Ni(e.char(t+o)))return-1;let s=t+o;return e.addElement(e.elt(`InlineMath`,n,s,[e.elt(`InlineMathMark`,n,i),e.elt(`InlineMathMark`,t,s)]))}return-1}}]},Li=/^[a-z][a-z0-9+.-]*:\/\/[^\s<]+/i;function Ri(e){return e>=65&&e<=90||e>=97&&e<=122}const zi={parseInline:[{name:`SchemeAutolink`,after:`Autolink`,parse(e,t,n){if(!Ri(t)||e.hasOpenLink)return-1;let r=e.slice(n-1,n);if(r!==``&&!Si.test(r))return-1;let i=Li.exec(e.slice(n,e.end));if(!i)return-1;let a=Ti(i[0]);return a<=i[0].indexOf(`://`)+3?-1:e.addElement(e.elt(`URL`,n,n+a))}}]},Bi={defineNodes:[{name:`Wikilink`},{name:`WikilinkMark`}],parseInline:[{name:`Wikilink`,before:`Link`,parse(e,t,n){if(t!==91||e.char(n+1)!==91)return-1;let r=!1;for(let t=n+2;t<e.end-1;t++){let i=e.char(t);if(i===93){if(e.char(t+1)!==93||!r)return-1;let i=t+2;return e.addElement(e.elt(`Wikilink`,n,i,[e.elt(`WikilinkMark`,n,n+2),e.elt(`WikilinkMark`,t,i)]))}if(i===91||i===10)return-1;i!==32&&i!==9&&(r=!0)}return-1}}]};function Vi(e){return e.end}const Hi=ot.configure([at,ki,Bi,Ei,zi,Mi,Ii]),Ui=Hi.configure({parseInline:[{name:`SkipInline`,before:`Escape`,parse:Vi}]});function Wi(e){return Hi.parseInline(e,0)}function Gi(e,t,n=[]){for(let r of e)t(r)&&n.push(r),Gi(r.children,t,n);return n}function Ki(e){let t={};for(let n of e.nodeSet.types)t[n.name]=n.id;return t}const V=Ki(Hi),qi=/^<!--\s*(\{[^}]*\})\s*-->$/,Ji=/<!--\s*\{[^}]*\}\s*-->$/;function Yi(e){let t=qi.exec(e.trim());if(!t)return;let n;try{n=JSON.parse(t[1])}catch{return}if(typeof n!=`object`||!n)return;let r=Xi(n);return Object.keys(r).length>0?r:void 0}function Xi(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 Zi(e){return`<!-- ${JSON.stringify(e)} -->`}function Qi(e){return e.replace(Ji,``)}function $i(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 ea(){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 ta(){return d({name:`mdWikilink`,constructor:ea()})}const na=new Map([[V.Emphasis,`mdEm`],[V.StrongEmphasis,`mdStrong`],[V.InlineCode,`mdCode`],[V.Strikethrough,`mdDel`],[V.Highlight,`mdHighlight`],[V.EmphasisMark,`mdMark`],[V.CodeMark,`mdMark`],[V.LinkMark,`mdMark`],[V.StrikethroughMark,`mdMark`],[V.HighlightMark,`mdMark`],[V.URL,`mdLinkUri`],[V.LinkTitle,`mdLinkTitle`],[V.Hashtag,`mdTag`],[V.WikilinkMark,`mdMark`]]);function ra(e,t,n){let r=Wi(t),i=[];return aa(r,[],0,t.length,t,e,i,n),i}function ia(e){return e.slice(1,-1).replaceAll(/\\(.)/g,`$1`)}function aa(e,t,n,r,i,a,o,s){let c=n;for(let n=0;n<e.length;n++){let r=e[n];r.from>c&&H(o,c,r.from,t);let l=r.type;if(l===V.Link){let e=ca(r,t,i,a,s);e?H(o,r.from,r.to,e):la(r,t,i,a,o)}else if(l===V.Image){let s=ua(r,e[n+1],i);da(r,t,i,a,o,s),s&&n++,c=s?s.to:r.to;continue}else if(l===V.Wikilink)pa(r,t,i,a,o);else if(l===V.InlineMath)fa(r,t,i,a,o);else if(l===V.URL){let e=bi(i.slice(r.from,r.to)),n=e?a.mdLinkText.create({href:e}):a.mdLinkUri.create();H(o,r.from,r.to,[...t,n])}else{let e;l===V.Emphasis?e=`italic`:l===V.StrongEmphasis?e=`bold`:l===V.InlineCode?e=`code`:l===V.Strikethrough?e=`strike`:l===V.Highlight?e=`highlight`:l===V.Autolink&&(e=`autolink`);let n=e?[...t,a.mdPack.create({key:e})]:t,c=na.get(l),u=c?[...n,a[c].create()]:n;r.children.length===0?H(o,r.from,r.to,u):aa(r.children,u,r.from,r.to,i,a,o,s)}c=r.to}c<r&&H(o,c,r,t)}function oa(e){let t=-1,n=-1,r=null,i=null,a=0;for(let o of e.children)o.type===V.LinkMark?(a++,a===1&&(t=o.to),a===2&&(n=o.from)):o.type===V.URL&&r===null?r=o:o.type===V.LinkTitle&&i===null&&(i=o);return{labelFrom:t,labelTo:n,urlNode:r,titleNode:i}}function sa(e){let t=e.split(/[?#]/,1)[0],n=t.split(/[/\\]/).findLast(Boolean)??t;try{return decodeURIComponent(n)}catch{return n}}function ca(e,t,n,r,i){let a=i?.resolveFileLink;if(!a)return;let{labelFrom:o,labelTo:s,urlNode:c,titleNode:l}=oa(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?ia(n.slice(l.from,l.to)):``;if(!a({href:u,label:d,title:f}))return;let p=d||sa(u);return[...t,r.mdFile.create({href:u,name:p,title:f})]}function la(e,t,n,r,i){let{labelTo:a,urlNode:o,titleNode:s}=oa(e),c=o?n.slice(o.from,o.to):``,l=s?ia(n.slice(s.from,s.to)):``,u=c?r.mdLinkText.create({href:c}):null,d=e=>a>=0&&e<a&&u!==null,f=r.mdPack.create({key:`link`,data:{href:c,title:l}}),p=[...t,f],m=e.from;for(let t of e.children){if(t.from>m){let e=d(m)?[...p,u]:p;H(i,m,t.from,e)}let e=d(t.from)?[...p,u]:p;if(t.type===V.Wikilink){pa(t,e,n,r,i),m=t.to;continue}let a=na.get(t.type),o=a?[...e,r[a].create()]:e;t.children.length===0?H(i,t.from,t.to,o):aa(t.children,o,t.from,t.to,n,r,i,void 0),m=t.to}m<e.to&&H(i,m,e.to,p)}function ua(e,t,n){if(!t||t.type!==V.Comment||t.from!==e.to)return;let r=Yi(n.slice(t.from,t.to));if(r)return{magic:r,to:t.to}}function da(e,t,n,r,i,a){let o=e.children.find(e=>e.type===V.URL);if(!o){la(e,t,n,r,i);return}let s=e.children.filter(e=>e.type===V.LinkMark),c=e.children.find(e=>e.type===V.LinkTitle),l=n.slice(o.from,o.to),u=s.length>=2?n.slice(s[0].to,s[1].from):``,d=c?ia(n.slice(c.from,c.to)):``,f=a?.magic.width??null,p=a?.magic.height??null,m=a?.to??e.to;H(i,e.from,m,[...t,r.mdImage.create({src:l,alt:u,title:d,width:f,height:p})])}function fa(e,t,n,r,i){let a=e.children.filter(e=>e.type===V.InlineMathMark);if(a.length<2){H(i,e.from,e.to,t);return}let o=n.slice(a[0].to,a[1].from),s=[...t,r.mdPack.create({key:`math`}),r.mdMath.create({formula:o})];H(i,e.from,a[0].to,[...s,r.mdMark.create()]),H(i,a[0].to,a[1].from,s),H(i,a[1].from,e.to,[...s,r.mdMark.create()])}function pa(e,t,n,r,i){let{target:a,display:o}=$i(n.slice(e.from,e.to));H(i,e.from,e.to,[...t,r.mdWikilink.create({target:a,display:o})])}function H(e,t,n,r){if(t>=n)return;let i=e.at(-1);if(i&&i[1]===t&&pi(i[2],r)){e[e.length-1]=[i[0],n,i[2]];return}e.push([t,n,r])}const ma=`inline-marks-applied`;let ha=0,ga=0;function _a(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 va(e){let t=new WeakMap;function n(n,r,i){let a=t.get(n);if(a?ga++:(ha++,a=ra(Qs(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 v({key:new y(`inline-mark`),appendTransaction(e,t,n){for(let t of e)if(t.getMeta(ma))return null;let i=r(n,_a(e,n));if(i.length===0)return null;let a=n.tr.step(new mi(i));return a.setMeta(ma,!0),a.setMeta(`addToHistory`,!1),a},view(e){return e.dispatch(ya(e.state)),{}}})}function ya(e){return e.tr.setMeta(`inline-marks-trigger`,!0)}function ba(e){return m(va(e))}function xa(){return u({name:`mdImage`,inclusive:!1,attrs:{src:{default:``},alt:{default:``},title:{default:``},width:{default:null},height:{default:null}},toDOM:()=>[`span`,{class:`md-image`},0],parseDOM:[{tag:`span.md-image`}]})}function Sa(){return u({name:`mdMark`,inclusive:!1,toDOM:()=>[`span`,{class:`md-mark`},0],parseDOM:[{tag:`span.md-mark`}]})}function Ca(){return u({name:`mdEm`,toDOM:()=>[`em`,0],parseDOM:[{tag:`em`}]})}function wa(){return u({name:`mdStrong`,toDOM:()=>[`strong`,0],parseDOM:[{tag:`strong`}]})}function Ta(){return u({name:`mdCode`,toDOM:()=>[`code`,0],parseDOM:[{tag:`code`}]})}function Ea(){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 Da(){return u({name:`mdLinkUri`,inclusive:!1,toDOM:()=>[`span`,{class:`md-link-uri`},0],parseDOM:[{tag:`span.md-link-uri`}]})}function Oa(){return u({name:`mdLinkTitle`,inclusive:!1,toDOM:()=>[`span`,{class:`md-link-title`},0],parseDOM:[{tag:`span.md-link-title`}]})}function ka(){return u({name:`mdDel`,toDOM:()=>[`del`,0],parseDOM:[{tag:`del`}]})}function Aa(){return u({name:`mdHighlight`,toDOM:()=>[`mark`,0],parseDOM:[{tag:`mark`}]})}function ja(){return u({name:`mdTag`,toDOM:()=>[`span`,{class:`md-tag`},0],parseDOM:[{tag:`span.md-tag`}]})}function Ma(){return u({name:`mdWikilink`,inclusive:!1,attrs:{target:{default:``},display:{default:``}},toDOM:()=>[`span`,{class:`md-wikilink`},0],parseDOM:[{tag:`span.md-wikilink`}]})}function Na(){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 Pa(){return u({name:`mdMath`,inclusive:!1,attrs:{formula:{default:``}},toDOM:()=>[`span`,{class:`md-math`},0],parseDOM:[{tag:`span.md-math`}]})}function Fa(){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 Ia(){return g(Sa(),Ca(),wa(),Ta(),Ea(),Da(),Oa(),ka(),Aa(),ja(),Ma(),xa(),Na(),Pa(),Fa())}const U={em:{node:V.Emphasis,delim:`*`},strong:{node:V.StrongEmphasis,delim:`**`},code:{node:V.InlineCode,delim:"`"},del:{node:V.Strikethrough,delim:`~~`},highlight:{node:V.Highlight,delim:`==`}},La=new Set([V.EmphasisMark,V.CodeMark,V.LinkMark,V.StrikethroughMark,V.HighlightMark]);function Ra(e){return[e.children[0],e.children.at(-1)]}function za(e){let{type:t,children:n}=e;if(t===V.Emphasis||t===V.StrongEmphasis||t===V.Strikethrough||t===V.Highlight)return[n[0].to,n.at(-1).from];if(t===V.Link||t===V.Image){let e=n.find((e,t)=>t>0&&e.type===V.LinkMark);return e?[n[0].to,e.from]:null}return null}function Ba(e,t,n){for(let r of e){if(r.to<=t||r.from>=n||t<=r.from&&r.to<=n)continue;let i=za(r);return i&&i[0]<=t&&n<=i[1]?Ba(r.children,t,n):Ba(e,Math.min(t,r.from),Math.max(n,r.to))}return[t,n]}function Va(e,t,n){for(let r of e)if(!(r.to<=t||r.from>=n)&&(t>r.from||r.to>n))return Va(e,Math.min(t,r.from),Math.max(n,r.to));return[t,n]}function Ha(e,t,n){for(;t<n&&N(e.charCodeAt(t));)t++;for(;n>t&&N(e.charCodeAt(n-1));)n--;return[t,n]}function Ua(e,t,n,r){let i=Gi(Wi(e),e=>e.type===r.node||La.has(e.type));for(let r=t;r<n;r++)if(!N(e.charCodeAt(r))&&i.every(e=>!(e.from<=r&&r<e.to)))return!1;return!0}function Wa(e,t,n,r,i){let a=Wi(e),o=Gi(a,e=>e.type===r.node);return i?qa(e,o,t,n):Ga(e,a,o,t,n,r)}function Ga(e,t,n,r,i,a){for(let e=0;e!==i-r;){e=i-r,[r,i]=Ba(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]=Ra(e);o.push({from:t.from,to:t.to,insert:``}),o.push({from:n.from,to:n.to,insert:``})}let[s,c]=Ka(e,r,i,o,a);return o.push({from:r,to:r,insert:s},{from:i,to:i,insert:c}),o}function Ka(e,t,n,r,i){if(i.node!==V.InlineCode)return[i.delim,i.delim];let a=e.slice(t,n);for(let e of[...r].sort((e,t)=>t.from-e.from))a=a.slice(0,e.from-t)+a.slice(e.to-t);let o="`".repeat(qn(a)+1),s=a.startsWith("`")||a.endsWith("`")?` `:``;return[o+s,s+o]}function qa(e,t,n,r){let i=[];for(let a of t){if(a.to<=n||a.from>=r)continue;let[t,o]=Ra(a),s=Math.max(n,t.to),c=Math.min(r,o.from);for(s>=c&&([s,c]=[t.to,o.from]),[s,c]=Va(a.children.slice(1,-1),s,c);s>t.to&&N(e.charCodeAt(s-1));)s--;for(;c<o.from&&N(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 Ja(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=Wi(e),o=Gi(a,e=>e.type===n.node).findLast(e=>e.from<=t&&t<=e.to);if(o){let[e,n]=Ra(o);return{kind:`move`,pos:t===o.from?e.to:t===o.to?n.from:o.to}}return Ya(a,t)||e[t-1]===r[0]||e[t]===r[0]?null:{kind:`insert`,pos:t}}function Ya(e,t){for(let n of e)if(n.from<t&&t<n.to){let e=za(n);return!e||t<e[0]||t>e[1]||Ya(n.children,t)}return!1}function W(e){return(t,n)=>{if(t.selection.empty)return Xa(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]=Ha(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:Ua(a,c,l,e)}),!1});let c=s.length>0&&s.every(e=>e.active),l=s.filter(e=>c||!e.active).flatMap(t=>Wa(t.text,t.from,t.to,e,c).map(e=>({from:e.from+t.base,to:e.to+t.base,insert:e.insert})));if(l.length===0)return!1;if(n){let e=t.tr;l.sort((e,t)=>t.from-e.from||t.to-e.to);for(let t of l)t.insert?e.insertText(t.insert,t.from,t.to):e.delete(t.from,t.to);e.setSelection(x.create(e.doc,e.mapping.map(a,a<=o?1:-1),e.mapping.map(o,o<a?1:-1))),n(e.scrollIntoView())}return!0}}function Xa(e,t,n){let{$from:r}=t.selection,i=r.parent;if(!i.isTextblock||i.type.spec.code)return!1;let a=Ja(i.textContent,r.parentOffset,e);if(!a)return!1;if(n){let i=r.start(),o=t.tr;a.kind===`unwrap`&&o.delete(i+a.from,i+a.to),a.kind===`move`&&o.setSelection(x.create(o.doc,i+a.pos)),a.kind===`insert`&&(o.insertText(e.delim+e.delim,i+a.pos),o.setSelection(x.create(o.doc,i+a.pos+e.delim.length))),n(o.scrollIntoView())}return!0}function Za(){return s({toggleEm:()=>W(U.em),toggleStrong:()=>W(U.strong),toggleCode:()=>W(U.code),toggleDel:()=>W(U.del),toggleHighlight:()=>W(U.highlight)})}function Qa(){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 $a(){return g(Za(),Qa())}function eo(e,t,n){let r;return e.doc.nodesBetween(t.from,t.to,(e,i)=>(e.isText&&e.marks.some(e=>e.type.name===n)&&(r={from:Math.max(i,t.from),to:Math.min(i+e.nodeSize,t.to)}),!0)),r}function G(e,t){let n=E(e,t,`mdLinkText`),r=E(e,t,`mdPack`,{key:`link`})??E(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`?eo(e,t,`mdLinkText`)??{from:i.from+1,to:i.to-1}:t,href:o,title:``}}let s=eo(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 to(e){let t=e.trim();return t?bi(t)??t:``}function no(e,t){return e+(t?` "${t.replaceAll(/(["\\])/g,String.raw`\$1`)}"`:``)}function ro(e){let{selection:t}=e,{$from:n,$to:r,empty:i}=t;if(i||!n.sameParent(r)||!h(t))return;let a=n.parent;if(!a.isTextblock||a.type.spec.code)return;let o=n.start(),[s,c]=Ha(a.textContent,n.parentOffset,r.parentOffset);if(!(s>=c))return{from:o+s,to:o+c}}function io({href:e,title:t,wrapText:n=!0}={}){return(r,i)=>{let a=ro(r);if(!a)return!1;if(i){let{from:o,to:s}=a,c=r.tr,l=`](${no(to(e??``),t??``)})`;c.insertText(l,s).insertText(`[`,o);let u=s+1+l.length;c.setSelection(n?x.create(c.doc,o,u):x.create(c.doc,u)),c.scrollIntoView(),i(c)}return!0}}function ao(e){return(t,n)=>{let r=G(t,t.selection.from);if(!r?.dest)return!1;let i=no(to(e.href??r.href),e.title??r.title);return n&&n(t.tr.insertText(i,r.dest.from,r.dest.to).scrollIntoView()),!0}}function oo(){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 so(){return s({insertLink:io,updateLink:ao,removeLink:oo})}function co(e){return(t,n,r)=>{let i=G(t,t.selection.from);if(i){if(n&&r){let{unit:{from:a,to:o}}=i;n(t.tr.setSelection(x.create(t.doc,a,o)).scrollIntoView()),r.focus(),e({from:a,to:o,link:i})}return!0}let a=ro(t);if(a){if(n&&r){let{from:i,to:o}=a;n(t.tr.setSelection(x.create(t.doc,i,o)).scrollIntoView()),r.focus(),e({from:i,to:o,link:void 0})}return!0}return!1}}function lo(e){return l({"Mod-k":co(e)})}function uo(e){return e===`)`||e===`*`||e===`+`?e:void 0}function fo(e){return e===`X`?e:void 0}function po(e){return go(e)?String(e):void 0}function mo(){return f({type:`list`,attr:`marker`,default:null,splittable:!0,toDOM:e=>{let t=uo(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 ho(){return f({type:`list`,attr:`taskMarker`,default:null,splittable:!0,toDOM:e=>{let t=fo(e);return t==null?null:[`data-list-task-marker`,t]},parseDOM:e=>e.getAttribute(`data-list-task-marker`)===`X`?`X`:null})}function go(e){return e===2||e===3||e===4}function _o(){return f({type:`list`,attr:`markerGap`,default:1,splittable:!0,toDOM:e=>{let t=po(e);return t==null?null:[`data-list-marker-gap`,t]},parseDOM:e=>{let t=Number.parseInt(e.getAttribute(`data-list-marker-gap`)??``,10);return go(t)?t:1}})}function vo(e){let t=e.attrs;return{...gt(e),"data-list-marker":uo(t.marker),"data-list-task-marker":fo(t.taskMarker),"data-list-marker-gap":po(t.markerGap)}}function yo(){return o({serializeFragmentWrapper:e=>(...t)=>bo(yt(e(...t))),serializeNodeWrapper:e=>(...t)=>{let n=e(...t);return _e(n)?bo(yt(n)):n},nodesFromSchemaWrapper:e=>(...t)=>({...e(...t),list:e=>bt({node:e,nativeList:!0,getAttributes:vo})})})}function bo(e){_e(e)&&xo(e);for(let t of e.children)bo(t);return e}function xo(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=_t(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 So=[St(/^\s?([*-])\s$/,{kind:`bullet`,collapsed:!1}),St(/^\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}}),St(/^\s?\[([\sX]?)\]\s$/i,({match:e})=>({kind:`task`,checked:[`x`,`X`].includes(e[1]),collapsed:!1})),St(/^\s?\+\s$/,{kind:`task`,marker:`+`,checked:!1,collapsed:!1})];function Co(){return g(So.map(qe))}function wo(){return T({kind:`task`,marker:`+`})}function To(){return T({kind:`task`,marker:null})}function Eo(e){let{$from:t}=e.selection;for(let e=t.depth;e>0;e--){let n=t.node(e);if(n.type.name===`list`)return n.attrs}return null}function Do(){return(e,t,n)=>{let r=Eo(e);return(r?.kind===`task`?r.marker===`+`?To():wo():T({kind:`task`,marker:null,checked:!1}))(e,t,n)}}function Oo(){return s({cycleCheckableList:Do,wrapInCircleTask:wo,wrapInSquareTask:To})}function ko(){return(e,t,n)=>{let r=Eo(e),i=r?.kind===`task`&&r.marker!==`+`,a;return a=i&&!r?.checked?{kind:`task`,marker:r?.marker??null,checked:!0}:i&&r?.checked?{kind:`bullet`,marker:null,checked:!1}:{kind:`task`,marker:null,checked:!1},T(a)(e,t,n)}}function Ao(){return(e,t,n)=>{let r=Eo(e),i=r?.kind===`task`&&r.marker===`+`,a;return a=i&&!r?.checked?{kind:`task`,marker:`+`,checked:!0}:i&&r?.checked?{kind:`bullet`,marker:null,checked:!1}:{kind:`task`,marker:`+`,checked:!1},T(a)(e,t,n)}}function jo(e){return e.type.name===`list`&&e.attrs.kind===`bullet`&&e.childCount>=2&&e.firstChild?.type!==e.type}const Mo=e=>{let t=e.attrs;return t.kind===`task`?{...t,checked:!t.checked}:jo(e)?{...t,collapsed:!t.collapsed}:t};function No(){return m(()=>[new v({props:{handleDOMEvents:{mousedown:(e,t)=>vt({view:e,event:t,onListClick:Mo})}}}),pt(),new v({props:{transformCopied:xt}}),mt()])}function Po(){return s({toggleListCollapsed:()=>ht({isToggleable:jo})})}function Fo(){return l({"Mod-Enter":ko(),"Mod-Shift-Enter":Ao(),"Mod-.":ht({isToggleable:jo}),"Mod-Shift-7":ft({kind:`ordered`,collapsed:!1}),"Mod-Shift-8":ft({kind:`bullet`,collapsed:!1}),"Mod-Shift-9":ft({kind:`task`,checked:!1,collapsed:!1})})}function Io(){return g(ut(),No(),lt(),st(),yo(),ct(),Co(),Fo(),mo(),ho(),_o(),Oo(),Po())}let Lo;function Ro(){return Lo??=import(`katex`).then(e=>e.render),Lo}function zo(e,t,n,r){try{e(n,t,{displayMode:r,throwOnError:!1,output:`mathml`})}catch(e){t.textContent=String(e)}}var Bo=class{#e;#t;#n;#r;constructor(e,t){this.#r=e.attrs.formula,this.#e=document.createElement(`span`),this.#e.className=`md-math-view`,this.#n=document.createElement(`span`),this.#n.className=`md-math-view-preview`,this.#n.dataset.testid=`math-preview`,this.#n.contentEditable=`false`,this.#n.addEventListener(`mousedown`,e=>{e.preventDefault();let n=t.posAtDOM(this.#t,0);if(n<0)return;let r=x.near(t.state.doc.resolve(n),1);t.dispatch(t.state.tr.setSelection(r)),t.focus()}),this.#t=document.createElement(`span`),this.#t.className=`md-math-view-content`,this.#e.appendChild(this.#n),this.#e.appendChild(this.#t),this.#i()}get dom(){return this.#e}get contentDOM(){return this.#t}update(e){let t=e.attrs.formula;return t!==this.#r&&(this.#r=t,this.#i()),!0}ignoreMutation(e){return!this.#t.contains(e.target)}#i(){let e=this.#r;Ro().then(t=>{e===this.#r&&zo(t,this.#n,e,!1)})}};function Vo(){return d({name:`mdMath`,constructor:(e,t)=>new Bo(e,t)})}function Ho(e){return e===`left`||e===`center`||e===`right`?e:null}function Uo(){return f({type:`tableCell`,attr:`align`,default:null,toDOM:e=>e?[`data-align`,e]:null,parseDOM:e=>Ho(e.getAttribute(`data-align`))})}function Wo(){return f({type:`tableHeaderCell`,attr:`align`,default:null,toDOM:e=>e?[`data-align`,e]:null,parseDOM:e=>Ho(e.getAttribute(`data-align`))})}function Go(e){for(let t=0;t<e.childCount;t++){let n=e.child(t);for(let e=0;e<n.childCount;e++)if(n.child(e).type.name===`tableHeaderCell`)return t}return 0}function Ko(e){return e.child(Go(e))}function qo(e,t){return t>=e.childCount?null:e.child(t).attrs.align??null}function Jo(e,t,n){if(e.childCount===0)return;let r=Ko(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=qo(r,e);(t.attrs.align??null)!==i&&n.setNodeMarkup(o,void 0,{...t.attrs,align:i}),o+=t.nodeSize}i+=a.nodeSize}}function Yo(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 Xo(){return new v({key:new y(`table-align-sync`),appendTransaction(e,t,n){if(!e.some(e=>e.docChanged))return;let r=Yo(e);if(!r)return;let i=n.doc,a=Math.max(0,Math.min(r.from,i.content.size)),o=Math.max(a,Math.min(r.to,i.content.size)),s;return i.nodesBetween(a,o,(e,t)=>e.type.name===`table`?(s??=n.tr,Jo(e,t,s),!1):!0),s?.docChanged?s:void 0}})}function Zo(){return m(Xo())}function Qo(e){let{selection:t}=e;if(jt(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 $o(e){return(t,n)=>{let r=Qo(t);if(!r||r.table.childCount===0)return!1;if(n){let{table:i,tablePos:a,firstColumn:o,lastColumn:s}=r,c=Go(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 es(e){let t=Qo(e);if(!(!t||t.table.childCount===0))return qo(Ko(t.table),t.lastColumn)??void 0}function ts(){return s({setTableColumnAlign:$o})}function ns(){return g(Uo(),Wo(),Zo(),ts())}function rs(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 is=`paragraph`;function as(){return g(p({name:`tableCell`,content:is}),p({name:`tableHeaderCell`,content:is}))}const os=(e,t)=>{let{selection:n}=e;return!jt(n)||!n.isColSelection()||!n.isRowSelection()?!1:At(e,t)};function ss(){return _(l({Backspace:os,Delete:os}),t.high)}function cs(){return g(kt(),Ot(),Ct(),Dt(),as(),ns(),Et({allowTableNodeSelection:!0}),wt(),Tt(),ss())}function ls(e){let{selection:t}=e,{$from:n,$to:r}=t;if(oe(t)&&n.depth===0||n.depth>0&&r.depth>0&&n.index(0)===r.index(0))return n.index(0)}function us(e){return(t,n)=>{if(rs(t))return!1;let r=ls(t);if(r==null)return!1;let i=r+e;if(i<0||i>=t.doc.childCount)return!1;if(n){let{selection:a}=t,o=Math.min(r,i),s=a.$from.posAtIndex(o,0),c=t.doc.child(o),l=t.doc.child(o+1),u=t.tr.replaceWith(s,s+c.nodeSize+l.nodeSize,[l,c]),d=e===-1?-c.nodeSize:l.nodeSize,f=oe(a)?Ee.create(u.doc,a.from+d):x.create(u.doc,a.anchor+d,a.head+d);u.setSelection(f),n(u.scrollIntoView())}return!0}}function ds(e){return(t,n,r)=>dt(e)(t,n,r)||us(e===`up`?-1:1)(t,n,r)}function fs(){return l({"Alt-ArrowUp":ds(`up`),"Alt-ArrowDown":ds(`down`)})}const K=new y(`meowdownPendingReplacement`);function q(e){return K.getState(e)?.pending??null}function ps(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 ms=new v({key:K,state:{init:()=>({pending:null}),apply:(e,t)=>{let n=e.getMeta(K);if(n)return ps(n,t);if(e.docChanged&&t.pending){let n=e.mapping.mapResult(t.pending.from,1),r=e.mapping.mapResult(t.pending.to,-1),i=Math.min(n.pos,r.pos),a=Math.max(n.pos,r.pos);return(n.deletedAfter&&r.deletedBefore||i>=a)&&t.pending.mode===`replace`?{pending:null,ended:{pending:t.pending,outcome:`discarded`}}:{pending:{...t.pending,from:i,to:a}}}return t}},props:{decorations:e=>{let t=q(e);return!t||t.from>=t.to?null:S.create(e.doc,[De.inline(t.from,t.to,{class:`md-pending-replacement`})])}}});function hs(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 gs(e){return(t,n)=>q(t)?(n?.(t.tr.setMeta(K,{type:`append`,text:e})),!0):!1}function _s(){return(e,t)=>q(e)?(t?.(e.tr.setMeta(K,{type:`discard`})),!0):!1}function vs(e={}){return(t,n)=>{let r=q(t);if(!r||!r.text.trim())return!1;if(n){let i=e.mode??r.mode,a=ec(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(x.near(s.doc.resolve(e+o.content.size),-1))}else{let e=t.doc.resolve(r.from),n=t.doc.resolve(r.to),i=o.childCount===1?o.firstChild:null;i?.type.name===`paragraph`&&e.sameParent(n)&&e.parent.isTextblock?(s.replaceWith(r.from,r.to,i.content),s.setSelection(x.near(s.doc.resolve(r.from+i.content.size),-1))):(s.replaceRange(r.from,r.to,new w(o.content,0,0)),s.setSelection(x.near(s.doc.resolve(s.mapping.map(r.to)),-1)))}n(s.scrollIntoView())}return!0}}function ys(){return s({startPendingReplacement:hs,appendPendingReplacementText:gs,acceptPendingReplacement:vs,discardPendingReplacement:_s})}function bs(){return l({"Mod-Enter":vs(),Escape:_s()})}function xs(){return g(m(ms),ys(),bs())}function Ss(e){return m(new v({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 Cs(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 Cs(r)?void 0:r}function ws(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 Ts(e){let t=e.state,n=t.selection.head,r=R(t,n),i=z(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 Es(e){let t=e.state,n=t.selection.head;for(let r of Ht){let i=E(t,n,r);if(i==null||i.from!==n&&i.to!==n)continue;let a=Ds(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 Ds(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 Os(e){return Ts(e)??Es(e)}const ks=new y(`meowdown-scroll-to-selection`);function As(e){let t=e.state.selection;if(!h(t)||J(e,t.head,1)!=null)return!1;let n=Os(e);if(n==null)return!1;let r=e.domAtPos(t.head).node;return Ps(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 js(e){let t=e.assignedSlot??e.parentNode;return t?.nodeType===11?t.host:t}function Ms(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 Ns(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 Ps(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=js(e);continue}let n=e,o=n===a.body,s=o?Ms(a):Ns(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:js(n)}}function Fs(){return m(new v({key:ks,props:{handleScrollToSelection:As}}))}function Is(e,t){return(n,r)=>{let i=e<0?b.atStart(n.doc):b.atEnd(n.doc),a=t?x.between(n.selection.$anchor,i.$head):i;return n.selection.eq(a)||r?.(n.tr.setSelection(a).scrollIntoView()),!0}}function Ls(){return l({"Meta-ArrowUp":Is(-1,!1),"Meta-ArrowDown":Is(1,!1),"Shift-Meta-ArrowUp":Is(-1,!0),"Shift-Meta-ArrowDown":Is(1,!0)})}function Rs(e){e.offsetWidth}const zs=new y(`meowdown-virtual-caret`),Bs=[`md-virtual-caret-blink`,`md-virtual-caret-blink2`];function Vs(e){let t=e.height*.19999999999999996;return{left:e.left,top:e.top-t/2,height:e.height+t}}function Hs(e){let t=ws(e)??Ts(e);return t==null?Es(e):Vs(t)}function Us(e,t){return e==null||t==null?e===t:e.left===t.left&&e.top===t.top&&e.height===t.height}var Ws=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=Bs[this.#s]}#l=()=>{let e=this.#e;if(e.isDestroyed)return;let t=e.state,n=t.selection,r=h(n)&&n.empty?Hs(e):void 0,i=r!=null&&O(t)===`hide`?Zr(t,n.head):void 0;if(Us(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&&(Rs(this.#n),this.#n.style.transitionProperty=``)}};function Gs(){return m(new v({key:zs,view:e=>new Ws(e)}))}function Ks(e){return g(Mn(),xe(),Vr(),we(),be(),Io(),On(),cs(),Mr(),li(),ui(),Ia(),Cr(),Br(),fs(),Ls(),ba(e),$a(),so(),ta(),Vo(),Rt(e.markMode??`focus`),_r(),Gs(),Fs(),si(),en({marks:Ht.map(e=>({name:e,modes:[`hide`,`focus`,`show`]}))}),a(),i(),c(),Se(),Te(),Ce(),Rr(),xs())}function qs(e={}){return Ks(e)}const Js=ye(()=>{let e=qs().schema;if(e==null)throw Error(`Unexpected empty schema`);return e}),Ys=ye(()=>r(Js())),Xs=ye(()=>n(Js())),Zs=`meowdown_mark_builders`;function Qs(e){let t=e.cached[Zs];if(t)return t;let r=n(e);return e.cached[Zs]=r,r}const $s=`meowdown_node_builders`;function ec(e){let t=e.cached[$s];if(t)return t;let n=r(e);return e.cached[$s]=n,n}function X(e,t={}){let{nodes:n=Ys(),frontmatter:r=!1}=t,i,a=e;if(r){let[t,n]=nc(e);i=t,n&&(a=e.slice(n))}let o=rc(n,Ui.parse(a).cursor(),a);return n.doc(i===void 0?{}:{frontmatter:i},o)}const tc=/^---[ \t]*\r?\n([\s\S]*?\n)?---[ \t]*(?:\r?\n|$)/;function nc(e){let t=tc.exec(e);return t?[(t[1]??``).replace(/\r?\n$/,``),t[0].length]:[]}function rc(e,t,n){let r=[];if(!t.firstChild())return r;let i;do i!=null&&ic(r,e,n,i,t.from),i=t.to,r.push(...ac(e,t,n));while(t.nextSibling());return t.parent(),r}function ic(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 ac(e,t,n){switch(t.type.id){case V.ATXHeading1:return[Z(e,t,n,1,!1)];case V.ATXHeading2:return[Z(e,t,n,2,!1)];case V.ATXHeading3:return[Z(e,t,n,3,!1)];case V.ATXHeading4:return[Z(e,t,n,4,!1)];case V.ATXHeading5:return[Z(e,t,n,5,!1)];case V.ATXHeading6:return[Z(e,t,n,6,!1)];case V.SetextHeading1:return[Z(e,t,n,1,!0)];case V.SetextHeading2:return[Z(e,t,n,2,!0)];case V.Paragraph:return[dc(e,t,n)];case V.CommentBlock:return[fc(e,t,n)];case V.HTMLBlock:case V.ProcessingInstructionBlock:return[dc(e,t,n)];case V.Blockquote:return[pc(e,t,n)];case V.BulletList:return mc(e,t,n,`bullet`);case V.OrderedList:return mc(e,t,n,`ordered`);case V.FencedCode:case V.CodeBlock:return[gc(e,t,n)];case V.BlockMath:return[_c(e,t,n)];case V.HorizontalRule:{let r=n.slice(t.from,t.to).trimEnd();return[e.horizontalRule({marker:r===`---`?null:r})]}case V.Table:return[vc(e,t,n)];case V.Task:return[dc(e,t,n)];default:return n.slice(t.from,t.to).trim()===``?[]:(console.warn(`[meowdown] unsupported lezer block "${t.type.name}"`),[dc(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===V.HeaderMark&&t.from===a&&(o=t.to);let e=-1,n=-1,r=-1;do e=t.type.id,n=t.from,r=t.to;while(t.nextSibling());e===V.HeaderMark&&n>o&&(s=n,c=n,l=r),t.parent()}let u=lc(n.slice(o,s),Q(n,o)).trim(),d=i?oc(n,c,l)||1:null,f=!i&&c>=0&&sc(n,c,l)||null;return e.heading({level:r,setextUnderline:d,closingHashes:f},u)}function oc(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 sc(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(`
26
+ `,t-1)+1,r=0;for(let i=n;i<t;i++)r+=e.charCodeAt(i)===9?4-r%4:1;return r}function cc(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 lc(e,t){return t===0||!e.includes(`
27
+ `)?e:e.split(`
28
+ `).map((e,n)=>n===0?e:cc(e,t)).join(`
29
+ `)}function uc(e,t,n){return e.paragraph(lc(t,n))}function dc(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===V.QuoteMark&&(o+=n.slice(s,t.from),s=t.to,N(n.charCodeAt(s))&&(s+=1));while(t.nextSibling());return t.parent(),o+=n.slice(s,i),uc(e,o,a)}return uc(e,n.slice(r,i),a)}function fc(e,t,n){let r=Q(n,t.from),i=lc(n.slice(t.from,t.to),r);return e.htmlComment({content:i})}function pc(e,t,n){let r=[];if(t.firstChild()){let i;do{if(t.type.id===V.QuoteMark)continue;i!=null&&ic(r,e,n,i,t.from),i=t.to,r.push(...ac(e,t,n))}while(t.nextSibling());t.parent()}return e.blockquote(r)}function mc(e,t,n,r){let i=[];if(t.firstChild()){do t.type.id===V.ListItem&&i.push(hc(e,t,n,r));while(t.nextSibling());t.parent()}return i}function hc(e,t,n,r){let i=[],a,o,s,c,l,u;if(t.firstChild()){do{if(t.type.id!==V.ListMark&&u==null&&(u=Q(n,t.from)),t.type.id===V.ListMark){if(r===`ordered`){let e=n.charCodeAt(t.to-1);e===41?c=`)`:e===46&&(c=`.`);let r=Number.parseInt(n.slice(t.from,t.to),10);s=Number.isFinite(r)?r:1}else{let e=n.charCodeAt(t.from);c=e===42?`*`:e===43?`+`:`-`}l=Q(n,t.to);continue}if(r===`bullet`&&t.type.id===V.Task){let r=t.from,s=t.to;if(a=!1,t.firstChild()){if(t.type.id===V.TaskMarker){let e=n.charCodeAt(t.from+1);e===120?(a=!0,o=`x`):e===88&&(a=!0,o=`X`),r=t.to}t.parent()}N(n.charCodeAt(r))&&(r+=1);let c=n.slice(r,s);i.push(uc(e,c,Q(n,r)));continue}i.push(...ac(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 gc(e,t,n){let r=t.type.id===V.CodeBlock,i=``,a=``,o=r?`indented`:null,s=null,c=!1;if(t.firstChild()){do switch(t.type.id){case V.CodeMark:{if(c)break;c=!0,n.charCodeAt(t.from)===126&&(o=`tilde`);let e=t.to-t.from;e>3&&(s=e);break}case V.CodeInfo:i=n.slice(t.from,t.to);break;case V.CodeText:a+=n.slice(t.from,t.to);break}while(t.nextSibling());t.parent()}return e.codeBlock({language:i,fenceStyle:o,fenceLength:s},a)}function _c(e,t,n){let r=``;if(t.firstChild()){do t.type.id===V.CodeText&&(r+=n.slice(t.from,t.to));while(t.nextSibling());t.parent()}return e.codeBlock({language:`math`,fenceStyle:`dollar`,fenceLength:null},r)}function vc(e,t,n){let r=[];if(t.firstChild()){do t.type.id===V.TableDelimiter&&(r=yc(n.slice(t.from,t.to)));while(t.nextSibling());t.parent()}let i=[];if(t.firstChild()){do{let a=t.type.id;a===V.TableHeader?i.push(bc(e,t,n,!0,r)):a===V.TableRow&&i.push(bc(e,t,n,!1,r))}while(t.nextSibling());t.parent()}return e.table(i)}function yc(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 bc(e,t,n,r,i){let a=i.length,o=Array(a).fill(``);if(t.firstChild()){let e=t.type.id===V.TableDelimiter,r=0;do if(t.type.id===V.TableDelimiter)r++;else if(t.type.id===V.TableCell){let i=r-+!!e;i>=0&&i<a&&(o[i]=n.slice(t.from,t.to).trim().replaceAll(String.raw`\|`,`|`))}while(t.nextSibling());t.parent()}let s=o.map((t,n)=>{let a=e.paragraph(t),o={align:i[n]};return r?e.tableHeaderCell(o,a):e.tableCell(o,a)});return e.tableRow(s)}function xc(e){return e.replace(/\n+$/u,``)}function Sc(e){return/^[\s>]*$/u.test(e)}function Cc(e){return e.split(`
30
+ `).filter(e=>!Sc(e))}function wc(e){return e.trim().replaceAll(/\s+/gu,` `)}function Tc(e,t={}){let n=P(X(e,{frontmatter:t.frontmatter}),{frontmatter:t.frontmatter});if(xc(n)===xc(e))return`exact`;let r=Cc(e),i=Cc(n);return r.length===i.length&&r.every((e,t)=>wc(e)===wc(i[t]))?`normalizing`:`lossy`}const Ec=(e,t)=>{let{$from:n,empty:r}=e.selection;if(!r||n.depth!==1||n.index(0)!==0||n.parent.type.name!==`heading`||n.parentOffset!==n.parent.content.size)return!1;if(t){let r=ne(e.schema,`list`),i=ne(e.schema,`paragraph`),a=r.create({kind:`bullet`},i.create()),o=n.after(),s=e.tr.insert(o,a);s.setSelection(x.create(s.doc,o+2)),t(s.scrollIntoView())}return!0};function Dc(){return _(l({Enter:Ec}),t.high)}const Oc=new Set([`MscGen`,`Xù`,`MsGenny`,`Angular Template`,`Brainfuck`,`Esper`,`Oz`,`Factor`,`Squirrel`,`Yacas`,`mIRC`,`FCL`,`ECL`,`MUMPS`,`Pig`,`Asterisk`,`Z80`,`Mathematica`]),kc=He.map(e=>({label:e.name,value:e.name.toLowerCase()})).filter(e=>!Oc.has(e.label)).concat([{label:`Plain text`,value:``},{label:`Math`,value:`math`}]).sort((e,t)=>e.label.localeCompare(t.label));function Ac(){return typeof window>`u`?!1:window.matchMedia(`(prefers-color-scheme: dark)`).matches}const jc=/^(?:www\.|mobile\.)?(?:twitter\.com|x\.com)$/i,Mc=/\/status(?:es)?\/(\d+)/;function Nc(e){let t;try{t=new URL(e)}catch{return}if(jc.test(t.hostname))return Mc.exec(t.pathname)?.[1]}const Pc=e=>{let t=Nc(e);if(!t)return;let n=Ac()?`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 Fc(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 Ic=/^(?:www\.|m\.)?(?:youtube\.com|youtube-nocookie\.com)$/i,Lc=/^(?:www\.)?youtu\.be$/i,Rc=/^[\w-]{11}$/;function zc(e){let t;try{t=new URL(e)}catch{return}let n=null;if(Lc.test(t.hostname))n=t.pathname.slice(1);else if(Ic.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||!Rc.test(n))return;let r=t.searchParams.get(`start`)??t.searchParams.get(`t`),i=r?Bc(r):void 0;return{videoId:n,startSeconds:i}}function Bc(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 Vc=[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}},Pc];function Hc(e){for(let t of Vc){let n=t(e);if(n)return n}}function Uc(e,t){return e.clipboardData?.getData(`text/plain`)||t.content.textBetween(0,t.content.size,`
31
+ `)}const Wc=new y(`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(Mt(e.state.tr.insertText(t,n,r)));let i=e.state.tr.insertText(`![](${t})`,n,n+t.length);e.dispatch(Mt(i))}function qc(){return m(new v({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 y(`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&&b.findFrom(a,t))}function Xc(e,t){let{state:n}=e,{selection:r}=n;return h(r)&&!r.empty||re(r)||r.$from.parent.inlineContent&&!e.endOfTextblock(t<0?`up`:`down`)?!0:Yc(n,t)}function Zc(e){return new v({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 _(m(Zc(e)),t.low)}function $c(e){return!!e.type?.startsWith(`image/`)}function el(e,t){return $c(e)?`![](${t})`:`[${rl(e.name)}](${t})`}function tl(e,t){return!e||!t.onFilePaste?[]:Array.from(e.files)}const nl=e=>{console.error(`[meowdown] failed to save pasted file:`,e)};function rl(e){return e.replaceAll(/[\\[\]]/g,String.raw`\$&`)}async function il(e,t,n,r){let{onFilePaste:i}=n;if(!i)return;let a=n.onFileSaveError??nl,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=el(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 al(e){return new v({key:new y(`file-paste`),props:{handlePaste:(t,n)=>{let r=tl(n.clipboardData,e);return r.length===0?!1:(il(t,r,e),!0)},handleDrop:(t,n)=>{let r=tl(n.dataTransfer,e);return r.length===0?!1:(il(t,r,e,t.posAtCoords({left:n.clientX,top:n.clientY})?.pos),!0)}}})}function ol(e={}){return _(m(al(e)),t.high)}const sl=new y(`meowdown-file-click`);function cl(e,t){let n=E(e,t,`mdFile`);if(!n)return;let{href:r,name:i}=n.mark.attrs;return{href:r,name:i}}function ll(e){return m(new v({key:sl,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=cl(t.state,t.posAtDOM(a,0));return o?(e({href:o.href,name:o.name,event:r}),!0):!1}}}))}const ul=[`KB`,`MB`,`GB`,`TB`];function dl(e){let t=e,n=`B`;for(let e of ul){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 fl=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 pl(e){let t=e.split(/[?#]/,1)[0],n=t.lastIndexOf(`.`);if(n<0)return`generic`;let r=t.slice(n+1).toLowerCase();return fl.get(r)??`generic`}const ml=`http://www.w3.org/2000/svg`;function hl(){let e=document.createElementNS(ml,`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(ml,`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 gl=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=pl(this.#a.href),this.#n.title=this.#a.name,this.#e.appendChild(this.#n),this.#n.appendChild(hl()),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=dl(n))}};function _l(e={}){return d({name:`mdFile`,constructor:t=>new gl(t,e)})}function vl(e){return m(new v({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 yl=new y(`meowdown-tag-click`);function bl(e,t){let n=E(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 xl(e){return vl({key:yl,selector:`.md-tag`,preventDefault:!1,findPayloadAt:(e,t)=>bl(e,t)?.tag,onClick:(t,n)=>e({tag:t,event:n})})}const Sl=new y(`meowdown-wikilink-click`);function Cl(e,t){let n=E(e,t,`mdWikilink`);if(!n)return;let{target:r}=n.mark.attrs;return{from:n.from,to:n.to,target:r}}function wl(e,t){let n=t.closest(`.md-wikilink-view`)?.querySelector(`.md-wikilink-view-content`);if(n)return Cl(e.state,e.posAtDOM(n,0))}function Tl(e){return vl({key:Sl,selector:`.md-wikilink-view-preview`,preventDefault:!1,findPayloadAt:(e,t)=>Cl(e,t)?.target,findPayloadForElement:(e,t)=>wl(e,t)?.target,onClick:(t,n)=>e({target:t,event:n})})}const El=new y(`meowdown-follow-link`);function Dl(e){return e.key!==`Enter`||e.shiftKey||e.altKey?!1:ie?e.metaKey&&!e.ctrlKey:e.ctrlKey&&!e.metaKey}function Ol(e){return new v({key:El,props:{handleKeyDown:(t,n)=>{if(!Dl(n))return!1;let{state:r}=t,i=r.selection.head,a=e.onWikilinkClick&&Cl(r,i);if(a)return e.onWikilinkClick?.({target:a.target,event:n}),!0;let o=e.onTagClick&&bl(r,i);if(o)return e.onTagClick?.({tag:o.tag,event:n}),!0;let s=e.onFileClick&&cl(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 kl(e){return _(m(Ol(e)),t.high)}const Al=new y(`meowdown-image-click`);function $(e){return e instanceof HTMLElement&&e.closest(`.md-image-view-preview`)}function jl(e,t){let n=E(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 Ml(e,t){let n=t.closest(`.md-image-view`)?.querySelector(`.md-image-view-content`);if(n)return jl(e.state,e.posAtDOM(n,0))}function Nl(e,t){return Array.from(e).find(e=>e.identifier===t)}function Pl(e,t){return Math.abs(t.clientX-e.clientX)<=10&&Math.abs(t.clientY-e.clientY)<=10}function Fl(e){let t=new WeakMap;return m(new v({key:Al,props:{handleDOMEvents:{pointerdown:(e,t)=>($(t.target)&&t.pointerType!==`mouse`&&t.preventDefault(),!1),touchstart:(e,n)=>{if(t.delete(e),n.touches.length!==1||!$(n.target)||n.target instanceof HTMLElement&&n.target.closest(`.md-image-resize-handle`))return!1;let r=n.changedTouches[0];return r&&t.set(e,{identifier:r.identifier,clientX:r.clientX,clientY:r.clientY}),!1},touchmove:(e,n)=>{let r=t.get(e);if(!r)return!1;let i=Nl(n.changedTouches,r.identifier);return i&&!Pl(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=Nl(r.changedTouches,i.identifier);if(!a||!Pl(i,a))return!1;let o=$(r.target);if(!o)return!1;r.preventDefault();let s=Ml(n,o);return s&&e({src:s.src,alt:s.alt,event:r}),!0}},handleClick:(t,n,r)=>{let i=$(r.target);if(!i)return!1;let a=Ml(t,i);return a?(e({src:a.src,alt:a.alt,event:r}),!0):!1}}}))}function Il(e){return/^https?:\/\//i.test(e)?e:void 0}function Ll(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 Rl(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 zl(e,t,n,r){let i=e.posAtDOM(t,0),a=E(e.state,i,`mdImage`);if(!a)return;let o=e.state.doc.textBetween(a.from,a.to),s=Qi(o),c=a.from+s.length,l=o.slice(s.length),u=Zi({...Yi(l)??{},width:Math.round(n),height:Math.round(r)});u!==l&&e.dispatch(e.state.tr.insertText(u,c,a.to))}var Bl=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)&&Rl(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(Ll(t)),e}let n=(this.#n.resolveImageUrl??Il)(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){Pt(),Nt();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,Rl(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)),Rl(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;zl(this.#r,this.#t,t,n)}),this.#a=t,this.#o=n,t}};function Vl(e={}){return d({name:`mdImage`,constructor:(t,n)=>new Bl(t,n,e)})}const Hl={"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`},Ul=new y(`meowdown-link-click`);function Wl(e){return vl({key:Ul,selector:`.md-link`,preventDefault:!0,findPayloadAt:(e,t)=>G(e,t)?.href,onClick:(t,n)=>e({href:t,event:n})})}function Gl(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||!_e(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 v({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 Kl=new y(`meowdown-link-hover`);function ql(e){return Gl({key:Kl,selector:`.md-link`,findPayloadAt:(e,t)=>G(e,t),isSamePayload:(e,t)=>e.href===t.href&&e.title===t.title,onHoverChange:e})}const Jl=new y(`meowdown-link-paste`);function Yl(e){let t=e.trim();if(!(!t||/\s/.test(t)))return bi(t)}function Xl(){return _(m(new v({key:Jl,props:{handlePaste:(e,t,n)=>{let r=Uc(t,n);if(!r)return!1;let i=Yl(r);return i?Hr(e,io({href:i,wrapText:!1})):!1}}})),t.high)}const Zl=new y(`meowdown-wikilink-hover`);function Ql(e){return Gl({key:Zl,selector:`.md-wikilink-view-preview`,findPayloadAt:Cl,findPayloadForElement:wl,isSamePayload:(e,t)=>e.target===t.target,onHoverChange:t=>{e(t?{...t.payload,element:t.element}:void 0)}})}const $l=new Set([`mdMark`,`mdLinkUri`,`mdLinkTitle`]);function eu(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=>$l.has(e))&&!(t.preserveMathSource&&n.includes(`mdMath`))||r.push(e.text),!1}),n.push(r.join(``))}),n.join(`
32
+ `)}function tu({allowEmpty:e}){return(t,n)=>{let{selection:r}=t;if(!h(r)||!e&&r.empty||!r.$head.sameParent(r.$anchor)||r.$head.parent.type.spec.code)return!1;let i=eu(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(x.create(e.doc,r.from+a.length)),Ye(e),n(e.scrollIntoView())}return!0}}function nu(){return l({"Mod-Shift-k":tu({allowEmpty:!0}),"[":tu({allowEmpty:!1})})}function ru(e){let{selection:t,schema:n}=e;if(t.empty)return``;let r=t.content().content;try{return P(n.topNodeType.create(null,r)).replace(/\n+$/,``)}catch{return e.doc.textBetween(t.from,t.to,`
31
33
 
32
- `)}}function xl(e,t){let n=new DOMRect(0,0,0,0),r=()=>{if(e.isDestroyed)return n;let r=Y(e,t.from,1)??Y(e,t.from,-1),i=Y(e,t.to,-1)??Y(e,t.to,1);if(r==null||i==null)return n;let a=Math.min(r.left,i.left),o=Math.max(r.right,i.right),s=Math.min(r.top,i.top),c=Math.max(r.bottom,i.bottom);return n=new DOMRect(a,s,o-a,c-s),n};return{getBoundingClientRect:r,getClientRects:()=>[r()]}}function Sl(e){return e instanceof He||e instanceof Ue||e instanceof We||e instanceof Ge||e instanceof R}function Cl(e){for(let t of e)for(let e of t.steps)if(!Sl(e))return!0;return!1}function wl(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){Cl(e)&&o()},view(e){return t=e,{destroy(){t=void 0}}}}}function Tl(e){let t=new y(`spell-check`);return new v({key:t,state:{init:()=>wl(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 El(e){return m(Tl(e))}export{al as EDITOR_KEY_BINDINGS,e as Priority,lc as buildFileMarkdown,Ps as checkRoundTrip,Rs as codeBlockLanguages,$c as defaultResolveImageUrl,Is as defineBulletAfterHeading,pe as defineCodeBlockPreviewPlugin,sn as defineCodeBlockSyntaxHighlight,Ro as defineEditorExtension,nc as defineEmbedPaste,sc as defineExitBoundaryHandler,vc as defineFileClickHandler,hc as defineFilePaste,Ec as defineFileView,Rc as defineFollowLinkHandler,er as defineHTMLComment,Gc as defineHTMLPaste,il as defineImage,Qc as defineImageClickHandler,sl as defineLinkClickHandler,Xi as defineLinkCommands,Qi as defineLinkEditKeymap,ul as defineLinkHoverHandler,pl as defineLinkPaste,hl as defineMarkdownCopy,ka as defineMath,po as definePendingReplacementHandler,he as definePlaceholder,ge as defineReadonly,El as defineSpellCheckPlugin,Ac as defineTagClickHandler,Pc as defineWikilinkClickHandler,_l as defineWikilinkHoverHandler,yl as defineWikilinkTrigger,fs as docToMarkdown,ln as getCodeTokens,K as getLinkUnitAt,Vo as getMarkBuilders,J as getPendingReplacement,bl as getSelectedText,Ha as getTableColumnAlign,xl as getVirtualElementFromRange,Wr as inlineTextToMarkChunks,qi as insertLink,me as isCodeBlockPreviewHiddenDecoration,Ga as isSelectionInTableCell,Ws as listenForTweetHeight,Ea as loadKaTeX,Z as markdownToDoc,Zs as matchEmbed,Yi as removeLink,Da as renderMathInto,Ji as updateLink,le as withPriority};
34
+ `)}}function iu(e,t){let n=new DOMRect(0,0,0,0),r=()=>{if(e.isDestroyed)return n;let r=J(e,t.from,1)??J(e,t.from,-1),i=J(e,t.to,-1)??J(e,t.to,1);if(r==null||i==null)return n;let a=Math.min(r.left,i.left),o=Math.max(r.right,i.right),s=Math.min(r.top,i.top),c=Math.max(r.bottom,i.bottom);return n=new DOMRect(a,s,o-a,c-s),n};return{getBoundingClientRect:r,getClientRects:()=>[r()]}}function au(e){return e instanceof Ze||e instanceof Qe||e instanceof $e||e instanceof et||e instanceof mi}function ou(e){for(let t of e)for(let e of t.steps)if(!au(e))return!0;return!1}function su(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){ou(e)&&o()},view(e){return t=e,{destroy(){t=void 0}}}}}function cu(e){let t=new y(`spell-check`);return new v({key:t,state:{init:()=>su(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 lu(e){return m(cu(e))}export{Hl as EDITOR_KEY_BINDINGS,e as Priority,el as buildFileMarkdown,Tc as checkRoundTrip,kc as codeBlockLanguages,Il as defaultResolveImageUrl,Dc as defineBulletAfterHeading,pe as defineCodeBlockPreviewPlugin,Cr as defineCodeBlockSyntaxHighlight,qs as defineEditorExtension,qc as defineEmbedPaste,Qc as defineExitBoundaryHandler,ll as defineFileClickHandler,ol as defineFilePaste,_l as defineFileView,kl as defineFollowLinkHandler,ui as defineHTMLComment,Vl as defineImage,Fl as defineImageClickHandler,Wl as defineLinkClickHandler,so as defineLinkCommands,lo as defineLinkEditKeymap,ql as defineLinkHoverHandler,Xl as defineLinkPaste,Vo as defineMath,Ss as definePendingReplacementHandler,he as definePlaceholder,ge as defineReadonly,lu as defineSpellCheckPlugin,xl as defineTagClickHandler,Tl as defineWikilinkClickHandler,Ql as defineWikilinkHoverHandler,nu as defineWikilinkTrigger,P as docToMarkdown,Tr as getCodeTokens,G as getLinkUnitAt,Xs as getMarkBuilders,q as getPendingReplacement,ru as getSelectedText,es as getTableColumnAlign,iu as getVirtualElementFromRange,ra as inlineTextToMarkChunks,io as insertLink,me as isCodeBlockPreviewHiddenDecoration,rs as isSelectionInTableCell,Fc as listenForTweetHeight,Ro as loadKaTeX,X as markdownToDoc,Hc as matchEmbed,oo as removeLink,zo as renderMathInto,ao as updateLink,le as withPriority};
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@meowdown/core",
3
3
  "type": "module",
4
- "version": "0.46.0",
4
+ "version": "0.47.0",
5
5
  "license": "MIT",
6
6
  "repository": {
7
7
  "type": "git",