deep-chat
Version:
Customizable chat component for AI APIs
1 lines • 326 kB
JavaScript
class t{static render(t,e){const i=document.createElement("div");i.id="error-view",i.innerText=e,t.replaceChildren(i)}}class e{static onLoad(t){t.innerHTML='<div id="loading-validate-key-property"></div>'}static createElements(){const t=document.createElement("div");return t.id="validate-property-key-view",t}static render(i,s,n){const o=e.createElements(),r={onSuccess:s,onFail:t.render.bind(this,i,"Your 'key' has failed authentication"),onLoad:e.onLoad.bind(this,o)};n.key&&n.verifyKey(n.key,r),i.replaceChildren(o)}}class i{static unsetStyle(t,e){const i=Object.keys(e).reduce(((t,e)=>(t[e]="",t)),{});Object.assign(t.style,i)}static unsetActivityCSSMouseStates(t,e){e.click&&i.unsetStyle(t,e.click),e.hover&&i.unsetStyle(t,e.hover)}static unsetAllCSSMouseStates(t,e){i.unsetActivityCSSMouseStates(t,e),e.default&&i.unsetStyle(t,e.default)}static processStateful(t,e,i){const s=t.default||{},n=Object.assign(JSON.parse(JSON.stringify({...s,...e})),null==t?void 0:t.hover);return{default:s,hover:n,click:Object.assign(JSON.parse(JSON.stringify({...n,...i})),null==t?void 0:t.click)}}static mergeStatefulStyles(t){const e={default:{},hover:{},click:{}};return t.forEach((t=>{e.default=Object.assign(e.default,t.default),e.hover=Object.assign(e.hover,t.hover),e.click=Object.assign(e.click,t.click)})),e}static overwriteDefaultWithAlreadyApplied(t,e){Object.keys(t.default||[]).forEach((i=>{var s;const n=i;e.style[n]&&null!=(s=t.default)&&s[n]&&(t.default[i]=e.style[n])}))}static applyToStyleIfNotDefined(t,e){for(const i in e){const s=e[i];""===t[i]&&s&&(t[i]=s)}}}const s=class t{static attemptAppendStyleSheetToHead(e){if(e.fontFamily&&e.fontFamily!==t.DEFAULT_FONT_FAMILY)return;const i=document.getElementsByTagName("head")[0];if(!Array.from(i.getElementsByTagName("link")).some((e=>e.getAttribute("href")===t.FONT_URL))){const e=document.createElement("link");e.rel="stylesheet",e.href=t.FONT_URL,i.appendChild(e)}}};s.FONT_URL="https://fonts.googleapis.com/css2?family=Inter:wght@400;600&display=swap",s.DEFAULT_FONT_FAMILY="'Inter', sans-serif, Avenir, Helvetica, Arial";let n=s;const o=class t{static apply(e,i){if(i)try{t.applyStyleSheet(e,i)}catch{t.addStyleElement(e,i)}}static applyStyleSheet(t,e){const i=new CSSStyleSheet;i.replaceSync(t),e.adoptedStyleSheets.push(i)}static addStyleElement(t,e){const i=document.createElement("style");i.innerHTML=t,e.appendChild(i)}static applyDefaultStyleToComponent(e,s){s&&i.applyToStyleIfNotDefined(e,s),i.applyToStyleIfNotDefined(e,t.DEFAULT_COMPONENT_STYLE)}};o.DEFAULT_COMPONENT_STYLE={height:"350px",width:"320px",borderTop:"1px solid #cacaca",borderRight:"1px solid #cacaca",borderLeft:"1px solid #cacaca",borderBottom:"1px solid #cacaca",fontFamily:n.DEFAULT_FONT_FAMILY,fontSize:"0.9rem",backgroundColor:"white",position:"relative",overflow:"hidden"};let r=o;var a;let l=((a=class{}).IS_SAFARI=/^((?!chrome|android).)*safari/i.test(navigator.userAgent),a.IS_CHROMIUM=window.chrome,a);var c=(t=>(t.ESCAPE="Escape",t.ENTER="Enter",t.TAB="Tab",t.ARROW_UP="ArrowUp",t.ARROW_DOWN="ArrowDown",t.ARROW_RIGHT="ArrowRight",t.ARROW_LEFT="ArrowLeft",t.BACKSPACE="Backspace",t.DELETE="Delete",t.META="Meta",t.CONTROL="Control",t))(c||{});const h=class t{static add(e,i,s,n){void 0!==s&&e.addEventListener("keydown",t.onKeyDown.bind(this,s)),e.oninput=t.onInput.bind(this,s,n),e.addEventListener("paste",(t=>{var e;t.preventDefault(),null!=(e=t.clipboardData)&&e.files.length&&i.addFilesToAnyType(Array.from(t.clipboardData.files))}))}static onKeyDown(e,i){const s=i.target.textContent;s&&s.length>=e&&!t.PERMITTED_KEYS.has(i.key)&&!t.isKeyCombinationPermitted(i)&&i.preventDefault()}static isKeyCombinationPermitted(t){return"a"===t.key&&(t.ctrlKey||t.metaKey)}static onInput(t,e,i){const s=i.target,n=s.textContent||"";void 0!==t&&n.length>t&&(s.textContent=n.substring(0,t),v.focusEndOfInput(s)),null==e||e()}};h.PERMITTED_KEYS=new Set([c.BACKSPACE,c.DELETE,c.ARROW_RIGHT,c.ARROW_LEFT,c.ARROW_DOWN,c.ARROW_UP,c.META,c.CONTROL,c.ENTER]);let u=h;class d{static sanitizePastedTextContent(t){var e,i;t.preventDefault();const s=null==(e=t.clipboardData)?void 0:e.getData("text/plain");s&&(null==(i=document.execCommand)||i.call(document,"insertText",!1,s))}}const p=class t{constructor(e,i,s){var n,o;const r=t.processConfig(i,e.textInput);this.elementRef=t.createContainerElement(null==(n=null==r?void 0:r.styles)?void 0:n.container),this._config=r,this.inputElementRef=this.createInputElement(),this.elementRef.appendChild(this.inputElementRef),e.setPlaceholderText=this.setPlaceholderText.bind(this),e.setPlaceholderText((null==(o=this._config.placeholder)?void 0:o.text)||"Ask me anything!"),setTimeout((()=>{u.add(this.inputElementRef,s,this._config.characterLimit,e._validationHandler)}))}static processConfig(t,e){var i;return e??(e={}),e.disabled??(e.disabled=t.isTextInputDisabled),e.placeholder??(e.placeholder={}),(i=e.placeholder).text??(i.text=t.textInputPlaceholderText),e}static createContainerElement(t){const e=document.createElement("div");return e.id="text-input-container",Object.assign(e.style,t),e}static preventAutomaticScrollUpOnNewLine(t){let e;t.addEventListener("keydown",(()=>{e=window.scrollY})),t.addEventListener("input",(()=>{e!==window.scrollY&&window.scrollTo({top:e})}))}clear(){var t;const e=window.scrollY;this.inputElementRef.classList.contains("text-input-disabled")||(Object.assign(this.inputElementRef.style,null==(t=this._config.placeholder)?void 0:t.style),this.inputElementRef.textContent="",v.focusEndOfInput(this.inputElementRef)),l.IS_CHROMIUM&&window.scrollTo({top:e})}createInputElement(){var e,i,s,n;const o=document.createElement("div");return o.id=t.TEXT_INPUT_ID,o.classList.add("text-input-styling"),l.IS_CHROMIUM&&t.preventAutomaticScrollUpOnNewLine(o),"boolean"==typeof this._config.disabled&&!0===this._config.disabled?(o.contentEditable="false",o.classList.add("text-input-disabled")):(o.contentEditable="true",this.addEventListeners(o)),Object.assign(o.style,null==(e=this._config.styles)?void 0:e.text),Object.assign(o.style,null==(i=this._config.placeholder)?void 0:i.style),null!=(n=null==(s=this._config.placeholder)?void 0:s.style)&&n.color||o.setAttribute("textcolor",""),o}removePlaceholderStyle(){var t,e,s,n;!this.inputElementRef.classList.contains("text-input-disabled")&&null!=(t=this._config.placeholder)&&t.style&&(i.unsetStyle(this.inputElementRef,null==(e=this._config.placeholder)?void 0:e.style),Object.assign(this.inputElementRef.style,null==(n=null==(s=this._config)?void 0:s.styles)?void 0:n.text))}addEventListeners(t){var e,i;null!=(e=this._config.styles)&&e.focus&&(t.onfocus=()=>{var t;return Object.assign(this.elementRef.style,null==(t=this._config.styles)?void 0:t.focus)},t.onblur=this.onBlur.bind(this,this._config.styles.focus,null==(i=this._config.styles)?void 0:i.container)),t.addEventListener("keydown",this.onKeydown.bind(this)),t.addEventListener("input",this.onInput.bind(this)),t.addEventListener("paste",d.sanitizePastedTextContent)}onBlur(t,e){i.unsetStyle(this.elementRef,t),e&&Object.assign(this.elementRef.style,e)}onKeydown(t){var e;t.key===c.ENTER&&!t.ctrlKey&&!t.shiftKey&&(t.preventDefault(),null==(e=this.submit)||e.call(this))}onInput(){var t;this.isTextInputEmpty()?Object.assign(this.inputElementRef.style,null==(t=this._config.placeholder)?void 0:t.style):this.removePlaceholderStyle()}setPlaceholderText(t){this.inputElementRef.setAttribute("deep-chat-placeholder-text",t)}isTextInputEmpty(){return""===this.inputElementRef.textContent}};p.TEXT_INPUT_ID="text-input";let m=p;class v{static focusEndOfInput(t){const e=document.createRange();e.selectNodeContents(t),e.collapse(!1);const i=window.getSelection();null==i||i.removeAllRanges(),null==i||i.addRange(e)}static focusFromParentElement(t){const e=t.querySelector(`#${m.TEXT_INPUT_ID}`);e&&(l.IS_SAFARI&&e.focus(),v.focusEndOfInput(e))}}function f(t){return t.charAt(0).toUpperCase()+t.slice(1)}function g(t,e,i,s){const n=`\n${f(e)} message: ${JSON.stringify(t)} \n`,o=i?`${f(e)} message after interceptor: ${function(t){return t&&JSON.stringify(t)}(s)} \n`:"";return n+o}const b="Make sure the events are using {text: string} or {html: string} format.\nYou can also augment them using the responseInterceptor property: https://deepchat.dev/docs/interceptors#responseInterceptor",y={INVALID_KEY:"Invalid API Key",CONNECTION_FAILED:"Failed to connect",INVALID_RESPONSE:function(t,e,i,s){return`${g(t,e,i,s)}Make sure the ${e} message is using the Response format: https://deepchat.dev/docs/connect/#Response \nYou can also augment it using the responseInterceptor property: https://deepchat.dev/docs/interceptors#responseInterceptor`},INVALID_MODEL_REQUEST:function(t,e){const i="request";return`${g(t,i,e)}Make sure the ${i} message is using the {body: {text: string}} format, e.g: {body: {text: "Model Response"}}`},INVALID_MODEL_RESPONSE:function(t,e,i){const s="response";return`${g(t,s,e,i)}Make sure the ${s} message is using the {text: string} format, e.g: {text: "Model Response"}`},INVALID_STREAM_EVENT:b,INVALID_STREAM_EVENT_MIX:"Cannot mix {text: string} and {html: string} responses.",NO_VALID_STREAM_EVENTS_SENT:`No valid stream events were sent.\n${b}`},w=class t{static addElements(t,...e){e.forEach((e=>t.appendChild(e)))}static isScrollbarAtBottomOfElement(e){const i=e.scrollHeight,s=e.clientHeight;return e.scrollTop>=i-s-t.CODE_SNIPPET_GENERATION_JUMP}static cloneElement(t){const e=t.cloneNode(!0);return t.parentNode.replaceChild(e,t),e}static scrollToBottom(t){t.scrollTop=t.scrollHeight}static scrollToTop(t){t.scrollTop=0}};w.CODE_SNIPPET_GENERATION_JUMP=.5;let x=w;const k=class t{static speak(t,e){if(window.SpeechSynthesisUtterance){const i=new SpeechSynthesisUtterance(t);Object.assign(i,e),speechSynthesis.speak(i)}}static processConfig(e,i){const s={};setTimeout((()=>{if("object"==typeof e&&(e.lang&&(s.lang=e.lang),e.pitch&&(s.pitch=e.pitch),e.rate&&(s.rate=e.rate),e.volume&&(s.volume=e.volume),e.voiceName)){const t=window.speechSynthesis.getVoices().find((t=>{var i;return t.name.toLocaleLowerCase()===(null==(i=e.voiceName)?void 0:i.toLocaleLowerCase())}));t&&(s.voice=t)}i(s)}),t.LOAD_VOICES_MS)}};k.LOAD_VOICES_MS=200;let _=k;const S=class t{static colorToHex(t){const e=document.createElement("div");return e.style.color=t,document.body.appendChild(e),`#${window.getComputedStyle(e).color.match(/\d+/g).map((t=>parseInt(t).toString(16).padStart(2,"0"))).join("")}`}static setDots(e,i){var s,n,o,r;if(null!=(r=null==(o=null==(n=null==(s=null==i?void 0:i.loading)?void 0:s.message)?void 0:n.styles)?void 0:o.bubble)&&r.color){const s=t.colorToHex(i.loading.message.styles.bubble.color);e.style.setProperty("--loading-message-color",s),e.style.setProperty("--loading-message-color-fade",`${s}33`)}else e.style.setProperty("--loading-message-color","#848484"),e.style.setProperty("--loading-message-color-fade","#55555533")}static setRing(e,i){const{color:s,width:n,height:o,margin:r,border:a}=i||{};if(s){const i=t.colorToHex(s);e.style.setProperty("--loading-history-color",i)}else e.style.setProperty("--loading-history-color","#dbdbdb");e.style.setProperty("--loading-history-height",o||"57px"),e.style.setProperty("--loading-history-width",n||"57px"),e.style.setProperty("--loading-history-margin",r||"7px"),e.style.setProperty("--loading-history-border",a||"6px solid")}};S.BUBBLE_CLASS="deep-chat-loading-message-bubble",S.DOTS_CONTAINER_CLASS="deep-chat-loading-message-dots-container";let T=S;const A=class t{static setElementProps(e,i,s,n){var o;"loading"!==s&&(e.applyCustomStyles(i,n,!0,null==(o=e.messageStyles)?void 0:o[s]),i.bubbleElement.classList.add(t.FILE_BUBBLE_CLASS))}static addMessage(e,i,s,n,o){t.setElementProps(e,i,s,n),o||(e.elementRef.appendChild(i.outerContainer),e.elementRef.scrollTop=e.elementRef.scrollHeight)}static wrapInLink(e,i,s){const n=document.createElement("a");return n.href=i,n.download=s||t.DEFAULT_FILE_NAME,n.target="_blank",n.appendChild(e),n}static isNonLinkableDataUrl(t,e){return!(!e.startsWith("data")||"image"===t)&&("any"===t&&e.startsWith("data:text/javascript")||!e.startsWith("data:image")&&!e.startsWith("data:application"))}static processContent(e,i,s,n){return!s||t.isNonLinkableDataUrl(e,s)?i:t.wrapInLink(i,s,n)}static waitToLoadThenScroll(t){setTimeout((()=>{t.scrollTop=t.scrollHeight}),60)}static scrollDownOnImageLoad(e,i){if(e.startsWith("data"))t.waitToLoadThenScroll(i);else try{fetch(e,{mode:"no-cors"}).catch((()=>{})).finally((()=>{t.waitToLoadThenScroll(i)}))}catch{i.scrollTop=i.scrollHeight}}static reAddFileRefToObject(t,e){var i;null==(i=t.files)||i.forEach(((t,i)=>{var s;t.ref&&null!=(s=e.message.files)&&s[i]&&(e.message.files[i].ref=t.ref)}))}static removeFileRef(t){const e={...t};return delete e.ref,e}static isAudioFile(t){const{type:e,src:i}=t;return"audio"===e||(null==i?void 0:i.startsWith("data:audio"))||i&&/\.(mp3|ogg|wav|aac|webm|4a)$/i.test(i)}static isImageFile(e){const{type:i,src:s}=e;return"image"===i||(null==s?void 0:s.startsWith("data:image"))||s&&t.isImageFileExtension(s)}static isImageFileExtension(t){return/\.(jpg|jpeg|png|gif|bmp)$/i.test(t)}};A.DEFAULT_FILE_NAME="file",A.FILE_BUBBLE_CLASS="file-message";let M=A;class C{static checkForContainerStyles(t,e){const i=t.containerStyle;i&&(Object.assign(e.style,i),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(t){return console.error("The {result: ....} response object type is deprecated since version 1.3.0."),console.error("Please change to using the new response object: https://deepchat.dev/docs/connect#Response"),t.result}static processHistory(t){const e=t.initialMessages;if(e)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"),e}static processHistoryFile(t){const e=t.file;e&&(console.error("The file property in MessageContent is deprecated since version 1.3.17."),console.error("Please change to using the files array property: https://deepchat.dev/docs/messages/#MessageContent"),t.files=[e])}static processValidateInput(t){const e=t.validateMessageBeforeSending;if(e)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"),e}static processSubmitUserMessage(t){return console.error("The submitUserMessage(text: string) argument string type is deprecated since version 1.4.4."),console.error("Please change to using the new argument type: https://deepchat.dev/docs/methods#submitUserMessage"),{text:t}}static flagHTMLUpdateClass(t){var e;null!=(e=t.children[0])&&e.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(t){const e=t;e.request&&(e.connect?Object.assign(e.connect,e.request):e.connect=e.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(t){const e=t.stream;if(e)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"),e}static fireOnNewMessage(t,e){var i;const s=t;s.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"),null==(i=s.onNewMessage)||i.call(s,e)),t.dispatchEvent(new CustomEvent("new-message",{detail:e}))}static processFileConfigConnect(t){const e=t;e.request&&(console.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"),e.connect||(e.connect=e.request))}static processMessageStyles(t){if(!t)return;const e=structuredClone(t),i=e.loading;return i&&(i.outerContainer||i.innerContainer||i.bubble||i.media)&&(console.error("The loading message styles are defined using LoadingMessageStyles interface since version 2.1.0."),console.error("Check it out here: https://deepchat.dev/docs/messages/styles#LoadingMessageStyles"),e.loading={message:{styles:i}}),e}static processDemo(t){return"boolean"==typeof t||t.displayLoadingBubble&&(console.error("The demo displayLoadingBubble property is deprecated since version 2.1.0."),console.error("Please use displayLoading instead: https://deepchat.dev/docs/demo#demo"),t.displayLoading={message:!0}),t}}class j{static mouseUp(t,e){i.unsetAllCSSMouseStates(t,e),Object.assign(t.style,e.default),Object.assign(t.style,e.hover)}static mouseDown(t,e){Object.assign(t.style,e.click)}static mouseLeave(t,e){i.unsetAllCSSMouseStates(t,e),Object.assign(t.style,e.default)}static mouseEnter(t,e){Object.assign(t.style,e.hover)}static add(t,e){t.addEventListener("mouseenter",j.mouseEnter.bind(this,t,e)),t.addEventListener("mouseleave",j.mouseLeave.bind(this,t,e)),t.addEventListener("mousedown",j.mouseDown.bind(this,t,e)),t.addEventListener("mouseup",j.mouseUp.bind(this,t,e))}}const O={"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"}}}},E=Object.keys(O);class I{static applySuggestionEvent(t,e){setTimeout((()=>{e.addEventListener("click",(()=>{var i,s;null==(s=t.submitUserMessage)||s.call(t,{text:(null==(i=e.textContent)?void 0:i.trim())||""})}))}))}static isElementTemporary(t){var e;return!!t&&(null==(e=t.bubbleElement.children[0])?void 0:e.classList.contains("deep-chat-temporary-message"))}static doesElementContainDeepChatClass(t){return E.find((e=>t.classList.contains(e)))}static applyEvents(t,e){const i=O[e].events;Object.keys(i||[]).forEach((e=>{t.addEventListener(e,null==i?void 0:i[e])}))}static getProcessedStyles(t,e,s){const n=Array.from(e.classList).reduce(((e,i)=>{var s;const n=null==(s=t[i])?void 0:s.styles;return n&&t[i].styles&&e.push(n),e}),[]),o=O[s].styles;if(o){const t=JSON.parse(JSON.stringify(o));t.default&&i.overwriteDefaultWithAlreadyApplied(t,e),n.unshift(t)}const r=i.mergeStatefulStyles(n);return i.processStateful(r,{},{})}static applyDeepChatUtilities(t,e,i){E.forEach((t=>{const s=i.getElementsByClassName(t);Array.from(s||[]).forEach((i=>{const s=I.getProcessedStyles(e,i,t);P.applyStylesToElement(i,s),I.applyEvents(i,t)}))}));const s=i.getElementsByClassName("deep-chat-suggestion-button");Array.from(s).forEach((e=>I.applySuggestionEvent(t,e)))}}class P{static applyStylesToElement(t,e){const s=i.processStateful(e,{},{});j.add(t,s),Object.assign(t.style,s.default)}static applyEventsToElement(t,e){Object.keys(e).forEach((i=>{const s=e[i];s&&t.addEventListener(i,s)}))}static applyClassUtilitiesToElement(t,e){const{events:i,styles:s}=e;i&&P.applyEventsToElement(t,i),s&&!I.doesElementContainDeepChatClass(t)&&P.applyStylesToElement(t,s)}static applyCustomClassUtilities(t,e){Object.keys(t).forEach((i=>{const s=e.getElementsByClassName(i);Array.from(s).forEach((e=>{t[i]&&P.applyClassUtilitiesToElement(e,t[i])}))}))}static apply(t,e){I.applyDeepChatUtilities(t,t.htmlClassUtilities,e),P.applyCustomClassUtilities(t.htmlClassUtilities,e)}static traverseNodes(t,e){t.nodeType===Node.ELEMENT_NODE&&e.push(t.outerHTML),t.childNodes.forEach((t=>{P.traverseNodes(t,e)}))}static splitHTML(t){const e=(new DOMParser).parseFromString(t,"text/html"),i=[];return e.body.childNodes.forEach((t=>{P.traverseNodes(t,i)})),i}}const N=class t{static addElement(t,e){t.elementRef.appendChild(e),t.elementRef.scrollTop=t.elementRef.scrollHeight}static createElements(e,i,s,n){const o=e.createMessageElementsOnOrientation("",s,n);return o.bubbleElement.classList.add(t.HTML_BUBBLE_CLASS),o.bubbleElement.innerHTML=i,o}static overwriteElements(t,e,i){i.bubbleElement.innerHTML=e,P.apply(t,i.outerContainer),C.flagHTMLUpdateClass(i.bubbleElement)}static overwrite(e,i,s,n){const{messageToElements:o}=e,r=we.overwriteMessage(o,n,i,s,"html",t.HTML_BUBBLE_CLASS);return r&&t.overwriteElements(e,i,r),r}static create(e,i,s,n=!1){var o;const r=t.createElements(e,i,s,n);return we.fillEmptyMessageElement(r.bubbleElement,i),P.apply(e,r.outerContainer),C.flagHTMLUpdateClass(r.bubbleElement),e.applyCustomStyles(r,s,!1,null==(o=e.messageStyles)?void 0:o.html),r}static add(e,i,s,n,o,r=!1){if(null!=o&&o.status){const t=this.overwrite(e,i,s,n);if(t)return t;o.status=!1}const a=t.create(e,i,s,r);return r||t.addElement(e,a.outerContainer),a}};N.HTML_BUBBLE_CLASS="html-message";let q=N;var R;function L(t){return(R=R||document.createElement("textarea")).innerHTML="&"+t+";",R.value}var B=Object.prototype.hasOwnProperty;function F(t){return[].slice.call(arguments,1).forEach((function(e){if(e){if("object"!=typeof e)throw new TypeError(e+"must be object");Object.keys(e).forEach((function(i){t[i]=e[i]}))}})),t}var z=/\\([\\!"#$%&'()*+,.\/:;<=>?@[\]^_`{|}~-])/g;function D(t){return t.indexOf("\\")<0?t:t.replace(z,"$1")}function $(t){return!(t>=55296&&t<=57343||t>=64976&&t<=65007||!(65535&~t)||65534==(65535&t)||t>=0&&t<=8||11===t||t>=14&&t<=31||t>=127&&t<=159||t>1114111)}function J(t){if(t>65535){var e=55296+((t-=65536)>>10),i=56320+(1023&t);return String.fromCharCode(e,i)}return String.fromCharCode(t)}var U=/&([a-z#][a-z0-9]{1,31});/gi,V=/^#((?:x[a-f0-9]{1,8}|[0-9]{1,8}))/i;function H(t,e){var i=0,s=L(e);return e!==s?s:35===e.charCodeAt(0)&&V.test(e)&&$(i="x"===e[1].toLowerCase()?parseInt(e.slice(2),16):parseInt(e.slice(1),10))?J(i):t}function K(t){return t.indexOf("&")<0?t:t.replace(U,H)}var G=/[&<>"]/,Z=/[&<>"]/g,W={"&":"&","<":"<",">":">",'"':"""};function X(t){return W[t]}function Q(t){return G.test(t)?t.replace(Z,X):t}var Y={};function tt(t,e){return++e>=t.length-2?e:"paragraph_open"===t[e].type&&t[e].tight&&"inline"===t[e+1].type&&0===t[e+1].content.length&&"paragraph_close"===t[e+2].type&&t[e+2].tight?tt(t,e+2):e}Y.blockquote_open=function(){return"<blockquote>\n"},Y.blockquote_close=function(t,e){return"</blockquote>"+et(t,e)},Y.code=function(t,e){return t[e].block?"<pre><code>"+Q(t[e].content)+"</code></pre>"+et(t,e):"<code>"+Q(t[e].content)+"</code>"},Y.fence=function(t,e,i,s,n){var o,r,a=t[e],l="",c=i.langPrefix;if(a.params){if(r=(o=a.params.split(/\s+/g)).join(" "),function(t,e){return!!t&&B.call(t,e)}(n.rules.fence_custom,o[0]))return n.rules.fence_custom[o[0]](t,e,i,s,n);l=' class="'+c+Q(K(D(r)))+'"'}return"<pre><code"+l+">"+(i.highlight&&i.highlight.apply(i.highlight,[a.content].concat(o))||Q(a.content))+"</code></pre>"+et(t,e)},Y.fence_custom={},Y.heading_open=function(t,e){return"<h"+t[e].hLevel+">"},Y.heading_close=function(t,e){return"</h"+t[e].hLevel+">\n"},Y.hr=function(t,e,i){return(i.xhtmlOut?"<hr />":"<hr>")+et(t,e)},Y.bullet_list_open=function(){return"<ul>\n"},Y.bullet_list_close=function(t,e){return"</ul>"+et(t,e)},Y.list_item_open=function(){return"<li>"},Y.list_item_close=function(){return"</li>\n"},Y.ordered_list_open=function(t,e){var i=t[e];return"<ol"+(i.order>1?' start="'+i.order+'"':"")+">\n"},Y.ordered_list_close=function(t,e){return"</ol>"+et(t,e)},Y.paragraph_open=function(t,e){return t[e].tight?"":"<p>"},Y.paragraph_close=function(t,e){var i=!(t[e].tight&&e&&"inline"===t[e-1].type&&!t[e-1].content);return(t[e].tight?"":"</p>")+(i?et(t,e):"")},Y.link_open=function(t,e,i){var s=t[e].title?' title="'+Q(K(t[e].title))+'"':"",n=i.linkTarget?' target="'+i.linkTarget+'"':"";return'<a href="'+Q(t[e].href)+'"'+s+n+">"},Y.link_close=function(){return"</a>"},Y.image=function(t,e,i){var s=' src="'+Q(t[e].src)+'"',n=t[e].title?' title="'+Q(K(t[e].title))+'"':"";return"<img"+s+(' alt="'+(t[e].alt?Q(K(D(t[e].alt))):"")+'"')+n+(i.xhtmlOut?" /":"")+">"},Y.table_open=function(){return"<table>\n"},Y.table_close=function(){return"</table>\n"},Y.thead_open=function(){return"<thead>\n"},Y.thead_close=function(){return"</thead>\n"},Y.tbody_open=function(){return"<tbody>\n"},Y.tbody_close=function(){return"</tbody>\n"},Y.tr_open=function(){return"<tr>"},Y.tr_close=function(){return"</tr>\n"},Y.th_open=function(t,e){var i=t[e];return"<th"+(i.align?' style="text-align:'+i.align+'"':"")+">"},Y.th_close=function(){return"</th>"},Y.td_open=function(t,e){var i=t[e];return"<td"+(i.align?' style="text-align:'+i.align+'"':"")+">"},Y.td_close=function(){return"</td>"},Y.strong_open=function(){return"<strong>"},Y.strong_close=function(){return"</strong>"},Y.em_open=function(){return"<em>"},Y.em_close=function(){return"</em>"},Y.del_open=function(){return"<del>"},Y.del_close=function(){return"</del>"},Y.ins_open=function(){return"<ins>"},Y.ins_close=function(){return"</ins>"},Y.mark_open=function(){return"<mark>"},Y.mark_close=function(){return"</mark>"},Y.sub=function(t,e){return"<sub>"+Q(t[e].content)+"</sub>"},Y.sup=function(t,e){return"<sup>"+Q(t[e].content)+"</sup>"},Y.hardbreak=function(t,e,i){return i.xhtmlOut?"<br />\n":"<br>\n"},Y.softbreak=function(t,e,i){return i.breaks?i.xhtmlOut?"<br />\n":"<br>\n":"\n"},Y.text=function(t,e){return Q(t[e].content)},Y.htmlblock=function(t,e){return t[e].content},Y.htmltag=function(t,e){return t[e].content},Y.abbr_open=function(t,e){return'<abbr title="'+Q(K(t[e].title))+'">'},Y.abbr_close=function(){return"</abbr>"},Y.footnote_ref=function(t,e){var i=Number(t[e].id+1).toString(),s="fnref"+i;return t[e].subId>0&&(s+=":"+t[e].subId),'<sup class="footnote-ref"><a href="#fn'+i+'" id="'+s+'">['+i+"]</a></sup>"},Y.footnote_block_open=function(t,e,i){return(i.xhtmlOut?'<hr class="footnotes-sep" />\n':'<hr class="footnotes-sep">\n')+'<section class="footnotes">\n<ol class="footnotes-list">\n'},Y.footnote_block_close=function(){return"</ol>\n</section>\n"},Y.footnote_open=function(t,e){return'<li id="fn'+Number(t[e].id+1).toString()+'" class="footnote-item">'},Y.footnote_close=function(){return"</li>\n"},Y.footnote_anchor=function(t,e){var i="fnref"+Number(t[e].id+1).toString();return t[e].subId>0&&(i+=":"+t[e].subId),' <a href="#'+i+'" class="footnote-backref">↩</a>'},Y.dl_open=function(){return"<dl>\n"},Y.dt_open=function(){return"<dt>"},Y.dd_open=function(){return"<dd>"},Y.dl_close=function(){return"</dl>\n"},Y.dt_close=function(){return"</dt>\n"},Y.dd_close=function(){return"</dd>\n"};var et=Y.getBreak=function(t,e){return(e=tt(t,e))<t.length&&"list_item_close"===t[e].type?"":"\n"};function it(){this.rules=F({},Y),this.getBreak=Y.getBreak}function st(){this.t=[],this.i=null}function nt(t,e,i,s,n){this.src=t,this.env=s,this.options=i,this.parser=e,this.tokens=n,this.pos=0,this.posMax=this.src.length,this.level=0,this.pending="",this.pendingLevel=0,this.cache=[],this.isInLabel=!1,this.linkLevel=0,this.linkContent="",this.labelUnmatchedScopes=0}function ot(t,e){var i,s,n,o=-1,r=t.posMax,a=t.pos,l=t.isInLabel;if(t.isInLabel)return-1;if(t.labelUnmatchedScopes)return t.labelUnmatchedScopes--,-1;for(t.pos=e+1,t.isInLabel=!0,i=1;t.pos<r;){if(91===(n=t.src.charCodeAt(t.pos)))i++;else if(93===n&&0===--i){s=!0;break}t.parser.skipToken(t)}return s?(o=t.pos,t.labelUnmatchedScopes=0):t.labelUnmatchedScopes=i-1,t.pos=a,t.isInLabel=l,o}function rt(t,e,i,s){var n,o,r,a,l,c;if(42!==t.charCodeAt(0)||91!==t.charCodeAt(1)||-1===t.indexOf("]:")||((o=ot(n=new nt(t,e,i,s,[]),1))<0||58!==t.charCodeAt(o+1)))return-1;for(a=n.posMax,r=o+2;r<a&&10!==n.src.charCodeAt(r);r++);return l=t.slice(2,o),0===(c=t.slice(o+2,r).trim()).length?-1:(s.abbreviations||(s.abbreviations={}),typeof s.abbreviations[":"+l]>"u"&&(s.abbreviations[":"+l]=c),r)}function at(t){var e=K(t);try{e=decodeURI(e)}catch{}return encodeURI(e)}function lt(t,e){var i,s,n,o=e,r=t.posMax;if(60===t.src.charCodeAt(e)){for(e++;e<r;){if(10===(i=t.src.charCodeAt(e)))return!1;if(62===i)return n=at(D(t.src.slice(o+1,e))),!!t.parser.validateLink(n)&&(t.pos=e+1,t.linkContent=n,!0);92===i&&e+1<r?e+=2:e++}return!1}for(s=0;e<r&&!(32===(i=t.src.charCodeAt(e))||i<32||127===i);)if(92===i&&e+1<r)e+=2;else{if(40===i&&++s>1||41===i&&--s<0)break;e++}return!(o===e||(n=D(t.src.slice(o,e)),!t.parser.validateLink(n)))&&(t.linkContent=n,t.pos=e,!0)}function ct(t,e){var i,s=e,n=t.posMax,o=t.src.charCodeAt(e);if(34!==o&&39!==o&&40!==o)return!1;for(e++,40===o&&(o=41);e<n;){if((i=t.src.charCodeAt(e))===o)return t.pos=e+1,t.linkContent=D(t.src.slice(s+1,e)),!0;92===i&&e+1<n?e+=2:e++}return!1}function ht(t){return t.trim().replace(/\s+/g," ").toUpperCase()}function ut(t,e,i,s){var n,o,r,a,l,c,h,u,d;if(91!==t.charCodeAt(0)||-1===t.indexOf("]:")||((o=ot(n=new nt(t,e,i,s,[]),0))<0||58!==t.charCodeAt(o+1)))return-1;for(a=n.posMax,r=o+2;r<a&&(32===(l=n.src.charCodeAt(r))||10===l);r++);if(!lt(n,r))return-1;for(h=n.linkContent,c=r=n.pos,r+=1;r<a&&(32===(l=n.src.charCodeAt(r))||10===l);r++);for(r<a&&c!==r&&ct(n,r)?(u=n.linkContent,r=n.pos):(u="",r=c);r<a&&32===n.src.charCodeAt(r);)r++;return r<a&&10!==n.src.charCodeAt(r)?-1:(d=ht(t.slice(1,o)),typeof s.references[d]>"u"&&(s.references[d]={title:u,href:h}),r)}it.prototype.renderInline=function(t,e,i){for(var s=this.rules,n=t.length,o=0,r="";n--;)r+=s[t[o].type](t,o++,e,i,this);return r},it.prototype.render=function(t,e,i){for(var s=this.rules,n=t.length,o=-1,r="";++o<n;)"inline"===t[o].type?r+=this.renderInline(t[o].children,e,i):r+=s[t[o].type](t,o,e,i,this);return r},st.prototype.o=function(t){for(var e=this.t.length,i=-1;e--;)if(this.t[++i].name===t)return i;return-1},st.prototype.l=function(){var t=this,e=[""];t.t.forEach((function(t){t.enabled&&t.alt.forEach((function(t){e.indexOf(t)<0&&e.push(t)}))})),t.i={},e.forEach((function(e){t.i[e]=[],t.t.forEach((function(i){i.enabled&&(e&&i.alt.indexOf(e)<0||t.i[e].push(i.fn))}))}))},st.prototype.at=function(t,e,i){var s=this.o(t),n=i||{};if(-1===s)throw new Error("Parser rule not found: "+t);this.t[s].fn=e,this.t[s].alt=n.alt||[],this.i=null},st.prototype.before=function(t,e,i,s){var n=this.o(t),o=s||{};if(-1===n)throw new Error("Parser rule not found: "+t);this.t.splice(n,0,{name:e,enabled:!0,fn:i,alt:o.alt||[]}),this.i=null},st.prototype.after=function(t,e,i,s){var n=this.o(t),o=s||{};if(-1===n)throw new Error("Parser rule not found: "+t);this.t.splice(n+1,0,{name:e,enabled:!0,fn:i,alt:o.alt||[]}),this.i=null},st.prototype.push=function(t,e,i){var s=i||{};this.t.push({name:t,enabled:!0,fn:e,alt:s.alt||[]}),this.i=null},st.prototype.enable=function(t,e){t=Array.isArray(t)?t:[t],e&&this.t.forEach((function(t){t.enabled=!1})),t.forEach((function(t){var e=this.o(t);if(e<0)throw new Error("Rules manager: invalid rule name "+t);this.t[e].enabled=!0}),this),this.i=null},st.prototype.disable=function(t){(t=Array.isArray(t)?t:[t]).forEach((function(t){var e=this.o(t);if(e<0)throw new Error("Rules manager: invalid rule name "+t);this.t[e].enabled=!1}),this),this.i=null},st.prototype.getRules=function(t){return null===this.i&&this.l(),this.i[t]||[]},nt.prototype.pushPending=function(){this.tokens.push({type:"text",content:this.pending,level:this.pendingLevel}),this.pending=""},nt.prototype.push=function(t){this.pending&&this.pushPending(),this.tokens.push(t),this.pendingLevel=this.level},nt.prototype.cacheSet=function(t,e){for(var i=this.cache.length;i<=t;i++)this.cache.push(0);this.cache[t]=e},nt.prototype.cacheGet=function(t){return t<this.cache.length?this.cache[t]:0};var dt=" \n()[]'\".,!?-";function pt(t){return t.replace(/([-()\[\]{}+?*.$\^|,:#<!\\])/g,"\\$1")}var mt=/\+-|\.\.|\?\?\?\?|!!!!|,,|--/,vt=/\((c|tm|r|p)\)/gi,ft={c:"©",r:"®",p:"§",tm:"™"};function gt(t){return t.indexOf("(")<0?t:t.replace(vt,(function(t,e){return ft[e.toLowerCase()]}))}var bt=/['"]/,yt=/['"]/g,wt=/[-\s()\[\]]/;function xt(t,e){return!(e<0||e>=t.length)&&!wt.test(t[e])}function kt(t,e,i){return t.substr(0,e)+i+t.substr(e+1)}var _t=[["block",function(t){t.inlineMode?t.tokens.push({type:"inline",content:t.src.replace(/\n/g," ").trim(),level:0,lines:[0,1],children:[]}):t.block.parse(t.src,t.options,t.env,t.tokens)}],["abbr",function(t){var e,i,s,n,o=t.tokens;if(!t.inlineMode)for(e=1,i=o.length-1;e<i;e++)if("paragraph_open"===o[e-1].type&&"inline"===o[e].type&&"paragraph_close"===o[e+1].type){for(s=o[e].content;s.length&&!((n=rt(s,t.inline,t.options,t.env))<0);)s=s.slice(n).trim();o[e].content=s,s.length||(o[e-1].tight=!0,o[e+1].tight=!0)}}],["references",function(t){var e,i,s,n,o=t.tokens;if(t.env.references=t.env.references||{},!t.inlineMode)for(e=1,i=o.length-1;e<i;e++)if("inline"===o[e].type&&"paragraph_open"===o[e-1].type&&"paragraph_close"===o[e+1].type){for(s=o[e].content;s.length&&!((n=ut(s,t.inline,t.options,t.env))<0);)s=s.slice(n).trim();o[e].content=s,s.length||(o[e-1].tight=!0,o[e+1].tight=!0)}}],["inline",function(t){var e,i,s,n=t.tokens;for(i=0,s=n.length;i<s;i++)"inline"===(e=n[i]).type&&t.inline.parse(e.content,t.options,t.env,e.children)}],["footnote_tail",function(t){var e,i,s,n,o,r,a,l,c,h=0,u=!1,d={};if(t.env.footnotes&&(t.tokens=t.tokens.filter((function(t){return"footnote_reference_open"===t.type?(u=!0,l=[],c=t.label,!1):"footnote_reference_close"===t.type?(u=!1,d[":"+c]=l,!1):(u&&l.push(t),!u)})),t.env.footnotes.list)){for(r=t.env.footnotes.list,t.tokens.push({type:"footnote_block_open",level:h++}),e=0,i=r.length;e<i;e++){for(t.tokens.push({type:"footnote_open",id:e,level:h++}),r[e].tokens?((a=[]).push({type:"paragraph_open",tight:!1,level:h++}),a.push({type:"inline",content:"",level:h,children:r[e].tokens}),a.push({type:"paragraph_close",tight:!1,level:--h})):r[e].label&&(a=d[":"+r[e].label]),t.tokens=t.tokens.concat(a),o="paragraph_close"===t.tokens[t.tokens.length-1].type?t.tokens.pop():null,n=r[e].count>0?r[e].count:1,s=0;s<n;s++)t.tokens.push({type:"footnote_anchor",id:e,subId:s,level:h});o&&t.tokens.push(o),t.tokens.push({type:"footnote_close",level:--h})}t.tokens.push({type:"footnote_block_close",level:--h})}}],["abbr2",function(t){var e,i,s,n,o,r,a,l,c,h,u,d,p=t.tokens;if(t.env.abbreviations)for(t.env.abbrRegExp||(d="(^|["+dt.split("").map(pt).join("")+"])("+Object.keys(t.env.abbreviations).map((function(t){return t.substr(1)})).sort((function(t,e){return e.length-t.length})).map(pt).join("|")+")($|["+dt.split("").map(pt).join("")+"])",t.env.abbrRegExp=new RegExp(d,"g")),h=t.env.abbrRegExp,i=0,s=p.length;i<s;i++)if("inline"===p[i].type)for(e=(n=p[i].children).length-1;e>=0;e--)if("text"===(o=n[e]).type){for(l=0,r=o.content,h.lastIndex=0,c=o.level,a=[];u=h.exec(r);)h.lastIndex>l&&a.push({type:"text",content:r.slice(l,u.index+u[1].length),level:c}),a.push({type:"abbr_open",title:t.env.abbreviations[":"+u[2]],level:c++}),a.push({type:"text",content:u[2],level:c}),a.push({type:"abbr_close",level:--c}),l=h.lastIndex-u[3].length;a.length&&(l<r.length&&a.push({type:"text",content:r.slice(l),level:c}),p[i].children=n=[].concat(n.slice(0,e),a,n.slice(e+1)))}}],["replacements",function(t){var e,i,s,n,o;if(t.options.typographer)for(o=t.tokens.length-1;o>=0;o--)if("inline"===t.tokens[o].type)for(e=(n=t.tokens[o].children).length-1;e>=0;e--)"text"===(i=n[e]).type&&(s=gt(s=i.content),mt.test(s)&&(s=s.replace(/\+-/g,"±").replace(/\.{2,}/g,"…").replace(/([?!])…/g,"$1..").replace(/([?!]){4,}/g,"$1$1$1").replace(/,{2,}/g,",").replace(/(^|[^-])---([^-]|$)/gm,"$1—$2").replace(/(^|\s)--(\s|$)/gm,"$1–$2").replace(/(^|[^-\s])--([^-\s]|$)/gm,"$1–$2")),i.content=s)}],["smartquotes",function(t){var e,i,s,n,o,r,a,l,c,h,u,d,p,m,v,f,g;if(t.options.typographer)for(g=[],v=t.tokens.length-1;v>=0;v--)if("inline"===t.tokens[v].type)for(f=t.tokens[v].children,g.length=0,e=0;e<f.length;e++)if("text"===(i=f[e]).type&&!bt.test(i.text)){for(a=f[e].level,p=g.length-1;p>=0&&!(g[p].level<=a);p--);g.length=p+1,o=0,r=(s=i.content).length;t:for(;o<r&&(yt.lastIndex=o,n=yt.exec(s),n);)if(l=!xt(s,n.index-1),o=n.index+1,m="'"===n[0],(c=!xt(s,o))||l){if(u=!c,d=!l)for(p=g.length-1;p>=0&&(h=g[p],!(g[p].level<a));p--)if(h.single===m&&g[p].level===a){h=g[p],m?(f[h.token].content=kt(f[h.token].content,h.pos,t.options.quotes[2]),i.content=kt(i.content,n.index,t.options.quotes[3])):(f[h.token].content=kt(f[h.token].content,h.pos,t.options.quotes[0]),i.content=kt(i.content,n.index,t.options.quotes[1])),g.length=p;continue t}u?g.push({token:e,pos:n.index,single:m,level:a}):d&&m&&(i.content=kt(i.content,n.index,"’"))}else m&&(i.content=kt(i.content,n.index,"’"))}}]];function St(){this.options={},this.ruler=new st;for(var t=0;t<_t.length;t++)this.ruler.push(_t[t][0],_t[t][1])}function Tt(t,e,i,s,n){var o,r,a,l,c,h,u;for(this.src=t,this.parser=e,this.options=i,this.env=s,this.tokens=n,this.bMarks=[],this.eMarks=[],this.tShift=[],this.blkIndent=0,this.line=0,this.lineMax=0,this.tight=!1,this.parentType="root",this.ddIndent=-1,this.level=0,this.result="",h=0,u=!1,a=l=h=0,c=(r=this.src).length;l<c;l++){if(o=r.charCodeAt(l),!u){if(32===o){h++;continue}u=!0}(10===o||l===c-1)&&(10!==o&&l++,this.bMarks.push(a),this.eMarks.push(l),this.tShift.push(h),u=!1,h=0,a=l+1)}this.bMarks.push(r.length),this.eMarks.push(r.length),this.tShift.push(0),this.lineMax=this.bMarks.length-1}function At(t,e){var i,s,n;return(s=t.bMarks[e]+t.tShift[e])>=(n=t.eMarks[e])||42!==(i=t.src.charCodeAt(s++))&&45!==i&&43!==i||s<n&&32!==t.src.charCodeAt(s)?-1:s}function Mt(t,e){var i,s=t.bMarks[e]+t.tShift[e],n=t.eMarks[e];if(s+1>=n||((i=t.src.charCodeAt(s++))<48||i>57))return-1;for(;;){if(s>=n)return-1;if(!((i=t.src.charCodeAt(s++))>=48&&i<=57)){if(41===i||46===i)break;return-1}}return s<n&&32!==t.src.charCodeAt(s)?-1:s}St.prototype.process=function(t){var e,i,s;for(e=0,i=(s=this.ruler.getRules("")).length;e<i;e++)s[e](t)},Tt.prototype.isEmpty=function(t){return this.bMarks[t]+this.tShift[t]>=this.eMarks[t]},Tt.prototype.skipEmptyLines=function(t){for(var e=this.lineMax;t<e&&!(this.bMarks[t]+this.tShift[t]<this.eMarks[t]);t++);return t},Tt.prototype.skipSpaces=function(t){for(var e=this.src.length;t<e&&32===this.src.charCodeAt(t);t++);return t},Tt.prototype.skipChars=function(t,e){for(var i=this.src.length;t<i&&this.src.charCodeAt(t)===e;t++);return t},Tt.prototype.skipCharsBack=function(t,e,i){if(t<=i)return t;for(;t>i;)if(e!==this.src.charCodeAt(--t))return t+1;return t},Tt.prototype.getLines=function(t,e,i,s){var n,o,r,a,l,c=t;if(t>=e)return"";if(c+1===e)return o=this.bMarks[c]+Math.min(this.tShift[c],i),r=s?this.eMarks[c]+1:this.eMarks[c],this.src.slice(o,r);for(a=new Array(e-t),n=0;c<e;c++,n++)(l=this.tShift[c])>i&&(l=i),l<0&&(l=0),o=this.bMarks[c]+l,r=c+1<e||s?this.eMarks[c]+1:this.eMarks[c],a[n]=this.src.slice(o,r);return a.join("")};var Ct={};["article","aside","button","blockquote","body","canvas","caption","col","colgroup","dd","div","dl","dt","embed","fieldset","figcaption","figure","footer","form","h1","h2","h3","h4","h5","h6","header","hgroup","hr","iframe","li","map","object","ol","output","p","pre","progress","script","section","style","table","tbody","td","textarea","tfoot","th","tr","thead","ul","video"].forEach((function(t){Ct[t]=!0}));var jt=/^<([a-zA-Z]{1,15})[\s\/>]/,Ot=/^<\/([a-zA-Z]{1,15})[\s>]/;function Et(t,e){var i=t.bMarks[e]+t.blkIndent,s=t.eMarks[e];return t.src.substr(i,s-i)}function It(t,e){var i,s,n=t.bMarks[e]+t.tShift[e],o=t.eMarks[e];return n>=o||126!==(s=t.src.charCodeAt(n++))&&58!==s||n===(i=t.skipSpaces(n))||i>=o?-1:i}var Pt=[["code",function(t,e,i){var s,n;if(t.tShift[e]-t.blkIndent<4)return!1;for(n=s=e+1;s<i;)if(t.isEmpty(s))s++;else{if(!(t.tShift[s]-t.blkIndent>=4))break;n=++s}return t.line=s,t.tokens.push({type:"code",content:t.getLines(e,n,4+t.blkIndent,!0),block:!0,lines:[e,t.line],level:t.level}),!0}],["fences",function(t,e,i,s){var n,o,r,a,l,c=!1,h=t.bMarks[e]+t.tShift[e],u=t.eMarks[e];if(h+3>u||126!==(n=t.src.charCodeAt(h))&&96!==n||(l=h,(o=(h=t.skipChars(h,n))-l)<3)||(r=t.src.slice(h,u).trim()).indexOf("`")>=0)return!1;if(s)return!0;for(a=e;!(++a>=i||(h=l=t.bMarks[a]+t.tShift[a],u=t.eMarks[a],h<u&&t.tShift[a]<t.blkIndent));)if(!(t.src.charCodeAt(h)!==n||t.tShift[a]-t.blkIndent>=4||(h=t.skipChars(h,n),h-l<o||(h=t.skipSpaces(h),h<u)))){c=!0;break}return o=t.tShift[e],t.line=a+(c?1:0),t.tokens.push({type:"fence",params:r,content:t.getLines(e+1,a,o,!0),lines:[e,t.line],level:t.level}),!0},["paragraph","blockquote","list"]],["blockquote",function(t,e,i,s){var n,o,r,a,l,c,h,u,d,p,m,v=t.bMarks[e]+t.tShift[e],f=t.eMarks[e];if(v>f||62!==t.src.charCodeAt(v++)||t.level>=t.options.maxNesting)return!1;if(s)return!0;for(32===t.src.charCodeAt(v)&&v++,l=t.blkIndent,t.blkIndent=0,a=[t.bMarks[e]],t.bMarks[e]=v,o=(v=v<f?t.skipSpaces(v):v)>=f,r=[t.tShift[e]],t.tShift[e]=v-t.bMarks[e],u=t.parser.ruler.getRules("blockquote"),n=e+1;n<i&&!((v=t.bMarks[n]+t.tShift[n])>=(f=t.eMarks[n]));n++)if(62!==t.src.charCodeAt(v++)){if(o)break;for(m=!1,d=0,p=u.length;d<p;d++)if(u[d](t,n,i,!0)){m=!0;break}if(m)break;a.push(t.bMarks[n]),r.push(t.tShift[n]),t.tShift[n]=-1337}else 32===t.src.charCodeAt(v)&&v++,a.push(t.bMarks[n]),t.bMarks[n]=v,o=(v=v<f?t.skipSpaces(v):v)>=f,r.push(t.tShift[n]),t.tShift[n]=v-t.bMarks[n];for(c=t.parentType,t.parentType="blockquote",t.tokens.push({type:"blockquote_open",lines:h=[e,0],level:t.level++}),t.parser.tokenize(t,e,n),t.tokens.push({type:"blockquote_close",level:--t.level}),t.parentType=c,h[1]=t.line,d=0;d<r.length;d++)t.bMarks[d+e]=a[d],t.tShift[d+e]=r[d];return t.blkIndent=l,!0},["paragraph","blockquote","list"]],["hr",function(t,e,i,s){var n,o,r,a=t.bMarks[e],l=t.eMarks[e];if((a+=t.tShift[e])>l||42!==(n=t.src.charCodeAt(a++))&&45!==n&&95!==n)return!1;for(o=1;a<l;){if((r=t.src.charCodeAt(a++))!==n&&32!==r)return!1;r===n&&o++}return!(o<3)&&(s||(t.line=e+1,t.tokens.push({type:"hr",lines:[e,t.line],level:t.level})),!0)},["paragraph","blockquote","list"]],["list",function(t,e,i,s){var n,o,r,a,l,c,h,u,d,p,m,v,f,g,b,y,w,x,k,_,S,T=!0;if((u=Mt(t,e))>=0)v=!0;else{if(!((u=At(t,e))>=0))return!1;v=!1}if(t.level>=t.options.maxNesting)return!1;if(m=t.src.charCodeAt(u-1),s)return!0;for(g=t.tokens.length,v?(h=t.bMarks[e]+t.tShift[e],p=Number(t.src.substr(h,u-h-1)),t.tokens.push({type:"ordered_list_open",order:p,lines:y=[e,0],level:t.level++})):t.tokens.push({type:"bullet_list_open",lines:y=[e,0],level:t.level++}),n=e,b=!1,x=t.parser.ruler.getRules("list");n<i&&((d=(f=t.skipSpaces(u))>=t.eMarks[n]?1:f-u)>4&&(d=1),d<1&&(d=1),o=u-t.bMarks[n]+d,t.tokens.push({type:"list_item_open",lines:w=[e,0],level:t.level++}),a=t.blkIndent,l=t.tight,r=t.tShift[e],c=t.parentType,t.tShift[e]=f-t.bMarks[e],t.blkIndent=o,t.tight=!0,t.parentType="list",t.parser.tokenize(t,e,i,!0),(!t.tight||b)&&(T=!1),b=t.line-e>1&&t.isEmpty(t.line-1),t.blkIndent=a,t.tShift[e]=r,t.tight=l,t.parentType=c,t.tokens.push({type:"list_item_close",level:--t.level}),n=e=t.line,w[1]=n,f=t.bMarks[e],!(n>=i||t.isEmpty(n)||t.tShift[n]<t.blkIndent));){for(S=!1,k=0,_=x.length;k<_;k++)if(x[k](t,n,i,!0)){S=!0;break}if(S)break;if(v){if((u=Mt(t,n))<0)break}else if((u=At(t,n))<0)break;if(m!==t.src.charCodeAt(u-1))break}return t.tokens.push({type:v?"ordered_list_close":"bullet_list_close",level:--t.level}),y[1]=n,t.line=n,T&&function(t,e){var i,s,n=t.level+2;for(i=e+2,s=t.tokens.length-2;i<s;i++)t.tokens[i].level===n&&"paragraph_open"===t.tokens[i].type&&(t.tokens[i+2].tight=!0,t.tokens[i].tight=!0,i+=2)}(t,g),!0},["paragraph","blockquote"]],["footnote",function(t,e,i,s){var n,o,r,a,l,c=t.bMarks[e]+t.tShift[e],h=t.eMarks[e];if(c+4>h||91!==t.src.charCodeAt(c)||94!==t.src.charCodeAt(c+1)||t.level>=t.options.maxNesting)return!1;for(a=c+2;a<h;a++){if(32===t.src.charCodeAt(a))return!1;if(93===t.src.charCodeAt(a))break}return!(a===c+2||a+1>=h||58!==t.src.charCodeAt(++a))&&(s||(a++,t.env.footnotes||(t.env.footnotes={}),t.env.footnotes.refs||(t.env.footnotes.refs={}),l=t.src.slice(c+2,a-2),t.env.footnotes.refs[":"+l]=-1,t.tokens.push({type:"footnote_reference_open",label:l,level:t.level++}),n=t.bMarks[e],o=t.tShift[e],r=t.parentType,t.tShift[e]=t.skipSpaces(a)-a,t.bMarks[e]=a,t.blkIndent+=4,t.parentType="footnote",t.tShift[e]<t.blkIndent&&(t.tShift[e]+=t.blkIndent,t.bMarks[e]-=t.blkIndent),t.parser.tokenize(t,e,i,!0),t.parentType=r,t.blkIndent-=4,t.tShift[e]=o,t.bMarks[e]=n,t.tokens.push({type:"footnote_reference_close",level:--t.level})),!0)},["paragraph"]],["heading",function(t,e,i,s){var n,o,r,a=t.bMarks[e]+t.tShift[e],l=t.eMarks[e];if(a>=l||(35!==(n=t.src.charCodeAt(a))||a>=l))return!1;for(o=1,n=t.src.charCodeAt(++a);35===n&&a<l&&o<=6;)o++,n=t.src.charCodeAt(++a);return!(o>6||a<l&&32!==n)&&(s||(l=t.skipCharsBack(l,32,a),(r=t.skipCharsBack(l,35,a))>a&&32===t.src.charCodeAt(r-1)&&(l=r),t.line=e+1,t.tokens.push({type:"heading_open",hLevel:o,lines:[e,t.line],level:t.level}),a<l&&t.tokens.push({type:"inline",content:t.src.slice(a,l).trim(),level:t.level+1,lines:[e,t.line],children:[]}),t.tokens.push({type:"heading_close",hLevel:o,level:t.level})),!0)},["paragraph","blockquote"]],["lheading",function(t,e,i){var s,n,o,r=e+1;return!(r>=i||t.tShift[r]<t.blkIndent||t.tShift[r]-t.blkIndent>3||(n=t.bMarks[r]+t.tShift[r],o=t.eMarks[r],n>=o)||(s=t.src.charCodeAt(n),45!==s&&61!==s)||(n=t.skipChars(n,s),n=t.skipSpaces(n),n<o))&&(n=t.bMarks[e]+t.tShift[e],t.line=r+1,t.tokens.push({type:"heading_open",hLevel:61===s?1:2,lines:[e,t.line],level:t.level}),t.tokens.push({type:"inline",content:t.src.slice(n,t.eMarks[e]).trim(),level:t.level+1,lines:[e,t.line-1],children:[]}),t.tokens.push({type:"heading_close",hLevel:61===s?1:2,level:t.level}),!0)}],["htmlblock",function(t,e,i,s){var n,o,r,a=t.bMarks[e],l=t.eMarks[e],c=t.tShift[e];if(a+=c,!t.options.html||c>3||a+2>=l||60!==t.src.charCodeAt(a))return!1;if(33===(n=t.src.charCodeAt(a+1))||63===n){if(s)return!0}else{if(47!==n&&!function(t){var e=32|t;return e>=97&&e<=122}(n))return!1;if(47===n){if(!(o=t.src.slice(a,l).match(Ot)))return!1}else if(!(o=t.src.slice(a,l).match(jt)))return!1;if(!0!==Ct[o[1].toLowerCase()])return!1;if(s)return!0}for(r=e+1;r<t.lineMax&&!t.isEmpty(r);)r++;return t.line=r,t.tokens.push({type:"htmlblock",level:t.level,lines:[e,t.line],content:t.getLines(e,r,0,!0)}),!0},["paragraph","blockquote"]],["table",function(t,e,i,s){var n,o,r,a,l,c,h,u,d,p,m;if(e+2>i||(l=e+1,t.tShift[l]<t.blkIndent)||(r=t.bMarks[l]+t.tShift[l])>=t.eMarks[l]||124!==(n=t.src.charCodeAt(r))&&45!==n&&58!==n||(o=Et(t,e+1),!/^[-:| ]+$/.test(o))||(c=o.split("|"))<=2)return!1;for(u=[],a=0;a<c.length;a++){if(!(d=c[a].trim())){if(0===a||a===c.length-1)continue;return!1}if(!/^:?-+:?$/.test(d))return!1;58===d.charCodeAt(d.length-1)?u.push(58===d.charCodeAt(0)?"center":"right"):58===d.charCodeAt(0)?u.push("left"):u.push("")}if(-1===(o=Et(t,e).trim()).indexOf("|")||(c=o.replace(/^\||\|$/g,"").split("|"),u.length!==c.length))return!1;if(s)return!0;for(t.tokens.push({type:"table_open",lines:p=[e,0],level:t.level++}),t.tokens.push({type:"thead_open",lines:[e,e+1],level:t.level++}),t.tokens.push({type:"tr_open",lines:[e,e+1],level:t.level++}),a=0;a<c.length;a++)t.tokens.push({type:"th_open",align:u[a],lines:[e,e+1],level:t.level++}),t.tokens.push({type:"inline",content:c[a].trim(),lines:[e,e+1],level:t.level,children:[]}),t.tokens.push({type:"th_close",level:--t.level});for(t.tokens.push({type:"tr_close",level:--t.level}),t.tokens.push({type:"thead_close",level:--t.level}),t.tokens.push({type:"tbody_open",lines:m=[e+2,0],level:t.level++}),l=e+2;l<i&&!(t.tShift[l]<t.blkIndent||(o=Et(t,l).trim(),-1===o.indexOf("|")));l++){for(c=o.replace(/^\||\|$/g,"").split("|"),t.tokens.push({type:"tr_open",level:t.level++}),a=0;a<c.length;a++)t.tokens.push({type:"td_open",align:u[a],level:t.level++}),h=c[a].substring(124===c[a].charCodeAt(0)?1:0,124===c[a].charCodeAt(c[a].length-1)?c[a].length-1:c[a].length).trim(),t.tokens.push({type:"inline",content:h,level:t.level,children:[]}),t.tokens.push({type:"td_close",level:--t.level});t.tokens.push({type:"tr_close",level:--t.level})}return t.tokens.push({type:"tbody_close",level:--t.level}),t.tokens.push({type:"table_close",level:--t.level}),p[1]=m[1]=l,t.line=l,!0},["paragraph"]],["deflist",function(t,e,i,s){var n,o,r,a,l,c,h,u,d,p,m,v,f,g;if(s)return!(t.ddIndent<0)&&It(t,e)>=0;if(h=e+1,t.isEmpty(h)&&++h>i||t.tShift[h]<t.blkIndent||(n=It(t,h))<0||t.level>=t.options.maxNesting)return!1;c=t.tokens.length,t.tokens.push({type:"dl_open",lines:l=[e,0],level:t.level++}),r=e,o=h;t:for(;;){for(g=!0,f=!1,t.tokens.push({type:"dt_open",lines:[r,r],level:t.level++}),t.tokens.push({type:"inline",content:t.getLines(r,r+1,t.blkIndent,!1).trim(),level:t.level+1,lines:[r,r],children:[]}),t.tokens.push({type:"dt_close",level:--t.level});;){if(t.tokens.push({type:"dd_open",lines:a=[h,0],level:t.level++}),v=t.tight,d=t.ddIndent,u=t.blkIndent,m=t.tShift[o],p=t.parentType,t.blkIndent=t.ddIndent=t.tShift[o]+2,t.tShift[o]=n-t.bMarks[o],t.tight=!0,t.parentType="deflist",t.parser.tokenize(t,o,i,!0),(!t.tight||f)&&(g=!1),f=t.line-o>1&&t.isEmpty(t.line-1),t.tShift[o]=m,t.tight=v,t.parentType=p,t.blkIndent=u,t.ddIndent=d,t.tokens.push({type:"dd_close",level:--t.level}),a[1]=h=t.line,h>=i||t.tShift[h]<t.blkIndent)break t;if((n=It(t,h))<0)break;o=h}if(h>=i||(r=h,t.isEmpty(r))||t.tShift[r]<t.blkIndent||(o=r+1)>=i||(t.isEmpty(o)&&o++,o>=i)||t.tShift[o]<t.blkIndent||(n=It(t,o))<0)break}return t.tokens.push({type:"dl_close",level:--t.level}),l[1]=h,t.line=h,g&&function(t,e){var i,s,n=t.level+2;for(i=e+2,s=t.tokens.length-2;i<s;i++)t.tokens[i].level===n&&"paragraph_open"===t.tokens[i].type&&(t.tokens[i+2].tight=!0,t.tokens[i].tight=!0,i+=2)}(t,c),!0},["paragraph"]],["paragraph",function(t,e){var i,s,n,o,r,a,l=e+1;if(l<(i=t.lineMax)&&!t.isEmpty(l))for(a=t.parser.ruler.getRules("paragraph");l<i&&!t.isEmpty(l);l++)if(!(t.tShift[l]-t.blkIndent>3)){for(n=!1,o=0,r=a.length;o<r;o++)if(a[o](t,l,i,!0)){n=!0;break}if(n)break}return s=t.getLines(e,l,t.blkIndent,!1).trim(),t.line=l,s.length&&(t.tokens.push({type:"paragraph_open",tight:!1,lines:[e,t.line],level:t.level}),t.tokens.push({type:"inline",co