var ta=Object.defineProperty;var na=(e,i,t)=>i in e?ta(e,i,{enumerable:!0,configurable:!0,writable:!0,value:t}):e[i]=t;var K=(e,i,t)=>(na(e,typeof i!="symbol"?i+"":i,t),t);var gt;function Xr(e){return gt=gt||document.createElement("textarea"),gt.innerHTML="&"+e+";",gt.value}var ra=Object.prototype.hasOwnProperty;function ia(e,i){return e?ra.call(e,i):!1}function Qr(e){var i=[].slice.call(arguments,1);return i.forEach(function(t){if(t){if(typeof t!="object")throw new TypeError(t+"must be object");Object.keys(t).forEach(function(n){e[n]=t[n]})}}),e}var aa=/\\([\\!"#$%&'()*+,.\/:;<=>?@[\]^_`{|}~-])/g;function tt(e){return e.indexOf("\\")<0?e:e.replace(aa,"$1")}function ei(e){return!(e>=55296&&e<=57343||e>=64976&&e<=65007||(e&65535)===65535||(e&65535)===65534||e>=0&&e<=8||e===11||e>=14&&e<=31||e>=127&&e<=159||e>1114111)}function bn(e){if(e>65535){e-=65536;var i=55296+(e>>10),t=56320+(e&1023);return String.fromCharCode(i,t)}return String.fromCharCode(e)}var oa=/&([a-z#][a-z0-9]{1,31});/gi,sa=/^#((?:x[a-f0-9]{1,8}|[0-9]{1,8}))/i;function la(e,i){var t=0,n=Xr(i);return i!==n?n:i.charCodeAt(0)===35&&sa.test(i)&&(t=i[1].toLowerCase()==="x"?parseInt(i.slice(2),16):parseInt(i.slice(1),10),ei(t))?bn(t):e}function Le(e){return e.indexOf("&")<0?e:e.replace(oa,la)}var ua=/[&<>"]/,ca=/[&<>"]/g,da={"&":"&amp;","<":"&lt;",">":"&gt;",'"':"&quot;"};function ha(e){return da[e]}function le(e){return ua.test(e)?e.replace(ca,ha):e}var A={};A.blockquote_open=function(){return`<blockquote>
`};A.blockquote_close=function(e,i){return"</blockquote>"+De(e,i)};A.code=function(e,i){return e[i].block?"<pre><code>"+le(e[i].content)+"</code></pre>"+De(e,i):"<code>"+le(e[i].content)+"</code>"};A.fence=function(e,i,t,n,r){var a=e[i],o="",s=t.langPrefix,l="",u,c,d;if(a.params){if(u=a.params.split(/\s+/g),c=u.join(" "),ia(r.rules.fence_custom,u[0]))return r.rules.fence_custom[u[0]](e,i,t,n,r);l=le(Le(tt(c))),o=' class="'+s+l+'"'}return t.highlight?d=t.highlight.apply(t.highlight,[a.content].concat(u))||le(a.content):d=le(a.content),"<pre><code"+o+">"+d+"</code></pre>"+De(e,i)};A.fence_custom={};A.heading_open=function(e,i){return"<h"+e[i].hLevel+">"};A.heading_close=function(e,i){return"</h"+e[i].hLevel+`>
`};A.hr=function(e,i,t){return(t.xhtmlOut?"<hr />":"<hr>")+De(e,i)};A.bullet_list_open=function(){return`<ul>
`};A.bullet_list_close=function(e,i){return"</ul>"+De(e,i)};A.list_item_open=function(){return"<li>"};A.list_item_close=function(){return`</li>
`};A.ordered_list_open=function(e,i){var t=e[i],n=t.order>1?' start="'+t.order+'"':"";return"<ol"+n+`>
`};A.ordered_list_close=function(e,i){return"</ol>"+De(e,i)};A.paragraph_open=function(e,i){return e[i].tight?"":"<p>"};A.paragraph_close=function(e,i){var t=!(e[i].tight&&i&&e[i-1].type==="inline"&&!e[i-1].content);return(e[i].tight?"":"</p>")+(t?De(e,i):"")};A.link_open=function(e,i,t){var n=e[i].title?' title="'+le(Le(e[i].title))+'"':"",r=t.linkTarget?' target="'+t.linkTarget+'"':"";return'<a href="'+le(e[i].href)+'"'+n+r+">"};A.link_close=function(){return"</a>"};A.image=function(e,i,t){var n=' src="'+le(e[i].src)+'"',r=e[i].title?' title="'+le(Le(e[i].title))+'"':"",a=' alt="'+(e[i].alt?le(Le(tt(e[i].alt))):"")+'"',o=t.xhtmlOut?" /":"";return"<img"+n+a+r+o+">"};A.table_open=function(){return`<table>
`};A.table_close=function(){return`</table>
`};A.thead_open=function(){return`<thead>
`};A.thead_close=function(){return`</thead>
`};A.tbody_open=function(){return`<tbody>
`};A.tbody_close=function(){return`</tbody>
`};A.tr_open=function(){return"<tr>"};A.tr_close=function(){return`</tr>
`};A.th_open=function(e,i){var t=e[i];return"<th"+(t.align?' style="text-align:'+t.align+'"':"")+">"};A.th_close=function(){return"</th>"};A.td_open=function(e,i){var t=e[i];return"<td"+(t.align?' style="text-align:'+t.align+'"':"")+">"};A.td_close=function(){return"</td>"};A.strong_open=function(){return"<strong>"};A.strong_close=function(){return"</strong>"};A.em_open=function(){return"<em>"};A.em_close=function(){return"</em>"};A.del_open=function(){return"<del>"};A.del_close=function(){return"</del>"};A.ins_open=function(){return"<ins>"};A.ins_close=function(){return"</ins>"};A.mark_open=function(){return"<mark>"};A.mark_close=function(){return"</mark>"};A.sub=function(e,i){return"<sub>"+le(e[i].content)+"</sub>"};A.sup=function(e,i){return"<sup>"+le(e[i].content)+"</sup>"};A.hardbreak=function(e,i,t){return t.xhtmlOut?`<br />
`:`<br>
`};A.softbreak=function(e,i,t){return t.breaks?t.xhtmlOut?`<br />
`:`<br>
`:`
`};A.text=function(e,i){return le(e[i].content)};A.htmlblock=function(e,i){return e[i].content};A.htmltag=function(e,i){return e[i].content};A.abbr_open=function(e,i){return'<abbr title="'+le(Le(e[i].title))+'">'};A.abbr_close=function(){return"</abbr>"};A.footnote_ref=function(e,i){var t=Number(e[i].id+1).toString(),n="fnref"+t;return e[i].subId>0&&(n+=":"+e[i].subId),'<sup class="footnote-ref"><a href="#fn'+t+'" id="'+n+'">['+t+"]</a></sup>"};A.footnote_block_open=function(e,i,t){var n=t.xhtmlOut?`<hr class="footnotes-sep" />
`:`<hr class="footnotes-sep">
`;return n+`<section class="footnotes">
<ol class="footnotes-list">
`};A.footnote_block_close=function(){return`</ol>
</section>
`};A.footnote_open=function(e,i){var t=Number(e[i].id+1).toString();return'<li id="fn'+t+'"  class="footnote-item">'};A.footnote_close=function(){return`</li>
`};A.footnote_anchor=function(e,i){var t=Number(e[i].id+1).toString(),n="fnref"+t;return e[i].subId>0&&(n+=":"+e[i].subId),' <a href="#'+n+'" class="footnote-backref">↩</a>'};A.dl_open=function(){return`<dl>
`};A.dt_open=function(){return"<dt>"};A.dd_open=function(){return"<dd>"};A.dl_close=function(){return`</dl>
`};A.dt_close=function(){return`</dt>
`};A.dd_close=function(){return`</dd>
`};function ti(e,i){return++i>=e.length-2?i:e[i].type==="paragraph_open"&&e[i].tight&&e[i+1].type==="inline"&&e[i+1].content.length===0&&e[i+2].type==="paragraph_close"&&e[i+2].tight?ti(e,i+2):i}var De=A.getBreak=function(i,t){return t=ti(i,t),t<i.length&&i[t].type==="list_item_close"?"":`
`};function Ln(){this.rules=Qr({},A),this.getBreak=A.getBreak}Ln.prototype.renderInline=function(e,i,t){for(var n=this.rules,r=e.length,a=0,o="";r--;)o+=n[e[a].type](e,a++,i,t,this);return o};Ln.prototype.render=function(e,i,t){for(var n=this.rules,r=e.length,a=-1,o="";++a<r;)e[a].type==="inline"?o+=this.renderInline(e[a].children,i,t):o+=n[e[a].type](e,a,i,t,this);return o};function fe(){this.__rules__=[],this.__cache__=null}fe.prototype.__find__=function(e){for(var i=this.__rules__.length,t=-1;i--;)if(this.__rules__[++t].name===e)return t;return-1};fe.prototype.__compile__=function(){var e=this,i=[""];e.__rules__.forEach(function(t){t.enabled&&t.alt.forEach(function(n){i.indexOf(n)<0&&i.push(n)})}),e.__cache__={},i.forEach(function(t){e.__cache__[t]=[],e.__rules__.forEach(function(n){n.enabled&&(t&&n.alt.indexOf(t)<0||e.__cache__[t].push(n.fn))})})};fe.prototype.at=function(e,i,t){var n=this.__find__(e),r=t||{};if(n===-1)throw new Error("Parser rule not found: "+e);this.__rules__[n].fn=i,this.__rules__[n].alt=r.alt||[],this.__cache__=null};fe.prototype.before=function(e,i,t,n){var r=this.__find__(e),a=n||{};if(r===-1)throw new Error("Parser rule not found: "+e);this.__rules__.splice(r,0,{name:i,enabled:!0,fn:t,alt:a.alt||[]}),this.__cache__=null};fe.prototype.after=function(e,i,t,n){var r=this.__find__(e),a=n||{};if(r===-1)throw new Error("Parser rule not found: "+e);this.__rules__.splice(r+1,0,{name:i,enabled:!0,fn:t,alt:a.alt||[]}),this.__cache__=null};fe.prototype.push=function(e,i,t){var n=t||{};this.__rules__.push({name:e,enabled:!0,fn:i,alt:n.alt||[]}),this.__cache__=null};fe.prototype.enable=function(e,i){e=Array.isArray(e)?e:[e],i&&this.__rules__.forEach(function(t){t.enabled=!1}),e.forEach(function(t){var n=this.__find__(t);if(n<0)throw new Error("Rules manager: invalid rule name "+t);this.__rules__[n].enabled=!0},this),this.__cache__=null};fe.prototype.disable=function(e){e=Array.isArray(e)?e:[e],e.forEach(function(i){var t=this.__find__(i);if(t<0)throw new Error("Rules manager: invalid rule name "+i);this.__rules__[t].enabled=!1},this),this.__cache__=null};fe.prototype.getRules=function(e){return this.__cache__===null&&this.__compile__(),this.__cache__[e]||[]};function pa(e){e.inlineMode?e.tokens.push({type:"inline",content:e.src.replace(/\n/g," ").trim(),level:0,lines:[0,1],children:[]}):e.block.parse(e.src,e.options,e.env,e.tokens)}function Fe(e,i,t,n,r){this.src=e,this.env=n,this.options=t,this.parser=i,this.tokens=r,this.pos=0,this.posMax=this.src.length,this.level=0,this.pending="",this.pendingLevel=0,this.cache=[],this.isInLabel=!1,this.linkLevel=0,this.linkContent="",this.labelUnmatchedScopes=0}Fe.prototype.pushPending=function(){this.tokens.push({type:"text",content:this.pending,level:this.pendingLevel}),this.pending=""};Fe.prototype.push=function(e){this.pending&&this.pushPending(),this.tokens.push(e),this.pendingLevel=this.level};Fe.prototype.cacheSet=function(e,i){for(var t=this.cache.length;t<=e;t++)this.cache.push(0);this.cache[e]=i};Fe.prototype.cacheGet=function(e){return e<this.cache.length?this.cache[e]:0};function nt(e,i){var t,n,r,a=-1,o=e.posMax,s=e.pos,l=e.isInLabel;if(e.isInLabel)return-1;if(e.labelUnmatchedScopes)return e.labelUnmatchedScopes--,-1;for(e.pos=i+1,e.isInLabel=!0,t=1;e.pos<o;){if(r=e.src.charCodeAt(e.pos),r===91)t++;else if(r===93&&(t--,t===0)){n=!0;break}e.parser.skipToken(e)}return n?(a=e.pos,e.labelUnmatchedScopes=0):e.labelUnmatchedScopes=t-1,e.pos=s,e.isInLabel=l,a}function fa(e,i,t,n){var r,a,o,s,l,u;if(e.charCodeAt(0)!==42||e.charCodeAt(1)!==91||e.indexOf("]:")===-1||(r=new Fe(e,i,t,n,[]),a=nt(r,1),a<0||e.charCodeAt(a+1)!==58))return-1;for(s=r.posMax,o=a+2;o<s&&r.src.charCodeAt(o)!==10;o++);return l=e.slice(2,a),u=e.slice(a+2,o).trim(),u.length===0?-1:(n.abbreviations||(n.abbreviations={}),typeof n.abbreviations[":"+l]>"u"&&(n.abbreviations[":"+l]=u),o)}function va(e){var i=e.tokens,t,n,r,a;if(!e.inlineMode){for(t=1,n=i.length-1;t<n;t++)if(i[t-1].type==="paragraph_open"&&i[t].type==="inline"&&i[t+1].type==="paragraph_close"){for(r=i[t].content;r.length&&(a=fa(r,e.inline,e.options,e.env),!(a<0));)r=r.slice(a).trim();i[t].content=r,r.length||(i[t-1].tight=!0,i[t+1].tight=!0)}}}function kn(e){var i=Le(e);try{i=decodeURI(i)}catch{}return encodeURI(i)}function ni(e,i){var t,n,r,a=i,o=e.posMax;if(e.src.charCodeAt(i)===60){for(i++;i<o;){if(t=e.src.charCodeAt(i),t===10)return!1;if(t===62)return r=kn(tt(e.src.slice(a+1,i))),e.parser.validateLink(r)?(e.pos=i+1,e.linkContent=r,!0):!1;if(t===92&&i+1<o){i+=2;continue}i++}return!1}for(n=0;i<o&&(t=e.src.charCodeAt(i),!(t===32||t<32||t===127));){if(t===92&&i+1<o){i+=2;continue}if(t===40&&(n++,n>1)||t===41&&(n--,n<0))break;i++}return a===i||(r=tt(e.src.slice(a,i)),!e.parser.validateLink(r))?!1:(e.linkContent=r,e.pos=i,!0)}function ri(e,i){var t,n=i,r=e.posMax,a=e.src.charCodeAt(i);if(a!==34&&a!==39&&a!==40)return!1;for(i++,a===40&&(a=41);i<r;){if(t=e.src.charCodeAt(i),t===a)return e.pos=i+1,e.linkContent=tt(e.src.slice(n+1,i)),!0;if(t===92&&i+1<r){i+=2;continue}i++}return!1}function ii(e){return e.trim().replace(/\s+/g," ").toUpperCase()}function ma(e,i,t,n){var r,a,o,s,l,u,c,d,h;if(e.charCodeAt(0)!==91||e.indexOf("]:")===-1||(r=new Fe(e,i,t,n,[]),a=nt(r,0),a<0||e.charCodeAt(a+1)!==58))return-1;for(s=r.posMax,o=a+2;o<s&&(l=r.src.charCodeAt(o),!(l!==32&&l!==10));o++);if(!ni(r,o))return-1;for(c=r.linkContent,o=r.pos,u=o,o=o+1;o<s&&(l=r.src.charCodeAt(o),!(l!==32&&l!==10));o++);for(o<s&&u!==o&&ri(r,o)?(d=r.linkContent,o=r.pos):(d="",o=u);o<s&&r.src.charCodeAt(o)===32;)o++;return o<s&&r.src.charCodeAt(o)!==10?-1:(h=ii(e.slice(1,a)),typeof n.references[h]>"u"&&(n.references[h]={title:d,href:c}),o)}function ga(e){var i=e.tokens,t,n,r,a;if(e.env.references=e.env.references||{},!e.inlineMode){for(t=1,n=i.length-1;t<n;t++)if(i[t].type==="inline"&&i[t-1].type==="paragraph_open"&&i[t+1].type==="paragraph_close"){for(r=i[t].content;r.length&&(a=ma(r,e.inline,e.options,e.env),!(a<0));)r=r.slice(a).trim();i[t].content=r,r.length||(i[t-1].tight=!0,i[t+1].tight=!0)}}}function ya(e){var i=e.tokens,t,n,r;for(n=0,r=i.length;n<r;n++)t=i[n],t.type==="inline"&&e.inline.parse(t.content,e.options,e.env,t.children)}function ba(e){var i,t,n,r,a,o,s,l,u,c=0,d=!1,h={};if(e.env.footnotes&&(e.tokens=e.tokens.filter(function(p){return p.type==="footnote_reference_open"?(d=!0,l=[],u=p.label,!1):p.type==="footnote_reference_close"?(d=!1,h[":"+u]=l,!1):(d&&l.push(p),!d)}),!!e.env.footnotes.list)){for(o=e.env.footnotes.list,e.tokens.push({type:"footnote_block_open",level:c++}),i=0,t=o.length;i<t;i++){for(e.tokens.push({type:"footnote_open",id:i,level:c++}),o[i].tokens?(s=[],s.push({type:"paragraph_open",tight:!1,level:c++}),s.push({type:"inline",content:"",level:c,children:o[i].tokens}),s.push({type:"paragraph_close",tight:!1,level:--c})):o[i].label&&(s=h[":"+o[i].label]),e.tokens=e.tokens.concat(s),e.tokens[e.tokens.length-1].type==="paragraph_close"?a=e.tokens.pop():a=null,r=o[i].count>0?o[i].count:1,n=0;n<r;n++)e.tokens.push({type:"footnote_anchor",id:i,subId:n,level:c});a&&e.tokens.push(a),e.tokens.push({type:"footnote_close",level:--c})}e.tokens.push({type:"footnote_block_close",level:--c})}}var Jn=` 
()[]'".,!?-`;function tn(e){return e.replace(/([-()\[\]{}+?*.$\^|,:#<!\\])/g,"\\$1")}function ka(e){var i,t,n,r,a,o,s,l,u,c,d,h,p=e.tokens;if(e.env.abbreviations){for(e.env.abbrRegExp||(h="(^|["+Jn.split("").map(tn).join("")+"])("+Object.keys(e.env.abbreviations).map(function(v){return v.substr(1)}).sort(function(v,m){return m.length-v.length}).map(tn).join("|")+")($|["+Jn.split("").map(tn).join("")+"])",e.env.abbrRegExp=new RegExp(h,"g")),c=e.env.abbrRegExp,t=0,n=p.length;t<n;t++)if(p[t].type==="inline"){for(r=p[t].children,i=r.length-1;i>=0;i--)if(a=r[i],a.type==="text"){for(l=0,o=a.content,c.lastIndex=0,u=a.level,s=[];d=c.exec(o);)c.lastIndex>l&&s.push({type:"text",content:o.slice(l,d.index+d[1].length),level:u}),s.push({type:"abbr_open",title:e.env.abbreviations[":"+d[2]],level:u++}),s.push({type:"text",content:d[2],level:u}),s.push({type:"abbr_close",level:--u}),l=c.lastIndex-d[3].length;s.length&&(l<o.length&&s.push({type:"text",content:o.slice(l),level:u}),p[t].children=r=[].concat(r.slice(0,i),s,r.slice(i+1)))}}}}var _a=/\+-|\.\.|\?\?\?\?|!!!!|,,|--/,wa=/\((c|tm|r|p)\)/ig,Sa={c:"©",r:"®",p:"§",tm:"™"};function xa(e){return e.indexOf("(")<0?e:e.replace(wa,function(i,t){return Sa[t.toLowerCase()]})}function Ea(e){var i,t,n,r,a;if(e.options.typographer){for(a=e.tokens.length-1;a>=0;a--)if(e.tokens[a].type==="inline")for(r=e.tokens[a].children,i=r.length-1;i>=0;i--)t=r[i],t.type==="text"&&(n=t.content,n=xa(n),_a.test(n)&&(n=n.replace(/\+-/g,"±").replace(/\.{2,}/g,"…").replace(/([?!])…/g,"$1..").replace(/([?!]){4,}/g,"$1$1$1").replace(/,{2,}/g,",").replace(/(^|[^-])---([^-]|$)/mg,"$1—$2").replace(/(^|\s)--(\s|$)/mg,"$1–$2").replace(/(^|[^-\s])--([^-\s]|$)/mg,"$1–$2")),t.content=n)}}var Ca=/['"]/,Zn=/['"]/g,Ma=/[-\s()\[\]]/,Xn="’";function Qn(e,i){return i<0||i>=e.length?!1:!Ma.test(e[i])}function Ge(e,i,t){return e.substr(0,i)+t+e.substr(i+1)}function Aa(e){var i,t,n,r,a,o,s,l,u,c,d,h,p,v,m,b,w;if(e.options.typographer){for(w=[],m=e.tokens.length-1;m>=0;m--)if(e.tokens[m].type==="inline"){for(b=e.tokens[m].children,w.length=0,i=0;i<b.length;i++)if(t=b[i],!(t.type!=="text"||Ca.test(t.text))){for(s=b[i].level,p=w.length-1;p>=0&&!(w[p].level<=s);p--);w.length=p+1,n=t.content,a=0,o=n.length;e:for(;a<o&&(Zn.lastIndex=a,r=Zn.exec(n),!!r);){if(l=!Qn(n,r.index-1),a=r.index+1,v=r[0]==="'",u=!Qn(n,a),!u&&!l){v&&(t.content=Ge(t.content,r.index,Xn));continue}if(d=!u,h=!l,h){for(p=w.length-1;p>=0&&(c=w[p],!(w[p].level<s));p--)if(c.single===v&&w[p].level===s){c=w[p],v?(b[c.token].content=Ge(b[c.token].content,c.pos,e.options.quotes[2]),t.content=Ge(t.content,r.index,e.options.quotes[3])):(b[c.token].content=Ge(b[c.token].content,c.pos,e.options.quotes[0]),t.content=Ge(t.content,r.index,e.options.quotes[1])),w.length=p;continue e}}d?w.push({token:i,pos:r.index,single:v,level:s}):h&&v&&(t.content=Ge(t.content,r.index,Xn))}}}}}var nn=[["block",pa],["abbr",va],["references",ga],["inline",ya],["footnote_tail",ba],["abbr2",ka],["replacements",Ea],["smartquotes",Aa]];function ai(){this.options={},this.ruler=new fe;for(var e=0;e<nn.length;e++)this.ruler.push(nn[e][0],nn[e][1])}ai.prototype.process=function(e){var i,t,n;for(n=this.ruler.getRules(""),i=0,t=n.length;i<t;i++)n[i](e)};function je(e,i,t,n,r){var a,o,s,l,u,c,d;for(this.src=e,this.parser=i,this.options=t,this.env=n,this.tokens=r,this.bMarks=[],this.eMarks=[],this.tShift=[],this.blkIndent=0,this.line=0,this.lineMax=0,this.tight=!1,this.parentType="root",this.ddIndent=-1,this.level=0,this.result="",o=this.src,c=0,d=!1,s=l=c=0,u=o.length;l<u;l++){if(a=o.charCodeAt(l),!d)if(a===32){c++;continue}else d=!0;(a===10||l===u-1)&&(a!==10&&l++,this.bMarks.push(s),this.eMarks.push(l),this.tShift.push(c),d=!1,c=0,s=l+1)}this.bMarks.push(o.length),this.eMarks.push(o.length),this.tShift.push(0),this.lineMax=this.bMarks.length-1}je.prototype.isEmpty=function(i){return this.bMarks[i]+this.tShift[i]>=this.eMarks[i]};je.prototype.skipEmptyLines=function(i){for(var t=this.lineMax;i<t&&!(this.bMarks[i]+this.tShift[i]<this.eMarks[i]);i++);return i};je.prototype.skipSpaces=function(i){for(var t=this.src.length;i<t&&this.src.charCodeAt(i)===32;i++);return i};je.prototype.skipChars=function(i,t){for(var n=this.src.length;i<n&&this.src.charCodeAt(i)===t;i++);return i};je.prototype.skipCharsBack=function(i,t,n){if(i<=n)return i;for(;i>n;)if(t!==this.src.charCodeAt(--i))return i+1;return i};je.prototype.getLines=function(i,t,n,r){var a,o,s,l,u,c=i;if(i>=t)return"";if(c+1===t)return o=this.bMarks[c]+Math.min(this.tShift[c],n),s=r?this.eMarks[c]+1:this.eMarks[c],this.src.slice(o,s);for(l=new Array(t-i),a=0;c<t;c++,a++)u=this.tShift[c],u>n&&(u=n),u<0&&(u=0),o=this.bMarks[c]+u,c+1<t||r?s=this.eMarks[c]+1:s=this.eMarks[c],l[a]=this.src.slice(o,s);return l.join("")};function Ta(e,i,t){var n,r;if(e.tShift[i]-e.blkIndent<4)return!1;for(r=n=i+1;n<t;){if(e.isEmpty(n)){n++;continue}if(e.tShift[n]-e.blkIndent>=4){n++,r=n;continue}break}return e.line=n,e.tokens.push({type:"code",content:e.getLines(i,r,4+e.blkIndent,!0),block:!0,lines:[i,e.line],level:e.level}),!0}function Ia(e,i,t,n){var r,a,o,s,l,u=!1,c=e.bMarks[i]+e.tShift[i],d=e.eMarks[i];if(c+3>d||(r=e.src.charCodeAt(c),r!==126&&r!==96)||(l=c,c=e.skipChars(c,r),a=c-l,a<3)||(o=e.src.slice(c,d).trim(),o.indexOf("`")>=0))return!1;if(n)return!0;for(s=i;s++,!(s>=t||(c=l=e.bMarks[s]+e.tShift[s],d=e.eMarks[s],c<d&&e.tShift[s]<e.blkIndent));)if(e.src.charCodeAt(c)===r&&!(e.tShift[s]-e.blkIndent>=4)&&(c=e.skipChars(c,r),!(c-l<a)&&(c=e.skipSpaces(c),!(c<d)))){u=!0;break}return a=e.tShift[i],e.line=s+(u?1:0),e.tokens.push({type:"fence",params:o,content:e.getLines(i+1,s,a,!0),lines:[i,e.line],level:e.level}),!0}function La(e,i,t,n){var r,a,o,s,l,u,c,d,h,p,v,m=e.bMarks[i]+e.tShift[i],b=e.eMarks[i];if(m>b||e.src.charCodeAt(m++)!==62||e.level>=e.options.maxNesting)return!1;if(n)return!0;for(e.src.charCodeAt(m)===32&&m++,l=e.blkIndent,e.blkIndent=0,s=[e.bMarks[i]],e.bMarks[i]=m,m=m<b?e.skipSpaces(m):m,a=m>=b,o=[e.tShift[i]],e.tShift[i]=m-e.bMarks[i],d=e.parser.ruler.getRules("blockquote"),r=i+1;r<t&&(m=e.bMarks[r]+e.tShift[r],b=e.eMarks[r],!(m>=b));r++){if(e.src.charCodeAt(m++)===62){e.src.charCodeAt(m)===32&&m++,s.push(e.bMarks[r]),e.bMarks[r]=m,m=m<b?e.skipSpaces(m):m,a=m>=b,o.push(e.tShift[r]),e.tShift[r]=m-e.bMarks[r];continue}if(a)break;for(v=!1,h=0,p=d.length;h<p;h++)if(d[h](e,r,t,!0)){v=!0;break}if(v)break;s.push(e.bMarks[r]),o.push(e.tShift[r]),e.tShift[r]=-1337}for(u=e.parentType,e.parentType="blockquote",e.tokens.push({type:"blockquote_open",lines:c=[i,0],level:e.level++}),e.parser.tokenize(e,i,r),e.tokens.push({type:"blockquote_close",level:--e.level}),e.parentType=u,c[1]=e.line,h=0;h<o.length;h++)e.bMarks[h+i]=s[h],e.tShift[h+i]=o[h];return e.blkIndent=l,!0}function Ra(e,i,t,n){var r,a,o,s=e.bMarks[i],l=e.eMarks[i];if(s+=e.tShift[i],s>l||(r=e.src.charCodeAt(s++),r!==42&&r!==45&&r!==95))return!1;for(a=1;s<l;){if(o=e.src.charCodeAt(s++),o!==r&&o!==32)return!1;o===r&&a++}return a<3?!1:(n||(e.line=i+1,e.tokens.push({type:"hr",lines:[i,e.line],level:e.level})),!0)}function er(e,i){var t,n,r;return n=e.bMarks[i]+e.tShift[i],r=e.eMarks[i],n>=r||(t=e.src.charCodeAt(n++),t!==42&&t!==45&&t!==43)||n<r&&e.src.charCodeAt(n)!==32?-1:n}function tr(e,i){var t,n=e.bMarks[i]+e.tShift[i],r=e.eMarks[i];if(n+1>=r||(t=e.src.charCodeAt(n++),t<48||t>57))return-1;for(;;){if(n>=r)return-1;if(t=e.src.charCodeAt(n++),!(t>=48&&t<=57)){if(t===41||t===46)break;return-1}}return n<r&&e.src.charCodeAt(n)!==32?-1:n}function Oa(e,i){var t,n,r=e.level+2;for(t=i+2,n=e.tokens.length-2;t<n;t++)e.tokens[t].level===r&&e.tokens[t].type==="paragraph_open"&&(e.tokens[t+2].tight=!0,e.tokens[t].tight=!0,t+=2)}function Pa(e,i,t,n){var r,a,o,s,l,u,c,d,h,p,v,m,b,w,_,x,N,M,j=!0,G,H,Z,te;if((d=tr(e,i))>=0)b=!0;else if((d=er(e,i))>=0)b=!1;else return!1;if(e.level>=e.options.maxNesting)return!1;if(m=e.src.charCodeAt(d-1),n)return!0;for(_=e.tokens.length,b?(c=e.bMarks[i]+e.tShift[i],v=Number(e.src.substr(c,d-c-1)),e.tokens.push({type:"ordered_list_open",order:v,lines:N=[i,0],level:e.level++})):e.tokens.push({type:"bullet_list_open",lines:N=[i,0],level:e.level++}),r=i,x=!1,G=e.parser.ruler.getRules("list");r<t&&(w=e.skipSpaces(d),h=e.eMarks[r],w>=h?p=1:p=w-d,p>4&&(p=1),p<1&&(p=1),a=d-e.bMarks[r]+p,e.tokens.push({type:"list_item_open",lines:M=[i,0],level:e.level++}),s=e.blkIndent,l=e.tight,o=e.tShift[i],u=e.parentType,e.tShift[i]=w-e.bMarks[i],e.blkIndent=a,e.tight=!0,e.parentType="list",e.parser.tokenize(e,i,t,!0),(!e.tight||x)&&(j=!1),x=e.line-i>1&&e.isEmpty(e.line-1),e.blkIndent=s,e.tShift[i]=o,e.tight=l,e.parentType=u,e.tokens.push({type:"list_item_close",level:--e.level}),r=i=e.line,M[1]=r,w=e.bMarks[i],!(r>=t||e.isEmpty(r)||e.tShift[r]<e.blkIndent));){for(te=!1,H=0,Z=G.length;H<Z;H++)if(G[H](e,r,t,!0)){te=!0;break}if(te)break;if(b){if(d=tr(e,r),d<0)break}else if(d=er(e,r),d<0)break;if(m!==e.src.charCodeAt(d-1))break}return e.tokens.push({type:b?"ordered_list_close":"bullet_list_close",level:--e.level}),N[1]=r,e.line=r,j&&Oa(e,_),!0}function Na(e,i,t,n){var r,a,o,s,l,u=e.bMarks[i]+e.tShift[i],c=e.eMarks[i];if(u+4>c||e.src.charCodeAt(u)!==91||e.src.charCodeAt(u+1)!==94||e.level>=e.options.maxNesting)return!1;for(s=u+2;s<c;s++){if(e.src.charCodeAt(s)===32)return!1;if(e.src.charCodeAt(s)===93)break}return s===u+2||s+1>=c||e.src.charCodeAt(++s)!==58?!1:(n||(s++,e.env.footnotes||(e.env.footnotes={}),e.env.footnotes.refs||(e.env.footnotes.refs={}),l=e.src.slice(u+2,s-2),e.env.footnotes.refs[":"+l]=-1,e.tokens.push({type:"footnote_reference_open",label:l,level:e.level++}),r=e.bMarks[i],a=e.tShift[i],o=e.parentType,e.tShift[i]=e.skipSpaces(s)-s,e.bMarks[i]=s,e.blkIndent+=4,e.parentType="footnote",e.tShift[i]<e.blkIndent&&(e.tShift[i]+=e.blkIndent,e.bMarks[i]-=e.blkIndent),e.parser.tokenize(e,i,t,!0),e.parentType=o,e.blkIndent-=4,e.tShift[i]=a,e.bMarks[i]=r,e.tokens.push({type:"footnote_reference_close",level:--e.level})),!0)}function Da(e,i,t,n){var r,a,o,s=e.bMarks[i]+e.tShift[i],l=e.eMarks[i];if(s>=l||(r=e.src.charCodeAt(s),r!==35||s>=l))return!1;for(a=1,r=e.src.charCodeAt(++s);r===35&&s<l&&a<=6;)a++,r=e.src.charCodeAt(++s);return a>6||s<l&&r!==32?!1:(n||(l=e.skipCharsBack(l,32,s),o=e.skipCharsBack(l,35,s),o>s&&e.src.charCodeAt(o-1)===32&&(l=o),e.line=i+1,e.tokens.push({type:"heading_open",hLevel:a,lines:[i,e.line],level:e.level}),s<l&&e.tokens.push({type:"inline",content:e.src.slice(s,l).trim(),level:e.level+1,lines:[i,e.line],children:[]}),e.tokens.push({type:"heading_close",hLevel:a,level:e.level})),!0)}function Fa(e,i,t){var n,r,a,o=i+1;return o>=t||e.tShift[o]<e.blkIndent||e.tShift[o]-e.blkIndent>3||(r=e.bMarks[o]+e.tShift[o],a=e.eMarks[o],r>=a)||(n=e.src.charCodeAt(r),n!==45&&n!==61)||(r=e.skipChars(r,n),r=e.skipSpaces(r),r<a)?!1:(r=e.bMarks[i]+e.tShift[i],e.line=o+1,e.tokens.push({type:"heading_open",hLevel:n===61?1:2,lines:[i,e.line],level:e.level}),e.tokens.push({type:"inline",content:e.src.slice(r,e.eMarks[i]).trim(),level:e.level+1,lines:[i,e.line-1],children:[]}),e.tokens.push({type:"heading_close",hLevel:n===61?1:2,level:e.level}),!0)}var oi={};["article","aside","button","blockquote","body","canvas","caption","col","colgroup","dd","div","dl","dt","embed","fieldset","figcaption","figure","footer","form","h1","h2","h3","h4","h5","h6","header","hgroup","hr","iframe","li","map","object","ol","output","p","pre","progress","script","section","style","table","tbody","td","textarea","tfoot","th","tr","thead","ul","video"].forEach(function(e){oi[e]=!0});var ja=/^<([a-zA-Z]{1,15})[\s\/>]/,Ba=/^<\/([a-zA-Z]{1,15})[\s>]/;function qa(e){var i=e|32;return i>=97&&i<=122}function za(e,i,t,n){var r,a,o,s=e.bMarks[i],l=e.eMarks[i],u=e.tShift[i];if(s+=u,!e.options.html||u>3||s+2>=l||e.src.charCodeAt(s)!==60)return!1;if(r=e.src.charCodeAt(s+1),r===33||r===63){if(n)return!0}else if(r===47||qa(r)){if(r===47){if(a=e.src.slice(s,l).match(Ba),!a)return!1}else if(a=e.src.slice(s,l).match(ja),!a)return!1;if(oi[a[1].toLowerCase()]!==!0)return!1;if(n)return!0}else return!1;for(o=i+1;o<e.lineMax&&!e.isEmpty(o);)o++;return e.line=o,e.tokens.push({type:"htmlblock",level:e.level,lines:[i,e.line],content:e.getLines(i,o,0,!0)}),!0}function rn(e,i){var t=e.bMarks[i]+e.blkIndent,n=e.eMarks[i];return e.src.substr(t,n-t)}function Ua(e,i,t,n){var r,a,o,s,l,u,c,d,h,p,v;if(i+2>t||(l=i+1,e.tShift[l]<e.blkIndent)||(o=e.bMarks[l]+e.tShift[l],o>=e.eMarks[l])||(r=e.src.charCodeAt(o),r!==124&&r!==45&&r!==58)||(a=rn(e,i+1),!/^[-:| ]+$/.test(a))||(u=a.split("|"),u<=2))return!1;for(d=[],s=0;s<u.length;s++){if(h=u[s].trim(),!h){if(s===0||s===u.length-1)continue;return!1}if(!/^:?-+:?$/.test(h))return!1;h.charCodeAt(h.length-1)===58?d.push(h.charCodeAt(0)===58?"center":"right"):h.charCodeAt(0)===58?d.push("left"):d.push("")}if(a=rn(e,i).trim(),a.indexOf("|")===-1||(u=a.replace(/^\||\|$/g,"").split("|"),d.length!==u.length))return!1;if(n)return!0;for(e.tokens.push({type:"table_open",lines:p=[i,0],level:e.level++}),e.tokens.push({type:"thead_open",lines:[i,i+1],level:e.level++}),e.tokens.push({type:"tr_open",lines:[i,i+1],level:e.level++}),s=0;s<u.length;s++)e.tokens.push({type:"th_open",align:d[s],lines:[i,i+1],level:e.level++}),e.tokens.push({type:"inline",content:u[s].trim(),lines:[i,i+1],level:e.level,children:[]}),e.tokens.push({type:"th_close",level:--e.level});for(e.tokens.push({type:"tr_close",level:--e.level}),e.tokens.push({type:"thead_close",level:--e.level}),e.tokens.push({type:"tbody_open",lines:v=[i+2,0],level:e.level++}),l=i+2;l<t&&!(e.tShift[l]<e.blkIndent||(a=rn(e,l).trim(),a.indexOf("|")===-1));l++){for(u=a.replace(/^\||\|$/g,"").split("|"),e.tokens.push({type:"tr_open",level:e.level++}),s=0;s<u.length;s++)e.tokens.push({type:"td_open",align:d[s],level:e.level++}),c=u[s].substring(u[s].charCodeAt(0)===124?1:0,u[s].charCodeAt(u[s].length-1)===124?u[s].length-1:u[s].length).trim(),e.tokens.push({type:"inline",content:c,level:e.level,children:[]}),e.tokens.push({type:"td_close",level:--e.level});e.tokens.push({type:"tr_close",level:--e.level})}return e.tokens.push({type:"tbody_close",level:--e.level}),e.tokens.push({type:"table_close",level:--e.level}),p[1]=v[1]=l,e.line=l,!0}function yt(e,i){var t,n,r=e.bMarks[i]+e.tShift[i],a=e.eMarks[i];return r>=a||(n=e.src.charCodeAt(r++),n!==126&&n!==58)||(t=e.skipSpaces(r),r===t)||t>=a?-1:t}function Ha(e,i){var t,n,r=e.level+2;for(t=i+2,n=e.tokens.length-2;t<n;t++)e.tokens[t].level===r&&e.tokens[t].type==="paragraph_open"&&(e.tokens[t+2].tight=!0,e.tokens[t].tight=!0,t+=2)}function Va(e,i,t,n){var r,a,o,s,l,u,c,d,h,p,v,m,b,w;if(n)return e.ddIndent<0?!1:yt(e,i)>=0;if(c=i+1,e.isEmpty(c)&&++c>t||e.tShift[c]<e.blkIndent||(r=yt(e,c),r<0)||e.level>=e.options.maxNesting)return!1;u=e.tokens.length,e.tokens.push({type:"dl_open",lines:l=[i,0],level:e.level++}),o=i,a=c;e:for(;;){for(w=!0,b=!1,e.tokens.push({type:"dt_open",lines:[o,o],level:e.level++}),e.tokens.push({type:"inline",content:e.getLines(o,o+1,e.blkIndent,!1).trim(),level:e.level+1,lines:[o,o],children:[]}),e.tokens.push({type:"dt_close",level:--e.level});;){if(e.tokens.push({type:"dd_open",lines:s=[c,0],level:e.level++}),m=e.tight,h=e.ddIndent,d=e.blkIndent,v=e.tShift[a],p=e.parentType,e.blkIndent=e.ddIndent=e.tShift[a]+2,e.tShift[a]=r-e.bMarks[a],e.tight=!0,e.parentType="deflist",e.parser.tokenize(e,a,t,!0),(!e.tight||b)&&(w=!1),b=e.line-a>1&&e.isEmpty(e.line-1),e.tShift[a]=v,e.tight=m,e.parentType=p,e.blkIndent=d,e.ddIndent=h,e.tokens.push({type:"dd_close",level:--e.level}),s[1]=c=e.line,c>=t||e.tShift[c]<e.blkIndent)break e;if(r=yt(e,c),r<0)break;a=c}if(c>=t||(o=c,e.isEmpty(o))||e.tShift[o]<e.blkIndent||(a=o+1,a>=t)||(e.isEmpty(a)&&a++,a>=t)||e.tShift[a]<e.blkIndent||(r=yt(e,a),r<0))break}return e.tokens.push({type:"dl_close",level:--e.level}),l[1]=c,e.line=c,w&&Ha(e,u),!0}function $a(e,i){var t,n,r,a,o,s=i+1,l;if(t=e.lineMax,s<t&&!e.isEmpty(s)){for(l=e.parser.ruler.getRules("paragraph");s<t&&!e.isEmpty(s);s++)if(!(e.tShift[s]-e.blkIndent>3)){for(r=!1,a=0,o=l.length;a<o;a++)if(l[a](e,s,t,!0)){r=!0;break}if(r)break}}return n=e.getLines(i,s,e.blkIndent,!1).trim(),e.line=s,n.length&&(e.tokens.push({type:"paragraph_open",tight:!1,lines:[i,e.line],level:e.level}),e.tokens.push({type:"inline",content:n,level:e.level+1,lines:[i,e.line],children:[]}),e.tokens.push({type:"paragraph_close",tight:!1,level:e.level})),!0}var bt=[["code",Ta],["fences",Ia,["paragraph","blockquote","list"]],["blockquote",La,["paragraph","blockquote","list"]],["hr",Ra,["paragraph","blockquote","list"]],["list",Pa,["paragraph","blockquote"]],["footnote",Na,["paragraph"]],["heading",Da,["paragraph","blockquote"]],["lheading",Fa],["htmlblock",za,["paragraph","blockquote"]],["table",Ua,["paragraph"]],["deflist",Va,["paragraph"]],["paragraph",$a]];function Rn(){this.ruler=new fe;for(var e=0;e<bt.length;e++)this.ruler.push(bt[e][0],bt[e][1],{alt:(bt[e][2]||[]).slice()})}Rn.prototype.tokenize=function(e,i,t){for(var n=this.ruler.getRules(""),r=n.length,a=i,o=!1,s,l;a<t&&(e.line=a=e.skipEmptyLines(a),!(a>=t||e.tShift[a]<e.blkIndent));){for(l=0;l<r&&(s=n[l](e,a,t,!1),!s);l++);if(e.tight=!o,e.isEmpty(e.line-1)&&(o=!0),a=e.line,a<t&&e.isEmpty(a)){if(o=!0,a++,a<t&&e.parentType==="list"&&e.isEmpty(a))break;e.line=a}}};var Ga=/[\n\t]/g,Wa=/\r[\n\u0085]|[\u2424\u2028\u0085]/g,Ka=/\u00a0/g;Rn.prototype.parse=function(e,i,t,n){var r,a=0,o=0;if(!e)return[];e=e.replace(Ka," "),e=e.replace(Wa,`
`),e.indexOf("	")>=0&&(e=e.replace(Ga,function(s,l){var u;return e.charCodeAt(l)===10?(a=l+1,o=0,s):(u="    ".slice((l-a-o)%4),o=l-a+1,u)})),r=new je(e,this,i,t,n),this.tokenize(r,r.line,r.lineMax)};function Ya(e){switch(e){case 10:case 92:case 96:case 42:case 95:case 94:case 91:case 93:case 33:case 38:case 60:case 62:case 123:case 125:case 36:case 37:case 64:case 126:case 43:case 61:case 58:return!0;default:return!1}}function Ja(e,i){for(var t=e.pos;t<e.posMax&&!Ya(e.src.charCodeAt(t));)t++;return t===e.pos?!1:(i||(e.pending+=e.src.slice(e.pos,t)),e.pos=t,!0)}function Za(e,i){var t,n,r=e.pos;if(e.src.charCodeAt(r)!==10)return!1;if(t=e.pending.length-1,n=e.posMax,!i)if(t>=0&&e.pending.charCodeAt(t)===32)if(t>=1&&e.pending.charCodeAt(t-1)===32){for(var a=t-2;a>=0;a--)if(e.pending.charCodeAt(a)!==32){e.pending=e.pending.substring(0,a+1);break}e.push({type:"hardbreak",level:e.level})}else e.pending=e.pending.slice(0,-1),e.push({type:"softbreak",level:e.level});else e.push({type:"softbreak",level:e.level});for(r++;r<n&&e.src.charCodeAt(r)===32;)r++;return e.pos=r,!0}var On=[];for(var nr=0;nr<256;nr++)On.push(0);"\\!\"#$%&'()*+,./:;<=>?@[]^_`{|}~-".split("").forEach(function(e){On[e.charCodeAt(0)]=1});function Xa(e,i){var t,n=e.pos,r=e.posMax;if(e.src.charCodeAt(n)!==92)return!1;if(n++,n<r){if(t=e.src.charCodeAt(n),t<256&&On[t]!==0)return i||(e.pending+=e.src[n]),e.pos+=2,!0;if(t===10){for(i||e.push({type:"hardbreak",level:e.level}),n++;n<r&&e.src.charCodeAt(n)===32;)n++;return e.pos=n,!0}}return i||(e.pending+="\\"),e.pos++,!0}function Qa(e,i){var t,n,r,a,o,s=e.pos,l=e.src.charCodeAt(s);if(l!==96)return!1;for(t=s,s++,n=e.posMax;s<n&&e.src.charCodeAt(s)===96;)s++;for(r=e.src.slice(t,s),a=o=s;(a=e.src.indexOf("`",o))!==-1;){for(o=a+1;o<n&&e.src.charCodeAt(o)===96;)o++;if(o-a===r.length)return i||e.push({type:"code",content:e.src.slice(s,a).replace(/[ \n]+/g," ").trim(),block:!1,level:e.level}),e.pos=o,!0}return i||(e.pending+=r),e.pos+=r.length,!0}function eo(e,i){var t,n,r,a=e.posMax,o=e.pos,s,l;if(e.src.charCodeAt(o)!==126||i||o+4>=a||e.src.charCodeAt(o+1)!==126||e.level>=e.options.maxNesting||(s=o>0?e.src.charCodeAt(o-1):-1,l=e.src.charCodeAt(o+2),s===126)||l===126||l===32||l===10)return!1;for(n=o+2;n<a&&e.src.charCodeAt(n)===126;)n++;if(n>o+3)return e.pos+=n-o,i||(e.pending+=e.src.slice(o,n)),!0;for(e.pos=o+2,r=1;e.pos+1<a;){if(e.src.charCodeAt(e.pos)===126&&e.src.charCodeAt(e.pos+1)===126&&(s=e.src.charCodeAt(e.pos-1),l=e.pos+2<a?e.src.charCodeAt(e.pos+2):-1,l!==126&&s!==126&&(s!==32&&s!==10?r--:l!==32&&l!==10&&r++,r<=0))){t=!0;break}e.parser.skipToken(e)}return t?(e.posMax=e.pos,e.pos=o+2,i||(e.push({type:"del_open",level:e.level++}),e.parser.tokenize(e),e.push({type:"del_close",level:--e.level})),e.pos=e.posMax+2,e.posMax=a,!0):(e.pos=o,!1)}function to(e,i){var t,n,r,a=e.posMax,o=e.pos,s,l;if(e.src.charCodeAt(o)!==43||i||o+4>=a||e.src.charCodeAt(o+1)!==43||e.level>=e.options.maxNesting||(s=o>0?e.src.charCodeAt(o-1):-1,l=e.src.charCodeAt(o+2),s===43)||l===43||l===32||l===10)return!1;for(n=o+2;n<a&&e.src.charCodeAt(n)===43;)n++;if(n!==o+2)return e.pos+=n-o,i||(e.pending+=e.src.slice(o,n)),!0;for(e.pos=o+2,r=1;e.pos+1<a;){if(e.src.charCodeAt(e.pos)===43&&e.src.charCodeAt(e.pos+1)===43&&(s=e.src.charCodeAt(e.pos-1),l=e.pos+2<a?e.src.charCodeAt(e.pos+2):-1,l!==43&&s!==43&&(s!==32&&s!==10?r--:l!==32&&l!==10&&r++,r<=0))){t=!0;break}e.parser.skipToken(e)}return t?(e.posMax=e.pos,e.pos=o+2,i||(e.push({type:"ins_open",level:e.level++}),e.parser.tokenize(e),e.push({type:"ins_close",level:--e.level})),e.pos=e.posMax+2,e.posMax=a,!0):(e.pos=o,!1)}function no(e,i){var t,n,r,a=e.posMax,o=e.pos,s,l;if(e.src.charCodeAt(o)!==61||i||o+4>=a||e.src.charCodeAt(o+1)!==61||e.level>=e.options.maxNesting||(s=o>0?e.src.charCodeAt(o-1):-1,l=e.src.charCodeAt(o+2),s===61)||l===61||l===32||l===10)return!1;for(n=o+2;n<a&&e.src.charCodeAt(n)===61;)n++;if(n!==o+2)return e.pos+=n-o,i||(e.pending+=e.src.slice(o,n)),!0;for(e.pos=o+2,r=1;e.pos+1<a;){if(e.src.charCodeAt(e.pos)===61&&e.src.charCodeAt(e.pos+1)===61&&(s=e.src.charCodeAt(e.pos-1),l=e.pos+2<a?e.src.charCodeAt(e.pos+2):-1,l!==61&&s!==61&&(s!==32&&s!==10?r--:l!==32&&l!==10&&r++,r<=0))){t=!0;break}e.parser.skipToken(e)}return t?(e.posMax=e.pos,e.pos=o+2,i||(e.push({type:"mark_open",level:e.level++}),e.parser.tokenize(e),e.push({type:"mark_close",level:--e.level})),e.pos=e.posMax+2,e.posMax=a,!0):(e.pos=o,!1)}function rr(e){return e>=48&&e<=57||e>=65&&e<=90||e>=97&&e<=122}function ir(e,i){var t=i,n,r,a,o=!0,s=!0,l=e.posMax,u=e.src.charCodeAt(i);for(n=i>0?e.src.charCodeAt(i-1):-1;t<l&&e.src.charCodeAt(t)===u;)t++;return t>=l&&(o=!1),a=t-i,a>=4?o=s=!1:(r=t<l?e.src.charCodeAt(t):-1,(r===32||r===10)&&(o=!1),(n===32||n===10)&&(s=!1),u===95&&(rr(n)&&(o=!1),rr(r)&&(s=!1))),{can_open:o,can_close:s,delims:a}}function ro(e,i){var t,n,r,a,o,s,l,u=e.posMax,c=e.pos,d=e.src.charCodeAt(c);if(d!==95&&d!==42||i)return!1;if(l=ir(e,c),t=l.delims,!l.can_open)return e.pos+=t,i||(e.pending+=e.src.slice(c,e.pos)),!0;if(e.level>=e.options.maxNesting)return!1;for(e.pos=c+t,s=[t];e.pos<u;){if(e.src.charCodeAt(e.pos)===d){if(l=ir(e,e.pos),n=l.delims,l.can_close){for(a=s.pop(),o=n;a!==o;){if(o<a){s.push(a-o);break}if(o-=a,s.length===0)break;e.pos+=a,a=s.pop()}if(s.length===0){t=a,r=!0;break}e.pos+=n;continue}l.can_open&&s.push(n),e.pos+=n;continue}e.parser.skipToken(e)}return r?(e.posMax=e.pos,e.pos=c+t,i||((t===2||t===3)&&e.push({type:"strong_open",level:e.level++}),(t===1||t===3)&&e.push({type:"em_open",level:e.level++}),e.parser.tokenize(e),(t===1||t===3)&&e.push({type:"em_close",level:--e.level}),(t===2||t===3)&&e.push({type:"strong_close",level:--e.level})),e.pos=e.posMax+t,e.posMax=u,!0):(e.pos=c,!1)}var io=/\\([ \\!"#$%&'()*+,.\/:;<=>?@[\]^_`{|}~-])/g;function ao(e,i){var t,n,r=e.posMax,a=e.pos;if(e.src.charCodeAt(a)!==126||i||a+2>=r||e.level>=e.options.maxNesting)return!1;for(e.pos=a+1;e.pos<r;){if(e.src.charCodeAt(e.pos)===126){t=!0;break}e.parser.skipToken(e)}return!t||a+1===e.pos||(n=e.src.slice(a+1,e.pos),n.match(/(^|[^\\])(\\\\)*\s/))?(e.pos=a,!1):(e.posMax=e.pos,e.pos=a+1,i||e.push({type:"sub",level:e.level,content:n.replace(io,"$1")}),e.pos=e.posMax+1,e.posMax=r,!0)}var oo=/\\([ \\!"#$%&'()*+,.\/:;<=>?@[\]^_`{|}~-])/g;function so(e,i){var t,n,r=e.posMax,a=e.pos;if(e.src.charCodeAt(a)!==94||i||a+2>=r||e.level>=e.options.maxNesting)return!1;for(e.pos=a+1;e.pos<r;){if(e.src.charCodeAt(e.pos)===94){t=!0;break}e.parser.skipToken(e)}return!t||a+1===e.pos||(n=e.src.slice(a+1,e.pos),n.match(/(^|[^\\])(\\\\)*\s/))?(e.pos=a,!1):(e.posMax=e.pos,e.pos=a+1,i||e.push({type:"sup",level:e.level,content:n.replace(oo,"$1")}),e.pos=e.posMax+1,e.posMax=r,!0)}function lo(e,i){var t,n,r,a,o,s,l,u,c=!1,d=e.pos,h=e.posMax,p=e.pos,v=e.src.charCodeAt(p);if(v===33&&(c=!0,v=e.src.charCodeAt(++p)),v!==91||e.level>=e.options.maxNesting||(t=p+1,n=nt(e,p),n<0))return!1;if(s=n+1,s<h&&e.src.charCodeAt(s)===40){for(s++;s<h&&(u=e.src.charCodeAt(s),!(u!==32&&u!==10));s++);if(s>=h)return!1;for(p=s,ni(e,s)?(a=e.linkContent,s=e.pos):a="",p=s;s<h&&(u=e.src.charCodeAt(s),!(u!==32&&u!==10));s++);if(s<h&&p!==s&&ri(e,s))for(o=e.linkContent,s=e.pos;s<h&&(u=e.src.charCodeAt(s),!(u!==32&&u!==10));s++);else o="";if(s>=h||e.src.charCodeAt(s)!==41)return e.pos=d,!1;s++}else{if(e.linkLevel>0)return!1;for(;s<h&&(u=e.src.charCodeAt(s),!(u!==32&&u!==10));s++);if(s<h&&e.src.charCodeAt(s)===91&&(p=s+1,s=nt(e,s),s>=0?r=e.src.slice(p,s++):s=p-1),r||(typeof r>"u"&&(s=n+1),r=e.src.slice(t,n)),l=e.env.references[ii(r)],!l)return e.pos=d,!1;a=l.href,o=l.title}return i||(e.pos=t,e.posMax=n,c?e.push({type:"image",src:a,title:o,alt:e.src.substr(t,n-t),level:e.level}):(e.push({type:"link_open",href:a,title:o,level:e.level++}),e.linkLevel++,e.parser.tokenize(e),e.linkLevel--,e.push({type:"link_close",level:--e.level}))),e.pos=s,e.posMax=h,!0}function uo(e,i){var t,n,r,a,o=e.posMax,s=e.pos;return s+2>=o||e.src.charCodeAt(s)!==94||e.src.charCodeAt(s+1)!==91||e.level>=e.options.maxNesting||(t=s+2,n=nt(e,s+1),n<0)?!1:(i||(e.env.footnotes||(e.env.footnotes={}),e.env.footnotes.list||(e.env.footnotes.list=[]),r=e.env.footnotes.list.length,e.pos=t,e.posMax=n,e.push({type:"footnote_ref",id:r,level:e.level}),e.linkLevel++,a=e.tokens.length,e.parser.tokenize(e),e.env.footnotes.list[r]={tokens:e.tokens.splice(a)},e.linkLevel--),e.pos=n+1,e.posMax=o,!0)}function co(e,i){var t,n,r,a,o=e.posMax,s=e.pos;if(s+3>o||!e.env.footnotes||!e.env.footnotes.refs||e.src.charCodeAt(s)!==91||e.src.charCodeAt(s+1)!==94||e.level>=e.options.maxNesting)return!1;for(n=s+2;n<o;n++){if(e.src.charCodeAt(n)===32||e.src.charCodeAt(n)===10)return!1;if(e.src.charCodeAt(n)===93)break}return n===s+2||n>=o||(n++,t=e.src.slice(s+2,n-1),typeof e.env.footnotes.refs[":"+t]>"u")?!1:(i||(e.env.footnotes.list||(e.env.footnotes.list=[]),e.env.footnotes.refs[":"+t]<0?(r=e.env.footnotes.list.length,e.env.footnotes.list[r]={label:t,count:0},e.env.footnotes.refs[":"+t]=r):r=e.env.footnotes.refs[":"+t],a=e.env.footnotes.list[r].count,e.env.footnotes.list[r].count++,e.push({type:"footnote_ref",id:r,subId:a,level:e.level})),e.pos=n,e.posMax=o,!0)}var ho=["coap","doi","javascript","aaa","aaas","about","acap","cap","cid","crid","data","dav","dict","dns","file","ftp","geo","go","gopher","h323","http","https","iax","icap","im","imap","info","ipp","iris","iris.beep","iris.xpc","iris.xpcs","iris.lwz","ldap","mailto","mid","msrp","msrps","mtqp","mupdate","news","nfs","ni","nih","nntp","opaquelocktoken","pop","pres","rtsp","service","session","shttp","sieve","sip","sips","sms","snmp","soap.beep","soap.beeps","tag","tel","telnet","tftp","thismessage","tn3270","tip","tv","urn","vemmi","ws","wss","xcon","xcon-userid","xmlrpc.beep","xmlrpc.beeps","xmpp","z39.50r","z39.50s","adiumxtra","afp","afs","aim","apt","attachment","aw","beshare","bitcoin","bolo","callto","chrome","chrome-extension","com-eventbrite-attendee","content","cvs","dlna-playsingle","dlna-playcontainer","dtn","dvb","ed2k","facetime","feed","finger","fish","gg","git","gizmoproject","gtalk","hcp","icon","ipn","irc","irc6","ircs","itms","jar","jms","keyparc","lastfm","ldaps","magnet","maps","market","message","mms","ms-help","msnim","mumble","mvn","notes","oid","palm","paparazzi","platform","proxy","psyc","query","res","resource","rmi","rsync","rtmp","secondlife","sftp","sgn","skype","smb","soldat","spotify","ssh","steam","svn","teamspeak","things","udp","unreal","ut2004","ventrilo","view-source","webcal","wtai","wyciwyg","xfire","xri","ymsgr"],po=/^<([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])?)*)>/,fo=/^<([a-zA-Z.\-]{1,25}):([^<>\x00-\x20]*)>/;function vo(e,i){var t,n,r,a,o,s=e.pos;return e.src.charCodeAt(s)!==60||(t=e.src.slice(s),t.indexOf(">")<0)?!1:(n=t.match(fo),n?ho.indexOf(n[1].toLowerCase())<0||(a=n[0].slice(1,-1),o=kn(a),!e.parser.validateLink(a))?!1:(i||(e.push({type:"link_open",href:o,level:e.level}),e.push({type:"text",content:a,level:e.level+1}),e.push({type:"link_close",level:e.level})),e.pos+=n[0].length,!0):(r=t.match(po),r?(a=r[0].slice(1,-1),o=kn("mailto:"+a),e.parser.validateLink(o)?(i||(e.push({type:"link_open",href:o,level:e.level}),e.push({type:"text",content:a,level:e.level+1}),e.push({type:"link_close",level:e.level})),e.pos+=r[0].length,!0):!1):!1))}function Lt(e,i){return e=e.source,i=i||"",function t(n,r){return n?(r=r.source||r,e=e.replace(n,r),t):new RegExp(e,i)}}var mo=/[a-zA-Z_:][a-zA-Z0-9:._-]*/,go=/[^"'=<>`\x00-\x20]+/,yo=/'[^']*'/,bo=/"[^"]*"/,ko=Lt(/(?:unquoted|single_quoted|double_quoted)/)("unquoted",go)("single_quoted",yo)("double_quoted",bo)(),_o=Lt(/(?:\s+attr_name(?:\s*=\s*attr_value)?)/)("attr_name",mo)("attr_value",ko)(),wo=Lt(/<[A-Za-z][A-Za-z0-9]*attribute*\s*\/?>/)("attribute",_o)(),So=/<\/[A-Za-z][A-Za-z0-9]*\s*>/,xo=/<!---->|<!--(?:-?[^>-])(?:-?[^-])*-->/,Eo=/<[?].*?[?]>/,Co=/<![A-Z]+\s+[^>]*>/,Mo=/<!\[CDATA\[[\s\S]*?\]\]>/,Ao=Lt(/^(?:open_tag|close_tag|comment|processing|declaration|cdata)/)("open_tag",wo)("close_tag",So)("comment",xo)("processing",Eo)("declaration",Co)("cdata",Mo)();function To(e){var i=e|32;return i>=97&&i<=122}function Io(e,i){var t,n,r,a=e.pos;return!e.options.html||(r=e.posMax,e.src.charCodeAt(a)!==60||a+2>=r)||(t=e.src.charCodeAt(a+1),t!==33&&t!==63&&t!==47&&!To(t))||(n=e.src.slice(a).match(Ao),!n)?!1:(i||e.push({type:"htmltag",content:e.src.slice(a,a+n[0].length),level:e.level}),e.pos+=n[0].length,!0)}var Lo=/^&#((?:x[a-f0-9]{1,8}|[0-9]{1,8}));/i,Ro=/^&([a-z][a-z0-9]{1,31});/i;function Oo(e,i){var t,n,r,a=e.pos,o=e.posMax;if(e.src.charCodeAt(a)!==38)return!1;if(a+1<o){if(t=e.src.charCodeAt(a+1),t===35){if(r=e.src.slice(a).match(Lo),r)return i||(n=r[1][0].toLowerCase()==="x"?parseInt(r[1].slice(1),16):parseInt(r[1],10),e.pending+=ei(n)?bn(n):bn(65533)),e.pos+=r[0].length,!0}else if(r=e.src.slice(a).match(Ro),r){var s=Xr(r[1]);if(r[1]!==s)return i||(e.pending+=s),e.pos+=r[0].length,!0}}return i||(e.pending+="&"),e.pos++,!0}var an=[["text",Ja],["newline",Za],["escape",Xa],["backticks",Qa],["del",eo],["ins",to],["mark",no],["emphasis",ro],["sub",ao],["sup",so],["links",lo],["footnote_inline",uo],["footnote_ref",co],["autolink",vo],["htmltag",Io],["entity",Oo]];function Rt(){this.ruler=new fe;for(var e=0;e<an.length;e++)this.ruler.push(an[e][0],an[e][1]);this.validateLink=Po}Rt.prototype.skipToken=function(e){var i=this.ruler.getRules(""),t=i.length,n=e.pos,r,a;if((a=e.cacheGet(n))>0){e.pos=a;return}for(r=0;r<t;r++)if(i[r](e,!0)){e.cacheSet(n,e.pos);return}e.pos++,e.cacheSet(n,e.pos)};Rt.prototype.tokenize=function(e){for(var i=this.ruler.getRules(""),t=i.length,n=e.posMax,r,a;e.pos<n;){for(a=0;a<t&&(r=i[a](e,!1),!r);a++);if(r){if(e.pos>=n)break;continue}e.pending+=e.src[e.pos++]}e.pending&&e.pushPending()};Rt.prototype.parse=function(e,i,t,n){var r=new Fe(e,this,i,t,n);this.tokenize(r)};function Po(e){var i=["vbscript","javascript","file","data"],t=e.trim().toLowerCase();return t=Le(t),!(t.indexOf(":")!==-1&&i.indexOf(t.split(":")[0])!==-1)}var No={options:{html:!1,xhtmlOut:!1,breaks:!1,langPrefix:"language-",linkTarget:"",typographer:!1,quotes:"“”‘’",highlight:null,maxNesting:20},components:{core:{rules:["block","inline","references","replacements","smartquotes","references","abbr2","footnote_tail"]},block:{rules:["blockquote","code","fences","footnote","heading","hr","htmlblock","lheading","list","paragraph","table"]},inline:{rules:["autolink","backticks","del","emphasis","entity","escape","footnote_ref","htmltag","links","newline","text"]}}},Do={options:{html:!1,xhtmlOut:!1,breaks:!1,langPrefix:"language-",linkTarget:"",typographer:!1,quotes:"“”‘’",highlight:null,maxNesting:20},components:{core:{},block:{},inline:{}}},Fo={options:{html:!0,xhtmlOut:!0,breaks:!1,langPrefix:"language-",linkTarget:"",typographer:!1,quotes:"“”‘’",highlight:null,maxNesting:20},components:{core:{rules:["block","inline","references","abbr2"]},block:{rules:["blockquote","code","fences","heading","hr","htmlblock","lheading","list","paragraph"]},inline:{rules:["autolink","backticks","emphasis","entity","escape","htmltag","links","newline","text"]}}},jo={default:No,full:Do,commonmark:Fo};function si(e,i,t){this.src=i,this.env=t,this.options=e.options,this.tokens=[],this.inlineMode=!1,this.inline=e.inline,this.block=e.block,this.renderer=e.renderer,this.typographer=e.typographer}function Ee(e,i){typeof e!="string"&&(i=e,e="default"),i&&i.linkify!=null&&console.warn(`linkify option is removed. Use linkify plugin instead:

import Remarkable from 'remarkable';
import linkify from 'remarkable/linkify';
new Remarkable().use(linkify)
`),this.inline=new Rt,this.block=new Rn,this.core=new ai,this.renderer=new Ln,this.ruler=new fe,this.options={},this.configure(jo[e]),this.set(i||{})}Ee.prototype.set=function(e){Qr(this.options,e)};Ee.prototype.configure=function(e){var i=this;if(!e)throw new Error("Wrong `remarkable` preset, check name/content");e.options&&i.set(e.options),e.components&&Object.keys(e.components).forEach(function(t){e.components[t].rules&&i[t].ruler.enable(e.components[t].rules,!0)})};Ee.prototype.use=function(e,i){return e(this,i),this};Ee.prototype.parse=function(e,i){var t=new si(this,e,i);return this.core.process(t),t.tokens};Ee.prototype.render=function(e,i){return i=i||{},this.renderer.render(this.parse(e,i),this.options,i)};Ee.prototype.parseInline=function(e,i){var t=new si(this,e,i);return t.inlineMode=!0,this.core.process(t),t.tokens};Ee.prototype.renderInline=function(e,i){return i=i||{},this.renderer.render(this.parseInline(e,i),this.options,i)};const li=new Ee({html:!0});li.renderer.rules.image=function(e,i){const t=e[i];return`<img src="${t.src}" alt="${t.alt}" title="${t.title||""}" style="max-width: 100%; height: auto; display: block; margin: 1em auto;">`};const ui=`
    :host {
        --main-color: #0087be;
        --text-color: #FFFFFF;
        --text-size: 1em;
        --bubble-color: #0087be;
        --reply-color: #23282d;
        --reply-bubble-color: #f1f1f1;
        --ai-bubble-color: #b3d6ec;
        --ai-text-color: #000000;
        --ai-sources-color: #0087be;
        --background-color: #FFFFFF;

        --avatar-size: 1.5em;
        --ai-bubble-border: 0.5px solid rgb(197, 206, 214);
        --ai-bubble-border-radius: 0 10px 10px;
        --reply-bubble-border: 0.5px solid rgb(197, 206, 214);
        --reply-bubble-border-radius: 10px;

        --bubble-max-width: calc(97.5% - 24px);
        --bubble-padding: .6em .75em .6em 1.3em;
    }

    #chat-content {
        width: 100%;
        height: 100%;
        overflow: auto;
        display: none;
    }

    .error {
        display: flex;
        justify-content: center;
        width: 100%;
    }

    .error-content {
        display: flex;
        align-items: center;
        gap: 8px;
        color: #dc3545;
    }
`,Bo=`
    ${ui}

    @keyframes fadeIn {
        0% { opacity: 0; transform: scale(0.5); }
        100% { opacity: 1; transform: scale(1); }
    }

    @keyframes slideInUp {
        0% {
          transform: translateY(20%);
          opacity: 0;
        }
        100% {
          transform: translateY(0);
          opacity: 1;
        }
    }

    @keyframes fadeOutDown {
        0% {
          transform: translateY(0);
          opacity: 1;
        }
        100% {
          transform: translateY(20%);
          opacity: 0;
        }
    }

    @keyframes fadeInAndMove {
        0% {
            top: initial;
            right: initial;
            width: initial;
            height: initial;
            border-radius: initial;
            opacity: 0;
        }
        100% {
            top: 0;
            right: 0;
            width: 50px;
            height: 50px;
            border-radius: 0;
            opacity: 1;
            z-index: 1000;
        }
    }

    @keyframes fadeOut {
        from { opacity: 1; }
        to { opacity: 0; }
    }

    #chat-widget {
        display: none;
        font-family: 'Inter', sans-serif, 'Avenir', 'Helvetica', 'Arial';
        font-size: 0.9rem;
        box-shadow: 0 0 15px rgba(0, 0, 0, 0.3);
        border-radius: 10px;
    }

    #chat-widget.loaded {
        display: flex;
    }

    #chat-icon {
        display: flex;
        fill: var(--text-color);
        position: fixed;
        bottom: 20px;
        right: 20px;
        width: 60px;
        height: 60px;
        background-color: var(--main-color);
        color: var(--text-color);
        border-radius: 50%;
        justify-content: center;
        align-items: center;
        cursor: pointer;
        transition: background-color 0.3s ease;
    }

    #chat-icon:hover {
        filter: brightness(115%);
    }

    #chat-icon .icon {
        width: 50%;
        height: 50%;
    }

    #chat-widget.open #open-icon {
        display: none;
    }

    #chat-widget.open #close-icon {
        display: inline-block;
    }

    #chat-widget:not(.open) #open-icon {
        display: inline-block;
    }

    #chat-widget:not(.open) #close-icon {
        display: none;
    }

    #chat-content {
        position: fixed;
        bottom: 90px;
        right: 20px;
        width: 400px;
        height: 700px;
        border-radius: 10px;
        background: white;
        box-shadow: 0 0 15px rgba(0, 0, 0, 0.3);
        transition: transform 0.3s ease, opacity 0.3s ease;
    }

    #chat-widget.open #chat-content {
        display: flex;
        flex-direction: column;
        animation: slideInUp 0.5s ease-out;
    }

    #chat-widget.closing #chat-content {
        animation: fadeOutDown 0.5s ease-in forwards;
    }

    #chat-header {
        background-color: var(--main-color);
        padding: 10px;
        color: var(--text-color);
        border-top-left-radius: 10px;
        border-top-right-radius: 10px;
        text-align: center;
    }

    #chat-close {
        position: absolute;
        right: 10px;
        top: 10px;
        cursor: pointer;
        display: none;
        fill: var(--text-color);
        width: 20px;
    }

    #chat-clear {
        position: absolute;
        left: 10px;
        top: 10px;
        cursor: pointer;
        fill: var(--text-color);
        width: 12px;
    }

    .header-title {
        margin: 0;
        font-size: 1rem;
    }

    .header-subtitle {
        margin: 0;
        font-size: 0.8rem;
    }

    #support-link {
        padding: 10px;
        background-color: #f8f8f8;
        text-align: center;
        overflow: hidden;
        text-overflow: ellipsis;
        max-height: 20px;
    }

    ::slotted(*) {
        margin: 0;
        font-size: 0.7rem;
    }

    @media screen and (max-width: 768px) {
        #chat-content {
            bottom: 0;
            right: 0;
            width: 100%;
            height: 100%;
            border-radius: 0;
        }

        #chat-header {
            border-top-left-radius: 0;
            border-top-right-radius: 0;
        }

        #chat-widget.open #chat-icon {
            display: none;
        }

        #chat-widget.open #chat-close {
            display: block;
        }
    }
`,qo=`
    ${ui}

    #chat-embed {
        width: 100%;
        height: 100%;
        position: relative;
        display: flex;
        justify-content: center;
        align-items: center;
        background-color: transparent;
    }

    #chat-embed.loaded .loader {
        display: none;
    }

    #chat-embed.loaded #chat-content {
        display: flex;
    }

    #chat-clear {
        display: none;
    }

    .loader {
        border: 4px solid #f3f3f3;
        border-radius: 50%;
        border-top: 4px solid var(--main-color);
        width: 40px;
        height: 40px;
        animation: spin 2s linear infinite;
        align-self: center;
    }

    @keyframes spin {
        0% { transform: rotate(0deg); }
        100% { transform: rotate(360deg); }
    }
`,zo='<svg id="open-icon" class="icon" xmlns="http://www.w3.org/2000/svg" viewBox="0 0 24 24"><rect x="0" fill="none" width="24" height="24"/><g><path d="M3 12c-1.1 0-2-.9-2-2V5c0-1.1.9-2 2-2h8c1.1 0 2 .9 2 2v5c0 1.1-.9 2-2 2H9v3l-3-3H3zM21 18c1.1 0 2-.9 2-2v-5c0-1.1-.9-2-2-2h-6v1c0 2.2-1.8 4-4 4v2c0 1.1.9 2 2 2h2v3l3-3h3z"/></g></svg>',ar='<svg id="close-icon" class="icon" xmlns="http://www.w3.org/2000/svg" viewBox="0 0 24 24"><rect x="0" fill="none" width="24" height="24"/><g><path d="M17.705 7.705l-1.41-1.41L12 10.59 7.705 6.295l-1.41 1.41L10.59 12l-4.295 4.295 1.41 1.41L12 13.41l4.295 4.295 1.41-1.41L13.41 12l4.295-4.295z"/></g></svg>',ci='<svg class="icon" xmlns="http://www.w3.org/2000/svg" viewBox="0 0 512 512"><path fill="currentColor" d="M105.1 202.6c7.7-21.8 20.2-42.3 37.8-59.8c62.5-62.5 163.8-62.5 226.3 0L386.3 160H336c-17.7 0-32 14.3-32 32s14.3 32 32 32H463.5c0 0 0 0 0 0h.4c17.7 0 32-14.3 32-32V64c0-17.7-14.3-32-32-32s-32 14.3-32 32v51.2L414.4 97.6c-87.5-87.5-229.3-87.5-316.8 0C73.2 122 55.6 150.7 44.8 181.4c-5.9 16.7 2.9 34.9 19.5 40.8s34.9-2.9 40.8-19.5zM39 289.3c-5 1.5-9.8 4.2-13.7 8.2c-4 4-6.7 8.8-8.1 14c-.3 1.2-.6 2.5-.8 3.8c-.3 1.7-.4 3.4-.4 5.1V448c0 17.7 14.3 32 32 32s32-14.3 32-32V396.9l17.6 17.5 0 0c87.5 87.4 229.3 87.4 316.7 0c24.4-24.4 42.1-53.1 52.9-83.7c5.9-16.7-2.9-34.9-19.5-40.8s-34.9 2.9-40.8 19.5c-7.7 21.8-20.2 42.3-37.8 59.8c-62.5 62.5-163.8 62.5-226.3 0l-.1-.1L125.6 352H176c17.7 0 32-14.3 32-32s-14.3-32-32-32H48.4c-1.6 0-3.2 .1-4.8 .3s-3.1 .5-4.6 1z"></path></svg>',Uo=`
    <style>${Bo}</style>
    <div id="chat-widget" part="widget">
        <div id="chat-icon">
            ${zo}
            ${ar}
        </div>
        <div id="chat-content">
            <div id="chat-header">
                <h1 class="header-title"></h1>
                <p class="header-subtitle"></p>
                <div id="chat-close">
                    ${ar}
                </div>
                <div id="chat-clear">
                    ${ci}
                </div>
            </div>
        </div>
    </div>
`,Ho=`
    <style>${qo}</style>
    <div id="chat-embed" part="widget">
        <div class="loader"></div>
        <div id="chat-clear">
            ${ci}
        </div>
        <div id="chat-content" />
    </div>
`;function Vo(e){return e?`
        <div class="feedback">
            <svg class="feedback-icon feedback-icon-positive" data-message-id=${e} viewBox="0 0 24 24" xmlns="http://www.w3.org/2000/svg"><path d="M20.22 9.55C19.79 9.04 19.17 8.75 18.5 8.75H14.47V6C14.47 4.48 13.24 3.25 11.64 3.25C10.94 3.25 10.31 3.67 10.03 4.32L7.49 10.25H5.62C4.31 10.25 3.25 11.31 3.25 12.62V18.39C3.25 19.69 4.32 20.75 5.62 20.75H17.18C18.27 20.75 19.2 19.97 19.39 18.89L20.71 11.39C20.82 10.73 20.64 10.06 20.21 9.55H20.22ZM5.62 19.25C5.14 19.25 4.75 18.86 4.75 18.39V12.62C4.75 12.14 5.14 11.75 5.62 11.75H7.23V19.25H5.62ZM17.92 18.63C17.86 18.99 17.55 19.25 17.18 19.25H8.74V11.15L11.41 4.9C11.45 4.81 11.54 4.74 11.73 4.74C12.42 4.74 12.97 5.3 12.97 5.99V10.24H18.5C18.73 10.24 18.93 10.33 19.07 10.5C19.21 10.67 19.27 10.89 19.23 11.12L17.91 18.62L17.92 18.63Z"/></svg>
            <svg class="feedback-icon feedback-icon-negative" data-message-id=${e} viewBox="0 0 24 24" xmlns="http://www.w3.org/2000/svg"><path d="M20.22 9.55C19.79 9.04 19.17 8.75 18.5 8.75H14.47V6C14.47 4.48 13.24 3.25 11.64 3.25C10.94 3.25 10.31 3.67 10.03 4.32L7.49 10.25H5.62C4.31 10.25 3.25 11.31 3.25 12.62V18.39C3.25 19.69 4.32 20.75 5.62 20.75H17.18C18.27 20.75 19.2 19.97 19.39 18.89L20.71 11.39C20.82 10.73 20.64 10.06 20.21 9.55H20.22ZM5.62 19.25C5.14 19.25 4.75 18.86 4.75 18.39V12.62C4.75 12.14 5.14 11.75 5.62 11.75H7.23V19.25H5.62ZM17.92 18.63C17.86 18.99 17.55 19.25 17.18 19.25H8.74V11.15L11.41 4.9C11.45 4.81 11.54 4.74 11.73 4.74C12.42 4.74 12.97 5.3 12.97 5.99V10.24H18.5C18.73 10.24 18.93 10.33 19.07 10.5C19.21 10.67 19.27 10.89 19.23 11.12L17.91 18.62L17.92 18.63Z"/></svg>
        </div>
    `:""}function $o(e){return e.length===0?`
        <div class="sources"></div>
    `:`
      <details class="sources">
        <summary class="sources-summary">Sources</summary>
        <ul class="sources-ul">
          ${e.map(t=>`
        <li class="sources-li">
          <a class="sources-a" href="${t.url}" target="_blank">
            <svg class="sources-icons" aria-hidden="true" focusable="false" data-prefix="fas" data-icon="link" role="img" xmlns="http://www.w3.org/2000/svg" viewBox="0 0 640 512">
              <path fill="currentColor" d="M579.8 267.7c56.5-56.5 56.5-148 0-204.5c-50-50-128.8-56.5-186.3-15.4l-1.6 1.1c-14.4 10.3-17.7 30.3-7.4 44.6s30.3 17.7 44.6 7.4l1.6-1.1c32.1-22.9 76-19.3 103.8 8.6c31.5 31.5 31.5 82.5 0 114L422.3 334.8c-31.5 31.5-82.5 31.5-114 0c-27.9-27.9-31.5-71.8-8.6-103.8l1.1-1.6c10.3-14.4 6.9-34.4-7.4-44.6s-34.4-6.9-44.6 7.4l-1.1 1.6C206.5 251.2 213 330 263 380c56.5 56.5 148 56.5 204.5 0L579.8 267.7zM60.2 244.3c-56.5 56.5-56.5 148 0 204.5c50 50 128.8 56.5 186.3 15.4l1.6-1.1c14.4-10.3 17.7-30.3 7.4-44.6s-30.3-17.7-44.6-7.4l-1.6 1.1c-32.1 22.9-76 19.3-103.8-8.6C74 372 74 321 105.5 289.5L217.7 177.2c31.5-31.5 82.5-31.5 114 0c27.9 27.9 31.5 71.8 8.6 103.9l-1.1 1.6c-10.3 14.4-6.9 34.4 7.4 44.6s34.4 6.9 44.6-7.4l1.1-1.6C433.5 260.8 427 182 377 132c-56.5-56.5-148-56.5-204.5 0L60.2 244.3z"></path>
            </svg>
            ${t.title}
          </a>
        </li>
      `).join("")}
        </ul>
      </details>
    `}function Go(e){if(e===null)return"";e===""&&(e="{}");let i;try{i=JSON.parse(e)}catch{return""}let t=i.text??"Powered by Support AI. Some responses may be inaccurate.";if(i.link){const n=i.linkText??"Learn More.";t+=` <a href="${i.link}" target="_blank" class="notice-link">${n}</a>`}return`
    <hr>
    <div class="notice">
      ${t}
    </div>
  `}function or(e,i,t,n){return`
    <div>
        <div class="response">
            ${li.render(e)}
        </div>
        <div class="footer">
            ${Vo(t)}
            ${$o(i)}
            ${Go(n)}
        </div>
    </div>
  `}function Wo(e){return`
    <div style="display: flex; justify-content: center; width: 100%;">
      <div style="display: flex; align-items: center; gap: 8px; color: #dc3545;">
        <svg width="20" height="20" viewBox="0 0 24 24" fill="currentColor">
          <path d="M12 4c-4.42 0-8 3.58-8 8s3.58 8 8 8 8-3.58 8-8-3.58-8-8-8zm1 13h-2v-2h2v2zm0-4h-2V7h2v6z"/>
        </svg>
        ${e}
      </div>
    </div>
  `}function di(e){return Jo(e)||Yo(e)||hi(e)||Ko()}function Ko(){throw new TypeError(`Invalid attempt to spread non-iterable instance.
In order to be iterable, non-array objects must have a [Symbol.iterator]() method.`)}function Yo(e){if(typeof Symbol<"u"&&e[Symbol.iterator]!=null||e["@@iterator"]!=null)return Array.from(e)}function Jo(e){if(Array.isArray(e))return _n(e)}function Zo(e,i){var t=typeof Symbol<"u"&&e[Symbol.iterator]||e["@@iterator"];if(!t){if(Array.isArray(e)||(t=hi(e))||i){t&&(e=t);var n=0,r=function(){};return{s:r,n:function(){return n>=e.length?{done:!0}:{done:!1,value:e[n++]}},e:function(u){throw u},f:r}}throw new TypeError(`Invalid attempt to iterate non-iterable instance.
In order to be iterable, non-array objects must have a [Symbol.iterator]() method.`)}var a=!0,o=!1,s;return{s:function(){t=t.call(e)},n:function(){var u=t.next();return a=u.done,u},e:function(u){o=!0,s=u},f:function(){try{!a&&t.return!=null&&t.return()}finally{if(o)throw s}}}}function hi(e,i){if(e){if(typeof e=="string")return _n(e,i);var t=Object.prototype.toString.call(e).slice(8,-1);if(t==="Object"&&e.constructor&&(t=e.constructor.name),t==="Map"||t==="Set")return Array.from(e);if(t==="Arguments"||/^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(t))return _n(e,i)}}function _n(e,i){(i==null||i>e.length)&&(i=e.length);for(var t=0,n=new Array(i);t<i;t++)n[t]=e[t];return n}function wn(e){var i=typeof Map=="function"?new Map:void 0;return wn=function(n){if(n===null||!Qo(n))return n;if(typeof n!="function")throw new TypeError("Super expression must either be null or a function");if(typeof i<"u"){if(i.has(n))return i.get(n);i.set(n,r)}function r(){return Xo(n,arguments,rt(this).constructor)}return r.prototype=Object.create(n.prototype,{constructor:{value:r,enumerable:!1,writable:!0,configurable:!0}}),it(r,n)},wn(e)}function Xo(e,i,t){if(Pn())return Reflect.construct.apply(null,arguments);var n=[null];n.push.apply(n,i);var r=new(e.bind.apply(e,n));return t&&it(r,t.prototype),r}function Qo(e){try{return Function.toString.call(e).indexOf("[native code]")!==-1}catch{return typeof e=="function"}}function O(e,i,t){return i=rt(i),es(e,Pn()?Reflect.construct(i,t||[],rt(e).constructor):i.apply(e,t))}function es(e,i){if(i&&(R(i)==="object"||typeof i=="function"))return i;if(i!==void 0)throw new TypeError("Derived constructors may only return object or undefined");return de(e)}function de(e){if(e===void 0)throw new ReferenceError("this hasn't been initialised - super() hasn't been called");return e}function Pn(){try{var e=!Boolean.prototype.valueOf.call(Reflect.construct(Boolean,[],function(){}))}catch{}return(Pn=function(){return!!e})()}function rt(e){return rt=Object.setPrototypeOf?Object.getPrototypeOf.bind():function(t){return t.__proto__||Object.getPrototypeOf(t)},rt(e)}function P(e,i){if(typeof i!="function"&&i!==null)throw new TypeError("Super expression must either be null or a function");e.prototype=Object.create(i&&i.prototype,{constructor:{value:e,writable:!0,configurable:!0}}),Object.defineProperty(e,"prototype",{writable:!1}),i&&it(e,i)}function it(e,i){return it=Object.setPrototypeOf?Object.setPrototypeOf.bind():function(n,r){return n.__proto__=r,n},it(e,i)}function f(){/*! regenerator-runtime -- Copyright (c) 2014-present, Facebook, Inc. -- license (MIT): https://github.com/facebook/regenerator/blob/main/LICENSE */f=function(){return i};var e,i={},t=Object.prototype,n=t.hasOwnProperty,r=Object.defineProperty||function(C,S,E){C[S]=E.value},a=typeof Symbol=="function"?Symbol:{},o=a.iterator||"@@iterator",s=a.asyncIterator||"@@asyncIterator",l=a.toStringTag||"@@toStringTag";function u(C,S,E){return Object.defineProperty(C,S,{value:E,enumerable:!0,configurable:!0,writable:!0}),C[S]}try{u({},"")}catch{u=function(E,L,D){return E[L]=D}}function c(C,S,E,L){var D=S&&S.prototype instanceof w?S:w,I=Object.create(D.prototype),W=new Y(L||[]);return r(I,"_invoke",{value:te(C,E,W)}),I}function d(C,S,E){try{return{type:"normal",arg:C.call(S,E)}}catch(L){return{type:"throw",arg:L}}}i.wrap=c;var h="suspendedStart",p="suspendedYield",v="executing",m="completed",b={};function w(){}function _(){}function x(){}var N={};u(N,o,function(){return this});var M=Object.getPrototypeOf,j=M&&M(M(Ce([])));j&&j!==t&&n.call(j,o)&&(N=j);var G=x.prototype=w.prototype=Object.create(N);function H(C){["next","throw","return"].forEach(function(S){u(C,S,function(E){return this._invoke(S,E)})})}function Z(C,S){function E(D,I,W,oe){var se=d(C[D],C,I);if(se.type!=="throw"){var Me=se.arg,ke=Me.value;return ke&&R(ke)=="object"&&n.call(ke,"__await")?S.resolve(ke.__await).then(function(Ae){E("next",Ae,W,oe)},function(Ae){E("throw",Ae,W,oe)}):S.resolve(ke).then(function(Ae){Me.value=Ae,W(Me)},function(Ae){return E("throw",Ae,W,oe)})}oe(se.arg)}var L;r(this,"_invoke",{value:function(I,W){function oe(){return new S(function(se,Me){E(I,W,se,Me)})}return L=L?L.then(oe,oe):oe()}})}function te(C,S,E){var L=h;return function(D,I){if(L===v)throw new Error("Generator is already running");if(L===m){if(D==="throw")throw I;return{value:e,done:!0}}for(E.method=D,E.arg=I;;){var W=E.delegate;if(W){var oe=X(W,E);if(oe){if(oe===b)continue;return oe}}if(E.method==="next")E.sent=E._sent=E.arg;else if(E.method==="throw"){if(L===h)throw L=m,E.arg;E.dispatchException(E.arg)}else E.method==="return"&&E.abrupt("return",E.arg);L=v;var se=d(C,S,E);if(se.type==="normal"){if(L=E.done?m:p,se.arg===b)continue;return{value:se.arg,done:E.done}}se.type==="throw"&&(L=m,E.method="throw",E.arg=se.arg)}}}function X(C,S){var E=S.method,L=C.iterator[E];if(L===e)return S.delegate=null,E==="throw"&&C.iterator.return&&(S.method="return",S.arg=e,X(C,S),S.method==="throw")||E!=="return"&&(S.method="throw",S.arg=new TypeError("The iterator does not provide a '"+E+"' method")),b;var D=d(L,C.iterator,S.arg);if(D.type==="throw")return S.method="throw",S.arg=D.arg,S.delegate=null,b;var I=D.arg;return I?I.done?(S[C.resultName]=I.value,S.next=C.nextLoc,S.method!=="return"&&(S.method="next",S.arg=e),S.delegate=null,b):I:(S.method="throw",S.arg=new TypeError("iterator result is not an object"),S.delegate=null,b)}function $(C){var S={tryLoc:C[0]};1 in C&&(S.catchLoc=C[1]),2 in C&&(S.finallyLoc=C[2],S.afterLoc=C[3]),this.tryEntries.push(S)}function Q(C){var S=C.completion||{};S.type="normal",delete S.arg,C.completion=S}function Y(C){this.tryEntries=[{tryLoc:"root"}],C.forEach($,this),this.reset(!0)}function Ce(C){if(C||C===""){var S=C[o];if(S)return S.call(C);if(typeof C.next=="function")return C;if(!isNaN(C.length)){var E=-1,L=function D(){for(;++E<C.length;)if(n.call(C,E))return D.value=C[E],D.done=!1,D;return D.value=e,D.done=!0,D};return L.next=L}}throw new TypeError(R(C)+" is not iterable")}return _.prototype=x,r(G,"constructor",{value:x,configurable:!0}),r(x,"constructor",{value:_,configurable:!0}),_.displayName=u(x,l,"GeneratorFunction"),i.isGeneratorFunction=function(C){var S=typeof C=="function"&&C.constructor;return!!S&&(S===_||(S.displayName||S.name)==="GeneratorFunction")},i.mark=function(C){return Object.setPrototypeOf?Object.setPrototypeOf(C,x):(C.__proto__=x,u(C,l,"GeneratorFunction")),C.prototype=Object.create(G),C},i.awrap=function(C){return{__await:C}},H(Z.prototype),u(Z.prototype,s,function(){return this}),i.AsyncIterator=Z,i.async=function(C,S,E,L,D){D===void 0&&(D=Promise);var I=new Z(c(C,S,E,L),D);return i.isGeneratorFunction(S)?I:I.next().then(function(W){return W.done?W.value:I.next()})},H(G),u(G,l,"Generator"),u(G,o,function(){return this}),u(G,"toString",function(){return"[object Generator]"}),i.keys=function(C){var S=Object(C),E=[];for(var L in S)E.push(L);return E.reverse(),function D(){for(;E.length;){var I=E.pop();if(I in S)return D.value=I,D.done=!1,D}return D.done=!0,D}},i.values=Ce,Y.prototype={constructor:Y,reset:function(S){if(this.prev=0,this.next=0,this.sent=this._sent=e,this.done=!1,this.delegate=null,this.method="next",this.arg=e,this.tryEntries.forEach(Q),!S)for(var E in this)E.charAt(0)==="t"&&n.call(this,E)&&!isNaN(+E.slice(1))&&(this[E]=e)},stop:function(){this.done=!0;var S=this.tryEntries[0].completion;if(S.type==="throw")throw S.arg;return this.rval},dispatchException:function(S){if(this.done)throw S;var E=this;function L(Me,ke){return W.type="throw",W.arg=S,E.next=Me,ke&&(E.method="next",E.arg=e),!!ke}for(var D=this.tryEntries.length-1;D>=0;--D){var I=this.tryEntries[D],W=I.completion;if(I.tryLoc==="root")return L("end");if(I.tryLoc<=this.prev){var oe=n.call(I,"catchLoc"),se=n.call(I,"finallyLoc");if(oe&&se){if(this.prev<I.catchLoc)return L(I.catchLoc,!0);if(this.prev<I.finallyLoc)return L(I.finallyLoc)}else if(oe){if(this.prev<I.catchLoc)return L(I.catchLoc,!0)}else{if(!se)throw new Error("try statement without catch or finally");if(this.prev<I.finallyLoc)return L(I.finallyLoc)}}}},abrupt:function(S,E){for(var L=this.tryEntries.length-1;L>=0;--L){var D=this.tryEntries[L];if(D.tryLoc<=this.prev&&n.call(D,"finallyLoc")&&this.prev<D.finallyLoc){var I=D;break}}I&&(S==="break"||S==="continue")&&I.tryLoc<=E&&E<=I.finallyLoc&&(I=null);var W=I?I.completion:{};return W.type=S,W.arg=E,I?(this.method="next",this.next=I.finallyLoc,b):this.complete(W)},complete:function(S,E){if(S.type==="throw")throw S.arg;return S.type==="break"||S.type==="continue"?this.next=S.arg:S.type==="return"?(this.rval=this.arg=S.arg,this.method="return",this.next="end"):S.type==="normal"&&E&&(this.next=E),b},finish:function(S){for(var E=this.tryEntries.length-1;E>=0;--E){var L=this.tryEntries[E];if(L.finallyLoc===S)return this.complete(L.completion,L.afterLoc),Q(L),b}},catch:function(S){for(var E=this.tryEntries.length-1;E>=0;--E){var L=this.tryEntries[E];if(L.tryLoc===S){var D=L.completion;if(D.type==="throw"){var I=D.arg;Q(L)}return I}}throw new Error("illegal catch attempt")},delegateYield:function(S,E,L){return this.delegate={iterator:Ce(S),resultName:E,nextLoc:L},this.method==="next"&&(this.arg=e),b}},i}function sr(e,i,t,n,r,a,o){try{var s=e[a](o),l=s.value}catch(u){t(u);return}s.done?i(l):Promise.resolve(l).then(n,r)}function k(e){return function(){var i=this,t=arguments;return new Promise(function(n,r){var a=e.apply(i,t);function o(l){sr(a,n,r,o,s,"next",l)}function s(l){sr(a,n,r,o,s,"throw",l)}o(void 0)})}}function lr(e,i){var t=Object.keys(e);if(Object.getOwnPropertySymbols){var n=Object.getOwnPropertySymbols(e);i&&(n=n.filter(function(r){return Object.getOwnPropertyDescriptor(e,r).enumerable})),t.push.apply(t,n)}return t}function V(e){for(var i=1;i<arguments.length;i++){var t=arguments[i]!=null?arguments[i]:{};i%2?lr(Object(t),!0).forEach(function(n){pi(e,n,t[n])}):Object.getOwnPropertyDescriptors?Object.defineProperties(e,Object.getOwnPropertyDescriptors(t)):lr(Object(t)).forEach(function(n){Object.defineProperty(e,n,Object.getOwnPropertyDescriptor(t,n))})}return e}function pi(e,i,t){return i=fi(i),i in e?Object.defineProperty(e,i,{value:t,enumerable:!0,configurable:!0,writable:!0}):e[i]=t,e}function R(e){"@babel/helpers - typeof";return R=typeof Symbol=="function"&&typeof Symbol.iterator=="symbol"?function(i){return typeof i}:function(i){return i&&typeof Symbol=="function"&&i.constructor===Symbol&&i!==Symbol.prototype?"symbol":typeof i},R(e)}function g(e,i){if(!(e instanceof i))throw new TypeError("Cannot call a class as a function")}function ur(e,i){for(var t=0;t<i.length;t++){var n=i[t];n.enumerable=n.enumerable||!1,n.configurable=!0,"value"in n&&(n.writable=!0),Object.defineProperty(e,fi(n.key),n)}}function y(e,i,t){return i&&ur(e.prototype,i),t&&ur(e,t),Object.defineProperty(e,"prototype",{writable:!1}),e}function fi(e){var i=ts(e,"string");return R(i)=="symbol"?i:String(i)}function ts(e,i){if(R(e)!="object"||!e)return e;var t=e[Symbol.toPrimitive];if(t!==void 0){var n=t.call(e,i);if(R(n)!="object")return n;throw new TypeError("@@toPrimitive must return a primitive value.")}return String(e)}var ns=function(){function e(){g(this,e)}return y(e,null,[{key:"render",value:function(t,n){var r=document.createElement("div");r.id="error-view",r.innerText=n,t.replaceChildren(r)}}]),e}(),rs=function(){function e(){g(this,e)}return y(e,null,[{key:"onLoad",value:function(t){t.innerHTML='<div id="large-loading-ring"></div>'}},{key:"createElements",value:function(){var t=document.createElement("div");return t.id="validate-property-key-view",t}},{key:"render",value:function(t,n,r){var a=e.createElements(),o={onSuccess:n,onFail:ns.render.bind(this,t,"Your 'key' has failed authentication"),onLoad:e.onLoad.bind(this,a)};r.key&&r.verifyKey(r.key,o),t.replaceChildren(a)}}]),e}(),ie=function(){function e(){g(this,e)}return y(e,null,[{key:"unsetStyle",value:function(t,n){var r=Object.keys(n).reduce(function(a,o){return a[o]="",a},{});Object.assign(t.style,r)}},{key:"unsetActivityCSSMouseStates",value:function(t,n){n.click&&e.unsetStyle(t,n.click),n.hover&&e.unsetStyle(t,n.hover)}},{key:"unsetAllCSSMouseStates",value:function(t,n){e.unsetActivityCSSMouseStates(t,n),n.default&&e.unsetStyle(t,n.default)}},{key:"processStateful",value:function(t,n,r){var a=t.default||{},o=Object.assign(JSON.parse(JSON.stringify(V(V({},a),n))),t==null?void 0:t.hover),s=Object.assign(JSON.parse(JSON.stringify(V(V({},o),r))),t==null?void 0:t.click);return{default:a,hover:o,click:s}}},{key:"mergeStatefulStyles",value:function(t){var n={default:{},hover:{},click:{}};return t.forEach(function(r){n.default=Object.assign(n.default,r.default),n.hover=Object.assign(n.hover,r.hover),n.click=Object.assign(n.click,r.click)}),n}},{key:"overwriteDefaultWithAlreadyApplied",value:function(t,n){Object.keys(t.default||[]).forEach(function(r){var a,o=r;n.style[o]&&(a=t.default)!=null&&a[o]&&(t.default[r]=n.style[o])})}},{key:"applyToStyleIfNotDefined",value:function(t,n){for(var r in n){var a=n[r];t[r]===""&&a&&(t[r]=a)}}}]),e}(),vi=function(){function e(){g(this,e)}return y(e,null,[{key:"apply",value:function(t,n){if(n)try{e.applyStyleSheet(t,n)}catch{e.addStyleElement(t,n)}}},{key:"applyStyleSheet",value:function(t,n){var r=new CSSStyleSheet;r.replaceSync(t),n.adoptedStyleSheets.push(r)}},{key:"addStyleElement",value:function(t,n){var r=document.createElement("style");r.innerHTML=t,n.appendChild(r)}},{key:"applyDefaultStyleToComponent",value:function(t,n){n&&ie.applyToStyleIfNotDefined(t,n),ie.applyToStyleIfNotDefined(t,e.DEFAULT_COMPONENT_STYLE)}}]),e}();vi.DEFAULT_COMPONENT_STYLE={height:"350px",width:"320px",border:"1px solid #cacaca",fontFamily:"'Inter', sans-serif, Avenir, Helvetica, Arial",fontSize:"0.9rem",backgroundColor:"white",position:"relative",overflow:"hidden"};var on=vi,ne=function(e){return e.ESCAPE="Escape",e.ENTER="Enter",e.TAB="Tab",e.ARROW_UP="ArrowUp",e.ARROW_DOWN="ArrowDown",e.ARROW_RIGHT="ArrowRight",e.ARROW_LEFT="ArrowLeft",e.BACKSPACE="Backspace",e.DELETE="Delete",e.META="Meta",e.CONTROL="Control",e}(ne||{}),we=y(function e(){g(this,e)});we.IS_SAFARI=/^((?!chrome|android).)*safari/i.test(navigator.userAgent);we.IS_CHROMIUM=window.chrome;var mi=function(){function e(){g(this,e)}return y(e,null,[{key:"add",value:function(t,n,r){n!==void 0&&t.addEventListener("keydown",e.onKeyDown.bind(this,n)),t.oninput=e.onInput.bind(this,n,r)}},{key:"onKeyDown",value:function(t,n){var r=n.target.textContent;r&&r.length>=t&&!e.PERMITTED_KEYS.has(n.key)&&!e.isKeyCombinationPermitted(n)&&n.preventDefault()}},{key:"isKeyCombinationPermitted",value:function(t){return t.key==="a"?t.ctrlKey||t.metaKey:!1}},{key:"onInput",value:function(t,n,r){var a=r.target,o=a.textContent||"";t!==void 0&&o.length>t&&(a.textContent=o.substring(0,t),yi.focusEndOfInput(a)),n==null||n()}}]),e}();mi.PERMITTED_KEYS=new Set([ne.BACKSPACE,ne.DELETE,ne.ARROW_RIGHT,ne.ARROW_LEFT,ne.ARROW_DOWN,ne.ARROW_UP,ne.META,ne.CONTROL,ne.ENTER]);var is=mi,as=function(){function e(){g(this,e)}return y(e,null,[{key:"sanitizePastedTextContent",value:function(t){var n,r;t.preventDefault();var a=(n=t.clipboardData)==null?void 0:n.getData("text/plain");(r=document.execCommand)==null||r.call(document,"insertText",!1,a)}}]),e}(),gi=function(){function e(i,t){var n=this;g(this,e);var r,a=e.processConfig(t,i.textInput);this.elementRef=e.createContainerElement((r=a==null?void 0:a.styles)==null?void 0:r.container),this.inputElementRef=this.createInputElement(a),this._config=a,this.elementRef.appendChild(this.inputElementRef),setTimeout(function(){var o;is.add(n.inputElementRef,(o=i.textInput)==null?void 0:o.characterLimit,i._validationHandler)})}return y(e,[{key:"createInputElement",value:function(t){var n,r,a,o=document.createElement("div");return o.id=e.TEXT_INPUT_ID,o.classList.add("text-input-styling","text-input-placeholder"),o.innerText=((n=t==null?void 0:t.placeholder)==null?void 0:n.text)||"Ask me anything!",we.IS_CHROMIUM&&e.preventAutomaticScrollUpOnNewLine(o),typeof(t==null?void 0:t.disabled)=="boolean"&&t.disabled===!0?(o.contentEditable="false",o.classList.add("text-input-disabled")):(o.contentEditable="true",this.addEventListeners(o,t)),Object.assign(o.style,(r=t==null?void 0:t.styles)==null?void 0:r.text),Object.assign(o.style,(a=t==null?void 0:t.placeholder)==null?void 0:a.style),o}},{key:"removeTextIfPlaceholder",value:function(){var t,n,r,a;this.inputElementRef.classList.contains("text-input-placeholder")&&!this.inputElementRef.classList.contains("text-input-disabled")&&((t=this._config.placeholder)!=null&&t.style&&(ie.unsetStyle(this.inputElementRef,(n=this._config.placeholder)==null?void 0:n.style),Object.assign(this.inputElementRef.style,(a=(r=this._config)==null?void 0:r.styles)==null?void 0:a.text)),e.clear(this.inputElementRef),this.inputElementRef.classList.remove("text-input-placeholder"))}},{key:"addEventListeners",value:function(t,n){var r,a,o;t.onfocus=this.onFocus.bind(this,(r=n==null?void 0:n.styles)==null?void 0:r.focus),(a=n==null?void 0:n.styles)!=null&&a.focus&&(t.onblur=this.onBlur.bind(this,n.styles.focus,(o=n==null?void 0:n.styles)==null?void 0:o.container)),t.addEventListener("keydown",this.onKeydown.bind(this)),t.onpaste=as.sanitizePastedTextContent}},{key:"onFocus",value:function(t){var n=this;we.IS_SAFARI?setTimeout(function(){n.removeTextIfPlaceholder()}):this.removeTextIfPlaceholder(),Object.assign(this.elementRef.style,t)}},{key:"onBlur",value:function(t,n){ie.unsetStyle(this.elementRef,t),n&&Object.assign(this.elementRef.style,n)}},{key:"onKeydown",value:function(t){var n;t.key===ne.ENTER&&!t.ctrlKey&&!t.shiftKey&&(t.preventDefault(),(n=this.submit)==null||n.call(this))}}],[{key:"processConfig",value:function(t,n){var r,a,o,s,l;return(r=n)!==null&&r!==void 0||(n={}),(a=n.disabled)!==null&&a!==void 0||(n.disabled=t.isTextInputDisabled),(o=n.placeholder)!==null&&o!==void 0||(n.placeholder={}),(s=(l=n.placeholder).text)!==null&&s!==void 0||(l.text=t.textInputPlaceholderText),n}},{key:"preventAutomaticScrollUpOnNewLine",value:function(t){var n;t.addEventListener("keydown",function(){n=window.scrollY}),t.addEventListener("input",function(){n!==window.scrollY&&window.scrollTo({top:n})})}},{key:"clear",value:function(t){var n=window.scrollY;t.classList.contains("text-input-disabled")||(t.textContent=""),we.IS_CHROMIUM&&window.scrollTo({top:n})}},{key:"toggleEditability",value:function(t,n){t.contentEditable=n?"true":"false"}},{key:"createContainerElement",value:function(t){var n=document.createElement("div");return n.id="text-input-container",Object.assign(n.style,t),n}}]),e}();gi.TEXT_INPUT_ID="text-input";var Nn=gi,yi=function(){function e(){g(this,e)}return y(e,null,[{key:"focusEndOfInput",value:function(t){var n=document.createRange();n.selectNodeContents(t),n.collapse(!1);var r=window.getSelection();r==null||r.removeAllRanges(),r==null||r.addRange(n)}},{key:"focusFromParentElement",value:function(t){var n=t.querySelector("#".concat(Nn.TEXT_INPUT_ID));n&&e.focusEndOfInput(n)}}]),e}();function cr(e){return e.charAt(0).toUpperCase()+e.slice(1)}function os(e){return e&&JSON.stringify(e)}function Dn(e,i,t,n){var r=`
`.concat(cr(i)," message: ").concat(JSON.stringify(e),` 
`),a=t?"".concat(cr(i)," message after interceptor: ").concat(os(n),` 
`):"";return r+a}function ss(e,i,t,n){return"".concat(Dn(e,i,t,n),"Make sure the ").concat(i,` message is using the Response format: https://deepchat.dev/docs/connect/#Response 
You can also augment it using the responseInterceptor property: https://deepchat.dev/docs/interceptors#responseInterceptor`)}function ls(e,i,t){var n="response";return"".concat(Dn(e,n,i,t),"Make sure the ").concat(n,' message is using the {text: string} format, e.g: {text: "Model Response"}')}function us(e,i){var t="request";return"".concat(Dn(e,t,i),"Make sure the ").concat(t,' message is using the {body: {text: string}} format, e.g: {body: {text: "Model Response"}}')}var dr=`Make sure the events are using {text: string} or {html: string} format.
You can also augment them using the responseInterceptor property: https://deepchat.dev/docs/interceptors#responseInterceptor`,ee={INVALID_KEY:"Invalid API Key",CONNECTION_FAILED:"Failed to connect",INVALID_RESPONSE:ss,INVALID_MODEL_REQUEST:us,INVALID_MODEL_RESPONSE:ls,INVALID_STREAM_EVENT:dr,INVALID_STREAM_EVENT_MIX:"Cannot mix {text: string} and {html: string} responses.",NO_VALID_STREAM_EVENTS_SENT:`No valid stream events were sent.
`.concat(dr)},bi=function(){function e(){g(this,e)}return y(e,null,[{key:"addElements",value:function(t){for(var n=arguments.length,r=new Array(n>1?n-1:0),a=1;a<n;a++)r[a-1]=arguments[a];r.forEach(function(o){return t.appendChild(o)})}},{key:"isScrollbarAtBottomOfElement",value:function(t){var n=t.scrollHeight,r=t.clientHeight,a=t.scrollTop,o=n-r;return a>=o-e.CODE_SNIPPET_GENERATION_JUMP}},{key:"cloneElement",value:function(t){var n=t.cloneNode(!0);return t.parentNode.replaceChild(n,t),n}},{key:"scrollToBottom",value:function(t){t.scrollTop=t.scrollHeight}},{key:"scrollToTop",value:function(t){t.scrollTop=0}}]),e}();bi.CODE_SNIPPET_GENERATION_JUMP=.5;var he=bi,ki=function(){function e(){g(this,e)}return y(e,null,[{key:"speak",value:function(t,n){if(window.SpeechSynthesisUtterance){var r=new SpeechSynthesisUtterance(t);Object.assign(r,n),speechSynthesis.speak(r)}}},{key:"processConfig",value:function(t,n){var r={};setTimeout(function(){if(R(t)=="object"&&(t.lang&&(r.lang=t.lang),t.pitch&&(r.pitch=t.pitch),t.rate&&(r.rate=t.rate),t.volume&&(r.volume=t.volume),t.voiceName)){var a=window.speechSynthesis.getVoices().find(function(o){var s;return o.name.toLocaleLowerCase()===((s=t.voiceName)==null?void 0:s.toLocaleLowerCase())});a&&(r.voice=a)}n(r)},e.LOAD_VOICES_MS)}}]),e}();ki.LOAD_VOICES_MS=200;var xt=ki,Re=function(){function e(){g(this,e)}return y(e,null,[{key:"checkForContainerStyles",value:function(t,n){var r=t.containerStyle;r&&(Object.assign(n.style,r),console.error("The containerStyle property is deprecated since version 1.3.14."),console.error("Please change to using the style property instead: https://deepchat.dev/docs/styles#style"))}},{key:"handleResponseProperty",value:function(t){return console.error("The {result: ....} response object type is deprecated since version 1.3.0."),console.error("Please change to using the new response object: https://deepchat.dev/docs/connect#Response"),t.result}},{key:"processInitialMessageFile",value:function(t){var n=t.file;n&&(console.error("The file property in MessageContent is deprecated since version 1.3.17."),console.error("Please change to using the files array property: https://deepchat.dev/docs/messages/#MessageContent"),t.files=[n])}},{key:"processValidateInput",value:function(t){var n=t.validateMessageBeforeSending;if(n)return console.error("The validateMessageBeforeSending property is deprecated since version 1.3.24."),console.error("Please change to using validateInput: https://deepchat.dev/docs/interceptors#validateInput"),n}},{key:"processSubmitUserMessage",value:function(t){return console.error("The submitUserMessage(text: string) argument string type is deprecated since version 1.4.4."),console.error("Please change to using the new argument type: https://deepchat.dev/docs/methods#submitUserMessage"),{text:t}}},{key:"flagHTMLUpdateClass",value:function(t){var n;(n=t.children[0])!=null&&n.classList.contains("deep-chat-update-message")&&(console.error('The "deep-chat-update-message" html class is deprecated since version 1.4.4.'),console.error("Please change to using {..., overwrite: true} object: https://deepchat.dev/docs/connect#Response"))}}]),e}(),cs="data:image/svg+xml;base64,PD94bWwgdmVyc2lvbj0iMS4wIiBlbmNvZGluZz0iaXNvLTg4NTktMSI/Pgo8c3ZnIGZpbGw9IiMwMDAwMDAiIHZlcnNpb249IjEuMSIgaWQ9IkxheWVyXzEiIHhtbG5zPSJodHRwOi8vd3d3LnczLm9yZy8yMDAwL3N2ZyIgeG1sbnM6eGxpbms9Imh0dHA6Ly93d3cudzMub3JnLzE5OTkveGxpbmsiIAoJCXZpZXdCb3g9IjAgMCAzMiAzMiIgeG1sOnNwYWNlPSJwcmVzZXJ2ZSI+Cgk8cGF0aCBkPSJNMjMsMzAuMzZIOWMtMi40MDQsMC00LjM2LTEuOTU2LTQuMzYtNC4zNlYxNWMwLTIuNDA0LDEuOTU2LTQuMzYsNC4zNi00LjM2aDMuNjU5CgkJYzAuMTY3LTEuNTY2LDEuNDE1LTIuODEzLDIuOTgxLTIuOTgxVjUuMzMzYy0xLjEzMS0wLjE3NC0yLTEuMTU0LTItMi4zMzNjMC0xLjMwMSwxLjA1OS0yLjM2LDIuMzYtMi4zNgoJCWMxLjMwMiwwLDIuMzYsMS4wNTksMi4zNiwyLjM2YzAsMS4xNzktMC44NjksMi4xNTktMiwyLjMzM1Y3LjY2YzEuNTY2LDAuMTY3LDIuODE0LDEuNDE1LDIuOTgxLDIuOTgxSDIzCgkJYzIuNDA0LDAsNC4zNiwxLjk1Niw0LjM2LDQuMzZ2MTFDMjcuMzYsMjguNDA0LDI1LjQwNCwzMC4zNiwyMywzMC4zNnogTTksMTEuMzZjLTIuMDA3LDAtMy42NCwxLjYzMy0zLjY0LDMuNjR2MTEKCQljMCwyLjAwNywxLjYzMywzLjY0LDMuNjQsMy42NGgxNGMyLjAwNywwLDMuNjQtMS42MzMsMy42NC0zLjY0VjE1YzAtMi4wMDctMS42MzMtMy42NC0zLjY0LTMuNjRIOXogTTEzLjM4NCwxMC42NGg1LjIzMQoJCUMxOC40MzksOS4zNTQsMTcuMzM0LDguMzYsMTYsOC4zNkMxNC42NjcsOC4zNiwxMy41NjEsOS4zNTQsMTMuMzg0LDEwLjY0eiBNMTYsMS4zNmMtMC45MDQsMC0xLjY0LDAuNzM2LTEuNjQsMS42NAoJCVMxNS4wOTYsNC42NCwxNiw0LjY0YzAuOTA0LDAsMS42NC0wLjczNiwxLjY0LTEuNjRTMTYuOTA0LDEuMzYsMTYsMS4zNnogTTIwLDI3LjM2aC04Yy0xLjMwMSwwLTIuMzYtMS4wNTktMi4zNi0yLjM2CgkJczEuMDU5LTIuMzYsMi4zNi0yLjM2aDhjMS4zMDIsMCwyLjM2LDEuMDU5LDIuMzYsMi4zNlMyMS4zMDIsMjcuMzYsMjAsMjcuMzZ6IE0xMiwyMy4zNmMtMC45MDQsMC0xLjY0LDAuNzM1LTEuNjQsMS42NAoJCXMwLjczNiwxLjY0LDEuNjQsMS42NGg4YzAuOTA0LDAsMS42NC0wLjczNSwxLjY0LTEuNjRzLTAuNzM1LTEuNjQtMS42NC0xLjY0SDEyeiBNMzEsMjMuODZoLTJjLTAuMTk5LDAtMC4zNi0wLjE2MS0wLjM2LTAuMzZWMTUKCQljMC0wLjE5OSwwLjE2MS0wLjM2LDAuMzYtMC4zNmgyYzAuMTk5LDAsMC4zNiwwLjE2MSwwLjM2LDAuMzZ2OC41QzMxLjM2LDIzLjY5OSwzMS4xOTksMjMuODYsMzEsMjMuODZ6IE0yOS4zNiwyMy4xNGgxLjI3OXYtNy43OAoJCUgyOS4zNlYyMy4xNHogTTMsMjMuODZIMWMtMC4xOTksMC0wLjM2LTAuMTYxLTAuMzYtMC4zNlYxNWMwLTAuMTk5LDAuMTYxLTAuMzYsMC4zNi0wLjM2aDJjMC4xOTksMCwwLjM2LDAuMTYxLDAuMzYsMC4zNnY4LjUKCQlDMy4zNiwyMy42OTksMy4xOTksMjMuODYsMywyMy44NnogTTEuMzYsMjMuMTRoMS4yOHYtNy43OEgxLjM2VjIzLjE0eiBNMjAsMjAuMzZjLTEuMzAyLDAtMi4zNi0xLjA1OS0yLjM2LTIuMzYKCQlzMS4wNTktMi4zNiwyLjM2LTIuMzZzMi4zNiwxLjA1OSwyLjM2LDIuMzZDMjIuMzYsMTkuMzAyLDIxLjMwMiwyMC4zNiwyMCwyMC4zNnogTTIwLDE2LjM2Yy0wLjkwNCwwLTEuNjQsMC43MzYtMS42NCwxLjY0CgkJczAuNzM1LDEuNjQsMS42NCwxLjY0czEuNjQtMC43MzUsMS42NC0xLjY0UzIwLjkwNCwxNi4zNiwyMCwxNi4zNnogTTEyLDIwLjM2Yy0xLjMwMSwwLTIuMzYtMS4wNTktMi4zNi0yLjM2czEuMDU5LTIuMzYsMi4zNi0yLjM2CgkJczIuMzYsMS4wNTksMi4zNiwyLjM2QzE0LjM2LDE5LjMwMiwxMy4zMDEsMjAuMzYsMTIsMjAuMzZ6IE0xMiwxNi4zNmMtMC45MDQsMC0xLjY0LDAuNzM2LTEuNjQsMS42NHMwLjczNiwxLjY0LDEuNjQsMS42NAoJCXMxLjY0LTAuNzM1LDEuNjQtMS42NFMxMi45MDQsMTYuMzYsMTIsMTYuMzZ6Ii8+Cgk8cmVjdCBzdHlsZT0iZmlsbDpub25lOyIgd2lkdGg9IjMyIiBoZWlnaHQ9IjMyIi8+Cjwvc3ZnPg==",ds="data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAPoAAAD6CAMAAAC/MqoPAAAABGdBTUEAALGPC/xhBQAAAAFzUkdCAK7OHOkAAAAgY0hSTQAAeiYAAICEAAD6AAAAgOgAAHUwAADqYAAAOpgAABdwnLpRPAAAADNQTFRF////9vX18vLy/Pz86enp4+Li2tnZ1tbWzczM+fn57Ozs4N/f09LS0M/P5uXl7+/v3dzcwtncCAAAAAFiS0dEAIgFHUgAAAAJcEhZcwAAAEgAAABIAEbJaz4AAAZNSURBVHja7d3bdtsqEABQYABZSLH9/3+ZpnUsIcF5iOM6PfElNoMHMfPQdq3GmL0GkLhEUqLaUExnOtOZznSmM53pTGc605nOdKYznelMZzrTmV4LXSqllKyJDkob26xWq8Zae/iH0QoWTm9d1xur4WuypQJtTd+5dqn0VjcxzNO5/57mEBvdLo8Oron6aseWOjYOFkVvjQs3DmgyONMuht52EfztP+4hdu0i6LCO808/M8c1lE/fuPGej41uUzgdtoO/75N+2ELJ9I3b3//hPXbiMenm3pR/Jt4USgcLBIp4Bh10gqKVhvLo0klCxeSky96nKcj3siw6pJIL4XsoiQ7apyvMY/V3HHrSRioLopvEhSpTCn2TPEuwKYMOIX0tAxRBf/Hpa+lfSqBv9gi1FPsNfTrMAiVmIE/vJhz61FGnQxRIEYE4vfNYdN8Rp6MlHaHotHTn8ejekaZPAjEmyvQWdZFTtYTpXqCGJ0zvcek9Yfoel76nS0ffv1NMp1ca+pkgyfRCGind4L7OWWc605l+cxjsyhqy9AGbPpClc1/nvl5VX0c/3Alk6RU3+Am7shNZ+h6bvidLr7jBB+zKBrL0irOOudmIUDzTmf5gIP+iEuXtRuTVaEmY/oZLfyNMrzjryPc0gerMTdpVg0tvjJUU6bLPcGOoUv46SLL6Wi8yhLf06C7TUyekI0efRaaYqdFltkeNpPumRPSMDxgBYvSM035FrKAmH72hRW99PrpvSdEHkTEGUvSsK3yKVDkuJ92RohcZaehzzirPpOg+J92Tolfc4Cumx5xVXpGiZ34+ICX6W84qv5GiR5NPbiIpOv6BCoSvSkTX+eiaGP092zINvBOj4x8mSf9FqejvNo/cvpOji19ZbmviL0GPLsYMFzgzCor0+Bv/ePDvSJKOb9dJ5UlnbnEHiHgzv6cdTpJOWuc/u3FEucLDOL75xGtBiefrcwgoC9NDSH/jkH6pAuXmBqPQ9HSUPVdZBH1GGOrMXAQdYxcKZfxAoK+KKBKFLosoEoX+u4giUehz8jlcnAuhp78I46yDYNAd+QLR6K+pr+yvxdBTHyVDubQh0UfSxaHSd0lbvNkVRE87JGOtc+PQd2QLQ6fHhJkKsSh6yg13tO08JPprsgrrXWH0dJd2vH1MLPprot4eXoujpzrdhngiD40ek2y92lggPcnWa8qN1Yz0BFuvZhRl0uOfR0v4Ewuli/Bg4Qr3lArqGdndQ3UPO1EunXYwnelMZzrTmc50pjOd6UxnOtOZznSmM53pTGf6kuj6oedFKV0s3fX6sX1S3bsi6a4PD7+/YAqYeBw6pIB/4qEgOqxdSPbGiim4NRRCbzs3Jj0L4UfXtQXQVRfn5IdA/Bw7RZzurEV6EtdsLeGXkIPuA+K1UoVeA0l62zmN/LqfSSft9KkepmoRuvi3nd5uKNFB9zbbXEANqdr941XO0NJx2v2jdJenpf+/3bvn0ts16ph+sd6hX7dPo2+2cZzE02Ia43bzDHqr+2Evnhz74ZHU30ffbKOeng1/NPV30Ns1gYQnSP2P6e65Pfxc6h02XZqXQCjhJ6kPL6bFo4NrGvAU4UII4SE2P1vQuZkuOxckVfehisF1MjUddN/MZBN+kvq5uf0O/xa66gyNS9ktMWlz44rO1Z8C19i5FPdHzPamXn+F3hryPfxMr78+4F+kq22kO6Rf6fUQt+puuustyWv4rbG3l/duztFB96GYoe1cTBdXMr+nw9qVM6ZfxOvzezff0nXi/ZOndvrR6Zvpm0c3h6nhdb+5iS7tsIim/qXZD9+97/Jf+rpZ5BET1ayv0GUzLhEuhBBjIy/RdVPgndutIRt9nt7p5cKFEEJ3Z+jQFDZL+XnMDXxHB73gxn5s9Kc3d3/pFciFkN/QTSXHJpX5l66gDrkQoP6hL3xsPw39la4qOiV8tH78XeSbue6N9mvWa6J/ybpc1CT1Wnh5Qq9meP8IOKH3ddH7E/ri1iYux/SXDrXR4UiPdck/wUpU+FtPf6/orja6O9KL3l56LOvVxe5Ib2qjN0d6Vbex4ghWlU3bPqI90If66MNng680FNpbJijH6kCvaF3uMzQ3+IrpFerV4Y9dffQdN3im10ivbuImhD3Qq5u4HdZkua8znelMZ/pS4z9CPVKkxowNxgAAACV0RVh0ZGF0ZTpjcmVhdGUAMjAxNy0wMy0yN1QxNTo0NToxNSswMDowMN1xSg4AAAAldEVYdGRhdGU6bW9kaWZ5ADIwMTctMDMtMjdUMTU6NDU6MTUrMDA6MDCsLPKyAAAAGXRFWHRTb2Z0d2FyZQBBZG9iZSBJbWFnZVJlYWR5ccllPAAAAABJRU5ErkJggg==",_i=function(){function e(){g(this,e)}return y(e,null,[{key:"hide",value:function(t){t.getElementsByClassName(e.CONTAINER_CLASS)[0].style.visibility="hidden"}},{key:"applyCustomStylesToElements",value:function(t,n,r){Object.assign(t.style,r.container),Object.assign(n.style,r.avatar)}},{key:"applyCustomStyles",value:function(t,n,r,a){var o,s,l,u;if((o=r.default)!=null&&o.styles&&e.applyCustomStylesToElements(t,n,r.default.styles),a===F.USER_ROLE)(s=r.user)!=null&&s.styles&&e.applyCustomStylesToElements(t,n,r.user.styles);else{(l=r.ai)!=null&&l.styles&&e.applyCustomStylesToElements(t,n,r.ai.styles);var c=(u=r[a])==null?void 0:u.styles;c&&e.applyCustomStylesToElements(t,n,c)}}},{key:"createAvatar",value:function(t,n){var r,a,o,s,l,u=document.createElement("img");t===F.USER_ROLE?u.src=((r=n==null?void 0:n.user)==null?void 0:r.src)||((a=n==null?void 0:n.default)==null?void 0:a.src)||ds:u.src=((o=n==null?void 0:n[t])==null?void 0:o.src)||((s=n==null?void 0:n.ai)==null?void 0:s.src)||((l=n==null?void 0:n.default)==null?void 0:l.src)||cs,u.classList.add("avatar");var c=document.createElement("div");return c.classList.add(e.CONTAINER_CLASS),c.appendChild(u),n&&e.applyCustomStyles(c,u,n,t),c}},{key:"getPosition",value:function(t,n){var r,a,o,s,l,u,c,d,h,p=(l=(s=n==null?void 0:n[t])==null?void 0:s.styles)==null?void 0:l.position;return t!==F.USER_ROLE&&((r=p)!==null&&r!==void 0||(p=(c=(u=n==null?void 0:n.ai)==null?void 0:u.styles)==null?void 0:c.position)),(a=p)!==null&&a!==void 0||(p=(h=(d=n==null?void 0:n.default)==null?void 0:d.styles)==null?void 0:h.position),(o=p)!==null&&o!==void 0||(p=t===F.USER_ROLE?"right":"left"),p}},{key:"add",value:function(t,n,r){var a=typeof r=="boolean"?void 0:r,o=e.createAvatar(n,a),s=e.getPosition(n,a);o.classList.add(s==="left"?"left-item-position":"right-item-position"),t.insertAdjacentElement(s==="left"?"beforebegin":"afterend",o)}}]),e}();_i.CONTAINER_CLASS="avatar-container";var hr=_i,wi=function(){function e(){g(this,e)}return y(e,null,[{key:"hide",value:function(t){t.getElementsByClassName(e.NAME_CLASS)[0].style.visibility="hidden"}},{key:"getPosition",value:function(t,n){var r,a,o,s,l,u,c=(s=n==null?void 0:n[t])==null?void 0:s.position;return t!==F.USER_ROLE&&((r=c)!==null&&r!==void 0||(c=(l=n==null?void 0:n.ai)==null?void 0:l.position)),(a=c)!==null&&a!==void 0||(c=(u=n==null?void 0:n.default)==null?void 0:u.position),(o=c)!==null&&o!==void 0||(c=t===F.USER_ROLE?"right":"left"),c}},{key:"applyStyle",value:function(t,n,r){var a,o,s,l;Object.assign(t.style,(a=r.default)==null?void 0:a.style),n===F.USER_ROLE?Object.assign(t.style,(o=r.user)==null?void 0:o.style):(Object.assign(t.style,(s=r.ai)==null?void 0:s.style),Object.assign(t.style,(l=r[n])==null?void 0:l.style))}},{key:"getNameText",value:function(t,n){var r,a,o,s,l,u;return t===F.USER_ROLE?((r=n.user)==null?void 0:r.text)||((a=n.default)==null?void 0:a.text)||"User":t===F.AI_ROLE?((o=n.ai)==null?void 0:o.text)||((s=n.default)==null?void 0:s.text)||"AI":((l=n[t])==null?void 0:l.text)||((u=n.default)==null?void 0:u.text)||t}},{key:"createName",value:function(t,n){var r=document.createElement("div");return r.classList.add(e.NAME_CLASS),r.textContent=e.getNameText(t,n),e.applyStyle(r,t,n),r}},{key:"add",value:function(t,n,r){var a=typeof r=="boolean"?{}:r,o=e.createName(n,a),s=e.getPosition(n,a);o.classList.add(s==="left"?"left-item-position":"right-item-position"),t.insertAdjacentElement(s==="left"?"beforebegin":"afterend",o)}}]),e}();wi.NAME_CLASS="name";var pr=wi,Ot=function(){function e(){g(this,e)}return y(e,null,[{key:"getLastElementsByClass",value:function(t,n,r){for(var a=function(){var u=t[s];if(u.bubbleElement.classList.contains(n[0])&&!n.slice(1).find(function(c){return!u.bubbleElement.classList.contains(c)}))if(r){if(!r.find(function(c){return u.bubbleElement.classList.contains(c)}))return{v:u}}else return{v:u}},o,s=t.length-1;s>=0;s-=1)if(o=a(),o)return o.v}},{key:"getLastMessage",value:function(t,n,r){for(var a=t.length-1;a>=0;a-=1)if(t[a].role===n)if(r){if(t[a][r])return t[a]}else return t[a]}},{key:"getLastTextToElement",value:function(t,n){for(var r=t.length-1;r>=0;r-=1)if(t[r][0]===n)return t[r]}},{key:"overwriteMessage",value:function(t,n,r,a,o,s){var l=e.getLastElementsByClass(n,[e.getRoleClass(a),s],["loading-message-text"]),u=e.getLastMessage(t,a,o);return u&&(u[o]=r),l}},{key:"getRoleClass",value:function(t){return"".concat(t,"-message")}},{key:"fillEmptyMessageElement",value:function(t,n){n.trim().length===0&&(t.classList.add(e.EMPTY_MESSAGE_CLASS),t.innerHTML='<div style="color:#00000000">.</div>')}},{key:"unfillEmptyMessageElement",value:function(t,n){t.classList.contains(e.EMPTY_MESSAGE_CLASS)&&n.trim().length>0&&t.replaceChildren()}},{key:"getLastMessageBubbleElement",value:function(t){var n,r,a;return Array.from(((a=(r=(n=e.getLastMessageElement(t))==null?void 0:n.children)==null?void 0:r[0])==null?void 0:a.children)||[]).find(function(o){return o.classList.contains("message-bubble")})}},{key:"getLastMessageElement",value:function(t){return t.children[t.children.length-1]}},{key:"addRoleElements",value:function(t,n,r,a){r&&hr.add(t,n,r),a&&pr.add(t,n,a)}},{key:"hideRoleElements",value:function(t,n,r){var a=t[t.length-1].innerContainer;n&&hr.hide(a),r&&pr.hide(a)}}]),e}();Ot.AI_ROLE="ai";Ot.USER_ROLE="user";Ot.EMPTY_MESSAGE_CLASS="empty-message";var F=Ot,Si=function(){function e(){g(this,e)}return y(e,null,[{key:"mouseUp",value:function(t,n){ie.unsetAllCSSMouseStates(t,n),Object.assign(t.style,n.default),Object.assign(t.style,n.hover)}},{key:"mouseDown",value:function(t,n){Object.assign(t.style,n.click)}},{key:"mouseLeave",value:function(t,n){ie.unsetAllCSSMouseStates(t,n),Object.assign(t.style,n.default)}},{key:"mouseEnter",value:function(t,n){Object.assign(t.style,n.hover)}},{key:"add",value:function(t,n){t.addEventListener("mouseenter",e.mouseEnter.bind(this,t,n)),t.addEventListener("mouseleave",e.mouseLeave.bind(this,t,n)),t.addEventListener("mousedown",e.mouseDown.bind(this,t,n)),t.addEventListener("mouseup",e.mouseUp.bind(this,t,n))}}]),e}(),hs="deep-chat-temporary-message",ps="deep-chat-suggestion-button",Sn={"deep-chat-button":{styles:{default:{backgroundColor:"white",padding:"5px",paddingLeft:"7px",paddingRight:"7px",border:"1px solid #c2c2c2",borderRadius:"6px",cursor:"pointer"},hover:{backgroundColor:"#fafafa"},click:{backgroundColor:"#f1f1f1"}}}},fr=Object.keys(Sn),Ct=function(){function e(){g(this,e)}return y(e,null,[{key:"applySuggestionEvent",value:function(t,n){setTimeout(function(){n.addEventListener("click",function(){var r,a;(a=t.submitUserMessage)==null||a.call(t,{text:((r=n.textContent)==null?void 0:r.trim())||""})})})}},{key:"isElementTemporary",value:function(t){var n;return t?(n=t.bubbleElement.children[0])==null?void 0:n.classList.contains(hs):!1}},{key:"doesElementContainDeepChatClass",value:function(t){return fr.find(function(n){return t.classList.contains(n)})}},{key:"applyEvents",value:function(t,n){var r=Sn[n].events;Object.keys(r||[]).forEach(function(a){t.addEventListener(a,r==null?void 0:r[a])})}},{key:"getProcessedStyles",value:function(t,n,r){var a=Array.from(n.classList).reduce(function(u,c){var d,h=(d=t[c])==null?void 0:d.styles;return h&&t[c].styles&&u.push(h),u},[]),o=Sn[r].styles;if(o){var s=JSON.parse(JSON.stringify(o));s.default&&ie.overwriteDefaultWithAlreadyApplied(s,n),a.unshift(s)}var l=ie.mergeStatefulStyles(a);return ie.processStateful(l,{},{})}},{key:"applyDeepChatUtilities",value:function(t,n,r){fr.forEach(function(o){var s=r.getElementsByClassName(o);Array.from(s||[]).forEach(function(l){var u=e.getProcessedStyles(n,l,o);at.applyStylesToElement(l,u),e.applyEvents(l,o)})});var a=r.getElementsByClassName(ps);Array.from(a).forEach(function(o){return e.applySuggestionEvent(t,o)})}}]),e}(),at=function(){function e(){g(this,e)}return y(e,null,[{key:"applyStylesToElement",value:function(t,n){var r=ie.processStateful(n,{},{});Si.add(t,r),Object.assign(t.style,r.default)}},{key:"applyEventsToElement",value:function(t,n){Object.keys(n).forEach(function(r){var a=n[r];a&&t.addEventListener(r,a)})}},{key:"applyClassUtilitiesToElement",value:function(t,n){var r=n.events,a=n.styles;r&&e.applyEventsToElement(t,r),a&&!Ct.doesElementContainDeepChatClass(t)&&e.applyStylesToElement(t,a)}},{key:"applyCustomClassUtilities",value:function(t,n){Object.keys(t).forEach(function(r){var a=n.getElementsByClassName(r);Array.from(a).forEach(function(o){t[r]&&e.applyClassUtilitiesToElement(o,t[r])})})}},{key:"apply",value:function(t,n){Ct.applyDeepChatUtilities(t,t.htmlClassUtilities,n),e.applyCustomClassUtilities(t.htmlClassUtilities,n)}}]),e}(),xn=function(){function e(){g(this,e)}return y(e,null,[{key:"addElement",value:function(t,n){t.elementRef.appendChild(n),t.elementRef.scrollTop=t.elementRef.scrollHeight}},{key:"createElements",value:function(t,n,r){var a=t.createNewMessageElement("",r);return a.bubbleElement.classList.add("html-message"),a.bubbleElement.innerHTML=n,a}},{key:"overwrite",value:function(t,n,r,a){var o=t.messages,s=F.overwriteMessage(o,a,n,r,"html","html-message");return s&&(s.bubbleElement.innerHTML=n,at.apply(t,s.outerContainer),Re.flagHTMLUpdateClass(s.bubbleElement)),s}},{key:"add",value:function(t,n,r,a,o){var s;if(o!=null&&o.status){var l=this.overwrite(t,n,r,a);if(l)return l;o.status=!1}var u=e.createElements(t,n,r);return F.fillEmptyMessageElement(u.bubbleElement,n),at.apply(t,u.outerContainer),Re.flagHTMLUpdateClass(u.bubbleElement),t.applyCustomStyles(u,r,!1,(s=t.messageStyles)==null?void 0:s.html),e.addElement(t,u.outerContainer),u}}]),e}(),kt;function xi(e){return kt=kt||document.createElement("textarea"),kt.innerHTML="&"+e+";",kt.value}var fs=Object.prototype.hasOwnProperty;function vs(e,i){return e?fs.call(e,i):!1}function Ei(e){var i=[].slice.call(arguments,1);return i.forEach(function(t){if(t){if(R(t)!="object")throw new TypeError(t+"must be object");Object.keys(t).forEach(function(n){e[n]=t[n]})}}),e}var ms=/\\([\\!"#$%&'()*+,.\/:;<=>?@[\]^_`{|}~-])/g;function ot(e){return e.indexOf("\\")<0?e:e.replace(ms,"$1")}function Ci(e){return!(e>=55296&&e<=57343||e>=64976&&e<=65007||(e&65535)===65535||(e&65535)===65534||e>=0&&e<=8||e===11||e>=14&&e<=31||e>=127&&e<=159||e>1114111)}function En(e){if(e>65535){e-=65536;var i=55296+(e>>10),t=56320+(e&1023);return String.fromCharCode(i,t)}return String.fromCharCode(e)}var gs=/&([a-z#][a-z0-9]{1,31});/gi,ys=/^#((?:x[a-f0-9]{1,8}|[0-9]{1,8}))/i;function bs(e,i){var t=0,n=xi(i);return i!==n?n:i.charCodeAt(0)===35&&ys.test(i)&&(t=i[1].toLowerCase()==="x"?parseInt(i.slice(2),16):parseInt(i.slice(1),10),Ci(t))?En(t):e}function Oe(e){return e.indexOf("&")<0?e:e.replace(gs,bs)}var ks=/[&<>"]/,_s=/[&<>"]/g,ws={"&":"&amp;","<":"&lt;",">":"&gt;",'"':"&quot;"};function Ss(e){return ws[e]}function ue(e){return ks.test(e)?e.replace(_s,Ss):e}var T={};T.blockquote_open=function(){return`<blockquote>
`};T.blockquote_close=function(e,i){return"</blockquote>"+Be(e,i)};T.code=function(e,i){return e[i].block?"<pre><code>"+ue(e[i].content)+"</code></pre>"+Be(e,i):"<code>"+ue(e[i].content)+"</code>"};T.fence=function(e,i,t,n,r){var a=e[i],o="",s=t.langPrefix,l="",u,c,d;if(a.params){if(u=a.params.split(/\s+/g),c=u.join(" "),vs(r.rules.fence_custom,u[0]))return r.rules.fence_custom[u[0]](e,i,t,n,r);l=ue(Oe(ot(c))),o=' class="'+s+l+'"'}return t.highlight?d=t.highlight.apply(t.highlight,[a.content].concat(u))||ue(a.content):d=ue(a.content),"<pre><code"+o+">"+d+"</code></pre>"+Be(e,i)};T.fence_custom={};T.heading_open=function(e,i){return"<h"+e[i].hLevel+">"};T.heading_close=function(e,i){return"</h"+e[i].hLevel+`>
`};T.hr=function(e,i,t){return(t.xhtmlOut?"<hr />":"<hr>")+Be(e,i)};T.bullet_list_open=function(){return`<ul>
`};T.bullet_list_close=function(e,i){return"</ul>"+Be(e,i)};T.list_item_open=function(){return"<li>"};T.list_item_close=function(){return`</li>
`};T.ordered_list_open=function(e,i){var t=e[i],n=t.order>1?' start="'+t.order+'"':"";return"<ol"+n+`>
`};T.ordered_list_close=function(e,i){return"</ol>"+Be(e,i)};T.paragraph_open=function(e,i){return e[i].tight?"":"<p>"};T.paragraph_close=function(e,i){var t=!(e[i].tight&&i&&e[i-1].type==="inline"&&!e[i-1].content);return(e[i].tight?"":"</p>")+(t?Be(e,i):"")};T.link_open=function(e,i,t){var n=e[i].title?' title="'+ue(Oe(e[i].title))+'"':"",r=t.linkTarget?' target="'+t.linkTarget+'"':"";return'<a href="'+ue(e[i].href)+'"'+n+r+">"};T.link_close=function(){return"</a>"};T.image=function(e,i,t){var n=' src="'+ue(e[i].src)+'"',r=e[i].title?' title="'+ue(Oe(e[i].title))+'"':"",a=' alt="'+(e[i].alt?ue(Oe(ot(e[i].alt))):"")+'"',o=t.xhtmlOut?" /":"";return"<img"+n+a+r+o+">"};T.table_open=function(){return`<table>
`};T.table_close=function(){return`</table>
`};T.thead_open=function(){return`<thead>
`};T.thead_close=function(){return`</thead>
`};T.tbody_open=function(){return`<tbody>
`};T.tbody_close=function(){return`</tbody>
`};T.tr_open=function(){return"<tr>"};T.tr_close=function(){return`</tr>
`};T.th_open=function(e,i){var t=e[i];return"<th"+(t.align?' style="text-align:'+t.align+'"':"")+">"};T.th_close=function(){return"</th>"};T.td_open=function(e,i){var t=e[i];return"<td"+(t.align?' style="text-align:'+t.align+'"':"")+">"};T.td_close=function(){return"</td>"};T.strong_open=function(){return"<strong>"};T.strong_close=function(){return"</strong>"};T.em_open=function(){return"<em>"};T.em_close=function(){return"</em>"};T.del_open=function(){return"<del>"};T.del_close=function(){return"</del>"};T.ins_open=function(){return"<ins>"};T.ins_close=function(){return"</ins>"};T.mark_open=function(){return"<mark>"};T.mark_close=function(){return"</mark>"};T.sub=function(e,i){return"<sub>"+ue(e[i].content)+"</sub>"};T.sup=function(e,i){return"<sup>"+ue(e[i].content)+"</sup>"};T.hardbreak=function(e,i,t){return t.xhtmlOut?`<br />
`:`<br>
`};T.softbreak=function(e,i,t){return t.breaks?t.xhtmlOut?`<br />
`:`<br>
`:`
`};T.text=function(e,i){return ue(e[i].content)};T.htmlblock=function(e,i){return e[i].content};T.htmltag=function(e,i){return e[i].content};T.abbr_open=function(e,i){return'<abbr title="'+ue(Oe(e[i].title))+'">'};T.abbr_close=function(){return"</abbr>"};T.footnote_ref=function(e,i){var t=Number(e[i].id+1).toString(),n="fnref"+t;return e[i].subId>0&&(n+=":"+e[i].subId),'<sup class="footnote-ref"><a href="#fn'+t+'" id="'+n+'">['+t+"]</a></sup>"};T.footnote_block_open=function(e,i,t){var n=t.xhtmlOut?`<hr class="footnotes-sep" />
`:`<hr class="footnotes-sep">
`;return n+`<section class="footnotes">
<ol class="footnotes-list">
`};T.footnote_block_close=function(){return`</ol>
</section>
`};T.footnote_open=function(e,i){var t=Number(e[i].id+1).toString();return'<li id="fn'+t+'"  class="footnote-item">'};T.footnote_close=function(){return`</li>
`};T.footnote_anchor=function(e,i){var t=Number(e[i].id+1).toString(),n="fnref"+t;return e[i].subId>0&&(n+=":"+e[i].subId),' <a href="#'+n+'" class="footnote-backref">↩</a>'};T.dl_open=function(){return`<dl>
`};T.dt_open=function(){return"<dt>"};T.dd_open=function(){return"<dd>"};T.dl_close=function(){return`</dl>
`};T.dt_close=function(){return`</dt>
`};T.dd_close=function(){return`</dd>
`};function Mi(e,i){return++i>=e.length-2?i:e[i].type==="paragraph_open"&&e[i].tight&&e[i+1].type==="inline"&&e[i+1].content.length===0&&e[i+2].type==="paragraph_close"&&e[i+2].tight?Mi(e,i+2):i}var Be=T.getBreak=function(e,i){return i=Mi(e,i),i<e.length&&e[i].type==="list_item_close"?"":`
`};function Fn(){this.rules=Ei({},T),this.getBreak=T.getBreak}Fn.prototype.renderInline=function(e,i,t){for(var n=this.rules,r=e.length,a=0,o="";r--;)o+=n[e[a].type](e,a++,i,t,this);return o};Fn.prototype.render=function(e,i,t){for(var n=this.rules,r=e.length,a=-1,o="";++a<r;)e[a].type==="inline"?o+=this.renderInline(e[a].children,i,t):o+=n[e[a].type](e,a,i,t,this);return o};function ve(){this.__rules__=[],this.__cache__=null}ve.prototype.__find__=function(e){for(var i=this.__rules__.length,t=-1;i--;)if(this.__rules__[++t].name===e)return t;return-1};ve.prototype.__compile__=function(){var e=this,i=[""];e.__rules__.forEach(function(t){t.enabled&&t.alt.forEach(function(n){i.indexOf(n)<0&&i.push(n)})}),e.__cache__={},i.forEach(function(t){e.__cache__[t]=[],e.__rules__.forEach(function(n){n.enabled&&(t&&n.alt.indexOf(t)<0||e.__cache__[t].push(n.fn))})})};ve.prototype.at=function(e,i,t){var n=this.__find__(e),r=t||{};if(n===-1)throw new Error("Parser rule not found: "+e);this.__rules__[n].fn=i,this.__rules__[n].alt=r.alt||[],this.__cache__=null};ve.prototype.before=function(e,i,t,n){var r=this.__find__(e),a=n||{};if(r===-1)throw new Error("Parser rule not found: "+e);this.__rules__.splice(r,0,{name:i,enabled:!0,fn:t,alt:a.alt||[]}),this.__cache__=null};ve.prototype.after=function(e,i,t,n){var r=this.__find__(e),a=n||{};if(r===-1)throw new Error("Parser rule not found: "+e);this.__rules__.splice(r+1,0,{name:i,enabled:!0,fn:t,alt:a.alt||[]}),this.__cache__=null};ve.prototype.push=function(e,i,t){var n=t||{};this.__rules__.push({name:e,enabled:!0,fn:i,alt:n.alt||[]}),this.__cache__=null};ve.prototype.enable=function(e,i){e=Array.isArray(e)?e:[e],i&&this.__rules__.forEach(function(t){t.enabled=!1}),e.forEach(function(t){var n=this.__find__(t);if(n<0)throw new Error("Rules manager: invalid rule name "+t);this.__rules__[n].enabled=!0},this),this.__cache__=null};ve.prototype.disable=function(e){e=Array.isArray(e)?e:[e],e.forEach(function(i){var t=this.__find__(i);if(t<0)throw new Error("Rules manager: invalid rule name "+i);this.__rules__[t].enabled=!1},this),this.__cache__=null};ve.prototype.getRules=function(e){return this.__cache__===null&&this.__compile__(),this.__cache__[e]||[]};function xs(e){e.inlineMode?e.tokens.push({type:"inline",content:e.src.replace(/\n/g," ").trim(),level:0,lines:[0,1],children:[]}):e.block.parse(e.src,e.options,e.env,e.tokens)}function qe(e,i,t,n,r){this.src=e,this.env=n,this.options=t,this.parser=i,this.tokens=r,this.pos=0,this.posMax=this.src.length,this.level=0,this.pending="",this.pendingLevel=0,this.cache=[],this.isInLabel=!1,this.linkLevel=0,this.linkContent="",this.labelUnmatchedScopes=0}qe.prototype.pushPending=function(){this.tokens.push({type:"text",content:this.pending,level:this.pendingLevel}),this.pending=""};qe.prototype.push=function(e){this.pending&&this.pushPending(),this.tokens.push(e),this.pendingLevel=this.level};qe.prototype.cacheSet=function(e,i){for(var t=this.cache.length;t<=e;t++)this.cache.push(0);this.cache[e]=i};qe.prototype.cacheGet=function(e){return e<this.cache.length?this.cache[e]:0};function st(e,i){var t,n,r,a=-1,o=e.posMax,s=e.pos,l=e.isInLabel;if(e.isInLabel)return-1;if(e.labelUnmatchedScopes)return e.labelUnmatchedScopes--,-1;for(e.pos=i+1,e.isInLabel=!0,t=1;e.pos<o;){if(r=e.src.charCodeAt(e.pos),r===91)t++;else if(r===93&&(t--,t===0)){n=!0;break}e.parser.skipToken(e)}return n?(a=e.pos,e.labelUnmatchedScopes=0):e.labelUnmatchedScopes=t-1,e.pos=s,e.isInLabel=l,a}function Es(e,i,t,n){var r,a,o,s,l,u;if(e.charCodeAt(0)!==42||e.charCodeAt(1)!==91||e.indexOf("]:")===-1||(r=new qe(e,i,t,n,[]),a=st(r,1),a<0||e.charCodeAt(a+1)!==58))return-1;for(s=r.posMax,o=a+2;o<s&&r.src.charCodeAt(o)!==10;o++);return l=e.slice(2,a),u=e.slice(a+2,o).trim(),u.length===0?-1:(n.abbreviations||(n.abbreviations={}),R(n.abbreviations[":"+l])>"u"&&(n.abbreviations[":"+l]=u),o)}function Cs(e){var i=e.tokens,t,n,r,a;if(!e.inlineMode){for(t=1,n=i.length-1;t<n;t++)if(i[t-1].type==="paragraph_open"&&i[t].type==="inline"&&i[t+1].type==="paragraph_close"){for(r=i[t].content;r.length&&(a=Es(r,e.inline,e.options,e.env),!(a<0));)r=r.slice(a).trim();i[t].content=r,r.length||(i[t-1].tight=!0,i[t+1].tight=!0)}}}function Cn(e){var i=Oe(e);try{i=decodeURI(i)}catch{}return encodeURI(i)}function Ai(e,i){var t,n,r,a=i,o=e.posMax;if(e.src.charCodeAt(i)===60){for(i++;i<o;){if(t=e.src.charCodeAt(i),t===10)return!1;if(t===62)return r=Cn(ot(e.src.slice(a+1,i))),e.parser.validateLink(r)?(e.pos=i+1,e.linkContent=r,!0):!1;if(t===92&&i+1<o){i+=2;continue}i++}return!1}for(n=0;i<o&&(t=e.src.charCodeAt(i),!(t===32||t<32||t===127));){if(t===92&&i+1<o){i+=2;continue}if(t===40&&(n++,n>1)||t===41&&(n--,n<0))break;i++}return a===i||(r=ot(e.src.slice(a,i)),!e.parser.validateLink(r))?!1:(e.linkContent=r,e.pos=i,!0)}function Ti(e,i){var t,n=i,r=e.posMax,a=e.src.charCodeAt(i);if(a!==34&&a!==39&&a!==40)return!1;for(i++,a===40&&(a=41);i<r;){if(t=e.src.charCodeAt(i),t===a)return e.pos=i+1,e.linkContent=ot(e.src.slice(n+1,i)),!0;if(t===92&&i+1<r){i+=2;continue}i++}return!1}function Ii(e){return e.trim().replace(/\s+/g," ").toUpperCase()}function Ms(e,i,t,n){var r,a,o,s,l,u,c,d,h;if(e.charCodeAt(0)!==91||e.indexOf("]:")===-1||(r=new qe(e,i,t,n,[]),a=st(r,0),a<0||e.charCodeAt(a+1)!==58))return-1;for(s=r.posMax,o=a+2;o<s&&(l=r.src.charCodeAt(o),!(l!==32&&l!==10));o++);if(!Ai(r,o))return-1;for(c=r.linkContent,o=r.pos,u=o,o=o+1;o<s&&(l=r.src.charCodeAt(o),!(l!==32&&l!==10));o++);for(o<s&&u!==o&&Ti(r,o)?(d=r.linkContent,o=r.pos):(d="",o=u);o<s&&r.src.charCodeAt(o)===32;)o++;return o<s&&r.src.charCodeAt(o)!==10?-1:(h=Ii(e.slice(1,a)),R(n.references[h])>"u"&&(n.references[h]={title:d,href:c}),o)}function As(e){var i=e.tokens,t,n,r,a;if(e.env.references=e.env.references||{},!e.inlineMode){for(t=1,n=i.length-1;t<n;t++)if(i[t].type==="inline"&&i[t-1].type==="paragraph_open"&&i[t+1].type==="paragraph_close"){for(r=i[t].content;r.length&&(a=Ms(r,e.inline,e.options,e.env),!(a<0));)r=r.slice(a).trim();i[t].content=r,r.length||(i[t-1].tight=!0,i[t+1].tight=!0)}}}function Ts(e){var i=e.tokens,t,n,r;for(n=0,r=i.length;n<r;n++)t=i[n],t.type==="inline"&&e.inline.parse(t.content,e.options,e.env,t.children)}function Is(e){var i,t,n,r,a,o,s,l,u,c=0,d=!1,h={};if(e.env.footnotes&&(e.tokens=e.tokens.filter(function(p){return p.type==="footnote_reference_open"?(d=!0,l=[],u=p.label,!1):p.type==="footnote_reference_close"?(d=!1,h[":"+u]=l,!1):(d&&l.push(p),!d)}),!!e.env.footnotes.list)){for(o=e.env.footnotes.list,e.tokens.push({type:"footnote_block_open",level:c++}),i=0,t=o.length;i<t;i++){for(e.tokens.push({type:"footnote_open",id:i,level:c++}),o[i].tokens?(s=[],s.push({type:"paragraph_open",tight:!1,level:c++}),s.push({type:"inline",content:"",level:c,children:o[i].tokens}),s.push({type:"paragraph_close",tight:!1,level:--c})):o[i].label&&(s=h[":"+o[i].label]),e.tokens=e.tokens.concat(s),e.tokens[e.tokens.length-1].type==="paragraph_close"?a=e.tokens.pop():a=null,r=o[i].count>0?o[i].count:1,n=0;n<r;n++)e.tokens.push({type:"footnote_anchor",id:i,subId:n,level:c});a&&e.tokens.push(a),e.tokens.push({type:"footnote_close",level:--c})}e.tokens.push({type:"footnote_block_close",level:--c})}}var vr=` 
()[]'".,!?-`;function sn(e){return e.replace(/([-()\[\]{}+?*.$\^|,:#<!\\])/g,"\\$1")}function Ls(e){var i,t,n,r,a,o,s,l,u,c,d,h,p=e.tokens;if(e.env.abbreviations){for(e.env.abbrRegExp||(h="(^|["+vr.split("").map(sn).join("")+"])("+Object.keys(e.env.abbreviations).map(function(v){return v.substr(1)}).sort(function(v,m){return m.length-v.length}).map(sn).join("|")+")($|["+vr.split("").map(sn).join("")+"])",e.env.abbrRegExp=new RegExp(h,"g")),c=e.env.abbrRegExp,t=0,n=p.length;t<n;t++)if(p[t].type==="inline"){for(r=p[t].children,i=r.length-1;i>=0;i--)if(a=r[i],a.type==="text"){for(l=0,o=a.content,c.lastIndex=0,u=a.level,s=[];d=c.exec(o);)c.lastIndex>l&&s.push({type:"text",content:o.slice(l,d.index+d[1].length),level:u}),s.push({type:"abbr_open",title:e.env.abbreviations[":"+d[2]],level:u++}),s.push({type:"text",content:d[2],level:u}),s.push({type:"abbr_close",level:--u}),l=c.lastIndex-d[3].length;s.length&&(l<o.length&&s.push({type:"text",content:o.slice(l),level:u}),p[t].children=r=[].concat(r.slice(0,i),s,r.slice(i+1)))}}}}var Rs=/\+-|\.\.|\?\?\?\?|!!!!|,,|--/,Os=/\((c|tm|r|p)\)/ig,Ps={c:"©",r:"®",p:"§",tm:"™"};function Ns(e){return e.indexOf("(")<0?e:e.replace(Os,function(i,t){return Ps[t.toLowerCase()]})}function Ds(e){var i,t,n,r,a;if(e.options.typographer){for(a=e.tokens.length-1;a>=0;a--)if(e.tokens[a].type==="inline")for(r=e.tokens[a].children,i=r.length-1;i>=0;i--)t=r[i],t.type==="text"&&(n=t.content,n=Ns(n),Rs.test(n)&&(n=n.replace(/\+-/g,"±").replace(/\.{2,}/g,"…").replace(/([?!])…/g,"$1..").replace(/([?!]){4,}/g,"$1$1$1").replace(/,{2,}/g,",").replace(/(^|[^-])---([^-]|$)/mg,"$1—$2").replace(/(^|\s)--(\s|$)/mg,"$1–$2").replace(/(^|[^-\s])--([^-\s]|$)/mg,"$1–$2")),t.content=n)}}var Fs=/['"]/,mr=/['"]/g,js=/[-\s()\[\]]/,gr="’";function yr(e,i){return i<0||i>=e.length?!1:!js.test(e[i])}function We(e,i,t){return e.substr(0,i)+t+e.substr(i+1)}function Bs(e){var i,t,n,r,a,o,s,l,u,c,d,h,p,v,m,b,w;if(e.options.typographer){for(w=[],m=e.tokens.length-1;m>=0;m--)if(e.tokens[m].type==="inline"){for(b=e.tokens[m].children,w.length=0,i=0;i<b.length;i++)if(t=b[i],!(t.type!=="text"||Fs.test(t.text))){for(s=b[i].level,p=w.length-1;p>=0&&!(w[p].level<=s);p--);w.length=p+1,n=t.content,a=0,o=n.length;e:for(;a<o&&(mr.lastIndex=a,r=mr.exec(n),!!r);){if(l=!yr(n,r.index-1),a=r.index+1,v=r[0]==="'",u=!yr(n,a),!u&&!l){v&&(t.content=We(t.content,r.index,gr));continue}if(d=!u,h=!l,h){for(p=w.length-1;p>=0&&(c=w[p],!(w[p].level<s));p--)if(c.single===v&&w[p].level===s){c=w[p],v?(b[c.token].content=We(b[c.token].content,c.pos,e.options.quotes[2]),t.content=We(t.content,r.index,e.options.quotes[3])):(b[c.token].content=We(b[c.token].content,c.pos,e.options.quotes[0]),t.content=We(t.content,r.index,e.options.quotes[1])),w.length=p;continue e}}d?w.push({token:i,pos:r.index,single:v,level:s}):h&&v&&(t.content=We(t.content,r.index,gr))}}}}}var ln=[["block",xs],["abbr",Cs],["references",As],["inline",Ts],["footnote_tail",Is],["abbr2",Ls],["replacements",Ds],["smartquotes",Bs]];function Li(){this.options={},this.ruler=new ve;for(var e=0;e<ln.length;e++)this.ruler.push(ln[e][0],ln[e][1])}Li.prototype.process=function(e){var i,t,n;for(n=this.ruler.getRules(""),i=0,t=n.length;i<t;i++)n[i](e)};function ze(e,i,t,n,r){var a,o,s,l,u,c,d;for(this.src=e,this.parser=i,this.options=t,this.env=n,this.tokens=r,this.bMarks=[],this.eMarks=[],this.tShift=[],this.blkIndent=0,this.line=0,this.lineMax=0,this.tight=!1,this.parentType="root",this.ddIndent=-1,this.level=0,this.result="",o=this.src,c=0,d=!1,s=l=c=0,u=o.length;l<u;l++){if(a=o.charCodeAt(l),!d)if(a===32){c++;continue}else d=!0;(a===10||l===u-1)&&(a!==10&&l++,this.bMarks.push(s),this.eMarks.push(l),this.tShift.push(c),d=!1,c=0,s=l+1)}this.bMarks.push(o.length),this.eMarks.push(o.length),this.tShift.push(0),this.lineMax=this.bMarks.length-1}ze.prototype.isEmpty=function(e){return this.bMarks[e]+this.tShift[e]>=this.eMarks[e]};ze.prototype.skipEmptyLines=function(e){for(var i=this.lineMax;e<i&&!(this.bMarks[e]+this.tShift[e]<this.eMarks[e]);e++);return e};ze.prototype.skipSpaces=function(e){for(var i=this.src.length;e<i&&this.src.charCodeAt(e)===32;e++);return e};ze.prototype.skipChars=function(e,i){for(var t=this.src.length;e<t&&this.src.charCodeAt(e)===i;e++);return e};ze.prototype.skipCharsBack=function(e,i,t){if(e<=t)return e;for(;e>t;)if(i!==this.src.charCodeAt(--e))return e+1;return e};ze.prototype.getLines=function(e,i,t,n){var r,a,o,s,l,u=e;if(e>=i)return"";if(u+1===i)return a=this.bMarks[u]+Math.min(this.tShift[u],t),o=n?this.eMarks[u]+1:this.eMarks[u],this.src.slice(a,o);for(s=new Array(i-e),r=0;u<i;u++,r++)l=this.tShift[u],l>t&&(l=t),l<0&&(l=0),a=this.bMarks[u]+l,u+1<i||n?o=this.eMarks[u]+1:o=this.eMarks[u],s[r]=this.src.slice(a,o);return s.join("")};function qs(e,i,t){var n,r;if(e.tShift[i]-e.blkIndent<4)return!1;for(r=n=i+1;n<t;){if(e.isEmpty(n)){n++;continue}if(e.tShift[n]-e.blkIndent>=4){n++,r=n;continue}break}return e.line=n,e.tokens.push({type:"code",content:e.getLines(i,r,4+e.blkIndent,!0),block:!0,lines:[i,e.line],level:e.level}),!0}function zs(e,i,t,n){var r,a,o,s,l,u=!1,c=e.bMarks[i]+e.tShift[i],d=e.eMarks[i];if(c+3>d||(r=e.src.charCodeAt(c),r!==126&&r!==96)||(l=c,c=e.skipChars(c,r),a=c-l,a<3)||(o=e.src.slice(c,d).trim(),o.indexOf("`")>=0))return!1;if(n)return!0;for(s=i;s++,!(s>=t||(c=l=e.bMarks[s]+e.tShift[s],d=e.eMarks[s],c<d&&e.tShift[s]<e.blkIndent));)if(e.src.charCodeAt(c)===r&&!(e.tShift[s]-e.blkIndent>=4)&&(c=e.skipChars(c,r),!(c-l<a)&&(c=e.skipSpaces(c),!(c<d)))){u=!0;break}return a=e.tShift[i],e.line=s+(u?1:0),e.tokens.push({type:"fence",params:o,content:e.getLines(i+1,s,a,!0),lines:[i,e.line],level:e.level}),!0}function Us(e,i,t,n){var r,a,o,s,l,u,c,d,h,p,v,m=e.bMarks[i]+e.tShift[i],b=e.eMarks[i];if(m>b||e.src.charCodeAt(m++)!==62||e.level>=e.options.maxNesting)return!1;if(n)return!0;for(e.src.charCodeAt(m)===32&&m++,l=e.blkIndent,e.blkIndent=0,s=[e.bMarks[i]],e.bMarks[i]=m,m=m<b?e.skipSpaces(m):m,a=m>=b,o=[e.tShift[i]],e.tShift[i]=m-e.bMarks[i],d=e.parser.ruler.getRules("blockquote"),r=i+1;r<t&&(m=e.bMarks[r]+e.tShift[r],b=e.eMarks[r],!(m>=b));r++){if(e.src.charCodeAt(m++)===62){e.src.charCodeAt(m)===32&&m++,s.push(e.bMarks[r]),e.bMarks[r]=m,m=m<b?e.skipSpaces(m):m,a=m>=b,o.push(e.tShift[r]),e.tShift[r]=m-e.bMarks[r];continue}if(a)break;for(v=!1,h=0,p=d.length;h<p;h++)if(d[h](e,r,t,!0)){v=!0;break}if(v)break;s.push(e.bMarks[r]),o.push(e.tShift[r]),e.tShift[r]=-1337}for(u=e.parentType,e.parentType="blockquote",e.tokens.push({type:"blockquote_open",lines:c=[i,0],level:e.level++}),e.parser.tokenize(e,i,r),e.tokens.push({type:"blockquote_close",level:--e.level}),e.parentType=u,c[1]=e.line,h=0;h<o.length;h++)e.bMarks[h+i]=s[h],e.tShift[h+i]=o[h];return e.blkIndent=l,!0}function Hs(e,i,t,n){var r,a,o,s=e.bMarks[i],l=e.eMarks[i];if(s+=e.tShift[i],s>l||(r=e.src.charCodeAt(s++),r!==42&&r!==45&&r!==95))return!1;for(a=1;s<l;){if(o=e.src.charCodeAt(s++),o!==r&&o!==32)return!1;o===r&&a++}return a<3?!1:(n||(e.line=i+1,e.tokens.push({type:"hr",lines:[i,e.line],level:e.level})),!0)}function br(e,i){var t,n,r;return n=e.bMarks[i]+e.tShift[i],r=e.eMarks[i],n>=r||(t=e.src.charCodeAt(n++),t!==42&&t!==45&&t!==43)||n<r&&e.src.charCodeAt(n)!==32?-1:n}function kr(e,i){var t,n=e.bMarks[i]+e.tShift[i],r=e.eMarks[i];if(n+1>=r||(t=e.src.charCodeAt(n++),t<48||t>57))return-1;for(;;){if(n>=r)return-1;if(t=e.src.charCodeAt(n++),!(t>=48&&t<=57)){if(t===41||t===46)break;return-1}}return n<r&&e.src.charCodeAt(n)!==32?-1:n}function Vs(e,i){var t,n,r=e.level+2;for(t=i+2,n=e.tokens.length-2;t<n;t++)e.tokens[t].level===r&&e.tokens[t].type==="paragraph_open"&&(e.tokens[t+2].tight=!0,e.tokens[t].tight=!0,t+=2)}function $s(e,i,t,n){var r,a,o,s,l,u,c,d,h,p,v,m,b,w,_,x,N,M,j=!0,G,H,Z,te;if((d=kr(e,i))>=0)b=!0;else if((d=br(e,i))>=0)b=!1;else return!1;if(e.level>=e.options.maxNesting)return!1;if(m=e.src.charCodeAt(d-1),n)return!0;for(_=e.tokens.length,b?(c=e.bMarks[i]+e.tShift[i],v=Number(e.src.substr(c,d-c-1)),e.tokens.push({type:"ordered_list_open",order:v,lines:N=[i,0],level:e.level++})):e.tokens.push({type:"bullet_list_open",lines:N=[i,0],level:e.level++}),r=i,x=!1,G=e.parser.ruler.getRules("list");r<t&&(w=e.skipSpaces(d),h=e.eMarks[r],w>=h?p=1:p=w-d,p>4&&(p=1),p<1&&(p=1),a=d-e.bMarks[r]+p,e.tokens.push({type:"list_item_open",lines:M=[i,0],level:e.level++}),s=e.blkIndent,l=e.tight,o=e.tShift[i],u=e.parentType,e.tShift[i]=w-e.bMarks[i],e.blkIndent=a,e.tight=!0,e.parentType="list",e.parser.tokenize(e,i,t,!0),(!e.tight||x)&&(j=!1),x=e.line-i>1&&e.isEmpty(e.line-1),e.blkIndent=s,e.tShift[i]=o,e.tight=l,e.parentType=u,e.tokens.push({type:"list_item_close",level:--e.level}),r=i=e.line,M[1]=r,w=e.bMarks[i],!(r>=t||e.isEmpty(r)||e.tShift[r]<e.blkIndent));){for(te=!1,H=0,Z=G.length;H<Z;H++)if(G[H](e,r,t,!0)){te=!0;break}if(te)break;if(b){if(d=kr(e,r),d<0)break}else if(d=br(e,r),d<0)break;if(m!==e.src.charCodeAt(d-1))break}return e.tokens.push({type:b?"ordered_list_close":"bullet_list_close",level:--e.level}),N[1]=r,e.line=r,j&&Vs(e,_),!0}function Gs(e,i,t,n){var r,a,o,s,l,u=e.bMarks[i]+e.tShift[i],c=e.eMarks[i];if(u+4>c||e.src.charCodeAt(u)!==91||e.src.charCodeAt(u+1)!==94||e.level>=e.options.maxNesting)return!1;for(s=u+2;s<c;s++){if(e.src.charCodeAt(s)===32)return!1;if(e.src.charCodeAt(s)===93)break}return s===u+2||s+1>=c||e.src.charCodeAt(++s)!==58?!1:(n||(s++,e.env.footnotes||(e.env.footnotes={}),e.env.footnotes.refs||(e.env.footnotes.refs={}),l=e.src.slice(u+2,s-2),e.env.footnotes.refs[":"+l]=-1,e.tokens.push({type:"footnote_reference_open",label:l,level:e.level++}),r=e.bMarks[i],a=e.tShift[i],o=e.parentType,e.tShift[i]=e.skipSpaces(s)-s,e.bMarks[i]=s,e.blkIndent+=4,e.parentType="footnote",e.tShift[i]<e.blkIndent&&(e.tShift[i]+=e.blkIndent,e.bMarks[i]-=e.blkIndent),e.parser.tokenize(e,i,t,!0),e.parentType=o,e.blkIndent-=4,e.tShift[i]=a,e.bMarks[i]=r,e.tokens.push({type:"footnote_reference_close",level:--e.level})),!0)}function Ws(e,i,t,n){var r,a,o,s=e.bMarks[i]+e.tShift[i],l=e.eMarks[i];if(s>=l||(r=e.src.charCodeAt(s),r!==35||s>=l))return!1;for(a=1,r=e.src.charCodeAt(++s);r===35&&s<l&&a<=6;)a++,r=e.src.charCodeAt(++s);return a>6||s<l&&r!==32?!1:(n||(l=e.skipCharsBack(l,32,s),o=e.skipCharsBack(l,35,s),o>s&&e.src.charCodeAt(o-1)===32&&(l=o),e.line=i+1,e.tokens.push({type:"heading_open",hLevel:a,lines:[i,e.line],level:e.level}),s<l&&e.tokens.push({type:"inline",content:e.src.slice(s,l).trim(),level:e.level+1,lines:[i,e.line],children:[]}),e.tokens.push({type:"heading_close",hLevel:a,level:e.level})),!0)}function Ks(e,i,t){var n,r,a,o=i+1;return o>=t||e.tShift[o]<e.blkIndent||e.tShift[o]-e.blkIndent>3||(r=e.bMarks[o]+e.tShift[o],a=e.eMarks[o],r>=a)||(n=e.src.charCodeAt(r),n!==45&&n!==61)||(r=e.skipChars(r,n),r=e.skipSpaces(r),r<a)?!1:(r=e.bMarks[i]+e.tShift[i],e.line=o+1,e.tokens.push({type:"heading_open",hLevel:n===61?1:2,lines:[i,e.line],level:e.level}),e.tokens.push({type:"inline",content:e.src.slice(r,e.eMarks[i]).trim(),level:e.level+1,lines:[i,e.line-1],children:[]}),e.tokens.push({type:"heading_close",hLevel:n===61?1:2,level:e.level}),!0)}var Ri={};["article","aside","button","blockquote","body","canvas","caption","col","colgroup","dd","div","dl","dt","embed","fieldset","figcaption","figure","footer","form","h1","h2","h3","h4","h5","h6","header","hgroup","hr","iframe","li","map","object","ol","output","p","pre","progress","script","section","style","table","tbody","td","textarea","tfoot","th","tr","thead","ul","video"].forEach(function(e){Ri[e]=!0});var Ys=/^<([a-zA-Z]{1,15})[\s\/>]/,Js=/^<\/([a-zA-Z]{1,15})[\s>]/;function Zs(e){var i=e|32;return i>=97&&i<=122}function Xs(e,i,t,n){var r,a,o,s=e.bMarks[i],l=e.eMarks[i],u=e.tShift[i];if(s+=u,!e.options.html||u>3||s+2>=l||e.src.charCodeAt(s)!==60)return!1;if(r=e.src.charCodeAt(s+1),r===33||r===63){if(n)return!0}else if(r===47||Zs(r)){if(r===47){if(a=e.src.slice(s,l).match(Js),!a)return!1}else if(a=e.src.slice(s,l).match(Ys),!a)return!1;if(Ri[a[1].toLowerCase()]!==!0)return!1;if(n)return!0}else return!1;for(o=i+1;o<e.lineMax&&!e.isEmpty(o);)o++;return e.line=o,e.tokens.push({type:"htmlblock",level:e.level,lines:[i,e.line],content:e.getLines(i,o,0,!0)}),!0}function un(e,i){var t=e.bMarks[i]+e.blkIndent,n=e.eMarks[i];return e.src.substr(t,n-t)}function Qs(e,i,t,n){var r,a,o,s,l,u,c,d,h,p,v;if(i+2>t||(l=i+1,e.tShift[l]<e.blkIndent)||(o=e.bMarks[l]+e.tShift[l],o>=e.eMarks[l])||(r=e.src.charCodeAt(o),r!==124&&r!==45&&r!==58)||(a=un(e,i+1),!/^[-:| ]+$/.test(a))||(u=a.split("|"),u<=2))return!1;for(d=[],s=0;s<u.length;s++){if(h=u[s].trim(),!h){if(s===0||s===u.length-1)continue;return!1}if(!/^:?-+:?$/.test(h))return!1;h.charCodeAt(h.length-1)===58?d.push(h.charCodeAt(0)===58?"center":"right"):h.charCodeAt(0)===58?d.push("left"):d.push("")}if(a=un(e,i).trim(),a.indexOf("|")===-1||(u=a.replace(/^\||\|$/g,"").split("|"),d.length!==u.length))return!1;if(n)return!0;for(e.tokens.push({type:"table_open",lines:p=[i,0],level:e.level++}),e.tokens.push({type:"thead_open",lines:[i,i+1],level:e.level++}),e.tokens.push({type:"tr_open",lines:[i,i+1],level:e.level++}),s=0;s<u.length;s++)e.tokens.push({type:"th_open",align:d[s],lines:[i,i+1],level:e.level++}),e.tokens.push({type:"inline",content:u[s].trim(),lines:[i,i+1],level:e.level,children:[]}),e.tokens.push({type:"th_close",level:--e.level});for(e.tokens.push({type:"tr_close",level:--e.level}),e.tokens.push({type:"thead_close",level:--e.level}),e.tokens.push({type:"tbody_open",lines:v=[i+2,0],level:e.level++}),l=i+2;l<t&&!(e.tShift[l]<e.blkIndent||(a=un(e,l).trim(),a.indexOf("|")===-1));l++){for(u=a.replace(/^\||\|$/g,"").split("|"),e.tokens.push({type:"tr_open",level:e.level++}),s=0;s<u.length;s++)e.tokens.push({type:"td_open",align:d[s],level:e.level++}),c=u[s].substring(u[s].charCodeAt(0)===124?1:0,u[s].charCodeAt(u[s].length-1)===124?u[s].length-1:u[s].length).trim(),e.tokens.push({type:"inline",content:c,level:e.level,children:[]}),e.tokens.push({type:"td_close",level:--e.level});e.tokens.push({type:"tr_close",level:--e.level})}return e.tokens.push({type:"tbody_close",level:--e.level}),e.tokens.push({type:"table_close",level:--e.level}),p[1]=v[1]=l,e.line=l,!0}function _t(e,i){var t,n,r=e.bMarks[i]+e.tShift[i],a=e.eMarks[i];return r>=a||(n=e.src.charCodeAt(r++),n!==126&&n!==58)||(t=e.skipSpaces(r),r===t)||t>=a?-1:t}function el(e,i){var t,n,r=e.level+2;for(t=i+2,n=e.tokens.length-2;t<n;t++)e.tokens[t].level===r&&e.tokens[t].type==="paragraph_open"&&(e.tokens[t+2].tight=!0,e.tokens[t].tight=!0,t+=2)}function tl(e,i,t,n){var r,a,o,s,l,u,c,d,h,p,v,m,b,w;if(n)return e.ddIndent<0?!1:_t(e,i)>=0;if(c=i+1,e.isEmpty(c)&&++c>t||e.tShift[c]<e.blkIndent||(r=_t(e,c),r<0)||e.level>=e.options.maxNesting)return!1;u=e.tokens.length,e.tokens.push({type:"dl_open",lines:l=[i,0],level:e.level++}),o=i,a=c;e:for(;;){for(w=!0,b=!1,e.tokens.push({type:"dt_open",lines:[o,o],level:e.level++}),e.tokens.push({type:"inline",content:e.getLines(o,o+1,e.blkIndent,!1).trim(),level:e.level+1,lines:[o,o],children:[]}),e.tokens.push({type:"dt_close",level:--e.level});;){if(e.tokens.push({type:"dd_open",lines:s=[c,0],level:e.level++}),m=e.tight,h=e.ddIndent,d=e.blkIndent,v=e.tShift[a],p=e.parentType,e.blkIndent=e.ddIndent=e.tShift[a]+2,e.tShift[a]=r-e.bMarks[a],e.tight=!0,e.parentType="deflist",e.parser.tokenize(e,a,t,!0),(!e.tight||b)&&(w=!1),b=e.line-a>1&&e.isEmpty(e.line-1),e.tShift[a]=v,e.tight=m,e.parentType=p,e.blkIndent=d,e.ddIndent=h,e.tokens.push({type:"dd_close",level:--e.level}),s[1]=c=e.line,c>=t||e.tShift[c]<e.blkIndent)break e;if(r=_t(e,c),r<0)break;a=c}if(c>=t||(o=c,e.isEmpty(o))||e.tShift[o]<e.blkIndent||(a=o+1,a>=t)||(e.isEmpty(a)&&a++,a>=t)||e.tShift[a]<e.blkIndent||(r=_t(e,a),r<0))break}return e.tokens.push({type:"dl_close",level:--e.level}),l[1]=c,e.line=c,w&&el(e,u),!0}function nl(e,i){var t,n,r,a,o,s=i+1,l;if(t=e.lineMax,s<t&&!e.isEmpty(s)){for(l=e.parser.ruler.getRules("paragraph");s<t&&!e.isEmpty(s);s++)if(!(e.tShift[s]-e.blkIndent>3)){for(r=!1,a=0,o=l.length;a<o;a++)if(l[a](e,s,t,!0)){r=!0;break}if(r)break}}return n=e.getLines(i,s,e.blkIndent,!1).trim(),e.line=s,n.length&&(e.tokens.push({type:"paragraph_open",tight:!1,lines:[i,e.line],level:e.level}),e.tokens.push({type:"inline",content:n,level:e.level+1,lines:[i,e.line],children:[]}),e.tokens.push({type:"paragraph_close",tight:!1,level:e.level})),!0}var wt=[["code",qs],["fences",zs,["paragraph","blockquote","list"]],["blockquote",Us,["paragraph","blockquote","list"]],["hr",Hs,["paragraph","blockquote","list"]],["list",$s,["paragraph","blockquote"]],["footnote",Gs,["paragraph"]],["heading",Ws,["paragraph","blockquote"]],["lheading",Ks],["htmlblock",Xs,["paragraph","blockquote"]],["table",Qs,["paragraph"]],["deflist",tl,["paragraph"]],["paragraph",nl]];function jn(){this.ruler=new ve;for(var e=0;e<wt.length;e++)this.ruler.push(wt[e][0],wt[e][1],{alt:(wt[e][2]||[]).slice()})}jn.prototype.tokenize=function(e,i,t){for(var n=this.ruler.getRules(""),r=n.length,a=i,o=!1,s,l;a<t&&(e.line=a=e.skipEmptyLines(a),!(a>=t||e.tShift[a]<e.blkIndent));){for(l=0;l<r&&(s=n[l](e,a,t,!1),!s);l++);if(e.tight=!o,e.isEmpty(e.line-1)&&(o=!0),a=e.line,a<t&&e.isEmpty(a)){if(o=!0,a++,a<t&&e.parentType==="list"&&e.isEmpty(a))break;e.line=a}}};var rl=/[\n\t]/g,il=/\r[\n\u0085]|[\u2424\u2028\u0085]/g,al=/\u00a0/g;jn.prototype.parse=function(e,i,t,n){var r,a=0,o=0;if(!e)return[];e=e.replace(al," "),e=e.replace(il,`
`),e.indexOf("	")>=0&&(e=e.replace(rl,function(s,l){var u;return e.charCodeAt(l)===10?(a=l+1,o=0,s):(u="    ".slice((l-a-o)%4),o=l-a+1,u)})),r=new ze(e,this,i,t,n),this.tokenize(r,r.line,r.lineMax)};function ol(e){switch(e){case 10:case 92:case 96:case 42:case 95:case 94:case 91:case 93:case 33:case 38:case 60:case 62:case 123:case 125:case 36:case 37:case 64:case 126:case 43:case 61:case 58:return!0;default:return!1}}function sl(e,i){for(var t=e.pos;t<e.posMax&&!ol(e.src.charCodeAt(t));)t++;return t===e.pos?!1:(i||(e.pending+=e.src.slice(e.pos,t)),e.pos=t,!0)}function ll(e,i){var t,n,r=e.pos;if(e.src.charCodeAt(r)!==10)return!1;if(t=e.pending.length-1,n=e.posMax,!i)if(t>=0&&e.pending.charCodeAt(t)===32)if(t>=1&&e.pending.charCodeAt(t-1)===32){for(var a=t-2;a>=0;a--)if(e.pending.charCodeAt(a)!==32){e.pending=e.pending.substring(0,a+1);break}e.push({type:"hardbreak",level:e.level})}else e.pending=e.pending.slice(0,-1),e.push({type:"softbreak",level:e.level});else e.push({type:"softbreak",level:e.level});for(r++;r<n&&e.src.charCodeAt(r)===32;)r++;return e.pos=r,!0}var Bn=[];for(var _r=0;_r<256;_r++)Bn.push(0);"\\!\"#$%&'()*+,./:;<=>?@[]^_`{|}~-".split("").forEach(function(e){Bn[e.charCodeAt(0)]=1});function ul(e,i){var t,n=e.pos,r=e.posMax;if(e.src.charCodeAt(n)!==92)return!1;if(n++,n<r){if(t=e.src.charCodeAt(n),t<256&&Bn[t]!==0)return i||(e.pending+=e.src[n]),e.pos+=2,!0;if(t===10){for(i||e.push({type:"hardbreak",level:e.level}),n++;n<r&&e.src.charCodeAt(n)===32;)n++;return e.pos=n,!0}}return i||(e.pending+="\\"),e.pos++,!0}function cl(e,i){var t,n,r,a,o,s=e.pos,l=e.src.charCodeAt(s);if(l!==96)return!1;for(t=s,s++,n=e.posMax;s<n&&e.src.charCodeAt(s)===96;)s++;for(r=e.src.slice(t,s),a=o=s;(a=e.src.indexOf("`",o))!==-1;){for(o=a+1;o<n&&e.src.charCodeAt(o)===96;)o++;if(o-a===r.length)return i||e.push({type:"code",content:e.src.slice(s,a).replace(/[ \n]+/g," ").trim(),block:!1,level:e.level}),e.pos=o,!0}return i||(e.pending+=r),e.pos+=r.length,!0}function dl(e,i){var t,n,r,a=e.posMax,o=e.pos,s,l;if(e.src.charCodeAt(o)!==126||i||o+4>=a||e.src.charCodeAt(o+1)!==126||e.level>=e.options.maxNesting||(s=o>0?e.src.charCodeAt(o-1):-1,l=e.src.charCodeAt(o+2),s===126)||l===126||l===32||l===10)return!1;for(n=o+2;n<a&&e.src.charCodeAt(n)===126;)n++;if(n>o+3)return e.pos+=n-o,i||(e.pending+=e.src.slice(o,n)),!0;for(e.pos=o+2,r=1;e.pos+1<a;){if(e.src.charCodeAt(e.pos)===126&&e.src.charCodeAt(e.pos+1)===126&&(s=e.src.charCodeAt(e.pos-1),l=e.pos+2<a?e.src.charCodeAt(e.pos+2):-1,l!==126&&s!==126&&(s!==32&&s!==10?r--:l!==32&&l!==10&&r++,r<=0))){t=!0;break}e.parser.skipToken(e)}return t?(e.posMax=e.pos,e.pos=o+2,i||(e.push({type:"del_open",level:e.level++}),e.parser.tokenize(e),e.push({type:"del_close",level:--e.level})),e.pos=e.posMax+2,e.posMax=a,!0):(e.pos=o,!1)}function hl(e,i){var t,n,r,a=e.posMax,o=e.pos,s,l;if(e.src.charCodeAt(o)!==43||i||o+4>=a||e.src.charCodeAt(o+1)!==43||e.level>=e.options.maxNesting||(s=o>0?e.src.charCodeAt(o-1):-1,l=e.src.charCodeAt(o+2),s===43)||l===43||l===32||l===10)return!1;for(n=o+2;n<a&&e.src.charCodeAt(n)===43;)n++;if(n!==o+2)return e.pos+=n-o,i||(e.pending+=e.src.slice(o,n)),!0;for(e.pos=o+2,r=1;e.pos+1<a;){if(e.src.charCodeAt(e.pos)===43&&e.src.charCodeAt(e.pos+1)===43&&(s=e.src.charCodeAt(e.pos-1),l=e.pos+2<a?e.src.charCodeAt(e.pos+2):-1,l!==43&&s!==43&&(s!==32&&s!==10?r--:l!==32&&l!==10&&r++,r<=0))){t=!0;break}e.parser.skipToken(e)}return t?(e.posMax=e.pos,e.pos=o+2,i||(e.push({type:"ins_open",level:e.level++}),e.parser.tokenize(e),e.push({type:"ins_close",level:--e.level})),e.pos=e.posMax+2,e.posMax=a,!0):(e.pos=o,!1)}function pl(e,i){var t,n,r,a=e.posMax,o=e.pos,s,l;if(e.src.charCodeAt(o)!==61||i||o+4>=a||e.src.charCodeAt(o+1)!==61||e.level>=e.options.maxNesting||(s=o>0?e.src.charCodeAt(o-1):-1,l=e.src.charCodeAt(o+2),s===61)||l===61||l===32||l===10)return!1;for(n=o+2;n<a&&e.src.charCodeAt(n)===61;)n++;if(n!==o+2)return e.pos+=n-o,i||(e.pending+=e.src.slice(o,n)),!0;for(e.pos=o+2,r=1;e.pos+1<a;){if(e.src.charCodeAt(e.pos)===61&&e.src.charCodeAt(e.pos+1)===61&&(s=e.src.charCodeAt(e.pos-1),l=e.pos+2<a?e.src.charCodeAt(e.pos+2):-1,l!==61&&s!==61&&(s!==32&&s!==10?r--:l!==32&&l!==10&&r++,r<=0))){t=!0;break}e.parser.skipToken(e)}return t?(e.posMax=e.pos,e.pos=o+2,i||(e.push({type:"mark_open",level:e.level++}),e.parser.tokenize(e),e.push({type:"mark_close",level:--e.level})),e.pos=e.posMax+2,e.posMax=a,!0):(e.pos=o,!1)}function wr(e){return e>=48&&e<=57||e>=65&&e<=90||e>=97&&e<=122}function Sr(e,i){var t=i,n,r,a,o=!0,s=!0,l=e.posMax,u=e.src.charCodeAt(i);for(n=i>0?e.src.charCodeAt(i-1):-1;t<l&&e.src.charCodeAt(t)===u;)t++;return t>=l&&(o=!1),a=t-i,a>=4?o=s=!1:(r=t<l?e.src.charCodeAt(t):-1,(r===32||r===10)&&(o=!1),(n===32||n===10)&&(s=!1),u===95&&(wr(n)&&(o=!1),wr(r)&&(s=!1))),{can_open:o,can_close:s,delims:a}}function fl(e,i){var t,n,r,a,o,s,l,u=e.posMax,c=e.pos,d=e.src.charCodeAt(c);if(d!==95&&d!==42||i)return!1;if(l=Sr(e,c),t=l.delims,!l.can_open)return e.pos+=t,i||(e.pending+=e.src.slice(c,e.pos)),!0;if(e.level>=e.options.maxNesting)return!1;for(e.pos=c+t,s=[t];e.pos<u;){if(e.src.charCodeAt(e.pos)===d){if(l=Sr(e,e.pos),n=l.delims,l.can_close){for(a=s.pop(),o=n;a!==o;){if(o<a){s.push(a-o);break}if(o-=a,s.length===0)break;e.pos+=a,a=s.pop()}if(s.length===0){t=a,r=!0;break}e.pos+=n;continue}l.can_open&&s.push(n),e.pos+=n;continue}e.parser.skipToken(e)}return r?(e.posMax=e.pos,e.pos=c+t,i||((t===2||t===3)&&e.push({type:"strong_open",level:e.level++}),(t===1||t===3)&&e.push({type:"em_open",level:e.level++}),e.parser.tokenize(e),(t===1||t===3)&&e.push({type:"em_close",level:--e.level}),(t===2||t===3)&&e.push({type:"strong_close",level:--e.level})),e.pos=e.posMax+t,e.posMax=u,!0):(e.pos=c,!1)}var vl=/\\([ \\!"#$%&'()*+,.\/:;<=>?@[\]^_`{|}~-])/g;function ml(e,i){var t,n,r=e.posMax,a=e.pos;if(e.src.charCodeAt(a)!==126||i||a+2>=r||e.level>=e.options.maxNesting)return!1;for(e.pos=a+1;e.pos<r;){if(e.src.charCodeAt(e.pos)===126){t=!0;break}e.parser.skipToken(e)}return!t||a+1===e.pos||(n=e.src.slice(a+1,e.pos),n.match(/(^|[^\\])(\\\\)*\s/))?(e.pos=a,!1):(e.posMax=e.pos,e.pos=a+1,i||e.push({type:"sub",level:e.level,content:n.replace(vl,"$1")}),e.pos=e.posMax+1,e.posMax=r,!0)}var gl=/\\([ \\!"#$%&'()*+,.\/:;<=>?@[\]^_`{|}~-])/g;function yl(e,i){var t,n,r=e.posMax,a=e.pos;if(e.src.charCodeAt(a)!==94||i||a+2>=r||e.level>=e.options.maxNesting)return!1;for(e.pos=a+1;e.pos<r;){if(e.src.charCodeAt(e.pos)===94){t=!0;break}e.parser.skipToken(e)}return!t||a+1===e.pos||(n=e.src.slice(a+1,e.pos),n.match(/(^|[^\\])(\\\\)*\s/))?(e.pos=a,!1):(e.posMax=e.pos,e.pos=a+1,i||e.push({type:"sup",level:e.level,content:n.replace(gl,"$1")}),e.pos=e.posMax+1,e.posMax=r,!0)}function bl(e,i){var t,n,r,a,o,s,l,u,c=!1,d=e.pos,h=e.posMax,p=e.pos,v=e.src.charCodeAt(p);if(v===33&&(c=!0,v=e.src.charCodeAt(++p)),v!==91||e.level>=e.options.maxNesting||(t=p+1,n=st(e,p),n<0))return!1;if(s=n+1,s<h&&e.src.charCodeAt(s)===40){for(s++;s<h&&(u=e.src.charCodeAt(s),!(u!==32&&u!==10));s++);if(s>=h)return!1;for(p=s,Ai(e,s)?(a=e.linkContent,s=e.pos):a="",p=s;s<h&&(u=e.src.charCodeAt(s),!(u!==32&&u!==10));s++);if(s<h&&p!==s&&Ti(e,s))for(o=e.linkContent,s=e.pos;s<h&&(u=e.src.charCodeAt(s),!(u!==32&&u!==10));s++);else o="";if(s>=h||e.src.charCodeAt(s)!==41)return e.pos=d,!1;s++}else{if(e.linkLevel>0)return!1;for(;s<h&&(u=e.src.charCodeAt(s),!(u!==32&&u!==10));s++);if(s<h&&e.src.charCodeAt(s)===91&&(p=s+1,s=st(e,s),s>=0?r=e.src.slice(p,s++):s=p-1),r||(R(r)>"u"&&(s=n+1),r=e.src.slice(t,n)),l=e.env.references[Ii(r)],!l)return e.pos=d,!1;a=l.href,o=l.title}return i||(e.pos=t,e.posMax=n,c?e.push({type:"image",src:a,title:o,alt:e.src.substr(t,n-t),level:e.level}):(e.push({type:"link_open",href:a,title:o,level:e.level++}),e.linkLevel++,e.parser.tokenize(e),e.linkLevel--,e.push({type:"link_close",level:--e.level}))),e.pos=s,e.posMax=h,!0}function kl(e,i){var t,n,r,a,o=e.posMax,s=e.pos;return s+2>=o||e.src.charCodeAt(s)!==94||e.src.charCodeAt(s+1)!==91||e.level>=e.options.maxNesting||(t=s+2,n=st(e,s+1),n<0)?!1:(i||(e.env.footnotes||(e.env.footnotes={}),e.env.footnotes.list||(e.env.footnotes.list=[]),r=e.env.footnotes.list.length,e.pos=t,e.posMax=n,e.push({type:"footnote_ref",id:r,level:e.level}),e.linkLevel++,a=e.tokens.length,e.parser.tokenize(e),e.env.footnotes.list[r]={tokens:e.tokens.splice(a)},e.linkLevel--),e.pos=n+1,e.posMax=o,!0)}function _l(e,i){var t,n,r,a,o=e.posMax,s=e.pos;if(s+3>o||!e.env.footnotes||!e.env.footnotes.refs||e.src.charCodeAt(s)!==91||e.src.charCodeAt(s+1)!==94||e.level>=e.options.maxNesting)return!1;for(n=s+2;n<o;n++){if(e.src.charCodeAt(n)===32||e.src.charCodeAt(n)===10)return!1;if(e.src.charCodeAt(n)===93)break}return n===s+2||n>=o||(n++,t=e.src.slice(s+2,n-1),R(e.env.footnotes.refs[":"+t])>"u")?!1:(i||(e.env.footnotes.list||(e.env.footnotes.list=[]),e.env.footnotes.refs[":"+t]<0?(r=e.env.footnotes.list.length,e.env.footnotes.list[r]={label:t,count:0},e.env.footnotes.refs[":"+t]=r):r=e.env.footnotes.refs[":"+t],a=e.env.footnotes.list[r].count,e.env.footnotes.list[r].count++,e.push({type:"footnote_ref",id:r,subId:a,level:e.level})),e.pos=n,e.posMax=o,!0)}var wl=["coap","doi","javascript","aaa","aaas","about","acap","cap","cid","crid","data","dav","dict","dns","file","ftp","geo","go","gopher","h323","http","https","iax","icap","im","imap","info","ipp","iris","iris.beep","iris.xpc","iris.xpcs","iris.lwz","ldap","mailto","mid","msrp","msrps","mtqp","mupdate","news","nfs","ni","nih","nntp","opaquelocktoken","pop","pres","rtsp","service","session","shttp","sieve","sip","sips","sms","snmp","soap.beep","soap.beeps","tag","tel","telnet","tftp","thismessage","tn3270","tip","tv","urn","vemmi","ws","wss","xcon","xcon-userid","xmlrpc.beep","xmlrpc.beeps","xmpp","z39.50r","z39.50s","adiumxtra","afp","afs","aim","apt","attachment","aw","beshare","bitcoin","bolo","callto","chrome","chrome-extension","com-eventbrite-attendee","content","cvs","dlna-playsingle","dlna-playcontainer","dtn","dvb","ed2k","facetime","feed","finger","fish","gg","git","gizmoproject","gtalk","hcp","icon","ipn","irc","irc6","ircs","itms","jar","jms","keyparc","lastfm","ldaps","magnet","maps","market","message","mms","ms-help","msnim","mumble","mvn","notes","oid","palm","paparazzi","platform","proxy","psyc","query","res","resource","rmi","rsync","rtmp","secondlife","sftp","sgn","skype","smb","soldat","spotify","ssh","steam","svn","teamspeak","things","udp","unreal","ut2004","ventrilo","view-source","webcal","wtai","wyciwyg","xfire","xri","ymsgr"],Sl=/^<([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])?)*)>/,xl=/^<([a-zA-Z.\-]{1,25}):([^<>\x00-\x20]*)>/;function El(e,i){var t,n,r,a,o,s=e.pos;return e.src.charCodeAt(s)!==60||(t=e.src.slice(s),t.indexOf(">")<0)?!1:(n=t.match(xl),n?wl.indexOf(n[1].toLowerCase())<0||(a=n[0].slice(1,-1),o=Cn(a),!e.parser.validateLink(a))?!1:(i||(e.push({type:"link_open",href:o,level:e.level}),e.push({type:"text",content:a,level:e.level+1}),e.push({type:"link_close",level:e.level})),e.pos+=n[0].length,!0):(r=t.match(Sl),r?(a=r[0].slice(1,-1),o=Cn("mailto:"+a),e.parser.validateLink(o)?(i||(e.push({type:"link_open",href:o,level:e.level}),e.push({type:"text",content:a,level:e.level+1}),e.push({type:"link_close",level:e.level})),e.pos+=r[0].length,!0):!1):!1))}function Pt(e,i){return e=e.source,i=i||"",function t(n,r){return n?(r=r.source||r,e=e.replace(n,r),t):new RegExp(e,i)}}var Cl=/[a-zA-Z_:][a-zA-Z0-9:._-]*/,Ml=/[^"'=<>`\x00-\x20]+/,Al=/'[^']*'/,Tl=/"[^"]*"/,Il=Pt(/(?:unquoted|single_quoted|double_quoted)/)("unquoted",Ml)("single_quoted",Al)("double_quoted",Tl)(),Ll=Pt(/(?:\s+attr_name(?:\s*=\s*attr_value)?)/)("attr_name",Cl)("attr_value",Il)(),Rl=Pt(/<[A-Za-z][A-Za-z0-9]*attribute*\s*\/?>/)("attribute",Ll)(),Ol=/<\/[A-Za-z][A-Za-z0-9]*\s*>/,Pl=/<!---->|<!--(?:-?[^>-])(?:-?[^-])*-->/,Nl=/<[?].*?[?]>/,Dl=/<![A-Z]+\s+[^>]*>/,Fl=/<!\[CDATA\[[\s\S]*?\]\]>/,jl=Pt(/^(?:open_tag|close_tag|comment|processing|declaration|cdata)/)("open_tag",Rl)("close_tag",Ol)("comment",Pl)("processing",Nl)("declaration",Dl)("cdata",Fl)();function Bl(e){var i=e|32;return i>=97&&i<=122}function ql(e,i){var t,n,r,a=e.pos;return!e.options.html||(r=e.posMax,e.src.charCodeAt(a)!==60||a+2>=r)||(t=e.src.charCodeAt(a+1),t!==33&&t!==63&&t!==47&&!Bl(t))||(n=e.src.slice(a).match(jl),!n)?!1:(i||e.push({type:"htmltag",content:e.src.slice(a,a+n[0].length),level:e.level}),e.pos+=n[0].length,!0)}var zl=/^&#((?:x[a-f0-9]{1,8}|[0-9]{1,8}));/i,Ul=/^&([a-z][a-z0-9]{1,31});/i;function Hl(e,i){var t,n,r,a=e.pos,o=e.posMax;if(e.src.charCodeAt(a)!==38)return!1;if(a+1<o){if(t=e.src.charCodeAt(a+1),t===35){if(r=e.src.slice(a).match(zl),r)return i||(n=r[1][0].toLowerCase()==="x"?parseInt(r[1].slice(1),16):parseInt(r[1],10),e.pending+=Ci(n)?En(n):En(65533)),e.pos+=r[0].length,!0}else if(r=e.src.slice(a).match(Ul),r){var s=xi(r[1]);if(r[1]!==s)return i||(e.pending+=s),e.pos+=r[0].length,!0}}return i||(e.pending+="&"),e.pos++,!0}var cn=[["text",sl],["newline",ll],["escape",ul],["backticks",cl],["del",dl],["ins",hl],["mark",pl],["emphasis",fl],["sub",ml],["sup",yl],["links",bl],["footnote_inline",kl],["footnote_ref",_l],["autolink",El],["htmltag",ql],["entity",Hl]];function Nt(){this.ruler=new ve;for(var e=0;e<cn.length;e++)this.ruler.push(cn[e][0],cn[e][1]);this.validateLink=Vl}Nt.prototype.skipToken=function(e){var i=this.ruler.getRules(""),t=i.length,n=e.pos,r,a;if((a=e.cacheGet(n))>0){e.pos=a;return}for(r=0;r<t;r++)if(i[r](e,!0)){e.cacheSet(n,e.pos);return}e.pos++,e.cacheSet(n,e.pos)};Nt.prototype.tokenize=function(e){for(var i=this.ruler.getRules(""),t=i.length,n=e.posMax,r,a;e.pos<n;){for(a=0;a<t&&(r=i[a](e,!1),!r);a++);if(r){if(e.pos>=n)break;continue}e.pending+=e.src[e.pos++]}e.pending&&e.pushPending()};Nt.prototype.parse=function(e,i,t,n){var r=new qe(e,this,i,t,n);this.tokenize(r)};function Vl(e){var i=["vbscript","javascript","file","data"],t=e.trim().toLowerCase();return t=Oe(t),!(t.indexOf(":")!==-1&&i.indexOf(t.split(":")[0])!==-1)}var $l={options:{html:!1,xhtmlOut:!1,breaks:!1,langPrefix:"language-",linkTarget:"",typographer:!1,quotes:"“”‘’",highlight:null,maxNesting:20},components:{core:{rules:["block","inline","references","replacements","smartquotes","references","abbr2","footnote_tail"]},block:{rules:["blockquote","code","fences","footnote","heading","hr","htmlblock","lheading","list","paragraph","table"]},inline:{rules:["autolink","backticks","del","emphasis","entity","escape","footnote_ref","htmltag","links","newline","text"]}}},Gl={options:{html:!1,xhtmlOut:!1,breaks:!1,langPrefix:"language-",linkTarget:"",typographer:!1,quotes:"“”‘’",highlight:null,maxNesting:20},components:{core:{},block:{},inline:{}}},Wl={options:{html:!0,xhtmlOut:!0,breaks:!1,langPrefix:"language-",linkTarget:"",typographer:!1,quotes:"“”‘’",highlight:null,maxNesting:20},components:{core:{rules:["block","inline","references","abbr2"]},block:{rules:["blockquote","code","fences","heading","hr","htmlblock","lheading","list","paragraph"]},inline:{rules:["autolink","backticks","emphasis","entity","escape","htmltag","links","newline","text"]}}},Kl={default:$l,full:Gl,commonmark:Wl};function Oi(e,i,t){this.src=i,this.env=t,this.options=e.options,this.tokens=[],this.inlineMode=!1,this.inline=e.inline,this.block=e.block,this.renderer=e.renderer,this.typographer=e.typographer}function be(e,i){typeof e!="string"&&(i=e,e="default"),i&&i.linkify!=null&&console.warn(`linkify option is removed. Use linkify plugin instead:

import Remarkable from 'remarkable';
import linkify from 'remarkable/linkify';
new Remarkable().use(linkify)
`),this.inline=new Nt,this.block=new jn,this.core=new Li,this.renderer=new Fn,this.ruler=new ve,this.options={},this.configure(Kl[e]),this.set(i||{})}be.prototype.set=function(e){Ei(this.options,e)};be.prototype.configure=function(e){var i=this;if(!e)throw new Error("Wrong `remarkable` preset, check name/content");e.options&&i.set(e.options),e.components&&Object.keys(e.components).forEach(function(t){e.components[t].rules&&i[t].ruler.enable(e.components[t].rules,!0)})};be.prototype.use=function(e,i){return e(this,i),this};be.prototype.parse=function(e,i){var t=new Oi(this,e,i);return this.core.process(t),t.tokens};be.prototype.render=function(e,i){return i=i||{},this.renderer.render(this.parse(e,i),this.options,i)};be.prototype.parseInline=function(e,i){var t=new Oi(this,e,i);return t.inlineMode=!0,this.core.process(t),t.tokens};be.prototype.renderInline=function(e,i){return i=i||{},this.renderer.render(this.parseInline(e,i),this.options,i)};var Mn=function(){function e(){g(this,e)}return y(e,null,[{key:"instantiate",value:function(){var t=window.hljs;return t?new be({highlight:function(r,a){if(a&&t.getLanguage(a))try{return t.highlight(a,r).value}catch{console.error("failed to setup the highlight dependency")}try{return t.highlightAuto(r).value}catch{console.error("failed to automatically highlight messages")}return""},html:!1,xhtmlOut:!1,breaks:!1,langPrefix:"language-",linkTarget:"_blank",typographer:!0}):new be({linkTarget:"_blank"})}},{key:"createNew",value:function(){var t=e.instantiate();return t.inline.validateLink=function(){return!0},t}}]),e}(),Pi=function(){function e(){g(this,e)}return y(e,null,[{key:"addMessage",value:function(t,n,r,a){var o;t.elementRef.appendChild(n.outerContainer),t.applyCustomStyles(n,a,!0,(o=t.messageStyles)==null?void 0:o[r]),t.elementRef.scrollTop=t.elementRef.scrollHeight}},{key:"wrapInLink",value:function(t,n,r){var a=document.createElement("a");return a.href=n,a.download=r||e.DEFAULT_FILE_NAME,a.target="_blank",a.appendChild(t),a}},{key:"isNonLinkableDataUrl",value:function(t,n){return!n.startsWith("data")||t==="image"?!1:t==="any"&&n.startsWith("data:text/javascript")||!n.startsWith("data:image")}},{key:"processContent",value:function(t,n,r,a){return!r||e.isNonLinkableDataUrl(t,r)?n:e.wrapInLink(n,r,a)}},{key:"waitToLoadThenScroll",value:function(t){setTimeout(function(){t.scrollTop=t.scrollHeight},60)}},{key:"scrollDownOnImageLoad",value:function(t,n){if(t.startsWith("data"))e.waitToLoadThenScroll(n);else try{fetch(t,{mode:"no-cors"}).catch(function(){}).finally(function(){e.waitToLoadThenScroll(n)})}catch{n.scrollTop=n.scrollHeight}}},{key:"reAddFileRefToObject",value:function(t,n){var r;(r=t.files)==null||r.forEach(function(a,o){var s;a.ref&&(s=n.message.files)!=null&&s[o]&&(n.message.files[o].ref=a.ref)})}},{key:"removeFileRef",value:function(t){var n=V({},t);return delete n.ref,n}}]),e}();Pi.DEFAULT_FILE_NAME="file";var ye=Pi,Mt=function(){function e(){g(this,e)}return y(e,null,[{key:"onNewMessage",value:function(t,n,r){var a,o=JSON.parse(JSON.stringify({message:n,isInitial:r}));ye.reAddFileRefToObject(n,o),(a=t.onNewMessage)==null||a.call(t,o),t.dispatchEvent(new CustomEvent("new-message",{detail:o}))}},{key:"onClearMessages",value:function(t){var n;(n=t.onClearMessages)==null||n.call(t),t.dispatchEvent(new CustomEvent("clear-messages"))}},{key:"onRender",value:function(t){var n;(n=t.onComponentRender)==null||n.call(t,t),t.dispatchEvent(new CustomEvent("render",{detail:t}))}},{key:"onError",value:function(t,n){var r;(r=t.onError)==null||r.call(t,n),t.dispatchEvent(new CustomEvent("error",{detail:n}))}}]),e}(),Et=function(){function e(){g(this,e)}return y(e,null,[{key:"applyCustomStylesToElements",value:function(t,n,r){if(r&&(Object.assign(t.outerContainer.style,r.outerContainer),Object.assign(t.innerContainer.style,r.innerContainer),Object.assign(t.bubbleElement.style,r.bubble),n)){var a=t.bubbleElement.children[0],o=a.tagName.toLocaleLowerCase()!=="a"?a:a.children[0];Object.assign(o.style,r.media)}}},{key:"applySideStyles",value:function(t,n,r,a){a&&(e.applyCustomStylesToElements(t,r,a.shared),n===F.USER_ROLE?e.applyCustomStylesToElements(t,r,a.user):(e.applyCustomStylesToElements(t,r,a.ai),e.applyCustomStylesToElements(t,r,a[n])))}},{key:"isMessageSideStyles",value:function(t){return!!(t.ai||t.shared||t.user)}},{key:"applyCustomStyles",value:function(t,n,r,a,o){var s;o&&t.default!==o?e.isMessageSideStyles(o)?(e.applySideStyles(n,r,a,t.default),e.applySideStyles(n,r,a,o)):(e.applyCustomStylesToElements(n,a,(s=t.default)==null?void 0:s.shared),e.applyCustomStylesToElements(n,a,o)):e.applySideStyles(n,r,a,t.default)}},{key:"extractParticularSharedStyles",value:function(t,n){if(n!=null&&n.shared){var r=n.shared,a={outerContainer:{},innerContainer:{},bubble:{},media:{}};return t.forEach(function(o){var s,l,u,c;a.outerContainer[o]=((s=r.outerContainer)==null?void 0:s[o])||"",a.innerContainer[o]=((l=r.innerContainer)==null?void 0:l[o])||"",a.bubble[o]=((u=r.bubble)==null?void 0:u[o])||"",a.media[o]=((c=r.media)==null?void 0:c[o])||""}),a}}}]),e}(),Ni=function(){function e(i){var t=this;g(this,e),this.messageElementRefs=[],this.messages=[],this.htmlClassUtilities={},this.textElementsToText=[],this.elementRef=e.createContainerElement(),this.messageStyles=i.messageStyles,this._remarkable=Mn.createNew(),this._avatars=i.avatars,this._names=i.names,this._onNewMessage=Mt.onNewMessage.bind(this,i),i.htmlClassUtilities&&(this.htmlClassUtilities=i.htmlClassUtilities),setTimeout(function(){t.submitUserMessage=i.submitUserMessage})}return y(e,[{key:"addNewTextMessage",value:function(t,n,r){if(r!=null&&r.status){var a=this.overwriteText(n,t,this.messageElementRefs);if(a)return a;r.status=!1}var o=this.createAndAppendNewMessageElement(t,n);return o.bubbleElement.classList.add("text-message"),this.applyCustomStyles(o,n,!1),F.fillEmptyMessageElement(o.bubbleElement,t),this.textElementsToText.push([o,t]),o}},{key:"overwriteText",value:function(t,n,r){var a=F.overwriteMessage(this.messages,r,n,t,"text","text-message");if(a){this.renderText(a.bubbleElement,n);var o=F.getLastTextToElement(this.textElementsToText,a);o&&(o[1]=n)}return a}},{key:"createAndAppendNewMessageElement",value:function(t,n){var r=this,a=this.createNewMessageElement(t,n);return this.elementRef.appendChild(a.outerContainer),setTimeout(function(){return he.scrollToBottom(r.elementRef)}),a}},{key:"createNewMessageElement",value:function(t,n){var r;(r=this._introPanel)==null||r.hide();var a=this.messageElementRefs[this.messageElementRefs.length-1];return e.isTemporaryElement(a)&&(a.outerContainer.remove(),this.messageElementRefs.pop()),this.createMessageElements(t,n)}},{key:"createMessageElements",value:function(t,n){var r=e.createBaseElements(),a=r.outerContainer,o=r.innerContainer,s=r.bubbleElement;return a.appendChild(o),this.addInnerContainerElements(s,t,n),this.messageElementRefs.push(r),r}},{key:"addInnerContainerElements",value:function(t,n,r){var a;return((a=this.messages[this.messages.length-1])==null?void 0:a.role)===r&&!this.isLastMessageError()&&F.hideRoleElements(this.messageElementRefs,!!this._avatars,!!this._names),t.classList.add("message-bubble",F.getRoleClass(r),r===F.USER_ROLE?"user-message-text":"ai-message-text"),this.renderText(t,n),F.addRoleElements(t,r,this._avatars,this._names),{bubbleElement:t}}},{key:"applyCustomStyles",value:function(t,n,r,a){t&&this.messageStyles&&Et.applyCustomStyles(this.messageStyles,t,n,r,a)}},{key:"removeLastMessage",value:function(){this.messageElementRefs[this.messageElementRefs.length-1].outerContainer.remove(),this.messageElementRefs.pop()}},{key:"isLastMessageError",value:function(){var t;return(t=F.getLastMessageBubbleElement(this.elementRef))==null?void 0:t.classList.contains("error-message-text")}},{key:"sendClientUpdate",value:function(t){var n=arguments.length>1&&arguments[1]!==void 0?arguments[1]:!1,r;(r=this._onNewMessage)==null||r.call(this,t,n)}},{key:"renderText",value:function(t,n){t.innerHTML=this._remarkable.render(n),t.innerText.trim().length===0&&(t.innerText=n)}},{key:"refreshTextMessages",value:function(){var t=this;this._remarkable=Mn.createNew(),this.textElementsToText.forEach(function(n){t.renderText(n[0].bubbleElement,n[1])})}}],[{key:"createContainerElement",value:function(){var t=document.createElement("div");return t.id="messages",t}},{key:"isTemporaryElement",value:function(t){return(t==null?void 0:t.bubbleElement.classList.contains("loading-message-text"))||Ct.isElementTemporary(t)}},{key:"createBaseElements",value:function(){var t=document.createElement("div"),n=document.createElement("div");n.classList.add("inner-message-container"),t.appendChild(n),t.classList.add("outer-message-container");var r=document.createElement("div");return r.classList.add("message-bubble"),n.appendChild(r),{outerContainer:t,innerContainer:n,bubbleElement:r}}},{key:"createMessageContent",value:function(t){var n=t.text,r=t.files,a=t.html,o=t._sessionId,s=t.role,l={role:s||F.AI_ROLE};return n&&(l.text=n),r&&(l.files=r),a&&(l.html=a),!n&&!r&&!a&&(l.text=""),o&&(l._sessionId=o),l}}]),e}(),qn=function(){function e(i){g(this,e),this._fileAdded=!1,this._streamedContent="",this._streamType="",this._hasStreamEnded=!1,this._messages=i}return y(e,[{key:"upsertStreamedMessage",value:function(t){var n;if(!this._hasStreamEnded){if((t==null?void 0:t.text)===void 0&&(t==null?void 0:t.html)===void 0)return console.error(ee.INVALID_STREAM_EVENT);var r=(t==null?void 0:t.text)||(t==null?void 0:t.html)||"",a=he.isScrollbarAtBottomOfElement(this._messages.elementRef),o=(t==null?void 0:t.text)!==void 0?"text":"html";if(!this._elements&&this._streamedContent==="")this.setInitialState(o,r,t==null?void 0:t.role);else{if(this._streamType!==o)return console.error(ee.INVALID_STREAM_EVENT_MIX);this.updateBasedOnType(r,o,(n=this._elements)==null?void 0:n.bubbleElement,t==null?void 0:t.overwrite)}a&&he.scrollToBottom(this._messages.elementRef)}}},{key:"setInitialState",value:function(t,n,r){var a;this._streamType=t,(a=r)!==null&&a!==void 0||(r=F.AI_ROLE),this._elements=t==="text"?this._messages.addNewTextMessage(n,r):xn.add(this._messages,n,r,this._messages.messageElementRefs),this._elements.bubbleElement.classList.add(e.MESSAGE_CLASS),this._streamedContent=n,this._activeMessageRole=r,this._message=pi({role:this._activeMessageRole},t,this._streamedContent),this._messages.messages.push(this._message)}},{key:"updateBasedOnType",value:function(t,n,r){var a=arguments.length>3&&arguments[3]!==void 0?arguments[3]:!1;F.unfillEmptyMessageElement(r,t),(n==="text"?this.updateText:this.updateHTML).bind(this)(t,r,a)}},{key:"updateText",value:function(t,n,r){this._streamedContent=r?t:this._streamedContent+t,this._messages.textElementsToText[this._messages.textElementsToText.length-1][1]=this._streamedContent,this._messages.renderText(n,this._streamedContent)}},{key:"updateHTML",value:function(t,n,r){if(r)this._streamedContent=t,n.innerHTML=t;else{var a=document.createElement("span");a.innerHTML=t,n.appendChild(a),this._streamedContent=e.HTML_CONTENT_PLACEHOLDER}}},{key:"finaliseStreamedMessage",value:function(){var t,n,r=this._messages.textElementsToText;if(!(this._fileAdded&&!this._elements)){if(!this._elements)throw Error(ee.NO_VALID_STREAM_EVENTS_SENT);(t=this._elements.bubbleElement)!=null&&t.classList.contains(e.MESSAGE_CLASS)&&(this._streamType==="text"?(r[r.length-1][1]=this._streamedContent,this._message&&(this._message.text=this._streamedContent),this._messages.textToSpeech&&xt.speak(this._streamedContent,this._messages.textToSpeech)):this._streamType==="html"&&(this._streamedContent===e.HTML_CONTENT_PLACEHOLDER&&(this._streamedContent=((n=this._elements.bubbleElement)==null?void 0:n.innerHTML)||""),this._elements&&at.apply(this._messages,this._elements.outerContainer),this._message&&(this._message.html=this._streamedContent)),this._message&&this._messages.sendClientUpdate(Ni.createMessageContent(this._message),!1),this._hasStreamEnded=!0)}}},{key:"markFileAded",value:function(){this._fileAdded=!0}}]),e}();qn.MESSAGE_CLASS="streamed-message";qn.HTML_CONTENT_PLACEHOLDER="htmlplaceholder";var Pe=qn,Di=function(){function e(){g(this,e)}return y(e,null,[{key:"tempRemoveContentHeader",value:function(){var i=k(f().mark(function n(r,a,o){var s,l;return f().wrap(function(c){for(;;)switch(c.prev=c.next){case 0:if(r!=null&&r.headers){c.next=2;break}throw new Error("Request settings have not been set up");case 2:return s=r.headers[e.CONTENT_TYPE],delete r.headers[e.CONTENT_TYPE],c.prev=4,c.next=7,a(o);case 7:l=c.sent,c.next=13;break;case 10:throw c.prev=10,c.t0=c.catch(4),r.headers[e.CONTENT_TYPE]=s,c.t0;case 13:return c.abrupt("return",(r.headers[e.CONTENT_TYPE]=s,l));case 14:case"end":return c.stop()}},n,null,[[4,10]])}));function t(n,r,a){return i.apply(this,arguments)}return t}()},{key:"displayError",value:function(t,n){var r=arguments.length>2&&arguments[2]!==void 0?arguments[2]:"Service error, please try again.";if(console.error(n),R(n)=="object")return Object.keys(n).length===0?t.addNewErrorMessage("service",r):t.addNewErrorMessage("service",JSON.stringify(n));t.addNewErrorMessage("service",n)}},{key:"fetch",value:function(i){function t(n,r,a,o){return i.apply(this,arguments)}return t.toString=function(){return i.toString()},t}(function(i,t,n,r){var a,o,s={method:((a=i.requestSettings)==null?void 0:a.method)||"POST",headers:t};return s.method!=="GET"&&(s.body=n?JSON.stringify(r):r),i.requestSettings.credentials&&(s.credentials=i.requestSettings.credentials),fetch(((o=i.requestSettings)==null?void 0:o.url)||i.url||"",s)})},{key:"processResponseByType",value:function(t){var n=t.headers.get("content-type");return n!=null&&n.includes("application/json")?t.json():n!=null&&n.includes("text/plain")||!n?t:t.blob()}},{key:"processRequestInterceptor",value:function(){var i=k(f().mark(function n(r,a){var o,s,l,u;return f().wrap(function(d){for(;;)switch(d.prev=d.next){case 0:return d.next=2,(o=r.requestInterceptor)==null?void 0:o.call(r,a);case 2:if(d.t0=d.sent,d.t0){d.next=5;break}d.t0=a;case 5:return s=d.t0,l=s,u=s,d.abrupt("return",{body:l.body,headers:l.headers,error:u.error});case 9:case"end":return d.stop()}},n)}));function t(n,r){return i.apply(this,arguments)}return t}()},{key:"validateResponseFormat",value:function(t){return t&&R(t)=="object"&&(typeof t.error=="string"||typeof t.text=="string"||typeof t.html=="string"||Array.isArray(t.files))}},{key:"onInterceptorError",value:function(t,n,r){t.addNewErrorMessage("service",n),r==null||r()}}]),e}();Di.CONTENT_TYPE="Content-Type";var B=Di;function Yl(e,i){return An.apply(this,arguments)}function An(){return An=k(f().mark(function e(i,t){var n,r;return f().wrap(function(o){for(;;)switch(o.prev=o.next){case 0:n=i.getReader();case 1:return o.next=3,n.read();case 3:if((r=o.sent).done){o.next=7;break}t(r.value);case 5:o.next=1;break;case 7:case"end":return o.stop()}},e)})),An.apply(this,arguments)}function Jl(e){var i,t,n,r=!1;return function(a){i===void 0?(i=a,t=0,n=-1):i=Xl(i,a);for(var o=i.length,s=0;t<o;){r&&(i[t]===10&&(s=++t),r=!1);for(var l=-1;t<o&&l===-1;++t)switch(i[t]){case 58:n===-1&&(n=t-s);break;case 13:r=!0;case 10:l=t;break}if(l===-1)break;e(i.subarray(s,l),n),s=t,n=-1}s===o?i=void 0:s!==0&&(i=i.subarray(s),t-=s)}}function Zl(e,i,t){var n=xr(),r=new TextDecoder;return function(a,o){if(a.length===0)t==null||t(n),n=xr();else if(o>0){var s=r.decode(a.subarray(0,o)),l=o+(a[o+1]===32?2:1),u=r.decode(a.subarray(l));switch(s){case"data":n.data=n.data?n.data+`
`+u:u;break;case"event":n.event=u;break;case"id":e(n.id=u);break;case"retry":var c=parseInt(u,10);isNaN(c)||i(n.retry=c);break}}}}function Xl(e,i){var t=new Uint8Array(e.length+i.length);return t.set(e),t.set(i,e.length),t}function xr(){return{data:"",event:"",id:"",retry:void 0}}var Ql=globalThis&&globalThis.__rest||function(e,i){var t={};for(var n in e)Object.prototype.hasOwnProperty.call(e,n)&&i.indexOf(n)<0&&(t[n]=e[n]);if(e!=null&&typeof Object.getOwnPropertySymbols=="function")for(var r=0,n=Object.getOwnPropertySymbols(e);r<n.length;r++)i.indexOf(n[r])<0&&Object.prototype.propertyIsEnumerable.call(e,n[r])&&(t[n[r]]=e[n[r]]);return t},Tn="text/event-stream",eu=1e3,Er="last-event-id";function tu(e,i){var t=i.signal,n=i.headers,r=i.onopen,a=i.onmessage,o=i.onclose,s=i.onerror,l=i.openWhenHidden,u=i.fetch,c=Ql(i,["signal","headers","onopen","onmessage","onclose","onerror","openWhenHidden","fetch"]);return new Promise(function(d,h){var p=Object.assign({},n);p.accept||(p.accept=Tn);var v;function m(){v.abort(),document.hidden||M()}l||document.addEventListener("visibilitychange",m);var b=eu,w=0;function _(){document.removeEventListener("visibilitychange",m),window.clearTimeout(w),v.abort()}t==null||t.addEventListener("abort",function(){_(),d()});var x=u??window.fetch,N=r??nu;function M(){return j.apply(this,arguments)}function j(){return j=k(f().mark(function G(){var H,Z,te;return f().wrap(function($){for(;;)switch($.prev=$.next){case 0:return v=new AbortController,$.prev=1,$.next=4,x(e,Object.assign(Object.assign({},c),{headers:p,signal:v.signal}));case 4:return Z=$.sent,$.next=7,N(Z);case 7:return $.next=9,Yl(Z.body,Jl(Zl(function(Q){Q?p[Er]=Q:delete p[Er]},function(Q){b=Q},a)));case 9:o==null||o(),_(),d(),$.next=17;break;case 14:if($.prev=14,$.t0=$.catch(1),!v.signal.aborted)try{te=(H=s==null?void 0:s($.t0))!==null&&H!==void 0?H:b,window.clearTimeout(w),w=window.setTimeout(M,te)}catch(Q){_(),h(Q)}case 17:case"end":return $.stop()}},G,null,[[1,14]])})),j.apply(this,arguments)}M()})}function nu(e){var i=e.headers.get("content-type");if(!(i!=null&&i.startsWith(Tn)))throw new Error("Expected content-type to be ".concat(Tn,", Actual: ").concat(i))}var re=function(){function e(){g(this,e)}return y(e,null,[{key:"request",value:function(){var i=k(f().mark(function n(r,a,o){var s,l,u,c,d,h,p,v,m,b,w,_,x,N,M,j,G,H,Z=arguments;return f().wrap(function(X){for(;;)switch(X.prev=X.next){case 0:return s=Z.length>3&&Z[3]!==void 0?Z[3]:!0,v={body:a,headers:(l=r.requestSettings)==null?void 0:l.headers},X.next=4,B.processRequestInterceptor(r.deepChat,v);case 4:if(m=X.sent,b=m.body,w=m.headers,_=m.error,x=r.streamHandlers,N=x.onOpen,M=x.onClose,j=x.abortStream,!_){X.next=14;break}return X.abrupt("return",B.onInterceptorError(o,_,M));case 14:if(!((u=r.requestSettings)!=null&&u.handler)){X.next=16;break}return X.abrupt("return",zn.stream(r,b,o));case 16:if(((c=r.requestSettings)==null?void 0:c.url)!==Se.URL){X.next=18;break}return X.abrupt("return",Se.requestStream(o,r.streamHandlers));case 18:G=new Pe(o),H=B.fetch.bind(this,r,w,s),tu(((d=r.requestSettings)==null?void 0:d.url)||r.url||"",{method:((h=r.requestSettings)==null?void 0:h.method)||"POST",headers:w,credentials:(p=r.requestSettings)==null?void 0:p.credentials,body:s?JSON.stringify(b):b,openWhenHidden:!0,onopen:function(Q){return k(f().mark(function Y(){return f().wrap(function(C){for(;;)switch(C.prev=C.next){case 0:if(!Q.ok){C.next=2;break}return C.abrupt("return",N());case 2:return C.next=4,B.processResponseByType(Q);case 4:throw C.sent;case 5:case"end":return C.stop()}},Y)}))()},onmessage:function(Q){return k(f().mark(function Y(){var Ce,C,S,E,L;return f().wrap(function(I){for(;;)switch(I.prev=I.next){case 0:if(JSON.stringify(Q.data)===JSON.stringify("[DONE]")){I.next=9;break}try{E=JSON.parse(Q.data)}catch{E={}}return I.next=4,(C=(Ce=r.deepChat).responseInterceptor)==null?void 0:C.call(Ce,E);case 4:if(I.t0=I.sent,I.t0){I.next=7;break}I.t0=E;case 7:L=I.t0,(S=r.extractResultData)==null||S.call(r,L,H,b).then(function(W){r.asyncCallInProgress&&W&&W.text!==""?(e.simulate(o,r.streamHandlers,W),M(),r.asyncCallInProgress=!1):e.upsertWFiles(o,G.upsertStreamedMessage.bind(G),G,W)}).catch(function(W){return B.displayError(o,W)});case 9:case"end":return I.stop()}},Y)}))()},onerror:function(Q){throw M(),Q},onclose:function(){r.asyncCallInProgress||(G.finaliseStreamedMessage(),M())},signal:j.signal}).catch(function($){var Q;o.isLastMessageError()||(Q=r.extractResultData)==null||Q.call(r,$).then(function(){B.displayError(o,$)}).catch(function(Y){B.displayError(o,Y)})});case 20:case"end":return X.stop()}},n,this)}));function t(n,r,a){return i.apply(this,arguments)}return t}()},{key:"simulate",value:function(t,n,r){var a=n;if((r.files||r.html)&&t.addNewMessage(V({sendUpdate:!1,ignoreText:!0},r),!1),r.text){n.onOpen();var o=r.text.split("");e.populateMessages(o,new Pe(t),a)}}},{key:"populateMessages",value:function(t,n,r){var a=arguments.length>3&&arguments[3]!==void 0?arguments[3]:0,o=t[a];if(o){n.upsertStreamedMessage({text:o});var s=setTimeout(function(){e.populateMessages(t,n,r,a+1)},r.simulationInterim||6);r.abortStream.abort=function(){e.abort(s,n,r.onClose)}}else n.finaliseStreamedMessage(),r.onClose()}},{key:"isSimulation",value:function(t){return R(t)=="object"&&!!t.simulation}},{key:"isSimulatable",value:function(t,n){return e.isSimulation(t)&&n&&(n.text||n.html)}},{key:"abort",value:function(t,n,r){clearTimeout(t),n.finaliseStreamedMessage(),r()}},{key:"upsertWFiles",value:function(t,n,r,a){if(a!=null&&a.text||a!=null&&a.html){var o,s=n(a);(o=r)!==null&&o!==void 0||(r=s||void 0)}a!=null&&a.files&&(t.addNewMessage({files:a.files}),r==null||r.markFileAded())}}]),e}(),Fi=function(){function e(){g(this,e)}return y(e,null,[{key:"generateResponse",value:function(t){var n=t.messages[t.messages.length-1];if(n.files&&n.files.length>0){if(n.files.length>1)return"These are interesting files!";var r=n.files[0];return r.src&&r.src.startsWith("data:image/gif")?"That is a nice gif!":r.type==="image"?"That is a nice image!":r.type==="audio"?"I like the sound of that!":"That is an interesting file!"}if(n.text){if(n.text.charAt(n.text.length-1)==="?")return"I'm sorry but I can't answer that question...";if(n.text.includes("updog"))return"What's updog?"}return"Hi there! This is a demo response!"}},{key:"getCustomResponse",value:function(t,n){return typeof t=="function"?t(n):t}},{key:"getResponse",value:function(t){return t.customDemoResponse?e.getCustomResponse(t.customDemoResponse,t.messages[t.messages.length-1]):{text:e.generateResponse(t)}}},{key:"request",value:function(t,n){var r=e.getResponse(n);setTimeout(k(f().mark(function a(){var o,s,l;return f().wrap(function(c){for(;;)switch(c.prev=c.next){case 0:return c.next=2,(s=(o=t.deepChat).responseInterceptor)==null?void 0:s.call(o,r);case 2:if(c.t0=c.sent,c.t0){c.next=5;break}c.t0=r;case 5:l=c.t0,l.error?(n.addNewErrorMessage("service",l.error),t.completionsHandlers.onFinish()):re.isSimulatable(t.deepChat.stream,l)?re.simulate(n,t.streamHandlers,l):(n.addNewMessage(l),t.completionsHandlers.onFinish());case 7:case"end":return c.stop()}},a)})),400)}},{key:"requestStream",value:function(t,n){setTimeout(function(){var r=e.getResponse(t);re.simulate(t,n,r)},400)}}]),e}();Fi.URL="deep-chat-demo";var Se=Fi,lt=function(){function e(){g(this,e)}return y(e,null,[{key:"setup",value:function(t){t.requestSettings.url!==Se.URL&&(t.permittedErrorPrefixes=["Connection error","Error in server message"],t.websocket="pending")}},{key:"createConnection",value:function(t,n){if(document.body.contains(t.deepChat)){var r=t.requestSettings.websocket;if(r){if(t.requestSettings.handler)return zn.websocket(t,n);try{var a=typeof r!="boolean"?r:void 0,o=new WebSocket(t.requestSettings.url||"",a);t.websocket=o,t.websocket.onopen=function(){var s,l;n.removeError(),t.websocket&&R(t.websocket)=="object"&&e.assignListeners(t,o,n),(l=(s=t.deepChat)._validationHandler)==null||l.call(s)},t.websocket.onerror=function(s){console.error(s),e.retryConnection(t,n)}}catch(s){console.error(s),e.retryConnection(t,n)}}}}},{key:"retryConnection",value:function(t,n){var r,a;(a=(r=t.deepChat)._validationHandler)==null||a.call(r),document.body.contains(t.deepChat)&&(t.websocket="pending",n.isLastMessageError()||n.addNewErrorMessage("service","Connection error"),setTimeout(function(){e.createConnection(t,n)},5e3))}},{key:"assignListeners",value:function(t,n,r){var a=this,o={};n.onmessage=function(){var s=k(f().mark(function l(u){var c,d,h,p,v,m,b;return f().wrap(function(_){for(;;)switch(_.prev=_.next){case 0:if(!t.extractResultData){_.next=20;break}return _.prev=1,h=JSON.parse(u.data),_.next=5,(d=(c=t.deepChat).responseInterceptor)==null?void 0:d.call(c,h);case 5:if(_.t0=_.sent,_.t0){_.next=8;break}_.t0=h;case 8:return p=_.t0,_.next=11,t.extractResultData(p);case 11:if(v=_.sent,!(!v||R(v)!="object")){_.next=14;break}throw Error(ee.INVALID_RESPONSE(h,"server",!!t.deepChat.responseInterceptor,p));case 14:re.isSimulation(t.deepChat.stream)?(m=e.stream.bind(a,t,r,o),b=o[h.role||F.AI_ROLE],re.upsertWFiles(r,m,b,v)):r.addNewMessage(v),_.next=20;break;case 17:_.prev=17,_.t1=_.catch(1),B.displayError(r,_.t1,"Error in server message");case 20:case"end":return _.stop()}},l,null,[[1,17]])}));return function(l){return s.apply(this,arguments)}}(),n.onclose=function(){console.error("Connection closed"),r.isLastMessageError()||r.addNewErrorMessage("service","Connection error"),t.deepChat.stream&&t.streamHandlers.abortStream.abort(),e.createConnection(t,r)}}},{key:"sendWebsocket",value:function(){var i=k(f().mark(function n(r,a,o){var s,l,u,c,d,h,p,v,m,b=arguments;return f().wrap(function(_){for(;;)switch(_.prev=_.next){case 0:if(s=b.length>3&&b[3]!==void 0?b[3]:!0,c=r.websocket,!(!c||c==="pending")){_.next=4;break}return _.abrupt("return");case 4:return d={body:a,headers:(l=r.requestSettings)==null?void 0:l.headers},_.next=7,B.processRequestInterceptor(r.deepChat,d);case 7:if(h=_.sent,p=h.body,v=h.error,!v){_.next=12;break}return _.abrupt("return",o.addNewErrorMessage("service",v));case 12:if(e.isWebSocket(c)){_.next=14;break}return _.abrupt("return",c.newUserMessage.listener(p));case 14:if(m=s?JSON.stringify(p):p,((u=r.requestSettings)==null?void 0:u.url)!==Se.URL){_.next=17;break}return _.abrupt("return",Se.request(r,o));case 17:c.readyState===void 0||c.readyState!==c.OPEN?(console.error("Connection is not open"),o.isLastMessageError()||o.addNewErrorMessage("service","Connection error")):(c.send(JSON.stringify(m)),r.completionsHandlers.onFinish());case 18:case"end":return _.stop()}},n)}));function t(n,r,a){return i.apply(this,arguments)}return t}()},{key:"canSendMessage",value:function(t){return t?t==="pending"?!1:e.isWebSocket(t)?t.readyState!==void 0&&t.readyState===t.OPEN:t.isOpen:!0}},{key:"isWebSocket",value:function(t){return t.send!==void 0}},{key:"stream",value:function(t,n,r,a){if(a){var o=t.deepChat.stream.simulation;if(typeof o=="string"){var s,l=a.role||F.AI_ROLE,u=r[l];a.text===o?(u==null||u.finaliseStreamedMessage(),delete r[l]):((s=r[l])!==null&&s!==void 0||(r[l]=new Pe(n)),r[l].upsertStreamedMessage(a))}else re.simulate(n,t.streamHandlers,a)}}}]),e}(),zn=function(){function e(){g(this,e)}return y(e,null,[{key:"request",value:function(){var i=k(f().mark(function n(r,a,o){var s,l,u,c,d;return f().wrap(function(p){for(;;)switch(p.prev=p.next){case 0:u=!0,c=function(){var v=k(f().mark(function m(b){var w,_,x;return f().wrap(function(M){for(;;)switch(M.prev=M.next){case 0:if(u){M.next=2;break}return M.abrupt("return");case 2:return u=!1,M.next=5,(_=(w=r.deepChat).responseInterceptor)==null?void 0:_.call(w,b);case 5:if(M.t0=M.sent,M.t0){M.next=8;break}M.t0=b;case 8:x=M.t0,B.validateResponseFormat(x)?typeof x.error=="string"?(console.error(x.error),o.addNewErrorMessage("service",x.error),r.completionsHandlers.onFinish()):re.isSimulatable(r.deepChat.stream,x)?re.simulate(o,r.streamHandlers,x):(o.addNewMessage(x),r.completionsHandlers.onFinish()):(console.error(ee.INVALID_RESPONSE(b,"server",!!r.deepChat.responseInterceptor,x)),o.addNewErrorMessage("service","Error in server message"),r.completionsHandlers.onFinish());case 10:case"end":return M.stop()}},m)}));return function(b){return v.apply(this,arguments)}}(),d=e.generateOptionalSignals(),(l=(s=r.requestSettings).handler)==null||l.call(s,a,V(V({},d),{},{onResponse:c}));case 3:case"end":return p.stop()}},n)}));function t(n,r,a){return i.apply(this,arguments)}return t}()},{key:"attemptToFinaliseStream",value:function(t,n){try{t.finaliseStreamedMessage()}catch(r){console.error(r),n.addNewErrorMessage("service",r)}}},{key:"stream",value:function(t,n,r){var a,o,s=!0,l=!1,u=new Pe(r),c=function(){l||!s||(t.streamHandlers.onOpen(),l=!0)},d=function(){s&&(e.attemptToFinaliseStream(u,r),t.streamHandlers.onClose(),s=!1)},h=function(){var v=k(f().mark(function m(b){var w,_,x;return f().wrap(function(M){for(;;)switch(M.prev=M.next){case 0:if(s){M.next=2;break}return M.abrupt("return");case 2:return M.next=4,(_=(w=t.deepChat).responseInterceptor)==null?void 0:_.call(w,b);case 4:if(M.t0=M.sent,M.t0){M.next=7;break}M.t0=b;case 7:x=M.t0,B.validateResponseFormat(x)?x.error?(console.error(x.error),u.finaliseStreamedMessage(),r.addNewErrorMessage("service",x.error),t.streamHandlers.onClose(),s=!1):re.upsertWFiles(r,u.upsertStreamedMessage.bind(u),u,x):console.error(ee.INVALID_RESPONSE(b,"server",!!t.deepChat.responseInterceptor,x));case 9:case"end":return M.stop()}},m)}));return function(b){return v.apply(this,arguments)}}();t.streamHandlers.abortStream.abort=function(){e.attemptToFinaliseStream(u,r),t.streamHandlers.onClose(),s=!1};var p=e.generateOptionalSignals();(o=(a=t.requestSettings).handler)==null||o.call(a,n,V(V({},p),{},{onOpen:c,onResponse:h,onClose:d,stopClicked:t.streamHandlers.stopClicked}))}},{key:"websocket",value:function(t,n){var r=this,a,o,s={isOpen:!1,newUserMessage:{listener:function(){}},roleToStream:{}};t.websocket=s;var l=function(){n.removeError(),s.isOpen=!0},u=function(){s.isOpen=!1},c=function(){var h=k(f().mark(function p(v){var m,b,w,_,x;return f().wrap(function(M){for(;;)switch(M.prev=M.next){case 0:if(s.isOpen){M.next=2;break}return M.abrupt("return");case 2:return M.next=4,(b=(m=t.deepChat).responseInterceptor)==null?void 0:b.call(m,v);case 4:if(M.t0=M.sent,M.t0){M.next=7;break}M.t0=v;case 7:w=M.t0,B.validateResponseFormat(w)?typeof w.error=="string"?(console.error(w.error),n.isLastMessageError()||n.addNewErrorMessage("service",w.error)):re.isSimulation(t.deepChat.stream)?(_=lt.stream.bind(r,t,n,s.roleToStream),x=s.roleToStream[v.role||F.AI_ROLE],re.upsertWFiles(n,_,x,v)):n.addNewMessage(w):(console.error(ee.INVALID_RESPONSE(v,"server",!!t.deepChat.responseInterceptor,w)),n.addNewErrorMessage("service","Error in server message"));case 9:case"end":return M.stop()}},p)}));return function(v){return h.apply(this,arguments)}}(),d=e.generateOptionalSignals();(o=(a=t.requestSettings).handler)==null||o.call(a,void 0,V(V({},d),{},{onOpen:l,onResponse:c,onClose:u,newUserMessage:s.newUserMessage}))}},{key:"generateOptionalSignals",value:function(){return{onClose:function(){},onOpen:function(){},stopClicked:{listener:function(){}},newUserMessage:{listener:function(){}}}}}]),e}(),J=function(){function e(){g(this,e)}return y(e,null,[{key:"request",value:function(){var i=k(f().mark(function n(r,a,o){var s,l,u,c,d,h,p,v,m,b,w,_,x=arguments;return f().wrap(function(M){for(;;)switch(M.prev=M.next){case 0:return s=x.length>3&&x[3]!==void 0?x[3]:!0,d={body:a,headers:(l=r.requestSettings)==null?void 0:l.headers},M.next=4,B.processRequestInterceptor(r.deepChat,d);case 4:if(h=M.sent,p=h.body,v=h.headers,m=h.error,b=r.completionsHandlers.onFinish,!m){M.next=11;break}return M.abrupt("return",B.onInterceptorError(o,m,b));case 11:if(!((u=r.requestSettings)!=null&&u.handler)){M.next=13;break}return M.abrupt("return",zn.request(r,p,o));case 13:if(((c=r.requestSettings)==null?void 0:c.url)!==Se.URL){M.next=15;break}return M.abrupt("return",Se.request(r,o));case 15:w=!0,_=B.fetch.bind(this,r,v,s),_(p).then(function(j){return w=!!j.ok,j}).then(function(j){return B.processResponseByType(j)}).then(function(){var j=k(f().mark(function G(H){var Z,te,X,$;return f().wrap(function(Y){for(;;)switch(Y.prev=Y.next){case 0:if(r.extractResultData){Y.next=2;break}return Y.abrupt("return");case 2:return Y.next=4,(te=(Z=r.deepChat).responseInterceptor)==null?void 0:te.call(Z,H);case 4:if(Y.t0=Y.sent,Y.t0){Y.next=7;break}Y.t0=H;case 7:return X=Y.t0,Y.next=10,r.extractResultData(X,_,p);case 10:if($=Y.sent,w){Y.next=13;break}throw H;case 13:if(!(!$||R($)!="object")){Y.next=15;break}throw Error(ee.INVALID_RESPONSE(H,"response",!!r.deepChat.responseInterceptor,X));case 15:$.makingAnotherRequest||(re.isSimulatable(r.deepChat.stream,$)?re.simulate(o,r.streamHandlers,$):(o.addNewMessage($),b()));case 16:case"end":return Y.stop()}},G)}));return function(G){return j.apply(this,arguments)}}()).catch(function(j){B.displayError(o,j),b()});case 18:case"end":return M.stop()}},n,this)}));function t(n,r,a){return i.apply(this,arguments)}return t}()},{key:"executePollRequest",value:function(t,n,r,a){var o=t.completionsHandlers.onFinish;fetch(n,r).then(function(s){return s.json()}).then(function(){var s=k(f().mark(function l(u){var c,d,h;return f().wrap(function(v){for(;;)switch(v.prev=v.next){case 0:if(t.extractPollResultData){v.next=2;break}return v.abrupt("return");case 2:return v.t0=t,v.next=5,(d=(c=t.deepChat).responseInterceptor)==null?void 0:d.call(c,u);case 5:if(v.t1=v.sent,v.t1){v.next=8;break}v.t1=u;case 8:return v.t2=v.t1,v.next=11,v.t0.extractPollResultData.call(v.t0,v.t2);case 11:h=v.sent,h.timeoutMS?setTimeout(function(){e.executePollRequest(t,n,r,a)},h.timeoutMS):re.isSimulatable(t.deepChat.stream,u)?re.simulate(a,t.streamHandlers,h):(a.addNewMessage(h),o());case 13:case"end":return v.stop()}},l)}));return function(l){return s.apply(this,arguments)}}()).catch(function(s){B.displayError(a,s),o()})}},{key:"poll",value:function(){var i=k(f().mark(function n(r,a,o){var s,l,u,c,d,h,p,v,m,b,w,_,x,N=arguments;return f().wrap(function(j){for(;;)switch(j.prev=j.next){case 0:return s=N.length>3&&N[3]!==void 0?N[3]:!0,d={body:a,headers:(l=r.requestSettings)==null?void 0:l.headers},j.next=4,B.processRequestInterceptor(r.deepChat,d);case 4:if(h=j.sent,p=h.body,v=h.headers,m=h.error,!m){j.next=10;break}return j.abrupt("return",B.onInterceptorError(o,m));case 10:b=((u=r.requestSettings)==null?void 0:u.url)||r.url||"",w=((c=r.requestSettings)==null?void 0:c.method)||"POST",_=s?JSON.stringify(p):p,x={method:w,body:_,headers:v},r.requestSettings.credentials&&(x.credentials=r.requestSettings.credentials),e.executePollRequest(r,b,x,o);case 12:case"end":return j.stop()}},n)}));function t(n,r,a){return i.apply(this,arguments)}return t}()},{key:"verifyKey",value:function(t,n,r,a,o,s,l,u,c){if(t==="")return s(ee.INVALID_KEY);l(),fetch(n,{method:a,headers:r,body:c||null}).then(function(d){return B.processResponseByType(d)}).then(function(d){u(d,t,o,s)}).catch(function(d){s(ee.CONNECTION_FAILED),console.error(d)})}}]),e}(),Un=function(){function e(){g(this,e)}return y(e,null,[{key:"getCharacterLimitMessages",value:function(t,n){var r;if(n===-1)return t;var a=0,o=t.length-1;for(o;o>=0;o-=1){var s=(r=t[o])==null?void 0:r.text;if(s!==void 0&&(a+=s.length,a>n)){t[o].text=s.substring(0,s.length-(a-n));break}}return t.slice(Math.max(o,0))}},{key:"getMaxMessages",value:function(t,n){return t.slice(Math.max(t.length-n,0))}},{key:"processMessages",value:function(t,n,r){return n!==void 0?n>0&&(t=e.getMaxMessages(t,n)):t=[t[t.length-1]],t=JSON.parse(JSON.stringify(t)),r===void 0?t:e.getCharacterLimitMessages(t,r)}}]),e}(),ru=function(){function e(){g(this,e)}return y(e,null,[{key:"parseConfig",value:function(t,n,r,a){var o,s={files:n};if(R(a)=="object"){var l=a.files,u=a.request,c=a.button;l&&(l.infoModal&&(s.files.infoModal=l.infoModal,(o=l.infoModal)!=null&&o.textMarkDown&&(s.infoModalTextMarkUp=r.render(l.infoModal.textMarkDown))),l.acceptedFormats&&(s.files.acceptedFormats=l.acceptedFormats),l.maxNumberOfFiles&&(s.files.maxNumberOfFiles=l.maxNumberOfFiles)),s.button=c,u&&(u.headers||u.method||u.url||u.credentials||t.headers||t.method||t.url||t.credentials)&&(s.request={url:(u==null?void 0:u.url)||t.url,method:(u==null?void 0:u.method)||t.method,headers:(u==null?void 0:u.headers)||t.headers,credentials:(u==null?void 0:u.credentials)||t.credentials})}return s}},{key:"processMixedFiles",value:function(t,n,r){if(r){var a={acceptedFormats:""};t.fileTypes.mixedFiles=e.parseConfig(t.requestSettings,a,n,r)}}},{key:"processMicrophone",value:function(t,n,r,a){var o,s,l,u,c,d,h,p,v=V({acceptedFormats:"audio/*"},((l=t.fileTypes.audio)==null?void 0:l.files)||{});r&&(navigator.mediaDevices.getUserMedia!==void 0?(t.recordAudio=e.parseConfig(t.requestSettings,v,n,r),R(r)=="object"&&r.files&&((o=(u=t.recordAudio).files)!==null&&o!==void 0||(u.files={}),t.recordAudio.files.format=(c=r.files)==null?void 0:c.format,t.recordAudio.files.maxDurationSeconds=(d=r.files)==null?void 0:d.maxDurationSeconds,(h=t.fileTypes.audio)!=null&&h.files&&((s=(p=t.fileTypes.audio.files).maxNumberOfFiles)!==null&&s!==void 0||(p.maxNumberOfFiles=r.files.maxNumberOfFiles)))):a||(t.fileTypes.audio=e.parseConfig(t.requestSettings,v,n,r)))}},{key:"processAudioConfig",value:function(t,n,r,a){if(!(!r&&!a)){var o=V({acceptedFormats:"audio/*"},(a==null?void 0:a.files)||{});t.fileTypes.audio=e.parseConfig(t.requestSettings,o,n,r)}}},{key:"processGifConfig",value:function(t,n,r,a){if(!(!r&&!a)){var o=V({acceptedFormats:"image/gif"},(a==null?void 0:a.files)||{});t.fileTypes.gifs=e.parseConfig(t.requestSettings,o,n,r)}}},{key:"processCamera",value:function(t,n,r,a){var o,s,l,u,c,d=V({acceptedFormats:"image/*"},((s=t.fileTypes.images)==null?void 0:s.files)||{});r&&(navigator.mediaDevices.getUserMedia!==void 0?(t.camera=e.parseConfig(t.requestSettings,d,n,r),R(r)=="object"&&(t.camera.modalContainerStyle=r.modalContainerStyle,r.files&&((o=(l=t.camera).files)!==null&&o!==void 0||(l.files={}),t.camera.files.format=(u=r.files)==null?void 0:u.format,t.camera.files.dimensions=(c=r.files)==null?void 0:c.dimensions))):a||(t.fileTypes.images=e.parseConfig(t.requestSettings,d,n,r)))}},{key:"processImagesConfig",value:function(t,n,r,a){if(!(!r&&!a)){var o=V({acceptedFormats:"image/*"},(a==null?void 0:a.files)||{});t.fileTypes.images=e.parseConfig(t.requestSettings,o,n,r)}}},{key:"populateDefaultFileIO",value:function(t,n){var r,a,o,s,l;t&&((r=t.files)!==null&&r!==void 0||(t.files={}),(a=(s=t.files).acceptedFormats)!==null&&a!==void 0||(s.acceptedFormats=n),(o=(l=t.files).maxNumberOfFiles)!==null&&o!==void 0||(l.maxNumberOfFiles=1))}},{key:"set",value:function(t,n,r){e.populateDefaultFileIO(r==null?void 0:r.audio,".4a,.mp3,.webm,.mp4,.mpga,.wav,.mpeg,.m4a"),e.populateDefaultFileIO(r==null?void 0:r.images,".png,.jpg");var a=Mn.createNew();e.processImagesConfig(n,a,t.images,r==null?void 0:r.images),e.processCamera(n,a,t.camera,t.images),e.processGifConfig(n,a,t.gifs,r==null?void 0:r.gifs),e.processAudioConfig(n,a,t.audio,r==null?void 0:r.audio),e.processMicrophone(n,a,t.microphone,t.audio),e.processMixedFiles(n,a,t.mixedFiles)}}]),e}(),At=function(){function e(i,t,n){var r;g(this,e);var a,o,s,l;this.rawBody={},this.validateConfigKey=!1,this.canSendMessage=e.canSendMessage,this.requestSettings={},this.fileTypes={},this.completionsHandlers={},this.streamHandlers={},this.deepChat=i,this.demo=n,Object.assign(this.rawBody,(a=i.request)==null?void 0:a.additionalBodyProps),this.totalMessagesMaxCharLength=(o=i==null?void 0:i.requestBodyLimits)==null?void 0:o.totalMessagesMaxCharLength,this.maxMessages=(s=i==null?void 0:i.requestBodyLimits)==null?void 0:s.maxMessages,ru.set(i,this,t),i.request&&(this.requestSettings=i.request),this.demo&&((r=(l=this.requestSettings).url)!==null&&r!==void 0||(l.url=Se.URL)),this.requestSettings.websocket&&lt.setup(this)}return y(e,[{key:"verifyKey",value:function(t,n){}},{key:"getServiceIOByType",value:function(t){if(t.type.startsWith("audio")&&this.fileTypes.audio)return this.fileTypes.audio;if(t.type.startsWith("image")){if(this.fileTypes.gifs&&t.type.endsWith("/gif"))return this.fileTypes.gifs;if(this.fileTypes.images)return this.fileTypes.images;if(this.camera)return this.camera}return this.fileTypes.mixedFiles}},{key:"request",value:function(){var i=k(f().mark(function n(r,a){var o,s,l=arguments;return f().wrap(function(c){for(;;)switch(c.prev=c.next){case 0:return o=l.length>2&&l[2]!==void 0?l[2]:!0,s=this.deepChat.stream,c.abrupt("return",s&&!re.isSimulation(s)?re.request(this,r,a):J.request(this,r,a,o));case 3:case"end":return c.stop()}},n,this)}));function t(n,r){return i.apply(this,arguments)}return t}()},{key:"callAPIWithText",value:function(){var i=k(f().mark(function n(r,a){var o,s,l,u,c,d,h,p;return f().wrap(function(m){for(;;)switch(m.prev=m.next){case 0:return h=V({messages:a},this.rawBody),p=!1,(l=this.requestSettings.headers)!=null&&l["Content-Type"]||((o=(u=this.requestSettings).headers)!==null&&o!==void 0||(u.headers={}),(s=(c=this.requestSettings.headers)["Content-Type"])!==null&&s!==void 0||(c["Content-Type"]="application/json"),p=!0),m.next=5,this.request(h,r);case 5:p&&((d=this.requestSettings.headers)==null||delete d["Content-Type"]);case 6:case"end":return m.stop()}},n,this)}));function t(n,r){return i.apply(this,arguments)}return t}()},{key:"callApiWithFiles",value:function(){var i=k(f().mark(function n(r,a,o){var s,l,u;return f().wrap(function(d){for(;;)switch(d.prev=d.next){case 0:return s=e.createCustomFormDataBody(this.rawBody,a,o),l=this.requestSettings,u=this.getServiceIOByType(o[0]),this.requestSettings=(u==null?void 0:u.request)||this.requestSettings,d.next=4,this.request(s,r,!1);case 4:this.requestSettings=l;case 5:case"end":return d.stop()}},n,this)}));function t(n,r,a){return i.apply(this,arguments)}return t}()},{key:"callServiceAPI",value:function(){var i=k(f().mark(function n(r,a,o){return f().wrap(function(l){for(;;)switch(l.prev=l.next){case 0:o?this.callApiWithFiles(r,a,o):this.callAPIWithText(r,a);case 1:case"end":return l.stop()}},n,this)}));function t(n,r,a){return i.apply(this,arguments)}return t}()},{key:"callAPI",value:function(){var i=k(f().mark(function n(r,a){var o,s;return f().wrap(function(u){for(;;)switch(u.prev=u.next){case 0:if(this.requestSettings){u.next=2;break}throw new Error("Request settings have not been set up");case 2:o=Un.processMessages(a.messages,this.maxMessages,this.totalMessagesMaxCharLength),this.requestSettings.websocket?(s=V({messages:o},this.rawBody),lt.sendWebsocket(this,s,a,!1)):this.callServiceAPI(a,o,r.files);case 4:case"end":return u.stop()}},n,this)}));function t(n,r){return i.apply(this,arguments)}return t}()},{key:"extractResultData",value:function(){var i=k(f().mark(function n(r){return f().wrap(function(o){for(;;)switch(o.prev=o.next){case 0:if(!r.error){o.next=2;break}throw r.error;case 2:if(!r.result){o.next=4;break}return o.abrupt("return",Re.handleResponseProperty(r));case 4:if(!B.validateResponseFormat(r)){o.next=6;break}return o.abrupt("return",r);case 6:case"end":return o.stop()}},n)}));function t(n){return i.apply(this,arguments)}return t}()},{key:"isDirectConnection",value:function(){return!1}},{key:"isWebModel",value:function(){return!1}}],[{key:"canSendMessage",value:function(t,n,r){return r?!0:!!(t&&t.trim()!=="")||!!(n&&n.length>0)}},{key:"createCustomFormDataBody",value:function(t,n,r){var a=new FormData;r.forEach(function(l){return a.append("files",l)}),Object.keys(t).forEach(function(l){return a.append(l,String(t[l]))});var o=0;n.slice(0,n.length-1).forEach(function(l){a.append("message".concat(o+=1),JSON.stringify(l))});var s=n[n.length-1];return s.text&&(delete s.files,a.append("message".concat(o+=1),JSON.stringify(s))),a}}]),e}(),ce=function(e){P(i,e);function i(t,n,r,a,o){var s;g(this,i);var l;return s=O(this,i,[t,o]),s.insertKeyPlaceholderText="API Key",s.keyHelpUrl="",Object.assign(s.rawBody,(l=t.request)==null?void 0:l.additionalBodyProps),s.keyVerificationDetails=n,s.buildHeadersFunc=r,a&&s.setApiKeyProperties(a),s.requestSettings=s.buildRequestSettings(s.key||"",t.request),s}return y(i,[{key:"setApiKeyProperties",value:function(n){this.key=n.key,n.validateKeyProperty&&(this.validateConfigKey=n.validateKeyProperty)}},{key:"buildRequestSettings",value:function(n,r){var a,o=r??{};return(a=o.headers)!==null&&a!==void 0||(o.headers={}),Object.assign(o.headers,this.buildHeadersFunc(n)),o}},{key:"keyAuthenticated",value:function(n,r){this.requestSettings=this.buildRequestSettings(r,this.requestSettings),this.key=r,n()}},{key:"verifyKey",value:function(n,r){var a=this.keyVerificationDetails,o=a.url,s=a.method,l=a.handleVerificationResult,u=a.createHeaders,c=a.body,d=(u==null?void 0:u(n))||this.buildHeadersFunc(n);J.verifyKey(n,o,d,s,this.keyAuthenticated.bind(this,r.onSuccess),r.onFail,r.onLoad,l,c)}},{key:"isDirectConnection",value:function(){return!0}}]),i}(At),iu=function(){function e(){g(this,e)}return y(e,null,[{key:"waitForPropertiesToBeUpdatedBeforeRender",value:function(t){t._propUpdated_=!1,setTimeout(function(){t._propUpdated_?e.waitForPropertiesToBeUpdatedBeforeRender(t):(t._waitingToRender_=!1,t.onRender())})}},{key:"attemptRender",value:function(t){t._propUpdated_=!0,t._waitingToRender_||(t._waitingToRender_=!0,e.waitForPropertiesToBeUpdatedBeforeRender(t))}}]),e}(),Hn=function(e){P(i,e);function i(){var t;return g(this,i),t=O(this,i),t._waitingToRender_=!1,t._propUpdated_=!1,Object.keys(i._attributeToProperty_).forEach(function(n){var r=i._attributeToProperty_[n];t.constructPropertyAccessors(r),t.hasOwnProperty(n)||t.constructPropertyAccessors(r,n)}),t}return y(i,[{key:"constructPropertyAccessors",value:function(n,r){var a;Object.defineProperty(this,r||n,{get:function(){return a},set:function(s){a=s,r?this[n]=s:iu.attemptRender(this)}})}},{key:"attributeChangedCallback",value:function(n,r,a){if(r!==a){var o=i._attributes_[n](a),s=i._attributeToProperty_[n];this[s]=o}}},{key:"onRender",value:function(){}}],[{key:"observedAttributes",get:function(){return Object.keys(i._attributes_)||[]}}]),i}(wn(HTMLElement));Hn._attributes_={};Hn._attributeToProperty_={};var au=Hn,ou=`<?xml version="1.0" standalone="no"?>
<svg version="1.1"
	xmlns:sodipodi="http://sodipodi.sourceforge.net/DTD/sodipodi-0.dtd" xmlns:inkscape="http://www.inkscape.org/namespaces/inkscape"
	xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink" width="0.9em" height="0.9em"
	viewBox="0 0 1200 1200" enable-background="new 0 0 1200 1200">
		<path d="
			M669.727,273.516c-22.891-2.476-46.15-3.895-69.727-4.248c-103.025,0.457-209.823,25.517-310.913,73.536
			c-75.058,37.122-148.173,89.529-211.67,154.174C46.232,529.978,6.431,577.76,0,628.74c0.76,44.162,48.153,98.67,77.417,131.764
			c59.543,62.106,130.754,113.013,211.67,154.174c2.75,1.335,5.51,2.654,8.276,3.955l-75.072,131.102l102.005,60.286l551.416-960.033
			l-98.186-60.008L669.727,273.516z M902.563,338.995l-74.927,129.857c34.47,44.782,54.932,100.006,54.932,159.888
			c0,149.257-126.522,270.264-282.642,270.264c-6.749,0-13.29-0.728-19.922-1.172l-49.585,85.84c22.868,2.449,45.99,4.233,69.58,4.541
			c103.123-0.463,209.861-25.812,310.84-73.535c75.058-37.122,148.246-89.529,211.743-154.174
			c31.186-32.999,70.985-80.782,77.417-131.764c-0.76-44.161-48.153-98.669-77.417-131.763
			c-59.543-62.106-130.827-113.013-211.743-154.175C908.108,341.478,905.312,340.287,902.563,338.995L902.563,338.995z
			M599.927,358.478c6.846,0,13.638,0.274,20.361,0.732l-58.081,100.561c-81.514,16.526-142.676,85.88-142.676,168.897
			c0,20.854,3.841,40.819,10.913,59.325c0.008,0.021-0.008,0.053,0,0.074l-58.228,100.854
			c-34.551-44.823-54.932-100.229-54.932-160.182C317.285,479.484,443.808,358.477,599.927,358.478L599.927,358.478z M768.896,570.513
			L638.013,797.271c81.076-16.837,141.797-85.875,141.797-168.603C779.81,608.194,775.724,588.729,768.896,570.513L768.896,570.513z"
			/>
</svg>
`,su=`<?xml version="1.0" standalone="no"?>
<svg version="1.1"
	xmlns:sodipodi="http://sodipodi.sourceforge.net/DTD/sodipodi-0.dtd" xmlns:inkscape="http://www.inkscape.org/namespaces/inkscape"
	xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink" width="0.9em" height="0.9em"
	viewBox="0 0 1200 1200" enable-background="new 0 0 1200 1200">
		<path id="path6686" inkscape:connector-curvature="0" d="M779.843,599.925c0,95.331-80.664,172.612-180.169,172.612
			c-99.504,0-180.168-77.281-180.168-172.612c0-95.332,80.664-172.612,180.168-172.612
			C699.179,427.312,779.843,504.594,779.843,599.925z M600,240.521c-103.025,0.457-209.814,25.538-310.904,73.557
			c-75.058,37.122-148.206,89.496-211.702,154.141C46.208,501.218,6.431,549,0,599.981c0.76,44.161,48.13,98.669,77.394,131.763
			c59.543,62.106,130.786,113.018,211.702,154.179c94.271,45.751,198.616,72.092,310.904,73.557
			c103.123-0.464,209.888-25.834,310.866-73.557c75.058-37.122,148.243-89.534,211.74-154.179
			c31.185-32.999,70.962-80.782,77.394-131.763c-0.76-44.161-48.13-98.671-77.394-131.764
			c-59.543-62.106-130.824-112.979-211.74-154.141C816.644,268.36,712.042,242.2,600,240.521z M599.924,329.769
			c156.119,0,282.675,120.994,282.675,270.251c0,149.256-126.556,270.25-282.675,270.25S317.249,749.275,317.249,600.02
			C317.249,450.763,443.805,329.769,599.924,329.769L599.924,329.769z"/>
</svg>
`,pe=function(){function e(){g(this,e)}return y(e,null,[{key:"createSVGElement",value:function(t){return new DOMParser().parseFromString(t,"image/svg+xml").documentElement}}]),e}(),ji=function(){function e(){g(this,e)}return y(e,null,[{key:"changeVisibility",value:function(t,n,r,a){a.target.id===e.VISIBLE_ICON_ID?(n.style.display="none",r.style.display="block",t.type="password"):(n.style.display="block",r.style.display="none",t.type="text")}},{key:"createIconElement",value:function(t,n){var r=pe.createSVGElement(t);return r.id=n,r.classList.add("visibility-icon"),r}},{key:"create",value:function(t){var n=document.createElement("div");n.id="visibility-icon-container";var r=e.createIconElement(su,e.VISIBLE_ICON_ID);r.style.display="none",n.appendChild(r);var a=e.createIconElement(ou,"not-visible-icon");return n.appendChild(a),n.onclick=e.changeVisibility.bind(this,t,r,a),n}}]),e}();ji.VISIBLE_ICON_ID="visible-icon";var lu=ji,uu=function(){function e(){g(this,e)}return y(e,null,[{key:"createCautionText",value:function(){var t=document.createElement("a");return t.classList.add("insert-key-input-help-text"),t.innerText="Please exercise CAUTION when inserting your API key outside of deepchat.dev or localhost!!",t}},{key:"createHelpLink",value:function(t){var n=document.createElement("a");return n.classList.add("insert-key-input-help-text"),n.href=t,n.innerText="Find more info here",n.target="_blank",n}},{key:"createFailText",value:function(){var t=document.createElement("div");return t.id="insert-key-input-invalid-text",t.style.display="none",t}},{key:"createHelpTextContainer",value:function(t){var n=arguments.length>1&&arguments[1]!==void 0?arguments[1]:!0,r=document.createElement("div");r.id="insert-key-help-text-container";var a=document.createElement("div");a.id="insert-key-help-text-contents";var o=e.createFailText();if(a.appendChild(o),t){var s=e.createHelpLink(t);a.appendChild(s)}if(n===!0){var l=e.createCautionText();a.appendChild(l)}return r.appendChild(a),{helpTextContainerElement:r,failTextElement:o}}},{key:"onFail",value:function(t,n,r,a){t.classList.replace("insert-key-input-valid","insert-key-input-invalid"),r.innerText=a,r.style.display="block",n.innerText="Start",t.classList.remove("loading")}},{key:"onLoad",value:function(t,n){t.classList.add("loading"),n.innerHTML='<div id="loading-ring"></div>'}},{key:"verifyKey",value:function(t,n,r){var a=t.value.trim();r.verifyKey(a,n)}},{key:"addVerificationEvents",value:function(t,n,r,a,o){var s={onSuccess:a,onFail:e.onFail.bind(this,t,n,r),onLoad:e.onLoad.bind(this,t,n)},l=e.verifyKey.bind(this,t,s,o);n.onclick=l,t.onkeydown=function(u){!t.classList.contains("loading")&&u.key===ne.ENTER&&l()}}},{key:"createStartButton",value:function(){var t=document.createElement("div");return t.id="start-button",t.innerText="Start",t}},{key:"onInputFocus",value:function(t){t.target.classList.replace("insert-key-input-invalid","insert-key-input-valid")}},{key:"createInput",value:function(t){var n=document.createElement("div");n.id="insert-key-input-container";var r=document.createElement("input");return r.id="insert-key-input",r.placeholder=t||"API Key",r.type="password",r.classList.add("insert-key-input-valid"),r.onfocus=e.onInputFocus,n.appendChild(r),n}},{key:"createContents",value:function(t,n){var r,a=document.createElement("div");a.id="insert-key-contents";var o=e.createInput(n.insertKeyPlaceholderText),s=o.children[0],l=lu.create(s);o.appendChild(l),a.appendChild(o);var u=e.createStartButton(),c=e.createHelpTextContainer(n.keyHelpUrl,(r=n.deepChat._insertKeyViewStyles)==null?void 0:r.displayCautionText),d=c.helpTextContainerElement,h=c.failTextElement;return a.appendChild(u),a.appendChild(d),e.addVerificationEvents(s,u,h,t,n),a}},{key:"createElements",value:function(t,n){var r=document.createElement("div");r.id="insert-key-view";var a=e.createContents(t,n);return r.appendChild(a),r}},{key:"render",value:function(t,n,r){var a=e.createElements(n,r);t.replaceChildren(a)}}]),e}(),ut=function(){function e(){g(this,e)}return y(e,null,[{key:"enableButtons",value:function(t,n){var r=arguments.length>2&&arguments[2]!==void 0?arguments[2]:0;window.webLLM?(t&&(t.disabled=!1),n&&(n.disabled=!1)):r<Vn.MODULE_SEARCH_LIMIT_S*4&&setTimeout(function(){return e.enableButtons(t,n,r+1)},250)}},{key:"setUpInitial",value:function(t,n,r,a){var o=(n==null?void 0:n.downloadClass)||e.DOWNLOAD_BUTTON_CLASS,s=(n==null?void 0:n.uploadClass)||e.UPLOAD_BUTTON_CLASS,l=(n==null?void 0:n.fileInputClass)||e.FILE_INPUT_CLASS;return setTimeout(function(){var u=r==null?void 0:r.getElementsByClassName(o)[0],c=r==null?void 0:r.getElementsByClassName(l)[0],d=r==null?void 0:r.getElementsByClassName(s)[0];u&&(u.onclick=function(){return t()}),c&&(c.onchange=function(){c.files&&c.files.length>0&&t(c.files)}),d&&(d.onclick=function(){return c.click()}),(u||d)&&e.enableButtons(u,d)}),(n==null?void 0:n.initialHtml)||`<div>
        Download or upload a web model that will run entirely on your browser: <br/> 
        <button disabled class="`.concat(o,` deep-chat-button deep-chat-web-model-button">Download</button>
        `).concat(a?"":'<input type="file" class="'.concat(l,`" hidden multiple />
          <button disabled class="`).concat(s,' deep-chat-button deep-chat-web-model-button">Upload</button>'),`
      </div>`)}},{key:"exportFile",value:function(t){for(var n=document.createElement("a"),r=4,a=function(l){setTimeout(function(){for(var u=l*r,c=u;c<Math.min(u+r,t.length);c+=1){var d=URL.createObjectURL(t[c]);n.href=d,n.download=t[c].name,document.body.appendChild(n),n.click(),URL.revokeObjectURL(d)}},500*l)},o=0;o<t.length/r;o+=1)a(o)}},{key:"setUpAfterLoad",value:function(t,n,r,a){var o=(n==null?void 0:n.exportFilesClass)||e.EXPORT_BUTTON_CLASS;return setTimeout(function(){var s=r==null?void 0:r.getElementsByClassName(o)[0];s&&(s.onclick=function(){return e.exportFile(t)})}),(n==null?void 0:n.afterLoadHtml)||`<div>
        Model loaded successfully and has been cached for future requests.
        `.concat(a?"":'<br/> <button style="margin-top: 5px" class="'.concat(o,' deep-chat-button">Export</button>'),`
      </div>`)}}]),e}();ut.DOWNLOAD_BUTTON_CLASS="deep-chat-download-button";ut.UPLOAD_BUTTON_CLASS="deep-chat-upload-button";ut.FILE_INPUT_CLASS="deep-chat-file-input";ut.EXPORT_BUTTON_CLASS="deep-chat-export-button";var Cr=ut,Mr={model_list:[{model_url:"https://huggingface.co/mlc-ai/Llama-2-7b-chat-hf-q4f32_1-MLC/resolve/main/",local_id:"Llama-2-7b-chat-hf-q4f32_1",model_lib_url:"https://raw.githubusercontent.com/mlc-ai/binary-mlc-llm-libs/main/Llama-2-7b-chat-hf/Llama-2-7b-chat-hf-q4f32_1-ctx4k_cs1k-webgpu.wasm",vram_required_MB:9109.03,low_resource_required:!1},{model_url:"https://huggingface.co/mlc-ai/Llama-2-7b-chat-hf-q4f16_1-MLC/resolve/main/",local_id:"Llama-2-7b-chat-hf-q4f16_1",model_lib_url:"https://raw.githubusercontent.com/mlc-ai/binary-mlc-llm-libs/main/Llama-2-7b-chat-hf/Llama-2-7b-chat-hf-q4f16_1-ctx4k_cs1k-webgpu.wasm",vram_required_MB:6749.02,low_resource_required:!1,required_features:["shader-f16"]},{model_url:"https://huggingface.co/mlc-ai/Llama-2-7b-chat-hf-q4f16_1-MLC/resolve/main/",local_id:"Llama-2-7b-chat-hf-q4f16_1-1k",model_lib_url:"https://raw.githubusercontent.com/mlc-ai/binary-mlc-llm-libs/main/Llama-2-7b-chat-hf/Llama-2-7b-chat-hf-q4f16_1-ctx1k-webgpu.wasm",vram_required_MB:4618.52,low_resource_required:!1,required_features:["shader-f16"]},{model_url:"https://huggingface.co/mlc-ai/Llama-2-13b-chat-hf-q4f16_1-MLC/resolve/main/",local_id:"Llama-2-13b-chat-hf-q4f16_1",model_lib_url:"https://raw.githubusercontent.com/mlc-ai/binary-mlc-llm-libs/main/Llama-2-13b-chat-hf/Llama-2-13b-chat-hf-q4f16_1-ctx4k_cs1k-webgpu.wasm",vram_required_MB:11814.09,low_resource_required:!1,required_features:["shader-f16"]},{model_url:"https://huggingface.co/mlc-ai/Llama-2-70b-chat-hf-q4f16_1-MLC/resolve/main/",local_id:"Llama-2-70b-chat-hf-q4f16_1",model_lib_url:"https://raw.githubusercontent.com/mlc-ai/binary-mlc-llm-libs/main/Llama-2-70b-chat-hf/Llama-2-70b-chat-hf-q4f16_1-ctx4k_cs1k-webgpu.wasm",vram_required_MB:43729.05,low_resource_required:!1,required_features:["shader-f16"]},{model_url:"https://huggingface.co/mlc-ai/RedPajama-INCITE-Chat-3B-v1-q4f16_1-MLC/resolve/main/",local_id:"RedPajama-INCITE-Chat-3B-v1-q4f16_1",model_lib_url:"https://raw.githubusercontent.com/mlc-ai/binary-mlc-llm-libs/main/RedPajama-INCITE-Chat-3B-v1/RedPajama-INCITE-Chat-3B-v1-q4f16_1-ctx2k-webgpu.wasm",vram_required_MB:2972.09,low_resource_required:!1,required_features:["shader-f16"]},{model_url:"https://huggingface.co/mlc-ai/RedPajama-INCITE-Chat-3B-v1-q4f32_1-MLC/resolve/main/",local_id:"RedPajama-INCITE-Chat-3B-v1-q4f32_1",model_lib_url:"https://raw.githubusercontent.com/mlc-ai/binary-mlc-llm-libs/main/RedPajama-INCITE-Chat-3B-v1/RedPajama-INCITE-Chat-3B-v1-q4f32_1-ctx2k-webgpu.wasm",vram_required_MB:3928.09,low_resource_required:!1},{model_url:"https://huggingface.co/mlc-ai/RedPajama-INCITE-Chat-3B-v1-q4f16_1-MLC/resolve/main/",local_id:"RedPajama-INCITE-Chat-3B-v1-q4f16_1-1k",model_lib_url:"https://raw.githubusercontent.com/mlc-ai/binary-mlc-llm-libs/main/RedPajama-INCITE-Chat-3B-v1/RedPajama-INCITE-Chat-3B-v1-q4f16_1-ctx1k-webgpu.wasm",vram_required_MB:2041.09,low_resource_required:!0,required_features:["shader-f16"]},{model_url:"https://huggingface.co/mlc-ai/RedPajama-INCITE-Chat-3B-v1-q4f32_1-MLC/resolve/main/",local_id:"RedPajama-INCITE-Chat-3B-v1-q4f32_1-1k",model_lib_url:"https://raw.githubusercontent.com/mlc-ai/binary-mlc-llm-libs/main/RedPajama-INCITE-Chat-3B-v1/RedPajama-INCITE-Chat-3B-v1-q4f32_1-ctx1k-webgpu.wasm",vram_required_MB:2558.09,low_resource_required:!0},{model_url:"https://huggingface.co/mlc-ai/WizardMath-7B-V1.1-q4f16_1-MLC/resolve/main/",local_id:"WizardMath-7B-V1.1-q4f16_1",model_lib_url:"https://raw.githubusercontent.com/mlc-ai/binary-mlc-llm-libs/main/Mistral-7B-Instruct-v0.2/Mistral-7B-Instruct-v0.2-q4f16_1-sw4k_cs1k-webgpu.wasm",vram_required_MB:6079.02,low_resource_required:!1,required_features:["shader-f16"]},{model_url:"https://huggingface.co/mlc-ai/Mistral-7B-Instruct-v0.2-q4f16_1-MLC/resolve/main/",local_id:"Mistral-7B-Instruct-v0.2-q4f16_1",model_lib_url:"https://raw.githubusercontent.com/mlc-ai/binary-mlc-llm-libs/main/Mistral-7B-Instruct-v0.2/Mistral-7B-Instruct-v0.2-q4f16_1-sw4k_cs1k-webgpu.wasm",vram_required_MB:6079.02,low_resource_required:!1,required_features:["shader-f16"]},{model_url:"https://huggingface.co/mlc-ai/OpenHermes-2.5-Mistral-7B-q4f16_1-MLC/resolve/main/",local_id:"OpenHermes-2.5-Mistral-7B-q4f16_1",model_lib_url:"https://raw.githubusercontent.com/mlc-ai/binary-mlc-llm-libs/main/Mistral-7B-Instruct-v0.2/Mistral-7B-Instruct-v0.2-q4f16_1-sw4k_cs1k-webgpu.wasm",vram_required_MB:6079.02,low_resource_required:!1,required_features:["shader-f16"]},{model_url:"https://huggingface.co/mlc-ai/NeuralHermes-2.5-Mistral-7B-q4f16_1-MLC/resolve/main/",local_id:"NeuralHermes-2.5-Mistral-7B-q4f16_1",model_lib_url:"https://raw.githubusercontent.com/mlc-ai/binary-mlc-llm-libs/main/Mistral-7B-Instruct-v0.2/Mistral-7B-Instruct-v0.2-q4f16_1-sw4k_cs1k-webgpu.wasm",vram_required_MB:6079.02,low_resource_required:!1,required_features:["shader-f16"]},{model_url:"https://huggingface.co/mlc-ai/TinyLlama-1.1B-Chat-v0.4-q0f16-MLC/resolve/main/",local_id:"TinyLlama-1.1B-Chat-v0.4-q0f16",model_lib_url:"https://raw.githubusercontent.com/mlc-ai/binary-mlc-llm-libs/main/TinyLlama-1.1B-Chat-v0.4/TinyLlama-1.1B-Chat-v0.4-q0f16-ctx2k-webgpu.wasm",vram_required_MB:5063.52,low_resource_required:!1,required_features:["shader-f16"]},{model_url:"https://huggingface.co/mlc-ai/TinyLlama-1.1B-Chat-v0.4-q0f32-MLC/resolve/main/",local_id:"TinyLlama-1.1B-Chat-v0.4-q0f32",model_lib_url:"https://raw.githubusercontent.com/mlc-ai/binary-mlc-llm-libs/main/TinyLlama-1.1B-Chat-v0.4/TinyLlama-1.1B-Chat-v0.4-q0f32-ctx2k-webgpu.wasm",vram_required_MB:5394.53,low_resource_required:!1},{model_url:"https://huggingface.co/mlc-ai/TinyLlama-1.1B-Chat-v0.4-q4f16_1-MLC/resolve/main/",local_id:"TinyLlama-1.1B-Chat-v0.4-q4f16_1-1k",model_lib_url:"https://raw.githubusercontent.com/mlc-ai/binary-mlc-llm-libs/main/TinyLlama-1.1B-Chat-v0.4/TinyLlama-1.1B-Chat-v0.4-q4f16_1-ctx1k-webgpu.wasm",vram_required_MB:899.11,low_resource_required:!0,required_features:["shader-f16"]},{model_url:"https://huggingface.co/mlc-ai/TinyLlama-1.1B-Chat-v0.4-q4f32_1-MLC/resolve/main/",local_id:"TinyLlama-1.1B-Chat-v0.4-q4f32_1-1k",model_lib_url:"https://raw.githubusercontent.com/mlc-ai/binary-mlc-llm-libs/main/TinyLlama-1.1B-Chat-v0.4/TinyLlama-1.1B-Chat-v0.4-q4f32_1-ctx1k-webgpu.wasm",vram_required_MB:992.11,low_resource_required:!0}],use_web_worker:!0},Je=function(e){P(i,e);function i(t){var n;g(this,i);var r,a;return n=O(this,i,[t]),n._isModelLoaded=!1,n._isModelLoading=!1,n._loadOnFirstMessage=!1,n._webModel={},n.permittedErrorPrefixes=[i.MULTIPLE_MODELS_ERROR,i.WEB_LLM_NOT_FOUND_ERROR,i.GENERIC_ERROR],n._conversationHistory=[],R(t.webModel)=="object"&&(n._webModel=t.webModel),(r=n._webModel.load)!=null&&r.clearCache&&i.clearAllCache(),n.findModelInWindow(t),n.canSendMessage=n.canSubmit.bind(de(n)),n._chatEl=(a=t.shadowRoot)==null?void 0:a.children[0],t.initialMessages&&i.setUpHistory(n._conversationHistory,t.initialMessages),n}return y(i,[{key:"setUpMessages",value:function(n){var r=this;this._messages=n,this._removeIntro=function(){n.removeIntroductoryMessage(),r._removeIntro=void 0}}},{key:"findModelInWindow",value:function(n){var r=this,a=arguments.length>1&&arguments[1]!==void 0?arguments[1]:0,o;window.webLLM?this.configureInit(this.shouldAddInitialMessage(n.introMessage)):a>i.MODULE_SEARCH_LIMIT_S?((o=this._messages)==null||o.addNewErrorMessage("service",i.WEB_LLM_NOT_FOUND_ERROR),console.error("The deep-chat-web-llm module has not been attached to the window object. Please see the following guide:"),console.error("https://deepchat.dev/examples/externalModules")):setTimeout(function(){return r.findModelInWindow(n,a+1)},1e3)}},{key:"shouldAddInitialMessage",value:function(n){var r;return!n&&this._webModel&&((r=this._webModel.introMessage)==null?void 0:r.displayed)!==!1}},{key:"scrollToTop",value:function(n){var r=this,a;((a=this._webModel.introMessage)==null?void 0:a.autoScroll)!==!1&&setTimeout(function(){var o,s;(o=r._messages)!=null&&o.elementRef&&he.scrollToTop((s=r._messages)==null?void 0:s.elementRef)},n)}},{key:"getIntroMessage",value:function(n){if(!(!this.shouldAddInitialMessage(n)||!this._chatEl)){var r=Cr.setUpInitial(this.init.bind(this),this._webModel.introMessage,this._chatEl,!!this._webModel.worker);return this.scrollToTop(1),{role:F.AI_ROLE,html:r,sendUpdate:!1}}}},{key:"configureInit",value:function(){var t=k(f().mark(function r(a){var o;return f().wrap(function(l){for(;;)switch(l.prev=l.next){case 0:if(o=this._webModel.load,!o){l.next=8;break}if(!o.onInit){l.next=5;break}return this.init(),l.abrupt("return");case 5:if(!o.onMessage){l.next=8;break}return this._loadOnFirstMessage=!0,l.abrupt("return");case 8:a||this.init();case 9:case"end":return l.stop()}},r,this)}));function n(r){return t.apply(this,arguments)}return n}()},{key:"init",value:function(){var t=k(f().mark(function r(a){var o,s;return f().wrap(function(u){for(;;)switch(u.prev=u.next){case 0:if((o=this._messages)==null||o.removeError(),s=this.attemptToCreateChat(),u.t0=s,!u.t0){u.next=6;break}return u.next=6,this.loadModel(s,a);case 6:case"end":return u.stop()}},r,this)}));function n(r){return t.apply(this,arguments)}return n}()},{key:"attemptToCreateChat",value:function(){var n;if(i.chat){(n=this._messages)==null||n.addNewErrorMessage("service",i.MULTIPLE_MODELS_ERROR),console.error(i.MULTIPLE_MODELS_ERROR);return}if(!(this._isModelLoaded||this._isModelLoading)){var r=this._webModel.worker;return Mr.use_web_worker&&r?new window.webLLM.ChatWorkerClient(r):new window.webLLM.ChatModule}}},{key:"getConfig",value:function(){var n,r=i.DEFAULT_MODEL;this._webModel.model&&(r=this._webModel.model);var a=JSON.parse(JSON.stringify(Mr));if(this._webModel.urls){var o=a.model_list.find(function(s){return s.local_id=r});o&&(this._webModel.urls.model&&(o.model_url=this._webModel.urls.model),this._webModel.urls.wasm&&(o.model_lib_url=this._webModel.urls.wasm))}return(n=this._webModel.load)!=null&&n.skipCache&&(a.use_cache=!1),{model:r,appConfig:a}}},{key:"loadModel",value:function(){var t=k(f().mark(function r(a,o){var s=this,l,u,c,d,h,p,v,m,b,w,_,x,N,M,j;return f().wrap(function(H){for(;;)switch(H.prev=H.next){case 0:return this.scrollToTop(),i.chat=a,this._isModelLoading=!0,m=((l=this._webModel.introMessage)==null?void 0:l.displayed)===!1,b=function(te){var X;(X=s._messages)==null||X.addNewMessage({html:"<div>".concat(te.text,"</div>"),overwrite:!0,sendUpdate:!1}),m&&(setTimeout(function(){var $;return he.scrollToBottom(($=s._messages)==null?void 0:$.elementRef)}),m=!1)},i.chat.setInitProgressCallback(b),H.prev=4,_=this.getConfig(),x=_.model,N=_.appConfig,M={},this._webModel.instruction&&(M.conv_config={system:this._webModel.instruction}),this._conversationHistory.length>0&&(M.conversation_history=this._conversationHistory),H.next=10,i.chat.reload(x,M,N,o);case 10:w=H.sent,H.next=16;break;case 13:return H.prev=13,H.t0=H.catch(4),H.abrupt("return",this.unloadChat(H.t0));case 16:(c=(u=this.deepChat)._validationHandler)==null||c.call(u),(d=this._webModel.introMessage)!=null&&d.removeAfterLoad?this._webModel.introMessage.displayed===!1?(p=this._messages)==null||p.removeLastMessage():(v=this._removeIntro)==null||v.call(this):(j=Cr.setUpAfterLoad(w,this._webModel.introMessage,this._chatEl,!!this._webModel.worker),(h=this._messages)==null||h.addNewMessage({html:j,overwrite:!0,sendUpdate:!1})),this._isModelLoaded=!0,this._isModelLoading=!1;case 18:case"end":return H.stop()}},r,this,[[4,13]])}));function n(r,a){return t.apply(this,arguments)}return n}()},{key:"unloadChat",value:function(){var t=k(f().mark(function r(a){var o;return f().wrap(function(l){for(;;)switch(l.prev=l.next){case 0:if((o=this._messages)==null||o.addNewErrorMessage("service",i.GENERIC_ERROR),console.error(a),this._isModelLoaded=!1,this._isModelLoading=!1,l.t0=i.chat,!l.t0){l.next=9;break}return l.next=8,i.chat.unload();case 8:i.chat=void 0;case 9:case"end":return l.stop()}},r,this)}));function n(r){return t.apply(this,arguments)}return n}()},{key:"immediateResp",value:function(){var t=k(f().mark(function r(a,o,s){var l,u;return f().wrap(function(d){for(;;)switch(d.prev=d.next){case 0:return d.next=2,s.generate(o,void 0,0);case 2:return d.t0=d.sent,l={text:d.t0},d.next=6,i.processResponse(this.deepChat,a,l);case 6:u=d.sent,u&&a.addNewMessage(u),this.completionsHandlers.onFinish();case 8:case"end":return d.stop()}},r,this)}));function n(r,a,o){return t.apply(this,arguments)}return n}()},{key:"streamResp",value:function(){var t=k(f().mark(function r(a,o,s){var l=this,u;return f().wrap(function(d){for(;;)switch(d.prev=d.next){case 0:return this.streamHandlers.abortStream.abort=function(){s.interruptGenerate()},this.streamHandlers.onOpen(),u=new Pe(a),d.next=4,s.generate(o,function(){var h=k(f().mark(function p(v,m){var b;return f().wrap(function(_){for(;;)switch(_.prev=_.next){case 0:return _.next=2,i.processResponse(l.deepChat,a,{text:m});case 2:b=_.sent,b&&u.upsertStreamedMessage({text:b.text,overwrite:!0});case 4:case"end":return _.stop()}},p)}));return function(p,v){return h.apply(this,arguments)}}());case 4:u.finaliseStreamedMessage(),this.streamHandlers.onClose();case 6:case"end":return d.stop()}},r,this)}));function n(r,a,o){return t.apply(this,arguments)}return n}()},{key:"generateRespByType",value:function(){var t=k(f().mark(function r(a,o,s,l){var u;return f().wrap(function(d){for(;;)switch(d.prev=d.next){case 0:if(d.prev=0,!s){d.next=6;break}return d.next=4,this.streamResp(a,o,l);case 4:d.next=8;break;case 6:return d.next=8,this.immediateResp(a,o,l);case 8:d.next=13;break;case 10:d.prev=10,d.t0=d.catch(0),(u=this._messages)==null||u.addNewErrorMessage("service"),console.log(d.t0);case 13:case"end":return d.stop()}},r,this,[[0,10]])}));function n(r,a,o,s){return t.apply(this,arguments)}return n}()},{key:"generateResp",value:function(){var t=k(f().mark(function r(a,o,s){var l,u,c,d,h,p,v;return f().wrap(function(b){for(;;)switch(b.prev=b.next){case 0:return l=o[o.length-1].text,b.next=3,B.processRequestInterceptor(this.deepChat,{body:{text:l}});case 3:u=b.sent,c=u.body,d=u.error,h=!!this.deepChat.stream;try{d?(B.displayError(a,new Error(d)),(h?this.streamHandlers.onClose:this.completionsHandlers.onFinish)()):!c||!c.text?(p=ee.INVALID_MODEL_REQUEST({body:c},!1),console.error(p),v=h?this.streamHandlers.onClose:this.completionsHandlers.onFinish,B.onInterceptorError(a,p,v)):this.generateRespByType(a,c.text,!!this.deepChat.stream,s)}catch(w){this.unloadChat(w)}case 8:case"end":return b.stop()}},r,this)}));function n(r,a,o){return t.apply(this,arguments)}return n}()},{key:"callServiceAPI",value:function(){var t=k(f().mark(function r(a,o){var s,l;return f().wrap(function(c){for(;;)switch(c.prev=c.next){case 0:if(this._isModelLoaded){c.next=7;break}if(!this._loadOnFirstMessage){c.next=6;break}return c.next=4,this.init();case 4:c.next=7;break;case 6:return c.abrupt("return");case 7:!i.chat||this._isModelLoading||((s=this._webModel.introMessage)!=null&&s.removeAfterMessage&&((l=this._removeIntro)==null||l.call(this)),a.addLoadingMessage(),this.generateResp(a,o,i.chat));case 8:case"end":return c.stop()}},r,this)}));function n(r,a){return t.apply(this,arguments)}return n}()},{key:"canSubmit",value:function(n){return!(n!=null&&n.trim())||this._isModelLoading?!1:this._loadOnFirstMessage?!0:!!this._isModelLoaded}},{key:"isWebModel",value:function(){return!0}}],[{key:"setUpHistory",value:function(n,r){r.forEach(function(a,o){if(a.role===F.USER_ROLE&&a.text){var s=r[o+1];s!=null&&s.text&&s.role!==F.USER_ROLE&&n.push([a.text,s.text])}})}},{key:"processResponse",value:function(){var t=k(f().mark(function r(a,o,s){var l,u,c;return f().wrap(function(h){for(;;)switch(h.prev=h.next){case 0:return h.next=2,(l=a.responseInterceptor)==null?void 0:l.call(a,s);case 2:if(h.t0=h.sent,h.t0){h.next=5;break}h.t0=s;case 5:if(u=h.t0,!u.error){h.next=11;break}return B.displayError(o,new Error(u.error)),h.abrupt("return");case 11:if(!(!u||!u.text)){h.next=15;break}return c=ee.INVALID_MODEL_RESPONSE(s,!!a.responseInterceptor,u),B.displayError(o,new Error(c)),h.abrupt("return");case 15:return h.abrupt("return",u);case 16:case"end":return h.stop()}},r)}));function n(r,a,o){return t.apply(this,arguments)}return n}()},{key:"clearAllCache",value:function(){i.clearCache("webllm/model"),i.clearCache("webllm/wasm")}},{key:"clearCache",value:function(n){caches.open(n).then(function(r){r.keys().then(function(a){a.forEach(function(o){r.delete(o)})})})}}]),i}(At);Je.GENERIC_ERROR="Error, please check the [troubleshooting](https://deepchat.dev/docs/webModel#troubleshooting) section of documentation for help.";Je.MULTIPLE_MODELS_ERROR="Cannot run multiple web models";Je.WEB_LLM_NOT_FOUND_ERROR="WebLLM module not found";Je.DEFAULT_MODEL="Llama-2-7b-chat-hf-q4f32_1";Je.MODULE_SEARCH_LIMIT_S=5;var Vn=Je,Ar=function(){function e(){g(this,e)}return y(e,null,[{key:"buildHeaders",value:function(t){return{Authorization:"Bearer ".concat(t),"Content-Type":"application/json"}}},{key:"handleVerificationResult",value:function(t,n,r,a){var o=t;Array.isArray(o.error)&&o.error[0]==="Error in `parameters`: field required"?r(n):a(ee.INVALID_KEY)}},{key:"buildKeyVerificationDetails",value:function(){return{url:"https://api-inference.huggingface.co/models/gpt2",method:"POST",handleVerificationResult:e.handleVerificationResult}}}]),e}(),Bi=function(e){P(i,e);function i(t,n,r,a,o,s){var l;return g(this,i),l=O(this,i,[t,Ar.buildKeyVerificationDetails(),Ar.buildHeaders,o,s]),l.insertKeyPlaceholderText="Hugging Face Token",l.keyHelpUrl="https://huggingface.co/settings/tokens",l.introPanelMarkUp=`
    <div style="width: 100%; text-align: center; margin-left: -10px"><b>Hugging Face</b></div>
    <p>First message may take an extented amount of time to complete as the model needs to be initialized.</p>`,l.permittedErrorPrefixes=["Authorization header"],l.url="".concat(i.URL_PREFIX).concat(r),l.textInputPlaceholderText=n,R(a)=="object"&&(a.model&&(l.url="".concat(i.URL_PREFIX).concat(a.model)),a.options&&(l.rawBody.options=a.options),a.parameters&&(l.rawBody.parameters=a.parameters)),l}return y(i,[{key:"preprocessBody",value:function(n,r,a){var o,s=JSON.parse(JSON.stringify(n)),l=r[r.length-1].text;if(l)return(o=s.options)!==null&&o!==void 0||(s.options={}),s.options.wait_for_model=!0,V({inputs:l},s)}},{key:"callServiceAPI",value:function(){var t=k(f().mark(function r(a,o,s){var l;return f().wrap(function(c){for(;;)switch(c.prev=c.next){case 0:if(this.requestSettings){c.next=2;break}throw new Error("Request settings have not been set up");case 2:l=this.preprocessBody(this.rawBody,o,s),J.request(this,l,a);case 4:case"end":return c.stop()}},r,this)}));function n(r,a,o){return t.apply(this,arguments)}return n}()}]),i}(ce);Bi.URL_PREFIX="https://api-inference.huggingface.co/models/";var Ue=Bi,$n=function(e){P(i,e);function i(t,n,r,a,o,s){var l;return g(this,i),l=O(this,i,[t,n,r,a,o,s]),l.isTextInputDisabled=!0,l.canSendMessage=i.canSendFile,l}return y(i,[{key:"preprocessBody",value:function(n,r,a){return a[0]}},{key:"callServiceAPI",value:function(){var t=k(f().mark(function r(a,o,s){return f().wrap(function(u){for(;;)switch(u.prev=u.next){case 0:if(this.requestSettings){u.next=2;break}throw new Error("Request settings have not been set up");case 2:if(s!=null&&s[0]){u.next=4;break}throw new Error("No file was added");case 4:J.poll(this,s[0],a,!1);case 5:case"end":return u.stop()}},r,this)}));function n(r,a,o){return t.apply(this,arguments)}return n}()}],[{key:"canSendFile",value:function(n,r){return!!(r!=null&&r[0])}}]),i}(Ue),cu=function(e){P(i,e);function i(t){g(this,i);var n,r,a,o=(r=(n=t.directConnection)==null?void 0:n.huggingFace)==null?void 0:r.audioClassification,s=(a=t.directConnection)==null?void 0:a.huggingFace;return O(this,i,[t,"Attach an audio file","ehcalabres/wav2vec2-lg-xlsr-en-speech-emotion-recognition",o,s,{audio:{}}])}return y(i,[{key:"extractPollResultData",value:function(){var t=k(f().mark(function r(a){var o;return f().wrap(function(l){for(;;)switch(l.prev=l.next){case 0:if(!a.estimated_time){l.next=2;break}return l.abrupt("return",{timeoutMS:(a.estimated_time+1)*1e3});case 2:if(!a.error){l.next=4;break}throw a.error;case 4:return l.abrupt("return",{text:((o=a[0])==null?void 0:o.label)||""});case 5:case"end":return l.stop()}},r)}));function n(r){return t.apply(this,arguments)}return n}()}]),i}($n),du=function(e){P(i,e);function i(t){g(this,i);var n,r,a,o=(r=(n=t.directConnection)==null?void 0:n.huggingFace)==null?void 0:r.imageClassification,s=(a=t.directConnection)==null?void 0:a.huggingFace;return O(this,i,[t,"Attach an image file","google/vit-base-patch16-224",o,s,{images:{}}])}return y(i,[{key:"extractPollResultData",value:function(){var t=k(f().mark(function r(a){var o;return f().wrap(function(l){for(;;)switch(l.prev=l.next){case 0:if(!a.estimated_time){l.next=2;break}return l.abrupt("return",{timeoutMS:(a.estimated_time+1)*1e3});case 2:if(!a.error){l.next=4;break}throw a.error;case 4:return l.abrupt("return",{text:((o=a[0])==null?void 0:o.label)||""});case 5:case"end":return l.stop()}},r)}));function n(r){return t.apply(this,arguments)}return n}()}]),i}($n),ct="data:image/png;base64,",xe=function(){function e(){g(this,e)}return y(e,null,[{key:"buildHeaders",value:function(t){return{Authorization:"Bearer ".concat(t),"Content-Type":"application/json"}}},{key:"handleVerificationResult",value:function(t,n,r,a){t.message?a(ee.INVALID_KEY):r(n)}},{key:"buildKeyVerificationDetails",value:function(){return{url:"https://api.stability.ai/v1/engines/list",method:"GET",handleVerificationResult:e.handleVerificationResult}}}]),e}(),Dt=function(e){P(i,e);function i(t,n,r,a,o){var s;return g(this,i),s=O(this,i,[t,n,r,a,o]),s.insertKeyPlaceholderText="Stability AI API Key",s.keyHelpUrl="https://platform.stability.ai/docs/getting-started/authentication",s.permittedErrorPrefixes=["Incorrect","invalid_"],s}return y(i)}(ce),hu=function(e){P(i,e);function i(t){var n;g(this,i);var r,a=JSON.parse(JSON.stringify(t.directConnection)),o=a==null?void 0:a.stabilityAI,s={images:{files:{acceptedFormats:".png",maxNumberOfFiles:1}}};n=O(this,i,[t,xe.buildKeyVerificationDetails(),xe.buildHeaders,o,s]),n.url="https://api.stability.ai/v1/generation/esrgan-v1-x2plus/image-to-image/upscale",n.textInputPlaceholderText="Describe image changes",n.introPanelMarkUp=`
    <div style="width: 100%; text-align: center; margin-left: -10px"><b>Stability AI</b></div>
    <div style="width: 100%; text-align: center; margin-left: -10px; margin-top: 5px"><b>Image to Image Upscale</b></div>
    <p>Upload an image to generate a new one with higher resolution.</p>
    <p>Click <a href="https://platform.stability.ai/">here</a> for more info.</p>`;var l=(r=a==null?void 0:a.stabilityAI)==null?void 0:r.imageToImageUpscale;return R(l)=="object"&&(l.engine_id&&(n.url="https://api.stability.ai/v1/generation/".concat(l.engine_id,"/image-to-image/upscale")),i.cleanConfig(l),Object.assign(n.rawBody,l)),n.canSendMessage=i.canSendFileMessage,n}return y(i,[{key:"createFormDataBody",value:function(n,r){var a=new FormData;return a.append("image",r),Object.keys(n).forEach(function(o){a.append(o,String(n[o]))}),a}},{key:"callServiceAPI",value:function(){var t=k(f().mark(function r(a,o,s){var l;return f().wrap(function(c){for(;;)switch(c.prev=c.next){case 0:if(this.requestSettings){c.next=2;break}throw new Error("Request settings have not been set up");case 2:if(s){c.next=4;break}throw new Error("Image was not found");case 4:l=this.createFormDataBody(this.rawBody,s[0]),B.tempRemoveContentHeader(this.requestSettings,J.request.bind(this,this,l,a),!1);case 6:case"end":return c.stop()}},r,this)}));function n(r,a,o){return t.apply(this,arguments)}return n}()},{key:"extractResultData",value:function(){var t=k(f().mark(function r(a){return f().wrap(function(s){for(;;)switch(s.prev=s.next){case 0:if(!a.message){s.next=2;break}throw a.message;case 2:return s.abrupt("return",{files:a.artifacts.map(function(l){return{src:"".concat(ct).concat(l.base64),type:"image"}})});case 3:case"end":return s.stop()}},r)}));function n(r){return t.apply(this,arguments)}return n}()}],[{key:"cleanConfig",value:function(n){delete n.engine_id}},{key:"canSendFileMessage",value:function(n,r){return!!(r!=null&&r[0])}}]),i}(Dt),pu=function(e){P(i,e);function i(t){var n;g(this,i);var r,a=JSON.parse(JSON.stringify(t.directConnection)),o=a==null?void 0:a.stabilityAI,s={images:{files:{acceptedFormats:".png",maxNumberOfFiles:2}}};n=O(this,i,[t,xe.buildKeyVerificationDetails(),xe.buildHeaders,o,s]),n.url="https://api.stability.ai/v1/generation/stable-diffusion-xl-1024-v1-0/image-to-image/masking",n._maskSource="MASK_IMAGE_WHITE",n.textInputPlaceholderText="Describe image changes",n.introPanelMarkUp=`
    <div style="width: 100%; text-align: center; margin-left: -10px"><b>Stability AI</b></div>
    <div style="width: 100%; text-align: center; margin-left: -10px; margin-top: 5px"><b>Image to Image Masking</b></div>
    <p>Upload an image, its mask image to create a new one based on the changes you have described for the mask area.</p>
    <p>Click <a href="https://platform.stability.ai/">here</a> for more info.</p>`;var l=(r=a==null?void 0:a.stabilityAI)==null?void 0:r.imageToImageMasking;return R(l)=="object"&&(l.engine_id&&(n.url="https://api.stability.ai/v1/generation/".concat(l.engine_id,"/image-to-image/masking")),l.weight!==void 0&&l.weight!==null&&(n._imageWeight=l.weight),l.mask_source!==void 0&&l.mask_source!==null&&(n._maskSource=l.mask_source),i.cleanConfig(l),Object.assign(n.rawBody,l)),n.canSendMessage=i.canSendFileTextMessage,n}return y(i,[{key:"createFormDataBody",value:function(n,r,a,o){var s=new FormData;return s.append("init_image",r),s.append("mask_source",String(this._maskSource)),s.append("mask_image",a),o&&o!==""&&s.append("text_prompts[0][text]",o),this._imageWeight!==void 0&&this._imageWeight!==null&&s.append("text_prompts[0][weight]",String(this._imageWeight)),Object.keys(n).forEach(function(l){s.append(l,String(n[l]))}),s.get("weight")===void 0&&s.append("weight",String(1)),s}},{key:"callServiceAPI",value:function(){var t=k(f().mark(function r(a,o,s){var l,u,c,d;return f().wrap(function(p){for(;;)switch(p.prev=p.next){case 0:if(this.requestSettings){p.next=2;break}throw new Error("Request settings have not been set up");case 2:if(!(!s||!s[0]||!s[1])){p.next=4;break}throw new Error("Image was not found");case 4:c=(u=(l=o[o.length-1])==null?void 0:l.text)==null?void 0:u.trim(),d=this.createFormDataBody(this.rawBody,s[0],s[1],c),B.tempRemoveContentHeader(this.requestSettings,J.request.bind(this,this,d,a),!1);case 6:case"end":return p.stop()}},r,this)}));function n(r,a,o){return t.apply(this,arguments)}return n}()},{key:"extractResultData",value:function(){var t=k(f().mark(function r(a){return f().wrap(function(s){for(;;)switch(s.prev=s.next){case 0:if(!a.message){s.next=2;break}throw a.message;case 2:return s.abrupt("return",{files:a.artifacts.map(function(l){return{src:"".concat(ct).concat(l.base64),type:"image"}})});case 3:case"end":return s.stop()}},r)}));function n(r){return t.apply(this,arguments)}return n}()}],[{key:"cleanConfig",value:function(n){delete n.engine_id,delete n.weight}},{key:"canSendFileTextMessage",value:function(n,r){return!!(r!=null&&r[0])&&!!(n&&n.trim()!=="")}}]),i}(Dt),fu=function(e){P(i,e);function i(t){g(this,i);var n,r,a,o=(r=(n=t.directConnection)==null?void 0:n.huggingFace)==null?void 0:r.audioSpeechRecognition,s=(a=t.directConnection)==null?void 0:a.huggingFace;return O(this,i,[t,"Attach an audio file","facebook/wav2vec2-large-960h-lv60-self",o,s,{audio:{}}])}return y(i,[{key:"extractPollResultData",value:function(){var t=k(f().mark(function r(a){return f().wrap(function(s){for(;;)switch(s.prev=s.next){case 0:if(!a.estimated_time){s.next=2;break}return s.abrupt("return",{timeoutMS:(a.estimated_time+1)*1e3});case 2:if(!a.error){s.next=4;break}throw a.error;case 4:return s.abrupt("return",{text:a.text||""});case 5:case"end":return s.stop()}},r)}));function n(r){return t.apply(this,arguments)}return n}()}]),i}($n),vu=function(e){P(i,e);function i(t){g(this,i);var n,r,a,o=(r=(n=t.directConnection)==null?void 0:n.huggingFace)==null?void 0:r.textGeneration,s=(a=t.directConnection)==null?void 0:a.huggingFace;return O(this,i,[t,"Once upon a time","gpt2",o,s])}return y(i,[{key:"extractResultData",value:function(){var t=k(f().mark(function r(a){return f().wrap(function(s){for(;;)switch(s.prev=s.next){case 0:if(!a.error){s.next=2;break}throw a.error;case 2:return s.abrupt("return",{text:a[0].generated_text||""});case 3:case"end":return s.stop()}},r)}));function n(r){return t.apply(this,arguments)}return n}()}]),i}(Ue),mu=function(e){P(i,e);function i(t){var n;g(this,i);var r,a,o,s=(a=(r=t.directConnection)==null?void 0:r.huggingFace)==null?void 0:a.questionAnswer,l=(o=t.directConnection)==null?void 0:o.huggingFace;return n=O(this,i,[t,"Ask a question","bert-large-uncased-whole-word-masking-finetuned-squad",s,l]),n.permittedErrorPrefixes=["Authorization header","Error in"],n.context=s.context,n}return y(i,[{key:"preprocessBody",value:function(n,r){var a=r[r.length-1].text;if(a)return{inputs:{question:a,context:this.context,options:{wait_for_model:!0}}}}},{key:"extractResultData",value:function(){var t=k(f().mark(function r(a){return f().wrap(function(s){for(;;)switch(s.prev=s.next){case 0:if(!a.error){s.next=2;break}throw a.error;case 2:return s.abrupt("return",{text:a.answer||""});case 3:case"end":return s.stop()}},r)}));function n(r){return t.apply(this,arguments)}return n}()}]),i}(Ue),gu=function(e){P(i,e);function i(t){g(this,i);var n,r,a,o=(r=(n=t.directConnection)==null?void 0:n.huggingFace)==null?void 0:r.summarization,s=(a=t.directConnection)==null?void 0:a.huggingFace;return O(this,i,[t,"Insert text to summarize","facebook/bart-large-cnn",o,s])}return y(i,[{key:"extractResultData",value:function(){var t=k(f().mark(function r(a){return f().wrap(function(s){for(;;)switch(s.prev=s.next){case 0:if(!a.error){s.next=2;break}throw a.error;case 2:return s.abrupt("return",{text:a[0].summary_text||""});case 3:case"end":return s.stop()}},r)}));function n(r){return t.apply(this,arguments)}return n}()}]),i}(Ue),yu=function(e){P(i,e);function i(t){var n,r;g(this,i);var a,o,s,l=(o=(a=t.directConnection)==null?void 0:a.huggingFace)==null?void 0:o.conversation,u=(s=t.directConnection)==null?void 0:s.huggingFace;return r=O(this,i,[t,"Ask me anything!","facebook/blenderbot-400M-distill",l,u]),(n=r.maxMessages)!==null&&n!==void 0||(r.maxMessages=-1),r}return y(i,[{key:"processMessages",value:function(n){var r=n.filter(function(u){return u.text}),a=r[r.length-1].text,o=r.slice(0,r.length-1);if(a){var s=o.filter(function(u){return u.role==="user"}).map(function(u){return u.text}),l=o.filter(function(u){return u.role==="ai"}).map(function(u){return u.text});return{past_user_inputs:s,generated_responses:l,mostRecentMessageText:a}}}},{key:"preprocessBody",value:function(n,r){var a,o=JSON.parse(JSON.stringify(n)),s=this.processMessages(r);if(s)return(a=o.options)!==null&&a!==void 0||(o.options={}),o.options.wait_for_model=!0,V({inputs:{past_user_inputs:s.past_user_inputs,generated_responses:s.generated_responses,text:s.mostRecentMessageText}},o)}},{key:"extractResultData",value:function(){var t=k(f().mark(function r(a){return f().wrap(function(s){for(;;)switch(s.prev=s.next){case 0:if(!a.error){s.next=2;break}throw a.error;case 2:return s.abrupt("return",{text:a.generated_text||""});case 3:case"end":return s.stop()}},r)}));function n(r){return t.apply(this,arguments)}return n}()}]),i}(Ue),bu=function(e){P(i,e);function i(t){var n;g(this,i);var r,a=JSON.parse(JSON.stringify(t.directConnection)),o=a.stabilityAI,s={images:{files:{acceptedFormats:".png",maxNumberOfFiles:1}}};n=O(this,i,[t,xe.buildKeyVerificationDetails(),xe.buildHeaders,o,s]),n.url="https://api.stability.ai/v1/generation/stable-diffusion-v1-6/image-to-image",n.textInputPlaceholderText="Describe image changes",n.introPanelMarkUp=`
    <div style="width: 100%; text-align: center; margin-left: -10px"><b>Stability AI: Image to Image</b></div>
    <p>Upload an image to create a new one with the changes you have described.</p>
    <p>Click <a href="https://platform.stability.ai/">here</a> for more info.</p>`;var l=(r=a.stabilityAI)==null?void 0:r.imageToImage;return R(l)=="object"&&(l.engine_id&&(n.url="https://api.stability.ai/v1/generation/".concat(l.engine_id,"/text-to-image")),l.weight!==void 0&&l.weight!==null&&(n._imageWeight=l.weight),i.cleanConfig(l),Object.assign(n.rawBody,l)),n.canSendMessage=i.canSendFileTextMessage,n}return y(i,[{key:"createFormDataBody",value:function(n,r,a){var o=new FormData;return o.append("init_image",r),a&&a!==""&&o.append("text_prompts[0][text]",a),this._imageWeight!==void 0&&this._imageWeight!==null&&o.append("text_prompts[0][weight]",String(this._imageWeight)),Object.keys(n).forEach(function(s){o.append(s,String(n[s]))}),o.get("weight")===void 0&&o.append("weight",String(1)),o}},{key:"callServiceAPI",value:function(){var t=k(f().mark(function r(a,o,s){var l,u,c,d;return f().wrap(function(p){for(;;)switch(p.prev=p.next){case 0:if(this.requestSettings){p.next=2;break}throw new Error("Request settings have not been set up");case 2:if(s){p.next=4;break}throw new Error("Image was not found");case 4:c=(u=(l=o[o.length-1])==null?void 0:l.text)==null?void 0:u.trim(),d=this.createFormDataBody(this.rawBody,s[0],c),B.tempRemoveContentHeader(this.requestSettings,J.request.bind(this,this,d,a),!1);case 6:case"end":return p.stop()}},r,this)}));function n(r,a,o){return t.apply(this,arguments)}return n}()},{key:"extractResultData",value:function(){var t=k(f().mark(function r(a){return f().wrap(function(s){for(;;)switch(s.prev=s.next){case 0:if(!a.message){s.next=2;break}throw a.message;case 2:return s.abrupt("return",{files:a.artifacts.map(function(l){return{src:"".concat(ct).concat(l.base64),type:"image"}})});case 3:case"end":return s.stop()}},r)}));function n(r){return t.apply(this,arguments)}return n}()}],[{key:"cleanConfig",value:function(n){delete n.engine_id,delete n.weight}},{key:"canSendFileTextMessage",value:function(n,r){return!!(r!=null&&r[0])&&!!(n&&n.trim()!=="")}}]),i}(Dt),ku=function(e){P(i,e);function i(t){g(this,i);var n,r,a,o=(r=(n=t.directConnection)==null?void 0:n.huggingFace)==null?void 0:r.translation,s=(a=t.directConnection)==null?void 0:a.huggingFace;return O(this,i,[t,"Insert text to translate","Helsinki-NLP/opus-tatoeba-en-ja",o,s])}return y(i,[{key:"extractResultData",value:function(){var t=k(f().mark(function r(a){return f().wrap(function(s){for(;;)switch(s.prev=s.next){case 0:if(!a.error){s.next=2;break}throw a.error;case 2:return s.abrupt("return",{text:a[0].translation_text||""});case 3:case"end":return s.stop()}},r)}));function n(r){return t.apply(this,arguments)}return n}()}]),i}(Ue),_u=function(e){P(i,e);function i(t){var n;g(this,i);var r,a=JSON.parse(JSON.stringify(t.directConnection)),o=a.stabilityAI;n=O(this,i,[t,xe.buildKeyVerificationDetails(),xe.buildHeaders,o]),n.url="https://api.stability.ai/v1/generation/stable-diffusion-v1-6/text-to-image",n.textInputPlaceholderText="Describe an image",n.introPanelMarkUp=`
    <div style="width: 100%; text-align: center; margin-left: -10px"><b>Stability AI: Text to Image</b></div>
    <p>Insert text to generate an image.</p>
    <p>Click <a href="https://platform.stability.ai/">here</a> for more info.</p>`;var s=(r=a.stabilityAI)==null?void 0:r.textToImage;return R(s)=="object"&&(s.engine_id&&(n.url="https://api.stability.ai/v1/generation/".concat(s.engine_id,"/text-to-image")),s.weight!==void 0&&s.weight!==null&&(n._imageWeight=s.weight),i.cleanConfig(s),Object.assign(n.rawBody,s)),n.canSendMessage=i.canSendTextMessage,n}return y(i,[{key:"preprocessBody",value:function(n,r){var a=JSON.parse(JSON.stringify(n)),o={text:r};return this._imageWeight&&(o.weight=this._imageWeight),a.text_prompts=[o],a}},{key:"callServiceAPI",value:function(){var t=k(f().mark(function r(a,o){var s;return f().wrap(function(u){for(;;)switch(u.prev=u.next){case 0:if(this.requestSettings){u.next=2;break}throw new Error("Request settings have not been set up");case 2:s=this.preprocessBody(this.rawBody,o[o.length-1].text),J.request(this,s,a);case 4:case"end":return u.stop()}},r,this)}));function n(r,a){return t.apply(this,arguments)}return n}()},{key:"extractResultData",value:function(){var t=k(f().mark(function r(a){return f().wrap(function(s){for(;;)switch(s.prev=s.next){case 0:if(!a.message){s.next=2;break}throw a.message;case 2:return s.abrupt("return",{files:a.artifacts.map(function(l){return{src:"".concat(ct).concat(l.base64),type:"image"}})});case 3:case"end":return s.stop()}},r)}));function n(r){return t.apply(this,arguments)}return n}()}],[{key:"cleanConfig",value:function(n){delete n.engine_id,delete n.weight}},{key:"canSendTextMessage",value:function(n){return!!(n&&n.trim()!=="")}}]),i}(Dt),wu=function(e){P(i,e);function i(t){var n;g(this,i);var r,a,o,s=(a=(r=t.directConnection)==null?void 0:r.huggingFace)==null?void 0:a.fillMask,l=(o=t.directConnection)==null?void 0:o.huggingFace;return n=O(this,i,[t,"The goal of life is [MASK].","bert-base-uncased",s,l]),n.introPanelMarkUp=`
    <div style="width: 100%; text-align: center; margin-left: -10px"><b>Hugging Face</b></div>
    <p>Insert a sentence with the word [MASK] and the model will try to fill it for you. E.g. I want [MASK].</p>
    <p>First message may take an extented amount of time to complete as the model needs to be initialized.</p>`,n.permittedErrorPrefixes=["Authorization header","No mask_token"],n}return y(i,[{key:"extractResultData",value:function(){var t=k(f().mark(function r(a){return f().wrap(function(s){for(;;)switch(s.prev=s.next){case 0:if(!a.error){s.next=2;break}throw a.error;case 2:return s.abrupt("return",{text:a[0].sequence||""});case 3:case"end":return s.stop()}},r)}));function n(r){return t.apply(this,arguments)}return n}()}]),i}(Ue),Tr=function(){function e(){g(this,e)}return y(e,null,[{key:"buildHeaders",value:function(t){return{Authorization:"Bearer ".concat(t),"Content-Type":"application/json",accept:"application/json"}}},{key:"handleVerificationResult",value:function(t,n,r,a){var o;(o=t.message)!=null&&o.includes("invalid request: prompt must be at least 1 token long")?r(n):a(ee.INVALID_KEY)}},{key:"buildKeyVerificationDetails",value:function(){return{url:"https://api.cohere.ai/v1/generate",method:"POST",handleVerificationResult:e.handleVerificationResult,body:JSON.stringify({prompt:""})}}}]),e}(),Gn=function(e){P(i,e);function i(t,n,r,a,o){var s;return g(this,i),s=O(this,i,[t,Tr.buildKeyVerificationDetails(),Tr.buildHeaders,o]),s.insertKeyPlaceholderText="Cohere API Key",s.keyHelpUrl="https://dashboard.cohere.ai/api-keys",s.permittedErrorPrefixes=["invalid"],s.url=n,s.textInputPlaceholderText=r,a&&R(a)=="object"&&Object.assign(s.rawBody,a),s}return y(i)}(ce),Su=function(e){P(i,e);function i(t){g(this,i);var n,r,a,o=(r=(n=t.directConnection)==null?void 0:n.cohere)==null?void 0:r.textGeneration,s=(a=t.directConnection)==null?void 0:a.cohere;return O(this,i,[t,"https://api.cohere.ai/v1/generate","Once upon a time",o,s])}return y(i,[{key:"preprocessBody",value:function(n,r){var a=JSON.parse(JSON.stringify(n)),o=r[r.length-1].text;if(o)return V({prompt:o},a)}},{key:"callServiceAPI",value:function(){var t=k(f().mark(function r(a,o){var s;return f().wrap(function(u){for(;;)switch(u.prev=u.next){case 0:if(this.requestSettings){u.next=2;break}throw new Error("Request settings have not been set up");case 2:s=this.preprocessBody(this.rawBody,o),J.request(this,s,a);case 4:case"end":return u.stop()}},r,this)}));function n(r,a){return t.apply(this,arguments)}return n}()},{key:"extractResultData",value:function(){var t=k(f().mark(function r(a){var o;return f().wrap(function(l){for(;;)switch(l.prev=l.next){case 0:if(!a.message){l.next=2;break}throw a.message;case 2:return l.abrupt("return",{text:((o=a.generations)==null?void 0:o[0].text)||""});case 3:case"end":return l.stop()}},r)}));function n(r){return t.apply(this,arguments)}return n}()}]),i}(Gn),xu=function(e){P(i,e);function i(t){g(this,i);var n,r,a,o=(r=(n=t.directConnection)==null?void 0:n.cohere)==null?void 0:r.summarization,s=(a=t.directConnection)==null?void 0:a.cohere;return O(this,i,[t,"https://api.cohere.ai/v1/summarize","Insert text to summarize",o,s])}return y(i,[{key:"preprocessBody",value:function(n,r){var a=JSON.parse(JSON.stringify(n)),o=r[r.length-1].text;if(o)return V({text:o},a)}},{key:"callServiceAPI",value:function(){var t=k(f().mark(function r(a,o){var s;return f().wrap(function(u){for(;;)switch(u.prev=u.next){case 0:if(this.requestSettings){u.next=2;break}throw new Error("Request settings have not been set up");case 2:s=this.preprocessBody(this.rawBody,o),J.request(this,s,a);case 4:case"end":return u.stop()}},r,this)}));function n(r,a){return t.apply(this,arguments)}return n}()},{key:"extractResultData",value:function(){var t=k(f().mark(function r(a){return f().wrap(function(s){for(;;)switch(s.prev=s.next){case 0:if(!a.message){s.next=2;break}throw a.message;case 2:return s.abrupt("return",{text:a.summary||""});case 3:case"end":return s.stop()}},r)}));function n(r){return t.apply(this,arguments)}return n}()}]),i}(Gn),ae=function(){function e(){g(this,e)}return y(e,null,[{key:"buildHeaders",value:function(t){return{Authorization:"Bearer ".concat(t),"Content-Type":"application/json"}}},{key:"handleVerificationResult",value:function(t,n,r,a){var o=t;o.error?o.error.code==="invalid_api_key"?a(ee.INVALID_KEY):a(ee.CONNECTION_FAILED):r(n)}},{key:"buildKeyVerificationDetails",value:function(){return{url:"https://api.openai.com/v1/models",method:"GET",handleVerificationResult:e.handleVerificationResult}}},{key:"directFetch",value:function(){var i=k(f().mark(function n(r,a,o){var s,l,u=arguments;return f().wrap(function(d){for(;;)switch(d.prev=d.next){case 0:return s=u.length>3&&u[3]!==void 0?u[3]:!0,r.requestSettings.method=o,d.next=4,B.fetch(r,r.requestSettings.headers,s,a).then(function(h){return B.processResponseByType(h)});case 4:if(l=d.sent,!l.error){d.next=7;break}throw l.error.message;case 7:return d.abrupt("return",l);case 8:case"end":return d.stop()}},n)}));function t(n,r,a){return i.apply(this,arguments)}return t}()}]),e}(),Wn=function(e){P(i,e);function i(t){var n,r,a;g(this,i);var o,s,l,u=JSON.parse(JSON.stringify(t.directConnection)),c=u==null?void 0:u.openAI;a=O(this,i,[t,ae.buildKeyVerificationDetails(),ae.buildHeaders,c]),a.insertKeyPlaceholderText="OpenAI API Key",a.keyHelpUrl="https://platform.openai.com/account/api-keys",a.url="https://api.openai.com/v1/audio/speech",a.permittedErrorPrefixes=["Invalid"],a.introPanelMarkUp=`
    <div style="width: 100%; text-align: center; margin-left: -10px"><b>OpenAI : Text To Speech</b></div>
    <p>Generate an audio file based on your text input.</p>
    <p>Click <a href="https://platform.openai.com/docs/guides/text-to-speech">here</a> for more information.</p>`;var d=(o=u==null?void 0:u.openAI)==null?void 0:o.textToSpeech;return R(d)=="object"&&Object.assign(a.rawBody,d),(n=(s=a.rawBody).model)!==null&&n!==void 0||(s.model=i.DEFAULT_MODEL),(r=(l=a.rawBody).voice)!==null&&r!==void 0||(l.voice=i.DEFAULT_VOIDE),a.textInputPlaceholderText="Insert text to generate audio",a.rawBody.response_format="mp3",a}return y(i,[{key:"preprocessBody",value:function(n,r){var a,o,s=JSON.parse(JSON.stringify(n)),l=(o=(a=r[r.length-1])==null?void 0:a.text)==null?void 0:o.trim();return l&&l!==""&&(s.input=l),s}},{key:"callServiceAPI",value:function(){var t=k(f().mark(function r(a,o){var s,l;return f().wrap(function(c){for(;;)switch(c.prev=c.next){case 0:if((s=this.requestSettings)!=null&&s.headers){c.next=2;break}throw new Error("Request settings have not been set up");case 2:this.url=this.requestSettings.url||this.url,l=this.preprocessBody(this.rawBody,o),J.request(this,l,a);case 5:case"end":return c.stop()}},r,this)}));function n(r,a){return t.apply(this,arguments)}return n}()},{key:"extractResultData",value:function(){var t=k(f().mark(function r(a){return f().wrap(function(s){for(;;)switch(s.prev=s.next){case 0:if(!(a instanceof Blob)){s.next=2;break}return s.abrupt("return",new Promise(function(l){var u=new FileReader;u.readAsDataURL(a),u.onload=function(c){l({files:[{src:c.target.result,type:"audio"}]})}}));case 2:if(!a.error){s.next=4;break}throw a.error.message;case 4:return s.abrupt("return",{error:"error"});case 5:case"end":return s.stop()}},r)}));function n(r){return t.apply(this,arguments)}return n}()}]),i}(ce);Wn.DEFAULT_MODEL="tts-1";Wn.DEFAULT_VOIDE="alloy";var Eu=Wn,Ft=function(e){P(i,e);function i(t){var n,r;g(this,i);var a,o,s=JSON.parse(JSON.stringify(t.directConnection)),l=s==null?void 0:s.openAI;r=O(this,i,[t,ae.buildKeyVerificationDetails(),ae.buildHeaders,l,{audio:{}}]),r.insertKeyPlaceholderText="OpenAI API Key",r.keyHelpUrl="https://platform.openai.com/account/api-keys",r.introPanelMarkUp=`
    <div style="width: 100%; text-align: center; margin-left: -10px"><b>OpenAI : Speech To Text</b></div>
    <p><b>Upload an audio file</b> to transcribe it into text. You can optionally provide text to guide the audio
      processing.
    <p>Click <a href="https://platform.openai.com/docs/guides/speech-to-text">here</a> for more info.</p>`,r.url="",r.permittedErrorPrefixes=["Invalid"],r.textInputPlaceholderText="Upload an audio file",r._service_url=i.AUDIO_TRANSCRIPTIONS_URL;var u=(a=s==null?void 0:s.openAI)==null?void 0:a.audio;return R(u)=="object"&&(r.processConfig(u),i.cleanConfig(u),Object.assign(r.rawBody,u)),(n=(o=r.rawBody).model)!==null&&n!==void 0||(o.model=i.DEFAULT_MODEL),r.rawBody.response_format="json",r.canSendMessage=i.canSendFileMessage,r}return y(i,[{key:"processConfig",value:function(n){n!=null&&n.type&&n.type==="translation"&&(this._service_url=i.AUDIO_TRANSLATIONS_URL,delete n.language)}},{key:"preprocessBody",value:function(n,r){var a,o,s=JSON.parse(JSON.stringify(n)),l=(o=(a=r[r.length-1])==null?void 0:a.text)==null?void 0:o.trim();return l&&l!==""&&(s.prompt=l),s}},{key:"callServiceAPI",value:function(){var t=k(f().mark(function r(a,o,s){var l,u,c;return f().wrap(function(h){for(;;)switch(h.prev=h.next){case 0:if((l=this.requestSettings)!=null&&l.headers){h.next=2;break}throw new Error("Request settings have not been set up");case 2:if(s!=null&&s[0]){h.next=4;break}throw new Error("No file was added");case 4:this.url=this.requestSettings.url||this._service_url,u=this.preprocessBody(this.rawBody,o),c=i.createFormDataBody(u,s[0]),B.tempRemoveContentHeader(this.requestSettings,J.request.bind(this,this,c,a),!1);case 7:case"end":return h.stop()}},r,this)}));function n(r,a,o){return t.apply(this,arguments)}return n}()},{key:"extractResultData",value:function(){var t=k(f().mark(function r(a){return f().wrap(function(s){for(;;)switch(s.prev=s.next){case 0:if(!a.error){s.next=2;break}throw a.error.message;case 2:return s.abrupt("return",{text:a.text});case 3:case"end":return s.stop()}},r)}));function n(r){return t.apply(this,arguments)}return n}()}],[{key:"canSendFileMessage",value:function(n,r){return!!(r!=null&&r[0])}},{key:"cleanConfig",value:function(n){delete n.type}},{key:"createFormDataBody",value:function(n,r){var a=new FormData;return a.append("file",r),Object.keys(n).forEach(function(o){a.append(o,String(n[o]))}),a}}]),i}(ce);Ft.AUDIO_TRANSCRIPTIONS_URL="https://api.openai.com/v1/audio/transcriptions";Ft.AUDIO_TRANSLATIONS_URL="https://api.openai.com/v1/audio/translations";Ft.DEFAULT_MODEL="whisper-1";var Cu=Ft,Ne=function(){function e(){g(this,e)}return y(e,null,[{key:"buildTextToSpeechHeaders",value:function(t,n){return{"Ocp-Apim-Subscription-Key":n,"Content-Type":"application/ssml+xml","X-Microsoft-OutputFormat":t}}},{key:"buildSpeechToTextHeaders",value:function(t){return{"Ocp-Apim-Subscription-Key":t,Accept:"application/json"}}},{key:"handleSpeechVerificationResult",value:function(t,n,r,a){t.error?a(ee.INVALID_KEY):r(n)}},{key:"buildSpeechKeyVerificationDetails",value:function(t){return{url:"https://".concat(t,".api.cognitive.microsoft.com/sts/v1.0/issuetoken"),method:"POST",createHeaders:function(r){return{"Ocp-Apim-Subscription-Key":"".concat(r)}},handleVerificationResult:e.handleSpeechVerificationResult}}},{key:"buildSummarizationHeader",value:function(t){return{"Ocp-Apim-Subscription-Key":t,"Content-Type":"application/json"}}},{key:"handleLanguageVerificationResult",value:function(t,n,r,a){var o;((o=t.error)==null?void 0:o.code)==="401"?a(ee.INVALID_KEY):r(n)}},{key:"buildLanguageKeyVerificationDetails",value:function(t){return{url:"".concat(t,"/language/analyze-text/jobs?api-version=2022-10-01-preview"),method:"POST",createHeaders:function(r){return{"Ocp-Apim-Subscription-Key":"".concat(r)}},handleVerificationResult:e.handleLanguageVerificationResult}}},{key:"handleTranslationVerificationResult",value:function(t,n,r,a){t.json().then(function(o){!Array.isArray(o)&&o.error.code===401e3?a(ee.INVALID_KEY):r(n)})}},{key:"buildTranslationKeyVerificationDetails",value:function(t){return{url:"https://api.cognitive.microsofttranslator.com/translate?api-version=3.0&to=es",method:"POST",createHeaders:function(r){return e.buildTranslationHeaders(t,r)},handleVerificationResult:e.handleTranslationVerificationResult}}},{key:"buildTranslationHeaders",value:function(t,n){var r={"Ocp-Apim-Subscription-Key":n,"Content-Type":"application/json"};return t&&(r["Ocp-Apim-Subscription-Region"]=t),r}}]),e}(),Mu=function(e){P(i,e);function i(t,n,r,a,o){var s;return g(this,i),s=O(this,i,[t,Ne.buildLanguageKeyVerificationDetails(r),n,a,o]),s.insertKeyPlaceholderText="Azure Language Subscription Key",s.keyHelpUrl="https://learn.microsoft.com/en-us/azure/api-management/api-management-subscriptions#create-and-manage-subscriptions-in-azure-portal",s.permittedErrorPrefixes=["Access"],s}return y(i)}(ce),Au=function(e){P(i,e);function i(t){var n,r;g(this,i);var a,o,s,l,u=(o=(a=t.directConnection)==null?void 0:a.azure)==null?void 0:o.summarization,c=(s=t.directConnection)==null?void 0:s.azure;return r=O(this,i,[t,Ne.buildSummarizationHeader,u.endpoint,c]),r.url="",r.textInputPlaceholderText="Insert text to summarize",(n=(l=r.rawBody).language)!==null&&n!==void 0||(l.language="en"),Object.assign(r.rawBody,u),r.url="".concat(u.endpoint,"/language/analyze-text/jobs?api-version=2022-10-01-preview"),r}return y(i,[{key:"preprocessBody",value:function(n,r){var a=r[r.length-1].text;if(a)return{analysisInput:{documents:[{id:"1",language:n.language,text:a}]},tasks:[{kind:"ExtractiveSummarization"}]}}},{key:"callServiceAPI",value:function(){var t=k(f().mark(function r(a,o){var s;return f().wrap(function(u){for(;;)switch(u.prev=u.next){case 0:if(this.requestSettings){u.next=2;break}throw new Error("Request settings have not been set up");case 2:s=this.preprocessBody(this.rawBody,o),J.request(this,s,a),this.messages=a;case 4:case"end":return u.stop()}},r,this)}));function n(r,a){return t.apply(this,arguments)}return n}()},{key:"extractResultData",value:function(){var t=k(f().mark(function r(a){var o,s,l;return f().wrap(function(c){for(;;)switch(c.prev=c.next){case 0:if(!a.error){c.next=2;break}throw a.error.message;case 2:return this.messages&&this.completionsHandlers&&(s=a.headers.get("operation-location"),l={method:"GET",headers:(o=this.requestSettings)==null?void 0:o.headers},J.executePollRequest(this,s,l,this.messages)),c.abrupt("return",{makingAnotherRequest:!0});case 4:case"end":return c.stop()}},r,this)}));function n(r){return t.apply(this,arguments)}return n}()},{key:"extractPollResultData",value:function(){var t=k(f().mark(function r(a){var o,s,l,u;return f().wrap(function(d){for(;;)switch(d.prev=d.next){case 0:if(!a.error){d.next=2;break}throw a.error;case 2:if(a.status!=="running"){d.next=4;break}return d.abrupt("return",{timeoutMS:2e3});case 4:if(!(a.errors.length>0)){d.next=6;break}throw a.errors[0];case 6:if(!(a.tasks.items[0].results.errors.length>0)){d.next=8;break}throw a.tasks.items[0].results.errors[0];case 8:o="",s=Zo(a.tasks.items[0].results.documents[0].sentences);try{for(s.s();!(l=s.n()).done;)u=l.value,o+=u.text}catch(h){s.e(h)}finally{s.f()}return d.abrupt("return",{text:o||""});case 12:case"end":return d.stop()}},r)}));function n(r){return t.apply(this,arguments)}return n}()}]),i}(Mu),dn=function(){function e(){g(this,e)}return y(e,null,[{key:"poll",value:function(){var i=k(f().mark(function n(r,a){var o,s,l,u;return f().wrap(function(d){for(;;)switch(d.prev=d.next){case 0:return o={authorization:r,"content-type":"application/json"},d.t0="https://api.assemblyai.com/v2/transcript/",d.next=4,fetch("https://api.assemblyai.com/v2/transcript",{method:"POST",body:JSON.stringify({audio_url:a}),headers:o});case 4:return d.next=6,d.sent.json();case 6:d.t1=d.sent.id,s=d.t0.concat.call(d.t0,d.t1);case 8:if(l){d.next=24;break}return d.next=11,fetch(s,{headers:o});case 11:return d.next=13,d.sent.json();case 13:if(u=d.sent,u.status!=="completed"){d.next=18;break}l=u,d.next=22;break;case 18:if(u.status!=="error"){d.next=20;break}throw new Error("Transcription failed: ".concat(u.error));case 20:return d.next=22,new Promise(function(h){return setTimeout(h,3e3)});case 22:d.next=8;break;case 24:return d.abrupt("return",l);case 25:case"end":return d.stop()}},n)}));function t(n,r){return i.apply(this,arguments)}return t}()},{key:"buildHeaders",value:function(t){return{Authorization:t,"Content-Type":"application/octet-stream"}}},{key:"handleVerificationResult",value:function(t,n,r,a){var o=t;o.error?o.error.code==="invalid_api_key"?a(ee.INVALID_KEY):a(ee.CONNECTION_FAILED):r(n)}},{key:"buildKeyVerificationDetails",value:function(){return{url:"https://api.assemblyai.com/v2/upload",method:"POST",handleVerificationResult:e.handleVerificationResult}}}]),e}(),Tu=function(e){P(i,e);function i(t){var n;g(this,i);var r,a=(r=t.directConnection)==null?void 0:r.assemblyAI;return n=O(this,i,[t,dn.buildKeyVerificationDetails(),dn.buildHeaders,a,{audio:{}}]),n.insertKeyPlaceholderText="AssemblyAI API Key",n.keyHelpUrl="https://www.assemblyai.com/app/account",n.introPanelMarkUp=`
    <div style="width: 100%; text-align: center; margin-left: -10px"><b>AssemblyAI Audio</b></div>
    <p><b>Upload an audio file</b> to transcribe it into text.
    <p>
      Click <a href="https://www.assemblyai.com/docs/Guides/transcribing_an_audio_file#get-started">here</a> for more info.
    </p>`,n.url="https://api.assemblyai.com/v2/upload",n.isTextInputDisabled=!0,n.textInputPlaceholderText="Upload an audio file",n.permittedErrorPrefixes=["Authentication","Invalid"],n.canSendMessage=i.canFileSendMessage,n}return y(i,[{key:"callServiceAPI",value:function(){var t=k(f().mark(function r(a,o,s){var l;return f().wrap(function(c){for(;;)switch(c.prev=c.next){case 0:if((l=this.requestSettings)!=null&&l.headers){c.next=2;break}throw new Error("Request settings have not been set up");case 2:if(s!=null&&s[0]){c.next=4;break}throw new Error("No file was added");case 4:J.request(this,s[0],a,!1);case 5:case"end":return c.stop()}},r,this)}));function n(r,a,o){return t.apply(this,arguments)}return n}()},{key:"extractResultData",value:function(){var t=k(f().mark(function r(a){var o,s,l;return f().wrap(function(c){for(;;)switch(c.prev=c.next){case 0:if(!a.error){c.next=2;break}throw a.error;case 2:return l=(s=(o=this.requestSettings)==null?void 0:o.headers)==null?void 0:s.Authorization,c.next=5,dn.poll(l,a.upload_url);case 5:return c.t0=c.sent.text,c.abrupt("return",{text:c.t0});case 7:case"end":return c.stop()}},r,this)}));function n(r){return t.apply(this,arguments)}return n}()}],[{key:"canFileSendMessage",value:function(n,r){return!!(r!=null&&r[0])}}]),i}(ce),qi=function(e){P(i,e);function i(t,n,r,a,o){var s;return g(this,i),s=O(this,i,[t,Ne.buildSpeechKeyVerificationDetails(r),n,a,o]),s.insertKeyPlaceholderText="Azure Speech Subscription Key",s.keyHelpUrl="https://learn.microsoft.com/en-us/azure/api-management/api-management-subscriptions#create-and-manage-subscriptions-in-azure-portal",s}return y(i)}(ce),zi=function(e){P(i,e);function i(t){var n,r,a,o;g(this,i);var s,l,u,c,d,h,p=(l=(s=t.directConnection)==null?void 0:s.azure)==null?void 0:l.textToSpeech,v=(u=t.directConnection)==null?void 0:u.azure;return o=O(this,i,[t,Ne.buildTextToSpeechHeaders.bind({},(p==null?void 0:p.outputFormat)||"audio-16khz-128kbitrate-mono-mp3"),p.region,v]),o.introPanelMarkUp=`
    <div style="width: 100%; text-align: center; margin-left: -10px"><b>Azure Text To Speech</b></div>
    <p>Insert text to synthesize it to audio.
    <p>
      Click <a href="`.concat(i.HELP_LINK,`">here</a> for more info.
    </p>`),o.url="",Object.assign(o.rawBody,p),(n=(c=o.rawBody).lang)!==null&&n!==void 0||(c.lang="en-US"),(r=(d=o.rawBody).name)!==null&&r!==void 0||(d.name="en-US-JennyNeural"),(a=(h=o.rawBody).gender)!==null&&a!==void 0||(h.gender="Female"),o.url="https://".concat(p.region,".tts.speech.microsoft.com/cognitiveservices/v1"),o}return y(i,[{key:"preprocessBody",value:function(n,r){var a=r[r.length-1].text;if(a)return"<speak version='1.0' xml:lang='".concat(n.lang,`'>
      <voice xml:lang='`).concat(n.lang,"' xml:gender='").concat(n.gender,"' name='").concat(n.name,`'>
        `).concat(a,`
      </voice>
    </speak>`)}},{key:"callServiceAPI",value:function(){var t=k(f().mark(function r(a,o){var s;return f().wrap(function(u){for(;;)switch(u.prev=u.next){case 0:if(this.requestSettings){u.next=2;break}throw new Error("Request settings have not been set up");case 2:s=this.preprocessBody(this.rawBody,o),J.request(this,s,a,!1);case 4:case"end":return u.stop()}},r,this)}));function n(r,a){return t.apply(this,arguments)}return n}()},{key:"extractResultData",value:function(){var t=k(f().mark(function r(a){return f().wrap(function(s){for(;;)switch(s.prev=s.next){case 0:return s.abrupt("return",new Promise(function(l){var u=new FileReader;u.readAsDataURL(a),u.onload=function(c){l({files:[{src:c.target.result,type:"audio"}]})}}));case 1:case"end":return s.stop()}},r)}));function n(r){return t.apply(this,arguments)}return n}()}]),i}(qi);zi.HELP_LINK="https://learn.microsoft.com/en-GB/azure/cognitive-services/speech-service/get-started-text-to-speech?tabs=windows%2Cterminal&pivots=programming-language-rest";var Iu=zi,Ui=function(e){P(i,e);function i(t){var n;g(this,i);var r,a,o,s=(a=(r=t.directConnection)==null?void 0:r.azure)==null?void 0:a.speechToText,l=(o=t.directConnection)==null?void 0:o.azure,u={audio:{files:{acceptedFormats:".wav,.ogg"}}};n=O(this,i,[t,Ne.buildSpeechToTextHeaders,s.region,l,u]),n.introPanelMarkUp=`
    <div style="width: 100%; text-align: center; margin-left: -10px"><b>Azure Speech To Text</b></div>
    <p><b>Upload a .wav or .ogg audio file</b> to transcribe it into text.
    <p>
      Click <a href="`.concat(i.HELP_LINK,`">here</a> for more info.
    </p>`),n.url="",n.isTextInputDisabled=!0,n.textInputPlaceholderText="Upload an audio file",n.canSendMessage=i.canFileSendMessage;var c=s.lang||"en-US";return n.url="https://".concat(s.region,".stt.speech.microsoft.com/speech/recognition/conversation/cognitiveservices/v1?language=").concat(c,"&format=detailed"),n.recordAudio=void 0,n}return y(i,[{key:"callServiceAPI",value:function(){var t=k(f().mark(function r(a,o,s){var l,u;return f().wrap(function(d){for(;;)switch(d.prev=d.next){case 0:if((l=this.requestSettings)!=null&&l.headers){d.next=2;break}throw new Error("Request settings have not been set up");case 2:if(s!=null&&s[0]){d.next=4;break}throw new Error("No file was added");case 4:(u=this.requestSettings)!=null&&u.headers&&(this.requestSettings.headers["Content-Type"]=s[0].name.toLocaleLowerCase().endsWith(".wav")?"audio/wav; codecs=audio/pcm; samplerate=16000":"audio/ogg; codecs=opus"),J.request(this,s[0],a,!1);case 5:case"end":return d.stop()}},r,this)}));function n(r,a,o){return t.apply(this,arguments)}return n}()},{key:"extractResultData",value:function(){var t=k(f().mark(function r(a){return f().wrap(function(s){for(;;)switch(s.prev=s.next){case 0:if(!a.error){s.next=2;break}throw a.error;case 2:return s.abrupt("return",{text:a.DisplayText||""});case 3:case"end":return s.stop()}},r)}));function n(r){return t.apply(this,arguments)}return n}()}],[{key:"canFileSendMessage",value:function(n,r){return!!(r!=null&&r[0])}}]),i}(qi);Ui.HELP_LINK="https://learn.microsoft.com/en-GB/azure/cognitive-services/speech-service/get-started-text-to-speech?tabs=windows%2Cterminal&pivots=programming-language-rest";var Lu=Ui,Ru=function(e){P(i,e);function i(t){var n;g(this,i);var r,a,o,s=(a=(r=t.directConnection)==null?void 0:r.azure)==null?void 0:a.translation,l=(o=t.directConnection)==null?void 0:o.azure;return n=O(this,i,[t,Ne.buildTranslationKeyVerificationDetails(s.region),Ne.buildTranslationHeaders.bind({},s==null?void 0:s.region),l]),n.insertKeyPlaceholderText="Azure Translate Subscription Key",n.keyHelpUrl="https://learn.microsoft.com/en-us/azure/api-management/api-management-subscriptions#create-and-manage-subscriptions-in-azure-portal",n.url="",n.url="https://api.cognitive.microsofttranslator.com/translate?api-version=3.0&to=".concat(s.language||"es"),n}return y(i,[{key:"preprocessBody",value:function(n){var r=n[n.length-1].text;if(r)return[{Text:r}]}},{key:"callServiceAPI",value:function(){var t=k(f().mark(function r(a,o){var s;return f().wrap(function(u){for(;;)switch(u.prev=u.next){case 0:if(this.requestSettings){u.next=2;break}throw new Error("Request settings have not been set up");case 2:s=this.preprocessBody(o),J.request(this,s,a);case 4:case"end":return u.stop()}},r,this)}));function n(r,a){return t.apply(this,arguments)}return n}()},{key:"extractResultData",value:function(){var t=k(f().mark(function r(a){var o;return f().wrap(function(l){for(;;)switch(l.prev=l.next){case 0:if(!Array.isArray(a)){l.next=2;break}return l.abrupt("return",{text:((o=a[0].translations)==null?void 0:o[0].text)||""});case 2:throw a.error;case 3:case"end":return l.stop()}},r)}));function n(r){return t.apply(this,arguments)}return n}()}]),i}(ce),Ir=function(){function e(){g(this,e)}return y(e,null,[{key:"storeFiles",value:function(){var i=k(f().mark(function n(r,a,o){var s,l,u,c;return f().wrap(function(h){for(;;)switch(h.prev=h.next){case 0:if(s=r.requestSettings.headers,s){h.next=3;break}return h.abrupt("return");case 3:return r.url="https://api.openai.com/v1/files",l=s[B.CONTENT_TYPE],delete s[B.CONTENT_TYPE],u=o.map(function(){var p=k(f().mark(function v(m){var b;return f().wrap(function(_){for(;;)switch(_.prev=_.next){case 0:return b=new FormData,_.abrupt("return",(b.append("purpose","assistants"),b.append("file",m),new Promise(function(x){x(ae.directFetch(r,b,"POST",!1))})));case 2:case"end":return _.stop()}},v)}));return function(v){return p.apply(this,arguments)}}()),h.prev=7,h.next=10,Promise.all(u);case 10:return c=h.sent.map(function(p){return p.id}),h.abrupt("return",(s[B.CONTENT_TYPE]=l,c));case 14:throw h.prev=14,h.t0=h.catch(7),s[B.CONTENT_TYPE]=l,B.displayError(a,h.t0),r.completionsHandlers.onFinish(),h.t0;case 17:case"end":return h.stop()}},n,null,[[7,14]])}));function t(n,r,a){return i.apply(this,arguments)}return t}()},{key:"getType",value:function(t,n){var r=t[n].path;return!r||r.endsWith("png")?"image":"any"}},{key:"getFiles",value:function(){var i=k(f().mark(function n(r,a){var o,s;return f().wrap(function(u){for(;;)switch(u.prev=u.next){case 0:return o=a.map(function(c){var d=c.fileId;return r.url="https://api.openai.com/v1/files/".concat(d,"/content"),new Promise(function(h){h(ae.directFetch(r,void 0,"GET",!1))})}),u.next=3,Promise.all(o);case 3:return s=u.sent.map(function(c,d){return new Promise(function(h){var p=new FileReader;p.readAsDataURL(c),p.onload=function(v){h({src:v.target.result,name:a[d].name,type:e.getType(a,d)})}})}),u.next=6,Promise.all(s);case 6:return u.abrupt("return",u.sent);case 7:case"end":return u.stop()}},n)}));function t(n,r){return i.apply(this,arguments)}return t}()},{key:"getFileName",value:function(t){var n=t.split("/");return n[n.length-1]}},{key:"getFileDetails",value:function(t,n){var r,a=[];return(r=n==null?void 0:n.text)!=null&&r.value&&t.content.forEach(function(o){var s,l;(l=(s=o.text)==null?void 0:s.annotations)==null||l.forEach(function(u){var c;u.text&&u.text.startsWith("sandbox:")&&(c=u.file_path)!=null&&c.file_id&&a.push({path:u.text,fileId:u.file_path.file_id,name:e.getFileName(u.text)})})}),n!=null&&n.image_file&&a.push({fileId:n.image_file.file_id}),a}},{key:"getFilesAndNewText",value:function(){var i=k(f().mark(function n(r,a,o,s){var l,u,c;return f().wrap(function(h){for(;;)switch(h.prev=h.next){case 0:if(h.t0=a.length>0,!h.t0){h.next=6;break}return h.next=4,e.getFiles(r,a);case 4:c=h.sent,(l=s==null?void 0:s.text)!=null&&l.value&&c.forEach(function(p,v){var m;if(p.src){var b=a[v].path;(m=s==null?void 0:s.text)!=null&&m.value&&b&&(s.text.value=s.text.value.replace(b,p.src))}});case 6:return h.abrupt("return",{files:c,text:(u=s==null?void 0:s.text)==null?void 0:u.value,role:o});case 7:case"end":return h.stop()}},n)}));function t(n,r,a,o){return i.apply(this,arguments)}return t}()},{key:"getFilesAndText",value:function(){var i=k(f().mark(function n(r,a,o){var s;return f().wrap(function(u){for(;;)switch(u.prev=u.next){case 0:return s=e.getFileDetails(a,o),u.next=3,e.getFilesAndNewText(r,s,a.role,o);case 3:return u.abrupt("return",u.sent);case 4:case"end":return u.stop()}},n)}));function t(n,r,a){return i.apply(this,arguments)}return t}()}]),e}(),jt=function(e){P(i,e);function i(t){var n,r,a;g(this,i);var o,s,l,u,c,d,h=JSON.parse(JSON.stringify(t.directConnection)),p=h.openAI;a=O(this,i,[t,ae.buildKeyVerificationDetails(),ae.buildHeaders,p]),a.insertKeyPlaceholderText="OpenAI API Key",a.keyHelpUrl="https://platform.openai.com/account/api-keys",a.url="",a.permittedErrorPrefixes=["Incorrect"],a.searchedForThreadId=!1,a.config={},a.newAssistantDetails={model:"gpt-4"},a.shouldFetchHistory=!1;var v=(o=h.openAI)==null?void 0:o.assistant;if(R(v)=="object"){a.config=v;var m=a.config,b=m.new_assistant,w=m.thread_id,_=m.load_thread_history;Object.assign(a.newAssistantDetails,b),w&&(a.sessionId=w),_&&(a.shouldFetchHistory=!0);var x=(l=(s=t.directConnection)==null?void 0:s.openAI)==null?void 0:l.assistant,N=x.function_handler;N&&(a._functionHandler=N)}else(u=h.openAI)!=null&&u.assistant&&(h.openAI.assistant=v);return(n=(c=a.requestSettings).headers)!==null&&n!==void 0||(c.headers={}),(r=(d=a.requestSettings.headers)["OpenAI-Beta"])!==null&&r!==void 0||(d["OpenAI-Beta"]="assistants=v1"),a.maxMessages=1,a.shouldFetchHistory&&a.sessionId&&(a.fetchHistory=a.fetchHistoryFunc.bind(de(a))),a}return y(i,[{key:"fetchHistoryFunc",value:function(){var t=k(f().mark(function r(){var a=this,o;return f().wrap(function(l){for(;;)switch(l.prev=l.next){case 0:return setTimeout(function(){return a.deepChat.disableSubmitButton()},2),l.prev=1,l.next=4,this.getThreadMessages(this.sessionId,!0);case 4:return o=l.sent,l.abrupt("return",(this.deepChat.disableSubmitButton(!1),o.reverse()));case 8:return l.prev=8,l.t0=l.catch(1),l.abrupt("return",[{error:"failed to fetch thread history"}]);case 11:case"end":return l.stop()}},r,this,[[1,8]])}));function n(){return t.apply(this,arguments)}return n}()},{key:"processMessage",value:function(n,r){var a=this.totalMessagesMaxCharLength||-1;return{content:Un.getCharacterLimitMessages(n,a)[0].text||"",role:"user",file_ids:r}}},{key:"createNewThreadMessages",value:function(n,r,a){var o=JSON.parse(JSON.stringify(n)),s=this.processMessage(r,a);return o.thread={messages:[s]},o}},{key:"callService",value:function(n,r,a){if(this.sessionId){this.url="".concat(i.THREAD_PREFIX,"/").concat(this.sessionId,"/messages");var o=this.processMessage(r,a);J.request(this,o,n)}else{this.url="".concat(i.THREAD_PREFIX,"/runs");var s=this.createNewThreadMessages(this.rawBody,r,a);J.request(this,s,n)}this.messages=n}},{key:"callServiceAPI",value:function(){var t=k(f().mark(function r(a,o,s){var l,u,c;return f().wrap(function(h){for(;;)switch(h.prev=h.next){case 0:if(this.requestSettings){h.next=2;break}throw new Error("Request settings have not been set up");case 2:if(!((l=(u=this.rawBody).assistant_id)!==null&&l!==void 0)){h.next=6;break}h.next=12;break;case 6:if(h.t0=this.config.assistant_id,h.t0){h.next=11;break}return h.next=10,this.createNewAssistant();case 10:h.t0=h.sent;case 11:u.assistant_id=h.t0;case 12:if(this.searchedForThreadId||this.searchPreviousMessagesForThreadId(a.messages),!s){h.next=19;break}return h.next=16,Ir.storeFiles(this,a,s);case 16:h.t1=h.sent,h.next=20;break;case 19:h.t1=void 0;case 20:c=h.t1,this.requestSettings.method="POST",this.callService(a,o,c);case 22:case"end":return h.stop()}},r,this)}));function n(r,a,o){return t.apply(this,arguments)}return n}()},{key:"createNewAssistant",value:function(){var t=k(f().mark(function r(){var a;return f().wrap(function(s){for(;;)switch(s.prev=s.next){case 0:return s.prev=0,this.url=i.NEW_ASSISTANT_URL,s.next=4,ae.directFetch(this,JSON.parse(JSON.stringify(this.newAssistantDetails)),"POST");case 4:return a=s.sent,s.abrupt("return",(this.config.assistant_id=a.id,this.config.assistant_id));case 8:s.prev=8,s.t0=s.catch(0),console.error(s.t0),console.error("Failed to create a new assistant");case 11:case"end":return s.stop()}},r,this,[[0,8]])}));function n(){return t.apply(this,arguments)}return n}()},{key:"searchPreviousMessagesForThreadId",value:function(n){var r=n.find(function(a){return a._sessionId});r&&(this.sessionId=r._sessionId),this.searchedForThreadId=!0}},{key:"extractResultData",value:function(){var t=k(f().mark(function r(a){var o,s,l;return f().wrap(function(c){for(;;)switch(c.prev=c.next){case 0:if(!a.error){c.next=2;break}throw a.error.message;case 2:return c.next=4,this.assignThreadAndRun(a);case 4:return s="".concat(i.THREAD_PREFIX,"/").concat(this.sessionId,"/runs/").concat(this.run_id),l={method:"GET",headers:(o=this.requestSettings)==null?void 0:o.headers},c.abrupt("return",(J.executePollRequest(this,s,l,this.messages),{makingAnotherRequest:!0}));case 6:case"end":return c.stop()}},r,this)}));function n(r){return t.apply(this,arguments)}return n}()},{key:"assignThreadAndRun",value:function(){var t=k(f().mark(function r(a){var o;return f().wrap(function(l){for(;;)switch(l.prev=l.next){case 0:if(!this.sessionId){l.next=8;break}return this.url="".concat(i.THREAD_PREFIX,"/").concat(this.sessionId,"/runs"),l.next=4,ae.directFetch(this,JSON.parse(JSON.stringify(this.rawBody)),"POST");case 4:o=l.sent,this.run_id=o.id,l.next=9;break;case 8:this.sessionId=a.thread_id,this.run_id=a.id,this.messages&&(this.messages.messages[this.messages.messages.length-1]._sessionId=this.sessionId);case 9:case"end":return l.stop()}},r,this)}));function n(r){return t.apply(this,arguments)}return n}()},{key:"getThreadMessages",value:function(){var t=k(f().mark(function r(a){var o=this,s,l,u,c,d,h=arguments;return f().wrap(function(v){for(;;)switch(v.prev=v.next){case 0:return s=h.length>1&&h[1]!==void 0?h[1]:!1,this.url="".concat(i.THREAD_PREFIX,"/").concat(a,"/messages"),v.next=4,ae.directFetch(this,{},"GET");case 4:if(c=v.sent,v.t0=!s&&this.deepChat.responseInterceptor,!v.t0){v.next=10;break}return v.next=9,(u=(l=this.deepChat).responseInterceptor)==null?void 0:u.call(l,c);case 9:c=v.sent;case 10:return d=(s?c.data:[c.data[0]]).map(function(){var m=k(f().mark(function b(w){var _;return f().wrap(function(N){for(;;)switch(N.prev=N.next){case 0:return _=w.content.find(function(M){return!!M.text||!!M.image_file}),N.next=3,Ir.getFilesAndText(o,w,_);case 3:return N.abrupt("return",N.sent);case 4:case"end":return N.stop()}},b)}));return function(b){return m.apply(this,arguments)}}()),v.abrupt("return",Promise.all(d));case 12:case"end":return v.stop()}},r,this)}));function n(r){return t.apply(this,arguments)}return n}()},{key:"extractPollResultData",value:function(){var t=k(f().mark(function r(a){var o,s,l,u,c,d,h,p,v,m,b;return f().wrap(function(_){for(;;)switch(_.prev=_.next){case 0:if(u=a.status,c=a.required_action,!(u==="queued"||u==="in_progress")){_.next=3;break}return _.abrupt("return",{timeoutMS:i.POLLING_TIMEOUT_MS});case 3:if(!(u==="completed"&&this.messages)){_.next=11;break}return _.next=6,this.getThreadMessages(a.thread_id);case 6:return d=_.sent,h=d[0],p=h.text,v=h.files,_.abrupt("return",{text:p,_sessionId:this.sessionId,files:v});case 11:if(m=(o=c==null?void 0:c.submit_tool_outputs)==null?void 0:o.tool_calls,!(u==="requires_action"&&m)){_.next=22;break}return _.next=15,this.handleTools(m);case 15:return b=_.sent,_.next=18,(l=(s=this.deepChat).responseInterceptor)==null?void 0:l.call(s,b);case 18:if(_.t0=_.sent,_.t0){_.next=21;break}_.t0=b;case 21:return _.abrupt("return",_.t0);case 22:throw Error("Thread run status: ".concat(u));case 23:case"end":return _.stop()}},r,this)}));function n(r){return t.apply(this,arguments)}return n}()},{key:"handleTools",value:function(){var t=k(f().mark(function r(a){var o,s,l;return f().wrap(function(c){for(;;)switch(c.prev=c.next){case 0:if(this._functionHandler){c.next=2;break}throw Error("Please define the `function_handler` property inside the [openAI](https://deepchat.dev/docs/directConnection/openAI#Assistant) object.");case 2:return o=a.map(function(d){return{name:d.function.name,arguments:d.function.arguments}}),c.next=5,this._functionHandler(o);case 5:if(s=c.sent,!(!Array.isArray(s)||s.find(function(d){return typeof d!="string"})||a.length!==s.length)){c.next=8;break}throw Error("Response must contain an array of strings for each individual function/tool_call, see https://deepchat.dev/docs/directConnection/OpenAI/#assistant-functions.");case 8:return l=s.map(function(d,h){return{tool_call_id:a[h].id,output:d}}),this.url="".concat(i.THREAD_PREFIX,"/").concat(this.sessionId,"/runs/").concat(this.run_id,"/submit_tool_outputs"),c.next=12,ae.directFetch(this,{tool_outputs:l},"POST");case 12:return c.abrupt("return",{timeoutMS:i.POLLING_TIMEOUT_MS});case 13:case"end":return c.stop()}},r,this)}));function n(r){return t.apply(this,arguments)}return n}()}]),i}(ce);jt.THREAD_PREFIX="https://api.openai.com/v1/threads";jt.NEW_ASSISTANT_URL="https://api.openai.com/v1/assistants";jt.POLLING_TIMEOUT_MS=800;var Ou=jt,Bt=function(e){P(i,e);function i(t){var n;g(this,i);var r,a=t.directConnection,o=a==null?void 0:a.openAI,s={images:{files:{acceptedFormats:".png",maxNumberOfFiles:2}}};n=O(this,i,[t,ae.buildKeyVerificationDetails(),ae.buildHeaders,o,s]),n.insertKeyPlaceholderText="OpenAI API Key",n.keyHelpUrl="https://platform.openai.com/account/api-keys",n.introPanelMarkUp=`
    <div style="width: 100%; text-align: center; margin-left: -10px"><b>OpenAI DALL·E</b></div>
    <p><b>Insert text</b> to generate an image.</p>
    <p><b>Upload 1</b> PNG image to generate its variation and optionally insert text to specify the change.</p>
    <p><b>Upload 2</b> PNG images where the second is a copy of the first with a transparent area where the edit should
      take place and text to specify the edit.</p>
    <p>Click <a href="https://platform.openai.com/docs/guides/images/introduction">here</a> for more info.</p>`,n.url="",n.permittedErrorPrefixes=["Incorrect","Invalid input image"];var l=(r=a==null?void 0:a.openAI)==null?void 0:r.images;if(n.camera){var u=R(l)=="object"&&l.size?Number.parseInt(l.size):1024;n.camera.files={dimensions:{width:u,height:u}}}return R(l)=="object"&&Object.assign(n.rawBody,l),n.canSendMessage=i.canFileSendMessage,n}return y(i,[{key:"preprocessBody",value:function(n,r){var a=JSON.parse(JSON.stringify(n));return r&&r!==""&&(a.prompt=r),a}},{key:"callApiWithImage",value:function(n,r,a){var o,s,l,u=(s=(o=r[r.length-1])==null?void 0:o.text)==null?void 0:s.trim();if(a[1]||u&&u!==""){this.url=i.IMAGE_EDIT_URL;var c=this.preprocessBody(this.rawBody,u);l=i.createFormDataBody(c,a[0],a[1])}else this.url=i.IMAGE_VARIATIONS_URL,l=i.createFormDataBody(this.rawBody,a[0]);B.tempRemoveContentHeader(this.requestSettings,J.request.bind(this,this,l,n),!1)}},{key:"callServiceAPI",value:function(){var t=k(f().mark(function r(a,o,s){var l,u;return f().wrap(function(d){for(;;)switch(d.prev=d.next){case 0:if((l=this.requestSettings)!=null&&l.headers){d.next=2;break}throw new Error("Request settings have not been set up");case 2:if(!(s!=null&&s[0])){d.next=6;break}this.callApiWithImage(a,o,s),d.next=11;break;case 6:if(this.requestSettings){d.next=8;break}throw new Error("Request settings have not been set up");case 8:this.url=i.IMAGE_GENERATION_URL,u=this.preprocessBody(this.rawBody,o[o.length-1].text),J.request(this,u,a);case 11:case"end":return d.stop()}},r,this)}));function n(r,a,o){return t.apply(this,arguments)}return n}()},{key:"extractResultData",value:function(){var t=k(f().mark(function r(a){return f().wrap(function(s){for(;;)switch(s.prev=s.next){case 0:if(!a.error){s.next=2;break}throw a.error.message;case 2:return s.abrupt("return",{files:a.data.map(function(l){return l.url?{src:l.url,type:"image"}:{src:"".concat(ct).concat(l.b64_json),type:"image"}})});case 3:case"end":return s.stop()}},r)}));function n(r){return t.apply(this,arguments)}return n}()}],[{key:"canFileSendMessage",value:function(n,r){return!!(r!=null&&r[0])||!!(n&&n.trim()!=="")}},{key:"createFormDataBody",value:function(n,r,a){var o=new FormData;return o.append("image",r),a&&o.append("mask",a),Object.keys(n).forEach(function(s){o.append(s,String(n[s]))}),o}}]),i}(ce);Bt.IMAGE_GENERATION_URL="https://api.openai.com/v1/images/generations";Bt.IMAGE_VARIATIONS_URL="https://api.openai.com/v1/images/variations";Bt.IMAGE_EDIT_URL="https://api.openai.com/v1/images/edits";var Pu=Bt,Nu=function(e){P(i,e);function i(t){var n,r,a;g(this,i);var o,s,l,u,c=JSON.parse(JSON.stringify(t.directConnection)),d=c.openAI;a=O(this,i,[t,ae.buildKeyVerificationDetails(),ae.buildHeaders,d]),a.insertKeyPlaceholderText="OpenAI API Key",a.keyHelpUrl="https://platform.openai.com/account/api-keys",a.url="https://api.openai.com/v1/chat/completions",a.permittedErrorPrefixes=["Incorrect"],a.asyncCallInProgress=!1,a._systemMessage=i.generateSystemMessage("You are a helpful assistant.");var h=(o=c.openAI)==null?void 0:o.chat;if(R(h)=="object"){h.system_prompt&&(a._systemMessage=i.generateSystemMessage(h.system_prompt));var p=(l=(s=t.directConnection)==null?void 0:s.openAI)==null?void 0:l.chat,v=p.function_handler;v&&(a._functionHandler=v),a.cleanConfig(h),Object.assign(a.rawBody,h)}return(n=a.maxMessages)!==null&&n!==void 0||(a.maxMessages=-1),(r=(u=a.rawBody).model)!==null&&r!==void 0||(u.model="gpt-3.5-turbo"),a}return y(i,[{key:"cleanConfig",value:function(n){delete n.system_prompt,delete n.function_handler}},{key:"preprocessBody",value:function(n,r){var a,o=JSON.parse(JSON.stringify(n)),s=Un.getCharacterLimitMessages(r,this.totalMessagesMaxCharLength?this.totalMessagesMaxCharLength-this._systemMessage.content.length:-1).map(function(l){return{content:i.getContent(l),role:l.role===F.USER_ROLE?"user":"assistant"}});return r.find(function(l){return l.files&&l.files.length>0})&&((a=o.max_tokens)!==null&&a!==void 0||(o.max_tokens=300)),o.messages=[this._systemMessage].concat(di(s)),o}},{key:"callServiceAPI",value:function(){var t=k(f().mark(function r(a,o){var s,l;return f().wrap(function(c){for(;;)switch(c.prev=c.next){case 0:if(this.requestSettings){c.next=2;break}throw new Error("Request settings have not been set up");case 2:s=this.preprocessBody(this.rawBody,o),l=this.deepChat.stream,l&&(R(l)!="object"||!l.simulation)||s.stream?(s.stream=!0,re.request(this,s,a)):J.request(this,s,a);case 4:case"end":return c.stop()}},r,this)}));function n(r,a){return t.apply(this,arguments)}return n}()},{key:"extractResultData",value:function(){var t=k(f().mark(function r(a,o,s){var l,u,c,d;return f().wrap(function(p){for(;;)switch(p.prev=p.next){case 0:if(!a.error){p.next=2;break}throw a.error.message;case 2:return p.abrupt("return",(u=(l=a.choices)==null?void 0:l[0])!=null&&u.delta?this.extractStreamResult(a.choices[0],o,s):(d=(c=a.choices)==null?void 0:c[0])!=null&&d.message?a.choices[0].message.tool_calls?this.handleTools(a.choices[0].message,o,s):{text:a.choices[0].message.content}:{text:""});case 3:case"end":return p.stop()}},r,this)}));function n(r,a,o){return t.apply(this,arguments)}return n}()},{key:"extractStreamResult",value:function(){var t=k(f().mark(function r(a,o,s){var l=this,u,c,d;return f().wrap(function(p){for(;;)switch(p.prev=p.next){case 0:if(u=a.delta,c=a.finish_reason,c!=="tool_calls"){p.next=7;break}return this.asyncCallInProgress=!0,d={tool_calls:this._streamToolCalls},p.abrupt("return",(this._streamToolCalls=void 0,this.handleTools(d,o,s)));case 7:u!=null&&u.tool_calls&&(this._streamToolCalls?u.tool_calls.forEach(function(v,m){l._streamToolCalls&&(l._streamToolCalls[m].function.arguments+=v.function.arguments)}):this._streamToolCalls=u.tool_calls);case 8:return p.abrupt("return",{text:(u==null?void 0:u.content)||""});case 9:case"end":return p.stop()}},r,this)}));function n(r,a,o){return t.apply(this,arguments)}return n}()},{key:"handleTools",value:function(){var t=k(f().mark(function r(a,o,s){var l,u,c,d,h,p,v,m,b,w;return f().wrap(function(x){for(;;)switch(x.prev=x.next){case 0:if(!(!a.tool_calls||!o||!s||!this._functionHandler)){x.next=2;break}throw Error("Please define the `function_handler` property inside the [openAI](https://deepchat.dev/docs/directConnection/openAI#Chat) object.");case 2:return p=JSON.parse(JSON.stringify(s)),v=a.tool_calls.map(function(N){return{name:N.function.name,arguments:N.function.arguments}}),x.next=6,(l=this._functionHandler)==null?void 0:l.call(this,v);case 6:if(m=x.sent,!m.text){x.next=15;break}return b={text:m.text},x.next=11,(c=(u=this.deepChat).responseInterceptor)==null?void 0:c.call(u,b);case 11:if(x.t0=x.sent,x.t0){x.next=14;break}x.t0=b;case 14:return x.abrupt("return",x.t0);case 15:if(p.messages.push({tool_calls:a.tool_calls,role:"assistant",content:null}),!(Array.isArray(m)&&!m.find(function(N){return typeof N!="string"})||v.length===m.length)){x.next=35;break}return m.forEach(function(N,M){var j,G=(j=a.tool_calls)==null?void 0:j[M];p==null||p.messages.push({role:"tool",tool_call_id:G==null?void 0:G.id,name:G==null?void 0:G.function.name,content:N.response})}),delete p.tools,delete p.tool_choice,delete p.stream,x.prev=17,x.next=20,o==null?void 0:o(p).then(function(N){return B.processResponseByType(N)});case 20:return w=x.sent,x.next=23,(h=(d=this.deepChat).responseInterceptor)==null?void 0:h.call(d,w);case 23:if(x.t1=x.sent,x.t1){x.next=26;break}x.t1=w;case 26:if(w=x.t1,!w.error){x.next=29;break}throw w.error.message;case 29:return x.abrupt("return",{text:w.choices[0].message.content||""});case 32:throw x.prev=32,x.t2=x.catch(17),this.asyncCallInProgress=!1,x.t2;case 35:throw Error("Response object must either be {response: string}[] for each individual function or {text: string} for a direct response, see https://deepchat.dev/docs/directConnection/OpenAI#FunctionHandler.");case 36:case"end":return x.stop()}},r,this,[[17,32]])}));function n(r,a,o){return t.apply(this,arguments)}return n}()}],[{key:"generateSystemMessage",value:function(n){return{role:"system",content:n}}},{key:"getContent",value:function(n){if(n.files&&n.files.length>0){var r=n.files.map(function(a){return{type:"image_url",image_url:{url:a.src}}});return n.text&&n.text.trim().length>0&&r.unshift({type:"text",text:n.text}),r}return n.text}}]),i}(ce),Du=function(e){P(i,e);function i(t){var n,r;g(this,i);var a,o=JSON.parse(JSON.stringify(t.directConnection)),s=(a=o.cohere)==null?void 0:a.chat,l=o.cohere;return r=O(this,i,[t,"https://api.cohere.ai/v1/chat","Ask me anything!",s,l]),R(s)=="object"&&Object.assign(r.rawBody,s),(n=r.maxMessages)!==null&&n!==void 0||(r.maxMessages=-1),r}return y(i,[{key:"preprocessBody",value:function(n,r){var a=JSON.parse(JSON.stringify(n)),o=r.filter(function(s){return s.text});return a.query=o[o.length-1].text,a.chat_history=o.slice(0,o.length-1).map(function(s){return{text:s.text,user_name:s.role==="ai"?"CHATBOT":"USER"}}),a}},{key:"callServiceAPI",value:function(){var t=k(f().mark(function r(a,o){var s;return f().wrap(function(u){for(;;)switch(u.prev=u.next){case 0:if(this.requestSettings){u.next=2;break}throw new Error("Request settings have not been set up");case 2:s=this.preprocessBody(this.rawBody,o),J.request(this,s,a);case 4:case"end":return u.stop()}},r,this)}));function n(r,a){return t.apply(this,arguments)}return n}()},{key:"extractResultData",value:function(){var t=k(f().mark(function r(a){return f().wrap(function(s){for(;;)switch(s.prev=s.next){case 0:if(!a.message){s.next=2;break}throw a.message;case 2:return s.abrupt("return",{text:a.text});case 3:case"end":return s.stop()}},r)}));function n(r){return t.apply(this,arguments)}return n}()}]),i}(Gn),Fu=function(){function e(){g(this,e)}return y(e,null,[{key:"create",value:function(t){var n=t.directConnection,r=t.request,a=t.demo,o=t.webModel;if(o)return new Vn(t);if(n){if(n.openAI)return n.openAI.images?new Pu(t):n.openAI.speechToText?new Cu(t):n.openAI.textToSpeech?new Eu(t):n.openAI.assistant?new Ou(t):new Nu(t);if(n.assemblyAI)return new Tu(t);if(n.cohere)return n.cohere.textGeneration?new Su(t):n.cohere.summarization?new xu(t):new Du(t);if(n.huggingFace)return n.huggingFace.textGeneration?new vu(t):n.huggingFace.summarization?new gu(t):n.huggingFace.translation?new ku(t):n.huggingFace.fillMask?new wu(t):n.huggingFace.questionAnswer?new mu(t):n.huggingFace.audioSpeechRecognition?new fu(t):n.huggingFace.audioClassification?new cu(t):n.huggingFace.imageClassification?new du(t):new yu(t);if(n.azure){if(n.azure.speechToText)return new Lu(t);if(n.azure.textToSpeech)return new Iu(t);if(n.azure.summarization)return new Au(t);if(n.azure.translation)return new Ru(t)}if(n.stabilityAI)return n.stabilityAI.imageToImage?new bu(t):n.stabilityAI.imageToImageUpscale?new hu(t):n.stabilityAI.imageToImageMasking?new pu(t):new _u(t)}return r?new At(t):new At(t,void 0,a||!0)}}]),e}(),Hi=function(){function e(){g(this,e)}return y(e,null,[{key:"appendStyleSheetToHead",value:function(){var t=document.getElementsByTagName("head")[0];if(!Array.from(t.getElementsByTagName("link")).some(function(r){return r.getAttribute("href")===e.FONT_URL})){var n=document.createElement("link");n.rel="stylesheet",n.href=e.FONT_URL,t.appendChild(n)}}}]),e}();Hi.FONT_URL="https://fonts.googleapis.com/css2?family=Inter:wght@400;600&display=swap";var ju=Hi,Vi=y(function e(){g(this,e)});Vi.attibutes={string:function(i){return i},number:function(i){return parseFloat(i)},boolean:function(i){return i==="true"},object:function(i){return JSON.parse(i)},array:function(i){return JSON.parse(i)},function:function(i){return new Function("return ".concat(i))()}};function z(e){return function(i,t){Object.defineProperty(i,t,{});var n=i.constructor,r=t.toLocaleLowerCase();n._attributes_[r]=Vi.attibutes[e],n._attributeToProperty_[r]=t}}var Bu=function(){function e(){g(this,e)}return y(e,null,[{key:"colorToHex",value:function(t){var n=document.createElement("div");return n.style.color=t,document.body.appendChild(n),"#".concat(window.getComputedStyle(n).color.match(/\d+/g).map(function(r){return parseInt(r).toString(16).padStart(2,"0")}).join(""))}},{key:"set",value:function(t,n){var r,a,o,s;if((a=(r=n==null?void 0:n.loading)==null?void 0:r.bubble)!=null&&a.color){var l=e.colorToHex((s=(o=n==null?void 0:n.loading)==null?void 0:o.bubble)==null?void 0:s.color);t.style.setProperty("--message-dots-color",l),t.style.setProperty("--message-dots-color-fade","".concat(l,"33"))}else t.style.setProperty("--message-dots-color","#848484"),t.style.setProperty("--message-dots-color-fade","#55555533")}}]),e}(),qu=function(){function e(i,t,n){g(this,e),this._isDisplayed=!1,i?(this._elementRef=this.createIntroPanelWithChild(i,n),this._isDisplayed=!0):t&&(this._elementRef=this.createInternalIntroPanel(t,n),this._isDisplayed=!0)}return y(e,[{key:"createIntroPanelWithChild",value:function(t,n){var r=e.createIntroPanel(n);return t.style.display==="none"&&(t.style.display="block"),r.appendChild(t),r}},{key:"createInternalIntroPanel",value:function(t,n){var r=e.createIntroPanel(n);return r.id="internal-intro-panel",r.innerHTML=t,r}},{key:"hide",value:function(){this._isDisplayed&&this._elementRef&&(this._elementRef.style.display="none",this._isDisplayed=!1)}},{key:"display",value:function(){!this._isDisplayed&&this._elementRef&&(this._elementRef.style.display="",this._isDisplayed=!0)}}],[{key:"createIntroPanel",value:function(t){var n=document.createElement("div");return n.classList.add("intro-panel"),Object.assign(n.style,t),n}}]),e}(),zu=function(){function e(){g(this,e)}return y(e,null,[{key:"getText",value:function(t,n){var r;if(!t.directConnection&&!t.request&&!t.webModel&&!t.demo)return`Connect to any API using the [request](https://deepchat.dev/docs/connect#Request)
        property or a popular service via
        [directConnection](https://deepchat.dev/docs/directConnection/#directConnection).
        
 Host AI entirely on your browser via a [webModel](https://deepchat.dev/docs/webModel).
        
 To get started checkout the [Start](https://deepchat.dev/start) page and
        live code [examples](https://deepchat.dev/examples/frameworks).
        
 To remove this message set the [demo](https://deepchat.dev/docs/demo#demo) property to true.`;if(t.directConnection){if(!n.isDirectConnection())return`Please define a valid service inside
          the [directConnection](https://deepchat.dev/docs/directConnection/#directConnection) object.`;var a=(r=t.directConnection.openAI)==null?void 0:r.chat;if(R(a)=="object"&&a.tools&&!a.function_handler)return"Please define the `function_handler` property inside the openAI [chat](https://deepchat.dev/docs/directConnection/openAI#Chat) object."}else if(t.request&&!t.request.url&&!t.request.handler)return"Please define a `url` or a `handler` property inside the [request](https://deepchat.dev/docs/connect#Request) object.";return null}}]),e}(),Uu=`<?xml version="1.0" encoding="iso-8859-1"?>
<svg version="1.1" xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink" 
	 viewBox="50 30 420 450" xml:space="preserve">
<g filter="brightness(0) saturate(100%) invert(16%) sepia(0%) saturate(1942%) hue-rotate(215deg) brightness(99%) contrast(93%)">
	<g>
		<path d="M447.933,103.629c-0.034-3.076-1.224-6.09-3.485-8.352L352.683,3.511c-0.004-0.004-0.007-0.005-0.011-0.008
			C350.505,1.338,347.511,0,344.206,0H89.278C75.361,0,64.04,11.32,64.04,25.237v461.525c0,13.916,11.32,25.237,25.237,25.237
			h333.444c13.916,0,25.237-11.32,25.237-25.237V103.753C447.96,103.709,447.937,103.672,447.933,103.629z M356.194,40.931
			l50.834,50.834h-49.572c-0.695,0-1.262-0.567-1.262-1.262V40.931z M423.983,486.763c0,0.695-0.566,1.261-1.261,1.261H89.278
			c-0.695,0-1.261-0.566-1.261-1.261V25.237c0-0.695,0.566-1.261,1.261-1.261h242.94v66.527c0,13.916,11.322,25.239,25.239,25.239
			h66.527V486.763z"/>
	</g>
</g>
<g>
	<g>
		<path d="M362.088,164.014H149.912c-6.62,0-11.988,5.367-11.988,11.988c0,6.62,5.368,11.988,11.988,11.988h212.175
			c6.62,0,11.988-5.368,11.988-11.988C374.076,169.381,368.707,164.014,362.088,164.014z"/>
	</g>
</g>
<g>
	<g>
		<path d="M362.088,236.353H149.912c-6.62,0-11.988,5.368-11.988,11.988c0,6.62,5.368,11.988,11.988,11.988h212.175
			c6.62,0,11.988-5.368,11.988-11.988C374.076,241.721,368.707,236.353,362.088,236.353z"/>
	</g>
</g>
<g>
	<g>
		<path d="M362.088,308.691H149.912c-6.62,0-11.988,5.368-11.988,11.988c0,6.621,5.368,11.988,11.988,11.988h212.175
			c6.62,0,11.988-5.367,11.988-11.988C374.076,314.06,368.707,308.691,362.088,308.691z"/>
	</g>
</g>
<g>
	<g>
		<path d="M256,381.031H149.912c-6.62,0-11.988,5.368-11.988,11.988c0,6.621,5.368,11.988,11.988,11.988H256
			c6.62,0,11.988-5.367,11.988-11.988C267.988,386.398,262.62,381.031,256,381.031z"/>
	</g>
</g>
</svg>`,Hu=function(){function e(){g(this,e)}return y(e,null,[{key:"createImage",value:function(t,n){var r=new Image;return r.src=t.src,ye.scrollDownOnImageLoad(r.src,n),ye.processContent("image",r,r.src,t.name)}},{key:"addNewImageMessage",value:function(){var i=k(f().mark(function n(r,a,o){var s,l;return f().wrap(function(c){for(;;)switch(c.prev=c.next){case 0:s=e.createImage(a,r.elementRef),l=r.createNewMessageElement("",o),l.bubbleElement.appendChild(s),l.bubbleElement.classList.add("image-message"),ye.addMessage(r,l,"image",o);case 2:case"end":return c.stop()}},n)}));function t(n,r,a){return i.apply(this,arguments)}return t}()},{key:"createAudioElement",value:function(t,n){var r=document.createElement("audio");return r.src=t.src,r.classList.add("audio-player"),r.controls=!0,we.IS_SAFARI&&(r.classList.add("audio-player-safari"),r.classList.add(n===F.USER_ROLE?"audio-player-safari-right":"audio-player-safari-left")),r}},{key:"addNewAudioMessage",value:function(t,n,r){var a=e.createAudioElement(n,r),o=t.createNewMessageElement("",r);o.bubbleElement.appendChild(a),o.bubbleElement.classList.add("audio-message"),ye.addMessage(t,o,"audio",r)}},{key:"createAnyFile",value:function(t){var n=document.createElement("div");n.classList.add("any-file-message-contents");var r=document.createElement("div");r.classList.add("any-file-message-icon-container");var a=pe.createSVGElement(Uu);a.classList.add("any-file-message-icon"),r.appendChild(a);var o=document.createElement("div");return o.classList.add("any-file-message-text"),o.textContent=t.name||ye.DEFAULT_FILE_NAME,n.appendChild(r),n.appendChild(o),ye.processContent("any",n,t.src,o.textContent)}},{key:"addNewAnyFileMessage",value:function(t,n,r){var a=t.createNewMessageElement("",r),o=e.createAnyFile(n);a.bubbleElement.classList.add("any-file-message-bubble"),a.bubbleElement.appendChild(o),ye.addMessage(t,a,"file",r)}},{key:"addMessages",value:function(t,n,r){n.forEach(function(a){var o,s;a.ref&&(a=ye.removeFileRef(a)),a.type==="audio"||(o=a.src)!=null&&o.startsWith("data:audio")?e.addNewAudioMessage(t,a,r):a.type==="image"||(s=a.src)!=null&&s.startsWith("data:image")?e.addNewImageMessage(t,a,r):e.addNewAnyFileMessage(t,a,r)})}}]),e}(),Vu=function(e){P(i,e);function i(t,n,r){var a;g(this,i);var o,s;a=O(this,i,[t]);var l=n.permittedErrorPrefixes,u=n.introPanelMarkUp,c=n.demo;return a._errorMessageOverrides=(o=t.errorMessages)==null?void 0:o.overrides,a._onClearMessages=Mt.onClearMessages.bind(de(a),t),a._onError=Mt.onError.bind(de(a),t),a._displayLoadingMessage=i.getDisplayLoadingMessage(t,n),a._permittedErrorPrefixes=l,a.addSetupMessageIfNeeded(t,n)||a.populateIntroPanel(r,u,t.introPanelStyle),a.addIntroductoryMessage(t,n),t.initialMessages&&a.populateInitialMessages(t.initialMessages),a._displayServiceErrorMessages=(s=t.errorMessages)==null?void 0:s.displayServiceErrorMessages,t.getMessages=function(){return JSON.parse(JSON.stringify(a.messages))},t.clearMessages=a.clearMessages.bind(de(a),n),t.refreshMessages=a.refreshTextMessages.bind(de(a)),t.scrollToBottom=he.scrollToBottom.bind(de(a),a.elementRef),t._addMessage=function(d,h){a.addNewMessage(V(V({},d),{},{sendUpdate:!!h}),!h)},n.isWebModel()&&n.setUpMessages(de(a)),c&&a.prepareDemo(c),t.textToSpeech&&xt.processConfig(t.textToSpeech,function(d){a.textToSpeech=d}),n.fetchHistory&&a.fetchHistory(n.fetchHistory),a}return y(i,[{key:"prepareDemo",value:function(n){R(n)=="object"&&(n.response&&(this.customDemoResponse=n.response),n.displayErrors&&(n.displayErrors.default&&this.addNewErrorMessage("",""),n.displayErrors.service&&this.addNewErrorMessage("service",""),n.displayErrors.speechToText&&this.addNewErrorMessage("speechToText","")),n.displayLoadingBubble&&this.addLoadingMessage())}},{key:"addSetupMessageIfNeeded",value:function(n,r){var a=zu.getText(n,r);if(a){var o=this.createAndAppendNewMessageElement(a,F.AI_ROLE);this.applyCustomStyles(o,F.AI_ROLE,!1)}return!!a}},{key:"addIntroductoryMessage",value:function(n,r){var a,o;n!=null&&n.shadowRoot&&(this._introMessage=n.introMessage);var s=this._introMessage;if(r!=null&&r.isWebModel()&&((a=s)!==null&&a!==void 0||(s=r.getIntroMessage(s))),s){var l;s!=null&&s.text?l=this.createAndAppendNewMessageElement(s.text,F.AI_ROLE):s!=null&&s.html&&(l=xn.add(this,s.html,F.AI_ROLE,this.messageElementRefs)),l&&(this.applyCustomStyles(l,F.AI_ROLE,!1,(o=this.messageStyles)==null?void 0:o.intro),l.outerContainer.classList.add("deep-chat-intro"))}}},{key:"removeIntroductoryMessage",value:function(){var n=this.messageElementRefs[0];n.outerContainer.classList.contains("deep-chat-intro")&&(n.outerContainer.remove(),this.messageElementRefs.shift())}},{key:"populateInitialMessages",value:function(n){var r=this;n.forEach(function(a){Re.processInitialMessageFile(a),r.addNewMessage(a,!0)}),setTimeout(function(){return he.scrollToBottom(r.elementRef)},0)}},{key:"fetchHistory",value:function(){var t=k(f().mark(function r(a){var o=this;return f().wrap(function(l){for(;;)switch(l.prev=l.next){case 0:return l.next=2,a();case 2:l.sent.forEach(function(u){u.error?o.addNewErrorMessage("service",u.error):o.addNewMessage(u,!0)}),setTimeout(function(){return he.scrollToBottom(o.elementRef)},0);case 4:case"end":return l.stop()}},r)}));function n(r){return t.apply(this,arguments)}return n}()},{key:"addNewMessage",value:function(n){var r=arguments.length>1&&arguments[1]!==void 0?arguments[1]:!1,a=i.createMessageContent(n),o={status:n.overwrite};if(!n.ignoreText&&a.text!==void 0&&n.text!==null&&(this.addNewTextMessage(a.text,a.role,o),!r&&this.textToSpeech&&a.role!==F.USER_ROLE&&xt.speak(a.text,this.textToSpeech)),a.files&&Array.isArray(a.files)&&Hu.addMessages(this,a.files,a.role),a.html!==void 0&&a.html!==null){var s=xn.add(this,a.html,a.role,this.messageElementRefs,o);Ct.isElementTemporary(s)&&delete a.html}this.isValidMessageContent(a)&&this.updateStateOnMessage(a,n.overwrite,n.sendUpdate,r)}},{key:"isValidMessageContent",value:function(n){return n.text||n.html||n.files&&n.files.length>0}},{key:"updateStateOnMessage",value:function(n,r){var a=arguments.length>2&&arguments[2]!==void 0?arguments[2]:!0,o=arguments.length>3&&arguments[3]!==void 0?arguments[3]:!1;r||this.messages.push(n),a&&this.sendClientUpdate(n,o)}},{key:"removeMessageOnError",value:function(){var n=this.messageElementRefs[this.messageElementRefs.length-1],r=n==null?void 0:n.bubbleElement;(r!=null&&r.classList.contains(Pe.MESSAGE_CLASS)&&r.textContent===""||i.isTemporaryElement(n))&&this.removeLastMessage()}},{key:"addNewErrorMessage",value:function(n,r){var a,o,s,l,u;this.removeMessageOnError();var c=i.createBaseElements(),d=c.outerContainer,h=c.bubbleElement;h.classList.add("error-message-text");var p=this.getPermittedMessage(r)||((a=this._errorMessageOverrides)==null?void 0:a[n])||((o=this._errorMessageOverrides)==null?void 0:o.default)||"Error, please try again.";this.renderText(h,p);var v=Et.extractParticularSharedStyles(["fontSize","fontFamily"],(s=this.messageStyles)==null?void 0:s.default);Et.applyCustomStylesToElements(c,!1,v),Et.applyCustomStylesToElements(c,!1,(l=this.messageStyles)==null?void 0:l.error),this.elementRef.appendChild(d),he.scrollToBottom(this.elementRef),this.textToSpeech&&xt.speak(p,this.textToSpeech),(u=this._onError)==null||u.call(this,p)}},{key:"getPermittedMessage",value:function(n){if(n){if(this._displayServiceErrorMessages)return n;if(typeof n=="string"&&this._permittedErrorPrefixes){var r=i.checkPermittedErrorPrefixes(this._permittedErrorPrefixes,n);if(r)return r}else if(Array.isArray(n)&&this._permittedErrorPrefixes)for(var a=0;a<n.length;a+=1){var o=i.checkPermittedErrorPrefixes(this._permittedErrorPrefixes,n[a]);if(o)return o}}}},{key:"removeError",value:function(){this.isLastMessageError()&&F.getLastMessageElement(this.elementRef).remove()}},{key:"addLoadingMessage",value:function(){var n;if(this._displayLoadingMessage){var r=this.createMessageElements("",F.AI_ROLE),a=r.outerContainer,o=r.bubbleElement;o.classList.add("loading-message-text");var s=document.createElement("div");s.classList.add("dots-flashing"),o.appendChild(s),this.applyCustomStyles(r,F.AI_ROLE,!1,(n=this.messageStyles)==null?void 0:n.loading),Bu.set(o,this.messageStyles),this.elementRef.appendChild(a),he.scrollToBottom(this.elementRef)}}},{key:"populateIntroPanel",value:function(n,r,a){(n||r)&&(this._introPanel=new qu(n,r,a),this._introPanel._elementRef&&(at.apply(this,this._introPanel._elementRef),this.elementRef.appendChild(this._introPanel._elementRef)))}},{key:"addMultipleFiles",value:function(){var t=k(f().mark(function r(a){return f().wrap(function(s){for(;;)switch(s.prev=s.next){case 0:return s.abrupt("return",Promise.all((a||[]).map(function(l){return new Promise(function(u){if(!l.type||l.type==="any"){var c=l.file.name||ye.DEFAULT_FILE_NAME;u({name:c,type:"any",ref:l.file})}else{var d=new FileReader;d.readAsDataURL(l.file),d.onload=function(){u({src:d.result,type:l.type,ref:l.file})}}})})));case 1:case"end":return s.stop()}},r)}));function n(r){return t.apply(this,arguments)}return n}()},{key:"clearMessages",value:function(n,r){var a,o,s=[];this.messageElementRefs.forEach(function(l){var u=l.bubbleElement.classList;u.contains("loading-message-text")||u.contains(Pe.MESSAGE_CLASS)?s.push(l):l.outerContainer.remove()}),Array.from(this.elementRef.children).forEach(function(l){var u,c=(u=l.children[0])==null?void 0:u.children[0];c!=null&&c.classList.contains("error-message-text")&&l.remove()}),this.messageElementRefs=s,r!==!1&&((a=this._introPanel)!=null&&a._elementRef&&this._introPanel.display(),this.addIntroductoryMessage()),this.messages.splice(0,this.messages.length),this.textElementsToText.splice(0,this.textElementsToText.length),(o=this._onClearMessages)==null||o.call(this),delete n.sessionId}}],[{key:"getDisplayLoadingMessage",value:function(n,r){var a;return r.websocket?!1:(a=n.displayLoadingBubble)!==null&&a!==void 0?a:!0}},{key:"checkPermittedErrorPrefixes",value:function(n,r){for(var a=0;a<n.length;a+=1)if(r.startsWith(n[a]))return r}}]),i}(Ni),dt=function(){function e(){g(this,e)}return y(e,null,[{key:"adjustInputPadding",value:function(t,n){n["inside-left"].length>0&&t.classList.add("text-input-inner-left-adjustment"),n["inside-right"].length>0&&t.classList.add("text-input-inner-right-adjustment")}},{key:"adjustForOutsideButton",value:function(t,n,r){r["outside-right"].length===0&&r["outside-left"].length>0?(t[0].classList.add(e.INPUT_OUTSIDE_LEFT_SMALL_ADJUSTMENT_CLASS),n.classList.add(e.INPUT_OUTSIDE_LEFT_SMALL_ADJUSTMENT_CLASS)):r["outside-left"].length===0&&r["outside-right"].length>0&&(t[3].classList.add(e.INPUT_OUTSIDE_RIGHT_SMALL_ADJUSTMENT_CLASS),n.classList.add(e.INPUT_OUTSIDE_RIGHT_SMALL_ADJUSTMENT_CLASS))}},{key:"adjustOutsideSubmit",value:function(t,n,r){if(!(r["inside-left"].length>0||r["inside-right"].length>0)){if(r["outside-right"].length===0&&r["outside-left"].length>0)return t[0].classList.add(e.INPUT_OUTSIDE_LEFT_ADJUSTMENT_CLASS),n.classList.add(e.INPUT_OUTSIDE_LEFT_ADJUSTMENT_CLASS),r["outside-left"].map(function(a){return a.button.elementRef.classList.add("submit-button-enlarged")});if(r["outside-left"].length===0&&r["outside-right"].length>0)return t[3].classList.add(e.INPUT_OUTSIDE_RIGHT_ADJUSTMENT_CLASS),n.classList.add(e.INPUT_OUTSIDE_RIGHT_ADJUSTMENT_CLASS),r["outside-right"].map(function(a){return a.button.elementRef.classList.add("submit-button-enlarged")})}}},{key:"set",value:function(t,n,r,a){e.adjustOutsideSubmit(n,r,a)||e.adjustForOutsideButton(n,r,a),e.adjustInputPadding(t,a)}}]),e}();dt.INPUT_OUTSIDE_LEFT_ADJUSTMENT_CLASS="text-input-container-left-adjustment";dt.INPUT_OUTSIDE_RIGHT_ADJUSTMENT_CLASS="text-input-container-right-adjustment";dt.INPUT_OUTSIDE_LEFT_SMALL_ADJUSTMENT_CLASS="text-input-container-left-small-adjustment";dt.INPUT_OUTSIDE_RIGHT_SMALL_ADJUSTMENT_CLASS="text-input-container-right-small-adjustment";var $u=dt,Tt=function(){function e(){g(this,e)}return y(e,null,[{key:"create",value:function(){return Array.from({length:4}).map(function(t,n){var r=document.createElement("div");return r.classList.add("input-button-container"),(n===0||n===3)&&r.classList.add("outer-button-container"),(n===1||n===2)&&r.classList.add("inner-button-container"),r})}},{key:"add",value:function(t,n){t.insertBefore(n[1],t.firstChild),t.insertBefore(n[0],t.firstChild),t.appendChild(n[2]),t.appendChild(n[3])}},{key:"getContainerIndex",value:function(t){return t==="outside-left"?0:t==="inside-left"?1:t==="inside-right"?2:3}},{key:"addButton",value:function(t,n,r){n.classList.add(r);var a=e.getContainerIndex(r);t[a].appendChild(n),a===3&&n.classList.add("outside-right")}}]),e}(),Lr=["camera","gifs","images","audio","mixedFiles","submit","microphone"],Ye=function(){function e(){g(this,e)}return y(e,null,[{key:"createTextElement",value:function(t){var n=document.createElement("div");return n.classList.add("text-button"),n.innerText=t,n}},{key:"createElement",value:function(t,n){return n?e.createTextElement(t):pe.createSVGElement(t)}},{key:"createCustomElement",value:function(t,n){var r,a,o,s,l=n==null?void 0:n[t];if((r=l==null?void 0:l.text)!=null&&r.content)return e.createElement((a=l==null?void 0:l.text)==null?void 0:a.content,!0);if((o=l==null?void 0:l.svg)!=null&&o.content)return e.createElement((s=l==null?void 0:l.svg)==null?void 0:s.content,!1)}},{key:"processElement",value:function(t,n){n!=null&&n.classList.contains("text-button")||t.classList.add("input-button-svg")}},{key:"createSpecificStateElement",value:function(t,n,r){var a;return r&&(a=e.createCustomElement(n,r)),e.processElement(t,a),a}},{key:"create",value:function(t,n,r){var a={};if(!r)return e.processElement(t),a;var o=e.createSpecificStateElement(t,n[0],r);a[n[0]]=o;var s=o;return n.slice(1).forEach(function(l){s=e.createCustomElement(l,r)||s,a[l]=s}),a}}]),e}(),Gu=`<?xml version="1.0" encoding="utf-8"?>
<svg viewBox="0 0 32 32" version="1.1" xmlns="http://www.w3.org/2000/svg">
    <path d="M16 0c-8.836 0-16 7.163-16 16s7.163 16 16 16c8.837 0 16-7.163 16-16s-7.163-16-16-16zM16 30.032c-7.72 0-14-6.312-14-14.032s6.28-14 14-14 14 6.28 14 14-6.28 14.032-14 14.032zM23 15h-6v-6c0-0.552-0.448-1-1-1s-1 0.448-1 1v6h-6c-0.552 0-1 0.448-1 1s0.448 1 1 1h6v6c0 0.552 0.448 1 1 1s1-0.448 1-1v-6h6c0.552 0 1-0.448 1-1s-0.448-1-1-1z"></path>
</svg>`,Te=function(){function e(){g(this,e)}return y(e,null,[{key:"unsetAllCSS",value:function(t,n){var r,a;n.container&&ie.unsetAllCSSMouseStates(t,n.container),(r=n.svg)!=null&&r.styles&&ie.unsetAllCSSMouseStates(t.children[0],n.svg.styles),(a=n.text)!=null&&a.styles&&ie.unsetAllCSSMouseStates(t.children[0],n.text.styles)}},{key:"unsetActionCSS",value:function(t,n){var r,a;n.container&&ie.unsetActivityCSSMouseStates(t,n.container),(r=n.svg)!=null&&r.styles&&ie.unsetActivityCSSMouseStates(t.children[0],n.svg.styles),(a=n.text)!=null&&a.styles&&ie.unsetActivityCSSMouseStates(t.children[0],n.text.styles)}},{key:"setElementsCSS",value:function(t,n,r){var a,o,s,l,u;Object.assign(t.style,(a=n.container)==null?void 0:a[r]),Object.assign(t.children[0].style,(s=(o=n.svg)==null?void 0:o.styles)==null?void 0:s[r]),Object.assign(t.children[0].style,(u=(l=n.text)==null?void 0:l.styles)==null?void 0:u[r])}},{key:"setElementCssUpToState",value:function(t,n,r){e.setElementsCSS(t,n,"default"),r!=="default"&&(e.setElementsCSS(t,n,"hover"),r!=="hover"&&e.setElementsCSS(t,n,"click"))}}]),e}(),ht=function(){function e(i,t,n,r){g(this,e),this._mouseState={state:"default"},this.elementRef=i,this._customStyles=n,this.position=t,this.dropupText=r}return y(e,[{key:"buttonMouseLeave",value:function(t){this._mouseState.state="default",t&&(Te.unsetAllCSS(this.elementRef,t),Te.setElementsCSS(this.elementRef,t,"default"))}},{key:"buttonMouseEnter",value:function(t){this._mouseState.state="hover",t&&Te.setElementsCSS(this.elementRef,t,"hover")}},{key:"buttonMouseUp",value:function(t){t&&Te.unsetActionCSS(this.elementRef,t),this.buttonMouseEnter(t)}},{key:"buttonMouseDown",value:function(t){this._mouseState.state="click",t&&Te.setElementsCSS(this.elementRef,t,"click")}},{key:"setEvents",value:function(t){this.elementRef.onmousedown=this.buttonMouseDown.bind(this,t),this.elementRef.onmouseup=this.buttonMouseUp.bind(this,t),this.elementRef.onmouseenter=this.buttonMouseEnter.bind(this,t),this.elementRef.onmouseleave=this.buttonMouseLeave.bind(this,t)}},{key:"unsetCustomStateStyles",value:function(t){if(this._customStyles)for(var n=0;n<t.length;n+=1){var r=t[n],a=r&&this._customStyles[r];a&&Te.unsetActionCSS(this.elementRef,a)}}},{key:"reapplyStateStyle",value:function(t,n){if(this._customStyles){n&&this.unsetCustomStateStyles(n);var r=this._customStyles[t];r&&Te.setElementCssUpToState(this.elementRef,r,this._mouseState.state),this.setEvents(r)}}}]),e}(),Rr=function(){function e(){g(this,e)}return y(e,null,[{key:"focusItemWhenOnEdge",value:function(t,n){var r=n?t.children[0]:t.children[t.children.length-1];e.focusSiblingItem(r,t,n,!0)}},{key:"focusSiblingItem",value:function(t,n,r){var a=arguments.length>3&&arguments[3]!==void 0?arguments[3]:!1,o=a?t:t[r?"nextSibling":"previousSibling"];o?(t.dispatchEvent(new MouseEvent("mouseleave")),o.dispatchEvent(new MouseEvent("mouseenter"))):(t.dispatchEvent(new MouseEvent("mouseleave")),e.focusItemWhenOnEdge(n,r))}}]),e}(),Wu=function(){function e(){g(this,e)}return y(e,null,[{key:"addItemEvents",value:function(t,n,r,a){Si.add(n,a),n.addEventListener("click",function(){r.click()}),n.addEventListener("mouseenter",function(o){t.highlightedItem=o.target}),n.addEventListener("mouseleave",function(){t.highlightedItem=void 0})}},{key:"createItemText",value:function(t,n){var r=document.createElement("div");return Object.assign(r.style,n),r.classList.add("dropup-menu-item-text"),r.textContent=t||"File",r}},{key:"createItemIcon",value:function(t,n){var r=document.createElement("div");return Object.assign(r.style,n),r.classList.add("dropup-menu-item-icon"),r.appendChild(t.children[0]),r}},{key:"populateItem",value:function(t,n,r,a){var o=t.children[0];o.classList.contains("text-button")?n.appendChild(e.createItemText(o.textContent,a==null?void 0:a.text)):(n.appendChild(e.createItemIcon(t,a==null?void 0:a.iconContainer)),n.appendChild(e.createItemText(r,a==null?void 0:a.text)))}},{key:"createItem",value:function(t,n,r){var a,o=n.elementRef,s=n.dropupText,l=document.createElement("div");Object.assign(l.style,(a=r==null?void 0:r.item)==null?void 0:a.default),e.populateItem(o,l,s,r),l.classList.add("dropup-menu-item");var u=ie.processStateful((r==null?void 0:r.item)||{},{backgroundColor:"#f3f3f3"},{backgroundColor:"#ebebeb"});return e.addItemEvents(t,l,o,u),l}}]),e}(),Ku=function(){function e(i,t){var n=this;g(this,e);var r;this._isOpen=!0,this._styles=t,this.elementRef=e.createElement((r=this._styles)==null?void 0:r.container),this.close(),setTimeout(function(){return n.addWindowEvents(i)})}return y(e,[{key:"open",value:function(){this.elementRef.style.display="block",this._isOpen=!0}},{key:"close",value:function(){this._isOpen&&(this.elementRef.style.display="none",this._isOpen=!1)}},{key:"toggle",value:function(){this._isOpen?this.close():this.open()}},{key:"addItem",value:function(t){var n=Wu.createItem(this,t,this._styles);this.elementRef.appendChild(n)}},{key:"addWindowEvents",value:function(t){this.clickEvent=this.windowClick.bind(this,t),window.addEventListener("click",this.clickEvent),this.keyDownEvent=this.windowKeyDown.bind(this,t),window.addEventListener("keydown",this.keyDownEvent)}},{key:"windowClick",value:function(t,n){var r;!t.isConnected&&this.clickEvent?window.removeEventListener("click",this.clickEvent):t.parentElement!==((r=n.target.shadowRoot)==null?void 0:r.children[0])&&this.close()}},{key:"windowKeyDown",value:function(t,n){var r,a,o;!t.isConnected&&this.keyDownEvent?window.removeEventListener("keydown",this.keyDownEvent):this._isOpen&&(n.key===ne.ESCAPE?(this.close(),(r=this.highlightedItem)==null||r.dispatchEvent(new MouseEvent("mouseleave"))):n.key===ne.ENTER?((a=this.highlightedItem)==null||a.click(),(o=this.highlightedItem)==null||o.dispatchEvent(new MouseEvent("mouseleave"))):n.key===ne.ARROW_DOWN?Rr.focusSiblingItem(this.highlightedItem||this.elementRef.children[this.elementRef.children.length-1],this.elementRef,!0):n.key===ne.ARROW_UP&&Rr.focusSiblingItem(this.highlightedItem||this.elementRef.children[0],this.elementRef,!1))}}],[{key:"createElement",value:function(t){var n=document.createElement("div");return n.id="dropup-menu",Object.assign(n.style,t),n}}]),e}(),Or=function(e){P(i,e);function i(t,n){var r;g(this,i);var a;r=O(this,i,[i.createButtonElement(),void 0,{styles:(a=n==null?void 0:n.button)==null?void 0:a.styles}]);var o=r.createInnerElements(r._customStyles);return r._menu=new Ku(t,n==null?void 0:n.menu),r.addClickEvent(),r.buttonContainer=i.createButtonContainer(),r.elementRef.appendChild(o.styles),r.buttonContainer.appendChild(r.elementRef),r.elementRef.classList.add("dropup-icon","upload-file-button"),r.elementRef.children[0].id="dropup-icon",r.buttonContainer.appendChild(r._menu.elementRef),r.reapplyStateStyle("styles"),r.addContainerEvents(t),r}return y(i,[{key:"createInnerElements",value:function(n){return{styles:this.createInnerElement(i.createSVGIconElement(),"styles",n)}}},{key:"createInnerElement",value:function(n,r,a){return Ye.createSpecificStateElement(this.elementRef,r,a)||n}},{key:"addClickEvent",value:function(){this.elementRef.onclick=this._menu.toggle.bind(this._menu)}},{key:"addItem",value:function(n){this._menu.addItem(n)}},{key:"addContainerEvents",value:function(n){var r=this;n.addEventListener("click",function(a){a.target.classList.contains("dropup-icon")||r._menu.close()})}}],[{key:"createButtonElement",value:function(){var n=document.createElement("div");return n.classList.add("input-button"),n}},{key:"createSVGIconElement",value:function(){return pe.createSVGElement(Gu)}},{key:"createButtonContainer",value:function(){var n=document.createElement("div");return n.id="dropup-container",n}},{key:"getPosition",value:function(n,r){var a,o;return(a=r==null?void 0:r.button)!=null&&a.position?(o=r==null?void 0:r.button)==null?void 0:o.position:n["outside-left"].length>0&&n["outside-right"].length===0?"outside-right":"outside-left"}}]),i}(ht),Yu=function(){function e(){g(this,e)}return y(e,null,[{key:"addToDropup",value:function(t,n,r,a){var o=new Or(r,a);Lr.forEach(function(l){var u=n["dropup-menu"].findIndex(function(d){return d.buttonType===l}),c=n["dropup-menu"][u];c&&(o.addItem(c.button),n["dropup-menu"].splice(u,1))});var s=Or.getPosition(n,a);Tt.addButton(t,o.buttonContainer,s),n[s].push({})}},{key:"addToSideContainer",value:function(t,n){["inside-left","inside-right","outside-left","outside-right"].forEach(function(r){var a=r;n[a].forEach(function(o){Tt.addButton(t,o.button.elementRef,a)})})}},{key:"setPosition",value:function(t,n,r){var a=V(V({},t[n]),{},{buttonType:n});r.push(a),delete t[n]}},{key:"createPositionsObj",value:function(){return{"dropup-menu":[],"outside-left":[],"inside-left":[],"inside-right":[],"outside-right":[]}}},{key:"generatePositions",value:function(t){var n=e.createPositionsObj();Object.keys(t).forEach(function(a){var o,s=(o=t[a])==null?void 0:o.button.position;s&&e.setPosition(t,a,n[s])}),n["inside-right"].length===0&&t.submit&&e.setPosition(t,"submit",n["inside-right"]),n["outside-right"].length===0&&(t.submit?e.setPosition(t,"submit",n["outside-right"]):t.microphone?e.setPosition(t,"microphone",n["outside-right"]):t.camera&&e.setPosition(t,"camera",n["outside-right"])),t.submit&&e.setPosition(t,"submit",n["outside-left"].length===0?n["outside-left"]:n["inside-right"]),t.microphone&&e.setPosition(t,"microphone",n["outside-left"].length===0?n["outside-left"]:n["inside-right"]);var r=Object.keys(t);return r.length>1||n["dropup-menu"].length>0?Lr.forEach(function(a){t[a]&&n["dropup-menu"].push(V(V({},t[a]),{},{buttonType:a}))}):r.length===1&&e.setPosition(t,r[0],n["outside-right"].length===0?n["outside-right"]:n["outside-left"]),n}},{key:"addButtons",value:function(t,n,r,a){var o=e.generatePositions(n);return e.addToSideContainer(t,o),o["dropup-menu"].length>0&&e.addToDropup(t,o,r,a),o}}]),e}(),Ju=`<?xml version="1.0" encoding="utf-8"?>
<svg viewBox="0 0 24 24" fill="none" xmlns="http://www.w3.org/2000/svg">
<title>file</title>
<path d="M20 10.9696L11.9628 18.5497C10.9782 19.4783 9.64274 20 8.25028 20C6.85782 20 5.52239 19.4783 4.53777 18.5497C3.55315 17.6211 3 16.3616 3 15.0483C3 13.7351 3.55315 12.4756 4.53777 11.547L12.575 3.96687C13.2314 3.34779 14.1217 3 15.05 3C15.9783 3 16.8686 3.34779 17.525 3.96687C18.1814 4.58595 18.5502 5.4256 18.5502 6.30111C18.5502 7.17662 18.1814 8.01628 17.525 8.63535L9.47904 16.2154C9.15083 16.525 8.70569 16.6989 8.24154 16.6989C7.77738 16.6989 7.33224 16.525 7.00403 16.2154C6.67583 15.9059 6.49144 15.4861 6.49144 15.0483C6.49144 14.6106 6.67583 14.1907 7.00403 13.8812L14.429 6.88674" stroke="#000000" stroke-width="1.5" stroke-linecap="round" stroke-linejoin="round"/>
</svg>`,Zu=`<?xml version="1.0" encoding="utf-8"?>
<svg viewBox="0 0 24 24" xmlns="http://www.w3.org/2000/svg">
  <path d="M20,15.2928932 L20,5.5 C20,4.67157288 19.3284271,4 18.5,4 L5.5,4 C4.67157288,4 4,4.67157288 4,5.5 L4,12.2928932 L7.14644661,9.14644661 C7.34170876,8.95118446 7.65829124,8.95118446 7.85355339,9.14644661 L13.5,14.7928932 L16.1464466,12.1464466 C16.3417088,11.9511845 16.6582912,11.9511845 16.8535534,12.1464466 L20,15.2928932 Z M20,16.7071068 L16.5,13.2071068 L13.8535534,15.8535534 C13.6582912,16.0488155 13.3417088,16.0488155 13.1464466,15.8535534 L7.5,10.2071068 L4,13.7071068 L4,18.5 C4,19.3284271 4.67157288,20 5.5,20 L18.5,20 C19.3284271,20 20,19.3284271 20,18.5 L20,16.7071068 Z M3,5.5 C3,4.11928813 4.11928813,3 5.5,3 L18.5,3 C19.8807119,3 21,4.11928813 21,5.5 L21,18.5 C21,19.8807119 19.8807119,21 18.5,21 L5.5,21 C4.11928813,21 3,19.8807119 3,18.5 L3,5.5 Z M15,6 L17,6 C17.5522847,6 18,6.44771525 18,7 L18,9 C18,9.55228475 17.5522847,10 17,10 L15,10 C14.4477153,10 14,9.55228475 14,9 L14,7 C14,6.44771525 14.4477153,6 15,6 Z M15,7 L15,9 L17,9 L17,7 L15,7 Z"/>
</svg>
`,Xu=`<svg version="1.1" id="Layer_1" xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink" viewBox="-49.49 -49.49 593.87 593.87" stroke-width="3.95908" transform="rotate(0)">
  <g stroke-width="0"></g>
  <g stroke-linecap="round" stroke-linejoin="round" stroke-width="0.98977"></g>
  <g>
    <g>
      <g>
        <path d="M163.205,76.413v293.301c-3.434-3.058-7.241-5.867-11.486-8.339c-21.38-12.452-49.663-15.298-77.567-7.846 c-49.038,13.096-80.904,54.519-71.038,92.337c4.019,15.404,14.188,28.221,29.404,37.087c13.553,7.894,29.87,11.933,47.115,11.933 c9.962,0,20.231-1.356,30.447-4.087c42.74-11.406,72.411-44.344,72.807-77.654h0.011v-0.162c0.002-0.166,0-0.331,0-0.496V187.072 l290.971-67.3v178.082c-3.433-3.055-7.238-5.863-11.481-8.334c-21.385-12.452-49.654-15.308-77.567-7.846 c-49.038,13.087-80.904,54.519-71.038,92.356c4.019,15.385,14.183,28.212,29.404,37.067c13.548,7.894,29.875,11.933,47.115,11.933 c9.962,0,20.231-1.356,30.452-4.087c42.74-11.413,72.411-44.346,72.804-77.654h0.004v-0.065c0.003-0.236,0.001-0.469,0-0.704V0 L163.205,76.413z M104.999,471.779c-22.543,6.038-45.942,3.846-62.572-5.846c-10.587-6.163-17.591-14.817-20.255-25.038 c-7.144-27.375,18.452-58.029,57.062-68.346c8.409-2.25,16.938-3.346,25.188-3.346c13.87,0,26.962,3.115,37.389,9.192 c10.587,6.163,17.591,14.817,20.255,25.029c0.809,3.102,1.142,6.248,1.139,9.4v0.321h0.014 C162.99,437.714,139.082,462.678,104.999,471.779z M182.898,166.853V92.067l290.971-67.298v74.784L182.898,166.853z M415.677,399.923c-22.558,6.038-45.942,3.837-62.587-5.846c-10.587-6.163-17.587-14.817-20.25-25.019 c-7.144-27.385,18.452-58.058,57.058-68.365c8.414-2.25,16.942-3.346,25.192-3.346c13.875,0,26.962,3.115,37.385,9.192 c10.596,6.163,17.596,14.817,20.26,25.029v0.01c0.796,3.05,1.124,6.144,1.135,9.244v0.468h0.02 C473.668,365.851,449.763,390.814,415.677,399.923z">
        </path>
      </g>
    </g>
  </g>
</svg>`,Qu=`<?xml version="1.0" encoding="UTF-8" standalone="no"?>
<svg xmlns="http://www.w3.org/2000/svg" version="1.1" viewBox="0 0 5.9266752 5.6408391" height="21.31971" width="22.4">
  <g>
    <path d="m 5.2564627,1.548212 c -3.1136005,-0.4796804 -1.5568006,-0.2398402 0,0 z M 2.0001198,2.0922063 c 0.1556781,0 0.2657489,0.020893 0.3917849,0.080366 0.081154,0.038347 0.1153492,0.134065 0.076377,0.2138602 -0.038973,0.07979 -0.1363527,0.1134129 -0.2175069,0.075091 -0.078199,-0.036919 -0.1407455,-0.048792 -0.250655,-0.048792 -0.2260486,0 -0.3921482,0.2042182 -0.3921482,0.4801409 0,0.2761822 0.1663188,0.4810688 0.3921482,0.4810688 0.1117901,0 0.2064255,-0.046133 0.255659,-0.1284198 l 0.00162,-0.00389 V 3.0534032 l -0.098011,1.75e-4 c -0.081844,0 -0.1495979,-0.059305 -0.1612403,-0.1365887 l -0.00175,-0.023683 c 0,-0.08047 0.060311,-0.1470874 0.1389194,-0.1585331 l 0.024085,-0.00195 h 0.2612303 c 0.081842,0 0.149598,0.059305 0.1612404,0.1365891 l 0.00175,0.023683 -3.398e-4,0.3968809 v 0 l -0.00168,0.014211 v 0 l -0.00553,0.023034 v 0 l -0.00532,0.014145 c -0.098178,0.22826 -0.3236506,0.3528713 -0.5706303,0.3528713 -0.4240855,0 -0.7181621,-0.3622714 -0.7181621,-0.8016063 0,-0.4391857 0.2940275,-0.8006848 0.7181621,-0.8006848 z m 1.2034759,0.031275 c 0.081843,0 0.1495977,0.059305 0.1612403,0.1365891 l 0.00175,0.023683 v 1.2211775 c 0,0.088516 -0.07298,0.1602721 -0.1630073,0.1602721 -0.081841,0 -0.1495972,-0.059305 -0.1612397,-0.1365892 L 3.040589,3.5049308 V 2.2837527 c 0,-0.088516 0.07298,-0.1602721 0.1630067,-0.1602714 z m 0.7813442,0 0.5209469,0.00195 c 0.090025,3.048e-4 0.1627543,0.072306 0.1624458,0.1608234 -2.809e-4,0.08047 -0.06083,0.1468798 -0.1394772,0.158066 l -0.024092,0.00195 -0.3575326,-0.0013 v 0.4497782 l 0.2928918,2.27e-4 c 0.081842,0 0.1495979,0.059305 0.1612403,0.136589 l 0.00175,0.023683 c 0,0.080469 -0.06031,0.1470871 -0.1389193,0.1585393 l -0.024092,0.00195 -0.2928919,-2.336e-4 1.563e-4,0.2860316 c 0,0.080471 -0.06031,0.1470873 -0.1389193,0.1585395 l -0.024085,0.00195 c -0.081843,0 -0.1495979,-0.059305 -0.1612403,-0.1365826 l -0.00175,-0.023691 V 2.2841354 c 2.798e-4,-0.08047 0.060829,-0.1468797 0.1394758,-0.1580594 z"/>
    <path d="m 5.0894191,1.0943261 c 0,-0.21918999 -0.177687,-0.39686999 -0.396876,-0.39686999 h -3.43959 c -0.2191879,0 -0.391262,0.1777519 -0.3968759,0.39686999 l -0.027082,3.4379266 c 0.040152,0.2939927 0.4235456,0.409415 0.4235456,0.409415 l 3.4785583,-0.00851 c 0,0 0.3008506,-0.1402998 0.3236271,-0.4201576 0.042911,-0.5272495 0.034693,-1.6106146 0.034693,-3.4186761 z m -4.49792494,0 c 0,-0.36530999 0.29614504,-0.66145999 0.66145894,-0.66145999 h 3.43959 c 0.365314,0 0.66146,0.29615 0.66146,0.66145999 v 3.43959 c 0,0.36532 -0.296146,0.66146 -0.66146,0.66146 h -3.43959 c -0.3653139,0 -0.66145894,-0.29614 -0.66145894,-0.66146 z"/>
  </g>
</svg>
`,ec={images:{id:"upload-images-icon",svgString:Zu,dropupText:"Image"},gifs:{id:"upload-gifs-icon",svgString:Qu,dropupText:"GIF"},audio:{id:"upload-audio-icon",svgString:Xu,dropupText:"Audio"},mixedFiles:{id:"upload-mixed-files-icon",svgString:Ju,dropupText:"File"}},Kn=function(){function e(i,t,n,r){var a=this;g(this,e),this._attachments=[],this._fileCountLimit=99,this._acceptedFormat="",t.maxNumberOfFiles&&(this._fileCountLimit=t.maxNumberOfFiles),this._toggleContainerDisplay=n,this._fileAttachmentsContainerRef=r,t.acceptedFormats&&(this._acceptedFormat=t.acceptedFormats),setTimeout(function(){a._validationHandler=i._validationHandler})}return y(e,[{key:"attemptAddFile",value:function(t,n){return e.isFileTypeValid(t,this._acceptedFormat)?(this.addAttachmentBasedOnType(t,n,!0),!0):!1}},{key:"addAttachmentBasedOnType",value:function(t,n,r){var a=e.getTypeFromBlob(t);if(a==="image"){var o=e.createImageAttachment(n);this.addFileAttachment(t,"image",o,r)}else if(a==="audio"){var s=In.createAudioAttachment(n);this.addFileAttachment(t,"audio",s,r)}else{var l=e.createAnyFileAttachment(t.name);this.addFileAttachment(t,"any",l,r)}}},{key:"addFileAttachment",value:function(t,n,r,a){var o,s=e.createContainer(r);if(this._attachments.length>=this._fileCountLimit){var l=this._attachments[this._attachments.length-1].removeButton;l==null||l.click();var u=this._fileAttachmentsContainerRef.children;this._fileAttachmentsContainerRef.insertBefore(s,u[0])}else this._fileAttachmentsContainerRef.appendChild(s);var c={file:t,attachmentContainerElement:s,fileType:n};return a&&(c.removeButton=this.createRemoveAttachmentButton(c),s.appendChild(c.removeButton)),this._toggleContainerDisplay(!0),this._attachments.push(c),this._fileAttachmentsContainerRef.scrollTop=this._fileAttachmentsContainerRef.scrollHeight,(o=this._validationHandler)==null||o.call(this),c}},{key:"createRemoveAttachmentButton",value:function(t){var n=document.createElement("div");n.classList.add("remove-file-attachment-button"),n.onclick=this.removeAttachment.bind(this,t);var r=document.createElement("div");return r.classList.add("x-icon"),r.innerText="×",n.appendChild(r),n}},{key:"removeAttachment",value:function(t){var n,r=this._attachments.findIndex(function(o){return o===t}),a=this._attachments[r].attachmentContainerElement;this._attachments.splice(r,1),In.stopAttachmentPlayback(a),a.remove(),this._toggleContainerDisplay(!1),(n=this._validationHandler)==null||n.call(this)}},{key:"getFiles",value:function(){return Array.from(this._attachments).map(function(t){return{file:t.file,type:t.fileType}})}},{key:"removeAllAttachments",value:function(){this._attachments.forEach(function(t){setTimeout(function(){var n;return(n=t.removeButton)==null?void 0:n.click()})})}}],[{key:"isFileTypeValid",value:function(t,n){if(n==="")return!0;for(var r=n.split(","),a=0;a<r.length;a++){var o=r[a].trim();if(t.type===o)return!0;if(o.startsWith(".")){var s=o.slice(1);if(t.name.endsWith(s))return!0}else if(t.name.endsWith(o)||o.endsWith("/*")&&t.type.startsWith(o.slice(0,-2)))return!0}return!1}},{key:"getTypeFromBlob",value:function(t){var n=t.type;return n.startsWith("image")?"image":n.startsWith("audio")?"audio":"any"}},{key:"createImageAttachment",value:function(t){var n=new Image;return n.src=t,n.classList.add("image-attachment"),n}},{key:"createAnyFileAttachment",value:function(t){var n=document.createElement("div");n.classList.add("border-bound-attachment"),we.IS_SAFARI&&n.classList.add("border-bound-attachment-safari");var r=document.createElement("div");r.classList.add("any-file-attachment-text");var a=document.createElement("div");return a.classList.add("file-attachment-text-container"),a.appendChild(r),r.textContent=t,n.appendChild(a),n}},{key:"createContainer",value:function(t){var n=document.createElement("div");return n.classList.add("file-attachment"),n.appendChild(t),n}}]),e}(),tc=`<?xml version="1.0" encoding="utf-8"?>
<svg viewBox="0 0 32 32" version="1.1" xmlns="http://www.w3.org/2000/svg">
  <title>play</title>
  <path d="M5.92 24.096q0 1.088 0.928 1.728 0.512 0.288 1.088 0.288 0.448 0 0.896-0.224l16.16-8.064q0.48-0.256 0.8-0.736t0.288-1.088-0.288-1.056-0.8-0.736l-16.16-8.064q-0.448-0.224-0.896-0.224-0.544 0-1.088 0.288-0.928 0.608-0.928 1.728v16.16z"></path>
</svg>`,Pr=`<?xml version="1.0" encoding="utf-8"?>
<svg viewBox="0 0 32 32" version="1.1" xmlns="http://www.w3.org/2000/svg">
<title>stop</title>
<path d="M5.92 24.096q0 0.832 0.576 1.408t1.44 0.608h16.128q0.832 0 1.44-0.608t0.576-1.408v-16.16q0-0.832-0.576-1.44t-1.44-0.576h-16.128q-0.832 0-1.44 0.576t-0.576 1.44v16.16z"></path>
</svg>`,$i=function(e){P(i,e);function i(t,n,r,a){return g(this,i),O(this,i,[t,n,r,a])}return y(i,[{key:"createTimer",value:function(n,r){var a=this,o=0,s=r!==void 0&&r<i.TIMER_LIMIT_S?r:i.TIMER_LIMIT_S;return setInterval(function(){var l;o+=1,o===s&&((l=a.stopPlaceholderCallback)==null||l.call(a),a.clearTimer()),o===600&&n.classList.add("audio-placeholder-text-4-digits");var u=Math.floor(o/60),c=(o%60).toString().padStart(2,"0");n.textContent="".concat(u,":").concat(c)},1e3)}},{key:"createPlaceholderAudioAttachment",value:function(n){var r=i.createAudioContainer(),a=document.createElement("div");a.classList.add("audio-placeholder-text-3-digits");var o=document.createElement("div");o.classList.add("file-attachment-text-container","audio-placeholder-text-3-digits-container"),o.appendChild(a);var s=pe.createSVGElement(Pr);return s.classList.add("attachment-icon","stop-icon","not-removable-attachment-icon"),a.textContent="0:00",this._activePlaceholderTimer=this.createTimer(a,n),r.appendChild(o),this.addPlaceholderAudioAttachmentEvents(r,s,o),r}},{key:"addPlaceholderAudioAttachmentEvents",value:function(n,r,a){var o=this,s=function(){return n.replaceChildren(r)};n.addEventListener("mouseenter",s);var l=function(){return n.replaceChildren(a)};n.addEventListener("mouseleave",l);var u=function(){var d;return(d=o.stopPlaceholderCallback)==null?void 0:d.call(o)};n.addEventListener("click",u)}},{key:"addPlaceholderAttachment",value:function(n,r){var a=this.createPlaceholderAudioAttachment(r);this._activePlaceholderAttachment=this.addFileAttachment(new File([],""),"audio",a,!1),this.stopPlaceholderCallback=n}},{key:"completePlaceholderAttachment",value:function(n,r){var a=this._activePlaceholderAttachment;a&&(a.file=n,i.addAudioElements(a.attachmentContainerElement.children[0],r),a.removeButton=this.createRemoveAttachmentButton(a),a.attachmentContainerElement.appendChild(a.removeButton),this._activePlaceholderAttachment=void 0,this.clearTimer())}},{key:"removePlaceholderAttachment",value:function(){this._activePlaceholderAttachment&&(this.removeAttachment(this._activePlaceholderAttachment),this._activePlaceholderAttachment=void 0,this.clearTimer())}},{key:"clearTimer",value:function(){this._activePlaceholderTimer!==void 0&&(clearInterval(this._activePlaceholderTimer),this._activePlaceholderTimer=void 0,this.stopPlaceholderCallback=void 0)}}],[{key:"createAudioContainer",value:function(){var n=document.createElement("div");return n.classList.add("border-bound-attachment","audio-attachment-icon-container"),we.IS_SAFARI&&n.classList.add("border-bound-attachment-safari"),n}},{key:"addAudioElements",value:function(n,r){var a=n.parentElement?he.cloneElement(n):n,o=document.createElement("audio");o.src=r;var s=pe.createSVGElement(tc);s.classList.add("attachment-icon","play-icon");var l=pe.createSVGElement(Pr);l.classList.add("attachment-icon","stop-icon"),a.replaceChildren(s),o.onplay=function(){a.replaceChildren(l)},o.onpause=function(){a.replaceChildren(s),o.currentTime=0},o.onended=function(){a.replaceChildren(s)},a.onclick=function(){o.paused?o.play():o.pause()}}},{key:"createAudioAttachment",value:function(n){var r=i.createAudioContainer();return i.addAudioElements(r,n),r}},{key:"stopAttachmentPlayback",value:function(n){var r,a,o;(o=(a=(r=n.children[0])==null?void 0:r.children)==null?void 0:a[0])!=null&&o.classList.contains("stop-icon")&&n.children[0].click()}}]),i}(Kn);$i.TIMER_LIMIT_S=5999;var In=$i,nc=function(){function e(){g(this,e)}return y(e,null,[{key:"create",value:function(t,n,r,a,o){return o==="audio"?new In(t,n,r,a):new Kn(t,n,r,a)}}]),e}(),Yn=function(){function e(i,t,n){g(this,e),this._fileAttachmentsTypes=[],this.elementRef=this.createAttachmentContainer();var r=R(n)=="object"&&!!n.displayFileAttachmentContainer;this.toggleContainerDisplay(r),i.appendChild(this.elementRef),t&&Object.assign(this.elementRef.style,t)}return y(e,[{key:"addType",value:function(t,n,r){var a=nc.create(t,n,this.toggleContainerDisplay.bind(this),this.elementRef,r);return this._fileAttachmentsTypes.push(a),a}},{key:"createAttachmentContainer",value:function(){var t=document.createElement("div");return t.id="file-attachment-container",t}},{key:"toggleContainerDisplay",value:function(t){t?this.elementRef.style.display="block":this.elementRef.children.length===0&&(this.elementRef.style.display="none")}},{key:"getAllFileData",value:function(){var t=this._fileAttachmentsTypes.map(function(n){return n.getFiles()}).flat();return t.length>0?t:void 0}},{key:"completePlaceholders",value:function(){var i=k(f().mark(function n(){return f().wrap(function(a){for(;;)switch(a.prev=a.next){case 0:return a.next=2,Promise.all(this._fileAttachmentsTypes.map(function(){var o=k(f().mark(function s(l){var u;return f().wrap(function(d){for(;;)switch(d.prev=d.next){case 0:return d.abrupt("return",(u=l.stopPlaceholderCallback)==null?void 0:u.call(l));case 1:case"end":return d.stop()}},s)}));return function(s){return o.apply(this,arguments)}}()));case 2:case"end":return a.stop()}},n,this)}));function t(){return i.apply(this,arguments)}return t}()},{key:"addFilesToAnyType",value:function(t){e.addFilesToType(t,this._fileAttachmentsTypes)}},{key:"removeAllFiles",value:function(){this._fileAttachmentsTypes.forEach(function(t){return t.removeAllAttachments()}),this.elementRef.replaceChildren(),this.toggleContainerDisplay(!1)}},{key:"getNumberOfTypes",value:function(){return this._fileAttachmentsTypes.length}}],[{key:"addFilesToType",value:function(t,n){t.forEach(function(r){var a=new FileReader;a.readAsDataURL(r),a.onload=function(o){for(var s=0;s<n.length&&!n[s].attemptAddFile(r,o.target.result);s+=1);}})}}]),e}(),Gi=function(){function e(i,t,n){g(this,e),this._isOpen=!1,this._contentRef=e.createModalContent(t,n==null?void 0:n.backgroundColor),this._buttonPanel=e.createButtonPanel(n==null?void 0:n.backgroundColor),this._elementRef=e.createContainer(this._contentRef,n),this._elementRef.appendChild(this._buttonPanel),i.appendChild(this._elementRef),this._backgroundPanelRef=e.createDarkBackgroundPanel(),i.appendChild(this._backgroundPanelRef),this.addWindowEvents(i)}return y(e,[{key:"isOpen",value:function(){return this._isOpen}},{key:"addButtons",value:function(){for(var t=this,n=arguments.length,r=new Array(n),a=0;a<n;a++)r[a]=arguments[a];r.forEach(function(o){return t._buttonPanel.appendChild(o)})}},{key:"close",value:function(){var t=this;this._elementRef.classList.remove("show-modal"),this._elementRef.classList.add("hide-modal"),this._backgroundPanelRef.classList.remove("show-modal-background"),this._backgroundPanelRef.classList.add("hide-modal-background"),this._isOpen=!1,setTimeout(function(){t._elementRef.style.display="none",t._backgroundPanelRef.style.display="none"},e.MODAL_CLOSE_TIMEOUT_MS)}},{key:"displayModalElements",value:function(){this._elementRef.style.display="flex",this._elementRef.classList.remove("hide-modal"),this._elementRef.classList.add("show-modal"),this._backgroundPanelRef.style.display="block",this._backgroundPanelRef.classList.remove("hide-modal-background"),this._backgroundPanelRef.classList.add("show-modal-background"),this._isOpen=!0}},{key:"openTextModal",value:function(t){this._contentRef.innerHTML=t,this.displayModalElements()}},{key:"addCloseButton",value:function(t,n,r){var a=this,o=n?e.createSVGButton(t):e.createTextButton(t);return this.addButtons(o),o.onclick=function(){a.close(),setTimeout(function(){r==null||r()},140)},o}},{key:"addWindowEvents",value:function(t){this.keyDownEvent=this.windowKeyDown.bind(this,t),window.addEventListener("keydown",this.keyDownEvent)}},{key:"windowKeyDown",value:function(t,n){var r,a;!t.isConnected&&this.keyDownEvent?window.removeEventListener("keydown",this.keyDownEvent):this._isOpen&&(n.key===ne.ESCAPE?(this.close(),(r=this.extensionCloseCallback)==null||r.call(this)):n.key===ne.ENTER&&(this.close(),(a=this.extensionCloseCallback)==null||a.call(this)))}}],[{key:"createContainer",value:function(t,n){var r=document.createElement("div");return r.classList.add("modal"),r.appendChild(t),n&&delete n.backgroundColor,Object.assign(r.style,n),r}},{key:"createModalContent",value:function(t,n){var r,a=document.createElement("div");return(r=a.classList).add.apply(r,di(t)),n&&(a.style.backgroundColor=n),document.createElement("div").appendChild(a),a}},{key:"createButtonPanel",value:function(t){var n=document.createElement("div");return n.classList.add("modal-button-panel"),t&&(n.style.backgroundColor=t),n}},{key:"createDarkBackgroundPanel",value:function(){var t=document.createElement("div");return t.id="modal-background-panel",t}},{key:"createTextButton",value:function(t){var n=document.createElement("div");return n.classList.add("modal-button"),n.textContent=t,n}},{key:"createSVGButton",value:function(t){var n=document.createElement("div");n.classList.add("modal-button","modal-svg-button");var r=pe.createSVGElement(t);return r.classList.add("modal-svg-button-icon"),n.appendChild(r),n}},{key:"createTextModalFunc",value:function(t,n,r){var a;if(R(n)=="object"&&(a=n.files)!=null&&a.infoModal){var o=new e(t,["modal-content"],n.files.infoModal.containerStyle);return o.addCloseButton("OK",!1,r),o.openTextModal.bind(o,n.infoModalTextMarkUp||"")}}}]),e}();Gi.MODAL_CLOSE_TIMEOUT_MS=190;var Qe=Gi,rc=function(e){P(i,e);function i(t,n,r,a,o,s){var l;g(this,i);var u,c,d,h,p,v;l=O(this,i,[i.createButtonElement(),(u=r.button)==null?void 0:u.position,r.button,s]);var m=l.createInnerElements(a,o,l._customStyles);return l._inputElement=i.createInputElement((c=r==null?void 0:r.files)==null?void 0:c.acceptedFormats),l.addClickEvent(t,r),l.elementRef.replaceChildren(m.styles),l.reapplyStateStyle("styles"),l._fileAttachmentsType=n,l._openModalOnce=((h=(d=r.files)==null?void 0:d.infoModal)==null?void 0:h.openModalOnce)===!1||(v=(p=r.files)==null?void 0:p.infoModal)==null?void 0:v.openModalOnce,l}return y(i,[{key:"createInnerElements",value:function(n,r,a){var o=i.createSVGIconElement(n,r);return{styles:this.createInnerElement(o,"styles",a)}}},{key:"triggerImportPrompt",value:function(n){n.onchange=this.import.bind(this,n),n.click()}},{key:"import",value:function(n){Yn.addFilesToType(Array.from(n.files||[]),[this._fileAttachmentsType]),n.value=""}},{key:"createInnerElement",value:function(n,r,a){return Ye.createSpecificStateElement(this.elementRef,r,a)||n}},{key:"addClickEvent",value:function(n,r){var a=this.triggerImportPrompt.bind(this,this._inputElement),o=Qe.createTextModalFunc(n,r,a);this.elementRef.onclick=this.click.bind(this,o)}},{key:"click",value:function(n){n&&(this._openModalOnce===void 0||this._openModalOnce===!0)?(n(),this._openModalOnce===!0&&(this._openModalOnce=!1)):this.triggerImportPrompt(this._inputElement)}}],[{key:"createInputElement",value:function(n){var r=document.createElement("input");return r.type="file",r.accept=n||"",r.hidden=!0,r.multiple=!0,r}},{key:"createButtonElement",value:function(){var n=document.createElement("div");return n.classList.add("input-button","upload-file-button"),n}},{key:"createSVGIconElement",value:function(n,r){var a=pe.createSVGElement(r);return a.id=n,a}}]),i}(ht),Nr=function(){function e(){g(this,e)}return y(e,null,[{key:"create",value:function(t,n,r){var a=e.createElement(r);e.addEvents(a,t,n),t.appendChild(a)}},{key:"createElement",value:function(t){var n=document.createElement("div");return n.id="drag-and-drop",R(t)=="object"&&Object.assign(n.style,t),n}},{key:"addEvents",value:function(t,n,r){n.ondragenter=function(a){a.preventDefault(),e.display(t)},t.ondragleave=function(a){a.preventDefault(),e.hide(t)},t.ondragover=function(a){a.preventDefault()},t.ondrop=function(a){a.preventDefault(),e.uploadFile(r,a),e.hide(t)}}},{key:"uploadFile",value:function(t,n){var r,a=(r=n.dataTransfer)==null?void 0:r.files;a&&t.addFilesToAnyType(Array.from(a))}},{key:"display",value:function(t){t.style.display="block"}},{key:"hide",value:function(t){t.style.display="none"}},{key:"isEnabled",value:function(t,n){return n!==void 0&&n===!1?!1:!!n||t.getNumberOfTypes()>0}}]),e}(),ic=function(){function e(){g(this,e)}return y(e,null,[{key:"validate",value:function(t,n,r,a,o){var s=t(r,a,o);return s?n.changeToSubmitIcon():n.changeToDisabledIcon(),s}},{key:"useValidationFunc",value:function(){var i=k(f().mark(function n(r,a,o,s){var l,u,c,d;return f().wrap(function(p){for(;;)switch(p.prev=p.next){case 0:return l=a.inputElementRef,u=l.classList.contains("text-input-placeholder")?"":l.textContent,p.next=3,o.completePlaceholders();case 3:return c=o.getAllFileData(),d=c==null?void 0:c.map(function(v){return v.file}),p.abrupt("return",e.validate(r,s,u,d));case 5:case"end":return p.stop()}},n)}));function t(n,r,a,o){return i.apply(this,arguments)}return t}()},{key:"useValidationFuncProgrammatic",value:function(){var i=k(f().mark(function n(r,a,o){var s,l;return f().wrap(function(c){for(;;)switch(c.prev=c.next){case 0:return l=(s=a.files)==null?void 0:s.map(function(d){return d.file}),c.abrupt("return",e.validate(r,o,a.text,l,!0));case 2:case"end":return c.stop()}},n)}));function t(n,r,a){return i.apply(this,arguments)}return t}()},{key:"validateWebsocket",value:function(t,n){return t.websocket&&!lt.canSendMessage(t.websocket)?(n.changeToDisabledIcon(),!1):!0}},{key:"attach",value:function(t,n,r,a,o){var s=t.validateInput||Re.processValidateInput(t);t._validationHandler=function(){var l=k(f().mark(function u(c){var d;return f().wrap(function(p){for(;;)switch(p.prev=p.next){case 0:if(!(o.status.loadingActive||o.status.requestInProgress||n.isSubmitProgrammaticallyDisabled===!0||!e.validateWebsocket(n,o))){p.next=2;break}return p.abrupt("return",!1);case 2:return d=s||n.canSendMessage,p.abrupt("return",d?c?e.useValidationFuncProgrammatic(d,c,o):e.useValidationFunc(d,r,a,o):null);case 4:case"end":return p.stop()}},u)}));return function(u){return l.apply(this,arguments)}}()}}]),e}(),ac=`<?xml version="1.0" encoding="iso-8859-1"?>
<svg height="1.4em" width="1.4em" version="1.1" xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink"
	 viewBox="0 0 490.9 490.9" xml:space="preserve">
	<g>
		<g>
			<path d="M245.5,322.9c53,0,96.2-43.2,96.2-96.2V96.2c0-53-43.2-96.2-96.2-96.2s-96.2,43.2-96.2,96.2v130.5
				C149.3,279.8,192.5,322.9,245.5,322.9z M173.8,96.2c0-39.5,32.2-71.7,71.7-71.7s71.7,32.2,71.7,71.7v130.5
				c0,39.5-32.2,71.7-71.7,71.7s-71.7-32.2-71.7-71.7V96.2z"/>
			<path d="M94.4,214.5c-6.8,0-12.3,5.5-12.3,12.3c0,85.9,66.7,156.6,151.1,162.8v76.7h-63.9c-6.8,0-12.3,5.5-12.3,12.3
				s5.5,12.3,12.3,12.3h152.3c6.8,0,12.3-5.5,12.3-12.3s-5.5-12.3-12.3-12.3h-63.9v-76.7c84.4-6.3,151.1-76.9,151.1-162.8
				c0-6.8-5.5-12.3-12.3-12.3s-12.3,5.5-12.3,12.3c0,76.6-62.3,138.9-138.9,138.9s-138.9-62.3-138.9-138.9
				C106.6,220,101.2,214.5,94.4,214.5z"/>
		</g>
	</g>
</svg>
`,Wi=function(e){P(i,e);function i(t){var n;return g(this,i),(t==null?void 0:t.position)==="dropup-menu"&&(t.position="outside-right"),n=O(this,i,[i.createMicrophoneElement(),t==null?void 0:t.position,t]),n.isActive=!1,n._innerElements=n.createInnerElements(n._customStyles),n.changeToDefault(),n}return y(i,[{key:"createInnerElements",value:function(n){var r=i.createSVGIconElement();return{default:this.createInnerElement(r,"default",n),active:this.createInnerElement(r,"active",n),unsupported:this.createInnerElement(r,"unsupported",n),commandMode:this.createInnerElement(r,"commandMode",n)}}},{key:"createInnerElement",value:function(n,r,a){return Ye.createSpecificStateElement(this.elementRef,r,a)||n}},{key:"changeToActive",value:function(){this.elementRef.replaceChildren(this._innerElements.active),this.toggleIconFilter("active"),this.reapplyStateStyle("active",["default","commandMode"]),this.isActive=!0}},{key:"changeToDefault",value:function(){this.elementRef.replaceChildren(this._innerElements.default),this.toggleIconFilter("default"),this.reapplyStateStyle("default",["active","commandMode"]),this.isActive=!1}},{key:"changeToCommandMode",value:function(){this.elementRef.replaceChildren(this._innerElements.unsupported),this.toggleIconFilter("command"),this.reapplyStateStyle("commandMode",["active"])}},{key:"changeToUnsupported",value:function(){this.elementRef.replaceChildren(this._innerElements.unsupported),this.elementRef.classList.add("unsupported-microphone"),this.reapplyStateStyle("unsupported",["active"])}},{key:"toggleIconFilter",value:function(n){var r=this.elementRef.children[0];if(r.tagName.toLocaleLowerCase()==="svg")switch(n){case"default":r.classList.remove("active-microphone-icon","command-microphone-icon"),r.classList.add("default-microphone-icon");break;case"active":r.classList.remove("default-microphone-icon","command-microphone-icon"),r.classList.add("active-microphone-icon");break;case"command":r.classList.remove("active-microphone-icon","default-microphone-icon"),r.classList.add("command-microphone-icon");break}}}],[{key:"createMicrophoneElement",value:function(){var n=document.createElement("div");return n.id="microphone-button",n.classList.add("input-button"),n}},{key:"createSVGIconElement",value:function(){var n=pe.createSVGElement(ac);return n.id="microphone-icon",n}}]),i}(ht),Ki={},qt={},zt={},pt={},He={};Object.defineProperty(He,"__esModule",{value:!0});He.Text=void 0;var Ut=function(){function e(){g(this,e)}return y(e,null,[{key:"capitalize",value:function(t){return t.replace(e.FIRST_CHAR_REGEX,function(n){return n.toUpperCase()})}},{key:"lineBreak",value:function(t){return t.replace(e.DOUBLE_LINE,"<p></p>").replace(e.ONE_LINE,"<br>")}},{key:"isCharDefined",value:function(t){return t!==void 0&&t!==" "&&t!==" "&&t!==`
`&&t!==""}},{key:"breakupIntoWordsArr",value:function(t){return t.split(/(\W+)/)}}]),e}();He.Text=Ut;Ut.FIRST_CHAR_REGEX=/\S/;Ut.DOUBLE_LINE=/\n\n/g;Ut.ONE_LINE=/\n/g;Object.defineProperty(pt,"__esModule",{value:!0});pt.Translate=void 0;var oc=He,sc=function(){function e(){g(this,e)}return y(e,null,[{key:"translate",value:function(t,n){for(var r=oc.Text.breakupIntoWordsArr(t),a=0;a<r.length;a+=1)n[r[a]]&&(r[a]=n[r[a]]);return r.join("")}}]),e}();pt.Translate=sc;Object.defineProperty(zt,"__esModule",{value:!0});zt.WebSpeechTranscript=void 0;var Dr=pt,lc=function(){function e(){g(this,e)}return y(e,null,[{key:"extract",value:function(t,n,r){for(var a="",o=t.resultIndex;o<t.results.length;++o){var s=t.results[o][0].transcript;r&&(s=Dr.Translate.translate(s,r)),t.results[o].isFinal?n+=s:a+=s}return{interimTranscript:a,finalTranscript:n,newText:a||n}}},{key:"extractSafari",value:function(t,n,r){for(var a="",o="",s=t.resultIndex;s<t.results.length;++s){var l=t.results[s][0].transcript;r&&(l=Dr.Translate.translate(l,r)),a+=l}return{interimTranscript:o,finalTranscript:a,newText:a}}}]),e}();zt.WebSpeechTranscript=lc;var Ze={};Object.defineProperty(Ze,"__esModule",{value:!0});Ze.Browser=void 0;var et=y(function e(){g(this,e)});Ze.Browser=et;et.IS_SAFARI=function(){return et._IS_SAFARI===void 0&&(et._IS_SAFARI=/^((?!chrome|android).)*safari/i.test(navigator.userAgent)),et._IS_SAFARI};var ft={},Ht={};Object.defineProperty(Ht,"__esModule",{value:!0});Ht.EventListeners=void 0;var Yi=function(){function e(){g(this,e)}return y(e,null,[{key:"getElementIfFocusedOnAvailable",value:function(t,n){return Array.isArray(t)?t.find(function(r){return n===r}):n===t?t:void 0}},{key:"keyDownWindow",value:function(t){var n=this;t.element&&e.getElementIfFocusedOnAvailable(t.element,document.activeElement)&&(e.KEY_DOWN_TIMEOUT!==null&&clearTimeout(e.KEY_DOWN_TIMEOUT),e.KEY_DOWN_TIMEOUT=setTimeout(function(){e.KEY_DOWN_TIMEOUT=null,n.resetRecording(t)},500))}},{key:"mouseDownWindow",value:function(t,n){this.mouseDownElement=e.getElementIfFocusedOnAvailable(t,n.target)}},{key:"mouseUpWindow",value:function(t){this.mouseDownElement&&this.resetRecording(t),this.mouseDownElement=void 0}},{key:"add",value:function(t,n){var r=(n==null?void 0:n.insertInCursorLocation)===void 0||(n==null?void 0:n.insertInCursorLocation);n!=null&&n.element&&r&&(t.mouseDownEvent=e.mouseDownWindow.bind(t,n.element),document.addEventListener("mousedown",t.mouseDownEvent),t.mouseUpEvent=e.mouseUpWindow.bind(t,n),document.addEventListener("mouseup",t.mouseUpEvent),t.keyDownEvent=e.keyDownWindow.bind(t,n),document.addEventListener("keydown",t.keyDownEvent))}},{key:"remove",value:function(t){document.removeEventListener("mousedown",t.mouseDownEvent),document.removeEventListener("mouseup",t.mouseUpEvent),document.removeEventListener("keydown",t.keyDownEvent)}}]),e}();Ht.EventListeners=Yi;Yi.KEY_DOWN_TIMEOUT=null;var Vt={};Object.defineProperty(Vt,"__esModule",{value:!0});Vt.PreResultUtils=void 0;var uc=function(){function e(){g(this,e)}return y(e,null,[{key:"process",value:function(t,n,r,a,o){var s=a==null?void 0:a(n,r);return s?(setTimeout(function(){s.restart?t.resetRecording(o):s.stop&&t.stop()}),(s.stop||s.restart)&&s.removeNewText):!1}}]),e}();Vt.PreResultUtils=uc;var vt={},mt={};Object.defineProperty(mt,"__esModule",{value:!0});mt.AutoScroll=void 0;var cc=function(){function e(){g(this,e)}return y(e,null,[{key:"changeStateIfNeeded",value:function(t,n){n&&!t.isCursorAtEnd&&(t.endPadding="",t.scrollingSpan.innerHTML="&nbsp;")}},{key:"scrollGeneric",value:function(t,n){t.isCursorAtEnd?n.scrollTop=n.scrollHeight:t.scrollingSpan.scrollIntoView({block:"nearest"})}},{key:"scrollSafariPrimitiveToEnd",value:function(t){t.scrollLeft=t.scrollWidth,t.scrollTop=t.scrollHeight}},{key:"isElementOverflown",value:function(t){return t.scrollHeight>t.clientHeight||t.scrollWidth>t.clientWidth}},{key:"isRequired",value:function(t,n){return t&&e.isElementOverflown(n)}}]),e}();mt.AutoScroll=cc;var Ve={};Object.defineProperty(Ve,"__esModule",{value:!0});Ve.Elements=void 0;var dc=function(){function e(){g(this,e)}return y(e,null,[{key:"isPrimitiveElement",value:function(t){return t.tagName==="INPUT"||t.tagName==="TEXTAREA"}},{key:"createInterimSpan",value:function(){var t=document.createElement("span");return t.style.color="grey",t.style.pointerEvents="none",t}},{key:"createGenericSpan",value:function(){var t=document.createElement("span");return t.style.pointerEvents="none",t}},{key:"appendSpans",value:function(t,n){if(t.spansPopulated=!0,t.insertInCursorLocation&&document.activeElement===n){var r=window.getSelection();if(r!=null&&r.focusNode){var a=r.getRangeAt(0);a.insertNode(t.scrollingSpan),a.insertNode(t.interimSpan),a.insertNode(t.finalSpan),a.collapse(!1),r.removeAllRanges(),r.addRange(a);return}}n.appendChild(t.finalSpan),n.appendChild(t.interimSpan),n.appendChild(t.scrollingSpan)}},{key:"applyCustomColors",value:function(t,n){n.interim&&(t.interimSpan.style.color=n.interim),n.final&&(t.finalSpan.style.color=n.final)}},{key:"isInsideShadowDOM",value:function(t){return t.getRootNode()instanceof ShadowRoot}}]),e}();Ve.Elements=dc;var $e={};Object.defineProperty($e,"__esModule",{value:!0});$e.Cursor=void 0;var hc=function(){function e(){g(this,e)}return y(e,null,[{key:"setOffsetForGeneric",value:function(t,n){for(var r=arguments.length>2&&arguments[2]!==void 0?arguments[2]:0,a=0,o=0;o<t.childNodes.length;o+=1){var s=t.childNodes[o];if(s.childNodes.length>0){var l=e.setOffsetForGeneric(s,n,r);if(l===-1)return-1;r+=l}else if(s.textContent!==null){if(r+s.textContent.length>n){var u=document.createRange();u.setStart(s,n-r),u.collapse(!0);var c=window.getSelection();return c==null||c.removeAllRanges(),c==null||c.addRange(u),t.focus(),-1}r+=s.textContent.length,a+=s.textContent.length}}return a}},{key:"focusEndOfGeneric",value:function(t){var n=document.createRange();n.selectNodeContents(t),n.collapse(!1);var r=window.getSelection();r&&(r.removeAllRanges(),r.addRange(n))}},{key:"setOffsetForSafariGeneric",value:function(t,n){var r=window.getSelection();if(r){var a=e.getGenericElementCursorOffset(t,r,!0);console.log(a),setTimeout(function(){},100),e.setOffsetForGeneric(t,a+n)}}},{key:"setOffsetForPrimitive",value:function(t,n,r){r&&t.blur(),t.setSelectionRange(n,n),t.focus()}},{key:"getGenericElementCursorOffset",value:function(t,n,r){var a=0;if(n.rangeCount>0){var o=n.getRangeAt(0),s=o.cloneRange();s.selectNodeContents(t),r?s.setEnd(o.startContainer,o.startOffset):s.setEnd(o.endContainer,o.endOffset),a=s.toString().length}return a}}]),e}();$e.Cursor=hc;Object.defineProperty(vt,"__esModule",{value:!0});vt.CommandUtils=void 0;var Fr=mt,pc=Ve,fc=Ze,jr=$e,Br=He,vc=function(){function e(){g(this,e)}return y(e,null,[{key:"processCommand",value:function(t,n){return(!n||!n.caseSensitive)&&(t=t.toLowerCase()),(n==null?void 0:n.substrings)===!1?Br.Text.breakupIntoWordsArr(t):t}},{key:"process",value:function(t){var n;return((n=t.settings)===null||n===void 0?void 0:n.caseSensitive)===!0?t:Object.keys(t).reduce(function(r,a){var o=t[a];return r[a]=typeof o=="string"?e.processCommand(o,t.settings):o,r},{})}},{key:"toggleCommandModeOn",value:function(t){var n;t.isWaitingForCommand=!0,(n=t.onCommandModeTrigger)===null||n===void 0||n.call(t,!0)}},{key:"toggleCommandModeOff",value:function(t){var n;t.isWaitingForCommand&&((n=t.onCommandModeTrigger)===null||n===void 0||n.call(t,!1),t.isWaitingForCommand=!1)}},{key:"setText",value:function(t,n,r,a){e.toggleCommandModeOff(t),pc.Elements.isPrimitiveElement(a)?(a.value=r,t.isTargetInShadow||jr.Cursor.setOffsetForPrimitive(a,r.length,!0),fc.Browser.IS_SAFARI()&&t.autoScroll&&Fr.AutoScroll.scrollSafariPrimitiveToEnd(a)):(a.textContent=r,t.isTargetInShadow||jr.Cursor.focusEndOfGeneric(a),setTimeout(function(){return Fr.AutoScroll.scrollGeneric(t,a)})),t.resetRecording(n)}},{key:"checkIfMatchesSubstring",value:function(t,n){return n.includes(t)}},{key:"checkIfMatchesWord",value:function(t,n,r){for(var a=t,o=r.length-1;o>=0;o-=1){for(var s=o,l=a.length-1;r[s]===a[l]&&l>=0;)s-=1,l-=1;if(l<0)return!0}return!1}},{key:"execCommand",value:function(t,n,r,a,o){var s,l,u,c=t.commands;if(!(!c||!a||!r)){var d=((s=c.settings)===null||s===void 0?void 0:s.caseSensitive)===!0?n:n.toLowerCase(),h=Br.Text.breakupIntoWordsArr(d),p=((l=c.settings)===null||l===void 0?void 0:l.substrings)===!1?e.checkIfMatchesWord:e.checkIfMatchesSubstring;if(c.commandMode&&p(c.commandMode,d,h))return t.setInterimColorToFinal(),setTimeout(function(){return e.toggleCommandModeOn(t)}),{doNotProcessTranscription:!1};if(!(c.commandMode&&!t.isWaitingForCommand)){if(c.stop&&p(c.stop,d,h))return e.toggleCommandModeOff(t),setTimeout(function(){return t.stop()}),{doNotProcessTranscription:!1};if(c.pause&&p(c.pause,d,h))return e.toggleCommandModeOff(t),t.setInterimColorToFinal(),setTimeout(function(){var v;t.isPaused=!0,(v=t.onPauseTrigger)===null||v===void 0||v.call(t,!0)}),{doNotProcessTranscription:!1};if(c.resume&&p(c.resume,d,h))return t.isPaused=!1,(u=t.onPauseTrigger)===null||u===void 0||u.call(t,!1),e.toggleCommandModeOff(t),t.resetRecording(r),{doNotProcessTranscription:!0};if(c.reset&&p(c.reset,d,h))return o!==void 0&&e.setText(t,r,o,a),{doNotProcessTranscription:!0};if(c.removeAllText&&p(c.removeAllText,d,h))return e.setText(t,r,"",a),{doNotProcessTranscription:!0}}}}}]),e}();vt.CommandUtils=vc;var $t={};Object.defineProperty($t,"__esModule",{value:!0});$t.Highlight=void 0;var mc=Ve,Xe=$e,gc=function(){function e(){g(this,e)}return y(e,null,[{key:"setStateForPrimitive",value:function(t,n){var r,a;n.selectionStart!==null&&(r=n.selectionStart),n.selectionEnd!==null&&(a=n.selectionEnd),t.isHighlighted=r!==a}},{key:"setStateForGeneric",value:function(t,n){var r=window.getSelection();if(r!=null&&r.focusNode){var a=Xe.Cursor.getGenericElementCursorOffset(n,r,!0),o=Xe.Cursor.getGenericElementCursorOffset(n,r,!1);t.isHighlighted=a!==o}}},{key:"setState",value:function(t,n){document.activeElement===n&&(mc.Elements.isPrimitiveElement(n)?e.setStateForPrimitive(t,n):e.setStateForGeneric(t,n))}},{key:"removeForGeneric",value:function(t,n){var r=window.getSelection();if(r){var a=Xe.Cursor.getGenericElementCursorOffset(n,r,!0);r.deleteFromDocument(),Xe.Cursor.setOffsetForGeneric(n,a),t.isHighlighted=!1}}},{key:"removeForPrimitive",value:function(t,n){var r=n.selectionStart,a=n.selectionEnd,o=n.value;if(r&&a){var s=o.substring(0,r)+o.substring(a);n.value=s,Xe.Cursor.setOffsetForPrimitive(n,r,t.autoScroll)}t.isHighlighted=!1}}]),e}();$t.Highlight=gc;var Gt={};Object.defineProperty(Gt,"__esModule",{value:!0});Gt.Padding=void 0;var yc=Ve,qr=$e,Ke=He,bc=function(){function e(){g(this,e)}return y(e,null,[{key:"setStateForPrimitiveElement",value:function(t,n){if(document.activeElement===n&&n.selectionStart!==null){var r=n.selectionStart,a=n.value[r-1],o=n.selectionEnd===null?r:n.selectionEnd,s=n.value[o];Ke.Text.isCharDefined(a)&&(t.startPadding=" ",t.numberOfSpacesBeforeNewText=1),Ke.Text.isCharDefined(s)&&(t.endPadding=" ",t.numberOfSpacesAfterNewText=1),t.isCursorAtEnd=n.value.length===o;return}var l=n.value[n.value.length-1];Ke.Text.isCharDefined(l)&&(t.startPadding=" ",t.numberOfSpacesBeforeNewText=1),t.isCursorAtEnd=!0}},{key:"setStateForGenericElement",value:function(t,n){var r,a,o;if(document.activeElement===n){var s=window.getSelection();if(s!=null&&s.focusNode){var l=qr.Cursor.getGenericElementCursorOffset(n,s,!0),u=(r=n.textContent)===null||r===void 0?void 0:r[l-1],c=qr.Cursor.getGenericElementCursorOffset(n,s,!1),d=(a=n.textContent)===null||a===void 0?void 0:a[c];Ke.Text.isCharDefined(u)&&(t.startPadding=" "),Ke.Text.isCharDefined(d)&&(t.endPadding=" "),t.isCursorAtEnd=((o=n.textContent)===null||o===void 0?void 0:o.length)===c;return}}var h=n.innerText.charAt(n.innerText.length-1);Ke.Text.isCharDefined(h)&&(t.startPadding=" "),t.isCursorAtEnd=!0}},{key:"setState",value:function(t,n){yc.Elements.isPrimitiveElement(n)?e.setStateForPrimitiveElement(t,n):e.setStateForGenericElement(t,n)}},{key:"adjustStateAfterRecodingPrimitiveElement",value:function(t,n){if(t.primitiveTextRecorded=!0,t.insertInCursorLocation&&document.activeElement===n&&(n.selectionEnd!==null&&(t.endPadding=t.endPadding+n.value.slice(n.selectionEnd)),n.selectionStart!==null)){t.startPadding=n.value.slice(0,n.selectionStart)+t.startPadding;return}t.startPadding=n.value+t.startPadding}},{key:"adjustSateForNoTextPrimitiveElement",value:function(t){t.numberOfSpacesBeforeNewText===1&&(t.startPadding=t.startPadding.substring(0,t.startPadding.length-1),t.numberOfSpacesBeforeNewText=0),t.numberOfSpacesAfterNewText===1&&(t.endPadding=t.endPadding.substring(1),t.numberOfSpacesAfterNewText=0)}}]),e}();Gt.Padding=bc;Object.defineProperty(ft,"__esModule",{value:!0});ft.Speech=void 0;var zr=Ht,kc=Vt,Ur=vt,St=mt,hn=$t,ge=Ve,pn=Gt,Hr=Ze,Vr=$e,fn=He,_c=function(){function e(){g(this,e),this.finalTranscript="",this.interimSpan=ge.Elements.createInterimSpan(),this.finalSpan=ge.Elements.createGenericSpan(),this.scrollingSpan=ge.Elements.createGenericSpan(),this.isCursorAtEnd=!1,this.spansPopulated=!1,this.startPadding="",this.endPadding="",this.numberOfSpacesBeforeNewText=0,this.numberOfSpacesAfterNewText=0,this.isHighlighted=!1,this.primitiveTextRecorded=!1,this.recognizing=!1,this._displayInterimResults=!0,this.insertInCursorLocation=!0,this.autoScroll=!0,this.isRestarting=!1,this.isPaused=!1,this.isWaitingForCommand=!1,this.isTargetInShadow=!1,this.cannotBeStopped=!1,this.resetState()}return y(e,[{key:"prepareBeforeStart",value:function(t){var n,r;if(t!=null&&t.element)if(zr.EventListeners.add(this,t),Array.isArray(t.element)){var a=t.element.find(function(o){return o===document.activeElement})||t.element[0];if(!a)return;this.prepare(a)}else this.prepare(t.element);(t==null?void 0:t.displayInterimResults)!==void 0&&(this._displayInterimResults=t.displayInterimResults),t!=null&&t.textColor&&(this._finalTextColor=(n=t==null?void 0:t.textColor)===null||n===void 0?void 0:n.final,ge.Elements.applyCustomColors(this,t.textColor)),(t==null?void 0:t.insertInCursorLocation)!==void 0&&(this.insertInCursorLocation=t.insertInCursorLocation),(t==null?void 0:t.autoScroll)!==void 0&&(this.autoScroll=t.autoScroll),this._onResult=t==null?void 0:t.onResult,this._onPreResult=t==null?void 0:t.onPreResult,this._onStart=t==null?void 0:t.onStart,this._onStop=t==null?void 0:t.onStop,this._onError=t==null?void 0:t.onError,this.onCommandModeTrigger=t==null?void 0:t.onCommandModeTrigger,this.onPauseTrigger=t==null?void 0:t.onPauseTrigger,this._options=t,!((r=this._options)===null||r===void 0)&&r.commands&&(this.commands=Ur.CommandUtils.process(this._options.commands))}},{key:"prepare",value:function(t){pn.Padding.setState(this,t),hn.Highlight.setState(this,t),this.isTargetInShadow=ge.Elements.isInsideShadowDOM(t),ge.Elements.isPrimitiveElement(t)?(this._primitiveElement=t,this._originalText=this._primitiveElement.value):(this._genericElement=t,this._originalText=this._genericElement.textContent)}},{key:"resetRecording",value:function(t){this.isRestarting=!0,this.stop(!0),this.resetState(!0),this.start(t,!0)}},{key:"updateElements",value:function(t,n,r){var a,o=fn.Text.capitalize(n);if(!(this.finalTranscript===o&&t==="")){kc.PreResultUtils.process(this,r,t==="",this._onPreResult,this._options)&&(t="",r="");var s=this.commands&&Ur.CommandUtils.execCommand(this,r,this._options,this._primitiveElement||this._genericElement,this._originalText);if(s){if(s.doNotProcessTranscription)return;t="",r=""}if(!(this.isPaused||this.isWaitingForCommand)){(a=this._onResult)===null||a===void 0||a.call(this,r,t===""),this.finalTranscript=o,this._displayInterimResults||(t="");var l=this.finalTranscript===""&&t==="";this._primitiveElement?this.updatePrimitiveElement(this._primitiveElement,t,l):this._genericElement&&this.updateGenericElement(this._genericElement,t,l)}}}},{key:"updatePrimitiveElement",value:function(t,n,r){this.isHighlighted&&hn.Highlight.removeForPrimitive(this,t),this.primitiveTextRecorded||pn.Padding.adjustStateAfterRecodingPrimitiveElement(this,t),r&&pn.Padding.adjustSateForNoTextPrimitiveElement(this);var a=this.startPadding+this.finalTranscript+n;if(t.value=a+this.endPadding,!this.isTargetInShadow){var o=a.length+this.numberOfSpacesAfterNewText;Vr.Cursor.setOffsetForPrimitive(t,o,this.autoScroll)}this.autoScroll&&Hr.Browser.IS_SAFARI()&&this.isCursorAtEnd&&St.AutoScroll.scrollSafariPrimitiveToEnd(t)}},{key:"updateGenericElement",value:function(t,n,r){this.isHighlighted&&hn.Highlight.removeForGeneric(this,t),this.spansPopulated||ge.Elements.appendSpans(this,t);var a=(r?"":this.startPadding)+fn.Text.lineBreak(this.finalTranscript);this.finalSpan.innerHTML=a;var o=St.AutoScroll.isRequired(this.autoScroll,t);St.AutoScroll.changeStateIfNeeded(this,o);var s=fn.Text.lineBreak(n)+(r?"":this.endPadding);this.interimSpan.innerHTML=s,Hr.Browser.IS_SAFARI()&&this.insertInCursorLocation&&Vr.Cursor.setOffsetForSafariGeneric(t,a.length+s.length),o&&St.AutoScroll.scrollGeneric(this,t),r&&(this.scrollingSpan.innerHTML="")}},{key:"finalise",value:function(t){this._genericElement&&(t?(this.finalSpan=ge.Elements.createGenericSpan(),this.setInterimColorToFinal(),this.interimSpan=ge.Elements.createInterimSpan(),this.scrollingSpan=ge.Elements.createGenericSpan()):this._genericElement.textContent=this._genericElement.textContent,this.spansPopulated=!1),zr.EventListeners.remove(this)}},{key:"setInterimColorToFinal",value:function(){this.interimSpan.style.color=this._finalTextColor||"black"}},{key:"resetState",value:function(t){this._primitiveElement=void 0,this._genericElement=void 0,this.finalTranscript="",this.finalSpan.innerHTML="",this.interimSpan.innerHTML="",this.scrollingSpan.innerHTML="",this.startPadding="",this.endPadding="",this.isHighlighted=!1,this.primitiveTextRecorded=!1,this.numberOfSpacesBeforeNewText=0,this.numberOfSpacesAfterNewText=0,t||(this.stopTimeout=void 0)}},{key:"setStateOnStart",value:function(){var t;this.recognizing=!0,this.isRestarting?this.isRestarting=!1:(t=this._onStart)===null||t===void 0||t.call(this)}},{key:"setStateOnStop",value:function(){var t;this.recognizing=!1,this.isRestarting||(t=this._onStop)===null||t===void 0||t.call(this)}},{key:"setStateOnError",value:function(t){var n;(n=this._onError)===null||n===void 0||n.call(this,t),this.recognizing=!1}}]),e}();ft.Speech=_c;Object.defineProperty(qt,"__esModule",{value:!0});qt.WebSpeech=void 0;var $r=zt,Gr=Ze,wc=ft,Sc=function(e){P(i,e);function i(){return g(this,i),O(this,i)}return y(i,[{key:"start",value:function(n){var r;this._extractText===void 0&&(this._extractText=Gr.Browser.IS_SAFARI()?$r.WebSpeechTranscript.extractSafari:$r.WebSpeechTranscript.extract),this.validate()&&(this.prepareBeforeStart(n),this.instantiateService(n),(r=this._service)===null||r===void 0||r.start(),this._translations=n==null?void 0:n.translations)}},{key:"validate",value:function(){return i.getAPI()?!0:(this.error("Speech Recognition is unsupported"),!1)}},{key:"instantiateService",value:function(n){var r,a,o=i.getAPI();this._service=new o,this._service.continuous=!0,this._service.interimResults=(r=n==null?void 0:n.displayInterimResults)!==null&&r!==void 0?r:!0,this._service.lang=((a=n==null?void 0:n.language)===null||a===void 0?void 0:a.trim())||"en-US",this.setEvents()}},{key:"setEvents",value:function(){var n=this;this._service&&(this._service.onstart=function(){n.setStateOnStart()},this._service.onerror=function(r){Gr.Browser.IS_SAFARI()&&r.message==="Another request is started"||r.error==="aborted"&&n.isRestarting||r.error!=="no-speech"&&n.error(r.message||r.error)},this._service.onaudioend=function(){n.setStateOnStop()},this._service.onend=function(){n._stopping=!1},this._service.onresult=function(r){if(R(r.results)>"u"&&n._service)n._service.onend=null,n._service.stop();else if(n._extractText&&!n._stopping){var a=n._extractText(r,n.finalTranscript,n._translations),o=a.interimTranscript,s=a.finalTranscript,l=a.newText;n.updateElements(o,s,l)}})}},{key:"stop",value:function(n){var r;this._stopping=!0,(r=this._service)===null||r===void 0||r.stop(),this.finalise(n)}},{key:"error",value:function(n){console.error(n),this.setStateOnError(n),this.stop()}}],[{key:"getAPI",value:function(){return window.webkitSpeechRecognition||window.SpeechRecognition}}]),i}(wc.Speech);qt.WebSpeech=Sc;var Wt={};Object.defineProperty(Wt,"__esModule",{value:!0});Wt.GlobalState=void 0;var Ji=function(){function e(){g(this,e)}return y(e,null,[{key:"doubleClickDetector",value:function(){return e.doubleClickPending?!0:(e.doubleClickPending=!0,setTimeout(function(){e.doubleClickPending=!1},300),!1)}}]),e}();Wt.GlobalState=Ji;Ji.doubleClickPending=!1;var Kt={},Yt={};Object.defineProperty(Yt,"__esModule",{value:!0});Yt.PreventConnectionStop=void 0;var xc=function(){function e(){g(this,e)}return y(e,null,[{key:"applyPrevention",value:function(t){clearTimeout(t._manualConnectionStopPrevention),t.cannotBeStopped=!0,t._manualConnectionStopPrevention=setTimeout(function(){t.cannotBeStopped=!1},800)}},{key:"clearPrevention",value:function(t){clearTimeout(t._manualConnectionStopPrevention),t.cannotBeStopped=!1}}]),e}();Yt.PreventConnectionStop=xc;var Jt={},Zt={};Object.defineProperty(Zt,"__esModule",{value:!0});Zt.README_URL=void 0;Zt.README_URL="https://github.com/OvidijusParsiunas/speech-to-element";Object.defineProperty(Jt,"__esModule",{value:!0});Jt.AzureSpeechConfig=void 0;var vn=Zt,Ec=function(){function e(){g(this,e)}return y(e,null,[{key:"validateOptions",value:function(t,n){return n?!n.subscriptionKey&&!n.token&&!n.retrieveToken?(t("Please define a 'subscriptionKey', 'token' or 'retrieveToken' property - more info: ".concat(vn.README_URL)),!1):n.region?!0:(t("Please define a 'region' property - more info: ".concat(vn.README_URL)),!1):(t("Please provide subscription details - more info: ".concat(vn.README_URL)),!1)}},{key:"getNewSpeechConfig",value:function(){var i=k(f().mark(function n(r,a){return f().wrap(function(s){for(;;)switch(s.prev=s.next){case 0:if(!a.region){s.next=2;break}return s.abrupt("return",a.subscriptionKey?r.fromSubscription(a.subscriptionKey.trim(),a.region.trim()):a.token?r.fromAuthorizationToken(a.token.trim(),a.region.trim()):a.retrieveToken?a.retrieveToken().then(function(l){return a.region?r.fromAuthorizationToken((l==null?void 0:l.trim())||"",a.region.trim()):null}).catch(function(l){return console.error(l),null}):null);case 2:case"end":return s.stop()}},n)}));function t(n,r){return i.apply(this,arguments)}return t}()},{key:"process",value:function(t,n){n.language&&(t.speechRecognitionLanguage=n.language.trim())}},{key:"get",value:function(){var i=k(f().mark(function n(r,a){var o;return f().wrap(function(l){for(;;)switch(l.prev=l.next){case 0:return l.next=2,e.getNewSpeechConfig(r,a);case 2:return o=l.sent,l.abrupt("return",(o&&e.process(o,a),o));case 4:case"end":return l.stop()}},n)}));function t(n,r){return i.apply(this,arguments)}return t}()}]),e}();Jt.AzureSpeechConfig=Ec;var Xt={};Object.defineProperty(Xt,"__esModule",{value:!0});Xt.StopTimeout=void 0;var Zi=function(){function e(){g(this,e)}return y(e,null,[{key:"set",value:function(t){t.stopTimeout=setTimeout(function(){return t.stop()},t.stopTimeoutMS)}},{key:"reset",value:function(t,n){t.stopTimeoutMS=n||e.DEFAULT_MS,t.stopTimeout&&clearTimeout(t.stopTimeout),e.set(t)}}]),e}();Xt.StopTimeout=Zi;Zi.DEFAULT_MS=2e4;var Qt={};Object.defineProperty(Qt,"__esModule",{value:!0});Qt.AzureTranscript=void 0;var Cc=pt,Mc=function(){function e(){g(this,e)}return y(e,null,[{key:"extract",value:function(t,n,r,a){return a&&(t=Cc.Translate.translate(t,a)),r?{interimTranscript:"",finalTranscript:n+t,newText:t}:{interimTranscript:t,finalTranscript:n,newText:t}}}]),e}();Qt.AzureTranscript=Mc;Object.defineProperty(Kt,"__esModule",{value:!0});Kt.Azure=void 0;var Wr=Yt,Kr=Jt,mn=Xt,Yr=Qt,Ac=ft,Tc=function(e){P(i,e);function i(){var t;return g(this,i),t=O(this,i,arguments),t._newTextPadding="",t}return y(i,[{key:"start",value:function(n,r){this._newTextPadding="",this.stopTimeout===void 0&&mn.StopTimeout.reset(this,n==null?void 0:n.stopAfterSilenceMs),this.prepareBeforeStart(n),this.startAsync(n),r||Wr.PreventConnectionStop.applyPrevention(this)}},{key:"startAsync",value:function(){var t=k(f().mark(function r(a){var o;return f().wrap(function(l){for(;;)switch(l.prev=l.next){case 0:if(l.t0=this.validate(a),!l.t0){l.next=6;break}return l.next=4,this.instantiateService(a);case 4:this._translations=a==null?void 0:a.translations,(o=this._service)===null||o===void 0||o.startContinuousRecognitionAsync(function(){},this.error);case 6:case"end":return l.stop()}},r,this)}));function n(r){return t.apply(this,arguments)}return n}()},{key:"validate",value:function(n){return i.getAPI()?Kr.AzureSpeechConfig.validateOptions(this.error.bind(this),n):(this.moduleNotFound(),!1)}},{key:"instantiateService",value:function(){var t=k(f().mark(function r(a){var o,s,l,u;return f().wrap(function(d){for(;;)switch(d.prev=d.next){case 0:return o=i.getAPI(),s=o.AudioConfig.fromDefaultMicrophoneInput(),d.next=4,Kr.AzureSpeechConfig.get(o.SpeechConfig,a);case 4:l=d.sent,l?(u=new o.SpeechRecognizer(l,s),this.setEvents(u),this._service=u,a.retrieveToken&&this.retrieveTokenInterval(a.retrieveToken)):this.error("Unable to contact Azure server");case 6:case"end":return d.stop()}},r,this)}));function n(r){return t.apply(this,arguments)}return n}()},{key:"setEvents",value:function(n){n.recognizing=this.onRecognizing.bind(this),n.recognized=this.onRecognized.bind(this),n.sessionStarted=this.onSessionStarted.bind(this),n.canceled=this.onCanceled.bind(this),n.sessionStopped=this.onSessionStopped.bind(this)}},{key:"onRecognizing",value:function(n,r){if(!this._stopping){var a=Yr.AzureTranscript.extract(this._newTextPadding+r.result.text,this.finalTranscript,!1,this._translations),o=a.interimTranscript,s=a.finalTranscript,l=a.newText;mn.StopTimeout.reset(this,this.stopTimeoutMS),this.updateElements(o,s,l)}}},{key:"onRecognized",value:function(n,r){var a=r.result;switch(a.reason){case window.SpeechSDK.ResultReason.Canceled:break;case window.SpeechSDK.ResultReason.RecognizedSpeech:if(a.text&&!this._stopping){var o=Yr.AzureTranscript.extract(this._newTextPadding+a.text,this.finalTranscript,!0,this._translations),s=o.interimTranscript,l=o.finalTranscript,u=o.newText;mn.StopTimeout.reset(this,this.stopTimeoutMS),this.updateElements(s,l,u),l!==""&&(this._newTextPadding=" ")}break}}},{key:"onCanceled",value:function(n,r){r.reason===window.SpeechSDK.CancellationReason.Error&&this.error(r.errorDetails)}},{key:"onSessionStarted",value:function(){Wr.PreventConnectionStop.clearPrevention(this),this.setStateOnStart()}},{key:"onSessionStopped",value:function(){this._retrieveTokenInterval||clearInterval(this._retrieveTokenInterval),this._stopping=!1,this.setStateOnStop()}},{key:"retrieveTokenInterval",value:function(n){var r=this;this._retrieveTokenInterval=setInterval(function(){n==null||n().then(function(a){r._service&&(r._service.authorizationToken=(a==null?void 0:a.trim())||"")}).catch(function(a){r.error(a)})},1e4)}},{key:"stop",value:function(n){var r;!n&&this._retrieveTokenInterval&&clearInterval(this._retrieveTokenInterval),this._stopping=!0,(r=this._service)===null||r===void 0||r.stopContinuousRecognitionAsync(),this.finalise(n)}},{key:"moduleNotFound",value:function(){console.error("speech recognition module not found:"),console.error(`please install the 'microsoft-cognitiveservices-speech-sdk' npm package or add a script tag: <script src="https://aka.ms/csspeech/jsbrowserpackageraw"><\/script>`),this.setStateOnError("speech recognition module not found")}},{key:"error",value:function(n){this._retrieveTokenInterval&&clearInterval(this._retrieveTokenInterval),console.error(n),this.setStateOnError(n),this.stop()}}],[{key:"getAPI",value:function(){return window.SpeechSDK}}]),i}(Ac.Speech);Kt.Azure=Tc;Object.defineProperty(Ki,"__esModule",{value:!0});var Jr=qt,Ic=vt,me=Wt,Lc=Kt,Rc=function(){function e(){g(this,e)}return y(e,null,[{key:"toggle",value:function(t,n){var r,a,o=t.toLocaleLowerCase().trim();!((r=me.GlobalState.service)===null||r===void 0)&&r.recognizing?this.stop():o==="webspeech"?e.startWebSpeech(n):o==="azure"?e.startAzure(n):(console.error("service not found - must be either 'webspeech' or 'azure'"),(a=n==null?void 0:n.onError)===null||a===void 0||a.call(n,"service not found - must be either 'webspeech' or 'azure'"))}},{key:"startWebSpeech",value:function(t){e.stop()||(me.GlobalState.service=new Jr.WebSpeech,me.GlobalState.service.start(t))}},{key:"isWebSpeechSupported",value:function(){return!!Jr.WebSpeech.getAPI()}},{key:"startAzure",value:function(t){var n;e.stop()||!((n=me.GlobalState.service)===null||n===void 0)&&n.cannotBeStopped||(me.GlobalState.service=new Lc.Azure,me.GlobalState.service.start(t))}},{key:"stop",value:function(){var t;return me.GlobalState.doubleClickDetector()?!0:(!((t=me.GlobalState.service)===null||t===void 0)&&t.recognizing&&me.GlobalState.service.stop(),!1)}},{key:"endCommandMode",value:function(){me.GlobalState.service&&Ic.CommandUtils.toggleCommandModeOff(me.GlobalState.service)}}]),e}(),gn=Ki.default=Rc,Oc=function(e){P(i,e);function i(t,n,r){var a;g(this,i);var o;a=O(this,i,[R(t.speechToText)=="object"?(o=t.speechToText)==null?void 0:o.button:{}]);var s=i.processConfiguration(n,t.speechToText),l=s.serviceName,u=s.processedConfig;if(a._addErrorMessage=r,l==="webspeech"&&!gn.isWebSpeechSupported())a.changeToUnsupported();else{var c=!t.textInput||!t.textInput.disabled;a.elementRef.onclick=a.buttonClick.bind(de(a),n,c,l,u)}return a}return y(i,[{key:"buttonClick",value:function(n,r,a,o){n.removeTextIfPlaceholder(),gn.toggle(a,V({insertInCursorLocation:!1,element:r?n.inputElementRef:void 0,onError:this.onError.bind(this),onStart:this.changeToActive.bind(this),onStop:this.changeToDefault.bind(this),onCommandModeTrigger:this.onCommandModeTrigger.bind(this)},o))}},{key:"onCommandModeTrigger",value:function(n){n?this.changeToCommandMode():this.changeToActive()}},{key:"onError",value:function(){this._addErrorMessage("speechToText","speech input error")}}],[{key:"processConfiguration",value:function(n,r){var a,o,s,l,u,c=R(r)=="object"?r:{},d=R(c.webSpeech)=="object"?c.webSpeech:{},h=c.azure||{},p=V(V({displayInterimResults:(a=c.displayInterimResults)!==null&&a!==void 0?a:void 0,textColor:(o=c.textColor)!==null&&o!==void 0?o:void 0,translations:(s=c.translations)!==null&&s!==void 0?s:void 0,commands:(l=c.commands)!==null&&l!==void 0?l:void 0},d),h),v=(u=c.commands)==null?void 0:u.submit;return v&&(p.onPreResult=function(m){return m.toLowerCase().includes(v)?(setTimeout(function(){var b;return(b=n.submit)==null?void 0:b.call(n)}),gn.endCommandMode(),{restart:!0,removeNewText:!0}):null}),{serviceName:i.getServiceName(c),processedConfig:p}}},{key:"getServiceName",value:function(n){return n.webSpeech?"webspeech":n.azure?"azure":"webspeech"}}]),i}(Wi),Xi=function(){function e(){g(this,e)}return y(e,null,[{key:"getFileName",value:function(t,n){var r=new Date,a=String(r.getHours()).padStart(2,"0"),o=String(r.getMinutes()).padStart(2,"0"),s=String(r.getSeconds()).padStart(2,"0");return"".concat(t,"-").concat(a,"-").concat(o,"-").concat(s,".").concat(n)}}]),e}(),Pc=function(e){P(i,e);function i(t,n){var r;g(this,i);var a,o;return r=O(this,i,[n.button]),r._waitingForBrowserApproval=!1,r._audioType=t,r._extension=((a=n.files)==null?void 0:a.format)||"mp3",r._maxDurationSeconds=(o=n.files)==null?void 0:o.maxDurationSeconds,r.elementRef.onclick=r.buttonClick.bind(de(r)),r}return y(i,[{key:"buttonClick",value:function(){this._waitingForBrowserApproval||(this.isActive?this.stop():(this._waitingForBrowserApproval=!0,this.record()))}},{key:"stop",value:function(){var n=this;return new Promise(function(r){var a,o;n.changeToDefault(),(a=n._mediaRecorder)==null||a.stop(),(o=n._mediaStream)==null||o.getTracks().forEach(function(s){return s.stop()}),setTimeout(function(){r()},10)})}},{key:"record",value:function(){var n=this;navigator.mediaDevices.getUserMedia({audio:!0}).then(function(r){n.changeToActive(),n._mediaRecorder=new MediaRecorder(r),n._audioType.addPlaceholderAttachment(n.stop.bind(n),n._maxDurationSeconds),n._mediaStream=r,n._mediaRecorder.addEventListener("dataavailable",function(a){n.createFile(a)}),n._mediaRecorder.start()}).catch(function(r){console.error(r),n.stop()}).finally(function(){n._waitingForBrowserApproval=!1})}},{key:"createFile",value:function(n){var r=this,a=new Blob([n.data],{type:"audio/".concat(this._extension)}),o=Xi.getFileName(this._newFilePrefix||"audio",this._extension),s=new File([a],o,{type:a.type}),l=new FileReader;l.readAsDataURL(s),l.onload=function(u){r._audioType.completePlaceholderAttachment(s,u.target.result)}}}]),i}(Wi),Nc=`<?xml version="1.0" standalone="no"?>
<!DOCTYPE svg PUBLIC "-//W3C//DTD SVG 1.0//EN" "http://www.w3.org/TR/2001/REC-SVG-20010904/DTD/svg10.dtd">
<svg xmlns="http://www.w3.org/2000/svg" stroke="currentColor" fill="none" stroke-width="1" viewBox="0 0 24 24" stroke-linecap="round" stroke-linejoin="round">
  <line x1="22" y1="2" x2="11" y2="14"></line>
  <polygon points="22 2 15 22 11 14 2 10 22 2"></polygon>
</svg>
`,Ie=function(){function e(){g(this,e)}return y(e,null,[{key:"setPropertyValueIfDoesNotExist",value:function(t,n,r){var a,o,s=n[0];n.length===1?(a=t[s])!==null&&a!==void 0||(t[s]=r):((o=t[s])!==null&&o!==void 0||(t[s]={}),n.shift(),e.setPropertyValueIfDoesNotExist(t[s],n,r))}},{key:"setPropertyValue",value:function(t,n,r){var a,o=n[0];n.length===1?t[o]=r:((a=t[o])!==null&&a!==void 0||(t[o]={}),n.shift(),e.setPropertyValue(t[o],n,r))}},{key:"getObjectValue",value:function(t,n){var r=n[0],a=t[r];return a===void 0||n.length===1?a:e.getObjectValue(a,n.slice(1))}},{key:"overwritePropertyObjectFromAnother",value:function(t,n,r){var a=e.getObjectValue(n,r);if(a){var o=V(V({},a),e.getObjectValue(t,r)||{});e.setPropertyValue(t,r,o)}}}]),e}(),Zr=function(){function e(){g(this,e)}return y(e,null,[{key:"resetSubmit",value:function(t,n){n?t.unsetCustomStateStyles(["loading","submit"]):t.unsetCustomStateStyles(["stop","loading","submit"]),t.reapplyStateStyle("submit")}},{key:"overwriteDefaultStyleWithSubmit",value:function(t,n){if(t.submit){var r=JSON.parse(JSON.stringify(t[n]||{}));Ie.overwritePropertyObjectFromAnother(r,t.submit,["container","default"]),Ie.overwritePropertyObjectFromAnother(r,t.submit,["text","styles","default"]),Ie.overwritePropertyObjectFromAnother(r,t.submit,["svg","styles","default"]),t[n]=r}}},{key:"setUpDisabledButton",value:function(t){Ie.setPropertyValueIfDoesNotExist(t,["submit","container","default","backgroundColor"],""),Ie.setPropertyValueIfDoesNotExist(t,["disabled","container","default","backgroundColor"],"unset"),Ie.setPropertyValueIfDoesNotExist(t.submit,["svg","styles","default","filter"],""),Ie.setPropertyValueIfDoesNotExist(t.disabled,["svg","styles","default","filter"],"brightness(0) saturate(100%) invert(70%) sepia(0%) saturate(5564%) hue-rotate(207deg) brightness(100%) contrast(97%)"),e.overwriteDefaultStyleWithSubmit(t,"disabled")}},{key:"process",value:function(t){var n=JSON.parse(JSON.stringify(t||{}));return e.overwriteDefaultStyleWithSubmit(n,"loading"),e.overwriteDefaultStyleWithSubmit(n,"stop"),t!=null&&t.alwaysEnabled||e.setUpDisabledButton(n),n}}]),e}(),en=function(e){P(i,e);function i(t,n,r,a,o){var s;g(this,i);var l=Zr.process(t.submitButtonStyles);return s=O(this,i,[i.createButtonContainerElement(),l==null?void 0:l.position,l]),s._isSVGLoadingIconOverriden=!1,s.status={requestInProgress:!1,loadingActive:!1},s._messages=r,s._inputElementRef=n,s._fileAttachments=o,s._innerElements=s.createInnerElements(),s._abortStream=new AbortController,s._stopClicked={listener:function(){}},s._serviceIO=a,s._alwaysEnabled=!!(l!=null&&l.alwaysEnabled),t.disableSubmitButton=s.disableSubmitButton.bind(de(s),a),s.attemptOverwriteLoadingStyle(t),setTimeout(function(){var u;s._validationHandler=t._validationHandler,s.assignHandlers(s._validationHandler),(u=s._validationHandler)==null||u.call(de(s))}),s}return y(i,[{key:"createInnerElements",value:function(){var n=Ye.create(this.elementRef,["submit","loading","stop"],this._customStyles),r=n.submit,a=n.loading,o=n.stop,s=r||i.createSubmitIconElement();return{submit:s,loading:a||i.createLoadingIconElement(),stop:o||i.createStopIconElement(),disabled:this.createDisabledIconElement(s)}}},{key:"createDisabledIconElement",value:function(n){return Ye.createCustomElement("disabled",this._customStyles)||n.cloneNode(!0)}},{key:"attemptOverwriteLoadingStyle",value:function(n){var r,a,o,s,l,u,c,d,h;if(!((a=(r=this._customStyles)==null?void 0:r.submit)!=null&&a.svg||(l=(s=(o=this._customStyles)==null?void 0:o.loading)==null?void 0:s.svg)!=null&&l.content||(d=(c=(u=this._customStyles)==null?void 0:u.loading)==null?void 0:c.text)!=null&&d.content)&&(n.displayLoadingBubble===void 0||n.displayLoadingBubble===!0)){var p=document.createElement("style");p.textContent=`
        .loading-button > * {
          filter: brightness(0) saturate(100%) invert(72%) sepia(0%) saturate(3044%) hue-rotate(322deg) brightness(100%)
            contrast(96%) !important;
        }`,(h=n.shadowRoot)==null||h.appendChild(p),this._isSVGLoadingIconOverriden=!0}}},{key:"assignHandlers",value:function(n){this._serviceIO.completionsHandlers={onFinish:this.resetSubmit.bind(this,n)},this._serviceIO.streamHandlers={onOpen:this.changeToStopIcon.bind(this),onClose:this.resetSubmit.bind(this,n),abortStream:this._abortStream,stopClicked:this._stopClicked};var r=this._serviceIO.deepChat.stream;R(r)=="object"&&typeof r.simulation=="number"&&(this._serviceIO.streamHandlers.simulationInterim=r.simulation)}},{key:"resetSubmit",value:function(n){this.status.requestInProgress=!1,this.status.loadingActive=!1,n()}},{key:"submitFromInput",value:function(){var t=k(f().mark(function r(){var a,o,s;return f().wrap(function(u){for(;;)switch(u.prev=u.next){case 0:return u.next=2,this._fileAttachments.completePlaceholders();case 2:o=this._fileAttachments.getAllFileData(),this._inputElementRef.classList.contains("text-input-placeholder")?this.attemptSubmit({text:"",files:o}):(s=(a=this._inputElementRef.textContent)==null?void 0:a.trim(),this.attemptSubmit({text:s,files:o}));case 4:case"end":return u.stop()}},r,this)}));function n(){return t.apply(this,arguments)}return n}()},{key:"programmaticSubmit",value:function(){var t=k(f().mark(function r(a){var o=this,s;return f().wrap(function(u){for(;;)switch(u.prev=u.next){case 0:typeof a=="string"&&(a=Re.processSubmitUserMessage(a)),s={text:a.text},a.files&&(s.files=Array.from(a.files).map(function(c){return{file:c,type:Kn.getTypeFromBlob(c)}})),setTimeout(function(){return o.attemptSubmit(s,!0)});case 3:case"end":return u.stop()}},r)}));function n(r){return t.apply(this,arguments)}return n}()},{key:"attemptSubmit",value:function(){var t=k(f().mark(function r(a){var o,s,l,u,c,d,h=arguments;return f().wrap(function(v){for(;;)switch(v.prev=v.next){case 0:return o=h.length>1&&h[1]!==void 0?h[1]:!1,v.next=3,(s=this._validationHandler)==null?void 0:s.call(this,o?a:void 0);case 3:if(v.t0=v.sent,v.t1=!1,v.t0!==v.t1){v.next=7;break}return v.abrupt("return");case 7:return this.changeToLoadingIcon(),v.next=10,this.addNewMessage(a);case 10:return this._serviceIO.isWebModel()||this._messages.addLoadingMessage(),Nn.clear(this._inputElementRef),c=(l=a.files)==null?void 0:l.map(function(m){return m.file}),d={text:a.text===""?void 0:a.text,files:c},v.next=15,this._serviceIO.callAPI(d,this._messages);case 15:(u=this._fileAttachments)==null||u.removeAllFiles();case 16:case"end":return v.stop()}},r,this)}));function n(r){return t.apply(this,arguments)}return n}()},{key:"addNewMessage",value:function(){var t=k(f().mark(function r(a){var o,s,l;return f().wrap(function(c){for(;;)switch(c.prev=c.next){case 0:if(o=a.text,s=a.files,l={role:F.USER_ROLE},o&&(l.text=o),c.t0=s,!c.t0){c.next=8;break}return c.next=7,this._messages.addMultipleFiles(s);case 7:l.files=c.sent;case 8:this._serviceIO.sessionId&&(l._sessionId=this._serviceIO.sessionId),Object.keys(l).length>0&&this._messages.addNewMessage(l);case 10:case"end":return c.stop()}},r,this)}));function n(r){return t.apply(this,arguments)}return n}()},{key:"stopStream",value:function(){var n;this._abortStream.abort(),(n=this._stopClicked)==null||n.listener(),this._validationHandler&&this.resetSubmit(this._validationHandler)}},{key:"changeToStopIcon",value:function(){this._serviceIO.websocket||(this.elementRef.classList.remove(i.LOADING_CLASS,i.DISABLED_CLASS,i.SUBMIT_CLASS),this.elementRef.replaceChildren(this._innerElements.stop),this.reapplyStateStyle("stop",["loading","submit"]),this.elementRef.onclick=this.stopStream.bind(this),this.status.loadingActive=!1)}},{key:"changeToLoadingIcon",value:function(){this._serviceIO.websocket||(this._isSVGLoadingIconOverriden||this.elementRef.replaceChildren(this._innerElements.loading),this.elementRef.classList.remove(i.SUBMIT_CLASS,i.DISABLED_CLASS),this.elementRef.classList.add(i.LOADING_CLASS),this.reapplyStateStyle("loading",["submit"]),this.elementRef.onclick=function(){},this.status.requestInProgress=!0,this.status.loadingActive=!0)}},{key:"changeToSubmitIcon",value:function(){this.elementRef.classList.contains(i.SUBMIT_CLASS)||(this.elementRef.classList.remove(i.LOADING_CLASS,i.DISABLED_CLASS),this.elementRef.classList.add(i.SUBMIT_CLASS),this.elementRef.replaceChildren(this._innerElements.submit),Zr.resetSubmit(this,this.status.loadingActive),this.elementRef.onclick=this.submitFromInput.bind(this))}},{key:"changeToDisabledIcon",value:function(){var n=arguments.length>0&&arguments[0]!==void 0?arguments[0]:!1;this._alwaysEnabled&&!n?this.changeToSubmitIcon():this.elementRef.classList.contains(i.DISABLED_CLASS)||(this.elementRef.classList.remove(i.LOADING_CLASS,i.SUBMIT_CLASS),this.elementRef.classList.add(i.DISABLED_CLASS),this.elementRef.replaceChildren(this._innerElements.disabled),this.reapplyStateStyle("disabled",["submit"]),this.elementRef.onclick=function(){})}},{key:"disableSubmitButton",value:function(n,r){var a;n.isSubmitProgrammaticallyDisabled=r!==!1,!(this.status.requestInProgress||this.status.loadingActive)&&(r===!1?(a=this._validationHandler)==null||a.call(this):this.changeToDisabledIcon(!0))}}],[{key:"createButtonContainerElement",value:function(){var n=document.createElement("div");return n.classList.add("input-button"),n}},{key:"createSubmitIconElement",value:function(){var n=pe.createSVGElement(Nc);return n.id="submit-icon",n}},{key:"createLoadingIconElement",value:function(){var n=document.createElement("div");return n.classList.add("dots-jumping"),n}},{key:"createStopIconElement",value:function(){var n=document.createElement("div");return n.id="stop-icon",n}}]),i}(ht);en.SUBMIT_CLASS="submit-button";en.LOADING_CLASS="loading-button";en.DISABLED_CLASS="disabled-button";var Dc=en,Fc=`<?xml version="1.0" encoding="utf-8"?>
<svg viewBox="0 0 32 32" xmlns="http://www.w3.org/2000/svg">
  <path d="M27.1 14.313V5.396L24.158 8.34c-2.33-2.325-5.033-3.503-8.11-3.503C9.902 4.837 4.901 9.847 4.899 16c.001 6.152 5.003 11.158 11.15 11.16 4.276 0 9.369-2.227 10.836-8.478l.028-.122h-3.23l-.022.068c-1.078 3.242-4.138 5.421-7.613 5.421a8 8 0 0 1-5.691-2.359A7.993 7.993 0 0 1 8 16.001c0-4.438 3.611-8.049 8.05-8.049 2.069 0 3.638.58 5.924 2.573l-3.792 3.789H27.1z"/>
</svg>
`,jc=`<?xml version="1.0" encoding="utf-8"?>
<svg viewBox="0 0 32 32" version="1.1" xmlns="http://www.w3.org/2000/svg">
  <title>capture</title>
  <path d="M0 16q0 3.264 1.28 6.208t3.392 5.12 5.12 3.424 6.208 1.248 6.208-1.248 5.12-3.424 3.392-5.12 1.28-6.208-1.28-6.208-3.392-5.12-5.088-3.392-6.24-1.28q-3.264 0-6.208 1.28t-5.12 3.392-3.392 5.12-1.28 6.208zM4 16q0-3.264 1.6-6.016t4.384-4.352 6.016-1.632 6.016 1.632 4.384 4.352 1.6 6.016-1.6 6.048-4.384 4.352-6.016 1.6-6.016-1.6-4.384-4.352-1.6-6.048z"></path>
</svg>
`,Bc=`<?xml version="1.0" encoding="utf-8"?>
<svg viewBox="0 0 1024 1024" xmlns="http://www.w3.org/2000/svg">
  <path d="M195.2 195.2a64 64 0 0 1 90.496 0L512 421.504 738.304 195.2a64 64 0 0 1 90.496 90.496L602.496 512 828.8 738.304a64 64 0 0 1-90.496 90.496L512 602.496 285.696 828.8a64 64 0 0 1-90.496-90.496L421.504 512 195.2 285.696a64 64 0 0 1 0-90.496z"/>
</svg>`,qc=`<?xml version="1.0" encoding="utf-8"?>
<svg viewBox="0 0 24 24" fill="none" xmlns="http://www.w3.org/2000/svg">
  <path d="M4.89163 13.2687L9.16582 17.5427L18.7085 8" stroke="#000000" stroke-width="2.5" stroke-linecap="round" stroke-linejoin="round"/>
</svg>`,zc=function(e){P(i,e);function i(t,n,r,a){var o;g(this,i),o=O(this,i,[t,["modal-content","modal-camera-content"],r]),o._stopped=!1,o._format="image/png",o._canvas=document.createElement("canvas"),o._canvas.classList.add("camera-modal-canvas");var s=o.addButtonsAndTheirEvents(n),l=s.captureButton,u=s.submitButton;return o._captureButton=l,o._submitButton=u,o._captureIcon=o._captureButton.children[0],o._refreshIcon=pe.createSVGElement(Fc),o._refreshIcon.classList.add("modal-svg-button-icon","modal-svg-refresh-icon"),(a==null?void 0:a.format)==="jpeg"&&(o._format="image/jpeg"),a!=null&&a.dimensions&&(o._dimensions=a.dimensions),o._contentRef.appendChild(o._canvas),o.extensionCloseCallback=o.stop,o}return y(i,[{key:"addButtonsAndTheirEvents",value:function(n){var r=Qe.createSVGButton(jc);r.classList.add("modal-svg-camera-button"),r.children[0].classList.add("modal-svg-camera-icon");var a=this.addCloseButton(Bc,!0);a.classList.add("modal-svg-close-button"),a.children[0].classList.add("modal-svg-close-icon");var o=Qe.createSVGButton(qc);return o.classList.add("modal-svg-submit-button"),this.addButtons(r,o),this.addButtonEvents(r,a,o,n),{captureButton:r,submitButton:o}}},{key:"addButtonEvents",value:function(n,r,a,o){var s=this;n.onclick=function(){s.capture()},r.addEventListener("click",this.stop.bind(this)),a.onclick=function(){var l=s.getFile();l&&Yn.addFilesToType([l],[o]),s.stop(),s.close()}}},{key:"stop",value:function(){var n=this;this._mediaStream&&this._mediaStream.getTracks().forEach(function(r){return r.stop()}),this._stopped=!0,setTimeout(function(){n._captureButton.replaceChildren(n._captureIcon),n._captureButton.classList.replace("modal-svg-refresh-button","modal-svg-camera-button");var r=n._canvas.getContext("2d");r==null||r.clearRect(0,0,n._canvas.width,n._canvas.height)},Qe.MODAL_CLOSE_TIMEOUT_MS)}},{key:"start",value:function(){var n=this;this._dataURL=void 0,this._submitButton.classList.add("modal-svg-submit-disabled"),this._stopped=!1,navigator.mediaDevices.getUserMedia({video:this._dimensions||!0}).then(function(r){if(n._mediaStream=r,!n.isOpen())return n.stop();var a=document.createElement("video");a.srcObject=r,a.play(),requestAnimationFrame(n.updateCanvas.bind(n,a,n._canvas))}).catch(function(r){console.error(r),n.stop(),n.close()})}},{key:"capture",value:function(){this._dataURL?(this._captureButton.replaceChildren(this._captureIcon),this._captureButton.classList.replace("modal-svg-refresh-button","modal-svg-camera-button"),this._submitButton.classList.add("modal-svg-submit-disabled"),this._dataURL=void 0):(this._captureButton.replaceChildren(this._refreshIcon),this._captureButton.classList.replace("modal-svg-camera-button","modal-svg-refresh-button"),this._submitButton.classList.remove("modal-svg-submit-disabled"),this._dataURL=this._canvas.toDataURL())}},{key:"getFile",value:function(){if(this._dataURL){for(var n=atob(this._dataURL.split(",")[1]),r=new Array(n.length),a=0;a<n.length;a++)r[a]=n.charCodeAt(a);var o=new Uint8Array(r),s=new Blob([o],{type:this._format}),l=this._format==="image/jpeg"?"jpeg":"png",u=Xi.getFileName(this._newFilePrefix||"photo",l);return new File([s],u,{type:s.type})}}},{key:"updateCanvas",value:function(n,r){if(!this._stopped){if(!this._dataURL){r.width=n.videoWidth,r.height=n.videoHeight;var a=r.getContext("2d");a==null||a.drawImage(n,0,0,r.width,r.height)}requestAnimationFrame(this.updateCanvas.bind(this,n,r))}}},{key:"openCameraModal",value:function(n){this.displayModalElements(),n.start()}}],[{key:"createCameraModalFunc",value:function(n,r,a,o){var s=new i(n,r,a,o);return s.openCameraModal.bind(s,s)}}]),i}(Qe),Uc=`<?xml version="1.0" encoding="utf-8"?>
<svg viewBox="0 0 32 32" version="1.1" xmlns="http://www.w3.org/2000/svg">
  <path d="M29 7h-4.599l-2.401-4h-12l-2.4 4h-4.6c-1 0-3 1-3 2.969v16.031c0 1.657 1.5 3 2.792 3h26.271c1.313 0 2.938-1.406 2.938-2.968v-16.032c0-1-1-3-3-3zM30 26.032c0 0.395-0.639 0.947-0.937 0.969h-26.265c-0.232-0.019-0.797-0.47-0.797-1v-16.031c0-0.634 0.851-0.953 1-0.969h5.732l2.4-4h9.802l1.785 3.030 0.55 0.97h5.731c0.705 0 0.99 0.921 1 1v16.032zM16 10c-3.866 0-7 3.134-7 7s3.134 7 7 7 7-3.134 7-7-3.134-7-7-7zM16 22c-2.757 0-5-2.243-5-5s2.243-5 5-5 5 2.243 5 5-2.243 5-5 5z"></path>
</svg>`,Hc=function(e){P(i,e);function i(t,n,r){var a;g(this,i);var o;a=O(this,i,[i.createButtonElement(),(o=r==null?void 0:r.button)==null?void 0:o.position,(r==null?void 0:r.button)||{},"Photo"]);var s=a.createInnerElements(a._customStyles);return r&&a.addClickEvent(t,n,r.modalContainerStyle,r.files),a.elementRef.classList.add("upload-file-button"),a.elementRef.appendChild(s.styles),a.reapplyStateStyle("styles"),a}return y(i,[{key:"createInnerElements",value:function(n){return{styles:this.createInnerElement(i.createSVGIconElement(),"styles",n)}}},{key:"createInnerElement",value:function(n,r,a){return Ye.createSpecificStateElement(this.elementRef,r,a)||n}},{key:"addClickEvent",value:function(n,r,a,o){var s=zc.createCameraModalFunc(n,r,a,o);this.elementRef.onclick=s}}],[{key:"createButtonElement",value:function(){var n=document.createElement("div");return n.classList.add("input-button"),n}},{key:"createSVGIconElement",value:function(){var n=pe.createSVGElement(Uc);return n.id="camera-icon",n}}]),i}(ht),Vc=function(){function e(i,t,n,r){g(this,e),this.elementRef=e.createPanelElement(i.inputAreaStyle);var a=new Nn(i,n),o={},s=this.createFileUploadComponents(i,n,r,o);i.speechToText&&!o.microphone&&(o.microphone={button:new Oc(i,a,t.addNewErrorMessage.bind(t))});var l=new Dc(i,a.inputElementRef,t,n,s);a.submit=l.submitFromInput.bind(l),ic.attach(i,n,a,s,l),i.submitUserMessage=l.programmaticSubmit.bind(l),o.submit={button:l},e.addElements(this.elementRef,a,o,r,s,i.dropupStyles)}return y(e,[{key:"createFileUploadComponents",value:function(t,n,r,a){var o,s,l,u,c=new Yn(this.elementRef,t.attachmentContainerStyle,n.demo);if(e.createUploadButtons(t,n.fileTypes||{},c,r,a),(o=n.camera)!=null&&o.files){var d=((s=a.images)==null?void 0:s.fileType)||c.addType(t,n.camera.files,"images");a.camera={button:new Hc(r,d,n.camera)}}if((l=n.recordAudio)!=null&&l.files){var h=((u=a.audio)==null?void 0:u.fileType)||c.addType(t,n.recordAudio.files,"audio");a.microphone={button:new Pc(h,n.recordAudio)}}return Nr.isEnabled(c,t.dragAndDrop)&&Nr.create(r,c,t.dragAndDrop),c}}],[{key:"createPanelElement",value:function(t){var n=document.createElement("div");return n.id="input",Object.assign(n.style,t),n}},{key:"createUploadButtons",value:function(t,n,r,a,o){Object.keys(n).forEach(function(s){var l=s,u=n[l];if(u.files){var c=r.addType(t,u.files,l),d=ec[l],h=d.id,p=d.svgString,v=d.dropupText,m=new rc(a,c,u,h,p,v);o[l]={button:m,fileType:c}}})}},{key:"addElements",value:function(t,n,r,a,o,s){he.addElements(t,n.elementRef);var l=Tt.create(),u=Yu.addButtons(l,r,a,s);$u.set(n.inputElementRef,l,o.elementRef,u),Tt.add(t,l)}}]),e}(),$c=function(){function e(){g(this,e)}return y(e,null,[{key:"createElements",value:function(t,n,r){var a=document.createElement("div");a.id="chat-view";var o=new Vu(t,n,r);n.websocket&&lt.createConnection(n,o);var s=new Vc(t,o,n,a);return he.addElements(a,o.elementRef,s.elementRef),a}},{key:"render",value:function(t,n,r,a){var o=e.createElements(t,r,a);n.replaceChildren(o)}}]),e}(),Gc=`#validate-property-key-view{height:100%;position:relative;display:flex;justify-content:center;align-items:center;padding:8px}#large-loading-ring{display:inline-block;width:50px;height:50px}#large-loading-ring:after{content:" ";display:block;width:38px;height:38px;margin:1px;border-radius:50%;border:5px solid #5fb2ff;border-color:#5fb2ff transparent #5fb2ff transparent;animation:large-loading-ring 1.4s linear infinite}@keyframes large-loading-ring{0%{transform:rotate(0)}to{transform:rotate(360deg)}}#insert-key-view{height:100%;position:relative}#insert-key-contents{text-align:center;position:absolute;top:44%;left:50%;transform:translate(-50%,-50%);width:82%;display:flex;max-width:700px}#insert-key-title{margin-bottom:15px}#insert-key-input-container{margin-right:2.7em;width:calc(100% - 80px)}#insert-key-input{padding:.3em 1.7em .3em .3em;border-width:1px;border-style:solid;border-radius:3px;width:100%;font-size:inherit}.insert-key-input-valid{border-color:gray}.insert-key-input-invalid{border-color:red}#visibility-icon-container{position:relative;float:right;cursor:pointer;-webkit-user-select:none;user-select:none}.visibility-icon{filter:brightness(0) saturate(100%) invert(63%) sepia(1%) saturate(9%) hue-rotate(43deg) brightness(98%) contrast(92%);position:absolute;right:-1.7em;top:-1.43em}#visible-icon{top:-1.4em}.visibility-icon:hover{filter:unset}.visibility-icon>*{pointer-events:none}#start-button{border:1px solid grey;color:#454545;border-radius:4px;width:3em;display:flex;justify-content:center;align-items:center;cursor:pointer;padding:.28em .3em;-webkit-user-select:none;user-select:none;background-color:#fff}#start-button:hover{background-color:#f2f2f2}#start-button:active{background-color:#d2d2d2}#insert-key-help-text-container{width:100%;position:absolute;margin-top:32px;margin-bottom:20px}#insert-key-help-text-contents{width:100%;position:absolute}#insert-key-input-invalid-text{display:block;margin-top:1em;margin-bottom:.5em;color:red}.insert-key-input-help-text{display:block;margin-top:16px}#loading-ring{display:inline-block;width:16px;height:16px}#loading-ring:after{content:" ";display:block;width:11px;height:11px;margin:1px;border-radius:50%;border:2px solid #0084ff;border-color:#0084ff transparent #0084ff transparent;animation:loading-ring 1.2s linear infinite}@keyframes loading-ring{0%{transform:rotate(0)}to{transform:rotate(360deg)}}#error-view{color:red;font-size:1.2em;line-height:1.3em;margin-top:-5px;text-align:center;height:100%;display:flex;justify-content:center;align-items:center;padding-left:8px;padding-right:8px}.intro-panel{position:absolute;display:flex;justify-content:center;right:0;bottom:0;left:0;margin:auto;height:fit-content;top:-2.5em}#internal-intro-panel{width:250px;height:min-content;display:block;border-radius:5px;overflow:auto;border:1px solid rgb(203,203,203);padding:10px;max-height:calc(100% - 6.8em)}#internal-intro-panel>p{margin-block-start:.8em;margin-block-end:.8em}pre code.hljs{display:block;overflow-x:auto;padding:1em}code.hljs{padding:3px 5px}/*!
  Theme: a11y-dark
  Author: @ericwbailey
  Maintainer: @ericwbailey

  Based on the Tomorrow Night Eighties theme: https://github.com/isagalaev/highlight.js/blob/master/src/styles/tomorrow-night-eighties.css
*/.hljs{background:#2b2b2b;color:#f8f8f2}.hljs-comment,.hljs-quote{color:#d4d0ab}.hljs-deletion,.hljs-name,.hljs-regexp,.hljs-selector-class,.hljs-selector-id,.hljs-tag,.hljs-template-variable,.hljs-variable{color:#ffa07a}.hljs-built_in,.hljs-link,.hljs-literal,.hljs-meta,.hljs-number,.hljs-params,.hljs-type{color:#f5ab35}.hljs-attribute{color:gold}.hljs-addition,.hljs-bullet,.hljs-string,.hljs-symbol{color:#abe338}.hljs-section,.hljs-title{color:#00e0e0}.hljs-keyword,.hljs-selector-tag{color:#dcc6e0}.hljs-emphasis{font-style:italic}.hljs-strong{font-weight:700}@media screen and (-ms-high-contrast: active){.hljs-addition,.hljs-attribute,.hljs-built_in,.hljs-bullet,.hljs-comment,.hljs-link,.hljs-literal,.hljs-meta,.hljs-number,.hljs-params,.hljs-quote,.hljs-string,.hljs-symbol,.hljs-type{color:highlight}.hljs-keyword,.hljs-selector-tag{font-weight:700}}#messages{overflow:auto}.outer-message-container:last-child{margin-bottom:5px}.inner-message-container{display:flex;margin-left:auto;margin-right:auto;width:calc(97.5% - 24px);max-width:100%}.message-bubble{margin-top:10px;word-wrap:break-word;width:fit-content;max-width:60%;border-radius:10px;padding:.42em .55em;height:fit-content;line-height:1.26em}.user-message-text{color:#fff;background-color:#0084ff;margin-right:0;margin-left:auto}.ai-message-text{color:#000;background-color:#e4e6eb;margin-left:0;margin-right:auto}.html-message{max-width:unset}.error-message-text{margin:14px auto 10px;background-color:#f4c0c0;color:#474747;text-align:center;max-width:95%}.loading-message-text{width:1em;padding:.6em .75em .6em 1.3em}.message-bubble>p:first-child{margin-top:0}.message-bubble>p:last-child{margin-bottom:0}pre{overflow:auto;display:block;word-break:break-all;word-wrap:break-word;border-radius:7px;background:#2b2b2b;color:#f8f8f2;margin-top:.8em;margin-bottom:.8em;padding:.6em;font-size:.9em;line-height:1.5em}.image-message{padding:0;display:flex;background-color:#ddd}.image-message>*,.image-message>*>*{width:100%;border-radius:8px;display:flex}.audio-message{width:60%;max-width:300px;height:2.2em;max-height:54px;padding:0;background-color:unset}.audio-player{width:100%;height:100%}.audio-player-safari{height:fit-content;width:40px}.audio-player-safari-left{float:left}.audio-player-safari-right{float:right}.any-file-message-bubble{padding:1px}.any-file-message-contents{display:flex}.any-file-message-icon-container{width:1.3em;min-width:1.3em;position:relative;border-radius:4px;margin-left:6px;margin-right:2px}.any-file-message-icon{background-color:#fff;border-radius:4px;position:absolute;width:1em;height:1.25em;padding:1px;margin-top:auto;margin-bottom:auto;top:0;bottom:0}.any-file-message-text{padding-top:5px;overflow-wrap:anywhere;padding-bottom:5px;padding-right:7px}.message-bubble>a{color:inherit}.left-item-position{margin-right:10px}.right-item-position{margin-left:10px}.deep-chat-web-model-button{margin-top:10px;margin-bottom:5px;margin-left:1px}.avatar{padding-top:5px;width:1.5em;height:1.5em;border-radius:1px}.avatar-container{margin-top:9px}.name{margin-top:16px;font-size:15px}#drag-and-drop{position:absolute;display:none;z-index:10;height:calc(100% - 10px);width:calc(100% - 10px);background-color:#70c6ff4d;border:5px dashed #6dafff}#file-attachment-container{position:absolute;height:3.6em;width:calc(80% - 4px);top:-2.5em;border-radius:5px;overflow:auto;text-align:left;background-color:#d7d7d73b;padding-left:4px}.file-attachment{width:2.85em;height:2.85em;display:inline-flex;margin-right:.6em;margin-bottom:.44em;margin-top:4px;position:relative;background-color:#fff;border-radius:5px}.image-attachment{width:100%;height:100%;object-fit:cover;border-radius:5px}.border-bound-attachment{width:calc(100% - 2px);height:calc(100% - 2px);border:1px solid #c3c3c3;border-radius:5px;overflow:hidden}.border-bound-attachment-safari{width:calc(100% - 1px);height:calc(100% - 1px)}.audio-attachment-icon-container{cursor:pointer}.audio-attachment-icon-container:hover{background-color:#f8f8f8}.attachment-icon{left:0;right:0;bottom:0;top:2px;margin:auto;position:absolute;width:25px;-webkit-user-select:none;user-select:none}.not-removable-attachment-icon{top:0;right:0;bottom:0;left:0}.play-icon{filter:brightness(0) saturate(100%) invert(17%) sepia(0%) saturate(1392%) hue-rotate(67deg) brightness(98%) contrast(97%)}.stop-icon{filter:brightness(0) saturate(100%) invert(29%) sepia(90%) saturate(1228%) hue-rotate(198deg) brightness(93%) contrast(98%)}.audio-placeholder-text-3-digits{padding-left:.26rem}.audio-placeholder-text-4-digits{padding-left:.1rem}.any-file-attachment{padding:2px 0}.file-attachment-text-container{position:absolute;width:inherit;display:flex;align-items:center;height:100%;top:-1px}.audio-placeholder-text-3-digits-container{padding-top:1px;cursor:default}.any-file-attachment-text{text-overflow:ellipsis;white-space:nowrap;overflow:hidden;padding-left:.13em;margin-left:auto;margin-right:auto}.remove-file-attachment-button{height:1.25em;width:1.25em;border:1px solid #cfcfcf;border-radius:25px;background-color:#fff;top:-4px;right:-5px;position:absolute;display:flex;justify-content:center;cursor:pointer;-webkit-user-select:none;user-select:none}.remove-file-attachment-button:hover{background-color:#e4e4e4}.remove-file-attachment-button:active{background-color:#d7d7d7}.x-icon{color:#4e4e4e;top:-.075em;position:relative;font-size:1.05em}.modal{display:none;flex-direction:column;align-items:center;justify-content:center;position:absolute;width:80%;max-width:420px;max-height:80%;margin:auto;top:0;right:0;bottom:0;left:0;z-index:2}.modal-content{border-top:1px solid rgb(217,217,217);border-left:1px solid rgb(217,217,217);border-right:1px solid rgb(217,217,217);border-top-left-radius:inherit;border-top-right-radius:inherit;background-color:#fff;overflow-y:auto;height:fit-content;max-height:calc(100% - 3.3em);width:100%}.modal-content>p{margin-left:1em;margin-right:1em}.modal-content>ul{margin-right:1em}.modal-button-panel{height:3.3em;border:1px solid;border-color:rgb(223,223,223) rgb(217,217,217) rgb(217,217,217);border-bottom-left-radius:inherit;border-bottom-right-radius:inherit;background-color:#fff;text-align:center;justify-content:center;display:flex;width:100%}.modal-button{min-width:2.5em;text-align:center;color:#fff;border-radius:5px;padding:.4em .4em .3em;height:1.25em;background-color:#3279b2;top:0;bottom:0;cursor:pointer;-webkit-user-select:none;user-select:none;margin:auto .31em}.modal-button:hover{background-color:#276da7}.modal-button:active{background-color:#1b5687}.modal-svg-button{padding:0 0 2px;width:2em;height:1.8em}.modal-svg-button-icon{width:100%;height:100%;filter:brightness(0) saturate(100%) invert(100%) sepia(15%) saturate(4%) hue-rotate(346deg) brightness(101%) contrast(102%)}#modal-background-panel{position:absolute;width:100%;height:100%;background-color:#00000042;z-index:1;display:none}.show-modal-background{animation:fadeInBackground .3s ease-in-out}@keyframes fadeInBackground{0%{opacity:0}to{opacity:1}}.show-modal{animation:fadeInModal .3s ease-in-out}@keyframes fadeInModal{0%{opacity:0;scale:.95}to{opacity:1;scale:1}}.hide-modal-background{animation:fadeOutBackground .2s ease-in-out}@keyframes fadeOutBackground{0%{opacity:1}to{opacity:0}}.hide-modal{animation:fadeOutModal .2s ease-in-out}@keyframes fadeOutModal{0%{opacity:1;scale:1}to{opacity:0;scale:.95}}.modal-camera-content{overflow:hidden;text-align:center;border:unset;height:100%;background-color:#2a2a2a;display:flex;justify-content:center}.camera-modal-canvas{max-width:100%;max-height:100%;margin-top:auto;margin-bottom:auto}.modal-svg-submit-button{background-color:green}.modal-svg-submit-button:hover{background-color:#007500}.modal-svg-submit-button:active{background-color:#006500}.modal-svg-submit-disabled{pointer-events:none;background-color:#747474}.modal-svg-close-button{height:1.56em;padding-top:.37em;padding-bottom:0;background-color:#c13e3e}.modal-svg-close-button:hover{background-color:#b43434}.modal-svg-close-button:active{background-color:#972929}.modal-svg-close-icon{width:80%;height:80%}.modal-svg-camera-button{height:1.6em;padding-top:.38em;padding-bottom:0}.modal-svg-camera-icon{height:76%}.modal-svg-refresh-icon{height:105%}.modal-svg-refresh-button{height:1.66em;padding-top:.11em;padding-bottom:.21em}.input-button-container{position:relative;z-index:1}.inside-right{position:absolute;right:calc(10% + .35em);bottom:.85em}.inside-left{position:absolute;left:calc(10% + .35em);bottom:.85em}.outside-left{position:absolute;right:calc(11px - .55em);bottom:.88em}.outside-right{position:absolute;left:calc(11px - .55em);bottom:.88em}#upload-images-icon{position:absolute;pointer-events:none;width:1.45em;height:1.45em;left:.11em;bottom:.08em;filter:brightness(0) saturate(100%) invert(43%) sepia(0%) saturate(740%) hue-rotate(77deg) brightness(99%) contrast(92%)}#upload-gifs-icon{position:absolute;pointer-events:none;width:1.5em;height:1.48em;left:.07em;bottom:.08em;filter:brightness(0) saturate(100%) invert(49%) sepia(0%) saturate(2586%) hue-rotate(12deg) brightness(93%) contrast(90%)}#upload-audio-icon{position:absolute;pointer-events:none;width:1.21em;height:1.21em;left:.17em;bottom:.2em;filter:brightness(0) saturate(100%) invert(15%) sepia(0%) saturate(337%) hue-rotate(125deg) brightness(91%) contrast(94%);transform:scaleX(.95)}#camera-icon{position:absolute;pointer-events:none;width:1.21em;height:1.21em;left:.23em;bottom:.2em;filter:brightness(0) saturate(100%) invert(52%) sepia(0%) saturate(161%) hue-rotate(164deg) brightness(91%) contrast(92%);transform:scaleX(.95)}#upload-mixed-files-icon{position:absolute;pointer-events:none;width:1.21em;height:1.21em;left:.25em;bottom:.2em;filter:brightness(0) saturate(100%) invert(53%) sepia(0%) saturate(36%) hue-rotate(74deg) brightness(98%) contrast(93%);transform:scaleX(.95)}#interim-text{color:gray}#microphone-button{padding-top:.5px}.outer-button-container>#microphone-button{padding-bottom:1px}#microphone-icon{position:absolute;pointer-events:none;width:1.21em;height:1.21em;left:.25em;bottom:.25em}.default-microphone-icon{filter:brightness(0) saturate(100%) invert(32%) sepia(0%) saturate(924%) hue-rotate(46deg) brightness(95%) contrast(99%)}.active-microphone-icon{filter:brightness(0) saturate(100%) invert(10%) sepia(97%) saturate(7495%) hue-rotate(0deg) brightness(101%) contrast(107%);border-radius:10px}.command-microphone-icon{filter:brightness(0) saturate(100%) invert(42%) sepia(96%) saturate(1067%) hue-rotate(77deg) brightness(99%) contrast(102%)}.unsupported-microphone{display:none}#submit-icon{height:100%;filter:brightness(0) saturate(100%) invert(32%) sepia(0%) saturate(924%) hue-rotate(46deg) brightness(95%) contrast(99%);width:1.21em}#stop-icon{background-color:#acacac;position:absolute;width:.95em;height:.95em;left:.35em;bottom:.35em;border-radius:2px}.submit-button-enlarged{scale:1.1;margin-right:.3em;margin-left:.3em}.dots-jumping{position:relative;left:calc(-9990px + .275em);width:.22em;height:.22em;border-radius:5px;background-color:#848484;color:#848484;box-shadow:9990px 0 #848484,calc(9990px + .44em) 0 0 0 #848484,calc(9990px + .8em) 0 0 0 #848484;animation:dots-jumping 1.5s infinite linear;bottom:-.7em}@keyframes dots-jumping{0%{box-shadow:9990px 0 #848484,calc(9990px + .44em) 0 0 0 #848484,calc(9990px + .8em) 0 0 0 #848484}16.667%{box-shadow:9990px -6px #848484,calc(9990px + .44em) 0 0 0 #848484,calc(9990px + .8em) 0 0 0 #848484}33.333%{box-shadow:9990px 0 #848484,calc(9990px + .44em) 0 0 0 #848484,calc(9990px + .8em) 0 0 0 #848484}50%{box-shadow:9990px 0 #848484,calc(9990px + .44em) -6px 0 0 #848484,calc(9990px + .8em) 0 0 0 #848484}66.667%{box-shadow:9990px 0 #848484,calc(9990px + .44em) 0 0 0 #848484,calc(9990px + .8em) 0 0 0 #848484}83.333%{box-shadow:9990px 0 #848484,calc(9990px + .44em) 0 0 0 #848484,calc(9990px + .8em) -6px 0 0 #848484}to{box-shadow:9990px 0 #848484,calc(9990px + .44em) 0 0 0 #848484,calc(9990px + .8em) 0 0 0 #848484}}.dots-flashing{position:relative;width:.45em;height:.45em;border-radius:5px;background-color:var(--message-dots-color);color:var(--message-dots-color);animation:dots-flashing 1s infinite linear alternate;animation-delay:.5s}.dots-flashing:before,.dots-flashing:after{content:"";display:inline-block;position:absolute;top:0}.dots-flashing:before{left:-.7em;width:.45em;height:.45em;border-radius:5px;background-color:var(--message-dots-color);color:var(--message-dots-color);animation:dots-flashing 1s infinite alternate;animation-delay:0s}.dots-flashing:after{left:.7em;width:.45em;height:.45em;border-radius:5px;background-color:var(--message-dots-color);color:var(--message-dots-color);animation:dots-flashing 1s infinite alternate;animation-delay:1s}@keyframes dots-flashing{0%{background-color:var(--message-dots-color)}50%,to{background-color:var(--message-dots-color-fade)}}.input-button{border-radius:4px;cursor:pointer;margin-bottom:.2em;-webkit-user-select:none;user-select:none}.input-button-svg{width:1.65em;height:1.65em}.input-button:hover{background-color:#9c9c9c2e}.input-button:active{background-color:#9c9c9c5e}.loading-button{cursor:auto}.loading-button:hover{background-color:unset}.text-button{filter:unset!important;display:flex;justify-content:center;align-items:center;margin-left:4px;margin-right:4px;height:1.6em}#text-input-container{background-color:#fff;width:80%;display:flex;border:1px solid #0000001a;border-radius:5px;margin-top:.8em;margin-bottom:.8em;box-shadow:#959da533 0 1px 12px;overflow-y:auto;max-height:200px;position:relative}.text-input-container-left-adjustment{margin-left:1.5em}.text-input-container-right-adjustment{margin-right:1.5em}.text-input-container-left-small-adjustment{margin-left:1.1em}.text-input-container-left-small-adjustment>.outside-left{right:calc(14px - .55em)}.text-input-container-right-small-adjustment{margin-right:1.1em}.text-input-container-right-small-adjustment>.outside-right{left:calc(14px - .55em)}#text-input{text-align:left;outline:none;word-wrap:break-word;line-break:auto}.text-input-styling{padding:.4em .5em;overflow:overlay;width:100%}.text-input-inner-left-adjustment{padding-left:2.2em}.text-input-inner-right-adjustment{padding-right:2em}.text-input-disabled{pointer-events:none;-webkit-user-select:none;user-select:none}.text-input-placeholder{color:gray}.outside-right>#dropup-menu,.inside-right>#dropup-menu{right:0}#dropup-icon{position:absolute;pointer-events:none;width:1.16em;height:1.2em;left:.265em;bottom:.43em;filter:brightness(0) saturate(100%) invert(54%) sepia(0%) saturate(724%) hue-rotate(6deg) brightness(92%) contrast(90%)}#dropup-menu{background-color:#fff;position:absolute;transform:translateY(-100%);border-radius:5px;z-index:1;top:-.49em;box-shadow:#0003 -1px 2px 10px,#0000001a 0 2px 4px;cursor:pointer;-webkit-user-select:none;user-select:none}.dropup-menu-item{height:1.4em;padding:.28em .84em .28em .35em;display:flex;position:relative}.dropup-menu-item:first-child{padding-top:.49em;border-top-left-radius:inherit;border-top-right-radius:inherit}.dropup-menu-item:last-child{padding-bottom:.45em;border-bottom-left-radius:inherit;border-bottom-right-radius:inherit}.dropup-menu-item-icon{width:1.39em;position:relative;margin-right:.56em}.dropup-menu-item-icon>svg{bottom:0!important;top:0!important;margin-bottom:auto;margin-top:auto}.dropup-menu-item-text{margin-top:.08em;width:max-content}#input{width:100%;display:inline-flex;text-align:center;margin-left:auto;margin-right:auto;margin-top:auto;position:relative;justify-content:center}#chat-view{height:100%;display:grid;grid-template-columns:100%}::-webkit-scrollbar{width:9px;height:9px}::-webkit-scrollbar-thumb{background-color:#d0d0d0;border-radius:5px}::-webkit-scrollbar-track{background-color:#f2f2f2}:host{all:initial;display:table-cell}#container{height:inherit;width:inherit;overflow:hidden}
`,Wc=Object.defineProperty,U=function(i,t,n,r){for(var a=void 0,o=i.length-1,s;o>=0;o--)(s=i[o])&&(a=s(t,n,a)||a);return a&&Wc(t,n,a),a},q=function(e){P(i,e);function i(){var t;return g(this,i),t=O(this,i),t.getMessages=function(){return[]},t.submitUserMessage=function(){return console.warn("submitUserMessage failed - please wait for chat view to render before calling this property.")},t.focusInput=function(){return yi.focusFromParentElement(t._elementRef)},t.refreshMessages=function(){},t.clearMessages=function(){},t.scrollToBottom=function(){},t.disableSubmitButton=function(){},t._hasBeenRendered=!1,t._auxiliaryStyleApplied=!1,t._addMessage=function(){return console.warn("addMessage failed - please wait for chat view to render before calling this property.")},ju.appendStyleSheetToHead(),t._elementRef=document.createElement("div"),t._elementRef.id="container",t.attachShadow({mode:"open"}).appendChild(t._elementRef),on.apply(Gc,t.shadowRoot),setTimeout(function(){t._hasBeenRendered||t.onRender()},20),t}return y(i,[{key:"changeToChatView",value:function(){this._activeService&&(this._activeService.validateConfigKey=!1),this.onRender()}},{key:"onRender",value:function(){var n;(!this._activeService||this._activeService.demo)&&(this._activeService=Fu.create(this)),this.auxiliaryStyle&&!this._auxiliaryStyleApplied&&(on.apply(this.auxiliaryStyle,this.shadowRoot),this._auxiliaryStyleApplied=!0),on.applyDefaultStyleToComponent(this.style,this.chatStyle),Re.checkForContainerStyles(this,this._elementRef),this._activeService.key&&this._activeService.validateConfigKey?rs.render(this._elementRef,this.changeToChatView.bind(this),this._activeService):!(this._activeService instanceof ce)||this._activeService.key?((n=this._childElement)!==null&&n!==void 0||(this._childElement=this.children[0]),$c.render(this,this._elementRef,this._activeService,this._childElement)):this._activeService instanceof ce&&uu.render(this._elementRef,this.changeToChatView.bind(this),this._activeService),this._hasBeenRendered=!0,Mt.onRender(this)}},{key:"disconnectedCallback",value:function(){Vn.chat=void 0}}]),i}(au);U([z("object")],q.prototype,"directConnection");U([z("object")],q.prototype,"request");U([z("object")],q.prototype,"webModel");U([z("object")],q.prototype,"stream");U([z("object")],q.prototype,"requestBodyLimits");U([z("function")],q.prototype,"requestInterceptor");U([z("function")],q.prototype,"responseInterceptor");U([z("function")],q.prototype,"validateInput");U([z("object")],q.prototype,"chatStyle");U([z("object")],q.prototype,"attachmentContainerStyle");U([z("object")],q.prototype,"dropupStyles");U([z("object")],q.prototype,"inputAreaStyle");U([z("object")],q.prototype,"textInput");U([z("object")],q.prototype,"submitButtonStyles");U([z("string")],q.prototype,"auxiliaryStyle");U([z("array")],q.prototype,"initialMessages");U([z("object")],q.prototype,"introMessage");U([z("object")],q.prototype,"avatars");U([z("object")],q.prototype,"names");U([z("boolean")],q.prototype,"displayLoadingBubble");U([z("object")],q.prototype,"errorMessages");U([z("object")],q.prototype,"messageStyles");U([z("object")],q.prototype,"textToSpeech");U([z("object")],q.prototype,"speechToText");U([z("object")],q.prototype,"images");U([z("object")],q.prototype,"gifs");U([z("object")],q.prototype,"camera");U([z("object")],q.prototype,"audio");U([z("object")],q.prototype,"microphone");U([z("object")],q.prototype,"mixedFiles");U([z("object")],q.prototype,"dragAndDrop");U([z("object")],q.prototype,"introPanelStyle");U([z("object")],q.prototype,"htmlClassUtilities");U([z("function")],q.prototype,"onNewMessage");U([z("function")],q.prototype,"onClearMessages");U([z("function")],q.prototype,"onComponentRender");U([z("function")],q.prototype,"onError");U([z("object")],q.prototype,"demo");U([z("object")],q.prototype,"_insertKeyViewStyles");customElements.define("deep-chat",q);const Qi="Chat failed to load. Clear chat or try again in a moment.";class _e extends Error{constructor(i,t,n){super(i),this.details=t,this.code=n,this.name="CustomError"}}function It(e){e instanceof _e&&e.details&&console.error("Details:",e.details)}async function yn(e,i="GET",t=null,n){const r={method:i,headers:{"Content-Type":"application/json"}};n&&(r.headers={...r.headers,Authorization:`Bearer ${n}`}),i==="POST"&&t&&(r.body=JSON.stringify(t));try{const a=await fetch(`https://public-api.wordpress.com/wpcom/v2/${e}`,r);if(!a.ok)throw a.status===429?new _e("Rate limit exceeded","Please try again later","RATE_LIMIT"):a.status===403?new _e("Request failed",`Status: ${a.status}`,"REQUEST_UNAUTHORIZED"):new _e("Request failed",`Status: ${a.status}`,"REQUEST_FAILED");return await a.json()}catch(a){throw a instanceof _e?a:new _e("Request failed",a.message,"UNKNOWN_ERROR")}}class Kc{constructor(i,t){K(this,"token");K(this,"bot");this.token=t,this.bot=i}async loadPreviousMessages(i,t){return await yn(`odie/chat/${this.bot}/${i}?${t?`&session_id=${t}`:""}`,"GET",null,this.token)}async sendMessage(i,t,n){var o,s;const r={message:i,session_id:n},a=await yn(`odie/chat/${this.bot}/${t||""}`,"POST",r,this.token);if(!a)throw new _e("Failed to update chat session","No response data");return{chatId:a.chat_id,sessionId:a.session_id,messageId:(o=a.messages[0])==null?void 0:o.message_id,content:(s=a==null?void 0:a.messages[0])==null?void 0:s.content,sources:a.messages[0].context.sources}}async sendFeedback(i,t,n,r){const a={rating_value:n?1:0,session_id:r};if(!i||!t)throw new _e("Failed to send feedback","No chat ID or message ID");return await yn(`odie/chat/${this.bot}/${i}/${t}/feedback?`,"POST",a,this.token)}}class ea{constructor(i,t,n,r=!1,a=null){K(this,"_chatBot");K(this,"_chatElementRef");K(this,"_chatId");K(this,"_sessionId");K(this,"_chatService");K(this,"_hideInputArea",!1);K(this,"_notice");if(!t)throw new Error("Error initializing chat");this._chatBot=t,this._chatId=this.getChatIdFromStorage(),this._sessionId=this.getSessionIdFromStorage(),this._chatElementRef=document.createElement("deep-chat"),this._chatElementRef.id="chat-element",i.appendChild(this._chatElementRef),this._chatService=new Kc(t,n),this._hideInputArea=r,this._notice=a,this.initializeChat()}initializeChat(){this.setupMessageHandlers(),this.applyChatStyles(),this.setupHtmlClassUtilities(),this.setupOnComponentRender()}async loadPreviousMessages(){if(this._chatId){const i=await this._chatService.loadPreviousMessages(this._chatId,this._sessionId);this.addMessagesToHistory(i.messages)}return[]}async handleChatRequest(i,t){try{const{chatId:n,sessionId:r,messageId:a=0,content:o,sources:s}=await this._chatService.sendMessage(i.messages[0].text,this._chatId,this._sessionId);this._chatId=n,this.saveChatIdToStorage(n),this._sessionId=r,this.saveSessionIdToStorage(r),t.onResponse({role:"ai",html:or(o,s,a,this._notice)})}catch(n){t.onResponse({error:n.message})}}setupMessageHandlers(){this._chatElementRef.request={handler:this.handleChatRequest.bind(this)}}applyChatStyles(){this._chatElementRef.messageStyles=this.getMessageStyles(),this._chatElementRef.chatStyle=this.getChatStyle(),this._chatElementRef.inputAreaStyle=this.getInputAreaStyle()}getMessageStyles(){return{default:{shared:{innerContainer:{width:"var(--bubble-max-width)"},bubble:{padding:"var(--bubble-padding)"}},user:{bubble:{borderBottomRightRadius:"0",border:"var(--reply-bubble-border)",borderRadius:"var(--reply-bubble-border-radius)",backgroundColor:"var(--reply-bubble-color)",color:"var(--reply-color)",overflow:"hidden",fontFamily:"var(--font-family)",fontSize:"var(--text-size)"}},ai:{bubble:{width:"100%",maxWidth:"100%",border:"var(--ai-bubble-border)",borderRadius:"var(--ai-bubble-border-radius)",backgroundColor:"var(--ai-bubble-color)",color:"var(--ai-text-color)",fontFamily:"var(--font-family)",fontSize:"var(--text-size)"}}}}}getChatStyle(){return{border:"none",width:"100%",height:"100%",maxWidth:"100vw",backgroundColor:"transparent"}}getInputAreaStyle(){return{display:this._hideInputArea?"none":"flex"}}setupOnComponentRender(){this._chatElementRef.onNewMessage=()=>{setTimeout(()=>{const i=this._chatElementRef.shadowRoot.getElementById("messages"),[t]=Array.from(i.getElementsByClassName("user-message")).slice(-1);!t||i.scrollTop<t.offsetTop||(i.scrollTop=t.offsetTop-5)})}}setupHtmlClassUtilities(){this._chatElementRef.htmlClassUtilities=this.getHtmlClassUtilities()}getHtmlClassUtilities(){return{response:{styles:{default:{margin:"-15px 0"}}},feedback:{styles:{default:{display:"flex",position:"absolute",top:"5px",right:"5px"}}},"feedback-text":{styles:{default:{width:"calc(100% - 42px)",paddingTop:"2px"}}},"feedback-icon":{styles:{default:{width:"20px",height:"20px",cursor:"pointer",borderRadius:"5px"}}},"feedback-icon-positive":{events:{click:i=>this.sendFeedback(!0,i)},styles:{hover:{fill:"green"}}},"feedback-icon-negative":{events:{click:i=>this.sendFeedback(!1,i)},styles:{default:{transform:"rotate(180deg)",marginLeft:"3px"},hover:{fill:"red"}}},footer:{styles:{default:{position:"relative"}}},sources:{styles:{default:{margin:"20px 0",color:"var(--ai-sources-color)",minHeight:"10px"}}},"sources-summary":{styles:{default:{fontWeight:"bold",cursor:"pointer",padding:"5px",borderRadius:"4px"}}},"sources-ul":{styles:{default:{listStyle:"none",padding:"0",margin:"10px 0 0"}}},"sources-li":{styles:{default:{margin:"10px 0"}}},"sources-a":{styles:{default:{textDecoration:"none",color:"inherit",display:"flex",alignItems:"center",marginLeft:"20px"},hover:{textDecoration:"underline"}}},"sources-icons":{styles:{default:{width:"16px",height:"16px",marginRight:"8px",fill:"currentColor"}}},notice:{styles:{default:{fontSize:"80%",textAlign:"right"}}},"notice-link":{styles:{default:{textDecoration:"none"},hover:{textDecoration:"underline"}}}}}getLocalStorageKey(i){return`ai-widget-${this._chatBot}-${i}-id`}saveChatIdToStorage(i){localStorage.setItem(this.getLocalStorageKey("chat"),i.toString())}saveSessionIdToStorage(i){localStorage.setItem(this.getLocalStorageKey("session"),i)}getChatIdFromStorage(){const i=localStorage.getItem(this.getLocalStorageKey("chat"));return i?parseInt(i,10):null}getSessionIdFromStorage(){return localStorage.getItem(this.getLocalStorageKey("session"))||null}setAvatar(i){this._chatElementRef.avatars={ai:{src:i,styles:{avatar:{display:i?"unset":"none",height:"var(--avatar-size)",marginTop:"-3px",width:"var(--avatar-size)"}}},user:{styles:{avatar:{display:"none"}}}}}setFirstMessage(i){this._chatElementRef.introMessage={text:i}}setErrorMessage(i){this._chatElementRef.introMessage={html:Wo(i)}}addMessagesToHistory(i){const t=i==null?void 0:i.map(n=>n.role==="user"?{role:"user",text:n.content}:{role:"ai",html:or(n.content,n.context.sources,n.message_id,this._notice)});this.setHistory(t)}clearChat(){var i;try{this._chatElementRef.clearMessages()}catch{this._chatElementRef.introMessage={text:((i=this._chatElementRef.introMessage)==null?void 0:i.text)||""}}this._chatId=null,localStorage.removeItem(this.getLocalStorageKey("chat")),this._sessionId=null,localStorage.removeItem(this.getLocalStorageKey("session")),this.setHistory([])}sendMessage(i){i.trim()!==""&&this._chatElementRef.submitUserMessage({text:i})}getChatId(){return this._chatId}getMessages(){return this._chatElementRef.getMessages()}async sendFeedback(i,t){const n=t.target,r=n==null?void 0:n.getAttribute("data-message-id");if(!r||!this._chatId)return;const a=n.closest(".feedback");if(a){const o=a.querySelector(".feedback-icon-positive"),s=a.querySelector(".feedback-icon-negative");o&&o.setAttribute("fill","currentColor"),s&&s.setAttribute("fill","currentColor")}try{await this._chatService.sendFeedback(this._chatId,Number(r),i,this._sessionId),n.setAttribute("fill",i?"green":"red")}catch(o){It(o)}}setHistory(i){this._chatElementRef.initialMessages=i}async load(){await this.loadPreviousMessages()}}class Yc extends HTMLElement{constructor(){super();K(this,"_shadowRoot");K(this,"_chatLogic");K(this,"_token");K(this,"_bot");K(this,"_avatar");K(this,"_title");K(this,"_subtitle");K(this,"_firstMessage");K(this,"_clearOnError",!1);K(this,"_notice",null);if(this._shadowRoot=this.attachShadow({mode:"open"}),this._chatLogic=null,this._token=this.getAttribute("token"),this._bot=this.getAttribute("bot"),this._avatar=this.getAttribute("avatar"),this._title=this.getAttribute("title"),this._subtitle=this.getAttribute("subtitle"),this._firstMessage=this.getAttribute("first-message"),this._clearOnError=!!this.hasAttribute("clear-on-error"),this.hasAttribute("notice")){try{this._notice=JSON.parse(this.getAttribute("notice")||"{}")}catch{}this.hasAttribute("notice")&&(this._notice=this.getAttribute("notice")||"{}")}this._shadowRoot.innerHTML=Uo}static get observedAttributes(){return["token","bot","avatar","title","subtitle","first-message","clear-on-error","notice"]}attributeChangedCallback(t,n,r){if(n!==r){const o={token:"_token",bot:"_bot",avatar:"_avatar",title:"_title",subtitle:"_subtitle","first-message":"_firstMessage",notice:"_notice"}[t];o&&(this[o]=r)}}setTitle(t){this._shadowRoot.querySelector(".header-title").textContent=t}setSubtitle(t){this._shadowRoot.querySelector(".header-subtitle").textContent=t}setLoaded(){this._shadowRoot.querySelector("#chat-widget").classList.add("loaded")}load(){var t;this._chatLogic&&((t=this._chatLogic)==null||t.load().then(()=>{var n,r;(n=this._chatLogic)==null||n.setAvatar(this._avatar),(r=this._chatLogic)==null||r.setFirstMessage(this._firstMessage),this.setSupportLink(),this.setTitle(this._title),this.setSubtitle(this._subtitle),this.setLoaded()}).catch(n=>this.handleOnLoadError(n)))}setSupportLink(){const t=document.createElement("div");t.id="support-link";const n=document.createElement("slot");n.name="support-link",t.appendChild(n),this._shadowRoot.querySelector("#chat-content").appendChild(t)}connectedCallback(){var t;this.addEventListeners(),this._chatLogic=new ea(this._shadowRoot.querySelector("#chat-content"),this._bot,this._token,!1,this._notice),(t=this._chatLogic)==null||t.load().then(()=>{var n,r;(n=this._chatLogic)==null||n.setAvatar(this._avatar),(r=this._chatLogic)==null||r.setFirstMessage(this._firstMessage),this.setSupportLink(),this.setTitle(this._title),this.setSubtitle(this._subtitle),this.setLoaded()}).catch(n=>{var r;It(n),(r=this._chatLogic)==null||r.setErrorMessage("We failed to load the chat. Please try again later or start a new chat."),this.setTitle(this._title),this.setSubtitle(this._subtitle),this.setLoaded()})}addEventListeners(){const t=this._shadowRoot.querySelector("#chat-icon"),n=this._shadowRoot.querySelector("#chat-close"),r=this._shadowRoot.querySelector("#chat-clear");this._shadowRoot.addEventListener("keypress",a=>a.stopPropagation()),t.addEventListener("click",()=>this.toggleChat()),n.addEventListener("click",()=>this.toggleChat()),r.addEventListener("click",()=>this.clearChat())}toggleChat(){const t=this._shadowRoot.querySelector("#chat-widget");t.classList.contains("open")?(t.classList.add("closing"),setTimeout(()=>{t.classList.remove("open","closing")},500)):t.classList.add("open")}clearChat(){this._chatLogic&&(this._chatLogic.clearChat(),this.load())}handleOnLoadError(t){var n;It(t),this.setTitle(this._title),this.setSubtitle(this._subtitle),this._clearOnError?this.clearChat():(n=this._chatLogic)==null||n.setErrorMessage(Qi),this.setLoaded()}getChatId(){return this._chatLogic?this._chatLogic.getChatId():null}getMessages(){return this._chatLogic?this._chatLogic.getMessages():[]}}class Jc extends HTMLElement{constructor(){super();K(this,"_shadowRoot");K(this,"_chatLogic");K(this,"_token");K(this,"_bot");K(this,"_avatar");K(this,"_firstMessage");K(this,"_hideInputArea",!1);K(this,"_clearOnError",!1);K(this,"_notice",null);this._shadowRoot=this.attachShadow({mode:"open"}),this._chatLogic=null,this._token=this.getAttribute("token"),this._bot=this.getAttribute("bot"),this._avatar=this.getAttribute("avatar"),this._firstMessage=this.getAttribute("first-message"),this._clearOnError=!!this.hasAttribute("clear-on-error"),this.hasAttribute("notice")&&(this._notice=this.getAttribute("notice")),this._shadowRoot.innerHTML=Ho}static get observedAttributes(){return["token","bot","avatar","first-message","hide-input-area","clear-on-error","notice"]}attributeChangedCallback(t,n,r){if(n!==r){const o={token:"_token",bot:"_bot",avatar:"_avatar","first-message":"_firstMessage","hide-input-area":"_hideInputArea","clear-on-error":"_clearOnError",notice:"_notice"}[t];o&&(this[o]=r)}}setLoaded(){this._shadowRoot.querySelector("#chat-embed").classList.add("loaded")}load(){this._chatLogic&&this._chatLogic.load().then(()=>{var t,n;(t=this._chatLogic)==null||t.setAvatar(this._avatar),(n=this._chatLogic)==null||n.setFirstMessage(this._firstMessage),this.setLoaded()}).catch(t=>this.handleOnLoadError(t))}connectedCallback(){this.addEventListeners(),this._chatLogic=new ea(this._shadowRoot.querySelector("#chat-content"),this._bot,this._token,this._hideInputArea,this._notice),this.load()}addEventListeners(){const t=this._shadowRoot.querySelector("#chat-clear");this._shadowRoot.addEventListener("keypress",n=>n.stopPropagation()),t.addEventListener("click",()=>this.clearChat())}clearChat(){this._chatLogic&&(this._chatLogic.clearChat(),this.load())}handleOnLoadError(t){var n;It(t),this._clearOnError?this.clearChat():(n=this._chatLogic)==null||n.setErrorMessage(Qi),this.setLoaded()}sendMessage(t){this._chatLogic&&this._chatLogic.sendMessage(t)}getChatId(){return this._chatLogic?this._chatLogic.getChatId():null}getMessages(){return this._chatLogic?this._chatLogic.getMessages():[]}}customElements.define("chat-widget",Yc);customElements.define("chat-embed",Jc);
