deep-chat-dev
Version:
Customizable chat component for AI APIs
1 lines • 401 kB
JavaScript
const t="classList",e="style",s="length",i=(t="div")=>document.createElement(t);class n{static render(t,e){const s=i();s.id="error-view",s.innerText=e,t.replaceChildren(s)}}class o{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,s){const i=o.createElements(),r={onSuccess:e,onFail:n.render.bind(this,t,"Your 'key' has failed authentication"),onLoad:o.onLoad.bind(this,i)};s.key&&s.verifyKey(s.key,r),t.replaceChildren(i)}}const r="service",a="text",l="html",c="error",h="https://deepchat.dev/docs/",u="ai",d="user",p="assistant",m="error-message-text",v="deep-chat-outer-container-role-",f="empty-message",g="deep-chat-top-message",b="deep-chat-middle-message",y="deep-chat-bottom-message",w="src",x="type",k="file",_="files",A="image",C="images",T="camera",M="gifs",S="audio",E="microphone",j="mixedFiles",$="any",I="file-message",P="start",O="messages",B="role",R="string",F=t=>JSON.stringify(t),L=t=>JSON.parse(F(t));function q(t){return t.charAt(0).toUpperCase()+t.slice(1)}function z(t,e,s,i){const n=`\n${q(e)} message: ${F(t)} \n`,o=s?`${q(e)} message after interceptor: ${function(t){return t&&F(t)}(i)} \n`:"";return n+o}const D=function(t,e,s,i){return`${z(t,e,s,i)}Make sure the ${e} message is using the Response format: ${h}connect/#Response \nYou can also augment it using the responseInterceptor property: ${h}interceptors#responseInterceptor`},N=function(t,e){const s="request";return`${z(t,s,e)}Make sure the ${s} message is using the {body: {text: string}} format, e.g: {body: {text: "Model Response"}}`},U=function(t,e,s){const i="response";return`${z(t,i,e,s)}Make sure the ${i} message is using the {text: string} format, e.g: {text: "Model Response"}`},H=function(t){return`${t} failed - please wait for chat view to render before calling this property.`},V="Invalid API Key",W="Failed to connect",G="Request settings have not been set up",Z="No file was added",K="Image was not found",J="Multi-response arrays are not supported for streaming",X=`Make sure the events are using {text: string} or {html: string} format.\nYou can also augment them using the responseInterceptor property: ${h}interceptors#responseInterceptor`,Q=`No valid stream events were sent.\n${X}`,Y="Please define a `function_handler` property inside the service config.",tt="Function tool response must be an array or contain a text property",et="Failed to fetch history";class st{static apply(t,e){if(e)try{st.applyStyleSheet(t,e)}catch{st.addStyleElement(t,e)}}static applyStyleSheet(t,e){const s=new CSSStyleSheet;s.replaceSync(t),e.adoptedStyleSheets.push(s)}static addStyleElement(t,e){const s=i("style");s.innerHTML=t,e.appendChild(s)}static camelToKebab(t){return t.replace(/[A-Z]/g,t=>`-${t.toLowerCase()}`)}static applyChatStyle(t,e){if(!t||!e)return;const s=Object.entries(t).filter(([,t])=>t).map(([t,e])=>`${st.camelToKebab(t)}: ${e};`).join(" ");s&&st.apply(`:host { ${s} }`,e)}}const it="inside-start",nt="inside-end",ot="outside-start",rt="outside-end",at="dropup-menu",lt="default",ct="hover",ht="click",ut="active",dt="disabled",pt="svg",mt="unavailable",vt="styles",ft="mouseenter",gt="mouseleave",bt="submit",yt="loading",wt="stop",xt="unsupported",kt="commandMode";class _t{static unsetStyle(t,s){const i=Object.keys(s).reduce((t,e)=>(t[e]="",t),{});Object.assign(t[e],i)}static unsetActivityCSSMouseStates(t,e){e[ht]&&_t.unsetStyle(t,e[ht]),e[ct]&&_t.unsetStyle(t,e[ct])}static unsetAllCSSMouseStates(t,e){_t.unsetActivityCSSMouseStates(t,e),e[lt]&&_t.unsetStyle(t,e[lt])}static processStateful(t){const e=t[lt]||{},s=Object.assign(L(e),null==t?void 0:t[ct]),i=Object.assign(L(s),null==t?void 0:t[ht]);return{[lt]:e,[ct]:s,[ht]:i}}static mergeStatefulStyles(t){const e={[lt]:{},[ct]:{},[ht]:{}};return t.forEach(t=>{e[lt]=Object.assign(e[lt],t[lt]),e[ct]=Object.assign(e[ct],t[ct]),e[ht]=Object.assign(e[ht],t[ht])}),e}static overwriteDefaultWithAlreadyApplied(t,s){Object.keys(t[lt]||[]).forEach(i=>{var n;const o=i;s[e][o]&&null!=(n=t[lt])&&n[o]&&(t[lt][i]=s[e][o])})}static applyToStyleIfNotDefined(t,e){for(const s in e){const i=e[s];""===t[s]&&i&&(t[s]=i)}}}const At=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,s){if(s)return"boolean"==typeof s?{[a]:t}:{[a]:s[a]||t,timeout:s.timeout||0,style:s[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[a]&&(n.children[0].textContent=i[a]),{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,s){clearTimeout(t.timeout),t.element[e].visibility="hidden",s[e]&&_t.unsetStyle(t.element,s[e]),t.element[e].left="",t.element[e].top=""}};At.OVERFLOW_NEW_POSITION_PX=4;let Ct=At;const Tt=class{};Tt.IS_SAFARI=/^((?!chrome|android).)*safari/i.test(navigator.userAgent),Tt.IS_CHROMIUM=window.chrome,Tt.IS_MOBILE=/iPhone|iPad|iPod|Android/i.test(navigator.userAgent);let Mt=Tt;var St=(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))(St||{});const Et=class t{static add(e,s,i,n){void 0!==i&&e.addEventListener("keydown",t.onKeyDown.bind(this,i)),e.oninput=t.onInput.bind(this,i,n),e.addEventListener("paste",t=>{var e;t.preventDefault(),null!=(e=t.clipboardData)&&e[_].length&&s.addFilesToAnyType(Array.from(t.clipboardData[_]))})}static onKeyDown(e,s){const i=s.target.textContent;i&&i.length>=e&&!t.PERMITTED_KEYS.has(s.key)&&!t.isKeyCombinationPermitted(s)&&s.preventDefault()}static isKeyCombinationPermitted(t){return"a"===t.key&&(t.ctrlKey||t.metaKey)}static onInput(t,e,s){const i=s.target,n=i.textContent||"";void 0!==t&&n.length>t&&(i.textContent=n.substring(0,t),Ot.focusEndOfInput(i)),null==e||e()}};Et.PERMITTED_KEYS=new Set([St.BACKSPACE,St.DELETE,St.ARROW_RIGHT,St.ARROW_LEFT,St.ARROW_DOWN,St.ARROW_UP,St.META,St.CONTROL,St.ENTER]);let jt=Et;class $t{static sanitizePastedTextContent(t){var e;t.preventDefault();const s=null==(e=t.clipboardData)?void 0:e.getData("text/plain");if(!s)return;const i=s.replace(/&/g,"&").replace(/</g,"<").replace(/>/g,">").replace(/\n/g,"<br>");document.execCommand("insertHTML",!1,i)}}const It=class s{constructor(t,e,i,n){var o,r,l,c;this._isComposing=!1;const h=s.processConfig(e,t.textInput);this.elementRef=s.createContainerElement(null==(o=null==h?void 0:h[vt])?void 0:o.container),this._config=h,this.inputElementRef=this.createInputElement(null==(r=t.defaultInput)?void 0:r[a],n),s.addFilesToAnyType(i,null==(l=t.defaultInput)?void 0:l[_]),this.elementRef.appendChild(this.inputElementRef),t.setPlaceholderText=this.setPlaceholderText.bind(this),t.setPlaceholderText((null==(c=this._config.placeholder)?void 0:c[a])||"Ask me anything!"),this._browserStorage=n,setTimeout(()=>{jt.add(this.inputElementRef,i,this._config.characterLimit,t._validationHandler),this._onInput=e.onInput})}static processConfig(t,e){var s;return e??(e={}),e[dt]??(e[dt]=t.isTextInputDisabled),e.placeholder??(e.placeholder={}),(s=e.placeholder)[a]??(s[a]=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 s,i,n;const o=window.scrollY;this.inputElementRef[t].contains(`text-input-${dt}`)||(Object.assign(this.inputElementRef[e],null==(s=this._config.placeholder)?void 0:s[e]),this.inputElementRef.textContent="",Ot.focusEndOfInput(this.inputElementRef),null==(i=this._onInput)||i.call(this,!1),null==(n=this._browserStorage)||n.addInputText("")),Mt.IS_CHROMIUM&&window.scrollTo({top:o})}createInputElement(n,o){var r,l,c,h;const u=i();return u.id=s.TEXT_INPUT_ID,u[t].add("text-input-styling"),u[B]="textbox","string"==typeof n?u.innerText=n:null!=o&&o.trackInputText&&(u.innerText=o.get().inputText||""),Mt.IS_MOBILE&&u.setAttribute("tabindex","0"),Mt.IS_CHROMIUM&&s.preventAutomaticScrollUpOnNewLine(u),"boolean"==typeof this._config[dt]&&!0===this._config[dt]?(u.contentEditable="false",u[t].add(`text-input-${dt}`),u.setAttribute(`aria-${dt}`,"true")):(u.contentEditable="true",u.removeAttribute(`aria-${dt}`),this.addEventListeners(u)),Object.assign(u[e],null==(r=this._config[vt])?void 0:r[a]),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 s,i,n,o;!this.inputElementRef[t].contains(`text-input-${dt}`)&&null!=(s=this._config.placeholder)&&s[e]&&(_t.unsetStyle(this.inputElementRef,null==(i=this._config.placeholder)?void 0:i[e]),Object.assign(this.inputElementRef[e],null==(o=null==(n=this._config)?void 0:n[vt])?void 0:o[a]))}addEventListeners(t){var s,i;null!=(s=this._config[vt])&&s.focus&&(t.onfocus=()=>{var t;return Object.assign(this.elementRef[e],null==(t=this._config[vt])?void 0:t.focus)},t.onblur=this.onBlur.bind(this,this._config[vt].focus,null==(i=this._config[vt])?void 0:i.container)),t.addEventListener("keydown",this.onKeydown.bind(this)),t.addEventListener("input",this.onInput.bind(this)),t.addEventListener("paste",$t.sanitizePastedTextContent),t.addEventListener("compositionstart",()=>this._isComposing=!0),t.addEventListener("compositionend",()=>this._isComposing=!1)}onBlur(t,s){_t.unsetStyle(this.elementRef,t),s&&Object.assign(this.elementRef[e],s)}onKeydown(t){var e;t.key===St.ENTER&&!Mt.IS_MOBILE&&!this._isComposing&&!t.ctrlKey&&!t.shiftKey&&(t.preventDefault(),null==(e=this.submit)||e.call(this))}onInput(){var t,s;this.isTextInputEmpty()?Object.assign(this.inputElementRef[e],null==(t=this._config.placeholder)?void 0:t[e]):this.removePlaceholderStyle(),null==(s=this._onInput)||s.call(this,!0)}setPlaceholderText(t){this.inputElementRef.setAttribute("deep-chat-placeholder-text",t),this.inputElementRef.setAttribute("aria-label",t)}isTextInputEmpty(){return""===this.inputElementRef.textContent}};It.TEXT_INPUT_ID="text-input";let Pt=It;class Ot{static focusEndOfInput(t){const e=document.createRange();e.selectNodeContents(t),e.collapse(!1);const s=window.getSelection();null==s||s.removeAllRanges(),null==s||s.addRange(e),(Mt.IS_MOBILE||Mt.IS_SAFARI)&&t.focus()}static focusFromParentElement(t){const e=t.querySelector(`#${Pt.TEXT_INPUT_ID}`);e&&Ot.focusEndOfInput(e)}}const Bt="Authentication",Rt="Authorization",Ft="authorization",Lt="Unauthorized",qt="Authorization header",zt="Invalid",Dt="Incorrect",Nt="authentication_error",Ut="invalid_request_error",Ht="Content-Type",Vt="content-type",Wt="application/json",Gt="object",Zt="completed",Kt="Bearer ",Jt="GET",Xt="POST",Qt="Upload an audio file",Yt="function_call",te="input_audio",ee="image_url",se="system",ie="placeholder",ne=class t{static addElements(t,...e){e.forEach(e=>t.appendChild(e))}static isScrollbarAtBottomOfElement(e,s=t.CODE_SNIPPET_GENERATION_JUMP){const i=e.scrollHeight,n=e.clientHeight;return e.scrollTop>=i-n-s}static cloneElement(t){const e=t.cloneNode(!0);return t.parentNode.replaceChild(e,t),e}static scrollToBottom(t,e=!1,s){t.scrollButton&&t.scrollButton.hiddenElements.size>0&&t.scrollButton.clearHidden(),s?t.elementRef.scrollTo({left:0,top:s.offsetTop}):e?t.elementRef.scrollTo({left:0,top:t.elementRef.scrollHeight,behavior:"smooth"}):t.elementRef.scrollTop=t.elementRef.scrollHeight}static scrollToTop(t){t.scrollTop=0}static isVisibleInParent(t,e){const s=t.getBoundingClientRect(),i=e.getBoundingClientRect();return s.bottom>i.top&&s.top<i.bottom}static waitForScrollEnd(t,e){let s=-1,i=0;const n=()=>{const o=t.scrollTop;if(o===s){if(i++,i>2)return void e()}else i=0,s=o;requestAnimationFrame(n)};requestAnimationFrame(n)}static assignButtonEvents(t,e){t.onclick=e,t.onkeydown=t=>{t.key===St.ENTER&&setTimeout(e)}}};ne.CODE_SNIPPET_GENERATION_JUMP=1;let oe=ne;const re=class t{static speak(t,e){if(!e.audio&&window.SpeechSynthesisUtterance){const s=new SpeechSynthesisUtterance(t);Object.assign(s,e),speechSynthesis.speak(s)}}static processConfig(e,s){const i={};setTimeout(()=>{if("object"==typeof e&&(e.audio&&(i.audio=e.audio),e.lang&&(i.lang=e.lang),e.pitch&&(i.pitch=e.pitch),e.rate&&(i.rate=e.rate),e.volume&&(i.volume=e.volume),e.voiceName)){const t=window.speechSynthesis.getVoices().find(t=>{var s;return t.name.toLocaleLowerCase()===(null==(s=e.voiceName)?void 0:s.toLocaleLowerCase())});t&&(i.voice=t)}s(i)},t.LOAD_VOICES_MS)}};re.LOAD_VOICES_MS=200;let ae=re;const le=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(s,i){var n,o;if(null!=(o=null==(n=null==i?void 0:i[vt])?void 0:n.bubble)&&o.color){const n=t.colorToHex(i[vt].bubble.color);s[e].setProperty("--loading-message-color",n),s[e].setProperty("--loading-message-color-fade",`${n}33`)}else s[e].setProperty("--loading-message-color","#848484"),s[e].setProperty("--loading-message-color-fade","#55555533")}static setRing(s,i){const{color:n,width:o,height:r,margin:a,border:l}=i||{};if(n){const i=t.colorToHex(n);s[e].setProperty("--loading-history-color",i)}else s[e].setProperty("--loading-history-color","#dbdbdb");s[e].setProperty("--loading-history-height",r||"57px"),s[e].setProperty("--loading-history-width",o||"57px"),s[e].setProperty("--loading-history-margin",a||"7px"),s[e].setProperty("--loading-history-border",l||"6px solid")}};le.BUBBLE_CLASS="deep-chat-loading-message-bubble",le.DOTS_CONTAINER_CLASS="deep-chat-loading-message-dots-container";let ce=le;class he{static checkForContainerStyles(t,s){const i=t.containerStyle;i&&(Object.assign(s[e],i),console[c](`The containerStyle property${de}1.3.14.`),console[c](`${pe}the style property instead: ${h}styles#style`))}static handleResponseProperty(t){return console[c](`The {result: ....} response object type${de}1.3.0.`),console[c](`${pe}the new response object: ${h}connect#Response`),t.result}static processHistory(t){const e=t.initialMessages;if(e)return console[c](`The initialMessages property${de}2.0.0.`),console[c](`${pe}the history property instead: ${h}messages/#history`),e}static processHistoryFile(t){const e=t[k];e&&(console[c](`The file property in MessageContent${de}1.3.17.`),console[c](`${pe}the files array property: ${h}messages/#MessageContent`),t[_]=[e])}static processValidateInput(t){const e=t.validateMessageBeforeSending;if(e)return console[c](`The validateMessageBeforeSending property${de}1.3.24.`),console[c](`${pe}validateInput: ${h}interceptors#validateInput`),e}static processSubmitUserMessage(t){return console[c](`The submitUserMessage(text: string) argument string type${de}1.4.4.`),console[c](`${pe}the new argument type: ${h}methods#submitUserMessage`),{[a]:t}}static flagHTMLUpdateClass(e){var s;null!=(s=e.children[0])&&s[t].contains("deep-chat-update-message")&&(console[c](`The "deep-chat-update-message" html class${de}1.4.4.`),console[c](`${pe}using {..., overwrite: true} object: ${h}connect#Response`))}static processConnect(t){const e=t;e.request&&(e.connect?Object.assign(e.connect,e.request):e.connect=e.request,console[c](`The request property${de}2.0.0.`),console[c](`${me}connect object: ${h}connect#connect-1`))}static checkForStream(t){const e=t.stream;if(e)return console[c](`The stream property${fe}the connect object in version 2.0.0.`),console[c](`${me}connect object: ${h}connect#connect-1`),e}static fireOnNewMessage(t,e){var s;const i=t;i.onNewMessage&&(console[c](`The onNewMessage event${de}2.0.0.`),console[c](`${me}onMessage event: ${h}events#onMessage`),null==(s=i.onNewMessage)||s.call(i,e)),t.dispatchEvent(new CustomEvent("new-message",{detail:e}))}static processFileConfigConnect(t){const e=t;e.request&&(console[c](`The request property in file configuration${de}2.0.0.`),console[c](`Please use the connect property instead: ${h}files`),e.connect||(e.connect=e.request))}static processMessageStyles(t){if(!t)return;const e=L(t),s=e.loading;return s&&(s.outerContainer||s.innerContainer||s.bubble||s.media)&&(console[c](`The loading message styles are defined using LoadingMessageStyles interface${ue}2.1.0.`),console[c](`Check it out here: ${h}messages/styles#LoadingMessageStyles`),e.loading={message:{styles:s}}),e}static processDemo(t){return"boolean"==typeof t||t.displayLoadingBubble&&(console[c](`The demo displayLoadingBubble property${de}2.1.0.`),console[c](`Please use displayLoading instead: ${h}modes#demo`),t.displayLoading={message:!0}),t}static processCohere(t){const e=t,s=`${me}official documentation: ${h}directConnection/Cohere`;return e.chat&&(console[c](`Cohere chat property${de}2.2.3.`),console[c](s),delete e.chat),e.textGeneration?(console[c](`Cohere textGeneration${ve}2.2.3.`),console[c](s),delete e.textGeneration,!1):!e.summarization||(console[c](`Cohere summarization${ve}2.2.3.`),console[c](s),delete e.summarization,!1)}static processStreamHTMLWrappers(t){if(!t||typeof t!==Gt)return;const e=t.htmlWrappers;return e?(console[c](`The htmlWrappers property${fe}Deep Chat's base${ue}2.3.0.`),console[c](`Check it out here: ${h}messages/HTML#htmlWrappers`),e):void 0}static processFocusMode(t){return!t||"boolean"==typeof t||t.scroll&&(console[c](`The scroll property in focusMode has been changed to smoothScroll${ue}2.3.0.`),console[c](`Check it out here: ${h}modes#focusMode`),t.smoothScroll=!0),t}static processPosition(t){if(!t)return t;const e=`Position names have been updated${ue}2.3.1.`;return"inside-left"===t?(console[c](e),it):"inside-right"===t?(console[c](e),nt):"outside-left"===t?(console[c](e),ot):"outside-right"===t?(console[c](e),rt):t}static processBrowserStorage(t){const e=t.get();e&&Array.isArray(e)&&t.addMessages(e)}}const ue=" since version ",de=` is deprecated ${ue}`,pe="Please change to using ",me="Please see the ",ve=` is not supported ${ue}`,fe=" has been moved to ";class ge{static mouseUp(t,s){_t.unsetAllCSSMouseStates(t,s),Object.assign(t[e],s[lt]),Object.assign(t[e],s[ct])}static mouseDown(t,s){Object.assign(t[e],s[ht])}static mouseLeave(t,s){_t.unsetAllCSSMouseStates(t,s),Object.assign(t[e],s[lt])}static mouseEnter(t,s){Object.assign(t[e],s[ct])}static add(t,e){t.addEventListener(ft,ge.mouseEnter.bind(this,t,e)),t.addEventListener(gt,ge.mouseLeave.bind(this,t,e)),t.addEventListener("mousedown",ge.mouseDown.bind(this,t,e)),t.addEventListener("mouseup",ge.mouseUp.bind(this,t,e))}}const be={"deep-chat-button":{styles:{[lt]:{backgroundColor:"white",padding:"5px",paddingLeft:"7px",paddingRight:"7px",border:"1px solid #c2c2c2",borderRadius:"6px",cursor:"pointer"},[ct]:{backgroundColor:"#fafafa"},[ht]:{backgroundColor:"#f1f1f1"}}}},ye=Object.keys(be);class we{static applySuggestionEvent(t,e){setTimeout(()=>{e.addEventListener(ht,()=>{var s,i;null==(i=t.submitUserMessage)||i.call(t,{[a]:(null==(s=e.textContent)?void 0:s.trim())||""})})})}static isElementTemporary(e){var s;return!!e&&(null==(s=e.bubbleElement.children[0])?void 0:s[t].contains("deep-chat-temporary-message"))}static doesElementContainDeepChatClass(e){return ye.find(s=>e[t].contains(s))}static applyEvents(t,e){const s=be[e].events;Object.keys(s||[]).forEach(e=>{t.addEventListener(e,null==s?void 0:s[e])})}static getProcessedStyles(e,s,i){const n=Array.from(s[t]).reduce((t,s)=>{var i;const n=null==(i=e[s])?void 0:i[vt];return n&&e[s][vt]&&t.push(n),t},[]),o=be[i][vt];if(o){const t=L(o);t[lt]&&_t.overwriteDefaultWithAlreadyApplied(t,s),n.unshift(t)}const r=_t.mergeStatefulStyles(n);return _t.processStateful(r)}static applyDeepChatUtilities(t,e,s){ye.forEach(t=>{const i=s.getElementsByClassName(t);Array.from(i||[]).forEach(s=>{const i=we.getProcessedStyles(e,s,t);xe.applyStylesToElement(s,i),we.applyEvents(s,t)})});const i=s.getElementsByClassName("deep-chat-suggestion-button");Array.from(i).forEach(e=>we.applySuggestionEvent(t,e))}}class xe{static applyStylesToElement(t,s){const i=_t.processStateful(s);ge.add(t,i),Object.assign(t[e],i[lt])}static applyEventsToElement(t,e){Object.keys(e).forEach(s=>{const i=e[s];i&&t.addEventListener(s,i)})}static applyClassUtilitiesToElement(t,e){const{events:s,styles:i}=e;s&&xe.applyEventsToElement(t,s),i&&!we.doesElementContainDeepChatClass(t)&&xe.applyStylesToElement(t,i)}static applyCustomClassUtilities(t,e){Object.keys(t).forEach(s=>{const i=e.getElementsByClassName(s);Array.from(i).forEach(e=>{t[s]&&xe.applyClassUtilitiesToElement(e,t[s])})})}static apply(t,e){we.applyDeepChatUtilities(t,t.htmlClassUtilities,e),xe.applyCustomClassUtilities(t.htmlClassUtilities,e)}static traverseNodes(t,e){t.nodeType===Node.ELEMENT_NODE&&e.push(t.outerHTML),t.childNodes.forEach(t=>{xe.traverseNodes(t,e)})}static splitHTML(t){const e=(new DOMParser).parseFromString(t,"text/html"),s=[];return e.body.childNodes.forEach(t=>{xe.traverseNodes(t,s)}),s}static isTemporaryBasedOnHTML(t){const e=i();return e.innerHTML=t,we.isElementTemporary({outerContainer:e,bubbleElement:e,innerContainer:e})}static replaceElementWithNewClone(t,e){var s;const i=(e||t).cloneNode(!0);return null==(s=t.parentNode)||s.replaceChild(i,t),i}static tryAddWrapper(t,e,s,i){if(e&&i){const e=(null==s?void 0:s[i])||(null==s?void 0:s[lt]);if(e)return t.innerHTML=e,{contentEl:xe.getTargetWrapper(t),wrapper:!0}}return{contentEl:t,wrapper:!1}}static getTargetWrapper(t){return t.getElementsByClassName("html-wrapper")[0]||t}}const ke=class e{static createElements(s,i,n,o,r=!1){const a=s.createMessageElementsOnOrientation("",n,o,r);a.bubbleElement[t].add(e.HTML_BUBBLE_CLASS);const{contentEl:l}=xe.tryAddWrapper(a.bubbleElement,i,s._customWrappers,n);return l.innerHTML=i,a}static overwriteElements(t,e,s){s.bubbleElement.innerHTML=e,xe.apply(t,s.outerContainer),he.flagHTMLUpdateClass(s.bubbleElement)}static overwrite(t,s,i,n){const{messageToElements:o}=t,r=mi.overwriteMessage(o,n,s,i,l,e.HTML_BUBBLE_CLASS);return r&&e.overwriteElements(t,s,r),r}static create(t,s,i,n=!1){var o;const r=e.createElements(t,s,i,n);return mi.fillEmptyMessageElement(r.bubbleElement,s),xe.apply(t,r.outerContainer),he.flagHTMLUpdateClass(r.bubbleElement),t.applyCustomStyles(r,i,!1,null==(o=t.messageStyles)?void 0:o[l]),r}static add(t,s,i,n,o=!1){if(null!=n&&n.status){const e=this.overwrite(t,s,i,t.messageElementRefs);if(e)return e;n.status=!1}if(o&&t.messageElementRefs.length>0&&xe.isTemporaryBasedOnHTML(s))return;const r=e.create(t,s,i,o);return o||t.appendOuterContainerElemet(r.outerContainer),r}};ke.HTML_BUBBLE_CLASS="html-message";let _e=ke;class Ae{static katex(t,e,s){const i=(s||{}).delimiter||"$";if(1!==i.length)throw new Error("invalid delimiter");e.inline.ruler.push("katex",(t,e)=>{const s=t.pos,n=t.posMax;let o=s;if(t[w].charAt(o)!==i)return!1;for(++o;o<n&&t[w].charAt(o)===i;)++o;const r=t[w].slice(s,o);if(r.length>2)return!1;const a=o;let l=0;for(;o<n;){const s=t[w].charAt(o);if("{"!==s||0!==o&&"\\"===t[w].charAt(o-1)){if("}"!==s||0!==o&&"\\"===t[w].charAt(o-1)){if(s===i&&0===l){const s=o;let l=o+1;for(;l<n&&t[w].charAt(l)===i;)++l;if(l-s===r.length){if(!e){const e=t[w].slice(a,s).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},s),e.block.ruler.push("katex",(t,e,s)=>{let n=!1,o=t.bMarks[e]+t.tShift[e],r=t.eMarks[e];if(o+1>r)return!1;const a=t[w].charAt(o);if(a!==i)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>=s||(o=l=t.bMarks[h]+t.tShift[h],r=t.eMarks[h],o<r&&t.tShift[h]<t.blkIndent));)if(!(t[w].charAt(o)!==i||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},s),e.renderer.rules.katex=(e,s)=>((e,s)=>{var i;return(null==(i=window.katex)?void 0:i.renderToString(e,{displayMode:s,throwOnError:!1,output:"mathml",...t}))||""})(e[s].content,e[s].block),e.renderer.rules.katex.delimiter=i}}var Ce;function Te(t){return(Ce=Ce||document.createElement("textarea")).innerHTML="&"+t+";",Ce.value}var Me=Object.prototype.hasOwnProperty;function Se(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(s){t[s]=e[s]})}}),t}var Ee=/\\([\\!"#$%&'()*+,.\/:;<=>?@[\]^_`{|}~-])/g;function je(t){return t.indexOf("\\")<0?t:t.replace(Ee,"$1")}function $e(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 Ie(t){if(t>65535){var e=55296+((t-=65536)>>10),s=56320+(1023&t);return String.fromCharCode(e,s)}return String.fromCharCode(t)}var Pe=/&([a-z#][a-z0-9]{1,31});/gi,Oe=/^#((?:x[a-f0-9]{1,8}|[0-9]{1,8}))/i;function Be(t,e){var s=0,i=Te(e);return e!==i?i:35===e.charCodeAt(0)&&Oe.test(e)&&$e(s="x"===e[1].toLowerCase()?parseInt(e.slice(2),16):parseInt(e.slice(1),10))?Ie(s):t}function Re(t){return t.indexOf("&")<0?t:t.replace(Pe,Be)}var Fe=/[&<>"]/,Le=/[&<>"]/g,qe={"&":"&","<":"<",">":">",'"':"""};function ze(t){return qe[t]}function De(t){return Fe.test(t)?t.replace(Le,ze):t}var Ne={};function Ue(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?Ue(t,e+2):e}Ne.blockquote_open=function(){return"<blockquote>\n"},Ne.blockquote_close=function(t,e){return"</blockquote>"+He(t,e)},Ne.code=function(t,e){return t[e].block?"<pre><code>"+De(t[e].content)+"</code></pre>"+He(t,e):"<code>"+De(t[e].content)+"</code>"},Ne.fence=function(t,e,s,i,n){var o,r,a=t[e],l="",c=s.langPrefix;if(a.params){if(r=(o=a.params.split(/\s+/g)).join(" "),function(t,e){return!!t&&Me.call(t,e)}(n.rules.fence_custom,o[0]))return n.rules.fence_custom[o[0]](t,e,s,i,n);l=' class="'+c+De(Re(je(r)))+'"'}return"<pre><code"+l+">"+(s.highlight&&s.highlight.apply(s.highlight,[a.content].concat(o))||De(a.content))+"</code></pre>"+He(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,s){return(s.xhtmlOut?"<hr />":"<hr>")+He(t,e)},Ne.bullet_list_open=function(){return"<ul>\n"},Ne.bullet_list_close=function(t,e){return"</ul>"+He(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 s=t[e];return"<ol"+(s.order>1?' start="'+s.order+'"':"")+">\n"},Ne.ordered_list_close=function(t,e){return"</ol>"+He(t,e)},Ne.paragraph_open=function(t,e){return t[e].tight?"":"<p>"},Ne.paragraph_close=function(t,e){var s=!(t[e].tight&&e&&"inline"===t[e-1].type&&!t[e-1].content);return(t[e].tight?"":"</p>")+(s?He(t,e):"")},Ne.link_open=function(t,e,s){var i=t[e].title?' title="'+De(Re(t[e].title))+'"':"",n=s.linkTarget?' target="'+s.linkTarget+'"':"";return'<a href="'+De(t[e].href)+'"'+i+n+">"},Ne.link_close=function(){return"</a>"},Ne.image=function(t,e,s){var i=' src="'+De(t[e].src)+'"',n=t[e].title?' title="'+De(Re(t[e].title))+'"':"";return"<img"+i+(' alt="'+(t[e].alt?De(Re(je(t[e].alt))):"")+'"')+n+(s.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 s=t[e];return"<th"+(s.align?' style="text-align:'+s.align+'"':"")+">"},Ne.th_close=function(){return"</th>"},Ne.td_open=function(t,e){var s=t[e];return"<td"+(s.align?' style="text-align:'+s.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>"+De(t[e].content)+"</sub>"},Ne.sup=function(t,e){return"<sup>"+De(t[e].content)+"</sup>"},Ne.hardbreak=function(t,e,s){return s.xhtmlOut?"<br />\n":"<br>\n"},Ne.softbreak=function(t,e,s){return s.breaks?s.xhtmlOut?"<br />\n":"<br>\n":"\n"},Ne.text=function(t,e){return De(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="'+De(Re(t[e].title))+'">'},Ne.abbr_close=function(){return"</abbr>"},Ne.footnote_ref=function(t,e){var s=Number(t[e].id+1).toString(),i="fnref"+s;return t[e].subId>0&&(i+=":"+t[e].subId),'<sup class="footnote-ref"><a href="#fn'+s+'" id="'+i+'">['+s+"]</a></sup>"},Ne.footnote_block_open=function(t,e,s){return(s.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 s="fnref"+Number(t[e].id+1).toString();return t[e].subId>0&&(s+=":"+t[e].subId),' <a href="#'+s+'" 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 He=Ne.getBreak=function(t,e){return(e=Ue(t,e))<t.length&&"list_item_close"===t[e].type?"":"\n"};function Ve(){this.rules=Se({},Ne),this.getBreak=Ne.getBreak}function We(){this.t=[],this.i=null}function Ge(t,e,s,i,n){this.src=t,this.env=i,this.options=s,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 Ze(t,e){var s,i,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,s=1;t.pos<r;){if(91===(n=t.src.charCodeAt(t.pos)))s++;else if(93===n&&0===--s){i=!0;break}t.parser.skipToken(t)}return i?(o=t.pos,t.labelUnmatchedScopes=0):t.labelUnmatchedScopes=s-1,t.pos=a,t.isInLabel=l,o}function Ke(t,e,s,i){var n,o,r,a,l,c;if(42!==t.charCodeAt(0)||91!==t.charCodeAt(1)||-1===t.indexOf("]:")||((o=Ze(n=new Ge(t,e,s,i,[]),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:(i.abbreviations||(i.abbreviations={}),typeof i.abbreviations[":"+l]>"u"&&(i.abbreviations[":"+l]=c),r)}function Je(t){var e=Re(t);try{e=decodeURI(e)}catch{}return encodeURI(e)}function Xe(t,e){var s,i,n,o=e,r=t.posMax;if(60===t.src.charCodeAt(e)){for(e++;e<r;){if(10===(s=t.src.charCodeAt(e)))return!1;if(62===s)return n=Je(je(t.src.slice(o+1,e))),!!t.parser.validateLink(n)&&(t.pos=e+1,t.linkContent=n,!0);92===s&&e+1<r?e+=2:e++}return!1}for(i=0;e<r&&!(32===(s=t.src.charCodeAt(e))||s<32||127===s);)if(92===s&&e+1<r)e+=2;else{if(40===s&&++i>1||41===s&&--i<0)break;e++}return!(o===e||(n=je(t.src.slice(o,e)),!t.parser.validateLink(n)))&&(t.linkContent=n,t.pos=e,!0)}function Qe(t,e){var s,i=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((s=t.src.charCodeAt(e))===o)return t.pos=e+1,t.linkContent=je(t.src.slice(i+1,e)),!0;92===s&&e+1<n?e+=2:e++}return!1}function Ye(t){return t.trim().replace(/\s+/g," ").toUpperCase()}function ts(t,e,s,i){var n,o,r,a,l,c,h,u,d;if(91!==t.charCodeAt(0)||-1===t.indexOf("]:")||((o=Ze(n=new Ge(t,e,s,i,[]),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(!Xe(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&&Qe(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=Ye(t.slice(1,o)),typeof i.references[d]>"u"&&(i.references[d]={title:u,href:h}),r)}Ve.prototype.renderInline=function(t,e,s){for(var i=this.rules,n=t.length,o=0,r="";n--;)r+=i[t[o].type](t,o++,e,s,this);return r},Ve.prototype.render=function(t,e,s){for(var i=this.rules,n=t.length,o=-1,r="";++o<n;)"inline"===t[o].type?r+=this.renderInline(t[o].children,e,s):r+=i[t[o].type](t,o,e,s,this);return r},We.prototype.o=function(t){for(var e=this.t.length,s=-1;e--;)if(this.t[++s].name===t)return s;return-1},We.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(s){s.enabled&&(e&&s.alt.indexOf(e)<0||t.i[e].push(s.fn))})})},We.prototype.at=function(t,e,s){var i=this.o(t),n=s||{};if(-1===i)throw new Error("Parser rule not found: "+t);this.t[i].fn=e,this.t[i].alt=n.alt||[],this.i=null},We.prototype.before=function(t,e,s,i){var n=this.o(t),o=i||{};if(-1===n)throw new Error("Parser rule not found: "+t);this.t.splice(n,0,{name:e,enabled:!0,fn:s,alt:o.alt||[]}),this.i=null},We.prototype.after=function(t,e,s,i){var n=this.o(t),o=i||{};if(-1===n)throw new Error("Parser rule not found: "+t);this.t.splice(n+1,0,{name:e,enabled:!0,fn:s,alt:o.alt||[]}),this.i=null},We.prototype.push=function(t,e,s){var i=s||{};this.t.push({name:t,enabled:!0,fn:e,alt:i.alt||[]}),this.i=null},We.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},We.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},We.prototype.getRules=function(t){return null===this.i&&this.l(),this.i[t]||[]},Ge.prototype.pushPending=function(){this.tokens.push({type:"text",content:this.pending,level:this.pendingLevel}),this.pending=""},Ge.prototype.push=function(t){this.pending&&this.pushPending(),this.tokens.push(t),this.pendingLevel=this.level},Ge.prototype.cacheSet=function(t,e){for(var s=this.cache.length;s<=t;s++)this.cache.push(0);this.cache[t]=e},Ge.prototype.cacheGet=function(t){return t<this.cache.length?this.cache[t]:0};var es=" \n()[]'\".,!?-";function ss(t){return t.replace(/([-()\[\]{}+?*.$\^|,:#<!\\])/g,"\\$1")}var is=/\+-|\.\.|\?\?\?\?|!!!!|,,|--/,ns=/\((c|tm|r|p)\)/gi,os={c:"©",r:"®",p:"§",tm:"™"};function rs(t){return t.indexOf("(")<0?t:t.replace(ns,function(t,e){return os[e.toLowerCase()]})}var as=/['"]/,ls=/['"]/g,cs=/[-\s()\[\]]/;function hs(t,e){return!(e<0||e>=t.length)&&!cs.test(t[e])}function us(t,e,s){return t.substr(0,e)+s+t.substr(e+1)}var ds=[["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,s,i,n,o=t.tokens;if(!t.inlineMode)for(e=1,s=o.length-1;e<s;e++)if("paragraph_open"===o[e-1].type&&"inline"===o[e].type&&"paragraph_close"===o[e+1].type){for(i=o[e].content;i.length&&!((n=Ke(i,t.inline,t.options,t.env))<0);)i=i.slice(n).trim();o[e].content=i,i.length||(o[e-1].tight=!0,o[e+1].tight=!0)}}],["references",function(t){var e,s,i,n,o=t.tokens;if(t.env.references=t.env.references||{},!t.inlineMode)for(e=1,s=o.length-1;e<s;e++)if("inline"===o[e].type&&"paragraph_open"===o[e-1].type&&"paragraph_close"===o[e+1].type){for(i=o[e].content;i.length&&!((n=ts(i,t.inline,t.options,t.env))<0);)i=i.slice(n).trim();o[e].content=i,i.length||(o[e-1].tight=!0,o[e+1].tight=!0)}}],["inline",function(t){var e,s,i,n=t.tokens;for(s=0,i=n.length;s<i;s++)"inline"===(e=n[s]).type&&t.inline.parse(e.content,t.options,t.env,e.children)}],["footnote_tail",function(t){var e,s,i,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,s=r.length;e<s;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,i=0;i<n;i++)t.tokens.push({type:"footnote_anchor",id:e,subId:i,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,s,i,n,o,r,a,l,c,h,u,d,p=t.tokens;if(t.env.abbreviations)for(t.env.abbrRegExp||(d="(^|["+es.split("").map(ss).join("")+"])("+Object.keys(t.env.abbreviations).map(function(t){return t.substr(1)}).sort(function(t,e){return e.length-t.length}).map(ss).join("|")+")($|["+es.split("").map(ss).join("")+"])",t.env.abbrRegExp=new RegExp(d,"g")),h=t.env.abbrRegExp,s=0,i=p.length;s<i;s++)if("inline"===p[s].type)for(e=(n=p[s].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[s].children=n=[].concat(n.slice(0,e),a,n.slice(e+1)))}}],["replacements",function(t){var e,s,i,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"===(s=n[e]).type&&(i=rs(i=s.content),is.test(i)&&(i=i.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")),s.content=i)}],["smartquotes",function(t){var e,s,i,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"===(s=f[e]).type&&!as.test(s.text)){for(a=f[e].level,p=g.length-1;p>=0&&!(g[p].level<=a);p--);g.length=p+1,o=0,r=(i=s.content).length;t:for(;o<r&&(ls.lastIndex=o,n=ls.exec(i),n);)if(l=!hs(i,n.index-1),o=n.index+1,m="'"===n[0],(c=!hs(i,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=us(f[h.token].content,h.pos,t.options.quotes[2]),s.content=us(s.content,n.index,t.options.quotes[3])):(f[h.token].content=us(f[h.token].content,h.pos,t.options.quotes[0]),s.content=us(s.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&&(s.content=us(s.content,n.index,"’"))}else m&&(s.content=us(s.content,n.index,"’"))}}]];function ps(){this.options={},this.ruler=new We;for(var t=0;t<ds.length;t++)this.ruler.push(ds[t][0],ds[t][1])}function ms(t,e,s,i,n){var o,r,a,l,c,h,u;for(this.src=t,this.parser=e,this.options=s,this.env=i,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 vs(t,e){var s,i,n;return(i=t.bMarks[e]+t.tShift[e])>=(n=t.eMarks[e])||42!==(s=t.src.charCodeAt(i++))&&45!==s&&43!==s||i<n&&32!==t.src.charCodeAt(i)?-1:i}function fs(t,e){var s,i=t.bMarks[e]+t.tShift[e],n=t.eMarks[e];if(i+1>=n||((s=t.src.charCodeAt(i++))<48||s>57))return-1;for(;;){if(i>=n)return-1;if(!((s=t.src.charCodeAt(i++))>=48&&s<=57)){if(41===s||46===s)break;return-1}}return i<n&&32!==t.src.charCodeAt(i)?-1:i}ps.prototype.process=function(t){var e,s,i;for(e=0,s=(i=this.ruler.getRules("")).length;e<s;e++)i[e](t)},ms.prototype.isEmpty=function(t){return this.bMarks[t]+this.tShift[t]>=this.eMarks[t]},ms.prototype.skipEmptyLines=function(t){for(var e=this.lineMax;t<e&&!(this.bMarks[t]+this.tShift[t]<this.eMarks[t]);t++);return t},ms.prototype.skipSpaces=function(t){for(var e=this.src.length;t<e&&32===this.src.charCodeAt(t);t++);return t},ms.prototype.skipChars=function(t,e){for(var s=this.src.length;t<s&&this.src.charCodeAt(t)===e;t++);return t},ms.prototype.skipCharsBack=function(t,e,s){if(t<=s)return t;for(;t>s;)if(e!==this.src.charCodeAt(--t))return t+1;return t},ms.prototype.getLines=function(t,e,s,i){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],s),r=i?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])>s&&(l=s),l<0&&(l=0),o=this.bMarks[c]+l,r=c+1<e||i?this.eMarks[c]+1:this.eMarks[c],a[n]=this.src.slice(o,r);return a.join("")};var gs={};["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){gs[t]=!0});var bs=/^<([a-zA-Z]{1,15})[\s\/>]/,ys=/^<\/([a-zA-Z]{1,15})[\s>]/;function ws(t,e){var s=t.bMarks[e]+t.blkIndent,i=t.eMarks[e];return t.src.substr(s,i-s)}function xs(t,e){var s,i,n=t.bMarks[e]+t.tShift[e],o=t.eMarks[e];return n>=o||126!==(i=t.src.charCodeAt(n++))&&58!==i||n===(s=t.skipSpaces(n))||s>=o?-1:s}var ks=[["code",function(t,e,s){var i,n;if(t.tShift[e]-t.blkIndent<4)return!1;for(n=i=e+1;i<s;)if(t.isEmpty(i))i++;else{if(!(t.tShift[i]-t.blkIndent>=4))break;n=++i}return t.line=i,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,s,i){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(i)return!0;for(a=e;!(++a>=s||(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,s,i){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(i)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<s&&!((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,s,!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,s,i){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)&&(i||(t.line=e+1,t.tokens.push({type:"hr",lines:[e,t.line],level:t.level})),!0)},["paragraph","blockquote","list"]],["list",function(t,e,s,i){var n,o,r,a,l,c,h,u,d,p,m,v,f,g,b,y,w,x,k,_,A,C=!0;if((u=fs(t,e))>=0)v=!0;else{if(!((u=vs(t,e))>=0))return!1;v=!1}if(t.level>=t.options.maxNesting)return!1;if(m=t.src.charCodeAt(u-1),i)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<s&&((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,s,!0),(!t.tight||b)&&(C=!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>=s||t.isEmpty(n)||t.tShift[n]<t.blkIndent));){for(A=!1,k=0,_=x.length;k<_;k++)if(x[k](t,n,s,!0)){A=!0;break}if(A)break;if(v){if((u=fs(t,n))<0)break}else if((u=vs(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,C&&function(t,e){var s,i,n=t.level+2;for(s=e+2,i=t.tokens.length-2;s<i;s++)t.tokens[s].level===n&&"paragraph_open"===t.tokens[s].type&&(t.tokens[s+2].tight=!0,t.tokens[s].tight=!0,s+=2)}(t,g),!0},["paragraph","blockquote"]],["footnote",function(t,e,s,i){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))&&(i||(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,s,!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,s,i){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)&&(i||(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,s){var i,n,o,r=e+1;return!(r>=s||t.tShift[r]<t.blkIndent||t.tShift[r]-t.blkIndent>3||(n=t.bMarks[r]+t.tShift[r],o=t.eMarks[r],n>=o)||(i=t.src.charCodeAt(n),45!==i&&61!==i)||(n=t.skipChars(n,i),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===i?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",hLevel:61===i?1:2,level:t.level}),!0)}],["htmlblock",function(t,e,s,i){var n,o,r,a=t.bMarks[e],l=t.eMarks[e],c=t.tShift[e];if(a+=c,!t.options.html||c>3||a+2>=l||60!==t.src.charCodeAt(a))return!1;if(33===(n=t.src.charCodeAt(a+1))||63===n){if(i)return!0}else{if(47!==n&&!function(t){var e=32|t;return e>=97&&e<=122}(n))return!1;if(47===n){if(!(o=t.src.slice(a,l).match(ys)))return!1}else if(!(o=t.src.slice(a,l).match(bs)))return!1;if(!0!==gs[o[1].toLowerCase()])return!1;if(i)return