@isartech/chat
Version:
A reusable native webcomponent that can be initiated with parameters such as an endpoint url and styles in any environment based on web technologies.
37 lines • 889 kB
JavaScript
"use strict";var hT=Object.defineProperty;var fT=(r,e,t)=>e in r?hT(r,e,{enumerable:!0,configurable:!0,writable:!0,value:t}):r[e]=t;var _=(r,e,t)=>fT(r,typeof e!="symbol"?e+"":e,t);Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});class pT{static render(e,t){const n=document.createElement("div");n.id="error-view",n.innerText=t,e.replaceChildren(n)}}class uc{static onLoad(e){e.innerHTML='<div id="loading-validate-key-property"></div>'}static createElements(){const e=document.createElement("div");return e.id="validate-property-key-view",e}static render(e,t,n){const i=uc.createElements(),s={onSuccess:t,onFail:pT.render.bind(this,e,"Your 'key' has failed authentication"),onLoad:uc.onLoad.bind(this,i)};n.key&&n.verifyKey(n.key,s),e.replaceChildren(i)}}class Se{static unsetStyle(e,t){const n=Object.keys(t).reduce((i,s)=>(i[s]="",i),{});Object.assign(e.style,n)}static unsetActivityCSSMouseStates(e,t){t.click&&Se.unsetStyle(e,t.click),t.hover&&Se.unsetStyle(e,t.hover)}static unsetAllCSSMouseStates(e,t){Se.unsetActivityCSSMouseStates(e,t),t.default&&Se.unsetStyle(e,t.default)}static processStateful(e,t,n){const i=e.default||{},s=Object.assign(JSON.parse(JSON.stringify({...i,...t})),e==null?void 0:e.hover),o=Object.assign(JSON.parse(JSON.stringify({...s,...n})),e==null?void 0:e.click);return{default:i,hover:s,click:o}}static mergeStatefulStyles(e){const t={default:{},hover:{},click:{}};return e.forEach(n=>{t.default=Object.assign(t.default,n.default),t.hover=Object.assign(t.hover,n.hover),t.click=Object.assign(t.click,n.click)}),t}static overwriteDefaultWithAlreadyApplied(e,t){Object.keys(e.default||[]).forEach(n=>{var s;const i=n;t.style[i]&&(s=e.default)!=null&&s[i]&&(e.default[n]=t.style[i])})}static applyToStyleIfNotDefined(e,t){for(const n in t){const i=t[n];e[n]===""&&i&&(e[n]=i)}}}const tn=class tn{static attemptAppendStyleSheetToHead(e){if(e.fontFamily&&e.fontFamily!==tn.DEFAULT_FONT_FAMILY)return;const t=document.getElementsByTagName("head")[0];if(!Array.from(t.getElementsByTagName("link")).some(i=>i.getAttribute("href")===tn.FONT_URL)){const i=document.createElement("link");i.rel="stylesheet",i.href=tn.FONT_URL,t.appendChild(i)}}};tn.FONT_URL="https://fonts.googleapis.com/css2?family=Inter:wght@400;600&display=swap",tn.DEFAULT_FONT_FAMILY="'Inter', sans-serif, Avenir, Helvetica, Arial";let lc=tn;const Bn=class Bn{static apply(e,t){if(t)try{Bn.applyStyleSheet(e,t)}catch{Bn.addStyleElement(e,t)}}static applyStyleSheet(e,t){const n=new CSSStyleSheet;n.replaceSync(e),t.adoptedStyleSheets.push(n)}static addStyleElement(e,t){const n=document.createElement("style");n.innerHTML=e,t.appendChild(n)}static applyDefaultStyleToComponent(e,t){t&&Se.applyToStyleIfNotDefined(e,t),Se.applyToStyleIfNotDefined(e,Bn.DEFAULT_COMPONENT_STYLE)}};Bn.DEFAULT_COMPONENT_STYLE={height:"350px",width:"320px",border:"1px solid #cacaca",fontFamily:lc.DEFAULT_FONT_FAMILY,fontSize:"0.9rem",backgroundColor:"white",position:"relative",overflow:"hidden"};let Do=Bn;var zt=(r=>(r.ESCAPE="Escape",r.ENTER="Enter",r.TAB="Tab",r.ARROW_UP="ArrowUp",r.ARROW_DOWN="ArrowDown",r.ARROW_RIGHT="ArrowRight",r.ARROW_LEFT="ArrowLeft",r.BACKSPACE="Backspace",r.DELETE="Delete",r.META="Meta",r.CONTROL="Control",r))(zt||{});const Wo=class Wo{};Wo.IS_SAFARI=/^((?!chrome|android).)*safari/i.test(navigator.userAgent),Wo.IS_CHROMIUM=window.chrome,Wo.IS_MOBILE=/Android|webOS|iPhone|iPad|iPod|BlackBerry|IEMobile|Opera Mini/i.test(navigator.userAgent);let gn=Wo;class mT{static sanitizePastedTextContent(e){var n,i;e.preventDefault();const t=(n=e.clipboardData)==null?void 0:n.getData("text/plain");t&&((i=document.execCommand)==null||i.call(document,"insertText",!1,t))}}const rn=class rn{constructor(e,t,n){var s,o;const i=rn.processConfig(t,e.textInput);this.elementRef=rn.createContainerElement((s=i==null?void 0:i.styles)==null?void 0:s.container),this._config=i,this.inputElementRef=this.createInputElement(),this.elementRef.appendChild(this.inputElementRef),e.setPlaceholderText=this.setPlaceholderText.bind(this),e.setPlaceholderText(((o=this._config.placeholder)==null?void 0:o.text)||"Ask me anything!")}static processConfig(e,t){var n;return t??(t={}),t.disabled??(t.disabled=e.isTextInputDisabled),t.placeholder??(t.placeholder={}),(n=t.placeholder).text??(n.text=e.textInputPlaceholderText),t}static createContainerElement(e){const t=document.createElement("div");return t.id="text-input-container",Object.assign(t.style,e),t}static preventAutomaticScrollUpOnNewLine(e){let t;e.addEventListener("keydown",()=>{t=window.scrollY}),e.addEventListener("input",()=>{t!==window.scrollY&&window.scrollTo({top:t})})}createHiddenInput(){const e=document.createElement("input");return e.id="hidden-text-input",e.style.display="none",e.style.width="0",e.style.height="0",e}clear(){var e;this.inputElementRef.classList.contains("text-input-disabled")||(Object.assign(this.inputElementRef.style,(e=this._config.placeholder)==null?void 0:e.style),this.inputElementRef.textContent="")}createInputElement(){var t,n,i,s;const e=document.createElement("div");return e.id=rn.TEXT_INPUT_ID,e.classList.add("text-input-styling"),e.inputMode="text",e.setAttribute("role","textbox"),e.setAttribute("aria-multiline","true"),e.setAttribute("aria-label","Message input"),e.setAttribute("tabindex","0"),gn.IS_CHROMIUM&&rn.preventAutomaticScrollUpOnNewLine(e),typeof this._config.disabled=="boolean"&&this._config.disabled===!0?(e.contentEditable="false",e.classList.add("text-input-disabled"),e.setAttribute("aria-disabled","true")):(e.contentEditable="true",e.setAttribute("aria-disabled","false"),this.addEventListeners(e)),Object.assign(e.style,(t=this._config.styles)==null?void 0:t.text),Object.assign(e.style,(n=this._config.placeholder)==null?void 0:n.style),(s=(i=this._config.placeholder)==null?void 0:i.style)!=null&&s.color||e.setAttribute("textcolor",""),e}removePlaceholderStyle(){var e,t,n,i;!this.inputElementRef.classList.contains("text-input-disabled")&&((e=this._config.placeholder)!=null&&e.style)&&(Se.unsetStyle(this.inputElementRef,(t=this._config.placeholder)==null?void 0:t.style),Object.assign(this.inputElementRef.style,(i=(n=this._config)==null?void 0:n.styles)==null?void 0:i.text))}addEventListeners(e){var t,n;(t=this._config.styles)!=null&&t.focus&&(e.onfocus=()=>{var i;Object.assign(this.elementRef.style,(i=this._config.styles)==null?void 0:i.focus)},e.onblur=this.onBlur.bind(this,this._config.styles.focus,(n=this._config.styles)==null?void 0:n.container)),e.addEventListener("keydown",this.onKeydown.bind(this)),e.addEventListener("input",this.onInput.bind(this)),e.addEventListener("paste",mT.sanitizePastedTextContent)}onBlur(e,t){Se.unsetStyle(this.elementRef,e),t&&Object.assign(this.elementRef.style,t)}blur(){this.inputElementRef.blur()}onKeydown(e){var t;e.key===zt.ENTER&&!e.ctrlKey&&!e.shiftKey&&!gn.IS_MOBILE&&(e.preventDefault(),(t=this.submit)==null||t.call(this),this.inputElementRef.blur())}onInput(){var e;this.isTextInputEmpty()?Object.assign(this.inputElementRef.style,(e=this._config.placeholder)==null?void 0:e.style):this.removePlaceholderStyle()}setPlaceholderText(e){}isTextInputEmpty(){return this.inputElementRef.textContent===""}};rn.TEXT_INPUT_ID="text-input";let dc=rn;class ud{static focusEndOfInput(e){const t=document.createRange();t.selectNodeContents(e),t.collapse(!1);const n=window.getSelection();n==null||n.removeAllRanges(),n==null||n.addRange(t)}static focusFromParentElement(e){const t=e.querySelector(`#${dc.TEXT_INPUT_ID}`);t&&ud.focusEndOfInput(t)}}function U0(r){return r.charAt(0).toUpperCase()+r.slice(1)}function _T(r){return r&&JSON.stringify(r)}function ld(r,e,t,n){const i=`
${U0(e)} message: ${JSON.stringify(r)}
`,s=t?`${U0(e)} message after interceptor: ${_T(n)}
`:"";return i+s}function gT(r,e,t,n){return`${ld(r,e,t,n)}Make sure the ${e} message is using the Response format: https://deepchat.dev/docs/connect/#Response
You can also augment it using the responseInterceptor property: https://deepchat.dev/docs/interceptors#responseInterceptor`}function ET(r,e,t){const n="response";return`${ld(r,n,e,t)}Make sure the ${n} message is using the {text: string} format, e.g: {text: "Model Response"}`}function ST(r,e){const t="request";return`${ld(r,t,e)}Make sure the ${t} message is using the {body: {text: string}} format, e.g: {body: {text: "Model Response"}}`}const B0=`Make sure the events are using {text: string} or {html: string} format.
You can also augment them using the responseInterceptor property: https://deepchat.dev/docs/interceptors#responseInterceptor`,Ee={INVALID_KEY:"Invalid API Key",CONNECTION_FAILED:"Failed to connect",INVALID_RESPONSE:gT,INVALID_MODEL_REQUEST:ST,INVALID_MODEL_RESPONSE:ET,INVALID_STREAM_EVENT:B0,INVALID_STREAM_EVENT_MIX:"Cannot mix {text: string} and {html: string} responses.",NO_VALID_STREAM_EVENTS_SENT:`No valid stream events were sent.
${B0}`},Yc=class Yc{static addElements(e,...t){t.forEach(n=>e.appendChild(n))}static isScrollbarAtBottomOfElement(e){const t=e.scrollHeight,n=e.clientHeight,i=e.scrollTop,s=t-n;return i>=s-Yc.CODE_SNIPPET_GENERATION_JUMP}static cloneElement(e){const t=e.cloneNode(!0);return e.parentNode.replaceChild(t,e),t}static scrollToBottom(e){e.scrollTop=e.scrollHeight}static scrollToTop(e){e.scrollTop=0}static scrollToElement(e,t){e.scrollTop=t.offsetTop}};Yc.CODE_SNIPPET_GENERATION_JUMP=.5;let He=Yc;const Kc=class Kc{static speak(e,t){if(window.SpeechSynthesisUtterance){const n=new SpeechSynthesisUtterance(e);Object.assign(n,t),speechSynthesis.speak(n)}}static processConfig(e,t){const n={};setTimeout(()=>{if(typeof e=="object"&&(e.lang&&(n.lang=e.lang),e.pitch&&(n.pitch=e.pitch),e.rate&&(n.rate=e.rate),e.volume&&(n.volume=e.volume),e.voiceName)){const i=window.speechSynthesis.getVoices().find(s=>{var o;return s.name.toLocaleLowerCase()===((o=e.voiceName)==null?void 0:o.toLocaleLowerCase())});i&&(n.voice=i)}t(n)},Kc.LOAD_VOICES_MS)}};Kc.LOAD_VOICES_MS=200;let Gn=Kc;class at{static checkForContainerStyles(e,t){const n=e.containerStyle;n&&(Object.assign(t.style,n),console.error("The containerStyle property is deprecated since version 1.3.14."),console.error("Please change to using the style property instead: https://deepchat.dev/docs/styles#style"))}static handleResponseProperty(e){return console.error("The {result: ....} response object type is deprecated since version 1.3.0."),console.error("Please change to using the new response object: https://deepchat.dev/docs/connect#Response"),e.result}static processHistory(e){const t=e.initialMessages;if(t)return console.error("The initialMessages property is deprecated since version 2.0.0."),console.error("Please change to using the history property instead: https://deepchat.dev/docs/messages/#history"),t}static processHistoryFile(e){const t=e.file;t&&(console.error("The file property in MessageContent is deprecated since version 1.3.17."),console.error("Please change to using the files array property: https://deepchat.dev/docs/messages/#MessageContent"),e.files=[t])}static processValidateInput(e){const t=e.validateMessageBeforeSending;if(t)return console.error("The validateMessageBeforeSending property is deprecated since version 1.3.24."),console.error("Please change to using validateInput: https://deepchat.dev/docs/interceptors#validateInput"),t}static processSubmitUserMessage(e){return console.error("The submitUserMessage(text: string) argument string type is deprecated since version 1.4.4."),console.error("Please change to using the new argument type: https://deepchat.dev/docs/methods#submitUserMessage"),{text:e}}static flagHTMLUpdateClass(e){var t;(t=e.children[0])!=null&&t.classList.contains("deep-chat-update-message")&&(console.error('The "deep-chat-update-message" html class is deprecated since version 1.4.4.'),console.error("Please change to using {..., overwrite: true} object: https://deepchat.dev/docs/connect#Response"))}static processConnect(e){const t=e;t.request&&(t.connect?Object.assign(t.connect,t.request):t.connect=t.request,console.error("The request property is deprecated since version 2.0.0."),console.error("Please see the connect object: https://deepchat.dev/docs/connect#connect-1"))}static checkForStream(e){const t=e.stream;if(t)return console.error("The stream property has been moved to the connect object in version 2.0.0."),console.error("Please see the connect object: https://deepchat.dev/docs/connect#connect-1"),t}static fireOnNewMessage(e,t){var i;const n=e;n.onNewMessage&&(console.error("The onNewMessage event has been deprecated since version 2.0.0."),console.error("Please see the onMessage event: https://deepchat.dev/docs/events#onMessage"),(i=n.onNewMessage)==null||i.call(n,t)),e.dispatchEvent(new CustomEvent("new-message",{detail:t}))}static processFileConfigConnect(e){const t=e;t.request&&(console.error("The request property in file configuration is deprecated since version 2.0.0."),console.error("Please use the connect property instead: https://deepchat.dev/docs/files"),t.connect||(t.connect=t.request))}}const Vn=class Vn{static colorToHex(e){const t=document.createElement("div");return t.style.color=e,document.body.appendChild(t),`#${window.getComputedStyle(t).color.match(/\d+/g).map(s=>parseInt(s).toString(16).padStart(2,"0")).join("")}`}static setDots(e,t){var n,i,s,o;if((o=(s=(i=(n=t==null?void 0:t.loading)==null?void 0:n.message)==null?void 0:i.styles)==null?void 0:s.bubble)!=null&&o.color){const a=Vn.colorToHex(t.loading.message.styles.bubble.color);e.style.setProperty("--loading-message-color",a),e.style.setProperty("--loading-message-color-fade",`${a}33`)}else e.style.setProperty("--loading-message-color","#848484"),e.style.setProperty("--loading-message-color-fade","#55555533")}static setRing(e,t){const{color:n,width:i,height:s,margin:o,border:a}=t||{};if(n){const c=Vn.colorToHex(n);e.style.setProperty("--loading-history-color",c)}else e.style.setProperty("--loading-history-color","#dbdbdb");e.style.setProperty("--loading-history-height",s||"57px"),e.style.setProperty("--loading-history-width",i||"57px"),e.style.setProperty("--loading-history-margin",o||"7px"),e.style.setProperty("--loading-history-border",a||"6px")}};Vn.BUBBLE_CLASS="deep-chat-loading-message-bubble",Vn.DOTS_CONTAINER_CLASS="deep-chat-loading-message-dots-container";let Yt=Vn;const TT="data:image/svg+xml,%3c?xml%20version='1.0'%20encoding='iso-8859-1'?%3e%3csvg%20fill='%23000000'%20version='1.1'%20id='Layer_1'%20xmlns='http://www.w3.org/2000/svg'%20xmlns:xlink='http://www.w3.org/1999/xlink'%20viewBox='0%200%2032%2032'%20xml:space='preserve'%3e%3cpath%20d='M23,30.36H9c-2.404,0-4.36-1.956-4.36-4.36V15c0-2.404,1.956-4.36,4.36-4.36h3.659%20c0.167-1.566,1.415-2.813,2.981-2.981V5.333c-1.131-0.174-2-1.154-2-2.333c0-1.301,1.059-2.36,2.36-2.36%20c1.302,0,2.36,1.059,2.36,2.36c0,1.179-0.869,2.159-2,2.333V7.66c1.566,0.167,2.814,1.415,2.981,2.981H23%20c2.404,0,4.36,1.956,4.36,4.36v11C27.36,28.404,25.404,30.36,23,30.36z%20M9,11.36c-2.007,0-3.64,1.633-3.64,3.64v11%20c0,2.007,1.633,3.64,3.64,3.64h14c2.007,0,3.64-1.633,3.64-3.64V15c0-2.007-1.633-3.64-3.64-3.64H9z%20M13.384,10.64h5.231%20C18.439,9.354,17.334,8.36,16,8.36C14.667,8.36,13.561,9.354,13.384,10.64z%20M16,1.36c-0.904,0-1.64,0.736-1.64,1.64%20S15.096,4.64,16,4.64c0.904,0,1.64-0.736,1.64-1.64S16.904,1.36,16,1.36z%20M20,27.36h-8c-1.301,0-2.36-1.059-2.36-2.36%20s1.059-2.36,2.36-2.36h8c1.302,0,2.36,1.059,2.36,2.36S21.302,27.36,20,27.36z%20M12,23.36c-0.904,0-1.64,0.735-1.64,1.64%20s0.736,1.64,1.64,1.64h8c0.904,0,1.64-0.735,1.64-1.64s-0.735-1.64-1.64-1.64H12z%20M31,23.86h-2c-0.199,0-0.36-0.161-0.36-0.36V15%20c0-0.199,0.161-0.36,0.36-0.36h2c0.199,0,0.36,0.161,0.36,0.36v8.5C31.36,23.699,31.199,23.86,31,23.86z%20M29.36,23.14h1.279v-7.78%20H29.36V23.14z%20M3,23.86H1c-0.199,0-0.36-0.161-0.36-0.36V15c0-0.199,0.161-0.36,0.36-0.36h2c0.199,0,0.36,0.161,0.36,0.36v8.5%20C3.36,23.699,3.199,23.86,3,23.86z%20M1.36,23.14h1.28v-7.78H1.36V23.14z%20M20,20.36c-1.302,0-2.36-1.059-2.36-2.36%20s1.059-2.36,2.36-2.36s2.36,1.059,2.36,2.36C22.36,19.302,21.302,20.36,20,20.36z%20M20,16.36c-0.904,0-1.64,0.736-1.64,1.64%20s0.735,1.64,1.64,1.64s1.64-0.735,1.64-1.64S20.904,16.36,20,16.36z%20M12,20.36c-1.301,0-2.36-1.059-2.36-2.36s1.059-2.36,2.36-2.36%20s2.36,1.059,2.36,2.36C14.36,19.302,13.301,20.36,12,20.36z%20M12,16.36c-0.904,0-1.64,0.736-1.64,1.64s0.736,1.64,1.64,1.64%20s1.64-0.735,1.64-1.64S12.904,16.36,12,16.36z'/%3e%3crect%20style='fill:none;'%20width='32'%20height='32'/%3e%3c/svg%3e",AT="data:image/png;base64,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",Xe=class Xe{static hide(e){var t;(t=e.getElementsByClassName(Xe.CONTAINER_CLASS)[0].style).visibility||(t.visibility="hidden")}static reveal(e){e.getElementsByClassName(Xe.CONTAINER_CLASS)[0].style.visibility=""}static applyCustomStylesToElements(e,t,n){Object.assign(e.style,n.container),Object.assign(t.style,n.avatar)}static applyCustomStyles(e,t,n,i){var s,o,a,c;if((s=n.default)!=null&&s.styles&&Xe.applyCustomStylesToElements(e,t,n.default.styles),i===F.USER_ROLE)(o=n.user)!=null&&o.styles&&Xe.applyCustomStylesToElements(e,t,n.user.styles);else{(a=n.ai)!=null&&a.styles&&Xe.applyCustomStylesToElements(e,t,n.ai.styles);const u=(c=n[i])==null?void 0:c.styles;u&&Xe.applyCustomStylesToElements(e,t,u)}}static createAvatar(e,t){var s,o,a,c,u;const n=document.createElement("img");e===F.USER_ROLE?n.src=((s=t==null?void 0:t.user)==null?void 0:s.src)||((o=t==null?void 0:t.default)==null?void 0:o.src)||AT:n.src=((a=t==null?void 0:t[e])==null?void 0:a.src)||((c=t==null?void 0:t.ai)==null?void 0:c.src)||((u=t==null?void 0:t.default)==null?void 0:u.src)||TT,n.classList.add("avatar");const i=document.createElement("div");return i.classList.add(Xe.CONTAINER_CLASS),i.appendChild(n),t&&Xe.applyCustomStyles(i,n,t,e),i}static getPosition(e,t){var i,s,o,a,c,u;let n=(s=(i=t==null?void 0:t[e])==null?void 0:i.styles)==null?void 0:s.position;return e!==F.USER_ROLE&&(n??(n=(a=(o=t==null?void 0:t.ai)==null?void 0:o.styles)==null?void 0:a.position)),n??(n=(u=(c=t==null?void 0:t.default)==null?void 0:c.styles)==null?void 0:u.position),n??(n=e===F.USER_ROLE?"right":"left"),n}static add(e,t,n){const i=typeof n=="boolean"?void 0:n,s=Xe.createAvatar(t,i),o=Xe.getPosition(t,i);s.classList.add(o==="left"?"left-item-position":"right-item-position"),e.insertAdjacentElement(o==="left"?"beforebegin":"afterend",s)}};Xe.CONTAINER_CLASS="avatar-container";let ko=Xe;const vt=class vt{static hide(e){var t;(t=e.getElementsByClassName(vt.NAME_CLASS)[0].style).visibility||(t.visibility="hidden")}static reveal(e){e.getElementsByClassName(vt.NAME_CLASS)[0].style.visibility=""}static getPosition(e,t){var i,s,o;let n=(i=t==null?void 0:t[e])==null?void 0:i.position;return e!==F.USER_ROLE&&(n??(n=(s=t==null?void 0:t.ai)==null?void 0:s.position)),n??(n=(o=t==null?void 0:t.default)==null?void 0:o.position),n??(n=e===F.USER_ROLE?"right":"left"),n}static applyStyle(e,t,n){var i,s,o,a;Object.assign(e.style,(i=n.default)==null?void 0:i.style),t===F.USER_ROLE?Object.assign(e.style,(s=n.user)==null?void 0:s.style):(Object.assign(e.style,(o=n.ai)==null?void 0:o.style),Object.assign(e.style,(a=n[t])==null?void 0:a.style))}static getNameText(e,t){var n,i,s,o,a,c;return e===F.USER_ROLE?((n=t.user)==null?void 0:n.text)||((i=t.default)==null?void 0:i.text)||"User":e===F.AI_ROLE?((s=t.ai)==null?void 0:s.text)||((o=t.default)==null?void 0:o.text)||"AI":((a=t[e])==null?void 0:a.text)||((c=t.default)==null?void 0:c.text)||e}static createName(e,t){const n=document.createElement("div");return n.classList.add(vt.NAME_CLASS),n.textContent=vt.getNameText(e,t),vt.applyStyle(n,e,t),n}static add(e,t,n){const i=typeof n=="boolean"?{}:n,s=vt.createName(t,i),o=vt.getPosition(t,i);s.classList.add(o==="left"?"left-item-position":"right-item-position"),e.insertAdjacentElement(o==="left"?"beforebegin":"afterend",s)}};vt.NAME_CLASS="name";let Uo=vt;const pt=class pt{static getLastElementsByClass(e,t,n){for(let i=e.length-1;i>=0;i-=1){const s=e[i];if(s.bubbleElement.classList.contains(t[0])&&!t.slice(1).find(a=>!s.bubbleElement.classList.contains(a)))if(n){if(!n.find(c=>s.bubbleElement.classList.contains(c)))return s}else return s}}static getLastMessage(e,t,n){for(let i=e.length-1;i>=0;i-=1)if(e[i].role===t)if(n){if(e[i][n])return e[i]}else return e[i]}static getLastTextToElement(e,t){for(let n=e.length-1;n>=0;n-=1)if(e[n][0]===t)return e[n]}static overwriteMessage(e,t,n,i,s,o){const a=pt.getLastElementsByClass(t,[pt.getRoleClass(i),o],[Yt.BUBBLE_CLASS]),c=pt.getLastMessage(e,i,s);return c&&(c[s]=n),a}static getRoleClass(e){return`${e}-message`}static fillEmptyMessageElement(e,t){t.trim().length===0&&(e.classList.add(pt.EMPTY_MESSAGE_CLASS),e.innerHTML='<div style="color:#00000000">.</div>')}static unfillEmptyMessageElement(e,t){e.classList.contains(pt.EMPTY_MESSAGE_CLASS)&&t.trim().length>0&&e.replaceChildren()}static getLastMessageBubbleElement(e){var t,n,i;return Array.from(((i=(n=(t=pt.getLastMessageElement(e))==null?void 0:t.children)==null?void 0:n[0])==null?void 0:i.children)||[]).find(s=>s.classList.contains("message-bubble"))}static getLastMessageElement(e){return e.children[e.children.length-1]}static addRoleElements(e,t,n,i){n&&ko.add(e,t,n),i&&Uo.add(e,t,i)}static hideRoleElements(e,t,n){const i=e[e.length-1].innerContainer;t&&ko.hide(i),n&&Uo.hide(i)}static revealRoleElements(e,t,n){t&&ko.reveal(e),n&&Uo.reveal(e)}static updateRefArr(e,t,n){n?e.unshift(t):e.push(t)}};pt.AI_ROLE="ai",pt.USER_ROLE="user",pt.EMPTY_MESSAGE_CLASS="empty-message";let F=pt;class an{static mouseUp(e,t){Se.unsetAllCSSMouseStates(e,t),Object.assign(e.style,t.default),Object.assign(e.style,t.hover)}static mouseDown(e,t){Object.assign(e.style,t.click)}static mouseLeave(e,t){Se.unsetAllCSSMouseStates(e,t),Object.assign(e.style,t.default)}static mouseEnter(e,t){Object.assign(e.style,t.hover)}static add(e,t){e.addEventListener("mouseenter",an.mouseEnter.bind(this,e,t)),e.addEventListener("mouseleave",an.mouseLeave.bind(this,e,t)),e.addEventListener("mousedown",an.mouseDown.bind(this,e,t)),e.addEventListener("mouseup",an.mouseUp.bind(this,e,t))}}const bT="deep-chat-temporary-message",vT="deep-chat-suggestion-button",El={"deep-chat-button":{styles:{default:{backgroundColor:"white",padding:"5px",paddingLeft:"7px",paddingRight:"7px",border:"1px solid #c2c2c2",borderRadius:"6px",cursor:"pointer"},hover:{backgroundColor:"#fafafa"},click:{backgroundColor:"#f1f1f1"}}}},V0=Object.keys(El);class Kt{static applySuggestionEvent(e,t){setTimeout(()=>{t.addEventListener("click",()=>{var n,i;(i=e.submitUserMessage)==null||i.call(e,{text:((n=t.textContent)==null?void 0:n.trim())||""})})})}static isElementTemporary(e){var t;return e?(t=e.bubbleElement.children[0])==null?void 0:t.classList.contains(bT):!1}static doesElementContainDeepChatClass(e){return V0.find(t=>e.classList.contains(t))}static applyEvents(e,t){const n=El[t].events;Object.keys(n||[]).forEach(i=>{e.addEventListener(i,n==null?void 0:n[i])})}static getProcessedStyles(e,t,n){const i=Array.from(t.classList).reduce((a,c)=>{var l;const u=(l=e[c])==null?void 0:l.styles;return u&&e[c].styles&&a.push(u),a},[]),s=El[n].styles;if(s){const a=JSON.parse(JSON.stringify(s));a.default&&Se.overwriteDefaultWithAlreadyApplied(a,t),i.unshift(a)}const o=Se.mergeStatefulStyles(i);return Se.processStateful(o,{},{})}static applyDeepChatUtilities(e,t,n){V0.forEach(s=>{const o=n.getElementsByClassName(s);Array.from(o||[]).forEach(a=>{const c=Kt.getProcessedStyles(t,a,s);et.applyStylesToElement(a,c),Kt.applyEvents(a,s)})});const i=n.getElementsByClassName(vT);Array.from(i).forEach(s=>Kt.applySuggestionEvent(e,s))}}class et{static applyStylesToElement(e,t){const n=Se.processStateful(t,{},{});an.add(e,n),Object.assign(e.style,n.default)}static applyEventsToElement(e,t){Object.keys(t).forEach(n=>{const i=t[n];i&&e.addEventListener(n,i)})}static applyClassUtilitiesToElement(e,t){const{events:n,styles:i}=t;n&&et.applyEventsToElement(e,n),i&&!Kt.doesElementContainDeepChatClass(e)&&et.applyStylesToElement(e,i)}static applyCustomClassUtilities(e,t){Object.keys(e).forEach(n=>{const i=t.getElementsByClassName(n);Array.from(i).forEach(s=>{e[n]&&et.applyClassUtilitiesToElement(s,e[n])})})}static apply(e,t){Kt.applyDeepChatUtilities(e,e.htmlClassUtilities,t),et.applyCustomClassUtilities(e.htmlClassUtilities,t)}static traverseNodes(e,t){e.nodeType===Node.ELEMENT_NODE&&t.push(e.outerHTML),e.childNodes.forEach(n=>{et.traverseNodes(n,t)})}static splitHTML(e){const n=new DOMParser().parseFromString(e,"text/html"),i=[];return n.body.childNodes.forEach(s=>{et.traverseNodes(s,i)}),i}}class gr{static addElement(e,t){e.appendMessageBeforeSpacer(t),e.elementRef.scrollTop=e.elementRef.scrollHeight}static createElements(e,t,n,i){const s=e.createMessageElementsOnOrientation("",n,i);return s.bubbleElement.classList.add("html-message"),s.bubbleElement.innerHTML=t,s}static overwrite(e,t,n,i){const{messages:s}=e,o=F.overwriteMessage(s,i,t,n,"html","html-message");return o&&(o.bubbleElement.innerHTML=t,et.apply(e,o.outerContainer),at.flagHTMLUpdateClass(o.bubbleElement)),o}static add(e,t,n,i,s,o=!1){var c;if(s!=null&&s.status){const u=this.overwrite(e,t,n,i);if(u)return u;s.status=!1}const a=gr.createElements(e,t,n,o);return F.fillEmptyMessageElement(a.bubbleElement,t),et.apply(e,a.outerContainer),at.flagHTMLUpdateClass(a.bubbleElement),e.applyCustomStyles(a,n,!1,(c=e.messageStyles)==null?void 0:c.html),o||gr.addElement(e,a.outerContainer),a}}var Va;function Jg(r){return Va=Va||document.createElement("textarea"),Va.innerHTML="&"+r+";",Va.value}var yT=Object.prototype.hasOwnProperty;function RT(r,e){return r?yT.call(r,e):!1}function Zg(r){var e=[].slice.call(arguments,1);return e.forEach(function(t){if(t){if(typeof t!="object")throw new TypeError(t+"must be object");Object.keys(t).forEach(function(n){r[n]=t[n]})}}),r}var CT=/\\([\\!"#$%&'()*+,.\/:;<=>?@[\]^_`{|}~-])/g;function Zo(r){return r.indexOf("\\")<0?r:r.replace(CT,"$1")}function eE(r){return!(r>=55296&&r<=57343||r>=64976&&r<=65007||(r&65535)===65535||(r&65535)===65534||r>=0&&r<=8||r===11||r>=14&&r<=31||r>=127&&r<=159||r>1114111)}function Sl(r){if(r>65535){r-=65536;var e=55296+(r>>10),t=56320+(r&1023);return String.fromCharCode(e,t)}return String.fromCharCode(r)}var MT=/&([a-z#][a-z0-9]{1,31});/gi,OT=/^#((?:x[a-f0-9]{1,8}|[0-9]{1,8}))/i;function xT(r,e){var t=0,n=Jg(e);return e!==n?n:e.charCodeAt(0)===35&&OT.test(e)&&(t=e[1].toLowerCase()==="x"?parseInt(e.slice(2),16):parseInt(e.slice(1),10),eE(t))?Sl(t):r}function En(r){return r.indexOf("&")<0?r:r.replace(MT,xT)}var NT=/[&<>"]/,IT=/[&<>"]/g,LT={"&":"&","<":"<",">":">",'"':"""};function wT(r){return LT[r]}function Ye(r){return NT.test(r)?r.replace(IT,wT):r}var k={};k.blockquote_open=function(){return`<blockquote>
`};k.blockquote_close=function(r,e){return"</blockquote>"+Rn(r,e)};k.code=function(r,e){return r[e].block?"<pre><code>"+Ye(r[e].content)+"</code></pre>"+Rn(r,e):"<code>"+Ye(r[e].content)+"</code>"};k.fence=function(r,e,t,n,i){var s=r[e],o="",a=t.langPrefix,c="",u,l,d;if(s.params){if(u=s.params.split(/\s+/g),l=u.join(" "),RT(i.rules.fence_custom,u[0]))return i.rules.fence_custom[u[0]](r,e,t,n,i);c=Ye(En(Zo(l))),o=' class="'+a+c+'"'}return t.highlight?d=t.highlight.apply(t.highlight,[s.content].concat(u))||Ye(s.content):d=Ye(s.content),"<pre><code"+o+">"+d+"</code></pre>"+Rn(r,e)};k.fence_custom={};k.heading_open=function(r,e){return"<h"+r[e].hLevel+">"};k.heading_close=function(r,e){return"</h"+r[e].hLevel+`>
`};k.hr=function(r,e,t){return(t.xhtmlOut?"<hr />":"<hr>")+Rn(r,e)};k.bullet_list_open=function(){return`<ul>
`};k.bullet_list_close=function(r,e){return"</ul>"+Rn(r,e)};k.list_item_open=function(){return"<li>"};k.list_item_close=function(){return`</li>
`};k.ordered_list_open=function(r,e){var t=r[e],n=t.order>1?' start="'+t.order+'"':"";return"<ol"+n+`>
`};k.ordered_list_close=function(r,e){return"</ol>"+Rn(r,e)};k.paragraph_open=function(r,e){return r[e].tight?"":"<p>"};k.paragraph_close=function(r,e){var t=!(r[e].tight&&e&&r[e-1].type==="inline"&&!r[e-1].content);return(r[e].tight?"":"</p>")+(t?Rn(r,e):"")};k.link_open=function(r,e,t){var n=r[e].title?' title="'+Ye(En(r[e].title))+'"':"",i=t.linkTarget?' target="'+t.linkTarget+'"':"";return'<a href="'+Ye(r[e].href)+'"'+n+i+">"};k.link_close=function(){return"</a>"};k.image=function(r,e,t){var n=' src="'+Ye(r[e].src)+'"',i=r[e].title?' title="'+Ye(En(r[e].title))+'"':"",s=' alt="'+(r[e].alt?Ye(En(Zo(r[e].alt))):"")+'"',o=t.xhtmlOut?" /":"";return"<img"+n+s+i+o+">"};k.table_open=function(){return`<table>
`};k.table_close=function(){return`</table>
`};k.thead_open=function(){return`<thead>
`};k.thead_close=function(){return`</thead>
`};k.tbody_open=function(){return`<tbody>
`};k.tbody_close=function(){return`</tbody>
`};k.tr_open=function(){return"<tr>"};k.tr_close=function(){return`</tr>
`};k.th_open=function(r,e){var t=r[e];return"<th"+(t.align?' style="text-align:'+t.align+'"':"")+">"};k.th_close=function(){return"</th>"};k.td_open=function(r,e){var t=r[e];return"<td"+(t.align?' style="text-align:'+t.align+'"':"")+">"};k.td_close=function(){return"</td>"};k.strong_open=function(){return"<strong>"};k.strong_close=function(){return"</strong>"};k.em_open=function(){return"<em>"};k.em_close=function(){return"</em>"};k.del_open=function(){return"<del>"};k.del_close=function(){return"</del>"};k.ins_open=function(){return"<ins>"};k.ins_close=function(){return"</ins>"};k.mark_open=function(){return"<mark>"};k.mark_close=function(){return"</mark>"};k.sub=function(r,e){return"<sub>"+Ye(r[e].content)+"</sub>"};k.sup=function(r,e){return"<sup>"+Ye(r[e].content)+"</sup>"};k.hardbreak=function(r,e,t){return t.xhtmlOut?`<br />
`:`<br>
`};k.softbreak=function(r,e,t){return t.breaks?t.xhtmlOut?`<br />
`:`<br>
`:`
`};k.text=function(r,e){return Ye(r[e].content)};k.htmlblock=function(r,e){return r[e].content};k.htmltag=function(r,e){return r[e].content};k.abbr_open=function(r,e){return'<abbr title="'+Ye(En(r[e].title))+'">'};k.abbr_close=function(){return"</abbr>"};k.footnote_ref=function(r,e){var t=Number(r[e].id+1).toString(),n="fnref"+t;return r[e].subId>0&&(n+=":"+r[e].subId),'<sup class="footnote-ref"><a href="#fn'+t+'" id="'+n+'">['+t+"]</a></sup>"};k.footnote_block_open=function(r,e,t){var n=t.xhtmlOut?`<hr class="footnotes-sep" />
`:`<hr class="footnotes-sep">
`;return n+`<section class="footnotes">
<ol class="footnotes-list">
`};k.footnote_block_close=function(){return`</ol>
</section>
`};k.footnote_open=function(r,e){var t=Number(r[e].id+1).toString();return'<li id="fn'+t+'" class="footnote-item">'};k.footnote_close=function(){return`</li>
`};k.footnote_anchor=function(r,e){var t=Number(r[e].id+1).toString(),n="fnref"+t;return r[e].subId>0&&(n+=":"+r[e].subId),' <a href="#'+n+'" class="footnote-backref">↩</a>'};k.dl_open=function(){return`<dl>
`};k.dt_open=function(){return"<dt>"};k.dd_open=function(){return"<dd>"};k.dl_close=function(){return`</dl>
`};k.dt_close=function(){return`</dt>
`};k.dd_close=function(){return`</dd>
`};function tE(r,e){return++e>=r.length-2?e:r[e].type==="paragraph_open"&&r[e].tight&&r[e+1].type==="inline"&&r[e+1].content.length===0&&r[e+2].type==="paragraph_close"&&r[e+2].tight?tE(r,e+2):e}var Rn=k.getBreak=function(e,t){return t=tE(e,t),t<e.length&&e[t].type==="list_item_close"?"":`
`};function dd(){this.rules=Zg({},k),this.getBreak=k.getBreak}dd.prototype.renderInline=function(r,e,t){for(var n=this.rules,i=r.length,s=0,o="";i--;)o+=n[r[s].type](r,s++,e,t,this);return o};dd.prototype.render=function(r,e,t){for(var n=this.rules,i=r.length,s=-1,o="";++s<i;)r[s].type==="inline"?o+=this.renderInline(r[s].children,e,t):o+=n[r[s].type](r,s,e,t,this);return o};function rt(){this.__rules__=[],this.__cache__=null}rt.prototype.__find__=function(r){for(var e=this.__rules__.length,t=-1;e--;)if(this.__rules__[++t].name===r)return t;return-1};rt.prototype.__compile__=function(){var r=this,e=[""];r.__rules__.forEach(function(t){t.enabled&&t.alt.forEach(function(n){e.indexOf(n)<0&&e.push(n)})}),r.__cache__={},e.forEach(function(t){r.__cache__[t]=[],r.__rules__.forEach(function(n){n.enabled&&(t&&n.alt.indexOf(t)<0||r.__cache__[t].push(n.fn))})})};rt.prototype.at=function(r,e,t){var n=this.__find__(r),i=t||{};if(n===-1)throw new Error("Parser rule not found: "+r);this.__rules__[n].fn=e,this.__rules__[n].alt=i.alt||[],this.__cache__=null};rt.prototype.before=function(r,e,t,n){var i=this.__find__(r),s=n||{};if(i===-1)throw new Error("Parser rule not found: "+r);this.__rules__.splice(i,0,{name:e,enabled:!0,fn:t,alt:s.alt||[]}),this.__cache__=null};rt.prototype.after=function(r,e,t,n){var i=this.__find__(r),s=n||{};if(i===-1)throw new Error("Parser rule not found: "+r);this.__rules__.splice(i+1,0,{name:e,enabled:!0,fn:t,alt:s.alt||[]}),this.__cache__=null};rt.prototype.push=function(r,e,t){var n=t||{};this.__rules__.push({name:r,enabled:!0,fn:e,alt:n.alt||[]}),this.__cache__=null};rt.prototype.enable=function(r,e){r=Array.isArray(r)?r:[r],e&&this.__rules__.forEach(function(t){t.enabled=!1}),r.forEach(function(t){var n=this.__find__(t);if(n<0)throw new Error("Rules manager: invalid rule name "+t);this.__rules__[n].enabled=!0},this),this.__cache__=null};rt.prototype.disable=function(r){r=Array.isArray(r)?r:[r],r.forEach(function(e){var t=this.__find__(e);if(t<0)throw new Error("Rules manager: invalid rule name "+e);this.__rules__[t].enabled=!1},this),this.__cache__=null};rt.prototype.getRules=function(r){return this.__cache__===null&&this.__compile__(),this.__cache__[r]||[]};function PT(r){r.inlineMode?r.tokens.push({type:"inline",content:r.src.replace(/\n/g," ").trim(),level:0,lines:[0,1],children:[]}):r.block.parse(r.src,r.options,r.env,r.tokens)}function Cn(r,e,t,n,i){this.src=r,this.env=n,this.options=t,this.parser=e,this.tokens=i,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}Cn.prototype.pushPending=function(){this.tokens.push({type:"text",content:this.pending,level:this.pendingLevel}),this.pending=""};Cn.prototype.push=function(r){this.pending&&this.pushPending(),this.tokens.push(r),this.pendingLevel=this.level};Cn.prototype.cacheSet=function(r,e){for(var t=this.cache.length;t<=r;t++)this.cache.push(0);this.cache[r]=e};Cn.prototype.cacheGet=function(r){return r<this.cache.length?this.cache[r]:0};function ea(r,e){var t,n,i,s=-1,o=r.posMax,a=r.pos,c=r.isInLabel;if(r.isInLabel)return-1;if(r.labelUnmatchedScopes)return r.labelUnmatchedScopes--,-1;for(r.pos=e+1,r.isInLabel=!0,t=1;r.pos<o;){if(i=r.src.charCodeAt(r.pos),i===91)t++;else if(i===93&&(t--,t===0)){n=!0;break}r.parser.skipToken(r)}return n?(s=r.pos,r.labelUnmatchedScopes=0):r.labelUnmatchedScopes=t-1,r.pos=a,r.isInLabel=c,s}function DT(r,e,t,n){var i,s,o,a,c,u;if(r.charCodeAt(0)!==42||r.charCodeAt(1)!==91||r.indexOf("]:")===-1||(i=new Cn(r,e,t,n,[]),s=ea(i,1),s<0||r.charCodeAt(s+1)!==58))return-1;for(a=i.posMax,o=s+2;o<a&&i.src.charCodeAt(o)!==10;o++);return c=r.slice(2,s),u=r.slice(s+2,o).trim(),u.length===0?-1:(n.abbreviations||(n.abbreviations={}),typeof n.abbreviations[":"+c]>"u"&&(n.abbreviations[":"+c]=u),o)}function kT(r){var e=r.tokens,t,n,i,s;if(!r.inlineMode){for(t=1,n=e.length-1;t<n;t++)if(e[t-1].type==="paragraph_open"&&e[t].type==="inline"&&e[t+1].type==="paragraph_close"){for(i=e[t].content;i.length&&(s=DT(i,r.inline,r.options,r.env),!(s<0));)i=i.slice(s).trim();e[t].content=i,i.length||(e[t-1].tight=!0,e[t+1].tight=!0)}}}function Tl(r){var e=En(r);try{e=decodeURI(e)}catch{}return encodeURI(e)}function rE(r,e){var t,n,i,s=e,o=r.posMax;if(r.src.charCodeAt(e)===60){for(e++;e<o;){if(t=r.src.charCodeAt(e),t===10)return!1;if(t===62)return i=Tl(Zo(r.src.slice(s+1,e))),r.parser.validateLink(i)?(r.pos=e+1,r.linkContent=i,!0):!1;if(t===92&&e+1<o){e+=2;continue}e++}return!1}for(n=0;e<o&&(t=r.src.charCodeAt(e),!(t===32||t<32||t===127));){if(t===92&&e+1<o){e+=2;continue}if(t===40&&(n++,n>1)||t===41&&(n--,n<0))break;e++}return s===e||(i=Zo(r.src.slice(s,e)),!r.parser.validateLink(i))?!1:(r.linkContent=i,r.pos=e,!0)}function nE(r,e){var t,n=e,i=r.posMax,s=r.src.charCodeAt(e);if(s!==34&&s!==39&&s!==40)return!1;for(e++,s===40&&(s=41);e<i;){if(t=r.src.charCodeAt(e),t===s)return r.pos=e+1,r.linkContent=Zo(r.src.slice(n+1,e)),!0;if(t===92&&e+1<i){e+=2;continue}e++}return!1}function iE(r){return r.trim().replace(/\s+/g," ").toUpperCase()}function UT(r,e,t,n){var i,s,o,a,c,u,l,d,h;if(r.charCodeAt(0)!==91||r.indexOf("]:")===-1||(i=new Cn(r,e,t,n,[]),s=ea(i,0),s<0||r.charCodeAt(s+1)!==58))return-1;for(a=i.posMax,o=s+2;o<a&&(c=i.src.charCodeAt(o),!(c!==32&&c!==10));o++);if(!rE(i,o))return-1;for(l=i.linkContent,o=i.pos,u=o,o=o+1;o<a&&(c=i.src.charCodeAt(o),!(c!==32&&c!==10));o++);for(o<a&&u!==o&&nE(i,o)?(d=i.linkContent,o=i.pos):(d="",o=u);o<a&&i.src.charCodeAt(o)===32;)o++;return o<a&&i.src.charCodeAt(o)!==10?-1:(h=iE(r.slice(1,s)),typeof n.references[h]>"u"&&(n.references[h]={title:d,href:l}),o)}function BT(r){var e=r.tokens,t,n,i,s;if(r.env.references=r.env.references||{},!r.inlineMode){for(t=1,n=e.length-1;t<n;t++)if(e[t].type==="inline"&&e[t-1].type==="paragraph_open"&&e[t+1].type==="paragraph_close"){for(i=e[t].content;i.length&&(s=UT(i,r.inline,r.options,r.env),!(s<0));)i=i.slice(s).trim();e[t].content=i,i.length||(e[t-1].tight=!0,e[t+1].tight=!0)}}}function VT(r){var e=r.tokens,t,n,i;for(n=0,i=e.length;n<i;n++)t=e[n],t.type==="inline"&&r.inline.parse(t.content,r.options,r.env,t.children)}function FT(r){var e,t,n,i,s,o,a,c,u,l=0,d=!1,h={};if(r.env.footnotes&&(r.tokens=r.tokens.filter(function(p){return p.type==="footnote_reference_open"?(d=!0,c=[],u=p.label,!1):p.type==="footnote_reference_close"?(d=!1,h[":"+u]=c,!1):(d&&c.push(p),!d)}),!!r.env.footnotes.list)){for(o=r.env.footnotes.list,r.tokens.push({type:"footnote_block_open",level:l++}),e=0,t=o.length;e<t;e++){for(r.tokens.push({type:"footnote_open",id:e,level:l++}),o[e].tokens?(a=[],a.push({type:"paragraph_open",tight:!1,level:l++}),a.push({type:"inline",content:"",level:l,children:o[e].tokens}),a.push({type:"paragraph_close",tight:!1,level:--l})):o[e].label&&(a=h[":"+o[e].label]),r.tokens=r.tokens.concat(a),r.tokens[r.tokens.length-1].type==="paragraph_close"?s=r.tokens.pop():s=null,i=o[e].count>0?o[e].count:1,n=0;n<i;n++)r.tokens.push({type:"footnote_anchor",id:e,subId:n,level:l});s&&r.tokens.push(s),r.tokens.push({type:"footnote_close",level:--l})}r.tokens.push({type:"footnote_block_close",level:--l})}}var F0=`
()[]'".,!?-`;function Ru(r){return r.replace(/([-()\[\]{}+?*.$\^|,:#<!\\])/g,"\\$1")}function HT(r){var e,t,n,i,s,o,a,c,u,l,d,h,p=r.tokens;if(r.env.abbreviations){for(r.env.abbrRegExp||(h="(^|["+F0.split("").map(Ru).join("")+"])("+Object.keys(r.env.abbreviations).map(function(m){return m.substr(1)}).sort(function(m,E){return E.length-m.length}).map(Ru).join("|")+")($|["+F0.split("").map(Ru).join("")+"])",r.env.abbrRegExp=new RegExp(h,"g")),l=r.env.abbrRegExp,t=0,n=p.length;t<n;t++)if(p[t].type==="inline"){for(i=p[t].children,e=i.length-1;e>=0;e--)if(s=i[e],s.type==="text"){for(c=0,o=s.content,l.lastIndex=0,u=s.level,a=[];d=l.exec(o);)l.lastIndex>c&&a.push({type:"text",content:o.slice(c,d.index+d[1].length),level:u}),a.push({type:"abbr_open",title:r.env.abbreviations[":"+d[2]],level:u++}),a.push({type:"text",content:d[2],level:u}),a.push({type:"abbr_close",level:--u}),c=l.lastIndex-d[3].length;a.length&&(c<o.length&&a.push({type:"text",content:o.slice(c),level:u}),p[t].children=i=[].concat(i.slice(0,e),a,i.slice(e+1)))}}}}var $T=/\+-|\.\.|\?\?\?\?|!!!!|,,|--/,GT=/\((c|tm|r|p)\)/ig,qT={c:"©",r:"®",p:"§",tm:"™"};function jT(r){return r.indexOf("(")<0?r:r.replace(GT,function(e,t){return qT[t.toLowerCase()]})}function zT(r){var e,t,n,i,s;if(r.options.typographer){for(s=r.tokens.length-1;s>=0;s--)if(r.tokens[s].type==="inline")for(i=r.tokens[s].children,e=i.length-1;e>=0;e--)t=i[e],t.type==="text"&&(n=t.content,n=jT(n),$T.test(n)&&(n=n.replace(/\+-/g,"±").replace(/\.{2,}/g,"…").replace(/([?!])…/g,"$1..").replace(/([?!]){4,}/g,"$1$1$1").replace(/,{2,}/g,",").replace(/(^|[^-])---([^-]|$)/mg,"$1—$2").replace(/(^|\s)--(\s|$)/mg,"$1–$2").replace(/(^|[^-\s])--([^-\s]|$)/mg,"$1–$2")),t.content=n)}}var YT=/['"]/,H0=/['"]/g,KT=/[-\s()\[\]]/,$0="’";function G0(r,e){return e<0||e>=r.length?!1:!KT.test(r[e])}function xn(r,e,t){return r.substr(0,e)+t+r.substr(e+1)}function WT(r){var e,t,n,i,s,o,a,c,u,l,d,h,p,m,E,A,T;if(r.options.typographer){for(T=[],E=r.tokens.length-1;E>=0;E--)if(r.tokens[E].type==="inline"){for(A=r.tokens[E].children,T.length=0,e=0;e<A.length;e++)if(t=A[e],!(t.type!=="text"||YT.test(t.text))){for(a=A[e].level,p=T.length-1;p>=0&&!(T[p].level<=a);p--);T.length=p+1,n=t.content,s=0,o=n.length;e:for(;s<o&&(H0.lastIndex=s,i=H0.exec(n),!!i);){if(c=!G0(n,i.index-1),s=i.index+1,m=i[0]==="'",u=!G0(n,s),!u&&!c){m&&(t.content=xn(t.content,i.index,$0));continue}if(d=!u,h=!c,h){for(p=T.length-1;p>=0&&(l=T[p],!(T[p].level<a));p--)if(l.single===m&&T[p].level===a){l=T[p],m?(A[l.token].content=xn(A[l.token].content,l.pos,r.options.quotes[2]),t.content=xn(t.content,i.index,r.options.quotes[3])):(A[l.token].content=xn(A[l.token].content,l.pos,r.options.quotes[0]),t.content=xn(t.content,i.index,r.options.quotes[1])),T.length=p;continue e}}d?T.push({token:e,pos:i.index,single:m,level:a}):h&&m&&(t.content=xn(t.content,i.index,$0))}}}}}var Cu=[["block",PT],["abbr",kT],["references",BT],["inline",VT],["footnote_tail",FT],["abbr2",HT],["replacements",zT],["smartquotes",WT]];function sE(){this.options={},this.ruler=new rt;for(var r=0;r<Cu.length;r++)this.ruler.push(Cu[r][0],Cu[r][1])}sE.prototype.process=function(r){var e,t,n;for(n=this.ruler.getRules(""),e=0,t=n.length;e<t;e++)n[e](r)};function Mn(r,e,t,n,i){var s,o,a,c,u,l,d;for(this.src=r,this.parser=e,this.options=t,this.env=n,this.tokens=i,this.bMarks=[],this.eMarks=[],this.tShift=[],this.blkIndent=0,this.line=0,this.lineMax=0,this.tight=!1,this.parentType="root",this.ddIndent=-1,this.level=0,this.result="",o=this.src,l=0,d=!1,a=c=l=0,u=o.length;c<u;c++){if(s=o.charCodeAt(c),!d)if(s===32){l++;continue}else d=!0;(s===10||c===u-1)&&(s!==10&&c++,this.bMarks.push(a),this.eMarks.push(c),this.tShift.push(l),d=!1,l=0,a=c+1)}this.bMarks.push(o.length),this.eMarks.push(o.length),this.tShift.push(0),this.lineMax=this.bMarks.length-1}Mn.prototype.isEmpty=function(e){return this.bMarks[e]+this.tShift[e]>=this.eMarks[e]};Mn.prototype.skipEmptyLines=function(e){for(var t=this.lineMax;e<t&&!(this.bMarks[e]+this.tShift[e]<this.eMarks[e]);e++);return e};Mn.prototype.skipSpaces=function(e){for(var t=this.src.length;e<t&&this.src.charCodeAt(e)===32;e++);return e};Mn.prototype.skipChars=function(e,t){for(var n=this.src.length;e<n&&this.src.charCodeAt(e)===t;e++);return e};Mn.prototype.skipCharsBack=function(e,t,n){if(e<=n)return e;for(;e>n;)if(t!==this.src.charCodeAt(--e))return e+1;return e};Mn.prototype.getLines=function(e,t,n,i){var s,o,a,c,u,l=e;if(e>=t)return"";if(l+1===t)return o=this.bMarks[l]+Math.min(this.tShift[l],n),a=i?this.eMarks[l]+1:this.eMarks[l],this.src.slice(o,a);for(c=new Array(t-e),s=0;l<t;l++,s++)u=this.tShift[l],u>n&&(u=n),u<0&&(u=0),o=this.bMarks[l]+u,l+1<t||i?a=this.eMarks[l]+1:a=this.eMarks[l],c[s]=this.src.slice(o,a);return c.join("")};function QT(r,e,t){var n,i;if(r.tShift[e]-r.blkIndent<4)return!1;for(i=n=e+1;n<t;){if(r.isEmpty(n)){n++;continue}if(r.tShift[n]-r.blkIndent>=4){n++,i=n;continue}break}return r.line=n,r.tokens.push({type:"code",content:r.getLines(e,i,4+r.blkIndent,!0),block:!0,lines:[e,r.line],level:r.level}),!0}function XT(r,e,t,n){var i,s,o,a,c,u=!1,l=r.bMarks[e]+r.tShift[e],d=r.eMarks[e];if(l+3>d||(i=r.src.charCodeAt(l),i!==126&&i!==96)||(c=l,l=r.skipChars(l,i),s=l-c,s<3)||(o=r.src.slice(l,d).trim(),o.indexOf("`")>=0))return!1;if(n)return!0;for(a=e;a++,!(a>=t||(l=c=r.bMarks[a]+r.tShift[a],d=r.eMarks[a],l<d&&r.tShift[a]<r.blkIndent));)if(r.src.charCodeAt(l)===i&&!(r.tShift[a]-r.blkIndent>=4)&&(l=r.skipChars(l,i),!(l-c<s)&&(l=r.skipSpaces(l),!(l<d)))){u=!0;break}return s=r.tShift[e],r.line=a+(u?1:0),r.tokens.push({type:"fence",params:o,content:r.getLines(e+1,a,s,!0),lines:[e,r.line],level:r.level}),!0}function JT(r,e,t,n){var i,s,o,a,c,u,l,d,h,p,m,E=r.bMarks[e]+r.tShift[e],A=r.eMarks[e];if(E>A||r.src.charCodeAt(E++)!==62||r.level>=r.options.maxNesting)return!1;if(n)return!0;for(r.src.charCodeAt(E)===32&&E++,c=r.blkIndent,r.blkIndent=0,a=[r.bMarks[e]],r.bMarks[e]=E,E=E<A?r.skipSpaces(E):E,s=E>=A,o=[r.tShift[e]],r.tShift[e]=E-r.bMarks[e],d=r.parser.ruler.getRules("blockquote"),i=e+1;i<t&&(E=r.bMarks[i]+r.tShift[i],A=r.eMarks[i],!(E>=A));i++){if(r.src.charCodeAt(E++)===62){r.src.charCodeAt(E)===32&&E++,a.push(r.bMarks[i]),r.bMarks[i]=E,E=E<A?r.skipSpaces(E):E,s=E>=A,o.push(r.tShift[i]),r.tShift[i]=E-r.bMarks[i];continue}if(s)break;for(m=!1,h=0,p=d.length;h<p;h++)if(d[h](r,i,t,!0)){m=!0;break}if(m)break;a.push(r.bMarks[i]),o.push(r.tShift[i]),r.tShift[i]=-1337}for(u=r.parentType,r.parentType="blockquote",r.tokens.push({type:"blockquote_open",lines:l=[e,0],level:r.level++}),r.parser.tokenize(r,e,i),r.tokens.push({type:"blockquote_close",level:--r.level}),r.parentType=u,l[1]=r.line,h=0;h<o.length;h++)r.bMarks[h+e]=a[h],r.tShift[h+e]=o[h];return r.blkIndent=c,!0}function ZT(r,e,t,n){var i,s,o,a=r.bMarks[e],c=r.eMarks[e];if(a+=r.tShift[e],a>c||(i=r.src.charCodeAt(a++),i!==42&&i!==45&&i!==95))return!1;for(s=1;a<c;){if(o=r.src.charCodeAt(a++),o!==i&&o!==32)return!1;o===i&&s++}return s<3?!1:(n||(r.line=e+1,r.tokens.push({type:"hr",lines:[e,r.line],level:r.level})),!0)}function q0(r,e){var t,n,i;return n=r.bMarks[e]+r.tShift[e],i=r.eMarks[e],n>=i||(t=r.src.charCodeAt(n++),t!==42&&t!==45&&t!==43)||n<i&&r.src.charCodeAt(n)!==32?-1:n}function j0(r,e){var t,n=r.bMarks[e]+r.tShift[e],i=r.eMarks[e];if(n+1>=i||(t=r.src.charCodeAt(n++),t<48||t>57))return-1;for(;;){if(n>=i)return-1;if(t=r.src.charCodeAt(n++),!(t>=48&&t<=57)){if(t===41||t===46)break;return-1}}return n<i&&r.src.charCodeAt(n)!==32?-1:n}function eA(r,e){var t,n,i=r.level+2;for(t=e+2,n=r.tokens.length-2;t<n;t++)r.tokens[t].level===i&&r.tokens[t].type==="paragraph_open"&&(r.tokens[t+2].tight=!0,r.tokens[t].tight=!0,t+=2)}function tA(r,e,t,n){var i,s,o,a,c,u,l,d,h,p,m,E,A,T,b,v,y,C,N=!0,I,L,P,j;if((d=j0(r,e))>=0)A=!0;else if((d=q0(r,e))>=0)A=!1;else return!1;if(r.level>=r.options.maxNesting)return!1;if(E=r.src.charCodeAt(d-1),n)return!0;for(b=r.tokens.length,A?(l=r.bMarks[e]+r.tShift[e],m=Number(r.src.substr(l,d-l-1)),r.tokens.push({type:"ordered_list_open",order:m,lines:y=[e,0],level:r.level++})):r.tokens.push({type:"bullet_list_open",lines:y=[e,0],level:r.level++}),i=e,v=!1,I=r.parser.ruler.getRules("list");i<t&&(T=r.skipSpaces(d),h=r.eMarks[i],T>=h?p=1:p=T-d,p>4&&(p=1),p<1&&(p=1),s=d-r.bMarks[i]+p,r.tokens.push({type:"list_item_open",lines:C=[e,0],level:r.level++}),a=r.blkIndent,c=r.tight,o=r.tShift[e],u=r.parentType,r.tShift[e]=T-r.bMarks[e],r.blkIndent=s,r.tight=!0,r.parentType="list",r.parser.tokenize(r,e,t,!0),(!r.tight||v)&&(N=!1),v=r.line-e>1&&r.isEmpty(r.line-1),r.blkIndent=a,r.tShift[e]=o,r.tight=c,r.parentType=u,r.tokens.push({type:"list_item_close",level:--r.level}),i=e=r.line,C[1]=i,T=r.bMarks[e],!(i>=t||r.isEmpty(i)||r.tShift[i]<r.blkIndent));){for(j=!1,L=0,P=I.length;L<P;L++)if(I[L](r,i,t,!0)){j=!0;break}if(j)break;if(A){if(d=j0(r,i),d<0)break}else if(d=q0(r,i),d<0)break;if(E!==r.src.charCodeAt(d-1))break}return r.tokens.push({type:A?"ordered_list