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,193 lines 1.16 MB
var fT = Object.defineProperty; var pT = (r, e, t) => e in r ? fT(r, e, { enumerable: !0, configurable: !0, writable: !0, value: t }) : r[e] = t; var _ = (r, e, t) => pT(r, typeof e != "symbol" ? e + "" : e, t); class mT { static render(e, t) { const n = document.createElement("div"); n.id = "error-view", n.innerText = t, e.replaceChildren(n); } } class dc { static onLoad(e) { e.innerHTML = '<div id="loading-validate-key-property"></div>'; } static createElements() { const e = document.createElement("div"); return e.id = "validate-property-key-view", e; } static render(e, t, n) { const i = dc.createElements(), s = { onSuccess: t, onFail: mT.render.bind(this, e, "Your 'key' has failed authentication"), onLoad: dc.onLoad.bind(this, i) }; n.key && n.verifyKey(n.key, s), e.replaceChildren(i); } } class Se { static unsetStyle(e, t) { const n = Object.keys(t).reduce((i, s) => (i[s] = "", i), {}); Object.assign(e.style, n); } static unsetActivityCSSMouseStates(e, t) { t.click && Se.unsetStyle(e, t.click), t.hover && Se.unsetStyle(e, t.hover); } static unsetAllCSSMouseStates(e, t) { Se.unsetActivityCSSMouseStates(e, t), t.default && Se.unsetStyle(e, t.default); } static processStateful(e, t, n) { const i = e.default || {}, s = Object.assign(JSON.parse(JSON.stringify({ ...i, ...t })), e == null ? void 0 : e.hover), o = Object.assign(JSON.parse(JSON.stringify({ ...s, ...n })), e == null ? void 0 : e.click); return { default: i, hover: s, click: o }; } static mergeStatefulStyles(e) { const t = { default: {}, hover: {}, click: {} }; return e.forEach((n) => { t.default = Object.assign(t.default, n.default), t.hover = Object.assign(t.hover, n.hover), t.click = Object.assign(t.click, n.click); }), t; } static overwriteDefaultWithAlreadyApplied(e, t) { Object.keys(e.default || []).forEach((n) => { var s; const i = n; t.style[i] && (s = e.default) != null && s[i] && (e.default[n] = t.style[i]); }); } static applyToStyleIfNotDefined(e, t) { for (const n in t) { const i = t[n]; e[n] === "" && i && (e[n] = i); } } } const rn = class rn { static attemptAppendStyleSheetToHead(e) { if (e.fontFamily && e.fontFamily !== rn.DEFAULT_FONT_FAMILY) return; const t = document.getElementsByTagName("head")[0]; if (!Array.from(t.getElementsByTagName("link")).some( (i) => i.getAttribute("href") === rn.FONT_URL )) { const i = document.createElement("link"); i.rel = "stylesheet", i.href = rn.FONT_URL, t.appendChild(i); } } }; rn.FONT_URL = "https://fonts.googleapis.com/css2?family=Inter:wght@400;600&display=swap", rn.DEFAULT_FONT_FAMILY = "'Inter', sans-serif, Avenir, Helvetica, Arial"; let hc = rn; const Fn = class Fn { static apply(e, t) { if (t) try { Fn.applyStyleSheet(e, t); } catch { Fn.addStyleElement(e, t); } } static applyStyleSheet(e, t) { const n = new CSSStyleSheet(); n.replaceSync(e), t.adoptedStyleSheets.push(n); } static addStyleElement(e, t) { const n = document.createElement("style"); n.innerHTML = e, t.appendChild(n); } static applyDefaultStyleToComponent(e, t) { t && Se.applyToStyleIfNotDefined(e, t), Se.applyToStyleIfNotDefined(e, Fn.DEFAULT_COMPONENT_STYLE); } }; Fn.DEFAULT_COMPONENT_STYLE = { height: "350px", width: "320px", border: "1px solid #cacaca", fontFamily: hc.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 Uo = Fn; var Yt = /* @__PURE__ */ ((r) => (r.ESCAPE = "Escape", r.ENTER = "Enter", r.TAB = "Tab", r.ARROW_UP = "ArrowUp", r.ARROW_DOWN = "ArrowDown", r.ARROW_RIGHT = "ArrowRight", r.ARROW_LEFT = "ArrowLeft", r.BACKSPACE = "Backspace", r.DELETE = "Delete", r.META = "Meta", r.CONTROL = "Control", r))(Yt || {}); const Xo = class Xo { }; Xo.IS_SAFARI = /^((?!chrome|android).)*safari/i.test(navigator.userAgent), Xo.IS_CHROMIUM = window.chrome, Xo.IS_MOBILE = /Android|webOS|iPhone|iPad|iPod|BlackBerry|IEMobile|Opera Mini/i.test( navigator.userAgent ); let En = Xo; class _T { static sanitizePastedTextContent(e) { var n, i; e.preventDefault(); const t = (n = e.clipboardData) == null ? void 0 : n.getData("text/plain"); t && ((i = document.execCommand) == null || i.call(document, "insertText", !1, t)); } } const nn = class nn { constructor(e, t, n) { var s, o; const i = nn.processConfig(t, e.textInput); this.elementRef = nn.createContainerElement((s = i == null ? void 0 : i.styles) == null ? void 0 : s.container), this._config = i, this.inputElementRef = this.createInputElement(), this.elementRef.appendChild(this.inputElementRef), e.setPlaceholderText = this.setPlaceholderText.bind(this), e.setPlaceholderText(((o = this._config.placeholder) == null ? void 0 : o.text) || "Ask me anything!"); } static processConfig(e, t) { var n; return t ?? (t = {}), t.disabled ?? (t.disabled = e.isTextInputDisabled), t.placeholder ?? (t.placeholder = {}), (n = t.placeholder).text ?? (n.text = e.textInputPlaceholderText), t; } static createContainerElement(e) { const t = document.createElement("div"); return t.id = "text-input-container", Object.assign(t.style, e), t; } // 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, n, i, s; const e = document.createElement("div"); return e.id = nn.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"), En.IS_CHROMIUM && nn.preventAutomaticScrollUpOnNewLine(e), typeof this._config.disabled == "boolean" && this._config.disabled === !0 ? (e.contentEditable = "false", e.classList.add("text-input-disabled"), e.setAttribute("aria-disabled", "true")) : (e.contentEditable = "true", e.setAttribute("aria-disabled", "false"), this.addEventListeners(e)), Object.assign(e.style, (t = this._config.styles) == null ? void 0 : t.text), Object.assign(e.style, (n = this._config.placeholder) == null ? void 0 : n.style), (s = (i = this._config.placeholder) == null ? void 0 : i.style) != null && s.color || e.setAttribute("textcolor", ""), e; } removePlaceholderStyle() { var e, t, n, i; !this.inputElementRef.classList.contains("text-input-disabled") && ((e = this._config.placeholder) != null && e.style) && (Se.unsetStyle(this.inputElementRef, (t = this._config.placeholder) == null ? void 0 : t.style), Object.assign(this.inputElementRef.style, (i = (n = this._config) == null ? void 0 : n.styles) == null ? void 0 : i.text)); } addEventListeners(e) { var t, n; (t = this._config.styles) != null && t.focus && (e.onfocus = () => { var i; Object.assign(this.elementRef.style, (i = this._config.styles) == null ? void 0 : i.focus); }, e.onblur = this.onBlur.bind(this, this._config.styles.focus, (n = this._config.styles) == null ? void 0 : n.container)), e.addEventListener("keydown", this.onKeydown.bind(this)), e.addEventListener("input", this.onInput.bind(this)), e.addEventListener("paste", _T.sanitizePastedTextContent); } onBlur(e, t) { Se.unsetStyle(this.elementRef, e), t && Object.assign(this.elementRef.style, t); } blur() { this.inputElementRef.blur(); } onKeydown(e) { var t; e.key === Yt.ENTER && !e.ctrlKey && !e.shiftKey && !En.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 === ""; } }; nn.TEXT_INPUT_ID = "text-input"; let fc = nn; class dd { static focusEndOfInput(e) { const t = document.createRange(); t.selectNodeContents(e), t.collapse(!1); const n = window.getSelection(); n == null || n.removeAllRanges(), n == null || n.addRange(t); } static focusFromParentElement(e) { const t = e.querySelector(`#${fc.TEXT_INPUT_ID}`); t && dd.focusEndOfInput(t); } } function V0(r) { return r.charAt(0).toUpperCase() + r.slice(1); } function gT(r) { return r && JSON.stringify(r); } function hd(r, e, t, n) { const i = ` ${V0(e)} message: ${JSON.stringify(r)} `, s = t ? `${V0(e)} message after interceptor: ${gT(n)} ` : ""; return i + s; } function ET(r, e, t, n) { return `${hd(r, e, t, n)}Make sure the ${e} message is using the Response format: https://deepchat.dev/docs/connect/#Response You can also augment it using the responseInterceptor property: https://deepchat.dev/docs/interceptors#responseInterceptor`; } function ST(r, e, t) { const n = "response"; return `${hd(r, n, e, t)}Make sure the ${n} message is using the {text: string} format, e.g: {text: "Model Response"}`; } function TT(r, e) { const t = "request"; return `${hd(r, t, e)}Make sure the ${t} message is using the {body: {text: string}} format, e.g: {body: {text: "Model Response"}}`; } const F0 = `Make sure the events are using {text: string} or {html: string} format. You can also augment them using the responseInterceptor property: https://deepchat.dev/docs/interceptors#responseInterceptor`, Ee = { INVALID_KEY: "Invalid API Key", CONNECTION_FAILED: "Failed to connect", INVALID_RESPONSE: ET, INVALID_MODEL_REQUEST: TT, INVALID_MODEL_RESPONSE: ST, INVALID_STREAM_EVENT: F0, INVALID_STREAM_EVENT_MIX: "Cannot mix {text: string} and {html: string} responses.", NO_VALID_STREAM_EVENTS_SENT: `No valid stream events were sent. ${F0}` }, Kc = class Kc { static addElements(e, ...t) { t.forEach((n) => e.appendChild(n)); } static isScrollbarAtBottomOfElement(e) { const t = e.scrollHeight, n = e.clientHeight, i = e.scrollTop, s = t - n; return i >= s - Kc.CODE_SNIPPET_GENERATION_JUMP; } static cloneElement(e) { const t = e.cloneNode(!0); return e.parentNode.replaceChild(t, e), t; } static scrollToBottom(e) { e.scrollTop = e.scrollHeight; } static scrollToTop(e) { e.scrollTop = 0; } static scrollToElement(e, t) { e.scrollTop = t.offsetTop; } }; Kc.CODE_SNIPPET_GENERATION_JUMP = 0.5; let $e = Kc; const Wc = class Wc { static speak(e, t) { if (window.SpeechSynthesisUtterance) { const n = new SpeechSynthesisUtterance(e); Object.assign(n, t), speechSynthesis.speak(n); } } static processConfig(e, t) { const n = {}; setTimeout(() => { if (typeof e == "object" && (e.lang && (n.lang = e.lang), e.pitch && (n.pitch = e.pitch), e.rate && (n.rate = e.rate), e.volume && (n.volume = e.volume), e.voiceName)) { const i = window.speechSynthesis.getVoices().find((s) => { var o; return s.name.toLocaleLowerCase() === ((o = e.voiceName) == null ? void 0 : o.toLocaleLowerCase()); }); i && (n.voice = i); } t(n); }, Wc.LOAD_VOICES_MS); } }; Wc.LOAD_VOICES_MS = 200; let jn = Wc; class ct { static checkForContainerStyles(e, t) { const n = e.containerStyle; n && (Object.assign(t.style, n), console.error("The containerStyle property is deprecated since version 1.3.14."), console.error("Please change to using the style property instead: https://deepchat.dev/docs/styles#style")); } // 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 n = e; n.onNewMessage && (console.error("The onNewMessage event has been deprecated since version 2.0.0."), console.error("Please see the onMessage event: https://deepchat.dev/docs/events#onMessage"), (i = n.onNewMessage) == null || i.call(n, t)), e.dispatchEvent(new CustomEvent("new-message", { detail: t })); } static processFileConfigConnect(e) { const t = e; t.request && (console.error("The request property in file configuration is deprecated since version 2.0.0."), console.error("Please use the connect property instead: https://deepchat.dev/docs/files"), t.connect || (t.connect = t.request)); } } const Hn = class Hn { static colorToHex(e) { const t = document.createElement("div"); return t.style.color = e, document.body.appendChild(t), `#${window.getComputedStyle(t).color.match(/\d+/g).map((s) => parseInt(s).toString(16).padStart(2, "0")).join("")}`; } static setDots(e, t) { var n, i, s, o; if ((o = (s = (i = (n = t == null ? void 0 : t.loading) == null ? void 0 : n.message) == null ? void 0 : i.styles) == null ? void 0 : s.bubble) != null && o.color) { const a = Hn.colorToHex(t.loading.message.styles.bubble.color); e.style.setProperty("--loading-message-color", a), e.style.setProperty("--loading-message-color-fade", `${a}33`); } else e.style.setProperty("--loading-message-color", "#848484"), e.style.setProperty("--loading-message-color-fade", "#55555533"); } static setRing(e, t) { const { color: n, width: i, height: s, margin: o, border: a } = t || {}; if (n) { const c = Hn.colorToHex(n); e.style.setProperty("--loading-history-color", c); } else e.style.setProperty("--loading-history-color", "#dbdbdb"); e.style.setProperty("--loading-history-height", s || "57px"), e.style.setProperty("--loading-history-width", i || "57px"), e.style.setProperty("--loading-history-margin", o || "7px"), e.style.setProperty("--loading-history-border", a || "6px"); } }; Hn.BUBBLE_CLASS = "deep-chat-loading-message-bubble", Hn.DOTS_CONTAINER_CLASS = "deep-chat-loading-message-dots-container"; let Kt = Hn; const AT = "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", bT = "data:image/png;base64,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", Je = class Je { static hide(e) { var t; (t = e.getElementsByClassName(Je.CONTAINER_CLASS)[0].style).visibility || (t.visibility = "hidden"); } static reveal(e) { e.getElementsByClassName(Je.CONTAINER_CLASS)[0].style.visibility = ""; } static applyCustomStylesToElements(e, t, n) { Object.assign(e.style, n.container), Object.assign(t.style, n.avatar); } static applyCustomStyles(e, t, n, i) { var s, o, a, c; if ((s = n.default) != null && s.styles && Je.applyCustomStylesToElements(e, t, n.default.styles), i === F.USER_ROLE) (o = n.user) != null && o.styles && Je.applyCustomStylesToElements(e, t, n.user.styles); else { (a = n.ai) != null && a.styles && Je.applyCustomStylesToElements(e, t, n.ai.styles); const u = (c = n[i]) == null ? void 0 : c.styles; u && Je.applyCustomStylesToElements(e, t, u); } } static createAvatar(e, t) { var s, o, a, c, u; const n = document.createElement("img"); e === F.USER_ROLE ? n.src = ((s = t == null ? void 0 : t.user) == null ? void 0 : s.src) || ((o = t == null ? void 0 : t.default) == null ? void 0 : o.src) || bT : n.src = ((a = t == null ? void 0 : t[e]) == null ? void 0 : a.src) || ((c = t == null ? void 0 : t.ai) == null ? void 0 : c.src) || ((u = t == null ? void 0 : t.default) == null ? void 0 : u.src) || AT, n.classList.add("avatar"); const i = document.createElement("div"); return i.classList.add(Je.CONTAINER_CLASS), i.appendChild(n), t && Je.applyCustomStyles(i, n, t, e), i; } static getPosition(e, t) { var i, s, o, a, c, u; let n = (s = (i = t == null ? void 0 : t[e]) == null ? void 0 : i.styles) == null ? void 0 : s.position; return e !== F.USER_ROLE && (n ?? (n = (a = (o = t == null ? void 0 : t.ai) == null ? void 0 : o.styles) == null ? void 0 : a.position)), n ?? (n = (u = (c = t == null ? void 0 : t.default) == null ? void 0 : c.styles) == null ? void 0 : u.position), n ?? (n = e === F.USER_ROLE ? "right" : "left"), n; } static add(e, t, n) { const i = typeof n == "boolean" ? void 0 : n, s = Je.createAvatar(t, i), o = Je.getPosition(t, i); s.classList.add(o === "left" ? "left-item-position" : "right-item-position"), e.insertAdjacentElement(o === "left" ? "beforebegin" : "afterend", s); } }; Je.CONTAINER_CLASS = "avatar-container"; let Bo = Je; const yt = class yt { static hide(e) { var t; (t = e.getElementsByClassName(yt.NAME_CLASS)[0].style).visibility || (t.visibility = "hidden"); } static reveal(e) { e.getElementsByClassName(yt.NAME_CLASS)[0].style.visibility = ""; } static getPosition(e, t) { var i, s, o; let n = (i = t == null ? void 0 : t[e]) == null ? void 0 : i.position; return e !== F.USER_ROLE && (n ?? (n = (s = t == null ? void 0 : t.ai) == null ? void 0 : s.position)), n ?? (n = (o = t == null ? void 0 : t.default) == null ? void 0 : o.position), n ?? (n = e === F.USER_ROLE ? "right" : "left"), n; } static applyStyle(e, t, n) { var i, s, o, a; Object.assign(e.style, (i = n.default) == null ? void 0 : i.style), t === F.USER_ROLE ? Object.assign(e.style, (s = n.user) == null ? void 0 : s.style) : (Object.assign(e.style, (o = n.ai) == null ? void 0 : o.style), Object.assign(e.style, (a = n[t]) == null ? void 0 : a.style)); } static getNameText(e, t) { var n, i, s, o, a, c; return e === F.USER_ROLE ? ((n = t.user) == null ? void 0 : n.text) || ((i = t.default) == null ? void 0 : i.text) || "User" : e === F.AI_ROLE ? ((s = t.ai) == null ? void 0 : s.text) || ((o = t.default) == null ? void 0 : o.text) || "AI" : ((a = t[e]) == null ? void 0 : a.text) || ((c = t.default) == null ? void 0 : c.text) || e; } static createName(e, t) { const n = document.createElement("div"); return n.classList.add(yt.NAME_CLASS), n.textContent = yt.getNameText(e, t), yt.applyStyle(n, e, t), n; } static add(e, t, n) { const i = typeof n == "boolean" ? {} : n, s = yt.createName(t, i), o = yt.getPosition(t, i); s.classList.add(o === "left" ? "left-item-position" : "right-item-position"), e.insertAdjacentElement(o === "left" ? "beforebegin" : "afterend", s); } }; yt.NAME_CLASS = "name"; let Vo = yt; const mt = class mt { static getLastElementsByClass(e, t, n) { for (let i = e.length - 1; i >= 0; i -= 1) { const s = e[i]; if (s.bubbleElement.classList.contains(t[0]) && !t.slice(1).find((a) => !s.bubbleElement.classList.contains(a))) if (n) { if (!n.find((c) => s.bubbleElement.classList.contains(c))) return s; } else return s; } } static getLastMessage(e, t, n) { for (let i = e.length - 1; i >= 0; i -= 1) if (e[i].role === t) if (n) { if (e[i][n]) return e[i]; } else return e[i]; } static getLastTextToElement(e, t) { for (let n = e.length - 1; n >= 0; n -= 1) if (e[n][0] === t) return e[n]; } // 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, n, i, s, o) { const a = mt.getLastElementsByClass( t, [mt.getRoleClass(i), o], [Kt.BUBBLE_CLASS] ), c = mt.getLastMessage(e, i, s); return c && (c[s] = n), 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(mt.EMPTY_MESSAGE_CLASS), e.innerHTML = '<div style="color:#00000000">.</div>'); } static unfillEmptyMessageElement(e, t) { e.classList.contains(mt.EMPTY_MESSAGE_CLASS) && t.trim().length > 0 && e.replaceChildren(); } static getLastMessageBubbleElement(e) { var t, n, i; return Array.from(((i = (n = (t = mt.getLastMessageElement(e)) == null ? void 0 : t.children) == null ? void 0 : n[0]) == null ? void 0 : i.children) || []).find((s) => s.classList.contains("message-bubble")); } static getLastMessageElement(e) { return e.children[e.children.length - 1]; } static addRoleElements(e, t, n, i) { n && Bo.add(e, t, n), i && Vo.add(e, t, i); } static hideRoleElements(e, t, n) { const i = e[e.length - 1].innerContainer; t && Bo.hide(i), n && Vo.hide(i); } static revealRoleElements(e, t, n) { t && Bo.reveal(e), n && Vo.reveal(e); } static updateRefArr(e, t, n) { n ? e.unshift(t) : e.push(t); } }; mt.AI_ROLE = "ai", mt.USER_ROLE = "user", mt.EMPTY_MESSAGE_CLASS = "empty-message"; let F = mt; class cn { static mouseUp(e, t) { Se.unsetAllCSSMouseStates(e, t), Object.assign(e.style, t.default), Object.assign(e.style, t.hover); } static mouseDown(e, t) { Object.assign(e.style, t.click); } static mouseLeave(e, t) { Se.unsetAllCSSMouseStates(e, t), Object.assign(e.style, t.default); } static mouseEnter(e, t) { Object.assign(e.style, t.hover); } static add(e, t) { e.addEventListener("mouseenter", cn.mouseEnter.bind(this, e, t)), e.addEventListener("mouseleave", cn.mouseLeave.bind(this, e, t)), e.addEventListener("mousedown", cn.mouseDown.bind(this, e, t)), e.addEventListener("mouseup", cn.mouseUp.bind(this, e, t)); } } const vT = "deep-chat-temporary-message", yT = "deep-chat-suggestion-button", Sl = { "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" } } } }, H0 = Object.keys(Sl); class Wt { static applySuggestionEvent(e, t) { setTimeout(() => { t.addEventListener("click", () => { var n, i; (i = e.submitUserMessage) == null || i.call(e, { text: ((n = t.textContent) == null ? void 0 : n.trim()) || "" }); }); }); } static isElementTemporary(e) { var t; return e ? (t = e.bubbleElement.children[0]) == null ? void 0 : t.classList.contains(vT) : !1; } static doesElementContainDeepChatClass(e) { return H0.find((t) => e.classList.contains(t)); } static applyEvents(e, t) { const n = Sl[t].events; Object.keys(n || []).forEach((i) => { e.addEventListener(i, n == null ? void 0 : n[i]); }); } static getProcessedStyles(e, t, n) { const i = Array.from(t.classList).reduce((a, c) => { var l; const u = (l = e[c]) == null ? void 0 : l.styles; return u && e[c].styles && a.push(u), a; }, []), s = Sl[n].styles; if (s) { const a = JSON.parse(JSON.stringify(s)); a.default && Se.overwriteDefaultWithAlreadyApplied(a, t), i.unshift(a); } const o = Se.mergeStatefulStyles(i); return Se.processStateful(o, {}, {}); } static applyDeepChatUtilities(e, t, n) { H0.forEach((s) => { const o = n.getElementsByClassName(s); Array.from(o || []).forEach((a) => { const c = Wt.getProcessedStyles(t, a, s); tt.applyStylesToElement(a, c), Wt.applyEvents(a, s); }); }); const i = n.getElementsByClassName(yT); Array.from(i).forEach((s) => Wt.applySuggestionEvent(e, s)); } } class tt { static applyStylesToElement(e, t) { const n = Se.processStateful(t, {}, {}); cn.add(e, n), Object.assign(e.style, n.default); } static applyEventsToElement(e, t) { Object.keys(t).forEach((n) => { const i = t[n]; i && e.addEventListener(n, i); }); } static applyClassUtilitiesToElement(e, t) { const { events: n, styles: i } = t; n && tt.applyEventsToElement(e, n), i && !Wt.doesElementContainDeepChatClass(e) && tt.applyStylesToElement(e, i); } static applyCustomClassUtilities(e, t) { Object.keys(e).forEach((n) => { const i = t.getElementsByClassName(n); Array.from(i).forEach((s) => { e[n] && tt.applyClassUtilitiesToElement(s, e[n]); }); }); } static apply(e, t) { Wt.applyDeepChatUtilities(e, e.htmlClassUtilities, t), tt.applyCustomClassUtilities(e.htmlClassUtilities, t); } static traverseNodes(e, t) { e.nodeType === Node.ELEMENT_NODE && t.push(e.outerHTML), e.childNodes.forEach((n) => { tt.traverseNodes(n, t); }); } static splitHTML(e) { const n = new DOMParser().parseFromString(e, "text/html"), i = []; return n.body.childNodes.forEach((s) => { tt.traverseNodes(s, i); }), i; } } class Er { static addElement(e, t) { e.appendMessageBeforeSpacer(t), e.elementRef.scrollTop = e.elementRef.scrollHeight; } static createElements(e, t, n, i) { const s = e.createMessageElementsOnOrientation("", n, i); return s.bubbleElement.classList.add("html-message"), s.bubbleElement.innerHTML = t, s; } static overwrite(e, t, n, i) { const { messages: s } = e, o = F.overwriteMessage(s, i, t, n, "html", "html-message"); return o && (o.bubbleElement.innerHTML = t, tt.apply(e, o.outerContainer), ct.flagHTMLUpdateClass(o.bubbleElement)), o; } // prettier-ignore static add(e, t, n, i, s, o = !1) { var c; if (s != null && s.status) { const u = this.overwrite(e, t, n, i); if (u) return u; s.status = !1; } const a = Er.createElements(e, t, n, o); return F.fillEmptyMessageElement(a.bubbleElement, t), tt.apply(e, a.outerContainer), ct.flagHTMLUpdateClass(a.bubbleElement), e.applyCustomStyles(a, n, !1, (c = e.messageStyles) == null ? void 0 : c.html), o || Er.addElement(e, a.outerContainer), a; } } var Ha; function eE(r) { return Ha = Ha || document.createElement("textarea"), Ha.innerHTML = "&" + r + ";", Ha.value; } var RT = Object.prototype.hasOwnProperty; function CT(r, e) { return r ? RT.call(r, e) : !1; } function tE(r) { var e = [].slice.call(arguments, 1); return e.forEach(function(t) { if (t) { if (typeof t != "object") throw new TypeError(t + "must be object"); Object.keys(t).forEach(function(n) { r[n] = t[n]; }); } }), r; } var MT = /\\([\\!"#$%&'()*+,.\/:;<=>?@[\]^_`{|}~-])/g; function ta(r) { return r.indexOf("\\") < 0 ? r : r.replace(MT, "$1"); } function rE(r) { return !(r >= 55296 && r <= 57343 || r >= 64976 && r <= 65007 || (r & 65535) === 65535 || (r & 65535) === 65534 || r >= 0 && r <= 8 || r === 11 || r >= 14 && r <= 31 || r >= 127 && r <= 159 || r > 1114111); } function Tl(r) { if (r > 65535) { r -= 65536; var e = 55296 + (r >> 10), t = 56320 + (r & 1023); return String.fromCharCode(e, t); } return String.fromCharCode(r); } var OT = /&([a-z#][a-z0-9]{1,31});/gi, xT = /^#((?:x[a-f0-9]{1,8}|[0-9]{1,8}))/i; function NT(r, e) { var t = 0, n = eE(e); return e !== n ? n : e.charCodeAt(0) === 35 && xT.test(e) && (t = e[1].toLowerCase() === "x" ? parseInt(e.slice(2), 16) : parseInt(e.slice(1), 10), rE(t)) ? Tl(t) : r; } function Sn(r) { return r.indexOf("&") < 0 ? r : r.replace(OT, NT); } var IT = /[&<>"]/, LT = /[&<>"]/g, wT = { "&": "&amp;", "<": "&lt;", ">": "&gt;", '"': "&quot;" }; function PT(r) { return wT[r]; } function Ke(r) { return IT.test(r) ? r.replace(LT, PT) : r; } var k = {}; k.blockquote_open = function() { return `<blockquote> `; }; k.blockquote_close = function(r, e) { return "</blockquote>" + Cn(r, e); }; k.code = function(r, e) { return r[e].block ? "<pre><code>" + Ke(r[e].content) + "</code></pre>" + Cn(r, e) : "<code>" + Ke(r[e].content) + "</code>"; }; k.fence = function(r, e, t, n, i) { var s = r[e], o = "", a = t.langPrefix, c = "", u, l, d; if (s.params) { if (u = s.params.split(/\s+/g), l = u.join(" "), CT(i.rules.fence_custom, u[0])) return i.rules.fence_custom[u[0]](r, e, t, n, i); c = Ke(Sn(ta(l))), o = ' class="' + a + c + '"'; } return t.highlight ? d = t.highlight.apply(t.highlight, [s.content].concat(u)) || Ke(s.content) : d = Ke(s.content), "<pre><code" + o + ">" + d + "</code></pre>" + Cn(r, e); }; k.fence_custom = {}; k.heading_open = function(r, e) { return "<h" + r[e].hLevel + ">"; }; k.heading_close = function(r, e) { return "</h" + r[e].hLevel + `> `; }; k.hr = function(r, e, t) { return (t.xhtmlOut ? "<hr />" : "<hr>") + Cn(r, e); }; k.bullet_list_open = function() { return `<ul> `; }; k.bullet_list_close = function(r, e) { return "</ul>" + Cn(r, e); }; k.list_item_open = function() { return "<li>"; }; k.list_item_close = function() { return `</li> `; }; k.ordered_list_open = function(r, e) { var t = r[e], n = t.order > 1 ? ' start="' + t.order + '"' : ""; return "<ol" + n + `> `; }; k.ordered_list_close = function(r, e) { return "</ol>" + Cn(r, e); }; k.paragraph_open = function(r, e) { return r[e].tight ? "" : "<p>"; }; k.paragraph_close = function(r, e) { var t = !(r[e].tight && e && r[e - 1].type === "inline" && !r[e - 1].content); return (r[e].tight ? "" : "</p>") + (t ? Cn(r, e) : ""); }; k.link_open = function(r, e, t) { var n = r[e].title ? ' title="' + Ke(Sn(r[e].title)) + '"' : "", i = t.linkTarget ? ' target="' + t.linkTarget + '"' : ""; return '<a href="' + Ke(r[e].href) + '"' + n + i + ">"; }; k.link_close = function() { return "</a>"; }; k.image = function(r, e, t) { var n = ' src="' + Ke(r[e].src) + '"', i = r[e].title ? ' title="' + Ke(Sn(r[e].title)) + '"' : "", s = ' alt="' + (r[e].alt ? Ke(Sn(ta(r[e].alt))) : "") + '"', o = t.xhtmlOut ? " /" : ""; return "<img" + n + s + i + o + ">"; }; k.table_open = function() { return `<table> `; }; k.table_close = function() { return `</table> `; }; k.thead_open = function() { return `<thead> `; }; k.thead_close = function() { return `</thead> `; }; k.tbody_open = function() { return `<tbody> `; }; k.tbody_close = function() { return `</tbody> `; }; k.tr_open = function() { return "<tr>"; }; k.tr_close = function() { return `</tr> `; }; k.th_open = function(r, e) { var t = r[e]; return "<th" + (t.align ? ' style="text-align:' + t.align + '"' : "") + ">"; }; k.th_close = function() { return "</th>"; }; k.td_open = function(r, e) { var t = r[e]; return "<td" + (t.align ? ' style="text-align:' + t.align + '"' : "") + ">"; }; k.td_close = function() { return "</td>"; }; k.strong_open = function() { return "<strong>"; }; k.strong_close = function() { return "</strong>"; }; k.em_open = function() { return "<em>"; }; k.em_close = function() { return "</em>"; }; k.del_open = function() { return "<del>"; }; k.del_close = function() { return "</del>"; }; k.ins_open = function() { return "<ins>"; }; k.ins_close = function() { return "</ins>"; }; k.mark_open = function() { return "<mark>"; }; k.mark_close = function() { return "</mark>"; }; k.sub = function(r, e) { return "<sub>" + Ke(r[e].content) + "</sub>"; }; k.sup = function(r, e) { return "<sup>" + Ke(r[e].content) + "</sup>"; }; k.hardbreak = function(r, e, t) { return t.xhtmlOut ? `<br /> ` : `<br> `; }; k.softbreak = function(r, e, t) { return t.breaks ? t.xhtmlOut ? `<br /> ` : `<br> ` : ` `; }; k.text = function(r, e) { return Ke(r[e].content); }; k.htmlblock = function(r, e) { return r[e].content; }; k.htmltag = function(r, e) { return r[e].content; }; k.abbr_open = function(r, e) { return '<abbr title="' + Ke(Sn(r[e].title)) + '">'; }; k.abbr_close = function() { return "</abbr>"; }; k.footnote_ref = function(r, e) { var t = Number(r[e].id + 1).toString(), n = "fnref" + t; return r[e].subId > 0 && (n += ":" + r[e].subId), '<sup class="footnote-ref"><a href="#fn' + t + '" id="' + n + '">[' + t + "]</a></sup>"; }; k.footnote_block_open = function(r, e, t) { var n = t.xhtmlOut ? `<hr class="footnotes-sep" /> ` : `<hr class="footnotes-sep"> `; return n + `<section class="footnotes"> <ol class="footnotes-list"> `; }; k.footnote_block_close = function() { return `</ol> </section> `; }; k.footnote_open = function(r, e) { var t = Number(r[e].id + 1).toString(); return '<li id="fn' + t + '" class="footnote-item">'; }; k.footnote_close = function() { return `</li> `; }; k.footnote_anchor = function(r, e) { var t = Number(r[e].id + 1).toString(), n = "fnref" + t; return r[e].subId > 0 && (n += ":" + r[e].subId), ' <a href="#' + n + '" class="footnote-backref">↩</a>'; }; k.dl_open = function() { return `<dl> `; }; k.dt_open = function() { return "<dt>"; }; k.dd_open = function() { return "<dd>"; }; k.dl_close = function() { return `</dl> `; }; k.dt_close = function() { return `</dt> `; }; k.dd_close = function() { return `</dd> `; }; function nE(r, e) { return ++e >= r.length - 2 ? e : r[e].type === "paragraph_open" && r[e].tight && r[e + 1].type === "inline" && r[e + 1].content.length === 0 && r[e + 2].type === "paragraph_close" && r[e + 2].tight ? nE(r, e + 2) : e; } var Cn = k.getBreak = function(e, t) { return t = nE(e, t), t < e.length && e[t].type === "list_item_close" ? "" : ` `; }; function fd() { this.rules = tE({}, k), this.getBreak = k.getBreak; } fd.prototype.renderInline = function(r, e, t) { for (var n = this.rules, i = r.length, s = 0, o = ""; i--; ) o += n[r[s].type](r, s++, e, t, this); return o; }; fd.prototype.render = function(r, e, t) { for (var n = this.rules, i = r.length, s = -1, o = ""; ++s < i; ) r[s].type === "inline" ? o += this.renderInline(r[s].children, e, t) : o += n[r[s].type](r, s, e, t, this); return o; }; function nt() { this.__rules__ = [], this.__cache__ = null; } nt.prototype.__find__ = function(r) { for (var e = this.__rules__.length, t = -1; e--; ) if (this.__rules__[++t].name === r) return t; return -1; }; nt.prototype.__compile__ = function() { var r = this, e = [""]; r.__rules__.forEach(function(t) { t.enabled && t.alt.forEach(function(n) { e.indexOf(n) < 0 && e.push(n); }); }), r.__cache__ = {}, e.forEach(function(t) { r.__cache__[t] = [], r.__rules__.forEach(function(n) { n.enabled && (t && n.alt.indexOf(t) < 0 || r.__cache__[t].push(n.fn)); }); }); }; nt.prototype.at = function(r, e, t) { var n = this.__find__(r), i = t || {}; if (n === -1) throw new Error("Parser rule not found: " + r); this.__rules__[n].fn = e, this.__rules__[n].alt = i.alt || [], this.__cache__ = null; }; nt.prototype.before = function(r, e, t, n) { var i = this.__find__(r), s = n || {}; if (i === -1) throw new Error("Parser rule not found: " + r); this.__rules__.splice(i, 0, { name: e, enabled: !0, fn: t, alt: s.alt || [] }), this.__cache__ = null; }; nt.prototype.after = function(r, e, t, n) { var i = this.__find__(r), s = n || {}; if (i === -1) throw new Error("Parser rule not found: " + r); this.__rules__.splice(i + 1, 0, { name: e, enabled: !0, fn: t, alt: s.alt || [] }), this.__cache__ = null; }; nt.prototype.push = function(r, e, t) { var n = t || {}; this.__rules__.push({ name: r, enabled: !0, fn: e, alt: n.alt || [] }), this.__cache__ = null; }; nt.prototype.enable = function(r, e) { r = Array.isArray(r) ? r : [r], e && this.__rules__.forEach(function(t) { t.enabled = !1; }), r.forEach(function(t) { var n = this.__find__(t); if (n < 0) throw new Error("Rules manager: invalid rule name " + t); this.__rules__[n].enabled = !0; }, this), this.__cache__ = null; }; nt.prototype.disable = function(r) { r = Array.isArray(r) ? r : [r], r.forEach(function(e) { var t = this.__find__(e); if (t < 0) throw new Error("Rules manager: invalid rule name " + e); this.__rules__[t].enabled = !1; }, this), this.__cache__ = null; }; nt.prototype.getRules = function(r) { return this.__cache__ === null && this.__compile__(), this.__cache__[r] || []; }; function DT(r) { r.inlineMode ? r.tokens.push({ type: "inline", content: r.src.replace(/\n/g, " ").trim(), level: 0, lines: [0, 1], children: [] }) : r.block.parse(r.src, r.options, r.env, r.tokens); } function Mn(r, e, t, n, i) { this.src = r, this.env = n, this.options = t, this.parser = e, this.tokens = i, this.pos = 0, this.posMax = this.src.length, this.level = 0, this.pending = "", this.pendingLevel = 0, this.cache = [], this.isInLabel = !1, this.linkLevel = 0, this.linkContent = "", this.labelUnmatchedScopes = 0; } Mn.prototype.pushPending = function() { this.tokens.push({ type: "text", content: this.pending, level: this.pendingLevel }), this.pending = ""; }; Mn.prototype.push = function(r) { this.pending && this.pushPending(), this.tokens.push(r), this.pendingLevel = this.level; }; Mn.prototype.cacheSet = function(r, e) { for (var t = this.cache.length; t <= r; t++) this.cache.push(0); this.cache[r] = e; }; Mn.prototype.cacheGet = function(r) { return r < this.cache.length ? this.cache[r] : 0; }; function ra(r, e) { var t, n, i, s = -1, o = r.posMax, a = r.pos, c = r.isInLabel; if (r.isInLabel) return -1; if (r.labelUnmatchedScopes) return r.labelUnmatchedScopes--, -1; for (r.pos = e + 1, r.isInLabel = !0, t = 1; r.pos < o; ) { if (i = r.src.charCodeAt(r.pos), i === 91) t++; else if (i === 93 && (t--, t === 0)) { n = !0; break; } r.parser.skipToken(r); } return n ? (s = r.pos, r.labelUnmatchedScopes = 0) : r.labelUnmatchedScopes = t - 1, r.pos = a, r.isInLabel = c, s; } function kT(r, e, t, n) { var i, s, o, a, c, u; if (r.charCodeAt(0) !== 42 || r.charCodeAt(1) !== 91 || r.indexOf("]:") === -1 || (i = new Mn(r, e, t, n, []), s = ra(i, 1), s < 0 || r.charCodeAt(s + 1) !== 58)) return -1; for (a = i.posMax, o = s + 2; o < a && i.src.charCodeAt(o) !== 10; o++) ; return c = r.slice(2, s), u = r.slice(s + 2, o).trim(), u.length === 0 ? -1 : (n.abbreviations || (n.abbreviations = {}), typeof n.abbreviations[":" + c] > "u" && (n.abbreviations[":" + c] = u), o); } function UT(r) { var e = r.tokens, t, n, i, s; if (!r.inlineMode) { for (t = 1, n = e.length - 1; t < n; t++) if (e[t - 1].type === "paragraph_open" && e[t].type === "inline" && e[t + 1].type === "paragraph_close") { for (i = e[t].content; i.length && (s = kT(i, r.inline, r.options, r.env), !(s < 0)); ) i = i.slice(s).trim(); e[t].content = i, i.length || (e[t - 1].tight = !0, e[t + 1].tight = !0); } } } function Al(r) { var e = Sn(r); try { e = decodeURI(e); } catch { } return encodeURI(e); } function iE(r, e) { var t, n, i, s = e, o = r.posMax; if (r.src.charCodeAt(e) === 60) { for (e++; e < o; ) { if (t = r.src.charCodeAt(e), t === 10) return !1; if (t === 62) return i = Al(ta(r.src.slice(s + 1, e))), r.parser.validateLink(i) ? (r.pos = e + 1, r.linkContent = i, !0) : !1; if (t === 92 && e + 1 < o) { e += 2; continue; } e++; } return !1; } for (n = 0; e < o && (t = r.src.charCodeAt(e), !(t === 32 || t < 32 || t === 127)); ) { if (t === 92 && e + 1 < o) { e += 2; continue; } if (t === 40 && (n++, n > 1) || t === 41 && (n--, n < 0)) break; e++; } return s === e || (i = ta(r.src.slice(s, e)), !r.parser.validateLink(i)) ? !1 : (r.linkContent = i, r.pos = e, !0); } function sE(r, e) { var t, n = e, i = r.posMax, s = r.src.charCodeAt(e); if (s !== 34 && s !== 39 && s !== 40) return !1; for (e++, s === 40 && (s = 41); e < i; ) { if (t = r.src.charCodeAt(e), t === s) return r.pos = e + 1, r.linkContent = ta(r.src.slice(n + 1, e)), !0; if (t === 92 && e + 1 < i) { e += 2; continue; } e++; } return !1; } function oE(r) { return r.trim().replace(/\s+/g, " ").toUpperCase(); } function BT(r, e, t, n) { var i, s, o, a, c, u, l, d, h; if (r.charCodeAt(0) !== 91 || r.indexOf("]:") === -1 || (i = new Mn(r, e, t, n, []), s = ra(i, 0), s < 0 || r.charCodeAt(s + 1) !== 58)) return -1; for (a = i.posMax, o = s + 2; o < a && (c = i.src.charCodeAt(o), !(c !== 32 && c !== 10)); o++) ; if (!iE(i, o)) return -1; for (l = i.linkContent, o = i.pos, u = o, o = o + 1; o < a && (c = i.src.charCodeAt(o), !(c !== 32 && c !== 10)); o++) ; for (o < a && u !== o && sE(i, o) ? (d = i.linkContent, o = i.pos) : (d = "", o = u); o < a && i.src.charCodeAt(o) === 32; ) o++; return o < a && i.src.charCodeAt(o) !== 10 ? -1 : (h = oE(r.slice(1, s)), typeof n.references[h] > "u" && (n.references[h] = { title: d, href: l }), o); } function VT(r) { var e = r.tokens, t, n, i, s; if (r.env.references = r.env.references || {}, !r.inlineMode) { for (t = 1, n = e.length - 1; t < n; t++) if (e[t].type === "inline" && e[t - 1].type === "paragraph_open" && e[t + 1].type === "paragraph_close") { for (i = e[t].content; i.length && (s = BT(i, r.inline, r.options, r.env), !(s < 0)); ) i = i.slice(s).trim(); e[t].content = i, i.length || (e[t - 1].tight = !0, e[t + 1].tight = !0); } } } function FT(r) { var e = r.tokens, t, n, i; for (n = 0, i = e.length; n < i; n++) t = e[n], t.type === "inline" && r.inline.parse(t.content, r.options, r.env, t.children); } function HT(r) { var e, t, n, i, s, o, a, c, u, l = 0, d = !1, h = {}; if (r.env.footnotes && (r.tokens = r.tokens.filter(function(p) { return p.type === "footnote_reference_open" ? (d = !0, c = [], u = p.label, !1) : p.type === "footnote_reference_close" ? (d = !1, h[":" + u] = c, !1) : (d && c.push(p), !d); }), !!r.env.footnotes.list)) { f