@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 • 726 kB
JavaScript
"use strict";var t0=Object.defineProperty;var n0=(n,e,t)=>e in n?t0(n,e,{enumerable:!0,configurable:!0,writable:!0,value:t}):n[e]=t;var m=(n,e,t)=>n0(n,typeof e!="symbol"?e+"":e,t);Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});class r0{static render(e,t){const r=document.createElement("div");r.id="error-view",r.innerText=t,e.replaceChildren(r)}}class Yi{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,r){const i=Yi.createElements(),s={onSuccess:t,onFail:r0.render.bind(this,e,"Your 'key' has failed authentication"),onLoad:Yi.onLoad.bind(this,i)};r.key&&r.verifyKey(r.key,s),e.replaceChildren(i)}}class ie{static unsetStyle(e,t){const r=Object.keys(t).reduce((i,s)=>(i[s]="",i),{});Object.assign(e.style,r)}static unsetActivityCSSMouseStates(e,t){t.click&&ie.unsetStyle(e,t.click),t.hover&&ie.unsetStyle(e,t.hover)}static unsetAllCSSMouseStates(e,t){ie.unsetActivityCSSMouseStates(e,t),t.default&&ie.unsetStyle(e,t.default)}static processStateful(e,t,r){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,...r})),e==null?void 0:e.click);return{default:i,hover:s,click:o}}static mergeStatefulStyles(e){const t={default:{},hover:{},click:{}};return e.forEach(r=>{t.default=Object.assign(t.default,r.default),t.hover=Object.assign(t.hover,r.hover),t.click=Object.assign(t.click,r.click)}),t}static overwriteDefaultWithAlreadyApplied(e,t){Object.keys(e.default||[]).forEach(r=>{var s;const i=r;t.style[i]&&(s=e.default)!=null&&s[i]&&(e.default[r]=t.style[i])})}static applyToStyleIfNotDefined(e,t){for(const r in t){const i=t[r];e[r]===""&&i&&(e[r]=i)}}}const Yt=class Yt{static attemptAppendStyleSheetToHead(e){if(e.fontFamily&&e.fontFamily!==Yt.DEFAULT_FONT_FAMILY)return;const t=document.getElementsByTagName("head")[0];if(!Array.from(t.getElementsByTagName("link")).some(i=>i.getAttribute("href")===Yt.FONT_URL)){const i=document.createElement("link");i.rel="stylesheet",i.href=Yt.FONT_URL,t.appendChild(i)}}};Yt.FONT_URL="https://fonts.googleapis.com/css2?family=Inter:wght@400;600&display=swap",Yt.DEFAULT_FONT_FAMILY="'Inter', sans-serif, Avenir, Helvetica, Arial";let Xi=Yt;const On=class On{static apply(e,t){if(t)try{On.applyStyleSheet(e,t)}catch{On.addStyleElement(e,t)}}static applyStyleSheet(e,t){const r=new CSSStyleSheet;r.replaceSync(e),t.adoptedStyleSheets.push(r)}static addStyleElement(e,t){const r=document.createElement("style");r.innerHTML=e,t.appendChild(r)}static applyDefaultStyleToComponent(e,t){t&&ie.applyToStyleIfNotDefined(e,t),ie.applyToStyleIfNotDefined(e,On.DEFAULT_COMPONENT_STYLE)}};On.DEFAULT_COMPONENT_STYLE={height:"350px",width:"320px",border:"1px solid #cacaca",fontFamily:Xi.DEFAULT_FONT_FAMILY,fontSize:"0.9rem",backgroundColor:"white",position:"relative",overflow:"hidden"};let Dr=On;var wt=(n=>(n.ESCAPE="Escape",n.ENTER="Enter",n.TAB="Tab",n.ARROW_UP="ArrowUp",n.ARROW_DOWN="ArrowDown",n.ARROW_RIGHT="ArrowRight",n.ARROW_LEFT="ArrowLeft",n.BACKSPACE="Backspace",n.DELETE="Delete",n.META="Meta",n.CONTROL="Control",n))(wt||{});const Kr=class Kr{};Kr.IS_SAFARI=/^((?!chrome|android).)*safari/i.test(navigator.userAgent),Kr.IS_CHROMIUM=window.chrome,Kr.IS_MOBILE=/Android|webOS|iPhone|iPad|iPod|BlackBerry|IEMobile|Opera Mini/i.test(navigator.userAgent);let fn=Kr;class i0{static sanitizePastedTextContent(e){var r,i;e.preventDefault();const t=(r=e.clipboardData)==null?void 0:r.getData("text/plain");t&&((i=document.execCommand)==null||i.call(document,"insertText",!1,t))}}const Xt=class Xt{constructor(e,t,r){var s,o;const i=Xt.processConfig(t,e.textInput);this.elementRef=Xt.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 r;return t??(t={}),t.disabled??(t.disabled=e.isTextInputDisabled),t.placeholder??(t.placeholder={}),(r=t.placeholder).text??(r.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,r,i,s;const e=document.createElement("div");return e.id=Xt.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"),fn.IS_CHROMIUM&&Xt.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,(r=this._config.placeholder)==null?void 0:r.style),(s=(i=this._config.placeholder)==null?void 0:i.style)!=null&&s.color||e.setAttribute("textcolor",""),e}removePlaceholderStyle(){var e,t,r,i;!this.inputElementRef.classList.contains("text-input-disabled")&&((e=this._config.placeholder)!=null&&e.style)&&(ie.unsetStyle(this.inputElementRef,(t=this._config.placeholder)==null?void 0:t.style),Object.assign(this.inputElementRef.style,(i=(r=this._config)==null?void 0:r.styles)==null?void 0:i.text))}addEventListeners(e){var t,r;(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,(r=this._config.styles)==null?void 0:r.container)),e.addEventListener("keydown",this.onKeydown.bind(this)),e.addEventListener("input",this.onInput.bind(this)),e.addEventListener("paste",i0.sanitizePastedTextContent)}onBlur(e,t){ie.unsetStyle(this.elementRef,e),t&&Object.assign(this.elementRef.style,t)}blur(){this.inputElementRef.blur()}onKeydown(e){var t;e.key===wt.ENTER&&!e.ctrlKey&&!e.shiftKey&&!fn.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===""}};Xt.TEXT_INPUT_ID="text-input";let es=Xt;class xa{static focusEndOfInput(e){const t=document.createRange();t.selectNodeContents(e),t.collapse(!1);const r=window.getSelection();r==null||r.removeAllRanges(),r==null||r.addRange(t)}static focusFromParentElement(e){const t=e.querySelector(`#${es.TEXT_INPUT_ID}`);t&&xa.focusEndOfInput(t)}}function wu(n){return n.charAt(0).toUpperCase()+n.slice(1)}function s0(n){return n&&JSON.stringify(n)}function Ea(n,e,t,r){const i=`
${wu(e)} message: ${JSON.stringify(n)}
`,s=t?`${wu(e)} message after interceptor: ${s0(r)}
`:"";return i+s}function o0(n,e,t,r){return`${Ea(n,e,t,r)}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 a0(n,e,t){const r="response";return`${Ea(n,r,e,t)}Make sure the ${r} message is using the {text: string} format, e.g: {text: "Model Response"}`}function u0(n,e){const t="request";return`${Ea(n,t,e)}Make sure the ${t} message is using the {body: {text: string}} format, e.g: {body: {text: "Model Response"}}`}const Su=`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`,re={INVALID_KEY:"Invalid API Key",CONNECTION_FAILED:"Failed to connect",INVALID_RESPONSE:o0,INVALID_MODEL_REQUEST:u0,INVALID_MODEL_RESPONSE:a0,INVALID_STREAM_EVENT:Su,INVALID_STREAM_EVENT_MIX:"Cannot mix {text: string} and {html: string} responses.",NO_VALID_STREAM_EVENTS_SENT:`No valid stream events were sent.
${Su}`},ks=class ks{static addElements(e,...t){t.forEach(r=>e.appendChild(r))}static isScrollbarAtBottomOfElement(e){const t=e.scrollHeight,r=e.clientHeight,i=e.scrollTop,s=t-r;return i>=s-ks.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}};ks.CODE_SNIPPET_GENERATION_JUMP=.5;let Ae=ks;const Ts=class Ts{static speak(e,t){if(window.SpeechSynthesisUtterance){const r=new SpeechSynthesisUtterance(e);Object.assign(r,t),speechSynthesis.speak(r)}}static processConfig(e,t){const r={};setTimeout(()=>{if(typeof e=="object"&&(e.lang&&(r.lang=e.lang),e.pitch&&(r.pitch=e.pitch),e.rate&&(r.rate=e.rate),e.volume&&(r.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&&(r.voice=i)}t(r)},Ts.LOAD_VOICES_MS)}};Ts.LOAD_VOICES_MS=200;let Un=Ts;class Ge{static checkForContainerStyles(e,t){const r=e.containerStyle;r&&(Object.assign(t.style,r),console.error("The containerStyle property is deprecated since version 1.3.14."),console.error("Please change to using the style property instead: https://deepchat.dev/docs/styles#style"))}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 r=e;r.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=r.onNewMessage)==null||i.call(r,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 Pn=class Pn{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 r,i,s,o;if((o=(s=(i=(r=t==null?void 0:t.loading)==null?void 0:r.message)==null?void 0:i.styles)==null?void 0:s.bubble)!=null&&o.color){const a=Pn.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:r,width:i,height:s,margin:o,border:a}=t||{};if(r){const u=Pn.colorToHex(r);e.style.setProperty("--loading-history-color",u)}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")}};Pn.BUBBLE_CLASS="deep-chat-loading-message-bubble",Pn.DOTS_CONTAINER_CLASS="deep-chat-loading-message-dots-container";let St=Pn;const c0="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",l0="data:image/png;base64,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",De=class De{static hide(e){var t;(t=e.getElementsByClassName(De.CONTAINER_CLASS)[0].style).visibility||(t.visibility="hidden")}static reveal(e){e.getElementsByClassName(De.CONTAINER_CLASS)[0].style.visibility=""}static applyCustomStylesToElements(e,t,r){Object.assign(e.style,r.container),Object.assign(t.style,r.avatar)}static applyCustomStyles(e,t,r,i){var s,o,a,u;if((s=r.default)!=null&&s.styles&&De.applyCustomStylesToElements(e,t,r.default.styles),i===O.USER_ROLE)(o=r.user)!=null&&o.styles&&De.applyCustomStylesToElements(e,t,r.user.styles);else{(a=r.ai)!=null&&a.styles&&De.applyCustomStylesToElements(e,t,r.ai.styles);const c=(u=r[i])==null?void 0:u.styles;c&&De.applyCustomStylesToElements(e,t,c)}}static createAvatar(e,t){var s,o,a,u,c;const r=document.createElement("img");e===O.USER_ROLE?r.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)||l0:r.src=((a=t==null?void 0:t[e])==null?void 0:a.src)||((u=t==null?void 0:t.ai)==null?void 0:u.src)||((c=t==null?void 0:t.default)==null?void 0:c.src)||c0,r.classList.add("avatar");const i=document.createElement("div");return i.classList.add(De.CONTAINER_CLASS),i.appendChild(r),t&&De.applyCustomStyles(i,r,t,e),i}static getPosition(e,t){var i,s,o,a,u,c;let r=(s=(i=t==null?void 0:t[e])==null?void 0:i.styles)==null?void 0:s.position;return e!==O.USER_ROLE&&(r??(r=(a=(o=t==null?void 0:t.ai)==null?void 0:o.styles)==null?void 0:a.position)),r??(r=(c=(u=t==null?void 0:t.default)==null?void 0:u.styles)==null?void 0:c.position),r??(r=e===O.USER_ROLE?"right":"left"),r}static add(e,t,r){const i=typeof r=="boolean"?void 0:r,s=De.createAvatar(t,i),o=De.getPosition(t,i);s.classList.add(o==="left"?"left-item-position":"right-item-position"),e.insertAdjacentElement(o==="left"?"beforebegin":"afterend",s)}};De.CONTAINER_CLASS="avatar-container";let Or=De;const nt=class nt{static hide(e){var t;(t=e.getElementsByClassName(nt.NAME_CLASS)[0].style).visibility||(t.visibility="hidden")}static reveal(e){e.getElementsByClassName(nt.NAME_CLASS)[0].style.visibility=""}static getPosition(e,t){var i,s,o;let r=(i=t==null?void 0:t[e])==null?void 0:i.position;return e!==O.USER_ROLE&&(r??(r=(s=t==null?void 0:t.ai)==null?void 0:s.position)),r??(r=(o=t==null?void 0:t.default)==null?void 0:o.position),r??(r=e===O.USER_ROLE?"right":"left"),r}static applyStyle(e,t,r){var i,s,o,a;Object.assign(e.style,(i=r.default)==null?void 0:i.style),t===O.USER_ROLE?Object.assign(e.style,(s=r.user)==null?void 0:s.style):(Object.assign(e.style,(o=r.ai)==null?void 0:o.style),Object.assign(e.style,(a=r[t])==null?void 0:a.style))}static getNameText(e,t){var r,i,s,o,a,u;return e===O.USER_ROLE?((r=t.user)==null?void 0:r.text)||((i=t.default)==null?void 0:i.text)||"User":e===O.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)||((u=t.default)==null?void 0:u.text)||e}static createName(e,t){const r=document.createElement("div");return r.classList.add(nt.NAME_CLASS),r.textContent=nt.getNameText(e,t),nt.applyStyle(r,e,t),r}static add(e,t,r){const i=typeof r=="boolean"?{}:r,s=nt.createName(t,i),o=nt.getPosition(t,i);s.classList.add(o==="left"?"left-item-position":"right-item-position"),e.insertAdjacentElement(o==="left"?"beforebegin":"afterend",s)}};nt.NAME_CLASS="name";let Pr=nt;const We=class We{static getLastElementsByClass(e,t,r){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(r){if(!r.find(u=>s.bubbleElement.classList.contains(u)))return s}else return s}}static getLastMessage(e,t,r){for(let i=e.length-1;i>=0;i-=1)if(e[i].role===t)if(r){if(e[i][r])return e[i]}else return e[i]}static getLastTextToElement(e,t){for(let r=e.length-1;r>=0;r-=1)if(e[r][0]===t)return e[r]}static overwriteMessage(e,t,r,i,s,o){const a=We.getLastElementsByClass(t,[We.getRoleClass(i),o],[St.BUBBLE_CLASS]),u=We.getLastMessage(e,i,s);return u&&(u[s]=r),a}static getRoleClass(e){return`${e}-message`}static fillEmptyMessageElement(e,t){t.trim().length===0&&(e.classList.add(We.EMPTY_MESSAGE_CLASS),e.innerHTML='<div style="color:#00000000">.</div>')}static unfillEmptyMessageElement(e,t){e.classList.contains(We.EMPTY_MESSAGE_CLASS)&&t.trim().length>0&&e.replaceChildren()}static getLastMessageBubbleElement(e){var t,r,i;return Array.from(((i=(r=(t=We.getLastMessageElement(e))==null?void 0:t.children)==null?void 0:r[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,r,i){r&&Or.add(e,t,r),i&&Pr.add(e,t,i)}static hideRoleElements(e,t,r){const i=e[e.length-1].innerContainer;t&&Or.hide(i),r&&Pr.hide(i)}static revealRoleElements(e,t,r){t&&Or.reveal(e),r&&Pr.reveal(e)}static updateRefArr(e,t,r){r?e.unshift(t):e.push(t)}};We.AI_ROLE="ai",We.USER_ROLE="user",We.EMPTY_MESSAGE_CLASS="empty-message";let O=We;class nn{static mouseUp(e,t){ie.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){ie.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",nn.mouseEnter.bind(this,e,t)),e.addEventListener("mouseleave",nn.mouseLeave.bind(this,e,t)),e.addEventListener("mousedown",nn.mouseDown.bind(this,e,t)),e.addEventListener("mouseup",nn.mouseUp.bind(this,e,t))}}const d0="deep-chat-temporary-message",h0="deep-chat-suggestion-button",Po={"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"}}}},Cu=Object.keys(Po);class Ct{static applySuggestionEvent(e,t){setTimeout(()=>{t.addEventListener("click",()=>{var r,i;(i=e.submitUserMessage)==null||i.call(e,{text:((r=t.textContent)==null?void 0:r.trim())||""})})})}static isElementTemporary(e){var t;return e?(t=e.bubbleElement.children[0])==null?void 0:t.classList.contains(d0):!1}static doesElementContainDeepChatClass(e){return Cu.find(t=>e.classList.contains(t))}static applyEvents(e,t){const r=Po[t].events;Object.keys(r||[]).forEach(i=>{e.addEventListener(i,r==null?void 0:r[i])})}static getProcessedStyles(e,t,r){const i=Array.from(t.classList).reduce((a,u)=>{var l;const c=(l=e[u])==null?void 0:l.styles;return c&&e[u].styles&&a.push(c),a},[]),s=Po[r].styles;if(s){const a=JSON.parse(JSON.stringify(s));a.default&&ie.overwriteDefaultWithAlreadyApplied(a,t),i.unshift(a)}const o=ie.mergeStatefulStyles(i);return ie.processStateful(o,{},{})}static applyDeepChatUtilities(e,t,r){Cu.forEach(s=>{const o=r.getElementsByClassName(s);Array.from(o||[]).forEach(a=>{const u=Ct.getProcessedStyles(t,a,s);Be.applyStylesToElement(a,u),Ct.applyEvents(a,s)})});const i=r.getElementsByClassName(h0);Array.from(i).forEach(s=>Ct.applySuggestionEvent(e,s))}}class Be{static applyStylesToElement(e,t){const r=ie.processStateful(t,{},{});nn.add(e,r),Object.assign(e.style,r.default)}static applyEventsToElement(e,t){Object.keys(t).forEach(r=>{const i=t[r];i&&e.addEventListener(r,i)})}static applyClassUtilitiesToElement(e,t){const{events:r,styles:i}=t;r&&Be.applyEventsToElement(e,r),i&&!Ct.doesElementContainDeepChatClass(e)&&Be.applyStylesToElement(e,i)}static applyCustomClassUtilities(e,t){Object.keys(e).forEach(r=>{const i=t.getElementsByClassName(r);Array.from(i).forEach(s=>{e[r]&&Be.applyClassUtilitiesToElement(s,e[r])})})}static apply(e,t){Ct.applyDeepChatUtilities(e,e.htmlClassUtilities,t),Be.applyCustomClassUtilities(e.htmlClassUtilities,t)}static traverseNodes(e,t){e.nodeType===Node.ELEMENT_NODE&&t.push(e.outerHTML),e.childNodes.forEach(r=>{Be.traverseNodes(r,t)})}static splitHTML(e){const r=new DOMParser().parseFromString(e,"text/html"),i=[];return r.body.childNodes.forEach(s=>{Be.traverseNodes(s,i)}),i}}class Ut{static addElement(e,t){e.elementRef.appendChild(t),e.elementRef.scrollTop=e.elementRef.scrollHeight}static createElements(e,t,r,i){const s=e.createMessageElementsOnOrientation("",r,i);return s.bubbleElement.classList.add("html-message"),s.bubbleElement.innerHTML=t,s}static overwrite(e,t,r,i){const{messages:s}=e,o=O.overwriteMessage(s,i,t,r,"html","html-message");return o&&(o.bubbleElement.innerHTML=t,Be.apply(e,o.outerContainer),Ge.flagHTMLUpdateClass(o.bubbleElement)),o}static add(e,t,r,i,s,o=!1){var u;if(s!=null&&s.status){const c=this.overwrite(e,t,r,i);if(c)return c;s.status=!1}const a=Ut.createElements(e,t,r,o);return O.fillEmptyMessageElement(a.bubbleElement,t),Be.apply(e,a.outerContainer),Ge.flagHTMLUpdateClass(a.bubbleElement),e.applyCustomStyles(a,r,!1,(u=e.messageStyles)==null?void 0:u.html),o||Ut.addElement(e,a.outerContainer),a}}var Fi;function Ul(n){return Fi=Fi||document.createElement("textarea"),Fi.innerHTML="&"+n+";",Fi.value}var f0=Object.prototype.hasOwnProperty;function p0(n,e){return n?f0.call(n,e):!1}function zl(n){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(r){n[r]=t[r]})}}),n}var m0=/\\([\\!"#$%&'()*+,.\/:;<=>?@[\]^_`{|}~-])/g;function Yr(n){return n.indexOf("\\")<0?n:n.replace(m0,"$1")}function ql(n){return!(n>=55296&&n<=57343||n>=64976&&n<=65007||(n&65535)===65535||(n&65535)===65534||n>=0&&n<=8||n===11||n>=14&&n<=31||n>=127&&n<=159||n>1114111)}function Fo(n){if(n>65535){n-=65536;var e=55296+(n>>10),t=56320+(n&1023);return String.fromCharCode(e,t)}return String.fromCharCode(n)}var g0=/&([a-z#][a-z0-9]{1,31});/gi,b0=/^#((?:x[a-f0-9]{1,8}|[0-9]{1,8}))/i;function v0(n,e){var t=0,r=Ul(e);return e!==r?r:e.charCodeAt(0)===35&&b0.test(e)&&(t=e[1].toLowerCase()==="x"?parseInt(e.slice(2),16):parseInt(e.slice(1),10),ql(t))?Fo(t):n}function pn(n){return n.indexOf("&")<0?n:n.replace(g0,v0)}var y0=/[&<>"]/,_0=/[&<>"]/g,x0={"&":"&","<":"<",">":">",'"':"""};function E0(n){return x0[n]}function Ie(n){return y0.test(n)?n.replace(_0,E0):n}var M={};M.blockquote_open=function(){return`<blockquote>
`};M.blockquote_close=function(n,e){return"</blockquote>"+_n(n,e)};M.code=function(n,e){return n[e].block?"<pre><code>"+Ie(n[e].content)+"</code></pre>"+_n(n,e):"<code>"+Ie(n[e].content)+"</code>"};M.fence=function(n,e,t,r,i){var s=n[e],o="",a=t.langPrefix,u="",c,l,d;if(s.params){if(c=s.params.split(/\s+/g),l=c.join(" "),p0(i.rules.fence_custom,c[0]))return i.rules.fence_custom[c[0]](n,e,t,r,i);u=Ie(pn(Yr(l))),o=' class="'+a+u+'"'}return t.highlight?d=t.highlight.apply(t.highlight,[s.content].concat(c))||Ie(s.content):d=Ie(s.content),"<pre><code"+o+">"+d+"</code></pre>"+_n(n,e)};M.fence_custom={};M.heading_open=function(n,e){return"<h"+n[e].hLevel+">"};M.heading_close=function(n,e){return"</h"+n[e].hLevel+`>
`};M.hr=function(n,e,t){return(t.xhtmlOut?"<hr />":"<hr>")+_n(n,e)};M.bullet_list_open=function(){return`<ul>
`};M.bullet_list_close=function(n,e){return"</ul>"+_n(n,e)};M.list_item_open=function(){return"<li>"};M.list_item_close=function(){return`</li>
`};M.ordered_list_open=function(n,e){var t=n[e],r=t.order>1?' start="'+t.order+'"':"";return"<ol"+r+`>
`};M.ordered_list_close=function(n,e){return"</ol>"+_n(n,e)};M.paragraph_open=function(n,e){return n[e].tight?"":"<p>"};M.paragraph_close=function(n,e){var t=!(n[e].tight&&e&&n[e-1].type==="inline"&&!n[e-1].content);return(n[e].tight?"":"</p>")+(t?_n(n,e):"")};M.link_open=function(n,e,t){var r=n[e].title?' title="'+Ie(pn(n[e].title))+'"':"",i=t.linkTarget?' target="'+t.linkTarget+'"':"";return'<a href="'+Ie(n[e].href)+'"'+r+i+">"};M.link_close=function(){return"</a>"};M.image=function(n,e,t){var r=' src="'+Ie(n[e].src)+'"',i=n[e].title?' title="'+Ie(pn(n[e].title))+'"':"",s=' alt="'+(n[e].alt?Ie(pn(Yr(n[e].alt))):"")+'"',o=t.xhtmlOut?" /":"";return"<img"+r+s+i+o+">"};M.table_open=function(){return`<table>
`};M.table_close=function(){return`</table>
`};M.thead_open=function(){return`<thead>
`};M.thead_close=function(){return`</thead>
`};M.tbody_open=function(){return`<tbody>
`};M.tbody_close=function(){return`</tbody>
`};M.tr_open=function(){return"<tr>"};M.tr_close=function(){return`</tr>
`};M.th_open=function(n,e){var t=n[e];return"<th"+(t.align?' style="text-align:'+t.align+'"':"")+">"};M.th_close=function(){return"</th>"};M.td_open=function(n,e){var t=n[e];return"<td"+(t.align?' style="text-align:'+t.align+'"':"")+">"};M.td_close=function(){return"</td>"};M.strong_open=function(){return"<strong>"};M.strong_close=function(){return"</strong>"};M.em_open=function(){return"<em>"};M.em_close=function(){return"</em>"};M.del_open=function(){return"<del>"};M.del_close=function(){return"</del>"};M.ins_open=function(){return"<ins>"};M.ins_close=function(){return"</ins>"};M.mark_open=function(){return"<mark>"};M.mark_close=function(){return"</mark>"};M.sub=function(n,e){return"<sub>"+Ie(n[e].content)+"</sub>"};M.sup=function(n,e){return"<sup>"+Ie(n[e].content)+"</sup>"};M.hardbreak=function(n,e,t){return t.xhtmlOut?`<br />
`:`<br>
`};M.softbreak=function(n,e,t){return t.breaks?t.xhtmlOut?`<br />
`:`<br>
`:`
`};M.text=function(n,e){return Ie(n[e].content)};M.htmlblock=function(n,e){return n[e].content};M.htmltag=function(n,e){return n[e].content};M.abbr_open=function(n,e){return'<abbr title="'+Ie(pn(n[e].title))+'">'};M.abbr_close=function(){return"</abbr>"};M.footnote_ref=function(n,e){var t=Number(n[e].id+1).toString(),r="fnref"+t;return n[e].subId>0&&(r+=":"+n[e].subId),'<sup class="footnote-ref"><a href="#fn'+t+'" id="'+r+'">['+t+"]</a></sup>"};M.footnote_block_open=function(n,e,t){var r=t.xhtmlOut?`<hr class="footnotes-sep" />
`:`<hr class="footnotes-sep">
`;return r+`<section class="footnotes">
<ol class="footnotes-list">
`};M.footnote_block_close=function(){return`</ol>
</section>
`};M.footnote_open=function(n,e){var t=Number(n[e].id+1).toString();return'<li id="fn'+t+'" class="footnote-item">'};M.footnote_close=function(){return`</li>
`};M.footnote_anchor=function(n,e){var t=Number(n[e].id+1).toString(),r="fnref"+t;return n[e].subId>0&&(r+=":"+n[e].subId),' <a href="#'+r+'" class="footnote-backref">↩</a>'};M.dl_open=function(){return`<dl>
`};M.dt_open=function(){return"<dt>"};M.dd_open=function(){return"<dd>"};M.dl_close=function(){return`</dl>
`};M.dt_close=function(){return`</dt>
`};M.dd_close=function(){return`</dd>
`};function Hl(n,e){return++e>=n.length-2?e:n[e].type==="paragraph_open"&&n[e].tight&&n[e+1].type==="inline"&&n[e+1].content.length===0&&n[e+2].type==="paragraph_close"&&n[e+2].tight?Hl(n,e+2):e}var _n=M.getBreak=function(e,t){return t=Hl(e,t),t<e.length&&e[t].type==="list_item_close"?"":`
`};function wa(){this.rules=zl({},M),this.getBreak=M.getBreak}wa.prototype.renderInline=function(n,e,t){for(var r=this.rules,i=n.length,s=0,o="";i--;)o+=r[n[s].type](n,s++,e,t,this);return o};wa.prototype.render=function(n,e,t){for(var r=this.rules,i=n.length,s=-1,o="";++s<i;)n[s].type==="inline"?o+=this.renderInline(n[s].children,e,t):o+=r[n[s].type](n,s,e,t,this);return o};function Ue(){this.__rules__=[],this.__cache__=null}Ue.prototype.__find__=function(n){for(var e=this.__rules__.length,t=-1;e--;)if(this.__rules__[++t].name===n)return t;return-1};Ue.prototype.__compile__=function(){var n=this,e=[""];n.__rules__.forEach(function(t){t.enabled&&t.alt.forEach(function(r){e.indexOf(r)<0&&e.push(r)})}),n.__cache__={},e.forEach(function(t){n.__cache__[t]=[],n.__rules__.forEach(function(r){r.enabled&&(t&&r.alt.indexOf(t)<0||n.__cache__[t].push(r.fn))})})};Ue.prototype.at=function(n,e,t){var r=this.__find__(n),i=t||{};if(r===-1)throw new Error("Parser rule not found: "+n);this.__rules__[r].fn=e,this.__rules__[r].alt=i.alt||[],this.__cache__=null};Ue.prototype.before=function(n,e,t,r){var i=this.__find__(n),s=r||{};if(i===-1)throw new Error("Parser rule not found: "+n);this.__rules__.splice(i,0,{name:e,enabled:!0,fn:t,alt:s.alt||[]}),this.__cache__=null};Ue.prototype.after=function(n,e,t,r){var i=this.__find__(n),s=r||{};if(i===-1)throw new Error("Parser rule not found: "+n);this.__rules__.splice(i+1,0,{name:e,enabled:!0,fn:t,alt:s.alt||[]}),this.__cache__=null};Ue.prototype.push=function(n,e,t){var r=t||{};this.__rules__.push({name:n,enabled:!0,fn:e,alt:r.alt||[]}),this.__cache__=null};Ue.prototype.enable=function(n,e){n=Array.isArray(n)?n:[n],e&&this.__rules__.forEach(function(t){t.enabled=!1}),n.forEach(function(t){var r=this.__find__(t);if(r<0)throw new Error("Rules manager: invalid rule name "+t);this.__rules__[r].enabled=!0},this),this.__cache__=null};Ue.prototype.disable=function(n){n=Array.isArray(n)?n:[n],n.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};Ue.prototype.getRules=function(n){return this.__cache__===null&&this.__compile__(),this.__cache__[n]||[]};function w0(n){n.inlineMode?n.tokens.push({type:"inline",content:n.src.replace(/\n/g," ").trim(),level:0,lines:[0,1],children:[]}):n.block.parse(n.src,n.options,n.env,n.tokens)}function xn(n,e,t,r,i){this.src=n,this.env=r,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}xn.prototype.pushPending=function(){this.tokens.push({type:"text",content:this.pending,level:this.pendingLevel}),this.pending=""};xn.prototype.push=function(n){this.pending&&this.pushPending(),this.tokens.push(n),this.pendingLevel=this.level};xn.prototype.cacheSet=function(n,e){for(var t=this.cache.length;t<=n;t++)this.cache.push(0);this.cache[n]=e};xn.prototype.cacheGet=function(n){return n<this.cache.length?this.cache[n]:0};function Xr(n,e){var t,r,i,s=-1,o=n.posMax,a=n.pos,u=n.isInLabel;if(n.isInLabel)return-1;if(n.labelUnmatchedScopes)return n.labelUnmatchedScopes--,-1;for(n.pos=e+1,n.isInLabel=!0,t=1;n.pos<o;){if(i=n.src.charCodeAt(n.pos),i===91)t++;else if(i===93&&(t--,t===0)){r=!0;break}n.parser.skipToken(n)}return r?(s=n.pos,n.labelUnmatchedScopes=0):n.labelUnmatchedScopes=t-1,n.pos=a,n.isInLabel=u,s}function S0(n,e,t,r){var i,s,o,a,u,c;if(n.charCodeAt(0)!==42||n.charCodeAt(1)!==91||n.indexOf("]:")===-1||(i=new xn(n,e,t,r,[]),s=Xr(i,1),s<0||n.charCodeAt(s+1)!==58))return-1;for(a=i.posMax,o=s+2;o<a&&i.src.charCodeAt(o)!==10;o++);return u=n.slice(2,s),c=n.slice(s+2,o).trim(),c.length===0?-1:(r.abbreviations||(r.abbreviations={}),typeof r.abbreviations[":"+u]>"u"&&(r.abbreviations[":"+u]=c),o)}function C0(n){var e=n.tokens,t,r,i,s;if(!n.inlineMode){for(t=1,r=e.length-1;t<r;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=S0(i,n.inline,n.options,n.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 Bo(n){var e=pn(n);try{e=decodeURI(e)}catch{}return encodeURI(e)}function jl(n,e){var t,r,i,s=e,o=n.posMax;if(n.src.charCodeAt(e)===60){for(e++;e<o;){if(t=n.src.charCodeAt(e),t===10)return!1;if(t===62)return i=Bo(Yr(n.src.slice(s+1,e))),n.parser.validateLink(i)?(n.pos=e+1,n.linkContent=i,!0):!1;if(t===92&&e+1<o){e+=2;continue}e++}return!1}for(r=0;e<o&&(t=n.src.charCodeAt(e),!(t===32||t<32||t===127));){if(t===92&&e+1<o){e+=2;continue}if(t===40&&(r++,r>1)||t===41&&(r--,r<0))break;e++}return s===e||(i=Yr(n.src.slice(s,e)),!n.parser.validateLink(i))?!1:(n.linkContent=i,n.pos=e,!0)}function Gl(n,e){var t,r=e,i=n.posMax,s=n.src.charCodeAt(e);if(s!==34&&s!==39&&s!==40)return!1;for(e++,s===40&&(s=41);e<i;){if(t=n.src.charCodeAt(e),t===s)return n.pos=e+1,n.linkContent=Yr(n.src.slice(r+1,e)),!0;if(t===92&&e+1<i){e+=2;continue}e++}return!1}function Vl(n){return n.trim().replace(/\s+/g," ").toUpperCase()}function A0(n,e,t,r){var i,s,o,a,u,c,l,d,h;if(n.charCodeAt(0)!==91||n.indexOf("]:")===-1||(i=new xn(n,e,t,r,[]),s=Xr(i,0),s<0||n.charCodeAt(s+1)!==58))return-1;for(a=i.posMax,o=s+2;o<a&&(u=i.src.charCodeAt(o),!(u!==32&&u!==10));o++);if(!jl(i,o))return-1;for(l=i.linkContent,o=i.pos,c=o,o=o+1;o<a&&(u=i.src.charCodeAt(o),!(u!==32&&u!==10));o++);for(o<a&&c!==o&&Gl(i,o)?(d=i.linkContent,o=i.pos):(d="",o=c);o<a&&i.src.charCodeAt(o)===32;)o++;return o<a&&i.src.charCodeAt(o)!==10?-1:(h=Vl(n.slice(1,s)),typeof r.references[h]>"u"&&(r.references[h]={title:d,href:l}),o)}function k0(n){var e=n.tokens,t,r,i,s;if(n.env.references=n.env.references||{},!n.inlineMode){for(t=1,r=e.length-1;t<r;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=A0(i,n.inline,n.options,n.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 T0(n){var e=n.tokens,t,r,i;for(r=0,i=e.length;r<i;r++)t=e[r],t.type==="inline"&&n.inline.parse(t.content,n.options,n.env,t.children)}function M0(n){var e,t,r,i,s,o,a,u,c,l=0,d=!1,h={};if(n.env.footnotes&&(n.tokens=n.tokens.filter(function(p){return p.type==="footnote_reference_open"?(d=!0,u=[],c=p.label,!1):p.type==="footnote_reference_close"?(d=!1,h[":"+c]=u,!1):(d&&u.push(p),!d)}),!!n.env.footnotes.list)){for(o=n.env.footnotes.list,n.tokens.push({type:"footnote_block_open",level:l++}),e=0,t=o.length;e<t;e++){for(n.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]),n.tokens=n.tokens.concat(a),n.tokens[n.tokens.length-1].type==="paragraph_close"?s=n.tokens.pop():s=null,i=o[e].count>0?o[e].count:1,r=0;r<i;r++)n.tokens.push({type:"footnote_anchor",id:e,subId:r,level:l});s&&n.tokens.push(s),n.tokens.push({type:"footnote_close",level:--l})}n.tokens.push({type:"footnote_block_close",level:--l})}}var Au=`
()[]'".,!?-`;function oo(n){return n.replace(/([-()\[\]{}+?*.$\^|,:#<!\\])/g,"\\$1")}function R0(n){var e,t,r,i,s,o,a,u,c,l,d,h,p=n.tokens;if(n.env.abbreviations){for(n.env.abbrRegExp||(h="(^|["+Au.split("").map(oo).join("")+"])("+Object.keys(n.env.abbreviations).map(function(f){return f.substr(1)}).sort(function(f,g){return g.length-f.length}).map(oo).join("|")+")($|["+Au.split("").map(oo).join("")+"])",n.env.abbrRegExp=new RegExp(h,"g")),l=n.env.abbrRegExp,t=0,r=p.length;t<r;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(u=0,o=s.content,l.lastIndex=0,c=s.level,a=[];d=l.exec(o);)l.lastIndex>u&&a.push({type:"text",content:o.slice(u,d.index+d[1].length),level:c}),a.push({type:"abbr_open",title:n.env.abbreviations[":"+d[2]],level:c++}),a.push({type:"text",content:d[2],level:c}),a.push({type:"abbr_close",level:--c}),u=l.lastIndex-d[3].length;a.length&&(u<o.length&&a.push({type:"text",content:o.slice(u),level:c}),p[t].children=i=[].concat(i.slice(0,e),a,i.slice(e+1)))}}}}var I0=/\+-|\.\.|\?\?\?\?|!!!!|,,|--/,L0=/\((c|tm|r|p)\)/ig,N0={c:"©",r:"®",p:"§",tm:"™"};function D0(n){return n.indexOf("(")<0?n:n.replace(L0,function(e,t){return N0[t.toLowerCase()]})}function O0(n){var e,t,r,i,s;if(n.options.typographer){for(s=n.tokens.length-1;s>=0;s--)if(n.tokens[s].type==="inline")for(i=n.tokens[s].children,e=i.length-1;e>=0;e--)t=i[e],t.type==="text"&&(r=t.content,r=D0(r),I0.test(r)&&(r=r.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=r)}}var P0=/['"]/,ku=/['"]/g,F0=/[-\s()\[\]]/,Tu="’";function Mu(n,e){return e<0||e>=n.length?!1:!F0.test(n[e])}function An(n,e,t){return n.substr(0,e)+t+n.substr(e+1)}function B0(n){var e,t,r,i,s,o,a,u,c,l,d,h,p,f,g,v,b;if(n.options.typographer){for(b=[],g=n.tokens.length-1;g>=0;g--)if(n.tokens[g].type==="inline"){for(v=n.tokens[g].children,b.length=0,e=0;e<v.length;e++)if(t=v[e],!(t.type!=="text"||P0.test(t.text))){for(a=v[e].level,p=b.length-1;p>=0&&!(b[p].level<=a);p--);b.length=p+1,r=t.content,s=0,o=r.length;e:for(;s<o&&(ku.lastIndex=s,i=ku.exec(r),!!i);){if(u=!Mu(r,i.index-1),s=i.index+1,f=i[0]==="'",c=!Mu(r,s),!c&&!u){f&&(t.content=An(t.content,i.index,Tu));continue}if(d=!c,h=!u,h){for(p=b.length-1;p>=0&&(l=b[p],!(b[p].level<a));p--)if(l.single===f&&b[p].level===a){l=b[p],f?(v[l.token].content=An(v[l.token].content,l.pos,n.options.quotes[2]),t.content=An(t.content,i.index,n.options.quotes[3])):(v[l.token].content=An(v[l.token].content,l.pos,n.options.quotes[0]),t.content=An(t.content,i.index,n.options.quotes[1])),b.length=p;continue e}}d?b.push({token:e,pos:i.index,single:f,level:a}):h&&f&&(t.content=An(t.content,i.index,Tu))}}}}}var ao=[["block",w0],["abbr",C0],["references",k0],["inline",T0],["footnote_tail",M0],["abbr2",R0],["replacements",O0],["smartquotes",B0]];function Wl(){this.options={},this.ruler=new Ue;for(var n=0;n<ao.length;n++)this.ruler.push(ao[n][0],ao[n][1])}Wl.prototype.process=function(n){var e,t,r;for(r=this.ruler.getRules(""),e=0,t=r.length;e<t;e++)r[e](n)};function En(n,e,t,r,i){var s,o,a,u,c,l,d;for(this.src=n,this.parser=e,this.options=t,this.env=r,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=u=l=0,c=o.length;u<c;u++){if(s=o.charCodeAt(u),!d)if(s===32){l++;continue}else d=!0;(s===10||u===c-1)&&(s!==10&&u++,this.bMarks.push(a),this.eMarks.push(u),this.tShift.push(l),d=!1,l=0,a=u+1)}this.bMarks.push(o.length),this.eMarks.push(o.length),this.tShift.push(0),this.lineMax=this.bMarks.length-1}En.prototype.isEmpty=function(e){return this.bMarks[e]+this.tShift[e]>=this.eMarks[e]};En.prototype.skipEmptyLines=function(e){for(var t=this.lineMax;e<t&&!(this.bMarks[e]+this.tShift[e]<this.eMarks[e]);e++);return e};En.prototype.skipSpaces=function(e){for(var t=this.src.length;e<t&&this.src.charCodeAt(e)===32;e++);return e};En.prototype.skipChars=function(e,t){for(var r=this.src.length;e<r&&this.src.charCodeAt(e)===t;e++);return e};En.prototype.skipCharsBack=function(e,t,r){if(e<=r)return e;for(;e>r;)if(t!==this.src.charCodeAt(--e))return e+1;return e};En.prototype.getLines=function(e,t,r,i){var s,o,a,u,c,l=e;if(e>=t)return"";if(l+1===t)return o=this.bMarks[l]+Math.min(this.tShift[l],r),a=i?this.eMarks[l]+1:this.eMarks[l],this.src.slice(o,a);for(u=new Array(t-e),s=0;l<t;l++,s++)c=this.tShift[l],c>r&&(c=r),c<0&&(c=0),o=this.bMarks[l]+c,l+1<t||i?a=this.eMarks[l]+1:a=this.eMarks[l],u[s]=this.src.slice(o,a);return u.join("")};function $0(n,e,t){var r,i;if(n.tShift[e]-n.blkIndent<4)return!1;for(i=r=e+1;r<t;){if(n.isEmpty(r)){r++;continue}if(n.tShift[r]-n.blkIndent>=4){r++,i=r;continue}break}return n.line=r,n.tokens.push({type:"code",content:n.getLines(e,i,4+n.blkIndent,!0),block:!0,lines:[e,n.line],level:n.level}),!0}function U0(n,e,t,r){var i,s,o,a,u,c=!1,l=n.bMarks[e]+n.tShift[e],d=n.eMarks[e];if(l+3>d||(i=n.src.charCodeAt(l),i!==126&&i!==96)||(u=l,l=n.skipChars(l,i),s=l-u,s<3)||(o=n.src.slice(l,d).trim(),o.indexOf("`")>=0))return!1;if(r)return!0;for(a=e;a++,!(a>=t||(l=u=n.bMarks[a]+n.tShift[a],d=n.eMarks[a],l<d&&n.tShift[a]<n.blkIndent));)if(n.src.charCodeAt(l)===i&&!(n.tShift[a]-n.blkIndent>=4)&&(l=n.skipChars(l,i),!(l-u<s)&&(l=n.skipSpaces(l),!(l<d)))){c=!0;break}return s=n.tShift[e],n.line=a+(c?1:0),n.tokens.push({type:"fence",params:o,content:n.getLines(e+1,a,s,!0),lines:[e,n.line],level:n.level}),!0}function z0(n,e,t,r){var i,s,o,a,u,c,l,d,h,p,f,g=n.bMarks[e]+n.tShift[e],v=n.eMarks[e];if(g>v||n.src.charCodeAt(g++)!==62||n.level>=n.options.maxNesting)return!1;if(r)return!0;for(n.src.charCodeAt(g)===32&&g++,u=n.blkIndent,n.blkIndent=0,a=[n.bMarks[e]],n.bMarks[e]=g,g=g<v?n.skipSpaces(g):g,s=g>=v,o=[n.tShift[e]],n.tShift[e]=g-n.bMarks[e],d=n.parser.ruler.getRules("blockquote"),i=e+1;i<t&&(g=n.bMarks[i]+n.tShift[i],v=n.eMarks[i],!(g>=v));i++){if(n.src.charCodeAt(g++)===62){n.src.charCodeAt(g)===32&&g++,a.push(n.bMarks[i]),n.bMarks[i]=g,g=g<v?n.skipSpaces(g):g,s=g>=v,o.push(n.tShift[i]),n.tShift[i]=g-n.bMarks[i];continue}if(s)break;for(f=!1,h=0,p=d.length;h<p;h++)if(d[h](n,i,t,!0)){f=!0;break}if(f)break;a.push(n.bMarks[i]),o.push(n.tShift[i]),n.tShift[i]=-1337}for(c=n.parentType,n.parentType="blockquote",n.tokens.push({type:"blockquote_open",lines:l=[e,0],level:n.level++}),n.parser.tokenize(n,e,i),n.tokens.push({type:"blockquote_close",level:--n.level}),n.parentType=c,l[1]=n.line,h=0;h<o.length;h++)n.bMarks[h+e]=a[h],n.tShift[h+e]=o[h];return n.blkIndent=u,!0}function q0(n,e,t,r){var i,s,o,a=n.bMarks[e],u=n.eMarks[e];if(a+=n.tShift[e],a>u||(i=n.src.charCodeAt(a++),i!==42&&i!==45&&i!==95))return!1;for(s=1;a<u;){if(o=n.src.charCodeAt(a++),o!==i&&o!==32)return!1;o===i&&s++}return s<3?!1:(r||(n.line=e+1,n.tokens.push({type:"hr",lines:[e,n.line],level:n.level})),!0)}function Ru(n,e){var t,r,i;return r=n.bMarks[e]+n.tShift[e],i=n.eMarks[e],r>=i||(t=n.src.charCodeAt(r++),t!==42&&t!==45&&t!==43)||r<i&&n.src.charCodeAt(r)!==32?-1:r}function Iu(n,e){var t,r=n.bMarks[e]+n.tShift[e],i=n.eMarks[e];if(r+1>=i||(t=n.src.charCodeAt(r++),t<48||t>57))return-1;for(;;){if(r>=i)return-1;if(t=n.src.charCodeAt(r++),!(t>=48&&t<=57)){if(t===41||t===46)break;return-1}}return r<i&&n.src.charCodeAt(r)!==32?-1:r}function H0(n,e){var t,r,i=n.level+2;for(t=e+2,r=n.tokens.length-2;t<r;t++)n.tokens[t].level===i&&n.tokens[t].type==="paragraph_open"&&(n.tokens[t+2].tight=!0,n.tokens[t].tight=!0,t+=2)}function j0(n,e,t,r){var i,s,o,a,u,c,l,d,h,p,f,g,v,b,y,_,x,E,w=!0,A,k,I,U;if((d=Iu(n,e))>=0)v=!0;else if((d=Ru(n,e))>=0)v=!1;else return!1;if(n.level>=n.options.maxNesting)return!1;if(g=n.src.charCodeAt(d-1),r)return!0;for(y=n.tokens.length,v?(l=n.bMarks[e]+n.tShift[e],f=Number(n.src.substr(l,d-l-1)),n.tokens.push({type:"ordered_list_open",order:f,lines:x=[e,0],level:n.level++})):n.tokens.push({type:"bullet_list_open",lines:x=[e,0],level:n.level++}),i=e,_=!1,A=n.parser.ruler.getRules("list");i<t&&(b=n.skipSpaces(d),h=n.eMarks[i],b>=h?p=1:p=b-d,p>4&&(p=1),p<1&&(p=1),s=d-n.bMarks[i]+p,n.tokens.push({type:"list_item_open",lines:E=[e,0],level:n.level++}),a=n.blkIndent,u=n.tight,o=n.tShift[e],c=n.parentType,n.tShift[e]=b-n.bMarks[e],n.blkIndent=s,n.tight=!0,n.parentType="list",n.parser.tokenize(n,e,t,!0),(!n.tight||_)&&(w=!1),_=n.line-e>1&&n.isEmpty(n.line-1),n.blkIndent=a,n.tShift[e]=o,n.tight=u,n.parentType=c,n.tokens.push({type:"list_item_close",level:--n.level}),i=e=n.line,E[1]=i,b=n.bMarks[e],!(i>=t||n.isEmpty(i)||n.tShift[i]<n.blkIndent));){for(U=!1,k=0,I=A.length;k<I;k++)if(A[k](n,i,t,!0)){U=!0;break}if(U)break;if(v){if(d=Iu(n,i),d<0)break}else if(d=Ru(n,i),d<0)break;if(g!==n.src.charCodeAt(d-1))break}return n.tokens.push({type:v?"ordered_list_close":"bullet_list_close",level:--n.level}),x[1]=i,n.