UNPKG

@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.

1,191 lines 944 kB
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); class r0 { static render(e, t) { const r = document.createElement("div"); r.id = "error-view", r.innerText = t, e.replaceChildren(r); } } class Xi { 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 = Xi.createElements(), s = { onSuccess: t, onFail: r0.render.bind(this, e, "Your 'key' has failed authentication"), onLoad: Xi.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 Xt = class Xt { static attemptAppendStyleSheetToHead(e) { if (e.fontFamily && e.fontFamily !== Xt.DEFAULT_FONT_FAMILY) return; const t = document.getElementsByTagName("head")[0]; if (!Array.from(t.getElementsByTagName("link")).some( (i) => i.getAttribute("href") === Xt.FONT_URL )) { const i = document.createElement("link"); i.rel = "stylesheet", i.href = Xt.FONT_URL, t.appendChild(i); } } }; Xt.FONT_URL = "https://fonts.googleapis.com/css2?family=Inter:wght@400;600&display=swap", Xt.DEFAULT_FONT_FAMILY = "'Inter', sans-serif, Avenir, Helvetica, Arial"; let es = Xt; const Pn = class Pn { static apply(e, t) { if (t) try { Pn.applyStyleSheet(e, t); } catch { Pn.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, Pn.DEFAULT_COMPONENT_STYLE); } }; Pn.DEFAULT_COMPONENT_STYLE = { height: "350px", width: "320px", border: "1px solid #cacaca", fontFamily: es.DEFAULT_FONT_FAMILY, fontSize: "0.9rem", backgroundColor: "white", position: "relative", // this is used to prevent inputAreaStyle background color from going beyond the container's rounded border // it will cause issues if there are elements that are meant to be outside of the chat component and in // that instance they should overwrite this overflow: "hidden" }; let Or = Pn; var St = /* @__PURE__ */ ((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))(St || {}); const Qr = class Qr { }; Qr.IS_SAFARI = /^((?!chrome|android).)*safari/i.test(navigator.userAgent), Qr.IS_CHROMIUM = window.chrome, Qr.IS_MOBILE = /Android|webOS|iPhone|iPad|iPod|BlackBerry|IEMobile|Opera Mini/i.test( navigator.userAgent ); let pn = Qr; 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 en = class en { constructor(e, t, r) { var s, o; const i = en.processConfig(t, e.textInput); this.elementRef = en.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; } // this is is a bug fix where if the browser is scrolled down and the user types in text that creates new line // the browser scrollbar will move up which leads to undesirable UX. // More details in this Stack Overflow question: // https://stackoverflow.com/questions/76285135/prevent-automatic-scroll-when-text-is-inserted-into-contenteditable-div // prettier-ignore 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; } // this also similarly prevents scroll up 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 = en.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"), pn.IS_CHROMIUM && en.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 === St.ENTER && !e.ctrlKey && !e.shiftKey && !pn.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 === ""; } }; en.TEXT_INPUT_ID = "text-input"; let ts = en; class wa { 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(`#${ts.TEXT_INPUT_ID}`); t && wa.focusEndOfInput(t); } } function Cu(n) { return n.charAt(0).toUpperCase() + n.slice(1); } function s0(n) { return n && JSON.stringify(n); } function Sa(n, e, t, r) { const i = ` ${Cu(e)} message: ${JSON.stringify(n)} `, s = t ? `${Cu(e)} message after interceptor: ${s0(r)} ` : ""; return i + s; } function o0(n, e, t, r) { return `${Sa(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 `${Sa(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 `${Sa(n, t, e)}Make sure the ${t} message is using the {body: {text: string}} format, e.g: {body: {text: "Model Response"}}`; } const Au = `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: Au, INVALID_STREAM_EVENT_MIX: "Cannot mix {text: string} and {html: string} responses.", NO_VALID_STREAM_EVENTS_SENT: `No valid stream events were sent. ${Au}` }, Ms = class Ms { 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 - Ms.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; } }; Ms.CODE_SNIPPET_GENERATION_JUMP = 0.5; let Ae = Ms; const Rs = class Rs { 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); }, Rs.LOAD_VOICES_MS); } }; Rs.LOAD_VOICES_MS = 200; let zn = Rs; class Ve { 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")); } // eslint-disable-next-line @typescript-eslint/no-explicit-any 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 Fn = class Fn { 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 = Fn.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 = Fn.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"); } }; Fn.BUBBLE_CLASS = "deep-chat-loading-message-bubble", Fn.DOTS_CONTAINER_CLASS = "deep-chat-loading-message-dots-container"; let Ct = Fn; 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,iVBORw0KGgoAAAANSUhEUgAAAPoAAAD6CAMAAAC/MqoPAAAABGdBTUEAALGPC/xhBQAAAAFzUkdCAK7OHOkAAAAgY0hSTQAAeiYAAICEAAD6AAAAgOgAAHUwAADqYAAAOpgAABdwnLpRPAAAADNQTFRF////9vX18vLy/Pz86enp4+Li2tnZ1tbWzczM+fn57Ozs4N/f09LS0M/P5uXl7+/v3dzcwtncCAAAAAFiS0dEAIgFHUgAAAAJcEhZcwAAAEgAAABIAEbJaz4AAAZNSURBVHja7d3bdtsqEABQYABZSLH9/3+ZpnUsIcF5iOM6PfElNoMHMfPQdq3GmL0GkLhEUqLaUExnOtOZznSmM53pTGc605nOdKYznelMZzrTmV4LXSqllKyJDkob26xWq8Zae/iH0QoWTm9d1xur4WuypQJtTd+5dqn0VjcxzNO5/57mEBvdLo8Oron6aseWOjYOFkVvjQs3DmgyONMuht52EfztP+4hdu0i6LCO808/M8c1lE/fuPGej41uUzgdtoO/75N+2ELJ9I3b3//hPXbiMenm3pR/Jt4USgcLBIp4Bh10gqKVhvLo0klCxeSky96nKcj3siw6pJIL4XsoiQ7apyvMY/V3HHrSRioLopvEhSpTCn2TPEuwKYMOIX0tAxRBf/Hpa+lfSqBv9gi1FPsNfTrMAiVmIE/vJhz61FGnQxRIEYE4vfNYdN8Rp6MlHaHotHTn8ejekaZPAjEmyvQWdZFTtYTpXqCGJ0zvcek9Yfoel76nS0ffv1NMp1ca+pkgyfRCGind4L7OWWc605l+cxjsyhqy9AGbPpClc1/nvl5VX0c/3Alk6RU3+Am7shNZ+h6bvidLr7jBB+zKBrL0irOOudmIUDzTmf5gIP+iEuXtRuTVaEmY/oZLfyNMrzjryPc0gerMTdpVg0tvjJUU6bLPcGOoUv46SLL6Wi8yhLf06C7TUyekI0efRaaYqdFltkeNpPumRPSMDxgBYvSM035FrKAmH72hRW99PrpvSdEHkTEGUvSsK3yKVDkuJ92RohcZaehzzirPpOg+J92Tolfc4Cumx5xVXpGiZ34+ICX6W84qv5GiR5NPbiIpOv6BCoSvSkTX+eiaGP092zINvBOj4x8mSf9FqejvNo/cvpOji19ZbmviL0GPLsYMFzgzCor0+Bv/ePDvSJKOb9dJ5UlnbnEHiHgzv6cdTpJOWuc/u3FEucLDOL75xGtBiefrcwgoC9NDSH/jkH6pAuXmBqPQ9HSUPVdZBH1GGOrMXAQdYxcKZfxAoK+KKBKFLosoEoX+u4giUehz8jlcnAuhp78I46yDYNAd+QLR6K+pr+yvxdBTHyVDubQh0UfSxaHSd0lbvNkVRE87JGOtc+PQd2QLQ6fHhJkKsSh6yg13tO08JPprsgrrXWH0dJd2vH1MLPprot4eXoujpzrdhngiD40ek2y92lggPcnWa8qN1Yz0BFuvZhRl0uOfR0v4Ewuli/Bg4Qr3lArqGdndQ3UPO1EunXYwnelMZzrTmc50pjOd6UxnOtOZznSmM53pTGf6kuj6oedFKV0s3fX6sX1S3bsi6a4PD7+/YAqYeBw6pIB/4qEgOqxdSPbGiim4NRRCbzs3Jj0L4UfXtQXQVRfn5IdA/Bw7RZzurEV6EtdsLeGXkIPuA+K1UoVeA0l62zmN/LqfSSft9KkepmoRuvi3nd5uKNFB9zbbXEANqdr941XO0NJx2v2jdJenpf+/3bvn0ts16ph+sd6hX7dPo2+2cZzE02Ia43bzDHqr+2Evnhz74ZHU30ffbKOeng1/NPV30Ns1gYQnSP2P6e65Pfxc6h02XZqXQCjhJ6kPL6bFo4NrGvAU4UII4SE2P1vQuZkuOxckVfehisF1MjUddN/MZBN+kvq5uf0O/xa66gyNS9ktMWlz44rO1Z8C19i5FPdHzPamXn+F3hryPfxMr78+4F+kq22kO6Rf6fUQt+puuustyWv4rbG3l/duztFB96GYoe1cTBdXMr+nw9qVM6ZfxOvzezff0nXi/ZOndvrR6Zvpm0c3h6nhdb+5iS7tsIim/qXZD9+97/Jf+rpZ5BET1ayv0GUzLhEuhBBjIy/RdVPgndutIRt9nt7p5cKFEEJ3Z+jQFDZL+XnMDXxHB73gxn5s9Kc3d3/pFciFkN/QTSXHJpX5l66gDrkQoP6hL3xsPw39la4qOiV8tH78XeSbue6N9mvWa6J/ybpc1CT1Wnh5Qq9meP8IOKH3ddH7E/ri1iYux/SXDrXR4UiPdck/wUpU+FtPf6/orja6O9KL3l56LOvVxe5Ib2qjN0d6Vbex4ghWlU3bPqI90If66MNng680FNpbJijH6kCvaF3uMzQ3+IrpFerV4Y9dffQdN3im10ivbuImhD3Qq5u4HdZkua8znelMZ/pS4z9CPVKkxowNxgAAACV0RVh0ZGF0ZTpjcmVhdGUAMjAxNy0wMy0yN1QxNTo0NToxNSswMDowMN1xSg4AAAAldEVYdGRhdGU6bW9kaWZ5ADIwMTctMDMtMjdUMTU6NDU6MTUrMDA6MDCsLPKyAAAAGXRFWHRTb2Z0d2FyZQBBZG9iZSBJbWFnZVJlYWR5ccllPAAAAABJRU5ErkJggg==", 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 Pr = De; const rt = class rt { static hide(e) { var t; (t = e.getElementsByClassName(rt.NAME_CLASS)[0].style).visibility || (t.visibility = "hidden"); } static reveal(e) { e.getElementsByClassName(rt.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(rt.NAME_CLASS), r.textContent = rt.getNameText(e, t), rt.applyStyle(r, e, t), r; } static add(e, t, r) { const i = typeof r == "boolean" ? {} : r, s = rt.createName(t, i), o = rt.getPosition(t, i); s.classList.add(o === "left" ? "left-item-position" : "right-item-position"), e.insertAdjacentElement(o === "left" ? "beforebegin" : "afterend", s); } }; rt.NAME_CLASS = "name"; let Fr = rt; const Ke = class Ke { 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]; } // IMPORTANT: If the overwrite message does not contain a role property it will look for the last 'ai' role message // and if messages have custom roles, it will still look to update the last 'ai' role message // prettier-ignore static overwriteMessage(e, t, r, i, s, o) { const a = Ke.getLastElementsByClass( t, [Ke.getRoleClass(i), o], [Ct.BUBBLE_CLASS] ), u = Ke.getLastMessage(e, i, s); return u && (u[s] = r), a; } static getRoleClass(e) { return `${e}-message`; } // makes sure the bubble has dimensions when there is no text static fillEmptyMessageElement(e, t) { t.trim().length === 0 && (e.classList.add(Ke.EMPTY_MESSAGE_CLASS), e.innerHTML = '<div style="color:#00000000">.</div>'); } static unfillEmptyMessageElement(e, t) { e.classList.contains(Ke.EMPTY_MESSAGE_CLASS) && t.trim().length > 0 && e.replaceChildren(); } static getLastMessageBubbleElement(e) { var t, r, i; return Array.from(((i = (r = (t = Ke.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 && Pr.add(e, t, r), i && Fr.add(e, t, i); } static hideRoleElements(e, t, r) { const i = e[e.length - 1].innerContainer; t && Pr.hide(i), r && Fr.hide(i); } static revealRoleElements(e, t, r) { t && Pr.reveal(e), r && Fr.reveal(e); } static updateRefArr(e, t, r) { r ? e.unshift(t) : e.push(t); } }; Ke.AI_ROLE = "ai", Ke.USER_ROLE = "user", Ke.EMPTY_MESSAGE_CLASS = "empty-message"; let O = Ke; class rn { 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", rn.mouseEnter.bind(this, e, t)), e.addEventListener("mouseleave", rn.mouseLeave.bind(this, e, t)), e.addEventListener("mousedown", rn.mouseDown.bind(this, e, t)), e.addEventListener("mouseup", rn.mouseUp.bind(this, e, t)); } } const d0 = "deep-chat-temporary-message", h0 = "deep-chat-suggestion-button", Bo = { "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" } } } }, ku = Object.keys(Bo); class At { 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 ku.find((t) => e.classList.contains(t)); } static applyEvents(e, t) { const r = Bo[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 = Bo[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) { ku.forEach((s) => { const o = r.getElementsByClassName(s); Array.from(o || []).forEach((a) => { const u = At.getProcessedStyles(t, a, s); Be.applyStylesToElement(a, u), At.applyEvents(a, s); }); }); const i = r.getElementsByClassName(h0); Array.from(i).forEach((s) => At.applySuggestionEvent(e, s)); } } class Be { static applyStylesToElement(e, t) { const r = ie.processStateful(t, {}, {}); rn.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 && !At.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) { At.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 zt { 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), Ve.flagHTMLUpdateClass(o.bubbleElement)), o; } // prettier-ignore 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 = zt.createElements(e, t, r, o); return O.fillEmptyMessageElement(a.bubbleElement, t), Be.apply(e, a.outerContainer), Ve.flagHTMLUpdateClass(a.bubbleElement), e.applyCustomStyles(a, r, !1, (u = e.messageStyles) == null ? void 0 : u.html), o || zt.addElement(e, a.outerContainer), a; } } var Bi; function ql(n) { return Bi = Bi || document.createElement("textarea"), Bi.innerHTML = "&" + n + ";", Bi.value; } var f0 = Object.prototype.hasOwnProperty; function p0(n, e) { return n ? f0.call(n, e) : !1; } function Hl(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 Xr(n) { return n.indexOf("\\") < 0 ? n : n.replace(m0, "$1"); } function jl(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 $o(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 = ql(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), jl(t)) ? $o(t) : n; } function mn(n) { return n.indexOf("&") < 0 ? n : n.replace(g0, v0); } var y0 = /[&<>"]/, _0 = /[&<>"]/g, x0 = { "&": "&amp;", "<": "&lt;", ">": "&gt;", '"': "&quot;" }; 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>" + xn(n, e); }; M.code = function(n, e) { return n[e].block ? "<pre><code>" + Ie(n[e].content) + "</code></pre>" + xn(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(mn(Xr(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>" + xn(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>") + xn(n, e); }; M.bullet_list_open = function() { return `<ul> `; }; M.bullet_list_close = function(n, e) { return "</ul>" + xn(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>" + xn(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 ? xn(n, e) : ""); }; M.link_open = function(n, e, t) { var r = n[e].title ? ' title="' + Ie(mn(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(mn(n[e].title)) + '"' : "", s = ' alt="' + (n[e].alt ? Ie(mn(Xr(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(mn(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 Gl(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 ? Gl(n, e + 2) : e; } var xn = M.getBreak = function(e, t) { return t = Gl(e, t), t < e.length && e[t].type === "list_item_close" ? "" : ` `; }; function Ca() { this.rules = Hl({}, M), this.getBreak = M.getBreak; } Ca.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; }; Ca.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 ze() { this.__rules__ = [], this.__cache__ = null; } ze.prototype.__find__ = function(n) { for (var e = this.__rules__.length, t = -1; e--; ) if (this.__rules__[++t].name === n) return t; return -1; }; ze.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)); }); }); }; ze.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; }; ze.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; }; ze.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; }; ze.prototype.push = function(n, e, t) { var r = t || {}; this.__rules__.push({ name: n, enabled: !0, fn: e, alt: r.alt || [] }), this.__cache__ = null; }; ze.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; }; ze.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; }; ze.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 En(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; } En.prototype.pushPending = function() { this.tokens.push({ type: "text", content: this.pending, level: this.pendingLevel }), this.pending = ""; }; En.prototype.push = function(n) { this.pending && this.pushPending(), this.tokens.push(n), this.pendingLevel = this.level; }; En.prototype.cacheSet = function(n, e) { for (var t = this.cache.length; t <= n; t++) this.cache.push(0); this.cache[n] = e; }; En.prototype.cacheGet = function(n) { return n < this.cache.length ? this.cache[n] : 0; }; function ei(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 En(n, e, t, r, []), s = ei(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 Uo(n) { var e = mn(n); try { e = decodeURI(e); } catch { } return encodeURI(e); } function Vl(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 = Uo(Xr(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 = Xr(n.src.slice(s, e)), !n.parser.validateLink(i)) ? !1 : (n.linkContent = i, n.pos = e, !0); } function Wl(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 = Xr(n.src.slice(r + 1, e)), !0; if (t === 92 && e + 1 < i) { e += 2; continue; } e++; } return !1; } function Kl(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 En(n, e, t, r, []), s = ei(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 (!Vl(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 && Wl(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 = Kl(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_blo