@aparte/n8n-chat 0.3.0 → 0.3.1

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.
Files changed (67) hide show
  1. package/README.md +71 -16
  2. package/dist/cards.d.ts +25 -1
  3. package/dist/cdn/chunks/{chunk-F2TNPBN3.js → chunk-37ODPEBD.js} +1 -1
  4. package/dist/cdn/chunks/{chunk-F2TNPBN3.js.map → chunk-37ODPEBD.js.map} +1 -1
  5. package/dist/cdn/chunks/{chunk-XC2SVYFR.js → chunk-DEOOTEDD.js} +2 -2
  6. package/dist/cdn/chunks/{chunk-XC2SVYFR.js.map → chunk-DEOOTEDD.js.map} +1 -1
  7. package/dist/cdn/chunks/{chunk-F2QIT4NR.js → chunk-NKYV5B7Q.js} +2 -2
  8. package/dist/cdn/chunks/{chunk-F2QIT4NR.js.map → chunk-NKYV5B7Q.js.map} +3 -3
  9. package/dist/cdn/chunks/{chunk-KY2H3HIJ.js → chunk-RDVTD2YO.js} +2 -2
  10. package/dist/cdn/chunks/{chunk-KY2H3HIJ.js.map → chunk-RDVTD2YO.js.map} +1 -1
  11. package/dist/cdn/chunks/{chunk-E55C7UF2.js → chunk-U6354LAY.js} +2 -2
  12. package/dist/cdn/chunks/{chunk-E55C7UF2.js.map → chunk-U6354LAY.js.map} +1 -1
  13. package/dist/cdn/chunks/{chunk-VLHCX6EH.js → chunk-ZNUFBTZ7.js} +2 -2
  14. package/dist/cdn/chunks/{chunk-VLHCX6EH.js.map → chunk-ZNUFBTZ7.js.map} +1 -1
  15. package/dist/cdn/chunks/{de-M5OVUL5F.js → de-BCWJVDW5.js} +1 -1
  16. package/dist/cdn/chunks/{de-M5OVUL5F.js.map → de-BCWJVDW5.js.map} +1 -1
  17. package/dist/cdn/chunks/{es-JUSLSPF7.js → es-72JNODLG.js} +1 -1
  18. package/dist/cdn/chunks/{es-JUSLSPF7.js.map → es-72JNODLG.js.map} +1 -1
  19. package/dist/cdn/chunks/{fr-Z2Y3375Z.js → fr-ZKACSOY5.js} +1 -1
  20. package/dist/cdn/chunks/{fr-Z2Y3375Z.js.map → fr-ZKACSOY5.js.map} +1 -1
  21. package/dist/cdn/chunks/{highlight-ADUWBKTT.js → highlight-DG2OVLBT.js} +2 -2
  22. package/dist/cdn/chunks/{highlight-ADUWBKTT.js.map → highlight-DG2OVLBT.js.map} +1 -1
  23. package/dist/cdn/chunks/{it-N53LIIX5.js → it-SSBBMSGX.js} +1 -1
  24. package/dist/cdn/chunks/{it-N53LIIX5.js.map → it-SSBBMSGX.js.map} +1 -1
  25. package/dist/cdn/chunks/{items-GTJKLFZT.js → items-MITCIPF3.js} +2 -2
  26. package/dist/cdn/chunks/{items-GTJKLFZT.js.map → items-MITCIPF3.js.map} +1 -1
  27. package/dist/cdn/chunks/{ja-LJHMBKJ4.js → ja-NCV4Z63H.js} +1 -1
  28. package/dist/cdn/chunks/{ja-LJHMBKJ4.js.map → ja-NCV4Z63H.js.map} +1 -1
  29. package/dist/cdn/chunks/{ko-XAQOC75B.js → ko-VCNS24WV.js} +1 -1
  30. package/dist/cdn/chunks/{ko-XAQOC75B.js.map → ko-VCNS24WV.js.map} +1 -1
  31. package/dist/cdn/chunks/{link-L4C4K5GE.js → link-7JYKZK3A.js} +2 -2
  32. package/dist/cdn/chunks/{link-L4C4K5GE.js.map → link-7JYKZK3A.js.map} +1 -1
  33. package/dist/cdn/chunks/{media-EOQEOMXK.js → media-7CZBXNEK.js} +2 -2
  34. package/dist/cdn/chunks/{media-EOQEOMXK.js.map → media-7CZBXNEK.js.map} +1 -1
  35. package/dist/cdn/chunks/{order-T5L422AO.js → order-CPY2L7MI.js} +2 -2
  36. package/dist/cdn/chunks/{order-T5L422AO.js.map → order-CPY2L7MI.js.map} +1 -1
  37. package/dist/cdn/chunks/{place-UD2C3U5F.js → place-KQ3IA5IV.js} +43 -4
  38. package/dist/cdn/chunks/place-KQ3IA5IV.js.map +7 -0
  39. package/dist/cdn/chunks/{plan-JJ3Z64NU.js → plan-OKXEPKPV.js} +2 -2
  40. package/dist/cdn/chunks/{plan-JJ3Z64NU.js.map → plan-OKXEPKPV.js.map} +1 -1
  41. package/dist/cdn/chunks/{product-FNGKWEQP.js → product-ONQRJRDO.js} +7 -3
  42. package/dist/cdn/chunks/product-ONQRJRDO.js.map +7 -0
  43. package/dist/cdn/chunks/{pt-BR-KMZM3WTU.js → pt-BR-73MNA3YX.js} +1 -1
  44. package/dist/cdn/chunks/{pt-BR-KMZM3WTU.js.map → pt-BR-73MNA3YX.js.map} +1 -1
  45. package/dist/cdn/chunks/{ru-3AG5HYY2.js → ru-SCEGVTR4.js} +1 -1
  46. package/dist/cdn/chunks/{ru-3AG5HYY2.js.map → ru-SCEGVTR4.js.map} +1 -1
  47. package/dist/cdn/chunks/{score-3CGZEPWP.js → score-QF27XJUE.js} +2 -2
  48. package/dist/cdn/chunks/{score-3CGZEPWP.js.map → score-QF27XJUE.js.map} +1 -1
  49. package/dist/cdn/chunks/{stats-FGZCRFFK.js → stats-2W3GFI4P.js} +2 -2
  50. package/dist/cdn/chunks/{stats-FGZCRFFK.js.map → stats-2W3GFI4P.js.map} +1 -1
  51. package/dist/cdn/chunks/{stock-E72GAUMB.js → stock-RCVJOOH4.js} +2 -2
  52. package/dist/cdn/chunks/{stock-E72GAUMB.js.map → stock-RCVJOOH4.js.map} +1 -1
  53. package/dist/cdn/chunks/{weather-5ZNWC2WM.js → weather-NQGN2JOS.js} +2 -2
  54. package/dist/cdn/chunks/{weather-5ZNWC2WM.js.map → weather-NQGN2JOS.js.map} +1 -1
  55. package/dist/cdn/chunks/{zh-CN-DL6ZWLGA.js → zh-CN-4K6QPBRT.js} +1 -1
  56. package/dist/cdn/chunks/{zh-CN-DL6ZWLGA.js.map → zh-CN-4K6QPBRT.js.map} +1 -1
  57. package/dist/cdn/n8n-chat.js +42 -42
  58. package/dist/cdn/n8n-chat.js.map +4 -4
  59. package/dist/create-chat.d.ts +11 -2
  60. package/dist/index.d.ts +1 -0
  61. package/dist/index.js +13 -2
  62. package/dist/index.js.map +1 -1
  63. package/dist/style.css +383 -370
  64. package/dist/theme.css +381 -368
  65. package/package.json +7 -7
  66. package/dist/cdn/chunks/place-UD2C3U5F.js.map +0 -7
  67. package/dist/cdn/chunks/product-FNGKWEQP.js.map +0 -7
@@ -1,34 +1,34 @@
1
- import"./chunks/chunk-XC2SVYFR.js";import"./chunks/chunk-KY2H3HIJ.js";import"./chunks/chunk-E55C7UF2.js";import"./chunks/chunk-F2TNPBN3.js";import{a as Dt,b as zt,c as Ut,d as Ht,k as Ge,l as qt,m as jt,o as Ft,q as Kt,r as Wt,w as Gt,y as Zt}from"./chunks/chunk-VLHCX6EH.js";import{a as I,b as L,c as oe,d as _t,e as Lt,f as We,g as Pt,h as me,i as Mt,l as Nt,m as Bt}from"./chunks/chunk-F2QIT4NR.js";import"./chunks/chunk-XAWE4EAK.js";function Qe(){return{async:!1,breaks:!1,extensions:null,gfm:!0,hooks:null,pedantic:!1,renderer:null,silent:!1,tokenizer:null,walkTokens:null}}var ue=Qe();function nn(e){ue=e}var le={exec:()=>null};function ke(e){let t=[];return n=>{let r=Math.max(0,Math.min(3,n-1)),s=t[r];return s||(s=e(r),t[r]=s),s}}function w(e,t=""){let n=typeof e=="string"?e:e.source,r={replace:(s,i)=>{let a=typeof i=="string"?i:i.source;return a=a.replace(P.caret,"$1"),n=n.replace(s,a),r},getRegex:()=>new RegExp(n,t)};return r}var ar=((e="")=>{try{return!!new RegExp("(?<=1)(?<!1)"+e)}catch{return!1}})(),P={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:e=>new RegExp(`^( {0,3}${e})((?:[ ][^\\n]*)?(?:\\n|$))`),nextBulletRegex:ke(e=>new RegExp(`^ {0,${e}}(?:[*+-]|\\d{1,9}[.)])((?:[ ][^\\n]*)?(?:\\n|$))`)),hrRegex:ke(e=>new RegExp(`^ {0,${e}}((?:- *){3,}|(?:_ *){3,}|(?:\\* *){3,})(?:\\n+|$)`)),fencesBeginRegex:ke(e=>new RegExp(`^ {0,${e}}(?:\`\`\`|~~~)`)),headingBeginRegex:ke(e=>new RegExp(`^ {0,${e}}#`)),htmlBeginRegex:ke(e=>new RegExp(`^ {0,${e}}<(?:[a-z].*>|!--)`,"i")),blockquoteBeginRegex:ke(e=>new RegExp(`^ {0,${e}}>`))},or=/^(?:[ \t]*(?:\n|$))+/,lr=/^((?: {4}| {0,3}\t)[^\n]+(?:\n(?:[ \t]*(?:\n|$))*)?)+/,cr=/^ {0,3}(`{3,}(?=[^`\n]*(?:\n|$))|~{3,})([^\n]*)(?:\n|$)(?:|([\s\S]*?)(?:\n|$))(?: {0,3}\1[~`]* *(?=\n|$)|$)/,Ee=/^ {0,3}((?:-[\t ]*){3,}|(?:_[ \t]*){3,}|(?:\*[ \t]*){3,})(?:\n+|$)/,ur=/^ {0,3}(#{1,6})(?=\s|$)(.*)(?:\n+|$)/,Xe=/ {0,3}(?:[*+-]|\d{1,9}[.)])/,rn=/^(?!bull |blockCode|fences|blockquote|heading|html|table)((?:.|\n(?!\s*?\n|bull |blockCode|fences|blockquote|heading|html|table))+?)\n {0,3}(=+|-+) *(?:\n+|$)/,sn=w(rn).replace(/bull/g,Xe).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(),hr=w(rn).replace(/bull/g,Xe).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(),Ye=/^([^\n]+(?:\n(?!hr|heading|lheading|blockquote|fences|list|html|table| +\n)[^\n]+)*)/,pr=/^[^\n]+/,et=/(?!\s*\])(?:\\[\s\S]|[^\[\]\\])+/,dr=w(/^ {0,3}\[(label)\]: *(?:\n[ \t]*)?([^<\s][^\s]*|<.*?>)(?:(?: +(?:\n[ \t]*)?| *\n[ \t]*)(title))? *(?:\n+|$)/).replace("label",et).replace("title",/(?:"(?:\\"?|[^"\\])*"|'[^'\n]*(?:\n[^'\n]+)*\n?'|\([^()]*\))/).getRegex(),fr=w(/^(bull)([ \t][^\n]*?)?(?:\n|$)/).replace(/bull/g,Xe).getRegex(),_e="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",tt=/<!--(?:-?>|[\s\S]*?(?:-->|$))/,gr=w("^ {0,3}(?:<(script|pre|style|textarea)[\\s>][\\s\\S]*?(?:</\\1>[^\\n]*\\n+|$)|comment[^\\n]*(\\n+|$)|<\\?[\\s\\S]*?(?:\\?>[^\\n]*\\n+|$)|<![A-Z][\\s\\S]*?(?:>[^\\n]*\\n+|$)|<!\\[CDATA\\[[\\s\\S]*?(?:\\]\\]>[^\\n]*\\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",tt).replace("tag",_e).replace("attribute",/ +[a-zA-Z:_][\w.:-]*(?: *= *"[^"\n]*"| *= *'[^'\n]*'| *= *[^\s"'=<>`]+)?/).getRegex(),an=e=>w(Ye).replace("hr",Ee).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",e).replace("html","</?(?:tag)(?: +|\\n|/?>)|<(?:script|pre|style|textarea|!--)").replace("tag",_e).getRegex(),mr=an(/ {0,3}(?:[*+-]|1[.)])[ \t]+[^ \t\n]/),kr=an(/ {0,3}(?:[*+-]|\d{1,9}[.)])[ \t]+[^ \t\n]/),br=w(/^( {0,3}> ?(paragraph|[^\n]*)(?:\n|$))+/).replace("paragraph",kr).getRegex(),nt={blockquote:br,code:lr,def:dr,fences:cr,heading:ur,hr:Ee,html:gr,lheading:sn,list:fr,newline:or,paragraph:mr,table:le,text:pr},Vt=w("^ *([^\\n ].*)\\n {0,3}((?:\\| *)?:?-+:? *(?:\\| *:?-+:? *)*(?:\\| *)?)(?:\\n((?:(?! *\\n|hr|heading|blockquote|code|fences|list|html).*(?:\\n|$))*)\\n*|$)").replace("hr",Ee).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",_e).getRegex(),wr={...nt,lheading:hr,table:Vt,paragraph:w(Ye).replace("hr",Ee).replace("heading"," {0,3}#{1,6}(?:\\s|$)").replace("|lheading","").replace("table",Vt).replace("blockquote"," {0,3}>").replace("fences"," {0,3}(?:`{3,}(?=[^`\\n]*\\n)|~{3,})[^\\n]*\\n").replace("list"," {0,3}(?:[*+-]|1[.)])[ \\t]+[^ \\t\\n]").replace("html","</?(?:tag)(?: +|\\n|/?>)|<(?:script|pre|style|textarea|!--)").replace("tag",_e).getRegex()},xr={...nt,html:w(`^ *(?:comment *(?:\\n|\\s*$)|<(tag)[\\s\\S]+?</\\1> *(?:\\n{2,}|\\s*$)|<tag(?:"[^"]*"|'[^']*'|\\s[^'"/>\\s]*)*?/?> *(?:\\n{2,}|\\s*$))`).replace("comment",tt).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:le,lheading:/^(.+?)\n {0,3}(=+|-+) *(?:\n+|$)/,paragraph:w(Ye).replace("hr",Ee).replace("heading",` *#{1,6} *[^
2
- ]`).replace("lheading",sn).replace("|table","").replace("blockquote"," {0,3}>").replace("|fences","").replace("|list","").replace("|html","").replace("|tag","").getRegex()},yr=/^\\([!"#$%&'()*+,\-./:;<=>?@\[\]\\^_`{|}~])/,Sr=/^(`+)([^`]|[^`][\s\S]*?[^`])\1(?!`)/,on=/^( {2,}|\\)\n(?!\s*$)/,Rr=/^(`+|[^`])(?:(?= {2,}\n)|[\s\S]*?(?:(?=[\\<!\[`*_]|\b_|$)|[^ ](?= {2,}\n)))/,be=/[\p{P}\p{S}]/u,Le=/[\s\p{P}\p{S}]/u,rt=/[^\s\p{P}\p{S}]/u,Er=w(/^((?![*_])punctSpace)/,"u").replace(/punctSpace/g,Le).getRegex(),ln=/(?!~)[\p{P}\p{S}]/u,vr=/(?!~)[\s\p{P}\p{S}]/u,$r=/(?:[^\s\p{P}\p{S}]|~)/u,Cr=w(/link|precode-code|html/,"g").replace("link",/\[(?:[^\[\]`]|(?<a>`+)[^`]+\k<a>(?!`))*?\]\((?:\\[\s\S]|[^\\\(\)]|\((?:\\[\s\S]|[^\\\(\)])*\))*\)/).replace("precode-",ar?"(?<!`)()":"(^^|[^`])").replace("code",/(?<b>`+)[^`]+\k<b>(?!`)/).replace("html",/<(?! )[^<>]*?>/).getRegex(),cn=/^(?:\*+(?:((?!\*)punct)|([^\s*]))?)|^_+(?:((?!_)punct)|([^\s_]))?/,Tr=w(cn,"u").replace(/punct/g,be).getRegex(),Ir=w(cn,"u").replace(/punct/g,ln).getRegex(),un="^[^_*]*?__[^_*]*?\\*[^_*]*?(?=__)|[^*]+(?=[^*])|(?!\\*)punct(\\*+)(?=[\\s]|$)|notPunctSpace(\\*+)(?!\\*)(?=punctSpace|$)|(?!\\*)punctSpace(\\*+)(?=notPunctSpace)|[\\s](\\*+)(?!\\*)(?=punct)|(?!\\*)punct(\\*+)(?!\\*)(?=punct)|notPunctSpace(\\*+)(?=notPunctSpace)",Ar=w(un,"gu").replace(/notPunctSpace/g,rt).replace(/punctSpace/g,Le).replace(/punct/g,be).getRegex(),Or=w(un,"gu").replace(/notPunctSpace/g,$r).replace(/punctSpace/g,vr).replace(/punct/g,ln).getRegex(),_r=w("^[^_*]*?\\*\\*[^_*]*?_[^_*]*?(?=\\*\\*)|[^_]+(?=[^_])|(?!_)punct(_+)(?=[\\s]|$)|notPunctSpace(_+)(?!_)(?=punctSpace|$)|(?!_)punctSpace(_+)(?=notPunctSpace)|[\\s](_+)(?!_)(?=punct)|(?!_)punct(_+)(?!_)(?=punct)","gu").replace(/notPunctSpace/g,rt).replace(/punctSpace/g,Le).replace(/punct/g,be).getRegex(),Lr=w(/^~~?(?:((?!~)punct)|[^\s~])/,"u").replace(/punct/g,be).getRegex(),Pr="^[^~]+(?=[^~])|(?!~)punct(~~?)(?=[\\s]|$)|notPunctSpace(~~?)(?!~)(?=punctSpace|$)|(?!~)punctSpace(~~?)(?=notPunctSpace)|[\\s](~~?)(?!~)(?=punct)|(?!~)punct(~~?)(?!~)(?=punct)|notPunctSpace(~~?)(?=notPunctSpace)",Mr=w(Pr,"gu").replace(/notPunctSpace/g,rt).replace(/punctSpace/g,Le).replace(/punct/g,be).getRegex(),Nr=w(/\\(punct)/,"gu").replace(/punct/g,be).getRegex(),Br=w(/^<(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(),Dr=w(tt).replace("(?:-->|$)","-->").getRegex(),zr=w("^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",Dr).replace("attribute",/\s+[a-zA-Z:_][\w.:-]*(?:\s*=\s*"[^"]*"|\s*=\s*'[^']*'|\s*=\s*[^\s"'=<>`]+)?/).getRegex(),Ie=/(?:\[(?:\\[\s\S]|[^\[\]\\])*\]|\\[\s\S]|`+(?!`)[^`]*?`+(?!`)|``+(?=\])|[^\[\]\\`])*?/,Ur=w(/^!?\[(label)\]\(\s*(href)(?:(?:[ \t]+(?:\n[ \t]*)?|\n[ \t]*)(title))?\s*\)/).replace("label",Ie).replace("href",/<(?:\\.|[^\n<>\\])+>|[^ \t\n\x00-\x1f]+|(?=\))/).replace("title",/"(?:\\"?|[^"\\])*"|'(?:\\'?|[^'\\])*'|\((?:\\\)?|[^)\\])*\)/).getRegex(),hn=w(/^!?\[(label)\]\[(ref)\]/).replace("label",Ie).replace("ref",et).getRegex(),pn=w(/^!?\[(ref)\](?:\[\])?/).replace("ref",et).getRegex(),Hr=w("reflink|nolink(?!\\()","g").replace("reflink",hn).replace("nolink",pn).getRegex(),Jt=/[hH][tT][tT][pP][sS]?|[fF][tT][pP]/,st={_backpedal:le,anyPunctuation:Nr,autolink:Br,blockSkip:Cr,br:on,code:Sr,del:le,delLDelim:le,delRDelim:le,emStrongLDelim:Tr,emStrongRDelimAst:Ar,emStrongRDelimUnd:_r,escape:yr,link:Ur,nolink:pn,punctuation:Er,reflink:hn,reflinkSearch:Hr,tag:zr,text:Rr,url:le},qr={...st,link:w(/^!?\[(label)\]\((.*?)\)/).replace("label",Ie).getRegex(),reflink:w(/^!?\[(label)\]\s*\[([^\]]*)\]/).replace("label",Ie).getRegex()},Ze={...st,emStrongRDelimAst:Or,emStrongLDelim:Ir,delLDelim:Lr,delRDelim:Mr,url:w(/^((?:protocol):\/\/|www\.)(?:[a-zA-Z0-9\-]+\.?)+[^\s<]*|^email/).replace("protocol",Jt).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:w(/^([`~]+|[^`~])(?:(?= {2,}\n)|(?=[a-zA-Z0-9.!#$%&'*+\/=?_`{\|}~-]+@)|[\s\S]*?(?:(?=[\\<!\[`*~_]|\b_|protocol:\/\/|www\.|$)|[^ ](?= {2,}\n)|[^a-zA-Z0-9.!#$%&'*+\/=?_`{\|}~-](?=[a-zA-Z0-9.!#$%&'*+\/=?_`{\|}~-]+@)))/).replace("protocol",Jt).getRegex()},jr={...Ze,br:w(on).replace("{2,}","*").getRegex(),text:w(Ze.text).replace("\\b_","\\b_| {2,}\\n").replace(/\{2,\}/g,"*").getRegex()},Te={normal:nt,gfm:wr,pedantic:xr},Se={normal:st,gfm:Ze,breaks:jr,pedantic:qr},Fr={"&":"&amp;","<":"&lt;",">":"&gt;",'"':"&quot;","'":"&#39;"},Qt=e=>Fr[e];function Z(e,t){if(t){if(P.escapeTest.test(e))return e.replace(P.escapeReplace,Qt)}else if(P.escapeTestNoEncode.test(e))return e.replace(P.escapeReplaceNoEncode,Qt);return e}function Xt(e){try{e=encodeURI(e).replace(P.percentDecode,"%")}catch{return null}return e}function Yt(e,t){let n=e.replace(P.findPipe,(i,a,o)=>{let c=!1,l=a;for(;--l>=0&&o[l]==="\\";)c=!c;return c?"|":" |"}),r=n.split(P.splitPipe),s=0;if(r[0].trim()||r.shift(),r.length>0&&!r.at(-1)?.trim()&&r.pop(),t)if(r.length>t)r.splice(t);else for(;r.length<t;)r.push("");for(;s<r.length;s++)r[s]=r[s].trim().replace(P.slashPipe,"|");return r}function ne(e,t,n){let r=e.length;if(r===0)return"";let s=0;for(;s<r;){let i=e.charAt(r-s-1);if(i===t&&!n)s++;else if(i!==t&&n)s++;else break}return e.slice(0,r-s)}function en(e){let t=e.split(`
1
+ import"./chunks/chunk-DEOOTEDD.js";import"./chunks/chunk-RDVTD2YO.js";import"./chunks/chunk-U6354LAY.js";import"./chunks/chunk-37ODPEBD.js";import{a as Dt,b as zt,c as Ut,d as Ht,k as Ge,l as jt,m as qt,o as Ft,q as Kt,r as Wt,w as Gt,y as Zt}from"./chunks/chunk-ZNUFBTZ7.js";import{a as I,b as L,c as oe,d as _t,e as Lt,f as We,g as Pt,h as me,i as Mt,l as Nt,m as Bt}from"./chunks/chunk-NKYV5B7Q.js";import"./chunks/chunk-XAWE4EAK.js";function Qe(){return{async:!1,breaks:!1,extensions:null,gfm:!0,hooks:null,pedantic:!1,renderer:null,silent:!1,tokenizer:null,walkTokens:null}}var ue=Qe();function nn(e){ue=e}var le={exec:()=>null};function ke(e){let t=[];return n=>{let r=Math.max(0,Math.min(3,n-1)),s=t[r];return s||(s=e(r),t[r]=s),s}}function w(e,t=""){let n=typeof e=="string"?e:e.source,r={replace:(s,i)=>{let a=typeof i=="string"?i:i.source;return a=a.replace(P.caret,"$1"),n=n.replace(s,a),r},getRegex:()=>new RegExp(n,t)};return r}var or=((e="")=>{try{return!!new RegExp("(?<=1)(?<!1)"+e)}catch{return!1}})(),P={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:e=>new RegExp(`^( {0,3}${e})((?:[ ][^\\n]*)?(?:\\n|$))`),nextBulletRegex:ke(e=>new RegExp(`^ {0,${e}}(?:[*+-]|\\d{1,9}[.)])((?:[ ][^\\n]*)?(?:\\n|$))`)),hrRegex:ke(e=>new RegExp(`^ {0,${e}}((?:- *){3,}|(?:_ *){3,}|(?:\\* *){3,})(?:\\n+|$)`)),fencesBeginRegex:ke(e=>new RegExp(`^ {0,${e}}(?:\`\`\`|~~~)`)),headingBeginRegex:ke(e=>new RegExp(`^ {0,${e}}#`)),htmlBeginRegex:ke(e=>new RegExp(`^ {0,${e}}<(?:[a-z].*>|!--)`,"i")),blockquoteBeginRegex:ke(e=>new RegExp(`^ {0,${e}}>`))},lr=/^(?:[ \t]*(?:\n|$))+/,cr=/^((?: {4}| {0,3}\t)[^\n]+(?:\n(?:[ \t]*(?:\n|$))*)?)+/,ur=/^ {0,3}(`{3,}(?=[^`\n]*(?:\n|$))|~{3,})([^\n]*)(?:\n|$)(?:|([\s\S]*?)(?:\n|$))(?: {0,3}\1[~`]* *(?=\n|$)|$)/,Ee=/^ {0,3}((?:-[\t ]*){3,}|(?:_[ \t]*){3,}|(?:\*[ \t]*){3,})(?:\n+|$)/,pr=/^ {0,3}(#{1,6})(?=\s|$)(.*)(?:\n+|$)/,Xe=/ {0,3}(?:[*+-]|\d{1,9}[.)])/,rn=/^(?!bull |blockCode|fences|blockquote|heading|html|table)((?:.|\n(?!\s*?\n|bull |blockCode|fences|blockquote|heading|html|table))+?)\n {0,3}(=+|-+) *(?:\n+|$)/,sn=w(rn).replace(/bull/g,Xe).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(),hr=w(rn).replace(/bull/g,Xe).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(),Ye=/^([^\n]+(?:\n(?!hr|heading|lheading|blockquote|fences|list|html|table| +\n)[^\n]+)*)/,dr=/^[^\n]+/,et=/(?!\s*\])(?:\\[\s\S]|[^\[\]\\])+/,fr=w(/^ {0,3}\[(label)\]: *(?:\n[ \t]*)?([^<\s][^\s]*|<.*?>)(?:(?: +(?:\n[ \t]*)?| *\n[ \t]*)(title))? *(?:\n+|$)/).replace("label",et).replace("title",/(?:"(?:\\"?|[^"\\])*"|'[^'\n]*(?:\n[^'\n]+)*\n?'|\([^()]*\))/).getRegex(),gr=w(/^(bull)([ \t][^\n]*?)?(?:\n|$)/).replace(/bull/g,Xe).getRegex(),_e="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",tt=/<!--(?:-?>|[\s\S]*?(?:-->|$))/,mr=w("^ {0,3}(?:<(script|pre|style|textarea)[\\s>][\\s\\S]*?(?:</\\1>[^\\n]*\\n+|$)|comment[^\\n]*(\\n+|$)|<\\?[\\s\\S]*?(?:\\?>[^\\n]*\\n+|$)|<![A-Z][\\s\\S]*?(?:>[^\\n]*\\n+|$)|<!\\[CDATA\\[[\\s\\S]*?(?:\\]\\]>[^\\n]*\\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",tt).replace("tag",_e).replace("attribute",/ +[a-zA-Z:_][\w.:-]*(?: *= *"[^"\n]*"| *= *'[^'\n]*'| *= *[^\s"'=<>`]+)?/).getRegex(),an=e=>w(Ye).replace("hr",Ee).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",e).replace("html","</?(?:tag)(?: +|\\n|/?>)|<(?:script|pre|style|textarea|!--)").replace("tag",_e).getRegex(),kr=an(/ {0,3}(?:[*+-]|1[.)])[ \t]+[^ \t\n]/),br=an(/ {0,3}(?:[*+-]|\d{1,9}[.)])[ \t]+[^ \t\n]/),wr=w(/^( {0,3}> ?(paragraph|[^\n]*)(?:\n|$))+/).replace("paragraph",br).getRegex(),nt={blockquote:wr,code:cr,def:fr,fences:ur,heading:pr,hr:Ee,html:mr,lheading:sn,list:gr,newline:lr,paragraph:kr,table:le,text:dr},Vt=w("^ *([^\\n ].*)\\n {0,3}((?:\\| *)?:?-+:? *(?:\\| *:?-+:? *)*(?:\\| *)?)(?:\\n((?:(?! *\\n|hr|heading|blockquote|code|fences|list|html).*(?:\\n|$))*)\\n*|$)").replace("hr",Ee).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",_e).getRegex(),xr={...nt,lheading:hr,table:Vt,paragraph:w(Ye).replace("hr",Ee).replace("heading"," {0,3}#{1,6}(?:\\s|$)").replace("|lheading","").replace("table",Vt).replace("blockquote"," {0,3}>").replace("fences"," {0,3}(?:`{3,}(?=[^`\\n]*\\n)|~{3,})[^\\n]*\\n").replace("list"," {0,3}(?:[*+-]|1[.)])[ \\t]+[^ \\t\\n]").replace("html","</?(?:tag)(?: +|\\n|/?>)|<(?:script|pre|style|textarea|!--)").replace("tag",_e).getRegex()},yr={...nt,html:w(`^ *(?:comment *(?:\\n|\\s*$)|<(tag)[\\s\\S]+?</\\1> *(?:\\n{2,}|\\s*$)|<tag(?:"[^"]*"|'[^']*'|\\s[^'"/>\\s]*)*?/?> *(?:\\n{2,}|\\s*$))`).replace("comment",tt).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:le,lheading:/^(.+?)\n {0,3}(=+|-+) *(?:\n+|$)/,paragraph:w(Ye).replace("hr",Ee).replace("heading",` *#{1,6} *[^
2
+ ]`).replace("lheading",sn).replace("|table","").replace("blockquote"," {0,3}>").replace("|fences","").replace("|list","").replace("|html","").replace("|tag","").getRegex()},Sr=/^\\([!"#$%&'()*+,\-./:;<=>?@\[\]\\^_`{|}~])/,Rr=/^(`+)([^`]|[^`][\s\S]*?[^`])\1(?!`)/,on=/^( {2,}|\\)\n(?!\s*$)/,Er=/^(`+|[^`])(?:(?= {2,}\n)|[\s\S]*?(?:(?=[\\<!\[`*_]|\b_|$)|[^ ](?= {2,}\n)))/,be=/[\p{P}\p{S}]/u,Le=/[\s\p{P}\p{S}]/u,rt=/[^\s\p{P}\p{S}]/u,vr=w(/^((?![*_])punctSpace)/,"u").replace(/punctSpace/g,Le).getRegex(),ln=/(?!~)[\p{P}\p{S}]/u,$r=/(?!~)[\s\p{P}\p{S}]/u,Cr=/(?:[^\s\p{P}\p{S}]|~)/u,Tr=w(/link|precode-code|html/,"g").replace("link",/\[(?:[^\[\]`]|(?<a>`+)[^`]+\k<a>(?!`))*?\]\((?:\\[\s\S]|[^\\\(\)]|\((?:\\[\s\S]|[^\\\(\)])*\))*\)/).replace("precode-",or?"(?<!`)()":"(^^|[^`])").replace("code",/(?<b>`+)[^`]+\k<b>(?!`)/).replace("html",/<(?! )[^<>]*?>/).getRegex(),cn=/^(?:\*+(?:((?!\*)punct)|([^\s*]))?)|^_+(?:((?!_)punct)|([^\s_]))?/,Ir=w(cn,"u").replace(/punct/g,be).getRegex(),Ar=w(cn,"u").replace(/punct/g,ln).getRegex(),un="^[^_*]*?__[^_*]*?\\*[^_*]*?(?=__)|[^*]+(?=[^*])|(?!\\*)punct(\\*+)(?=[\\s]|$)|notPunctSpace(\\*+)(?!\\*)(?=punctSpace|$)|(?!\\*)punctSpace(\\*+)(?=notPunctSpace)|[\\s](\\*+)(?!\\*)(?=punct)|(?!\\*)punct(\\*+)(?!\\*)(?=punct)|notPunctSpace(\\*+)(?=notPunctSpace)",Or=w(un,"gu").replace(/notPunctSpace/g,rt).replace(/punctSpace/g,Le).replace(/punct/g,be).getRegex(),_r=w(un,"gu").replace(/notPunctSpace/g,Cr).replace(/punctSpace/g,$r).replace(/punct/g,ln).getRegex(),Lr=w("^[^_*]*?\\*\\*[^_*]*?_[^_*]*?(?=\\*\\*)|[^_]+(?=[^_])|(?!_)punct(_+)(?=[\\s]|$)|notPunctSpace(_+)(?!_)(?=punctSpace|$)|(?!_)punctSpace(_+)(?=notPunctSpace)|[\\s](_+)(?!_)(?=punct)|(?!_)punct(_+)(?!_)(?=punct)","gu").replace(/notPunctSpace/g,rt).replace(/punctSpace/g,Le).replace(/punct/g,be).getRegex(),Pr=w(/^~~?(?:((?!~)punct)|[^\s~])/,"u").replace(/punct/g,be).getRegex(),Mr="^[^~]+(?=[^~])|(?!~)punct(~~?)(?=[\\s]|$)|notPunctSpace(~~?)(?!~)(?=punctSpace|$)|(?!~)punctSpace(~~?)(?=notPunctSpace)|[\\s](~~?)(?!~)(?=punct)|(?!~)punct(~~?)(?!~)(?=punct)|notPunctSpace(~~?)(?=notPunctSpace)",Nr=w(Mr,"gu").replace(/notPunctSpace/g,rt).replace(/punctSpace/g,Le).replace(/punct/g,be).getRegex(),Br=w(/\\(punct)/,"gu").replace(/punct/g,be).getRegex(),Dr=w(/^<(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(),zr=w(tt).replace("(?:-->|$)","-->").getRegex(),Ur=w("^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",zr).replace("attribute",/\s+[a-zA-Z:_][\w.:-]*(?:\s*=\s*"[^"]*"|\s*=\s*'[^']*'|\s*=\s*[^\s"'=<>`]+)?/).getRegex(),Ie=/(?:\[(?:\\[\s\S]|[^\[\]\\])*\]|\\[\s\S]|`+(?!`)[^`]*?`+(?!`)|``+(?=\])|[^\[\]\\`])*?/,Hr=w(/^!?\[(label)\]\(\s*(href)(?:(?:[ \t]+(?:\n[ \t]*)?|\n[ \t]*)(title))?\s*\)/).replace("label",Ie).replace("href",/<(?:\\.|[^\n<>\\])+>|[^ \t\n\x00-\x1f]+|(?=\))/).replace("title",/"(?:\\"?|[^"\\])*"|'(?:\\'?|[^'\\])*'|\((?:\\\)?|[^)\\])*\)/).getRegex(),pn=w(/^!?\[(label)\]\[(ref)\]/).replace("label",Ie).replace("ref",et).getRegex(),hn=w(/^!?\[(ref)\](?:\[\])?/).replace("ref",et).getRegex(),jr=w("reflink|nolink(?!\\()","g").replace("reflink",pn).replace("nolink",hn).getRegex(),Jt=/[hH][tT][tT][pP][sS]?|[fF][tT][pP]/,st={_backpedal:le,anyPunctuation:Br,autolink:Dr,blockSkip:Tr,br:on,code:Rr,del:le,delLDelim:le,delRDelim:le,emStrongLDelim:Ir,emStrongRDelimAst:Or,emStrongRDelimUnd:Lr,escape:Sr,link:Hr,nolink:hn,punctuation:vr,reflink:pn,reflinkSearch:jr,tag:Ur,text:Er,url:le},qr={...st,link:w(/^!?\[(label)\]\((.*?)\)/).replace("label",Ie).getRegex(),reflink:w(/^!?\[(label)\]\s*\[([^\]]*)\]/).replace("label",Ie).getRegex()},Ze={...st,emStrongRDelimAst:_r,emStrongLDelim:Ar,delLDelim:Pr,delRDelim:Nr,url:w(/^((?:protocol):\/\/|www\.)(?:[a-zA-Z0-9\-]+\.?)+[^\s<]*|^email/).replace("protocol",Jt).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:w(/^([`~]+|[^`~])(?:(?= {2,}\n)|(?=[a-zA-Z0-9.!#$%&'*+\/=?_`{\|}~-]+@)|[\s\S]*?(?:(?=[\\<!\[`*~_]|\b_|protocol:\/\/|www\.|$)|[^ ](?= {2,}\n)|[^a-zA-Z0-9.!#$%&'*+\/=?_`{\|}~-](?=[a-zA-Z0-9.!#$%&'*+\/=?_`{\|}~-]+@)))/).replace("protocol",Jt).getRegex()},Fr={...Ze,br:w(on).replace("{2,}","*").getRegex(),text:w(Ze.text).replace("\\b_","\\b_| {2,}\\n").replace(/\{2,\}/g,"*").getRegex()},Te={normal:nt,gfm:xr,pedantic:yr},Se={normal:st,gfm:Ze,breaks:Fr,pedantic:qr},Kr={"&":"&amp;","<":"&lt;",">":"&gt;",'"':"&quot;","'":"&#39;"},Qt=e=>Kr[e];function Z(e,t){if(t){if(P.escapeTest.test(e))return e.replace(P.escapeReplace,Qt)}else if(P.escapeTestNoEncode.test(e))return e.replace(P.escapeReplaceNoEncode,Qt);return e}function Xt(e){try{e=encodeURI(e).replace(P.percentDecode,"%")}catch{return null}return e}function Yt(e,t){let n=e.replace(P.findPipe,(i,a,o)=>{let c=!1,l=a;for(;--l>=0&&o[l]==="\\";)c=!c;return c?"|":" |"}),r=n.split(P.splitPipe),s=0;if(r[0].trim()||r.shift(),r.length>0&&!r.at(-1)?.trim()&&r.pop(),t)if(r.length>t)r.splice(t);else for(;r.length<t;)r.push("");for(;s<r.length;s++)r[s]=r[s].trim().replace(P.slashPipe,"|");return r}function ne(e,t,n){let r=e.length;if(r===0)return"";let s=0;for(;s<r;){let i=e.charAt(r-s-1);if(i===t&&!n)s++;else if(i!==t&&n)s++;else break}return e.slice(0,r-s)}function en(e){let t=e.split(`
3
3
  `),n=t.length-1;for(;n>=0&&P.blankLine.test(t[n]);)n--;return t.length-n<=2?e:t.slice(0,n+1).join(`
4
- `)}function Kr(e,t){if(e.indexOf(t[1])===-1)return-1;let n=0;for(let r=0;r<e.length;r++)if(e[r]==="\\")r++;else if(e[r]===t[0])n++;else if(e[r]===t[1]&&(n--,n<0))return r;return n>0?-2:-1}function Wr(e,t=0){let n=t,r="";for(let s of e)if(s===" "){let i=4-n%4;r+=" ".repeat(i),n+=i}else r+=s,n++;return r}function tn(e,t,n,r,s){let i=t.href,a=t.title||null,o=e[1].replace(s.other.outputLinkReplace,"$1");r.state.inLink=!0;let c={type:e[0].charAt(0)==="!"?"image":"link",raw:n,href:i,title:a,text:o,tokens:r.inlineTokens(o)};return r.state.inLink=!1,c}function Gr(e,t,n){let r=e.match(n.other.indentCodeCompensation);if(r===null)return t;let s=r[1];return t.split(`
4
+ `)}function Wr(e,t){if(e.indexOf(t[1])===-1)return-1;let n=0;for(let r=0;r<e.length;r++)if(e[r]==="\\")r++;else if(e[r]===t[0])n++;else if(e[r]===t[1]&&(n--,n<0))return r;return n>0?-2:-1}function Gr(e,t=0){let n=t,r="";for(let s of e)if(s===" "){let i=4-n%4;r+=" ".repeat(i),n+=i}else r+=s,n++;return r}function tn(e,t,n,r,s){let i=t.href,a=t.title||null,o=e[1].replace(s.other.outputLinkReplace,"$1");r.state.inLink=!0;let c={type:e[0].charAt(0)==="!"?"image":"link",raw:n,href:i,title:a,text:o,tokens:r.inlineTokens(o)};return r.state.inLink=!1,c}function Zr(e,t,n){let r=e.match(n.other.indentCodeCompensation);if(r===null)return t;let s=r[1];return t.split(`
5
5
  `).map(i=>{let a=i.match(n.other.beginningSpace);if(a===null)return i;let[o]=a;return o.length>=s.length?i.slice(s.length):i}).join(`
6
- `)}var Ae=class{options;rules;lexer;constructor(e){this.options=e||ue}space(e){let t=this.rules.block.newline.exec(e);if(t&&t[0].length>0)return{type:"space",raw:t[0]}}code(e){let t=this.rules.block.code.exec(e);if(t){let n=this.options.pedantic?t[0]:en(t[0]),r=n.replace(this.rules.other.codeRemoveIndent,"");return{type:"code",raw:n,codeBlockStyle:"indented",text:r}}}fences(e){let t=this.rules.block.fences.exec(e);if(t){let n=t[0],r=Gr(n,t[3]||"",this.rules);return{type:"code",raw:n,lang:t[2]?t[2].trim().replace(this.rules.inline.anyPunctuation,"$1"):t[2],text:r}}}heading(e){let t=this.rules.block.heading.exec(e);if(t){let n=t[2].trim();if(this.rules.other.endingHash.test(n)){let r=ne(n,"#");(this.options.pedantic||!r||this.rules.other.endingSpaceChar.test(r))&&(n=r.trim())}return{type:"heading",raw:ne(t[0],`
6
+ `)}var Ae=class{options;rules;lexer;constructor(e){this.options=e||ue}space(e){let t=this.rules.block.newline.exec(e);if(t&&t[0].length>0)return{type:"space",raw:t[0]}}code(e){let t=this.rules.block.code.exec(e);if(t){let n=this.options.pedantic?t[0]:en(t[0]),r=n.replace(this.rules.other.codeRemoveIndent,"");return{type:"code",raw:n,codeBlockStyle:"indented",text:r}}}fences(e){let t=this.rules.block.fences.exec(e);if(t){let n=t[0],r=Zr(n,t[3]||"",this.rules);return{type:"code",raw:n,lang:t[2]?t[2].trim().replace(this.rules.inline.anyPunctuation,"$1"):t[2],text:r}}}heading(e){let t=this.rules.block.heading.exec(e);if(t){let n=t[2].trim();if(this.rules.other.endingHash.test(n)){let r=ne(n,"#");(this.options.pedantic||!r||this.rules.other.endingSpaceChar.test(r))&&(n=r.trim())}return{type:"heading",raw:ne(t[0],`
7
7
  `),depth:t[1].length,text:n,tokens:this.lexer.inline(n)}}}hr(e){let t=this.rules.block.hr.exec(e);if(t)return{type:"hr",raw:ne(t[0],`
8
8
  `)}}blockquote(e){let t=this.rules.block.blockquote.exec(e);if(t){let n=ne(t[0],`
9
9
  `).split(`
10
10
  `),r="",s="",i=[];for(;n.length>0;){let a=!1,o=[],c;for(c=0;c<n.length;c++)if(this.rules.other.blockquoteStart.test(n[c]))o.push(n[c]),a=!0;else if(!a)o.push(n[c]);else break;n=n.slice(c);let l=o.join(`
11
- `),h=l.replace(this.rules.other.blockquoteSetextReplace,`
11
+ `),p=l.replace(this.rules.other.blockquoteSetextReplace,`
12
12
  $1`).replace(this.rules.other.blockquoteSetextReplace2,"");r=r?`${r}
13
13
  ${l}`:l,s=s?`${s}
14
- ${h}`:h;let u=this.lexer.state.top;if(this.lexer.state.top=!0,this.lexer.blockTokens(h,i,!0),this.lexer.state.top=u,n.length===0)break;let d=i.at(-1);if(d?.type==="code")break;if(d?.type==="blockquote"){let m=d,k=m.raw+`
14
+ ${p}`:p;let u=this.lexer.state.top;if(this.lexer.state.top=!0,this.lexer.blockTokens(p,i,!0),this.lexer.state.top=u,n.length===0)break;let d=i.at(-1);if(d?.type==="code")break;if(d?.type==="blockquote"){let m=d,k=m.raw+`
15
15
  `+n.join(`
16
16
  `),v=this.blockquote(k);i[i.length-1]=v,r=r.substring(0,r.length-m.raw.length)+v.raw,s=s.substring(0,s.length-m.text.length)+v.text;break}else if(d?.type==="list"){let m=d,k=m.raw+`
17
17
  `+n.join(`
18
18
  `),v=this.list(k);i[i.length-1]=v,r=r.substring(0,r.length-d.raw.length)+v.raw,s=s.substring(0,s.length-m.raw.length)+v.raw,n=k.substring(i.at(-1).raw.length).split(`
19
- `);continue}}return{type:"blockquote",raw:r,tokens:i,text:s}}}list(e){let t=this.rules.block.list.exec(e);if(t){let n=t[1].trim(),r=n.length>1,s={type:"list",raw:"",ordered:r,start:r?+n.slice(0,-1):"",loose:!1,items:[]};n=r?`\\d{1,9}\\${n.slice(-1)}`:`\\${n}`,this.options.pedantic&&(n=r?n:"[*+-]");let i=this.rules.other.listItemRegex(n),a=!1;for(;e;){let c=!1,l="",h="";if(!(t=i.exec(e))||this.rules.block.hr.test(e))break;l=t[0],e=e.substring(l.length);let u=Wr(t[2].split(`
19
+ `);continue}}return{type:"blockquote",raw:r,tokens:i,text:s}}}list(e){let t=this.rules.block.list.exec(e);if(t){let n=t[1].trim(),r=n.length>1,s={type:"list",raw:"",ordered:r,start:r?+n.slice(0,-1):"",loose:!1,items:[]};n=r?`\\d{1,9}\\${n.slice(-1)}`:`\\${n}`,this.options.pedantic&&(n=r?n:"[*+-]");let i=this.rules.other.listItemRegex(n),a=!1;for(;e;){let c=!1,l="",p="";if(!(t=i.exec(e))||this.rules.block.hr.test(e))break;l=t[0],e=e.substring(l.length);let u=Gr(t[2].split(`
20
20
  `,1)[0],t[1].length),d=e.split(`
21
- `,1)[0],m=!u.trim(),k=0;if(this.options.pedantic?(k=2,h=u.trimStart()):m?k=t[1].length+1:(k=u.search(this.rules.other.nonSpaceChar),k=k>4?1:k,h=u.slice(k),k+=t[1].length),m&&this.rules.other.blankLine.test(d)&&(l+=d+`
22
- `,e=e.substring(d.length+1),c=!0),!c){let v=this.rules.other.nextBulletRegex(k),$=this.rules.other.hrRegex(k),x=this.rules.other.fencesBeginRegex(k),O=this.rules.other.headingBeginRegex(k),U=this.rules.other.htmlBeginRegex(k),q=this.rules.other.blockquoteBeginRegex(k);for(;e;){let b=e.split(`
23
- `,1)[0],S;if(d=b,this.options.pedantic?(d=d.replace(this.rules.other.listReplaceNesting," "),S=d):S=d.replace(this.rules.other.tabCharGlobal," "),x.test(d)||O.test(d)||U.test(d)||q.test(d)||v.test(d)||$.test(d))break;if(S.search(this.rules.other.nonSpaceChar)>=k||!d.trim())h+=`
24
- `+S.slice(k);else{if(m||u.replace(this.rules.other.tabCharGlobal," ").search(this.rules.other.nonSpaceChar)>=4||x.test(u)||O.test(u)||$.test(u))break;h+=`
21
+ `,1)[0],m=!u.trim(),k=0;if(this.options.pedantic?(k=2,p=u.trimStart()):m?k=t[1].length+1:(k=u.search(this.rules.other.nonSpaceChar),k=k>4?1:k,p=u.slice(k),k+=t[1].length),m&&this.rules.other.blankLine.test(d)&&(l+=d+`
22
+ `,e=e.substring(d.length+1),c=!0),!c){let v=this.rules.other.nextBulletRegex(k),$=this.rules.other.hrRegex(k),x=this.rules.other.fencesBeginRegex(k),O=this.rules.other.headingBeginRegex(k),U=this.rules.other.htmlBeginRegex(k),j=this.rules.other.blockquoteBeginRegex(k);for(;e;){let b=e.split(`
23
+ `,1)[0],S;if(d=b,this.options.pedantic?(d=d.replace(this.rules.other.listReplaceNesting," "),S=d):S=d.replace(this.rules.other.tabCharGlobal," "),x.test(d)||O.test(d)||U.test(d)||j.test(d)||v.test(d)||$.test(d))break;if(S.search(this.rules.other.nonSpaceChar)>=k||!d.trim())p+=`
24
+ `+S.slice(k);else{if(m||u.replace(this.rules.other.tabCharGlobal," ").search(this.rules.other.nonSpaceChar)>=4||x.test(u)||O.test(u)||$.test(u))break;p+=`
25
25
  `+d}m=!d.trim(),l+=b+`
26
- `,e=e.substring(b.length+1),u=S.slice(k)}}s.loose||(a?s.loose=!0:this.rules.other.doubleBlankLine.test(l)&&(a=!0)),s.items.push({type:"list_item",raw:l,task:!!this.options.gfm&&this.rules.other.listIsTask.test(h),loose:!1,text:h,tokens:[]}),s.raw+=l}let o=s.items.at(-1);if(o)o.raw=o.raw.trimEnd(),o.text=o.text.trimEnd();else return;s.raw=s.raw.trimEnd();for(let c of s.items){this.lexer.state.top=!1,c.tokens=this.lexer.blockTokens(c.text,[]);let l=c.tokens[0];if(c.task&&(l?.type==="text"||l?.type==="paragraph")){c.text=c.text.replace(this.rules.other.listReplaceTask,""),l.raw=l.raw.replace(this.rules.other.listReplaceTask,""),l.text=l.text.replace(this.rules.other.listReplaceTask,"");for(let u=this.lexer.inlineQueue.length-1;u>=0;u--)if(this.rules.other.listIsTask.test(this.lexer.inlineQueue[u].src)){this.lexer.inlineQueue[u].src=this.lexer.inlineQueue[u].src.replace(this.rules.other.listReplaceTask,"");break}let h=this.rules.other.listTaskCheckbox.exec(c.raw);if(h){let u={type:"checkbox",raw:h[0]+" ",checked:h[0]!=="[ ]"};c.checked=u.checked,s.loose?c.tokens[0]&&["paragraph","text"].includes(c.tokens[0].type)&&"tokens"in c.tokens[0]&&c.tokens[0].tokens?(c.tokens[0].raw=u.raw+c.tokens[0].raw,c.tokens[0].text=u.raw+c.tokens[0].text,c.tokens[0].tokens.unshift(u)):c.tokens.unshift({type:"paragraph",raw:u.raw,text:u.raw,tokens:[u]}):c.tokens.unshift(u)}}else c.task&&(c.task=!1);if(!s.loose){let h=c.tokens.filter(d=>d.type==="space"),u=h.length>0&&h.some(d=>this.rules.other.anyLine.test(d.raw));s.loose=u}}if(s.loose)for(let c of s.items){c.loose=!0;for(let l of c.tokens)l.type==="text"&&(l.type="paragraph")}return s}}html(e){let t=this.rules.block.html.exec(e);if(t){let n=en(t[0]);return{type:"html",block:!0,raw:n,pre:t[1]==="pre"||t[1]==="script"||t[1]==="style",text:n}}}def(e){let t=this.rules.block.def.exec(e);if(t){let n=t[1].toLowerCase().replace(this.rules.other.multipleSpaceGlobal," "),r=t[2]?t[2].replace(this.rules.other.hrefBrackets,"$1").replace(this.rules.inline.anyPunctuation,"$1"):"",s=t[3]?t[3].substring(1,t[3].length-1).replace(this.rules.inline.anyPunctuation,"$1"):t[3];return{type:"def",tag:n,raw:ne(t[0],`
26
+ `,e=e.substring(b.length+1),u=S.slice(k)}}s.loose||(a?s.loose=!0:this.rules.other.doubleBlankLine.test(l)&&(a=!0)),s.items.push({type:"list_item",raw:l,task:!!this.options.gfm&&this.rules.other.listIsTask.test(p),loose:!1,text:p,tokens:[]}),s.raw+=l}let o=s.items.at(-1);if(o)o.raw=o.raw.trimEnd(),o.text=o.text.trimEnd();else return;s.raw=s.raw.trimEnd();for(let c of s.items){this.lexer.state.top=!1,c.tokens=this.lexer.blockTokens(c.text,[]);let l=c.tokens[0];if(c.task&&(l?.type==="text"||l?.type==="paragraph")){c.text=c.text.replace(this.rules.other.listReplaceTask,""),l.raw=l.raw.replace(this.rules.other.listReplaceTask,""),l.text=l.text.replace(this.rules.other.listReplaceTask,"");for(let u=this.lexer.inlineQueue.length-1;u>=0;u--)if(this.rules.other.listIsTask.test(this.lexer.inlineQueue[u].src)){this.lexer.inlineQueue[u].src=this.lexer.inlineQueue[u].src.replace(this.rules.other.listReplaceTask,"");break}let p=this.rules.other.listTaskCheckbox.exec(c.raw);if(p){let u={type:"checkbox",raw:p[0]+" ",checked:p[0]!=="[ ]"};c.checked=u.checked,s.loose?c.tokens[0]&&["paragraph","text"].includes(c.tokens[0].type)&&"tokens"in c.tokens[0]&&c.tokens[0].tokens?(c.tokens[0].raw=u.raw+c.tokens[0].raw,c.tokens[0].text=u.raw+c.tokens[0].text,c.tokens[0].tokens.unshift(u)):c.tokens.unshift({type:"paragraph",raw:u.raw,text:u.raw,tokens:[u]}):c.tokens.unshift(u)}}else c.task&&(c.task=!1);if(!s.loose){let p=c.tokens.filter(d=>d.type==="space"),u=p.length>0&&p.some(d=>this.rules.other.anyLine.test(d.raw));s.loose=u}}if(s.loose)for(let c of s.items){c.loose=!0;for(let l of c.tokens)l.type==="text"&&(l.type="paragraph")}return s}}html(e){let t=this.rules.block.html.exec(e);if(t){let n=en(t[0]);return{type:"html",block:!0,raw:n,pre:t[1]==="pre"||t[1]==="script"||t[1]==="style",text:n}}}def(e){let t=this.rules.block.def.exec(e);if(t){let n=t[1].toLowerCase().replace(this.rules.other.multipleSpaceGlobal," "),r=t[2]?t[2].replace(this.rules.other.hrefBrackets,"$1").replace(this.rules.inline.anyPunctuation,"$1"):"",s=t[3]?t[3].substring(1,t[3].length-1).replace(this.rules.inline.anyPunctuation,"$1"):t[3];return{type:"def",tag:n,raw:ne(t[0],`
27
27
  `),href:r,title:s}}}table(e){let t=this.rules.block.table.exec(e);if(!t||!this.rules.other.tableDelimiter.test(t[2]))return;let n=Yt(t[1]),r=t[2].replace(this.rules.other.tableAlignChars,"").split("|"),s=t[3]?.trim()?t[3].replace(this.rules.other.tableRowBlankLine,"").split(`
28
28
  `):[],i={type:"table",raw:ne(t[0],`
29
29
  `),header:[],align:[],rows:[]};if(n.length===r.length){for(let a of r)this.rules.other.tableAlignRight.test(a)?i.align.push("right"):this.rules.other.tableAlignCenter.test(a)?i.align.push("center"):this.rules.other.tableAlignLeft.test(a)?i.align.push("left"):i.align.push(null);for(let a=0;a<n.length;a++)i.header.push({text:n[a],tokens:this.lexer.inline(n[a]),header:!0,align:i.align[a]});for(let a of s)i.rows.push(Yt(a,i.header.length).map((o,c)=>({text:o,tokens:this.lexer.inline(o),header:!1,align:i.align[c]})));return i}}lheading(e){let t=this.rules.block.lheading.exec(e);if(t){let n=t[1].trim();return{type:"heading",raw:ne(t[0],`
30
30
  `),depth:t[2].charAt(0)==="="?1:2,text:n,tokens:this.lexer.inline(n)}}}paragraph(e){let t=this.rules.block.paragraph.exec(e);if(t){let n=t[1].charAt(t[1].length-1)===`
31
- `?t[1].slice(0,-1):t[1];return{type:"paragraph",raw:t[0],text:n,tokens:this.lexer.inline(n)}}}text(e){let t=this.rules.block.text.exec(e);if(t)return{type:"text",raw:t[0],text:t[0],tokens:this.lexer.inline(t[0])}}escape(e){let t=this.rules.inline.escape.exec(e);if(t)return{type:"escape",raw:t[0],text:t[1]}}tag(e){let t=this.rules.inline.tag.exec(e);if(t)return!this.lexer.state.inLink&&this.rules.other.startATag.test(t[0])?this.lexer.state.inLink=!0:this.lexer.state.inLink&&this.rules.other.endATag.test(t[0])&&(this.lexer.state.inLink=!1),!this.lexer.state.inRawBlock&&this.rules.other.startPreScriptTag.test(t[0])?this.lexer.state.inRawBlock=!0:this.lexer.state.inRawBlock&&this.rules.other.endPreScriptTag.test(t[0])&&(this.lexer.state.inRawBlock=!1),{type:"html",raw:t[0],inLink:this.lexer.state.inLink,inRawBlock:this.lexer.state.inRawBlock,block:!1,text:t[0]}}link(e){let t=this.rules.inline.link.exec(e);if(t){let n=t[2].trim();if(!this.options.pedantic&&this.rules.other.startAngleBracket.test(n)){if(!this.rules.other.endAngleBracket.test(n))return;let i=ne(n.slice(0,-1),"\\");if((n.length-i.length)%2===0)return}else{let i=Kr(t[2],"()");if(i===-2)return;if(i>-1){let a=(t[0].indexOf("!")===0?5:4)+t[1].length+i;t[2]=t[2].substring(0,i),t[0]=t[0].substring(0,a).trim(),t[3]=""}}let r=t[2],s="";if(this.options.pedantic){let i=this.rules.other.pedanticHrefTitle.exec(r);i&&(r=i[1],s=i[3])}else s=t[3]?t[3].slice(1,-1):"";return r=r.trim(),this.rules.other.startAngleBracket.test(r)&&(this.options.pedantic&&!this.rules.other.endAngleBracket.test(n)?r=r.slice(1):r=r.slice(1,-1)),tn(t,{href:r&&r.replace(this.rules.inline.anyPunctuation,"$1"),title:s&&s.replace(this.rules.inline.anyPunctuation,"$1")},t[0],this.lexer,this.rules)}}reflink(e,t){let n;if((n=this.rules.inline.reflink.exec(e))||(n=this.rules.inline.nolink.exec(e))){let r=(n[2]||n[1]).replace(this.rules.other.multipleSpaceGlobal," "),s=t[r.toLowerCase()];if(!s){let i=n[0].charAt(0);return{type:"text",raw:i,text:i}}return tn(n,s,n[0],this.lexer,this.rules)}}emStrong(e,t,n=""){let r=this.rules.inline.emStrongLDelim.exec(e);if(!(!r||!r[1]&&!r[2]&&!r[3]&&!r[4]||r[4]&&n.match(this.rules.other.unicodeAlphaNumeric))&&(!(r[1]||r[3])||!n||this.rules.inline.punctuation.exec(n))){let s=[...r[0]].length-1,i,a,o=s,c=0,l=r[0][0]==="*"?this.rules.inline.emStrongRDelimAst:this.rules.inline.emStrongRDelimUnd;for(l.lastIndex=0,t=t.slice(-1*e.length+s);(r=l.exec(t))!==null;){if(i=r[1]||r[2]||r[3]||r[4]||r[5]||r[6],!i)continue;if(a=[...i].length,r[3]||r[4]){o+=a;continue}else if((r[5]||r[6])&&s%3&&!((s+a)%3)){c+=a;continue}if(o-=a,o>0)continue;a=Math.min(a,a+o+c);let h=[...r[0]][0].length,u=e.slice(0,s+r.index+h+a);if(Math.min(s,a)%2){let m=u.slice(1,-1);return{type:"em",raw:u,text:m,tokens:this.lexer.inlineTokens(m)}}let d=u.slice(2,-2);return{type:"strong",raw:u,text:d,tokens:this.lexer.inlineTokens(d)}}}}codespan(e){let t=this.rules.inline.code.exec(e);if(t){let n=t[2].replace(this.rules.other.newLineCharGlobal," "),r=this.rules.other.nonSpaceChar.test(n),s=this.rules.other.startingSpaceChar.test(n)&&this.rules.other.endingSpaceChar.test(n);return r&&s&&(n=n.substring(1,n.length-1)),{type:"codespan",raw:t[0],text:n}}}br(e){let t=this.rules.inline.br.exec(e);if(t)return{type:"br",raw:t[0]}}del(e,t,n=""){let r=this.rules.inline.delLDelim.exec(e);if(r&&(!r[1]||!n||this.rules.inline.punctuation.exec(n))){let s=[...r[0]].length-1,i,a,o=s,c=this.rules.inline.delRDelim;for(c.lastIndex=0,t=t.slice(-1*e.length+s);(r=c.exec(t))!==null;){if(i=r[1]||r[2]||r[3]||r[4]||r[5]||r[6],!i||(a=[...i].length,a!==s))continue;if(r[3]||r[4]){o+=a;continue}if(o-=a,o>0)continue;a=Math.min(a,a+o);let l=[...r[0]][0].length,h=e.slice(0,s+r.index+l+a),u=h.slice(s,-s);return{type:"del",raw:h,text:u,tokens:this.lexer.inlineTokens(u)}}}}autolink(e){let t=this.rules.inline.autolink.exec(e);if(t){let n,r;return t[2]==="@"?(n=t[1],r="mailto:"+n):(n=t[1],r=n),{type:"link",raw:t[0],text:n,href:r,tokens:[{type:"text",raw:n,text:n}]}}}url(e){let t;if(t=this.rules.inline.url.exec(e)){let n,r;if(t[2]==="@")n=t[0],r="mailto:"+n;else{let s;do s=t[0],t[0]=this.rules.inline._backpedal.exec(t[0])?.[0]??"";while(s!==t[0]);n=t[0],t[1]==="www."?r="http://"+t[0]:r=t[0]}return{type:"link",raw:t[0],text:n,href:r,tokens:[{type:"text",raw:n,text:n}]}}}inlineText(e){let t=this.rules.inline.text.exec(e);if(t){let n=this.lexer.state.inRawBlock;return{type:"text",raw:t[0],text:t[0],escaped:n}}}},j=class Ve{tokens;options;state;inlineQueue;tokenizer;constructor(t){this.tokens=[],this.tokens.links=Object.create(null),this.options=t||ue,this.options.tokenizer=this.options.tokenizer||new Ae,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:P,block:Te.normal,inline:Se.normal};this.options.pedantic?(n.block=Te.pedantic,n.inline=Se.pedantic):this.options.gfm&&(n.block=Te.gfm,this.options.breaks?n.inline=Se.breaks:n.inline=Se.gfm),this.tokenizer.rules=n}static get rules(){return{block:Te,inline:Se}}static lex(t,n){return new Ve(n).lex(t)}static lexInline(t,n){return new Ve(n).inlineTokens(t)}lex(t){t=t.replace(P.carriageReturn,`
31
+ `?t[1].slice(0,-1):t[1];return{type:"paragraph",raw:t[0],text:n,tokens:this.lexer.inline(n)}}}text(e){let t=this.rules.block.text.exec(e);if(t)return{type:"text",raw:t[0],text:t[0],tokens:this.lexer.inline(t[0])}}escape(e){let t=this.rules.inline.escape.exec(e);if(t)return{type:"escape",raw:t[0],text:t[1]}}tag(e){let t=this.rules.inline.tag.exec(e);if(t)return!this.lexer.state.inLink&&this.rules.other.startATag.test(t[0])?this.lexer.state.inLink=!0:this.lexer.state.inLink&&this.rules.other.endATag.test(t[0])&&(this.lexer.state.inLink=!1),!this.lexer.state.inRawBlock&&this.rules.other.startPreScriptTag.test(t[0])?this.lexer.state.inRawBlock=!0:this.lexer.state.inRawBlock&&this.rules.other.endPreScriptTag.test(t[0])&&(this.lexer.state.inRawBlock=!1),{type:"html",raw:t[0],inLink:this.lexer.state.inLink,inRawBlock:this.lexer.state.inRawBlock,block:!1,text:t[0]}}link(e){let t=this.rules.inline.link.exec(e);if(t){let n=t[2].trim();if(!this.options.pedantic&&this.rules.other.startAngleBracket.test(n)){if(!this.rules.other.endAngleBracket.test(n))return;let i=ne(n.slice(0,-1),"\\");if((n.length-i.length)%2===0)return}else{let i=Wr(t[2],"()");if(i===-2)return;if(i>-1){let a=(t[0].indexOf("!")===0?5:4)+t[1].length+i;t[2]=t[2].substring(0,i),t[0]=t[0].substring(0,a).trim(),t[3]=""}}let r=t[2],s="";if(this.options.pedantic){let i=this.rules.other.pedanticHrefTitle.exec(r);i&&(r=i[1],s=i[3])}else s=t[3]?t[3].slice(1,-1):"";return r=r.trim(),this.rules.other.startAngleBracket.test(r)&&(this.options.pedantic&&!this.rules.other.endAngleBracket.test(n)?r=r.slice(1):r=r.slice(1,-1)),tn(t,{href:r&&r.replace(this.rules.inline.anyPunctuation,"$1"),title:s&&s.replace(this.rules.inline.anyPunctuation,"$1")},t[0],this.lexer,this.rules)}}reflink(e,t){let n;if((n=this.rules.inline.reflink.exec(e))||(n=this.rules.inline.nolink.exec(e))){let r=(n[2]||n[1]).replace(this.rules.other.multipleSpaceGlobal," "),s=t[r.toLowerCase()];if(!s){let i=n[0].charAt(0);return{type:"text",raw:i,text:i}}return tn(n,s,n[0],this.lexer,this.rules)}}emStrong(e,t,n=""){let r=this.rules.inline.emStrongLDelim.exec(e);if(!(!r||!r[1]&&!r[2]&&!r[3]&&!r[4]||r[4]&&n.match(this.rules.other.unicodeAlphaNumeric))&&(!(r[1]||r[3])||!n||this.rules.inline.punctuation.exec(n))){let s=[...r[0]].length-1,i,a,o=s,c=0,l=r[0][0]==="*"?this.rules.inline.emStrongRDelimAst:this.rules.inline.emStrongRDelimUnd;for(l.lastIndex=0,t=t.slice(-1*e.length+s);(r=l.exec(t))!==null;){if(i=r[1]||r[2]||r[3]||r[4]||r[5]||r[6],!i)continue;if(a=[...i].length,r[3]||r[4]){o+=a;continue}else if((r[5]||r[6])&&s%3&&!((s+a)%3)){c+=a;continue}if(o-=a,o>0)continue;a=Math.min(a,a+o+c);let p=[...r[0]][0].length,u=e.slice(0,s+r.index+p+a);if(Math.min(s,a)%2){let m=u.slice(1,-1);return{type:"em",raw:u,text:m,tokens:this.lexer.inlineTokens(m)}}let d=u.slice(2,-2);return{type:"strong",raw:u,text:d,tokens:this.lexer.inlineTokens(d)}}}}codespan(e){let t=this.rules.inline.code.exec(e);if(t){let n=t[2].replace(this.rules.other.newLineCharGlobal," "),r=this.rules.other.nonSpaceChar.test(n),s=this.rules.other.startingSpaceChar.test(n)&&this.rules.other.endingSpaceChar.test(n);return r&&s&&(n=n.substring(1,n.length-1)),{type:"codespan",raw:t[0],text:n}}}br(e){let t=this.rules.inline.br.exec(e);if(t)return{type:"br",raw:t[0]}}del(e,t,n=""){let r=this.rules.inline.delLDelim.exec(e);if(r&&(!r[1]||!n||this.rules.inline.punctuation.exec(n))){let s=[...r[0]].length-1,i,a,o=s,c=this.rules.inline.delRDelim;for(c.lastIndex=0,t=t.slice(-1*e.length+s);(r=c.exec(t))!==null;){if(i=r[1]||r[2]||r[3]||r[4]||r[5]||r[6],!i||(a=[...i].length,a!==s))continue;if(r[3]||r[4]){o+=a;continue}if(o-=a,o>0)continue;a=Math.min(a,a+o);let l=[...r[0]][0].length,p=e.slice(0,s+r.index+l+a),u=p.slice(s,-s);return{type:"del",raw:p,text:u,tokens:this.lexer.inlineTokens(u)}}}}autolink(e){let t=this.rules.inline.autolink.exec(e);if(t){let n,r;return t[2]==="@"?(n=t[1],r="mailto:"+n):(n=t[1],r=n),{type:"link",raw:t[0],text:n,href:r,tokens:[{type:"text",raw:n,text:n}]}}}url(e){let t;if(t=this.rules.inline.url.exec(e)){let n,r;if(t[2]==="@")n=t[0],r="mailto:"+n;else{let s;do s=t[0],t[0]=this.rules.inline._backpedal.exec(t[0])?.[0]??"";while(s!==t[0]);n=t[0],t[1]==="www."?r="http://"+t[0]:r=t[0]}return{type:"link",raw:t[0],text:n,href:r,tokens:[{type:"text",raw:n,text:n}]}}}inlineText(e){let t=this.rules.inline.text.exec(e);if(t){let n=this.lexer.state.inRawBlock;return{type:"text",raw:t[0],text:t[0],escaped:n}}}},q=class Ve{tokens;options;state;inlineQueue;tokenizer;constructor(t){this.tokens=[],this.tokens.links=Object.create(null),this.options=t||ue,this.options.tokenizer=this.options.tokenizer||new Ae,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:P,block:Te.normal,inline:Se.normal};this.options.pedantic?(n.block=Te.pedantic,n.inline=Se.pedantic):this.options.gfm&&(n.block=Te.gfm,this.options.breaks?n.inline=Se.breaks:n.inline=Se.gfm),this.tokenizer.rules=n}static get rules(){return{block:Te,inline:Se}}static lex(t,n){return new Ve(n).lex(t)}static lexInline(t,n){return new Ve(n).inlineTokens(t)}lex(t){t=t.replace(P.carriageReturn,`
32
32
  `),this.blockTokens(t,this.tokens);for(let n=0;n<this.inlineQueue.length;n++){let r=this.inlineQueue[n];this.inlineTokens(r.src,r.tokens)}return this.inlineQueue=[],this.tokens}blockTokens(t,n=[],r=!1){this.tokenizer.lexer=this,this.options.pedantic&&(t=t.replace(P.tabCharGlobal," ").replace(P.spaceLine,""));let s=1/0;for(;t;){if(t.length<s)s=t.length;else{this.infiniteLoopError(t.charCodeAt(0));break}let i;if(this.options.extensions?.block?.some(o=>(i=o.call({lexer:this},t,n))?(t=t.substring(i.raw.length),n.push(i),!0):!1))continue;if(i=this.tokenizer.space(t)){t=t.substring(i.raw.length);let o=n.at(-1);i.raw.length===1&&o!==void 0?o.raw+=`
33
33
  `:n.push(i);continue}if(i=this.tokenizer.code(t)){t=t.substring(i.raw.length);let o=n.at(-1);o?.type==="paragraph"||o?.type==="text"?(o.raw+=(o.raw.endsWith(`
34
34
  `)?"":`
@@ -36,13 +36,13 @@ ${h}`:h;let u=this.lexer.state.top;if(this.lexer.state.top=!0,this.lexer.blockTo
36
36
  `+i.text,this.inlineQueue.at(-1).src=o.text):n.push(i);continue}if(i=this.tokenizer.fences(t)){t=t.substring(i.raw.length),n.push(i);continue}if(i=this.tokenizer.heading(t)){t=t.substring(i.raw.length),n.push(i);continue}if(i=this.tokenizer.hr(t)){t=t.substring(i.raw.length),n.push(i);continue}if(i=this.tokenizer.blockquote(t)){t=t.substring(i.raw.length),n.push(i);continue}if(i=this.tokenizer.list(t)){t=t.substring(i.raw.length),n.push(i);continue}if(i=this.tokenizer.html(t)){t=t.substring(i.raw.length),n.push(i);continue}if(i=this.tokenizer.def(t)){t=t.substring(i.raw.length);let o=n.at(-1);o?.type==="paragraph"||o?.type==="text"?(o.raw+=(o.raw.endsWith(`
37
37
  `)?"":`
38
38
  `)+i.raw,o.text+=`
39
- `+i.raw,this.inlineQueue.at(-1).src=o.text):this.tokens.links[i.tag]||(this.tokens.links[i.tag]={href:i.href,title:i.title},n.push(i));continue}if(i=this.tokenizer.table(t)){t=t.substring(i.raw.length),n.push(i);continue}if(i=this.tokenizer.lheading(t)){t=t.substring(i.raw.length),n.push(i);continue}let a=t;if(this.options.extensions?.startBlock){let o=1/0,c=t.slice(1),l;this.options.extensions.startBlock.forEach(h=>{l=h.call({lexer:this},c),typeof l=="number"&&l>=0&&(o=Math.min(o,l))}),o<1/0&&o>=0&&(a=t.substring(0,o+1))}if(this.state.top&&(i=this.tokenizer.paragraph(a))){let o=n.at(-1);r&&o?.type==="paragraph"?(o.raw+=(o.raw.endsWith(`
39
+ `+i.raw,this.inlineQueue.at(-1).src=o.text):this.tokens.links[i.tag]||(this.tokens.links[i.tag]={href:i.href,title:i.title},n.push(i));continue}if(i=this.tokenizer.table(t)){t=t.substring(i.raw.length),n.push(i);continue}if(i=this.tokenizer.lheading(t)){t=t.substring(i.raw.length),n.push(i);continue}let a=t;if(this.options.extensions?.startBlock){let o=1/0,c=t.slice(1),l;this.options.extensions.startBlock.forEach(p=>{l=p.call({lexer:this},c),typeof l=="number"&&l>=0&&(o=Math.min(o,l))}),o<1/0&&o>=0&&(a=t.substring(0,o+1))}if(this.state.top&&(i=this.tokenizer.paragraph(a))){let o=n.at(-1);r&&o?.type==="paragraph"?(o.raw+=(o.raw.endsWith(`
40
40
  `)?"":`
41
41
  `)+i.raw,o.text+=`
42
42
  `+i.text,this.inlineQueue.pop(),this.inlineQueue.at(-1).src=o.text):n.push(i),r=a.length!==t.length,t=t.substring(i.raw.length);continue}if(i=this.tokenizer.text(t)){t=t.substring(i.raw.length);let o=n.at(-1);o?.type==="text"?(o.raw+=(o.raw.endsWith(`
43
43
  `)?"":`
44
44
  `)+i.raw,o.text+=`
45
- `+i.text,this.inlineQueue.pop(),this.inlineQueue.at(-1).src=o.text):n.push(i);continue}if(t){this.infiniteLoopError(t.charCodeAt(0));break}}return this.state.top=!0,n}inline(t,n=[]){return this.inlineQueue.push({src:t,tokens:n}),n}inlineTokens(t,n=[]){this.tokenizer.lexer=this;let r=t,s=null;if(this.tokens.links){let l=Object.keys(this.tokens.links);if(l.length>0)for(;(s=this.tokenizer.rules.inline.reflinkSearch.exec(r))!==null;)l.includes(s[0].slice(s[0].lastIndexOf("[")+1,-1))&&(r=r.slice(0,s.index)+"["+"a".repeat(s[0].length-2)+"]"+r.slice(this.tokenizer.rules.inline.reflinkSearch.lastIndex))}for(;(s=this.tokenizer.rules.inline.anyPunctuation.exec(r))!==null;)r=r.slice(0,s.index)+"++"+r.slice(this.tokenizer.rules.inline.anyPunctuation.lastIndex);let i;for(;(s=this.tokenizer.rules.inline.blockSkip.exec(r))!==null;)i=s[2]?s[2].length:0,r=r.slice(0,s.index+i)+"["+"a".repeat(s[0].length-i-2)+"]"+r.slice(this.tokenizer.rules.inline.blockSkip.lastIndex);r=this.options.hooks?.emStrongMask?.call({lexer:this},r)??r;let a=!1,o="",c=1/0;for(;t;){if(t.length<c)c=t.length;else{this.infiniteLoopError(t.charCodeAt(0));break}a||(o=""),a=!1;let l;if(this.options.extensions?.inline?.some(u=>(l=u.call({lexer:this},t,n))?(t=t.substring(l.raw.length),n.push(l),!0):!1))continue;if(l=this.tokenizer.escape(t)){t=t.substring(l.raw.length),n.push(l);continue}if(l=this.tokenizer.tag(t)){t=t.substring(l.raw.length),n.push(l);continue}if(l=this.tokenizer.link(t)){t=t.substring(l.raw.length),n.push(l);continue}if(l=this.tokenizer.reflink(t,this.tokens.links)){t=t.substring(l.raw.length);let u=n.at(-1);l.type==="text"&&u?.type==="text"?(u.raw+=l.raw,u.text+=l.text):n.push(l);continue}if(l=this.tokenizer.emStrong(t,r,o)){t=t.substring(l.raw.length),n.push(l);continue}if(l=this.tokenizer.codespan(t)){t=t.substring(l.raw.length),n.push(l);continue}if(l=this.tokenizer.br(t)){t=t.substring(l.raw.length),n.push(l);continue}if(l=this.tokenizer.del(t,r,o)){t=t.substring(l.raw.length),n.push(l);continue}if(l=this.tokenizer.autolink(t)){t=t.substring(l.raw.length),n.push(l);continue}if(!this.state.inLink&&(l=this.tokenizer.url(t))){t=t.substring(l.raw.length),n.push(l);continue}let h=t;if(this.options.extensions?.startInline){let u=1/0,d=t.slice(1),m;this.options.extensions.startInline.forEach(k=>{m=k.call({lexer:this},d),typeof m=="number"&&m>=0&&(u=Math.min(u,m))}),u<1/0&&u>=0&&(h=t.substring(0,u+1))}if(l=this.tokenizer.inlineText(h)){t=t.substring(l.raw.length),l.raw.slice(-1)!=="_"&&(o=l.raw.slice(-1)),a=!0;let u=n.at(-1);u?.type==="text"?(u.raw+=l.raw,u.text+=l.text):n.push(l);continue}if(t){this.infiniteLoopError(t.charCodeAt(0));break}}return n}infiniteLoopError(t){let n="Infinite loop on byte: "+t;if(this.options.silent)console.error(n);else throw new Error(n)}},Oe=class{options;parser;constructor(e){this.options=e||ue}space(e){return""}code({text:e,lang:t,escaped:n}){let r=(t||"").match(P.notSpaceStart)?.[0],s=e.replace(P.endingNewline,"")+`
45
+ `+i.text,this.inlineQueue.pop(),this.inlineQueue.at(-1).src=o.text):n.push(i);continue}if(t){this.infiniteLoopError(t.charCodeAt(0));break}}return this.state.top=!0,n}inline(t,n=[]){return this.inlineQueue.push({src:t,tokens:n}),n}inlineTokens(t,n=[]){this.tokenizer.lexer=this;let r=t,s=null;if(this.tokens.links){let l=Object.keys(this.tokens.links);if(l.length>0)for(;(s=this.tokenizer.rules.inline.reflinkSearch.exec(r))!==null;)l.includes(s[0].slice(s[0].lastIndexOf("[")+1,-1))&&(r=r.slice(0,s.index)+"["+"a".repeat(s[0].length-2)+"]"+r.slice(this.tokenizer.rules.inline.reflinkSearch.lastIndex))}for(;(s=this.tokenizer.rules.inline.anyPunctuation.exec(r))!==null;)r=r.slice(0,s.index)+"++"+r.slice(this.tokenizer.rules.inline.anyPunctuation.lastIndex);let i;for(;(s=this.tokenizer.rules.inline.blockSkip.exec(r))!==null;)i=s[2]?s[2].length:0,r=r.slice(0,s.index+i)+"["+"a".repeat(s[0].length-i-2)+"]"+r.slice(this.tokenizer.rules.inline.blockSkip.lastIndex);r=this.options.hooks?.emStrongMask?.call({lexer:this},r)??r;let a=!1,o="",c=1/0;for(;t;){if(t.length<c)c=t.length;else{this.infiniteLoopError(t.charCodeAt(0));break}a||(o=""),a=!1;let l;if(this.options.extensions?.inline?.some(u=>(l=u.call({lexer:this},t,n))?(t=t.substring(l.raw.length),n.push(l),!0):!1))continue;if(l=this.tokenizer.escape(t)){t=t.substring(l.raw.length),n.push(l);continue}if(l=this.tokenizer.tag(t)){t=t.substring(l.raw.length),n.push(l);continue}if(l=this.tokenizer.link(t)){t=t.substring(l.raw.length),n.push(l);continue}if(l=this.tokenizer.reflink(t,this.tokens.links)){t=t.substring(l.raw.length);let u=n.at(-1);l.type==="text"&&u?.type==="text"?(u.raw+=l.raw,u.text+=l.text):n.push(l);continue}if(l=this.tokenizer.emStrong(t,r,o)){t=t.substring(l.raw.length),n.push(l);continue}if(l=this.tokenizer.codespan(t)){t=t.substring(l.raw.length),n.push(l);continue}if(l=this.tokenizer.br(t)){t=t.substring(l.raw.length),n.push(l);continue}if(l=this.tokenizer.del(t,r,o)){t=t.substring(l.raw.length),n.push(l);continue}if(l=this.tokenizer.autolink(t)){t=t.substring(l.raw.length),n.push(l);continue}if(!this.state.inLink&&(l=this.tokenizer.url(t))){t=t.substring(l.raw.length),n.push(l);continue}let p=t;if(this.options.extensions?.startInline){let u=1/0,d=t.slice(1),m;this.options.extensions.startInline.forEach(k=>{m=k.call({lexer:this},d),typeof m=="number"&&m>=0&&(u=Math.min(u,m))}),u<1/0&&u>=0&&(p=t.substring(0,u+1))}if(l=this.tokenizer.inlineText(p)){t=t.substring(l.raw.length),l.raw.slice(-1)!=="_"&&(o=l.raw.slice(-1)),a=!0;let u=n.at(-1);u?.type==="text"?(u.raw+=l.raw,u.text+=l.text):n.push(l);continue}if(t){this.infiniteLoopError(t.charCodeAt(0));break}}return n}infiniteLoopError(t){let n="Infinite loop on byte: "+t;if(this.options.silent)console.error(n);else throw new Error(n)}},Oe=class{options;parser;constructor(e){this.options=e||ue}space(e){return""}code({text:e,lang:t,escaped:n}){let r=(t||"").match(P.notSpaceStart)?.[0],s=e.replace(P.endingNewline,"")+`
46
46
  `;return r?'<pre><code class="language-'+Z(r)+'">'+(n?s:Z(s,!0))+`</code></pre>
47
47
  `:"<pre><code>"+(n?s:Z(s,!0))+`</code></pre>
48
48
  `}blockquote({tokens:e}){return`<blockquote>
@@ -60,44 +60,44 @@ ${this.parser.parse(e)}</blockquote>
60
60
  `}tablerow({text:e}){return`<tr>
61
61
  ${e}</tr>
62
62
  `}tablecell(e){let t=this.parser.parseInline(e.tokens),n=e.header?"th":"td";return(e.align?`<${n} align="${e.align}">`:`<${n}>`)+t+`</${n}>
63
- `}strong({tokens:e}){return`<strong>${this.parser.parseInline(e)}</strong>`}em({tokens:e}){return`<em>${this.parser.parseInline(e)}</em>`}codespan({text:e}){return`<code>${Z(e,!0)}</code>`}br(e){return"<br>"}del({tokens:e}){return`<del>${this.parser.parseInline(e)}</del>`}link({href:e,title:t,tokens:n}){let r=this.parser.parseInline(n),s=Xt(e);if(s===null)return r;e=s;let i='<a href="'+e+'"';return t&&(i+=' title="'+Z(t)+'"'),i+=">"+r+"</a>",i}image({href:e,title:t,text:n,tokens:r}){r&&(n=this.parser.parseInline(r,this.parser.textRenderer));let s=Xt(e);if(s===null)return Z(n);e=s;let i=`<img src="${e}" alt="${Z(n)}"`;return t&&(i+=` title="${Z(t)}"`),i+=">",i}text(e){return"tokens"in e&&e.tokens?this.parser.parseInline(e.tokens):"escaped"in e&&e.escaped?e.text:Z(e.text)}},it=class{strong({text:e}){return e}em({text:e}){return e}codespan({text:e}){return e}del({text:e}){return e}html({text:e}){return e}text({text:e}){return e}link({text:e}){return""+e}image({text:e}){return""+e}br(){return""}checkbox({raw:e}){return e}},F=class Je{options;renderer;textRenderer;constructor(t){this.options=t||ue,this.options.renderer=this.options.renderer||new Oe,this.renderer=this.options.renderer,this.renderer.options=this.options,this.renderer.parser=this,this.textRenderer=new it}static parse(t,n){return new Je(n).parse(t)}static parseInline(t,n){return new Je(n).parseInline(t)}parse(t){this.renderer.parser=this;let n="";for(let r=0;r<t.length;r++){let s=t[r];if(this.options.extensions?.renderers?.[s.type]){let a=s,o=this.options.extensions.renderers[a.type].call({parser:this},a);if(o!==!1||!["space","hr","heading","code","table","blockquote","list","html","def","paragraph","text"].includes(a.type)){n+=o||"";continue}}let i=s;switch(i.type){case"space":{n+=this.renderer.space(i);break}case"hr":{n+=this.renderer.hr(i);break}case"heading":{n+=this.renderer.heading(i);break}case"code":{n+=this.renderer.code(i);break}case"table":{n+=this.renderer.table(i);break}case"blockquote":{n+=this.renderer.blockquote(i);break}case"list":{n+=this.renderer.list(i);break}case"checkbox":{n+=this.renderer.checkbox(i);break}case"html":{n+=this.renderer.html(i);break}case"def":{n+=this.renderer.def(i);break}case"paragraph":{n+=this.renderer.paragraph(i);break}case"text":{n+=this.renderer.text(i);break}default:{let a='Token with "'+i.type+'" type was not found.';if(this.options.silent)return console.error(a),"";throw new Error(a)}}}return n}parseInline(t,n=this.renderer){this.renderer.parser=this;let r="";for(let s=0;s<t.length;s++){let i=t[s];if(this.options.extensions?.renderers?.[i.type]){let o=this.options.extensions.renderers[i.type].call({parser:this},i);if(o!==!1||!["escape","html","link","image","strong","em","codespan","br","del","text"].includes(i.type)){r+=o||"";continue}}let a=i;switch(a.type){case"escape":{r+=n.text(a);break}case"html":{r+=n.html(a);break}case"link":{r+=n.link(a);break}case"image":{r+=n.image(a);break}case"checkbox":{r+=n.checkbox(a);break}case"strong":{r+=n.strong(a);break}case"em":{r+=n.em(a);break}case"codespan":{r+=n.codespan(a);break}case"br":{r+=n.br(a);break}case"del":{r+=n.del(a);break}case"text":{r+=n.text(a);break}default:{let o='Token with "'+a.type+'" type was not found.';if(this.options.silent)return console.error(o),"";throw new Error(o)}}}return r}},Re=class{options;block;constructor(e){this.options=e||ue}static passThroughHooks=new Set(["preprocess","postprocess","processAllTokens","emStrongMask"]);static passThroughHooksRespectAsync=new Set(["preprocess","postprocess","processAllTokens"]);preprocess(e){return e}postprocess(e){return e}processAllTokens(e){return e}emStrongMask(e){return e}provideLexer(e=this.block){return e?j.lex:j.lexInline}provideParser(e=this.block){return e?F.parse:F.parseInline}},ve=class{defaults=Qe();options=this.setOptions;parse=this.parseMarkdown(!0);parseInline=this.parseMarkdown(!1);Parser=F;Renderer=Oe;TextRenderer=it;Lexer=j;Tokenizer=Ae;Hooks=Re;constructor(...e){this.use(...e)}walkTokens(e,t){let n=[];for(let r of e)switch(n=n.concat(t.call(this,r)),r.type){case"table":{let s=r;for(let i of s.header)n=n.concat(this.walkTokens(i.tokens,t));for(let i of s.rows)for(let a of i)n=n.concat(this.walkTokens(a.tokens,t));break}case"list":{let s=r;n=n.concat(this.walkTokens(s.items,t));break}default:{let s=r;this.defaults.extensions?.childTokens?.[s.type]?this.defaults.extensions.childTokens[s.type].forEach(i=>{let a=s[i].flat(1/0);n=n.concat(this.walkTokens(a,t))}):s.tokens&&(n=n.concat(this.walkTokens(s.tokens,t)))}}return n}use(...e){let t=this.defaults.extensions||{renderers:{},childTokens:{}};return e.forEach(n=>{let r={...n};if(r.async=this.defaults.async||r.async||!1,n.extensions&&(n.extensions.forEach(s=>{if(!s.name)throw new Error("extension name required");if("renderer"in s){let i=t.renderers[s.name];i?t.renderers[s.name]=function(...a){let o=s.renderer.apply(this,a);return o===!1&&(o=i.apply(this,a)),o}:t.renderers[s.name]=s.renderer}if("tokenizer"in s){if(!s.level||s.level!=="block"&&s.level!=="inline")throw new Error("extension level must be 'block' or 'inline'");let i=t[s.level];i?i.unshift(s.tokenizer):t[s.level]=[s.tokenizer],s.start&&(s.level==="block"?t.startBlock?t.startBlock.push(s.start):t.startBlock=[s.start]:s.level==="inline"&&(t.startInline?t.startInline.push(s.start):t.startInline=[s.start]))}"childTokens"in s&&s.childTokens&&(t.childTokens[s.name]=s.childTokens)}),r.extensions=t),n.renderer){let s=this.defaults.renderer||new Oe(this.defaults);for(let i in n.renderer){if(!(i in s))throw new Error(`renderer '${i}' does not exist`);if(["options","parser"].includes(i))continue;let a=i,o=n.renderer[a],c=s[a];s[a]=(...l)=>{let h=o.apply(s,l);return h===!1&&(h=c.apply(s,l)),h||""}}r.renderer=s}if(n.tokenizer){let s=this.defaults.tokenizer||new Ae(this.defaults);for(let i in n.tokenizer){if(!(i in s))throw new Error(`tokenizer '${i}' does not exist`);if(["options","rules","lexer"].includes(i))continue;let a=i,o=n.tokenizer[a],c=s[a];s[a]=(...l)=>{let h=o.apply(s,l);return h===!1&&(h=c.apply(s,l)),h}}r.tokenizer=s}if(n.hooks){let s=this.defaults.hooks||new Re;for(let i in n.hooks){if(!(i in s))throw new Error(`hook '${i}' does not exist`);if(["options","block"].includes(i))continue;let a=i,o=n.hooks[a],c=s[a];Re.passThroughHooks.has(i)?s[a]=l=>{if(this.defaults.async&&Re.passThroughHooksRespectAsync.has(i))return(async()=>{let u=await o.call(s,l);return c.call(s,u)})();let h=o.call(s,l);return c.call(s,h)}:s[a]=(...l)=>{if(this.defaults.async)return(async()=>{let u=await o.apply(s,l);return u===!1&&(u=await c.apply(s,l)),u})();let h=o.apply(s,l);return h===!1&&(h=c.apply(s,l)),h}}r.hooks=s}if(n.walkTokens){let s=this.defaults.walkTokens,i=n.walkTokens;r.walkTokens=function(a){let o=[];return o.push(i.call(this,a)),s&&(o=o.concat(s.call(this,a))),o}}this.defaults={...this.defaults,...r}}),this}setOptions(e){return this.defaults={...this.defaults,...e},this}lexer(e,t){return j.lex(e,t??this.defaults)}parser(e,t){return F.parse(e,t??this.defaults)}parseMarkdown(e){return(t,n)=>{let r={...n},s={...this.defaults,...r},i=this.onError(!!s.silent,!!s.async);if(this.defaults.async===!0&&r.async===!1)return i(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 t>"u"||t===null)return i(new Error("marked(): input parameter is undefined or null"));if(typeof t!="string")return i(new Error("marked(): input parameter is of type "+Object.prototype.toString.call(t)+", string expected"));if(s.hooks&&(s.hooks.options=s,s.hooks.block=e),s.async)return(async()=>{let a=s.hooks?await s.hooks.preprocess(t):t,o=await(s.hooks?await s.hooks.provideLexer(e):e?j.lex:j.lexInline)(a,s),c=s.hooks?await s.hooks.processAllTokens(o):o;s.walkTokens&&await Promise.all(this.walkTokens(c,s.walkTokens));let l=await(s.hooks?await s.hooks.provideParser(e):e?F.parse:F.parseInline)(c,s);return s.hooks?await s.hooks.postprocess(l):l})().catch(i);try{s.hooks&&(t=s.hooks.preprocess(t));let a=(s.hooks?s.hooks.provideLexer(e):e?j.lex:j.lexInline)(t,s);s.hooks&&(a=s.hooks.processAllTokens(a)),s.walkTokens&&this.walkTokens(a,s.walkTokens);let o=(s.hooks?s.hooks.provideParser(e):e?F.parse:F.parseInline)(a,s);return s.hooks&&(o=s.hooks.postprocess(o)),o}catch(a){return i(a)}}}onError(e,t){return n=>{if(n.message+=`
64
- Please report this to https://github.com/markedjs/marked.`,e){let r="<p>An error occurred:</p><pre>"+Z(n.message+"",!0)+"</pre>";return t?Promise.resolve(r):r}if(t)return Promise.reject(n);throw n}}},ce=new ve;function y(e,t){return ce.parse(e,t)}y.options=y.setOptions=function(e){return ce.setOptions(e),y.defaults=ce.defaults,nn(y.defaults),y};y.getDefaults=Qe;y.defaults=ue;y.use=function(...e){return ce.use(...e),y.defaults=ce.defaults,nn(y.defaults),y};y.walkTokens=function(e,t){return ce.walkTokens(e,t)};y.parseInline=ce.parseInline;y.Parser=F;y.parser=F.parse;y.Renderer=Oe;y.TextRenderer=it;y.Lexer=j;y.lexer=j.lex;y.Tokenizer=Ae;y.Hooks=Re;y.parse=y;var Ta=y.options,Ia=y.setOptions,Aa=y.use,Oa=y.walkTokens,_a=y.parseInline;var La=F.parse,Pa=j.lex;var Zr=Object.defineProperty,Vr=Object.defineProperties,Jr=Object.getOwnPropertyDescriptors,dn=Object.getOwnPropertySymbols,Qr=Object.prototype.hasOwnProperty,Xr=Object.prototype.propertyIsEnumerable,fn=(e,t,n)=>t in e?Zr(e,t,{enumerable:!0,configurable:!0,writable:!0,value:n}):e[t]=n,xn=(e,t)=>{for(var n in t||(t={}))Qr.call(t,n)&&fn(e,n,t[n]);if(dn)for(var n of dn(t))Xr.call(t,n)&&fn(e,n,t[n]);return e},yn=(e,t)=>Vr(e,Jr(t)),E={PROSE:0,FENCE_MARKER:1,FENCE_INFO:2,FENCE_BODY:3,CODE_SPAN:4,CODE_SPAN_OPEN:5},Yr=/^(`{3,}|~{3,})(.*)$/,es=e=>e!==void 0&&e>="0"&&e<="9",ts=(e,t)=>{let n=t;if(e[n]==="-"||e[n]==="*"||e[n]==="+")n+=1;else{for(;es(e[n])&&n-t<9;)n+=1;if(n===t||e[n]!=="."&&e[n]!==")")return-1;n+=1}return e[n]===" "?n+1:-1},ns=(e,t,n)=>{let r=0,s=t,i=!1,a=t;for(;;){for(;a<n&&e[a]===" ";)a+=1;if(e[a]===">"){r+=1,a+=e[a+1]===" "?2:1,s=a,i=!1;continue}let o=a<n?ts(e,a):-1;if(o===-1)return{contentStart:a,listIndent:i?a-s:0,quoteDepth:r};a=o,i=!0}},rs=(e,t,n,r)=>{let s=t;for(let i=0;i<r;i+=1){for(;s<n&&e[s]===" ";)s+=1;if(e[s]!==">")return-1;s+=1,e[s]===" "&&(s+=1)}return s},ss=(e,t,n,r,s)=>{let i=t+r;e.fill(E.FENCE_MARKER,i,i+s),e.fill(E.FENCE_INFO,i+s,Math.min(n+1,e.length))},is=(e,t,n,r)=>{let s=t;for(;s<n&&e[s]===" ";)s+=1;let i=0;for(;s<n&&e[s]===r.char;)s+=1,i+=1;if(i<r.length)return!1;for(;s<n;){if(e[s]!==" "&&e[s]!==" "&&e[s]!=="\r")return!1;s+=1}return!0},as=(e,t,n,r)=>{let s=r>n&&e[r-1]==="\r"?r-1:r,i=ns(e,n,s),a=e.slice(i.contentStart,s).match(Yr);if(!a)return null;let[,o,c]=a,l=o[0];return l==="`"&&c.includes("`")?null:(ss(t,n,r,i.contentStart-n,o.length),{char:l,length:o.length,listIndent:i.listIndent,quoteDepth:i.quoteDepth})},os=(e,t,n,r)=>{let s=rs(e,t,n,r.quoteDepth);if(s===-1||r.listIndent===0)return s;let i=s;for(;i<n&&e[i]===" ";)i+=1;return i===n||e[i]==="\r"&&i+1===n||i-s>=r.listIndent?s:-1},ls=(e,t)=>{let n=e.length,r=null,s=0;for(;s<n;){let i=e.indexOf(`
65
- `,s);i===-1&&(i=n);let a=r?os(e,s,i,r):-1;r&&a===-1&&(r=null),r?is(e,a,i,r)?(t.fill(E.FENCE_MARKER,s,i),r=null):t.fill(E.FENCE_BODY,s,Math.min(i+1,n)):r=as(e,t,s,i),s=i+1}return r},gn=(e,t)=>{let n=t+1;for(;n<e.length&&e[n]==="`";)n+=1;return n},cs=(e,t)=>{let n=t+1;for(;n<e.length&&(e[n]===" "||e[n]===" "||e[n]==="\r");)n+=1;return n<e.length&&e[n]===`
66
- `},us=(e,t,n)=>{let r=n;for(;;){let s=e.indexOf("`",r);if(s===-1)return-1;let i=s>r&&e[s-1]==="\\"&&t[s-1]===E.PROSE;if(t[s]===E.PROSE&&!i)return s;r=s+1}},hs=(e,t)=>{let n=e.length,r=-1,s=0,i=0;for(;i<n;){if(r<0){if(i=us(e,t,i),i===-1)break;let o=gn(e,i);r=i,s=o-i,i=o;continue}if(t[i]!==E.PROSE){t.fill(E.CODE_SPAN_OPEN,r,i),r=-1,i+=1;continue}if(e[i]===`
67
- `&&cs(e,i)){r=-1,i+=1;continue}if(e[i]!=="`"){i+=1;continue}let a=gn(e,i);a-i===s&&(t.fill(E.CODE_SPAN,r,a),r=-1),i=a}return r>=0?(t.fill(E.CODE_SPAN_OPEN,r,n),{start:r,runLength:s}):null},ps=e=>{let t=new Uint8Array(e.length),n=ls(e,t),r=hs(e,t);return{text:e,regions:t,openFence:n,openSpan:r,mathMask:null,linkUrlMask:null,htmlTagMask:null}},ot=null,Pe=null,H=e=>{if(Pe!==null&&e===ot)return Pe;let t=ps(e);return ot=e,Pe=t,t},ds=()=>{ot=null,Pe=null},fs=(e,t)=>t>=e.regions.length?e.openFence!==null||e.openSpan!==null:t<0?!1:e.regions[t]!==E.PROSE;var gs=(e,t)=>e.regions[t]===E.CODE_SPAN,lt=(e,t)=>{let n=H(e),r=t+t,s=0;for(let i=e.indexOf(r);i!==-1;i=e.indexOf(r,i))n.regions[i]===E.PROSE?(s+=1,i+=2):i+=1;return s},ct=new Uint8Array(0),ms=e=>e==="inlineLatex"||e==="blockLatex",ks=(e,t)=>t==="["&&e==="none"?"blockLatex":t==="]"&&e==="blockLatex"?"none":t==="("&&e==="none"?"inlineLatex":t===")"&&e==="inlineLatex"?"none":null,bs=(e,t)=>t?e==="blockDollar"?"none":"blockDollar":e==="blockDollar"?e:e==="inlineDollar"?"none":"inlineDollar",ws=e=>e.includes("$")||e.includes("\\(")||e.includes("\\["),xs=(e,t,n)=>{let r=e[t+1];if(e[t]==="\\"){if(r==="$")return{context:n,length:2};let s=ks(n,r);return s===null?null:{context:s,length:2}}if(e[t]==="$"&&!ms(n)){let s=r==="$";return{context:bs(n,s),length:s?2:1}}return null},ys=e=>{let{text:t,regions:n}=e,r=t.length,s=new Uint8Array(r),i="none",a=0;for(;a<r;){s[a]=i==="none"?0:1;let o=n[a]===E.PROSE?xs(t,a,i):null;if(o===null){a+=1;continue}i=o.context,o.length===2&&(s[a+1]=i==="none"?0:1),a+=o.length}return s},we=(e,t)=>t<0||t>=e.text.length?!1:(e.mathMask===null&&(e.mathMask=ws(e.text)?ys(e):ct),e.mathMask[t]===1),Ss=(e,t,n,r)=>{let{text:s,regions:i}=e,a=new Uint8Array(n-t),o=0;for(let l=n-1;l>=t;l-=1)s[l]===")"&&i[l]===E.PROSE&&(o=1),a[l-t]=o;let c=!1;for(let l=t;l<n;l+=1)c&&a[l-t]===1&&(r[l]=1),i[l]===E.PROSE&&(s[l]===")"?c=!1:s[l]==="("&&(c=l>0&&s[l-1]==="]"))},Rs=e=>{let{text:t}=e,n=t.length,r=new Uint8Array(n),s=0;for(;s<n;){let i=t.indexOf(`
68
- `,s);i===-1&&(i=n),Ss(e,s,i,r),s=i+1}return r},ut=(e,t)=>t<0||t>=e.text.length?!1:(e.linkUrlMask===null&&(e.linkUrlMask=e.text.includes("](")?Rs(e):ct),e.linkUrlMask[t]===1),Es=e=>{let{text:t,regions:n}=e,r=t.length,s=new Uint8Array(r),i=!1;for(let a=0;a<r;a+=1){if(t[a]===`
69
- `){i=!1;continue}if(s[a]=i?1:0,n[a]===E.PROSE){if(t[a]===">")i=!1;else if(t[a]==="<"){let o=t[a+1];i=o!==void 0&&(o>="a"&&o<="z"||o>="A"&&o<="Z"||o==="/")}}}return s},Sn=(e,t)=>t<0||t>=e.text.length?!1:(e.htmlTagMask===null&&(e.htmlTagMask=e.text.includes("<")?Es(e):ct),e.htmlTagMask[t]===1),B=(e,t)=>fs(H(e),t),re=(e,t)=>gs(H(e),t),vs=/^(\s*(?:[-*+]|\d+[.)]) +)>(=?\s*[$]?\d)/gm,$s=e=>!e||typeof e!="string"||!e.includes(">")?e:e.replace(vs,(t,n,r,s)=>B(e,s)?t:`${n}\\>${r}`),se=(e,{delimiter:t,markerLength:n,regex:r})=>{let s=e.lastIndexOf(t,e.length-2),i=s===-1?e.length-1:s;return e.slice(Math.max(0,i-n+1)).match(r)},Cs={delimiter:"*",markerLength:2,regex:/(\*\*)([^*]*\*?)$/},Ts={delimiter:"_",markerLength:2,regex:/(__)([^_]*?)$/},Is={delimiter:"*",markerLength:3,regex:/(\*\*\*)([^*]*?)$/},As={delimiter:"*",markerLength:1,regex:/(\*)([^*]*?)$/},Os={delimiter:"_",markerLength:1,regex:/(_)([^_]*?)$/},_s={delimiter:"~",markerLength:2,regex:/(~~)([^~]*?)$/},Ls={delimiter:"_",markerLength:2,regex:/(__)([^_]+)_$/},Ps={delimiter:"~",markerLength:2,regex:/(~~)([^~]+)~$/},he=/^[\s_~*`]*$/,Rn=/^[\s]*[-*+][\s]+$/,Ms=/[\p{L}\p{N}_]/u,Ns=/^\*{4,}$/,K=e=>{if(!e)return!1;let t=e.charCodeAt(0);return t>=48&&t<=57||t>=65&&t<=90||t>=97&&t<=122||t===95?!0:Ms.test(e)};var Bs=(e,t)=>{let n=1;for(let r=t-1;r>=0;r-=1)if(e[r]==="]")n+=1;else if(e[r]==="["&&(n-=1,n===0))return r;return-1},En=(e,t)=>{let n=1;for(let r=t+1;r<e.length;r+=1)if(e[r]==="[")n+=1;else if(e[r]==="]"&&(n-=1,n===0))return r;return-1},Ds=(e,t)=>we(H(e),t);var Be=(e,t,n)=>{let r=0;for(let c=t-1;c>=0;c-=1)if(e[c]===`
63
+ `}strong({tokens:e}){return`<strong>${this.parser.parseInline(e)}</strong>`}em({tokens:e}){return`<em>${this.parser.parseInline(e)}</em>`}codespan({text:e}){return`<code>${Z(e,!0)}</code>`}br(e){return"<br>"}del({tokens:e}){return`<del>${this.parser.parseInline(e)}</del>`}link({href:e,title:t,tokens:n}){let r=this.parser.parseInline(n),s=Xt(e);if(s===null)return r;e=s;let i='<a href="'+e+'"';return t&&(i+=' title="'+Z(t)+'"'),i+=">"+r+"</a>",i}image({href:e,title:t,text:n,tokens:r}){r&&(n=this.parser.parseInline(r,this.parser.textRenderer));let s=Xt(e);if(s===null)return Z(n);e=s;let i=`<img src="${e}" alt="${Z(n)}"`;return t&&(i+=` title="${Z(t)}"`),i+=">",i}text(e){return"tokens"in e&&e.tokens?this.parser.parseInline(e.tokens):"escaped"in e&&e.escaped?e.text:Z(e.text)}},it=class{strong({text:e}){return e}em({text:e}){return e}codespan({text:e}){return e}del({text:e}){return e}html({text:e}){return e}text({text:e}){return e}link({text:e}){return""+e}image({text:e}){return""+e}br(){return""}checkbox({raw:e}){return e}},F=class Je{options;renderer;textRenderer;constructor(t){this.options=t||ue,this.options.renderer=this.options.renderer||new Oe,this.renderer=this.options.renderer,this.renderer.options=this.options,this.renderer.parser=this,this.textRenderer=new it}static parse(t,n){return new Je(n).parse(t)}static parseInline(t,n){return new Je(n).parseInline(t)}parse(t){this.renderer.parser=this;let n="";for(let r=0;r<t.length;r++){let s=t[r];if(this.options.extensions?.renderers?.[s.type]){let a=s,o=this.options.extensions.renderers[a.type].call({parser:this},a);if(o!==!1||!["space","hr","heading","code","table","blockquote","list","html","def","paragraph","text"].includes(a.type)){n+=o||"";continue}}let i=s;switch(i.type){case"space":{n+=this.renderer.space(i);break}case"hr":{n+=this.renderer.hr(i);break}case"heading":{n+=this.renderer.heading(i);break}case"code":{n+=this.renderer.code(i);break}case"table":{n+=this.renderer.table(i);break}case"blockquote":{n+=this.renderer.blockquote(i);break}case"list":{n+=this.renderer.list(i);break}case"checkbox":{n+=this.renderer.checkbox(i);break}case"html":{n+=this.renderer.html(i);break}case"def":{n+=this.renderer.def(i);break}case"paragraph":{n+=this.renderer.paragraph(i);break}case"text":{n+=this.renderer.text(i);break}default:{let a='Token with "'+i.type+'" type was not found.';if(this.options.silent)return console.error(a),"";throw new Error(a)}}}return n}parseInline(t,n=this.renderer){this.renderer.parser=this;let r="";for(let s=0;s<t.length;s++){let i=t[s];if(this.options.extensions?.renderers?.[i.type]){let o=this.options.extensions.renderers[i.type].call({parser:this},i);if(o!==!1||!["escape","html","link","image","strong","em","codespan","br","del","text"].includes(i.type)){r+=o||"";continue}}let a=i;switch(a.type){case"escape":{r+=n.text(a);break}case"html":{r+=n.html(a);break}case"link":{r+=n.link(a);break}case"image":{r+=n.image(a);break}case"checkbox":{r+=n.checkbox(a);break}case"strong":{r+=n.strong(a);break}case"em":{r+=n.em(a);break}case"codespan":{r+=n.codespan(a);break}case"br":{r+=n.br(a);break}case"del":{r+=n.del(a);break}case"text":{r+=n.text(a);break}default:{let o='Token with "'+a.type+'" type was not found.';if(this.options.silent)return console.error(o),"";throw new Error(o)}}}return r}},Re=class{options;block;constructor(e){this.options=e||ue}static passThroughHooks=new Set(["preprocess","postprocess","processAllTokens","emStrongMask"]);static passThroughHooksRespectAsync=new Set(["preprocess","postprocess","processAllTokens"]);preprocess(e){return e}postprocess(e){return e}processAllTokens(e){return e}emStrongMask(e){return e}provideLexer(e=this.block){return e?q.lex:q.lexInline}provideParser(e=this.block){return e?F.parse:F.parseInline}},ve=class{defaults=Qe();options=this.setOptions;parse=this.parseMarkdown(!0);parseInline=this.parseMarkdown(!1);Parser=F;Renderer=Oe;TextRenderer=it;Lexer=q;Tokenizer=Ae;Hooks=Re;constructor(...e){this.use(...e)}walkTokens(e,t){let n=[];for(let r of e)switch(n=n.concat(t.call(this,r)),r.type){case"table":{let s=r;for(let i of s.header)n=n.concat(this.walkTokens(i.tokens,t));for(let i of s.rows)for(let a of i)n=n.concat(this.walkTokens(a.tokens,t));break}case"list":{let s=r;n=n.concat(this.walkTokens(s.items,t));break}default:{let s=r;this.defaults.extensions?.childTokens?.[s.type]?this.defaults.extensions.childTokens[s.type].forEach(i=>{let a=s[i].flat(1/0);n=n.concat(this.walkTokens(a,t))}):s.tokens&&(n=n.concat(this.walkTokens(s.tokens,t)))}}return n}use(...e){let t=this.defaults.extensions||{renderers:{},childTokens:{}};return e.forEach(n=>{let r={...n};if(r.async=this.defaults.async||r.async||!1,n.extensions&&(n.extensions.forEach(s=>{if(!s.name)throw new Error("extension name required");if("renderer"in s){let i=t.renderers[s.name];i?t.renderers[s.name]=function(...a){let o=s.renderer.apply(this,a);return o===!1&&(o=i.apply(this,a)),o}:t.renderers[s.name]=s.renderer}if("tokenizer"in s){if(!s.level||s.level!=="block"&&s.level!=="inline")throw new Error("extension level must be 'block' or 'inline'");let i=t[s.level];i?i.unshift(s.tokenizer):t[s.level]=[s.tokenizer],s.start&&(s.level==="block"?t.startBlock?t.startBlock.push(s.start):t.startBlock=[s.start]:s.level==="inline"&&(t.startInline?t.startInline.push(s.start):t.startInline=[s.start]))}"childTokens"in s&&s.childTokens&&(t.childTokens[s.name]=s.childTokens)}),r.extensions=t),n.renderer){let s=this.defaults.renderer||new Oe(this.defaults);for(let i in n.renderer){if(!(i in s))throw new Error(`renderer '${i}' does not exist`);if(["options","parser"].includes(i))continue;let a=i,o=n.renderer[a],c=s[a];s[a]=(...l)=>{let p=o.apply(s,l);return p===!1&&(p=c.apply(s,l)),p||""}}r.renderer=s}if(n.tokenizer){let s=this.defaults.tokenizer||new Ae(this.defaults);for(let i in n.tokenizer){if(!(i in s))throw new Error(`tokenizer '${i}' does not exist`);if(["options","rules","lexer"].includes(i))continue;let a=i,o=n.tokenizer[a],c=s[a];s[a]=(...l)=>{let p=o.apply(s,l);return p===!1&&(p=c.apply(s,l)),p}}r.tokenizer=s}if(n.hooks){let s=this.defaults.hooks||new Re;for(let i in n.hooks){if(!(i in s))throw new Error(`hook '${i}' does not exist`);if(["options","block"].includes(i))continue;let a=i,o=n.hooks[a],c=s[a];Re.passThroughHooks.has(i)?s[a]=l=>{if(this.defaults.async&&Re.passThroughHooksRespectAsync.has(i))return(async()=>{let u=await o.call(s,l);return c.call(s,u)})();let p=o.call(s,l);return c.call(s,p)}:s[a]=(...l)=>{if(this.defaults.async)return(async()=>{let u=await o.apply(s,l);return u===!1&&(u=await c.apply(s,l)),u})();let p=o.apply(s,l);return p===!1&&(p=c.apply(s,l)),p}}r.hooks=s}if(n.walkTokens){let s=this.defaults.walkTokens,i=n.walkTokens;r.walkTokens=function(a){let o=[];return o.push(i.call(this,a)),s&&(o=o.concat(s.call(this,a))),o}}this.defaults={...this.defaults,...r}}),this}setOptions(e){return this.defaults={...this.defaults,...e},this}lexer(e,t){return q.lex(e,t??this.defaults)}parser(e,t){return F.parse(e,t??this.defaults)}parseMarkdown(e){return(t,n)=>{let r={...n},s={...this.defaults,...r},i=this.onError(!!s.silent,!!s.async);if(this.defaults.async===!0&&r.async===!1)return i(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 t>"u"||t===null)return i(new Error("marked(): input parameter is undefined or null"));if(typeof t!="string")return i(new Error("marked(): input parameter is of type "+Object.prototype.toString.call(t)+", string expected"));if(s.hooks&&(s.hooks.options=s,s.hooks.block=e),s.async)return(async()=>{let a=s.hooks?await s.hooks.preprocess(t):t,o=await(s.hooks?await s.hooks.provideLexer(e):e?q.lex:q.lexInline)(a,s),c=s.hooks?await s.hooks.processAllTokens(o):o;s.walkTokens&&await Promise.all(this.walkTokens(c,s.walkTokens));let l=await(s.hooks?await s.hooks.provideParser(e):e?F.parse:F.parseInline)(c,s);return s.hooks?await s.hooks.postprocess(l):l})().catch(i);try{s.hooks&&(t=s.hooks.preprocess(t));let a=(s.hooks?s.hooks.provideLexer(e):e?q.lex:q.lexInline)(t,s);s.hooks&&(a=s.hooks.processAllTokens(a)),s.walkTokens&&this.walkTokens(a,s.walkTokens);let o=(s.hooks?s.hooks.provideParser(e):e?F.parse:F.parseInline)(a,s);return s.hooks&&(o=s.hooks.postprocess(o)),o}catch(a){return i(a)}}}onError(e,t){return n=>{if(n.message+=`
64
+ Please report this to https://github.com/markedjs/marked.`,e){let r="<p>An error occurred:</p><pre>"+Z(n.message+"",!0)+"</pre>";return t?Promise.resolve(r):r}if(t)return Promise.reject(n);throw n}}},ce=new ve;function y(e,t){return ce.parse(e,t)}y.options=y.setOptions=function(e){return ce.setOptions(e),y.defaults=ce.defaults,nn(y.defaults),y};y.getDefaults=Qe;y.defaults=ue;y.use=function(...e){return ce.use(...e),y.defaults=ce.defaults,nn(y.defaults),y};y.walkTokens=function(e,t){return ce.walkTokens(e,t)};y.parseInline=ce.parseInline;y.Parser=F;y.parser=F.parse;y.Renderer=Oe;y.TextRenderer=it;y.Lexer=q;y.lexer=q.lex;y.Tokenizer=Ae;y.Hooks=Re;y.parse=y;var Ia=y.options,Aa=y.setOptions,Oa=y.use,_a=y.walkTokens,La=y.parseInline;var Pa=F.parse,Ma=q.lex;var Vr=Object.defineProperty,Jr=Object.defineProperties,Qr=Object.getOwnPropertyDescriptors,dn=Object.getOwnPropertySymbols,Xr=Object.prototype.hasOwnProperty,Yr=Object.prototype.propertyIsEnumerable,fn=(e,t,n)=>t in e?Vr(e,t,{enumerable:!0,configurable:!0,writable:!0,value:n}):e[t]=n,xn=(e,t)=>{for(var n in t||(t={}))Xr.call(t,n)&&fn(e,n,t[n]);if(dn)for(var n of dn(t))Yr.call(t,n)&&fn(e,n,t[n]);return e},yn=(e,t)=>Jr(e,Qr(t)),E={PROSE:0,FENCE_MARKER:1,FENCE_INFO:2,FENCE_BODY:3,CODE_SPAN:4,CODE_SPAN_OPEN:5},es=/^(`{3,}|~{3,})(.*)$/,ts=e=>e!==void 0&&e>="0"&&e<="9",ns=(e,t)=>{let n=t;if(e[n]==="-"||e[n]==="*"||e[n]==="+")n+=1;else{for(;ts(e[n])&&n-t<9;)n+=1;if(n===t||e[n]!=="."&&e[n]!==")")return-1;n+=1}return e[n]===" "?n+1:-1},rs=(e,t,n)=>{let r=0,s=t,i=!1,a=t;for(;;){for(;a<n&&e[a]===" ";)a+=1;if(e[a]===">"){r+=1,a+=e[a+1]===" "?2:1,s=a,i=!1;continue}let o=a<n?ns(e,a):-1;if(o===-1)return{contentStart:a,listIndent:i?a-s:0,quoteDepth:r};a=o,i=!0}},ss=(e,t,n,r)=>{let s=t;for(let i=0;i<r;i+=1){for(;s<n&&e[s]===" ";)s+=1;if(e[s]!==">")return-1;s+=1,e[s]===" "&&(s+=1)}return s},is=(e,t,n,r,s)=>{let i=t+r;e.fill(E.FENCE_MARKER,i,i+s),e.fill(E.FENCE_INFO,i+s,Math.min(n+1,e.length))},as=(e,t,n,r)=>{let s=t;for(;s<n&&e[s]===" ";)s+=1;let i=0;for(;s<n&&e[s]===r.char;)s+=1,i+=1;if(i<r.length)return!1;for(;s<n;){if(e[s]!==" "&&e[s]!==" "&&e[s]!=="\r")return!1;s+=1}return!0},os=(e,t,n,r)=>{let s=r>n&&e[r-1]==="\r"?r-1:r,i=rs(e,n,s),a=e.slice(i.contentStart,s).match(es);if(!a)return null;let[,o,c]=a,l=o[0];return l==="`"&&c.includes("`")?null:(is(t,n,r,i.contentStart-n,o.length),{char:l,length:o.length,listIndent:i.listIndent,quoteDepth:i.quoteDepth})},ls=(e,t,n,r)=>{let s=ss(e,t,n,r.quoteDepth);if(s===-1||r.listIndent===0)return s;let i=s;for(;i<n&&e[i]===" ";)i+=1;return i===n||e[i]==="\r"&&i+1===n||i-s>=r.listIndent?s:-1},cs=(e,t)=>{let n=e.length,r=null,s=0;for(;s<n;){let i=e.indexOf(`
65
+ `,s);i===-1&&(i=n);let a=r?ls(e,s,i,r):-1;r&&a===-1&&(r=null),r?as(e,a,i,r)?(t.fill(E.FENCE_MARKER,s,i),r=null):t.fill(E.FENCE_BODY,s,Math.min(i+1,n)):r=os(e,t,s,i),s=i+1}return r},gn=(e,t)=>{let n=t+1;for(;n<e.length&&e[n]==="`";)n+=1;return n},us=(e,t)=>{let n=t+1;for(;n<e.length&&(e[n]===" "||e[n]===" "||e[n]==="\r");)n+=1;return n<e.length&&e[n]===`
66
+ `},ps=(e,t,n)=>{let r=n;for(;;){let s=e.indexOf("`",r);if(s===-1)return-1;let i=s>r&&e[s-1]==="\\"&&t[s-1]===E.PROSE;if(t[s]===E.PROSE&&!i)return s;r=s+1}},hs=(e,t)=>{let n=e.length,r=-1,s=0,i=0;for(;i<n;){if(r<0){if(i=ps(e,t,i),i===-1)break;let o=gn(e,i);r=i,s=o-i,i=o;continue}if(t[i]!==E.PROSE){t.fill(E.CODE_SPAN_OPEN,r,i),r=-1,i+=1;continue}if(e[i]===`
67
+ `&&us(e,i)){r=-1,i+=1;continue}if(e[i]!=="`"){i+=1;continue}let a=gn(e,i);a-i===s&&(t.fill(E.CODE_SPAN,r,a),r=-1),i=a}return r>=0?(t.fill(E.CODE_SPAN_OPEN,r,n),{start:r,runLength:s}):null},ds=e=>{let t=new Uint8Array(e.length),n=cs(e,t),r=hs(e,t);return{text:e,regions:t,openFence:n,openSpan:r,mathMask:null,linkUrlMask:null,htmlTagMask:null}},ot=null,Pe=null,H=e=>{if(Pe!==null&&e===ot)return Pe;let t=ds(e);return ot=e,Pe=t,t},fs=()=>{ot=null,Pe=null},gs=(e,t)=>t>=e.regions.length?e.openFence!==null||e.openSpan!==null:t<0?!1:e.regions[t]!==E.PROSE;var ms=(e,t)=>e.regions[t]===E.CODE_SPAN,lt=(e,t)=>{let n=H(e),r=t+t,s=0;for(let i=e.indexOf(r);i!==-1;i=e.indexOf(r,i))n.regions[i]===E.PROSE?(s+=1,i+=2):i+=1;return s},ct=new Uint8Array(0),ks=e=>e==="inlineLatex"||e==="blockLatex",bs=(e,t)=>t==="["&&e==="none"?"blockLatex":t==="]"&&e==="blockLatex"?"none":t==="("&&e==="none"?"inlineLatex":t===")"&&e==="inlineLatex"?"none":null,ws=(e,t)=>t?e==="blockDollar"?"none":"blockDollar":e==="blockDollar"?e:e==="inlineDollar"?"none":"inlineDollar",xs=e=>e.includes("$")||e.includes("\\(")||e.includes("\\["),ys=(e,t,n)=>{let r=e[t+1];if(e[t]==="\\"){if(r==="$")return{context:n,length:2};let s=bs(n,r);return s===null?null:{context:s,length:2}}if(e[t]==="$"&&!ks(n)){let s=r==="$";return{context:ws(n,s),length:s?2:1}}return null},Ss=e=>{let{text:t,regions:n}=e,r=t.length,s=new Uint8Array(r),i="none",a=0;for(;a<r;){s[a]=i==="none"?0:1;let o=n[a]===E.PROSE?ys(t,a,i):null;if(o===null){a+=1;continue}i=o.context,o.length===2&&(s[a+1]=i==="none"?0:1),a+=o.length}return s},we=(e,t)=>t<0||t>=e.text.length?!1:(e.mathMask===null&&(e.mathMask=xs(e.text)?Ss(e):ct),e.mathMask[t]===1),Rs=(e,t,n,r)=>{let{text:s,regions:i}=e,a=new Uint8Array(n-t),o=0;for(let l=n-1;l>=t;l-=1)s[l]===")"&&i[l]===E.PROSE&&(o=1),a[l-t]=o;let c=!1;for(let l=t;l<n;l+=1)c&&a[l-t]===1&&(r[l]=1),i[l]===E.PROSE&&(s[l]===")"?c=!1:s[l]==="("&&(c=l>0&&s[l-1]==="]"))},Es=e=>{let{text:t}=e,n=t.length,r=new Uint8Array(n),s=0;for(;s<n;){let i=t.indexOf(`
68
+ `,s);i===-1&&(i=n),Rs(e,s,i,r),s=i+1}return r},ut=(e,t)=>t<0||t>=e.text.length?!1:(e.linkUrlMask===null&&(e.linkUrlMask=e.text.includes("](")?Es(e):ct),e.linkUrlMask[t]===1),vs=e=>{let{text:t,regions:n}=e,r=t.length,s=new Uint8Array(r),i=!1;for(let a=0;a<r;a+=1){if(t[a]===`
69
+ `){i=!1;continue}if(s[a]=i?1:0,n[a]===E.PROSE){if(t[a]===">")i=!1;else if(t[a]==="<"){let o=t[a+1];i=o!==void 0&&(o>="a"&&o<="z"||o>="A"&&o<="Z"||o==="/")}}}return s},Sn=(e,t)=>t<0||t>=e.text.length?!1:(e.htmlTagMask===null&&(e.htmlTagMask=e.text.includes("<")?vs(e):ct),e.htmlTagMask[t]===1),B=(e,t)=>gs(H(e),t),re=(e,t)=>ms(H(e),t),$s=/^(\s*(?:[-*+]|\d+[.)]) +)>(=?\s*[$]?\d)/gm,Cs=e=>!e||typeof e!="string"||!e.includes(">")?e:e.replace($s,(t,n,r,s)=>B(e,s)?t:`${n}\\>${r}`),se=(e,{delimiter:t,markerLength:n,regex:r})=>{let s=e.lastIndexOf(t,e.length-2),i=s===-1?e.length-1:s;return e.slice(Math.max(0,i-n+1)).match(r)},Ts={delimiter:"*",markerLength:2,regex:/(\*\*)([^*]*\*?)$/},Is={delimiter:"_",markerLength:2,regex:/(__)([^_]*?)$/},As={delimiter:"*",markerLength:3,regex:/(\*\*\*)([^*]*?)$/},Os={delimiter:"*",markerLength:1,regex:/(\*)([^*]*?)$/},_s={delimiter:"_",markerLength:1,regex:/(_)([^_]*?)$/},Ls={delimiter:"~",markerLength:2,regex:/(~~)([^~]*?)$/},Ps={delimiter:"_",markerLength:2,regex:/(__)([^_]+)_$/},Ms={delimiter:"~",markerLength:2,regex:/(~~)([^~]+)~$/},pe=/^[\s_~*`]*$/,Rn=/^[\s]*[-*+][\s]+$/,Ns=/[\p{L}\p{N}_]/u,Bs=/^\*{4,}$/,K=e=>{if(!e)return!1;let t=e.charCodeAt(0);return t>=48&&t<=57||t>=65&&t<=90||t>=97&&t<=122||t===95?!0:Ns.test(e)};var Ds=(e,t)=>{let n=1;for(let r=t-1;r>=0;r-=1)if(e[r]==="]")n+=1;else if(e[r]==="["&&(n-=1,n===0))return r;return-1},En=(e,t)=>{let n=1;for(let r=t+1;r<e.length;r+=1)if(e[r]==="[")n+=1;else if(e[r]==="]"&&(n-=1,n===0))return r;return-1},zs=(e,t)=>we(H(e),t);var Be=(e,t,n)=>{let r=0;for(let c=t-1;c>=0;c-=1)if(e[c]===`
70
70
  `){r=c+1;break}let s=e.length;for(let c=t;c<e.length;c+=1)if(e[c]===`
71
- `){s=c;break}let i=e.substring(r,s),a=0,o=!1;for(let c of i)if(c===n)a+=1;else if(c!==" "&&c!==" "){o=!0;break}return a>=3&&!o},zs=(e,t,n,r)=>n==="\\"||we(e,t)?!0:n!=="*"&&r==="*"?(t<e.text.length-2?e.text[t+2]:"")!=="*":n==="*"||(!n||n===" "||n===" "||n===`
71
+ `){s=c;break}let i=e.substring(r,s),a=0,o=!1;for(let c of i)if(c===n)a+=1;else if(c!==" "&&c!==" "){o=!0;break}return a>=3&&!o},Us=(e,t,n,r)=>n==="\\"||we(e,t)?!0:n!=="*"&&r==="*"?(t<e.text.length-2?e.text[t+2]:"")!=="*":n==="*"||(!n||n===" "||n===" "||n===`
72
72
  `)&&(!r||r===" "||r===" "||r===`
73
73
  `),Me=e=>e===" "||e===" "||e===`
74
- `,Us=(e,t)=>!!(e&&t&&K(e)&&K(t)),Hs=(e,t,n,r)=>{let s=Us(e,t),i=!!t&&!Me(t),a=!!e&&!Me(e);return s&&n%2===0&&!r?{count:!1}:a&&n%2===1||i?{count:!0,inWordAsteriskChain:s}:{count:!1}},vn=e=>{let t=H(e),n=0,r=!1,s=e.length;for(let i=0;i<s;i+=1){if(e[i]!=="*"||t.regions[i]!==E.PROSE){K(e[i])||(r=!1);continue}let a=i>0?e[i-1]:"",o=i<s-1?e[i+1]:"";if(zs(t,i,a,o))continue;let c=Hs(a,o,n,r);c.count&&(n+=1,r=c.inWordAsteriskChain)}return n},qs=(e,t,n,r)=>!!(n==="\\"||we(e,t)||ut(e,t)||Sn(e,t)||n==="_"||r==="_"||n&&r&&K(n)&&K(r)),js=e=>{let t=H(e),n=0,r=e.length;for(let s=0;s<r;s+=1){if(e[s]!=="_"||t.regions[s]!==E.PROSE)continue;let i=s>0?e[s-1]:"",a=s<r-1?e[s+1]:"";qs(t,s,i,a)||(n+=1)}return n},Fs=e=>{let t=H(e),n=0,r=0;for(let s=0;s<e.length;s+=1)e[s]==="*"&&t.regions[s]===E.PROSE?r+=1:(r>=3&&(n+=Math.floor(r/3)),r=0);return r>=3&&(n+=Math.floor(r/3)),n},ht=e=>lt(e,"*"),mn=e=>e===""||e===" "||e===" "||e===`
75
- `,Ks=(e,t,n,r,s)=>{if(!(mn(n)&&mn(r)))return!1;if(t>s.lineEnd){let i=e.indexOf(`
76
- `,t);s.lineEnd=i===-1?e.length:i,s.result=Be(e,t,"_")}return s.result},Ws=(e,t,n,r)=>{let s=e.text,i=t,a=!1;i>0&&s[i-1]==="\\"&&(i+=1,a=!0);let o=n-i;if(o<2)return!1;let c=i>0?s[i-1]:"",l=a?"\\":c,h=n<s.length?s[n]:"";return K(l)&&K(h)||Ks(s,i,l,h,r)||we(e,i)||ut(e,i)||Sn(e,i)?!1:Math.floor(o/2)%2===1},kn=e=>{let t=H(e),n=e.length,r={lineEnd:-1,result:!1},s=!1,i=0;for(;i<n;){if(e[i]!=="_"||t.regions[i]!==E.PROSE){i+=1;continue}let a=i,o=i+1;for(;o<n&&e[o]==="_"&&t.regions[o]===E.PROSE;)o+=1;i=o,Ws(t,a,o,r)&&(s=!s)}return s},Gs=(e,t,n)=>{if(!t||he.test(t))return!0;let r=e.substring(0,n).lastIndexOf(`
74
+ `,Hs=(e,t)=>!!(e&&t&&K(e)&&K(t)),js=(e,t,n,r)=>{let s=Hs(e,t),i=!!t&&!Me(t),a=!!e&&!Me(e);return s&&n%2===0&&!r?{count:!1}:a&&n%2===1||i?{count:!0,inWordAsteriskChain:s}:{count:!1}},vn=e=>{let t=H(e),n=0,r=!1,s=e.length;for(let i=0;i<s;i+=1){if(e[i]!=="*"||t.regions[i]!==E.PROSE){K(e[i])||(r=!1);continue}let a=i>0?e[i-1]:"",o=i<s-1?e[i+1]:"";if(Us(t,i,a,o))continue;let c=js(a,o,n,r);c.count&&(n+=1,r=c.inWordAsteriskChain)}return n},qs=(e,t,n,r)=>!!(n==="\\"||we(e,t)||ut(e,t)||Sn(e,t)||n==="_"||r==="_"||n&&r&&K(n)&&K(r)),Fs=e=>{let t=H(e),n=0,r=e.length;for(let s=0;s<r;s+=1){if(e[s]!=="_"||t.regions[s]!==E.PROSE)continue;let i=s>0?e[s-1]:"",a=s<r-1?e[s+1]:"";qs(t,s,i,a)||(n+=1)}return n},Ks=e=>{let t=H(e),n=0,r=0;for(let s=0;s<e.length;s+=1)e[s]==="*"&&t.regions[s]===E.PROSE?r+=1:(r>=3&&(n+=Math.floor(r/3)),r=0);return r>=3&&(n+=Math.floor(r/3)),n},pt=e=>lt(e,"*"),mn=e=>e===""||e===" "||e===" "||e===`
75
+ `,Ws=(e,t,n,r,s)=>{if(!(mn(n)&&mn(r)))return!1;if(t>s.lineEnd){let i=e.indexOf(`
76
+ `,t);s.lineEnd=i===-1?e.length:i,s.result=Be(e,t,"_")}return s.result},Gs=(e,t,n,r)=>{let s=e.text,i=t,a=!1;i>0&&s[i-1]==="\\"&&(i+=1,a=!0);let o=n-i;if(o<2)return!1;let c=i>0?s[i-1]:"",l=a?"\\":c,p=n<s.length?s[n]:"";return K(l)&&K(p)||Ws(s,i,l,p,r)||we(e,i)||ut(e,i)||Sn(e,i)?!1:Math.floor(o/2)%2===1},kn=e=>{let t=H(e),n=e.length,r={lineEnd:-1,result:!1},s=!1,i=0;for(;i<n;){if(e[i]!=="_"||t.regions[i]!==E.PROSE){i+=1;continue}let a=i,o=i+1;for(;o<n&&e[o]==="_"&&t.regions[o]===E.PROSE;)o+=1;i=o,Gs(t,a,o,r)&&(s=!s)}return s},Zs=(e,t,n)=>{if(!t||pe.test(t))return!0;let r=e.substring(0,n).lastIndexOf(`
77
77
  `),s=r===-1?0:r+1,i=e.substring(s,n);return Rn.test(i)&&t.includes(`
78
- `)?!0:Be(e,n,"*")},Zs=e=>{let t=se(e,Cs);if(!t)return e;let n=t[2],r=e.lastIndexOf(t[1]);return B(e,r)||re(e,r)||Gs(e,n,r)?e:ht(e)%2===1?n.endsWith("*")?`${e}*`:`${e}**`:e},Vs=(e,t,n)=>{if(!t||he.test(t))return!0;let r=e.substring(0,n).lastIndexOf(`
78
+ `)?!0:Be(e,n,"*")},Vs=e=>{let t=se(e,Ts);if(!t)return e;let n=t[2],r=e.lastIndexOf(t[1]);return B(e,r)||re(e,r)||Zs(e,n,r)?e:pt(e)%2===1?n.endsWith("*")?`${e}*`:`${e}**`:e},Js=(e,t,n)=>{if(!t||pe.test(t))return!0;let r=e.substring(0,n).lastIndexOf(`
79
79
  `),s=r===-1?0:r+1,i=e.substring(s,n);return Rn.test(i)&&t.includes(`
80
- `)?!0:Be(e,n,"_")},Js=e=>{let t=se(e,Ts);if(!t){let s=se(e,Ls);if(s){let i=e.lastIndexOf(s[1]);if(!(B(e,i)||re(e,i))&&kn(e))return`${e}_`}return e}let n=t[2],r=e.lastIndexOf(t[1]);return B(e,r)||re(e,r)||Vs(e,n,r)?e:kn(e)?`${e}__`:e},Qs=(e,t)=>{let{text:n}=e;return n[t]==="*"&&e.regions[t]===E.PROSE&&n[t-1]!=="*"&&n[t+1]!=="*"&&n[t-1]!=="\\"&&!we(e,t)},Xs=e=>{let t=H(e);for(let n=e.indexOf("*");n!==-1;n=e.indexOf("*",n+1)){if(!Qs(t,n))continue;let r=n>0?e[n-1]:"",s=n<e.length-1?e[n+1]:"",i=!r||Me(r),a=!s||Me(s);if(!(i&&a)&&!(r&&s&&K(r)&&K(s))&&!a)return n}return-1},Ys=e=>{if(!se(e,As))return e;let t=Xs(e);if(t===-1||B(e,t)||re(e,t))return e;let n=e.substring(t+1);return!n||he.test(n)?e:vn(e)%2===1?`${e}*`:e},$n=e=>{let t=H(e);for(let n=e.indexOf("_");n!==-1;n=e.indexOf("_",n+1))if(t.regions[n]===E.PROSE&&e[n-1]!=="_"&&e[n+1]!=="_"&&e[n-1]!=="\\"&&!we(t,n)&&!ut(t,n)){let r=n>0?e[n-1]:"",s=n<e.length-1?e[n+1]:"";if(r&&s&&K(r)&&K(s))continue;return n}return-1},ei=e=>{let t=e.length;for(;t>0&&e[t-1]===`
81
- `;)t-=1;if(t<e.length){let n=e.slice(0,t),r=e.slice(t);return`${n}_${r}`}return`${e}_`},ti=e=>{if(!e.endsWith("**"))return null;let t=e.slice(0,-2);if(ht(t)%2!==1)return null;let n=t.indexOf("**"),r=$n(t);return n!==-1&&r!==-1&&n<r?`${t}_**`:null},ni=e=>{if(!se(e,Os))return e;let t=$n(e);if(t===-1)return e;let n=e.substring(t+1);if(!n||he.test(n)||B(e,t)||re(e,t))return e;if(js(e)%2===1){let r=ti(e);return r!==null?r:ei(e)}return e},ri=e=>{let t=ht(e),n=vn(e);return t%2===0&&n%2===0},si=(e,t,n)=>!t||he.test(t)||B(e,n)||re(e,n)?!0:Be(e,n,"*"),ii=e=>{if(Ns.test(e))return e;let t=se(e,Is);if(!t)return e;let n=t[2],r=e.lastIndexOf(t[1]);return si(e,n,r)?e:Fs(e)%2===1?ri(e)?e:`${e}***`:e},ai=/<[a-zA-Z/][^>]*$/,oi=/[a-zA-Z/]/,li=e=>e.includes("$")||e.includes("\\(")||e.includes("\\["),ci=(e,t)=>{let n=e[t+1];return n!==void 0&&oi.test(n)},ui=e=>{let t=e.match(ai);if(!t||t.index===void 0)return e;let n=li(e);for(let r=t.index;r<e.length;r+=1)if(!(e[r]!=="<"||!ci(e,r))&&!B(e,r)&&!(n&&Ds(e,r)))return e.substring(0,r).trimEnd();return e},hi=e=>{let t=H(e);if(t.openFence)return e;let n=t.openSpan;if(!n)return e;let r=e.slice(n.start+n.runLength);if(!r||he.test(r))return e;let s=0,i=e.length-1;for(;i>=0&&e[i]==="`";)s+=1,i-=1;return s>=n.runLength?e:e+"`".repeat(n.runLength-s)},pi=e=>lt(e,"$"),di=e=>{let t=H(e),n=0;for(let r=0;r<e.length;r+=1){if(e[r]==="\\"){r+=1;continue}t.regions[r]===E.PROSE&&e[r]==="$"&&(r+1<e.length&&e[r+1]==="$"?r+=1:n+=1)}return n},fi=e=>{if(e.endsWith("$")&&!e.endsWith("$$"))return`${e}$`;let t=e.indexOf("$$");return t!==-1&&e.indexOf(`
80
+ `)?!0:Be(e,n,"_")},Qs=e=>{let t=se(e,Is);if(!t){let s=se(e,Ps);if(s){let i=e.lastIndexOf(s[1]);if(!(B(e,i)||re(e,i))&&kn(e))return`${e}_`}return e}let n=t[2],r=e.lastIndexOf(t[1]);return B(e,r)||re(e,r)||Js(e,n,r)?e:kn(e)?`${e}__`:e},Xs=(e,t)=>{let{text:n}=e;return n[t]==="*"&&e.regions[t]===E.PROSE&&n[t-1]!=="*"&&n[t+1]!=="*"&&n[t-1]!=="\\"&&!we(e,t)},Ys=e=>{let t=H(e);for(let n=e.indexOf("*");n!==-1;n=e.indexOf("*",n+1)){if(!Xs(t,n))continue;let r=n>0?e[n-1]:"",s=n<e.length-1?e[n+1]:"",i=!r||Me(r),a=!s||Me(s);if(!(i&&a)&&!(r&&s&&K(r)&&K(s))&&!a)return n}return-1},ei=e=>{if(!se(e,Os))return e;let t=Ys(e);if(t===-1||B(e,t)||re(e,t))return e;let n=e.substring(t+1);return!n||pe.test(n)?e:vn(e)%2===1?`${e}*`:e},$n=e=>{let t=H(e);for(let n=e.indexOf("_");n!==-1;n=e.indexOf("_",n+1))if(t.regions[n]===E.PROSE&&e[n-1]!=="_"&&e[n+1]!=="_"&&e[n-1]!=="\\"&&!we(t,n)&&!ut(t,n)){let r=n>0?e[n-1]:"",s=n<e.length-1?e[n+1]:"";if(r&&s&&K(r)&&K(s))continue;return n}return-1},ti=e=>{let t=e.length;for(;t>0&&e[t-1]===`
81
+ `;)t-=1;if(t<e.length){let n=e.slice(0,t),r=e.slice(t);return`${n}_${r}`}return`${e}_`},ni=e=>{if(!e.endsWith("**"))return null;let t=e.slice(0,-2);if(pt(t)%2!==1)return null;let n=t.indexOf("**"),r=$n(t);return n!==-1&&r!==-1&&n<r?`${t}_**`:null},ri=e=>{if(!se(e,_s))return e;let t=$n(e);if(t===-1)return e;let n=e.substring(t+1);if(!n||pe.test(n)||B(e,t)||re(e,t))return e;if(Fs(e)%2===1){let r=ni(e);return r!==null?r:ti(e)}return e},si=e=>{let t=pt(e),n=vn(e);return t%2===0&&n%2===0},ii=(e,t,n)=>!t||pe.test(t)||B(e,n)||re(e,n)?!0:Be(e,n,"*"),ai=e=>{if(Bs.test(e))return e;let t=se(e,As);if(!t)return e;let n=t[2],r=e.lastIndexOf(t[1]);return ii(e,n,r)?e:Ks(e)%2===1?si(e)?e:`${e}***`:e},oi=/<[a-zA-Z/][^>]*$/,li=/[a-zA-Z/]/,ci=e=>e.includes("$")||e.includes("\\(")||e.includes("\\["),ui=(e,t)=>{let n=e[t+1];return n!==void 0&&li.test(n)},pi=e=>{let t=e.match(oi);if(!t||t.index===void 0)return e;let n=ci(e);for(let r=t.index;r<e.length;r+=1)if(!(e[r]!=="<"||!ui(e,r))&&!B(e,r)&&!(n&&zs(e,r)))return e.substring(0,r).trimEnd();return e},hi=e=>{let t=H(e);if(t.openFence)return e;let n=t.openSpan;if(!n)return e;let r=e.slice(n.start+n.runLength);if(!r||pe.test(r))return e;let s=0,i=e.length-1;for(;i>=0&&e[i]==="`";)s+=1,i-=1;return s>=n.runLength?e:e+"`".repeat(n.runLength-s)},di=e=>lt(e,"$"),fi=e=>{let t=H(e),n=0;for(let r=0;r<e.length;r+=1){if(e[r]==="\\"){r+=1;continue}t.regions[r]===E.PROSE&&e[r]==="$"&&(r+1<e.length&&e[r+1]==="$"?r+=1:n+=1)}return n},gi=e=>{if(e.endsWith("$")&&!e.endsWith("$$"))return`${e}$`;let t=e.indexOf("$$");return t!==-1&&e.indexOf(`
82
82
  `,t)!==-1&&!e.endsWith(`
83
83
  `)?`${e}
84
- $$`:`${e}$$`},gi=e=>pi(e)%2===0?e:fi(e),mi=e=>di(e)%2===1?`${e}$`:e,Ne="streamdown:incomplete-image",ki=(e,t,n)=>{if(e.substring(t+2).includes(")"))return null;let r=Bs(e,t);if(r===-1||B(e,r))return null;let s=r>0&&e[r-1]==="!",i=s?r-1:r,a=e.substring(0,i),o=e.substring(r+1,t);return s?`${a}![${o}](${Ne})`:n==="text-only"?`${a}${o}`:`${a}[${o}](streamdown:incomplete-link)`},bn=(e,t)=>{for(let n=0;n<t;n++)if(e[n]==="["&&!B(e,n)){if(n>0&&e[n-1]==="!")continue;let r=En(e,n);if(r===-1)return n;if(r+1<e.length&&e[r+1]==="("){let s=e.indexOf(")",r+2);s!==-1&&(n=s)}}return t},bi=(e,t,n)=>{let r=t>0&&e[t-1]==="!",s=r?t-1:t;if(!e.substring(t+1).includes("]")){let i=e.substring(0,s);if(r){let a=e.substring(t+1);return`${i}![${a}](${Ne})`}if(n==="text-only"){let a=bn(e,t);return e.substring(0,a)+e.substring(a+1)}return`${e}](streamdown:incomplete-link)`}if(En(e,t)===-1){let i=e.substring(0,s);if(r){let a=e.substring(t+1);return`${i}![${a}](${Ne})`}if(n==="text-only"){let a=bn(e,t);return e.substring(0,a)+e.substring(a+1)}return`${e}](streamdown:incomplete-link)`}return null},wi=(e,t)=>{let n=e.lastIndexOf("](");if(n!==-1&&!B(e,n)){let r=ki(e,n,t);if(r!==null)return r}for(let r=e.lastIndexOf("[");r!==-1;r=r===0?-1:e.lastIndexOf("[",r-1))if(!B(e,r)){let s=bi(e,r,t);if(s!==null)return s}return e},xi=32,Cn=(e,t="protocol")=>{let n=e;for(let r=0;r<xi;r+=1){let s=wi(n,t);if(s.length>=n.length)return s;n=s}return n},yi=/^-{1,2}$/,Si=/^[\s]*-{1,2}[\s]+$/,Ri=/^={1,2}$/,Ei=/^[\s]*={1,2}[\s]+$/,vi=e=>{if(!e||typeof e!="string")return e;let t=e.lastIndexOf(`
85
- `);if(t===-1)return e;let n=e.substring(t+1),r=e.substring(0,t),s=n.trim();if(yi.test(s)&&!n.match(Si)){let i=r.split(`
86
- `).at(-1);if(i&&i.trim().length>0)return`${e}\u200B`}if(Ri.test(s)&&!n.match(Ei)){let i=r.split(`
87
- `).at(-1);if(i&&i.trim().length>0)return`${e}\u200B`}return e},$i=/([\p{L}\p{N}_])~(?!~)(?=[\p{L}\p{N}_])/gu,Ci=e=>!e||typeof e!="string"||!e.includes("~")?e:e.replace($i,(t,n,r)=>{let s=r+n.length;return B(e,s)?t:`${n}\\~`}),wn=e=>lt(e,"~"),Ti=e=>{let t=se(e,_s);if(t){let n=t[2];if(!n||he.test(n))return e;let r=e.lastIndexOf(t[1]);if(B(e,r)||re(e,r))return e;if(wn(e)%2===1)return`${e}~~`}else{let n=se(e,Ps);if(n){let r=e.lastIndexOf(n[0].slice(0,2));if(B(e,r)||re(e,r))return e;if(wn(e)%2===1)return`${e}~`}}return e},at=e=>e!==!1,Ii=e=>e===!0,N={SINGLE_TILDE:0,COMPARISON_OPERATORS:5,HTML_TAGS:10,SETEXT_HEADINGS:15,LINKS:20,BOLD_ITALIC:30,BOLD:35,ITALIC_DOUBLE_UNDERSCORE:40,ITALIC_SINGLE_ASTERISK:41,ITALIC_SINGLE_UNDERSCORE:42,INLINE_CODE:50,STRIKETHROUGH:60,KATEX:70,INLINE_KATEX:75,DEFAULT:100},Ai=[{handler:{name:"singleTilde",handle:Ci,priority:N.SINGLE_TILDE},optionKey:"singleTilde"},{handler:{name:"comparisonOperators",handle:$s,priority:N.COMPARISON_OPERATORS},optionKey:"comparisonOperators"},{handler:{name:"htmlTags",handle:ui,priority:N.HTML_TAGS},optionKey:"htmlTags"},{handler:{name:"setextHeadings",handle:vi,priority:N.SETEXT_HEADINGS},optionKey:"setextHeadings"},{handler:{name:"links",handle:Cn,priority:N.LINKS},optionKey:"links",earlyReturn:e=>e.endsWith("](streamdown:incomplete-link)")||e.endsWith(`](${Ne})`)},{handler:{name:"boldItalic",handle:ii,priority:N.BOLD_ITALIC},optionKey:"boldItalic"},{handler:{name:"bold",handle:Zs,priority:N.BOLD},optionKey:"bold"},{handler:{name:"italicDoubleUnderscore",handle:Js,priority:N.ITALIC_DOUBLE_UNDERSCORE},optionKey:"italic"},{handler:{name:"italicSingleAsterisk",handle:Ys,priority:N.ITALIC_SINGLE_ASTERISK},optionKey:"italic"},{handler:{name:"italicSingleUnderscore",handle:ni,priority:N.ITALIC_SINGLE_UNDERSCORE},optionKey:"italic"},{handler:{name:"inlineCode",handle:hi,priority:N.INLINE_CODE},optionKey:"inlineCode"},{handler:{name:"strikethrough",handle:Ti,priority:N.STRIKETHROUGH},optionKey:"strikethrough"},{handler:{name:"katex",handle:gi,priority:N.KATEX},optionKey:"katex"},{handler:{name:"inlineKatex",handle:mi,priority:N.INLINE_KATEX},optionKey:"inlineKatex"}],Oi=e=>{var t;let n=(t=e?.linkMode)!=null?t:"protocol";return Ai.filter(({handler:r,optionKey:s})=>r.name==="links"?at(e?.links)||at(e?.images):r.name==="inlineKatex"?Ii(e?.inlineKatex):at(e?.[s])).map(({handler:r,earlyReturn:s})=>r.name==="links"?{handler:yn(xn({},r),{handle:i=>Cn(i,n)}),earlyReturn:n==="protocol"?s:void 0}:{handler:r,earlyReturn:s})},_i=(e,t)=>{var n;if(!e||typeof e!="string")return e;let r=e.endsWith(" ")&&!e.endsWith(" ")?e.slice(0,-1):e,s=Oi(t),i=((n=t?.handlers)!=null?n:[]).map(o=>{var c;return{handler:yn(xn({},o),{priority:(c=o.priority)!=null?c:N.DEFAULT}),earlyReturn:void 0}}),a=[...s,...i].sort((o,c)=>{var l,h;return((l=o.handler.priority)!=null?l:0)-((h=c.handler.priority)!=null?h:0)});try{for(let{handler:o,earlyReturn:c}of a)if(r=o.handle(r),c!=null&&c(r))return r;return r.endsWith(" ")&&!r.endsWith(" ")?r.slice(0,-1):r}finally{ds()}},pt=_i;var dt=e=>e===void 0||/\s/.test(e);function An(e,t){if(e[t]!==`
84
+ $$`:`${e}$$`},mi=e=>di(e)%2===0?e:gi(e),ki=e=>fi(e)%2===1?`${e}$`:e,Ne="streamdown:incomplete-image",bi=(e,t,n)=>{if(e.substring(t+2).includes(")"))return null;let r=Ds(e,t);if(r===-1||B(e,r))return null;let s=r>0&&e[r-1]==="!",i=s?r-1:r,a=e.substring(0,i),o=e.substring(r+1,t);return s?`${a}![${o}](${Ne})`:n==="text-only"?`${a}${o}`:`${a}[${o}](streamdown:incomplete-link)`},bn=(e,t)=>{for(let n=0;n<t;n++)if(e[n]==="["&&!B(e,n)){if(n>0&&e[n-1]==="!")continue;let r=En(e,n);if(r===-1)return n;if(r+1<e.length&&e[r+1]==="("){let s=e.indexOf(")",r+2);s!==-1&&(n=s)}}return t},wi=(e,t,n)=>{let r=t>0&&e[t-1]==="!",s=r?t-1:t;if(!e.substring(t+1).includes("]")){let i=e.substring(0,s);if(r){let a=e.substring(t+1);return`${i}![${a}](${Ne})`}if(n==="text-only"){let a=bn(e,t);return e.substring(0,a)+e.substring(a+1)}return`${e}](streamdown:incomplete-link)`}if(En(e,t)===-1){let i=e.substring(0,s);if(r){let a=e.substring(t+1);return`${i}![${a}](${Ne})`}if(n==="text-only"){let a=bn(e,t);return e.substring(0,a)+e.substring(a+1)}return`${e}](streamdown:incomplete-link)`}return null},xi=(e,t)=>{let n=e.lastIndexOf("](");if(n!==-1&&!B(e,n)){let r=bi(e,n,t);if(r!==null)return r}for(let r=e.lastIndexOf("[");r!==-1;r=r===0?-1:e.lastIndexOf("[",r-1))if(!B(e,r)){let s=wi(e,r,t);if(s!==null)return s}return e},yi=32,Cn=(e,t="protocol")=>{let n=e;for(let r=0;r<yi;r+=1){let s=xi(n,t);if(s.length>=n.length)return s;n=s}return n},Si=/^-{1,2}$/,Ri=/^[\s]*-{1,2}[\s]+$/,Ei=/^={1,2}$/,vi=/^[\s]*={1,2}[\s]+$/,$i=e=>{if(!e||typeof e!="string")return e;let t=e.lastIndexOf(`
85
+ `);if(t===-1)return e;let n=e.substring(t+1),r=e.substring(0,t),s=n.trim();if(Si.test(s)&&!n.match(Ri)){let i=r.split(`
86
+ `).at(-1);if(i&&i.trim().length>0)return`${e}\u200B`}if(Ei.test(s)&&!n.match(vi)){let i=r.split(`
87
+ `).at(-1);if(i&&i.trim().length>0)return`${e}\u200B`}return e},Ci=/([\p{L}\p{N}_])~(?!~)(?=[\p{L}\p{N}_])/gu,Ti=e=>!e||typeof e!="string"||!e.includes("~")?e:e.replace(Ci,(t,n,r)=>{let s=r+n.length;return B(e,s)?t:`${n}\\~`}),wn=e=>lt(e,"~"),Ii=e=>{let t=se(e,Ls);if(t){let n=t[2];if(!n||pe.test(n))return e;let r=e.lastIndexOf(t[1]);if(B(e,r)||re(e,r))return e;if(wn(e)%2===1)return`${e}~~`}else{let n=se(e,Ms);if(n){let r=e.lastIndexOf(n[0].slice(0,2));if(B(e,r)||re(e,r))return e;if(wn(e)%2===1)return`${e}~`}}return e},at=e=>e!==!1,Ai=e=>e===!0,N={SINGLE_TILDE:0,COMPARISON_OPERATORS:5,HTML_TAGS:10,SETEXT_HEADINGS:15,LINKS:20,BOLD_ITALIC:30,BOLD:35,ITALIC_DOUBLE_UNDERSCORE:40,ITALIC_SINGLE_ASTERISK:41,ITALIC_SINGLE_UNDERSCORE:42,INLINE_CODE:50,STRIKETHROUGH:60,KATEX:70,INLINE_KATEX:75,DEFAULT:100},Oi=[{handler:{name:"singleTilde",handle:Ti,priority:N.SINGLE_TILDE},optionKey:"singleTilde"},{handler:{name:"comparisonOperators",handle:Cs,priority:N.COMPARISON_OPERATORS},optionKey:"comparisonOperators"},{handler:{name:"htmlTags",handle:pi,priority:N.HTML_TAGS},optionKey:"htmlTags"},{handler:{name:"setextHeadings",handle:$i,priority:N.SETEXT_HEADINGS},optionKey:"setextHeadings"},{handler:{name:"links",handle:Cn,priority:N.LINKS},optionKey:"links",earlyReturn:e=>e.endsWith("](streamdown:incomplete-link)")||e.endsWith(`](${Ne})`)},{handler:{name:"boldItalic",handle:ai,priority:N.BOLD_ITALIC},optionKey:"boldItalic"},{handler:{name:"bold",handle:Vs,priority:N.BOLD},optionKey:"bold"},{handler:{name:"italicDoubleUnderscore",handle:Qs,priority:N.ITALIC_DOUBLE_UNDERSCORE},optionKey:"italic"},{handler:{name:"italicSingleAsterisk",handle:ei,priority:N.ITALIC_SINGLE_ASTERISK},optionKey:"italic"},{handler:{name:"italicSingleUnderscore",handle:ri,priority:N.ITALIC_SINGLE_UNDERSCORE},optionKey:"italic"},{handler:{name:"inlineCode",handle:hi,priority:N.INLINE_CODE},optionKey:"inlineCode"},{handler:{name:"strikethrough",handle:Ii,priority:N.STRIKETHROUGH},optionKey:"strikethrough"},{handler:{name:"katex",handle:mi,priority:N.KATEX},optionKey:"katex"},{handler:{name:"inlineKatex",handle:ki,priority:N.INLINE_KATEX},optionKey:"inlineKatex"}],_i=e=>{var t;let n=(t=e?.linkMode)!=null?t:"protocol";return Oi.filter(({handler:r,optionKey:s})=>r.name==="links"?at(e?.links)||at(e?.images):r.name==="inlineKatex"?Ai(e?.inlineKatex):at(e?.[s])).map(({handler:r,earlyReturn:s})=>r.name==="links"?{handler:yn(xn({},r),{handle:i=>Cn(i,n)}),earlyReturn:n==="protocol"?s:void 0}:{handler:r,earlyReturn:s})},Li=(e,t)=>{var n;if(!e||typeof e!="string")return e;let r=e.endsWith(" ")&&!e.endsWith(" ")?e.slice(0,-1):e,s=_i(t),i=((n=t?.handlers)!=null?n:[]).map(o=>{var c;return{handler:yn(xn({},o),{priority:(c=o.priority)!=null?c:N.DEFAULT}),earlyReturn:void 0}}),a=[...s,...i].sort((o,c)=>{var l,p;return((l=o.handler.priority)!=null?l:0)-((p=c.handler.priority)!=null?p:0)});try{for(let{handler:o,earlyReturn:c}of a)if(r=o.handle(r),c!=null&&c(r))return r;return r.endsWith(" ")&&!r.endsWith(" ")?r.slice(0,-1):r}finally{fs()}},ht=Li;var dt=e=>e===void 0||/\s/.test(e);function An(e,t){if(e[t]!==`
88
88
  `)return!1;for(let n=t+1;n<e.length;n++){if(e[n]===`
89
- `)return!0;if(e[n]!==" "&&e[n]!==" ")return!1}return!1}var Li=/^ {0,3}(?:~~~|#{1,6}(?:[ \t]|$)|>|<(?:[/!?]|(?:address|article|aside|blockquote|details|dialog|div|dl|fieldset|figure|footer|form|h[1-6]|header|hr|li|main|nav|ol|p|pre|script|section|style|table|textarea|ul)(?=[\s/>]|$))|([-*_])(?:[ \t]*\1){2,}[ \t]*$)/i,Pi=/^ {0,3}(?:[-+*]|\d{1,9}[.)])[ \t]/;function Mi(e,t,n){let r=e.indexOf(`
90
- `,t+1),s=e.slice(t+1,r<0?e.length:r);return Li.test(s)||n&&Pi.test(s)}function On(e,t,n){let r=e.indexOf(`
89
+ `)return!0;if(e[n]!==" "&&e[n]!==" ")return!1}return!1}var Pi=/^ {0,3}(?:~~~|#{1,6}(?:[ \t]|$)|>|<(?:[/!?]|(?:address|article|aside|blockquote|details|dialog|div|dl|fieldset|figure|footer|form|h[1-6]|header|hr|li|main|nav|ol|p|pre|script|section|style|table|textarea|ul)(?=[\s/>]|$))|([-*_])(?:[ \t]*\1){2,}[ \t]*$)/i,Mi=/^ {0,3}(?:[-+*]|\d{1,9}[.)])[ \t]/;function Ni(e,t,n){let r=e.indexOf(`
90
+ `,t+1),s=e.slice(t+1,r<0?e.length:r);return Pi.test(s)||n&&Mi.test(s)}function On(e,t,n){let r=e.indexOf(`
91
91
  `,t),s=/\S/.test(e.slice(t,r<0?e.length:r));for(let i=t;i<e.length;i++){if(n!==""&&e.startsWith(n,i))return{at:i,closed:!0};if(e[i]==="`"||e[i]===`
92
- `&&(An(e,i)||Mi(e,i,s)))return{at:i,closed:!1};e[i]==="\\"&&n!=="\\)"&&n!=="\\]"&&i++}return{at:e.length,closed:!1}}function _n(e){if(e[0]!=="$"||dt(e[1])||e[1]==="$")return-1;let t=0;for(let n=1;n<e.length;n++){let r=e[n];if(r==="\\"){n++;continue}if(r==="`"||An(e,n))return-1;if(r==="{"){t++;continue}if(r==="}"){t=Math.max(0,t-1);continue}if(!(r!=="$"||t>0))return dt(e[n-1])||/\d/.test(e[n+1]??"")?-1:n}return-1}function ft(e,t,n){let{at:r,closed:s}=On(e,t,n);return s?r:-1}function De(e,t,n){return On(e,t,n).at}function gt(e,t,n){return e.startsWith("\\")?/[\p{L}\p{N}]$/u.test(n)||/^\s*[\d.,]*\s*$/.test(t):!1}var mt=[{open:"$$",close:"$$",display:!0},{open:"\\[",close:"\\]",display:!0},{open:"\\(",close:"\\)",display:!1}];function Ln(e,t){let n=[],r=-1;for(let s=0;s<e.length;){let i=e[s];if(i==="`"){let c=/^`+/.exec(e.slice(s))[0],l=e.indexOf(c,s+c.length);s=l===-1?s+c.length:l+c.length;continue}let a=-1,o=mt.find(c=>e.startsWith(c.open,s));if(o){let c=s+o.open.length,l=ft(e,c,o.close);l!==-1?a=l+o.close.length:t&&(a=De(e,c,o.close))}else if(i==="\\"){s+=2;continue}else if(i==="$"){let c=_n(e.slice(s));c!==-1?a=s+c+1:r<0&&!dt(e[s+1])&&e[s+1]!=="$"&&(r=s)}if(a<=s){s++;continue}n.push([s,a]),s=a}return{spans:n,openDollar:r}}function kt(e){let{spans:t,openDollar:n}=Ln(e,!0);if(n>=0){let a=De(e,n+1,"");if(!t.some(([o,c])=>o<a&&c>n)){for(let o=n;o<a;o++)e[o]==="["&&t.push([o,o+1]);t.sort((o,c)=>o[0]-c[0])}}let r=[],s="",i=0;for(let[a,o]of t)s+=e.slice(i,a)+`\uE000${r.length}\uE001`,r.push(e.slice(a,o)),i=o;return s+=e.slice(i),{masked:s,unmask:a=>a.replace(/\uE000(\d+)\uE001/g,(o,c)=>r[Number(c)]??"")}}function Tn(e,t){let n=t.length-e.length,r="";for(let o=0;o<e.length;o++)r+=t[n+o]==="+"?e[o]:t[n+o];r=r.replace(/\[a+\]/g,o=>`\`${"a".repeat(o.length-2)}\``);let s=Ln(r,!1).spans.filter(([o,c])=>!gt(r.slice(o,o+2),r.slice(o+2,c-2),r.slice(0,o))),i=t.slice(0,n),a=0;for(let[o,c]of s)i+=t.slice(n+a,n+o)+"a".repeat(c-o),a=c;return i+t.slice(n+a)}var Ni=e=>e.replace(/&/g,"&amp;").replace(/</g,"&lt;").replace(/>/g,"&gt;").replace(/"/g,"&quot;");function In(e,t){let n=e.open?" data-aparte-open":"",s=`<code class="language-math ${e.display?"math-display":"math-inline"}"${n}>${Ni(e.text)}</code>`;return t?`<pre${n}>${s}</pre>
93
- `:s}function bt(e={}){let t=e.live===!0;return{tokenizer:{emStrong(n,r,s){return Object.getPrototypeOf(this).emStrong.call(this,n,Tn(n,r),s)},del(n,r,s){return Object.getPrototypeOf(this).del.call(this,n,Tn(n,r),s)}},extensions:[{name:"aparteMathBlock",level:"block",start(n){let r=n.search(/\n[ \t]*\n/),s=/\n {0,3}(\$\$|\\\[)/.exec(r<0?n:n.slice(0,r));return s?s.index+1:void 0},tokenizer(n){let r=/^ {0,3}(\$\$|\\\[)/.exec(n);if(!r)return;let s=mt.find(h=>h.open===r[1]),i=r[0].length,a=ft(n,i,s.close);if(a===-1)return!t||De(n,i,s.close)<n.length?void 0:{type:"aparteMathBlock",raw:n,text:n.slice(i).trim(),display:!0,open:!0};let o=n.slice(i,a).trim();if(gt(s.open,o,""))return;let c=/^[ \t]*(\n|$)/.exec(n.slice(a+s.close.length));return c?{type:"aparteMathBlock",raw:n.slice(0,a+s.close.length+c[0].length),text:o,display:!0,open:!1}:void 0},renderer:n=>In(n,!0)},{name:"aparteMathInline",level:"inline",start(n){let r=n.search(/\$|\\[([]/);return r===-1?void 0:r},tokenizer(n,r){for(let i of mt){if(!n.startsWith(i.open))continue;let a=ft(n,i.open.length,i.close);if(a===-1)return!t||i.open!=="$$"&&/[\p{L}\p{N}]$/u.test(r.at(-1)?.raw??"")||De(n,i.open.length,i.close)<n.length?void 0:{type:"aparteMathInline",raw:n,text:n.slice(i.open.length),display:i.display,open:!0};let o=n.slice(i.open.length,a);return gt(i.open,o,r.at(-1)?.raw??"")?void 0:{type:"aparteMathInline",raw:n.slice(0,a+i.close.length),text:o,display:i.display,open:!1}}let s=_n(n);if(s!==-1)return{type:"aparteMathInline",raw:n.slice(0,s+1),text:n.slice(1,s),display:!1,open:!1}},renderer:n=>In(n,!1)}]}}var Pn="streamdown:",Bi=/(^|[ \t])[*_~`]+$/;function Di(e,t){let n=e.replace(Bi,"$1");if(!t)return pt(n);let{masked:r,unmask:s}=kt(n);return/$/.test(r)&&/[\s\\]$/.test(n)&&({masked:r,unmask:s}=kt(n.replace(/[\s\\]+$/,""))),s(pt(r,{katex:!1}))}function zi(e,t,n){let r=document.createElement("template");if(r.innerHTML=e,t){for(let s of r.content.querySelectorAll(`a[href^="${Pn}"]`))s.removeAttribute("href");for(let s of r.content.querySelectorAll(`img[src^="${Pn}"]`))s.remove()}return r.innerHTML=n.sanitizeHtml(r.innerHTML),Array.from(r.content.childNodes)}function Ui(e,t,n){let r="",s=[],i=a=>{let o=(a?t.arriving:t.finished).lexer(r),c=0;for(;c<o.length&&c<s.length;){let h=a&&c===o.length-1,u=s[c];if(u.raw!==o[c].raw||u.healed!==h)break;c++}for(let h of s.slice(c))for(let u of h.nodes)u.remove();let l=s.slice(0,c);for(let h=c;h<o.length;h++){let u=o[h].raw,d=a&&h===o.length-1,m=d?t.arriving.parse(Di(u,t.math),{async:!1}):t.finished.parse(u,{async:!1}),k=zi(m,d,n);e.append(...k),l.push({raw:u,healed:d,nodes:k})}s=l};return{write(a){r+=a,i(!0)},end(){i(!1)}}}function Mn(e,t=me){let{math:n,...r}=e??{},i=e!==void 0&&(n===void 0||Object.keys(r).length>0)?new ve(r):y,a,o,c=()=>n??t.hasCodeLanguageRenderer("math"),l=()=>a??=new ve(r,bt()),h=()=>o??=new ve(r,bt({live:!0}));t.setMarkdownProvider(u=>(c()?l():i).parse(u,{async:!1})),t.setStreamingMarkdownProvider(u=>{let d=c();return Ui(u,d?{finished:l(),arriving:h(),math:!0}:{finished:i,arriving:i,math:!1},t)})}function Hi(e){if(!Un(e))return!1;let t=e.metadata,n=typeof t=="object"&&t!==null&&typeof t.nodeId=="string";return e.type==="keepalive"?!0:e.type==="error"?n||typeof e.content=="string":n}function Dn(e){return/^\s*<(?:!doctype|html|head|body)[\s>]/i.test(e)}function zn(e){try{return JSON.parse(e)}catch{return}}function Un(e){return typeof e=="object"&&e!==null&&!Array.isArray(e)&&typeof e.type=="string"}function wt(e){let t=e.metadata??{};return`${String(t.nodeId??"")}:${String(t.runIndex??0)}:${String(t.itemIndex??0)}`}function qi(e){switch(e.type){case"begin":return{kind:"begin",stream:wt(e)};case"item":return{kind:"item",stream:wt(e),text:typeof e.content=="string"?e.content:""};case"end":return{kind:"end",stream:wt(e)};case"error":return{kind:"error",message:typeof e.content=="string"?e.content:""};case"keepalive":return;default:return{kind:"unknown",type:e.type}}}function Hn(e){if(typeof e=="string")return e;if(Array.isArray(e)){let s=e.map(Hn);return s.every(i=>i===void 0)&&e.length>0?void 0:s.filter(i=>i!==void 0).join(`
92
+ `&&(An(e,i)||Ni(e,i,s)))return{at:i,closed:!1};e[i]==="\\"&&n!=="\\)"&&n!=="\\]"&&i++}return{at:e.length,closed:!1}}function _n(e){if(e[0]!=="$"||dt(e[1])||e[1]==="$")return-1;let t=0;for(let n=1;n<e.length;n++){let r=e[n];if(r==="\\"){n++;continue}if(r==="`"||An(e,n))return-1;if(r==="{"){t++;continue}if(r==="}"){t=Math.max(0,t-1);continue}if(!(r!=="$"||t>0))return dt(e[n-1])||/\d/.test(e[n+1]??"")?-1:n}return-1}function ft(e,t,n){let{at:r,closed:s}=On(e,t,n);return s?r:-1}function De(e,t,n){return On(e,t,n).at}function gt(e,t,n){return e.startsWith("\\")?/[\p{L}\p{N}]$/u.test(n)||/^\s*[\d.,]*\s*$/.test(t):!1}var mt=[{open:"$$",close:"$$",display:!0},{open:"\\[",close:"\\]",display:!0},{open:"\\(",close:"\\)",display:!1}];function Ln(e,t){let n=[],r=-1;for(let s=0;s<e.length;){let i=e[s];if(i==="`"){let c=/^`+/.exec(e.slice(s))[0],l=e.indexOf(c,s+c.length);s=l===-1?s+c.length:l+c.length;continue}let a=-1,o=mt.find(c=>e.startsWith(c.open,s));if(o){let c=s+o.open.length,l=ft(e,c,o.close);l!==-1?a=l+o.close.length:t&&(a=De(e,c,o.close))}else if(i==="\\"){s+=2;continue}else if(i==="$"){let c=_n(e.slice(s));c!==-1?a=s+c+1:r<0&&!dt(e[s+1])&&e[s+1]!=="$"&&(r=s)}if(a<=s){s++;continue}n.push([s,a]),s=a}return{spans:n,openDollar:r}}function kt(e){let{spans:t,openDollar:n}=Ln(e,!0);if(n>=0){let a=De(e,n+1,"");if(!t.some(([o,c])=>o<a&&c>n)){for(let o=n;o<a;o++)e[o]==="["&&t.push([o,o+1]);t.sort((o,c)=>o[0]-c[0])}}let r=[],s="",i=0;for(let[a,o]of t)s+=e.slice(i,a)+`\uE000${r.length}\uE001`,r.push(e.slice(a,o)),i=o;return s+=e.slice(i),{masked:s,unmask:a=>a.replace(/\uE000(\d+)\uE001/g,(o,c)=>r[Number(c)]??"")}}function Tn(e,t){let n=t.length-e.length,r="";for(let o=0;o<e.length;o++)r+=t[n+o]==="+"?e[o]:t[n+o];r=r.replace(/\[a+\]/g,o=>`\`${"a".repeat(o.length-2)}\``);let s=Ln(r,!1).spans.filter(([o,c])=>!gt(r.slice(o,o+2),r.slice(o+2,c-2),r.slice(0,o))),i=t.slice(0,n),a=0;for(let[o,c]of s)i+=t.slice(n+a,n+o)+"a".repeat(c-o),a=c;return i+t.slice(n+a)}var Bi=e=>e.replace(/&/g,"&amp;").replace(/</g,"&lt;").replace(/>/g,"&gt;").replace(/"/g,"&quot;");function In(e,t){let n=e.open?" data-aparte-open":"",s=`<code class="language-math ${e.display?"math-display":"math-inline"}"${n}>${Bi(e.text)}</code>`;return t?`<pre${n}>${s}</pre>
93
+ `:s}function bt(e={}){let t=e.live===!0;return{tokenizer:{emStrong(n,r,s){return Object.getPrototypeOf(this).emStrong.call(this,n,Tn(n,r),s)},del(n,r,s){return Object.getPrototypeOf(this).del.call(this,n,Tn(n,r),s)}},extensions:[{name:"aparteMathBlock",level:"block",start(n){let r=n.search(/\n[ \t]*\n/),s=/\n {0,3}(\$\$|\\\[)/.exec(r<0?n:n.slice(0,r));return s?s.index+1:void 0},tokenizer(n){let r=/^ {0,3}(\$\$|\\\[)/.exec(n);if(!r)return;let s=mt.find(p=>p.open===r[1]),i=r[0].length,a=ft(n,i,s.close);if(a===-1)return!t||De(n,i,s.close)<n.length?void 0:{type:"aparteMathBlock",raw:n,text:n.slice(i).trim(),display:!0,open:!0};let o=n.slice(i,a).trim();if(gt(s.open,o,""))return;let c=/^[ \t]*(\n|$)/.exec(n.slice(a+s.close.length));return c?{type:"aparteMathBlock",raw:n.slice(0,a+s.close.length+c[0].length),text:o,display:!0,open:!1}:void 0},renderer:n=>In(n,!0)},{name:"aparteMathInline",level:"inline",start(n){let r=n.search(/\$|\\[([]/);return r===-1?void 0:r},tokenizer(n,r){for(let i of mt){if(!n.startsWith(i.open))continue;let a=ft(n,i.open.length,i.close);if(a===-1)return!t||i.open!=="$$"&&/[\p{L}\p{N}]$/u.test(r.at(-1)?.raw??"")||De(n,i.open.length,i.close)<n.length?void 0:{type:"aparteMathInline",raw:n,text:n.slice(i.open.length),display:i.display,open:!0};let o=n.slice(i.open.length,a);return gt(i.open,o,r.at(-1)?.raw??"")?void 0:{type:"aparteMathInline",raw:n.slice(0,a+i.close.length),text:o,display:i.display,open:!1}}let s=_n(n);if(s!==-1)return{type:"aparteMathInline",raw:n.slice(0,s+1),text:n.slice(1,s),display:!1,open:!1}},renderer:n=>In(n,!1)}]}}var Pn="streamdown:",Di=/(^|[ \t])[*_~`]+$/;function zi(e,t){let n=e.replace(Di,"$1");if(!t)return ht(n);let{masked:r,unmask:s}=kt(n);return/$/.test(r)&&/[\s\\]$/.test(n)&&({masked:r,unmask:s}=kt(n.replace(/[\s\\]+$/,""))),s(ht(r,{katex:!1}))}function Ui(e,t,n){let r=document.createElement("template");if(r.innerHTML=e,t){for(let s of r.content.querySelectorAll(`a[href^="${Pn}"]`))s.removeAttribute("href");for(let s of r.content.querySelectorAll(`img[src^="${Pn}"]`))s.remove()}return r.innerHTML=n.sanitizeHtml(r.innerHTML),Array.from(r.content.childNodes)}function Hi(e,t,n){let r="",s=[],i=a=>{let o=(a?t.arriving:t.finished).lexer(r),c=0;for(;c<o.length&&c<s.length;){let p=a&&c===o.length-1,u=s[c];if(u.raw!==o[c].raw||u.healed!==p)break;c++}for(let p of s.slice(c))for(let u of p.nodes)u.remove();let l=s.slice(0,c);for(let p=c;p<o.length;p++){let u=o[p].raw,d=a&&p===o.length-1,m=d?t.arriving.parse(zi(u,t.math),{async:!1}):t.finished.parse(u,{async:!1}),k=Ui(m,d,n);e.append(...k),l.push({raw:u,healed:d,nodes:k})}s=l};return{write(a){r+=a,i(!0)},end(){i(!1)}}}function Mn(e,t=me){let{math:n,...r}=e??{},i=e!==void 0&&(n===void 0||Object.keys(r).length>0)?new ve(r):y,a,o,c=()=>n??t.hasCodeLanguageRenderer("math"),l=()=>a??=new ve(r,bt()),p=()=>o??=new ve(r,bt({live:!0}));t.setMarkdownProvider(u=>(c()?l():i).parse(u,{async:!1})),t.setStreamingMarkdownProvider(u=>{let d=c();return Hi(u,d?{finished:l(),arriving:p(),math:!0}:{finished:i,arriving:i,math:!1},t)})}function ji(e){if(!Un(e))return!1;let t=e.metadata,n=typeof t=="object"&&t!==null&&typeof t.nodeId=="string";return e.type==="keepalive"?!0:e.type==="error"?n||typeof e.content=="string":n}function Dn(e){return/^\s*<(?:!doctype|html|head|body)[\s>]/i.test(e)}function zn(e){try{return JSON.parse(e)}catch{return}}function Un(e){return typeof e=="object"&&e!==null&&!Array.isArray(e)&&typeof e.type=="string"}function wt(e){let t=e.metadata??{};return`${String(t.nodeId??"")}:${String(t.runIndex??0)}:${String(t.itemIndex??0)}`}function qi(e){switch(e.type){case"begin":return{kind:"begin",stream:wt(e)};case"item":return{kind:"item",stream:wt(e),text:typeof e.content=="string"?e.content:""};case"end":return{kind:"end",stream:wt(e)};case"error":return{kind:"error",message:typeof e.content=="string"?e.content:""};case"keepalive":return;default:return{kind:"unknown",type:e.type}}}function Hn(e){if(typeof e=="string")return e;if(Array.isArray(e)){let s=e.map(Hn);return s.every(i=>i===void 0)&&e.length>0?void 0:s.filter(i=>i!==void 0).join(`
94
94
 
95
95
  `)}if(typeof e!="object"||e===null)return e==null?"":String(e);let t=e,n=["output","text","message"].find(s=>t[s]!==void 0&&t[s]!==null);if(n===void 0)return Object.keys(t).length>0?void 0:"";let r=t[n];return typeof r=="string"?r:typeof r=="object"&&r!==null&&r.type==="text"&&typeof r.text=="string"?r.text:typeof r=="number"||typeof r=="boolean"?String(r):["```json",JSON.stringify(r,null,2),"```"].join(`
96
- `)}function ji(e){let t=e;for(;Array.isArray(t);)t=t[0];return Object.keys(t).slice(0,6)}function Fi(e){let t=e.trim();if(!t)return;let n=zn(t);if(n===void 0)return Dn(t)?{kind:"html"}:{kind:"reply",text:e};if(typeof n=="object"&&n!==null&&n.executionStarted===!0){let{executionId:s,resumeToken:i}=n;return{kind:"deferred",...typeof s=="string"||typeof s=="number"?{executionId:String(s)}:{},...typeof i=="string"?{resumeToken:i}:{}}}let r=Hn(n);return r===void 0?{kind:"unreadable",fields:ji(n)}:{kind:"reply",text:r}}async function*Ki(e){let t=e.getReader(),n=new TextDecoder,r="unknown",s="",i="";function*a(o,c){let l=o.split(`
97
- `);for(let[h,u]of l.entries()){if(!u.trim())continue;let d=zn(u);if(r==="unknown"){if(!Hi(d)){r="whole";return}r="frames"}if(Un(d)){let m=qi(d);m&&(yield m)}else c&&h===l.length-1&&u.trimStart().startsWith("{")?yield{kind:"cut"}:Dn(u)?yield{kind:"html"}:yield{kind:"item",text:u}}}try{for(;;){let{done:o,value:c}=await t.read(),l=o?n.decode():n.decode(c,{stream:!0});if(s+=l,r!=="whole"){i+=l;let h=o?i.length:i.lastIndexOf(`
98
- `)+1,u=i.slice(0,h);i=i.slice(h),yield*a(u,o)}if(o)break}}finally{t.releaseLock()}if(r!=="frames"){let o=Fi(s);o&&(yield o)}}var Wi=new Set([502,504,524]);function Gi(e){let n=(Array.isArray(e.credentials)?e.credentials:[]).map(r=>typeof r=="object"&&r!==null?r.credentialName:void 0).filter(r=>typeof r=="string"&&r.length>0);return n.length>0?` (${n.join(", ")})`:""}async function xt(e,t){let n=e.status,r=(await e.text().catch(()=>"")).trim(),s=L.codeForStatus(n)??(n===404?I.PROVIDER_MISCONFIGURED:I.PROVIDER_ERROR),i=(l,h=s)=>new L(l,h,void 0,void 0,n),a=I.PROVIDER_MISCONFIGURED;if(r.startsWith("<")||(e.headers.get("content-type")??"").includes("text/html"))return Wi.has(n)?i(`A proxy in front of n8n gave up waiting (HTTP ${n}). The workflow may still be running \u2014 its execution list shows the result.`,I.NET_TIMEOUT):i(`n8n answered HTTP ${n} with a web page instead of a chat answer. Check that the URL is the Chat Trigger's production URL, the one that ends in /chat.`,L.codeForStatus(n)??a);let o={};try{o=JSON.parse(r)}catch{}if(n===428||o.status==="credential_connections_required")return i(`The n8n workflow cannot run until its credentials are connected${Gi(o)}. Connect them in n8n, then try again.`,a);if(o.status==="credential_readiness_check_failed")return i("n8n could not check the workflow's credentials. Open the workflow in n8n to see which one fails.");if(t==="history"&&n===500)return i(`n8n could not load the conversation's history. When the Chat Trigger's "Load Previous Session" is "From Memory", connect the memory node to the Chat Trigger as well as to the agent.`,a);let c=typeof o.message=="string"?o.message:r;return typeof o.message=="string"&&typeof o.hint=="string"&&(c=`${o.message} ${o.hint}`),i(c.slice(0,400)||`The n8n workflow answered HTTP ${n}.`)}function yt(e,t){if(!(e instanceof TypeError))return e;let n=typeof location>"u"?"this page's origin":location.origin,r=typeof navigator<"u"&&navigator.onLine===!1;return new L(`Could not reach n8n at ${t}. Check that it is the Chat Trigger's production URL, that the workflow is published, and that ${n} is in the trigger's Allowed Origins (CORS).`,r?I.NET_OFFLINE:I.NET_ERROR)}function Zi(e,t,n,r){let s=new URL(e).origin.replace(/^http/,"ws"),i=new URLSearchParams({sessionId:t,executionId:n,isPublic:"true"});return r&&i.set("token",r),`${s}/chat?${i.toString()}`}function Vi(e){if(e==="n8n|heartbeat")return"heartbeat";if(e==="n8n|continue")return{kind:"continue"};let t;try{t=JSON.parse(e)}catch{return{kind:"text",text:e}}if(typeof t!="object"||t===null)return{kind:"text",text:e};let n=t;switch(n.type){case"heartbeat":return"heartbeat-json";case"continue":return{kind:"continue"};case"message":return{kind:"text",text:typeof n.text=="string"?n.text:""};case"error":return{kind:"error",message:typeof n.message=="string"?n.message:""};case"with-buttons":{let r=(Array.isArray(n.buttons)?n.buttons:[]).filter(s=>typeof s=="object"&&s!==null&&typeof s.text=="string"&&typeof s.link=="string").map(s=>({text:s.text,link:s.link,type:typeof s.type=="string"?s.type:"primary"}));return{kind:"buttons",text:typeof n.text=="string"?n.text:"",buttons:r,blockUserInput:n.blockUserInput===!0}}default:return{kind:"text",text:e}}}var Ji=1,St=class{closed=!1;socket;queue=[];waiter;opened;constructor(t,n){this.socket=new n(t),this.opened=new Promise(r=>{this.socket.onopen=()=>r()}),this.socket.onmessage=r=>{let s=Vi(String(r.data));s==="heartbeat"?this.socket.send("n8n|heartbeat-ack"):s==="heartbeat-json"?this.socket.send(JSON.stringify({type:"heartbeat-ack"})):this.push(s)},this.socket.onerror=()=>{},this.socket.onclose=()=>{this.closed=!0,this.push({kind:"closed"})}}push(t){let n=this.waiter;this.waiter=void 0,n?n(t):this.queue.push(t)}unshift(t){this.queue.unshift(t)}next(t,n){let r=this.queue.shift();return r?Promise.resolve(r):this.closed?Promise.resolve({kind:"closed"}):t.aborted?Promise.resolve(void 0):new Promise(s=>{let i,a=l=>{i!==void 0&&clearTimeout(i),t.removeEventListener("abort",c),this.waiter===o&&(this.waiter=void 0),s(l)},o=l=>a(l),c=()=>a(void 0);this.waiter=o,t.addEventListener("abort",c,{once:!0}),n!==void 0&&(i=setTimeout(()=>a("timeout"),n))})}async send(t){this.socket.readyState!==Ji&&await this.opened,this.socket.send(JSON.stringify(t))}close(){this.socket.close()}},ze="n8n_buttons";function qn(e=me){e.registerTool({name:ze,description:"The buttons of an n8n Chat node that waits for an answer. Answered by the person in the page.",inputSchema:{type:"object",properties:{}}},async(t,n,r)=>{let s=t.input,i=await Nt({kind:"approval",message:s.text,options:s.buttons.map((u,d)=>({value:String(d),label:u.text,tone:u.type==="secondary"?"deny":"affirm"})),allowOther:!s.blockUserInput,signal:n,...r?.target?{target:r.target}:{}}),a=i.action==="accept"?i.content:void 0,o=a?.instruction?.trim();if(o&&a?.option===void 0){let u={index:-1,text:o,written:!0};return{toolCallId:t.id,content:o,structuredContent:u}}let c=a?.option===void 0?-1:Number(a.option),l=s.buttons[c];if(!l)throw new Error("No button was chosen.");let h={index:c,text:l.text};return{toolCallId:t.id,content:l.text,structuredContent:h}}),e.registerToolDisplay(ze,{icon:"messageSquare",label:t=>typeof t.result=="string"&&t.result?t.result:Qi(t),quiet:!0,details:!1})}function Qi(e){return e.toolCall?.input?.text??""}function Xi(e){if(e)try{let t=JSON.parse(e);return t.v===1&&typeof t.sessionId=="string"&&typeof t.executionId=="string"&&typeof t.toolCallId=="string"&&Array.isArray(t.links)?t:void 0}catch{return}}var Yi=250;async function ea(e){let t=new Uint8Array(await e.blob.arrayBuffer()),n="";for(let s=0;s<t.length;s++)n+=String.fromCharCode(t[s]);let r=e.blob.type||"application/octet-stream";return{name:e.name,type:r,data:`data:${r};base64,${btoa(n)}`}}var Nn=`The n8n workflow streamed nothing. When its Chat Trigger streams, the node that answers has to stream too: turn on streaming in the AI Agent's options, or set the trigger's Response Mode to "When Last Node Finishes".`,ta="The n8n workflow finished without an answer: its last node returned no text. End the workflow on the node that answers \u2014 an AI Agent, or a node that returns an `output` field.",na="A proxy timed out waiting for n8n's answer. The workflow may still be running \u2014 its execution list shows the result.",ra="This n8n workflow answers through response nodes, over n8n's chat WebSocket, and n8n did not say which execution to listen to. Check the Chat Trigger's Response Mode.",sa="This n8n workflow answers through response nodes, over n8n's chat WebSocket, and this runtime has no WebSocket. Pass one as the runner's `WebSocket` option.",ia=e=>`The n8n workflow answered with the fields ${e.map(t=>`"${t}"`).join(", ")} but no "output", "text" or "message" field, which is where a chat reads the answer. End the workflow on an AI Agent, or add a Set node that puts the reply in "output".`;function aa(e){for(let t=e.length-1;t>=0;t--)if(e[t]?.role==="user")return t;return-1}function Bn(e){return e===void 0?"":typeof e=="string"?e:e.flatMap(t=>t.type==="text"&&t.text?[t.text]:[]).join(`
96
+ `)}function Fi(e){let t=e;for(;Array.isArray(t);)t=t[0];return Object.keys(t).slice(0,6)}function Ki(e){let t=e.trim();if(!t)return;let n=zn(t);if(n===void 0)return Dn(t)?{kind:"html"}:{kind:"reply",text:e};if(typeof n=="object"&&n!==null&&n.executionStarted===!0){let{executionId:s,resumeToken:i}=n;return{kind:"deferred",...typeof s=="string"||typeof s=="number"?{executionId:String(s)}:{},...typeof i=="string"?{resumeToken:i}:{}}}let r=Hn(n);return r===void 0?{kind:"unreadable",fields:Fi(n)}:{kind:"reply",text:r}}async function*Wi(e){let t=e.getReader(),n=new TextDecoder,r="unknown",s="",i="";function*a(o,c){let l=o.split(`
97
+ `);for(let[p,u]of l.entries()){if(!u.trim())continue;let d=zn(u);if(r==="unknown"){if(!ji(d)){r="whole";return}r="frames"}if(Un(d)){let m=qi(d);m&&(yield m)}else c&&p===l.length-1&&u.trimStart().startsWith("{")?yield{kind:"cut"}:Dn(u)?yield{kind:"html"}:yield{kind:"item",text:u}}}try{for(;;){let{done:o,value:c}=await t.read(),l=o?n.decode():n.decode(c,{stream:!0});if(s+=l,r!=="whole"){i+=l;let p=o?i.length:i.lastIndexOf(`
98
+ `)+1,u=i.slice(0,p);i=i.slice(p),yield*a(u,o)}if(o)break}}finally{t.releaseLock()}if(r!=="frames"){let o=Ki(s);o&&(yield o)}}var Gi=new Set([502,504,524]);function Zi(e){let n=(Array.isArray(e.credentials)?e.credentials:[]).map(r=>typeof r=="object"&&r!==null?r.credentialName:void 0).filter(r=>typeof r=="string"&&r.length>0);return n.length>0?` (${n.join(", ")})`:""}async function xt(e,t){let n=e.status,r=(await e.text().catch(()=>"")).trim(),s=L.codeForStatus(n)??(n===404?I.PROVIDER_MISCONFIGURED:I.PROVIDER_ERROR),i=(l,p=s)=>new L(l,p,void 0,void 0,n),a=I.PROVIDER_MISCONFIGURED;if(r.startsWith("<")||(e.headers.get("content-type")??"").includes("text/html"))return Gi.has(n)?i(`A proxy in front of n8n gave up waiting (HTTP ${n}). The workflow may still be running \u2014 its execution list shows the result.`,I.NET_TIMEOUT):i(`n8n answered HTTP ${n} with a web page instead of a chat answer. Check that the URL is the Chat Trigger's production URL, the one that ends in /chat.`,L.codeForStatus(n)??a);let o={};try{o=JSON.parse(r)}catch{}if(n===428||o.status==="credential_connections_required")return i(`The n8n workflow cannot run until its credentials are connected${Zi(o)}. Connect them in n8n, then try again.`,a);if(o.status==="credential_readiness_check_failed")return i("n8n could not check the workflow's credentials. Open the workflow in n8n to see which one fails.");if(t==="history"&&n===500)return i(`n8n could not load the conversation's history. When the Chat Trigger's "Load Previous Session" is "From Memory", connect the memory node to the Chat Trigger as well as to the agent.`,a);let c=typeof o.message=="string"?o.message:r;return typeof o.message=="string"&&typeof o.hint=="string"&&(c=`${o.message} ${o.hint}`),i(c.slice(0,400)||`The n8n workflow answered HTTP ${n}.`)}function yt(e,t){if(!(e instanceof TypeError))return e;let n=typeof location>"u"?"this page's origin":location.origin,r=typeof navigator<"u"&&navigator.onLine===!1;return new L(`Could not reach n8n at ${t}. Check that it is the Chat Trigger's production URL, that the workflow is published, and that ${n} is in the trigger's Allowed Origins (CORS).`,r?I.NET_OFFLINE:I.NET_ERROR)}function Vi(e,t,n,r){let s=new URL(e).origin.replace(/^http/,"ws"),i=new URLSearchParams({sessionId:t,executionId:n,isPublic:"true"});return r&&i.set("token",r),`${s}/chat?${i.toString()}`}function Ji(e){if(e==="n8n|heartbeat")return"heartbeat";if(e==="n8n|continue")return{kind:"continue"};let t;try{t=JSON.parse(e)}catch{return{kind:"text",text:e}}if(typeof t!="object"||t===null)return{kind:"text",text:e};let n=t;switch(n.type){case"heartbeat":return"heartbeat-json";case"continue":return{kind:"continue"};case"message":return{kind:"text",text:typeof n.text=="string"?n.text:""};case"error":return{kind:"error",message:typeof n.message=="string"?n.message:""};case"with-buttons":{let r=(Array.isArray(n.buttons)?n.buttons:[]).filter(s=>typeof s=="object"&&s!==null&&typeof s.text=="string"&&typeof s.link=="string").map(s=>({text:s.text,link:s.link,type:typeof s.type=="string"?s.type:"primary"}));return{kind:"buttons",text:typeof n.text=="string"?n.text:"",buttons:r,blockUserInput:n.blockUserInput===!0}}default:return{kind:"text",text:e}}}var Qi=1,St=class{closed=!1;socket;queue=[];waiter;opened;constructor(t,n){this.socket=new n(t),this.opened=new Promise(r=>{this.socket.onopen=()=>r()}),this.socket.onmessage=r=>{let s=Ji(String(r.data));s==="heartbeat"?this.socket.send("n8n|heartbeat-ack"):s==="heartbeat-json"?this.socket.send(JSON.stringify({type:"heartbeat-ack"})):this.push(s)},this.socket.onerror=()=>{},this.socket.onclose=()=>{this.closed=!0,this.push({kind:"closed"})}}push(t){let n=this.waiter;this.waiter=void 0,n?n(t):this.queue.push(t)}unshift(t){this.queue.unshift(t)}next(t,n){let r=this.queue.shift();return r?Promise.resolve(r):this.closed?Promise.resolve({kind:"closed"}):t.aborted?Promise.resolve(void 0):new Promise(s=>{let i,a=l=>{i!==void 0&&clearTimeout(i),t.removeEventListener("abort",c),this.waiter===o&&(this.waiter=void 0),s(l)},o=l=>a(l),c=()=>a(void 0);this.waiter=o,t.addEventListener("abort",c,{once:!0}),n!==void 0&&(i=setTimeout(()=>a("timeout"),n))})}async send(t){this.socket.readyState!==Qi&&await this.opened,this.socket.send(JSON.stringify(t))}close(){this.socket.close()}},ze="n8n_buttons";function jn(e=me){e.registerTool({name:ze,description:"The buttons of an n8n Chat node that waits for an answer. Answered by the person in the page.",inputSchema:{type:"object",properties:{}}},async(t,n,r)=>{let s=t.input,i=await Nt({kind:"approval",message:s.text,options:s.buttons.map((u,d)=>({value:String(d),label:u.text,tone:u.type==="secondary"?"deny":"affirm"})),allowOther:!s.blockUserInput,signal:n,...r?.target?{target:r.target}:{}}),a=i.action==="accept"?i.content:void 0,o=a?.instruction?.trim();if(o&&a?.option===void 0){let u={index:-1,text:o,written:!0};return{toolCallId:t.id,content:o,structuredContent:u}}let c=a?.option===void 0?-1:Number(a.option),l=s.buttons[c];if(!l)throw new Error("No button was chosen.");let p={index:c,text:l.text};return{toolCallId:t.id,content:l.text,structuredContent:p}}),e.registerToolDisplay(ze,{icon:"messageSquare",label:t=>typeof t.result=="string"&&t.result?t.result:Xi(t),quiet:!0,details:!1})}function Xi(e){return e.toolCall?.input?.text??""}function Yi(e){if(e)try{let t=JSON.parse(e);return t.v===1&&typeof t.sessionId=="string"&&typeof t.executionId=="string"&&typeof t.toolCallId=="string"&&Array.isArray(t.links)?t:void 0}catch{return}}var ea=250;async function ta(e){let t=new Uint8Array(await e.blob.arrayBuffer()),n="";for(let s=0;s<t.length;s++)n+=String.fromCharCode(t[s]);let r=e.blob.type||"application/octet-stream";return{name:e.name,type:r,data:`data:${r};base64,${btoa(n)}`}}var Nn=`The n8n workflow streamed nothing. When its Chat Trigger streams, the node that answers has to stream too: turn on streaming in the AI Agent's options, or set the trigger's Response Mode to "When Last Node Finishes".`,na="The n8n workflow finished without an answer: its last node returned no text. End the workflow on the node that answers \u2014 an AI Agent, or a node that returns an `output` field.",ra="A proxy timed out waiting for n8n's answer. The workflow may still be running \u2014 its execution list shows the result.",sa="This n8n workflow answers through response nodes, over n8n's chat WebSocket, and n8n did not say which execution to listen to. Check the Chat Trigger's Response Mode.",ia="This n8n workflow answers through response nodes, over n8n's chat WebSocket, and this runtime has no WebSocket. Pass one as the runner's `WebSocket` option.",aa=e=>`The n8n workflow answered with the fields ${e.map(t=>`"${t}"`).join(", ")} but no "output", "text" or "message" field, which is where a chat reads the answer. End the workflow on an AI Agent, or add a Set node that puts the reply in "output".`;function oa(e){for(let t=e.length-1;t>=0;t--)if(e[t]?.role==="user")return t;return-1}function Bn(e){return e===void 0?"":typeof e=="string"?e:e.flatMap(t=>t.type==="text"&&t.text?[t.text]:[]).join(`
99
99
 
100
- `)}var oa={"image/png":"png","image/jpeg":"jpg","image/gif":"gif","image/webp":"webp","image/svg+xml":"svg"};function la(e,t,n){let r=/^data:([^;,]+)?((?:;[^;,]*)*?);base64,(.*)$/s.exec(e);if(!r)return;let s=t??r[1]??"application/octet-stream",i=atob(r[3]??""),a=new Uint8Array(i.length);for(let o=0;o<i.length;o++)a[o]=i.charCodeAt(o);return{blob:new Blob([a],{type:s}),name:`image-${n+1}.${oa[s]??"bin"}`}}function ca(e,t){return e.files&&e.files.length>0?e.files.map(n=>({blob:n,name:n.name})):(Array.isArray(t?.content)?t.content:[]).flatMap(n=>n.type==="image"?[n]:[]).map((n,r)=>la(n.image,n.mimeType,r)).filter(n=>n!==void 0)}function jn(e){let t=e.onWarning??(l=>console.warn(`[aparte] n8n: ${l}`)),n=e.chatSessionKey??"sessionId",r=e.chatInputKey??"chatInput",s=`aparte-${oe()}`,i=new Map,a=(l,h,u)=>{let d=e.WebSocket??globalThis.WebSocket;if(!d)throw new L(sa,I.PROVIDER_MISCONFIGURED);i.get(l)?.socket.close();let m={socket:new St(Zi(e.webhookUrl,l,h,u),d),executionId:h,...u?{token:u}:{}};return i.set(l,m),m},o=async(l,h)=>{let u=l.emitter,d=i.get(h),{socket:m}=d,k=!1,v=()=>{k&&u({type:"text-flush"}),u({type:"run-done"})};for(;;){let $=await m.next(l.signal);if($===void 0)return;if(!($==="timeout"||$.kind==="continue"))switch($.kind){case"text":{k&&u({type:"text-flush"}),$.text&&(u({type:"text-delta",delta:$.text}),k=!0);let x=await m.next(l.signal,Yi);if(x===void 0)return;if(x==="timeout")return v();x.kind!=="continue"&&m.unshift(x);break}case"buttons":{k&&u({type:"text-flush"}),$.text&&(u({type:"text-delta",delta:$.text}),u({type:"text-flush"}));let x=new URL(e.webhookUrl).origin,O=$.buttons.filter(S=>{try{return new URL(S.link,e.webhookUrl).origin===x}catch{return!1}});if(O.length===0){t("An n8n Chat node sent buttons whose links lead off this n8n instance; they were not shown."),u({type:"run-done"});return}let U=`n8n-buttons-${oe()}`,q={text:$.text,buttons:O.map(S=>({text:S.text,type:S.type})),blockUserInput:$.blockUserInput},b={v:1,sessionId:h,executionId:d.executionId,...d.token?{token:d.token}:{},toolCallId:U,links:O.map(S=>S.link)};u({type:"tool-start",toolCallId:U,name:ze,input:q}),u({type:"run-suspended",pending:[{toolCallId:U,name:ze,input:q,reason:"external"}],ticket:JSON.stringify(b)});return}case"error":throw k&&u({type:"text-flush"}),new L($.message||"The n8n workflow failed.",I.PROVIDER_ERROR);case"closed":return i.delete(h),v()}}},c=async(l,h,u)=>{let d=l.emitter;d({type:"run-start"}),d({type:"turn-start"});let m=l.deferral?.outcomes?.[h.toolCallId],k=m?.kind==="result"?m.structuredContent:void 0,v=k?h.links[k.index]:void 0;if(m?.kind==="result"&&k?.written){d({type:"tool-resolved",toolCallId:h.toolCallId,result:m.content,structuredResult:k}),await(i.get(h.sessionId)??a(h.sessionId,h.executionId,h.token)).socket.send({sessionId:h.sessionId,action:"sendMessage",chatInput:k.text,files:[]}),await o(l,h.sessionId);return}if(!m||m.kind!=="result"||!v){d({type:"tool-aborted",toolCallId:h.toolCallId}),d({type:"run-done"});return}d({type:"tool-resolved",toolCallId:h.toolCallId,result:m.content,structuredResult:k});let $=i.get(h.sessionId);(!$||$.socket.closed)&&a(h.sessionId,h.executionId,h.token);let x=await u(v,{signal:l.signal,...e.credentials?{credentials:e.credentials}:{}}).catch(O=>{throw yt(O,v)});if(!x.ok)throw await xt(x,"answer");await o(l,h.sessionId)};return async l=>{let h=l.emitter,u=e.fetch??fetch;try{let d=Xi(l.deferral?.token);if(d){await c(l,d,u);return}let m=l.baseRequest.messages,k=aa(m),v=k>=0?m[k]:void 0;e.sessionId===void 0&&!m.slice(0,Math.max(k,0)).some(f=>f.role==="assistant")&&(s=`aparte-${oe()}`);let $=typeof e.headers=="function"?await e.headers():e.headers??{},x=(typeof e.sessionId=="function"?e.sessionId(l):e.sessionId)??s,O=typeof e.metadata=="function"?e.metadata(l):e.metadata,U=ca(l,v),q=i.get(x);if(q&&!q.socket.closed){h({type:"run-start"}),h({type:"turn-start"}),await q.socket.send({sessionId:x,action:"sendMessage",chatInput:Bn(v?.content),files:await Promise.all(U.map(ea))}),await o(l,x);return}let b={action:"sendMessage",[n]:x,[r]:Bn(v?.content),...O?{metadata:O}:{}},S,M={Accept:"text/plain"};for(let[f,A]of Object.entries($))f.toLowerCase()!=="content-type"&&(M[f]=A);if(U.length>0){let f=new FormData;for(let[A,G]of Object.entries(b))f.append(A,typeof G=="string"?G:JSON.stringify(G));for(let A of U)f.append("files",A.blob,A.name);S=f}else S=JSON.stringify(b),M["Content-Type"]="application/json";let X=await u(e.webhookUrl,{method:"POST",headers:M,body:S,signal:l.signal,...e.credentials?{credentials:e.credentials}:{}}).catch(f=>{throw yt(f,e.webhookUrl)});if(!X.ok)throw await xt(X,"answer");h({type:"run-start"}),h({type:"turn-start"});let ie=!1,Ce=!1,pe=!1,W=!1,C,V=new Map,de=new Set,fe=()=>{pe&&h({type:"text-flush"}),pe=!1},Y=f=>{f&&(ie=!0,pe=!0,h({type:"text-delta",delta:f}))},ee=f=>{C=f,fe()},te=()=>{C=void 0;for(let[f,A]of V){V.delete(f),ee(f);for(let G of A.text)Y(G);if(!A.ended)return;C=void 0}},J=f=>{let A=V.get(f);return A||V.set(f,A={text:[],ended:!1}),A};if(!X.body)throw new L(Nn,I.PROVIDER_MISCONFIGURED);for await(let f of Ki(X.body))switch(f.kind){case"begin":C===void 0?ee(f.stream):f.stream!==C&&J(f.stream);break;case"item":f.stream===void 0||f.stream===C?Y(f.text):C===void 0?(ee(f.stream),Y(f.text)):J(f.stream).text.push(f.text);break;case"end":f.stream===C?te():J(f.stream).ended=!0;break;case"error":throw fe(),new L(f.message||"The n8n workflow failed.",I.PROVIDER_ERROR);case"reply":Ce=!0,Y(f.text);break;case"unreadable":throw new L(ia(f.fields),I.PROVIDER_MISCONFIGURED);case"deferred":if(!f.executionId)throw new L(ra,I.PROVIDER_MISCONFIGURED);a(x,f.executionId,f.resumeToken),W=!0;break;case"html":throw fe(),new L(na,I.NET_TIMEOUT);case"cut":t("n8n's stream stopped in the middle of a frame; the text before it is kept.");break;case"unknown":de.has(f.type)||t(`n8n sent a "${f.type}" frame, which this runner does not read; it was skipped.`),de.add(f.type);break}if(W){await o(l,x);return}te();for(let[f,A]of V){V.delete(f),ee(f);for(let G of A.text)Y(G)}if(!ie)throw new L(Ce?ta:Nn,I.PROVIDER_MISCONFIGURED);fe(),h({type:"run-done"});return}catch(d){if(l.signal.aborted)return;throw d}}}function ua(e){let t=Array.isArray(e.id)?e.id:[],n=t[t.length-1];return typeof n=="string"?n:typeof e.type=="string"?e.type:""}function ha(e){return typeof e=="string"?e:Array.isArray(e)?e.map(t=>typeof t=="string"?t:typeof t=="object"&&t!==null&&t.type==="text"?String(t.text??""):"").filter(Boolean).join(`
100
+ `)}var la={"image/png":"png","image/jpeg":"jpg","image/gif":"gif","image/webp":"webp","image/svg+xml":"svg"};function ca(e,t,n){let r=/^data:([^;,]+)?((?:;[^;,]*)*?);base64,(.*)$/s.exec(e);if(!r)return;let s=t??r[1]??"application/octet-stream",i=atob(r[3]??""),a=new Uint8Array(i.length);for(let o=0;o<i.length;o++)a[o]=i.charCodeAt(o);return{blob:new Blob([a],{type:s}),name:`image-${n+1}.${la[s]??"bin"}`}}function ua(e,t){return e.files&&e.files.length>0?e.files.map(n=>({blob:n,name:n.name})):(Array.isArray(t?.content)?t.content:[]).flatMap(n=>n.type==="image"?[n]:[]).map((n,r)=>ca(n.image,n.mimeType,r)).filter(n=>n!==void 0)}function qn(e){let t=e.onWarning??(l=>console.warn(`[aparte] n8n: ${l}`)),n=e.chatSessionKey??"sessionId",r=e.chatInputKey??"chatInput",s=`aparte-${oe()}`,i=new Map,a=(l,p,u)=>{let d=e.WebSocket??globalThis.WebSocket;if(!d)throw new L(ia,I.PROVIDER_MISCONFIGURED);i.get(l)?.socket.close();let m={socket:new St(Vi(e.webhookUrl,l,p,u),d),executionId:p,...u?{token:u}:{}};return i.set(l,m),m},o=async(l,p)=>{let u=l.emitter,d=i.get(p),{socket:m}=d,k=!1,v=()=>{k&&u({type:"text-flush"}),u({type:"run-done"})};for(;;){let $=await m.next(l.signal);if($===void 0)return;if(!($==="timeout"||$.kind==="continue"))switch($.kind){case"text":{k&&u({type:"text-flush"}),$.text&&(u({type:"text-delta",delta:$.text}),k=!0);let x=await m.next(l.signal,ea);if(x===void 0)return;if(x==="timeout")return v();x.kind!=="continue"&&m.unshift(x);break}case"buttons":{k&&u({type:"text-flush"}),$.text&&(u({type:"text-delta",delta:$.text}),u({type:"text-flush"}));let x=new URL(e.webhookUrl).origin,O=$.buttons.filter(S=>{try{return new URL(S.link,e.webhookUrl).origin===x}catch{return!1}});if(O.length===0){t("An n8n Chat node sent buttons whose links lead off this n8n instance; they were not shown."),u({type:"run-done"});return}let U=`n8n-buttons-${oe()}`,j={text:$.text,buttons:O.map(S=>({text:S.text,type:S.type})),blockUserInput:$.blockUserInput},b={v:1,sessionId:p,executionId:d.executionId,...d.token?{token:d.token}:{},toolCallId:U,links:O.map(S=>S.link)};u({type:"tool-start",toolCallId:U,name:ze,input:j}),u({type:"run-suspended",pending:[{toolCallId:U,name:ze,input:j,reason:"external"}],ticket:JSON.stringify(b)});return}case"error":throw k&&u({type:"text-flush"}),new L($.message||"The n8n workflow failed.",I.PROVIDER_ERROR);case"closed":return i.delete(p),v()}}},c=async(l,p,u)=>{let d=l.emitter;d({type:"run-start"}),d({type:"turn-start"});let m=l.deferral?.outcomes?.[p.toolCallId],k=m?.kind==="result"?m.structuredContent:void 0,v=k?p.links[k.index]:void 0;if(m?.kind==="result"&&k?.written){d({type:"tool-resolved",toolCallId:p.toolCallId,result:m.content,structuredResult:k}),await(i.get(p.sessionId)??a(p.sessionId,p.executionId,p.token)).socket.send({sessionId:p.sessionId,action:"sendMessage",chatInput:k.text,files:[]}),await o(l,p.sessionId);return}if(!m||m.kind!=="result"||!v){d({type:"tool-aborted",toolCallId:p.toolCallId}),d({type:"run-done"});return}d({type:"tool-resolved",toolCallId:p.toolCallId,result:m.content,structuredResult:k});let $=i.get(p.sessionId);(!$||$.socket.closed)&&a(p.sessionId,p.executionId,p.token);let x=await u(v,{signal:l.signal,...e.credentials?{credentials:e.credentials}:{}}).catch(O=>{throw yt(O,v)});if(!x.ok)throw await xt(x,"answer");await o(l,p.sessionId)};return async l=>{let p=l.emitter,u=e.fetch??fetch;try{let d=Yi(l.deferral?.token);if(d){await c(l,d,u);return}let m=l.baseRequest.messages,k=oa(m),v=k>=0?m[k]:void 0;e.sessionId===void 0&&!m.slice(0,Math.max(k,0)).some(f=>f.role==="assistant")&&(s=`aparte-${oe()}`);let $=typeof e.headers=="function"?await e.headers():e.headers??{},x=(typeof e.sessionId=="function"?e.sessionId(l):e.sessionId)??s,O=typeof e.metadata=="function"?e.metadata(l):e.metadata,U=ua(l,v),j=i.get(x);if(j&&!j.socket.closed){p({type:"run-start"}),p({type:"turn-start"}),await j.socket.send({sessionId:x,action:"sendMessage",chatInput:Bn(v?.content),files:await Promise.all(U.map(ta))}),await o(l,x);return}let b={action:"sendMessage",[n]:x,[r]:Bn(v?.content),...O?{metadata:O}:{}},S,M={Accept:"text/plain"};for(let[f,A]of Object.entries($))f.toLowerCase()!=="content-type"&&(M[f]=A);if(U.length>0){let f=new FormData;for(let[A,G]of Object.entries(b))f.append(A,typeof G=="string"?G:JSON.stringify(G));for(let A of U)f.append("files",A.blob,A.name);S=f}else S=JSON.stringify(b),M["Content-Type"]="application/json";let X=await u(e.webhookUrl,{method:"POST",headers:M,body:S,signal:l.signal,...e.credentials?{credentials:e.credentials}:{}}).catch(f=>{throw yt(f,e.webhookUrl)});if(!X.ok)throw await xt(X,"answer");p({type:"run-start"}),p({type:"turn-start"});let ie=!1,Ce=!1,he=!1,W=!1,C,V=new Map,de=new Set,fe=()=>{he&&p({type:"text-flush"}),he=!1},Y=f=>{f&&(ie=!0,he=!0,p({type:"text-delta",delta:f}))},ee=f=>{C=f,fe()},te=()=>{C=void 0;for(let[f,A]of V){V.delete(f),ee(f);for(let G of A.text)Y(G);if(!A.ended)return;C=void 0}},J=f=>{let A=V.get(f);return A||V.set(f,A={text:[],ended:!1}),A};if(!X.body)throw new L(Nn,I.PROVIDER_MISCONFIGURED);for await(let f of Wi(X.body))switch(f.kind){case"begin":C===void 0?ee(f.stream):f.stream!==C&&J(f.stream);break;case"item":f.stream===void 0||f.stream===C?Y(f.text):C===void 0?(ee(f.stream),Y(f.text)):J(f.stream).text.push(f.text);break;case"end":f.stream===C?te():J(f.stream).ended=!0;break;case"error":throw fe(),new L(f.message||"The n8n workflow failed.",I.PROVIDER_ERROR);case"reply":Ce=!0,Y(f.text);break;case"unreadable":throw new L(aa(f.fields),I.PROVIDER_MISCONFIGURED);case"deferred":if(!f.executionId)throw new L(sa,I.PROVIDER_MISCONFIGURED);a(x,f.executionId,f.resumeToken),W=!0;break;case"html":throw fe(),new L(ra,I.NET_TIMEOUT);case"cut":t("n8n's stream stopped in the middle of a frame; the text before it is kept.");break;case"unknown":de.has(f.type)||t(`n8n sent a "${f.type}" frame, which this runner does not read; it was skipped.`),de.add(f.type);break}if(W){await o(l,x);return}te();for(let[f,A]of V){V.delete(f),ee(f);for(let G of A.text)Y(G)}if(!ie)throw new L(Ce?na:Nn,I.PROVIDER_MISCONFIGURED);fe(),p({type:"run-done"});return}catch(d){if(l.signal.aborted)return;throw d}}}function pa(e){let t=Array.isArray(e.id)?e.id:[],n=t[t.length-1];return typeof n=="string"?n:typeof e.type=="string"?e.type:""}function ha(e){return typeof e=="string"?e:Array.isArray(e)?e.map(t=>typeof t=="string"?t:typeof t=="object"&&t!==null&&t.type==="text"?String(t.text??""):"").filter(Boolean).join(`
101
101
 
102
- `):""}function pa(e,{now:t=Date.now()}={}){let n=[];return e.forEach((r,s)=>{if(typeof r!="object"||r===null)return;let i=r,a=ua(i),o=/^Human/.test(a)||a==="human"?"user":/^AI/.test(a)||a==="ai"?"assistant":void 0;if(!o)return;let c=ha(i.kwargs?.content);c.trim()&&n.push({id:`n8n-${s}`,role:o,content:c,timestamp:t-(e.length-s),status:"completed"})}),n}async function Fn(e){let t=e.fetch??fetch,n=typeof e.headers=="function"?await e.headers():e.headers??{},r={"Content-Type":"application/json"};for(let[o,c]of Object.entries(n))o.toLowerCase()!=="content-type"&&(r[o]=c);let s=await t(e.webhookUrl,{method:"POST",headers:r,body:JSON.stringify({action:"loadPreviousSession",[e.chatSessionKey??"sessionId"]:e.sessionId,...e.metadata?{metadata:e.metadata}:{}}),...e.signal?{signal:e.signal}:{},...e.credentials?{credentials:e.credentials}:{}}).catch(o=>{throw yt(o,e.webhookUrl)});if(!s.ok)throw await xt(s,"history");let i;try{i=await s.json()}catch{throw new L("n8n answered the history request with something that is not JSON. Check that the URL is the Chat Trigger's production URL.",I.PROVIDER_MISCONFIGURED)}let a=typeof i=="object"&&i!==null?i.data:void 0;return pa(Array.isArray(a)?a:[])}var Rt="card-",da=["weather","items","product","place","stats","order","stock","plan","score","media","link"],Ue="aparte-card-fence",Et=new WeakMap,fa=e=>`setup${e.charAt(0).toUpperCase()}${e.slice(1)}Card`;function ga(e,t){let n=Et.get(e),r=n?.load[t];if(!n||!r)return Promise.resolve(!1);let s=n.pending.get(t);return s||(s=r().then(i=>{let a=i[fa(t)];return typeof a!="function"?!1:(a({config:e}),!0)},i=>(console.warn(`[aparte-cards] the ${t} card could not be loaded; its fence shows its source.`,i),!1)),n.pending.set(t,s)),s}function ma(e,t){let n=0;for(let r=0;r<t.length;r++)n=Math.imul(31,n)+t.charCodeAt(r)|0;return`fence-${e}-${(n>>>0).toString(36)}`}async function ka(e){let t=e.getAttribute("data-card")??"",n=e.getAttribute("data-source")??"",r=Lt(e),s=()=>{let l=document.createElement("code");l.className="aparte-code-error",l.textContent=n,e.replaceChildren(l)},i;try{i=JSON.parse(n)}catch{s();return}let a=i&&typeof i=="object"&&typeof i.variant=="string"?i.variant:void 0,o={id:ma(t,n),type:"card",card:t,data:i,...a?{variant:a}:{}},c=Ge(r,o);!c&&await ga(r,t)&&e.isConnected&&(c=Ge(r,o)),c?e.replaceChildren(c):s()}function ba(){typeof customElements>"u"||typeof HTMLElement>"u"||customElements.get(Ue)||customElements.define(Ue,class extends HTMLElement{connectedCallback(){this.hasAttribute("data-drawn")||(this.setAttribute("data-drawn",""),ka(this))}})}function Kn(e={}){let t=e.config??me;e.load&&Et.set(t,{load:e.load,pending:new Map}),ba();let n=new Set([...da,...qt(t),...Object.keys(e.load??{})]),r={languages:[...n].map(i=>`${Rt}${i}`),bare:!0,render:({language:i,source:a,open:o})=>{if(o)return'<span class="aparte-skeleton aparte-skeleton--rect aparte-rich-card__fence-wait" aria-hidden="true"></span>';let c=i.slice(Rt.length);return`<${Ue} data-card="${We(c)}" data-source="${We(a)}"></${Ue}>`}},s=[t.registerCodeLanguageRenderer(r)];return s.push(jt(t,i=>{n.has(i)||(n.add(i),s.push(t.registerCodeLanguageRenderer({...r,languages:[`${Rt}${i}`]})))})),()=>{for(let i of s.splice(0))i();Et.delete(t)}}var wa={weather:()=>import("./chunks/weather-5ZNWC2WM.js"),items:()=>import("./chunks/items-GTJKLFZT.js"),product:()=>import("./chunks/product-FNGKWEQP.js"),place:()=>import("./chunks/place-UD2C3U5F.js"),stats:()=>import("./chunks/stats-FGZCRFFK.js"),order:()=>import("./chunks/order-T5L422AO.js"),stock:()=>import("./chunks/stock-E72GAUMB.js"),plan:()=>import("./chunks/plan-JJ3Z64NU.js"),score:()=>import("./chunks/score-3CGZEPWP.js"),media:()=>import("./chunks/media-EOQEOMXK.js"),link:()=>import("./chunks/link-L4C4K5GE.js")},Wn=e=>Kn({config:e,load:wa});var xa='<svg class="aparte-icon" viewBox="0 0 24 24" fill="currentColor"><path d="M5.5 3.5h13a3 3 0 0 1 3 3v8.5a3 3 0 0 1-3 3h-6.2l-4.8 3.6a.6.6 0 0 1-1-.5v-3.1H5.5a3 3 0 0 1-3-3V6.5a3 3 0 0 1 3-3Z"/></svg>',ya='<svg class="aparte-icon" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2.5" stroke-linecap="round" stroke-linejoin="round"><path d="m6 9.5 6 6 6-6"/></svg>',Sa='<svg class="aparte-icon" viewBox="0 0 24 24" fill="currentColor"><path d="M3.4 20.2 21 12.6a.7.7 0 0 0 0-1.2L3.4 3.8a.6.6 0 0 0-.9.7L5 11l8 1-8 1-2.5 6.5a.6.6 0 0 0 .9.7Z"/></svg>',Gn={launcherOpen:()=>xa,launcherClose:()=>ya,send:()=>Sa};var $e={en:{strings:{title:"Hi there! \u{1F44B}",subtitle:"Start a chat. We're here to help you 24/7.",footer:"",getStarted:"New Conversation",inputPlaceholder:"Type your question..",closeButtonTooltip:"Close chat",repostButton:"Repost message",reuseButton:"Reuse message"},initial:["Hi there! \u{1F44B}","My name is Nathan. How can I assist you today?"]},fr:{strings:{title:"Bonjour ! \u{1F44B}",subtitle:"D\xE9marrez une conversation. Nous sommes l\xE0 pour vous aider, 24 h/24.",footer:"",getStarted:"Nouvelle conversation",inputPlaceholder:"Posez votre question\u2026",closeButtonTooltip:"Fermer le chat",repostButton:"Renvoyer le message",reuseButton:"R\xE9utiliser le message"},initial:["Bonjour ! \u{1F44B}","Je m\u2019appelle Nathan. Comment puis-je vous aider ?"],locale:()=>import("./chunks/fr-Z2Y3375Z.js").then(e=>e.fr)},es:{strings:{title:"\xA1Hola! \u{1F44B}",subtitle:"Inicia una conversaci\xF3n. Estamos aqu\xED para ayudarte, 24/7.",footer:"",getStarted:"Nueva conversaci\xF3n",inputPlaceholder:"Escribe tu pregunta\u2026",closeButtonTooltip:"Cerrar el chat",repostButton:"Volver a enviar el mensaje",reuseButton:"Reutilizar el mensaje"},initial:["\xA1Hola! \u{1F44B}","Me llamo Nathan. \xBFEn qu\xE9 puedo ayudarte hoy?"],locale:()=>import("./chunks/es-JUSLSPF7.js").then(e=>e.es)},"pt-BR":{strings:{title:"Ol\xE1! \u{1F44B}",subtitle:"Comece uma conversa. Estamos aqui para ajudar, 24 horas por dia.",footer:"",getStarted:"Nova conversa",inputPlaceholder:"Digite sua pergunta\u2026",closeButtonTooltip:"Fechar o chat",repostButton:"Reenviar a mensagem",reuseButton:"Reutilizar a mensagem"},initial:["Ol\xE1! \u{1F44B}","Meu nome \xE9 Nathan. Como posso ajudar voc\xEA hoje?"],locale:()=>import("./chunks/pt-BR-KMZM3WTU.js").then(e=>e.ptBR)},de:{strings:{title:"Hallo! \u{1F44B}",subtitle:"Starte ein Gespr\xE4ch. Wir sind rund um die Uhr f\xFCr dich da.",footer:"",getStarted:"Neues Gespr\xE4ch",inputPlaceholder:"Stell deine Frage\u2026",closeButtonTooltip:"Chat schlie\xDFen",repostButton:"Nachricht erneut senden",reuseButton:"Nachricht wiederverwenden"},initial:["Hallo! \u{1F44B}","Ich hei\xDFe Nathan. Wie kann ich dir heute helfen?"],locale:()=>import("./chunks/de-M5OVUL5F.js").then(e=>e.de)},it:{strings:{title:"Ciao! \u{1F44B}",subtitle:"Inizia una conversazione. Siamo qui per aiutarti, 24 ore su 24.",footer:"",getStarted:"Nuova conversazione",inputPlaceholder:"Scrivi la tua domanda\u2026",closeButtonTooltip:"Chiudi la chat",repostButton:"Invia di nuovo il messaggio",reuseButton:"Riusa il messaggio"},initial:["Ciao! \u{1F44B}","Mi chiamo Nathan. Come posso aiutarti oggi?"],locale:()=>import("./chunks/it-N53LIIX5.js").then(e=>e.it)},ru:{strings:{title:"\u0417\u0434\u0440\u0430\u0432\u0441\u0442\u0432\u0443\u0439\u0442\u0435! \u{1F44B}",subtitle:"\u041D\u0430\u0447\u043D\u0438\u0442\u0435 \u0440\u0430\u0437\u0433\u043E\u0432\u043E\u0440. \u041C\u044B \u043D\u0430 \u0441\u0432\u044F\u0437\u0438 \u043A\u0440\u0443\u0433\u043B\u043E\u0441\u0443\u0442\u043E\u0447\u043D\u043E.",footer:"",getStarted:"\u041D\u043E\u0432\u044B\u0439 \u0440\u0430\u0437\u0433\u043E\u0432\u043E\u0440",inputPlaceholder:"\u0412\u0432\u0435\u0434\u0438\u0442\u0435 \u0432\u0430\u0448 \u0432\u043E\u043F\u0440\u043E\u0441\u2026",closeButtonTooltip:"\u0417\u0430\u043A\u0440\u044B\u0442\u044C \u0447\u0430\u0442",repostButton:"\u041E\u0442\u043F\u0440\u0430\u0432\u0438\u0442\u044C \u0441\u043E\u043E\u0431\u0449\u0435\u043D\u0438\u0435 \u0435\u0449\u0451 \u0440\u0430\u0437",reuseButton:"\u0418\u0441\u043F\u043E\u043B\u044C\u0437\u043E\u0432\u0430\u0442\u044C \u0441\u043E\u043E\u0431\u0449\u0435\u043D\u0438\u0435 \u0441\u043D\u043E\u0432\u0430"},initial:["\u0417\u0434\u0440\u0430\u0432\u0441\u0442\u0432\u0443\u0439\u0442\u0435! \u{1F44B}","\u041C\u0435\u043D\u044F \u0437\u043E\u0432\u0443\u0442 \u041D\u0430\u0442\u0430\u043D. \u0427\u0435\u043C \u043C\u043E\u0433\u0443 \u043F\u043E\u043C\u043E\u0447\u044C?"],locale:()=>import("./chunks/ru-3AG5HYY2.js").then(e=>e.ru)},ja:{strings:{title:"\u3053\u3093\u306B\u3061\u306F\uFF01\u{1F44B}",subtitle:"\u30C1\u30E3\u30C3\u30C8\u3092\u59CB\u3081\u307E\u3057\u3087\u3046\u300224\u6642\u9593\u3044\u3064\u3067\u3082\u304A\u624B\u4F1D\u3044\u3057\u307E\u3059\u3002",footer:"",getStarted:"\u65B0\u3057\u3044\u4F1A\u8A71",inputPlaceholder:"\u8CEA\u554F\u3092\u5165\u529B\u3057\u3066\u304F\u3060\u3055\u3044\u2026",closeButtonTooltip:"\u30C1\u30E3\u30C3\u30C8\u3092\u9589\u3058\u308B",repostButton:"\u30E1\u30C3\u30BB\u30FC\u30B8\u3092\u518D\u9001\u4FE1",reuseButton:"\u30E1\u30C3\u30BB\u30FC\u30B8\u3092\u518D\u5229\u7528"},initial:["\u3053\u3093\u306B\u3061\u306F\uFF01\u{1F44B}","\u30CD\u30A4\u30B5\u30F3\u3067\u3059\u3002\u4ECA\u65E5\u306F\u3069\u306E\u3088\u3046\u306A\u3054\u7528\u4EF6\u3067\u3057\u3087\u3046\u304B\uFF1F"],locale:()=>import("./chunks/ja-LJHMBKJ4.js").then(e=>e.ja)},ko:{strings:{title:"\uC548\uB155\uD558\uC138\uC694! \u{1F44B}",subtitle:"\uB300\uD654\uB97C \uC2DC\uC791\uD558\uC138\uC694. 24\uC2DC\uAC04 \uC5B8\uC81C\uB4E0 \uB3C4\uC640\uB4DC\uB9B4\uAC8C\uC694.",footer:"",getStarted:"\uC0C8 \uB300\uD654",inputPlaceholder:"\uC9C8\uBB38\uC744 \uC785\uB825\uD558\uC138\uC694\u2026",closeButtonTooltip:"\uCC44\uD305 \uB2EB\uAE30",repostButton:"\uBA54\uC2DC\uC9C0 \uB2E4\uC2DC \uBCF4\uB0B4\uAE30",reuseButton:"\uBA54\uC2DC\uC9C0 \uB2E4\uC2DC \uC0AC\uC6A9"},initial:["\uC548\uB155\uD558\uC138\uC694! \u{1F44B}","\uC800\uB294 \uB124\uC774\uC120\uC785\uB2C8\uB2E4. \uBB34\uC5C7\uC744 \uB3C4\uC640\uB4DC\uB9B4\uAE4C\uC694?"],locale:()=>import("./chunks/ko-XAQOC75B.js").then(e=>e.ko)},"zh-CN":{strings:{title:"\u4F60\u597D\uFF01\u{1F44B}",subtitle:"\u5F00\u59CB\u804A\u5929\u5427\u3002\u6211\u4EEC\u5168\u5929\u5019\u4E3A\u4F60\u670D\u52A1\u3002",footer:"",getStarted:"\u65B0\u5BF9\u8BDD",inputPlaceholder:"\u8F93\u5165\u4F60\u7684\u95EE\u9898\u2026",closeButtonTooltip:"\u5173\u95ED\u804A\u5929",repostButton:"\u91CD\u65B0\u53D1\u9001\u6D88\u606F",reuseButton:"\u91CD\u65B0\u4F7F\u7528\u6D88\u606F"},initial:["\u4F60\u597D\uFF01\u{1F44B}","\u6211\u662F Nathan\u3002\u4ECA\u5929\u6709\u4EC0\u4E48\u53EF\u4EE5\u5E2E\u4F60\u7684\uFF1F"],locale:()=>import("./chunks/zh-CN-DL6ZWLGA.js").then(e=>e.zhCN)}};function vt(e){if($e[e])return e;let t=e.split("-")[0]?.toLowerCase()??"";return Object.keys($e).find(n=>n.split("-")[0]?.toLowerCase()===t)??"en"}function Zn(e,t){return{...$e[vt(e)].strings,...t?.[e]??{}}}function Vn(e){return $e[vt(e)].initial}function Jn(e){return $e[vt(e)].locale?.()}function Ra(e){if(typeof e!="string"||!e.trim())throw new TypeError("[aparte] n8n: createChat needs webhookUrl, the Chat Trigger's production URL, the one that ends in /chat.");try{return new URL(e,typeof document>"u"?void 0:document.baseURI).href}catch{throw new TypeError(`[aparte] n8n: webhookUrl "${e}" is not a URL. Use the Chat Trigger's production URL, the one that ends in /chat.`)}}var He="n8n-chat/sessionId",Qn="N8N_WORKFLOW_ERROR",tr=new WeakMap,Xn=!1;function Ea(){Xn||(Xn=!0,Mt({type:"n8n-component",render:e=>{let{key:t,arguments:n}=e,r=document.createElement("div");return r.className="aparte-segment aparte-n8n__component",r.setAttribute("data-component",t),queueMicrotask(()=>{let s=r.closest("aparte-chat"),i=s?tr.get(s)?.[t]:void 0;if(!i){console.warn(`[aparte] n8n: no messageComponents entry for "${t}".`);return}let a=i(n);typeof a=="string"?r.innerHTML=a:r.replaceChildren(a)}),r}}))}function Yn(e){try{return localStorage.getItem(e)??void 0}catch{return}}function er(e,t){try{localStorage.setItem(e,t)}catch{}}function va(e){if(typeof e!="string")return e;let t=document.querySelector(e);if(t)return t;let n=document.createElement("div");return e.startsWith("#")?n.id=e.slice(1):e.startsWith(".")&&(n.className=e.slice(1)),document.body.appendChild(n),n}function R(e,t,n){let r=document.createElement(e);return t&&(r.className=t),n!==void 0&&(r.textContent=n),r}var $a=0;function Ca(e){let t=Ra(e.webhookUrl),n=e.mode??"window",r=e.defaultLanguage??"en",s=Zn(r,e.i18n),i=e.loadPreviousSession??!0,a=e.initialMessages??Vn(r),o=++$a,c=`aparte-n8n-title-${o}`,l=i&&!e.sessionId&&!!Yn(He),h=e.sessionId??(i?Yn(He):void 0)??oe();i&&!e.sessionId&&er(He,h);let u=new Pt;e.locale&&u.setLocale(e.locale);let d=!1,m=u.getLocale();Jn(r)?.then(p=>{!d&&!e.locale&&u.getLocale()===m&&u.setLocale(p)},p=>console.warn("[aparte] n8n: the chat's language could not be loaded; it stays in English.",p)),u.registerIcons(Gn),e.enableMessageActions&&(u.registerAction({id:"n8n-repost",icon:"retry",label:s.repostButton,zones:["bubble"],bubble:{roles:["user"]}}),u.registerAction({id:"n8n-reuse",icon:"edit",label:s.reuseButton,zones:["bubble"],bubble:{roles:["user"]}})),u.setHostHandlers({attachmentPreview:!0,filePreview:!0}),qn(u);let k=e.cards===!1?void 0:Wn(u);u.setErrorRenderer(({message:p,sentence:g,code:T})=>{let _=T===Qn,D=R("div","aparte-segment aparte-alert aparte-alert--danger aparte-segment-error");T&&D.setAttribute("data-error-code",_?I.PROVIDER_ERROR:T);let ae=R("span","aparte-alert__icon");ae.innerHTML=u.getIcon("error")||"\u26A0";let z=R("div","aparte-alert__body");return z.append(R("div","aparte-alert__title",u.t("error")),R("div","aparte-alert__message",_?u.t("errorNoAnswer"):g??p)),_&&p&&z.append(R("p","aparte-n8n__error-detail",p)),D.append(ae,z),D}),Mn(void 0,u);let v;u.setHighlightProvider(async(p,g)=>(v??=import("./chunks/highlight-ADUWBKTT.js").then(T=>T.createHighlighter()),(await v)(p,g))),m=u.getLocale();let $=e.setup?.(u),x=R("section","aparte-n8n__window");x.setAttribute("aria-labelledby",c);let O=R("header","aparte-n8n__header"),U=R("div","aparte-n8n__heading"),q=R("p","aparte-n8n__title",s.title);if(q.id=c,U.append(q),s.subtitle&&U.append(R("p","aparte-n8n__subtitle",s.subtitle)),O.append(U),n==="window"&&e.showWindowCloseButton){let p=R("button","aparte-btn aparte-btn--icon aparte-btn--ghost aparte-n8n__close");p.type="button",p.setAttribute("aria-label",s.closeButtonTooltip),p.setAttribute("data-aparte-launcher-close","");let g=R("aparte-icon");g.setAttribute("name","close"),p.append(g),O.append(p)}let b=R("aparte-chat","aparte-n8n__chat");b.id=`aparte-n8n-chat-${o}`,e.messageComponents&&(Ea(),tr.set(b,e.messageComponents));let S=R("aparte-composer");S.setAttribute("placeholder",s.inputPlaceholder);let M;e.suggestions?.length&&(M=R("aparte-suggestions"),M.setAttribute("suggestions",JSON.stringify(e.suggestions.map(p=>({label:p,prompt:p})))),S.append(M));let X=R("div","aparte-composer-shell"),ie=R("div","aparte-composer-row");ie.append(R("aparte-composer-input"));let Ce=typeof e.allowFileUploads=="object"?e.allowFileUploads?.value:e.allowFileUploads,pe=typeof e.allowedFilesMimeTypes=="object"?e.allowedFilesMimeTypes?.value:e.allowedFilesMimeTypes;if(Ce){X.append(R("aparte-composer-attachments"));let p=R("aparte-composer-add-attachment");pe&&p.setAttribute("accept",pe),ie.append(p)}ie.append(R("aparte-composer-send")),X.append(ie),S.append(X),b.append(R("aparte-chat-viewport"),R("aparte-elicitation"),S),x.append(O,b),s.footer&&x.append(R("p","aparte-n8n__footer",s.footer));let W;if(e.showWelcomeScreen&&!l){W=R("div","aparte-n8n__welcome");let p=R("button","aparte-btn aparte-btn--primary aparte-btn--solid aparte-n8n__start",s.getStarted);p.type="button",p.addEventListener("click",()=>{W.hidden=!0,b.hidden=!1,b.querySelector("aparte-composer-input")?.focusEnd?.()}),W.append(p),b.hidden=!0,x.insertBefore(W,b)}let C;n==="window"?(C=R("aparte-launcher","aparte-n8n aparte-n8n--window"),C.append(x)):(C=R("div","aparte-n8n aparte-n8n--fullscreen"),C.append(x));let V=e.colorScheme??"light";V!=="auto"&&C.setAttribute("data-aparte-theme",V),C.setAttribute("lang",r),n==="window"&&C.addEventListener("aparte-launcher-toggle",p=>{let{open:g,sheet:T}=p.detail;g&&T?(x.setAttribute("role","dialog"),x.setAttribute("aria-modal","true")):(x.removeAttribute("role"),x.removeAttribute("aria-modal"))}),_t(C,u),va(e.target??"#n8n-chat").append(C);let de=()=>a.map((p,g)=>({id:`n8n-initial-${g}`,role:"assistant",content:p,timestamp:Date.now()-a.length+g,status:"completed"})),fe=()=>(e.messageHistory??[]).map((p,g)=>{let T={id:`n8n-seed-${g}`,role:p.sender==="user"?"user":"assistant",timestamp:Date.now(),status:"completed"};if(p.type==="component"){let _={id:`n8n-seed-${g}-component`,type:"n8n-component",key:p.key,arguments:p.arguments??{}};return{...T,content:"",segments:[_]}}return{...T,content:p.text}}),Y=new Set((e.messageHistory??[]).flatMap((p,g)=>p.transparent?[`n8n-seed-${g}`]:[]));Y.size&&new MutationObserver(()=>{for(let p of Y){let g=b.querySelector(`aparte-chat-bubble[message-id="${p}"]`);g&&!g.hasAttribute("data-n8n-transparent")&&g.setAttribute("data-n8n-transparent","")}}).observe(b,{childList:!0,subtree:!0});let ee=p=>b.viewport?.setMessages(p);ee([...de(),...fe()]),e.messageHistory?.length&&M&&(M.hidden=!0);let te=0,J,f=()=>{let p=++te;J=new AbortController,Fn({webhookUrl:t,sessionId:h,...e.metadata?{metadata:e.metadata}:{},...e.chatSessionKey?{chatSessionKey:e.chatSessionKey}:{},headers:()=>({...e.webhookConfig?.headers??{}}),...e.fetch?{fetch:e.fetch}:{},signal:J.signal}).then(g=>{p!==te||g.length===0||(M&&(M.hidden=!0),ee([...de(),...g]))},g=>{J?.signal.aborted||console.warn(`[aparte] n8n: ${g instanceof Error?g.message:String(g)}`)})};if(i)if(n==="window"){let p=g=>{g.detail.open&&(C.removeEventListener("aparte-launcher-toggle",p),te===0&&f())};C.addEventListener("aparte-launcher-toggle",p)}else f();let A="",G=h,xe=!1,ye=[];b.addEventListener("aparte-send",p=>{te++,A=String(p.detail?.content??""),G=h,M&&(M.hidden=!0)});let qe=(p,g)=>{W&&!W.hidden&&(W.hidden=!0,b.hidden=!1),b.dispatchEvent(new CustomEvent("aparte-send",{detail:{content:p,timestamp:Date.now(),targetId:b.id,...g?.length?{files:g}:{}},bubbles:!0,composed:!0}))},$t=()=>{xe=!1;let p=ye.shift();p!==void 0&&queueMicrotask(()=>qe(p))};b.addEventListener("aparte-message-start",()=>{xe=!0});for(let p of["aparte-message-done","aparte-message-error","aparte-message-aborted"])b.addEventListener(p,$t);let Ct=p=>{p.detail?.targetId===b.id&&$t()};window.addEventListener("aparte-message-aborted",Ct);let Tt=h,nr=jn({webhookUrl:t,sessionId:()=>Tt,headers:()=>({...e.webhookConfig?.headers??{}}),...e.fetch?{fetch:e.fetch}:{},...e.metadata?{metadata:e.metadata}:{},...e.chatInputKey?{chatInputKey:e.chatInputKey}:{},...e.chatSessionKey?{chatSessionKey:e.chatSessionKey}:{}}),rr=async p=>{let g=A,T=G;if(await e.beforeMessageSent?.(g),p.signal.aborted)return;Tt=T;let _="",D=!1,ae=await nr({...p,emitter:z=>{z.type==="text-delta"&&(_+=z.delta),z.type==="run-done"&&(D=!0),p.emitter(z)}}).catch(z=>{let ge=z;throw ge?.code===I.PROVIDER_ERROR&&ge.httpStatus===void 0?new L(ge.message??"",Qn,ge.data,z):z});if(D&&e.afterMessageSent){let z=e.afterMessageSent;queueMicrotask(()=>{Promise.resolve().then(()=>z(g,{output:_,message:_,hasReceivedChunks:_.length>0})).catch(ge=>console.warn("[aparte] n8n: afterMessageSent threw:",ge))})}return ae},je=new Bt({config:u,streamRunner:rr,rawFileInject:"none",scopeToTargetId:b.id});je.start();let It=()=>b.viewport,sr=p=>{let{actionId:g,messageId:T}=p.detail;if(g!=="n8n-repost"&&g!=="n8n-reuse")return;let _=It()?.getMessage?.(T);if(_){if(g==="n8n-reuse"){S.setValue(_.content??""),b.querySelector("aparte-composer-input")?.focusEnd?.();return}Promise.all((_.attachments??[]).map(async D=>{let ae=await(await fetch(D.url)).blob();return new File([ae],D.name,{type:D.type||ae.type})})).then(D=>{xe?ye.push(_.content??""):qe(_.content??"",D)},D=>console.warn("[aparte] n8n: a file of that message could not be read again:",D))}};b.addEventListener("aparte-action",sr);let Q=-1,Fe="",ir=()=>b.querySelector("aparte-composer-input");S.addEventListener("keydown",p=>{if(p.key!=="ArrowUp"&&p.key!=="ArrowDown"||p.altKey||p.ctrlKey||p.metaKey||p.shiftKey||p.isComposing||!p.target?.closest("aparte-composer-input"))return;let g=(It()?.getMessages?.()??[]).filter(T=>T.role==="user"&&T.content?.trim()).map(T=>T.content??"");if(p.key==="ArrowUp"){if(Q===-1&&S.value!==""||Q>=g.length-1)return;Q===-1&&(Fe=S.value),Q++}else{if(Q===-1)return;Q--}p.preventDefault(),S.setValue(Q===-1?Fe:g[g.length-1-Q]??""),ir()?.focusEnd?.()}),b.addEventListener("aparte-send",()=>{Q=-1,Fe=""}),b.addEventListener("click",p=>{if(p.defaultPrevented||p.button!==0||p.metaKey||p.ctrlKey||p.shiftKey||p.altKey)return;let g=p.target?.closest(".aparte-message-content a[href]");!g||g.getAttribute("href")?.startsWith("#")||(p.preventDefault(),window.open(g.href,"_blank","noopener"))}),b.addEventListener("aparte-attachment-preview",p=>{let{url:g}=p.detail;g&&window.open(g,"_blank","noopener")});let At=p=>S.toggleAttribute("disabled",p);(typeof e.disabled=="object"?e.disabled?.value:e.disabled)&&At(!0);let Ke=()=>n==="window"?C:void 0,Ot=()=>{d||(d=!0,J?.abort(),ye.length=0,window.removeEventListener("aparte-message-aborted",Ct),je.stop(),k?.(),typeof $=="function"&&$(),C.remove())};return{element:C,get sessionId(){return h},open:()=>Ke()?.show(),close:()=>Ke()?.close(),toggle:()=>Ke()?.toggle(),send:p=>{xe?ye.push(p):qe(p)},reset:()=>{ye.length=0,S.streaming&&S.cancel(),je.abort(),xe=!1,J?.abort(),te++,h=e.sessionId??oe(),i&&!e.sessionId&&er(He,h),M&&(M.hidden=!1),ee(de())},setDisabled:At,destroy:Ot,unmount:Ot}}export{Ca as createChat,Ft as defineCard,Dt as el,Gt as formatDay,Kt as formatNumber,Wt as formatPrice,Zt as formatWhen,zt as glyph,Ut as safeUrl,Ht as webUrl};
102
+ `):""}function da(e,{now:t=Date.now()}={}){let n=[];return e.forEach((r,s)=>{if(typeof r!="object"||r===null)return;let i=r,a=pa(i),o=/^Human/.test(a)||a==="human"?"user":/^AI/.test(a)||a==="ai"?"assistant":void 0;if(!o)return;let c=ha(i.kwargs?.content);c.trim()&&n.push({id:`n8n-${s}`,role:o,content:c,timestamp:t-(e.length-s),status:"completed"})}),n}async function Fn(e){let t=e.fetch??fetch,n=typeof e.headers=="function"?await e.headers():e.headers??{},r={"Content-Type":"application/json"};for(let[o,c]of Object.entries(n))o.toLowerCase()!=="content-type"&&(r[o]=c);let s=await t(e.webhookUrl,{method:"POST",headers:r,body:JSON.stringify({action:"loadPreviousSession",[e.chatSessionKey??"sessionId"]:e.sessionId,...e.metadata?{metadata:e.metadata}:{}}),...e.signal?{signal:e.signal}:{},...e.credentials?{credentials:e.credentials}:{}}).catch(o=>{throw yt(o,e.webhookUrl)});if(!s.ok)throw await xt(s,"history");let i;try{i=await s.json()}catch{throw new L("n8n answered the history request with something that is not JSON. Check that the URL is the Chat Trigger's production URL.",I.PROVIDER_MISCONFIGURED)}let a=typeof i=="object"&&i!==null?i.data:void 0;return da(Array.isArray(a)?a:[])}var Rt="card-",fa=["weather","items","product","place","stats","order","stock","plan","score","media","link"],Ue="aparte-card-fence",Et=new WeakMap,ga=e=>`setup${e.charAt(0).toUpperCase()}${e.slice(1)}Card`;function ma(e,t){let n=Et.get(e),r=n?.load[t];if(!n||!r)return Promise.resolve(!1);let s=n.pending.get(t);return s||(s=r().then(i=>{let a=i[ga(t)];return typeof a!="function"?!1:(a({config:e}),!0)},i=>(console.warn(`[aparte-cards] the ${t} card could not be loaded; its fence shows its source.`,i),!1)),n.pending.set(t,s)),s}function ka(e,t){let n=0;for(let r=0;r<t.length;r++)n=Math.imul(31,n)+t.charCodeAt(r)|0;return`fence-${e}-${(n>>>0).toString(36)}`}async function ba(e){let t=e.getAttribute("data-card")??"",n=e.getAttribute("data-source")??"",r=Lt(e),s=()=>{let l=document.createElement("code");l.className="aparte-code-error",l.textContent=n,e.replaceChildren(l)},i;try{i=JSON.parse(n)}catch{s();return}let a=i&&typeof i=="object"&&typeof i.variant=="string"?i.variant:void 0,o={id:ka(t,n),type:"card",card:t,data:i,...a?{variant:a}:{}},c=Ge(r,o);!c&&await ma(r,t)&&e.isConnected&&(c=Ge(r,o)),c?e.replaceChildren(c):s()}function wa(){typeof customElements>"u"||typeof HTMLElement>"u"||customElements.get(Ue)||customElements.define(Ue,class extends HTMLElement{connectedCallback(){this.hasAttribute("data-drawn")||(this.setAttribute("data-drawn",""),ba(this))}})}function Kn(e={}){let t=e.config??me;e.load&&Et.set(t,{load:e.load,pending:new Map}),wa();let n=new Set([...fa,...jt(t),...Object.keys(e.load??{})]),r={languages:[...n].map(i=>`${Rt}${i}`),bare:!0,render:({language:i,source:a,open:o})=>{if(o)return'<span class="aparte-skeleton aparte-skeleton--rect aparte-rich-card__fence-wait" aria-hidden="true"></span>';let c=i.slice(Rt.length);return`<${Ue} data-card="${We(c)}" data-source="${We(a)}"></${Ue}>`}},s=[t.registerCodeLanguageRenderer(r)];return s.push(qt(t,i=>{n.has(i)||(n.add(i),s.push(t.registerCodeLanguageRenderer({...r,languages:[`${Rt}${i}`]})))})),()=>{for(let i of s.splice(0))i();Et.delete(t)}}var xa={weather:()=>import("./chunks/weather-NQGN2JOS.js"),items:()=>import("./chunks/items-MITCIPF3.js"),product:()=>import("./chunks/product-ONQRJRDO.js"),place:()=>import("./chunks/place-KQ3IA5IV.js"),stats:()=>import("./chunks/stats-2W3GFI4P.js"),order:()=>import("./chunks/order-CPY2L7MI.js"),stock:()=>import("./chunks/stock-RCVJOOH4.js"),plan:()=>import("./chunks/plan-OKXEPKPV.js"),score:()=>import("./chunks/score-QF27XJUE.js"),media:()=>import("./chunks/media-7CZBXNEK.js"),link:()=>import("./chunks/link-7JYKZK3A.js")},Wn=e=>`setup${e.charAt(0).toUpperCase()}${e.slice(1)}Card`;function Gn(e,t={}){let n=Object.fromEntries(Object.entries(xa).map(([r,s])=>{let i=t[r];return i?[r,()=>s().then(a=>{let o=a[Wn(r)];return typeof o=="function"?{...a,[Wn(r)]:c=>o({...i,...c})}:a})]:[r,s]}));return Kn({config:e,load:n})}var ya='<svg class="aparte-icon" viewBox="0 0 24 24" fill="currentColor"><path d="M5.5 3.5h13a3 3 0 0 1 3 3v8.5a3 3 0 0 1-3 3h-6.2l-4.8 3.6a.6.6 0 0 1-1-.5v-3.1H5.5a3 3 0 0 1-3-3V6.5a3 3 0 0 1 3-3Z"/></svg>',Sa='<svg class="aparte-icon" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2.5" stroke-linecap="round" stroke-linejoin="round"><path d="m6 9.5 6 6 6-6"/></svg>',Ra='<svg class="aparte-icon" viewBox="0 0 24 24" fill="currentColor"><path d="M3.4 20.2 21 12.6a.7.7 0 0 0 0-1.2L3.4 3.8a.6.6 0 0 0-.9.7L5 11l8 1-8 1-2.5 6.5a.6.6 0 0 0 .9.7Z"/></svg>',Zn={launcherOpen:()=>ya,launcherClose:()=>Sa,send:()=>Ra};var $e={en:{strings:{title:"Hi there! \u{1F44B}",subtitle:"Start a chat. We're here to help you 24/7.",footer:"",getStarted:"New Conversation",inputPlaceholder:"Type your question..",closeButtonTooltip:"Close chat",repostButton:"Repost message",reuseButton:"Reuse message"},initial:["Hi there! \u{1F44B}","My name is Nathan. How can I assist you today?"]},fr:{strings:{title:"Bonjour ! \u{1F44B}",subtitle:"D\xE9marrez une conversation. Nous sommes l\xE0 pour vous aider, 24 h/24.",footer:"",getStarted:"Nouvelle conversation",inputPlaceholder:"Posez votre question\u2026",closeButtonTooltip:"Fermer le chat",repostButton:"Renvoyer le message",reuseButton:"R\xE9utiliser le message"},initial:["Bonjour ! \u{1F44B}","Je m\u2019appelle Nathan. Comment puis-je vous aider ?"],locale:()=>import("./chunks/fr-ZKACSOY5.js").then(e=>e.fr)},es:{strings:{title:"\xA1Hola! \u{1F44B}",subtitle:"Inicia una conversaci\xF3n. Estamos aqu\xED para ayudarte, 24/7.",footer:"",getStarted:"Nueva conversaci\xF3n",inputPlaceholder:"Escribe tu pregunta\u2026",closeButtonTooltip:"Cerrar el chat",repostButton:"Volver a enviar el mensaje",reuseButton:"Reutilizar el mensaje"},initial:["\xA1Hola! \u{1F44B}","Me llamo Nathan. \xBFEn qu\xE9 puedo ayudarte hoy?"],locale:()=>import("./chunks/es-72JNODLG.js").then(e=>e.es)},"pt-BR":{strings:{title:"Ol\xE1! \u{1F44B}",subtitle:"Comece uma conversa. Estamos aqui para ajudar, 24 horas por dia.",footer:"",getStarted:"Nova conversa",inputPlaceholder:"Digite sua pergunta\u2026",closeButtonTooltip:"Fechar o chat",repostButton:"Reenviar a mensagem",reuseButton:"Reutilizar a mensagem"},initial:["Ol\xE1! \u{1F44B}","Meu nome \xE9 Nathan. Como posso ajudar voc\xEA hoje?"],locale:()=>import("./chunks/pt-BR-73MNA3YX.js").then(e=>e.ptBR)},de:{strings:{title:"Hallo! \u{1F44B}",subtitle:"Starte ein Gespr\xE4ch. Wir sind rund um die Uhr f\xFCr dich da.",footer:"",getStarted:"Neues Gespr\xE4ch",inputPlaceholder:"Stell deine Frage\u2026",closeButtonTooltip:"Chat schlie\xDFen",repostButton:"Nachricht erneut senden",reuseButton:"Nachricht wiederverwenden"},initial:["Hallo! \u{1F44B}","Ich hei\xDFe Nathan. Wie kann ich dir heute helfen?"],locale:()=>import("./chunks/de-BCWJVDW5.js").then(e=>e.de)},it:{strings:{title:"Ciao! \u{1F44B}",subtitle:"Inizia una conversazione. Siamo qui per aiutarti, 24 ore su 24.",footer:"",getStarted:"Nuova conversazione",inputPlaceholder:"Scrivi la tua domanda\u2026",closeButtonTooltip:"Chiudi la chat",repostButton:"Invia di nuovo il messaggio",reuseButton:"Riusa il messaggio"},initial:["Ciao! \u{1F44B}","Mi chiamo Nathan. Come posso aiutarti oggi?"],locale:()=>import("./chunks/it-SSBBMSGX.js").then(e=>e.it)},ru:{strings:{title:"\u0417\u0434\u0440\u0430\u0432\u0441\u0442\u0432\u0443\u0439\u0442\u0435! \u{1F44B}",subtitle:"\u041D\u0430\u0447\u043D\u0438\u0442\u0435 \u0440\u0430\u0437\u0433\u043E\u0432\u043E\u0440. \u041C\u044B \u043D\u0430 \u0441\u0432\u044F\u0437\u0438 \u043A\u0440\u0443\u0433\u043B\u043E\u0441\u0443\u0442\u043E\u0447\u043D\u043E.",footer:"",getStarted:"\u041D\u043E\u0432\u044B\u0439 \u0440\u0430\u0437\u0433\u043E\u0432\u043E\u0440",inputPlaceholder:"\u0412\u0432\u0435\u0434\u0438\u0442\u0435 \u0432\u0430\u0448 \u0432\u043E\u043F\u0440\u043E\u0441\u2026",closeButtonTooltip:"\u0417\u0430\u043A\u0440\u044B\u0442\u044C \u0447\u0430\u0442",repostButton:"\u041E\u0442\u043F\u0440\u0430\u0432\u0438\u0442\u044C \u0441\u043E\u043E\u0431\u0449\u0435\u043D\u0438\u0435 \u0435\u0449\u0451 \u0440\u0430\u0437",reuseButton:"\u0418\u0441\u043F\u043E\u043B\u044C\u0437\u043E\u0432\u0430\u0442\u044C \u0441\u043E\u043E\u0431\u0449\u0435\u043D\u0438\u0435 \u0441\u043D\u043E\u0432\u0430"},initial:["\u0417\u0434\u0440\u0430\u0432\u0441\u0442\u0432\u0443\u0439\u0442\u0435! \u{1F44B}","\u041C\u0435\u043D\u044F \u0437\u043E\u0432\u0443\u0442 \u041D\u0430\u0442\u0430\u043D. \u0427\u0435\u043C \u043C\u043E\u0433\u0443 \u043F\u043E\u043C\u043E\u0447\u044C?"],locale:()=>import("./chunks/ru-SCEGVTR4.js").then(e=>e.ru)},ja:{strings:{title:"\u3053\u3093\u306B\u3061\u306F\uFF01\u{1F44B}",subtitle:"\u30C1\u30E3\u30C3\u30C8\u3092\u59CB\u3081\u307E\u3057\u3087\u3046\u300224\u6642\u9593\u3044\u3064\u3067\u3082\u304A\u624B\u4F1D\u3044\u3057\u307E\u3059\u3002",footer:"",getStarted:"\u65B0\u3057\u3044\u4F1A\u8A71",inputPlaceholder:"\u8CEA\u554F\u3092\u5165\u529B\u3057\u3066\u304F\u3060\u3055\u3044\u2026",closeButtonTooltip:"\u30C1\u30E3\u30C3\u30C8\u3092\u9589\u3058\u308B",repostButton:"\u30E1\u30C3\u30BB\u30FC\u30B8\u3092\u518D\u9001\u4FE1",reuseButton:"\u30E1\u30C3\u30BB\u30FC\u30B8\u3092\u518D\u5229\u7528"},initial:["\u3053\u3093\u306B\u3061\u306F\uFF01\u{1F44B}","\u30CD\u30A4\u30B5\u30F3\u3067\u3059\u3002\u4ECA\u65E5\u306F\u3069\u306E\u3088\u3046\u306A\u3054\u7528\u4EF6\u3067\u3057\u3087\u3046\u304B\uFF1F"],locale:()=>import("./chunks/ja-NCV4Z63H.js").then(e=>e.ja)},ko:{strings:{title:"\uC548\uB155\uD558\uC138\uC694! \u{1F44B}",subtitle:"\uB300\uD654\uB97C \uC2DC\uC791\uD558\uC138\uC694. 24\uC2DC\uAC04 \uC5B8\uC81C\uB4E0 \uB3C4\uC640\uB4DC\uB9B4\uAC8C\uC694.",footer:"",getStarted:"\uC0C8 \uB300\uD654",inputPlaceholder:"\uC9C8\uBB38\uC744 \uC785\uB825\uD558\uC138\uC694\u2026",closeButtonTooltip:"\uCC44\uD305 \uB2EB\uAE30",repostButton:"\uBA54\uC2DC\uC9C0 \uB2E4\uC2DC \uBCF4\uB0B4\uAE30",reuseButton:"\uBA54\uC2DC\uC9C0 \uB2E4\uC2DC \uC0AC\uC6A9"},initial:["\uC548\uB155\uD558\uC138\uC694! \u{1F44B}","\uC800\uB294 \uB124\uC774\uC120\uC785\uB2C8\uB2E4. \uBB34\uC5C7\uC744 \uB3C4\uC640\uB4DC\uB9B4\uAE4C\uC694?"],locale:()=>import("./chunks/ko-VCNS24WV.js").then(e=>e.ko)},"zh-CN":{strings:{title:"\u4F60\u597D\uFF01\u{1F44B}",subtitle:"\u5F00\u59CB\u804A\u5929\u5427\u3002\u6211\u4EEC\u5168\u5929\u5019\u4E3A\u4F60\u670D\u52A1\u3002",footer:"",getStarted:"\u65B0\u5BF9\u8BDD",inputPlaceholder:"\u8F93\u5165\u4F60\u7684\u95EE\u9898\u2026",closeButtonTooltip:"\u5173\u95ED\u804A\u5929",repostButton:"\u91CD\u65B0\u53D1\u9001\u6D88\u606F",reuseButton:"\u91CD\u65B0\u4F7F\u7528\u6D88\u606F"},initial:["\u4F60\u597D\uFF01\u{1F44B}","\u6211\u662F Nathan\u3002\u4ECA\u5929\u6709\u4EC0\u4E48\u53EF\u4EE5\u5E2E\u4F60\u7684\uFF1F"],locale:()=>import("./chunks/zh-CN-4K6QPBRT.js").then(e=>e.zhCN)}};function vt(e){if($e[e])return e;let t=e.split("-")[0]?.toLowerCase()??"";return Object.keys($e).find(n=>n.split("-")[0]?.toLowerCase()===t)??"en"}function Vn(e,t){return{...$e[vt(e)].strings,...t?.[e]??{}}}function Jn(e){return $e[vt(e)].initial}function Qn(e){return $e[vt(e)].locale?.()}function Ea(e){if(typeof e!="string"||!e.trim())throw new TypeError("[aparte] n8n: createChat needs webhookUrl, the Chat Trigger's production URL, the one that ends in /chat.");try{return new URL(e,typeof document>"u"?void 0:document.baseURI).href}catch{throw new TypeError(`[aparte] n8n: webhookUrl "${e}" is not a URL. Use the Chat Trigger's production URL, the one that ends in /chat.`)}}var He="n8n-chat/sessionId",Xn="N8N_WORKFLOW_ERROR",nr=new WeakMap,Yn=!1;function va(){Yn||(Yn=!0,Mt({type:"n8n-component",render:e=>{let{key:t,arguments:n}=e,r=document.createElement("div");return r.className="aparte-segment aparte-n8n__component",r.setAttribute("data-component",t),queueMicrotask(()=>{let s=r.closest("aparte-chat"),i=s?nr.get(s)?.[t]:void 0;if(!i){console.warn(`[aparte] n8n: no messageComponents entry for "${t}".`);return}let a=i(n);typeof a=="string"?r.innerHTML=a:r.replaceChildren(a)}),r}}))}function er(e){try{return localStorage.getItem(e)??void 0}catch{return}}function tr(e,t){try{localStorage.setItem(e,t)}catch{}}function $a(e){if(typeof e!="string")return e;let t=document.querySelector(e);if(t)return t;let n=document.createElement("div");return e.startsWith("#")?n.id=e.slice(1):e.startsWith(".")&&(n.className=e.slice(1)),document.body.appendChild(n),n}function R(e,t,n){let r=document.createElement(e);return t&&(r.className=t),n!==void 0&&(r.textContent=n),r}var Ca=0;function Ta(e){let t=Ea(e.webhookUrl),n=e.mode??"window",r=e.defaultLanguage??"en",s=Vn(r,e.i18n),i=e.loadPreviousSession??!0,a=e.initialMessages??Jn(r),o=++Ca,c=`aparte-n8n-title-${o}`,l=i&&!e.sessionId&&!!er(He),p=e.sessionId??(i?er(He):void 0)??oe();i&&!e.sessionId&&tr(He,p);let u=new Pt;e.locale&&u.setLocale(e.locale);let d=!1,m=u.getLocale();Qn(r)?.then(h=>{!d&&!e.locale&&u.getLocale()===m&&u.setLocale(h)},h=>console.warn("[aparte] n8n: the chat's language could not be loaded; it stays in English.",h)),u.registerIcons(Zn),e.enableMessageActions&&(u.registerAction({id:"n8n-repost",icon:"retry",label:s.repostButton,zones:["bubble"],bubble:{roles:["user"]}}),u.registerAction({id:"n8n-reuse",icon:"edit",label:s.reuseButton,zones:["bubble"],bubble:{roles:["user"]}})),u.setHostHandlers({attachmentPreview:!0,filePreview:!0}),jn(u);let k=e.cards===!1?void 0:Gn(u,typeof e.cards=="object"?e.cards:{});u.setErrorRenderer(({message:h,sentence:g,code:T})=>{let _=T===Xn,D=R("div","aparte-segment aparte-alert aparte-alert--danger aparte-segment-error");T&&D.setAttribute("data-error-code",_?I.PROVIDER_ERROR:T);let ae=R("span","aparte-alert__icon");ae.innerHTML=u.getIcon("error")||"\u26A0";let z=R("div","aparte-alert__body");return z.append(R("div","aparte-alert__title",u.t("error")),R("div","aparte-alert__message",_?u.t("errorNoAnswer"):g??h)),_&&h&&z.append(R("p","aparte-n8n__error-detail",h)),D.append(ae,z),D}),Mn(void 0,u);let v;u.setHighlightProvider(async(h,g)=>(v??=import("./chunks/highlight-DG2OVLBT.js").then(T=>T.createHighlighter()),(await v)(h,g))),m=u.getLocale();let $=e.setup?.(u),x=R("section","aparte-n8n__window");x.setAttribute("aria-labelledby",c);let O=R("header","aparte-n8n__header"),U=R("div","aparte-n8n__heading"),j=R("p","aparte-n8n__title",s.title);if(j.id=c,U.append(j),s.subtitle&&U.append(R("p","aparte-n8n__subtitle",s.subtitle)),O.append(U),n==="window"&&e.showWindowCloseButton){let h=R("button","aparte-btn aparte-btn--icon aparte-btn--ghost aparte-n8n__close");h.type="button",h.setAttribute("aria-label",s.closeButtonTooltip),h.setAttribute("data-aparte-launcher-close","");let g=R("aparte-icon");g.setAttribute("name","close"),h.append(g),O.append(h)}let b=R("aparte-chat","aparte-n8n__chat");b.id=`aparte-n8n-chat-${o}`,e.messageComponents&&(va(),nr.set(b,e.messageComponents));let S=R("aparte-composer");S.setAttribute("placeholder",s.inputPlaceholder);let M;e.suggestions?.length&&(M=R("aparte-suggestions"),M.setAttribute("suggestions",JSON.stringify(e.suggestions.map(h=>({label:h,prompt:h})))),S.append(M));let X=R("div","aparte-composer-shell"),ie=R("div","aparte-composer-row");ie.append(R("aparte-composer-input"));let Ce=typeof e.allowFileUploads=="object"?e.allowFileUploads?.value:e.allowFileUploads,he=typeof e.allowedFilesMimeTypes=="object"?e.allowedFilesMimeTypes?.value:e.allowedFilesMimeTypes;if(Ce){X.append(R("aparte-composer-attachments"));let h=R("aparte-composer-add-attachment");he&&h.setAttribute("accept",he),ie.append(h)}ie.append(R("aparte-composer-send")),X.append(ie),S.append(X),b.append(R("aparte-chat-viewport"),R("aparte-elicitation"),S),x.append(O,b),s.footer&&x.append(R("p","aparte-n8n__footer",s.footer));let W;if(e.showWelcomeScreen&&!l){W=R("div","aparte-n8n__welcome");let h=R("button","aparte-btn aparte-btn--primary aparte-btn--solid aparte-n8n__start",s.getStarted);h.type="button",h.addEventListener("click",()=>{W.hidden=!0,b.hidden=!1,b.querySelector("aparte-composer-input")?.focusEnd?.()}),W.append(h),b.hidden=!0,x.insertBefore(W,b)}let C;n==="window"?(C=R("aparte-launcher","aparte-n8n aparte-n8n--window"),C.append(x)):(C=R("div","aparte-n8n aparte-n8n--fullscreen"),C.append(x));let V=e.colorScheme??"light";V!=="auto"&&C.setAttribute("data-aparte-theme",V),C.setAttribute("lang",r),n==="window"&&C.addEventListener("aparte-launcher-toggle",h=>{let{open:g,sheet:T}=h.detail;g&&T?(x.setAttribute("role","dialog"),x.setAttribute("aria-modal","true")):(x.removeAttribute("role"),x.removeAttribute("aria-modal"))}),_t(C,u),$a(e.target??"#n8n-chat").append(C);let de=()=>a.map((h,g)=>({id:`n8n-initial-${g}`,role:"assistant",content:h,timestamp:Date.now()-a.length+g,status:"completed"})),fe=()=>(e.messageHistory??[]).map((h,g)=>{let T={id:`n8n-seed-${g}`,role:h.sender==="user"?"user":"assistant",timestamp:Date.now(),status:"completed"};if(h.type==="component"){let _={id:`n8n-seed-${g}-component`,type:"n8n-component",key:h.key,arguments:h.arguments??{}};return{...T,content:"",segments:[_]}}return{...T,content:h.text}}),Y=new Set((e.messageHistory??[]).flatMap((h,g)=>h.transparent?[`n8n-seed-${g}`]:[]));Y.size&&new MutationObserver(()=>{for(let h of Y){let g=b.querySelector(`aparte-chat-bubble[message-id="${h}"]`);g&&!g.hasAttribute("data-n8n-transparent")&&g.setAttribute("data-n8n-transparent","")}}).observe(b,{childList:!0,subtree:!0});let ee=h=>b.viewport?.setMessages(h);ee([...de(),...fe()]),e.messageHistory?.length&&M&&(M.hidden=!0);let te=0,J,f=()=>{let h=++te;J=new AbortController,Fn({webhookUrl:t,sessionId:p,...e.metadata?{metadata:e.metadata}:{},...e.chatSessionKey?{chatSessionKey:e.chatSessionKey}:{},headers:()=>({...e.webhookConfig?.headers??{}}),...e.fetch?{fetch:e.fetch}:{},signal:J.signal}).then(g=>{h!==te||g.length===0||(M&&(M.hidden=!0),ee([...de(),...g]))},g=>{J?.signal.aborted||console.warn(`[aparte] n8n: ${g instanceof Error?g.message:String(g)}`)})};if(i)if(n==="window"){let h=g=>{g.detail.open&&(C.removeEventListener("aparte-launcher-toggle",h),te===0&&f())};C.addEventListener("aparte-launcher-toggle",h)}else f();let A="",G=p,xe=!1,ye=[];b.addEventListener("aparte-send",h=>{te++,A=String(h.detail?.content??""),G=p,M&&(M.hidden=!0)});let je=(h,g)=>{W&&!W.hidden&&(W.hidden=!0,b.hidden=!1),b.dispatchEvent(new CustomEvent("aparte-send",{detail:{content:h,timestamp:Date.now(),targetId:b.id,...g?.length?{files:g}:{}},bubbles:!0,composed:!0}))},$t=()=>{xe=!1;let h=ye.shift();h!==void 0&&queueMicrotask(()=>je(h))};b.addEventListener("aparte-message-start",()=>{xe=!0});for(let h of["aparte-message-done","aparte-message-error","aparte-message-aborted"])b.addEventListener(h,$t);let Ct=h=>{h.detail?.targetId===b.id&&$t()};window.addEventListener("aparte-message-aborted",Ct);let Tt=p,rr=qn({webhookUrl:t,sessionId:()=>Tt,headers:()=>({...e.webhookConfig?.headers??{}}),...e.fetch?{fetch:e.fetch}:{},...e.metadata?{metadata:e.metadata}:{},...e.chatInputKey?{chatInputKey:e.chatInputKey}:{},...e.chatSessionKey?{chatSessionKey:e.chatSessionKey}:{}}),sr=async h=>{let g=A,T=G;if(await e.beforeMessageSent?.(g),h.signal.aborted)return;Tt=T;let _="",D=!1,ae=await rr({...h,emitter:z=>{z.type==="text-delta"&&(_+=z.delta),z.type==="run-done"&&(D=!0),h.emitter(z)}}).catch(z=>{let ge=z;throw ge?.code===I.PROVIDER_ERROR&&ge.httpStatus===void 0?new L(ge.message??"",Xn,ge.data,z):z});if(D&&e.afterMessageSent){let z=e.afterMessageSent;queueMicrotask(()=>{Promise.resolve().then(()=>z(g,{output:_,message:_,hasReceivedChunks:_.length>0})).catch(ge=>console.warn("[aparte] n8n: afterMessageSent threw:",ge))})}return ae},qe=new Bt({config:u,streamRunner:sr,rawFileInject:"none",scopeToTargetId:b.id});qe.start();let It=()=>b.viewport,ir=h=>{let{actionId:g,messageId:T}=h.detail;if(g!=="n8n-repost"&&g!=="n8n-reuse")return;let _=It()?.getMessage?.(T);if(_){if(g==="n8n-reuse"){S.setValue(_.content??""),b.querySelector("aparte-composer-input")?.focusEnd?.();return}Promise.all((_.attachments??[]).map(async D=>{let ae=await(await fetch(D.url)).blob();return new File([ae],D.name,{type:D.type||ae.type})})).then(D=>{xe?ye.push(_.content??""):je(_.content??"",D)},D=>console.warn("[aparte] n8n: a file of that message could not be read again:",D))}};b.addEventListener("aparte-action",ir);let Q=-1,Fe="",ar=()=>b.querySelector("aparte-composer-input");S.addEventListener("keydown",h=>{if(h.key!=="ArrowUp"&&h.key!=="ArrowDown"||h.altKey||h.ctrlKey||h.metaKey||h.shiftKey||h.isComposing||!h.target?.closest("aparte-composer-input"))return;let g=(It()?.getMessages?.()??[]).filter(T=>T.role==="user"&&T.content?.trim()).map(T=>T.content??"");if(h.key==="ArrowUp"){if(Q===-1&&S.value!==""||Q>=g.length-1)return;Q===-1&&(Fe=S.value),Q++}else{if(Q===-1)return;Q--}h.preventDefault(),S.setValue(Q===-1?Fe:g[g.length-1-Q]??""),ar()?.focusEnd?.()}),b.addEventListener("aparte-send",()=>{Q=-1,Fe=""}),b.addEventListener("click",h=>{if(h.defaultPrevented||h.button!==0||h.metaKey||h.ctrlKey||h.shiftKey||h.altKey)return;let g=h.target?.closest(".aparte-message-content a[href]");!g||g.getAttribute("href")?.startsWith("#")||(h.preventDefault(),window.open(g.href,"_blank","noopener"))}),b.addEventListener("aparte-attachment-preview",h=>{let{url:g}=h.detail;g&&window.open(g,"_blank","noopener")});let At=h=>S.toggleAttribute("disabled",h);(typeof e.disabled=="object"?e.disabled?.value:e.disabled)&&At(!0);let Ke=()=>n==="window"?C:void 0,Ot=()=>{d||(d=!0,J?.abort(),ye.length=0,window.removeEventListener("aparte-message-aborted",Ct),qe.stop(),k?.(),typeof $=="function"&&$(),C.remove())};return{element:C,get sessionId(){return p},open:()=>Ke()?.show(),close:()=>Ke()?.close(),toggle:()=>Ke()?.toggle(),send:h=>{xe?ye.push(h):je(h)},reset:()=>{ye.length=0,S.streaming&&S.cancel(),qe.abort(),xe=!1,J?.abort(),te++,p=e.sessionId??oe(),i&&!e.sessionId&&tr(He,p),M&&(M.hidden=!1),ee(de())},setDisabled:At,destroy:Ot,unmount:Ot}}export{Ta as createChat,Ft as defineCard,Dt as el,Gt as formatDay,Kt as formatNumber,Wt as formatPrice,Zt as formatWhen,zt as glyph,Ut as safeUrl,Ht as webUrl};
103
103
  //# sourceMappingURL=n8n-chat.js.map