UNPKG

@guialvess/chat-widget

Version:

A customizable chat widget built with Preact

32 lines (31 loc) 26.2 kB
(function(S,E){typeof exports=="object"&&typeof module<"u"?E(exports):typeof define=="function"&&define.amd?define(["exports"],E):(S=typeof globalThis<"u"?globalThis:S||self,E(S.ChatWidget={}))})(this,function(S){"use strict";var E,f,le,A,ae,ce,se,ue,X,J,Q,L={},fe=[],nt=/acit|ex(?:s|g|n|p|$)|rph|grid|ows|mnc|ntw|ine[ch]|zoo|^ord|itera/i,I=Array.isArray;function N(e,t){for(var _ in t)e[_]=t[_];return e}function Y(e){e&&e.parentNode&&e.parentNode.removeChild(e)}function U(e,t,_){var n,o,r,l={};for(r in t)r=="key"?n=t[r]:r=="ref"?o=t[r]:l[r]=t[r];if(arguments.length>2&&(l.children=arguments.length>3?E.call(arguments,2):_),typeof e=="function"&&e.defaultProps!=null)for(r in e.defaultProps)l[r]===void 0&&(l[r]=e.defaultProps[r]);return z(e,l,n,o,null)}function z(e,t,_,n,o){var r={type:e,props:t,key:_,ref:n,__k:null,__:null,__b:0,__e:null,__c:null,constructor:void 0,__v:o??++le,__i:-1,__u:0};return o==null&&f.vnode!=null&&f.vnode(r),r}function T(e){return e.children}function P(e,t){this.props=e,this.context=t}function O(e,t){if(t==null)return e.__?O(e.__,e.__i+1):null;for(var _;t<e.__k.length;t++)if((_=e.__k[t])!=null&&_.__e!=null)return _.__e;return typeof e.type=="function"?O(e):null}function de(e){var t,_;if((e=e.__)!=null&&e.__c!=null){for(e.__e=e.__c.base=null,t=0;t<e.__k.length;t++)if((_=e.__k[t])!=null&&_.__e!=null){e.__e=e.__c.base=_.__e;break}return de(e)}}function pe(e){(!e.__d&&(e.__d=!0)&&A.push(e)&&!F.__r++||ae!=f.debounceRendering)&&((ae=f.debounceRendering)||ce)(F)}function F(){for(var e,t,_,n,o,r,l,a=1;A.length;)A.length>a&&A.sort(se),e=A.shift(),a=A.length,e.__d&&(_=void 0,o=(n=(t=e).__v).__e,r=[],l=[],t.__P&&((_=N({},n)).__v=n.__v+1,f.vnode&&f.vnode(_),ee(t.__P,_,n,t.__n,t.__P.namespaceURI,32&n.__u?[o]:null,r,o??O(n),!!(32&n.__u),l),_.__v=n.__v,_.__.__k[_.__i]=_,be(r,_,l),_.__e!=o&&de(_)));F.__r=0}function he(e,t,_,n,o,r,l,a,s,c,d){var i,p,u,g,w,k,m=n&&n.__k||fe,h=t.length;for(s=ot(_,t,m,s,h),i=0;i<h;i++)(u=_.__k[i])!=null&&(p=u.__i==-1?L:m[u.__i]||L,u.__i=i,k=ee(e,u,p,o,r,l,a,s,c,d),g=u.__e,u.ref&&p.ref!=u.ref&&(p.ref&&te(p.ref,null,u),d.push(u.ref,u.__c||g,u)),w==null&&g!=null&&(w=g),4&u.__u||p.__k===u.__k?s=me(u,s,e):typeof u.type=="function"&&k!==void 0?s=k:g&&(s=g.nextSibling),u.__u&=-7);return _.__e=w,s}function ot(e,t,_,n,o){var r,l,a,s,c,d=_.length,i=d,p=0;for(e.__k=new Array(o),r=0;r<o;r++)(l=t[r])!=null&&typeof l!="boolean"&&typeof l!="function"?(s=r+p,(l=e.__k[r]=typeof l=="string"||typeof l=="number"||typeof l=="bigint"||l.constructor==String?z(null,l,null,null,null):I(l)?z(T,{children:l},null,null,null):l.constructor==null&&l.__b>0?z(l.type,l.props,l.key,l.ref?l.ref:null,l.__v):l).__=e,l.__b=e.__b+1,a=null,(c=l.__i=rt(l,_,s,i))!=-1&&(i--,(a=_[c])&&(a.__u|=2)),a==null||a.__v==null?(c==-1&&(o>d?p--:o<d&&p++),typeof l.type!="function"&&(l.__u|=4)):c!=s&&(c==s-1?p--:c==s+1?p++:(c>s?p--:p++,l.__u|=4))):e.__k[r]=null;if(i)for(r=0;r<d;r++)(a=_[r])!=null&&!(2&a.__u)&&(a.__e==n&&(n=O(a)),ke(a,a));return n}function me(e,t,_){var n,o;if(typeof e.type=="function"){for(n=e.__k,o=0;n&&o<n.length;o++)n[o]&&(n[o].__=e,t=me(n[o],t,_));return t}e.__e!=t&&(t&&e.type&&!_.contains(t)&&(t=O(e)),_.insertBefore(e.__e,t||null),t=e.__e);do t=t&&t.nextSibling;while(t!=null&&t.nodeType==8);return t}function B(e,t){return t=t||[],e==null||typeof e=="boolean"||(I(e)?e.some(function(_){B(_,t)}):t.push(e)),t}function rt(e,t,_,n){var o,r,l=e.key,a=e.type,s=t[_];if(s===null&&e.key==null||s&&l==s.key&&a==s.type&&!(2&s.__u))return _;if(n>(s!=null&&!(2&s.__u)?1:0))for(o=_-1,r=_+1;o>=0||r<t.length;){if(o>=0){if((s=t[o])&&!(2&s.__u)&&l==s.key&&a==s.type)return o;o--}if(r<t.length){if((s=t[r])&&!(2&s.__u)&&l==s.key&&a==s.type)return r;r++}}return-1}function ve(e,t,_){t[0]=="-"?e.setProperty(t,_??""):e[t]=_==null?"":typeof _!="number"||nt.test(t)?_:_+"px"}function V(e,t,_,n,o){var r,l;e:if(t=="style")if(typeof _=="string")e.style.cssText=_;else{if(typeof n=="string"&&(e.style.cssText=n=""),n)for(t in n)_&&t in _||ve(e.style,t,"");if(_)for(t in _)n&&_[t]==n[t]||ve(e.style,t,_[t])}else if(t[0]=="o"&&t[1]=="n")r=t!=(t=t.replace(ue,"$1")),l=t.toLowerCase(),t=l in e||t=="onFocusOut"||t=="onFocusIn"?l.slice(2):t.slice(2),e.l||(e.l={}),e.l[t+r]=_,_?n?_.u=n.u:(_.u=X,e.addEventListener(t,r?Q:J,r)):e.removeEventListener(t,r?Q:J,r);else{if(o=="http://www.w3.org/2000/svg")t=t.replace(/xlink(H|:h)/,"h").replace(/sName$/,"s");else if(t!="width"&&t!="height"&&t!="href"&&t!="list"&&t!="form"&&t!="tabIndex"&&t!="download"&&t!="rowSpan"&&t!="colSpan"&&t!="role"&&t!="popover"&&t in e)try{e[t]=_??"";break e}catch{}typeof _=="function"||(_==null||_===!1&&t[4]!="-"?e.removeAttribute(t):e.setAttribute(t,t=="popover"&&_==1?"":_))}}function ye(e){return function(t){if(this.l){var _=this.l[t.type+e];if(t.t==null)t.t=X++;else if(t.t<_.u)return;return _(f.event?f.event(t):t)}}}function ee(e,t,_,n,o,r,l,a,s,c){var d,i,p,u,g,w,k,m,h,C,x,W,H,_t,K,R,ie,$=t.type;if(t.constructor!=null)return null;128&_.__u&&(s=!!(32&_.__u),r=[a=t.__e=_.__e]),(d=f.__b)&&d(t);e:if(typeof $=="function")try{if(m=t.props,h="prototype"in $&&$.prototype.render,C=(d=$.contextType)&&n[d.__c],x=d?C?C.props.value:d.__:n,_.__c?k=(i=t.__c=_.__c).__=i.__E:(h?t.__c=i=new $(m,x):(t.__c=i=new P(m,x),i.constructor=$,i.render=lt),C&&C.sub(i),i.props=m,i.state||(i.state={}),i.context=x,i.__n=n,p=i.__d=!0,i.__h=[],i._sb=[]),h&&i.__s==null&&(i.__s=i.state),h&&$.getDerivedStateFromProps!=null&&(i.__s==i.state&&(i.__s=N({},i.__s)),N(i.__s,$.getDerivedStateFromProps(m,i.__s))),u=i.props,g=i.state,i.__v=t,p)h&&$.getDerivedStateFromProps==null&&i.componentWillMount!=null&&i.componentWillMount(),h&&i.componentDidMount!=null&&i.__h.push(i.componentDidMount);else{if(h&&$.getDerivedStateFromProps==null&&m!==u&&i.componentWillReceiveProps!=null&&i.componentWillReceiveProps(m,x),!i.__e&&i.shouldComponentUpdate!=null&&i.shouldComponentUpdate(m,i.__s,x)===!1||t.__v==_.__v){for(t.__v!=_.__v&&(i.props=m,i.state=i.__s,i.__d=!1),t.__e=_.__e,t.__k=_.__k,t.__k.some(function(j){j&&(j.__=t)}),W=0;W<i._sb.length;W++)i.__h.push(i._sb[W]);i._sb=[],i.__h.length&&l.push(i);break e}i.componentWillUpdate!=null&&i.componentWillUpdate(m,i.__s,x),h&&i.componentDidUpdate!=null&&i.__h.push(function(){i.componentDidUpdate(u,g,w)})}if(i.context=x,i.props=m,i.__P=e,i.__e=!1,H=f.__r,_t=0,h){for(i.state=i.__s,i.__d=!1,H&&H(t),d=i.render(i.props,i.state,i.context),K=0;K<i._sb.length;K++)i.__h.push(i._sb[K]);i._sb=[]}else do i.__d=!1,H&&H(t),d=i.render(i.props,i.state,i.context),i.state=i.__s;while(i.__d&&++_t<25);i.state=i.__s,i.getChildContext!=null&&(n=N(N({},n),i.getChildContext())),h&&!p&&i.getSnapshotBeforeUpdate!=null&&(w=i.getSnapshotBeforeUpdate(u,g)),R=d,d!=null&&d.type===T&&d.key==null&&(R=ge(d.props.children)),a=he(e,I(R)?R:[R],t,_,n,o,r,l,a,s,c),i.base=t.__e,t.__u&=-161,i.__h.length&&l.push(i),k&&(i.__E=i.__=null)}catch(j){if(t.__v=null,s||r!=null)if(j.then){for(t.__u|=s?160:128;a&&a.nodeType==8&&a.nextSibling;)a=a.nextSibling;r[r.indexOf(a)]=null,t.__e=a}else for(ie=r.length;ie--;)Y(r[ie]);else t.__e=_.__e,t.__k=_.__k;f.__e(j,t,_)}else r==null&&t.__v==_.__v?(t.__k=_.__k,t.__e=_.__e):a=t.__e=it(_.__e,t,_,n,o,r,l,s,c);return(d=f.diffed)&&d(t),128&t.__u?void 0:a}function be(e,t,_){for(var n=0;n<_.length;n++)te(_[n],_[++n],_[++n]);f.__c&&f.__c(t,e),e.some(function(o){try{e=o.__h,o.__h=[],e.some(function(r){r.call(o)})}catch(r){f.__e(r,o.__v)}})}function ge(e){return typeof e!="object"||e==null||e.__b&&e.__b>0?e:I(e)?e.map(ge):N({},e)}function it(e,t,_,n,o,r,l,a,s){var c,d,i,p,u,g,w,k=_.props,m=t.props,h=t.type;if(h=="svg"?o="http://www.w3.org/2000/svg":h=="math"?o="http://www.w3.org/1998/Math/MathML":o||(o="http://www.w3.org/1999/xhtml"),r!=null){for(c=0;c<r.length;c++)if((u=r[c])&&"setAttribute"in u==!!h&&(h?u.localName==h:u.nodeType==3)){e=u,r[c]=null;break}}if(e==null){if(h==null)return document.createTextNode(m);e=document.createElementNS(o,h,m.is&&m),a&&(f.__m&&f.__m(t,r),a=!1),r=null}if(h==null)k===m||a&&e.data==m||(e.data=m);else{if(r=r&&E.call(e.childNodes),k=_.props||L,!a&&r!=null)for(k={},c=0;c<e.attributes.length;c++)k[(u=e.attributes[c]).name]=u.value;for(c in k)if(u=k[c],c!="children"){if(c=="dangerouslySetInnerHTML")i=u;else if(!(c in m)){if(c=="value"&&"defaultValue"in m||c=="checked"&&"defaultChecked"in m)continue;V(e,c,null,u,o)}}for(c in m)u=m[c],c=="children"?p=u:c=="dangerouslySetInnerHTML"?d=u:c=="value"?g=u:c=="checked"?w=u:a&&typeof u!="function"||k[c]===u||V(e,c,u,k[c],o);if(d)a||i&&(d.__html==i.__html||d.__html==e.innerHTML)||(e.innerHTML=d.__html),t.__k=[];else if(i&&(e.innerHTML=""),he(t.type=="template"?e.content:e,I(p)?p:[p],t,_,n,h=="foreignObject"?"http://www.w3.org/1999/xhtml":o,r,l,r?r[0]:_.__k&&O(_,0),a,s),r!=null)for(c=r.length;c--;)Y(r[c]);a||(c="value",h=="progress"&&g==null?e.removeAttribute("value"):g!=null&&(g!==e[c]||h=="progress"&&!g||h=="option"&&g!=k[c])&&V(e,c,g,k[c],o),c="checked",w!=null&&w!=e[c]&&V(e,c,w,k[c],o))}return e}function te(e,t,_){try{if(typeof e=="function"){var n=typeof e.__u=="function";n&&e.__u(),n&&t==null||(e.__u=e(t))}else e.current=t}catch(o){f.__e(o,_)}}function ke(e,t,_){var n,o;if(f.unmount&&f.unmount(e),(n=e.ref)&&(n.current&&n.current!=e.__e||te(n,null,t)),(n=e.__c)!=null){if(n.componentWillUnmount)try{n.componentWillUnmount()}catch(r){f.__e(r,t)}n.base=n.__P=null}if(n=e.__k)for(o=0;o<n.length;o++)n[o]&&ke(n[o],t,_||typeof e.type!="function");_||Y(e.__e),e.__c=e.__=e.__e=void 0}function lt(e,t,_){return this.constructor(e,_)}function at(e,t,_){var n,o,r,l;t==document&&(t=document.documentElement),f.__&&f.__(e,t),o=(n=typeof _=="function")?null:_&&_.__k||t.__k,r=[],l=[],ee(t,e=(!n&&_||t).__k=U(T,null,[e]),o||L,L,t.namespaceURI,!n&&_?[_]:o?null:t.firstChild?E.call(t.childNodes):null,r,!n&&_?_:o?o.__e:t.firstChild,n,l),be(r,e,l)}E=fe.slice,f={__e:function(e,t,_,n){for(var o,r,l;t=t.__;)if((o=t.__c)&&!o.__)try{if((r=o.constructor)&&r.getDerivedStateFromError!=null&&(o.setState(r.getDerivedStateFromError(e)),l=o.__d),o.componentDidCatch!=null&&(o.componentDidCatch(e,n||{}),l=o.__d),l)return o.__E=o}catch(a){e=a}throw e}},le=0,P.prototype.setState=function(e,t){var _;_=this.__s!=null&&this.__s!=this.state?this.__s:this.__s=N({},this.state),typeof e=="function"&&(e=e(N({},_),this.props)),e&&N(_,e),e!=null&&this.__v&&(t&&this._sb.push(t),pe(this))},P.prototype.forceUpdate=function(e){this.__v&&(this.__e=!0,e&&this.__h.push(e),pe(this))},P.prototype.render=T,A=[],ce=typeof Promise=="function"?Promise.prototype.then.bind(Promise.resolve()):setTimeout,se=function(e,t){return e.__v.__b-t.__v.__b},F.__r=0,ue=/(PointerCapture)$|Capture$/i,X=0,J=ye(!1),Q=ye(!0);var D,y,_e,we,q=0,Ce=[],b=f,xe=b.__b,$e=b.__r,Ne=b.diffed,Pe=b.__c,Se=b.unmount,Ee=b.__;function ne(e,t){b.__h&&b.__h(y,e,q||t),q=0;var _=y.__H||(y.__H={__:[],__h:[]});return e>=_.__.length&&_.__.push({}),_.__[e]}function He(e){return q=1,ct(Ue,e)}function ct(e,t,_){var n=ne(D++,2);if(n.t=e,!n.__c&&(n.__=[_?_(t):Ue(void 0,t),function(a){var s=n.__N?n.__N[0]:n.__[0],c=n.t(s,a);s!==c&&(n.__N=[c,n.__[1]],n.__c.setState({}))}],n.__c=y,!y.__f)){var o=function(a,s,c){if(!n.__c.__H)return!0;var d=n.__c.__H.__.filter(function(p){return!!p.__c});if(d.every(function(p){return!p.__N}))return!r||r.call(this,a,s,c);var i=n.__c.props!==a;return d.forEach(function(p){if(p.__N){var u=p.__[0];p.__=p.__N,p.__N=void 0,u!==p.__[0]&&(i=!0)}}),r&&r.call(this,a,s,c)||i};y.__f=!0;var r=y.shouldComponentUpdate,l=y.componentWillUpdate;y.componentWillUpdate=function(a,s,c){if(this.__e){var d=r;r=void 0,o(a,s,c),r=d}l&&l.call(this,a,s,c)},y.shouldComponentUpdate=o}return n.__N||n.__}function Ae(e,t){var _=ne(D++,3);!b.__s&&We(_.__H,t)&&(_.__=e,_.u=t,y.__H.__h.push(_))}function st(e){return q=5,ut(function(){return{current:e}},[])}function ut(e,t){var _=ne(D++,7);return We(_.__H,t)&&(_.__=e(),_.__H=t,_.__h=e),_.__}function ft(){for(var e;e=Ce.shift();)if(e.__P&&e.__H)try{e.__H.__h.forEach(Z),e.__H.__h.forEach(oe),e.__H.__h=[]}catch(t){e.__H.__h=[],b.__e(t,e.__v)}}b.__b=function(e){y=null,xe&&xe(e)},b.__=function(e,t){e&&t.__k&&t.__k.__m&&(e.__m=t.__k.__m),Ee&&Ee(e,t)},b.__r=function(e){$e&&$e(e),D=0;var t=(y=e.__c).__H;t&&(_e===y?(t.__h=[],y.__h=[],t.__.forEach(function(_){_.__N&&(_.__=_.__N),_.u=_.__N=void 0})):(t.__h.forEach(Z),t.__h.forEach(oe),t.__h=[],D=0)),_e=y},b.diffed=function(e){Ne&&Ne(e);var t=e.__c;t&&t.__H&&(t.__H.__h.length&&(Ce.push(t)!==1&&we===b.requestAnimationFrame||((we=b.requestAnimationFrame)||dt)(ft)),t.__H.__.forEach(function(_){_.u&&(_.__H=_.u),_.u=void 0})),_e=y=null},b.__c=function(e,t){t.some(function(_){try{_.__h.forEach(Z),_.__h=_.__h.filter(function(n){return!n.__||oe(n)})}catch(n){t.some(function(o){o.__h&&(o.__h=[])}),t=[],b.__e(n,_.__v)}}),Pe&&Pe(e,t)},b.unmount=function(e){Se&&Se(e);var t,_=e.__c;_&&_.__H&&(_.__H.__.forEach(function(n){try{Z(n)}catch(o){t=o}}),_.__H=void 0,t&&b.__e(t,_.__v))};var Me=typeof requestAnimationFrame=="function";function dt(e){var t,_=function(){clearTimeout(n),Me&&cancelAnimationFrame(t),setTimeout(e)},n=setTimeout(_,35);Me&&(t=requestAnimationFrame(_))}function Z(e){var t=y,_=e.__c;typeof _=="function"&&(e.__c=void 0,_()),y=t}function oe(e){var t=y;e.__c=e.__(),y=t}function We(e,t){return!e||e.length!==t.length||t.some(function(_,n){return _!==e[n]})}function Ue(e,t){return typeof t=="function"?t(e):t}function Te(e,t){for(var _ in t)e[_]=t[_];return e}function Oe(e,t){for(var _ in e)if(_!=="__source"&&!(_ in t))return!0;for(var n in t)if(n!=="__source"&&e[n]!==t[n])return!0;return!1}function Le(e,t){this.props=e,this.context=t}(Le.prototype=new P).isPureReactComponent=!0,Le.prototype.shouldComponentUpdate=function(e,t){return Oe(this.props,e)||Oe(this.state,t)};var Ie=f.__b;f.__b=function(e){e.type&&e.type.__f&&e.ref&&(e.props.ref=e.ref,e.ref=null),Ie&&Ie(e)};var pt=typeof Symbol<"u"&&Symbol.for&&Symbol.for("react.forward_ref")||3911;function De(e){function t(_){var n=Te({},_);return delete n.ref,e(n,_.ref||null)}return t.$$typeof=pt,t.render=t,t.prototype.isReactComponent=t.__f=!0,t.displayName="ForwardRef("+(e.displayName||e.name)+")",t}var ht=f.__e;f.__e=function(e,t,_,n){if(e.then){for(var o,r=t;r=r.__;)if((o=r.__c)&&o.__c)return t.__e==null&&(t.__e=_.__e,t.__k=_.__k),o.__c(e,t)}ht(e,t,_,n)};var Re=f.unmount;function je(e,t,_){return e&&(e.__c&&e.__c.__H&&(e.__c.__H.__.forEach(function(n){typeof n.__c=="function"&&n.__c()}),e.__c.__H=null),(e=Te({},e)).__c!=null&&(e.__c.__P===_&&(e.__c.__P=t),e.__c.__e=!0,e.__c=null),e.__k=e.__k&&e.__k.map(function(n){return je(n,t,_)})),e}function ze(e,t,_){return e&&_&&(e.__v=null,e.__k=e.__k&&e.__k.map(function(n){return ze(n,t,_)}),e.__c&&e.__c.__P===t&&(e.__e&&_.appendChild(e.__e),e.__c.__e=!0,e.__c.__P=_)),e}function re(){this.__u=0,this.o=null,this.__b=null}function Fe(e){var t=e.__.__c;return t&&t.__a&&t.__a(e)}function G(){this.i=null,this.l=null}f.unmount=function(e){var t=e.__c;t&&t.__R&&t.__R(),t&&32&e.__u&&(e.type=null),Re&&Re(e)},(re.prototype=new P).__c=function(e,t){var _=t.__c,n=this;n.o==null&&(n.o=[]),n.o.push(_);var o=Fe(n.__v),r=!1,l=function(){r||(r=!0,_.__R=null,o?o(a):a())};_.__R=l;var a=function(){if(!--n.__u){if(n.state.__a){var s=n.state.__a;n.__v.__k[0]=ze(s,s.__c.__P,s.__c.__O)}var c;for(n.setState({__a:n.__b=null});c=n.o.pop();)c.forceUpdate()}};n.__u++||32&t.__u||n.setState({__a:n.__b=n.__v.__k[0]}),e.then(l,l)},re.prototype.componentWillUnmount=function(){this.o=[]},re.prototype.render=function(e,t){if(this.__b){if(this.__v.__k){var _=document.createElement("div"),n=this.__v.__k[0].__c;this.__v.__k[0]=je(this.__b,_,n.__O=n.__P)}this.__b=null}var o=t.__a&&U(T,null,e.fallback);return o&&(o.__u&=-33),[U(T,null,t.__a?null:e.children),o]};var Be=function(e,t,_){if(++_[1]===_[0]&&e.l.delete(t),e.props.revealOrder&&(e.props.revealOrder[0]!=="t"||!e.l.size))for(_=e.i;_;){for(;_.length>3;)_.pop()();if(_[1]<_[0])break;e.i=_=_[2]}};(G.prototype=new P).__a=function(e){var t=this,_=Fe(t.__v),n=t.l.get(e);return n[0]++,function(o){var r=function(){t.props.revealOrder?(n.push(o),Be(t,e,n)):o()};_?_(r):r()}},G.prototype.render=function(e){this.i=null,this.l=new Map;var t=B(e.children);e.revealOrder&&e.revealOrder[0]==="b"&&t.reverse();for(var _=t.length;_--;)this.l.set(t[_],this.i=[1,0,this.i]);return e.children},G.prototype.componentDidUpdate=G.prototype.componentDidMount=function(){var e=this;this.l.forEach(function(t,_){Be(e,_,t)})};var mt=typeof Symbol<"u"&&Symbol.for&&Symbol.for("react.element")||60103,vt=/^(?:accent|alignment|arabic|baseline|cap|clip(?!PathU)|color|dominant|fill|flood|font|glyph(?!R)|horiz|image(!S)|letter|lighting|marker(?!H|W|U)|overline|paint|pointer|shape|stop|strikethrough|stroke|text(?!L)|transform|underline|unicode|units|v|vector|vert|word|writing|x(?!C))[A-Z]/,yt=/^on(Ani|Tra|Tou|BeforeInp|Compo)/,bt=/[A-Z0-9]/g,gt=typeof document<"u",kt=function(e){return(typeof Symbol<"u"&&typeof Symbol()=="symbol"?/fil|che|rad/:/fil|che|ra/).test(e)};P.prototype.isReactComponent={},["componentWillMount","componentWillReceiveProps","componentWillUpdate"].forEach(function(e){Object.defineProperty(P.prototype,e,{configurable:!0,get:function(){return this["UNSAFE_"+e]},set:function(t){Object.defineProperty(this,e,{configurable:!0,writable:!0,value:t})}})});var Ve=f.event;function wt(){}function Ct(){return this.cancelBubble}function xt(){return this.defaultPrevented}f.event=function(e){return Ve&&(e=Ve(e)),e.persist=wt,e.isPropagationStopped=Ct,e.isDefaultPrevented=xt,e.nativeEvent=e};var $t={enumerable:!1,configurable:!0,get:function(){return this.class}},qe=f.vnode;f.vnode=function(e){typeof e.type=="string"&&function(t){var _=t.props,n=t.type,o={},r=n.indexOf("-")===-1;for(var l in _){var a=_[l];if(!(l==="value"&&"defaultValue"in _&&a==null||gt&&l==="children"&&n==="noscript"||l==="class"||l==="className")){var s=l.toLowerCase();l==="defaultValue"&&"value"in _&&_.value==null?l="value":l==="download"&&a===!0?a="":s==="translate"&&a==="no"?a=!1:s[0]==="o"&&s[1]==="n"?s==="ondoubleclick"?l="ondblclick":s!=="onchange"||n!=="input"&&n!=="textarea"||kt(_.type)?s==="onfocus"?l="onfocusin":s==="onblur"?l="onfocusout":yt.test(l)&&(l=s):s=l="oninput":r&&vt.test(l)?l=l.replace(bt,"-$&").toLowerCase():a===null&&(a=void 0),s==="oninput"&&o[l=s]&&(l="oninputCapture"),o[l]=a}}n=="select"&&o.multiple&&Array.isArray(o.value)&&(o.value=B(_.children).forEach(function(c){c.props.selected=o.value.indexOf(c.props.value)!=-1})),n=="select"&&o.defaultValue!=null&&(o.value=B(_.children).forEach(function(c){c.props.selected=o.multiple?o.defaultValue.indexOf(c.props.value)!=-1:o.defaultValue==c.props.value})),_.class&&!_.className?(o.class=_.class,Object.defineProperty(o,"className",$t)):(_.className&&!_.class||_.class&&_.className)&&(o.class=o.className=_.className),t.props=o}(e),e.$$typeof=mt,qe&&qe(e)};var Ze=f.__r;f.__r=function(e){Ze&&Ze(e),e.__c};var Ge=f.diffed;f.diffed=function(e){Ge&&Ge(e);var t=e.props,_=e.__e;_!=null&&e.type==="textarea"&&"value"in t&&t.value!==_.value&&(_.value=t.value==null?"":t.value)};/** * @license lucide-react v0.525.0 - ISC * * This source code is licensed under the ISC license. * See the LICENSE file in the root directory of this source tree. */const Nt=e=>e.replace(/([a-z0-9])([A-Z])/g,"$1-$2").toLowerCase(),Pt=e=>e.replace(/^([A-Z])|[\s-_]+(\w)/g,(t,_,n)=>n?n.toUpperCase():_.toLowerCase()),Ke=e=>{const t=Pt(e);return t.charAt(0).toUpperCase()+t.slice(1)},Xe=(...e)=>e.filter((t,_,n)=>!!t&&t.trim()!==""&&n.indexOf(t)===_).join(" ").trim(),St=e=>{for(const t in e)if(t.startsWith("aria-")||t==="role"||t==="title")return!0};/** * @license lucide-react v0.525.0 - ISC * * This source code is licensed under the ISC license. * See the LICENSE file in the root directory of this source tree. */var Et={xmlns:"http://www.w3.org/2000/svg",width:24,height:24,viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:2,strokeLinecap:"round",strokeLinejoin:"round"};/** * @license lucide-react v0.525.0 - ISC * * This source code is licensed under the ISC license. * See the LICENSE file in the root directory of this source tree. */const Ht=De(({color:e="currentColor",size:t=24,strokeWidth:_=2,absoluteStrokeWidth:n,className:o="",children:r,iconNode:l,...a},s)=>U("svg",{ref:s,...Et,width:t,height:t,stroke:e,strokeWidth:n?Number(_)*24/Number(t):_,className:Xe("lucide",o),...!r&&!St(a)&&{"aria-hidden":"true"},...a},[...l.map(([c,d])=>U(c,d)),...Array.isArray(r)?r:[r]]));/** * @license lucide-react v0.525.0 - ISC * * This source code is licensed under the ISC license. * See the LICENSE file in the root directory of this source tree. */const Je=(e,t)=>{const _=De(({className:n,...o},r)=>U(Ht,{ref:r,iconNode:t,className:Xe(`lucide-${Nt(Ke(e))}`,`lucide-${e}`,n),...o}));return _.displayName=Ke(e),_};/** * @license lucide-react v0.525.0 - ISC * * This source code is licensed under the ISC license. * See the LICENSE file in the root directory of this source tree. */const At=Je("minimize-2",[["path",{d:"m14 10 7-7",key:"oa77jy"}],["path",{d:"M20 10h-6V4",key:"mjg0md"}],["path",{d:"m3 21 7-7",key:"tjx5ai"}],["path",{d:"M4 14h6v6",key:"rmj7iw"}]]);/** * @license lucide-react v0.525.0 - ISC * * This source code is licensed under the ISC license. * See the LICENSE file in the root directory of this source tree. */const Mt=Je("x",[["path",{d:"M18 6 6 18",key:"1bl5f8"}],["path",{d:"m6 6 12 12",key:"d8bk6v"}]]);var Wt=0;function v(e,t,_,n,o,r){t||(t={});var l,a,s=t;if("ref"in s)for(a in s={},t)a=="ref"?l=t[a]:s[a]=t[a];var c={type:e,props:s,key:_,ref:l,__k:null,__:null,__b:0,__e:null,__c:null,constructor:void 0,__v:--Wt,__i:-1,__u:0,__source:o,__self:r};if(typeof e=="function"&&(l=e.defaultProps))for(a in l)s[a]===void 0&&(s[a]=l[a]);return f.vnode&&f.vnode(c),c}const Qe=({size:e=32})=>v("svg",{width:e,height:e,viewBox:"0 0 24 24",fill:"none",xmlns:"http://www.w3.org/2000/svg",children:[v("path",{d:"M12 2C17.523 2 22 6.477 22 12C22 17.523 17.523 22 12 22C10.298 22 8.685 21.575 7.26 20.82L2 22L3.18 16.74C2.425 15.315 2 13.702 2 12C2 6.477 6.477 2 12 2Z",fill:"currentColor",fillRule:"evenodd",clipRule:"evenodd"}),v("circle",{cx:"8",cy:"12",r:"1.5",fill:"white",fillOpacity:"0.9"}),v("circle",{cx:"12",cy:"12",r:"1.5",fill:"white",fillOpacity:"0.9"}),v("circle",{cx:"16",cy:"12",r:"1.5",fill:"white",fillOpacity:"0.9"})]});function Ut({config:e}){const[t,_]=He(!1),[n,o]=He(!1),r=e.position??"bottom-right",l=e.theme??"dark",a=e.width??384,s=e.height??600,d=`http://localhost:5173/widgets?theme=${l}&flowId=688389642e4b04b550bc269c`,i=st(null),p={"bottom-right":"bottom-6 right-6","bottom-left":"bottom-6 left-6","top-right":"top-6 right-6","top-left":"top-6 left-6"};Ae(()=>{i.current&&i.current.setAttribute("allowtransparency","true")},[]),Ae(()=>{const C=x=>{var W,H;((W=x.data)==null?void 0:W.type)==="WIDGET_MINIMIZE"&&o(x.data.minimized),((H=x.data)==null?void 0:H.type)==="WIDGET_CLOSE"&&(_(!1),o(!1))};return window.addEventListener("message",C),()=>window.removeEventListener("message",C)},[]);const u=C=>typeof C=="number"?`${C}px`:C,g=()=>{_(!0),o(!1)},w=()=>{_(!1),o(!1)},k=()=>o(!0),m=()=>o(!1),h={width:"60px",height:"60px",background:`linear-gradient(135deg, ${e.primaryColor??"#374151"} 0%, ${e.primaryColor??"#4b5563"}dd 100%)`,color:"#fff",border:"none",cursor:"pointer",borderRadius:"50%"};return t?n?v("button",{onClick:m,className:`fixed ${p[r]} flex items-center justify-center transition-transform duration-300 ease-out hover:scale-110 active:scale-95 z-50`,style:h,"aria-label":"Maximizar chat",children:v(Qe,{size:32})}):v("div",{className:`fixed ${p[r]} flex flex-col z-50`,style:{width:u(a),height:u(s),borderRadius:12,overflow:"hidden",backgroundColor:l==="dark"?"#1f2937":"#f3f4f6",border:l==="dark"?"1px solid #374151":"1px solid #d1d5db",boxShadow:"none"},role:"dialog","aria-modal":"true",children:[v("header",{className:"flex items-center justify-between px-5",style:{background:l==="dark"?"#111827":"#e5e7eb",borderBottom:l==="dark"?"1px solid #4b5563":"1px solid #d1d5db",color:l==="dark"?"#e0e7ff":"#374151",minHeight:56},children:[v("div",{className:"flex items-center gap-3",children:[v("div",{className:"w-3 h-3 rounded-full",style:{background:e.primaryColor??(l==="dark"?"#2563eb":"#3b82f6")}}),v("span",{className:"font-semibold text-sm tracking-tight",children:e.title})]}),v("div",{className:"flex items-center gap-1",children:[v("button",{onClick:k,className:"p-2 rounded hover:bg-gray-700",style:{color:l==="dark"?"#cbd5e1":"#4b5563",backgroundColor:"transparent",border:"none",cursor:"pointer"},"aria-label":"Minimizar",children:v(At,{size:16})}),v("button",{onClick:w,className:"p-2 rounded hover:bg-gray-700",style:{color:l==="dark"?"#cbd5e1":"#4b5563",backgroundColor:"transparent",border:"none",cursor:"pointer"},"aria-label":"Fechar",children:v(Mt,{size:16})})]})]}),v("main",{className:"flex-1 overflow-hidden",children:v("iframe",{ref:i,src:d,title:"Chat",className:"w-full h-full border-0 block",style:{backgroundColor:"transparent",display:"block"},allow:"microphone; camera",sandbox:"allow-scripts allow-same-origin allow-forms allow-popups",loading:"lazy"})})]}):v("button",{onClick:g,className:`fixed ${p[r]} flex items-center justify-center transition-transform duration-300 ease-out hover:scale-110 active:scale-95 z-50`,style:h,"aria-label":"Abrir chat",children:v(Qe,{size:32})})}const Lt="",M=new Map;function Ye(e={title:"Default Widget Title"}){const t=e.id||"default-widget",_=M.get(t);_&&document.body.contains(_)&&document.body.removeChild(_);const n=document.createElement("div");return n.id=`chat-widget-${t}`,n.className="chat-widget-container",document.body.appendChild(n),M.set(t,n),at(v(Ut,{config:e}),n),{destroy:()=>{n&&document.body.contains(n)&&(document.body.removeChild(n),M.delete(t))},getConfig:()=>e}}function et(e="default-widget"){const t=M.get(e);t&&document.body.contains(t)&&(document.body.removeChild(t),M.delete(e))}function tt(){M.forEach(e=>{document.body.contains(e)&&document.body.removeChild(e)}),M.clear()}typeof window<"u"&&(window.ChatWidget={initWidget:Ye,destroyWidget:et,destroyAllWidgets:tt}),S.destroyAllWidgets=tt,S.destroyWidget=et,S.initWidget=Ye,Object.defineProperty(S,Symbol.toStringTag,{value:"Module"})});