UNPKG

deep-chat-dev

Version:

Customizable chat component for AI APIs

1 lines 390 kB
const t="classList",e="style",i=(t="div")=>document.createElement(t);class s{static render(t,e){const s=i();s.id="error-view",s.innerText=e,t.replaceChildren(s)}}class n{static onLoad(t){t.innerHTML='<div id="loading-validate-key-property"></div>'}static createElements(){const t=i();return t.id="validate-property-key-view",t}static render(t,e,i){const o=n.createElements(),r={onSuccess:e,onFail:s.render.bind(this,t,"Your 'key' has failed authentication"),onLoad:n.onLoad.bind(this,o)};i.key&&i.verifyKey(i.key,r),t.replaceChildren(o)}}const o="service",r="text",a="html",l="error",c="https://deepchat.dev/docs/",h="ai",u="user",d="assistant",p="error-message-text",m="deep-chat-outer-container-role-",v="empty-message",f="deep-chat-top-message",g="deep-chat-middle-message",b="deep-chat-bottom-message",y="src",w="type",x="file",k="files",S="image",_="images",O="camera",A="gifs",M="audio",C="microphone",T="mixedFiles",j="any",E="file-message",N="start";function I(t){return t.charAt(0).toUpperCase()+t.slice(1)}function $(t,e,i,s){const n=`\n${I(e)} message: ${JSON.stringify(t)} \n`,o=i?`${I(e)} message after interceptor: ${function(t){return t&&JSON.stringify(t)}(s)} \n`:"";return n+o}const P=function(t,e,i,s){return`${$(t,e,i,s)}Make sure the ${e} message is using the Response format: ${c}connect/#Response \nYou can also augment it using the responseInterceptor property: ${c}interceptors#responseInterceptor`},B=function(t,e){const i="request";return`${$(t,i,e)}Make sure the ${i} message is using the {body: {text: string}} format, e.g: {body: {text: "Model Response"}}`},R=function(t,e,i){const s="response";return`${$(t,s,e,i)}Make sure the ${s} message is using the {text: string} format, e.g: {text: "Model Response"}`},F=function(t){return`${t} failed - please wait for chat view to render before calling this property.`},J="Invalid API Key",L="Failed to connect",q="Request settings have not been set up",z="No file was added",D="Image was not found",U="Multi-response arrays are not supported for streaming",H=`Make sure the events are using {text: string} or {html: string} format.\nYou can also augment them using the responseInterceptor property: ${c}interceptors#responseInterceptor`,V=`No valid stream events were sent.\n${H}`,W="Please define a `function_handler` property inside the service config.",G="Function tool response must be an array or contain a text property",Z="Failed to fetch history",K="inside-start",X="inside-end",Q="outside-start",Y="outside-end",tt="dropup-menu",et="default",it="hover",st="click";class nt{static unsetStyle(t,i){const s=Object.keys(i).reduce((t,e)=>(t[e]="",t),{});Object.assign(t[e],s)}static unsetActivityCSSMouseStates(t,e){e[st]&&nt.unsetStyle(t,e[st]),e[it]&&nt.unsetStyle(t,e[it])}static unsetAllCSSMouseStates(t,e){nt.unsetActivityCSSMouseStates(t,e),e[et]&&nt.unsetStyle(t,e[et])}static processStateful(t){const e=t[et]||{},i=Object.assign(JSON.parse(JSON.stringify(e)),null==t?void 0:t[it]),s=Object.assign(JSON.parse(JSON.stringify(i)),null==t?void 0:t[st]);return{[et]:e,[it]:i,[st]:s}}static mergeStatefulStyles(t){const e={[et]:{},[it]:{},[st]:{}};return t.forEach(t=>{e[et]=Object.assign(e[et],t[et]),e[it]=Object.assign(e[it],t[it]),e[st]=Object.assign(e[st],t[st])}),e}static overwriteDefaultWithAlreadyApplied(t,i){Object.keys(t[et]||[]).forEach(s=>{var n;const o=s;i[e][o]&&null!=(n=t[et])&&n[o]&&(t[et][s]=i[e][o])})}static applyToStyleIfNotDefined(t,e){for(const i in e){const s=e[i];""===t[i]&&s&&(t[i]=s)}}}const ot=class t{static attemptAppendStyleSheetToHead(e){if(e.fontFamily&&e.fontFamily!==t.DEFAULT_FONT_FAMILY)return;const s=document.getElementsByTagName("head")[0];if(!Array.from(s.getElementsByTagName("link")).some(e=>e.getAttribute("href")===t.FONT_URL)){const e=i("link");e.rel="stylesheet",e.href=t.FONT_URL,s.appendChild(e)}}};ot.FONT_URL="https://fonts.googleapis.com/css2?family=Inter:wght@400;600&display=swap",ot.DEFAULT_FONT_FAMILY="'Inter', sans-serif, Avenir, Helvetica, Arial";let rt=ot;const at=class t{static apply(e,i){if(i)try{t.applyStyleSheet(e,i)}catch{t.addStyleElement(e,i)}}static applyStyleSheet(t,e){const i=new CSSStyleSheet;i.replaceSync(t),e.adoptedStyleSheets.push(i)}static addStyleElement(t,e){const s=i("style");s.innerHTML=t,e.appendChild(s)}static applyDefaultStyleToComponent(e,i){i&&nt.applyToStyleIfNotDefined(e,i),nt.applyToStyleIfNotDefined(e,t.DEFAULT_COMPONENT_STYLE)}};at.DEFAULT_COMPONENT_STYLE={height:"350px",width:"320px",borderTop:"1px solid #cacaca",borderRight:"1px solid #cacaca",borderLeft:"1px solid #cacaca",borderBottom:"1px solid #cacaca",fontFamily:rt.DEFAULT_FONT_FAMILY,fontSize:"0.9rem",backgroundColor:"white",position:"relative",overflow:"hidden"};let lt=at;const ct=class s{static buildElement(){const e=i();e[t].add("tooltip");const s=i("span");return s[t].add("tooltip-text"),e.appendChild(s),e}static tryCreateConfig(t,i){if(i)return"boolean"==typeof i?{[r]:t}:{[r]:i[r]||t,timeout:i.timeout||0,style:i[e]}}static traverseParentUntilContainer(t){let e=t;for(;e.parentElement;)e=e.parentElement;return e}static setPosition(t,i){const n=i.getRootNode().host.getBoundingClientRect(),o=t.getBoundingClientRect(),r=i.getBoundingClientRect().width/2,a=o.left+o.width/2;i[e].left=a-r-n.left+"px",i[e].top=o.top-36-n.top+"px";const l=i.getBoundingClientRect();l.left<n.left?i[e].left=`${s.OVERFLOW_NEW_POSITION_PX}px`:l.right>n.right&&(i[e].left=n.width-l.width-s.OVERFLOW_NEW_POSITION_PX+"px")}static display(t,i,n){return n||(n=s.traverseParentUntilContainer(t).nextSibling),i[r]&&(n.children[0].textContent=i[r]),{timeout:setTimeout(()=>{n[e].visibility="visible",s.setPosition(t,n),i[e]&&Object.assign(n[e],i[e])},i.timeout||0),element:n}}static hide(t,i){clearTimeout(t.timeout),t.element[e].visibility="hidden",i[e]&&nt.unsetStyle(t.element,i[e]),t.element[e].left="",t.element[e].top=""}};ct.OVERFLOW_NEW_POSITION_PX=4;let ht=ct;const ut=class{};ut.IS_SAFARI=/^((?!chrome|android).)*safari/i.test(navigator.userAgent),ut.IS_CHROMIUM=window.chrome,ut.IS_MOBILE=/iPhone|iPad|iPod|Android/i.test(navigator.userAgent);let dt=ut;var pt=(t=>(t.ESCAPE="Escape",t.ENTER="Enter",t.TAB="Tab",t.ARROW_UP="ArrowUp",t.ARROW_DOWN="ArrowDown",t.ARROW_RIGHT="ArrowRight",t.ARROW_LEFT="ArrowLeft",t.BACKSPACE="Backspace",t.DELETE="Delete",t.META="Meta",t.CONTROL="Control",t))(pt||{});const mt=class t{static add(e,i,s,n){void 0!==s&&e.addEventListener("keydown",t.onKeyDown.bind(this,s)),e.oninput=t.onInput.bind(this,s,n),e.addEventListener("paste",t=>{var e;t.preventDefault(),null!=(e=t.clipboardData)&&e[k].length&&i.addFilesToAnyType(Array.from(t.clipboardData[k]))})}static onKeyDown(e,i){const s=i.target.textContent;s&&s.length>=e&&!t.PERMITTED_KEYS.has(i.key)&&!t.isKeyCombinationPermitted(i)&&i.preventDefault()}static isKeyCombinationPermitted(t){return"a"===t.key&&(t.ctrlKey||t.metaKey)}static onInput(t,e,i){const s=i.target,n=s.textContent||"";void 0!==t&&n.length>t&&(s.textContent=n.substring(0,t),yt.focusEndOfInput(s)),null==e||e()}};mt.PERMITTED_KEYS=new Set([pt.BACKSPACE,pt.DELETE,pt.ARROW_RIGHT,pt.ARROW_LEFT,pt.ARROW_DOWN,pt.ARROW_UP,pt.META,pt.CONTROL,pt.ENTER]);let vt=mt;class ft{static sanitizePastedTextContent(t){var e,i;t.preventDefault();const s=null==(e=t.clipboardData)?void 0:e.getData("text/plain");s&&(null==(i=document.execCommand)||i.call(document,"insertText",!1,s))}}const gt=class s{constructor(t,e,i,n){var o,a,l,c;this._isComposing=!1;const h=s.processConfig(e,t.textInput);this.elementRef=s.createContainerElement(null==(o=null==h?void 0:h.styles)?void 0:o.container),this._config=h,this.inputElementRef=this.createInputElement(null==(a=t.defaultInput)?void 0:a[r],n),s.addFilesToAnyType(i,null==(l=t.defaultInput)?void 0:l[k]),this.elementRef.appendChild(this.inputElementRef),t.setPlaceholderText=this.setPlaceholderText.bind(this),t.setPlaceholderText((null==(c=this._config.placeholder)?void 0:c[r])||"Ask me anything!"),setTimeout(()=>{vt.add(this.inputElementRef,i,this._config.characterLimit,t._validationHandler),this._onInput=e.onInput})}static processConfig(t,e){var i;return e??(e={}),e.disabled??(e.disabled=t.isTextInputDisabled),e.placeholder??(e.placeholder={}),(i=e.placeholder)[r]??(i[r]=t.textInputPlaceholderText),e}static createContainerElement(t){const s=i();return s.id="text-input-container",Object.assign(s[e],t),s}static preventAutomaticScrollUpOnNewLine(t){let e;t.addEventListener("keydown",()=>{e=window.scrollY}),t.addEventListener("input",()=>{e!==window.scrollY&&window.scrollTo({top:e})})}clear(){var i,s;const n=window.scrollY;this.inputElementRef[t].contains("text-input-disabled")||(Object.assign(this.inputElementRef[e],null==(i=this._config.placeholder)?void 0:i[e]),this.inputElementRef.textContent="",yt.focusEndOfInput(this.inputElementRef),null==(s=this._onInput)||s.call(this,!1)),dt.IS_CHROMIUM&&window.scrollTo({top:n})}createInputElement(n,o){var a,l,c,h;const u=i();return u.id=s.TEXT_INPUT_ID,u[t].add("text-input-styling"),u.role="textbox","string"==typeof n?u.innerText=n:null!=o&&o.trackInputText&&(u.innerText=o.get().inputText||""),dt.IS_MOBILE&&u.setAttribute("tabindex","0"),dt.IS_CHROMIUM&&s.preventAutomaticScrollUpOnNewLine(u),"boolean"==typeof this._config.disabled&&!0===this._config.disabled?(u.contentEditable="false",u[t].add("text-input-disabled"),u.setAttribute("aria-disabled","true")):(u.contentEditable="true",u.removeAttribute("aria-disabled"),this.addEventListeners(u)),Object.assign(u[e],null==(a=this._config.styles)?void 0:a[r]),Object.assign(u[e],null==(l=this._config.placeholder)?void 0:l[e]),null!=(h=null==(c=this._config.placeholder)?void 0:c[e])&&h.color||u.setAttribute("textcolor",""),u}static addFilesToAnyType(t,e){e&&t.addFilesToAnyType(Array.from(e).map(t=>t))}removePlaceholderStyle(){var i,s,n,o;!this.inputElementRef[t].contains("text-input-disabled")&&null!=(i=this._config.placeholder)&&i[e]&&(nt.unsetStyle(this.inputElementRef,null==(s=this._config.placeholder)?void 0:s[e]),Object.assign(this.inputElementRef[e],null==(o=null==(n=this._config)?void 0:n.styles)?void 0:o[r]))}addEventListeners(t){var i,s;null!=(i=this._config.styles)&&i.focus&&(t.onfocus=()=>{var t;return Object.assign(this.elementRef[e],null==(t=this._config.styles)?void 0:t.focus)},t.onblur=this.onBlur.bind(this,this._config.styles.focus,null==(s=this._config.styles)?void 0:s.container)),t.addEventListener("keydown",this.onKeydown.bind(this)),t.addEventListener("input",this.onInput.bind(this)),t.addEventListener("paste",ft.sanitizePastedTextContent),t.addEventListener("compositionstart",()=>this._isComposing=!0),t.addEventListener("compositionend",()=>this._isComposing=!1)}onBlur(t,i){nt.unsetStyle(this.elementRef,t),i&&Object.assign(this.elementRef[e],i)}onKeydown(t){var e;t.key===pt.ENTER&&!dt.IS_MOBILE&&!this._isComposing&&!t.ctrlKey&&!t.shiftKey&&(t.preventDefault(),null==(e=this.submit)||e.call(this))}onInput(){var t,i;this.isTextInputEmpty()?Object.assign(this.inputElementRef[e],null==(t=this._config.placeholder)?void 0:t[e]):this.removePlaceholderStyle(),null==(i=this._onInput)||i.call(this,!0)}setPlaceholderText(t){this.inputElementRef.setAttribute("deep-chat-placeholder-text",t),this.inputElementRef.setAttribute("aria-label",t)}isTextInputEmpty(){return""===this.inputElementRef.textContent}};gt.TEXT_INPUT_ID="text-input";let bt=gt;class yt{static focusEndOfInput(t){const e=document.createRange();e.selectNodeContents(t),e.collapse(!1);const i=window.getSelection();null==i||i.removeAllRanges(),null==i||i.addRange(e),(dt.IS_MOBILE||dt.IS_SAFARI)&&t.focus()}static focusFromParentElement(t){const e=t.querySelector(`#${bt.TEXT_INPUT_ID}`);e&&yt.focusEndOfInput(e)}}const wt="Authentication",xt="Authorization",kt="authorization",St="Unauthorized",_t="Authorization header",Ot="Invalid",At="Incorrect",Mt="authentication_error",Ct="invalid_request_error",Tt="Content-Type",jt="content-type",Et="application/json",Nt="object",It="completed",$t="Bearer ",Pt="GET",Bt="POST",Rt="Upload an audio file",Ft="function_call",Jt="deep-chat-upwards-mode",Lt="submit-button",qt="loading-button",zt="disabled-button",Dt="text-input-container-start-adjustment",Ut="text-input-container-end-adjustment",Ht="text-input-container-start-small-adjustment",Vt="text-input-container-end-small-adjustment",Wt=class t{static addElements(t,...e){e.forEach(e=>t.appendChild(e))}static isScrollbarAtBottomOfElement(e){const i=e.scrollHeight,s=e.clientHeight;return e.scrollTop>=i-s-t.CODE_SNIPPET_GENERATION_JUMP}static cloneElement(t){const e=t.cloneNode(!0);return t.parentNode.replaceChild(e,t),e}static scrollToBottom(t,e=!1,i){var s;const n=null!=(s=t.parentElement)&&s.classList.contains(Jt)?t.children[0]:t;i?n.scrollTo({left:0,top:i.offsetTop}):e?n.scrollTo({left:0,top:n.scrollHeight,behavior:"smooth"}):n.scrollTop=n.scrollHeight}static scrollToTop(t){t.scrollTop=0}};Wt.CODE_SNIPPET_GENERATION_JUMP=.5;let Gt=Wt;const Zt=class t{static speak(t,e){if(!e.audio&&window.SpeechSynthesisUtterance){const i=new SpeechSynthesisUtterance(t);Object.assign(i,e),speechSynthesis.speak(i)}}static processConfig(e,i){const s={};setTimeout(()=>{if("object"==typeof e&&(e.audio&&(s.audio=e.audio),e.lang&&(s.lang=e.lang),e.pitch&&(s.pitch=e.pitch),e.rate&&(s.rate=e.rate),e.volume&&(s.volume=e.volume),e.voiceName)){const t=window.speechSynthesis.getVoices().find(t=>{var i;return t.name.toLocaleLowerCase()===(null==(i=e.voiceName)?void 0:i.toLocaleLowerCase())});t&&(s.voice=t)}i(s)},t.LOAD_VOICES_MS)}};Zt.LOAD_VOICES_MS=200;let Kt=Zt;const Xt=class t{static colorToHex(t){const s=i();return s[e].color=t,document.body.appendChild(s),`#${window.getComputedStyle(s).color.match(/\d+/g).map(t=>parseInt(t).toString(16).padStart(2,"0")).join("")}`}static setDots(i,s){var n,o;if(null!=(o=null==(n=null==s?void 0:s.styles)?void 0:n.bubble)&&o.color){const n=t.colorToHex(s.styles.bubble.color);i[e].setProperty("--loading-message-color",n),i[e].setProperty("--loading-message-color-fade",`${n}33`)}else i[e].setProperty("--loading-message-color","#848484"),i[e].setProperty("--loading-message-color-fade","#55555533")}static setRing(i,s){const{color:n,width:o,height:r,margin:a,border:l}=s||{};if(n){const s=t.colorToHex(n);i[e].setProperty("--loading-history-color",s)}else i[e].setProperty("--loading-history-color","#dbdbdb");i[e].setProperty("--loading-history-height",r||"57px"),i[e].setProperty("--loading-history-width",o||"57px"),i[e].setProperty("--loading-history-margin",a||"7px"),i[e].setProperty("--loading-history-border",l||"6px solid")}};Xt.BUBBLE_CLASS="deep-chat-loading-message-bubble",Xt.DOTS_CONTAINER_CLASS="deep-chat-loading-message-dots-container";let Qt=Xt;class Yt{static checkForContainerStyles(t,i){const s=t.containerStyle;s&&(Object.assign(i[e],s),console[l](`The containerStyle property${ee}1.3.14.`),console[l](`${ie}the style property instead: ${c}styles#style`))}static handleResponseProperty(t){return console[l](`The {result: ....} response object type${ee}1.3.0.`),console[l](`${ie}the new response object: ${c}connect#Response`),t.result}static processHistory(t){const e=t.initialMessages;if(e)return console[l](`The initialMessages property${ee}2.0.0.`),console[l](`${ie}the history property instead: ${c}messages/#history`),e}static processHistoryFile(t){const e=t[x];e&&(console[l](`The file property in MessageContent${ee}1.3.17.`),console[l](`${ie}the files array property: ${c}messages/#MessageContent`),t[k]=[e])}static processValidateInput(t){const e=t.validateMessageBeforeSending;if(e)return console[l](`The validateMessageBeforeSending property${ee}1.3.24.`),console[l](`${ie}validateInput: ${c}interceptors#validateInput`),e}static processSubmitUserMessage(t){return console[l](`The submitUserMessage(text: string) argument string type${ee}1.4.4.`),console[l](`${ie}the new argument type: ${c}methods#submitUserMessage`),{[r]:t}}static flagHTMLUpdateClass(e){var i;null!=(i=e.children[0])&&i[t].contains("deep-chat-update-message")&&(console[l](`The "deep-chat-update-message" html class${ee}1.4.4.`),console[l](`${ie}using {..., overwrite: true} object: ${c}connect#Response`))}static processConnect(t){const e=t;e.request&&(e.connect?Object.assign(e.connect,e.request):e.connect=e.request,console[l](`The request property${ee}2.0.0.`),console[l](`${se}connect object: ${c}connect#connect-1`))}static checkForStream(t){const e=t.stream;if(e)return console[l](`The stream property${oe}the connect object in version 2.0.0.`),console[l](`${se}connect object: ${c}connect#connect-1`),e}static fireOnNewMessage(t,e){var i;const s=t;s.onNewMessage&&(console[l](`The onNewMessage event${ee}2.0.0.`),console[l](`${se}onMessage event: ${c}events#onMessage`),null==(i=s.onNewMessage)||i.call(s,e)),t.dispatchEvent(new CustomEvent("new-message",{detail:e}))}static processFileConfigConnect(t){const e=t;e.request&&(console[l](`The request property in file configuration${ee}2.0.0.`),console[l](`Please use the connect property instead: ${c}files`),e.connect||(e.connect=e.request))}static processMessageStyles(t){if(!t)return;const e=JSON.parse(JSON.stringify(t)),i=e.loading;return i&&(i.outerContainer||i.innerContainer||i.bubble||i.media)&&(console[l](`The loading message styles are defined using LoadingMessageStyles interface${te}2.1.0.`),console[l](`Check it out here: ${c}messages/styles#LoadingMessageStyles`),e.loading={message:{styles:i}}),e}static processDemo(t){return"boolean"==typeof t||t.displayLoadingBubble&&(console[l](`The demo displayLoadingBubble property${ee}2.1.0.`),console[l](`Please use displayLoading instead: ${c}modes#demo`),t.displayLoading={message:!0}),t}static processCohere(t){const e=t,i=`${se}official documentation: ${c}directConnection/Cohere`;return e.chat&&(console[l](`Cohere chat property${ee}2.2.3.`),console[l](i),delete e.chat),e.textGeneration?(console[l](`Cohere textGeneration${ne}2.2.3.`),console[l](i),delete e.textGeneration,!1):!e.summarization||(console[l](`Cohere summarization${ne}2.2.3.`),console[l](i),delete e.summarization,!1)}static processStreamHTMLWrappers(t){if(!t||typeof t!==Nt)return;const e=t.htmlWrappers;return e?(console[l](`The htmlWrappers property${oe}Deep Chat's base${te}2.3.0.`),console[l](`Check it out here: ${c}messages/HTML#htmlWrappers`),e):void 0}static processFocusMode(t){return!t||"boolean"==typeof t||t.scroll&&(console[l](`The scroll property in focusMode has been changed to smoothScroll${te}2.3.0.`),console[l](`Check it out here: ${c}modes#focusMode`),t.smoothScroll=!0),t}static processPosition(t){if(!t)return t;const e=`Position names have been updated${te}2.3.1.`;return"inside-left"===t?(console[l](e),K):"inside-right"===t?(console[l](e),X):"outside-left"===t?(console[l](e),Q):"outside-right"===t?(console[l](e),Y):t}static processBrowserStorage(t){const e=t.get();e&&Array.isArray(e)&&t.addMessages(e)}}const te=" since version ",ee=` is deprecated ${te}`,ie="Please change to using ",se="Please see the ",ne=` is not supported ${te}`,oe=" has been moved to ";class re{static mouseUp(t,i){nt.unsetAllCSSMouseStates(t,i),Object.assign(t[e],i[et]),Object.assign(t[e],i[it])}static mouseDown(t,i){Object.assign(t[e],i[st])}static mouseLeave(t,i){nt.unsetAllCSSMouseStates(t,i),Object.assign(t[e],i[et])}static mouseEnter(t,i){Object.assign(t[e],i[it])}static add(t,e){t.addEventListener("mouseenter",re.mouseEnter.bind(this,t,e)),t.addEventListener("mouseleave",re.mouseLeave.bind(this,t,e)),t.addEventListener("mousedown",re.mouseDown.bind(this,t,e)),t.addEventListener("mouseup",re.mouseUp.bind(this,t,e))}}const ae={"deep-chat-button":{styles:{[et]:{backgroundColor:"white",padding:"5px",paddingLeft:"7px",paddingRight:"7px",border:"1px solid #c2c2c2",borderRadius:"6px",cursor:"pointer"},[it]:{backgroundColor:"#fafafa"},[st]:{backgroundColor:"#f1f1f1"}}}},le=Object.keys(ae);class ce{static applySuggestionEvent(t,e){setTimeout(()=>{e.addEventListener(st,()=>{var i,s;null==(s=t.submitUserMessage)||s.call(t,{[r]:(null==(i=e.textContent)?void 0:i.trim())||""})})})}static isElementTemporary(e){var i;return!!e&&(null==(i=e.bubbleElement.children[0])?void 0:i[t].contains("deep-chat-temporary-message"))}static doesElementContainDeepChatClass(e){return le.find(i=>e[t].contains(i))}static applyEvents(t,e){const i=ae[e].events;Object.keys(i||[]).forEach(e=>{t.addEventListener(e,null==i?void 0:i[e])})}static getProcessedStyles(e,i,s){const n=Array.from(i[t]).reduce((t,i)=>{var s;const n=null==(s=e[i])?void 0:s.styles;return n&&e[i].styles&&t.push(n),t},[]),o=ae[s].styles;if(o){const t=JSON.parse(JSON.stringify(o));t[et]&&nt.overwriteDefaultWithAlreadyApplied(t,i),n.unshift(t)}const r=nt.mergeStatefulStyles(n);return nt.processStateful(r)}static applyDeepChatUtilities(t,e,i){le.forEach(t=>{const s=i.getElementsByClassName(t);Array.from(s||[]).forEach(i=>{const s=ce.getProcessedStyles(e,i,t);ue.applyStylesToElement(i,s),ce.applyEvents(i,t)})});const s=i.getElementsByClassName("deep-chat-suggestion-button");Array.from(s).forEach(e=>ce.applySuggestionEvent(t,e))}}const he=class t{static applyStylesToElement(t,i){const s=nt.processStateful(i);re.add(t,s),Object.assign(t[e],s[et])}static applyEventsToElement(t,e){Object.keys(e).forEach(i=>{const s=e[i];s&&t.addEventListener(i,s)})}static applyClassUtilitiesToElement(e,i){const{events:s,styles:n}=i;s&&t.applyEventsToElement(e,s),n&&!ce.doesElementContainDeepChatClass(e)&&t.applyStylesToElement(e,n)}static applyCustomClassUtilities(e,i){Object.keys(e).forEach(s=>{const n=i.getElementsByClassName(s);Array.from(n).forEach(i=>{e[s]&&t.applyClassUtilitiesToElement(i,e[s])})})}static apply(e,i){ce.applyDeepChatUtilities(e,e.htmlClassUtilities,i),t.applyCustomClassUtilities(e.htmlClassUtilities,i)}static traverseNodes(e,i){e.nodeType===Node.ELEMENT_NODE&&i.push(e.outerHTML),e.childNodes.forEach(e=>{t.traverseNodes(e,i)})}static splitHTML(e){const i=(new DOMParser).parseFromString(e,"text/html"),s=[];return i.body.childNodes.forEach(e=>{t.traverseNodes(e,s)}),s}static isTemporaryBasedOnHTML(t){const e=i();return e.innerHTML=t,ce.isElementTemporary({outerContainer:e,bubbleElement:e,innerContainer:e})}static replaceElementWithNewClone(t,e){var i;const s=(e||t).cloneNode(!0);return null==(i=t.parentNode)||i.replaceChild(s,t),s}static tryAddWrapper(e,i,s,n){if(i&&n){const i=(null==s?void 0:s[n])||(null==s?void 0:s[et]);if(i)return e.innerHTML=i,{contentEl:t.getTargetWrapper(e),wrapper:!0}}return{contentEl:e,wrapper:!1}}static getTargetWrapper(e){return e.getElementsByClassName(t.TARGET_WRAPPER_CLASS)[0]||e}};he.TARGET_WRAPPER_CLASS="html-wrapper";let ue=he;const de=class e{static addElement(t,e,i){const s=Gt.isScrollbarAtBottomOfElement(t.elementRef);t.appendOuterContainerElemet(e),!t.focusMode&&i&&s&&Gt.scrollToBottom(t.elementRef,!1,e)}static createElements(i,s,n,o,r=!1){const a=i.createMessageElementsOnOrientation("",n,o,r);a.bubbleElement[t].add(e.HTML_BUBBLE_CLASS);const{contentEl:l}=ue.tryAddWrapper(a.bubbleElement,s,i._customWrappers,n);return l.innerHTML=s,a}static overwriteElements(t,e,i){i.bubbleElement.innerHTML=e,ue.apply(t,i.outerContainer),Yt.flagHTMLUpdateClass(i.bubbleElement)}static overwrite(t,i,s,n){const{messageToElements:o}=t,r=ss.overwriteMessage(o,n,i,s,a,e.HTML_BUBBLE_CLASS);return r&&e.overwriteElements(t,i,r),r}static create(t,i,s,n=!1){var o;const r=e.createElements(t,i,s,n);return ss.fillEmptyMessageElement(r.bubbleElement,i),ue.apply(t,r.outerContainer),Yt.flagHTMLUpdateClass(r.bubbleElement),t.applyCustomStyles(r,s,!1,null==(o=t.messageStyles)?void 0:o[a]),r}static add(t,i,s,n,o,r=!1){if(null!=o&&o.status){const e=this.overwrite(t,i,s,t.messageElementRefs);if(e)return e;o.status=!1}if(r&&t.messageElementRefs.length>0&&ue.isTemporaryBasedOnHTML(i))return;const a=e.create(t,i,s,r);return r||e.addElement(t,a.outerContainer,n),a}};de.HTML_BUBBLE_CLASS="html-message";let pe=de;class me{static katex(t,e,i){const s=(i||{}).delimiter||"$";if(1!==s.length)throw new Error("invalid delimiter");e.inline.ruler.push("katex",(t,e)=>{const i=t.pos,n=t.posMax;let o=i;if(t.src.charAt(o)!==s)return!1;for(++o;o<n&&t.src.charAt(o)===s;)++o;const r=t.src.slice(i,o);if(r.length>2)return!1;const a=o;let l=0;for(;o<n;){const i=t.src.charAt(o);if("{"!==i||0!==o&&"\\"===t.src.charAt(o-1)){if("}"!==i||0!==o&&"\\"===t.src.charAt(o-1)){if(i===s&&0===l){const i=o;let l=o+1;for(;l<n&&t.src.charAt(l)===s;)++l;if(l-i===r.length){if(!e){const e=t.src.slice(a,i).replace(/[ \n]+/g," ").trim();t.push({type:"katex",content:e,block:r.length>1,level:t.level})}return t.pos=l,!0}}}else if(l-=1,l<0)return!1}else l+=1;o+=1}return e||(t.pending+=r),t.pos+=r.length,!0},i),e.block.ruler.push("katex",(t,e,i)=>{let n=!1,o=t.bMarks[e]+t.tShift[e],r=t.eMarks[e];if(o+1>r)return!1;const a=t.src.charAt(o);if(a!==s)return!1;let l=o;o=t.skipChars(o,a);let c=o-l;if(2!==c)return!1;let h=e;for(;++h,!(h>=i||(o=l=t.bMarks[h]+t.tShift[h],r=t.eMarks[h],o<r&&t.tShift[h]<t.blkIndent));)if(!(t.src.charAt(o)!==s||t.tShift[h]-t.blkIndent>=4||(o=t.skipChars(o,a),o-l<c||(o=t.skipSpaces(o),o<r)))){n=!0;break}c=t.tShift[e],t.line=h+(n?1:0);const u=t.getLines(e+1,h,c,!0).replace(/[ \n]+/g," ").trim();return t.tokens.push({type:"katex",params:null,content:u,lines:[e,t.line],level:t.level,block:!0}),!0},i),e.renderer.rules.katex=(e,i)=>((e,i)=>{var s;return(null==(s=window.katex)?void 0:s.renderToString(e,{displayMode:i,throwOnError:!1,output:"mathml",...t}))||""})(e[i].content,e[i].block),e.renderer.rules.katex.delimiter=s}}var ve;function fe(t){return(ve=ve||document.createElement("textarea")).innerHTML="&"+t+";",ve.value}var ge=Object.prototype.hasOwnProperty;function be(t){return[].slice.call(arguments,1).forEach(function(e){if(e){if("object"!=typeof e)throw new TypeError(e+"must be object");Object.keys(e).forEach(function(i){t[i]=e[i]})}}),t}var ye=/\\([\\!"#$%&'()*+,.\/:;<=>?@[\]^_`{|}~-])/g;function we(t){return t.indexOf("\\")<0?t:t.replace(ye,"$1")}function xe(t){return!(t>=55296&&t<=57343||t>=64976&&t<=65007||!(65535&~t)||65534==(65535&t)||t>=0&&t<=8||11===t||t>=14&&t<=31||t>=127&&t<=159||t>1114111)}function ke(t){if(t>65535){var e=55296+((t-=65536)>>10),i=56320+(1023&t);return String.fromCharCode(e,i)}return String.fromCharCode(t)}var Se=/&([a-z#][a-z0-9]{1,31});/gi,_e=/^#((?:x[a-f0-9]{1,8}|[0-9]{1,8}))/i;function Oe(t,e){var i=0,s=fe(e);return e!==s?s:35===e.charCodeAt(0)&&_e.test(e)&&xe(i="x"===e[1].toLowerCase()?parseInt(e.slice(2),16):parseInt(e.slice(1),10))?ke(i):t}function Ae(t){return t.indexOf("&")<0?t:t.replace(Se,Oe)}var Me=/[&<>"]/,Ce=/[&<>"]/g,Te={"&":"&amp;","<":"&lt;",">":"&gt;",'"':"&quot;"};function je(t){return Te[t]}function Ee(t){return Me.test(t)?t.replace(Ce,je):t}var Ne={};function Ie(t,e){return++e>=t.length-2?e:"paragraph_open"===t[e].type&&t[e].tight&&"inline"===t[e+1].type&&0===t[e+1].content.length&&"paragraph_close"===t[e+2].type&&t[e+2].tight?Ie(t,e+2):e}Ne.blockquote_open=function(){return"<blockquote>\n"},Ne.blockquote_close=function(t,e){return"</blockquote>"+$e(t,e)},Ne.code=function(t,e){return t[e].block?"<pre><code>"+Ee(t[e].content)+"</code></pre>"+$e(t,e):"<code>"+Ee(t[e].content)+"</code>"},Ne.fence=function(t,e,i,s,n){var o,r,a=t[e],l="",c=i.langPrefix;if(a.params){if(r=(o=a.params.split(/\s+/g)).join(" "),function(t,e){return!!t&&ge.call(t,e)}(n.rules.fence_custom,o[0]))return n.rules.fence_custom[o[0]](t,e,i,s,n);l=' class="'+c+Ee(Ae(we(r)))+'"'}return"<pre><code"+l+">"+(i.highlight&&i.highlight.apply(i.highlight,[a.content].concat(o))||Ee(a.content))+"</code></pre>"+$e(t,e)},Ne.fence_custom={},Ne.heading_open=function(t,e){return"<h"+t[e].hLevel+">"},Ne.heading_close=function(t,e){return"</h"+t[e].hLevel+">\n"},Ne.hr=function(t,e,i){return(i.xhtmlOut?"<hr />":"<hr>")+$e(t,e)},Ne.bullet_list_open=function(){return"<ul>\n"},Ne.bullet_list_close=function(t,e){return"</ul>"+$e(t,e)},Ne.list_item_open=function(){return"<li>"},Ne.list_item_close=function(){return"</li>\n"},Ne.ordered_list_open=function(t,e){var i=t[e];return"<ol"+(i.order>1?' start="'+i.order+'"':"")+">\n"},Ne.ordered_list_close=function(t,e){return"</ol>"+$e(t,e)},Ne.paragraph_open=function(t,e){return t[e].tight?"":"<p>"},Ne.paragraph_close=function(t,e){var i=!(t[e].tight&&e&&"inline"===t[e-1].type&&!t[e-1].content);return(t[e].tight?"":"</p>")+(i?$e(t,e):"")},Ne.link_open=function(t,e,i){var s=t[e].title?' title="'+Ee(Ae(t[e].title))+'"':"",n=i.linkTarget?' target="'+i.linkTarget+'"':"";return'<a href="'+Ee(t[e].href)+'"'+s+n+">"},Ne.link_close=function(){return"</a>"},Ne.image=function(t,e,i){var s=' src="'+Ee(t[e].src)+'"',n=t[e].title?' title="'+Ee(Ae(t[e].title))+'"':"";return"<img"+s+(' alt="'+(t[e].alt?Ee(Ae(we(t[e].alt))):"")+'"')+n+(i.xhtmlOut?" /":"")+">"},Ne.table_open=function(){return"<table>\n"},Ne.table_close=function(){return"</table>\n"},Ne.thead_open=function(){return"<thead>\n"},Ne.thead_close=function(){return"</thead>\n"},Ne.tbody_open=function(){return"<tbody>\n"},Ne.tbody_close=function(){return"</tbody>\n"},Ne.tr_open=function(){return"<tr>"},Ne.tr_close=function(){return"</tr>\n"},Ne.th_open=function(t,e){var i=t[e];return"<th"+(i.align?' style="text-align:'+i.align+'"':"")+">"},Ne.th_close=function(){return"</th>"},Ne.td_open=function(t,e){var i=t[e];return"<td"+(i.align?' style="text-align:'+i.align+'"':"")+">"},Ne.td_close=function(){return"</td>"},Ne.strong_open=function(){return"<strong>"},Ne.strong_close=function(){return"</strong>"},Ne.em_open=function(){return"<em>"},Ne.em_close=function(){return"</em>"},Ne.del_open=function(){return"<del>"},Ne.del_close=function(){return"</del>"},Ne.ins_open=function(){return"<ins>"},Ne.ins_close=function(){return"</ins>"},Ne.mark_open=function(){return"<mark>"},Ne.mark_close=function(){return"</mark>"},Ne.sub=function(t,e){return"<sub>"+Ee(t[e].content)+"</sub>"},Ne.sup=function(t,e){return"<sup>"+Ee(t[e].content)+"</sup>"},Ne.hardbreak=function(t,e,i){return i.xhtmlOut?"<br />\n":"<br>\n"},Ne.softbreak=function(t,e,i){return i.breaks?i.xhtmlOut?"<br />\n":"<br>\n":"\n"},Ne.text=function(t,e){return Ee(t[e].content)},Ne.htmlblock=function(t,e){return t[e].content},Ne.htmltag=function(t,e){return t[e].content},Ne.abbr_open=function(t,e){return'<abbr title="'+Ee(Ae(t[e].title))+'">'},Ne.abbr_close=function(){return"</abbr>"},Ne.footnote_ref=function(t,e){var i=Number(t[e].id+1).toString(),s="fnref"+i;return t[e].subId>0&&(s+=":"+t[e].subId),'<sup class="footnote-ref"><a href="#fn'+i+'" id="'+s+'">['+i+"]</a></sup>"},Ne.footnote_block_open=function(t,e,i){return(i.xhtmlOut?'<hr class="footnotes-sep" />\n':'<hr class="footnotes-sep">\n')+'<section class="footnotes">\n<ol class="footnotes-list">\n'},Ne.footnote_block_close=function(){return"</ol>\n</section>\n"},Ne.footnote_open=function(t,e){return'<li id="fn'+Number(t[e].id+1).toString()+'" class="footnote-item">'},Ne.footnote_close=function(){return"</li>\n"},Ne.footnote_anchor=function(t,e){var i="fnref"+Number(t[e].id+1).toString();return t[e].subId>0&&(i+=":"+t[e].subId),' <a href="#'+i+'" class="footnote-backref">↩</a>'},Ne.dl_open=function(){return"<dl>\n"},Ne.dt_open=function(){return"<dt>"},Ne.dd_open=function(){return"<dd>"},Ne.dl_close=function(){return"</dl>\n"},Ne.dt_close=function(){return"</dt>\n"},Ne.dd_close=function(){return"</dd>\n"};var $e=Ne.getBreak=function(t,e){return(e=Ie(t,e))<t.length&&"list_item_close"===t[e].type?"":"\n"};function Pe(){this.rules=be({},Ne),this.getBreak=Ne.getBreak}function Be(){this.t=[],this.i=null}function Re(t,e,i,s,n){this.src=t,this.env=s,this.options=i,this.parser=e,this.tokens=n,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}function Fe(t,e){var i,s,n,o=-1,r=t.posMax,a=t.pos,l=t.isInLabel;if(t.isInLabel)return-1;if(t.labelUnmatchedScopes)return t.labelUnmatchedScopes--,-1;for(t.pos=e+1,t.isInLabel=!0,i=1;t.pos<r;){if(91===(n=t.src.charCodeAt(t.pos)))i++;else if(93===n&&0===--i){s=!0;break}t.parser.skipToken(t)}return s?(o=t.pos,t.labelUnmatchedScopes=0):t.labelUnmatchedScopes=i-1,t.pos=a,t.isInLabel=l,o}function Je(t,e,i,s){var n,o,r,a,l,c;if(42!==t.charCodeAt(0)||91!==t.charCodeAt(1)||-1===t.indexOf("]:")||((o=Fe(n=new Re(t,e,i,s,[]),1))<0||58!==t.charCodeAt(o+1)))return-1;for(a=n.posMax,r=o+2;r<a&&10!==n.src.charCodeAt(r);r++);return l=t.slice(2,o),0===(c=t.slice(o+2,r).trim()).length?-1:(s.abbreviations||(s.abbreviations={}),typeof s.abbreviations[":"+l]>"u"&&(s.abbreviations[":"+l]=c),r)}function Le(t){var e=Ae(t);try{e=decodeURI(e)}catch{}return encodeURI(e)}function qe(t,e){var i,s,n,o=e,r=t.posMax;if(60===t.src.charCodeAt(e)){for(e++;e<r;){if(10===(i=t.src.charCodeAt(e)))return!1;if(62===i)return n=Le(we(t.src.slice(o+1,e))),!!t.parser.validateLink(n)&&(t.pos=e+1,t.linkContent=n,!0);92===i&&e+1<r?e+=2:e++}return!1}for(s=0;e<r&&!(32===(i=t.src.charCodeAt(e))||i<32||127===i);)if(92===i&&e+1<r)e+=2;else{if(40===i&&++s>1||41===i&&--s<0)break;e++}return!(o===e||(n=we(t.src.slice(o,e)),!t.parser.validateLink(n)))&&(t.linkContent=n,t.pos=e,!0)}function ze(t,e){var i,s=e,n=t.posMax,o=t.src.charCodeAt(e);if(34!==o&&39!==o&&40!==o)return!1;for(e++,40===o&&(o=41);e<n;){if((i=t.src.charCodeAt(e))===o)return t.pos=e+1,t.linkContent=we(t.src.slice(s+1,e)),!0;92===i&&e+1<n?e+=2:e++}return!1}function De(t){return t.trim().replace(/\s+/g," ").toUpperCase()}function Ue(t,e,i,s){var n,o,r,a,l,c,h,u,d;if(91!==t.charCodeAt(0)||-1===t.indexOf("]:")||((o=Fe(n=new Re(t,e,i,s,[]),0))<0||58!==t.charCodeAt(o+1)))return-1;for(a=n.posMax,r=o+2;r<a&&(32===(l=n.src.charCodeAt(r))||10===l);r++);if(!qe(n,r))return-1;for(h=n.linkContent,c=r=n.pos,r+=1;r<a&&(32===(l=n.src.charCodeAt(r))||10===l);r++);for(r<a&&c!==r&&ze(n,r)?(u=n.linkContent,r=n.pos):(u="",r=c);r<a&&32===n.src.charCodeAt(r);)r++;return r<a&&10!==n.src.charCodeAt(r)?-1:(d=De(t.slice(1,o)),typeof s.references[d]>"u"&&(s.references[d]={title:u,href:h}),r)}Pe.prototype.renderInline=function(t,e,i){for(var s=this.rules,n=t.length,o=0,r="";n--;)r+=s[t[o].type](t,o++,e,i,this);return r},Pe.prototype.render=function(t,e,i){for(var s=this.rules,n=t.length,o=-1,r="";++o<n;)"inline"===t[o].type?r+=this.renderInline(t[o].children,e,i):r+=s[t[o].type](t,o,e,i,this);return r},Be.prototype.o=function(t){for(var e=this.t.length,i=-1;e--;)if(this.t[++i].name===t)return i;return-1},Be.prototype.l=function(){var t=this,e=[""];t.t.forEach(function(t){t.enabled&&t.alt.forEach(function(t){e.indexOf(t)<0&&e.push(t)})}),t.i={},e.forEach(function(e){t.i[e]=[],t.t.forEach(function(i){i.enabled&&(e&&i.alt.indexOf(e)<0||t.i[e].push(i.fn))})})},Be.prototype.at=function(t,e,i){var s=this.o(t),n=i||{};if(-1===s)throw new Error("Parser rule not found: "+t);this.t[s].fn=e,this.t[s].alt=n.alt||[],this.i=null},Be.prototype.before=function(t,e,i,s){var n=this.o(t),o=s||{};if(-1===n)throw new Error("Parser rule not found: "+t);this.t.splice(n,0,{name:e,enabled:!0,fn:i,alt:o.alt||[]}),this.i=null},Be.prototype.after=function(t,e,i,s){var n=this.o(t),o=s||{};if(-1===n)throw new Error("Parser rule not found: "+t);this.t.splice(n+1,0,{name:e,enabled:!0,fn:i,alt:o.alt||[]}),this.i=null},Be.prototype.push=function(t,e,i){var s=i||{};this.t.push({name:t,enabled:!0,fn:e,alt:s.alt||[]}),this.i=null},Be.prototype.enable=function(t,e){t=Array.isArray(t)?t:[t],e&&this.t.forEach(function(t){t.enabled=!1}),t.forEach(function(t){var e=this.o(t);if(e<0)throw new Error("Rules manager: invalid rule name "+t);this.t[e].enabled=!0},this),this.i=null},Be.prototype.disable=function(t){(t=Array.isArray(t)?t:[t]).forEach(function(t){var e=this.o(t);if(e<0)throw new Error("Rules manager: invalid rule name "+t);this.t[e].enabled=!1},this),this.i=null},Be.prototype.getRules=function(t){return null===this.i&&this.l(),this.i[t]||[]},Re.prototype.pushPending=function(){this.tokens.push({type:"text",content:this.pending,level:this.pendingLevel}),this.pending=""},Re.prototype.push=function(t){this.pending&&this.pushPending(),this.tokens.push(t),this.pendingLevel=this.level},Re.prototype.cacheSet=function(t,e){for(var i=this.cache.length;i<=t;i++)this.cache.push(0);this.cache[t]=e},Re.prototype.cacheGet=function(t){return t<this.cache.length?this.cache[t]:0};var He=" \n()[]'\".,!?-";function Ve(t){return t.replace(/([-()\[\]{}+?*.$\^|,:#<!\\])/g,"\\$1")}var We=/\+-|\.\.|\?\?\?\?|!!!!|,,|--/,Ge=/\((c|tm|r|p)\)/gi,Ze={c:"©",r:"®",p:"§",tm:"™"};function Ke(t){return t.indexOf("(")<0?t:t.replace(Ge,function(t,e){return Ze[e.toLowerCase()]})}var Xe=/['"]/,Qe=/['"]/g,Ye=/[-\s()\[\]]/;function ti(t,e){return!(e<0||e>=t.length)&&!Ye.test(t[e])}function ei(t,e,i){return t.substr(0,e)+i+t.substr(e+1)}var ii=[["block",function(t){t.inlineMode?t.tokens.push({type:"inline",content:t.src.replace(/\n/g," ").trim(),level:0,lines:[0,1],children:[]}):t.block.parse(t.src,t.options,t.env,t.tokens)}],["abbr",function(t){var e,i,s,n,o=t.tokens;if(!t.inlineMode)for(e=1,i=o.length-1;e<i;e++)if("paragraph_open"===o[e-1].type&&"inline"===o[e].type&&"paragraph_close"===o[e+1].type){for(s=o[e].content;s.length&&!((n=Je(s,t.inline,t.options,t.env))<0);)s=s.slice(n).trim();o[e].content=s,s.length||(o[e-1].tight=!0,o[e+1].tight=!0)}}],["references",function(t){var e,i,s,n,o=t.tokens;if(t.env.references=t.env.references||{},!t.inlineMode)for(e=1,i=o.length-1;e<i;e++)if("inline"===o[e].type&&"paragraph_open"===o[e-1].type&&"paragraph_close"===o[e+1].type){for(s=o[e].content;s.length&&!((n=Ue(s,t.inline,t.options,t.env))<0);)s=s.slice(n).trim();o[e].content=s,s.length||(o[e-1].tight=!0,o[e+1].tight=!0)}}],["inline",function(t){var e,i,s,n=t.tokens;for(i=0,s=n.length;i<s;i++)"inline"===(e=n[i]).type&&t.inline.parse(e.content,t.options,t.env,e.children)}],["footnote_tail",function(t){var e,i,s,n,o,r,a,l,c,h=0,u=!1,d={};if(t.env.footnotes&&(t.tokens=t.tokens.filter(function(t){return"footnote_reference_open"===t.type?(u=!0,l=[],c=t.label,!1):"footnote_reference_close"===t.type?(u=!1,d[":"+c]=l,!1):(u&&l.push(t),!u)}),t.env.footnotes.list)){for(r=t.env.footnotes.list,t.tokens.push({type:"footnote_block_open",level:h++}),e=0,i=r.length;e<i;e++){for(t.tokens.push({type:"footnote_open",id:e,level:h++}),r[e].tokens?((a=[]).push({type:"paragraph_open",tight:!1,level:h++}),a.push({type:"inline",content:"",level:h,children:r[e].tokens}),a.push({type:"paragraph_close",tight:!1,level:--h})):r[e].label&&(a=d[":"+r[e].label]),t.tokens=t.tokens.concat(a),o="paragraph_close"===t.tokens[t.tokens.length-1].type?t.tokens.pop():null,n=r[e].count>0?r[e].count:1,s=0;s<n;s++)t.tokens.push({type:"footnote_anchor",id:e,subId:s,level:h});o&&t.tokens.push(o),t.tokens.push({type:"footnote_close",level:--h})}t.tokens.push({type:"footnote_block_close",level:--h})}}],["abbr2",function(t){var e,i,s,n,o,r,a,l,c,h,u,d,p=t.tokens;if(t.env.abbreviations)for(t.env.abbrRegExp||(d="(^|["+He.split("").map(Ve).join("")+"])("+Object.keys(t.env.abbreviations).map(function(t){return t.substr(1)}).sort(function(t,e){return e.length-t.length}).map(Ve).join("|")+")($|["+He.split("").map(Ve).join("")+"])",t.env.abbrRegExp=new RegExp(d,"g")),h=t.env.abbrRegExp,i=0,s=p.length;i<s;i++)if("inline"===p[i].type)for(e=(n=p[i].children).length-1;e>=0;e--)if("text"===(o=n[e]).type){for(l=0,r=o.content,h.lastIndex=0,c=o.level,a=[];u=h.exec(r);)h.lastIndex>l&&a.push({type:"text",content:r.slice(l,u.index+u[1].length),level:c}),a.push({type:"abbr_open",title:t.env.abbreviations[":"+u[2]],level:c++}),a.push({type:"text",content:u[2],level:c}),a.push({type:"abbr_close",level:--c}),l=h.lastIndex-u[3].length;a.length&&(l<r.length&&a.push({type:"text",content:r.slice(l),level:c}),p[i].children=n=[].concat(n.slice(0,e),a,n.slice(e+1)))}}],["replacements",function(t){var e,i,s,n,o;if(t.options.typographer)for(o=t.tokens.length-1;o>=0;o--)if("inline"===t.tokens[o].type)for(e=(n=t.tokens[o].children).length-1;e>=0;e--)"text"===(i=n[e]).type&&(s=Ke(s=i.content),We.test(s)&&(s=s.replace(/\+-/g,"±").replace(/\.{2,}/g,"…").replace(/([?!])…/g,"$1..").replace(/([?!]){4,}/g,"$1$1$1").replace(/,{2,}/g,",").replace(/(^|[^-])---([^-]|$)/gm,"$1—$2").replace(/(^|\s)--(\s|$)/gm,"$1–$2").replace(/(^|[^-\s])--([^-\s]|$)/gm,"$1–$2")),i.content=s)}],["smartquotes",function(t){var e,i,s,n,o,r,a,l,c,h,u,d,p,m,v,f,g;if(t.options.typographer)for(g=[],v=t.tokens.length-1;v>=0;v--)if("inline"===t.tokens[v].type)for(f=t.tokens[v].children,g.length=0,e=0;e<f.length;e++)if("text"===(i=f[e]).type&&!Xe.test(i.text)){for(a=f[e].level,p=g.length-1;p>=0&&!(g[p].level<=a);p--);g.length=p+1,o=0,r=(s=i.content).length;t:for(;o<r&&(Qe.lastIndex=o,n=Qe.exec(s),n);)if(l=!ti(s,n.index-1),o=n.index+1,m="'"===n[0],(c=!ti(s,o))||l){if(u=!c,d=!l)for(p=g.length-1;p>=0&&(h=g[p],!(g[p].level<a));p--)if(h.single===m&&g[p].level===a){h=g[p],m?(f[h.token].content=ei(f[h.token].content,h.pos,t.options.quotes[2]),i.content=ei(i.content,n.index,t.options.quotes[3])):(f[h.token].content=ei(f[h.token].content,h.pos,t.options.quotes[0]),i.content=ei(i.content,n.index,t.options.quotes[1])),g.length=p;continue t}u?g.push({token:e,pos:n.index,single:m,level:a}):d&&m&&(i.content=ei(i.content,n.index,"’"))}else m&&(i.content=ei(i.content,n.index,"’"))}}]];function si(){this.options={},this.ruler=new Be;for(var t=0;t<ii.length;t++)this.ruler.push(ii[t][0],ii[t][1])}function ni(t,e,i,s,n){var o,r,a,l,c,h,u;for(this.src=t,this.parser=e,this.options=i,this.env=s,this.tokens=n,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="",h=0,u=!1,a=l=h=0,c=(r=this.src).length;l<c;l++){if(o=r.charCodeAt(l),!u){if(32===o){h++;continue}u=!0}(10===o||l===c-1)&&(10!==o&&l++,this.bMarks.push(a),this.eMarks.push(l),this.tShift.push(h),u=!1,h=0,a=l+1)}this.bMarks.push(r.length),this.eMarks.push(r.length),this.tShift.push(0),this.lineMax=this.bMarks.length-1}function oi(t,e){var i,s,n;return(s=t.bMarks[e]+t.tShift[e])>=(n=t.eMarks[e])||42!==(i=t.src.charCodeAt(s++))&&45!==i&&43!==i||s<n&&32!==t.src.charCodeAt(s)?-1:s}function ri(t,e){var i,s=t.bMarks[e]+t.tShift[e],n=t.eMarks[e];if(s+1>=n||((i=t.src.charCodeAt(s++))<48||i>57))return-1;for(;;){if(s>=n)return-1;if(!((i=t.src.charCodeAt(s++))>=48&&i<=57)){if(41===i||46===i)break;return-1}}return s<n&&32!==t.src.charCodeAt(s)?-1:s}si.prototype.process=function(t){var e,i,s;for(e=0,i=(s=this.ruler.getRules("")).length;e<i;e++)s[e](t)},ni.prototype.isEmpty=function(t){return this.bMarks[t]+this.tShift[t]>=this.eMarks[t]},ni.prototype.skipEmptyLines=function(t){for(var e=this.lineMax;t<e&&!(this.bMarks[t]+this.tShift[t]<this.eMarks[t]);t++);return t},ni.prototype.skipSpaces=function(t){for(var e=this.src.length;t<e&&32===this.src.charCodeAt(t);t++);return t},ni.prototype.skipChars=function(t,e){for(var i=this.src.length;t<i&&this.src.charCodeAt(t)===e;t++);return t},ni.prototype.skipCharsBack=function(t,e,i){if(t<=i)return t;for(;t>i;)if(e!==this.src.charCodeAt(--t))return t+1;return t},ni.prototype.getLines=function(t,e,i,s){var n,o,r,a,l,c=t;if(t>=e)return"";if(c+1===e)return o=this.bMarks[c]+Math.min(this.tShift[c],i),r=s?this.eMarks[c]+1:this.eMarks[c],this.src.slice(o,r);for(a=new Array(e-t),n=0;c<e;c++,n++)(l=this.tShift[c])>i&&(l=i),l<0&&(l=0),o=this.bMarks[c]+l,r=c+1<e||s?this.eMarks[c]+1:this.eMarks[c],a[n]=this.src.slice(o,r);return a.join("")};var ai={};["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(t){ai[t]=!0});var li=/^<([a-zA-Z]{1,15})[\s\/>]/,ci=/^<\/([a-zA-Z]{1,15})[\s>]/;function hi(t,e){var i=t.bMarks[e]+t.blkIndent,s=t.eMarks[e];return t.src.substr(i,s-i)}function ui(t,e){var i,s,n=t.bMarks[e]+t.tShift[e],o=t.eMarks[e];return n>=o||126!==(s=t.src.charCodeAt(n++))&&58!==s||n===(i=t.skipSpaces(n))||i>=o?-1:i}var di=[["code",function(t,e,i){var s,n;if(t.tShift[e]-t.blkIndent<4)return!1;for(n=s=e+1;s<i;)if(t.isEmpty(s))s++;else{if(!(t.tShift[s]-t.blkIndent>=4))break;n=++s}return t.line=s,t.tokens.push({type:"code",content:t.getLines(e,n,4+t.blkIndent,!0),block:!0,lines:[e,t.line],level:t.level}),!0}],["fences",function(t,e,i,s){var n,o,r,a,l,c=!1,h=t.bMarks[e]+t.tShift[e],u=t.eMarks[e];if(h+3>u||126!==(n=t.src.charCodeAt(h))&&96!==n||(l=h,(o=(h=t.skipChars(h,n))-l)<3)||(r=t.src.slice(h,u).trim()).indexOf("`")>=0)return!1;if(s)return!0;for(a=e;!(++a>=i||(h=l=t.bMarks[a]+t.tShift[a],u=t.eMarks[a],h<u&&t.tShift[a]<t.blkIndent));)if(!(t.src.charCodeAt(h)!==n||t.tShift[a]-t.blkIndent>=4||(h=t.skipChars(h,n),h-l<o||(h=t.skipSpaces(h),h<u)))){c=!0;break}return o=t.tShift[e],t.line=a+(c?1:0),t.tokens.push({type:"fence",params:r,content:t.getLines(e+1,a,o,!0),lines:[e,t.line],level:t.level}),!0},["paragraph","blockquote","list"]],["blockquote",function(t,e,i,s){var n,o,r,a,l,c,h,u,d,p,m,v=t.bMarks[e]+t.tShift[e],f=t.eMarks[e];if(v>f||62!==t.src.charCodeAt(v++)||t.level>=t.options.maxNesting)return!1;if(s)return!0;for(32===t.src.charCodeAt(v)&&v++,l=t.blkIndent,t.blkIndent=0,a=[t.bMarks[e]],t.bMarks[e]=v,o=(v=v<f?t.skipSpaces(v):v)>=f,r=[t.tShift[e]],t.tShift[e]=v-t.bMarks[e],u=t.parser.ruler.getRules("blockquote"),n=e+1;n<i&&!((v=t.bMarks[n]+t.tShift[n])>=(f=t.eMarks[n]));n++)if(62!==t.src.charCodeAt(v++)){if(o)break;for(m=!1,d=0,p=u.length;d<p;d++)if(u[d](t,n,i,!0)){m=!0;break}if(m)break;a.push(t.bMarks[n]),r.push(t.tShift[n]),t.tShift[n]=-1337}else 32===t.src.charCodeAt(v)&&v++,a.push(t.bMarks[n]),t.bMarks[n]=v,o=(v=v<f?t.skipSpaces(v):v)>=f,r.push(t.tShift[n]),t.tShift[n]=v-t.bMarks[n];for(c=t.parentType,t.parentType="blockquote",t.tokens.push({type:"blockquote_open",lines:h=[e,0],level:t.level++}),t.parser.tokenize(t,e,n),t.tokens.push({type:"blockquote_close",level:--t.level}),t.parentType=c,h[1]=t.line,d=0;d<r.length;d++)t.bMarks[d+e]=a[d],t.tShift[d+e]=r[d];return t.blkIndent=l,!0},["paragraph","blockquote","list"]],["hr",function(t,e,i,s){var n,o,r,a=t.bMarks[e],l=t.eMarks[e];if((a+=t.tShift[e])>l||42!==(n=t.src.charCodeAt(a++))&&45!==n&&95!==n)return!1;for(o=1;a<l;){if((r=t.src.charCodeAt(a++))!==n&&32!==r)return!1;r===n&&o++}return!(o<3)&&(s||(t.line=e+1,t.tokens.push({type:"hr",lines:[e,t.line],level:t.level})),!0)},["paragraph","blockquote","list"]],["list",function(t,e,i,s){var n,o,r,a,l,c,h,u,d,p,m,v,f,g,b,y,w,x,k,S,_,O=!0;if((u=ri(t,e))>=0)v=!0;else{if(!((u=oi(t,e))>=0))return!1;v=!1}if(t.level>=t.options.maxNesting)return!1;if(m=t.src.charCodeAt(u-1),s)return!0;for(g=t.tokens.length,v?(h=t.bMarks[e]+t.tShift[e],p=Number(t.src.substr(h,u-h-1)),t.tokens.push({type:"ordered_list_open",order:p,lines:y=[e,0],level:t.level++})):t.tokens.push({type:"bullet_list_open",lines:y=[e,0],level:t.level++}),n=e,b=!1,x=t.parser.ruler.getRules("list");n<i&&((d=(f=t.skipSpaces(u))>=t.eMarks[n]?1:f-u)>4&&(d=1),d<1&&(d=1),o=u-t.bMarks[n]+d,t.tokens.push({type:"list_item_open",lines:w=[e,0],level:t.level++}),a=t.blkIndent,l=t.tight,r=t.tShift[e],c=t.parentType,t.tShift[e]=f-t.bMarks[e],t.blkIndent=o,t.tight=!0,t.parentType="list",t.parser.tokenize(t,e,i,!0),(!t.tight||b)&&(O=!1),b=t.line-e>1&&t.isEmpty(t.line-1),t.blkIndent=a,t.tShift[e]=r,t.tight=l,t.parentType=c,t.tokens.push({type:"list_item_close",level:--t.level}),n=e=t.line,w[1]=n,f=t.bMarks[e],!(n>=i||t.isEmpty(n)||t.tShift[n]<t.blkIndent));){for(_=!1,k=0,S=x.length;k<S;k++)if(x[k](t,n,i,!0)){_=!0;break}if(_)break;if(v){if((u=ri(t,n))<0)break}else if((u=oi(t,n))<0)break;if(m!==t.src.charCodeAt(u-1))break}return t.tokens.push({type:v?"ordered_list_close":"bullet_list_close",level:--t.level}),y[1]=n,t.line=n,O&&function(t,e){var i,s,n=t.level+2;for(i=e+2,s=t.tokens.length-2;i<s;i++)t.tokens[i].level===n&&"paragraph_open"===t.tokens[i].type&&(t.tokens[i+2].tight=!0,t.tokens[i].tight=!0,i+=2)}(t,g),!0},["paragraph","blockquote"]],["footnote",function(t,e,i,s){var n,o,r,a,l,c=t.bMarks[e]+t.tShift[e],h=t.eMarks[e];if(c+4>h||91!==t.src.charCodeAt(c)||94!==t.src.charCodeAt(c+1)||t.level>=t.options.maxNesting)return!1;for(a=c+2;a<h;a++){if(32===t.src.charCodeAt(a))return!1;if(93===t.src.charCodeAt(a))break}return!(a===c+2||a+1>=h||58!==t.src.charCodeAt(++a))&&(s||(a++,t.env.footnotes||(t.env.footnotes={}),t.env.footnotes.refs||(t.env.footnotes.refs={}),l=t.src.slice(c+2,a-2),t.env.footnotes.refs[":"+l]=-1,t.tokens.push({type:"footnote_reference_open",label:l,level:t.level++}),n=t.bMarks[e],o=t.tShift[e],r=t.parentType,t.tShift[e]=t.skipSpaces(a)-a,t.bMarks[e]=a,t.blkIndent+=4,t.parentType="footnote",t.tShift[e]<t.blkIndent&&(t.tShift[e]+=t.blkIndent,t.bMarks[e]-=t.blkIndent),t.parser.tokenize(t,e,i,!0),t.parentType=r,t.blkIndent-=4,t.tShift[e]=o,t.bMarks[e]=n,t.tokens.push({type:"footnote_reference_close",level:--t.level})),!0)},["paragraph"]],["heading",function(t,e,i,s){var n,o,r,a=t.bMarks[e]+t.tShift[e],l=t.eMarks[e];if(a>=l||(35!==(n=t.src.charCodeAt(a))||a>=l))return!1;for(o=1,n=t.src.charCodeAt(++a);35===n&&a<l&&o<=6;)o++,n=t.src.charCodeAt(++a);return!(o>6||a<l&&32!==n)&&(s||(l=t.skipCharsBack(l,32,a),(r=t.skipCharsBack(l,35,a))>a&&32===t.src.charCodeAt(r-1)&&(l=r),t.line=e+1,t.tokens.push({type:"heading_open",hLevel:o,lines:[e,t.line],level:t.level}),a<l&&t.tokens.push({type:"inline",content:t.src.slice(a,l).trim(),level:t.level+1,lines:[e,t.line],children:[]}),t.tokens.push({type:"heading_close",hLevel:o,level:t.level})),!0)},["paragraph","blockquote"]],["lheading",function(t,e,i){var s,n,o,r=e+1;return!(r>=i||t.tShift[r]<t.blkIndent||t.tShift[r]-t.blkIndent>3||(n=t.bMarks[r]+t.tShift[r],o=t.eMarks[r],n>=o)||(s=t.src.charCodeAt(n),45!==s&&61!==s)||(n=t.skipChars(n,s),n=t.skipSpaces(n),n<o))&&(n=t.bMarks[e]+t.tShift[e],t.line=r+1,t.tokens.push({type:"heading_open",hLevel:61===s?1:2,lines:[e,t.line],level:t.level}),t.tokens.push({type:"inline",content:t.src.slice(n,t.eMarks[e]).trim(),level:t.level+1,lines:[e,t.line-1],children:[]}),t.tokens.push({type:"heading_close",hLev