@aparte/n8n-chat 0.5.0 → 1.0.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (87) hide show
  1. package/README.md +109 -18
  2. package/dist/cdn/chunks/{chunk-27HPUSEO.js → chunk-75MBZEMR.js} +2 -2
  3. package/dist/cdn/chunks/{chunk-27HPUSEO.js.map → chunk-75MBZEMR.js.map} +1 -1
  4. package/dist/cdn/chunks/{chunk-J2RB5NH4.js → chunk-EKOAQWDB.js} +2 -2
  5. package/dist/cdn/chunks/{chunk-J2RB5NH4.js.map → chunk-EKOAQWDB.js.map} +1 -1
  6. package/dist/cdn/chunks/chunk-FPBJCFJN.js +379 -0
  7. package/dist/cdn/chunks/chunk-FPBJCFJN.js.map +7 -0
  8. package/dist/cdn/chunks/chunk-FZXRS5MT.js +208 -0
  9. package/dist/cdn/chunks/chunk-FZXRS5MT.js.map +7 -0
  10. package/dist/cdn/chunks/{chunk-A2H2YABP.js → chunk-UCBMONE6.js} +2 -2
  11. package/dist/cdn/chunks/{chunk-A2H2YABP.js.map → chunk-UCBMONE6.js.map} +1 -1
  12. package/dist/cdn/chunks/{chunk-GJ4YMVTA.js → chunk-WCZRD7U7.js} +1 -1
  13. package/dist/cdn/chunks/{chunk-GJ4YMVTA.js.map → chunk-WCZRD7U7.js.map} +1 -1
  14. package/dist/cdn/chunks/de-7JCOF7FR.js +2 -0
  15. package/dist/cdn/chunks/de-7JCOF7FR.js.map +7 -0
  16. package/dist/cdn/chunks/es-KUX7YCK6.js +2 -0
  17. package/dist/cdn/chunks/es-KUX7YCK6.js.map +7 -0
  18. package/dist/cdn/chunks/fr-VYD7EC55.js +2 -0
  19. package/dist/cdn/chunks/fr-VYD7EC55.js.map +7 -0
  20. package/dist/cdn/chunks/{highlight-SCSTGNZJ.js → highlight-W7QGGHNK.js} +2 -2
  21. package/dist/cdn/chunks/{highlight-SCSTGNZJ.js.map → highlight-W7QGGHNK.js.map} +1 -1
  22. package/dist/cdn/chunks/it-BXNO2THQ.js +2 -0
  23. package/dist/cdn/chunks/it-BXNO2THQ.js.map +7 -0
  24. package/dist/cdn/chunks/{items-TBASSOQ3.js → items-X2D73Z5A.js} +3 -3
  25. package/dist/cdn/chunks/{items-TBASSOQ3.js.map → items-X2D73Z5A.js.map} +4 -4
  26. package/dist/cdn/chunks/ja-6VGJFQ66.js +2 -0
  27. package/dist/cdn/chunks/ja-6VGJFQ66.js.map +7 -0
  28. package/dist/cdn/chunks/ko-HUU4F44X.js +2 -0
  29. package/dist/cdn/chunks/ko-HUU4F44X.js.map +7 -0
  30. package/dist/cdn/chunks/{link-VR62DJAD.js → link-LNDRLLUH.js} +3 -3
  31. package/dist/cdn/chunks/link-LNDRLLUH.js.map +7 -0
  32. package/dist/cdn/chunks/{media-O7WQHRGC.js → media-JDTPNZHJ.js} +4 -4
  33. package/dist/cdn/chunks/{media-O7WQHRGC.js.map → media-JDTPNZHJ.js.map} +4 -4
  34. package/dist/cdn/chunks/{order-H7FHTQ2J.js → order-HS6FXBIB.js} +3 -3
  35. package/dist/cdn/chunks/{order-H7FHTQ2J.js.map → order-HS6FXBIB.js.map} +3 -3
  36. package/dist/cdn/chunks/{place-TGHDGFFI.js → place-N3E7T2EV.js} +3 -3
  37. package/dist/cdn/chunks/{place-TGHDGFFI.js.map → place-N3E7T2EV.js.map} +4 -4
  38. package/dist/cdn/chunks/{plan-JA7466PF.js → plan-TCWRW3OC.js} +3 -3
  39. package/dist/cdn/chunks/{plan-JA7466PF.js.map → plan-TCWRW3OC.js.map} +4 -4
  40. package/dist/cdn/chunks/{product-VEI5FUDZ.js → product-JH7QUP6I.js} +3 -3
  41. package/dist/cdn/chunks/{product-VEI5FUDZ.js.map → product-JH7QUP6I.js.map} +4 -4
  42. package/dist/cdn/chunks/pt-BR-SNSDLB4C.js +2 -0
  43. package/dist/cdn/chunks/pt-BR-SNSDLB4C.js.map +7 -0
  44. package/dist/cdn/chunks/ru-QE2LLTEY.js +2 -0
  45. package/dist/cdn/chunks/ru-QE2LLTEY.js.map +7 -0
  46. package/dist/cdn/chunks/{score-QTZEGTBP.js → score-GUHJWHW3.js} +6 -6
  47. package/dist/cdn/chunks/{score-QTZEGTBP.js.map → score-GUHJWHW3.js.map} +4 -4
  48. package/dist/cdn/chunks/{stats-CNVSRBY6.js → stats-UIVYR2CG.js} +2 -2
  49. package/dist/cdn/chunks/{stats-CNVSRBY6.js.map → stats-UIVYR2CG.js.map} +1 -1
  50. package/dist/cdn/chunks/{stock-2KHFILSB.js → stock-PV4GC573.js} +2 -2
  51. package/dist/cdn/chunks/{stock-2KHFILSB.js.map → stock-PV4GC573.js.map} +1 -1
  52. package/dist/cdn/chunks/{weather-FAK6EHSV.js → weather-7L3Y3DNB.js} +2 -2
  53. package/dist/cdn/chunks/{weather-FAK6EHSV.js.map → weather-7L3Y3DNB.js.map} +1 -1
  54. package/dist/cdn/chunks/zh-CN-WKC5MGZY.js +2 -0
  55. package/dist/cdn/chunks/zh-CN-WKC5MGZY.js.map +7 -0
  56. package/dist/cdn/n8n-chat.js +61 -61
  57. package/dist/cdn/n8n-chat.js.map +4 -4
  58. package/dist/create-chat.d.ts +27 -2
  59. package/dist/index.js +18 -5
  60. package/dist/index.js.map +1 -1
  61. package/dist/strings.d.ts +5 -0
  62. package/dist/style.css +5 -9
  63. package/dist/theme.css +4 -8
  64. package/package.json +7 -7
  65. package/dist/cdn/chunks/chunk-7CJVMXIB.js +0 -356
  66. package/dist/cdn/chunks/chunk-7CJVMXIB.js.map +0 -7
  67. package/dist/cdn/chunks/chunk-N7SVHDCW.js +0 -206
  68. package/dist/cdn/chunks/chunk-N7SVHDCW.js.map +0 -7
  69. package/dist/cdn/chunks/de-NQDMZC5V.js +0 -2
  70. package/dist/cdn/chunks/de-NQDMZC5V.js.map +0 -7
  71. package/dist/cdn/chunks/es-IBJAOBGB.js +0 -2
  72. package/dist/cdn/chunks/es-IBJAOBGB.js.map +0 -7
  73. package/dist/cdn/chunks/fr-32HJELG3.js +0 -2
  74. package/dist/cdn/chunks/fr-32HJELG3.js.map +0 -7
  75. package/dist/cdn/chunks/it-HHSL2KBW.js +0 -2
  76. package/dist/cdn/chunks/it-HHSL2KBW.js.map +0 -7
  77. package/dist/cdn/chunks/ja-2EHR4WNO.js +0 -2
  78. package/dist/cdn/chunks/ja-2EHR4WNO.js.map +0 -7
  79. package/dist/cdn/chunks/ko-XONDEFR4.js +0 -2
  80. package/dist/cdn/chunks/ko-XONDEFR4.js.map +0 -7
  81. package/dist/cdn/chunks/link-VR62DJAD.js.map +0 -7
  82. package/dist/cdn/chunks/pt-BR-367NLYVE.js +0 -2
  83. package/dist/cdn/chunks/pt-BR-367NLYVE.js.map +0 -7
  84. package/dist/cdn/chunks/ru-ETHLBBSY.js +0 -2
  85. package/dist/cdn/chunks/ru-ETHLBBSY.js.map +0 -7
  86. package/dist/cdn/chunks/zh-CN-OGEW5BS2.js +0 -2
  87. package/dist/cdn/chunks/zh-CN-OGEW5BS2.js.map +0 -7
@@ -1,50 +1,50 @@
1
- import"./chunks/chunk-J2RB5NH4.js";import"./chunks/chunk-A2H2YABP.js";import"./chunks/chunk-27HPUSEO.js";import"./chunks/chunk-GJ4YMVTA.js";import{a as Ut,b as jt,c as Ht,d as qt,k as Ge,l as Ft,m as Kt,o as Wt,q as Gt,r as Zt,w as Vt,y as Jt}from"./chunks/chunk-7CJVMXIB.js";import{a as I,b as N,c as ae,d as Lt,e as Pt,f as We,g as Mt,i as Nt,j as fe,k as Bt,m as Dt,n as zt}from"./chunks/chunk-N7SVHDCW.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 ce=Qe();function sn(e){ce=e}var oe={exec:()=>null};function ge(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(B.caret,"$1"),n=n.replace(s,a),r},getRegex:()=>new RegExp(n,t)};return r}var cr=((e="")=>{try{return!!new RegExp("(?<=1)(?<!1)"+e)}catch{return!1}})(),B={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:ge(e=>new RegExp(`^ {0,${e}}(?:[*+-]|\\d{1,9}[.)])((?:[ ][^\\n]*)?(?:\\n|$))`)),hrRegex:ge(e=>new RegExp(`^ {0,${e}}((?:- *){3,}|(?:_ *){3,}|(?:\\* *){3,})(?:\\n+|$)`)),fencesBeginRegex:ge(e=>new RegExp(`^ {0,${e}}(?:\`\`\`|~~~)`)),headingBeginRegex:ge(e=>new RegExp(`^ {0,${e}}#`)),htmlBeginRegex:ge(e=>new RegExp(`^ {0,${e}}<(?:[a-z].*>|!--)`,"i")),blockquoteBeginRegex:ge(e=>new RegExp(`^ {0,${e}}>`))},ur=/^(?:[ \t]*(?:\n|$))+/,pr=/^((?: {4}| {0,3}\t)[^\n]+(?:\n(?:[ \t]*(?:\n|$))*)?)+/,hr=/^ {0,3}(`{3,}(?=[^`\n]*(?:\n|$))|~{3,})([^\n]*)(?:\n|$)(?:|([\s\S]*?)(?:\n|$))(?: {0,3}\1[~`]* *(?=\n|$)|$)/,ve=/^ {0,3}((?:-[\t ]*){3,}|(?:_[ \t]*){3,}|(?:\*[ \t]*){3,})(?:\n+|$)/,dr=/^ {0,3}(#{1,6})(?=\s|$)(.*)(?:\n+|$)/,Xe=/ {0,3}(?:[*+-]|\d{1,9}[.)])/,an=/^(?!bull |blockCode|fences|blockquote|heading|html|table)((?:.|\n(?!\s*?\n|bull |blockCode|fences|blockquote|heading|html|table))+?)\n {0,3}(=+|-+) *(?:\n+|$)/,on=w(an).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(),fr=w(an).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]+)*)/,gr=/^[^\n]+/,et=/(?!\s*\])(?:\\[\s\S]|[^\[\]\\])+/,mr=w(/^ {0,3}\[(label)\]: *(?:\n[ \t]*)?([^<\s][^\s]*|<.*?>)(?:(?: +(?:\n[ \t]*)?| *\n[ \t]*)(title))? *(?:\n+|$)/).replace("label",et).replace("title",/(?:"(?:\\"?|[^"\\])*"|'[^'\n]*(?:\n[^'\n]+)*\n?'|\([^()]*\))/).getRegex(),kr=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]*?(?:-->|$))/,br=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(),ln=e=>w(Ye).replace("hr",ve).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(),wr=ln(/ {0,3}(?:[*+-]|1[.)])[ \t]+[^ \t\n]/),yr=ln(/ {0,3}(?:[*+-]|\d{1,9}[.)])[ \t]+[^ \t\n]/),xr=w(/^( {0,3}> ?(paragraph|[^\n]*)(?:\n|$))+/).replace("paragraph",yr).getRegex(),nt={blockquote:xr,code:pr,def:mr,fences:hr,heading:dr,hr:ve,html:br,lheading:on,list:kr,newline:ur,paragraph:wr,table:oe,text:gr},Qt=w("^ *([^\\n ].*)\\n {0,3}((?:\\| *)?:?-+:? *(?:\\| *:?-+:? *)*(?:\\| *)?)(?:\\n((?:(?! *\\n|hr|heading|blockquote|code|fences|list|html).*(?:\\n|$))*)\\n*|$)").replace("hr",ve).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(),Sr={...nt,lheading:fr,table:Qt,paragraph:w(Ye).replace("hr",ve).replace("heading"," {0,3}#{1,6}(?:\\s|$)").replace("|lheading","").replace("table",Qt).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()},Rr={...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:oe,lheading:/^(.+?)\n {0,3}(=+|-+) *(?:\n+|$)/,paragraph:w(Ye).replace("hr",ve).replace("heading",` *#{1,6} *[^
2
- ]`).replace("lheading",on).replace("|table","").replace("blockquote"," {0,3}>").replace("|fences","").replace("|list","").replace("|html","").replace("|tag","").getRegex()},Er=/^\\([!"#$%&'()*+,\-./:;<=>?@\[\]\\^_`{|}~])/,vr=/^(`+)([^`]|[^`][\s\S]*?[^`])\1(?!`)/,cn=/^( {2,}|\\)\n(?!\s*$)/,$r=/^(`+|[^`])(?:(?= {2,}\n)|[\s\S]*?(?:(?=[\\<!\[`*_]|\b_|$)|[^ ](?= {2,}\n)))/,me=/[\p{P}\p{S}]/u,Le=/[\s\p{P}\p{S}]/u,rt=/[^\s\p{P}\p{S}]/u,Cr=w(/^((?![*_])punctSpace)/,"u").replace(/punctSpace/g,Le).getRegex(),un=/(?!~)[\p{P}\p{S}]/u,Tr=/(?!~)[\s\p{P}\p{S}]/u,Ar=/(?:[^\s\p{P}\p{S}]|~)/u,Ir=w(/link|precode-code|html/,"g").replace("link",/\[(?:[^\[\]`]|(?<a>`+)[^`]+\k<a>(?!`))*?\]\((?:\\[\s\S]|[^\\\(\)]|\((?:\\[\s\S]|[^\\\(\)])*\))*\)/).replace("precode-",cr?"(?<!`)()":"(^^|[^`])").replace("code",/(?<b>`+)[^`]+\k<b>(?!`)/).replace("html",/<(?! )[^<>]*?>/).getRegex(),pn=/^(?:\*+(?:((?!\*)punct)|([^\s*]))?)|^_+(?:((?!_)punct)|([^\s_]))?/,Or=w(pn,"u").replace(/punct/g,me).getRegex(),_r=w(pn,"u").replace(/punct/g,un).getRegex(),hn="^[^_*]*?__[^_*]*?\\*[^_*]*?(?=__)|[^*]+(?=[^*])|(?!\\*)punct(\\*+)(?=[\\s]|$)|notPunctSpace(\\*+)(?!\\*)(?=punctSpace|$)|(?!\\*)punctSpace(\\*+)(?=notPunctSpace)|[\\s](\\*+)(?!\\*)(?=punct)|(?!\\*)punct(\\*+)(?!\\*)(?=punct)|notPunctSpace(\\*+)(?=notPunctSpace)",Lr=w(hn,"gu").replace(/notPunctSpace/g,rt).replace(/punctSpace/g,Le).replace(/punct/g,me).getRegex(),Pr=w(hn,"gu").replace(/notPunctSpace/g,Ar).replace(/punctSpace/g,Tr).replace(/punct/g,un).getRegex(),Mr=w("^[^_*]*?\\*\\*[^_*]*?_[^_*]*?(?=\\*\\*)|[^_]+(?=[^_])|(?!_)punct(_+)(?=[\\s]|$)|notPunctSpace(_+)(?!_)(?=punctSpace|$)|(?!_)punctSpace(_+)(?=notPunctSpace)|[\\s](_+)(?!_)(?=punct)|(?!_)punct(_+)(?!_)(?=punct)","gu").replace(/notPunctSpace/g,rt).replace(/punctSpace/g,Le).replace(/punct/g,me).getRegex(),Nr=w(/^~~?(?:((?!~)punct)|[^\s~])/,"u").replace(/punct/g,me).getRegex(),Br="^[^~]+(?=[^~])|(?!~)punct(~~?)(?=[\\s]|$)|notPunctSpace(~~?)(?!~)(?=punctSpace|$)|(?!~)punctSpace(~~?)(?=notPunctSpace)|[\\s](~~?)(?!~)(?=punct)|(?!~)punct(~~?)(?!~)(?=punct)|notPunctSpace(~~?)(?=notPunctSpace)",Dr=w(Br,"gu").replace(/notPunctSpace/g,rt).replace(/punctSpace/g,Le).replace(/punct/g,me).getRegex(),zr=w(/\\(punct)/,"gu").replace(/punct/g,me).getRegex(),Ur=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(),jr=w(tt).replace("(?:-->|$)","-->").getRegex(),Hr=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",jr).replace("attribute",/\s+[a-zA-Z:_][\w.:-]*(?:\s*=\s*"[^"]*"|\s*=\s*'[^']*'|\s*=\s*[^\s"'=<>`]+)?/).getRegex(),Ae=/(?:\[(?:\\[\s\S]|[^\[\]\\])*\]|\\[\s\S]|`+(?!`)[^`]*?`+(?!`)|``+(?=\])|[^\[\]\\`])*?/,qr=w(/^!?\[(label)\]\(\s*(href)(?:(?:[ \t]+(?:\n[ \t]*)?|\n[ \t]*)(title))?\s*\)/).replace("label",Ae).replace("href",/<(?:\\.|[^\n<>\\])+>|[^ \t\n\x00-\x1f]+|(?=\))/).replace("title",/"(?:\\"?|[^"\\])*"|'(?:\\'?|[^'\\])*'|\((?:\\\)?|[^)\\])*\)/).getRegex(),dn=w(/^!?\[(label)\]\[(ref)\]/).replace("label",Ae).replace("ref",et).getRegex(),fn=w(/^!?\[(ref)\](?:\[\])?/).replace("ref",et).getRegex(),Fr=w("reflink|nolink(?!\\()","g").replace("reflink",dn).replace("nolink",fn).getRegex(),Xt=/[hH][tT][tT][pP][sS]?|[fF][tT][pP]/,st={_backpedal:oe,anyPunctuation:zr,autolink:Ur,blockSkip:Ir,br:cn,code:vr,del:oe,delLDelim:oe,delRDelim:oe,emStrongLDelim:Or,emStrongRDelimAst:Lr,emStrongRDelimUnd:Mr,escape:Er,link:qr,nolink:fn,punctuation:Cr,reflink:dn,reflinkSearch:Fr,tag:Hr,text:$r,url:oe},Kr={...st,link:w(/^!?\[(label)\]\((.*?)\)/).replace("label",Ae).getRegex(),reflink:w(/^!?\[(label)\]\s*\[([^\]]*)\]/).replace("label",Ae).getRegex()},Ze={...st,emStrongRDelimAst:Pr,emStrongLDelim:_r,delLDelim:Nr,delRDelim:Dr,url:w(/^((?:protocol):\/\/|www\.)(?:[a-zA-Z0-9\-]+\.?)+[^\s<]*|^email/).replace("protocol",Xt).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",Xt).getRegex()},Wr={...Ze,br:w(cn).replace("{2,}","*").getRegex(),text:w(Ze.text).replace("\\b_","\\b_| {2,}\\n").replace(/\{2,\}/g,"*").getRegex()},Te={normal:nt,gfm:Sr,pedantic:Rr},Re={normal:st,gfm:Ze,breaks:Wr,pedantic:Kr},Gr={"&":"&amp;","<":"&lt;",">":"&gt;",'"':"&quot;","'":"&#39;"},Yt=e=>Gr[e];function V(e,t){if(t){if(B.escapeTest.test(e))return e.replace(B.escapeReplace,Yt)}else if(B.escapeTestNoEncode.test(e))return e.replace(B.escapeReplaceNoEncode,Yt);return e}function en(e){try{e=encodeURI(e).replace(B.percentDecode,"%")}catch{return null}return e}function tn(e,t){let n=e.replace(B.findPipe,(i,a,o)=>{let c=!1,l=a;for(;--l>=0&&o[l]==="\\";)c=!c;return c?"|":" |"}),r=n.split(B.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(B.slashPipe,"|");return r}function Y(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 nn(e){let t=e.split(`
3
- `),n=t.length-1;for(;n>=0&&B.blankLine.test(t[n]);)n--;return t.length-n<=2?e:t.slice(0,n+1).join(`
4
- `)}function Zr(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 Vr(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 rn(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 Jr(e,t,n){let r=e.match(n.other.indentCodeCompensation);if(r===null)return t;let s=r[1];return t.split(`
1
+ import"./chunks/chunk-EKOAQWDB.js";import"./chunks/chunk-UCBMONE6.js";import"./chunks/chunk-75MBZEMR.js";import"./chunks/chunk-WCZRD7U7.js";import{a as qt,b as Ft,c as Kt,d as Wt,k as Je,l as Gt,m as Zt,o as Vt,q as Jt,r as Qt,w as Xt,y as Yt}from"./chunks/chunk-FPBJCFJN.js";import{a as L,b as z,c as ue,d as Nt,e as Bt,f as Ve,g as Dt,i as zt,j as be,k as Ut,m as jt,n as Ht}from"./chunks/chunk-FZXRS5MT.js";import"./chunks/chunk-XAWE4EAK.js";function et(){return{async:!1,breaks:!1,extensions:null,gfm:!0,hooks:null,pedantic:!1,renderer:null,silent:!1,tokenizer:null,walkTokens:null}}var de=et();function ln(e){de=e}var pe={exec:()=>null};function we(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 y(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(U.caret,"$1"),n=n.replace(s,a),r},getRegex:()=>new RegExp(n,t)};return r}var hr=((e="")=>{try{return!!new RegExp("(?<=1)(?<!1)"+e)}catch{return!1}})(),U={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:we(e=>new RegExp(`^ {0,${e}}(?:[*+-]|\\d{1,9}[.)])((?:[ ][^\\n]*)?(?:\\n|$))`)),hrRegex:we(e=>new RegExp(`^ {0,${e}}((?:- *){3,}|(?:_ *){3,}|(?:\\* *){3,})(?:\\n+|$)`)),fencesBeginRegex:we(e=>new RegExp(`^ {0,${e}}(?:\`\`\`|~~~)`)),headingBeginRegex:we(e=>new RegExp(`^ {0,${e}}#`)),htmlBeginRegex:we(e=>new RegExp(`^ {0,${e}}<(?:[a-z].*>|!--)`,"i")),blockquoteBeginRegex:we(e=>new RegExp(`^ {0,${e}}>`))},dr=/^(?:[ \t]*(?:\n|$))+/,fr=/^((?: {4}| {0,3}\t)[^\n]+(?:\n(?:[ \t]*(?:\n|$))*)?)+/,gr=/^ {0,3}(`{3,}(?=[^`\n]*(?:\n|$))|~{3,})([^\n]*)(?:\n|$)(?:|([\s\S]*?)(?:\n|$))(?: {0,3}\1[~`]* *(?=\n|$)|$)/,Ie=/^ {0,3}((?:-[\t ]*){3,}|(?:_[ \t]*){3,}|(?:\*[ \t]*){3,})(?:\n+|$)/,mr=/^ {0,3}(#{1,6})(?=\s|$)(.*)(?:\n+|$)/,tt=/ {0,3}(?:[*+-]|\d{1,9}[.)])/,cn=/^(?!bull |blockCode|fences|blockquote|heading|html|table)((?:.|\n(?!\s*?\n|bull |blockCode|fences|blockquote|heading|html|table))+?)\n {0,3}(=+|-+) *(?:\n+|$)/,un=y(cn).replace(/bull/g,tt).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(),kr=y(cn).replace(/bull/g,tt).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(),nt=/^([^\n]+(?:\n(?!hr|heading|lheading|blockquote|fences|list|html|table| +\n)[^\n]+)*)/,br=/^[^\n]+/,rt=/(?!\s*\])(?:\\[\s\S]|[^\[\]\\])+/,wr=y(/^ {0,3}\[(label)\]: *(?:\n[ \t]*)?([^<\s][^\s]*|<.*?>)(?:(?: +(?:\n[ \t]*)?| *\n[ \t]*)(title))? *(?:\n+|$)/).replace("label",rt).replace("title",/(?:"(?:\\"?|[^"\\])*"|'[^'\n]*(?:\n[^'\n]+)*\n?'|\([^()]*\))/).getRegex(),yr=y(/^(bull)([ \t][^\n]*?)?(?:\n|$)/).replace(/bull/g,tt).getRegex(),Me="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",st=/<!--(?:-?>|[\s\S]*?(?:-->|$))/,xr=y("^ {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",st).replace("tag",Me).replace("attribute",/ +[a-zA-Z:_][\w.:-]*(?: *= *"[^"\n]*"| *= *'[^'\n]*'| *= *[^\s"'=<>`]+)?/).getRegex(),pn=e=>y(nt).replace("hr",Ie).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",Me).getRegex(),Sr=pn(/ {0,3}(?:[*+-]|1[.)])[ \t]+[^ \t\n]/),vr=pn(/ {0,3}(?:[*+-]|\d{1,9}[.)])[ \t]+[^ \t\n]/),Rr=y(/^( {0,3}> ?(paragraph|[^\n]*)(?:\n|$))+/).replace("paragraph",vr).getRegex(),it={blockquote:Rr,code:fr,def:wr,fences:gr,heading:mr,hr:Ie,html:xr,lheading:un,list:yr,newline:dr,paragraph:Sr,table:pe,text:br},en=y("^ *([^\\n ].*)\\n {0,3}((?:\\| *)?:?-+:? *(?:\\| *:?-+:? *)*(?:\\| *)?)(?:\\n((?:(?! *\\n|hr|heading|blockquote|code|fences|list|html).*(?:\\n|$))*)\\n*|$)").replace("hr",Ie).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",Me).getRegex(),Er={...it,lheading:kr,table:en,paragraph:y(nt).replace("hr",Ie).replace("heading"," {0,3}#{1,6}(?:\\s|$)").replace("|lheading","").replace("table",en).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",Me).getRegex()},$r={...it,html:y(`^ *(?:comment *(?:\\n|\\s*$)|<(tag)[\\s\\S]+?</\\1> *(?:\\n{2,}|\\s*$)|<tag(?:"[^"]*"|'[^']*'|\\s[^'"/>\\s]*)*?/?> *(?:\\n{2,}|\\s*$))`).replace("comment",st).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:pe,lheading:/^(.+?)\n {0,3}(=+|-+) *(?:\n+|$)/,paragraph:y(nt).replace("hr",Ie).replace("heading",` *#{1,6} *[^
2
+ ]`).replace("lheading",un).replace("|table","").replace("blockquote"," {0,3}>").replace("|fences","").replace("|list","").replace("|html","").replace("|tag","").getRegex()},Cr=/^\\([!"#$%&'()*+,\-./:;<=>?@\[\]\\^_`{|}~])/,Ir=/^(`+)([^`]|[^`][\s\S]*?[^`])\1(?!`)/,hn=/^( {2,}|\\)\n(?!\s*$)/,Ar=/^(`+|[^`])(?:(?= {2,}\n)|[\s\S]*?(?:(?=[\\<!\[`*_]|\b_|$)|[^ ](?= {2,}\n)))/,ye=/[\p{P}\p{S}]/u,Ne=/[\s\p{P}\p{S}]/u,at=/[^\s\p{P}\p{S}]/u,Tr=y(/^((?![*_])punctSpace)/,"u").replace(/punctSpace/g,Ne).getRegex(),dn=/(?!~)[\p{P}\p{S}]/u,Or=/(?!~)[\s\p{P}\p{S}]/u,_r=/(?:[^\s\p{P}\p{S}]|~)/u,Lr=y(/link|precode-code|html/,"g").replace("link",/\[(?:[^\[\]`]|(?<a>`+)[^`]+\k<a>(?!`))*?\]\((?:\\[\s\S]|[^\\\(\)]|\((?:\\[\s\S]|[^\\\(\)])*\))*\)/).replace("precode-",hr?"(?<!`)()":"(^^|[^`])").replace("code",/(?<b>`+)[^`]+\k<b>(?!`)/).replace("html",/<(?! )[^<>]*?>/).getRegex(),fn=/^(?:\*+(?:((?!\*)punct)|([^\s*]))?)|^_+(?:((?!_)punct)|([^\s_]))?/,Pr=y(fn,"u").replace(/punct/g,ye).getRegex(),Mr=y(fn,"u").replace(/punct/g,dn).getRegex(),gn="^[^_*]*?__[^_*]*?\\*[^_*]*?(?=__)|[^*]+(?=[^*])|(?!\\*)punct(\\*+)(?=[\\s]|$)|notPunctSpace(\\*+)(?!\\*)(?=punctSpace|$)|(?!\\*)punctSpace(\\*+)(?=notPunctSpace)|[\\s](\\*+)(?!\\*)(?=punct)|(?!\\*)punct(\\*+)(?!\\*)(?=punct)|notPunctSpace(\\*+)(?=notPunctSpace)",Nr=y(gn,"gu").replace(/notPunctSpace/g,at).replace(/punctSpace/g,Ne).replace(/punct/g,ye).getRegex(),Br=y(gn,"gu").replace(/notPunctSpace/g,_r).replace(/punctSpace/g,Or).replace(/punct/g,dn).getRegex(),Dr=y("^[^_*]*?\\*\\*[^_*]*?_[^_*]*?(?=\\*\\*)|[^_]+(?=[^_])|(?!_)punct(_+)(?=[\\s]|$)|notPunctSpace(_+)(?!_)(?=punctSpace|$)|(?!_)punctSpace(_+)(?=notPunctSpace)|[\\s](_+)(?!_)(?=punct)|(?!_)punct(_+)(?!_)(?=punct)","gu").replace(/notPunctSpace/g,at).replace(/punctSpace/g,Ne).replace(/punct/g,ye).getRegex(),zr=y(/^~~?(?:((?!~)punct)|[^\s~])/,"u").replace(/punct/g,ye).getRegex(),Ur="^[^~]+(?=[^~])|(?!~)punct(~~?)(?=[\\s]|$)|notPunctSpace(~~?)(?!~)(?=punctSpace|$)|(?!~)punctSpace(~~?)(?=notPunctSpace)|[\\s](~~?)(?!~)(?=punct)|(?!~)punct(~~?)(?!~)(?=punct)|notPunctSpace(~~?)(?=notPunctSpace)",jr=y(Ur,"gu").replace(/notPunctSpace/g,at).replace(/punctSpace/g,Ne).replace(/punct/g,ye).getRegex(),Hr=y(/\\(punct)/,"gu").replace(/punct/g,ye).getRegex(),qr=y(/^<(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(),Fr=y(st).replace("(?:-->|$)","-->").getRegex(),Kr=y("^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",Fr).replace("attribute",/\s+[a-zA-Z:_][\w.:-]*(?:\s*=\s*"[^"]*"|\s*=\s*'[^']*'|\s*=\s*[^\s"'=<>`]+)?/).getRegex(),_e=/(?:\[(?:\\[\s\S]|[^\[\]\\])*\]|\\[\s\S]|`+(?!`)[^`]*?`+(?!`)|``+(?=\])|[^\[\]\\`])*?/,Wr=y(/^!?\[(label)\]\(\s*(href)(?:(?:[ \t]+(?:\n[ \t]*)?|\n[ \t]*)(title))?\s*\)/).replace("label",_e).replace("href",/<(?:\\.|[^\n<>\\])+>|[^ \t\n\x00-\x1f]+|(?=\))/).replace("title",/"(?:\\"?|[^"\\])*"|'(?:\\'?|[^'\\])*'|\((?:\\\)?|[^)\\])*\)/).getRegex(),mn=y(/^!?\[(label)\]\[(ref)\]/).replace("label",_e).replace("ref",rt).getRegex(),kn=y(/^!?\[(ref)\](?:\[\])?/).replace("ref",rt).getRegex(),Gr=y("reflink|nolink(?!\\()","g").replace("reflink",mn).replace("nolink",kn).getRegex(),tn=/[hH][tT][tT][pP][sS]?|[fF][tT][pP]/,ot={_backpedal:pe,anyPunctuation:Hr,autolink:qr,blockSkip:Lr,br:hn,code:Ir,del:pe,delLDelim:pe,delRDelim:pe,emStrongLDelim:Pr,emStrongRDelimAst:Nr,emStrongRDelimUnd:Dr,escape:Cr,link:Wr,nolink:kn,punctuation:Tr,reflink:mn,reflinkSearch:Gr,tag:Kr,text:Ar,url:pe},Zr={...ot,link:y(/^!?\[(label)\]\((.*?)\)/).replace("label",_e).getRegex(),reflink:y(/^!?\[(label)\]\s*\[([^\]]*)\]/).replace("label",_e).getRegex()},Qe={...ot,emStrongRDelimAst:Br,emStrongLDelim:Mr,delLDelim:zr,delRDelim:jr,url:y(/^((?:protocol):\/\/|www\.)(?:[a-zA-Z0-9\-]+\.?)+[^\s<]*|^email/).replace("protocol",tn).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:y(/^([`~]+|[^`~])(?:(?= {2,}\n)|(?=[a-zA-Z0-9.!#$%&'*+\/=?_`{\|}~-]+@)|[\s\S]*?(?:(?=[\\<!\[`*~_]|\b_|protocol:\/\/|www\.|$)|[^ ](?= {2,}\n)|[^a-zA-Z0-9.!#$%&'*+\/=?_`{\|}~-](?=[a-zA-Z0-9.!#$%&'*+\/=?_`{\|}~-]+@)))/).replace("protocol",tn).getRegex()},Vr={...Qe,br:y(hn).replace("{2,}","*").getRegex(),text:y(Qe.text).replace("\\b_","\\b_| {2,}\\n").replace(/\{2,\}/g,"*").getRegex()},Oe={normal:it,gfm:Er,pedantic:$r},$e={normal:ot,gfm:Qe,breaks:Vr,pedantic:Zr},Jr={"&":"&amp;","<":"&lt;",">":"&gt;",'"':"&quot;","'":"&#39;"},nn=e=>Jr[e];function Q(e,t){if(t){if(U.escapeTest.test(e))return e.replace(U.escapeReplace,nn)}else if(U.escapeTestNoEncode.test(e))return e.replace(U.escapeReplaceNoEncode,nn);return e}function rn(e){try{e=encodeURI(e).replace(U.percentDecode,"%")}catch{return null}return e}function sn(e,t){let n=e.replace(U.findPipe,(i,a,o)=>{let l=!1,c=a;for(;--c>=0&&o[c]==="\\";)l=!l;return l?"|":" |"}),r=n.split(U.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(U.slashPipe,"|");return r}function ie(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 an(e){let t=e.split(`
3
+ `),n=t.length-1;for(;n>=0&&U.blankLine.test(t[n]);)n--;return t.length-n<=2?e:t.slice(0,n+1).join(`
4
+ `)}function Qr(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 Xr(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 on(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 l={type:e[0].charAt(0)==="!"?"image":"link",raw:n,href:i,title:a,text:o,tokens:r.inlineTokens(o)};return r.state.inLink=!1,l}function Yr(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 Ie=class{options;rules;lexer;constructor(e){this.options=e||ce}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]:nn(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=Jr(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=Y(n,"#");(this.options.pedantic||!r||this.rules.other.endingSpaceChar.test(r))&&(n=r.trim())}return{type:"heading",raw:Y(t[0],`
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:Y(t[0],`
8
- `)}}blockquote(e){let t=this.rules.block.blockquote.exec(e);if(t){let n=Y(t[0],`
6
+ `)}var Le=class{options;rules;lexer;constructor(e){this.options=e||de}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]:an(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=Yr(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=ie(n,"#");(this.options.pedantic||!r||this.rules.other.endingSpaceChar.test(r))&&(n=r.trim())}return{type:"heading",raw:ie(t[0],`
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:ie(t[0],`
8
+ `)}}blockquote(e){let t=this.rules.block.blockquote.exec(e);if(t){let n=ie(t[0],`
9
9
  `).split(`
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
- `),p=l.replace(this.rules.other.blockquoteSetextReplace,`
10
+ `),r="",s="",i=[];for(;n.length>0;){let a=!1,o=[],l;for(l=0;l<n.length;l++)if(this.rules.other.blockquoteStart.test(n[l]))o.push(n[l]),a=!0;else if(!a)o.push(n[l]);else break;n=n.slice(l);let c=o.join(`
11
+ `),d=c.replace(this.rules.other.blockquoteSetextReplace,`
12
12
  $1`).replace(this.rules.other.blockquoteSetextReplace2,"");r=r?`${r}
13
- ${l}`:l,s=s?`${s}
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+`
13
+ ${c}`:c,s=s?`${s}
14
+ ${d}`:d;let u=this.lexer.state.top;if(this.lexer.state.top=!0,this.lexer.blockTokens(d,i,!0),this.lexer.state.top=u,n.length===0)break;let h=i.at(-1);if(h?.type==="code")break;if(h?.type==="blockquote"){let g=h,f=g.raw+`
15
15
  `+n.join(`
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+`
16
+ `),w=this.blockquote(f);i[i.length-1]=w,r=r.substring(0,r.length-g.raw.length)+w.raw,s=s.substring(0,s.length-g.text.length)+w.text;break}else if(h?.type==="list"){let g=h,f=g.raw+`
17
17
  `+n.join(`
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="",p="";if(!(t=i.exec(e))||this.rules.block.hr.test(e))break;l=t[0],e=e.substring(l.length);let u=Vr(t[2].split(`
20
- `,1)[0],t[1].length),d=e.split(`
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),E=this.rules.other.hrRegex(k),$=this.rules.other.fencesBeginRegex(k),R=this.rules.other.headingBeginRegex(k),j=this.rules.other.htmlBeginRegex(k),H=this.rules.other.blockquoteBeginRegex(k);for(;e;){let F=e.split(`
23
- `,1)[0],b;if(d=F,this.options.pedantic?(d=d.replace(this.rules.other.listReplaceNesting," "),b=d):b=d.replace(this.rules.other.tabCharGlobal," "),$.test(d)||R.test(d)||j.test(d)||H.test(d)||v.test(d)||E.test(d))break;if(b.search(this.rules.other.nonSpaceChar)>=k||!d.trim())p+=`
24
- `+b.slice(k);else{if(m||u.replace(this.rules.other.tabCharGlobal," ").search(this.rules.other.nonSpaceChar)>=4||$.test(u)||R.test(u)||E.test(u))break;p+=`
25
- `+d}m=!d.trim(),l+=F+`
26
- `,e=e.substring(F.length+1),u=b.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=nn(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:Y(t[0],`
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=tn(t[1]),r=t[2].replace(this.rules.other.tableAlignChars,"").split("|"),s=t[3]?.trim()?t[3].replace(this.rules.other.tableRowBlankLine,"").split(`
28
- `):[],i={type:"table",raw:Y(t[0],`
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(tn(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:Y(t[0],`
18
+ `),w=this.list(f);i[i.length-1]=w,r=r.substring(0,r.length-h.raw.length)+w.raw,s=s.substring(0,s.length-g.raw.length)+w.raw,n=f.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 l=!1,c="",d="";if(!(t=i.exec(e))||this.rules.block.hr.test(e))break;c=t[0],e=e.substring(c.length);let u=Xr(t[2].split(`
20
+ `,1)[0],t[1].length),h=e.split(`
21
+ `,1)[0],g=!u.trim(),f=0;if(this.options.pedantic?(f=2,d=u.trimStart()):g?f=t[1].length+1:(f=u.search(this.rules.other.nonSpaceChar),f=f>4?1:f,d=u.slice(f),f+=t[1].length),g&&this.rules.other.blankLine.test(h)&&(c+=h+`
22
+ `,e=e.substring(h.length+1),l=!0),!l){let w=this.rules.other.nextBulletRegex(f),v=this.rules.other.hrRegex(f),E=this.rules.other.fencesBeginRegex(f),$=this.rules.other.headingBeginRegex(f),R=this.rules.other.htmlBeginRegex(f),I=this.rules.other.blockquoteBeginRegex(f);for(;e;){let N=e.split(`
23
+ `,1)[0],b;if(h=N,this.options.pedantic?(h=h.replace(this.rules.other.listReplaceNesting," "),b=h):b=h.replace(this.rules.other.tabCharGlobal," "),E.test(h)||$.test(h)||R.test(h)||I.test(h)||w.test(h)||v.test(h))break;if(b.search(this.rules.other.nonSpaceChar)>=f||!h.trim())d+=`
24
+ `+b.slice(f);else{if(g||u.replace(this.rules.other.tabCharGlobal," ").search(this.rules.other.nonSpaceChar)>=4||E.test(u)||$.test(u)||v.test(u))break;d+=`
25
+ `+h}g=!h.trim(),c+=N+`
26
+ `,e=e.substring(N.length+1),u=b.slice(f)}}s.loose||(a?s.loose=!0:this.rules.other.doubleBlankLine.test(c)&&(a=!0)),s.items.push({type:"list_item",raw:c,task:!!this.options.gfm&&this.rules.other.listIsTask.test(d),loose:!1,text:d,tokens:[]}),s.raw+=c}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 l of s.items){this.lexer.state.top=!1,l.tokens=this.lexer.blockTokens(l.text,[]);let c=l.tokens[0];if(l.task&&(c?.type==="text"||c?.type==="paragraph")){l.text=l.text.replace(this.rules.other.listReplaceTask,""),c.raw=c.raw.replace(this.rules.other.listReplaceTask,""),c.text=c.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 d=this.rules.other.listTaskCheckbox.exec(l.raw);if(d){let u={type:"checkbox",raw:d[0]+" ",checked:d[0]!=="[ ]"};l.checked=u.checked,s.loose?l.tokens[0]&&["paragraph","text"].includes(l.tokens[0].type)&&"tokens"in l.tokens[0]&&l.tokens[0].tokens?(l.tokens[0].raw=u.raw+l.tokens[0].raw,l.tokens[0].text=u.raw+l.tokens[0].text,l.tokens[0].tokens.unshift(u)):l.tokens.unshift({type:"paragraph",raw:u.raw,text:u.raw,tokens:[u]}):l.tokens.unshift(u)}}else l.task&&(l.task=!1);if(!s.loose){let d=l.tokens.filter(h=>h.type==="space"),u=d.length>0&&d.some(h=>this.rules.other.anyLine.test(h.raw));s.loose=u}}if(s.loose)for(let l of s.items){l.loose=!0;for(let c of l.tokens)c.type==="text"&&(c.type="paragraph")}return s}}html(e){let t=this.rules.block.html.exec(e);if(t){let n=an(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:ie(t[0],`
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=sn(t[1]),r=t[2].replace(this.rules.other.tableAlignChars,"").split("|"),s=t[3]?.trim()?t[3].replace(this.rules.other.tableRowBlankLine,"").split(`
28
+ `):[],i={type:"table",raw:ie(t[0],`
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(sn(a,i.header.length).map((o,l)=>({text:o,tokens:this.lexer.inline(o),header:!1,align:i.align[l]})));return i}}lheading(e){let t=this.rules.block.lheading.exec(e);if(t){let n=t[1].trim();return{type:"heading",raw:ie(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=Y(n.slice(0,-1),"\\");if((n.length-i.length)%2===0)return}else{let i=Zr(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)),rn(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 rn(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}}}},K=class Ve{tokens;options;state;inlineQueue;tokenizer;constructor(t){this.tokens=[],this.tokens.links=Object.create(null),this.options=t||ce,this.options.tokenizer=this.options.tokenizer||new Ie,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:B,block:Te.normal,inline:Re.normal};this.options.pedantic?(n.block=Te.pedantic,n.inline=Re.pedantic):this.options.gfm&&(n.block=Te.gfm,this.options.breaks?n.inline=Re.breaks:n.inline=Re.gfm),this.tokenizer.rules=n}static get rules(){return{block:Te,inline:Re}}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(B.carriageReturn,`
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(B.tabCharGlobal," ").replace(B.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+=`
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=ie(n.slice(0,-1),"\\");if((n.length-i.length)%2===0)return}else{let i=Qr(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)),on(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 on(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,l=0,c=r[0][0]==="*"?this.rules.inline.emStrongRDelimAst:this.rules.inline.emStrongRDelimUnd;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)continue;if(a=[...i].length,r[3]||r[4]){o+=a;continue}else if((r[5]||r[6])&&s%3&&!((s+a)%3)){l+=a;continue}if(o-=a,o>0)continue;a=Math.min(a,a+o+l);let d=[...r[0]][0].length,u=e.slice(0,s+r.index+d+a);if(Math.min(s,a)%2){let g=u.slice(1,-1);return{type:"em",raw:u,text:g,tokens:this.lexer.inlineTokens(g)}}let h=u.slice(2,-2);return{type:"strong",raw:u,text:h,tokens:this.lexer.inlineTokens(h)}}}}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,l=this.rules.inline.delRDelim;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||(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 c=[...r[0]][0].length,d=e.slice(0,s+r.index+c+a),u=d.slice(s,-s);return{type:"del",raw:d,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}}}},K=class Xe{tokens;options;state;inlineQueue;tokenizer;constructor(t){this.tokens=[],this.tokens.links=Object.create(null),this.options=t||de,this.options.tokenizer=this.options.tokenizer||new Le,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:U,block:Oe.normal,inline:$e.normal};this.options.pedantic?(n.block=Oe.pedantic,n.inline=$e.pedantic):this.options.gfm&&(n.block=Oe.gfm,this.options.breaks?n.inline=$e.breaks:n.inline=$e.gfm),this.tokenizer.rules=n}static get rules(){return{block:Oe,inline:$e}}static lex(t,n){return new Xe(n).lex(t)}static lexInline(t,n){return new Xe(n).inlineTokens(t)}lex(t){t=t.replace(U.carriageReturn,`
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(U.tabCharGlobal," ").replace(U.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
  `)?"":`
35
35
  `)+i.raw,o.text+=`
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(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(`
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,l=t.slice(1),c;this.options.extensions.startBlock.forEach(d=>{c=d.call({lexer:this},l),typeof c=="number"&&c>=0&&(o=Math.min(o,c))}),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 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||ce}space(e){return""}code({text:e,lang:t,escaped:n}){let r=(t||"").match(B.notSpaceStart)?.[0],s=e.replace(B.endingNewline,"")+`
46
- `;return r?'<pre><code class="language-'+V(r)+'">'+(n?s:V(s,!0))+`</code></pre>
47
- `:"<pre><code>"+(n?s:V(s,!0))+`</code></pre>
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 c=Object.keys(this.tokens.links);if(c.length>0)for(;(s=this.tokenizer.rules.inline.reflinkSearch.exec(r))!==null;)c.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="",l=1/0;for(;t;){if(t.length<l)l=t.length;else{this.infiniteLoopError(t.charCodeAt(0));break}a||(o=""),a=!1;let c;if(this.options.extensions?.inline?.some(u=>(c=u.call({lexer:this},t,n))?(t=t.substring(c.raw.length),n.push(c),!0):!1))continue;if(c=this.tokenizer.escape(t)){t=t.substring(c.raw.length),n.push(c);continue}if(c=this.tokenizer.tag(t)){t=t.substring(c.raw.length),n.push(c);continue}if(c=this.tokenizer.link(t)){t=t.substring(c.raw.length),n.push(c);continue}if(c=this.tokenizer.reflink(t,this.tokens.links)){t=t.substring(c.raw.length);let u=n.at(-1);c.type==="text"&&u?.type==="text"?(u.raw+=c.raw,u.text+=c.text):n.push(c);continue}if(c=this.tokenizer.emStrong(t,r,o)){t=t.substring(c.raw.length),n.push(c);continue}if(c=this.tokenizer.codespan(t)){t=t.substring(c.raw.length),n.push(c);continue}if(c=this.tokenizer.br(t)){t=t.substring(c.raw.length),n.push(c);continue}if(c=this.tokenizer.del(t,r,o)){t=t.substring(c.raw.length),n.push(c);continue}if(c=this.tokenizer.autolink(t)){t=t.substring(c.raw.length),n.push(c);continue}if(!this.state.inLink&&(c=this.tokenizer.url(t))){t=t.substring(c.raw.length),n.push(c);continue}let d=t;if(this.options.extensions?.startInline){let u=1/0,h=t.slice(1),g;this.options.extensions.startInline.forEach(f=>{g=f.call({lexer:this},h),typeof g=="number"&&g>=0&&(u=Math.min(u,g))}),u<1/0&&u>=0&&(d=t.substring(0,u+1))}if(c=this.tokenizer.inlineText(d)){t=t.substring(c.raw.length),c.raw.slice(-1)!=="_"&&(o=c.raw.slice(-1)),a=!0;let u=n.at(-1);u?.type==="text"?(u.raw+=c.raw,u.text+=c.text):n.push(c);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)}},Pe=class{options;parser;constructor(e){this.options=e||de}space(e){return""}code({text:e,lang:t,escaped:n}){let r=(t||"").match(U.notSpaceStart)?.[0],s=e.replace(U.endingNewline,"")+`
46
+ `;return r?'<pre><code class="language-'+Q(r)+'">'+(n?s:Q(s,!0))+`</code></pre>
47
+ `:"<pre><code>"+(n?s:Q(s,!0))+`</code></pre>
48
48
  `}blockquote({tokens:e}){return`<blockquote>
49
49
  ${this.parser.parse(e)}</blockquote>
50
50
  `}html({text:e}){return e}def(e){return""}heading({tokens:e,depth:t}){return`<h${t}>${this.parser.parseInline(e)}</h${t}>
@@ -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>${V(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=en(e);if(s===null)return r;e=s;let i='<a href="'+e+'"';return t&&(i+=' title="'+V(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=en(e);if(s===null)return V(n);e=s;let i=`<img src="${e}" alt="${V(n)}"`;return t&&(i+=` title="${V(t)}"`),i+=">",i}text(e){return"tokens"in e&&e.tokens?this.parser.parseInline(e.tokens):"escaped"in e&&e.escaped?e.text:V(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}},W=class Je{options;renderer;textRenderer;constructor(t){this.options=t||ce,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}},Ee=class{options;block;constructor(e){this.options=e||ce}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?K.lex:K.lexInline}provideParser(e=this.block){return e?W.parse:W.parseInline}},$e=class{defaults=Qe();options=this.setOptions;parse=this.parseMarkdown(!0);parseInline=this.parseMarkdown(!1);Parser=W;Renderer=Oe;TextRenderer=it;Lexer=K;Tokenizer=Ie;Hooks=Ee;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 Ie(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 Ee;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];Ee.passThroughHooks.has(i)?s[a]=l=>{if(this.defaults.async&&Ee.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 K.lex(e,t??this.defaults)}parser(e,t){return W.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?K.lex:K.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?W.parse:W.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?K.lex:K.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?W.parse:W.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>"+V(n.message+"",!0)+"</pre>";return t?Promise.resolve(r):r}if(t)return Promise.reject(n);throw n}}},le=new $e;function x(e,t){return le.parse(e,t)}x.options=x.setOptions=function(e){return le.setOptions(e),x.defaults=le.defaults,sn(x.defaults),x};x.getDefaults=Qe;x.defaults=ce;x.use=function(...e){return le.use(...e),x.defaults=le.defaults,sn(x.defaults),x};x.walkTokens=function(e,t){return le.walkTokens(e,t)};x.parseInline=le.parseInline;x.Parser=W;x.parser=W.parse;x.Renderer=Oe;x.TextRenderer=it;x.Lexer=K;x.lexer=K.lex;x.Tokenizer=Ie;x.Hooks=Ee;x.parse=x;var Oa=x.options,_a=x.setOptions,La=x.use,Pa=x.walkTokens,Ma=x.parseInline;var Na=W.parse,Ba=K.lex;var Qr=Object.defineProperty,Xr=Object.defineProperties,Yr=Object.getOwnPropertyDescriptors,gn=Object.getOwnPropertySymbols,es=Object.prototype.hasOwnProperty,ts=Object.prototype.propertyIsEnumerable,mn=(e,t,n)=>t in e?Qr(e,t,{enumerable:!0,configurable:!0,writable:!0,value:n}):e[t]=n,Sn=(e,t)=>{for(var n in t||(t={}))es.call(t,n)&&mn(e,n,t[n]);if(gn)for(var n of gn(t))ts.call(t,n)&&mn(e,n,t[n]);return e},Rn=(e,t)=>Xr(e,Yr(t)),S={PROSE:0,FENCE_MARKER:1,FENCE_INFO:2,FENCE_BODY:3,CODE_SPAN:4,CODE_SPAN_OPEN:5},ns=/^(`{3,}|~{3,})(.*)$/,rs=e=>e!==void 0&&e>="0"&&e<="9",ss=(e,t)=>{let n=t;if(e[n]==="-"||e[n]==="*"||e[n]==="+")n+=1;else{for(;rs(e[n])&&n-t<9;)n+=1;if(n===t||e[n]!=="."&&e[n]!==")")return-1;n+=1}return e[n]===" "?n+1:-1},is=(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?ss(e,a):-1;if(o===-1)return{contentStart:a,listIndent:i?a-s:0,quoteDepth:r};a=o,i=!0}},as=(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},os=(e,t,n,r,s)=>{let i=t+r;e.fill(S.FENCE_MARKER,i,i+s),e.fill(S.FENCE_INFO,i+s,Math.min(n+1,e.length))},ls=(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},cs=(e,t,n,r)=>{let s=r>n&&e[r-1]==="\r"?r-1:r,i=is(e,n,s),a=e.slice(i.contentStart,s).match(ns);if(!a)return null;let[,o,c]=a,l=o[0];return l==="`"&&c.includes("`")?null:(os(t,n,r,i.contentStart-n,o.length),{char:l,length:o.length,listIndent:i.listIndent,quoteDepth:i.quoteDepth})},us=(e,t,n,r)=>{let s=as(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},ps=(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?us(e,s,i,r):-1;r&&a===-1&&(r=null),r?ls(e,a,i,r)?(t.fill(S.FENCE_MARKER,s,i),r=null):t.fill(S.FENCE_BODY,s,Math.min(i+1,n)):r=cs(e,t,s,i),s=i+1}return r},kn=(e,t)=>{let n=t+1;for(;n<e.length&&e[n]==="`";)n+=1;return n},hs=(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
- `},ds=(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]===S.PROSE;if(t[s]===S.PROSE&&!i)return s;r=s+1}},fs=(e,t)=>{let n=e.length,r=-1,s=0,i=0;for(;i<n;){if(r<0){if(i=ds(e,t,i),i===-1)break;let o=kn(e,i);r=i,s=o-i,i=o;continue}if(t[i]!==S.PROSE){t.fill(S.CODE_SPAN_OPEN,r,i),r=-1,i+=1;continue}if(e[i]===`
67
- `&&hs(e,i)){r=-1,i+=1;continue}if(e[i]!=="`"){i+=1;continue}let a=kn(e,i);a-i===s&&(t.fill(S.CODE_SPAN,r,a),r=-1),i=a}return r>=0?(t.fill(S.CODE_SPAN_OPEN,r,n),{start:r,runLength:s}):null},gs=e=>{let t=new Uint8Array(e.length),n=ps(e,t),r=fs(e,t);return{text:e,regions:t,openFence:n,openSpan:r,mathMask:null,linkUrlMask:null,htmlTagMask:null}},ot=null,Pe=null,q=e=>{if(Pe!==null&&e===ot)return Pe;let t=gs(e);return ot=e,Pe=t,t},ms=()=>{ot=null,Pe=null},ks=(e,t)=>t>=e.regions.length?e.openFence!==null||e.openSpan!==null:t<0?!1:e.regions[t]!==S.PROSE;var bs=(e,t)=>e.regions[t]===S.CODE_SPAN,lt=(e,t)=>{let n=q(e),r=t+t,s=0;for(let i=e.indexOf(r);i!==-1;i=e.indexOf(r,i))n.regions[i]===S.PROSE?(s+=1,i+=2):i+=1;return s},ct=new Uint8Array(0),ws=e=>e==="inlineLatex"||e==="blockLatex",ys=(e,t)=>t==="["&&e==="none"?"blockLatex":t==="]"&&e==="blockLatex"?"none":t==="("&&e==="none"?"inlineLatex":t===")"&&e==="inlineLatex"?"none":null,xs=(e,t)=>t?e==="blockDollar"?"none":"blockDollar":e==="blockDollar"?e:e==="inlineDollar"?"none":"inlineDollar",Ss=e=>e.includes("$")||e.includes("\\(")||e.includes("\\["),Rs=(e,t,n)=>{let r=e[t+1];if(e[t]==="\\"){if(r==="$")return{context:n,length:2};let s=ys(n,r);return s===null?null:{context:s,length:2}}if(e[t]==="$"&&!ws(n)){let s=r==="$";return{context:xs(n,s),length:s?2:1}}return null},Es=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]===S.PROSE?Rs(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},ke=(e,t)=>t<0||t>=e.text.length?!1:(e.mathMask===null&&(e.mathMask=Ss(e.text)?Es(e):ct),e.mathMask[t]===1),vs=(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]===S.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]===S.PROSE&&(s[l]===")"?c=!1:s[l]==="("&&(c=l>0&&s[l-1]==="]"))},$s=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),vs(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("](")?$s(e):ct),e.linkUrlMask[t]===1),Cs=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]===S.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},En=(e,t)=>t<0||t>=e.text.length?!1:(e.htmlTagMask===null&&(e.htmlTagMask=e.text.includes("<")?Cs(e):ct),e.htmlTagMask[t]===1),z=(e,t)=>ks(q(e),t),ee=(e,t)=>bs(q(e),t),Ts=/^(\s*(?:[-*+]|\d+[.)]) +)>(=?\s*[$]?\d)/gm,As=e=>!e||typeof e!="string"||!e.includes(">")?e:e.replace(Ts,(t,n,r,s)=>z(e,s)?t:`${n}\\>${r}`),te=(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)},Is={delimiter:"*",markerLength:2,regex:/(\*\*)([^*]*\*?)$/},Os={delimiter:"_",markerLength:2,regex:/(__)([^_]*?)$/},_s={delimiter:"*",markerLength:3,regex:/(\*\*\*)([^*]*?)$/},Ls={delimiter:"*",markerLength:1,regex:/(\*)([^*]*?)$/},Ps={delimiter:"_",markerLength:1,regex:/(_)([^_]*?)$/},Ms={delimiter:"~",markerLength:2,regex:/(~~)([^~]*?)$/},Ns={delimiter:"_",markerLength:2,regex:/(__)([^_]+)_$/},Bs={delimiter:"~",markerLength:2,regex:/(~~)([^~]+)~$/},ue=/^[\s_~*`]*$/,vn=/^[\s]*[-*+][\s]+$/,Ds=/[\p{L}\p{N}_]/u,zs=/^\*{4,}$/,G=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:Ds.test(e)};var Us=(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},$n=(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},js=(e,t)=>ke(q(e),t);var Be=(e,t,n)=>{let r=0;for(let c=t-1;c>=0;c-=1)if(e[c]===`
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},Hs=(e,t,n,r)=>n==="\\"||ke(e,t)?!0:n!=="*"&&r==="*"?(t<e.text.length-2?e.text[t+2]:"")!=="*":n==="*"||(!n||n===" "||n===" "||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>${Q(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=rn(e);if(s===null)return r;e=s;let i='<a href="'+e+'"';return t&&(i+=' title="'+Q(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=rn(e);if(s===null)return Q(n);e=s;let i=`<img src="${e}" alt="${Q(n)}"`;return t&&(i+=` title="${Q(t)}"`),i+=">",i}text(e){return"tokens"in e&&e.tokens?this.parser.parseInline(e.tokens):"escaped"in e&&e.escaped?e.text:Q(e.text)}},lt=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}},W=class Ye{options;renderer;textRenderer;constructor(t){this.options=t||de,this.options.renderer=this.options.renderer||new Pe,this.renderer=this.options.renderer,this.renderer.options=this.options,this.renderer.parser=this,this.textRenderer=new lt}static parse(t,n){return new Ye(n).parse(t)}static parseInline(t,n){return new Ye(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}},Ce=class{options;block;constructor(e){this.options=e||de}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?K.lex:K.lexInline}provideParser(e=this.block){return e?W.parse:W.parseInline}},Ae=class{defaults=et();options=this.setOptions;parse=this.parseMarkdown(!0);parseInline=this.parseMarkdown(!1);Parser=W;Renderer=Pe;TextRenderer=lt;Lexer=K;Tokenizer=Le;Hooks=Ce;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 Pe(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],l=s[a];s[a]=(...c)=>{let d=o.apply(s,c);return d===!1&&(d=l.apply(s,c)),d||""}}r.renderer=s}if(n.tokenizer){let s=this.defaults.tokenizer||new Le(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],l=s[a];s[a]=(...c)=>{let d=o.apply(s,c);return d===!1&&(d=l.apply(s,c)),d}}r.tokenizer=s}if(n.hooks){let s=this.defaults.hooks||new Ce;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],l=s[a];Ce.passThroughHooks.has(i)?s[a]=c=>{if(this.defaults.async&&Ce.passThroughHooksRespectAsync.has(i))return(async()=>{let u=await o.call(s,c);return l.call(s,u)})();let d=o.call(s,c);return l.call(s,d)}:s[a]=(...c)=>{if(this.defaults.async)return(async()=>{let u=await o.apply(s,c);return u===!1&&(u=await l.apply(s,c)),u})();let d=o.apply(s,c);return d===!1&&(d=l.apply(s,c)),d}}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 K.lex(e,t??this.defaults)}parser(e,t){return W.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?K.lex:K.lexInline)(a,s),l=s.hooks?await s.hooks.processAllTokens(o):o;s.walkTokens&&await Promise.all(this.walkTokens(l,s.walkTokens));let c=await(s.hooks?await s.hooks.provideParser(e):e?W.parse:W.parseInline)(l,s);return s.hooks?await s.hooks.postprocess(c):c})().catch(i);try{s.hooks&&(t=s.hooks.preprocess(t));let a=(s.hooks?s.hooks.provideLexer(e):e?K.lex:K.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?W.parse:W.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>"+Q(n.message+"",!0)+"</pre>";return t?Promise.resolve(r):r}if(t)return Promise.reject(n);throw n}}},he=new Ae;function S(e,t){return he.parse(e,t)}S.options=S.setOptions=function(e){return he.setOptions(e),S.defaults=he.defaults,ln(S.defaults),S};S.getDefaults=et;S.defaults=de;S.use=function(...e){return he.use(...e),S.defaults=he.defaults,ln(S.defaults),S};S.walkTokens=function(e,t){return he.walkTokens(e,t)};S.parseInline=he.parseInline;S.Parser=W;S.parser=W.parse;S.Renderer=Pe;S.TextRenderer=lt;S.Lexer=K;S.lexer=K.lex;S.Tokenizer=Le;S.Hooks=Ce;S.parse=S;var Da=S.options,za=S.setOptions,Ua=S.use,ja=S.walkTokens,Ha=S.parseInline;var qa=W.parse,Fa=K.lex;var es=Object.defineProperty,ts=Object.defineProperties,ns=Object.getOwnPropertyDescriptors,bn=Object.getOwnPropertySymbols,rs=Object.prototype.hasOwnProperty,ss=Object.prototype.propertyIsEnumerable,wn=(e,t,n)=>t in e?es(e,t,{enumerable:!0,configurable:!0,writable:!0,value:n}):e[t]=n,En=(e,t)=>{for(var n in t||(t={}))rs.call(t,n)&&wn(e,n,t[n]);if(bn)for(var n of bn(t))ss.call(t,n)&&wn(e,n,t[n]);return e},$n=(e,t)=>ts(e,ns(t)),C={PROSE:0,FENCE_MARKER:1,FENCE_INFO:2,FENCE_BODY:3,CODE_SPAN:4,CODE_SPAN_OPEN:5},is=/^(`{3,}|~{3,})(.*)$/,as=e=>e!==void 0&&e>="0"&&e<="9",os=(e,t)=>{let n=t;if(e[n]==="-"||e[n]==="*"||e[n]==="+")n+=1;else{for(;as(e[n])&&n-t<9;)n+=1;if(n===t||e[n]!=="."&&e[n]!==")")return-1;n+=1}return e[n]===" "?n+1:-1},ls=(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?os(e,a):-1;if(o===-1)return{contentStart:a,listIndent:i?a-s:0,quoteDepth:r};a=o,i=!0}},cs=(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},us=(e,t,n,r,s)=>{let i=t+r;e.fill(C.FENCE_MARKER,i,i+s),e.fill(C.FENCE_INFO,i+s,Math.min(n+1,e.length))},ps=(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},hs=(e,t,n,r)=>{let s=r>n&&e[r-1]==="\r"?r-1:r,i=ls(e,n,s),a=e.slice(i.contentStart,s).match(is);if(!a)return null;let[,o,l]=a,c=o[0];return c==="`"&&l.includes("`")?null:(us(t,n,r,i.contentStart-n,o.length),{char:c,length:o.length,listIndent:i.listIndent,quoteDepth:i.quoteDepth})},ds=(e,t,n,r)=>{let s=cs(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},fs=(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?ds(e,s,i,r):-1;r&&a===-1&&(r=null),r?ps(e,a,i,r)?(t.fill(C.FENCE_MARKER,s,i),r=null):t.fill(C.FENCE_BODY,s,Math.min(i+1,n)):r=hs(e,t,s,i),s=i+1}return r},yn=(e,t)=>{let n=t+1;for(;n<e.length&&e[n]==="`";)n+=1;return n},gs=(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
+ `},ms=(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]===C.PROSE;if(t[s]===C.PROSE&&!i)return s;r=s+1}},ks=(e,t)=>{let n=e.length,r=-1,s=0,i=0;for(;i<n;){if(r<0){if(i=ms(e,t,i),i===-1)break;let o=yn(e,i);r=i,s=o-i,i=o;continue}if(t[i]!==C.PROSE){t.fill(C.CODE_SPAN_OPEN,r,i),r=-1,i+=1;continue}if(e[i]===`
67
+ `&&gs(e,i)){r=-1,i+=1;continue}if(e[i]!=="`"){i+=1;continue}let a=yn(e,i);a-i===s&&(t.fill(C.CODE_SPAN,r,a),r=-1),i=a}return r>=0?(t.fill(C.CODE_SPAN_OPEN,r,n),{start:r,runLength:s}):null},bs=e=>{let t=new Uint8Array(e.length),n=fs(e,t),r=ks(e,t);return{text:e,regions:t,openFence:n,openSpan:r,mathMask:null,linkUrlMask:null,htmlTagMask:null}},ut=null,Be=null,F=e=>{if(Be!==null&&e===ut)return Be;let t=bs(e);return ut=e,Be=t,t},ws=()=>{ut=null,Be=null},ys=(e,t)=>t>=e.regions.length?e.openFence!==null||e.openSpan!==null:t<0?!1:e.regions[t]!==C.PROSE;var xs=(e,t)=>e.regions[t]===C.CODE_SPAN,pt=(e,t)=>{let n=F(e),r=t+t,s=0;for(let i=e.indexOf(r);i!==-1;i=e.indexOf(r,i))n.regions[i]===C.PROSE?(s+=1,i+=2):i+=1;return s},ht=new Uint8Array(0),Ss=e=>e==="inlineLatex"||e==="blockLatex",vs=(e,t)=>t==="["&&e==="none"?"blockLatex":t==="]"&&e==="blockLatex"?"none":t==="("&&e==="none"?"inlineLatex":t===")"&&e==="inlineLatex"?"none":null,Rs=(e,t)=>t?e==="blockDollar"?"none":"blockDollar":e==="blockDollar"?e:e==="inlineDollar"?"none":"inlineDollar",Es=e=>e.includes("$")||e.includes("\\(")||e.includes("\\["),$s=(e,t,n)=>{let r=e[t+1];if(e[t]==="\\"){if(r==="$")return{context:n,length:2};let s=vs(n,r);return s===null?null:{context:s,length:2}}if(e[t]==="$"&&!Ss(n)){let s=r==="$";return{context:Rs(n,s),length:s?2:1}}return null},Cs=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]===C.PROSE?$s(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},xe=(e,t)=>t<0||t>=e.text.length?!1:(e.mathMask===null&&(e.mathMask=Es(e.text)?Cs(e):ht),e.mathMask[t]===1),Is=(e,t,n,r)=>{let{text:s,regions:i}=e,a=new Uint8Array(n-t),o=0;for(let c=n-1;c>=t;c-=1)s[c]===")"&&i[c]===C.PROSE&&(o=1),a[c-t]=o;let l=!1;for(let c=t;c<n;c+=1)l&&a[c-t]===1&&(r[c]=1),i[c]===C.PROSE&&(s[c]===")"?l=!1:s[c]==="("&&(l=c>0&&s[c-1]==="]"))},As=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),Is(e,s,i,r),s=i+1}return r},dt=(e,t)=>t<0||t>=e.text.length?!1:(e.linkUrlMask===null&&(e.linkUrlMask=e.text.includes("](")?As(e):ht),e.linkUrlMask[t]===1),Ts=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]===C.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},Cn=(e,t)=>t<0||t>=e.text.length?!1:(e.htmlTagMask===null&&(e.htmlTagMask=e.text.includes("<")?Ts(e):ht),e.htmlTagMask[t]===1),H=(e,t)=>ys(F(e),t),ae=(e,t)=>xs(F(e),t),Os=/^(\s*(?:[-*+]|\d+[.)]) +)>(=?\s*[$]?\d)/gm,_s=e=>!e||typeof e!="string"||!e.includes(">")?e:e.replace(Os,(t,n,r,s)=>H(e,s)?t:`${n}\\>${r}`),oe=(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)},Ls={delimiter:"*",markerLength:2,regex:/(\*\*)([^*]*\*?)$/},Ps={delimiter:"_",markerLength:2,regex:/(__)([^_]*?)$/},Ms={delimiter:"*",markerLength:3,regex:/(\*\*\*)([^*]*?)$/},Ns={delimiter:"*",markerLength:1,regex:/(\*)([^*]*?)$/},Bs={delimiter:"_",markerLength:1,regex:/(_)([^_]*?)$/},Ds={delimiter:"~",markerLength:2,regex:/(~~)([^~]*?)$/},zs={delimiter:"_",markerLength:2,regex:/(__)([^_]+)_$/},Us={delimiter:"~",markerLength:2,regex:/(~~)([^~]+)~$/},fe=/^[\s_~*`]*$/,In=/^[\s]*[-*+][\s]+$/,js=/[\p{L}\p{N}_]/u,Hs=/^\*{4,}$/,G=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:js.test(e)};var qs=(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},An=(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},Fs=(e,t)=>xe(F(e),t);var Ue=(e,t,n)=>{let r=0;for(let l=t-1;l>=0;l-=1)if(e[l]===`
70
+ `){r=l+1;break}let s=e.length;for(let l=t;l<e.length;l+=1)if(e[l]===`
71
+ `){s=l;break}let i=e.substring(r,s),a=0,o=!1;for(let l of i)if(l===n)a+=1;else if(l!==" "&&l!==" "){o=!0;break}return a>=3&&!o},Ks=(e,t,n,r)=>n==="\\"||xe(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
- `),Me=e=>e===" "||e===" "||e===`
74
- `,qs=(e,t)=>!!(e&&t&&G(e)&&G(t)),Fs=(e,t,n,r)=>{let s=qs(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}},Cn=e=>{let t=q(e),n=0,r=!1,s=e.length;for(let i=0;i<s;i+=1){if(e[i]!=="*"||t.regions[i]!==S.PROSE){G(e[i])||(r=!1);continue}let a=i>0?e[i-1]:"",o=i<s-1?e[i+1]:"";if(Hs(t,i,a,o))continue;let c=Fs(a,o,n,r);c.count&&(n+=1,r=c.inWordAsteriskChain)}return n},Ks=(e,t,n,r)=>!!(n==="\\"||ke(e,t)||ut(e,t)||En(e,t)||n==="_"||r==="_"||n&&r&&G(n)&&G(r)),Ws=e=>{let t=q(e),n=0,r=e.length;for(let s=0;s<r;s+=1){if(e[s]!=="_"||t.regions[s]!==S.PROSE)continue;let i=s>0?e[s-1]:"",a=s<r-1?e[s+1]:"";Ks(t,s,i,a)||(n+=1)}return n},Gs=e=>{let t=q(e),n=0,r=0;for(let s=0;s<e.length;s+=1)e[s]==="*"&&t.regions[s]===S.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,"*"),bn=e=>e===""||e===" "||e===" "||e===`
75
- `,Zs=(e,t,n,r,s)=>{if(!(bn(n)&&bn(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},Vs=(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 G(l)&&G(p)||Zs(s,i,l,p,r)||ke(e,i)||ut(e,i)||En(e,i)?!1:Math.floor(o/2)%2===1},wn=e=>{let t=q(e),n=e.length,r={lineEnd:-1,result:!1},s=!1,i=0;for(;i<n;){if(e[i]!=="_"||t.regions[i]!==S.PROSE){i+=1;continue}let a=i,o=i+1;for(;o<n&&e[o]==="_"&&t.regions[o]===S.PROSE;)o+=1;i=o,Vs(t,a,o,r)&&(s=!s)}return s},Js=(e,t,n)=>{if(!t||ue.test(t))return!0;let r=e.substring(0,n).lastIndexOf(`
77
- `),s=r===-1?0:r+1,i=e.substring(s,n);return vn.test(i)&&t.includes(`
78
- `)?!0:Be(e,n,"*")},Qs=e=>{let t=te(e,Is);if(!t)return e;let n=t[2],r=e.lastIndexOf(t[1]);return z(e,r)||ee(e,r)||Js(e,n,r)?e:pt(e)%2===1?n.endsWith("*")?`${e}*`:`${e}**`:e},Xs=(e,t,n)=>{if(!t||ue.test(t))return!0;let r=e.substring(0,n).lastIndexOf(`
79
- `),s=r===-1?0:r+1,i=e.substring(s,n);return vn.test(i)&&t.includes(`
80
- `)?!0:Be(e,n,"_")},Ys=e=>{let t=te(e,Os);if(!t){let s=te(e,Ns);if(s){let i=e.lastIndexOf(s[1]);if(!(z(e,i)||ee(e,i))&&wn(e))return`${e}_`}return e}let n=t[2],r=e.lastIndexOf(t[1]);return z(e,r)||ee(e,r)||Xs(e,n,r)?e:wn(e)?`${e}__`:e},ei=(e,t)=>{let{text:n}=e;return n[t]==="*"&&e.regions[t]===S.PROSE&&n[t-1]!=="*"&&n[t+1]!=="*"&&n[t-1]!=="\\"&&!ke(e,t)},ti=e=>{let t=q(e);for(let n=e.indexOf("*");n!==-1;n=e.indexOf("*",n+1)){if(!ei(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&&G(r)&&G(s))&&!a)return n}return-1},ni=e=>{if(!te(e,Ls))return e;let t=ti(e);if(t===-1||z(e,t)||ee(e,t))return e;let n=e.substring(t+1);return!n||ue.test(n)?e:Cn(e)%2===1?`${e}*`:e},Tn=e=>{let t=q(e);for(let n=e.indexOf("_");n!==-1;n=e.indexOf("_",n+1))if(t.regions[n]===S.PROSE&&e[n-1]!=="_"&&e[n+1]!=="_"&&e[n-1]!=="\\"&&!ke(t,n)&&!ut(t,n)){let r=n>0?e[n-1]:"",s=n<e.length-1?e[n+1]:"";if(r&&s&&G(r)&&G(s))continue;return n}return-1},ri=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}_`},si=e=>{if(!e.endsWith("**"))return null;let t=e.slice(0,-2);if(pt(t)%2!==1)return null;let n=t.indexOf("**"),r=Tn(t);return n!==-1&&r!==-1&&n<r?`${t}_**`:null},ii=e=>{if(!te(e,Ps))return e;let t=Tn(e);if(t===-1)return e;let n=e.substring(t+1);if(!n||ue.test(n)||z(e,t)||ee(e,t))return e;if(Ws(e)%2===1){let r=si(e);return r!==null?r:ri(e)}return e},ai=e=>{let t=pt(e),n=Cn(e);return t%2===0&&n%2===0},oi=(e,t,n)=>!t||ue.test(t)||z(e,n)||ee(e,n)?!0:Be(e,n,"*"),li=e=>{if(zs.test(e))return e;let t=te(e,_s);if(!t)return e;let n=t[2],r=e.lastIndexOf(t[1]);return oi(e,n,r)?e:Gs(e)%2===1?ai(e)?e:`${e}***`:e},ci=/<[a-zA-Z/][^>]*$/,ui=/[a-zA-Z/]/,pi=e=>e.includes("$")||e.includes("\\(")||e.includes("\\["),hi=(e,t)=>{let n=e[t+1];return n!==void 0&&ui.test(n)},di=e=>{let t=e.match(ci);if(!t||t.index===void 0)return e;let n=pi(e);for(let r=t.index;r<e.length;r+=1)if(!(e[r]!=="<"||!hi(e,r))&&!z(e,r)&&!(n&&js(e,r)))return e.substring(0,r).trimEnd();return e},fi=e=>{let t=q(e);if(t.openFence)return e;let n=t.openSpan;if(!n)return e;let r=e.slice(n.start+n.runLength);if(!r||ue.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)},gi=e=>lt(e,"$"),mi=e=>{let t=q(e),n=0;for(let r=0;r<e.length;r+=1){if(e[r]==="\\"){r+=1;continue}t.regions[r]===S.PROSE&&e[r]==="$"&&(r+1<e.length&&e[r+1]==="$"?r+=1:n+=1)}return n},ki=e=>{if(e.endsWith("$")&&!e.endsWith("$$"))return`${e}$`;let t=e.indexOf("$$");return t!==-1&&e.indexOf(`
73
+ `),De=e=>e===" "||e===" "||e===`
74
+ `,Ws=(e,t)=>!!(e&&t&&G(e)&&G(t)),Gs=(e,t,n,r)=>{let s=Ws(e,t),i=!!t&&!De(t),a=!!e&&!De(e);return s&&n%2===0&&!r?{count:!1}:a&&n%2===1||i?{count:!0,inWordAsteriskChain:s}:{count:!1}},Tn=e=>{let t=F(e),n=0,r=!1,s=e.length;for(let i=0;i<s;i+=1){if(e[i]!=="*"||t.regions[i]!==C.PROSE){G(e[i])||(r=!1);continue}let a=i>0?e[i-1]:"",o=i<s-1?e[i+1]:"";if(Ks(t,i,a,o))continue;let l=Gs(a,o,n,r);l.count&&(n+=1,r=l.inWordAsteriskChain)}return n},Zs=(e,t,n,r)=>!!(n==="\\"||xe(e,t)||dt(e,t)||Cn(e,t)||n==="_"||r==="_"||n&&r&&G(n)&&G(r)),Vs=e=>{let t=F(e),n=0,r=e.length;for(let s=0;s<r;s+=1){if(e[s]!=="_"||t.regions[s]!==C.PROSE)continue;let i=s>0?e[s-1]:"",a=s<r-1?e[s+1]:"";Zs(t,s,i,a)||(n+=1)}return n},Js=e=>{let t=F(e),n=0,r=0;for(let s=0;s<e.length;s+=1)e[s]==="*"&&t.regions[s]===C.PROSE?r+=1:(r>=3&&(n+=Math.floor(r/3)),r=0);return r>=3&&(n+=Math.floor(r/3)),n},ft=e=>pt(e,"*"),xn=e=>e===""||e===" "||e===" "||e===`
75
+ `,Qs=(e,t,n,r,s)=>{if(!(xn(n)&&xn(r)))return!1;if(t>s.lineEnd){let i=e.indexOf(`
76
+ `,t);s.lineEnd=i===-1?e.length:i,s.result=Ue(e,t,"_")}return s.result},Xs=(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 l=i>0?s[i-1]:"",c=a?"\\":l,d=n<s.length?s[n]:"";return G(c)&&G(d)||Qs(s,i,c,d,r)||xe(e,i)||dt(e,i)||Cn(e,i)?!1:Math.floor(o/2)%2===1},Sn=e=>{let t=F(e),n=e.length,r={lineEnd:-1,result:!1},s=!1,i=0;for(;i<n;){if(e[i]!=="_"||t.regions[i]!==C.PROSE){i+=1;continue}let a=i,o=i+1;for(;o<n&&e[o]==="_"&&t.regions[o]===C.PROSE;)o+=1;i=o,Xs(t,a,o,r)&&(s=!s)}return s},Ys=(e,t,n)=>{if(!t||fe.test(t))return!0;let r=e.substring(0,n).lastIndexOf(`
77
+ `),s=r===-1?0:r+1,i=e.substring(s,n);return In.test(i)&&t.includes(`
78
+ `)?!0:Ue(e,n,"*")},ei=e=>{let t=oe(e,Ls);if(!t)return e;let n=t[2],r=e.lastIndexOf(t[1]);return H(e,r)||ae(e,r)||Ys(e,n,r)?e:ft(e)%2===1?n.endsWith("*")?`${e}*`:`${e}**`:e},ti=(e,t,n)=>{if(!t||fe.test(t))return!0;let r=e.substring(0,n).lastIndexOf(`
79
+ `),s=r===-1?0:r+1,i=e.substring(s,n);return In.test(i)&&t.includes(`
80
+ `)?!0:Ue(e,n,"_")},ni=e=>{let t=oe(e,Ps);if(!t){let s=oe(e,zs);if(s){let i=e.lastIndexOf(s[1]);if(!(H(e,i)||ae(e,i))&&Sn(e))return`${e}_`}return e}let n=t[2],r=e.lastIndexOf(t[1]);return H(e,r)||ae(e,r)||ti(e,n,r)?e:Sn(e)?`${e}__`:e},ri=(e,t)=>{let{text:n}=e;return n[t]==="*"&&e.regions[t]===C.PROSE&&n[t-1]!=="*"&&n[t+1]!=="*"&&n[t-1]!=="\\"&&!xe(e,t)},si=e=>{let t=F(e);for(let n=e.indexOf("*");n!==-1;n=e.indexOf("*",n+1)){if(!ri(t,n))continue;let r=n>0?e[n-1]:"",s=n<e.length-1?e[n+1]:"",i=!r||De(r),a=!s||De(s);if(!(i&&a)&&!(r&&s&&G(r)&&G(s))&&!a)return n}return-1},ii=e=>{if(!oe(e,Ns))return e;let t=si(e);if(t===-1||H(e,t)||ae(e,t))return e;let n=e.substring(t+1);return!n||fe.test(n)?e:Tn(e)%2===1?`${e}*`:e},On=e=>{let t=F(e);for(let n=e.indexOf("_");n!==-1;n=e.indexOf("_",n+1))if(t.regions[n]===C.PROSE&&e[n-1]!=="_"&&e[n+1]!=="_"&&e[n-1]!=="\\"&&!xe(t,n)&&!dt(t,n)){let r=n>0?e[n-1]:"",s=n<e.length-1?e[n+1]:"";if(r&&s&&G(r)&&G(s))continue;return n}return-1},ai=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}_`},oi=e=>{if(!e.endsWith("**"))return null;let t=e.slice(0,-2);if(ft(t)%2!==1)return null;let n=t.indexOf("**"),r=On(t);return n!==-1&&r!==-1&&n<r?`${t}_**`:null},li=e=>{if(!oe(e,Bs))return e;let t=On(e);if(t===-1)return e;let n=e.substring(t+1);if(!n||fe.test(n)||H(e,t)||ae(e,t))return e;if(Vs(e)%2===1){let r=oi(e);return r!==null?r:ai(e)}return e},ci=e=>{let t=ft(e),n=Tn(e);return t%2===0&&n%2===0},ui=(e,t,n)=>!t||fe.test(t)||H(e,n)||ae(e,n)?!0:Ue(e,n,"*"),pi=e=>{if(Hs.test(e))return e;let t=oe(e,Ms);if(!t)return e;let n=t[2],r=e.lastIndexOf(t[1]);return ui(e,n,r)?e:Js(e)%2===1?ci(e)?e:`${e}***`:e},hi=/<[a-zA-Z/][^>]*$/,di=/[a-zA-Z/]/,fi=e=>e.includes("$")||e.includes("\\(")||e.includes("\\["),gi=(e,t)=>{let n=e[t+1];return n!==void 0&&di.test(n)},mi=e=>{let t=e.match(hi);if(!t||t.index===void 0)return e;let n=fi(e);for(let r=t.index;r<e.length;r+=1)if(!(e[r]!=="<"||!gi(e,r))&&!H(e,r)&&!(n&&Fs(e,r)))return e.substring(0,r).trimEnd();return e},ki=e=>{let t=F(e);if(t.openFence)return e;let n=t.openSpan;if(!n)return e;let r=e.slice(n.start+n.runLength);if(!r||fe.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)},bi=e=>pt(e,"$"),wi=e=>{let t=F(e),n=0;for(let r=0;r<e.length;r+=1){if(e[r]==="\\"){r+=1;continue}t.regions[r]===C.PROSE&&e[r]==="$"&&(r+1<e.length&&e[r+1]==="$"?r+=1:n+=1)}return n},yi=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}$$`},bi=e=>gi(e)%2===0?e:ki(e),wi=e=>mi(e)%2===1?`${e}$`:e,Ne="streamdown:incomplete-image",yi=(e,t,n)=>{if(e.substring(t+2).includes(")"))return null;let r=Us(e,t);if(r===-1||z(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)`},yn=(e,t)=>{for(let n=0;n<t;n++)if(e[n]==="["&&!z(e,n)){if(n>0&&e[n-1]==="!")continue;let r=$n(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},xi=(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=yn(e,t);return e.substring(0,a)+e.substring(a+1)}return`${e}](streamdown:incomplete-link)`}if($n(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=yn(e,t);return e.substring(0,a)+e.substring(a+1)}return`${e}](streamdown:incomplete-link)`}return null},Si=(e,t)=>{let n=e.lastIndexOf("](");if(n!==-1&&!z(e,n)){let r=yi(e,n,t);if(r!==null)return r}for(let r=e.lastIndexOf("[");r!==-1;r=r===0?-1:e.lastIndexOf("[",r-1))if(!z(e,r)){let s=xi(e,r,t);if(s!==null)return s}return e},Ri=32,An=(e,t="protocol")=>{let n=e;for(let r=0;r<Ri;r+=1){let s=Si(n,t);if(s.length>=n.length)return s;n=s}return n},Ei=/^-{1,2}$/,vi=/^[\s]*-{1,2}[\s]+$/,$i=/^={1,2}$/,Ci=/^[\s]*={1,2}[\s]+$/,Ti=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(Ei.test(s)&&!n.match(vi)){let i=r.split(`
86
- `).at(-1);if(i&&i.trim().length>0)return`${e}\u200B`}if($i.test(s)&&!n.match(Ci)){let i=r.split(`
87
- `).at(-1);if(i&&i.trim().length>0)return`${e}\u200B`}return e},Ai=/([\p{L}\p{N}_])~(?!~)(?=[\p{L}\p{N}_])/gu,Ii=e=>!e||typeof e!="string"||!e.includes("~")?e:e.replace(Ai,(t,n,r)=>{let s=r+n.length;return z(e,s)?t:`${n}\\~`}),xn=e=>lt(e,"~"),Oi=e=>{let t=te(e,Ms);if(t){let n=t[2];if(!n||ue.test(n))return e;let r=e.lastIndexOf(t[1]);if(z(e,r)||ee(e,r))return e;if(xn(e)%2===1)return`${e}~~`}else{let n=te(e,Bs);if(n){let r=e.lastIndexOf(n[0].slice(0,2));if(z(e,r)||ee(e,r))return e;if(xn(e)%2===1)return`${e}~`}}return e},at=e=>e!==!1,_i=e=>e===!0,D={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},Li=[{handler:{name:"singleTilde",handle:Ii,priority:D.SINGLE_TILDE},optionKey:"singleTilde"},{handler:{name:"comparisonOperators",handle:As,priority:D.COMPARISON_OPERATORS},optionKey:"comparisonOperators"},{handler:{name:"htmlTags",handle:di,priority:D.HTML_TAGS},optionKey:"htmlTags"},{handler:{name:"setextHeadings",handle:Ti,priority:D.SETEXT_HEADINGS},optionKey:"setextHeadings"},{handler:{name:"links",handle:An,priority:D.LINKS},optionKey:"links",earlyReturn:e=>e.endsWith("](streamdown:incomplete-link)")||e.endsWith(`](${Ne})`)},{handler:{name:"boldItalic",handle:li,priority:D.BOLD_ITALIC},optionKey:"boldItalic"},{handler:{name:"bold",handle:Qs,priority:D.BOLD},optionKey:"bold"},{handler:{name:"italicDoubleUnderscore",handle:Ys,priority:D.ITALIC_DOUBLE_UNDERSCORE},optionKey:"italic"},{handler:{name:"italicSingleAsterisk",handle:ni,priority:D.ITALIC_SINGLE_ASTERISK},optionKey:"italic"},{handler:{name:"italicSingleUnderscore",handle:ii,priority:D.ITALIC_SINGLE_UNDERSCORE},optionKey:"italic"},{handler:{name:"inlineCode",handle:fi,priority:D.INLINE_CODE},optionKey:"inlineCode"},{handler:{name:"strikethrough",handle:Oi,priority:D.STRIKETHROUGH},optionKey:"strikethrough"},{handler:{name:"katex",handle:bi,priority:D.KATEX},optionKey:"katex"},{handler:{name:"inlineKatex",handle:wi,priority:D.INLINE_KATEX},optionKey:"inlineKatex"}],Pi=e=>{var t;let n=(t=e?.linkMode)!=null?t:"protocol";return Li.filter(({handler:r,optionKey:s})=>r.name==="links"?at(e?.links)||at(e?.images):r.name==="inlineKatex"?_i(e?.inlineKatex):at(e?.[s])).map(({handler:r,earlyReturn:s})=>r.name==="links"?{handler:Rn(Sn({},r),{handle:i=>An(i,n)}),earlyReturn:n==="protocol"?s:void 0}:{handler:r,earlyReturn:s})},Mi=(e,t)=>{var n;if(!e||typeof e!="string")return e;let r=e.endsWith(" ")&&!e.endsWith(" ")?e.slice(0,-1):e,s=Pi(t),i=((n=t?.handlers)!=null?n:[]).map(o=>{var c;return{handler:Rn(Sn({},o),{priority:(c=o.priority)!=null?c:D.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{ms()}},ht=Mi;var dt=e=>e===void 0||/\s/.test(e);function _n(e,t){if(e[t]!==`
84
+ $$`:`${e}$$`},xi=e=>bi(e)%2===0?e:yi(e),Si=e=>wi(e)%2===1?`${e}$`:e,ze="streamdown:incomplete-image",vi=(e,t,n)=>{if(e.substring(t+2).includes(")"))return null;let r=qs(e,t);if(r===-1||H(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}](${ze})`:n==="text-only"?`${a}${o}`:`${a}[${o}](streamdown:incomplete-link)`},vn=(e,t)=>{for(let n=0;n<t;n++)if(e[n]==="["&&!H(e,n)){if(n>0&&e[n-1]==="!")continue;let r=An(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},Ri=(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}](${ze})`}if(n==="text-only"){let a=vn(e,t);return e.substring(0,a)+e.substring(a+1)}return`${e}](streamdown:incomplete-link)`}if(An(e,t)===-1){let i=e.substring(0,s);if(r){let a=e.substring(t+1);return`${i}![${a}](${ze})`}if(n==="text-only"){let a=vn(e,t);return e.substring(0,a)+e.substring(a+1)}return`${e}](streamdown:incomplete-link)`}return null},Ei=(e,t)=>{let n=e.lastIndexOf("](");if(n!==-1&&!H(e,n)){let r=vi(e,n,t);if(r!==null)return r}for(let r=e.lastIndexOf("[");r!==-1;r=r===0?-1:e.lastIndexOf("[",r-1))if(!H(e,r)){let s=Ri(e,r,t);if(s!==null)return s}return e},$i=32,_n=(e,t="protocol")=>{let n=e;for(let r=0;r<$i;r+=1){let s=Ei(n,t);if(s.length>=n.length)return s;n=s}return n},Ci=/^-{1,2}$/,Ii=/^[\s]*-{1,2}[\s]+$/,Ai=/^={1,2}$/,Ti=/^[\s]*={1,2}[\s]+$/,Oi=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(Ci.test(s)&&!n.match(Ii)){let i=r.split(`
86
+ `).at(-1);if(i&&i.trim().length>0)return`${e}\u200B`}if(Ai.test(s)&&!n.match(Ti)){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,Li=e=>!e||typeof e!="string"||!e.includes("~")?e:e.replace(_i,(t,n,r)=>{let s=r+n.length;return H(e,s)?t:`${n}\\~`}),Rn=e=>pt(e,"~"),Pi=e=>{let t=oe(e,Ds);if(t){let n=t[2];if(!n||fe.test(n))return e;let r=e.lastIndexOf(t[1]);if(H(e,r)||ae(e,r))return e;if(Rn(e)%2===1)return`${e}~~`}else{let n=oe(e,Us);if(n){let r=e.lastIndexOf(n[0].slice(0,2));if(H(e,r)||ae(e,r))return e;if(Rn(e)%2===1)return`${e}~`}}return e},ct=e=>e!==!1,Mi=e=>e===!0,j={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},Ni=[{handler:{name:"singleTilde",handle:Li,priority:j.SINGLE_TILDE},optionKey:"singleTilde"},{handler:{name:"comparisonOperators",handle:_s,priority:j.COMPARISON_OPERATORS},optionKey:"comparisonOperators"},{handler:{name:"htmlTags",handle:mi,priority:j.HTML_TAGS},optionKey:"htmlTags"},{handler:{name:"setextHeadings",handle:Oi,priority:j.SETEXT_HEADINGS},optionKey:"setextHeadings"},{handler:{name:"links",handle:_n,priority:j.LINKS},optionKey:"links",earlyReturn:e=>e.endsWith("](streamdown:incomplete-link)")||e.endsWith(`](${ze})`)},{handler:{name:"boldItalic",handle:pi,priority:j.BOLD_ITALIC},optionKey:"boldItalic"},{handler:{name:"bold",handle:ei,priority:j.BOLD},optionKey:"bold"},{handler:{name:"italicDoubleUnderscore",handle:ni,priority:j.ITALIC_DOUBLE_UNDERSCORE},optionKey:"italic"},{handler:{name:"italicSingleAsterisk",handle:ii,priority:j.ITALIC_SINGLE_ASTERISK},optionKey:"italic"},{handler:{name:"italicSingleUnderscore",handle:li,priority:j.ITALIC_SINGLE_UNDERSCORE},optionKey:"italic"},{handler:{name:"inlineCode",handle:ki,priority:j.INLINE_CODE},optionKey:"inlineCode"},{handler:{name:"strikethrough",handle:Pi,priority:j.STRIKETHROUGH},optionKey:"strikethrough"},{handler:{name:"katex",handle:xi,priority:j.KATEX},optionKey:"katex"},{handler:{name:"inlineKatex",handle:Si,priority:j.INLINE_KATEX},optionKey:"inlineKatex"}],Bi=e=>{var t;let n=(t=e?.linkMode)!=null?t:"protocol";return Ni.filter(({handler:r,optionKey:s})=>r.name==="links"?ct(e?.links)||ct(e?.images):r.name==="inlineKatex"?Mi(e?.inlineKatex):ct(e?.[s])).map(({handler:r,earlyReturn:s})=>r.name==="links"?{handler:$n(En({},r),{handle:i=>_n(i,n)}),earlyReturn:n==="protocol"?s:void 0}:{handler:r,earlyReturn:s})},Di=(e,t)=>{var n;if(!e||typeof e!="string")return e;let r=e.endsWith(" ")&&!e.endsWith(" ")?e.slice(0,-1):e,s=Bi(t),i=((n=t?.handlers)!=null?n:[]).map(o=>{var l;return{handler:$n(En({},o),{priority:(l=o.priority)!=null?l:j.DEFAULT}),earlyReturn:void 0}}),a=[...s,...i].sort((o,l)=>{var c,d;return((c=o.handler.priority)!=null?c:0)-((d=l.handler.priority)!=null?d:0)});try{for(let{handler:o,earlyReturn:l}of a)if(r=o.handle(r),l!=null&&l(r))return r;return r.endsWith(" ")&&!r.endsWith(" ")?r.slice(0,-1):r}finally{ws()}},gt=Di;var mt=e=>e===void 0||/\s/.test(e);function Mn(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 Ni=/^ {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,Bi=/^ {0,3}(?:[-+*]|\d{1,9}[.)])[ \t]/;function Di(e,t,n){let r=e.indexOf(`
90
- `,t+1),s=e.slice(t+1,r<0?e.length:r);return Ni.test(s)||n&&Bi.test(s)}function Ln(e,t,n){let r=e.indexOf(`
89
+ `)return!0;if(e[n]!==" "&&e[n]!==" ")return!1}return!1}var zi=/^ {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,Ui=/^ {0,3}(?:[-+*]|\d{1,9}[.)])[ \t]/;function ji(e,t,n){let r=e.indexOf(`
90
+ `,t+1),s=e.slice(t+1,r<0?e.length:r);return zi.test(s)||n&&Ui.test(s)}function Nn(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
- `&&(_n(e,i)||Di(e,i,s)))return{at:i,closed:!1};e[i]==="\\"&&n!=="\\)"&&n!=="\\]"&&i++}return{at:e.length,closed:!1}}function Pn(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==="`"||_n(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}=Ln(e,t,n);return s?r:-1}function De(e,t,n){return Ln(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 Mn(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=Pn(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}=Mn(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 In(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=Mn(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 zi=e=>e.replace(/&/g,"&amp;").replace(/</g,"&lt;").replace(/>/g,"&gt;").replace(/"/g,"&quot;");function On(e,t){let n=e.open?" data-aparte-open":"",s=`<code class="language-math ${e.display?"math-display":"math-inline"}"${n}>${zi(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,In(n,r),s)},del(n,r,s){return Object.getPrototypeOf(this).del.call(this,n,In(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=>On(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=Pn(n);if(s!==-1)return{type:"aparteMathInline",raw:n.slice(0,s+1),text:n.slice(1,s),display:!1,open:!1}},renderer:n=>On(n,!1)}]}}var Nn="streamdown:",Ui=/(^|[ \t])[*_~`]+$/;function ji(e,t){let n=e.replace(Ui,"$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 Hi(e,t,n){let r=document.createElement("template");if(r.innerHTML=e,t){for(let s of r.content.querySelectorAll(`a[href^="${Nn}"]`))s.removeAttribute("href");for(let s of r.content.querySelectorAll(`img[src^="${Nn}"]`))s.remove()}return r.innerHTML=n.sanitizeHtml(r.innerHTML),Array.from(r.content.childNodes)}function qi(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(ji(u,t.math),{async:!1}):t.finished.parse(u,{async:!1}),k=Hi(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 Bn(e,t=fe){let{math:n,...r}=e??{},i=e!==void 0&&(n===void 0||Object.keys(r).length>0)?new $e(r):x,a,o,c=()=>n??t.hasCodeLanguageRenderer("math"),l=()=>a??=new $e(r,bt()),p=()=>o??=new $e(r,bt({live:!0}));t.setMarkdownProvider(u=>(c()?l():i).parse(u,{async:!1})),t.setStreamingMarkdownProvider(u=>{let d=c();return qi(u,d?{finished:l(),arriving:p(),math:!0}:{finished:i,arriving:i,math:!1},t)})}function Fi(e){if(!Hn(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 Un(e){return/^\s*<(?:!doctype|html|head|body)[\s>]/i.test(e)}function jn(e){try{return JSON.parse(e)}catch{return}}function Hn(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 Ki(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 qn(e){if(typeof e=="string")return e;if(Array.isArray(e)){let s=e.map(qn);return s.every(i=>i===void 0)&&e.length>0?void 0:s.filter(i=>i!==void 0).join(`
92
+ `&&(Mn(e,i)||ji(e,i,s)))return{at:i,closed:!1};e[i]==="\\"&&n!=="\\)"&&n!=="\\]"&&i++}return{at:e.length,closed:!1}}function Bn(e){if(e[0]!=="$"||mt(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==="`"||Mn(e,n))return-1;if(r==="{"){t++;continue}if(r==="}"){t=Math.max(0,t-1);continue}if(!(r!=="$"||t>0))return mt(e[n-1])||/\d/.test(e[n+1]??"")?-1:n}return-1}function kt(e,t,n){let{at:r,closed:s}=Nn(e,t,n);return s?r:-1}function je(e,t,n){return Nn(e,t,n).at}function bt(e,t,n){return e.startsWith("\\")?/[\p{L}\p{N}]$/u.test(n)||/^\s*[\d.,]*\s*$/.test(t):!1}var wt=[{open:"$$",close:"$$",display:!0},{open:"\\[",close:"\\]",display:!0},{open:"\\(",close:"\\)",display:!1}];function Dn(e,t){let n=[],r=-1;for(let s=0;s<e.length;){let i=e[s];if(i==="`"){let l=/^`+/.exec(e.slice(s))[0],c=e.indexOf(l,s+l.length);s=c===-1?s+l.length:c+l.length;continue}let a=-1,o=wt.find(l=>e.startsWith(l.open,s));if(o){let l=s+o.open.length,c=kt(e,l,o.close);c!==-1?a=c+o.close.length:t&&(a=je(e,l,o.close))}else if(i==="\\"){s+=2;continue}else if(i==="$"){let l=Bn(e.slice(s));l!==-1?a=s+l+1:r<0&&!mt(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 yt(e){let{spans:t,openDollar:n}=Dn(e,!0);if(n>=0){let a=je(e,n+1,"");if(!t.some(([o,l])=>o<a&&l>n)){for(let o=n;o<a;o++)e[o]==="["&&t.push([o,o+1]);t.sort((o,l)=>o[0]-l[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,l)=>r[Number(l)]??"")}}function Ln(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=Dn(r,!1).spans.filter(([o,l])=>!bt(r.slice(o,o+2),r.slice(o+2,l-2),r.slice(0,o))),i=t.slice(0,n),a=0;for(let[o,l]of s)i+=t.slice(n+a,n+o)+"a".repeat(l-o),a=l;return i+t.slice(n+a)}var Hi=e=>e.replace(/&/g,"&amp;").replace(/</g,"&lt;").replace(/>/g,"&gt;").replace(/"/g,"&quot;");function Pn(e,t){let n=e.open?" data-aparte-open":"",s=`<code class="language-math ${e.display?"math-display":"math-inline"}"${n}>${Hi(e.text)}</code>`;return t?`<pre${n}>${s}</pre>
93
+ `:s}function xt(e={}){let t=e.live===!0;return{tokenizer:{emStrong(n,r,s){return Object.getPrototypeOf(this).emStrong.call(this,n,Ln(n,r),s)},del(n,r,s){return Object.getPrototypeOf(this).del.call(this,n,Ln(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=wt.find(d=>d.open===r[1]),i=r[0].length,a=kt(n,i,s.close);if(a===-1)return!t||je(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(bt(s.open,o,""))return;let l=/^[ \t]*(\n|$)/.exec(n.slice(a+s.close.length));return l?{type:"aparteMathBlock",raw:n.slice(0,a+s.close.length+l[0].length),text:o,display:!0,open:!1}:void 0},renderer:n=>Pn(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 wt){if(!n.startsWith(i.open))continue;let a=kt(n,i.open.length,i.close);if(a===-1)return!t||i.open!=="$$"&&/[\p{L}\p{N}]$/u.test(r.at(-1)?.raw??"")||je(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 bt(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=Bn(n);if(s!==-1)return{type:"aparteMathInline",raw:n.slice(0,s+1),text:n.slice(1,s),display:!1,open:!1}},renderer:n=>Pn(n,!1)}]}}var zn="streamdown:",qi=/(^|[ \t])[*_~`]+$/;function Fi(e,t){let n=e.replace(qi,"$1");if(!t)return gt(n);let{masked:r,unmask:s}=yt(n);return/$/.test(r)&&/[\s\\]$/.test(n)&&({masked:r,unmask:s}=yt(n.replace(/[\s\\]+$/,""))),s(gt(r,{katex:!1}))}function Ki(e,t,n){let r=document.createElement("template");if(r.innerHTML=e,t){for(let s of r.content.querySelectorAll(`a[href^="${zn}"]`))s.removeAttribute("href");for(let s of r.content.querySelectorAll(`img[src^="${zn}"]`))s.remove()}return r.innerHTML=n.sanitizeHtml(r.innerHTML),Array.from(r.content.childNodes)}function Wi(e,t,n){let r="",s=[],i=a=>{let o=(a?t.arriving:t.finished).lexer(r),l=0;for(;l<o.length&&l<s.length;){let d=a&&l===o.length-1,u=s[l];if(u.raw!==o[l].raw||u.healed!==d)break;l++}for(let d of s.slice(l))for(let u of d.nodes)u.remove();let c=s.slice(0,l);for(let d=l;d<o.length;d++){let u=o[d].raw,h=a&&d===o.length-1,g=h?t.arriving.parse(Fi(u,t.math),{async:!1}):t.finished.parse(u,{async:!1}),f=Ki(g,h,n);e.append(...f),c.push({raw:u,healed:h,nodes:f})}s=c};return{write(a){r+=a,i(!0)},end(){i(!1)}}}function Un(e,t=be){let{math:n,...r}=e??{},i=e!==void 0&&(n===void 0||Object.keys(r).length>0)?new Ae(r):S,a,o,l=()=>n??t.hasCodeLanguageRenderer("math"),c=()=>a??=new Ae(r,xt()),d=()=>o??=new Ae(r,xt({live:!0}));t.setMarkdownProvider(u=>(l()?c():i).parse(u,{async:!1})),t.setStreamingMarkdownProvider(u=>{let h=l();return Wi(u,h?{finished:c(),arriving:d(),math:!0}:{finished:i,arriving:i,math:!1},t)})}function Gi(e){if(!Kn(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 qn(e){return/^\s*<(?:!doctype|html|head|body)[\s>]/i.test(e)}function Fn(e){try{return JSON.parse(e)}catch{return}}function Kn(e){return typeof e=="object"&&e!==null&&!Array.isArray(e)&&typeof e.type=="string"}function St(e){let t=e.metadata??{};return`${String(t.nodeId??"")}:${String(t.runIndex??0)}:${String(t.itemIndex??0)}`}function Zi(e){switch(e.type){case"begin":return{kind:"begin",stream:St(e)};case"item":return{kind:"item",stream:St(e),text:typeof e.content=="string"?e.content:""};case"end":return{kind:"end",stream:St(e)};case"error":return{kind:"error",message:typeof e.content=="string"?e.content:""};case"keepalive":return;default:return{kind:"unknown",type:e.type}}}function Wn(e){if(typeof e=="string")return e;if(Array.isArray(e)){let s=e.map(Wn);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 Wi(e){let t=e;for(;Array.isArray(t);)t=t[0];return Object.keys(t).slice(0,6)}function Gi(e){let t=e.trim();if(!t)return;let n=jn(t);if(n===void 0)return Un(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=qn(n);return r===void 0?{kind:"unreadable",fields:Wi(n)}:{kind:"reply",text:r}}async function*Zi(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=jn(u);if(r==="unknown"){if(!Fi(d)){r="whole";return}r="frames"}if(Hn(d)){let m=Ki(d);m&&(yield m)}else c&&p===l.length-1&&u.trimStart().startsWith("{")?yield{kind:"cut"}:Un(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=Gi(s);o&&(yield o)}}var Vi=new Set([502,504,524]);function Ji(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 yt(e,t){let n=e.status,r=(await e.text().catch(()=>"")).trim(),s=N.codeForStatus(n)??(n===404?I.PROVIDER_MISCONFIGURED:I.PROVIDER_ERROR),i=(l,p=s)=>new N(l,p,void 0,void 0,n),a=I.PROVIDER_MISCONFIGURED;if(r.startsWith("<")||(e.headers.get("content-type")??"").includes("text/html"))return Vi.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.`,N.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${Ji(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 xt(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 N(`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 Qi(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 Xi(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 Yi=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=Xi(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!==Yi&&await this.opened,this.socket.send(JSON.stringify(t))}close(){this.socket.close()}},ze="n8n_buttons";function Fn(e=fe){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 Dt({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:ea(t),quiet:!0,details:!1})}function ea(e){return e.toolCall?.input?.text??""}function ta(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 na=250;async function ra(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 Dn=`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".`,sa="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.",ia="A proxy timed out waiting for n8n's answer. The workflow may still be running \u2014 its execution list shows the result.",aa="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.",oa="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.",la=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 ca(e){for(let t=e.length-1;t>=0;t--)if(e[t]?.role==="user")return t;return-1}function zn(e){return e===void 0?"":typeof e=="string"?e:e.flatMap(t=>t.type==="text"&&t.text?[t.text]:[]).join(`
96
+ `)}function Vi(e){let t=e;for(;Array.isArray(t);)t=t[0];return Object.keys(t).slice(0,6)}var Ji=new Set(["executionStarted","executionId","resumeToken"]);function Qi(e,t){if(e.executionStarted!==!0||!t||!Object.keys(e).every(s=>Ji.has(s)))return!1;let{executionId:n,resumeToken:r}=e;return n!==void 0&&!/^\d{1,20}$/.test(String(n))?!1:r===void 0||typeof r=="string"}function Xi(e,t){let n=e.trim();if(!n)return;let r=Fn(n);if(r===void 0)return qn(n)?{kind:"html"}:{kind:"reply",text:e};if(typeof r=="object"&&r!==null&&r.executionStarted===!0){if(!Qi(r,t))return{kind:"reply",text:e};let{executionId:i,resumeToken:a}=r;return{kind:"deferred",...typeof i=="string"||typeof i=="number"?{executionId:String(i)}:{},...typeof a=="string"?{resumeToken:a}:{}}}let s=Wn(r);return s===void 0?{kind:"unreadable",fields:Vi(r)}:{kind:"reply",text:s}}async function*Yi(e,t=""){let n=e.getReader(),r=new TextDecoder,s="unknown",i="",a="";function*o(l,c){let d=l.split(`
97
+ `);for(let[u,h]of d.entries()){if(!h.trim())continue;let g=Fn(h);if(s==="unknown"){if(!Gi(g)){s="whole";return}s="frames"}if(Kn(g)){let f=Zi(g);f&&(yield f)}else c&&u===d.length-1&&h.trimStart().startsWith("{")?yield{kind:"cut"}:qn(h)?yield{kind:"html"}:yield{kind:"item",text:h}}}try{for(;;){let{done:l,value:c}=await n.read(),d=l?r.decode():r.decode(c,{stream:!0});if(i+=d,s!=="whole"){a+=d;let u=l?a.length:a.lastIndexOf(`
98
+ `)+1,h=a.slice(0,u);a=a.slice(u),yield*o(h,l)}if(l)break}}finally{n.releaseLock()}if(s!=="frames"){let l=Xi(i,/^\s*application\/(?:[\w.+-]+\+)?json\b/i.test(t));l&&(yield l)}}var ea=new Set([502,504,524]);function ta(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 vt(e,t){let n=e.status,r=(await e.text().catch(()=>"")).trim(),s=z.codeForStatus(n)??(n===404?L.PROVIDER_MISCONFIGURED:L.PROVIDER_ERROR),i=(c,d=s)=>new z(c,d,void 0,void 0,n),a=L.PROVIDER_MISCONFIGURED;if(r.startsWith("<")||(e.headers.get("content-type")??"").includes("text/html"))return ea.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.`,L.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.`,z.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${ta(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 l=typeof o.message=="string"?o.message:r;return typeof o.message=="string"&&typeof o.hint=="string"&&(l=`${o.message} ${o.hint}`),i(l.slice(0,400)||`The n8n workflow answered HTTP ${n}.`)}function Rt(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 z(`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?L.NET_OFFLINE:L.NET_ERROR)}function na(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 ra(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 sa=1,Et=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=ra(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=c=>{i!==void 0&&clearTimeout(i),t.removeEventListener("abort",l),this.waiter===o&&(this.waiter=void 0),s(c)},o=c=>a(c),l=()=>a(void 0);this.waiter=o,t.addEventListener("abort",l,{once:!0}),n!==void 0&&(i=setTimeout(()=>a("timeout"),n))})}async send(t){this.socket.readyState!==sa&&await this.opened,this.socket.send(JSON.stringify(t))}close(){this.socket.close()}},He="n8n_buttons";function Gn(e=be){e.registerTool({name:He,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 jt({kind:"approval",message:s.text,options:s.buttons.map((u,h)=>({value:String(h),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 l=a?.option===void 0?-1:Number(a.option),c=s.buttons[l];if(!c)throw new Error("No button was chosen.");let d={index:l,text:c.text};return{toolCallId:t.id,content:c.text,structuredContent:d}}),e.registerToolDisplay(He,{icon:"messageSquare",label:t=>typeof t.result=="string"&&t.result?t.result:ia(t),quiet:!0,details:!1})}function ia(e){return e.toolCall?.input?.text??""}function aa(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.links.every(n=>typeof n=="string")?t:void 0}catch{return}}var oa=250;async function la(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 jn=`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".`,ca="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.",ua="A proxy timed out waiting for n8n's answer. The workflow may still be running \u2014 its execution list shows the result.",pa="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.",ha="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.",da=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 fa(e){for(let t=e.length-1;t>=0;t--)if(e[t]?.role==="user")return t;return-1}function Hn(e){return e===void 0?"":typeof e=="string"?e:e.flatMap(t=>t.type==="text"&&t.text?[t.text]:[]).join(`
99
99
 
100
- `)}var ua={"image/png":"png","image/jpeg":"jpg","image/gif":"gif","image/webp":"webp","image/svg+xml":"svg"};function pa(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}.${ua[s]??"bin"}`}}function ha(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)=>pa(n.image,n.mimeType,r)).filter(n=>n!==void 0)}function Kn(e){let t=e.onWarning??(l=>console.warn(`[aparte] n8n: ${l}`)),n=e.chatSessionKey??"sessionId",r=e.chatInputKey??"chatInput",s=`aparte-${ae()}`,i=new Map,a=(l,p,u)=>{let d=e.WebSocket??globalThis.WebSocket;if(!d)throw new N(oa,I.PROVIDER_MISCONFIGURED);i.get(l)?.socket.close();let m={socket:new St(Qi(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 E=await m.next(l.signal);if(E===void 0)return;if(!(E==="timeout"||E.kind==="continue"))switch(E.kind){case"text":{k&&u({type:"text-flush"}),E.text&&(u({type:"text-delta",delta:E.text}),k=!0);let $=await m.next(l.signal,na);if($===void 0)return;if($==="timeout")return v();$.kind!=="continue"&&m.unshift($);break}case"buttons":{k&&u({type:"text-flush"}),E.text&&(u({type:"text-delta",delta:E.text}),u({type:"text-flush"}));let $=new URL(e.webhookUrl).origin,R=E.buttons.filter(b=>{try{return new URL(b.link,e.webhookUrl).origin===$}catch{return!1}});if(R.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 j=`n8n-buttons-${ae()}`,H={text:E.text,buttons:R.map(b=>({text:b.text,type:b.type})),blockUserInput:E.blockUserInput},F={v:1,sessionId:p,executionId:d.executionId,...d.token?{token:d.token}:{},toolCallId:j,links:R.map(b=>b.link)};u({type:"tool-start",toolCallId:j,name:ze,input:H}),u({type:"run-suspended",pending:[{toolCallId:j,name:ze,input:H,reason:"external"}],ticket:JSON.stringify(F)});return}case"error":throw k&&u({type:"text-flush"}),new N(E.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 E=i.get(p.sessionId);(!E||E.socket.closed)&&a(p.sessionId,p.executionId,p.token);let $=await u(v,{signal:l.signal,...e.credentials?{credentials:e.credentials}:{}}).catch(R=>{throw xt(R,v)});if(!$.ok)throw await yt($,"answer");await o(l,p.sessionId)};return async l=>{let p=l.emitter,u=e.fetch??fetch;try{let d=ta(l.deferral?.token);if(d){await c(l,d,u);return}let m=l.baseRequest.messages,k=ca(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-${ae()}`);let E=typeof e.headers=="function"?await e.headers():e.headers??{},$=(typeof e.sessionId=="function"?e.sessionId(l):e.sessionId)??s,R=typeof e.metadata=="function"?e.metadata(l):e.metadata,j=ha(l,v),H=i.get($);if(H&&!H.socket.closed){p({type:"run-start"}),p({type:"turn-start"}),await H.socket.send({sessionId:$,action:"sendMessage",chatInput:zn(v?.content),files:await Promise.all(j.map(ra))}),await o(l,$);return}let F={action:"sendMessage",[n]:$,[r]:zn(v?.content),...R?{metadata:R}:{}},b,L={Accept:"text/plain"};for(let[f,O]of Object.entries(E))f.toLowerCase()!=="content-type"&&(L[f]=O);if(j.length>0){let f=new FormData;for(let[O,Z]of Object.entries(F))f.append(O,typeof Z=="string"?Z:JSON.stringify(Z));for(let O of j)f.append("files",O.blob,O.name);b=f}else b=JSON.stringify(F),L["Content-Type"]="application/json";let P=await u(e.webhookUrl,{method:"POST",headers:L,body:b,signal:l.signal,...e.credentials?{credentials:e.credentials}:{}}).catch(f=>{throw xt(f,e.webhookUrl)});if(!P.ok)throw await yt(P,"answer");p({type:"run-start"}),p({type:"turn-start"});let pe=!1,ne=!1,be=!1,we=!1,M,C=new Map,ye=new Set,X=()=>{be&&p({type:"text-flush"}),be=!1},re=f=>{f&&(pe=!0,be=!0,p({type:"text-delta",delta:f}))},se=f=>{M=f,X()},he=()=>{M=void 0;for(let[f,O]of C){C.delete(f),se(f);for(let Z of O.text)re(Z);if(!O.ended)return;M=void 0}},J=f=>{let O=C.get(f);return O||C.set(f,O={text:[],ended:!1}),O};if(!P.body)throw new N(Dn,I.PROVIDER_MISCONFIGURED);for await(let f of Zi(P.body))switch(f.kind){case"begin":M===void 0?se(f.stream):f.stream!==M&&J(f.stream);break;case"item":f.stream===void 0||f.stream===M?re(f.text):M===void 0?(se(f.stream),re(f.text)):J(f.stream).text.push(f.text);break;case"end":f.stream===M?he():J(f.stream).ended=!0;break;case"error":throw X(),new N(f.message||"The n8n workflow failed.",I.PROVIDER_ERROR);case"reply":ne=!0,re(f.text);break;case"unreadable":throw new N(la(f.fields),I.PROVIDER_MISCONFIGURED);case"deferred":if(!f.executionId)throw new N(aa,I.PROVIDER_MISCONFIGURED);a($,f.executionId,f.resumeToken),we=!0;break;case"html":throw X(),new N(ia,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":ye.has(f.type)||t(`n8n sent a "${f.type}" frame, which this runner does not read; it was skipped.`),ye.add(f.type);break}if(we){await o(l,$);return}he();for(let[f,O]of C){C.delete(f),se(f);for(let Z of O.text)re(Z)}if(!pe)throw new N(ne?sa:Dn,I.PROVIDER_MISCONFIGURED);X(),p({type:"run-done"});return}catch(d){if(l.signal.aborted)return;throw d}}}function da(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 fa(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 ga={"image/png":"png","image/jpeg":"jpg","image/gif":"gif","image/webp":"webp","image/svg+xml":"svg"};function ma(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}.${ga[s]??"bin"}`}}function ka(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)=>ma(n.image,n.mimeType,r)).filter(n=>n!==void 0)}function Zn(e){let t=e.onWarning??(h=>console.warn(`[aparte] n8n: ${h}`)),n=e.chatSessionKey??"sessionId",r=e.chatInputKey??"chatInput",s=`aparte-${ue()}`,i=new Map,a=(()=>{try{let h=/^(.*)\/webhook(?:-test)?\/[^/]+\/chat\/?$/.exec(new URL(e.webhookUrl).pathname);return h?h[1].replace(/\/+$/,""):void 0}catch{return}})(),o=e.waitingPrefix!==void 0?`/${e.waitingPrefix.replace(/^\/+|\/+$/g,"")}`:a===void 0?void 0:`${a}/webhook-waiting`,l=(h,g)=>{try{let f=new URL(h,e.webhookUrl);if(f.protocol!=="http:"&&f.protocol!=="https:"||f.origin!==new URL(e.webhookUrl).origin||f.username||f.password)return;let w=f.pathname;if(/%2f|%5c|%2e/i.test(w)||o===void 0||f.hash)return;let v=w.startsWith(`${o}/`)?w.slice(o.length+1).split("/"):[];if(v.length!==2||v[0]!==encodeURIComponent(g)||!/^[A-Za-z0-9_-]+$/.test(v[1]))return;let E=f.searchParams.get("approved");return[...f.searchParams].length!==2||E!=="true"&&E!=="false"||!/^[0-9a-f]{64}$/.test(f.searchParams.get("signature")??"")?void 0:f.href}catch{return}},c=(h,g,f)=>{let w=e.WebSocket??globalThis.WebSocket;if(!w)throw new z(ha,L.PROVIDER_MISCONFIGURED);i.get(h)?.socket.close();let v={socket:new Et(na(e.webhookUrl,h,g,f),w),executionId:g,...f?{token:f}:{}};return i.set(h,v),v},d=async(h,g)=>{let f=h.emitter,w=i.get(g),{socket:v}=w,E=!1,$=()=>{E&&f({type:"text-flush"}),f({type:"run-done"})};for(;;){let R=await v.next(h.signal);if(R===void 0)return;if(!(R==="timeout"||R.kind==="continue"))switch(R.kind){case"text":{E&&f({type:"text-flush"}),R.text&&(f({type:"text-delta",delta:R.text}),E=!0);let I=await v.next(h.signal,oa);if(I===void 0)return;if(I==="timeout")return $();I.kind!=="continue"&&v.unshift(I);break}case"buttons":{E&&f({type:"text-flush"}),R.text&&(f({type:"text-delta",delta:R.text}),f({type:"text-flush"}));let I=R.buttons.map(D=>l(D.link,w.executionId)),N=I.every(D=>D!==void 0)?R.buttons:[];if(N.length<R.buttons.length&&t(`An n8n Chat node sent buttons whose links do not resume this execution on this n8n instance; they were not shown. A link has to be on the webhook's origin, http(s), and be ${o===void 0?`n8n's own, but the webhook URL is not a Chat Trigger URL ("\u2026/webhook/<id>/chat") that says where n8n is mounted: set the runner's waitingPrefix option`:`"${o}/<execution id>/<node id>?approved=true|false&signature=<64 hex>"; if your instance serves its waiting links elsewhere, set the runner's waitingPrefix option`}.`),N.length===0){f({type:"run-done"});return}let b=`n8n-buttons-${ue()}`,T={text:R.text,buttons:N.map(D=>({text:D.text,type:D.type})),blockUserInput:R.blockUserInput},B={v:1,sessionId:g,executionId:w.executionId,...w.token?{token:w.token}:{},toolCallId:b,links:I.filter(D=>D!==void 0)};f({type:"tool-start",toolCallId:b,name:He,input:T}),f({type:"run-suspended",pending:[{toolCallId:b,name:He,input:T,reason:"external"}],ticket:JSON.stringify(B)});return}case"error":throw E&&f({type:"text-flush"}),R.message&&t(`n8n sent an error: ${R.message}`),new z("The n8n workflow failed.",L.PROVIDER_ERROR);case"closed":return i.delete(g),$()}}},u=async(h,g,f)=>{let w=h.emitter;w({type:"run-start"}),w({type:"turn-start"});let v=h.deferral?.outcomes?.[g.toolCallId],E=v?.kind==="result"?v.structuredContent:void 0,$=E?g.links[E.index]:void 0,R=$===void 0?void 0:l($,g.executionId);if($!==void 0&&R===void 0&&t("An n8n button link in the ticket does not resume this execution on this n8n instance; it was not fetched."),v?.kind==="result"&&E?.written){w({type:"tool-resolved",toolCallId:g.toolCallId,result:v.content,structuredResult:E}),await(i.get(g.sessionId)??c(g.sessionId,g.executionId,g.token)).socket.send({sessionId:g.sessionId,action:"sendMessage",chatInput:E.text,files:[]}),await d(h,g.sessionId);return}if(!v||v.kind!=="result"||!R){w({type:"tool-aborted",toolCallId:g.toolCallId}),w({type:"run-done"});return}w({type:"tool-resolved",toolCallId:g.toolCallId,result:v.content,structuredResult:E});let I=i.get(g.sessionId);(!I||I.socket.closed)&&c(g.sessionId,g.executionId,g.token);let N=await f(R,{signal:h.signal,...e.credentials?{credentials:e.credentials}:{}}).catch(b=>{throw Rt(b,R)});if(!N.ok)throw await vt(N,"answer");await d(h,g.sessionId)};return async h=>{let g=h.emitter,f=e.fetch??fetch;try{let w=aa(h.deferral?.token);if(w){await u(h,w,f);return}let v=h.baseRequest.messages,E=fa(v),$=E>=0?v[E]:void 0;e.sessionId===void 0&&!v.slice(0,Math.max(E,0)).some(k=>k.role==="assistant")&&(s=`aparte-${ue()}`);let R=typeof e.headers=="function"?await e.headers():e.headers??{},I=(typeof e.sessionId=="function"?e.sessionId(h):e.sessionId)??s,N=typeof e.metadata=="function"?e.metadata(h):e.metadata,b=ka(h,$),T=i.get(I);if(T&&!T.socket.closed){g({type:"run-start"}),g({type:"turn-start"}),await T.socket.send({sessionId:I,action:"sendMessage",chatInput:Hn($?.content),files:await Promise.all(b.map(la))}),await d(h,I);return}let B={action:"sendMessage",[n]:I,[r]:Hn($?.content),...N?{metadata:N}:{}},D,te={Accept:"text/plain"};for(let[k,P]of Object.entries(R))k.toLowerCase()!=="content-type"&&(te[k]=P);if(b.length>0){let k=new FormData;for(let[P,J]of Object.entries(B))k.append(P,typeof J=="string"?J:JSON.stringify(J));for(let P of b)k.append("files",P.blob,P.name);D=k}else D=JSON.stringify(B),te["Content-Type"]="application/json";let le=await f(e.webhookUrl,{method:"POST",headers:te,body:D,signal:h.signal,...e.credentials?{credentials:e.credentials}:{}}).catch(k=>{throw Rt(k,e.webhookUrl)});if(!le.ok)throw await vt(le,"answer");g({type:"run-start"}),g({type:"turn-start"});let Se=!1,Z=!1,O=!1,ve=!1,V,X=new Map,ge=new Set,me=()=>{O&&g({type:"text-flush"}),O=!1},ne=k=>{k&&(Se=!0,O=!0,g({type:"text-delta",delta:k}))},re=k=>{V=k,me()},se=()=>{V=void 0;for(let[k,P]of X){X.delete(k),re(k);for(let J of P.text)ne(J);if(!P.ended)return;V=void 0}},Y=k=>{let P=X.get(k);return P||X.set(k,P={text:[],ended:!1}),P};if(!le.body)throw new z(jn,L.PROVIDER_MISCONFIGURED);for await(let k of Yi(le.body,le.headers.get("content-type")??""))switch(k.kind){case"begin":V===void 0?re(k.stream):k.stream!==V&&Y(k.stream);break;case"item":k.stream===void 0||k.stream===V?ne(k.text):V===void 0?(re(k.stream),ne(k.text)):Y(k.stream).text.push(k.text);break;case"end":k.stream===V?se():Y(k.stream).ended=!0;break;case"error":throw me(),k.message&&t(`n8n sent an error: ${k.message}`),new z("The n8n workflow failed.",L.PROVIDER_ERROR);case"reply":Z=!0,ne(k.text);break;case"unreadable":throw new z(da(k.fields),L.PROVIDER_MISCONFIGURED);case"deferred":if(!k.executionId)throw new z(pa,L.PROVIDER_MISCONFIGURED);c(I,k.executionId,k.resumeToken),ve=!0;break;case"html":throw me(),new z(ua,L.NET_TIMEOUT);case"cut":t("n8n's stream stopped in the middle of a frame; the text before it is kept.");break;case"unknown":ge.has(k.type)||t(`n8n sent a "${k.type}" frame, which this runner does not read; it was skipped.`),ge.add(k.type);break}if(ve){await d(h,I);return}se();for(let[k,P]of X){X.delete(k),re(k);for(let J of P.text)ne(J)}if(!Se)throw new z(Z?ca:jn,L.PROVIDER_MISCONFIGURED);me(),g({type:"run-done"});return}catch(w){if(h.signal.aborted)return;throw w}}}function ba(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 wa(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 ga(e,{now:t=Date.now()}={}){let n=[];return e.forEach((r,s)=>{if(typeof r!="object"||r===null)return;let i=r,a=da(i),o=/^Human/.test(a)||a==="human"?"user":/^AI/.test(a)||a==="ai"?"assistant":void 0;if(!o)return;let c=fa(i.kwargs?.content);c.trim()&&n.push({id:`n8n-${s}`,role:o,content:c,timestamp:t-(e.length-s),status:"completed"})}),n}async function Wn(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 xt(o,e.webhookUrl)});if(!s.ok)throw await yt(s,"history");let i;try{i=await s.json()}catch{throw new N("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 ga(Array.isArray(a)?a:[])}var Rt="card-",ma=["weather","items","product","place","stats","order","stock","plan","score","media","link"],Ue="aparte-card-fence",Et=new WeakMap,ka=e=>`setup${e.charAt(0).toUpperCase()}${e.slice(1)}Card`;function ba(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[ka(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 wa(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 ya(e){let t=e.getAttribute("data-card")??"",n=e.getAttribute("data-source")??"",r=Pt(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:wa(t,n),type:"card",card:t,data:i,...a?{variant:a}:{}},c=Ge(r,o);!c&&await ba(r,t)&&e.isConnected&&(c=Ge(r,o)),c?e.replaceChildren(c):s()}function xa(){typeof customElements>"u"||typeof HTMLElement>"u"||customElements.get(Ue)||customElements.define(Ue,class extends HTMLElement{connectedCallback(){this.hasAttribute("data-drawn")||(this.setAttribute("data-drawn",""),ya(this))}})}function Gn(e={}){let t=e.config??fe;e.load&&Et.set(t,{load:e.load,pending:new Map}),xa();let n=new Set([...ma,...Ft(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(Kt(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 Sa={weather:()=>import("./chunks/weather-FAK6EHSV.js"),items:()=>import("./chunks/items-TBASSOQ3.js"),product:()=>import("./chunks/product-VEI5FUDZ.js"),place:()=>import("./chunks/place-TGHDGFFI.js"),stats:()=>import("./chunks/stats-CNVSRBY6.js"),order:()=>import("./chunks/order-H7FHTQ2J.js"),stock:()=>import("./chunks/stock-2KHFILSB.js"),plan:()=>import("./chunks/plan-JA7466PF.js"),score:()=>import("./chunks/score-QTZEGTBP.js"),media:()=>import("./chunks/media-O7WQHRGC.js"),link:()=>import("./chunks/link-VR62DJAD.js")},Zn=e=>`setup${e.charAt(0).toUpperCase()}${e.slice(1)}Card`;function Vn(e,t={}){let n=Object.fromEntries(Object.entries(Sa).map(([r,s])=>{let i=t[r];return i?[r,()=>s().then(a=>{let o=a[Zn(r)];return typeof o=="function"?{...a,[Zn(r)]:c=>o({...i,...c})}:a})]:[r,s]}));return Gn({config:e,load:n})}var Ra='<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>',Ea='<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>',va='<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>',Jn={launcherOpen:()=>Ra,launcherClose:()=>Ea,send:()=>va};var Ce={en:{strings:{title:"Hi there! \u{1F44B}",subtitle:"Start a chat. We're here to help you 24/7.",footer:"",poweredBy:"Powered by {aparte}",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:"",poweredBy:"Propuls\xE9 par {aparte}",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-32HJELG3.js").then(e=>e.fr)},es:{strings:{title:"\xA1Hola! \u{1F44B}",subtitle:"Inicia una conversaci\xF3n. Estamos aqu\xED para ayudarte, 24/7.",footer:"",poweredBy:"Con la tecnolog\xEDa de {aparte}",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-IBJAOBGB.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:"",poweredBy:"Desenvolvido com {aparte}",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-367NLYVE.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:"",poweredBy:"Bereitgestellt mit {aparte}",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-NQDMZC5V.js").then(e=>e.de)},it:{strings:{title:"Ciao! \u{1F44B}",subtitle:"Inizia una conversazione. Siamo qui per aiutarti, 24 ore su 24.",footer:"",poweredBy:"Realizzato con {aparte}",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-HHSL2KBW.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:"",poweredBy:"\u0420\u0430\u0431\u043E\u0442\u0430\u0435\u0442 \u043D\u0430 {aparte}",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-ETHLBBSY.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:"",poweredBy:"{aparte} \u3067\u52D5\u4F5C",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-2EHR4WNO.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:"",poweredBy:"{aparte} \uAE30\uBC18",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-XONDEFR4.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:"",poweredBy:"\u7531 {aparte} \u9A71\u52A8",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-OGEW5BS2.js").then(e=>e.zhCN)}};function vt(e){if(Ce[e])return e;let t=e.split("-")[0]?.toLowerCase()??"";return Object.keys(Ce).find(n=>n.split("-")[0]?.toLowerCase()===t)??"en"}function Qn(e,t){return{...Ce[vt(e)].strings,...t?.[e]??{}}}function Xn(e){return Ce[vt(e)].initial}function Yn(e){return Ce[vt(e)].locale?.()}function $a(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 je="n8n-chat/sessionId",er="N8N_WORKFLOW_ERROR",sr=new WeakMap,tr=!1;function Ca(){tr||(tr=!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?sr.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 nr(e){try{return localStorage.getItem(e)??void 0}catch{return}}function rr(e,t){try{localStorage.setItem(e,t)}catch{}}function Ta(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 y(e,t,n){let r=document.createElement(e);return t&&(r.className=t),n!==void 0&&(r.textContent=n),r}var Aa=0;function Ia(e){let t=$a(e.webhookUrl),n=e.mode??"window",r=e.defaultLanguage??"en",s=Qn(r,e.i18n),i=e.loadPreviousSession??!0,a=e.initialMessages??Xn(r),o=++Aa,c=`aparte-n8n-title-${o}`,l=i&&!e.sessionId&&!!nr(je),p=e.sessionId??(i?nr(je):void 0)??ae();i&&!e.sessionId&&rr(je,p);let u=new Nt;e.locale&&u.setLocale(e.locale);let d=!1,m=u.getLocale();Yn(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(Jn),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}),Fn(u);let k=e.cards===!1?void 0:Vn(u,typeof e.cards=="object"?e.cards:{}),v=e.replies===!1?void 0:Bt(u);u.setErrorRenderer(({message:h,sentence:g,code:T})=>{let _=T===er,A=y("div","aparte-segment aparte-alert aparte-alert--danger aparte-segment-error");T&&A.setAttribute("data-error-code",_?I.PROVIDER_ERROR:T);let ie=y("span","aparte-alert__icon");ie.innerHTML=u.getIcon("error")||"\u26A0";let U=y("div","aparte-alert__body");return U.append(y("div","aparte-alert__title",u.t("error")),y("div","aparte-alert__message",_?u.t("errorNoAnswer"):g??h)),_&&h&&U.append(y("p","aparte-n8n__error-detail",h)),A.append(ie,U),A}),Bn(void 0,u);let E;u.setHighlightProvider(async(h,g)=>(E??=import("./chunks/highlight-SCSTGNZJ.js").then(T=>T.createHighlighter()),(await E)(h,g))),m=u.getLocale();let $=e.setup?.(u),R=y("section","aparte-n8n__window");R.setAttribute("aria-labelledby",c);let j=y("header","aparte-n8n__header"),H=y("div","aparte-n8n__heading"),F=y("p","aparte-n8n__title",s.title);if(F.id=c,H.append(F),s.subtitle&&H.append(y("p","aparte-n8n__subtitle",s.subtitle)),j.append(H),n==="window"&&e.showWindowCloseButton){let h=y("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=y("aparte-icon");g.setAttribute("name","close"),h.append(g),j.append(h)}let b=y("aparte-chat","aparte-n8n__chat");b.id=`aparte-n8n-chat-${o}`,e.messageComponents&&(Ca(),sr.set(b,e.messageComponents));let L=y("aparte-composer");L.setAttribute("placeholder",s.inputPlaceholder);let P;if(e.suggestions?.length&&(P=y("aparte-suggestions"),P.setAttribute("suggestions",JSON.stringify(e.suggestions.map(h=>({label:h,prompt:h})))),L.append(P)),e.replies!==!1){let h=y("aparte-suggestions");h.setAttribute("answers",""),L.append(h)}let pe=y("div","aparte-composer-shell"),ne=y("div","aparte-composer-row");ne.append(y("aparte-composer-input"));let be=typeof e.allowFileUploads=="object"?e.allowFileUploads?.value:e.allowFileUploads,we=typeof e.allowedFilesMimeTypes=="object"?e.allowedFilesMimeTypes?.value:e.allowedFilesMimeTypes;if(be){pe.append(y("aparte-composer-attachments"));let h=y("aparte-composer-add-attachment");we&&h.setAttribute("accept",we),ne.append(h)}ne.append(y("aparte-composer-send")),pe.append(ne),L.append(pe),b.append(y("aparte-chat-viewport"),y("aparte-elicitation"),L),R.append(j,b);{let h=y("p","aparte-n8n__powered"),g=s.poweredBy?.includes("{aparte}")?s.poweredBy:"Powered by {aparte}",[T,_=""]=g.split("{aparte}"),A=y("a",void 0,"apart\xE9");A.setAttribute("href","https://apartejs.dev/?ref=n8n-chat"),A.setAttribute("target","_blank"),A.setAttribute("rel","noopener"),h.append(T??"",A,_),R.append(h)}s.footer&&R.append(y("p","aparte-n8n__footer",s.footer));let M;if(e.showWelcomeScreen&&!l){M=y("div","aparte-n8n__welcome");let h=y("button","aparte-btn aparte-btn--primary aparte-btn--solid aparte-n8n__start",s.getStarted);h.type="button",h.addEventListener("click",()=>{M.hidden=!0,b.hidden=!1,b.querySelector("aparte-composer-input")?.focusEnd?.()}),M.append(h),b.hidden=!0,R.insertBefore(M,b)}let C;n==="window"?(C=y("aparte-launcher","aparte-n8n aparte-n8n--window"),C.append(R)):(C=y("div","aparte-n8n aparte-n8n--fullscreen"),C.append(R));let ye=e.colorScheme??"light";ye!=="auto"&&C.setAttribute("data-aparte-theme",ye),C.setAttribute("lang",r),n==="window"&&C.addEventListener("aparte-launcher-toggle",h=>{let{open:g,sheet:T}=h.detail;g&&T?(R.setAttribute("role","dialog"),R.setAttribute("aria-modal","true")):(R.removeAttribute("role"),R.removeAttribute("aria-modal"))}),Lt(C,u),Ta(e.target??"#n8n-chat").append(C);let X=()=>a.map((h,g)=>({id:`n8n-initial-${g}`,role:"assistant",content:h,timestamp:Date.now()-a.length+g,status:"completed"})),re=()=>(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}}),se=new Set((e.messageHistory??[]).flatMap((h,g)=>h.transparent?[`n8n-seed-${g}`]:[]));se.size&&new MutationObserver(()=>{for(let h of se){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 he=h=>b.viewport?.setMessages(h);he([...X(),...re()]),e.messageHistory?.length&&P&&(P.hidden=!0);let J=0,f,O=()=>{let h=++J;f=new AbortController,Wn({webhookUrl:t,sessionId:p,...e.metadata?{metadata:e.metadata}:{},...e.chatSessionKey?{chatSessionKey:e.chatSessionKey}:{},headers:()=>({...e.webhookConfig?.headers??{}}),...e.fetch?{fetch:e.fetch}:{},signal:f.signal}).then(g=>{h!==J||g.length===0||(P&&(P.hidden=!0),he([...X(),...g]))},g=>{f?.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),J===0&&O())};C.addEventListener("aparte-launcher-toggle",h)}else O();let Z="",$t=p,xe=!1,Se=[];b.addEventListener("aparte-send",h=>{J++,Z=String(h.detail?.content??""),$t=p,P&&(P.hidden=!0)});let He=(h,g)=>{M&&!M.hidden&&(M.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}))},Ct=()=>{xe=!1;let h=Se.shift();h!==void 0&&queueMicrotask(()=>He(h))};b.addEventListener("aparte-message-start",()=>{xe=!0});for(let h of["aparte-message-done","aparte-message-error","aparte-message-aborted"])b.addEventListener(h,Ct);let Tt=h=>{h.detail?.targetId===b.id&&Ct()};window.addEventListener("aparte-message-aborted",Tt);let At=p,ir=Kn({webhookUrl:t,sessionId:()=>At,headers:()=>({...e.webhookConfig?.headers??{}}),...e.fetch?{fetch:e.fetch}:{},...e.metadata?{metadata:e.metadata}:{},...e.chatInputKey?{chatInputKey:e.chatInputKey}:{},...e.chatSessionKey?{chatSessionKey:e.chatSessionKey}:{}}),ar=async h=>{let g=Z,T=$t;if(await e.beforeMessageSent?.(g),h.signal.aborted)return;At=T;let _="",A=!1,ie=await ir({...h,emitter:U=>{U.type==="text-delta"&&(_+=U.delta),U.type==="run-done"&&(A=!0),h.emitter(U)}}).catch(U=>{let de=U;throw de?.code===I.PROVIDER_ERROR&&de.httpStatus===void 0?new N(de.message??"",er,de.data,U):U});if(A&&e.afterMessageSent){let U=e.afterMessageSent;queueMicrotask(()=>{Promise.resolve().then(()=>U(g,{output:_,message:_,hasReceivedChunks:_.length>0})).catch(de=>console.warn("[aparte] n8n: afterMessageSent threw:",de))})}return ie},qe=new zt({config:u,streamRunner:ar,rawFileInject:"none",scopeToTargetId:b.id});qe.start();let It=()=>b.viewport,or=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"){L.setValue(_.content??""),b.querySelector("aparte-composer-input")?.focusEnd?.();return}Promise.all((_.attachments??[]).map(async A=>{let ie=await(await fetch(A.url)).blob();return new File([ie],A.name,{type:A.type||ie.type})})).then(A=>{xe?Se.push(_.content??""):He(_.content??"",A)},A=>console.warn("[aparte] n8n: a file of that message could not be read again:",A))}};b.addEventListener("aparte-action",or);let Q=-1,Fe="",lr=()=>b.querySelector("aparte-composer-input");L.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&&L.value!==""||Q>=g.length-1)return;Q===-1&&(Fe=L.value),Q++}else{if(Q===-1)return;Q--}h.preventDefault(),L.setValue(Q===-1?Fe:g[g.length-1-Q]??""),lr()?.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 Ot=h=>L.toggleAttribute("disabled",h);(typeof e.disabled=="object"?e.disabled?.value:e.disabled)&&Ot(!0);let Ke=()=>n==="window"?C:void 0,_t=()=>{d||(d=!0,f?.abort(),Se.length=0,window.removeEventListener("aparte-message-aborted",Tt),qe.stop(),k?.(),v?.(),typeof $=="function"&&$(),C.remove())};return{element:C,get sessionId(){return p},open:()=>Ke()?.show(),close:()=>Ke()?.close(),toggle:()=>Ke()?.toggle(),send:h=>{xe?Se.push(h):He(h)},reset:()=>{Se.length=0,L.streaming&&L.cancel(),qe.abort(),xe=!1,f?.abort(),J++,p=e.sessionId??ae(),i&&!e.sessionId&&rr(je,p),P&&(P.hidden=!1),he(X())},setDisabled:Ot,destroy:_t,unmount:_t}}export{Ia as createChat,Wt as defineCard,Ut as el,Vt as formatDay,Gt as formatNumber,Zt as formatPrice,Jt as formatWhen,jt as glyph,Ht as safeUrl,qt as webUrl};
102
+ `):""}function ya(e,{now:t=Date.now()}={}){let n=[];return e.forEach((r,s)=>{if(typeof r!="object"||r===null)return;let i=r,a=ba(i),o=/^Human/.test(a)||a==="human"?"user":/^AI/.test(a)||a==="ai"?"assistant":void 0;if(!o)return;let l=wa(i.kwargs?.content);l.trim()&&n.push({id:`n8n-${s}`,role:o,content:l,timestamp:t-(e.length-s),status:"completed"})}),n}async function Vn(e){let t=e.fetch??fetch,n=typeof e.headers=="function"?await e.headers():e.headers??{},r={"Content-Type":"application/json"};for(let[o,l]of Object.entries(n))o.toLowerCase()!=="content-type"&&(r[o]=l);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 Rt(o,e.webhookUrl)});if(!s.ok)throw await vt(s,"history");let i;try{i=await s.json()}catch{throw new z("n8n answered the history request with something that is not JSON. Check that the URL is the Chat Trigger's production URL.",L.PROVIDER_MISCONFIGURED)}let a=typeof i=="object"&&i!==null?i.data:void 0;return ya(Array.isArray(a)?a:[])}var $t="card-",xa=["weather","items","product","place","stats","order","stock","plan","score","media","link"],qe="aparte-card-fence",Ct=new WeakMap,Sa=e=>`setup${e.charAt(0).toUpperCase()}${e.slice(1)}Card`;function va(e,t){let n=Ct.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[Sa(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 Ra(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 Ea(e){let t=e.getAttribute("data-card")??"",n=e.getAttribute("data-source")??"",r=Bt(e),s=()=>{let c=document.createElement("code");c.className="aparte-code-error",c.textContent=n,e.replaceChildren(c)},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:Ra(t,n),type:"card",card:t,data:i,...a?{variant:a}:{}},l=Je(r,o,"fence");!l&&await va(r,t)&&e.isConnected&&(l=Je(r,o,"fence")),l?e.replaceChildren(l):s()}function $a(){typeof customElements>"u"||typeof HTMLElement>"u"||customElements.get(qe)||customElements.define(qe,class extends HTMLElement{connectedCallback(){this.hasAttribute("data-drawn")||(this.setAttribute("data-drawn",""),Ea(this))}})}function Jn(e={}){let t=e.config??be;e.load&&Ct.set(t,{load:e.load,pending:new Map}),$a();let n=new Set([...xa,...Gt(t),...Object.keys(e.load??{})]),r={languages:[...n].map(i=>`${$t}${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 l=i.slice($t.length);return`<${qe} data-card="${Ve(l)}" data-source="${Ve(a)}"></${qe}>`}},s=[t.registerCodeLanguageRenderer(r)];return s.push(Zt(t,i=>{n.has(i)||(n.add(i),s.push(t.registerCodeLanguageRenderer({...r,languages:[`${$t}${i}`]})))})),()=>{for(let i of s.splice(0))i();Ct.delete(t)}}var Ca={weather:()=>import("./chunks/weather-7L3Y3DNB.js"),items:()=>import("./chunks/items-X2D73Z5A.js"),product:()=>import("./chunks/product-JH7QUP6I.js"),place:()=>import("./chunks/place-N3E7T2EV.js"),stats:()=>import("./chunks/stats-UIVYR2CG.js"),order:()=>import("./chunks/order-HS6FXBIB.js"),stock:()=>import("./chunks/stock-PV4GC573.js"),plan:()=>import("./chunks/plan-TCWRW3OC.js"),score:()=>import("./chunks/score-GUHJWHW3.js"),media:()=>import("./chunks/media-JDTPNZHJ.js"),link:()=>import("./chunks/link-LNDRLLUH.js")},Qn=e=>`setup${e.charAt(0).toUpperCase()}${e.slice(1)}Card`;function Xn(e,t={}){let n=Object.fromEntries(Object.entries(Ca).map(([r,s])=>{let i=t[r];return i?[r,()=>s().then(a=>{let o=a[Qn(r)];return typeof o=="function"?{...a,[Qn(r)]:l=>o({...i,...l})}:a})]:[r,s]}));return Jn({config:e,load:n})}var Ia='<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>',Aa='<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>',Ta='<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>',Yn={launcherOpen:()=>Ia,launcherClose:()=>Aa,send:()=>Ta};var Te={en:{strings:{title:"Hi there! \u{1F44B}",subtitle:"Start a chat. We're here to help you 24/7.",footer:"",poweredBy:"Powered by {aparte}",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:"",poweredBy:"Propuls\xE9 par {aparte}",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-VYD7EC55.js").then(e=>e.fr)},es:{strings:{title:"\xA1Hola! \u{1F44B}",subtitle:"Inicia una conversaci\xF3n. Estamos aqu\xED para ayudarte, 24/7.",footer:"",poweredBy:"Con la tecnolog\xEDa de {aparte}",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-KUX7YCK6.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:"",poweredBy:"Desenvolvido com {aparte}",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-SNSDLB4C.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:"",poweredBy:"Bereitgestellt mit {aparte}",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-7JCOF7FR.js").then(e=>e.de)},it:{strings:{title:"Ciao! \u{1F44B}",subtitle:"Inizia una conversazione. Siamo qui per aiutarti, 24 ore su 24.",footer:"",poweredBy:"Realizzato con {aparte}",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-BXNO2THQ.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:"",poweredBy:"\u0420\u0430\u0431\u043E\u0442\u0430\u0435\u0442 \u043D\u0430 {aparte}",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-QE2LLTEY.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:"",poweredBy:"{aparte} \u3067\u52D5\u4F5C",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-6VGJFQ66.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:"",poweredBy:"{aparte} \uAE30\uBC18",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-HUU4F44X.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:"",poweredBy:"\u7531 {aparte} \u9A71\u52A8",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-WKC5MGZY.js").then(e=>e.zhCN)}};function It(e){if(Te[e])return e;let t=e.split("-")[0]?.toLowerCase()??"";return Object.keys(Te).find(n=>n.split("-")[0]?.toLowerCase()===t)??"en"}function At(e,t){return t?.[e]??t?.[e.split("-")[0]??""]}function er(e,t){return{...Te[It(e)].strings,...At(e,t)??{}}}function tr(e){return Te[It(e)].initial}function nr(e){return Te[It(e)].locale?.()}function Oa(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 Fe="n8n-chat/sessionId",_a=/^(ar|arc|ckb|dv|fa|he|ku-arab|ps|sd|ug|ur|yi)(-|$)/i,rr="N8N_WORKFLOW_ERROR";function La(e){return e===void 0||e===!0?["*"]:e===!1?[]:typeof e=="string"?[e]:e}var or=new WeakMap,sr=!1;function Pa(){sr||(sr=!0,Dt({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?or.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 ir(e){try{return localStorage.getItem(e)??void 0}catch{return}}function ar(e,t){try{localStorage.setItem(e,t)}catch{}}function Ma(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 x(e,t,n){let r=document.createElement(e);return t&&(r.className=t),n!==void 0&&(r.textContent=n),r}var Na=0;function Ba(e){let t=Oa(e.webhookUrl),n=e.mode??"window",r=e.defaultLanguage??"en",s=er(r,e.i18n),i=e.loadPreviousSession??!0,a=e.initialMessages??tr(r),o=++Na,l=`aparte-n8n-title-${o}`,c=i&&!e.sessionId&&!!ir(Fe),d=e.sessionId??(i?ir(Fe):void 0)??ue();i&&!e.sessionId&&ar(Fe,d);let u=new zt;u.setImagePolicy(La(e.images)),e.locale&&u.setLocale(e.locale);let h=!1,g=u.getLocale();nr(r)?.then(p=>{!h&&!e.locale&&u.getLocale()===g&&u.setLocale(p)},p=>console.warn("[aparte] n8n: the chat's language could not be loaded; it stays in English.",p)),u.registerIcons(Yn),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}),Gn(u);let f=e.cards===!1?void 0:Xn(u,typeof e.cards=="object"?e.cards:{}),w=e.replies===!1?void 0:Ut(u);u.setErrorRenderer(({message:p,sentence:m,code:A})=>{let M=A===rr,_=x("div","aparte-segment aparte-alert aparte-alert--danger aparte-segment-error");A&&_.setAttribute("data-error-code",M?L.PROVIDER_ERROR:A);let ce=x("span","aparte-alert__icon");ce.innerHTML=u.getIcon("error")||"\u26A0";let q=x("div","aparte-alert__body");return q.append(x("div","aparte-alert__title",u.t("error")),x("div","aparte-alert__message",M?u.t("errorNoAnswer"):m??p)),_.append(ce,q),_}),Un(void 0,u);let v;u.setHighlightProvider(async(p,m)=>(v??=import("./chunks/highlight-W7QGGHNK.js").then(A=>A.createHighlighter()),(await v)(p,m))),g=u.getLocale();let E=e.setup?.(u),$=x("section","aparte-n8n__window");$.setAttribute("aria-labelledby",l);let R=x("header","aparte-n8n__header"),I=x("div","aparte-n8n__heading"),N=x("p","aparte-n8n__title",s.title);if(N.id=l,I.append(N),s.subtitle&&I.append(x("p","aparte-n8n__subtitle",s.subtitle)),R.append(I),n==="window"&&e.showWindowCloseButton){let p=x("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 m=x("aparte-icon");m.setAttribute("name","close"),p.append(m),R.append(p)}let b=x("aparte-chat","aparte-n8n__chat");b.id=`aparte-n8n-chat-${o}`,e.messageComponents&&(Pa(),or.set(b,e.messageComponents));let T=x("aparte-composer");T.setAttribute("placeholder",s.inputPlaceholder);let B;if(e.suggestions?.length&&(B=x("aparte-suggestions"),B.setAttribute("suggestions",JSON.stringify(e.suggestions.map(p=>({label:p,prompt:p})))),T.append(B)),e.replies!==!1){let p=x("aparte-suggestions");p.setAttribute("answers",""),T.append(p)}let D=x("div","aparte-composer-shell"),te=x("div","aparte-composer-row");te.append(x("aparte-composer-input"));let le=typeof e.allowFileUploads=="object"?e.allowFileUploads?.value:e.allowFileUploads,Se=typeof e.allowedFilesMimeTypes=="object"?e.allowedFilesMimeTypes?.value:e.allowedFilesMimeTypes;if(le){D.append(x("aparte-composer-attachments"));let p=x("aparte-composer-add-attachment");Se&&p.setAttribute("accept",Se),te.append(p)}te.append(x("aparte-composer-send")),D.append(te),T.append(D),b.append(x("aparte-chat-viewport"),x("aparte-elicitation"),T),$.append(R,b);{let p=x("p","aparte-n8n__powered"),m=s.poweredBy?.includes("{aparte}")?s.poweredBy:"Powered by {aparte}",[A,M=""]=m.split("{aparte}"),_=x("a",void 0,"apart\xE9");_.setAttribute("href","https://apartejs.dev/?ref=n8n-chat"),_.setAttribute("target","_blank"),_.setAttribute("rel","noopener"),p.append(A??"",_,M),$.append(p)}s.footer&&$.append(x("p","aparte-n8n__footer",s.footer));let Z;if(e.showWelcomeScreen&&!c){Z=x("div","aparte-n8n__welcome");let p=x("button","aparte-btn aparte-btn--primary aparte-btn--solid aparte-n8n__start",s.getStarted);p.type="button",p.addEventListener("click",()=>{Z.hidden=!0,b.hidden=!1,b.querySelector("aparte-composer-input")?.focusEnd?.()}),Z.append(p),b.hidden=!0,$.insertBefore(Z,b)}let O;n==="window"?(O=x("aparte-launcher","aparte-n8n aparte-n8n--window"),O.append($)):(O=x("div","aparte-n8n aparte-n8n--fullscreen"),O.append($));let ve=e.colorScheme??"light";ve!=="auto"&&O.setAttribute("data-aparte-theme",ve),O.setAttribute("lang",r);let V=e.locale!==void 0||At(r,e.i18n)!==void 0,X=e.locale?.direction??(V&&_a.test(r)?"rtl":void 0);X&&O.setAttribute("dir",X),n==="window"&&O.addEventListener("aparte-launcher-toggle",p=>{let{open:m,sheet:A}=p.detail;m&&A?($.setAttribute("role","dialog"),$.setAttribute("aria-modal","true")):($.removeAttribute("role"),$.removeAttribute("aria-modal"))}),Nt(O,u),Ma(e.target??"#n8n-chat").append(O);let ge=()=>a.map((p,m)=>({id:`n8n-initial-${m}`,role:"assistant",content:p,timestamp:Date.now()-a.length+m,status:"completed"})),me=()=>(e.messageHistory??[]).map((p,m)=>{let A={id:`n8n-seed-${m}`,role:p.sender==="user"?"user":"assistant",timestamp:Date.now(),status:"completed"};if(p.type==="component"){let M={id:`n8n-seed-${m}-component`,type:"n8n-component",key:p.key,arguments:p.arguments??{}};return{...A,content:"",segments:[M]}}return{...A,content:p.text}}),ne=new Set((e.messageHistory??[]).flatMap((p,m)=>p.transparent?[`n8n-seed-${m}`]:[]));ne.size&&new MutationObserver(()=>{for(let p of ne){let m=b.querySelector(`aparte-chat-bubble[message-id="${p}"]`);m&&!m.hasAttribute("data-n8n-transparent")&&m.setAttribute("data-n8n-transparent","")}}).observe(b,{childList:!0,subtree:!0});let re=p=>b.viewport?.setMessages(p);re([...ge(),...me()]),e.messageHistory?.length&&B&&(B.hidden=!0);let se=0,Y,k=()=>{let p=++se;Y=new AbortController,Vn({webhookUrl:t,sessionId:d,...e.metadata?{metadata:e.metadata}:{},...e.chatSessionKey?{chatSessionKey:e.chatSessionKey}:{},headers:()=>({...e.webhookConfig?.headers??{}}),...e.fetch?{fetch:e.fetch}:{},signal:Y.signal}).then(m=>{p!==se||m.length===0||(B&&(B.hidden=!0),re([...ge(),...m]))},m=>{Y?.signal.aborted||console.warn(`[aparte] n8n: ${m instanceof Error?m.message:String(m)}`)})};if(i)if(n==="window"){let p=m=>{m.detail.open&&(O.removeEventListener("aparte-launcher-toggle",p),se===0&&k())};O.addEventListener("aparte-launcher-toggle",p)}else k();let P="",J=d,Re=!1,Ee=[];b.addEventListener("aparte-send",p=>{se++,P=String(p.detail?.content??""),J=d,B&&(B.hidden=!0)});let Ke=(p,m)=>{Z&&!Z.hidden&&(Z.hidden=!0,b.hidden=!1),b.dispatchEvent(new CustomEvent("aparte-send",{detail:{content:p,timestamp:Date.now(),targetId:b.id,...m?.length?{files:m}:{}},bubbles:!0,composed:!0}))},Tt=()=>{Re=!1;let p=Ee.shift();p!==void 0&&queueMicrotask(()=>Ke(p))};b.addEventListener("aparte-message-start",()=>{Re=!0});for(let p of["aparte-message-done","aparte-message-error","aparte-message-aborted"])b.addEventListener(p,Tt);let Ot=p=>{p.detail?.targetId===b.id&&Tt()};window.addEventListener("aparte-message-aborted",Ot);let _t=d,lr=Zn({webhookUrl:t,sessionId:()=>_t,headers:()=>({...e.webhookConfig?.headers??{}}),...e.fetch?{fetch:e.fetch}:{},...e.metadata?{metadata:e.metadata}:{},...e.chatInputKey?{chatInputKey:e.chatInputKey}:{},...e.chatSessionKey?{chatSessionKey:e.chatSessionKey}:{},...e.waitingPrefix!==void 0?{waitingPrefix:e.waitingPrefix}:{}}),cr=async p=>{let m=P,A=J;if(await e.beforeMessageSent?.(m),p.signal.aborted)return;_t=A;let M="",_=!1,ce=await lr({...p,emitter:q=>{q.type==="text-delta"&&(M+=q.delta),q.type==="run-done"&&(_=!0),p.emitter(q)}}).catch(q=>{let ke=q;throw ke?.code===L.PROVIDER_ERROR&&ke.httpStatus===void 0?new z(ke.message??"",rr,ke.data,q):q});if(_&&e.afterMessageSent){let q=e.afterMessageSent;queueMicrotask(()=>{Promise.resolve().then(()=>q(m,{output:M,message:M,hasReceivedChunks:M.length>0})).catch(ke=>console.warn("[aparte] n8n: afterMessageSent threw:",ke))})}return ce},We=new Ht({config:u,streamRunner:cr,rawFileInject:"none",scopeToTargetId:b.id});We.start();let Lt=()=>b.viewport,ur=p=>{let{actionId:m,messageId:A}=p.detail;if(m!=="n8n-repost"&&m!=="n8n-reuse")return;let M=Lt()?.getMessage?.(A);if(M){if(m==="n8n-reuse"){T.setValue(M.content??""),b.querySelector("aparte-composer-input")?.focusEnd?.();return}Promise.all((M.attachments??[]).map(async _=>{let ce=await(await fetch(_.url)).blob();return new File([ce],_.name,{type:_.type||ce.type})})).then(_=>{Re?Ee.push(M.content??""):Ke(M.content??"",_)},_=>console.warn("[aparte] n8n: a file of that message could not be read again:",_))}};b.addEventListener("aparte-action",ur);let ee=-1,Ge="",pr=()=>b.querySelector("aparte-composer-input");T.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 m=(Lt()?.getMessages?.()??[]).filter(A=>A.role==="user"&&A.content?.trim()).map(A=>A.content??"");if(p.key==="ArrowUp"){if(ee===-1&&T.value!==""||ee>=m.length-1)return;ee===-1&&(Ge=T.value),ee++}else{if(ee===-1)return;ee--}p.preventDefault(),T.setValue(ee===-1?Ge:m[m.length-1-ee]??""),pr()?.focusEnd?.()}),b.addEventListener("aparte-send",()=>{ee=-1,Ge=""}),b.addEventListener("click",p=>{if(p.defaultPrevented||p.button!==0||p.metaKey||p.ctrlKey||p.shiftKey||p.altKey)return;let m=p.target?.closest(".aparte-message-content a[href]");!m||m.getAttribute("href")?.startsWith("#")||(p.preventDefault(),window.open(m.href,"_blank","noopener,noreferrer"))}),b.addEventListener("aparte-attachment-preview",p=>{let{url:m}=p.detail;m&&window.open(m,"_blank","noopener,noreferrer")});let Pt=p=>T.toggleAttribute("disabled",p);(typeof e.disabled=="object"?e.disabled?.value:e.disabled)&&Pt(!0);let Ze=()=>n==="window"?O:void 0,Mt=()=>{h||(h=!0,Y?.abort(),Ee.length=0,window.removeEventListener("aparte-message-aborted",Ot),We.stop(),f?.(),w?.(),typeof E=="function"&&E(),O.remove())};return{element:O,get sessionId(){return d},open:()=>Ze()?.show(),close:()=>Ze()?.close(),toggle:()=>Ze()?.toggle(),send:p=>{Re?Ee.push(p):Ke(p)},reset:()=>{Ee.length=0,T.streaming&&T.cancel(),We.abort(),Re=!1,Y?.abort(),se++,d=e.sessionId??ue(),i&&!e.sessionId&&ar(Fe,d),B&&(B.hidden=!1),re(ge())},setDisabled:Pt,destroy:Mt,unmount:Mt}}export{Ba as createChat,Vt as defineCard,qt as el,Xt as formatDay,Jt as formatNumber,Qt as formatPrice,Yt as formatWhen,Ft as glyph,Kt as safeUrl,Wt as webUrl};
103
103
  //# sourceMappingURL=n8n-chat.js.map