@meowdown/core 0.30.1 → 0.32.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/README.md CHANGED
@@ -52,26 +52,38 @@ const markdown = docToMarkdown(editor.state.doc)
52
52
 
53
53
  `Mod` is Cmd on macOS and Ctrl elsewhere. Each formatting shortcut inserts or removes the literal Markdown delimiters around the selection; each heading shortcut toggles the current block to that level (or back to a paragraph).
54
54
 
55
- | Key | Action | Markdown |
56
- | ------------- | ----------------------- | ------------------- |
57
- | `Mod-B` | Bold | `**bold**` |
58
- | `Mod-I` | Italic | `*italic*` |
59
- | `Mod-E` | Inline code | `` `code` `` |
60
- | `Mod-Shift-X` | Strikethrough | `~~strikethrough~~` |
61
- | `Mod-Shift-H` | Highlight | `==highlight==` |
62
- | `Mod-1` | Heading 1 | `# heading` |
63
- | `Mod-2` | Heading 2 | `## heading` |
64
- | `Mod-3` | Heading 3 | `### heading` |
65
- | `Mod-4` | Heading 4 | `#### heading` |
66
- | `Mod-5` | Heading 5 | `##### heading` |
67
- | `Mod-6` | Heading 6 | `###### heading` |
68
- | `Mod-.` | Fold or unfold a bullet | |
55
+ | Key | Action | Markdown |
56
+ | ----------------- | --------------------------------------------------------- | ------------------- |
57
+ | `Mod-B` | Bold | `**bold**` |
58
+ | `Mod-I` | Italic | `*italic*` |
59
+ | `Mod-E` | Inline code | `` `code` `` |
60
+ | `Mod-Shift-X` | Strikethrough | `~~strikethrough~~` |
61
+ | `Mod-Shift-H` | Highlight | `==highlight==` |
62
+ | `Mod-K` | Link | `[text](url)` |
63
+ | `Mod-Shift-K` | Insert a wikilink | `[[target]]` |
64
+ | `Mod-1` | Heading 1 | `# heading` |
65
+ | `Mod-2` | Heading 2 | `## heading` |
66
+ | `Mod-3` | Heading 3 | `### heading` |
67
+ | `Mod-4` | Heading 4 | `#### heading` |
68
+ | `Mod-5` | Heading 5 | `##### heading` |
69
+ | `Mod-6` | Heading 6 | `###### heading` |
70
+ | `Mod-.` | Fold or unfold a bullet | |
71
+ | `Mod-Enter` | Follow the link under the caret, or cycle a checkbox task | `- [ ]` / `- [x]` |
72
+ | `Mod-Shift-Enter` | Cycle a circle checkbox task | `+ [ ]` / `+ [x]` |
73
+ | `Mod-Shift-7` | Ordered list | `1. item` |
74
+ | `Mod-Shift-8` | Bullet list | `- item` |
75
+ | `Mod-Shift-9` | Checkbox task list | `- [ ] item` |
76
+ | `Alt-ArrowUp` | Move the block or list item up | |
77
+ | `Alt-ArrowDown` | Move the block or list item down | |
78
+ | `Escape` | Collapse the selection | |
79
+
80
+ The list-type toggles wrap the current block, convert a list of a different kind in place, and unwrap a list of the same kind back to a paragraph. `Mod-Shift-7/8/9` follow the physical digit key, so they work on layouts where Shift+digit types punctuation. `Alt-ArrowUp`/`Alt-ArrowDown` move a list item together with its nested children, or swap a non-list block with its neighbor. Typing `[` over a selection wraps it into an open wikilink (`[[selection`) with the wikilink menu searching it.
69
81
 
70
82
  `EDITOR_KEY_BINDINGS` is a literal (`as const`) object mapping every key above to its description, for host settings UIs and keybinding-collision checks.
71
83
 
72
84
  ## Round-trip fidelity
73
85
 
74
- `checkRoundTrip(markdown)` reports how faithfully markdown survives a parse-then-serialize round trip: `'exact'` (byte-identical modulo the trailing newline), `'normalizing'` (same non-blank lines, only blank-line layout differs), or `'lossy'` (a non-blank line changed, e.g. a closing ATX hash sequence or unaligned table columns). Hosts that keep markdown on disk can gate saves on it, opening lossy files read-only so a save never rewrites content.
86
+ [`checkRoundTrip(markdown)`](https://npmx.dev/package-docs/@meowdown%2Fcore#function-checkRoundTrip) reports how faithfully markdown survives a parse-then-serialize round trip: `'exact'`, `'normalizing'`, or `'lossy'`. Hosts that keep markdown on disk can gate saves on it, opening lossy files read-only so a save never rewrites content.
75
87
 
76
88
  ## Styling
77
89
 
@@ -87,27 +99,31 @@ meowdown's CSS is wrapped in a cascade layer, `@layer meowdown` (with sub-layers
87
99
  @import '@meowdown/core/style.css';
88
100
  ```
89
101
 
90
- Two things the variable list cannot show: `--meowdown-gutter` is the horizontal editor padding, applied to the editable root's `.meowdown-content` class (set by `@meowdown/react`), not `.ProseMirror`, so the block handle's drag preview stays unpadded; floating UI such as the block handle lives inside it, so keep it at least `3.5rem`. The selection variables (`--meowdown-selection`, `--meowdown-node-outline`, `--meowdown-node-selection`) are standalone, not derived from `--meowdown-accent`, so selection can be restyled independently.
102
+ Two things the variable list cannot show: `--meowdown-gutter` is the horizontal editor padding, applied to the editable root's `.meowdown-content` class (set by `@meowdown/react`), not `.ProseMirror`, so the block handle's drag preview stays unpadded; floating UI such as the block handle lives inside it, so keep it at least `3.5rem`. A headless mount (like the quick start above) has no `.meowdown-content`, so add that class to the mount element (or your own padding) yourself. The selection variables (`--meowdown-selection`, `--meowdown-node-outline`, `--meowdown-node-selection`) are standalone, not derived from `--meowdown-accent`, so selection can be restyled independently.
91
103
 
92
104
  Tags (`#tag`) render as pills via the `.md-tag` class, tinted from `--meowdown-accent`. Wire click handling with `defineTagClickHandler(({ tag, event }) => ...)` (or `@meowdown/react`'s `onTagClick` prop); `tag` is read from the rendered text without the leading `#`.
93
105
 
94
- 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).
106
+ 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`.
95
107
 
96
108
  Markdown links (`[text](url)`) render the label as an `<a href>` with the `.md-link` class, colored by `--meowdown-accent`; the `[`, `]`, and `(url)` syntax dims in show mode and hides in hide and focus modes. Wire click handling with `defineLinkClickHandler(({ href, event }) => ...)` (or `@meowdown/react`'s `onLinkClick` prop).
97
109
 
98
110
  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.
99
111
 
100
- Inline images (`![alt](src)`) stay literal text and render in place via a mark view, with the raw `![alt](src)` hidden in hide and focus modes. Add it with `defineImage({ resolveImageUrl, onImagePaste })` (or `@meowdown/react`'s image props). `resolveImageUrl` is optional and defaults to showing http(s) URLs as-is. Wire click handling with `defineImageClickHandler(({ src, alt, event }) => ...)` (or `@meowdown/react`'s `onImageClick` prop).
112
+ Inline images (`![alt](src)`) stay literal text and render in place via a mark view, with the raw `![alt](src)` hidden in hide and focus modes. Add it 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).
113
+
114
+ 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 `![](src)`; 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).
115
+
116
+ 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.
101
117
 
102
118
  Rendered images are resizable: drag the corner handle and the chosen size is written back into the source as a trailing comment, `![alt](src)<!-- {"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.
103
119
 
104
- Pasting a lone tweet or YouTube link can auto-embed it. `defineEmbedPaste()` (or `@meowdown/react`'s `embedPaste` prop) rewrites the pasted link to `![](url)` so it renders as an embed; one undo turns the embed back into the raw link. It is not part of `defineEditorExtension`; add it explicitly.
120
+ Pasting a lone tweet or YouTube link can auto-embed it: [`defineEmbedPaste`](https://npmx.dev/package-docs/@meowdown%2Fcore#function-defineEmbedPaste) (`@meowdown/react`'s `embedPaste` prop, on by default).
105
121
 
106
- Pasting rich-text HTML from a browser (a bullet list, **bold**, a link, ...) converts it to Markdown so the formatting survives instead of arriving as plain text. `defineHTMLPaste()` (applied by default in `@meowdown/react`) rewrites the clipboard's `text/html` through the unified (rehype / remark) pipeline and reparses the Markdown with the editor's schema; meowdown's own clipboard (tagged `data-pm-slice`) and any paste landing in a code block are left to the default path. Going the other way, `defineMarkdownCopy()` serializes copied content to Markdown for the clipboard's `text/plain` flavor, so pasting into a plain-text field keeps list markers and block structure. Neither is part of `defineEditorExtension`; add them explicitly.
122
+ Pasting rich-text HTML from a browser (a bullet list, **bold**, a link, ...) converts it to Markdown so the formatting survives instead of arriving as plain text: [`defineHTMLPaste`](https://npmx.dev/package-docs/@meowdown%2Fcore#function-defineHTMLPaste) rewrites the clipboard's `text/html` through the unified (rehype / remark) pipeline; meowdown's own clipboard (tagged `data-pm-slice`) and any paste landing in a code block are left to the default path. Going the other way, [`defineMarkdownCopy`](https://npmx.dev/package-docs/@meowdown%2Fcore#function-defineMarkdownCopy) serializes copied content to Markdown for the clipboard's `text/plain` flavor. Neither is part of `defineEditorExtension`; `@meowdown/react` applies both by default, a headless host adds them explicitly.
107
123
 
108
- Pressing Enter at the end of the document's first heading (the title line) can start a fresh empty bullet on the next line instead of a plain paragraph. `defineBulletAfterHeading()` binds this. It is not part of `defineEditorExtension`; add it explicitly.
124
+ Enter at the end of the document's first heading (the title line) can start a fresh empty bullet instead of a plain paragraph: [`defineBulletAfterHeading`](https://npmx.dev/package-docs/@meowdown%2Fcore#function-defineBulletAfterHeading) (`@meowdown/react`'s `bulletAfterHeading` prop). Not part of `defineEditorExtension`.
109
125
 
110
- Pressing ArrowUp on the first visual line or ArrowDown on the last, when the caret can move no further, can notify the host so it can move focus elsewhere (a previous/next note or page). `defineExitBoundaryHandler(({ direction, event }) => ...)` (or `@meowdown/react`'s `onExitBoundary` prop) fires with `direction` (`'up'` or `'down'`) and the original `KeyboardEvent`; return `false` to let the editor handle the key normally. It also fires for a selected node at the edge, and ignores arrows carrying a modifier. It is not part of `defineEditorExtension`; add it explicitly.
126
+ An arrow press that can move the caret no further can notify the host, so it can move focus elsewhere (a previous/next note or page): [`defineExitBoundaryHandler`](https://npmx.dev/package-docs/@meowdown%2Fcore#function-defineExitBoundaryHandler) (`@meowdown/react`'s `onExitBoundary` prop). Not part of `defineEditorExtension`.
111
127
 
112
128
  ## API
113
129
 
package/dist/index.d.ts CHANGED
@@ -4,8 +4,8 @@ import { defineReadonly } from "@prosekit/extensions/readonly";
4
4
  import { CodeBlockAttrs } from "@prosekit/extensions/code-block";
5
5
  import { Command, EditorState } from "@prosekit/pm/state";
6
6
  import { EditorView } from "@prosekit/pm/view";
7
- import { HorizontalRuleExtension } from "@prosekit/extensions/horizontal-rule";
8
7
  import { Mark, ProseMirrorNode } from "@prosekit/pm/model";
8
+ import { HorizontalRuleExtension } from "@prosekit/extensions/horizontal-rule";
9
9
  import { VirtualElement } from "@floating-ui/dom";
10
10
 
11
11
  //#region src/converters/check-roundtrip.d.ts
@@ -107,11 +107,21 @@ type HTMLCommentExtension = Extension<{
107
107
  declare function defineHTMLComment(): HTMLCommentExtension;
108
108
  //#endregion
109
109
  //#region src/extensions/inline-marks.d.ts
110
+ /**
111
+ * Attributes of the `mdImage` mark, derived from the image source
112
+ * `![alt](src "title")` and its optional trailing size comment
113
+ * `<!-- {"width":N,"height":M} -->`.
114
+ */
110
115
  interface MdImageAttrs {
116
+ /** The image destination, exactly as written in the source. */
111
117
  src: string;
118
+ /** The image alt text. */
112
119
  alt: string;
120
+ /** The image title, or `''` when the source has none. */
113
121
  title: string;
122
+ /** Display width in CSS pixels from the trailing comment, or `null`. */
114
123
  width: number | null;
124
+ /** Display height in CSS pixels from the trailing comment, or `null`. */
115
125
  height: number | null;
116
126
  }
117
127
  interface MdLinkTextAttrs {
@@ -121,6 +131,18 @@ interface MdWikilinkAttrs {
121
131
  target: string;
122
132
  display: string;
123
133
  }
134
+ /**
135
+ * Attributes of the `mdFile` mark: a whole `[label](url)` link that the host's
136
+ * `resolveFileLink` claimed as a file attachment, rendered as a file pill.
137
+ */
138
+ interface MdFileAttrs {
139
+ /** The link destination, exactly as written in the source. */
140
+ href: string;
141
+ /** The display name: the raw label slice, or the `href` basename when the label is empty. */
142
+ name: string;
143
+ /** The link title, or `''` when the source has none. */
144
+ title: string;
145
+ }
124
146
  /** mdPack keys for units that store no extra data; the syntax marks carry it. */
125
147
  type MdPackSimpleKey = 'bold' | 'italic' | 'code' | 'strike' | 'highlight' | 'autolink';
126
148
  /**
@@ -202,8 +224,96 @@ interface LinkEditOptions {
202
224
  type LinkEditHandler = (options: LinkEditOptions) => void;
203
225
  declare function defineLinkEditKeymap(onLinkEdit: LinkEditHandler): PlainExtension;
204
226
  //#endregion
227
+ //#region src/extensions/pending-replacement.d.ts
228
+ /** Where an accepted replacement lands relative to the source range. */
229
+ type PendingReplacementMode = 'replace' | 'append';
230
+ /** How a pending replacement ended. */
231
+ type PendingReplacementOutcome = 'accepted' | 'discarded';
232
+ /**
233
+ * A staged replacement: Markdown text accumulating over `[from, to]` that is
234
+ * only written into the document when accepted. Until then the document is
235
+ * untouched; discarding is a no-op.
236
+ */
237
+ interface PendingReplacement {
238
+ /** Start of the source range the replacement targets. */
239
+ from: number;
240
+ /** End of the source range the replacement targets. */
241
+ to: number;
242
+ /** The Markdown accumulated so far (e.g. streamed from an AI provider). */
243
+ text: string;
244
+ /** Whether accepting replaces the source range or inserts after its block. */
245
+ mode: PendingReplacementMode;
246
+ }
247
+ /** The active pending replacement, or null when there is none. */
248
+ declare function getPendingReplacement(state: EditorState): PendingReplacement | null;
249
+ /** Options for the `startPendingReplacement` command. */
250
+ interface StartPendingReplacementOptions extends PositionRange {
251
+ mode: PendingReplacementMode;
252
+ }
253
+ /** Options for the `acceptPendingReplacement` command. */
254
+ interface AcceptPendingReplacementOptions {
255
+ /** Overrides the staged mode for this accept (e.g. "Insert below" on a replace stage). */
256
+ mode?: PendingReplacementMode;
257
+ }
258
+ /** A pending-replacement change: text/range updates, or how the stage ended. */
259
+ type PendingReplacementEvent = {
260
+ type: 'update';
261
+ pending: PendingReplacement;
262
+ } | {
263
+ type: 'ended';
264
+ pending: PendingReplacement;
265
+ outcome: PendingReplacementOutcome;
266
+ };
267
+ type PendingReplacementHandler = (event: PendingReplacementEvent) => void;
268
+ /**
269
+ * Watches pending-replacement state and reports changes, so a UI layer can
270
+ * render the preview and know whether the stage was accepted or discarded.
271
+ */
272
+ declare function definePendingReplacementHandler(handler: PendingReplacementHandler): PlainExtension;
273
+ //#endregion
274
+ //#region src/extensions/mark-chunk.d.ts
275
+ /**
276
+ * Contiguous range with a uniform inline-mark set.
277
+ */
278
+ type MarkChunk = readonly [from: number, to: number, marks: readonly Mark[]];
279
+ //#endregion
280
+ //#region src/extensions/inline-text-to-mark-chunks.d.ts
281
+ /** What {@link FileLinkResolver} sees for one `[label](url)` link. */
282
+ interface FileLinkPayload {
283
+ /** The link destination, exactly as written in the source. */
284
+ href: string;
285
+ /** The raw label slice between the brackets; may be empty or contain nested syntax. */
286
+ label: string;
287
+ /** The link title, or `''` when the source has none. */
288
+ title: string;
289
+ }
290
+ /**
291
+ * Claims a `[label](url)` link as a file attachment. A claimed link carries a
292
+ * single `mdFile` mark over its whole source (rendered as a file pill by
293
+ * `defineFileView`) instead of the usual link marks, so link click/hover/menu
294
+ * no longer apply to it. Must be pure: parse results are cached and diffed,
295
+ * so the same input must always produce the same answer.
296
+ */
297
+ type FileLinkResolver = (link: FileLinkPayload) => boolean;
298
+ /** Host options that influence inline parsing. */
299
+ interface FileLinkOptions {
300
+ resolveFileLink?: FileLinkResolver;
301
+ }
302
+ /**
303
+ * Walk a textblock's inline content and produce a list of mark chunks
304
+ * with positions relative to the start of `text` (i.e. zero-based).
305
+ * Callers shift the chunks into the document's coordinate space.
306
+ */
307
+ declare function inlineTextToMarkChunks(/** Typed mark builders bound to the target schema. */
308
+
309
+ marks: TypedMarkBuilders, /** The raw inline text of one textblock (no block prefix). */
310
+
311
+ text: string, /** Host options; omit for the default parse. */
312
+
313
+ options?: FileLinkOptions): MarkChunk[];
314
+ //#endregion
205
315
  //#region src/extensions/extension.d.ts
206
- declare function defineEditorExtensionImpl(): import("@prosekit/core").Union<readonly [import("@prosekit/core").Extension<{
316
+ declare function defineEditorExtensionImpl(options: EditorExtensionOptions): import("@prosekit/core").Union<readonly [import("@prosekit/core").Extension<{
207
317
  Nodes: import("@prosekit/core").SimplifyDeeper<{
208
318
  paragraph: import("@prosekit/pm/model").Attrs;
209
319
  }>;
@@ -320,11 +430,15 @@ declare function defineEditorExtensionImpl(): import("@prosekit/core").Union<rea
320
430
  Marks: {
321
431
  mdImage: MdImageAttrs;
322
432
  };
433
+ }>, import("@prosekit/core").Extension<{
434
+ Marks: {
435
+ mdFile: MdFileAttrs;
436
+ };
323
437
  }>, import("@prosekit/core").Extension<{
324
438
  Marks: {
325
439
  mdPack: MdPackAttrs;
326
440
  };
327
- }>]>, import("@prosekit/core").Extension<import("@prosekit/core").ExtensionTyping<any, any, any>>, import("@prosekit/core").PlainExtension, import("@prosekit/core").Union<readonly [import("@prosekit/core").Extension<{
441
+ }>]>, import("@prosekit/core").Extension<import("@prosekit/core").ExtensionTyping<any, any, any>>, import("@prosekit/core").PlainExtension, import("@prosekit/core").PlainExtension, import("@prosekit/core").PlainExtension, import("@prosekit/core").Union<readonly [import("@prosekit/core").Extension<{
328
442
  Commands: {
329
443
  toggleEm: [];
330
444
  toggleStrong: [];
@@ -340,12 +454,26 @@ declare function defineEditorExtensionImpl(): import("@prosekit/core").Union<rea
340
454
  };
341
455
  }>, import("@prosekit/core").PlainExtension, import("@prosekit/core").PlainExtension, import("@prosekit/core").PlainExtension, import("@prosekit/core").BaseCommandsExtension, import("@prosekit/core").HistoryExtension, import("@prosekit/core").PlainExtension, import("@prosekit/core").PlainExtension, import("@prosekit/core").PlainExtension, import("@prosekit/core").Extension<{
342
456
  Commands: {
457
+ insertMarkdown: [markdown: string];
343
458
  selectText: [anchor: number, head?: number | undefined];
344
459
  selectTextBetween: [$anchor: import("@prosekit/pm/model").ResolvedPos, $head: import("@prosekit/pm/model").ResolvedPos, bias?: number | undefined];
345
460
  };
346
- }>]>;
461
+ }>, import("@prosekit/core").Union<readonly [import("@prosekit/core").PlainExtension, import("@prosekit/core").Extension<{
462
+ Commands: {
463
+ startPendingReplacement: [options: StartPendingReplacementOptions];
464
+ appendPendingReplacementText: [text: string];
465
+ acceptPendingReplacement: [options?: AcceptPendingReplacementOptions | undefined];
466
+ discardPendingReplacement: [];
467
+ };
468
+ }>, import("@prosekit/core").PlainExtension]>]>;
347
469
  type EditorExtension = ReturnType<typeof defineEditorExtensionImpl>;
348
- declare function defineEditorExtension(): EditorExtension;
470
+ /**
471
+ * Options for {@link defineEditorExtension}. Creation-time configuration: it
472
+ * is baked into the editor's parse pipeline, so changing it requires
473
+ * rebuilding the editor.
474
+ */
475
+ type EditorExtensionOptions = FileLinkOptions;
476
+ declare function defineEditorExtension(options?: EditorExtensionOptions): EditorExtension;
349
477
  type TypedEditor = Editor<EditorExtension>;
350
478
  //#endregion
351
479
  //#region src/extensions/schema.d.ts
@@ -487,13 +615,153 @@ declare function listenForTweetHeight(iframe: HTMLIFrameElement): () => void;
487
615
  declare function matchEmbed(src: string): EmbedDescriptor | undefined;
488
616
  //#endregion
489
617
  //#region src/extensions/exit-boundary.d.ts
618
+ /** Payload for {@link ExitBoundaryHandler}. */
490
619
  interface ExitBoundaryOptions {
620
+ /** The boundary the caret would leave: `up` at the document start, `down` at the end. */
491
621
  direction: 'up' | 'down';
622
+ /** The originating arrow key press. */
492
623
  event: KeyboardEvent;
493
624
  }
625
+ /**
626
+ * Called when an arrow key press would move the caret past the document
627
+ * boundary. Return `false` to let the editor handle the key normally; any
628
+ * other return value consumes it.
629
+ */
494
630
  type ExitBoundaryHandler = (options: ExitBoundaryOptions) => boolean | void;
631
+ /** Call `onExitBoundary` when an arrow key press would leave the document boundary. */
495
632
  declare function defineExitBoundaryHandler(onExitBoundary: ExitBoundaryHandler): PlainExtension;
496
633
  //#endregion
634
+ //#region src/extensions/file-paste.d.ts
635
+ type FilePasteHandler = (file: File) => string | undefined | Promise<string | undefined>;
636
+ type FileSaveErrorHandler = (error: unknown, file: File) => void;
637
+ /** Options for {@link defineFilePaste}. */
638
+ interface FilePasteOptions {
639
+ /**
640
+ * Persist a pasted/dropped file and return its markdown destination, or
641
+ * `undefined` to decline (nothing is inserted, but the event is consumed).
642
+ * An image (`image/*` MIME type) inserts `![](src)`; any other file inserts
643
+ * a `[name](src)` link.
644
+ */
645
+ onFilePaste?: FilePasteHandler;
646
+ /** Called when persisting a pasted/dropped file throws. Defaults to `console.error`. */
647
+ onFileSaveError?: FileSaveErrorHandler;
648
+ }
649
+ /**
650
+ * The markdown a saved file becomes: `![](destination)` for an image (a
651
+ * `type` starting with `image/`), a `[name](destination)` link otherwise,
652
+ * with `\`, `[`, and `]` escaped in the name. Exported so a host command that
653
+ * inserts file links itself (e.g. an attach-file picker) produces markdown
654
+ * byte-identical to a paste/drop.
655
+ */
656
+ declare function buildFileMarkdown(file: {
657
+ name: string;
658
+ type?: string;
659
+ }, destination: string): string;
660
+ /**
661
+ * Persist pasted/dropped files via `onFilePaste` and insert the returned
662
+ * markdown destination: `![](src)` for an image, a `[name](src)` link for any
663
+ * other file. Multiple files insert one link per line, in DataTransfer order.
664
+ */
665
+ declare function defineFilePaste(options?: FilePasteOptions): PlainExtension;
666
+ //#endregion
667
+ //#region src/extensions/file-click.d.ts
668
+ /** Payload for {@link FileClickHandler}. */
669
+ interface FileClickPayload {
670
+ /** The link destination, exactly as written in `[name](href)`. */
671
+ href: string;
672
+ /** The file name shown on the pill. */
673
+ name: string;
674
+ /**
675
+ * The originating click, or the `Mod-Enter` key press that followed the
676
+ * pill. Read modifier keys or position a popover from it.
677
+ */
678
+ event: MouseEvent | KeyboardEvent;
679
+ }
680
+ type FileClickHandler = (payload: FileClickPayload) => void;
681
+ /**
682
+ * Call `onClick` when the user clicks a rendered file pill, with the file's
683
+ * `href`, `name`, and the originating `MouseEvent`. The host decides what a
684
+ * click does (e.g. open the file in the OS default app).
685
+ */
686
+ declare function defineFileClickHandler(onClick: FileClickHandler): PlainExtension;
687
+ //#endregion
688
+ //#region src/extensions/file-view.d.ts
689
+ /** Metadata a host resolves for one file link, shown on its pill. */
690
+ interface FileInfo {
691
+ /** File size in bytes, shown as a human-readable suffix (e.g. `1.4 MB`). */
692
+ size?: number;
693
+ }
694
+ /**
695
+ * Resolve display metadata for a file `href`, directly or as a promise; the
696
+ * pill renders immediately and fills the metadata in when the promise
697
+ * settles. Return `undefined` for a file without metadata (e.g. one that no
698
+ * longer exists). Called once per rendered pill, so the same `href` may
699
+ * resolve repeatedly: cache in the host when resolving is expensive.
700
+ */
701
+ type FileInfoResolver = (href: string) => FileInfo | undefined | Promise<FileInfo | undefined>;
702
+ /** Options for {@link defineFileView}. */
703
+ interface FileViewOptions {
704
+ /** Resolve the metadata (file size) shown on a pill. Omit to show none. */
705
+ resolveFileInfo?: FileInfoResolver;
706
+ }
707
+ /**
708
+ * Render a claimed file link (the `mdFile` mark, see `resolveFileLink`) as an
709
+ * inline pill: a file-kind icon, the file name, and the size once
710
+ * `resolveFileInfo` supplies it. The pill never loads the file's content;
711
+ * clicks are reported through `defineFileClickHandler`.
712
+ */
713
+ declare function defineFileView(options?: FileViewOptions): PlainExtension;
714
+ //#endregion
715
+ //#region src/extensions/link-click.d.ts
716
+ interface LinkClickPayload {
717
+ href: string;
718
+ /** The originating click, or the `Mod-Enter` key press that followed the link. */
719
+ event: MouseEvent | KeyboardEvent;
720
+ }
721
+ type LinkClickHandler = (payload: LinkClickPayload) => void;
722
+ interface LinkCopyPayload {
723
+ href: string;
724
+ }
725
+ type LinkCopyHandler = (payload: LinkCopyPayload) => void;
726
+ declare function defineLinkClickHandler(onClick: LinkClickHandler): PlainExtension;
727
+ //#endregion
728
+ //#region src/extensions/tag-click.d.ts
729
+ interface TagClickPayload {
730
+ /** The tag name, without the leading `#`. */
731
+ tag: string;
732
+ /**
733
+ * The originating click, or the `Mod-Enter` key press that followed the tag.
734
+ * Read modifier keys or position a popover from it.
735
+ */
736
+ event: MouseEvent | KeyboardEvent;
737
+ }
738
+ type TagClickHandler = (payload: TagClickPayload) => void;
739
+ declare function defineTagClickHandler(onClick: TagClickHandler): PlainExtension;
740
+ //#endregion
741
+ //#region src/extensions/wikilink-click.d.ts
742
+ interface WikilinkClickPayload {
743
+ target: string;
744
+ /** The originating click, or the `Mod-Enter` key press that followed the link. */
745
+ event: MouseEvent | KeyboardEvent;
746
+ }
747
+ type WikilinkClickHandler = (payload: WikilinkClickPayload) => void;
748
+ declare function defineWikilinkClickHandler(onClick: WikilinkClickHandler): PlainExtension;
749
+ //#endregion
750
+ //#region src/extensions/follow-link.d.ts
751
+ interface FollowLinkHandlers {
752
+ onWikilinkClick?: WikilinkClickHandler;
753
+ onTagClick?: TagClickHandler;
754
+ onFileClick?: FileClickHandler;
755
+ onLinkClick?: LinkClickHandler;
756
+ }
757
+ /**
758
+ * Binds `Mod-Enter` to follow the wikilink, tag, file pill, or Markdown link
759
+ * under the caret, firing the same handlers a click does. Off a link the key
760
+ * falls through, so the list keymap keeps cycling checkbox tasks. High
761
+ * priority puts this ahead of every keymap binding.
762
+ */
763
+ declare function defineFollowLinkHandler(handlers: FollowLinkHandlers): PlainExtension;
764
+ //#endregion
497
765
  //#region src/extensions/html-paste.d.ts
498
766
  /**
499
767
  * Paste foreign rich-text HTML as meowdown Markdown. Rewrites the clipboard's
@@ -506,6 +774,7 @@ declare function defineExitBoundaryHandler(onExitBoundary: ExitBoundaryHandler):
506
774
  declare function defineHTMLPaste(): PlainExtension;
507
775
  //#endregion
508
776
  //#region src/extensions/image-click.d.ts
777
+ /** Payload for {@link ImageClickHandler}. */
509
778
  interface ImageClickPayload {
510
779
  /** The markdown `src`, exactly as written in `![alt](src)`. */
511
780
  src: string;
@@ -515,46 +784,27 @@ interface ImageClickPayload {
515
784
  event: MouseEvent;
516
785
  }
517
786
  type ImageClickHandler = (payload: ImageClickPayload) => void;
787
+ /**
788
+ * Call `onClick` when the user clicks a rendered image preview, with the
789
+ * image's markdown `src`, `alt`, and the originating `MouseEvent`.
790
+ */
518
791
  declare function defineImageClickHandler(onClick: ImageClickHandler): PlainExtension;
519
792
  //#endregion
520
793
  //#region src/extensions/image.d.ts
521
794
  type ImageUrlResolver = (src: string) => string | undefined;
522
- type ImagePasteHandler = (file: File) => string | undefined | Promise<string | undefined>;
523
- type ImageSaveErrorHandler = (error: unknown, file: File) => void;
795
+ /** Options for {@link defineImage}. */
524
796
  interface ImageOptions {
525
797
  /**
526
798
  * Map a markdown `src` to a displayable URL, or `undefined` to skip rendering
527
799
  * that image. Defaults to `defaultResolveImageUrl`.
528
800
  */
529
801
  resolveImageUrl?: ImageUrlResolver;
530
- /** Persist a pasted/dropped image file and return its markdown `src`, or `undefined` to decline. */
531
- onImagePaste?: ImagePasteHandler;
532
- /** Called when persisting a pasted/dropped image throws. Defaults to `console.error`. */
533
- onImageSaveError?: ImageSaveErrorHandler;
534
802
  }
535
803
  /** Show an `src` as-is when it is an http(s) URL, otherwise skip rendering it. */
536
804
  declare function defaultResolveImageUrl(src: string): string | undefined;
537
- /** Inline image/embed rendering (a mark view) plus paste/drop persistence. */
805
+ /** Inline image/embed rendering: a mark view on the `mdImage` mark. */
538
806
  declare function defineImage(options?: ImageOptions): PlainExtension;
539
807
  //#endregion
540
- //#region src/extensions/mark-chunk.d.ts
541
- /**
542
- * Contiguous range with a uniform inline-mark set.
543
- */
544
- type MarkChunk = readonly [from: number, to: number, marks: readonly Mark[]];
545
- //#endregion
546
- //#region src/extensions/inline-text-to-mark-chunks.d.ts
547
- /**
548
- * Walk a textblock's inline content and produce a list of mark chunks
549
- * with positions relative to the start of `text` (i.e. zero-based).
550
- * Callers shift the chunks into the document's coordinate space.
551
- */
552
- declare function inlineTextToMarkChunks(/** Typed mark builders bound to the target schema. */
553
-
554
- marks: TypedMarkBuilders, /** The raw inline text of one textblock (no block prefix). */
555
-
556
- text: string): MarkChunk[];
557
- //#endregion
558
808
  //#region src/extensions/key-bindings.d.ts
559
809
  /** Human-readable descriptions of the editor's formatting and heading shortcuts. */
560
810
  declare const EDITOR_KEY_BINDINGS: {
@@ -564,6 +814,7 @@ declare const EDITOR_KEY_BINDINGS: {
564
814
  readonly 'Mod-Shift-x': "Strikethrough";
565
815
  readonly 'Mod-Shift-h': "Highlight";
566
816
  readonly 'Mod-k': "Link";
817
+ readonly 'Mod-Shift-k': "Insert a wikilink";
567
818
  readonly 'Mod-1': "Heading 1";
568
819
  readonly 'Mod-2': "Heading 2";
569
820
  readonly 'Mod-3': "Heading 3";
@@ -571,20 +822,16 @@ declare const EDITOR_KEY_BINDINGS: {
571
822
  readonly 'Mod-5': "Heading 5";
572
823
  readonly 'Mod-6': "Heading 6";
573
824
  readonly 'Mod-.': "Fold or unfold a bullet";
825
+ readonly 'Mod-Enter': "Follow the link under the caret, or cycle a checkbox task";
826
+ readonly 'Mod-Shift-Enter': "Cycle a circle checkbox task";
827
+ readonly 'Mod-Shift-7': "Ordered list";
828
+ readonly 'Mod-Shift-8': "Bullet list";
829
+ readonly 'Mod-Shift-9': "Checkbox task list";
830
+ readonly 'Alt-ArrowUp': "Move the block or list item up";
831
+ readonly 'Alt-ArrowDown': "Move the block or list item down";
832
+ readonly Escape: "Collapse the selection";
574
833
  };
575
834
  //#endregion
576
- //#region src/extensions/link-click.d.ts
577
- interface LinkClickPayload {
578
- href: string;
579
- event: MouseEvent;
580
- }
581
- type LinkClickHandler = (payload: LinkClickPayload) => void;
582
- interface LinkCopyPayload {
583
- href: string;
584
- }
585
- type LinkCopyHandler = (payload: LinkCopyPayload) => void;
586
- declare function defineLinkClickHandler(onClick: LinkClickHandler): PlainExtension;
587
- //#endregion
588
835
  //#region src/extensions/mark-hover.d.ts
589
836
  interface MarkHoverHit<Payload> {
590
837
  payload: Payload;
@@ -608,7 +855,7 @@ type MarkMode = 'hide' | 'focus' | 'show';
608
855
  declare function defineMarkMode(mode: MarkMode): PlainExtension;
609
856
  //#endregion
610
857
  //#region src/extensions/mark-names.d.ts
611
- declare const MARK_NAMES: readonly ["mdWikilink", "mdImage", "mdMark", "mdEm", "mdStrong", "mdCode", "mdLinkText", "mdLinkUri", "mdLinkTitle", "mdDel", "mdHighlight", "mdTag", "mdPack"];
858
+ declare const MARK_NAMES: readonly ["mdWikilink", "mdImage", "mdFile", "mdMark", "mdEm", "mdStrong", "mdCode", "mdLinkText", "mdLinkUri", "mdLinkTitle", "mdDel", "mdHighlight", "mdTag", "mdPack"];
612
859
  type MarkName = (typeof MARK_NAMES)[number];
613
860
  //#endregion
614
861
  //#region src/extensions/markdown-copy.d.ts
@@ -637,37 +884,34 @@ type NodeName = (typeof NODE_NAMES)[number];
637
884
  */
638
885
  declare function isSelectionInTableCell(state: EditorState): boolean;
639
886
  //#endregion
640
- //#region src/extensions/tag-click.d.ts
641
- interface TagClickPayload {
642
- /** The tag name, without the leading `#`. */
643
- tag: string;
644
- /** The originating click. Read modifier keys or position a popover from it. */
645
- event: MouseEvent;
646
- }
647
- type TagClickHandler = (payload: TagClickPayload) => void;
648
- declare function defineTagClickHandler(onClick: TagClickHandler): PlainExtension;
649
- //#endregion
650
- //#region src/extensions/wikilink-click.d.ts
651
- interface WikilinkClickPayload {
652
- target: string;
653
- event: MouseEvent;
654
- }
655
- type WikilinkClickHandler = (payload: WikilinkClickPayload) => void;
656
- declare function defineWikilinkClickHandler(onClick: WikilinkClickHandler): PlainExtension;
657
- //#endregion
658
887
  //#region src/extensions/wikilink-trigger.d.ts
659
888
  /**
660
- * Binds `Mod-Shift-k` to open the wikilink menu.
889
+ * Binds `Mod-Shift-k` to open the wikilink menu, and `[` to wrap a selected
890
+ * phrase into an open wikilink (`[[phrase`) with the menu searching it.
661
891
  */
662
892
  declare function defineWikilinkTrigger(): PlainExtension;
663
893
  //#endregion
894
+ //#region src/utils/selected-text.d.ts
895
+ /**
896
+ * The current selection as Markdown: block structure (list markers, headings,
897
+ * blockquotes) is serialized, and inline Markdown syntax is already literal
898
+ * text in the document. A selection inside one textblock comes back as its
899
+ * bare text; a multi-block selection keeps its block markers, so downstream
900
+ * consumers (e.g. an AI prompt) see the same Markdown the user would.
901
+ */
902
+ declare function getSelectedText(state: EditorState): string;
903
+ //#endregion
664
904
  //#region src/utils/virtual-element.d.ts
665
905
  /**
666
906
  * Returns a Floating-UI virtual element tracking a document range.
907
+ *
908
+ * Positioning libraries re-measure asynchronously (resize observers, animation
909
+ * frames), so a measurement can fire after the view is destroyed or the range
910
+ * no longer resolves — those return the last known rect instead of throwing.
667
911
  */
668
912
  declare function getVirtualElementFromRange(view: EditorView, range: PositionRange): VirtualElement;
669
913
  //#endregion
670
914
  //#region src/extensions/spell-check.d.ts
671
915
  declare function defineSpellCheckPlugin(spellCheck: boolean): import("@prosekit/core").PlainExtension;
672
916
  //#endregion
673
- export { type CheckRoundTripOptions, type CodeBlockAttrs, type CodeToken, type DocToMarkdownOptions, EDITOR_KEY_BINDINGS, type EditorExtension, type EmbedDescriptor, type ExitBoundaryHandler, type ExitBoundaryOptions, type ImageClickHandler, type ImageClickPayload, type ImageOptions, type LinkAttrs, type LinkClickHandler, type LinkClickPayload, type LinkCopyHandler, type LinkCopyPayload, type LinkEditHandler, type LinkEditOptions, type LinkHoverHandler, type LinkUnit, type MarkChunk, type MarkMode, type MarkName, type MarkdownToDocOptions, type MdImageAttrs, type MdLinkTextAttrs, type MdWikilinkAttrs, type MeowdownHTMLCommentAttrs, type NodeName, type PlaceholderOptions, type PositionRange, Priority, type RoundTripFidelity, type TagClickHandler, type TagClickPayload, type TypedEditor, type TypedMarkBuilders, type VirtualElement, type WikilinkClickHandler, type WikilinkClickPayload, checkRoundTrip, codeBlockLanguages, defaultResolveImageUrl, defineBulletAfterHeading, defineCodeBlockSyntaxHighlight, defineEditorExtension, defineEmbedPaste, defineExitBoundaryHandler, defineHTMLComment, defineHTMLPaste, defineImage, defineImageClickHandler, defineLinkClickHandler, defineLinkCommands, defineLinkEditKeymap, defineLinkHoverHandler, defineMarkMode, defineMarkdownCopy, definePlaceholder, defineReadonly, defineSpellCheckPlugin, defineTagClickHandler, defineWikilinkClickHandler, defineWikilinkTrigger, docToMarkdown, getCodeTokens, getLinkUnitAt, getMarkBuilders, getVirtualElementFromRange, inlineTextToMarkChunks, insertLink, isSelectionInTableCell, listenForTweetHeight, markdownToDoc, matchEmbed, removeLink, updateLink, withPriority };
917
+ export { type AcceptPendingReplacementOptions, type CheckRoundTripOptions, type CodeBlockAttrs, 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 LinkAttrs, type LinkClickHandler, type LinkClickPayload, type LinkCopyHandler, type LinkCopyPayload, type LinkEditHandler, type LinkEditOptions, type LinkHoverHandler, type LinkUnit, type MarkChunk, type MarkMode, type MarkName, type MarkdownToDocOptions, type MdFileAttrs, type MdImageAttrs, type MdLinkTextAttrs, type MdWikilinkAttrs, type MeowdownHTMLCommentAttrs, type NodeName, type PendingReplacement, type PendingReplacementEvent, type PendingReplacementHandler, type PendingReplacementMode, type PendingReplacementOutcome, type PlaceholderOptions, type PositionRange, Priority, type RoundTripFidelity, type StartPendingReplacementOptions, type TagClickHandler, type TagClickPayload, type TypedEditor, type TypedMarkBuilders, type VirtualElement, type WikilinkClickHandler, type WikilinkClickPayload, buildFileMarkdown, checkRoundTrip, codeBlockLanguages, defaultResolveImageUrl, defineBulletAfterHeading, defineCodeBlockSyntaxHighlight, defineEditorExtension, defineEmbedPaste, defineExitBoundaryHandler, defineFileClickHandler, defineFilePaste, defineFileView, defineFollowLinkHandler, defineHTMLComment, defineHTMLPaste, defineImage, defineImageClickHandler, defineLinkClickHandler, defineLinkCommands, defineLinkEditKeymap, defineLinkHoverHandler, defineMarkMode, defineMarkdownCopy, definePendingReplacementHandler, definePlaceholder, defineReadonly, defineSpellCheckPlugin, defineTagClickHandler, defineWikilinkClickHandler, defineWikilinkTrigger, docToMarkdown, getCodeTokens, getLinkUnitAt, getMarkBuilders, getPendingReplacement, getSelectedText, getVirtualElementFromRange, inlineTextToMarkChunks, insertLink, isSelectionInTableCell, listenForTweetHeight, markdownToDoc, matchEmbed, removeLink, updateLink, withPriority };
package/dist/index.js CHANGED
@@ -1,25 +1,27 @@
1
- import{Priority as e,Priority as t,createMarkBuilders as n,createNodeBuilders as r,defineBaseCommands as i,defineBaseKeymap as a,defineCommands as o,defineDOMEventHandler 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,isAtBlockStart as re,isTextSelection as g,toggleNode as ie,union as _,unsetBlockType as ae,withPriority as oe,withPriority as v,withSkipCodeBlock as se}from"@prosekit/core";import{definePlaceholder as ce}from"@prosekit/extensions/placeholder";import{defineReadonly as le}from"@prosekit/extensions/readonly";import{isElementLike as ue,once as y}from"@ocavue/utils";import{defineBlockquote as de}from"@prosekit/extensions/blockquote";import{defineCodeBlock as fe,defineCodeBlockHighlight as pe}from"@prosekit/extensions/code-block";import{defineDoc as me}from"@prosekit/extensions/doc";import{defineGapCursor as he}from"@prosekit/extensions/gap-cursor";import{defineModClickPrevention as ge}from"@prosekit/extensions/mod-click-prevention";import{defineText as _e}from"@prosekit/extensions/text";import{defineVirtualSelection as ve}from"@prosekit/extensions/virtual-selection";import{Plugin as b,PluginKey as x,Selection as ye,TextSelection as S}from"@prosekit/pm/state";import{Decoration as C,DecorationSet as w}from"@prosekit/pm/view";import{LanguageDescription as be}from"@codemirror/language";import{languages as xe}from"@codemirror/language-data";import{classHighlighter as Se,highlightTree as Ce}from"@lezer/highlight";import{createParser as we}from"prosemirror-highlight/lezer";import{defineHeadingCommands as Te,defineHeadingInputRule as Ee,defineHeadingSpec as De}from"@prosekit/extensions/heading";import{defineHorizontalRule as Oe}from"@prosekit/extensions/horizontal-rule";import{AddMarkStep as ke,AddNodeMarkStep as Ae,RemoveMarkStep as je,RemoveNodeMarkStep as Me,ReplaceStep as Ne,Step as Pe,StepResult as Fe,Transform as Ie}from"@prosekit/pm/transform";import{DOMSerializer as Le,Mark as Re}from"@prosekit/pm/model";import{GFM as ze,parser as Be}from"@lezer/markdown";import{defineInputRule as Ve}from"@prosekit/extensions/input-rule";import{defineListCommands as He,defineListDropIndicator as Ue,defineListKeymap as We,defineListSerializer as Ge,defineListSpec as Ke,wrapInList as T}from"@prosekit/extensions/list";import{createListRenderingPlugin as qe,createSafariInputMethodWorkaroundPlugin as Je,createToggleCollapsedCommand as Ye,handleListMarkerMouseDown as Xe,unwrapListSlice as Ze,wrappingListInputRule as E}from"prosemirror-flat-list";import{defineParagraphCommands as Qe,defineParagraphKeymap as $e}from"@prosekit/extensions/paragraph";import{defineTableCellSpec as et,defineTableCommands as tt,defineTableDropIndicator as nt,defineTableEditingPlugin as rt,defineTableHeaderCellSpec as it,defineTableRowSpec as at,defineTableSpec as ot,deleteTable as st,isCellSelection as ct}from"@prosekit/extensions/table";import{closeHistory as lt}from"@prosekit/pm/history";import ut from"rehype-parse";import dt from"rehype-remark";import ft from"remark-gfm";import pt from"remark-stringify";import{unified as mt}from"unified";import{registerResizableHandleElement as ht,registerResizableRootElement as gt}from"@prosekit/web/resizable";import{triggerAutocomplete as _t}from"@prosekit/extensions/autocomplete";function D(e,t,n){let r=e.doc.content.size;if(t<0||t>r)return;let i=e.doc.resolve(t);if(!(!i.parent.isTextblock||i.parent.type.spec.code))return h(i,n)}const vt=new Set([`mdMark`,`mdLinkUri`,`mdLinkTitle`]),yt=new x(`mark-mode`);function bt(e){return new b({key:yt,state:{init:()=>e,apply:(e,t)=>t},props:{attributes:{"data-mark-mode":e},decorations:e===`focus`?e=>wt(e):void 0,clipboardTextSerializer:e===`show`?void 0:Ct}})}function xt(e){return m(bt(e))}function St(e){return yt.getState(e)}function Ct(e){let t=[];return e.content.forEach(e=>{let n=[];e.descendants(e=>!e.isText||!e.text?!0:(e.marks.some(e=>vt.has(e.type.name))||n.push(e.text),!1)),t.push(n.join(``))}),t.join(`
2
- `)}function wt(e){let{selection:t}=e;if(!t.empty)return w.empty;let n=t.$head,{parent:r}=n;if(!r.isTextblock||r.type.spec.code)return w.empty;let i=h(n,ee(e.schema,`mdPack`));return i?w.create(e.doc,[C.inline(i.from,i.to,{class:`show`})]):w.empty}function O(e,t){let n=St(t);return n?e.flatMap(e=>e.modes.includes(n)?[e.name]:[]):[]}function k(e,t,n){for(let r of n){let n=D(e,t,r);if(n)return n}}function A(e,t,n){let r=k(e,t,n);return r&&r.to===t?r:void 0}function j(e,t,n){let r=k(e,t,n);return r&&r.from===t?r:void 0}function M(e,t){let{from:n,to:r,empty:i}=e.selection;if(i)return;let a=k(e,n,t);return a&&a.from===n&&a.to===r?a:void 0}function Tt(e,t){return S.create(e.doc,t.from,t.to)}function Et(e){return(t,n)=>{let r=O(e,t);if(r.length===0||!g(t.selection))return!1;let i=t.selection;if(i.empty){let e=j(t,i.from,r);if(e)return n?.(t.tr.setSelection(Tt(t,e))),!0;if(A(t,i.from,r)){let e=t.doc.resolve(i.from);return i.from>=e.end()?!1:(n?.(t.tr.setSelection(S.create(t.doc,i.from+1))),!0)}return!1}let a=M(t,r);return a?(n?.(t.tr.setSelection(S.create(t.doc,a.to))),!0):!1}}function Dt(e){return(t,n)=>{let r=O(e,t);if(r.length===0||!g(t.selection))return!1;let i=t.selection;if(i.empty){let e=A(t,i.from,r);return e?(n?.(t.tr.setSelection(Tt(t,e))),!0):!1}let a=M(t,r);return a?(n?.(t.tr.setSelection(S.create(t.doc,a.from))),!0):!1}}function Ot(e){return(t,n)=>{let r=O(e,t);if(r.length===0||!t.selection.empty)return!1;let i=t.selection.from,a=A(t,i,r);return a?(n?.(t.tr.delete(a.from,a.to)),!0):!j(t,i,r)||i<=t.doc.resolve(i).start()?!1:(n?.(t.tr.delete(i-1,i)),!0)}}function kt(e){return(t,n)=>{let r=O(e,t);if(r.length===0||!t.selection.empty)return!1;let i=t.selection.from,a=j(t,i,r);return a?(n?.(t.tr.delete(a.from,a.to)),!0):!A(t,i,r)||i>=t.doc.resolve(i).end()?!1:(n?.(t.tr.delete(i,i+1)),!0)}}const At=`md-atom-selected`;function jt(e){return new b({key:new x(`atom-mark-selection`),props:{decorations:t=>{let n=O(e,t);if(n.length===0)return;let r=M(t,n);if(r)return w.create(t.doc,[C.inline(r.from,r.to,{class:At})]);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(C.inline(t,t+e.nodeSize,{class:At}))}),w.create(t.doc,s)}}})}function Mt({marks:e}){return _(v(l({ArrowRight:Et(e),ArrowLeft:Dt(e),Backspace:Ot(e),Delete:kt(e)}),t.high),m(jt(e)))}const N=new Map,Nt=new Map;async function Pt(e){let t=N.get(e);if(t!==void 0)return t;let n=be.matchLanguageName(xe,e,!0);if(!n)return N.set(e,null),null;let r=n.support;if(!r)try{r=await n.load()}catch(t){return console.error(`[meowdown] Failed to load language "${e}":`,t),N.set(e,null),null}return N.set(e,r),r}function Ft(e,t){let n=Nt.get(e);if(n)return n;let r=we({parse:e=>t.language.parser.parse(e.content),highlighter:Se});return Nt.set(e,r),r}const It=e=>{let t=e.language?.trim();if(!t)return[];let n=N.get(t);return n===null?[]:n?Ft(t,n)(e):Pt(t).then(()=>void 0)};function Lt(){return pe({parser:It,nodeTypes:[`codeBlock`]})}function Rt(e,t){let n=t.language.parser.parse(e),r=[];return Ce(n,Se,(e,t,n)=>{r.push([e,t,n])}),r}function zt(e,t){let n=t.trim();if(!n)return[];let r=N.get(n);return r===null?[]:r?Rt(e,r):Pt(n).then(t=>t?Rt(e,t):[])}function Bt(e,t){return(n,r)=>{if(r){let i=S.create(n.doc,e,t);r(n.tr.setSelection(i))}return!0}}function Vt(e,t,n){return(r,i)=>{if(i){let a=S.between(e,t,n);i(r.tr.setSelection(a))}return!0}}function Ht(){return o({selectText:Bt,selectTextBetween:Vt})}function Ut(){return f({type:`doc`,attr:`frontmatter`,default:null})}function Wt(){return p({name:`heading`,whitespace:`pre`})}function Gt(){return f({type:`heading`,attr:`setextUnderline`,default:null,toDOM:e=>e==null?null:[`data-setext-underline`,String(e)],parseDOM:e=>{let t=e.getAttribute(`data-setext-underline`);if(t==null)return null;let n=Number.parseInt(t,10);return Number.isSafeInteger(n)&&n>0?n:null}})}function Kt(){return f({type:`heading`,attr:`closingHashes`,default:null,toDOM:e=>e==null?null:[`data-closing-hashes`,String(e)],parseDOM:e=>{let t=e.getAttribute(`data-closing-hashes`);if(t==null)return null;let n=Number.parseInt(t,10);return Number.isSafeInteger(n)&&n>0?n:null}})}function P(e){return se(ie({type:`heading`,attrs:{level:e}}))}const qt=(e,t,n)=>re(e,n)?.parent.type.name===`heading`?ae()(e,t,n):!1;function Jt(){return l({"Mod-1":P(1),"Mod-2":P(2),"Mod-3":P(3),"Mod-4":P(4),"Mod-5":P(5),"Mod-6":P(6),Backspace:qt})}function Yt(){return _(De(),Wt(),Gt(),Kt(),Ee(),Te(),Jt())}function Xt(){return f({type:`horizontalRule`,attr:`marker`,default:null,toDOM:e=>e?[`data-hr-marker`,e]:null,parseDOM:e=>e.getAttribute(`data-hr-marker`)})}function Zt(){return _(Oe(),Xt())}function Qt(){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 $t(e){let[t,n,r]=e;return[t,n,r.map(e=>e.toJSON())]}function en(e,t){let[n,r,i]=t;return[n,r,i.map(t=>Re.fromJSON(e,t))]}var F=class e extends Pe{constructor(e){super(),this.chunks=e}apply(e){if(this.chunks.length===0)return Fe.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));o>=s||e.nodesBetween(o,s,(t,r)=>{if(!t.isText)return!0;let i=Math.max(o,r),c=Math.min(s,r+t.nodeSize);if(i>=c)return!1;let l=t.marks;for(let t of l)t.isInSet(a)||(n??=new Ie(e),n.removeMark(i,c,t));for(let t of a)t.isInSet(l)||(n??=new Ie(e),n.addMark(i,c,t));return!1})}return Fe.ok(n?n.doc:e)}invert(e){if(this.chunks.length===0)return tn;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 Ne(i,a,e.slice(i,a),!1)}map(e){return null}toJSON(){return{stepType:`batchSetMark`,chunks:this.chunks.map($t)}}static fromJSON(t,n){let r=n.chunks;return new e(r.map(e=>en(t,e)))}};Pe.jsonID(`batchSetMark`,F);const tn=new F([]),nn=new Set([`com`,`br`,`net`,`jp`,`org`,`in`,`de`,`ru`,`it`,`fr`]),rn=/^[a-z0-9](?:[a-z0-9-]*[a-z0-9])?$/i;function an(e){let t=e.indexOf(`/`);return t===-1?e:e.slice(0,t)}function on(e){let t=e.split(`.`);if(t.length<2)return!1;let n=t[t.length-1].toLowerCase();if(!nn.has(n)||t[t.length-2].length<3)return!1;for(let e of t)if(e.length>63||!rn.test(e))return!1;return!0}function I(e){return e===32||e===9||e===10||e===13}const sn=/^[a-z0-9-]+(?:\.[a-z0-9-]+)+(?:\/[^\s<]*)?/i,cn=/[\s(*_~]/;function ln(e){return e>=48&&e<=57||e>=65&&e<=90||e>=97&&e<=122||e===45}function un(e,t,n){let r=0;for(let i=0;i<t;i++)e[i]===n&&r++;return r}function dn(e){let t=e.length;for(;;){let n=e[t-1];if(/[?!.,:*_~]/.test(n)||n===`)`&&un(e,t,`)`)>un(e,t,`(`))t--;else if(n===`;`){let n=/&(?:#\d+|#x[a-f\d]+|\w+);$/.exec(e.slice(0,t));if(!n)break;t=n.index}else break}return t}const fn={parseInline:[{name:`BareAutolink`,before:`Link`,parse(e,t,n){if(!ln(t)||e.hasOpenLink)return-1;let r=e.slice(n-1,n);if(r!==``&&!cn.test(r))return-1;let i=sn.exec(e.slice(n,e.end));if(!i)return-1;let a=dn(i[0]);return a===0||!on(an(i[0].slice(0,a)))?-1:e.addElement(e.elt(`URL`,n,n+a))}}]};function pn(e){return e>=48&&e<=57||e>=65&&e<=90||e>=97&&e<=122||e===45||e===95||e>127&&/[\p{L}\p{N}]/u.test(String.fromCharCode(e))}function mn(e){return e>=65&&e<=90||e>=97&&e<=122||e>127&&/\p{L}/u.test(String.fromCharCode(e))}const hn={defineNodes:[{name:`Hashtag`}],parseInline:[{name:`Hashtag`,parse(e,t,n){if(t!==35||!/\s|^$/.test(e.slice(n-1,n)))return-1;let r=n+1,i=!1;for(;r<e.end;){let t=e.char(r);if(!pn(t))break;i||=mn(t),r++}return i?e.addElement(e.elt(`Hashtag`,n,r)):-1}}]},gn={resolve:`Highlight`,mark:`HighlightMark`},_n=/[!"#$%&'()*+,\-./:;<=>?@[\\\]^_`{|}~\u{A1}\u{2010}-\u{2027}]/u,vn={defineNodes:[{name:`Highlight`},{name:`HighlightMark`}],parseInline:[{name:`Highlight`,after:`Emphasis`,parse(e,t,n){if(t!==61||e.char(n+1)!==61||e.char(n+2)===61)return-1;let r=e.slice(n-1,n),i=e.slice(n+2,n+3),a=/\s|^$/.test(r),o=/\s|^$/.test(i),s=_n.test(r),c=_n.test(i);return e.addDelimiter(gn,n,n+2,!o&&(!c||a||s),!a&&(!s||o||c))}}]},yn={defineNodes:[{name:`Wikilink`},{name:`WikilinkMark`}],parseInline:[{name:`Wikilink`,before:`Link`,parse(e,t,n){if(t!==91||e.char(n+1)!==91)return-1;let r=!1;for(let t=n+2;t<e.end-1;t++){let i=e.char(t);if(i===93){if(e.char(t+1)!==93||!r)return-1;let i=t+2;return e.addElement(e.elt(`Wikilink`,n,i,[e.elt(`WikilinkMark`,n,n+2),e.elt(`WikilinkMark`,t,i)]))}if(i===91||i===10)return-1;i!==32&&i!==9&&(r=!0)}return-1}}]};function bn(e){return e.end}const L=Be.configure([ze,hn,yn,fn,vn]),xn=L.configure({parseInline:[{name:`SkipInline`,before:`Escape`,parse:bn}]});function R(e){return L.parseInline(e,0)}function z(e,t,n=[]){for(let r of e)t(r)&&n.push(r),z(r.children,t,n);return n}function Sn(e){let t={};for(let n of e.nodeSet.types)t[n.name]=n.id;return t}const B=Sn(L),Cn=/^<!--\s*(\{[^}]*\})\s*-->$/,wn=/<!--\s*\{[^}]*\}\s*-->$/;function Tn(e){let t=Cn.exec(e.trim());if(!t)return;let n;try{n=JSON.parse(t[1])}catch{return}if(typeof n!=`object`||!n)return;let r=En(n);return Object.keys(r).length>0?r:void 0}function En(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 Dn(e){return`<!-- ${JSON.stringify(e)} -->`}function On(e){return e.replace(wn,``)}function kn(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 An(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 jn(){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 Mn(){return d({name:`mdWikilink`,constructor:jn()})}const Nn=new Map([[B.Emphasis,`mdEm`],[B.StrongEmphasis,`mdStrong`],[B.InlineCode,`mdCode`],[B.Strikethrough,`mdDel`],[B.Highlight,`mdHighlight`],[B.EmphasisMark,`mdMark`],[B.CodeMark,`mdMark`],[B.LinkMark,`mdMark`],[B.StrikethroughMark,`mdMark`],[B.HighlightMark,`mdMark`],[B.URL,`mdLinkUri`],[B.LinkTitle,`mdLinkTitle`],[B.Hashtag,`mdTag`],[B.WikilinkMark,`mdMark`]]);function Pn(e,t){let n=R(t),r=[];return V(n,[],0,t.length,t,e,r),r}function Fn(e){if(/^[a-z][a-z0-9+.-]*:/i.test(e))return e;if(/^[^\s@]+@[^\s@]+$/.test(e))return`mailto:${e}`;if(/^www\./i.test(e)||on(an(e)))return`https://${e}`}function In(e){return e.slice(1,-1).replaceAll(/\\(.)/g,`$1`)}function V(e,t,n,r,i,a,o){let s=n;for(let n=0;n<e.length;n++){let r=e[n];r.from>s&&H(o,s,r.from,t);let c=r.type;if(c===B.Link)Ln(r,t,i,a,o);else if(c===B.Image){let c=Rn(r,e[n+1],i);zn(r,t,i,a,o,c),c&&n++,s=c?c.to:r.to;continue}else if(c===B.Wikilink)Bn(r,t,i,a,o);else if(c===B.URL){let e=Fn(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;c===B.Emphasis?e=`italic`:c===B.StrongEmphasis?e=`bold`:c===B.InlineCode?e=`code`:c===B.Strikethrough?e=`strike`:c===B.Highlight?e=`highlight`:c===B.Autolink&&(e=`autolink`);let n=e?[...t,a.mdPack.create({key:e})]:t,s=Nn.get(c),l=s?[...n,a[s].create()]:n;r.children.length===0?H(o,r.from,r.to,l):V(r.children,l,r.from,r.to,i,a,o)}s=r.to}s<r&&H(o,s,r,t)}function Ln(e,t,n,r,i){let a=-1,o=null,s=null,c=0;for(let t of e.children)t.type===B.LinkMark?(c++,c===2&&(a=t.from)):t.type===B.URL&&o===null?o=t:t.type===B.LinkTitle&&s===null&&(s=t);let l=o?n.slice(o.from,o.to):``,u=s?In(n.slice(s.from,s.to)):``,d=l?r.mdLinkText.create({href:l}):null,f=e=>a>=0&&e<a&&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===B.Wikilink){Bn(t,e,n,r,i),h=t.to;continue}let a=Nn.get(t.type),o=a?[...e,r[a].create()]:e;t.children.length===0?H(i,t.from,t.to,o):V(t.children,o,t.from,t.to,n,r,i),h=t.to}h<e.to&&H(i,h,e.to,m)}function Rn(e,t,n){if(!t||t.type!==B.Comment||t.from!==e.to)return;let r=Tn(n.slice(t.from,t.to));if(r)return{magic:r,to:t.to}}function zn(e,t,n,r,i,a){let o=e.children.find(e=>e.type===B.URL);if(!o){Ln(e,t,n,r,i);return}let s=e.children.filter(e=>e.type===B.LinkMark),c=e.children.find(e=>e.type===B.LinkTitle),l=n.slice(o.from,o.to),u=s.length>=2?n.slice(s[0].to,s[1].from):``,d=c?In(n.slice(c.from,c.to)):``,f=a?.magic.width??null,p=a?.magic.height??null,m=a?.to??e.to;H(i,e.from,m,[...t,r.mdImage.create({src:l,alt:u,title:d,width:f,height:p})])}function Bn(e,t,n,r,i){let{target:a,display:o}=An(n.slice(e.from,e.to));H(i,e.from,e.to,[...t,r.mdWikilink.create({target:a,display:o})])}function H(e,t,n,r){if(t>=n)return;let i=e.at(-1);if(i&&i[1]===t&&kn(i[2],r)){e[e.length-1]=[i[0],n,i[2]];return}e.push([t,n,r])}const Vn=`inline-marks-applied`,Hn=new WeakMap;let Un=0,Wn=0;function Gn(e,t,n){let r=Hn.get(e);if(r?Wn++:(Un++,r=Pn(hi(n),e.textContent),Hn.set(e,r)),t===0)return r;let i=[];for(let[e,n,a]of r)i.push([e+t,n+t,a]);return i}function Kn(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 qn(e,t){let n=[];return e.doc.nodesBetween(t.from,t.to,(t,r)=>{if(t.type.spec.code)return!1;if(!t.isTextblock)return!0;if(t.childCount===0)return!1;let i=Gn(t,r+1,e.schema);return i.length>0&&n.push(...i),!1}),n}function Jn(){return new b({key:new x(`inline-mark`),appendTransaction(e,t,n){for(let t of e)if(t.getMeta(Vn))return null;let r=qn(n,Kn(e,n));if(r.length===0)return null;let i=n.tr.step(new F(r));return i.setMeta(Vn,!0),i.setMeta(`addToHistory`,!1),i},view(e){return e.dispatch(Yn(e.state)),{}}})}function Yn(e){return e.tr.setMeta(`inline-marks-trigger`,!0)}function Xn(){return m(Jn())}function Zn(){return u({name:`mdImage`,inclusive:!1,attrs:{src:{default:``},alt:{default:``},title:{default:``},width:{default:null},height:{default:null}},toDOM:()=>[`span`,{class:`md-image`},0],parseDOM:[{tag:`span.md-image`}]})}function Qn(){return u({name:`mdMark`,inclusive:!1,toDOM:()=>[`span`,{class:`md-mark`},0],parseDOM:[{tag:`span.md-mark`}]})}function $n(){return u({name:`mdEm`,toDOM:()=>[`em`,0],parseDOM:[{tag:`em`}]})}function er(){return u({name:`mdStrong`,toDOM:()=>[`strong`,0],parseDOM:[{tag:`strong`}]})}function tr(){return u({name:`mdCode`,toDOM:()=>[`code`,0],parseDOM:[{tag:`code`}]})}function nr(){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 rr(){return u({name:`mdLinkUri`,inclusive:!1,toDOM:()=>[`span`,{class:`md-link-uri`},0],parseDOM:[{tag:`span.md-link-uri`}]})}function ir(){return u({name:`mdLinkTitle`,inclusive:!1,toDOM:()=>[`span`,{class:`md-link-title`},0],parseDOM:[{tag:`span.md-link-title`}]})}function ar(){return u({name:`mdDel`,toDOM:()=>[`del`,0],parseDOM:[{tag:`del`}]})}function or(){return u({name:`mdHighlight`,toDOM:()=>[`mark`,0],parseDOM:[{tag:`mark`}]})}function sr(){return u({name:`mdTag`,toDOM:()=>[`span`,{class:`md-tag`},0],parseDOM:[{tag:`span.md-tag`}]})}function cr(){return u({name:`mdWikilink`,inclusive:!1,attrs:{target:{default:``},display:{default:``}},toDOM:()=>[`span`,{class:`md-wikilink`},0],parseDOM:[{tag:`span.md-wikilink`}]})}function lr(){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 ur(){return _(Qn(),$n(),er(),tr(),nr(),rr(),ir(),ar(),or(),sr(),cr(),Zn(),lr())}function dr(e,t=0){let n=t,r=0;for(let t=0;t<e.length;t++)e.charCodeAt(t)===96?(r++,r>n&&(n=r)):r=0;return n}const U={em:{node:B.Emphasis,delim:`*`},strong:{node:B.StrongEmphasis,delim:`**`},code:{node:B.InlineCode,delim:"`"},del:{node:B.Strikethrough,delim:`~~`},highlight:{node:B.Highlight,delim:`==`}},fr=new Set([B.EmphasisMark,B.CodeMark,B.LinkMark,B.StrikethroughMark,B.HighlightMark]);function pr(e){return[e.children[0],e.children.at(-1)]}function mr(e){let{type:t,children:n}=e;if(t===B.Emphasis||t===B.StrongEmphasis||t===B.Strikethrough||t===B.Highlight)return[n[0].to,n.at(-1).from];if(t===B.Link||t===B.Image){let e=n.find((e,t)=>t>0&&e.type===B.LinkMark);return e?[n[0].to,e.from]:null}return null}function W(e,t,n){for(let r of e){if(r.to<=t||r.from>=n||t<=r.from&&r.to<=n)continue;let i=mr(r);return i&&i[0]<=t&&n<=i[1]?W(r.children,t,n):W(e,Math.min(t,r.from),Math.max(n,r.to))}return[t,n]}function hr(e,t,n){for(let r of e)if(!(r.to<=t||r.from>=n)&&(t>r.from||r.to>n))return hr(e,Math.min(t,r.from),Math.max(n,r.to));return[t,n]}function gr(e,t,n){for(;t<n&&I(e.charCodeAt(t));)t++;for(;n>t&&I(e.charCodeAt(n-1));)n--;return[t,n]}function _r(e,t,n,r){let i=z(R(e),e=>e.type===r.node||fr.has(e.type));for(let r=t;r<n;r++)if(!I(e.charCodeAt(r))&&i.every(e=>!(e.from<=r&&r<e.to)))return!1;return!0}function vr(e,t,n,r,i){let a=R(e),o=z(a,e=>e.type===r.node);return i?xr(e,o,t,n):yr(e,a,o,t,n,r)}function yr(e,t,n,r,i,a){for(let e=0;e!==i-r;){e=i-r,[r,i]=W(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]=pr(e);o.push({from:t.from,to:t.to,insert:``}),o.push({from:n.from,to:n.to,insert:``})}let[s,c]=br(e,r,i,o,a);return o.push({from:r,to:r,insert:s},{from:i,to:i,insert:c}),o}function br(e,t,n,r,i){if(i.node!==B.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(dr(a)+1),s=a.startsWith("`")||a.endsWith("`")?` `:``;return[o+s,s+o]}function xr(e,t,n,r){let i=[];for(let a of t){if(a.to<=n||a.from>=r)continue;let[t,o]=pr(a),s=Math.max(n,t.to),c=Math.min(r,o.from);for(s>=c&&([s,c]=[t.to,o.from]),[s,c]=hr(a.children.slice(1,-1),s,c);s>t.to&&I(e.charCodeAt(s-1));)s--;for(;c<o.from&&I(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 Sr(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=R(e),o=z(a,e=>e.type===n.node).findLast(e=>e.from<=t&&t<=e.to);if(o){let[e,n]=pr(o);return{kind:`move`,pos:t===o.from?e.to:t===o.to?n.from:o.to}}return Cr(a,t)||e[t-1]===r[0]||e[t]===r[0]?null:{kind:`insert`,pos:t}}function Cr(e,t){for(let n of e)if(n.from<t&&t<n.to){let e=mr(n);return!e||t<e[0]||t>e[1]?!0:Cr(n.children,t)}return!1}function G(e){return(t,n)=>{if(t.selection.empty)return wr(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]=gr(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:_r(a,c,l,e)}),!1});let c=s.length>0&&s.every(e=>e.active),l=s.filter(e=>c||!e.active).flatMap(t=>vr(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(S.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 wr(e,t,n){let{$from:r}=t.selection,i=r.parent;if(!i.isTextblock||i.type.spec.code)return!1;let a=Sr(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(S.create(o.doc,i+a.pos)),a.kind===`insert`&&(o.insertText(e.delim+e.delim,i+a.pos),o.setSelection(S.create(o.doc,i+a.pos+e.delim.length))),n(o.scrollIntoView())}return!0}function Tr(){return o({toggleEm:()=>G(U.em),toggleStrong:()=>G(U.strong),toggleCode:()=>G(U.code),toggleDel:()=>G(U.del),toggleHighlight:()=>G(U.highlight)})}function Er(){return l({"Mod-b":G(U.strong),"Mod-i":G(U.em),"Mod-e":G(U.code),"Mod-Shift-x":G(U.del),"Mod-Shift-h":G(U.highlight)})}function Dr(){return _(Tr(),Er())}function Or(e,t,n){let r;return e.doc.nodesBetween(t.from,t.to,(e,i)=>(e.isText&&e.marks.some(e=>e.type.name===n)&&(r={from:Math.max(i,t.from),to:Math.min(i+e.nodeSize,t.to)}),!0)),r}function K(e,t){let n=D(e,t,`mdLinkText`),r=D(e,t,`mdPack`),i=r??n;if(!i)return;let a=r?.mark.attrs,o=n?.mark.attrs?.href??``;if(!r||a?.key!==`link`)return{unit:{from:i.from,to:i.to},href:o,title:``};let s=Or(e,i,`mdLinkUri`),c=s?s.from-2:i.to-3,l=s?s.from:i.to-1;return{unit:{from:i.from,to:i.to},label:{from:i.from+1,to:c},dest:{from:l,to:i.to-1},href:a.data.href,title:a.data.title}}function kr(e){let t=e.trim();return t?Fn(t)??t:``}function Ar(e,t){return e+(t?` "${t.replaceAll(/(["\\])/g,String.raw`\$1`)}"`:``)}function jr(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]=gr(a.textContent,n.parentOffset,r.parentOffset);if(!(s>=c))return{from:o+s,to:o+c}}function Mr(e={}){return(t,n)=>{let r=Ar(kr(e.href??``),e.title??``),i=jr(t);if(!i)return!1;if(n){let{from:e,to:a}=i,o=t.tr,s=`](${r})`;o.insertText(s,a).insertText(`[`,e),n(o.setSelection(S.create(o.doc,e,a+1+s.length)).scrollIntoView())}return!0}}function Nr(e){return(t,n)=>{let r=K(t,t.selection.from);if(!r?.dest)return!1;let i=Ar(kr(e.href??r.href),e.title??r.title);return n&&n(t.tr.insertText(i,r.dest.from,r.dest.to).scrollIntoView()),!0}}function Pr(){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 Fr(){return o({insertLink:Mr,updateLink:Nr,removeLink:Pr})}function Ir(e){return(t,n,r)=>{let i=K(t,t.selection.from);if(i){if(n&&r){let{unit:{from:a,to:o}}=i;n(t.tr.setSelection(S.create(t.doc,a,o)).scrollIntoView()),r.focus(),e({from:a,to:o,link:i})}return!0}let a=jr(t);if(a){if(n&&r){let{from:i,to:o}=a;n(t.tr.setSelection(S.create(t.doc,i,o)).scrollIntoView()),r.focus(),e({from:i,to:o,link:void 0})}return!0}return!1}}function Lr(e){return l({"Mod-k":Ir(e)})}function Rr(){return f({type:`list`,attr:`marker`,default:null,splittable:!0,toDOM:e=>e===`)`||e===`*`||e===`+`?[`data-list-marker`,e]:null,parseDOM:e=>{let t=e.getAttribute(`data-list-marker`);return t===`)`||t===`*`||t===`+`?t:null}})}function zr(){return f({type:`list`,attr:`taskMarker`,default:null,splittable:!0,toDOM:e=>e===`X`?[`data-list-task-marker`,e]:null,parseDOM:e=>e.getAttribute(`data-list-task-marker`)===`X`?`X`:null})}function Br(e){return e===2||e===3||e===4}function Vr(){return f({type:`list`,attr:`markerGap`,default:1,splittable:!0,toDOM:e=>Br(e)?[`data-list-marker-gap`,String(e)]:null,parseDOM:e=>{let t=Number.parseInt(e.getAttribute(`data-list-marker-gap`)??``,10);return Br(t)?t:1}})}const Hr=[E(/^\s?([*-])\s$/,{kind:`bullet`,collapsed:!1}),E(/^\s?(\d+)\.\s$/,({match:e})=>{let t=e[1],n=t?parseInt(t,10):void 0;return{kind:`ordered`,collapsed:!1,order:n&&n>=2&&Number.isSafeInteger(n)?n:null}}),E(/^\s?\[([\sXx]?)]\s$/,({match:e})=>({kind:`task`,checked:[`x`,`X`].includes(e[1]),collapsed:!1})),E(/^\s?\+\s$/,{kind:`task`,marker:`+`,checked:!1,collapsed:!1})];function Ur(){return _(Hr.map(Ve))}function Wr(){return T({kind:`task`,marker:`+`})}function Gr(){return T({kind:`task`,marker:null})}function Kr(){return o({wrapInCircleTask:Wr,wrapInSquareTask:Gr})}function qr(e){let{$from:t}=e.selection;for(let e=t.depth;e>0;e--){let n=t.node(e);if(n.type.name===`list`)return n.attrs}return null}function Jr(){return(e,t,n)=>{let r=qr(e),i=r?.kind===`task`&&r.marker!==`+`,a;return a=i&&!r?.checked?{kind:`task`,marker:r?.marker??null,checked:!0}:i&&r?.checked?{kind:`bullet`,marker:null,checked:!1}:{kind:`task`,marker:null,checked:!1},T(a)(e,t,n)}}function Yr(){return(e,t,n)=>{let r=qr(e),i=r?.kind===`task`&&r.marker===`+`,a;return a=i&&!r?.checked?{kind:`task`,marker:`+`,checked:!0}:i&&r?.checked?{kind:`bullet`,marker:null,checked:!1}:{kind:`task`,marker:`+`,checked:!1},T(a)(e,t,n)}}function q(e){return e.type.name===`list`&&e.attrs.kind===`bullet`&&e.childCount>=2&&e.firstChild?.type!==e.type}const Xr=e=>{let t=e.attrs;return t.kind===`task`?{...t,checked:!t.checked}:q(e)?{...t,collapsed:!t.collapsed}:t};function Zr(){return m(()=>[new b({props:{handleDOMEvents:{mousedown:(e,t)=>Xe({view:e,event:t,onListClick:Xr})}}}),qe(),new b({props:{transformCopied:Ze}}),Je()])}function Qr(){return o({toggleListCollapsed:()=>Ye({isToggleable:q})})}function $r(){return l({"Mod-Enter":Jr(),"Mod-Shift-Enter":Yr(),"Mod-.":Ye({isToggleable:q})})}function ei(){return _(Ke(),Zr(),We(),He(),Ge(),Ue(),Ur(),$r(),Rr(),zr(),Vr(),Kr(),Qr())}function ti(){return p({name:`paragraph`,content:`inline*`,group:`block`,whitespace:`pre`,parseDOM:[{tag:`p`}],toDOM(){return[`p`,0]}})}function ni(){return _(v(ti(),t.highest),Qe(),$e())}function ri(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 ii=`paragraph`;function ai(){return _(p({name:`tableCell`,content:ii}),p({name:`tableHeaderCell`,content:ii}))}const oi=(e,t)=>{let{selection:n}=e;return!ct(n)||!n.isColSelection()||!n.isRowSelection()?!1:st(e,t)};function si(){return v(l({Backspace:oi,Delete:oi}),t.high)}function ci(){return _(ot(),at(),et(),it(),ai(),rt({allowTableNodeSelection:!0}),tt(),nt(),si())}function li(){return _(ni(),me(),Ut(),_e(),de(),ei(),Yt(),ci(),fe(),Zt(),Qt(),ur(),Lt(),Xn(),Dr(),Fr(),Mn(),Mt({marks:[{name:`mdImage`,modes:[`hide`,`focus`,`show`]},{name:`mdWikilink`,modes:[`hide`,`focus`,`show`]}]}),a(),i(),c(),he(),ve(),ge(),Ht())}function ui(){return li()}const di=y(()=>{let e=ui().schema;if(e==null)throw Error(`Unexpected empty schema`);return e}),fi=y(()=>r(di())),pi=y(()=>n(di())),mi=`meowdown_mark_builders`;function hi(e){let t=e.cached[mi];if(t)return t;let r=n(e);return e.cached[mi]=r,r}const gi=`meowdown_node_builders`;function _i(e){let t=e.cached[gi];if(t)return t;let n=r(e);return e.cached[gi]=n,n}function J(e,t={}){let{nodes:n=fi(),frontmatter:r=!1}=t,i,a=e;if(r){let[t,n]=yi(e);i=t,n&&(a=e.slice(n))}let o=bi(n,xn.parse(a).cursor(),a);return n.doc(i===void 0?{}:{frontmatter:i},o)}const vi=/^---[ \t]*\r?\n([\s\S]*?\n)?---[ \t]*(?:\r?\n|$)/;function yi(e){let t=vi.exec(e);return t?[(t[1]??``).replace(/\r?\n$/,``),t[0].length]:[]}function bi(e,t,n){let r=[];if(!t.firstChild())return r;do r.push(...Y(e,t,n));while(t.nextSibling());return t.parent(),r}function Y(e,t,n){switch(t.type.id){case B.ATXHeading1:return[X(e,t,n,1,!1)];case B.ATXHeading2:return[X(e,t,n,2,!1)];case B.ATXHeading3:return[X(e,t,n,3,!1)];case B.ATXHeading4:return[X(e,t,n,4,!1)];case B.ATXHeading5:return[X(e,t,n,5,!1)];case B.ATXHeading6:return[X(e,t,n,6,!1)];case B.SetextHeading1:return[X(e,t,n,1,!0)];case B.SetextHeading2:return[X(e,t,n,2,!0)];case B.Paragraph:return[$(e,t,n)];case B.CommentBlock:return[Ti(e,t,n)];case B.HTMLBlock:case B.ProcessingInstructionBlock:return[$(e,t,n)];case B.Blockquote:return[Ei(e,t,n)];case B.BulletList:return Di(e,t,n,`bullet`);case B.OrderedList:return Di(e,t,n,`ordered`);case B.FencedCode:case B.CodeBlock:return[ki(e,t,n)];case B.HorizontalRule:{let r=n.slice(t.from,t.to).trimEnd();return[e.horizontalRule({marker:r===`---`?null:r})]}case B.Table:return[Ai(e,t,n)];case B.Task:return[$(e,t,n)];default:return n.slice(t.from,t.to).trim()===``?[]:(console.warn(`[meowdown] unsupported lezer block "${t.type.name}"`),[$(e,t,n)])}}function X(e,t,n,r,i){let a=t.from,o=t.from,s=t.to,c=-1,l=-1;if(t.firstChild()){t.type.id===B.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===B.HeaderMark&&n>o&&(s=n,c=n,l=r),t.parent()}let u=Q(n.slice(o,s),Z(n,o)).trim(),d=i?xi(n,c,l)||1:null,f=!i&&c>=0&&Si(n,c,l)||null;return e.heading({level:r,setextUnderline:d,closingHashes:f},u)}function xi(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 Si(e,t,n){if(t<0)return 0;let r=0;for(let i=t;i<n;i++)e.charCodeAt(i)===35&&r++;return r}function Z(e,t){let n=e.lastIndexOf(`
3
- `,t-1)+1,r=0;for(let i=n;i<t;i++)r+=e.charCodeAt(i)===9?4-r%4:1;return r}function Ci(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 Q(e,t){return t===0||!e.includes(`
1
+ import{Priority as e,Priority as t,createMarkBuilders as n,createNodeBuilders as r,defineBaseCommands as i,defineBaseKeymap as a,defineCommands as o,defineDOMEventHandler as s,defineHistory as c,defineKeymap as l,defineMarkSpec as u,defineMarkView as d,defineNodeAttr as f,defineNodeSpec as p,definePlugin as m,getMarkRange as h,getMarkType as ee,getNodeType as te,isAllSelection as ne,isApple as re,isAtBlockStart as ie,isNodeSelection as ae,isTextSelection as g,toggleNode as oe,union as _,unsetBlockType as se,withPriority as ce,withPriority as v,withSkipCodeBlock as le}from"@prosekit/core";import{definePlaceholder as ue}from"@prosekit/extensions/placeholder";import{defineReadonly as de}from"@prosekit/extensions/readonly";import{isElementLike as fe,once as y}from"@ocavue/utils";import{defineBlockquote as pe}from"@prosekit/extensions/blockquote";import{defineCodeBlock as me,defineCodeBlockHighlight as he}from"@prosekit/extensions/code-block";import{defineDoc as ge}from"@prosekit/extensions/doc";import{defineGapCursor as _e}from"@prosekit/extensions/gap-cursor";import{defineModClickPrevention as ve}from"@prosekit/extensions/mod-click-prevention";import{defineText as ye}from"@prosekit/extensions/text";import{defineVirtualSelection as be}from"@prosekit/extensions/virtual-selection";import{NodeSelection as xe,Plugin as b,PluginKey as x,Selection as Se,TextSelection as S}from"@prosekit/pm/state";import{Decoration as C,DecorationSet as w}from"@prosekit/pm/view";import{LanguageDescription as Ce}from"@codemirror/language";import{languages as we}from"@codemirror/language-data";import{classHighlighter as Te,highlightTree as Ee}from"@lezer/highlight";import{createParser as De}from"prosemirror-highlight/lezer";import{DOMSerializer as Oe,Mark as ke,Slice as T}from"@prosekit/pm/model";import{defineHeadingCommands as Ae,defineHeadingInputRule as je,defineHeadingSpec as Me}from"@prosekit/extensions/heading";import{defineHorizontalRule as Ne}from"@prosekit/extensions/horizontal-rule";import{AddMarkStep as Pe,AddNodeMarkStep as Fe,RemoveMarkStep as Ie,RemoveNodeMarkStep as Le,ReplaceStep as Re,Step as ze,StepResult as Be,Transform as Ve}from"@prosekit/pm/transform";import{GFM as He,parser as Ue}from"@lezer/markdown";import{defineInputRule as We}from"@prosekit/extensions/input-rule";import{defineListCommands as Ge,defineListDropIndicator as Ke,defineListKeymap as qe,defineListSerializer as Je,defineListSpec as Ye,moveList as Xe,toggleList as Ze,wrapInList as E}from"@prosekit/extensions/list";import{createListRenderingPlugin as Qe,createSafariInputMethodWorkaroundPlugin as $e,createToggleCollapsedCommand as et,handleListMarkerMouseDown as tt,unwrapListSlice as nt,wrappingListInputRule as D}from"prosemirror-flat-list";import{defineTableCellSpec as rt,defineTableCommands as it,defineTableDropIndicator as at,defineTableEditingPlugin as ot,defineTableHeaderCellSpec as st,defineTableRowSpec as ct,defineTableSpec as lt,deleteTable as ut,isCellSelection as dt}from"@prosekit/extensions/table";import{defineParagraphCommands as ft,defineParagraphKeymap as pt}from"@prosekit/extensions/paragraph";import{closeHistory as mt}from"@prosekit/pm/history";import ht from"rehype-parse";import gt from"rehype-remark";import _t from"remark-gfm";import vt from"remark-stringify";import{unified as yt}from"unified";import{registerResizableHandleElement as bt,registerResizableRootElement as xt}from"@prosekit/web/resizable";import{triggerAutocomplete as St}from"@prosekit/extensions/autocomplete";function O(e,t,n){let r=e.doc.content.size;if(t<0||t>r)return;let i=e.doc.resolve(t);if(!(!i.parent.isTextblock||i.parent.type.spec.code))return h(i,n)}const Ct=new Set([`mdMark`,`mdLinkUri`,`mdLinkTitle`]),wt=new x(`mark-mode`);function Tt(e){return new b({key:wt,state:{init:()=>e,apply:(e,t)=>t},props:{attributes:{"data-mark-mode":e},decorations:e===`focus`?e=>kt(e):void 0,clipboardTextSerializer:e===`show`?void 0:Ot}})}function Et(e){return m(Tt(e))}function Dt(e){return wt.getState(e)}function Ot(e){let t=[];return e.content.forEach(e=>{let n=[];e.descendants(e=>!e.isText||!e.text?!0:(e.marks.some(e=>Ct.has(e.type.name))||n.push(e.text),!1)),t.push(n.join(``))}),t.join(`
2
+ `)}function kt(e){let{selection:t}=e;if(!t.empty)return w.empty;let n=t.$head,{parent:r}=n;if(!r.isTextblock||r.type.spec.code)return w.empty;let i=h(n,ee(e.schema,`mdPack`));return i?w.create(e.doc,[C.inline(i.from,i.to,{class:`show`})]):w.empty}function k(e,t){let n=Dt(t);return n?e.flatMap(e=>e.modes.includes(n)?[e.name]:[]):[]}function At(e,t,n){for(let r of n){let n=O(e,t,r);if(n)return n}}function A(e,t,n){let r=At(e,t,n);return r&&r.to===t?r:void 0}function jt(e,t,n){let r=At(e,t,n);return r&&r.from===t?r:void 0}function Mt(e,t){let{from:n,to:r,empty:i}=e.selection;if(i)return;let a=At(e,n,t);return a&&a.from===n&&a.to===r?a:void 0}function Nt(e,t){return S.create(e.doc,t.from,t.to)}function Pt(e){return(t,n)=>{let r=k(e,t);if(r.length===0||!g(t.selection))return!1;let i=t.selection;if(i.empty){let e=jt(t,i.from,r);if(e)return n?.(t.tr.setSelection(Nt(t,e))),!0;if(A(t,i.from,r)){let e=t.doc.resolve(i.from);return i.from>=e.end()?!1:(n?.(t.tr.setSelection(S.create(t.doc,i.from+1))),!0)}return!1}let a=Mt(t,r);return a?(n?.(t.tr.setSelection(S.create(t.doc,a.to))),!0):!1}}function Ft(e){return(t,n)=>{let r=k(e,t);if(r.length===0||!g(t.selection))return!1;let i=t.selection;if(i.empty){let e=A(t,i.from,r);return e?(n?.(t.tr.setSelection(Nt(t,e))),!0):!1}let a=Mt(t,r);return a?(n?.(t.tr.setSelection(S.create(t.doc,a.from))),!0):!1}}function It(e){return(t,n)=>{let r=k(e,t);if(r.length===0||!t.selection.empty)return!1;let i=t.selection.from,a=A(t,i,r);return a?(n?.(t.tr.delete(a.from,a.to)),!0):!jt(t,i,r)||i<=t.doc.resolve(i).start()?!1:(n?.(t.tr.delete(i-1,i)),!0)}}function Lt(e){return(t,n)=>{let r=k(e,t);if(r.length===0||!t.selection.empty)return!1;let i=t.selection.from,a=jt(t,i,r);return a?(n?.(t.tr.delete(a.from,a.to)),!0):!A(t,i,r)||i>=t.doc.resolve(i).end()?!1:(n?.(t.tr.delete(i,i+1)),!0)}}const Rt=`md-atom-selected`;function zt(e){return new b({key:new x(`atom-mark-selection`),props:{decorations:t=>{let n=k(e,t);if(n.length===0)return;let r=Mt(t,n);if(r)return w.create(t.doc,[C.inline(r.from,r.to,{class:Rt})]);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(C.inline(t,t+e.nodeSize,{class:Rt}))}),w.create(t.doc,s)}}})}function Bt({marks:e}){return _(v(l({ArrowRight:Pt(e),ArrowLeft:Ft(e),Backspace:It(e),Delete:Lt(e)}),t.high),m(zt(e)))}const j=new Map,Vt=new Map;async function Ht(e){let t=j.get(e);if(t!==void 0)return t;let n=Ce.matchLanguageName(we,e,!0);if(!n)return j.set(e,null),null;let r=n.support;if(!r)try{r=await n.load()}catch(t){return console.error(`[meowdown] Failed to load language "${e}":`,t),j.set(e,null),null}return j.set(e,r),r}function Ut(e,t){let n=Vt.get(e);if(n)return n;let r=De({parse:e=>t.language.parser.parse(e.content),highlighter:Te});return Vt.set(e,r),r}const Wt=e=>{let t=e.language?.trim();if(!t)return[];let n=j.get(t);return n===null?[]:n?Ut(t,n)(e):Ht(t).then(()=>void 0)};function Gt(){return he({parser:Wt,nodeTypes:[`codeBlock`]})}function Kt(e,t){let n=t.language.parser.parse(e),r=[];return Ee(n,Te,(e,t,n)=>{r.push([e,t,n])}),r}function qt(e,t){let n=t.trim();if(!n)return[];let r=j.get(n);return r===null?[]:r?Kt(e,r):Ht(n).then(t=>t?Kt(e,t):[])}function Jt(e,t){return(n,r)=>{if(r){let i=S.create(n.doc,e,t);r(n.tr.setSelection(i))}return!0}}function Yt(e,t,n){return(r,i)=>{if(i){let a=S.between(e,t,n);i(r.tr.setSelection(a))}return!0}}function Xt(e){return(t,n)=>{if(!e.trim())return!1;let r=Y(e,{nodes:Hi(t.schema)}).content;if(r.childCount===0)return!1;let i=r.childCount===1&&r.child(0).type.name===`paragraph`?new T(r,1,1):new T(r,0,T.maxOpen(r).openEnd);return n&&n(t.tr.replaceSelection(i).scrollIntoView()),!0}}function Zt(){return o({insertMarkdown:Xt,selectText:Jt,selectTextBetween:Yt})}const Qt=(e,t,n)=>{let{selection:r}=e;return r.empty||n?.composing?!1:(t?.(e.tr.setSelection(S.near(r.$head))),!0)};function $t(){return v(l({Escape:Qt}),t.low)}function en(){return f({type:`doc`,attr:`frontmatter`,default:null})}function tn(){return p({name:`heading`,whitespace:`pre`})}function nn(){return f({type:`heading`,attr:`setextUnderline`,default:null,toDOM:e=>e==null?null:[`data-setext-underline`,String(e)],parseDOM:e=>{let t=e.getAttribute(`data-setext-underline`);if(t==null)return null;let n=Number.parseInt(t,10);return Number.isSafeInteger(n)&&n>0?n:null}})}function rn(){return f({type:`heading`,attr:`closingHashes`,default:null,toDOM:e=>e==null?null:[`data-closing-hashes`,String(e)],parseDOM:e=>{let t=e.getAttribute(`data-closing-hashes`);if(t==null)return null;let n=Number.parseInt(t,10);return Number.isSafeInteger(n)&&n>0?n:null}})}function M(e){return le(oe({type:`heading`,attrs:{level:e}}))}const an=(e,t,n)=>ie(e,n)?.parent.type.name===`heading`?se()(e,t,n):!1;function on(){return l({"Mod-1":M(1),"Mod-2":M(2),"Mod-3":M(3),"Mod-4":M(4),"Mod-5":M(5),"Mod-6":M(6),Backspace:an})}function sn(){return _(Me(),tn(),nn(),rn(),je(),Ae(),on())}function cn(){return f({type:`horizontalRule`,attr:`marker`,default:null,toDOM:e=>e?[`data-hr-marker`,e]:null,parseDOM:e=>e.getAttribute(`data-hr-marker`)})}function ln(){return _(Ne(),cn())}function un(){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 dn(e){let[t,n,r]=e;return[t,n,r.map(e=>e.toJSON())]}function fn(e,t){let[n,r,i]=t;return[n,r,i.map(t=>ke.fromJSON(e,t))]}var N=class e extends ze{constructor(e){super(),this.chunks=e}apply(e){if(this.chunks.length===0)return Be.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));o>=s||e.nodesBetween(o,s,(t,r)=>{if(!t.isText)return!0;let i=Math.max(o,r),c=Math.min(s,r+t.nodeSize);if(i>=c)return!1;let l=t.marks;for(let t of l)t.isInSet(a)||(n??=new Ve(e),n.removeMark(i,c,t));for(let t of a)t.isInSet(l)||(n??=new Ve(e),n.addMark(i,c,t));return!1})}return Be.ok(n?n.doc:e)}invert(e){if(this.chunks.length===0)return pn;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 Re(i,a,e.slice(i,a),!1)}map(e){return null}toJSON(){return{stepType:`batchSetMark`,chunks:this.chunks.map(dn)}}static fromJSON(t,n){let r=n.chunks;return new e(r.map(e=>fn(t,e)))}};ze.jsonID(`batchSetMark`,N);const pn=new N([]),mn=new Set([`com`,`br`,`net`,`jp`,`org`,`in`,`de`,`ru`,`it`,`fr`]),hn=/^[a-z0-9](?:[a-z0-9-]*[a-z0-9])?$/i;function gn(e){let t=e.indexOf(`/`);return t===-1?e:e.slice(0,t)}function _n(e){let t=e.split(`.`);if(t.length<2)return!1;let n=t[t.length-1].toLowerCase();if(!mn.has(n)||t[t.length-2].length<3)return!1;for(let e of t)if(e.length>63||!hn.test(e))return!1;return!0}function P(e){return e===32||e===9||e===10||e===13}const vn=/^[a-z0-9-]+(?:\.[a-z0-9-]+)+(?:\/[^\s<]*)?/i,yn=/[\s(*_~]/;function bn(e){return e>=48&&e<=57||e>=65&&e<=90||e>=97&&e<=122||e===45}function xn(e,t,n){let r=0;for(let i=0;i<t;i++)e[i]===n&&r++;return r}function Sn(e){let t=e.length;for(;;){let n=e[t-1];if(/[?!.,:*_~]/.test(n)||n===`)`&&xn(e,t,`)`)>xn(e,t,`(`))t--;else if(n===`;`){let n=/&(?:#\d+|#x[a-f\d]+|\w+);$/.exec(e.slice(0,t));if(!n)break;t=n.index}else break}return t}const Cn={parseInline:[{name:`BareAutolink`,before:`Link`,parse(e,t,n){if(!bn(t)||e.hasOpenLink)return-1;let r=e.slice(n-1,n);if(r!==``&&!yn.test(r))return-1;let i=vn.exec(e.slice(n,e.end));if(!i)return-1;let a=Sn(i[0]);return a===0||!_n(gn(i[0].slice(0,a)))?-1:e.addElement(e.elt(`URL`,n,n+a))}}]};function wn(e){return e>=48&&e<=57||e>=65&&e<=90||e>=97&&e<=122||e===45||e===95||e>127&&/[\p{L}\p{N}]/u.test(String.fromCharCode(e))}function Tn(e){return e>=65&&e<=90||e>=97&&e<=122||e>127&&/\p{L}/u.test(String.fromCharCode(e))}const En={defineNodes:[{name:`Hashtag`}],parseInline:[{name:`Hashtag`,parse(e,t,n){if(t!==35||!/\s|^$/.test(e.slice(n-1,n)))return-1;let r=n+1,i=!1;for(;r<e.end;){let t=e.char(r);if(!wn(t))break;i||=Tn(t),r++}return i?e.addElement(e.elt(`Hashtag`,n,r)):-1}}]},Dn={resolve:`Highlight`,mark:`HighlightMark`},On=/[!"#$%&'()*+,\-./:;<=>?@[\\\]^_`{|}~\u{A1}\u{2010}-\u{2027}]/u,kn={defineNodes:[{name:`Highlight`},{name:`HighlightMark`}],parseInline:[{name:`Highlight`,after:`Emphasis`,parse(e,t,n){if(t!==61||e.char(n+1)!==61||e.char(n+2)===61)return-1;let r=e.slice(n-1,n),i=e.slice(n+2,n+3),a=/\s|^$/.test(r),o=/\s|^$/.test(i),s=On.test(r),c=On.test(i);return e.addDelimiter(Dn,n,n+2,!o&&(!c||a||s),!a&&(!s||o||c))}}]},An={defineNodes:[{name:`Wikilink`},{name:`WikilinkMark`}],parseInline:[{name:`Wikilink`,before:`Link`,parse(e,t,n){if(t!==91||e.char(n+1)!==91)return-1;let r=!1;for(let t=n+2;t<e.end-1;t++){let i=e.char(t);if(i===93){if(e.char(t+1)!==93||!r)return-1;let i=t+2;return e.addElement(e.elt(`Wikilink`,n,i,[e.elt(`WikilinkMark`,n,n+2),e.elt(`WikilinkMark`,t,i)]))}if(i===91||i===10)return-1;i!==32&&i!==9&&(r=!0)}return-1}}]};function jn(e){return e.end}const F=Ue.configure([He,En,An,Cn,kn]),Mn=F.configure({parseInline:[{name:`SkipInline`,before:`Escape`,parse:jn}]});function I(e){return F.parseInline(e,0)}function L(e,t,n=[]){for(let r of e)t(r)&&n.push(r),L(r.children,t,n);return n}function Nn(e){let t={};for(let n of e.nodeSet.types)t[n.name]=n.id;return t}const R=Nn(F),Pn=/^<!--\s*(\{[^}]*\})\s*-->$/,Fn=/<!--\s*\{[^}]*\}\s*-->$/;function In(e){let t=Pn.exec(e.trim());if(!t)return;let n;try{n=JSON.parse(t[1])}catch{return}if(typeof n!=`object`||!n)return;let r=Ln(n);return Object.keys(r).length>0?r:void 0}function Ln(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 Rn(e){return`<!-- ${JSON.stringify(e)} -->`}function zn(e){return e.replace(Fn,``)}function Bn(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 Vn(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 Hn(){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 Un(){return d({name:`mdWikilink`,constructor:Hn()})}const Wn=new Map([[R.Emphasis,`mdEm`],[R.StrongEmphasis,`mdStrong`],[R.InlineCode,`mdCode`],[R.Strikethrough,`mdDel`],[R.Highlight,`mdHighlight`],[R.EmphasisMark,`mdMark`],[R.CodeMark,`mdMark`],[R.LinkMark,`mdMark`],[R.StrikethroughMark,`mdMark`],[R.HighlightMark,`mdMark`],[R.URL,`mdLinkUri`],[R.LinkTitle,`mdLinkTitle`],[R.Hashtag,`mdTag`],[R.WikilinkMark,`mdMark`]]);function Gn(e,t,n){let r=I(t),i=[];return B(r,[],0,t.length,t,e,i,n),i}function Kn(e){if(/^[a-z][a-z0-9+.-]*:/i.test(e))return e;if(/^[^\s@]+@[^\s@]+$/.test(e))return`mailto:${e}`;if(/^www\./i.test(e)||_n(gn(e)))return`https://${e}`}function z(e){return e.slice(1,-1).replaceAll(/\\(.)/g,`$1`)}function B(e,t,n,r,i,a,o,s){let c=n;for(let n=0;n<e.length;n++){let r=e[n];r.from>c&&V(o,c,r.from,t);let l=r.type;if(l===R.Link){let e=Yn(r,t,i,a,s);e?V(o,r.from,r.to,e):Xn(r,t,i,a,o)}else if(l===R.Image){let s=Zn(r,e[n+1],i);Qn(r,t,i,a,o,s),s&&n++,c=s?s.to:r.to;continue}else if(l===R.Wikilink)$n(r,t,i,a,o);else if(l===R.URL){let e=Kn(i.slice(r.from,r.to)),n=e?a.mdLinkText.create({href:e}):a.mdLinkUri.create();V(o,r.from,r.to,[...t,n])}else{let e;l===R.Emphasis?e=`italic`:l===R.StrongEmphasis?e=`bold`:l===R.InlineCode?e=`code`:l===R.Strikethrough?e=`strike`:l===R.Highlight?e=`highlight`:l===R.Autolink&&(e=`autolink`);let n=e?[...t,a.mdPack.create({key:e})]:t,c=Wn.get(l),u=c?[...n,a[c].create()]:n;r.children.length===0?V(o,r.from,r.to,u):B(r.children,u,r.from,r.to,i,a,o,s)}c=r.to}c<r&&V(o,c,r,t)}function qn(e){let t=-1,n=-1,r=null,i=null,a=0;for(let o of e.children)o.type===R.LinkMark?(a++,a===1&&(t=o.to),a===2&&(n=o.from)):o.type===R.URL&&r===null?r=o:o.type===R.LinkTitle&&i===null&&(i=o);return{labelFrom:t,labelTo:n,urlNode:r,titleNode:i}}function Jn(e){let t=e.split(/[?#]/,1)[0],n=t.split(/[/\\]/).findLast(Boolean)??t;try{return decodeURIComponent(n)}catch{return n}}function Yn(e,t,n,r,i){let a=i?.resolveFileLink;if(!a)return;let{labelFrom:o,labelTo:s,urlNode:c,titleNode:l}=qn(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?z(n.slice(l.from,l.to)):``;if(!a({href:u,label:d,title:f}))return;let p=d||Jn(u);return[...t,r.mdFile.create({href:u,name:p,title:f})]}function Xn(e,t,n,r,i){let{labelTo:a,urlNode:o,titleNode:s}=qn(e),c=o?n.slice(o.from,o.to):``,l=s?z(n.slice(s.from,s.to)):``,u=c?r.mdLinkText.create({href:c}):null,d=e=>a>=0&&e<a&&u!==null,f=r.mdPack.create({key:`link`,data:{href:c,title:l}}),p=[...t,f],m=e.from;for(let t of e.children){if(t.from>m){let e=d(m)?[...p,u]:p;V(i,m,t.from,e)}let e=d(t.from)?[...p,u]:p;if(t.type===R.Wikilink){$n(t,e,n,r,i),m=t.to;continue}let a=Wn.get(t.type),o=a?[...e,r[a].create()]:e;t.children.length===0?V(i,t.from,t.to,o):B(t.children,o,t.from,t.to,n,r,i,void 0),m=t.to}m<e.to&&V(i,m,e.to,p)}function Zn(e,t,n){if(!t||t.type!==R.Comment||t.from!==e.to)return;let r=In(n.slice(t.from,t.to));if(r)return{magic:r,to:t.to}}function Qn(e,t,n,r,i,a){let o=e.children.find(e=>e.type===R.URL);if(!o){Xn(e,t,n,r,i);return}let s=e.children.filter(e=>e.type===R.LinkMark),c=e.children.find(e=>e.type===R.LinkTitle),l=n.slice(o.from,o.to),u=s.length>=2?n.slice(s[0].to,s[1].from):``,d=c?z(n.slice(c.from,c.to)):``,f=a?.magic.width??null,p=a?.magic.height??null,m=a?.to??e.to;V(i,e.from,m,[...t,r.mdImage.create({src:l,alt:u,title:d,width:f,height:p})])}function $n(e,t,n,r,i){let{target:a,display:o}=Vn(n.slice(e.from,e.to));V(i,e.from,e.to,[...t,r.mdWikilink.create({target:a,display:o})])}function V(e,t,n,r){if(t>=n)return;let i=e.at(-1);if(i&&i[1]===t&&Bn(i[2],r)){e[e.length-1]=[i[0],n,i[2]];return}e.push([t,n,r])}const er=`inline-marks-applied`;let tr=0,nr=0;function rr(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 ir(e){let t=new WeakMap;function n(n,r,i){let a=t.get(n);if(a?nr++:(tr++,a=Gn(Bi(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 b({key:new x(`inline-mark`),appendTransaction(e,t,n){for(let t of e)if(t.getMeta(er))return null;let i=r(n,rr(e,n));if(i.length===0)return null;let a=n.tr.step(new N(i));return a.setMeta(er,!0),a.setMeta(`addToHistory`,!1),a},view(e){return e.dispatch(ar(e.state)),{}}})}function ar(e){return e.tr.setMeta(`inline-marks-trigger`,!0)}function or(e){return m(ir(e))}function sr(){return u({name:`mdImage`,inclusive:!1,attrs:{src:{default:``},alt:{default:``},title:{default:``},width:{default:null},height:{default:null}},toDOM:()=>[`span`,{class:`md-image`},0],parseDOM:[{tag:`span.md-image`}]})}function cr(){return u({name:`mdMark`,inclusive:!1,toDOM:()=>[`span`,{class:`md-mark`},0],parseDOM:[{tag:`span.md-mark`}]})}function lr(){return u({name:`mdEm`,toDOM:()=>[`em`,0],parseDOM:[{tag:`em`}]})}function ur(){return u({name:`mdStrong`,toDOM:()=>[`strong`,0],parseDOM:[{tag:`strong`}]})}function dr(){return u({name:`mdCode`,toDOM:()=>[`code`,0],parseDOM:[{tag:`code`}]})}function fr(){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 pr(){return u({name:`mdLinkUri`,inclusive:!1,toDOM:()=>[`span`,{class:`md-link-uri`},0],parseDOM:[{tag:`span.md-link-uri`}]})}function mr(){return u({name:`mdLinkTitle`,inclusive:!1,toDOM:()=>[`span`,{class:`md-link-title`},0],parseDOM:[{tag:`span.md-link-title`}]})}function hr(){return u({name:`mdDel`,toDOM:()=>[`del`,0],parseDOM:[{tag:`del`}]})}function gr(){return u({name:`mdHighlight`,toDOM:()=>[`mark`,0],parseDOM:[{tag:`mark`}]})}function _r(){return u({name:`mdTag`,toDOM:()=>[`span`,{class:`md-tag`},0],parseDOM:[{tag:`span.md-tag`}]})}function vr(){return u({name:`mdWikilink`,inclusive:!1,attrs:{target:{default:``},display:{default:``}},toDOM:()=>[`span`,{class:`md-wikilink`},0],parseDOM:[{tag:`span.md-wikilink`}]})}function yr(){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 br(){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 xr(){return _(cr(),lr(),ur(),dr(),fr(),pr(),mr(),hr(),gr(),_r(),vr(),sr(),yr(),br())}function Sr(e,t=0){let n=t,r=0;for(let t=0;t<e.length;t++)e.charCodeAt(t)===96?(r++,r>n&&(n=r)):r=0;return n}const H={em:{node:R.Emphasis,delim:`*`},strong:{node:R.StrongEmphasis,delim:`**`},code:{node:R.InlineCode,delim:"`"},del:{node:R.Strikethrough,delim:`~~`},highlight:{node:R.Highlight,delim:`==`}},Cr=new Set([R.EmphasisMark,R.CodeMark,R.LinkMark,R.StrikethroughMark,R.HighlightMark]);function U(e){return[e.children[0],e.children.at(-1)]}function wr(e){let{type:t,children:n}=e;if(t===R.Emphasis||t===R.StrongEmphasis||t===R.Strikethrough||t===R.Highlight)return[n[0].to,n.at(-1).from];if(t===R.Link||t===R.Image){let e=n.find((e,t)=>t>0&&e.type===R.LinkMark);return e?[n[0].to,e.from]:null}return null}function W(e,t,n){for(let r of e){if(r.to<=t||r.from>=n||t<=r.from&&r.to<=n)continue;let i=wr(r);return i&&i[0]<=t&&n<=i[1]?W(r.children,t,n):W(e,Math.min(t,r.from),Math.max(n,r.to))}return[t,n]}function Tr(e,t,n){for(let r of e)if(!(r.to<=t||r.from>=n)&&(t>r.from||r.to>n))return Tr(e,Math.min(t,r.from),Math.max(n,r.to));return[t,n]}function Er(e,t,n){for(;t<n&&P(e.charCodeAt(t));)t++;for(;n>t&&P(e.charCodeAt(n-1));)n--;return[t,n]}function Dr(e,t,n,r){let i=L(I(e),e=>e.type===r.node||Cr.has(e.type));for(let r=t;r<n;r++)if(!P(e.charCodeAt(r))&&i.every(e=>!(e.from<=r&&r<e.to)))return!1;return!0}function Or(e,t,n,r,i){let a=I(e),o=L(a,e=>e.type===r.node);return i?jr(e,o,t,n):kr(e,a,o,t,n,r)}function kr(e,t,n,r,i,a){for(let e=0;e!==i-r;){e=i-r,[r,i]=W(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]=U(e);o.push({from:t.from,to:t.to,insert:``}),o.push({from:n.from,to:n.to,insert:``})}let[s,c]=Ar(e,r,i,o,a);return o.push({from:r,to:r,insert:s},{from:i,to:i,insert:c}),o}function Ar(e,t,n,r,i){if(i.node!==R.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(Sr(a)+1),s=a.startsWith("`")||a.endsWith("`")?` `:``;return[o+s,s+o]}function jr(e,t,n,r){let i=[];for(let a of t){if(a.to<=n||a.from>=r)continue;let[t,o]=U(a),s=Math.max(n,t.to),c=Math.min(r,o.from);for(s>=c&&([s,c]=[t.to,o.from]),[s,c]=Tr(a.children.slice(1,-1),s,c);s>t.to&&P(e.charCodeAt(s-1));)s--;for(;c<o.from&&P(e.charCodeAt(c));)c++;s>t.to?i.push({from:s,to:s,insert:e.slice(o.from,o.to)}):i.push({from:t.from,to:t.to,insert:``}),c<o.from?i.push({from:c,to:c,insert:e.slice(t.from,t.to)}):i.push({from:o.from,to:o.to,insert:``})}return i}function Mr(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=I(e),o=L(a,e=>e.type===n.node).findLast(e=>e.from<=t&&t<=e.to);if(o){let[e,n]=U(o);return{kind:`move`,pos:t===o.from?e.to:t===o.to?n.from:o.to}}return Nr(a,t)||e[t-1]===r[0]||e[t]===r[0]?null:{kind:`insert`,pos:t}}function Nr(e,t){for(let n of e)if(n.from<t&&t<n.to){let e=wr(n);return!e||t<e[0]||t>e[1]?!0:Nr(n.children,t)}return!1}function G(e){return(t,n)=>{if(t.selection.empty)return Pr(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]=Er(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:Dr(a,c,l,e)}),!1});let c=s.length>0&&s.every(e=>e.active),l=s.filter(e=>c||!e.active).flatMap(t=>Or(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(S.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 Pr(e,t,n){let{$from:r}=t.selection,i=r.parent;if(!i.isTextblock||i.type.spec.code)return!1;let a=Mr(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(S.create(o.doc,i+a.pos)),a.kind===`insert`&&(o.insertText(e.delim+e.delim,i+a.pos),o.setSelection(S.create(o.doc,i+a.pos+e.delim.length))),n(o.scrollIntoView())}return!0}function Fr(){return o({toggleEm:()=>G(H.em),toggleStrong:()=>G(H.strong),toggleCode:()=>G(H.code),toggleDel:()=>G(H.del),toggleHighlight:()=>G(H.highlight)})}function Ir(){return l({"Mod-b":G(H.strong),"Mod-i":G(H.em),"Mod-e":G(H.code),"Mod-Shift-x":G(H.del),"Mod-Shift-h":G(H.highlight)})}function Lr(){return _(Fr(),Ir())}function Rr(e,t,n){let r;return e.doc.nodesBetween(t.from,t.to,(e,i)=>(e.isText&&e.marks.some(e=>e.type.name===n)&&(r={from:Math.max(i,t.from),to:Math.min(i+e.nodeSize,t.to)}),!0)),r}function K(e,t){let n=O(e,t,`mdLinkText`),r=O(e,t,`mdPack`),i=r??n;if(!i)return;let a=r?.mark.attrs,o=n?.mark.attrs?.href??``;if(!r||a?.key!==`link`)return{unit:{from:i.from,to:i.to},href:o,title:``};let s=Rr(e,i,`mdLinkUri`),c=s?s.from-2:i.to-3,l=s?s.from:i.to-1;return{unit:{from:i.from,to:i.to},label:{from:i.from+1,to:c},dest:{from:l,to:i.to-1},href:a.data.href,title:a.data.title}}function zr(e){let t=e.trim();return t?Kn(t)??t:``}function Br(e,t){return e+(t?` "${t.replaceAll(/(["\\])/g,String.raw`\$1`)}"`:``)}function Vr(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]=Er(a.textContent,n.parentOffset,r.parentOffset);if(!(s>=c))return{from:o+s,to:o+c}}function Hr(e={}){return(t,n)=>{let r=Br(zr(e.href??``),e.title??``),i=Vr(t);if(!i)return!1;if(n){let{from:e,to:a}=i,o=t.tr,s=`](${r})`;o.insertText(s,a).insertText(`[`,e),n(o.setSelection(S.create(o.doc,e,a+1+s.length)).scrollIntoView())}return!0}}function Ur(e){return(t,n)=>{let r=K(t,t.selection.from);if(!r?.dest)return!1;let i=Br(zr(e.href??r.href),e.title??r.title);return n&&n(t.tr.insertText(i,r.dest.from,r.dest.to).scrollIntoView()),!0}}function Wr(){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 Gr(){return o({insertLink:Hr,updateLink:Ur,removeLink:Wr})}function Kr(e){return(t,n,r)=>{let i=K(t,t.selection.from);if(i){if(n&&r){let{unit:{from:a,to:o}}=i;n(t.tr.setSelection(S.create(t.doc,a,o)).scrollIntoView()),r.focus(),e({from:a,to:o,link:i})}return!0}let a=Vr(t);if(a){if(n&&r){let{from:i,to:o}=a;n(t.tr.setSelection(S.create(t.doc,i,o)).scrollIntoView()),r.focus(),e({from:i,to:o,link:void 0})}return!0}return!1}}function qr(e){return l({"Mod-k":Kr(e)})}function Jr(){return f({type:`list`,attr:`marker`,default:null,splittable:!0,toDOM:e=>e===`)`||e===`*`||e===`+`?[`data-list-marker`,e]:null,parseDOM:e=>{let t=e.getAttribute(`data-list-marker`);return t===`)`||t===`*`||t===`+`?t:null}})}function Yr(){return f({type:`list`,attr:`taskMarker`,default:null,splittable:!0,toDOM:e=>e===`X`?[`data-list-task-marker`,e]:null,parseDOM:e=>e.getAttribute(`data-list-task-marker`)===`X`?`X`:null})}function Xr(e){return e===2||e===3||e===4}function Zr(){return f({type:`list`,attr:`markerGap`,default:1,splittable:!0,toDOM:e=>Xr(e)?[`data-list-marker-gap`,String(e)]:null,parseDOM:e=>{let t=Number.parseInt(e.getAttribute(`data-list-marker-gap`)??``,10);return Xr(t)?t:1}})}const Qr=[D(/^\s?([*-])\s$/,{kind:`bullet`,collapsed:!1}),D(/^\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}}),D(/^\s?\[([\sXx]?)]\s$/,({match:e})=>({kind:`task`,checked:[`x`,`X`].includes(e[1]),collapsed:!1})),D(/^\s?\+\s$/,{kind:`task`,marker:`+`,checked:!1,collapsed:!1})];function $r(){return _(Qr.map(We))}function ei(){return E({kind:`task`,marker:`+`})}function ti(){return E({kind:`task`,marker:null})}function ni(){return o({wrapInCircleTask:ei,wrapInSquareTask:ti})}function ri(e){let{$from:t}=e.selection;for(let e=t.depth;e>0;e--){let n=t.node(e);if(n.type.name===`list`)return n.attrs}return null}function ii(){return(e,t,n)=>{let r=ri(e),i=r?.kind===`task`&&r.marker!==`+`,a;return a=i&&!r?.checked?{kind:`task`,marker:r?.marker??null,checked:!0}:i&&r?.checked?{kind:`bullet`,marker:null,checked:!1}:{kind:`task`,marker:null,checked:!1},E(a)(e,t,n)}}function ai(){return(e,t,n)=>{let r=ri(e),i=r?.kind===`task`&&r.marker===`+`,a;return a=i&&!r?.checked?{kind:`task`,marker:`+`,checked:!0}:i&&r?.checked?{kind:`bullet`,marker:null,checked:!1}:{kind:`task`,marker:`+`,checked:!1},E(a)(e,t,n)}}function oi(e){return e.type.name===`list`&&e.attrs.kind===`bullet`&&e.childCount>=2&&e.firstChild?.type!==e.type}const si=e=>{let t=e.attrs;return t.kind===`task`?{...t,checked:!t.checked}:oi(e)?{...t,collapsed:!t.collapsed}:t};function ci(){return m(()=>[new b({props:{handleDOMEvents:{mousedown:(e,t)=>tt({view:e,event:t,onListClick:si})}}}),Qe(),new b({props:{transformCopied:nt}}),$e()])}function li(){return o({toggleListCollapsed:()=>et({isToggleable:oi})})}function ui(){return l({"Mod-Enter":ii(),"Mod-Shift-Enter":ai(),"Mod-.":et({isToggleable:oi}),"Mod-Shift-7":Ze({kind:`ordered`,collapsed:!1}),"Mod-Shift-8":Ze({kind:`bullet`,collapsed:!1}),"Mod-Shift-9":Ze({kind:`task`,checked:!1,collapsed:!1})})}function di(){return _(Ye(),ci(),qe(),Ge(),Je(),Ke(),$r(),ui(),Jr(),Yr(),Zr(),ni(),li())}function fi(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 pi=`paragraph`;function mi(){return _(p({name:`tableCell`,content:pi}),p({name:`tableHeaderCell`,content:pi}))}const hi=(e,t)=>{let{selection:n}=e;return!dt(n)||!n.isColSelection()||!n.isRowSelection()?!1:ut(e,t)};function gi(){return v(l({Backspace:hi,Delete:hi}),t.high)}function _i(){return _(lt(),ct(),rt(),st(),mi(),ot({allowTableNodeSelection:!0}),it(),at(),gi())}function vi(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 yi(e){return(t,n)=>{if(fi(t))return!1;let r=vi(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)?xe.create(u.doc,a.from+d):S.create(u.doc,a.anchor+d,a.head+d);u.setSelection(f),n(u.scrollIntoView())}return!0}}function bi(e){return(t,n,r)=>Xe(e)(t,n,r)||yi(e===`up`?-1:1)(t,n,r)}function xi(){return l({"Alt-ArrowUp":bi(`up`),"Alt-ArrowDown":bi(`down`)})}function Si(){return p({name:`paragraph`,content:`inline*`,group:`block`,whitespace:`pre`,parseDOM:[{tag:`p`}],toDOM(){return[`p`,0]}})}function Ci(){return _(v(Si(),t.highest),ft(),pt())}const q=new x(`meowdownPendingReplacement`);function J(e){return q.getState(e)?.pending??null}function wi(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 Ti=new b({key:q,state:{init:()=>({pending:null}),apply:(e,t)=>{let n=e.getMeta(q);if(n)return wi(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:w.create(e.doc,[C.inline(t.from,t.to,{class:`md-pending-replacement`})])}}});function Ei(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 Di(e){return(t,n)=>J(t)?(n?.(t.tr.setMeta(q,{type:`append`,text:e})),!0):!1}function Oi(){return(e,t)=>J(e)?(t?.(e.tr.setMeta(q,{type:`discard`})),!0):!1}function ki(e={}){return(t,n)=>{let r=J(t);if(!r||!r.text.trim())return!1;if(n){let i=e.mode??r.mode,a=Hi(t.schema),o=Y(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(S.near(s.doc.resolve(e+o.content.size),-1))}else{let e=t.doc.resolve(r.from),n=t.doc.resolve(r.to),i=o.childCount===1?o.firstChild:null;i?.type.name===`paragraph`&&e.sameParent(n)&&e.parent.isTextblock?(s.replaceWith(r.from,r.to,i.content),s.setSelection(S.near(s.doc.resolve(r.from+i.content.size),-1))):(s.replaceRange(r.from,r.to,new T(o.content,0,0)),s.setSelection(S.near(s.doc.resolve(s.mapping.map(r.to)),-1)))}n(s.scrollIntoView())}return!0}}function Ai(){return o({startPendingReplacement:Ei,appendPendingReplacementText:Di,acceptPendingReplacement:ki,discardPendingReplacement:Oi})}function ji(){return l({"Mod-Enter":ki(),Escape:Oi()})}function Mi(){return _(m(Ti),Ai(),ji())}function Ni(e){return m(new b({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 Pi(e){return _(Ci(),ge(),en(),ye(),pe(),di(),sn(),_i(),me(),ln(),un(),xr(),Gt(),$t(),xi(),or(e),Lr(),Gr(),Un(),Bt({marks:[{name:`mdImage`,modes:[`hide`,`focus`,`show`]},{name:`mdWikilink`,modes:[`hide`,`focus`,`show`]},{name:`mdFile`,modes:[`hide`,`focus`,`show`]}]}),a(),i(),c(),_e(),be(),ve(),Zt(),Mi())}function Fi(e={}){return Pi(e)}const Ii=y(()=>{let e=Fi().schema;if(e==null)throw Error(`Unexpected empty schema`);return e}),Li=y(()=>r(Ii())),Ri=y(()=>n(Ii())),zi=`meowdown_mark_builders`;function Bi(e){let t=e.cached[zi];if(t)return t;let r=n(e);return e.cached[zi]=r,r}const Vi=`meowdown_node_builders`;function Hi(e){let t=e.cached[Vi];if(t)return t;let n=r(e);return e.cached[Vi]=n,n}function Y(e,t={}){let{nodes:n=Li(),frontmatter:r=!1}=t,i,a=e;if(r){let[t,n]=Wi(e);i=t,n&&(a=e.slice(n))}let o=Gi(n,Mn.parse(a).cursor(),a);return n.doc(i===void 0?{}:{frontmatter:i},o)}const Ui=/^---[ \t]*\r?\n([\s\S]*?\n)?---[ \t]*(?:\r?\n|$)/;function Wi(e){let t=Ui.exec(e);return t?[(t[1]??``).replace(/\r?\n$/,``),t[0].length]:[]}function Gi(e,t,n){let r=[];if(!t.firstChild())return r;do r.push(...Ki(e,t,n));while(t.nextSibling());return t.parent(),r}function Ki(e,t,n){switch(t.type.id){case R.ATXHeading1:return[X(e,t,n,1,!1)];case R.ATXHeading2:return[X(e,t,n,2,!1)];case R.ATXHeading3:return[X(e,t,n,3,!1)];case R.ATXHeading4:return[X(e,t,n,4,!1)];case R.ATXHeading5:return[X(e,t,n,5,!1)];case R.ATXHeading6:return[X(e,t,n,6,!1)];case R.SetextHeading1:return[X(e,t,n,1,!0)];case R.SetextHeading2:return[X(e,t,n,2,!0)];case R.Paragraph:return[Q(e,t,n)];case R.CommentBlock:return[Qi(e,t,n)];case R.HTMLBlock:case R.ProcessingInstructionBlock:return[Q(e,t,n)];case R.Blockquote:return[$i(e,t,n)];case R.BulletList:return ea(e,t,n,`bullet`);case R.OrderedList:return ea(e,t,n,`ordered`);case R.FencedCode:case R.CodeBlock:return[na(e,t,n)];case R.HorizontalRule:{let r=n.slice(t.from,t.to).trimEnd();return[e.horizontalRule({marker:r===`---`?null:r})]}case R.Table:return[ra(e,t,n)];case R.Task:return[Q(e,t,n)];default:return n.slice(t.from,t.to).trim()===``?[]:(console.warn(`[meowdown] unsupported lezer block "${t.type.name}"`),[Q(e,t,n)])}}function X(e,t,n,r,i){let a=t.from,o=t.from,s=t.to,c=-1,l=-1;if(t.firstChild()){t.type.id===R.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===R.HeaderMark&&n>o&&(s=n,c=n,l=r),t.parent()}let u=Xi(n.slice(o,s),Z(n,o)).trim(),d=i?qi(n,c,l)||1:null,f=!i&&c>=0&&Ji(n,c,l)||null;return e.heading({level:r,setextUnderline:d,closingHashes:f},u)}function qi(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 Ji(e,t,n){if(t<0)return 0;let r=0;for(let i=t;i<n;i++)e.charCodeAt(i)===35&&r++;return r}function Z(e,t){let n=e.lastIndexOf(`
3
+ `,t-1)+1,r=0;for(let i=n;i<t;i++)r+=e.charCodeAt(i)===9?4-r%4:1;return r}function Yi(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 Xi(e,t){return t===0||!e.includes(`
4
4
  `)?e:e.split(`
5
- `).map((e,n)=>n===0?e:Ci(e,t)).join(`
6
- `)}function wi(e,t,n){return e.paragraph(Q(t,n))}function $(e,t,n){let r=t.from,i=t.to,a=Z(n,r);if(t.firstChild()){let o=``,s=r;do t.type.id===B.QuoteMark&&(o+=n.slice(s,t.from),s=t.to,I(n.charCodeAt(s))&&(s+=1));while(t.nextSibling());return t.parent(),o+=n.slice(s,i),wi(e,o,a)}return wi(e,n.slice(r,i),a)}function Ti(e,t,n){let r=Z(n,t.from),i=Q(n.slice(t.from,t.to),r);return e.htmlComment({content:i})}function Ei(e,t,n){let r=[];if(t.firstChild()){do{if(t.type.id===B.QuoteMark)continue;r.push(...Y(e,t,n))}while(t.nextSibling());t.parent()}return e.blockquote(r)}function Di(e,t,n,r){let i=[];if(t.firstChild()){do t.type.id===B.ListItem&&i.push(Oi(e,t,n,r));while(t.nextSibling());t.parent()}return i}function Oi(e,t,n,r){let i=[],a,o,s,c,l,u;if(t.firstChild()){do{if(t.type.id!==B.ListMark&&u==null&&(u=Z(n,t.from)),t.type.id===B.ListMark){if(r===`ordered`){let e=n.charCodeAt(t.to-1);e===41?c=`)`:e===46&&(c=`.`);let r=Number.parseInt(n.slice(t.from,t.to),10);s=Number.isFinite(r)?r:1}else{let e=n.charCodeAt(t.from);c=e===42?`*`:e===43?`+`:`-`}l=Z(n,t.to);continue}if(r===`bullet`&&t.type.id===B.Task){let r=t.from,s=t.to;if(a=!1,t.firstChild()){if(t.type.id===B.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()}I(n.charCodeAt(r))&&(r+=1);let c=n.slice(r,s);i.push(wi(e,c,Z(n,r)));continue}i.push(...Y(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 ki(e,t,n){let r=``,i=``;if(t.firstChild()){do switch(t.type.id){case B.CodeInfo:r=n.slice(t.from,t.to);break;case B.CodeText:i+=n.slice(t.from,t.to);break}while(t.nextSibling());t.parent()}return e.codeBlock({language:r},i)}function Ai(e,t,n){let r=0;if(t.firstChild()){do t.type.id===B.TableDelimiter&&(r=ji(n.slice(t.from,t.to)));while(t.nextSibling());t.parent()}let i=[];if(t.firstChild()){do{let a=t.type.id;a===B.TableHeader?i.push(Mi(e,t,n,!0,r)):a===B.TableRow&&i.push(Mi(e,t,n,!1,r))}while(t.nextSibling());t.parent()}return e.table(i)}function ji(e){return e.split(`|`).filter(e=>e.trim()!==``).length}function Mi(e,t,n,r,i){let a=Array(i).fill(``);if(t.firstChild()){let e=t.type.id===B.TableDelimiter,r=0;do if(t.type.id===B.TableDelimiter)r++;else if(t.type.id===B.TableCell){let o=r-+!!e;o>=0&&o<i&&(a[o]=n.slice(t.from,t.to).trim().replaceAll(String.raw`\|`,`|`))}while(t.nextSibling());t.parent()}let o=a.map(t=>{let n=e.paragraph(t);return r?e.tableHeaderCell(n):e.tableCell(n)});return e.tableRow(o)}function Ni(e,t={}){let n=new Li;return t.frontmatter&&Pi(e.attrs.frontmatter,n),Ri(e,n),n.finish()}function Pi(e,t){e!==null&&(t.write(`---`),t.write(`
5
+ `).map((e,n)=>n===0?e:Yi(e,t)).join(`
6
+ `)}function Zi(e,t,n){return e.paragraph(Xi(t,n))}function Q(e,t,n){let r=t.from,i=t.to,a=Z(n,r);if(t.firstChild()){let o=``,s=r;do t.type.id===R.QuoteMark&&(o+=n.slice(s,t.from),s=t.to,P(n.charCodeAt(s))&&(s+=1));while(t.nextSibling());return t.parent(),o+=n.slice(s,i),Zi(e,o,a)}return Zi(e,n.slice(r,i),a)}function Qi(e,t,n){let r=Z(n,t.from),i=Xi(n.slice(t.from,t.to),r);return e.htmlComment({content:i})}function $i(e,t,n){let r=[];if(t.firstChild()){do{if(t.type.id===R.QuoteMark)continue;r.push(...Ki(e,t,n))}while(t.nextSibling());t.parent()}return e.blockquote(r)}function ea(e,t,n,r){let i=[];if(t.firstChild()){do t.type.id===R.ListItem&&i.push(ta(e,t,n,r));while(t.nextSibling());t.parent()}return i}function ta(e,t,n,r){let i=[],a,o,s,c,l,u;if(t.firstChild()){do{if(t.type.id!==R.ListMark&&u==null&&(u=Z(n,t.from)),t.type.id===R.ListMark){if(r===`ordered`){let e=n.charCodeAt(t.to-1);e===41?c=`)`:e===46&&(c=`.`);let r=Number.parseInt(n.slice(t.from,t.to),10);s=Number.isFinite(r)?r:1}else{let e=n.charCodeAt(t.from);c=e===42?`*`:e===43?`+`:`-`}l=Z(n,t.to);continue}if(r===`bullet`&&t.type.id===R.Task){let r=t.from,s=t.to;if(a=!1,t.firstChild()){if(t.type.id===R.TaskMarker){let e=n.charCodeAt(t.from+1);e===120?(a=!0,o=`x`):e===88&&(a=!0,o=`X`),r=t.to}t.parent()}P(n.charCodeAt(r))&&(r+=1);let c=n.slice(r,s);i.push(Zi(e,c,Z(n,r)));continue}i.push(...Ki(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 na(e,t,n){let r=``,i=``;if(t.firstChild()){do switch(t.type.id){case R.CodeInfo:r=n.slice(t.from,t.to);break;case R.CodeText:i+=n.slice(t.from,t.to);break}while(t.nextSibling());t.parent()}return e.codeBlock({language:r},i)}function ra(e,t,n){let r=0;if(t.firstChild()){do t.type.id===R.TableDelimiter&&(r=ia(n.slice(t.from,t.to)));while(t.nextSibling());t.parent()}let i=[];if(t.firstChild()){do{let a=t.type.id;a===R.TableHeader?i.push(aa(e,t,n,!0,r)):a===R.TableRow&&i.push(aa(e,t,n,!1,r))}while(t.nextSibling());t.parent()}return e.table(i)}function ia(e){return e.split(`|`).filter(e=>e.trim()!==``).length}function aa(e,t,n,r,i){let a=Array(i).fill(``);if(t.firstChild()){let e=t.type.id===R.TableDelimiter,r=0;do if(t.type.id===R.TableDelimiter)r++;else if(t.type.id===R.TableCell){let o=r-+!!e;o>=0&&o<i&&(a[o]=n.slice(t.from,t.to).trim().replaceAll(String.raw`\|`,`|`))}while(t.nextSibling());t.parent()}let o=a.map(t=>{let n=e.paragraph(t);return r?e.tableHeaderCell(n):e.tableCell(n)});return e.tableRow(o)}function $(e,t={}){let n=new la;return t.frontmatter&&oa(e.attrs.frontmatter,n),ua(e,n),n.finish()}function oa(e,t){e!==null&&(t.write(`---`),t.write(`
7
7
  `),e!==``&&(t.write(e),t.write(`
8
- `)),t.write(`---`),t.closeBlock())}const Fi=[``,`# `,`## `,`### `,`#### `,`##### `,`###### `];function Ii(e,t){let n=e.attrs,r=n.setextUnderline;if(r!=null&&e.content.size>0&&n.level<=2){Hi(e,t);let i=n.level===1?`=`:`-`;t.write(`
9
- `+i.repeat(Math.max(1,r))),t.closeBlock();return}t.write(Fi[n.level]??`# `),Hi(e,t);let i=n.closingHashes;i!=null&&i>0&&t.write(` `+`#`.repeat(i)),t.closeBlock()}var Li=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(`
8
+ `)),t.write(`---`),t.closeBlock())}const sa=[``,`# `,`## `,`### `,`#### `,`##### `,`###### `];function ca(e,t){let n=e.attrs,r=n.setextUnderline;if(r!=null&&e.content.size>0&&n.level<=2){ma(e,t);let i=n.level===1?`=`:`-`;t.write(`
9
+ `+i.repeat(Math.max(1,r))),t.closeBlock();return}t.write(sa[n.level]??`# `),ma(e,t);let i=n.closingHashes;i!=null&&i>0&&t.write(` `+`#`.repeat(i)),t.closeBlock()}var la=class{constructor(){this.parts=[],this.linePrefix=``,this.pendingFirst=null,this.atLineStart=!0,this.deferredBlankPrefix=null}write(e){if(e===``)return;if(this.emitDeferredBlankLine(),this.atLineStart&&=(this.parts.push(this.pendingFirst??this.linePrefix),this.pendingFirst=null,!1),!e.includes(`
10
10
  `)){this.parts.push(e);return}let t=e.split(`
11
11
  `);for(let e=0;e<t.length;e++)e>0&&this.parts.push(`
12
12
  `,this.linePrefix),t[e]!==``&&this.parts.push(t[e])}closeBlock(){this.atLineStart&&this.pendingFirst!==null&&(this.emitDeferredBlankLine(),this.parts.push(this.pendingFirst.trimEnd()),this.pendingFirst=null,this.atLineStart=!1),this.atLineStart||this.parts.push(`
13
13
  `),this.atLineStart=!0,this.deferredBlankPrefix=this.linePrefix}suppressBlank(){this.deferredBlankPrefix=null}withPrefix(e,t,n){let r=this.linePrefix,i=this.pendingFirst;if(this.linePrefix=r+e,t!==null){let e=i??r;this.pendingFirst=e+t}n(),this.linePrefix=r,this.pendingFirst=t===null?i:null}finish(){return this.parts.join(``).replace(/\s+$/,``)+`
14
14
  `}emitDeferredBlankLine(){let e=this.deferredBlankPrefix;e!==null&&(this.parts.push(e.trimEnd(),`
15
- `),this.deferredBlankPrefix=null)}};function Ri(e,t){switch(e.type.name){case`doc`:zi(e,t);return;case`paragraph`:Hi(e,t),t.closeBlock();return;case`heading`:Ii(e,t);return;case`blockquote`:t.withPrefix(`> `,`> `,()=>zi(e,t)),t.closeBlock();return;case`list`:Ui(e,t,Vi(e));return;case`codeBlock`:Wi(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`:Gi(e,t);return;case`text`:e.text&&t.write(e.text);return}}function zi(e,t,n=!1){let r=e.childCount,i=0;for(;i<r;){let a=e.child(i);if(a.type.name!==`list`){n&&i>0&&t.suppressBlank(),Ri(a,t),i++;continue}let o=i+1;for(;o<r&&e.child(o).type.name===`list`;)o++;let s=Bi(e,i,o);for(let r=i;r<o;r++)(r===i?n&&i>0:s)&&t.suppressBlank(),Ui(e.child(r),t,s);i=o}}function Bi(e,t,n){for(let r=t;r<n;r++)if(!Vi(e.child(r)))return!1;return!0}function Vi(e){let t=e.childCount;for(let n=0;n<t;n++){let t=e.child(n);if(t.type.name!==`list`&&!(t.type.name===`paragraph`&&n===0))return!1}return!0}function Hi(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 Ui(e,t,n){let{kind:r,marker:i,order:a,taskMarker:o,collapsed:s,markerGap:c,checked:l}=e.attrs,u=r===`task`?i===`+`?`+`:i===`*`?`*`:`-`:s?`+`:i===`*`?`*`:`-`,d=i===`)`?`)`:`.`,f=o===`X`?`X`:`x`,p=Math.min(Math.max(c??1,1),4),m=`${r===`ordered`?`${a??1}${d}`:u}${` `.repeat(p)}`,h=r===`task`?`${m}[${l?f:` `}] `:m,ee=` `.repeat(m.length);t.withPrefix(ee,h,()=>zi(e,t,n)),t.closeBlock()}function Wi(e,t){let n=e.attrs.language||``,r=e.textContent,i="`".repeat(dr(r,2)+1);t.write(i),n&&t.write(n),t.write(`
15
+ `),this.deferredBlankPrefix=null)}};function ua(e,t){switch(e.type.name){case`doc`:da(e,t);return;case`paragraph`:ma(e,t),t.closeBlock();return;case`heading`:ca(e,t);return;case`blockquote`:t.withPrefix(`> `,`> `,()=>da(e,t)),t.closeBlock();return;case`list`:ha(e,t,pa(e));return;case`codeBlock`:ga(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`:_a(e,t);return;case`text`:e.text&&t.write(e.text);return}}function da(e,t,n=!1){let r=e.childCount,i=0;for(;i<r;){let a=e.child(i);if(a.type.name!==`list`){n&&i>0&&t.suppressBlank(),ua(a,t),i++;continue}let o=i+1;for(;o<r&&e.child(o).type.name===`list`;)o++;let s=fa(e,i,o);for(let r=i;r<o;r++)(r===i?n&&i>0:s)&&t.suppressBlank(),ha(e.child(r),t,s);i=o}}function fa(e,t,n){for(let r=t;r<n;r++)if(!pa(e.child(r)))return!1;return!0}function pa(e){let t=e.childCount;for(let n=0;n<t;n++){let t=e.child(n);if(t.type.name!==`list`&&!(t.type.name===`paragraph`&&n===0))return!1}return!0}function ma(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 ha(e,t,n){let{kind:r,marker:i,order:a,taskMarker:o,collapsed:s,markerGap:c,checked:l}=e.attrs,u=r===`task`?i===`+`?`+`:i===`*`?`*`:`-`:s?`+`:i===`*`?`*`:`-`,d=i===`)`?`)`:`.`,f=o===`X`?`X`:`x`,p=Math.min(Math.max(c??1,1),4),m=`${r===`ordered`?`${a??1}${d}`:u}${` `.repeat(p)}`,h=r===`task`?`${m}[${l?f:` `}] `:m,ee=` `.repeat(m.length);t.withPrefix(ee,h,()=>da(e,t,n)),t.closeBlock()}function ga(e,t){let n=e.attrs.language||``,r=e.textContent,i="`".repeat(Sr(r,2)+1);t.write(i),n&&t.write(n),t.write(`
16
16
  `),r&&(t.write(r),t.write(`
17
- `)),t.write(i),t.closeBlock()}function Gi(e,t){let n=e.childCount;if(n===0)return;let r=[],i=0,a=-1;for(let t=0;t<n;t++){let n=e.child(t),o=[],s=!1;for(let e=0;e<n.childCount;e++){let t=n.child(e);t.type.name===`tableHeaderCell`&&(s=!0),o.push(qi(t))}s&&a<0&&(a=t),o.length>i&&(i=o.length),r.push(o)}if(i===0)return;let o=`| `+Array(i).fill(`---`).join(` | `)+` |`,s=a>=0?r[a]:Array(i).fill(``);t.write(Ki(s,i)),t.write(`
17
+ `)),t.write(i),t.closeBlock()}function _a(e,t){let n=e.childCount;if(n===0)return;let r=[],i=0,a=-1;for(let t=0;t<n;t++){let n=e.child(t),o=[],s=!1;for(let e=0;e<n.childCount;e++){let t=n.child(e);t.type.name===`tableHeaderCell`&&(s=!0),o.push(ya(t))}s&&a<0&&(a=t),o.length>i&&(i=o.length),r.push(o)}if(i===0)return;let o=`| `+Array(i).fill(`---`).join(` | `)+` |`,s=a>=0?r[a]:Array(i).fill(``);t.write(va(s,i)),t.write(`
18
18
  `),t.write(o);for(let e=0;e<n;e++)e!==a&&(t.write(`
19
- `),t.write(Ki(r[e],i)));t.closeBlock()}function Ki(e,t){let n=`|`;for(let r=0;r<t;r++)n+=` `+(e[r]??``)+` |`;return n}function qi(e){let t=e.textContent.trim();return!t.includes(`|`)&&!t.includes(`
19
+ `),t.write(va(r[e],i)));t.closeBlock()}function va(e,t){let n=`|`;for(let r=0;r<t;r++)n+=` `+(e[r]??``)+` |`;return n}function ya(e){let t=e.textContent.trim();return!t.includes(`|`)&&!t.includes(`
20
20
  `)?t:t.replaceAll(`|`,String.raw`\|`).replaceAll(`
21
- `,` `)}function Ji(e){return e.replace(/\n+$/u,``)}function Yi(e){return/^[\s>]*$/u.test(e)}function Xi(e){return e.split(`
22
- `).filter(e=>!Yi(e))}function Zi(e){return e.trim().replaceAll(/\s+/gu,` `)}function Qi(e,t={}){let n=Ni(J(e,{frontmatter:t.frontmatter}),{frontmatter:t.frontmatter});if(Ji(n)===Ji(e))return`exact`;let r=Xi(e),i=Xi(n);return r.length===i.length&&r.every((e,t)=>Zi(e)===Zi(i[t]))?`normalizing`:`lossy`}const $i=(e,t)=>{let{$from:n,empty:r}=e.selection;if(!r||n.depth!==1||n.index(0)!==0||n.parent.type.name!==`heading`||n.parentOffset!==n.parent.content.size)return!1;if(t){let r=te(e.schema,`list`),i=te(e.schema,`paragraph`),a=r.create({kind:`bullet`},i.create()),o=n.after(),s=e.tr.insert(o,a);s.setSelection(S.create(s.doc,o+2)),t(s.scrollIntoView())}return!0};function ea(){return v(l({Enter:$i}),t.high)}const ta=new Set([`MscGen`,`Xù`,`MsGenny`,`Angular Template`,`Brainfuck`,`Esper`,`Oz`,`Factor`,`Squirrel`,`Yacas`,`mIRC`,`FCL`,`ECL`,`MUMPS`,`Pig`,`Asterisk`,`Z80`]),na=xe.map(e=>e.name).filter(e=>!ta.has(e)).map(e=>({label:e,value:e.toLowerCase()})).concat({label:`Plain text`,value:``}).sort((e,t)=>e.label.localeCompare(t.label));function ra(){return typeof window>`u`?!1:window.matchMedia(`(prefers-color-scheme: dark)`).matches}const ia=/^(?:www\.|mobile\.)?(?:twitter\.com|x\.com)$/i,aa=/\/status(?:es)?\/(\d+)/;function oa(e){let t;try{t=new URL(e)}catch{return}if(ia.test(t.hostname))return aa.exec(t.pathname)?.[1]}const sa=e=>{let t=oa(e);if(!t)return;let n=ra()?`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 ca(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 la=/^(?:www\.|m\.)?(?:youtube\.com|youtube-nocookie\.com)$/i,ua=/^(?:www\.)?youtu\.be$/i,da=/^[\w-]{11}$/;function fa(e){let t;try{t=new URL(e)}catch{return}let n=null;if(ua.test(t.hostname))n=t.pathname.slice(1);else if(la.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||!da.test(n))return;let r=t.searchParams.get(`start`)??t.searchParams.get(`t`),i=r?pa(r):void 0;return{videoId:n,startSeconds:i}}function pa(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 ma=[e=>{let t=fa(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}},sa];function ha(e){for(let t of ma){let n=t(e);if(n)return n}}const ga=new x(`meowdown-embed-paste`);function _a(e){let t=e.trim();if(!(!t||/\s/.test(t)))return ha(t)?t:void 0}function va(e,t){return e.clipboardData?.getData(`text/plain`)||t.content.textBetween(0,t.content.size,`
23
- `)}function ya(e,t){let{from:n,to:r}=e.state.selection;e.dispatch(lt(e.state.tr.insertText(t,n,r)));let i=e.state.tr.insertText(`![](${t})`,n,n+t.length);e.dispatch(lt(i))}function ba(){return m(new b({key:ga,props:{handlePaste:(e,t,n)=>{let r=e.state.selection.$from.parent;if(!r.inlineContent||r.type.spec.code)return!1;let i=va(t,n);if(!i)return!1;let a=_a(i);return a?(ya(e,a),!0):!1}}}))}const xa=new x(`meowdown-exit-boundary`);function Sa(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&&ye.findFrom(a,t))}function Ca(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:Sa(n,t)}function wa(e){return new b({key:xa,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||Ca(t,r)||e({direction:r<0?`up`:`down`,event:n})===!1)}}})}function Ta(e){return v(m(wa(e)),t.low)}const Ea=(e,t)=>{let n={type:`highlight`,children:e.all(t)};return e.patch(t,n),n},Da=(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 Oa(){return mt().use(ut).use(dt,{handlers:{mark:Ea}}).use(ft).use(pt,{bullet:`-`,emphasis:`*`,strong:`*`,fence:"`",fences:!0,rule:`-`,ruleRepetition:3,listItemIndent:`one`,handlers:{highlight:Da}}).freeze()}const ka=y(Oa);function Aa(e){return String(ka().processSync(e))}const ja=new x(`meowdown-html-paste`);function Ma(){return m(new b({key:ja,props:{transformPastedHTML:(e,t)=>{if(e.includes(`data-pm-slice`))return e;let n=t.state.selection.$from.parent;if(!n.inlineContent||n.type.spec.code)return e;let r=Aa(e);if(!r.trim())return e;let i=J(r,{nodes:_i(t.state.schema)}),a=Le.fromSchema(t.state.schema),o=document.createElement(`div`);return o.append(a.serializeFragment(i.content)),o.innerHTML}}}))}const Na=new x(`meowdown-image-click`);function Pa(e,t){let n=D(e,t,`mdImage`);if(!n)return;let{src:r,alt:i}=n.mark.attrs;return{from:n.from,to:n.to,src:r,alt:i}}function Fa(e){return m(new b({key:Na,props:{handleClick:(t,n,r)=>{let i=r.target?.closest?.(`.md-image-view-preview`);if(!i)return!1;let a=i.closest(`.md-image-view`)?.querySelector(`.md-image-view-content`);if(!a)return!1;let o=Pa(t.state,t.posAtDOM(a,0));return o?(e({src:o.src,alt:o.alt,event:r}),!0):!1}}}))}function Ia(e){return/^https?:\/\//i.test(e)?e:void 0}function La(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`&&ca(t),t}function Ra(e,t,n,r,i,a,o){let s=ha(e);if(s){let e=document.createElement(`span`);return e.className=`md-image-view-preview md-atom-view-preview`,e.appendChild(La(s)),e}let c=(i.resolveImageUrl??Ia)(e);if(!c)return;let l=document.createElement(`span`);return l.className=`md-image-view-preview md-atom-view-preview`,l.dataset.testid=`image-preview`,l.appendChild(za(c,t,n,r,a,o)),l}function za(e,t,n,r,i,a){gt(),ht();let o=document.createElement(`prosekit-resizable-root`);o.className=`md-image-resizable`,o.dataset.testid=`image-resizable`,o.setAttribute(`data-loading`,``),n!=null&&o.setAttribute(`data-width`,String(n)),r!=null&&o.setAttribute(`data-height`,String(r));let s=document.createElement(`img`);s.src=e,s.alt=t,s.draggable=!1,s.addEventListener(`load`,()=>{o.removeAttribute(`data-loading`);let{naturalWidth:e,naturalHeight:t}=s,i=e/t;if(!Number.isFinite(i)||i<=0||(o.setAttribute(`data-aspect-ratio`,String(i)),n!=null&&r!=null))return;let a=n==null?Math.min(t,500):n/i,c=n??a*i;o.setAttribute(`data-width`,String(Math.round(c))),o.setAttribute(`data-height`,String(Math.round(a)))}),s.addEventListener(`error`,()=>{o.removeAttribute(`data-loading`)}),o.appendChild(s);let c=document.createElement(`prosekit-resizable-handle`);return c.className=`md-image-resize-handle`,c.setAttribute(`position`,`bottom-right`),c.addEventListener(`click`,e=>e.stopPropagation()),o.appendChild(c),o.addEventListener(`resizeEnd`,e=>{let{width:t,height:n}=e.detail;Ba(i,a,t,n)}),o}function Ba(e,t,n,r){let i=e.posAtDOM(t,0),a=D(e.state,i,`mdImage`);if(!a)return;let o=e.state.doc.textBetween(a.from,a.to),s=On(o),c=a.from+s.length,l=o.slice(s.length),u=Dn({...Tn(l)??{},width:Math.round(n),height:Math.round(r)});u!==l&&e.dispatch(e.state.tr.insertText(u,c,a.to))}function Va(e){return(t,n)=>{let{src:r,alt:i,width:a,height:o}=t.attrs,s=document.createElement(`span`);s.className=`md-image-view md-atom-view`;let c=document.createElement(`span`);c.className=`md-image-view-content md-atom-view-content`;let l=Ra(r,i,a,o,e,n,c);return l&&(l.contentEditable=`false`,s.appendChild(l)),s.appendChild(c),{dom:s,contentDOM:c,ignoreMutation:e=>!c.contains(e.target)}}}function Ha(e){return e?Array.from(e.files).filter(e=>e.type.startsWith(`image/`)):[]}const Ua=e=>{console.error(`[meowdown] failed to save pasted image:`,e)};async function Wa(e,t,n,r=Ua,i){let a=i;for(let i of t){let t;try{t=await n(i)}catch(e){r(e,i);continue}if(!t||e.isDestroyed)continue;let o=`![](${t})`,s=a==null?e.state.tr.insertText(o):e.state.tr.insertText(o,a);e.dispatch(s),a!=null&&(a+=o.length)}}function Ga(e){return new b({key:new x(`image-input`),props:{handlePaste:(t,n)=>{let r=Ha(n.clipboardData),{onImagePaste:i,onImageSaveError:a}=e;return r.length===0||!i?!1:(Wa(t,r,i,a),!0)},handleDrop:(t,n)=>{let r=Ha(n.dataTransfer),{onImagePaste:i,onImageSaveError:a}=e;return r.length===0||!i?!1:(Wa(t,r,i,a,t.posAtCoords({left:n.clientX,top:n.clientY})?.pos),!0)}}})}function Ka(e={}){return _(d({name:`mdImage`,constructor:Va(e)}),v(m(Ga(e)),t.high))}const qa={"Mod-b":`Bold`,"Mod-i":`Italic`,"Mod-e":`Inline code`,"Mod-Shift-x":`Strikethrough`,"Mod-Shift-h":`Highlight`,"Mod-k":`Link`,"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`};function Ja(e){return m(new b({key:e.key,props:{handleClick:(t,n,r)=>{if(!r.target?.closest?.(e.selector))return!1;let i=e.findPayloadAt(t.state,n);return i==null?!1:(e.preventDefault&&r.preventDefault(),e.onClick(i,r),!0)}}}))}const Ya=new x(`meowdown-link-click`);function Xa(e){return Ja({key:Ya,selector:`.md-link`,preventDefault:!0,findPayloadAt:(e,t)=>K(e,t)?.href,onClick:(t,n)=>e({href:t,event:n})})}function Za(e){let t,n=(n,r)=>{let i=r.target;if(!i||!ue(i))return;let a=i.closest(e.selector);if(!a||a===t)return;let o=n.posAtDOM(a,0),s=e.findPayloadAt(n.state,o);s!=null&&(t=a,e.onHoverChange({payload:s,element:a}))},r=n=>{if(!t)return;let r=n.relatedTarget;r&&t.contains(r)||(t=void 0,e.onHoverChange(void 0))};return _(s(`mouseover`,(e,t)=>n(e,t)),s(`mouseout`,(e,t)=>r(t)))}function Qa(e){return Za({selector:`.md-link`,findPayloadAt:(e,t)=>K(e,t),onHoverChange:e})}const $a=new x(`meowdown-markdown-copy`);function eo(){return m(new b({key:$a,props:{clipboardTextSerializer:(e,t)=>{let n=e.content,r;try{r=t.state.schema.topNodeType.createAndFill(void 0,n)??void 0}catch{r=void 0}return r?Ni(r).replace(/\n+$/,``):n.textBetween(0,n.size,`
21
+ `,` `)}function ba(e){return e.replace(/\n+$/u,``)}function xa(e){return/^[\s>]*$/u.test(e)}function Sa(e){return e.split(`
22
+ `).filter(e=>!xa(e))}function Ca(e){return e.trim().replaceAll(/\s+/gu,` `)}function wa(e,t={}){let n=$(Y(e,{frontmatter:t.frontmatter}),{frontmatter:t.frontmatter});if(ba(n)===ba(e))return`exact`;let r=Sa(e),i=Sa(n);return r.length===i.length&&r.every((e,t)=>Ca(e)===Ca(i[t]))?`normalizing`:`lossy`}const Ta=(e,t)=>{let{$from:n,empty:r}=e.selection;if(!r||n.depth!==1||n.index(0)!==0||n.parent.type.name!==`heading`||n.parentOffset!==n.parent.content.size)return!1;if(t){let r=te(e.schema,`list`),i=te(e.schema,`paragraph`),a=r.create({kind:`bullet`},i.create()),o=n.after(),s=e.tr.insert(o,a);s.setSelection(S.create(s.doc,o+2)),t(s.scrollIntoView())}return!0};function Ea(){return v(l({Enter:Ta}),t.high)}const Da=new Set([`MscGen`,`Xù`,`MsGenny`,`Angular Template`,`Brainfuck`,`Esper`,`Oz`,`Factor`,`Squirrel`,`Yacas`,`mIRC`,`FCL`,`ECL`,`MUMPS`,`Pig`,`Asterisk`,`Z80`]),Oa=we.map(e=>e.name).filter(e=>!Da.has(e)).map(e=>({label:e,value:e.toLowerCase()})).concat({label:`Plain text`,value:``}).sort((e,t)=>e.label.localeCompare(t.label));function ka(){return typeof window>`u`?!1:window.matchMedia(`(prefers-color-scheme: dark)`).matches}const Aa=/^(?:www\.|mobile\.)?(?:twitter\.com|x\.com)$/i,ja=/\/status(?:es)?\/(\d+)/;function Ma(e){let t;try{t=new URL(e)}catch{return}if(Aa.test(t.hostname))return ja.exec(t.pathname)?.[1]}const Na=e=>{let t=Ma(e);if(!t)return;let n=ka()?`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 Pa(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 Fa=/^(?:www\.|m\.)?(?:youtube\.com|youtube-nocookie\.com)$/i,Ia=/^(?:www\.)?youtu\.be$/i,La=/^[\w-]{11}$/;function Ra(e){let t;try{t=new URL(e)}catch{return}let n=null;if(Ia.test(t.hostname))n=t.pathname.slice(1);else if(Fa.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||!La.test(n))return;let r=t.searchParams.get(`start`)??t.searchParams.get(`t`),i=r?za(r):void 0;return{videoId:n,startSeconds:i}}function za(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 Ba=[e=>{let t=Ra(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}},Na];function Va(e){for(let t of Ba){let n=t(e);if(n)return n}}const Ha=new x(`meowdown-embed-paste`);function Ua(e){let t=e.trim();if(!(!t||/\s/.test(t)))return Va(t)?t:void 0}function Wa(e,t){return e.clipboardData?.getData(`text/plain`)||t.content.textBetween(0,t.content.size,`
23
+ `)}function Ga(e,t){let{from:n,to:r}=e.state.selection;e.dispatch(mt(e.state.tr.insertText(t,n,r)));let i=e.state.tr.insertText(`![](${t})`,n,n+t.length);e.dispatch(mt(i))}function Ka(){return m(new b({key:Ha,props:{handlePaste:(e,t,n)=>{let r=e.state.selection.$from.parent;if(!r.inlineContent||r.type.spec.code)return!1;let i=Wa(t,n);if(!i)return!1;let a=Ua(i);return a?(Ga(e,a),!0):!1}}}))}const qa=new x(`meowdown-exit-boundary`);function Ja(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&&Se.findFrom(a,t))}function Ya(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:Ja(n,t)}function Xa(e){return new b({key:qa,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||Ya(t,r)||e({direction:r<0?`up`:`down`,event:n})===!1)}}})}function Za(e){return v(m(Xa(e)),t.low)}function Qa(e){return!!e.type?.startsWith(`image/`)}function $a(e,t){return Qa(e)?`![](${t})`:`[${no(e.name)}](${t})`}function eo(e,t){return!e||!t.onFilePaste?[]:Array.from(e.files)}const to=e=>{console.error(`[meowdown] failed to save pasted file:`,e)};function no(e){return e.replaceAll(/[\\[\]]/g,String.raw`\$&`)}async function ro(e,t,n,r){let{onFilePaste:i}=n;if(!i)return;let a=n.onFileSaveError??to,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=$a(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 io(e){return new b({key:new x(`file-paste`),props:{handlePaste:(t,n)=>{let r=eo(n.clipboardData,e);return r.length===0?!1:(ro(t,r,e),!0)},handleDrop:(t,n)=>{let r=eo(n.dataTransfer,e);return r.length===0?!1:(ro(t,r,e,t.posAtCoords({left:n.clientX,top:n.clientY})?.pos),!0)}}})}function ao(e={}){return v(m(io(e)),t.high)}const oo=new x(`meowdown-file-click`);function so(e,t){let n=O(e,t,`mdFile`);if(!n)return;let{href:r,name:i}=n.mark.attrs;return{href:r,name:i}}function co(e){return m(new b({key:oo,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=so(t.state,t.posAtDOM(a,0));return o?(e({href:o.href,name:o.name,event:r}),!0):!1}}}))}const lo=[`KB`,`MB`,`GB`,`TB`];function uo(e){let t=e,n=`B`;for(let e of lo){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 fo=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 po(e){let t=e.split(/[?#]/,1)[0],n=t.lastIndexOf(`.`);if(n<0)return`generic`;let r=t.slice(n+1).toLowerCase();return fo.get(r)??`generic`}const mo=`http://www.w3.org/2000/svg`;function ho(){let e=document.createElementNS(mo,`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(mo,`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 go=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=po(this.#a.href),this.#n.title=this.#a.name,this.#e.appendChild(this.#n),this.#n.appendChild(ho()),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=uo(n))}};function _o(e={}){return d({name:`mdFile`,constructor:t=>new go(t,e)})}function vo(e){return m(new b({key:e.key,props:{handleClick:(t,n,r)=>{if(!r.target?.closest?.(e.selector))return!1;let i=e.findPayloadAt(t.state,n);return i==null?!1:(e.preventDefault&&r.preventDefault(),e.onClick(i,r),!0)}}}))}const yo=new x(`meowdown-tag-click`);function bo(e,t){let n=O(e,t,`mdTag`);if(!n)return;let r=e.doc.textBetween(n.from,n.to),i=r.startsWith(`#`)?r.slice(1):r;return{from:n.from,to:n.to,tag:i}}function xo(e){return vo({key:yo,selector:`.md-tag`,preventDefault:!1,findPayloadAt:(e,t)=>bo(e,t)?.tag,onClick:(t,n)=>e({tag:t,event:n})})}const So=new x(`meowdown-wikilink-click`);function Co(e,t){let n=O(e,t,`mdWikilink`);if(!n)return;let{target:r}=n.mark.attrs;return{from:n.from,to:n.to,target:r}}function wo(e){return vo({key:So,selector:`.md-wikilink-view-preview`,preventDefault:!1,findPayloadAt:(e,t)=>Co(e,t)?.target,onClick:(t,n)=>e({target:t,event:n})})}const To=new x(`meowdown-follow-link`);function Eo(e){return e.key!==`Enter`||e.shiftKey||e.altKey?!1:re?e.metaKey&&!e.ctrlKey:e.ctrlKey&&!e.metaKey}function Do(e){return new b({key:To,props:{handleKeyDown:(t,n)=>{if(!Eo(n))return!1;let{state:r}=t,i=r.selection.head,a=e.onWikilinkClick&&Co(r,i);if(a)return e.onWikilinkClick?.({target:a.target,event:n}),!0;let o=e.onTagClick&&bo(r,i);if(o)return e.onTagClick?.({tag:o.tag,event:n}),!0;let s=e.onFileClick&&so(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 Oo(e){return v(m(Do(e)),t.high)}const ko=(e,t)=>{let n={type:`highlight`,children:e.all(t)};return e.patch(t,n),n},Ao=(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 jo(){return yt().use(ht).use(gt,{handlers:{mark:ko}}).use(_t).use(vt,{bullet:`-`,emphasis:`*`,strong:`*`,fence:"`",fences:!0,rule:`-`,ruleRepetition:3,listItemIndent:`one`,handlers:{highlight:Ao}}).freeze()}const Mo=y(jo);function No(e){return String(Mo().processSync(e))}const Po=new x(`meowdown-html-paste`);function Fo(){return m(new b({key:Po,props:{transformPastedHTML:(e,t)=>{if(e.includes(`data-pm-slice`))return e;let n=t.state.selection.$from.parent;if(!n.inlineContent||n.type.spec.code)return e;let r=No(e);if(!r.trim())return e;let i=Y(r,{nodes:Hi(t.state.schema)}),a=Oe.fromSchema(t.state.schema),o=document.createElement(`div`);return o.append(a.serializeFragment(i.content)),o.innerHTML}}}))}const Io=new x(`meowdown-image-click`);function Lo(e,t){let n=O(e,t,`mdImage`);if(!n)return;let{src:r,alt:i}=n.mark.attrs;return{from:n.from,to:n.to,src:r,alt:i}}function Ro(e){return m(new b({key:Io,props:{handleClick:(t,n,r)=>{let i=r.target?.closest?.(`.md-image-view-preview`);if(!i)return!1;let a=i.closest(`.md-image-view`)?.querySelector(`.md-image-view-content`);if(!a)return!1;let o=Lo(t.state,t.posAtDOM(a,0));return o?(e({src:o.src,alt:o.alt,event:r}),!0):!1}}}))}function zo(e){return/^https?:\/\//i.test(e)?e:void 0}function Bo(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`&&Pa(t),t}function Vo(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 Ho(e,t,n,r){let i=e.posAtDOM(t,0),a=O(e.state,i,`mdImage`);if(!a)return;let o=e.state.doc.textBetween(a.from,a.to),s=zn(o),c=a.from+s.length,l=o.slice(s.length),u=Rn({...In(l)??{},width:Math.round(n),height:Math.round(r)});u!==l&&e.dispatch(e.state.tr.insertText(u,c,a.to))}var Uo=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)&&Vo(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=Va(e);if(t){let e=document.createElement(`span`);return e.className=`md-image-view-preview md-atom-view-preview`,e.appendChild(Bo(t)),e}let n=(this.#n.resolveImageUrl??zo)(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){xt(),bt();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,Vo(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)),Vo(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;Ho(this.#r,this.#t,t,n)}),this.#a=t,this.#o=n,t}};function Wo(e={}){return d({name:`mdImage`,constructor:(t,n)=>new Uo(t,n,e)})}const Go={"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`,Escape:`Collapse the selection`},Ko=new x(`meowdown-link-click`);function qo(e){return vo({key:Ko,selector:`.md-link`,preventDefault:!0,findPayloadAt:(e,t)=>K(e,t)?.href,onClick:(t,n)=>e({href:t,event:n})})}function Jo(e){let t,n=(n,r)=>{let i=r.target;if(!i||!fe(i))return;let a=i.closest(e.selector);if(!a||a===t)return;let o=n.posAtDOM(a,0),s=e.findPayloadAt(n.state,o);s!=null&&(t=a,e.onHoverChange({payload:s,element:a}))},r=n=>{if(!t)return;let r=n.relatedTarget;r&&t.contains(r)||(t=void 0,e.onHoverChange(void 0))};return _(s(`mouseover`,(e,t)=>n(e,t)),s(`mouseout`,(e,t)=>r(t)))}function Yo(e){return Jo({selector:`.md-link`,findPayloadAt:(e,t)=>K(e,t),onHoverChange:e})}const Xo=new x(`meowdown-markdown-copy`);function Zo(){return m(new b({key:Xo,props:{clipboardTextSerializer:(e,t)=>{let n=e.content,r;try{r=t.state.schema.topNodeType.createAndFill(void 0,n)??void 0}catch{r=void 0}return r?$(r).replace(/\n+$/,``):n.textBetween(0,n.size,`
24
24
  `,`
25
- `)}}}))}const to=new x(`meowdown-tag-click`);function no(e,t){let n=D(e,t,`mdTag`);if(!n)return;let r=e.doc.textBetween(n.from,n.to),i=r.startsWith(`#`)?r.slice(1):r;return{from:n.from,to:n.to,tag:i}}function ro(e){return Ja({key:to,selector:`.md-tag`,preventDefault:!1,findPayloadAt:(e,t)=>no(e,t)?.tag,onClick:(t,n)=>e({tag:t,event:n})})}const io=new x(`meowdown-wikilink-click`);function ao(e,t){let n=D(e,t,`mdWikilink`);if(!n)return;let{target:r}=n.mark.attrs;return{from:n.from,to:n.to,target:r}}function oo(e){return Ja({key:io,selector:`.md-wikilink-view-preview`,preventDefault:!1,findPayloadAt:(e,t)=>ao(e,t)?.target,onClick:(t,n)=>e({target:t,event:n})})}const so=(e,t)=>{let{selection:n}=e;if(!n.empty&&!n.$head.sameParent(n.$anchor))return!1;let r=e.doc.textBetween(n.from,n.to);if(r.startsWith(`[[`))return!1;r.startsWith(`[`)&&(r=r.slice(1));let i=`[[`+r;if(t){let r=e.tr.insertText(i,n.from,n.to);r.setSelection(S.create(r.doc,n.from+i.length)),_t(r),t(r.scrollIntoView())}return!0};function co(){return l({"Mod-Shift-k":so})}function lo(e,t){let n=()=>{let n=e.coordsAtPos(t.from),r=e.coordsAtPos(t.to),i=Math.min(n.left,r.left),a=Math.max(n.right,r.right),o=Math.min(n.top,r.top),s=Math.max(n.bottom,r.bottom);return new DOMRect(i,o,a-i,s-o)};return{getBoundingClientRect:n,getClientRects:()=>[n()]}}function uo(e){return e instanceof ke||e instanceof Ae||e instanceof je||e instanceof Me||e instanceof F}function fo(e){for(let t of e)for(let e of t.steps)if(!uo(e))return!0;return!1}function po(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){fo(e)&&o()},view(e){return t=e,{destroy(){t=void 0}}}}}function mo(e){let t=new x(`spell-check`);return new b({key:t,state:{init:()=>po(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 ho(e){return m(mo(e))}export{qa as EDITOR_KEY_BINDINGS,e as Priority,Qi as checkRoundTrip,na as codeBlockLanguages,Ia as defaultResolveImageUrl,ea as defineBulletAfterHeading,Lt as defineCodeBlockSyntaxHighlight,ui as defineEditorExtension,ba as defineEmbedPaste,Ta as defineExitBoundaryHandler,Qt as defineHTMLComment,Ma as defineHTMLPaste,Ka as defineImage,Fa as defineImageClickHandler,Xa as defineLinkClickHandler,Fr as defineLinkCommands,Lr as defineLinkEditKeymap,Qa as defineLinkHoverHandler,xt as defineMarkMode,eo as defineMarkdownCopy,ce as definePlaceholder,le as defineReadonly,ho as defineSpellCheckPlugin,ro as defineTagClickHandler,oo as defineWikilinkClickHandler,co as defineWikilinkTrigger,Ni as docToMarkdown,zt as getCodeTokens,K as getLinkUnitAt,pi as getMarkBuilders,lo as getVirtualElementFromRange,Pn as inlineTextToMarkChunks,Mr as insertLink,ri as isSelectionInTableCell,ca as listenForTweetHeight,J as markdownToDoc,ha as matchEmbed,Pr as removeLink,Nr as updateLink,oe as withPriority};
25
+ `)}}}))}function Qo({allowEmpty:e}){return(t,n)=>{let{selection:r}=t;if(!g(r)||!e&&r.empty||!r.$head.sameParent(r.$anchor)||r.$head.parent.type.spec.code)return!1;let i=t.doc.textBetween(r.from,r.to);if(i.startsWith(`[[`))return!1;i.startsWith(`[`)&&(i=i.slice(1));let a=`[[`+i;if(n){let e=t.tr.insertText(a,r.from,r.to);e.setSelection(S.create(e.doc,r.from+a.length)),St(e),n(e.scrollIntoView())}return!0}}function $o(){return l({"Mod-Shift-k":Qo({allowEmpty:!0}),"[":Qo({allowEmpty:!1})})}function es(e){let{selection:t,schema:n}=e;if(t.empty)return``;let r=t.content().content;try{return $(n.topNodeType.create(null,r)).replace(/\n+$/,``)}catch{return e.doc.textBetween(t.from,t.to,`
26
+
27
+ `)}}function ts(e,t){let n=new DOMRect(0,0,0,0),r=()=>{if(e.isDestroyed)return n;try{let r=e.coordsAtPos(t.from),i=e.coordsAtPos(t.to),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);n=new DOMRect(a,s,o-a,c-s)}catch{}return n};return{getBoundingClientRect:r,getClientRects:()=>[r()]}}function ns(e){return e instanceof Pe||e instanceof Fe||e instanceof Ie||e instanceof Le||e instanceof N}function rs(e){for(let t of e)for(let e of t.steps)if(!ns(e))return!0;return!1}function is(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){rs(e)&&o()},view(e){return t=e,{destroy(){t=void 0}}}}}function as(e){let t=new x(`spell-check`);return new b({key:t,state:{init:()=>is(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 os(e){return m(as(e))}export{Go as EDITOR_KEY_BINDINGS,e as Priority,$a as buildFileMarkdown,wa as checkRoundTrip,Oa as codeBlockLanguages,zo as defaultResolveImageUrl,Ea as defineBulletAfterHeading,Gt as defineCodeBlockSyntaxHighlight,Fi as defineEditorExtension,Ka as defineEmbedPaste,Za as defineExitBoundaryHandler,co as defineFileClickHandler,ao as defineFilePaste,_o as defineFileView,Oo as defineFollowLinkHandler,un as defineHTMLComment,Fo as defineHTMLPaste,Wo as defineImage,Ro as defineImageClickHandler,qo as defineLinkClickHandler,Gr as defineLinkCommands,qr as defineLinkEditKeymap,Yo as defineLinkHoverHandler,Et as defineMarkMode,Zo as defineMarkdownCopy,Ni as definePendingReplacementHandler,ue as definePlaceholder,de as defineReadonly,os as defineSpellCheckPlugin,xo as defineTagClickHandler,wo as defineWikilinkClickHandler,$o as defineWikilinkTrigger,$ as docToMarkdown,qt as getCodeTokens,K as getLinkUnitAt,Ri as getMarkBuilders,J as getPendingReplacement,es as getSelectedText,ts as getVirtualElementFromRange,Gn as inlineTextToMarkChunks,Hr as insertLink,fi as isSelectionInTableCell,Pa as listenForTweetHeight,Y as markdownToDoc,Va as matchEmbed,Wr as removeLink,Ur as updateLink,ce as withPriority};
package/dist/style.css CHANGED
@@ -162,6 +162,10 @@
162
162
  --meowdown-code-bg: light-dark(oklch(96.7% 0 0), oklch(21% .006 286));
163
163
  --meowdown-image-loading-bg: light-dark(oklch(96.7% 0 0), oklch(27.4% .005 286));
164
164
  --meowdown-image-radius: .5rem;
165
+ --meowdown-file-pill-bg: light-dark(oklch(98.5% 0 0), oklch(21% .006 286));
166
+ --meowdown-file-pill-bg-hover: light-dark(oklch(96.7% 0 0), oklch(27.4% .005 286));
167
+ --meowdown-file-pill-border: var(--meowdown-border);
168
+ --meowdown-file-pill-muted: var(--meowdown-muted);
165
169
  --meowdown-table-header-bg: light-dark(oklch(98.5% 0 0), oklch(27.4% .005 286));
166
170
  --meowdown-popover-bg: light-dark(oklch(100% 0 0), oklch(21% .006 286));
167
171
  --meowdown-popover-hover-bg: light-dark(oklch(96.7% 0 0), oklch(27.4% .005 286));
@@ -253,6 +257,13 @@
253
257
  padding: 0 1px;
254
258
  }
255
259
 
260
+ .ProseMirror .md-pending-replacement {
261
+ background: var(--meowdown-selection);
262
+ -webkit-box-decoration-break: clone;
263
+ box-decoration-break: clone;
264
+ border-radius: 2px;
265
+ }
266
+
256
267
  .ProseMirror code {
257
268
  font-family: var(--meowdown-font-mono);
258
269
  background: var(--meowdown-code-bg);
@@ -659,6 +670,50 @@
659
670
  }
660
671
  }
661
672
 
673
+ .ProseMirror {
674
+ & .md-file-view {
675
+ max-width: 100%;
676
+ margin-left: 2px;
677
+ margin-right: 2px;
678
+ }
679
+
680
+ & .md-file-view-preview {
681
+ border: 1px solid var(--meowdown-file-pill-border);
682
+ background: var(--meowdown-file-pill-bg);
683
+ cursor: pointer;
684
+ border-radius: 999px;
685
+ align-items: center;
686
+ gap: .4em;
687
+ max-width: 100%;
688
+ padding: .1em .65em;
689
+ display: inline-flex;
690
+ }
691
+
692
+ & .md-file-view-preview:hover {
693
+ background: var(--meowdown-file-pill-bg-hover);
694
+ }
695
+
696
+ & .md-file-view-icon {
697
+ width: 1em;
698
+ height: 1em;
699
+ color: var(--meowdown-file-pill-muted);
700
+ flex: none;
701
+ }
702
+
703
+ & .md-file-view-name {
704
+ white-space: nowrap;
705
+ text-overflow: ellipsis;
706
+ overflow: hidden;
707
+ }
708
+
709
+ & .md-file-view-size {
710
+ white-space: nowrap;
711
+ color: var(--meowdown-file-pill-muted);
712
+ flex: none;
713
+ font-size: .85em;
714
+ }
715
+ }
716
+
662
717
  .ProseMirror {
663
718
  & .md-wikilink-view-label {
664
719
  background: color-mix(in oklab, var(--meowdown-accent) 10%, transparent);
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@meowdown/core",
3
3
  "type": "module",
4
- "version": "0.30.1",
4
+ "version": "0.32.0",
5
5
  "license": "MIT",
6
6
  "repository": {
7
7
  "type": "git",