akvo-rag-js 1.2.3 → 1.3.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +50 -9
- package/dist/akvo-rag.css +1 -1
- package/dist/akvo-rag.js +2 -1
- package/dist/akvo-rag.js.LICENSE.txt +1 -0
- package/dist/index.html +815 -13
- package/package.json +1 -1
package/dist/akvo-rag.js
CHANGED
|
@@ -1 +1,2 @@
|
|
|
1
|
-
!function(e,t){"object"==typeof exports&&"object"==typeof module?module.exports=t():"function"==typeof define&&define.amd?define([],t):"object"==typeof exports?exports.AkvoRAG=t():e.AkvoRAG=t()}(this,(()=>(()=>{"use strict";var e={d:(t,n)=>{for(var r in n)e.o(n,r)&&!e.o(t,r)&&Object.defineProperty(t,r,{enumerable:!0,get:n[r]})},o:(e,t)=>Object.prototype.hasOwnProperty.call(e,t),r:e=>{"undefined"!=typeof Symbol&&Symbol.toStringTag&&Object.defineProperty(e,Symbol.toStringTag,{value:"Module"}),Object.defineProperty(e,"__esModule",{value:!0})}},t={};function n(e){return n="function"==typeof Symbol&&"symbol"==typeof Symbol.iterator?function(e){return typeof e}:function(e){return e&&"function"==typeof Symbol&&e.constructor===Symbol&&e!==Symbol.prototype?"symbol":typeof e},n(e)}function r(e,t){var n=Object.keys(e);if(Object.getOwnPropertySymbols){var r=Object.getOwnPropertySymbols(e);t&&(r=r.filter((function(t){return Object.getOwnPropertyDescriptor(e,t).enumerable}))),n.push.apply(n,r)}return n}function i(e){for(var t=1;t<arguments.length;t++){var n=null!=arguments[t]?arguments[t]:{};t%2?r(Object(n),!0).forEach((function(t){o(e,t,n[t])})):Object.getOwnPropertyDescriptors?Object.defineProperties(e,Object.getOwnPropertyDescriptors(n)):r(Object(n)).forEach((function(t){Object.defineProperty(e,t,Object.getOwnPropertyDescriptor(n,t))}))}return e}function o(e,t,r){return(t=function(e){var t=function(e){if("object"!=n(e)||!e)return e;var t=e[Symbol.toPrimitive];if(void 0!==t){var r=t.call(e,"string");if("object"!=n(r))return r;throw new TypeError("@@toPrimitive must return a primitive value.")}return String(e)}(e);return"symbol"==n(t)?t:t+""}(t))in e?Object.defineProperty(e,t,{value:r,enumerable:!0,configurable:!0,writable:!0}):e[t]=r,e}function s(e,t){(null==t||t>e.length)&&(t=e.length);for(var n=0,r=Array(t);n<t;n++)r[n]=e[n];return r}e.r(t),e.d(t,{initChat:()=>Rt});let a={async:!1,breaks:!1,extensions:null,gfm:!0,hooks:null,pedantic:!1,renderer:null,silent:!1,tokenizer:null,walkTokens:null};function l(e){a=e}const c={exec:()=>null};function u(e,t=""){let n="string"==typeof e?e:e.source;const r={replace:(e,t)=>{let i="string"==typeof t?t:t.source;return i=i.replace(p.caret,"$1"),n=n.replace(e,i),r},getRegex:()=>new RegExp(n,t)};return r}const p={codeRemoveIndent:/^(?: {1,4}| {0,3}\t)/gm,outputLinkReplace:/\\([\[\]])/g,indentCodeCompensation:/^(\s+)(?:```)/,beginningSpace:/^\s+/,endingHash:/#$/,startingSpaceChar:/^ /,endingSpaceChar:/ $/,nonSpaceChar:/[^ ]/,newLineCharGlobal:/\n/g,tabCharGlobal:/\t/g,multipleSpaceGlobal:/\s+/g,blankLine:/^[ \t]*$/,doubleBlankLine:/\n[ \t]*\n[ \t]*$/,blockquoteStart:/^ {0,3}>/,blockquoteSetextReplace:/\n {0,3}((?:=+|-+) *)(?=\n|$)/g,blockquoteSetextReplace2:/^ {0,3}>[ \t]?/gm,listReplaceTabs:/^\t+/,listReplaceNesting:/^ {1,4}(?=( {4})*[^ ])/g,listIsTask:/^\[[ xX]\] /,listReplaceTask:/^\[[ 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,unescapeTest:/&(#(?:\d+)|(?:#x[0-9A-Fa-f]+)|(?:\w+));?/gi,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})((?:[\t ][^\\n]*)?(?:\\n|$))`),nextBulletRegex:e=>new RegExp(`^ {0,${Math.min(3,e-1)}}(?:[*+-]|\\d{1,9}[.)])((?:[ \t][^\\n]*)?(?:\\n|$))`),hrRegex:e=>new RegExp(`^ {0,${Math.min(3,e-1)}}((?:- *){3,}|(?:_ *){3,}|(?:\\* *){3,})(?:\\n+|$)`),fencesBeginRegex:e=>new RegExp(`^ {0,${Math.min(3,e-1)}}(?:\`\`\`|~~~)`),headingBeginRegex:e=>new RegExp(`^ {0,${Math.min(3,e-1)}}#`),htmlBeginRegex:e=>new RegExp(`^ {0,${Math.min(3,e-1)}}<(?:[a-z].*>|!--)`,"i")},h=/^ {0,3}((?:-[\t ]*){3,}|(?:_[ \t]*){3,}|(?:\*[ \t]*){3,})(?:\n+|$)/,d=/(?:[*+-]|\d{1,9}[.)])/,f=/^(?!bull |blockCode|fences|blockquote|heading|html|table)((?:.|\n(?!\s*?\n|bull |blockCode|fences|blockquote|heading|html|table))+?)\n {0,3}(=+|-+) *(?:\n+|$)/,g=u(f).replace(/bull/g,d).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(),m=u(f).replace(/bull/g,d).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(),k=/^([^\n]+(?:\n(?!hr|heading|lheading|blockquote|fences|list|html|table| +\n)[^\n]+)*)/,b=/(?!\s*\])(?:\\.|[^\[\]\\])+/,y=u(/^ {0,3}\[(label)\]: *(?:\n[ \t]*)?([^<\s][^\s]*|<.*?>)(?:(?: +(?:\n[ \t]*)?| *\n[ \t]*)(title))? *(?:\n+|$)/).replace("label",b).replace("title",/(?:"(?:\\"?|[^"\\])*"|'[^'\n]*(?:\n[^'\n]+)*\n?'|\([^()]*\))/).getRegex(),x=u(/^( {0,3}bull)([ \t][^\n]+?)?(?:\n|$)/).replace(/bull/g,d).getRegex(),w="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",v=/<!--(?:-?>|[\s\S]*?(?:-->|$))/,S=u("^ {0,3}(?:<(script|pre|style|textarea)[\\s>][\\s\\S]*?(?:</\\1>[^\\n]*\\n+|$)|comment[^\\n]*(\\n+|$)|<\\?[\\s\\S]*?(?:\\?>\\n*|$)|<![A-Z][\\s\\S]*?(?:>\\n*|$)|<!\\[CDATA\\[[\\s\\S]*?(?:\\]\\]>\\n*|$)|</?(tag)(?: +|\\n|/?>)[\\s\\S]*?(?:(?:\\n[ \t]*)+\\n|$)|<(?!script|pre|style|textarea)([a-z][\\w-]*)(?:attribute)*? */?>(?=[ \\t]*(?:\\n|$))[\\s\\S]*?(?:(?:\\n[ \t]*)+\\n|$)|</(?!script|pre|style|textarea)[a-z][\\w-]*\\s*>(?=[ \\t]*(?:\\n|$))[\\s\\S]*?(?:(?:\\n[ \t]*)+\\n|$))","i").replace("comment",v).replace("tag",w).replace("attribute",/ +[a-zA-Z:_][\w.:-]*(?: *= *"[^"\n]*"| *= *'[^'\n]*'| *= *[^\s"'=<>`]+)?/).getRegex(),T=u(k).replace("hr",h).replace("heading"," {0,3}#{1,6}(?:\\s|$)").replace("|lheading","").replace("|table","").replace("blockquote"," {0,3}>").replace("fences"," {0,3}(?:`{3,}(?=[^`\\n]*\\n)|~{3,})[^\\n]*\\n").replace("list"," {0,3}(?:[*+-]|1[.)]) ").replace("html","</?(?:tag)(?: +|\\n|/?>)|<(?:script|pre|style|textarea|!--)").replace("tag",w).getRegex(),_={blockquote:u(/^( {0,3}> ?(paragraph|[^\n]*)(?:\n|$))+/).replace("paragraph",T).getRegex(),code:/^((?: {4}| {0,3}\t)[^\n]+(?:\n(?:[ \t]*(?:\n|$))*)?)+/,def:y,fences:/^ {0,3}(`{3,}(?=[^`\n]*(?:\n|$))|~{3,})([^\n]*)(?:\n|$)(?:|([\s\S]*?)(?:\n|$))(?: {0,3}\1[~`]* *(?=\n|$)|$)/,heading:/^ {0,3}(#{1,6})(?=\s|$)(.*)(?:\n+|$)/,hr:h,html:S,lheading:g,list:x,newline:/^(?:[ \t]*(?:\n|$))+/,paragraph:T,table:c,text:/^[^\n]+/},E=u("^ *([^\\n ].*)\\n {0,3}((?:\\| *)?:?-+:? *(?:\\| *:?-+:? *)*(?:\\| *)?)(?:\\n((?:(?! *\\n|hr|heading|blockquote|code|fences|list|html).*(?:\\n|$))*)\\n*|$)").replace("hr",h).replace("heading"," {0,3}#{1,6}(?:\\s|$)").replace("blockquote"," {0,3}>").replace("code","(?: {4}| {0,3}\t)[^\\n]").replace("fences"," {0,3}(?:`{3,}(?=[^`\\n]*\\n)|~{3,})[^\\n]*\\n").replace("list"," {0,3}(?:[*+-]|1[.)]) ").replace("html","</?(?:tag)(?: +|\\n|/?>)|<(?:script|pre|style|textarea|!--)").replace("tag",w).getRegex(),A={..._,lheading:m,table:E,paragraph:u(k).replace("hr",h).replace("heading"," {0,3}#{1,6}(?:\\s|$)").replace("|lheading","").replace("table",E).replace("blockquote"," {0,3}>").replace("fences"," {0,3}(?:`{3,}(?=[^`\\n]*\\n)|~{3,})[^\\n]*\\n").replace("list"," {0,3}(?:[*+-]|1[.)]) ").replace("html","</?(?:tag)(?: +|\\n|/?>)|<(?:script|pre|style|textarea|!--)").replace("tag",w).getRegex()},R={..._,html:u("^ *(?:comment *(?:\\n|\\s*$)|<(tag)[\\s\\S]+?</\\1> *(?:\\n{2,}|\\s*$)|<tag(?:\"[^\"]*\"|'[^']*'|\\s[^'\"/>\\s]*)*?/?> *(?:\\n{2,}|\\s*$))").replace("comment",v).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:c,lheading:/^(.+?)\n {0,3}(=+|-+) *(?:\n+|$)/,paragraph:u(k).replace("hr",h).replace("heading"," *#{1,6} *[^\n]").replace("lheading",g).replace("|table","").replace("blockquote"," {0,3}>").replace("|fences","").replace("|list","").replace("|html","").replace("|tag","").getRegex()},L=/^( {2,}|\\)\n(?!\s*$)/,O=/[\p{P}\p{S}]/u,N=/[\s\p{P}\p{S}]/u,C=/[^\s\p{P}\p{S}]/u,z=u(/^((?![*_])punctSpace)/,"u").replace(/punctSpace/g,N).getRegex(),I=/(?!~)[\p{P}\p{S}]/u,M=/^(?:\*+(?:((?!\*)punct)|[^\s*]))|^_+(?:((?!_)punct)|([^\s_]))/,P=u(M,"u").replace(/punct/g,O).getRegex(),$=u(M,"u").replace(/punct/g,I).getRegex(),D="^[^_*]*?__[^_*]*?\\*[^_*]*?(?=__)|[^*]+(?=[^*])|(?!\\*)punct(\\*+)(?=[\\s]|$)|notPunctSpace(\\*+)(?!\\*)(?=punctSpace|$)|(?!\\*)punctSpace(\\*+)(?=notPunctSpace)|[\\s](\\*+)(?!\\*)(?=punct)|(?!\\*)punct(\\*+)(?!\\*)(?=punct)|notPunctSpace(\\*+)(?=notPunctSpace)",H=u(D,"gu").replace(/notPunctSpace/g,C).replace(/punctSpace/g,N).replace(/punct/g,O).getRegex(),U=u(D,"gu").replace(/notPunctSpace/g,/(?:[^\s\p{P}\p{S}]|~)/u).replace(/punctSpace/g,/(?!~)[\s\p{P}\p{S}]/u).replace(/punct/g,I).getRegex(),j=u("^[^_*]*?\\*\\*[^_*]*?_[^_*]*?(?=\\*\\*)|[^_]+(?=[^_])|(?!_)punct(_+)(?=[\\s]|$)|notPunctSpace(_+)(?!_)(?=punctSpace|$)|(?!_)punctSpace(_+)(?=notPunctSpace)|[\\s](_+)(?!_)(?=punct)|(?!_)punct(_+)(?!_)(?=punct)","gu").replace(/notPunctSpace/g,C).replace(/punctSpace/g,N).replace(/punct/g,O).getRegex(),B=u(/\\(punct)/,"gu").replace(/punct/g,O).getRegex(),q=u(/^<(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(),F=u(v).replace("(?:--\x3e|$)","--\x3e").getRegex(),W=u("^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",F).replace("attribute",/\s+[a-zA-Z:_][\w.:-]*(?:\s*=\s*"[^"]*"|\s*=\s*'[^']*'|\s*=\s*[^\s"'=<>`]+)?/).getRegex(),G=/(?:\[(?:\\.|[^\[\]\\])*\]|\\.|`[^`]*`|[^\[\]\\`])*?/,Z=u(/^!?\[(label)\]\(\s*(href)(?:(?:[ \t]*(?:\n[ \t]*)?)(title))?\s*\)/).replace("label",G).replace("href",/<(?:\\.|[^\n<>\\])+>|[^ \t\n\x00-\x1f]*/).replace("title",/"(?:\\"?|[^"\\])*"|'(?:\\'?|[^'\\])*'|\((?:\\\)?|[^)\\])*\)/).getRegex(),Y=u(/^!?\[(label)\]\[(ref)\]/).replace("label",G).replace("ref",b).getRegex(),X=u(/^!?\[(ref)\](?:\[\])?/).replace("ref",b).getRegex(),Q={_backpedal:c,anyPunctuation:B,autolink:q,blockSkip:/\[[^[\]]*?\]\((?:\\.|[^\\\(\)]|\((?:\\.|[^\\\(\)])*\))*\)|`[^`]*?`|<[^<>]*?>/g,br:L,code:/^(`+)([^`]|[^`][\s\S]*?[^`])\1(?!`)/,del:c,emStrongLDelim:P,emStrongRDelimAst:H,emStrongRDelimUnd:j,escape:/^\\([!"#$%&'()*+,\-./:;<=>?@\[\]\\^_`{|}~])/,link:Z,nolink:X,punctuation:z,reflink:Y,reflinkSearch:u("reflink|nolink(?!\\()","g").replace("reflink",Y).replace("nolink",X).getRegex(),tag:W,text:/^(`+|[^`])(?:(?= {2,}\n)|[\s\S]*?(?:(?=[\\<!\[`*_]|\b_|$)|[^ ](?= {2,}\n)))/,url:c},J={...Q,link:u(/^!?\[(label)\]\((.*?)\)/).replace("label",G).getRegex(),reflink:u(/^!?\[(label)\]\s*\[([^\]]*)\]/).replace("label",G).getRegex()},K={...Q,emStrongRDelimAst:U,emStrongLDelim:$,url:u(/^((?:ftp|https?):\/\/|www\.)(?:[a-zA-Z0-9\-]+\.?)+[^\s<]*|^email/,"i").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~\\]))\1(?=[^~]|$)/,text:/^([`~]+|[^`~])(?:(?= {2,}\n)|(?=[a-zA-Z0-9.!#$%&'*+\/=?_`{\|}~-]+@)|[\s\S]*?(?:(?=[\\<!\[`*~_]|\b_|https?:\/\/|ftp:\/\/|www\.|$)|[^ ](?= {2,}\n)|[^a-zA-Z0-9.!#$%&'*+\/=?_`{\|}~-](?=[a-zA-Z0-9.!#$%&'*+\/=?_`{\|}~-]+@)))/},V={...K,br:u(L).replace("{2,}","*").getRegex(),text:u(K.text).replace("\\b_","\\b_| {2,}\\n").replace(/\{2,\}/g,"*").getRegex()},ee={normal:_,gfm:A,pedantic:R},te={normal:Q,gfm:K,breaks:V,pedantic:J},ne={"&":"&","<":"<",">":">",'"':""","'":"'"},re=e=>ne[e];function ie(e,t){if(t){if(p.escapeTest.test(e))return e.replace(p.escapeReplace,re)}else if(p.escapeTestNoEncode.test(e))return e.replace(p.escapeReplaceNoEncode,re);return e}function oe(e){try{e=encodeURI(e).replace(p.percentDecode,"%")}catch{return null}return e}function se(e,t){const n=e.replace(p.findPipe,((e,t,n)=>{let r=!1,i=t;for(;--i>=0&&"\\"===n[i];)r=!r;return r?"|":" |"})).split(p.splitPipe);let r=0;if(n[0].trim()||n.shift(),n.length>0&&!n.at(-1)?.trim()&&n.pop(),t)if(n.length>t)n.splice(t);else for(;n.length<t;)n.push("");for(;r<n.length;r++)n[r]=n[r].trim().replace(p.slashPipe,"|");return n}function ae(e,t,n){const r=e.length;if(0===r)return"";let i=0;for(;i<r&&e.charAt(r-i-1)===t;)i++;return e.slice(0,r-i)}function le(e,t,n,r,i){const o=t.href,s=t.title||null,a=e[1].replace(i.other.outputLinkReplace,"$1");r.state.inLink=!0;const l={type:"!"===e[0].charAt(0)?"image":"link",raw:n,href:o,title:s,text:a,tokens:r.inlineTokens(a)};return r.state.inLink=!1,l}class ce{options;rules;lexer;constructor(e){this.options=e||a}space(e){const t=this.rules.block.newline.exec(e);if(t&&t[0].length>0)return{type:"space",raw:t[0]}}code(e){const t=this.rules.block.code.exec(e);if(t){const e=t[0].replace(this.rules.other.codeRemoveIndent,"");return{type:"code",raw:t[0],codeBlockStyle:"indented",text:this.options.pedantic?e:ae(e,"\n")}}}fences(e){const t=this.rules.block.fences.exec(e);if(t){const e=t[0],n=function(e,t,n){const r=e.match(n.other.indentCodeCompensation);if(null===r)return t;const i=r[1];return t.split("\n").map((e=>{const t=e.match(n.other.beginningSpace);if(null===t)return e;const[r]=t;return r.length>=i.length?e.slice(i.length):e})).join("\n")}(e,t[3]||"",this.rules);return{type:"code",raw:e,lang:t[2]?t[2].trim().replace(this.rules.inline.anyPunctuation,"$1"):t[2],text:n}}}heading(e){const t=this.rules.block.heading.exec(e);if(t){let e=t[2].trim();if(this.rules.other.endingHash.test(e)){const t=ae(e,"#");this.options.pedantic?e=t.trim():t&&!this.rules.other.endingSpaceChar.test(t)||(e=t.trim())}return{type:"heading",raw:t[0],depth:t[1].length,text:e,tokens:this.lexer.inline(e)}}}hr(e){const t=this.rules.block.hr.exec(e);if(t)return{type:"hr",raw:ae(t[0],"\n")}}blockquote(e){const t=this.rules.block.blockquote.exec(e);if(t){let e=ae(t[0],"\n").split("\n"),n="",r="";const i=[];for(;e.length>0;){let t=!1;const o=[];let s;for(s=0;s<e.length;s++)if(this.rules.other.blockquoteStart.test(e[s]))o.push(e[s]),t=!0;else{if(t)break;o.push(e[s])}e=e.slice(s);const a=o.join("\n"),l=a.replace(this.rules.other.blockquoteSetextReplace,"\n $1").replace(this.rules.other.blockquoteSetextReplace2,"");n=n?`${n}\n${a}`:a,r=r?`${r}\n${l}`:l;const c=this.lexer.state.top;if(this.lexer.state.top=!0,this.lexer.blockTokens(l,i,!0),this.lexer.state.top=c,0===e.length)break;const u=i.at(-1);if("code"===u?.type)break;if("blockquote"===u?.type){const t=u,o=t.raw+"\n"+e.join("\n"),s=this.blockquote(o);i[i.length-1]=s,n=n.substring(0,n.length-t.raw.length)+s.raw,r=r.substring(0,r.length-t.text.length)+s.text;break}if("list"!==u?.type);else{const t=u,o=t.raw+"\n"+e.join("\n"),s=this.list(o);i[i.length-1]=s,n=n.substring(0,n.length-u.raw.length)+s.raw,r=r.substring(0,r.length-t.raw.length)+s.raw,e=o.substring(i.at(-1).raw.length).split("\n")}}return{type:"blockquote",raw:n,tokens:i,text:r}}}list(e){let t=this.rules.block.list.exec(e);if(t){let n=t[1].trim();const r=n.length>1,i={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:"[*+-]");const o=this.rules.other.listItemRegex(n);let s=!1;for(;e;){let n=!1,r="",a="";if(!(t=o.exec(e)))break;if(this.rules.block.hr.test(e))break;r=t[0],e=e.substring(r.length);let l=t[2].split("\n",1)[0].replace(this.rules.other.listReplaceTabs,(e=>" ".repeat(3*e.length))),c=e.split("\n",1)[0],u=!l.trim(),p=0;if(this.options.pedantic?(p=2,a=l.trimStart()):u?p=t[1].length+1:(p=t[2].search(this.rules.other.nonSpaceChar),p=p>4?1:p,a=l.slice(p),p+=t[1].length),u&&this.rules.other.blankLine.test(c)&&(r+=c+"\n",e=e.substring(c.length+1),n=!0),!n){const t=this.rules.other.nextBulletRegex(p),n=this.rules.other.hrRegex(p),i=this.rules.other.fencesBeginRegex(p),o=this.rules.other.headingBeginRegex(p),s=this.rules.other.htmlBeginRegex(p);for(;e;){const h=e.split("\n",1)[0];let d;if(c=h,this.options.pedantic?(c=c.replace(this.rules.other.listReplaceNesting," "),d=c):d=c.replace(this.rules.other.tabCharGlobal," "),i.test(c))break;if(o.test(c))break;if(s.test(c))break;if(t.test(c))break;if(n.test(c))break;if(d.search(this.rules.other.nonSpaceChar)>=p||!c.trim())a+="\n"+d.slice(p);else{if(u)break;if(l.replace(this.rules.other.tabCharGlobal," ").search(this.rules.other.nonSpaceChar)>=4)break;if(i.test(l))break;if(o.test(l))break;if(n.test(l))break;a+="\n"+c}u||c.trim()||(u=!0),r+=h+"\n",e=e.substring(h.length+1),l=d.slice(p)}}i.loose||(s?i.loose=!0:this.rules.other.doubleBlankLine.test(r)&&(s=!0));let h,d=null;this.options.gfm&&(d=this.rules.other.listIsTask.exec(a),d&&(h="[ ] "!==d[0],a=a.replace(this.rules.other.listReplaceTask,""))),i.items.push({type:"list_item",raw:r,task:!!d,checked:h,loose:!1,text:a,tokens:[]}),i.raw+=r}const a=i.items.at(-1);if(!a)return;a.raw=a.raw.trimEnd(),a.text=a.text.trimEnd(),i.raw=i.raw.trimEnd();for(let e=0;e<i.items.length;e++)if(this.lexer.state.top=!1,i.items[e].tokens=this.lexer.blockTokens(i.items[e].text,[]),!i.loose){const t=i.items[e].tokens.filter((e=>"space"===e.type)),n=t.length>0&&t.some((e=>this.rules.other.anyLine.test(e.raw)));i.loose=n}if(i.loose)for(let e=0;e<i.items.length;e++)i.items[e].loose=!0;return i}}html(e){const t=this.rules.block.html.exec(e);if(t)return{type:"html",block:!0,raw:t[0],pre:"pre"===t[1]||"script"===t[1]||"style"===t[1],text:t[0]}}def(e){const t=this.rules.block.def.exec(e);if(t){const e=t[1].toLowerCase().replace(this.rules.other.multipleSpaceGlobal," "),n=t[2]?t[2].replace(this.rules.other.hrefBrackets,"$1").replace(this.rules.inline.anyPunctuation,"$1"):"",r=t[3]?t[3].substring(1,t[3].length-1).replace(this.rules.inline.anyPunctuation,"$1"):t[3];return{type:"def",tag:e,raw:t[0],href:n,title:r}}}table(e){const t=this.rules.block.table.exec(e);if(!t)return;if(!this.rules.other.tableDelimiter.test(t[2]))return;const n=se(t[1]),r=t[2].replace(this.rules.other.tableAlignChars,"").split("|"),i=t[3]?.trim()?t[3].replace(this.rules.other.tableRowBlankLine,"").split("\n"):[],o={type:"table",raw:t[0],header:[],align:[],rows:[]};if(n.length===r.length){for(const e of r)this.rules.other.tableAlignRight.test(e)?o.align.push("right"):this.rules.other.tableAlignCenter.test(e)?o.align.push("center"):this.rules.other.tableAlignLeft.test(e)?o.align.push("left"):o.align.push(null);for(let e=0;e<n.length;e++)o.header.push({text:n[e],tokens:this.lexer.inline(n[e]),header:!0,align:o.align[e]});for(const e of i)o.rows.push(se(e,o.header.length).map(((e,t)=>({text:e,tokens:this.lexer.inline(e),header:!1,align:o.align[t]}))));return o}}lheading(e){const t=this.rules.block.lheading.exec(e);if(t)return{type:"heading",raw:t[0],depth:"="===t[2].charAt(0)?1:2,text:t[1],tokens:this.lexer.inline(t[1])}}paragraph(e){const t=this.rules.block.paragraph.exec(e);if(t){const e="\n"===t[1].charAt(t[1].length-1)?t[1].slice(0,-1):t[1];return{type:"paragraph",raw:t[0],text:e,tokens:this.lexer.inline(e)}}}text(e){const 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){const t=this.rules.inline.escape.exec(e);if(t)return{type:"escape",raw:t[0],text:t[1]}}tag(e){const 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){const t=this.rules.inline.link.exec(e);if(t){const e=t[2].trim();if(!this.options.pedantic&&this.rules.other.startAngleBracket.test(e)){if(!this.rules.other.endAngleBracket.test(e))return;const t=ae(e.slice(0,-1),"\\");if((e.length-t.length)%2==0)return}else{const e=function(e,t){if(-1===e.indexOf(t[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}(t[2],"()");if(-2===e)return;if(e>-1){const n=(0===t[0].indexOf("!")?5:4)+t[1].length+e;t[2]=t[2].substring(0,e),t[0]=t[0].substring(0,n).trim(),t[3]=""}}let n=t[2],r="";if(this.options.pedantic){const e=this.rules.other.pedanticHrefTitle.exec(n);e&&(n=e[1],r=e[3])}else r=t[3]?t[3].slice(1,-1):"";return n=n.trim(),this.rules.other.startAngleBracket.test(n)&&(n=this.options.pedantic&&!this.rules.other.endAngleBracket.test(e)?n.slice(1):n.slice(1,-1)),le(t,{href:n?n.replace(this.rules.inline.anyPunctuation,"$1"):n,title:r?r.replace(this.rules.inline.anyPunctuation,"$1"):r},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))){const e=t[(n[2]||n[1]).replace(this.rules.other.multipleSpaceGlobal," ").toLowerCase()];if(!e){const e=n[0].charAt(0);return{type:"text",raw:e,text:e}}return le(n,e,n[0],this.lexer,this.rules)}}emStrong(e,t,n=""){let r=this.rules.inline.emStrongLDelim.exec(e);if(r&&(!r[3]||!n.match(this.rules.other.unicodeAlphaNumeric))&&(!r[1]&&!r[2]||!n||this.rules.inline.punctuation.exec(n))){const n=[...r[0]].length-1;let i,o,s=n,a=0;const l="*"===r[0][0]?this.rules.inline.emStrongRDelimAst:this.rules.inline.emStrongRDelimUnd;for(l.lastIndex=0,t=t.slice(-1*e.length+n);null!=(r=l.exec(t));){if(i=r[1]||r[2]||r[3]||r[4]||r[5]||r[6],!i)continue;if(o=[...i].length,r[3]||r[4]){s+=o;continue}if((r[5]||r[6])&&n%3&&!((n+o)%3)){a+=o;continue}if(s-=o,s>0)continue;o=Math.min(o,o+s+a);const t=[...r[0]][0].length,l=e.slice(0,n+r.index+t+o);if(Math.min(n,o)%2){const e=l.slice(1,-1);return{type:"em",raw:l,text:e,tokens:this.lexer.inlineTokens(e)}}const c=l.slice(2,-2);return{type:"strong",raw:l,text:c,tokens:this.lexer.inlineTokens(c)}}}}codespan(e){const t=this.rules.inline.code.exec(e);if(t){let e=t[2].replace(this.rules.other.newLineCharGlobal," ");const n=this.rules.other.nonSpaceChar.test(e),r=this.rules.other.startingSpaceChar.test(e)&&this.rules.other.endingSpaceChar.test(e);return n&&r&&(e=e.substring(1,e.length-1)),{type:"codespan",raw:t[0],text:e}}}br(e){const t=this.rules.inline.br.exec(e);if(t)return{type:"br",raw:t[0]}}del(e){const t=this.rules.inline.del.exec(e);if(t)return{type:"del",raw:t[0],text:t[2],tokens:this.lexer.inlineTokens(t[2])}}autolink(e){const t=this.rules.inline.autolink.exec(e);if(t){let e,n;return"@"===t[2]?(e=t[1],n="mailto:"+e):(e=t[1],n=e),{type:"link",raw:t[0],text:e,href:n,tokens:[{type:"text",raw:e,text:e}]}}}url(e){let t;if(t=this.rules.inline.url.exec(e)){let e,n;if("@"===t[2])e=t[0],n="mailto:"+e;else{let r;do{r=t[0],t[0]=this.rules.inline._backpedal.exec(t[0])?.[0]??""}while(r!==t[0]);e=t[0],n="www."===t[1]?"http://"+t[0]:t[0]}return{type:"link",raw:t[0],text:e,href:n,tokens:[{type:"text",raw:e,text:e}]}}}inlineText(e){const t=this.rules.inline.text.exec(e);if(t){const e=this.lexer.state.inRawBlock;return{type:"text",raw:t[0],text:t[0],escaped:e}}}}class ue{tokens;options;state;tokenizer;inlineQueue;constructor(e){this.tokens=[],this.tokens.links=Object.create(null),this.options=e||a,this.options.tokenizer=this.options.tokenizer||new ce,this.tokenizer=this.options.tokenizer,this.tokenizer.options=this.options,this.tokenizer.lexer=this,this.inlineQueue=[],this.state={inLink:!1,inRawBlock:!1,top:!0};const t={other:p,block:ee.normal,inline:te.normal};this.options.pedantic?(t.block=ee.pedantic,t.inline=te.pedantic):this.options.gfm&&(t.block=ee.gfm,this.options.breaks?t.inline=te.breaks:t.inline=te.gfm),this.tokenizer.rules=t}static get rules(){return{block:ee,inline:te}}static lex(e,t){return new ue(t).lex(e)}static lexInline(e,t){return new ue(t).inlineTokens(e)}lex(e){e=e.replace(p.carriageReturn,"\n"),this.blockTokens(e,this.tokens);for(let e=0;e<this.inlineQueue.length;e++){const t=this.inlineQueue[e];this.inlineTokens(t.src,t.tokens)}return this.inlineQueue=[],this.tokens}blockTokens(e,t=[],n=!1){for(this.options.pedantic&&(e=e.replace(p.tabCharGlobal," ").replace(p.spaceLine,""));e;){let r;if(this.options.extensions?.block?.some((n=>!!(r=n.call({lexer:this},e,t))&&(e=e.substring(r.raw.length),t.push(r),!0))))continue;if(r=this.tokenizer.space(e)){e=e.substring(r.raw.length);const n=t.at(-1);1===r.raw.length&&void 0!==n?n.raw+="\n":t.push(r);continue}if(r=this.tokenizer.code(e)){e=e.substring(r.raw.length);const n=t.at(-1);"paragraph"===n?.type||"text"===n?.type?(n.raw+="\n"+r.raw,n.text+="\n"+r.text,this.inlineQueue.at(-1).src=n.text):t.push(r);continue}if(r=this.tokenizer.fences(e)){e=e.substring(r.raw.length),t.push(r);continue}if(r=this.tokenizer.heading(e)){e=e.substring(r.raw.length),t.push(r);continue}if(r=this.tokenizer.hr(e)){e=e.substring(r.raw.length),t.push(r);continue}if(r=this.tokenizer.blockquote(e)){e=e.substring(r.raw.length),t.push(r);continue}if(r=this.tokenizer.list(e)){e=e.substring(r.raw.length),t.push(r);continue}if(r=this.tokenizer.html(e)){e=e.substring(r.raw.length),t.push(r);continue}if(r=this.tokenizer.def(e)){e=e.substring(r.raw.length);const n=t.at(-1);"paragraph"===n?.type||"text"===n?.type?(n.raw+="\n"+r.raw,n.text+="\n"+r.raw,this.inlineQueue.at(-1).src=n.text):this.tokens.links[r.tag]||(this.tokens.links[r.tag]={href:r.href,title:r.title});continue}if(r=this.tokenizer.table(e)){e=e.substring(r.raw.length),t.push(r);continue}if(r=this.tokenizer.lheading(e)){e=e.substring(r.raw.length),t.push(r);continue}let i=e;if(this.options.extensions?.startBlock){let t=1/0;const n=e.slice(1);let r;this.options.extensions.startBlock.forEach((e=>{r=e.call({lexer:this},n),"number"==typeof r&&r>=0&&(t=Math.min(t,r))})),t<1/0&&t>=0&&(i=e.substring(0,t+1))}if(this.state.top&&(r=this.tokenizer.paragraph(i))){const o=t.at(-1);n&&"paragraph"===o?.type?(o.raw+="\n"+r.raw,o.text+="\n"+r.text,this.inlineQueue.pop(),this.inlineQueue.at(-1).src=o.text):t.push(r),n=i.length!==e.length,e=e.substring(r.raw.length)}else if(r=this.tokenizer.text(e)){e=e.substring(r.raw.length);const n=t.at(-1);"text"===n?.type?(n.raw+="\n"+r.raw,n.text+="\n"+r.text,this.inlineQueue.pop(),this.inlineQueue.at(-1).src=n.text):t.push(r)}else if(e){const t="Infinite loop on byte: "+e.charCodeAt(0);if(this.options.silent){console.error(t);break}throw new Error(t)}}return this.state.top=!0,t}inline(e,t=[]){return this.inlineQueue.push({src:e,tokens:t}),t}inlineTokens(e,t=[]){let n=e,r=null;if(this.tokens.links){const e=Object.keys(this.tokens.links);if(e.length>0)for(;null!=(r=this.tokenizer.rules.inline.reflinkSearch.exec(n));)e.includes(r[0].slice(r[0].lastIndexOf("[")+1,-1))&&(n=n.slice(0,r.index)+"["+"a".repeat(r[0].length-2)+"]"+n.slice(this.tokenizer.rules.inline.reflinkSearch.lastIndex))}for(;null!=(r=this.tokenizer.rules.inline.anyPunctuation.exec(n));)n=n.slice(0,r.index)+"++"+n.slice(this.tokenizer.rules.inline.anyPunctuation.lastIndex);for(;null!=(r=this.tokenizer.rules.inline.blockSkip.exec(n));)n=n.slice(0,r.index)+"["+"a".repeat(r[0].length-2)+"]"+n.slice(this.tokenizer.rules.inline.blockSkip.lastIndex);let i=!1,o="";for(;e;){let r;if(i||(o=""),i=!1,this.options.extensions?.inline?.some((n=>!!(r=n.call({lexer:this},e,t))&&(e=e.substring(r.raw.length),t.push(r),!0))))continue;if(r=this.tokenizer.escape(e)){e=e.substring(r.raw.length),t.push(r);continue}if(r=this.tokenizer.tag(e)){e=e.substring(r.raw.length),t.push(r);continue}if(r=this.tokenizer.link(e)){e=e.substring(r.raw.length),t.push(r);continue}if(r=this.tokenizer.reflink(e,this.tokens.links)){e=e.substring(r.raw.length);const n=t.at(-1);"text"===r.type&&"text"===n?.type?(n.raw+=r.raw,n.text+=r.text):t.push(r);continue}if(r=this.tokenizer.emStrong(e,n,o)){e=e.substring(r.raw.length),t.push(r);continue}if(r=this.tokenizer.codespan(e)){e=e.substring(r.raw.length),t.push(r);continue}if(r=this.tokenizer.br(e)){e=e.substring(r.raw.length),t.push(r);continue}if(r=this.tokenizer.del(e)){e=e.substring(r.raw.length),t.push(r);continue}if(r=this.tokenizer.autolink(e)){e=e.substring(r.raw.length),t.push(r);continue}if(!this.state.inLink&&(r=this.tokenizer.url(e))){e=e.substring(r.raw.length),t.push(r);continue}let s=e;if(this.options.extensions?.startInline){let t=1/0;const n=e.slice(1);let r;this.options.extensions.startInline.forEach((e=>{r=e.call({lexer:this},n),"number"==typeof r&&r>=0&&(t=Math.min(t,r))})),t<1/0&&t>=0&&(s=e.substring(0,t+1))}if(r=this.tokenizer.inlineText(s)){e=e.substring(r.raw.length),"_"!==r.raw.slice(-1)&&(o=r.raw.slice(-1)),i=!0;const n=t.at(-1);"text"===n?.type?(n.raw+=r.raw,n.text+=r.text):t.push(r)}else if(e){const t="Infinite loop on byte: "+e.charCodeAt(0);if(this.options.silent){console.error(t);break}throw new Error(t)}}return t}}class pe{options;parser;constructor(e){this.options=e||a}space(e){return""}code({text:e,lang:t,escaped:n}){const r=(t||"").match(p.notSpaceStart)?.[0],i=e.replace(p.endingNewline,"")+"\n";return r?'<pre><code class="language-'+ie(r)+'">'+(n?i:ie(i,!0))+"</code></pre>\n":"<pre><code>"+(n?i:ie(i,!0))+"</code></pre>\n"}blockquote({tokens:e}){return`<blockquote>\n${this.parser.parse(e)}</blockquote>\n`}html({text:e}){return e}heading({tokens:e,depth:t}){return`<h${t}>${this.parser.parseInline(e)}</h${t}>\n`}hr(e){return"<hr>\n"}list(e){const t=e.ordered,n=e.start;let r="";for(let t=0;t<e.items.length;t++){const n=e.items[t];r+=this.listitem(n)}const i=t?"ol":"ul";return"<"+i+(t&&1!==n?' start="'+n+'"':"")+">\n"+r+"</"+i+">\n"}listitem(e){let t="";if(e.task){const n=this.checkbox({checked:!!e.checked});e.loose?"paragraph"===e.tokens[0]?.type?(e.tokens[0].text=n+" "+e.tokens[0].text,e.tokens[0].tokens&&e.tokens[0].tokens.length>0&&"text"===e.tokens[0].tokens[0].type&&(e.tokens[0].tokens[0].text=n+" "+ie(e.tokens[0].tokens[0].text),e.tokens[0].tokens[0].escaped=!0)):e.tokens.unshift({type:"text",raw:n+" ",text:n+" ",escaped:!0}):t+=n+" "}return t+=this.parser.parse(e.tokens,!!e.loose),`<li>${t}</li>\n`}checkbox({checked:e}){return"<input "+(e?'checked="" ':"")+'disabled="" type="checkbox">'}paragraph({tokens:e}){return`<p>${this.parser.parseInline(e)}</p>\n`}table(e){let t="",n="";for(let t=0;t<e.header.length;t++)n+=this.tablecell(e.header[t]);t+=this.tablerow({text:n});let r="";for(let t=0;t<e.rows.length;t++){const i=e.rows[t];n="";for(let e=0;e<i.length;e++)n+=this.tablecell(i[e]);r+=this.tablerow({text:n})}return r&&(r=`<tbody>${r}</tbody>`),"<table>\n<thead>\n"+t+"</thead>\n"+r+"</table>\n"}tablerow({text:e}){return`<tr>\n${e}</tr>\n`}tablecell(e){const t=this.parser.parseInline(e.tokens),n=e.header?"th":"td";return(e.align?`<${n} align="${e.align}">`:`<${n}>`)+t+`</${n}>\n`}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>${ie(e,!0)}</code>`}br(e){return"<br>"}del({tokens:e}){return`<del>${this.parser.parseInline(e)}</del>`}link({href:e,title:t,tokens:n}){const r=this.parser.parseInline(n),i=oe(e);if(null===i)return r;let o='<a href="'+(e=i)+'"';return t&&(o+=' title="'+ie(t)+'"'),o+=">"+r+"</a>",o}image({href:e,title:t,text:n,tokens:r}){r&&(n=this.parser.parseInline(r,this.parser.textRenderer));const i=oe(e);if(null===i)return ie(n);let o=`<img src="${e=i}" alt="${n}"`;return t&&(o+=` title="${ie(t)}"`),o+=">",o}text(e){return"tokens"in e&&e.tokens?this.parser.parseInline(e.tokens):"escaped"in e&&e.escaped?e.text:ie(e.text)}}class he{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""}}class de{options;renderer;textRenderer;constructor(e){this.options=e||a,this.options.renderer=this.options.renderer||new pe,this.renderer=this.options.renderer,this.renderer.options=this.options,this.renderer.parser=this,this.textRenderer=new he}static parse(e,t){return new de(t).parse(e)}static parseInline(e,t){return new de(t).parseInline(e)}parse(e,t=!0){let n="";for(let r=0;r<e.length;r++){const i=e[r];if(this.options.extensions?.renderers?.[i.type]){const e=i,t=this.options.extensions.renderers[e.type].call({parser:this},e);if(!1!==t||!["space","hr","heading","code","table","blockquote","list","html","paragraph","text"].includes(e.type)){n+=t||"";continue}}const o=i;switch(o.type){case"space":n+=this.renderer.space(o);continue;case"hr":n+=this.renderer.hr(o);continue;case"heading":n+=this.renderer.heading(o);continue;case"code":n+=this.renderer.code(o);continue;case"table":n+=this.renderer.table(o);continue;case"blockquote":n+=this.renderer.blockquote(o);continue;case"list":n+=this.renderer.list(o);continue;case"html":n+=this.renderer.html(o);continue;case"paragraph":n+=this.renderer.paragraph(o);continue;case"text":{let i=o,s=this.renderer.text(i);for(;r+1<e.length&&"text"===e[r+1].type;)i=e[++r],s+="\n"+this.renderer.text(i);n+=t?this.renderer.paragraph({type:"paragraph",raw:s,text:s,tokens:[{type:"text",raw:s,text:s,escaped:!0}]}):s;continue}default:{const e='Token with "'+o.type+'" type was not found.';if(this.options.silent)return console.error(e),"";throw new Error(e)}}}return n}parseInline(e,t=this.renderer){let n="";for(let r=0;r<e.length;r++){const i=e[r];if(this.options.extensions?.renderers?.[i.type]){const e=this.options.extensions.renderers[i.type].call({parser:this},i);if(!1!==e||!["escape","html","link","image","strong","em","codespan","br","del","text"].includes(i.type)){n+=e||"";continue}}const o=i;switch(o.type){case"escape":case"text":n+=t.text(o);break;case"html":n+=t.html(o);break;case"link":n+=t.link(o);break;case"image":n+=t.image(o);break;case"strong":n+=t.strong(o);break;case"em":n+=t.em(o);break;case"codespan":n+=t.codespan(o);break;case"br":n+=t.br(o);break;case"del":n+=t.del(o);break;default:{const e='Token with "'+o.type+'" type was not found.';if(this.options.silent)return console.error(e),"";throw new Error(e)}}}return n}}class fe{options;block;constructor(e){this.options=e||a}static passThroughHooks=new Set(["preprocess","postprocess","processAllTokens"]);preprocess(e){return e}postprocess(e){return e}processAllTokens(e){return e}provideLexer(){return this.block?ue.lex:ue.lexInline}provideParser(){return this.block?de.parse:de.parseInline}}const ge=new class{defaults={async:!1,breaks:!1,extensions:null,gfm:!0,hooks:null,pedantic:!1,renderer:null,silent:!1,tokenizer:null,walkTokens:null};options=this.setOptions;parse=this.parseMarkdown(!0);parseInline=this.parseMarkdown(!1);Parser=de;Renderer=pe;TextRenderer=he;Lexer=ue;Tokenizer=ce;Hooks=fe;constructor(...e){this.use(...e)}walkTokens(e,t){let n=[];for(const r of e)switch(n=n.concat(t.call(this,r)),r.type){case"table":{const e=r;for(const r of e.header)n=n.concat(this.walkTokens(r.tokens,t));for(const r of e.rows)for(const e of r)n=n.concat(this.walkTokens(e.tokens,t));break}case"list":{const e=r;n=n.concat(this.walkTokens(e.items,t));break}default:{const e=r;this.defaults.extensions?.childTokens?.[e.type]?this.defaults.extensions.childTokens[e.type].forEach((r=>{const i=e[r].flat(1/0);n=n.concat(this.walkTokens(i,t))})):e.tokens&&(n=n.concat(this.walkTokens(e.tokens,t)))}}return n}use(...e){const t=this.defaults.extensions||{renderers:{},childTokens:{}};return e.forEach((e=>{const n={...e};if(n.async=this.defaults.async||n.async||!1,e.extensions&&(e.extensions.forEach((e=>{if(!e.name)throw new Error("extension name required");if("renderer"in e){const n=t.renderers[e.name];t.renderers[e.name]=n?function(...t){let r=e.renderer.apply(this,t);return!1===r&&(r=n.apply(this,t)),r}:e.renderer}if("tokenizer"in e){if(!e.level||"block"!==e.level&&"inline"!==e.level)throw new Error("extension level must be 'block' or 'inline'");const n=t[e.level];n?n.unshift(e.tokenizer):t[e.level]=[e.tokenizer],e.start&&("block"===e.level?t.startBlock?t.startBlock.push(e.start):t.startBlock=[e.start]:"inline"===e.level&&(t.startInline?t.startInline.push(e.start):t.startInline=[e.start]))}"childTokens"in e&&e.childTokens&&(t.childTokens[e.name]=e.childTokens)})),n.extensions=t),e.renderer){const t=this.defaults.renderer||new pe(this.defaults);for(const n in e.renderer){if(!(n in t))throw new Error(`renderer '${n}' does not exist`);if(["options","parser"].includes(n))continue;const r=n,i=e.renderer[r],o=t[r];t[r]=(...e)=>{let n=i.apply(t,e);return!1===n&&(n=o.apply(t,e)),n||""}}n.renderer=t}if(e.tokenizer){const t=this.defaults.tokenizer||new ce(this.defaults);for(const n in e.tokenizer){if(!(n in t))throw new Error(`tokenizer '${n}' does not exist`);if(["options","rules","lexer"].includes(n))continue;const r=n,i=e.tokenizer[r],o=t[r];t[r]=(...e)=>{let n=i.apply(t,e);return!1===n&&(n=o.apply(t,e)),n}}n.tokenizer=t}if(e.hooks){const t=this.defaults.hooks||new fe;for(const n in e.hooks){if(!(n in t))throw new Error(`hook '${n}' does not exist`);if(["options","block"].includes(n))continue;const r=n,i=e.hooks[r],o=t[r];fe.passThroughHooks.has(n)?t[r]=e=>{if(this.defaults.async)return Promise.resolve(i.call(t,e)).then((e=>o.call(t,e)));const n=i.call(t,e);return o.call(t,n)}:t[r]=(...e)=>{let n=i.apply(t,e);return!1===n&&(n=o.apply(t,e)),n}}n.hooks=t}if(e.walkTokens){const t=this.defaults.walkTokens,r=e.walkTokens;n.walkTokens=function(e){let n=[];return n.push(r.call(this,e)),t&&(n=n.concat(t.call(this,e))),n}}this.defaults={...this.defaults,...n}})),this}setOptions(e){return this.defaults={...this.defaults,...e},this}lexer(e,t){return ue.lex(e,t??this.defaults)}parser(e,t){return de.parse(e,t??this.defaults)}parseMarkdown(e){return(t,n)=>{const r={...n},i={...this.defaults,...r},o=this.onError(!!i.silent,!!i.async);if(!0===this.defaults.async&&!1===r.async)return o(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(null==t)return o(new Error("marked(): input parameter is undefined or null"));if("string"!=typeof t)return o(new Error("marked(): input parameter is of type "+Object.prototype.toString.call(t)+", string expected"));i.hooks&&(i.hooks.options=i,i.hooks.block=e);const s=i.hooks?i.hooks.provideLexer():e?ue.lex:ue.lexInline,a=i.hooks?i.hooks.provideParser():e?de.parse:de.parseInline;if(i.async)return Promise.resolve(i.hooks?i.hooks.preprocess(t):t).then((e=>s(e,i))).then((e=>i.hooks?i.hooks.processAllTokens(e):e)).then((e=>i.walkTokens?Promise.all(this.walkTokens(e,i.walkTokens)).then((()=>e)):e)).then((e=>a(e,i))).then((e=>i.hooks?i.hooks.postprocess(e):e)).catch(o);try{i.hooks&&(t=i.hooks.preprocess(t));let e=s(t,i);i.hooks&&(e=i.hooks.processAllTokens(e)),i.walkTokens&&this.walkTokens(e,i.walkTokens);let n=a(e,i);return i.hooks&&(n=i.hooks.postprocess(n)),n}catch(e){return o(e)}}}onError(e,t){return n=>{if(n.message+="\nPlease report this to https://github.com/markedjs/marked.",e){const e="<p>An error occurred:</p><pre>"+ie(n.message+"",!0)+"</pre>";return t?Promise.resolve(e):e}if(t)return Promise.reject(n);throw n}}};function me(e,t){return ge.parse(e,t)}me.options=me.setOptions=function(e){return ge.setOptions(e),me.defaults=ge.defaults,l(me.defaults),me},me.getDefaults=function(){return{async:!1,breaks:!1,extensions:null,gfm:!0,hooks:null,pedantic:!1,renderer:null,silent:!1,tokenizer:null,walkTokens:null}},me.defaults=a,me.use=function(...e){return ge.use(...e),me.defaults=ge.defaults,l(me.defaults),me},me.walkTokens=function(e,t){return ge.walkTokens(e,t)},me.parseInline=ge.parseInline,me.Parser=de,me.parser=de.parse,me.Renderer=pe,me.TextRenderer=he,me.Lexer=ue,me.lexer=ue.lex,me.Tokenizer=ce,me.Hooks=fe,me.parse=me,me.options,me.setOptions,me.use,me.walkTokens,me.parseInline,de.parse,ue.lex;const{entries:ke,setPrototypeOf:be,isFrozen:ye,getPrototypeOf:xe,getOwnPropertyDescriptor:we}=Object;let{freeze:ve,seal:Se,create:Te}=Object,{apply:_e,construct:Ee}="undefined"!=typeof Reflect&&Reflect;ve||(ve=function(e){return e}),Se||(Se=function(e){return e}),_e||(_e=function(e,t,n){return e.apply(t,n)}),Ee||(Ee=function(e,t){return new e(...t)});const Ae=Be(Array.prototype.forEach),Re=Be(Array.prototype.lastIndexOf),Le=Be(Array.prototype.pop),Oe=Be(Array.prototype.push),Ne=Be(Array.prototype.splice),Ce=Be(String.prototype.toLowerCase),ze=Be(String.prototype.toString),Ie=Be(String.prototype.match),Me=Be(String.prototype.replace),Pe=Be(String.prototype.indexOf),$e=Be(String.prototype.trim),De=Be(Object.prototype.hasOwnProperty),He=Be(RegExp.prototype.test),Ue=(je=TypeError,function(){for(var e=arguments.length,t=new Array(e),n=0;n<e;n++)t[n]=arguments[n];return Ee(je,t)});var je;function Be(e){return function(t){t instanceof RegExp&&(t.lastIndex=0);for(var n=arguments.length,r=new Array(n>1?n-1:0),i=1;i<n;i++)r[i-1]=arguments[i];return _e(e,t,r)}}function qe(e,t){let n=arguments.length>2&&void 0!==arguments[2]?arguments[2]:Ce;be&&be(e,null);let r=t.length;for(;r--;){let i=t[r];if("string"==typeof i){const e=n(i);e!==i&&(ye(t)||(t[r]=e),i=e)}e[i]=!0}return e}function Fe(e){for(let t=0;t<e.length;t++)De(e,t)||(e[t]=null);return e}function We(e){const t=Te(null);for(const[n,r]of ke(e))De(e,n)&&(Array.isArray(r)?t[n]=Fe(r):r&&"object"==typeof r&&r.constructor===Object?t[n]=We(r):t[n]=r);return t}function Ge(e,t){for(;null!==e;){const n=we(e,t);if(n){if(n.get)return Be(n.get);if("function"==typeof n.value)return Be(n.value)}e=xe(e)}return function(){return null}}const Ze=ve(["a","abbr","acronym","address","area","article","aside","audio","b","bdi","bdo","big","blink","blockquote","body","br","button","canvas","caption","center","cite","code","col","colgroup","content","data","datalist","dd","decorator","del","details","dfn","dialog","dir","div","dl","dt","element","em","fieldset","figcaption","figure","font","footer","form","h1","h2","h3","h4","h5","h6","head","header","hgroup","hr","html","i","img","input","ins","kbd","label","legend","li","main","map","mark","marquee","menu","menuitem","meter","nav","nobr","ol","optgroup","option","output","p","picture","pre","progress","q","rp","rt","ruby","s","samp","section","select","shadow","small","source","spacer","span","strike","strong","style","sub","summary","sup","table","tbody","td","template","textarea","tfoot","th","thead","time","tr","track","tt","u","ul","var","video","wbr"]),Ye=ve(["svg","a","altglyph","altglyphdef","altglyphitem","animatecolor","animatemotion","animatetransform","circle","clippath","defs","desc","ellipse","filter","font","g","glyph","glyphref","hkern","image","line","lineargradient","marker","mask","metadata","mpath","path","pattern","polygon","polyline","radialgradient","rect","stop","style","switch","symbol","text","textpath","title","tref","tspan","view","vkern"]),Xe=ve(["feBlend","feColorMatrix","feComponentTransfer","feComposite","feConvolveMatrix","feDiffuseLighting","feDisplacementMap","feDistantLight","feDropShadow","feFlood","feFuncA","feFuncB","feFuncG","feFuncR","feGaussianBlur","feImage","feMerge","feMergeNode","feMorphology","feOffset","fePointLight","feSpecularLighting","feSpotLight","feTile","feTurbulence"]),Qe=ve(["animate","color-profile","cursor","discard","font-face","font-face-format","font-face-name","font-face-src","font-face-uri","foreignobject","hatch","hatchpath","mesh","meshgradient","meshpatch","meshrow","missing-glyph","script","set","solidcolor","unknown","use"]),Je=ve(["math","menclose","merror","mfenced","mfrac","mglyph","mi","mlabeledtr","mmultiscripts","mn","mo","mover","mpadded","mphantom","mroot","mrow","ms","mspace","msqrt","mstyle","msub","msup","msubsup","mtable","mtd","mtext","mtr","munder","munderover","mprescripts"]),Ke=ve(["maction","maligngroup","malignmark","mlongdiv","mscarries","mscarry","msgroup","mstack","msline","msrow","semantics","annotation","annotation-xml","mprescripts","none"]),Ve=ve(["#text"]),et=ve(["accept","action","align","alt","autocapitalize","autocomplete","autopictureinpicture","autoplay","background","bgcolor","border","capture","cellpadding","cellspacing","checked","cite","class","clear","color","cols","colspan","controls","controlslist","coords","crossorigin","datetime","decoding","default","dir","disabled","disablepictureinpicture","disableremoteplayback","download","draggable","enctype","enterkeyhint","face","for","headers","height","hidden","high","href","hreflang","id","inputmode","integrity","ismap","kind","label","lang","list","loading","loop","low","max","maxlength","media","method","min","minlength","multiple","muted","name","nonce","noshade","novalidate","nowrap","open","optimum","pattern","placeholder","playsinline","popover","popovertarget","popovertargetaction","poster","preload","pubdate","radiogroup","readonly","rel","required","rev","reversed","role","rows","rowspan","spellcheck","scope","selected","shape","size","sizes","span","srclang","start","src","srcset","step","style","summary","tabindex","title","translate","type","usemap","valign","value","width","wrap","xmlns","slot"]),tt=ve(["accent-height","accumulate","additive","alignment-baseline","amplitude","ascent","attributename","attributetype","azimuth","basefrequency","baseline-shift","begin","bias","by","class","clip","clippathunits","clip-path","clip-rule","color","color-interpolation","color-interpolation-filters","color-profile","color-rendering","cx","cy","d","dx","dy","diffuseconstant","direction","display","divisor","dur","edgemode","elevation","end","exponent","fill","fill-opacity","fill-rule","filter","filterunits","flood-color","flood-opacity","font-family","font-size","font-size-adjust","font-stretch","font-style","font-variant","font-weight","fx","fy","g1","g2","glyph-name","glyphref","gradientunits","gradienttransform","height","href","id","image-rendering","in","in2","intercept","k","k1","k2","k3","k4","kerning","keypoints","keysplines","keytimes","lang","lengthadjust","letter-spacing","kernelmatrix","kernelunitlength","lighting-color","local","marker-end","marker-mid","marker-start","markerheight","markerunits","markerwidth","maskcontentunits","maskunits","max","mask","media","method","mode","min","name","numoctaves","offset","operator","opacity","order","orient","orientation","origin","overflow","paint-order","path","pathlength","patterncontentunits","patterntransform","patternunits","points","preservealpha","preserveaspectratio","primitiveunits","r","rx","ry","radius","refx","refy","repeatcount","repeatdur","restart","result","rotate","scale","seed","shape-rendering","slope","specularconstant","specularexponent","spreadmethod","startoffset","stddeviation","stitchtiles","stop-color","stop-opacity","stroke-dasharray","stroke-dashoffset","stroke-linecap","stroke-linejoin","stroke-miterlimit","stroke-opacity","stroke","stroke-width","style","surfacescale","systemlanguage","tabindex","tablevalues","targetx","targety","transform","transform-origin","text-anchor","text-decoration","text-rendering","textlength","type","u1","u2","unicode","values","viewbox","visibility","version","vert-adv-y","vert-origin-x","vert-origin-y","width","word-spacing","wrap","writing-mode","xchannelselector","ychannelselector","x","x1","x2","xmlns","y","y1","y2","z","zoomandpan"]),nt=ve(["accent","accentunder","align","bevelled","close","columnsalign","columnlines","columnspan","denomalign","depth","dir","display","displaystyle","encoding","fence","frame","height","href","id","largeop","length","linethickness","lspace","lquote","mathbackground","mathcolor","mathsize","mathvariant","maxsize","minsize","movablelimits","notation","numalign","open","rowalign","rowlines","rowspacing","rowspan","rspace","rquote","scriptlevel","scriptminsize","scriptsizemultiplier","selection","separator","separators","stretchy","subscriptshift","supscriptshift","symmetric","voffset","width","xmlns"]),rt=ve(["xlink:href","xml:id","xlink:title","xml:space","xmlns:xlink"]),it=Se(/\{\{[\w\W]*|[\w\W]*\}\}/gm),ot=Se(/<%[\w\W]*|[\w\W]*%>/gm),st=Se(/\$\{[\w\W]*/gm),at=Se(/^data-[\-\w.\u00B7-\uFFFF]+$/),lt=Se(/^aria-[\-\w]+$/),ct=Se(/^(?:(?:(?:f|ht)tps?|mailto|tel|callto|sms|cid|xmpp):|[^a-z]|[a-z+.\-]+(?:[^a-z+.\-:]|$))/i),ut=Se(/^(?:\w+script|data):/i),pt=Se(/[\u0000-\u0020\u00A0\u1680\u180E\u2000-\u2029\u205F\u3000]/g),ht=Se(/^html$/i),dt=Se(/^[a-z][.\w]*(-[.\w]+)+$/i);var ft=Object.freeze({__proto__:null,ARIA_ATTR:lt,ATTR_WHITESPACE:pt,CUSTOM_ELEMENT:dt,DATA_ATTR:at,DOCTYPE_NAME:ht,ERB_EXPR:ot,IS_ALLOWED_URI:ct,IS_SCRIPT_OR_DATA:ut,MUSTACHE_EXPR:it,TMPLIT_EXPR:st});const gt=function(){return"undefined"==typeof window?null:window};var mt=function e(){let t=arguments.length>0&&void 0!==arguments[0]?arguments[0]:gt();const n=t=>e(t);if(n.version="3.2.5",n.removed=[],!t||!t.document||9!==t.document.nodeType||!t.Element)return n.isSupported=!1,n;let{document:r}=t;const i=r,o=i.currentScript,{DocumentFragment:s,HTMLTemplateElement:a,Node:l,Element:c,NodeFilter:u,NamedNodeMap:p=t.NamedNodeMap||t.MozNamedAttrMap,HTMLFormElement:h,DOMParser:d,trustedTypes:f}=t,g=c.prototype,m=Ge(g,"cloneNode"),k=Ge(g,"remove"),b=Ge(g,"nextSibling"),y=Ge(g,"childNodes"),x=Ge(g,"parentNode");if("function"==typeof a){const e=r.createElement("template");e.content&&e.content.ownerDocument&&(r=e.content.ownerDocument)}let w,v="";const{implementation:S,createNodeIterator:T,createDocumentFragment:_,getElementsByTagName:E}=r,{importNode:A}=i;let R={afterSanitizeAttributes:[],afterSanitizeElements:[],afterSanitizeShadowDOM:[],beforeSanitizeAttributes:[],beforeSanitizeElements:[],beforeSanitizeShadowDOM:[],uponSanitizeAttribute:[],uponSanitizeElement:[],uponSanitizeShadowNode:[]};n.isSupported="function"==typeof ke&&"function"==typeof x&&S&&void 0!==S.createHTMLDocument;const{MUSTACHE_EXPR:L,ERB_EXPR:O,TMPLIT_EXPR:N,DATA_ATTR:C,ARIA_ATTR:z,IS_SCRIPT_OR_DATA:I,ATTR_WHITESPACE:M,CUSTOM_ELEMENT:P}=ft;let{IS_ALLOWED_URI:$}=ft,D=null;const H=qe({},[...Ze,...Ye,...Xe,...Je,...Ve]);let U=null;const j=qe({},[...et,...tt,...nt,...rt]);let B=Object.seal(Te(null,{tagNameCheck:{writable:!0,configurable:!1,enumerable:!0,value:null},attributeNameCheck:{writable:!0,configurable:!1,enumerable:!0,value:null},allowCustomizedBuiltInElements:{writable:!0,configurable:!1,enumerable:!0,value:!1}})),q=null,F=null,W=!0,G=!0,Z=!1,Y=!0,X=!1,Q=!0,J=!1,K=!1,V=!1,ee=!1,te=!1,ne=!1,re=!0,ie=!1,oe=!0,se=!1,ae={},le=null;const ce=qe({},["annotation-xml","audio","colgroup","desc","foreignobject","head","iframe","math","mi","mn","mo","ms","mtext","noembed","noframes","noscript","plaintext","script","style","svg","template","thead","title","video","xmp"]);let ue=null;const pe=qe({},["audio","video","img","source","image","track"]);let he=null;const de=qe({},["alt","class","for","id","label","name","pattern","placeholder","role","summary","title","value","style","xmlns"]),fe="http://www.w3.org/1998/Math/MathML",ge="http://www.w3.org/2000/svg",me="http://www.w3.org/1999/xhtml";let be=me,ye=!1,xe=null;const we=qe({},[fe,ge,me],ze);let Se=qe({},["mi","mo","mn","ms","mtext"]),_e=qe({},["annotation-xml"]);const Ee=qe({},["title","style","font","a","script"]);let je=null;const Be=["application/xhtml+xml","text/html"];let Fe=null,it=null;const ot=r.createElement("form"),st=function(e){return e instanceof RegExp||e instanceof Function},at=function(){let e=arguments.length>0&&void 0!==arguments[0]?arguments[0]:{};if(!it||it!==e){if(e&&"object"==typeof e||(e={}),e=We(e),je=-1===Be.indexOf(e.PARSER_MEDIA_TYPE)?"text/html":e.PARSER_MEDIA_TYPE,Fe="application/xhtml+xml"===je?ze:Ce,D=De(e,"ALLOWED_TAGS")?qe({},e.ALLOWED_TAGS,Fe):H,U=De(e,"ALLOWED_ATTR")?qe({},e.ALLOWED_ATTR,Fe):j,xe=De(e,"ALLOWED_NAMESPACES")?qe({},e.ALLOWED_NAMESPACES,ze):we,he=De(e,"ADD_URI_SAFE_ATTR")?qe(We(de),e.ADD_URI_SAFE_ATTR,Fe):de,ue=De(e,"ADD_DATA_URI_TAGS")?qe(We(pe),e.ADD_DATA_URI_TAGS,Fe):pe,le=De(e,"FORBID_CONTENTS")?qe({},e.FORBID_CONTENTS,Fe):ce,q=De(e,"FORBID_TAGS")?qe({},e.FORBID_TAGS,Fe):{},F=De(e,"FORBID_ATTR")?qe({},e.FORBID_ATTR,Fe):{},ae=!!De(e,"USE_PROFILES")&&e.USE_PROFILES,W=!1!==e.ALLOW_ARIA_ATTR,G=!1!==e.ALLOW_DATA_ATTR,Z=e.ALLOW_UNKNOWN_PROTOCOLS||!1,Y=!1!==e.ALLOW_SELF_CLOSE_IN_ATTR,X=e.SAFE_FOR_TEMPLATES||!1,Q=!1!==e.SAFE_FOR_XML,J=e.WHOLE_DOCUMENT||!1,ee=e.RETURN_DOM||!1,te=e.RETURN_DOM_FRAGMENT||!1,ne=e.RETURN_TRUSTED_TYPE||!1,V=e.FORCE_BODY||!1,re=!1!==e.SANITIZE_DOM,ie=e.SANITIZE_NAMED_PROPS||!1,oe=!1!==e.KEEP_CONTENT,se=e.IN_PLACE||!1,$=e.ALLOWED_URI_REGEXP||ct,be=e.NAMESPACE||me,Se=e.MATHML_TEXT_INTEGRATION_POINTS||Se,_e=e.HTML_INTEGRATION_POINTS||_e,B=e.CUSTOM_ELEMENT_HANDLING||{},e.CUSTOM_ELEMENT_HANDLING&&st(e.CUSTOM_ELEMENT_HANDLING.tagNameCheck)&&(B.tagNameCheck=e.CUSTOM_ELEMENT_HANDLING.tagNameCheck),e.CUSTOM_ELEMENT_HANDLING&&st(e.CUSTOM_ELEMENT_HANDLING.attributeNameCheck)&&(B.attributeNameCheck=e.CUSTOM_ELEMENT_HANDLING.attributeNameCheck),e.CUSTOM_ELEMENT_HANDLING&&"boolean"==typeof e.CUSTOM_ELEMENT_HANDLING.allowCustomizedBuiltInElements&&(B.allowCustomizedBuiltInElements=e.CUSTOM_ELEMENT_HANDLING.allowCustomizedBuiltInElements),X&&(G=!1),te&&(ee=!0),ae&&(D=qe({},Ve),U=[],!0===ae.html&&(qe(D,Ze),qe(U,et)),!0===ae.svg&&(qe(D,Ye),qe(U,tt),qe(U,rt)),!0===ae.svgFilters&&(qe(D,Xe),qe(U,tt),qe(U,rt)),!0===ae.mathMl&&(qe(D,Je),qe(U,nt),qe(U,rt))),e.ADD_TAGS&&(D===H&&(D=We(D)),qe(D,e.ADD_TAGS,Fe)),e.ADD_ATTR&&(U===j&&(U=We(U)),qe(U,e.ADD_ATTR,Fe)),e.ADD_URI_SAFE_ATTR&&qe(he,e.ADD_URI_SAFE_ATTR,Fe),e.FORBID_CONTENTS&&(le===ce&&(le=We(le)),qe(le,e.FORBID_CONTENTS,Fe)),oe&&(D["#text"]=!0),J&&qe(D,["html","head","body"]),D.table&&(qe(D,["tbody"]),delete q.tbody),e.TRUSTED_TYPES_POLICY){if("function"!=typeof e.TRUSTED_TYPES_POLICY.createHTML)throw Ue('TRUSTED_TYPES_POLICY configuration option must provide a "createHTML" hook.');if("function"!=typeof e.TRUSTED_TYPES_POLICY.createScriptURL)throw Ue('TRUSTED_TYPES_POLICY configuration option must provide a "createScriptURL" hook.');w=e.TRUSTED_TYPES_POLICY,v=w.createHTML("")}else void 0===w&&(w=function(e,t){if("object"!=typeof e||"function"!=typeof e.createPolicy)return null;let n=null;const r="data-tt-policy-suffix";t&&t.hasAttribute(r)&&(n=t.getAttribute(r));const i="dompurify"+(n?"#"+n:"");try{return e.createPolicy(i,{createHTML:e=>e,createScriptURL:e=>e})}catch(e){return console.warn("TrustedTypes policy "+i+" could not be created."),null}}(f,o)),null!==w&&"string"==typeof v&&(v=w.createHTML(""));ve&&ve(e),it=e}},lt=qe({},[...Ye,...Xe,...Qe]),ut=qe({},[...Je,...Ke]),pt=function(e){Oe(n.removed,{element:e});try{x(e).removeChild(e)}catch(t){k(e)}},dt=function(e,t){try{Oe(n.removed,{attribute:t.getAttributeNode(e),from:t})}catch(e){Oe(n.removed,{attribute:null,from:t})}if(t.removeAttribute(e),"is"===e)if(ee||te)try{pt(t)}catch(e){}else try{t.setAttribute(e,"")}catch(e){}},mt=function(e){let t=null,n=null;if(V)e="<remove></remove>"+e;else{const t=Ie(e,/^[\r\n\t ]+/);n=t&&t[0]}"application/xhtml+xml"===je&&be===me&&(e='<html xmlns="http://www.w3.org/1999/xhtml"><head></head><body>'+e+"</body></html>");const i=w?w.createHTML(e):e;if(be===me)try{t=(new d).parseFromString(i,je)}catch(e){}if(!t||!t.documentElement){t=S.createDocument(be,"template",null);try{t.documentElement.innerHTML=ye?v:i}catch(e){}}const o=t.body||t.documentElement;return e&&n&&o.insertBefore(r.createTextNode(n),o.childNodes[0]||null),be===me?E.call(t,J?"html":"body")[0]:J?t.documentElement:o},kt=function(e){return T.call(e.ownerDocument||e,e,u.SHOW_ELEMENT|u.SHOW_COMMENT|u.SHOW_TEXT|u.SHOW_PROCESSING_INSTRUCTION|u.SHOW_CDATA_SECTION,null)},bt=function(e){return e instanceof h&&("string"!=typeof e.nodeName||"string"!=typeof e.textContent||"function"!=typeof e.removeChild||!(e.attributes instanceof p)||"function"!=typeof e.removeAttribute||"function"!=typeof e.setAttribute||"string"!=typeof e.namespaceURI||"function"!=typeof e.insertBefore||"function"!=typeof e.hasChildNodes)},yt=function(e){return"function"==typeof l&&e instanceof l};function xt(e,t,r){Ae(e,(e=>{e.call(n,t,r,it)}))}const wt=function(e){let t=null;if(xt(R.beforeSanitizeElements,e,null),bt(e))return pt(e),!0;const r=Fe(e.nodeName);if(xt(R.uponSanitizeElement,e,{tagName:r,allowedTags:D}),e.hasChildNodes()&&!yt(e.firstElementChild)&&He(/<[/\w!]/g,e.innerHTML)&&He(/<[/\w!]/g,e.textContent))return pt(e),!0;if(7===e.nodeType)return pt(e),!0;if(Q&&8===e.nodeType&&He(/<[/\w]/g,e.data))return pt(e),!0;if(!D[r]||q[r]){if(!q[r]&&St(r)){if(B.tagNameCheck instanceof RegExp&&He(B.tagNameCheck,r))return!1;if(B.tagNameCheck instanceof Function&&B.tagNameCheck(r))return!1}if(oe&&!le[r]){const t=x(e)||e.parentNode,n=y(e)||e.childNodes;if(n&&t)for(let r=n.length-1;r>=0;--r){const i=m(n[r],!0);i.__removalCount=(e.__removalCount||0)+1,t.insertBefore(i,b(e))}}return pt(e),!0}return e instanceof c&&!function(e){let t=x(e);t&&t.tagName||(t={namespaceURI:be,tagName:"template"});const n=Ce(e.tagName),r=Ce(t.tagName);return!!xe[e.namespaceURI]&&(e.namespaceURI===ge?t.namespaceURI===me?"svg"===n:t.namespaceURI===fe?"svg"===n&&("annotation-xml"===r||Se[r]):Boolean(lt[n]):e.namespaceURI===fe?t.namespaceURI===me?"math"===n:t.namespaceURI===ge?"math"===n&&_e[r]:Boolean(ut[n]):e.namespaceURI===me?!(t.namespaceURI===ge&&!_e[r])&&!(t.namespaceURI===fe&&!Se[r])&&!ut[n]&&(Ee[n]||!lt[n]):!("application/xhtml+xml"!==je||!xe[e.namespaceURI]))}(e)?(pt(e),!0):"noscript"!==r&&"noembed"!==r&&"noframes"!==r||!He(/<\/no(script|embed|frames)/i,e.innerHTML)?(X&&3===e.nodeType&&(t=e.textContent,Ae([L,O,N],(e=>{t=Me(t,e," ")})),e.textContent!==t&&(Oe(n.removed,{element:e.cloneNode()}),e.textContent=t)),xt(R.afterSanitizeElements,e,null),!1):(pt(e),!0)},vt=function(e,t,n){if(re&&("id"===t||"name"===t)&&(n in r||n in ot))return!1;if(G&&!F[t]&&He(C,t));else if(W&&He(z,t));else if(!U[t]||F[t]){if(!(St(e)&&(B.tagNameCheck instanceof RegExp&&He(B.tagNameCheck,e)||B.tagNameCheck instanceof Function&&B.tagNameCheck(e))&&(B.attributeNameCheck instanceof RegExp&&He(B.attributeNameCheck,t)||B.attributeNameCheck instanceof Function&&B.attributeNameCheck(t))||"is"===t&&B.allowCustomizedBuiltInElements&&(B.tagNameCheck instanceof RegExp&&He(B.tagNameCheck,n)||B.tagNameCheck instanceof Function&&B.tagNameCheck(n))))return!1}else if(he[t]);else if(He($,Me(n,M,"")));else if("src"!==t&&"xlink:href"!==t&&"href"!==t||"script"===e||0!==Pe(n,"data:")||!ue[e])if(Z&&!He(I,Me(n,M,"")));else if(n)return!1;return!0},St=function(e){return"annotation-xml"!==e&&Ie(e,P)},Tt=function(e){xt(R.beforeSanitizeAttributes,e,null);const{attributes:t}=e;if(!t||bt(e))return;const r={attrName:"",attrValue:"",keepAttr:!0,allowedAttributes:U,forceKeepAttr:void 0};let i=t.length;for(;i--;){const o=t[i],{name:s,namespaceURI:a,value:l}=o,c=Fe(s);let u="value"===s?l:$e(l);if(r.attrName=c,r.attrValue=u,r.keepAttr=!0,r.forceKeepAttr=void 0,xt(R.uponSanitizeAttribute,e,r),u=r.attrValue,!ie||"id"!==c&&"name"!==c||(dt(s,e),u="user-content-"+u),Q&&He(/((--!?|])>)|<\/(style|title)/i,u)){dt(s,e);continue}if(r.forceKeepAttr)continue;if(dt(s,e),!r.keepAttr)continue;if(!Y&&He(/\/>/i,u)){dt(s,e);continue}X&&Ae([L,O,N],(e=>{u=Me(u,e," ")}));const p=Fe(e.nodeName);if(vt(p,c,u)){if(w&&"object"==typeof f&&"function"==typeof f.getAttributeType)if(a);else switch(f.getAttributeType(p,c)){case"TrustedHTML":u=w.createHTML(u);break;case"TrustedScriptURL":u=w.createScriptURL(u)}try{a?e.setAttributeNS(a,s,u):e.setAttribute(s,u),bt(e)?pt(e):Le(n.removed)}catch(e){}}}xt(R.afterSanitizeAttributes,e,null)},_t=function e(t){let n=null;const r=kt(t);for(xt(R.beforeSanitizeShadowDOM,t,null);n=r.nextNode();)xt(R.uponSanitizeShadowNode,n,null),wt(n),Tt(n),n.content instanceof s&&e(n.content);xt(R.afterSanitizeShadowDOM,t,null)};return n.sanitize=function(e){let t=arguments.length>1&&void 0!==arguments[1]?arguments[1]:{},r=null,o=null,a=null,c=null;if(ye=!e,ye&&(e="\x3c!--\x3e"),"string"!=typeof e&&!yt(e)){if("function"!=typeof e.toString)throw Ue("toString is not a function");if("string"!=typeof(e=e.toString()))throw Ue("dirty is not a string, aborting")}if(!n.isSupported)return e;if(K||at(t),n.removed=[],"string"==typeof e&&(se=!1),se){if(e.nodeName){const t=Fe(e.nodeName);if(!D[t]||q[t])throw Ue("root node is forbidden and cannot be sanitized in-place")}}else if(e instanceof l)r=mt("\x3c!----\x3e"),o=r.ownerDocument.importNode(e,!0),1===o.nodeType&&"BODY"===o.nodeName||"HTML"===o.nodeName?r=o:r.appendChild(o);else{if(!ee&&!X&&!J&&-1===e.indexOf("<"))return w&&ne?w.createHTML(e):e;if(r=mt(e),!r)return ee?null:ne?v:""}r&&V&&pt(r.firstChild);const u=kt(se?e:r);for(;a=u.nextNode();)wt(a),Tt(a),a.content instanceof s&&_t(a.content);if(se)return e;if(ee){if(te)for(c=_.call(r.ownerDocument);r.firstChild;)c.appendChild(r.firstChild);else c=r;return(U.shadowroot||U.shadowrootmode)&&(c=A.call(i,c,!0)),c}let p=J?r.outerHTML:r.innerHTML;return J&&D["!doctype"]&&r.ownerDocument&&r.ownerDocument.doctype&&r.ownerDocument.doctype.name&&He(ht,r.ownerDocument.doctype.name)&&(p="<!DOCTYPE "+r.ownerDocument.doctype.name+">\n"+p),X&&Ae([L,O,N],(e=>{p=Me(p,e," ")})),w&&ne?w.createHTML(p):p},n.setConfig=function(){at(arguments.length>0&&void 0!==arguments[0]?arguments[0]:{}),K=!0},n.clearConfig=function(){it=null,K=!1},n.isValidAttribute=function(e,t,n){it||at({});const r=Fe(e),i=Fe(t);return vt(r,i,n)},n.addHook=function(e,t){"function"==typeof t&&Oe(R[e],t)},n.removeHook=function(e,t){if(void 0!==t){const n=Re(R[e],t);return-1===n?void 0:Ne(R[e],n,1)[0]}return Le(R[e])},n.removeHooks=function(e){R[e]=[]},n.removeAllHooks=function(){R={afterSanitizeAttributes:[],afterSanitizeElements:[],afterSanitizeShadowDOM:[],beforeSanitizeAttributes:[],beforeSanitizeElements:[],beforeSanitizeShadowDOM:[],uponSanitizeAttribute:[],uponSanitizeElement:[],uponSanitizeShadowNode:[]}},n}();function kt(e,t){var n=arguments.length>2&&void 0!==arguments[2]&&arguments[2],r=arguments.length>3?arguments[3]:void 0,i=document.querySelector("#akvo-rag-body");if(i){var o=document.createElement("div"),s="akvo-msg-".concat(e,"-").concat(r);if(o.id=s,o.className="akvo-msg-".concat(e),n)o.innerHTML='\n <div class="typing-indicator">\n <span></span><span></span><span></span>\n </div>\n ';else{var a=me.parse(t||""),l=mt.sanitize(a);o.innerHTML=l}return i.appendChild(o),i.scrollTop=i.scrollHeight,o}}function bt(e){document.querySelectorAll(".citation-popover").forEach((function(e){return e.remove()}));var t=e.target,n=document.createElement("div");n.className="citation-popover",n.innerHTML='\n <div class="arrow"></div>\n <div><strong>'.concat(t.dataset.title,"</strong></div>\n <div><small>Source: ").concat(t.dataset.source,", Page: ").concat(t.dataset.page,"</small></div>\n <p>").concat(t.dataset.text,"</p>\n "),document.body.appendChild(n);var r=n.offsetWidth,i=n.offsetHeight,o=t.getBoundingClientRect(),s=o.left+window.scrollX-r/2+o.width/2,a=window.scrollX+window.innerWidth-r-10,l=window.scrollX+10;s=Math.max(Math.min(s,a),l),o.top;var c=window.innerHeight-o.bottom<i+8+10,u=c?o.top+window.scrollY-i-8-2:o.bottom+window.scrollY+8+2;n.style.left="".concat(s,"px"),n.style.top="".concat(u,"px"),n.dataset.target=t.dataset.id,n.classList.toggle("above",c),n.classList.toggle("below",!c);var p=n.querySelector(".arrow"),h=o.left+o.width/2+window.scrollX-s-8;h=Math.max(8,Math.min(h,r-16)),p.style.left="".concat(h,"px")}function yt(e){var t=e.target;document.querySelectorAll(".citation-popover").forEach((function(e){e.dataset.target===t.dataset.id&&e.remove()}))}function xt(e){return xt="function"==typeof Symbol&&"symbol"==typeof Symbol.iterator?function(e){return typeof e}:function(e){return e&&"function"==typeof Symbol&&e.constructor===Symbol&&e!==Symbol.prototype?"symbol":typeof e},xt(e)}function wt(e,t){var n=Object.keys(e);if(Object.getOwnPropertySymbols){var r=Object.getOwnPropertySymbols(e);t&&(r=r.filter((function(t){return Object.getOwnPropertyDescriptor(e,t).enumerable}))),n.push.apply(n,r)}return n}function vt(e){for(var t=1;t<arguments.length;t++){var n=null!=arguments[t]?arguments[t]:{};t%2?wt(Object(n),!0).forEach((function(t){St(e,t,n[t])})):Object.getOwnPropertyDescriptors?Object.defineProperties(e,Object.getOwnPropertyDescriptors(n)):wt(Object(n)).forEach((function(t){Object.defineProperty(e,t,Object.getOwnPropertyDescriptor(n,t))}))}return e}function St(e,t,n){return(t=_t(t))in e?Object.defineProperty(e,t,{value:n,enumerable:!0,configurable:!0,writable:!0}):e[t]=n,e}function Tt(e,t){for(var n=0;n<t.length;n++){var r=t[n];r.enumerable=r.enumerable||!1,r.configurable=!0,"value"in r&&(r.writable=!0),Object.defineProperty(e,_t(r.key),r)}}function _t(e){var t=function(e){if("object"!=xt(e)||!e)return e;var t=e[Symbol.toPrimitive];if(void 0!==t){var n=t.call(e,"string");if("object"!=xt(n))return n;throw new TypeError("@@toPrimitive must return a primitive value.")}return String(e)}(e);return"symbol"==xt(t)?t:t+""}me.setOptions({gfm:!0,breaks:!0});var Et="Hello! How can I help you today?",At=function(){return e=function e(){var t,n=arguments.length>0&&void 0!==arguments[0]?arguments[0]:{};!function(e,t){if(!(e instanceof t))throw new TypeError("Cannot call a class as a function")}(this,e),this.options=n,this.wsConnection=null,this.currentAssistantMsgEl=null,this.isLoading=!1,this.citations=[],this.messageCounter=0,this.chatHistory=[],this.visitorId=((t=localStorage.getItem("akvo-visitor-id"))||(t=crypto.randomUUID(),localStorage.setItem("akvo-visitor-id",t)),t),this.container=null,this._onMessage=this._onMessage.bind(this),this._handleSend=this._handleSend.bind(this),this._handleStartChat=this._handleStartChat.bind(this),this.init()},t=[{key:"init",value:function(){if(this.container=document.getElementById("akvo-rag"),this.container){this.container.classList.remove("minimized");var e=this.container.querySelector("#akvo-rag-close-btn");e&&(e.innerHTML='<i class="fa fa-window-minimize" aria-hidden="true"></i>')}else this._createUI(),this._bindEvents(),this.options.kb_id&&this._connect()}},{key:"destroy",value:function(){this.wsConnection&&this.wsConnection.close(),this.container&&(this.container.remove(),this.container=null)}},{key:"_createUI",value:function(){var e;this.container=document.createElement("div"),this.container.id="akvo-rag",this.container.innerHTML='\n <div id="akvo-rag-header">\n '.concat(this.options.title||"Chatbot",'\n <button id="akvo-rag-close-btn" class="akvo-rag-close-btn">\n <i class="fa fa-window-minimize" aria-hidden="true"></i>\n </button>\n </div>\n <div id="akvo-rag-body" class="akvo-rag-body">\n ').concat(!this.options.kb_id&&null!==(e=this.options.kb_options)&&void 0!==e&&e.length?'\n <div id="akvo-kb-options" class="akvo-kb-options">\n <p>Please select a knowledge base to continue:</p>\n '.concat(this.options.kb_options.map((function(e){return'\n <div class="kb-option">\n <input type="radio" id="kb-'.concat(e.kb_id,'" name="akvo-kb" value="').concat(e.kb_id,'">\n <label for="kb-').concat(e.kb_id,'">').concat(e.label,"</label>\n </div>\n ")})).join(""),'\n <div class="akvo-kb-options-hint">\n After selecting, click "Start Chat" to begin.\n </div>\n </div>\n '):'<p class="akvo-msg-system">'.concat(Et,"</p>"),'\n </div>\n <div id="akvo-rag-input-container" class="akvo-rag-input-container">\n ').concat(this.options.kb_id?'\n <input\n type="text"\n id="akvo-rag-input"\n placeholder="Type a message..."\n autocomplete="off"\n autocorrect="off"\n autocapitalize="off"\n spellcheck="false"\n />\n <button id="akvo-rag-send-btn">Send</button>\n ':'\n <button id="akvo-start-chat-btn" class="akvo-start-chat-btn" style="flex: 1;" disabled>\n Start Chat\n </button>\n ',"\n </div>\n "),document.body.appendChild(this.container)}},{key:"_bindEvents",value:function(){var e,t=this,n=this.container.querySelector("#akvo-rag-header");if(this.container.querySelector("#akvo-rag-close-btn").addEventListener("click",(function(e){e.stopPropagation(),t.container.classList.toggle("minimized")})),n.addEventListener("click",(function(){t.container.classList.contains("minimized")&&t.container.classList.remove("minimized")})),!this.options.kb_id&&null!==(e=this.options.kb_options)&&void 0!==e&&e.length){var r=this.container.querySelector("#akvo-start-chat-btn");this.container.querySelectorAll("input[name='akvo-kb']").forEach((function(e){e.addEventListener("change",(function(){r.disabled=!1}))})),r.addEventListener("click",this._handleStartChat)}else this._bindInputEvents()}},{key:"_bindInputEvents",value:function(){var e=this,t=this.container.querySelector("#akvo-rag-input"),n=this.container.querySelector("#akvo-rag-send-btn");t&&n&&(t.addEventListener("keypress",(function(t){"Enter"===t.key&&e._handleSend()})),n.addEventListener("click",this._handleSend))}},{key:"_connect",value:function(){var e=this,t={onReconnect:function(t){console.log("Reconnecting attempt #".concat(t,", resetting isLoading")),e.isLoading=!1,e._updateSendButtonState()}};this.wsConnection=function(e,t){var n=arguments.length>2&&void 0!==arguments[2]?arguments[2]:{},r=null,o=0;return function a(){console.log("[WebSocket] Connecting to: ".concat(e.wsURL)),(r=new WebSocket(e.wsURL)).onopen=function(){console.log("[WebSocket] Connected"),o=0,r.send(JSON.stringify({type:"auth",visitor_id:e.visitorId,kb_id:e.kb_id})),e.onOpen&&e.onOpen()},r.onmessage=function(e){var n=null;try{n=JSON.parse(e.data)}catch(t){return void console.warn("[WebSocket] Received non-JSON data",e.data)}if(t){if("ping"===n.type)return r.send(JSON.stringify({type:"pong"})),void console.log("Pong sent to server");if("response_chunk"===n.type&&n.content.includes("__LLM_RESPONSE__"))try{var o,a=function(e,t){return function(e){if(Array.isArray(e))return e}(e)||function(e,t){var n=null==e?null:"undefined"!=typeof Symbol&&e[Symbol.iterator]||e["@@iterator"];if(null!=n){var r,i,o,s,a=[],l=!0,c=!1;try{if(o=(n=n.call(e)).next,0===t){if(Object(n)!==n)return;l=!1}else for(;!(l=(r=o.call(n)).done)&&(a.push(r.value),a.length!==t);l=!0);}catch(e){c=!0,i=e}finally{try{if(!l&&null!=n.return&&(s=n.return(),Object(s)!==s))return}finally{if(c)throw i}}return a}}(e,t)||function(e,t){if(e){if("string"==typeof e)return s(e,t);var n={}.toString.call(e).slice(8,-1);return"Object"===n&&e.constructor&&(n=e.constructor.name),"Map"===n||"Set"===n?Array.from(e):"Arguments"===n||/^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n)?s(e,t):void 0}}(e,t)||function(){throw new TypeError("Invalid attempt to destructure non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.")}()}(n.content.split("__LLM_RESPONSE__"),2),l=a[0],c=a[1],u=function(e){if(!e)return"";var t=e.split(":")[1].trim().replace(/^"|"$/g,"").match(/[A-Za-z0-9+/=]+/);return t?t[0]:""}(l),p=null;if(u)try{var h=atob(u);p=JSON.parse(h)}catch(e){console.warn("Failed to decode or parse base64 contextData",e)}var d=(null===(o=p)||void 0===o||null===(o=o.context)||void 0===o?void 0:o.map((function(e,t){return{id:t+1,text:e.page_content,metadata:e.metadata}})))||[];t(i(i({},n),{},{content:c.trim(),citations:d}))}catch(e){console.error("Failed to parse __LLM_RESPONSE__",e),t(n)}else t(n)}},r.onclose=function(t){if(console.warn("[WebSocket] Closed (URL: ".concat(e.wsURL,"): code=").concat(t.code," reason=").concat(t.reason||"no reason provided")),e.autoReconnect&&1e3!==t.code)if(o<10){o++;var r=Math.min(1e3*Math.pow(2,o-1),3e4),i=1e3*Math.random()-500,s=Math.max(1e3,r+i);console.log("[WebSocket] Reconnect attempt ".concat(o," in ").concat(Math.round(s),"ms")),null!=n&&n.onReconnect&&n.onReconnect(o),setTimeout((function(){a()}),s)}else console.error("[WebSocket] Max reconnect attempts reached."),e.onMaxReconnect&&e.onMaxReconnect()},r.onerror=function(t){console.error("[WebSocket] Error (URL: ".concat(e.wsURL,"):"),t),e.onError&&e.onError(t)}}(),{get socket(){return r},close:function(){e.autoReconnect=!1,r.close(1e3,"Client closed connection")}}}(vt(vt({},this.options),{},{autoReconnect:!0,visitorId:this.visitorId}),this._onMessage,t)}},{key:"_handleStartChat",value:function(){var e=this.container.querySelector("input[name='akvo-kb']:checked");if(e){this.options.kb_id=parseInt(e.value,10);var t=this.container.querySelector("#akvo-kb-options");t&&t.remove(),this.container.querySelector("#akvo-rag-input-container").innerHTML='\n <input\n type="text"\n id="akvo-rag-input"\n placeholder="Type a message..."\n autocomplete="off"\n autocorrect="off"\n autocapitalize="off"\n spellcheck="false"\n />\n <button id="akvo-rag-send-btn">Send</button>\n ',this._connect();var n=this.container.querySelector("#akvo-rag-body"),r=document.createElement("p");r.className="akvo-msg-system",r.textContent=Et,n.appendChild(r),this._bindInputEvents()}}},{key:"_handleSend",value:function(){var e;if(!this.isLoading){var t=this.container.querySelector("#akvo-rag-input"),n=t.value.trim();if(n&&(null===(e=this.wsConnection)||void 0===e||null===(e=e.socket)||void 0===e?void 0:e.readyState)===WebSocket.OPEN){this.chatHistory.push({role:"user",content:n});var r=this.chatHistory.slice(-10);this.wsConnection.socket.send(JSON.stringify({type:"chat",kb_id:this.options.kb_id,messages:r})),kt("user",n),t.value="",this.currentAssistantMsgEl=null,this.isLoading=!0,this._updateSendButtonState()}}}},{key:"_updateSendButtonState",value:function(){var e=this.container.querySelector("#akvo-rag-send-btn");e&&(this.isLoading?(e.disabled=!0,e.innerHTML='<span class="akvo-send-spinner"></span>'):(e.disabled=!1,e.innerHTML="Send"))}},{key:"_onMessage",value:function(e){var t=this;if("info"===e.type)kt("system",e.message);else if("start"===e.type)this.citations=[],this.messageCounter++,this.currentAssistantMsgEl=kt("assistant","",!0,this.messageCounter);else if("response_chunk"===e.type){var n;null!=e&&null!==(n=e.citations)&&void 0!==n&&n.length&&e.citations.forEach((function(e){var n=t.citations.findIndex((function(t){return t.id===e.id}));if(n>-1){var r=t.citations[n],i=e.text&&e.metadata,o=r.text&&r.metadata;!i&&o||(t.citations[n]=e)}else t.citations.push(e)})),function(e,t){var n=document.querySelector("#akvo-rag-body");if(n&&e&&t){t.rawText||(t.rawText="");var r=function(e){var t=arguments.length>1&&void 0!==arguments[1]?arguments[1]:"";if(/^\s*d:\{/.test(e))return t;var n=e;(n=n.replace(/^\d+:\s*/,"")).startsWith('"')&&(n=n.substring(1)),n.endsWith('"')?n=n.substring(0,n.length-1):n.trimEnd().endsWith('"')&&(n=(n=n.trimEnd()).substring(0,n.length-1));try{var r=n.replace(/\\"/g,'"').replace(/"/g,'\\"');n=JSON.parse('"'+r+'"')}catch(e){}return((t||"")+n).replace(/^"\s*/,"")}(e,t.rawText);t.rawText=r;var i=function(e){var t=e;t=(t=(t=(t=(t=(t=(t=(t=(t=t.replace(/\b[A-Za-z0-9](?: [A-Za-z0-9])+\b/g,(function(e){return e.replace(/ /g,"")}))).replace(/\s+([,.:;!?])/g,"$1")).replace(/(\*\*|__)\s*(.*?)\s*(\*\*|__)/g,"$1$2$3")).replace(/` +([^`]+?) +`/g,"`$1`")).replace(/``` *bash/g,"```bash")).replace(/\\\n\s*/g,"")).replace(/\n{3,}/g,"\n\n")).replace(/[ \t]{2,}/g," ")).split("\n").map((function(e){return e.trim()})).join("\n");var n=[],r="";return t.split("\n").forEach((function(e){""===e?r&&(n.push(r.trim()),r=""):r?/[.!?]$/.test(r)?(n.push(r.trim()),r=e):r+=" "+e:r=e})),r&&n.push(r.trim()),n.join("\n\n")}(t.rawText);if(t.lastRenderedText!==i){var o=me.parse(i),s=mt.sanitize(o);t.innerHTML=s,t.lastRenderedText=i,n.scrollTop=n.scrollHeight}}}(e.content,this.currentAssistantMsgEl)}else if("end"===e.type){var r=document.querySelector("#akvo-msg-assistant-".concat(this.messageCounter));r&&(function(e,t){e&&null!=t&&t.length&&requestAnimationFrame((function(){var n=e.innerHTML;t.forEach((function(e){var t=null==e?void 0:e.id;if(null!=t){var r=new RegExp("(\\[|&?#?[a-zA-Z0-9]+;)\\s*citation:\\s*".concat(t,"\\s*(\\]|&?#?[a-zA-Z0-9]+;)"),"gi"),i=((null==e?void 0:e.text)||"").replace(/\s+/g," ").trim().slice(0,200)+"...",o=(null==e?void 0:e.metadata)||{},s=o.source||"Unknown Source",a=o.page_label||o.page||"n/a",l=o.title||o.source||"Untitled Document",c=i.replace(/"/g,"""),u=s.replace(/"/g,"""),p=l.replace(/"/g,"""),h='\n <sup\n class="citation"\n data-id="'.concat(t,'"\n data-text="').concat(c,'"\n data-source="').concat(u,'"\n data-page="').concat(a,'"\n data-title="').concat(p,'"\n >[').concat(t,"]</sup>");n=n.replace(r,h)}})),n=n.replace(/(?:\[|[|[)\s*citation:\s*\d+\s*(?:\]|]|])/gi,""),e.innerHTML=n,e.querySelectorAll(".citation").forEach((function(e){e.style.cursor="pointer",e.addEventListener("mouseenter",bt),e.addEventListener("mouseleave",yt)}))}))}(r,this.citations),null!=r&&r.rawText&&this.chatHistory.push({role:"assistant",content:r.rawText})),this.isLoading=!1,this._updateSendButtonState()}}}],t&&Tt(e.prototype,t),Object.defineProperty(e,"prototype",{writable:!1}),e;var e,t}();function Rt(){return new At(arguments.length>0&&void 0!==arguments[0]?arguments[0]:{})}return"undefined"!=typeof window&&(window.AkvoRAG={initChat:Rt}),t})()));
|
|
1
|
+
/*! For license information please see akvo-rag.js.LICENSE.txt */
|
|
2
|
+
!function(e,t){"object"==typeof exports&&"object"==typeof module?module.exports=t():"function"==typeof define&&define.amd?define([],t):"object"==typeof exports?exports.AkvoRAG=t():e.AkvoRAG=t()}(this,(()=>(()=>{"use strict";var e={d:(t,n)=>{for(var r in n)e.o(n,r)&&!e.o(t,r)&&Object.defineProperty(t,r,{enumerable:!0,get:n[r]})},o:(e,t)=>Object.prototype.hasOwnProperty.call(e,t),r:e=>{"undefined"!=typeof Symbol&&Symbol.toStringTag&&Object.defineProperty(e,Symbol.toStringTag,{value:"Module"}),Object.defineProperty(e,"__esModule",{value:!0})}},t={};e.r(t),e.d(t,{initChat:()=>Lt});const{entries:n,setPrototypeOf:r,isFrozen:i,getPrototypeOf:o,getOwnPropertyDescriptor:s}=Object;let{freeze:a,seal:l,create:c}=Object,{apply:u,construct:p}="undefined"!=typeof Reflect&&Reflect;a||(a=function(e){return e}),l||(l=function(e){return e}),u||(u=function(e,t,n){return e.apply(t,n)}),p||(p=function(e,t){return new e(...t)});const h=A(Array.prototype.forEach),d=A(Array.prototype.lastIndexOf),f=A(Array.prototype.pop),g=A(Array.prototype.push),m=A(Array.prototype.splice),k=A(String.prototype.toLowerCase),b=A(String.prototype.toString),y=A(String.prototype.match),x=A(String.prototype.replace),v=A(String.prototype.indexOf),w=A(String.prototype.trim),S=A(Object.prototype.hasOwnProperty),_=A(RegExp.prototype.test),T=(E=TypeError,function(){for(var e=arguments.length,t=new Array(e),n=0;n<e;n++)t[n]=arguments[n];return p(E,t)});var E;function A(e){return function(t){t instanceof RegExp&&(t.lastIndex=0);for(var n=arguments.length,r=new Array(n>1?n-1:0),i=1;i<n;i++)r[i-1]=arguments[i];return u(e,t,r)}}function R(e,t){let n=arguments.length>2&&void 0!==arguments[2]?arguments[2]:k;r&&r(e,null);let o=t.length;for(;o--;){let r=t[o];if("string"==typeof r){const e=n(r);e!==r&&(i(t)||(t[o]=e),r=e)}e[r]=!0}return e}function L(e){for(let t=0;t<e.length;t++)S(e,t)||(e[t]=null);return e}function C(e){const t=c(null);for(const[r,i]of n(e))S(e,r)&&(Array.isArray(i)?t[r]=L(i):i&&"object"==typeof i&&i.constructor===Object?t[r]=C(i):t[r]=i);return t}function O(e,t){for(;null!==e;){const n=s(e,t);if(n){if(n.get)return A(n.get);if("function"==typeof n.value)return A(n.value)}e=o(e)}return function(){return null}}const z=a(["a","abbr","acronym","address","area","article","aside","audio","b","bdi","bdo","big","blink","blockquote","body","br","button","canvas","caption","center","cite","code","col","colgroup","content","data","datalist","dd","decorator","del","details","dfn","dialog","dir","div","dl","dt","element","em","fieldset","figcaption","figure","font","footer","form","h1","h2","h3","h4","h5","h6","head","header","hgroup","hr","html","i","img","input","ins","kbd","label","legend","li","main","map","mark","marquee","menu","menuitem","meter","nav","nobr","ol","optgroup","option","output","p","picture","pre","progress","q","rp","rt","ruby","s","samp","section","select","shadow","small","source","spacer","span","strike","strong","style","sub","summary","sup","table","tbody","td","template","textarea","tfoot","th","thead","time","tr","track","tt","u","ul","var","video","wbr"]),N=a(["svg","a","altglyph","altglyphdef","altglyphitem","animatecolor","animatemotion","animatetransform","circle","clippath","defs","desc","ellipse","filter","font","g","glyph","glyphref","hkern","image","line","lineargradient","marker","mask","metadata","mpath","path","pattern","polygon","polyline","radialgradient","rect","stop","style","switch","symbol","text","textpath","title","tref","tspan","view","vkern"]),I=a(["feBlend","feColorMatrix","feComponentTransfer","feComposite","feConvolveMatrix","feDiffuseLighting","feDisplacementMap","feDistantLight","feDropShadow","feFlood","feFuncA","feFuncB","feFuncG","feFuncR","feGaussianBlur","feImage","feMerge","feMergeNode","feMorphology","feOffset","fePointLight","feSpecularLighting","feSpotLight","feTile","feTurbulence"]),M=a(["animate","color-profile","cursor","discard","font-face","font-face-format","font-face-name","font-face-src","font-face-uri","foreignobject","hatch","hatchpath","mesh","meshgradient","meshpatch","meshrow","missing-glyph","script","set","solidcolor","unknown","use"]),P=a(["math","menclose","merror","mfenced","mfrac","mglyph","mi","mlabeledtr","mmultiscripts","mn","mo","mover","mpadded","mphantom","mroot","mrow","ms","mspace","msqrt","mstyle","msub","msup","msubsup","mtable","mtd","mtext","mtr","munder","munderover","mprescripts"]),$=a(["maction","maligngroup","malignmark","mlongdiv","mscarries","mscarry","msgroup","mstack","msline","msrow","semantics","annotation","annotation-xml","mprescripts","none"]),D=a(["#text"]),H=a(["accept","action","align","alt","autocapitalize","autocomplete","autopictureinpicture","autoplay","background","bgcolor","border","capture","cellpadding","cellspacing","checked","cite","class","clear","color","cols","colspan","controls","controlslist","coords","crossorigin","datetime","decoding","default","dir","disabled","disablepictureinpicture","disableremoteplayback","download","draggable","enctype","enterkeyhint","face","for","headers","height","hidden","high","href","hreflang","id","inputmode","integrity","ismap","kind","label","lang","list","loading","loop","low","max","maxlength","media","method","min","minlength","multiple","muted","name","nonce","noshade","novalidate","nowrap","open","optimum","pattern","placeholder","playsinline","popover","popovertarget","popovertargetaction","poster","preload","pubdate","radiogroup","readonly","rel","required","rev","reversed","role","rows","rowspan","spellcheck","scope","selected","shape","size","sizes","span","srclang","start","src","srcset","step","style","summary","tabindex","title","translate","type","usemap","valign","value","width","wrap","xmlns","slot"]),U=a(["accent-height","accumulate","additive","alignment-baseline","amplitude","ascent","attributename","attributetype","azimuth","basefrequency","baseline-shift","begin","bias","by","class","clip","clippathunits","clip-path","clip-rule","color","color-interpolation","color-interpolation-filters","color-profile","color-rendering","cx","cy","d","dx","dy","diffuseconstant","direction","display","divisor","dur","edgemode","elevation","end","exponent","fill","fill-opacity","fill-rule","filter","filterunits","flood-color","flood-opacity","font-family","font-size","font-size-adjust","font-stretch","font-style","font-variant","font-weight","fx","fy","g1","g2","glyph-name","glyphref","gradientunits","gradienttransform","height","href","id","image-rendering","in","in2","intercept","k","k1","k2","k3","k4","kerning","keypoints","keysplines","keytimes","lang","lengthadjust","letter-spacing","kernelmatrix","kernelunitlength","lighting-color","local","marker-end","marker-mid","marker-start","markerheight","markerunits","markerwidth","maskcontentunits","maskunits","max","mask","media","method","mode","min","name","numoctaves","offset","operator","opacity","order","orient","orientation","origin","overflow","paint-order","path","pathlength","patterncontentunits","patterntransform","patternunits","points","preservealpha","preserveaspectratio","primitiveunits","r","rx","ry","radius","refx","refy","repeatcount","repeatdur","restart","result","rotate","scale","seed","shape-rendering","slope","specularconstant","specularexponent","spreadmethod","startoffset","stddeviation","stitchtiles","stop-color","stop-opacity","stroke-dasharray","stroke-dashoffset","stroke-linecap","stroke-linejoin","stroke-miterlimit","stroke-opacity","stroke","stroke-width","style","surfacescale","systemlanguage","tabindex","tablevalues","targetx","targety","transform","transform-origin","text-anchor","text-decoration","text-rendering","textlength","type","u1","u2","unicode","values","viewbox","visibility","version","vert-adv-y","vert-origin-x","vert-origin-y","width","word-spacing","wrap","writing-mode","xchannelselector","ychannelselector","x","x1","x2","xmlns","y","y1","y2","z","zoomandpan"]),B=a(["accent","accentunder","align","bevelled","close","columnsalign","columnlines","columnspan","denomalign","depth","dir","display","displaystyle","encoding","fence","frame","height","href","id","largeop","length","linethickness","lspace","lquote","mathbackground","mathcolor","mathsize","mathvariant","maxsize","minsize","movablelimits","notation","numalign","open","rowalign","rowlines","rowspacing","rowspan","rspace","rquote","scriptlevel","scriptminsize","scriptsizemultiplier","selection","separator","separators","stretchy","subscriptshift","supscriptshift","symmetric","voffset","width","xmlns"]),j=a(["xlink:href","xml:id","xlink:title","xml:space","xmlns:xlink"]),q=l(/\{\{[\w\W]*|[\w\W]*\}\}/gm),F=l(/<%[\w\W]*|[\w\W]*%>/gm),W=l(/\$\{[\w\W]*/gm),G=l(/^data-[\-\w.\u00B7-\uFFFF]+$/),Z=l(/^aria-[\-\w]+$/),Y=l(/^(?:(?:(?:f|ht)tps?|mailto|tel|callto|sms|cid|xmpp):|[^a-z]|[a-z+.\-]+(?:[^a-z+.\-:]|$))/i),X=l(/^(?:\w+script|data):/i),Q=l(/[\u0000-\u0020\u00A0\u1680\u180E\u2000-\u2029\u205F\u3000]/g),J=l(/^html$/i),V=l(/^[a-z][.\w]*(-[.\w]+)+$/i);var K=Object.freeze({__proto__:null,ARIA_ATTR:Z,ATTR_WHITESPACE:Q,CUSTOM_ELEMENT:V,DATA_ATTR:G,DOCTYPE_NAME:J,ERB_EXPR:F,IS_ALLOWED_URI:Y,IS_SCRIPT_OR_DATA:X,MUSTACHE_EXPR:q,TMPLIT_EXPR:W});const ee=function(){return"undefined"==typeof window?null:window};var te=function e(){let t=arguments.length>0&&void 0!==arguments[0]?arguments[0]:ee();const r=t=>e(t);if(r.version="3.2.5",r.removed=[],!t||!t.document||9!==t.document.nodeType||!t.Element)return r.isSupported=!1,r;let{document:i}=t;const o=i,s=o.currentScript,{DocumentFragment:l,HTMLTemplateElement:u,Node:p,Element:E,NodeFilter:A,NamedNodeMap:L=t.NamedNodeMap||t.MozNamedAttrMap,HTMLFormElement:q,DOMParser:F,trustedTypes:W}=t,G=E.prototype,Z=O(G,"cloneNode"),X=O(G,"remove"),Q=O(G,"nextSibling"),V=O(G,"childNodes"),te=O(G,"parentNode");if("function"==typeof u){const e=i.createElement("template");e.content&&e.content.ownerDocument&&(i=e.content.ownerDocument)}let ne,re="";const{implementation:ie,createNodeIterator:oe,createDocumentFragment:se,getElementsByTagName:ae}=i,{importNode:le}=o;let ce={afterSanitizeAttributes:[],afterSanitizeElements:[],afterSanitizeShadowDOM:[],beforeSanitizeAttributes:[],beforeSanitizeElements:[],beforeSanitizeShadowDOM:[],uponSanitizeAttribute:[],uponSanitizeElement:[],uponSanitizeShadowNode:[]};r.isSupported="function"==typeof n&&"function"==typeof te&&ie&&void 0!==ie.createHTMLDocument;const{MUSTACHE_EXPR:ue,ERB_EXPR:pe,TMPLIT_EXPR:he,DATA_ATTR:de,ARIA_ATTR:fe,IS_SCRIPT_OR_DATA:ge,ATTR_WHITESPACE:me,CUSTOM_ELEMENT:ke}=K;let{IS_ALLOWED_URI:be}=K,ye=null;const xe=R({},[...z,...N,...I,...P,...D]);let ve=null;const we=R({},[...H,...U,...B,...j]);let Se=Object.seal(c(null,{tagNameCheck:{writable:!0,configurable:!1,enumerable:!0,value:null},attributeNameCheck:{writable:!0,configurable:!1,enumerable:!0,value:null},allowCustomizedBuiltInElements:{writable:!0,configurable:!1,enumerable:!0,value:!1}})),_e=null,Te=null,Ee=!0,Ae=!0,Re=!1,Le=!0,Ce=!1,Oe=!0,ze=!1,Ne=!1,Ie=!1,Me=!1,Pe=!1,$e=!1,De=!0,He=!1,Ue=!0,Be=!1,je={},qe=null;const Fe=R({},["annotation-xml","audio","colgroup","desc","foreignobject","head","iframe","math","mi","mn","mo","ms","mtext","noembed","noframes","noscript","plaintext","script","style","svg","template","thead","title","video","xmp"]);let We=null;const Ge=R({},["audio","video","img","source","image","track"]);let Ze=null;const Ye=R({},["alt","class","for","id","label","name","pattern","placeholder","role","summary","title","value","style","xmlns"]),Xe="http://www.w3.org/1998/Math/MathML",Qe="http://www.w3.org/2000/svg",Je="http://www.w3.org/1999/xhtml";let Ve=Je,Ke=!1,et=null;const tt=R({},[Xe,Qe,Je],b);let nt=R({},["mi","mo","mn","ms","mtext"]),rt=R({},["annotation-xml"]);const it=R({},["title","style","font","a","script"]);let ot=null;const st=["application/xhtml+xml","text/html"];let at=null,lt=null;const ct=i.createElement("form"),ut=function(e){return e instanceof RegExp||e instanceof Function},pt=function(){let e=arguments.length>0&&void 0!==arguments[0]?arguments[0]:{};if(!lt||lt!==e){if(e&&"object"==typeof e||(e={}),e=C(e),ot=-1===st.indexOf(e.PARSER_MEDIA_TYPE)?"text/html":e.PARSER_MEDIA_TYPE,at="application/xhtml+xml"===ot?b:k,ye=S(e,"ALLOWED_TAGS")?R({},e.ALLOWED_TAGS,at):xe,ve=S(e,"ALLOWED_ATTR")?R({},e.ALLOWED_ATTR,at):we,et=S(e,"ALLOWED_NAMESPACES")?R({},e.ALLOWED_NAMESPACES,b):tt,Ze=S(e,"ADD_URI_SAFE_ATTR")?R(C(Ye),e.ADD_URI_SAFE_ATTR,at):Ye,We=S(e,"ADD_DATA_URI_TAGS")?R(C(Ge),e.ADD_DATA_URI_TAGS,at):Ge,qe=S(e,"FORBID_CONTENTS")?R({},e.FORBID_CONTENTS,at):Fe,_e=S(e,"FORBID_TAGS")?R({},e.FORBID_TAGS,at):{},Te=S(e,"FORBID_ATTR")?R({},e.FORBID_ATTR,at):{},je=!!S(e,"USE_PROFILES")&&e.USE_PROFILES,Ee=!1!==e.ALLOW_ARIA_ATTR,Ae=!1!==e.ALLOW_DATA_ATTR,Re=e.ALLOW_UNKNOWN_PROTOCOLS||!1,Le=!1!==e.ALLOW_SELF_CLOSE_IN_ATTR,Ce=e.SAFE_FOR_TEMPLATES||!1,Oe=!1!==e.SAFE_FOR_XML,ze=e.WHOLE_DOCUMENT||!1,Me=e.RETURN_DOM||!1,Pe=e.RETURN_DOM_FRAGMENT||!1,$e=e.RETURN_TRUSTED_TYPE||!1,Ie=e.FORCE_BODY||!1,De=!1!==e.SANITIZE_DOM,He=e.SANITIZE_NAMED_PROPS||!1,Ue=!1!==e.KEEP_CONTENT,Be=e.IN_PLACE||!1,be=e.ALLOWED_URI_REGEXP||Y,Ve=e.NAMESPACE||Je,nt=e.MATHML_TEXT_INTEGRATION_POINTS||nt,rt=e.HTML_INTEGRATION_POINTS||rt,Se=e.CUSTOM_ELEMENT_HANDLING||{},e.CUSTOM_ELEMENT_HANDLING&&ut(e.CUSTOM_ELEMENT_HANDLING.tagNameCheck)&&(Se.tagNameCheck=e.CUSTOM_ELEMENT_HANDLING.tagNameCheck),e.CUSTOM_ELEMENT_HANDLING&&ut(e.CUSTOM_ELEMENT_HANDLING.attributeNameCheck)&&(Se.attributeNameCheck=e.CUSTOM_ELEMENT_HANDLING.attributeNameCheck),e.CUSTOM_ELEMENT_HANDLING&&"boolean"==typeof e.CUSTOM_ELEMENT_HANDLING.allowCustomizedBuiltInElements&&(Se.allowCustomizedBuiltInElements=e.CUSTOM_ELEMENT_HANDLING.allowCustomizedBuiltInElements),Ce&&(Ae=!1),Pe&&(Me=!0),je&&(ye=R({},D),ve=[],!0===je.html&&(R(ye,z),R(ve,H)),!0===je.svg&&(R(ye,N),R(ve,U),R(ve,j)),!0===je.svgFilters&&(R(ye,I),R(ve,U),R(ve,j)),!0===je.mathMl&&(R(ye,P),R(ve,B),R(ve,j))),e.ADD_TAGS&&(ye===xe&&(ye=C(ye)),R(ye,e.ADD_TAGS,at)),e.ADD_ATTR&&(ve===we&&(ve=C(ve)),R(ve,e.ADD_ATTR,at)),e.ADD_URI_SAFE_ATTR&&R(Ze,e.ADD_URI_SAFE_ATTR,at),e.FORBID_CONTENTS&&(qe===Fe&&(qe=C(qe)),R(qe,e.FORBID_CONTENTS,at)),Ue&&(ye["#text"]=!0),ze&&R(ye,["html","head","body"]),ye.table&&(R(ye,["tbody"]),delete _e.tbody),e.TRUSTED_TYPES_POLICY){if("function"!=typeof e.TRUSTED_TYPES_POLICY.createHTML)throw T('TRUSTED_TYPES_POLICY configuration option must provide a "createHTML" hook.');if("function"!=typeof e.TRUSTED_TYPES_POLICY.createScriptURL)throw T('TRUSTED_TYPES_POLICY configuration option must provide a "createScriptURL" hook.');ne=e.TRUSTED_TYPES_POLICY,re=ne.createHTML("")}else void 0===ne&&(ne=function(e,t){if("object"!=typeof e||"function"!=typeof e.createPolicy)return null;let n=null;const r="data-tt-policy-suffix";t&&t.hasAttribute(r)&&(n=t.getAttribute(r));const i="dompurify"+(n?"#"+n:"");try{return e.createPolicy(i,{createHTML:e=>e,createScriptURL:e=>e})}catch(e){return console.warn("TrustedTypes policy "+i+" could not be created."),null}}(W,s)),null!==ne&&"string"==typeof re&&(re=ne.createHTML(""));a&&a(e),lt=e}},ht=R({},[...N,...I,...M]),dt=R({},[...P,...$]),ft=function(e){g(r.removed,{element:e});try{te(e).removeChild(e)}catch(t){X(e)}},gt=function(e,t){try{g(r.removed,{attribute:t.getAttributeNode(e),from:t})}catch(e){g(r.removed,{attribute:null,from:t})}if(t.removeAttribute(e),"is"===e)if(Me||Pe)try{ft(t)}catch(e){}else try{t.setAttribute(e,"")}catch(e){}},mt=function(e){let t=null,n=null;if(Ie)e="<remove></remove>"+e;else{const t=y(e,/^[\r\n\t ]+/);n=t&&t[0]}"application/xhtml+xml"===ot&&Ve===Je&&(e='<html xmlns="http://www.w3.org/1999/xhtml"><head></head><body>'+e+"</body></html>");const r=ne?ne.createHTML(e):e;if(Ve===Je)try{t=(new F).parseFromString(r,ot)}catch(e){}if(!t||!t.documentElement){t=ie.createDocument(Ve,"template",null);try{t.documentElement.innerHTML=Ke?re:r}catch(e){}}const o=t.body||t.documentElement;return e&&n&&o.insertBefore(i.createTextNode(n),o.childNodes[0]||null),Ve===Je?ae.call(t,ze?"html":"body")[0]:ze?t.documentElement:o},kt=function(e){return oe.call(e.ownerDocument||e,e,A.SHOW_ELEMENT|A.SHOW_COMMENT|A.SHOW_TEXT|A.SHOW_PROCESSING_INSTRUCTION|A.SHOW_CDATA_SECTION,null)},bt=function(e){return e instanceof q&&("string"!=typeof e.nodeName||"string"!=typeof e.textContent||"function"!=typeof e.removeChild||!(e.attributes instanceof L)||"function"!=typeof e.removeAttribute||"function"!=typeof e.setAttribute||"string"!=typeof e.namespaceURI||"function"!=typeof e.insertBefore||"function"!=typeof e.hasChildNodes)},yt=function(e){return"function"==typeof p&&e instanceof p};function xt(e,t,n){h(e,(e=>{e.call(r,t,n,lt)}))}const vt=function(e){let t=null;if(xt(ce.beforeSanitizeElements,e,null),bt(e))return ft(e),!0;const n=at(e.nodeName);if(xt(ce.uponSanitizeElement,e,{tagName:n,allowedTags:ye}),e.hasChildNodes()&&!yt(e.firstElementChild)&&_(/<[/\w!]/g,e.innerHTML)&&_(/<[/\w!]/g,e.textContent))return ft(e),!0;if(7===e.nodeType)return ft(e),!0;if(Oe&&8===e.nodeType&&_(/<[/\w]/g,e.data))return ft(e),!0;if(!ye[n]||_e[n]){if(!_e[n]&&St(n)){if(Se.tagNameCheck instanceof RegExp&&_(Se.tagNameCheck,n))return!1;if(Se.tagNameCheck instanceof Function&&Se.tagNameCheck(n))return!1}if(Ue&&!qe[n]){const t=te(e)||e.parentNode,n=V(e)||e.childNodes;if(n&&t)for(let r=n.length-1;r>=0;--r){const i=Z(n[r],!0);i.__removalCount=(e.__removalCount||0)+1,t.insertBefore(i,Q(e))}}return ft(e),!0}return e instanceof E&&!function(e){let t=te(e);t&&t.tagName||(t={namespaceURI:Ve,tagName:"template"});const n=k(e.tagName),r=k(t.tagName);return!!et[e.namespaceURI]&&(e.namespaceURI===Qe?t.namespaceURI===Je?"svg"===n:t.namespaceURI===Xe?"svg"===n&&("annotation-xml"===r||nt[r]):Boolean(ht[n]):e.namespaceURI===Xe?t.namespaceURI===Je?"math"===n:t.namespaceURI===Qe?"math"===n&&rt[r]:Boolean(dt[n]):e.namespaceURI===Je?!(t.namespaceURI===Qe&&!rt[r])&&!(t.namespaceURI===Xe&&!nt[r])&&!dt[n]&&(it[n]||!ht[n]):!("application/xhtml+xml"!==ot||!et[e.namespaceURI]))}(e)?(ft(e),!0):"noscript"!==n&&"noembed"!==n&&"noframes"!==n||!_(/<\/no(script|embed|frames)/i,e.innerHTML)?(Ce&&3===e.nodeType&&(t=e.textContent,h([ue,pe,he],(e=>{t=x(t,e," ")})),e.textContent!==t&&(g(r.removed,{element:e.cloneNode()}),e.textContent=t)),xt(ce.afterSanitizeElements,e,null),!1):(ft(e),!0)},wt=function(e,t,n){if(De&&("id"===t||"name"===t)&&(n in i||n in ct))return!1;if(Ae&&!Te[t]&&_(de,t));else if(Ee&&_(fe,t));else if(!ve[t]||Te[t]){if(!(St(e)&&(Se.tagNameCheck instanceof RegExp&&_(Se.tagNameCheck,e)||Se.tagNameCheck instanceof Function&&Se.tagNameCheck(e))&&(Se.attributeNameCheck instanceof RegExp&&_(Se.attributeNameCheck,t)||Se.attributeNameCheck instanceof Function&&Se.attributeNameCheck(t))||"is"===t&&Se.allowCustomizedBuiltInElements&&(Se.tagNameCheck instanceof RegExp&&_(Se.tagNameCheck,n)||Se.tagNameCheck instanceof Function&&Se.tagNameCheck(n))))return!1}else if(Ze[t]);else if(_(be,x(n,me,"")));else if("src"!==t&&"xlink:href"!==t&&"href"!==t||"script"===e||0!==v(n,"data:")||!We[e])if(Re&&!_(ge,x(n,me,"")));else if(n)return!1;return!0},St=function(e){return"annotation-xml"!==e&&y(e,ke)},_t=function(e){xt(ce.beforeSanitizeAttributes,e,null);const{attributes:t}=e;if(!t||bt(e))return;const n={attrName:"",attrValue:"",keepAttr:!0,allowedAttributes:ve,forceKeepAttr:void 0};let i=t.length;for(;i--;){const o=t[i],{name:s,namespaceURI:a,value:l}=o,c=at(s);let u="value"===s?l:w(l);if(n.attrName=c,n.attrValue=u,n.keepAttr=!0,n.forceKeepAttr=void 0,xt(ce.uponSanitizeAttribute,e,n),u=n.attrValue,!He||"id"!==c&&"name"!==c||(gt(s,e),u="user-content-"+u),Oe&&_(/((--!?|])>)|<\/(style|title)/i,u)){gt(s,e);continue}if(n.forceKeepAttr)continue;if(gt(s,e),!n.keepAttr)continue;if(!Le&&_(/\/>/i,u)){gt(s,e);continue}Ce&&h([ue,pe,he],(e=>{u=x(u,e," ")}));const p=at(e.nodeName);if(wt(p,c,u)){if(ne&&"object"==typeof W&&"function"==typeof W.getAttributeType)if(a);else switch(W.getAttributeType(p,c)){case"TrustedHTML":u=ne.createHTML(u);break;case"TrustedScriptURL":u=ne.createScriptURL(u)}try{a?e.setAttributeNS(a,s,u):e.setAttribute(s,u),bt(e)?ft(e):f(r.removed)}catch(e){}}}xt(ce.afterSanitizeAttributes,e,null)},Tt=function e(t){let n=null;const r=kt(t);for(xt(ce.beforeSanitizeShadowDOM,t,null);n=r.nextNode();)xt(ce.uponSanitizeShadowNode,n,null),vt(n),_t(n),n.content instanceof l&&e(n.content);xt(ce.afterSanitizeShadowDOM,t,null)};return r.sanitize=function(e){let t=arguments.length>1&&void 0!==arguments[1]?arguments[1]:{},n=null,i=null,s=null,a=null;if(Ke=!e,Ke&&(e="\x3c!--\x3e"),"string"!=typeof e&&!yt(e)){if("function"!=typeof e.toString)throw T("toString is not a function");if("string"!=typeof(e=e.toString()))throw T("dirty is not a string, aborting")}if(!r.isSupported)return e;if(Ne||pt(t),r.removed=[],"string"==typeof e&&(Be=!1),Be){if(e.nodeName){const t=at(e.nodeName);if(!ye[t]||_e[t])throw T("root node is forbidden and cannot be sanitized in-place")}}else if(e instanceof p)n=mt("\x3c!----\x3e"),i=n.ownerDocument.importNode(e,!0),1===i.nodeType&&"BODY"===i.nodeName||"HTML"===i.nodeName?n=i:n.appendChild(i);else{if(!Me&&!Ce&&!ze&&-1===e.indexOf("<"))return ne&&$e?ne.createHTML(e):e;if(n=mt(e),!n)return Me?null:$e?re:""}n&&Ie&&ft(n.firstChild);const c=kt(Be?e:n);for(;s=c.nextNode();)vt(s),_t(s),s.content instanceof l&&Tt(s.content);if(Be)return e;if(Me){if(Pe)for(a=se.call(n.ownerDocument);n.firstChild;)a.appendChild(n.firstChild);else a=n;return(ve.shadowroot||ve.shadowrootmode)&&(a=le.call(o,a,!0)),a}let u=ze?n.outerHTML:n.innerHTML;return ze&&ye["!doctype"]&&n.ownerDocument&&n.ownerDocument.doctype&&n.ownerDocument.doctype.name&&_(J,n.ownerDocument.doctype.name)&&(u="<!DOCTYPE "+n.ownerDocument.doctype.name+">\n"+u),Ce&&h([ue,pe,he],(e=>{u=x(u,e," ")})),ne&&$e?ne.createHTML(u):u},r.setConfig=function(){pt(arguments.length>0&&void 0!==arguments[0]?arguments[0]:{}),Ne=!0},r.clearConfig=function(){lt=null,Ne=!1},r.isValidAttribute=function(e,t,n){lt||pt({});const r=at(e),i=at(t);return wt(r,i,n)},r.addHook=function(e,t){"function"==typeof t&&g(ce[e],t)},r.removeHook=function(e,t){if(void 0!==t){const n=d(ce[e],t);return-1===n?void 0:m(ce[e],n,1)[0]}return f(ce[e])},r.removeHooks=function(e){ce[e]=[]},r.removeAllHooks=function(){ce={afterSanitizeAttributes:[],afterSanitizeElements:[],afterSanitizeShadowDOM:[],beforeSanitizeAttributes:[],beforeSanitizeElements:[],beforeSanitizeShadowDOM:[],uponSanitizeAttribute:[],uponSanitizeElement:[],uponSanitizeShadowNode:[]}},r}();function ne(e){return ne="function"==typeof Symbol&&"symbol"==typeof Symbol.iterator?function(e){return typeof e}:function(e){return e&&"function"==typeof Symbol&&e.constructor===Symbol&&e!==Symbol.prototype?"symbol":typeof e},ne(e)}function re(e,t){var n=Object.keys(e);if(Object.getOwnPropertySymbols){var r=Object.getOwnPropertySymbols(e);t&&(r=r.filter((function(t){return Object.getOwnPropertyDescriptor(e,t).enumerable}))),n.push.apply(n,r)}return n}function ie(e){for(var t=1;t<arguments.length;t++){var n=null!=arguments[t]?arguments[t]:{};t%2?re(Object(n),!0).forEach((function(t){oe(e,t,n[t])})):Object.getOwnPropertyDescriptors?Object.defineProperties(e,Object.getOwnPropertyDescriptors(n)):re(Object(n)).forEach((function(t){Object.defineProperty(e,t,Object.getOwnPropertyDescriptor(n,t))}))}return e}function oe(e,t,n){return(t=function(e){var t=function(e){if("object"!=ne(e)||!e)return e;var t=e[Symbol.toPrimitive];if(void 0!==t){var n=t.call(e,"string");if("object"!=ne(n))return n;throw new TypeError("@@toPrimitive must return a primitive value.")}return String(e)}(e);return"symbol"==ne(t)?t:t+""}(t))in e?Object.defineProperty(e,t,{value:n,enumerable:!0,configurable:!0,writable:!0}):e[t]=n,e}function se(e,t){(null==t||t>e.length)&&(t=e.length);for(var n=0,r=Array(t);n<t;n++)r[n]=e[n];return r}let ae={async:!1,breaks:!1,extensions:null,gfm:!0,hooks:null,pedantic:!1,renderer:null,silent:!1,tokenizer:null,walkTokens:null};function le(e){ae=e}const ce={exec:()=>null};function ue(e,t=""){let n="string"==typeof e?e:e.source;const r={replace:(e,t)=>{let i="string"==typeof t?t:t.source;return i=i.replace(pe.caret,"$1"),n=n.replace(e,i),r},getRegex:()=>new RegExp(n,t)};return r}const pe={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,listReplaceTabs:/^\t+/,listReplaceNesting:/^ {1,4}(?=( {4})*[^ ])/g,listIsTask:/^\[[ xX]\] /,listReplaceTask:/^\[[ 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,unescapeTest:/&(#(?:\d+)|(?:#x[0-9A-Fa-f]+)|(?:\w+));?/gi,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})((?:[\t ][^\\n]*)?(?:\\n|$))`),nextBulletRegex:e=>new RegExp(`^ {0,${Math.min(3,e-1)}}(?:[*+-]|\\d{1,9}[.)])((?:[ \t][^\\n]*)?(?:\\n|$))`),hrRegex:e=>new RegExp(`^ {0,${Math.min(3,e-1)}}((?:- *){3,}|(?:_ *){3,}|(?:\\* *){3,})(?:\\n+|$)`),fencesBeginRegex:e=>new RegExp(`^ {0,${Math.min(3,e-1)}}(?:\`\`\`|~~~)`),headingBeginRegex:e=>new RegExp(`^ {0,${Math.min(3,e-1)}}#`),htmlBeginRegex:e=>new RegExp(`^ {0,${Math.min(3,e-1)}}<(?:[a-z].*>|!--)`,"i")},he=/^ {0,3}((?:-[\t ]*){3,}|(?:_[ \t]*){3,}|(?:\*[ \t]*){3,})(?:\n+|$)/,de=/(?:[*+-]|\d{1,9}[.)])/,fe=/^(?!bull |blockCode|fences|blockquote|heading|html|table)((?:.|\n(?!\s*?\n|bull |blockCode|fences|blockquote|heading|html|table))+?)\n {0,3}(=+|-+) *(?:\n+|$)/,ge=ue(fe).replace(/bull/g,de).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(),me=ue(fe).replace(/bull/g,de).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(),ke=/^([^\n]+(?:\n(?!hr|heading|lheading|blockquote|fences|list|html|table| +\n)[^\n]+)*)/,be=/(?!\s*\])(?:\\.|[^\[\]\\])+/,ye=ue(/^ {0,3}\[(label)\]: *(?:\n[ \t]*)?([^<\s][^\s]*|<.*?>)(?:(?: +(?:\n[ \t]*)?| *\n[ \t]*)(title))? *(?:\n+|$)/).replace("label",be).replace("title",/(?:"(?:\\"?|[^"\\])*"|'[^'\n]*(?:\n[^'\n]+)*\n?'|\([^()]*\))/).getRegex(),xe=ue(/^( {0,3}bull)([ \t][^\n]+?)?(?:\n|$)/).replace(/bull/g,de).getRegex(),ve="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",we=/<!--(?:-?>|[\s\S]*?(?:-->|$))/,Se=ue("^ {0,3}(?:<(script|pre|style|textarea)[\\s>][\\s\\S]*?(?:</\\1>[^\\n]*\\n+|$)|comment[^\\n]*(\\n+|$)|<\\?[\\s\\S]*?(?:\\?>\\n*|$)|<![A-Z][\\s\\S]*?(?:>\\n*|$)|<!\\[CDATA\\[[\\s\\S]*?(?:\\]\\]>\\n*|$)|</?(tag)(?: +|\\n|/?>)[\\s\\S]*?(?:(?:\\n[ \t]*)+\\n|$)|<(?!script|pre|style|textarea)([a-z][\\w-]*)(?:attribute)*? */?>(?=[ \\t]*(?:\\n|$))[\\s\\S]*?(?:(?:\\n[ \t]*)+\\n|$)|</(?!script|pre|style|textarea)[a-z][\\w-]*\\s*>(?=[ \\t]*(?:\\n|$))[\\s\\S]*?(?:(?:\\n[ \t]*)+\\n|$))","i").replace("comment",we).replace("tag",ve).replace("attribute",/ +[a-zA-Z:_][\w.:-]*(?: *= *"[^"\n]*"| *= *'[^'\n]*'| *= *[^\s"'=<>`]+)?/).getRegex(),_e=ue(ke).replace("hr",he).replace("heading"," {0,3}#{1,6}(?:\\s|$)").replace("|lheading","").replace("|table","").replace("blockquote"," {0,3}>").replace("fences"," {0,3}(?:`{3,}(?=[^`\\n]*\\n)|~{3,})[^\\n]*\\n").replace("list"," {0,3}(?:[*+-]|1[.)]) ").replace("html","</?(?:tag)(?: +|\\n|/?>)|<(?:script|pre|style|textarea|!--)").replace("tag",ve).getRegex(),Te={blockquote:ue(/^( {0,3}> ?(paragraph|[^\n]*)(?:\n|$))+/).replace("paragraph",_e).getRegex(),code:/^((?: {4}| {0,3}\t)[^\n]+(?:\n(?:[ \t]*(?:\n|$))*)?)+/,def:ye,fences:/^ {0,3}(`{3,}(?=[^`\n]*(?:\n|$))|~{3,})([^\n]*)(?:\n|$)(?:|([\s\S]*?)(?:\n|$))(?: {0,3}\1[~`]* *(?=\n|$)|$)/,heading:/^ {0,3}(#{1,6})(?=\s|$)(.*)(?:\n+|$)/,hr:he,html:Se,lheading:ge,list:xe,newline:/^(?:[ \t]*(?:\n|$))+/,paragraph:_e,table:ce,text:/^[^\n]+/},Ee=ue("^ *([^\\n ].*)\\n {0,3}((?:\\| *)?:?-+:? *(?:\\| *:?-+:? *)*(?:\\| *)?)(?:\\n((?:(?! *\\n|hr|heading|blockquote|code|fences|list|html).*(?:\\n|$))*)\\n*|$)").replace("hr",he).replace("heading"," {0,3}#{1,6}(?:\\s|$)").replace("blockquote"," {0,3}>").replace("code","(?: {4}| {0,3}\t)[^\\n]").replace("fences"," {0,3}(?:`{3,}(?=[^`\\n]*\\n)|~{3,})[^\\n]*\\n").replace("list"," {0,3}(?:[*+-]|1[.)]) ").replace("html","</?(?:tag)(?: +|\\n|/?>)|<(?:script|pre|style|textarea|!--)").replace("tag",ve).getRegex(),Ae={...Te,lheading:me,table:Ee,paragraph:ue(ke).replace("hr",he).replace("heading"," {0,3}#{1,6}(?:\\s|$)").replace("|lheading","").replace("table",Ee).replace("blockquote"," {0,3}>").replace("fences"," {0,3}(?:`{3,}(?=[^`\\n]*\\n)|~{3,})[^\\n]*\\n").replace("list"," {0,3}(?:[*+-]|1[.)]) ").replace("html","</?(?:tag)(?: +|\\n|/?>)|<(?:script|pre|style|textarea|!--)").replace("tag",ve).getRegex()},Re={...Te,html:ue("^ *(?:comment *(?:\\n|\\s*$)|<(tag)[\\s\\S]+?</\\1> *(?:\\n{2,}|\\s*$)|<tag(?:\"[^\"]*\"|'[^']*'|\\s[^'\"/>\\s]*)*?/?> *(?:\\n{2,}|\\s*$))").replace("comment",we).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:ce,lheading:/^(.+?)\n {0,3}(=+|-+) *(?:\n+|$)/,paragraph:ue(ke).replace("hr",he).replace("heading"," *#{1,6} *[^\n]").replace("lheading",ge).replace("|table","").replace("blockquote"," {0,3}>").replace("|fences","").replace("|list","").replace("|html","").replace("|tag","").getRegex()},Le=/^( {2,}|\\)\n(?!\s*$)/,Ce=/[\p{P}\p{S}]/u,Oe=/[\s\p{P}\p{S}]/u,ze=/[^\s\p{P}\p{S}]/u,Ne=ue(/^((?![*_])punctSpace)/,"u").replace(/punctSpace/g,Oe).getRegex(),Ie=/(?!~)[\p{P}\p{S}]/u,Me=/^(?:\*+(?:((?!\*)punct)|[^\s*]))|^_+(?:((?!_)punct)|([^\s_]))/,Pe=ue(Me,"u").replace(/punct/g,Ce).getRegex(),$e=ue(Me,"u").replace(/punct/g,Ie).getRegex(),De="^[^_*]*?__[^_*]*?\\*[^_*]*?(?=__)|[^*]+(?=[^*])|(?!\\*)punct(\\*+)(?=[\\s]|$)|notPunctSpace(\\*+)(?!\\*)(?=punctSpace|$)|(?!\\*)punctSpace(\\*+)(?=notPunctSpace)|[\\s](\\*+)(?!\\*)(?=punct)|(?!\\*)punct(\\*+)(?!\\*)(?=punct)|notPunctSpace(\\*+)(?=notPunctSpace)",He=ue(De,"gu").replace(/notPunctSpace/g,ze).replace(/punctSpace/g,Oe).replace(/punct/g,Ce).getRegex(),Ue=ue(De,"gu").replace(/notPunctSpace/g,/(?:[^\s\p{P}\p{S}]|~)/u).replace(/punctSpace/g,/(?!~)[\s\p{P}\p{S}]/u).replace(/punct/g,Ie).getRegex(),Be=ue("^[^_*]*?\\*\\*[^_*]*?_[^_*]*?(?=\\*\\*)|[^_]+(?=[^_])|(?!_)punct(_+)(?=[\\s]|$)|notPunctSpace(_+)(?!_)(?=punctSpace|$)|(?!_)punctSpace(_+)(?=notPunctSpace)|[\\s](_+)(?!_)(?=punct)|(?!_)punct(_+)(?!_)(?=punct)","gu").replace(/notPunctSpace/g,ze).replace(/punctSpace/g,Oe).replace(/punct/g,Ce).getRegex(),je=ue(/\\(punct)/,"gu").replace(/punct/g,Ce).getRegex(),qe=ue(/^<(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(),Fe=ue(we).replace("(?:--\x3e|$)","--\x3e").getRegex(),We=ue("^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",Fe).replace("attribute",/\s+[a-zA-Z:_][\w.:-]*(?:\s*=\s*"[^"]*"|\s*=\s*'[^']*'|\s*=\s*[^\s"'=<>`]+)?/).getRegex(),Ge=/(?:\[(?:\\.|[^\[\]\\])*\]|\\.|`[^`]*`|[^\[\]\\`])*?/,Ze=ue(/^!?\[(label)\]\(\s*(href)(?:(?:[ \t]*(?:\n[ \t]*)?)(title))?\s*\)/).replace("label",Ge).replace("href",/<(?:\\.|[^\n<>\\])+>|[^ \t\n\x00-\x1f]*/).replace("title",/"(?:\\"?|[^"\\])*"|'(?:\\'?|[^'\\])*'|\((?:\\\)?|[^)\\])*\)/).getRegex(),Ye=ue(/^!?\[(label)\]\[(ref)\]/).replace("label",Ge).replace("ref",be).getRegex(),Xe=ue(/^!?\[(ref)\](?:\[\])?/).replace("ref",be).getRegex(),Qe={_backpedal:ce,anyPunctuation:je,autolink:qe,blockSkip:/\[[^[\]]*?\]\((?:\\.|[^\\\(\)]|\((?:\\.|[^\\\(\)])*\))*\)|`[^`]*?`|<[^<>]*?>/g,br:Le,code:/^(`+)([^`]|[^`][\s\S]*?[^`])\1(?!`)/,del:ce,emStrongLDelim:Pe,emStrongRDelimAst:He,emStrongRDelimUnd:Be,escape:/^\\([!"#$%&'()*+,\-./:;<=>?@\[\]\\^_`{|}~])/,link:Ze,nolink:Xe,punctuation:Ne,reflink:Ye,reflinkSearch:ue("reflink|nolink(?!\\()","g").replace("reflink",Ye).replace("nolink",Xe).getRegex(),tag:We,text:/^(`+|[^`])(?:(?= {2,}\n)|[\s\S]*?(?:(?=[\\<!\[`*_]|\b_|$)|[^ ](?= {2,}\n)))/,url:ce},Je={...Qe,link:ue(/^!?\[(label)\]\((.*?)\)/).replace("label",Ge).getRegex(),reflink:ue(/^!?\[(label)\]\s*\[([^\]]*)\]/).replace("label",Ge).getRegex()},Ve={...Qe,emStrongRDelimAst:Ue,emStrongLDelim:$e,url:ue(/^((?:ftp|https?):\/\/|www\.)(?:[a-zA-Z0-9\-]+\.?)+[^\s<]*|^email/,"i").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~\\]))\1(?=[^~]|$)/,text:/^([`~]+|[^`~])(?:(?= {2,}\n)|(?=[a-zA-Z0-9.!#$%&'*+\/=?_`{\|}~-]+@)|[\s\S]*?(?:(?=[\\<!\[`*~_]|\b_|https?:\/\/|ftp:\/\/|www\.|$)|[^ ](?= {2,}\n)|[^a-zA-Z0-9.!#$%&'*+\/=?_`{\|}~-](?=[a-zA-Z0-9.!#$%&'*+\/=?_`{\|}~-]+@)))/},Ke={...Ve,br:ue(Le).replace("{2,}","*").getRegex(),text:ue(Ve.text).replace("\\b_","\\b_| {2,}\\n").replace(/\{2,\}/g,"*").getRegex()},et={normal:Te,gfm:Ae,pedantic:Re},tt={normal:Qe,gfm:Ve,breaks:Ke,pedantic:Je},nt={"&":"&","<":"<",">":">",'"':""","'":"'"},rt=e=>nt[e];function it(e,t){if(t){if(pe.escapeTest.test(e))return e.replace(pe.escapeReplace,rt)}else if(pe.escapeTestNoEncode.test(e))return e.replace(pe.escapeReplaceNoEncode,rt);return e}function ot(e){try{e=encodeURI(e).replace(pe.percentDecode,"%")}catch{return null}return e}function st(e,t){const n=e.replace(pe.findPipe,((e,t,n)=>{let r=!1,i=t;for(;--i>=0&&"\\"===n[i];)r=!r;return r?"|":" |"})).split(pe.splitPipe);let r=0;if(n[0].trim()||n.shift(),n.length>0&&!n.at(-1)?.trim()&&n.pop(),t)if(n.length>t)n.splice(t);else for(;n.length<t;)n.push("");for(;r<n.length;r++)n[r]=n[r].trim().replace(pe.slashPipe,"|");return n}function at(e,t,n){const r=e.length;if(0===r)return"";let i=0;for(;i<r&&e.charAt(r-i-1)===t;)i++;return e.slice(0,r-i)}function lt(e,t,n,r,i){const o=t.href,s=t.title||null,a=e[1].replace(i.other.outputLinkReplace,"$1");r.state.inLink=!0;const l={type:"!"===e[0].charAt(0)?"image":"link",raw:n,href:o,title:s,text:a,tokens:r.inlineTokens(a)};return r.state.inLink=!1,l}class ct{options;rules;lexer;constructor(e){this.options=e||ae}space(e){const t=this.rules.block.newline.exec(e);if(t&&t[0].length>0)return{type:"space",raw:t[0]}}code(e){const t=this.rules.block.code.exec(e);if(t){const e=t[0].replace(this.rules.other.codeRemoveIndent,"");return{type:"code",raw:t[0],codeBlockStyle:"indented",text:this.options.pedantic?e:at(e,"\n")}}}fences(e){const t=this.rules.block.fences.exec(e);if(t){const e=t[0],n=function(e,t,n){const r=e.match(n.other.indentCodeCompensation);if(null===r)return t;const i=r[1];return t.split("\n").map((e=>{const t=e.match(n.other.beginningSpace);if(null===t)return e;const[r]=t;return r.length>=i.length?e.slice(i.length):e})).join("\n")}(e,t[3]||"",this.rules);return{type:"code",raw:e,lang:t[2]?t[2].trim().replace(this.rules.inline.anyPunctuation,"$1"):t[2],text:n}}}heading(e){const t=this.rules.block.heading.exec(e);if(t){let e=t[2].trim();if(this.rules.other.endingHash.test(e)){const t=at(e,"#");this.options.pedantic?e=t.trim():t&&!this.rules.other.endingSpaceChar.test(t)||(e=t.trim())}return{type:"heading",raw:t[0],depth:t[1].length,text:e,tokens:this.lexer.inline(e)}}}hr(e){const t=this.rules.block.hr.exec(e);if(t)return{type:"hr",raw:at(t[0],"\n")}}blockquote(e){const t=this.rules.block.blockquote.exec(e);if(t){let e=at(t[0],"\n").split("\n"),n="",r="";const i=[];for(;e.length>0;){let t=!1;const o=[];let s;for(s=0;s<e.length;s++)if(this.rules.other.blockquoteStart.test(e[s]))o.push(e[s]),t=!0;else{if(t)break;o.push(e[s])}e=e.slice(s);const a=o.join("\n"),l=a.replace(this.rules.other.blockquoteSetextReplace,"\n $1").replace(this.rules.other.blockquoteSetextReplace2,"");n=n?`${n}\n${a}`:a,r=r?`${r}\n${l}`:l;const c=this.lexer.state.top;if(this.lexer.state.top=!0,this.lexer.blockTokens(l,i,!0),this.lexer.state.top=c,0===e.length)break;const u=i.at(-1);if("code"===u?.type)break;if("blockquote"===u?.type){const t=u,o=t.raw+"\n"+e.join("\n"),s=this.blockquote(o);i[i.length-1]=s,n=n.substring(0,n.length-t.raw.length)+s.raw,r=r.substring(0,r.length-t.text.length)+s.text;break}if("list"!==u?.type);else{const t=u,o=t.raw+"\n"+e.join("\n"),s=this.list(o);i[i.length-1]=s,n=n.substring(0,n.length-u.raw.length)+s.raw,r=r.substring(0,r.length-t.raw.length)+s.raw,e=o.substring(i.at(-1).raw.length).split("\n")}}return{type:"blockquote",raw:n,tokens:i,text:r}}}list(e){let t=this.rules.block.list.exec(e);if(t){let n=t[1].trim();const r=n.length>1,i={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:"[*+-]");const o=this.rules.other.listItemRegex(n);let s=!1;for(;e;){let n=!1,r="",a="";if(!(t=o.exec(e)))break;if(this.rules.block.hr.test(e))break;r=t[0],e=e.substring(r.length);let l=t[2].split("\n",1)[0].replace(this.rules.other.listReplaceTabs,(e=>" ".repeat(3*e.length))),c=e.split("\n",1)[0],u=!l.trim(),p=0;if(this.options.pedantic?(p=2,a=l.trimStart()):u?p=t[1].length+1:(p=t[2].search(this.rules.other.nonSpaceChar),p=p>4?1:p,a=l.slice(p),p+=t[1].length),u&&this.rules.other.blankLine.test(c)&&(r+=c+"\n",e=e.substring(c.length+1),n=!0),!n){const t=this.rules.other.nextBulletRegex(p),n=this.rules.other.hrRegex(p),i=this.rules.other.fencesBeginRegex(p),o=this.rules.other.headingBeginRegex(p),s=this.rules.other.htmlBeginRegex(p);for(;e;){const h=e.split("\n",1)[0];let d;if(c=h,this.options.pedantic?(c=c.replace(this.rules.other.listReplaceNesting," "),d=c):d=c.replace(this.rules.other.tabCharGlobal," "),i.test(c))break;if(o.test(c))break;if(s.test(c))break;if(t.test(c))break;if(n.test(c))break;if(d.search(this.rules.other.nonSpaceChar)>=p||!c.trim())a+="\n"+d.slice(p);else{if(u)break;if(l.replace(this.rules.other.tabCharGlobal," ").search(this.rules.other.nonSpaceChar)>=4)break;if(i.test(l))break;if(o.test(l))break;if(n.test(l))break;a+="\n"+c}u||c.trim()||(u=!0),r+=h+"\n",e=e.substring(h.length+1),l=d.slice(p)}}i.loose||(s?i.loose=!0:this.rules.other.doubleBlankLine.test(r)&&(s=!0));let h,d=null;this.options.gfm&&(d=this.rules.other.listIsTask.exec(a),d&&(h="[ ] "!==d[0],a=a.replace(this.rules.other.listReplaceTask,""))),i.items.push({type:"list_item",raw:r,task:!!d,checked:h,loose:!1,text:a,tokens:[]}),i.raw+=r}const a=i.items.at(-1);if(!a)return;a.raw=a.raw.trimEnd(),a.text=a.text.trimEnd(),i.raw=i.raw.trimEnd();for(let e=0;e<i.items.length;e++)if(this.lexer.state.top=!1,i.items[e].tokens=this.lexer.blockTokens(i.items[e].text,[]),!i.loose){const t=i.items[e].tokens.filter((e=>"space"===e.type)),n=t.length>0&&t.some((e=>this.rules.other.anyLine.test(e.raw)));i.loose=n}if(i.loose)for(let e=0;e<i.items.length;e++)i.items[e].loose=!0;return i}}html(e){const t=this.rules.block.html.exec(e);if(t)return{type:"html",block:!0,raw:t[0],pre:"pre"===t[1]||"script"===t[1]||"style"===t[1],text:t[0]}}def(e){const t=this.rules.block.def.exec(e);if(t){const e=t[1].toLowerCase().replace(this.rules.other.multipleSpaceGlobal," "),n=t[2]?t[2].replace(this.rules.other.hrefBrackets,"$1").replace(this.rules.inline.anyPunctuation,"$1"):"",r=t[3]?t[3].substring(1,t[3].length-1).replace(this.rules.inline.anyPunctuation,"$1"):t[3];return{type:"def",tag:e,raw:t[0],href:n,title:r}}}table(e){const t=this.rules.block.table.exec(e);if(!t)return;if(!this.rules.other.tableDelimiter.test(t[2]))return;const n=st(t[1]),r=t[2].replace(this.rules.other.tableAlignChars,"").split("|"),i=t[3]?.trim()?t[3].replace(this.rules.other.tableRowBlankLine,"").split("\n"):[],o={type:"table",raw:t[0],header:[],align:[],rows:[]};if(n.length===r.length){for(const e of r)this.rules.other.tableAlignRight.test(e)?o.align.push("right"):this.rules.other.tableAlignCenter.test(e)?o.align.push("center"):this.rules.other.tableAlignLeft.test(e)?o.align.push("left"):o.align.push(null);for(let e=0;e<n.length;e++)o.header.push({text:n[e],tokens:this.lexer.inline(n[e]),header:!0,align:o.align[e]});for(const e of i)o.rows.push(st(e,o.header.length).map(((e,t)=>({text:e,tokens:this.lexer.inline(e),header:!1,align:o.align[t]}))));return o}}lheading(e){const t=this.rules.block.lheading.exec(e);if(t)return{type:"heading",raw:t[0],depth:"="===t[2].charAt(0)?1:2,text:t[1],tokens:this.lexer.inline(t[1])}}paragraph(e){const t=this.rules.block.paragraph.exec(e);if(t){const e="\n"===t[1].charAt(t[1].length-1)?t[1].slice(0,-1):t[1];return{type:"paragraph",raw:t[0],text:e,tokens:this.lexer.inline(e)}}}text(e){const 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){const t=this.rules.inline.escape.exec(e);if(t)return{type:"escape",raw:t[0],text:t[1]}}tag(e){const 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){const t=this.rules.inline.link.exec(e);if(t){const e=t[2].trim();if(!this.options.pedantic&&this.rules.other.startAngleBracket.test(e)){if(!this.rules.other.endAngleBracket.test(e))return;const t=at(e.slice(0,-1),"\\");if((e.length-t.length)%2==0)return}else{const e=function(e,t){if(-1===e.indexOf(t[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}(t[2],"()");if(-2===e)return;if(e>-1){const n=(0===t[0].indexOf("!")?5:4)+t[1].length+e;t[2]=t[2].substring(0,e),t[0]=t[0].substring(0,n).trim(),t[3]=""}}let n=t[2],r="";if(this.options.pedantic){const e=this.rules.other.pedanticHrefTitle.exec(n);e&&(n=e[1],r=e[3])}else r=t[3]?t[3].slice(1,-1):"";return n=n.trim(),this.rules.other.startAngleBracket.test(n)&&(n=this.options.pedantic&&!this.rules.other.endAngleBracket.test(e)?n.slice(1):n.slice(1,-1)),lt(t,{href:n?n.replace(this.rules.inline.anyPunctuation,"$1"):n,title:r?r.replace(this.rules.inline.anyPunctuation,"$1"):r},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))){const e=t[(n[2]||n[1]).replace(this.rules.other.multipleSpaceGlobal," ").toLowerCase()];if(!e){const e=n[0].charAt(0);return{type:"text",raw:e,text:e}}return lt(n,e,n[0],this.lexer,this.rules)}}emStrong(e,t,n=""){let r=this.rules.inline.emStrongLDelim.exec(e);if(r&&(!r[3]||!n.match(this.rules.other.unicodeAlphaNumeric))&&(!r[1]&&!r[2]||!n||this.rules.inline.punctuation.exec(n))){const n=[...r[0]].length-1;let i,o,s=n,a=0;const l="*"===r[0][0]?this.rules.inline.emStrongRDelimAst:this.rules.inline.emStrongRDelimUnd;for(l.lastIndex=0,t=t.slice(-1*e.length+n);null!=(r=l.exec(t));){if(i=r[1]||r[2]||r[3]||r[4]||r[5]||r[6],!i)continue;if(o=[...i].length,r[3]||r[4]){s+=o;continue}if((r[5]||r[6])&&n%3&&!((n+o)%3)){a+=o;continue}if(s-=o,s>0)continue;o=Math.min(o,o+s+a);const t=[...r[0]][0].length,l=e.slice(0,n+r.index+t+o);if(Math.min(n,o)%2){const e=l.slice(1,-1);return{type:"em",raw:l,text:e,tokens:this.lexer.inlineTokens(e)}}const c=l.slice(2,-2);return{type:"strong",raw:l,text:c,tokens:this.lexer.inlineTokens(c)}}}}codespan(e){const t=this.rules.inline.code.exec(e);if(t){let e=t[2].replace(this.rules.other.newLineCharGlobal," ");const n=this.rules.other.nonSpaceChar.test(e),r=this.rules.other.startingSpaceChar.test(e)&&this.rules.other.endingSpaceChar.test(e);return n&&r&&(e=e.substring(1,e.length-1)),{type:"codespan",raw:t[0],text:e}}}br(e){const t=this.rules.inline.br.exec(e);if(t)return{type:"br",raw:t[0]}}del(e){const t=this.rules.inline.del.exec(e);if(t)return{type:"del",raw:t[0],text:t[2],tokens:this.lexer.inlineTokens(t[2])}}autolink(e){const t=this.rules.inline.autolink.exec(e);if(t){let e,n;return"@"===t[2]?(e=t[1],n="mailto:"+e):(e=t[1],n=e),{type:"link",raw:t[0],text:e,href:n,tokens:[{type:"text",raw:e,text:e}]}}}url(e){let t;if(t=this.rules.inline.url.exec(e)){let e,n;if("@"===t[2])e=t[0],n="mailto:"+e;else{let r;do{r=t[0],t[0]=this.rules.inline._backpedal.exec(t[0])?.[0]??""}while(r!==t[0]);e=t[0],n="www."===t[1]?"http://"+t[0]:t[0]}return{type:"link",raw:t[0],text:e,href:n,tokens:[{type:"text",raw:e,text:e}]}}}inlineText(e){const t=this.rules.inline.text.exec(e);if(t){const e=this.lexer.state.inRawBlock;return{type:"text",raw:t[0],text:t[0],escaped:e}}}}class ut{tokens;options;state;tokenizer;inlineQueue;constructor(e){this.tokens=[],this.tokens.links=Object.create(null),this.options=e||ae,this.options.tokenizer=this.options.tokenizer||new ct,this.tokenizer=this.options.tokenizer,this.tokenizer.options=this.options,this.tokenizer.lexer=this,this.inlineQueue=[],this.state={inLink:!1,inRawBlock:!1,top:!0};const t={other:pe,block:et.normal,inline:tt.normal};this.options.pedantic?(t.block=et.pedantic,t.inline=tt.pedantic):this.options.gfm&&(t.block=et.gfm,this.options.breaks?t.inline=tt.breaks:t.inline=tt.gfm),this.tokenizer.rules=t}static get rules(){return{block:et,inline:tt}}static lex(e,t){return new ut(t).lex(e)}static lexInline(e,t){return new ut(t).inlineTokens(e)}lex(e){e=e.replace(pe.carriageReturn,"\n"),this.blockTokens(e,this.tokens);for(let e=0;e<this.inlineQueue.length;e++){const t=this.inlineQueue[e];this.inlineTokens(t.src,t.tokens)}return this.inlineQueue=[],this.tokens}blockTokens(e,t=[],n=!1){for(this.options.pedantic&&(e=e.replace(pe.tabCharGlobal," ").replace(pe.spaceLine,""));e;){let r;if(this.options.extensions?.block?.some((n=>!!(r=n.call({lexer:this},e,t))&&(e=e.substring(r.raw.length),t.push(r),!0))))continue;if(r=this.tokenizer.space(e)){e=e.substring(r.raw.length);const n=t.at(-1);1===r.raw.length&&void 0!==n?n.raw+="\n":t.push(r);continue}if(r=this.tokenizer.code(e)){e=e.substring(r.raw.length);const n=t.at(-1);"paragraph"===n?.type||"text"===n?.type?(n.raw+="\n"+r.raw,n.text+="\n"+r.text,this.inlineQueue.at(-1).src=n.text):t.push(r);continue}if(r=this.tokenizer.fences(e)){e=e.substring(r.raw.length),t.push(r);continue}if(r=this.tokenizer.heading(e)){e=e.substring(r.raw.length),t.push(r);continue}if(r=this.tokenizer.hr(e)){e=e.substring(r.raw.length),t.push(r);continue}if(r=this.tokenizer.blockquote(e)){e=e.substring(r.raw.length),t.push(r);continue}if(r=this.tokenizer.list(e)){e=e.substring(r.raw.length),t.push(r);continue}if(r=this.tokenizer.html(e)){e=e.substring(r.raw.length),t.push(r);continue}if(r=this.tokenizer.def(e)){e=e.substring(r.raw.length);const n=t.at(-1);"paragraph"===n?.type||"text"===n?.type?(n.raw+="\n"+r.raw,n.text+="\n"+r.raw,this.inlineQueue.at(-1).src=n.text):this.tokens.links[r.tag]||(this.tokens.links[r.tag]={href:r.href,title:r.title});continue}if(r=this.tokenizer.table(e)){e=e.substring(r.raw.length),t.push(r);continue}if(r=this.tokenizer.lheading(e)){e=e.substring(r.raw.length),t.push(r);continue}let i=e;if(this.options.extensions?.startBlock){let t=1/0;const n=e.slice(1);let r;this.options.extensions.startBlock.forEach((e=>{r=e.call({lexer:this},n),"number"==typeof r&&r>=0&&(t=Math.min(t,r))})),t<1/0&&t>=0&&(i=e.substring(0,t+1))}if(this.state.top&&(r=this.tokenizer.paragraph(i))){const o=t.at(-1);n&&"paragraph"===o?.type?(o.raw+="\n"+r.raw,o.text+="\n"+r.text,this.inlineQueue.pop(),this.inlineQueue.at(-1).src=o.text):t.push(r),n=i.length!==e.length,e=e.substring(r.raw.length)}else if(r=this.tokenizer.text(e)){e=e.substring(r.raw.length);const n=t.at(-1);"text"===n?.type?(n.raw+="\n"+r.raw,n.text+="\n"+r.text,this.inlineQueue.pop(),this.inlineQueue.at(-1).src=n.text):t.push(r)}else if(e){const t="Infinite loop on byte: "+e.charCodeAt(0);if(this.options.silent){console.error(t);break}throw new Error(t)}}return this.state.top=!0,t}inline(e,t=[]){return this.inlineQueue.push({src:e,tokens:t}),t}inlineTokens(e,t=[]){let n=e,r=null;if(this.tokens.links){const e=Object.keys(this.tokens.links);if(e.length>0)for(;null!=(r=this.tokenizer.rules.inline.reflinkSearch.exec(n));)e.includes(r[0].slice(r[0].lastIndexOf("[")+1,-1))&&(n=n.slice(0,r.index)+"["+"a".repeat(r[0].length-2)+"]"+n.slice(this.tokenizer.rules.inline.reflinkSearch.lastIndex))}for(;null!=(r=this.tokenizer.rules.inline.anyPunctuation.exec(n));)n=n.slice(0,r.index)+"++"+n.slice(this.tokenizer.rules.inline.anyPunctuation.lastIndex);for(;null!=(r=this.tokenizer.rules.inline.blockSkip.exec(n));)n=n.slice(0,r.index)+"["+"a".repeat(r[0].length-2)+"]"+n.slice(this.tokenizer.rules.inline.blockSkip.lastIndex);let i=!1,o="";for(;e;){let r;if(i||(o=""),i=!1,this.options.extensions?.inline?.some((n=>!!(r=n.call({lexer:this},e,t))&&(e=e.substring(r.raw.length),t.push(r),!0))))continue;if(r=this.tokenizer.escape(e)){e=e.substring(r.raw.length),t.push(r);continue}if(r=this.tokenizer.tag(e)){e=e.substring(r.raw.length),t.push(r);continue}if(r=this.tokenizer.link(e)){e=e.substring(r.raw.length),t.push(r);continue}if(r=this.tokenizer.reflink(e,this.tokens.links)){e=e.substring(r.raw.length);const n=t.at(-1);"text"===r.type&&"text"===n?.type?(n.raw+=r.raw,n.text+=r.text):t.push(r);continue}if(r=this.tokenizer.emStrong(e,n,o)){e=e.substring(r.raw.length),t.push(r);continue}if(r=this.tokenizer.codespan(e)){e=e.substring(r.raw.length),t.push(r);continue}if(r=this.tokenizer.br(e)){e=e.substring(r.raw.length),t.push(r);continue}if(r=this.tokenizer.del(e)){e=e.substring(r.raw.length),t.push(r);continue}if(r=this.tokenizer.autolink(e)){e=e.substring(r.raw.length),t.push(r);continue}if(!this.state.inLink&&(r=this.tokenizer.url(e))){e=e.substring(r.raw.length),t.push(r);continue}let s=e;if(this.options.extensions?.startInline){let t=1/0;const n=e.slice(1);let r;this.options.extensions.startInline.forEach((e=>{r=e.call({lexer:this},n),"number"==typeof r&&r>=0&&(t=Math.min(t,r))})),t<1/0&&t>=0&&(s=e.substring(0,t+1))}if(r=this.tokenizer.inlineText(s)){e=e.substring(r.raw.length),"_"!==r.raw.slice(-1)&&(o=r.raw.slice(-1)),i=!0;const n=t.at(-1);"text"===n?.type?(n.raw+=r.raw,n.text+=r.text):t.push(r)}else if(e){const t="Infinite loop on byte: "+e.charCodeAt(0);if(this.options.silent){console.error(t);break}throw new Error(t)}}return t}}class pt{options;parser;constructor(e){this.options=e||ae}space(e){return""}code({text:e,lang:t,escaped:n}){const r=(t||"").match(pe.notSpaceStart)?.[0],i=e.replace(pe.endingNewline,"")+"\n";return r?'<pre><code class="language-'+it(r)+'">'+(n?i:it(i,!0))+"</code></pre>\n":"<pre><code>"+(n?i:it(i,!0))+"</code></pre>\n"}blockquote({tokens:e}){return`<blockquote>\n${this.parser.parse(e)}</blockquote>\n`}html({text:e}){return e}heading({tokens:e,depth:t}){return`<h${t}>${this.parser.parseInline(e)}</h${t}>\n`}hr(e){return"<hr>\n"}list(e){const t=e.ordered,n=e.start;let r="";for(let t=0;t<e.items.length;t++){const n=e.items[t];r+=this.listitem(n)}const i=t?"ol":"ul";return"<"+i+(t&&1!==n?' start="'+n+'"':"")+">\n"+r+"</"+i+">\n"}listitem(e){let t="";if(e.task){const n=this.checkbox({checked:!!e.checked});e.loose?"paragraph"===e.tokens[0]?.type?(e.tokens[0].text=n+" "+e.tokens[0].text,e.tokens[0].tokens&&e.tokens[0].tokens.length>0&&"text"===e.tokens[0].tokens[0].type&&(e.tokens[0].tokens[0].text=n+" "+it(e.tokens[0].tokens[0].text),e.tokens[0].tokens[0].escaped=!0)):e.tokens.unshift({type:"text",raw:n+" ",text:n+" ",escaped:!0}):t+=n+" "}return t+=this.parser.parse(e.tokens,!!e.loose),`<li>${t}</li>\n`}checkbox({checked:e}){return"<input "+(e?'checked="" ':"")+'disabled="" type="checkbox">'}paragraph({tokens:e}){return`<p>${this.parser.parseInline(e)}</p>\n`}table(e){let t="",n="";for(let t=0;t<e.header.length;t++)n+=this.tablecell(e.header[t]);t+=this.tablerow({text:n});let r="";for(let t=0;t<e.rows.length;t++){const i=e.rows[t];n="";for(let e=0;e<i.length;e++)n+=this.tablecell(i[e]);r+=this.tablerow({text:n})}return r&&(r=`<tbody>${r}</tbody>`),"<table>\n<thead>\n"+t+"</thead>\n"+r+"</table>\n"}tablerow({text:e}){return`<tr>\n${e}</tr>\n`}tablecell(e){const t=this.parser.parseInline(e.tokens),n=e.header?"th":"td";return(e.align?`<${n} align="${e.align}">`:`<${n}>`)+t+`</${n}>\n`}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>${it(e,!0)}</code>`}br(e){return"<br>"}del({tokens:e}){return`<del>${this.parser.parseInline(e)}</del>`}link({href:e,title:t,tokens:n}){const r=this.parser.parseInline(n),i=ot(e);if(null===i)return r;let o='<a href="'+(e=i)+'"';return t&&(o+=' title="'+it(t)+'"'),o+=">"+r+"</a>",o}image({href:e,title:t,text:n,tokens:r}){r&&(n=this.parser.parseInline(r,this.parser.textRenderer));const i=ot(e);if(null===i)return it(n);let o=`<img src="${e=i}" alt="${n}"`;return t&&(o+=` title="${it(t)}"`),o+=">",o}text(e){return"tokens"in e&&e.tokens?this.parser.parseInline(e.tokens):"escaped"in e&&e.escaped?e.text:it(e.text)}}class ht{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""}}class dt{options;renderer;textRenderer;constructor(e){this.options=e||ae,this.options.renderer=this.options.renderer||new pt,this.renderer=this.options.renderer,this.renderer.options=this.options,this.renderer.parser=this,this.textRenderer=new ht}static parse(e,t){return new dt(t).parse(e)}static parseInline(e,t){return new dt(t).parseInline(e)}parse(e,t=!0){let n="";for(let r=0;r<e.length;r++){const i=e[r];if(this.options.extensions?.renderers?.[i.type]){const e=i,t=this.options.extensions.renderers[e.type].call({parser:this},e);if(!1!==t||!["space","hr","heading","code","table","blockquote","list","html","paragraph","text"].includes(e.type)){n+=t||"";continue}}const o=i;switch(o.type){case"space":n+=this.renderer.space(o);continue;case"hr":n+=this.renderer.hr(o);continue;case"heading":n+=this.renderer.heading(o);continue;case"code":n+=this.renderer.code(o);continue;case"table":n+=this.renderer.table(o);continue;case"blockquote":n+=this.renderer.blockquote(o);continue;case"list":n+=this.renderer.list(o);continue;case"html":n+=this.renderer.html(o);continue;case"paragraph":n+=this.renderer.paragraph(o);continue;case"text":{let i=o,s=this.renderer.text(i);for(;r+1<e.length&&"text"===e[r+1].type;)i=e[++r],s+="\n"+this.renderer.text(i);n+=t?this.renderer.paragraph({type:"paragraph",raw:s,text:s,tokens:[{type:"text",raw:s,text:s,escaped:!0}]}):s;continue}default:{const e='Token with "'+o.type+'" type was not found.';if(this.options.silent)return console.error(e),"";throw new Error(e)}}}return n}parseInline(e,t=this.renderer){let n="";for(let r=0;r<e.length;r++){const i=e[r];if(this.options.extensions?.renderers?.[i.type]){const e=this.options.extensions.renderers[i.type].call({parser:this},i);if(!1!==e||!["escape","html","link","image","strong","em","codespan","br","del","text"].includes(i.type)){n+=e||"";continue}}const o=i;switch(o.type){case"escape":case"text":n+=t.text(o);break;case"html":n+=t.html(o);break;case"link":n+=t.link(o);break;case"image":n+=t.image(o);break;case"strong":n+=t.strong(o);break;case"em":n+=t.em(o);break;case"codespan":n+=t.codespan(o);break;case"br":n+=t.br(o);break;case"del":n+=t.del(o);break;default:{const e='Token with "'+o.type+'" type was not found.';if(this.options.silent)return console.error(e),"";throw new Error(e)}}}return n}}class ft{options;block;constructor(e){this.options=e||ae}static passThroughHooks=new Set(["preprocess","postprocess","processAllTokens"]);preprocess(e){return e}postprocess(e){return e}processAllTokens(e){return e}provideLexer(){return this.block?ut.lex:ut.lexInline}provideParser(){return this.block?dt.parse:dt.parseInline}}const gt=new class{defaults={async:!1,breaks:!1,extensions:null,gfm:!0,hooks:null,pedantic:!1,renderer:null,silent:!1,tokenizer:null,walkTokens:null};options=this.setOptions;parse=this.parseMarkdown(!0);parseInline=this.parseMarkdown(!1);Parser=dt;Renderer=pt;TextRenderer=ht;Lexer=ut;Tokenizer=ct;Hooks=ft;constructor(...e){this.use(...e)}walkTokens(e,t){let n=[];for(const r of e)switch(n=n.concat(t.call(this,r)),r.type){case"table":{const e=r;for(const r of e.header)n=n.concat(this.walkTokens(r.tokens,t));for(const r of e.rows)for(const e of r)n=n.concat(this.walkTokens(e.tokens,t));break}case"list":{const e=r;n=n.concat(this.walkTokens(e.items,t));break}default:{const e=r;this.defaults.extensions?.childTokens?.[e.type]?this.defaults.extensions.childTokens[e.type].forEach((r=>{const i=e[r].flat(1/0);n=n.concat(this.walkTokens(i,t))})):e.tokens&&(n=n.concat(this.walkTokens(e.tokens,t)))}}return n}use(...e){const t=this.defaults.extensions||{renderers:{},childTokens:{}};return e.forEach((e=>{const n={...e};if(n.async=this.defaults.async||n.async||!1,e.extensions&&(e.extensions.forEach((e=>{if(!e.name)throw new Error("extension name required");if("renderer"in e){const n=t.renderers[e.name];t.renderers[e.name]=n?function(...t){let r=e.renderer.apply(this,t);return!1===r&&(r=n.apply(this,t)),r}:e.renderer}if("tokenizer"in e){if(!e.level||"block"!==e.level&&"inline"!==e.level)throw new Error("extension level must be 'block' or 'inline'");const n=t[e.level];n?n.unshift(e.tokenizer):t[e.level]=[e.tokenizer],e.start&&("block"===e.level?t.startBlock?t.startBlock.push(e.start):t.startBlock=[e.start]:"inline"===e.level&&(t.startInline?t.startInline.push(e.start):t.startInline=[e.start]))}"childTokens"in e&&e.childTokens&&(t.childTokens[e.name]=e.childTokens)})),n.extensions=t),e.renderer){const t=this.defaults.renderer||new pt(this.defaults);for(const n in e.renderer){if(!(n in t))throw new Error(`renderer '${n}' does not exist`);if(["options","parser"].includes(n))continue;const r=n,i=e.renderer[r],o=t[r];t[r]=(...e)=>{let n=i.apply(t,e);return!1===n&&(n=o.apply(t,e)),n||""}}n.renderer=t}if(e.tokenizer){const t=this.defaults.tokenizer||new ct(this.defaults);for(const n in e.tokenizer){if(!(n in t))throw new Error(`tokenizer '${n}' does not exist`);if(["options","rules","lexer"].includes(n))continue;const r=n,i=e.tokenizer[r],o=t[r];t[r]=(...e)=>{let n=i.apply(t,e);return!1===n&&(n=o.apply(t,e)),n}}n.tokenizer=t}if(e.hooks){const t=this.defaults.hooks||new ft;for(const n in e.hooks){if(!(n in t))throw new Error(`hook '${n}' does not exist`);if(["options","block"].includes(n))continue;const r=n,i=e.hooks[r],o=t[r];ft.passThroughHooks.has(n)?t[r]=e=>{if(this.defaults.async)return Promise.resolve(i.call(t,e)).then((e=>o.call(t,e)));const n=i.call(t,e);return o.call(t,n)}:t[r]=(...e)=>{let n=i.apply(t,e);return!1===n&&(n=o.apply(t,e)),n}}n.hooks=t}if(e.walkTokens){const t=this.defaults.walkTokens,r=e.walkTokens;n.walkTokens=function(e){let n=[];return n.push(r.call(this,e)),t&&(n=n.concat(t.call(this,e))),n}}this.defaults={...this.defaults,...n}})),this}setOptions(e){return this.defaults={...this.defaults,...e},this}lexer(e,t){return ut.lex(e,t??this.defaults)}parser(e,t){return dt.parse(e,t??this.defaults)}parseMarkdown(e){return(t,n)=>{const r={...n},i={...this.defaults,...r},o=this.onError(!!i.silent,!!i.async);if(!0===this.defaults.async&&!1===r.async)return o(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(null==t)return o(new Error("marked(): input parameter is undefined or null"));if("string"!=typeof t)return o(new Error("marked(): input parameter is of type "+Object.prototype.toString.call(t)+", string expected"));i.hooks&&(i.hooks.options=i,i.hooks.block=e);const s=i.hooks?i.hooks.provideLexer():e?ut.lex:ut.lexInline,a=i.hooks?i.hooks.provideParser():e?dt.parse:dt.parseInline;if(i.async)return Promise.resolve(i.hooks?i.hooks.preprocess(t):t).then((e=>s(e,i))).then((e=>i.hooks?i.hooks.processAllTokens(e):e)).then((e=>i.walkTokens?Promise.all(this.walkTokens(e,i.walkTokens)).then((()=>e)):e)).then((e=>a(e,i))).then((e=>i.hooks?i.hooks.postprocess(e):e)).catch(o);try{i.hooks&&(t=i.hooks.preprocess(t));let e=s(t,i);i.hooks&&(e=i.hooks.processAllTokens(e)),i.walkTokens&&this.walkTokens(e,i.walkTokens);let n=a(e,i);return i.hooks&&(n=i.hooks.postprocess(n)),n}catch(e){return o(e)}}}onError(e,t){return n=>{if(n.message+="\nPlease report this to https://github.com/markedjs/marked.",e){const e="<p>An error occurred:</p><pre>"+it(n.message+"",!0)+"</pre>";return t?Promise.resolve(e):e}if(t)return Promise.reject(n);throw n}}};function mt(e,t){return gt.parse(e,t)}function kt(e,t){var n=arguments.length>2&&void 0!==arguments[2]&&arguments[2],r=arguments.length>3?arguments[3]:void 0,i=document.querySelector("#akvo-rag-body");if(i){var o=document.createElement("div"),s="akvo-msg-".concat(e,"-").concat(r);if(o.id=s,o.className="akvo-msg-".concat(e),n)o.innerHTML='\n <div class="typing-indicator">\n <span></span><span></span><span></span>\n </div>\n ';else{var a=mt.parse(t||""),l=te.sanitize(a);o.innerHTML=l}return i.appendChild(o),i.scrollTop=i.scrollHeight,o}}function bt(){"undefined"!=typeof document&&"function"==typeof document.querySelectorAll&&document.querySelectorAll(".citation-popover").forEach((function(e){return e.remove()}))}function yt(e){bt();var t=e.target,n=document.createElement("div");n.className="citation-popover";var r='\n <div class="arrow"></div>\n <div><strong>'.concat(t.dataset.title||"","</strong></div>\n <div><small>Source: ").concat(t.dataset.source||"",", Page: ").concat(t.dataset.page||"","</small></div>\n <p>").concat(t.dataset.text||"","</p>\n ");n.innerHTML=te.sanitize(r),document.body.appendChild(n);var i=n.offsetWidth,o=n.offsetHeight,s=t.getBoundingClientRect(),a=s.left+window.scrollX-i/2+s.width/2,l=window.scrollX+window.innerWidth-i-10,c=window.scrollX+10;a=Math.max(Math.min(a,l),c),s.top;var u=window.innerHeight-s.bottom<o+8+10,p=u?s.top+window.scrollY-o-8-2:s.bottom+window.scrollY+8+2;n.style.left="".concat(a,"px"),n.style.top="".concat(p,"px"),n.dataset.target=t.dataset.id,n.classList.toggle("above",u),n.classList.toggle("below",!u);var h=n.querySelector(".arrow"),d=s.left+s.width/2+window.scrollX-a-8;d=Math.max(8,Math.min(d,i-16)),h.style.left="".concat(d,"px")}function xt(e){var t=e.target;document.querySelectorAll(".citation-popover").forEach((function(e){e.dataset.target===t.dataset.id&&e.remove()}))}function vt(e){return vt="function"==typeof Symbol&&"symbol"==typeof Symbol.iterator?function(e){return typeof e}:function(e){return e&&"function"==typeof Symbol&&e.constructor===Symbol&&e!==Symbol.prototype?"symbol":typeof e},vt(e)}function wt(e,t){var n=Object.keys(e);if(Object.getOwnPropertySymbols){var r=Object.getOwnPropertySymbols(e);t&&(r=r.filter((function(t){return Object.getOwnPropertyDescriptor(e,t).enumerable}))),n.push.apply(n,r)}return n}function St(e){for(var t=1;t<arguments.length;t++){var n=null!=arguments[t]?arguments[t]:{};t%2?wt(Object(n),!0).forEach((function(t){_t(e,t,n[t])})):Object.getOwnPropertyDescriptors?Object.defineProperties(e,Object.getOwnPropertyDescriptors(n)):wt(Object(n)).forEach((function(t){Object.defineProperty(e,t,Object.getOwnPropertyDescriptor(n,t))}))}return e}function _t(e,t,n){return(t=Et(t))in e?Object.defineProperty(e,t,{value:n,enumerable:!0,configurable:!0,writable:!0}):e[t]=n,e}function Tt(e,t){for(var n=0;n<t.length;n++){var r=t[n];r.enumerable=r.enumerable||!1,r.configurable=!0,"value"in r&&(r.writable=!0),Object.defineProperty(e,Et(r.key),r)}}function Et(e){var t=function(e){if("object"!=vt(e)||!e)return e;var t=e[Symbol.toPrimitive];if(void 0!==t){var n=t.call(e,"string");if("object"!=vt(n))return n;throw new TypeError("@@toPrimitive must return a primitive value.")}return String(e)}(e);return"symbol"==vt(t)?t:t+""}mt.options=mt.setOptions=function(e){return gt.setOptions(e),mt.defaults=gt.defaults,le(mt.defaults),mt},mt.getDefaults=function(){return{async:!1,breaks:!1,extensions:null,gfm:!0,hooks:null,pedantic:!1,renderer:null,silent:!1,tokenizer:null,walkTokens:null}},mt.defaults=ae,mt.use=function(...e){return gt.use(...e),mt.defaults=gt.defaults,le(mt.defaults),mt},mt.walkTokens=function(e,t){return gt.walkTokens(e,t)},mt.parseInline=gt.parseInline,mt.Parser=dt,mt.parser=dt.parse,mt.Renderer=pt,mt.TextRenderer=ht,mt.Lexer=ut,mt.lexer=ut.lex,mt.Tokenizer=ct,mt.Hooks=ft,mt.parse=mt,mt.options,mt.setOptions,mt.use,mt.walkTokens,mt.parseInline,dt.parse,ut.lex,mt.setOptions({gfm:!0,breaks:!0});var At="Hello! How can I help you today?",Rt=function(){return e=function e(){var t,n=arguments.length>0&&void 0!==arguments[0]?arguments[0]:{};!function(e,t){if(!(e instanceof t))throw new TypeError("Cannot call a class as a function")}(this,e),this.options=n,this.showLauncher=void 0===this.options.showLauncher||Boolean(this.options.showLauncher),this.isMinimized=void 0!==this.options.startMinimized?Boolean(this.options.startMinimized):this.showLauncher,this.wsConnection=null,this.currentAssistantMsgEl=null,this.isLoading=!1,this.citations=[],this.messageCounter=0,this.chatHistory=[],this.visitorId=((t=localStorage.getItem("akvo-visitor-id"))||(t=crypto.randomUUID(),localStorage.setItem("akvo-visitor-id",t)),t),this.container=null,this.launcher=null,this._onMessage=this._onMessage.bind(this),this._handleSend=this._handleSend.bind(this),this._handleStartChat=this._handleStartChat.bind(this),this.init()},t=[{key:"init",value:function(){if(this.container=document.getElementById("akvo-rag"),this.launcher=document.getElementById("akvo-rag-launcher"),this.container)return this._applyCustomStyles(this.container,!1),this.launcher&&this._applyCustomStyles(this.launcher,!0),void(this.isMinimized?this.close():this.open());this.showLauncher?this._createLauncher():this.launcher=null,this._createUI(),this._bindEvents(),this.isMinimized?this.close():this.open(),this.options.kb_id&&this._connect()}},{key:"destroy",value:function(){this.wsConnection&&this.wsConnection.close(),this.container&&(this.container.remove(),this.container=null),this.launcher&&(this.launcher.remove(),this.launcher=null),bt()}},{key:"open",value:function(){var e;this.isMinimized=!1,this.container&&(this.container.style&&(this.container.style.display="flex"),null===(e=this.container.classList)||void 0===e||e.remove("minimized")),this.launcher&&this.launcher.style&&(this.launcher.style.display="none")}},{key:"close",value:function(){var e;this.isMinimized=!0,this.container&&(this.showLauncher?this.container.style&&(this.container.style.display="none"):null===(e=this.container.classList)||void 0===e||e.add("minimized")),this.launcher&&this.launcher.style&&(this.launcher.style.display="flex")}},{key:"minimize",value:function(){this.close()}},{key:"_isValidCssColor",value:function(e){if(!e||"string"!=typeof e)return!1;var t=e.trim();return!!/^#(?:[0-9a-fA-F]{3,4}|[0-9a-fA-F]{6}|[0-9a-fA-F]{8})$/.test(t)||!!/^(?:rgb|hsl)a?\(\s*[\d.%\s,/-]+\s*\)$/i.test(t)||/^(?:teal|blue|green|red|purple|indigo|slate|gray|black|white|transparent)$/i.test(t)}},{key:"_toCssDimension",value:function(e){if("number"==typeof e&&Number.isFinite(e)&&e>0)return"".concat(e,"px");if("string"==typeof e){var t=e.trim();if(/^\d+(\.\d+)?$/.test(t))return"".concat(t,"px");if(/^\d+(\.\d+)?(px|rem|em|vh|vw|%)$/i.test(t))return t}return null}},{key:"_toSafeZIndex",value:function(e){if("number"==typeof e&&Number.isInteger(e)&&e>=0&&e<=2147483647)return e;if("string"==typeof e){var t=e.trim();if(/^\d+$/.test(t)){var n=parseInt(t,10);if(!isNaN(n)&&n>=0&&n<=2147483647)return n}}return null}},{key:"_applyCustomStyles",value:function(e){var t=arguments.length>1&&void 0!==arguments[1]&&arguments[1];if(e&&e.style){var n;this._isValidCssColor(this.options.primaryColor)&&"function"==typeof e.style.setProperty&&e.style.setProperty("--akvo-primary",this.options.primaryColor.trim()),"bottom-left"===String(this.options.position||"").trim().toLowerCase()&&(null===(n=e.classList)||void 0===n||n.add("akvo-position-left"));var r=this._toSafeZIndex(this.options.zIndex);if(null!==r&&"function"==typeof e.style.setProperty){var i=t?Math.max(0,r-1):r;e.style.setProperty("--akvo-z-index",String(i)),e.style.zIndex=String(i)}if(t&&"function"==typeof e.style.setProperty){var o=this._toCssDimension(this.options.launcherSize),s=this._toCssDimension(this.options.launcherWidth)||o,a=this._toCssDimension(this.options.launcherHeight)||o;s&&e.style.setProperty("--akvo-launcher-width",s),a&&e.style.setProperty("--akvo-launcher-height",a)}else if(!t&&"function"==typeof e.style.setProperty){var l=this._toCssDimension(this.options.width);l&&e.style.setProperty("--akvo-width",l);var c=this._toCssDimension(this.options.height);c&&e.style.setProperty("--akvo-height",c);var u=this._toCssDimension(this.options.borderRadius);u&&e.style.setProperty("--akvo-border-radius",u)}}}},{key:"_sanitizeHtml",value:function(e,t){if("function"==typeof(null==te?void 0:te.sanitize))return te.sanitize(e,t);if("function"==typeof te)try{var n=te(globalThis.window||globalThis);if("function"==typeof(null==n?void 0:n.sanitize))return n.sanitize(e,t)}catch(e){}return String(e).replace(/<script\b[^<]*(?:(?!<\/script>)<[^<]*)*<\/script>/gi,"").replace(/on\w+="[^"]*"/gi,"").replace(/on\w+='[^']*'/gi,"")}},{key:"_renderIcon",value:function(e){if(!e)return arguments.length>1&&void 0!==arguments[1]?arguments[1]:"";var t=String(e).trim();if(t.startsWith("<svg")||t.includes("<svg"))return this._sanitizeHtml(t,{USE_PROFILES:{svg:!0,svgFilters:!0}});if(/^(https?:\/\/|data:image\/|\/|\.\/)/i.test(t)||/\.(svg|png|jpe?g|webp|gif)(\?.*)?$/i.test(t)){var n=this._sanitizeHtml(t);return'<img src="'.concat(n,'" alt="icon" class="akvo-icon-img" />')}var r=this._sanitizeHtml(t);return'<i class="'.concat(r,'" aria-hidden="true"></i>')}},{key:"_createLauncher",value:function(){this.launcher=document.createElement("button"),this.launcher.id="akvo-rag-launcher",this.launcher.className="akvo-rag-launcher","function"==typeof this.launcher.setAttribute&&(this.launcher.setAttribute("type","button"),this.launcher.setAttribute("aria-label","Open chat")),this.launcher.innerHTML=this._renderIcon(this.options.launcherIcon,'<i class="fa fa-comments" aria-hidden="true"></i>'),this._applyCustomStyles(this.launcher,!0),this.launcher.style&&(this.launcher.style.display=this.isMinimized?"flex":"none"),document.body&&"function"==typeof document.body.appendChild&&document.body.appendChild(this.launcher)}},{key:"_renderInputArea",value:function(){return'\n <input\n type="text"\n id="akvo-rag-input"\n placeholder="Type a message..."\n autocomplete="off"\n autocorrect="off"\n autocapitalize="off"\n spellcheck="false"\n />\n <button id="akvo-rag-send-btn">Send</button>\n '}},{key:"_createUI",value:function(){var e;this.container=document.createElement("div"),this.container.id="akvo-rag",this._applyCustomStyles(this.container,!1),this.container.style&&(this.container.style.display=this.showLauncher&&this.isMinimized?"none":"flex");var t=this.options.headerIcon?'<span class="akvo-header-icon">'.concat(this._renderIcon(this.options.headerIcon,""),"</span>"):"";this.container.innerHTML='\n <div id="akvo-rag-header">\n <div class="akvo-header-title">\n '.concat(t,"\n <span>").concat(this.options.title||"Chatbot",'</span>\n </div>\n <button id="akvo-rag-close-btn" class="akvo-rag-close-btn" aria-label="Minimize chat">\n <i class="fa fa-window-minimize" aria-hidden="true"></i>\n </button>\n </div>\n <div id="akvo-rag-body" class="akvo-rag-body">\n ').concat(!this.options.kb_id&&null!==(e=this.options.kb_options)&&void 0!==e&&e.length?'\n <div id="akvo-kb-options" class="akvo-kb-options">\n <p>Please select a knowledge base to continue:</p>\n '.concat(this.options.kb_options.map((function(e){return'\n <div class="kb-option">\n <input type="radio" id="kb-'.concat(e.kb_id,'" name="akvo-kb" value="').concat(e.kb_id,'">\n <label for="kb-').concat(e.kb_id,'">').concat(e.label,"</label>\n </div>\n ")})).join(""),'\n <div class="akvo-kb-options-hint">\n After selecting, click "Start Chat" to begin.\n </div>\n </div>\n '):'<p class="akvo-msg-system">'.concat(At,"</p>"),'\n </div>\n <div id="akvo-rag-input-container" class="akvo-rag-input-container">\n ').concat(this.options.kb_id?this._renderInputArea():'\n <button id="akvo-start-chat-btn" class="akvo-start-chat-btn" style="flex: 1;" disabled>\n Start Chat\n </button>\n ',"\n </div>\n "),document.body.appendChild(this.container)}},{key:"_bindEvents",value:function(){var e,t,n,r=this,i=null===(e=this.container)||void 0===e?void 0:e.querySelector("#akvo-rag-header"),o=null===(t=this.container)||void 0===t?void 0:t.querySelector("#akvo-rag-close-btn");if(this.launcher&&"function"==typeof this.launcher.addEventListener&&this.launcher.addEventListener("click",(function(){r.open()})),o&&o.addEventListener("click",(function(e){var t;e.stopPropagation(),r.showLauncher?r.close():null!==(t=r.container)&&void 0!==t&&null!==(t=t.classList)&&void 0!==t&&t.contains("minimized")?r.open():r.close()})),i&&i.addEventListener("click",(function(){var e;r.showLauncher?r.isMinimized&&r.open():null!==(e=r.container)&&void 0!==e&&null!==(e=e.classList)&&void 0!==e&&e.contains("minimized")&&r.open()})),!this.options.kb_id&&null!==(n=this.options.kb_options)&&void 0!==n&&n.length){var s=this.container.querySelector("#akvo-start-chat-btn");this.container.querySelectorAll("input[name='akvo-kb']").forEach((function(e){e.addEventListener("change",(function(){s.disabled=!1}))})),s.addEventListener("click",this._handleStartChat)}else this._bindInputEvents()}},{key:"_bindInputEvents",value:function(){var e=this,t=this.container.querySelector("#akvo-rag-input"),n=this.container.querySelector("#akvo-rag-send-btn");t&&n&&(t.addEventListener("keypress",(function(t){"Enter"===t.key&&e._handleSend()})),n.addEventListener("click",this._handleSend))}},{key:"_connect",value:function(){var e=this,t={onReconnect:function(t){console.log("Reconnecting attempt #".concat(t,", resetting isLoading")),e.isLoading=!1,e._updateSendButtonState()},onMaxReconnect:function(){e.isLoading=!1,e._updateSendButtonState(),kt("system","Connection to the chat server lost. Please check your network and refresh the page.")}};this.wsConnection=function(e,t){var n=arguments.length>2&&void 0!==arguments[2]?arguments[2]:{},r=null,i=0,o=e.wsURL||e.wsUrl;return function s(){o?(console.log("[WebSocket] Connecting to: ".concat(o)),(r=new WebSocket(o)).onopen=function(){console.log("[WebSocket] Connected"),i=0,r.send(JSON.stringify({type:"auth",visitor_id:e.visitorId,kb_id:e.kb_id})),e.onOpen&&e.onOpen()},r.onmessage=function(e){var n=null;try{n=JSON.parse(e.data)}catch(t){return void console.warn("[WebSocket] Received non-JSON data",e.data)}if(t){if("ping"===n.type)return r.send(JSON.stringify({type:"pong"})),void console.log("Pong sent to server");if("response_chunk"===n.type&&n.content.includes("__LLM_RESPONSE__"))try{var i,o=function(e,t){return function(e){if(Array.isArray(e))return e}(e)||function(e,t){var n=null==e?null:"undefined"!=typeof Symbol&&e[Symbol.iterator]||e["@@iterator"];if(null!=n){var r,i,o,s,a=[],l=!0,c=!1;try{if(o=(n=n.call(e)).next,0===t){if(Object(n)!==n)return;l=!1}else for(;!(l=(r=o.call(n)).done)&&(a.push(r.value),a.length!==t);l=!0);}catch(e){c=!0,i=e}finally{try{if(!l&&null!=n.return&&(s=n.return(),Object(s)!==s))return}finally{if(c)throw i}}return a}}(e,t)||function(e,t){if(e){if("string"==typeof e)return se(e,t);var n={}.toString.call(e).slice(8,-1);return"Object"===n&&e.constructor&&(n=e.constructor.name),"Map"===n||"Set"===n?Array.from(e):"Arguments"===n||/^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n)?se(e,t):void 0}}(e,t)||function(){throw new TypeError("Invalid attempt to destructure non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.")}()}(n.content.split("__LLM_RESPONSE__"),2),s=o[0],a=o[1],l=function(e){if(!e)return"";var t=e.split(":")[1].trim().replace(/^"|"$/g,"").match(/[A-Za-z0-9+/=]+/);return t?t[0]:""}(s),c=null;if(l)try{var u=atob(l);c=JSON.parse(u)}catch(e){console.warn("Failed to decode or parse base64 contextData",e)}var p=(null===(i=c)||void 0===i||null===(i=i.context)||void 0===i?void 0:i.map((function(e,t){return{id:t+1,text:e.page_content,metadata:e.metadata}})))||[];t(ie(ie({},n),{},{content:a.trim(),citations:p}))}catch(e){console.error("Failed to parse __LLM_RESPONSE__",e),t(n)}else t(n)}},r.onclose=function(t){if(console.warn("[WebSocket] Closed (URL: ".concat(o,"): code=").concat(t.code," reason=").concat(t.reason||"no reason provided")),e.autoReconnect&&1e3!==t.code)if(i<10){i++;var r=Math.min(1e3*Math.pow(2,i-1),3e4),a=1e3*Math.random()-500,l=Math.max(1e3,r+a);console.log("[WebSocket] Reconnect attempt ".concat(i," in ").concat(Math.round(l),"ms")),null!=n&&n.onReconnect&&n.onReconnect(i),setTimeout((function(){s()}),l)}else console.error("[WebSocket] Max reconnect attempts reached."),e.onMaxReconnect&&e.onMaxReconnect()},r.onerror=function(t){console.error("[WebSocket] Error (URL: ".concat(o,"):"),t),e.onError&&e.onError(t)}):console.warn("[WebSocket] No wsURL provided in options.")}(),{get socket(){return r},close:function(){e.autoReconnect=!1,r&&r.close(1e3,"Client closed connection")}}}(St(St({},this.options),{},{autoReconnect:!0,visitorId:this.visitorId,onMaxReconnect:t.onMaxReconnect}),this._onMessage,t)}},{key:"_handleStartChat",value:function(){var e=this.container.querySelector("input[name='akvo-kb']:checked");if(e){this.options.kb_id=parseInt(e.value,10);var t=this.container.querySelector("#akvo-kb-options");t&&t.remove(),this.container.querySelector("#akvo-rag-input-container").innerHTML=this._renderInputArea(),this._connect();var n=this.container.querySelector("#akvo-rag-body"),r=document.createElement("p");r.className="akvo-msg-system",r.textContent=At,n.appendChild(r),this._bindInputEvents()}}},{key:"_handleSend",value:function(){var e;if(!this.isLoading){var t=this.container.querySelector("#akvo-rag-input"),n=t.value.trim();if(n&&(null===(e=this.wsConnection)||void 0===e||null===(e=e.socket)||void 0===e?void 0:e.readyState)===WebSocket.OPEN){this.chatHistory.push({role:"user",content:n});var r=this.chatHistory.slice(-10);this.wsConnection.socket.send(JSON.stringify({type:"chat",kb_id:this.options.kb_id,messages:r})),kt("user",n),t.value="",this.currentAssistantMsgEl=null,this.isLoading=!0,this._updateSendButtonState()}}}},{key:"_updateSendButtonState",value:function(){var e=this.container.querySelector("#akvo-rag-send-btn");e&&(this.isLoading?(e.disabled=!0,e.innerHTML='<span class="akvo-send-spinner"></span>'):(e.disabled=!1,e.innerHTML="Send"))}},{key:"_onMessage",value:function(e){var t=this;if("info"===e.type)kt("system",e.message);else if("start"===e.type)this.citations=[],this.messageCounter++,this.currentAssistantMsgEl=kt("assistant","",!0,this.messageCounter);else if("response_chunk"===e.type){var n;null!=e&&null!==(n=e.citations)&&void 0!==n&&n.length&&e.citations.forEach((function(e){var n=t.citations.findIndex((function(t){return t.id===e.id}));if(n>-1){var r=t.citations[n],i=e.text&&e.metadata,o=r.text&&r.metadata;!i&&o||(t.citations[n]=e)}else t.citations.push(e)})),function(e,t){var n=document.querySelector("#akvo-rag-body");if(n&&e&&t){t.rawText||(t.rawText="");var r=function(e){var t=arguments.length>1&&void 0!==arguments[1]?arguments[1]:"";if(/^\s*d:\{/.test(e))return t;var n=e;(n=n.replace(/^\d+:\s*/,"")).startsWith('"')&&(n=n.substring(1)),n.endsWith('"')?n=n.substring(0,n.length-1):n.trimEnd().endsWith('"')&&(n=(n=n.trimEnd()).substring(0,n.length-1));try{var r=n.replace(/\\"/g,'"').replace(/"/g,'\\"');n=JSON.parse('"'+r+'"')}catch(e){}return((t||"")+n).replace(/^"\s*/,"")}(e,t.rawText);t.rawText=r;var i=function(e){var t=e;t=(t=(t=(t=(t=(t=(t=(t=(t=t.replace(/\b[A-Za-z0-9](?: [A-Za-z0-9])+\b/g,(function(e){return e.replace(/ /g,"")}))).replace(/\s+([,.:;!?])/g,"$1")).replace(/(\*\*|__)\s*(.*?)\s*(\*\*|__)/g,"$1$2$3")).replace(/` +([^`]+?) +`/g,"`$1`")).replace(/``` *bash/g,"```bash")).replace(/\\\n\s*/g,"")).replace(/\n{3,}/g,"\n\n")).replace(/[ \t]{2,}/g," ")).split("\n").map((function(e){return e.trim()})).join("\n");var n=[],r="";return t.split("\n").forEach((function(e){""===e?r&&(n.push(r.trim()),r=""):r?/[.!?]$/.test(r)?(n.push(r.trim()),r=e):r+=" "+e:r=e})),r&&n.push(r.trim()),n.join("\n\n")}(t.rawText);if(t.lastRenderedText!==i){var o=mt.parse(i),s=te.sanitize(o);t.innerHTML=s,t.lastRenderedText=i,n.scrollTop=n.scrollHeight}}}(e.content,this.currentAssistantMsgEl)}else if("end"===e.type){var r=this.currentAssistantMsgEl||document.querySelector("#akvo-msg-assistant-".concat(this.messageCounter));r&&(function(e,t){e&&null!=t&&t.length&&requestAnimationFrame((function(){var n=e.innerHTML;t.forEach((function(e){var t=null==e?void 0:e.id;if(null!=t){var r=new RegExp("(\\[|&?#?[a-zA-Z0-9]+;)\\s*citation:\\s*".concat(t,"\\s*(\\]|&?#?[a-zA-Z0-9]+;)"),"gi"),i=((null==e?void 0:e.text)||"").replace(/\s+/g," ").trim().slice(0,200)+"...",o=(null==e?void 0:e.metadata)||{},s=o.source||"Unknown Source",a=o.page_label||o.page||"n/a",l=o.title||o.source||"Untitled Document",c=i.replace(/"/g,"""),u=s.replace(/"/g,"""),p=l.replace(/"/g,"""),h='\n <sup\n class="citation"\n data-id="'.concat(t,'"\n data-text="').concat(c,'"\n data-source="').concat(u,'"\n data-page="').concat(a,'"\n data-title="').concat(p,'"\n >[').concat(t,"]</sup>");n=n.replace(r,h)}})),n=n.replace(/(?:\[|[|[)\s*citation:\s*\d+\s*(?:\]|]|])/gi,""),e.innerHTML=n,e.querySelectorAll(".citation").forEach((function(e){e.style.cursor="pointer",e.addEventListener("mouseenter",yt),e.addEventListener("mouseleave",xt)}))}))}(r,this.citations),null!=r&&r.rawText&&this.chatHistory.push({role:"assistant",content:r.rawText})),this.isLoading=!1,this._updateSendButtonState()}}}],t&&Tt(e.prototype,t),Object.defineProperty(e,"prototype",{writable:!1}),e;var e,t}();function Lt(){return new Rt(arguments.length>0&&void 0!==arguments[0]?arguments[0]:{})}return"undefined"!=typeof window&&(window.AkvoRAG={initChat:Lt}),t})()));
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
/*! @license DOMPurify 3.2.5 | (c) Cure53 and other contributors | Released under the Apache license 2.0 and Mozilla Public License 2.0 | github.com/cure53/DOMPurify/blob/3.2.5/LICENSE */
|