bitmax-crm-widget 1.5.2 → 1.5.4
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/chat-widget.min.js +1 -1
- package/dist/chat-widget.min.js.map +1 -1
- package/dist/index.esm.js +1 -1
- package/dist/index.esm.js.map +1 -1
- package/dist/index.js +1 -1
- package/dist/index.js.map +1 -1
- package/package.json +1 -1
package/dist/chat-widget.min.js
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
1
|
!function(){"use strict";function t(t,e){(null==e||e>t.length)&&(e=t.length);for(var n=0,s=Array(e);n<e;n++)s[n]=t[n];return s}function e(t,e,n,s,r,i,o){try{var a=t[i](o),c=a.value}catch(t){return void n(t)}a.done?e(c):Promise.resolve(c).then(s,r)}function n(t){return function(){var n=this,s=arguments;return new Promise(function(r,i){var o=t.apply(n,s);function a(t){e(o,r,i,a,c,"next",t)}function c(t){e(o,r,i,a,c,"throw",t)}a(void 0)})}}function s(t,e,n){return e&&function(t,e){for(var n=0;n<e.length;n++){var s=e[n];s.enumerable=s.enumerable||!1,s.configurable=!0,"value"in s&&(s.writable=!0),Object.defineProperty(t,u(s.key),s)}}(t.prototype,e),Object.defineProperty(t,"prototype",{writable:!1}),t}function r(e,n){var s="undefined"!=typeof Symbol&&e[Symbol.iterator]||e["@@iterator"];if(!s){if(Array.isArray(e)||(s=function(e,n){if(e){if("string"==typeof e)return t(e,n);var s={}.toString.call(e).slice(8,-1);return"Object"===s&&e.constructor&&(s=e.constructor.name),"Map"===s||"Set"===s?Array.from(e):"Arguments"===s||/^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(s)?t(e,n):void 0}}(e))||n){s&&(e=s);var r=0,i=function(){};return{s:i,n:function(){return r>=e.length?{done:!0}:{done:!1,value:e[r++]}},e:function(t){throw t},f:i}}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,c=!1;return{s:function(){s=s.call(e)},n:function(){var t=s.next();return a=t.done,t},e:function(t){c=!0,o=t},f:function(){try{a||null==s.return||s.return()}finally{if(c)throw o}}}}function i(t,e,n){return(e=u(e))in t?Object.defineProperty(t,e,{value:n,enumerable:!0,configurable:!0,writable:!0}):t[e]=n,t}function o(t,e){var n=Object.keys(t);if(Object.getOwnPropertySymbols){var s=Object.getOwnPropertySymbols(t);e&&(s=s.filter(function(e){return Object.getOwnPropertyDescriptor(t,e).enumerable})),n.push.apply(n,s)}return n}function a(t){for(var e=1;e<arguments.length;e++){var n=null!=arguments[e]?arguments[e]:{};e%2?o(Object(n),!0).forEach(function(e){i(t,e,n[e])}):Object.getOwnPropertyDescriptors?Object.defineProperties(t,Object.getOwnPropertyDescriptors(n)):o(Object(n)).forEach(function(e){Object.defineProperty(t,e,Object.getOwnPropertyDescriptor(n,e))})}return t}function c(){
|
|
2
2
|
/*! regenerator-runtime -- Copyright (c) 2014-present, Facebook, Inc. -- license (MIT): https://github.com/babel/babel/blob/main/packages/babel-helpers/LICENSE */
|
|
3
|
-
var t,e,n="function"==typeof Symbol?Symbol:{},s=n.iterator||"@@iterator",r=n.toStringTag||"@@toStringTag";function i(n,s,r,i){var c=s&&s.prototype instanceof a?s:a,u=Object.create(c.prototype);return h(u,"_invoke",function(n,s,r){var i,a,c,h=0,u=r||[],l=!1,d={p:0,n:0,v:t,a:p,f:p.bind(t,4),d:function(e,n){return i=e,a=0,c=t,d.n=n,o}};function p(n,s){for(a=n,c=s,e=0;!l&&h&&!r&&e<u.length;e++){var r,i=u[e],p=d.p,f=i[2];n>3?(r=f===s)&&(c=i[(a=i[4])?5:(a=3,3)],i[4]=i[5]=t):i[0]<=p&&((r=n<2&&p<i[1])?(a=0,d.v=s,d.n=i[1]):p<f&&(r=n<3||i[0]>s||s>f)&&(i[4]=n,i[5]=s,d.n=f,a=0))}if(r||n>1)return o;throw l=!0,s}return function(r,u,f){if(h>1)throw TypeError("Generator is already running");for(l&&1===u&&p(u,f),a=u,c=f;(e=a<2?t:c)||!l;){i||(a?a<3?(a>1&&(d.n=-1),p(a,c)):d.n=c:d.v=c);try{if(h=2,i){if(a||(r="next"),e=i[r]){if(!(e=e.call(i,c)))throw TypeError("iterator result is not an object");if(!e.done)return e;c=e.value,a<2&&(a=0)}else 1===a&&(e=i.return)&&e.call(i),a<2&&(c=TypeError("The iterator does not provide a '"+r+"' method"),a=1);i=t}else if((e=(l=d.n<0)?c:n.call(s,d))!==o)break}catch(e){i=t,a=1,c=e}finally{h=1}}return{value:e,done:l}}}(n,r,i),!0),u}var o={};function a(){}function u(){}function l(){}e=Object.getPrototypeOf;var d=[][s]?e(e([][s]())):(h(e={},s,function(){return this}),e),p=l.prototype=a.prototype=Object.create(d);function f(t){return Object.setPrototypeOf?Object.setPrototypeOf(t,l):(t.__proto__=l,h(t,r,"GeneratorFunction")),t.prototype=Object.create(p),t}return u.prototype=l,h(p,"constructor",l),h(l,"constructor",u),u.displayName="GeneratorFunction",h(l,r,"GeneratorFunction"),h(p),h(p,r,"Generator"),h(p,s,function(){return this}),h(p,"toString",function(){return"[object Generator]"}),(c=function(){return{w:i,m:f}})()}function h(t,e,n,s){var r=Object.defineProperty;try{r({},"",{})}catch(t){r=0}h=function(t,e,n,s){function i(e,n){h(t,e,function(t){return this._invoke(e,n,t)})}e?r?r(t,e,{value:n,enumerable:!s,configurable:!s,writable:!s}):t[e]=n:(i("next",0),i("throw",1),i("return",2))},h(t,e,n,s)}function u(t){var e=function(t,e){if("object"!=typeof t||!t)return t;var n=t[Symbol.toPrimitive];if(void 0!==n){var s=n.call(t,e);if("object"!=typeof s)return s;throw new TypeError("@@toPrimitive must return a primitive value.")}return String(t)}(t,"string");return"symbol"==typeof e?e:e+""}const l=Object.create(null);l.open="0",l.close="1",l.ping="2",l.pong="3",l.message="4",l.upgrade="5",l.noop="6";const d=Object.create(null);Object.keys(l).forEach(t=>{d[l[t]]=t});const p={type:"error",data:"parser error"},f="function"==typeof Blob||"undefined"!=typeof Blob&&"[object BlobConstructor]"===Object.prototype.toString.call(Blob),m="function"==typeof ArrayBuffer,y=t=>"function"==typeof ArrayBuffer.isView?ArrayBuffer.isView(t):t&&t.buffer instanceof ArrayBuffer,g=({type:t,data:e},n,s)=>f&&e instanceof Blob?n?s(e):v(e,s):m&&(e instanceof ArrayBuffer||y(e))?n?s(e):v(new Blob([e]),s):s(l[t]+(e||"")),v=(t,e)=>{const n=new FileReader;return n.onload=function(){const t=n.result.split(",")[1];e("b"+(t||""))},n.readAsDataURL(t)};function b(t){return t instanceof Uint8Array?t:t instanceof ArrayBuffer?new Uint8Array(t):new Uint8Array(t.buffer,t.byteOffset,t.byteLength)}let w;const k="ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/",_="undefined"==typeof Uint8Array?[]:new Uint8Array(256);for(let t=0;t<64;t++)_[k.charCodeAt(t)]=t;const E="function"==typeof ArrayBuffer,C=(t,e)=>{if("string"!=typeof t)return{type:"message",data:O(t,e)};const n=t.charAt(0);if("b"===n)return{type:"message",data:x(t.substring(1),e)};return d[n]?t.length>1?{type:d[n],data:t.substring(1)}:{type:d[n]}:p},x=(t,e)=>{if(E){const n=(t=>{let e,n,s,r,i,o=.75*t.length,a=t.length,c=0;"="===t[t.length-1]&&(o--,"="===t[t.length-2]&&o--);const h=new ArrayBuffer(o),u=new Uint8Array(h);for(e=0;e<a;e+=4)n=_[t.charCodeAt(e)],s=_[t.charCodeAt(e+1)],r=_[t.charCodeAt(e+2)],i=_[t.charCodeAt(e+3)],u[c++]=n<<2|s>>4,u[c++]=(15&s)<<4|r>>2,u[c++]=(3&r)<<6|63&i;return h})(t);return O(n,e)}return{base64:!0,data:t}},O=(t,e)=>"blob"===e?t instanceof Blob?t:new Blob([t]):t instanceof ArrayBuffer?t:t.buffer,S=String.fromCharCode(30);function A(){return new TransformStream({transform(t,e){!function(t,e){f&&t.data instanceof Blob?t.data.arrayBuffer().then(b).then(e):m&&(t.data instanceof ArrayBuffer||y(t.data))?e(b(t.data)):g(t,!1,t=>{w||(w=new TextEncoder),e(w.encode(t))})}(t,n=>{const s=n.length;let r;if(s<126)r=new Uint8Array(1),new DataView(r.buffer).setUint8(0,s);else if(s<65536){r=new Uint8Array(3);const t=new DataView(r.buffer);t.setUint8(0,126),t.setUint16(1,s)}else{r=new Uint8Array(9);const t=new DataView(r.buffer);t.setUint8(0,127),t.setBigUint64(1,BigInt(s))}t.data&&"string"!=typeof t.data&&(r[0]|=128),e.enqueue(r),e.enqueue(n)})}})}let T;function N(t){return t.reduce((t,e)=>t+e.length,0)}function I(t,e){if(t[0].length===e)return t.shift();const n=new Uint8Array(e);let s=0;for(let r=0;r<e;r++)n[r]=t[0][s++],s===t[0].length&&(t.shift(),s=0);return t.length&&s<t[0].length&&(t[0]=t[0].slice(s)),n}function B(t){if(t)return function(t){for(var e in B.prototype)t[e]=B.prototype[e];return t}(t)}B.prototype.on=B.prototype.addEventListener=function(t,e){return this._callbacks=this._callbacks||{},(this._callbacks["$"+t]=this._callbacks["$"+t]||[]).push(e),this},B.prototype.once=function(t,e){function n(){this.off(t,n),e.apply(this,arguments)}return n.fn=e,this.on(t,n),this},B.prototype.off=B.prototype.removeListener=B.prototype.removeAllListeners=B.prototype.removeEventListener=function(t,e){if(this._callbacks=this._callbacks||{},0==arguments.length)return this._callbacks={},this;var n,s=this._callbacks["$"+t];if(!s)return this;if(1==arguments.length)return delete this._callbacks["$"+t],this;for(var r=0;r<s.length;r++)if((n=s[r])===e||n.fn===e){s.splice(r,1);break}return 0===s.length&&delete this._callbacks["$"+t],this},B.prototype.emit=function(t){this._callbacks=this._callbacks||{};for(var e=new Array(arguments.length-1),n=this._callbacks["$"+t],s=1;s<arguments.length;s++)e[s-1]=arguments[s];if(n){s=0;for(var r=(n=n.slice(0)).length;s<r;++s)n[s].apply(this,e)}return this},B.prototype.emitReserved=B.prototype.emit,B.prototype.listeners=function(t){return this._callbacks=this._callbacks||{},this._callbacks["$"+t]||[]},B.prototype.hasListeners=function(t){return!!this.listeners(t).length};const L="function"==typeof Promise&&"function"==typeof Promise.resolve?t=>Promise.resolve().then(t):(t,e)=>e(t,0),R="undefined"!=typeof self?self:"undefined"!=typeof window?window:Function("return this")();function P(t,...e){return e.reduce((e,n)=>(t.hasOwnProperty(n)&&(e[n]=t[n]),e),{})}const j=R.setTimeout,M=R.clearTimeout;function q(t,e){e.useNativeTimers?(t.setTimeoutFn=j.bind(R),t.clearTimeoutFn=M.bind(R)):(t.setTimeoutFn=R.setTimeout.bind(R),t.clearTimeoutFn=R.clearTimeout.bind(R))}function U(t){return"string"==typeof t?function(t){let e=0,n=0;for(let s=0,r=t.length;s<r;s++)e=t.charCodeAt(s),e<128?n+=1:e<2048?n+=2:e<55296||e>=57344?n+=3:(s++,n+=4);return n}(t):Math.ceil(1.33*(t.byteLength||t.size))}function D(){return Date.now().toString(36).substring(3)+Math.random().toString(36).substring(2,5)}class F extends Error{constructor(t,e,n){super(t),this.description=e,this.context=n,this.type="TransportError"}}class H extends B{constructor(t){super(),this.writable=!1,q(this,t),this.opts=t,this.query=t.query,this.socket=t.socket,this.supportsBinary=!t.forceBase64}onError(t,e,n){return super.emitReserved("error",new F(t,e,n)),this}open(){return this.readyState="opening",this.doOpen(),this}close(){return"opening"!==this.readyState&&"open"!==this.readyState||(this.doClose(),this.onClose()),this}send(t){"open"===this.readyState&&this.write(t)}onOpen(){this.readyState="open",this.writable=!0,super.emitReserved("open")}onData(t){const e=C(t,this.socket.binaryType);this.onPacket(e)}onPacket(t){super.emitReserved("packet",t)}onClose(t){this.readyState="closed",super.emitReserved("close",t)}pause(t){}createUri(t,e={}){return t+"://"+this._hostname()+this._port()+this.opts.path+this._query(e)}_hostname(){const t=this.opts.hostname;return-1===t.indexOf(":")?t:"["+t+"]"}_port(){return this.opts.port&&(this.opts.secure&&Number(443!==this.opts.port)||!this.opts.secure&&80!==Number(this.opts.port))?":"+this.opts.port:""}_query(t){const e=function(t){let e="";for(let n in t)t.hasOwnProperty(n)&&(e.length&&(e+="&"),e+=encodeURIComponent(n)+"="+encodeURIComponent(t[n]));return e}(t);return e.length?"?"+e:""}}class z extends H{constructor(){super(...arguments),this._polling=!1}get name(){return"polling"}doOpen(){this._poll()}pause(t){this.readyState="pausing";const e=()=>{this.readyState="paused",t()};if(this._polling||!this.writable){let t=0;this._polling&&(t++,this.once("pollComplete",function(){--t||e()})),this.writable||(t++,this.once("drain",function(){--t||e()}))}else e()}_poll(){this._polling=!0,this.doPoll(),this.emitReserved("poll")}onData(t){((t,e)=>{const n=t.split(S),s=[];for(let t=0;t<n.length;t++){const r=C(n[t],e);if(s.push(r),"error"===r.type)break}return s})(t,this.socket.binaryType).forEach(t=>{if("opening"===this.readyState&&"open"===t.type&&this.onOpen(),"close"===t.type)return this.onClose({description:"transport closed by the server"}),!1;this.onPacket(t)}),"closed"!==this.readyState&&(this._polling=!1,this.emitReserved("pollComplete"),"open"===this.readyState&&this._poll())}doClose(){const t=()=>{this.write([{type:"close"}])};"open"===this.readyState?t():this.once("open",t)}write(t){this.writable=!1,((t,e)=>{const n=t.length,s=new Array(n);let r=0;t.forEach((t,i)=>{g(t,!1,t=>{s[i]=t,++r===n&&e(s.join(S))})})})(t,t=>{this.doWrite(t,()=>{this.writable=!0,this.emitReserved("drain")})})}uri(){const t=this.opts.secure?"https":"http",e=this.query||{};return!1!==this.opts.timestampRequests&&(e[this.opts.timestampParam]=D()),this.supportsBinary||e.sid||(e.b64=1),this.createUri(t,e)}}let K=!1;try{K="undefined"!=typeof XMLHttpRequest&&"withCredentials"in new XMLHttpRequest}catch(t){}const V=K;function W(){}class G extends z{constructor(t){if(super(t),"undefined"!=typeof location){const e="https:"===location.protocol;let n=location.port;n||(n=e?"443":"80"),this.xd="undefined"!=typeof location&&t.hostname!==location.hostname||n!==t.port}}doWrite(t,e){const n=this.request({method:"POST",data:t});n.on("success",e),n.on("error",(t,e)=>{this.onError("xhr post error",t,e)})}doPoll(){const t=this.request();t.on("data",this.onData.bind(this)),t.on("error",(t,e)=>{this.onError("xhr poll error",t,e)}),this.pollXhr=t}}class Y extends B{constructor(t,e,n){super(),this.createRequest=t,q(this,n),this._opts=n,this._method=n.method||"GET",this._uri=e,this._data=void 0!==n.data?n.data:null,this._create()}_create(){var t;const e=P(this._opts,"agent","pfx","key","passphrase","cert","ca","ciphers","rejectUnauthorized","autoUnref");e.xdomain=!!this._opts.xd;const n=this._xhr=this.createRequest(e);try{n.open(this._method,this._uri,!0);try{if(this._opts.extraHeaders){n.setDisableHeaderCheck&&n.setDisableHeaderCheck(!0);for(let t in this._opts.extraHeaders)this._opts.extraHeaders.hasOwnProperty(t)&&n.setRequestHeader(t,this._opts.extraHeaders[t])}}catch(t){}if("POST"===this._method)try{n.setRequestHeader("Content-type","text/plain;charset=UTF-8")}catch(t){}try{n.setRequestHeader("Accept","*/*")}catch(t){}null===(t=this._opts.cookieJar)||void 0===t||t.addCookies(n),"withCredentials"in n&&(n.withCredentials=this._opts.withCredentials),this._opts.requestTimeout&&(n.timeout=this._opts.requestTimeout),n.onreadystatechange=()=>{var t;3===n.readyState&&(null===(t=this._opts.cookieJar)||void 0===t||t.parseCookies(n.getResponseHeader("set-cookie"))),4===n.readyState&&(200===n.status||1223===n.status?this._onLoad():this.setTimeoutFn(()=>{this._onError("number"==typeof n.status?n.status:0)},0))},n.send(this._data)}catch(t){return void this.setTimeoutFn(()=>{this._onError(t)},0)}"undefined"!=typeof document&&(this._index=Y.requestsCount++,Y.requests[this._index]=this)}_onError(t){this.emitReserved("error",t,this._xhr),this._cleanup(!0)}_cleanup(t){if(void 0!==this._xhr&&null!==this._xhr){if(this._xhr.onreadystatechange=W,t)try{this._xhr.abort()}catch(t){}"undefined"!=typeof document&&delete Y.requests[this._index],this._xhr=null}}_onLoad(){const t=this._xhr.responseText;null!==t&&(this.emitReserved("data",t),this.emitReserved("success"),this._cleanup())}abort(){this._cleanup()}}if(Y.requestsCount=0,Y.requests={},"undefined"!=typeof document)if("function"==typeof attachEvent)attachEvent("onunload",J);else if("function"==typeof addEventListener){addEventListener("onpagehide"in R?"pagehide":"unload",J,!1)}function J(){for(let t in Y.requests)Y.requests.hasOwnProperty(t)&&Y.requests[t].abort()}const $=function(){const t=X({xdomain:!1});return t&&null!==t.responseType}();function X(t){const e=t.xdomain;try{if("undefined"!=typeof XMLHttpRequest&&(!e||V))return new XMLHttpRequest}catch(t){}if(!e)try{return new(R[["Active"].concat("Object").join("X")])("Microsoft.XMLHTTP")}catch(t){}}const Q="undefined"!=typeof navigator&&"string"==typeof navigator.product&&"reactnative"===navigator.product.toLowerCase();class Z extends H{get name(){return"websocket"}doOpen(){const t=this.uri(),e=this.opts.protocols,n=Q?{}:P(this.opts,"agent","perMessageDeflate","pfx","key","passphrase","cert","ca","ciphers","rejectUnauthorized","localAddress","protocolVersion","origin","maxPayload","family","checkServerIdentity");this.opts.extraHeaders&&(n.headers=this.opts.extraHeaders);try{this.ws=this.createSocket(t,e,n)}catch(t){return this.emitReserved("error",t)}this.ws.binaryType=this.socket.binaryType,this.addEventListeners()}addEventListeners(){this.ws.onopen=()=>{this.opts.autoUnref&&this.ws._socket.unref(),this.onOpen()},this.ws.onclose=t=>this.onClose({description:"websocket connection closed",context:t}),this.ws.onmessage=t=>this.onData(t.data),this.ws.onerror=t=>this.onError("websocket error",t)}write(t){this.writable=!1;for(let e=0;e<t.length;e++){const n=t[e],s=e===t.length-1;g(n,this.supportsBinary,t=>{try{this.doWrite(n,t)}catch(t){}s&&L(()=>{this.writable=!0,this.emitReserved("drain")},this.setTimeoutFn)})}}doClose(){void 0!==this.ws&&(this.ws.onerror=()=>{},this.ws.close(),this.ws=null)}uri(){const t=this.opts.secure?"wss":"ws",e=this.query||{};return this.opts.timestampRequests&&(e[this.opts.timestampParam]=D()),this.supportsBinary||(e.b64=1),this.createUri(t,e)}}const tt=R.WebSocket||R.MozWebSocket;const et={websocket:class extends Z{createSocket(t,e,n){return Q?new tt(t,e,n):e?new tt(t,e):new tt(t)}doWrite(t,e){this.ws.send(e)}},webtransport:class extends H{get name(){return"webtransport"}doOpen(){try{this._transport=new WebTransport(this.createUri("https"),this.opts.transportOptions[this.name])}catch(t){return this.emitReserved("error",t)}this._transport.closed.then(()=>{this.onClose()}).catch(t=>{this.onError("webtransport error",t)}),this._transport.ready.then(()=>{this._transport.createBidirectionalStream().then(t=>{const e=function(t,e){T||(T=new TextDecoder);const n=[];let s=0,r=-1,i=!1;return new TransformStream({transform(o,a){for(n.push(o);;){if(0===s){if(N(n)<1)break;const t=I(n,1);i=!(128&~t[0]),r=127&t[0],s=r<126?3:126===r?1:2}else if(1===s){if(N(n)<2)break;const t=I(n,2);r=new DataView(t.buffer,t.byteOffset,t.length).getUint16(0),s=3}else if(2===s){if(N(n)<8)break;const t=I(n,8),e=new DataView(t.buffer,t.byteOffset,t.length),i=e.getUint32(0);if(i>Math.pow(2,21)-1){a.enqueue(p);break}r=i*Math.pow(2,32)+e.getUint32(4),s=3}else{if(N(n)<r)break;const t=I(n,r);a.enqueue(C(i?t:T.decode(t),e)),s=0}if(0===r||r>t){a.enqueue(p);break}}}})}(Number.MAX_SAFE_INTEGER,this.socket.binaryType),n=t.readable.pipeThrough(e).getReader(),s=A();s.readable.pipeTo(t.writable),this._writer=s.writable.getWriter();const r=()=>{n.read().then(({done:t,value:e})=>{t||(this.onPacket(e),r())}).catch(t=>{})};r();const i={type:"open"};this.query.sid&&(i.data=`{"sid":"${this.query.sid}"}`),this._writer.write(i).then(()=>this.onOpen())})})}write(t){this.writable=!1;for(let e=0;e<t.length;e++){const n=t[e],s=e===t.length-1;this._writer.write(n).then(()=>{s&&L(()=>{this.writable=!0,this.emitReserved("drain")},this.setTimeoutFn)})}}doClose(){var t;null===(t=this._transport)||void 0===t||t.close()}},polling:class extends G{constructor(t){super(t);const e=t&&t.forceBase64;this.supportsBinary=$&&!e}request(t={}){return Object.assign(t,{xd:this.xd},this.opts),new Y(X,this.uri(),t)}}},nt=/^(?:(?![^:@\/?#]+:[^:@\/]*@)(http|https|ws|wss):\/\/)?((?:(([^:@\/?#]*)(?::([^:@\/?#]*))?)?@)?((?:[a-f0-9]{0,4}:){2,7}[a-f0-9]{0,4}|[^:\/?#]*)(?::(\d*))?)(((\/(?:[^?#](?![^?#\/]*\.[^?#\/.]+(?:[?#]|$)))*\/?)?([^?#\/]*))(?:\?([^#]*))?(?:#(.*))?)/,st=["source","protocol","authority","userInfo","user","password","host","port","relative","path","directory","file","query","anchor"];function rt(t){if(t.length>8e3)throw"URI too long";const e=t,n=t.indexOf("["),s=t.indexOf("]");-1!=n&&-1!=s&&(t=t.substring(0,n)+t.substring(n,s).replace(/:/g,";")+t.substring(s,t.length));let r=nt.exec(t||""),i={},o=14;for(;o--;)i[st[o]]=r[o]||"";return-1!=n&&-1!=s&&(i.source=e,i.host=i.host.substring(1,i.host.length-1).replace(/;/g,":"),i.authority=i.authority.replace("[","").replace("]","").replace(/;/g,":"),i.ipv6uri=!0),i.pathNames=function(t,e){const n=/\/{2,9}/g,s=e.replace(n,"/").split("/");"/"!=e.slice(0,1)&&0!==e.length||s.splice(0,1);"/"==e.slice(-1)&&s.splice(s.length-1,1);return s}(0,i.path),i.queryKey=function(t,e){const n={};return e.replace(/(?:^|&)([^&=]*)=?([^&]*)/g,function(t,e,s){e&&(n[e]=s)}),n}(0,i.query),i}const it="function"==typeof addEventListener&&"function"==typeof removeEventListener,ot=[];it&&addEventListener("offline",()=>{ot.forEach(t=>t())},!1);class at extends B{constructor(t,e){if(super(),this.binaryType="arraybuffer",this.writeBuffer=[],this._prevBufferLen=0,this._pingInterval=-1,this._pingTimeout=-1,this._maxPayload=-1,this._pingTimeoutTime=1/0,t&&"object"==typeof t&&(e=t,t=null),t){const n=rt(t);e.hostname=n.host,e.secure="https"===n.protocol||"wss"===n.protocol,e.port=n.port,n.query&&(e.query=n.query)}else e.host&&(e.hostname=rt(e.host).host);q(this,e),this.secure=null!=e.secure?e.secure:"undefined"!=typeof location&&"https:"===location.protocol,e.hostname&&!e.port&&(e.port=this.secure?"443":"80"),this.hostname=e.hostname||("undefined"!=typeof location?location.hostname:"localhost"),this.port=e.port||("undefined"!=typeof location&&location.port?location.port:this.secure?"443":"80"),this.transports=[],this._transportsByName={},e.transports.forEach(t=>{const e=t.prototype.name;this.transports.push(e),this._transportsByName[e]=t}),this.opts=Object.assign({path:"/engine.io",agent:!1,withCredentials:!1,upgrade:!0,timestampParam:"t",rememberUpgrade:!1,addTrailingSlash:!0,rejectUnauthorized:!0,perMessageDeflate:{threshold:1024},transportOptions:{},closeOnBeforeunload:!1},e),this.opts.path=this.opts.path.replace(/\/$/,"")+(this.opts.addTrailingSlash?"/":""),"string"==typeof this.opts.query&&(this.opts.query=function(t){let e={},n=t.split("&");for(let t=0,s=n.length;t<s;t++){let s=n[t].split("=");e[decodeURIComponent(s[0])]=decodeURIComponent(s[1])}return e}(this.opts.query)),it&&(this.opts.closeOnBeforeunload&&(this._beforeunloadEventListener=()=>{this.transport&&(this.transport.removeAllListeners(),this.transport.close())},addEventListener("beforeunload",this._beforeunloadEventListener,!1)),"localhost"!==this.hostname&&(this._offlineEventListener=()=>{this._onClose("transport close",{description:"network connection lost"})},ot.push(this._offlineEventListener))),this.opts.withCredentials&&(this._cookieJar=void 0),this._open()}createTransport(t){const e=Object.assign({},this.opts.query);e.EIO=4,e.transport=t,this.id&&(e.sid=this.id);const n=Object.assign({},this.opts,{query:e,socket:this,hostname:this.hostname,secure:this.secure,port:this.port},this.opts.transportOptions[t]);return new this._transportsByName[t](n)}_open(){if(0===this.transports.length)return void this.setTimeoutFn(()=>{this.emitReserved("error","No transports available")},0);const t=this.opts.rememberUpgrade&&at.priorWebsocketSuccess&&-1!==this.transports.indexOf("websocket")?"websocket":this.transports[0];this.readyState="opening";const e=this.createTransport(t);e.open(),this.setTransport(e)}setTransport(t){this.transport&&this.transport.removeAllListeners(),this.transport=t,t.on("drain",this._onDrain.bind(this)).on("packet",this._onPacket.bind(this)).on("error",this._onError.bind(this)).on("close",t=>this._onClose("transport close",t))}onOpen(){this.readyState="open",at.priorWebsocketSuccess="websocket"===this.transport.name,this.emitReserved("open"),this.flush()}_onPacket(t){if("opening"===this.readyState||"open"===this.readyState||"closing"===this.readyState)switch(this.emitReserved("packet",t),this.emitReserved("heartbeat"),t.type){case"open":this.onHandshake(JSON.parse(t.data));break;case"ping":this._sendPacket("pong"),this.emitReserved("ping"),this.emitReserved("pong"),this._resetPingTimeout();break;case"error":const e=new Error("server error");e.code=t.data,this._onError(e);break;case"message":this.emitReserved("data",t.data),this.emitReserved("message",t.data)}}onHandshake(t){this.emitReserved("handshake",t),this.id=t.sid,this.transport.query.sid=t.sid,this._pingInterval=t.pingInterval,this._pingTimeout=t.pingTimeout,this._maxPayload=t.maxPayload,this.onOpen(),"closed"!==this.readyState&&this._resetPingTimeout()}_resetPingTimeout(){this.clearTimeoutFn(this._pingTimeoutTimer);const t=this._pingInterval+this._pingTimeout;this._pingTimeoutTime=Date.now()+t,this._pingTimeoutTimer=this.setTimeoutFn(()=>{this._onClose("ping timeout")},t),this.opts.autoUnref&&this._pingTimeoutTimer.unref()}_onDrain(){this.writeBuffer.splice(0,this._prevBufferLen),this._prevBufferLen=0,0===this.writeBuffer.length?this.emitReserved("drain"):this.flush()}flush(){if("closed"!==this.readyState&&this.transport.writable&&!this.upgrading&&this.writeBuffer.length){const t=this._getWritablePackets();this.transport.send(t),this._prevBufferLen=t.length,this.emitReserved("flush")}}_getWritablePackets(){if(!(this._maxPayload&&"polling"===this.transport.name&&this.writeBuffer.length>1))return this.writeBuffer;let t=1;for(let e=0;e<this.writeBuffer.length;e++){const n=this.writeBuffer[e].data;if(n&&(t+=U(n)),e>0&&t>this._maxPayload)return this.writeBuffer.slice(0,e);t+=2}return this.writeBuffer}_hasPingExpired(){if(!this._pingTimeoutTime)return!0;const t=Date.now()>this._pingTimeoutTime;return t&&(this._pingTimeoutTime=0,L(()=>{this._onClose("ping timeout")},this.setTimeoutFn)),t}write(t,e,n){return this._sendPacket("message",t,e,n),this}send(t,e,n){return this._sendPacket("message",t,e,n),this}_sendPacket(t,e,n,s){if("function"==typeof e&&(s=e,e=void 0),"function"==typeof n&&(s=n,n=null),"closing"===this.readyState||"closed"===this.readyState)return;(n=n||{}).compress=!1!==n.compress;const r={type:t,data:e,options:n};this.emitReserved("packetCreate",r),this.writeBuffer.push(r),s&&this.once("flush",s),this.flush()}close(){const t=()=>{this._onClose("forced close"),this.transport.close()},e=()=>{this.off("upgrade",e),this.off("upgradeError",e),t()},n=()=>{this.once("upgrade",e),this.once("upgradeError",e)};return"opening"!==this.readyState&&"open"!==this.readyState||(this.readyState="closing",this.writeBuffer.length?this.once("drain",()=>{this.upgrading?n():t()}):this.upgrading?n():t()),this}_onError(t){if(at.priorWebsocketSuccess=!1,this.opts.tryAllTransports&&this.transports.length>1&&"opening"===this.readyState)return this.transports.shift(),this._open();this.emitReserved("error",t),this._onClose("transport error",t)}_onClose(t,e){if("opening"===this.readyState||"open"===this.readyState||"closing"===this.readyState){if(this.clearTimeoutFn(this._pingTimeoutTimer),this.transport.removeAllListeners("close"),this.transport.close(),this.transport.removeAllListeners(),it&&(this._beforeunloadEventListener&&removeEventListener("beforeunload",this._beforeunloadEventListener,!1),this._offlineEventListener)){const t=ot.indexOf(this._offlineEventListener);-1!==t&&ot.splice(t,1)}this.readyState="closed",this.id=null,this.emitReserved("close",t,e),this.writeBuffer=[],this._prevBufferLen=0}}}at.protocol=4;class ct extends at{constructor(){super(...arguments),this._upgrades=[]}onOpen(){if(super.onOpen(),"open"===this.readyState&&this.opts.upgrade)for(let t=0;t<this._upgrades.length;t++)this._probe(this._upgrades[t])}_probe(t){let e=this.createTransport(t),n=!1;at.priorWebsocketSuccess=!1;const s=()=>{n||(e.send([{type:"ping",data:"probe"}]),e.once("packet",t=>{if(!n)if("pong"===t.type&&"probe"===t.data){if(this.upgrading=!0,this.emitReserved("upgrading",e),!e)return;at.priorWebsocketSuccess="websocket"===e.name,this.transport.pause(()=>{n||"closed"!==this.readyState&&(h(),this.setTransport(e),e.send([{type:"upgrade"}]),this.emitReserved("upgrade",e),e=null,this.upgrading=!1,this.flush())})}else{const t=new Error("probe error");t.transport=e.name,this.emitReserved("upgradeError",t)}}))};function r(){n||(n=!0,h(),e.close(),e=null)}const i=t=>{const n=new Error("probe error: "+t);n.transport=e.name,r(),this.emitReserved("upgradeError",n)};function o(){i("transport closed")}function a(){i("socket closed")}function c(t){e&&t.name!==e.name&&r()}const h=()=>{e.removeListener("open",s),e.removeListener("error",i),e.removeListener("close",o),this.off("close",a),this.off("upgrading",c)};e.once("open",s),e.once("error",i),e.once("close",o),this.once("close",a),this.once("upgrading",c),-1!==this._upgrades.indexOf("webtransport")&&"webtransport"!==t?this.setTimeoutFn(()=>{n||e.open()},200):e.open()}onHandshake(t){this._upgrades=this._filterUpgrades(t.upgrades),super.onHandshake(t)}_filterUpgrades(t){const e=[];for(let n=0;n<t.length;n++)~this.transports.indexOf(t[n])&&e.push(t[n]);return e}}let ht=class extends ct{constructor(t,e={}){const n="object"==typeof t?t:e;(!n.transports||n.transports&&"string"==typeof n.transports[0])&&(n.transports=(n.transports||["polling","websocket","webtransport"]).map(t=>et[t]).filter(t=>!!t)),super(t,n)}};const ut="function"==typeof ArrayBuffer,lt=Object.prototype.toString,dt="function"==typeof Blob||"undefined"!=typeof Blob&&"[object BlobConstructor]"===lt.call(Blob),pt="function"==typeof File||"undefined"!=typeof File&&"[object FileConstructor]"===lt.call(File);function ft(t){return ut&&(t instanceof ArrayBuffer||(t=>"function"==typeof ArrayBuffer.isView?ArrayBuffer.isView(t):t.buffer instanceof ArrayBuffer)(t))||dt&&t instanceof Blob||pt&&t instanceof File}function mt(t,e){if(!t||"object"!=typeof t)return!1;if(Array.isArray(t)){for(let e=0,n=t.length;e<n;e++)if(mt(t[e]))return!0;return!1}if(ft(t))return!0;if(t.toJSON&&"function"==typeof t.toJSON&&1===arguments.length)return mt(t.toJSON(),!0);for(const e in t)if(Object.prototype.hasOwnProperty.call(t,e)&&mt(t[e]))return!0;return!1}function yt(t){const e=[],n=t.data,s=t;return s.data=gt(n,e),s.attachments=e.length,{packet:s,buffers:e}}function gt(t,e){if(!t)return t;if(ft(t)){const n={_placeholder:!0,num:e.length};return e.push(t),n}if(Array.isArray(t)){const n=new Array(t.length);for(let s=0;s<t.length;s++)n[s]=gt(t[s],e);return n}if("object"==typeof t&&!(t instanceof Date)){const n={};for(const s in t)Object.prototype.hasOwnProperty.call(t,s)&&(n[s]=gt(t[s],e));return n}return t}function vt(t,e){return t.data=bt(t.data,e),delete t.attachments,t}function bt(t,e){if(!t)return t;if(t&&!0===t._placeholder){if("number"==typeof t.num&&t.num>=0&&t.num<e.length)return e[t.num];throw new Error("illegal attachments")}if(Array.isArray(t))for(let n=0;n<t.length;n++)t[n]=bt(t[n],e);else if("object"==typeof t)for(const n in t)Object.prototype.hasOwnProperty.call(t,n)&&(t[n]=bt(t[n],e));return t}const wt=["connect","connect_error","disconnect","disconnecting","newListener","removeListener"];var kt;!function(t){t[t.CONNECT=0]="CONNECT",t[t.DISCONNECT=1]="DISCONNECT",t[t.EVENT=2]="EVENT",t[t.ACK=3]="ACK",t[t.CONNECT_ERROR=4]="CONNECT_ERROR",t[t.BINARY_EVENT=5]="BINARY_EVENT",t[t.BINARY_ACK=6]="BINARY_ACK"}(kt||(kt={}));function _t(t){return"[object Object]"===Object.prototype.toString.call(t)}class Et extends B{constructor(t){super(),this.reviver=t}add(t){let e;if("string"==typeof t){if(this.reconstructor)throw new Error("got plaintext data when reconstructing a packet");e=this.decodeString(t);const n=e.type===kt.BINARY_EVENT;n||e.type===kt.BINARY_ACK?(e.type=n?kt.EVENT:kt.ACK,this.reconstructor=new Ct(e),0===e.attachments&&super.emitReserved("decoded",e)):super.emitReserved("decoded",e)}else{if(!ft(t)&&!t.base64)throw new Error("Unknown type: "+t);if(!this.reconstructor)throw new Error("got binary data when not reconstructing a packet");e=this.reconstructor.takeBinaryData(t),e&&(this.reconstructor=null,super.emitReserved("decoded",e))}}decodeString(t){let e=0;const n={type:Number(t.charAt(0))};if(void 0===kt[n.type])throw new Error("unknown packet type "+n.type);if(n.type===kt.BINARY_EVENT||n.type===kt.BINARY_ACK){const s=e+1;for(;"-"!==t.charAt(++e)&&e!=t.length;);const r=t.substring(s,e);if(r!=Number(r)||"-"!==t.charAt(e))throw new Error("Illegal attachments");n.attachments=Number(r)}if("/"===t.charAt(e+1)){const s=e+1;for(;++e;){if(","===t.charAt(e))break;if(e===t.length)break}n.nsp=t.substring(s,e)}else n.nsp="/";const s=t.charAt(e+1);if(""!==s&&Number(s)==s){const s=e+1;for(;++e;){const n=t.charAt(e);if(null==n||Number(n)!=n){--e;break}if(e===t.length)break}n.id=Number(t.substring(s,e+1))}if(t.charAt(++e)){const s=this.tryParse(t.substr(e));if(!Et.isPayloadValid(n.type,s))throw new Error("invalid payload");n.data=s}return n}tryParse(t){try{return JSON.parse(t,this.reviver)}catch(t){return!1}}static isPayloadValid(t,e){switch(t){case kt.CONNECT:return _t(e);case kt.DISCONNECT:return void 0===e;case kt.CONNECT_ERROR:return"string"==typeof e||_t(e);case kt.EVENT:case kt.BINARY_EVENT:return Array.isArray(e)&&("number"==typeof e[0]||"string"==typeof e[0]&&-1===wt.indexOf(e[0]));case kt.ACK:case kt.BINARY_ACK:return Array.isArray(e)}}destroy(){this.reconstructor&&(this.reconstructor.finishedReconstruction(),this.reconstructor=null)}}class Ct{constructor(t){this.packet=t,this.buffers=[],this.reconPack=t}takeBinaryData(t){if(this.buffers.push(t),this.buffers.length===this.reconPack.attachments){const t=vt(this.reconPack,this.buffers);return this.finishedReconstruction(),t}return null}finishedReconstruction(){this.reconPack=null,this.buffers=[]}}var xt=Object.freeze({__proto__:null,Decoder:Et,Encoder:class{constructor(t){this.replacer=t}encode(t){return t.type!==kt.EVENT&&t.type!==kt.ACK||!mt(t)?[this.encodeAsString(t)]:this.encodeAsBinary({type:t.type===kt.EVENT?kt.BINARY_EVENT:kt.BINARY_ACK,nsp:t.nsp,data:t.data,id:t.id})}encodeAsString(t){let e=""+t.type;return t.type!==kt.BINARY_EVENT&&t.type!==kt.BINARY_ACK||(e+=t.attachments+"-"),t.nsp&&"/"!==t.nsp&&(e+=t.nsp+","),null!=t.id&&(e+=t.id),null!=t.data&&(e+=JSON.stringify(t.data,this.replacer)),e}encodeAsBinary(t){const e=yt(t),n=this.encodeAsString(e.packet),s=e.buffers;return s.unshift(n),s}},get PacketType(){return kt},protocol:5});function Ot(t,e,n){return t.on(e,n),function(){t.off(e,n)}}const St=Object.freeze({connect:1,connect_error:1,disconnect:1,disconnecting:1,newListener:1,removeListener:1});class At extends B{constructor(t,e,n){super(),this.connected=!1,this.recovered=!1,this.receiveBuffer=[],this.sendBuffer=[],this._queue=[],this._queueSeq=0,this.ids=0,this.acks={},this.flags={},this.io=t,this.nsp=e,n&&n.auth&&(this.auth=n.auth),this._opts=Object.assign({},n),this.io._autoConnect&&this.open()}get disconnected(){return!this.connected}subEvents(){if(this.subs)return;const t=this.io;this.subs=[Ot(t,"open",this.onopen.bind(this)),Ot(t,"packet",this.onpacket.bind(this)),Ot(t,"error",this.onerror.bind(this)),Ot(t,"close",this.onclose.bind(this))]}get active(){return!!this.subs}connect(){return this.connected||(this.subEvents(),this.io._reconnecting||this.io.open(),"open"===this.io._readyState&&this.onopen()),this}open(){return this.connect()}send(...t){return t.unshift("message"),this.emit.apply(this,t),this}emit(t,...e){var n,s,r;if(St.hasOwnProperty(t))throw new Error('"'+t.toString()+'" is a reserved event name');if(e.unshift(t),this._opts.retries&&!this.flags.fromQueue&&!this.flags.volatile)return this._addToQueue(e),this;const i={type:kt.EVENT,data:e,options:{}};if(i.options.compress=!1!==this.flags.compress,"function"==typeof e[e.length-1]){const t=this.ids++,n=e.pop();this._registerAckCallback(t,n),i.id=t}const o=null===(s=null===(n=this.io.engine)||void 0===n?void 0:n.transport)||void 0===s?void 0:s.writable,a=this.connected&&!(null===(r=this.io.engine)||void 0===r?void 0:r._hasPingExpired());return this.flags.volatile&&!o||(a?(this.notifyOutgoingListeners(i),this.packet(i)):this.sendBuffer.push(i)),this.flags={},this}_registerAckCallback(t,e){var n;const s=null!==(n=this.flags.timeout)&&void 0!==n?n:this._opts.ackTimeout;if(void 0===s)return void(this.acks[t]=e);const r=this.io.setTimeoutFn(()=>{delete this.acks[t];for(let e=0;e<this.sendBuffer.length;e++)this.sendBuffer[e].id===t&&this.sendBuffer.splice(e,1);e.call(this,new Error("operation has timed out"))},s),i=(...t)=>{this.io.clearTimeoutFn(r),e.apply(this,t)};i.withError=!0,this.acks[t]=i}emitWithAck(t,...e){return new Promise((n,s)=>{const r=(t,e)=>t?s(t):n(e);r.withError=!0,e.push(r),this.emit(t,...e)})}_addToQueue(t){let e;"function"==typeof t[t.length-1]&&(e=t.pop());const n={id:this._queueSeq++,tryCount:0,pending:!1,args:t,flags:Object.assign({fromQueue:!0},this.flags)};t.push((t,...s)=>{if(n!==this._queue[0])return;return null!==t?n.tryCount>this._opts.retries&&(this._queue.shift(),e&&e(t)):(this._queue.shift(),e&&e(null,...s)),n.pending=!1,this._drainQueue()}),this._queue.push(n),this._drainQueue()}_drainQueue(t=!1){if(!this.connected||0===this._queue.length)return;const e=this._queue[0];e.pending&&!t||(e.pending=!0,e.tryCount++,this.flags=e.flags,this.emit.apply(this,e.args))}packet(t){t.nsp=this.nsp,this.io._packet(t)}onopen(){"function"==typeof this.auth?this.auth(t=>{this._sendConnectPacket(t)}):this._sendConnectPacket(this.auth)}_sendConnectPacket(t){this.packet({type:kt.CONNECT,data:this._pid?Object.assign({pid:this._pid,offset:this._lastOffset},t):t})}onerror(t){this.connected||this.emitReserved("connect_error",t)}onclose(t,e){this.connected=!1,delete this.id,this.emitReserved("disconnect",t,e),this._clearAcks()}_clearAcks(){Object.keys(this.acks).forEach(t=>{if(!this.sendBuffer.some(e=>String(e.id)===t)){const e=this.acks[t];delete this.acks[t],e.withError&&e.call(this,new Error("socket has been disconnected"))}})}onpacket(t){if(t.nsp===this.nsp)switch(t.type){case kt.CONNECT:t.data&&t.data.sid?this.onconnect(t.data.sid,t.data.pid):this.emitReserved("connect_error",new Error("It seems you are trying to reach a Socket.IO server in v2.x with a v3.x client, but they are not compatible (more information here: https://socket.io/docs/v3/migrating-from-2-x-to-3-0/)"));break;case kt.EVENT:case kt.BINARY_EVENT:this.onevent(t);break;case kt.ACK:case kt.BINARY_ACK:this.onack(t);break;case kt.DISCONNECT:this.ondisconnect();break;case kt.CONNECT_ERROR:this.destroy();const e=new Error(t.data.message);e.data=t.data.data,this.emitReserved("connect_error",e)}}onevent(t){const e=t.data||[];null!=t.id&&e.push(this.ack(t.id)),this.connected?this.emitEvent(e):this.receiveBuffer.push(Object.freeze(e))}emitEvent(t){if(this._anyListeners&&this._anyListeners.length){const e=this._anyListeners.slice();for(const n of e)n.apply(this,t)}super.emit.apply(this,t),this._pid&&t.length&&"string"==typeof t[t.length-1]&&(this._lastOffset=t[t.length-1])}ack(t){const e=this;let n=!1;return function(...s){n||(n=!0,e.packet({type:kt.ACK,id:t,data:s}))}}onack(t){const e=this.acks[t.id];"function"==typeof e&&(delete this.acks[t.id],e.withError&&t.data.unshift(null),e.apply(this,t.data))}onconnect(t,e){this.id=t,this.recovered=e&&this._pid===e,this._pid=e,this.connected=!0,this.emitBuffered(),this.emitReserved("connect"),this._drainQueue(!0)}emitBuffered(){this.receiveBuffer.forEach(t=>this.emitEvent(t)),this.receiveBuffer=[],this.sendBuffer.forEach(t=>{this.notifyOutgoingListeners(t),this.packet(t)}),this.sendBuffer=[]}ondisconnect(){this.destroy(),this.onclose("io server disconnect")}destroy(){this.subs&&(this.subs.forEach(t=>t()),this.subs=void 0),this.io._destroy(this)}disconnect(){return this.connected&&this.packet({type:kt.DISCONNECT}),this.destroy(),this.connected&&this.onclose("io client disconnect"),this}close(){return this.disconnect()}compress(t){return this.flags.compress=t,this}get volatile(){return this.flags.volatile=!0,this}timeout(t){return this.flags.timeout=t,this}onAny(t){return this._anyListeners=this._anyListeners||[],this._anyListeners.push(t),this}prependAny(t){return this._anyListeners=this._anyListeners||[],this._anyListeners.unshift(t),this}offAny(t){if(!this._anyListeners)return this;if(t){const e=this._anyListeners;for(let n=0;n<e.length;n++)if(t===e[n])return e.splice(n,1),this}else this._anyListeners=[];return this}listenersAny(){return this._anyListeners||[]}onAnyOutgoing(t){return this._anyOutgoingListeners=this._anyOutgoingListeners||[],this._anyOutgoingListeners.push(t),this}prependAnyOutgoing(t){return this._anyOutgoingListeners=this._anyOutgoingListeners||[],this._anyOutgoingListeners.unshift(t),this}offAnyOutgoing(t){if(!this._anyOutgoingListeners)return this;if(t){const e=this._anyOutgoingListeners;for(let n=0;n<e.length;n++)if(t===e[n])return e.splice(n,1),this}else this._anyOutgoingListeners=[];return this}listenersAnyOutgoing(){return this._anyOutgoingListeners||[]}notifyOutgoingListeners(t){if(this._anyOutgoingListeners&&this._anyOutgoingListeners.length){const e=this._anyOutgoingListeners.slice();for(const n of e)n.apply(this,t.data)}}}function Tt(t){t=t||{},this.ms=t.min||100,this.max=t.max||1e4,this.factor=t.factor||2,this.jitter=t.jitter>0&&t.jitter<=1?t.jitter:0,this.attempts=0}Tt.prototype.duration=function(){var t=this.ms*Math.pow(this.factor,this.attempts++);if(this.jitter){var e=Math.random(),n=Math.floor(e*this.jitter*t);t=1&Math.floor(10*e)?t+n:t-n}return 0|Math.min(t,this.max)},Tt.prototype.reset=function(){this.attempts=0},Tt.prototype.setMin=function(t){this.ms=t},Tt.prototype.setMax=function(t){this.max=t},Tt.prototype.setJitter=function(t){this.jitter=t};class Nt extends B{constructor(t,e){var n;super(),this.nsps={},this.subs=[],t&&"object"==typeof t&&(e=t,t=void 0),(e=e||{}).path=e.path||"/socket.io",this.opts=e,q(this,e),this.reconnection(!1!==e.reconnection),this.reconnectionAttempts(e.reconnectionAttempts||1/0),this.reconnectionDelay(e.reconnectionDelay||1e3),this.reconnectionDelayMax(e.reconnectionDelayMax||5e3),this.randomizationFactor(null!==(n=e.randomizationFactor)&&void 0!==n?n:.5),this.backoff=new Tt({min:this.reconnectionDelay(),max:this.reconnectionDelayMax(),jitter:this.randomizationFactor()}),this.timeout(null==e.timeout?2e4:e.timeout),this._readyState="closed",this.uri=t;const s=e.parser||xt;this.encoder=new s.Encoder,this.decoder=new s.Decoder,this._autoConnect=!1!==e.autoConnect,this._autoConnect&&this.open()}reconnection(t){return arguments.length?(this._reconnection=!!t,t||(this.skipReconnect=!0),this):this._reconnection}reconnectionAttempts(t){return void 0===t?this._reconnectionAttempts:(this._reconnectionAttempts=t,this)}reconnectionDelay(t){var e;return void 0===t?this._reconnectionDelay:(this._reconnectionDelay=t,null===(e=this.backoff)||void 0===e||e.setMin(t),this)}randomizationFactor(t){var e;return void 0===t?this._randomizationFactor:(this._randomizationFactor=t,null===(e=this.backoff)||void 0===e||e.setJitter(t),this)}reconnectionDelayMax(t){var e;return void 0===t?this._reconnectionDelayMax:(this._reconnectionDelayMax=t,null===(e=this.backoff)||void 0===e||e.setMax(t),this)}timeout(t){return arguments.length?(this._timeout=t,this):this._timeout}maybeReconnectOnOpen(){!this._reconnecting&&this._reconnection&&0===this.backoff.attempts&&this.reconnect()}open(t){if(~this._readyState.indexOf("open"))return this;this.engine=new ht(this.uri,this.opts);const e=this.engine,n=this;this._readyState="opening",this.skipReconnect=!1;const s=Ot(e,"open",function(){n.onopen(),t&&t()}),r=e=>{this.cleanup(),this._readyState="closed",this.emitReserved("error",e),t?t(e):this.maybeReconnectOnOpen()},i=Ot(e,"error",r);if(!1!==this._timeout){const t=this._timeout,n=this.setTimeoutFn(()=>{s(),r(new Error("timeout")),e.close()},t);this.opts.autoUnref&&n.unref(),this.subs.push(()=>{this.clearTimeoutFn(n)})}return this.subs.push(s),this.subs.push(i),this}connect(t){return this.open(t)}onopen(){this.cleanup(),this._readyState="open",this.emitReserved("open");const t=this.engine;this.subs.push(Ot(t,"ping",this.onping.bind(this)),Ot(t,"data",this.ondata.bind(this)),Ot(t,"error",this.onerror.bind(this)),Ot(t,"close",this.onclose.bind(this)),Ot(this.decoder,"decoded",this.ondecoded.bind(this)))}onping(){this.emitReserved("ping")}ondata(t){try{this.decoder.add(t)}catch(t){this.onclose("parse error",t)}}ondecoded(t){L(()=>{this.emitReserved("packet",t)},this.setTimeoutFn)}onerror(t){this.emitReserved("error",t)}socket(t,e){let n=this.nsps[t];return n?this._autoConnect&&!n.active&&n.connect():(n=new At(this,t,e),this.nsps[t]=n),n}_destroy(t){const e=Object.keys(this.nsps);for(const t of e){if(this.nsps[t].active)return}this._close()}_packet(t){const e=this.encoder.encode(t);for(let n=0;n<e.length;n++)this.engine.write(e[n],t.options)}cleanup(){this.subs.forEach(t=>t()),this.subs.length=0,this.decoder.destroy()}_close(){this.skipReconnect=!0,this._reconnecting=!1,this.onclose("forced close")}disconnect(){return this._close()}onclose(t,e){var n;this.cleanup(),null===(n=this.engine)||void 0===n||n.close(),this.backoff.reset(),this._readyState="closed",this.emitReserved("close",t,e),this._reconnection&&!this.skipReconnect&&this.reconnect()}reconnect(){if(this._reconnecting||this.skipReconnect)return this;const t=this;if(this.backoff.attempts>=this._reconnectionAttempts)this.backoff.reset(),this.emitReserved("reconnect_failed"),this._reconnecting=!1;else{const e=this.backoff.duration();this._reconnecting=!0;const n=this.setTimeoutFn(()=>{t.skipReconnect||(this.emitReserved("reconnect_attempt",t.backoff.attempts),t.skipReconnect||t.open(e=>{e?(t._reconnecting=!1,t.reconnect(),this.emitReserved("reconnect_error",e)):t.onreconnect()}))},e);this.opts.autoUnref&&n.unref(),this.subs.push(()=>{this.clearTimeoutFn(n)})}}onreconnect(){const t=this.backoff.attempts;this._reconnecting=!1,this.backoff.reset(),this.emitReserved("reconnect",t)}}const It={};function Bt(t,e){"object"==typeof t&&(e=t,t=void 0);const n=function(t,e="",n){let s=t;n=n||"undefined"!=typeof location&&location,null==t&&(t=n.protocol+"//"+n.host),"string"==typeof t&&("/"===t.charAt(0)&&(t="/"===t.charAt(1)?n.protocol+t:n.host+t),/^(https?|wss?):\/\//.test(t)||(t=void 0!==n?n.protocol+"//"+t:"https://"+t),s=rt(t)),s.port||(/^(http|ws)$/.test(s.protocol)?s.port="80":/^(http|ws)s$/.test(s.protocol)&&(s.port="443")),s.path=s.path||"/";const r=-1!==s.host.indexOf(":")?"["+s.host+"]":s.host;return s.id=s.protocol+"://"+r+":"+s.port+e,s.href=s.protocol+"://"+r+(n&&n.port===s.port?"":":"+s.port),s}(t,(e=e||{}).path||"/socket.io"),s=n.source,r=n.id,i=n.path,o=It[r]&&i in It[r].nsps;let a;return e.forceNew||e["force new connection"]||!1===e.multiplex||o?a=new Nt(s,e):(It[r]||(It[r]=new Nt(s,e)),a=It[r]),n.query&&!e.query&&(e.query=n.queryKey),a.socket(n.path,e)}Object.assign(Bt,{Manager:Nt,Socket:At,io:Bt,connect:Bt}),function(){var t=document.createElement("style");t.textContent="/* Styles will be injected by Rollup */",document.head.appendChild(t);var e=function(){return s(function t(){var e=arguments.length>0&&void 0!==arguments[0]?arguments[0]:{};!function(t,e){if(!(t instanceof e))throw new TypeError("Cannot call a class as a function")}(this,t),this.config={apiKey:e.apiKey||"",apiUrl:e.apiUrl||"https://chat-crm-backend-7mzo.onrender.com",primaryColor:e.primaryColor||"#4F46E5",position:e.position||"bottom-right",userData:e.userData||null,welcomeMessage:e.welcomeMessage||"👋 Welcome! How can we help you today?",companyName:e.companyName||"Support",autoOpen:e.autoOpen||!1,showNotifications:!1!==e.showNotifications,playSound:e.playSound||!1,theme:e.theme||"light",zIndex:e.zIndex||9999},this.state={isOpen:this.config.autoOpen,messages:[],isConnected:!1,isTyping:!1,agentName:"Support Agent",guestId:null,conversationId:null,unreadCount:0,socket:null,widgetSocket:null,petitionId:null,snapshotRequest:null,isCapturing:!1,currentStream:null},this.init()},[{key:"init",value:function(){this.createWidget(),this.attachEventListeners(),this.config.autoOpen&&this.openChat()}},{key:"detectUserInfo",value:function(){for(var t={name:null,email:null,phone:null},e=function(t){var e,n;if(!t)return null;if("META"===t.tagName)return t.getAttribute("content")||null;if("INPUT"===t.tagName||"TEXTAREA"===t.tagName)return t.value||t.getAttribute("value")||t.getAttribute("placeholder")||null;var s=t.getAttribute("data-name")||t.getAttribute("data-user-name")||t.getAttribute("data-full-name")||t.getAttribute("data-display-name")||t.getAttribute("data-email")||t.getAttribute("data-phone");return s||((null===(e=t.textContent)||void 0===e?void 0:e.trim())||(null===(n=t.innerText)||void 0===n?void 0:n.trim())||null)},n=null,s=null,i=null,o=0,a=['[name="firstName"], [name="firstname"], [name="FirstName"], [name="FIRSTNAME"]','[name="lastName"], [name="lastname"], [name="LastName"], [name="LASTNAME"]','[name="fullName"], [name="fullname"], [name="FullName"], [name="FULLNAME"]','[name="userName"], [name="username"], [name="UserName"], [name="USERNAME"]','[name="displayName"], [name="display_name"]','[name="name"], [name="Name"], [name="NAME"]',"#firstName, #firstname, #FirstName, #FIRSTNAME","#lastName, #lastname, #LastName, #LASTNAME","#fullName, #fullname, #FullName, #FULLNAME","#userName, #username, #UserName, #USERNAME","#displayName, #display_name","#name, #Name, #NAME",".firstName, .firstname, .FirstName, .FIRSTNAME",".lastName, .lastname, .LastName, .LASTNAME",".fullName, .fullname, .FullName, .FULLNAME",".userName, .username, .UserName, .USERNAME",".displayName, .display_name",".name, .Name, .NAME","[data-name], [data-user-name], [data-full-name], [data-display-name]",".profile-name, .user-name, .username, .full-name",".header-name, .nav-name, .account-name",'meta[name="user-name"], meta[property="user:name"]'];o<a.length;o++){var c=a[o];try{var h,u=r(document.querySelectorAll(c));try{for(u.s();!(h=u.n()).done;){var l=e(h.value);l&&l.length>1&&"Guest User"!==l&&(c.toLowerCase().includes("firstname")&&!n?n=l:c.toLowerCase().includes("lastname")&&!s?s=l:(c.toLowerCase().includes("fullname")||c.toLowerCase().includes("username")||c.toLowerCase().includes("displayname")||c.toLowerCase().includes("name"))&&!i&&(i=l))}}catch(t){u.e(t)}finally{u.f()}}catch(t){}}n&&s?t.name="".concat(n," ").concat(s):n?t.name=n:s?t.name=s:i&&(t.name=i);for(var d=0,p=['[name="email"], [name="Email"], [name="EMAIL"]','[type="email"]',"#email, #Email, #EMAIL",".email, .Email, .EMAIL","[data-email]",'meta[name="user-email"], meta[property="user:email"]'];d<p.length;d++){var f=p[d];try{var m=e(document.querySelector(f));if(m&&m.includes("@")){t.email=m;break}}catch(t){}}for(var y=0,g=['[name="phone"], [name="Phone"], [name="PHONE"]','[name="phoneNumber"], [name="phone_number"]','[type="tel"]',"#phone, #Phone, #PHONE",".phone, .Phone, .PHONE","[data-phone]"];y<g.length;y++){var v=g[y];try{var b=e(document.querySelector(v));if(b&&/[\d\+\-\(\)\s]{10,}/.test(b)){t.phone=b;break}}catch(t){}}return t}},{key:"getUserData",value:function(){if(this.config.userData)return{name:this.config.userData.name||"Guest User",email:this.config.userData.email||null,phone:this.config.userData.phone||null,userId:this.config.userData.userId||null};var t=this.detectUserInfo();return{name:t.name||localStorage.getItem("chatGuestName")||"Guest User",email:t.email||localStorage.getItem("chatGuestEmail")||null,phone:t.phone||localStorage.getItem("chatGuestPhone")||null,userId:localStorage.getItem("chatUserId")||null}}},{key:"createWidget",value:function(){var t=document.createElement("div");t.id="chat-crm-widget-root",t.className="crm-widget-container",t.style.zIndex=this.config.zIndex,t.innerHTML=this.getWidgetHTML(),document.body.appendChild(t)}},{key:"getWidgetHTML",value:function(){var t=this.getPositionClass();return'\n <button id="crm-chat-button" class="crm-chat-button '.concat(t,'" style="background: linear-gradient(135deg, ').concat(this.config.primaryColor,' 0%, #6366f1 100%);">\n <svg class="crm-icon" fill="none" stroke="currentColor" viewBox="0 0 24 24">\n <path stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="M18 3a3 3 0 0 1 3 3v8a3 3 0 0 1-3 3h-5l-5 3v-3H6a3 3 0 0 1-3-3V6a3 3 0 0 1 3-3h12z"/>\n <circle cx="9" cy="10" r="1" fill="currentColor"/>\n <circle cx="12" cy="10" r="1" fill="currentColor"/>\n <circle cx="15" cy="10" r="1" fill="currentColor"/>\n <path stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="M9 14c.5.5 1.5 1 3 1s2.5-.5 3-1"/>\n </svg>\n <span id="crm-badge" class="crm-badge" style="display: none;">0</span>\n </button>\n\n <div id="crm-chat-window" class="crm-chat-window ').concat(t,'" style="display: none;">\n <div class="crm-header" style="background: linear-gradient(135deg, ').concat(this.config.primaryColor,' 0%, #6366f1 100%);">\n <div class="crm-header-content">\n <div class="crm-avatar">\n <svg width="24" height="24" viewBox="0 0 24 24" fill="none" stroke="').concat(this.config.primaryColor,'" stroke-width="2">\n <path d="M12 2a4 4 0 0 1 4 4v2a4 4 0 0 1-8 0V6a4 4 0 0 1 4-4z"/>\n <path d="M12 14v8"/>\n <path d="M8 22h8"/>\n <path d="M8 14c-2 0-3 1-3 3v1c0 2 1 3 3 3h8c2 0 3-1 3-3v-1c0-2-1-3-3-3H8z"/>\n </svg>\n </div>\n <div>\n <h3 class="crm-title">').concat(this.config.companyName,'</h3>\n <div class="crm-status">\n <div id="crm-status-dot" class="crm-status-dot crm-offline"></div>\n <span id="crm-status-text">Connecting...</span>\n </div>\n </div>\n </div>\n <button id="crm-close-btn" class="crm-close-btn">\n <svg class="crm-icon-sm" fill="none" stroke="currentColor" viewBox="0 0 24 24">\n <path stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="M6 18L18 6M6 6l12 12" />\n </svg>\n </button>\n </div>\n\n <div class="crm-widget-body" style="position: relative; flex: 1; display: flex; flex-direction: column; overflow: hidden;">\n <div id="crm-messages" class="crm-messages">\n <div class="crm-welcome-message">\n <p>').concat(this.config.welcomeMessage,'</p>\n </div>\n </div>\n\n <div class="crm-input-container">\n <div class="crm-input-wrapper">\n <textarea \n id="crm-input" \n class="crm-input" \n placeholder="Type your message..." \n rows="1"\n disabled\n ></textarea>\n <button id="crm-send-btn" class="crm-send-btn" style="background-color: ').concat(this.config.primaryColor,'" disabled>\n <svg class="crm-icon-sm" fill="none" stroke="currentColor" viewBox="0 0 24 24">\n <path stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="M12 19l9 2-9-18-9 18 9-2zm0 0v-8" />\n </svg>\n </button>\n </div>\n <p class="crm-input-hint">Press Enter to send • Shift+Enter for new line</p>\n </div>\n </div>\n </div>\n ')}},{key:"getPositionClass",value:function(){var t={"bottom-right":"crm-bottom-6 crm-right-6","bottom-left":"crm-bottom-6 crm-left-6","top-right":"crm-top-6 crm-right-6","top-left":"crm-top-6 crm-left-6"};return t[this.config.position]||t["bottom-right"]}},{key:"attachEventListeners",value:function(){var t=this;document.getElementById("crm-chat-button").addEventListener("click",function(){return t.toggleChat()}),document.getElementById("crm-close-btn").addEventListener("click",function(){return t.closeChat()}),document.getElementById("crm-send-btn").addEventListener("click",function(){return t.sendMessage()}),document.getElementById("crm-input").addEventListener("keypress",function(e){"Enter"!==e.key||e.shiftKey||(e.preventDefault(),t.sendMessage())})}},{key:"toggleChat",value:function(){this.state.isOpen?this.closeChat():this.openChat()}},{key:"updateButtonIcon",value:function(){var t=document.getElementById("crm-chat-button");if(t){var e=t.querySelector("svg");e&&(this.state.isOpen?e.innerHTML='<path stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="M6 18L18 6M6 6l12 12" />':e.innerHTML='<path stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="M8 12h.01M12 12h.01M16 12h.01M21 12c0 4.418-4.03 8-9 8a9.863 9.863 0 01-4.255-.949L3 20l1.395-3.72C3.512 15.042 3 13.574 3 12c0-4.418 4.03-8 9-8s9 3.582 9 8z" />')}}},{key:"openChat",value:(l=n(c().m(function t(){return c().w(function(t){for(;;)switch(t.n){case 0:if(this.state.isOpen=!0,this.state.unreadCount=0,document.getElementById("crm-chat-window").style.display="flex",document.getElementById("crm-badge").style.display="none",this.updateButtonIcon(),this.state.socket){t.n=1;break}return t.n=1,this.initializeChat();case 1:return t.a(2)}},t,this)})),function(){return l.apply(this,arguments)})},{key:"closeChat",value:function(){this.state.isOpen=!1,document.getElementById("crm-chat-window").style.display="none",this.updateButtonIcon()}},{key:"initializeChat",value:(u=n(c().m(function t(){var e,n,s,r;return c().w(function(t){for(;;)switch(t.p=t.n){case 0:return t.p=0,e=this.getUserData(),t.n=1,fetch("".concat(this.config.apiUrl,"/api/v1/webhook/guest-conversation"),{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({apiKey:this.config.apiKey,guestName:e.name,guestEmail:e.email,guestPhone:e.phone,customUserId:e.userId})});case 1:return n=t.v,t.n=2,n.json();case 2:(s=t.v).status&&(this.state.guestId=s.data.guestId,this.state.conversationId=s.data.conversationId,this.state.petitionId=s.data.petitionId||s.petitionId,localStorage.setItem("chatGuestId",this.state.guestId),localStorage.setItem("chatConversationId",this.state.conversationId),this.state.petitionId&&localStorage.setItem("chatPetitionId",this.state.petitionId),this.connectSocket(),this.connectWidgetNamespace()),t.n=4;break;case 3:t.p=3,r=t.v,console.error("❌ Chat initialization error:",r),alert("Failed to connect to chat. Please try again.");case 4:return t.a(2)}},t,this,[[0,3]])})),function(){return u.apply(this,arguments)})},{key:"connectSocket",value:function(){var t=this;this.state.socket=Bt(this.config.apiUrl,{query:{guestId:this.state.guestId,conversationId:this.state.conversationId,apiKey:this.config.apiKey},transports:["websocket","polling"]}),this.state.socket.on("connect",function(){t.state.isConnected=!0,t.updateConnectionStatus(!0),document.getElementById("crm-input").disabled=!1,document.getElementById("crm-send-btn").disabled=!1}),this.state.socket.on("disconnect",function(){t.state.isConnected=!1,t.updateConnectionStatus(!1)}),this.state.socket.on("new-message",function(e){t.addMessage(a(a({},e),{},{sender:"agent",timestamp:new Date})),!t.state.isOpen&&t.config.showNotifications&&(t.state.unreadCount++,t.updateBadge(),t.config.playSound&&t.playNotificationSound())}),this.state.socket.on("agent-typing",function(e){t.state.agentName=e.agentName||"Support Agent",t.showTypingIndicator()})}},{key:"connectWidgetNamespace",value:function(){var t=this;try{if(!this.state.conversationId)return;var e=this.state.petitionId||localStorage.getItem("chatPetitionId");this.state.widgetSocket=Bt("".concat(this.config.apiUrl,"/widget"),{query:{conversationId:this.state.conversationId,petitionId:e,apiKey:this.config.apiKey},transports:["websocket","polling"]}),this.state.widgetSocket.on("connect",function(){}),this.state.widgetSocket.on("disconnect",function(){}),this.state.widgetSocket.on("request-camera-snapshot",function(e){try{var n,s=localStorage.getItem("chatPetitionId");if(null!=e&&e.petitionId&&s&&e.petitionId===s)t.state.snapshotRequest={requesterName:e.requesterName||(null===(n=e.requester)||void 0===n?void 0:n.name)||"Agent",at:Date.now()},t.showSnapshotModal()}catch(t){}})}catch(t){console.error("Widget namespace connect error:",t)}}},{key:"updateConnectionStatus",value:function(t){var e=document.getElementById("crm-status-dot"),n=document.getElementById("crm-status-text");t?(e.classList.remove("crm-offline"),e.classList.add("crm-online"),n.textContent="Online"):(e.classList.remove("crm-online"),e.classList.add("crm-offline"),n.textContent="Connecting...")}},{key:"updateBadge",value:function(){var t=document.getElementById("crm-badge");this.state.unreadCount>0?(t.textContent=this.state.unreadCount,t.style.display="flex"):t.style.display="none"}},{key:"addMessage",value:function(t){this.state.messages.push(t);var e=document.getElementById("crm-messages"),n=document.createElement("div");n.className="crm-message crm-message-".concat(t.sender);var s="guest"===t.sender?'style="background-color: '.concat(this.config.primaryColor,'"'):"",r=String(t.message||""),i=r.match(/https?:[^\s]+\.(?:png|jpg|jpeg|gif|webp)/i),o='<p class="crm-message-text">'.concat(this.escapeHtml(r),"</p>");if(i){var a=i[0],c=r.replace(a,"").trim(),h=c?'<p class="crm-message-text" style="opacity:0.85">'.concat(this.escapeHtml(c),"</p>"):"";o="".concat(h,'<img src="').concat(this.escapeHtml(a),'" alt="snapshot" style="max-width:240px;max-height:180px;border-radius:8px;border:1px solid #E5E7EB;display:block" />')}n.innerHTML='\n <div class="crm-message-bubble" '.concat(s,">\n ").concat("agent"===t.sender?'<p class="crm-agent-name">'.concat(this.state.agentName,"</p>"):"","\n ").concat(o,'\n <p class="crm-message-time">').concat(this.formatTime(t.timestamp),"</p>\n </div>\n "),e.appendChild(n),e.scrollTop=e.scrollHeight}},{key:"showSnapshotModal",value:function(){this.showCameraInWidget()}},{key:"showCameraInWidget",value:function(){var t,e,n,s,r,i,o=this;if(document.getElementById("crm-messages")){var a=document.createElement("div");a.id="crm-camera-interface",a.style.cssText="\n position: absolute;\n top: 0;\n left: 0;\n right: 0;\n bottom: 0;\n background: #fff;\n display: flex;\n flex-direction: column;\n z-index: 1000;\n ",a.innerHTML='\n <div style="padding: 16px; border-bottom: 1px solid #E5E7EB; display: flex; justify-content: space-between; align-items: center;">\n <h3 style="margin: 0; font-size: 16px; font-weight: 600; color: #111827;">Camera Access</h3>\n <button id="crm-camera-close" style="background: none; border: none; font-size: 24px; cursor: pointer; color: #6B7280; padding: 0; width: 32px; height: 32px; display: flex; align-items: center; justify-content: center;">×</button>\n </div>\n \n <div style="flex: 1; display: flex; flex-direction: column; padding: 16px; overflow: hidden;">\n <p style="margin: 0 0 12px 0; font-size: 14px; color: #6B7280;">\n '.concat(this.escapeHtml((null===(t=this.state.snapshotRequest)||void 0===t?void 0:t.requesterName)||"Agent"),' is requesting a photo from your camera.\n </p>\n \n <div id="crm-camera-preview" style="flex: 1; background: #000; border-radius: 8px; position: relative; overflow: hidden; display: flex; align-items: center; justify-content: center; min-height: 200px;">\n <video id="crm-video-stream" autoplay playsinline style="width: 100%; height: 100%; object-fit: cover; display: none;"></video>\n <canvas id="crm-canvas-capture" style="width: 100%; height: 100%; object-fit: contain; display: none;"></canvas>\n <div id="crm-camera-loading" style="color: #fff; text-align: center;">\n <div style="font-size: 14px;">Initializing camera...</div>\n </div>\n </div>\n \n <div id="crm-camera-controls" style="margin-top: 16px; display: flex; gap: 8px; justify-content: center;">\n <button id="crm-camera-cancel" style="padding: 10px 20px; border: 1px solid #E5E7EB; background: #fff; color: #374151; border-radius: 6px; cursor: pointer; font-size: 14px; font-weight: 500;">\n Cancel\n </button>\n <button id="crm-camera-capture" style="padding: 10px 20px; border: none; background: ').concat(this.config.primaryColor,'; color: #fff; border-radius: 6px; cursor: pointer; font-size: 14px; font-weight: 500;">\n Capture\n </button>\n </div>\n \n <div id="crm-camera-review-controls" style="margin-top: 16px; display: none; gap: 8px; justify-content: center;">\n <button id="crm-camera-retake" style="padding: 10px 20px; border: 1px solid #E5E7EB; background: #fff; color: #374151; border-radius: 6px; cursor: pointer; font-size: 14px; font-weight: 500;">\n Retake\n </button>\n <button id="crm-camera-submit" style="padding: 10px 20px; border: none; background: ').concat(this.config.primaryColor,'; color: #fff; border-radius: 6px; cursor: pointer; font-size: 14px; font-weight: 500;">\n Submit\n </button>\n </div>\n </div>\n ');var c=document.querySelector(".crm-widget-body");c&&c.appendChild(a),this.initializeCamera(),null===(e=document.getElementById("crm-camera-close"))||void 0===e||e.addEventListener("click",function(){return o.closeCameraInterface()}),null===(n=document.getElementById("crm-camera-cancel"))||void 0===n||n.addEventListener("click",function(){return o.closeCameraInterface()}),null===(s=document.getElementById("crm-camera-capture"))||void 0===s||s.addEventListener("click",function(){return o.capturePhoto()}),null===(r=document.getElementById("crm-camera-retake"))||void 0===r||r.addEventListener("click",function(){return o.retakePhoto()}),null===(i=document.getElementById("crm-camera-submit"))||void 0===i||i.addEventListener("click",function(){return o.submitPhoto()})}}},{key:"initializeCamera",value:(h=n(c().m(function t(){var e,n,s,r,i;return c().w(function(t){for(;;)switch(t.p=t.n){case 0:return t.p=0,e=document.getElementById("crm-video-stream"),n=document.getElementById("crm-camera-loading"),t.n=1,navigator.mediaDevices.getUserMedia({video:{facingMode:"user",width:{ideal:1280},height:{ideal:720}}});case 1:if(s=t.v,!e){t.n=3;break}return e.srcObject=s,this.currentStream=s,t.n=2,e.play();case 2:e.style.display="block",n&&(n.style.display="none");case 3:t.n=5;break;case 4:t.p=4,i=t.v,console.error("Camera access error:",i),(r=document.getElementById("crm-camera-loading"))&&(r.innerHTML='<div style="color: #EF4444; font-size: 14px;">Camera access denied<br/><small style="font-size: 12px; opacity: 0.8;">Please allow camera permission</small></div>'),alert("Camera permission denied. Please allow camera access and try again.");case 5:return t.a(2)}},t,this,[[0,4]])})),function(){return h.apply(this,arguments)})},{key:"capturePhoto",value:function(){var t=document.getElementById("crm-video-stream"),e=document.getElementById("crm-canvas-capture");t&&e&&(e.width=t.videoWidth||640,e.height=t.videoHeight||480,e.getContext("2d").drawImage(t,0,0,e.width,e.height),t.style.display="none",e.style.display="block",document.getElementById("crm-camera-controls").style.display="none",document.getElementById("crm-camera-review-controls").style.display="flex",this.currentStream&&(this.currentStream.getTracks().forEach(function(t){return t.stop()}),this.currentStream=null))}},{key:"retakePhoto",value:function(){var t=document.getElementById("crm-video-stream"),e=document.getElementById("crm-canvas-capture");t&&(t.style.display="block"),e&&(e.style.display="none"),document.getElementById("crm-camera-controls").style.display="flex",document.getElementById("crm-camera-review-controls").style.display="none",this.initializeCamera()}},{key:"submitPhoto",value:(o=n(c().m(function t(){var e,n,s,r;return c().w(function(t){for(;;)switch(t.p=t.n){case 0:if(e=document.getElementById("crm-canvas-capture")){t.n=1;break}return t.a(2);case 1:return(n=document.getElementById("crm-camera-submit"))&&(n.textContent="Uploading...",n.disabled=!0),t.p=2,t.n=3,new Promise(function(t){return e.toBlob(t,"image/png")});case 3:if(s=t.v){t.n=4;break}throw new Error("Failed to capture image");case 4:return t.n=5,this.uploadSnapshot(s);case 5:this.closeCameraInterface(),t.n=7;break;case 6:t.p=6,r=t.v,console.error("Upload error:",r),alert("Failed to upload photo. Please try again."),n&&(n.textContent="Submit",n.disabled=!1);case 7:return t.a(2)}},t,this,[[2,6]])})),function(){return o.apply(this,arguments)})},{key:"closeCameraInterface",value:function(){this.currentStream&&(this.currentStream.getTracks().forEach(function(t){return t.stop()}),this.currentStream=null);var t=document.getElementById("crm-camera-interface");t&&t.remove(),this.state.snapshotRequest=null}},{key:"uploadSnapshot",value:(i=n(c().m(function t(e){var n,s,r,i,o,a,h,u,l;return c().w(function(t){for(;;)switch(t.n){case 0:return r=this.state.petitionId||localStorage.getItem("chatPetitionId"),i=new FormData,o="snapshot-".concat(r,"-").concat(Date.now(),".png"),i.append("screenshot",e,o),i.append("petitionId",r),i.append("apiKey",this.config.apiKey),i.append("metadata",JSON.stringify({source:"widget",requesterName:null===(n=this.state.snapshotRequest)||void 0===n?void 0:n.requesterName})),t.n=1,fetch("".concat(this.config.apiUrl,"/api/v1/webhook/upload-snapshot"),{method:"POST",body:i});case 1:return a=t.v,t.n=2,a.json();case 2:if(h=t.v,!(u=null==h||null===(s=h.data)||void 0===s?void 0:s.imageUrl)){t.n=3;break}return l=new Date,this.addMessage({message:"📸 Screenshot: ".concat(u),sender:"guest",timestamp:l}),t.n=3,fetch("".concat(this.config.apiUrl,"/api/v1/webhook/send-message"),{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({apiKey:this.config.apiKey,petitionId:r,message:"📸 Screenshot: ".concat(u),senderName:"Guest User"})});case 3:return t.a(2)}},t,this)})),function(t){return i.apply(this,arguments)})},{key:"captureAndUploadSnapshot",value:(e=n(c().m(function t(){return c().w(function(t){for(;;)switch(t.n){case 0:this.showCameraInWidget();case 1:return t.a(2)}},t,this)})),function(){return e.apply(this,arguments)})},{key:"sendMessage",value:(t=n(c().m(function t(){var e,n,s,r;return c().w(function(t){for(;;)switch(t.p=t.n){case 0:if(e=document.getElementById("crm-input"),(n=e.value.trim())&&this.state.isConnected){t.n=1;break}return t.a(2);case 1:return s={guestId:this.state.guestId,conversationId:this.state.conversationId,message:n,timestamp:new Date},t.p=2,this.addMessage(a(a({},s),{},{sender:"guest"})),e.value="",this.state.socket.emit("send-message",s),t.n=3,fetch("".concat(this.config.apiUrl,"/api/v1/webhook/send-message"),{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({apiKey:this.config.apiKey,guestId:this.state.guestId,conversationId:this.state.conversationId,message:n})});case 3:t.n=5;break;case 4:t.p=4,r=t.v,console.error("❌ Send message error:",r),alert("Failed to send message. Please try again.");case 5:return t.a(2)}},t,this,[[2,4]])})),function(){return t.apply(this,arguments)})},{key:"showTypingIndicator",value:function(){var t=this;this.state.isTyping=!0,setTimeout(function(){t.state.isTyping=!1},3e3)}},{key:"playNotificationSound",value:function(){try{var t=new(window.AudioContext||window.webkitAudioContext),e=t.createOscillator(),n=t.createGain();e.connect(n),n.connect(t.destination),e.frequency.value=800,e.type="sine",n.gain.value=.1,e.start(),setTimeout(function(){return e.stop()},200)}catch(t){console.log("Sound playback not available")}}},{key:"formatTime",value:function(t){return new Date(t).toLocaleTimeString("en-US",{hour:"2-digit",minute:"2-digit"})}},{key:"escapeHtml",value:function(t){var e=document.createElement("div");return e.textContent=t,e.innerHTML}},{key:"setupOutsideClick",value:function(){var t=this,e=function(e){if(t.state.isOpen){var n=document.getElementById("crm-chat-window"),s=document.getElementById("crm-chat-button");n&&!n.contains(e.target)&&s&&!s.contains(e.target)&&t.closeChat()}};document.addEventListener("mousedown",e),document.addEventListener("touchstart",e)}}]);var t,e,i,o,h,u,l}();window.ChatCRMWidget={init:function(t){var n=new e(t);return n.setupOutsideClick(),n}}}()}();
|
|
3
|
+
var t,e,n="function"==typeof Symbol?Symbol:{},s=n.iterator||"@@iterator",r=n.toStringTag||"@@toStringTag";function i(n,s,r,i){var c=s&&s.prototype instanceof a?s:a,u=Object.create(c.prototype);return h(u,"_invoke",function(n,s,r){var i,a,c,h=0,u=r||[],l=!1,d={p:0,n:0,v:t,a:p,f:p.bind(t,4),d:function(e,n){return i=e,a=0,c=t,d.n=n,o}};function p(n,s){for(a=n,c=s,e=0;!l&&h&&!r&&e<u.length;e++){var r,i=u[e],p=d.p,f=i[2];n>3?(r=f===s)&&(c=i[(a=i[4])?5:(a=3,3)],i[4]=i[5]=t):i[0]<=p&&((r=n<2&&p<i[1])?(a=0,d.v=s,d.n=i[1]):p<f&&(r=n<3||i[0]>s||s>f)&&(i[4]=n,i[5]=s,d.n=f,a=0))}if(r||n>1)return o;throw l=!0,s}return function(r,u,f){if(h>1)throw TypeError("Generator is already running");for(l&&1===u&&p(u,f),a=u,c=f;(e=a<2?t:c)||!l;){i||(a?a<3?(a>1&&(d.n=-1),p(a,c)):d.n=c:d.v=c);try{if(h=2,i){if(a||(r="next"),e=i[r]){if(!(e=e.call(i,c)))throw TypeError("iterator result is not an object");if(!e.done)return e;c=e.value,a<2&&(a=0)}else 1===a&&(e=i.return)&&e.call(i),a<2&&(c=TypeError("The iterator does not provide a '"+r+"' method"),a=1);i=t}else if((e=(l=d.n<0)?c:n.call(s,d))!==o)break}catch(e){i=t,a=1,c=e}finally{h=1}}return{value:e,done:l}}}(n,r,i),!0),u}var o={};function a(){}function u(){}function l(){}e=Object.getPrototypeOf;var d=[][s]?e(e([][s]())):(h(e={},s,function(){return this}),e),p=l.prototype=a.prototype=Object.create(d);function f(t){return Object.setPrototypeOf?Object.setPrototypeOf(t,l):(t.__proto__=l,h(t,r,"GeneratorFunction")),t.prototype=Object.create(p),t}return u.prototype=l,h(p,"constructor",l),h(l,"constructor",u),u.displayName="GeneratorFunction",h(l,r,"GeneratorFunction"),h(p),h(p,r,"Generator"),h(p,s,function(){return this}),h(p,"toString",function(){return"[object Generator]"}),(c=function(){return{w:i,m:f}})()}function h(t,e,n,s){var r=Object.defineProperty;try{r({},"",{})}catch(t){r=0}h=function(t,e,n,s){function i(e,n){h(t,e,function(t){return this._invoke(e,n,t)})}e?r?r(t,e,{value:n,enumerable:!s,configurable:!s,writable:!s}):t[e]=n:(i("next",0),i("throw",1),i("return",2))},h(t,e,n,s)}function u(t){var e=function(t,e){if("object"!=typeof t||!t)return t;var n=t[Symbol.toPrimitive];if(void 0!==n){var s=n.call(t,e);if("object"!=typeof s)return s;throw new TypeError("@@toPrimitive must return a primitive value.")}return String(t)}(t,"string");return"symbol"==typeof e?e:e+""}const l=Object.create(null);l.open="0",l.close="1",l.ping="2",l.pong="3",l.message="4",l.upgrade="5",l.noop="6";const d=Object.create(null);Object.keys(l).forEach(t=>{d[l[t]]=t});const p={type:"error",data:"parser error"},f="function"==typeof Blob||"undefined"!=typeof Blob&&"[object BlobConstructor]"===Object.prototype.toString.call(Blob),m="function"==typeof ArrayBuffer,y=t=>"function"==typeof ArrayBuffer.isView?ArrayBuffer.isView(t):t&&t.buffer instanceof ArrayBuffer,g=({type:t,data:e},n,s)=>f&&e instanceof Blob?n?s(e):v(e,s):m&&(e instanceof ArrayBuffer||y(e))?n?s(e):v(new Blob([e]),s):s(l[t]+(e||"")),v=(t,e)=>{const n=new FileReader;return n.onload=function(){const t=n.result.split(",")[1];e("b"+(t||""))},n.readAsDataURL(t)};function b(t){return t instanceof Uint8Array?t:t instanceof ArrayBuffer?new Uint8Array(t):new Uint8Array(t.buffer,t.byteOffset,t.byteLength)}let w;const k="ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/",_="undefined"==typeof Uint8Array?[]:new Uint8Array(256);for(let t=0;t<64;t++)_[k.charCodeAt(t)]=t;const E="function"==typeof ArrayBuffer,C=(t,e)=>{if("string"!=typeof t)return{type:"message",data:O(t,e)};const n=t.charAt(0);if("b"===n)return{type:"message",data:x(t.substring(1),e)};return d[n]?t.length>1?{type:d[n],data:t.substring(1)}:{type:d[n]}:p},x=(t,e)=>{if(E){const n=(t=>{let e,n,s,r,i,o=.75*t.length,a=t.length,c=0;"="===t[t.length-1]&&(o--,"="===t[t.length-2]&&o--);const h=new ArrayBuffer(o),u=new Uint8Array(h);for(e=0;e<a;e+=4)n=_[t.charCodeAt(e)],s=_[t.charCodeAt(e+1)],r=_[t.charCodeAt(e+2)],i=_[t.charCodeAt(e+3)],u[c++]=n<<2|s>>4,u[c++]=(15&s)<<4|r>>2,u[c++]=(3&r)<<6|63&i;return h})(t);return O(n,e)}return{base64:!0,data:t}},O=(t,e)=>"blob"===e?t instanceof Blob?t:new Blob([t]):t instanceof ArrayBuffer?t:t.buffer,A=String.fromCharCode(30);function S(){return new TransformStream({transform(t,e){!function(t,e){f&&t.data instanceof Blob?t.data.arrayBuffer().then(b).then(e):m&&(t.data instanceof ArrayBuffer||y(t.data))?e(b(t.data)):g(t,!1,t=>{w||(w=new TextEncoder),e(w.encode(t))})}(t,n=>{const s=n.length;let r;if(s<126)r=new Uint8Array(1),new DataView(r.buffer).setUint8(0,s);else if(s<65536){r=new Uint8Array(3);const t=new DataView(r.buffer);t.setUint8(0,126),t.setUint16(1,s)}else{r=new Uint8Array(9);const t=new DataView(r.buffer);t.setUint8(0,127),t.setBigUint64(1,BigInt(s))}t.data&&"string"!=typeof t.data&&(r[0]|=128),e.enqueue(r),e.enqueue(n)})}})}let T;function N(t){return t.reduce((t,e)=>t+e.length,0)}function I(t,e){if(t[0].length===e)return t.shift();const n=new Uint8Array(e);let s=0;for(let r=0;r<e;r++)n[r]=t[0][s++],s===t[0].length&&(t.shift(),s=0);return t.length&&s<t[0].length&&(t[0]=t[0].slice(s)),n}function B(t){if(t)return function(t){for(var e in B.prototype)t[e]=B.prototype[e];return t}(t)}B.prototype.on=B.prototype.addEventListener=function(t,e){return this._callbacks=this._callbacks||{},(this._callbacks["$"+t]=this._callbacks["$"+t]||[]).push(e),this},B.prototype.once=function(t,e){function n(){this.off(t,n),e.apply(this,arguments)}return n.fn=e,this.on(t,n),this},B.prototype.off=B.prototype.removeListener=B.prototype.removeAllListeners=B.prototype.removeEventListener=function(t,e){if(this._callbacks=this._callbacks||{},0==arguments.length)return this._callbacks={},this;var n,s=this._callbacks["$"+t];if(!s)return this;if(1==arguments.length)return delete this._callbacks["$"+t],this;for(var r=0;r<s.length;r++)if((n=s[r])===e||n.fn===e){s.splice(r,1);break}return 0===s.length&&delete this._callbacks["$"+t],this},B.prototype.emit=function(t){this._callbacks=this._callbacks||{};for(var e=new Array(arguments.length-1),n=this._callbacks["$"+t],s=1;s<arguments.length;s++)e[s-1]=arguments[s];if(n){s=0;for(var r=(n=n.slice(0)).length;s<r;++s)n[s].apply(this,e)}return this},B.prototype.emitReserved=B.prototype.emit,B.prototype.listeners=function(t){return this._callbacks=this._callbacks||{},this._callbacks["$"+t]||[]},B.prototype.hasListeners=function(t){return!!this.listeners(t).length};const R="function"==typeof Promise&&"function"==typeof Promise.resolve?t=>Promise.resolve().then(t):(t,e)=>e(t,0),L="undefined"!=typeof self?self:"undefined"!=typeof window?window:Function("return this")();function P(t,...e){return e.reduce((e,n)=>(t.hasOwnProperty(n)&&(e[n]=t[n]),e),{})}const j=L.setTimeout,M=L.clearTimeout;function q(t,e){e.useNativeTimers?(t.setTimeoutFn=j.bind(L),t.clearTimeoutFn=M.bind(L)):(t.setTimeoutFn=L.setTimeout.bind(L),t.clearTimeoutFn=L.clearTimeout.bind(L))}function U(t){return"string"==typeof t?function(t){let e=0,n=0;for(let s=0,r=t.length;s<r;s++)e=t.charCodeAt(s),e<128?n+=1:e<2048?n+=2:e<55296||e>=57344?n+=3:(s++,n+=4);return n}(t):Math.ceil(1.33*(t.byteLength||t.size))}function D(){return Date.now().toString(36).substring(3)+Math.random().toString(36).substring(2,5)}class F extends Error{constructor(t,e,n){super(t),this.description=e,this.context=n,this.type="TransportError"}}class H extends B{constructor(t){super(),this.writable=!1,q(this,t),this.opts=t,this.query=t.query,this.socket=t.socket,this.supportsBinary=!t.forceBase64}onError(t,e,n){return super.emitReserved("error",new F(t,e,n)),this}open(){return this.readyState="opening",this.doOpen(),this}close(){return"opening"!==this.readyState&&"open"!==this.readyState||(this.doClose(),this.onClose()),this}send(t){"open"===this.readyState&&this.write(t)}onOpen(){this.readyState="open",this.writable=!0,super.emitReserved("open")}onData(t){const e=C(t,this.socket.binaryType);this.onPacket(e)}onPacket(t){super.emitReserved("packet",t)}onClose(t){this.readyState="closed",super.emitReserved("close",t)}pause(t){}createUri(t,e={}){return t+"://"+this._hostname()+this._port()+this.opts.path+this._query(e)}_hostname(){const t=this.opts.hostname;return-1===t.indexOf(":")?t:"["+t+"]"}_port(){return this.opts.port&&(this.opts.secure&&443!==Number(this.opts.port)||!this.opts.secure&&80!==Number(this.opts.port))?":"+this.opts.port:""}_query(t){const e=function(t){let e="";for(let n in t)t.hasOwnProperty(n)&&(e.length&&(e+="&"),e+=encodeURIComponent(n)+"="+encodeURIComponent(t[n]));return e}(t);return e.length?"?"+e:""}}class z extends H{constructor(){super(...arguments),this._polling=!1}get name(){return"polling"}doOpen(){this._poll()}pause(t){this.readyState="pausing";const e=()=>{this.readyState="paused",t()};if(this._polling||!this.writable){let t=0;this._polling&&(t++,this.once("pollComplete",function(){--t||e()})),this.writable||(t++,this.once("drain",function(){--t||e()}))}else e()}_poll(){this._polling=!0,this.doPoll(),this.emitReserved("poll")}onData(t){((t,e)=>{const n=t.split(A),s=[];for(let t=0;t<n.length;t++){const r=C(n[t],e);if(s.push(r),"error"===r.type)break}return s})(t,this.socket.binaryType).forEach(t=>{if("opening"===this.readyState&&"open"===t.type&&this.onOpen(),"close"===t.type)return this.onClose({description:"transport closed by the server"}),!1;this.onPacket(t)}),"closed"!==this.readyState&&(this._polling=!1,this.emitReserved("pollComplete"),"open"===this.readyState&&this._poll())}doClose(){const t=()=>{this.write([{type:"close"}])};"open"===this.readyState?t():this.once("open",t)}write(t){this.writable=!1,((t,e)=>{const n=t.length,s=new Array(n);let r=0;t.forEach((t,i)=>{g(t,!1,t=>{s[i]=t,++r===n&&e(s.join(A))})})})(t,t=>{this.doWrite(t,()=>{this.writable=!0,this.emitReserved("drain")})})}uri(){const t=this.opts.secure?"https":"http",e=this.query||{};return!1!==this.opts.timestampRequests&&(e[this.opts.timestampParam]=D()),this.supportsBinary||e.sid||(e.b64=1),this.createUri(t,e)}}let K=!1;try{K="undefined"!=typeof XMLHttpRequest&&"withCredentials"in new XMLHttpRequest}catch(t){}const V=K;function W(){}class G extends z{constructor(t){if(super(t),"undefined"!=typeof location){const e="https:"===location.protocol;let n=location.port;n||(n=e?"443":"80"),this.xd="undefined"!=typeof location&&t.hostname!==location.hostname||n!==t.port}}doWrite(t,e){const n=this.request({method:"POST",data:t});n.on("success",e),n.on("error",(t,e)=>{this.onError("xhr post error",t,e)})}doPoll(){const t=this.request();t.on("data",this.onData.bind(this)),t.on("error",(t,e)=>{this.onError("xhr poll error",t,e)}),this.pollXhr=t}}class Y extends B{constructor(t,e,n){super(),this.createRequest=t,q(this,n),this._opts=n,this._method=n.method||"GET",this._uri=e,this._data=void 0!==n.data?n.data:null,this._create()}_create(){var t;const e=P(this._opts,"agent","pfx","key","passphrase","cert","ca","ciphers","rejectUnauthorized","autoUnref");e.xdomain=!!this._opts.xd;const n=this._xhr=this.createRequest(e);try{n.open(this._method,this._uri,!0);try{if(this._opts.extraHeaders){n.setDisableHeaderCheck&&n.setDisableHeaderCheck(!0);for(let t in this._opts.extraHeaders)this._opts.extraHeaders.hasOwnProperty(t)&&n.setRequestHeader(t,this._opts.extraHeaders[t])}}catch(t){}if("POST"===this._method)try{n.setRequestHeader("Content-type","text/plain;charset=UTF-8")}catch(t){}try{n.setRequestHeader("Accept","*/*")}catch(t){}null===(t=this._opts.cookieJar)||void 0===t||t.addCookies(n),"withCredentials"in n&&(n.withCredentials=this._opts.withCredentials),this._opts.requestTimeout&&(n.timeout=this._opts.requestTimeout),n.onreadystatechange=()=>{var t;3===n.readyState&&(null===(t=this._opts.cookieJar)||void 0===t||t.parseCookies(n.getResponseHeader("set-cookie"))),4===n.readyState&&(200===n.status||1223===n.status?this._onLoad():this.setTimeoutFn(()=>{this._onError("number"==typeof n.status?n.status:0)},0))},n.send(this._data)}catch(t){return void this.setTimeoutFn(()=>{this._onError(t)},0)}"undefined"!=typeof document&&(this._index=Y.requestsCount++,Y.requests[this._index]=this)}_onError(t){this.emitReserved("error",t,this._xhr),this._cleanup(!0)}_cleanup(t){if(void 0!==this._xhr&&null!==this._xhr){if(this._xhr.onreadystatechange=W,t)try{this._xhr.abort()}catch(t){}"undefined"!=typeof document&&delete Y.requests[this._index],this._xhr=null}}_onLoad(){const t=this._xhr.responseText;null!==t&&(this.emitReserved("data",t),this.emitReserved("success"),this._cleanup())}abort(){this._cleanup()}}if(Y.requestsCount=0,Y.requests={},"undefined"!=typeof document)if("function"==typeof attachEvent)attachEvent("onunload",J);else if("function"==typeof addEventListener){addEventListener("onpagehide"in L?"pagehide":"unload",J,!1)}function J(){for(let t in Y.requests)Y.requests.hasOwnProperty(t)&&Y.requests[t].abort()}const $=function(){const t=X({xdomain:!1});return t&&null!==t.responseType}();function X(t){const e=t.xdomain;try{if("undefined"!=typeof XMLHttpRequest&&(!e||V))return new XMLHttpRequest}catch(t){}if(!e)try{return new(L[["Active"].concat("Object").join("X")])("Microsoft.XMLHTTP")}catch(t){}}const Q="undefined"!=typeof navigator&&"string"==typeof navigator.product&&"reactnative"===navigator.product.toLowerCase();class Z extends H{get name(){return"websocket"}doOpen(){const t=this.uri(),e=this.opts.protocols,n=Q?{}:P(this.opts,"agent","perMessageDeflate","pfx","key","passphrase","cert","ca","ciphers","rejectUnauthorized","localAddress","protocolVersion","origin","maxPayload","family","checkServerIdentity");this.opts.extraHeaders&&(n.headers=this.opts.extraHeaders);try{this.ws=this.createSocket(t,e,n)}catch(t){return this.emitReserved("error",t)}this.ws.binaryType=this.socket.binaryType,this.addEventListeners()}addEventListeners(){this.ws.onopen=()=>{this.opts.autoUnref&&this.ws._socket.unref(),this.onOpen()},this.ws.onclose=t=>this.onClose({description:"websocket connection closed",context:t}),this.ws.onmessage=t=>this.onData(t.data),this.ws.onerror=t=>this.onError("websocket error",t)}write(t){this.writable=!1;for(let e=0;e<t.length;e++){const n=t[e],s=e===t.length-1;g(n,this.supportsBinary,t=>{try{this.doWrite(n,t)}catch(t){}s&&R(()=>{this.writable=!0,this.emitReserved("drain")},this.setTimeoutFn)})}}doClose(){void 0!==this.ws&&(this.ws.onerror=()=>{},this.ws.close(),this.ws=null)}uri(){const t=this.opts.secure?"wss":"ws",e=this.query||{};return this.opts.timestampRequests&&(e[this.opts.timestampParam]=D()),this.supportsBinary||(e.b64=1),this.createUri(t,e)}}const tt=L.WebSocket||L.MozWebSocket;const et={websocket:class extends Z{createSocket(t,e,n){return Q?new tt(t,e,n):e?new tt(t,e):new tt(t)}doWrite(t,e){this.ws.send(e)}},webtransport:class extends H{get name(){return"webtransport"}doOpen(){try{this._transport=new WebTransport(this.createUri("https"),this.opts.transportOptions[this.name])}catch(t){return this.emitReserved("error",t)}this._transport.closed.then(()=>{this.onClose()}).catch(t=>{this.onError("webtransport error",t)}),this._transport.ready.then(()=>{this._transport.createBidirectionalStream().then(t=>{const e=function(t,e){T||(T=new TextDecoder);const n=[];let s=0,r=-1,i=!1;return new TransformStream({transform(o,a){for(n.push(o);;){if(0===s){if(N(n)<1)break;const t=I(n,1);i=!(128&~t[0]),r=127&t[0],s=r<126?3:126===r?1:2}else if(1===s){if(N(n)<2)break;const t=I(n,2);r=new DataView(t.buffer,t.byteOffset,t.length).getUint16(0),s=3}else if(2===s){if(N(n)<8)break;const t=I(n,8),e=new DataView(t.buffer,t.byteOffset,t.length),i=e.getUint32(0);if(i>Math.pow(2,21)-1){a.enqueue(p);break}r=i*Math.pow(2,32)+e.getUint32(4),s=3}else{if(N(n)<r)break;const t=I(n,r);a.enqueue(C(i?t:T.decode(t),e)),s=0}if(0===r||r>t){a.enqueue(p);break}}}})}(Number.MAX_SAFE_INTEGER,this.socket.binaryType),n=t.readable.pipeThrough(e).getReader(),s=S();s.readable.pipeTo(t.writable),this._writer=s.writable.getWriter();const r=()=>{n.read().then(({done:t,value:e})=>{t||(this.onPacket(e),r())}).catch(t=>{})};r();const i={type:"open"};this.query.sid&&(i.data=`{"sid":"${this.query.sid}"}`),this._writer.write(i).then(()=>this.onOpen())})})}write(t){this.writable=!1;for(let e=0;e<t.length;e++){const n=t[e],s=e===t.length-1;this._writer.write(n).then(()=>{s&&R(()=>{this.writable=!0,this.emitReserved("drain")},this.setTimeoutFn)})}}doClose(){var t;null===(t=this._transport)||void 0===t||t.close()}},polling:class extends G{constructor(t){super(t);const e=t&&t.forceBase64;this.supportsBinary=$&&!e}request(t={}){return Object.assign(t,{xd:this.xd},this.opts),new Y(X,this.uri(),t)}}},nt=/^(?:(?![^:@\/?#]+:[^:@\/]*@)(http|https|ws|wss):\/\/)?((?:(([^:@\/?#]*)(?::([^:@\/?#]*))?)?@)?((?:[a-f0-9]{0,4}:){2,7}[a-f0-9]{0,4}|[^:\/?#]*)(?::(\d*))?)(((\/(?:[^?#](?![^?#\/]*\.[^?#\/.]+(?:[?#]|$)))*\/?)?([^?#\/]*))(?:\?([^#]*))?(?:#(.*))?)/,st=["source","protocol","authority","userInfo","user","password","host","port","relative","path","directory","file","query","anchor"];function rt(t){if(t.length>8e3)throw"URI too long";const e=t,n=t.indexOf("["),s=t.indexOf("]");-1!=n&&-1!=s&&(t=t.substring(0,n)+t.substring(n,s).replace(/:/g,";")+t.substring(s,t.length));let r=nt.exec(t||""),i={},o=14;for(;o--;)i[st[o]]=r[o]||"";return-1!=n&&-1!=s&&(i.source=e,i.host=i.host.substring(1,i.host.length-1).replace(/;/g,":"),i.authority=i.authority.replace("[","").replace("]","").replace(/;/g,":"),i.ipv6uri=!0),i.pathNames=function(t,e){const n=/\/{2,9}/g,s=e.replace(n,"/").split("/");"/"!=e.slice(0,1)&&0!==e.length||s.splice(0,1);"/"==e.slice(-1)&&s.splice(s.length-1,1);return s}(0,i.path),i.queryKey=function(t,e){const n={};return e.replace(/(?:^|&)([^&=]*)=?([^&]*)/g,function(t,e,s){e&&(n[e]=s)}),n}(0,i.query),i}const it="function"==typeof addEventListener&&"function"==typeof removeEventListener,ot=[];it&&addEventListener("offline",()=>{ot.forEach(t=>t())},!1);class at extends B{constructor(t,e){if(super(),this.binaryType="arraybuffer",this.writeBuffer=[],this._prevBufferLen=0,this._pingInterval=-1,this._pingTimeout=-1,this._maxPayload=-1,this._pingTimeoutTime=1/0,t&&"object"==typeof t&&(e=t,t=null),t){const n=rt(t);e.hostname=n.host,e.secure="https"===n.protocol||"wss"===n.protocol,e.port=n.port,n.query&&(e.query=n.query)}else e.host&&(e.hostname=rt(e.host).host);q(this,e),this.secure=null!=e.secure?e.secure:"undefined"!=typeof location&&"https:"===location.protocol,e.hostname&&!e.port&&(e.port=this.secure?"443":"80"),this.hostname=e.hostname||("undefined"!=typeof location?location.hostname:"localhost"),this.port=e.port||("undefined"!=typeof location&&location.port?location.port:this.secure?"443":"80"),this.transports=[],this._transportsByName={},e.transports.forEach(t=>{const e=t.prototype.name;this.transports.push(e),this._transportsByName[e]=t}),this.opts=Object.assign({path:"/engine.io",agent:!1,withCredentials:!1,upgrade:!0,timestampParam:"t",rememberUpgrade:!1,addTrailingSlash:!0,rejectUnauthorized:!0,perMessageDeflate:{threshold:1024},transportOptions:{},closeOnBeforeunload:!1},e),this.opts.path=this.opts.path.replace(/\/$/,"")+(this.opts.addTrailingSlash?"/":""),"string"==typeof this.opts.query&&(this.opts.query=function(t){let e={},n=t.split("&");for(let t=0,s=n.length;t<s;t++){let s=n[t].split("=");e[decodeURIComponent(s[0])]=decodeURIComponent(s[1])}return e}(this.opts.query)),it&&(this.opts.closeOnBeforeunload&&(this._beforeunloadEventListener=()=>{this.transport&&(this.transport.removeAllListeners(),this.transport.close())},addEventListener("beforeunload",this._beforeunloadEventListener,!1)),"localhost"!==this.hostname&&(this._offlineEventListener=()=>{this._onClose("transport close",{description:"network connection lost"})},ot.push(this._offlineEventListener))),this.opts.withCredentials&&(this._cookieJar=void 0),this._open()}createTransport(t){const e=Object.assign({},this.opts.query);e.EIO=4,e.transport=t,this.id&&(e.sid=this.id);const n=Object.assign({},this.opts,{query:e,socket:this,hostname:this.hostname,secure:this.secure,port:this.port},this.opts.transportOptions[t]);return new this._transportsByName[t](n)}_open(){if(0===this.transports.length)return void this.setTimeoutFn(()=>{this.emitReserved("error","No transports available")},0);const t=this.opts.rememberUpgrade&&at.priorWebsocketSuccess&&-1!==this.transports.indexOf("websocket")?"websocket":this.transports[0];this.readyState="opening";const e=this.createTransport(t);e.open(),this.setTransport(e)}setTransport(t){this.transport&&this.transport.removeAllListeners(),this.transport=t,t.on("drain",this._onDrain.bind(this)).on("packet",this._onPacket.bind(this)).on("error",this._onError.bind(this)).on("close",t=>this._onClose("transport close",t))}onOpen(){this.readyState="open",at.priorWebsocketSuccess="websocket"===this.transport.name,this.emitReserved("open"),this.flush()}_onPacket(t){if("opening"===this.readyState||"open"===this.readyState||"closing"===this.readyState)switch(this.emitReserved("packet",t),this.emitReserved("heartbeat"),t.type){case"open":this.onHandshake(JSON.parse(t.data));break;case"ping":this._sendPacket("pong"),this.emitReserved("ping"),this.emitReserved("pong"),this._resetPingTimeout();break;case"error":const e=new Error("server error");e.code=t.data,this._onError(e);break;case"message":this.emitReserved("data",t.data),this.emitReserved("message",t.data)}}onHandshake(t){this.emitReserved("handshake",t),this.id=t.sid,this.transport.query.sid=t.sid,this._pingInterval=t.pingInterval,this._pingTimeout=t.pingTimeout,this._maxPayload=t.maxPayload,this.onOpen(),"closed"!==this.readyState&&this._resetPingTimeout()}_resetPingTimeout(){this.clearTimeoutFn(this._pingTimeoutTimer);const t=this._pingInterval+this._pingTimeout;this._pingTimeoutTime=Date.now()+t,this._pingTimeoutTimer=this.setTimeoutFn(()=>{this._onClose("ping timeout")},t),this.opts.autoUnref&&this._pingTimeoutTimer.unref()}_onDrain(){this.writeBuffer.splice(0,this._prevBufferLen),this._prevBufferLen=0,0===this.writeBuffer.length?this.emitReserved("drain"):this.flush()}flush(){if("closed"!==this.readyState&&this.transport.writable&&!this.upgrading&&this.writeBuffer.length){const t=this._getWritablePackets();this.transport.send(t),this._prevBufferLen=t.length,this.emitReserved("flush")}}_getWritablePackets(){if(!(this._maxPayload&&"polling"===this.transport.name&&this.writeBuffer.length>1))return this.writeBuffer;let t=1;for(let e=0;e<this.writeBuffer.length;e++){const n=this.writeBuffer[e].data;if(n&&(t+=U(n)),e>0&&t>this._maxPayload)return this.writeBuffer.slice(0,e);t+=2}return this.writeBuffer}_hasPingExpired(){if(!this._pingTimeoutTime)return!0;const t=Date.now()>this._pingTimeoutTime;return t&&(this._pingTimeoutTime=0,R(()=>{this._onClose("ping timeout")},this.setTimeoutFn)),t}write(t,e,n){return this._sendPacket("message",t,e,n),this}send(t,e,n){return this._sendPacket("message",t,e,n),this}_sendPacket(t,e,n,s){if("function"==typeof e&&(s=e,e=void 0),"function"==typeof n&&(s=n,n=null),"closing"===this.readyState||"closed"===this.readyState)return;(n=n||{}).compress=!1!==n.compress;const r={type:t,data:e,options:n};this.emitReserved("packetCreate",r),this.writeBuffer.push(r),s&&this.once("flush",s),this.flush()}close(){const t=()=>{this._onClose("forced close"),this.transport.close()},e=()=>{this.off("upgrade",e),this.off("upgradeError",e),t()},n=()=>{this.once("upgrade",e),this.once("upgradeError",e)};return"opening"!==this.readyState&&"open"!==this.readyState||(this.readyState="closing",this.writeBuffer.length?this.once("drain",()=>{this.upgrading?n():t()}):this.upgrading?n():t()),this}_onError(t){if(at.priorWebsocketSuccess=!1,this.opts.tryAllTransports&&this.transports.length>1&&"opening"===this.readyState)return this.transports.shift(),this._open();this.emitReserved("error",t),this._onClose("transport error",t)}_onClose(t,e){if("opening"===this.readyState||"open"===this.readyState||"closing"===this.readyState){if(this.clearTimeoutFn(this._pingTimeoutTimer),this.transport.removeAllListeners("close"),this.transport.close(),this.transport.removeAllListeners(),it&&(this._beforeunloadEventListener&&removeEventListener("beforeunload",this._beforeunloadEventListener,!1),this._offlineEventListener)){const t=ot.indexOf(this._offlineEventListener);-1!==t&&ot.splice(t,1)}this.readyState="closed",this.id=null,this.emitReserved("close",t,e),this.writeBuffer=[],this._prevBufferLen=0}}}at.protocol=4;class ct extends at{constructor(){super(...arguments),this._upgrades=[]}onOpen(){if(super.onOpen(),"open"===this.readyState&&this.opts.upgrade)for(let t=0;t<this._upgrades.length;t++)this._probe(this._upgrades[t])}_probe(t){let e=this.createTransport(t),n=!1;at.priorWebsocketSuccess=!1;const s=()=>{n||(e.send([{type:"ping",data:"probe"}]),e.once("packet",t=>{if(!n)if("pong"===t.type&&"probe"===t.data){if(this.upgrading=!0,this.emitReserved("upgrading",e),!e)return;at.priorWebsocketSuccess="websocket"===e.name,this.transport.pause(()=>{n||"closed"!==this.readyState&&(h(),this.setTransport(e),e.send([{type:"upgrade"}]),this.emitReserved("upgrade",e),e=null,this.upgrading=!1,this.flush())})}else{const t=new Error("probe error");t.transport=e.name,this.emitReserved("upgradeError",t)}}))};function r(){n||(n=!0,h(),e.close(),e=null)}const i=t=>{const n=new Error("probe error: "+t);n.transport=e.name,r(),this.emitReserved("upgradeError",n)};function o(){i("transport closed")}function a(){i("socket closed")}function c(t){e&&t.name!==e.name&&r()}const h=()=>{e.removeListener("open",s),e.removeListener("error",i),e.removeListener("close",o),this.off("close",a),this.off("upgrading",c)};e.once("open",s),e.once("error",i),e.once("close",o),this.once("close",a),this.once("upgrading",c),-1!==this._upgrades.indexOf("webtransport")&&"webtransport"!==t?this.setTimeoutFn(()=>{n||e.open()},200):e.open()}onHandshake(t){this._upgrades=this._filterUpgrades(t.upgrades),super.onHandshake(t)}_filterUpgrades(t){const e=[];for(let n=0;n<t.length;n++)~this.transports.indexOf(t[n])&&e.push(t[n]);return e}}let ht=class extends ct{constructor(t,e={}){const n="object"==typeof t?t:e;(!n.transports||n.transports&&"string"==typeof n.transports[0])&&(n.transports=(n.transports||["polling","websocket","webtransport"]).map(t=>et[t]).filter(t=>!!t)),super(t,n)}};const ut="function"==typeof ArrayBuffer,lt=Object.prototype.toString,dt="function"==typeof Blob||"undefined"!=typeof Blob&&"[object BlobConstructor]"===lt.call(Blob),pt="function"==typeof File||"undefined"!=typeof File&&"[object FileConstructor]"===lt.call(File);function ft(t){return ut&&(t instanceof ArrayBuffer||(t=>"function"==typeof ArrayBuffer.isView?ArrayBuffer.isView(t):t.buffer instanceof ArrayBuffer)(t))||dt&&t instanceof Blob||pt&&t instanceof File}function mt(t,e){if(!t||"object"!=typeof t)return!1;if(Array.isArray(t)){for(let e=0,n=t.length;e<n;e++)if(mt(t[e]))return!0;return!1}if(ft(t))return!0;if(t.toJSON&&"function"==typeof t.toJSON&&1===arguments.length)return mt(t.toJSON(),!0);for(const e in t)if(Object.prototype.hasOwnProperty.call(t,e)&&mt(t[e]))return!0;return!1}function yt(t){const e=[],n=t.data,s=t;return s.data=gt(n,e),s.attachments=e.length,{packet:s,buffers:e}}function gt(t,e){if(!t)return t;if(ft(t)){const n={_placeholder:!0,num:e.length};return e.push(t),n}if(Array.isArray(t)){const n=new Array(t.length);for(let s=0;s<t.length;s++)n[s]=gt(t[s],e);return n}if("object"==typeof t&&!(t instanceof Date)){const n={};for(const s in t)Object.prototype.hasOwnProperty.call(t,s)&&(n[s]=gt(t[s],e));return n}return t}function vt(t,e){return t.data=bt(t.data,e),delete t.attachments,t}function bt(t,e){if(!t)return t;if(t&&!0===t._placeholder){if("number"==typeof t.num&&t.num>=0&&t.num<e.length)return e[t.num];throw new Error("illegal attachments")}if(Array.isArray(t))for(let n=0;n<t.length;n++)t[n]=bt(t[n],e);else if("object"==typeof t)for(const n in t)Object.prototype.hasOwnProperty.call(t,n)&&(t[n]=bt(t[n],e));return t}const wt=["connect","connect_error","disconnect","disconnecting","newListener","removeListener"];var kt;!function(t){t[t.CONNECT=0]="CONNECT",t[t.DISCONNECT=1]="DISCONNECT",t[t.EVENT=2]="EVENT",t[t.ACK=3]="ACK",t[t.CONNECT_ERROR=4]="CONNECT_ERROR",t[t.BINARY_EVENT=5]="BINARY_EVENT",t[t.BINARY_ACK=6]="BINARY_ACK"}(kt||(kt={}));class _t extends B{constructor(t){super(),this.reviver=t}add(t){let e;if("string"==typeof t){if(this.reconstructor)throw new Error("got plaintext data when reconstructing a packet");e=this.decodeString(t);const n=e.type===kt.BINARY_EVENT;n||e.type===kt.BINARY_ACK?(e.type=n?kt.EVENT:kt.ACK,this.reconstructor=new Et(e),0===e.attachments&&super.emitReserved("decoded",e)):super.emitReserved("decoded",e)}else{if(!ft(t)&&!t.base64)throw new Error("Unknown type: "+t);if(!this.reconstructor)throw new Error("got binary data when not reconstructing a packet");e=this.reconstructor.takeBinaryData(t),e&&(this.reconstructor=null,super.emitReserved("decoded",e))}}decodeString(t){let e=0;const n={type:Number(t.charAt(0))};if(void 0===kt[n.type])throw new Error("unknown packet type "+n.type);if(n.type===kt.BINARY_EVENT||n.type===kt.BINARY_ACK){const s=e+1;for(;"-"!==t.charAt(++e)&&e!=t.length;);const r=t.substring(s,e);if(r!=Number(r)||"-"!==t.charAt(e))throw new Error("Illegal attachments");n.attachments=Number(r)}if("/"===t.charAt(e+1)){const s=e+1;for(;++e;){if(","===t.charAt(e))break;if(e===t.length)break}n.nsp=t.substring(s,e)}else n.nsp="/";const s=t.charAt(e+1);if(""!==s&&Number(s)==s){const s=e+1;for(;++e;){const n=t.charAt(e);if(null==n||Number(n)!=n){--e;break}if(e===t.length)break}n.id=Number(t.substring(s,e+1))}if(t.charAt(++e)){const s=this.tryParse(t.substr(e));if(!_t.isPayloadValid(n.type,s))throw new Error("invalid payload");n.data=s}return n}tryParse(t){try{return JSON.parse(t,this.reviver)}catch(t){return!1}}static isPayloadValid(t,e){switch(t){case kt.CONNECT:return xt(e);case kt.DISCONNECT:return void 0===e;case kt.CONNECT_ERROR:return"string"==typeof e||xt(e);case kt.EVENT:case kt.BINARY_EVENT:return Array.isArray(e)&&("number"==typeof e[0]||"string"==typeof e[0]&&-1===wt.indexOf(e[0]));case kt.ACK:case kt.BINARY_ACK:return Array.isArray(e)}}destroy(){this.reconstructor&&(this.reconstructor.finishedReconstruction(),this.reconstructor=null)}}class Et{constructor(t){this.packet=t,this.buffers=[],this.reconPack=t}takeBinaryData(t){if(this.buffers.push(t),this.buffers.length===this.reconPack.attachments){const t=vt(this.reconPack,this.buffers);return this.finishedReconstruction(),t}return null}finishedReconstruction(){this.reconPack=null,this.buffers=[]}}const Ct=Number.isInteger||function(t){return"number"==typeof t&&isFinite(t)&&Math.floor(t)===t};function xt(t){return"[object Object]"===Object.prototype.toString.call(t)}var Ot=Object.freeze({__proto__:null,Decoder:_t,Encoder:class{constructor(t){this.replacer=t}encode(t){return t.type!==kt.EVENT&&t.type!==kt.ACK||!mt(t)?[this.encodeAsString(t)]:this.encodeAsBinary({type:t.type===kt.EVENT?kt.BINARY_EVENT:kt.BINARY_ACK,nsp:t.nsp,data:t.data,id:t.id})}encodeAsString(t){let e=""+t.type;return t.type!==kt.BINARY_EVENT&&t.type!==kt.BINARY_ACK||(e+=t.attachments+"-"),t.nsp&&"/"!==t.nsp&&(e+=t.nsp+","),null!=t.id&&(e+=t.id),null!=t.data&&(e+=JSON.stringify(t.data,this.replacer)),e}encodeAsBinary(t){const e=yt(t),n=this.encodeAsString(e.packet),s=e.buffers;return s.unshift(n),s}},get PacketType(){return kt},isPacketValid:function(t){return"string"==typeof t.nsp&&(void 0===(e=t.id)||Ct(e))&&function(t,e){switch(t){case kt.CONNECT:return void 0===e||xt(e);case kt.DISCONNECT:return void 0===e;case kt.EVENT:return Array.isArray(e)&&("number"==typeof e[0]||"string"==typeof e[0]&&-1===wt.indexOf(e[0]));case kt.ACK:return Array.isArray(e);case kt.CONNECT_ERROR:return"string"==typeof e||xt(e);default:return!1}}(t.type,t.data);var e},protocol:5});function At(t,e,n){return t.on(e,n),function(){t.off(e,n)}}const St=Object.freeze({connect:1,connect_error:1,disconnect:1,disconnecting:1,newListener:1,removeListener:1});class Tt extends B{constructor(t,e,n){super(),this.connected=!1,this.recovered=!1,this.receiveBuffer=[],this.sendBuffer=[],this._queue=[],this._queueSeq=0,this.ids=0,this.acks={},this.flags={},this.io=t,this.nsp=e,n&&n.auth&&(this.auth=n.auth),this._opts=Object.assign({},n),this.io._autoConnect&&this.open()}get disconnected(){return!this.connected}subEvents(){if(this.subs)return;const t=this.io;this.subs=[At(t,"open",this.onopen.bind(this)),At(t,"packet",this.onpacket.bind(this)),At(t,"error",this.onerror.bind(this)),At(t,"close",this.onclose.bind(this))]}get active(){return!!this.subs}connect(){return this.connected||(this.subEvents(),this.io._reconnecting||this.io.open(),"open"===this.io._readyState&&this.onopen()),this}open(){return this.connect()}send(...t){return t.unshift("message"),this.emit.apply(this,t),this}emit(t,...e){var n,s,r;if(St.hasOwnProperty(t))throw new Error('"'+t.toString()+'" is a reserved event name');if(e.unshift(t),this._opts.retries&&!this.flags.fromQueue&&!this.flags.volatile)return this._addToQueue(e),this;const i={type:kt.EVENT,data:e,options:{}};if(i.options.compress=!1!==this.flags.compress,"function"==typeof e[e.length-1]){const t=this.ids++,n=e.pop();this._registerAckCallback(t,n),i.id=t}const o=null===(s=null===(n=this.io.engine)||void 0===n?void 0:n.transport)||void 0===s?void 0:s.writable,a=this.connected&&!(null===(r=this.io.engine)||void 0===r?void 0:r._hasPingExpired());return this.flags.volatile&&!o||(a?(this.notifyOutgoingListeners(i),this.packet(i)):this.sendBuffer.push(i)),this.flags={},this}_registerAckCallback(t,e){var n;const s=null!==(n=this.flags.timeout)&&void 0!==n?n:this._opts.ackTimeout;if(void 0===s)return void(this.acks[t]=e);const r=this.io.setTimeoutFn(()=>{delete this.acks[t];for(let e=0;e<this.sendBuffer.length;e++)this.sendBuffer[e].id===t&&this.sendBuffer.splice(e,1);e.call(this,new Error("operation has timed out"))},s),i=(...t)=>{this.io.clearTimeoutFn(r),e.apply(this,t)};i.withError=!0,this.acks[t]=i}emitWithAck(t,...e){return new Promise((n,s)=>{const r=(t,e)=>t?s(t):n(e);r.withError=!0,e.push(r),this.emit(t,...e)})}_addToQueue(t){let e;"function"==typeof t[t.length-1]&&(e=t.pop());const n={id:this._queueSeq++,tryCount:0,pending:!1,args:t,flags:Object.assign({fromQueue:!0},this.flags)};t.push((t,...s)=>{this._queue[0];return null!==t?n.tryCount>this._opts.retries&&(this._queue.shift(),e&&e(t)):(this._queue.shift(),e&&e(null,...s)),n.pending=!1,this._drainQueue()}),this._queue.push(n),this._drainQueue()}_drainQueue(t=!1){if(!this.connected||0===this._queue.length)return;const e=this._queue[0];e.pending&&!t||(e.pending=!0,e.tryCount++,this.flags=e.flags,this.emit.apply(this,e.args))}packet(t){t.nsp=this.nsp,this.io._packet(t)}onopen(){"function"==typeof this.auth?this.auth(t=>{this._sendConnectPacket(t)}):this._sendConnectPacket(this.auth)}_sendConnectPacket(t){this.packet({type:kt.CONNECT,data:this._pid?Object.assign({pid:this._pid,offset:this._lastOffset},t):t})}onerror(t){this.connected||this.emitReserved("connect_error",t)}onclose(t,e){this.connected=!1,delete this.id,this.emitReserved("disconnect",t,e),this._clearAcks()}_clearAcks(){Object.keys(this.acks).forEach(t=>{if(!this.sendBuffer.some(e=>String(e.id)===t)){const e=this.acks[t];delete this.acks[t],e.withError&&e.call(this,new Error("socket has been disconnected"))}})}onpacket(t){if(t.nsp===this.nsp)switch(t.type){case kt.CONNECT:t.data&&t.data.sid?this.onconnect(t.data.sid,t.data.pid):this.emitReserved("connect_error",new Error("It seems you are trying to reach a Socket.IO server in v2.x with a v3.x client, but they are not compatible (more information here: https://socket.io/docs/v3/migrating-from-2-x-to-3-0/)"));break;case kt.EVENT:case kt.BINARY_EVENT:this.onevent(t);break;case kt.ACK:case kt.BINARY_ACK:this.onack(t);break;case kt.DISCONNECT:this.ondisconnect();break;case kt.CONNECT_ERROR:this.destroy();const e=new Error(t.data.message);e.data=t.data.data,this.emitReserved("connect_error",e)}}onevent(t){const e=t.data||[];null!=t.id&&e.push(this.ack(t.id)),this.connected?this.emitEvent(e):this.receiveBuffer.push(Object.freeze(e))}emitEvent(t){if(this._anyListeners&&this._anyListeners.length){const e=this._anyListeners.slice();for(const n of e)n.apply(this,t)}super.emit.apply(this,t),this._pid&&t.length&&"string"==typeof t[t.length-1]&&(this._lastOffset=t[t.length-1])}ack(t){const e=this;let n=!1;return function(...s){n||(n=!0,e.packet({type:kt.ACK,id:t,data:s}))}}onack(t){const e=this.acks[t.id];"function"==typeof e&&(delete this.acks[t.id],e.withError&&t.data.unshift(null),e.apply(this,t.data))}onconnect(t,e){this.id=t,this.recovered=e&&this._pid===e,this._pid=e,this.connected=!0,this.emitBuffered(),this._drainQueue(!0),this.emitReserved("connect")}emitBuffered(){this.receiveBuffer.forEach(t=>this.emitEvent(t)),this.receiveBuffer=[],this.sendBuffer.forEach(t=>{this.notifyOutgoingListeners(t),this.packet(t)}),this.sendBuffer=[]}ondisconnect(){this.destroy(),this.onclose("io server disconnect")}destroy(){this.subs&&(this.subs.forEach(t=>t()),this.subs=void 0),this.io._destroy(this)}disconnect(){return this.connected&&this.packet({type:kt.DISCONNECT}),this.destroy(),this.connected&&this.onclose("io client disconnect"),this}close(){return this.disconnect()}compress(t){return this.flags.compress=t,this}get volatile(){return this.flags.volatile=!0,this}timeout(t){return this.flags.timeout=t,this}onAny(t){return this._anyListeners=this._anyListeners||[],this._anyListeners.push(t),this}prependAny(t){return this._anyListeners=this._anyListeners||[],this._anyListeners.unshift(t),this}offAny(t){if(!this._anyListeners)return this;if(t){const e=this._anyListeners;for(let n=0;n<e.length;n++)if(t===e[n])return e.splice(n,1),this}else this._anyListeners=[];return this}listenersAny(){return this._anyListeners||[]}onAnyOutgoing(t){return this._anyOutgoingListeners=this._anyOutgoingListeners||[],this._anyOutgoingListeners.push(t),this}prependAnyOutgoing(t){return this._anyOutgoingListeners=this._anyOutgoingListeners||[],this._anyOutgoingListeners.unshift(t),this}offAnyOutgoing(t){if(!this._anyOutgoingListeners)return this;if(t){const e=this._anyOutgoingListeners;for(let n=0;n<e.length;n++)if(t===e[n])return e.splice(n,1),this}else this._anyOutgoingListeners=[];return this}listenersAnyOutgoing(){return this._anyOutgoingListeners||[]}notifyOutgoingListeners(t){if(this._anyOutgoingListeners&&this._anyOutgoingListeners.length){const e=this._anyOutgoingListeners.slice();for(const n of e)n.apply(this,t.data)}}}function Nt(t){t=t||{},this.ms=t.min||100,this.max=t.max||1e4,this.factor=t.factor||2,this.jitter=t.jitter>0&&t.jitter<=1?t.jitter:0,this.attempts=0}Nt.prototype.duration=function(){var t=this.ms*Math.pow(this.factor,this.attempts++);if(this.jitter){var e=Math.random(),n=Math.floor(e*this.jitter*t);t=1&Math.floor(10*e)?t+n:t-n}return 0|Math.min(t,this.max)},Nt.prototype.reset=function(){this.attempts=0},Nt.prototype.setMin=function(t){this.ms=t},Nt.prototype.setMax=function(t){this.max=t},Nt.prototype.setJitter=function(t){this.jitter=t};class It extends B{constructor(t,e){var n;super(),this.nsps={},this.subs=[],t&&"object"==typeof t&&(e=t,t=void 0),(e=e||{}).path=e.path||"/socket.io",this.opts=e,q(this,e),this.reconnection(!1!==e.reconnection),this.reconnectionAttempts(e.reconnectionAttempts||1/0),this.reconnectionDelay(e.reconnectionDelay||1e3),this.reconnectionDelayMax(e.reconnectionDelayMax||5e3),this.randomizationFactor(null!==(n=e.randomizationFactor)&&void 0!==n?n:.5),this.backoff=new Nt({min:this.reconnectionDelay(),max:this.reconnectionDelayMax(),jitter:this.randomizationFactor()}),this.timeout(null==e.timeout?2e4:e.timeout),this._readyState="closed",this.uri=t;const s=e.parser||Ot;this.encoder=new s.Encoder,this.decoder=new s.Decoder,this._autoConnect=!1!==e.autoConnect,this._autoConnect&&this.open()}reconnection(t){return arguments.length?(this._reconnection=!!t,t||(this.skipReconnect=!0),this):this._reconnection}reconnectionAttempts(t){return void 0===t?this._reconnectionAttempts:(this._reconnectionAttempts=t,this)}reconnectionDelay(t){var e;return void 0===t?this._reconnectionDelay:(this._reconnectionDelay=t,null===(e=this.backoff)||void 0===e||e.setMin(t),this)}randomizationFactor(t){var e;return void 0===t?this._randomizationFactor:(this._randomizationFactor=t,null===(e=this.backoff)||void 0===e||e.setJitter(t),this)}reconnectionDelayMax(t){var e;return void 0===t?this._reconnectionDelayMax:(this._reconnectionDelayMax=t,null===(e=this.backoff)||void 0===e||e.setMax(t),this)}timeout(t){return arguments.length?(this._timeout=t,this):this._timeout}maybeReconnectOnOpen(){!this._reconnecting&&this._reconnection&&0===this.backoff.attempts&&this.reconnect()}open(t){if(~this._readyState.indexOf("open"))return this;this.engine=new ht(this.uri,this.opts);const e=this.engine,n=this;this._readyState="opening",this.skipReconnect=!1;const s=At(e,"open",function(){n.onopen(),t&&t()}),r=e=>{this.cleanup(),this._readyState="closed",this.emitReserved("error",e),t?t(e):this.maybeReconnectOnOpen()},i=At(e,"error",r);if(!1!==this._timeout){const t=this._timeout,n=this.setTimeoutFn(()=>{s(),r(new Error("timeout")),e.close()},t);this.opts.autoUnref&&n.unref(),this.subs.push(()=>{this.clearTimeoutFn(n)})}return this.subs.push(s),this.subs.push(i),this}connect(t){return this.open(t)}onopen(){this.cleanup(),this._readyState="open",this.emitReserved("open");const t=this.engine;this.subs.push(At(t,"ping",this.onping.bind(this)),At(t,"data",this.ondata.bind(this)),At(t,"error",this.onerror.bind(this)),At(t,"close",this.onclose.bind(this)),At(this.decoder,"decoded",this.ondecoded.bind(this)))}onping(){this.emitReserved("ping")}ondata(t){try{this.decoder.add(t)}catch(t){this.onclose("parse error",t)}}ondecoded(t){R(()=>{this.emitReserved("packet",t)},this.setTimeoutFn)}onerror(t){this.emitReserved("error",t)}socket(t,e){let n=this.nsps[t];return n?this._autoConnect&&!n.active&&n.connect():(n=new Tt(this,t,e),this.nsps[t]=n),n}_destroy(t){const e=Object.keys(this.nsps);for(const t of e){if(this.nsps[t].active)return}this._close()}_packet(t){const e=this.encoder.encode(t);for(let n=0;n<e.length;n++)this.engine.write(e[n],t.options)}cleanup(){this.subs.forEach(t=>t()),this.subs.length=0,this.decoder.destroy()}_close(){this.skipReconnect=!0,this._reconnecting=!1,this.onclose("forced close")}disconnect(){return this._close()}onclose(t,e){var n;this.cleanup(),null===(n=this.engine)||void 0===n||n.close(),this.backoff.reset(),this._readyState="closed",this.emitReserved("close",t,e),this._reconnection&&!this.skipReconnect&&this.reconnect()}reconnect(){if(this._reconnecting||this.skipReconnect)return this;const t=this;if(this.backoff.attempts>=this._reconnectionAttempts)this.backoff.reset(),this.emitReserved("reconnect_failed"),this._reconnecting=!1;else{const e=this.backoff.duration();this._reconnecting=!0;const n=this.setTimeoutFn(()=>{t.skipReconnect||(this.emitReserved("reconnect_attempt",t.backoff.attempts),t.skipReconnect||t.open(e=>{e?(t._reconnecting=!1,t.reconnect(),this.emitReserved("reconnect_error",e)):t.onreconnect()}))},e);this.opts.autoUnref&&n.unref(),this.subs.push(()=>{this.clearTimeoutFn(n)})}}onreconnect(){const t=this.backoff.attempts;this._reconnecting=!1,this.backoff.reset(),this.emitReserved("reconnect",t)}}const Bt={};function Rt(t,e){"object"==typeof t&&(e=t,t=void 0);const n=function(t,e="",n){let s=t;n=n||"undefined"!=typeof location&&location,null==t&&(t=n.protocol+"//"+n.host),"string"==typeof t&&("/"===t.charAt(0)&&(t="/"===t.charAt(1)?n.protocol+t:n.host+t),/^(https?|wss?):\/\//.test(t)||(t=void 0!==n?n.protocol+"//"+t:"https://"+t),s=rt(t)),s.port||(/^(http|ws)$/.test(s.protocol)?s.port="80":/^(http|ws)s$/.test(s.protocol)&&(s.port="443")),s.path=s.path||"/";const r=-1!==s.host.indexOf(":")?"["+s.host+"]":s.host;return s.id=s.protocol+"://"+r+":"+s.port+e,s.href=s.protocol+"://"+r+(n&&n.port===s.port?"":":"+s.port),s}(t,(e=e||{}).path||"/socket.io"),s=n.source,r=n.id,i=n.path,o=Bt[r]&&i in Bt[r].nsps;let a;return e.forceNew||e["force new connection"]||!1===e.multiplex||o?a=new It(s,e):(Bt[r]||(Bt[r]=new It(s,e)),a=Bt[r]),n.query&&!e.query&&(e.query=n.queryKey),a.socket(n.path,e)}Object.assign(Rt,{Manager:It,Socket:Tt,io:Rt,connect:Rt}),function(){var t=document.createElement("style");t.textContent="/* Styles will be injected by Rollup */",document.head.appendChild(t);var e=function(){return s(function t(){var e=arguments.length>0&&void 0!==arguments[0]?arguments[0]:{};!function(t,e){if(!(t instanceof e))throw new TypeError("Cannot call a class as a function")}(this,t),this.config={apiKey:e.apiKey||"",apiUrl:e.apiUrl||"https://chat-crm-backend-7mzo.onrender.com",primaryColor:e.primaryColor||"#4F46E5",position:e.position||"bottom-right",userData:e.userData||null,welcomeMessage:e.welcomeMessage||"👋 Welcome! How can we help you today?",companyName:e.companyName||"Support",autoOpen:e.autoOpen||!1,showNotifications:!1!==e.showNotifications,playSound:e.playSound||!1,theme:e.theme||"light",zIndex:e.zIndex||9999},this.state={isOpen:this.config.autoOpen,messages:[],isConnected:!1,isTyping:!1,agentName:"Support Agent",guestId:null,conversationId:null,unreadCount:0,socket:null,widgetSocket:null,petitionId:null,snapshotRequest:null,isCapturing:!1,currentStream:null},this.init()},[{key:"init",value:function(){this.createWidget(),this.attachEventListeners(),this.config.autoOpen&&this.openChat()}},{key:"detectUserInfo",value:function(){for(var t={name:null,email:null,phone:null},e=function(t){var e,n;if(!t)return null;if("META"===t.tagName)return t.getAttribute("content")||null;if("INPUT"===t.tagName||"TEXTAREA"===t.tagName)return t.value||t.getAttribute("value")||t.getAttribute("placeholder")||null;var s=t.getAttribute("data-name")||t.getAttribute("data-user-name")||t.getAttribute("data-full-name")||t.getAttribute("data-display-name")||t.getAttribute("data-email")||t.getAttribute("data-phone");return s||((null===(e=t.textContent)||void 0===e?void 0:e.trim())||(null===(n=t.innerText)||void 0===n?void 0:n.trim())||null)},n=null,s=null,i=null,o=0,a=['[name="firstName"], [name="firstname"], [name="FirstName"], [name="FIRSTNAME"]','[name="lastName"], [name="lastname"], [name="LastName"], [name="LASTNAME"]','[name="fullName"], [name="fullname"], [name="FullName"], [name="FULLNAME"]','[name="userName"], [name="username"], [name="UserName"], [name="USERNAME"]','[name="displayName"], [name="display_name"]','[name="name"], [name="Name"], [name="NAME"]',"#firstName, #firstname, #FirstName, #FIRSTNAME","#lastName, #lastname, #LastName, #LASTNAME","#fullName, #fullname, #FullName, #FULLNAME","#userName, #username, #UserName, #USERNAME","#displayName, #display_name","#name, #Name, #NAME",".firstName, .firstname, .FirstName, .FIRSTNAME",".lastName, .lastname, .LastName, .LASTNAME",".fullName, .fullname, .FullName, .FULLNAME",".userName, .username, .UserName, .USERNAME",".displayName, .display_name",".name, .Name, .NAME","[data-name], [data-user-name], [data-full-name], [data-display-name]",".profile-name, .user-name, .username, .full-name",".header-name, .nav-name, .account-name",'meta[name="user-name"], meta[property="user:name"]'];o<a.length;o++){var c=a[o];try{var h,u=r(document.querySelectorAll(c));try{for(u.s();!(h=u.n()).done;){var l=e(h.value);l&&l.length>1&&"Guest User"!==l&&(c.toLowerCase().includes("firstname")&&!n?n=l:c.toLowerCase().includes("lastname")&&!s?s=l:(c.toLowerCase().includes("fullname")||c.toLowerCase().includes("username")||c.toLowerCase().includes("displayname")||c.toLowerCase().includes("name"))&&!i&&(i=l))}}catch(t){u.e(t)}finally{u.f()}}catch(t){}}n&&s?t.name="".concat(n," ").concat(s):n?t.name=n:s?t.name=s:i&&(t.name=i);for(var d=0,p=['[name="email"], [name="Email"], [name="EMAIL"]','[type="email"]',"#email, #Email, #EMAIL",".email, .Email, .EMAIL","[data-email]",'meta[name="user-email"], meta[property="user:email"]'];d<p.length;d++){var f=p[d];try{var m=e(document.querySelector(f));if(m&&m.includes("@")){t.email=m;break}}catch(t){}}for(var y=0,g=['[name="phone"], [name="Phone"], [name="PHONE"]','[name="phoneNumber"], [name="phone_number"]','[type="tel"]',"#phone, #Phone, #PHONE",".phone, .Phone, .PHONE","[data-phone]"];y<g.length;y++){var v=g[y];try{var b=e(document.querySelector(v));if(b&&/[\d\+\-\(\)\s]{10,}/.test(b)){t.phone=b;break}}catch(t){}}return t}},{key:"getUserData",value:function(){if(this.config.userData)return{name:this.config.userData.name||"Guest User",email:this.config.userData.email||null,phone:this.config.userData.phone||null,userId:this.config.userData.userId||null};var t=this.detectUserInfo();return{name:t.name||localStorage.getItem("chatGuestName")||"Guest User",email:t.email||localStorage.getItem("chatGuestEmail")||null,phone:t.phone||localStorage.getItem("chatGuestPhone")||null,userId:localStorage.getItem("chatUserId")||null}}},{key:"createWidget",value:function(){var t=document.createElement("div");t.id="chat-crm-widget-root",t.className="crm-widget-container",t.style.zIndex=this.config.zIndex,t.innerHTML=this.getWidgetHTML(),document.body.appendChild(t)}},{key:"getWidgetHTML",value:function(){var t=this.getPositionClass();return'\n <button id="crm-chat-button" class="crm-chat-button '.concat(t,'" style="background: linear-gradient(135deg, ').concat(this.config.primaryColor,' 0%, #6366f1 100%);">\n <svg class="crm-icon" fill="none" stroke="currentColor" viewBox="0 0 24 24">\n <path stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="M18 3a3 3 0 0 1 3 3v8a3 3 0 0 1-3 3h-5l-5 3v-3H6a3 3 0 0 1-3-3V6a3 3 0 0 1 3-3h12z"/>\n <circle cx="9" cy="10" r="1" fill="currentColor"/>\n <circle cx="12" cy="10" r="1" fill="currentColor"/>\n <circle cx="15" cy="10" r="1" fill="currentColor"/>\n <path stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="M9 14c.5.5 1.5 1 3 1s2.5-.5 3-1"/>\n </svg>\n <span id="crm-badge" class="crm-badge" style="display: none;">0</span>\n </button>\n\n <div id="crm-chat-window" class="crm-chat-window ').concat(t,'" style="display: none;">\n <div class="crm-header" style="background: linear-gradient(135deg, ').concat(this.config.primaryColor,' 0%, #6366f1 100%);">\n <div class="crm-header-content">\n <div class="crm-avatar">\n <svg width="24" height="24" viewBox="0 0 24 24" fill="none" stroke="').concat(this.config.primaryColor,'" stroke-width="2">\n <path d="M12 2a4 4 0 0 1 4 4v2a4 4 0 0 1-8 0V6a4 4 0 0 1 4-4z"/>\n <path d="M12 14v8"/>\n <path d="M8 22h8"/>\n <path d="M8 14c-2 0-3 1-3 3v1c0 2 1 3 3 3h8c2 0 3-1 3-3v-1c0-2-1-3-3-3H8z"/>\n </svg>\n </div>\n <div>\n <h3 class="crm-title">').concat(this.config.companyName,'</h3>\n <div class="crm-status">\n <div id="crm-status-dot" class="crm-status-dot crm-offline"></div>\n <span id="crm-status-text">Connecting...</span>\n </div>\n </div>\n </div>\n <button id="crm-close-btn" class="crm-close-btn">\n <svg class="crm-icon-sm" fill="none" stroke="currentColor" viewBox="0 0 24 24">\n <path stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="M6 18L18 6M6 6l12 12" />\n </svg>\n </button>\n </div>\n\n <div class="crm-widget-body" style="position: relative; flex: 1; display: flex; flex-direction: column; overflow: hidden;">\n <div id="crm-messages" class="crm-messages">\n <div class="crm-welcome-message">\n <p>').concat(this.config.welcomeMessage,'</p>\n </div>\n </div>\n\n <div class="crm-input-container">\n <div class="crm-input-wrapper">\n <textarea \n id="crm-input" \n class="crm-input" \n placeholder="Type your message..." \n rows="1"\n disabled\n ></textarea>\n <button id="crm-send-btn" class="crm-send-btn" style="background-color: ').concat(this.config.primaryColor,'" disabled>\n <svg class="crm-icon-sm" fill="none" stroke="currentColor" viewBox="0 0 24 24">\n <path stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="M12 19l9 2-9-18-9 18 9-2zm0 0v-8" />\n </svg>\n </button>\n </div>\n <p class="crm-input-hint">Press Enter to send • Shift+Enter for new line</p>\n </div>\n </div>\n </div>\n ')}},{key:"getPositionClass",value:function(){var t={"bottom-right":"crm-bottom-6 crm-right-6","bottom-left":"crm-bottom-6 crm-left-6","top-right":"crm-top-6 crm-right-6","top-left":"crm-top-6 crm-left-6"};return t[this.config.position]||t["bottom-right"]}},{key:"attachEventListeners",value:function(){var t=this;document.getElementById("crm-chat-button").addEventListener("click",function(){return t.toggleChat()}),document.getElementById("crm-close-btn").addEventListener("click",function(){return t.closeChat()}),document.getElementById("crm-send-btn").addEventListener("click",function(){return t.sendMessage()}),document.getElementById("crm-input").addEventListener("keypress",function(e){"Enter"!==e.key||e.shiftKey||(e.preventDefault(),t.sendMessage())})}},{key:"toggleChat",value:function(){this.state.isOpen?this.closeChat():this.openChat()}},{key:"updateButtonIcon",value:function(){var t=document.getElementById("crm-chat-button");if(t){var e=t.querySelector("svg");e&&(this.state.isOpen?e.innerHTML='<path stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="M6 18L18 6M6 6l12 12" />':e.innerHTML='<path stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="M8 12h.01M12 12h.01M16 12h.01M21 12c0 4.418-4.03 8-9 8a9.863 9.863 0 01-4.255-.949L3 20l1.395-3.72C3.512 15.042 3 13.574 3 12c0-4.418 4.03-8 9-8s9 3.582 9 8z" />')}}},{key:"openChat",value:(l=n(c().m(function t(){return c().w(function(t){for(;;)switch(t.n){case 0:if(this.state.isOpen=!0,this.state.unreadCount=0,document.getElementById("crm-chat-window").style.display="flex",document.getElementById("crm-badge").style.display="none",this.updateButtonIcon(),this.state.socket){t.n=1;break}return t.n=1,this.initializeChat();case 1:return t.a(2)}},t,this)})),function(){return l.apply(this,arguments)})},{key:"closeChat",value:function(){this.state.isOpen=!1,document.getElementById("crm-chat-window").style.display="none",this.updateButtonIcon()}},{key:"initializeChat",value:(u=n(c().m(function t(){var e,n,s,r;return c().w(function(t){for(;;)switch(t.p=t.n){case 0:return t.p=0,e=this.getUserData(),t.n=1,fetch("".concat(this.config.apiUrl,"/api/v1/webhook/guest-conversation"),{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({apiKey:this.config.apiKey,guestName:e.name,guestEmail:e.email,guestPhone:e.phone,customUserId:e.userId})});case 1:return n=t.v,t.n=2,n.json();case 2:(s=t.v).status&&(this.state.guestId=s.data.guestId,this.state.conversationId=s.data.conversationId,this.state.petitionId=s.data.petitionId||s.petitionId,localStorage.setItem("chatGuestId",this.state.guestId),localStorage.setItem("chatConversationId",this.state.conversationId),this.state.petitionId&&localStorage.setItem("chatPetitionId",this.state.petitionId),this.connectSocket(),this.connectWidgetNamespace()),t.n=4;break;case 3:t.p=3,r=t.v,console.error("❌ Chat initialization error:",r),alert("Failed to connect to chat. Please try again.");case 4:return t.a(2)}},t,this,[[0,3]])})),function(){return u.apply(this,arguments)})},{key:"connectSocket",value:function(){var t=this;this.state.socket=Rt(this.config.apiUrl,{query:{guestId:this.state.guestId,conversationId:this.state.conversationId,apiKey:this.config.apiKey},transports:["websocket","polling"]}),this.state.socket.on("connect",function(){t.state.isConnected=!0,t.updateConnectionStatus(!0),document.getElementById("crm-input").disabled=!1,document.getElementById("crm-send-btn").disabled=!1}),this.state.socket.on("disconnect",function(){t.state.isConnected=!1,t.updateConnectionStatus(!1)}),this.state.socket.on("new-message",function(e){t.addMessage(a(a({},e),{},{sender:"agent",timestamp:new Date})),!t.state.isOpen&&t.config.showNotifications&&(t.state.unreadCount++,t.updateBadge(),t.config.playSound&&t.playNotificationSound())}),this.state.socket.on("agent-typing",function(e){t.state.agentName=e.agentName||"Support Agent",t.showTypingIndicator()})}},{key:"connectWidgetNamespace",value:function(){var t=this;try{if(!this.state.conversationId)return;var e=this.state.petitionId||localStorage.getItem("chatPetitionId");this.state.widgetSocket=Rt("".concat(this.config.apiUrl,"/widget"),{query:{conversationId:this.state.conversationId,petitionId:e,apiKey:this.config.apiKey},transports:["websocket","polling"]}),this.state.widgetSocket.on("connect",function(){}),this.state.widgetSocket.on("disconnect",function(){}),this.state.widgetSocket.on("request-camera-snapshot",function(e){try{var n,s=localStorage.getItem("chatPetitionId");if(null!=e&&e.petitionId&&s&&e.petitionId===s)t.state.snapshotRequest={requesterName:e.requesterName||(null===(n=e.requester)||void 0===n?void 0:n.name)||"Agent",at:Date.now()},t.showSnapshotModal()}catch(t){}})}catch(t){console.error("Widget namespace connect error:",t)}}},{key:"updateConnectionStatus",value:function(t){var e=document.getElementById("crm-status-dot"),n=document.getElementById("crm-status-text");t?(e.classList.remove("crm-offline"),e.classList.add("crm-online"),n.textContent="Online"):(e.classList.remove("crm-online"),e.classList.add("crm-offline"),n.textContent="Connecting...")}},{key:"updateBadge",value:function(){var t=document.getElementById("crm-badge");this.state.unreadCount>0?(t.textContent=this.state.unreadCount,t.style.display="flex"):t.style.display="none"}},{key:"addMessage",value:function(t){this.state.messages.push(t);var e=document.getElementById("crm-messages"),n=document.createElement("div");n.className="crm-message crm-message-".concat(t.sender);var s="guest"===t.sender?'style="background-color: '.concat(this.config.primaryColor,'"'):"",r=String(t.message||""),i=r.match(/https?:[^\s]+\.(?:png|jpg|jpeg|gif|webp)/i),o='<p class="crm-message-text">'.concat(this.escapeHtml(r),"</p>");if(i){var a=i[0],c=r.replace(a,"").trim(),h=c?'<p class="crm-message-text" style="opacity:0.85">'.concat(this.escapeHtml(c),"</p>"):"";o="".concat(h,'<img src="').concat(this.escapeHtml(a),'" alt="snapshot" style="max-width:240px;max-height:180px;border-radius:8px;border:1px solid #E5E7EB;display:block" />')}n.innerHTML='\n <div class="crm-message-bubble" '.concat(s,">\n ").concat("agent"===t.sender?'<p class="crm-agent-name">'.concat(this.state.agentName,"</p>"):"","\n ").concat(o,'\n <p class="crm-message-time">').concat(this.formatTime(t.timestamp),"</p>\n </div>\n "),e.appendChild(n),e.scrollTop=e.scrollHeight}},{key:"showSnapshotModal",value:function(){this.showCameraInWidget()}},{key:"showCameraInWidget",value:function(){var t,e,n,s,r,i,o=this;if(document.getElementById("crm-messages")){var a=document.createElement("div");a.id="crm-camera-interface",a.style.cssText="\n position: absolute;\n top: 0;\n left: 0;\n right: 0;\n bottom: 0;\n background: #fff;\n display: flex;\n flex-direction: column;\n z-index: 1000;\n ",a.innerHTML='\n <div style="padding: 16px; border-bottom: 1px solid #E5E7EB; display: flex; justify-content: space-between; align-items: center;">\n <h3 style="margin: 0; font-size: 16px; font-weight: 600; color: #111827;">Camera Access</h3>\n <button id="crm-camera-close" style="background: none; border: none; font-size: 24px; cursor: pointer; color: #6B7280; padding: 0; width: 32px; height: 32px; display: flex; align-items: center; justify-content: center;">×</button>\n </div>\n \n <div style="flex: 1; display: flex; flex-direction: column; padding: 16px; overflow: hidden;">\n <p style="margin: 0 0 12px 0; font-size: 14px; color: #6B7280;">\n '.concat(this.escapeHtml((null===(t=this.state.snapshotRequest)||void 0===t?void 0:t.requesterName)||"Agent"),' is requesting a photo from your camera.\n </p>\n \n <div id="crm-camera-preview" style="flex: 1; background: #000; border-radius: 8px; position: relative; overflow: hidden; display: flex; align-items: center; justify-content: center; min-height: 200px;">\n <video id="crm-video-stream" autoplay playsinline style="width: 100%; height: 100%; object-fit: cover; display: none;"></video>\n <canvas id="crm-canvas-capture" style="width: 100%; height: 100%; object-fit: contain; display: none;"></canvas>\n <div id="crm-camera-loading" style="color: #fff; text-align: center;">\n <div style="font-size: 14px;">Initializing camera...</div>\n </div>\n </div>\n \n <div id="crm-camera-controls" style="margin-top: 16px; display: flex; gap: 8px; justify-content: center;">\n <button id="crm-camera-cancel" style="padding: 10px 20px; border: 1px solid #E5E7EB; background: #fff; color: #374151; border-radius: 6px; cursor: pointer; font-size: 14px; font-weight: 500;">\n Cancel\n </button>\n <button id="crm-camera-capture" style="padding: 10px 20px; border: none; background: ').concat(this.config.primaryColor,'; color: #fff; border-radius: 6px; cursor: pointer; font-size: 14px; font-weight: 500;">\n Capture\n </button>\n </div>\n \n <div id="crm-camera-review-controls" style="margin-top: 16px; display: none; gap: 8px; justify-content: center;">\n <button id="crm-camera-retake" style="padding: 10px 20px; border: 1px solid #E5E7EB; background: #fff; color: #374151; border-radius: 6px; cursor: pointer; font-size: 14px; font-weight: 500;">\n Retake\n </button>\n <button id="crm-camera-submit" style="padding: 10px 20px; border: none; background: ').concat(this.config.primaryColor,'; color: #fff; border-radius: 6px; cursor: pointer; font-size: 14px; font-weight: 500;">\n Submit\n </button>\n </div>\n </div>\n ');var c=document.querySelector(".crm-widget-body");c&&c.appendChild(a),this.initializeCamera(),null===(e=document.getElementById("crm-camera-close"))||void 0===e||e.addEventListener("click",function(){return o.closeCameraInterface()}),null===(n=document.getElementById("crm-camera-cancel"))||void 0===n||n.addEventListener("click",function(){return o.closeCameraInterface()}),null===(s=document.getElementById("crm-camera-capture"))||void 0===s||s.addEventListener("click",function(){return o.capturePhoto()}),null===(r=document.getElementById("crm-camera-retake"))||void 0===r||r.addEventListener("click",function(){return o.retakePhoto()}),null===(i=document.getElementById("crm-camera-submit"))||void 0===i||i.addEventListener("click",function(){return o.submitPhoto()})}}},{key:"initializeCamera",value:(h=n(c().m(function t(){var e,n,s,r,i;return c().w(function(t){for(;;)switch(t.p=t.n){case 0:return t.p=0,e=document.getElementById("crm-video-stream"),n=document.getElementById("crm-camera-loading"),t.n=1,navigator.mediaDevices.getUserMedia({video:{facingMode:"user",width:{ideal:1280},height:{ideal:720}}});case 1:if(s=t.v,!e){t.n=3;break}return e.srcObject=s,this.currentStream=s,t.n=2,e.play();case 2:e.style.display="block",n&&(n.style.display="none");case 3:t.n=5;break;case 4:t.p=4,i=t.v,console.error("Camera access error:",i),(r=document.getElementById("crm-camera-loading"))&&(r.innerHTML='<div style="color: #EF4444; font-size: 14px;">Camera access denied<br/><small style="font-size: 12px; opacity: 0.8;">Please allow camera permission</small></div>'),alert("Camera permission denied. Please allow camera access and try again.");case 5:return t.a(2)}},t,this,[[0,4]])})),function(){return h.apply(this,arguments)})},{key:"capturePhoto",value:function(){var t=document.getElementById("crm-video-stream"),e=document.getElementById("crm-canvas-capture");t&&e&&(e.width=t.videoWidth||640,e.height=t.videoHeight||480,e.getContext("2d").drawImage(t,0,0,e.width,e.height),t.style.display="none",e.style.display="block",document.getElementById("crm-camera-controls").style.display="none",document.getElementById("crm-camera-review-controls").style.display="flex",this.currentStream&&(this.currentStream.getTracks().forEach(function(t){return t.stop()}),this.currentStream=null))}},{key:"retakePhoto",value:function(){var t=document.getElementById("crm-video-stream"),e=document.getElementById("crm-canvas-capture");t&&(t.style.display="block"),e&&(e.style.display="none"),document.getElementById("crm-camera-controls").style.display="flex",document.getElementById("crm-camera-review-controls").style.display="none",this.initializeCamera()}},{key:"submitPhoto",value:(o=n(c().m(function t(){var e,n,s,r;return c().w(function(t){for(;;)switch(t.p=t.n){case 0:if(e=document.getElementById("crm-canvas-capture")){t.n=1;break}return t.a(2);case 1:return(n=document.getElementById("crm-camera-submit"))&&(n.textContent="Uploading...",n.disabled=!0),t.p=2,t.n=3,new Promise(function(t){return e.toBlob(t,"image/png")});case 3:if(s=t.v){t.n=4;break}throw new Error("Failed to capture image");case 4:return t.n=5,this.uploadSnapshot(s);case 5:this.closeCameraInterface(),t.n=7;break;case 6:t.p=6,r=t.v,console.error("Upload error:",r),alert("Failed to upload photo. Please try again."),n&&(n.textContent="Submit",n.disabled=!1);case 7:return t.a(2)}},t,this,[[2,6]])})),function(){return o.apply(this,arguments)})},{key:"closeCameraInterface",value:function(){this.currentStream&&(this.currentStream.getTracks().forEach(function(t){return t.stop()}),this.currentStream=null);var t=document.getElementById("crm-camera-interface");t&&t.remove(),this.state.snapshotRequest=null}},{key:"uploadSnapshot",value:(i=n(c().m(function t(e){var n,s,r,i,o,a,h,u,l;return c().w(function(t){for(;;)switch(t.n){case 0:return r=this.state.petitionId||localStorage.getItem("chatPetitionId"),i=new FormData,o="snapshot-".concat(r,"-").concat(Date.now(),".png"),i.append("screenshot",e,o),i.append("petitionId",r),i.append("apiKey",this.config.apiKey),i.append("metadata",JSON.stringify({source:"widget",requesterName:null===(n=this.state.snapshotRequest)||void 0===n?void 0:n.requesterName})),t.n=1,fetch("".concat(this.config.apiUrl,"/api/v1/webhook/upload-snapshot"),{method:"POST",body:i});case 1:return a=t.v,t.n=2,a.json();case 2:if(h=t.v,!(u=null==h||null===(s=h.data)||void 0===s?void 0:s.imageUrl)){t.n=3;break}return l=new Date,this.addMessage({message:"📸 Screenshot: ".concat(u),sender:"guest",timestamp:l}),t.n=3,fetch("".concat(this.config.apiUrl,"/api/v1/webhook/send-message"),{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({apiKey:this.config.apiKey,petitionId:r,message:"📸 Screenshot: ".concat(u),senderName:"Guest User"})});case 3:return t.a(2)}},t,this)})),function(t){return i.apply(this,arguments)})},{key:"captureAndUploadSnapshot",value:(e=n(c().m(function t(){return c().w(function(t){for(;;)switch(t.n){case 0:this.showCameraInWidget();case 1:return t.a(2)}},t,this)})),function(){return e.apply(this,arguments)})},{key:"sendMessage",value:(t=n(c().m(function t(){var e,n,s,r;return c().w(function(t){for(;;)switch(t.p=t.n){case 0:if(e=document.getElementById("crm-input"),(n=e.value.trim())&&this.state.isConnected){t.n=1;break}return t.a(2);case 1:return s={guestId:this.state.guestId,conversationId:this.state.conversationId,message:n,timestamp:new Date},t.p=2,this.addMessage(a(a({},s),{},{sender:"guest"})),e.value="",this.state.socket.emit("send-message",s),t.n=3,fetch("".concat(this.config.apiUrl,"/api/v1/webhook/send-message"),{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({apiKey:this.config.apiKey,guestId:this.state.guestId,conversationId:this.state.conversationId,message:n})});case 3:t.n=5;break;case 4:t.p=4,r=t.v,console.error("❌ Send message error:",r),alert("Failed to send message. Please try again.");case 5:return t.a(2)}},t,this,[[2,4]])})),function(){return t.apply(this,arguments)})},{key:"showTypingIndicator",value:function(){var t=this;this.state.isTyping=!0,setTimeout(function(){t.state.isTyping=!1},3e3)}},{key:"playNotificationSound",value:function(){try{var t=new(window.AudioContext||window.webkitAudioContext),e=t.createOscillator(),n=t.createGain();e.connect(n),n.connect(t.destination),e.frequency.value=800,e.type="sine",n.gain.value=.1,e.start(),setTimeout(function(){return e.stop()},200)}catch(t){console.log("Sound playback not available")}}},{key:"formatTime",value:function(t){return new Date(t).toLocaleTimeString("en-US",{hour:"2-digit",minute:"2-digit"})}},{key:"escapeHtml",value:function(t){var e=document.createElement("div");return e.textContent=t,e.innerHTML}},{key:"setupOutsideClick",value:function(){var t=this,e=function(e){if(t.state.isOpen){var n=document.getElementById("crm-chat-window"),s=document.getElementById("crm-chat-button");n&&!n.contains(e.target)&&s&&!s.contains(e.target)&&t.closeChat()}};document.addEventListener("mousedown",e),document.addEventListener("touchstart",e)}}]);var t,e,i,o,h,u,l}();window.ChatCRMWidget={init:function(t){var n=new e(t);return n.setupOutsideClick(),n}}}()}();
|
|
4
4
|
//# sourceMappingURL=chat-widget.min.js.map
|