@meowdown/core 0.9.0 → 0.11.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
@@ -61,6 +61,12 @@ Inline images (`![alt](src)`) stay literal text and render beneath their line as
61
61
 
62
62
  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.
63
63
 
64
+ 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.
65
+
66
+ ## Re-exports
67
+
68
+ `Priority` and `withPriority` are re-exported from `@prosekit/core`, so you can set extension priorities (e.g. `withPriority(extension, Priority.high)`) without depending on `@prosekit/core` directly.
69
+
64
70
  ## License
65
71
 
66
72
  MIT
package/dist/index.d.ts CHANGED
@@ -1,4 +1,4 @@
1
- import { Editor, ExtractNodeBuilders, PlainExtension } from "@prosekit/core";
1
+ import { Editor, ExtractNodeBuilders, PlainExtension, Priority, withPriority } from "@prosekit/core";
2
2
  import { CodeBlockAttrs } from "@prosekit/extensions/code-block";
3
3
  import { ProseMirrorNode } from "@prosekit/pm/model";
4
4
  import { PlaceholderOptions, definePlaceholder } from "@prosekit/extensions/placeholder";
@@ -99,6 +99,14 @@ declare function defineImages(options: ImageOptions): PlainExtension;
99
99
  */
100
100
  declare function defineEmbedPaste(): PlainExtension;
101
101
  //#endregion
102
+ //#region src/extensions/bullet-after-heading.d.ts
103
+ /**
104
+ * "Type a title, press Return, start bullets." When this extension is applied,
105
+ * pressing Enter at the end of the document's first heading (the title line)
106
+ * drops the caret into a fresh empty bullet instead of a plain paragraph.
107
+ */
108
+ declare function defineBulletAfterHeading(): PlainExtension;
109
+ //#endregion
102
110
  //#region src/extensions/key-bindings.d.ts
103
111
  /** Human-readable descriptions of the editor's formatting and heading shortcuts. */
104
112
  declare const EDITOR_KEY_BINDINGS: {
@@ -172,4 +180,4 @@ type RoundTripFidelity = 'exact' | 'normalizing' | 'lossy';
172
180
  /** Classify how `markdown` survives the editor's parse-then-serialize round trip. */
173
181
  declare function checkRoundTrip(markdown: string): RoundTripFidelity;
174
182
  //#endregion
175
- export { type CodeBlockAttrs, EDITOR_KEY_BINDINGS, type EditorExtension, type ImageOptions, type MarkMode, type PlaceholderOptions, type RoundTripFidelity, type TypedEditor, type WikilinkClickHandler, type WikilinkClickPayload, checkRoundTrip, codeBlockLanguages, defineEditorExtension, defineEmbedPaste, defineImages, defineMarkMode, definePlaceholder, defineReadonly, defineWikilinkClickHandler, docToMarkdown, markdownToDoc };
183
+ export { type CodeBlockAttrs, EDITOR_KEY_BINDINGS, type EditorExtension, type ImageOptions, type MarkMode, type PlaceholderOptions, Priority, type RoundTripFidelity, type TypedEditor, type WikilinkClickHandler, type WikilinkClickPayload, checkRoundTrip, codeBlockLanguages, defineBulletAfterHeading, defineEditorExtension, defineEmbedPaste, defineImages, defineMarkMode, definePlaceholder, defineReadonly, defineWikilinkClickHandler, docToMarkdown, markdownToDoc, withPriority };
package/dist/index.js CHANGED
@@ -1,15 +1,15 @@
1
- import{Priority as e,createMarkBuilders as t,createNodeBuilders as n,defineBaseCommands as r,defineBaseKeymap as i,defineCommands as a,defineHistory as o,defineKeymap as s,defineMarkSpec as c,definePlugin as l,getMarkType as u,isApple as d,isAtBlockStart as ee,toggleNode as te,union as f,unsetBlockType as ne,withPriority as re,withSkipCodeBlock as ie}from"@prosekit/core";import{defineBlockquote as ae}from"@prosekit/extensions/blockquote";import{defineCodeBlock as oe,defineCodeBlockHighlight as se}from"@prosekit/extensions/code-block";import{defineDoc as ce}from"@prosekit/extensions/doc";import{defineGapCursor as le}from"@prosekit/extensions/gap-cursor";import{defineHorizontalRule as ue}from"@prosekit/extensions/horizontal-rule";import{defineList as de}from"@prosekit/extensions/list";import{defineModClickPrevention as fe}from"@prosekit/extensions/mod-click-prevention";import{defineParagraph as pe}from"@prosekit/extensions/paragraph";import{defineText as me}from"@prosekit/extensions/text";import{defineVirtualSelection as he}from"@prosekit/extensions/virtual-selection";import{LanguageDescription as ge}from"@codemirror/language";import{languages as _e}from"@codemirror/language-data";import{classHighlighter as ve}from"@lezer/highlight";import{createParser as ye}from"prosemirror-highlight/lezer";import{defineHeadingCommands as be,defineHeadingInputRule as xe,defineHeadingSpec as Se}from"@prosekit/extensions/heading";import{Plugin as p,PluginKey as m,TextSelection as h}from"@prosekit/pm/state";import{ReplaceStep as Ce,Step as we,StepResult as g,Transform as _}from"@prosekit/pm/transform";import{Mark as Te}from"@prosekit/pm/model";import{GFM as Ee,parser as De}from"@lezer/markdown";import{once as Oe}from"@ocavue/utils";import{defineTableCellSpec as ke,defineTableCommands as Ae,defineTableDropIndicator as je,defineTableEditingPlugin as Me,defineTableHeaderCellSpec as Ne,defineTableRowSpec as Pe,defineTableSpec as Fe}from"@prosekit/extensions/table";import{Decoration as v,DecorationSet as y}from"@prosekit/pm/view";import{closeHistory as b}from"@prosekit/pm/history";import{definePlaceholder as Ie}from"@prosekit/extensions/placeholder";import{defineReadonly as Le}from"@prosekit/extensions/readonly";const x=new Map;async function Re(e){let t=ge.matchLanguageName(_e,e,!0);if(!t){x.set(e,null);return}let n=t.support;if(!n)try{n=await t.load()}catch(t){console.error(`[meowdown] Failed to load language "${e}":`,t),x.set(e,null)}if(x.has(e))return;if(!n){x.set(e,null);return}let r=ye({parse:e=>n.language.parser.parse(e.content),highlighter:ve});x.set(e,r)}const ze=e=>{let t=e.language?.trim();if(!t)return[];let n=x.get(t);return n?n(e):n===null?[]:Re(t)};function Be(){return se({parser:ze,nodeTypes:[`codeBlock`]})}function S(e){return ie(te({type:`heading`,attrs:{level:e}}))}const Ve=(e,t,n)=>ee(e,n)?.parent.type.name===`heading`?ne()(e,t,n):!1;function He(){return s({"Mod-1":S(1),"Mod-2":S(2),"Mod-3":S(3),"Mod-4":S(4),"Mod-5":S(5),"Mod-6":S(6),Backspace:Ve})}function Ue(){return f(Se(),xe(),be(),He())}function We(e){let[t,n,r]=e;return[t,n,r.map(e=>e.toJSON())]}function Ge(e,t){let[n,r,i]=t;return[n,r,i.map(t=>Te.fromJSON(e,t))]}var C=class e extends we{constructor(e){super(),this.chunks=e}apply(e){if(this.chunks.length===0)return g.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 _(e),n.removeMark(i,c,t));for(let t of a)t.isInSet(l)||(n??=new _(e),n.addMark(i,c,t));return!1})}return g.ok(n?n.doc:e)}invert(e){if(this.chunks.length===0)return Ke;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 Ce(i,a,e.slice(i,a),!1)}map(e){return null}toJSON(){return{stepType:`batchSetMark`,chunks:this.chunks.map(We)}}static fromJSON(t,n){let r=n.chunks;return new e(r.map(e=>Ge(t,e)))}};we.jsonID(`batchSetMark`,C);const Ke=new C([]);function qe(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 Je(e){return e>=65&&e<=90||e>=97&&e<=122||e>127&&/\p{L}/u.test(String.fromCharCode(e))}const Ye={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(!qe(t))break;i||=Je(t),r++}return i?e.addElement(e.elt(`Hashtag`,n,r)):-1}}]},Xe={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 Ze(e){return e.end}const w=De.configure([Ee,Ye,Xe]),Qe=w.configure({parseInline:[{name:`SkipInline`,before:`Escape`,parse:Ze}]});function T(e){return w.parseInline(e,0)}function E(e,t,n=[]){for(let r of e)t(r)&&n.push(r),E(r.children,t,n);return n}function $e(e){let t={};for(let n of e.nodeSet.types)t[n.name]=n.id;return t}const D=$e(w);function et(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}const O=new Map([[D.Emphasis,`mdEm`],[D.StrongEmphasis,`mdStrong`],[D.InlineCode,`mdCode`],[D.Strikethrough,`mdDel`],[D.EmphasisMark,`mdMark`],[D.CodeMark,`mdMark`],[D.LinkMark,`mdMark`],[D.StrikethroughMark,`mdMark`],[D.URL,`mdLinkUri`],[D.Hashtag,`mdTag`],[D.Wikilink,`mdWikilink`],[D.WikilinkMark,`mdMark`]]);function tt(e,t){let n=T(t),r=[];return k(n,[],0,t.length,t,e,r),r}function nt(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))return`https://${e}`}function k(e,t,n,r,i,a,o){let s=n;for(let n of e){if(n.from>s&&A(o,s,n.from,t),n.type===D.Link||n.type===D.Image)rt(n,t,i,a,o);else if(n.type===D.URL){let e=nt(i.slice(n.from,n.to)),r=e?a.mdLinkText.create({href:e}):a.mdLinkUri.create();A(o,n.from,n.to,[...t,r])}else{let e=O.get(n.type),r=e?[...t,a[e].create()]:t;n.children.length===0?A(o,n.from,n.to,r):k(n.children,r,n.from,n.to,i,a,o)}s=n.to}s<r&&A(o,s,r,t)}function rt(e,t,n,r,i){let a=-1,o=null,s=0;for(let t of e.children)t.type===D.LinkMark?(s++,s===2&&(a=t.from)):t.type===D.URL&&o===null&&(o=t);let c=o?n.slice(o.from,o.to):``,l=c?r.mdLinkText.create({href:c}):null,u=e=>a>=0&&e<a&&l!==null,d=e.from;for(let a of e.children){if(a.from>d){let e=u(d)?[...t,l]:t;A(i,d,a.from,e)}let e=u(a.from)?[...t,l]:t,o=O.get(a.type),s=o?[...e,r[o].create()]:e;a.children.length===0?A(i,a.from,a.to,s):k(a.children,s,a.from,a.to,n,r,i),d=a.to}d<e.to&&A(i,d,e.to,t)}function A(e,t,n,r){if(t>=n)return;let i=e.at(-1);if(i&&i[1]===t&&et(i[2],r)){e[e.length-1]=[i[0],n,i[2]];return}e.push([t,n,r])}const it=Oe(()=>{let e=H().schema;if(e==null)throw Error(`Unexpected empty schema`);return e}),at=Oe(()=>n(it())),j=`meowdown_mark_builders`;function ot(e){let n=e.cached[j];if(n)return n;let r=t(e);return e.cached[j]=r,r}const M=`inline-marks-applied`,N=new WeakMap;let st=0,ct=0;function lt(e,t,n){let r=N.get(e);if(r?ct++:(st++,r=tt(ot(n),e.textContent),N.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 ut(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 dt(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=lt(t,r+1,e.schema);return i.length>0&&n.push(...i),!1}),n}function ft(){return new p({key:new m(`inline-mark`),appendTransaction(e,t,n){for(let t of e)if(t.getMeta(M))return null;let r=dt(n,ut(e,n));if(r.length===0)return null;let i=n.tr.step(new C(r));return i.setMeta(M,!0),i.setMeta(`addToHistory`,!1),i},view(e){return e.dispatch(pt(e.state)),{}}})}function pt(e){return e.tr.setMeta(`inline-marks-trigger`,!0)}function mt(){return l(ft())}function ht(){return c({name:`mdMark`,inclusive:!1,toDOM:()=>[`span`,{class:`md-mark`},0],parseDOM:[{tag:`span.md-mark`}]})}function gt(){return c({name:`mdEm`,toDOM:()=>[`em`,0],parseDOM:[{tag:`em`}]})}function _t(){return c({name:`mdStrong`,toDOM:()=>[`strong`,0],parseDOM:[{tag:`strong`}]})}function vt(){return c({name:`mdCode`,toDOM:()=>[`code`,0],parseDOM:[{tag:`code`}]})}function yt(){return c({name:`mdLinkText`,inclusive:!1,attrs:{href:{default:``}},toDOM:e=>[`a`,{href:e.attrs.href},0],parseDOM:[{tag:`a`,getAttrs:e=>({href:e.getAttribute(`href`)??``})}]})}function bt(){return c({name:`mdLinkUri`,inclusive:!1,toDOM:()=>[`span`,{class:`md-link-uri`},0],parseDOM:[{tag:`span.md-link-uri`}]})}function xt(){return c({name:`mdDel`,toDOM:()=>[`del`,0],parseDOM:[{tag:`del`}]})}function St(){return c({name:`mdTag`,toDOM:()=>[`span`,{class:`md-tag`},0],parseDOM:[{tag:`span.md-tag`}]})}function Ct(){return c({name:`mdWikilink`,inclusive:!1,toDOM:()=>[`span`,{class:`md-wikilink`},0],parseDOM:[{tag:`span.md-wikilink`}]})}function wt(){return f(ht(),gt(),_t(),vt(),yt(),bt(),xt(),St(),Ct())}function Tt(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 P={em:{node:D.Emphasis,delim:`*`},strong:{node:D.StrongEmphasis,delim:`**`},code:{node:D.InlineCode,delim:"`"},del:{node:D.Strikethrough,delim:`~~`}},Et=new Set([D.EmphasisMark,D.CodeMark,D.LinkMark,D.StrikethroughMark]);function F(e){return[e.children[0],e.children.at(-1)]}function I(e){let{type:t,children:n}=e;if(t===D.Emphasis||t===D.StrongEmphasis||t===D.Strikethrough)return[n[0].to,n.at(-1).from];if(t===D.Link||t===D.Image){let e=n.find((e,t)=>t>0&&e.type===D.LinkMark);return e?[n[0].to,e.from]:null}return null}function L(e,t,n){for(let r of e){if(r.to<=t||r.from>=n||t<=r.from&&r.to<=n)continue;let i=I(r);return i&&i[0]<=t&&n<=i[1]?L(r.children,t,n):L(e,Math.min(t,r.from),Math.max(n,r.to))}return[t,n]}function R(e,t,n){for(let r of e)if(!(r.to<=t||r.from>=n)&&(t>r.from||r.to>n))return R(e,Math.min(t,r.from),Math.max(n,r.to));return[t,n]}const z=e=>e===` `||e===` `;function Dt(e,t,n){for(;t<n&&z(e[t]);)t++;for(;n>t&&z(e[n-1]);)n--;return[t,n]}function Ot(e,t,n,r){let i=E(T(e),e=>e.type===r.node||Et.has(e.type));for(let r=t;r<n;r++)if(!z(e[r])&&i.every(e=>!(e.from<=r&&r<e.to)))return!1;return!0}function kt(e,t,n,r,i){let a=T(e),o=E(a,e=>e.type===r.node);return i?Mt(e,o,t,n):At(e,a,o,t,n,r)}function At(e,t,n,r,i,a){for(let e=0;e!==i-r;){e=i-r,[r,i]=L(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]=F(e);o.push({from:t.from,to:t.to,insert:``}),o.push({from:n.from,to:n.to,insert:``})}let[s,c]=jt(e,r,i,o,a);return o.push({from:r,to:r,insert:s},{from:i,to:i,insert:c}),o}function jt(e,t,n,r,i){if(i.node!==D.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(Tt(a)+1),s=a.startsWith("`")||a.endsWith("`")?` `:``;return[o+s,s+o]}function Mt(e,t,n,r){let i=[];for(let a of t){if(a.to<=n||a.from>=r)continue;let[t,o]=F(a),s=Math.max(n,t.to),c=Math.min(r,o.from);for(s>=c&&([s,c]=[t.to,o.from]),[s,c]=R(a.children.slice(1,-1),s,c);s>t.to&&z(e[s-1]);)s--;for(;c<o.from&&z(e[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 Nt(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=T(e),o=E(a,e=>e.type===n.node).findLast(e=>e.from<=t&&t<=e.to);if(o){let[e,n]=F(o);return{kind:`move`,pos:t===o.from?e.to:t===o.to?n.from:o.to}}return B(a,t)||e[t-1]===r[0]||e[t]===r[0]?null:{kind:`insert`,pos:t}}function B(e,t){for(let n of e)if(n.from<t&&t<n.to){let e=I(n);return!e||t<e[0]||t>e[1]?!0:B(n.children,t)}return!1}function V(e){return(t,n)=>{if(t.selection.empty)return Pt(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]=Dt(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:Ot(a,c,l,e)}),!1});let c=s.length>0&&s.every(e=>e.active),l=s.filter(e=>c||!e.active).flatMap(t=>kt(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(h.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 Pt(e,t,n){let{$from:r}=t.selection,i=r.parent;if(!i.isTextblock||i.type.spec.code)return!1;let a=Nt(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(h.create(o.doc,i+a.pos)),a.kind===`insert`&&(o.insertText(e.delim+e.delim,i+a.pos),o.setSelection(h.create(o.doc,i+a.pos+e.delim.length))),n(o.scrollIntoView())}return!0}function Ft(){return a({toggleEm:()=>V(P.em),toggleStrong:()=>V(P.strong),toggleCode:()=>V(P.code),toggleDel:()=>V(P.del)})}function It(){return s({"Mod-b":V(P.strong),"Mod-i":V(P.em),"Mod-e":V(P.code),"Mod-Shift-x":V(P.del)})}function Lt(){return f(Ft(),It())}function Rt(){return f(Fe(),Pe(),ke(),Ne(),Me({allowTableNodeSelection:!0}),Ae(),je())}function zt(){return f(pe(),ce(),me(),ae(),de(),Ue(),Rt(),oe(),ue(),wt(),Be(),mt(),Lt(),i(),r(),o(),le(),he(),fe())}function H(){return zt()}const Bt=new Set([`mdStrong`,`mdEm`,`mdCode`,`mdDel`,`mdLinkText`,`mdLinkUri`,`mdWikilink`]),Vt=new Set([`mdMark`,`mdLinkUri`]),Ht=new Set([`mdMark`,`mdLinkUri`]),U=new Set([`mdLinkText`,`mdLinkUri`]),Ut=new Set([`mdStrong`,`mdEm`,`mdCode`,`mdDel`,`mdWikilink`]);function Wt(e){return new p({key:new m(`mark-mode`),props:{attributes:{"data-mark-mode":e},decorations:e===`focus`?e=>qt(e):void 0,clipboardTextSerializer:e===`show`?void 0:Kt}})}function Gt(e){return l(Wt(e))}function Kt(e){let t=[];return e.content.forEach(e=>{let n=[];e.descendants(e=>!e.isText||!e.text?!0:(e.marks.some(e=>Ht.has(e.type.name))||n.push(e.text),!1)),t.push(n.join(``))}),t.join(`
2
- `)}function qt(e){let{$anchor:t,empty:n}=e.selection;if(!n)return y.empty;let r=t.parent;if(!r.isTextblock)return null;let i=t.start(),a=t.parentOffset,o=Jt(r,a);if(o.size===0)return y.empty;let s=[],c=new Set,l=!1;for(let e of o)if(U.has(e)){if(l)continue;l=!0,Xt(r,i,a,s,c)}else Yt(r,i,e,a,s,c);let u=s.map(([e,t])=>v.inline(e,t,{class:`show`}));return y.create(e.doc,u)}function Jt(e,t){let n=new Set,r=0;return e.forEach(e=>{let i=r+e.nodeSize;if(t>=r&&t<=i)for(let t of e.marks){let e=t.type.name;Bt.has(e)&&n.add(e)}r=i}),n}function Yt(e,t,n,r,i,a){let o=t,s=0,c=-1,l=-1;e.forEach(u=>{let d=u.marks.some(e=>e.type.name===n);d&&c===-1&&(c=o,l=s),!d&&c!==-1&&(r>=l&&r<=s&&G(e,t,c,o,i,a),c=-1,l=-1),o+=u.nodeSize,s+=u.nodeSize}),c!==-1&&r>=l&&r<=s&&G(e,t,c,o,i,a)}function Xt(e,t,n,r,i){let a=e.childCount;if(a===0)return;let o=-1,s=0;for(let t=0;t<a;t++){let r=e.child(t),i=s+r.nodeSize;if(n>=s&&n<=i&&r.marks.some(e=>U.has(e.type.name))){o=t;break}s=i}if(o===-1)return;let c=o;for(;c>0&&W(e.child(c-1));)c--;let l=o;for(;l<a-1&&W(e.child(l+1));)l++;let u=t;for(let t=0;t<c;t++)u+=e.child(t).nodeSize;let d=u;for(let t=c;t<=l;t++)d+=e.child(t).nodeSize;G(e,t,u,d,r,i)}function W(e){let t=!1,n=!1,r=!1;for(let i of e.marks){let e=i.type.name;e===`mdMark`?t=!0:U.has(e)?n=!0:Ut.has(e)&&(r=!0)}return!!(n||t&&!r)}function G(e,t,n,r,i,a){let o=t;e.forEach(e=>{let t=o,s=o+e.nodeSize;if(t>=n&&s<=r)for(let n of e.marks){let e=n.type.name;if(Vt.has(e)){let e=`${t}_${s}`;a.has(e)||(a.add(e),i.push([t,s]));break}}o=s})}const Zt=new m(`meowdown-wikilink-click`);function Qt(e,t){let n=u(e.schema,`mdWikilink`),r=e.doc.resolve(t),i=r.parent;if(!i.isTextblock||i.type.spec.code)return;let a=r.start(),o=-1,s=-1,c,l=0;if(i.forEach(e=>{let r=a+l;l+=e.nodeSize;let i=a+l;n.isInSet(e.marks)?(o<0&&(o=r),s=i):(o>=0&&o<=t&&t<=s&&(c={from:o,to:s}),o=-1)}),o>=0&&o<=t&&t<=s&&(c={from:o,to:s}),c)return{from:c.from,to:c.to,target:$t(e.doc.textBetween(c.from,c.to))}}function $t(e){let t=e.replace(/^\[\[/u,``).replace(/\]\]$/u,``),n=t.indexOf(`|`);return(n>=0?t.slice(0,n):t).trim()}function en(e){let t;return l(new p({key:Zt,props:{handleDOMEvents:{mousedown:e=>{let{from:n,to:r,empty:i}=e.state.selection;return t={from:n,to:r,empty:i},!1}},handleClick:(n,r,i)=>{if(!i.target?.closest?.(`.md-wikilink`))return!1;let a=Qt(n.state,r);return!a||!(d?i.metaKey:i.ctrlKey)&&t?.empty&&t.from>=a.from&&t.to<=a.to?!1:(e({target:a.target,event:i}),!0)}}}))}function tn(e){let t=[],n=E(T(e),e=>e.type===D.Image);for(let r of n){let n=r.children.find(e=>e.type===D.URL),i=r.children.filter(e=>e.type===D.LinkMark);!n||i.length<2||t.push({from:r.from,to:r.to,alt:e.slice(i[0].to,i[1].from),src:e.slice(n.from,n.to)})}return t}function nn(){return typeof window>`u`?!1:window.matchMedia(`(prefers-color-scheme: dark)`).matches}const rn=/^(?:www\.|mobile\.)?(?:twitter\.com|x\.com)$/i,an=/\/status(?:es)?\/(\d+)/;function on(e){let t;try{t=new URL(e)}catch{return}if(rn.test(t.hostname))return an.exec(t.pathname)?.[1]}const sn=e=>{let t=on(e);if(t)return{key:`tweet:${t}`,render:()=>{let e=nn()?`dark`:`light`,n=document.createElement(`iframe`);return n.src=`https://platform.twitter.com/embed/Tweet.html?id=${t}&theme=${e}&dnt=true`,n.title=`Tweet`,n.className=`md-embed md-embed-tweet`,n.dataset.testid=`tweet-embed`,n.loading=`lazy`,n.referrerPolicy=`strict-origin-when-cross-origin`,n.setAttribute(`frameborder`,`0`),cn(n),n}}};function cn(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=new MutationObserver(()=>{e.isConnected||(window.removeEventListener(`message`,t),n.disconnect())});n.observe(document.body,{childList:!0,subtree:!0})}const ln=/^(?:www\.|m\.)?(?:youtube\.com|youtube-nocookie\.com)$/i,un=/^(?:www\.)?youtu\.be$/i,dn=/^[\w-]{11}$/;function fn(e){let t;try{t=new URL(e)}catch{return}let n=null;if(un.test(t.hostname))n=t.pathname.slice(1);else if(ln.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||!dn.test(n))return;let r=t.searchParams.get(`start`)??t.searchParams.get(`t`),i=r?pn(r):void 0;return{videoId:n,startSeconds:i}}function pn(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 mn=[e=>{let t=fn(e);if(!t)return;let n=t.startSeconds?`?start=${t.startSeconds}`:``;return{key:`youtube:${t.videoId}:${t.startSeconds??0}`,render:()=>{let e=document.createElement(`iframe`);return e.src=`https://www.youtube-nocookie.com/embed/${t.videoId}${n}`,e.title=`YouTube video`,e.className=`md-embed md-embed-youtube`,e.dataset.testid=`youtube-embed`,e.loading=`lazy`,e.referrerPolicy=`strict-origin-when-cross-origin`,e.setAttribute(`frameborder`,`0`),e.allow=`accelerometer; autoplay; clipboard-write; encrypted-media; gyroscope; picture-in-picture; web-share; fullscreen`,e.allowFullscreen=!0,e}}},sn];function K(e){for(let t of mn){let n=t(e);if(n)return n}}const q=new m(`meowdown-images`);function hn(e){let t=[];return e.doc.descendants((e,n)=>{if(e.type.spec.code)return!1;if(!e.isTextblock)return!0;if(e.childCount===0)return!1;let r=!0;if(e.forEach(e=>{e.isText||(r=!1)}),!r)return!1;for(let r of tn(e.textContent))t.push({widgetAt:n+e.nodeSize-1,alt:r.alt,src:r.src});return!1}),t}function J(e,t){let n=[];for(let r of hn(e)){let e=K(r.src);if(e){n.push(gn(r,e));continue}let i=t.resolveImageUrl(r.src);i&&n.push(_n(r,i))}return y.create(e.doc,n)}function gn(e,t){return v.widget(e.widgetAt,()=>{let e=document.createElement(`div`);return e.className=`md-embed-wrapper`,e.contentEditable=`false`,e.appendChild(t.render()),e},{key:`md-embed:${t.key}`,side:1})}function _n(e,t){return v.widget(e.widgetAt,()=>{let n=document.createElement(`div`);n.className=`md-image`,n.contentEditable=`false`;let r=document.createElement(`img`);return r.src=t,r.alt=e.alt,r.draggable=!1,n.appendChild(r),n},{key:`md-image:${t}`,side:1})}function vn(e){return new p({key:q,state:{init:(t,n)=>J(n,e),apply:(t,n,r,i)=>t.docChanged?J(i,e):n},props:{decorations:e=>q.getState(e)}})}function Y(e){return e?Array.from(e.files).filter(e=>e.type.startsWith(`image/`)):[]}const yn=e=>{console.error(`[meowdown] failed to save pasted image:`,e)};async function X(e,t,n,r=yn,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 bn(e){return new p({props:{handlePaste:(t,n)=>{let r=Y(n.clipboardData),{onImagePaste:i,onImageSaveError:a}=e;return r.length===0||!i?!1:(X(t,r,i,a),!0)},handleDrop:(t,n)=>{let r=Y(n.dataTransfer),{onImagePaste:i,onImageSaveError:a}=e;return r.length===0||!i?!1:(X(t,r,i,a,t.posAtCoords({left:n.clientX,top:n.clientY})?.pos),!0)}}})}function xn(t){return f(l(vn(t)),re(l(bn(t)),e.high))}const Sn=new m(`meowdown-embed-paste`);function Cn(e){let t=e.trim();if(!(!t||/\s/.test(t)))return K(t)?t:void 0}function wn(e,t){let{from:n,to:r}=e.state.selection;e.dispatch(b(e.state.tr.insertText(t,n,r)));let i=e.state.tr.insertText(`![](${t})`,n,n+t.length);e.dispatch(b(i))}function Tn(){return l(new p({key:Sn,props:{handlePaste:(e,t)=>{let n=e.state.selection.$from.parent;if(!n.inlineContent||n.type.spec.code)return!1;let r=t.clipboardData?.getData(`text/plain`);if(!r)return!1;let i=Cn(r);return i?(wn(e,i),!0):!1}}}))}const En={"Mod-b":`Bold`,"Mod-i":`Italic`,"Mod-e":`Inline code`,"Mod-Shift-x":`Strikethrough`,"Mod-1":`Heading 1`,"Mod-2":`Heading 2`,"Mod-3":`Heading 3`,"Mod-4":`Heading 4`,"Mod-5":`Heading 5`,"Mod-6":`Heading 6`},Dn=new Set([`MscGen`,`Xù`,`MsGenny`,`Angular Template`]),On=_e.map(e=>e.name).filter(e=>!Dn.has(e)).map(e=>({label:e,value:e.toLowerCase()})).concat({label:`Plain text`,value:``}).sort((e,t)=>e.label.localeCompare(t.label));function kn(e){let t=new jn;return Mn(e,t),t.finish()}const An=[``,`# `,`## `,`### `,`#### `,`##### `,`###### `];var jn=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(`
1
+ import{Priority as e,Priority as t,createMarkBuilders as n,createNodeBuilders as r,defineBaseCommands as i,defineBaseKeymap as a,defineCommands as o,defineHistory as s,defineKeymap as c,defineMarkSpec as l,definePlugin as u,getMarkType as d,getNodeType as f,isApple as ee,isAtBlockStart as te,toggleNode as ne,union as p,unsetBlockType as re,withPriority as ie,withPriority as m,withSkipCodeBlock as ae}from"@prosekit/core";import{defineBlockquote as oe}from"@prosekit/extensions/blockquote";import{defineCodeBlock as se,defineCodeBlockHighlight as ce}from"@prosekit/extensions/code-block";import{defineDoc as le}from"@prosekit/extensions/doc";import{defineGapCursor as ue}from"@prosekit/extensions/gap-cursor";import{defineHorizontalRule as de}from"@prosekit/extensions/horizontal-rule";import{defineList as fe}from"@prosekit/extensions/list";import{defineModClickPrevention as pe}from"@prosekit/extensions/mod-click-prevention";import{defineParagraph as me}from"@prosekit/extensions/paragraph";import{defineText as he}from"@prosekit/extensions/text";import{defineVirtualSelection as ge}from"@prosekit/extensions/virtual-selection";import{LanguageDescription as _e}from"@codemirror/language";import{languages as ve}from"@codemirror/language-data";import{classHighlighter as ye}from"@lezer/highlight";import{createParser as be}from"prosemirror-highlight/lezer";import{defineHeadingCommands as xe,defineHeadingInputRule as Se,defineHeadingSpec as Ce}from"@prosekit/extensions/heading";import{Plugin as h,PluginKey as g,TextSelection as _}from"@prosekit/pm/state";import{ReplaceStep as we,Step as v,StepResult as y,Transform as b}from"@prosekit/pm/transform";import{Mark as Te}from"@prosekit/pm/model";import{GFM as Ee,parser as De}from"@lezer/markdown";import{once as x}from"@ocavue/utils";import{defineTableCellSpec as Oe,defineTableCommands as ke,defineTableDropIndicator as Ae,defineTableEditingPlugin as je,defineTableHeaderCellSpec as Me,defineTableRowSpec as Ne,defineTableSpec as Pe}from"@prosekit/extensions/table";import{Decoration as S,DecorationSet as C}from"@prosekit/pm/view";import{closeHistory as Fe}from"@prosekit/pm/history";import{definePlaceholder as Ie}from"@prosekit/extensions/placeholder";import{defineReadonly as Le}from"@prosekit/extensions/readonly";const w=new Map;async function Re(e){let t=_e.matchLanguageName(ve,e,!0);if(!t){w.set(e,null);return}let n=t.support;if(!n)try{n=await t.load()}catch(t){console.error(`[meowdown] Failed to load language "${e}":`,t),w.set(e,null)}if(w.has(e))return;if(!n){w.set(e,null);return}let r=be({parse:e=>n.language.parser.parse(e.content),highlighter:ye});w.set(e,r)}const ze=e=>{let t=e.language?.trim();if(!t)return[];let n=w.get(t);return n?n(e):n===null?[]:Re(t)};function Be(){return ce({parser:ze,nodeTypes:[`codeBlock`]})}function T(e){return ae(ne({type:`heading`,attrs:{level:e}}))}const Ve=(e,t,n)=>te(e,n)?.parent.type.name===`heading`?re()(e,t,n):!1;function He(){return c({"Mod-1":T(1),"Mod-2":T(2),"Mod-3":T(3),"Mod-4":T(4),"Mod-5":T(5),"Mod-6":T(6),Backspace:Ve})}function Ue(){return p(Ce(),Se(),xe(),He())}function We(e){let[t,n,r]=e;return[t,n,r.map(e=>e.toJSON())]}function Ge(e,t){let[n,r,i]=t;return[n,r,i.map(t=>Te.fromJSON(e,t))]}var E=class e extends v{constructor(e){super(),this.chunks=e}apply(e){if(this.chunks.length===0)return y.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 b(e),n.removeMark(i,c,t));for(let t of a)t.isInSet(l)||(n??=new b(e),n.addMark(i,c,t));return!1})}return y.ok(n?n.doc:e)}invert(e){if(this.chunks.length===0)return Ke;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 we(i,a,e.slice(i,a),!1)}map(e){return null}toJSON(){return{stepType:`batchSetMark`,chunks:this.chunks.map(We)}}static fromJSON(t,n){let r=n.chunks;return new e(r.map(e=>Ge(t,e)))}};v.jsonID(`batchSetMark`,E);const Ke=new E([]);function qe(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 Je(e){return e>=65&&e<=90||e>=97&&e<=122||e>127&&/\p{L}/u.test(String.fromCharCode(e))}const Ye={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(!qe(t))break;i||=Je(t),r++}return i?e.addElement(e.elt(`Hashtag`,n,r)):-1}}]},Xe={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 Ze(e){return e.end}const D=De.configure([Ee,Ye,Xe]),Qe=D.configure({parseInline:[{name:`SkipInline`,before:`Escape`,parse:Ze}]});function O(e){return D.parseInline(e,0)}function k(e,t,n=[]){for(let r of e)t(r)&&n.push(r),k(r.children,t,n);return n}function $e(e){let t={};for(let n of e.nodeSet.types)t[n.name]=n.id;return t}const A=$e(D);function et(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}const j=new Map([[A.Emphasis,`mdEm`],[A.StrongEmphasis,`mdStrong`],[A.InlineCode,`mdCode`],[A.Strikethrough,`mdDel`],[A.EmphasisMark,`mdMark`],[A.CodeMark,`mdMark`],[A.LinkMark,`mdMark`],[A.StrikethroughMark,`mdMark`],[A.URL,`mdLinkUri`],[A.Hashtag,`mdTag`],[A.Wikilink,`mdWikilink`],[A.WikilinkMark,`mdMark`]]);function tt(e,t){let n=O(t),r=[];return M(n,[],0,t.length,t,e,r),r}function nt(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))return`https://${e}`}function M(e,t,n,r,i,a,o){let s=n;for(let n of e){if(n.from>s&&N(o,s,n.from,t),n.type===A.Link||n.type===A.Image)rt(n,t,i,a,o);else if(n.type===A.URL){let e=nt(i.slice(n.from,n.to)),r=e?a.mdLinkText.create({href:e}):a.mdLinkUri.create();N(o,n.from,n.to,[...t,r])}else{let e=j.get(n.type),r=e?[...t,a[e].create()]:t;n.children.length===0?N(o,n.from,n.to,r):M(n.children,r,n.from,n.to,i,a,o)}s=n.to}s<r&&N(o,s,r,t)}function rt(e,t,n,r,i){let a=-1,o=null,s=0;for(let t of e.children)t.type===A.LinkMark?(s++,s===2&&(a=t.from)):t.type===A.URL&&o===null&&(o=t);let c=o?n.slice(o.from,o.to):``,l=c?r.mdLinkText.create({href:c}):null,u=e=>a>=0&&e<a&&l!==null,d=e.from;for(let a of e.children){if(a.from>d){let e=u(d)?[...t,l]:t;N(i,d,a.from,e)}let e=u(a.from)?[...t,l]:t,o=j.get(a.type),s=o?[...e,r[o].create()]:e;a.children.length===0?N(i,a.from,a.to,s):M(a.children,s,a.from,a.to,n,r,i),d=a.to}d<e.to&&N(i,d,e.to,t)}function N(e,t,n,r){if(t>=n)return;let i=e.at(-1);if(i&&i[1]===t&&et(i[2],r)){e[e.length-1]=[i[0],n,i[2]];return}e.push([t,n,r])}const it=x(()=>{let e=U().schema;if(e==null)throw Error(`Unexpected empty schema`);return e}),at=x(()=>r(it())),ot=`meowdown_mark_builders`;function st(e){let t=e.cached[ot];if(t)return t;let r=n(e);return e.cached[ot]=r,r}const ct=`inline-marks-applied`,lt=new WeakMap;let ut=0,dt=0;function ft(e,t,n){let r=lt.get(e);if(r?dt++:(ut++,r=tt(st(n),e.textContent),lt.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 pt(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 mt(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=ft(t,r+1,e.schema);return i.length>0&&n.push(...i),!1}),n}function ht(){return new h({key:new g(`inline-mark`),appendTransaction(e,t,n){for(let t of e)if(t.getMeta(ct))return null;let r=mt(n,pt(e,n));if(r.length===0)return null;let i=n.tr.step(new E(r));return i.setMeta(ct,!0),i.setMeta(`addToHistory`,!1),i},view(e){return e.dispatch(gt(e.state)),{}}})}function gt(e){return e.tr.setMeta(`inline-marks-trigger`,!0)}function _t(){return u(ht())}function vt(){return l({name:`mdMark`,inclusive:!1,toDOM:()=>[`span`,{class:`md-mark`},0],parseDOM:[{tag:`span.md-mark`}]})}function yt(){return l({name:`mdEm`,toDOM:()=>[`em`,0],parseDOM:[{tag:`em`}]})}function bt(){return l({name:`mdStrong`,toDOM:()=>[`strong`,0],parseDOM:[{tag:`strong`}]})}function xt(){return l({name:`mdCode`,toDOM:()=>[`code`,0],parseDOM:[{tag:`code`}]})}function St(){return l({name:`mdLinkText`,inclusive:!1,attrs:{href:{default:``}},toDOM:e=>[`a`,{href:e.attrs.href},0],parseDOM:[{tag:`a`,getAttrs:e=>({href:e.getAttribute(`href`)??``})}]})}function Ct(){return l({name:`mdLinkUri`,inclusive:!1,toDOM:()=>[`span`,{class:`md-link-uri`},0],parseDOM:[{tag:`span.md-link-uri`}]})}function wt(){return l({name:`mdDel`,toDOM:()=>[`del`,0],parseDOM:[{tag:`del`}]})}function Tt(){return l({name:`mdTag`,toDOM:()=>[`span`,{class:`md-tag`},0],parseDOM:[{tag:`span.md-tag`}]})}function Et(){return l({name:`mdWikilink`,inclusive:!1,toDOM:()=>[`span`,{class:`md-wikilink`},0],parseDOM:[{tag:`span.md-wikilink`}]})}function Dt(){return p(vt(),yt(),bt(),xt(),St(),Ct(),wt(),Tt(),Et())}function P(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 F={em:{node:A.Emphasis,delim:`*`},strong:{node:A.StrongEmphasis,delim:`**`},code:{node:A.InlineCode,delim:"`"},del:{node:A.Strikethrough,delim:`~~`}},Ot=new Set([A.EmphasisMark,A.CodeMark,A.LinkMark,A.StrikethroughMark]);function I(e){return[e.children[0],e.children.at(-1)]}function L(e){let{type:t,children:n}=e;if(t===A.Emphasis||t===A.StrongEmphasis||t===A.Strikethrough)return[n[0].to,n.at(-1).from];if(t===A.Link||t===A.Image){let e=n.find((e,t)=>t>0&&e.type===A.LinkMark);return e?[n[0].to,e.from]:null}return null}function R(e,t,n){for(let r of e){if(r.to<=t||r.from>=n||t<=r.from&&r.to<=n)continue;let i=L(r);return i&&i[0]<=t&&n<=i[1]?R(r.children,t,n):R(e,Math.min(t,r.from),Math.max(n,r.to))}return[t,n]}function z(e,t,n){for(let r of e)if(!(r.to<=t||r.from>=n)&&(t>r.from||r.to>n))return z(e,Math.min(t,r.from),Math.max(n,r.to));return[t,n]}const B=e=>e===` `||e===` `;function kt(e,t,n){for(;t<n&&B(e[t]);)t++;for(;n>t&&B(e[n-1]);)n--;return[t,n]}function At(e,t,n,r){let i=k(O(e),e=>e.type===r.node||Ot.has(e.type));for(let r=t;r<n;r++)if(!B(e[r])&&i.every(e=>!(e.from<=r&&r<e.to)))return!1;return!0}function jt(e,t,n,r,i){let a=O(e),o=k(a,e=>e.type===r.node);return i?Pt(e,o,t,n):Mt(e,a,o,t,n,r)}function Mt(e,t,n,r,i,a){for(let e=0;e!==i-r;){e=i-r,[r,i]=R(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]=I(e);o.push({from:t.from,to:t.to,insert:``}),o.push({from:n.from,to:n.to,insert:``})}let[s,c]=Nt(e,r,i,o,a);return o.push({from:r,to:r,insert:s},{from:i,to:i,insert:c}),o}function Nt(e,t,n,r,i){if(i.node!==A.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(P(a)+1),s=a.startsWith("`")||a.endsWith("`")?` `:``;return[o+s,s+o]}function Pt(e,t,n,r){let i=[];for(let a of t){if(a.to<=n||a.from>=r)continue;let[t,o]=I(a),s=Math.max(n,t.to),c=Math.min(r,o.from);for(s>=c&&([s,c]=[t.to,o.from]),[s,c]=z(a.children.slice(1,-1),s,c);s>t.to&&B(e[s-1]);)s--;for(;c<o.from&&B(e[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 Ft(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=O(e),o=k(a,e=>e.type===n.node).findLast(e=>e.from<=t&&t<=e.to);if(o){let[e,n]=I(o);return{kind:`move`,pos:t===o.from?e.to:t===o.to?n.from:o.to}}return V(a,t)||e[t-1]===r[0]||e[t]===r[0]?null:{kind:`insert`,pos:t}}function V(e,t){for(let n of e)if(n.from<t&&t<n.to){let e=L(n);return!e||t<e[0]||t>e[1]?!0:V(n.children,t)}return!1}function H(e){return(t,n)=>{if(t.selection.empty)return It(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]=kt(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:At(a,c,l,e)}),!1});let c=s.length>0&&s.every(e=>e.active),l=s.filter(e=>c||!e.active).flatMap(t=>jt(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(_.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 It(e,t,n){let{$from:r}=t.selection,i=r.parent;if(!i.isTextblock||i.type.spec.code)return!1;let a=Ft(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(_.create(o.doc,i+a.pos)),a.kind===`insert`&&(o.insertText(e.delim+e.delim,i+a.pos),o.setSelection(_.create(o.doc,i+a.pos+e.delim.length))),n(o.scrollIntoView())}return!0}function Lt(){return o({toggleEm:()=>H(F.em),toggleStrong:()=>H(F.strong),toggleCode:()=>H(F.code),toggleDel:()=>H(F.del)})}function Rt(){return c({"Mod-b":H(F.strong),"Mod-i":H(F.em),"Mod-e":H(F.code),"Mod-Shift-x":H(F.del)})}function zt(){return p(Lt(),Rt())}function Bt(){return p(Pe(),Ne(),Oe(),Me(),je({allowTableNodeSelection:!0}),ke(),Ae())}function Vt(){return p(me(),le(),he(),oe(),fe(),Ue(),Bt(),se(),de(),Dt(),Be(),_t(),zt(),a(),i(),s(),ue(),ge(),pe())}function U(){return Vt()}const Ht=new Set([`mdStrong`,`mdEm`,`mdCode`,`mdDel`,`mdLinkText`,`mdLinkUri`,`mdWikilink`]),Ut=new Set([`mdMark`,`mdLinkUri`]),Wt=new Set([`mdMark`,`mdLinkUri`]),W=new Set([`mdLinkText`,`mdLinkUri`]),Gt=new Set([`mdStrong`,`mdEm`,`mdCode`,`mdDel`,`mdWikilink`]);function Kt(e){return new h({key:new g(`mark-mode`),props:{attributes:{"data-mark-mode":e},decorations:e===`focus`?e=>Yt(e):void 0,clipboardTextSerializer:e===`show`?void 0:Jt}})}function qt(e){return u(Kt(e))}function Jt(e){let t=[];return e.content.forEach(e=>{let n=[];e.descendants(e=>!e.isText||!e.text?!0:(e.marks.some(e=>Wt.has(e.type.name))||n.push(e.text),!1)),t.push(n.join(``))}),t.join(`
2
+ `)}function Yt(e){let{$anchor:t,empty:n}=e.selection;if(!n)return C.empty;let r=t.parent;if(!r.isTextblock)return null;let i=t.start(),a=t.parentOffset,o=Xt(r,a);if(o.size===0)return C.empty;let s=[],c=new Set,l=!1;for(let e of o)if(W.has(e)){if(l)continue;l=!0,Qt(r,i,a,s,c)}else Zt(r,i,e,a,s,c);let u=s.map(([e,t])=>S.inline(e,t,{class:`show`}));return C.create(e.doc,u)}function Xt(e,t){let n=new Set,r=0;return e.forEach(e=>{let i=r+e.nodeSize;if(t>=r&&t<=i)for(let t of e.marks){let e=t.type.name;Ht.has(e)&&n.add(e)}r=i}),n}function Zt(e,t,n,r,i,a){let o=t,s=0,c=-1,l=-1;e.forEach(u=>{let d=u.marks.some(e=>e.type.name===n);d&&c===-1&&(c=o,l=s),!d&&c!==-1&&(r>=l&&r<=s&&K(e,t,c,o,i,a),c=-1,l=-1),o+=u.nodeSize,s+=u.nodeSize}),c!==-1&&r>=l&&r<=s&&K(e,t,c,o,i,a)}function Qt(e,t,n,r,i){let a=e.childCount;if(a===0)return;let o=-1,s=0;for(let t=0;t<a;t++){let r=e.child(t),i=s+r.nodeSize;if(n>=s&&n<=i&&r.marks.some(e=>W.has(e.type.name))){o=t;break}s=i}if(o===-1)return;let c=o;for(;c>0&&G(e.child(c-1));)c--;let l=o;for(;l<a-1&&G(e.child(l+1));)l++;let u=t;for(let t=0;t<c;t++)u+=e.child(t).nodeSize;let d=u;for(let t=c;t<=l;t++)d+=e.child(t).nodeSize;K(e,t,u,d,r,i)}function G(e){let t=!1,n=!1,r=!1;for(let i of e.marks){let e=i.type.name;e===`mdMark`?t=!0:W.has(e)?n=!0:Gt.has(e)&&(r=!0)}return!!(n||t&&!r)}function K(e,t,n,r,i,a){let o=t;e.forEach(e=>{let t=o,s=o+e.nodeSize;if(t>=n&&s<=r)for(let n of e.marks){let e=n.type.name;if(Ut.has(e)){let e=`${t}_${s}`;a.has(e)||(a.add(e),i.push([t,s]));break}}o=s})}const $t=new g(`meowdown-wikilink-click`);function en(e,t){let n=d(e.schema,`mdWikilink`),r=e.doc.resolve(t),i=r.parent;if(!i.isTextblock||i.type.spec.code)return;let a=r.start(),o=-1,s=-1,c,l=0;if(i.forEach(e=>{let r=a+l;l+=e.nodeSize;let i=a+l;n.isInSet(e.marks)?(o<0&&(o=r),s=i):(o>=0&&o<=t&&t<=s&&(c={from:o,to:s}),o=-1)}),o>=0&&o<=t&&t<=s&&(c={from:o,to:s}),c)return{from:c.from,to:c.to,target:tn(e.doc.textBetween(c.from,c.to))}}function tn(e){let t=e.replace(/^\[\[/u,``).replace(/\]\]$/u,``),n=t.indexOf(`|`);return(n>=0?t.slice(0,n):t).trim()}function nn(e){let t;return u(new h({key:$t,props:{handleDOMEvents:{mousedown:e=>{let{from:n,to:r,empty:i}=e.state.selection;return t={from:n,to:r,empty:i},!1}},handleClick:(n,r,i)=>{if(!i.target?.closest?.(`.md-wikilink`))return!1;let a=en(n.state,r);return!a||!(ee?i.metaKey:i.ctrlKey)&&t?.empty&&t.from>=a.from&&t.to<=a.to?!1:(e({target:a.target,event:i}),!0)}}}))}function rn(e){let t=[],n=k(O(e),e=>e.type===A.Image);for(let r of n){let n=r.children.find(e=>e.type===A.URL),i=r.children.filter(e=>e.type===A.LinkMark);!n||i.length<2||t.push({from:r.from,to:r.to,alt:e.slice(i[0].to,i[1].from),src:e.slice(n.from,n.to)})}return t}function an(){return typeof window>`u`?!1:window.matchMedia(`(prefers-color-scheme: dark)`).matches}const on=/^(?:www\.|mobile\.)?(?:twitter\.com|x\.com)$/i,sn=/\/status(?:es)?\/(\d+)/;function cn(e){let t;try{t=new URL(e)}catch{return}if(on.test(t.hostname))return sn.exec(t.pathname)?.[1]}const ln=e=>{let t=cn(e);if(t)return{key:`tweet:${t}`,render:()=>{let e=an()?`dark`:`light`,n=document.createElement(`iframe`);return n.src=`https://platform.twitter.com/embed/Tweet.html?id=${t}&theme=${e}&dnt=true`,n.title=`Tweet`,n.className=`md-embed md-embed-tweet`,n.dataset.testid=`tweet-embed`,n.loading=`lazy`,n.referrerPolicy=`strict-origin-when-cross-origin`,n.setAttribute(`frameborder`,`0`),un(n),n}}};function un(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=new MutationObserver(()=>{e.isConnected||(window.removeEventListener(`message`,t),n.disconnect())});n.observe(document.body,{childList:!0,subtree:!0})}const dn=/^(?:www\.|m\.)?(?:youtube\.com|youtube-nocookie\.com)$/i,fn=/^(?:www\.)?youtu\.be$/i,pn=/^[\w-]{11}$/;function mn(e){let t;try{t=new URL(e)}catch{return}let n=null;if(fn.test(t.hostname))n=t.pathname.slice(1);else if(dn.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||!pn.test(n))return;let r=t.searchParams.get(`start`)??t.searchParams.get(`t`),i=r?hn(r):void 0;return{videoId:n,startSeconds:i}}function hn(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 gn=[e=>{let t=mn(e);if(!t)return;let n=t.startSeconds?`?start=${t.startSeconds}`:``;return{key:`youtube:${t.videoId}:${t.startSeconds??0}`,render:()=>{let e=document.createElement(`iframe`);return e.src=`https://www.youtube-nocookie.com/embed/${t.videoId}${n}`,e.title=`YouTube video`,e.className=`md-embed md-embed-youtube`,e.dataset.testid=`youtube-embed`,e.loading=`lazy`,e.referrerPolicy=`strict-origin-when-cross-origin`,e.setAttribute(`frameborder`,`0`),e.allow=`accelerometer; autoplay; clipboard-write; encrypted-media; gyroscope; picture-in-picture; web-share; fullscreen`,e.allowFullscreen=!0,e}}},ln];function q(e){for(let t of gn){let n=t(e);if(n)return n}}const J=new g(`meowdown-images`);function _n(e){let t=[];return e.doc.descendants((e,n)=>{if(e.type.spec.code)return!1;if(!e.isTextblock)return!0;if(e.childCount===0)return!1;let r=!0;if(e.forEach(e=>{e.isText||(r=!1)}),!r)return!1;for(let r of rn(e.textContent))t.push({widgetAt:n+e.nodeSize-1,alt:r.alt,src:r.src});return!1}),t}function Y(e,t){let n=[];for(let r of _n(e)){let e=q(r.src);if(e){n.push(vn(r,e));continue}let i=t.resolveImageUrl(r.src);i&&n.push(yn(r,i))}return C.create(e.doc,n)}function vn(e,t){return S.widget(e.widgetAt,()=>{let e=document.createElement(`div`);return e.className=`md-embed-wrapper`,e.contentEditable=`false`,e.appendChild(t.render()),e},{key:`md-embed:${t.key}`,side:1})}function yn(e,t){return S.widget(e.widgetAt,()=>{let n=document.createElement(`div`);n.className=`md-image`,n.contentEditable=`false`;let r=document.createElement(`img`);return r.src=t,r.alt=e.alt,r.draggable=!1,n.appendChild(r),n},{key:`md-image:${t}`,side:1})}function bn(e){return new h({key:J,state:{init:(t,n)=>Y(n,e),apply:(t,n,r,i)=>t.docChanged?Y(i,e):n},props:{decorations:e=>J.getState(e)}})}function xn(e){return e?Array.from(e.files).filter(e=>e.type.startsWith(`image/`)):[]}const Sn=e=>{console.error(`[meowdown] failed to save pasted image:`,e)};async function Cn(e,t,n,r=Sn,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 wn(e){return new h({props:{handlePaste:(t,n)=>{let r=xn(n.clipboardData),{onImagePaste:i,onImageSaveError:a}=e;return r.length===0||!i?!1:(Cn(t,r,i,a),!0)},handleDrop:(t,n)=>{let r=xn(n.dataTransfer),{onImagePaste:i,onImageSaveError:a}=e;return r.length===0||!i?!1:(Cn(t,r,i,a,t.posAtCoords({left:n.clientX,top:n.clientY})?.pos),!0)}}})}function Tn(e){return p(u(bn(e)),m(u(wn(e)),t.high))}const En=new g(`meowdown-embed-paste`);function Dn(e){let t=e.trim();if(!(!t||/\s/.test(t)))return q(t)?t:void 0}function On(e,t){let{from:n,to:r}=e.state.selection;e.dispatch(Fe(e.state.tr.insertText(t,n,r)));let i=e.state.tr.insertText(`![](${t})`,n,n+t.length);e.dispatch(Fe(i))}function kn(){return u(new h({key:En,props:{handlePaste:(e,t)=>{let n=e.state.selection.$from.parent;if(!n.inlineContent||n.type.spec.code)return!1;let r=t.clipboardData?.getData(`text/plain`);if(!r)return!1;let i=Dn(r);return i?(On(e,i),!0):!1}}}))}const An=(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=f(e.schema,`list`),i=f(e.schema,`paragraph`),a=r.create({kind:`bullet`},i.create()),o=n.after(),s=e.tr.insert(o,a);s.setSelection(_.create(s.doc,o+2)),t(s.scrollIntoView())}return!0};function jn(){return m(c({Enter:An}),t.high)}const Mn={"Mod-b":`Bold`,"Mod-i":`Italic`,"Mod-e":`Inline code`,"Mod-Shift-x":`Strikethrough`,"Mod-1":`Heading 1`,"Mod-2":`Heading 2`,"Mod-3":`Heading 3`,"Mod-4":`Heading 4`,"Mod-5":`Heading 5`,"Mod-6":`Heading 6`},Nn=new Set([`MscGen`,`Xù`,`MsGenny`,`Angular Template`]),Pn=ve.map(e=>e.name).filter(e=>!Nn.has(e)).map(e=>({label:e,value:e.toLowerCase()})).concat({label:`Plain text`,value:``}).sort((e,t)=>e.label.localeCompare(t.label));function Fn(e){let t=new Ln;return Rn(e,t),t.finish()}const In=[``,`# `,`## `,`### `,`#### `,`##### `,`###### `];var Ln=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(`
3
3
  `)){this.parts.push(e);return}let t=e.split(`
4
4
  `);for(let e=0;e<t.length;e++)e>0&&this.parts.push(`
5
5
  `,this.linePrefix),t[e]!==``&&this.parts.push(t[e])}closeBlock(){this.atLineStart||this.parts.push(`
6
6
  `),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=i}finish(){return this.parts.join(``).replace(/\s+$/,``)+`
7
7
  `}emitDeferredBlankLine(){let e=this.deferredBlankPrefix;e!==null&&(this.parts.push(e.trimEnd(),`
8
- `),this.deferredBlankPrefix=null)}};function Mn(e,t){switch(e.type.name){case`doc`:Z(e,t);return;case`paragraph`:Fn(e,t),t.closeBlock();return;case`heading`:{let n=e.attrs.level;t.write(An[n]??`# `),Fn(e,t),t.closeBlock();return}case`blockquote`:t.withPrefix(`> `,`> `,()=>Z(e,t)),t.closeBlock();return;case`list`:In(e,t,Pn(e));return;case`codeBlock`:Ln(e,t);return;case`horizontalRule`:t.write(`---`),t.closeBlock();return;case`table`:Rn(e,t);return;case`text`:e.text&&t.write(e.text);return}}function Z(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(),Mn(a,t),i++;continue}let o=i+1;for(;o<r&&e.child(o).type.name===`list`;)o++;let s=Nn(e,i,o);for(let r=i;r<o;r++)(r===i?n&&i>0:s)&&t.suppressBlank(),In(e.child(r),t,s);i=o}}function Nn(e,t,n){for(let r=t;r<n;r++)if(!Pn(e.child(r)))return!1;return!0}function Pn(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 Fn(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 In(e,t,n){let r=e.attrs,i=r.kind===`ordered`?`${r.order??1}. `:r.kind===`task`?r.checked?`- [x] `:`- [ ] `:`- `,a=` `.repeat(r.kind===`task`?2:i.length);t.withPrefix(a,i,()=>Z(e,t,n)),t.closeBlock()}function Ln(e,t){let n=e.attrs.language??``,r=e.textContent,i="`".repeat(Tt(r,2)+1);t.write(i),n&&t.write(n),t.write(`
8
+ `),this.deferredBlankPrefix=null)}};function Rn(e,t){switch(e.type.name){case`doc`:X(e,t);return;case`paragraph`:Vn(e,t),t.closeBlock();return;case`heading`:{let n=e.attrs.level;t.write(In[n]??`# `),Vn(e,t),t.closeBlock();return}case`blockquote`:t.withPrefix(`> `,`> `,()=>X(e,t)),t.closeBlock();return;case`list`:Hn(e,t,Bn(e));return;case`codeBlock`:Un(e,t);return;case`horizontalRule`:t.write(`---`),t.closeBlock();return;case`table`:Wn(e,t);return;case`text`:e.text&&t.write(e.text);return}}function X(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(),Rn(a,t),i++;continue}let o=i+1;for(;o<r&&e.child(o).type.name===`list`;)o++;let s=zn(e,i,o);for(let r=i;r<o;r++)(r===i?n&&i>0:s)&&t.suppressBlank(),Hn(e.child(r),t,s);i=o}}function zn(e,t,n){for(let r=t;r<n;r++)if(!Bn(e.child(r)))return!1;return!0}function Bn(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 Vn(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 Hn(e,t,n){let r=e.attrs,i=r.kind===`ordered`?`${r.order??1}. `:r.kind===`task`?r.checked?`- [x] `:`- [ ] `:`- `,a=` `.repeat(r.kind===`task`?2:i.length);t.withPrefix(a,i,()=>X(e,t,n)),t.closeBlock()}function Un(e,t){let n=e.attrs.language??``,r=e.textContent,i="`".repeat(P(r,2)+1);t.write(i),n&&t.write(n),t.write(`
9
9
  `),t.write(r),t.write(`
10
- `),t.write(i),t.closeBlock()}function Rn(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(Bn(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(zn(s,i)),t.write(`
10
+ `),t.write(i),t.closeBlock()}function Wn(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(Kn(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(Gn(s,i)),t.write(`
11
11
  `),t.write(o);for(let e=0;e<n;e++)e!==a&&(t.write(`
12
- `),t.write(zn(r[e],i)));t.closeBlock()}function zn(e,t){let n=`|`;for(let r=0;r<t;r++)n+=` `+(e[r]??``)+` |`;return n}function Bn(e){let t=e.textContent.trim();return!t.includes(`|`)&&!t.includes(`
12
+ `),t.write(Gn(r[e],i)));t.closeBlock()}function Gn(e,t){let n=`|`;for(let r=0;r<t;r++)n+=` `+(e[r]??``)+` |`;return n}function Kn(e){let t=e.textContent.trim();return!t.includes(`|`)&&!t.includes(`
13
13
  `)?t:t.replaceAll(`|`,String.raw`\|`).replaceAll(`
14
- `,` `)}function Vn(e,t=at()){let n=Hn(t,Qe.parse(e).cursor(),e);return t.doc(n)}function Hn(e,t,n){let r=[];if(!t.firstChild())return r;do r.push(...Q(e,t,n));while(t.nextSibling());return t.parent(),r}function Q(e,t,n){switch(t.type.id){case D.ATXHeading1:return[$(e,t,n,1)];case D.ATXHeading2:return[$(e,t,n,2)];case D.ATXHeading3:return[$(e,t,n,3)];case D.ATXHeading4:return[$(e,t,n,4)];case D.ATXHeading5:return[$(e,t,n,5)];case D.ATXHeading6:return[$(e,t,n,6)];case D.SetextHeading1:return[$(e,t,n,1)];case D.SetextHeading2:return[$(e,t,n,2)];case D.Paragraph:return[Un(e,t,n)];case D.Blockquote:return[Wn(e,t,n)];case D.BulletList:return Gn(e,t,n,`bullet`,1);case D.OrderedList:return Kn(e,t,n);case D.FencedCode:case D.CodeBlock:return[Yn(e,t,n)];case D.HorizontalRule:return[e.horizontalRule()];case D.Table:return[Xn(e,t,n)];case D.Task:return[Un(e,t,n)];default:return[]}}function $(e,t,n,r){let i=t.from,a=t.to;if(t.firstChild()){t.type.id===D.HeaderMark&&(i=t.to);let e=-1,n=-1;do e=t.type.id,n=t.from;while(t.nextSibling());e===D.HeaderMark&&n>i&&(a=n),t.parent()}let o=n.slice(i,a).trim();return e.heading({level:r},o)}function Un(e,t,n){let r=n.slice(t.from,t.to);return e.paragraph(r)}function Wn(e,t,n){let r=[];if(t.firstChild()){do{if(t.type.id===D.QuoteMark)continue;r.push(...Q(e,t,n))}while(t.nextSibling());t.parent()}return e.blockquote(r)}function Gn(e,t,n,r,i){let a=[];if(t.firstChild()){do t.type.id===D.ListItem&&a.push(qn(e,t,n,r,i));while(t.nextSibling());t.parent()}return a}function Kn(e,t,n){let r=1;if(t.firstChild()){if(t.type.id===D.ListItem&&t.firstChild()){if(t.type.id===D.ListMark){let e=n.slice(t.from,t.to),i=Number.parseInt(e,10);Number.isFinite(i)&&(r=i)}t.parent()}t.parent()}return Gn(e,t,n,`ordered`,r)}function qn(e,t,n,r,i){let a=[],o=null;if(t.firstChild()){do{if(t.type.id===D.ListMark)continue;if(r===`bullet`&&t.type.id===D.Task){let r=Jn(e,t,n);o=r.checked,a.push(r.paragraph);continue}a.push(...Q(e,t,n))}while(t.nextSibling());t.parent()}return e.list({kind:o===null?r:`task`,order:r===`ordered`?i:null,checked:o??!1,collapsed:!1},a)}function Jn(e,t,n){let r=!1,i=t.from,a=t.to;t.firstChild()&&(t.type.id===D.TaskMarker&&(r=n.slice(t.from,t.to).toLowerCase().includes(`x`),i=t.to),t.parent());let o=n.slice(i,a);return o.startsWith(` `)&&(o=o.slice(1)),{checked:r,paragraph:o===``?e.paragraph():e.paragraph(o)}}function Yn(e,t,n){let r=``,i=``;if(t.firstChild()){do switch(t.type.id){case D.CodeInfo:r=n.slice(t.from,t.to);break;case D.CodeText:i=n.slice(t.from,t.to);break}while(t.nextSibling());t.parent()}return e.codeBlock({language:r},i)}function Xn(e,t,n){let r=0;if(t.firstChild()){do t.type.id===D.TableDelimiter&&(r=Zn(n.slice(t.from,t.to)));while(t.nextSibling());t.parent()}let i=[];if(t.firstChild()){do{let a=t.type.id;a===D.TableHeader?i.push(Qn(e,t,n,!0,r)):a===D.TableRow&&i.push(Qn(e,t,n,!1,r))}while(t.nextSibling());t.parent()}return e.table(i)}function Zn(e){return e.split(`|`).filter(e=>e.trim()!==``).length}function Qn(e,t,n,r,i){let a=Array(i).fill(``);if(t.firstChild()){let e=t.type.id===D.TableDelimiter,r=0;do if(t.type.id===D.TableDelimiter)r++;else if(t.type.id===D.TableCell){let o=r-+!!e;o>=0&&o<i&&(a[o]=n.slice(t.from,t.to).trim())}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 $n(e){return e.replace(/\n+$/u,``)}function er(e){return e.split(`
15
- `).filter(e=>e.trim()!==``)}function tr(e){let t=kn(Vn(e));if($n(t)===$n(e))return`exact`;let n=er(e),r=er(t);return n.length===r.length&&n.every((e,t)=>e===r[t])?`normalizing`:`lossy`}export{En as EDITOR_KEY_BINDINGS,tr as checkRoundTrip,On as codeBlockLanguages,H as defineEditorExtension,Tn as defineEmbedPaste,xn as defineImages,Gt as defineMarkMode,Ie as definePlaceholder,Le as defineReadonly,en as defineWikilinkClickHandler,kn as docToMarkdown,Vn as markdownToDoc};
14
+ `,` `)}function qn(e,t=at()){let n=Jn(t,Qe.parse(e).cursor(),e);return t.doc(n)}function Jn(e,t,n){let r=[];if(!t.firstChild())return r;do r.push(...Z(e,t,n));while(t.nextSibling());return t.parent(),r}function Z(e,t,n){switch(t.type.id){case A.ATXHeading1:return[Q(e,t,n,1)];case A.ATXHeading2:return[Q(e,t,n,2)];case A.ATXHeading3:return[Q(e,t,n,3)];case A.ATXHeading4:return[Q(e,t,n,4)];case A.ATXHeading5:return[Q(e,t,n,5)];case A.ATXHeading6:return[Q(e,t,n,6)];case A.SetextHeading1:return[Q(e,t,n,1)];case A.SetextHeading2:return[Q(e,t,n,2)];case A.Paragraph:return[$(e,t,n)];case A.Blockquote:return[Yn(e,t,n)];case A.BulletList:return Xn(e,t,n,`bullet`,1);case A.OrderedList:return Zn(e,t,n);case A.FencedCode:case A.CodeBlock:return[er(e,t,n)];case A.HorizontalRule:return[e.horizontalRule()];case A.Table:return[tr(e,t,n)];case A.Task:return[$(e,t,n)];default:return[]}}function Q(e,t,n,r){let i=t.from,a=t.to;if(t.firstChild()){t.type.id===A.HeaderMark&&(i=t.to);let e=-1,n=-1;do e=t.type.id,n=t.from;while(t.nextSibling());e===A.HeaderMark&&n>i&&(a=n),t.parent()}let o=n.slice(i,a).trim();return e.heading({level:r},o)}function $(e,t,n){let r=n.slice(t.from,t.to);return e.paragraph(r)}function Yn(e,t,n){let r=[];if(t.firstChild()){do{if(t.type.id===A.QuoteMark)continue;r.push(...Z(e,t,n))}while(t.nextSibling());t.parent()}return e.blockquote(r)}function Xn(e,t,n,r,i){let a=[];if(t.firstChild()){do t.type.id===A.ListItem&&a.push(Qn(e,t,n,r,i));while(t.nextSibling());t.parent()}return a}function Zn(e,t,n){let r=1;if(t.firstChild()){if(t.type.id===A.ListItem&&t.firstChild()){if(t.type.id===A.ListMark){let e=n.slice(t.from,t.to),i=Number.parseInt(e,10);Number.isFinite(i)&&(r=i)}t.parent()}t.parent()}return Xn(e,t,n,`ordered`,r)}function Qn(e,t,n,r,i){let a=[],o=null;if(t.firstChild()){do{if(t.type.id===A.ListMark)continue;if(r===`bullet`&&t.type.id===A.Task){let r=$n(e,t,n);o=r.checked,a.push(r.paragraph);continue}a.push(...Z(e,t,n))}while(t.nextSibling());t.parent()}return e.list({kind:o===null?r:`task`,order:r===`ordered`?i:null,checked:o??!1,collapsed:!1},a)}function $n(e,t,n){let r=!1,i=t.from,a=t.to;t.firstChild()&&(t.type.id===A.TaskMarker&&(r=n.slice(t.from,t.to).toLowerCase().includes(`x`),i=t.to),t.parent());let o=n.slice(i,a);return o.startsWith(` `)&&(o=o.slice(1)),{checked:r,paragraph:o===``?e.paragraph():e.paragraph(o)}}function er(e,t,n){let r=``,i=``;if(t.firstChild()){do switch(t.type.id){case A.CodeInfo:r=n.slice(t.from,t.to);break;case A.CodeText:i=n.slice(t.from,t.to);break}while(t.nextSibling());t.parent()}return e.codeBlock({language:r},i)}function tr(e,t,n){let r=0;if(t.firstChild()){do t.type.id===A.TableDelimiter&&(r=nr(n.slice(t.from,t.to)));while(t.nextSibling());t.parent()}let i=[];if(t.firstChild()){do{let a=t.type.id;a===A.TableHeader?i.push(rr(e,t,n,!0,r)):a===A.TableRow&&i.push(rr(e,t,n,!1,r))}while(t.nextSibling());t.parent()}return e.table(i)}function nr(e){return e.split(`|`).filter(e=>e.trim()!==``).length}function rr(e,t,n,r,i){let a=Array(i).fill(``);if(t.firstChild()){let e=t.type.id===A.TableDelimiter,r=0;do if(t.type.id===A.TableDelimiter)r++;else if(t.type.id===A.TableCell){let o=r-+!!e;o>=0&&o<i&&(a[o]=n.slice(t.from,t.to).trim())}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 ir(e){return e.replace(/\n+$/u,``)}function ar(e){return e.split(`
15
+ `).filter(e=>e.trim()!==``)}function or(e){let t=Fn(qn(e));if(ir(t)===ir(e))return`exact`;let n=ar(e),r=ar(t);return n.length===r.length&&n.every((e,t)=>e===r[t])?`normalizing`:`lossy`}export{Mn as EDITOR_KEY_BINDINGS,e as Priority,or as checkRoundTrip,Pn as codeBlockLanguages,jn as defineBulletAfterHeading,U as defineEditorExtension,kn as defineEmbedPaste,Tn as defineImages,qt as defineMarkMode,Ie as definePlaceholder,Le as defineReadonly,nn as defineWikilinkClickHandler,Fn as docToMarkdown,qn as markdownToDoc,ie as withPriority};
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@meowdown/core",
3
3
  "type": "module",
4
- "version": "0.9.0",
4
+ "version": "0.11.0",
5
5
  "license": "MIT",
6
6
  "repository": {
7
7
  "type": "git",
@@ -31,11 +31,11 @@
31
31
  "devDependencies": {
32
32
  "@ocavue/tsconfig": "^0.7.1",
33
33
  "@tsdown/css": "^0.22.2",
34
- "@vitest/browser-playwright": "^4.1.8",
34
+ "@vitest/browser-playwright": "^4.1.9",
35
35
  "dedent": "^1.7.2",
36
36
  "diffable-html-snapshot": "^0.2.0",
37
37
  "tsdown": "^0.22.2",
38
- "vitest": "^4.1.8"
38
+ "vitest": "^4.1.9"
39
39
  },
40
40
  "publishConfig": {
41
41
  "access": "public"