@aparte/n8n-chat 1.1.1 → 1.1.3

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