decocms
Version:
Deco CMS — Self-hostable MCP Gateway for managing AI connections and tools
70 lines • 86.6 kB
JavaScript
import{c as $,b as j,r as _,j as f,m as B,a_ as at,t as se,b8 as Oe,a6 as ot,ho as lt,i as ct,K as ut,cd as ht,h as De,o as pt}from"./index-ztdGKvBm.js";import{u as dt,v as Be,f as ue,B as ft,w as gt,_ as P,$ as mt,a0 as kt,J as xt,K as D,a1 as ve,a2 as bt,e as wt,a3 as Se,a4 as yt,a5 as G,N as Fe,a6 as he,c as qe,a7 as pe,a8 as Tt,a9 as vt,s as St,aa as Mt,a as Et,E as At}from"./usage-stats-B0_Yl-r0.js";import{T as C,n as Rt,i as _t,E as $t}from"./editor-classes-DYlqLnQ7.js";import{a as Ct,e as Ue,s as Lt,S as It}from"./suggestion-aR93AXr2.js";import{B as zt}from"./index-DrJBZ2ZV.js";import{aF as Pt,aj as jt,ak as Nt,am as Ht,L as Ot,aZ as Dt,aK as Bt}from"./agent-icon-BYWtutu9.js";import{i as Ft}from"./SwitchHorizontal01-CMdpIiQk.js";import{s as qt}from"./Trash01-BxBhF2b8.js";import{k as Ut,a as Zt}from"./use-org-fs-D9dHgOYs.js";import{E as Me,i as Ze,b as Gt,c as Kt,d as Ge,A as Wt,e as Qt,f as Xt,g as Vt,j as Jt}from"./markdown-CJR_ooUO.js";import{s as Yt,T as en}from"./index-BL01DXCf.js";import{f as tn,a as nn,c as rn,C as sn,b as Ee}from"./command-C3tlrKUq.js";import{I as an}from"./icon-button-BH8Qviy5.js";function on(t){const e=$.c(30),{editor:n}=t,s=j(),[r,a]=_.useState(!1),[i,l]=_.useState(""),[o,h]=_.useState(!1);let c;e[0]!==n?(c=n.isActive("link"),e[0]=n,e[1]=c):c=e[1];const u=c;let p;e[2]!==n||e[3]!==r?(p=()=>{if(r){a(!1);return}const T=n.getAttributes("link").href;l(typeof T=="string"?T:""),h(!1),a(!0)},e[2]=n,e[3]=r,e[4]=p):p=e[4];const d=p;let g;e[5]!==n?(g=()=>{n.chain().focus().extendMarkRange("link").unsetLink().run(),a(!1)},e[5]=n,e[6]=g):g=e[6];const x=g;let w;e[7]!==i||e[8]!==n||e[9]!==x?(w=()=>{const T=Rt(i);if(T===""){x();return}if(!_t(T)){h(!0);return}n.chain().focus().extendMarkRange("link").setLink({href:T}).run(),a(!1)},e[7]=i,e[8]=n,e[9]=x,e[10]=w):w=e[10];const b=w;let y;e[11]!==s?(y=s("markdownEditor.link"),e[11]=s,e[12]=y):y=e[12];let v;e[13]===Symbol.for("react.memo_cache_sentinel")?(v=f.jsx(Pt,{size:14}),e[13]=v):v=e[13];let M;e[14]!==u||e[15]!==y||e[16]!==d?(M=f.jsx(C,{active:u,label:y,onClick:d,children:v}),e[14]=u,e[15]=y,e[16]=d,e[17]=M):M=e[17];let m;e[18]!==u||e[19]!==b||e[20]!==i||e[21]!==n||e[22]!==o||e[23]!==r||e[24]!==x||e[25]!==s?(m=r&&f.jsxs("div",{className:"absolute left-0 top-full z-20 mt-1.5 flex w-64 items-center gap-0.5 rounded-md bg-popover p-1 shadow-soft",onBlur:T=>{T.currentTarget.contains(T.relatedTarget)||a(!1)},children:[f.jsx("input",{autoFocus:!0,type:"text","aria-label":s("markdownEditor.linkInputAriaLabel"),"aria-invalid":o,placeholder:s("markdownEditor.linkPlaceholder"),value:i,onChange:T=>{l(T.target.value),h(!1)},onKeyDown:T=>{T.key==="Enter"?(T.preventDefault(),b()):T.key==="Escape"&&(T.preventDefault(),a(!1),n.chain().focus().run())},className:B("h-7 min-w-0 flex-1 rounded bg-transparent px-2 text-sm text-foreground placeholder:text-muted-foreground focus:outline-none",o&&"text-destructive")}),f.jsx(C,{active:!1,label:s("markdownEditor.linkApply"),onClick:b,children:f.jsx(at,{size:14})}),u&&f.jsx(C,{active:!1,label:s("markdownEditor.linkRemove"),onClick:x,children:f.jsx(qt,{size:14})})]}),e[18]=u,e[19]=b,e[20]=i,e[21]=n,e[22]=o,e[23]=r,e[24]=x,e[25]=s,e[26]=m):m=e[26];let k;return e[27]!==M||e[28]!==m?(k=f.jsxs("div",{className:"relative",children:[M,m]}),e[27]=M,e[28]=m,e[29]=k):k=e[29],k}const ne=()=>{const t=$.c(1);let e;return t[0]===Symbol.for("react.memo_cache_sentinel")?(e=f.jsx("div",{className:"mx-0.5 h-4 w-px bg-border"}),t[0]=e):e=t[0],e},Ae=t=>{const e=$.c(2),{children:n}=t;let s;return e[0]!==n?(s=f.jsx("span",{className:"text-2xs font-semibold leading-none",children:n}),e[0]=n,e[1]=s):s=e[1],s},Ke=[1,2,3],ln=({editor:t,state:e})=>t.isEditable&&!e.selection.empty&&!t.isActive("image")&&!t.isActive("attachment")&&!t.isActive("codeBlock");function cn(t){const e=$.c(20),{editor:n}=t,s=j(),[r,a]=_.useState(null);let i;e[0]!==n?(i={editor:n,selector:un},e[0]=n,e[1]=i):i=e[1];const l=dt(i);let o;e[2]!==s?(o=s("markdownEditor.heading1"),e[2]=s,e[3]=o):o=e[3];let h;e[4]!==s?(h=s("markdownEditor.heading2"),e[4]=s,e[5]=h):h=e[5];let c;e[6]!==s?(c=s("markdownEditor.heading3"),e[6]=s,e[7]=c):c=e[7];let u;e[8]!==o||e[9]!==h||e[10]!==c?(u={1:o,2:h,3:c},e[8]=o,e[9]=h,e[10]=c,e[11]=u):u=e[11];const p=u;let d;e[12]!==n||e[13]!==p||e[14]!==r||e[15]!==l||e[16]!==s?(d=r&&f.jsxs(zt,{editor:n,shouldShow:ln,appendTo:r,className:"flex items-center gap-0.5 rounded-lg bg-popover p-1 shadow-soft","aria-label":s("markdownEditor.toolbarAriaLabel"),children:[f.jsx(C,{active:l.bold,label:s("markdownEditor.bold"),onClick:()=>n.chain().focus().toggleBold().run(),children:f.jsx(jt,{size:14})}),f.jsx(C,{active:l.italic,label:s("markdownEditor.italic"),onClick:()=>n.chain().focus().toggleItalic().run(),children:f.jsx(Nt,{size:14})}),f.jsx(C,{active:l.strike,label:s("markdownEditor.strikethrough"),onClick:()=>n.chain().focus().toggleStrike().run(),children:f.jsx(Ht,{size:14})}),f.jsx(C,{active:l.code,label:s("markdownEditor.code"),onClick:()=>n.chain().focus().toggleCode().run(),children:f.jsx(Ot,{size:14})}),f.jsx(ne,{}),Ke.map((x,w)=>f.jsx(C,{active:l.headings[w]??!1,label:p[x],onClick:()=>n.chain().focus().toggleHeading({level:x}).run(),children:f.jsx(Ae,{children:`H${x}`})},x)),f.jsx(ne,{}),f.jsx(C,{active:l.bulletList,label:s("markdownEditor.bulletList"),onClick:()=>n.chain().focus().toggleBulletList().run(),children:f.jsx(Ft,{size:14})}),f.jsx(C,{active:l.orderedList,label:s("markdownEditor.orderedList"),onClick:()=>n.chain().focus().toggleOrderedList().run(),children:f.jsx(Ae,{children:"1."})}),f.jsx(C,{active:l.blockquote,label:s("markdownEditor.quote"),onClick:()=>n.chain().focus().toggleBlockquote().run(),children:f.jsx(Dt,{size:14})}),f.jsx(ne,{}),f.jsx(on,{editor:n})]}),e[12]=n,e[13]=p,e[14]=r,e[15]=l,e[16]=s,e[17]=d):d=e[17];let g;return e[18]!==d?(g=f.jsx("div",{ref:a,className:"relative z-20",children:d}),e[18]=d,e[19]=g):g=e[19],g}function un(t){const{editor:e}=t;return{bold:e.isActive("bold"),italic:e.isActive("italic"),strike:e.isActive("strike"),code:e.isActive("code"),headings:Ke.map(n=>e.isActive("heading",{level:n})),bulletList:e.isActive("bulletList"),orderedList:e.isActive("orderedList"),blockquote:e.isActive("blockquote")}}const hn=10,pn=25,dn={"image/png":".png","image/jpeg":".jpg","image/gif":".gif","image/webp":".webp","image/avif":".avif","image/svg+xml":".svg"};function fn(t){return t.name.match(/\.[a-z0-9]{1,8}$/i)?.[0]??dn[t.type]??""}function gn(){const t=$.c(4),e=j(),{upload:n}=Ut(Me),s=Zt(Me);let r;return t[0]!==s||t[1]!==e||t[2]!==n?(r={uploadFile:async i=>{const l=Ze(i),o=l?hn:pn;if(i.size>o*1024*1024)return se.error(e("markdownEditor.fileTooLarge",{name:i.name,max:String(o)})),null;const h=l?Gt:Kt,c=`${crypto.randomUUID()}${fn(i)}`;try{return await n.mutateAsync({dir:h,files:[new File([i],c,{type:i.type})]}),s(`${h}/${c}`)}catch{return se.error(e("markdownEditor.uploadFailed",{name:i.name})),null}}},t[0]=s,t[1]=e,t[2]=n,t[3]=r):r=t[3],r}const X=new Be("uploadSlots"),mn=ue.create({name:"uploadSlots",addProseMirrorPlugins(){return[new ft({key:X,state:{init:()=>new Map,apply(t,e){const n=t.getMeta(X);if(!t.docChanged&&!n)return e;const s=new Map;for(const[r,a]of e)s.set(r,t.mapping.map(a));if(n){const[r,a]=n;a===null?s.delete(r):s.set(r,a)}return s}}})]}});function ie(t,e,n){return t.setMeta(X,[e,n])}function kn(t,e){return X.getState(t)?.get(e)}function xn(t,e,n,s,r){const{schema:a}=t.state,i=a.nodes[n];if(!i)return;const l=i.create(s),o=t.state.selection.to===e,h=t.state.doc.resolve(e),c=h.parent.textBetween(Math.max(0,h.parentOffset-1),h.parentOffset,void 0,""),u=()=>a.text(" "),p=l.isInline?[...c&&!/\s/.test(c)?[u()]:[],l,u()]:l,d=t.state.tr.replaceWith(e,e,p);let g=e,x=e;d.mapping.maps.at(-1)?.forEach((M,m,k,T)=>{g=k,x=T});let w;d.doc.nodesBetween(g,x,(M,m)=>{M===l&&(w=m+M.nodeSize)});let b=w??x;w!==void 0&&l.isInline&&(b+=1);const y=a.nodes.paragraph;w!==void 0&&l.isBlock&&y&&(d.doc.resolve(w).nodeAfter?.isTextblock||d.insert(w,y.create()),b=w+1);const v=gt.near(d.doc.resolve(b));o&&d.setSelection(v),r&&ie(d,r,v.to),t.dispatch(d)}function bn(t){return!t||t.files.length===0?[]:t.getData("text/html")!==""&&t.getData("text/plain").trim()!==""?[]:Array.from(t.files)}function wn(t=!0){const e=j(),{uploadFile:n}=gn(),s=_.useRef(n);s.current=n;const[r,a]=_.useState(0),i=_.useRef(0),l=u=>{i.current+=u,a(i.current)},o=(u,p,d)=>{if(!t||p.length===0)return!1;l(p.length);const g=Symbol("upload");return u.dispatch(ie(u.state.tr,g,d)),(async()=>{for(const x of p)try{const w=await s.current(x);if(!w||u.isDestroyed)continue;const b=Ze(x);xn(u,kn(u.state,g)??u.state.selection.to,b?"image":"attachment",b?{src:w,alt:x.name}:{href:w,name:x.name},g)}catch{se.error(e("markdownEditor.uploadFailed",{name:x.name}))}finally{l(-1)}u.isDestroyed||u.dispatch(ie(u.state.tr,g,null))})(),!0};return{pending:r,uploading:()=>i.current>0,uploadInto:o,handlePaste:(u,p)=>{const d=bn(p.clipboardData);return d.length===0?!1:(p.stopPropagation(),o(u,d,u.state.selection.to))},handleDrop:(u,p,d,g)=>{if(g)return!1;const x=Array.from(p.dataTransfer?.files??[]);if(x.length===0)return!1;const w=u.posAtCoords({left:p.clientX,top:p.clientY})?.pos;return w===void 0?!1:(p.stopPropagation(),o(u,x,w))}}}function de(){return{async:!1,breaks:!1,extensions:null,gfm:!0,hooks:null,pedantic:!1,renderer:null,silent:!1,tokenizer:null,walkTokens:null}}var O=de();function We(t){O=t}var N={exec:()=>null};function S(t,e=""){let n=typeof t=="string"?t:t.source,s={replace:(r,a)=>{let i=typeof a=="string"?a:a.source;return i=i.replace(R.caret,"$1"),n=n.replace(r,i),s},getRegex:()=>new RegExp(n,e)};return s}var yn=(()=>{try{return!!new RegExp("(?<=1)(?<!1)")}catch{return!1}})(),R={codeRemoveIndent:/^(?: {1,4}| {0,3}\t)/gm,outputLinkReplace:/\\([\[\]])/g,indentCodeCompensation:/^(\s+)(?:```)/,beginningSpace:/^\s+/,endingHash:/#$/,startingSpaceChar:/^ /,endingSpaceChar:/ $/,nonSpaceChar:/[^ ]/,newLineCharGlobal:/\n/g,tabCharGlobal:/\t/g,multipleSpaceGlobal:/\s+/g,blankLine:/^[ \t]*$/,doubleBlankLine:/\n[ \t]*\n[ \t]*$/,blockquoteStart:/^ {0,3}>/,blockquoteSetextReplace:/\n {0,3}((?:=+|-+) *)(?=\n|$)/g,blockquoteSetextReplace2:/^ {0,3}>[ \t]?/gm,listReplaceNesting:/^ {1,4}(?=( {4})*[^ ])/g,listIsTask:/^\[[ xX]\] +\S/,listReplaceTask:/^\[[ xX]\] +/,listTaskCheckbox:/\[[ xX]\]/,anyLine:/\n.*\n/,hrefBrackets:/^<(.*)>$/,tableDelimiter:/[:|]/,tableAlignChars:/^\||\| *$/g,tableRowBlankLine:/\n[ \t]*$/,tableAlignRight:/^ *-+: *$/,tableAlignCenter:/^ *:-+: *$/,tableAlignLeft:/^ *:-+ *$/,startATag:/^<a /i,endATag:/^<\/a>/i,startPreScriptTag:/^<(pre|code|kbd|script)(\s|>)/i,endPreScriptTag:/^<\/(pre|code|kbd|script)(\s|>)/i,startAngleBracket:/^</,endAngleBracket:/>$/,pedanticHrefTitle:/^([^'"]*[^\s])\s+(['"])(.*)\2/,unicodeAlphaNumeric:/[\p{L}\p{N}]/u,escapeTest:/[&<>"']/,escapeReplace:/[&<>"']/g,escapeTestNoEncode:/[<>"']|&(?!(#\d{1,7}|#[Xx][a-fA-F0-9]{1,6}|\w+);)/,escapeReplaceNoEncode:/[<>"']|&(?!(#\d{1,7}|#[Xx][a-fA-F0-9]{1,6}|\w+);)/g,caret:/(^|[^\[])\^/g,percentDecode:/%25/g,findPipe:/\|/g,splitPipe:/ \|/,slashPipe:/\\\|/g,carriageReturn:/\r\n|\r/g,spaceLine:/^ +$/gm,notSpaceStart:/^\S*/,endingNewline:/\n$/,listItemRegex:t=>new RegExp(`^( {0,3}${t})((?:[ ][^\\n]*)?(?:\\n|$))`),nextBulletRegex:t=>new RegExp(`^ {0,${Math.min(3,t-1)}}(?:[*+-]|\\d{1,9}[.)])((?:[ ][^\\n]*)?(?:\\n|$))`),hrRegex:t=>new RegExp(`^ {0,${Math.min(3,t-1)}}((?:- *){3,}|(?:_ *){3,}|(?:\\* *){3,})(?:\\n+|$)`),fencesBeginRegex:t=>new RegExp(`^ {0,${Math.min(3,t-1)}}(?:\`\`\`|~~~)`),headingBeginRegex:t=>new RegExp(`^ {0,${Math.min(3,t-1)}}#`),htmlBeginRegex:t=>new RegExp(`^ {0,${Math.min(3,t-1)}}<(?:[a-z].*>|!--)`,"i"),blockquoteBeginRegex:t=>new RegExp(`^ {0,${Math.min(3,t-1)}}>`)},Tn=/^(?:[ \t]*(?:\n|$))+/,vn=/^((?: {4}| {0,3}\t)[^\n]+(?:\n(?:[ \t]*(?:\n|$))*)?)+/,Sn=/^ {0,3}(`{3,}(?=[^`\n]*(?:\n|$))|~{3,})([^\n]*)(?:\n|$)(?:|([\s\S]*?)(?:\n|$))(?: {0,3}\1[~`]* *(?=\n|$)|$)/,K=/^ {0,3}((?:-[\t ]*){3,}|(?:_[ \t]*){3,}|(?:\*[ \t]*){3,})(?:\n+|$)/,Mn=/^ {0,3}(#{1,6})(?=\s|$)(.*)(?:\n+|$)/,fe=/ {0,3}(?:[*+-]|\d{1,9}[.)])/,Qe=/^(?!bull |blockCode|fences|blockquote|heading|html|table)((?:.|\n(?!\s*?\n|bull |blockCode|fences|blockquote|heading|html|table))+?)\n {0,3}(=+|-+) *(?:\n+|$)/,Xe=S(Qe).replace(/bull/g,fe).replace(/blockCode/g,/(?: {4}| {0,3}\t)/).replace(/fences/g,/ {0,3}(?:`{3,}|~{3,})/).replace(/blockquote/g,/ {0,3}>/).replace(/heading/g,/ {0,3}#{1,6}/).replace(/html/g,/ {0,3}<[^\n>]+>\n/).replace(/\|table/g,"").getRegex(),En=S(Qe).replace(/bull/g,fe).replace(/blockCode/g,/(?: {4}| {0,3}\t)/).replace(/fences/g,/ {0,3}(?:`{3,}|~{3,})/).replace(/blockquote/g,/ {0,3}>/).replace(/heading/g,/ {0,3}#{1,6}/).replace(/html/g,/ {0,3}<[^\n>]+>\n/).replace(/table/g,/ {0,3}\|?(?:[:\- ]*\|)+[\:\- ]*\n/).getRegex(),ge=/^([^\n]+(?:\n(?!hr|heading|lheading|blockquote|fences|list|html|table| +\n)[^\n]+)*)/,An=/^[^\n]+/,me=/(?!\s*\])(?:\\[\s\S]|[^\[\]\\])+/,Rn=S(/^ {0,3}\[(label)\]: *(?:\n[ \t]*)?([^<\s][^\s]*|<.*?>)(?:(?: +(?:\n[ \t]*)?| *\n[ \t]*)(title))? *(?:\n+|$)/).replace("label",me).replace("title",/(?:"(?:\\"?|[^"\\])*"|'[^'\n]*(?:\n[^'\n]+)*\n?'|\([^()]*\))/).getRegex(),_n=S(/^(bull)([ \t][^\n]+?)?(?:\n|$)/).replace(/bull/g,fe).getRegex(),ee="address|article|aside|base|basefont|blockquote|body|caption|center|col|colgroup|dd|details|dialog|dir|div|dl|dt|fieldset|figcaption|figure|footer|form|frame|frameset|h[1-6]|head|header|hr|html|iframe|legend|li|link|main|menu|menuitem|meta|nav|noframes|ol|optgroup|option|p|param|search|section|summary|table|tbody|td|tfoot|th|thead|title|tr|track|ul",ke=/<!--(?:-?>|[\s\S]*?(?:-->|$))/,$n=S("^ {0,3}(?:<(script|pre|style|textarea)[\\s>][\\s\\S]*?(?:</\\1>[^\\n]*\\n+|$)|comment[^\\n]*(\\n+|$)|<\\?[\\s\\S]*?(?:\\?>\\n*|$)|<![A-Z][\\s\\S]*?(?:>\\n*|$)|<!\\[CDATA\\[[\\s\\S]*?(?:\\]\\]>\\n*|$)|</?(tag)(?: +|\\n|/?>)[\\s\\S]*?(?:(?:\\n[ ]*)+\\n|$)|<(?!script|pre|style|textarea)([a-z][\\w-]*)(?:attribute)*? */?>(?=[ \\t]*(?:\\n|$))[\\s\\S]*?(?:(?:\\n[ ]*)+\\n|$)|</(?!script|pre|style|textarea)[a-z][\\w-]*\\s*>(?=[ \\t]*(?:\\n|$))[\\s\\S]*?(?:(?:\\n[ ]*)+\\n|$))","i").replace("comment",ke).replace("tag",ee).replace("attribute",/ +[a-zA-Z:_][\w.:-]*(?: *= *"[^"\n]*"| *= *'[^'\n]*'| *= *[^\s"'=<>`]+)?/).getRegex(),Ve=S(ge).replace("hr",K).replace("heading"," {0,3}#{1,6}(?:\\s|$)").replace("|lheading","").replace("|table","").replace("blockquote"," {0,3}>").replace("fences"," {0,3}(?:`{3,}(?=[^`\\n]*\\n)|~{3,})[^\\n]*\\n").replace("list"," {0,3}(?:[*+-]|1[.)])[ \\t]").replace("html","</?(?:tag)(?: +|\\n|/?>)|<(?:script|pre|style|textarea|!--)").replace("tag",ee).getRegex(),Cn=S(/^( {0,3}> ?(paragraph|[^\n]*)(?:\n|$))+/).replace("paragraph",Ve).getRegex(),xe={blockquote:Cn,code:vn,def:Rn,fences:Sn,heading:Mn,hr:K,html:$n,lheading:Xe,list:_n,newline:Tn,paragraph:Ve,table:N,text:An},Re=S("^ *([^\\n ].*)\\n {0,3}((?:\\| *)?:?-+:? *(?:\\| *:?-+:? *)*(?:\\| *)?)(?:\\n((?:(?! *\\n|hr|heading|blockquote|code|fences|list|html).*(?:\\n|$))*)\\n*|$)").replace("hr",K).replace("heading"," {0,3}#{1,6}(?:\\s|$)").replace("blockquote"," {0,3}>").replace("code","(?: {4}| {0,3} )[^\\n]").replace("fences"," {0,3}(?:`{3,}(?=[^`\\n]*\\n)|~{3,})[^\\n]*\\n").replace("list"," {0,3}(?:[*+-]|1[.)])[ \\t]").replace("html","</?(?:tag)(?: +|\\n|/?>)|<(?:script|pre|style|textarea|!--)").replace("tag",ee).getRegex(),Ln={...xe,lheading:En,table:Re,paragraph:S(ge).replace("hr",K).replace("heading"," {0,3}#{1,6}(?:\\s|$)").replace("|lheading","").replace("table",Re).replace("blockquote"," {0,3}>").replace("fences"," {0,3}(?:`{3,}(?=[^`\\n]*\\n)|~{3,})[^\\n]*\\n").replace("list"," {0,3}(?:[*+-]|1[.)])[ \\t]").replace("html","</?(?:tag)(?: +|\\n|/?>)|<(?:script|pre|style|textarea|!--)").replace("tag",ee).getRegex()},In={...xe,html:S(`^ *(?:comment *(?:\\n|\\s*$)|<(tag)[\\s\\S]+?</\\1> *(?:\\n{2,}|\\s*$)|<tag(?:"[^"]*"|'[^']*'|\\s[^'"/>\\s]*)*?/?> *(?:\\n{2,}|\\s*$))`).replace("comment",ke).replace(/tag/g,"(?!(?:a|em|strong|small|s|cite|q|dfn|abbr|data|time|code|var|samp|kbd|sub|sup|i|b|u|mark|ruby|rt|rp|bdi|bdo|span|br|wbr|ins|del|img)\\b)\\w+(?!:|[^\\w\\s@]*@)\\b").getRegex(),def:/^ *\[([^\]]+)\]: *<?([^\s>]+)>?(?: +(["(][^\n]+[")]))? *(?:\n+|$)/,heading:/^(#{1,6})(.*)(?:\n+|$)/,fences:N,lheading:/^(.+?)\n {0,3}(=+|-+) *(?:\n+|$)/,paragraph:S(ge).replace("hr",K).replace("heading",` *#{1,6} *[^
]`).replace("lheading",Xe).replace("|table","").replace("blockquote"," {0,3}>").replace("|fences","").replace("|list","").replace("|html","").replace("|tag","").getRegex()},zn=/^\\([!"#$%&'()*+,\-./:;<=>?@\[\]\\^_`{|}~])/,Pn=/^(`+)([^`]|[^`][\s\S]*?[^`])\1(?!`)/,Je=/^( {2,}|\\)\n(?!\s*$)/,jn=/^(`+|[^`])(?:(?= {2,}\n)|[\s\S]*?(?:(?=[\\<!\[`*_]|\b_|$)|[^ ](?= {2,}\n)))/,F=/[\p{P}\p{S}]/u,te=/[\s\p{P}\p{S}]/u,be=/[^\s\p{P}\p{S}]/u,Nn=S(/^((?![*_])punctSpace)/,"u").replace(/punctSpace/g,te).getRegex(),Ye=/(?!~)[\p{P}\p{S}]/u,Hn=/(?!~)[\s\p{P}\p{S}]/u,On=/(?:[^\s\p{P}\p{S}]|~)/u,Dn=S(/link|precode-code|html/,"g").replace("link",/\[(?:[^\[\]`]|(?<a>`+)[^`]+\k<a>(?!`))*?\]\((?:\\[\s\S]|[^\\\(\)]|\((?:\\[\s\S]|[^\\\(\)])*\))*\)/).replace("precode-",yn?"(?<!`)()":"(^^|[^`])").replace("code",/(?<b>`+)[^`]+\k<b>(?!`)/).replace("html",/<(?! )[^<>]*?>/).getRegex(),et=/^(?:\*+(?:((?!\*)punct)|([^\s*]))?)|^_+(?:((?!_)punct)|([^\s_]))?/,Bn=S(et,"u").replace(/punct/g,F).getRegex(),Fn=S(et,"u").replace(/punct/g,Ye).getRegex(),tt="^[^_*]*?__[^_*]*?\\*[^_*]*?(?=__)|[^*]+(?=[^*])|(?!\\*)punct(\\*+)(?=[\\s]|$)|notPunctSpace(\\*+)(?!\\*)(?=punctSpace|$)|(?!\\*)punctSpace(\\*+)(?=notPunctSpace)|[\\s](\\*+)(?!\\*)(?=punct)|(?!\\*)punct(\\*+)(?!\\*)(?=punct)|notPunctSpace(\\*+)(?=notPunctSpace)",qn=S(tt,"gu").replace(/notPunctSpace/g,be).replace(/punctSpace/g,te).replace(/punct/g,F).getRegex(),Un=S(tt,"gu").replace(/notPunctSpace/g,On).replace(/punctSpace/g,Hn).replace(/punct/g,Ye).getRegex(),Zn=S("^[^_*]*?\\*\\*[^_*]*?_[^_*]*?(?=\\*\\*)|[^_]+(?=[^_])|(?!_)punct(_+)(?=[\\s]|$)|notPunctSpace(_+)(?!_)(?=punctSpace|$)|(?!_)punctSpace(_+)(?=notPunctSpace)|[\\s](_+)(?!_)(?=punct)|(?!_)punct(_+)(?!_)(?=punct)","gu").replace(/notPunctSpace/g,be).replace(/punctSpace/g,te).replace(/punct/g,F).getRegex(),Gn=S(/^~~?(?:((?!~)punct)|[^\s~])/,"u").replace(/punct/g,F).getRegex(),Kn="^[^~]+(?=[^~])|(?!~)punct(~~?)(?=[\\s]|$)|notPunctSpace(~~?)(?!~)(?=punctSpace|$)|(?!~)punctSpace(~~?)(?=notPunctSpace)|[\\s](~~?)(?!~)(?=punct)|(?!~)punct(~~?)(?!~)(?=punct)|notPunctSpace(~~?)(?=notPunctSpace)",Wn=S(Kn,"gu").replace(/notPunctSpace/g,be).replace(/punctSpace/g,te).replace(/punct/g,F).getRegex(),Qn=S(/\\(punct)/,"gu").replace(/punct/g,F).getRegex(),Xn=S(/^<(scheme:[^\s\x00-\x1f<>]*|email)>/).replace("scheme",/[a-zA-Z][a-zA-Z0-9+.-]{1,31}/).replace("email",/[a-zA-Z0-9.!#$%&'*+/=?^_`{|}~-]+(@)[a-zA-Z0-9](?:[a-zA-Z0-9-]{0,61}[a-zA-Z0-9])?(?:\.[a-zA-Z0-9](?:[a-zA-Z0-9-]{0,61}[a-zA-Z0-9])?)+(?![-_])/).getRegex(),Vn=S(ke).replace("(?:-->|$)","-->").getRegex(),Jn=S("^comment|^</[a-zA-Z][\\w:-]*\\s*>|^<[a-zA-Z][\\w-]*(?:attribute)*?\\s*/?>|^<\\?[\\s\\S]*?\\?>|^<![a-zA-Z]+\\s[\\s\\S]*?>|^<!\\[CDATA\\[[\\s\\S]*?\\]\\]>").replace("comment",Vn).replace("attribute",/\s+[a-zA-Z:_][\w.:-]*(?:\s*=\s*"[^"]*"|\s*=\s*'[^']*'|\s*=\s*[^\s"'=<>`]+)?/).getRegex(),V=/(?:\[(?:\\[\s\S]|[^\[\]\\])*\]|\\[\s\S]|`+(?!`)[^`]*?`+(?!`)|``+(?=\])|[^\[\]\\`])*?/,Yn=S(/^!?\[(label)\]\(\s*(href)(?:(?:[ \t]+(?:\n[ \t]*)?|\n[ \t]*)(title))?\s*\)/).replace("label",V).replace("href",/<(?:\\.|[^\n<>\\])+>|[^ \t\n\x00-\x1f]*/).replace("title",/"(?:\\"?|[^"\\])*"|'(?:\\'?|[^'\\])*'|\((?:\\\)?|[^)\\])*\)/).getRegex(),nt=S(/^!?\[(label)\]\[(ref)\]/).replace("label",V).replace("ref",me).getRegex(),rt=S(/^!?\[(ref)\](?:\[\])?/).replace("ref",me).getRegex(),er=S("reflink|nolink(?!\\()","g").replace("reflink",nt).replace("nolink",rt).getRegex(),_e=/[hH][tT][tT][pP][sS]?|[fF][tT][pP]/,we={_backpedal:N,anyPunctuation:Qn,autolink:Xn,blockSkip:Dn,br:Je,code:Pn,del:N,delLDelim:N,delRDelim:N,emStrongLDelim:Bn,emStrongRDelimAst:qn,emStrongRDelimUnd:Zn,escape:zn,link:Yn,nolink:rt,punctuation:Nn,reflink:nt,reflinkSearch:er,tag:Jn,text:jn,url:N},tr={...we,link:S(/^!?\[(label)\]\((.*?)\)/).replace("label",V).getRegex(),reflink:S(/^!?\[(label)\]\s*\[([^\]]*)\]/).replace("label",V).getRegex()},ae={...we,emStrongRDelimAst:Un,emStrongLDelim:Fn,delLDelim:Gn,delRDelim:Wn,url:S(/^((?:protocol):\/\/|www\.)(?:[a-zA-Z0-9\-]+\.?)+[^\s<]*|^email/).replace("protocol",_e).replace("email",/[A-Za-z0-9._+-]+(@)[a-zA-Z0-9-_]+(?:\.[a-zA-Z0-9-_]*[a-zA-Z0-9])+(?![-_])/).getRegex(),_backpedal:/(?:[^?!.,:;*_'"~()&]+|\([^)]*\)|&(?![a-zA-Z0-9]+;$)|[?!.,:;*_'"~)]+(?!$))+/,del:/^(~~?)(?=[^\s~])((?:\\[\s\S]|[^\\])*?(?:\\[\s\S]|[^\s~\\]))\1(?=[^~]|$)/,text:S(/^([`~]+|[^`~])(?:(?= {2,}\n)|(?=[a-zA-Z0-9.!#$%&'*+\/=?_`{\|}~-]+@)|[\s\S]*?(?:(?=[\\<!\[`*~_]|\b_|protocol:\/\/|www\.|$)|[^ ](?= {2,}\n)|[^a-zA-Z0-9.!#$%&'*+\/=?_`{\|}~-](?=[a-zA-Z0-9.!#$%&'*+\/=?_`{\|}~-]+@)))/).replace("protocol",_e).getRegex()},nr={...ae,br:S(Je).replace("{2,}","*").getRegex(),text:S(ae.text).replace("\\b_","\\b_| {2,}\\n").replace(/\{2,\}/g,"*").getRegex()},W={normal:xe,gfm:Ln,pedantic:In},q={normal:we,gfm:ae,breaks:nr,pedantic:tr},rr={"&":"&","<":"<",">":">",'"':""","'":"'"},$e=t=>rr[t];function z(t,e){if(e){if(R.escapeTest.test(t))return t.replace(R.escapeReplace,$e)}else if(R.escapeTestNoEncode.test(t))return t.replace(R.escapeReplaceNoEncode,$e);return t}function Ce(t){try{t=encodeURI(t).replace(R.percentDecode,"%")}catch{return null}return t}function Le(t,e){let n=t.replace(R.findPipe,(a,i,l)=>{let o=!1,h=i;for(;--h>=0&&l[h]==="\\";)o=!o;return o?"|":" |"}),s=n.split(R.splitPipe),r=0;if(s[0].trim()||s.shift(),s.length>0&&!s.at(-1)?.trim()&&s.pop(),e)if(s.length>e)s.splice(e);else for(;s.length<e;)s.push("");for(;r<s.length;r++)s[r]=s[r].trim().replace(R.slashPipe,"|");return s}function U(t,e,n){let s=t.length;if(s===0)return"";let r=0;for(;r<s&&t.charAt(s-r-1)===e;)r++;return t.slice(0,s-r)}function sr(t,e){if(t.indexOf(e[1])===-1)return-1;let n=0;for(let s=0;s<t.length;s++)if(t[s]==="\\")s++;else if(t[s]===e[0])n++;else if(t[s]===e[1]&&(n--,n<0))return s;return n>0?-2:-1}function ir(t,e=0){let n=e,s="";for(let r of t)if(r===" "){let a=4-n%4;s+=" ".repeat(a),n+=a}else s+=r,n++;return s}function Ie(t,e,n,s,r){let a=e.href,i=e.title||null,l=t[1].replace(r.other.outputLinkReplace,"$1");s.state.inLink=!0;let o={type:t[0].charAt(0)==="!"?"image":"link",raw:n,href:a,title:i,text:l,tokens:s.inlineTokens(l)};return s.state.inLink=!1,o}function ar(t,e,n){let s=t.match(n.other.indentCodeCompensation);if(s===null)return e;let r=s[1];return e.split(`
`).map(a=>{let i=a.match(n.other.beginningSpace);if(i===null)return a;let[l]=i;return l.length>=r.length?a.slice(r.length):a}).join(`
`)}var J=class{options;rules;lexer;constructor(t){this.options=t||O}space(t){let e=this.rules.block.newline.exec(t);if(e&&e[0].length>0)return{type:"space",raw:e[0]}}code(t){let e=this.rules.block.code.exec(t);if(e){let n=e[0].replace(this.rules.other.codeRemoveIndent,"");return{type:"code",raw:e[0],codeBlockStyle:"indented",text:this.options.pedantic?n:U(n,`
`)}}}fences(t){let e=this.rules.block.fences.exec(t);if(e){let n=e[0],s=ar(n,e[3]||"",this.rules);return{type:"code",raw:n,lang:e[2]?e[2].trim().replace(this.rules.inline.anyPunctuation,"$1"):e[2],text:s}}}heading(t){let e=this.rules.block.heading.exec(t);if(e){let n=e[2].trim();if(this.rules.other.endingHash.test(n)){let s=U(n,"#");(this.options.pedantic||!s||this.rules.other.endingSpaceChar.test(s))&&(n=s.trim())}return{type:"heading",raw:e[0],depth:e[1].length,text:n,tokens:this.lexer.inline(n)}}}hr(t){let e=this.rules.block.hr.exec(t);if(e)return{type:"hr",raw:U(e[0],`
`)}}blockquote(t){let e=this.rules.block.blockquote.exec(t);if(e){let n=U(e[0],`
`).split(`
`),s="",r="",a=[];for(;n.length>0;){let i=!1,l=[],o;for(o=0;o<n.length;o++)if(this.rules.other.blockquoteStart.test(n[o]))l.push(n[o]),i=!0;else if(!i)l.push(n[o]);else break;n=n.slice(o);let h=l.join(`
`),c=h.replace(this.rules.other.blockquoteSetextReplace,`
$1`).replace(this.rules.other.blockquoteSetextReplace2,"");s=s?`${s}
${h}`:h,r=r?`${r}
${c}`:c;let u=this.lexer.state.top;if(this.lexer.state.top=!0,this.lexer.blockTokens(c,a,!0),this.lexer.state.top=u,n.length===0)break;let p=a.at(-1);if(p?.type==="code")break;if(p?.type==="blockquote"){let d=p,g=d.raw+`
`+n.join(`
`),x=this.blockquote(g);a[a.length-1]=x,s=s.substring(0,s.length-d.raw.length)+x.raw,r=r.substring(0,r.length-d.text.length)+x.text;break}else if(p?.type==="list"){let d=p,g=d.raw+`
`+n.join(`
`),x=this.list(g);a[a.length-1]=x,s=s.substring(0,s.length-p.raw.length)+x.raw,r=r.substring(0,r.length-d.raw.length)+x.raw,n=g.substring(a.at(-1).raw.length).split(`
`);continue}}return{type:"blockquote",raw:s,tokens:a,text:r}}}list(t){let e=this.rules.block.list.exec(t);if(e){let n=e[1].trim(),s=n.length>1,r={type:"list",raw:"",ordered:s,start:s?+n.slice(0,-1):"",loose:!1,items:[]};n=s?`\\d{1,9}\\${n.slice(-1)}`:`\\${n}`,this.options.pedantic&&(n=s?n:"[*+-]");let a=this.rules.other.listItemRegex(n),i=!1;for(;t;){let o=!1,h="",c="";if(!(e=a.exec(t))||this.rules.block.hr.test(t))break;h=e[0],t=t.substring(h.length);let u=ir(e[2].split(`
`,1)[0],e[1].length),p=t.split(`
`,1)[0],d=!u.trim(),g=0;if(this.options.pedantic?(g=2,c=u.trimStart()):d?g=e[1].length+1:(g=u.search(this.rules.other.nonSpaceChar),g=g>4?1:g,c=u.slice(g),g+=e[1].length),d&&this.rules.other.blankLine.test(p)&&(h+=p+`
`,t=t.substring(p.length+1),o=!0),!o){let x=this.rules.other.nextBulletRegex(g),w=this.rules.other.hrRegex(g),b=this.rules.other.fencesBeginRegex(g),y=this.rules.other.headingBeginRegex(g),v=this.rules.other.htmlBeginRegex(g),M=this.rules.other.blockquoteBeginRegex(g);for(;t;){let m=t.split(`
`,1)[0],k;if(p=m,this.options.pedantic?(p=p.replace(this.rules.other.listReplaceNesting," "),k=p):k=p.replace(this.rules.other.tabCharGlobal," "),b.test(p)||y.test(p)||v.test(p)||M.test(p)||x.test(p)||w.test(p))break;if(k.search(this.rules.other.nonSpaceChar)>=g||!p.trim())c+=`
`+k.slice(g);else{if(d||u.replace(this.rules.other.tabCharGlobal," ").search(this.rules.other.nonSpaceChar)>=4||b.test(u)||y.test(u)||w.test(u))break;c+=`
`+p}d=!p.trim(),h+=m+`
`,t=t.substring(m.length+1),u=k.slice(g)}}r.loose||(i?r.loose=!0:this.rules.other.doubleBlankLine.test(h)&&(i=!0)),r.items.push({type:"list_item",raw:h,task:!!this.options.gfm&&this.rules.other.listIsTask.test(c),loose:!1,text:c,tokens:[]}),r.raw+=h}let l=r.items.at(-1);if(l)l.raw=l.raw.trimEnd(),l.text=l.text.trimEnd();else return;r.raw=r.raw.trimEnd();for(let o of r.items){if(this.lexer.state.top=!1,o.tokens=this.lexer.blockTokens(o.text,[]),o.task){if(o.text=o.text.replace(this.rules.other.listReplaceTask,""),o.tokens[0]?.type==="text"||o.tokens[0]?.type==="paragraph"){o.tokens[0].raw=o.tokens[0].raw.replace(this.rules.other.listReplaceTask,""),o.tokens[0].text=o.tokens[0].text.replace(this.rules.other.listReplaceTask,"");for(let c=this.lexer.inlineQueue.length-1;c>=0;c--)if(this.rules.other.listIsTask.test(this.lexer.inlineQueue[c].src)){this.lexer.inlineQueue[c].src=this.lexer.inlineQueue[c].src.replace(this.rules.other.listReplaceTask,"");break}}let h=this.rules.other.listTaskCheckbox.exec(o.raw);if(h){let c={type:"checkbox",raw:h[0]+" ",checked:h[0]!=="[ ]"};o.checked=c.checked,r.loose?o.tokens[0]&&["paragraph","text"].includes(o.tokens[0].type)&&"tokens"in o.tokens[0]&&o.tokens[0].tokens?(o.tokens[0].raw=c.raw+o.tokens[0].raw,o.tokens[0].text=c.raw+o.tokens[0].text,o.tokens[0].tokens.unshift(c)):o.tokens.unshift({type:"paragraph",raw:c.raw,text:c.raw,tokens:[c]}):o.tokens.unshift(c)}}if(!r.loose){let h=o.tokens.filter(u=>u.type==="space"),c=h.length>0&&h.some(u=>this.rules.other.anyLine.test(u.raw));r.loose=c}}if(r.loose)for(let o of r.items){o.loose=!0;for(let h of o.tokens)h.type==="text"&&(h.type="paragraph")}return r}}html(t){let e=this.rules.block.html.exec(t);if(e)return{type:"html",block:!0,raw:e[0],pre:e[1]==="pre"||e[1]==="script"||e[1]==="style",text:e[0]}}def(t){let e=this.rules.block.def.exec(t);if(e){let n=e[1].toLowerCase().replace(this.rules.other.multipleSpaceGlobal," "),s=e[2]?e[2].replace(this.rules.other.hrefBrackets,"$1").replace(this.rules.inline.anyPunctuation,"$1"):"",r=e[3]?e[3].substring(1,e[3].length-1).replace(this.rules.inline.anyPunctuation,"$1"):e[3];return{type:"def",tag:n,raw:e[0],href:s,title:r}}}table(t){let e=this.rules.block.table.exec(t);if(!e||!this.rules.other.tableDelimiter.test(e[2]))return;let n=Le(e[1]),s=e[2].replace(this.rules.other.tableAlignChars,"").split("|"),r=e[3]?.trim()?e[3].replace(this.rules.other.tableRowBlankLine,"").split(`
`):[],a={type:"table",raw:e[0],header:[],align:[],rows:[]};if(n.length===s.length){for(let i of s)this.rules.other.tableAlignRight.test(i)?a.align.push("right"):this.rules.other.tableAlignCenter.test(i)?a.align.push("center"):this.rules.other.tableAlignLeft.test(i)?a.align.push("left"):a.align.push(null);for(let i=0;i<n.length;i++)a.header.push({text:n[i],tokens:this.lexer.inline(n[i]),header:!0,align:a.align[i]});for(let i of r)a.rows.push(Le(i,a.header.length).map((l,o)=>({text:l,tokens:this.lexer.inline(l),header:!1,align:a.align[o]})));return a}}lheading(t){let e=this.rules.block.lheading.exec(t);if(e){let n=e[1].trim();return{type:"heading",raw:e[0],depth:e[2].charAt(0)==="="?1:2,text:n,tokens:this.lexer.inline(n)}}}paragraph(t){let e=this.rules.block.paragraph.exec(t);if(e){let n=e[1].charAt(e[1].length-1)===`
`?e[1].slice(0,-1):e[1];return{type:"paragraph",raw:e[0],text:n,tokens:this.lexer.inline(n)}}}text(t){let e=this.rules.block.text.exec(t);if(e)return{type:"text",raw:e[0],text:e[0],tokens:this.lexer.inline(e[0])}}escape(t){let e=this.rules.inline.escape.exec(t);if(e)return{type:"escape",raw:e[0],text:e[1]}}tag(t){let e=this.rules.inline.tag.exec(t);if(e)return!this.lexer.state.inLink&&this.rules.other.startATag.test(e[0])?this.lexer.state.inLink=!0:this.lexer.state.inLink&&this.rules.other.endATag.test(e[0])&&(this.lexer.state.inLink=!1),!this.lexer.state.inRawBlock&&this.rules.other.startPreScriptTag.test(e[0])?this.lexer.state.inRawBlock=!0:this.lexer.state.inRawBlock&&this.rules.other.endPreScriptTag.test(e[0])&&(this.lexer.state.inRawBlock=!1),{type:"html",raw:e[0],inLink:this.lexer.state.inLink,inRawBlock:this.lexer.state.inRawBlock,block:!1,text:e[0]}}link(t){let e=this.rules.inline.link.exec(t);if(e){let n=e[2].trim();if(!this.options.pedantic&&this.rules.other.startAngleBracket.test(n)){if(!this.rules.other.endAngleBracket.test(n))return;let a=U(n.slice(0,-1),"\\");if((n.length-a.length)%2===0)return}else{let a=sr(e[2],"()");if(a===-2)return;if(a>-1){let i=(e[0].indexOf("!")===0?5:4)+e[1].length+a;e[2]=e[2].substring(0,a),e[0]=e[0].substring(0,i).trim(),e[3]=""}}let s=e[2],r="";if(this.options.pedantic){let a=this.rules.other.pedanticHrefTitle.exec(s);a&&(s=a[1],r=a[3])}else r=e[3]?e[3].slice(1,-1):"";return s=s.trim(),this.rules.other.startAngleBracket.test(s)&&(this.options.pedantic&&!this.rules.other.endAngleBracket.test(n)?s=s.slice(1):s=s.slice(1,-1)),Ie(e,{href:s&&s.replace(this.rules.inline.anyPunctuation,"$1"),title:r&&r.replace(this.rules.inline.anyPunctuation,"$1")},e[0],this.lexer,this.rules)}}reflink(t,e){let n;if((n=this.rules.inline.reflink.exec(t))||(n=this.rules.inline.nolink.exec(t))){let s=(n[2]||n[1]).replace(this.rules.other.multipleSpaceGlobal," "),r=e[s.toLowerCase()];if(!r){let a=n[0].charAt(0);return{type:"text",raw:a,text:a}}return Ie(n,r,n[0],this.lexer,this.rules)}}emStrong(t,e,n=""){let s=this.rules.inline.emStrongLDelim.exec(t);if(!(!s||!s[1]&&!s[2]&&!s[3]&&!s[4]||s[4]&&n.match(this.rules.other.unicodeAlphaNumeric))&&(!(s[1]||s[3])||!n||this.rules.inline.punctuation.exec(n))){let r=[...s[0]].length-1,a,i,l=r,o=0,h=s[0][0]==="*"?this.rules.inline.emStrongRDelimAst:this.rules.inline.emStrongRDelimUnd;for(h.lastIndex=0,e=e.slice(-1*t.length+r);(s=h.exec(e))!==null;){if(a=s[1]||s[2]||s[3]||s[4]||s[5]||s[6],!a)continue;if(i=[...a].length,s[3]||s[4]){l+=i;continue}else if((s[5]||s[6])&&r%3&&!((r+i)%3)){o+=i;continue}if(l-=i,l>0)continue;i=Math.min(i,i+l+o);let c=[...s[0]][0].length,u=t.slice(0,r+s.index+c+i);if(Math.min(r,i)%2){let d=u.slice(1,-1);return{type:"em",raw:u,text:d,tokens:this.lexer.inlineTokens(d)}}let p=u.slice(2,-2);return{type:"strong",raw:u,text:p,tokens:this.lexer.inlineTokens(p)}}}}codespan(t){let e=this.rules.inline.code.exec(t);if(e){let n=e[2].replace(this.rules.other.newLineCharGlobal," "),s=this.rules.other.nonSpaceChar.test(n),r=this.rules.other.startingSpaceChar.test(n)&&this.rules.other.endingSpaceChar.test(n);return s&&r&&(n=n.substring(1,n.length-1)),{type:"codespan",raw:e[0],text:n}}}br(t){let e=this.rules.inline.br.exec(t);if(e)return{type:"br",raw:e[0]}}del(t,e,n=""){let s=this.rules.inline.delLDelim.exec(t);if(s&&(!s[1]||!n||this.rules.inline.punctuation.exec(n))){let r=[...s[0]].length-1,a,i,l=r,o=this.rules.inline.delRDelim;for(o.lastIndex=0,e=e.slice(-1*t.length+r);(s=o.exec(e))!==null;){if(a=s[1]||s[2]||s[3]||s[4]||s[5]||s[6],!a||(i=[...a].length,i!==r))continue;if(s[3]||s[4]){l+=i;continue}if(l-=i,l>0)continue;i=Math.min(i,i+l);let h=[...s[0]][0].length,c=t.slice(0,r+s.index+h+i),u=c.slice(r,-r);return{type:"del",raw:c,text:u,tokens:this.lexer.inlineTokens(u)}}}}autolink(t){let e=this.rules.inline.autolink.exec(t);if(e){let n,s;return e[2]==="@"?(n=e[1],s="mailto:"+n):(n=e[1],s=n),{type:"link",raw:e[0],text:n,href:s,tokens:[{type:"text",raw:n,text:n}]}}}url(t){let e;if(e=this.rules.inline.url.exec(t)){let n,s;if(e[2]==="@")n=e[0],s="mailto:"+n;else{let r;do r=e[0],e[0]=this.rules.inline._backpedal.exec(e[0])?.[0]??"";while(r!==e[0]);n=e[0],e[1]==="www."?s="http://"+e[0]:s=e[0]}return{type:"link",raw:e[0],text:n,href:s,tokens:[{type:"text",raw:n,text:n}]}}}inlineText(t){let e=this.rules.inline.text.exec(t);if(e){let n=this.lexer.state.inRawBlock;return{type:"text",raw:e[0],text:e[0],escaped:n}}}},L=class oe{tokens;options;state;inlineQueue;tokenizer;constructor(e){this.tokens=[],this.tokens.links=Object.create(null),this.options=e||O,this.options.tokenizer=this.options.tokenizer||new J,this.tokenizer=this.options.tokenizer,this.tokenizer.options=this.options,this.tokenizer.lexer=this,this.inlineQueue=[],this.state={inLink:!1,inRawBlock:!1,top:!0};let n={other:R,block:W.normal,inline:q.normal};this.options.pedantic?(n.block=W.pedantic,n.inline=q.pedantic):this.options.gfm&&(n.block=W.gfm,this.options.breaks?n.inline=q.breaks:n.inline=q.gfm),this.tokenizer.rules=n}static get rules(){return{block:W,inline:q}}static lex(e,n){return new oe(n).lex(e)}static lexInline(e,n){return new oe(n).inlineTokens(e)}lex(e){e=e.replace(R.carriageReturn,`
`),this.blockTokens(e,this.tokens);for(let n=0;n<this.inlineQueue.length;n++){let s=this.inlineQueue[n];this.inlineTokens(s.src,s.tokens)}return this.inlineQueue=[],this.tokens}blockTokens(e,n=[],s=!1){for(this.tokenizer.lexer=this,this.options.pedantic&&(e=e.replace(R.tabCharGlobal," ").replace(R.spaceLine,""));e;){let r;if(this.options.extensions?.block?.some(i=>(r=i.call({lexer:this},e,n))?(e=e.substring(r.raw.length),n.push(r),!0):!1))continue;if(r=this.tokenizer.space(e)){e=e.substring(r.raw.length);let i=n.at(-1);r.raw.length===1&&i!==void 0?i.raw+=`
`:n.push(r);continue}if(r=this.tokenizer.code(e)){e=e.substring(r.raw.length);let i=n.at(-1);i?.type==="paragraph"||i?.type==="text"?(i.raw+=(i.raw.endsWith(`
`)?"":`
`)+r.raw,i.text+=`
`+r.text,this.inlineQueue.at(-1).src=i.text):n.push(r);continue}if(r=this.tokenizer.fences(e)){e=e.substring(r.raw.length),n.push(r);continue}if(r=this.tokenizer.heading(e)){e=e.substring(r.raw.length),n.push(r);continue}if(r=this.tokenizer.hr(e)){e=e.substring(r.raw.length),n.push(r);continue}if(r=this.tokenizer.blockquote(e)){e=e.substring(r.raw.length),n.push(r);continue}if(r=this.tokenizer.list(e)){e=e.substring(r.raw.length),n.push(r);continue}if(r=this.tokenizer.html(e)){e=e.substring(r.raw.length),n.push(r);continue}if(r=this.tokenizer.def(e)){e=e.substring(r.raw.length);let i=n.at(-1);i?.type==="paragraph"||i?.type==="text"?(i.raw+=(i.raw.endsWith(`
`)?"":`
`)+r.raw,i.text+=`
`+r.raw,this.inlineQueue.at(-1).src=i.text):this.tokens.links[r.tag]||(this.tokens.links[r.tag]={href:r.href,title:r.title},n.push(r));continue}if(r=this.tokenizer.table(e)){e=e.substring(r.raw.length),n.push(r);continue}if(r=this.tokenizer.lheading(e)){e=e.substring(r.raw.length),n.push(r);continue}let a=e;if(this.options.extensions?.startBlock){let i=1/0,l=e.slice(1),o;this.options.extensions.startBlock.forEach(h=>{o=h.call({lexer:this},l),typeof o=="number"&&o>=0&&(i=Math.min(i,o))}),i<1/0&&i>=0&&(a=e.substring(0,i+1))}if(this.state.top&&(r=this.tokenizer.paragraph(a))){let i=n.at(-1);s&&i?.type==="paragraph"?(i.raw+=(i.raw.endsWith(`
`)?"":`
`)+r.raw,i.text+=`
`+r.text,this.inlineQueue.pop(),this.inlineQueue.at(-1).src=i.text):n.push(r),s=a.length!==e.length,e=e.substring(r.raw.length);continue}if(r=this.tokenizer.text(e)){e=e.substring(r.raw.length);let i=n.at(-1);i?.type==="text"?(i.raw+=(i.raw.endsWith(`
`)?"":`
`)+r.raw,i.text+=`
`+r.text,this.inlineQueue.pop(),this.inlineQueue.at(-1).src=i.text):n.push(r);continue}if(e){let i="Infinite loop on byte: "+e.charCodeAt(0);if(this.options.silent){console.error(i);break}else throw new Error(i)}}return this.state.top=!0,n}inline(e,n=[]){return this.inlineQueue.push({src:e,tokens:n}),n}inlineTokens(e,n=[]){this.tokenizer.lexer=this;let s=e,r=null;if(this.tokens.links){let o=Object.keys(this.tokens.links);if(o.length>0)for(;(r=this.tokenizer.rules.inline.reflinkSearch.exec(s))!==null;)o.includes(r[0].slice(r[0].lastIndexOf("[")+1,-1))&&(s=s.slice(0,r.index)+"["+"a".repeat(r[0].length-2)+"]"+s.slice(this.tokenizer.rules.inline.reflinkSearch.lastIndex))}for(;(r=this.tokenizer.rules.inline.anyPunctuation.exec(s))!==null;)s=s.slice(0,r.index)+"++"+s.slice(this.tokenizer.rules.inline.anyPunctuation.lastIndex);let a;for(;(r=this.tokenizer.rules.inline.blockSkip.exec(s))!==null;)a=r[2]?r[2].length:0,s=s.slice(0,r.index+a)+"["+"a".repeat(r[0].length-a-2)+"]"+s.slice(this.tokenizer.rules.inline.blockSkip.lastIndex);s=this.options.hooks?.emStrongMask?.call({lexer:this},s)??s;let i=!1,l="";for(;e;){i||(l=""),i=!1;let o;if(this.options.extensions?.inline?.some(c=>(o=c.call({lexer:this},e,n))?(e=e.substring(o.raw.length),n.push(o),!0):!1))continue;if(o=this.tokenizer.escape(e)){e=e.substring(o.raw.length),n.push(o);continue}if(o=this.tokenizer.tag(e)){e=e.substring(o.raw.length),n.push(o);continue}if(o=this.tokenizer.link(e)){e=e.substring(o.raw.length),n.push(o);continue}if(o=this.tokenizer.reflink(e,this.tokens.links)){e=e.substring(o.raw.length);let c=n.at(-1);o.type==="text"&&c?.type==="text"?(c.raw+=o.raw,c.text+=o.text):n.push(o);continue}if(o=this.tokenizer.emStrong(e,s,l)){e=e.substring(o.raw.length),n.push(o);continue}if(o=this.tokenizer.codespan(e)){e=e.substring(o.raw.length),n.push(o);continue}if(o=this.tokenizer.br(e)){e=e.substring(o.raw.length),n.push(o);continue}if(o=this.tokenizer.del(e,s,l)){e=e.substring(o.raw.length),n.push(o);continue}if(o=this.tokenizer.autolink(e)){e=e.substring(o.raw.length),n.push(o);continue}if(!this.state.inLink&&(o=this.tokenizer.url(e))){e=e.substring(o.raw.length),n.push(o);continue}let h=e;if(this.options.extensions?.startInline){let c=1/0,u=e.slice(1),p;this.options.extensions.startInline.forEach(d=>{p=d.call({lexer:this},u),typeof p=="number"&&p>=0&&(c=Math.min(c,p))}),c<1/0&&c>=0&&(h=e.substring(0,c+1))}if(o=this.tokenizer.inlineText(h)){e=e.substring(o.raw.length),o.raw.slice(-1)!=="_"&&(l=o.raw.slice(-1)),i=!0;let c=n.at(-1);c?.type==="text"?(c.raw+=o.raw,c.text+=o.text):n.push(o);continue}if(e){let c="Infinite loop on byte: "+e.charCodeAt(0);if(this.options.silent){console.error(c);break}else throw new Error(c)}}return n}},Y=class{options;parser;constructor(t){this.options=t||O}space(t){return""}code({text:t,lang:e,escaped:n}){let s=(e||"").match(R.notSpaceStart)?.[0],r=t.replace(R.endingNewline,"")+`
`;return s?'<pre><code class="language-'+z(s)+'">'+(n?r:z(r,!0))+`</code></pre>
`:"<pre><code>"+(n?r:z(r,!0))+`</code></pre>
`}blockquote({tokens:t}){return`<blockquote>
${this.parser.parse(t)}</blockquote>
`}html({text:t}){return t}def(t){return""}heading({tokens:t,depth:e}){return`<h${e}>${this.parser.parseInline(t)}</h${e}>
`}hr(t){return`<hr>
`}list(t){let e=t.ordered,n=t.start,s="";for(let i=0;i<t.items.length;i++){let l=t.items[i];s+=this.listitem(l)}let r=e?"ol":"ul",a=e&&n!==1?' start="'+n+'"':"";return"<"+r+a+`>
`+s+"</"+r+`>
`}listitem(t){return`<li>${this.parser.parse(t.tokens)}</li>
`}checkbox({checked:t}){return"<input "+(t?'checked="" ':"")+'disabled="" type="checkbox"> '}paragraph({tokens:t}){return`<p>${this.parser.parseInline(t)}</p>
`}table(t){let e="",n="";for(let r=0;r<t.header.length;r++)n+=this.tablecell(t.header[r]);e+=this.tablerow({text:n});let s="";for(let r=0;r<t.rows.length;r++){let a=t.rows[r];n="";for(let i=0;i<a.length;i++)n+=this.tablecell(a[i]);s+=this.tablerow({text:n})}return s&&(s=`<tbody>${s}</tbody>`),`<table>
<thead>
`+e+`</thead>
`+s+`</table>
`}tablerow({text:t}){return`<tr>
${t}</tr>
`}tablecell(t){let e=this.parser.parseInline(t.tokens),n=t.header?"th":"td";return(t.align?`<${n} align="${t.align}">`:`<${n}>`)+e+`</${n}>
`}strong({tokens:t}){return`<strong>${this.parser.parseInline(t)}</strong>`}em({tokens:t}){return`<em>${this.parser.parseInline(t)}</em>`}codespan({text:t}){return`<code>${z(t,!0)}</code>`}br(t){return"<br>"}del({tokens:t}){return`<del>${this.parser.parseInline(t)}</del>`}link({href:t,title:e,tokens:n}){let s=this.parser.parseInline(n),r=Ce(t);if(r===null)return s;t=r;let a='<a href="'+t+'"';return e&&(a+=' title="'+z(e)+'"'),a+=">"+s+"</a>",a}image({href:t,title:e,text:n,tokens:s}){s&&(n=this.parser.parseInline(s,this.parser.textRenderer));let r=Ce(t);if(r===null)return z(n);t=r;let a=`<img src="${t}" alt="${z(n)}"`;return e&&(a+=` title="${z(e)}"`),a+=">",a}text(t){return"tokens"in t&&t.tokens?this.parser.parseInline(t.tokens):"escaped"in t&&t.escaped?t.text:z(t.text)}},ye=class{strong({text:t}){return t}em({text:t}){return t}codespan({text:t}){return t}del({text:t}){return t}html({text:t}){return t}text({text:t}){return t}link({text:t}){return""+t}image({text:t}){return""+t}br(){return""}checkbox({raw:t}){return t}},I=class le{options;renderer;textRenderer;constructor(e){this.options=e||O,this.options.renderer=this.options.renderer||new Y,this.renderer=this.options.renderer,this.renderer.options=this.options,this.renderer.parser=this,this.textRenderer=new ye}static parse(e,n){return new le(n).parse(e)}static parseInline(e,n){return new le(n).parseInline(e)}parse(e){this.renderer.parser=this;let n="";for(let s=0;s<e.length;s++){let r=e[s];if(this.options.extensions?.renderers?.[r.type]){let i=r,l=this.options.extensions.renderers[i.type].call({parser:this},i);if(l!==!1||!["space","hr","heading","code","table","blockquote","list","html","def","paragraph","text"].includes(i.type)){n+=l||"";continue}}let a=r;switch(a.type){case"space":{n+=this.renderer.space(a);break}case"hr":{n+=this.renderer.hr(a);break}case"heading":{n+=this.renderer.heading(a);break}case"code":{n+=this.renderer.code(a);break}case"table":{n+=this.renderer.table(a);break}case"blockquote":{n+=this.renderer.blockquote(a);break}case"list":{n+=this.renderer.list(a);break}case"checkbox":{n+=this.renderer.checkbox(a);break}case"html":{n+=this.renderer.html(a);break}case"def":{n+=this.renderer.def(a);break}case"paragraph":{n+=this.renderer.paragraph(a);break}case"text":{n+=this.renderer.text(a);break}default:{let i='Token with "'+a.type+'" type was not found.';if(this.options.silent)return console.error(i),"";throw new Error(i)}}}return n}parseInline(e,n=this.renderer){this.renderer.parser=this;let s="";for(let r=0;r<e.length;r++){let a=e[r];if(this.options.extensions?.renderers?.[a.type]){let l=this.options.extensions.renderers[a.type].call({parser:this},a);if(l!==!1||!["escape","html","link","image","strong","em","codespan","br","del","text"].includes(a.type)){s+=l||"";continue}}let i=a;switch(i.type){case"escape":{s+=n.text(i);break}case"html":{s+=n.html(i);break}case"link":{s+=n.link(i);break}case"image":{s+=n.image(i);break}case"checkbox":{s+=n.checkbox(i);break}case"strong":{s+=n.strong(i);break}case"em":{s+=n.em(i);break}case"codespan":{s+=n.codespan(i);break}case"br":{s+=n.br(i);break}case"del":{s+=n.del(i);break}case"text":{s+=n.text(i);break}default:{let l='Token with "'+i.type+'" type was not found.';if(this.options.silent)return console.error(l),"";throw new Error(l)}}}return s}},Z=class{options;block;constructor(t){this.options=t||O}static passThroughHooks=new Set(["preprocess","postprocess","processAllTokens","emStrongMask"]);static passThroughHooksRespectAsync=new Set(["preprocess","postprocess","processAllTokens"]);preprocess(t){return t}postprocess(t){return t}processAllTokens(t){return t}emStrongMask(t){return t}provideLexer(t=this.block){return t?L.lex:L.lexInline}provideParser(t=this.block){return t?I.parse:I.parseInline}},or=class{defaults=de();options=this.setOptions;parse=this.parseMarkdown(!0);parseInline=this.parseMarkdown(!1);Parser=I;Renderer=Y;TextRenderer=ye;Lexer=L;Tokenizer=J;Hooks=Z;constructor(...t){this.use(...t)}walkTokens(t,e){let n=[];for(let s of t)switch(n=n.concat(e.call(this,s)),s.type){case"table":{let r=s;for(let a of r.header)n=n.concat(this.walkTokens(a.tokens,e));for(let a of r.rows)for(let i of a)n=n.concat(this.walkTokens(i.tokens,e));break}case"list":{let r=s;n=n.concat(this.walkTokens(r.items,e));break}default:{let r=s;this.defaults.extensions?.childTokens?.[r.type]?this.defaults.extensions.childTokens[r.type].forEach(a=>{let i=r[a].flat(1/0);n=n.concat(this.walkTokens(i,e))}):r.tokens&&(n=n.concat(this.walkTokens(r.tokens,e)))}}return n}use(...t){let e=this.defaults.extensions||{renderers:{},childTokens:{}};return t.forEach(n=>{let s={...n};if(s.async=this.defaults.async||s.async||!1,n.extensions&&(n.extensions.forEach(r=>{if(!r.name)throw new Error("extension name required");if("renderer"in r){let a=e.renderers[r.name];a?e.renderers[r.name]=function(...i){let l=r.renderer.apply(this,i);return l===!1&&(l=a.apply(this,i)),l}:e.renderers[r.name]=r.renderer}if("tokenizer"in r){if(!r.level||r.level!=="block"&&r.level!=="inline")throw new Error("extension level must be 'block' or 'inline'");let a=e[r.level];a?a.unshift(r.tokenizer):e[r.level]=[r.tokenizer],r.start&&(r.level==="block"?e.startBlock?e.startBlock.push(r.start):e.startBlock=[r.start]:r.level==="inline"&&(e.startInline?e.startInline.push(r.start):e.startInline=[r.start]))}"childTokens"in r&&r.childTokens&&(e.childTokens[r.name]=r.childTokens)}),s.extensions=e),n.renderer){let r=this.defaults.renderer||new Y(this.defaults);for(let a in n.renderer){if(!(a in r))throw new Error(`renderer '${a}' does not exist`);if(["options","parser"].includes(a))continue;let i=a,l=n.renderer[i],o=r[i];r[i]=(...h)=>{let c=l.apply(r,h);return c===!1&&(c=o.apply(r,h)),c||""}}s.renderer=r}if(n.tokenizer){let r=this.defaults.tokenizer||new J(this.defaults);for(let a in n.tokenizer){if(!(a in r))throw new Error(`tokenizer '${a}' does not exist`);if(["options","rules","lexer"].includes(a))continue;let i=a,l=n.tokenizer[i],o=r[i];r[i]=(...h)=>{let c=l.apply(r,h);return c===!1&&(c=o.apply(r,h)),c}}s.tokenizer=r}if(n.hooks){let r=this.defaults.hooks||new Z;for(let a in n.hooks){if(!(a in r))throw new Error(`hook '${a}' does not exist`);if(["options","block"].includes(a))continue;let i=a,l=n.hooks[i],o=r[i];Z.passThroughHooks.has(a)?r[i]=h=>{if(this.defaults.async&&Z.passThroughHooksRespectAsync.has(a))return(async()=>{let u=await l.call(r,h);return o.call(r,u)})();let c=l.call(r,h);return o.call(r,c)}:r[i]=(...h)=>{if(this.defaults.async)return(async()=>{let u=await l.apply(r,h);return u===!1&&(u=await o.apply(r,h)),u})();let c=l.apply(r,h);return c===!1&&(c=o.apply(r,h)),c}}s.hooks=r}if(n.walkTokens){let r=this.defaults.walkTokens,a=n.walkTokens;s.walkTokens=function(i){let l=[];return l.push(a.call(this,i)),r&&(l=l.concat(r.call(this,i))),l}}this.defaults={...this.defaults,...s}}),this}setOptions(t){return this.defaults={...this.defaults,...t},this}lexer(t,e){return L.lex(t,e??this.defaults)}parser(t,e){return I.parse(t,e??this.defaults)}parseMarkdown(t){return(e,n)=>{let s={...n},r={...this.defaults,...s},a=this.onError(!!r.silent,!!r.async);if(this.defaults.async===!0&&s.async===!1)return a(new Error("marked(): The async option was set to true by an extension. Remove async: false from the parse options object to return a Promise."));if(typeof e>"u"||e===null)return a(new Error("marked(): input parameter is undefined or null"));if(typeof e!="string")return a(new Error("marked(): input parameter is of type "+Object.prototype.toString.call(e)+", string expected"));if(r.hooks&&(r.hooks.options=r,r.hooks.block=t),r.async)return(async()=>{let i=r.hooks?await r.hooks.preprocess(e):e,l=await(r.hooks?await r.hooks.provideLexer(t):t?L.lex:L.lexInline)(i,r),o=r.hooks?await r.hooks.processAllTokens(l):l;r.walkTokens&&await Promise.all(this.walkTokens(o,r.walkTokens));let h=await(r.hooks?await r.hooks.provideParser(t):t?I.parse:I.parseInline)(o,r);return r.hooks?await r.hooks.postprocess(h):h})().catch(a);try{r.hooks&&(e=r.hooks.preprocess(e));let i=(r.hooks?r.hooks.provideLexer(t):t?L.lex:L.lexInline)(e,r);r.hooks&&(i=r.hooks.processAllTokens(i)),r.walkTokens&&this.walkTokens(i,r.walkTokens);let l=(r.hooks?r.hooks.provideParser(t):t?I.parse:I.parseInline)(i,r);return r.hooks&&(l=r.hooks.postprocess(l)),l}catch(i){return a(i)}}}onError(t,e){return n=>{if(n.message+=`
Please report this to https://github.com/markedjs/marked.`,t){let s="<p>An error occurred:</p><pre>"+z(n.message+"",!0)+"</pre>";return e?Promise.resolve(s):s}if(e)return Promise.reject(n);throw n}}},H=new or;function E(t,e){return H.parse(t,e)}E.options=E.setOptions=function(t){return H.setOptions(t),E.defaults=H.defaults,We(E.defaults),E};E.getDefaults=de;E.defaults=O;E.use=function(...t){return H.use(...t),E.defaults=H.defaults,We(E.defaults),E};E.walkTokens=function(t,e){return H.walkTokens(t,e)};E.parseInline=H.parseInline;E.Parser=I;E.parser=I.parse;E.Renderer=Y;E.TextRenderer=ye;E.Lexer=L;E.lexer=L.lex;E.Tokenizer=J;E.Hooks=Z;E.parse=E;E.options;E.setOptions;E.use;E.walkTokens;E.parseInline;I.parse;L.lex;const lr=/\n[^\S\n]*(?:\n[^\S\n]*)+$/;function cr(t){return t.flatMap((e,n)=>{var s;if(e.type==="space"||((s=t[n+1])===null||s===void 0?void 0:s.type)==="space")return[e];const r=(e.raw||"").match(lr);return r?[{...e,raw:(e.raw||"").slice(0,-r[0].length)},{type:"space",raw:r[0]}]:[e]})}function ur(t,e){const n=e.split(`
`).flatMap(s=>[s,""]).map(s=>`${t}${s}`).join(`
`);return n.slice(0,n.length-1)}function hr(t,e){const n=[];return Array.from(t.entries()).forEach(([s,r])=>{if(!e){n.push(s);return}(e.marks||[]).find(a=>a.type===s&&G(a.attrs,r.attrs))||n.push(s)}),n}function pr(t,e){const n=[];return Array.from(e.entries()).forEach(([s,r])=>{const a=t.get(s);(!a||!G(a.attrs,r.attrs))&&n.push({type:s,mark:r})}),n}function dr(t,e,n,s){const r=!n,a=n&&(!n.marks||n.marks.length===0),i=n&&n.marks&&!s(e,new Map(n.marks.map(o=>[o.type,o]))),l=[];return(r||a||i)&&(n&&n.marks?Array.from(t.entries()).reverse().forEach(([o,h])=>{n.marks.find(c=>c.type===o&&G(c.attrs,h.attrs))||l.push(o)}):(r||a)&&l.push(...Array.from(t.keys()).reverse())),l}function fr(t,e){let n="";return Array.from(t.keys()).reverse().forEach(s=>{const r=e(s,t.get(s));r&&(n=r+n)}),t.clear(),n}function gr(t,e,n){let s="";return Array.from(t.entries()).forEach(([r,a])=>{const i=n(r,a);i&&(s+=i),e.set(r,a)}),s}function re(t){const e=(t.raw||t.text||"").match(/^(\s*)[-+*]\s+\[([ xX])\]\s+/);return e?{isTask:!0,checked:e[2].toLowerCase()==="x",indentLevel:e[1].length}:{isTask:!1,indentLevel:0}}function Q(t,e){return typeof t!="string"?"json":e}const mr=new Set(["a","abbr","address","area","article","aside","audio","b","base","bdi","bdo","blockquote","body","br","button","canvas","caption","cite","code","col","colgroup","data","datalist","dd","del","details","dfn","dialog","div","dl","dt","em","embed","fieldset","figcaption","figure","footer","form","h1","h2","h3","h4","h5","h6","head","header","hgroup","hr","html","i","iframe","img","input","ins","kbd","label","legend","li","link","main","map","mark","menu","meta","meter","nav","noscript","object","ol","optgroup","option","output","p","param","picture","pre","progress","q","rp","rt","ruby","s","samp","script","search","section","select","slot","small","source","span","strong","style","sub","summary","sup","svg","circle","clippath","defs","ellipse","foreignobject","g","image","line","lineargradient","mask","path","polygon","polyline","radialgradient","rect","stop","switch","symbol","textpath","tspan","use","table","tbody","td","template","textarea","tfoot","th","thead","time","title","tr","track","u","ul","var","video","wbr"]),kr=/<\/?([a-zA-Z][\w-]*)/g;function xr(t){const e=[];let n;for(;(n=kr.exec(t))!==null;)e.push(n[1].toLowerCase());return e}function br(t){const e=t.toLowerCase();return e.includes("-")?!1:!mr.has(e)}function wr(t,e){return xr(t).some(n=>br(n)?!e.has(n):!1)}var ze=class{constructor(t){var e,n,s,r,a;this.activeParseLexer=null,this.extensionRanks=new Map,this.baseExtensions=[],this.extensions=[],this.codeTypes=new Set,this.schemaParseDomTagsCache=null,this.inlineNodeTypesCache=null,this.lastParseResult=null,this.markedInstance=(e=t?.marked)!==null&&e!==void 0?e:E,this.indentStyle=(n=t==null||(s=t.indentation)===null||s===void 0?void 0:s.style)!==null&&n!==void 0?n:"space",this.indentSize=(r=t==null||(a=t.indentation)===null||a===void 0?void 0:a.size)!==null&&r!==void 0?r:2,this.baseExtensions=t?.extensions||[],t?.markedOptions&&typeof this.markedInstance.setOptions=="function"&&this.markedInstance.setOptions(t.markedOptions),this.registry=new Map,this.nodeTypeRegistry=new Map,t?.extensions&&(this.baseExtensions=t.extensions,mt(kt(t.extensions)).forEach(i=>this.registerExtension(i)))}get instance(){return this.markedInstance}get indentCharacter(){return this.indentStyle==="space"?" ":" "}get indentString(){return this.indentCharacter.repeat(this.indentSize)}hasMarked(){return!!this.markedInstance}registerExtension(t){var e,n;this.extensions.push(t);const s=xt(D(t,"code")),r=t.name;s&&this.codeTypes.add(r),this.extensionRanks.has(r)||this.extensionRanks.set(r,this.extensionRanks.size);const a=D(t,"markdownTokenName")||r,i=D(t,"parseMarkdown"),l=D(t,"renderMarkdown"),o=D(t,"markdownTokenizer"),h=(e=D(t,"markdownOptions"))!==null&&e!==void 0?e:null,c={tokenName:a,nodeName:r,parseMarkdown:i,renderMarkdown:l,isIndenting:(n=h?.indentsContent)!==null&&n!==void 0?n:!1,htmlReopen:h?.htmlReopen,tokenizer:o};if(a&&i){const u=this.registry.get(a)||[];u.push(c),this.registry.set(a,u)}if(l){const u=this.nodeTypeRegistry.get(r)||[];u.push(c),this.nodeTypeRegistry.set(r,u)}o&&this.hasMarked()&&this.registerTokenizer(o)}createLexer(){return new this.markedInstance.Lexer(this.markedInstance.defaults)}createTokenizerHelpers(t){return{inlineTokens:e=>t.inlineTokens(e),blockTokens:e=>t.blockTokens(e)}}tokenizeInline(t){var e;return((e=this.activeParseLexer)!==null&&e!==void 0?e:this.createLexer()).inlineTokens(t)}registerTokenizer(t){if(!this.hasMarked())return;const{name:e,start:n,level:s="inline",tokenize:r}=t,a=this.createTokenizerHelpers.bind(this),i=this.createLexer.bind(this);let l;n?l=typeof n=="function"?n:h=>h.indexOf(n):l=h=>{const c=r(h,[],this.createTokenizerHelpers(this.createLexer()));return c&&c.raw?h.indexOf(c.raw):-1};const o={name:e,level:s,start:l,tokenizer(h,c){const u=this.lexer?a(this.lexer):a(i()),p=r(h,c,u);if(p&&p.type)return{...p,type:p.type||e,raw:p.raw||"",tokens:p.tokens||[]}},childTokens:[]};this.markedInstance.use({extensions:[o]})}getHandlersForToken(t){try{return this.registry.get(t)||[]}catch{return[]}}getHandlerForToken(t){const e=this.getHandlersForToken(t);if(e.length>0)return e[0];const n=this.getHandlersForNodeType(t);return n.length>0?n[0]:void 0}getHandlersForNodeType(t){try{return this.nodeTypeRegistry.get(t)||[]}catch{return[]}}serialize(t){if(!t)return"";const e=this.renderNodes(t,t);return this.isEmptyOutput(e)?"":e}isEmptyOutput(t){return!t||t.trim()===""?!0:t.replace(/ /g,"").replace(/\u00A0/g,"").trim()===""}parse(t){if(!this.hasMarked())throw new Error("No marked instance available for parsing");const e=this.activeParseLexer,n=this.createLexer();this.activeParseLexer=n;try{const s=n.lex(t);return{type:"doc",content:this.parseTokens(s,!0)}}finally{this.activeParseLexer=e}}parseTokens(t,e=!1){const n=e?cr(t):t,s=n.reduce((i,l,o)=>(l.type!=="space"&&i.push(o),i),[]);let r=-1,a=0;return n.flatMap((i,l)=>{for(;a<s.length&&s[a]<l;)r=s[a],a+=1;if(e&&i.type==="space"){var o;const c=(o=s[a])!==null&&o!==void 0?o:-1;return this.createImplicitEmptyParagraphsFromSpace(i,r,c)}const h=this.parseToken(i,e);return h===null?[]:Array.isArray(h)?h:[h]})}createImplicitEmptyParagraphsFromSpace(t,e,n){const s=this.countParagraphSeparators(t.raw||"");if(s===0)return[];const r=Math.max(s-(e===-1||n===-1?0:1),0);return Array.from({length:r},()=>({type:"paragraph",content:[]}))}countParagraphSeparators(t){return(t.replace(/\r\n/g,`
`).match(/\n\n/g)||[]).length}parseToken(t,e=!1){if(!t.type)return null;if(t.type==="list")return this.parseListToken(t);const n=this.getHandlersForToken(t.type),s=this.createParseHelpers();if(n.find(r=>{if(!r.parseMarkdown)return!1;const a=r.parseMarkdown(t,s),i=this.normalizeParseResult(a);return i&&(!Array.isArray(i)||i.length>0)?(this.lastParseResult=i,!0):!1})&&this.lastParseResult){const r=this.lastParseResult;return this.lastParseResult=null,r}return this.parseFallbackToken(t,e)}parseListToken(t){if(!t.items||t.items.length===0)return this.parseTokenWithHandlers(t);const e=t.items.some(l=>re(l).isTask),n=t.items.some(l=>!re(l).isTask);if(!e||!n||this.getHandlersForToken("taskList").length===0)return this.parseTokenWithHandlers(t);const s=[];let r=[],a=null;for(let l=0;l<t.items.length;l+=1){const o=t.items[l],{isTask:h,checked:c,indentLevel:u}=re(o);let p=o;if(h){const g=(o.raw||o.text||"").split(`
`),x=g[0].match(/^\s*[-+*]\s+\[([ xX])\]\s+(.*)$/),w=x?x[2]:"";let b=[];if(g.length>1&&g.slice(1).join(`
`).trim()){const y=g.slice(1),v=y.filter(M=>M.trim());if(v.length>0){const M=Math.min(...v.map(k=>k.length-k.trimStart().length)),m=y.map(k=>k.trim()?k.slice(M):"").join(`
`).trim();m&&(b=this.markedInstance.lexer(`${m}
`))}}p={type:"taskItem",raw:"",mainContent:w,indentLevel:u,checked:c??!1,text:w,tokens:this.tokenizeInline(w),nestedTokens:b}}const d=h?"taskList":"list";a!==d?(r.length>0&&s.push({type:a,items:r}),r=[p],a=d):r.push(p)}r.length>0&&s.push({type:a,items:r});const i=[];for(let l=0;l<s.length;l+=1){const o=s[l],h={...t,type:o.type,items:o.items},c=this.parseToken(h);c&&(Array.isArray(c)?i.push(...c):i.push(c))}return i.length>0?i:null}parseTokenWithHandlers(t){if(!t.type)return null;const e=this.getHandlersForToken(t.type),n=this.createParseHelpers();if(e.find(s=>{if(!s.parseMarkdown)return!1;const r=s.parseMarkdown(t,n),a=this.normalizeParseResult(r);return a&&(!Array.isArray(a)||a.length>0)?(this.lastParseResult=a,!0):!1})&&this.lastParseResult){const s=this.lastParseResult;return this.lastParseResult=null,s}return this.parseFallbackToken(t)}createParseHelpers(){return{parseInline:t=>this.parseInlineTokens(t),tokenizeInline:t=>this.tokenizeInline(t),parseChildren:t=>this.parseTokens(t),parseBlockChildren:t=>this.parseTokens(t,!0),createTextNode:(t,e)=>({type:"text",text:t,marks:e||void 0}),createNode:(t,e,n)=>{const s={type:t,attrs:e||void 0,content:n||void 0};return(!e||Object.keys(e).length===0)&&delete s.attrs,s},applyMark:(t,e,n)=>({mark:t,content:e,attrs:n&&Object.keys(n).length>0?n:void 0})}}escapeRegex(t){return t.replace(/[.*+?^${}()|[\]\\]/g,"\\$&")}parseInlineTokens(t){const e=[];for(let i=0;i<t.length;i+=1){const l=t[i];if(l.type==="text")e.push({type:"text",text:ve(l.text||"")});else if(l.type==="escape")e.push({type:"text",text:l.text||""});else if(l.type==="html"){var n,s;const o=((n=(s=l.raw)!==null&&s!==void 0?s:l.text)!==null&&n!==void 0?n:"").toString(),h=/^<\/[\s]*[\w-]+/i.test(o),c=o.match(/^<[\s]*([\w-]+)(\s|>|\/|$)/i);if(!h&&c&&!/\/>$/.test(o)){const p=c[1],d=this.escapeRegex(p),g=new RegExp(`^<\\/\\s*${d}\\b`,"i");let x=-1;const w=[o];for(let b=i+1;b<t.length;b+=1){var r,a;const y=t[b],v=((r=(a=y.raw)!==null&&a!==void 0?a:y.text)!==null&&r!==void 0?r:"").toString();if(w.push(v),y.type==="html"&&g.test(v)){x=b;break}}if(x!==-1){const b=w.join(""),y={type:"html",raw:b,text:b,block:!1},v=this.parseHTMLToken(y);if(v){const M=this.normalizeParseResult(v);Array.isArray(M)?e.push(...M):M&&e.push(M)}i=x;continue}}const u=this.parseHTMLToken(l);if(u){const p=this.normalizeParseResult(u);Array.isArray(p)?e.push(...p):p&&e.push(p)}}else if(l.type){const o=this.getHandlerForToken(l.type);if(o&&o.parseMarkdown){const h=this.createParseHelpers(),c=o.parseMarkdown(l,h);if(this.isMarkResult(c)){const u=this.applyMarkToContent(c.mark,c.content,c.attrs);e.push(...u)}else{const u=this.normalizeParseResult(c);Array.isArray(u)?e.push(...u):u&&e.push(u)}}else l.tokens&&e.push(...this.parseInlineTokens(l.tokens))}}for(let i=e.length-1;i>0;i-=1){const l=e[i],o=e[i-1];if(l.type==="text"&&o.type==="text"){const h=l.marks||[],c=o.marks||[];bt(h,c)&&(o.text=(o.text||"")+(l.text||""),e.splice(i,1))}}return e}applyMarkToContent(t,e,n){return e.map(s=>{if(s.type==="text"){const r=s.marks||[],a=n?{type:t,attrs:n}:{type:t};return{...s,marks:[...r,a]}}return{...s,content:s.content?this.applyMarkToContent(t,s.content,n):void 0}})}isMarkResult(t){return t&&typeof t=="object"&&"mark"in t}normalizeParseResult(t){return t?this.isMarkResult(t)?t.content:t:null}parseFallbackToken(t,e=!1){switch(t.type){case"paragraph":return{type:"paragraph",content:t.tokens?this.parseInlineTokens(t.tokens):[]};case"heading":return{type:"heading",attrs:{level:t.depth||1},content:t.tokens?this.parseInlineTokens(t.tokens):[]};case"text":return{type:"text",text:ve(t.text||"")};case"html":return this.parseHTMLToken(t);case"escape":return{type:"text",text:t.text||""};case"space":return null;default:return t.tokens?this.parseTokens(t.tokens,e):null}}parseHTMLToken(t){const e=t.text||t.raw||"";if(!e.trim())return null;if(this.isUnrecognizedHtml(e))return this.htmlAsLiteralText(e,!!t.block);if(typeof window>"u"||typeof window.DOMParser>"u")return this.htmlAsLiteralText(e,!!t.block);try{const n=wt(e,this.baseExtensions);if(n.type==="doc"&&n.content){if(t.block)return n.content;const s=this.toInlineContent(n.content);return s.length>0?s:null}return n}catch(n){throw new Error(`Failed to parse HTML in markdown: ${n}`)}}toInlineContent(t){const e=this.getInlineNodeTypes();return t.flatMap(n=>n.type&&e.has(n.type)?[n]:n.content?this.toInlineContent(n.content):[])}getInlineNodeTypes(){if(this.inlineNodeTypesCache)return this.inlineNodeTypesCache;const t=new Set(["text"]);try{const e=Se(this.baseExtensions);Object.values(e.nodes).forEach(n=>{n.isInline&&t.add(n.name)})}catch{}return this.inlineNodeTypesCache=t,t}isUnrecognizedHtml(t){return wr(t,this.getSchemaParseDomTags())}getSchemaParseDomTags(){if(this.schemaParseDomTagsCache)return this.schemaParseDomTagsCache;const t=new Set;try{const e=Se(this.baseExtensions),n=s=>{const r=s?.parseDOM;Array.isArray(r)&&r.forEach(a=>{if(typeof a?.tag=="string"){const i=a.tag.match(/^[a-zA-Z][\w-]*/);i&&t.add(i[0].toLowerCase())}})};Object.values(e.nodes).forEach(s=>n(s.spec)),Object.values(e.marks).forEach(s=>n(s.spec))}catch{}return this.schemaParseDomTagsCache=t,t}htmlAsLiteralText(t,e){const n=t.replace(/\s+$/,"");return n?e?{type:"paragraph",content:[{type:"text",text:n}]}:{type:"text",text:n}:null}encodeTextForMarkdown(t,e,n){return n?.type!=null&&this.codeTypes.has(n.type)||(e.marks||[]).some(s=>this.codeTypes.has(typeof s=="string"?s:s.type))?t:this.escapeMarkdownSyntax(yt(t))}escapeMarkdownSyntax(t){return t.replace(/([\\`*_[\]~])/g,"\\$1")}renderNodeToMarkdown(t,e,n=0,s=0,r={}){var a;if(t.type==="text")return this.encodeTextForMarkdown(t.text||"",t,e);if(!t.type)return"";const i=this.getHandlerForToken(t.type);if(!i)return"";const l=Array.isArray(e?.content)&&n>0?e.content[n-1]:void 0,o={renderChildren:(c,u)=>{const p=i.isIndenting?s+1:s;return!Array.isArray(c)&&c.content?this.renderNodes(c.content,t,u||"",n,p):this.renderNodes(c,t,u||"",n,p)},renderChild:(c,u)=>{const p=i.isIndenting?s+1:s;return this.renderNodeToMarkdown(c,t,u,p)},indent:c=>this.indentString+c,wrapInBlock:ur},h={index:n,level:s,parentType:e?.type,previousNode:l,meta:{parentAttrs:e?.attrs,...r}};return((a=i.renderMarkdown)===null||a===void 0?void 0:a.call(i,t,o,h))||""}renderNodes(t,e,n="",s=0,r=0){return Array.isArray(t)?this.renderNodesWithMarkBoundaries(t,e,n,r):t.type?this.renderNodeToMarkdown(t,e,s,r):""}renderNodesWithMarkBoundaries(t,e,n="",s=0){const r=[],a=new Map,i=new Set,l=new Map;return t.forEach((o,h)=>{const c=h<t.length-1?t[h+1]:null;if(o.type)if(o.type==="text"){let u=this.encodeTextForMarkdown(o.text||"",o,e);const p=new Map((o.marks||[]).map(m=>[m.type,m])),d=this.getMarksToOpenForSerialization(a,p,c),g=hr(p,c),x=g.filter(m=>a.has(m)),w=x.length>0&&d.length>0;let b="";if(g.length>0&&!w){const m=u.match(/(\s+)$/);m&&(b=m[1],u=u.slice(0,-b.length))}w||g.slice().reverse().forEach(m=>{if(!a.has(m))return;const k=p.get(m),T=this.getMarkClosing(m,k,l.get(m));T&&(u+=T),a.has(m)&&(a.delete(m),l.delete(m))});let y="";if(d.length>0){const m=u.match(/^(\s+)/);m&&(y=m[1],u=u.slice(y.length))}d.forEach(({type:m,mark:k})=>{const T=i.has(m)?"html":"markdown",A=this.getMarkOpening(m,k,T);A&&(u=A+u),l.set(m,T),i.delete(m)}),w||d.slice().reverse().forEach(({type:m,mark:k})=>{a.set(m,k)}),u=y+u;let v;if(w){const m=new Set((c?.marks||[]).map(A=>A.type));d.forEach(({type:A})=>{m.has(A)&&this.getHtmlReopenTags(A)&&i.add(A)});const k=Array.from(a.keys()),T=x.slice().sort((A,it)=>k.indexOf(it)-k.indexOf(A));v=[...d.map(A=>A.type),...T]}else v=dr(a,p,c,this.markSetsEqual.bind(this));let M="";if(v.length>0){const m=u.match(/(\s+)$/);m&&(M=m[1],u=u.slice(0,-M.length))}v.forEach(m=>{var k;const T=(k=a.get(m))!==null&&k!==void 0?k:p.get(m),A=this.getMarkClosing(m,T,l.get(m));A&&(u+=A),a.delete(m),l.delete(m)}),u+=M,u+=b,r.push(u)}else{const u=new Set((o.marks||[]).map(b=>b.type)),p=new Map,d=new Map;a.forEach((b,y)=>{if(u.has(y)){var v;p.set(y,b),d.set(y,(v=l.get(y))!==null&&v!==void 0?v:"markdown")}});const g=fr(a,(b,y)=>this.getMarkClosing(b,y,l.get(b)));l.clear();const x=this.renderNodeToMarkdown(o,e,h,s),w=o.type==="hardBreak"?"":gr(p,a,(b,y)=>{var v;const M=(v=d.get(b))!==null&&v!==void 0?v:"markdown";return l.set(b,M),this.getMarkOpening(b,y,M)});r.push(g+x+w)}}),r.join(n)}getMarkOpening(t,e,n="markdown"){if(n==="html"){var s;return((s=this.getHtmlReopenTags(t))===null||s===void 0?void 0:s.open)||""}const r=this.getHandlersForNodeType(t),a=r.length>0?r[0]:void 0;if(!a||!a.renderMarkdown)return"";const i="__TIPTAP_MARKDOWN_PLACEHOLDER__",l={type:t,attrs:e.attrs||{},content:[{type:"text",text:i}]};try{const o=a.renderMarkdown(l,{renderChildren:()=>i,renderChild:()=>i,indent:c=>c,wrapInBlock:(c,u)=>c+u},{index:0,level:0,parentType:"text",meta:{}}),h=o.indexOf(i);return h>=0?o.substring(0,h):""}catch(o){throw new Error(`Failed to get mark opening for ${t}: ${o}`)}}getMarkClosing(t,e,n="markdown"){if(n==="html"){var s;return((s=this.getHtmlReopenTags(t))===null||s===void 0?void 0:s.close)||""}const r=this.getHandlersForNodeType(t),a=r.length>0?r[0]:void 0;if(!a||!a.renderMarkdown)return"";const i="__TIPTAP_MARKDOWN_PLACEHOLDER__",l={type:t,attrs:e.attrs||{},content:[{type:"text",text:i}]};try{const o=a.renderMarkdown(l,{renderChildren:()=>i,renderChild:()=>i,indent:u=>u,wrapInBlock:(u,p)=>u+p},{index:0,level:0,parentType:"text",meta:{}}),h=o.indexOf(i),c=h+33;return h>=0?o.substring(c):""}catch(o){throw new Error(`Failed to get mark closing for ${t}: ${o}`)}}getHtmlReopenTags(t){const e=this.getHandlersForNodeType(t),n=e.length>0?e[0]:void 0;return n?.htmlReopen}markSetsEqual(t,e){return t.size!==e.size?!1:Array.from(t.entries()).every(([n,s])=>{const r=e.get(n);return r&&G(s.attrs,r.attrs)})}getMarksToOpenForSerialization(t,e,n){const s=pr(t,e);if(s.length<=1)return s;const r=n?.marks||[],a=(h,c)=>r.some(u=>u.type===h&&G(u.attrs,c)),i=(h,c)=>{var u,p;const d=(u=this.extensionRanks.get(h.type))!==null&&u!==void 0?u:Number.MAX_SAFE_INTEGER,g=(p=this.extensionRanks.get(c.type))!==null&&p!==void 0?p:Number.MAX_SAFE_INTEGER;return d!==g?g-d:h.type.localeCompare(c.type)},l=s.filter(h=>!a(h.type,h.mark.attrs)).sort(i),o=s.filter(h=>a(h.type,h.mark.attrs)).sort(i);return[...l,...o]}};const yr=ue.create({name:"markdown",addOptions(){return{indentation:{style:"space",size:2},marked:void 0,markedOptions:{}}},addCommands(){return{setContent:(t,e)=>{if(!e?.contentType)return P.setContent(t,e);if(Q(t,e?.contentType)!=="markdown"||!this.editor.markdown)return P.setContent(t,e);const n=this.editor.markdown.parse(t);return P.setContent(n,e)},insertContent:(t,e)=>{if(!e?.contentType)return P.insertContent(t,e);if(Q(t,e?.contentType)!=="markdown"||!this.editor.markdown)return P.insertContent(t,e);const n=this.editor.markdown.parse(t);return P.insertContent(n,e)},insertContentAt:(t,e,n)=>{if(!n?.contentType)return P.insertContentAt(t,e,n);if(Q(e,n?.contentType)!=="markdown"||!this.editor.markdown)return P.insertContentAt(t,e,n);const s=this.editor.markdown.parse(e);return P.insertContentAt(t,s,n)}}},addStorage(){return{manager:new ze({indentation:this.options.indentation,marked:this.options.marked,markedOptions:this.options.markedOptions,extensions:[]})}},onBeforeCreate(){var t;if(this.editor.markdown){console.error("[tiptap][markdown]: There is already a `markdown` property on the editor instance. This might lead to unexpected behavior.");return}if(this.storage.manager=new ze({indentation:this.options.indentation,marked:this.options.marked,markedOptions:this.options.markedOptions,extensions:this.editor.extensionManager.baseExtensions}),this.editor.markdown=this.storage.manager,this.editor.getMarkdown=()=>this.storage.manager.serialize(this.editor.getJSON()),!this.editor.options.contentType||Q(this.editor.options.content,this.editor.options.contentType)!=="markdown")return;if(!this.editor.markdown)throw new Error('[tiptap][markdown]: The `contentType` option is set to "markdown", but the Markdown extension is not added to the editor. Please add the Markdown extension to use this feature.');if(this.editor.options.content===void 0||typeof this.editor.options.content!="string")throw new Error('[tiptap][markdown]: The `contentType` option is set to "markdown", but the initial content is not a string. Please provide the initial content as a markdown string.');const e=this.editor.markdown.parse(this.editor.options.content);!((t=e.content)===null||t===void 0)&&t.length&&(this.editor.options.content=e)}});function Tr(t){const e=$.c(13),{node:n,selected:s,editor:r,deleteNode:a}=t,i=j(),l=typeof n.attrs.href=="string"?n.attrs.href:"",o=typeof n.attrs.name=="string"?n.attrs.name:"",h=s&&"ring-2 ring-ring ring-offset-2 ring-offset-background";let c;e[0]!==h?(c=B(Wt,"select-none",h),e[0]=h,e[1]=c):c=e[1];let u;e[2]!==a||e[3]!==r.isEditable||e[4]!==i?(u=r.isEditable&&f.jsx("button",{type:"button","aria-label":i("markdownEditor.removeFile"),onMouseDown:vr,onClick:a,className:"shrink-0 rounded-lg p-0.5 text-muted-foreground transition-colors hover:bg-accent hover:text-foreground",children:f.jsx(Oe,{size:14})}),e[2]=a,e[3]=r.isEditable,e[4]=i,e[5]=u):u=e[5];let p;e[6]!==l||e[7]!==o||e[8]!==u?(p=f.jsx(Qt,{href:l,name:o,children:u}),e[6]=l,e[7]=o,e[8]=u,e[9]=p):p=e[9];let d;return e[10]!==c||e[11]!==p?(d=f.jsx(pe,{as:"span",className:c,children:p}),e[10]=c,e[11]=p,e[12]=d):d=e[12],d}function vr(t){return t.preventDefault()}function Sr(t){return t.replace(/([[\]])/g,"\\$1")}const Mr=Fe.create({name:"attachment",group:"inline",inline:!0,atom:!0,draggable:!0,addAttributes(){return{href:{default:null,parseHTML:t=>t.getAttribute("href"),renderHTML:t=>t.href?{href:t.href}:{}},name:{default:null,parseHTML:t=>t.getAttribute("data-name")||t.textContent,renderHTML:t=>t.name?{"data-name":t.name}:{}}}},parseHTML(){return[{tag:"a[data-attachment]",getAttrs:t=>Ge(t.getAttribute("href")??"")?null:!1}]},renderHTML({HTMLAttributes:t,node:e}){return["a",qe(t,{"data-attachment":""}),typeof e.attrs.name=="string"?e.attrs.name:""]},renderMarkdown:t=>{const e=typeof t.attrs?.href=="string"?t.attrs.href:"",n=typeof t.attrs?.name=="string"?t.attrs.name:"";return`[${Sr(n)}](${e})`},addNodeView(){return he(Tr)}});function Er(t){const e=$.c(6),{node:n,selected:s}=t,r=typeof n.attrs.name=="string"?n.attrs.name:"";let a;e[0]!==n.attrs.id||e[1]!==s?(a=B("select-none",Vt(typeof n.attrs.id=="string"?n.attrs.id:null),s&&"ring-2 ring-ring"),e[0]=n.attrs.id,e[1]=s,e[2]=a):a=e[2];let i;return e[3]!==r||e[4]!==a?(i=f.jsxs(pe,{as:"span","data-testid":"mention-chip",className:a,children:["@",r]}),e[3]=r,e[4]=a,e[5]=i):i=e[5],i}const Ar=Fe.create({name:"mention",group:"inline",inline:!0,atom:!0,selectable:!0,addAttributes(){return{id:{default:null,parseHTML:t=>t.getAttribute("data-mention-id"),renderHTML:t=>t.id?{"data-mention-id":t.id}:{}},name:{default:null,parseHTML:t=>t.getAttribute("data-mention-name"),renderHTML:t=>t.name?{"data-mention-name":t.name}:{}}}},parseHTML(){return[{tag:"span[data-mention-id]"}]},renderHTML({HTMLAttributes:t,node:e}){return["span",qe(t),`@${typeof e.attrs.name=="string"?e.attrs.name:""}`]},renderMarkdown:t=>{const e=typeof t.attrs?.id=="string"?t.attrs.id:"",n=typeof t.attrs?.name=="string"?t.attrs.name:"";return e?Xt(e,n):`@${n}`},addNodeView(){return he(Er)}}),Rr="studio.mention-members.",ce=new Map;function Pe(t){const e=ce.get(t);if(e)return e;try{const n=localStorage.getItem(t);if(!n)return;const s=JSON.parse(n);if(!Array.isArray(s))return;const r=s.filter(a=>!!a&&typeof a.id=="string"&&typeof a.name=="string");return ce.set(t,r),r}catch{return}}function _r(t,e){ce.set(t,e);try{localStorage.setItem(t,JSON.stringify(e))}catch{}}function $r(t,e){if(!t?.length)return e;const n=new Map(t.map(s=>[s.id,s]));return e.map(s=>{const r=n.get(s.id);return r&&r.name===s.name&&r.email===s.email&&r.image===s.image?r:s})}function Cr(t){return t.map(e=>({id:e.userId,name:e.user?.name?.trim()||e.user?.email?.trim()||"",email:e.user?.email??"",image:e.user?.image??null})).filter(e=>!!e.name).sort((e,n)=>e.name.localeCompare(n.name))}function Lr(t){const e=$.c(17),{locator:n}=ot(),s=lt(),r=`${Rr}${n}`;let a;e[0]!==n?(a=ut.mentionMembers(n),e[0]=n,e[1]=a):a=e[1];let i;e[2]!==r?(i=()=>Pe(r),e[2]=r,e[3]=i):i=e[3];let l;e[4]!==s||e[5]!==r?(l=async()=>{const d=await s.organization.listMembers(),g=$r(Pe(r),Cr(d?.data?.members??[]));return _r(r,g),g},e[4]=s,e[5]=r,e[6]=l):l=e[6];let o;e[7]!==t||e[8]!==a||e[9]!==i||e[10]!==l?(o={queryKey:a,enabled:t,staleTime:0,placeholderData:i,queryFn:l},e[7]=t,e[8]=a,e[9]=i,e[10]=l,e[11]=o):o=e[11];const h=ct(o);let c;e[12]!==h.data?(c=h.data??[],e[12]=h.data,e[13]=c):c=e[13];const u=h.isFetching&&!h.data;let p;return e[14]!==c||e[15]!==u?(p={members:c,loading:u},e[14]=c,e[15]=u,e[16]=p):p=e[16],p}const je={query:"",range:null,rect:null,editor:null};class Ir{state=je;listeners=new Set;dismissal=null;latched=!1;subscribe=e=>(this.listeners.add(e),()=>this.listeners.delete(e));getSnapshot=()=>this.state;set(e){this.state=e;for(const n of this.listeners)n()}close(){this.latched=!1,this.set(je)}}const Te=new Be("markdownEditorMention");function zr(t,e,n){t.chain().focus().insertContentAt(e,[{type:"mention",attrs:{id:n.id,name:n.name}},{type:"text",text:" "}]).run(),Ue(t.view,Te)}function Pr(t,e,n){const s=Math.min(e+n,t.content.size);return e>=s?"":t.textBetween(e,s,"","")}function st(t,e){const n=e.getSnapshot().range??void 0;n&&n.to>n.from&&(e.dismissal={from:n.from,text:t.state.doc.textBetween(n.from,n.to,"")}),Ue(t.view,Te)}function jr(t){return ue.create({name:"mentionSuggestion",addProseMirrorPlugins(){const e={editor:this.editor,char:"@",pluginKey:Te,allowedPrefixes:[" ",`
`],allow:({state:n,range:s})=>{const r=t.dismissal;return r?s.from===r.from&&Pr(n.doc,r.from,r.text.length)===r.text?!1:(t.dismissal=null,!0):!0},items:()=>[],render:()=>({onStart:n=>{t.set({query:n.query,range:n.range,rect:n.clientRect??null,editor:n.editor})},onUpdate:n=>{t.set({query:n.query,range:n.range,rect:n.clientRect??null,editor:n.editor})},onKeyDown:({event:n})=>n.key==="Escape"?(st(this.editor,t),t.close(),!0):!1,onExit:()=>{t.latched||t.close()}})};return[Ct(e)]}})}const Ne=256,Nr=40,He=280,Hr=140,Or=[];function Dr(t){const e=$.c(5),{store:n,agents:s}=t,r=s===void 0?Or:s,a=_.useSyncExternalStore(n.subscribe,n.getSnapshot),i=a.range!==null;let l;return e[0]!==r||e[1]!==i||e[2]!==a||e[3]!==n?(l=i?f.jsx(Br,{store:n,state:a,agents:r}):null,e[0]=r,e[1]=i,e[2]=a,e[3]=n,e[4]=l):l=e[4],l}function Br({store:t,state:e,agents:n}){const s=j(),{members:r,loading:a}=Lr(!0),[i,l]=_.useState(e.query),[o,h]=_.useState(null),c=Fr(e.editor),u=c.getBoundingClientRect(),p=c===document.body?new DOMRect(0,0,window.innerWidth,window.innerHeight):u,d=e.rect?.()??new DOMRect(0,0,0,0),g=p.bottom-d.bottom,x=g<He&&d.top-p.top>g,w=(x?d.top-p.top:g)-8,b=Math.min(He,Math.max(w,Hr))-Nr,y={position:"absolute",width:Ne,left:Math.min(d.left,p.right-Ne-8)-u.left,...x?{bottom:u.bottom-d.top+6}:{top:d.bottom-u.top+6}},v=()=>{e.editor&&st(e.editor,t),t.close()},M=k=>{const T=k.relatedTarget;if((!T||e.editor?.view.dom.contains(T)===!0)&&t.latched){o?.focus();return}v()},m=k=>{!e.editor||!e.range||(zr(e.editor,e.range,k),t.close())};return ht.createPortal(f.jsx("div",{style:y,"data-testid":"mention-menu",className:"z-50 overflow-hidden rounded-lg bg-popover shadow-soft",children:f.jsxs(tn,{onKeyDown:k=>{k.key==="Escape"&&(k.preventDefault(),v(),e.editor?.commands.focus())},children:[f.jsx(nn,{ref:h,autoFocus:!0,onFocus:()=>{t.latched=!0},value:i,onValueChange:l,placeholder:s("markdownEditor.mentionSearch"),onBlur:M}),f.jsxs(rn,{style:{maxHeight:b},children:[a?f.jsx("div",{className:"flex items-center justify-center py-6",children:f.jsx(De,{size:"sm"})}):f.jsx(sn,{children:s("markdownEditor.mentionEmpty")}),n.map(k=>f.jsxs(Ee,{value:k.name,onSelect:()=>m(k),onMouseDown:T=>T.preventDefault(),className:"gap-2",children:[k.icon,f.jsx("span",{className:"min-w-0 flex-1 truncate",children:k.name})]},k.id)),r.map(k=>f.jsxs(Ee,{value:`${k.name} ${k.email}`,onSelect:()=>m(k),onMouseDown:T=>T.preventDefault(),className:"gap-2",children:[f.jsx(pt,{url:k.image??void 0,fallback:k.name??"?",shape:"circle",size:"xs"}),f.jsx("span",{className:"min-w-0 flex-1 truncate",children:k.name})]},k.id))]})]})}),c)}function Fr(t){const e=t?.view.dom.closest('[role="dialog"]');return e instanceof HTMLElement?e:document.body}function qr(t){const e=$.c(16),{node:n,selected:s,editor:r,deleteNode:a}=t,i=j(),l=typeof n.attrs.src=="string"?n.attrs.src:"",o=typeof n.attrs.alt=="string"?n.attrs.alt:"";let h;e[0]!==o||e[1]!==i?(h=o||i("markdownEditor.imageAltFallback"),e[0]=o,e[1]=i,e[2]=h):h=e[2];const c=s&&"ring-2 ring-ring ring-offset-2 ring-offset-background";let u;e[3]!==c?(u=B("max-h-[420px] max-w-full rounded-lg border border-border object-contain",c),e[3]=c,e[4]=u):u=e[4];let p;e[5]!==l||e[6]!==h||e[7]!==u?(p=f.jsx("img",{src:l,alt:h,draggable:!1,className:u}),e[5]=l,e[6]=h,e[7]=u,e[8]=p):p=e[8];let d;e[9]!==a||e[10]!==r.isEditable||e[11]!==i?(d=r.isEditable&&f.jsx("button",{type:"button","aria-label":i("markdownEditor.removeImage"),onMouseDown:Ur,onClick:a,className:"absolute right-2 top-2 flex size-7 items-center justify-center rounded-lg bg-card text-muted-foreground opacity-0 shadow-edge transition-opacity hover:text-foreground focus-visible:opacity-100 group-hover/image:opacity-100",children:f.jsx(Oe,{size:14})}),e[9]=a,e[10]=r.isEditable,e[11]=i,e[12]=d):d=e[12];let g;return e[13]!==p||e[14]!==d?(g=f.jsxs(pe,{className:"group/image relative my-3 w-fit max-w-full",children:[p,d]}),e[13]=p,e[14]=d,e[15]=g):g=e[15],g}function Ur(t){return t.preventDefault()}const Zr=Yt.extend({addNodeView(){return he(qr)}}).configure({inline:!1,allowBase64:!1}),Gr={openOnClick:!1,autolink:!0,HTMLAttributes:{rel:"noopener noreferrer",target:"_blank"}},Kr=Tt.extend({parseMarkdown:(t,e)=>{const n=typeof t.href=="string"?t.href:"";if(Ge(n))return e.createNode("attachment",{href:n,name:t.text??""});const s=Jt(n);return s?e.createNode("mention",{id:s,name:(t.text??"").replace(/^@/,"")}):e.applyMark("link",e.parseInline(t.tokens??[]),{href:n,title:t.title||null})}});function Wr(t="",e){return[St.configure({heading:{levels:[1,2,3]},underline:!1,link:!1}),Kr.configure(Gr),Lt.configure({placeholder:t}),en,vt,Mt.configure({nested:!0}),Zr,Mr,mn,Ar,...e?[jr(e)]:[],yr.configure({markedOptions:{breaks:!0}})]}const Qr=/^(\s*)([-*+]|\d+[.)])\s+\S/,Xr=/^\s*(```|~~~)/,Vr=/^\s+(?![-*+>#]|\d+[.)]\s)\S/;function Jr(t){const e=[];let n=!1,s=!1;for(const r of t.split(`
`)){if(Xr.test(r)){n=!n,s=!1,e.push(r);continue}if(n){e.push(r);continue}if(Qr.test(r)){s=!0,e.push(r);continue}if(!r.trim()){s=!1,e.push(r);continue}if(s&&Vr.test(r)){e[e.length-1]=`${e[e.length-1]} ${r.trim()}`;continue}s=!1,e.push(r)}return e.join(`
`)}function Yr(t){const e=$.c(12),{onFiles:n,disabled:s}=t,r=j(),a=_.useRef(null);let i;e[0]!==r?(i=r("markdownEditor.attachFile"),e[0]=r,e[1]=i):i=e[1];let l,o;e[2]===Symbol.for("react.memo_cache_sentinel")?(l=()=>a.current?.click(),o=f.jsx(Bt,{size:16}),e[2]=l,e[3]=o):(l=e[2],o=e[3]);let h;e[4]!==s||e[5]!==i?(h=f.jsx(an,{type:"button",label:i,disabled:s,onClick:l,children:o}),e[4]=s,e[5]=i,e[6]=h):h=e[6];let c;e[7]!==n?(c=f.jsx("input",{ref:a,type:"file",multiple:!0,className:"hidden",onChange:p=>{const d=Array.from(p.target.files??[]);p.target.value="",d.length>0&&n(d)}}),e[7]=n,e[8]=c):c=e[8];let u;return e[9]!==h||e[10]!==c?(u=f.jsxs(f.Fragment,{children:[h,c]}),e[9]=h,e[10]=c,e[11]=u):u=e[11],u}function es(t){const e=$.c(6),{pending:n}=t,s=j();if(n===0)return null;let r;e[0]===Symbol.for("react.memo_cache_sentinel")?(r=f.jsx(De,{className:"size-3"}),e[0]=r):r=e[0];let a;e[1]!==n||e[2]!==s?(a=n===1?s("markdownEditor.uploading"):s("markdownEditor.uploadingCount",{count:String(n)}),e[1]=n,e[2]=s,e[3]=a):a=e[3];let i;return e[4]!==a?(i=f.jsxs("span",{className:"inline-flex items-center gap-1.5 text-xs text-muted-foreground","aria-live":"polite",role:"status",children:[r,a]}),e[4]=a,e[5]=i):i=e[5],i}const ts=["outline-none","[&>*:first-child]:mt-0 [&>*:last-child]:mb-0","[&_p]:my-3 [&_p]:leading-[1.5]","[&_h1]:my-3 [&_h1]:text-xl [&_h1]:font-semibold [&_h1]:leading-[1.5] [&_h1]:text-foreground","[&_h2]:my-3 [&_h2]:text-lg [&_h2]:font-semibold [&_h2]:leading-[1.5] [&_h2]:text-foreground","[&_h3]:my-3 [&_h3]:text-base [&_h3]:font-semibold [&_h3]:leading-[1.5] [&_h3]:text-foreground","[&_ul]:my-3 [&_ul]:list-disc [&_ul]:pl-5","[&_ol]:my-3 [&_ol]:list-decimal [&_ol]:pl-5","[&_li]:my-0.5 [&_li>p]:my-0","[&_blockquote]:my-2 [&_blockquote]:border-l-2 [&_blockquote]:border-border [&_blockquote]:pl-3 [&_blockquote]:text-muted-foreground","[&_code]:rounded [&_code]:bg-muted [&_code]:px-1 [&_code]:py-0.5 [&_code]:font-mono [&_code]:text-[0.85em]","[&_pre]:my-3 [&_pre]:overflow-x-auto [&_pre]:rounded-lg [&_pre]:bg-muted [&_pre]:p-3 [&_pre]:font-mono [&_pre]:text-sm","[&_pre_code]:bg-transparent [&_pre_code]:p-0",$t,"[&_hr]:my-4 [&_hr]:border-border","[&_strong]:font-semibold [&_strong]:text-foreground","[&_table]:my-3 [&_table]:w-full [&_table]:table-fixed [&_table]:border-collapse","[&_th]:border [&_th]:border-border [&_th]:bg-muted [&_th]:p-2 [&_th]:text-left [&_th]:font-semibold","[&_td]:border [&_td]:border-border [&_td]:p-2 [&_td]:align-top","[&_th>p]:my-0 [&_td>p]:my-0","[&_ul[data-type=taskList]]:my-3 [&_ul[data-type=taskList]]:list-none [&_ul[data-type=taskList]]:pl-0","[&_li[data-type=taskItem]]:flex [&_li[data-type=taskItem]]:items-start [&_li[data-type=taskItem]]:gap-2","[&_li[data-type=taskItem]>label]:mt-1 [&_li[data-type=taskItem]>label]:shrink-0","[&_li[data-type=taskItem]>div]:min-w-0 [&_li[data-type=taskItem]>div>p]:my-0"].join(" "),ns=["[&_p.is-editor-empty:first-child::before]:content-[attr(data-placeholder)]","[&_p.is-editor-empty:first-child::before]:text-muted-foreground/50","[&_p.is-editor-empty:first-child::before]:float-left","[&_p.is-editor-empty:first-child::before]:h-0","[&_p.is-editor-empty:first-child::before]:pointer-events-none"].join(" ");function rs(t){const e=$.c(10),{editor:n,mentions:s}=t,r=s.items;let a;e[0]===Symbol.for("react.memo_cache_sentinel")?(a=["markdown-editor-mentions"],e[0]=a):a=e[0];let i;e[1]!==r?(i=h=>{const{query:c}=h,u=c.trim().toLowerCase();return Promise.resolve(u?r.filter(p=>`${p.name} ${p.title??""}`.toLowerCase().includes(u)):r)},e[1]=r,e[2]=i):i=e[2];let l;e[3]!==n?(l=h=>{const{range:c,item:u}=h;n.chain().focus().insertContentAt(c,[{type:"text",text:`@${u.name}`,marks:u.href?[{type:"link",attrs:{href:u.href}}]:void 0},{type:"text",text:" "}]).run()},e[3]=n,e[4]=l):l=e[4];let o;return e[5]!==n||e[6]!==s.emptyLabel||e[7]!==i||e[8]!==l?(o=f.jsx(It,{editor:n,char:"@",pluginKey:"markdownMentionMenu",queryKey:a,queryFn:i,emptyLabel:s.emptyLabel,renderItem:ss,onSelect:l}),e[5]=n,e[6]=s.emptyLabel,e[7]=i,e[8]=l,e[9]=o):o=e[9],o}function ss(t){return f.jsxs("div",{className:"flex min-w-0 flex-col gap-0.5",children:[f.jsx("span",{className:"truncate font-medium",children:t.title??t.name}),t.description&&f.jsx("span",{className:"line-clamp-1 text-xs text-muted-foreground",children:t.description})]})}function xs({defaultValue:t,onChange:e,placeholder:n,editable:s=!0,attachments:r=!0,mentions:a,inline:i=!1}){const l=wn(r),[o]=_.useState(()=>new Ir),h=_.useRef(e);h.current=e;const c=Et({extensions:Wr(n,a?void 0:o),content:Jr(t),contentType:"markdown",editable:s,autofocus:i?"end":!1,editorProps:{attributes:{role:"textbox","aria-label":n??"","aria-multiline":"true",class:B(ts,!i&&"min-h-[200px] sm:min-h-[320px]",ns)},handlePaste:l.handlePaste,handleDrop:l.handleDrop},onUpdate:({editor:u,transaction:p})=>{p.docChanged&&h.current(u.getMarkdown())}});return c?f.jsxs("div",{className:"flex flex-col",children:[f.jsx(cn,{editor:c}),!a&&f.jsx(Dr,{store:o}),f.jsx(At,{editor:c,className:B(i?"text-sm text-foreground":"text-base text-muted-foreground")}),s&&a&&f.jsx(rs,{editor:c,mentions:a}),f.jsxs("div",{className:"mt-4 flex items-center gap-2 text-xs text-muted-foreground empty:mt-0",children:[s&&a?.hint&&f.jsx("span",{children:a.hint}),s&&r&&f.jsx(Yr,{onFiles:u=>l.uploadInto(c.view,u,c.state.selection.to)}),f.jsx(es,{pending:l.pending})]})]}):null}export{Yr as A,Ir as M,mn as U,Ar as a,yr as b,Zr as c,Mr as d,Te as e,Dr as f,es as g,xs as h,jr as m,wn as u};