@meowdown/core 0.48.0 → 0.49.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/dist/index.d.ts CHANGED
@@ -169,9 +169,8 @@ declare function defineHTMLComment(): HTMLCommentExtension;
169
169
  //#endregion
170
170
  //#region src/extensions/inline-marks.d.ts
171
171
  /**
172
- * Attributes of the `mdImage` mark, derived from the image source
173
- * `![alt](src "title")` and its optional trailing size comment
174
- * `<!-- {"width":N,"height":M} -->`.
172
+ * Attributes of the `mdImage` mark, derived from either `![alt](src "title")`
173
+ * (plus an optional trailing size comment) or a resolved wiki image embed.
175
174
  */
176
175
  interface MdImageAttrs {
177
176
  /** The image destination, exactly as written in the source. */
@@ -184,6 +183,10 @@ interface MdImageAttrs {
184
183
  width: number | null;
185
184
  /** Display height in CSS pixels from the trailing comment, or `null`. */
186
185
  height: number | null;
186
+ /** `wikiEmbed` when the source is `![[target]]`; otherwise `null`. */
187
+ syntax: 'wikiEmbed' | null;
188
+ /** Original wiki-embed target used when persisting a resized image, or `null`. */
189
+ wikiTarget: string | null;
187
190
  }
188
191
  interface MdLinkTextAttrs {
189
192
  href: string;
@@ -361,6 +364,57 @@ declare function definePendingReplacementHandler(handler: PendingReplacementHand
361
364
  */
362
365
  type MarkChunk = readonly [from: number, to: number, marks: readonly Mark[]];
363
366
  //#endregion
367
+ //#region src/extensions/wiki-embed.d.ts
368
+ /** The parsed source payload of an Obsidian-style `![[target]]` embed. */
369
+ interface ParsedWikiEmbed {
370
+ /** Target before an optional alias or size suffix. */
371
+ target: string;
372
+ /** Non-size suffix after `|`, or `''` when absent. */
373
+ display: string;
374
+ /** Requested display width in CSS pixels, or `null`. */
375
+ width: number | null;
376
+ /** Requested display height in CSS pixels, or `null`. */
377
+ height: number | null;
378
+ }
379
+ /** A resolved wiki embed rendered through Meowdown's existing atom views. */
380
+ type WikiEmbedResolution = {
381
+ kind: 'image';
382
+ /** Source passed to `resolveImageUrl` and image click handlers. Defaults to `target`. */
383
+ src?: string;
384
+ /** Image alt text. Defaults to the alias or target basename. */
385
+ alt?: string;
386
+ } | {
387
+ kind: 'file';
388
+ /** Destination passed to file metadata and click handlers. Defaults to `target`. */
389
+ href?: string;
390
+ /** File pill label. Defaults to the alias or target basename. */
391
+ name?: string;
392
+ /** Optional file title. */
393
+ title?: string;
394
+ } | {
395
+ kind: 'note';
396
+ /** Target passed to wikilink click handlers. Defaults to the source target. */
397
+ target?: string;
398
+ /** Chip label. Defaults to the source alias or resolved target. */
399
+ display?: string;
400
+ };
401
+ /**
402
+ * Classifies one wiki embed for rendering. Return `undefined` to leave the
403
+ * source literal and editable. The resolver participates in the parse cache,
404
+ * so it must be pure: the same payload must always return the same result.
405
+ */
406
+ type WikiEmbedResolver = (embed: ParsedWikiEmbed) => WikiEmbedResolution | undefined;
407
+ /** Host options for wiki-embed parsing. */
408
+ interface WikiEmbedOptions {
409
+ resolveWikiEmbed?: WikiEmbedResolver;
410
+ }
411
+ /** Parse `![[target]]`, `![[target|alias]]`, `![[target|width]]`, or `![[target|widthxheight]]`. */
412
+ declare function parseWikiEmbed(source: string): ParsedWikiEmbed;
413
+ /** Rewrite a wiki image embed with a persisted display size. */
414
+ declare function formatSizedWikiEmbed(target: string, width: number, height: number): string;
415
+ /** Last path component of a target, with a note heading/block fragment removed. */
416
+ declare function wikiEmbedBasename(target: string): string;
417
+ //#endregion
364
418
  //#region src/extensions/inline-text-to-mark-chunks.d.ts
365
419
  /** What {@link FileLinkResolver} sees for one `[label](url)` link. */
366
420
  interface FileLinkPayload {
@@ -383,6 +437,8 @@ type FileLinkResolver = (link: FileLinkPayload) => boolean;
383
437
  interface FileLinkOptions {
384
438
  resolveFileLink?: FileLinkResolver;
385
439
  }
440
+ /** Host options that influence source-backed inline atom parsing. */
441
+ type InlineMarkOptions = FileLinkOptions & WikiEmbedOptions;
386
442
  /**
387
443
  * Walk a textblock's inline content and produce a list of mark chunks
388
444
  * with positions relative to the start of `text` (i.e. zero-based).
@@ -394,7 +450,7 @@ marks: TypedMarkBuilders,
394
450
  /** The raw inline text of one textblock (no block prefix). */
395
451
  text: string,
396
452
  /** Host options; omit for the default parse. */
397
- options?: FileLinkOptions): MarkChunk[];
453
+ options?: InlineMarkOptions): MarkChunk[];
398
454
  //#endregion
399
455
  //#region src/extensions/mark-mode.d.ts
400
456
  /**
@@ -591,10 +647,11 @@ declare function defineEditorExtensionImpl(options: EditorExtensionOptions): imp
591
647
  type EditorExtension = ReturnType<typeof defineEditorExtensionImpl>;
592
648
  /**
593
649
  * Options for {@link defineEditorExtension}. Creation-time configuration:
594
- * `resolveFileLink` is baked into the editor's parse pipeline, so changing it
595
- * requires rebuilding the editor; `markMode` is only the initial value.
650
+ * `resolveFileLink` and `resolveWikiEmbed` are baked into the editor's parse
651
+ * pipeline, so changing them requires rebuilding the editor; `markMode` is
652
+ * only the initial value.
596
653
  */
597
- type EditorExtensionOptions = FileLinkOptions & {
654
+ type EditorExtensionOptions = InlineMarkOptions & {
598
655
  /**
599
656
  * The initial mark mode, applied from the first paint. Defaults to
600
657
  * `'focus'`. Switch later with the `setMarkMode` command.
@@ -768,8 +825,8 @@ interface FilePasteOptions {
768
825
  /**
769
826
  * Persist a pasted/dropped file and return its markdown destination, or
770
827
  * `undefined` to decline (nothing is inserted, but the event is consumed).
771
- * An image (`image/*` MIME type) inserts `![](src)`; any other file inserts
772
- * a `[name](src)` link.
828
+ * An image (`image/*` MIME type or a recognized image filename extension)
829
+ * inserts `![](src)`; any other file inserts a `[name](src)` link.
773
830
  */
774
831
  onFilePaste?: FilePasteHandler;
775
832
  /** Called when persisting a pasted/dropped file throws. Defaults to `console.error`. */
@@ -777,10 +834,10 @@ interface FilePasteOptions {
777
834
  }
778
835
  /**
779
836
  * The markdown a saved file becomes: `![](destination)` for an image (a
780
- * `type` starting with `image/`), a `[name](destination)` link otherwise,
781
- * with `\`, `[`, and `]` escaped in the name. Exported so a host command that
782
- * inserts file links itself (e.g. an attach-file picker) produces markdown
783
- * byte-identical to a paste/drop.
837
+ * `type` starting with `image/` or a recognized image filename extension), a
838
+ * `[name](destination)` link otherwise, with `\`, `[`, and `]` escaped in the
839
+ * name. Exported so a host command that inserts file links itself (e.g. an
840
+ * attach-file picker) produces markdown byte-identical to a paste/drop.
784
841
  */
785
842
  declare function buildFileMarkdown(file: {
786
843
  name: string;
@@ -796,7 +853,7 @@ declare function defineFilePaste(options?: FilePasteOptions): PlainExtension;
796
853
  //#region src/extensions/file-click.d.ts
797
854
  /** Payload for {@link FileClickHandler}. */
798
855
  interface FileClickPayload {
799
- /** The link destination, exactly as written in `[name](href)`. */
856
+ /** The resolved destination from `[name](href)` or a claimed `![[target]]`. */
800
857
  href: string;
801
858
  /** The file name shown on the pill. */
802
859
  name: string;
@@ -833,9 +890,11 @@ interface FileViewOptions {
833
890
  /** Resolve the metadata (file size) shown on a pill. Omit to show none. */
834
891
  resolveFileInfo?: FileInfoResolver;
835
892
  }
893
+ /** Classify a file destination for the pill's `data-file-kind` attribute. */
894
+ declare function getFileKind(href: string): string;
836
895
  /**
837
- * Render a claimed file link (the `mdFile` mark, see `resolveFileLink`) as an
838
- * inline pill: a file-kind icon, the file name, and the size once
896
+ * Render a claimed file link or wiki embed (the `mdFile` mark) as an inline
897
+ * pill: a file-kind icon, the file name, and the size once
839
898
  * `resolveFileInfo` supplies it. The pill never loads the file's content;
840
899
  * clicks are reported through `defineFileClickHandler`.
841
900
  */
@@ -899,7 +958,7 @@ declare function defineFollowLinkHandler(handlers: FollowLinkHandlers): PlainExt
899
958
  //#region src/extensions/image-click.d.ts
900
959
  /** Payload for {@link ImageClickHandler}. */
901
960
  interface ImageClickPayload {
902
- /** The markdown `src`, exactly as written in `![alt](src)`. */
961
+ /** The resolved source from `![alt](src)` or a claimed `![[target]]`. */
903
962
  src: string;
904
963
  /** The image alt text. */
905
964
  alt: string;
@@ -1083,4 +1142,11 @@ declare function getVirtualElementFromRange(view: EditorView, range: PositionRan
1083
1142
  //#region src/extensions/spell-check.d.ts
1084
1143
  declare function defineSpellCheckPlugin(spellCheck: boolean): import("@prosekit/core").PlainExtension;
1085
1144
  //#endregion
1086
- 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, defineSubstitution, defineTagClickHandler, defineWikilinkClickHandler, defineWikilinkHoverHandler, defineWikilinkTrigger, docToMarkdown, getCodeTokens, getLinkUnitAt, getMarkBuilders, getPendingReplacement, getSelectedText, getTableColumnAlign, getVirtualElementFromRange, inlineTextToMarkChunks, insertLink, isCodeBlockPreviewHiddenDecoration, isSelectionInTableCell, listenForTweetHeight, loadKaTeX, markdownToDoc, matchEmbed, removeLink, renderMathInto, updateLink, withPriority };
1145
+ //#region src/utils/format-file-size.d.ts
1146
+ /**
1147
+ * Format a byte count for display on a file pill: decimal units (1 KB =
1148
+ * 1000 B, matching macOS Finder), one decimal below 10, integers otherwise.
1149
+ */
1150
+ declare function formatFileSize(bytes: number): string;
1151
+ //#endregion
1152
+ 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 InlineMarkOptions, 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 ParsedWikiEmbed, 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 WikiEmbedOptions, type WikiEmbedResolution, type WikiEmbedResolver, 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, defineSubstitution, defineTagClickHandler, defineWikilinkClickHandler, defineWikilinkHoverHandler, defineWikilinkTrigger, docToMarkdown, formatFileSize, formatSizedWikiEmbed, getCodeTokens, getFileKind, getLinkUnitAt, getMarkBuilders, getPendingReplacement, getSelectedText, getTableColumnAlign, getVirtualElementFromRange, inlineTextToMarkChunks, insertLink, isCodeBlockPreviewHiddenDecoration, isSelectionInTableCell, listenForTweetHeight, loadKaTeX, markdownToDoc, matchEmbed, parseWikiEmbed, removeLink, renderMathInto, updateLink, wikiEmbedBasename, withPriority };
package/dist/index.js CHANGED
@@ -1,34 +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,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 De,TextSelection as b}from"@prosekit/pm/state";import{Decoration as Oe,DecorationSet as x}from"@prosekit/pm/view";import ke from"rehype-parse";import Ae from"rehype-remark";import je from"remark-gfm";import Me from"remark-stringify";import{unified as Ne}from"unified";import{DOMParser as Pe,DOMSerializer as S,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{defineEnterRule as Ke,defineTextBlockEnterRule as qe}from"@prosekit/extensions/enter-rule";import{defineInputRule as Je,defineTextBlockInputRule as Ye}from"@prosekit/extensions/input-rule";import{triggerAutocomplete as Xe}from"@prosekit/extensions/autocomplete";import{defineHorizontalRule as Ze}from"@prosekit/extensions/horizontal-rule";import{AddMarkStep as Qe,AddNodeMarkStep as $e,RemoveMarkStep as et,RemoveNodeMarkStep as tt,ReplaceStep as nt,Step as rt,StepResult as it,Transform as at}from"@prosekit/pm/transform";import{GFM as ot,parser as st}from"@lezer/markdown";import{defineListCommands as ct,defineListDropIndicator as lt,defineListKeymap as ut,defineListSpec as dt,moveList as ft,toggleList as pt,wrapInList as T}from"@prosekit/extensions/list";import{createListRenderingPlugin as mt,createSafariInputMethodWorkaroundPlugin as ht,createToggleCollapsedCommand as gt,defaultAttributesGetter as _t,findCheckboxInListItem as vt,handleListMarkerMouseDown as yt,joinListElements as bt,listToDOM as xt,unwrapListSlice as St,wrappingListInputRule as Ct}from"prosemirror-flat-list";import{defineTableCellSpec as wt,defineTableCommands as Tt,defineTableDropIndicator as Et,defineTableEditingPlugin as Dt,defineTableHeaderCellSpec as Ot,defineTableRowSpec as kt,defineTableSpec as At,deleteTable as jt,isCellSelection as Mt}from"@prosekit/extensions/table";import{closeHistory as Nt}from"@prosekit/pm/history";import{registerResizableHandleElement as Pt,registerResizableRootElement as Ft}from"@prosekit/web/resizable";import{InputRule as It}from"@prosekit/pm/inputrules";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 Lt(e){return D.getState(e)}function Rt(e){return new v({key:D,state:{init:()=>e,apply:(e,t)=>e.getMeta(D)??t},props:{attributes:t=>({"data-mark-mode":Lt(t)??e}),decorations:e=>{let t=Lt(e);if(t===`focus`)return Vt(e);if(t===`hide`)return Ht(e)}}})}function zt(e){return(t,n)=>O(t)===e?!1:(n?.(t.tr.setMeta(D,e)),!0)}function Bt(e){return g(m(Rt(e)),s({setMarkMode:zt}))}function O(e){return D.getState(e)}function Vt(e){return Ut(e,void 0)}function Ht(e){return Ut(e,{key:`math`})}function Ut(e,t){let{selection:n}=e;if(!n.empty)return x.empty;let r=n.$head,{parent:i}=r;if(!i.isTextblock||i.type.spec.code)return x.empty;let a=ee(r,te(e.schema,`mdPack`),t);return a?x.create(e.doc,[Oe.inline(a.from,a.to,{class:`show`})]):x.empty}const Wt=[`mdImage`,`mdWikilink`,`mdFile`];function k(e,t){let n=O(t);return n?e.flatMap(e=>e.modes.includes(n)?[e.name]:[]):[]}function Gt(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=Gt(e,t,n);return r&&r.to===t?r:void 0}function j(e,t,n){let r=Gt(e,t,n);return r&&r.from===t?r:void 0}function Kt(e,t){let{from:n,to:r,empty:i}=e.selection;if(i)return;let a=Gt(e,n,t);return a&&a.from===n&&a.to===r?a:void 0}function qt(e,t){return b.create(e.doc,t.from,t.to)}function Jt(e,t,n,r){let i=e.doc.resolve(t);if(!(r===-1?i.parentOffset===0:i.parentOffset===i.parent.content.size)||i.depth===0)return;let a=r===-1?j(e,t,n):A(e,t,n),o=r===-1?i.before():i.after(),s=De.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 Yt(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(qt(t,e))),!0;if(A(t,i.from,r)&&i.from<t.doc.resolve(i.from).end())return n?.(t.tr.setSelection(b.create(t.doc,i.from+1))),!0;let a=Jt(t,i.from,r,1);return a?(n?.(t.tr.setSelection(a).scrollIntoView()),!0):!1}let a=Kt(t,r);return a?(n?.(t.tr.setSelection(b.create(t.doc,a.to))),!0):!1}}function Xt(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(qt(t,e))),!0;let a=Jt(t,i.from,r,-1);return a?(n?.(t.tr.setSelection(a).scrollIntoView()),!0):!1}let a=Kt(t,r);return a?(n?.(t.tr.setSelection(b.create(t.doc,a.from))),!0):!1}}function Zt(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(b.create(n.doc,a,e)).scrollIntoView()),!0}let c=Jt(n,o,i,t);return!c||!h(c)?!1:(r?.(n.tr.setSelection(b.create(n.doc,a,c.head)).scrollIntoView()),!0)}}function Qt(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 $t(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 en=`md-atom-selected`;function tn(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=Kt(t,n);if(r)return x.create(t.doc,[Oe.inline(r.from,r.to,{class:en})]);let{from:i,to:a,empty:o}=t.selection;if(o)return null;let s=[];return t.doc.nodesBetween(i,a,(e,t)=>{e.marks.some(e=>n.includes(e.type.name))&&s.push(Oe.inline(t,t+e.nodeSize,{class:en}))}),x.create(t.doc,s)}}})}function nn({marks:e}){return g(_(l({ArrowRight:Yt(e),ArrowLeft:Xt(e),"Shift-ArrowRight":Zt(e,1),"Shift-ArrowLeft":Zt(e,-1),Backspace:Qt(e),Delete:$t(e)}),t.high),m(tn(e)))}const rn=(e,t)=>{let n={type:`highlight`,children:e.all(t)};return e.patch(t,n),n},an=(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 on(){return Ne().use(ke).use(Ae,{handlers:{mark:rn}}).use(je).use(Me,{bullet:`-`,emphasis:`*`,strong:`*`,fence:"`",fences:!0,rule:`-`,ruleRepetition:3,listItemIndent:`one`,handlers:{highlight:an}}).freeze()}const sn=ye(on);function cn(e){return String(sn().processSync(e))}function ln(e){if(e==null)return;let t=Number.parseInt(e,10);return Number.isSafeInteger(t)?t:void 0}function un(e){let t=ln(e);return t!=null&&t>0?t:void 0}const dn=new Set([`mdMark`,`mdLinkUri`,`mdLinkTitle`]),fn=new Set([`mdImage`,`mdWikilink`,`mdMath`,`mdFile`]),pn={mdStrong:`strong`,mdEm:`em`,mdCode:`code`,mdDel:`del`,mdHighlight:`mark`,mdLinkText:`a`};function mn(e){return e.find(e=>fn.has(e.type.name))}function hn(e){return e.some(e=>dn.has(e.type.name))}function gn(e){let t=[];return e.forEach(e=>{if(!e.isText||!e.text)return;let n=mn(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 _n(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 yn(t,r),r}function vn(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 yn(e,t){let n=[];for(let r of gn(e)){if(r.atom!=null){n.length=0,t.append(Sn(r.atom,r.text));continue}for(let e of r.children)hn(e.marks)||(bn(n,e.marks.filter(e=>pn[e.type.name]),t),xn(n.at(-1)?.element??t,e.text??``))}}function bn(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(pn[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 xn(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 Sn(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 Cn(){return p({name:`heading`,whitespace:`pre`})}function wn(e){let t=e.attrs;return _n(`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 Tn(){return[1,2,3,4,5,6].map(e=>vn(`h${e}`,`heading`,t=>({level:e,setextUnderline:un(t.getAttribute(`data-setext-underline`))??null,closingHashes:un(t.getAttribute(`data-closing-hashes`))??null})))}function En(){return f({type:`heading`,attr:`setextUnderline`,default:null,toDOM:e=>e==null?null:[`data-setext-underline`,String(e)],parseDOM:e=>un(e.getAttribute(`data-setext-underline`))??null})}function Dn(){return f({type:`heading`,attr:`closingHashes`,default:null,toDOM:e=>e==null?null:[`data-closing-hashes`,String(e)],parseDOM:e=>un(e.getAttribute(`data-closing-hashes`))??null})}function M(e){return ue(se({type:`heading`,attrs:{level:e}}))}const On=(e,t,n)=>ae(e,n)?.parent.type.name===`heading`&&ce()(e,t,n);function kn(){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:On})}function An(){return g(Re(),Cn(),En(),Dn(),Le(),Ie(),kn())}function jn(){return p({name:`paragraph`,content:`inline*`,group:`block`,whitespace:`pre`,parseDOM:[{tag:`p`}],toDOM(){return[`p`,0]}})}function Mn(e){return _n(`p`,e)}function Nn(){return[vn(`p`,`paragraph`)]}function Pn(){return g(_(jn(),t.highest),ze(),Be())}function Fn(e){return{...e,paragraph:e=>({dom:Mn(e)}),heading:e=>({dom:wn(e)})}}function In(){return o({serializeFragmentWrapper:e=>(...t)=>{let n=e(...t);for(let e of n.children)e.setAttribute(`data-meowdown`,``);return n},nodesFromSchemaWrapper:e=>(...t)=>Fn(e(...t))})}const Ln=new WeakMap;function Rn(e){let t=Ln.get(e);return t??(t=new S(Fn(S.nodesFromSchema(e)),S.marksFromSchema(e)),Ln.set(e,t)),t}const zn=new y(`meowdown-html-paste`);function Bn(e){return e.includes(`data-meowdown`)?!0:e.includes(`data-pm-slice`)&&e.includes(`md-mark`)}function Vn(){return m(new v({key:zn,props:{transformPastedHTML:(e,t)=>{if(Bn(e))return e;let n=t.state.selection.$from.parent;if(!n.inlineContent||n.type.spec.code)return e;let r=cn(e);if(!r.trim())return e;let i=X(r,{nodes:nc(t.state.schema)}),a=Rn(t.state.schema),o=document.createElement(`div`);return o.append(a.serializeFragment(i.content)),o.innerHTML}}}))}function Hn(e){return new Pe(e,[...Nn(),...Tn(),...Pe.fromSchema(e).rules])}const Un=new y(`meowdown-clipboard-parser`);function Wn(){return m(({schema:e})=>new v({key:Un,props:{clipboardParser:Hn(e)}}))}function Gn(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 Kn(e,t,n){let r=n.marks(),i=S.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 Pe.fromSchema(e).parseSlice(a,{preserveWhitespace:!0,context:n})}function qn(){return m(new v({key:new y(`meowdown-plain-paste`),props:{clipboardTextParser:(e,t,n,r)=>{let{schema:i}=r.state;return n?Kn(i,e,t):Gn(i,e)}}}))}function N(e){return e===32||e===9||e===10||e===13}function Jn(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 Yn(e,t=0){return Jn(e,96,t)}function P(e,t={}){let n=new $n;return t.frontmatter&&Xn(e.attrs.frontmatter,n),er(e,n),n.finish()}function Xn(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 h,getMarkType as ee,getNodeType as te,isAllSelection as ne,isApple as re,isAtBlockStart as ie,isNodeSelection as ae,isTextSelection as g,toggleNode as oe,union as _,unsetBlockType as se,withPriority as ce,withPriority as v,withSkipCodeBlock as le}from"@prosekit/core";import{defineCodeBlock as ue,defineCodeBlockHighlight as de,defineCodeBlockPreviewPlugin as fe,isCodeBlockPreviewHiddenDecoration as pe}from"@prosekit/extensions/code-block";import{definePlaceholder as me}from"@prosekit/extensions/placeholder";import{defineReadonly as he}from"@prosekit/extensions/readonly";import{isElementLike as ge,isHTMLElement as _e,once as ve}from"@ocavue/utils";import{defineBlockquote as ye}from"@prosekit/extensions/blockquote";import{defineDoc as be}from"@prosekit/extensions/doc";import{defineGapCursor as xe}from"@prosekit/extensions/gap-cursor";import{defineModClickPrevention as Se}from"@prosekit/extensions/mod-click-prevention";import{defineText as Ce}from"@prosekit/extensions/text";import{defineVirtualSelection as we}from"@prosekit/extensions/virtual-selection";import{NodeSelection as Te,Plugin as y,PluginKey as b,Selection as Ee,TextSelection as x}from"@prosekit/pm/state";import{Decoration as De,DecorationSet as S}from"@prosekit/pm/view";import 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 C,Fragment as w,Mark as Pe,Slice as T}from"@prosekit/pm/model";import{defineHeadingCommands as Fe,defineHeadingInputRule as Ie,defineHeadingSpec as Le}from"@prosekit/extensions/heading";import{defineParagraphCommands as Re,defineParagraphKeymap as ze}from"@prosekit/extensions/paragraph";import{LanguageDescription as Be}from"@codemirror/language";import{languages as Ve}from"@codemirror/language-data";import{classHighlighter as He,highlightTree as Ue}from"@lezer/highlight";import{createParser as We}from"prosemirror-highlight/lezer";import{defineEnterRule as Ge,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 E}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";import{InputRule as Ft}from"@prosekit/pm/inputrules";function D(e,t,n,r){let i=e.doc.content.size;if(t<0||t>i)return;let a=e.doc.resolve(t);if(!(!a.parent.isTextblock||a.parent.type.spec.code))return h(a,n,r)}const O=new b(`mark-mode`);function It(e){return O.getState(e)}function Lt(e){return new y({key:O,state:{init:()=>e,apply:(e,t)=>e.getMeta(O)??t},props:{attributes:t=>({"data-mark-mode":It(t)??e}),decorations:e=>{let t=It(e);if(t===`focus`)return Bt(e);if(t===`hide`)return Vt(e)}}})}function Rt(e){return(t,n)=>k(t)===e?!1:(n?.(t.tr.setMeta(O,e)),!0)}function zt(e){return _(m(Lt(e)),s({setMarkMode:Rt}))}function k(e){return O.getState(e)}function Bt(e){return Ht(e,void 0)}function Vt(e){return Ht(e,{key:`math`})}function Ht(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=h(r,ee(e.schema,`mdPack`),t);return a?S.create(e.doc,[De.inline(a.from,a.to,{class:`show`})]):S.empty}const Ut=[`mdImage`,`mdWikilink`,`mdFile`];function A(e,t){let n=k(t);return n?e.flatMap(e=>e.modes.includes(n)?[e.name]:[]):[]}function Wt(e,t,n){for(let r of n){let n=D(e,t,r);if(n)return n}}function j(e,t,n){let r=Wt(e,t,n);return r&&r.to===t?r:void 0}function M(e,t,n){let r=Wt(e,t,n);return r&&r.from===t?r:void 0}function Gt(e,t){let{from:n,to:r,empty:i}=e.selection;if(i)return;let a=Wt(e,n,t);return a&&a.from===n&&a.to===r?a:void 0}function Kt(e,t){return x.create(e.doc,t.from,t.to)}function qt(e,t,n,r){let i=e.doc.resolve(t);if(!(r===-1?i.parentOffset===0:i.parentOffset===i.parent.content.size)||i.depth===0)return;let a=r===-1?M(e,t,n):j(e,t,n),o=r===-1?i.before():i.after(),s=Ee.findFrom(e.doc.resolve(o),r);if(!s)return;let c=g(s)?r===-1?j(e,s.head,n):M(e,s.head,n):void 0;if(!(a==null&&c==null))return s}function Jt(e){return(t,n)=>{let r=A(e,t);if(r.length===0||!g(t.selection))return!1;let i=t.selection;if(i.empty){let e=M(t,i.from,r);if(e)return n?.(t.tr.setSelection(Kt(t,e))),!0;if(j(t,i.from,r)&&i.from<t.doc.resolve(i.from).end())return n?.(t.tr.setSelection(x.create(t.doc,i.from+1))),!0;let a=qt(t,i.from,r,1);return a?(n?.(t.tr.setSelection(a).scrollIntoView()),!0):!1}let a=Gt(t,r);return a?(n?.(t.tr.setSelection(x.create(t.doc,a.to))),!0):!1}}function Yt(e){return(t,n)=>{let r=A(e,t);if(r.length===0||!g(t.selection))return!1;let i=t.selection;if(i.empty){let e=j(t,i.from,r);if(e)return n?.(t.tr.setSelection(Kt(t,e))),!0;let a=qt(t,i.from,r,-1);return a?(n?.(t.tr.setSelection(a).scrollIntoView()),!0):!1}let a=Gt(t,r);return a?(n?.(t.tr.setSelection(x.create(t.doc,a.from))),!0):!1}}function Xt(e,t){return(n,r)=>{let i=A(e,n);if(i.length===0||!g(n.selection))return!1;let{anchor:a,head:o}=n.selection,s=t===-1?j(n,o,i):M(n,o,i);if(s){let e=t===-1?s.from:s.to;return r?.(n.tr.setSelection(x.create(n.doc,a,e)).scrollIntoView()),!0}let c=qt(n,o,i,t);return!c||!g(c)?!1:(r?.(n.tr.setSelection(x.create(n.doc,a,c.head)).scrollIntoView()),!0)}}function Zt(e){return(t,n)=>{let r=A(e,t);if(r.length===0||!t.selection.empty)return!1;let i=t.selection.from,a=j(t,i,r);return a?(n?.(t.tr.delete(a.from,a.to)),!0):!M(t,i,r)||i<=t.doc.resolve(i).start()?!1:(n?.(t.tr.delete(i-1,i)),!0)}}function Qt(e){return(t,n)=>{let r=A(e,t);if(r.length===0||!t.selection.empty)return!1;let i=t.selection.from,a=M(t,i,r);return a?(n?.(t.tr.delete(a.from,a.to)),!0):!j(t,i,r)||i>=t.doc.resolve(i).end()?!1:(n?.(t.tr.delete(i,i+1)),!0)}}const $t=`md-atom-selected`;function en(e){return new y({key:new b(`atom-mark-selection`),props:{decorations:t=>{let n=A(e,t);if(n.length===0||ae(t.selection))return;let r=Gt(t,n);if(r)return S.create(t.doc,[De.inline(r.from,r.to,{class:$t})]);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:$t}))}),S.create(t.doc,s)}}})}function tn({marks:e}){return _(v(l({ArrowRight:Jt(e),ArrowLeft:Yt(e),"Shift-ArrowRight":Xt(e,1),"Shift-ArrowLeft":Xt(e,-1),Backspace:Zt(e),Delete:Qt(e)}),t.high),m(en(e)))}const nn=(e,t)=>{let n={type:`highlight`,children:e.all(t)};return e.patch(t,n),n},rn=(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 an(){return Me().use(Oe).use(ke,{handlers:{mark:nn}}).use(Ae).use(je,{bullet:`-`,emphasis:`*`,strong:`*`,fence:"`",fences:!0,rule:`-`,ruleRepetition:3,listItemIndent:`one`,handlers:{highlight:rn}}).freeze()}const on=ve(an);function sn(e){return String(on().processSync(e))}function cn(e){if(e==null)return;let t=Number.parseInt(e,10);return Number.isSafeInteger(t)?t:void 0}function ln(e){let t=cn(e);return t!=null&&t>0?t:void 0}const un=new Set([`mdMark`,`mdLinkUri`,`mdLinkTitle`]),dn=new Set([`mdImage`,`mdWikilink`,`mdMath`,`mdFile`]),fn={mdStrong:`strong`,mdEm:`em`,mdCode:`code`,mdDel:`del`,mdHighlight:`mark`,mdLinkText:`a`};function pn(e){return e.find(e=>dn.has(e.type.name))}function mn(e){return e.some(e=>un.has(e.type.name))}function hn(e){let t=[];return e.forEach(e=>{if(!e.isText||!e.text)return;let n=pn(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 gn(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 vn(t,r),r}function _n(e,t,n){return{tag:`${e}[data-md]`,node:t,priority:100,getAttrs:n,getContent:(e,t)=>{let n=(_e(e)?e:void 0)?.getAttribute(`data-md`)??``;return n?w.from(t.text(n)):w.empty}}}function vn(e,t){let n=[];for(let r of hn(e)){if(r.atom!=null){n.length=0,t.append(xn(r.atom,r.text));continue}for(let e of r.children)mn(e.marks)||(yn(n,e.marks.filter(e=>fn[e.type.name]),t),bn(n.at(-1)?.element??t,e.text??``))}}function yn(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(fn[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 bn(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 xn(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 Sn(){return p({name:`heading`,whitespace:`pre`})}function Cn(e){let t=e.attrs;return gn(`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 wn(){return[1,2,3,4,5,6].map(e=>_n(`h${e}`,`heading`,t=>({level:e,setextUnderline:ln(t.getAttribute(`data-setext-underline`))??null,closingHashes:ln(t.getAttribute(`data-closing-hashes`))??null})))}function Tn(){return f({type:`heading`,attr:`setextUnderline`,default:null,toDOM:e=>e==null?null:[`data-setext-underline`,String(e)],parseDOM:e=>ln(e.getAttribute(`data-setext-underline`))??null})}function En(){return f({type:`heading`,attr:`closingHashes`,default:null,toDOM:e=>e==null?null:[`data-closing-hashes`,String(e)],parseDOM:e=>ln(e.getAttribute(`data-closing-hashes`))??null})}function N(e){return le(oe({type:`heading`,attrs:{level:e}}))}const Dn=(e,t,n)=>ie(e,n)?.parent.type.name===`heading`&&se()(e,t,n);function On(){return l({"Mod-1":N(1),"Mod-2":N(2),"Mod-3":N(3),"Mod-4":N(4),"Mod-5":N(5),"Mod-6":N(6),Backspace:Dn})}function kn(){return _(Le(),Sn(),Tn(),En(),Ie(),Fe(),On())}function An(){return p({name:`paragraph`,content:`inline*`,group:`block`,whitespace:`pre`,parseDOM:[{tag:`p`}],toDOM(){return[`p`,0]}})}function jn(e){return gn(`p`,e)}function Mn(){return[_n(`p`,`paragraph`)]}function Nn(){return _(v(An(),t.highest),Re(),ze())}function Pn(e){return{...e,paragraph:e=>({dom:jn(e)}),heading:e=>({dom:Cn(e)})}}function Fn(){return o({serializeFragmentWrapper:e=>(...t)=>{let n=e(...t);for(let e of n.children)e.setAttribute(`data-meowdown`,``);return n},nodesFromSchemaWrapper:e=>(...t)=>Pn(e(...t))})}const In=new WeakMap;function Ln(e){let t=In.get(e);return t??(t=new C(Pn(C.nodesFromSchema(e)),C.marksFromSchema(e)),In.set(e,t)),t}const Rn=new b(`meowdown-html-paste`);function zn(e){return e.includes(`data-meowdown`)?!0:e.includes(`data-pm-slice`)&&e.includes(`md-mark`)}function Bn(){return m(new y({key:Rn,props:{transformPastedHTML:(e,t)=>{if(zn(e))return e;let n=t.state.selection.$from.parent;if(!n.inlineContent||n.type.spec.code)return e;let r=sn(e);if(!r.trim())return e;let i=X(r,{nodes:lc(t.state.schema)}),a=Ln(t.state.schema),o=document.createElement(`div`);return o.append(a.serializeFragment(i.content)),o.innerHTML}}}))}function Vn(e){return new Ne(e,[...Mn(),...wn(),...Ne.fromSchema(e).rules])}const Hn=new b(`meowdown-clipboard-parser`);function Un(){return m(({schema:e})=>new y({key:Hn,props:{clipboardParser:Vn(e)}}))}function Wn(e,t){let n=t.replaceAll(/\r\n?/g,`
3
+ `).replace(/^\n+/,``).replace(/\n+$/,``);if(!n)return T.empty;let r=te(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 T.maxOpen(w.from(i))}function Gn(e,t,n){let r=n.marks(),i=C.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 Kn(){return m(new y({key:new b(`meowdown-plain-paste`),props:{clipboardTextParser:(e,t,n,r)=>{let{schema:i}=r.state;return n?Gn(i,e,t):Wn(i,e)}}}))}function P(e){return e===32||e===9||e===10||e===13}function qn(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 Jn(e,t=0){return qn(e,96,t)}function F(e,t={}){let n=new Qn;return t.frontmatter&&Yn(e.attrs.frontmatter,n),$n(e,n),n.finish()}function Yn(e,t){e!==null&&(t.write(`---`),t.write(`
4
4
  `),e!==``&&(t.write(e),t.write(`
5
- `)),t.write(`---`),t.closeBlock())}const Zn=[``,`# `,`## `,`### `,`#### `,`##### `,`###### `];function Qn(e,t){let n=e.attrs,r=n.setextUnderline;if(r!=null&&e.content.size>0&&n.level<=2){ir(e,t);let i=n.level===1?`=`:`-`;t.write(`
6
- `+i.repeat(Math.max(1,r))),t.closeBlock();return}t.write(Zn[n.level]??`# `),ir(e,t);let i=n.closingHashes;i!=null&&i>0&&t.write(` `+`#`.repeat(i)),t.closeBlock()}var $n=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 Xn=[``,`# `,`## `,`### `,`#### `,`##### `,`###### `];function Zn(e,t){let n=e.attrs,r=n.setextUnderline;if(r!=null&&e.content.size>0&&n.level<=2){rr(e,t);let i=n.level===1?`=`:`-`;t.write(`
6
+ `+i.repeat(Math.max(1,r))),t.closeBlock();return}t.write(Xn[n.level]??`# `),rr(e,t);let i=n.closingHashes;i!=null&&i>0&&t.write(` `+`#`.repeat(i)),t.closeBlock()}var Qn=class{constructor(){this.parts=[],this.linePrefix=``,this.pendingFirst=null,this.atLineStart=!0,this.deferredBlankPrefix=null}write(e){if(e===``)return;if(this.emitDeferredBlankLine(),this.atLineStart&&=(this.parts.push(this.pendingFirst??this.linePrefix),this.pendingFirst=null,!1),!e.includes(`
7
7
  `)){this.parts.push(e);return}let t=e.split(`
8
8
  `);for(let e=0;e<t.length;e++)e>0&&this.parts.push(`
9
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(`
10
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+$/,``)+`
11
11
  `}emitDeferredBlankLine(){let e=this.deferredBlankPrefix;e!==null&&(this.parts.push(e.trimEnd(),`
12
- `),this.deferredBlankPrefix=null)}};function er(e,t){switch(e.type.name){case`doc`:tr(e,t);return;case`paragraph`:if(e.childCount===0){t.closeEmptyBlock();return}ir(e,t),t.closeBlock();return;case`heading`:Qn(e,t);return;case`blockquote`:t.withPrefix(`> `,`> `,()=>tr(e,t)),t.closeBlock();return;case`list`:ar(e,t,rr(e));return;case`codeBlock`:or(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`:lr(e,t);return;case`text`:e.text&&t.write(e.text);return}}function tr(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(),er(a,t),i++;continue}let o=i+1;for(;o<r&&e.child(o).type.name===`list`;)o++;let s=nr(e,i,o);for(let r=i;r<o;r++)(r===i?n&&i>0:s)&&t.suppressBlank(),ar(e.child(r),t,s);i=o}}function nr(e,t,n){for(let r=t;r<n;r++)if(!rr(e.child(r)))return!1;return!0}function rr(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 ir(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 ar(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,()=>tr(e,t,n)),t.closeBlock()}function or(e,t){let n=e.attrs,r=n.language||``,i=e.textContent;if(n.fenceStyle===`indented`&&!r){let e=sr(i);if(e!=null){t.write(e),t.closeBlock();return}}if(n.fenceStyle===`dollar`&&r===`math`&&!cr(i)){t.write(`$$`),t.write(`
12
+ `),this.deferredBlankPrefix=null)}};function $n(e,t){switch(e.type.name){case`doc`:er(e,t);return;case`paragraph`:if(e.childCount===0){t.closeEmptyBlock();return}rr(e,t),t.closeBlock();return;case`heading`:Zn(e,t);return;case`blockquote`:t.withPrefix(`> `,`> `,()=>er(e,t)),t.closeBlock();return;case`list`:ir(e,t,nr(e));return;case`codeBlock`:ar(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`:cr(e,t);return;case`text`:e.text&&t.write(e.text);return}}function er(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(),$n(a,t),i++;continue}let o=i+1;for(;o<r&&e.child(o).type.name===`list`;)o++;let s=tr(e,i,o);for(let r=i;r<o;r++)(r===i?n&&i>0:s)&&t.suppressBlank(),ir(e.child(r),t,s);i=o}}function tr(e,t,n){for(let r=t;r<n;r++)if(!nr(e.child(r)))return!1;return!0}function nr(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 rr(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 ir(e,t,n){let{kind:r,marker:i,order:a,taskMarker:o,collapsed:s,markerGap:c,checked:l}=e.attrs,u=r===`task`?i===`+`?`+`:i===`*`?`*`:`-`:s?`+`:i===`*`?`*`:`-`,d=i===`)`?`)`:`.`,f=o===`X`?`X`:`x`,p=Math.min(Math.max(c??1,1),4),m=`${r===`ordered`?`${a??1}${d}`:u}${` `.repeat(p)}`,h=r===`task`?`${m}[${l?f:` `}] `:m,ee=` `.repeat(m.length);t.withPrefix(ee,h,()=>er(e,t,n)),t.closeBlock()}function ar(e,t){let n=e.attrs,r=n.language||``,i=e.textContent;if(n.fenceStyle===`indented`&&!r){let e=or(i);if(e!=null){t.write(e),t.closeBlock();return}}if(n.fenceStyle===`dollar`&&r===`math`&&!sr(i)){t.write(`$$`),t.write(`
13
13
  `),i&&(t.write(i),t.write(`
14
- `)),t.write(`$$`),t.closeBlock();return}let a=n.fenceStyle===`tilde`,o=Jn(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=qn(i,a?126:96,2)+1,s=(a?`~`:"`").repeat(Math.max(n.fenceLength??0,o));t.write(s),r&&t.write(r),t.write(`
15
15
  `),i&&(t.write(i),t.write(`
16
- `)),t.write(s),t.closeBlock()}function sr(e){if(e===``)return;let t=e.split(`
16
+ `)),t.write(s),t.closeBlock()}function or(e){if(e===``)return;let t=e.split(`
17
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(`
18
- `)}}function cr(e){return e.split(`
19
- `).some(e=>e.trim()===`$$`)}function lr(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(fr(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(ur(n))}let c=`| `+s.join(` | `)+` |`,l=a>=0?r[a]:Array(i).fill(``);t.write(dr(l,i)),t.write(`
18
+ `)}}function sr(e){return e.split(`
19
+ `).some(e=>e.trim()===`$$`)}function cr(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(dr(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(lr(n))}let c=`| `+s.join(` | `)+` |`,l=a>=0?r[a]:Array(i).fill(``);t.write(ur(l,i)),t.write(`
20
20
  `),t.write(c);for(let e=0;e<n;e++)e!==a&&(t.write(`
21
- `),t.write(dr(r[e],i)));t.closeBlock()}function ur(e){switch(e){case`left`:return`:--`;case`center`:return`:-:`;case`right`:return`--:`;default:return`---`}}function dr(e,t){let n=`|`;for(let r=0;r<t;r++)n+=` `+(e[r]??``)+` |`;return n}function fr(e){let t=e.textContent.trim();return!t.includes(`|`)&&!t.includes(`
21
+ `),t.write(ur(r[e],i)));t.closeBlock()}function lr(e){switch(e){case`left`:return`:--`;case`center`:return`:-:`;case`right`:return`--:`;default:return`---`}}function ur(e,t){let n=`|`;for(let r=0;r<t;r++)n+=` `+(e[r]??``)+` |`;return n}function dr(e){let t=e.textContent.trim();return!t.includes(`|`)&&!t.includes(`
22
22
  `)?t:t.replaceAll(`|`,String.raw`\|`).replaceAll(`
23
- `,` `)}function pr(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,`
23
+ `,` `)}function fr(e,t){let n=t.content,r;try{r=e.topNodeType.createAndFill(void 0,n)??void 0}catch{r=void 0}return r?F(r).replace(/\n+$/,``):n.textBetween(0,n.size,`
24
24
  `,`
25
- `)}function mr(){return m(new v({key:new y(`meowdown-plain-text-copy`),props:{clipboardTextSerializer:(e,t)=>{let n=O(t.state)===`hide`?hr(e):e;return pr(t.state.schema,n)}}}))}function hr(e){return new w(gr(e.content),e.openStart,e.openEnd)}function gr(e){let t=[];return e.forEach(e=>{t.push(e.isTextblock?vr(e):_r(e))}),C.from(t)}function _r(e){return e.childCount>0?e.copy(gr(e.content)):e}function vr(e){let t=e.type.schema,n=[];for(let r of gn(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)hn(e.marks)||n.push(e)}return e.copy(C.from(n))}function yr(){return g(In(),mr(),Wn(),Vn(),qn())}const F=new Map,br=new Map,xr={math:`latex`};async function Sr(e){let t=F.get(e);if(t!==void 0)return t;let n=Ve.matchLanguageName(He,xr[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 Cr(e,t){let n=br.get(e);if(n)return n;let r=Ge({parse:e=>t.language.parser.parse(e.content),highlighter:Ue});return br.set(e,r),r}const wr=e=>{let t=e.language?.trim();if(!t)return[];let n=F.get(t);return n===null?[]:n?Cr(t,n)(e):Sr(t).then(()=>void 0)};function Tr(){return fe({parser:wr,nodeTypes:[`codeBlock`]})}function Er(e,t){let n=t.language.parser.parse(e),r=[];return We(n,Ue,(e,t,n)=>{r.push([e,t,n])}),r}function Dr(e,t){let n=t.trim();if(!n)return[];let r=F.get(n);return r===null?[]:r?Er(e,r):Sr(n).then(t=>t?Er(e,t):[])}function Or(){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 kr(){return f({type:`codeBlock`,attr:`fenceLength`,default:null,toDOM:e=>e==null?null:[`data-fence-length`,String(e)],parseDOM:e=>{let t=ln(e.getAttribute(`data-fence-length`));return t!=null&&t>3?t:null}})}function Ar(e){return{language:e[1]||``,fenceStyle:`tilde`}}function jr(){return Ye({regex:/^~~~(\S*)\s$/,type:`codeBlock`,attrs:Ar})}function Mr(){return qe({regex:/^~~~(\S*)$/,type:`codeBlock`,attrs:Ar})}function Nr(){return qe({regex:/^\$\$$/,type:`codeBlock`,attrs:()=>({language:`math`,fenceStyle:`dollar`})})}function Pr(){return g(de(),Or(),kr(),jr(),Mr(),Nr())}function Fr(e,t){return(n,r)=>{if(r){let i=b.create(n.doc,e,t);r(n.tr.setSelection(i))}return!0}}function Ir(e,t,n){return(r,i)=>{if(i){let a=b.between(e,t,n);i(r.tr.setSelection(a))}return!0}}function Lr(e){return(t,n)=>{if(!e.trim())return!1;let r=X(e,{nodes:nc(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(b.near(r.$from)),n(e.replaceSelection(i).scrollIntoView())}return!0}}function Rr(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);Xe(s),n(s.scrollIntoView())}return!0}}function zr(){return(e,t)=>(t&&t(e.tr.scrollIntoView()),!0)}function Br(){return s({insertMarkdown:Lr,insertTrigger:Rr,scrollIntoView:zr,selectText:Fr,selectTextBetween:Ir})}const Vr=(e,t,n)=>{let{selection:r}=e;return r.empty||n?.composing?!1:(t?.(e.tr.setSelection(b.near(r.$head))),!0)};function Hr(){return _(l({Escape:Vr}),t.low)}function Ur(){return f({type:`doc`,attr:`frontmatter`,default:null})}function Wr(e,t){return t(e.state,e.dispatch,e)}const Gr=new Set([`mdMark`,`mdLinkUri`,`mdLinkTitle`]);function Kr(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=Kr(e,t);return n!=null&&n.some(e=>Gr.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 qr(e,t){return I(e,t-1)&&I(e,t)}function Jr(e,t){if(!qr(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 Yr(e,t,n){let r=Kr(e,t);return r!=null&&n.isInSet(r)}function Xr(e,t){let n=Kr(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&&Yr(e,r-1,n);)r--;let i=t+1;for(;i<s&&Yr(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=Xr(e,n===`from`?t.from:t.to-1);return r==null?!1:n===`from`?r.from===t.from:r.to===t.to}function Zr(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 Qr(e,t,n,r){if(!L(e,n))return n;let i=Jr(e,n);if(i!=null)return r?Zr(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 $r(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 ei(e,t){let n=Xr(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 ti=new y(`meowdown-hidden-run-snap`),ni=new y(`meowdown-hidden-run-beforeinput`);function ri(){let e=!1;return new v({key:ti,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=Qr(r,n.selection.head,i.head,a);return e===i.head?null:r.tr.setSelection(b.create(r.doc,e))}let o=Jr(r,i.from)?.from??i.from,s=Jr(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(b.create(r.doc,c,l))}})}const ii=(e,t)=>{if(O(e)!==`hide`)return!1;let n=e.selection;if(!h(n)||!n.empty)return!1;let r=Qr(e,n.head,n.head,!0);return r===n.head||t?.(e.tr.setSelection(b.create(e.doc,r))),!1};function ai(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=ei(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 oi=ai(-1),si=ai(1);function ci(){return new v({key:ni,props:{handleDOMEvents:{beforeinput:(e,t)=>{if(e.composing)return!1;let n=t.inputType===`deleteContentBackward`?oi:t.inputType===`deleteContentForward`?si:void 0;return n==null||!Wr(e,n)?!1:(t.preventDefault(),!0)}}}})}function li(){return g(m(ri()),m(ci()),_(l({Enter:ii,Backspace:oi,Delete:si}),t.highest))}function ui(){return f({type:`horizontalRule`,attr:`marker`,default:null,toDOM:e=>e?[`data-hr-marker`,e]:null,parseDOM:e=>e.getAttribute(`data-hr-marker`)})}function di(){return g(Ze(),ui())}function fi(){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 pi(e){let[t,n,r]=e;return[t,n,r.map(e=>e.toJSON())]}function mi(e,t){let[n,r,i]=t;return[n,r,i.map(t=>Fe.fromJSON(e,t))]}function hi(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 gi=class e extends rt{constructor(e){super(),this.chunks=e}apply(e){if(this.chunks.length===0)return it.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(hi(l,c))return!1;n??=new at(e);for(let e of l)n.removeMark(i,a,e);for(let e of c)n.addMark(i,a,e);return!1})}return it.ok(n?n.doc:e)}invert(e){if(this.chunks.length===0)return _i;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 nt(i,a,e.slice(i,a),!1)}map(e){return null}toJSON(){return{stepType:`batchSetMark`,chunks:this.chunks.map(pi)}}static fromJSON(t,n){let r=n.chunks;return new e(r.map(e=>mi(t,e)))}};rt.jsonID(`batchSetMark`,gi);const _i=new gi([]),vi=new Set([`com`,`br`,`net`,`jp`,`org`,`in`,`de`,`ru`,`it`,`fr`]),yi=/^[a-z0-9](?:[a-z0-9-]*[a-z0-9])?$/i;function bi(e){let t=e.indexOf(`/`);return t===-1?e:e.slice(0,t)}function xi(e){let t=e.split(`.`);if(t.length<2)return!1;let n=t[t.length-1].toLowerCase();if(!vi.has(n)||t[t.length-2].length<3)return!1;for(let e of t)if(e.length>63||!yi.test(e))return!1;return!0}function Si(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)||xi(bi(e)))return`https://${e}`}const Ci=/^[a-z0-9-]+(?:\.[a-z0-9-]+)+(?:\/[^\s<]*)?/i,wi=/[\s(*_~]/;function Ti(e){return e>=48&&e<=57||e>=65&&e<=90||e>=97&&e<=122||e===45}function Ei(e,t,n){let r=0;for(let i=0;i<t;i++)e[i]===n&&r++;return r}function Di(e){let t=e.length;for(;;){let n=e[t-1];if(/[?!.,:*_~]/.test(n)||n===`)`&&Ei(e,t,`)`)>Ei(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 Oi={parseInline:[{name:`BareAutolink`,before:`Link`,parse(e,t,n){if(!Ti(t)||e.hasOpenLink)return-1;let r=e.slice(n-1,n);if(r!==``&&!wi.test(r))return-1;let i=Ci.exec(e.slice(n,e.end));if(!i)return-1;let a=Di(i[0]);return a===0||!xi(bi(i[0].slice(0,a)))?-1:e.addElement(e.elt(`URL`,n,n+a))}}]};function ki(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 Ai(e){return e>=65&&e<=90||e>=97&&e<=122||e>127&&/\p{L}/u.test(String.fromCharCode(e))}const ji={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(!ki(t))break;i||=Ai(t),r++}return i?e.addElement(e.elt(`Hashtag`,n,r)):-1}}]},Mi={resolve:`Highlight`,mark:`HighlightMark`},Ni=/[!"#$%&'()*+,\-./:;<=>?@[\\\]^_`{|}~\u{A1}\u{2010}-\u{2027}]/u,Pi={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=Ni.test(r),c=Ni.test(i);return e.addDelimiter(Mi,n,n+2,!o&&(!c||a||s),!a&&(!s||o||c))}}]};function Fi(e){return e>=48&&e<=57}function Ii(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 Li(e){let t=e.depth;return typeof t==`number`?t:2**53-1}const Ri={defineNodes:[{name:`InlineMath`},{name:`InlineMathMark`},{name:`BlockMath`,block:!0},{name:`BlockMathMark`}],parseBlock:[{name:`BlockMath`,before:`FencedCode`,parse(e,t){if(!Ii(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()||Li(t)<e.depth);n=!1){if(Ii(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 Ii(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))||Fi(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}}]},zi=/^[a-z][a-z0-9+.-]*:\/\/[^\s<]+/i;function Bi(e){return e>=65&&e<=90||e>=97&&e<=122}const Vi={parseInline:[{name:`SchemeAutolink`,after:`Autolink`,parse(e,t,n){if(!Bi(t)||e.hasOpenLink)return-1;let r=e.slice(n-1,n);if(r!==``&&!wi.test(r))return-1;let i=zi.exec(e.slice(n,e.end));if(!i)return-1;let a=Di(i[0]);return a<=i[0].indexOf(`://`)+3?-1:e.addElement(e.elt(`URL`,n,n+a))}}]},Hi={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 Ui(e){return e.end}const Wi=st.configure([ot,ji,Hi,Oi,Vi,Pi,Ri]),Gi=Wi.configure({parseInline:[{name:`SkipInline`,before:`Escape`,parse:Ui}]});function Ki(e){return Wi.parseInline(e,0)}function qi(e,t,n=[]){for(let r of e)t(r)&&n.push(r),qi(r.children,t,n);return n}function Ji(e){let t={};for(let n of e.nodeSet.types)t[n.name]=n.id;return t}const V=Ji(Wi),Yi=/^<!--\s*(\{[^}]*\})\s*-->$/,Xi=/<!--\s*\{[^}]*\}\s*-->$/;function Zi(e){let t=Yi.exec(e.trim());if(!t)return;let n;try{n=JSON.parse(t[1])}catch{return}if(typeof n!=`object`||!n)return;let r=Qi(n);return Object.keys(r).length>0?r:void 0}function Qi(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 $i(e){return`<!-- ${JSON.stringify(e)} -->`}function ea(e){return e.replace(Xi,``)}function ta(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 na(){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 ra(){return d({name:`mdWikilink`,constructor:na()})}const ia=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 aa(e,t,n){let r=Ki(t),i=[];return sa(r,[],0,t.length,t,e,i,n),i}function oa(e){return e.slice(1,-1).replaceAll(/\\(.)/g,`$1`)}function sa(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=ua(r,t,i,a,s);e?H(o,r.from,r.to,e):da(r,t,i,a,o)}else if(l===V.Image){let s=fa(r,e[n+1],i);pa(r,t,i,a,o,s),s&&n++,c=s?s.to:r.to;continue}else if(l===V.Wikilink)ha(r,t,i,a,o);else if(l===V.InlineMath)ma(r,t,i,a,o);else if(l===V.URL){let e=Si(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=ia.get(l),u=c?[...n,a[c].create()]:n;r.children.length===0?H(o,r.from,r.to,u):sa(r.children,u,r.from,r.to,i,a,o,s)}c=r.to}c<r&&H(o,c,r,t)}function ca(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 la(e){let t=e.split(/[?#]/,1)[0],n=t.split(/[/\\]/).findLast(Boolean)??t;try{return decodeURIComponent(n)}catch{return n}}function ua(e,t,n,r,i){let a=i?.resolveFileLink;if(!a)return;let{labelFrom:o,labelTo:s,urlNode:c,titleNode:l}=ca(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?oa(n.slice(l.from,l.to)):``;if(!a({href:u,label:d,title:f}))return;let p=d||la(u);return[...t,r.mdFile.create({href:u,name:p,title:f})]}function da(e,t,n,r,i){let{labelTo:a,urlNode:o,titleNode:s}=ca(e),c=o?n.slice(o.from,o.to):``,l=s?oa(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){ha(t,e,n,r,i),m=t.to;continue}let a=ia.get(t.type),o=a?[...e,r[a].create()]:e;t.children.length===0?H(i,t.from,t.to,o):sa(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 fa(e,t,n){if(!t||t.type!==V.Comment||t.from!==e.to)return;let r=Zi(n.slice(t.from,t.to));if(r)return{magic:r,to:t.to}}function pa(e,t,n,r,i,a){let o=e.children.find(e=>e.type===V.URL);if(!o){da(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?oa(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 ma(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 ha(e,t,n,r,i){let{target:a,display:o}=ta(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&&hi(i[2],r)){e[e.length-1]=[i[0],n,i[2]];return}e.push([t,n,r])}const ga=`inline-marks-applied`;let _a=0,va=0;function ya(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 ba(e){let t=new WeakMap;function n(n,r,i){let a=t.get(n);if(a?va++:(_a++,a=aa(ec(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(ga))return null;let i=r(n,ya(e,n));if(i.length===0)return null;let a=n.tr.step(new gi(i));return a.setMeta(ga,!0),a.setMeta(`addToHistory`,!1),a},view(e){return e.dispatch(xa(e.state)),{}}})}function xa(e){return e.tr.setMeta(`inline-marks-trigger`,!0)}function Sa(e){return m(ba(e))}function Ca(){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 wa(){return u({name:`mdMark`,inclusive:!1,toDOM:()=>[`span`,{class:`md-mark`},0],parseDOM:[{tag:`span.md-mark`}]})}function Ta(){return u({name:`mdEm`,toDOM:()=>[`em`,0],parseDOM:[{tag:`em`}]})}function Ea(){return u({name:`mdStrong`,toDOM:()=>[`strong`,0],parseDOM:[{tag:`strong`}]})}function Da(){return u({name:`mdCode`,toDOM:()=>[`code`,0],parseDOM:[{tag:`code`}]})}function Oa(){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 ka(){return u({name:`mdLinkUri`,inclusive:!1,toDOM:()=>[`span`,{class:`md-link-uri`},0],parseDOM:[{tag:`span.md-link-uri`}]})}function Aa(){return u({name:`mdLinkTitle`,inclusive:!1,toDOM:()=>[`span`,{class:`md-link-title`},0],parseDOM:[{tag:`span.md-link-title`}]})}function ja(){return u({name:`mdDel`,toDOM:()=>[`del`,0],parseDOM:[{tag:`del`}]})}function Ma(){return u({name:`mdHighlight`,toDOM:()=>[`mark`,0],parseDOM:[{tag:`mark`}]})}function Na(){return u({name:`mdTag`,toDOM:()=>[`span`,{class:`md-tag`},0],parseDOM:[{tag:`span.md-tag`}]})}function Pa(){return u({name:`mdWikilink`,inclusive:!1,attrs:{target:{default:``},display:{default:``}},toDOM:()=>[`span`,{class:`md-wikilink`},0],parseDOM:[{tag:`span.md-wikilink`}]})}function Fa(){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 Ia(){return u({name:`mdMath`,inclusive:!1,attrs:{formula:{default:``}},toDOM:()=>[`span`,{class:`md-math`},0],parseDOM:[{tag:`span.md-math`}]})}function La(){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 Ra(){return g(wa(),Ta(),Ea(),Da(),Oa(),ka(),Aa(),ja(),Ma(),Na(),Pa(),Ca(),Fa(),Ia(),La())}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:`==`}},za=new Set([V.EmphasisMark,V.CodeMark,V.LinkMark,V.StrikethroughMark,V.HighlightMark]);function Ba(e){return[e.children[0],e.children.at(-1)]}function Va(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 Ha(e,t,n){for(let r of e){if(r.to<=t||r.from>=n||t<=r.from&&r.to<=n)continue;let i=Va(r);return i&&i[0]<=t&&n<=i[1]?Ha(r.children,t,n):Ha(e,Math.min(t,r.from),Math.max(n,r.to))}return[t,n]}function Ua(e,t,n){for(let r of e)if(!(r.to<=t||r.from>=n)&&(t>r.from||r.to>n))return Ua(e,Math.min(t,r.from),Math.max(n,r.to));return[t,n]}function Wa(e,t,n){for(;t<n&&N(e.charCodeAt(t));)t++;for(;n>t&&N(e.charCodeAt(n-1));)n--;return[t,n]}function Ga(e,t,n,r){let i=qi(Ki(e),e=>e.type===r.node||za.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 Ka(e,t,n,r,i){let a=Ki(e),o=qi(a,e=>e.type===r.node);return i?Ya(e,o,t,n):qa(e,a,o,t,n,r)}function qa(e,t,n,r,i,a){for(let e=0;e!==i-r;){e=i-r,[r,i]=Ha(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]=Ba(e);o.push({from:t.from,to:t.to,insert:``}),o.push({from:n.from,to:n.to,insert:``})}let[s,c]=Ja(e,r,i,o,a);return o.push({from:r,to:r,insert:s},{from:i,to:i,insert:c}),o}function Ja(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(Yn(a)+1),s=a.startsWith("`")||a.endsWith("`")?` `:``;return[o+s,s+o]}function Ya(e,t,n,r){let i=[];for(let a of t){if(a.to<=n||a.from>=r)continue;let[t,o]=Ba(a),s=Math.max(n,t.to),c=Math.min(r,o.from);for(s>=c&&([s,c]=[t.to,o.from]),[s,c]=Ua(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 Xa(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=Ki(e),o=qi(a,e=>e.type===n.node).findLast(e=>e.from<=t&&t<=e.to);if(o){let[e,n]=Ba(o);return{kind:`move`,pos:t===o.from?e.to:t===o.to?n.from:o.to}}return Za(a,t)||e[t-1]===r[0]||e[t]===r[0]?null:{kind:`insert`,pos:t}}function Za(e,t){for(let n of e)if(n.from<t&&t<n.to){let e=Va(n);return!e||t<e[0]||t>e[1]||Za(n.children,t)}return!1}function W(e){return(t,n)=>{if(t.selection.empty)return Qa(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]=Wa(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:Ga(a,c,l,e)}),!1});let c=s.length>0&&s.every(e=>e.active),l=s.filter(e=>c||!e.active).flatMap(t=>Ka(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(b.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 Qa(e,t,n){let{$from:r}=t.selection,i=r.parent;if(!i.isTextblock||i.type.spec.code)return!1;let a=Xa(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(b.create(o.doc,i+a.pos)),a.kind===`insert`&&(o.insertText(e.delim+e.delim,i+a.pos),o.setSelection(b.create(o.doc,i+a.pos+e.delim.length))),n(o.scrollIntoView())}return!0}function $a(){return s({toggleEm:()=>W(U.em),toggleStrong:()=>W(U.strong),toggleCode:()=>W(U.code),toggleDel:()=>W(U.del),toggleHighlight:()=>W(U.highlight)})}function eo(){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 to(){return g($a(),eo())}function no(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`?no(e,t,`mdLinkText`)??{from:i.from+1,to:i.to-1}:t,href:o,title:``}}let s=no(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 ro(e){let t=e.trim();return t?Si(t)??t:``}function io(e,t){return e+(t?` "${t.replaceAll(/(["\\])/g,String.raw`\$1`)}"`:``)}function ao(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]=Wa(a.textContent,n.parentOffset,r.parentOffset);if(!(s>=c))return{from:o+s,to:o+c}}function oo({href:e,title:t,wrapText:n=!0}={}){return(r,i)=>{let a=ao(r);if(!a)return!1;if(i){let{from:o,to:s}=a,c=r.tr,l=`](${io(ro(e??``),t??``)})`;c.insertText(l,s).insertText(`[`,o);let u=s+1+l.length;c.setSelection(n?b.create(c.doc,o,u):b.create(c.doc,u)),c.scrollIntoView(),i(c)}return!0}}function so(e){return(t,n)=>{let r=G(t,t.selection.from);if(!r?.dest)return!1;let i=io(ro(e.href??r.href),e.title??r.title);return n&&n(t.tr.insertText(i,r.dest.from,r.dest.to).scrollIntoView()),!0}}function co(){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 lo(){return s({insertLink:oo,updateLink:so,removeLink:co})}function uo(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(b.create(t.doc,a,o)).scrollIntoView()),r.focus(),e({from:a,to:o,link:i})}return!0}let a=ao(t);if(a){if(n&&r){let{from:i,to:o}=a;n(t.tr.setSelection(b.create(t.doc,i,o)).scrollIntoView()),r.focus(),e({from:i,to:o,link:void 0})}return!0}return!1}}function fo(e){return l({"Mod-k":uo(e)})}function po(e){return e===`)`||e===`*`||e===`+`?e:void 0}function mo(e){return e===`X`?e:void 0}function ho(e){return vo(e)?String(e):void 0}function go(){return f({type:`list`,attr:`marker`,default:null,splittable:!0,toDOM:e=>{let t=po(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 _o(){return f({type:`list`,attr:`taskMarker`,default:null,splittable:!0,toDOM:e=>{let t=mo(e);return t==null?null:[`data-list-task-marker`,t]},parseDOM:e=>e.getAttribute(`data-list-task-marker`)===`X`?`X`:null})}function vo(e){return e===2||e===3||e===4}function yo(){return f({type:`list`,attr:`markerGap`,default:1,splittable:!0,toDOM:e=>{let t=ho(e);return t==null?null:[`data-list-marker-gap`,t]},parseDOM:e=>{let t=Number.parseInt(e.getAttribute(`data-list-marker-gap`)??``,10);return vo(t)?t:1}})}function bo(e){let t=e.attrs;return{..._t(e),"data-list-marker":po(t.marker),"data-list-task-marker":mo(t.taskMarker),"data-list-marker-gap":ho(t.markerGap)}}function xo(){return o({serializeFragmentWrapper:e=>(...t)=>So(bt(e(...t))),serializeNodeWrapper:e=>(...t)=>{let n=e(...t);return _e(n)?So(bt(n)):n},nodesFromSchemaWrapper:e=>(...t)=>({...e(...t),list:e=>xt({node:e,nativeList:!0,getAttributes:bo})})})}function So(e){_e(e)&&Co(e);for(let t of e.children)So(t);return e}function Co(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=vt(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 wo=[Ct(/^\s?([*-])\s$/,{kind:`bullet`,collapsed:!1}),Ct(/^\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}}),Ct(/^\s?\[([\sX]?)\]\s$/i,({match:e})=>({kind:`task`,checked:[`x`,`X`].includes(e[1]),collapsed:!1})),Ct(/^\s?\+\s$/,{kind:`task`,marker:`+`,checked:!1,collapsed:!1})];function To(){return g(wo.map(Je))}function Eo(){return T({kind:`task`,marker:`+`})}function Do(){return T({kind:`task`,marker:null})}function Oo(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 ko(){return(e,t,n)=>{let r=Oo(e);return(r?.kind===`task`?r.marker===`+`?Do():Eo():T({kind:`task`,marker:null,checked:!1}))(e,t,n)}}function Ao(){return s({cycleCheckableList:ko,wrapInCircleTask:Eo,wrapInSquareTask:Do})}function jo(){return(e,t,n)=>{let r=Oo(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 Mo(){return(e,t,n)=>{let r=Oo(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 No(e){return e.type.name===`list`&&e.attrs.kind===`bullet`&&e.childCount>=2&&e.firstChild?.type!==e.type}const Po=e=>{let t=e.attrs;return t.kind===`task`?{...t,checked:!t.checked}:No(e)?{...t,collapsed:!t.collapsed}:t};function Fo(){return m(()=>[new v({props:{handleDOMEvents:{mousedown:(e,t)=>yt({view:e,event:t,onListClick:Po})}}}),mt(),new v({props:{transformCopied:St}}),ht()])}function Io(){return s({toggleListCollapsed:()=>gt({isToggleable:No})})}function Lo(){return l({"Mod-Enter":jo(),"Mod-Shift-Enter":Mo(),"Mod-.":gt({isToggleable:No}),"Mod-Shift-7":pt({kind:`ordered`,collapsed:!1}),"Mod-Shift-8":pt({kind:`bullet`,collapsed:!1}),"Mod-Shift-9":pt({kind:`task`,checked:!1,collapsed:!1})})}function Ro(){return g(dt(),Fo(),ut(),ct(),xo(),lt(),To(),Lo(),go(),_o(),yo(),Ao(),Io())}let zo;function Bo(){return zo??=import(`katex`).then(e=>e.render),zo}function Vo(e,t,n,r){try{e(n,t,{displayMode:r,throwOnError:!1,output:`mathml`})}catch(e){t.textContent=String(e)}}var Ho=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=b.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;Bo().then(t=>{e===this.#r&&Vo(t,this.#n,e,!1)})}};function Uo(){return d({name:`mdMath`,constructor:(e,t)=>new Ho(e,t)})}function Wo(e){return e===`left`||e===`center`||e===`right`?e:null}function Go(){return f({type:`tableCell`,attr:`align`,default:null,toDOM:e=>e?[`data-align`,e]:null,parseDOM:e=>Wo(e.getAttribute(`data-align`))})}function Ko(){return f({type:`tableHeaderCell`,attr:`align`,default:null,toDOM:e=>e?[`data-align`,e]:null,parseDOM:e=>Wo(e.getAttribute(`data-align`))})}function qo(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 Jo(e){return e.child(qo(e))}function Yo(e,t){return t>=e.childCount?null:e.child(t).attrs.align??null}function Xo(e,t,n){if(e.childCount===0)return;let r=Jo(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=Yo(r,e);(t.attrs.align??null)!==i&&n.setNodeMarkup(o,void 0,{...t.attrs,align:i}),o+=t.nodeSize}i+=a.nodeSize}}function Zo(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 Qo(){return new v({key:new y(`table-align-sync`),appendTransaction(e,t,n){if(!e.some(e=>e.docChanged))return;let r=Zo(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,Xo(e,t,s),!1):!0),s?.docChanged?s:void 0}})}function $o(){return m(Qo())}function es(e){let{selection:t}=e;if(Mt(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 ts(e){return(t,n)=>{let r=es(t);if(!r||r.table.childCount===0)return!1;if(n){let{table:i,tablePos:a,firstColumn:o,lastColumn:s}=r,c=qo(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 ns(e){let t=es(e);if(!(!t||t.table.childCount===0))return Yo(Jo(t.table),t.lastColumn)??void 0}function rs(){return s({setTableColumnAlign:ts})}function is(){return g(Go(),Ko(),$o(),rs())}function as(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 os=`paragraph`;function ss(){return g(p({name:`tableCell`,content:os}),p({name:`tableHeaderCell`,content:os}))}const cs=(e,t)=>{let{selection:n}=e;return!Mt(n)||!n.isColSelection()||!n.isRowSelection()?!1:jt(e,t)};function ls(){return _(l({Backspace:cs,Delete:cs}),t.high)}function us(){return g(At(),kt(),wt(),Ot(),ss(),is(),Dt({allowTableNodeSelection:!0}),Tt(),Et(),ls())}function ds(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 fs(e){return(t,n)=>{if(as(t))return!1;let r=ds(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):b.create(u.doc,a.anchor+d,a.head+d);u.setSelection(f),n(u.scrollIntoView())}return!0}}function ps(e){return(t,n,r)=>ft(e)(t,n,r)||fs(e===`up`?-1:1)(t,n,r)}function ms(){return l({"Alt-ArrowUp":ps(`up`),"Alt-ArrowDown":ps(`down`)})}const K=new y(`meowdownPendingReplacement`);function q(e){return K.getState(e)?.pending??null}function hs(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 gs=new v({key:K,state:{init:()=>({pending:null}),apply:(e,t)=>{let n=e.getMeta(K);if(n)return hs(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:x.create(e.doc,[Oe.inline(t.from,t.to,{class:`md-pending-replacement`})])}}});function _s(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 vs(e){return(t,n)=>q(t)?(n?.(t.tr.setMeta(K,{type:`append`,text:e})),!0):!1}function ys(){return(e,t)=>q(e)?(t?.(e.tr.setMeta(K,{type:`discard`})),!0):!1}function bs(e={}){return(t,n)=>{let r=q(t);if(!r||!r.text.trim())return!1;if(n){let i=e.mode??r.mode,a=nc(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(b.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(b.near(s.doc.resolve(r.from+i.content.size),-1))):(s.replaceRange(r.from,r.to,new w(o.content,0,0)),s.setSelection(b.near(s.doc.resolve(s.mapping.map(r.to)),-1)))}n(s.scrollIntoView())}return!0}}function xs(){return s({startPendingReplacement:_s,appendPendingReplacementText:vs,acceptPendingReplacement:bs,discardPendingReplacement:ys})}function Ss(){return l({"Mod-Enter":bs(),Escape:ys()})}function Cs(){return g(m(gs),xs(),Ss())}function ws(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 Ts(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 Ts(r)?void 0:r}function Es(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 Ds(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 Os(e){let t=e.state,n=t.selection.head;for(let r of Wt){let i=E(t,n,r);if(i==null||i.from!==n&&i.to!==n)continue;let a=ks(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 ks(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 As(e){return Ds(e)??Os(e)}const js=new y(`meowdown-scroll-to-selection`);function Ms(e){let t=e.state.selection;if(!h(t)||J(e,t.head,1)!=null)return!1;let n=As(e);if(n==null)return!1;let r=e.domAtPos(t.head).node;return Is(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 Ns(e){let t=e.assignedSlot??e.parentNode;return t?.nodeType===11?t.host:t}function Ps(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 Fs(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 Is(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=Ns(e);continue}let n=e,o=n===a.body,s=o?Ps(a):Fs(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:Ns(n)}}function Ls(){return m(new v({key:js,props:{handleScrollToSelection:Ms}}))}function Rs(e,t){return(n,r)=>{let i=e<0?De.atStart(n.doc):De.atEnd(n.doc),a=t?b.between(n.selection.$anchor,i.$head):i;return n.selection.eq(a)||r?.(n.tr.setSelection(a).scrollIntoView()),!0}}function zs(){return l({"Meta-ArrowUp":Rs(-1,!1),"Meta-ArrowDown":Rs(1,!1),"Shift-Meta-ArrowUp":Rs(-1,!0),"Shift-Meta-ArrowDown":Rs(1,!0)})}function Bs(e){e.offsetWidth}const Vs=new y(`meowdown-virtual-caret`),Hs=[`md-virtual-caret-blink`,`md-virtual-caret-blink2`];function Us(e){let t=e.height*.19999999999999996;return{left:e.left,top:e.top-t/2,height:e.height+t}}function Ws(e){let t=Es(e)??Ds(e);return t==null?Os(e):Us(t)}function Gs(e,t){return e==null||t==null?e===t:e.left===t.left&&e.top===t.top&&e.height===t.height}var Ks=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=Hs[this.#s]}#l=()=>{let e=this.#e;if(e.isDestroyed)return;let t=e.state,n=t.selection,r=h(n)&&n.empty?Ws(e):void 0,i=r!=null&&O(t)===`hide`?$r(t,n.head):void 0;if(Gs(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&&(Bs(this.#n),this.#n.style.transitionProperty=``)}};function qs(){return m(new v({key:Vs,view:e=>new Ks(e)}))}function Js(e){return g(Pn(),xe(),Ur(),we(),be(),Ro(),An(),us(),Pr(),di(),fi(),Ra(),Tr(),Hr(),ms(),zs(),Sa(e),to(),lo(),ra(),Uo(),Bt(e.markMode??`focus`),yr(),qs(),Ls(),li(),nn({marks:Wt.map(e=>({name:e,modes:[`hide`,`focus`,`show`]}))}),a(),i(),c(),Se(),Te(),Ce(),Br(),Cs())}function Ys(e={}){return Js(e)}const Xs=ye(()=>{let e=Ys().schema;if(e==null)throw Error(`Unexpected empty schema`);return e}),Zs=ye(()=>r(Xs())),Qs=ye(()=>n(Xs())),$s=`meowdown_mark_builders`;function ec(e){let t=e.cached[$s];if(t)return t;let r=n(e);return e.cached[$s]=r,r}const tc=`meowdown_node_builders`;function nc(e){let t=e.cached[tc];if(t)return t;let n=r(e);return e.cached[tc]=n,n}function X(e,t={}){let{nodes:n=Zs(),frontmatter:r=!1}=t,i,a=e;if(r){let[t,n]=ic(e);i=t,n&&(a=e.slice(n))}let o=ac(n,Gi.parse(a).cursor(),a);return n.doc(i===void 0?{}:{frontmatter:i},o)}const rc=/^---[ \t]*\r?\n([\s\S]*?\n)?---[ \t]*(?:\r?\n|$)/;function ic(e){let t=rc.exec(e);return t?[(t[1]??``).replace(/\r?\n$/,``),t[0].length]:[]}function ac(e,t,n){let r=[];if(!t.firstChild())return r;let i;do i!=null&&oc(r,e,n,i,t.from),i=t.to,r.push(...sc(e,t,n));while(t.nextSibling());return t.parent(),r}function oc(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 sc(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[pc(e,t,n)];case V.CommentBlock:return[mc(e,t,n)];case V.HTMLBlock:case V.ProcessingInstructionBlock:return[pc(e,t,n)];case V.Blockquote:return[hc(e,t,n)];case V.BulletList:return gc(e,t,n,`bullet`);case V.OrderedList:return gc(e,t,n,`ordered`);case V.FencedCode:case V.CodeBlock:return[vc(e,t,n)];case V.BlockMath:return[yc(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[bc(e,t,n)];case V.Task:return[pc(e,t,n)];default:return n.slice(t.from,t.to).trim()===``?[]:(console.warn(`[meowdown] unsupported lezer block "${t.type.name}"`),[pc(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=dc(n.slice(o,s),Q(n,o)).trim(),d=i?cc(n,c,l)||1:null,f=!i&&c>=0&&lc(n,c,l)||null;return e.heading({level:r,setextUnderline:d,closingHashes:f},u)}function cc(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 lc(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 uc(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 dc(e,t){return t===0||!e.includes(`
25
+ `)}function pr(){return m(new y({key:new b(`meowdown-plain-text-copy`),props:{clipboardTextSerializer:(e,t)=>{let n=k(t.state)===`hide`?mr(e):e;return fr(t.state.schema,n)}}}))}function mr(e){return new T(hr(e.content),e.openStart,e.openEnd)}function hr(e){let t=[];return e.forEach(e=>{t.push(e.isTextblock?_r(e):gr(e))}),w.from(t)}function gr(e){return e.childCount>0?e.copy(hr(e.content)):e}function _r(e){let t=e.type.schema,n=[];for(let r of hn(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)mn(e.marks)||n.push(e)}return e.copy(w.from(n))}function vr(){return _(Fn(),pr(),Un(),Bn(),Kn())}const I=new Map,yr=new Map,br={math:`latex`};async function xr(e){let t=I.get(e);if(t!==void 0)return t;let n=Be.matchLanguageName(Ve,br[e]??e,!0);if(!n)return I.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),I.set(e,null),null}return I.set(e,r),r}function Sr(e,t){let n=yr.get(e);if(n)return n;let r=We({parse:e=>t.language.parser.parse(e.content),highlighter:He});return yr.set(e,r),r}const Cr=e=>{let t=e.language?.trim();if(!t)return[];let n=I.get(t);return n===null?[]:n?Sr(t,n)(e):xr(t).then(()=>void 0)};function wr(){return de({parser:Cr,nodeTypes:[`codeBlock`]})}function Tr(e,t){let n=t.language.parser.parse(e),r=[];return Ue(n,He,(e,t,n)=>{r.push([e,t,n])}),r}function Er(e,t){let n=t.trim();if(!n)return[];let r=I.get(n);return r===null?[]:r?Tr(e,r):xr(n).then(t=>t?Tr(e,t):[])}function Dr(){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 Or(){return f({type:`codeBlock`,attr:`fenceLength`,default:null,toDOM:e=>e==null?null:[`data-fence-length`,String(e)],parseDOM:e=>{let t=cn(e.getAttribute(`data-fence-length`));return t!=null&&t>3?t:null}})}function kr(e){return{language:e[1]||``,fenceStyle:`tilde`}}function Ar(){return Je({regex:/^~~~(\S*)\s$/,type:`codeBlock`,attrs:kr})}function jr(){return Ke({regex:/^~~~(\S*)$/,type:`codeBlock`,attrs:kr})}function Mr(){return Ke({regex:/^\$\$$/,type:`codeBlock`,attrs:()=>({language:`math`,fenceStyle:`dollar`})})}function Nr(){return _(ue(),Dr(),Or(),Ar(),jr(),Mr())}function Pr(e,t){return(n,r)=>{if(r){let i=x.create(n.doc,e,t);r(n.tr.setSelection(i))}return!0}}function Fr(e,t,n){return(r,i)=>{if(i){let a=x.between(e,t,n);i(r.tr.setSelection(a))}return!0}}function Ir(e){return(t,n)=>{if(!e.trim())return!1;let r=X(e,{nodes:lc(t.schema)}).content;if(r.childCount===0)return!1;let i=r.childCount===1&&r.child(0).type.name===`paragraph`?new T(r,1,1):new T(r,0,T.maxOpen(r).openEnd);if(n){let e=t.tr,r=e.selection;(!g(r)||!r.empty)&&e.setSelection(x.near(r.$from)),n(e.replaceSelection(i).scrollIntoView())}return!0}}function Lr(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 Rr(){return(e,t)=>(t&&t(e.tr.scrollIntoView()),!0)}function zr(){return s({insertMarkdown:Ir,insertTrigger:Lr,scrollIntoView:Rr,selectText:Pr,selectTextBetween:Fr})}const Br=(e,t,n)=>{let{selection:r}=e;return r.empty||n?.composing?!1:(t?.(e.tr.setSelection(x.near(r.$head))),!0)};function Vr(){return v(l({Escape:Br}),t.low)}function Hr(){return f({type:`doc`,attr:`frontmatter`,default:null})}function Ur(e,t){return t(e.state,e.dispatch,e)}const Wr=new Set([`mdMark`,`mdLinkUri`,`mdLinkTitle`]);function Gr(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 L(e,t){let n=Gr(e,t);return n!=null&&n.some(e=>Wr.has(e.type.name))}function R(e,t){if(t<0||t>e.doc.content.size)return!1;let n=e.doc.resolve(t);return n.parent.isTextblock&&!n.parent.type.spec.code}function z(e,t){if(!R(e,t))return;let n=e.doc.resolve(t).start(),r=t;for(;r>n&&L(e,r-1);)r--;return r<t?{from:r,to:t}:void 0}function B(e,t){if(!R(e,t))return;let n=e.doc.resolve(t).end(),r=t;for(;r<n&&L(e,r);)r++;return r>t?{from:t,to:r}:void 0}function Kr(e,t){return L(e,t-1)&&L(e,t)}function qr(e,t){if(!Kr(e,t))return;let n=z(e,t),r=B(e,t);if(!(n==null||r==null))return{from:n.from,to:r.to}}function Jr(e,t,n){let r=Gr(e,t);return r!=null&&n.isInSet(r)}function Yr(e,t){let n=Gr(e,t);if(n==null)return;let r=ee(e.schema,`mdPack`),i=n.filter(e=>e.type===r);if(i.length===0)return;let a=e.doc.resolve(t),o=a.start(),s=a.end(),c;for(let n of i){let r=t;for(;r>o&&Jr(e,r-1,n);)r--;let i=t+1;for(;i<s&&Jr(e,i,n);)i++;(c==null||i-r<c.to-c.from)&&(c={from:r,to:i})}return c}function Xr(e,t,n){let r=Yr(e,n===`from`?t.from:t.to-1);return r==null?!1:n===`from`?r.from===t.from:r.to===t.to}function Zr(e,t,n){let r=Xr(e,t,`from`),i=Xr(e,t,`to`);return r&&!i?t.from:i&&!r?t.to:n-t.from<=t.to-n?t.from:t.to}function Qr(e,t,n,r){if(!R(e,n))return n;let i=qr(e,n);if(i!=null)return r?Zr(e,i,n):n>=t?i.to:i.from;if(!r)return n;let a=z(e,n);if(a!=null&&Xr(e,a,`from`))return a.from;let o=B(e,n);return o!=null&&Xr(e,o,`to`)?o.to:n}function $r(e,t){if(!R(e,t))return;let n=L(e,t-1),r=L(e,t);if(n!==r)return r?`left`:`right`}function ei(e,t){let n=Yr(e,t);if(n==null)return[];let r=B(e,n.from),i=z(e,n.to),a=[];return i!=null&&a.push(i),r!=null&&(i==null||r.from!==i.from)&&a.push(r),a}const ti=new b(`meowdown-hidden-run-snap`),ni=new b(`meowdown-hidden-run-beforeinput`);function ri(){let e=!1;return new y({key:ti,props:{handleDOMEvents:{compositionstart:()=>(e=!0,!1),compositionend:()=>(e=!1,!1)}},appendTransaction:(t,n,r)=>{if(e||k(r)!==`hide`)return null;let i=r.selection;if(!g(i))return null;let a=t.some(e=>e.getMeta(`pointer`)!=null);if(i.empty){let e=Qr(r,n.selection.head,i.head,a);return e===i.head?null:r.tr.setSelection(x.create(r.doc,e))}let o=qr(r,i.from)?.from??i.from,s=qr(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 ii=(e,t)=>{if(k(e)!==`hide`)return!1;let n=e.selection;if(!g(n)||!n.empty)return!1;let r=Qr(e,n.head,n.head,!0);return r===n.head||t?.(e.tr.setSelection(x.create(e.doc,r))),!1};function ai(e){return(t,n)=>{if(k(t)!==`hide`)return!1;let r=t.selection;if(!g(r)||!r.empty)return!1;let i=r.$head;if(!i.parent.isTextblock||i.parent.type.spec.code)return!1;let a=e===-1?z(t,r.head):B(t,r.head);if(a==null)return!1;let o=ei(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 oi=ai(-1),si=ai(1);function ci(){return new y({key:ni,props:{handleDOMEvents:{beforeinput:(e,t)=>{if(e.composing)return!1;let n=t.inputType===`deleteContentBackward`?oi:t.inputType===`deleteContentForward`?si:void 0;return n==null||!Ur(e,n)?!1:(t.preventDefault(),!0)}}}})}function li(){return _(m(ri()),m(ci()),v(l({Enter:ii,Backspace:oi,Delete:si}),t.highest))}function ui(){return f({type:`horizontalRule`,attr:`marker`,default:null,toDOM:e=>e?[`data-hr-marker`,e]:null,parseDOM:e=>e.getAttribute(`data-hr-marker`)})}function di(){return _(Xe(),ui())}function fi(){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 pi(e){let[t,n,r]=e;return[t,n,r.map(e=>e.toJSON())]}function mi(e,t){let[n,r,i]=t;return[n,r,i.map(t=>Pe.fromJSON(e,t))]}function hi(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 gi=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=Pe.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(hi(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 _i;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(pi)}}static fromJSON(t,n){let r=n.chunks;return new e(r.map(e=>mi(t,e)))}};nt.jsonID(`batchSetMark`,gi);const _i=new gi([]),vi=new Set([`com`,`br`,`net`,`jp`,`org`,`in`,`de`,`ru`,`it`,`fr`]),yi=/^[a-z0-9](?:[a-z0-9-]*[a-z0-9])?$/i;function bi(e){let t=e.indexOf(`/`);return t===-1?e:e.slice(0,t)}function xi(e){let t=e.split(`.`);if(t.length<2)return!1;let n=t[t.length-1].toLowerCase();if(!vi.has(n)||t[t.length-2].length<3)return!1;for(let e of t)if(e.length>63||!yi.test(e))return!1;return!0}function Si(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)||xi(bi(e)))return`https://${e}`}const Ci=/^[a-z0-9-]+(?:\.[a-z0-9-]+)+(?:\/[^\s<]*)?/i,wi=/[\s(*_~]/;function Ti(e){return e>=48&&e<=57||e>=65&&e<=90||e>=97&&e<=122||e===45}function Ei(e,t,n){let r=0;for(let i=0;i<t;i++)e[i]===n&&r++;return r}function Di(e){let t=e.length;for(;;){let n=e[t-1];if(/[?!.,:*_~]/.test(n)||n===`)`&&Ei(e,t,`)`)>Ei(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 Oi={parseInline:[{name:`BareAutolink`,before:`Link`,parse(e,t,n){if(!Ti(t)||e.hasOpenLink)return-1;let r=e.slice(n-1,n);if(r!==``&&!wi.test(r))return-1;let i=Ci.exec(e.slice(n,e.end));if(!i)return-1;let a=Di(i[0]);return a===0||!xi(bi(i[0].slice(0,a)))?-1:e.addElement(e.elt(`URL`,n,n+a))}}]};function ki(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 Ai(e){return e>=65&&e<=90||e>=97&&e<=122||e>127&&/\p{L}/u.test(String.fromCharCode(e))}const ji={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(!ki(t))break;i||=Ai(t),r++}return i?e.addElement(e.elt(`Hashtag`,n,r)):-1}}]},Mi={resolve:`Highlight`,mark:`HighlightMark`},Ni=/[!"#$%&'()*+,\-./:;<=>?@[\\\]^_`{|}~\u{A1}\u{2010}-\u{2027}]/u,Pi={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=Ni.test(r),c=Ni.test(i);return e.addDelimiter(Mi,n,n+2,!o&&(!c||a||s),!a&&(!s||o||c))}}]};function Fi(e){return e>=48&&e<=57}function Ii(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 Li(e){let t=e.depth;return typeof t==`number`?t:2**53-1}const Ri={defineNodes:[{name:`InlineMath`},{name:`InlineMathMark`},{name:`BlockMath`,block:!0},{name:`BlockMathMark`}],parseBlock:[{name:`BlockMath`,before:`FencedCode`,parse(e,t){if(!Ii(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()||Li(t)<e.depth);n=!1){if(Ii(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 Ii(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(P(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||P(e.char(t-1))||Fi(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}}]},zi=/^[a-z][a-z0-9+.-]*:\/\/[^\s<]+/i;function Bi(e){return e>=65&&e<=90||e>=97&&e<=122}const Vi={parseInline:[{name:`SchemeAutolink`,after:`Autolink`,parse(e,t,n){if(!Bi(t)||e.hasOpenLink)return-1;let r=e.slice(n-1,n);if(r!==``&&!wi.test(r))return-1;let i=zi.exec(e.slice(n,e.end));if(!i)return-1;let a=Di(i[0]);return a<=i[0].indexOf(`://`)+3?-1:e.addElement(e.elt(`URL`,n,n+a))}}]},Hi={defineNodes:[{name:`WikiEmbed`},{name:`WikiEmbedMark`}],parseInline:[{name:`WikiEmbed`,before:`Link`,parse(e,t,n){if(t!==33||e.char(n+1)!==91||e.char(n+2)!==91)return-1;let r=!1;for(let t=n+3;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(`WikiEmbed`,n,i,[e.elt(`WikiEmbedMark`,n,n+3),e.elt(`WikiEmbedMark`,t,i)]))}if(i===91||i===10)return-1;i!==32&&i!==9&&(r=!0)}return-1}}]},Ui={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 Wi(e){return e.end}const Gi=ot.configure([at,ji,Hi,Ui,Oi,Vi,Pi,Ri]),Ki=Gi.configure({parseInline:[{name:`SkipInline`,before:`Escape`,parse:Wi}]});function qi(e){return Gi.parseInline(e,0)}function Ji(e,t,n=[]){for(let r of e)t(r)&&n.push(r),Ji(r.children,t,n);return n}function Yi(e){let t={};for(let n of e.nodeSet.types)t[n.name]=n.id;return t}const V=Yi(Gi),Xi=/^<!--\s*(\{[^}]*\})\s*-->$/,Zi=/<!--\s*\{[^}]*\}\s*-->$/;function Qi(e){let t=Xi.exec(e.trim());if(!t)return;let n;try{n=JSON.parse(t[1])}catch{return}if(typeof n!=`object`||!n)return;let r=$i(n);return Object.keys(r).length>0?r:void 0}function $i(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 ea(e){return`<!-- ${JSON.stringify(e)} -->`}function ta(e){return e.replace(Zi,``)}const na=/^(\d+)(?:x(\d+))?$/i;function ra(e){if(!e)return null;let t=Number.parseInt(e,10);return Number.isSafeInteger(t)&&t>0?t:null}function ia(e){let t=e.replace(/^!\[\[/,``).replace(/\]\]$/,``),n=t.lastIndexOf(`|`);if(n<0)return{target:t.trim(),display:``,width:null,height:null};let r=t.slice(0,n).trim(),i=t.slice(n+1).trim(),a=na.exec(i);if(!a)return{target:r,display:i,width:null,height:null};let o=ra(a[1]),s=ra(a[2]);return o==null||a[2]&&s==null?{target:r,display:i,width:null,height:null}:{target:r,display:``,width:o,height:s}}function aa(e,t,n){return`![[${e}|${Math.round(t)}x${Math.round(n)}]]`}function oa(e){let t=e.split(/[?#]/,1)[0],n=t.split(/[/\\]/).findLast(Boolean)??t;try{return decodeURIComponent(n)}catch{return n}}function sa(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 ca(){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 la(){return d({name:`mdWikilink`,constructor:ca()})}const ua=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 da(e,t,n){let r=qi(t),i=[];return pa(r,[],0,t.length,t,e,i,n),i}function fa(e){return e.slice(1,-1).replaceAll(/\\(.)/g,`$1`)}function pa(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=ga(r,t,i,a,s);e?H(o,r.from,r.to,e):_a(r,t,i,a,o,s)}else if(l===V.Image){let s=va(r,e[n+1],i);ya(r,t,i,a,o,s),s&&n++,c=s?s.to:r.to;continue}else if(l===V.Wikilink)xa(r,t,i,a,o);else if(l===V.WikiEmbed)Sa(r,t,i,a,o,s);else if(l===V.InlineMath)ba(r,t,i,a,o);else if(l===V.URL){let e=Si(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=ua.get(l),u=c?[...n,a[c].create()]:n;r.children.length===0?H(o,r.from,r.to,u):pa(r.children,u,r.from,r.to,i,a,o,s)}c=r.to}c<r&&H(o,c,r,t)}function ma(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 ha(e){let t=e.split(/[?#]/,1)[0],n=t.split(/[/\\]/).findLast(Boolean)??t;try{return decodeURIComponent(n)}catch{return n}}function ga(e,t,n,r,i){let a=i?.resolveFileLink;if(!a)return;let{labelFrom:o,labelTo:s,urlNode:c,titleNode:l}=ma(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?fa(n.slice(l.from,l.to)):``;if(!a({href:u,label:d,title:f}))return;let p=d||ha(u);return[...t,r.mdFile.create({href:u,name:p,title:f})]}function _a(e,t,n,r,i,a){let{labelTo:o,urlNode:s,titleNode:c}=ma(e),l=s?n.slice(s.from,s.to):``,u=c?fa(n.slice(c.from,c.to)):``,d=l?r.mdLinkText.create({href:l}):null,f=e=>o>=0&&e<o&&d!==null,p=r.mdPack.create({key:`link`,data:{href:l,title:u}}),m=[...t,p],h=e.from;for(let t of e.children){if(t.from>h){let e=f(h)?[...m,d]:m;H(i,h,t.from,e)}let e=f(t.from)?[...m,d]:m;if(t.type===V.Wikilink){xa(t,e,n,r,i),h=t.to;continue}if(t.type===V.WikiEmbed){Sa(t,e,n,r,i,a),h=t.to;continue}let o=ua.get(t.type),s=o?[...e,r[o].create()]:e;t.children.length===0?H(i,t.from,t.to,s):pa(t.children,s,t.from,t.to,n,r,i,a),h=t.to}h<e.to&&H(i,h,e.to,m)}function va(e,t,n){if(!t||t.type!==V.Comment||t.from!==e.to)return;let r=Qi(n.slice(t.from,t.to));if(r)return{magic:r,to:t.to}}function ya(e,t,n,r,i,a){let o=e.children.find(e=>e.type===V.URL);if(!o){_a(e,t,n,r,i,void 0);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?fa(n.slice(c.from,c.to)):``,f=a?.magic.width??null,p=a?.magic.height??null,m=a?.to??e.to;H(i,e.from,m,[...t,r.mdImage.create({src:l,alt:u,title:d,width:f,height:p,syntax:null,wikiTarget:null})])}function ba(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 xa(e,t,n,r,i){let{target:a,display:o}=sa(n.slice(e.from,e.to));H(i,e.from,e.to,[...t,r.mdWikilink.create({target:a,display:o})])}function Sa(e,t,n,r,i,a){let o=ia(n.slice(e.from,e.to)),s=a?.resolveWikiEmbed?.(o);if(!s){H(i,e.from,e.to,t);return}if(s.kind===`image`){let n=s.src??o.target,a=(s.alt??o.display)||oa(o.target);H(i,e.from,e.to,[...t,r.mdImage.create({src:n,alt:a,title:``,width:o.width,height:o.height,syntax:`wikiEmbed`,wikiTarget:o.target})]);return}if(s.kind===`file`){let n=s.href??o.target,a=(s.name??o.display)||oa(o.target);H(i,e.from,e.to,[...t,r.mdFile.create({href:n,name:a,title:s.title??``})]);return}let c=s.target??o.target,l=s.display??o.display;H(i,e.from,e.to,[...t,r.mdWikilink.create({target:c,display:l})])}function H(e,t,n,r){if(t>=n)return;let i=e.at(-1);if(i&&i[1]===t&&hi(i[2],r)){e[e.length-1]=[i[0],n,i[2]];return}e.push([t,n,r])}const Ca=`inline-marks-applied`;let wa=0,Ta=0;function Ea(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 Da(e){let t=new WeakMap;function n(n,r,i){let a=t.get(n);if(a?Ta++:(wa++,a=da(sc(i),n.textContent,e),t.set(n,a)),r===0)return a;let o=[];for(let[e,t,n]of a)o.push([e+r,t+r,n]);return o}function r(e,t){let r=[];return e.doc.nodesBetween(t.from,t.to,(t,i)=>{if(t.type.spec.code)return!1;if(!t.isTextblock)return!0;if(t.childCount===0)return!1;let a=n(t,i+1,e.schema);return a.length>0&&r.push(...a),!1}),r}return new y({key:new b(`inline-mark`),appendTransaction(e,t,n){for(let t of e)if(t.getMeta(Ca))return null;let i=r(n,Ea(e,n));if(i.length===0)return null;let a=n.tr.step(new gi(i));return a.setMeta(Ca,!0),a.setMeta(`addToHistory`,!1),a},view(e){return e.dispatch(Oa(e.state)),{}}})}function Oa(e){return e.tr.setMeta(`inline-marks-trigger`,!0)}function ka(e){return m(Da(e))}function Aa(){return u({name:`mdImage`,inclusive:!1,attrs:{src:{default:``},alt:{default:``},title:{default:``},width:{default:null},height:{default:null},syntax:{default:null},wikiTarget:{default:null}},toDOM:()=>[`span`,{class:`md-image`},0],parseDOM:[{tag:`span.md-image`}]})}function ja(){return u({name:`mdMark`,inclusive:!1,toDOM:()=>[`span`,{class:`md-mark`},0],parseDOM:[{tag:`span.md-mark`}]})}function Ma(){return u({name:`mdEm`,toDOM:()=>[`em`,0],parseDOM:[{tag:`em`}]})}function Na(){return u({name:`mdStrong`,toDOM:()=>[`strong`,0],parseDOM:[{tag:`strong`}]})}function Pa(){return u({name:`mdCode`,toDOM:()=>[`code`,0],parseDOM:[{tag:`code`}]})}function Fa(){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 Ia(){return u({name:`mdLinkUri`,inclusive:!1,toDOM:()=>[`span`,{class:`md-link-uri`},0],parseDOM:[{tag:`span.md-link-uri`}]})}function La(){return u({name:`mdLinkTitle`,inclusive:!1,toDOM:()=>[`span`,{class:`md-link-title`},0],parseDOM:[{tag:`span.md-link-title`}]})}function Ra(){return u({name:`mdDel`,toDOM:()=>[`del`,0],parseDOM:[{tag:`del`}]})}function za(){return u({name:`mdHighlight`,toDOM:()=>[`mark`,0],parseDOM:[{tag:`mark`}]})}function Ba(){return u({name:`mdTag`,toDOM:()=>[`span`,{class:`md-tag`},0],parseDOM:[{tag:`span.md-tag`}]})}function Va(){return u({name:`mdWikilink`,inclusive:!1,attrs:{target:{default:``},display:{default:``}},toDOM:()=>[`span`,{class:`md-wikilink`},0],parseDOM:[{tag:`span.md-wikilink`}]})}function Ha(){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 Ua(){return u({name:`mdMath`,inclusive:!1,attrs:{formula:{default:``}},toDOM:()=>[`span`,{class:`md-math`},0],parseDOM:[{tag:`span.md-math`}]})}function Wa(){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 Ga(){return _(ja(),Ma(),Na(),Pa(),Fa(),Ia(),La(),Ra(),za(),Ba(),Va(),Aa(),Ha(),Ua(),Wa())}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:`==`}},Ka=new Set([V.EmphasisMark,V.CodeMark,V.LinkMark,V.StrikethroughMark,V.HighlightMark]);function qa(e){return[e.children[0],e.children.at(-1)]}function Ja(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 Ya(e,t,n){for(let r of e){if(r.to<=t||r.from>=n||t<=r.from&&r.to<=n)continue;let i=Ja(r);return i&&i[0]<=t&&n<=i[1]?Ya(r.children,t,n):Ya(e,Math.min(t,r.from),Math.max(n,r.to))}return[t,n]}function Xa(e,t,n){for(let r of e)if(!(r.to<=t||r.from>=n)&&(t>r.from||r.to>n))return Xa(e,Math.min(t,r.from),Math.max(n,r.to));return[t,n]}function Za(e,t,n){for(;t<n&&P(e.charCodeAt(t));)t++;for(;n>t&&P(e.charCodeAt(n-1));)n--;return[t,n]}function Qa(e,t,n,r){let i=Ji(qi(e),e=>e.type===r.node||Ka.has(e.type));for(let r=t;r<n;r++)if(!P(e.charCodeAt(r))&&i.every(e=>!(e.from<=r&&r<e.to)))return!1;return!0}function $a(e,t,n,r,i){let a=qi(e),o=Ji(a,e=>e.type===r.node);return i?no(e,o,t,n):eo(e,a,o,t,n,r)}function eo(e,t,n,r,i,a){for(let e=0;e!==i-r;){e=i-r,[r,i]=Ya(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]=qa(e);o.push({from:t.from,to:t.to,insert:``}),o.push({from:n.from,to:n.to,insert:``})}let[s,c]=to(e,r,i,o,a);return o.push({from:r,to:r,insert:s},{from:i,to:i,insert:c}),o}function to(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(Jn(a)+1),s=a.startsWith("`")||a.endsWith("`")?` `:``;return[o+s,s+o]}function no(e,t,n,r){let i=[];for(let a of t){if(a.to<=n||a.from>=r)continue;let[t,o]=qa(a),s=Math.max(n,t.to),c=Math.min(r,o.from);for(s>=c&&([s,c]=[t.to,o.from]),[s,c]=Xa(a.children.slice(1,-1),s,c);s>t.to&&P(e.charCodeAt(s-1));)s--;for(;c<o.from&&P(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 ro(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=qi(e),o=Ji(a,e=>e.type===n.node).findLast(e=>e.from<=t&&t<=e.to);if(o){let[e,n]=qa(o);return{kind:`move`,pos:t===o.from?e.to:t===o.to?n.from:o.to}}return io(a,t)||e[t-1]===r[0]||e[t]===r[0]?null:{kind:`insert`,pos:t}}function io(e,t){for(let n of e)if(n.from<t&&t<n.to){let e=Ja(n);return!e||t<e[0]||t>e[1]||io(n.children,t)}return!1}function W(e){return(t,n)=>{if(t.selection.empty)return ao(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]=Za(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:Qa(a,c,l,e)}),!1});let c=s.length>0&&s.every(e=>e.active),l=s.filter(e=>c||!e.active).flatMap(t=>$a(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 ao(e,t,n){let{$from:r}=t.selection,i=r.parent;if(!i.isTextblock||i.type.spec.code)return!1;let a=ro(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 oo(){return s({toggleEm:()=>W(U.em),toggleStrong:()=>W(U.strong),toggleCode:()=>W(U.code),toggleDel:()=>W(U.del),toggleHighlight:()=>W(U.highlight)})}function so(){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 co(){return _(oo(),so())}function lo(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=D(e,t,`mdLinkText`),r=D(e,t,`mdPack`,{key:`link`})??D(e,t,`mdPack`,{key:`autolink`}),i=r??n;if(!i)return;let a=r?.mark.attrs,o=n?.mark.attrs?.href??``;if(!r||a?.key!==`link`){let t={from:i.from,to:i.to};return{unit:t,text:a?.key===`autolink`?lo(e,t,`mdLinkText`)??{from:i.from+1,to:i.to-1}:t,href:o,title:``}}let s=lo(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 uo(e){let t=e.trim();return t?Si(t)??t:``}function fo(e,t){return e+(t?` "${t.replaceAll(/(["\\])/g,String.raw`\$1`)}"`:``)}function po(e){let{selection:t}=e,{$from:n,$to:r,empty:i}=t;if(i||!n.sameParent(r)||!g(t))return;let a=n.parent;if(!a.isTextblock||a.type.spec.code)return;let o=n.start(),[s,c]=Za(a.textContent,n.parentOffset,r.parentOffset);if(!(s>=c))return{from:o+s,to:o+c}}function mo({href:e,title:t,wrapText:n=!0}={}){return(r,i)=>{let a=po(r);if(!a)return!1;if(i){let{from:o,to:s}=a,c=r.tr,l=`](${fo(uo(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 ho(e){return(t,n)=>{let r=G(t,t.selection.from);if(!r?.dest)return!1;let i=fo(uo(e.href??r.href),e.title??r.title);return n&&n(t.tr.insertText(i,r.dest.from,r.dest.to).scrollIntoView()),!0}}function go(){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 _o(){return s({insertLink:mo,updateLink:ho,removeLink:go})}function vo(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=po(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 yo(e){return l({"Mod-k":vo(e)})}function bo(e){return e===`)`||e===`*`||e===`+`?e:void 0}function xo(e){return e===`X`?e:void 0}function So(e){return To(e)?String(e):void 0}function Co(){return f({type:`list`,attr:`marker`,default:null,splittable:!0,toDOM:e=>{let t=bo(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 wo(){return f({type:`list`,attr:`taskMarker`,default:null,splittable:!0,toDOM:e=>{let t=xo(e);return t==null?null:[`data-list-task-marker`,t]},parseDOM:e=>e.getAttribute(`data-list-task-marker`)===`X`?`X`:null})}function To(e){return e===2||e===3||e===4}function Eo(){return f({type:`list`,attr:`markerGap`,default:1,splittable:!0,toDOM:e=>{let t=So(e);return t==null?null:[`data-list-marker-gap`,t]},parseDOM:e=>{let t=Number.parseInt(e.getAttribute(`data-list-marker-gap`)??``,10);return To(t)?t:1}})}function Do(e){let t=e.attrs;return{...gt(e),"data-list-marker":bo(t.marker),"data-list-task-marker":xo(t.taskMarker),"data-list-marker-gap":So(t.markerGap)}}function Oo(){return o({serializeFragmentWrapper:e=>(...t)=>ko(yt(e(...t))),serializeNodeWrapper:e=>(...t)=>{let n=e(...t);return ge(n)?ko(yt(n)):n},nodesFromSchemaWrapper:e=>(...t)=>({...e(...t),list:e=>bt({node:e,nativeList:!0,getAttributes:Do})})})}function ko(e){ge(e)&&Ao(e);for(let t of e.children)ko(t);return e}function Ao(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 jo=[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 Mo(){return _(jo.map(qe))}function No(){return E({kind:`task`,marker:`+`})}function Po(){return E({kind:`task`,marker:null})}function Fo(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 Io(){return(e,t,n)=>{let r=Fo(e);return(r?.kind===`task`?r.marker===`+`?Po():No():E({kind:`task`,marker:null,checked:!1}))(e,t,n)}}function Lo(){return s({cycleCheckableList:Io,wrapInCircleTask:No,wrapInSquareTask:Po})}function Ro(){return(e,t,n)=>{let r=Fo(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},E(a)(e,t,n)}}function zo(){return(e,t,n)=>{let r=Fo(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},E(a)(e,t,n)}}function Bo(e){return e.type.name===`list`&&e.attrs.kind===`bullet`&&e.childCount>=2&&e.firstChild?.type!==e.type}const Vo=e=>{let t=e.attrs;return t.kind===`task`?{...t,checked:!t.checked}:Bo(e)?{...t,collapsed:!t.collapsed}:t};function Ho(){return m(()=>[new y({props:{handleDOMEvents:{mousedown:(e,t)=>vt({view:e,event:t,onListClick:Vo})}}}),pt(),new y({props:{transformCopied:xt}}),mt()])}function Uo(){return s({toggleListCollapsed:()=>ht({isToggleable:Bo})})}function Wo(){return l({"Mod-Enter":Ro(),"Mod-Shift-Enter":zo(),"Mod-.":ht({isToggleable:Bo}),"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 Go(){return _(ut(),Ho(),lt(),st(),Oo(),ct(),Mo(),Wo(),Co(),wo(),Eo(),Lo(),Uo())}let Ko;function qo(){return Ko??=import(`katex`).then(e=>e.render),Ko}function Jo(e,t,n,r){try{e(n,t,{displayMode:r,throwOnError:!1,output:`mathml`})}catch(e){t.textContent=String(e)}}var Yo=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;qo().then(t=>{e===this.#r&&Jo(t,this.#n,e,!1)})}};function Xo(){return d({name:`mdMath`,constructor:(e,t)=>new Yo(e,t)})}function Zo(e){return e===`left`||e===`center`||e===`right`?e:null}function Qo(){return f({type:`tableCell`,attr:`align`,default:null,toDOM:e=>e?[`data-align`,e]:null,parseDOM:e=>Zo(e.getAttribute(`data-align`))})}function $o(){return f({type:`tableHeaderCell`,attr:`align`,default:null,toDOM:e=>e?[`data-align`,e]:null,parseDOM:e=>Zo(e.getAttribute(`data-align`))})}function es(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 ts(e){return e.child(es(e))}function ns(e,t){return t>=e.childCount?null:e.child(t).attrs.align??null}function rs(e,t,n){if(e.childCount===0)return;let r=ts(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=ns(r,e);(t.attrs.align??null)!==i&&n.setNodeMarkup(o,void 0,{...t.attrs,align:i}),o+=t.nodeSize}i+=a.nodeSize}}function is(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 as(){return new y({key:new b(`table-align-sync`),appendTransaction(e,t,n){if(!e.some(e=>e.docChanged))return;let r=is(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,rs(e,t,s),!1):!0),s?.docChanged?s:void 0}})}function os(){return m(as())}function ss(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 cs(e){return(t,n)=>{let r=ss(t);if(!r||r.table.childCount===0)return!1;if(n){let{table:i,tablePos:a,firstColumn:o,lastColumn:s}=r,c=es(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 ls(e){let t=ss(e);if(!(!t||t.table.childCount===0))return ns(ts(t.table),t.lastColumn)??void 0}function us(){return s({setTableColumnAlign:cs})}function ds(){return _(Qo(),$o(),os(),us())}function fs(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 ps=`paragraph`;function ms(){return _(p({name:`tableCell`,content:ps}),p({name:`tableHeaderCell`,content:ps}))}const hs=(e,t)=>{let{selection:n}=e;return!jt(n)||!n.isColSelection()||!n.isRowSelection()?!1:At(e,t)};function gs(){return v(l({Backspace:hs,Delete:hs}),t.high)}function _s(){return _(kt(),Ot(),Ct(),Dt(),ms(),ds(),Et({allowTableNodeSelection:!0}),wt(),Tt(),gs())}function vs(e){let{selection:t}=e,{$from:n,$to:r}=t;if(ae(t)&&n.depth===0||n.depth>0&&r.depth>0&&n.index(0)===r.index(0))return n.index(0)}function ys(e){return(t,n)=>{if(fs(t))return!1;let r=vs(t);if(r==null)return!1;let i=r+e;if(i<0||i>=t.doc.childCount)return!1;if(n){let{selection:a}=t,o=Math.min(r,i),s=a.$from.posAtIndex(o,0),c=t.doc.child(o),l=t.doc.child(o+1),u=t.tr.replaceWith(s,s+c.nodeSize+l.nodeSize,[l,c]),d=e===-1?-c.nodeSize:l.nodeSize,f=ae(a)?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 bs(e){return(t,n,r)=>dt(e)(t,n,r)||ys(e===`up`?-1:1)(t,n,r)}function xs(){return l({"Alt-ArrowUp":bs(`up`),"Alt-ArrowDown":bs(`down`)})}const K=new b(`meowdownPendingReplacement`);function q(e){return K.getState(e)?.pending??null}function Ss(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 Cs=new y({key:K,state:{init:()=>({pending:null}),apply:(e,t)=>{let n=e.getMeta(K);if(n)return Ss(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 ws(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 Ts(e){return(t,n)=>q(t)?(n?.(t.tr.setMeta(K,{type:`append`,text:e})),!0):!1}function Es(){return(e,t)=>q(e)?(t?.(e.tr.setMeta(K,{type:`discard`})),!0):!1}function Ds(e={}){return(t,n)=>{let r=q(t);if(!r||!r.text.trim())return!1;if(n){let i=e.mode??r.mode,a=lc(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 T(o.content,0,0)),s.setSelection(x.near(s.doc.resolve(s.mapping.map(r.to)),-1)))}n(s.scrollIntoView())}return!0}}function Os(){return s({startPendingReplacement:ws,appendPendingReplacementText:Ts,acceptPendingReplacement:Ds,discardPendingReplacement:Es})}function ks(){return l({"Mod-Enter":Ds(),Escape:Es()})}function As(){return _(m(Cs),Os(),ks())}function js(e){return m(new y({view:()=>({update:(t,n)=>{let r=K.getState(n),i=K.getState(t.state);!i||r===i||(i.pending?i.pending!==r?.pending&&e({type:`update`,pending:i.pending}):i.ended&&i.ended!==r?.ended&&e({type:`ended`,pending:i.ended.pending,outcome:i.ended.outcome}))}})}))}function Ms(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 Ms(r)?void 0:r}function Ns(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 Ps(e){let t=e.state,n=t.selection.head,r=z(t,n),i=B(t,n),a=r==null,o=[[n,a],[n,!a]];r!=null&&o.push([r.from,!0]),i!=null&&o.push([i.to,!1]);for(let[t,n]of o){let r=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 Fs(e){let t=e.state,n=t.selection.head;for(let r of Ut){let i=D(t,n,r);if(i==null||i.from!==n&&i.to!==n)continue;let a=Is(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 Is(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 Ls(e){return Ps(e)??Fs(e)}const Rs=new b(`meowdown-scroll-to-selection`);function zs(e){let t=e.state.selection;if(!g(t)||J(e,t.head,1)!=null)return!1;let n=Ls(e);if(n==null)return!1;let r=e.domAtPos(t.head).node;return Us(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 Bs(e){let t=e.assignedSlot??e.parentNode;return t?.nodeType===11?t.host:t}function Vs(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 Hs(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 Us(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=Bs(e);continue}let n=e,o=n===a.body,s=o?Vs(a):Hs(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:Bs(n)}}function Ws(){return m(new y({key:Rs,props:{handleScrollToSelection:zs}}))}function Gs(e,t){return(n,r)=>{let i=e<0?Ee.atStart(n.doc):Ee.atEnd(n.doc),a=t?x.between(n.selection.$anchor,i.$head):i;return n.selection.eq(a)||r?.(n.tr.setSelection(a).scrollIntoView()),!0}}function Ks(){return l({"Meta-ArrowUp":Gs(-1,!1),"Meta-ArrowDown":Gs(1,!1),"Shift-Meta-ArrowUp":Gs(-1,!0),"Shift-Meta-ArrowDown":Gs(1,!0)})}function qs(e){e.offsetWidth}const Js=new b(`meowdown-virtual-caret`),Ys=[`md-virtual-caret-blink`,`md-virtual-caret-blink2`];function Xs(e){let t=e.height*.19999999999999996;return{left:e.left,top:e.top-t/2,height:e.height+t}}function Zs(e){let t=Ns(e)??Ps(e);return t==null?Fs(e):Xs(t)}function Qs(e,t){return e==null||t==null?e===t:e.left===t.left&&e.top===t.top&&e.height===t.height}var $s=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=Ys[this.#s]}#l=()=>{let e=this.#e;if(e.isDestroyed)return;let t=e.state,n=t.selection,r=g(n)&&n.empty?Zs(e):void 0,i=r!=null&&k(t)===`hide`?$r(t,n.head):void 0;if(Qs(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&&(qs(this.#n),this.#n.style.transitionProperty=``)}};function ec(){return m(new y({key:Js,view:e=>new $s(e)}))}function tc(e){return _(Nn(),be(),Hr(),Ce(),ye(),Go(),kn(),_s(),Nr(),di(),fi(),Ga(),wr(),Vr(),xs(),Ks(),ka(e),co(),_o(),la(),Xo(),zt(e.markMode??`focus`),vr(),ec(),Ws(),li(),tn({marks:Ut.map(e=>({name:e,modes:[`hide`,`focus`,`show`]}))}),a(),i(),c(),xe(),we(),Se(),zr(),As())}function nc(e={}){return tc(e)}const rc=ve(()=>{let e=nc().schema;if(e==null)throw Error(`Unexpected empty schema`);return e}),ic=ve(()=>r(rc())),ac=ve(()=>n(rc())),oc=`meowdown_mark_builders`;function sc(e){let t=e.cached[oc];if(t)return t;let r=n(e);return e.cached[oc]=r,r}const cc=`meowdown_node_builders`;function lc(e){let t=e.cached[cc];if(t)return t;let n=r(e);return e.cached[cc]=n,n}function X(e,t={}){let{nodes:n=ic(),frontmatter:r=!1}=t,i,a=e;if(r){let[t,n]=dc(e);i=t,n&&(a=e.slice(n))}let o=fc(n,Ki.parse(a).cursor(),a);return n.doc(i===void 0?{}:{frontmatter:i},o)}const uc=/^---[ \t]*\r?\n([\s\S]*?\n)?---[ \t]*(?:\r?\n|$)/;function dc(e){let t=uc.exec(e);return t?[(t[1]??``).replace(/\r?\n$/,``),t[0].length]:[]}function fc(e,t,n){let r=[];if(!t.firstChild())return r;let i;do i!=null&&pc(r,e,n,i,t.from),i=t.to,r.push(...mc(e,t,n));while(t.nextSibling());return t.parent(),r}function pc(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 mc(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[bc(e,t,n)];case V.CommentBlock:return[xc(e,t,n)];case V.HTMLBlock:case V.ProcessingInstructionBlock:return[bc(e,t,n)];case V.Blockquote:return[Sc(e,t,n)];case V.BulletList:return Cc(e,t,n,`bullet`);case V.OrderedList:return Cc(e,t,n,`ordered`);case V.FencedCode:case V.CodeBlock:return[Tc(e,t,n)];case V.BlockMath:return[Ec(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[Dc(e,t,n)];case V.Task:return[bc(e,t,n)];default:return n.slice(t.from,t.to).trim()===``?[]:(console.warn(`[meowdown] unsupported lezer block "${t.type.name}"`),[bc(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=vc(n.slice(o,s),Q(n,o)).trim(),d=i?hc(n,c,l)||1:null,f=!i&&c>=0&&gc(n,c,l)||null;return e.heading({level:r,setextUnderline:d,closingHashes:f},u)}function hc(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 gc(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 _c(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 vc(e,t){return t===0||!e.includes(`
27
27
  `)?e:e.split(`
28
- `).map((e,n)=>n===0?e:uc(e,t)).join(`
29
- `)}function fc(e,t,n){return e.paragraph(dc(t,n))}function pc(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),fc(e,o,a)}return fc(e,n.slice(r,i),a)}function mc(e,t,n){let r=Q(n,t.from),i=dc(n.slice(t.from,t.to),r);return e.htmlComment({content:i})}function hc(e,t,n){let r=[];if(t.firstChild()){let i;do{if(t.type.id===V.QuoteMark)continue;i!=null&&oc(r,e,n,i,t.from),i=t.to,r.push(...sc(e,t,n))}while(t.nextSibling());t.parent()}return e.blockquote(r)}function gc(e,t,n,r){let i=[];if(t.firstChild()){do t.type.id===V.ListItem&&i.push(_c(e,t,n,r));while(t.nextSibling());t.parent()}return i}function _c(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(fc(e,c,Q(n,r)));continue}i.push(...sc(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 vc(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 yc(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 bc(e,t,n){let r=[];if(t.firstChild()){do t.type.id===V.TableDelimiter&&(r=xc(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(Sc(e,t,n,!0,r)):a===V.TableRow&&i.push(Sc(e,t,n,!1,r))}while(t.nextSibling());t.parent()}return e.table(i)}function xc(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 Sc(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 Cc(e){return e.replace(/\n+$/u,``)}function wc(e){return/^[\s>]*$/u.test(e)}function Tc(e){return e.split(`
30
- `).filter(e=>!wc(e))}function Ec(e){return e.trim().replaceAll(/\s+/gu,` `)}function Dc(e,t={}){let n=P(X(e,{frontmatter:t.frontmatter}),{frontmatter:t.frontmatter});if(Cc(n)===Cc(e))return`exact`;let r=Tc(e),i=Tc(n);return r.length===i.length&&r.every((e,t)=>Ec(e)===Ec(i[t]))?`normalizing`:`lossy`}const Oc=(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(b.create(s.doc,o+2)),t(s.scrollIntoView())}return!0};function kc(){return _(l({Enter:Oc}),t.high)}const Ac=new Set([`MscGen`,`Xù`,`MsGenny`,`Angular Template`,`Brainfuck`,`Esper`,`Oz`,`Factor`,`Squirrel`,`Yacas`,`mIRC`,`FCL`,`ECL`,`MUMPS`,`Pig`,`Asterisk`,`Z80`,`Mathematica`]),jc=He.map(e=>({label:e.name,value:e.name.toLowerCase()})).filter(e=>!Ac.has(e.label)).concat([{label:`Plain text`,value:``},{label:`Math`,value:`math`}]).sort((e,t)=>e.label.localeCompare(t.label));function Mc(){return typeof window>`u`?!1:window.matchMedia(`(prefers-color-scheme: dark)`).matches}const Nc=/^(?:www\.|mobile\.)?(?:twitter\.com|x\.com)$/i,Pc=/\/status(?:es)?\/(\d+)/;function Fc(e){let t;try{t=new URL(e)}catch{return}if(Nc.test(t.hostname))return Pc.exec(t.pathname)?.[1]}const Ic=e=>{let t=Fc(e);if(!t)return;let n=Mc()?`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 Lc(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 Rc=/^(?:www\.|m\.)?(?:youtube\.com|youtube-nocookie\.com)$/i,zc=/^(?:www\.)?youtu\.be$/i,Bc=/^[\w-]{11}$/;function Vc(e){let t;try{t=new URL(e)}catch{return}let n=null;if(zc.test(t.hostname))n=t.pathname.slice(1);else if(Rc.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||!Bc.test(n))return;let r=t.searchParams.get(`start`)??t.searchParams.get(`t`),i=r?Hc(r):void 0;return{videoId:n,startSeconds:i}}function Hc(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 Uc=[e=>{let t=Vc(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}},Ic];function Wc(e){for(let t of Uc){let n=t(e);if(n)return n}}function Gc(e,t){return e.clipboardData?.getData(`text/plain`)||t.content.textBetween(0,t.content.size,`
31
- `)}const Kc=new y(`meowdown-embed-paste`);function qc(e){let t=e.trim();if(!(!t||/\s/.test(t)))return Wc(t)?t:void 0}function Jc(e,t){let{from:n,to:r}=e.state.selection;e.dispatch(Nt(e.state.tr.insertText(t,n,r)));let i=e.state.tr.insertText(`![](${t})`,n,n+t.length);e.dispatch(Nt(i))}function Yc(){return m(new v({key:Kc,props:{handlePaste:(e,t,n)=>{let r=e.state.selection.$from.parent;if(!r.inlineContent||r.type.spec.code)return!1;let i=Gc(t,n);if(!i)return!1;let a=qc(i);return a?(Jc(e,a),!0):!1}}}))}const Xc=new y(`meowdown-exit-boundary`);function Zc(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&&De.findFrom(a,t))}function Qc(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:Zc(n,t)}function $c(e){return new v({key:Xc,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||Qc(t,r)||e({direction:r<0?`up`:`down`,event:n})===!1)}}})}function el(e){return _(m($c(e)),t.low)}function tl(e){return!!e.type?.startsWith(`image/`)}function nl(e,t){return tl(e)?`![](${t})`:`[${al(e.name)}](${t})`}function rl(e,t){return!e||!t.onFilePaste?[]:Array.from(e.files)}const il=e=>{console.error(`[meowdown] failed to save pasted file:`,e)};function al(e){return e.replaceAll(/[\\[\]]/g,String.raw`\$&`)}async function ol(e,t,n,r){let{onFilePaste:i}=n;if(!i)return;let a=n.onFileSaveError??il,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=nl(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 sl(e){return new v({key:new y(`file-paste`),props:{handlePaste:(t,n)=>{let r=rl(n.clipboardData,e);return r.length===0?!1:(ol(t,r,e),!0)},handleDrop:(t,n)=>{let r=rl(n.dataTransfer,e);return r.length===0?!1:(ol(t,r,e,t.posAtCoords({left:n.clientX,top:n.clientY})?.pos),!0)}}})}function cl(e={}){return _(m(sl(e)),t.high)}const ll=new y(`meowdown-file-click`);function ul(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 dl(e){return m(new v({key:ll,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=ul(t.state,t.posAtDOM(a,0));return o?(e({href:o.href,name:o.name,event:r}),!0):!1}}}))}const fl=[`KB`,`MB`,`GB`,`TB`];function pl(e){let t=e,n=`B`;for(let e of fl){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 ml=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 hl(e){let t=e.split(/[?#]/,1)[0],n=t.lastIndexOf(`.`);if(n<0)return`generic`;let r=t.slice(n+1).toLowerCase();return ml.get(r)??`generic`}const gl=`http://www.w3.org/2000/svg`;function _l(){let e=document.createElementNS(gl,`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(gl,`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 vl=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=hl(this.#a.href),this.#n.title=this.#a.name,this.#e.appendChild(this.#n),this.#n.appendChild(_l()),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=pl(n))}};function yl(e={}){return d({name:`mdFile`,constructor:t=>new vl(t,e)})}function bl(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 xl=new y(`meowdown-tag-click`);function Sl(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 Cl(e){return bl({key:xl,selector:`.md-tag`,preventDefault:!1,findPayloadAt:(e,t)=>Sl(e,t)?.tag,onClick:(t,n)=>e({tag:t,event:n})})}const wl=new y(`meowdown-wikilink-click`);function Tl(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 El(e,t){let n=t.closest(`.md-wikilink-view`)?.querySelector(`.md-wikilink-view-content`);if(n)return Tl(e.state,e.posAtDOM(n,0))}function Dl(e){return bl({key:wl,selector:`.md-wikilink-view-preview`,preventDefault:!1,findPayloadAt:(e,t)=>Tl(e,t)?.target,findPayloadForElement:(e,t)=>El(e,t)?.target,onClick:(t,n)=>e({target:t,event:n})})}const Ol=new y(`meowdown-follow-link`);function kl(e){return e.key!==`Enter`||e.shiftKey||e.altKey?!1:ie?e.metaKey&&!e.ctrlKey:e.ctrlKey&&!e.metaKey}function Al(e){return new v({key:Ol,props:{handleKeyDown:(t,n)=>{if(!kl(n))return!1;let{state:r}=t,i=r.selection.head,a=e.onWikilinkClick&&Tl(r,i);if(a)return e.onWikilinkClick?.({target:a.target,event:n}),!0;let o=e.onTagClick&&Sl(r,i);if(o)return e.onTagClick?.({tag:o.tag,event:n}),!0;let s=e.onFileClick&&ul(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 jl(e){return _(m(Al(e)),t.high)}const Ml=new y(`meowdown-image-click`);function Nl(e){return e instanceof HTMLElement&&e.closest(`.md-image-view-preview`)}function Pl(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 Fl(e,t){let n=t.closest(`.md-image-view`)?.querySelector(`.md-image-view-content`);if(n)return Pl(e.state,e.posAtDOM(n,0))}function Il(e,t){return Array.from(e).find(e=>e.identifier===t)}function Ll(e,t){return Math.abs(t.clientX-e.clientX)<=10&&Math.abs(t.clientY-e.clientY)<=10}function Rl(e){let t=new WeakMap;return m(new v({key:Ml,props:{handleDOMEvents:{pointerdown:(e,t)=>(Nl(t.target)&&t.pointerType!==`mouse`&&t.preventDefault(),!1),touchstart:(e,n)=>{if(t.delete(e),n.touches.length!==1||!Nl(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=Il(n.changedTouches,r.identifier);return i&&!Ll(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=Il(r.changedTouches,i.identifier);if(!a||!Ll(i,a))return!1;let o=Nl(r.target);if(!o)return!1;r.preventDefault();let s=Fl(n,o);return s&&e({src:s.src,alt:s.alt,event:r}),!0}},handleClick:(t,n,r)=>{let i=Nl(r.target);if(!i)return!1;let a=Fl(t,i);return a?(e({src:a.src,alt:a.alt,event:r}),!0):!1}}}))}function zl(e){return/^https?:\/\//i.test(e)?e:void 0}function Bl(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`&&Lc(t),t}function Vl(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 Hl(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=ea(o),c=a.from+s.length,l=o.slice(s.length),u=$i({...Zi(l)??{},width:Math.round(n),height:Math.round(r)});u!==l&&e.dispatch(e.state.tr.insertText(u,c,a.to))}var Ul=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)&&Vl(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=Wc(e);if(t){let e=document.createElement(`span`);return e.className=`md-image-view-preview md-atom-view-preview`,e.appendChild(Bl(t)),e}let n=(this.#n.resolveImageUrl??zl)(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){Ft(),Pt();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,Vl(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)),Vl(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;Hl(this.#r,this.#t,t,n)}),this.#a=t,this.#o=n,t}};function Wl(e={}){return d({name:`mdImage`,constructor:(t,n)=>new Ul(t,n,e)})}const Gl={"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`},Kl=new y(`meowdown-link-click`);function ql(e){return bl({key:Kl,selector:`.md-link`,preventDefault:!0,findPayloadAt:(e,t)=>G(e,t)?.href,onClick:(t,n)=>e({href:t,event:n})})}function Jl(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 Yl=new y(`meowdown-link-hover`);function Xl(e){return Jl({key:Yl,selector:`.md-link`,findPayloadAt:(e,t)=>G(e,t),isSamePayload:(e,t)=>e.href===t.href&&e.title===t.title,onHoverChange:e})}const Zl=new y(`meowdown-link-paste`);function Ql(e){let t=e.trim();if(!(!t||/\s/.test(t)))return Si(t)}function $l(){return _(m(new v({key:Zl,props:{handlePaste:(e,t,n)=>{let r=Gc(t,n);if(!r)return!1;let i=Ql(r);return i?Wr(e,oo({href:i,wrapText:!1})):!1}}})),t.high)}const eu=[[/<-/,`←`],[/(?<!-)->/,`→`],[/\(c\)/,`©`],[/\(r\)/,`®`],[/1\/2/,`½`],[/\+\/-/,`±`],[/!=/,`≠`],[/<</,`«`],[/>>/,`»`],[/(?<!<!)(?<!^(?:-[ \t]*)+)--/,`—`]],$=new y(`meowdown-substitution-undo`);function tu(e,t,n){let r=te(e.schema,`mdCode`);return e.doc.rangeHasMark(t,n,r)}function nu(e,t,n,r,i){if(tu(e,t,n))return null;let[,a]=r,o=i==null?a:`${a} `,s=e.tr.replaceWith(t,n,e.schema.text(o));return i!=null&&s.setMeta($,{from:t,to:t+o.length,before:i,after:o}),s}function ru(){return g(eu.map(e=>Je(new It(new RegExp(String.raw`(?:${e[0].source})\s$`),(t,n,r,i)=>nu(t,r,i,e,n[0])))))}function iu(){return m(new v({key:$,state:{init:()=>null,apply:(e,t)=>{let n=e.getMeta($);if(n!==void 0)return n;if(!t)return null;let r=e.mapping.map(t.from),i=e.mapping.map(t.to);return e.selection.empty&&e.selection.from===i&&e.doc.textBetween(r,i)===t.after?{...t,from:r,to:i}:null}}}))}function au(){return _(l({Backspace:(e,t)=>{let n=$.getState(e);return n?(t?.(e.tr.replaceWith(n.from,n.to,e.schema.text(n.before)).setMeta($,null)),!0):!1}}),t.highest)}function ou(){return g(iu(),au())}function su(){return g(eu.map(e=>Ke({regex:RegExp(`(?:${e[0].source})$`),handler:({state:t,from:n,to:r})=>nu(t,n,r,e)})))}function cu(){return g(ru(),ou(),su())}const lu=new y(`meowdown-wikilink-hover`);function uu(e){return Jl({key:lu,selector:`.md-wikilink-view-preview`,findPayloadAt:Tl,findPayloadForElement:El,isSamePayload:(e,t)=>e.target===t.target,onHoverChange:t=>{e(t?{...t.payload,element:t.element}:void 0)}})}const du=new Set([`mdMark`,`mdLinkUri`,`mdLinkTitle`]);function fu(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=>du.has(e))&&!(t.preserveMathSource&&n.includes(`mdMath`))||r.push(e.text),!1}),n.push(r.join(``))}),n.join(`
32
- `)}function pu({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=fu(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(b.create(e.doc,r.from+a.length)),Xe(e),n(e.scrollIntoView())}return!0}}function mu(){return l({"Mod-Shift-k":pu({allowEmpty:!0}),"[":pu({allowEmpty:!1})})}function hu(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,`
28
+ `).map((e,n)=>n===0?e:_c(e,t)).join(`
29
+ `)}function yc(e,t,n){return e.paragraph(vc(t,n))}function bc(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,P(n.charCodeAt(s))&&(s+=1));while(t.nextSibling());return t.parent(),o+=n.slice(s,i),yc(e,o,a)}return yc(e,n.slice(r,i),a)}function xc(e,t,n){let r=Q(n,t.from),i=vc(n.slice(t.from,t.to),r);return e.htmlComment({content:i})}function Sc(e,t,n){let r=[];if(t.firstChild()){let i;do{if(t.type.id===V.QuoteMark)continue;i!=null&&pc(r,e,n,i,t.from),i=t.to,r.push(...mc(e,t,n))}while(t.nextSibling());t.parent()}return e.blockquote(r)}function Cc(e,t,n,r){let i=[];if(t.firstChild()){do t.type.id===V.ListItem&&i.push(wc(e,t,n,r));while(t.nextSibling());t.parent()}return i}function wc(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()}P(n.charCodeAt(r))&&(r+=1);let c=n.slice(r,s);i.push(yc(e,c,Q(n,r)));continue}i.push(...mc(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 Tc(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 Ec(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 Dc(e,t,n){let r=[];if(t.firstChild()){do t.type.id===V.TableDelimiter&&(r=Oc(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(kc(e,t,n,!0,r)):a===V.TableRow&&i.push(kc(e,t,n,!1,r))}while(t.nextSibling());t.parent()}return e.table(i)}function Oc(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 kc(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 Ac(e){return e.replace(/\n+$/u,``)}function jc(e){return/^[\s>]*$/u.test(e)}function Mc(e){return e.split(`
30
+ `).filter(e=>!jc(e))}function Nc(e){return e.trim().replaceAll(/\s+/gu,` `)}function Pc(e,t={}){let n=F(X(e,{frontmatter:t.frontmatter}),{frontmatter:t.frontmatter});if(Ac(n)===Ac(e))return`exact`;let r=Mc(e),i=Mc(n);return r.length===i.length&&r.every((e,t)=>Nc(e)===Nc(i[t]))?`normalizing`:`lossy`}const Fc=(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=te(e.schema,`list`),i=te(e.schema,`paragraph`),a=r.create({kind:`bullet`},i.create()),o=n.after(),s=e.tr.insert(o,a);s.setSelection(x.create(s.doc,o+2)),t(s.scrollIntoView())}return!0};function Ic(){return v(l({Enter:Fc}),t.high)}const Lc=new Set([`MscGen`,`Xù`,`MsGenny`,`Angular Template`,`Brainfuck`,`Esper`,`Oz`,`Factor`,`Squirrel`,`Yacas`,`mIRC`,`FCL`,`ECL`,`MUMPS`,`Pig`,`Asterisk`,`Z80`,`Mathematica`]),Rc=Ve.map(e=>({label:e.name,value:e.name.toLowerCase()})).filter(e=>!Lc.has(e.label)).concat([{label:`Plain text`,value:``},{label:`Math`,value:`math`}]).sort((e,t)=>e.label.localeCompare(t.label));function zc(){return typeof window>`u`?!1:window.matchMedia(`(prefers-color-scheme: dark)`).matches}const Bc=/^(?:www\.|mobile\.)?(?:twitter\.com|x\.com)$/i,Vc=/\/status(?:es)?\/(\d+)/;function Hc(e){let t;try{t=new URL(e)}catch{return}if(Bc.test(t.hostname))return Vc.exec(t.pathname)?.[1]}const Uc=e=>{let t=Hc(e);if(!t)return;let n=zc()?`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 Wc(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 Gc=/^(?:www\.|m\.)?(?:youtube\.com|youtube-nocookie\.com)$/i,Kc=/^(?:www\.)?youtu\.be$/i,qc=/^[\w-]{11}$/;function Jc(e){let t;try{t=new URL(e)}catch{return}let n=null;if(Kc.test(t.hostname))n=t.pathname.slice(1);else if(Gc.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||!qc.test(n))return;let r=t.searchParams.get(`start`)??t.searchParams.get(`t`),i=r?Yc(r):void 0;return{videoId:n,startSeconds:i}}function Yc(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 Xc=[e=>{let t=Jc(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}},Uc];function Zc(e){for(let t of Xc){let n=t(e);if(n)return n}}function Qc(e,t){return e.clipboardData?.getData(`text/plain`)||t.content.textBetween(0,t.content.size,`
31
+ `)}const $c=new b(`meowdown-embed-paste`);function el(e){let t=e.trim();if(!(!t||/\s/.test(t)))return Zc(t)?t:void 0}function tl(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 nl(){return m(new y({key:$c,props:{handlePaste:(e,t,n)=>{let r=e.state.selection.$from.parent;if(!r.inlineContent||r.type.spec.code)return!1;let i=Qc(t,n);if(!i)return!1;let a=el(i);return a?(tl(e,a),!0):!1}}}))}const rl=new b(`meowdown-exit-boundary`);function il(e,t){let{$anchor:n,$head:r}=e.selection,i=t>0?n.max(r):n.min(r),a=i.parent.inlineContent?i.depth?e.doc.resolve(t>0?i.after():i.before()):void 0:i;return!!(a&&Ee.findFrom(a,t))}function al(e,t){let{state:n}=e,{selection:r}=n;return g(r)&&!r.empty||ne(r)||r.$from.parent.inlineContent&&!e.endOfTextblock(t<0?`up`:`down`)?!0:il(n,t)}function ol(e){return new y({key:rl,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||al(t,r)||e({direction:r<0?`up`:`down`,event:n})===!1)}}})}function sl(e){return v(m(ol(e)),t.low)}const cl=new Set([`avif`,`bmp`,`gif`,`jpeg`,`jpg`,`png`,`svg`,`webp`]);function ll(e){if(e.type?.startsWith(`image/`))return!0;let t=e.name.lastIndexOf(`.`);if(t===-1)return!1;let n=e.name.slice(t+1).toLowerCase();return cl.has(n)}function ul(e,t){return ll(e)?`![](${t})`:`[${pl(e.name)}](${t})`}function dl(e,t){return!e||!t.onFilePaste?[]:Array.from(e.files)}const fl=e=>{console.error(`[meowdown] failed to save pasted file:`,e)};function pl(e){return e.replaceAll(/[\\[\]]/g,String.raw`\$&`)}async function ml(e,t,n,r){let{onFilePaste:i}=n;if(!i)return;let a=n.onFileSaveError??fl,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=ul(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 hl(e){return new y({key:new b(`file-paste`),props:{handlePaste:(t,n)=>{let r=dl(n.clipboardData,e);return r.length===0?!1:(ml(t,r,e),!0)},handleDrop:(t,n)=>{let r=dl(n.dataTransfer,e);return r.length===0?!1:(ml(t,r,e,t.posAtCoords({left:n.clientX,top:n.clientY})?.pos),!0)}}})}function gl(e={}){return v(m(hl(e)),t.high)}const _l=new b(`meowdown-file-click`);function vl(e,t){let n=D(e,t,`mdFile`);if(!n)return;let{href:r,name:i}=n.mark.attrs;return{href:r,name:i}}function yl(e){return m(new y({key:_l,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=vl(t.state,t.posAtDOM(a,0));return o?(e({href:o.href,name:o.name,event:r}),!0):!1}}}))}const bl=[`KB`,`MB`,`GB`,`TB`];function xl(e){let t=e,n=`B`;for(let e of bl){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 Sl=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 Cl(e){let t=e.split(/[?#]/,1)[0],n=t.lastIndexOf(`.`);if(n<0)return`generic`;let r=t.slice(n+1).toLowerCase();return Sl.get(r)??`generic`}const wl=`http://www.w3.org/2000/svg`;function Tl(){let e=document.createElementNS(wl,`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(wl,`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 El=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=Cl(this.#a.href),this.#n.title=this.#a.name,this.#e.appendChild(this.#n),this.#n.appendChild(Tl()),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=xl(n))}};function Dl(e={}){return d({name:`mdFile`,constructor:t=>new El(t,e)})}function Ol(e){return m(new y({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 kl=new b(`meowdown-tag-click`);function Al(e,t){let n=D(e,t,`mdTag`);if(!n)return;let r=e.doc.textBetween(n.from,n.to),i=r.startsWith(`#`)?r.slice(1):r;return{from:n.from,to:n.to,tag:i}}function jl(e){return Ol({key:kl,selector:`.md-tag`,preventDefault:!1,findPayloadAt:(e,t)=>Al(e,t)?.tag,onClick:(t,n)=>e({tag:t,event:n})})}const Ml=new b(`meowdown-wikilink-click`);function Nl(e,t){let n=D(e,t,`mdWikilink`);if(!n)return;let{target:r}=n.mark.attrs;return{from:n.from,to:n.to,target:r}}function Pl(e,t){let n=t.closest(`.md-wikilink-view`)?.querySelector(`.md-wikilink-view-content`);if(n)return Nl(e.state,e.posAtDOM(n,0))}function Fl(e){return Ol({key:Ml,selector:`.md-wikilink-view-preview`,preventDefault:!1,findPayloadAt:(e,t)=>Nl(e,t)?.target,findPayloadForElement:(e,t)=>Pl(e,t)?.target,onClick:(t,n)=>e({target:t,event:n})})}const Il=new b(`meowdown-follow-link`);function Ll(e){return e.key!==`Enter`||e.shiftKey||e.altKey?!1:re?e.metaKey&&!e.ctrlKey:e.ctrlKey&&!e.metaKey}function Rl(e){return new y({key:Il,props:{handleKeyDown:(t,n)=>{if(!Ll(n))return!1;let{state:r}=t,i=r.selection.head,a=e.onWikilinkClick&&Nl(r,i);if(a)return e.onWikilinkClick?.({target:a.target,event:n}),!0;let o=e.onTagClick&&Al(r,i);if(o)return e.onTagClick?.({tag:o.tag,event:n}),!0;let s=e.onFileClick&&vl(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 zl(e){return v(m(Rl(e)),t.high)}const Bl=new b(`meowdown-image-click`);function Vl(e){return e instanceof HTMLElement&&e.closest(`.md-image-view-preview`)}function Hl(e,t){let n=D(e,t,`mdImage`);if(!n)return;let{src:r,alt:i}=n.mark.attrs;return{from:n.from,to:n.to,src:r,alt:i}}function Ul(e,t){let n=t.closest(`.md-image-view`)?.querySelector(`.md-image-view-content`);if(n)return Hl(e.state,e.posAtDOM(n,0))}function Wl(e,t){return Array.from(e).find(e=>e.identifier===t)}function Gl(e,t){return Math.abs(t.clientX-e.clientX)<=10&&Math.abs(t.clientY-e.clientY)<=10}function Kl(e){let t=new WeakMap;return m(new y({key:Bl,props:{handleDOMEvents:{pointerdown:(e,t)=>(Vl(t.target)&&t.pointerType!==`mouse`&&t.preventDefault(),!1),touchstart:(e,n)=>{if(t.delete(e),n.touches.length!==1||!Vl(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=Wl(n.changedTouches,r.identifier);return i&&!Gl(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=Wl(r.changedTouches,i.identifier);if(!a||!Gl(i,a))return!1;let o=Vl(r.target);if(!o)return!1;r.preventDefault();let s=Ul(n,o);return s&&e({src:s.src,alt:s.alt,event:r}),!0}},handleClick:(t,n,r)=>{let i=Vl(r.target);if(!i)return!1;let a=Ul(t,i);return a?(e({src:a.src,alt:a.alt,event:r}),!0):!1}}}))}function ql(e){return/^https?:\/\//i.test(e)?e:void 0}function Jl(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`&&Wc(t),t}function Yl(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 Xl(e,t,n,r){let i=e.posAtDOM(t,0),a=D(e.state,i,`mdImage`);if(!a)return;let o=e.state.doc.textBetween(a.from,a.to),s=a.mark.attrs;if(s.syntax===`wikiEmbed`){let t=s.wikiTarget||ia(o).target;if(!t)return;let i=aa(t,n,r);i!==o&&e.dispatch(e.state.tr.insertText(i,a.from,a.to));return}let c=ta(o),l=a.from+c.length,u=o.slice(c.length),d=ea({...Qi(u)??{},width:Math.round(n),height:Math.round(r)});d!==u&&e.dispatch(e.state.tr.insertText(d,l,a.to))}var Zl=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)&&Yl(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=Zc(e);if(t){let e=document.createElement(`span`);return e.className=`md-image-view-preview md-atom-view-preview`,e.appendChild(Jl(t)),e}let n=(this.#n.resolveImageUrl??ql)(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,Yl(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)),Yl(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;Xl(this.#r,this.#t,t,n)}),this.#a=t,this.#o=n,t}};function Ql(e={}){return d({name:`mdImage`,constructor:(t,n)=>new Zl(t,n,e)})}const $l={"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`},eu=new b(`meowdown-link-click`);function tu(e){return Ol({key:eu,selector:`.md-link`,preventDefault:!0,findPayloadAt:(e,t)=>G(e,t)?.href,onClick:(t,n)=>e({href:t,event:n})})}function nu(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||!ge(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 y({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 ru=new b(`meowdown-link-hover`);function iu(e){return nu({key:ru,selector:`.md-link`,findPayloadAt:(e,t)=>G(e,t),isSamePayload:(e,t)=>e.href===t.href&&e.title===t.title,onHoverChange:e})}const au=new b(`meowdown-link-paste`);function ou(e){let t=e.trim();if(!(!t||/\s/.test(t)))return Si(t)}function su(){return v(m(new y({key:au,props:{handlePaste:(e,t,n)=>{let r=Qc(t,n);if(!r)return!1;let i=ou(r);return i?Ur(e,mo({href:i,wrapText:!1})):!1}}})),t.high)}const cu=[[/<-/,`←`],[/(?<!-)->/,`→`],[/\(c\)/,`©`],[/\(r\)/,`®`],[/1\/2/,`½`],[/\+\/-/,`±`],[/!=/,`≠`],[/<</,`«`],[/>>/,`»`],[/(?<!<!)(?<!^(?:-[ \t]*)+)--/,`—`]],$=new b(`meowdown-substitution-undo`);function lu(e,t,n){let r=ee(e.schema,`mdCode`);return e.doc.rangeHasMark(t,n,r)}function uu(e,t,n,r,i){if(lu(e,t,n))return null;let[,a]=r,o=i==null?a:`${a} `,s=e.tr.replaceWith(t,n,e.schema.text(o));return i!=null&&s.setMeta($,{from:t,to:t+o.length,before:i,after:o}),s}function du(){return _(cu.map(e=>qe(new Ft(new RegExp(String.raw`(?:${e[0].source})\s$`),(t,n,r,i)=>uu(t,r,i,e,n[0])))))}function fu(){return m(new y({key:$,state:{init:()=>null,apply:(e,t)=>{let n=e.getMeta($);if(n!==void 0)return n;if(!t)return null;let r=e.mapping.map(t.from),i=e.mapping.map(t.to);return e.selection.empty&&e.selection.from===i&&e.doc.textBetween(r,i)===t.after?{...t,from:r,to:i}:null}}}))}function pu(){return v(l({Backspace:(e,t)=>{let n=$.getState(e);return n?(t?.(e.tr.replaceWith(n.from,n.to,e.schema.text(n.before)).setMeta($,null)),!0):!1}}),t.highest)}function mu(){return _(fu(),pu())}function hu(){return _(cu.map(e=>Ge({regex:RegExp(`(?:${e[0].source})$`),handler:({state:t,from:n,to:r})=>uu(t,n,r,e)})))}function gu(){return _(du(),mu(),hu())}const _u=new b(`meowdown-wikilink-hover`);function vu(e){return nu({key:_u,selector:`.md-wikilink-view-preview`,findPayloadAt:Nl,findPayloadForElement:Pl,isSamePayload:(e,t)=>e.target===t.target,onHoverChange:t=>{e(t?{...t.payload,element:t.element}:void 0)}})}const yu=new Set([`mdMark`,`mdLinkUri`,`mdLinkTitle`]);function bu(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=>yu.has(e))&&!(t.preserveMathSource&&n.includes(`mdMath`))||r.push(e.text),!1}),n.push(r.join(``))}),n.join(`
32
+ `)}function xu({allowEmpty:e}){return(t,n)=>{let{selection:r}=t;if(!g(r)||!e&&r.empty||!r.$head.sameParent(r.$anchor)||r.$head.parent.type.spec.code)return!1;let i=bu(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 Su(){return l({"Mod-Shift-k":xu({allowEmpty:!0}),"[":xu({allowEmpty:!1})})}function Cu(e){let{selection:t,schema:n}=e;if(t.empty)return``;let r=t.content().content;try{return F(n.topNodeType.create(null,r)).replace(/\n+$/,``)}catch{return e.doc.textBetween(t.from,t.to,`
33
33
 
34
- `)}}function gu(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 _u(e){return e instanceof Qe||e instanceof $e||e instanceof et||e instanceof tt||e instanceof gi}function vu(e){for(let t of e)for(let e of t.steps)if(!_u(e))return!0;return!1}function yu(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){vu(e)&&o()},view(e){return t=e,{destroy(){t=void 0}}}}}function bu(e){let t=new y(`spell-check`);return new v({key:t,state:{init:()=>yu(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 xu(e){return m(bu(e))}export{Gl as EDITOR_KEY_BINDINGS,e as Priority,nl as buildFileMarkdown,Dc as checkRoundTrip,jc as codeBlockLanguages,zl as defaultResolveImageUrl,kc as defineBulletAfterHeading,pe as defineCodeBlockPreviewPlugin,Tr as defineCodeBlockSyntaxHighlight,Ys as defineEditorExtension,Yc as defineEmbedPaste,el as defineExitBoundaryHandler,dl as defineFileClickHandler,cl as defineFilePaste,yl as defineFileView,jl as defineFollowLinkHandler,fi as defineHTMLComment,Wl as defineImage,Rl as defineImageClickHandler,ql as defineLinkClickHandler,lo as defineLinkCommands,fo as defineLinkEditKeymap,Xl as defineLinkHoverHandler,$l as defineLinkPaste,Uo as defineMath,ws as definePendingReplacementHandler,he as definePlaceholder,ge as defineReadonly,xu as defineSpellCheckPlugin,cu as defineSubstitution,Cl as defineTagClickHandler,Dl as defineWikilinkClickHandler,uu as defineWikilinkHoverHandler,mu as defineWikilinkTrigger,P as docToMarkdown,Dr as getCodeTokens,G as getLinkUnitAt,Qs as getMarkBuilders,q as getPendingReplacement,hu as getSelectedText,ns as getTableColumnAlign,gu as getVirtualElementFromRange,aa as inlineTextToMarkChunks,oo as insertLink,me as isCodeBlockPreviewHiddenDecoration,as as isSelectionInTableCell,Lc as listenForTweetHeight,Bo as loadKaTeX,X as markdownToDoc,Wc as matchEmbed,co as removeLink,Vo as renderMathInto,so as updateLink,le as withPriority};
34
+ `)}}function wu(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 Tu(e){return e instanceof Ze||e instanceof Qe||e instanceof $e||e instanceof et||e instanceof gi}function Eu(e){for(let t of e)for(let e of t.steps)if(!Tu(e))return!0;return!1}function Du(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){Eu(e)&&o()},view(e){return t=e,{destroy(){t=void 0}}}}}function Ou(e){let t=new b(`spell-check`);return new y({key:t,state:{init:()=>Du(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 ku(e){return m(Ou(e))}export{$l as EDITOR_KEY_BINDINGS,e as Priority,ul as buildFileMarkdown,Pc as checkRoundTrip,Rc as codeBlockLanguages,ql as defaultResolveImageUrl,Ic as defineBulletAfterHeading,fe as defineCodeBlockPreviewPlugin,wr as defineCodeBlockSyntaxHighlight,nc as defineEditorExtension,nl as defineEmbedPaste,sl as defineExitBoundaryHandler,yl as defineFileClickHandler,gl as defineFilePaste,Dl as defineFileView,zl as defineFollowLinkHandler,fi as defineHTMLComment,Ql as defineImage,Kl as defineImageClickHandler,tu as defineLinkClickHandler,_o as defineLinkCommands,yo as defineLinkEditKeymap,iu as defineLinkHoverHandler,su as defineLinkPaste,Xo as defineMath,js as definePendingReplacementHandler,me as definePlaceholder,he as defineReadonly,ku as defineSpellCheckPlugin,gu as defineSubstitution,jl as defineTagClickHandler,Fl as defineWikilinkClickHandler,vu as defineWikilinkHoverHandler,Su as defineWikilinkTrigger,F as docToMarkdown,xl as formatFileSize,aa as formatSizedWikiEmbed,Er as getCodeTokens,Cl as getFileKind,G as getLinkUnitAt,ac as getMarkBuilders,q as getPendingReplacement,Cu as getSelectedText,ls as getTableColumnAlign,wu as getVirtualElementFromRange,da as inlineTextToMarkChunks,mo as insertLink,pe as isCodeBlockPreviewHiddenDecoration,fs as isSelectionInTableCell,Wc as listenForTweetHeight,qo as loadKaTeX,X as markdownToDoc,Zc as matchEmbed,ia as parseWikiEmbed,go as removeLink,Jo as renderMathInto,ho as updateLink,oa as wikiEmbedBasename,ce as withPriority};
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@meowdown/core",
3
3
  "type": "module",
4
- "version": "0.48.0",
4
+ "version": "0.49.0",
5
5
  "license": "MIT",
6
6
  "repository": {
7
7
  "type": "git",