'+(n?r:Ct(r,!0))+`
-`:""+(n?r:Ct(r,!0))+`
-`}blockquote({tokens:e}){return`+`), s = "", r = "", i = []; for (; n.length > 0;) { + let o = !1, a = [], l; for (l = 0; l < n.length; l++)if (this.rules.other.blockquoteStart.test(n[l])) a.push(n[l]), o = !0; else if (!o) a.push(n[l]); else break; n = n.slice(l); let f = a.join(` +`), u = f.replace(this.rules.other.blockquoteSetextReplace, ` + $1`).replace(this.rules.other.blockquoteSetextReplace2, ""); s = s ? `${s} +${f}` : f, r = r ? `${r} +${u}` : u; let d = this.lexer.state.top; if (this.lexer.state.top = !0, this.lexer.blockTokens(u, i, !0), this.lexer.state.top = d, n.length === 0) break; let g = i.at(-1); if ((g == null ? void 0 : g.type) === "code") break; if ((g == null ? void 0 : g.type) === "blockquote") { + let y = g, E = y.raw + ` +`+ n.join(` +`), x = this.blockquote(E); i[i.length - 1] = x, s = s.substring(0, s.length - y.raw.length) + x.raw, r = r.substring(0, r.length - y.text.length) + x.text; break + } else if ((g == null ? void 0 : g.type) === "list") { + let y = g, E = y.raw + ` +`+ n.join(` +`), x = this.list(E); i[i.length - 1] = x, s = s.substring(0, s.length - g.raw.length) + x.raw, r = r.substring(0, r.length - y.raw.length) + x.raw, n = E.substring(i.at(-1).raw.length).split(` +`); continue + } + } return { type: "blockquote", raw: s, tokens: i, text: r } + } + } list(e) { + let t = this.rules.block.list.exec(e); if (t) { + let n = t[1].trim(), s = n.length > 1, r = { type: "list", raw: "", ordered: s, start: s ? +n.slice(0, -1) : "", loose: !1, items: [] }; n = s ? `\\d{1,9}\\${n.slice(-1)}` : `\\${n}`, this.options.pedantic && (n = s ? n : "[*+-]"); let i = this.rules.other.listItemRegex(n), o = !1; for (; e;) { + let l = !1, f = "", u = ""; if (!(t = i.exec(e)) || this.rules.block.hr.test(e)) break; f = t[0], e = e.substring(f.length); let d = yf(t[2].split(` +`, 1)[0], t[1].length), g = e.split(` +`, 1)[0], y = !d.trim(), E = 0; if (this.options.pedantic ? (E = 2, u = d.trimStart()) : y ? E = t[1].length + 1 : (E = d.search(this.rules.other.nonSpaceChar), E = E > 4 ? 1 : E, u = d.slice(E), E += t[1].length), y && this.rules.other.blankLine.test(g) && (f += g + ` +`, e = e.substring(g.length + 1), l = !0), !l) { + let x = this.rules.other.nextBulletRegex(E), M = this.rules.other.hrRegex(E), m = this.rules.other.fencesBeginRegex(E), H = this.rules.other.headingBeginRegex(E), Y = this.rules.other.htmlBeginRegex(E), $ = this.rules.other.blockquoteBeginRegex(E); for (; e;) { + let z = e.split(` +`, 1)[0], O; if (g = z, this.options.pedantic ? (g = g.replace(this.rules.other.listReplaceNesting, " "), O = g) : O = g.replace(this.rules.other.tabCharGlobal, " "), m.test(g) || H.test(g) || Y.test(g) || $.test(g) || x.test(g) || M.test(g)) break; if (O.search(this.rules.other.nonSpaceChar) >= E || !g.trim()) u += ` +`+ O.slice(E); else { + if (y || d.replace(this.rules.other.tabCharGlobal, " ").search(this.rules.other.nonSpaceChar) >= 4 || m.test(d) || H.test(d) || M.test(d)) break; u += ` +`+ g + } y = !g.trim(), f += z + ` +`, e = e.substring(z.length + 1), d = O.slice(E) + } + } r.loose || (o ? r.loose = !0 : this.rules.other.doubleBlankLine.test(f) && (o = !0)), r.items.push({ type: "list_item", raw: f, task: !!this.options.gfm && this.rules.other.listIsTask.test(u), loose: !1, text: u, tokens: [] }), r.raw += f + } let a = r.items.at(-1); if (a) a.raw = a.raw.trimEnd(), a.text = a.text.trimEnd(); else return; r.raw = r.raw.trimEnd(); for (let l of r.items) { this.lexer.state.top = !1, l.tokens = this.lexer.blockTokens(l.text, []); let f = l.tokens[0]; if (l.task && ((f == null ? void 0 : f.type) === "text" || (f == null ? void 0 : f.type) === "paragraph")) { l.text = l.text.replace(this.rules.other.listReplaceTask, ""), f.raw = f.raw.replace(this.rules.other.listReplaceTask, ""), f.text = f.text.replace(this.rules.other.listReplaceTask, ""); for (let d = this.lexer.inlineQueue.length - 1; d >= 0; d--)if (this.rules.other.listIsTask.test(this.lexer.inlineQueue[d].src)) { this.lexer.inlineQueue[d].src = this.lexer.inlineQueue[d].src.replace(this.rules.other.listReplaceTask, ""); break } let u = this.rules.other.listTaskCheckbox.exec(l.raw); if (u) { let d = { type: "checkbox", raw: u[0] + " ", checked: u[0] !== "[ ]" }; l.checked = d.checked, r.loose ? l.tokens[0] && ["paragraph", "text"].includes(l.tokens[0].type) && "tokens" in l.tokens[0] && l.tokens[0].tokens ? (l.tokens[0].raw = d.raw + l.tokens[0].raw, l.tokens[0].text = d.raw + l.tokens[0].text, l.tokens[0].tokens.unshift(d)) : l.tokens.unshift({ type: "paragraph", raw: d.raw, text: d.raw, tokens: [d] }) : l.tokens.unshift(d) } } else l.task && (l.task = !1); if (!r.loose) { let u = l.tokens.filter(g => g.type === "space"), d = u.length > 0 && u.some(g => this.rules.other.anyLine.test(g.raw)); r.loose = d } } if (r.loose) for (let l of r.items) { l.loose = !0; for (let f of l.tokens) f.type === "text" && (f.type = "paragraph") } return r + } + } html(e) { let t = this.rules.block.html.exec(e); if (t) { let n = tl(t[0]); return { type: "html", block: !0, raw: n, pre: t[1] === "pre" || t[1] === "script" || t[1] === "style", text: n } } } def(e) { + let t = this.rules.block.def.exec(e); if (t) { + let n = t[1].toLowerCase().replace(this.rules.other.multipleSpaceGlobal, " "), s = t[2] ? t[2].replace(this.rules.other.hrefBrackets, "$1").replace(this.rules.inline.anyPunctuation, "$1") : "", r = t[3] ? t[3].substring(1, t[3].length - 1).replace(this.rules.inline.anyPunctuation, "$1") : t[3]; return { + type: "def", tag: n, raw: Qt(t[0], ` +`), href: s, title: r + } + } + } table(e) { + var o; let t = this.rules.block.table.exec(e); if (!t || !this.rules.other.tableDelimiter.test(t[2])) return; let n = el(t[1]), s = t[2].replace(this.rules.other.tableAlignChars, "").split("|"), r = (o = t[3]) != null && o.trim() ? t[3].replace(this.rules.other.tableRowBlankLine, "").split(` +`) : [], i = { + type: "table", raw: Qt(t[0], ` +`), header: [], align: [], rows: [] + }; if (n.length === s.length) { for (let a of s) this.rules.other.tableAlignRight.test(a) ? i.align.push("right") : this.rules.other.tableAlignCenter.test(a) ? i.align.push("center") : this.rules.other.tableAlignLeft.test(a) ? i.align.push("left") : i.align.push(null); for (let a = 0; a < n.length; a++)i.header.push({ text: n[a], tokens: this.lexer.inline(n[a]), header: !0, align: i.align[a] }); for (let a of r) i.rows.push(el(a, i.header.length).map((l, f) => ({ text: l, tokens: this.lexer.inline(l), header: !1, align: i.align[f] }))); return i } + } lheading(e) { + let t = this.rules.block.lheading.exec(e); if (t) { + let n = t[1].trim(); return { + type: "heading", raw: Qt(t[0], ` +`), depth: t[2].charAt(0) === "=" ? 1 : 2, text: n, tokens: this.lexer.inline(n) + } + } + } paragraph(e) { + let t = this.rules.block.paragraph.exec(e); if (t) { + let n = t[1].charAt(t[1].length - 1) === ` +`? t[1].slice(0, -1) : t[1]; return { type: "paragraph", raw: t[0], text: n, tokens: this.lexer.inline(n) } + } + } text(e) { let t = this.rules.block.text.exec(e); if (t) return { type: "text", raw: t[0], text: t[0], tokens: this.lexer.inline(t[0]) } } escape(e) { let t = this.rules.inline.escape.exec(e); if (t) return { type: "escape", raw: t[0], text: t[1] } } tag(e) { let t = this.rules.inline.tag.exec(e); if (t) return !this.lexer.state.inLink && this.rules.other.startATag.test(t[0]) ? this.lexer.state.inLink = !0 : this.lexer.state.inLink && this.rules.other.endATag.test(t[0]) && (this.lexer.state.inLink = !1), !this.lexer.state.inRawBlock && this.rules.other.startPreScriptTag.test(t[0]) ? this.lexer.state.inRawBlock = !0 : this.lexer.state.inRawBlock && this.rules.other.endPreScriptTag.test(t[0]) && (this.lexer.state.inRawBlock = !1), { type: "html", raw: t[0], inLink: this.lexer.state.inLink, inRawBlock: this.lexer.state.inRawBlock, block: !1, text: t[0] } } link(e) { let t = this.rules.inline.link.exec(e); if (t) { let n = t[2].trim(); if (!this.options.pedantic && this.rules.other.startAngleBracket.test(n)) { if (!this.rules.other.endAngleBracket.test(n)) return; let i = Qt(n.slice(0, -1), "\\"); if ((n.length - i.length) % 2 === 0) return } else { let i = xf(t[2], "()"); if (i === -2) return; if (i > -1) { let o = (t[0].indexOf("!") === 0 ? 5 : 4) + t[1].length + i; t[2] = t[2].substring(0, i), t[0] = t[0].substring(0, o).trim(), t[3] = "" } } let s = t[2], r = ""; if (this.options.pedantic) { let i = this.rules.other.pedanticHrefTitle.exec(s); i && (s = i[1], r = i[3]) } else r = t[3] ? t[3].slice(1, -1) : ""; return s = s.trim(), this.rules.other.startAngleBracket.test(s) && (this.options.pedantic && !this.rules.other.endAngleBracket.test(n) ? s = s.slice(1) : s = s.slice(1, -1)), nl(t, { href: s && s.replace(this.rules.inline.anyPunctuation, "$1"), title: r && r.replace(this.rules.inline.anyPunctuation, "$1") }, t[0], this.lexer, this.rules) } } reflink(e, t) { let n; if ((n = this.rules.inline.reflink.exec(e)) || (n = this.rules.inline.nolink.exec(e))) { let s = (n[2] || n[1]).replace(this.rules.other.multipleSpaceGlobal, " "), r = t[s.toLowerCase()]; if (!r) { let i = n[0].charAt(0); return { type: "text", raw: i, text: i } } return nl(n, r, n[0], this.lexer, this.rules) } } emStrong(e, t, n = "") { let s = this.rules.inline.emStrongLDelim.exec(e); if (!(!s || !s[1] && !s[2] && !s[3] && !s[4] || s[4] && n.match(this.rules.other.unicodeAlphaNumeric)) && (!(s[1] || s[3]) || !n || this.rules.inline.punctuation.exec(n))) { let r = [...s[0]].length - 1, i, o, a = r, l = 0, f = s[0][0] === "*" ? this.rules.inline.emStrongRDelimAst : this.rules.inline.emStrongRDelimUnd; for (f.lastIndex = 0, t = t.slice(-1 * e.length + r); (s = f.exec(t)) !== null;) { if (i = s[1] || s[2] || s[3] || s[4] || s[5] || s[6], !i) continue; if (o = [...i].length, s[3] || s[4]) { a += o; continue } else if ((s[5] || s[6]) && r % 3 && !((r + o) % 3)) { l += o; continue } if (a -= o, a > 0) continue; o = Math.min(o, o + a + l); let u = [...s[0]][0].length, d = e.slice(0, r + s.index + u + o); if (Math.min(r, o) % 2) { let y = d.slice(1, -1); return { type: "em", raw: d, text: y, tokens: this.lexer.inlineTokens(y) } } let g = d.slice(2, -2); return { type: "strong", raw: d, text: g, tokens: this.lexer.inlineTokens(g) } } } } codespan(e) { let t = this.rules.inline.code.exec(e); if (t) { let n = t[2].replace(this.rules.other.newLineCharGlobal, " "), s = this.rules.other.nonSpaceChar.test(n), r = this.rules.other.startingSpaceChar.test(n) && this.rules.other.endingSpaceChar.test(n); return s && r && (n = n.substring(1, n.length - 1)), { type: "codespan", raw: t[0], text: n } } } br(e) { let t = this.rules.inline.br.exec(e); if (t) return { type: "br", raw: t[0] } } del(e, t, n = "") { let s = this.rules.inline.delLDelim.exec(e); if (s && (!s[1] || !n || this.rules.inline.punctuation.exec(n))) { let r = [...s[0]].length - 1, i, o, a = r, l = this.rules.inline.delRDelim; for (l.lastIndex = 0, t = t.slice(-1 * e.length + r); (s = l.exec(t)) !== null;) { if (i = s[1] || s[2] || s[3] || s[4] || s[5] || s[6], !i || (o = [...i].length, o !== r)) continue; if (s[3] || s[4]) { a += o; continue } if (a -= o, a > 0) continue; o = Math.min(o, o + a); let f = [...s[0]][0].length, u = e.slice(0, r + s.index + f + o), d = u.slice(r, -r); return { type: "del", raw: u, text: d, tokens: this.lexer.inlineTokens(d) } } } } autolink(e) { let t = this.rules.inline.autolink.exec(e); if (t) { let n, s; return t[2] === "@" ? (n = t[1], s = "mailto:" + n) : (n = t[1], s = n), { type: "link", raw: t[0], text: n, href: s, tokens: [{ type: "text", raw: n, text: n }] } } } url(e) { var n, s; let t; if (t = this.rules.inline.url.exec(e)) { let r, i; if (t[2] === "@") r = t[0], i = "mailto:" + r; else { let o; do o = t[0], t[0] = (s = (n = this.rules.inline._backpedal.exec(t[0])) == null ? void 0 : n[0]) != null ? s : ""; while (o !== t[0]); r = t[0], t[1] === "www." ? i = "http://" + t[0] : i = t[0] } return { type: "link", raw: t[0], text: r, href: i, tokens: [{ type: "text", raw: r, text: r }] } } } inlineText(e) { let t = this.rules.inline.text.exec(e); if (t) { let n = this.lexer.state.inRawBlock; return { type: "text", raw: t[0], text: t[0], escaped: n } } } + }, yt = class Xr { + constructor(t) { _e(this, "tokens"); _e(this, "options"); _e(this, "state"); _e(this, "inlineQueue"); _e(this, "tokenizer"); this.tokens = [], this.tokens.links = Object.create(null), this.options = t || cn, this.options.tokenizer = this.options.tokenizer || new Ls, this.tokenizer = this.options.tokenizer, this.tokenizer.options = this.options, this.tokenizer.lexer = this, this.inlineQueue = [], this.state = { inLink: !1, inRawBlock: !1, top: !0 }; let n = { other: We, block: Os.normal, inline: Yn.normal }; this.options.pedantic ? (n.block = Os.pedantic, n.inline = Yn.pedantic) : this.options.gfm && (n.block = Os.gfm, this.options.breaks ? n.inline = Yn.breaks : n.inline = Yn.gfm), this.tokenizer.rules = n } static get rules() { return { block: Os, inline: Yn } } static lex(t, n) { return new Xr(n).lex(t) } static lexInline(t, n) { return new Xr(n).inlineTokens(t) } lex(t) { + t = t.replace(We.carriageReturn, ` +`), this.blockTokens(t, this.tokens); for (let n = 0; n < this.inlineQueue.length; n++) { let s = this.inlineQueue[n]; this.inlineTokens(s.src, s.tokens) } return this.inlineQueue = [], this.tokens + } blockTokens(t, n = [], s = !1) { + var i, o, a; this.tokenizer.lexer = this, this.options.pedantic && (t = t.replace(We.tabCharGlobal, " ").replace(We.spaceLine, "")); let r = 1 / 0; for (; t;) { + if (t.length < r) r = t.length; else { this.infiniteLoopError(t.charCodeAt(0)); break } let l; if ((o = (i = this.options.extensions) == null ? void 0 : i.block) != null && o.some(u => (l = u.call({ lexer: this }, t, n)) ? (t = t.substring(l.raw.length), n.push(l), !0) : !1)) continue; if (l = this.tokenizer.space(t)) { + t = t.substring(l.raw.length); let u = n.at(-1); l.raw.length === 1 && u !== void 0 ? u.raw += ` +`: n.push(l); continue + } if (l = this.tokenizer.code(t)) { + t = t.substring(l.raw.length); let u = n.at(-1); (u == null ? void 0 : u.type) === "paragraph" || (u == null ? void 0 : u.type) === "text" ? (u.raw += (u.raw.endsWith(` +`) ? "" : ` +`) + l.raw, u.text += ` +`+ l.text, this.inlineQueue.at(-1).src = u.text) : n.push(l); continue + } if (l = this.tokenizer.fences(t)) { t = t.substring(l.raw.length), n.push(l); continue } if (l = this.tokenizer.heading(t)) { t = t.substring(l.raw.length), n.push(l); continue } if (l = this.tokenizer.hr(t)) { t = t.substring(l.raw.length), n.push(l); continue } if (l = this.tokenizer.blockquote(t)) { t = t.substring(l.raw.length), n.push(l); continue } if (l = this.tokenizer.list(t)) { t = t.substring(l.raw.length), n.push(l); continue } if (l = this.tokenizer.html(t)) { t = t.substring(l.raw.length), n.push(l); continue } if (l = this.tokenizer.def(t)) { + t = t.substring(l.raw.length); let u = n.at(-1); (u == null ? void 0 : u.type) === "paragraph" || (u == null ? void 0 : u.type) === "text" ? (u.raw += (u.raw.endsWith(` +`) ? "" : ` +`) + l.raw, u.text += ` +`+ l.raw, this.inlineQueue.at(-1).src = u.text) : this.tokens.links[l.tag] || (this.tokens.links[l.tag] = { href: l.href, title: l.title }, n.push(l)); continue + } if (l = this.tokenizer.table(t)) { t = t.substring(l.raw.length), n.push(l); continue } if (l = this.tokenizer.lheading(t)) { t = t.substring(l.raw.length), n.push(l); continue } let f = t; if ((a = this.options.extensions) != null && a.startBlock) { let u = 1 / 0, d = t.slice(1), g; this.options.extensions.startBlock.forEach(y => { g = y.call({ lexer: this }, d), typeof g == "number" && g >= 0 && (u = Math.min(u, g)) }), u < 1 / 0 && u >= 0 && (f = t.substring(0, u + 1)) } if (this.state.top && (l = this.tokenizer.paragraph(f))) { + let u = n.at(-1); s && (u == null ? void 0 : u.type) === "paragraph" ? (u.raw += (u.raw.endsWith(` +`) ? "" : ` +`) + l.raw, u.text += ` +`+ l.text, this.inlineQueue.pop(), this.inlineQueue.at(-1).src = u.text) : n.push(l), s = f.length !== t.length, t = t.substring(l.raw.length); continue + } if (l = this.tokenizer.text(t)) { + t = t.substring(l.raw.length); let u = n.at(-1); (u == null ? void 0 : u.type) === "text" ? (u.raw += (u.raw.endsWith(` +`) ? "" : ` +`) + l.raw, u.text += ` +`+ l.text, this.inlineQueue.pop(), this.inlineQueue.at(-1).src = u.text) : n.push(l); continue + } if (t) { this.infiniteLoopError(t.charCodeAt(0)); break } + } return this.state.top = !0, n + } inline(t, n = []) { return this.inlineQueue.push({ src: t, tokens: n }), n } inlineTokens(t, n = []) { var f, u, d, g, y, E; this.tokenizer.lexer = this; let s = t, r = null; if (this.tokens.links) { let x = Object.keys(this.tokens.links); if (x.length > 0) for (; (r = this.tokenizer.rules.inline.reflinkSearch.exec(s)) !== null;)x.includes(r[0].slice(r[0].lastIndexOf("[") + 1, -1)) && (s = s.slice(0, r.index) + "[" + "a".repeat(r[0].length - 2) + "]" + s.slice(this.tokenizer.rules.inline.reflinkSearch.lastIndex)) } for (; (r = this.tokenizer.rules.inline.anyPunctuation.exec(s)) !== null;)s = s.slice(0, r.index) + "++" + s.slice(this.tokenizer.rules.inline.anyPunctuation.lastIndex); let i; for (; (r = this.tokenizer.rules.inline.blockSkip.exec(s)) !== null;)i = r[2] ? r[2].length : 0, s = s.slice(0, r.index + i) + "[" + "a".repeat(r[0].length - i - 2) + "]" + s.slice(this.tokenizer.rules.inline.blockSkip.lastIndex); s = (d = (u = (f = this.options.hooks) == null ? void 0 : f.emStrongMask) == null ? void 0 : u.call({ lexer: this }, s)) != null ? d : s; let o = !1, a = "", l = 1 / 0; for (; t;) { if (t.length < l) l = t.length; else { this.infiniteLoopError(t.charCodeAt(0)); break } o || (a = ""), o = !1; let x; if ((y = (g = this.options.extensions) == null ? void 0 : g.inline) != null && y.some(m => (x = m.call({ lexer: this }, t, n)) ? (t = t.substring(x.raw.length), n.push(x), !0) : !1)) continue; if (x = this.tokenizer.escape(t)) { t = t.substring(x.raw.length), n.push(x); continue } if (x = this.tokenizer.tag(t)) { t = t.substring(x.raw.length), n.push(x); continue } if (x = this.tokenizer.link(t)) { t = t.substring(x.raw.length), n.push(x); continue } if (x = this.tokenizer.reflink(t, this.tokens.links)) { t = t.substring(x.raw.length); let m = n.at(-1); x.type === "text" && (m == null ? void 0 : m.type) === "text" ? (m.raw += x.raw, m.text += x.text) : n.push(x); continue } if (x = this.tokenizer.emStrong(t, s, a)) { t = t.substring(x.raw.length), n.push(x); continue } if (x = this.tokenizer.codespan(t)) { t = t.substring(x.raw.length), n.push(x); continue } if (x = this.tokenizer.br(t)) { t = t.substring(x.raw.length), n.push(x); continue } if (x = this.tokenizer.del(t, s, a)) { t = t.substring(x.raw.length), n.push(x); continue } if (x = this.tokenizer.autolink(t)) { t = t.substring(x.raw.length), n.push(x); continue } if (!this.state.inLink && (x = this.tokenizer.url(t))) { t = t.substring(x.raw.length), n.push(x); continue } let M = t; if ((E = this.options.extensions) != null && E.startInline) { let m = 1 / 0, H = t.slice(1), Y; this.options.extensions.startInline.forEach($ => { Y = $.call({ lexer: this }, H), typeof Y == "number" && Y >= 0 && (m = Math.min(m, Y)) }), m < 1 / 0 && m >= 0 && (M = t.substring(0, m + 1)) } if (x = this.tokenizer.inlineText(M)) { t = t.substring(x.raw.length), x.raw.slice(-1) !== "_" && (a = x.raw.slice(-1)), o = !0; let m = n.at(-1); (m == null ? void 0 : m.type) === "text" ? (m.raw += x.raw, m.text += x.text) : n.push(x); continue } if (t) { this.infiniteLoopError(t.charCodeAt(0)); break } } return n } infiniteLoopError(t) { let n = "Infinite loop on byte: " + t; if (!this.options.silent) throw new Error(n) } + }, $s = class { + constructor(e) { _e(this, "options"); _e(this, "parser"); this.options = e || cn } space(e) { return "" } code({ text: e, lang: t, escaped: n }) { + var i; let s = (i = (t || "").match(We.notSpaceStart)) == null ? void 0 : i[0], r = e.replace(We.endingNewline, "") + ` +`; return s ? '+`: "' + (n ? r : Ct(r, !0)) + `+`} blockquote({ tokens: e }) { + return `" + (n ? r : Ct(r, !0)) + `${this.parser.parse(e)}-`}html({text:e}){return e}def(e){return""}heading({tokens:e,depth:t}){return`${this.parser.parseInline(e)} -`}hr(e){return`
-`}list(e){let t=e.ordered,n=e.start,s="";for(let o=0;o-`+s+""+r+`> -`}listitem(e){return` ${this.parser.parse(e.tokens)} -`}checkbox({checked:e}){return" '}paragraph({tokens:e}){return`${this.parser.parseInline(e)}
-`}table(e){let t="",n="";for(let r=0;r${s}`),` +`} html({ text: e }) { return e } def(e) { return "" } heading({ tokens: e, depth: t }) { + return `
+`} tablerow({ text: e }) { + return `${this.parser.parseInline(e)} +`} hr(e) { + return `
+`} list(e) { + let t = e.ordered, n = e.start, s = ""; for (let o = 0; o < e.items.length; o++) { let a = e.items[o]; s += this.listitem(a) } let r = t ? "ol" : "ul", i = t && n !== 1 ? ' start="' + n + '"' : ""; return "<" + r + i + `> +`+ s + "" + r + `> +`} listitem(e) { + return `${this.parser.parse(e.tokens)} +`} checkbox({ checked: e }) { return " ' } paragraph({ tokens: e }) { + return `${this.parser.parseInline(e)}
+`} table(e) { + let t = "", n = ""; for (let r = 0; r < e.header.length; r++)n += this.tablecell(e.header[r]); t += this.tablerow({ text: n }); let s = ""; for (let r = 0; r < e.rows.length; r++) { let i = e.rows[r]; n = ""; for (let o = 0; o < i.length; o++)n += this.tablecell(i[o]); s += this.tablerow({ text: n }) } return s && (s = `${s}`), `-`+t+` -`+s+`
-`}tablerow({text:e}){return`+`+ t + ` +`+ s + ` ${e} -`}tablecell(e){let t=this.parser.parseInline(e.tokens),n=e.header?"th":"td";return(e.align?`<${n} align="${e.align}">`:`<${n}>`)+t+`${n}> -`}strong({tokens:e}){return`${this.parser.parseInline(e)}`}em({tokens:e}){return`${this.parser.parseInline(e)}`}codespan({text:e}){return`${Ct(e,!0)}`}br(e){return"
"}del({tokens:e}){return`${this.parser.parseInline(e)}`}link({href:e,title:t,tokens:n}){let s=this.parser.parseInline(n),r=Jo(e);if(r===null)return s;e=r;let i='"+s+"",i}image({href:e,title:t,text:n,tokens:s}){s&&(n=this.parser.parseInline(s,this.parser.textRenderer));let r=Jo(e);if(r===null)return Ct(n);e=r;let i=`",i}text(e){return"tokens"in e&&e.tokens?this.parser.parseInline(e.tokens):"escaped"in e&&e.escaped?e.text:Ct(e.text)}},Lr=class{strong({text:e}){return e}em({text:e}){return e}codespan({text:e}){return e}del({text:e}){return e}html({text:e}){return e}text({text:e}){return e}link({text:e}){return""+e}image({text:e}){return""+e}br(){return""}checkbox({raw:e}){return e}},wt=class Qr{constructor(t){_e(this,"options");_e(this,"renderer");_e(this,"textRenderer");this.options=t||cn,this.options.renderer=this.options.renderer||new $s,this.renderer=this.options.renderer,this.renderer.options=this.options,this.renderer.parser=this,this.textRenderer=new Lr}static parse(t,n){return new Qr(n).parse(t)}static parseInline(t,n){return new Qr(n).parseInline(t)}parse(t){var s,r;this.renderer.parser=this;let n="";for(let i=0;i
{let l=o[a].flat(1/0);n=n.concat(this.walkTokens(l,t))}):o.tokens&&(n=n.concat(this.walkTokens(o.tokens,t)))}}return n}use(...e){let t=this.defaults.extensions||{renderers:{},childTokens:{}};return e.forEach(n=>{let s={...n};if(s.async=this.defaults.async||s.async||!1,n.extensions&&(n.extensions.forEach(r=>{if(!r.name)throw new Error("extension name required");if("renderer"in r){let i=t.renderers[r.name];i?t.renderers[r.name]=function(...o){let a=r.renderer.apply(this,o);return a===!1&&(a=i.apply(this,o)),a}:t.renderers[r.name]=r.renderer}if("tokenizer"in r){if(!r.level||r.level!=="block"&&r.level!=="inline")throw new Error("extension level must be 'block' or 'inline'");let i=t[r.level];i?i.unshift(r.tokenizer):t[r.level]=[r.tokenizer],r.start&&(r.level==="block"?t.startBlock?t.startBlock.push(r.start):t.startBlock=[r.start]:r.level==="inline"&&(t.startInline?t.startInline.push(r.start):t.startInline=[r.start]))}"childTokens"in r&&r.childTokens&&(t.childTokens[r.name]=r.childTokens)}),s.extensions=t),n.renderer){let r=this.defaults.renderer||new $s(this.defaults);for(let i in n.renderer){if(!(i in r))throw new Error(`renderer '${i}' does not exist`);if(["options","parser"].includes(i))continue;let o=i,a=n.renderer[o],l=r[o];r[o]=(...f)=>{let u=a.apply(r,f);return u===!1&&(u=l.apply(r,f)),u||""}}s.renderer=r}if(n.tokenizer){let r=this.defaults.tokenizer||new Ls(this.defaults);for(let i in n.tokenizer){if(!(i in r))throw new Error(`tokenizer '${i}' does not exist`);if(["options","rules","lexer"].includes(i))continue;let o=i,a=n.tokenizer[o],l=r[o];r[o]=(...f)=>{let u=a.apply(r,f);return u===!1&&(u=l.apply(r,f)),u}}s.tokenizer=r}if(n.hooks){let r=this.defaults.hooks||new Zn;for(let i in n.hooks){if(!(i in r))throw new Error(`hook '${i}' does not exist`);if(["options","block"].includes(i))continue;let o=i,a=n.hooks[o],l=r[o];Zn.passThroughHooks.has(i)?r[o]=f=>{if(this.defaults.async&&Zn.passThroughHooksRespectAsync.has(i))return(async()=>{let d=await a.call(r,f);return l.call(r,d)})();let u=a.call(r,f);return l.call(r,u)}:r[o]=(...f)=>{if(this.defaults.async)return(async()=>{let d=await a.apply(r,f);return d===!1&&(d=await l.apply(r,f)),d})();let u=a.apply(r,f);return u===!1&&(u=l.apply(r,f)),u}}s.hooks=r}if(n.walkTokens){let r=this.defaults.walkTokens,i=n.walkTokens;s.walkTokens=function(o){let a=[];return a.push(i.call(this,o)),r&&(a=a.concat(r.call(this,o))),a}}this.defaults={...this.defaults,...s}}),this}setOptions(e){return this.defaults={...this.defaults,...e},this}lexer(e,t){return yt.lex(e,t!=null?t:this.defaults)}parser(e,t){return wt.parse(e,t!=null?t:this.defaults)}parseMarkdown(e){return(t,n)=>{let s={...n},r={...this.defaults,...s},i=this.onError(!!r.silent,!!r.async);if(this.defaults.async===!0&&s.async===!1)return i(new Error("marked(): The async option was set to true by an extension. Remove async: false from the parse options object to return a Promise."));if(typeof t>"u"||t===null)return i(new Error("marked(): input parameter is undefined or null"));if(typeof t!="string")return i(new Error("marked(): input parameter is of type "+Object.prototype.toString.call(t)+", string expected"));if(r.hooks&&(r.hooks.options=r,r.hooks.block=e),r.async)return(async()=>{let o=r.hooks?await r.hooks.preprocess(t):t,a=await(r.hooks?await r.hooks.provideLexer(e):e?yt.lex:yt.lexInline)(o,r),l=r.hooks?await r.hooks.processAllTokens(a):a;r.walkTokens&&await Promise.all(this.walkTokens(l,r.walkTokens));let f=await(r.hooks?await r.hooks.provideParser(e):e?wt.parse:wt.parseInline)(l,r);return r.hooks?await r.hooks.postprocess(f):f})().catch(i);try{r.hooks&&(t=r.hooks.preprocess(t));let o=(r.hooks?r.hooks.provideLexer(e):e?yt.lex:yt.lexInline)(t,r);r.hooks&&(o=r.hooks.processAllTokens(o)),r.walkTokens&&this.walkTokens(o,r.walkTokens);let a=(r.hooks?r.hooks.provideParser(e):e?wt.parse:wt.parseInline)(o,r);return r.hooks&&(a=r.hooks.postprocess(a)),a}catch(o){return i(o)}}}onError(e,t){return n=>{if(n.message+=` -Please report this to https://github.com/markedjs/marked.`,e){let s=" An error occurred:
"+Ct(n.message+"",!0)+"";return t?Promise.resolve(s):s}if(t)return Promise.reject(n);throw n}}},pn=new vf;function xe(e,t){return pn.parse(e,t)}xe.options=xe.setOptions=function(e){return pn.setOptions(e),xe.defaults=pn.defaults,Ho(xe.defaults),xe},xe.getDefaults=Sr,xe.defaults=cn,xe.use=function(...e){return pn.use(...e),xe.defaults=pn.defaults,Ho(xe.defaults),xe},xe.walkTokens=function(e,t){return pn.walkTokens(e,t)},xe.parseInline=pn.parseInline,xe.Parser=wt,xe.parser=wt.parse,xe.Renderer=$s,xe.TextRenderer=Lr,xe.Lexer=yt,xe.lexer=yt.lex,xe.Tokenizer=Ls,xe.Hooks=Zn,xe.parse=xe,xe.options,xe.setOptions,xe.use,xe.walkTokens,xe.parseInline,wt.parse,yt.lex;function sl(e,t){(t==null||t>e.length)&&(t=e.length);for(var n=0,s=Array(t);n2?s-2:0),i=2;i 1?n-1:0),r=1;r1?n-1:0),r=1;r 2&&arguments[2]!==void 0?arguments[2]:Xn;if(il&&il(e,null),!Xe(t))return e;let s=t.length;for(;s--;){let r=t[s];if(typeof r=="string"){const i=n(r);i!==r&&(Af(t)||(t[s]=i),r=i)}e[r]=!0}return e}function Df(e){for(let t=0;t /g),jf=dt(/\${[\w\W]*/g),Vf=dt(/^data-[\-\w.\u00B7-\uFFFF]+$/),qf=dt(/^aria-[\-\w]+$/),ml=dt(/^(?:(?:(?:f|ht)tps?|mailto|tel|callto|sms|cid|xmpp|matrix):|[^a-z]|[a-z+.\-]+(?:[^a-z+.\-:]|$))/i),Wf=dt(/^(?:\w+script|data):/i),Gf=dt(/[\u0000-\u0020\u00A0\u1680\u180E\u2000-\u2029\u205F\u3000]/g),Kf=dt(/^html$/i),Yf=dt(/^[a-z][.\w]*(-[.\w]+)+$/i),Rn={element:1,text:3,progressingInstruction:7,comment:8,document:9},Zf=function(){return typeof window=="undefined"?null:window},Xf=function(t,n){if(typeof t!="object"||typeof t.createPolicy!="function")return null;let s=null;const r="data-tt-policy-suffix";n&&n.hasAttribute(r)&&(s=n.getAttribute(r));const i="dompurify"+(s?"#"+s:"");try{return t.createPolicy(i,{createHTML(o){return o},createScriptURL(o){return o}})}catch{return null}},bl=function(){return{afterSanitizeAttributes:[],afterSanitizeElements:[],afterSanitizeShadowDOM:[],beforeSanitizeAttributes:[],beforeSanitizeElements:[],beforeSanitizeShadowDOM:[],uponSanitizeAttribute:[],uponSanitizeElement:[],uponSanitizeShadowNode:[]}};function xl(){let e=arguments.length>0&&arguments[0]!==void 0?arguments[0]:Zf();const t=q=>xl(q);if(t.version="3.4.3",t.removed=[],!e||!e.document||e.document.nodeType!==Rn.document||!e.Element)return t.isSupported=!1,t;let n=e.document;const s=n,r=s.currentScript,i=e.DocumentFragment,o=e.HTMLTemplateElement,a=e.Node,l=e.Element,f=e.NodeFilter,u=e.NamedNodeMap,d=u===void 0?e.NamedNodeMap||e.MozNamedAttrMap:u,g=e.HTMLFormElement,y=e.DOMParser,E=e.trustedTypes,x=l.prototype,M=An(x,"cloneNode"),m=An(x,"remove"),H=An(x,"nextSibling"),Y=An(x,"childNodes"),$=An(x,"parentNode");if(typeof o=="function"){const q=n.createElement("template");q.content&&q.content.ownerDocument&&(n=q.content.ownerDocument)}let z,O="";const P=n,ee=P.implementation,V=P.createNodeIterator,se=P.createDocumentFragment,fe=P.getElementsByTagName,D=s.importNode;let Z=bl();t.isSupported=typeof rl=="function"&&typeof $=="function"&&ee&&ee.createHTMLDocument!==void 0;const Se=zf,Ue=Uf,te=jf,C=Vf,pe=qf,Ge=Wf,re=Gf,B=Yf;let de=ml,ae=null;const ve=X({},[...pl,...Fr,...Br,...Hr,...dl]);let ge=null;const nt=X({},[...hl,...zr,...gl,...Ns]);let ye=Object.seal(Tn(null,{tagNameCheck:{writable:!0,configurable:!1,enumerable:!0,value:null},attributeNameCheck:{writable:!0,configurable:!1,enumerable:!0,value:null},allowCustomizedBuiltInElements:{writable:!0,configurable:!1,enumerable:!0,value:!1}})),ht=null,G=null;const Ce=Object.seal(Tn(null,{tagCheck:{writable:!0,configurable:!1,enumerable:!0,value:null},attributeCheck:{writable:!0,configurable:!1,enumerable:!0,value:null}}));let Ft=!0,c=!0,h=!1,b=!0,k=!1,v=!0,_=!1,I=!1,R=!1,A=!1,S=!1,U=!1,L=!0,j=!1;const K="user-content-";let ne=!0,he=!1,ie={},ke=null;const $e=X({},["annotation-xml","audio","colgroup","desc","foreignobject","head","iframe","math","mi","mn","mo","ms","mtext","noembed","noframes","noscript","plaintext","script","style","svg","template","thead","title","video","xmp"]);let ot=null;const lt=X({},["audio","video","img","source","image","track"]);let Bt=null;const Jn=X({},["alt","class","for","id","label","name","pattern","placeholder","role","summary","title","value","style","xmlns"]),De="http://www.w3.org/1998/Math/MathML",Qe="http://www.w3.org/2000/svg",at="http://www.w3.org/1999/xhtml";let Ht=at,Ur=!1,jr=null;const hd=X({},[De,Qe,at],Nr);let Vr=X({},["mi","mo","mn","ms","mtext"]),qr=X({},["annotation-xml"]);const gd=X({},["title","style","font","a","script"]);let es=null;const md=["application/xhtml+xml","text/html"],bd="text/html";let Le=null,Cn=null;const xd=n.createElement("form"),Sl=function(p){return p instanceof RegExp||p instanceof Function},Wr=function(){let p=arguments.length>0&&arguments[0]!==void 0?arguments[0]:{};if(Cn&&Cn===p)return;(!p||typeof p!="object")&&(p={}),p=tt(p),es=md.indexOf(p.PARSER_MEDIA_TYPE)===-1?bd:p.PARSER_MEDIA_TYPE,Le=es==="application/xhtml+xml"?Nr:Xn,ae=Ae(p,"ALLOWED_TAGS")&&Xe(p.ALLOWED_TAGS)?X({},p.ALLOWED_TAGS,Le):ve,ge=Ae(p,"ALLOWED_ATTR")&&Xe(p.ALLOWED_ATTR)?X({},p.ALLOWED_ATTR,Le):nt,jr=Ae(p,"ALLOWED_NAMESPACES")&&Xe(p.ALLOWED_NAMESPACES)?X({},p.ALLOWED_NAMESPACES,Nr):hd,Bt=Ae(p,"ADD_URI_SAFE_ATTR")&&Xe(p.ADD_URI_SAFE_ATTR)?X(tt(Jn),p.ADD_URI_SAFE_ATTR,Le):Jn,ot=Ae(p,"ADD_DATA_URI_TAGS")&&Xe(p.ADD_DATA_URI_TAGS)?X(tt(lt),p.ADD_DATA_URI_TAGS,Le):lt,ke=Ae(p,"FORBID_CONTENTS")&&Xe(p.FORBID_CONTENTS)?X({},p.FORBID_CONTENTS,Le):$e,ht=Ae(p,"FORBID_TAGS")&&Xe(p.FORBID_TAGS)?X({},p.FORBID_TAGS,Le):tt({}),G=Ae(p,"FORBID_ATTR")&&Xe(p.FORBID_ATTR)?X({},p.FORBID_ATTR,Le):tt({}),ie=Ae(p,"USE_PROFILES")?p.USE_PROFILES&&typeof p.USE_PROFILES=="object"?tt(p.USE_PROFILES):p.USE_PROFILES:!1,Ft=p.ALLOW_ARIA_ATTR!==!1,c=p.ALLOW_DATA_ATTR!==!1,h=p.ALLOW_UNKNOWN_PROTOCOLS||!1,b=p.ALLOW_SELF_CLOSE_IN_ATTR!==!1,k=p.SAFE_FOR_TEMPLATES||!1,v=p.SAFE_FOR_XML!==!1,_=p.WHOLE_DOCUMENT||!1,A=p.RETURN_DOM||!1,S=p.RETURN_DOM_FRAGMENT||!1,U=p.RETURN_TRUSTED_TYPE||!1,R=p.FORCE_BODY||!1,L=p.SANITIZE_DOM!==!1,j=p.SANITIZE_NAMED_PROPS||!1,ne=p.KEEP_CONTENT!==!1,he=p.IN_PLACE||!1,de=Ff(p.ALLOWED_URI_REGEXP)?p.ALLOWED_URI_REGEXP:ml,Ht=typeof p.NAMESPACE=="string"?p.NAMESPACE:at,Vr=Ae(p,"MATHML_TEXT_INTEGRATION_POINTS")&&p.MATHML_TEXT_INTEGRATION_POINTS&&typeof p.MATHML_TEXT_INTEGRATION_POINTS=="object"?tt(p.MATHML_TEXT_INTEGRATION_POINTS):X({},["mi","mo","mn","ms","mtext"]),qr=Ae(p,"HTML_INTEGRATION_POINTS")&&p.HTML_INTEGRATION_POINTS&&typeof p.HTML_INTEGRATION_POINTS=="object"?tt(p.HTML_INTEGRATION_POINTS):X({},["annotation-xml"]);const T=Ae(p,"CUSTOM_ELEMENT_HANDLING")&&p.CUSTOM_ELEMENT_HANDLING&&typeof p.CUSTOM_ELEMENT_HANDLING=="object"?tt(p.CUSTOM_ELEMENT_HANDLING):Tn(null);if(ye=Tn(null),Ae(T,"tagNameCheck")&&Sl(T.tagNameCheck)&&(ye.tagNameCheck=T.tagNameCheck),Ae(T,"attributeNameCheck")&&Sl(T.attributeNameCheck)&&(ye.attributeNameCheck=T.attributeNameCheck),Ae(T,"allowCustomizedBuiltInElements")&&typeof T.allowCustomizedBuiltInElements=="boolean"&&(ye.allowCustomizedBuiltInElements=T.allowCustomizedBuiltInElements),k&&(c=!1),S&&(A=!0),ie&&(ae=X({},dl),ge=Tn(null),ie.html===!0&&(X(ae,pl),X(ge,hl)),ie.svg===!0&&(X(ae,Fr),X(ge,zr),X(ge,Ns)),ie.svgFilters===!0&&(X(ae,Br),X(ge,zr),X(ge,Ns)),ie.mathMl===!0&&(X(ae,Hr),X(ge,gl),X(ge,Ns))),Ce.tagCheck=null,Ce.attributeCheck=null,Ae(p,"ADD_TAGS")&&(typeof p.ADD_TAGS=="function"?Ce.tagCheck=p.ADD_TAGS:Xe(p.ADD_TAGS)&&(ae===ve&&(ae=tt(ae)),X(ae,p.ADD_TAGS,Le))),Ae(p,"ADD_ATTR")&&(typeof p.ADD_ATTR=="function"?Ce.attributeCheck=p.ADD_ATTR:Xe(p.ADD_ATTR)&&(ge===nt&&(ge=tt(ge)),X(ge,p.ADD_ATTR,Le))),Ae(p,"ADD_URI_SAFE_ATTR")&&Xe(p.ADD_URI_SAFE_ATTR)&&X(Bt,p.ADD_URI_SAFE_ATTR,Le),Ae(p,"FORBID_CONTENTS")&&Xe(p.FORBID_CONTENTS)&&(ke===$e&&(ke=tt(ke)),X(ke,p.FORBID_CONTENTS,Le)),Ae(p,"ADD_FORBID_CONTENTS")&&Xe(p.ADD_FORBID_CONTENTS)&&(ke===$e&&(ke=tt(ke)),X(ke,p.ADD_FORBID_CONTENTS,Le)),ne&&(ae["#text"]=!0),_&&X(ae,["html","head","body"]),ae.table&&(X(ae,["tbody"]),delete ht.tbody),p.TRUSTED_TYPES_POLICY){if(typeof p.TRUSTED_TYPES_POLICY.createHTML!="function")throw Ds('TRUSTED_TYPES_POLICY configuration option must provide a "createHTML" hook.');if(typeof p.TRUSTED_TYPES_POLICY.createScriptURL!="function")throw Ds('TRUSTED_TYPES_POLICY configuration option must provide a "createScriptURL" hook.');z=p.TRUSTED_TYPES_POLICY,O=z.createHTML("")}else z===void 0&&(z=Xf(E,r)),z!==null&&typeof O=="string"&&(O=z.createHTML(""));Ze&&Ze(p),Cn=p},El=X({},[...Fr,...Br,...Bf]),Al=X({},[...Hr,...Hf]),yd=function(p){let T=$(p);(!T||!T.tagName)&&(T={namespaceURI:Ht,tagName:"template"});const N=Xn(p.tagName),ce=Xn(T.tagName);return jr[p.namespaceURI]?p.namespaceURI===Qe?T.namespaceURI===at?N==="svg":T.namespaceURI===De?N==="svg"&&(ce==="annotation-xml"||Vr[ce]):!!El[N]:p.namespaceURI===De?T.namespaceURI===at?N==="math":T.namespaceURI===Qe?N==="math"&&qr[ce]:!!Al[N]:p.namespaceURI===at?T.namespaceURI===Qe&&!qr[ce]||T.namespaceURI===De&&!Vr[ce]?!1:!Al[N]&&(gd[N]||!El[N]):!!(es==="application/xhtml+xml"&&jr[p.namespaceURI]):!1},vt=function(p){Sn(t.removed,{element:p});try{$(p).removeChild(p)}catch{m(p)}},dn=function(p,T){try{Sn(t.removed,{attribute:T.getAttributeNode(p),from:T})}catch{Sn(t.removed,{attribute:null,from:T})}if(T.removeAttribute(p),p==="is")if(A||S)try{vt(T)}catch{}else try{T.setAttribute(p,"")}catch{}},Rl=function(p){let T=null,N=null;if(R)p=" "+p;else{const Me=al(p,/^[\r\n\t ]+/);N=Me&&Me[0]}es==="application/xhtml+xml"&&Ht===at&&(p=''+p+"");const ce=z?z.createHTML(p):p;if(Ht===at)try{T=new y().parseFromString(ce,es)}catch{}if(!T||!T.documentElement){T=ee.createDocument(Ht,"template",null);try{T.documentElement.innerHTML=Ur?O:ce}catch{}}const Ne=T.body||T.documentElement;return p&&N&&Ne.insertBefore(n.createTextNode(N),Ne.childNodes[0]||null),Ht===at?fe.call(T,_?"html":"body")[0]:_?T.documentElement:Ne},Cl=function(p){return V.call(p.ownerDocument||p,p,f.SHOW_ELEMENT|f.SHOW_COMMENT|f.SHOW_TEXT|f.SHOW_PROCESSING_INSTRUCTION|f.SHOW_CDATA_SECTION,null)},Gr=function(p){return p instanceof g&&(typeof p.nodeName!="string"||typeof p.textContent!="string"||typeof p.removeChild!="function"||!(p.attributes instanceof d)||typeof p.removeAttribute!="function"||typeof p.setAttribute!="function"||typeof p.namespaceURI!="string"||typeof p.insertBefore!="function"||typeof p.hasChildNodes!="function")},Kr=function(p){return typeof a=="function"&&p instanceof a};function zt(q,p,T){kn(q,N=>{N.call(t,p,T,Cn)})}const Pl=function(p){let T=null;if(zt(Z.beforeSanitizeElements,p,null),Gr(p))return vt(p),!0;const N=Le(p.nodeName);if(zt(Z.uponSanitizeElement,p,{tagName:N,allowedTags:ae}),v&&p.hasChildNodes()&&!Kr(p.firstElementChild)&&ze(/<[/\w!]/g,p.innerHTML)&&ze(/<[/\w!]/g,p.textContent)||v&&p.namespaceURI===at&&N==="style"&&Kr(p.firstElementChild)||p.nodeType===Rn.progressingInstruction||v&&p.nodeType===Rn.comment&&ze(/<[/\w]/g,p.data))return vt(p),!0;if(ht[N]||!(Ce.tagCheck instanceof Function&&Ce.tagCheck(N))&&!ae[N]){if(!ht[N]&&Ml(N)&&(ye.tagNameCheck instanceof RegExp&&ze(ye.tagNameCheck,N)||ye.tagNameCheck instanceof Function&&ye.tagNameCheck(N)))return!1;if(ne&&!ke[N]){const ce=$(p)||p.parentNode,Ne=Y(p)||p.childNodes;if(Ne&&ce){const Me=Ne.length;for(let st=Me-1;st>=0;--st){const gt=M(Ne[st],!0);ce.insertBefore(gt,H(p))}}}return vt(p),!0}return p instanceof l&&!yd(p)||(N==="noscript"||N==="noembed"||N==="noframes")&&ze(/<\/no(script|embed|frames)/i,p.innerHTML)?(vt(p),!0):(k&&p.nodeType===Rn.text&&(T=p.textContent,kn([Se,Ue,te],ce=>{T=En(T,ce," ")}),p.textContent!==T&&(Sn(t.removed,{element:p.cloneNode()}),p.textContent=T)),zt(Z.afterSanitizeElements,p,null),!1)},Il=function(p,T,N){if(G[T]||L&&(T==="id"||T==="name")&&(N in n||N in xd))return!1;const ce=ge[T]||Ce.attributeCheck instanceof Function&&Ce.attributeCheck(T,p);if(!(c&&!G[T]&&ze(C,T))){if(!(Ft&&ze(pe,T))){if(!ce||G[T]){if(!(Ml(p)&&(ye.tagNameCheck instanceof RegExp&&ze(ye.tagNameCheck,p)||ye.tagNameCheck instanceof Function&&ye.tagNameCheck(p))&&(ye.attributeNameCheck instanceof RegExp&&ze(ye.attributeNameCheck,T)||ye.attributeNameCheck instanceof Function&&ye.attributeNameCheck(T,p))||T==="is"&&ye.allowCustomizedBuiltInElements&&(ye.tagNameCheck instanceof RegExp&&ze(ye.tagNameCheck,N)||ye.tagNameCheck instanceof Function&&ye.tagNameCheck(N))))return!1}else if(!Bt[T]){if(!ze(de,En(N,re,""))){if(!((T==="src"||T==="xlink:href"||T==="href")&&p!=="script"&&ul(N,"data:")===0&&ot[p])){if(!(h&&!ze(Ge,En(N,re,"")))){if(N)return!1}}}}}}return!0},wd=X({},["annotation-xml","color-profile","font-face","font-face-format","font-face-name","font-face-src","font-face-uri","missing-glyph"]),Ml=function(p){return!wd[Xn(p)]&&ze(B,p)},Ol=function(p){zt(Z.beforeSanitizeAttributes,p,null);const T=p.attributes;if(!T||Gr(p))return;const N={attrName:"",attrValue:"",keepAttr:!0,allowedAttributes:ge,forceKeepAttr:void 0};let ce=T.length;for(;ce--;){const Ne=T[ce],Me=Ne.name,st=Ne.namespaceURI,gt=Ne.value,_t=Le(Me),Zr=gt;let Fe=Me==="value"?Zr:Mf(Zr);if(N.attrName=_t,N.attrValue=Fe,N.keepAttr=!0,N.forceKeepAttr=void 0,zt(Z.uponSanitizeAttribute,p,N),Fe=N.attrValue,j&&(_t==="id"||_t==="name")&&ul(Fe,K)!==0&&(dn(Me,p),Fe=K+Fe),v&&ze(/((--!?|])>)|<\/(style|script|title|xmp|textarea|noscript|iframe|noembed|noframes)/i,Fe)){dn(Me,p);continue}if(_t==="attributename"&&al(Fe,"href")){dn(Me,p);continue}if(N.forceKeepAttr)continue;if(!N.keepAttr){dn(Me,p);continue}if(!b&&ze(/\/>/i,Fe)){dn(Me,p);continue}k&&kn([Se,Ue,te],$l=>{Fe=En(Fe,$l," ")});const Ll=Le(p.nodeName);if(!Il(Ll,_t,Fe)){dn(Me,p);continue}if(z&&typeof E=="object"&&typeof E.getAttributeType=="function"&&!st)switch(E.getAttributeType(Ll,_t)){case"TrustedHTML":{Fe=z.createHTML(Fe);break}case"TrustedScriptURL":{Fe=z.createScriptURL(Fe);break}}if(Fe!==Zr)try{st?p.setAttributeNS(st,Me,Fe):p.setAttribute(Me,Fe),Gr(p)?vt(p):ll(t.removed)}catch{dn(Me,p)}}zt(Z.afterSanitizeAttributes,p,null)},Yr=function(p){let T=null;const N=Cl(p);for(zt(Z.beforeSanitizeShadowDOM,p,null);T=N.nextNode();)zt(Z.uponSanitizeShadowNode,T,null),Pl(T),Ol(T),T.content instanceof i&&Yr(T.content);zt(Z.afterSanitizeShadowDOM,p,null)},Bs=function(p){if(p.nodeType===Rn.element&&p.shadowRoot instanceof i){const ce=p.shadowRoot;Bs(ce),Yr(ce)}const T=p.childNodes;if(!T)return;const N=[];kn(T,ce=>{Sn(N,ce)});for(const ce of N)Bs(ce)};return t.sanitize=function(q){let p=arguments.length>1&&arguments[1]!==void 0?arguments[1]:{},T=null,N=null,ce=null,Ne=null;if(Ur=!q,Ur&&(q=""),typeof q!="string"&&!Kr(q)&&(q=Nf(q),typeof q!="string"))throw Ds("dirty is not a string, aborting");if(!t.isSupported)return q;if(I||Wr(p),t.removed=[],typeof q=="string"&&(he=!1),he){const gt=q.nodeName;if(typeof gt=="string"){const _t=Le(gt);if(!ae[_t]||ht[_t])throw Ds("root node is forbidden and cannot be sanitized in-place")}Bs(q)}else if(q instanceof a)T=Rl(""),N=T.ownerDocument.importNode(q,!0),N.nodeType===Rn.element&&N.nodeName==="BODY"||N.nodeName==="HTML"?T=N:T.appendChild(N),Bs(N);else{if(!A&&!k&&!_&&q.indexOf("<")===-1)return z&&U?z.createHTML(q):q;if(T=Rl(q),!T)return A?null:U?O:""}T&&R&&vt(T.firstChild);const Me=Cl(he?q:T);for(;ce=Me.nextNode();)Pl(ce),Ol(ce),ce.content instanceof i&&Yr(ce.content);if(he)return q;if(A){if(k){T.normalize();let gt=T.innerHTML;kn([Se,Ue,te],_t=>{gt=En(gt,_t," ")}),T.innerHTML=gt}if(S)for(Ne=se.call(T.ownerDocument);T.firstChild;)Ne.appendChild(T.firstChild);else Ne=T;return(ge.shadowroot||ge.shadowrootmode)&&(Ne=D.call(s,Ne,!0)),Ne}let st=_?T.outerHTML:T.innerHTML;return _&&ae["!doctype"]&&T.ownerDocument&&T.ownerDocument.doctype&&T.ownerDocument.doctype.name&&ze(Kf,T.ownerDocument.doctype.name)&&(st=" -`+st),k&&kn([Se,Ue,te],gt=>{st=En(st,gt," ")}),z&&U?z.createHTML(st):st},t.setConfig=function(){let q=arguments.length>0&&arguments[0]!==void 0?arguments[0]:{};Wr(q),I=!0},t.clearConfig=function(){Cn=null,I=!1},t.isValidAttribute=function(q,p,T){Cn||Wr({});const N=Le(q),ce=Le(p);return Il(N,ce,T)},t.addHook=function(q,p){typeof p=="function"&&Sn(Z[q],p)},t.removeHook=function(q,p){if(p!==void 0){const T=Pf(Z[q],p);return T===-1?void 0:If(Z[q],T,1)[0]}return ll(Z[q])},t.removeHooks=function(q){Z[q]=[]},t.removeAllHooks=function(){Z=bl()},t}var Qf=xl();const Jf={key:1,class:"flex min-w-0 max-w-[calc(100%-2.5rem)] flex-1 flex-col max-[600px]:max-w-[calc(100%-2.25rem)]"},ep={key:0,class:"flex w-fit flex-col items-start gap-1"},tp=["aria-label"],np={class:"inline-flex items-center gap-1.5"},sp={class:"text-[8px] font-semibold tracking-[0.12em] uppercase text-[#3a67c9]"},rp={key:1,class:"flex w-fit max-w-full flex-col items-start gap-2"},ip={class:"chat-card relative w-fit max-w-full whitespace-pre-line rounded-[10px_10px_10px_3px] px-4 py-3 text-xs leading-relaxed wrap-anywhere text-slate-900"},op=["innerHTML"],lp={key:0,class:"pointer-events-none absolute inset-x-0 bottom-0 h-14 rounded-b-[10px] bg-linear-to-t from-white via-white/92 to-white/0","aria-hidden":"true"},ap={key:0,class:"flex flex-wrap items-center gap-2"},up=["title","aria-label"],cp={key:1,class:"flex flex-wrap items-center"},fp=["title","aria-label"],pp={viewBox:"0 0 24 24",width:"14",height:"14",fill:"none",stroke:"currentColor","stroke-width":"2","aria-hidden":"true"},dp=["innerHTML"],yl={__name:"ChatMessage",props:{message:{type:Object,required:!0},autoReadEnabled:{type:Boolean,default:!1},ttsConfig:{type:Object,default:()=>({enableVoiceChat:!1,pollyAvailable:!1,usePolly:!0,voiceId:"Zayd"})}},setup(e){const t=e,n=J(!1),s=J(null),r=J(!1),i=J(!1),o=Ee(()=>typeof window!="undefined"&&"speechSynthesis"in window&&"SpeechSynthesisUtterance"in window);function a(O){typeof window!="undefined"&&window.dispatchEvent(new CustomEvent("changai-tts-provider",{detail:{provider:O}}))}function l(O){if(typeof O!="string")return"";const P=O.replace(/[\u{1F000}-\u{1FFFF}]/gu,"").replace(/[\u{2600}-\u{26FF}]/gu,"").replace(/[\u{2700}-\u{27BF}]/gu,"").replace(/\*\*(.*?)\*\*/g,"$1").replace(/\*(.*?)\*/g,"$1").replace(/`([^`]+)`/g,"$1").replace(/#{1,6}\s+/g,"").replace(/[-*+]\s+/g,"").replace(/\[([^\]]+)\]\([^)]+\)/g,"$1").replace(/\s+/g," ");return P.includes("<")?(new DOMParser().parseFromString(O,"text/html").body.textContent||"").replace(/\s+/g," ").trim():P.trim()}function f(){o.value&&window.speechSynthesis.cancel(),s.value&&(s.value.pause(),s.value.src="",s.value=null),n.value=!1}function u(){var O,P,ee;if(i.value=!i.value,i.value)f();else{const V=M.value;if(!t.autoReadEnabled||!((O=t.ttsConfig)!=null&&O.enableVoiceChat)||!V||E())return;if((P=t.ttsConfig)!=null&&P.pollyAvailable&&((ee=t.ttsConfig)!=null&&ee.usePolly)){g(V).catch(se=>{d(V)});return}d(V)}}function d(O){if(!o.value||!O)return;window.dispatchEvent(new CustomEvent("changai-tts-stop")),window.speechSynthesis.cancel();const P=new SpeechSynthesisUtterance(O);P.rate=1,P.pitch=1,P.onend=()=>{n.value=!1},P.onerror=()=>{n.value=!1},n.value=!0,a("browser"),window.speechSynthesis.speak(P)}async function g(O){var fe;const P=await Oc(O,((fe=t.ttsConfig)==null?void 0:fe.voiceId)||"Zayd");if(!(P!=null&&P.ok)||!(P!=null&&P.audio_base64))throw new Error((P==null?void 0:P.error)||"Polly synthesis failed");window.dispatchEvent(new CustomEvent("changai-tts-stop")),f();const ee=(P==null?void 0:P.mime_type)||"audio/mpeg",V=new Audio(`data:${ee};base64,${P.audio_base64}`);s.value=V,n.value=!0;let se=!1;V.onplay=()=>{se=!0,a("polly")},V.onended=()=>{s.value===V&&(s.value=null),n.value=!1},V.onerror=()=>{s.value===V&&(s.value=null),n.value=!1},await V.play(),se||a("polly")}function y(){f()}function E(){var O;return!!((O=t.message)!=null&&O.isStatus)}function x(O){const P=O.target.closest("a");!P||!P.href||(O.preventDefault(),O.stopPropagation(),window.open(P.href,"_blank","noopener,noreferrer"))}const M=Ee(()=>{var O;return l(((O=t.message)==null?void 0:O.text)||"")}),m=Ee(()=>{var O;return((O=t.message)==null?void 0:O.role)!=="user"&&E()}),H=Ee(()=>{var O;return(O=t.message)!=null&&O.isStatus?t.message.statusType==="support"?"Sending to support":M.value||"Thinking":""}),Y=Ee(()=>{var ee;if(((ee=t.message)==null?void 0:ee.role)==="user"||m.value)return!1;const O=M.value,P=O.split(/\n+/).filter(Boolean).length;return O.length>520||P>8}),$=Ee(()=>{var O,P;return((O=t.message)==null?void 0:O.role)!=="user"&&!m.value&&((P=t.ttsConfig)==null?void 0:P.enableVoiceChat)}),z=Ee(()=>{var P;const O=((P=t.message)==null?void 0:P.text)||"";return Qf.sanitize(xe.parse(O))});return on(()=>t.message.text,async(O,P)=>{var se,fe,D;if(!t.autoReadEnabled||t.message.role==="user"||i.value)return;if(!((se=t.ttsConfig)!=null&&se.enableVoiceChat)){a("off");return}const ee=l(O);if(!ee||E())return;const V=l(P||"");if(ee!==V){if((fe=t.ttsConfig)!=null&&fe.pollyAvailable&&((D=t.ttsConfig)!=null&&D.usePolly))try{await g(ee);return}catch{}d(ee)}}),on(()=>t.message.text,()=>{r.value=!1,i.value=!1}),zn(()=>{typeof window!="undefined"&&window.addEventListener("changai-tts-stop",y)}),ys(()=>{typeof window!="undefined"&&window.removeEventListener("changai-tts-stop",y),n.value&&f()}),(O,P)=>(F(),W("div",{class:we(["motion-safe:animate-fade-rise flex w-full gap-1.5",e.message.role==="user"?"flex-col items-end":"items-start"])},[e.message.role!=="user"?(F(),Et(Fo,{key:0})):qe("",!0),e.message.role!=="user"?(F(),W("div",Jf,[m.value?(F(),W("div",ep,[w("div",{class:"chat-card inline-flex w-fit rounded-[10px_10px_10px_3px] px-3 py-2",role:"status","aria-live":"polite","aria-label":H.value},[w("div",np,[P[1]||(P[1]=w("span",{class:"relative inline-flex h-4 w-4 shrink-0 items-center justify-center"},[w("span",{class:"absolute inset-0 rounded-full border border-transparent border-t-[#4b89ff] border-r-[#4b89ff]/70 animate-gemini-arc"}),w("svg",{viewBox:"0 0 24 24",class:"relative h-3 w-3 text-[#4b89ff] animate-gemini-spark","aria-hidden":"true"},[w("path",{fill:"currentColor",d:"M12 2.8c.52 3.22 1.6 5.66 3.22 7.28 1.62 1.62 4.06 2.7 7.28 3.22-3.22.52-5.66 1.6-7.28 3.22-1.62 1.62-2.7 4.06-3.22 7.28-.52-3.22-1.6-5.66-3.22-7.28-1.62-1.62-4.06-2.7-7.28-3.22 3.22-.52 5.66-1.6 7.28-3.22 1.62-1.62 2.7-4.06 3.22-7.28Z"})])],-1)),w("span",sp,Je(H.value),1)])],8,tp)])):(F(),W("div",rp,[w("div",ip,[w("div",{class:we(["overflow-x-auto",Y.value&&!r.value?"max-h-48 overflow-y-hidden":""]),innerHTML:z.value,onClick:x},null,10,op),Y.value&&!r.value?(F(),W("div",lp)):qe("",!0)]),Y.value?(F(),W("div",ap,[w("button",{type:"button",class:"inline-flex items-center rounded-full border border-slate-200 bg-white px-2.5 py-1 text-[10px] font-semibold uppercase tracking-[0.08em] text-slate-600 transition-colors duration-200 hover:border-brand-200 hover:text-brand-600",title:r.value?"Collapse response":"Expand response","aria-label":r.value?"Collapse response":"Expand response",onClick:P[0]||(P[0]=ee=>r.value=!r.value)},Je(r.value?"Collapse":"Expand"),9,up)])):qe("",!0),$.value?(F(),W("div",cp,[w("button",{type:"button",class:we(["inline-flex h-8 w-8 items-center justify-center rounded-full border transition-colors duration-200",i.value?"border-red-200 bg-red-50 text-red-600 hover:border-red-300 hover:bg-red-100":"border-green-200 bg-green-50 text-green-600 hover:border-green-300 hover:bg-green-100"]),title:i.value?"Unmute voice playback":"Mute voice playback","aria-label":i.value?"Unmute voice playback":"Mute voice playback",onClick:u},[(F(),W("svg",pp,[P[6]||(P[6]=w("path",{d:"M11 5L6 9H3v6h3l5 4V5Z"},null,-1)),i.value?(F(),W(He,{key:0},[P[2]||(P[2]=w("path",{d:"M15 9l4 6"},null,-1)),P[3]||(P[3]=w("path",{d:"M19 9l-4 6"},null,-1))],64)):(F(),W(He,{key:1},[P[4]||(P[4]=w("path",{d:"M15 10a3 3 0 0 1 0 4"},null,-1)),P[5]||(P[5]=w("path",{d:"M17.5 7.5a6 6 0 0 1 0 9"},null,-1))],64))]))],10,fp)])):qe("",!0)]))])):(F(),W("div",{key:2,class:"w-fit max-w-[85%] whitespace-pre-line rounded-[13px_13px_3px_13px] bg-linear-to-br from-brand-500 to-brand-600 px-4 py-3 text-[11px] leading-relaxed wrap-anywhere text-white shadow-[0_14px_30px_-18px_rgba(109,79,194,0.85)] max-[600px]:max-w-[88%]",innerHTML:z.value},null,8,dp))],2))}},hp={class:"flex flex-col gap-4 sm:gap-5"},gp={class:"motion-safe:animate-fade-rise flex w-full items-start gap-1.5"},mp={__name:"ChatTab",props:{messages:{type:Array,required:!0},autoReadEnabled:{type:Boolean,default:!1},ttsConfig:{type:Object,required:!0}},setup(e){return(t,n)=>(F(),W("div",hp,[w("div",gp,[Oe(Fo),n[0]||(n[0]=w("p",{class:"w-fit max-w-[calc(100%-2.5rem)] whitespace-pre-line rounded-[10px_10px_10px_3px] bg-brand-50 px-4 py-3 text-xs leading-relaxed wrap-anywhere text-slate-900 max-[600px]:max-w-[calc(100%-2.25rem)]"},[Ss(" Hello there 👋 I am ChangAI from "),w("a",{target:"_blank",href:"https://erpgulf.com",rel:"noopener noreferrer",style:{color:"#1e90ff"}},"ERPGulf.com"),Ss(", your ERP assistant."),w("br"),w("a",{target:"_blank",href:"https://app.erpgulf.com/en/articles/chang-ai-quick-start-guide",rel:"noopener noreferrer",style:{color:"#1e90ff"}},"ChangAI Quick Start Guide - Click here.")],-1))]),(F(!0),W(He,null,ws(e.messages,(s,r)=>(F(),Et(yl,{key:r,message:s,autoReadEnabled:e.autoReadEnabled,ttsConfig:e.ttsConfig},null,8,["message","autoReadEnabled","ttsConfig"]))),128))]))}};function wl(e){try{return JSON.stringify(e,null,2)}catch{return String(e)}}function vl(e){var t,n;return(e==null?void 0:e.message)||((t=e==null?void 0:e.responseJSON)==null?void 0:t.exception)||((n=e==null?void 0:e.responseJSON)==null?void 0:n.message)||(e==null?void 0:e.responseText)||String(e)}function bp(e){return typeof e=="string"?e:e&&typeof e=="object"?e.error?`⚠️ ${e.error}`:e.answer||e.text||"":""}const xp={key:0,class:"rounded-lg bg-brand-50 px-4 py-3 text-xs text-black"},yp={class:"whitespace-pre-wrap wrap-anywhere text-[11px] leading-relaxed text-black"},wp={key:1,class:"mb-3 min-w-0 overflow-x-auto rounded-lg bg-brand-50 p-2 text-[11px]"},vp={class:"whitespace-pre-wrap wrap-anywhere text-[11px] leading-relaxed text-black"},_p={__name:"DebugTab",props:{logs:{type:Array,required:!0},currentDebug:{type:Object,default:null}},setup(e){const t=new Set(["gemini_json_content","private_key","private_key_id","client_secret","client_id","aws_access_key","aws_secret_key","api_key","token","access_token","refresh_token","password","secret","authorization","embed_version_id","llm_version_id","entity_retriever","retriever","deploy_url","support_api_url","get_ticket_details_url"]);function n(r,i=0){if(i>10||r===null||r===void 0||typeof r=="string"||typeof r=="number"||typeof r=="boolean")return r;if(Array.isArray(r))return r.map(o=>n(o,i+1));if(typeof r=="object"){const o={};for(const[a,l]of Object.entries(r))t.has(a.toLowerCase())||(o[a]=n(l,i+1));return o}return r}function s(r){return wl(n(r))}return(r,i)=>(F(),W("div",null,[e.logs.length===0?(F(),W("p",xp,"No debug data yet.")):qe("",!0),(F(!0),W(He,null,ws(e.logs,(o,a)=>(F(),W("div",{key:a,class:"mb-3 min-w-0 overflow-x-auto rounded-lg bg-gray-100 p-2 text-[11px]"},[w("pre",yp,Je(s(o)),1)]))),128)),e.currentDebug?(F(),W("div",wp,[w("pre",vp,Je(s(e.currentDebug)),1)])):qe("",!0)]))}},Tp={class:"flex flex-col gap-4 sm:gap-5"},kp={key:0,class:"chat-card motion-safe:animate-fade-rise rounded-lg px-4 py-3 text-xs text-slate-900"},Sp={__name:"SupportTab",props:{messages:{type:Array,required:!0},autoReadEnabled:{type:Boolean,default:!1},ttsConfig:{type:Object,required:!0}},setup(e){return(t,n)=>(F(),W("div",Tp,[e.messages.length===0?(F(),W("p",kp,"Send a message to Support.")):qe("",!0),(F(!0),W(He,null,ws(e.messages,(s,r)=>(F(),Et(yl,{key:r,message:s,autoReadEnabled:e.autoReadEnabled,ttsConfig:e.ttsConfig},null,8,["message","autoReadEnabled","ttsConfig"]))),128))]))}},Ep={class:"flex flex-col gap-4"},Ap={class:"chat-card motion-safe:animate-fade-rise rounded-xl p-4"},Rp={class:"flex items-start justify-between gap-4"},Cp=["aria-pressed","title"],Pp={class:"chat-card motion-safe:animate-fade-rise rounded-xl p-4"},Ip={class:"flex items-start justify-between gap-4"},Mp={class:"mt-2 text-[11px] text-slate-500"},Op={key:0,class:"mt-1 text-[11px] text-slate-500"},Lp={key:1,class:"mt-1 text-[11px] text-slate-500"},$p=["aria-pressed","disabled"],Dp={key:0,class:"mt-3 rounded-md bg-amber-50 px-2.5 py-2 text-xs text-amber-700"},Np={key:1,class:"mt-3 rounded-md bg-amber-50 px-2.5 py-2 text-xs text-amber-700"},Fp={class:"chat-card motion-safe:animate-fade-rise rounded-xl p-4"},Bp={class:"flex items-start justify-between gap-4"},Hp=["aria-pressed","title"],zp={class:"chat-card motion-safe:animate-fade-rise rounded-xl p-4"},Up={class:"flex items-start justify-between gap-4"},jp=["aria-pressed","title"],Vp={__name:"SettingsTab",props:{autoReadEnabled:{type:Boolean,required:!0},ttsConfig:{type:Object,required:!0},settings:{type:Object,default:null},debugEnabled:{type:Boolean,default:!1},sendNonERPtoaiEnabled:{type:Boolean,default:!1}},emits:["toggleAutoRead","togglePollyPreference","toggleDebug","toggleSendNonERP"],setup(e){const t=e,n=Ee(()=>{var s,r;return(s=t.ttsConfig)!=null&&s.enableVoiceChat?(r=t.ttsConfig)!=null&&r.pollyAvailable?"Available":"Unavailable":"Voice disabled on server"});return(s,r)=>{var i,o,a,l,f,u,d,g,y,E,x,M,m,H,Y;return F(),W("div",Ep,[r[10]||(r[10]=w("div",{class:"chat-card motion-safe:animate-fade-rise rounded-xl p-4 text-slate-900"},[w("h3",{class:"text-sm font-semibold tracking-[0.01em]"},"Speech Settings"),w("p",{class:"mt-1 text-xs leading-relaxed text-slate-600"},"These controls apply only inside this chatbot box for the current browser session.")],-1)),w("div",Ap,[w("div",Rp,[r[4]||(r[4]=w("div",null,[w("p",{class:"text-sm font-semibold text-slate-900"},"Auto Read Replies"),w("p",{class:"mt-1 text-xs text-slate-600"},"Automatically read bot replies aloud.")],-1)),w("button",{class:we(["group relative h-7 w-12 shrink-0 rounded-full border border-slate-200 transition-all duration-200",e.autoReadEnabled?"bg-emerald-500/95":"bg-slate-300"]),"aria-pressed":e.autoReadEnabled?"true":"false",title:e.autoReadEnabled?"Disable auto read":"Enable auto read",onClick:r[0]||(r[0]=$=>s.$emit("toggleAutoRead"))},[w("span",{class:we(["absolute top-0.5 h-5.5 w-5.5 rounded-full bg-white shadow-sm transition-all duration-200",e.autoReadEnabled?"left-[1.45rem]":"left-0.5"])},null,2)],10,Cp)]),w("p",{class:we(["mt-3 text-[11px] font-medium",e.autoReadEnabled?"text-emerald-700":"text-slate-500"])},Je(e.autoReadEnabled?"Auto read is active.":"Auto read is currently off."),3)]),w("div",Pp,[w("div",Ip,[w("div",null,[r[5]||(r[5]=w("p",{class:"text-sm font-semibold text-slate-900"},"Use Amazon Polly",-1)),r[6]||(r[6]=w("p",{class:"mt-1 text-xs text-slate-600"},"Use Polly when available; otherwise browser speech is used automatically.",-1)),w("p",Mp,"Availability: "+Je(n.value),1),(i=e.settings)!=null&&i.aws_region?(F(),W("p",Op,"Region: "+Je(e.settings.aws_region),1)):qe("",!0),(o=e.ttsConfig)!=null&&o.voiceId?(F(),W("p",Lp,"Voice: "+Je(e.ttsConfig.voiceId),1)):qe("",!0)]),w("button",{class:we(["relative h-7 w-12 shrink-0 rounded-full border border-slate-200 transition-all duration-200 disabled:cursor-not-allowed disabled:opacity-55",(a=e.ttsConfig)!=null&&a.usePolly&&((l=e.ttsConfig)!=null&&l.enableVoiceChat)&&((f=e.ttsConfig)!=null&&f.pollyAvailable)?"bg-emerald-500/95":"bg-slate-300"]),"aria-pressed":(u=e.ttsConfig)!=null&&u.usePolly&&((d=e.ttsConfig)!=null&&d.enableVoiceChat)&&((g=e.ttsConfig)!=null&&g.pollyAvailable)?"true":"false",disabled:!((y=e.ttsConfig)!=null&&y.pollyAvailable)||!((E=e.ttsConfig)!=null&&E.enableVoiceChat),onClick:r[1]||(r[1]=$=>s.$emit("togglePollyPreference"))},[w("span",{class:we(["absolute top-0.5 h-5.5 w-5.5 rounded-full bg-white shadow-sm transition-all duration-200",(x=e.ttsConfig)!=null&&x.usePolly&&((M=e.ttsConfig)!=null&&M.enableVoiceChat)&&((m=e.ttsConfig)!=null&&m.pollyAvailable)?"left-[1.45rem]":"left-0.5"])},null,2)],10,$p)]),(H=e.ttsConfig)!=null&&H.enableVoiceChat?(Y=e.ttsConfig)!=null&&Y.pollyAvailable?qe("",!0):(F(),W("p",Np,"Polly is not available for this site. Browser speech will be used.")):(F(),W("p",Dp,"Voice chat is disabled in ChangAI Settings."))]),w("div",Fp,[w("div",Bp,[w("div",null,[r[7]||(r[7]=w("p",{class:"text-sm font-semibold text-slate-900"},"Enable Debug Tab",-1)),r[8]||(r[8]=w("p",{class:"mt-1 text-xs text-slate-600"}," Show or hide the Debug tab inside this chatbot. ",-1)),w("p",{class:we(["mt-2 text-[11px] font-medium",e.debugEnabled?"text-emerald-700":"text-slate-500"])},Je(e.debugEnabled?"Debug tab is active.":"Debug tab is currently off."),3)]),w("button",{type:"button",class:we(["relative h-7 w-12 shrink-0 rounded-full border border-slate-200 transition-all duration-200",e.debugEnabled?"bg-emerald-500/95":"bg-slate-300"]),"aria-pressed":e.debugEnabled?"true":"false",title:e.debugEnabled?"Disable debug tab":"Enable debug tab",onClick:r[2]||(r[2]=$=>s.$emit("toggleDebug"))},[w("span",{class:we(["absolute top-0.5 h-5.5 w-5.5 rounded-full bg-white shadow-sm transition-all duration-200",e.debugEnabled?"left-[1.45rem]":"left-0.5"])},null,2)],10,Hp)])]),w("div",zp,[w("div",Up,[r[9]||(r[9]=w("div",null,[w("p",{class:"text-sm font-semibold text-slate-900"},"Send non-ERP questions directly to AI"),w("p",{class:"mt-1 text-xs text-slate-600"},"Questions unrelated to your ERP will skip the system and go straight to AI")],-1)),w("button",{class:we(["group relative h-7 w-12 shrink-0 rounded-full border border-slate-200 transition-all duration-200",e.sendNonERPtoaiEnabled?"bg-emerald-500/95":"bg-slate-300"]),"aria-pressed":e.sendNonERPtoaiEnabled?"true":"false",title:e.sendNonERPtoaiEnabled?"Non-ERP questions are being sent directly to AI":"Enable direct AI reply for non-ERP questions",onClick:r[3]||(r[3]=$=>s.$emit("toggleSendNonERP"))},[w("span",{class:we(["absolute top-0.5 h-5.5 w-5.5 rounded-full bg-white shadow-sm transition-all duration-200",e.sendNonERPtoaiEnabled?"left-[1.45rem]":"left-0.5"])},null,2)],10,jp)]),w("p",{class:we(["mt-3 text-[11px] font-medium",e.sendNonERPtoaiEnabled?"text-emerald-700":"text-slate-500"])},Je(e.sendNonERPtoaiEnabled?"Non-ERP questions are now routed directly to AI":"Direct AI routing is currently off"),3)])])}}},qp={key:0,class:"pointer-events-none absolute -top-14 left-0 right-0 z-20 flex justify-center px-2",role:"status","aria-live":"polite"},Wp={__name:"StatusToast",props:{visible:{type:Boolean,required:!0},message:{type:String,default:""},type:{type:String,default:"info"},dismissible:{type:Boolean,default:!0}},emits:["close"],setup(e){const t=e,n=Ee(()=>t.type==="error"?"bg-red-50 text-red-700 ring-red-200":(t.type==="listening","bg-blue-50 text-blue-700 ring-blue-200")),s=Ee(()=>t.type==="error"?"bg-red-500":t.type==="listening"?"bg-blue-500 animate-pulse":"bg-blue-500");return(r,i)=>(F(),Et(Pu,{"enter-active-class":"transition duration-200 ease-out","enter-from-class":"translate-y-1 opacity-0","enter-to-class":"translate-y-0 opacity-100","leave-active-class":"transition duration-150 ease-in","leave-from-class":"translate-y-0 opacity-100","leave-to-class":"translate-y-1 opacity-0"},{default:Di(()=>[e.visible?(F(),W("div",qp,[w("div",{class:we(["pointer-events-auto flex max-w-[92%] items-start gap-2 rounded-lg px-3 py-2 text-xs shadow-lg ring-1",n.value])},[w("span",{class:we(["mt-0.5 h-2 w-2 shrink-0 rounded-full",s.value])},null,2),w("span",null,Je(e.message),1),e.dismissible?(F(),W("button",{key:0,type:"button",class:"ml-1 appearance-none border-0 text-current/80 transition hover:text-current focus:outline-none","aria-label":"Dismiss notification",onClick:i[0]||(i[0]=o=>r.$emit("close"))}," × ")):qe("",!0)],2)])):qe("",!0)]),_:1}))}},Gp={class:"relative w-full"},Kp=["placeholder","disabled"],Yp=["title","aria-label","disabled"],Zp={key:0,viewBox:"0 0 24 24",width:"16",height:"16",fill:"currentColor","aria-hidden":"true"},Xp={key:1,viewBox:"0 0 24 24",width:"16",height:"16",fill:"none",stroke:"currentColor","stroke-width":"2","aria-hidden":"true"},Qp={key:2,viewBox:"0 0 24 24",width:"16",height:"16",fill:"none",stroke:"currentColor","stroke-width":"2","aria-hidden":"true",class:"animate-spin"},Jp=["title","aria-label","disabled"],ed={key:0,viewBox:"0 0 24 24",width:"18",height:"18",fill:"none","aria-hidden":"true",class:"text-rose-600 motion-safe:animate-stop-button-pulse"},td={key:1,viewBox:"0 0 24 24",width:"16",height:"16",fill:"currentColor","aria-hidden":"true"},nd={__name:"ChatForm",props:{placeholder:{type:String,default:"Message..."},disabled:{type:Boolean,default:!1},isAwaitingResponse:{type:Boolean,default:!1}},emits:["submit","cancel"],setup(e,{expose:t,emit:n}){const s=e,r=n,i=J(""),o=J(null),a=J(!1),l=J(!1),f=J(!1),u=J(!1),d=J(!1),g=J(!1),y=J(!1),E=J(""),x=J("info"),M=J("Voice input is unavailable in this browser/context.");let m=null,H=null,Y=null;const $=J(""),z=J(!1),O=Ee(()=>f.value?"Requesting microphone permission...":u.value?"Starting voice input...":d.value?"Stopping voice input...":l.value?a.value?"Stop voice input":"Start voice input":"Voice input is unavailable in this browser/context"),P=Ee(()=>s.isAwaitingResponse?"Stop response":"Send"),ee=Ee(()=>s.isAwaitingResponse?!1:s.disabled||!i.value.trim()),V=Ee(()=>s.isAwaitingResponse?"bg-white border border-rose-100 shadow-[0_8px_20px_-12px_rgba(159,18,57,0.35)] hover:bg-rose-50":"bg-linear-to-br from-brand-500 to-brand-600 text-white shadow-[0_10px_24px_-16px_rgba(109,79,194,0.85)] hover:from-brand-600 hover:to-violet-700");function se(){return typeof window=="undefined"?null:window.SpeechRecognition||window.webkitSpeechRecognition||null}function fe(){var ae;const re=se(),B=typeof window!="undefined"?window.isSecureContext:!1,de=typeof navigator!="undefined"&&!!((ae=navigator.mediaDevices)!=null&&ae.getUserMedia);l.value=!!(re&&B&&de),B?(!de||!re)&&(M.value="Voice input is not supported in this browser."):M.value="Voice input requires HTTPS (or localhost).",re&&l.value&&(m=new re,m.continuous=!0,m.interimResults=!0,m.lang=typeof navigator!="undefined"&&navigator.language||"en-US",m.onstart=()=>{a.value=!0,u.value=!1,d.value=!1,D(),C("Listening... Tap mic to stop","listening",{persistent:!0,key:"listening"})},m.onend=()=>{a.value=!1,u.value=!1,d.value=!1,D(),$.value==="listening"&&pe(),z.value&&(z.value=!1,Ge())},m.onerror=ve=>{if(a.value=!1,u.value=!1,d.value=!1,D(),z.value=!1,(ve==null?void 0:ve.error)==="not-allowed"||(ve==null?void 0:ve.error)==="service-not-allowed"){C("Microphone permission denied. Please allow microphone access in browser settings.","error");return}if((ve==null?void 0:ve.error)==="audio-capture"){C("No microphone detected. Please connect a microphone and try again.","error");return}if((ve==null?void 0:ve.error)==="no-speech"){C("No speech detected. Try speaking a bit louder.","info");return}C("Voice input failed. Please try again.","error")},m.onresult=ve=>{let ge="";for(let nt=ve.resultIndex;nt {if(m&&!(!a.value&&!d.value))try{m.abort()}catch{d.value=!1,z.value=!1}},1200)}}function Se(){if(!l.value||!m){C(M.value,"error");return}if(a.value||u.value||d.value){Z({submitAfterStop:a.value});return}te()}async function Ue(){var re;if(g.value)return!0;if(!((re=navigator.mediaDevices)!=null&&re.getUserMedia))return C("Microphone API is unavailable in this browser.","error"),!1;f.value=!0,C("Requesting microphone permission...","info",{persistent:!0,key:"requesting"});try{return(await navigator.mediaDevices.getUserMedia({audio:!0})).getTracks().forEach(de=>de.stop()),g.value=!0,!0}catch(B){return(B==null?void 0:B.name)==="NotAllowedError"||(B==null?void 0:B.name)==="SecurityError"?C("Microphone permission denied. Please allow it and try again.","error"):(B==null?void 0:B.name)==="NotFoundError"?C("No microphone found on this device.","error"):C("Unable to access microphone. Please check browser permissions.","error"),!1}finally{f.value=!1,$.value==="requesting"&&pe()}}async function te(){var B;if(!(!m||a.value||u.value||d.value||!await Ue()||!m)){z.value=!1,(B=o.value)==null||B.focus(),u.value=!0;try{m.start()}catch(de){u.value=!1,d.value=!1,(de==null?void 0:de.name)!=="InvalidStateError"&&C("Unable to start voice input. Please try again.","error")}}}function C(re,B="info",de={}){const{duration:ae=4200,persistent:ve=!1,key:ge=""}=de;E.value=re,x.value=B,$.value=ge,y.value=!0,H&&clearTimeout(H),ve||(H=setTimeout(()=>{y.value=!1,$.value=""},ae))}function pe(){y.value=!1,$.value="",H&&(clearTimeout(H),H=null)}function Ge(){if(s.isAwaitingResponse){r("cancel");return}const re=i.value.trim();re&&((a.value||u.value||d.value)&&m&&Z({submitAfterStop:!1}),r("submit",re),i.value="")}return t({focus:()=>{var re;return(re=o.value)==null?void 0:re.focus()}}),zn(()=>{fe()}),ys(()=>{if(m&&(a.value||u.value||d.value)){z.value=!1,D();try{m.abort()}catch{}}D(),pe()}),(re,B)=>(F(),W("div",Gp,[w("form",{class:"group flex min-h-11 items-center gap-2 rounded-full border border-slate-200/90 bg-white/95 px-3 shadow-[0_12px_26px_-20px_rgba(15,23,42,0.7)] transition-all duration-250 focus-within:-translate-y-0.5 focus-within:border-brand-200 focus-within:shadow-[0_18px_30px_-20px_rgba(13,110,253,0.5)] focus-within:ring-2 focus-within:ring-brand-500/25",style:{"border-radius":"9999px"},autocomplete:"off",onSubmit:pt(Ge,["prevent"]),onClick:B[5]||(B[5]=pt(()=>{},["stop"])),onMousedown:B[6]||(B[6]=pt(()=>{},["stop"])),onKeydown:B[7]||(B[7]=pt(()=>{},["stop"])),onKeyup:B[8]||(B[8]=pt(()=>{},["stop"]))},[Pa(w("input",{ref_key:"inputRef",ref:o,type:"text","onUpdate:modelValue":B[0]||(B[0]=de=>i.value=de),class:"h-11 w-full border-none bg-transparent text-sm font-medium text-slate-800 placeholder:text-slate-400 focus:outline-none disabled:cursor-not-allowed disabled:opacity-50",placeholder:e.disabled?"Waiting for response...":e.placeholder,disabled:e.disabled,required:"",onKeydown:B[1]||(B[1]=pt(()=>{},["stop"])),onKeyup:B[2]||(B[2]=pt(()=>{},["stop"])),onKeypress:B[3]||(B[3]=pt(()=>{},["stop"])),onInput:B[4]||(B[4]=pt(()=>{},["stop"]))},null,40,Kp),[[Xu,i.value]]),w("button",{type:"button",class:we(["grid h-8 w-8 shrink-0 appearance-none place-items-center rounded-full border border-transparent text-slate-600 transition-all duration-200 hover:-translate-y-0.5 hover:border-slate-200 hover:bg-slate-100 hover:text-slate-900 focus:outline-none disabled:cursor-not-allowed disabled:opacity-40",a.value?"border-red-200 bg-red-100 text-red-600 shadow-[0_10px_20px_-18px_rgba(220,38,38,0.9)] hover:bg-red-100 hover:text-red-600":""]),style:{"border-radius":"9999px"},title:O.value,"aria-label":O.value,disabled:e.disabled||!l.value||f.value||u.value||d.value,onClick:Se},[a.value&&!f.value?(F(),W("svg",Zp,B[9]||(B[9]=[w("rect",{x:"6",y:"6",width:"12",height:"12",rx:"2"},null,-1)]))):f.value?(F(),W("svg",Qp,B[11]||(B[11]=[w("circle",{cx:"12",cy:"12",r:"9",opacity:"0.3"},null,-1),w("path",{d:"M21 12a9 9 0 0 1-9 9"},null,-1)]))):(F(),W("svg",Xp,B[10]||(B[10]=[w("path",{d:"M12 3a3 3 0 0 0-3 3v6a3 3 0 0 0 6 0V6a3 3 0 0 0-3-3z"},null,-1),w("path",{d:"M19 10v2a7 7 0 0 1-14 0v-2"},null,-1),w("path",{d:"M12 19v3"},null,-1)])))],10,Yp),w("button",{type:"submit",title:P.value,"aria-label":P.value,class:we(["grid h-8 w-8 shrink-0 appearance-none place-items-center rounded-full border-0 transition-all duration-200 hover:-translate-y-0.5 focus:outline-none disabled:cursor-not-allowed disabled:opacity-40",V.value]),style:{"border-radius":"9999px"},disabled:ee.value},[e.isAwaitingResponse?(F(),W("svg",ed,B[12]||(B[12]=[w("circle",{cx:"12",cy:"12",r:"8",stroke:"currentColor","stroke-width":"2.1",class:"opacity-95"},null,-1),w("rect",{x:"9",y:"9",width:"6",height:"6",rx:"1.35",fill:"currentColor"},null,-1)]))):(F(),W("svg",td,B[13]||(B[13]=[w("path",{d:"M4 12l1.41 1.41L11 7.83V20h2V7.83l5.59 5.58L20 12l-8-8-8 8z"},null,-1)])))],10,Jp)],32),Oe(Wp,{visible:y.value,message:E.value,type:x.value,dismissible:x.value!=="listening",onClose:pe},null,8,["visible","message","type","dismissible"])]))}},sd={class:"relative overflow-hidden bg-linear-to-br from-brand-600 via-brand-500 to-violet-400"},rd={class:"min-w-0"},id={key:1,class:"border-t border-slate-200/80 bg-white/90 px-3 py-3 pb-[calc(12px+env(safe-area-inset-bottom))] backdrop-blur-sm sm:px-4 sm:py-4"},od=56,ld={__name:"ChatbotPopup",props:{isOpen:{type:Boolean,required:!0},activeTab:{type:String,required:!0},debugEnabled:{type:Boolean,default:!1},sendNonERPtoaiEnabled:{type:Boolean,default:!1},chatHistory:{type:Array,required:!0},debugLogs:{type:Array,required:!0},currentDebug:{type:Object,default:null},supportHistory:{type:Array,required:!0},autoReadEnabled:{type:Boolean,required:!0},ttsConfig:{type:Object,required:!0},activeTtsProvider:{type:String,required:!0},settings:{type:Object,default:null},isAwaitingChatResponse:{type:Boolean,default:!1},isAwaitingSupportResponse:{type:Boolean,default:!1}},emits:["close","submit","cancelResponse","update:activeTab","toggleAutoRead","togglePollyPreference","toggleDebug","toggleSendNonERP"],setup(e,{expose:t,emit:n}){const s=e,r=n,i=J(null),o=J(null),a=J(s.activeTab),l=J("default"),f=J(!1),u=Ee(()=>a.value==="support"?s.isAwaitingSupportResponse:a.value==="chat"?s.isAwaitingChatResponse:!1);function d(){const M=i.value;if(!s.isOpen||!M){f.value=!1;return}const m=M.scrollHeight-M.clientHeight;if(m<=4){f.value=!1;return}const H=m-M.scrollTop;f.value=H>od}function g(){const M=i.value;M&&(M.scrollTo({top:M.scrollHeight,behavior:"smooth"}),setTimeout(()=>{d()},220))}function y(){St(()=>{d()})}function E(){if(l.value==="default"){l.value="half";return}if(l.value==="half"){l.value="full";return}l.value="default"}const x=Ee(()=>{const M="chat-shell fixed z-[9999] flex min-h-0 flex-col overflow-hidden border border-slate-200/80 shadow-[0_32px_80px_-44px_rgba(2,6,23,0.7),0_18px_40px_-24px_rgba(15,23,42,0.45)] transition-all duration-300 ease-out origin-bottom-right",m=s.isOpen?"pointer-events-auto opacity-100 translate-x-0 translate-y-0 scale-100 motion-safe:animate-surface-in":"pointer-events-none opacity-0 translate-x-1/5 translate-y-8 scale-95";return l.value==="full"?[M,m,"inset-0 h-screen w-screen max-h-screen max-w-screen rounded-none origin-center"]:l.value==="half"?[M,m,"bottom-[74px] right-5 h-[min(86vh,860px)] w-[min(50vw,860px)] rounded-2xl","max-[900px]:bottom-[78px] max-[900px]:right-3 max-[900px]:h-[min(86vh,760px)] max-[900px]:w-[min(70vw,760px)] max-[900px]:rounded-[14px]","max-[600px]:inset-0 max-[600px]:h-screen max-[600px]:w-screen max-[600px]:max-h-screen max-[600px]:max-w-screen max-[600px]:rounded-none max-[600px]:pb-[env(safe-area-inset-bottom)]"]:[M,m,"bottom-[74px] right-5 h-[min(560px,72vh)] w-[min(360px,calc(100vw-40px))] rounded-2xl","max-[900px]:bottom-[78px] max-[900px]:right-3 max-[900px]:h-[min(70vh,540px)] max-[900px]:w-[min(360px,calc(100vw-24px))] max-[900px]:rounded-[14px]","max-[600px]:inset-0 max-[600px]:h-screen max-[600px]:w-screen max-[600px]:max-h-screen max-[600px]:max-w-screen max-[600px]:rounded-none max-[600px]:pb-[env(safe-area-inset-bottom)]"]});return on(()=>s.activeTab,M=>{a.value=M,y()}),on(()=>s.isOpen,M=>{M&&a.value!=="settings"&&St(()=>{var m;return(m=o.value)==null?void 0:m.focus()}),y()}),on(a,M=>{r("update:activeTab",M),y()}),on(()=>[s.chatHistory.length,s.supportHistory.length,s.debugLogs.length,s.currentDebug],()=>{y()}),on(()=>s.debugEnabled,M=>{!M&&a.value==="debug"&&(a.value="chat"),y()}),zn(()=>{y()}),t({scrollToBottom(){St(()=>{g()})}}),(M,m)=>(F(),W("div",{class:we(x.value),onKeydown:m[9]||(m[9]=pt(()=>{},["stop"])),onKeyup:m[10]||(m[10]=pt(()=>{},["stop"])),onKeypress:m[11]||(m[11]=pt(()=>{},["stop"]))},[m[14]||(m[14]=w("div",{class:"pointer-events-none absolute -right-14 -top-14 h-36 w-36 rounded-full bg-brand-500/15 blur-2xl"},null,-1)),m[15]||(m[15]=w("div",{class:"pointer-events-none absolute -bottom-14 -left-12 h-32 w-32 rounded-full bg-violet-400/15 blur-2xl"},null,-1)),w("div",sd,[m[12]||(m[12]=w("div",{class:"pointer-events-none absolute inset-0 opacity-45",style:{background:"linear-gradient(120deg, rgba(255,255,255,0.16) 0%, rgba(255,255,255,0.02) 52%, rgba(255,255,255,0.12) 100%)"}},null,-1)),Oe(vc,{windowMode:l.value,autoReadEnabled:e.autoReadEnabled,activeTtsProvider:e.activeTtsProvider,onClose:m[0]||(m[0]=H=>M.$emit("close")),onCycleResize:E,onToggleAutoRead:m[1]||(m[1]=H=>M.$emit("toggleAutoRead"))},null,8,["windowMode","autoReadEnabled","activeTtsProvider"]),Oe(Sc,{modelValue:a.value,"onUpdate:modelValue":m[2]||(m[2]=H=>a.value=H),debugEnabled:e.debugEnabled},null,8,["modelValue","debugEnabled"])]),w("div",{class:"chat-scrollbar min-h-0 flex-1 overflow-x-hidden overflow-y-scroll bg-slate-50/60 px-4 py-4 max-[900px]:px-3.5 max-[900px]:py-3.5 max-[600px]:px-3 max-[600px]:py-3",ref_key:"chatBodyRef",ref:i,onScrollPassive:d},[w("div",rd,[a.value==="chat"?(F(),Et(mp,{key:0,messages:e.chatHistory,autoReadEnabled:e.autoReadEnabled,ttsConfig:e.ttsConfig},null,8,["messages","autoReadEnabled","ttsConfig"])):a.value==="debug"&&e.debugEnabled?(F(),Et(_p,{key:1,logs:e.debugLogs,currentDebug:e.currentDebug},null,8,["logs","currentDebug"])):a.value==="support"?(F(),Et(Sp,{key:2,messages:e.supportHistory,autoReadEnabled:e.autoReadEnabled,ttsConfig:e.ttsConfig},null,8,["messages","autoReadEnabled","ttsConfig"])):a.value==="settings"?(F(),Et(Vp,{key:3,autoReadEnabled:e.autoReadEnabled,ttsConfig:e.ttsConfig,settings:e.settings,debugEnabled:e.debugEnabled,sendNonERPtoaiEnabled:e.sendNonERPtoaiEnabled,onToggleAutoRead:m[3]||(m[3]=H=>M.$emit("toggleAutoRead")),onTogglePollyPreference:m[4]||(m[4]=H=>M.$emit("togglePollyPreference")),onToggleDebug:m[5]||(m[5]=H=>M.$emit("toggleDebug")),onToggleSendNonERP:m[6]||(m[6]=H=>M.$emit("toggleSendNonERP"))},null,8,["autoReadEnabled","ttsConfig","settings","debugEnabled","sendNonERPtoaiEnabled"])):qe("",!0)])],544),f.value?(F(),W("button",{key:0,type:"button",class:we(["absolute right-4 z-20 grid h-9 w-9 place-items-center rounded-full border border-brand-200/70 bg-white/95 text-brand-600 shadow-[0_14px_26px_-16px_rgba(15,23,42,0.65)] transition-all duration-200 hover:-translate-y-0.5 hover:border-brand-300 hover:text-brand-700 focus:outline-none",a.value!=="settings"?"bottom-[calc(90px+env(safe-area-inset-bottom))] sm:bottom-[96px]":"bottom-4 sm:bottom-5"]),title:"Scroll to bottom","aria-label":"Scroll to bottom",onClick:g},m[13]||(m[13]=[w("svg",{viewBox:"0 0 24 24",width:"16",height:"16",fill:"none",stroke:"currentColor","stroke-width":"2","aria-hidden":"true"},[w("path",{d:"M7 10l5 5 5-5"})],-1)]),2)):qe("",!0),a.value!=="settings"?(F(),W("div",id,[Oe(nd,{ref_key:"chatFormRef",ref:o,placeholder:a.value==="support"?"Message Support...":"Message...",disabled:u.value,isAwaitingResponse:u.value,onSubmit:m[7]||(m[7]=H=>M.$emit("submit",H)),onCancel:m[8]||(m[8]=H=>M.$emit("cancelResponse"))},null,8,["placeholder","disabled","isAwaitingResponse"])])):qe("",!0)],34))}},_l="changai_chat_id",Tl="changai_polly_enabled";function ad(){let e=sessionStorage.getItem(_l);return e||(e=`session_${Date.now()}_${crypto.randomUUID()}`,sessionStorage.setItem(_l,e)),e}function ud(){const e=localStorage.getItem(Tl);return e===null?!0:e==="true"}function cd(e){localStorage.setItem(Tl,String(!!e))}const fd={__name:"App",setup(e){const t=J(!1),n=J("chat"),s=J([]),r=J([]),i=J(!1),o=J([]),a=J(null),l=J("actual"),f=J(!0),u=J(null),d=J(!1),g=J(null),y=J(!1),E=J({enableVoiceChat:!1,pollyAvailable:!1,usePolly:!0,voiceId:"Zayd",enable_changai:!1}),x=J("off"),M=J(null),m=J(null),H=Ee(()=>M.value!==null),Y=Ee(()=>m.value!==null);function $(){if(!E.value.enableVoiceChat){x.value="off";return}x.value=E.value.usePolly?"polly":"browser"}function z(te){var pe;const C=(pe=te==null?void 0:te.detail)==null?void 0:pe.provider;(C==="polly"||C==="browser"||C==="off")&&(x.value=C)}async function O(){var pe,Ge,re,B,de;if(!(d.value||u.value)){d.value=!0;try{u.value=await Mc(l.value),E.value={enableVoiceChat:!!((pe=u.value)!=null&&pe.enable_voice_chat),pollyAvailable:!!((Ge=u.value)!=null&&Ge.polly_enabled),usePolly:!!((re=u.value)!=null&&re.polly_enabled)&&ud(),voiceId:((B=u.value)==null?void 0:B.polly_voice_id)||"Zayd",enable_changai:!!((de=u.value)!=null&&de.enable_changai)},$(),r.value.push({type:"settings",settings:u.value})}catch(ae){const ve=vl(ae);r.value.push({type:"settings",error:ve})}finally{d.value=!1}}}function P(){t.value=!t.value}function ee(){var te;(te=a.value)==null||te.scrollToBottom()}function V(){f.value=!f.value}function se(){const te=!E.value.usePolly;E.value={...E.value,usePolly:te&&E.value.pollyAvailable},cd(E.value.usePolly),$()}function fe(){y.value=!y.value}async function D(te){n.value==="support"?await Ue(te):await Z(te)}async function Z(te){var ye,ht;g.value=null,l.value==="actual"&&await O(),s.value.push({role:"user",text:te}),await St(),ee();const C=cs({role:"model",text:"Thinking...",cancelable:!0,isStatus:!0,statusType:"thinking"});s.value.push(C),await St(),ee();let pe=!1;const Ge=ad(),re=`${Ge}_${Date.now()}`,B=y.value,de=Pc(te,Ge,l.value,re,y.value),ae=`debug_${re}`;let ve=Date.now();const ge=[],nt=G=>{var h;const Ce=Date.now(),Ft=((Ce-ve)/1e3).toFixed(2);ve=Ce;const c=`${G.message} (${Ft}s)`;if(G.message&&(ge.push(c),g.value=c),!G.done&&G.message&&(C.text=G.message,C.statusType="pipeline"),G.done){C.cancelable=!1,G.error?(C.text=`⚠️ ${G.message||"Something failed"}`,C.isStatus=!1,C.statusType=null):(h=G.data)!=null&&h.answer&&(C.text=G.data.answer,C.isStatus=!1,C.statusType=null),frappe.realtime.off(ae),g.value=null;return}};frappe.realtime.on(ae,nt),M.value=()=>{pe||(pe=!0,de.cancel(),frappe.realtime.off(ae),C.isStatus=!1,C.statusType=null,C.text="Cancelled by user.",r.value.push({type:"cancelled",user:te,steps:[...ge]}),g.value=null,C.cancelable=!1,M.value=null)};try{const G=await de.promise;if(G!=null&&G.open_report){if(C.isStatus=!1,C.statusType=null,C.text=`Opening "${G.report_name}" report." `,r.value.push({type:"success",steps:[...ge],final_response:G,entity_raw:G.entity_raw}),g.value=null,!G.report_name){C.text="Report name extraction failed.Can you ask the same question again?";return}frappe.set_route("query-report",G.report_name,G.filters||{});return}else if(G!=null&&G.create_entity){C.isStatus=!1,C.statusType=null,C.cancelable=!1,C.text=`Opening "${G.doc}" doctype for creating Entity "${G.entity_name}" record.`,r.value.push({type:"success",user:te,steps:[...ge],final_response:G}),g.value=null;const Ft=G.doc,c=G.entity_name||"",b={Customer:{customer_name:c},Supplier:{supplier_name:c},Employee:{employee_name:c},Item:{item_code:c,item_name:c},Project:{project_name:c},Lead:{lead_name:c},Opportunity:{opportunity_name:c}}[Ft]||{};frappe.route_options=b,frappe.set_route("Form",Ft,"new");const k=setInterval(()=>{cur_frm&&cur_frm.doctype===Ft&&cur_frm.is_new()&&(clearInterval(k),Object.entries(b).forEach(([v,_])=>{_&&cur_frm.fields_dict[v]&&(cur_frm.set_value(v,_),cur_frm.refresh_field(v))}))},200);return}if(pe)return;C.cancelable=!1;const Ce=((ye=bp(G==null?void 0:G.Bot))==null?void 0:ye.trim())||"No response.";C.isStatus=!1,C.statusType=null,C.text=Ce,r.value.push({type:"success",user:te,steps:[...ge],final_response:G}),g.value=null}catch(G){if(pe)return;frappe.realtime.off(ae),C.cancelable=!1,C.isStatus=!1,C.statusType=null;const Ce=vl(G);g.value=null,r.value.push({type:"failed",user:te,steps:[...ge],error:Ce}),(G==null?void 0:G.code)==="ERR_NETWORK_CHANGED"||(ht=G==null?void 0:G.message)!=null&&ht.includes("ERR_NETWORK_CHANGED")?(C.isStatus=!1,C.statusType=null,C.text="⚠️ Network error. Please check your connection and try again."):(C.isStatus=!1,C.statusType=null,C.text="⚠️ Something went wrong. Please try again.")}finally{frappe.realtime.off(ae),pe||(M.value=null)}await St(),ee()}function Se(){var te,C;if(n.value==="support"){(te=m.value)==null||te.call(m);return}(C=M.value)==null||C.call(M)}async function Ue(te){o.value.push({role:"user",text:te}),await St(),ee();const C=cs({role:"model",text:"Sending to support...",isStatus:!0,statusType:"support"});o.value.push(C),await St(),ee();let pe=!1;const Ge=Ic(te,l.value);m.value=()=>{pe||(pe=!0,Ge.cancel(),C.isStatus=!1,C.statusType=null,C.text="Cancelled by user.",m.value=null)};try{const re=await Ge.promise;if(pe)return;C.isStatus=!1,C.statusType=null,C.text=re?wl(re):"Support request sent successfully."}catch{if(pe)return;C.isStatus=!1,C.statusType=null,C.text="⚠️ Failed to reach support. Please try again."}finally{pe||(m.value=null)}await St(),ee()}return zn(()=>{typeof window!="undefined"&&window.addEventListener("changai-tts-provider",z),l.value==="actual"&&O()}),ys(()=>{typeof window!="undefined"&&window.removeEventListener("changai-tts-provider",z)}),(te,C)=>(F(),W(He,null,[E.value.enable_changai?(F(),Et(ac,{key:0,isOpen:t.value,onToggle:P},null,8,["isOpen"])):qe("",!0),Oe(ld,{ref_key:"popupRef",ref:a,isOpen:t.value,activeTab:n.value,"onUpdate:activeTab":C[0]||(C[0]=pe=>n.value=pe),chatHistory:s.value,debugLogs:r.value,currentDebug:g.value,supportHistory:o.value,autoReadEnabled:f.value,ttsConfig:E.value,activeTtsProvider:x.value,settings:u.value,isAwaitingChatResponse:H.value,isAwaitingSupportResponse:Y.value,debugEnabled:i.value,sendNonERPtoaiEnabled:y.value,onToggleDebug:C[1]||(C[1]=pe=>i.value=!i.value),onClose:C[2]||(C[2]=pe=>t.value=!1),onSubmit:D,onCancelResponse:Se,onToggleAutoRead:V,onTogglePollyPreference:se,onToggleSendNonERP:fe},null,8,["isOpen","activeTab","chatHistory","debugLogs","currentDebug","supportHistory","autoReadEnabled","ttsConfig","activeTtsProvider","settings","isAwaitingChatResponse","isAwaitingSupportResponse","debugEnabled","sendNonERPtoaiEnabled"])],64))}};function pd(){const e=document.querySelector('link[href*="/assets/changai/dist/changai-chatbot.css"]');if(e!=null&&e.href)return e.href;const t=Array.from(document.scripts).find(n=>{var s;return(s=n.src)==null?void 0:s.includes("/assets/changai/dist/changai-chatbot.js")});return t!=null&&t.src?t.src.replace(/changai-chatbot\.js(\?.*)?$/,"changai-chatbot.css$1"):null}function dd(e){const t=pd();if(!t){const n=Array.from(document.querySelectorAll("style[data-vite-dev-id]"));return n.length&&n.forEach(s=>{const r=document.createElement("style");r.dataset.changaiShadowDevStyle="1",r.textContent=s.textContent||"",e.appendChild(r)}),Promise.resolve()}return e.querySelector('link[data-changai-shadow-style="1"]')?Promise.resolve():new Promise(n=>{const s=document.createElement("link");s.rel="stylesheet",s.href=t,s.dataset.changaiShadowStyle="1",s.onload=()=>n(),s.onerror=()=>n(),e.appendChild(s),setTimeout(n,1200)})}async function kl(){if(document.getElementById("changai-chatbot-host"))return;const e=document.createElement("div");e.id="changai-chatbot-host",document.body.appendChild(e);const t=e.attachShadow({mode:"open"});await dd(t);const n=document.createElement("div");n.id="changai-chatbot-root",t.appendChild(n),nc(fd).mount(n);function s(r){r.stopPropagation()}n.addEventListener("keydown",s),n.addEventListener("keyup",s),n.addEventListener("keypress",s)}document.readyState==="loading"?document.addEventListener("DOMContentLoaded",kl):kl()})(); +`} tablecell(e) { + let t = this.parser.parseInline(e.tokens), n = e.header ? "th" : "td"; return (e.align ? `<${n} align="${e.align}">` : `<${n}>`) + t + `${n}> +`} strong({ tokens: e }) { return `${this.parser.parseInline(e)}` } em({ tokens: e }) { return `${this.parser.parseInline(e)}` } codespan({ text: e }) { return ` ${Ct(e, !0)}` } br(e) { return "
" } del({ tokens: e }) { return `${this.parser.parseInline(e)}` } link({ href: e, title: t, tokens: n }) { let s = this.parser.parseInline(n), r = Jo(e); if (r === null) return s; e = r; let i = '" + s + "", i } image({ href: e, title: t, text: n, tokens: s }) { s && (n = this.parser.parseInline(s, this.parser.textRenderer)); let r = Jo(e); if (r === null) return Ct(n); e = r; let i = `", i } text(e) { return "tokens" in e && e.tokens ? this.parser.parseInline(e.tokens) : "escaped" in e && e.escaped ? e.text : Ct(e.text) } + }, Lr = class { strong({ text: e }) { return e } em({ text: e }) { return e } codespan({ text: e }) { return e } del({ text: e }) { return e } html({ text: e }) { return e } text({ text: e }) { return e } link({ text: e }) { return "" + e } image({ text: e }) { return "" + e } br() { return "" } checkbox({ raw: e }) { return e } }, wt = class Qr { constructor(t) { _e(this, "options"); _e(this, "renderer"); _e(this, "textRenderer"); this.options = t || cn, this.options.renderer = this.options.renderer || new $s, this.renderer = this.options.renderer, this.renderer.options = this.options, this.renderer.parser = this, this.textRenderer = new Lr } static parse(t, n) { return new Qr(n).parse(t) } static parseInline(t, n) { return new Qr(n).parseInline(t) } parse(t) { var s, r; this.renderer.parser = this; let n = ""; for (let i = 0; i < t.length; i++) { let o = t[i]; if ((r = (s = this.options.extensions) == null ? void 0 : s.renderers) != null && r[o.type]) { let l = o, f = this.options.extensions.renderers[l.type].call({ parser: this }, l); if (f !== !1 || !["space", "hr", "heading", "code", "table", "blockquote", "list", "html", "def", "paragraph", "text"].includes(l.type)) { n += f || ""; continue } } let a = o; switch (a.type) { case "space": { n += this.renderer.space(a); break } case "hr": { n += this.renderer.hr(a); break } case "heading": { n += this.renderer.heading(a); break } case "code": { n += this.renderer.code(a); break } case "table": { n += this.renderer.table(a); break } case "blockquote": { n += this.renderer.blockquote(a); break } case "list": { n += this.renderer.list(a); break } case "checkbox": { n += this.renderer.checkbox(a); break } case "html": { n += this.renderer.html(a); break } case "def": { n += this.renderer.def(a); break } case "paragraph": { n += this.renderer.paragraph(a); break } case "text": { n += this.renderer.text(a); break } default: { let l = 'Token with "' + a.type + '" type was not found.'; if (this.options.silent) return ""; throw new Error(l) } } } return n } parseInline(t, n = this.renderer) { var r, i; this.renderer.parser = this; let s = ""; for (let o = 0; o < t.length; o++) { let a = t[o]; if ((i = (r = this.options.extensions) == null ? void 0 : r.renderers) != null && i[a.type]) { let f = this.options.extensions.renderers[a.type].call({ parser: this }, a); if (f !== !1 || !["escape", "html", "link", "image", "strong", "em", "codespan", "br", "del", "text"].includes(a.type)) { s += f || ""; continue } } let l = a; switch (l.type) { case "escape": { s += n.text(l); break } case "html": { s += n.html(l); break } case "link": { s += n.link(l); break } case "image": { s += n.image(l); break } case "checkbox": { s += n.checkbox(l); break } case "strong": { s += n.strong(l); break } case "em": { s += n.em(l); break } case "codespan": { s += n.codespan(l); break } case "br": { s += n.br(l); break } case "del": { s += n.del(l); break } case "text": { s += n.text(l); break } default: { let f = 'Token with "' + l.type + '" type was not found.'; if (this.options.silent) return ""; throw new Error(f) } } } return s } }, Zn = (Fs = class { constructor(e) { _e(this, "options"); _e(this, "block"); this.options = e || cn } preprocess(e) { return e } postprocess(e) { return e } processAllTokens(e) { return e } emStrongMask(e) { return e } provideLexer(e = this.block) { return e ? yt.lex : yt.lexInline } provideParser(e = this.block) { return e ? wt.parse : wt.parseInline } }, _e(Fs, "passThroughHooks", new Set(["preprocess", "postprocess", "processAllTokens", "emStrongMask"])), _e(Fs, "passThroughHooksRespectAsync", new Set(["preprocess", "postprocess", "processAllTokens"])), Fs), vf = class { + constructor(...e) { _e(this, "defaults", Sr()); _e(this, "options", this.setOptions); _e(this, "parse", this.parseMarkdown(!0)); _e(this, "parseInline", this.parseMarkdown(!1)); _e(this, "Parser", wt); _e(this, "Renderer", $s); _e(this, "TextRenderer", Lr); _e(this, "Lexer", yt); _e(this, "Tokenizer", Ls); _e(this, "Hooks", Zn); this.use(...e) } walkTokens(e, t) { var s, r; let n = []; for (let i of e) switch (n = n.concat(t.call(this, i)), i.type) { case "table": { let o = i; for (let a of o.header) n = n.concat(this.walkTokens(a.tokens, t)); for (let a of o.rows) for (let l of a) n = n.concat(this.walkTokens(l.tokens, t)); break } case "list": { let o = i; n = n.concat(this.walkTokens(o.items, t)); break } default: { let o = i; (r = (s = this.defaults.extensions) == null ? void 0 : s.childTokens) != null && r[o.type] ? this.defaults.extensions.childTokens[o.type].forEach(a => { let l = o[a].flat(1 / 0); n = n.concat(this.walkTokens(l, t)) }) : o.tokens && (n = n.concat(this.walkTokens(o.tokens, t))) } }return n } use(...e) { let t = this.defaults.extensions || { renderers: {}, childTokens: {} }; return e.forEach(n => { let s = { ...n }; if (s.async = this.defaults.async || s.async || !1, n.extensions && (n.extensions.forEach(r => { if (!r.name) throw new Error("extension name required"); if ("renderer" in r) { let i = t.renderers[r.name]; i ? t.renderers[r.name] = function (...o) { let a = r.renderer.apply(this, o); return a === !1 && (a = i.apply(this, o)), a } : t.renderers[r.name] = r.renderer } if ("tokenizer" in r) { if (!r.level || r.level !== "block" && r.level !== "inline") throw new Error("extension level must be 'block' or 'inline'"); let i = t[r.level]; i ? i.unshift(r.tokenizer) : t[r.level] = [r.tokenizer], r.start && (r.level === "block" ? t.startBlock ? t.startBlock.push(r.start) : t.startBlock = [r.start] : r.level === "inline" && (t.startInline ? t.startInline.push(r.start) : t.startInline = [r.start])) } "childTokens" in r && r.childTokens && (t.childTokens[r.name] = r.childTokens) }), s.extensions = t), n.renderer) { let r = this.defaults.renderer || new $s(this.defaults); for (let i in n.renderer) { if (!(i in r)) throw new Error(`renderer '${i}' does not exist`); if (["options", "parser"].includes(i)) continue; let o = i, a = n.renderer[o], l = r[o]; r[o] = (...f) => { let u = a.apply(r, f); return u === !1 && (u = l.apply(r, f)), u || "" } } s.renderer = r } if (n.tokenizer) { let r = this.defaults.tokenizer || new Ls(this.defaults); for (let i in n.tokenizer) { if (!(i in r)) throw new Error(`tokenizer '${i}' does not exist`); if (["options", "rules", "lexer"].includes(i)) continue; let o = i, a = n.tokenizer[o], l = r[o]; r[o] = (...f) => { let u = a.apply(r, f); return u === !1 && (u = l.apply(r, f)), u } } s.tokenizer = r } if (n.hooks) { let r = this.defaults.hooks || new Zn; for (let i in n.hooks) { if (!(i in r)) throw new Error(`hook '${i}' does not exist`); if (["options", "block"].includes(i)) continue; let o = i, a = n.hooks[o], l = r[o]; Zn.passThroughHooks.has(i) ? r[o] = f => { if (this.defaults.async && Zn.passThroughHooksRespectAsync.has(i)) return (async () => { let d = await a.call(r, f); return l.call(r, d) })(); let u = a.call(r, f); return l.call(r, u) } : r[o] = (...f) => { if (this.defaults.async) return (async () => { let d = await a.apply(r, f); return d === !1 && (d = await l.apply(r, f)), d })(); let u = a.apply(r, f); return u === !1 && (u = l.apply(r, f)), u } } s.hooks = r } if (n.walkTokens) { let r = this.defaults.walkTokens, i = n.walkTokens; s.walkTokens = function (o) { let a = []; return a.push(i.call(this, o)), r && (a = a.concat(r.call(this, o))), a } } this.defaults = { ...this.defaults, ...s } }), this } setOptions(e) { return this.defaults = { ...this.defaults, ...e }, this } lexer(e, t) { return yt.lex(e, t != null ? t : this.defaults) } parser(e, t) { return wt.parse(e, t != null ? t : this.defaults) } parseMarkdown(e) { return (t, n) => { let s = { ...n }, r = { ...this.defaults, ...s }, i = this.onError(!!r.silent, !!r.async); if (this.defaults.async === !0 && s.async === !1) return i(new Error("marked(): The async option was set to true by an extension. Remove async: false from the parse options object to return a Promise.")); if (typeof t > "u" || t === null) return i(new Error("marked(): input parameter is undefined or null")); if (typeof t != "string") return i(new Error("marked(): input parameter is of type " + Object.prototype.toString.call(t) + ", string expected")); if (r.hooks && (r.hooks.options = r, r.hooks.block = e), r.async) return (async () => { let o = r.hooks ? await r.hooks.preprocess(t) : t, a = await (r.hooks ? await r.hooks.provideLexer(e) : e ? yt.lex : yt.lexInline)(o, r), l = r.hooks ? await r.hooks.processAllTokens(a) : a; r.walkTokens && await Promise.all(this.walkTokens(l, r.walkTokens)); let f = await (r.hooks ? await r.hooks.provideParser(e) : e ? wt.parse : wt.parseInline)(l, r); return r.hooks ? await r.hooks.postprocess(f) : f })().catch(i); try { r.hooks && (t = r.hooks.preprocess(t)); let o = (r.hooks ? r.hooks.provideLexer(e) : e ? yt.lex : yt.lexInline)(t, r); r.hooks && (o = r.hooks.processAllTokens(o)), r.walkTokens && this.walkTokens(o, r.walkTokens); let a = (r.hooks ? r.hooks.provideParser(e) : e ? wt.parse : wt.parseInline)(o, r); return r.hooks && (a = r.hooks.postprocess(a)), a } catch (o) { return i(o) } } } onError(e, t) { + return n => { + if (n.message += ` +Please report this to https://github.com/markedjs/marked.`, e) { let s = "
An error occurred:
" + Ct(n.message + "", !0) + ""; return t ? Promise.resolve(s) : s } if (t) return Promise.reject(n); throw n + } + } + }, pn = new vf; function xe(e, t) { return pn.parse(e, t) } xe.options = xe.setOptions = function (e) { return pn.setOptions(e), xe.defaults = pn.defaults, Ho(xe.defaults), xe }, xe.getDefaults = Sr, xe.defaults = cn, xe.use = function (...e) { return pn.use(...e), xe.defaults = pn.defaults, Ho(xe.defaults), xe }, xe.walkTokens = function (e, t) { return pn.walkTokens(e, t) }, xe.parseInline = pn.parseInline, xe.Parser = wt, xe.parser = wt.parse, xe.Renderer = $s, xe.TextRenderer = Lr, xe.Lexer = yt, xe.lexer = yt.lex, xe.Tokenizer = Ls, xe.Hooks = Zn, xe.parse = xe, xe.options, xe.setOptions, xe.use, xe.walkTokens, xe.parseInline, wt.parse, yt.lex; function sl(e, t) { (t == null || t > e.length) && (t = e.length); for (var n = 0, s = Array(t); n < t; n++)s[n] = e[n]; return s } function _f(e) { if (Array.isArray(e)) return e } function Tf(e, t) { var n = e == null ? null : typeof Symbol != "undefined" && e[Symbol.iterator] || e["@@iterator"]; if (n != null) { var s, r, i, o, a = [], l = !0, f = !1; try { if (i = (n = n.call(e)).next, t !== 0) for (; !(l = (s = i.call(n)).done) && (a.push(s.value), a.length !== t); l = !0); } catch (u) { f = !0, r = u } finally { try { if (!l && n.return != null && (o = n.return(), Object(o) !== o)) return } finally { if (f) throw r } } return a } } function kf() { + throw new TypeError(`Invalid attempt to destructure non-iterable instance. +In order to be iterable, non-array objects must have a [Symbol.iterator]() method.`) + } function Sf(e, t) { return _f(e) || Tf(e, t) || Ef(e, t) || kf() } function Ef(e, t) { if (e) { if (typeof e == "string") return sl(e, t); var n = {}.toString.call(e).slice(8, -1); return n === "Object" && e.constructor && (n = e.constructor.name), n === "Map" || n === "Set" ? Array.from(e) : n === "Arguments" || /^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n) ? sl(e, t) : void 0 } } const rl = Object.entries, il = Object.setPrototypeOf, Af = Object.isFrozen, Rf = Object.getPrototypeOf, Cf = Object.getOwnPropertyDescriptor; let Ze = Object.freeze, dt = Object.seal, Tn = Object.create, ol = typeof Reflect != "undefined" && Reflect, $r = ol.apply, Dr = ol.construct; Ze || (Ze = function (t) { return t }), dt || (dt = function (t) { return t }), $r || ($r = function (t, n) { for (var s = arguments.length, r = new Array(s > 2 ? s - 2 : 0), i = 2; i < s; i++)r[i - 2] = arguments[i]; return t.apply(n, r) }), Dr || (Dr = function (t) { for (var n = arguments.length, s = new Array(n > 1 ? n - 1 : 0), r = 1; r < n; r++)s[r - 1] = arguments[r]; return new t(...s) }); const kn = Ie(Array.prototype.forEach), Pf = Ie(Array.prototype.lastIndexOf), ll = Ie(Array.prototype.pop), Sn = Ie(Array.prototype.push), If = Ie(Array.prototype.splice), Xe = Array.isArray, Xn = Ie(String.prototype.toLowerCase), Nr = Ie(String.prototype.toString), al = Ie(String.prototype.match), En = Ie(String.prototype.replace), ul = Ie(String.prototype.indexOf), Mf = Ie(String.prototype.trim), Of = Ie(Number.prototype.toString), Lf = Ie(Boolean.prototype.toString), cl = typeof BigInt == "undefined" ? null : Ie(BigInt.prototype.toString), fl = typeof Symbol == "undefined" ? null : Ie(Symbol.prototype.toString), Ae = Ie(Object.prototype.hasOwnProperty), Qn = Ie(Object.prototype.toString), ze = Ie(RegExp.prototype.test), Ds = $f(TypeError); function Ie(e) { return function (t) { t instanceof RegExp && (t.lastIndex = 0); for (var n = arguments.length, s = new Array(n > 1 ? n - 1 : 0), r = 1; r < n; r++)s[r - 1] = arguments[r]; return $r(e, t, s) } } function $f(e) { return function () { for (var t = arguments.length, n = new Array(t), s = 0; s < t; s++)n[s] = arguments[s]; return Dr(e, n) } } function X(e, t) { let n = arguments.length > 2 && arguments[2] !== void 0 ? arguments[2] : Xn; if (il && il(e, null), !Xe(t)) return e; let s = t.length; for (; s--;) { let r = t[s]; if (typeof r == "string") { const i = n(r); i !== r && (Af(t) || (t[s] = i), r = i) } e[r] = !0 } return e } function Df(e) { for (let t = 0; t < e.length; t++)Ae(e, t) || (e[t] = null); return e } function tt(e) { const t = Tn(null); for (const s of rl(e)) { var n = Sf(s, 2); const r = n[0], i = n[1]; Ae(e, r) && (Xe(i) ? t[r] = Df(i) : i && typeof i == "object" && i.constructor === Object ? t[r] = tt(i) : t[r] = i) } return t } function Nf(e) { switch (typeof e) { case "string": return e; case "number": return Of(e); case "boolean": return Lf(e); case "bigint": return cl ? cl(e) : "0"; case "symbol": return fl ? fl(e) : "Symbol()"; case "undefined": return Qn(e); case "function": case "object": { if (e === null) return Qn(e); const t = e, n = An(t, "toString"); if (typeof n == "function") { const s = n(t); return typeof s == "string" ? s : Qn(s) } return Qn(e) } default: return Qn(e) } } function An(e, t) { for (; e !== null;) { const s = Cf(e, t); if (s) { if (s.get) return Ie(s.get); if (typeof s.value == "function") return Ie(s.value) } e = Rf(e) } function n() { return null } return n } function Ff(e) { try { return ze(e, ""), !0 } catch { return !1 } } const pl = Ze(["a", "abbr", "acronym", "address", "area", "article", "aside", "audio", "b", "bdi", "bdo", "big", "blink", "blockquote", "body", "br", "button", "canvas", "caption", "center", "cite", "code", "col", "colgroup", "content", "data", "datalist", "dd", "decorator", "del", "details", "dfn", "dialog", "dir", "div", "dl", "dt", "element", "em", "fieldset", "figcaption", "figure", "font", "footer", "form", "h1", "h2", "h3", "h4", "h5", "h6", "head", "header", "hgroup", "hr", "html", "i", "img", "input", "ins", "kbd", "label", "legend", "li", "main", "map", "mark", "marquee", "menu", "menuitem", "meter", "nav", "nobr", "ol", "optgroup", "option", "output", "p", "picture", "pre", "progress", "q", "rp", "rt", "ruby", "s", "samp", "search", "section", "select", "shadow", "slot", "small", "source", "spacer", "span", "strike", "strong", "style", "sub", "summary", "sup", "table", "tbody", "td", "template", "textarea", "tfoot", "th", "thead", "time", "tr", "track", "tt", "u", "ul", "var", "video", "wbr"]), Fr = Ze(["svg", "a", "altglyph", "altglyphdef", "altglyphitem", "animatecolor", "animatemotion", "animatetransform", "circle", "clippath", "defs", "desc", "ellipse", "enterkeyhint", "exportparts", "filter", "font", "g", "glyph", "glyphref", "hkern", "image", "inputmode", "line", "lineargradient", "marker", "mask", "metadata", "mpath", "part", "path", "pattern", "polygon", "polyline", "radialgradient", "rect", "stop", "style", "switch", "symbol", "text", "textpath", "title", "tref", "tspan", "view", "vkern"]), Br = Ze(["feBlend", "feColorMatrix", "feComponentTransfer", "feComposite", "feConvolveMatrix", "feDiffuseLighting", "feDisplacementMap", "feDistantLight", "feDropShadow", "feFlood", "feFuncA", "feFuncB", "feFuncG", "feFuncR", "feGaussianBlur", "feImage", "feMerge", "feMergeNode", "feMorphology", "feOffset", "fePointLight", "feSpecularLighting", "feSpotLight", "feTile", "feTurbulence"]), Bf = Ze(["animate", "color-profile", "cursor", "discard", "font-face", "font-face-format", "font-face-name", "font-face-src", "font-face-uri", "foreignobject", "hatch", "hatchpath", "mesh", "meshgradient", "meshpatch", "meshrow", "missing-glyph", "script", "set", "solidcolor", "unknown", "use"]), Hr = Ze(["math", "menclose", "merror", "mfenced", "mfrac", "mglyph", "mi", "mlabeledtr", "mmultiscripts", "mn", "mo", "mover", "mpadded", "mphantom", "mroot", "mrow", "ms", "mspace", "msqrt", "mstyle", "msub", "msup", "msubsup", "mtable", "mtd", "mtext", "mtr", "munder", "munderover", "mprescripts"]), Hf = Ze(["maction", "maligngroup", "malignmark", "mlongdiv", "mscarries", "mscarry", "msgroup", "mstack", "msline", "msrow", "semantics", "annotation", "annotation-xml", "mprescripts", "none"]), dl = Ze(["#text"]), hl = Ze(["accept", "action", "align", "alt", "autocapitalize", "autocomplete", "autopictureinpicture", "autoplay", "background", "bgcolor", "border", "capture", "cellpadding", "cellspacing", "checked", "cite", "class", "clear", "color", "cols", "colspan", "controls", "controlslist", "coords", "crossorigin", "datetime", "decoding", "default", "dir", "disabled", "disablepictureinpicture", "disableremoteplayback", "download", "draggable", "enctype", "enterkeyhint", "exportparts", "face", "for", "headers", "height", "hidden", "high", "href", "hreflang", "id", "inert", "inputmode", "integrity", "ismap", "kind", "label", "lang", "list", "loading", "loop", "low", "max", "maxlength", "media", "method", "min", "minlength", "multiple", "muted", "name", "nonce", "noshade", "novalidate", "nowrap", "open", "optimum", "part", "pattern", "placeholder", "playsinline", "popover", "popovertarget", "popovertargetaction", "poster", "preload", "pubdate", "radiogroup", "readonly", "rel", "required", "rev", "reversed", "role", "rows", "rowspan", "spellcheck", "scope", "selected", "shape", "size", "sizes", "slot", "span", "srclang", "start", "src", "srcset", "step", "style", "summary", "tabindex", "title", "translate", "type", "usemap", "valign", "value", "width", "wrap", "xmlns"]), zr = Ze(["accent-height", "accumulate", "additive", "alignment-baseline", "amplitude", "ascent", "attributename", "attributetype", "azimuth", "basefrequency", "baseline-shift", "begin", "bias", "by", "class", "clip", "clippathunits", "clip-path", "clip-rule", "color", "color-interpolation", "color-interpolation-filters", "color-profile", "color-rendering", "cx", "cy", "d", "dx", "dy", "diffuseconstant", "direction", "display", "divisor", "dur", "edgemode", "elevation", "end", "exponent", "fill", "fill-opacity", "fill-rule", "filter", "filterunits", "flood-color", "flood-opacity", "font-family", "font-size", "font-size-adjust", "font-stretch", "font-style", "font-variant", "font-weight", "fx", "fy", "g1", "g2", "glyph-name", "glyphref", "gradientunits", "gradienttransform", "height", "href", "id", "image-rendering", "in", "in2", "intercept", "k", "k1", "k2", "k3", "k4", "kerning", "keypoints", "keysplines", "keytimes", "lang", "lengthadjust", "letter-spacing", "kernelmatrix", "kernelunitlength", "lighting-color", "local", "marker-end", "marker-mid", "marker-start", "markerheight", "markerunits", "markerwidth", "maskcontentunits", "maskunits", "max", "mask", "mask-type", "media", "method", "mode", "min", "name", "numoctaves", "offset", "operator", "opacity", "order", "orient", "orientation", "origin", "overflow", "paint-order", "path", "pathlength", "patterncontentunits", "patterntransform", "patternunits", "points", "preservealpha", "preserveaspectratio", "primitiveunits", "r", "rx", "ry", "radius", "refx", "refy", "repeatcount", "repeatdur", "restart", "result", "rotate", "scale", "seed", "shape-rendering", "slope", "specularconstant", "specularexponent", "spreadmethod", "startoffset", "stddeviation", "stitchtiles", "stop-color", "stop-opacity", "stroke-dasharray", "stroke-dashoffset", "stroke-linecap", "stroke-linejoin", "stroke-miterlimit", "stroke-opacity", "stroke", "stroke-width", "style", "surfacescale", "systemlanguage", "tabindex", "tablevalues", "targetx", "targety", "transform", "transform-origin", "text-anchor", "text-decoration", "text-rendering", "textlength", "type", "u1", "u2", "unicode", "values", "viewbox", "visibility", "version", "vert-adv-y", "vert-origin-x", "vert-origin-y", "width", "word-spacing", "wrap", "writing-mode", "xchannelselector", "ychannelselector", "x", "x1", "x2", "xmlns", "y", "y1", "y2", "z", "zoomandpan"]), gl = Ze(["accent", "accentunder", "align", "bevelled", "close", "columnalign", "columnlines", "columnspacing", "columnspan", "denomalign", "depth", "dir", "display", "displaystyle", "encoding", "fence", "frame", "height", "href", "id", "largeop", "length", "linethickness", "lquote", "lspace", "mathbackground", "mathcolor", "mathsize", "mathvariant", "maxsize", "minsize", "movablelimits", "notation", "numalign", "open", "rowalign", "rowlines", "rowspacing", "rowspan", "rspace", "rquote", "scriptlevel", "scriptminsize", "scriptsizemultiplier", "selection", "separator", "separators", "stretchy", "subscriptshift", "supscriptshift", "symmetric", "voffset", "width", "xmlns"]), Ns = Ze(["xlink:href", "xml:id", "xlink:title", "xml:space", "xmlns:xlink"]), zf = dt(/{{[\w\W]*|^[\w\W]*}}/g), Uf = dt(/<%[\w\W]*|^[\w\W]*%>/g), jf = dt(/\${[\w\W]*/g), Vf = dt(/^data-[\-\w.\u00B7-\uFFFF]+$/), qf = dt(/^aria-[\-\w]+$/), ml = dt(/^(?:(?:(?:f|ht)tps?|mailto|tel|callto|sms|cid|xmpp|matrix):|[^a-z]|[a-z+.\-]+(?:[^a-z+.\-:]|$))/i), Wf = dt(/^(?:\w+script|data):/i), Gf = dt(/[\u0000-\u0020\u00A0\u1680\u180E\u2000-\u2029\u205F\u3000]/g), Kf = dt(/^html$/i), Yf = dt(/^[a-z][.\w]*(-[.\w]+)+$/i), Rn = { element: 1, text: 3, progressingInstruction: 7, comment: 8, document: 9 }, Zf = function () { return typeof window == "undefined" ? null : window }, Xf = function (t, n) { if (typeof t != "object" || typeof t.createPolicy != "function") return null; let s = null; const r = "data-tt-policy-suffix"; n && n.hasAttribute(r) && (s = n.getAttribute(r)); const i = "dompurify" + (s ? "#" + s : ""); try { return t.createPolicy(i, { createHTML(o) { return o }, createScriptURL(o) { return o } }) } catch { return null } }, bl = function () { return { afterSanitizeAttributes: [], afterSanitizeElements: [], afterSanitizeShadowDOM: [], beforeSanitizeAttributes: [], beforeSanitizeElements: [], beforeSanitizeShadowDOM: [], uponSanitizeAttribute: [], uponSanitizeElement: [], uponSanitizeShadowNode: [] } }; function xl() { + let e = arguments.length > 0 && arguments[0] !== void 0 ? arguments[0] : Zf(); const t = q => xl(q); if (t.version = "3.4.3", t.removed = [], !e || !e.document || e.document.nodeType !== Rn.document || !e.Element) return t.isSupported = !1, t; let n = e.document; const s = n, r = s.currentScript, i = e.DocumentFragment, o = e.HTMLTemplateElement, a = e.Node, l = e.Element, f = e.NodeFilter, u = e.NamedNodeMap, d = u === void 0 ? e.NamedNodeMap || e.MozNamedAttrMap : u, g = e.HTMLFormElement, y = e.DOMParser, E = e.trustedTypes, x = l.prototype, M = An(x, "cloneNode"), m = An(x, "remove"), H = An(x, "nextSibling"), Y = An(x, "childNodes"), $ = An(x, "parentNode"); if (typeof o == "function") { const q = n.createElement("template"); q.content && q.content.ownerDocument && (n = q.content.ownerDocument) } let z, O = ""; const P = n, ee = P.implementation, V = P.createNodeIterator, se = P.createDocumentFragment, fe = P.getElementsByTagName, D = s.importNode; let Z = bl(); t.isSupported = typeof rl == "function" && typeof $ == "function" && ee && ee.createHTMLDocument !== void 0; const Se = zf, Ue = Uf, te = jf, C = Vf, pe = qf, Ge = Wf, re = Gf, B = Yf; let de = ml, ae = null; const ve = X({}, [...pl, ...Fr, ...Br, ...Hr, ...dl]); let ge = null; const nt = X({}, [...hl, ...zr, ...gl, ...Ns]); let ye = Object.seal(Tn(null, { tagNameCheck: { writable: !0, configurable: !1, enumerable: !0, value: null }, attributeNameCheck: { writable: !0, configurable: !1, enumerable: !0, value: null }, allowCustomizedBuiltInElements: { writable: !0, configurable: !1, enumerable: !0, value: !1 } })), ht = null, G = null; const Ce = Object.seal(Tn(null, { tagCheck: { writable: !0, configurable: !1, enumerable: !0, value: null }, attributeCheck: { writable: !0, configurable: !1, enumerable: !0, value: null } })); let Ft = !0, c = !0, h = !1, b = !0, k = !1, v = !0, _ = !1, I = !1, R = !1, A = !1, S = !1, U = !1, L = !0, j = !1; const K = "user-content-"; let ne = !0, he = !1, ie = {}, ke = null; const $e = X({}, ["annotation-xml", "audio", "colgroup", "desc", "foreignobject", "head", "iframe", "math", "mi", "mn", "mo", "ms", "mtext", "noembed", "noframes", "noscript", "plaintext", "script", "style", "svg", "template", "thead", "title", "video", "xmp"]); let ot = null; const lt = X({}, ["audio", "video", "img", "source", "image", "track"]); let Bt = null; const Jn = X({}, ["alt", "class", "for", "id", "label", "name", "pattern", "placeholder", "role", "summary", "title", "value", "style", "xmlns"]), De = "http://www.w3.org/1998/Math/MathML", Qe = "http://www.w3.org/2000/svg", at = "http://www.w3.org/1999/xhtml"; let Ht = at, Ur = !1, jr = null; const hd = X({}, [De, Qe, at], Nr); let Vr = X({}, ["mi", "mo", "mn", "ms", "mtext"]), qr = X({}, ["annotation-xml"]); const gd = X({}, ["title", "style", "font", "a", "script"]); let es = null; const md = ["application/xhtml+xml", "text/html"], bd = "text/html"; let Le = null, Cn = null; const xd = n.createElement("form"), Sl = function (p) { return p instanceof RegExp || p instanceof Function }, Wr = function () { let p = arguments.length > 0 && arguments[0] !== void 0 ? arguments[0] : {}; if (Cn && Cn === p) return; (!p || typeof p != "object") && (p = {}), p = tt(p), es = md.indexOf(p.PARSER_MEDIA_TYPE) === -1 ? bd : p.PARSER_MEDIA_TYPE, Le = es === "application/xhtml+xml" ? Nr : Xn, ae = Ae(p, "ALLOWED_TAGS") && Xe(p.ALLOWED_TAGS) ? X({}, p.ALLOWED_TAGS, Le) : ve, ge = Ae(p, "ALLOWED_ATTR") && Xe(p.ALLOWED_ATTR) ? X({}, p.ALLOWED_ATTR, Le) : nt, jr = Ae(p, "ALLOWED_NAMESPACES") && Xe(p.ALLOWED_NAMESPACES) ? X({}, p.ALLOWED_NAMESPACES, Nr) : hd, Bt = Ae(p, "ADD_URI_SAFE_ATTR") && Xe(p.ADD_URI_SAFE_ATTR) ? X(tt(Jn), p.ADD_URI_SAFE_ATTR, Le) : Jn, ot = Ae(p, "ADD_DATA_URI_TAGS") && Xe(p.ADD_DATA_URI_TAGS) ? X(tt(lt), p.ADD_DATA_URI_TAGS, Le) : lt, ke = Ae(p, "FORBID_CONTENTS") && Xe(p.FORBID_CONTENTS) ? X({}, p.FORBID_CONTENTS, Le) : $e, ht = Ae(p, "FORBID_TAGS") && Xe(p.FORBID_TAGS) ? X({}, p.FORBID_TAGS, Le) : tt({}), G = Ae(p, "FORBID_ATTR") && Xe(p.FORBID_ATTR) ? X({}, p.FORBID_ATTR, Le) : tt({}), ie = Ae(p, "USE_PROFILES") ? p.USE_PROFILES && typeof p.USE_PROFILES == "object" ? tt(p.USE_PROFILES) : p.USE_PROFILES : !1, Ft = p.ALLOW_ARIA_ATTR !== !1, c = p.ALLOW_DATA_ATTR !== !1, h = p.ALLOW_UNKNOWN_PROTOCOLS || !1, b = p.ALLOW_SELF_CLOSE_IN_ATTR !== !1, k = p.SAFE_FOR_TEMPLATES || !1, v = p.SAFE_FOR_XML !== !1, _ = p.WHOLE_DOCUMENT || !1, A = p.RETURN_DOM || !1, S = p.RETURN_DOM_FRAGMENT || !1, U = p.RETURN_TRUSTED_TYPE || !1, R = p.FORCE_BODY || !1, L = p.SANITIZE_DOM !== !1, j = p.SANITIZE_NAMED_PROPS || !1, ne = p.KEEP_CONTENT !== !1, he = p.IN_PLACE || !1, de = Ff(p.ALLOWED_URI_REGEXP) ? p.ALLOWED_URI_REGEXP : ml, Ht = typeof p.NAMESPACE == "string" ? p.NAMESPACE : at, Vr = Ae(p, "MATHML_TEXT_INTEGRATION_POINTS") && p.MATHML_TEXT_INTEGRATION_POINTS && typeof p.MATHML_TEXT_INTEGRATION_POINTS == "object" ? tt(p.MATHML_TEXT_INTEGRATION_POINTS) : X({}, ["mi", "mo", "mn", "ms", "mtext"]), qr = Ae(p, "HTML_INTEGRATION_POINTS") && p.HTML_INTEGRATION_POINTS && typeof p.HTML_INTEGRATION_POINTS == "object" ? tt(p.HTML_INTEGRATION_POINTS) : X({}, ["annotation-xml"]); const T = Ae(p, "CUSTOM_ELEMENT_HANDLING") && p.CUSTOM_ELEMENT_HANDLING && typeof p.CUSTOM_ELEMENT_HANDLING == "object" ? tt(p.CUSTOM_ELEMENT_HANDLING) : Tn(null); if (ye = Tn(null), Ae(T, "tagNameCheck") && Sl(T.tagNameCheck) && (ye.tagNameCheck = T.tagNameCheck), Ae(T, "attributeNameCheck") && Sl(T.attributeNameCheck) && (ye.attributeNameCheck = T.attributeNameCheck), Ae(T, "allowCustomizedBuiltInElements") && typeof T.allowCustomizedBuiltInElements == "boolean" && (ye.allowCustomizedBuiltInElements = T.allowCustomizedBuiltInElements), k && (c = !1), S && (A = !0), ie && (ae = X({}, dl), ge = Tn(null), ie.html === !0 && (X(ae, pl), X(ge, hl)), ie.svg === !0 && (X(ae, Fr), X(ge, zr), X(ge, Ns)), ie.svgFilters === !0 && (X(ae, Br), X(ge, zr), X(ge, Ns)), ie.mathMl === !0 && (X(ae, Hr), X(ge, gl), X(ge, Ns))), Ce.tagCheck = null, Ce.attributeCheck = null, Ae(p, "ADD_TAGS") && (typeof p.ADD_TAGS == "function" ? Ce.tagCheck = p.ADD_TAGS : Xe(p.ADD_TAGS) && (ae === ve && (ae = tt(ae)), X(ae, p.ADD_TAGS, Le))), Ae(p, "ADD_ATTR") && (typeof p.ADD_ATTR == "function" ? Ce.attributeCheck = p.ADD_ATTR : Xe(p.ADD_ATTR) && (ge === nt && (ge = tt(ge)), X(ge, p.ADD_ATTR, Le))), Ae(p, "ADD_URI_SAFE_ATTR") && Xe(p.ADD_URI_SAFE_ATTR) && X(Bt, p.ADD_URI_SAFE_ATTR, Le), Ae(p, "FORBID_CONTENTS") && Xe(p.FORBID_CONTENTS) && (ke === $e && (ke = tt(ke)), X(ke, p.FORBID_CONTENTS, Le)), Ae(p, "ADD_FORBID_CONTENTS") && Xe(p.ADD_FORBID_CONTENTS) && (ke === $e && (ke = tt(ke)), X(ke, p.ADD_FORBID_CONTENTS, Le)), ne && (ae["#text"] = !0), _ && X(ae, ["html", "head", "body"]), ae.table && (X(ae, ["tbody"]), delete ht.tbody), p.TRUSTED_TYPES_POLICY) { if (typeof p.TRUSTED_TYPES_POLICY.createHTML != "function") throw Ds('TRUSTED_TYPES_POLICY configuration option must provide a "createHTML" hook.'); if (typeof p.TRUSTED_TYPES_POLICY.createScriptURL != "function") throw Ds('TRUSTED_TYPES_POLICY configuration option must provide a "createScriptURL" hook.'); z = p.TRUSTED_TYPES_POLICY, O = z.createHTML("") } else z === void 0 && (z = Xf(E, r)), z !== null && typeof O == "string" && (O = z.createHTML("")); Ze && Ze(p), Cn = p }, El = X({}, [...Fr, ...Br, ...Bf]), Al = X({}, [...Hr, ...Hf]), yd = function (p) { let T = $(p); (!T || !T.tagName) && (T = { namespaceURI: Ht, tagName: "template" }); const N = Xn(p.tagName), ce = Xn(T.tagName); return jr[p.namespaceURI] ? p.namespaceURI === Qe ? T.namespaceURI === at ? N === "svg" : T.namespaceURI === De ? N === "svg" && (ce === "annotation-xml" || Vr[ce]) : !!El[N] : p.namespaceURI === De ? T.namespaceURI === at ? N === "math" : T.namespaceURI === Qe ? N === "math" && qr[ce] : !!Al[N] : p.namespaceURI === at ? T.namespaceURI === Qe && !qr[ce] || T.namespaceURI === De && !Vr[ce] ? !1 : !Al[N] && (gd[N] || !El[N]) : !!(es === "application/xhtml+xml" && jr[p.namespaceURI]) : !1 }, vt = function (p) { Sn(t.removed, { element: p }); try { $(p).removeChild(p) } catch { m(p) } }, dn = function (p, T) { try { Sn(t.removed, { attribute: T.getAttributeNode(p), from: T }) } catch { Sn(t.removed, { attribute: null, from: T }) } if (T.removeAttribute(p), p === "is") if (A || S) try { vt(T) } catch { } else try { T.setAttribute(p, "") } catch { } }, Rl = function (p) { let T = null, N = null; if (R) p = "" + p; else { const Me = al(p, /^[\r\n\t ]+/); N = Me && Me[0] } es === "application/xhtml+xml" && Ht === at && (p = '' + p + ""); const ce = z ? z.createHTML(p) : p; if (Ht === at) try { T = new y().parseFromString(ce, es) } catch { } if (!T || !T.documentElement) { T = ee.createDocument(Ht, "template", null); try { T.documentElement.innerHTML = Ur ? O : ce } catch { } } const Ne = T.body || T.documentElement; return p && N && Ne.insertBefore(n.createTextNode(N), Ne.childNodes[0] || null), Ht === at ? fe.call(T, _ ? "html" : "body")[0] : _ ? T.documentElement : Ne }, Cl = function (p) { return V.call(p.ownerDocument || p, p, f.SHOW_ELEMENT | f.SHOW_COMMENT | f.SHOW_TEXT | f.SHOW_PROCESSING_INSTRUCTION | f.SHOW_CDATA_SECTION, null) }, Gr = function (p) { return p instanceof g && (typeof p.nodeName != "string" || typeof p.textContent != "string" || typeof p.removeChild != "function" || !(p.attributes instanceof d) || typeof p.removeAttribute != "function" || typeof p.setAttribute != "function" || typeof p.namespaceURI != "string" || typeof p.insertBefore != "function" || typeof p.hasChildNodes != "function") }, Kr = function (p) { return typeof a == "function" && p instanceof a }; function zt(q, p, T) { kn(q, N => { N.call(t, p, T, Cn) }) } const Pl = function (p) { let T = null; if (zt(Z.beforeSanitizeElements, p, null), Gr(p)) return vt(p), !0; const N = Le(p.nodeName); if (zt(Z.uponSanitizeElement, p, { tagName: N, allowedTags: ae }), v && p.hasChildNodes() && !Kr(p.firstElementChild) && ze(/<[/\w!]/g, p.innerHTML) && ze(/<[/\w!]/g, p.textContent) || v && p.namespaceURI === at && N === "style" && Kr(p.firstElementChild) || p.nodeType === Rn.progressingInstruction || v && p.nodeType === Rn.comment && ze(/<[/\w]/g, p.data)) return vt(p), !0; if (ht[N] || !(Ce.tagCheck instanceof Function && Ce.tagCheck(N)) && !ae[N]) { if (!ht[N] && Ml(N) && (ye.tagNameCheck instanceof RegExp && ze(ye.tagNameCheck, N) || ye.tagNameCheck instanceof Function && ye.tagNameCheck(N))) return !1; if (ne && !ke[N]) { const ce = $(p) || p.parentNode, Ne = Y(p) || p.childNodes; if (Ne && ce) { const Me = Ne.length; for (let st = Me - 1; st >= 0; --st) { const gt = M(Ne[st], !0); ce.insertBefore(gt, H(p)) } } } return vt(p), !0 } return p instanceof l && !yd(p) || (N === "noscript" || N === "noembed" || N === "noframes") && ze(/<\/no(script|embed|frames)/i, p.innerHTML) ? (vt(p), !0) : (k && p.nodeType === Rn.text && (T = p.textContent, kn([Se, Ue, te], ce => { T = En(T, ce, " ") }), p.textContent !== T && (Sn(t.removed, { element: p.cloneNode() }), p.textContent = T)), zt(Z.afterSanitizeElements, p, null), !1) }, Il = function (p, T, N) { if (G[T] || L && (T === "id" || T === "name") && (N in n || N in xd)) return !1; const ce = ge[T] || Ce.attributeCheck instanceof Function && Ce.attributeCheck(T, p); if (!(c && !G[T] && ze(C, T))) { if (!(Ft && ze(pe, T))) { if (!ce || G[T]) { if (!(Ml(p) && (ye.tagNameCheck instanceof RegExp && ze(ye.tagNameCheck, p) || ye.tagNameCheck instanceof Function && ye.tagNameCheck(p)) && (ye.attributeNameCheck instanceof RegExp && ze(ye.attributeNameCheck, T) || ye.attributeNameCheck instanceof Function && ye.attributeNameCheck(T, p)) || T === "is" && ye.allowCustomizedBuiltInElements && (ye.tagNameCheck instanceof RegExp && ze(ye.tagNameCheck, N) || ye.tagNameCheck instanceof Function && ye.tagNameCheck(N)))) return !1 } else if (!Bt[T]) { if (!ze(de, En(N, re, ""))) { if (!((T === "src" || T === "xlink:href" || T === "href") && p !== "script" && ul(N, "data:") === 0 && ot[p])) { if (!(h && !ze(Ge, En(N, re, "")))) { if (N) return !1 } } } } } } return !0 }, wd = X({}, ["annotation-xml", "color-profile", "font-face", "font-face-format", "font-face-name", "font-face-src", "font-face-uri", "missing-glyph"]), Ml = function (p) { return !wd[Xn(p)] && ze(B, p) }, Ol = function (p) { zt(Z.beforeSanitizeAttributes, p, null); const T = p.attributes; if (!T || Gr(p)) return; const N = { attrName: "", attrValue: "", keepAttr: !0, allowedAttributes: ge, forceKeepAttr: void 0 }; let ce = T.length; for (; ce--;) { const Ne = T[ce], Me = Ne.name, st = Ne.namespaceURI, gt = Ne.value, _t = Le(Me), Zr = gt; let Fe = Me === "value" ? Zr : Mf(Zr); if (N.attrName = _t, N.attrValue = Fe, N.keepAttr = !0, N.forceKeepAttr = void 0, zt(Z.uponSanitizeAttribute, p, N), Fe = N.attrValue, j && (_t === "id" || _t === "name") && ul(Fe, K) !== 0 && (dn(Me, p), Fe = K + Fe), v && ze(/((--!?|])>)|<\/(style|script|title|xmp|textarea|noscript|iframe|noembed|noframes)/i, Fe)) { dn(Me, p); continue } if (_t === "attributename" && al(Fe, "href")) { dn(Me, p); continue } if (N.forceKeepAttr) continue; if (!N.keepAttr) { dn(Me, p); continue } if (!b && ze(/\/>/i, Fe)) { dn(Me, p); continue } k && kn([Se, Ue, te], $l => { Fe = En(Fe, $l, " ") }); const Ll = Le(p.nodeName); if (!Il(Ll, _t, Fe)) { dn(Me, p); continue } if (z && typeof E == "object" && typeof E.getAttributeType == "function" && !st) switch (E.getAttributeType(Ll, _t)) { case "TrustedHTML": { Fe = z.createHTML(Fe); break } case "TrustedScriptURL": { Fe = z.createScriptURL(Fe); break } }if (Fe !== Zr) try { st ? p.setAttributeNS(st, Me, Fe) : p.setAttribute(Me, Fe), Gr(p) ? vt(p) : ll(t.removed) } catch { dn(Me, p) } } zt(Z.afterSanitizeAttributes, p, null) }, Yr = function (p) { let T = null; const N = Cl(p); for (zt(Z.beforeSanitizeShadowDOM, p, null); T = N.nextNode();)zt(Z.uponSanitizeShadowNode, T, null), Pl(T), Ol(T), T.content instanceof i && Yr(T.content); zt(Z.afterSanitizeShadowDOM, p, null) }, Bs = function (p) { if (p.nodeType === Rn.element && p.shadowRoot instanceof i) { const ce = p.shadowRoot; Bs(ce), Yr(ce) } const T = p.childNodes; if (!T) return; const N = []; kn(T, ce => { Sn(N, ce) }); for (const ce of N) Bs(ce) }; return t.sanitize = function (q) { + let p = arguments.length > 1 && arguments[1] !== void 0 ? arguments[1] : {}, T = null, N = null, ce = null, Ne = null; if (Ur = !q, Ur && (q = ""), typeof q != "string" && !Kr(q) && (q = Nf(q), typeof q != "string")) throw Ds("dirty is not a string, aborting"); if (!t.isSupported) return q; if (I || Wr(p), t.removed = [], typeof q == "string" && (he = !1), he) { const gt = q.nodeName; if (typeof gt == "string") { const _t = Le(gt); if (!ae[_t] || ht[_t]) throw Ds("root node is forbidden and cannot be sanitized in-place") } Bs(q) } else if (q instanceof a) T = Rl(""), N = T.ownerDocument.importNode(q, !0), N.nodeType === Rn.element && N.nodeName === "BODY" || N.nodeName === "HTML" ? T = N : T.appendChild(N), Bs(N); else { if (!A && !k && !_ && q.indexOf("<") === -1) return z && U ? z.createHTML(q) : q; if (T = Rl(q), !T) return A ? null : U ? O : "" } T && R && vt(T.firstChild); const Me = Cl(he ? q : T); for (; ce = Me.nextNode();)Pl(ce), Ol(ce), ce.content instanceof i && Yr(ce.content); if (he) return q; if (A) { if (k) { T.normalize(); let gt = T.innerHTML; kn([Se, Ue, te], _t => { gt = En(gt, _t, " ") }), T.innerHTML = gt } if (S) for (Ne = se.call(T.ownerDocument); T.firstChild;)Ne.appendChild(T.firstChild); else Ne = T; return (ge.shadowroot || ge.shadowrootmode) && (Ne = D.call(s, Ne, !0)), Ne } let st = _ ? T.outerHTML : T.innerHTML; return _ && ae["!doctype"] && T.ownerDocument && T.ownerDocument.doctype && T.ownerDocument.doctype.name && ze(Kf, T.ownerDocument.doctype.name) && (st = " +`+ st), k && kn([Se, Ue, te], gt => { st = En(st, gt, " ") }), z && U ? z.createHTML(st) : st + }, t.setConfig = function () { let q = arguments.length > 0 && arguments[0] !== void 0 ? arguments[0] : {}; Wr(q), I = !0 }, t.clearConfig = function () { Cn = null, I = !1 }, t.isValidAttribute = function (q, p, T) { Cn || Wr({}); const N = Le(q), ce = Le(p); return Il(N, ce, T) }, t.addHook = function (q, p) { typeof p == "function" && Sn(Z[q], p) }, t.removeHook = function (q, p) { if (p !== void 0) { const T = Pf(Z[q], p); return T === -1 ? void 0 : If(Z[q], T, 1)[0] } return ll(Z[q]) }, t.removeHooks = function (q) { Z[q] = [] }, t.removeAllHooks = function () { Z = bl() }, t + } var Qf = xl(); const Jf = { key: 1, class: "flex min-w-0 max-w-[calc(100%-2.5rem)] flex-1 flex-col max-[600px]:max-w-[calc(100%-2.25rem)]" }, ep = { key: 0, class: "flex w-fit flex-col items-start gap-1" }, tp = ["aria-label"], np = { class: "inline-flex items-center gap-1.5" }, sp = { class: "text-[8px] font-semibold tracking-[0.12em] uppercase text-[#3a67c9]" }, rp = { key: 1, class: "flex w-fit max-w-full flex-col items-start gap-2" }, ip = { class: "chat-card relative w-fit max-w-full whitespace-pre-line rounded-[10px_10px_10px_3px] px-4 py-3 text-xs leading-relaxed wrap-anywhere text-slate-900" }, op = ["innerHTML"], lp = { key: 0, class: "pointer-events-none absolute inset-x-0 bottom-0 h-14 rounded-b-[10px] bg-linear-to-t from-white via-white/92 to-white/0", "aria-hidden": "true" }, ap = { key: 0, class: "flex flex-wrap items-center gap-2" }, up = ["title", "aria-label"], cp = { key: 1, class: "flex flex-wrap items-center" }, fp = ["title", "aria-label"], pp = { viewBox: "0 0 24 24", width: "14", height: "14", fill: "none", stroke: "currentColor", "stroke-width": "2", "aria-hidden": "true" }, dp = ["innerHTML"], yl = { __name: "ChatMessage", props: { message: { type: Object, required: !0 }, autoReadEnabled: { type: Boolean, default: !1 }, ttsConfig: { type: Object, default: () => ({ enableVoiceChat: !1, pollyAvailable: !1, usePolly: !0, voiceId: "Zayd" }) } }, setup(e) { const t = e, n = J(!1), s = J(null), r = J(!1), i = J(!1), o = Ee(() => typeof window != "undefined" && "speechSynthesis" in window && "SpeechSynthesisUtterance" in window); function a(O) { typeof window != "undefined" && window.dispatchEvent(new CustomEvent("changai-tts-provider", { detail: { provider: O } })) } function l(O) { if (typeof O != "string") return ""; const P = O.replace(/[\u{1F000}-\u{1FFFF}]/gu, "").replace(/[\u{2600}-\u{26FF}]/gu, "").replace(/[\u{2700}-\u{27BF}]/gu, "").replace(/\*\*(.*?)\*\*/g, "$1").replace(/\*(.*?)\*/g, "$1").replace(/`([^`]+)`/g, "$1").replace(/#{1,6}\s+/g, "").replace(/[-*+]\s+/g, "").replace(/\[([^\]]+)\]\([^)]+\)/g, "$1").replace(/\s+/g, " "); return P.includes("<") ? (new DOMParser().parseFromString(O, "text/html").body.textContent || "").replace(/\s+/g, " ").trim() : P.trim() } function f() { o.value && window.speechSynthesis.cancel(), s.value && (s.value.pause(), s.value.src = "", s.value = null), n.value = !1 } function u() { var O, P, ee; if (i.value = !i.value, i.value) f(); else { const V = M.value; if (!t.autoReadEnabled || !((O = t.ttsConfig) != null && O.enableVoiceChat) || !V || E()) return; if ((P = t.ttsConfig) != null && P.pollyAvailable && ((ee = t.ttsConfig) != null && ee.usePolly)) { g(V).catch(se => { d(V) }); return } d(V) } } function d(O) { if (!o.value || !O) return; window.dispatchEvent(new CustomEvent("changai-tts-stop")), window.speechSynthesis.cancel(); const P = new SpeechSynthesisUtterance(O); P.rate = 1, P.pitch = 1, P.onend = () => { n.value = !1 }, P.onerror = () => { n.value = !1 }, n.value = !0, a("browser"), window.speechSynthesis.speak(P) } async function g(O) { var fe; const P = await Oc(O, ((fe = t.ttsConfig) == null ? void 0 : fe.voiceId) || "Zayd"); if (!(P != null && P.ok) || !(P != null && P.audio_base64)) throw new Error((P == null ? void 0 : P.error) || "Polly synthesis failed"); window.dispatchEvent(new CustomEvent("changai-tts-stop")), f(); const ee = (P == null ? void 0 : P.mime_type) || "audio/mpeg", V = new Audio(`data:${ee};base64,${P.audio_base64}`); s.value = V, n.value = !0; let se = !1; V.onplay = () => { se = !0, a("polly") }, V.onended = () => { s.value === V && (s.value = null), n.value = !1 }, V.onerror = () => { s.value === V && (s.value = null), n.value = !1 }, await V.play(), se || a("polly") } function y() { f() } function E() { var O; return !!((O = t.message) != null && O.isStatus) } function x(O) { const P = O.target.closest("a"); !P || !P.href || (O.preventDefault(), O.stopPropagation(), window.open(P.href, "_blank", "noopener,noreferrer")) } const M = Ee(() => { var O; return l(((O = t.message) == null ? void 0 : O.text) || "") }), m = Ee(() => { var O; return ((O = t.message) == null ? void 0 : O.role) !== "user" && E() }), H = Ee(() => { var O; return (O = t.message) != null && O.isStatus ? t.message.statusType === "support" ? "Sending to support" : M.value || "Thinking" : "" }), Y = Ee(() => { var ee; if (((ee = t.message) == null ? void 0 : ee.role) === "user" || m.value) return !1; const O = M.value, P = O.split(/\n+/).filter(Boolean).length; return O.length > 520 || P > 8 }), $ = Ee(() => { var O, P; return ((O = t.message) == null ? void 0 : O.role) !== "user" && !m.value && ((P = t.ttsConfig) == null ? void 0 : P.enableVoiceChat) }), z = Ee(() => { var P; const O = ((P = t.message) == null ? void 0 : P.text) || ""; return Qf.sanitize(xe.parse(O)) }); return on(() => t.message.text, async (O, P) => { var se, fe, D; if (!t.autoReadEnabled || t.message.role === "user" || i.value) return; if (!((se = t.ttsConfig) != null && se.enableVoiceChat)) { a("off"); return } const ee = l(O); if (!ee || E()) return; const V = l(P || ""); if (ee !== V) { if ((fe = t.ttsConfig) != null && fe.pollyAvailable && ((D = t.ttsConfig) != null && D.usePolly)) try { await g(ee); return } catch { } d(ee) } }), on(() => t.message.text, () => { r.value = !1, i.value = !1 }), zn(() => { typeof window != "undefined" && window.addEventListener("changai-tts-stop", y) }), ys(() => { typeof window != "undefined" && window.removeEventListener("changai-tts-stop", y), n.value && f() }), (O, P) => (F(), W("div", { class: we(["motion-safe:animate-fade-rise flex w-full gap-1.5", e.message.role === "user" ? "flex-col items-end" : "items-start"]) }, [e.message.role !== "user" ? (F(), Et(Fo, { key: 0 })) : qe("", !0), e.message.role !== "user" ? (F(), W("div", Jf, [m.value ? (F(), W("div", ep, [w("div", { class: "chat-card inline-flex w-fit rounded-[10px_10px_10px_3px] px-3 py-2", role: "status", "aria-live": "polite", "aria-label": H.value }, [w("div", np, [P[1] || (P[1] = w("span", { class: "relative inline-flex h-4 w-4 shrink-0 items-center justify-center" }, [w("span", { class: "absolute inset-0 rounded-full border border-transparent border-t-[#4b89ff] border-r-[#4b89ff]/70 animate-gemini-arc" }), w("svg", { viewBox: "0 0 24 24", class: "relative h-3 w-3 text-[#4b89ff] animate-gemini-spark", "aria-hidden": "true" }, [w("path", { fill: "currentColor", d: "M12 2.8c.52 3.22 1.6 5.66 3.22 7.28 1.62 1.62 4.06 2.7 7.28 3.22-3.22.52-5.66 1.6-7.28 3.22-1.62 1.62-2.7 4.06-3.22 7.28-.52-3.22-1.6-5.66-3.22-7.28-1.62-1.62-4.06-2.7-7.28-3.22 3.22-.52 5.66-1.6 7.28-3.22 1.62-1.62 2.7-4.06 3.22-7.28Z" })])], -1)), w("span", sp, Je(H.value), 1)])], 8, tp)])) : (F(), W("div", rp, [w("div", ip, [w("div", { class: we(["overflow-x-auto", Y.value && !r.value ? "max-h-48 overflow-y-hidden" : ""]), innerHTML: z.value, onClick: x }, null, 10, op), Y.value && !r.value ? (F(), W("div", lp)) : qe("", !0)]), Y.value ? (F(), W("div", ap, [w("button", { type: "button", class: "inline-flex items-center rounded-full border border-slate-200 bg-white px-2.5 py-1 text-[10px] font-semibold uppercase tracking-[0.08em] text-slate-600 transition-colors duration-200 hover:border-brand-200 hover:text-brand-600", title: r.value ? "Collapse response" : "Expand response", "aria-label": r.value ? "Collapse response" : "Expand response", onClick: P[0] || (P[0] = ee => r.value = !r.value) }, Je(r.value ? "Collapse" : "Expand"), 9, up)])) : qe("", !0), $.value ? (F(), W("div", cp, [w("button", { type: "button", class: we(["inline-flex h-8 w-8 items-center justify-center rounded-full border transition-colors duration-200", i.value ? "border-red-200 bg-red-50 text-red-600 hover:border-red-300 hover:bg-red-100" : "border-green-200 bg-green-50 text-green-600 hover:border-green-300 hover:bg-green-100"]), title: i.value ? "Unmute voice playback" : "Mute voice playback", "aria-label": i.value ? "Unmute voice playback" : "Mute voice playback", onClick: u }, [(F(), W("svg", pp, [P[6] || (P[6] = w("path", { d: "M11 5L6 9H3v6h3l5 4V5Z" }, null, -1)), i.value ? (F(), W(He, { key: 0 }, [P[2] || (P[2] = w("path", { d: "M15 9l4 6" }, null, -1)), P[3] || (P[3] = w("path", { d: "M19 9l-4 6" }, null, -1))], 64)) : (F(), W(He, { key: 1 }, [P[4] || (P[4] = w("path", { d: "M15 10a3 3 0 0 1 0 4" }, null, -1)), P[5] || (P[5] = w("path", { d: "M17.5 7.5a6 6 0 0 1 0 9" }, null, -1))], 64))]))], 10, fp)])) : qe("", !0)]))])) : (F(), W("div", { key: 2, class: "w-fit max-w-[85%] whitespace-pre-line rounded-[13px_13px_3px_13px] bg-linear-to-br from-brand-500 to-brand-600 px-4 py-3 text-[11px] leading-relaxed wrap-anywhere text-white shadow-[0_14px_30px_-18px_rgba(109,79,194,0.85)] max-[600px]:max-w-[88%]", innerHTML: z.value }, null, 8, dp))], 2)) } }, hp = { class: "flex flex-col gap-4 sm:gap-5" }, gp = { class: "motion-safe:animate-fade-rise flex w-full items-start gap-1.5" }, mp = { __name: "ChatTab", props: { messages: { type: Array, required: !0 }, autoReadEnabled: { type: Boolean, default: !1 }, ttsConfig: { type: Object, required: !0 } }, setup(e) { return (t, n) => (F(), W("div", hp, [w("div", gp, [Oe(Fo), n[0] || (n[0] = w("p", { class: "w-fit max-w-[calc(100%-2.5rem)] whitespace-pre-line rounded-[10px_10px_10px_3px] bg-brand-50 px-4 py-3 text-xs leading-relaxed wrap-anywhere text-slate-900 max-[600px]:max-w-[calc(100%-2.25rem)]" }, [Ss(" Hello there 👋 I am ChangAI from "), w("a", { target: "_blank", href: "https://erpgulf.com", rel: "noopener noreferrer", style: { color: "#1e90ff" } }, "ERPGulf.com"), Ss(", your ERP assistant."), w("br"), w("a", { target: "_blank", href: "https://app.erpgulf.com/en/articles/chang-ai-quick-start-guide", rel: "noopener noreferrer", style: { color: "#1e90ff" } }, "ChangAI Quick Start Guide - Click here.")], -1))]), (F(!0), W(He, null, ws(e.messages, (s, r) => (F(), Et(yl, { key: r, message: s, autoReadEnabled: e.autoReadEnabled, ttsConfig: e.ttsConfig }, null, 8, ["message", "autoReadEnabled", "ttsConfig"]))), 128))])) } }; function wl(e) { try { return JSON.stringify(e, null, 2) } catch { return String(e) } } function vl(e) { var t, n; return (e == null ? void 0 : e.message) || ((t = e == null ? void 0 : e.responseJSON) == null ? void 0 : t.exception) || ((n = e == null ? void 0 : e.responseJSON) == null ? void 0 : n.message) || (e == null ? void 0 : e.responseText) || String(e) } function bp(e) { return typeof e == "string" ? e : e && typeof e == "object" ? e.error ? `⚠️ ${e.error}` : e.answer || e.text || "" : "" } const xp = { key: 0, class: "rounded-lg bg-brand-50 px-4 py-3 text-xs text-black" }, yp = { class: "whitespace-pre-wrap wrap-anywhere text-[11px] leading-relaxed text-black" }, wp = { key: 1, class: "mb-3 min-w-0 overflow-x-auto rounded-lg bg-brand-50 p-2 text-[11px]" }, vp = { class: "whitespace-pre-wrap wrap-anywhere text-[11px] leading-relaxed text-black" }, _p = { __name: "DebugTab", props: { logs: { type: Array, required: !0 }, currentDebug: { type: Object, default: null } }, setup(e) { const t = new Set(["gemini_json_content", "private_key", "private_key_id", "client_secret", "client_id", "aws_access_key", "aws_secret_key", "api_key", "token", "access_token", "refresh_token", "password", "secret", "authorization", "embed_version_id", "llm_version_id", "entity_retriever", "retriever", "deploy_url", "support_api_url", "get_ticket_details_url"]); function n(r, i = 0) { if (i > 10 || r === null || r === void 0 || typeof r == "string" || typeof r == "number" || typeof r == "boolean") return r; if (Array.isArray(r)) return r.map(o => n(o, i + 1)); if (typeof r == "object") { const o = {}; for (const [a, l] of Object.entries(r)) t.has(a.toLowerCase()) || (o[a] = n(l, i + 1)); return o } return r } function s(r) { return wl(n(r)) } return (r, i) => (F(), W("div", null, [e.logs.length === 0 ? (F(), W("p", xp, "No debug data yet.")) : qe("", !0), (F(!0), W(He, null, ws(e.logs, (o, a) => (F(), W("div", { key: a, class: "mb-3 min-w-0 overflow-x-auto rounded-lg bg-gray-100 p-2 text-[11px]" }, [w("pre", yp, Je(s(o)), 1)]))), 128)), e.currentDebug ? (F(), W("div", wp, [w("pre", vp, Je(s(e.currentDebug)), 1)])) : qe("", !0)])) } }, Tp = { class: "flex flex-col gap-4 sm:gap-5" }, kp = { key: 0, class: "chat-card motion-safe:animate-fade-rise rounded-lg px-4 py-3 text-xs text-slate-900" }, Sp = { __name: "SupportTab", props: { messages: { type: Array, required: !0 }, autoReadEnabled: { type: Boolean, default: !1 }, ttsConfig: { type: Object, required: !0 } }, setup(e) { return (t, n) => (F(), W("div", Tp, [e.messages.length === 0 ? (F(), W("p", kp, "Send a message to Support.")) : qe("", !0), (F(!0), W(He, null, ws(e.messages, (s, r) => (F(), Et(yl, { key: r, message: s, autoReadEnabled: e.autoReadEnabled, ttsConfig: e.ttsConfig }, null, 8, ["message", "autoReadEnabled", "ttsConfig"]))), 128))])) } }, Ep = { class: "flex flex-col gap-4" }, Ap = { class: "chat-card motion-safe:animate-fade-rise rounded-xl p-4" }, Rp = { class: "flex items-start justify-between gap-4" }, Cp = ["aria-pressed", "title"], Pp = { class: "chat-card motion-safe:animate-fade-rise rounded-xl p-4" }, Ip = { class: "flex items-start justify-between gap-4" }, Mp = { class: "mt-2 text-[11px] text-slate-500" }, Op = { key: 0, class: "mt-1 text-[11px] text-slate-500" }, Lp = { key: 1, class: "mt-1 text-[11px] text-slate-500" }, $p = ["aria-pressed", "disabled"], Dp = { key: 0, class: "mt-3 rounded-md bg-amber-50 px-2.5 py-2 text-xs text-amber-700" }, Np = { key: 1, class: "mt-3 rounded-md bg-amber-50 px-2.5 py-2 text-xs text-amber-700" }, Fp = { class: "chat-card motion-safe:animate-fade-rise rounded-xl p-4" }, Bp = { class: "flex items-start justify-between gap-4" }, Hp = ["aria-pressed", "title"], zp = { class: "chat-card motion-safe:animate-fade-rise rounded-xl p-4" }, Up = { class: "flex items-start justify-between gap-4" }, jp = ["aria-pressed", "title"], Vp = { __name: "SettingsTab", props: { autoReadEnabled: { type: Boolean, required: !0 }, ttsConfig: { type: Object, required: !0 }, settings: { type: Object, default: null }, debugEnabled: { type: Boolean, default: !1 }, sendNonERPtoaiEnabled: { type: Boolean, default: !1 } }, emits: ["toggleAutoRead", "togglePollyPreference", "toggleDebug", "toggleSendNonERP"], setup(e) { const t = e, n = Ee(() => { var s, r; return (s = t.ttsConfig) != null && s.enableVoiceChat ? (r = t.ttsConfig) != null && r.pollyAvailable ? "Available" : "Unavailable" : "Voice disabled on server" }); return (s, r) => { var i, o, a, l, f, u, d, g, y, E, x, M, m, H, Y; return F(), W("div", Ep, [r[10] || (r[10] = w("div", { class: "chat-card motion-safe:animate-fade-rise rounded-xl p-4 text-slate-900" }, [w("h3", { class: "text-sm font-semibold tracking-[0.01em]" }, "Speech Settings"), w("p", { class: "mt-1 text-xs leading-relaxed text-slate-600" }, "These controls apply only inside this chatbot box for the current browser session.")], -1)), w("div", Ap, [w("div", Rp, [r[4] || (r[4] = w("div", null, [w("p", { class: "text-sm font-semibold text-slate-900" }, "Auto Read Replies"), w("p", { class: "mt-1 text-xs text-slate-600" }, "Automatically read bot replies aloud.")], -1)), w("button", { class: we(["group relative h-7 w-12 shrink-0 rounded-full border border-slate-200 transition-all duration-200", e.autoReadEnabled ? "bg-emerald-500/95" : "bg-slate-300"]), "aria-pressed": e.autoReadEnabled ? "true" : "false", title: e.autoReadEnabled ? "Disable auto read" : "Enable auto read", onClick: r[0] || (r[0] = $ => s.$emit("toggleAutoRead")) }, [w("span", { class: we(["absolute top-0.5 h-5.5 w-5.5 rounded-full bg-white shadow-sm transition-all duration-200", e.autoReadEnabled ? "left-[1.45rem]" : "left-0.5"]) }, null, 2)], 10, Cp)]), w("p", { class: we(["mt-3 text-[11px] font-medium", e.autoReadEnabled ? "text-emerald-700" : "text-slate-500"]) }, Je(e.autoReadEnabled ? "Auto read is active." : "Auto read is currently off."), 3)]), w("div", Pp, [w("div", Ip, [w("div", null, [r[5] || (r[5] = w("p", { class: "text-sm font-semibold text-slate-900" }, "Use Amazon Polly", -1)), r[6] || (r[6] = w("p", { class: "mt-1 text-xs text-slate-600" }, "Use Polly when available; otherwise browser speech is used automatically.", -1)), w("p", Mp, "Availability: " + Je(n.value), 1), (i = e.settings) != null && i.aws_region ? (F(), W("p", Op, "Region: " + Je(e.settings.aws_region), 1)) : qe("", !0), (o = e.ttsConfig) != null && o.voiceId ? (F(), W("p", Lp, "Voice: " + Je(e.ttsConfig.voiceId), 1)) : qe("", !0)]), w("button", { class: we(["relative h-7 w-12 shrink-0 rounded-full border border-slate-200 transition-all duration-200 disabled:cursor-not-allowed disabled:opacity-55", (a = e.ttsConfig) != null && a.usePolly && ((l = e.ttsConfig) != null && l.enableVoiceChat) && ((f = e.ttsConfig) != null && f.pollyAvailable) ? "bg-emerald-500/95" : "bg-slate-300"]), "aria-pressed": (u = e.ttsConfig) != null && u.usePolly && ((d = e.ttsConfig) != null && d.enableVoiceChat) && ((g = e.ttsConfig) != null && g.pollyAvailable) ? "true" : "false", disabled: !((y = e.ttsConfig) != null && y.pollyAvailable) || !((E = e.ttsConfig) != null && E.enableVoiceChat), onClick: r[1] || (r[1] = $ => s.$emit("togglePollyPreference")) }, [w("span", { class: we(["absolute top-0.5 h-5.5 w-5.5 rounded-full bg-white shadow-sm transition-all duration-200", (x = e.ttsConfig) != null && x.usePolly && ((M = e.ttsConfig) != null && M.enableVoiceChat) && ((m = e.ttsConfig) != null && m.pollyAvailable) ? "left-[1.45rem]" : "left-0.5"]) }, null, 2)], 10, $p)]), (H = e.ttsConfig) != null && H.enableVoiceChat ? (Y = e.ttsConfig) != null && Y.pollyAvailable ? qe("", !0) : (F(), W("p", Np, "Polly is not available for this site. Browser speech will be used.")) : (F(), W("p", Dp, "Voice chat is disabled in ChangAI Settings."))]), w("div", Fp, [w("div", Bp, [w("div", null, [r[7] || (r[7] = w("p", { class: "text-sm font-semibold text-slate-900" }, "Enable Debug Tab", -1)), r[8] || (r[8] = w("p", { class: "mt-1 text-xs text-slate-600" }, " Show or hide the Debug tab inside this chatbot. ", -1)), w("p", { class: we(["mt-2 text-[11px] font-medium", e.debugEnabled ? "text-emerald-700" : "text-slate-500"]) }, Je(e.debugEnabled ? "Debug tab is active." : "Debug tab is currently off."), 3)]), w("button", { type: "button", class: we(["relative h-7 w-12 shrink-0 rounded-full border border-slate-200 transition-all duration-200", e.debugEnabled ? "bg-emerald-500/95" : "bg-slate-300"]), "aria-pressed": e.debugEnabled ? "true" : "false", title: e.debugEnabled ? "Disable debug tab" : "Enable debug tab", onClick: r[2] || (r[2] = $ => s.$emit("toggleDebug")) }, [w("span", { class: we(["absolute top-0.5 h-5.5 w-5.5 rounded-full bg-white shadow-sm transition-all duration-200", e.debugEnabled ? "left-[1.45rem]" : "left-0.5"]) }, null, 2)], 10, Hp)])]), w("div", zp, [w("div", Up, [r[9] || (r[9] = w("div", null, [w("p", { class: "text-sm font-semibold text-slate-900" }, "Send non-ERP questions directly to AI"), w("p", { class: "mt-1 text-xs text-slate-600" }, "Questions unrelated to your ERP will skip the system and go straight to AI")], -1)), w("button", { class: we(["group relative h-7 w-12 shrink-0 rounded-full border border-slate-200 transition-all duration-200", e.sendNonERPtoaiEnabled ? "bg-emerald-500/95" : "bg-slate-300"]), "aria-pressed": e.sendNonERPtoaiEnabled ? "true" : "false", title: e.sendNonERPtoaiEnabled ? "Non-ERP questions are being sent directly to AI" : "Enable direct AI reply for non-ERP questions", onClick: r[3] || (r[3] = $ => s.$emit("toggleSendNonERP")) }, [w("span", { class: we(["absolute top-0.5 h-5.5 w-5.5 rounded-full bg-white shadow-sm transition-all duration-200", e.sendNonERPtoaiEnabled ? "left-[1.45rem]" : "left-0.5"]) }, null, 2)], 10, jp)]), w("p", { class: we(["mt-3 text-[11px] font-medium", e.sendNonERPtoaiEnabled ? "text-emerald-700" : "text-slate-500"]) }, Je(e.sendNonERPtoaiEnabled ? "Non-ERP questions are now routed directly to AI" : "Direct AI routing is currently off"), 3)])]) } } }, qp = { key: 0, class: "pointer-events-none absolute -top-14 left-0 right-0 z-20 flex justify-center px-2", role: "status", "aria-live": "polite" }, Wp = { __name: "StatusToast", props: { visible: { type: Boolean, required: !0 }, message: { type: String, default: "" }, type: { type: String, default: "info" }, dismissible: { type: Boolean, default: !0 } }, emits: ["close"], setup(e) { const t = e, n = Ee(() => t.type === "error" ? "bg-red-50 text-red-700 ring-red-200" : (t.type === "listening", "bg-blue-50 text-blue-700 ring-blue-200")), s = Ee(() => t.type === "error" ? "bg-red-500" : t.type === "listening" ? "bg-blue-500 animate-pulse" : "bg-blue-500"); return (r, i) => (F(), Et(Pu, { "enter-active-class": "transition duration-200 ease-out", "enter-from-class": "translate-y-1 opacity-0", "enter-to-class": "translate-y-0 opacity-100", "leave-active-class": "transition duration-150 ease-in", "leave-from-class": "translate-y-0 opacity-100", "leave-to-class": "translate-y-1 opacity-0" }, { default: Di(() => [e.visible ? (F(), W("div", qp, [w("div", { class: we(["pointer-events-auto flex max-w-[92%] items-start gap-2 rounded-lg px-3 py-2 text-xs shadow-lg ring-1", n.value]) }, [w("span", { class: we(["mt-0.5 h-2 w-2 shrink-0 rounded-full", s.value]) }, null, 2), w("span", null, Je(e.message), 1), e.dismissible ? (F(), W("button", { key: 0, type: "button", class: "ml-1 appearance-none border-0 text-current/80 transition hover:text-current focus:outline-none", "aria-label": "Dismiss notification", onClick: i[0] || (i[0] = o => r.$emit("close")) }, " × ")) : qe("", !0)], 2)])) : qe("", !0)]), _: 1 })) } }, Gp = { class: "relative w-full" }, Kp = ["placeholder", "disabled"], Yp = ["title", "aria-label", "disabled"], Zp = { key: 0, viewBox: "0 0 24 24", width: "16", height: "16", fill: "currentColor", "aria-hidden": "true" }, Xp = { key: 1, viewBox: "0 0 24 24", width: "16", height: "16", fill: "none", stroke: "currentColor", "stroke-width": "2", "aria-hidden": "true" }, Qp = { key: 2, viewBox: "0 0 24 24", width: "16", height: "16", fill: "none", stroke: "currentColor", "stroke-width": "2", "aria-hidden": "true", class: "animate-spin" }, Jp = ["title", "aria-label", "disabled"], ed = { key: 0, viewBox: "0 0 24 24", width: "18", height: "18", fill: "none", "aria-hidden": "true", class: "text-rose-600 motion-safe:animate-stop-button-pulse" }, td = { key: 1, viewBox: "0 0 24 24", width: "16", height: "16", fill: "currentColor", "aria-hidden": "true" }, nd = { __name: "ChatForm", props: { placeholder: { type: String, default: "Message..." }, disabled: { type: Boolean, default: !1 }, isAwaitingResponse: { type: Boolean, default: !1 } }, emits: ["submit", "cancel"], setup(e, { expose: t, emit: n }) { const s = e, r = n, i = J(""), o = J(null), a = J(!1), l = J(!1), f = J(!1), u = J(!1), d = J(!1), g = J(!1), y = J(!1), E = J(""), x = J("info"), M = J("Voice input is unavailable in this browser/context."); let m = null, H = null, Y = null; const $ = J(""), z = J(!1), O = Ee(() => f.value ? "Requesting microphone permission..." : u.value ? "Starting voice input..." : d.value ? "Stopping voice input..." : l.value ? a.value ? "Stop voice input" : "Start voice input" : "Voice input is unavailable in this browser/context"), P = Ee(() => s.isAwaitingResponse ? "Stop response" : "Send"), ee = Ee(() => s.isAwaitingResponse ? !1 : s.disabled || !i.value.trim()), V = Ee(() => s.isAwaitingResponse ? "bg-white border border-rose-100 shadow-[0_8px_20px_-12px_rgba(159,18,57,0.35)] hover:bg-rose-50" : "bg-linear-to-br from-brand-500 to-brand-600 text-white shadow-[0_10px_24px_-16px_rgba(109,79,194,0.85)] hover:from-brand-600 hover:to-violet-700"); function se() { return typeof window == "undefined" ? null : window.SpeechRecognition || window.webkitSpeechRecognition || null } function fe() { var ae; const re = se(), B = typeof window != "undefined" ? window.isSecureContext : !1, de = typeof navigator != "undefined" && !!((ae = navigator.mediaDevices) != null && ae.getUserMedia); l.value = !!(re && B && de), B ? (!de || !re) && (M.value = "Voice input is not supported in this browser.") : M.value = "Voice input requires HTTPS (or localhost).", re && l.value && (m = new re, m.continuous = !0, m.interimResults = !0, m.lang = typeof navigator != "undefined" && navigator.language || "en-US", m.onstart = () => { a.value = !0, u.value = !1, d.value = !1, D(), C("Listening... Tap mic to stop", "listening", { persistent: !0, key: "listening" }) }, m.onend = () => { a.value = !1, u.value = !1, d.value = !1, D(), $.value === "listening" && pe(), z.value && (z.value = !1, Ge()) }, m.onerror = ve => { if (a.value = !1, u.value = !1, d.value = !1, D(), z.value = !1, (ve == null ? void 0 : ve.error) === "not-allowed" || (ve == null ? void 0 : ve.error) === "service-not-allowed") { C("Microphone permission denied. Please allow microphone access in browser settings.", "error"); return } if ((ve == null ? void 0 : ve.error) === "audio-capture") { C("No microphone detected. Please connect a microphone and try again.", "error"); return } if ((ve == null ? void 0 : ve.error) === "no-speech") { C("No speech detected. Try speaking a bit louder.", "info"); return } C("Voice input failed. Please try again.", "error") }, m.onresult = ve => { let ge = ""; for (let nt = ve.resultIndex; nt < ve.results.length; nt += 1)ge += ve.results[nt][0].transcript; i.value = ge.trimStart() }) } function D() { Y && (clearTimeout(Y), Y = null) } function Z(re = {}) { const { submitAfterStop: B = !1 } = re; if (m) { z.value = B, u.value = !1, d.value = !0, D(); try { m.stop() } catch { d.value = !1, B && (z.value = !1, Ge()); return } Y = setTimeout(() => { if (m && !(!a.value && !d.value)) try { m.abort() } catch { d.value = !1, z.value = !1 } }, 1200) } } function Se() { if (!l.value || !m) { C(M.value, "error"); return } if (a.value || u.value || d.value) { Z({ submitAfterStop: a.value }); return } te() } async function Ue() { var re; if (g.value) return !0; if (!((re = navigator.mediaDevices) != null && re.getUserMedia)) return C("Microphone API is unavailable in this browser.", "error"), !1; f.value = !0, C("Requesting microphone permission...", "info", { persistent: !0, key: "requesting" }); try { return (await navigator.mediaDevices.getUserMedia({ audio: !0 })).getTracks().forEach(de => de.stop()), g.value = !0, !0 } catch (B) { return (B == null ? void 0 : B.name) === "NotAllowedError" || (B == null ? void 0 : B.name) === "SecurityError" ? C("Microphone permission denied. Please allow it and try again.", "error") : (B == null ? void 0 : B.name) === "NotFoundError" ? C("No microphone found on this device.", "error") : C("Unable to access microphone. Please check browser permissions.", "error"), !1 } finally { f.value = !1, $.value === "requesting" && pe() } } async function te() { var B; if (!(!m || a.value || u.value || d.value || !await Ue() || !m)) { z.value = !1, (B = o.value) == null || B.focus(), u.value = !0; try { m.start() } catch (de) { u.value = !1, d.value = !1, (de == null ? void 0 : de.name) !== "InvalidStateError" && C("Unable to start voice input. Please try again.", "error") } } } function C(re, B = "info", de = {}) { const { duration: ae = 4200, persistent: ve = !1, key: ge = "" } = de; E.value = re, x.value = B, $.value = ge, y.value = !0, H && clearTimeout(H), ve || (H = setTimeout(() => { y.value = !1, $.value = "" }, ae)) } function pe() { y.value = !1, $.value = "", H && (clearTimeout(H), H = null) } function Ge() { if (s.isAwaitingResponse) { r("cancel"); return } const re = i.value.trim(); re && ((a.value || u.value || d.value) && m && Z({ submitAfterStop: !1 }), r("submit", re), i.value = "") } return t({ focus: () => { var re; return (re = o.value) == null ? void 0 : re.focus() } }), zn(() => { fe() }), ys(() => { if (m && (a.value || u.value || d.value)) { z.value = !1, D(); try { m.abort() } catch { } } D(), pe() }), (re, B) => (F(), W("div", Gp, [w("form", { class: "group flex min-h-11 items-center gap-2 rounded-full border border-slate-200/90 bg-white/95 px-3 shadow-[0_12px_26px_-20px_rgba(15,23,42,0.7)] transition-all duration-250 focus-within:-translate-y-0.5 focus-within:border-brand-200 focus-within:shadow-[0_18px_30px_-20px_rgba(13,110,253,0.5)] focus-within:ring-2 focus-within:ring-brand-500/25", style: { "border-radius": "9999px" }, autocomplete: "off", onSubmit: pt(Ge, ["prevent"]), onClick: B[5] || (B[5] = pt(() => { }, ["stop"])), onMousedown: B[6] || (B[6] = pt(() => { }, ["stop"])), onKeydown: B[7] || (B[7] = pt(() => { }, ["stop"])), onKeyup: B[8] || (B[8] = pt(() => { }, ["stop"])) }, [Pa(w("input", { ref_key: "inputRef", ref: o, type: "text", "onUpdate:modelValue": B[0] || (B[0] = de => i.value = de), class: "h-11 w-full border-none bg-transparent text-sm font-medium text-slate-800 placeholder:text-slate-400 focus:outline-none disabled:cursor-not-allowed disabled:opacity-50", placeholder: e.disabled ? "Waiting for response..." : e.placeholder, disabled: e.disabled, required: "", onKeydown: B[1] || (B[1] = pt(() => { }, ["stop"])), onKeyup: B[2] || (B[2] = pt(() => { }, ["stop"])), onKeypress: B[3] || (B[3] = pt(() => { }, ["stop"])), onInput: B[4] || (B[4] = pt(() => { }, ["stop"])) }, null, 40, Kp), [[Xu, i.value]]), w("button", { type: "button", class: we(["grid h-8 w-8 shrink-0 appearance-none place-items-center rounded-full border border-transparent text-slate-600 transition-all duration-200 hover:-translate-y-0.5 hover:border-slate-200 hover:bg-slate-100 hover:text-slate-900 focus:outline-none disabled:cursor-not-allowed disabled:opacity-40", a.value ? "border-red-200 bg-red-100 text-red-600 shadow-[0_10px_20px_-18px_rgba(220,38,38,0.9)] hover:bg-red-100 hover:text-red-600" : ""]), style: { "border-radius": "9999px" }, title: O.value, "aria-label": O.value, disabled: e.disabled || !l.value || f.value || u.value || d.value, onClick: Se }, [a.value && !f.value ? (F(), W("svg", Zp, B[9] || (B[9] = [w("rect", { x: "6", y: "6", width: "12", height: "12", rx: "2" }, null, -1)]))) : f.value ? (F(), W("svg", Qp, B[11] || (B[11] = [w("circle", { cx: "12", cy: "12", r: "9", opacity: "0.3" }, null, -1), w("path", { d: "M21 12a9 9 0 0 1-9 9" }, null, -1)]))) : (F(), W("svg", Xp, B[10] || (B[10] = [w("path", { d: "M12 3a3 3 0 0 0-3 3v6a3 3 0 0 0 6 0V6a3 3 0 0 0-3-3z" }, null, -1), w("path", { d: "M19 10v2a7 7 0 0 1-14 0v-2" }, null, -1), w("path", { d: "M12 19v3" }, null, -1)])))], 10, Yp), w("button", { type: "submit", title: P.value, "aria-label": P.value, class: we(["grid h-8 w-8 shrink-0 appearance-none place-items-center rounded-full border-0 transition-all duration-200 hover:-translate-y-0.5 focus:outline-none disabled:cursor-not-allowed disabled:opacity-40", V.value]), style: { "border-radius": "9999px" }, disabled: ee.value }, [e.isAwaitingResponse ? (F(), W("svg", ed, B[12] || (B[12] = [w("circle", { cx: "12", cy: "12", r: "8", stroke: "currentColor", "stroke-width": "2.1", class: "opacity-95" }, null, -1), w("rect", { x: "9", y: "9", width: "6", height: "6", rx: "1.35", fill: "currentColor" }, null, -1)]))) : (F(), W("svg", td, B[13] || (B[13] = [w("path", { d: "M4 12l1.41 1.41L11 7.83V20h2V7.83l5.59 5.58L20 12l-8-8-8 8z" }, null, -1)])))], 10, Jp)], 32), Oe(Wp, { visible: y.value, message: E.value, type: x.value, dismissible: x.value !== "listening", onClose: pe }, null, 8, ["visible", "message", "type", "dismissible"])])) } }, sd = { class: "relative overflow-hidden bg-linear-to-br from-brand-600 via-brand-500 to-violet-400" }, rd = { class: "min-w-0" }, id = { key: 1, class: "border-t border-slate-200/80 bg-white/90 px-3 py-3 pb-[calc(12px+env(safe-area-inset-bottom))] backdrop-blur-sm sm:px-4 sm:py-4" }, od = 56, ld = { __name: "ChatbotPopup", props: { isOpen: { type: Boolean, required: !0 }, activeTab: { type: String, required: !0 }, debugEnabled: { type: Boolean, default: !1 }, sendNonERPtoaiEnabled: { type: Boolean, default: !1 }, chatHistory: { type: Array, required: !0 }, debugLogs: { type: Array, required: !0 }, currentDebug: { type: Object, default: null }, supportHistory: { type: Array, required: !0 }, autoReadEnabled: { type: Boolean, required: !0 }, ttsConfig: { type: Object, required: !0 }, activeTtsProvider: { type: String, required: !0 }, settings: { type: Object, default: null }, isAwaitingChatResponse: { type: Boolean, default: !1 }, isAwaitingSupportResponse: { type: Boolean, default: !1 } }, emits: ["close", "submit", "cancelResponse", "update:activeTab", "toggleAutoRead", "togglePollyPreference", "toggleDebug", "toggleSendNonERP"], setup(e, { expose: t, emit: n }) { const s = e, r = n, i = J(null), o = J(null), a = J(s.activeTab), l = J("default"), f = J(!1), u = Ee(() => a.value === "support" ? s.isAwaitingSupportResponse : a.value === "chat" ? s.isAwaitingChatResponse : !1); function d() { const M = i.value; if (!s.isOpen || !M) { f.value = !1; return } const m = M.scrollHeight - M.clientHeight; if (m <= 4) { f.value = !1; return } const H = m - M.scrollTop; f.value = H > od } function g() { const M = i.value; M && (M.scrollTo({ top: M.scrollHeight, behavior: "smooth" }), setTimeout(() => { d() }, 220)) } function y() { St(() => { d() }) } function E() { if (l.value === "default") { l.value = "half"; return } if (l.value === "half") { l.value = "full"; return } l.value = "default" } const x = Ee(() => { const M = "chat-shell fixed z-[9999] flex min-h-0 flex-col overflow-hidden border border-slate-200/80 shadow-[0_32px_80px_-44px_rgba(2,6,23,0.7),0_18px_40px_-24px_rgba(15,23,42,0.45)] transition-all duration-300 ease-out origin-bottom-right", m = s.isOpen ? "pointer-events-auto opacity-100 translate-x-0 translate-y-0 scale-100 motion-safe:animate-surface-in" : "pointer-events-none opacity-0 translate-x-1/5 translate-y-8 scale-95"; return l.value === "full" ? [M, m, "inset-0 h-screen w-screen max-h-screen max-w-screen rounded-none origin-center"] : l.value === "half" ? [M, m, "bottom-[74px] right-5 h-[min(86vh,860px)] w-[min(50vw,860px)] rounded-2xl", "max-[900px]:bottom-[78px] max-[900px]:right-3 max-[900px]:h-[min(86vh,760px)] max-[900px]:w-[min(70vw,760px)] max-[900px]:rounded-[14px]", "max-[600px]:inset-0 max-[600px]:h-screen max-[600px]:w-screen max-[600px]:max-h-screen max-[600px]:max-w-screen max-[600px]:rounded-none max-[600px]:pb-[env(safe-area-inset-bottom)]"] : [M, m, "bottom-[74px] right-5 h-[min(560px,72vh)] w-[min(360px,calc(100vw-40px))] rounded-2xl", "max-[900px]:bottom-[78px] max-[900px]:right-3 max-[900px]:h-[min(70vh,540px)] max-[900px]:w-[min(360px,calc(100vw-24px))] max-[900px]:rounded-[14px]", "max-[600px]:inset-0 max-[600px]:h-screen max-[600px]:w-screen max-[600px]:max-h-screen max-[600px]:max-w-screen max-[600px]:rounded-none max-[600px]:pb-[env(safe-area-inset-bottom)]"] }); return on(() => s.activeTab, M => { a.value = M, y() }), on(() => s.isOpen, M => { M && a.value !== "settings" && St(() => { var m; return (m = o.value) == null ? void 0 : m.focus() }), y() }), on(a, M => { r("update:activeTab", M), y() }), on(() => [s.chatHistory.length, s.supportHistory.length, s.debugLogs.length, s.currentDebug], () => { y() }), on(() => s.debugEnabled, M => { !M && a.value === "debug" && (a.value = "chat"), y() }), zn(() => { y() }), t({ scrollToBottom() { St(() => { g() }) } }), (M, m) => (F(), W("div", { class: we(x.value), onKeydown: m[9] || (m[9] = pt(() => { }, ["stop"])), onKeyup: m[10] || (m[10] = pt(() => { }, ["stop"])), onKeypress: m[11] || (m[11] = pt(() => { }, ["stop"])) }, [m[14] || (m[14] = w("div", { class: "pointer-events-none absolute -right-14 -top-14 h-36 w-36 rounded-full bg-brand-500/15 blur-2xl" }, null, -1)), m[15] || (m[15] = w("div", { class: "pointer-events-none absolute -bottom-14 -left-12 h-32 w-32 rounded-full bg-violet-400/15 blur-2xl" }, null, -1)), w("div", sd, [m[12] || (m[12] = w("div", { class: "pointer-events-none absolute inset-0 opacity-45", style: { background: "linear-gradient(120deg, rgba(255,255,255,0.16) 0%, rgba(255,255,255,0.02) 52%, rgba(255,255,255,0.12) 100%)" } }, null, -1)), Oe(vc, { windowMode: l.value, autoReadEnabled: e.autoReadEnabled, activeTtsProvider: e.activeTtsProvider, onClose: m[0] || (m[0] = H => M.$emit("close")), onCycleResize: E, onToggleAutoRead: m[1] || (m[1] = H => M.$emit("toggleAutoRead")) }, null, 8, ["windowMode", "autoReadEnabled", "activeTtsProvider"]), Oe(Sc, { modelValue: a.value, "onUpdate:modelValue": m[2] || (m[2] = H => a.value = H), debugEnabled: e.debugEnabled }, null, 8, ["modelValue", "debugEnabled"])]), w("div", { class: "chat-scrollbar min-h-0 flex-1 overflow-x-hidden overflow-y-scroll bg-slate-50/60 px-4 py-4 max-[900px]:px-3.5 max-[900px]:py-3.5 max-[600px]:px-3 max-[600px]:py-3", ref_key: "chatBodyRef", ref: i, onScrollPassive: d }, [w("div", rd, [a.value === "chat" ? (F(), Et(mp, { key: 0, messages: e.chatHistory, autoReadEnabled: e.autoReadEnabled, ttsConfig: e.ttsConfig }, null, 8, ["messages", "autoReadEnabled", "ttsConfig"])) : a.value === "debug" && e.debugEnabled ? (F(), Et(_p, { key: 1, logs: e.debugLogs, currentDebug: e.currentDebug }, null, 8, ["logs", "currentDebug"])) : a.value === "support" ? (F(), Et(Sp, { key: 2, messages: e.supportHistory, autoReadEnabled: e.autoReadEnabled, ttsConfig: e.ttsConfig }, null, 8, ["messages", "autoReadEnabled", "ttsConfig"])) : a.value === "settings" ? (F(), Et(Vp, { key: 3, autoReadEnabled: e.autoReadEnabled, ttsConfig: e.ttsConfig, settings: e.settings, debugEnabled: e.debugEnabled, sendNonERPtoaiEnabled: e.sendNonERPtoaiEnabled, onToggleAutoRead: m[3] || (m[3] = H => M.$emit("toggleAutoRead")), onTogglePollyPreference: m[4] || (m[4] = H => M.$emit("togglePollyPreference")), onToggleDebug: m[5] || (m[5] = H => M.$emit("toggleDebug")), onToggleSendNonERP: m[6] || (m[6] = H => M.$emit("toggleSendNonERP")) }, null, 8, ["autoReadEnabled", "ttsConfig", "settings", "debugEnabled", "sendNonERPtoaiEnabled"])) : qe("", !0)])], 544), f.value ? (F(), W("button", { key: 0, type: "button", class: we(["absolute right-4 z-20 grid h-9 w-9 place-items-center rounded-full border border-brand-200/70 bg-white/95 text-brand-600 shadow-[0_14px_26px_-16px_rgba(15,23,42,0.65)] transition-all duration-200 hover:-translate-y-0.5 hover:border-brand-300 hover:text-brand-700 focus:outline-none", a.value !== "settings" ? "bottom-[calc(90px+env(safe-area-inset-bottom))] sm:bottom-[96px]" : "bottom-4 sm:bottom-5"]), title: "Scroll to bottom", "aria-label": "Scroll to bottom", onClick: g }, m[13] || (m[13] = [w("svg", { viewBox: "0 0 24 24", width: "16", height: "16", fill: "none", stroke: "currentColor", "stroke-width": "2", "aria-hidden": "true" }, [w("path", { d: "M7 10l5 5 5-5" })], -1)]), 2)) : qe("", !0), a.value !== "settings" ? (F(), W("div", id, [Oe(nd, { ref_key: "chatFormRef", ref: o, placeholder: a.value === "support" ? "Message Support..." : "Message...", disabled: u.value, isAwaitingResponse: u.value, onSubmit: m[7] || (m[7] = H => M.$emit("submit", H)), onCancel: m[8] || (m[8] = H => M.$emit("cancelResponse")) }, null, 8, ["placeholder", "disabled", "isAwaitingResponse"])])) : qe("", !0)], 34)) } }, _l = "changai_chat_id", Tl = "changai_polly_enabled"; function ad() { let e = sessionStorage.getItem(_l); return e || (e = `session_${Date.now()}_${crypto.randomUUID()}`, sessionStorage.setItem(_l, e)), e } function ud() { const e = localStorage.getItem(Tl); return e === null ? !0 : e === "true" } function cd(e) { localStorage.setItem(Tl, String(!!e)) } const fd = { __name: "App", setup(e) { const t = J(!1), n = J("chat"), s = J([]), r = J([]), i = J(!1), o = J([]), a = J(null), l = J("actual"), f = J(!0), u = J(null), d = J(!1), g = J(null), y = J(!1), E = J({ enableVoiceChat: !1, pollyAvailable: !1, usePolly: !0, voiceId: "Zayd", enable_changai: !1 }), x = J("off"), M = J(null), m = J(null), H = Ee(() => M.value !== null), Y = Ee(() => m.value !== null); function $() { if (!E.value.enableVoiceChat) { x.value = "off"; return } x.value = E.value.usePolly ? "polly" : "browser" } function z(te) { var pe; const C = (pe = te == null ? void 0 : te.detail) == null ? void 0 : pe.provider; (C === "polly" || C === "browser" || C === "off") && (x.value = C) } async function O() { var pe, Ge, re, B, de; if (!(d.value || u.value)) { d.value = !0; try { u.value = await Mc(l.value), E.value = { enableVoiceChat: !!((pe = u.value) != null && pe.enable_voice_chat), pollyAvailable: !!((Ge = u.value) != null && Ge.polly_enabled), usePolly: !!((re = u.value) != null && re.polly_enabled) && ud(), voiceId: ((B = u.value) == null ? void 0 : B.polly_voice_id) || "Zayd", enable_changai: !!((de = u.value) != null && de.enable_changai) }, $(), r.value.push({ type: "settings", settings: u.value }) } catch (ae) { const ve = vl(ae); r.value.push({ type: "settings", error: ve }) } finally { d.value = !1 } } } function P() { t.value = !t.value } function ee() { var te; (te = a.value) == null || te.scrollToBottom() } function V() { f.value = !f.value } function se() { const te = !E.value.usePolly; E.value = { ...E.value, usePolly: te && E.value.pollyAvailable }, cd(E.value.usePolly), $() } function fe() { y.value = !y.value } async function D(te) { n.value === "support" ? await Ue(te) : await Z(te) } async function Z(te) { var ye, ht; g.value = null, l.value === "actual" && await O(), s.value.push({ role: "user", text: te }), await St(), ee(); const C = cs({ role: "model", text: "Thinking...", cancelable: !0, isStatus: !0, statusType: "thinking" }); s.value.push(C), await St(), ee(); let pe = !1; const Ge = ad(), re = `${Ge}_${Date.now()}`, B = y.value, de = Pc(te, Ge, l.value, re, y.value), ae = `debug_${re}`; let ve = Date.now(); const ge = [], nt = G => { var h; const Ce = Date.now(), Ft = ((Ce - ve) / 1e3).toFixed(2); ve = Ce; const c = `${G.message} (${Ft}s)`; if (G.message && (ge.push(c), g.value = c), !G.done && G.message && (C.text = G.message, C.statusType = "pipeline"), G.done) { C.cancelable = !1, G.error ? (C.text = `⚠️ ${G.message || "Something failed"}`, C.isStatus = !1, C.statusType = null) : (h = G.data) != null && h.answer && (C.text = G.data.answer, C.isStatus = !1, C.statusType = null), frappe.realtime.off(ae), g.value = null; return } }; frappe.realtime.on(ae, nt), M.value = () => { pe || (pe = !0, de.cancel(), frappe.realtime.off(ae), C.isStatus = !1, C.statusType = null, C.text = "Cancelled by user.", r.value.push({ type: "cancelled", user: te, steps: [...ge] }), g.value = null, C.cancelable = !1, M.value = null) }; try { const G = await de.promise; if (G != null && G.open_report) { if (C.isStatus = !1, C.statusType = null, C.text = `Opening "${G.report_name}" report." `, r.value.push({ type: "success", steps: [...ge], final_response: G, entity_raw: G.entity_raw }), g.value = null, !G.report_name) { C.text = "Report name extraction failed.Can you ask the same question again?"; return } frappe.set_route("query-report", G.report_name, G.filters || {}); return } else if (G != null && G.create_entity) { C.isStatus = !1, C.statusType = null, C.cancelable = !1, C.text = `Opening "${G.doc}" doctype for creating Entity "${G.entity_name}" record.`, r.value.push({ type: "success", user: te, steps: [...ge], final_response: G }), g.value = null; const Ft = G.doc, c = G.entity_name || "", b = { Customer: { customer_name: c }, Supplier: { supplier_name: c }, Employee: { employee_name: c }, Item: { item_code: c, item_name: c }, Project: { project_name: c }, Lead: { lead_name: c }, Opportunity: { opportunity_name: c } }[Ft] || {}; frappe.route_options = b, frappe.set_route("Form", Ft, "new"); const k = setInterval(() => { cur_frm && cur_frm.doctype === Ft && cur_frm.is_new() && (clearInterval(k), Object.entries(b).forEach(([v, _]) => { _ && cur_frm.fields_dict[v] && (cur_frm.set_value(v, _), cur_frm.refresh_field(v)) })) }, 200); return } if (pe) return; C.cancelable = !1; const Ce = ((ye = bp(G == null ? void 0 : G.Bot)) == null ? void 0 : ye.trim()) || "No response."; C.isStatus = !1, C.statusType = null, C.text = Ce, r.value.push({ type: "success", user: te, steps: [...ge], final_response: G }), g.value = null } catch (G) { if (pe) return; frappe.realtime.off(ae), C.cancelable = !1, C.isStatus = !1, C.statusType = null; const Ce = vl(G); g.value = null, r.value.push({ type: "failed", user: te, steps: [...ge], error: Ce }), (G == null ? void 0 : G.code) === "ERR_NETWORK_CHANGED" || (ht = G == null ? void 0 : G.message) != null && ht.includes("ERR_NETWORK_CHANGED") ? (C.isStatus = !1, C.statusType = null, C.text = "⚠️ Network error. Please check your connection and try again.") : (C.isStatus = !1, C.statusType = null, C.text = "⚠️ Something went wrong. Please try again.") } finally { frappe.realtime.off(ae), pe || (M.value = null) } await St(), ee() } function Se() { var te, C; if (n.value === "support") { (te = m.value) == null || te.call(m); return } (C = M.value) == null || C.call(M) } async function Ue(te) { o.value.push({ role: "user", text: te }), await St(), ee(); const C = cs({ role: "model", text: "Sending to support...", isStatus: !0, statusType: "support" }); o.value.push(C), await St(), ee(); let pe = !1; const Ge = Ic(te, l.value); m.value = () => { pe || (pe = !0, Ge.cancel(), C.isStatus = !1, C.statusType = null, C.text = "Cancelled by user.", m.value = null) }; try { const re = await Ge.promise; if (pe) return; C.isStatus = !1, C.statusType = null, C.text = re ? wl(re) : "Support request sent successfully." } catch { if (pe) return; C.isStatus = !1, C.statusType = null, C.text = "⚠️ Failed to reach support. Please try again." } finally { pe || (m.value = null) } await St(), ee() } return zn(() => { typeof window != "undefined" && window.addEventListener("changai-tts-provider", z), l.value === "actual" && O() }), ys(() => { typeof window != "undefined" && window.removeEventListener("changai-tts-provider", z) }), (te, C) => (F(), W(He, null, [E.value.enable_changai ? (F(), Et(ac, { key: 0, isOpen: t.value, onToggle: P }, null, 8, ["isOpen"])) : qe("", !0), Oe(ld, { ref_key: "popupRef", ref: a, isOpen: t.value, activeTab: n.value, "onUpdate:activeTab": C[0] || (C[0] = pe => n.value = pe), chatHistory: s.value, debugLogs: r.value, currentDebug: g.value, supportHistory: o.value, autoReadEnabled: f.value, ttsConfig: E.value, activeTtsProvider: x.value, settings: u.value, isAwaitingChatResponse: H.value, isAwaitingSupportResponse: Y.value, debugEnabled: i.value, sendNonERPtoaiEnabled: y.value, onToggleDebug: C[1] || (C[1] = pe => i.value = !i.value), onClose: C[2] || (C[2] = pe => t.value = !1), onSubmit: D, onCancelResponse: Se, onToggleAutoRead: V, onTogglePollyPreference: se, onToggleSendNonERP: fe }, null, 8, ["isOpen", "activeTab", "chatHistory", "debugLogs", "currentDebug", "supportHistory", "autoReadEnabled", "ttsConfig", "activeTtsProvider", "settings", "isAwaitingChatResponse", "isAwaitingSupportResponse", "debugEnabled", "sendNonERPtoaiEnabled"])], 64)) } }; function pd() { const e = document.querySelector('link[href*="/assets/changai/dist/changai-chatbot.css"]'); if (e != null && e.href) return e.href; const t = Array.from(document.scripts).find(n => { var s; return (s = n.src) == null ? void 0 : s.includes("/assets/changai/dist/changai-chatbot.js") }); return t != null && t.src ? t.src.replace(/changai-chatbot\.js(\?.*)?$/, "changai-chatbot.css$1") : null } function dd(e) { const t = pd(); if (!t) { const n = Array.from(document.querySelectorAll("style[data-vite-dev-id]")); return n.length && n.forEach(s => { const r = document.createElement("style"); r.dataset.changaiShadowDevStyle = "1", r.textContent = s.textContent || "", e.appendChild(r) }), Promise.resolve() } return e.querySelector('link[data-changai-shadow-style="1"]') ? Promise.resolve() : new Promise(n => { const s = document.createElement("link"); s.rel = "stylesheet", s.href = t, s.dataset.changaiShadowStyle = "1", s.onload = () => n(), s.onerror = () => n(), e.appendChild(s), setTimeout(n, 1200) }) } async function kl() { if (document.getElementById("changai-chatbot-host")) return; const e = document.createElement("div"); e.id = "changai-chatbot-host", document.body.appendChild(e); const t = e.attachShadow({ mode: "open" }); await dd(t); const n = document.createElement("div"); n.id = "changai-chatbot-root", t.appendChild(n), nc(fd).mount(n); function s(r) { r.stopPropagation() } n.addEventListener("keydown", s), n.addEventListener("keyup", s), n.addEventListener("keypress", s) } document.readyState === "loading" ? document.addEventListener("DOMContentLoaded", kl) : kl() +})(); diff --git a/frontend/src/App.vue b/frontend/src/App.vue index 03162eb..bc4be27 100644 --- a/frontend/src/App.vue +++ b/frontend/src/App.vue @@ -99,6 +99,10 @@ function togglePollyPreference() { function sendNonErpToAI() { sendNonERPtoaiEnabled.value = !sendNonERPtoaiEnabled.value + localStorage.setItem( + 'sendNonERPtoaiEnabled', + sendNonERPtoaiEnabled.value + ) } async function handleSubmit(message) { if (activeTab.value === 'support') { @@ -126,7 +130,9 @@ async function handleChatSubmit(message) { let cancelled = false const chatId = getOrCreateChatId() const requestId = `${chatId}_${Date.now()}` - const sendNonErptoAI = sendNonERPtoaiEnabled.value + const sendNonERPtoaiEnabled = ref( + localStorage.getItem('sendNonERPtoaiEnabled') === 'true' + ) console.log('sendNonErptoAI value being sent:', sendNonErptoAI, typeof sendNonErptoAI) const eventName = `debug_${requestId}` frappe.realtime.on(eventName, onPipelineUpdate) diff --git a/frontend/src/utils/frappe.js b/frontend/src/utils/frappe.js index 8c39f10..cd1ff6a 100644 --- a/frontend/src/utils/frappe.js +++ b/frontend/src/utils/frappe.js @@ -2,9 +2,9 @@ const IS_DEV = import.meta.env.DEV export const API = { PIPELINE: 'changai.changai.api.v2.text2sql_pipeline_v2.run_text2sql_pipeline', - SUPPORT: 'changai.changai.api.v2.text2sql_pipeline_v2.support_bot', - SETTINGS: 'changai.changai.api.v2.text2sql_pipeline_v2.get_frontend_settings', - TTS: 'changai.changai.api.v2.text2sql_pipeline_v2.synthesize_tts', + SUPPORT: 'changai.changai.api.v2.helpdesk_api.support_bot', + SETTINGS: 'changai.changai.api.v2.schema_utils.get_frontend_settings', + TTS: 'changai.changai.api.v2.tts.synthesize_tts', } export function frappeCall(method, args = {}, mode = 'actual') {