@pocketping/widget 0.3.3 → 0.3.5

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.
@@ -1,4 +1,4 @@
1
- "use strict";var PocketPing=(()=>{var Y=Object.defineProperty;var st=Object.getOwnPropertyDescriptor;var ot=Object.getOwnPropertyNames;var it=Object.prototype.hasOwnProperty;var rt=(t,e)=>{for(var n in e)Y(t,n,{get:e[n],enumerable:!0})},at=(t,e,n,s)=>{if(e&&typeof e=="object"||typeof e=="function")for(let o of ot(e))!it.call(t,o)&&o!==n&&Y(t,o,{get:()=>e[o],enumerable:!(s=st(e,o))||s.enumerable});return t};var ct=t=>at(Y({},"__esModule",{value:!0}),t);var Et={};rt(Et,{close:()=>Je,default:()=>Ct,destroy:()=>Be,getIdentity:()=>tt,identify:()=>Ye,init:()=>ue,offEvent:()=>Qe,on:()=>nt,onEvent:()=>Ke,open:()=>qe,reset:()=>et,sendMessage:()=>Ge,toggle:()=>Xe,trigger:()=>Ze});var X,g,ve,lt,W,fe,ye,be,xe,se,ee,te,pt,L={},ke=[],dt=/acit|ex(?:s|g|n|p|$)|rph|grid|ows|mnc|ntw|ine[ch]|zoo|^ord|itera/i,G=Array.isArray;function O(t,e){for(var n in e)t[n]=e[n];return t}function oe(t){t&&t.parentNode&&t.parentNode.removeChild(t)}function ie(t,e,n){var s,o,i,a={};for(i in e)i=="key"?s=e[i]:i=="ref"?o=e[i]:a[i]=e[i];if(arguments.length>2&&(a.children=arguments.length>3?X.call(arguments,2):n),typeof t=="function"&&t.defaultProps!=null)for(i in t.defaultProps)a[i]===void 0&&(a[i]=t.defaultProps[i]);return B(t,a,s,o,null)}function B(t,e,n,s,o){var i={type:t,props:e,key:n,ref:s,__k:null,__:null,__b:0,__e:null,__c:null,constructor:void 0,__v:o??++ve,__i:-1,__u:0};return o==null&&g.vnode!=null&&g.vnode(i),i}function E(t){return t.children}function q(t,e){this.props=t,this.context=e}function U(t,e){if(e==null)return t.__?U(t.__,t.__i+1):null;for(var n;e<t.__k.length;e++)if((n=t.__k[e])!=null&&n.__e!=null)return n.__e;return typeof t.type=="function"?U(t):null}function we(t){var e,n;if((t=t.__)!=null&&t.__c!=null){for(t.__e=t.__c.base=null,e=0;e<t.__k.length;e++)if((n=t.__k[e])!=null&&n.__e!=null){t.__e=t.__c.base=n.__e;break}return we(t)}}function ge(t){(!t.__d&&(t.__d=!0)&&W.push(t)&&!J.__r++||fe!=g.debounceRendering)&&((fe=g.debounceRendering)||ye)(J)}function J(){for(var t,e,n,s,o,i,a,c=1;W.length;)W.length>c&&W.sort(be),t=W.shift(),c=W.length,t.__d&&(n=void 0,s=void 0,o=(s=(e=t).__v).__e,i=[],a=[],e.__P&&((n=O({},s)).__v=s.__v+1,g.vnode&&g.vnode(n),re(e.__P,n,s,e.__n,e.__P.namespaceURI,32&s.__u?[o]:null,i,o??U(s),!!(32&s.__u),a),n.__v=s.__v,n.__.__k[n.__i]=n,Ie(i,n,a),s.__e=s.__=null,n.__e!=o&&we(n)));J.__r=0}function Pe(t,e,n,s,o,i,a,c,p,l,f){var r,u,_,x,S,b,v,h=s&&s.__k||ke,M=e.length;for(p=_t(n,e,h,p,M),r=0;r<M;r++)(_=n.__k[r])!=null&&(u=_.__i==-1?L:h[_.__i]||L,_.__i=r,b=re(t,_,u,o,i,a,c,p,l,f),x=_.__e,_.ref&&u.ref!=_.ref&&(u.ref&&ae(u.ref,null,_),f.push(_.ref,_.__c||x,_)),S==null&&x!=null&&(S=x),(v=!!(4&_.__u))||u.__k===_.__k?p=Se(_,p,t,v):typeof _.type=="function"&&b!==void 0?p=b:x&&(p=x.nextSibling),_.__u&=-7);return n.__e=S,p}function _t(t,e,n,s,o){var i,a,c,p,l,f=n.length,r=f,u=0;for(t.__k=new Array(o),i=0;i<o;i++)(a=e[i])!=null&&typeof a!="boolean"&&typeof a!="function"?(typeof a=="string"||typeof a=="number"||typeof a=="bigint"||a.constructor==String?a=t.__k[i]=B(null,a,null,null,null):G(a)?a=t.__k[i]=B(E,{children:a},null,null,null):a.constructor===void 0&&a.__b>0?a=t.__k[i]=B(a.type,a.props,a.key,a.ref?a.ref:null,a.__v):t.__k[i]=a,p=i+u,a.__=t,a.__b=t.__b+1,c=null,(l=a.__i=ut(a,n,p,r))!=-1&&(r--,(c=n[l])&&(c.__u|=2)),c==null||c.__v==null?(l==-1&&(o>f?u--:o<f&&u++),typeof a.type!="function"&&(a.__u|=4)):l!=p&&(l==p-1?u--:l==p+1?u++:(l>p?u--:u++,a.__u|=4))):t.__k[i]=null;if(r)for(i=0;i<f;i++)(c=n[i])!=null&&(2&c.__u)==0&&(c.__e==s&&(s=U(c)),Ee(c,c));return s}function Se(t,e,n,s){var o,i;if(typeof t.type=="function"){for(o=t.__k,i=0;o&&i<o.length;i++)o[i]&&(o[i].__=t,e=Se(o[i],e,n,s));return e}t.__e!=e&&(s&&(e&&t.type&&!e.parentNode&&(e=U(t)),n.insertBefore(t.__e,e||null)),e=t.__e);do e=e&&e.nextSibling;while(e!=null&&e.nodeType==8);return e}function ut(t,e,n,s){var o,i,a,c=t.key,p=t.type,l=e[n],f=l!=null&&(2&l.__u)==0;if(l===null&&c==null||f&&c==l.key&&p==l.type)return n;if(s>(f?1:0)){for(o=n-1,i=n+1;o>=0||i<e.length;)if((l=e[a=o>=0?o--:i++])!=null&&(2&l.__u)==0&&c==l.key&&p==l.type)return a}return-1}function he(t,e,n){e[0]=="-"?t.setProperty(e,n??""):t[e]=n==null?"":typeof n!="number"||dt.test(e)?n:n+"px"}function z(t,e,n,s,o){var i,a;e:if(e=="style")if(typeof n=="string")t.style.cssText=n;else{if(typeof s=="string"&&(t.style.cssText=s=""),s)for(e in s)n&&e in n||he(t.style,e,"");if(n)for(e in n)s&&n[e]==s[e]||he(t.style,e,n[e])}else if(e[0]=="o"&&e[1]=="n")i=e!=(e=e.replace(xe,"$1")),a=e.toLowerCase(),e=a in t||e=="onFocusOut"||e=="onFocusIn"?a.slice(2):e.slice(2),t.l||(t.l={}),t.l[e+i]=n,n?s?n.u=s.u:(n.u=se,t.addEventListener(e,i?te:ee,i)):t.removeEventListener(e,i?te:ee,i);else{if(o=="http://www.w3.org/2000/svg")e=e.replace(/xlink(H|:h)/,"h").replace(/sName$/,"s");else if(e!="width"&&e!="height"&&e!="href"&&e!="list"&&e!="form"&&e!="tabIndex"&&e!="download"&&e!="rowSpan"&&e!="colSpan"&&e!="role"&&e!="popover"&&e in t)try{t[e]=n??"";break e}catch{}typeof n=="function"||(n==null||n===!1&&e[4]!="-"?t.removeAttribute(e):t.setAttribute(e,e=="popover"&&n==1?"":n))}}function me(t){return function(e){if(this.l){var n=this.l[e.type+t];if(e.t==null)e.t=se++;else if(e.t<n.u)return;return n(g.event?g.event(e):e)}}}function re(t,e,n,s,o,i,a,c,p,l){var f,r,u,_,x,S,b,v,h,M,T,H,R,m,P,C,D,I=e.type;if(e.constructor!==void 0)return null;128&n.__u&&(p=!!(32&n.__u),i=[c=e.__e=n.__e]),(f=g.__b)&&f(e);e:if(typeof I=="function")try{if(v=e.props,h="prototype"in I&&I.prototype.render,M=(f=I.contextType)&&s[f.__c],T=f?M?M.props.value:f.__:s,n.__c?b=(r=e.__c=n.__c).__=r.__E:(h?e.__c=r=new I(v,T):(e.__c=r=new q(v,T),r.constructor=I,r.render=gt),M&&M.sub(r),r.state||(r.state={}),r.__n=s,u=r.__d=!0,r.__h=[],r._sb=[]),h&&r.__s==null&&(r.__s=r.state),h&&I.getDerivedStateFromProps!=null&&(r.__s==r.state&&(r.__s=O({},r.__s)),O(r.__s,I.getDerivedStateFromProps(v,r.__s))),_=r.props,x=r.state,r.__v=e,u)h&&I.getDerivedStateFromProps==null&&r.componentWillMount!=null&&r.componentWillMount(),h&&r.componentDidMount!=null&&r.__h.push(r.componentDidMount);else{if(h&&I.getDerivedStateFromProps==null&&v!==_&&r.componentWillReceiveProps!=null&&r.componentWillReceiveProps(v,T),e.__v==n.__v||!r.__e&&r.shouldComponentUpdate!=null&&r.shouldComponentUpdate(v,r.__s,T)===!1){for(e.__v!=n.__v&&(r.props=v,r.state=r.__s,r.__d=!1),e.__e=n.__e,e.__k=n.__k,e.__k.some(function($){$&&($.__=e)}),H=0;H<r._sb.length;H++)r.__h.push(r._sb[H]);r._sb=[],r.__h.length&&a.push(r);break e}r.componentWillUpdate!=null&&r.componentWillUpdate(v,r.__s,T),h&&r.componentDidUpdate!=null&&r.__h.push(function(){r.componentDidUpdate(_,x,S)})}if(r.context=T,r.props=v,r.__P=t,r.__e=!1,R=g.__r,m=0,h){for(r.state=r.__s,r.__d=!1,R&&R(e),f=r.render(r.props,r.state,r.context),P=0;P<r._sb.length;P++)r.__h.push(r._sb[P]);r._sb=[]}else do r.__d=!1,R&&R(e),f=r.render(r.props,r.state,r.context),r.state=r.__s;while(r.__d&&++m<25);r.state=r.__s,r.getChildContext!=null&&(s=O(O({},s),r.getChildContext())),h&&!u&&r.getSnapshotBeforeUpdate!=null&&(S=r.getSnapshotBeforeUpdate(_,x)),C=f,f!=null&&f.type===E&&f.key==null&&(C=Ce(f.props.children)),c=Pe(t,G(C)?C:[C],e,n,s,o,i,a,c,p,l),r.base=e.__e,e.__u&=-161,r.__h.length&&a.push(r),b&&(r.__E=r.__=null)}catch($){if(e.__v=null,p||i!=null)if($.then){for(e.__u|=p?160:128;c&&c.nodeType==8&&c.nextSibling;)c=c.nextSibling;i[i.indexOf(c)]=null,e.__e=c}else{for(D=i.length;D--;)oe(i[D]);ne(e)}else e.__e=n.__e,e.__k=n.__k,$.then||ne(e);g.__e($,e,n)}else i==null&&e.__v==n.__v?(e.__k=n.__k,e.__e=n.__e):c=e.__e=ft(n.__e,e,n,s,o,i,a,p,l);return(f=g.diffed)&&f(e),128&e.__u?void 0:c}function ne(t){t&&t.__c&&(t.__c.__e=!0),t&&t.__k&&t.__k.forEach(ne)}function Ie(t,e,n){for(var s=0;s<n.length;s++)ae(n[s],n[++s],n[++s]);g.__c&&g.__c(e,t),t.some(function(o){try{t=o.__h,o.__h=[],t.some(function(i){i.call(o)})}catch(i){g.__e(i,o.__v)}})}function Ce(t){return typeof t!="object"||t==null||t.__b&&t.__b>0?t:G(t)?t.map(Ce):O({},t)}function ft(t,e,n,s,o,i,a,c,p){var l,f,r,u,_,x,S,b=n.props||L,v=e.props,h=e.type;if(h=="svg"?o="http://www.w3.org/2000/svg":h=="math"?o="http://www.w3.org/1998/Math/MathML":o||(o="http://www.w3.org/1999/xhtml"),i!=null){for(l=0;l<i.length;l++)if((_=i[l])&&"setAttribute"in _==!!h&&(h?_.localName==h:_.nodeType==3)){t=_,i[l]=null;break}}if(t==null){if(h==null)return document.createTextNode(v);t=document.createElementNS(o,h,v.is&&v),c&&(g.__m&&g.__m(e,i),c=!1),i=null}if(h==null)b===v||c&&t.data==v||(t.data=v);else{if(i=i&&X.call(t.childNodes),!c&&i!=null)for(b={},l=0;l<t.attributes.length;l++)b[(_=t.attributes[l]).name]=_.value;for(l in b)if(_=b[l],l!="children"){if(l=="dangerouslySetInnerHTML")r=_;else if(!(l in v)){if(l=="value"&&"defaultValue"in v||l=="checked"&&"defaultChecked"in v)continue;z(t,l,null,_,o)}}for(l in v)_=v[l],l=="children"?u=_:l=="dangerouslySetInnerHTML"?f=_:l=="value"?x=_:l=="checked"?S=_:c&&typeof _!="function"||b[l]===_||z(t,l,_,b[l],o);if(f)c||r&&(f.__html==r.__html||f.__html==t.innerHTML)||(t.innerHTML=f.__html),e.__k=[];else if(r&&(t.innerHTML=""),Pe(e.type=="template"?t.content:t,G(u)?u:[u],e,n,s,h=="foreignObject"?"http://www.w3.org/1999/xhtml":o,i,a,i?i[0]:n.__k&&U(n,0),c,p),i!=null)for(l=i.length;l--;)oe(i[l]);c||(l="value",h=="progress"&&x==null?t.removeAttribute("value"):x!=null&&(x!==t[l]||h=="progress"&&!x||h=="option"&&x!=b[l])&&z(t,l,x,b[l],o),l="checked",S!=null&&S!=t[l]&&z(t,l,S,b[l],o))}return t}function ae(t,e,n){try{if(typeof t=="function"){var s=typeof t.__u=="function";s&&t.__u(),s&&e==null||(t.__u=t(e))}else t.current=e}catch(o){g.__e(o,n)}}function Ee(t,e,n){var s,o;if(g.unmount&&g.unmount(t),(s=t.ref)&&(s.current&&s.current!=t.__e||ae(s,null,e)),(s=t.__c)!=null){if(s.componentWillUnmount)try{s.componentWillUnmount()}catch(i){g.__e(i,e)}s.base=s.__P=null}if(s=t.__k)for(o=0;o<s.length;o++)s[o]&&Ee(s[o],e,n||typeof t.type!="function");n||oe(t.__e),t.__c=t.__=t.__e=void 0}function gt(t,e,n){return this.constructor(t,n)}function ce(t,e,n){var s,o,i,a;e==document&&(e=document.documentElement),g.__&&g.__(t,e),o=(s=typeof n=="function")?null:n&&n.__k||e.__k,i=[],a=[],re(e,t=(!s&&n||e).__k=ie(E,null,[t]),o||L,L,e.namespaceURI,!s&&n?[n]:o?null:e.firstChild?X.call(e.childNodes):null,i,!s&&n?n:o?o.__e:e.firstChild,s,a),Ie(i,t,a)}X=ke.slice,g={__e:function(t,e,n,s){for(var o,i,a;e=e.__;)if((o=e.__c)&&!o.__)try{if((i=o.constructor)&&i.getDerivedStateFromError!=null&&(o.setState(i.getDerivedStateFromError(t)),a=o.__d),o.componentDidCatch!=null&&(o.componentDidCatch(t,s||{}),a=o.__d),a)return o.__E=o}catch(c){t=c}throw t}},ve=0,lt=function(t){return t!=null&&t.constructor===void 0},q.prototype.setState=function(t,e){var n;n=this.__s!=null&&this.__s!=this.state?this.__s:this.__s=O({},this.state),typeof t=="function"&&(t=t(O({},n),this.props)),t&&O(n,t),t!=null&&this.__v&&(e&&this._sb.push(e),ge(this))},q.prototype.forceUpdate=function(t){this.__v&&(this.__e=!0,t&&this.__h.push(t),ge(this))},q.prototype.render=E,W=[],ye=typeof Promise=="function"?Promise.prototype.then.bind(Promise.resolve()):setTimeout,be=function(t,e){return t.__v.__b-e.__v.__b},J.__r=0,xe=/(PointerCapture)$|Capture$/i,se=0,ee=me(!1),te=me(!0),pt=0;var F,k,le,Me,j=0,Ve=[],w=g,Te=w.__b,$e=w.__r,Oe=w.diffed,Ae=w.__c,He=w.unmount,Re=w.__;function de(t,e){w.__h&&w.__h(k,t,j||e),j=0;var n=k.__H||(k.__H={__:[],__h:[]});return t>=n.__.length&&n.__.push({}),n.__[t]}function V(t){return j=1,ht(Le,t)}function ht(t,e,n){var s=de(F++,2);if(s.t=t,!s.__c&&(s.__=[n?n(e):Le(void 0,e),function(c){var p=s.__N?s.__N[0]:s.__[0],l=s.t(p,c);p!==l&&(s.__N=[l,s.__[1]],s.__c.setState({}))}],s.__c=k,!k.__f)){var o=function(c,p,l){if(!s.__c.__H)return!0;var f=s.__c.__H.__.filter(function(u){return!!u.__c});if(f.every(function(u){return!u.__N}))return!i||i.call(this,c,p,l);var r=s.__c.props!==c;return f.forEach(function(u){if(u.__N){var _=u.__[0];u.__=u.__N,u.__N=void 0,_!==u.__[0]&&(r=!0)}}),i&&i.call(this,c,p,l)||r};k.__f=!0;var i=k.shouldComponentUpdate,a=k.componentWillUpdate;k.componentWillUpdate=function(c,p,l){if(this.__e){var f=i;i=void 0,o(c,p,l),i=f}a&&a.call(this,c,p,l)},k.shouldComponentUpdate=o}return s.__N||s.__}function N(t,e){var n=de(F++,3);!w.__s&&De(n.__H,e)&&(n.__=t,n.u=e,k.__H.__h.push(n))}function _e(t){return j=5,Ne(function(){return{current:t}},[])}function Ne(t,e){var n=de(F++,7);return De(n.__H,e)&&(n.__=t(),n.__H=e,n.__h=t),n.__}function Ue(t,e){return j=8,Ne(function(){return t},e)}function mt(){for(var t;t=Ve.shift();)if(t.__P&&t.__H)try{t.__H.__h.forEach(Z),t.__H.__h.forEach(pe),t.__H.__h=[]}catch(e){t.__H.__h=[],w.__e(e,t.__v)}}w.__b=function(t){k=null,Te&&Te(t)},w.__=function(t,e){t&&e.__k&&e.__k.__m&&(t.__m=e.__k.__m),Re&&Re(t,e)},w.__r=function(t){$e&&$e(t),F=0;var e=(k=t.__c).__H;e&&(le===k?(e.__h=[],k.__h=[],e.__.forEach(function(n){n.__N&&(n.__=n.__N),n.u=n.__N=void 0})):(e.__h.forEach(Z),e.__h.forEach(pe),e.__h=[],F=0)),le=k},w.diffed=function(t){Oe&&Oe(t);var e=t.__c;e&&e.__H&&(e.__H.__h.length&&(Ve.push(e)!==1&&Me===w.requestAnimationFrame||((Me=w.requestAnimationFrame)||vt)(mt)),e.__H.__.forEach(function(n){n.u&&(n.__H=n.u),n.u=void 0})),le=k=null},w.__c=function(t,e){e.some(function(n){try{n.__h.forEach(Z),n.__h=n.__h.filter(function(s){return!s.__||pe(s)})}catch(s){e.some(function(o){o.__h&&(o.__h=[])}),e=[],w.__e(s,n.__v)}}),Ae&&Ae(t,e)},w.unmount=function(t){He&&He(t);var e,n=t.__c;n&&n.__H&&(n.__H.__.forEach(function(s){try{Z(s)}catch(o){e=o}}),n.__H=void 0,e&&w.__e(e,n.__v))};var We=typeof requestAnimationFrame=="function";function vt(t){var e,n=function(){clearTimeout(s),We&&cancelAnimationFrame(e),setTimeout(t)},s=setTimeout(n,35);We&&(e=requestAnimationFrame(n))}function Z(t){var e=k,n=t.__c;typeof n=="function"&&(t.__c=void 0,n()),k=e}function pe(t){var e=k;t.__c=t.__(),k=e}function De(t,e){return!t||t.length!==e.length||e.some(function(n,s){return n!==t[s]})}function Le(t,e){return typeof e=="function"?e(t):e}function Fe(t,e){let n=e==="dark",s={bg:n?"#1f2937":"#ffffff",bgSecondary:n?"#374151":"#f3f4f6",text:n?"#f9fafb":"#111827",textSecondary:n?"#9ca3af":"#6b7280",border:n?"#4b5563":"#e5e7eb",messageBg:n?"#374151":"#f3f4f6"};return`
1
+ "use strict";var PocketPing=(()=>{var Q=Object.defineProperty;var ot=Object.getOwnPropertyDescriptor;var rt=Object.getOwnPropertyNames;var at=Object.prototype.hasOwnProperty;var lt=(t,e)=>{for(var n in e)Q(t,n,{get:e[n],enumerable:!0})},ct=(t,e,n,s)=>{if(e&&typeof e=="object"||typeof e=="function")for(let i of rt(e))!at.call(t,i)&&i!==n&&Q(t,i,{get:()=>e[i],enumerable:!(s=ot(e,i))||s.enumerable});return t};var pt=t=>ct(Q({},"__esModule",{value:!0}),t);var Mt={};lt(Mt,{close:()=>Je,default:()=>Tt,destroy:()=>Be,getIdentity:()=>st,getTrackedElements:()=>Ke,identify:()=>tt,init:()=>_e,offEvent:()=>et,on:()=>it,onEvent:()=>Qe,open:()=>qe,reset:()=>nt,sendMessage:()=>Ge,setupTrackedElements:()=>Ze,toggle:()=>Xe,trigger:()=>Ye});var X,f,ve,dt,L,ge,ye,be,ke,se,ee,te,ut,U={},xe=[],_t=/acit|ex(?:s|g|n|p|$)|rph|grid|ows|mnc|ntw|ine[ch]|zoo|^ord|itera/i,G=Array.isArray;function O(t,e){for(var n in e)t[n]=e[n];return t}function ie(t){t&&t.parentNode&&t.parentNode.removeChild(t)}function oe(t,e,n){var s,i,o,l={};for(o in e)o=="key"?s=e[o]:o=="ref"?i=e[o]:l[o]=e[o];if(arguments.length>2&&(l.children=arguments.length>3?X.call(arguments,2):n),typeof t=="function"&&t.defaultProps!=null)for(o in t.defaultProps)l[o]===void 0&&(l[o]=t.defaultProps[o]);return B(t,l,s,i,null)}function B(t,e,n,s,i){var o={type:t,props:e,key:n,ref:s,__k:null,__:null,__b:0,__e:null,__c:null,constructor:void 0,__v:i??++ve,__i:-1,__u:0};return i==null&&f.vnode!=null&&f.vnode(o),o}function C(t){return t.children}function q(t,e){this.props=t,this.context=e}function V(t,e){if(e==null)return t.__?V(t.__,t.__i+1):null;for(var n;e<t.__k.length;e++)if((n=t.__k[e])!=null&&n.__e!=null)return n.__e;return typeof t.type=="function"?V(t):null}function we(t){var e,n;if((t=t.__)!=null&&t.__c!=null){for(t.__e=t.__c.base=null,e=0;e<t.__k.length;e++)if((n=t.__k[e])!=null&&n.__e!=null){t.__e=t.__c.base=n.__e;break}return we(t)}}function fe(t){(!t.__d&&(t.__d=!0)&&L.push(t)&&!J.__r++||ge!=f.debounceRendering)&&((ge=f.debounceRendering)||ye)(J)}function J(){for(var t,e,n,s,i,o,l,c=1;L.length;)L.length>c&&L.sort(be),t=L.shift(),c=L.length,t.__d&&(n=void 0,s=void 0,i=(s=(e=t).__v).__e,o=[],l=[],e.__P&&((n=O({},s)).__v=s.__v+1,f.vnode&&f.vnode(n),re(e.__P,n,s,e.__n,e.__P.namespaceURI,32&s.__u?[i]:null,o,i??V(s),!!(32&s.__u),l),n.__v=s.__v,n.__.__k[n.__i]=n,Se(o,n,l),s.__e=s.__=null,n.__e!=i&&we(n)));J.__r=0}function Pe(t,e,n,s,i,o,l,c,p,a,_){var r,d,g,k,P,y,b,m=s&&s.__k||xe,T=e.length;for(p=gt(n,e,m,p,T),r=0;r<T;r++)(g=n.__k[r])!=null&&(d=g.__i==-1?U:m[g.__i]||U,g.__i=r,y=re(t,g,d,i,o,l,c,p,a,_),k=g.__e,g.ref&&d.ref!=g.ref&&(d.ref&&ae(d.ref,null,g),_.push(g.ref,g.__c||k,g)),P==null&&k!=null&&(P=k),(b=!!(4&g.__u))||d.__k===g.__k?p=Ee(g,p,t,b):typeof g.type=="function"&&y!==void 0?p=y:k&&(p=k.nextSibling),g.__u&=-7);return n.__e=P,p}function gt(t,e,n,s,i){var o,l,c,p,a,_=n.length,r=_,d=0;for(t.__k=new Array(i),o=0;o<i;o++)(l=e[o])!=null&&typeof l!="boolean"&&typeof l!="function"?(typeof l=="string"||typeof l=="number"||typeof l=="bigint"||l.constructor==String?l=t.__k[o]=B(null,l,null,null,null):G(l)?l=t.__k[o]=B(C,{children:l},null,null,null):l.constructor===void 0&&l.__b>0?l=t.__k[o]=B(l.type,l.props,l.key,l.ref?l.ref:null,l.__v):t.__k[o]=l,p=o+d,l.__=t,l.__b=t.__b+1,c=null,(a=l.__i=ft(l,n,p,r))!=-1&&(r--,(c=n[a])&&(c.__u|=2)),c==null||c.__v==null?(a==-1&&(i>_?d--:i<_&&d++),typeof l.type!="function"&&(l.__u|=4)):a!=p&&(a==p-1?d--:a==p+1?d++:(a>p?d--:d++,l.__u|=4))):t.__k[o]=null;if(r)for(o=0;o<_;o++)(c=n[o])!=null&&(2&c.__u)==0&&(c.__e==s&&(s=V(c)),Ce(c,c));return s}function Ee(t,e,n,s){var i,o;if(typeof t.type=="function"){for(i=t.__k,o=0;i&&o<i.length;o++)i[o]&&(i[o].__=t,e=Ee(i[o],e,n,s));return e}t.__e!=e&&(s&&(e&&t.type&&!e.parentNode&&(e=V(t)),n.insertBefore(t.__e,e||null)),e=t.__e);do e=e&&e.nextSibling;while(e!=null&&e.nodeType==8);return e}function ft(t,e,n,s){var i,o,l,c=t.key,p=t.type,a=e[n],_=a!=null&&(2&a.__u)==0;if(a===null&&c==null||_&&c==a.key&&p==a.type)return n;if(s>(_?1:0)){for(i=n-1,o=n+1;i>=0||o<e.length;)if((a=e[l=i>=0?i--:o++])!=null&&(2&a.__u)==0&&c==a.key&&p==a.type)return l}return-1}function he(t,e,n){e[0]=="-"?t.setProperty(e,n??""):t[e]=n==null?"":typeof n!="number"||_t.test(e)?n:n+"px"}function j(t,e,n,s,i){var o,l;e:if(e=="style")if(typeof n=="string")t.style.cssText=n;else{if(typeof s=="string"&&(t.style.cssText=s=""),s)for(e in s)n&&e in n||he(t.style,e,"");if(n)for(e in n)s&&n[e]==s[e]||he(t.style,e,n[e])}else if(e[0]=="o"&&e[1]=="n")o=e!=(e=e.replace(ke,"$1")),l=e.toLowerCase(),e=l in t||e=="onFocusOut"||e=="onFocusIn"?l.slice(2):e.slice(2),t.l||(t.l={}),t.l[e+o]=n,n?s?n.u=s.u:(n.u=se,t.addEventListener(e,o?te:ee,o)):t.removeEventListener(e,o?te:ee,o);else{if(i=="http://www.w3.org/2000/svg")e=e.replace(/xlink(H|:h)/,"h").replace(/sName$/,"s");else if(e!="width"&&e!="height"&&e!="href"&&e!="list"&&e!="form"&&e!="tabIndex"&&e!="download"&&e!="rowSpan"&&e!="colSpan"&&e!="role"&&e!="popover"&&e in t)try{t[e]=n??"";break e}catch{}typeof n=="function"||(n==null||n===!1&&e[4]!="-"?t.removeAttribute(e):t.setAttribute(e,e=="popover"&&n==1?"":n))}}function me(t){return function(e){if(this.l){var n=this.l[e.type+t];if(e.t==null)e.t=se++;else if(e.t<n.u)return;return n(f.event?f.event(e):e)}}}function re(t,e,n,s,i,o,l,c,p,a){var _,r,d,g,k,P,y,b,m,T,M,H,R,v,E,I,F,S=e.type;if(e.constructor!==void 0)return null;128&n.__u&&(p=!!(32&n.__u),o=[c=e.__e=n.__e]),(_=f.__b)&&_(e);e:if(typeof S=="function")try{if(b=e.props,m="prototype"in S&&S.prototype.render,T=(_=S.contextType)&&s[_.__c],M=_?T?T.props.value:_.__:s,n.__c?y=(r=e.__c=n.__c).__=r.__E:(m?e.__c=r=new S(b,M):(e.__c=r=new q(b,M),r.constructor=S,r.render=mt),T&&T.sub(r),r.state||(r.state={}),r.__n=s,d=r.__d=!0,r.__h=[],r._sb=[]),m&&r.__s==null&&(r.__s=r.state),m&&S.getDerivedStateFromProps!=null&&(r.__s==r.state&&(r.__s=O({},r.__s)),O(r.__s,S.getDerivedStateFromProps(b,r.__s))),g=r.props,k=r.state,r.__v=e,d)m&&S.getDerivedStateFromProps==null&&r.componentWillMount!=null&&r.componentWillMount(),m&&r.componentDidMount!=null&&r.__h.push(r.componentDidMount);else{if(m&&S.getDerivedStateFromProps==null&&b!==g&&r.componentWillReceiveProps!=null&&r.componentWillReceiveProps(b,M),e.__v==n.__v||!r.__e&&r.shouldComponentUpdate!=null&&r.shouldComponentUpdate(b,r.__s,M)===!1){for(e.__v!=n.__v&&(r.props=b,r.state=r.__s,r.__d=!1),e.__e=n.__e,e.__k=n.__k,e.__k.some(function($){$&&($.__=e)}),H=0;H<r._sb.length;H++)r.__h.push(r._sb[H]);r._sb=[],r.__h.length&&l.push(r);break e}r.componentWillUpdate!=null&&r.componentWillUpdate(b,r.__s,M),m&&r.componentDidUpdate!=null&&r.__h.push(function(){r.componentDidUpdate(g,k,P)})}if(r.context=M,r.props=b,r.__P=t,r.__e=!1,R=f.__r,v=0,m){for(r.state=r.__s,r.__d=!1,R&&R(e),_=r.render(r.props,r.state,r.context),E=0;E<r._sb.length;E++)r.__h.push(r._sb[E]);r._sb=[]}else do r.__d=!1,R&&R(e),_=r.render(r.props,r.state,r.context),r.state=r.__s;while(r.__d&&++v<25);r.state=r.__s,r.getChildContext!=null&&(s=O(O({},s),r.getChildContext())),m&&!d&&r.getSnapshotBeforeUpdate!=null&&(P=r.getSnapshotBeforeUpdate(g,k)),I=_,_!=null&&_.type===C&&_.key==null&&(I=Ie(_.props.children)),c=Pe(t,G(I)?I:[I],e,n,s,i,o,l,c,p,a),r.base=e.__e,e.__u&=-161,r.__h.length&&l.push(r),y&&(r.__E=r.__=null)}catch($){if(e.__v=null,p||o!=null)if($.then){for(e.__u|=p?160:128;c&&c.nodeType==8&&c.nextSibling;)c=c.nextSibling;o[o.indexOf(c)]=null,e.__e=c}else{for(F=o.length;F--;)ie(o[F]);ne(e)}else e.__e=n.__e,e.__k=n.__k,$.then||ne(e);f.__e($,e,n)}else o==null&&e.__v==n.__v?(e.__k=n.__k,e.__e=n.__e):c=e.__e=ht(n.__e,e,n,s,i,o,l,p,a);return(_=f.diffed)&&_(e),128&e.__u?void 0:c}function ne(t){t&&t.__c&&(t.__c.__e=!0),t&&t.__k&&t.__k.forEach(ne)}function Se(t,e,n){for(var s=0;s<n.length;s++)ae(n[s],n[++s],n[++s]);f.__c&&f.__c(e,t),t.some(function(i){try{t=i.__h,i.__h=[],t.some(function(o){o.call(i)})}catch(o){f.__e(o,i.__v)}})}function Ie(t){return typeof t!="object"||t==null||t.__b&&t.__b>0?t:G(t)?t.map(Ie):O({},t)}function ht(t,e,n,s,i,o,l,c,p){var a,_,r,d,g,k,P,y=n.props||U,b=e.props,m=e.type;if(m=="svg"?i="http://www.w3.org/2000/svg":m=="math"?i="http://www.w3.org/1998/Math/MathML":i||(i="http://www.w3.org/1999/xhtml"),o!=null){for(a=0;a<o.length;a++)if((g=o[a])&&"setAttribute"in g==!!m&&(m?g.localName==m:g.nodeType==3)){t=g,o[a]=null;break}}if(t==null){if(m==null)return document.createTextNode(b);t=document.createElementNS(i,m,b.is&&b),c&&(f.__m&&f.__m(e,o),c=!1),o=null}if(m==null)y===b||c&&t.data==b||(t.data=b);else{if(o=o&&X.call(t.childNodes),!c&&o!=null)for(y={},a=0;a<t.attributes.length;a++)y[(g=t.attributes[a]).name]=g.value;for(a in y)if(g=y[a],a!="children"){if(a=="dangerouslySetInnerHTML")r=g;else if(!(a in b)){if(a=="value"&&"defaultValue"in b||a=="checked"&&"defaultChecked"in b)continue;j(t,a,null,g,i)}}for(a in b)g=b[a],a=="children"?d=g:a=="dangerouslySetInnerHTML"?_=g:a=="value"?k=g:a=="checked"?P=g:c&&typeof g!="function"||y[a]===g||j(t,a,g,y[a],i);if(_)c||r&&(_.__html==r.__html||_.__html==t.innerHTML)||(t.innerHTML=_.__html),e.__k=[];else if(r&&(t.innerHTML=""),Pe(e.type=="template"?t.content:t,G(d)?d:[d],e,n,s,m=="foreignObject"?"http://www.w3.org/1999/xhtml":i,o,l,o?o[0]:n.__k&&V(n,0),c,p),o!=null)for(a=o.length;a--;)ie(o[a]);c||(a="value",m=="progress"&&k==null?t.removeAttribute("value"):k!=null&&(k!==t[a]||m=="progress"&&!k||m=="option"&&k!=y[a])&&j(t,a,k,y[a],i),a="checked",P!=null&&P!=t[a]&&j(t,a,P,y[a],i))}return t}function ae(t,e,n){try{if(typeof t=="function"){var s=typeof t.__u=="function";s&&t.__u(),s&&e==null||(t.__u=t(e))}else t.current=e}catch(i){f.__e(i,n)}}function Ce(t,e,n){var s,i;if(f.unmount&&f.unmount(t),(s=t.ref)&&(s.current&&s.current!=t.__e||ae(s,null,e)),(s=t.__c)!=null){if(s.componentWillUnmount)try{s.componentWillUnmount()}catch(o){f.__e(o,e)}s.base=s.__P=null}if(s=t.__k)for(i=0;i<s.length;i++)s[i]&&Ce(s[i],e,n||typeof t.type!="function");n||ie(t.__e),t.__c=t.__=t.__e=void 0}function mt(t,e,n){return this.constructor(t,n)}function le(t,e,n){var s,i,o,l;e==document&&(e=document.documentElement),f.__&&f.__(t,e),i=(s=typeof n=="function")?null:n&&n.__k||e.__k,o=[],l=[],re(e,t=(!s&&n||e).__k=oe(C,null,[t]),i||U,U,e.namespaceURI,!s&&n?[n]:i?null:e.firstChild?X.call(e.childNodes):null,o,!s&&n?n:i?i.__e:e.firstChild,s,l),Se(o,t,l)}X=xe.slice,f={__e:function(t,e,n,s){for(var i,o,l;e=e.__;)if((i=e.__c)&&!i.__)try{if((o=i.constructor)&&o.getDerivedStateFromError!=null&&(i.setState(o.getDerivedStateFromError(t)),l=i.__d),i.componentDidCatch!=null&&(i.componentDidCatch(t,s||{}),l=i.__d),l)return i.__E=i}catch(c){t=c}throw t}},ve=0,dt=function(t){return t!=null&&t.constructor===void 0},q.prototype.setState=function(t,e){var n;n=this.__s!=null&&this.__s!=this.state?this.__s:this.__s=O({},this.state),typeof t=="function"&&(t=t(O({},n),this.props)),t&&O(n,t),t!=null&&this.__v&&(e&&this._sb.push(e),fe(this))},q.prototype.forceUpdate=function(t){this.__v&&(this.__e=!0,t&&this.__h.push(t),fe(this))},q.prototype.render=C,L=[],ye=typeof Promise=="function"?Promise.prototype.then.bind(Promise.resolve()):setTimeout,be=function(t,e){return t.__v.__b-e.__v.__b},J.__r=0,ke=/(PointerCapture)$|Capture$/i,se=0,ee=me(!1),te=me(!0),ut=0;var D,x,ce,Te,z=0,We=[],w=f,Me=w.__b,$e=w.__r,Oe=w.diffed,Ae=w.__c,He=w.unmount,Re=w.__;function de(t,e){w.__h&&w.__h(x,t,z||e),z=0;var n=x.__H||(x.__H={__:[],__h:[]});return t>=n.__.length&&n.__.push({}),n.__[t]}function W(t){return z=1,vt(Ue,t)}function vt(t,e,n){var s=de(D++,2);if(s.t=t,!s.__c&&(s.__=[n?n(e):Ue(void 0,e),function(c){var p=s.__N?s.__N[0]:s.__[0],a=s.t(p,c);p!==a&&(s.__N=[a,s.__[1]],s.__c.setState({}))}],s.__c=x,!x.__f)){var i=function(c,p,a){if(!s.__c.__H)return!0;var _=s.__c.__H.__.filter(function(d){return!!d.__c});if(_.every(function(d){return!d.__N}))return!o||o.call(this,c,p,a);var r=s.__c.props!==c;return _.forEach(function(d){if(d.__N){var g=d.__[0];d.__=d.__N,d.__N=void 0,g!==d.__[0]&&(r=!0)}}),o&&o.call(this,c,p,a)||r};x.__f=!0;var o=x.shouldComponentUpdate,l=x.componentWillUpdate;x.componentWillUpdate=function(c,p,a){if(this.__e){var _=o;o=void 0,i(c,p,a),o=_}l&&l.call(this,c,p,a)},x.shouldComponentUpdate=i}return s.__N||s.__}function N(t,e){var n=de(D++,3);!w.__s&&Fe(n.__H,e)&&(n.__=t,n.u=e,x.__H.__h.push(n))}function ue(t){return z=5,Ne(function(){return{current:t}},[])}function Ne(t,e){var n=de(D++,7);return Fe(n.__H,e)&&(n.__=t(),n.__H=e,n.__h=t),n.__}function Ve(t,e){return z=8,Ne(function(){return t},e)}function yt(){for(var t;t=We.shift();)if(t.__P&&t.__H)try{t.__H.__h.forEach(Y),t.__H.__h.forEach(pe),t.__H.__h=[]}catch(e){t.__H.__h=[],w.__e(e,t.__v)}}w.__b=function(t){x=null,Me&&Me(t)},w.__=function(t,e){t&&e.__k&&e.__k.__m&&(t.__m=e.__k.__m),Re&&Re(t,e)},w.__r=function(t){$e&&$e(t),D=0;var e=(x=t.__c).__H;e&&(ce===x?(e.__h=[],x.__h=[],e.__.forEach(function(n){n.__N&&(n.__=n.__N),n.u=n.__N=void 0})):(e.__h.forEach(Y),e.__h.forEach(pe),e.__h=[],D=0)),ce=x},w.diffed=function(t){Oe&&Oe(t);var e=t.__c;e&&e.__H&&(e.__H.__h.length&&(We.push(e)!==1&&Te===w.requestAnimationFrame||((Te=w.requestAnimationFrame)||bt)(yt)),e.__H.__.forEach(function(n){n.u&&(n.__H=n.u),n.u=void 0})),ce=x=null},w.__c=function(t,e){e.some(function(n){try{n.__h.forEach(Y),n.__h=n.__h.filter(function(s){return!s.__||pe(s)})}catch(s){e.some(function(i){i.__h&&(i.__h=[])}),e=[],w.__e(s,n.__v)}}),Ae&&Ae(t,e)},w.unmount=function(t){He&&He(t);var e,n=t.__c;n&&n.__H&&(n.__H.__.forEach(function(s){try{Y(s)}catch(i){e=i}}),n.__H=void 0,e&&w.__e(e,n.__v))};var Le=typeof requestAnimationFrame=="function";function bt(t){var e,n=function(){clearTimeout(s),Le&&cancelAnimationFrame(e),setTimeout(t)},s=setTimeout(n,35);Le&&(e=requestAnimationFrame(n))}function Y(t){var e=x,n=t.__c;typeof n=="function"&&(t.__c=void 0,n()),x=e}function pe(t){var e=x;t.__c=t.__(),x=e}function Fe(t,e){return!t||t.length!==e.length||e.some(function(n,s){return n!==t[s]})}function Ue(t,e){return typeof e=="function"?e(t):e}function De(t,e){let n=e==="dark",s={bg:n?"#1f2937":"#ffffff",bgSecondary:n?"#374151":"#f3f4f6",text:n?"#f9fafb":"#111827",textSecondary:n?"#9ca3af":"#6b7280",border:n?"#4b5563":"#e5e7eb",messageBg:n?"#374151":"#f3f4f6"};return`
2
2
  #pocketping-container {
3
3
  font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, 'Helvetica Neue', Arial, sans-serif;
4
4
  font-size: 14px;
@@ -326,4 +326,92 @@
326
326
  .pp-footer a:hover {
327
327
  text-decoration: underline;
328
328
  }
329
- `}var yt=0;function d(t,e,n,s,o,i){e||(e={});var a,c,p=e;if("ref"in p)for(c in p={},e)c=="ref"?a=e[c]:p[c]=e[c];var l={type:t,props:p,key:n,ref:a,__k:null,__:null,__b:0,__e:null,__c:null,constructor:void 0,__v:--yt,__i:-1,__u:0,__source:o,__self:i};if(typeof t=="function"&&(a=t.defaultProps))for(c in a)p[c]===void 0&&(p[c]=a[c]);return g.vnode&&g.vnode(l),l}function ze({client:t,config:e}){let[n,s]=V(!1),[o,i]=V([]),[a,c]=V(""),[p,l]=V(!1),[f,r]=V(!1),[u,_]=V(!1),x=_e(null),S=_e(null);N(()=>{let m=t.on("openChange",s),P=t.on("message",()=>{i([...t.getMessages()])}),C=t.on("typing",$=>{l($.isTyping)}),D=t.on("presence",$=>{r($.online)}),I=t.on("connect",()=>{_(!0),i(t.getMessages()),r(t.getSession()?.operatorOnline??!1)});return t.isConnected()&&(_(!0),i(t.getMessages()),r(t.getSession()?.operatorOnline??!1)),()=>{m(),P(),C(),D(),I()}},[t]),N(()=>{x.current?.scrollIntoView({behavior:"smooth"})},[o]),N(()=>{n&&S.current?.focus()},[n]);let b=Ue(()=>{if(!n||!u)return;let m=o.filter(P=>P.sender!=="visitor"&&P.status!=="read");if(m.length>0){let P=m.map(C=>C.id);t.sendReadStatus(P,"read")}},[n,u,o,t]);if(N(()=>{if(!n||!u)return;let m=setTimeout(()=>{b()},1e3);return()=>clearTimeout(m)},[n,u,o,b]),N(()=>{let m=()=>{document.visibilityState==="visible"&&n&&b()};return document.addEventListener("visibilitychange",m),()=>document.removeEventListener("visibilitychange",m)},[n,b]),N(()=>{let m=t.on("read",()=>{i([...t.getMessages()])});return()=>m()},[t]),!bt(e))return null;let h=async m=>{if(m.preventDefault(),!a.trim())return;let P=a;c("");try{await t.sendMessage(P)}catch(C){console.error("[PocketPing] Failed to send message:",C)}},M=m=>{let P=m.target;c(P.value),t.sendTyping(!0)},T=e.position??"bottom-right",H=xt(e.theme??"auto"),R=e.primaryColor??"#6366f1";return d(E,{children:[d("style",{children:Fe(R,H)}),d("button",{class:`pp-toggle pp-${T}`,onClick:()=>t.toggleOpen(),"aria-label":n?"Close chat":"Open chat",children:[n?d(je,{}):d(wt,{}),!n&&f&&d("span",{class:"pp-online-dot"})]}),n&&d("div",{class:`pp-window pp-${T} pp-theme-${H}`,children:[d("div",{class:"pp-header",children:[d("div",{class:"pp-header-info",children:[e.operatorAvatar&&d("img",{src:e.operatorAvatar,alt:"",class:"pp-avatar"}),d("div",{children:[d("div",{class:"pp-header-title",children:e.operatorName??"Support"}),d("div",{class:"pp-header-status",children:f?d(E,{children:[d("span",{class:"pp-status-dot pp-online"})," Online"]}):d(E,{children:[d("span",{class:"pp-status-dot"})," Away"]})})]})]}),d("button",{class:"pp-close-btn",onClick:()=>t.setOpen(!1),"aria-label":"Close chat",children:d(je,{})})]}),d("div",{class:"pp-messages",children:[e.welcomeMessage&&o.length===0&&d("div",{class:"pp-welcome",children:e.welcomeMessage}),o.map(m=>d("div",{class:`pp-message pp-message-${m.sender}`,children:[d("div",{class:"pp-message-content",children:m.content}),d("div",{class:"pp-message-time",children:[kt(m.timestamp),m.sender==="ai"&&d("span",{class:"pp-ai-badge",children:"AI"}),m.sender==="visitor"&&d("span",{class:`pp-status pp-status-${m.status??"sent"}`,children:d(St,{status:m.status})})]})]},m.id)),p&&d("div",{class:"pp-message pp-message-operator pp-typing",children:[d("span",{}),d("span",{}),d("span",{})]}),d("div",{ref:x})]}),d("form",{class:"pp-input-form",onSubmit:h,children:[d("input",{ref:S,type:"text",class:"pp-input",placeholder:e.placeholder??"Type a message...",value:a,onInput:M,disabled:!u}),d("button",{type:"submit",class:"pp-send-btn",disabled:!a.trim()||!u,"aria-label":"Send message",children:d(Pt,{})})]}),d("div",{class:"pp-footer",children:["Powered by ",d("a",{href:"https://pocketping.io",target:"_blank",rel:"noopener",children:"PocketPing"})]})]})]})}function bt(t){let e=window.location.pathname;return t.hideOnPages?.some(n=>new RegExp(n).test(e))?!1:t.showOnPages?.length?t.showOnPages.some(n=>new RegExp(n).test(e)):!0}function xt(t){return t==="auto"?window.matchMedia("(prefers-color-scheme: dark)").matches?"dark":"light":t}function kt(t){return new Date(t).toLocaleTimeString([],{hour:"2-digit",minute:"2-digit"})}function wt(){return d("svg",{viewBox:"0 0 24 24",fill:"none",stroke:"currentColor","stroke-width":"2",children:d("path",{d:"M21 15a2 2 0 0 1-2 2H7l-4 4V5a2 2 0 0 1 2-2h14a2 2 0 0 1 2 2z"})})}function je(){return d("svg",{viewBox:"0 0 24 24",fill:"none",stroke:"currentColor","stroke-width":"2",children:[d("line",{x1:"18",y1:"6",x2:"6",y2:"18"}),d("line",{x1:"6",y1:"6",x2:"18",y2:"18"})]})}function Pt(){return d("svg",{viewBox:"0 0 24 24",fill:"none",stroke:"currentColor","stroke-width":"2",children:[d("line",{x1:"22",y1:"2",x2:"11",y2:"13"}),d("polygon",{points:"22 2 15 22 11 13 2 9 22 2"})]})}function St({status:t}){return!t||t==="sending"||t==="sent"?d("svg",{viewBox:"0 0 16 16",fill:"none",stroke:"currentColor","stroke-width":"2",class:"pp-check",children:d("polyline",{points:"3 8 7 12 13 4"})}):t==="delivered"?d("svg",{viewBox:"0 0 20 16",fill:"none",stroke:"currentColor","stroke-width":"2",class:"pp-check-double",children:[d("polyline",{points:"1 8 5 12 11 4"}),d("polyline",{points:"7 8 11 12 17 4"})]}):t==="read"?d("svg",{viewBox:"0 0 20 16",fill:"none",stroke:"currentColor","stroke-width":"2",class:"pp-check-double pp-check-read",children:[d("polyline",{points:"1 8 5 12 11 4"}),d("polyline",{points:"7 8 11 12 17 4"})]}):null}var K="0.3.3";var Q=class{constructor(e){this.session=null;this.ws=null;this.isOpen=!1;this.listeners=new Map;this.customEventHandlers=new Map;this.reconnectAttempts=0;this.maxReconnectAttempts=5;this.reconnectTimeout=null;this.config=e}async connect(){let e=this.getOrCreateVisitorId(),n=this.getStoredSessionId(),s=this.getStoredIdentity(),o=await this.fetch("/connect",{method:"POST",body:JSON.stringify({visitorId:e,sessionId:n,metadata:{url:window.location.href,referrer:document.referrer||void 0,pageTitle:document.title||void 0,userAgent:navigator.userAgent,timezone:Intl.DateTimeFormat().resolvedOptions().timeZone,language:navigator.language,screenResolution:`${window.screen.width}x${window.screen.height}`},identity:s||void 0})});return this.session={sessionId:o.sessionId,visitorId:o.visitorId,operatorOnline:o.operatorOnline??!1,messages:o.messages??[],identity:o.identity||s||void 0},this.storeSessionId(o.sessionId),this.connectWebSocket(),this.emit("connect",this.session),this.config.onConnect?.(o.sessionId),this.session}disconnect(){this.ws?.close(),this.ws=null,this.session=null,this.reconnectTimeout&&clearTimeout(this.reconnectTimeout)}async sendMessage(e){if(!this.session)throw new Error("Not connected");let n=`temp-${this.generateId()}`,s={id:n,sessionId:this.session.sessionId,content:e,sender:"visitor",timestamp:new Date().toISOString(),status:"sending"};this.session.messages.push(s),this.emit("message",s);try{let o=await this.fetch("/message",{method:"POST",body:JSON.stringify({sessionId:this.session.sessionId,content:e,sender:"visitor"})}),i=this.session.messages.findIndex(c=>c.id===n);i>=0&&(this.session.messages[i].id=o.messageId,this.session.messages[i].timestamp=o.timestamp,this.session.messages[i].status="sent",this.emit("message",this.session.messages[i]));let a=this.session.messages[i]||{id:o.messageId,sessionId:this.session.sessionId,content:e,sender:"visitor",timestamp:o.timestamp,status:"sent"};return this.config.onMessage?.(a),a}catch(o){let i=this.session.messages.findIndex(a=>a.id===n);throw i>=0&&(this.session.messages.splice(i,1),this.emit("message",s)),o}}async fetchMessages(e){if(!this.session)throw new Error("Not connected");let n=new URLSearchParams({sessionId:this.session.sessionId});return e&&n.set("after",e),(await this.fetch(`/messages?${n}`,{method:"GET"})).messages}async sendTyping(e=!0){this.session&&await this.fetch("/typing",{method:"POST",body:JSON.stringify({sessionId:this.session.sessionId,sender:"visitor",isTyping:e})})}async sendReadStatus(e,n){if(!(!this.session||e.length===0))try{await this.fetch("/read",{method:"POST",body:JSON.stringify({sessionId:this.session.sessionId,messageIds:e,status:n})});for(let s of this.session.messages)e.includes(s.id)&&(s.status=n,n==="delivered"?s.deliveredAt=new Date().toISOString():n==="read"&&(s.readAt=new Date().toISOString()));this.emit("readStatusSent",{messageIds:e,status:n})}catch(s){console.error("[PocketPing] Failed to send read status:",s)}}async getPresence(){return this.fetch("/presence",{method:"GET"})}async identify(e){if(!e?.id)throw new Error("[PocketPing] identity.id is required");if(this.storeIdentity(e),this.session)try{await this.fetch("/identify",{method:"POST",body:JSON.stringify({sessionId:this.session.sessionId,identity:e})}),this.session.identity=e,this.emit("identify",e)}catch(n){throw console.error("[PocketPing] Failed to identify:",n),n}}async reset(e){this.clearIdentity(),this.session&&(this.session.identity=void 0),e?.newSession&&(localStorage.removeItem("pocketping_session_id"),localStorage.removeItem("pocketping_visitor_id"),this.disconnect(),await this.connect()),this.emit("reset",null)}getIdentity(){return this.session?.identity||this.getStoredIdentity()}getSession(){return this.session}getMessages(){return this.session?.messages??[]}isConnected(){return this.session!==null}isWidgetOpen(){return this.isOpen}setOpen(e){this.isOpen=e,this.emit("openChange",e),e?this.config.onOpen?.():this.config.onClose?.()}toggleOpen(){this.setOpen(!this.isOpen)}on(e,n){return this.listeners.has(e)||this.listeners.set(e,new Set),this.listeners.get(e).add(n),()=>{this.listeners.get(e)?.delete(n)}}emit(e,n){this.listeners.get(e)?.forEach(s=>s(n))}trigger(e,n){if(!this.ws||this.ws.readyState!==WebSocket.OPEN){console.warn("[PocketPing] Cannot trigger event: WebSocket not connected");return}let s={name:e,data:n,timestamp:new Date().toISOString()};this.ws.send(JSON.stringify({type:"event",data:s})),this.emit(`event:${e}`,s)}onEvent(e,n){return this.customEventHandlers.has(e)||this.customEventHandlers.set(e,new Set),this.customEventHandlers.get(e).add(n),()=>{this.customEventHandlers.get(e)?.delete(n)}}offEvent(e,n){this.customEventHandlers.get(e)?.delete(n)}emitCustomEvent(e){let n=this.customEventHandlers.get(e.name);n&&n.forEach(s=>s(e.data,e)),this.emit("event",e),this.emit(`event:${e.name}`,e)}connectWebSocket(){if(!this.session)return;let e=this.config.endpoint.replace(/^http/,"ws").replace(/\/$/,"")+`/stream?sessionId=${this.session.sessionId}`;try{this.ws=new WebSocket(e),this.ws.onopen=()=>{this.reconnectAttempts=0,this.emit("wsConnected",null)},this.ws.onmessage=n=>{try{let s=JSON.parse(n.data);this.handleWebSocketEvent(s)}catch(s){console.error("[PocketPing] Failed to parse WS message:",s)}},this.ws.onclose=()=>{this.emit("wsDisconnected",null),this.scheduleReconnect()},this.ws.onerror=n=>{console.error("[PocketPing] WebSocket error:",n)}}catch{console.warn("[PocketPing] WebSocket unavailable, using polling"),this.startPolling()}}handleWebSocketEvent(e){switch(e.type){case"message":let n=e.data;if(this.session){let c=this.session.messages.findIndex(p=>p.id===n.id);if(c<0&&n.sender==="visitor"&&(c=this.session.messages.findIndex(p=>p.id.startsWith("temp-")&&p.content===n.content&&p.sender==="visitor"),c>=0&&(this.session.messages[c].id=n.id)),c<0&&n.sender!=="visitor"){let p=new Date(n.timestamp).getTime();c=this.session.messages.findIndex(l=>l.sender===n.sender&&l.content===n.content&&Math.abs(new Date(l.timestamp).getTime()-p)<2e3)}if(c>=0){let p=this.session.messages[c];n.status&&n.status!==p.status&&(p.status=n.status,n.deliveredAt&&(p.deliveredAt=n.deliveredAt),n.readAt&&(p.readAt=n.readAt),this.emit("read",{messageIds:[n.id],status:n.status}))}else this.session.messages.push(n),this.emit("message",n),this.config.onMessage?.(n)}n.sender!=="visitor"&&this.emit("typing",{isTyping:!1});break;case"typing":let s=e.data;s.sender!=="visitor"&&this.emit("typing",{isTyping:s.isTyping});break;case"presence":this.session&&(this.session.operatorOnline=e.data.online),this.emit("presence",e.data);break;case"ai_takeover":this.emit("aiTakeover",e.data);break;case"read":let o=e.data;if(this.session)for(let c of this.session.messages)o.messageIds.includes(c.id)&&(c.status=o.status,o.deliveredAt&&(c.deliveredAt=o.deliveredAt),o.readAt&&(c.readAt=o.readAt));this.emit("read",o);break;case"event":let i=e.data;this.emitCustomEvent(i);break;case"version_warning":let a=e.data;this.handleVersionWarning(a);break}}handleVersionWarning(e){let n="[PocketPing]",s=e.upgradeUrl?` Upgrade: ${e.upgradeUrl}`:" Update your widget to the latest version.";switch(e.severity){case"error":console.error(`${n} \u{1F6A8} VERSION ERROR: ${e.message}${s}`),console.error(`${n} Current: ${e.currentVersion}, Required: ${e.minVersion||"unknown"}`);break;case"warning":console.warn(`${n} \u26A0\uFE0F VERSION WARNING: ${e.message}${s}`),console.warn(`${n} Current: ${e.currentVersion}, Latest: ${e.latestVersion||"unknown"}`);break;case"info":console.info(`${n} \u2139\uFE0F ${e.message}`);break}this.emit("versionWarning",e),this.config.onVersionWarning?.(e),e.canContinue||(console.error(`${n} Widget is incompatible with backend. Please update immediately.`),this.disconnect())}scheduleReconnect(){if(this.reconnectAttempts>=this.maxReconnectAttempts){console.warn("[PocketPing] Max reconnect attempts reached, switching to polling"),this.startPolling();return}let e=Math.min(1e3*Math.pow(2,this.reconnectAttempts),3e4);this.reconnectAttempts++,this.reconnectTimeout=setTimeout(()=>{this.connectWebSocket()},e)}startPolling(){let e=async()=>{if(this.session){try{let n=this.session.messages[this.session.messages.length-1]?.id,s=await this.fetchMessages(n);for(let o of s)this.session.messages.find(i=>i.id===o.id)||(this.session.messages.push(o),this.emit("message",o),this.config.onMessage?.(o))}catch(n){console.error("[PocketPing] Polling error:",n)}this.session&&setTimeout(e,3e3)}};e()}async fetch(e,n){let s=this.config.endpoint.replace(/\/$/,"")+e,o=await fetch(s,{...n,headers:{"Content-Type":"application/json","X-PocketPing-Version":K,...n.headers}});if(this.checkVersionHeaders(o),!o.ok){let i=await o.text();throw new Error(`PocketPing API error: ${o.status} ${i}`)}return o.json()}checkVersionHeaders(e){let n=e.headers.get("X-PocketPing-Version-Status"),s=e.headers.get("X-PocketPing-Min-Version"),o=e.headers.get("X-PocketPing-Latest-Version"),i=e.headers.get("X-PocketPing-Version-Message");if(!n||n==="ok")return;let a="info",c=!0;n==="deprecated"?a="warning":n==="unsupported"?(a="error",c=!1):n==="outdated"&&(a="info");let p={severity:a,message:i||`Widget version ${K} is ${n}`,currentVersion:K,minVersion:s||void 0,latestVersion:o||void 0,canContinue:c,upgradeUrl:"https://docs.pocketping.io/widget/installation"};this.handleVersionWarning(p)}getOrCreateVisitorId(){let e="pocketping_visitor_id",n=localStorage.getItem(e);return n||(n=this.generateId(),localStorage.setItem(e,n)),n}getStoredSessionId(){return localStorage.getItem("pocketping_session_id")}storeSessionId(e){localStorage.setItem("pocketping_session_id",e)}getStoredIdentity(){try{let e=localStorage.getItem("pocketping_user_identity");return e?JSON.parse(e):null}catch{return null}}storeIdentity(e){localStorage.setItem("pocketping_user_identity",JSON.stringify(e))}clearIdentity(){localStorage.removeItem("pocketping_user_identity")}generateId(){return`${Date.now().toString(36)}-${Math.random().toString(36).slice(2,11)}`}};var y=null,A=null,It="https://app.pocketping.io/api/widget";function ue(t){if(y)return console.warn("[PocketPing] Already initialized"),y;let e=t.endpoint;if(!e&&t.projectId&&(e=`${It}/${t.projectId}`),!e)throw new Error("[PocketPing] endpoint or projectId is required");let n={...t,endpoint:e};return y=new Q(n),A=document.createElement("div"),A.id="pocketping-container",document.body.appendChild(A),ce(ie(ze,{client:y,config:t}),A),y.connect().catch(s=>{console.error("[PocketPing] Failed to connect:",s)}),y}function Be(){A&&(ce(null,A),A.remove(),A=null),y&&(y.disconnect(),y=null)}function qe(){y?.setOpen(!0)}function Je(){y?.setOpen(!1)}function Xe(){y?.toggleOpen()}function Ge(t){if(!y)throw new Error("[PocketPing] Not initialized");return y.sendMessage(t)}function Ze(t,e){if(!y){console.warn("[PocketPing] Not initialized, cannot trigger event");return}y.trigger(t,e)}function Ke(t,e){return y?y.onEvent(t,e):(console.warn("[PocketPing] Not initialized, cannot subscribe to event"),()=>{})}function Qe(t,e){y?.offEvent(t,e)}async function Ye(t){if(!y)throw new Error("[PocketPing] Not initialized");return y.identify(t)}async function et(t){if(!y){console.warn("[PocketPing] Not initialized");return}return y.reset(t)}function tt(){return y?.getIdentity()||null}function nt(t,e){return y?y.on(t,e):(console.warn("[PocketPing] Not initialized, cannot subscribe to event"),()=>{})}if(typeof document<"u"){let t=document.currentScript;if(t){let e=t.dataset.projectId,n=t.dataset.endpoint;(e||n)&&ue({projectId:e,endpoint:n,theme:t.dataset.theme||"auto",position:t.dataset.position||"bottom-right"})}}var Ct={init:ue,destroy:Be,open:qe,close:Je,toggle:Xe,sendMessage:Ge,trigger:Ze,onEvent:Ke,offEvent:Qe,on:nt,identify:Ye,reset:et,getIdentity:tt};return ct(Et);})();
329
+ `}var kt=0;function u(t,e,n,s,i,o){e||(e={});var l,c,p=e;if("ref"in p)for(c in p={},e)c=="ref"?l=e[c]:p[c]=e[c];var a={type:t,props:p,key:n,ref:l,__k:null,__:null,__b:0,__e:null,__c:null,constructor:void 0,__v:--kt,__i:-1,__u:0,__source:i,__self:o};if(typeof t=="function"&&(l=t.defaultProps))for(c in l)p[c]===void 0&&(p[c]=l[c]);return f.vnode&&f.vnode(a),a}function je({client:t,config:e}){let[n,s]=W(!1),[i,o]=W([]),[l,c]=W(""),[p,a]=W(!1),[_,r]=W(!1),[d,g]=W(!1),k=ue(null),P=ue(null);N(()=>{let v=t.on("openChange",s),E=t.on("message",()=>{o([...t.getMessages()])}),I=t.on("typing",$=>{a($.isTyping)}),F=t.on("presence",$=>{r($.online)}),S=t.on("connect",()=>{g(!0),o(t.getMessages()),r(t.getSession()?.operatorOnline??!1)});return t.isConnected()&&(g(!0),o(t.getMessages()),r(t.getSession()?.operatorOnline??!1)),()=>{v(),E(),I(),F(),S()}},[t]),N(()=>{k.current?.scrollIntoView({behavior:"smooth"})},[i]),N(()=>{n&&P.current?.focus()},[n]);let y=Ve(()=>{if(!n||!d)return;let v=i.filter(E=>E.sender!=="visitor"&&E.status!=="read");if(v.length>0){let E=v.map(I=>I.id);t.sendReadStatus(E,"read")}},[n,d,i,t]);if(N(()=>{if(!n||!d)return;let v=setTimeout(()=>{y()},1e3);return()=>clearTimeout(v)},[n,d,i,y]),N(()=>{let v=()=>{document.visibilityState==="visible"&&n&&y()};return document.addEventListener("visibilitychange",v),()=>document.removeEventListener("visibilitychange",v)},[n,y]),N(()=>{let v=t.on("read",()=>{o([...t.getMessages()])});return()=>v()},[t]),!xt(e))return null;let m=async v=>{if(v.preventDefault(),!l.trim())return;let E=l;c("");try{await t.sendMessage(E)}catch(I){console.error("[PocketPing] Failed to send message:",I)}},T=v=>{let E=v.target;c(E.value),t.sendTyping(!0)},M=e.position??"bottom-right",H=wt(e.theme??"auto"),R=e.primaryColor??"#6366f1";return u(C,{children:[u("style",{children:De(R,H)}),u("button",{class:`pp-toggle pp-${M}`,onClick:()=>t.toggleOpen(),"aria-label":n?"Close chat":"Open chat",children:[n?u(ze,{}):u(Et,{}),!n&&_&&u("span",{class:"pp-online-dot"})]}),n&&u("div",{class:`pp-window pp-${M} pp-theme-${H}`,children:[u("div",{class:"pp-header",children:[u("div",{class:"pp-header-info",children:[e.operatorAvatar&&u("img",{src:e.operatorAvatar,alt:"",class:"pp-avatar"}),u("div",{children:[u("div",{class:"pp-header-title",children:e.operatorName??"Support"}),u("div",{class:"pp-header-status",children:_?u(C,{children:[u("span",{class:"pp-status-dot pp-online"})," Online"]}):u(C,{children:[u("span",{class:"pp-status-dot"})," Away"]})})]})]}),u("button",{class:"pp-close-btn",onClick:()=>t.setOpen(!1),"aria-label":"Close chat",children:u(ze,{})})]}),u("div",{class:"pp-messages",children:[e.welcomeMessage&&i.length===0&&u("div",{class:"pp-welcome",children:e.welcomeMessage}),i.map(v=>u("div",{class:`pp-message pp-message-${v.sender}`,children:[u("div",{class:"pp-message-content",children:v.content}),u("div",{class:"pp-message-time",children:[Pt(v.timestamp),v.sender==="ai"&&u("span",{class:"pp-ai-badge",children:"AI"}),v.sender==="visitor"&&u("span",{class:`pp-status pp-status-${v.status??"sent"}`,children:u(It,{status:v.status})})]})]},v.id)),p&&u("div",{class:"pp-message pp-message-operator pp-typing",children:[u("span",{}),u("span",{}),u("span",{})]}),u("div",{ref:k})]}),u("form",{class:"pp-input-form",onSubmit:m,children:[u("input",{ref:P,type:"text",class:"pp-input",placeholder:e.placeholder??"Type a message...",value:l,onInput:T,disabled:!d}),u("button",{type:"submit",class:"pp-send-btn",disabled:!l.trim()||!d,"aria-label":"Send message",children:u(St,{})})]}),u("div",{class:"pp-footer",children:["Powered by ",u("a",{href:"https://pocketping.io",target:"_blank",rel:"noopener",children:"PocketPing"})]})]})]})}function xt(t){let e=window.location.pathname;return t.hideOnPages?.some(n=>new RegExp(n).test(e))?!1:t.showOnPages?.length?t.showOnPages.some(n=>new RegExp(n).test(e)):!0}function wt(t){return t==="auto"?window.matchMedia("(prefers-color-scheme: dark)").matches?"dark":"light":t}function Pt(t){return new Date(t).toLocaleTimeString([],{hour:"2-digit",minute:"2-digit"})}function Et(){return u("svg",{viewBox:"0 0 24 24",fill:"none",stroke:"currentColor","stroke-width":"2",children:u("path",{d:"M21 15a2 2 0 0 1-2 2H7l-4 4V5a2 2 0 0 1 2-2h14a2 2 0 0 1 2 2z"})})}function ze(){return u("svg",{viewBox:"0 0 24 24",fill:"none",stroke:"currentColor","stroke-width":"2",children:[u("line",{x1:"18",y1:"6",x2:"6",y2:"18"}),u("line",{x1:"6",y1:"6",x2:"18",y2:"18"})]})}function St(){return u("svg",{viewBox:"0 0 24 24",fill:"none",stroke:"currentColor","stroke-width":"2",children:[u("line",{x1:"22",y1:"2",x2:"11",y2:"13"}),u("polygon",{points:"22 2 15 22 11 13 2 9 22 2"})]})}function It({status:t}){return!t||t==="sending"||t==="sent"?u("svg",{viewBox:"0 0 16 16",fill:"none",stroke:"currentColor","stroke-width":"2",class:"pp-check",children:u("polyline",{points:"3 8 7 12 13 4"})}):t==="delivered"?u("svg",{viewBox:"0 0 20 16",fill:"none",stroke:"currentColor","stroke-width":"2",class:"pp-check-double",children:[u("polyline",{points:"1 8 5 12 11 4"}),u("polyline",{points:"7 8 11 12 17 4"})]}):t==="read"?u("svg",{viewBox:"0 0 20 16",fill:"none",stroke:"currentColor","stroke-width":"2",class:"pp-check-double pp-check-read",children:[u("polyline",{points:"1 8 5 12 11 4"}),u("polyline",{points:"7 8 11 12 17 4"})]}):null}var Z="0.3.5";var K=class{constructor(e){this.session=null;this.ws=null;this.isOpen=!1;this.listeners=new Map;this.customEventHandlers=new Map;this.reconnectAttempts=0;this.maxReconnectAttempts=5;this.reconnectTimeout=null;this.pollingTimeout=null;this.pollingFailures=0;this.maxPollingFailures=10;this.trackedElementCleanups=[];this.currentTrackedElements=[];this.inspectorMode=!1;this.inspectorCleanup=null;this.config=e}async connect(){let e=this.getOrCreateVisitorId(),n=this.getStoredSessionId(),s=this.getStoredIdentity(),o=new URLSearchParams(window.location.search).get("pp_inspector"),l=await this.fetch("/connect",{method:"POST",body:JSON.stringify({visitorId:e,sessionId:n,inspectorToken:o||void 0,metadata:{url:window.location.href,referrer:document.referrer||void 0,pageTitle:document.title||void 0,userAgent:navigator.userAgent,timezone:Intl.DateTimeFormat().resolvedOptions().timeZone,language:navigator.language,screenResolution:`${window.screen.width}x${window.screen.height}`},identity:s||void 0})});return this.session={sessionId:l.sessionId,visitorId:l.visitorId,operatorOnline:l.operatorOnline??!1,messages:l.messages??[],identity:l.identity||s||void 0},this.storeSessionId(l.sessionId),this.connectWebSocket(),l.inspectorMode?this.enableInspectorMode():l.trackedElements?.length&&this.setupTrackedElements(l.trackedElements),this.emit("connect",this.session),this.config.onConnect?.(l.sessionId),this.session}disconnect(){this.ws?.close(),this.ws=null,this.session=null,this.reconnectTimeout&&clearTimeout(this.reconnectTimeout),this.stopPolling(),this.cleanupTrackedElements(),this.disableInspectorMode()}async sendMessage(e){if(!this.session)throw new Error("Not connected");let n=`temp-${this.generateId()}`,s={id:n,sessionId:this.session.sessionId,content:e,sender:"visitor",timestamp:new Date().toISOString(),status:"sending"};this.session.messages.push(s),this.emit("message",s);try{let i=await this.fetch("/message",{method:"POST",body:JSON.stringify({sessionId:this.session.sessionId,content:e,sender:"visitor"})}),o=this.session.messages.findIndex(c=>c.id===n);o>=0&&(this.session.messages[o].id=i.messageId,this.session.messages[o].timestamp=i.timestamp,this.session.messages[o].status="sent",this.emit("message",this.session.messages[o]));let l=this.session.messages[o]||{id:i.messageId,sessionId:this.session.sessionId,content:e,sender:"visitor",timestamp:i.timestamp,status:"sent"};return this.config.onMessage?.(l),l}catch(i){let o=this.session.messages.findIndex(l=>l.id===n);throw o>=0&&(this.session.messages.splice(o,1),this.emit("message",s)),i}}async fetchMessages(e){if(!this.session)throw new Error("Not connected");let n=new URLSearchParams({sessionId:this.session.sessionId});return e&&n.set("after",e),(await this.fetch(`/messages?${n}`,{method:"GET"})).messages}async sendTyping(e=!0){this.session&&await this.fetch("/typing",{method:"POST",body:JSON.stringify({sessionId:this.session.sessionId,sender:"visitor",isTyping:e})})}async sendReadStatus(e,n){if(!(!this.session||e.length===0))try{await this.fetch("/read",{method:"POST",body:JSON.stringify({sessionId:this.session.sessionId,messageIds:e,status:n})});for(let s of this.session.messages)e.includes(s.id)&&(s.status=n,n==="delivered"?s.deliveredAt=new Date().toISOString():n==="read"&&(s.readAt=new Date().toISOString()));this.emit("readStatusSent",{messageIds:e,status:n})}catch(s){console.error("[PocketPing] Failed to send read status:",s)}}async getPresence(){return this.fetch("/presence",{method:"GET"})}async identify(e){if(!e?.id)throw new Error("[PocketPing] identity.id is required");if(this.storeIdentity(e),this.session)try{await this.fetch("/identify",{method:"POST",body:JSON.stringify({sessionId:this.session.sessionId,identity:e})}),this.session.identity=e,this.emit("identify",e)}catch(n){throw console.error("[PocketPing] Failed to identify:",n),n}}async reset(e){this.clearIdentity(),this.session&&(this.session.identity=void 0),e?.newSession&&(localStorage.removeItem("pocketping_session_id"),localStorage.removeItem("pocketping_visitor_id"),this.disconnect(),await this.connect()),this.emit("reset",null)}getIdentity(){return this.session?.identity||this.getStoredIdentity()}getSession(){return this.session}getMessages(){return this.session?.messages??[]}isConnected(){return this.session!==null}isWidgetOpen(){return this.isOpen}setOpen(e){this.isOpen=e,this.emit("openChange",e),e?this.config.onOpen?.():this.config.onClose?.()}toggleOpen(){this.setOpen(!this.isOpen)}on(e,n){return this.listeners.has(e)||this.listeners.set(e,new Set),this.listeners.get(e).add(n),()=>{this.listeners.get(e)?.delete(n)}}emit(e,n){this.listeners.get(e)?.forEach(s=>s(n))}trigger(e,n,s){if(!this.ws||this.ws.readyState!==WebSocket.OPEN){console.warn("[PocketPing] Cannot trigger event: WebSocket not connected");return}let i={name:e,data:n,timestamp:new Date().toISOString()};this.ws.send(JSON.stringify({type:"event",data:i})),this.emit(`event:${e}`,i),s?.widgetMessage&&(this.setOpen(!0),this.emit("triggerMessage",{message:s.widgetMessage,eventName:e}))}onEvent(e,n){return this.customEventHandlers.has(e)||this.customEventHandlers.set(e,new Set),this.customEventHandlers.get(e).add(n),()=>{this.customEventHandlers.get(e)?.delete(n)}}offEvent(e,n){this.customEventHandlers.get(e)?.delete(n)}emitCustomEvent(e){let n=this.customEventHandlers.get(e.name);n&&n.forEach(s=>s(e.data,e)),this.emit("event",e),this.emit(`event:${e.name}`,e)}setupTrackedElements(e){this.cleanupTrackedElements(),this.currentTrackedElements=e;for(let n of e){let s=n.event||"click",i=l=>{let c={...n.data,selector:n.selector,elementText:l.target?.textContent?.trim().slice(0,100),url:window.location.href};this.trigger(n.name,c,{widgetMessage:n.widgetMessage})},o=l=>{l.target?.closest(n.selector)&&i(l)};document.addEventListener(s,o,!0),this.trackedElementCleanups.push(()=>{document.removeEventListener(s,o,!0)})}e.length>0&&console.info(`[PocketPing] Tracking ${e.length} element(s)`)}cleanupTrackedElements(){for(let e of this.trackedElementCleanups)e();this.trackedElementCleanups=[],this.currentTrackedElements=[]}getTrackedElements(){return[...this.currentTrackedElements]}enableInspectorMode(){if(this.inspectorMode)return;this.inspectorMode=!0,console.info("[PocketPing] \u{1F50D} Inspector mode active - click on any element to select it");let e=document.createElement("div");e.id="pp-inspector-overlay",e.innerHTML=`
330
+ <style>
331
+ #pp-inspector-overlay {
332
+ position: fixed;
333
+ top: 0;
334
+ left: 0;
335
+ right: 0;
336
+ bottom: 0;
337
+ z-index: 999999;
338
+ pointer-events: none;
339
+ }
340
+ #pp-inspector-overlay * {
341
+ pointer-events: auto;
342
+ }
343
+ #pp-inspector-banner {
344
+ position: fixed;
345
+ top: 16px;
346
+ left: 50%;
347
+ transform: translateX(-50%);
348
+ background: linear-gradient(135deg, #6366f1, #8b5cf6);
349
+ color: white;
350
+ padding: 12px 24px;
351
+ border-radius: 12px;
352
+ font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
353
+ font-size: 14px;
354
+ font-weight: 500;
355
+ box-shadow: 0 4px 20px rgba(99, 102, 241, 0.4);
356
+ display: flex;
357
+ align-items: center;
358
+ gap: 12px;
359
+ z-index: 1000000;
360
+ }
361
+ #pp-inspector-banner svg {
362
+ animation: pp-pulse 1.5s ease-in-out infinite;
363
+ }
364
+ @keyframes pp-pulse {
365
+ 0%, 100% { opacity: 1; }
366
+ 50% { opacity: 0.5; }
367
+ }
368
+ #pp-inspector-exit {
369
+ background: rgba(255,255,255,0.2);
370
+ border: none;
371
+ color: white;
372
+ padding: 6px 12px;
373
+ border-radius: 6px;
374
+ cursor: pointer;
375
+ font-size: 12px;
376
+ margin-left: 8px;
377
+ }
378
+ #pp-inspector-exit:hover {
379
+ background: rgba(255,255,255,0.3);
380
+ }
381
+ .pp-inspector-highlight {
382
+ outline: 3px dashed #6366f1 !important;
383
+ outline-offset: 2px !important;
384
+ background: rgba(99, 102, 241, 0.1) !important;
385
+ }
386
+ #pp-inspector-tooltip {
387
+ position: fixed;
388
+ background: #1f2937;
389
+ color: white;
390
+ padding: 8px 12px;
391
+ border-radius: 8px;
392
+ font-family: ui-monospace, SFMono-Regular, monospace;
393
+ font-size: 12px;
394
+ pointer-events: none;
395
+ z-index: 1000001;
396
+ max-width: 400px;
397
+ word-break: break-all;
398
+ display: none;
399
+ }
400
+ </style>
401
+ <div id="pp-inspector-banner">
402
+ <svg width="20" height="20" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2">
403
+ <circle cx="12" cy="12" r="10"/>
404
+ <line x1="22" y1="22" x2="16.65" y2="16.65"/>
405
+ <line x1="12" y1="8" x2="12" y2="12"/>
406
+ <line x1="12" y1="16" x2="12" y2="16"/>
407
+ </svg>
408
+ <span>Inspector Mode - Click an element to capture its selector</span>
409
+ <button id="pp-inspector-exit">Exit</button>
410
+ </div>
411
+ <div id="pp-inspector-tooltip"></div>
412
+ `,document.body.appendChild(e);let n=document.getElementById("pp-inspector-tooltip"),s=null,i=p=>{if(p.id&&!p.id.startsWith("pp-"))return`#${CSS.escape(p.id)}`;let a=Array.from(p.classList).filter(d=>!d.startsWith("pp-"));if(a.length>0){let d="."+a.map(g=>CSS.escape(g)).join(".");if(document.querySelectorAll(d).length===1)return d}for(let d of Array.from(p.attributes))if(d.name.startsWith("data-")&&d.value){let g=`[${d.name}="${CSS.escape(d.value)}"]`;if(document.querySelectorAll(g).length===1)return g}let _=[],r=p;for(;r&&r!==document.body;){let d=r.tagName.toLowerCase();if(r.id&&!r.id.startsWith("pp-")){d=`#${CSS.escape(r.id)}`,_.unshift(d);break}let g=r.parentElement;if(g){let k=r.tagName,P=Array.from(g.children).filter(y=>y.tagName===k);if(P.length>1){let y=P.indexOf(r)+1;d+=`:nth-of-type(${y})`}}_.unshift(d),r=g}return _.join(" > ")},o=p=>{let a=p.target;if(a.closest("#pp-inspector-overlay")||a.closest("#pocketping-widget"))return;s&&s.classList.remove("pp-inspector-highlight"),a.classList.add("pp-inspector-highlight"),s=a;let _=i(a);n.textContent=_,n.style.display="block",n.style.left=`${p.clientX+15}px`,n.style.top=`${p.clientY+15}px`;let r=n.getBoundingClientRect();r.right>window.innerWidth&&(n.style.left=`${p.clientX-r.width-15}px`),r.bottom>window.innerHeight&&(n.style.top=`${p.clientY-r.height-15}px`)},l=p=>{let a=p.target;a.closest("#pp-inspector-overlay")||(a.classList.remove("pp-inspector-highlight"),n.style.display="none")},c=p=>{let a=p.target;if(a.id==="pp-inspector-exit"){this.disableInspectorMode();return}if(a.closest("#pp-inspector-overlay")||a.closest("#pocketping-widget"))return;p.preventDefault(),p.stopPropagation();let _=i(a);this.ws&&this.ws.readyState===WebSocket.OPEN&&this.ws.send(JSON.stringify({type:"inspector_select",data:{selector:_,tagName:a.tagName.toLowerCase(),text:a.textContent?.trim().slice(0,50)||"",url:window.location.href}})),this.emit("inspectorSelect",{selector:_,element:a}),a.classList.remove("pp-inspector-highlight"),a.classList.add("pp-inspector-highlight"),setTimeout(()=>{a.classList.remove("pp-inspector-highlight")},500);let r=document.getElementById("pp-inspector-banner");if(r){let d=r.innerHTML;r.innerHTML=`
413
+ <svg width="20" height="20" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2">
414
+ <polyline points="20 6 9 17 4 12"/>
415
+ </svg>
416
+ <span>Selector captured: <code style="background:rgba(255,255,255,0.2);padding:2px 6px;border-radius:4px;font-family:monospace;">${_}</code></span>
417
+ `,setTimeout(()=>{r&&this.inspectorMode&&(r.innerHTML=d,document.getElementById("pp-inspector-exit")?.addEventListener("click",()=>{this.disableInspectorMode()}))},2e3)}console.info(`[PocketPing] \u{1F4CC} Selector captured: ${_}`)};document.addEventListener("mouseover",o,!0),document.addEventListener("mouseout",l,!0),document.addEventListener("click",c,!0),this.inspectorCleanup=()=>{document.removeEventListener("mouseover",o,!0),document.removeEventListener("mouseout",l,!0),document.removeEventListener("click",c,!0),e.remove(),s&&s.classList.remove("pp-inspector-highlight")},document.getElementById("pp-inspector-exit")?.addEventListener("click",()=>{this.disableInspectorMode()})}disableInspectorMode(){this.inspectorMode&&(this.inspectorMode=!1,this.inspectorCleanup&&(this.inspectorCleanup(),this.inspectorCleanup=null),console.info("[PocketPing] Inspector mode disabled"),this.emit("inspectorDisabled",null))}isInspectorModeActive(){return this.inspectorMode}connectWebSocket(){if(!this.session)return;let e=this.config.endpoint.replace(/^http/,"ws").replace(/\/$/,"")+`/stream?sessionId=${this.session.sessionId}`;try{this.ws=new WebSocket(e),this.ws.onopen=()=>{this.reconnectAttempts=0,this.emit("wsConnected",null)},this.ws.onmessage=n=>{try{let s=JSON.parse(n.data);this.handleWebSocketEvent(s)}catch(s){console.error("[PocketPing] Failed to parse WS message:",s)}},this.ws.onclose=()=>{this.emit("wsDisconnected",null),this.scheduleReconnect()},this.ws.onerror=n=>{console.error("[PocketPing] WebSocket error:",n)}}catch{console.warn("[PocketPing] WebSocket unavailable, using polling"),this.startPolling()}}handleWebSocketEvent(e){switch(e.type){case"message":let n=e.data;if(this.session){let p=this.session.messages.findIndex(a=>a.id===n.id);if(p<0&&n.sender==="visitor"&&(p=this.session.messages.findIndex(a=>a.id.startsWith("temp-")&&a.content===n.content&&a.sender==="visitor"),p>=0&&(this.session.messages[p].id=n.id)),p<0&&n.sender!=="visitor"){let a=new Date(n.timestamp).getTime();p=this.session.messages.findIndex(_=>_.sender===n.sender&&_.content===n.content&&Math.abs(new Date(_.timestamp).getTime()-a)<2e3)}if(p>=0){let a=this.session.messages[p];n.status&&n.status!==a.status&&(a.status=n.status,n.deliveredAt&&(a.deliveredAt=n.deliveredAt),n.readAt&&(a.readAt=n.readAt),this.emit("read",{messageIds:[n.id],status:n.status}))}else this.session.messages.push(n),this.emit("message",n),this.config.onMessage?.(n)}n.sender!=="visitor"&&this.emit("typing",{isTyping:!1});break;case"typing":let s=e.data;s.sender!=="visitor"&&this.emit("typing",{isTyping:s.isTyping});break;case"presence":this.session&&(this.session.operatorOnline=e.data.online),this.emit("presence",e.data);break;case"ai_takeover":this.emit("aiTakeover",e.data);break;case"read":let i=e.data;if(this.session)for(let p of this.session.messages)i.messageIds.includes(p.id)&&(p.status=i.status,i.deliveredAt&&(p.deliveredAt=i.deliveredAt),i.readAt&&(p.readAt=i.readAt));this.emit("read",i);break;case"event":let o=e.data;this.emitCustomEvent(o);break;case"version_warning":let l=e.data;this.handleVersionWarning(l);break;case"config_update":let c=e.data;c.trackedElements&&(this.setupTrackedElements(c.trackedElements),this.emit("configUpdate",c));break}}handleVersionWarning(e){let n="[PocketPing]",s=e.upgradeUrl?` Upgrade: ${e.upgradeUrl}`:" Update your widget to the latest version.";switch(e.severity){case"error":console.error(`${n} \u{1F6A8} VERSION ERROR: ${e.message}${s}`),console.error(`${n} Current: ${e.currentVersion}, Required: ${e.minVersion||"unknown"}`);break;case"warning":console.warn(`${n} \u26A0\uFE0F VERSION WARNING: ${e.message}${s}`),console.warn(`${n} Current: ${e.currentVersion}, Latest: ${e.latestVersion||"unknown"}`);break;case"info":console.info(`${n} \u2139\uFE0F ${e.message}`);break}this.emit("versionWarning",e),this.config.onVersionWarning?.(e),e.canContinue||(console.error(`${n} Widget is incompatible with backend. Please update immediately.`),this.disconnect())}scheduleReconnect(){if(this.reconnectAttempts>=this.maxReconnectAttempts){console.warn("[PocketPing] Max reconnect attempts reached, switching to polling"),this.startPolling();return}let e=Math.min(1e3*Math.pow(2,this.reconnectAttempts),3e4);this.reconnectAttempts++,this.reconnectTimeout=setTimeout(()=>{this.connectWebSocket()},e)}startPolling(){let e=async()=>{if(this.session){try{let n=this.session.messages[this.session.messages.length-1]?.id,s=await this.fetchMessages(n);this.pollingFailures=0;for(let i of s)this.session.messages.find(o=>o.id===i.id)||(this.session.messages.push(i),this.emit("message",i),this.config.onMessage?.(i))}catch{if(this.pollingFailures++,(this.pollingFailures<=3||this.pollingFailures%3===0)&&console.warn(`[PocketPing] Polling failed (${this.pollingFailures}/${this.maxPollingFailures})`),this.pollingFailures>=this.maxPollingFailures){console.error("[PocketPing] Polling disabled after too many failures. Real-time updates unavailable."),this.emit("pollingDisabled",{failures:this.pollingFailures});return}}if(this.session){let n=this.pollingFailures>0?Math.min(3e3*Math.pow(2,this.pollingFailures-1),3e4):3e3;this.pollingTimeout=setTimeout(e,n)}}};e()}stopPolling(){this.pollingTimeout&&(clearTimeout(this.pollingTimeout),this.pollingTimeout=null),this.pollingFailures=0}async fetch(e,n){let s=this.config.endpoint.replace(/\/$/,"")+e,i=await fetch(s,{...n,headers:{"Content-Type":"application/json","X-PocketPing-Version":Z,...n.headers}});if(this.checkVersionHeaders(i),!i.ok){let o=await i.text();throw new Error(`PocketPing API error: ${i.status} ${o}`)}return i.json()}checkVersionHeaders(e){let n=e.headers.get("X-PocketPing-Version-Status"),s=e.headers.get("X-PocketPing-Min-Version"),i=e.headers.get("X-PocketPing-Latest-Version"),o=e.headers.get("X-PocketPing-Version-Message");if(!n||n==="ok")return;let l="info",c=!0;n==="deprecated"?l="warning":n==="unsupported"?(l="error",c=!1):n==="outdated"&&(l="info");let p={severity:l,message:o||`Widget version ${Z} is ${n}`,currentVersion:Z,minVersion:s||void 0,latestVersion:i||void 0,canContinue:c,upgradeUrl:"https://docs.pocketping.io/widget/installation"};this.handleVersionWarning(p)}getOrCreateVisitorId(){let e="pocketping_visitor_id",n=localStorage.getItem(e);return n||(n=this.generateId(),localStorage.setItem(e,n)),n}getStoredSessionId(){return localStorage.getItem("pocketping_session_id")}storeSessionId(e){localStorage.setItem("pocketping_session_id",e)}getStoredIdentity(){try{let e=localStorage.getItem("pocketping_user_identity");return e?JSON.parse(e):null}catch{return null}}storeIdentity(e){localStorage.setItem("pocketping_user_identity",JSON.stringify(e))}clearIdentity(){localStorage.removeItem("pocketping_user_identity")}generateId(){return`${Date.now().toString(36)}-${Math.random().toString(36).slice(2,11)}`}};var h=null,A=null,Ct="https://app.pocketping.io/api/widget";function _e(t){if(h)return console.warn("[PocketPing] Already initialized"),h;let e=t.endpoint;if(!e&&t.projectId&&(e=`${Ct}/${t.projectId}`),!e)throw new Error("[PocketPing] endpoint or projectId is required");let n={...t,endpoint:e};return h=new K(n),A=document.createElement("div"),A.id="pocketping-container",document.body.appendChild(A),le(oe(je,{client:h,config:t}),A),h.connect().catch(s=>{console.error("[PocketPing] Failed to connect:",s)}),h}function Be(){A&&(le(null,A),A.remove(),A=null),h&&(h.disconnect(),h=null)}function qe(){h?.setOpen(!0)}function Je(){h?.setOpen(!1)}function Xe(){h?.toggleOpen()}function Ge(t){if(!h)throw new Error("[PocketPing] Not initialized");return h.sendMessage(t)}function Ye(t,e,n){if(!h){console.warn("[PocketPing] Not initialized, cannot trigger event");return}h.trigger(t,e,n)}function Ze(t){if(!h){console.warn("[PocketPing] Not initialized, cannot setup tracked elements");return}h.setupTrackedElements(t)}function Ke(){return h?.getTrackedElements()||[]}function Qe(t,e){return h?h.onEvent(t,e):(console.warn("[PocketPing] Not initialized, cannot subscribe to event"),()=>{})}function et(t,e){h?.offEvent(t,e)}async function tt(t){if(!h)throw new Error("[PocketPing] Not initialized");return h.identify(t)}async function nt(t){if(!h){console.warn("[PocketPing] Not initialized");return}return h.reset(t)}function st(){return h?.getIdentity()||null}function it(t,e){return h?h.on(t,e):(console.warn("[PocketPing] Not initialized, cannot subscribe to event"),()=>{})}if(typeof document<"u"){let t=document.currentScript;if(t){let e=t.dataset.projectId,n=t.dataset.endpoint;(e||n)&&_e({projectId:e,endpoint:n,theme:t.dataset.theme||"auto",position:t.dataset.position||"bottom-right"})}}var Tt={init:_e,destroy:Be,open:qe,close:Je,toggle:Xe,sendMessage:Ge,trigger:Ye,onEvent:Qe,offEvent:et,on:it,identify:tt,reset:nt,getIdentity:st,setupTrackedElements:Ze,getTrackedElements:Ke};return pt(Mt);})();
package/package.json CHANGED
@@ -1,15 +1,16 @@
1
1
  {
2
2
  "name": "@pocketping/widget",
3
- "version": "0.3.3",
3
+ "version": "0.3.5",
4
+ "type": "module",
4
5
  "description": "Embeddable chat widget for PocketPing",
5
- "main": "dist/index.js",
6
- "module": "dist/index.mjs",
6
+ "main": "dist/index.cjs",
7
+ "module": "dist/index.js",
7
8
  "types": "dist/index.d.ts",
8
9
  "exports": {
9
10
  ".": {
10
- "import": "./dist/index.mjs",
11
- "require": "./dist/index.js",
12
- "types": "./dist/index.d.ts"
11
+ "types": "./dist/index.d.ts",
12
+ "import": "./dist/index.js",
13
+ "require": "./dist/index.cjs"
13
14
  },
14
15
  "./cdn": "./dist/pocketping.min.global.js"
15
16
  },
@@ -22,11 +23,11 @@
22
23
  "devDependencies": {
23
24
  "@preact/preset-vite": "^2.10.2",
24
25
  "@testing-library/preact": "^3.2.4",
25
- "@vitest/coverage-v8": "^1.6.1",
26
+ "@vitest/coverage-v8": "^4.0.18",
26
27
  "jsdom": "^27.4.0",
27
28
  "tsup": "^8.0.0",
28
29
  "typescript": "^5.3.0",
29
- "vitest": "^1.2.0"
30
+ "vitest": "^4.0.18"
30
31
  },
31
32
  "keywords": [
32
33
  "chat",