deep-chat
Version:
Customizable chat component for AI APIs
901 lines • 718 kB
JavaScript
function _createForOfIteratorHelper(r, e) { var t = "undefined" != typeof Symbol && r[Symbol.iterator] || r["@@iterator"]; if (!t) { if (Array.isArray(r) || (t = _unsupportedIterableToArray(r)) || e && r && "number" == typeof r.length) { t && (r = t); var _n2 = 0, F = function F() {}; return { s: F, n: function n() { return _n2 >= r.length ? { done: !0 } : { done: !1, value: r[_n2++] }; }, e: function e(r) { throw r; }, f: F }; } throw new TypeError("Invalid attempt to iterate non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method."); } var o, a = !0, u = !1; return { s: function s() { t = t.call(r); }, n: function n() { var r = t.next(); return a = r.done, r; }, e: function e(r) { u = !0, o = r; }, f: function f() { try { a || null == t["return"] || t["return"](); } finally { if (u) throw o; } } }; }
function _wrapNativeSuper(t) { var r = "function" == typeof Map ? new Map() : void 0; return _wrapNativeSuper = function _wrapNativeSuper(t) { if (null === t || !_isNativeFunction(t)) return t; if ("function" != typeof t) throw new TypeError("Super expression must either be null or a function"); if (void 0 !== r) { if (r.has(t)) return r.get(t); r.set(t, Wrapper); } function Wrapper() { return _construct(t, arguments, _getPrototypeOf(this).constructor); } return Wrapper.prototype = Object.create(t.prototype, { constructor: { value: Wrapper, enumerable: !1, writable: !0, configurable: !0 } }), _setPrototypeOf(Wrapper, t); }, _wrapNativeSuper(t); }
function _construct(t, e, r) { if (_isNativeReflectConstruct()) return Reflect.construct.apply(null, arguments); var o = [null]; o.push.apply(o, e); var p = new (t.bind.apply(t, o))(); return r && _setPrototypeOf(p, r.prototype), p; }
function _isNativeFunction(t) { try { return -1 !== Function.toString.call(t).indexOf("[native code]"); } catch (n) { return "function" == typeof t; } }
function _slicedToArray(r, e) { return _arrayWithHoles(r) || _iterableToArrayLimit(r, e) || _unsupportedIterableToArray(r, e) || _nonIterableRest(); }
function _nonIterableRest() { throw new TypeError("Invalid attempt to destructure non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method."); }
function _iterableToArrayLimit(r, l) { var t = null == r ? null : "undefined" != typeof Symbol && r[Symbol.iterator] || r["@@iterator"]; if (null != t) { var e, n, i, u, a = [], f = !0, o = !1; try { if (i = (t = t.call(r)).next, 0 === l) { if (Object(t) !== t) return; f = !1; } else for (; !(f = (e = i.call(t)).done) && (a.push(e.value), a.length !== l); f = !0); } catch (r) { o = !0, n = r; } finally { try { if (!f && null != t["return"] && (u = t["return"](), Object(u) !== u)) return; } finally { if (o) throw n; } } return a; } }
function _arrayWithHoles(r) { if (Array.isArray(r)) return r; }
function _toConsumableArray(r) { return _arrayWithoutHoles(r) || _iterableToArray(r) || _unsupportedIterableToArray(r) || _nonIterableSpread(); }
function _nonIterableSpread() { throw new TypeError("Invalid attempt to spread non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method."); }
function _unsupportedIterableToArray(r, a) { if (r) { if ("string" == typeof r) return _arrayLikeToArray(r, a); var t = {}.toString.call(r).slice(8, -1); return "Object" === t && r.constructor && (t = r.constructor.name), "Map" === t || "Set" === t ? Array.from(r) : "Arguments" === t || /^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(t) ? _arrayLikeToArray(r, a) : void 0; } }
function _iterableToArray(r) { if ("undefined" != typeof Symbol && null != r[Symbol.iterator] || null != r["@@iterator"]) return Array.from(r); }
function _arrayWithoutHoles(r) { if (Array.isArray(r)) return _arrayLikeToArray(r); }
function _arrayLikeToArray(r, a) { (null == a || a > r.length) && (a = r.length); for (var e = 0, n = Array(a); e < a; e++) n[e] = r[e]; return n; }
function _callSuper(t, o, e) { return o = _getPrototypeOf(o), _possibleConstructorReturn(t, _isNativeReflectConstruct() ? Reflect.construct(o, e || [], _getPrototypeOf(t).constructor) : o.apply(t, e)); }
function _possibleConstructorReturn(t, e) { if (e && ("object" == _typeof(e) || "function" == typeof e)) return e; if (void 0 !== e) throw new TypeError("Derived constructors may only return object or undefined"); return _assertThisInitialized(t); }
function _assertThisInitialized(e) { if (void 0 === e) throw new ReferenceError("this hasn't been initialised - super() hasn't been called"); return e; }
function _isNativeReflectConstruct() { try { var t = !Boolean.prototype.valueOf.call(Reflect.construct(Boolean, [], function () {})); } catch (t) {} return (_isNativeReflectConstruct = function _isNativeReflectConstruct() { return !!t; })(); }
function _getPrototypeOf(t) { return _getPrototypeOf = Object.setPrototypeOf ? Object.getPrototypeOf.bind() : function (t) { return t.__proto__ || Object.getPrototypeOf(t); }, _getPrototypeOf(t); }
function _inherits(t, e) { if ("function" != typeof e && null !== e) throw new TypeError("Super expression must either be null or a function"); t.prototype = Object.create(e && e.prototype, { constructor: { value: t, writable: !0, configurable: !0 } }), Object.defineProperty(t, "prototype", { writable: !1 }), e && _setPrototypeOf(t, e); }
function _setPrototypeOf(t, e) { return _setPrototypeOf = Object.setPrototypeOf ? Object.setPrototypeOf.bind() : function (t, e) { return t.__proto__ = e, t; }, _setPrototypeOf(t, e); }
function _regeneratorRuntime() { "use strict"; /*! regenerator-runtime -- Copyright (c) 2014-present, Facebook, Inc. -- license (MIT): https://github.com/babel/babel/blob/main/packages/babel-helpers/LICENSE */ _regeneratorRuntime = function _regeneratorRuntime() { return r; }; var t, r = {}, e = Object.prototype, n = e.hasOwnProperty, o = "function" == typeof Symbol ? Symbol : {}, i = o.iterator || "@@iterator", a = o.asyncIterator || "@@asyncIterator", u = o.toStringTag || "@@toStringTag"; function c(t, r, e, n) { return Object.defineProperty(t, r, { value: e, enumerable: !n, configurable: !n, writable: !n }); } try { c({}, ""); } catch (t) { c = function c(t, r, e) { return t[r] = e; }; } function h(r, e, n, o) { var i = e && e.prototype instanceof Generator ? e : Generator, a = Object.create(i.prototype); return c(a, "_invoke", function (r, e, n) { var o = 1; return function (i, a) { if (3 === o) throw Error("Generator is already running"); if (4 === o) { if ("throw" === i) throw a; return { value: t, done: !0 }; } for (n.method = i, n.arg = a;;) { var u = n.delegate; if (u) { var c = d(u, n); if (c) { if (c === f) continue; return c; } } if ("next" === n.method) n.sent = n._sent = n.arg;else if ("throw" === n.method) { if (1 === o) throw o = 4, n.arg; n.dispatchException(n.arg); } else "return" === n.method && n.abrupt("return", n.arg); o = 3; var h = s(r, e, n); if ("normal" === h.type) { if (o = n.done ? 4 : 2, h.arg === f) continue; return { value: h.arg, done: n.done }; } "throw" === h.type && (o = 4, n.method = "throw", n.arg = h.arg); } }; }(r, n, new Context(o || [])), !0), a; } function s(t, r, e) { try { return { type: "normal", arg: t.call(r, e) }; } catch (t) { return { type: "throw", arg: t }; } } r.wrap = h; var f = {}; function Generator() {} function GeneratorFunction() {} function GeneratorFunctionPrototype() {} var l = {}; c(l, i, function () { return this; }); var p = Object.getPrototypeOf, y = p && p(p(x([]))); y && y !== e && n.call(y, i) && (l = y); var v = GeneratorFunctionPrototype.prototype = Generator.prototype = Object.create(l); function g(t) { ["next", "throw", "return"].forEach(function (r) { c(t, r, function (t) { return this._invoke(r, t); }); }); } function AsyncIterator(t, r) { function e(o, i, a, u) { var c = s(t[o], t, i); if ("throw" !== c.type) { var h = c.arg, f = h.value; return f && "object" == _typeof(f) && n.call(f, "__await") ? r.resolve(f.__await).then(function (t) { e("next", t, a, u); }, function (t) { e("throw", t, a, u); }) : r.resolve(f).then(function (t) { h.value = t, a(h); }, function (t) { return e("throw", t, a, u); }); } u(c.arg); } var o; c(this, "_invoke", function (t, n) { function i() { return new r(function (r, o) { e(t, n, r, o); }); } return o = o ? o.then(i, i) : i(); }, !0); } function d(r, e) { var n = e.method, o = r.i[n]; if (o === t) return e.delegate = null, "throw" === n && r.i["return"] && (e.method = "return", e.arg = t, d(r, e), "throw" === e.method) || "return" !== n && (e.method = "throw", e.arg = new TypeError("The iterator does not provide a '" + n + "' method")), f; var i = s(o, r.i, e.arg); if ("throw" === i.type) return e.method = "throw", e.arg = i.arg, e.delegate = null, f; var a = i.arg; return a ? a.done ? (e[r.r] = a.value, e.next = r.n, "return" !== e.method && (e.method = "next", e.arg = t), e.delegate = null, f) : a : (e.method = "throw", e.arg = new TypeError("iterator result is not an object"), e.delegate = null, f); } function w(t) { this.tryEntries.push(t); } function m(r) { var e = r[4] || {}; e.type = "normal", e.arg = t, r[4] = e; } function Context(t) { this.tryEntries = [[-1]], t.forEach(w, this), this.reset(!0); } function x(r) { if (null != r) { var e = r[i]; if (e) return e.call(r); if ("function" == typeof r.next) return r; if (!isNaN(r.length)) { var o = -1, a = function e() { for (; ++o < r.length;) if (n.call(r, o)) return e.value = r[o], e.done = !1, e; return e.value = t, e.done = !0, e; }; return a.next = a; } } throw new TypeError(_typeof(r) + " is not iterable"); } return GeneratorFunction.prototype = GeneratorFunctionPrototype, c(v, "constructor", GeneratorFunctionPrototype), c(GeneratorFunctionPrototype, "constructor", GeneratorFunction), GeneratorFunction.displayName = c(GeneratorFunctionPrototype, u, "GeneratorFunction"), r.isGeneratorFunction = function (t) { var r = "function" == typeof t && t.constructor; return !!r && (r === GeneratorFunction || "GeneratorFunction" === (r.displayName || r.name)); }, r.mark = function (t) { return Object.setPrototypeOf ? Object.setPrototypeOf(t, GeneratorFunctionPrototype) : (t.__proto__ = GeneratorFunctionPrototype, c(t, u, "GeneratorFunction")), t.prototype = Object.create(v), t; }, r.awrap = function (t) { return { __await: t }; }, g(AsyncIterator.prototype), c(AsyncIterator.prototype, a, function () { return this; }), r.AsyncIterator = AsyncIterator, r.async = function (t, e, n, o, i) { void 0 === i && (i = Promise); var a = new AsyncIterator(h(t, e, n, o), i); return r.isGeneratorFunction(e) ? a : a.next().then(function (t) { return t.done ? t.value : a.next(); }); }, g(v), c(v, u, "Generator"), c(v, i, function () { return this; }), c(v, "toString", function () { return "[object Generator]"; }), r.keys = function (t) { var r = Object(t), e = []; for (var n in r) e.unshift(n); return function t() { for (; e.length;) if ((n = e.pop()) in r) return t.value = n, t.done = !1, t; return t.done = !0, t; }; }, r.values = x, Context.prototype = { constructor: Context, reset: function reset(r) { if (this.prev = this.next = 0, this.sent = this._sent = t, this.done = !1, this.delegate = null, this.method = "next", this.arg = t, this.tryEntries.forEach(m), !r) for (var e in this) "t" === e.charAt(0) && n.call(this, e) && !isNaN(+e.slice(1)) && (this[e] = t); }, stop: function stop() { this.done = !0; var t = this.tryEntries[0][4]; if ("throw" === t.type) throw t.arg; return this.rval; }, dispatchException: function dispatchException(r) { if (this.done) throw r; var e = this; function n(t) { a.type = "throw", a.arg = r, e.next = t; } for (var o = e.tryEntries.length - 1; o >= 0; --o) { var i = this.tryEntries[o], a = i[4], u = this.prev, c = i[1], h = i[2]; if (-1 === i[0]) return n("end"), !1; if (!c && !h) throw Error("try statement without catch or finally"); if (null != i[0] && i[0] <= u) { if (u < c) return this.method = "next", this.arg = t, n(c), !0; if (u < h) return n(h), !1; } } }, abrupt: function abrupt(t, r) { for (var e = this.tryEntries.length - 1; e >= 0; --e) { var n = this.tryEntries[e]; if (n[0] > -1 && n[0] <= this.prev && this.prev < n[2]) { var o = n; break; } } o && ("break" === t || "continue" === t) && o[0] <= r && r <= o[2] && (o = null); var i = o ? o[4] : {}; return i.type = t, i.arg = r, o ? (this.method = "next", this.next = o[2], f) : this.complete(i); }, complete: function complete(t, r) { if ("throw" === t.type) throw t.arg; return "break" === t.type || "continue" === t.type ? this.next = t.arg : "return" === t.type ? (this.rval = this.arg = t.arg, this.method = "return", this.next = "end") : "normal" === t.type && r && (this.next = r), f; }, finish: function finish(t) { for (var r = this.tryEntries.length - 1; r >= 0; --r) { var e = this.tryEntries[r]; if (e[2] === t) return this.complete(e[4], e[3]), m(e), f; } }, "catch": function _catch(t) { for (var r = this.tryEntries.length - 1; r >= 0; --r) { var e = this.tryEntries[r]; if (e[0] === t) { var n = e[4]; if ("throw" === n.type) { var o = n.arg; m(e); } return o; } } throw Error("illegal catch attempt"); }, delegateYield: function delegateYield(r, e, n) { return this.delegate = { i: x(r), r: e, n: n }, "next" === this.method && (this.arg = t), f; } }, r; }
function asyncGeneratorStep(n, t, e, r, o, a, c) { try { var i = n[a](c), u = i.value; } catch (n) { return void e(n); } i.done ? t(u) : Promise.resolve(u).then(r, o); }
function _asyncToGenerator(n) { return function () { var t = this, e = arguments; return new Promise(function (r, o) { var a = n.apply(t, e); function _next(n) { asyncGeneratorStep(a, r, o, _next, _throw, "next", n); } function _throw(n) { asyncGeneratorStep(a, r, o, _next, _throw, "throw", n); } _next(void 0); }); }; }
function ownKeys(e, r) { var t = Object.keys(e); if (Object.getOwnPropertySymbols) { var o = Object.getOwnPropertySymbols(e); r && (o = o.filter(function (r) { return Object.getOwnPropertyDescriptor(e, r).enumerable; })), t.push.apply(t, o); } return t; }
function _objectSpread(e) { for (var r = 1; r < arguments.length; r++) { var t = null != arguments[r] ? arguments[r] : {}; r % 2 ? ownKeys(Object(t), !0).forEach(function (r) { _defineProperty(e, r, t[r]); }) : Object.getOwnPropertyDescriptors ? Object.defineProperties(e, Object.getOwnPropertyDescriptors(t)) : ownKeys(Object(t)).forEach(function (r) { Object.defineProperty(e, r, Object.getOwnPropertyDescriptor(t, r)); }); } return e; }
function _defineProperty(e, r, t) { return (r = _toPropertyKey(r)) in e ? Object.defineProperty(e, r, { value: t, enumerable: !0, configurable: !0, writable: !0 }) : e[r] = t, e; }
function _typeof(o) { "@babel/helpers - typeof"; return _typeof = "function" == typeof Symbol && "symbol" == typeof Symbol.iterator ? function (o) { return typeof o; } : function (o) { return o && "function" == typeof Symbol && o.constructor === Symbol && o !== Symbol.prototype ? "symbol" : typeof o; }, _typeof(o); }
function _classCallCheck(a, n) { if (!(a instanceof n)) throw new TypeError("Cannot call a class as a function"); }
function _defineProperties(e, r) { for (var t = 0; t < r.length; t++) { var o = r[t]; o.enumerable = o.enumerable || !1, o.configurable = !0, "value" in o && (o.writable = !0), Object.defineProperty(e, _toPropertyKey(o.key), o); } }
function _createClass(e, r, t) { return r && _defineProperties(e.prototype, r), t && _defineProperties(e, t), Object.defineProperty(e, "prototype", { writable: !1 }), e; }
function _toPropertyKey(t) { var i = _toPrimitive(t, "string"); return "symbol" == _typeof(i) ? i : i + ""; }
function _toPrimitive(t, r) { if ("object" != _typeof(t) || !t) return t; var e = t[Symbol.toPrimitive]; if (void 0 !== e) { var i = e.call(t, r || "default"); if ("object" != _typeof(i)) return i; throw new TypeError("@@toPrimitive must return a primitive value."); } return ("string" === r ? String : Number)(t); }
var Vn = /*#__PURE__*/function () {
function Vn() {
_classCallCheck(this, Vn);
}
return _createClass(Vn, null, [{
key: "render",
value: function render(e, t) {
var i = document.createElement("div");
i.id = "error-view", i.innerText = t, e.replaceChildren(i);
}
}]);
}();
var yi = /*#__PURE__*/function () {
function yi() {
_classCallCheck(this, yi);
}
return _createClass(yi, null, [{
key: "onLoad",
value: function onLoad(e) {
e.innerHTML = '<div id="loading-validate-key-property"></div>';
}
}, {
key: "createElements",
value: function createElements() {
var e = document.createElement("div");
return e.id = "validate-property-key-view", e;
}
}, {
key: "render",
value: function render(e, t, i) {
var s = yi.createElements(),
r = {
onSuccess: t,
onFail: Vn.render.bind(this, e, "Your 'key' has failed authentication"),
onLoad: yi.onLoad.bind(this, s)
};
i.key && i.verifyKey(i.key, r), e.replaceChildren(s);
}
}]);
}();
var L = /*#__PURE__*/function () {
function L() {
_classCallCheck(this, L);
}
return _createClass(L, null, [{
key: "unsetStyle",
value: function unsetStyle(e, t) {
var i = Object.keys(t).reduce(function (s, r) {
return s[r] = "", s;
}, {});
Object.assign(e.style, i);
}
}, {
key: "unsetActivityCSSMouseStates",
value: function unsetActivityCSSMouseStates(e, t) {
t.click && L.unsetStyle(e, t.click), t.hover && L.unsetStyle(e, t.hover);
}
}, {
key: "unsetAllCSSMouseStates",
value: function unsetAllCSSMouseStates(e, t) {
L.unsetActivityCSSMouseStates(e, t), t["default"] && L.unsetStyle(e, t["default"]);
}
// if you want to asdd default styling - use pure css classes
}, {
key: "processStateful",
value: function processStateful(e) {
var t = e["default"] || {},
i = Object.assign(JSON.parse(JSON.stringify(t)), e == null ? void 0 : e.hover),
s = Object.assign(JSON.parse(JSON.stringify(i)), e == null ? void 0 : e.click);
return {
"default": t,
hover: i,
click: s
};
}
}, {
key: "mergeStatefulStyles",
value: function mergeStatefulStyles(e) {
var t = {
"default": {},
hover: {},
click: {}
};
return e.forEach(function (i) {
t["default"] = Object.assign(t["default"], i["default"]), t.hover = Object.assign(t.hover, i.hover), t.click = Object.assign(t.click, i.click);
}), t;
}
}, {
key: "overwriteDefaultWithAlreadyApplied",
value: function overwriteDefaultWithAlreadyApplied(e, t) {
Object.keys(e["default"] || []).forEach(function (i) {
var r;
var s = i;
t.style[s] && (r = e["default"]) != null && r[s] && (e["default"][i] = t.style[s]);
});
}
}, {
key: "applyToStyleIfNotDefined",
value: function applyToStyleIfNotDefined(e, t) {
for (var i in t) {
var s = t[i];
e[i] === "" && s && (e[i] = s);
}
}
}]);
}();
var Xe = /*#__PURE__*/function () {
function Xe() {
_classCallCheck(this, Xe);
}
return _createClass(Xe, null, [{
key: "attemptAppendStyleSheetToHead",
value: function attemptAppendStyleSheetToHead(e) {
if (e.fontFamily && e.fontFamily !== Xe.DEFAULT_FONT_FAMILY) return;
var t = document.getElementsByTagName("head")[0];
if (!Array.from(t.getElementsByTagName("link")).some(function (s) {
return s.getAttribute("href") === Xe.FONT_URL;
})) {
var s = document.createElement("link");
s.rel = "stylesheet", s.href = Xe.FONT_URL, t.appendChild(s);
}
}
}]);
}();
Xe.FONT_URL = "https://fonts.googleapis.com/css2?family=Inter:wght@400;600&display=swap", Xe.DEFAULT_FONT_FAMILY = "'Inter', sans-serif, Avenir, Helvetica, Arial";
var Ei = Xe;
var mt = /*#__PURE__*/function () {
function mt() {
_classCallCheck(this, mt);
}
return _createClass(mt, null, [{
key: "apply",
value: function apply(e, t) {
if (t) try {
mt.applyStyleSheet(e, t);
} catch (_unused) {
mt.addStyleElement(e, t);
}
}
}, {
key: "applyStyleSheet",
value: function applyStyleSheet(e, t) {
var i = new CSSStyleSheet();
i.replaceSync(e), t.adoptedStyleSheets.push(i);
}
}, {
key: "addStyleElement",
value: function addStyleElement(e, t) {
var i = document.createElement("style");
i.innerHTML = e, t.appendChild(i);
}
}, {
key: "applyDefaultStyleToComponent",
value: function applyDefaultStyleToComponent(e, t) {
t && L.applyToStyleIfNotDefined(e, t), L.applyToStyleIfNotDefined(e, mt.DEFAULT_COMPONENT_STYLE);
}
}]);
}();
mt.DEFAULT_COMPONENT_STYLE = {
height: "350px",
width: "320px",
borderTop: "1px solid #cacaca",
borderRight: "1px solid #cacaca",
borderLeft: "1px solid #cacaca",
borderBottom: "1px solid #cacaca",
fontFamily: Ei.DEFAULT_FONT_FAMILY,
fontSize: "0.9rem",
backgroundColor: "white",
position: "relative",
// this is used to prevent inputAreaStyle background color from going beyond the container's rounded border
// it will cause issues if there are elements that are meant to be outside of the chat component and in
// that instance they should overwrite this
// this is also causing the chat to squeeze when there is no space
overflow: "hidden"
};
var Vt = mt;
var Ye = /*#__PURE__*/function () {
function Ye() {
_classCallCheck(this, Ye);
}
return _createClass(Ye, null, [{
key: "buildElement",
value: function buildElement() {
var e = document.createElement("div");
e.classList.add("tooltip");
var t = document.createElement("span");
return t.classList.add("tooltip-text"), e.appendChild(t), e;
}
}, {
key: "tryCreateConfig",
value: function tryCreateConfig(e, t) {
if (t) return typeof t == "boolean" ? {
text: e
} : {
text: t.text || e,
timeout: t.timeout || 0,
style: t.style
};
}
}, {
key: "traverseParentUntilContainer",
value: function traverseParentUntilContainer(e) {
var t = e;
for (; t.parentElement;) t = t.parentElement;
return t;
}
}, {
key: "setPosition",
value: function setPosition(e, t) {
var s = t.getRootNode().host.getBoundingClientRect(),
r = e.getBoundingClientRect(),
a = t.getBoundingClientRect().width / 2,
l = r.left + r.width / 2;
t.style.left = "".concat(l - a - s.left, "px"), t.style.top = "".concat(r.top - 36 - s.top, "px");
var c = t.getBoundingClientRect();
c.left < s.left ? t.style.left = "".concat(Ye.OVERFLOW_NEW_POSITION_PX, "px") : c.right > s.right && (t.style.left = "".concat(s.width - c.width - Ye.OVERFLOW_NEW_POSITION_PX, "px"));
}
}, {
key: "display",
value: function display(e, t, i) {
return i || (i = Ye.traverseParentUntilContainer(e).nextSibling), t.text && (i.children[0].textContent = t.text), {
timeout: setTimeout(function () {
i.style.visibility = "visible", Ye.setPosition(e, i), t.style && Object.assign(i.style, t.style);
}, t.timeout || 0),
element: i
};
}
}, {
key: "hide",
value: function hide(e, t) {
clearTimeout(e.timeout), e.element.style.visibility = "hidden", t.style && L.unsetStyle(e.element, t.style), e.element.style.left = "", e.element.style.top = "";
}
}]);
}();
Ye.OVERFLOW_NEW_POSITION_PX = 4;
var Ee = Ye;
var Jt = /*#__PURE__*/_createClass(function Jt() {
_classCallCheck(this, Jt);
});
Jt.IS_SAFARI = /^((?!chrome|android).)*safari/i.test(navigator.userAgent), Jt.IS_CHROMIUM = window.chrome, Jt.IS_MOBILE = /iPhone|iPad|iPod|Android/i.test(navigator.userAgent);
var Ue = Jt;
var U = /* @__PURE__ */function (n) {
return n.ESCAPE = "Escape", n.ENTER = "Enter", n.TAB = "Tab", n.ARROW_UP = "ArrowUp", n.ARROW_DOWN = "ArrowDown", n.ARROW_RIGHT = "ArrowRight", n.ARROW_LEFT = "ArrowLeft", n.BACKSPACE = "Backspace", n.DELETE = "Delete", n.META = "Meta", n.CONTROL = "Control", n;
}(U || {});
var Ze = /*#__PURE__*/function () {
function Ze() {
_classCallCheck(this, Ze);
}
return _createClass(Ze, null, [{
key: "add",
value:
// prettier-ignore
function add(e, t, i, s) {
i !== void 0 && e.addEventListener("keydown", Ze.onKeyDown.bind(this, i)), e.oninput = Ze.onInput.bind(this, i, s), e.addEventListener("paste", function (r) {
var o;
r.preventDefault(), (o = r.clipboardData) != null && o.files.length && t.addFilesToAnyType(Array.from(r.clipboardData.files));
});
}
// preventing insertion early for a nicer UX
// prettier-ignore
}, {
key: "onKeyDown",
value: function onKeyDown(e, t) {
var s = t.target.textContent;
s && s.length >= e && !Ze.PERMITTED_KEYS.has(t.key) && !Ze.isKeyCombinationPermitted(t) && t.preventDefault();
}
}, {
key: "isKeyCombinationPermitted",
value: function isKeyCombinationPermitted(e) {
return e.key === "a" ? e.ctrlKey || e.metaKey : !1;
}
}, {
key: "onInput",
value: function onInput(e, t, i) {
var s = i.target,
r = s.textContent || "";
e !== void 0 && r.length > e && (s.textContent = r.substring(0, e), di.focusEndOfInput(s)), t == null || t();
}
}]);
}();
Ze.PERMITTED_KEYS = /* @__PURE__ */new Set([U.BACKSPACE, U.DELETE, U.ARROW_RIGHT, U.ARROW_LEFT, U.ARROW_DOWN, U.ARROW_UP, U.META, U.CONTROL, U.ENTER]);
var is = Ze;
var Kn = /*#__PURE__*/function () {
function Kn() {
_classCallCheck(this, Kn);
}
return _createClass(Kn, null, [{
key: "sanitizePastedTextContent",
value: function sanitizePastedTextContent(e) {
var i, s;
e.preventDefault();
var t = (i = e.clipboardData) == null ? void 0 : i.getData("text/plain");
t && ((s = document.execCommand) == null || s.call(document, "insertText", !1, t));
}
}]);
}();
var Qe = /*#__PURE__*/function () {
function Qe(e, t, i) {
var _this = this;
_classCallCheck(this, Qe);
var r, o;
this._isComposing = !1;
var s = Qe.processConfig(t, e.textInput);
this.elementRef = Qe.createContainerElement((r = s == null ? void 0 : s.styles) == null ? void 0 : r.container), this._config = s, this.inputElementRef = this.createInputElement(), this.elementRef.appendChild(this.inputElementRef), e.setPlaceholderText = this.setPlaceholderText.bind(this), e.setPlaceholderText(((o = this._config.placeholder) == null ? void 0 : o.text) || "Ask me anything!"), setTimeout(function () {
is.add(_this.inputElementRef, i, _this._config.characterLimit, e._validationHandler), _this._onInput = t.onInput;
});
}
return _createClass(Qe, [{
key: "clear",
value:
// this also similarly prevents scroll up
function clear() {
var t, i;
var e = window.scrollY;
this.inputElementRef.classList.contains("text-input-disabled") || (Object.assign(this.inputElementRef.style, (t = this._config.placeholder) == null ? void 0 : t.style), this.inputElementRef.textContent = "", di.focusEndOfInput(this.inputElementRef), (i = this._onInput) == null || i.call(this, !1)), Ue.IS_CHROMIUM && window.scrollTo({
top: e
});
}
}, {
key: "createInputElement",
value: function createInputElement() {
var t, i, s, r;
var e = document.createElement("div");
return e.id = Qe.TEXT_INPUT_ID, e.classList.add("text-input-styling"), e.role = "textbox", Ue.IS_CHROMIUM && Qe.preventAutomaticScrollUpOnNewLine(e), typeof this._config.disabled == "boolean" && this._config.disabled === !0 ? (e.contentEditable = "false", e.classList.add("text-input-disabled"), e.setAttribute("aria-disabled", "true")) : (e.contentEditable = "true", e.removeAttribute("aria-disabled"), this.addEventListeners(e)), Object.assign(e.style, (t = this._config.styles) == null ? void 0 : t.text), Object.assign(e.style, (i = this._config.placeholder) == null ? void 0 : i.style), (r = (s = this._config.placeholder) == null ? void 0 : s.style) != null && r.color || e.setAttribute("textcolor", ""), e;
}
}, {
key: "removePlaceholderStyle",
value: function removePlaceholderStyle() {
var e, t, i, s;
!this.inputElementRef.classList.contains("text-input-disabled") && (e = this._config.placeholder) != null && e.style && (L.unsetStyle(this.inputElementRef, (t = this._config.placeholder) == null ? void 0 : t.style), Object.assign(this.inputElementRef.style, (s = (i = this._config) == null ? void 0 : i.styles) == null ? void 0 : s.text));
}
}, {
key: "addEventListeners",
value: function addEventListeners(e) {
var _this2 = this;
var t, i;
(t = this._config.styles) != null && t.focus && (e.onfocus = function () {
var s;
return Object.assign(_this2.elementRef.style, (s = _this2._config.styles) == null ? void 0 : s.focus);
}, e.onblur = this.onBlur.bind(this, this._config.styles.focus, (i = this._config.styles) == null ? void 0 : i.container)), e.addEventListener("keydown", this.onKeydown.bind(this)), e.addEventListener("input", this.onInput.bind(this)), e.addEventListener("paste", Kn.sanitizePastedTextContent), e.addEventListener("compositionstart", function () {
return _this2._isComposing = !0;
}), e.addEventListener("compositionend", function () {
return _this2._isComposing = !1;
});
}
}, {
key: "onBlur",
value: function onBlur(e, t) {
L.unsetStyle(this.elementRef, e), t && Object.assign(this.elementRef.style, t);
}
}, {
key: "onKeydown",
value: function onKeydown(e) {
var t;
e.key === U.ENTER && !Ue.IS_MOBILE && !this._isComposing && !e.ctrlKey && !e.shiftKey && (e.preventDefault(), (t = this.submit) == null || t.call(this));
}
}, {
key: "onInput",
value: function onInput() {
var e, t;
this.isTextInputEmpty() ? Object.assign(this.inputElementRef.style, (e = this._config.placeholder) == null ? void 0 : e.style) : this.removePlaceholderStyle(), (t = this._onInput) == null || t.call(this, !0);
}
}, {
key: "setPlaceholderText",
value: function setPlaceholderText(e) {
this.inputElementRef.setAttribute("deep-chat-placeholder-text", e), this.inputElementRef.setAttribute("aria-label", e);
}
}, {
key: "isTextInputEmpty",
value: function isTextInputEmpty() {
return this.inputElementRef.textContent === "";
}
}], [{
key: "processConfig",
value: function processConfig(e, t) {
var _t$disabled, _t$placeholder, _i$text;
var i;
return t !== null && t !== void 0 ? t : t = {}, (_t$disabled = t.disabled) !== null && _t$disabled !== void 0 ? _t$disabled : t.disabled = e.isTextInputDisabled, (_t$placeholder = t.placeholder) !== null && _t$placeholder !== void 0 ? _t$placeholder : t.placeholder = {}, (_i$text = (i = t.placeholder).text) !== null && _i$text !== void 0 ? _i$text : i.text = e.textInputPlaceholderText, t;
}
}, {
key: "createContainerElement",
value: function createContainerElement(e) {
var t = document.createElement("div");
return t.id = "text-input-container", Object.assign(t.style, e), t;
}
// this is is a bug fix where if the browser is scrolled down and the user types in text that creates new line
// the browser scrollbar will move up which leads to undesirable UX.
// More details in this Stack Overflow question:
// https://stackoverflow.com/questions/76285135/prevent-automatic-scroll-when-text-is-inserted-into-contenteditable-div
// prettier-ignore
}, {
key: "preventAutomaticScrollUpOnNewLine",
value: function preventAutomaticScrollUpOnNewLine(e) {
var t;
e.addEventListener("keydown", function () {
t = window.scrollY;
}), e.addEventListener("input", function () {
t !== window.scrollY && window.scrollTo({
top: t
});
});
}
}]);
}();
Qe.TEXT_INPUT_ID = "text-input";
var Si = Qe;
var di = /*#__PURE__*/function () {
function di() {
_classCallCheck(this, di);
}
return _createClass(di, null, [{
key: "focusEndOfInput",
value: function focusEndOfInput(e) {
var t = document.createRange();
t.selectNodeContents(e), t.collapse(!1);
var i = window.getSelection();
i == null || i.removeAllRanges(), i == null || i.addRange(t);
}
}, {
key: "focusFromParentElement",
value: function focusFromParentElement(e) {
var t = e.querySelector("#".concat(Si.TEXT_INPUT_ID));
t && (Ue.IS_SAFARI && t.focus(), di.focusEndOfInput(t));
}
}]);
}();
function Us(n) {
return n.charAt(0).toUpperCase() + n.slice(1);
}
function Wn(n) {
return n && JSON.stringify(n);
}
function _s(n, e, t, i) {
var s = "\n".concat(Us(e), " message: ").concat(JSON.stringify(n), " \n"),
r = t ? "".concat(Us(e), " message after interceptor: ").concat(Wn(i), " \n") : "";
return s + r;
}
function $n(n, e, t, i) {
return "".concat(_s(n, e, t, i), "Make sure the ").concat(e, " message is using the Response format: https://deepchat.dev/docs/connect/#Response \nYou can also augment it using the responseInterceptor property: https://deepchat.dev/docs/interceptors#responseInterceptor");
}
function Jn(n, e, t) {
var i = "response";
return "".concat(_s(n, i, e, t), "Make sure the ").concat(i, " message is using the {text: string} format, e.g: {text: \"Model Response\"}");
}
function Xn(n, e) {
var t = "request";
return "".concat(_s(n, t, e), "Make sure the ").concat(t, " message is using the {body: {text: string}} format, e.g: {body: {text: \"Model Response\"}}");
}
var js = "Make sure the events are using {text: string} or {html: string} format.\nYou can also augment them using the responseInterceptor property: https://deepchat.dev/docs/interceptors#responseInterceptor",
M = {
INVALID_KEY: "Invalid API Key",
CONNECTION_FAILED: "Failed to connect",
INVALID_RESPONSE: $n,
INVALID_MODEL_REQUEST: Xn,
INVALID_MODEL_RESPONSE: Jn,
INVALID_STREAM_ARRAY_RESPONSE: "Multi-response arrays are not supported for streaming",
INVALID_STREAM_EVENT: js,
INVALID_STREAM_EVENT_MIX: "Cannot mix {text: string} and {html: string} responses.",
NO_VALID_STREAM_EVENTS_SENT: "No valid stream events were sent.\n".concat(js),
READABLE_STREAM_CONNECTION_ERROR: "Readable Stream connection error."
},
ji = /*#__PURE__*/function () {
function ji() {
_classCallCheck(this, ji);
}
return _createClass(ji, null, [{
key: "addElements",
value: function addElements(e) {
for (var _len = arguments.length, t = new Array(_len > 1 ? _len - 1 : 0), _key = 1; _key < _len; _key++) {
t[_key - 1] = arguments[_key];
}
t.forEach(function (i) {
return e.appendChild(i);
});
}
}, {
key: "isScrollbarAtBottomOfElement",
value: function isScrollbarAtBottomOfElement(e) {
var t = e.scrollHeight,
i = e.clientHeight,
s = e.scrollTop,
r = t - i;
return s >= r - ji.CODE_SNIPPET_GENERATION_JUMP;
}
}, {
key: "cloneElement",
value: function cloneElement(e) {
var t = e.cloneNode(!0);
return e.parentNode.replaceChild(t, e), t;
}
}, {
key: "scrollToBottom",
value: function scrollToBottom(e) {
var t = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : !1;
t ? e.scrollTo({
left: 0,
top: e.scrollHeight,
behavior: "smooth"
}) : e.scrollTop = e.scrollHeight;
}
}, {
key: "scrollToTop",
value: function scrollToTop(e) {
e.scrollTop = 0;
}
}]);
}();
ji.CODE_SNIPPET_GENERATION_JUMP = 0.5;
var W = ji;
var Hi = /*#__PURE__*/function () {
function Hi() {
_classCallCheck(this, Hi);
}
return _createClass(Hi, null, [{
key: "speak",
value: function speak(e, t) {
if (window.SpeechSynthesisUtterance) {
var i = new SpeechSynthesisUtterance(e);
Object.assign(i, t), speechSynthesis.speak(i);
}
}
}, {
key: "processConfig",
value: function processConfig(e, t) {
var i = {};
setTimeout(function () {
if (_typeof(e) == "object" && (e.lang && (i.lang = e.lang), e.pitch && (i.pitch = e.pitch), e.rate && (i.rate = e.rate), e.volume && (i.volume = e.volume), e.voiceName)) {
var s = window.speechSynthesis.getVoices().find(function (r) {
var o;
return r.name.toLocaleLowerCase() === ((o = e.voiceName) == null ? void 0 : o.toLocaleLowerCase());
});
s && (i.voice = s);
}
t(i);
}, Hi.LOAD_VOICES_MS);
}
}]);
}();
Hi.LOAD_VOICES_MS = 200;
var Et = Hi;
var gt = /*#__PURE__*/function () {
function gt() {
_classCallCheck(this, gt);
}
return _createClass(gt, null, [{
key: "colorToHex",
value: function colorToHex(e) {
var t = document.createElement("div");
return t.style.color = e, document.body.appendChild(t), "#".concat(window.getComputedStyle(t).color.match(/\d+/g).map(function (r) {
return parseInt(r).toString(16).padStart(2, "0");
}).join(""));
}
}, {
key: "setDots",
value: function setDots(e, t) {
var i, s, r, o;
if ((o = (r = (s = (i = t == null ? void 0 : t.loading) == null ? void 0 : i.message) == null ? void 0 : s.styles) == null ? void 0 : r.bubble) != null && o.color) {
var a = gt.colorToHex(t.loading.message.styles.bubble.color);
e.style.setProperty("--loading-message-color", a), e.style.setProperty("--loading-message-color-fade", "".concat(a, "33"));
} else e.style.setProperty("--loading-message-color", "#848484"), e.style.setProperty("--loading-message-color-fade", "#55555533");
}
}, {
key: "setRing",
value: function setRing(e, t) {
var _ref = t || {},
i = _ref.color,
s = _ref.width,
r = _ref.height,
o = _ref.margin,
a = _ref.border;
if (i) {
var l = gt.colorToHex(i);
e.style.setProperty("--loading-history-color", l);
} else e.style.setProperty("--loading-history-color", "#dbdbdb");
e.style.setProperty("--loading-history-height", r || "57px"), e.style.setProperty("--loading-history-width", s || "57px"), e.style.setProperty("--loading-history-margin", o || "7px"), e.style.setProperty("--loading-history-border", a || "6px solid");
}
}]);
}();
gt.BUBBLE_CLASS = "deep-chat-loading-message-bubble", gt.DOTS_CONTAINER_CLASS = "deep-chat-loading-message-dots-container";
var Fe = gt;
var ce = /*#__PURE__*/function () {
function ce() {
_classCallCheck(this, ce);
}
return _createClass(ce, null, [{
key: "setElementProps",
value:
// prettier-ignore
function setElementProps(e, t, i, s) {
var r;
i !== "loading" && (e.applyCustomStyles(t, s, !0, (r = e.messageStyles) == null ? void 0 : r[i]), t.bubbleElement.classList.add(ce.FILE_BUBBLE_CLASS));
}
// prettier-ignore
}, {
key: "addMessage",
value: function addMessage(e, t, i, s, r) {
ce.setElementProps(e, t, i, s), r || (e.appendOuterContainerElemet(t.outerContainer), e.focusMode || (e.elementRef.scrollTop = e.elementRef.scrollHeight));
}
}, {
key: "wrapInLink",
value: function wrapInLink(e, t, i) {
var s = document.createElement("a");
return s.href = t, s.download = i || ce.DEFAULT_FILE_NAME, s.target = "_blank", s.appendChild(e), s;
}
}, {
key: "isNonLinkableDataUrl",
value: function isNonLinkableDataUrl(e, t) {
return !t.startsWith("data") || e === "image" ? !1 : e === "any" && t.startsWith("data:text/javascript") || !t.startsWith("data:image") && !t.startsWith("data:application");
}
}, {
key: "processContent",
value: function processContent(e, t, i, s) {
return !i || ce.isNonLinkableDataUrl(e, i) ? t : ce.wrapInLink(t, i, s);
}
}, {
key: "waitToLoadThenScroll",
value: function waitToLoadThenScroll(e) {
setTimeout(function () {
e.scrollTop = e.scrollHeight;
}, 60);
}
}, {
key: "scrollDownOnImageLoad",
value: function scrollDownOnImageLoad(e, t) {
if (e.startsWith("data")) ce.waitToLoadThenScroll(t);else try {
fetch(e, {
mode: "no-cors"
})["catch"](function () {})["finally"](function () {
ce.waitToLoadThenScroll(t);
});
} catch (_unused2) {
t.scrollTop = t.scrollHeight;
}
}
// The strategy is to emit the actual file reference in the `onMessage` event for the user to inspect it
// But it is not actually used by anything in the chat, hence it is removed when adding a message
// after the body has been stringified and parsed - the file reference will disappear, hence this readds it
}, {
key: "reAddFileRefToObject",
value: function reAddFileRefToObject(e, t) {
var i;
(i = e.files) == null || i.forEach(function (s, r) {
var o;
s.ref && (o = t.files) != null && o[r] && (t.files[r].ref = s.ref);
});
}
// the chat does not use the actual file
}, {
key: "removeFileRef",
value: function removeFileRef(e) {
var t = _objectSpread({}, e);
return delete t.ref, t;
}
}, {
key: "isAudioFile",
value: function isAudioFile(e) {
var t = /\.(mp3|ogg|wav|aac|webm|4a)$/i,
i = e.type,
s = e.src;
return i === "audio" || (s == null ? void 0 : s.startsWith("data:audio")) || s && t.test(s);
}
}, {
key: "isImageFile",
value: function isImageFile(e) {
var t = e.type,
i = e.src;
return t === "image" || (i == null ? void 0 : i.startsWith("data:image")) || i && ce.isImageFileExtension(i);
}
}, {
key: "isImageFileExtension",
value: function isImageFileExtension(e) {
return /\.(jpg|jpeg|png|gif|bmp)$/i.test(e);
}
}]);
}();
ce.DEFAULT_FILE_NAME = "file", ce.FILE_BUBBLE_CLASS = "file-message";
var q = ce;
var te = /*#__PURE__*/function () {
function te() {
_classCallCheck(this, te);
}
return _createClass(te, null, [{
key: "checkForContainerStyles",
value: function checkForContainerStyles(e, t) {
var i = e.containerStyle;
i && (Object.assign(t.style, i), console.error("The containerStyle property is deprecated since version 1.3.14."), console.error("Please change to using the style property instead: https://deepchat.dev/docs/styles#style"));
}
// eslint-disable-next-line @typescript-eslint/no-explicit-any
}, {
key: "handleResponseProperty",
value: function handleResponseProperty(e) {
return console.error("The {result: ....} response object type is deprecated since version 1.3.0."), console.error("Please change to using the new response object: https://deepchat.dev/docs/connect#Response"), e.result;
}
}, {
key: "processHistory",
value: function processHistory(e) {
var t = e.initialMessages;
if (t) return console.error("The initialMessages property is deprecated since version 2.0.0."), console.error("Please change to using the history property instead: https://deepchat.dev/docs/messages/#history"), t;
}
}, {
key: "processHistoryFile",
value: function processHistoryFile(e) {
var t = e.file;
t && (console.error("The file property in MessageContent is deprecated since version 1.3.17."), console.error("Please change to using the files array property: https://deepchat.dev/docs/messages/#MessageContent"), e.files = [t]);
}
}, {
key: "processValidateInput",
value: function processValidateInput(e) {
var t = e.validateMessageBeforeSending;
if (t) return console.error("The validateMessageBeforeSending property is deprecated since version 1.3.24."), console.error("Please change to using validateInput: https://deepchat.dev/docs/interceptors#validateInput"), t;
}
}, {
key: "processSubmitUserMessage",
value: function processSubmitUserMessage(e) {
return console.error("The submitUserMessage(text: string) argument string type is deprecated since version 1.4.4."), console.error("Please change to using the new argument type: https://deepchat.dev/docs/methods#submitUserMessage"), {
text: e
};
}
}, {
key: "flagHTMLUpdateClass",
value: function flagHTMLUpdateClass(e) {
var t;
(t = e.children[0]) != null && t.classList.contains("deep-chat-update-message") && (console.error('The "deep-chat-update-message" html class is deprecated since version 1.4.4.'), console.error("Please change to using {..., overwrite: true} object: https://deepchat.dev/docs/connect#Response"));
}
}, {
key: "processConnect",
value: function processConnect(e) {
var t = e;
t.request && (t.connect ? Object.assign(t.connect, t.request) : t.connect = t.request, console.error("The request property is deprecated since version 2.0.0."), console.error("Please see the connect object: https://deepchat.dev/docs/connect#connect-1"));
}
}, {
key: "checkForStream",
value: function checkForStream(e) {
var t = e.stream;
if (t) return console.error("The stream property has been moved to the connect object in version 2.0.0."), console.error("Please see the connect object: https://deepchat.dev/docs/connect#connect-1"), t;
}
}, {
key: "fireOnNewMessage",
value: function fireOnNewMessage(e, t) {
var s;
var i = e;
i.onNewMessage && (console.error("The onNewMessage event has been deprecated since version 2.0.0."), console.error("Please see the onMessage event: https://deepchat.dev/docs/events#onMessage"), (s = i.onNewMessage) == null || s.call(i, t)), e.dispatchEvent(new CustomEvent("new-message", {
detail: t
}));
}
}, {
key: "processFileConfigConnect",
value: function processFileConfigConnect(e) {
var t = e;
t.request && (console.error("The request property in file configuration is deprecated since version 2.0.0."), console.error("Please use the connect property instead: https://deepchat.dev/docs/files"), t.connect || (t.connect = t.request));
}
}, {
key: "processMessageStyles",
value: function processMessageStyles(e) {
if (!e) return;
var t = JSON.parse(JSON.stringify(e)),
i = t.loading;
return i && (i.outerContainer || i.innerContainer || i.bubble || i.media) && (console.error("The loading message styles are defined using LoadingMessageStyles interface since version 2.1.0."), console.error("Check it out here: https://deepchat.dev/docs/messages/styles#LoadingMessageStyles"), t.loading = {
message: {
styles: i
}
}), t;
}
}, {
key: "processDemo",
value: function processDemo(e) {
return typeof e == "boolean" || e.displayLoadingBubble && (console.error("The demo displayLoadingBubble property is deprecated since version 2.1.0."), console.error("Please use displayLoading instead: https://deepchat.dev/docs/modes#demo"), e.displayLoading = {
message: !0
}), e;
}
}]);
}();
var $e = /*#__PURE__*/function () {
function $e() {
_classCallCheck(this, $e);
}
return _createClass($e, null, [{
key: "mouseUp",
value: function mouseUp(e, t) {
L.unsetAllCSSMouseStates(e, t), Object.assign(e.style, t["default"]), Object.assign(e.style, t.hover);
}
}, {
key: "mouseDown",
value: function mouseDown(e, t) {
Object.assign(e.style, t.click);
}
}, {
key: "mouseLeave",
value: function mouseLeave(e, t) {
L.unsetAllCSSMouseStates(e, t), Object.assign(e.style, t["default"]);
}
}, {
key: "mouseEnter",
value: function mouseEnter(e, t) {
Object.assign(e.style, t.hover);
}
}, {
key: "add",
value: function add(e, t) {
e.addEventListener("mouseenter", $e.mouseEnter.bind(this, e, t)), e.addEventListener("mouseleave", $e.mouseLeave.bind(this, e, t)), e.addEventListener("mousedown", $e.mouseDown.bind(this, e, t)), e.addEventListener("mouseup", $e.mouseUp.bind(this, e, t));
}
}]);
}();
var Yn = "deep-chat-temporary-message",
Zn = "deep-chat-suggestion-button",
ss = {
"deep-chat-button": {
styles: {
"default": {
backgroundColor: "white",
padding: "5px",
paddingLeft: "7px",
paddingRight: "7px",
border: "1px solid #c2c2c2",
borderRadius: "6px",
cursor: "pointer"
},
hover: {
backgroundColor: "#fafafa"
},
click: {
backgroundColor: "#f1f1f1"
}
}
}
},
Hs = Object.keys(ss);
var we = /*#__PURE__*/function () {
function we() {
_classCallCheck(this, we);
}
return _createClass(we, null, [{
key: "applySuggestionEvent",
value: function applySuggestionEvent(e, t) {
setTimeout(function () {
t.addEventListener("click", function () {
var i, s;
(s = e.submitUserMessage) == null || s.call(e, {
text: ((i = t.textContent) == null ? void 0 : i.trim()) || ""
});
});
});
}
}, {
key: "isElementTemporary",
value: function isElementTemporary(e) {
var t;
return e ? (t = e.bubbleElement.children[0]) == null ? void 0 : t.classList.contains(Yn) : !1;
}
}, {
key: "doesElementContainDeepChatClass",
value: function doesElementContainDeepChatClass(e) {
return Hs.find(function (t) {
return e.classList.contains(t);
});
}
}, {
key: "applyEvents",
value: function applyEvents(e, t) {
var i = ss[t].events;
Object.keys(i || []).forEach(function (s) {
e.addEventListener(s, i == null ? void 0 : i[s]);
});
}
}, {
key: "getProcessedStyles",
value: function getProcessedStyles(e, t, i) {
var s