@meowdown/core 0.57.2 → 0.58.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +9 -4
- package/dist/index.d.ts +26 -3
- package/dist/index.js +23 -23
- package/package.json +4 -2
package/README.md
CHANGED
|
@@ -37,7 +37,10 @@ const markdown = docToMarkdown(editor.state.doc)
|
|
|
37
37
|
- Indented code blocks (four leading spaces)
|
|
38
38
|
- Thematic breaks (`---`, `***`, `___`)
|
|
39
39
|
- Bold (`**bold**`), italic (`*italic*`), and inline code
|
|
40
|
-
-
|
|
40
|
+
- Inline and reference links (`[text](url)`, `[text][label]`, `[label][]`, `[label]`)
|
|
41
|
+
- Inline and reference images (``, `![alt][label]`)
|
|
42
|
+
- Link reference definitions (`[label]: url "title"`)
|
|
43
|
+
- Autolinks (`<https://example.com>`)
|
|
41
44
|
- Hard line breaks
|
|
42
45
|
- GitHub Flavored Markdown (GFM)
|
|
43
46
|
- Tables, including column alignment (`:--`, `:-:`, `--:`)
|
|
@@ -114,15 +117,17 @@ Tags (`#tag`) render as pills via the `.md-tag` class, tinted from `--meowdown-a
|
|
|
114
117
|
|
|
115
118
|
Wikilinks (`[[target]]`/`[[target|alias]]`) render in place via a mark view as an immutable label (the alias, or the target when there is no alias), with the raw source hidden in hide and focus modes and shown dimmed in show mode. The label uses the `.md-wikilink-view-label` class, dashed-underlined and colored by `--meowdown-accent`. In every mark mode the link is a single immutable caret stop: arrowing onto it selects the whole source (ringed with `--meowdown-node-outline` in hide and focus, the native selection over the visible source in show), and Backspace/Delete remove it as a unit. Wire click navigation with `defineWikilinkClickHandler(({ target, event }) => ...)` (or `@meowdown/react`'s `onWikilinkClick` prop); `Mod-Enter` with the caret on a wikilink, tag, or Markdown link fires the same handler, with the `KeyboardEvent` as `event`. `defineWikilinkHoverHandler` reports the hovered target, source range, and visible anchor element, then reports `undefined` on leave, deletion, replacement, or editor teardown.
|
|
116
119
|
|
|
117
|
-
Markdown links
|
|
120
|
+
Markdown links render the label as an `<a href>` with the `.md-link` class, colored by `--meowdown-accent`; the source syntax dims in show mode and hides in hide and focus modes. This includes inline links (`[text](url)`), full references (`[text][label]`), collapsed references (`[label][]`), and shortcut references (`[label]`). Definitions use CommonMark label normalization and first-definition-wins semantics. Definitions remain visible and editable as literal source in the editor, while unresolved references remain literal and preserve nested formatting. Reference destinations are read-only through the link commands and menu because editing one safely requires a definition-aware workflow. Citing links update after a 200 ms pause in definition editing, which coalesces large fan-out restyles; definition-shaped textblocks longer than 1,024 characters stay literal and are not indexed. `[[target]]` continues to use meowdown's wikilink syntax. Wire click handling with `defineLinkClickHandler(({ href, event }) => ...)` (or `@meowdown/react`'s `onLinkClick` prop).
|
|
121
|
+
|
|
122
|
+
Low-level renderers can import `collectReferenceDefinitions` and `inlineTextToMarkChunksWithContext` directly from `@meowdown/core` to share the editor's definition collection and reference resolution.
|
|
118
123
|
|
|
119
124
|
Bare URLs autolink without `[text](url)` brackets and share the same `.md-link` rendering and click handling: a scheme URL (`https://example.com`), an angle autolink (`<https://example.com>`), a `www.` host (`www.example.com`), an email (`me@example.com`), and a bare domain (`google.com`, `sub.domain.io/path`). Bare domains are matched against a curated list of common TLDs, so file names and prose keep their dots without linkifying (`README.md`, `node.js`, `i.e.` stay plain text); reach for `[text](url)` or `<url>` to link anything off that list. Autolinks are derived live from the text, so editing one re-evaluates it; the caret sitting inside a link never un-links it.
|
|
120
125
|
|
|
121
|
-
Inline images (``) stay literal text and render in place via a mark view, with
|
|
126
|
+
Inline and reference images (``, `![alt][label]`, `![label][]`, and `![label]`) stay literal text and render in place via a mark view, with their raw source hidden in hide and focus modes. Add an inline image with [`defineImage`](https://npmx.dev/package-docs/@meowdown%2Fcore#function-defineImage) (or `@meowdown/react`'s image props) and wire click handling with [`defineImageClickHandler`](https://npmx.dev/package-docs/@meowdown%2Fcore#function-defineImageClickHandler) (`@meowdown/react`'s `onImageClick` prop).
|
|
122
127
|
|
|
123
128
|
Pasted or dropped files persist through [`defineFilePaste`](https://npmx.dev/package-docs/@meowdown%2Fcore#function-defineFilePaste) (or `@meowdown/react`'s `onFilePaste` prop): the handler persists each file and returns its markdown destination. An image (`image/*` MIME type) inserts ``; any other file inserts a `[name](src)` link; multiple files insert one link per line, in the order they appear in the drop. Without `onFilePaste`, file events are left to the browser's default handling. A host command that inserts file links itself (e.g. an attach-file picker) can build the same markdown with [`buildFileMarkdown`](https://npmx.dev/package-docs/@meowdown%2Fcore#function-buildFileMarkdown).
|
|
124
129
|
|
|
125
|
-
A host can render chosen file links as inline **file pills**: pass `resolveFileLink` to [`defineEditorExtension`](https://npmx.dev/package-docs/@meowdown%2Fcore#function-defineEditorExtension) (or `@meowdown/react`'s `resolveFileLink` prop) to claim links by their href (e.g. everything under `assets/`), and add [`defineFileView`](https://npmx.dev/package-docs/@meowdown%2Fcore#function-defineFileView) to render each claimed link as a pill: a file-kind icon, the name, and the size supplied (possibly async) by `resolveFileInfo`. The markdown text is untouched, and a claimed link behaves like an image: one caret unit with an editable source, clicks (and `Mod-Enter` with the caret on it) reported through [`defineFileClickHandler`](https://npmx.dev/package-docs/@meowdown%2Fcore#function-defineFileClickHandler) (`@meowdown/react`'s `onFileClick`) rather than the link click handler, and no link hover or edit menu.
|
|
130
|
+
A host can render chosen file links as inline **file pills**: pass `resolveFileLink` to [`defineEditorExtension`](https://npmx.dev/package-docs/@meowdown%2Fcore#function-defineEditorExtension) (or `@meowdown/react`'s `resolveFileLink` prop) to claim inline or resolved reference links by their href (e.g. everything under `assets/`), and add [`defineFileView`](https://npmx.dev/package-docs/@meowdown%2Fcore#function-defineFileView) to render each claimed link as a pill: a file-kind icon, the name, and the size supplied (possibly async) by `resolveFileInfo`. The markdown text is untouched, and a claimed link behaves like an image: one caret unit with an editable source, clicks (and `Mod-Enter` with the caret on it) reported through [`defineFileClickHandler`](https://npmx.dev/package-docs/@meowdown%2Fcore#function-defineFileClickHandler) (`@meowdown/react`'s `onFileClick`) rather than the link click handler, and no link hover or edit menu.
|
|
126
131
|
|
|
127
132
|
Rendered images are resizable: drag the corner handle and the chosen size is written back into the source as a trailing comment, `<!-- {"width":320,"height":240} -->`, which round-trips as plain Markdown. A comment immediately after an image is folded into its mark and drives the image's `width` and `height` attributes, so the box keeps its dimensions before the image loads; any other comment stays literal text.
|
|
128
133
|
|
package/dist/index.d.ts
CHANGED
|
@@ -4,7 +4,7 @@ import { PlaceholderOptions, definePlaceholder } from "@prosekit/extensions/plac
|
|
|
4
4
|
import { defineReadonly } from "@prosekit/extensions/readonly";
|
|
5
5
|
import { Command, EditorState, PluginKey } from "@prosekit/pm/state";
|
|
6
6
|
import { EditorView } from "@prosekit/pm/view";
|
|
7
|
-
import { Mark, ProseMirrorNode } from "@prosekit/pm/model";
|
|
7
|
+
import { EditorNode, Mark, ProseMirrorNode } from "@prosekit/pm/model";
|
|
8
8
|
import { ListAttrs } from "@prosekit/extensions/list";
|
|
9
9
|
import { HorizontalRuleExtension } from "@prosekit/extensions/horizontal-rule";
|
|
10
10
|
import { render } from "katex";
|
|
@@ -231,6 +231,7 @@ type MdPackAttrs = {
|
|
|
231
231
|
data: {
|
|
232
232
|
href: string;
|
|
233
233
|
title: string;
|
|
234
|
+
reference?: true;
|
|
234
235
|
};
|
|
235
236
|
} | {
|
|
236
237
|
key: 'image';
|
|
@@ -250,7 +251,7 @@ interface PositionRange {
|
|
|
250
251
|
//#endregion
|
|
251
252
|
//#region src/extensions/get-link-unit-at.d.ts
|
|
252
253
|
interface LinkUnit {
|
|
253
|
-
/** Whole
|
|
254
|
+
/** Whole inline link, reference link, or autolink range. */
|
|
254
255
|
unit: PositionRange;
|
|
255
256
|
/**
|
|
256
257
|
* The visible text of the link: the `[ ]` interior for a full link, the URL
|
|
@@ -365,6 +366,19 @@ declare function definePendingReplacementHandler(handler: PendingReplacementHand
|
|
|
365
366
|
*/
|
|
366
367
|
type MarkChunk = readonly [from: number, to: number, marks: readonly Mark[]];
|
|
367
368
|
//#endregion
|
|
369
|
+
//#region src/extensions/reference-links.d.ts
|
|
370
|
+
interface ReferenceDefinition {
|
|
371
|
+
key: string;
|
|
372
|
+
href: string;
|
|
373
|
+
title: string;
|
|
374
|
+
}
|
|
375
|
+
type ReferenceDefinitions = ReadonlyMap<string, ReferenceDefinition>;
|
|
376
|
+
interface ReferenceDefinitionIndex {
|
|
377
|
+
definitions: ReferenceDefinitions;
|
|
378
|
+
nodes: ReadonlySet<EditorNode>;
|
|
379
|
+
}
|
|
380
|
+
declare function collectReferenceDefinitions(doc: EditorNode): ReferenceDefinitionIndex;
|
|
381
|
+
//#endregion
|
|
368
382
|
//#region src/extensions/wiki-embed.d.ts
|
|
369
383
|
/** The parsed source payload of an Obsidian-style `![[target]]` embed. */
|
|
370
384
|
interface ParsedWikiEmbed {
|
|
@@ -440,6 +454,14 @@ interface FileLinkOptions {
|
|
|
440
454
|
}
|
|
441
455
|
/** Host options that influence source-backed inline atom parsing. */
|
|
442
456
|
type InlineMarkOptions = FileLinkOptions & WikiEmbedOptions;
|
|
457
|
+
interface InlineMarkContext {
|
|
458
|
+
/** Effective document-wide definitions, keyed by normalized reference label. */
|
|
459
|
+
referenceDefinitions?: ReferenceDefinitions;
|
|
460
|
+
/** Prevent this definition block's own label from resolving as a shortcut reference. */
|
|
461
|
+
isReferenceDefinition?: boolean;
|
|
462
|
+
/** Receives every normalized key read by this block, including unresolved references. */
|
|
463
|
+
referencedKeys?: Set<string>;
|
|
464
|
+
}
|
|
443
465
|
/**
|
|
444
466
|
* Walk a textblock's inline content and produce a list of mark chunks
|
|
445
467
|
* with positions relative to the start of `text` (i.e. zero-based).
|
|
@@ -452,6 +474,7 @@ marks: TypedMarkBuilders,
|
|
|
452
474
|
text: string,
|
|
453
475
|
/** Host options; omit for the default parse. */
|
|
454
476
|
options?: InlineMarkOptions): MarkChunk[];
|
|
477
|
+
declare function inlineTextToMarkChunksWithContext(marks: TypedMarkBuilders, text: string, options?: InlineMarkOptions, context?: InlineMarkContext): MarkChunk[];
|
|
455
478
|
//#endregion
|
|
456
479
|
//#region src/extensions/mark-mode.d.ts
|
|
457
480
|
/**
|
|
@@ -1162,4 +1185,4 @@ declare function defineSpellCheckPlugin(spellCheck: boolean): import("@prosekit/
|
|
|
1162
1185
|
*/
|
|
1163
1186
|
declare function formatFileSize(bytes: number): string;
|
|
1164
1187
|
//#endregion
|
|
1165
|
-
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, getTextblockDisplayText, getVirtualElementFromRange, inlineTextToMarkChunks, insertLink, isCodeBlockPreviewHiddenDecoration, isMarkOfType, isNodeOfType, isSelectionInTableCell, listenForTweetHeight, loadKaTeX, markdownToDoc, matchEmbed, parseWikiEmbed, removeLink, renderMathInto, updateLink, wikiEmbedBasename, withPriority };
|
|
1188
|
+
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 InlineMarkContext, 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 ReferenceDefinition, type ReferenceDefinitionIndex, type ReferenceDefinitions, 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, collectReferenceDefinitions, 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, getTextblockDisplayText, getVirtualElementFromRange, inlineTextToMarkChunks, inlineTextToMarkChunksWithContext, insertLink, isCodeBlockPreviewHiddenDecoration, isMarkOfType, isNodeOfType, isSelectionInTableCell, listenForTweetHeight, loadKaTeX, markdownToDoc, matchEmbed, parseWikiEmbed, removeLink, renderMathInto, updateLink, wikiEmbedBasename, withPriority };
|
package/dist/index.js
CHANGED
|
@@ -1,38 +1,38 @@
|
|
|
1
|
-
import{Priority as e,Priority as t,createMarkBuilders as n,createNodeBuilders as r,defineBaseCommands as i,defineBaseKeymap as a,defineClipboardSerializer as o,defineCommands as s,defineHistory as c,defineKeymap as l,defineMarkSpec as u,defineMarkView as d,defineNodeAttr as f,defineNodeSpec as p,definePlugin as m,getMarkRange as h,getMarkType as ee,getNodeType as te,isAllSelection as ne,isApple as re,isAtBlockStart as ie,isNodeSelection as ae,isTextSelection as g,setBlockType as oe,toggleNode as se,union as _,unsetBlockType as ce,withPriority as le,withPriority as v,withSkipCodeBlock as ue}from"@prosekit/core";import{defineCodeBlock as de,defineCodeBlockHighlight as fe,defineCodeBlockPreviewPlugin as pe,isCodeBlockPreviewHiddenDecoration as me}from"@prosekit/extensions/code-block";import{definePlaceholder as he}from"@prosekit/extensions/placeholder";import{defineReadonly as ge}from"@prosekit/extensions/readonly";import{LEZER_NODE_IDS as y,collectInlineElements as _e,getAutolinkHref as ve,gfmBlockOnlyParser as ye,isSpaceChar as b,parseInline as x}from"@meowdown/markdown";import{isElementLike as be,isHTMLElement as xe,isObject as Se,once as Ce}from"@ocavue/utils";import{defineBlockquote as we}from"@prosekit/extensions/blockquote";import{defineDoc as Te}from"@prosekit/extensions/doc";import{defineGapCursor as Ee}from"@prosekit/extensions/gap-cursor";import{defineModClickPrevention as De}from"@prosekit/extensions/mod-click-prevention";import{defineText as Oe}from"@prosekit/extensions/text";import{defineVirtualSelection as ke}from"@prosekit/extensions/virtual-selection";import{NodeSelection as Ae,Plugin as S,PluginKey as C,Selection as je,TextSelection as w}from"@prosekit/pm/state";import{Decoration as Me,DecorationSet as T}from"@prosekit/pm/view";import{NO_BREAK_SPACE as Ne}from"unicode-by-name";import{defaultHandlers as Pe}from"hast-util-to-mdast";import{defaultHandlers as Fe}from"mdast-util-to-markdown";import Ie from"rehype-parse";import Le from"rehype-remark";import Re from"remark-gfm";import ze from"remark-stringify";import{unified as Be}from"unified";import{DOMParser as Ve,DOMSerializer as He,Fragment as E,Mark as Ue,Slice as D}from"@prosekit/pm/model";import{defineHeadingCommands as We,defineHeadingInputRule as Ge,defineHeadingSpec as Ke}from"@prosekit/extensions/heading";import{defineParagraphCommands as qe,defineParagraphKeymap as Je}from"@prosekit/extensions/paragraph";import{LanguageDescription as Ye}from"@codemirror/language";import{languages as Xe}from"@codemirror/language-data";import{classHighlighter as Ze,highlightTree as Qe}from"@lezer/highlight";import{createParser as $e}from"prosemirror-highlight/lezer";import{defineEnterRule as et,defineTextBlockEnterRule as tt}from"@prosekit/extensions/enter-rule";import{defineInputRule as nt,defineTextBlockInputRule as rt}from"@prosekit/extensions/input-rule";import{triggerAutocomplete as it}from"@prosekit/extensions/autocomplete";import{defineListCommands as at,defineListDropIndicator as ot,defineListKeymap as st,defineListSpec as ct,moveList as lt,toggleList as ut,unwrapList as dt,wrapInList as O}from"@prosekit/extensions/list";import{chainCommands as ft,lift as pt}from"@prosekit/pm/commands";import{defineHorizontalRule as mt}from"@prosekit/extensions/horizontal-rule";import{AddMarkStep as ht,AddNodeMarkStep as gt,RemoveMarkStep as _t,RemoveNodeMarkStep as vt,ReplaceStep as yt,Step as bt,StepResult as xt,Transform as St}from"@prosekit/pm/transform";import{createListRenderingPlugin as Ct,createSafariInputMethodWorkaroundPlugin as wt,createToggleCollapsedCommand as Tt,defaultAttributesGetter as Et,findCheckboxInListItem as Dt,handleListMarkerMouseDown as Ot,joinListElements as kt,listToDOM as At,unwrapListSlice as jt,wrappingListInputRule as Mt}from"prosemirror-flat-list";import{defineTableCellSpec as Nt,defineTableCommands as Pt,defineTableDropIndicator as Ft,defineTableEditingPlugin as It,defineTableHeaderCellSpec as Lt,defineTableRowSpec as Rt,defineTableSpec as zt,deleteTable as Bt,isCellSelection as Vt}from"@prosekit/extensions/table";import{closeHistory as Ht}from"@prosekit/pm/history";import{registerResizableHandleElement as Ut,registerResizableRootElement as Wt}from"@prosekit/web/resizable";import{InputRule as Gt}from"@prosekit/pm/inputrules";function k(e,t,n,r){let i=e.doc.content.size;if(t<0||t>i)return;let a=e.doc.resolve(t);if(!(!a.parent.isTextblock||a.parent.type.spec.code))return h(a,n,r)}const A=new C(`mark-mode`);function Kt(e){return A.getState(e)}function qt(e){return new S({key:A,state:{init:()=>e,apply:(e,t)=>e.getMeta(A)??t},props:{attributes:t=>({"data-mark-mode":Kt(t)??e}),decorations:e=>{let t=Kt(e);if(t===`focus`)return Xt(e);if(t===`hide`)return Zt(e)}}})}function Jt(e){return(t,n)=>j(t)===e?!1:(n?.(t.tr.setMeta(A,e)),!0)}function Yt(e){return _(m(qt(e)),s({setMarkMode:Jt}))}function j(e){return A.getState(e)}function Xt(e){return Qt(e,void 0)}function Zt(e){return Qt(e,{key:`math`})}function Qt(e,t){let{selection:n}=e;if(!n.empty)return T.empty;let r=n.$head,{parent:i}=r;if(!i.isTextblock||i.type.spec.code)return T.empty;let a=h(r,ee(e.schema,`mdPack`),t);return a?T.create(e.doc,[Me.inline(a.from,a.to,{class:`show`})]):T.empty}const $t=[`mdImage`,`mdWikilink`,`mdFile`];function M(e,t){let n=j(t);return n?e.flatMap(e=>e.modes.includes(n)?[e.name]:[]):[]}function en(e,t,n){for(let r of n){let n=k(e,t,r);if(n)return n}}function N(e,t,n){let r=en(e,t,n);return r&&r.to===t?r:void 0}function P(e,t,n){let r=en(e,t,n);return r&&r.from===t?r:void 0}function tn(e,t){let{from:n,to:r,empty:i}=e.selection;if(i)return;let a=en(e,n,t);return a&&a.from===n&&a.to===r?a:void 0}function nn(e,t){return w.create(e.doc,t.from,t.to)}function rn(e,t,n,r){let i=e.doc.resolve(t);if(!(r===-1?i.parentOffset===0:i.parentOffset===i.parent.content.size)||i.depth===0)return;let a=r===-1?P(e,t,n):N(e,t,n),o=r===-1?i.before():i.after(),s=je.findFrom(e.doc.resolve(o),r);if(!s)return;let c=g(s)?r===-1?N(e,s.head,n):P(e,s.head,n):void 0;if(!(a==null&&c==null))return s}function an(e){return(t,n)=>{let r=M(e,t);if(r.length===0||!g(t.selection))return!1;let i=t.selection;if(i.empty){let e=P(t,i.from,r);if(e)return n?.(t.tr.setSelection(nn(t,e))),!0;if(N(t,i.from,r)&&i.from<t.doc.resolve(i.from).end())return n?.(t.tr.setSelection(w.create(t.doc,i.from+1))),!0;let a=rn(t,i.from,r,1);return a?(n?.(t.tr.setSelection(a).scrollIntoView()),!0):!1}let a=tn(t,r);return a?(n?.(t.tr.setSelection(w.create(t.doc,a.to))),!0):!1}}function on(e){return(t,n)=>{let r=M(e,t);if(r.length===0||!g(t.selection))return!1;let i=t.selection;if(i.empty){let e=N(t,i.from,r);if(e)return n?.(t.tr.setSelection(nn(t,e))),!0;let a=rn(t,i.from,r,-1);return a?(n?.(t.tr.setSelection(a).scrollIntoView()),!0):!1}let a=tn(t,r);return a?(n?.(t.tr.setSelection(w.create(t.doc,a.from))),!0):!1}}function sn(e,t){return(n,r)=>{let i=M(e,n);if(i.length===0||!g(n.selection))return!1;let{anchor:a,head:o}=n.selection,s=t===-1?N(n,o,i):P(n,o,i);if(s){let e=t===-1?s.from:s.to;return r?.(n.tr.setSelection(w.create(n.doc,a,e)).scrollIntoView()),!0}let c=rn(n,o,i,t);return!c||!g(c)?!1:(r?.(n.tr.setSelection(w.create(n.doc,a,c.head)).scrollIntoView()),!0)}}function cn(e){return(t,n)=>{let r=M(e,t);if(r.length===0||!t.selection.empty)return!1;let i=t.selection.from,a=N(t,i,r);return a?(n?.(t.tr.delete(a.from,a.to)),!0):!P(t,i,r)||i<=t.doc.resolve(i).start()?!1:(n?.(t.tr.delete(i-1,i)),!0)}}function ln(e){return(t,n)=>{let r=M(e,t);if(r.length===0||!t.selection.empty)return!1;let i=t.selection.from,a=P(t,i,r);return a?(n?.(t.tr.delete(a.from,a.to)),!0):!N(t,i,r)||i>=t.doc.resolve(i).end()?!1:(n?.(t.tr.delete(i,i+1)),!0)}}const un=`md-atom-selected`;function dn(e){return new S({key:new C(`atom-mark-selection`),props:{decorations:t=>{let n=M(e,t);if(n.length===0||ae(t.selection))return;let r=tn(t,n);if(r)return T.create(t.doc,[Me.inline(r.from,r.to,{class:un})]);let{from:i,to:a,empty:o}=t.selection;if(o)return null;let s=[];return t.doc.nodesBetween(i,a,(e,t)=>{e.marks.some(e=>n.includes(e.type.name))&&s.push(Me.inline(t,t+e.nodeSize,{class:un}))}),T.create(t.doc,s)}}})}function fn({marks:e}){return _(v(l({ArrowRight:an(e),ArrowLeft:on(e),"Shift-ArrowRight":sn(e,1),"Shift-ArrowLeft":sn(e,-1),Backspace:cn(e),Delete:ln(e)}),t.high),m(dn(e)))}const pn=(e,t)=>{let n={type:`highlight`,children:e.all(t)};return e.patch(t,n),n},mn=(e,t,n,r)=>{let i=e,a=n.createTracker(r),o=a.move(`==`);return o+=a.move(n.containerPhrasing(i,{...a.current(),before:o,after:`=`})),o+=a.move(`==`),o};function hn(e){return e.tagName===`input`&&e.properties.type===`checkbox`}function gn(e){for(let t of e.children){if(t.type!==`element`)continue;if(hn(t))return t;if(t.tagName===`ul`||t.tagName===`ol`)continue;let e=gn(t);if(e)return e}}function _n(e){let t=e.properties.dataChecked,n=gn(e);if(!(t!=null||e.properties.dataType===`taskItem`||e.properties.dataTaskListItem!=null||n!==void 0))return;let r=typeof t==`string`?t!==`false`:!!n?.properties.checked,i=e.children.filter(e=>e.type!==`element`||!(hn(e)||e.tagName===`label`&&gn(e)));for(let e of[`div`,`p`]){let t=i.length===1&&i[0].type===`element`?i[0]:void 0;t?.tagName===e&&(i=t.children)}let a={type:`element`,tagName:`input`,properties:{type:`checkbox`,checked:r},children:[]};return{...e,children:[a,...i]}}const vn=(e,t)=>Pe.li(e,_n(t)??t);function yn(e){return e.filter(e=>e.character!==`[`&&e.character!==`~`?!0:e.atBreak?e.character===`~`:!(Array.isArray(e.inConstruct)?e.inConstruct:e.inConstruct?[e.inConstruct]:[]).includes(`phrasing`))}const bn=(e,t,n,r)=>Fe.text(e,t,{...n,unsafe:yn(n.unsafe)},r);function xn(){return Be().use(Ie).use(Le,{handlers:{mark:pn,li:vn}}).use(Re).use(ze,{bullet:`-`,emphasis:`*`,strong:`*`,fence:"`",fences:!0,rule:`-`,ruleRepetition:3,listItemIndent:`one`,handlers:{highlight:mn,text:bn}}).freeze()}const Sn=Ce(xn);function Cn(e){return String(Sn().processSync(e))}function wn(e){if(e==null)return;let t=Number.parseInt(e,10);return Number.isSafeInteger(t)?t:void 0}function F(e){let t=wn(e);return t!=null&&t>0?t:void 0}function Tn(e,t){return e.type.name===t}const En=new Set([`mdMark`,`mdLinkUri`,`mdLinkTitle`]),Dn=new Set([`mdWikilink`,`mdImage`,`mdFile`,`mdMath`]);function On(e){return e.find(e=>Dn.has(e.type.name))}function kn(e){return e.some(e=>En.has(e.type.name))}function An(e){let t=[];return e.forEach(e=>{if(!e.isText||!e.text)return;let n=On(e.marks),r=t.at(-1);if(n!=null&&r!=null&&r.atom===n){r.text+=e.text,r.children.push(e);return}t.push({atom:n,text:e.text,children:[e]})}),t}const jn={mdStrong:`strong`,mdEm:`em`,mdCode:`code`,mdDel:`del`,mdHighlight:`mark`,mdLinkText:`a`};function Mn(e,t,n={}){let r=document.createElement(e);r.setAttribute(`data-md`,t.textContent);for(let[e,t]of Object.entries(n))t!=null&&r.setAttribute(e,t);return Pn(t,r),r}function Nn(e,t,n){return{tag:`${e}[data-md]`,node:t,priority:100,getAttrs:n,getContent:(e,t)=>{let n=(xe(e)?e:void 0)?.getAttribute(`data-md`)??``;return n?E.from(t.text(n)):E.empty}}}function Pn(e,t){let n=[];for(let r of An(e)){if(r.atom!=null){n.length=0,t.append(Ln(r.atom,r.text));continue}for(let e of r.children)kn(e.marks)||(Fn(n,e.marks.filter(e=>jn[e.type.name]),t),In(n.at(-1)?.element??t,e.text??``))}}function Fn(e,t,n){let r=0;for(;r<e.length&&r<t.length&&t[r].eq(e[r].mark);)r++;e.length=r;for(let i=r;i<t.length;i++){let r=t[i],a=document.createElement(jn[r.type.name]??`span`);Tn(r,`mdLinkText`)&&a.setAttribute(`href`,r.attrs.href),(e.at(-1)?.element??n).append(a),e.push({mark:r,element:a})}}function In(e,t){let n=t.split(`
|
|
2
|
-
`);for(let[t,r]of n.entries())t>0&&e.append(document.createElement(`br`)),r&&e.append(document.createTextNode(r))}function
|
|
3
|
-
`.repeat(t-e.trailingNewlines))}function
|
|
4
|
-
`),!0;if(i===`STYLE`||i===`TITLE`)return!0;let a=i===`DIV`?1:i===`P`?2:0;a&&
|
|
5
|
-
`).replace(/^\n+/,``).replace(/\n+$/,``);if(!n)return
|
|
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 g,getNodeType as _,isAllSelection as v,isApple as ee,isAtBlockStart as te,isNodeSelection as ne,isTextSelection as y,setBlockType as re,toggleNode as ie,union as b,unsetBlockType as ae,withPriority as oe,withPriority as x,withSkipCodeBlock as se}from"@prosekit/core";import{defineCodeBlock as ce,defineCodeBlockHighlight as le,defineCodeBlockPreviewPlugin as ue,isCodeBlockPreviewHiddenDecoration as de}from"@prosekit/extensions/code-block";import{definePlaceholder as fe}from"@prosekit/extensions/placeholder";import{defineReadonly as pe}from"@prosekit/extensions/readonly";import{LEZER_NODE_IDS as S,collectInlineElements as me,getAutolinkHref as he,gfmBlockOnlyParser as ge,gfmParser as _e,isSpaceChar as C,parseInline as ve}from"@meowdown/markdown";import{isElementLike as ye,isHTMLElement as be,isObject as xe,once as Se}from"@ocavue/utils";import{defineBlockquote as Ce}from"@prosekit/extensions/blockquote";import{defineDoc as we}from"@prosekit/extensions/doc";import{defineGapCursor as Te}from"@prosekit/extensions/gap-cursor";import{defineModClickPrevention as Ee}from"@prosekit/extensions/mod-click-prevention";import{defineText as De}from"@prosekit/extensions/text";import{defineVirtualSelection as Oe}from"@prosekit/extensions/virtual-selection";import{NodeSelection as ke,Plugin as w,PluginKey as T,Selection as Ae,TextSelection as E}from"@prosekit/pm/state";import{Decoration as je,DecorationSet as D}from"@prosekit/pm/view";import{NO_BREAK_SPACE as Me}from"unicode-by-name";import{defaultHandlers as Ne}from"hast-util-to-mdast";import{defaultHandlers as Pe}from"mdast-util-to-markdown";import Fe from"rehype-parse";import Ie from"rehype-remark";import Le from"remark-gfm";import Re from"remark-stringify";import{unified as ze}from"unified";import{DOMParser as Be,DOMSerializer as Ve,Fragment as O,Mark as He,Slice as k}from"@prosekit/pm/model";import{defineHeadingCommands as Ue,defineHeadingInputRule as We,defineHeadingSpec as Ge}from"@prosekit/extensions/heading";import{defineParagraphCommands as Ke,defineParagraphKeymap as qe}from"@prosekit/extensions/paragraph";import{LanguageDescription as Je}from"@codemirror/language";import{languages as Ye}from"@codemirror/language-data";import{classHighlighter as Xe,highlightTree as Ze}from"@lezer/highlight";import{createParser as Qe}from"prosemirror-highlight/lezer";import{defineEnterRule as $e,defineTextBlockEnterRule as et}from"@prosekit/extensions/enter-rule";import{defineInputRule as tt,defineTextBlockInputRule as nt}from"@prosekit/extensions/input-rule";import{triggerAutocomplete as rt}from"@prosekit/extensions/autocomplete";import{defineListCommands as it,defineListDropIndicator as at,defineListKeymap as ot,defineListSpec as st,moveList as ct,toggleList as lt,unwrapList as ut,wrapInList as dt}from"@prosekit/extensions/list";import{chainCommands as ft,lift as pt}from"@prosekit/pm/commands";import{defineHorizontalRule as mt}from"@prosekit/extensions/horizontal-rule";import{AddMarkStep as ht,AddNodeMarkStep as gt,AttrStep as _t,RemoveMarkStep as vt,RemoveNodeMarkStep as yt,ReplaceStep as bt,Step as xt,StepResult as St,Transform as Ct}from"@prosekit/pm/transform";import{decodeString as wt}from"micromark-util-decode-string";import{normalizeIdentifier as Tt}from"micromark-util-normalize-identifier";import{createListRenderingPlugin as Et,createSafariInputMethodWorkaroundPlugin as Dt,createToggleCollapsedCommand as Ot,defaultAttributesGetter as kt,findCheckboxInListItem as At,handleListMarkerMouseDown as jt,joinListElements as Mt,listToDOM as Nt,unwrapListSlice as Pt,wrappingListInputRule as Ft}from"prosemirror-flat-list";import{defineTableCellSpec as It,defineTableCommands as Lt,defineTableDropIndicator as Rt,defineTableEditingPlugin as zt,defineTableHeaderCellSpec as Bt,defineTableRowSpec as Vt,defineTableSpec as Ht,deleteTable as Ut,isCellSelection as Wt}from"@prosekit/extensions/table";import{closeHistory as Gt}from"@prosekit/pm/history";import{registerResizableHandleElement as Kt,registerResizableRootElement as qt}from"@prosekit/web/resizable";import{InputRule as Jt}from"@prosekit/pm/inputrules";function A(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 Yt=new T(`mark-mode`);function Xt(e){return Yt.getState(e)}function Zt(e){return new w({key:Yt,state:{init:()=>e,apply:(e,t)=>e.getMeta(Yt)??t},props:{attributes:t=>({"data-mark-mode":Xt(t)??e}),decorations:e=>{let t=Xt(e);if(t===`focus`)return en(e);if(t===`hide`)return tn(e)}}})}function Qt(e){return(t,n)=>j(t)===e?!1:(n?.(t.tr.setMeta(Yt,e)),!0)}function $t(e){return b(m(Zt(e)),s({setMarkMode:Qt}))}function j(e){return Yt.getState(e)}function en(e){return nn(e,void 0)}function tn(e){return nn(e,{key:`math`})}function nn(e,t){let{selection:n}=e;if(!n.empty)return D.empty;let r=n.$head,{parent:i}=r;if(!i.isTextblock||i.type.spec.code)return D.empty;let a=h(r,g(e.schema,`mdPack`),t);return a?D.create(e.doc,[je.inline(a.from,a.to,{class:`show`})]):D.empty}const rn=[`mdImage`,`mdWikilink`,`mdFile`];function M(e,t){let n=j(t);return n?e.flatMap(e=>e.modes.includes(n)?[e.name]:[]):[]}function an(e,t,n){for(let r of n){let n=A(e,t,r);if(n)return n}}function N(e,t,n){let r=an(e,t,n);return r&&r.to===t?r:void 0}function P(e,t,n){let r=an(e,t,n);return r&&r.from===t?r:void 0}function on(e,t){let{from:n,to:r,empty:i}=e.selection;if(i)return;let a=an(e,n,t);return a&&a.from===n&&a.to===r?a:void 0}function sn(e,t){return E.create(e.doc,t.from,t.to)}function cn(e,t,n,r){let i=e.doc.resolve(t);if(!(r===-1?i.parentOffset===0:i.parentOffset===i.parent.content.size)||i.depth===0)return;let a=r===-1?P(e,t,n):N(e,t,n),o=r===-1?i.before():i.after(),s=Ae.findFrom(e.doc.resolve(o),r);if(!s)return;let c=y(s)?r===-1?N(e,s.head,n):P(e,s.head,n):void 0;if(!(a==null&&c==null))return s}function ln(e){return(t,n)=>{let r=M(e,t);if(r.length===0||!y(t.selection))return!1;let i=t.selection;if(i.empty){let e=P(t,i.from,r);if(e)return n?.(t.tr.setSelection(sn(t,e))),!0;if(N(t,i.from,r)&&i.from<t.doc.resolve(i.from).end())return n?.(t.tr.setSelection(E.create(t.doc,i.from+1))),!0;let a=cn(t,i.from,r,1);return a?(n?.(t.tr.setSelection(a).scrollIntoView()),!0):!1}let a=on(t,r);return a?(n?.(t.tr.setSelection(E.create(t.doc,a.to))),!0):!1}}function un(e){return(t,n)=>{let r=M(e,t);if(r.length===0||!y(t.selection))return!1;let i=t.selection;if(i.empty){let e=N(t,i.from,r);if(e)return n?.(t.tr.setSelection(sn(t,e))),!0;let a=cn(t,i.from,r,-1);return a?(n?.(t.tr.setSelection(a).scrollIntoView()),!0):!1}let a=on(t,r);return a?(n?.(t.tr.setSelection(E.create(t.doc,a.from))),!0):!1}}function dn(e,t){return(n,r)=>{let i=M(e,n);if(i.length===0||!y(n.selection))return!1;let{anchor:a,head:o}=n.selection,s=t===-1?N(n,o,i):P(n,o,i);if(s){let e=t===-1?s.from:s.to;return r?.(n.tr.setSelection(E.create(n.doc,a,e)).scrollIntoView()),!0}let c=cn(n,o,i,t);return!c||!y(c)?!1:(r?.(n.tr.setSelection(E.create(n.doc,a,c.head)).scrollIntoView()),!0)}}function fn(e){return(t,n)=>{let r=M(e,t);if(r.length===0||!t.selection.empty)return!1;let i=t.selection.from,a=N(t,i,r);return a?(n?.(t.tr.delete(a.from,a.to)),!0):!P(t,i,r)||i<=t.doc.resolve(i).start()?!1:(n?.(t.tr.delete(i-1,i)),!0)}}function pn(e){return(t,n)=>{let r=M(e,t);if(r.length===0||!t.selection.empty)return!1;let i=t.selection.from,a=P(t,i,r);return a?(n?.(t.tr.delete(a.from,a.to)),!0):!N(t,i,r)||i>=t.doc.resolve(i).end()?!1:(n?.(t.tr.delete(i,i+1)),!0)}}const mn=`md-atom-selected`;function hn(e){return new w({key:new T(`atom-mark-selection`),props:{decorations:t=>{let n=M(e,t);if(n.length===0||ne(t.selection))return;let r=on(t,n);if(r)return D.create(t.doc,[je.inline(r.from,r.to,{class:mn})]);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(je.inline(t,t+e.nodeSize,{class:mn}))}),D.create(t.doc,s)}}})}function gn({marks:e}){return b(x(l({ArrowRight:ln(e),ArrowLeft:un(e),"Shift-ArrowRight":dn(e,1),"Shift-ArrowLeft":dn(e,-1),Backspace:fn(e),Delete:pn(e)}),t.high),m(hn(e)))}const _n=(e,t)=>{let n={type:`highlight`,children:e.all(t)};return e.patch(t,n),n},vn=(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 yn(e){return e.tagName===`input`&&e.properties.type===`checkbox`}function bn(e){for(let t of e.children){if(t.type!==`element`)continue;if(yn(t))return t;if(t.tagName===`ul`||t.tagName===`ol`)continue;let e=bn(t);if(e)return e}}function xn(e){let t=e.properties.dataChecked,n=bn(e);if(!(t!=null||e.properties.dataType===`taskItem`||e.properties.dataTaskListItem!=null||n!==void 0))return;let r=typeof t==`string`?t!==`false`:!!n?.properties.checked,i=e.children.filter(e=>e.type!==`element`||!(yn(e)||e.tagName===`label`&&bn(e)));for(let e of[`div`,`p`]){let t=i.length===1&&i[0].type===`element`?i[0]:void 0;t?.tagName===e&&(i=t.children)}let a={type:`element`,tagName:`input`,properties:{type:`checkbox`,checked:r},children:[]};return{...e,children:[a,...i]}}const Sn=(e,t)=>Ne.li(e,xn(t)??t);function Cn(e){return e.filter(e=>e.character!==`[`&&e.character!==`~`?!0:e.atBreak?e.character===`~`:!(Array.isArray(e.inConstruct)?e.inConstruct:e.inConstruct?[e.inConstruct]:[]).includes(`phrasing`))}const wn=(e,t,n,r)=>Pe.text(e,t,{...n,unsafe:Cn(n.unsafe)},r);function Tn(){return ze().use(Fe).use(Ie,{handlers:{mark:_n,li:Sn}}).use(Le).use(Re,{bullet:`-`,emphasis:`*`,strong:`*`,fence:"`",fences:!0,rule:`-`,ruleRepetition:3,listItemIndent:`one`,handlers:{highlight:vn,text:wn}}).freeze()}const En=Se(Tn);function Dn(e){return String(En().processSync(e))}function On(e){if(e==null)return;let t=Number.parseInt(e,10);return Number.isSafeInteger(t)?t:void 0}function kn(e){let t=On(e);return t!=null&&t>0?t:void 0}function An(e,t){return e.type.name===t}const jn=new Set([`mdMark`,`mdLinkUri`,`mdLinkTitle`]),Mn=new Set([`mdWikilink`,`mdImage`,`mdFile`,`mdMath`]);function Nn(e){return e.find(e=>Mn.has(e.type.name))}function Pn(e){return e.some(e=>jn.has(e.type.name))}function Fn(e){let t=[];return e.forEach(e=>{if(!e.isText||!e.text)return;let n=Nn(e.marks),r=t.at(-1);if(n!=null&&r!=null&&r.atom===n){r.text+=e.text,r.children.push(e);return}t.push({atom:n,text:e.text,children:[e]})}),t}const In={mdStrong:`strong`,mdEm:`em`,mdCode:`code`,mdDel:`del`,mdHighlight:`mark`,mdLinkText:`a`};function Ln(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 zn(t,r),r}function Rn(e,t,n){return{tag:`${e}[data-md]`,node:t,priority:100,getAttrs:n,getContent:(e,t)=>{let n=(be(e)?e:void 0)?.getAttribute(`data-md`)??``;return n?O.from(t.text(n)):O.empty}}}function zn(e,t){let n=[];for(let r of Fn(e)){if(r.atom!=null){n.length=0,t.append(Hn(r.atom,r.text));continue}for(let e of r.children)Pn(e.marks)||(Bn(n,e.marks.filter(e=>In[e.type.name]),t),Vn(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(In[r.type.name]??`span`);An(r,`mdLinkText`)&&a.setAttribute(`href`,r.attrs.href),(e.at(-1)?.element??n).append(a),e.push({mark:r,element:a})}}function Vn(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 Hn(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 F(e,t){return e.type.name===t}function Un(){return p({name:`heading`,whitespace:`pre`})}function Wn(e){let t=e.attrs;return Ln(`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 Gn(){return[1,2,3,4,5,6].map(e=>Rn(`h${e}`,`heading`,t=>({level:e,setextUnderline:kn(t.getAttribute(`data-setext-underline`))??null,closingHashes:kn(t.getAttribute(`data-closing-hashes`))??null})))}function Kn(){return f({type:`heading`,attr:`setextUnderline`,default:null,toDOM:e=>e==null?null:[`data-setext-underline`,String(e)],parseDOM:e=>kn(e.getAttribute(`data-setext-underline`))??null})}function qn(){return f({type:`heading`,attr:`closingHashes`,default:null,toDOM:e=>e==null?null:[`data-closing-hashes`,String(e)],parseDOM:e=>kn(e.getAttribute(`data-closing-hashes`))??null})}function I(e){return se(ie({type:`heading`,attrs:{level:e}}))}const Jn=(e,t,n)=>{let r=te(e,n);return r!=null&&F(r.parent,`heading`)?ae()(e,t,n):!1};function Yn(){return l({"Mod-1":I(1),"Mod-2":I(2),"Mod-3":I(3),"Mod-4":I(4),"Mod-5":I(5),"Mod-6":I(6),Backspace:Jn})}function Xn(){return b(Ge(),Un(),Kn(),qn(),We(),Ue(),Yn())}function Zn(){return p({name:`paragraph`,content:`inline*`,group:`block`,whitespace:`pre`,parseDOM:[{tag:`p`}],toDOM(){return[`p`,0]}})}function Qn(e){return Ln(`p`,e)}function $n(){return[Rn(`p`,`paragraph`)]}function er(){return b(x(Zn(),t.highest),Ke(),qe())}function tr(e){return{...e,paragraph:e=>({dom:Qn(e)}),heading:e=>({dom:Wn(e)})}}function nr(){return o({serializeFragmentWrapper:e=>(...t)=>{let n=e(...t);for(let e of n.children)e.setAttribute(`data-meowdown`,``);return n},nodesFromSchemaWrapper:e=>(...t)=>tr(e(...t))})}const rr=new WeakMap;function ir(e){let t=rr.get(e);return t??(t=new Ve(tr(Ve.nodesFromSchema(e)),Ve.marksFromSchema(e)),rr.set(e,t)),t}const ar=new T(`meowdown-html-paste`);function or(e){return e.includes(`data-meowdown`)?!0:e.includes(`data-pm-slice`)&&e.includes(`md-mark`)}const sr=new Set([`html`,`head`,`body`,`meta`,`style`,`title`,`div`,`span`,`p`,`br`,`font`,`wbr`]);function cr(e){let t=new window.DOMParser().parseFromString(e,`text/html`),n={chunks:[],hasContent:!1,trailingNewlines:0,hasStyledLine:!1};if(dr(t.documentElement,n,!1)&&n.hasStyledLine)return n.chunks.join(``).replaceAll(Me,` `)}function lr(e,t){!e.hasContent||e.trailingNewlines>=t||ur(e,`
|
|
3
|
+
`.repeat(t-e.trailingNewlines))}function ur(e,t){if(!t)return;e.chunks.push(t);let n=t.length;for(;n>0&&t.charCodeAt(n-1)===10;)n--;n===0?e.trailingNewlines+=t.length:(e.hasContent=!0,e.trailingNewlines=t.length-n)}function dr(e,t,n){if(e.nodeType===Node.TEXT_NODE)return ur(t,e.nodeValue??``),!0;if(e.nodeType!==Node.ELEMENT_NODE)return!0;let r=e,i=r.tagName;if(!sr.has(i.toLowerCase()))return!1;if(n||=i===`DIV`,n&&r.getAttribute(`style`)?.trim()&&(t.hasStyledLine=!0),i===`BR`)return ur(t,`
|
|
4
|
+
`),!0;if(i===`STYLE`||i===`TITLE`)return!0;let a=i===`DIV`?1:i===`P`?2:0;a&&lr(t,a);for(let r of e.childNodes)if(!dr(r,t,n))return!1;return a&&lr(t,a),!0}function fr(){return m(new w({key:ar,props:{transformPastedHTML:(e,t)=>{if(or(e))return e;let n=t.state.selection.$from.parent;if(!n.inlineContent||n.type.spec.code)return e;let r=cr(e)??Dn(e);if(!r.trim())return e;let i=Z(r,{nodes:Lc(t.state.schema)}),a=ir(t.state.schema),o=document.createElement(`div`);return o.append(a.serializeFragment(i.content)),o.innerHTML}}}))}function pr(e){return new Be(e,[...$n(),...Gn(),...Be.fromSchema(e).rules])}const mr=new T(`meowdown-clipboard-parser`);function hr(){return m(({schema:e})=>new w({key:mr,props:{clipboardParser:pr(e)}}))}function gr(e,t){let n=t.replaceAll(/\r\n?/g,`
|
|
5
|
+
`).replace(/^\n+/,``).replace(/\n+$/,``);if(!n)return k.empty;let r=Z(n,{nodes:Lc(e)}),i=_(e,`paragraph`),a=+(r.childCount>0&&r.child(0).type===i),o=+(r.childCount>0&&r.child(r.childCount-1).type===i);return new k(r.content,a,o)}function _r(e,t,n){let r=n.marks(),i=Ve.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 Be.fromSchema(e).parseSlice(a,{preserveWhitespace:!0,context:n})}function vr(){let e;return m(new w({key:new T(`meowdown-plain-paste`),props:{clipboardTextParser:(t,n,r,i)=>{let{schema:a}=i.state;return r?_r(a,t,n):e=gr(a,t)},transformPasted:t=>{if(e==null)return t;let n=e;return e=void 0,n}}}))}function yr(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 br(e,t=0){return yr(e,96,t)}function xr(e,t={}){let n=new Tr;return t.frontmatter&&Sr(e.attrs.frontmatter,n),Er(e,n),n.finish()}function Sr(e,t){e!==null&&(t.write(`---`),t.write(`
|
|
6
6
|
`),e!==``&&(t.write(e),t.write(`
|
|
7
|
-
`)),t.write(`---`),t.closeBlock())}const
|
|
8
|
-
`+i.repeat(Math.max(1,r))),t.closeBlock();return}t.write(
|
|
7
|
+
`)),t.write(`---`),t.closeBlock())}const Cr=[``,`# `,`## `,`### `,`#### `,`##### `,`###### `];function wr(e,t){let n=e.attrs,r=n.setextUnderline;if(r!=null&&e.content.size>0&&n.level<=2){Ar(e,t);let i=n.level===1?`=`:`-`;t.write(`
|
|
8
|
+
`+i.repeat(Math.max(1,r))),t.closeBlock();return}t.write(Cr[n.level]??`# `),Ar(e,t);let i=n.closingHashes;i!=null&&i>0&&t.write(` `+`#`.repeat(i)),t.closeBlock()}var Tr=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(`
|
|
9
9
|
`)){this.parts.push(e);return}let t=e.split(`
|
|
10
10
|
`);for(let e=0;e<t.length;e++)e>0&&this.parts.push(`
|
|
11
11
|
`,this.linePrefix),t[e]!==``&&this.parts.push(t[e])}closeEmptyBlock(){if(!this.atLineStart||this.pendingFirst!==null){this.closeBlock();return}this.parts.length!==0&&(this.emitDeferredBlankLine(),this.deferredBlankPrefix=this.linePrefix)}closeBlock(){this.atLineStart&&this.pendingFirst!==null&&(this.emitDeferredBlankLine(),this.parts.push(this.pendingFirst.trimEnd()),this.pendingFirst=null,this.atLineStart=!1),this.atLineStart||this.parts.push(`
|
|
12
12
|
`),this.atLineStart=!0,this.deferredBlankPrefix=this.linePrefix}suppressBlank(){this.deferredBlankPrefix=null}withPrefix(e,t,n){let r=this.linePrefix,i=this.pendingFirst;if(this.linePrefix=r+e,t!==null){let e=i??r;this.pendingFirst=e+t}n(),this.linePrefix=r,this.pendingFirst=t===null?i:null}finish(){return this.parts.join(``).replace(/\s+$/,``)+`
|
|
13
13
|
`}emitDeferredBlankLine(){let e=this.deferredBlankPrefix;e!==null&&(this.parts.push(e.trimEnd(),`
|
|
14
|
-
`),this.deferredBlankPrefix=null)}};function
|
|
14
|
+
`),this.deferredBlankPrefix=null)}};function Er(e,t){switch(e.type.name){case`doc`:Dr(e,t);return;case`paragraph`:if(e.childCount===0){t.closeEmptyBlock();return}Ar(e,t),t.closeBlock();return;case`heading`:wr(e,t);return;case`blockquote`:t.withPrefix(`> `,`> `,()=>Dr(e,t)),t.closeBlock();return;case`list`:jr(e,t,kr(e));return;case`codeBlock`:Mr(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`:Fr(e,t);return;case`text`:e.text&&t.write(e.text);return}}function Dr(e,t,n=!1){let r=e.childCount,i=0;for(;i<r;){let a=e.child(i);if(!F(a,`list`)){n&&i>0&&t.suppressBlank(),Er(a,t),i++;continue}let o=i+1;for(;o<r&&F(e.child(o),`list`);)o++;let s=Or(e,i,o);for(let r=i;r<o;r++)(r===i?n&&i>0:s)&&t.suppressBlank(),jr(e.child(r),t,s);i=o}}function Or(e,t,n){for(let r=t;r<n;r++)if(!kr(e.child(r)))return!1;return!0}function kr(e){let t=e.childCount;for(let n=0;n<t;n++){let t=e.child(n).type.name;if(t!==`list`&&!(t===`paragraph`&&n===0))return!1}return!0}function Ar(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 jr(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,g=` `.repeat(m.length);t.withPrefix(g,h,()=>Dr(e,t,n)),t.closeBlock()}function Mr(e,t){let n=e.attrs,r=n.language||``,i=e.textContent;if(n.fenceStyle===`indented`&&!r){let e=Nr(i);if(e!=null){t.write(e),t.closeBlock();return}}if(n.fenceStyle===`dollar`&&r===`math`&&!Pr(i)){t.write(`$$`),t.write(`
|
|
15
15
|
`),i&&(t.write(i),t.write(`
|
|
16
|
-
`)),t.write(`$$`),t.closeBlock();return}let a=n.fenceStyle===`tilde`,o=
|
|
16
|
+
`)),t.write(`$$`),t.closeBlock();return}let a=n.fenceStyle===`tilde`,o=yr(i,a?126:96,2)+1,s=(a?`~`:"`").repeat(Math.max(n.fenceLength??0,o));t.write(s),r&&t.write(r),t.write(`
|
|
17
17
|
`),i&&(t.write(i),t.write(`
|
|
18
|
-
`)),t.write(s),t.closeBlock()}function
|
|
18
|
+
`)),t.write(s),t.closeBlock()}function Nr(e){if(e===``)return;let t=e.split(`
|
|
19
19
|
`);if(!(t[0]===``||t[t.length-1]===``)){for(let e=0;e<t.length;e++)t[e]!==``&&(t[e]=` ${t[e]}`);return t.join(`
|
|
20
|
-
`)}}function
|
|
21
|
-
`).some(e=>e.trim()===`$$`)}function
|
|
20
|
+
`)}}function Pr(e){return e.split(`
|
|
21
|
+
`).some(e=>e.trim()===`$$`)}function Fr(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);F(t,`tableHeaderCell`)&&(s=!0),o.push(Rr(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(Ir(n))}let c=`| `+s.join(` | `)+` |`,l=a>=0?r[a]:Array(i).fill(``);t.write(Lr(l,i)),t.write(`
|
|
22
22
|
`),t.write(c);for(let e=0;e<n;e++)e!==a&&(t.write(`
|
|
23
|
-
`),t.write(
|
|
23
|
+
`),t.write(Lr(r[e],i)));t.closeBlock()}function Ir(e){switch(e){case`left`:return`:--`;case`center`:return`:-:`;case`right`:return`--:`;default:return`---`}}function Lr(e,t){let n=`|`;for(let r=0;r<t;r++)n+=` `+(e[r]??``)+` |`;return n}function Rr(e){let t=e.textContent.trim();return!t.includes(`|`)&&!t.includes(`
|
|
24
24
|
`)?t:t.replaceAll(`|`,String.raw`\|`).replaceAll(`
|
|
25
|
-
`,` `)}function
|
|
25
|
+
`,` `)}function zr(e){if(e.depth===0)return!0;if(e.parentOffset!==0)return!1;for(let t=1;t<e.depth;t++)if(e.index(t)!==0)return!1;return!0}function Br(e){if(e.depth===0)return!0;if(e.parentOffset!==e.parent.content.size)return!1;for(let t=1;t<e.depth;t++)if(e.indexAfter(t)!==e.node(t).childCount)return!1;return!0}function Vr(e,t,n){let r=Hr(e,t,n),i;try{i=e.topNodeType.createAndFill(void 0,r)??void 0}catch{i=void 0}return i?xr(i).replace(/\n+$/,``):r.textBetween(0,r.size,`
|
|
26
26
|
`,`
|
|
27
|
-
`)}function
|
|
27
|
+
`)}function Hr(e,t,n){let{content:r,openStart:i,openEnd:a}=t;if(r.childCount===0||i===0&&a===0)return r;let o=y(n)&&zr(n.$from),s=y(n)&&Br(n.$to),c=r.childCount-1,l=[];return r.forEach((t,n,r)=>{r===0&&i>0&&!o?l.push(Wr(e,t)):r===c&&a>0&&!s?l.push(Ur(e,t,a)):l.push(t)}),O.from(l)}function Ur(e,t,n){if(F(t,`codeBlock`)||F(t,`table`))return Wr(e,t);if(F(t,`heading`)){let n=t.attrs;if(n.setextUnderline!=null)return Wr(e,t);if(n.closingHashes!=null)return t.type.create({...n,closingHashes:null},t.content,t.marks)}if(n<=1||t.childCount===0)return t;let r=t.childCount-1,i=t.child(r),a=Ur(e,i,n-1);return a===i?t:t.copy(t.content.replaceChild(r,a))}function Wr(e,t){let n=_(e,`paragraph`),r=t.textBetween(0,t.content.size,`
|
|
28
28
|
`,`
|
|
29
|
-
`);return n.create(void 0,r?e.text(r):void 0)}function Br(){return m(new S({key:new C(`meowdown-plain-text-copy`),props:{clipboardTextSerializer:(e,t)=>{let n=j(t.state)===`hide`?Vr(e):e;return Ir(t.state.schema,n,t.state.selection)}}}))}function Vr(e){return new D(Hr(e.content),e.openStart,e.openEnd)}function Hr(e){let t=[];return e.forEach(e=>{t.push(e.isTextblock?Wr(e):Ur(e))}),E.from(t)}function Ur(e){return e.childCount>0?e.copy(Hr(e.content)):e}function Wr(e){let t=e.type.schema,n=[];for(let r of An(e)){let e=r.atom;if(e!=null){if(Tn(e,`mdWikilink`)){let r=e.attrs,i=r.display||r.target;i&&n.push(t.text(i))}else n.push(...r.children);continue}for(let e of r.children)kn(e.marks)||n.push(e)}return e.copy(E.from(n))}function Gr(){return _(Zn(),Br(),ur(),sr(),pr())}const R=new Map,Kr=new Map,qr={math:`latex`};async function Jr(e){let t=R.get(e);if(t!==void 0)return t;let n=Ye.matchLanguageName(Xe,qr[e]??e,!0);if(!n)return R.set(e,null),null;let r=n.support;if(!r)try{r=await n.load()}catch(t){return console.error(`[meowdown] Failed to load language "${e}":`,t),R.set(e,null),null}return R.set(e,r),r}function Yr(e,t){let n=Kr.get(e);if(n)return n;let r=$e({parse:e=>t.language.parser.parse(e.content),highlighter:Ze});return Kr.set(e,r),r}const Xr=e=>{let t=e.language?.trim();if(!t)return[];let n=R.get(t);return n===null?[]:n?Yr(t,n)(e):Jr(t).then(()=>void 0)};function Zr(){return fe({parser:Xr,nodeTypes:[`codeBlock`]})}function Qr(e,t){let n=t.language.parser.parse(e),r=[];return Qe(n,Ze,(e,t,n)=>{r.push([e,t,n])}),r}function $r(e,t){let n=t.trim();if(!n)return[];let r=R.get(n);return r===null?[]:r?Qr(e,r):Jr(n).then(t=>t?Qr(e,t):[])}function ei(){return f({type:`codeBlock`,attr:`fenceStyle`,default:null,toDOM:e=>e==null?null:[`data-fence-style`,e],parseDOM:e=>{let t=e.getAttribute(`data-fence-style`);return t===`tilde`||t===`indented`||t===`dollar`?t:null}})}function ti(){return f({type:`codeBlock`,attr:`fenceLength`,default:null,toDOM:e=>e==null?null:[`data-fence-length`,String(e)],parseDOM:e=>{let t=wn(e.getAttribute(`data-fence-length`));return t!=null&&t>3?t:null}})}function ni(e){return{language:e[1]||``,fenceStyle:`tilde`}}function ri(){return rt({regex:/^~~~(\S*)\s$/,type:`codeBlock`,attrs:ni})}function ii(){return tt({regex:/^~~~(\S*)$/,type:`codeBlock`,attrs:ni})}function ai(){return tt({regex:/^\$\$$/,type:`codeBlock`,attrs:()=>({language:`math`,fenceStyle:`dollar`})})}function oi(){return _(de(),ei(),ti(),ri(),ii(),ai())}function si(e,t){return(n,r)=>{if(r){let i=w.create(n.doc,e,t);r(n.tr.setSelection(i))}return!0}}function ci(e,t,n){return(r,i)=>{if(i){let a=w.between(e,t,n);i(r.tr.setSelection(a))}return!0}}function li(e){return(t,n)=>{if(!e.trim())return!1;let r=X(e,{nodes:cc(t.schema)}).content;if(r.childCount===0)return!1;let i=r.childCount===1&&I(r.child(0),`paragraph`)?new D(r,1,1):new D(r,0,D.maxOpen(r).openEnd);if(n){let e=t.tr,r=e.selection;(!g(r)||!r.empty)&&e.setSelection(w.near(r.$from)),n(e.replaceSelection(i).scrollIntoView())}return!0}}function ui(e){return(t,n)=>{if(!e)return!1;let r=t.selection.$from;if(r.parent.type.spec.code)return!1;if(n){let i=r.parentOffset,a=i===0?``:r.parent.textBetween(i-1,i),o=a!==``&&!/\s/u.test(a),s=t.tr.insertText(o?` ${e}`:e);it(s),n(s.scrollIntoView())}return!0}}function di(){return ft(oe({type:`paragraph`}),dt(),pt)}function fi(){return(e,t)=>(t&&t(e.tr.scrollIntoView()),!0)}function pi(){return s({insertMarkdown:li,insertTrigger:ui,scrollIntoView:fi,selectText:si,selectTextBetween:ci,turnIntoText:di})}const mi=(e,t,n)=>{let{selection:r}=e;return r.empty||n?.composing?!1:(t?.(e.tr.setSelection(w.near(r.$head))),!0)};function hi(){return v(l({Escape:mi}),t.low)}function gi(){return f({type:`doc`,attr:`frontmatter`,default:null})}function _i(e,t){return t(e.state,e.dispatch,e)}function vi(e,t){if(t<0||t+1>e.doc.content.size)return;let n=e.doc.resolve(t),r=n.parent.maybeChild(n.index());if(!(r==null||!r.isText))return r.marks}function z(e,t){let n=vi(e,t);return n!=null&&n.some(e=>En.has(e.type.name))}function yi(e,t){if(t<0||t>e.doc.content.size)return!1;let n=e.doc.resolve(t);return n.parent.isTextblock&&!n.parent.type.spec.code}function B(e,t){if(!yi(e,t))return;let n=e.doc.resolve(t).start(),r=t;for(;r>n&&z(e,r-1);)r--;return r<t?{from:r,to:t}:void 0}function V(e,t){if(!yi(e,t))return;let n=e.doc.resolve(t).end(),r=t;for(;r<n&&z(e,r);)r++;return r>t?{from:t,to:r}:void 0}function bi(e,t){return z(e,t-1)&&z(e,t)}function xi(e,t){if(!bi(e,t))return;let n=B(e,t);if(!n)return;let r=V(e,t);if(r)return{from:n.from,to:r.to}}function Si(e,t,n){let r=vi(e,t);return r!=null&&n.isInSet(r)}function Ci(e,t){let n=vi(e,t);if(n==null)return;let r=ee(e.schema,`mdPack`),i=n.filter(e=>e.type===r);if(i.length===0)return;let a=e.doc.resolve(t),o=a.start(),s=a.end(),c;for(let n of i){let r=t;for(;r>o&&Si(e,r-1,n);)r--;let i=t+1;for(;i<s&&Si(e,i,n);)i++;(c==null||i-r<c.to-c.from)&&(c={from:r,to:i})}return c}function wi(e,t,n){let r=Ci(e,n===`from`?t.from:t.to-1);return r==null?!1:n===`from`?r.from===t.from:r.to===t.to}function Ti(e,t,n){let r=wi(e,t,`from`),i=wi(e,t,`to`);return r&&!i?t.from:i&&!r?t.to:n-t.from<=t.to-n?t.from:t.to}function Ei(e,t,n,r){if(!yi(e,n))return n;let i=xi(e,n);if(i!=null)return r?Ti(e,i,n):n>=t?i.to:i.from;if(!r)return n;let a=B(e,n);if(a!=null&&wi(e,a,`from`))return a.from;let o=V(e,n);return o!=null&&wi(e,o,`to`)?o.to:n}function Di(e,t){if(!yi(e,t))return;let n=z(e,t-1),r=z(e,t);if(n!==r)return r?`left`:`right`}function Oi(e,t){let n=Ci(e,t);if(n==null)return[];let r=V(e,n.from),i=B(e,n.to),a=[];return i!=null&&a.push(i),r!=null&&(i==null||r.from!==i.from)&&a.push(r),a}const ki=new C(`meowdown-hidden-run-snap`),Ai=new C(`meowdown-hidden-run-beforeinput`);function ji(){let e=!1;return new S({key:ki,props:{handleDOMEvents:{compositionstart:()=>(e=!0,!1),compositionend:()=>(e=!1,!1)}},appendTransaction:(t,n,r)=>{if(e||j(r)!==`hide`)return null;let i=r.selection;if(!g(i))return null;let a=t.some(e=>e.getMeta(`pointer`)!=null);if(i.empty){let e=Ei(r,n.selection.head,i.head,a);return e===i.head?null:r.tr.setSelection(w.create(r.doc,e))}let o=xi(r,i.from)?.from??i.from,s=xi(r,i.to)?.to??i.to;if(o===i.from&&s===i.to)return null;let c=i.anchor===i.from?o:s,l=i.head===i.from?o:s;return r.tr.setSelection(w.create(r.doc,c,l))}})}const Mi=(e,t)=>{if(j(e)!==`hide`)return!1;let n=e.selection;if(!g(n)||!n.empty)return!1;let r=Ei(e,n.head,n.head,!0);return r===n.head||t?.(e.tr.setSelection(w.create(e.doc,r))),!1};function Ni(e){return(t,n)=>{if(j(t)!==`hide`)return!1;let r=t.selection;if(!g(r)||!r.empty)return!1;let i=r.$head;if(!i.parent.isTextblock||i.parent.type.spec.code)return!1;let a=e===-1?B(t,r.head):V(t,r.head);if(a==null)return!1;let o=Oi(t,e===-1?a.to-1:a.from),s=t.tr;if(o.length===0)s.delete(a.from,a.to);else for(let e of o)s.delete(e.from,e.to);return n?.(s),!0}}const Pi=Ni(-1),Fi=Ni(1);function Ii(){return new S({key:Ai,props:{handleDOMEvents:{beforeinput:(e,t)=>{if(e.composing)return!1;let n=t.inputType===`deleteContentBackward`?Pi:t.inputType===`deleteContentForward`?Fi:void 0;return n==null||!_i(e,n)?!1:(t.preventDefault(),!0)}}}})}function Li(){return _(m(ji()),m(Ii()),v(l({Enter:Mi,Backspace:Pi,Delete:Fi}),t.highest))}function Ri(){return f({type:`horizontalRule`,attr:`marker`,default:null,toDOM:e=>e?[`data-hr-marker`,e]:null,parseDOM:e=>e.getAttribute(`data-hr-marker`)})}function zi(){return _(mt(),Ri())}function Bi(){return p({name:`htmlComment`,group:`block`,atom:!0,selectable:!1,attrs:{content:{default:``}},toDOM:e=>[`div`,{"data-html-comment":e.attrs.content,style:`display: none`}],parseDOM:[{tag:`div[data-html-comment]`,getAttrs:e=>({content:e.getAttribute(`data-html-comment`)??``})}]})}function Vi(e){let[t,n,r]=e;return[t,n,r.map(e=>e.toJSON())]}function Hi(e,t){let[n,r,i]=t;return[n,r,i.map(t=>Ue.fromJSON(e,t))]}function Ui(e,t){if(e===t)return!0;if(e.length!==t.length)return!1;for(let n=0;n<e.length;n++)if(!e[n].eq(t[n]))return!1;return!0}var Wi=class e extends bt{constructor(e){super(),this.chunks=e}apply(e){if(this.chunks.length===0)return xt.ok(e);let t=e.content.size,n;for(let[r,i,a]of this.chunks){if(r>=i)continue;let o=Math.max(0,Math.min(r,t)),s=Math.max(o,Math.min(i,t));if(o>=s)continue;let c=Ue.setFrom(a);e.nodesBetween(o,s,(t,r)=>{if(!t.isText)return!0;let i=Math.max(o,r),a=Math.min(s,r+t.nodeSize);if(i>=a)return!1;let l=t.marks;if(Ui(l,c))return!1;n??=new St(e);for(let e of l)n.removeMark(i,a,e);for(let e of c)n.addMark(i,a,e);return!1})}return xt.ok(n?n.doc:e)}invert(e){if(this.chunks.length===0)return Gi;let t=this.chunks[0][0],n=this.chunks[0][1];for(let[,e]of this.chunks)e>n&&(n=e);let r=e.content.size,i=Math.max(0,Math.min(t,r)),a=Math.max(i,Math.min(n,r));return new yt(i,a,e.slice(i,a),!1)}map(e){return null}toJSON(){return{stepType:`batchSetMark`,chunks:this.chunks.map(Vi)}}static fromJSON(t,n){let r=n.chunks;return new e(r.map(e=>Hi(t,e)))}};bt.jsonID(`batchSetMark`,Wi);const Gi=new Wi([]),Ki=/^<!--\s*(\{[^}]*\})\s*-->$/,qi=/<!--\s*\{[^}]*\}\s*-->$/;function Ji(e){let t=Ki.exec(e.trim());if(!t)return;let n;try{n=JSON.parse(t[1])}catch{return}if(!Se(n))return;let r=Yi(n);return Object.keys(r).length>0?r:void 0}function Yi(e){let t={},{width:n,height:r}=e;return typeof n==`number`&&Number.isFinite(n)&&n>0&&(t.width=Math.round(n)),typeof r==`number`&&Number.isFinite(r)&&r>0&&(t.height=Math.round(r)),t}function Xi(e){return`<!-- ${JSON.stringify(e)} -->`}function Zi(e){return e.replace(qi,``)}const Qi=/^(\d+)(?:x(\d+))?$/i;function $i(e){if(!e)return null;let t=Number.parseInt(e,10);return Number.isSafeInteger(t)&&t>0?t:null}function ea(e){let t=e.replace(/^!\[\[/,``).replace(/\]\]$/,``),n=t.lastIndexOf(`|`);if(n<0)return{target:t.trim(),display:``,width:null,height:null};let r=t.slice(0,n).trim(),i=t.slice(n+1).trim(),a=Qi.exec(i);if(!a)return{target:r,display:i,width:null,height:null};let o=$i(a[1]),s=$i(a[2]);return o==null||a[2]&&s==null?{target:r,display:i,width:null,height:null}:{target:r,display:``,width:o,height:s}}function ta(e,t,n){return`![[${e}|${Math.round(t)}x${Math.round(n)}]]`}function na(e){let t=e.split(/[?#]/,1)[0],n=t.split(/[/\\]/).findLast(Boolean)??t;try{return decodeURIComponent(n)}catch{return n}}function ra(e){let t=e.replace(/^\[\[/,``).replace(/\]\]$/,``),n=t.indexOf(`|`);return n<0?{target:t.trim(),display:``}:{target:t.slice(0,n).trim(),display:t.slice(n+1).trim()}}function ia(){return e=>{let t=e.attrs,n=document.createElement(`span`);n.className=`md-wikilink-view md-atom-view`;let r=document.createElement(`span`);r.className=`md-wikilink-view-preview md-atom-view-preview`,r.contentEditable=`false`,r.dataset.testid=`wikilink`,n.appendChild(r);let i=document.createElement(`span`);i.className=`md-wikilink-view-label`,i.contentEditable=`false`,i.textContent=t.display||t.target,r.appendChild(i);let a=document.createElement(`span`);return a.className=`md-wikilink-view-content md-atom-view-content`,n.appendChild(a),{dom:n,contentDOM:a,ignoreMutation:e=>!a.contains(e.target)}}}function aa(){return d({name:`mdWikilink`,constructor:ia()})}const oa=new Map([[y.Emphasis,`mdEm`],[y.StrongEmphasis,`mdStrong`],[y.InlineCode,`mdCode`],[y.Strikethrough,`mdDel`],[y.Highlight,`mdHighlight`],[y.EmphasisMark,`mdMark`],[y.CodeMark,`mdMark`],[y.LinkMark,`mdMark`],[y.StrikethroughMark,`mdMark`],[y.HighlightMark,`mdMark`],[y.URL,`mdLinkUri`],[y.LinkTitle,`mdLinkTitle`],[y.Hashtag,`mdTag`],[y.WikilinkMark,`mdMark`]]);function sa(e,t,n){let r=x(t),i=[];return la(r,[],0,t.length,t,e,i,n),i}function ca(e){return e.slice(1,-1).replaceAll(/\\(.)/g,`$1`)}function la(e,t,n,r,i,a,o,s){let c=n;for(let n=0;n<e.length;n++){let r=e[n];r.from>c&&H(o,c,r.from,t);let l=r.type;if(l===y.Link)if(!ua(r))la(r.children.filter(e=>e.type!==y.LinkMark&&e.type!==y.LinkLabel),t,r.from,r.to,i,a,o,s);else{let e=pa(r,t,i,a,s);e?H(o,r.from,r.to,e):ma(r,t,i,a,o,s)}else if(l===y.Image){let s=ha(r,e[n+1],i);ga(r,t,i,a,o,s),s&&n++,c=s?s.to:r.to;continue}else if(l===y.Wikilink)va(r,t,i,a,o);else if(l===y.WikiEmbed)ya(r,t,i,a,o,s);else if(l===y.InlineMath)_a(r,t,i,a,o);else if(l===y.URL){let e=ve(i.slice(r.from,r.to)),n=e?a.mdLinkText.create({href:e}):a.mdLinkUri.create();H(o,r.from,r.to,[...t,n])}else{let e;l===y.Emphasis?e=`italic`:l===y.StrongEmphasis?e=`bold`:l===y.InlineCode?e=`code`:l===y.Strikethrough?e=`strike`:l===y.Highlight?e=`highlight`:l===y.Autolink&&(e=`autolink`);let n=e?[...t,a.mdPack.create({key:e})]:t,c=oa.get(l),u=c?[...n,a[c].create()]:n;r.children.length===0?H(o,r.from,r.to,u):la(r.children,u,r.from,r.to,i,a,o,s)}c=r.to}c<r&&H(o,c,r,t)}function ua(e){let t=0;for(let n of e.children)n.type===y.LinkMark&&t++;return t>=3}function da(e){let t=-1,n=-1,r=null,i=null,a=0;for(let o of e.children){let e=o.type;e===y.LinkMark?(a++,a===1&&(t=o.to),a===2&&(n=o.from)):r==null&&e===y.URL?r=o:i==null&&e===y.LinkTitle&&(i=o)}return{labelFrom:t,labelTo:n,urlNode:r,titleNode:i}}function fa(e){let t=e.split(/[?#]/,1)[0],n=t.split(/[/\\]/).findLast(Boolean)??t;try{return decodeURIComponent(n)}catch{return n}}function pa(e,t,n,r,i){let a=i?.resolveFileLink;if(!a)return;let{labelFrom:o,labelTo:s,urlNode:c,titleNode:l}=da(e);if(o<0||s<0||!c)return;let u=n.slice(c.from,c.to);if(!u)return;let d=n.slice(o,s),f=l?ca(n.slice(l.from,l.to)):``;if(!a({href:u,label:d,title:f}))return;let p=d||fa(u);return[...t,r.mdFile.create({href:u,name:p,title:f})]}function ma(e,t,n,r,i,a){let{labelTo:o,urlNode:s,titleNode:c}=da(e),l=s?n.slice(s.from,s.to):``,u=c?ca(n.slice(c.from,c.to)):``,d=l?r.mdLinkText.create({href:l}):null,f=e=>o>=0&&e<o&&d!==null,p=r.mdPack.create({key:`link`,data:{href:l,title:u}}),m=[...t,p],h=e.from;for(let t of e.children){if(t.from>h){let e=f(h)?[...m,d]:m;H(i,h,t.from,e)}let e=f(t.from)?[...m,d]:m;if(t.type===y.Wikilink){va(t,e,n,r,i),h=t.to;continue}if(t.type===y.WikiEmbed){ya(t,e,n,r,i,a),h=t.to;continue}let o=oa.get(t.type),s=o?[...e,r[o].create()]:e;t.children.length===0?H(i,t.from,t.to,s):la(t.children,s,t.from,t.to,n,r,i,a),h=t.to}h<e.to&&H(i,h,e.to,m)}function ha(e,t,n){if(!t||t.type!==y.Comment||t.from!==e.to)return;let r=Ji(n.slice(t.from,t.to));if(r)return{magic:r,to:t.to}}function ga(e,t,n,r,i,a){let o=e.children.find(e=>e.type===y.URL);if(!o){ma(e,t,n,r,i,void 0);return}let s=e.children.filter(e=>e.type===y.LinkMark),c=e.children.find(e=>e.type===y.LinkTitle),l=n.slice(o.from,o.to),u=s.length>=2?n.slice(s[0].to,s[1].from):``,d=c?ca(n.slice(c.from,c.to)):``,f=a?.magic.width??null,p=a?.magic.height??null,m=a?.to??e.to;H(i,e.from,m,[...t,r.mdImage.create({src:l,alt:u,title:d,width:f,height:p,syntax:null,wikiTarget:null})])}function _a(e,t,n,r,i){let a=e.children.filter(e=>e.type===y.InlineMathMark);if(a.length<2){H(i,e.from,e.to,t);return}let o=n.slice(a[0].to,a[1].from),s=[...t,r.mdPack.create({key:`math`}),r.mdMath.create({formula:o})];H(i,e.from,a[0].to,[...s,r.mdMark.create()]),H(i,a[0].to,a[1].from,s),H(i,a[1].from,e.to,[...s,r.mdMark.create()])}function va(e,t,n,r,i){let{target:a,display:o}=ra(n.slice(e.from,e.to));H(i,e.from,e.to,[...t,r.mdWikilink.create({target:a,display:o})])}function ya(e,t,n,r,i,a){let o=ea(n.slice(e.from,e.to)),s=a?.resolveWikiEmbed?.(o);if(!s){H(i,e.from,e.to,t);return}if(s.kind===`image`){let n=s.src??o.target,a=(s.alt??o.display)||na(o.target);H(i,e.from,e.to,[...t,r.mdImage.create({src:n,alt:a,title:``,width:o.width,height:o.height,syntax:`wikiEmbed`,wikiTarget:o.target})]);return}if(s.kind===`file`){let n=s.href??o.target,a=(s.name??o.display)||na(o.target);H(i,e.from,e.to,[...t,r.mdFile.create({href:n,name:a,title:s.title??``})]);return}let c=s.target??o.target,l=s.display??o.display;H(i,e.from,e.to,[...t,r.mdWikilink.create({target:c,display:l})])}function H(e,t,n,r){if(t>=n)return;let i=e.at(-1);if(i&&i[1]===t&&Ui(i[2],r)){e[e.length-1]=[i[0],n,i[2]];return}e.push([t,n,r])}const ba=`inline-marks-applied`;let xa=0,Sa=0;function Ca(e,t){let n=1/0,r=-1/0;for(let t of e)for(let e of t.mapping.maps)e.forEach((e,t,i,a)=>{i<n&&(n=i),a>r&&(r=a)});let i=t.doc.content.size;return n>r?{from:0,to:i}:{from:Math.max(0,n),to:Math.min(i,r)}}function wa(e){let t=new WeakMap;function n(n,r,i){let a=t.get(n);if(a?Sa++:(xa++,a=sa(oc(i),n.textContent,e),t.set(n,a)),r===0)return a;let o=[];for(let[e,t,n]of a)o.push([e+r,t+r,n]);return o}function r(e,t){let r=[];return e.doc.nodesBetween(t.from,t.to,(t,i)=>{if(t.type.spec.code)return!1;if(!t.isTextblock)return!0;if(t.childCount===0)return!1;let a=n(t,i+1,e.schema);return a.length>0&&r.push(...a),!1}),r}return new S({key:new C(`inline-mark`),appendTransaction(e,t,n){for(let t of e)if(t.getMeta(ba))return null;let i=r(n,Ca(e,n));if(i.length===0)return null;let a=n.tr.step(new Wi(i));return a.setMeta(ba,!0),a.setMeta(`addToHistory`,!1),a},view(e){return e.dispatch(Ta(e.state)),{}}})}function Ta(e){return e.tr.setMeta(`inline-marks-trigger`,!0)}function Ea(e){return m(wa(e))}function Da(){return u({name:`mdImage`,inclusive:!1,attrs:{src:{default:``},alt:{default:``},title:{default:``},width:{default:null},height:{default:null},syntax:{default:null},wikiTarget:{default:null}},toDOM:()=>[`span`,{class:`md-image`},0],parseDOM:[{tag:`span.md-image`}]})}function Oa(){return u({name:`mdMark`,inclusive:!1,toDOM:()=>[`span`,{class:`md-mark`},0],parseDOM:[{tag:`span.md-mark`}]})}function ka(){return u({name:`mdEm`,toDOM:()=>[`em`,0],parseDOM:[{tag:`em`}]})}function Aa(){return u({name:`mdStrong`,toDOM:()=>[`strong`,0],parseDOM:[{tag:`strong`}]})}function ja(){return u({name:`mdCode`,toDOM:()=>[`code`,0],parseDOM:[{tag:`code`}]})}function Ma(){return u({name:`mdLinkText`,inclusive:!1,attrs:{href:{default:``}},toDOM:e=>[`a`,{class:`md-link`,href:e.attrs.href},0],parseDOM:[{tag:`a`,getAttrs:e=>({href:e.getAttribute(`href`)??``})}]})}function Na(){return u({name:`mdLinkUri`,inclusive:!1,toDOM:()=>[`span`,{class:`md-link-uri`},0],parseDOM:[{tag:`span.md-link-uri`}]})}function Pa(){return u({name:`mdLinkTitle`,inclusive:!1,toDOM:()=>[`span`,{class:`md-link-title`},0],parseDOM:[{tag:`span.md-link-title`}]})}function Fa(){return u({name:`mdDel`,toDOM:()=>[`del`,0],parseDOM:[{tag:`del`}]})}function Ia(){return u({name:`mdHighlight`,toDOM:()=>[`mark`,0],parseDOM:[{tag:`mark`}]})}function La(){return u({name:`mdTag`,toDOM:()=>[`span`,{class:`md-tag`},0],parseDOM:[{tag:`span.md-tag`}]})}function Ra(){return u({name:`mdWikilink`,inclusive:!1,attrs:{target:{default:``},display:{default:``}},toDOM:()=>[`span`,{class:`md-wikilink`},0],parseDOM:[{tag:`span.md-wikilink`}]})}function za(){return u({name:`mdFile`,inclusive:!1,attrs:{href:{default:``},name:{default:``},title:{default:``}},toDOM:()=>[`span`,{class:`md-file`},0],parseDOM:[{tag:`span.md-file`}]})}function Ba(){return u({name:`mdMath`,inclusive:!1,attrs:{formula:{default:``}},toDOM:()=>[`span`,{class:`md-math`},0],parseDOM:[{tag:`span.md-math`}]})}function Va(){return u({name:`mdPack`,excludes:``,inclusive:!1,attrs:{key:{},data:{default:null}},toDOM:e=>[`span`,{class:`md-pack`,"data-key":e.attrs.key},0],parseDOM:[{tag:`span.md-pack`}]})}function Ha(){return _(Oa(),ka(),Aa(),ja(),Ma(),Na(),Pa(),Fa(),Ia(),La(),Ra(),Da(),za(),Ba(),Va())}const U={em:{node:y.Emphasis,delim:`*`},strong:{node:y.StrongEmphasis,delim:`**`},code:{node:y.InlineCode,delim:"`"},del:{node:y.Strikethrough,delim:`~~`},highlight:{node:y.Highlight,delim:`==`}},Ua=new Set([y.EmphasisMark,y.CodeMark,y.LinkMark,y.StrikethroughMark,y.HighlightMark]);function Wa(e){return[e.children[0],e.children.at(-1)]}function Ga(e){let{type:t,children:n}=e;if(t===y.Emphasis||t===y.StrongEmphasis||t===y.Strikethrough||t===y.Highlight)return[n[0].to,n.at(-1).from];if(t===y.Link||t===y.Image){let e=n.find((e,t)=>t>0&&e.type===y.LinkMark);return e?[n[0].to,e.from]:null}return null}function Ka(e,t,n){for(let r of e){if(r.to<=t||r.from>=n||t<=r.from&&r.to<=n)continue;let i=Ga(r);return i&&i[0]<=t&&n<=i[1]?Ka(r.children,t,n):Ka(e,Math.min(t,r.from),Math.max(n,r.to))}return[t,n]}function qa(e,t,n){for(let r of e)if(!(r.to<=t||r.from>=n)&&(t>r.from||r.to>n))return qa(e,Math.min(t,r.from),Math.max(n,r.to));return[t,n]}function Ja(e,t,n){for(;t<n&&b(e.charCodeAt(t));)t++;for(;n>t&&b(e.charCodeAt(n-1));)n--;return[t,n]}function Ya(e,t,n,r){let i=_e(x(e),e=>e.type===r.node||Ua.has(e.type));for(let r=t;r<n;r++)if(!b(e.charCodeAt(r))&&i.every(e=>!(e.from<=r&&r<e.to)))return!1;return!0}function Xa(e,t,n,r,i){let a=x(e),o=_e(a,e=>e.type===r.node);return i?$a(e,o,t,n):Za(e,a,o,t,n,r)}function Za(e,t,n,r,i,a){for(let e=0;e!==i-r;){e=i-r,[r,i]=Ka(t,r,i);for(let e of n)e.to===r&&(r=e.from),e.from===i&&(i=e.to)}let o=[];for(let e of n)if(r<=e.from&&e.to<=i){let[t,n]=Wa(e);o.push({from:t.from,to:t.to,insert:``}),o.push({from:n.from,to:n.to,insert:``})}let[s,c]=Qa(e,r,i,o,a);return o.push({from:r,to:r,insert:s},{from:i,to:i,insert:c}),o}function Qa(e,t,n,r,i){if(i.node!==y.InlineCode)return[i.delim,i.delim];let a=e.slice(t,n);for(let e of[...r].sort((e,t)=>t.from-e.from))a=a.slice(0,e.from-t)+a.slice(e.to-t);let o="`".repeat(hr(a)+1),s=a.startsWith("`")||a.endsWith("`")?` `:``;return[o+s,s+o]}function $a(e,t,n,r){let i=[];for(let a of t){if(a.to<=n||a.from>=r)continue;let[t,o]=Wa(a),s=Math.max(n,t.to),c=Math.min(r,o.from);for(s>=c&&([s,c]=[t.to,o.from]),[s,c]=qa(a.children.slice(1,-1),s,c);s>t.to&&b(e.charCodeAt(s-1));)s--;for(;c<o.from&&b(e.charCodeAt(c));)c++;s>t.to?i.push({from:s,to:s,insert:e.slice(o.from,o.to)}):i.push({from:t.from,to:t.to,insert:``}),c<o.from?i.push({from:c,to:c,insert:e.slice(t.from,t.to)}):i.push({from:o.from,to:o.to,insert:``})}return i}function eo(e,t,n){let{delim:r}=n,i=r.length;if(e.slice(t-i,t)===r&&e.startsWith(r,t)&&e[t-i-1]!==r[0]&&e[t+i]!==r[0])return{kind:`unwrap`,from:t-i,to:t+i};let a=x(e),o=_e(a,e=>e.type===n.node).findLast(e=>e.from<=t&&t<=e.to);if(o){let[e,n]=Wa(o);return{kind:`move`,pos:t===o.from?e.to:t===o.to?n.from:o.to}}return to(a,t)||e[t-1]===r[0]||e[t]===r[0]?null:{kind:`insert`,pos:t}}function to(e,t){for(let n of e)if(n.from<t&&t<n.to){let e=Ga(n);return!e||t<e[0]||t>e[1]||to(n.children,t)}return!1}function W(e){return(t,n)=>{if(t.selection.empty)return no(e,t,n);let{from:r,to:i,anchor:a,head:o}=t.selection,s=[];t.doc.nodesBetween(r,i,(t,n)=>{if(t.type.spec.code)return!1;if(!t.isTextblock)return!0;let a=t.textContent,o=n+1,[c,l]=Ja(a,Math.max(r-o,0),Math.min(i-o,a.length));return c<l&&s.push({text:a,base:o,from:c,to:l,active:Ya(a,c,l,e)}),!1});let c=s.length>0&&s.every(e=>e.active),l=s.filter(e=>c||!e.active).flatMap(t=>Xa(t.text,t.from,t.to,e,c).map(e=>({from:e.from+t.base,to:e.to+t.base,insert:e.insert})));if(l.length===0)return!1;if(n){let e=t.tr;l.sort((e,t)=>t.from-e.from||t.to-e.to);for(let t of l)t.insert?e.insertText(t.insert,t.from,t.to):e.delete(t.from,t.to);e.setSelection(w.create(e.doc,e.mapping.map(a,a<=o?1:-1),e.mapping.map(o,o<a?1:-1))),n(e.scrollIntoView())}return!0}}function no(e,t,n){let{$from:r}=t.selection,i=r.parent;if(!i.isTextblock||i.type.spec.code)return!1;let a=eo(i.textContent,r.parentOffset,e);if(!a)return!1;if(n){let i=r.start(),o=t.tr;a.kind===`unwrap`&&o.delete(i+a.from,i+a.to),a.kind===`move`&&o.setSelection(w.create(o.doc,i+a.pos)),a.kind===`insert`&&(o.insertText(e.delim+e.delim,i+a.pos),o.setSelection(w.create(o.doc,i+a.pos+e.delim.length))),n(o.scrollIntoView())}return!0}function ro(){return s({toggleEm:()=>W(U.em),toggleStrong:()=>W(U.strong),toggleCode:()=>W(U.code),toggleDel:()=>W(U.del),toggleHighlight:()=>W(U.highlight)})}function io(){return l({"Mod-b":W(U.strong),"Mod-i":W(U.em),"Mod-e":W(U.code),"Mod-Shift-x":W(U.del),"Mod-Shift-h":W(U.highlight)})}function ao(){return _(ro(),io())}function oo(e,t,n){let r;return e.doc.nodesBetween(t.from,t.to,(e,i)=>(e.isText&&e.marks.some(e=>Tn(e,n))&&(r={from:Math.max(i,t.from),to:Math.min(i+e.nodeSize,t.to)}),!0)),r}function G(e,t){let n=k(e,t,`mdLinkText`),r=k(e,t,`mdPack`,{key:`link`})??k(e,t,`mdPack`,{key:`autolink`}),i=r??n;if(!i)return;let a=r?.mark.attrs,o=n?.mark.attrs?.href??``;if(!r||a?.key!==`link`){let t={from:i.from,to:i.to};return{unit:t,text:a?.key===`autolink`?oo(e,t,`mdLinkText`)??{from:i.from+1,to:i.to-1}:t,href:o,title:``}}let s=oo(e,i,`mdLinkUri`),c=s?s.from-2:i.to-3,l=s?s.from:i.to-1,u={from:i.from+1,to:c};return{unit:{from:i.from,to:i.to},text:u,label:u,dest:{from:l,to:i.to-1},href:a.data.href,title:a.data.title}}function so(e){let t=e.trim();return t?ve(t)??t:``}function co(e,t){return e+(t?` "${t.replaceAll(/(["\\])/g,String.raw`\$1`)}"`:``)}function lo(e){let{selection:t}=e,{$from:n,$to:r,empty:i}=t;if(i||!n.sameParent(r)||!g(t))return;let a=n.parent;if(!a.isTextblock||a.type.spec.code)return;let o=n.start(),[s,c]=Ja(a.textContent,n.parentOffset,r.parentOffset);if(!(s>=c))return{from:o+s,to:o+c}}function uo({href:e,title:t,wrapText:n=!0}={}){return(r,i)=>{let a=lo(r);if(!a)return!1;if(i){let{from:o,to:s}=a,c=r.tr,l=`](${co(so(e??``),t??``)})`;c.insertText(l,s).insertText(`[`,o);let u=s+1+l.length;c.setSelection(n?w.create(c.doc,o,u):w.create(c.doc,u)),c.scrollIntoView(),i(c)}return!0}}function fo(e){return(t,n)=>{let r=G(t,t.selection.from);if(!r?.dest)return!1;let i=co(so(e.href??r.href),e.title??r.title);return n&&n(t.tr.insertText(i,r.dest.from,r.dest.to).scrollIntoView()),!0}}function po(){return(e,t)=>{let n=G(e,e.selection.from);return n?.label?(t&&t(e.tr.delete(n.label.to,n.unit.to).delete(n.unit.from,n.label.from).scrollIntoView()),!0):!1}}function mo(){return s({insertLink:uo,updateLink:fo,removeLink:po})}function ho(e){return(t,n,r)=>{let i=G(t,t.selection.from);if(i){if(n&&r){let{unit:{from:a,to:o}}=i;n(t.tr.setSelection(w.create(t.doc,a,o)).scrollIntoView()),r.focus(),e({from:a,to:o,link:i})}return!0}let a=lo(t);if(a){if(n&&r){let{from:i,to:o}=a;n(t.tr.setSelection(w.create(t.doc,i,o)).scrollIntoView()),r.focus(),e({from:i,to:o,link:void 0})}return!0}return!1}}function go(e){return l({"Mod-k":ho(e)})}function _o(e){return e===`)`||e===`*`||e===`+`?e:void 0}function vo(e){return e===`X`?e:void 0}function yo(e){return So(e)?String(e):void 0}function bo(){return f({type:`list`,attr:`marker`,default:null,splittable:!0,toDOM:e=>{let t=_o(e);return t==null?null:[`data-list-marker`,t]},parseDOM:e=>{let t=e.getAttribute(`data-list-marker`);return t===`)`||t===`*`||t===`+`?t:null}})}function xo(){return f({type:`list`,attr:`taskMarker`,default:null,splittable:!0,toDOM:e=>{let t=vo(e);return t==null?null:[`data-list-task-marker`,t]},parseDOM:e=>e.getAttribute(`data-list-task-marker`)===`X`?`X`:null})}function So(e){return e===2||e===3||e===4}function Co(){return f({type:`list`,attr:`markerGap`,default:1,splittable:!0,toDOM:e=>{let t=yo(e);return t==null?null:[`data-list-marker-gap`,t]},parseDOM:e=>{let t=Number.parseInt(e.getAttribute(`data-list-marker-gap`)??``,10);return So(t)?t:1}})}function wo(e){let t=e.attrs;return{...Et(e),"data-list-marker":_o(t.marker),"data-list-task-marker":vo(t.taskMarker),"data-list-marker-gap":yo(t.markerGap)}}function To(){return o({serializeFragmentWrapper:e=>(...t)=>Eo(kt(e(...t))),serializeNodeWrapper:e=>(...t)=>{let n=e(...t);return be(n)?Eo(kt(n)):n},nodesFromSchemaWrapper:e=>(...t)=>({...e(...t),list:e=>At({node:e,nativeList:!0,getAttributes:wo})})})}function Eo(e){be(e)&&Do(e);for(let t of e.children)Eo(t);return e}function Do(e){if(!e.classList.contains(`prosemirror-flat-list`)||e.getAttribute(`data-list-kind`)!==`task`||e.children.length!==2)return;let t=e.children.item(0);if(!t||!t.classList.contains(`list-marker`))return;let n=Dt(t);if(!n)return;let r=e.children.item(1);if(!r||!r.classList.contains(`list-content`))return;let i=r.children.item(0);!i||![`P`,`H1`,`H2`,`H3`,`H4`,`H5`,`H6`].includes(i.tagName)||(e.replaceChildren(...r.children),i.prepend(n))}const Oo=[Mt(/^\s?([*-])\s$/,{kind:`bullet`,collapsed:!1}),Mt(/^\s?(\d+)\.\s$/,({match:e})=>{let t=e[1],n=t?parseInt(t,10):void 0;return{kind:`ordered`,collapsed:!1,order:n&&n>=2&&Number.isSafeInteger(n)?n:null}}),Mt(/^\s?\[([\sX]?)\]\s$/i,({match:e})=>({kind:`task`,checked:[`x`,`X`].includes(e[1]),collapsed:!1})),Mt(/^\s?\+\s$/,{kind:`task`,marker:`+`,checked:!1,collapsed:!1})];function ko(){return _(Oo.map(nt))}function Ao(){return O({kind:`task`,marker:`+`})}function jo(){return O({kind:`task`,marker:null})}function Mo(e){let{$from:t}=e.selection;for(let e=t.depth;e>0;e--){let n=t.node(e);if(I(n,`list`))return n.attrs}return null}function No(){return(e,t,n)=>{let r=Mo(e);return(r?.kind===`task`?r.marker===`+`?jo():Ao():O({kind:`task`,marker:null,checked:!1}))(e,t,n)}}function Po(){return s({cycleCheckableList:No,wrapInCircleTask:Ao,wrapInSquareTask:jo})}function Fo(){return(e,t,n)=>{let r=Mo(e),i=r?.kind===`task`&&r.marker!==`+`,a;return a=i&&!r?.checked?{kind:`task`,marker:r?.marker??null,checked:!0}:i&&r?.checked?{kind:`bullet`,marker:null,checked:!1}:{kind:`task`,marker:null,checked:!1},O(a)(e,t,n)}}function Io(){return(e,t,n)=>{let r=Mo(e),i=r?.kind===`task`&&r.marker===`+`,a;return a=i&&!r?.checked?{kind:`task`,marker:`+`,checked:!0}:i&&r?.checked?{kind:`bullet`,marker:null,checked:!1}:{kind:`task`,marker:`+`,checked:!1},O(a)(e,t,n)}}function Lo(e){return I(e,`list`)&&e.attrs.kind===`bullet`&&e.childCount>=2&&e.firstChild?.type!==e.type}const Ro=e=>{let t=e.attrs;return t.kind===`task`?{...t,checked:!t.checked}:Lo(e)?{...t,collapsed:!t.collapsed}:t};function zo(){return m(()=>[new S({props:{handleDOMEvents:{mousedown:(e,t)=>Ot({view:e,event:t,onListClick:Ro})}}}),Ct(),new S({props:{transformCopied:jt}}),wt()])}function Bo(){return s({toggleListCollapsed:()=>Tt({isToggleable:Lo})})}function Vo(){return l({"Mod-Enter":Fo(),"Mod-Shift-Enter":Io(),"Mod-.":Tt({isToggleable:Lo}),"Mod-Shift-7":ut({kind:`ordered`,collapsed:!1}),"Mod-Shift-8":ut({kind:`bullet`,collapsed:!1}),"Mod-Shift-9":ut({kind:`task`,checked:!1,collapsed:!1})})}function Ho(){return _(ct(),zo(),st(),at(),To(),ot(),ko(),Vo(),bo(),xo(),Co(),Po(),Bo())}let Uo;function Wo(){return Uo??=import(`./katex-chunk-Ch7kgbXr.js`).then(e=>e.render),Uo}function Go(e,t,n,r){try{e(n,t,{displayMode:r,throwOnError:!1,output:`mathml`})}catch(e){t.textContent=String(e)}}var Ko=class{#e;#t;#n;#r;constructor(e,t){this.#r=e.attrs.formula,this.#e=document.createElement(`span`),this.#e.className=`md-math-view`,this.#n=document.createElement(`span`),this.#n.className=`md-math-view-preview`,this.#n.dataset.testid=`math-preview`,this.#n.contentEditable=`false`,this.#n.addEventListener(`mousedown`,e=>{e.preventDefault();let n=t.posAtDOM(this.#t,0);if(n<0)return;let r=w.near(t.state.doc.resolve(n),1);t.dispatch(t.state.tr.setSelection(r)),t.focus()}),this.#t=document.createElement(`span`),this.#t.className=`md-math-view-content`,this.#e.appendChild(this.#n),this.#e.appendChild(this.#t),this.#i()}get dom(){return this.#e}get contentDOM(){return this.#t}update(e){let t=e.attrs.formula;return t!==this.#r&&(this.#r=t,this.#i()),!0}ignoreMutation(e){return!this.#t.contains(e.target)}#i(){let e=this.#r;Wo().then(t=>{e===this.#r&&Go(t,this.#n,e,!1)})}};function qo(){return d({name:`mdMath`,constructor:(e,t)=>new Ko(e,t)})}function Jo(e){return e===`left`||e===`center`||e===`right`?e:null}function Yo(){return f({type:`tableCell`,attr:`align`,default:null,toDOM:e=>e?[`data-align`,e]:null,parseDOM:e=>Jo(e.getAttribute(`data-align`))})}function Xo(){return f({type:`tableHeaderCell`,attr:`align`,default:null,toDOM:e=>e?[`data-align`,e]:null,parseDOM:e=>Jo(e.getAttribute(`data-align`))})}function Zo(e){for(let t=0;t<e.childCount;t++){let n=e.child(t);for(let e=0;e<n.childCount;e++)if(I(n.child(e),`tableHeaderCell`))return t}return 0}function Qo(e){return e.child(Zo(e))}function $o(e,t){return t>=e.childCount?null:e.child(t).attrs.align??null}function es(e,t,n){if(e.childCount===0)return;let r=Qo(e),i=t+1;for(let t=0;t<e.childCount;t++){let a=e.child(t),o=i+1;for(let e=0;e<a.childCount;e++){let t=a.child(e),i=$o(r,e);(t.attrs.align??null)!==i&&n.setNodeMarkup(o,void 0,{...t.attrs,align:i}),o+=t.nodeSize}i+=a.nodeSize}}function ts(e){let t,n;for(let r of e){if(!r.docChanged)continue;t!=null&&n!=null&&(t=r.mapping.map(t,-1),n=r.mapping.map(n,1));let e=r.mapping;for(let[r,i]of e.maps.entries()){let a=e.slice(r+1);i.forEach((e,r,i,o)=>{let s=a.map(i,-1),c=a.map(o,1);t=t==null?s:Math.min(t,s),n=n==null?c:Math.max(n,c)})}}if(!(t==null||n==null))return{from:t,to:n}}function ns(){return new S({key:new C(`table-align-sync`),appendTransaction(e,t,n){if(!e.some(e=>e.docChanged))return;let r=ts(e);if(!r)return;let i=n.doc,a=Math.max(0,Math.min(r.from,i.content.size)),o=Math.max(a,Math.min(r.to,i.content.size)),s;return i.nodesBetween(a,o,(e,t)=>I(e,`table`)?(s??=n.tr,es(e,t,s),!1):!0),s?.docChanged?s:void 0}})}function rs(){return m(ns())}function is(e){let{selection:t}=e;if(Vt(t)){let{$anchorCell:e,$headCell:n}=t,r=e.depth-1,i=e.index(),a=n.index();return{table:e.node(r),tablePos:e.before(r),firstColumn:Math.min(i,a),lastColumn:Math.max(i,a)}}let{$from:n}=t;for(let e=n.depth;e>2;e--){let t=n.node(e).type.name;if(t===`tableCell`||t===`tableHeaderCell`){let t=n.index(e-1);return{table:n.node(e-2),tablePos:n.before(e-2),firstColumn:t,lastColumn:t}}}}function as(e){return(t,n)=>{let r=is(t);if(!r||r.table.childCount===0)return!1;if(n){let{table:i,tablePos:a,firstColumn:o,lastColumn:s}=r,c=Zo(i),l=a+1;for(let e=0;e<c;e++)l+=i.child(e).nodeSize;let u=i.child(c),d=t.tr,f=l+1;for(let t=0;t<u.childCount;t++){let n=u.child(t);t>=o&&t<=s&&(n.attrs.align??null)!==e&&d.setNodeMarkup(f,void 0,{...n.attrs,align:e}),f+=n.nodeSize}n(d)}return!0}}function os(e){let t=is(e);if(!(!t||t.table.childCount===0))return $o(Qo(t.table),t.lastColumn)??void 0}function ss(){return s({setTableColumnAlign:as})}function cs(){return _(Yo(),Xo(),rs(),ss())}function ls(e){let{$from:t}=e.selection;for(let e=t.depth;e>0;e--){let n=t.node(e).type.name;if(n===`tableCell`||n===`tableHeaderCell`)return!0}return!1}const us=`paragraph`;function ds(){return _(p({name:`tableCell`,content:us}),p({name:`tableHeaderCell`,content:us}))}const fs=(e,t)=>{let{selection:n}=e;return!Vt(n)||!n.isColSelection()||!n.isRowSelection()?!1:Bt(e,t)};function ps(){return v(l({Backspace:fs,Delete:fs}),t.high)}function ms(){return _(zt(),Rt(),Nt(),Lt(),ds(),cs(),It({allowTableNodeSelection:!0}),Pt(),Ft(),ps())}function hs(e){let{selection:t}=e,{$from:n,$to:r}=t;if(ae(t)&&n.depth===0||n.depth>0&&r.depth>0&&n.index(0)===r.index(0))return n.index(0)}function gs(e){return(t,n)=>{if(ls(t))return!1;let r=hs(t);if(r==null)return!1;let i=r+e;if(i<0||i>=t.doc.childCount)return!1;if(n){let{selection:a}=t,o=Math.min(r,i),s=a.$from.posAtIndex(o,0),c=t.doc.child(o),l=t.doc.child(o+1),u=t.tr.replaceWith(s,s+c.nodeSize+l.nodeSize,[l,c]),d=e===-1?-c.nodeSize:l.nodeSize,f=ae(a)?Ae.create(u.doc,a.from+d):w.create(u.doc,a.anchor+d,a.head+d);u.setSelection(f),n(u.scrollIntoView())}return!0}}function _s(e){return(t,n,r)=>lt(e)(t,n,r)||gs(e===`up`?-1:1)(t,n,r)}function vs(){return l({"Alt-ArrowUp":_s(`up`),"Alt-ArrowDown":_s(`down`)})}const K=new C(`meowdownPendingReplacement`);function q(e){return K.getState(e)?.pending??null}function ys(e,t){switch(e.type){case`start`:return{pending:{from:e.from,to:e.to,mode:e.mode,text:``}};case`append`:return t.pending?{pending:{...t.pending,text:t.pending.text+e.text}}:t;case`accept`:return t.pending?{pending:null,ended:{pending:t.pending,outcome:`accepted`}}:t;case`discard`:return t.pending?{pending:null,ended:{pending:t.pending,outcome:`discarded`}}:t}}const bs=new S({key:K,state:{init:()=>({pending:null}),apply:(e,t)=>{let n=e.getMeta(K);if(n)return ys(n,t);if(e.docChanged&&t.pending){let n=e.mapping.mapResult(t.pending.from,1),r=e.mapping.mapResult(t.pending.to,-1),i=Math.min(n.pos,r.pos),a=Math.max(n.pos,r.pos);return(n.deletedAfter&&r.deletedBefore||i>=a)&&t.pending.mode===`replace`?{pending:null,ended:{pending:t.pending,outcome:`discarded`}}:{pending:{...t.pending,from:i,to:a}}}return t}},props:{decorations:e=>{let t=q(e);return!t||t.from>=t.to?null:T.create(e.doc,[Me.inline(t.from,t.to,{class:`md-pending-replacement`})])}}});function xs(e){return(t,n)=>{let{from:r,to:i,mode:a}=e;return r<0||i>t.doc.content.size||r>i||r===i&&a===`replace`?!1:(n?.(t.tr.setMeta(K,{type:`start`,from:r,to:i,mode:a})),!0)}}function Ss(e){return(t,n)=>q(t)?(n?.(t.tr.setMeta(K,{type:`append`,text:e})),!0):!1}function Cs(){return(e,t)=>q(e)?(t?.(e.tr.setMeta(K,{type:`discard`})),!0):!1}function ws(e={}){return(t,n)=>{let r=q(t);if(!r||!r.text.trim())return!1;if(n){let i=e.mode??r.mode,a=cc(t.schema),o=X(r.text,{nodes:a}),s=t.tr;if(s.setMeta(K,{type:`accept`}),i===`append`){let e=t.doc.resolve(r.to).after(1);s.insert(e,o.content),s.setSelection(w.near(s.doc.resolve(e+o.content.size),-1))}else{let e=t.doc.resolve(r.from),n=t.doc.resolve(r.to),i=o.childCount===1?o.firstChild:null;i!=null&&I(i,`paragraph`)&&e.sameParent(n)&&e.parent.isTextblock?(s.replaceWith(r.from,r.to,i.content),s.setSelection(w.near(s.doc.resolve(r.from+i.content.size),-1))):(s.replaceRange(r.from,r.to,new D(o.content,0,0)),s.setSelection(w.near(s.doc.resolve(s.mapping.map(r.to)),-1)))}n(s.scrollIntoView())}return!0}}function Ts(){return s({startPendingReplacement:xs,appendPendingReplacementText:Ss,acceptPendingReplacement:ws,discardPendingReplacement:Cs})}function Es(){return l({"Mod-Enter":ws(),Escape:Cs()})}function Ds(){return _(m(bs),Ts(),Es())}function Os(e){return m(new S({view:()=>({update:(t,n)=>{let r=K.getState(n),i=K.getState(t.state);!i||r===i||(i.pending?i.pending!==r?.pending&&e({type:`update`,pending:i.pending}):i.ended&&i.ended!==r?.ended&&e({type:`ended`,pending:i.ended.pending,outcome:i.ended.outcome}))}})}))}function ks(e){return e.left===e.right&&e.top===e.bottom}function J(e,t,n){if(t<0||t>e.state.doc.content.size)return;let r;try{r=e.coordsAtPos(t,n)}catch{return}return ks(r)?void 0:r}function As(e){let t=e.dom.ownerDocument.getSelection();if(t==null||t.rangeCount===0||!e.dom.contains(t.anchorNode))return;let n=t.getRangeAt(0).cloneRange();n.collapse(!0);let r=Array.from(n.getClientRects()).filter(e=>e.height>0);if(r.length===0)return;let i=r[r.length-1];return{left:i.left,top:i.top,height:i.height}}function js(e){let t=e.state,n=t.selection.head,r=B(t,n),i=V(t,n),a=r==null,o=[[n,a],[n,!a]];r!=null&&o.push([r.from,!0]),i!=null&&o.push([i.to,!1]);for(let[t,n]of o){let r=J(e,t,n?-1:1);if(r!=null&&r.bottom>r.top)return{left:r.left,top:r.top,height:r.bottom-r.top}}}function Ms(e){let t=e.state,n=t.selection.head;for(let r of $t){let i=k(t,n,r);if(i==null||i.from!==n&&i.to!==n)continue;let a=Ps(e,i.from+1);if(a==null)continue;let o=Array.from(a.getClientRects()).filter(e=>e.height>0);if(o.length===0)continue;let s=i.to===n,c=s?o[o.length-1]:o[0];return{left:s?c.right:c.left,top:c.top,height:c.height}}}function Ns(e,t,n){let r=e.state;for(let i of $t){let a=k(r,t,i);if(a==null)continue;let o=Ps(e,a.from+1);if(o==null)continue;let s=Array.from(o.getClientRects()).filter(e=>e.height>0);if(s.length!==0)return n===1?s[0]:s[s.length-1]}}function Ps(e,t){let{node:n}=e.domAtPos(t,0);return(n instanceof Element?n:n.parentElement)?.closest(`.md-atom-view`)?.querySelector(`.md-atom-view-preview`)??void 0}function Fs(e){return js(e)??Ms(e)}const Is=new C(`meowdown-scroll-to-selection`);function Ls(e){let t=e.state.selection;if(!g(t)||J(e,t.head,1)!=null)return!1;let n=Fs(e);if(n==null)return!1;let r=e.domAtPos(t.head).node;return Vs(e,{left:n.left,right:n.left,top:n.top,bottom:n.top+n.height},r),!0}function Y(e,t){return typeof e==`number`?e:e[t]}function Rs(e){let t=e.assignedSlot??e.parentNode;return t?.nodeType===11?t.host:t}function zs(e){let t=e.defaultView?.visualViewport;return t?{left:0,right:t.width,top:0,bottom:t.height}:{left:0,right:e.documentElement.clientWidth,top:0,bottom:e.documentElement.clientHeight}}function Bs(e){let t=e.getBoundingClientRect(),n=t.width/e.offsetWidth||1,r=t.height/e.offsetHeight||1;return{left:t.left,right:t.left+e.clientWidth*n,top:t.top,bottom:t.top+e.clientHeight*r}}function Vs(e,t,n){let r=e.someProp(`scrollThreshold`)??0,i=e.someProp(`scrollMargin`)??5,a=e.dom.ownerDocument;for(let e=n;e;){if(e.nodeType!==1){e=Rs(e);continue}let n=e,o=n===a.body,s=o?zs(a):Bs(n),c=0,l=0;if(t.top<s.top+Y(r,`top`)?l=-(s.top-t.top+Y(i,`top`)):t.bottom>s.bottom-Y(r,`bottom`)&&(l=t.bottom-t.top>s.bottom-s.top?t.top+Y(i,`top`)-s.top:t.bottom-s.bottom+Y(i,`bottom`)),t.left<s.left+Y(r,`left`)?c=-(s.left-t.left+Y(i,`left`)):t.right>s.right-Y(r,`right`)&&(c=t.right-s.right+Y(i,`right`)),c||l)if(o)a.defaultView?.scrollBy(c,l);else{let e=n.scrollLeft,r=n.scrollTop;l&&(n.scrollTop+=l),c&&(n.scrollLeft+=c);let i=n.scrollLeft-e,a=n.scrollTop-r;t={left:t.left-i,top:t.top-a,right:t.right-i,bottom:t.bottom-a}}let u=o?`fixed`:getComputedStyle(n).position;if(/^(?:fixed|sticky)$/.test(u))break;e=u===`absolute`?n.offsetParent:Rs(n)}}function Hs(){return m(new S({key:Is,props:{handleScrollToSelection:Ls}}))}function Us(e,t){return(n,r)=>{let i=e<0?je.atStart(n.doc):je.atEnd(n.doc),a=t?w.between(n.selection.$anchor,i.$head):i;return n.selection.eq(a)||r?.(n.tr.setSelection(a).scrollIntoView()),!0}}function Ws(){return l({"Meta-ArrowUp":Us(-1,!1),"Meta-ArrowDown":Us(1,!1),"Shift-Meta-ArrowUp":Us(-1,!0),"Shift-Meta-ArrowDown":Us(1,!0)})}function Gs(e){e.offsetWidth}const Ks=new C(`meowdown-virtual-caret`),qs=[`md-virtual-caret-blink`,`md-virtual-caret-blink2`],Js=`data-meowdown-virtual-caret`;function Ys(e){let t=e.height*.19999999999999996;return{left:e.left,top:e.top-t/2,height:e.height+t}}function Xs(e){let t=As(e)??js(e);return t==null?Ms(e):Ys(t)}function Zs(e,t){return e==null||t==null?e===t:e.left===t.left&&e.top===t.top&&e.height===t.height}var Qs=class{#e;#t;#n;#r;#i;#a;#o;#s=0;constructor(e){this.#e=e,this.#r=e.dom.ownerDocument,this.#t=this.#r.createElement(`div`),this.#t.className=`md-virtual-caret-layer`,this.#n=this.#t.appendChild(this.#r.createElement(`div`)),this.#n.className=`md-virtual-caret`,this.#n.dataset.testid=`virtual-caret`,e.dom.insertAdjacentElement(`afterend`,this.#t),this.#r.addEventListener(`selectionchange`,this.#l),typeof ResizeObserver<`u`&&(this.#i=new ResizeObserver(this.#l),this.#i.observe(e.dom)),this.#l()}update(e,t){e.state.selection.eq(t.selection)||this.#c(),this.#l()}destroy(){this.#r.removeEventListener(`selectionchange`,this.#l),this.#i?.disconnect(),this.#t.remove()}#c(){this.#s=1-this.#s,this.#n.style.animationName=qs[this.#s]}#l=()=>{let e=this.#e;if(e.isDestroyed)return;let t=e.state,n=t.selection,r=g(n)&&n.empty?Xs(e):void 0,i=r!=null&&j(t)===`hide`?Di(t,n.head):void 0;if(Zs(r,this.#a)&&i===this.#o)return;let a=this.#a==null;if(this.#a=r,this.#o=i,i==null?delete this.#n.dataset.tail:this.#n.dataset.tail=i,r==null){this.#n.style.visibility=`hidden`,e.dom.removeAttribute(Js);return}let o=this.#t.getBoundingClientRect();a&&(this.#n.style.transitionProperty=`none`),this.#n.style.visibility=``,this.#n.style.left=`${r.left-o.left}px`,this.#n.style.top=`${r.top-o.top}px`,this.#n.style.height=`${r.height}px`,e.dom.setAttribute(Js,``),a&&(Gs(this.#n),this.#n.style.transitionProperty=``)}};function $s(){return m(new S({key:Ks,view:e=>new Qs(e)}))}function ec(e){return _(Yn(),Te(),gi(),Oe(),we(),Ho(),Gn(),ms(),oi(),zi(),Bi(),Ha(),Zr(),hi(),vs(),Ws(),Ea(e),ao(),mo(),aa(),qo(),Yt(e.markMode??`focus`),Gr(),$s(),Hs(),Li(),fn({marks:$t.map(e=>({name:e,modes:[`hide`,`focus`,`show`]}))}),a(),i(),c(),Ee(),ke(),De(),pi(),Ds())}function tc(e={}){return ec(e)}const nc=Ce(()=>{let e=tc().schema;if(e==null)throw Error(`Unexpected empty schema`);return e}),rc=Ce(()=>r(nc())),ic=Ce(()=>n(nc())),ac=`meowdown_mark_builders`;function oc(e){let t=e.cached[ac];if(t)return t;let r=n(e);return e.cached[ac]=r,r}const sc=`meowdown_node_builders`;function cc(e){let t=e.cached[sc];if(t)return t;let n=r(e);return e.cached[sc]=n,n}function X(e,t={}){let{nodes:n=rc(),frontmatter:r=!1}=t,i,a=e;if(r){let[t,n]=uc(e);i=t,n&&(a=e.slice(n))}let o=dc(n,ye.parse(a).cursor(),a);return n.doc(i===void 0?{}:{frontmatter:i},o)}const lc=/^---[ \t]*\r?\n([\s\S]*?\n)?---[ \t]*(?:\r?\n|$)/;function uc(e){let t=lc.exec(e);return t?[(t[1]??``).replace(/\r?\n$/,``),t[0].length]:[]}function dc(e,t,n){let r=[];if(!t.firstChild())return r;let i;do i!=null&&fc(r,e,n,i,t.from),i=t.to,r.push(...pc(e,t,n));while(t.nextSibling());return t.parent(),r}function fc(e,t,n,r,i){let a=0;for(let e=r;e<i;e++)n.charCodeAt(e)===10&&a++;for(let n=2;n<a;n++)e.push(t.paragraph())}function pc(e,t,n){switch(t.type.id){case y.ATXHeading1:return[Z(e,t,n,1,!1)];case y.ATXHeading2:return[Z(e,t,n,2,!1)];case y.ATXHeading3:return[Z(e,t,n,3,!1)];case y.ATXHeading4:return[Z(e,t,n,4,!1)];case y.ATXHeading5:return[Z(e,t,n,5,!1)];case y.ATXHeading6:return[Z(e,t,n,6,!1)];case y.SetextHeading1:return[Z(e,t,n,1,!0)];case y.SetextHeading2:return[Z(e,t,n,2,!0)];case y.Paragraph:return[yc(e,t,n)];case y.CommentBlock:return[bc(e,t,n)];case y.HTMLBlock:case y.ProcessingInstructionBlock:return[yc(e,t,n)];case y.Blockquote:return[xc(e,t,n)];case y.BulletList:return Sc(e,t,n,`bullet`);case y.OrderedList:return Sc(e,t,n,`ordered`);case y.FencedCode:case y.CodeBlock:return[wc(e,t,n)];case y.BlockMath:return[Tc(e,t,n)];case y.HorizontalRule:{let r=n.slice(t.from,t.to).trimEnd();return[e.horizontalRule({marker:r===`---`?null:r})]}case y.Table:return[Ec(e,t,n)];case y.Task:return[yc(e,t,n)];default:return n.slice(t.from,t.to).trim()===``?[]:(console.warn(`[meowdown] unsupported lezer block "${t.type.name}"`),[yc(e,t,n)])}}function Z(e,t,n,r,i){let a=t.from,o=t.from,s=t.to,c=-1,l=-1;if(t.firstChild()){t.type.id===y.HeaderMark&&t.from===a&&(o=t.to);let e=-1,n=-1,r=-1;do e=t.type.id,n=t.from,r=t.to;while(t.nextSibling());e===y.HeaderMark&&n>o&&(s=n,c=n,l=r),t.parent()}let u=_c(n.slice(o,s),Q(n,o)).trim(),d=i?mc(n,c,l)||1:null,f=!i&&c>=0&&hc(n,c,l)||null;return e.heading({level:r,setextUnderline:d,closingHashes:f},u)}function mc(e,t,n){if(t<0)return 0;let r=0;for(let i=t;i<n;i++){let t=e.charCodeAt(i);(t===61||t===45)&&r++}return r}function hc(e,t,n){if(t<0)return 0;let r=0;for(let i=t;i<n;i++)e.charCodeAt(i)===35&&r++;return r}function Q(e,t){let n=e.lastIndexOf(`
|
|
30
|
-
`,t-1)+1,r=0;for(let i=n;i<t;i++)r+=e.charCodeAt(i)===9?4-r%4:1;return r}function
|
|
29
|
+
`);return n.create(void 0,r?e.text(r):void 0)}function Gr(){return m(new w({key:new T(`meowdown-plain-text-copy`),props:{clipboardTextSerializer:(e,t)=>{let n=j(t.state)===`hide`?Kr(e):e;return Vr(t.state.schema,n,t.state.selection)}}}))}function Kr(e){return new k(qr(e.content),e.openStart,e.openEnd)}function qr(e){let t=[];return e.forEach(e=>{t.push(e.isTextblock?Yr(e):Jr(e))}),O.from(t)}function Jr(e){return e.childCount>0?e.copy(qr(e.content)):e}function Yr(e){let t=e.type.schema,n=[];for(let r of Fn(e)){let e=r.atom;if(e!=null){if(An(e,`mdWikilink`)){let r=e.attrs,i=r.display||r.target;i&&n.push(t.text(i))}else n.push(...r.children);continue}for(let e of r.children)Pn(e.marks)||n.push(e)}return e.copy(O.from(n))}function Xr(){return b(nr(),Gr(),hr(),fr(),vr())}const L=new Map,Zr=new Map,Qr={math:`latex`};async function $r(e){let t=L.get(e);if(t!==void 0)return t;let n=Je.matchLanguageName(Ye,Qr[e]??e,!0);if(!n)return L.set(e,null),null;let r=n.support;if(!r)try{r=await n.load()}catch(t){return console.error(`[meowdown] Failed to load language "${e}":`,t),L.set(e,null),null}return L.set(e,r),r}function ei(e,t){let n=Zr.get(e);if(n)return n;let r=Qe({parse:e=>t.language.parser.parse(e.content),highlighter:Xe});return Zr.set(e,r),r}const ti=e=>{let t=e.language?.trim();if(!t)return[];let n=L.get(t);return n===null?[]:n?ei(t,n)(e):$r(t).then(()=>void 0)};function ni(){return le({parser:ti,nodeTypes:[`codeBlock`]})}function ri(e,t){let n=t.language.parser.parse(e),r=[];return Ze(n,Xe,(e,t,n)=>{r.push([e,t,n])}),r}function ii(e,t){let n=t.trim();if(!n)return[];let r=L.get(n);return r===null?[]:r?ri(e,r):$r(n).then(t=>t?ri(e,t):[])}function ai(){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 oi(){return f({type:`codeBlock`,attr:`fenceLength`,default:null,toDOM:e=>e==null?null:[`data-fence-length`,String(e)],parseDOM:e=>{let t=On(e.getAttribute(`data-fence-length`));return t!=null&&t>3?t:null}})}function si(e){return{language:e[1]||``,fenceStyle:`tilde`}}function ci(){return nt({regex:/^~~~(\S*)\s$/,type:`codeBlock`,attrs:si})}function li(){return et({regex:/^~~~(\S*)$/,type:`codeBlock`,attrs:si})}function ui(){return et({regex:/^\$\$$/,type:`codeBlock`,attrs:()=>({language:`math`,fenceStyle:`dollar`})})}function di(){return b(ce(),ai(),oi(),ci(),li(),ui())}function fi(e,t){return(n,r)=>{if(r){let i=E.create(n.doc,e,t);r(n.tr.setSelection(i))}return!0}}function pi(e,t,n){return(r,i)=>{if(i){let a=E.between(e,t,n);i(r.tr.setSelection(a))}return!0}}function mi(e){return(t,n)=>{if(!e.trim())return!1;let r=Z(e,{nodes:Lc(t.schema)}).content;if(r.childCount===0)return!1;let i=r.childCount===1&&F(r.child(0),`paragraph`)?new k(r,1,1):new k(r,0,k.maxOpen(r).openEnd);if(n){let e=t.tr,r=e.selection;(!y(r)||!r.empty)&&e.setSelection(E.near(r.$from)),n(e.replaceSelection(i).scrollIntoView())}return!0}}function hi(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);rt(s),n(s.scrollIntoView())}return!0}}function gi(){return ft(re({type:`paragraph`}),ut(),pt)}function _i(){return(e,t)=>(t&&t(e.tr.scrollIntoView()),!0)}function vi(){return s({insertMarkdown:mi,insertTrigger:hi,scrollIntoView:_i,selectText:fi,selectTextBetween:pi,turnIntoText:gi})}const yi=(e,t,n)=>{let{selection:r}=e;return r.empty||n?.composing?!1:(t?.(e.tr.setSelection(E.near(r.$head))),!0)};function bi(){return x(l({Escape:yi}),t.low)}function xi(){return f({type:`doc`,attr:`frontmatter`,default:null})}function Si(e,t){return t(e.state,e.dispatch,e)}function Ci(e,t){if(t<0||t+1>e.doc.content.size)return;let n=e.doc.resolve(t),r=n.parent.maybeChild(n.index());if(!(r==null||!r.isText))return r.marks}function R(e,t){let n=Ci(e,t);return n!=null&&n.some(e=>jn.has(e.type.name))}function wi(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(!wi(e,t))return;let n=e.doc.resolve(t).start(),r=t;for(;r>n&&R(e,r-1);)r--;return r<t?{from:r,to:t}:void 0}function B(e,t){if(!wi(e,t))return;let n=e.doc.resolve(t).end(),r=t;for(;r<n&&R(e,r);)r++;return r>t?{from:t,to:r}:void 0}function Ti(e,t){return R(e,t-1)&&R(e,t)}function Ei(e,t){if(!Ti(e,t))return;let n=z(e,t);if(!n)return;let r=B(e,t);if(r)return{from:n.from,to:r.to}}function Di(e,t,n){let r=Ci(e,t);return r!=null&&n.isInSet(r)}function Oi(e,t){let n=Ci(e,t);if(n==null)return;let r=g(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&&Di(e,r-1,n);)r--;let i=t+1;for(;i<s&&Di(e,i,n);)i++;(c==null||i-r<c.to-c.from)&&(c={from:r,to:i})}return c}function ki(e,t,n){let r=Oi(e,n===`from`?t.from:t.to-1);return r==null?!1:n===`from`?r.from===t.from:r.to===t.to}function Ai(e,t,n){let r=ki(e,t,`from`),i=ki(e,t,`to`);return r&&!i?t.from:i&&!r?t.to:n-t.from<=t.to-n?t.from:t.to}function ji(e,t,n,r){if(!wi(e,n))return n;let i=Ei(e,n);if(i!=null)return r?Ai(e,i,n):n>=t?i.to:i.from;if(!r)return n;let a=z(e,n);if(a!=null&&ki(e,a,`from`))return a.from;let o=B(e,n);return o!=null&&ki(e,o,`to`)?o.to:n}function Mi(e,t){if(!wi(e,t))return;let n=R(e,t-1),r=R(e,t);if(n!==r)return r?`left`:`right`}function Ni(e,t){let n=Oi(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 Pi=new T(`meowdown-hidden-run-snap`),Fi=new T(`meowdown-hidden-run-beforeinput`);function Ii(){let e=!1;return new w({key:Pi,props:{handleDOMEvents:{compositionstart:()=>(e=!0,!1),compositionend:()=>(e=!1,!1)}},appendTransaction:(t,n,r)=>{if(e||j(r)!==`hide`)return null;let i=r.selection;if(!y(i))return null;let a=t.some(e=>e.getMeta(`pointer`)!=null);if(i.empty){let e=ji(r,n.selection.head,i.head,a);return e===i.head?null:r.tr.setSelection(E.create(r.doc,e))}let o=Ei(r,i.from)?.from??i.from,s=Ei(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(E.create(r.doc,c,l))}})}const Li=(e,t)=>{if(j(e)!==`hide`)return!1;let n=e.selection;if(!y(n)||!n.empty)return!1;let r=ji(e,n.head,n.head,!0);return r===n.head||t?.(e.tr.setSelection(E.create(e.doc,r))),!1};function Ri(e){return(t,n)=>{if(j(t)!==`hide`)return!1;let r=t.selection;if(!y(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=Ni(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 zi=Ri(-1),Bi=Ri(1);function Vi(){return new w({key:Fi,props:{handleDOMEvents:{beforeinput:(e,t)=>{if(e.composing)return!1;let n=t.inputType===`deleteContentBackward`?zi:t.inputType===`deleteContentForward`?Bi:void 0;return n==null||!Si(e,n)?!1:(t.preventDefault(),!0)}}}})}function Hi(){return b(m(Ii()),m(Vi()),x(l({Enter:Li,Backspace:zi,Delete:Bi}),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 Wi(){return b(mt(),Ui())}function Gi(){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 Ki(e){let[t,n,r]=e;return[t,n,r.map(e=>e.toJSON())]}function qi(e,t){let[n,r,i]=t;return[n,r,i.map(t=>He.fromJSON(e,t))]}function Ji(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}function Yi(e,t){let n=e.content.size,r;for(let[i,a,o]of t){if(i>=a)continue;let t=Math.max(0,Math.min(i,n)),s=Math.max(t,Math.min(a,n));if(t>=s)continue;let c=He.setFrom(o);e.nodesBetween(t,s,(n,i)=>{if(!n.isText)return!0;let a=Math.max(t,i),o=Math.min(s,i+n.nodeSize);if(a>=o||Ji(n.marks,c))return!1;r??=new Ct(e);for(let e of n.marks)r.removeMark(a,o,e);for(let e of c)r.addMark(a,o,e);return!1})}return St.ok(r?.doc??e)}function Xi(e,t){let n=e.content.size,r=[...t].filter(([e,t])=>e<t&&e<n).sort((e,t)=>e[0]-t[0]);if(r.length===0)return St.ok(e);let i=r.map(([,,e])=>He.setFrom(e)),a=Math.max(0,r[0][0]),o=0;for(let[,e]of r)e>o&&(o=e);if(o=Math.min(o,n),a>=o)return St.ok(e);let s=0;function c(e,t){let n=t+e.nodeSize;for(;s<r.length&&r[s][1]<=t;)s++;let a=[],o=t,c=!1;for(let t=s;t<r.length;t++){let[s,l]=r[t];if(s>=n)break;let u=Math.max(s,o),d=Math.min(l,n);if(u>=d)continue;u>o&&a.push({from:o,to:u,marks:void 0});let f=i[t],p=!Ji(e.marks,f);p&&(c=!0),a.push({from:u,to:d,marks:p?f:void 0}),o=d}if(c)return o<n&&a.push({from:o,to:n,marks:void 0}),a.map(n=>{let r=e.cut(n.from-t,n.to-t);return n.marks==null?r:r.mark(n.marks)})}function l(e,t){let n,r=t;for(let t=0;t<e.childCount;t++){let i=e.child(t),s=r+i.nodeSize,u=i;if(s>a&&r<o){if(i.isText)u=c(i,r)??i;else if(i.childCount>0){let e=l(i,r+1);e!=null&&(u=i.copy(e))}}if(u!==i&&n==null){n=[];for(let r=0;r<t;r++)n.push(e.child(r))}n!=null&&(Array.isArray(u)?n.push(...u):n.push(u)),r=s}return n==null?void 0:O.fromArray(n)}let u=l(e,0);return St.ok(u==null?e:e.copy(u))}var Zi=class e extends xt{constructor(e){super(),this.chunks=e}apply(e){return this.chunks.length===0?St.ok(e):this.chunks.length<=32?Yi(e,this.chunks):Xi(e,this.chunks)}invert(e){if(this.chunks.length===0)return Qi;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 bt(i,a,e.slice(i,a),!1)}map(e){return null}toJSON(){return{stepType:`batchSetMark`,chunks:this.chunks.map(Ki)}}static fromJSON(t,n){let r=n.chunks;return new e(r.map(e=>qi(t,e)))}};xt.jsonID(`batchSetMark`,Zi);const Qi=new Zi([]),$i=/^<!--\s*(\{[^}]*\})\s*-->$/,ea=/<!--\s*\{[^}]*\}\s*-->$/;function ta(e){let t=$i.exec(e.trim());if(!t)return;let n;try{n=JSON.parse(t[1])}catch{return}if(!xe(n))return;let r=na(n);return Object.keys(r).length>0?r:void 0}function na(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 ra(e){return`<!-- ${JSON.stringify(e)} -->`}function ia(e){return e.replace(ea,``)}function aa(e){return Tt(e)}function oa(e){if(e.length>1024)return!1;let t=e.search(/\S/);return t<0||e.charCodeAt(t)!==91?!1:e.includes(`]:`,t+1)}function sa(e){if(!oa(e))return;let t=_e.parse(e).topNode.firstChild;if(t?.type.id===S.LinkReference&&t.nextSibling==null)return t}function ca(e){return wt(e.startsWith(`<`)&&e.endsWith(`>`)?e.slice(1,-1):e)}function la(e){return e.length<2?``:wt(e.slice(1,-1))}function ua(e){let t=sa(e);if(t==null)return;let n=t.getChild(`LinkLabel`),r=t.getChild(`URL`);if(n==null||r==null)return;let i=aa(e.slice(n.from+1,n.to-1));if(i===``)return;let a=t.getChild(`LinkTitle`);return{key:i,href:ca(e.slice(r.from,r.to)),title:a==null?``:la(e.slice(a.from,a.to))}}function da(e,t){return e==null?!0:F(e,`tableCell`)||F(e,`tableHeaderCell`)?!1:!F(e,`list`)||e.attrs.kind!==`task`||t>0}function fa(e,t,n){return F(e,`paragraph`)&&da(t,n)}const V=new WeakMap;function pa(e,t,n){if(!fa(e,t,n))return;if(V.has(e))return V.get(e);let r=ua(e.textContent);return V.set(e,r),r}function ma(e,t,n){return pa(e,t,n)!=null}function ha(e){let t=new Map,n=new Set;return e.descendants((e,r,i,a)=>{if(e.type.spec.code)return!1;if(!e.isTextblock)return!0;let o=pa(e,i,a);return o!=null&&(n.add(e),t.has(o.key)||t.set(o.key,o)),!1}),{definitions:t,nodes:n}}function ga(e,t,n){let r=e.content.size,i=!1;return e.nodesBetween(Math.max(0,t-1),Math.min(r,n+1),(e,t,n,r)=>i||e.type.spec.code?!1:e.isTextblock?(fa(e,n,r)&&(V.has(e)?V.get(e)!=null:oa(e.textContent))&&(i=!0),!1):!0),i}function _a(e){if(e.steps.some(e=>e instanceof _t&&e.attr===`kind`))return!0;for(let[t,n]of e.mapping.maps.entries()){let r=e.docs[t],i=t+1<e.docs.length?e.docs[t+1]:e.doc,a=!1;if(n.forEach((e,t,n,o)=>{a||=ga(r,e,t)||ga(i,n,o)}),a)return!0}return!1}function va(e,t,n){return!t.docChanged||!_a(t)?e:ha(n)}const ya=/^(\d+)(?:x(\d+))?$/i;function ba(e){if(!e)return null;let t=Number.parseInt(e,10);return Number.isSafeInteger(t)&&t>0?t:null}function xa(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=ya.exec(i);if(!a)return{target:r,display:i,width:null,height:null};let o=ba(a[1]),s=ba(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 Sa(e,t,n){return`![[${e}|${Math.round(t)}x${Math.round(n)}]]`}function Ca(e){let t=e.split(/[?#]/,1)[0],n=t.split(/[/\\]/).findLast(Boolean)??t;try{return decodeURIComponent(n)}catch{return n}}function wa(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 Ta(){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 Ea(){return d({name:`mdWikilink`,constructor:Ta()})}const Da=new Map([[S.Emphasis,`mdEm`],[S.StrongEmphasis,`mdStrong`],[S.InlineCode,`mdCode`],[S.Strikethrough,`mdDel`],[S.Highlight,`mdHighlight`],[S.EmphasisMark,`mdMark`],[S.CodeMark,`mdMark`],[S.LinkMark,`mdMark`],[S.StrikethroughMark,`mdMark`],[S.HighlightMark,`mdMark`],[S.URL,`mdLinkUri`],[S.LinkTitle,`mdLinkTitle`],[S.Hashtag,`mdTag`],[S.WikilinkMark,`mdMark`]]);function Oa(e,t,n){return ka(e,t,n)}function ka(e,t,n,r){let i=ve(t),a=[];return ja(i,[],0,t.length,t,e,a,n,r),a}function Aa(e){return e.slice(1,-1).replaceAll(/\\(.)/g,`$1`)}function ja(e,t,n,r,i,a,o,s,c){let l=n;for(let n=0;n<e.length;n++){let r=e[n];r.from>l&&H(o,l,r.from,t);let u=r.type;if(u===S.Link){let e=Ma(r),n=Na(e,i,c);if(n==null)Pa(r,t,i,a,o,s,c);else{let l=Ia(e,n,t,i,a,s);l?H(o,r.from,r.to,l):La(r,e,n,t,i,a,o,s,c)}}else if(u===S.Image){let u=Ra(r,e[n+1],i);za(r,t,i,a,o,s,c,u),u&&n++,l=u?u.to:r.to;continue}else if(u===S.Wikilink)Va(r,t,i,a,o);else if(u===S.WikiEmbed)Ha(r,t,i,a,o,s);else if(u===S.InlineMath)Ba(r,t,i,a,o);else if(u===S.URL){let e=he(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;u===S.Emphasis?e=`italic`:u===S.StrongEmphasis?e=`bold`:u===S.InlineCode?e=`code`:u===S.Strikethrough?e=`strike`:u===S.Highlight?e=`highlight`:u===S.Autolink&&(e=`autolink`);let n=e?[...t,a.mdPack.create({key:e})]:t,l=Da.get(u),d=l?[...n,a[l].create()]:n;r.children.length===0?H(o,r.from,r.to,d):ja(r.children,d,r.from,r.to,i,a,o,s,c)}l=r.to}l<r&&H(o,l,r,t)}function Ma(e){let t=-1,n=-1,r=null,i=null,a=null,o=0,s=0;for(let c of e.children){let e=c.type;e===S.LinkMark?(s++,o++,o===1&&(t=c.to),o===2&&(n=c.from)):r==null&&e===S.URL?r=c:i==null&&e===S.LinkTitle?i=c:a==null&&e===S.LinkLabel&&(a=c)}return{labelFrom:t,labelTo:n,urlNode:r,titleNode:i,referenceLabelNode:a,linkMarkCount:s}}function Na(e,t,n){if(e.linkMarkCount>=3)return{href:e.urlNode==null?``:t.slice(e.urlNode.from,e.urlNode.to),title:e.titleNode==null?``:Aa(t.slice(e.titleNode.from,e.titleNode.to)),isReference:!1};if(e.labelFrom<0||e.labelTo<0||n?.isReferenceDefinition===!0)return;let r=t.slice(e.labelFrom,e.labelTo),i=aa(e.referenceLabelNode==null?r:t.slice(e.referenceLabelNode.from+1,e.referenceLabelNode.to-1)||r);if(i===``)return;n?.referencedKeys?.add(i);let a=n?.referenceDefinitions?.get(i);if(a!=null)return{href:a.href,title:a.title,isReference:!0}}function Pa(e,t,n,r,i,a,o){ja(e.children.filter(e=>e.type!==S.LinkMark&&e.type!==S.LinkLabel),t,e.from,e.to,n,r,i,a,o)}function Fa(e){let t=e.split(/[?#]/,1)[0],n=t.split(/[/\\]/).findLast(Boolean)??t;try{return decodeURIComponent(n)}catch{return n}}function Ia(e,t,n,r,i,a){let o=a?.resolveFileLink;if(!o)return;let{labelFrom:s,labelTo:c}=e;if(s<0||c<0)return;let{href:l,title:u}=t;if(!l)return;let d=r.slice(s,c);if(!o({href:l,label:d,title:u}))return;let f=d||Fa(l);return[...n,i.mdFile.create({href:l,name:f,title:u})]}function La(e,t,n,r,i,a,o,s,c){let{labelTo:l}=t,{href:u,title:d,isReference:f}=n,p=a.mdLinkText.create({href:u}),m=e=>l>=0&&e<l,h=f?{href:u,title:d,reference:!0}:{href:u,title:d},g=a.mdPack.create({key:`link`,data:h}),_=[...r,g],v=e.from;for(let t of e.children){if(t.from>v){let e=m(v)?[..._,p]:_;H(o,v,t.from,e)}let e=m(t.from)?[..._,p]:_;if(t.type===S.Wikilink){Va(t,e,i,a,o),v=t.to;continue}if(t.type===S.WikiEmbed){Ha(t,e,i,a,o,s),v=t.to;continue}if(t.type===S.Image){za(t,e,i,a,o,s,c),v=t.to;continue}if(f&&t.type===S.LinkLabel){H(o,t.from,t.to,[...e,a.mdMark.create()]),v=t.to;continue}let n=Da.get(t.type),r=n?[...e,a[n].create()]:e;t.children.length===0?H(o,t.from,t.to,r):ja(t.children,r,t.from,t.to,i,a,o,s,c),v=t.to}v<e.to&&H(o,v,e.to,_)}function Ra(e,t,n){if(!t||t.type!==S.Comment||t.from!==e.to)return;let r=ta(n.slice(t.from,t.to));if(r)return{magic:r,to:t.to}}function za(e,t,n,r,i,a,o,s){let c=Na(Ma(e),n,o);if(c==null){Pa(e,t,n,r,i,a,o),s!=null&&H(i,e.to,s.to,t);return}let l=e.children.filter(e=>e.type===S.LinkMark),u=c.href,d=l.length>=2?n.slice(l[0].to,l[1].from):``,f=c.title,p=s?.magic.width??null,m=s?.magic.height??null,h=s?.to??e.to;H(i,e.from,h,[...t,r.mdImage.create({src:u,alt:d,title:f,width:p,height:m,syntax:null,wikiTarget:null})])}function Ba(e,t,n,r,i){let a=e.children.filter(e=>e.type===S.InlineMathMark);if(a.length<2){H(i,e.from,e.to,t);return}let o=n.slice(a[0].to,a[1].from),s=[...t,r.mdPack.create({key:`math`}),r.mdMath.create({formula:o})];H(i,e.from,a[0].to,[...s,r.mdMark.create()]),H(i,a[0].to,a[1].from,s),H(i,a[1].from,e.to,[...s,r.mdMark.create()])}function Va(e,t,n,r,i){let{target:a,display:o}=wa(n.slice(e.from,e.to));H(i,e.from,e.to,[...t,r.mdWikilink.create({target:a,display:o})])}function Ha(e,t,n,r,i,a){let o=xa(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)||Ca(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)||Ca(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&&Ji(i[2],r)){e[e.length-1]=[i[0],n,i[2]];return}e.push([t,n,r])}const Ua=`inline-marks-applied`,Wa=`inline-marks-trigger`,Ga=`inline-marks-restyle`,U=new T(`inline-mark`),Ka=new Set;let qa=0,Ja=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 Xa(e){let t=new WeakMap;function n(e,t){for(let n of e)if(t.has(n))return!0;return!1}function r(e,t){let n=[];for(let[r,i,a]of e)n.push([r+t,i+t,a]);return n}function i(i,a,o,s,c,l){let u=t.get(i),d;if(u?.isReferenceDefinition===l&&!n(u.referencedKeys,c))Ja++,d=u.chunks;else{qa++;let n=new Set;d=ka(Fc(o),i.textContent,e,{referenceDefinitions:s.definitions,isReferenceDefinition:l,referencedKeys:n}),t.set(i,{isReferenceDefinition:l,referencedKeys:n,chunks:d})}return a===0?d:r(d,a)}function a(e,r,a,o){let s=[],c=[],l=(l,u,d,f)=>{if(l.type.spec.code)return!1;if(!l.isTextblock)return!0;if(l.childCount===0)return!1;let p=t.get(l),m=u<=r.to&&u+l.nodeSize>=r.from,h=p==null||n(p.referencedKeys,o);if(!m&&!h)return!1;let g=i(l,u+1,e.schema,a,o,ma(l,d,f));g.length>0&&s.push(...g);let _=t.get(l);return _!=null&&c.push({position:u,cached:_}),!1};return o.size===0?e.doc.nodesBetween(r.from,r.to,l):e.doc.descendants(l),{chunks:s,processed:c}}function o(e,n){for(let{position:r,cached:i}of n){let n=e.nodeAt(r);n?.isTextblock&&t.set(n,i)}}return new w({key:U,state:{init(e,t){return{references:ha(t.doc),pendingReferenceKeys:Ka}},apply(e,t,n,r){if(e.getMeta(Ga)===!0)return t.pendingReferenceKeys.size===0?t:{references:t.references,pendingReferenceKeys:Ka};if(e.getMeta(Ua))return t;let i=va(t.references,e,r.doc);if(i===t.references)return t;let a=$a(t.references.definitions,i.definitions);return a.size===0?{references:i,pendingReferenceKeys:t.pendingReferenceKeys}:{references:i,pendingReferenceKeys:eo(t.pendingReferenceKeys,a)}}},appendTransaction(e,t,n){for(let t of e)if(t.getMeta(Ua))return null;let r=e.some(e=>e.getMeta(Ga));if(!(r||e.some(e=>e.docChanged||e.getMeta(Wa))))return null;let i=U.getState(n)?.references;if(i==null)return null;let s=r?U.getState(t)?.pendingReferenceKeys??Ka:Ka,{chunks:c,processed:l}=a(n,r?{from:0,to:0}:Ya(e,n),i,s);if(c.length===0)return null;let u=n.tr.step(new Zi(c));return o(u.doc,l),u.setMeta(Ua,!0),u.setMeta(`addToHistory`,!1),u},view(e){e.dispatch(Za(e.state));let t,n=e=>{t=void 0,!e.isDestroyed&&(U.getState(e.state)?.pendingReferenceKeys.size??0)!==0&&e.dispatch(e.state.tr.setMeta(Ga,!0))};return{update(e,r){let i=U.getState(e.state);if((i?.pendingReferenceKeys.size??0)===0){t!=null&&clearTimeout(t),t=void 0;return}(t==null||U.getState(r)!==i)&&(t!=null&&clearTimeout(t),t=setTimeout(()=>n(e),200))},destroy(){t!=null&&clearTimeout(t)}}}})}function Za(e){return e.tr.setMeta(Wa,!0)}function Qa(e,t){return e?.href===t?.href&&e?.title===t?.title}function $a(e,t){if(e==null)return new Set(t.keys());let n=new Set;for(let[r,i]of e)Qa(i,t.get(r))||n.add(r);for(let[r,i]of t)Qa(i,e.get(r))||n.add(r);return n}function eo(e,t){if(e.size===0)return t;let n=new Set(e);for(let e of t)n.add(e);return n}function to(e){return m(Xa(e))}function no(){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 ro(){return u({name:`mdMark`,inclusive:!1,toDOM:()=>[`span`,{class:`md-mark`},0],parseDOM:[{tag:`span.md-mark`}]})}function io(){return u({name:`mdEm`,toDOM:()=>[`em`,0],parseDOM:[{tag:`em`}]})}function ao(){return u({name:`mdStrong`,toDOM:()=>[`strong`,0],parseDOM:[{tag:`strong`}]})}function oo(){return u({name:`mdCode`,toDOM:()=>[`code`,0],parseDOM:[{tag:`code`}]})}function so(){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 co(){return u({name:`mdLinkUri`,inclusive:!1,toDOM:()=>[`span`,{class:`md-link-uri`},0],parseDOM:[{tag:`span.md-link-uri`}]})}function lo(){return u({name:`mdLinkTitle`,inclusive:!1,toDOM:()=>[`span`,{class:`md-link-title`},0],parseDOM:[{tag:`span.md-link-title`}]})}function uo(){return u({name:`mdDel`,toDOM:()=>[`del`,0],parseDOM:[{tag:`del`}]})}function fo(){return u({name:`mdHighlight`,toDOM:()=>[`mark`,0],parseDOM:[{tag:`mark`}]})}function po(){return u({name:`mdTag`,toDOM:()=>[`span`,{class:`md-tag`},0],parseDOM:[{tag:`span.md-tag`}]})}function mo(){return u({name:`mdWikilink`,inclusive:!1,attrs:{target:{default:``},display:{default:``}},toDOM:()=>[`span`,{class:`md-wikilink`},0],parseDOM:[{tag:`span.md-wikilink`}]})}function ho(){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 go(){return u({name:`mdMath`,inclusive:!1,attrs:{formula:{default:``}},toDOM:()=>[`span`,{class:`md-math`},0],parseDOM:[{tag:`span.md-math`}]})}function _o(){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 vo(){return b(ro(),io(),ao(),oo(),so(),co(),lo(),uo(),fo(),po(),mo(),no(),ho(),go(),_o())}const W={em:{node:S.Emphasis,delim:`*`},strong:{node:S.StrongEmphasis,delim:`**`},code:{node:S.InlineCode,delim:"`"},del:{node:S.Strikethrough,delim:`~~`},highlight:{node:S.Highlight,delim:`==`}},yo=new Set([S.EmphasisMark,S.CodeMark,S.LinkMark,S.StrikethroughMark,S.HighlightMark]);function bo(e){return[e.children[0],e.children.at(-1)]}function xo(e){let{type:t,children:n}=e;if(t===S.Emphasis||t===S.StrongEmphasis||t===S.Strikethrough||t===S.Highlight)return[n[0].to,n.at(-1).from];if(t===S.Link||t===S.Image){let e=n.find((e,t)=>t>0&&e.type===S.LinkMark);return e?[n[0].to,e.from]:null}return null}function So(e,t,n){for(let r of e){if(r.to<=t||r.from>=n||t<=r.from&&r.to<=n)continue;let i=xo(r);return i&&i[0]<=t&&n<=i[1]?So(r.children,t,n):So(e,Math.min(t,r.from),Math.max(n,r.to))}return[t,n]}function Co(e,t,n){for(let r of e)if(!(r.to<=t||r.from>=n)&&(t>r.from||r.to>n))return Co(e,Math.min(t,r.from),Math.max(n,r.to));return[t,n]}function wo(e,t,n){for(;t<n&&C(e.charCodeAt(t));)t++;for(;n>t&&C(e.charCodeAt(n-1));)n--;return[t,n]}function To(e,t,n,r){let i=me(ve(e),e=>e.type===r.node||yo.has(e.type));for(let r=t;r<n;r++)if(!C(e.charCodeAt(r))&&i.every(e=>!(e.from<=r&&r<e.to)))return!1;return!0}function Eo(e,t,n,r,i){let a=ve(e),o=me(a,e=>e.type===r.node);return i?ko(e,o,t,n):Do(e,a,o,t,n,r)}function Do(e,t,n,r,i,a){for(let e=0;e!==i-r;){e=i-r,[r,i]=So(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]=bo(e);o.push({from:t.from,to:t.to,insert:``}),o.push({from:n.from,to:n.to,insert:``})}let[s,c]=Oo(e,r,i,o,a);return o.push({from:r,to:r,insert:s},{from:i,to:i,insert:c}),o}function Oo(e,t,n,r,i){if(i.node!==S.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(br(a)+1),s=a.startsWith("`")||a.endsWith("`")?` `:``;return[o+s,s+o]}function ko(e,t,n,r){let i=[];for(let a of t){if(a.to<=n||a.from>=r)continue;let[t,o]=bo(a),s=Math.max(n,t.to),c=Math.min(r,o.from);for(s>=c&&([s,c]=[t.to,o.from]),[s,c]=Co(a.children.slice(1,-1),s,c);s>t.to&&C(e.charCodeAt(s-1));)s--;for(;c<o.from&&C(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 Ao(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=ve(e),o=me(a,e=>e.type===n.node).findLast(e=>e.from<=t&&t<=e.to);if(o){let[e,n]=bo(o);return{kind:`move`,pos:t===o.from?e.to:t===o.to?n.from:o.to}}return jo(a,t)||e[t-1]===r[0]||e[t]===r[0]?null:{kind:`insert`,pos:t}}function jo(e,t){for(let n of e)if(n.from<t&&t<n.to){let e=xo(n);return!e||t<e[0]||t>e[1]||jo(n.children,t)}return!1}function G(e){return(t,n)=>{if(t.selection.empty)return Mo(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]=wo(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:To(a,c,l,e)}),!1});let c=s.length>0&&s.every(e=>e.active),l=s.filter(e=>c||!e.active).flatMap(t=>Eo(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(E.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 Mo(e,t,n){let{$from:r}=t.selection,i=r.parent;if(!i.isTextblock||i.type.spec.code)return!1;let a=Ao(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(E.create(o.doc,i+a.pos)),a.kind===`insert`&&(o.insertText(e.delim+e.delim,i+a.pos),o.setSelection(E.create(o.doc,i+a.pos+e.delim.length))),n(o.scrollIntoView())}return!0}function No(){return s({toggleEm:()=>G(W.em),toggleStrong:()=>G(W.strong),toggleCode:()=>G(W.code),toggleDel:()=>G(W.del),toggleHighlight:()=>G(W.highlight)})}function Po(){return l({"Mod-b":G(W.strong),"Mod-i":G(W.em),"Mod-e":G(W.code),"Mod-Shift-x":G(W.del),"Mod-Shift-h":G(W.highlight)})}function Fo(){return b(No(),Po())}function Io(e,t,n){let r;return e.doc.nodesBetween(t.from,t.to,(e,i)=>(e.isText&&e.marks.some(e=>An(e,n))&&(r={from:Math.max(i,t.from),to:Math.min(i+e.nodeSize,t.to)}),!0)),r}function K(e,t){let n=A(e,t,`mdLinkText`),r=A(e,t,`mdPack`,{key:`link`})??A(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`?Io(e,t,`mdLinkText`)??{from:i.from+1,to:i.to-1}:t,href:o,title:``}}if(a.data.reference===!0){let e=n==null?{from:i.from,to:i.to}:{from:n.from+1,to:n.to};return{unit:{from:i.from,to:i.to},text:e,href:a.data.href,title:a.data.title}}let s=Io(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 Lo(e){let t=e.trim();return t?he(t)??t:``}function Ro(e,t){return e+(t?` "${t.replaceAll(/(["\\])/g,String.raw`\$1`)}"`:``)}function zo(e){let{selection:t}=e,{$from:n,$to:r,empty:i}=t;if(i||!n.sameParent(r)||!y(t))return;let a=n.parent;if(!a.isTextblock||a.type.spec.code)return;let o=n.start(),[s,c]=wo(a.textContent,n.parentOffset,r.parentOffset);if(!(s>=c))return{from:o+s,to:o+c}}function Bo({href:e,title:t,wrapText:n=!0}={}){return(r,i)=>{let a=zo(r);if(!a)return!1;if(i){let{from:o,to:s}=a,c=r.tr,l=`](${Ro(Lo(e??``),t??``)})`;c.insertText(l,s).insertText(`[`,o);let u=s+1+l.length;c.setSelection(n?E.create(c.doc,o,u):E.create(c.doc,u)),c.scrollIntoView(),i(c)}return!0}}function Vo(e){return(t,n)=>{let r=K(t,t.selection.from);if(!r?.dest)return!1;let i=Ro(Lo(e.href??r.href),e.title??r.title);return n&&n(t.tr.insertText(i,r.dest.from,r.dest.to).scrollIntoView()),!0}}function Ho(){return(e,t)=>{let n=K(e,e.selection.from);return n?.label?(t&&t(e.tr.delete(n.label.to,n.unit.to).delete(n.unit.from,n.label.from).scrollIntoView()),!0):!1}}function Uo(){return s({insertLink:Bo,updateLink:Vo,removeLink:Ho})}function Wo(e){return(t,n,r)=>{let i=K(t,t.selection.from);if(i){if(i.label==null||i.dest==null)return!1;if(n&&r){let{unit:{from:a,to:o}}=i;n(t.tr.setSelection(E.create(t.doc,a,o)).scrollIntoView()),r.focus(),e({from:a,to:o,link:i})}return!0}let a=zo(t);if(a){if(n&&r){let{from:i,to:o}=a;n(t.tr.setSelection(E.create(t.doc,i,o)).scrollIntoView()),r.focus(),e({from:i,to:o,link:void 0})}return!0}return!1}}function Go(e){return l({"Mod-k":Wo(e)})}function Ko(e){return e===`)`||e===`*`||e===`+`?e:void 0}function qo(e){return e===`X`?e:void 0}function Jo(e){return Zo(e)?String(e):void 0}function Yo(){return f({type:`list`,attr:`marker`,default:null,splittable:!0,toDOM:e=>{let t=Ko(e);return t==null?null:[`data-list-marker`,t]},parseDOM:e=>{let t=e.getAttribute(`data-list-marker`);return t===`)`||t===`*`||t===`+`?t:null}})}function Xo(){return f({type:`list`,attr:`taskMarker`,default:null,splittable:!0,toDOM:e=>{let t=qo(e);return t==null?null:[`data-list-task-marker`,t]},parseDOM:e=>e.getAttribute(`data-list-task-marker`)===`X`?`X`:null})}function Zo(e){return e===2||e===3||e===4}function Qo(){return f({type:`list`,attr:`markerGap`,default:1,splittable:!0,toDOM:e=>{let t=Jo(e);return t==null?null:[`data-list-marker-gap`,t]},parseDOM:e=>{let t=Number.parseInt(e.getAttribute(`data-list-marker-gap`)??``,10);return Zo(t)?t:1}})}function $o(e){let t=e.attrs;return{...kt(e),"data-list-marker":Ko(t.marker),"data-list-task-marker":qo(t.taskMarker),"data-list-marker-gap":Jo(t.markerGap)}}function es(){return o({serializeFragmentWrapper:e=>(...t)=>ts(Mt(e(...t))),serializeNodeWrapper:e=>(...t)=>{let n=e(...t);return ye(n)?ts(Mt(n)):n},nodesFromSchemaWrapper:e=>(...t)=>({...e(...t),list:e=>Nt({node:e,nativeList:!0,getAttributes:$o})})})}function ts(e){ye(e)&&ns(e);for(let t of e.children)ts(t);return e}function ns(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=At(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 rs=[Ft(/^\s?([*-])\s$/,{kind:`bullet`,collapsed:!1}),Ft(/^\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}}),Ft(/^\s?\[([\sX]?)\]\s$/i,({match:e})=>({kind:`task`,checked:[`x`,`X`].includes(e[1]),collapsed:!1})),Ft(/^\s?\+\s$/,{kind:`task`,marker:`+`,checked:!1,collapsed:!1})];function is(){return b(rs.map(tt))}function as(){return dt({kind:`task`,marker:`+`})}function os(){return dt({kind:`task`,marker:null})}function ss(e){let{$from:t}=e.selection;for(let e=t.depth;e>0;e--){let n=t.node(e);if(F(n,`list`))return n.attrs}return null}function cs(){return(e,t,n)=>{let r=ss(e);return(r?.kind===`task`?r.marker===`+`?os():as():dt({kind:`task`,marker:null,checked:!1}))(e,t,n)}}function ls(){return s({cycleCheckableList:cs,wrapInCircleTask:as,wrapInSquareTask:os})}function us(){return(e,t,n)=>{let r=ss(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},dt(a)(e,t,n)}}function ds(){return(e,t,n)=>{let r=ss(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},dt(a)(e,t,n)}}function fs(e){return F(e,`list`)&&e.attrs.kind===`bullet`&&e.childCount>=2&&e.firstChild?.type!==e.type}const ps=e=>{let t=e.attrs;return t.kind===`task`?{...t,checked:!t.checked}:fs(e)?{...t,collapsed:!t.collapsed}:t};function ms(){return m(()=>[new w({props:{handleDOMEvents:{mousedown:(e,t)=>jt({view:e,event:t,onListClick:ps})}}}),Et(),new w({props:{transformCopied:Pt}}),Dt()])}function hs(){return s({toggleListCollapsed:()=>Ot({isToggleable:fs})})}function gs(){return l({"Mod-Enter":us(),"Mod-Shift-Enter":ds(),"Mod-.":Ot({isToggleable:fs}),"Mod-Shift-7":lt({kind:`ordered`,collapsed:!1}),"Mod-Shift-8":lt({kind:`bullet`,collapsed:!1}),"Mod-Shift-9":lt({kind:`task`,checked:!1,collapsed:!1})})}function _s(){return b(st(),ms(),ot(),it(),es(),at(),is(),gs(),Yo(),Xo(),Qo(),ls(),hs())}let vs;function ys(){return vs??=import(`./katex-chunk-Ch7kgbXr.js`).then(e=>e.render),vs}function bs(e,t,n,r){try{e(n,t,{displayMode:r,throwOnError:!1,output:`mathml`})}catch(e){t.textContent=String(e)}}var xs=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=E.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;ys().then(t=>{e===this.#r&&bs(t,this.#n,e,!1)})}};function Ss(){return d({name:`mdMath`,constructor:(e,t)=>new xs(e,t)})}function Cs(e){return e===`left`||e===`center`||e===`right`?e:null}function ws(){return f({type:`tableCell`,attr:`align`,default:null,toDOM:e=>e?[`data-align`,e]:null,parseDOM:e=>Cs(e.getAttribute(`data-align`))})}function Ts(){return f({type:`tableHeaderCell`,attr:`align`,default:null,toDOM:e=>e?[`data-align`,e]:null,parseDOM:e=>Cs(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(F(n.child(e),`tableHeaderCell`))return t}return 0}function Ds(e){return e.child(Es(e))}function Os(e,t){return t>=e.childCount?null:e.child(t).attrs.align??null}function ks(e,t,n){if(e.childCount===0)return;let r=Ds(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=Os(r,e);(t.attrs.align??null)!==i&&n.setNodeMarkup(o,void 0,{...t.attrs,align:i}),o+=t.nodeSize}i+=a.nodeSize}}function As(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 js(){return new w({key:new T(`table-align-sync`),appendTransaction(e,t,n){if(!e.some(e=>e.docChanged))return;let r=As(e);if(!r)return;let i=n.doc,a=Math.max(0,Math.min(r.from,i.content.size)),o=Math.max(a,Math.min(r.to,i.content.size)),s;return i.nodesBetween(a,o,(e,t)=>F(e,`table`)?(s??=n.tr,ks(e,t,s),!1):!0),s?.docChanged?s:void 0}})}function Ms(){return m(js())}function Ns(e){let{selection:t}=e;if(Wt(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 Ps(e){return(t,n)=>{let r=Ns(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 Fs(e){let t=Ns(e);if(!(!t||t.table.childCount===0))return Os(Ds(t.table),t.lastColumn)??void 0}function Is(){return s({setTableColumnAlign:Ps})}function Ls(){return b(ws(),Ts(),Ms(),Is())}function Rs(e){let{$from:t}=e.selection;for(let e=t.depth;e>0;e--){let n=t.node(e).type.name;if(n===`tableCell`||n===`tableHeaderCell`)return!0}return!1}const zs=`paragraph`;function Bs(){return b(p({name:`tableCell`,content:zs}),p({name:`tableHeaderCell`,content:zs}))}const Vs=(e,t)=>{let{selection:n}=e;return!Wt(n)||!n.isColSelection()||!n.isRowSelection()?!1:Ut(e,t)};function Hs(){return x(l({Backspace:Vs,Delete:Vs}),t.high)}function Us(){return b(Ht(),Vt(),It(),Bt(),Bs(),Ls(),zt({allowTableNodeSelection:!0}),Lt(),Rt(),Hs())}function Ws(e){let{selection:t}=e,{$from:n,$to:r}=t;if(ne(t)&&n.depth===0||n.depth>0&&r.depth>0&&n.index(0)===r.index(0))return n.index(0)}function Gs(e){return(t,n)=>{if(Rs(t))return!1;let r=Ws(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=ne(a)?ke.create(u.doc,a.from+d):E.create(u.doc,a.anchor+d,a.head+d);u.setSelection(f),n(u.scrollIntoView())}return!0}}function Ks(e){return(t,n,r)=>ct(e)(t,n,r)||Gs(e===`up`?-1:1)(t,n,r)}function qs(){return l({"Alt-ArrowUp":Ks(`up`),"Alt-ArrowDown":Ks(`down`)})}const q=new T(`meowdownPendingReplacement`);function J(e){return q.getState(e)?.pending??null}function Js(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 Ys=new w({key:q,state:{init:()=>({pending:null}),apply:(e,t)=>{let n=e.getMeta(q);if(n)return Js(n,t);if(e.docChanged&&t.pending){let n=e.mapping.mapResult(t.pending.from,1),r=e.mapping.mapResult(t.pending.to,-1),i=Math.min(n.pos,r.pos),a=Math.max(n.pos,r.pos);return(n.deletedAfter&&r.deletedBefore||i>=a)&&t.pending.mode===`replace`?{pending:null,ended:{pending:t.pending,outcome:`discarded`}}:{pending:{...t.pending,from:i,to:a}}}return t}},props:{decorations:e=>{let t=J(e);return!t||t.from>=t.to?null:D.create(e.doc,[je.inline(t.from,t.to,{class:`md-pending-replacement`})])}}});function Xs(e){return(t,n)=>{let{from:r,to:i,mode:a}=e;return r<0||i>t.doc.content.size||r>i||r===i&&a===`replace`?!1:(n?.(t.tr.setMeta(q,{type:`start`,from:r,to:i,mode:a})),!0)}}function Zs(e){return(t,n)=>J(t)?(n?.(t.tr.setMeta(q,{type:`append`,text:e})),!0):!1}function Qs(){return(e,t)=>J(e)?(t?.(e.tr.setMeta(q,{type:`discard`})),!0):!1}function $s(e={}){return(t,n)=>{let r=J(t);if(!r||!r.text.trim())return!1;if(n){let i=e.mode??r.mode,a=Lc(t.schema),o=Z(r.text,{nodes:a}),s=t.tr;if(s.setMeta(q,{type:`accept`}),i===`append`){let e=t.doc.resolve(r.to).after(1);s.insert(e,o.content),s.setSelection(E.near(s.doc.resolve(e+o.content.size),-1))}else{let e=t.doc.resolve(r.from),n=t.doc.resolve(r.to),i=o.childCount===1?o.firstChild:null;i!=null&&F(i,`paragraph`)&&e.sameParent(n)&&e.parent.isTextblock?(s.replaceWith(r.from,r.to,i.content),s.setSelection(E.near(s.doc.resolve(r.from+i.content.size),-1))):(s.replaceRange(r.from,r.to,new k(o.content,0,0)),s.setSelection(E.near(s.doc.resolve(s.mapping.map(r.to)),-1)))}n(s.scrollIntoView())}return!0}}function ec(){return s({startPendingReplacement:Xs,appendPendingReplacementText:Zs,acceptPendingReplacement:$s,discardPendingReplacement:Qs})}function tc(){return l({"Mod-Enter":$s(),Escape:Qs()})}function nc(){return b(m(Ys),ec(),tc())}function rc(e){return m(new w({view:()=>({update:(t,n)=>{let r=q.getState(n),i=q.getState(t.state);!i||r===i||(i.pending?i.pending!==r?.pending&&e({type:`update`,pending:i.pending}):i.ended&&i.ended!==r?.ended&&e({type:`ended`,pending:i.ended.pending,outcome:i.ended.outcome}))}})}))}function ic(e){return e.left===e.right&&e.top===e.bottom}function Y(e,t,n){if(t<0||t>e.state.doc.content.size)return;let r;try{r=e.coordsAtPos(t,n)}catch{return}return ic(r)?void 0:r}function ac(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 oc(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=Y(e,t,n?-1:1);if(r!=null&&r.bottom>r.top)return{left:r.left,top:r.top,height:r.bottom-r.top}}}function sc(e){let t=e.state,n=t.selection.head;for(let r of rn){let i=A(t,n,r);if(i==null||i.from!==n&&i.to!==n)continue;let a=lc(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 cc(e,t,n){let r=e.state;for(let i of rn){let a=A(r,t,i);if(a==null)continue;let o=lc(e,a.from+1);if(o==null)continue;let s=Array.from(o.getClientRects()).filter(e=>e.height>0);if(s.length!==0)return n===1?s[0]:s[s.length-1]}}function lc(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 uc(e){return oc(e)??sc(e)}const dc=new T(`meowdown-scroll-to-selection`);function fc(e){let t=e.state.selection;if(!y(t)||Y(e,t.head,1)!=null)return!1;let n=uc(e);if(n==null)return!1;let r=e.domAtPos(t.head).node;return gc(e,{left:n.left,right:n.left,top:n.top,bottom:n.top+n.height},r),!0}function X(e,t){return typeof e==`number`?e:e[t]}function pc(e){let t=e.assignedSlot??e.parentNode;return t?.nodeType===11?t.host:t}function mc(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 hc(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 gc(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=pc(e);continue}let n=e,o=n===a.body,s=o?mc(a):hc(n),c=0,l=0;if(t.top<s.top+X(r,`top`)?l=-(s.top-t.top+X(i,`top`)):t.bottom>s.bottom-X(r,`bottom`)&&(l=t.bottom-t.top>s.bottom-s.top?t.top+X(i,`top`)-s.top:t.bottom-s.bottom+X(i,`bottom`)),t.left<s.left+X(r,`left`)?c=-(s.left-t.left+X(i,`left`)):t.right>s.right-X(r,`right`)&&(c=t.right-s.right+X(i,`right`)),c||l)if(o)a.defaultView?.scrollBy(c,l);else{let e=n.scrollLeft,r=n.scrollTop;l&&(n.scrollTop+=l),c&&(n.scrollLeft+=c);let i=n.scrollLeft-e,a=n.scrollTop-r;t={left:t.left-i,top:t.top-a,right:t.right-i,bottom:t.bottom-a}}let u=o?`fixed`:getComputedStyle(n).position;if(/^(?:fixed|sticky)$/.test(u))break;e=u===`absolute`?n.offsetParent:pc(n)}}function _c(){return m(new w({key:dc,props:{handleScrollToSelection:fc}}))}function vc(e,t){return(n,r)=>{let i=e<0?Ae.atStart(n.doc):Ae.atEnd(n.doc),a=t?E.between(n.selection.$anchor,i.$head):i;return n.selection.eq(a)||r?.(n.tr.setSelection(a).scrollIntoView()),!0}}function yc(){return l({"Meta-ArrowUp":vc(-1,!1),"Meta-ArrowDown":vc(1,!1),"Shift-Meta-ArrowUp":vc(-1,!0),"Shift-Meta-ArrowDown":vc(1,!0)})}function bc(e){e.offsetWidth}const xc=new T(`meowdown-virtual-caret`),Sc=[`md-virtual-caret-blink`,`md-virtual-caret-blink2`],Cc=`data-meowdown-virtual-caret`;function wc(e){let t=e.height*.19999999999999996;return{left:e.left,top:e.top-t/2,height:e.height+t}}function Tc(e){let t=ac(e)??oc(e);return t==null?sc(e):wc(t)}function Ec(e,t){return e==null||t==null?e===t:e.left===t.left&&e.top===t.top&&e.height===t.height}var Dc=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=Sc[this.#s]}#l=()=>{let e=this.#e;if(e.isDestroyed)return;let t=e.state,n=t.selection,r=y(n)&&n.empty?Tc(e):void 0,i=r!=null&&j(t)===`hide`?Mi(t,n.head):void 0;if(Ec(r,this.#a)&&i===this.#o)return;let a=this.#a==null;if(this.#a=r,this.#o=i,i==null?delete this.#n.dataset.tail:this.#n.dataset.tail=i,r==null){this.#n.style.visibility=`hidden`,e.dom.removeAttribute(Cc);return}let o=this.#t.getBoundingClientRect();a&&(this.#n.style.transitionProperty=`none`),this.#n.style.visibility=``,this.#n.style.left=`${r.left-o.left}px`,this.#n.style.top=`${r.top-o.top}px`,this.#n.style.height=`${r.height}px`,e.dom.setAttribute(Cc,``),a&&(bc(this.#n),this.#n.style.transitionProperty=``)}};function Oc(){return m(new w({key:xc,view:e=>new Dc(e)}))}function kc(e){return b(er(),we(),xi(),De(),Ce(),_s(),Xn(),Us(),di(),Wi(),Gi(),vo(),ni(),bi(),qs(),yc(),to(e),Fo(),Uo(),Ea(),Ss(),$t(e.markMode??`focus`),Xr(),Oc(),_c(),Hi(),gn({marks:rn.map(e=>({name:e,modes:[`hide`,`focus`,`show`]}))}),a(),i(),c(),Te(),Oe(),Ee(),vi(),nc())}function Ac(e={}){return kc(e)}const jc=Se(()=>{let e=Ac().schema;if(e==null)throw Error(`Unexpected empty schema`);return e}),Mc=Se(()=>r(jc())),Nc=Se(()=>n(jc())),Pc=`meowdown_mark_builders`;function Fc(e){let t=e.cached[Pc];if(t)return t;let r=n(e);return e.cached[Pc]=r,r}const Ic=`meowdown_node_builders`;function Lc(e){let t=e.cached[Ic];if(t)return t;let n=r(e);return e.cached[Ic]=n,n}function Z(e,t={}){let{nodes:n=Mc(),frontmatter:r=!1}=t,i,a=e;if(r){let[t,n]=zc(e);i=t,n&&(a=e.slice(n))}let o=Bc(n,ge.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 zc(e){let t=Rc.exec(e);return t?[(t[1]??``).replace(/\r?\n$/,``),t[0].length]:[]}function Bc(e,t,n){let r=[];if(!t.firstChild())return r;let i;do i!=null&&Vc(r,e,n,i,t.from),i=t.to,r.push(...Hc(e,t,n));while(t.nextSibling());return t.parent(),r}function Vc(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 Hc(e,t,n){switch(t.type.id){case S.ATXHeading1:return[Q(e,t,n,1,!1)];case S.ATXHeading2:return[Q(e,t,n,2,!1)];case S.ATXHeading3:return[Q(e,t,n,3,!1)];case S.ATXHeading4:return[Q(e,t,n,4,!1)];case S.ATXHeading5:return[Q(e,t,n,5,!1)];case S.ATXHeading6:return[Q(e,t,n,6,!1)];case S.SetextHeading1:return[Q(e,t,n,1,!0)];case S.SetextHeading2:return[Q(e,t,n,2,!0)];case S.Paragraph:return[Jc(e,t,n)];case S.LinkReference:return[Jc(e,t,n)];case S.CommentBlock:return[Yc(e,t,n)];case S.HTMLBlock:case S.ProcessingInstructionBlock:return[Jc(e,t,n)];case S.Blockquote:return[Xc(e,t,n)];case S.BulletList:return Zc(e,t,n,`bullet`);case S.OrderedList:return Zc(e,t,n,`ordered`);case S.FencedCode:case S.CodeBlock:return[$c(e,t,n)];case S.BlockMath:return[el(e,t,n)];case S.HorizontalRule:{let r=n.slice(t.from,t.to).trimEnd();return[e.horizontalRule({marker:r===`---`?null:r})]}case S.Table:return[tl(e,t,n)];case S.Task:return[Jc(e,t,n)];default:return n.slice(t.from,t.to).trim()===``?[]:(console.warn(`[meowdown] unsupported lezer block "${t.type.name}"`),[Jc(e,t,n)])}}function Q(e,t,n,r,i){let a=t.from,o=t.from,s=t.to,c=-1,l=-1;if(t.firstChild()){t.type.id===S.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===S.HeaderMark&&n>o&&(s=n,c=n,l=r),t.parent()}let u=Kc(n.slice(o,s),$(n,o)).trim(),d=i?Uc(n,c,l)||1:null,f=!i&&c>=0&&Wc(n,c,l)||null;return e.heading({level:r,setextUnderline:d,closingHashes:f},u)}function Uc(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 Wc(e,t,n){if(t<0)return 0;let r=0;for(let i=t;i<n;i++)e.charCodeAt(i)===35&&r++;return r}function $(e,t){let n=e.lastIndexOf(`
|
|
30
|
+
`,t-1)+1,r=0;for(let i=n;i<t;i++)r+=e.charCodeAt(i)===9?4-r%4:1;return r}function Gc(e,t){let n=0,r=0;for(;r<e.length&&n<t;){let t=e.charCodeAt(r);if(t===32)n+=1;else if(t===9)n+=4-n%4;else break;r++}return e.slice(r)}function Kc(e,t){return t===0||!e.includes(`
|
|
31
31
|
`)?e:e.split(`
|
|
32
|
-
`).map((e,n)=>n===0?e:
|
|
33
|
-
`)}function
|
|
34
|
-
`).filter(e=>!
|
|
35
|
-
`)}const nl=new C(`meowdown-embed-paste`);function rl(e){let t=e.trim();if(!(!t||/\s/.test(t)))return el(t)?t:void 0}function il(e,t){let{from:n,to:r}=e.state.selection;e.dispatch(Ht(e.state.tr.insertText(t,n,r)));let i=e.state.tr.insertText(``,n,n+t.length);e.dispatch(Ht(i))}function al(){return m(new S({key:nl,props:{handlePaste:(e,t,n)=>{let r=e.state.selection.$from.parent;if(!r.inlineContent||r.type.spec.code)return!1;let i=tl(t,n);if(!i)return!1;let a=rl(i);return a?(il(e,a),!0):!1}}}))}const ol=new C(`meowdown-exit-boundary`);function sl(e,t){let{$anchor:n,$head:r}=e.selection,i=t>0?n.max(r):n.min(r),a=i.parent.inlineContent?i.depth?e.doc.resolve(t>0?i.after():i.before()):void 0:i;return!!(a&&je.findFrom(a,t))}function cl(e,t){let{state:n}=e,{selection:r}=n;return g(r)&&!r.empty||ne(r)||r.$from.parent.inlineContent&&!e.endOfTextblock(t<0?`up`:`down`)?!0:sl(n,t)}function ll(e){return new S({key:ol,props:{handleKeyDown:(t,n)=>{if(n.shiftKey||n.altKey||n.ctrlKey||n.metaKey)return!1;let r=n.key===`ArrowUp`?-1:n.key===`ArrowDown`?1:void 0;return!(!r||cl(t,r)||e({direction:r<0?`up`:`down`,event:n})===!1)}}})}function ul(e){return v(m(ll(e)),t.low)}const dl=new Set([`avif`,`bmp`,`gif`,`jpeg`,`jpg`,`png`,`svg`,`webp`]);function fl(e){if(e.type?.startsWith(`image/`))return!0;let t=e.name.lastIndexOf(`.`);if(t===-1)return!1;let n=e.name.slice(t+1).toLowerCase();return dl.has(n)}function pl(e,t){return fl(e)?``:`[${gl(e.name)}](${t})`}function ml(e,t){return!e||!t.onFilePaste?[]:Array.from(e.files)}const hl=e=>{console.error(`[meowdown] failed to save pasted file:`,e)};function gl(e){return e.replaceAll(/[\\[\]]/g,String.raw`\$&`)}async function _l(e,t,n,r){let{onFilePaste:i}=n;if(!i)return;let a=n.onFileSaveError??hl,o=r,s=!1;for(let n of t){let t;try{t=await i(n)}catch(e){a(e,n);continue}if(!t||e.isDestroyed)continue;let r=pl(n,t),c=s?`\n${r}`:r,l=o==null?e.state.tr.insertText(c):e.state.tr.insertText(c,o);e.dispatch(l),s=!0,o!=null&&(o+=c.length)}}function vl(e){return new S({key:new C(`file-paste`),props:{handlePaste:(t,n)=>{let r=ml(n.clipboardData,e);return r.length===0?!1:(_l(t,r,e),!0)},handleDrop:(t,n)=>{let r=ml(n.dataTransfer,e);return r.length===0?!1:(_l(t,r,e,t.posAtCoords({left:n.clientX,top:n.clientY})?.pos),!0)}}})}function yl(e={}){return v(m(vl(e)),t.high)}const bl=new C(`meowdown-file-click`);function xl(e,t){let n=k(e,t,`mdFile`);if(!n)return;let{href:r,name:i}=n.mark.attrs;return{href:r,name:i}}function Sl(e){return m(new S({key:bl,props:{handleClick:(t,n,r)=>{let i=r.target?.closest?.(`.md-file-view-preview`);if(!i)return!1;let a=i.closest(`.md-file-view`)?.querySelector(`.md-file-view-content`);if(!a)return!1;let o=xl(t.state,t.posAtDOM(a,0));return o?(e({href:o.href,name:o.name,event:r}),!0):!1}}}))}const Cl=[`KB`,`MB`,`GB`,`TB`];function wl(e){let t=e,n=`B`;for(let e of Cl){if(t<999.5)break;t/=1e3,n=e}return n===`B`?`${Math.round(t)} B`:`${t<9.95?Math.round(t*10)/10:Math.round(t)} ${n}`}const Tl=new Map([[`pdf`,`pdf`],[`zip`,`archive`],[`tar`,`archive`],[`gz`,`archive`],[`tgz`,`archive`],[`rar`,`archive`],[`7z`,`archive`],[`doc`,`doc`],[`docx`,`doc`],[`pages`,`doc`],[`xls`,`sheet`],[`xlsx`,`sheet`],[`csv`,`sheet`],[`numbers`,`sheet`],[`ppt`,`slides`],[`pptx`,`slides`],[`key`,`slides`],[`mp3`,`audio`],[`wav`,`audio`],[`m4a`,`audio`],[`flac`,`audio`],[`ogg`,`audio`],[`mp4`,`video`],[`mov`,`video`],[`mkv`,`video`],[`webm`,`video`],[`txt`,`text`],[`md`,`text`]]);function El(e){let t=e.split(/[?#]/,1)[0],n=t.lastIndexOf(`.`);if(n<0)return`generic`;let r=t.slice(n+1).toLowerCase();return Tl.get(r)??`generic`}const Dl=`http://www.w3.org/2000/svg`;function Ol(){let e=document.createElementNS(Dl,`svg`);e.setAttribute(`class`,`md-file-view-icon`),e.setAttribute(`viewBox`,`0 0 24 24`),e.setAttribute(`aria-hidden`,`true`);for(let t of[`M15 2H6a2 2 0 0 0-2 2v16a2 2 0 0 0 2 2h12a2 2 0 0 0 2-2V7Z`,`M14 2v4a2 2 0 0 0 2 2h4`]){let n=document.createElementNS(Dl,`path`);n.setAttribute(`d`,t),n.setAttribute(`fill`,`none`),n.setAttribute(`stroke`,`currentColor`),n.setAttribute(`stroke-width`,`2`),n.setAttribute(`stroke-linecap`,`round`),n.setAttribute(`stroke-linejoin`,`round`),e.appendChild(n)}return e}var kl=class{#e;#t;#n;#r;#i;#a;#o=!1;constructor(e,t){this.#a=e.attrs,this.#e=document.createElement(`span`),this.#e.className=`md-file-view md-atom-view`,this.#n=document.createElement(`span`),this.#n.className=`md-file-view-preview md-atom-view-preview`,this.#n.contentEditable=`false`,this.#n.dataset.testid=`file-pill`,this.#n.dataset.fileKind=El(this.#a.href),this.#n.title=this.#a.name,this.#e.appendChild(this.#n),this.#n.appendChild(Ol()),this.#r=document.createElement(`span`),this.#r.className=`md-file-view-name`,this.#r.textContent=this.#a.name,this.#n.appendChild(this.#r),this.#i=document.createElement(`span`),this.#i.className=`md-file-view-size`,this.#i.dataset.testid=`file-pill-size`,this.#n.appendChild(this.#i),this.#t=document.createElement(`span`),this.#t.className=`md-file-view-content md-atom-view-content`,this.#e.appendChild(this.#t),this.#s(t.resolveFileInfo)}get dom(){return this.#e}get contentDOM(){return this.#t}update(e){let t=e.attrs,n=this.#a;return t.href===n.href?(this.#a=t,t.name!==n.name&&(this.#r.textContent=t.name,this.#n.title=t.name),!0):!1}ignoreMutation(e){return!this.#t.contains(e.target)}destroy(){this.#o=!0}async#s(e){if(!e)return;let t;try{t=await e(this.#a.href)}catch(e){console.error(`[meowdown] resolveFileInfo failed:`,e);return}if(this.#o||!t)return;let{size:n}=t;n==null||!Number.isFinite(n)||n<0||(this.#i.textContent=wl(n))}};function Al(e={}){return d({name:`mdFile`,constructor:t=>new kl(t,e)})}function jl(e){return m(new S({key:e.key,props:{handleClick:(t,n,r)=>{let i=r.target?.closest?.(e.selector);if(!i)return!1;let a=e.findPayloadForElement?e.findPayloadForElement(t,i):e.findPayloadAt(t.state,n);return a==null?!1:(e.preventDefault&&r.preventDefault(),e.onClick(a,r),!0)}}}))}const Ml=new C(`meowdown-tag-click`);function Nl(e,t){let n=k(e,t,`mdTag`);if(!n)return;let r=e.doc.textBetween(n.from,n.to),i=r.startsWith(`#`)?r.slice(1):r;return{from:n.from,to:n.to,tag:i}}function Pl(e){return jl({key:Ml,selector:`.md-tag`,preventDefault:!1,findPayloadAt:(e,t)=>Nl(e,t)?.tag,onClick:(t,n)=>e({tag:t,event:n})})}const Fl=new C(`meowdown-wikilink-click`);function Il(e,t){let n=k(e,t,`mdWikilink`);if(!n)return;let{target:r}=n.mark.attrs;return{from:n.from,to:n.to,target:r}}function Ll(e,t){let n=t.closest(`.md-wikilink-view`)?.querySelector(`.md-wikilink-view-content`);if(n)return Il(e.state,e.posAtDOM(n,0))}function Rl(e){return jl({key:Fl,selector:`.md-wikilink-view-preview`,preventDefault:!1,findPayloadAt:(e,t)=>Il(e,t)?.target,findPayloadForElement:(e,t)=>Ll(e,t)?.target,onClick:(t,n)=>e({target:t,event:n})})}const zl=new C(`meowdown-follow-link`);function Bl(e){return e.key!==`Enter`||e.shiftKey||e.altKey?!1:re?e.metaKey&&!e.ctrlKey:e.ctrlKey&&!e.metaKey}function Vl(e){return new S({key:zl,props:{handleKeyDown:(t,n)=>{if(!Bl(n))return!1;let{state:r}=t,i=r.selection.head,a=e.onWikilinkClick&&Il(r,i);if(a)return e.onWikilinkClick?.({target:a.target,event:n}),!0;let o=e.onTagClick&&Nl(r,i);if(o)return e.onTagClick?.({tag:o.tag,event:n}),!0;let s=e.onFileClick&&xl(r,i);if(s)return e.onFileClick?.({href:s.href,name:s.name,event:n}),!0;let c=e.onLinkClick&&G(r,i);return c?(e.onLinkClick?.({href:c.href,event:n}),!0):!1}}})}function Hl(e){return v(m(Vl(e)),t.high)}const Ul=new C(`meowdown-image-click`);function Wl(e){return e instanceof HTMLElement&&e.closest(`.md-image-view-preview`)}function Gl(e,t){let n=k(e,t,`mdImage`);if(!n)return;let{src:r,alt:i}=n.mark.attrs;return{from:n.from,to:n.to,src:r,alt:i}}function Kl(e,t){let n=t.closest(`.md-image-view`)?.querySelector(`.md-image-view-content`);if(n)return Gl(e.state,e.posAtDOM(n,0))}function ql(e,t){return Array.from(e).find(e=>e.identifier===t)}function Jl(e,t){return Math.abs(t.clientX-e.clientX)<=10&&Math.abs(t.clientY-e.clientY)<=10}function Yl(e){let t=new WeakMap;return m(new S({key:Ul,props:{handleDOMEvents:{pointerdown:(e,t)=>(Wl(t.target)&&t.pointerType!==`mouse`&&t.preventDefault(),!1),touchstart:(e,n)=>{if(t.delete(e),n.touches.length!==1||!Wl(n.target)||n.target instanceof HTMLElement&&n.target.closest(`.md-image-resize-handle`))return!1;let r=n.changedTouches[0];return r&&t.set(e,{identifier:r.identifier,clientX:r.clientX,clientY:r.clientY}),!1},touchmove:(e,n)=>{let r=t.get(e);if(!r)return!1;let i=ql(n.changedTouches,r.identifier);return i&&!Jl(r,i)&&t.delete(e),!1},touchcancel:e=>(t.delete(e),!1),touchend:(n,r)=>{let i=t.get(n);if(t.delete(n),!i||r.touches.length>0)return!1;let a=ql(r.changedTouches,i.identifier);if(!a||!Jl(i,a))return!1;let o=Wl(r.target);if(!o)return!1;r.preventDefault();let s=Kl(n,o);return s&&e({src:s.src,alt:s.alt,event:r}),!0}},handleClick:(t,n,r)=>{let i=Wl(r.target);if(!i)return!1;let a=Kl(t,i);return a?(e({src:a.src,alt:a.alt,event:r}),!0):!1}}}))}function Xl(e){return/^https?:\/\//i.test(e)?e:void 0}function Zl(e){let t=document.createElement(`iframe`);return t.src=e.src,t.title=e.title,t.className=e.className,t.dataset.testid=e.testid,t.loading=`lazy`,t.referrerPolicy=`strict-origin-when-cross-origin`,t.setAttribute(`frameborder`,`0`),e.allow&&(t.allow=e.allow),e.allowFullscreen&&(t.allowFullscreen=!0),e.kind===`tweet`&&qc(t),t}function Ql(e,t,n,r){if(n!=null&&r!=null){e.setAttribute(`data-width`,String(n)),e.setAttribute(`data-height`,String(r));return}let i=t.naturalWidth/t.naturalHeight;if(!Number.isFinite(i)||i<=0){n!=null&&e.setAttribute(`data-width`,String(n)),r!=null&&e.setAttribute(`data-height`,String(r));return}let a=n==null?Math.min(t.naturalHeight,500):n/i,o=n??a*i;e.setAttribute(`data-width`,String(Math.round(o))),e.setAttribute(`data-height`,String(Math.round(a)))}function $l(e,t,n,r){let i=e.posAtDOM(t,0),a=k(e.state,i,`mdImage`);if(!a)return;let o=e.state.doc.textBetween(a.from,a.to),s=a.mark.attrs;if(s.syntax===`wikiEmbed`){let t=s.wikiTarget||ea(o).target;if(!t)return;let i=ta(t,n,r);i!==o&&e.dispatch(e.state.tr.insertText(i,a.from,a.to));return}let c=Zi(o),l=a.from+c.length,u=o.slice(c.length),d=Xi({...Ji(u)??{},width:Math.round(n),height:Math.round(r)});d!==u&&e.dispatch(e.state.tr.insertText(d,l,a.to))}var eu=class{#e;#t;#n;#r;#i;#a;#o;constructor(e,t,n){this.#i=e.attrs,this.#n=n,this.#r=t,this.#e=document.createElement(`span`),this.#e.className=`md-image-view md-atom-view`,this.#t=document.createElement(`span`),this.#t.className=`md-image-view-content md-atom-view-content`;let r=this.#s();r&&(r.contentEditable=`false`,this.#e.appendChild(r)),this.#e.appendChild(this.#t)}get dom(){return this.#e}get contentDOM(){return this.#t}update(e){let t=e.attrs,n=this.#i;return t.src===n.src?(this.#i=t,this.#o&&t.alt!==n.alt&&(this.#o.alt=t.alt),this.#a&&this.#o&&(t.width!==n.width||t.height!==n.height)&&Ql(this.#a,this.#o,t.width,t.height),!0):!1}ignoreMutation(e){return!this.#t.contains(e.target)}#s(){let{src:e}=this.#i,t=el(e);if(t){let e=document.createElement(`span`);return e.className=`md-image-view-preview md-atom-view-preview`,e.appendChild(Zl(t)),e}let n=(this.#n.resolveImageUrl??Xl)(e);if(!n)return;let r=document.createElement(`span`);return r.className=`md-image-view-preview md-atom-view-preview`,r.dataset.testid=`image-preview`,r.appendChild(this.#c(n)),r}#c(e){Wt(),Ut();let t=document.createElement(`prosekit-resizable-root`);t.className=`md-image-resizable`,t.dataset.testid=`image-resizable`,t.setAttribute(`data-loading`,``);let n=document.createElement(`img`);n.src=e,n.alt=this.#i.alt,n.draggable=!1,Ql(t,n,this.#i.width,this.#i.height),n.addEventListener(`load`,()=>{t.removeAttribute(`data-loading`);let e=n.naturalWidth/n.naturalHeight;!Number.isFinite(e)||e<=0||(t.setAttribute(`data-aspect-ratio`,String(e)),Ql(t,n,this.#i.width,this.#i.height))}),n.addEventListener(`error`,()=>{t.removeAttribute(`data-loading`)}),t.appendChild(n);let r=document.createElement(`prosekit-resizable-handle`);return r.className=`md-image-resize-handle`,r.setAttribute(`position`,`bottom-right`),r.addEventListener(`click`,e=>e.stopPropagation()),t.appendChild(r),t.addEventListener(`resizeEnd`,e=>{let{width:t,height:n}=e.detail;$l(this.#r,this.#t,t,n)}),this.#a=t,this.#o=n,t}};function tu(e={}){return d({name:`mdImage`,constructor:(t,n)=>new eu(t,n,e)})}const nu={"Mod-b":`Bold`,"Mod-i":`Italic`,"Mod-e":`Inline code`,"Mod-Shift-x":`Strikethrough`,"Mod-Shift-h":`Highlight`,"Mod-k":`Link`,"Mod-Shift-k":`Insert a wikilink`,"Mod-1":`Heading 1`,"Mod-2":`Heading 2`,"Mod-3":`Heading 3`,"Mod-4":`Heading 4`,"Mod-5":`Heading 5`,"Mod-6":`Heading 6`,"Mod-.":`Fold or unfold a bullet`,"Mod-Enter":`Follow the link under the caret, or cycle a checkbox task`,"Mod-Shift-Enter":`Cycle a circle checkbox task`,"Mod-Shift-7":`Ordered list`,"Mod-Shift-8":`Bullet list`,"Mod-Shift-9":`Checkbox task list`,"Alt-ArrowUp":`Move the block or list item up`,"Alt-ArrowDown":`Move the block or list item down`,"Meta-ArrowUp":`Move the caret to the document start`,"Meta-ArrowDown":`Move the caret to the document end`,"Shift-Meta-ArrowUp":`Select to the document start`,"Shift-Meta-ArrowDown":`Select to the document end`,Escape:`Collapse the selection`},ru=new C(`meowdown-link-click`);function iu(e){return jl({key:ru,selector:`.md-link`,preventDefault:!0,findPayloadAt:(e,t)=>G(e,t)?.href,onClick:(t,n)=>e({href:t,event:n})})}function au(e){let t,n=(t,n)=>e.findPayloadForElement?e.findPayloadForElement(t,n):e.findPayloadAt(t.state,t.posAtDOM(n,0)),r=()=>{t&&(t=void 0,e.onHoverChange(void 0))},i=(i,a)=>{let o=a.target;if(!o||!be(o))return;let s=o.closest(e.selector);if(!s||!i.dom.contains(s)||s===t?.element)return;r();let c=n(i,s);c!=null&&(t={payload:c,element:s},e.onHoverChange(t))},a=e=>{if(!t)return;let n=e.relatedTarget;n instanceof Node&&t.element.contains(n)||r()};return m(new S({key:e.key,props:{handleDOMEvents:{mouseover:(e,t)=>(i(e,t),!1),mouseout:(e,t)=>(a(t),!1)}},view:()=>({update:i=>{if(!t)return;if(!t.element.isConnected||!i.dom.contains(t.element)){r();return}let a=n(i,t.element);if(a==null||!e.isSamePayload(t.payload,a)){r();return}t={...t,payload:a}},destroy:r})}))}const ou=new C(`meowdown-link-hover`);function su(e){return au({key:ou,selector:`.md-link`,findPayloadAt:(e,t)=>G(e,t),isSamePayload:(e,t)=>e.href===t.href&&e.title===t.title,onHoverChange:e})}const cu=new C(`meowdown-link-paste`);function lu(e){let t=e.trim();if(!(!t||/\s/.test(t)))return ve(t)}function uu(){return v(m(new S({key:cu,props:{handlePaste:(e,t,n)=>{let r=tl(t,n);if(!r)return!1;let i=lu(r);return i?_i(e,uo({href:i,wrapText:!1})):!1}}})),t.high)}const du=[[/<-/,`←`],[/(?<!-)->/,`→`],[/\(c\)/,`©`],[/\(r\)/,`®`],[/1\/2/,`½`],[/\+\/-/,`±`],[/!=/,`≠`],[/<</,`«`],[/>>/,`»`],[/(?<!<!)(?<!^(?:-[ \t]*)+)--/,`—`]],$=new C(`meowdown-substitution-undo`);function fu(e,t,n){let r=ee(e.schema,`mdCode`);return e.doc.rangeHasMark(t,n,r)}function pu(e,t,n,r,i){if(fu(e,t,n))return null;let[,a]=r,o=i==null?a:`${a} `,s=e.tr.replaceWith(t,n,e.schema.text(o));return i!=null&&s.setMeta($,{from:t,to:t+o.length,before:i,after:o}),s}function mu(){return _(du.map(e=>nt(new Gt(new RegExp(String.raw`(?:${e[0].source})\s$`),(t,n,r,i)=>pu(t,r,i,e,n[0])))))}function hu(){return m(new S({key:$,state:{init:()=>null,apply:(e,t)=>{let n=e.getMeta($);if(n!==void 0)return n;if(!t)return null;let r=e.mapping.map(t.from),i=e.mapping.map(t.to);return e.selection.empty&&e.selection.from===i&&e.doc.textBetween(r,i)===t.after?{...t,from:r,to:i}:null}}}))}function gu(){return v(l({Backspace:(e,t)=>{let n=$.getState(e);return n?(t?.(e.tr.replaceWith(n.from,n.to,e.schema.text(n.before)).setMeta($,null)),!0):!1}}),t.highest)}function _u(){return _(hu(),gu())}function vu(){return _(du.map(e=>et({regex:RegExp(`(?:${e[0].source})$`),handler:({state:t,from:n,to:r})=>pu(t,n,r,e)})))}function yu(){return _(mu(),_u(),vu())}const bu=new C(`meowdown-wikilink-hover`);function xu(e){return au({key:bu,selector:`.md-wikilink-view-preview`,findPayloadAt:Il,findPayloadForElement:Ll,isSamePayload:(e,t)=>e.target===t.target,onHoverChange:t=>{e(t?{...t.payload,element:t.element}:void 0)}})}function Su(e,t={}){let n=[];return e.content.forEach(e=>{let r=[];e.descendants(e=>{if(!e.isText||!e.text)return!0;let n=e.marks.map(e=>e.type.name);return n.some(e=>En.has(e))&&!(t.preserveMathSource&&n.includes(`mdMath`))||r.push(e.text),!1}),n.push(r.join(``))}),n.join(`
|
|
36
|
-
`)}function
|
|
32
|
+
`).map((e,n)=>n===0?e:Gc(e,t)).join(`
|
|
33
|
+
`)}function qc(e,t,n){return e.paragraph(Kc(t,n))}function Jc(e,t,n){let r=t.from,i=t.to,a=$(n,r);if(t.firstChild()){let o=``,s=r;do t.type.id===S.QuoteMark&&(o+=n.slice(s,t.from),s=t.to,C(n.charCodeAt(s))&&(s+=1));while(t.nextSibling());return t.parent(),o+=n.slice(s,i),qc(e,o,a)}return qc(e,n.slice(r,i),a)}function Yc(e,t,n){let r=$(n,t.from),i=Kc(n.slice(t.from,t.to),r);return e.htmlComment({content:i})}function Xc(e,t,n){let r=[];if(t.firstChild()){let i;do{if(t.type.id===S.QuoteMark)continue;i!=null&&Vc(r,e,n,i,t.from),i=t.to,r.push(...Hc(e,t,n))}while(t.nextSibling());t.parent()}return e.blockquote(r)}function Zc(e,t,n,r){let i=[];if(t.firstChild()){do t.type.id===S.ListItem&&i.push(Qc(e,t,n,r));while(t.nextSibling());t.parent()}return i}function Qc(e,t,n,r){let i=[],a,o,s,c,l,u;if(t.firstChild()){do{if(t.type.id!==S.ListMark&&u==null&&(u=$(n,t.from)),t.type.id===S.ListMark){if(r===`ordered`){let e=n.charCodeAt(t.to-1);e===41?c=`)`:e===46&&(c=`.`);let r=Number.parseInt(n.slice(t.from,t.to),10);s=Number.isFinite(r)?r:1}else{let e=n.charCodeAt(t.from);c=e===42?`*`:e===43?`+`:`-`}l=$(n,t.to);continue}if(r===`bullet`&&t.type.id===S.Task){let r=t.from,s=t.to;if(a=!1,t.firstChild()){if(t.type.id===S.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()}C(n.charCodeAt(r))&&(r+=1);let c=n.slice(r,s);i.push(qc(e,c,$(n,r)));continue}i.push(...Hc(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 $c(e,t,n){let r=t.type.id===S.CodeBlock,i=``,a=``,o=r?`indented`:null,s=null,c=!1;if(t.firstChild()){do switch(t.type.id){case S.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 S.CodeInfo:i=n.slice(t.from,t.to);break;case S.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 el(e,t,n){let r=``;if(t.firstChild()){do t.type.id===S.CodeText&&(r+=n.slice(t.from,t.to));while(t.nextSibling());t.parent()}return e.codeBlock({language:`math`,fenceStyle:`dollar`,fenceLength:null},r)}function tl(e,t,n){let r=[];if(t.firstChild()){do t.type.id===S.TableDelimiter&&(r=nl(n.slice(t.from,t.to)));while(t.nextSibling());t.parent()}let i=[];if(t.firstChild()){do{let a=t.type.id;a===S.TableHeader?i.push(rl(e,t,n,!0,r)):a===S.TableRow&&i.push(rl(e,t,n,!1,r))}while(t.nextSibling());t.parent()}return e.table(i)}function nl(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 rl(e,t,n,r,i){let a=i.length,o=Array(a).fill(``);if(t.firstChild()){let e=t.type.id===S.TableDelimiter,r=0;do if(t.type.id===S.TableDelimiter)r++;else if(t.type.id===S.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 il(e){return e.replace(/\n+$/u,``)}function al(e){return/^[\s>]*$/u.test(e)}function ol(e){return e.split(`
|
|
34
|
+
`).filter(e=>!al(e))}function sl(e){return e.trim().replaceAll(/\s+/gu,` `)}const cl=/^:?-+:?$/u;function ll(e){let t=e.startsWith(`:`),n=e.endsWith(`:`);return t&&n?`:-:`:t?`:--`:n?`--:`:`---`}function ul(e){if(!e.includes(`|`))return;let t=/^[\s>]*/u.exec(e)?.[0]??``,n=e.slice(t.length).trim().replace(/^\|/u,``).replace(/\|$/u,``).split(`|`).map(e=>sl(e));return sl(`${t} | ${(n.every(e=>cl.test(e))?n.map(ll):n).join(` | `)} |`)}function dl(e){return ul(e)??sl(e)}function fl(e,t={}){let n=xr(Z(e,{frontmatter:t.frontmatter}),{frontmatter:t.frontmatter});if(il(n)===il(e))return`exact`;let r=ol(e),i=ol(n);return r.length===i.length&&r.every((e,t)=>dl(e)===dl(i[t]))?`normalizing`:`lossy`}const pl=(e,t)=>{let{$from:n,empty:r}=e.selection;if(!r||n.depth!==1||n.index(0)!==0||!F(n.parent,`heading`)||n.parentOffset!==n.parent.content.size)return!1;if(t){let r=_(e.schema,`list`),i=_(e.schema,`paragraph`),a=r.create({kind:`bullet`},i.create()),o=n.after(),s=e.tr.insert(o,a);s.setSelection(E.create(s.doc,o+2)),t(s.scrollIntoView())}return!0};function ml(){return x(l({Enter:pl}),t.high)}const hl=new Set([`MscGen`,`Xù`,`MsGenny`,`Angular Template`,`Brainfuck`,`Esper`,`Oz`,`Factor`,`Squirrel`,`Yacas`,`mIRC`,`FCL`,`ECL`,`MUMPS`,`Pig`,`Asterisk`,`Z80`,`Mathematica`]),gl=Ye.map(e=>({label:e.name,value:e.name.toLowerCase()})).filter(e=>!hl.has(e.label)).concat([{label:`Plain text`,value:``},{label:`Math`,value:`math`},{label:`Mermaid`,value:`mermaid`}]).sort((e,t)=>e.label.localeCompare(t.label));function _l(){return typeof window>`u`?!1:window.matchMedia(`(prefers-color-scheme: dark)`).matches}const vl=/^(?:www\.|mobile\.)?(?:twitter\.com|x\.com)$/i,yl=/\/status(?:es)?\/(\d+)/;function bl(e){let t;try{t=new URL(e)}catch{return}if(vl.test(t.hostname))return yl.exec(t.pathname)?.[1]}const xl=e=>{let t=bl(e);if(!t)return;let n=_l()?`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 Sl(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 Cl=/^(?:www\.|m\.)?(?:youtube\.com|youtube-nocookie\.com)$/i,wl=/^(?:www\.)?youtu\.be$/i,Tl=/^[\w-]{11}$/;function El(e){let t;try{t=new URL(e)}catch{return}let n=null;if(wl.test(t.hostname))n=t.pathname.slice(1);else if(Cl.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||!Tl.test(n))return;let r=t.searchParams.get(`start`)??t.searchParams.get(`t`),i=r?Dl(r):void 0;return{videoId:n,startSeconds:i}}function Dl(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 Ol=[e=>{let t=El(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}},xl];function kl(e){for(let t of Ol){let n=t(e);if(n)return n}}function Al(e,t){return e.clipboardData?.getData(`text/plain`)||t.content.textBetween(0,t.content.size,`
|
|
35
|
+
`)}const jl=new T(`meowdown-embed-paste`);function Ml(e){let t=e.trim();if(!(!t||/\s/.test(t)))return kl(t)?t:void 0}function Nl(e,t){let{from:n,to:r}=e.state.selection;e.dispatch(Gt(e.state.tr.insertText(t,n,r)));let i=e.state.tr.insertText(``,n,n+t.length);e.dispatch(Gt(i))}function Pl(){return m(new w({key:jl,props:{handlePaste:(e,t,n)=>{let r=e.state.selection.$from.parent;if(!r.inlineContent||r.type.spec.code)return!1;let i=Al(t,n);if(!i)return!1;let a=Ml(i);return a?(Nl(e,a),!0):!1}}}))}const Fl=new T(`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&&Ae.findFrom(a,t))}function Ll(e,t){let{state:n}=e,{selection:r}=n;return y(r)&&!r.empty||v(r)||r.$from.parent.inlineContent&&!e.endOfTextblock(t<0?`up`:`down`)?!0:Il(n,t)}function Rl(e){return new w({key:Fl,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||Ll(t,r)||e({direction:r<0?`up`:`down`,event:n})===!1)}}})}function zl(e){return x(m(Rl(e)),t.low)}const Bl=new Set([`avif`,`bmp`,`gif`,`jpeg`,`jpg`,`png`,`svg`,`webp`]);function Vl(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 Bl.has(n)}function Hl(e,t){return Vl(e)?``:`[${Gl(e.name)}](${t})`}function Ul(e,t){return!e||!t.onFilePaste?[]:Array.from(e.files)}const Wl=e=>{console.error(`[meowdown] failed to save pasted file:`,e)};function Gl(e){return e.replaceAll(/[\\[\]]/g,String.raw`\$&`)}async function Kl(e,t,n,r){let{onFilePaste:i}=n;if(!i)return;let a=n.onFileSaveError??Wl,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=Hl(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 ql(e){return new w({key:new T(`file-paste`),props:{handlePaste:(t,n)=>{let r=Ul(n.clipboardData,e);return r.length===0?!1:(Kl(t,r,e),!0)},handleDrop:(t,n)=>{let r=Ul(n.dataTransfer,e);return r.length===0?!1:(Kl(t,r,e,t.posAtCoords({left:n.clientX,top:n.clientY})?.pos),!0)}}})}function Jl(e={}){return x(m(ql(e)),t.high)}const Yl=new T(`meowdown-file-click`);function Xl(e,t){let n=A(e,t,`mdFile`);if(!n)return;let{href:r,name:i}=n.mark.attrs;return{href:r,name:i}}function Zl(e){return m(new w({key:Yl,props:{handleClick:(t,n,r)=>{let i=r.target?.closest?.(`.md-file-view-preview`);if(!i)return!1;let a=i.closest(`.md-file-view`)?.querySelector(`.md-file-view-content`);if(!a)return!1;let o=Xl(t.state,t.posAtDOM(a,0));return o?(e({href:o.href,name:o.name,event:r}),!0):!1}}}))}const Ql=[`KB`,`MB`,`GB`,`TB`];function $l(e){let t=e,n=`B`;for(let e of Ql){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 eu=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 tu(e){let t=e.split(/[?#]/,1)[0],n=t.lastIndexOf(`.`);if(n<0)return`generic`;let r=t.slice(n+1).toLowerCase();return eu.get(r)??`generic`}const nu=`http://www.w3.org/2000/svg`;function ru(){let e=document.createElementNS(nu,`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(nu,`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 iu=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=tu(this.#a.href),this.#n.title=this.#a.name,this.#e.appendChild(this.#n),this.#n.appendChild(ru()),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=$l(n))}};function au(e={}){return d({name:`mdFile`,constructor:t=>new iu(t,e)})}function ou(e){return m(new w({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 su=new T(`meowdown-tag-click`);function cu(e,t){let n=A(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 lu(e){return ou({key:su,selector:`.md-tag`,preventDefault:!1,findPayloadAt:(e,t)=>cu(e,t)?.tag,onClick:(t,n)=>e({tag:t,event:n})})}const uu=new T(`meowdown-wikilink-click`);function du(e,t){let n=A(e,t,`mdWikilink`);if(!n)return;let{target:r}=n.mark.attrs;return{from:n.from,to:n.to,target:r}}function fu(e,t){let n=t.closest(`.md-wikilink-view`)?.querySelector(`.md-wikilink-view-content`);if(n)return du(e.state,e.posAtDOM(n,0))}function pu(e){return ou({key:uu,selector:`.md-wikilink-view-preview`,preventDefault:!1,findPayloadAt:(e,t)=>du(e,t)?.target,findPayloadForElement:(e,t)=>fu(e,t)?.target,onClick:(t,n)=>e({target:t,event:n})})}const mu=new T(`meowdown-follow-link`);function hu(e){return e.key!==`Enter`||e.shiftKey||e.altKey?!1:ee?e.metaKey&&!e.ctrlKey:e.ctrlKey&&!e.metaKey}function gu(e){return new w({key:mu,props:{handleKeyDown:(t,n)=>{if(!hu(n))return!1;let{state:r}=t,i=r.selection.head,a=e.onWikilinkClick&&du(r,i);if(a)return e.onWikilinkClick?.({target:a.target,event:n}),!0;let o=e.onTagClick&&cu(r,i);if(o)return e.onTagClick?.({tag:o.tag,event:n}),!0;let s=e.onFileClick&&Xl(r,i);if(s)return e.onFileClick?.({href:s.href,name:s.name,event:n}),!0;let c=e.onLinkClick&&K(r,i);return c?(e.onLinkClick?.({href:c.href,event:n}),!0):!1}}})}function _u(e){return x(m(gu(e)),t.high)}const vu=new T(`meowdown-image-click`);function yu(e){return e instanceof HTMLElement&&e.closest(`.md-image-view-preview`)}function bu(e,t){let n=A(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 xu(e,t){let n=t.closest(`.md-image-view`)?.querySelector(`.md-image-view-content`);if(n)return bu(e.state,e.posAtDOM(n,0))}function Su(e,t){return Array.from(e).find(e=>e.identifier===t)}function Cu(e,t){return Math.abs(t.clientX-e.clientX)<=10&&Math.abs(t.clientY-e.clientY)<=10}function wu(e){let t=new WeakMap;return m(new w({key:vu,props:{handleDOMEvents:{pointerdown:(e,t)=>(yu(t.target)&&t.pointerType!==`mouse`&&t.preventDefault(),!1),touchstart:(e,n)=>{if(t.delete(e),n.touches.length!==1||!yu(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=Su(n.changedTouches,r.identifier);return i&&!Cu(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=Su(r.changedTouches,i.identifier);if(!a||!Cu(i,a))return!1;let o=yu(r.target);if(!o)return!1;r.preventDefault();let s=xu(n,o);return s&&e({src:s.src,alt:s.alt,event:r}),!0}},handleClick:(t,n,r)=>{let i=yu(r.target);if(!i)return!1;let a=xu(t,i);return a?(e({src:a.src,alt:a.alt,event:r}),!0):!1}}}))}function Tu(e){return/^https?:\/\//i.test(e)?e:void 0}function Eu(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`&&Sl(t),t}function Du(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 Ou(e,t,n,r){let i=e.posAtDOM(t,0),a=A(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||xa(o).target;if(!t)return;let i=Sa(t,n,r);i!==o&&e.dispatch(e.state.tr.insertText(i,a.from,a.to));return}let c=ia(o),l=a.from+c.length,u=o.slice(c.length),d=ra({...ta(u)??{},width:Math.round(n),height:Math.round(r)});d!==u&&e.dispatch(e.state.tr.insertText(d,l,a.to))}var ku=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)&&Du(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=kl(e);if(t){let e=document.createElement(`span`);return e.className=`md-image-view-preview md-atom-view-preview`,e.appendChild(Eu(t)),e}let n=(this.#n.resolveImageUrl??Tu)(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){qt(),Kt();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,Du(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)),Du(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;Ou(this.#r,this.#t,t,n)}),this.#a=t,this.#o=n,t}};function Au(e={}){return d({name:`mdImage`,constructor:(t,n)=>new ku(t,n,e)})}const ju={"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`},Mu=new T(`meowdown-link-click`);function Nu(e){return ou({key:Mu,selector:`.md-link`,preventDefault:!0,findPayloadAt:(e,t)=>K(e,t)?.href,onClick:(t,n)=>e({href:t,event:n})})}function Pu(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||!ye(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 w({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 Fu=new T(`meowdown-link-hover`);function Iu(e){return Pu({key:Fu,selector:`.md-link`,findPayloadAt:(e,t)=>K(e,t),isSamePayload:(e,t)=>e.href===t.href&&e.title===t.title,onHoverChange:e})}const Lu=new T(`meowdown-link-paste`);function Ru(e){let t=e.trim();if(!(!t||/\s/.test(t)))return he(t)}function zu(){return x(m(new w({key:Lu,props:{handlePaste:(e,t,n)=>{let r=Al(t,n);if(!r)return!1;let i=Ru(r);return i?Si(e,Bo({href:i,wrapText:!1})):!1}}})),t.high)}const Bu=[[/<-/,`←`],[/(?<!-)->/,`→`],[/\(c\)/,`©`],[/\(r\)/,`®`],[/1\/2/,`½`],[/\+\/-/,`±`],[/!=/,`≠`],[/<</,`«`],[/>>/,`»`],[/(?<!<!)(?<!^(?:-[ \t]*)+)--/,`—`]],Vu=new T(`meowdown-substitution-undo`);function Hu(e,t,n){let r=g(e.schema,`mdCode`);return e.doc.rangeHasMark(t,n,r)}function Uu(e,t,n,r,i){if(Hu(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(Vu,{from:t,to:t+o.length,before:i,after:o}),s}function Wu(){return b(Bu.map(e=>tt(new Jt(new RegExp(String.raw`(?:${e[0].source})\s$`),(t,n,r,i)=>Uu(t,r,i,e,n[0])))))}function Gu(){return m(new w({key:Vu,state:{init:()=>null,apply:(e,t)=>{let n=e.getMeta(Vu);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 Ku(){return x(l({Backspace:(e,t)=>{let n=Vu.getState(e);return n?(t?.(e.tr.replaceWith(n.from,n.to,e.schema.text(n.before)).setMeta(Vu,null)),!0):!1}}),t.highest)}function qu(){return b(Gu(),Ku())}function Ju(){return b(Bu.map(e=>$e({regex:RegExp(`(?:${e[0].source})$`),handler:({state:t,from:n,to:r})=>Uu(t,n,r,e)})))}function Yu(){return b(Wu(),qu(),Ju())}const Xu=new T(`meowdown-wikilink-hover`);function Zu(e){return Pu({key:Xu,selector:`.md-wikilink-view-preview`,findPayloadAt:du,findPayloadForElement:fu,isSamePayload:(e,t)=>e.target===t.target,onHoverChange:t=>{e(t?{...t.payload,element:t.element}:void 0)}})}function Qu(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=>jn.has(e))&&!(t.preserveMathSource&&n.includes(`mdMath`))||r.push(e.text),!1}),n.push(r.join(``))}),n.join(`
|
|
36
|
+
`)}function $u({allowEmpty:e}){return(t,n)=>{let{selection:r}=t;if(!y(r)||!e&&r.empty||!r.$head.sameParent(r.$anchor)||r.$head.parent.type.spec.code)return!1;let i=Qu(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(E.create(e.doc,r.from+a.length)),rt(e),n(e.scrollIntoView())}return!0}}function ed(){return l({"Mod-Shift-k":$u({allowEmpty:!0}),"[":$u({allowEmpty:!1})})}function td(e){switch(e.type.name){case`mdWikilink`:{let t=e.attrs;return t.display||t.target}case`mdImage`:return e.attrs.alt;case`mdFile`:return e.attrs.name;case`mdMath`:return e.attrs.formula;default:return``}}function nd(e){let t=``;for(let n of Fn(e)){if(n.atom!=null){t+=td(n.atom);continue}for(let e of n.children)Pn(e.marks)||(t+=e.text??``)}return t}function rd(e){let{selection:t,schema:n}=e;if(t.empty)return``;let r=t.content().content;try{return xr(n.topNodeType.create(null,r)).replace(/\n+$/,``)}catch{return e.doc.textBetween(t.from,t.to,`
|
|
37
37
|
|
|
38
|
-
`)}}function
|
|
38
|
+
`)}}function id(e,t,n){if(n===1){let r=B(e.state,t);return r&&Y(e,r.to,n)}else{let n=z(e.state,t);return n&&Y(e,n.from,-1)}}function ad(e,t){let n=new DOMRect(0,0,0,0),r=()=>{if(e.isDestroyed)return n;let r=Y(e,t.from,1)??cc(e,t.from,1)??id(e,t.from,1)??Y(e,t.from,-1);if(r==null)return n;let i=Y(e,t.to,-1)??cc(e,t.to,-1)??id(e,t.to,-1)??Y(e,t.to,1);if(i==null)return n;let a=Math.min(r.left,i.left),o=Math.max(r.right,i.right),s=Math.min(r.top,i.top),c=Math.max(r.bottom,i.bottom);return n=new DOMRect(a,s,o-a,c-s),n};return{getBoundingClientRect:r,getClientRects:()=>[r()]}}function od(e){return e instanceof ht||e instanceof gt||e instanceof vt||e instanceof yt||e instanceof Zi}function sd(e){for(let t of e)for(let e of t.steps)if(!od(e))return!0;return!1}function cd(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){sd(e)&&o()},view(e){return t=e,{destroy(){t=void 0}}}}}function ld(e){let t=new T(`spell-check`);return new w({key:t,state:{init:()=>cd(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 ud(e){return m(ld(e))}export{ju as EDITOR_KEY_BINDINGS,e as Priority,Hl as buildFileMarkdown,fl as checkRoundTrip,gl as codeBlockLanguages,ha as collectReferenceDefinitions,Tu as defaultResolveImageUrl,ml as defineBulletAfterHeading,ue as defineCodeBlockPreviewPlugin,ni as defineCodeBlockSyntaxHighlight,Ac as defineEditorExtension,Pl as defineEmbedPaste,zl as defineExitBoundaryHandler,Zl as defineFileClickHandler,Jl as defineFilePaste,au as defineFileView,_u as defineFollowLinkHandler,Gi as defineHTMLComment,Au as defineImage,wu as defineImageClickHandler,Nu as defineLinkClickHandler,Uo as defineLinkCommands,Go as defineLinkEditKeymap,Iu as defineLinkHoverHandler,zu as defineLinkPaste,Ss as defineMath,rc as definePendingReplacementHandler,fe as definePlaceholder,pe as defineReadonly,ud as defineSpellCheckPlugin,Yu as defineSubstitution,lu as defineTagClickHandler,pu as defineWikilinkClickHandler,Zu as defineWikilinkHoverHandler,ed as defineWikilinkTrigger,xr as docToMarkdown,$l as formatFileSize,Sa as formatSizedWikiEmbed,ii as getCodeTokens,tu as getFileKind,K as getLinkUnitAt,Nc as getMarkBuilders,J as getPendingReplacement,rd as getSelectedText,Fs as getTableColumnAlign,nd as getTextblockDisplayText,ad as getVirtualElementFromRange,Oa as inlineTextToMarkChunks,ka as inlineTextToMarkChunksWithContext,Bo as insertLink,de as isCodeBlockPreviewHiddenDecoration,An as isMarkOfType,F as isNodeOfType,Rs as isSelectionInTableCell,Sl as listenForTweetHeight,ys as loadKaTeX,Z as markdownToDoc,kl as matchEmbed,xa as parseWikiEmbed,Ho as removeLink,bs as renderMathInto,Vo as updateLink,Ca as wikiEmbedBasename,oe as withPriority};
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@meowdown/core",
|
|
3
3
|
"type": "module",
|
|
4
|
-
"version": "0.
|
|
4
|
+
"version": "0.58.0",
|
|
5
5
|
"license": "MIT",
|
|
6
6
|
"repository": {
|
|
7
7
|
"type": "git",
|
|
@@ -33,6 +33,8 @@
|
|
|
33
33
|
"hast-util-to-mdast": "^10.1.2",
|
|
34
34
|
"katex": "^0.18.1",
|
|
35
35
|
"mdast-util-to-markdown": "^2.1.2",
|
|
36
|
+
"micromark-util-decode-string": "^2.0.1",
|
|
37
|
+
"micromark-util-normalize-identifier": "^2.0.1",
|
|
36
38
|
"prosemirror-flat-list": "^0.7.1",
|
|
37
39
|
"prosemirror-highlight": "^0.15.3",
|
|
38
40
|
"rehype-parse": "^9.0.1",
|
|
@@ -41,7 +43,7 @@
|
|
|
41
43
|
"remark-stringify": "^11.0.0",
|
|
42
44
|
"unicode-by-name": "^0.2.0",
|
|
43
45
|
"unified": "^11.0.5",
|
|
44
|
-
"@meowdown/markdown": "^0.
|
|
46
|
+
"@meowdown/markdown": "^0.58.0"
|
|
45
47
|
},
|
|
46
48
|
"devDependencies": {
|
|
47
49
|
"@ocavue/tsconfig": "^0.7.1",
|