deep-chat-dev
Version:
Customizable chat component for AI APIs
14 lines • 605 kB
JavaScript
function _objectWithoutProperties(e,t){if(null==e)return{};var o,r,i=_objectWithoutPropertiesLoose(e,t);if(Object.getOwnPropertySymbols){var n=Object.getOwnPropertySymbols(e);for(r=0;r<n.length;r++)o=n[r],-1===t.indexOf(o)&&{}.propertyIsEnumerable.call(e,o)&&(i[o]=e[o]);}return i;}function _objectWithoutPropertiesLoose(r,e){if(null==r)return{};var t={};for(var n in r)if({}.hasOwnProperty.call(r,n)){if(-1!==e.indexOf(n))continue;t[n]=r[n];}return t;}function _superPropGet(t,o,e,r){var p=_get(_getPrototypeOf(1&r?t.prototype:t),o,e);return 2&r&&"function"==typeof p?function(t){return p.apply(e,t);}:p;}function _get(){return _get="undefined"!=typeof Reflect&&Reflect.get?Reflect.get.bind():function(e,t,r){var p=_superPropBase(e,t);if(p){var n=Object.getOwnPropertyDescriptor(p,t);return n.get?n.get.call(arguments.length<3?e:r):n.value;}},_get.apply(null,arguments);}function _superPropBase(t,o){for(;!{}.hasOwnProperty.call(t,o)&&null!==(t=_getPrototypeOf(t)););return t;}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 n=0,F=function F(){};return{s:F,n:function(_n22){function n(){return _n22.apply(this,arguments);}n.toString=function(){return _n22.toString();};return n;}(function(){return n>=r.length?{done:!0}:{done:!1,value:r[n++]};}),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 _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 _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 _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 _regenerator(){/*! regenerator-runtime -- Copyright (c) 2014-present, Facebook, Inc. -- license (MIT): https://github.com/babel/babel/blob/main/packages/babel-helpers/LICENSE */var e,t,r="function"==typeof Symbol?Symbol:{},n=r.iterator||"@@iterator",o=r.toStringTag||"@@toStringTag";function i(r,n,o,i){var c=n&&n.prototype instanceof Generator?n:Generator,u=Object.create(c.prototype);return _regeneratorDefine2(u,"_invoke",function(r,n,o){var i,c,u,f=0,p=o||[],y=!1,G={p:0,n:0,v:e,a:d,f:d.bind(e,4),d:function d(t,r){return i=t,c=0,u=e,G.n=r,a;}};function d(r,n){for(c=r,u=n,t=0;!y&&f&&!o&&t<p.length;t++){var o,i=p[t],d=G.p,l=i[2];r>3?(o=l===n)&&(u=i[(c=i[4])?5:(c=3,3)],i[4]=i[5]=e):i[0]<=d&&((o=r<2&&d<i[1])?(c=0,G.v=n,G.n=i[1]):d<l&&(o=r<3||i[0]>n||n>l)&&(i[4]=r,i[5]=n,G.n=l,c=0));}if(o||r>1)return a;throw y=!0,n;}return function(o,p,l){if(f>1)throw TypeError("Generator is already running");for(y&&1===p&&d(p,l),c=p,u=l;(t=c<2?e:u)||!y;){i||(c?c<3?(c>1&&(G.n=-1),d(c,u)):G.n=u:G.v=u);try{if(f=2,i){if(c||(o="next"),t=i[o]){if(!(t=t.call(i,u)))throw TypeError("iterator result is not an object");if(!t.done)return t;u=t.value,c<2&&(c=0);}else 1===c&&(t=i["return"])&&t.call(i),c<2&&(u=TypeError("The iterator does not provide a '"+o+"' method"),c=1);i=e;}else if((t=(y=G.n<0)?u:r.call(n,G))!==a)break;}catch(t){i=e,c=1,u=t;}finally{f=1;}}return{value:t,done:y};};}(r,o,i),!0),u;}var a={};function Generator(){}function GeneratorFunction(){}function GeneratorFunctionPrototype(){}t=Object.getPrototypeOf;var c=[][n]?t(t([][n]())):(_regeneratorDefine2(t={},n,function(){return this;}),t),u=GeneratorFunctionPrototype.prototype=Generator.prototype=Object.create(c);function f(e){return Object.setPrototypeOf?Object.setPrototypeOf(e,GeneratorFunctionPrototype):(e.__proto__=GeneratorFunctionPrototype,_regeneratorDefine2(e,o,"GeneratorFunction")),e.prototype=Object.create(u),e;}return GeneratorFunction.prototype=GeneratorFunctionPrototype,_regeneratorDefine2(u,"constructor",GeneratorFunctionPrototype),_regeneratorDefine2(GeneratorFunctionPrototype,"constructor",GeneratorFunction),GeneratorFunction.displayName="GeneratorFunction",_regeneratorDefine2(GeneratorFunctionPrototype,o,"GeneratorFunction"),_regeneratorDefine2(u),_regeneratorDefine2(u,o,"Generator"),_regeneratorDefine2(u,n,function(){return this;}),_regeneratorDefine2(u,"toString",function(){return"[object Generator]";}),(_regenerator=function _regenerator(){return{w:i,m:f};})();}function _regeneratorDefine2(e,r,n,t){var i=Object.defineProperty;try{i({},"",{});}catch(e){i=0;}_regeneratorDefine2=function _regeneratorDefine(e,r,n,t){function o(r,n){_regeneratorDefine2(e,r,function(e){return this._invoke(r,n,e);});}r?i?i(e,r,{value:n,enumerable:!t,configurable:!t,writable:!t}):e[r]=n:(o("next",0),o("throw",1),o("return",2));},_regeneratorDefine2(e,r,n,t);}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 _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 _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 _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 _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 _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 f="classList",E="style",Ko="unset",Wo="html-wrapper",W="length",x=function x(){var i=arguments.length>0&&arguments[0]!==undefined?arguments[0]:"div";return document.createElement(i);};var Xo=/*#__PURE__*/function(){function Xo(){_classCallCheck(this,Xo);}return _createClass(Xo,null,[{key:"render",value:function render(e,t){var n=x();n.id="error-view",n.innerText=t,e.replaceChildren(n);}}]);}();var js=/*#__PURE__*/function(){function js(){_classCallCheck(this,js);}return _createClass(js,null,[{key:"onLoad",value:function onLoad(e){e.innerHTML='<div id="loading-validate-key-property"></div>';}},{key:"createElements",value:function createElements(){var e=x();return e.id="validate-property-key-view",e;}},{key:"render",value:function render(e,t,n){var s=js.createElements(),r={onSuccess:t,onFail:Xo.render.bind(this,e,"Your 'key' has failed authentication"),onLoad:js.onLoad.bind(this,s)};n.key&&n.verifyKey(n.key,r),e.replaceChildren(s);}}]);}();var oe="service",h="text",L="html",p="error",X="https://deepchat.dev/docs/",te="ai",F="user",St="assistant",$s="error-message-text",Rs="deep-chat-outer-container-role-",Mr="empty-message",Si="deep-chat-top-message",kr="deep-chat-middle-message",xi="deep-chat-bottom-message",T="src",y="type",ne="file",m="files",K="image",ee="images",Fe="camera",Bn="gifs",q="audio",pt="microphone",lo="mixedFiles",mn="any",ho="file-message",Jt="start",uo="end",po="messages",Lr="0",Pr="1",S="role",_e="string",ae=function ae(i){return JSON.stringify(i);},w=function w(i){return JSON.parse(ae(i));};function Nr(i){return i.charAt(0).toUpperCase()+i.slice(1);}function Zo(i){return i&&ae(i);}function nr(i,e,t,n){var s="\n".concat(Nr(e)," message: ").concat(ae(i)," \n"),r=t?"".concat(Nr(e)," message after interceptor: ").concat(Zo(n)," \n"):"";return s+r;}function Yo(i,e,t,n){return"".concat(nr(i,e,t,n),"Make sure the ").concat(e," message is using the Response format: ").concat(X,"connect/#Response \nYou can also augment it using the responseInterceptor property: ").concat(X,"interceptors#responseInterceptor");}function Jo(i,e,t){var n="response";return"".concat(nr(i,n,e,t),"Make sure the ").concat(n," message is using the {text: string} format, e.g: {text: \"Model Response\"}");}function Qo(i,e){var t="request";return"".concat(nr(i,t,e),"Make sure the ").concat(t," message is using the {body: {text: string}} format, e.g: {body: {text: \"Model Response\"}}");}function ea(i){return"".concat(i," failed - please wait for chat view to render before calling this property.");}var On=Yo,ta=Qo,na=Jo,Br=ea,ue="Invalid API Key",He="Failed to connect",je="Request settings have not been set up",pi="No file was added",sr="Image was not found",fo="Multi-response arrays are not supported for streaming",mo="Make sure the events are using {text: string} or {html: string} format.\nYou can also augment them using the responseInterceptor property: ".concat(X,"interceptors#responseInterceptor"),sa="Cannot mix {text: string} and {html: string} responses.",ia="No valid stream events were sent.\n".concat(mo),ra="Readable Stream connection error.",Qt="Please define a `function_handler` property inside the service config.",gn="Function tool response must be an array or contain a text property",go="Failed to fetch history";var Xt=/*#__PURE__*/function(){function Xt(){_classCallCheck(this,Xt);}return _createClass(Xt,null,[{key:"apply",value:function apply(e,t){if(t)try{Xt.applyStyleSheet(e,t);}catch(_unused){Xt.addStyleElement(e,t);}}},{key:"applyStyleSheet",value:function applyStyleSheet(e,t){var n=new CSSStyleSheet();n.replaceSync(e),t.adoptedStyleSheets.push(n);}},{key:"addStyleElement",value:function addStyleElement(e,t){var n=x("style");n.innerHTML=e,t.appendChild(n);}},{key:"camelToKebab",value:function camelToKebab(e){return e.replace(/[A-Z]/g,function(t){return"-".concat(t.toLowerCase());});}},{key:"applyChatStyle",value:function applyChatStyle(e,t){if(!e||!t)return;var n=Object.entries(e).filter(function(_ref){var _ref2=_slicedToArray(_ref,2),s=_ref2[1];return s;}).map(function(_ref3){var _ref4=_slicedToArray(_ref3,2),s=_ref4[0],r=_ref4[1];return"".concat(Xt.camelToKebab(s),": ").concat(r,";");}).join(" ");n&&Xt.apply(":host { ".concat(n," }"),t);}}]);}();var Hn="inside-start",_t="inside-end",Pe="outside-start",ve="outside-end",it="dropup-menu",A="default",De="hover",Y="click",j="active",$="disabled",G="svg",$t="unavailable",R="styles",As="mouseenter",bn="mouseleave",oa="mousedown",aa="mouseup",ct="submit",Ot="loading",Mi="stop",Zn="unsupported",Cn="commandMode";var de=/*#__PURE__*/function(){function de(){_classCallCheck(this,de);}return _createClass(de,null,[{key:"unsetStyle",value:function unsetStyle(e,t){var n=Object.keys(t).reduce(function(s,r){return s[r]="",s;},{});Object.assign(e[E],n);}},{key:"unsetActivityCSSMouseStates",value:function unsetActivityCSSMouseStates(e,t){t[Y]&&de.unsetStyle(e,t[Y]),t[De]&&de.unsetStyle(e,t[De]);}},{key:"unsetAllCSSMouseStates",value:function unsetAllCSSMouseStates(e,t){de.unsetActivityCSSMouseStates(e,t),t[A]&&de.unsetStyle(e,t[A]);}// if you want to asdd default styling - use pure css classes
},{key:"processStateful",value:function processStateful(e){var t=e[A]||{},n=Object.assign(w(t),e==null?void 0:e[De]),s=Object.assign(w(n),e==null?void 0:e[Y]);return _defineProperty(_defineProperty(_defineProperty({},A,t),De,n),Y,s);}},{key:"mergeStatefulStyles",value:function mergeStatefulStyles(e){var t=_defineProperty(_defineProperty(_defineProperty({},A,{}),De,{}),Y,{});return e.forEach(function(n){t[A]=Object.assign(t[A],n[A]),t[De]=Object.assign(t[De],n[De]),t[Y]=Object.assign(t[Y],n[Y]);}),t;}},{key:"overwriteDefaultWithAlreadyApplied",value:function overwriteDefaultWithAlreadyApplied(e,t){Object.keys(e[A]||[]).forEach(function(n){var r;var s=n;t[E][s]&&(r=e[A])!=null&&r[s]&&(e[A][n]=t[E][s]);});}},{key:"applyToStyleIfNotDefined",value:function applyToStyleIfNotDefined(e,t){for(var n in t){var s=t[n];e[n]===""&&s&&(e[n]=s);}}}]);}();var rn=/*#__PURE__*/function(){function rn(){_classCallCheck(this,rn);}return _createClass(rn,null,[{key:"buildElement",value:function buildElement(){var e=x();e[f].add("tooltip");var t=x("span");return t[f].add("tooltip-text"),e.appendChild(t),e;}},{key:"tryCreateConfig",value:function tryCreateConfig(e,t){if(t)return typeof t=="boolean"?_defineProperty({},h,e):_defineProperty(_defineProperty(_defineProperty({},h,t[h]||e),"timeout",t.timeout||0),"style",t[E]);}},{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,c=r.left+r.width/2;t[E].left="".concat(c-a-s.left,"px"),t[E].top="".concat(r.top-36-s.top,"px");var l=t.getBoundingClientRect();l.left<s.left?t[E].left="".concat(rn.OVERFLOW_NEW_POSITION_PX,"px"):l.right>s.right&&(t[E].left="".concat(s.width-l.width-rn.OVERFLOW_NEW_POSITION_PX,"px"));}},{key:"display",value:function display(e,t,n){return n||(n=rn.traverseParentUntilContainer(e).nextSibling),t[h]&&(n.children[0].textContent=t[h]),{timeout:setTimeout(function(){n[E].visibility="visible",rn.setPosition(e,n),t[E]&&Object.assign(n[E],t[E]);},t.timeout||0),element:n};}},{key:"hide",value:function hide(e,t){clearTimeout(e.timeout),e.element[E].visibility="hidden",t[E]&&de.unsetStyle(e.element,t[E]),e.element[E].left="",e.element[E].top="";}}]);}();rn.OVERFLOW_NEW_POSITION_PX=4;var bt=rn;var os=/*#__PURE__*/_createClass(function os(){_classCallCheck(this,os);});os.IS_SAFARI=/^((?!chrome|android).)*safari/i.test(navigator.userAgent),os.IS_CHROMIUM=window.chrome,os.IS_MOBILE=/iPhone|iPad|iPod|Android/i.test(navigator.userAgent);var Ge=os;var Ee=/* @__PURE__ */function(i){return i.ESCAPE="Escape",i.ENTER="Enter",i.TAB="Tab",i.ARROW_UP="ArrowUp",i.ARROW_DOWN="ArrowDown",i.ARROW_RIGHT="ArrowRight",i.ARROW_LEFT="ArrowLeft",i.BACKSPACE="Backspace",i.DELETE="Delete",i.META="Meta",i.CONTROL="Control",i;}(Ee||{});var on=/*#__PURE__*/function(){function on(){_classCallCheck(this,on);}return _createClass(on,null,[{key:"add",value:// prettier-ignore
function add(e,t,n,s){n!==void 0&&e.addEventListener("keydown",on.onKeyDown.bind(this,n)),e.oninput=on.onInput.bind(this,n,s),e.addEventListener("paste",function(r){var o;r.preventDefault(),(o=r.clipboardData)!=null&&o[m].length&&t.addFilesToAnyType(Array.from(r.clipboardData[m]));});}// 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&&!on.PERMITTED_KEYS.has(t.key)&&!on.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,n){var s=n.target,r=s.textContent||"";e!==void 0&&r.length>e&&(s.textContent=r.substring(0,e),yn.focusEndOfInput(s)),t==null||t();}}]);}();on.PERMITTED_KEYS=/* @__PURE__ */new Set([Ee.BACKSPACE,Ee.DELETE,Ee.ARROW_RIGHT,Ee.ARROW_LEFT,Ee.ARROW_DOWN,Ee.ARROW_UP,Ee.META,Ee.CONTROL,Ee.ENTER]);var ki=on;var ca=/*#__PURE__*/function(){function ca(){_classCallCheck(this,ca);}return _createClass(ca,null,[{key:"sanitizePastedTextContent",value:function sanitizePastedTextContent(e){var s;e.preventDefault();var t=(s=e.clipboardData)==null?void 0:s.getData("text/plain");if(!t)return;var n=t.replace(/&/g,"&").replace(/</g,"<").replace(/>/g,">").replace(/\n/g,"<br>");document.execCommand("insertHTML",!1,n);}}]);}();var qt=/*#__PURE__*/function(){function qt(e,t,n,s){var _this=this;_classCallCheck(this,qt);var o,a,c,l;this._isComposing=!1;var r=qt.processConfig(t,e.textInput);this.elementRef=qt.createContainerElement((o=r==null?void 0:r[R])==null?void 0:o.container),this._config=r,this.inputElementRef=this.createInputElement((a=e.defaultInput)==null?void 0:a[h],s),qt.addFilesToAnyType(n,(c=e.defaultInput)==null?void 0:c[m]),this.elementRef.appendChild(this.inputElementRef),e.setPlaceholderText=this.setPlaceholderText.bind(this),e.setPlaceholderText(((l=this._config.placeholder)==null?void 0:l[h])||"Ask me anything!"),this._browserStorage=s,setTimeout(function(){ki.add(_this.inputElementRef,n,_this._config.characterLimit,e._validationHandler),_this._onInput=t.onInput;});}return _createClass(qt,[{key:"clear",value:// this also similarly prevents scroll up
function clear(){var t,n,s;var e=window.scrollY;this.inputElementRef[f].contains("text-input-".concat($))||(Object.assign(this.inputElementRef[E],(t=this._config.placeholder)==null?void 0:t[E]),this.inputElementRef.textContent="",yn.focusEndOfInput(this.inputElementRef),(n=this._onInput)==null||n.call(this,!1),(s=this._browserStorage)==null||s.addInputText("")),Ge.IS_CHROMIUM&&window.scrollTo({top:e});}},{key:"createInputElement",value:function createInputElement(e,t){var s,r,o,a;var n=x();return n.id=qt.TEXT_INPUT_ID,n[f].add("text-input-styling"),n[S]="textbox",typeof e=="string"?n.innerText=e:t!=null&&t.trackInputText&&(n.innerText=t.get().inputText||""),Ge.IS_MOBILE&&n.setAttribute("tabindex","0"),Ge.IS_CHROMIUM&&qt.preventAutomaticScrollUpOnNewLine(n),typeof this._config[$]=="boolean"&&this._config[$]===!0?(n.contentEditable="false",n[f].add("text-input-".concat($)),n.setAttribute("aria-".concat($),"true")):(n.contentEditable="true",n.removeAttribute("aria-".concat($)),this.addEventListeners(n)),Object.assign(n[E],(s=this._config[R])==null?void 0:s[h]),Object.assign(n[E],(r=this._config.placeholder)==null?void 0:r[E]),(a=(o=this._config.placeholder)==null?void 0:o[E])!=null&&a.color||n.setAttribute("textcolor",""),n;}},{key:"removePlaceholderStyle",value:function removePlaceholderStyle(){var e,t,n,s;!this.inputElementRef[f].contains("text-input-".concat($))&&(e=this._config.placeholder)!=null&&e[E]&&(de.unsetStyle(this.inputElementRef,(t=this._config.placeholder)==null?void 0:t[E]),Object.assign(this.inputElementRef[E],(s=(n=this._config)==null?void 0:n[R])==null?void 0:s[h]));}},{key:"addEventListeners",value:function addEventListeners(e){var _this2=this;var t,n;(t=this._config[R])!=null&&t.focus&&(e.onfocus=function(){var s;return Object.assign(_this2.elementRef[E],(s=_this2._config[R])==null?void 0:s.focus);},e.onblur=this.onBlur.bind(this,this._config[R].focus,(n=this._config[R])==null?void 0:n.container)),e.addEventListener("keydown",this.onKeydown.bind(this)),e.addEventListener("input",this.onInput.bind(this)),e.addEventListener("paste",ca.sanitizePastedTextContent),e.addEventListener("compositionstart",function(){return _this2._isComposing=!0;}),e.addEventListener("compositionend",function(){return _this2._isComposing=!1;});}},{key:"onBlur",value:function onBlur(e,t){de.unsetStyle(this.elementRef,e),t&&Object.assign(this.elementRef[E],t);}},{key:"onKeydown",value:function onKeydown(e){var t;e.key===Ee.ENTER&&!Ge.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[E],(e=this._config.placeholder)==null?void 0:e[E]):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$$,_t$placeholder,_n$h;var n;return t!==null&&t!==void 0?t:t={},(_t$$=t[$])!==null&&_t$$!==void 0?_t$$:t[$]=e.isTextInputDisabled,(_t$placeholder=t.placeholder)!==null&&_t$placeholder!==void 0?_t$placeholder:t.placeholder={},(_n$h=(n=t.placeholder)[h])!==null&&_n$h!==void 0?_n$h:n[h]=e.textInputPlaceholderText,t;}},{key:"createContainerElement",value:function createContainerElement(e){var t=x();return t.id="text-input-container",Object.assign(t[E],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});});}},{key:"addFilesToAnyType",value:function addFilesToAnyType(e,t){t&&e.addFilesToAnyType(Array.from(t).map(function(n){return n;}));}}]);}();qt.TEXT_INPUT_ID="text-input";var qs=qt;var yn=/*#__PURE__*/function(){function yn(){_classCallCheck(this,yn);}return _createClass(yn,null,[{key:"focusEndOfInput",value:function focusEndOfInput(e){var t=document.createRange();t.selectNodeContents(e),t.collapse(!1);var n=window.getSelection();n==null||n.removeAllRanges(),n==null||n.addRange(t),(Ge.IS_MOBILE||Ge.IS_SAFARI)&&e.focus();}},{key:"focusFromParentElement",value:function focusFromParentElement(e){var t=e.querySelector("#".concat(qs.TEXT_INPUT_ID));t&&yn.focusEndOfInput(t);}}]);}();var bo="Authentication",le="Authorization",la="authorization",fi="Unauthorized",ir="Authorization header",en="Invalid",ws="Incorrect",we="authentication_error",et="invalid_request_error",H="Content-Type",ha="content-type",J="application/json",U="object",rr="completed",Ae="Bearer ",he="GET",ye="POST",or="Upload an audio file",Bs="function_call",pn="input_audio",Ve="image_url",jn="system",Li="placeholder",li=/*#__PURE__*/function(){function li(){_classCallCheck(this,li);}return _createClass(li,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(n){return e.appendChild(n);});}},{key:"isScrollbarAtBottomOfElement",value:function isScrollbarAtBottomOfElement(e){var t=arguments.length>1&&arguments[1]!==undefined?arguments[1]:li.CODE_SNIPPET_GENERATION_JUMP;var n=e.scrollHeight,s=e.clientHeight,r=e.scrollTop,o=n-s;return r>=o-t;}},{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;var n=arguments.length>2?arguments[2]:undefined;e.scrollButton&&e.scrollButton.hiddenElements.size>0&&e.scrollButton.clearHidden(),n?e.elementRef.scrollTo({left:0,top:n.offsetTop}):t?e.elementRef.scrollTo({left:0,top:e.elementRef.scrollHeight,behavior:"smooth"}):e.elementRef.scrollTop=e.elementRef.scrollHeight;}},{key:"scrollToTop",value:function scrollToTop(e){e.scrollTop=0;}},{key:"isVisibleInParent",value:function isVisibleInParent(e,t){var n=e.getBoundingClientRect(),s=t.getBoundingClientRect();return n.bottom>s.top&&n.top<s.bottom;}},{key:"waitForScrollEnd",value:function waitForScrollEnd(e,t){var n=-1,s=0;var _r2=function r(){var o=e.scrollTop;if(o===n){if(s++,s>2){t();return;}}else s=0,n=o;requestAnimationFrame(_r2);};requestAnimationFrame(_r2);}},{key:"assignButtonEvents",value:function assignButtonEvents(e,t){e.onclick=t,e.onkeydown=function(n){n.key===Ee.ENTER&&setTimeout(t);};}}]);}();li.CODE_SNIPPET_GENERATION_JUMP=1;var V=li;var hi=/*#__PURE__*/function(){function hi(){_classCallCheck(this,hi);}return _createClass(hi,null,[{key:"speak",value:function speak(e,t){if(!t.audio&&window.SpeechSynthesisUtterance){var n=new SpeechSynthesisUtterance(e);Object.assign(n,t),speechSynthesis.speak(n);}}},{key:"processConfig",value:function processConfig(e,t){var n={};setTimeout(function(){if(_typeof(e)=="object"&&(e.audio&&(n.audio=e.audio),e.lang&&(n.lang=e.lang),e.pitch&&(n.pitch=e.pitch),e.rate&&(n.rate=e.rate),e.volume&&(n.volume=e.volume),e.voiceName)){var s=window.speechSynthesis.getVoices().find(function(r){var o;return r.name.toLocaleLowerCase()===((o=e.voiceName)==null?void 0:o.toLocaleLowerCase());});s&&(n.voice=s);}t(n);},hi.LOAD_VOICES_MS);}}]);}();hi.LOAD_VOICES_MS=200;var Dn=hi;var kn=/*#__PURE__*/function(){function kn(){_classCallCheck(this,kn);}return _createClass(kn,null,[{key:"colorToHex",value:function colorToHex(e){var t=x();return t[E].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 n,s;if((s=(n=t==null?void 0:t[R])==null?void 0:n.bubble)!=null&&s.color){var r=kn.colorToHex(t[R].bubble.color);e[E].setProperty("--loading-message-color",r),e[E].setProperty("--loading-message-color-fade","".concat(r,"33"));}else e[E].setProperty("--loading-message-color","#848484"),e[E].setProperty("--loading-message-color-fade","#55555533");}},{key:"setRing",value:function setRing(e,t){var _ref8=t||{},n=_ref8.color,s=_ref8.width,r=_ref8.height,o=_ref8.margin,a=_ref8.border;if(n){var c=kn.colorToHex(n);e[E].setProperty("--loading-history-color",c);}else e[E].setProperty("--loading-history-color","#dbdbdb");e[E].setProperty("--loading-history-height",r||"57px"),e[E].setProperty("--loading-history-width",s||"57px"),e[E].setProperty("--loading-history-margin",o||"7px"),e[E].setProperty("--loading-history-border",a||"6px solid");}}]);}();kn.BUBBLE_CLASS="deep-chat-loading-message-bubble",kn.DOTS_CONTAINER_CLASS="deep-chat-loading-message-dots-container";var vt=kn;var ce=/*#__PURE__*/function(){function ce(){_classCallCheck(this,ce);}return _createClass(ce,null,[{key:"checkForContainerStyles",value:function checkForContainerStyles(e,t){var n=e.containerStyle;n&&(Object.assign(t[E],n),console[p]("The containerStyle property".concat(nt,"1.3.14.")),console[p]("".concat(tn,"the style property instead: ").concat(X,"styles#style")));}// eslint-disable-next-line @typescript-eslint/no-explicit-any
},{key:"handleResponseProperty",value:function handleResponseProperty(e){return console[p]("The {result: ....} response object type".concat(nt,"1.3.0.")),console[p]("".concat(tn,"the new response object: ").concat(X,"connect#Response")),e.result;}},{key:"processHistory",value:function processHistory(e){var t=e.initialMessages;if(t)return console[p]("The initialMessages property".concat(nt,"2.0.0.")),console[p]("".concat(tn,"the history property instead: ").concat(X,"messages/#history")),t;}},{key:"processHistoryFile",value:function processHistoryFile(e){var t=e[ne];t&&(console[p]("The file property in MessageContent".concat(nt,"1.3.17.")),console[p]("".concat(tn,"the files array property: ").concat(X,"messages/#MessageContent")),e[m]=[t]);}},{key:"processValidateInput",value:function processValidateInput(e){var t=e.validateMessageBeforeSending;if(t)return console[p]("The validateMessageBeforeSending property".concat(nt,"1.3.24.")),console[p]("".concat(tn,"validateInput: ").concat(X,"interceptors#validateInput")),t;}},{key:"processSubmitUserMessage",value:function processSubmitUserMessage(e){return console[p]("The submitUserMessage(text: string) argument string type".concat(nt,"1.4.4.")),console[p]("".concat(tn,"the new argument type: ").concat(X,"methods#submitUserMessage")),_defineProperty({},h,e);}},{key:"flagHTMLUpdateClass",value:function flagHTMLUpdateClass(e){var t;(t=e.children[0])!=null&&t[f].contains("deep-chat-update-message")&&(console[p]("The \"deep-chat-update-message\" html class".concat(nt,"1.4.4.")),console[p]("".concat(tn,"using {..., overwrite: true} object: ").concat(X,"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[p]("The request property".concat(nt,"2.0.0.")),console[p]("".concat(Is,"connect object: ").concat(X,"connect#connect-1")));}},{key:"checkForStream",value:function checkForStream(e){var t=e.stream;if(t)return console[p]("The stream property".concat(Dr,"the connect object in version 2.0.0.")),console[p]("".concat(Is,"connect object: ").concat(X,"connect#connect-1")),t;}},{key:"fireOnNewMessage",value:function fireOnNewMessage(e,t){var s;var n=e;n.onNewMessage&&(console[p]("The onNewMessage event".concat(nt,"2.0.0.")),console[p]("".concat(Is,"onMessage event: ").concat(X,"events#onMessage")),(s=n.onNewMessage)==null||s.call(n,t)),e.dispatchEvent(new CustomEvent("new-message",{detail:t}));}},{key:"processFileConfigConnect",value:function processFileConfigConnect(e){var t=e;t.request&&(console[p]("The request property in file configuration".concat(nt,"2.0.0.")),console[p]("Please use the connect property instead: ".concat(X,"files")),t.connect||(t.connect=t.request));}},{key:"processMessageStyles",value:function processMessageStyles(e){if(!e)return;var t=w(e),n=t.loading;return n&&(n.outerContainer||n.innerContainer||n.bubble||n.media)&&(console[p]("The loading message styles are defined using LoadingMessageStyles interface".concat(In,"2.1.0.")),console[p]("Check it out here: ".concat(X,"messages/styles#LoadingMessageStyles")),t.loading={message:{styles:n}}),t;}},{key:"processDemo",value:function processDemo(e){return typeof e=="boolean"||e.displayLoadingBubble&&(console[p]("The demo displayLoadingBubble property".concat(nt,"2.1.0.")),console[p]("Please use displayLoading instead: ".concat(X,"modes#demo")),e.displayLoading={message:!0}),e;}},{key:"processCohere",value:function processCohere(e){var t=e,n="".concat(Is,"official documentation: ").concat(X,"directConnection/Cohere");return t.chat&&(console[p]("Cohere chat property".concat(nt,"2.2.3.")),console[p](n),delete t.chat),t.textGeneration?(console[p]("Cohere textGeneration".concat(Or,"2.2.3.")),console[p](n),delete t.textGeneration,!1):t.summarization?(console[p]("Cohere summarization".concat(Or,"2.2.3.")),console[p](n),delete t.summarization,!1):!0;}},{key:"processStreamHTMLWrappers",value:function processStreamHTMLWrappers(e){if(!e||_typeof(e)!==U)return;var t=e.htmlWrappers;if(t)return console[p]("The htmlWrappers property".concat(Dr,"Deep Chat's base").concat(In,"2.3.0.")),console[p]("Check it out here: ".concat(X,"messages/HTML#htmlWrappers")),t;}},{key:"processFocusMode",value:function processFocusMode(e){return!e||typeof e=="boolean"||e.scroll&&(console[p]("The scroll property in focusMode has been changed to smoothScroll".concat(In,"2.3.0.")),console[p]("Check it out here: ".concat(X,"modes#focusMode")),e.smoothScroll=!0),e;}},{key:"processPosition",value:function processPosition(e){if(!e)return e;var t="Position names have been updated".concat(In,"2.3.1.");return e==="inside-left"?(console[p](t),Hn):e==="inside-right"?(console[p](t),_t):e==="outside-left"?(console[p](t),Pe):e==="outside-right"?(console[p](t),ve):e;}},{key:"processBrowserStorage",value:function processBrowserStorage(e){var t=e.get();t&&Array.isArray(t)&&e.addMessages(t);}}]);}();var In=" since version ",nt=" is deprecated ".concat(In),tn="Please change to using ",Is="Please see the ",Or=" is not supported ".concat(In),Dr=" has been moved to ";var Nt=/*#__PURE__*/function(){function Nt(){_classCallCheck(this,Nt);}return _createClass(Nt,null,[{key:"mouseUp",value:function mouseUp(e,t){de.unsetAllCSSMouseStates(e,t),Object.assign(e[E],t[A]),Object.assign(e[E],t[De]);}},{key:"mouseDown",value:function mouseDown(e,t){Object.assign(e[E],t[Y]);}},{key:"mouseLeave",value:function mouseLeave(e,t){de.unsetAllCSSMouseStates(e,t),Object.assign(e[E],t[A]);}},{key:"mouseEnter",value:function mouseEnter(e,t){Object.assign(e[E],t[De]);}},{key:"add",value:function add(e,t){e.addEventListener(As,Nt.mouseEnter.bind(this,e,t)),e.addEventListener(bn,Nt.mouseLeave.bind(this,e,t)),e.addEventListener(oa,Nt.mouseDown.bind(this,e,t)),e.addEventListener(aa,Nt.mouseUp.bind(this,e,t));}}]);}();var da="deep-chat-temporary-message",ua="deep-chat-suggestion-button",Pi={"deep-chat-button":{styles:_defineProperty(_defineProperty(_defineProperty({},A,{backgroundColor:"white",padding:"5px",paddingLeft:"7px",paddingRight:"7px",border:"1px solid #c2c2c2",borderRadius:"6px",cursor:"pointer"}),De,{backgroundColor:"#fafafa"}),Y,{backgroundColor:"#f1f1f1"})}},Fr=Object.keys(Pi);var xt=/*#__PURE__*/function(){function xt(){_classCallCheck(this,xt);}return _createClass(xt,null,[{key:"applySuggestionEvent",value:function applySuggestionEvent(e,t){setTimeout(function(){t.addEventListener(Y,function(){var n,s;(s=e.submitUserMessage)==null||s.call(e,_defineProperty({},h,((n=t.textContent)==null?void 0:n.trim())||""));});});}},{key:"isElementTemporary",value:function isElementTemporary(e){var t;return e?(t=e.bubbleElement.children[0])==null?void 0:t[f].contains(da):!1;}},{key:"doesElementContainDeepChatClass",value:function doesElementContainDeepChatClass(e){return Fr.find(function(t){return e[f].contains(t);});}},{key:"applyEvents",value:function applyEvents(e,t){var n=Pi[t].events;Object.keys(n||[]).forEach(function(s){e.addEventListener(s,n==null?void 0:n[s]);});}},{key:"getProcessedStyles",value:function getProcessedStyles(e,t,n){var s=Array.from(t[f]).reduce(function(a,c){var d;var l=(d=e[c])==null?void 0:d[R];return l&&e[c][R]&&a.push(l),a;},[]),r=Pi[n][R];if(r){var a=w(r);a[A]&&de.overwriteDefaultWithAlreadyApplied(a,t),s.unshift(a);}var o=de.mergeStatefulStyles(s);return de.processStateful(o);}},{key:"applyDeepChatUtilities",value:function applyDeepChatUtilities(e,t,n){Fr.forEach(function(r){var o=n.getElementsByClassName(r);Array.from(o||[]).forEach(function(a){var c=xt.getProcessedStyles(t,a,r);re.applyStylesToElement(a,c),xt.applyEvents(a,r);});});var s=n.getElementsByClassName(ua);Array.from(s).forEach(function(r){return xt.applySuggestionEvent(e,r);});}}]);}();var re=/*#__PURE__*/function(){function re(){_classCallCheck(this,re);}return _createClass(re,null,[{key:"applyStylesToElement",value:function applyStylesToElement(e,t){var n=de.processStateful(t);Nt.add(e,n),Object.assign(e[E],n[A]);}},{key:"applyEventsToElement",value:function applyEventsToElement(e,t){Object.keys(t).forEach(function(n){var s=t[n];s&&e.addEventListener(n,s);});}},{key:"applyClassUtilitiesToElement",value:function applyClassUtilitiesToElement(e,t){var n=t.events,s=t.styles;n&&re.applyEventsToElement(e,n),s&&!xt.doesElementContainDeepChatClass(e)&&re.applyStylesToElement(e,s);}},{key:"applyCustomClassUtilities",value:function applyCustomClassUtilities(e,t){Object.keys(e).forEach(function(n){var s=t.getElementsByClassName(n);Array.from(s).forEach(function(r){e[n]&&re.applyClassUtilitiesToElement(r,e[n]);});});}},{key:"apply",value:function apply(e,t){xt.applyDeepChatUtilities(e,e.htmlClassUtilities,t),re.applyCustomClassUtilities(e.htmlClassUtilities,t);}},{key:"traverseNodes",value:function traverseNodes(e,t){e.nodeType===Node.ELEMENT_NODE&&t.push(e.outerHTML),e.childNodes.forEach(function(n){re.traverseNodes(n,t);});}},{key:"splitHTML",value:function splitHTML(e){var n=new DOMParser().parseFromString(e,"text/html"),s=[];return n.body.childNodes.forEach(function(r){re.traverseNodes(r,s);}),s;}},{key:"isTemporaryBasedOnHTML",value:function isTemporaryBasedOnHTML(e){var t=x();return t.innerHTML=e,xt.isElementTemporary({outerContainer:t,bubbleElement:t,innerContainer:t});}// useful for removing event listeners
},{key:"replaceElementWithNewClone",value:function replaceElementWithNewClone(e,t){var s;var n=(t||e).cloneNode(!0);return(s=e.parentNode)==null||s.replaceChild(n,e),n;}},{key:"tryAddWrapper",value:function tryAddWrapper(e,t,n,s){if(t&&s){var r=(n==null?void 0:n[s])||(n==null?void 0:n[A]);if(r)return e.innerHTML=r,{contentEl:re.getTargetWrapper(e),wrapper:!0};}return{contentEl:e,wrapper:!1};}},{key:"getTargetWrapper",value:function getTargetWrapper(e){return e.getElementsByClassName(Wo)[0]||e;}}]);}();var Gt=/*#__PURE__*/function(){function Gt(){_classCallCheck(this,Gt);}return _createClass(Gt,null,[{key:"createElements",value:function createElements(e,t,n,s){var r=arguments.length>4&&arguments[4]!==undefined?arguments[4]:!1;var o=e.createMessageElementsOnOrientation("",n,s,r);o.bubbleElement[f].add(Gt.HTML_BUBBLE_CLASS);var _re$tryAddWrapper=re.tryAddWrapper(o.bubbleElement,t,e._customWrappers,n),a=_re$tryAddWrapper.contentEl;return a.innerHTML=t,o;}},{key:"overwriteElements",value:function overwriteElements(e,t,n){n.bubbleElement.innerHTML=t,re.apply(e,n.outerContainer),ce.flagHTMLUpdateClass(n.bubbleElement);}// prettier-ignore
},{key:"overwrite",value:function overwrite(e,t,n,s){var r=e.messageToElements,o=O.overwriteMessage(r,s,t,n,L,Gt.HTML_BUBBLE_CLASS);return o&&Gt.overwriteElements(e,t,o),o;}},{key:"create",value:function create(e,t,n){var s=arguments.length>3&&arguments[3]!==undefined?arguments[3]:!1;var o;var r=Gt.createElements(e,t,n,s);return O.fillEmptyMessageElement(r.bubbleElement,t),re.apply(e,r.outerContainer),ce.flagHTMLUpdateClass(r.bubbleElement),e.applyCustomStyles(r,n,!1,(o=e.messageStyles)==null?void 0:o[L]),r;}},{key:"add",value:function add(e,t,n,s){var r=arguments.length>4&&arguments[4]!==undefined?arguments[4]:!1;if(s!=null&&s.status){var a=this.overwrite(e,t,n,e.messageElementRefs);if(a)return a;s.status=!1;}if(r&&e.messageElementRefs.length>0&&re.isTemporaryBasedOnHTML(t))return;var o=Gt.create(e,t,n,r);return r||e.appendOuterContainerElemet(o.outerContainer),o;}}]);}();Gt.HTML_BUBBLE_CLASS="html-message";var At=Gt;var pa=/*#__PURE__*/function(){function pa(){_classCallCheck(this,pa);}return _createClass(pa,null,[{key:"katex",value:function katex(e,t,n){var a=(n||{}).delimiter||"$";if(a.length!==1)throw new Error("invalid delimiter");var c=function c(u,g){var b;return((b=window.katex)==null?void 0:b.renderToString(u,_objectSpread({displayMode:g,throwOnError:!1,output:"mathml"},e)))||"";},l=function l(u,g,b){var _=!1,v=u.bMarks[g]+u.tShift[g],C=u.eMarks[g];if(v+1>C)return!1;var B=u[T].charAt(v);if(B!==a)return!1;var se=v;v=u.skipChars(v,B);var fe=v-se;if(fe!==2)return!1;var ie=g;for(;++ie,!(ie>=b||(v=se=u.bMarks[ie]+u.tShift[ie],C=u.eMarks[ie],v<C&&u.tShift[ie]<u.blkIndent));)if(u[T].charAt(v)===a&&!(u.tShift[ie]-u.blkIndent>=4)&&(v=u.skipChars(v,B),!(v-se<fe)&&(v=u.skipSpaces(v),!(v<C)))){_=!0;break;}fe=u.tShift[g],u.line=ie+(_?1:0);var Re=u.getLines(g+1,ie,fe,!0).replace(/[ \n]+/g," ").trim();return u.tokens.push({type:"katex",params:null,content:Re,lines:[g,u.line],level:u.level,block:!0}),!0;},d=function d(u,g){var b=u.pos,_=u.posMax;var v=b;if(u[T].charAt(v)!==a)return!1;for(++v;v<_&&u[T].charAt(v)===a;)++v;var C=u[T].slice(b,v);if(C.length>2)return!1;var B=v;var se=0;for(;v<_;){var fe=u[T].charAt(v);if(fe==="{"&&(v===0||u[T].charAt(v-1)!=="\\"))se+=1;else if(fe==="}"&&(v===0||u[T].charAt(v-1)!=="\\")){if(se-=1,se<0)return!1;}else if(fe===a&&se===0){var ie=v;var Re=v+1;for(;Re<_&&u[T].charAt(Re)===a;)++Re;if(Re-ie===C.length){if(!g){var Ht=u[T].slice(B,ie).replace(/[ \n]+/g," ").trim();u.push({type:"katex",content:Ht,block:C.length>1,level:u.level});}return u.pos=Re,!0;}}v+=1;}return g||(u.pending+=C),u.pos+=C.length,!0;};t.inline.ruler.push("katex",d,n),t.block.ruler.push("katex",l,n),t.renderer.rules.katex=function(u,g){return c(u[g].content,u[g].block);},t.renderer.rules.katex.delimiter=a;}}]);}();var Ms;function yo(i){return Ms=Ms||document.createElement("textarea"),Ms.innerHTML="&"+i+";",Ms.value;}var fa=Object.prototype.hasOwnProperty;function ma(i,e){return i?fa.call(i,e):!1;}function Eo(i){var e=[].slice.call(arguments,1);return e.forEach(function(t){if(t){if(_typeof(t)!="object")throw new TypeError(t+"must be object");Object.keys(t).forEach(function(n){i[n]=t[n];});}}),i;}var ga=/\\([\\!"#$%&'()*+,.\/:;<=>?@[\]^_`{|}~-])/g;function ps(i){return i.indexOf("\\")<0?i:i.replace(ga,"$1");}function _o(i){return!(i>=55296&&i<=57343||i>=64976&&i<=65007||(i&65535)===65535||(i&65535)===65534||i>=0&&i<=8||i===11||i>=14&&i<=31||i>=127&&i<=159||i>1114111);}function Ni(i){if(i>65535){i-=65536;var e=55296+(i>>10),t=56320+(i&1023);return String.fromCharCode(e,t);}return String.fromCharCode(i);}var ba=/&([a-z#][a-z0-9]{1,31});/gi,ya=/^#((?:x[a-f0-9]{1,8}|[0-9]{1,8}))/i;function Ea(i,e){var t=0,n=yo(e);return e!==n?n:e.charCodeAt(0)===35&&ya.test(e)&&(t=e[1].toLowerCase()==="x"?parseInt(e.slice(2),16):parseInt(e.slice(1),10),_o(t))?Ni(t):i;}function En(i){return i.indexOf("&")<0?i:i.replace(ba,Ea);}var _a=/[&<>"]/,va=/[&<>"]/g,Sa={"&":"&","<":"<",">":">",'"':"""};function xa(i){return Sa[i];}function ze(i){return _a.test(i)?i.replace(va,xa):i;}var I={};I.blockquote_open=function(){return"<blockquote>\n";};I.blockquote_close=function(i,e){return"</blockquote>"+Sn(i,e);};I.code=function(i,e){return i[e].block?"<pre><code>"+ze(i[e].content)+"</code></pre>"+Sn(i,e):"<code>"+ze(i[e].content)+"</code>";};I.fence=function(i,e,t,n,s){var r=i[e],o="",a=t.langPrefix,c="",l,d,u;if(r.params){if(l=r.params.split(/\s+/g),d=l.join(" "),ma(s.rules.fence_custom,l[0]))return s.rules.fence_custom[l[0]](i,e,t,n,s);c=ze(En(ps(d))),o=' class="'+a+c+'"';}return t.highlight?u=t.highlight.apply(t.highlight,[r.content].concat(l))||ze(r.content):u=ze(r.content),"<pre><code"+o+">"+u+"</code></pre>"+Sn(i,e);};I.fence_custom={};I.heading_open=function(i,e){return"<h"+i[e].hLevel+">";};I.heading_close=function(i,e){return"</h"+i[e].hLevel+">\n";};I.hr=function(i,e,t){return(t.xhtmlOut?"<hr />":"<hr>")+Sn(i,e);};I.bullet_list_open=function(){return"<ul>\n";};I.bullet_list_close=function(i,e){return"</ul>"+Sn(i,e);};I.list_item_open=function(){return"<li>";};I.list_item_close=function(){return"</li>\n";};I.ordered_list_open=function(i,e){var t=i[e],n=t.order>1?' start="'+t.order+'"':"";return"<ol"+n+">\n";};I.ordered_list_close=function(i,e){return"</ol>"+Sn(i,e);};I.paragraph_open=function(i,e){return i[e].tight?"":"<p>";};I.paragraph_close=function(i,e){var t=!(i[e].tight&&e&&i[e-1].type==="inline"&&!i[e-1].content);return(i[e].tight?"":"</p>")+(t?Sn(i,e):"");};I.link_open=function(i,e,t){var n=i[e].title?' title="'+ze(En(i[e].title))+'"':"",s=t.linkTarget?' target="'+t.linkTarget+'"':"";return'<a href="'+ze(i[e].href)+'"'+n+s+">";};I.link_close=function(){return"</a>";};I.image=function(i,e,t){var n=' src="'+ze(i[e].src)+'"',s=i[e].title?' title="'+ze(En(i[e].title))+'"':"",r=' alt="'+(i[e].alt?ze(En(ps(i[e].alt))):"")+'"',o=t.xhtmlOut?" /":"";return"<img"+n+r+s+o+">";};I.table_open=function(){return"<table>\n";};I.table_close=function(){return"</table>\n";};I.thead_open=function(){return"<thead>\n";};I.thead_close=function(){return"</thead>\n";};I.tbody_open=function(){return"<tbody>\n";};I.tbody_close=function(){return"</tbody>\n";};I.tr_open=function(){return"<tr>";};I.tr_close=function(){return"</tr>\n";};I.th_open=function(i,e){var t=i[e];return"<th"+(t.align?' style="text-align:'+t.align+'"':"")+">";};I.th_close=function(){return"</th>";};I.td_open=function(i,e){var t=i[e];return"<td"+(t.align?' style="text-align:'+t.align+'"':"")+">";};I.td_close=function(){return"</td>";};I.strong_open=function(){return"<strong>";};I.strong_close=function(){return"</strong>";};I.em_open=function(){return"<em>";};I.em_close=function(){return"</em>";};I.del_open=function(){return"<del>";};I.del_close=function(){return"</del>";};I.ins_open=function(){return"<ins>";};I.ins_close=function(){return"</ins>";};I.mark_open=function(){return"<mark>";};I.mark_close=function(){return"</mark>";};I.sub=function(i,e){return"<sub>"+ze(i[e].content)+"</sub>";};I.sup=function(i,e){return"<sup>"+ze(i[e].content)+"</sup>";};I.hardbreak=function(i,e,t){return t.xhtmlOut?"<br />\n":"<br>\n";};I.softbreak=function(i,e,t){return t.breaks?t.xhtmlOut?"<br />\n":"<br>\n":"\n";};I.text=function(i,e){return ze(i[e].content);};I.htmlblock=function(i,e){return i[e].content;};I.htmltag=function(i,e){return i[e].content;};I.abbr_open=function(i,e){return'<abbr title="'+ze(En(i[e].title))+'">';};I.abbr_close=function(){return"</abbr>";};I.footnote_ref=function(i,e){var t=Number(i[e].id+1).toString(),n="fnref"+t;return i[e].subId>0&&(n+=":"+i[e].subId),'<sup class="footnote-ref"><a href="#fn'+t+'" id="'+n+'">['+t+"]</a></sup>";};I.footnote_block_open=function(i,e,t){var n=t.xhtmlOut?"<hr class=\"footnotes-sep\" />\n":"<hr class=\"footnotes-sep\">\n";return n+"<section class=\"footnotes\">\n<ol class=\"footnotes-list\">\n";};I.footnote_block_close=function(){return"</ol>\n</section>\n";};I.footnote_open=function(i,e){var t=Number(i[e].id+1).toString();return'<li id="fn'+t+'" class="footnote-item">';};I.footnote_close=function(){return"</li>\n";};I.footnote_anchor=function(i,e){var t=Number(i[e].id+1).toString(),n="fnref"+t;return i[e].subId>0&&(n+=":"+i[e].subId),' <a href="#'+n+'" class="footnote-backref">↩</a>';};I.dl_open=function(){return"<dl>\n";};I.dt_open=function(){return"<dt>";};I.dd_open=functio