@meowdown/core 0.9.0 → 0.10.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 +2 -0
- package/dist/index.d.ts +9 -1
- package/dist/index.js +7 -7
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -61,6 +61,8 @@ Inline images (``) 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 `` 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
|
+
|
|
64
66
|
## License
|
|
65
67
|
|
|
66
68
|
MIT
|
package/dist/index.d.ts
CHANGED
|
@@ -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, type RoundTripFidelity, type TypedEditor, type WikilinkClickHandler, type WikilinkClickPayload, checkRoundTrip, codeBlockLanguages, defineBulletAfterHeading, defineEditorExtension, defineEmbedPaste, defineImages, defineMarkMode, definePlaceholder, defineReadonly, defineWikilinkClickHandler, docToMarkdown, markdownToDoc };
|
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
|
|
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,getNodeType as d,isApple as ee,isAtBlockStart as te,toggleNode as ne,union as f,unsetBlockType as re,withPriority as p,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 m}from"@codemirror/language-data";import{classHighlighter as _e}from"@lezer/highlight";import{createParser as ve}from"prosemirror-highlight/lezer";import{defineHeadingCommands as ye,defineHeadingInputRule as be,defineHeadingSpec as xe}from"@prosekit/extensions/heading";import{Plugin as h,PluginKey as g,TextSelection as _}from"@prosekit/pm/state";import{ReplaceStep as Se,Step as v,StepResult as y,Transform as b}from"@prosekit/pm/transform";import{Mark as Ce}from"@prosekit/pm/model";import{GFM as we,parser as Te}from"@lezer/markdown";import{once as x}from"@ocavue/utils";import{defineTableCellSpec as Ee,defineTableCommands as De,defineTableDropIndicator as Oe,defineTableEditingPlugin as ke,defineTableHeaderCellSpec as Ae,defineTableRowSpec as je,defineTableSpec as Me}from"@prosekit/extensions/table";import{Decoration as S,DecorationSet as C}from"@prosekit/pm/view";import{closeHistory as Ne}from"@prosekit/pm/history";import{definePlaceholder as Pe}from"@prosekit/extensions/placeholder";import{defineReadonly as Fe}from"@prosekit/extensions/readonly";const w=new Map;async function Ie(e){let t=ge.matchLanguageName(m,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=ve({parse:e=>n.language.parser.parse(e.content),highlighter:_e});w.set(e,r)}const Le=e=>{let t=e.language?.trim();if(!t)return[];let n=w.get(t);return n?n(e):n===null?[]:Ie(t)};function Re(){return se({parser:Le,nodeTypes:[`codeBlock`]})}function T(e){return ie(ne({type:`heading`,attrs:{level:e}}))}const ze=(e,t,n)=>te(e,n)?.parent.type.name===`heading`?re()(e,t,n):!1;function Be(){return s({"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:ze})}function Ve(){return f(xe(),be(),ye(),Be())}function He(e){let[t,n,r]=e;return[t,n,r.map(e=>e.toJSON())]}function Ue(e,t){let[n,r,i]=t;return[n,r,i.map(t=>Ce.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 We;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 Se(i,a,e.slice(i,a),!1)}map(e){return null}toJSON(){return{stepType:`batchSetMark`,chunks:this.chunks.map(He)}}static fromJSON(t,n){let r=n.chunks;return new e(r.map(e=>Ue(t,e)))}};v.jsonID(`batchSetMark`,E);const We=new E([]);function Ge(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 Ke(e){return e>=65&&e<=90||e>=97&&e<=122||e>127&&/\p{L}/u.test(String.fromCharCode(e))}const qe={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(!Ge(t))break;i||=Ke(t),r++}return i?e.addElement(e.elt(`Hashtag`,n,r)):-1}}]},Je={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 Ye(e){return e.end}const D=Te.configure([we,qe,Je]),Xe=D.configure({parseInline:[{name:`SkipInline`,before:`Escape`,parse:Ye}]});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 Ze(e){let t={};for(let n of e.nodeSet.types)t[n.name]=n.id;return t}const A=Ze(D);function Qe(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 $e(e,t){let n=O(t),r=[];return M(n,[],0,t.length,t,e,r),r}function et(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)tt(n,t,i,a,o);else if(n.type===A.URL){let e=et(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 tt(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&&Qe(i[2],r)){e[e.length-1]=[i[0],n,i[2]];return}e.push([t,n,r])}const nt=x(()=>{let e=U().schema;if(e==null)throw Error(`Unexpected empty schema`);return e}),rt=x(()=>n(nt())),P=`meowdown_mark_builders`;function it(e){let n=e.cached[P];if(n)return n;let r=t(e);return e.cached[P]=r,r}const at=`inline-marks-applied`,ot=new WeakMap;let st=0,ct=0;function lt(e,t,n){let r=ot.get(e);if(r?ct++:(st++,r=$e(it(n),e.textContent),ot.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 h({key:new g(`inline-mark`),appendTransaction(e,t,n){for(let t of e)if(t.getMeta(at))return null;let r=dt(n,ut(e,n));if(r.length===0)return null;let i=n.tr.step(new E(r));return i.setMeta(at,!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 F={em:{node:A.Emphasis,delim:`*`},strong:{node:A.StrongEmphasis,delim:`**`},code:{node:A.InlineCode,delim:"`"},del:{node:A.Strikethrough,delim:`~~`}},Et=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 Dt(e,t,n){for(;t<n&&B(e[t]);)t++;for(;n>t&&B(e[n-1]);)n--;return[t,n]}function Ot(e,t,n,r){let i=k(O(e),e=>e.type===r.node||Et.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 kt(e,t,n,r,i){let a=O(e),o=k(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]=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]=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!==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(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]=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 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=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 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(_.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(_.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 Ft(){return a({toggleEm:()=>H(F.em),toggleStrong:()=>H(F.strong),toggleCode:()=>H(F.code),toggleDel:()=>H(F.del)})}function It(){return s({"Mod-b":H(F.strong),"Mod-i":H(F.em),"Mod-e":H(F.code),"Mod-Shift-x":H(F.del)})}function Lt(){return f(Ft(),It())}function Rt(){return f(Me(),je(),Ee(),Ae(),ke({allowTableNodeSelection:!0}),De(),Oe())}function zt(){return f(pe(),ce(),me(),ae(),de(),Ve(),Rt(),oe(),ue(),wt(),Re(),mt(),Lt(),i(),r(),o(),le(),he(),fe())}function U(){return zt()}const Bt=new Set([`mdStrong`,`mdEm`,`mdCode`,`mdDel`,`mdLinkText`,`mdLinkUri`,`mdWikilink`]),Vt=new Set([`mdMark`,`mdLinkUri`]),Ht=new Set([`mdMark`,`mdLinkUri`]),W=new Set([`mdLinkText`,`mdLinkUri`]),Ut=new Set([`mdStrong`,`mdEm`,`mdCode`,`mdDel`,`mdWikilink`]);function Wt(e){return new h({key:new g(`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 C.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 C.empty;let s=[],c=new Set,l=!1;for(let e of o)if(W.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])=>S.inline(e,t,{class:`show`}));return C.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&&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 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=>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:Ut.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(Vt.has(e)){let e=`${t}_${s}`;a.has(e)||(a.add(e),i.push([t,s]));break}}o=s})}const Zt=new g(`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 h({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||!(ee?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=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 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 q(e){for(let t of mn){let n=t(e);if(n)return n}}const J=new g(`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 Y(e,t){let n=[];for(let r of hn(e)){let e=q(r.src);if(e){n.push(gn(r,e));continue}let i=t.resolveImageUrl(r.src);i&&n.push(_n(r,i))}return C.create(e.doc,n)}function gn(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 _n(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 vn(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 X(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 bn(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=``,s=a==null?e.state.tr.insertText(o):e.state.tr.insertText(o,a);e.dispatch(s),a!=null&&(a+=o.length)}}function xn(e){return new h({props:{handlePaste:(t,n)=>{let r=X(n.clipboardData),{onImagePaste:i,onImageSaveError:a}=e;return r.length===0||!i?!1:(bn(t,r,i,a),!0)},handleDrop:(t,n)=>{let r=X(n.dataTransfer),{onImagePaste:i,onImageSaveError:a}=e;return r.length===0||!i?!1:(bn(t,r,i,a,t.posAtCoords({left:n.clientX,top:n.clientY})?.pos),!0)}}})}function Sn(t){return f(l(vn(t)),p(l(xn(t)),e.high))}const Cn=new g(`meowdown-embed-paste`);function wn(e){let t=e.trim();if(!(!t||/\s/.test(t)))return q(t)?t:void 0}function Tn(e,t){let{from:n,to:r}=e.state.selection;e.dispatch(Ne(e.state.tr.insertText(t,n,r)));let i=e.state.tr.insertText(``,n,n+t.length);e.dispatch(Ne(i))}function En(){return l(new h({key:Cn,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=wn(r);return i?(Tn(e,i),!0):!1}}}))}const Dn=(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=d(e.schema,`list`),i=d(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 On(){return p(s({Enter:Dn}),e.high)}const kn={"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`},An=new Set([`MscGen`,`Xù`,`MsGenny`,`Angular Template`]),jn=m.map(e=>e.name).filter(e=>!An.has(e)).map(e=>({label:e,value:e.toLowerCase()})).concat({label:`Plain text`,value:``}).sort((e,t)=>e.label.localeCompare(t.label));function Mn(e){let t=new Pn;return Fn(e,t),t.finish()}const Nn=[``,`# `,`## `,`### `,`#### `,`##### `,`###### `];var Pn=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
|
|
8
|
+
`),this.deferredBlankPrefix=null)}};function Fn(e,t){switch(e.type.name){case`doc`:Z(e,t);return;case`paragraph`:Rn(e,t),t.closeBlock();return;case`heading`:{let n=e.attrs.level;t.write(Nn[n]??`# `),Rn(e,t),t.closeBlock();return}case`blockquote`:t.withPrefix(`> `,`> `,()=>Z(e,t)),t.closeBlock();return;case`list`:zn(e,t,Ln(e));return;case`codeBlock`:Bn(e,t);return;case`horizontalRule`:t.write(`---`),t.closeBlock();return;case`table`:Vn(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(),Fn(a,t),i++;continue}let o=i+1;for(;o<r&&e.child(o).type.name===`list`;)o++;let s=In(e,i,o);for(let r=i;r<o;r++)(r===i?n&&i>0:s)&&t.suppressBlank(),zn(e.child(r),t,s);i=o}}function In(e,t,n){for(let r=t;r<n;r++)if(!Ln(e.child(r)))return!1;return!0}function Ln(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 Rn(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 zn(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 Bn(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(`
|
|
9
9
|
`),t.write(r),t.write(`
|
|
10
|
-
`),t.write(i),t.closeBlock()}function
|
|
10
|
+
`),t.write(i),t.closeBlock()}function Vn(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(Un(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(Hn(s,i)),t.write(`
|
|
11
11
|
`),t.write(o);for(let e=0;e<n;e++)e!==a&&(t.write(`
|
|
12
|
-
`),t.write(
|
|
12
|
+
`),t.write(Hn(r[e],i)));t.closeBlock()}function Hn(e,t){let n=`|`;for(let r=0;r<t;r++)n+=` `+(e[r]??``)+` |`;return n}function Un(e){let t=e.textContent.trim();return!t.includes(`|`)&&!t.includes(`
|
|
13
13
|
`)?t:t.replaceAll(`|`,String.raw`\|`).replaceAll(`
|
|
14
|
-
`,` `)}function
|
|
15
|
-
`).filter(e=>e.trim()!==``)}function
|
|
14
|
+
`,` `)}function Wn(e,t=rt()){let n=Gn(t,Xe.parse(e).cursor(),e);return t.doc(n)}function Gn(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 A.ATXHeading1:return[$(e,t,n,1)];case A.ATXHeading2:return[$(e,t,n,2)];case A.ATXHeading3:return[$(e,t,n,3)];case A.ATXHeading4:return[$(e,t,n,4)];case A.ATXHeading5:return[$(e,t,n,5)];case A.ATXHeading6:return[$(e,t,n,6)];case A.SetextHeading1:return[$(e,t,n,1)];case A.SetextHeading2:return[$(e,t,n,2)];case A.Paragraph:return[Kn(e,t,n)];case A.Blockquote:return[qn(e,t,n)];case A.BulletList:return Jn(e,t,n,`bullet`,1);case A.OrderedList:return Yn(e,t,n);case A.FencedCode:case A.CodeBlock:return[Qn(e,t,n)];case A.HorizontalRule:return[e.horizontalRule()];case A.Table:return[$n(e,t,n)];case A.Task:return[Kn(e,t,n)];default:return[]}}function $(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 Kn(e,t,n){let r=n.slice(t.from,t.to);return e.paragraph(r)}function qn(e,t,n){let r=[];if(t.firstChild()){do{if(t.type.id===A.QuoteMark)continue;r.push(...Q(e,t,n))}while(t.nextSibling());t.parent()}return e.blockquote(r)}function Jn(e,t,n,r,i){let a=[];if(t.firstChild()){do t.type.id===A.ListItem&&a.push(Xn(e,t,n,r,i));while(t.nextSibling());t.parent()}return a}function Yn(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 Jn(e,t,n,`ordered`,r)}function Xn(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=Zn(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 Zn(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 Qn(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 $n(e,t,n){let r=0;if(t.firstChild()){do t.type.id===A.TableDelimiter&&(r=er(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(tr(e,t,n,!0,r)):a===A.TableRow&&i.push(tr(e,t,n,!1,r))}while(t.nextSibling());t.parent()}return e.table(i)}function er(e){return e.split(`|`).filter(e=>e.trim()!==``).length}function tr(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 nr(e){return e.replace(/\n+$/u,``)}function rr(e){return e.split(`
|
|
15
|
+
`).filter(e=>e.trim()!==``)}function ir(e){let t=Mn(Wn(e));if(nr(t)===nr(e))return`exact`;let n=rr(e),r=rr(t);return n.length===r.length&&n.every((e,t)=>e===r[t])?`normalizing`:`lossy`}export{kn as EDITOR_KEY_BINDINGS,ir as checkRoundTrip,jn as codeBlockLanguages,On as defineBulletAfterHeading,U as defineEditorExtension,En as defineEmbedPaste,Sn as defineImages,Gt as defineMarkMode,Pe as definePlaceholder,Fe as defineReadonly,en as defineWikilinkClickHandler,Mn as docToMarkdown,Wn as markdownToDoc};
|