@pocketping/widget 1.5.2 → 1.6.0
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/index.cjs +177 -101
- package/dist/index.js +177 -101
- package/dist/pocketping.min.global.js +83 -30
- package/package.json +1 -1
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
"use strict";var PocketPing=(()=>{var xe=Object.defineProperty;var nn=Object.getOwnPropertyDescriptor;var sn=Object.getOwnPropertyNames;var on=Object.prototype.hasOwnProperty;var rn=(t,e)=>{for(var n in e)xe(t,n,{get:e[n],enumerable:!0})},an=(t,e,n,s)=>{if(e&&typeof e=="object"||typeof e=="function")for(let i of sn(e))!on.call(t,i)&&i!==n&&xe(t,i,{get:()=>e[i],enumerable:!(s=nn(e,i))||s.enumerable});return t};var pn=t=>an(xe({},"__esModule",{value:!0}),t);var Mn={};rn(Mn,{close:()=>Tt,default:()=>In,destroy:()=>St,getIdentity:()=>Wt,getTrackedElements:()=>Ot,identify:()=>Ht,init:()=>Ae,offEvent:()=>Lt,on:()=>Nt,onEvent:()=>Dt,open:()=>Pt,reset:()=>Ft,sendMessage:()=>Mt,setupTrackedElements:()=>Rt,toggle:()=>It,trigger:()=>At,uploadFile:()=>Ct,uploadFiles:()=>$t});var pe,w,Xe,ln,J,je,Ye,Ge,Ke,ke,ye,be,cn,Z={},Qe=[],dn=/acit|ex(?:s|g|n|p|$)|rph|grid|ows|mnc|ntw|ine[ch]|zoo|^ord|itera/i,le=Array.isArray;function V(t,e){for(var n in e)t[n]=e[n];return t}function Ee(t){t&&t.parentNode&&t.parentNode.removeChild(t)}function Se(t,e,n){var s,i,a,r={};for(a in e)a=="key"?s=e[a]:a=="ref"?i=e[a]:r[a]=e[a];if(arguments.length>2&&(r.children=arguments.length>3?pe.call(arguments,2):n),typeof t=="function"&&t.defaultProps!=null)for(a in t.defaultProps)r[a]===void 0&&(r[a]=t.defaultProps[a]);return oe(t,r,s,i,null)}function oe(t,e,n,s,i){var a={type:t,props:e,key:n,ref:s,__k:null,__:null,__b:0,__e:null,__c:null,constructor:void 0,__v:i??++Xe,__i:-1,__u:0};return i==null&&w.vnode!=null&&w.vnode(a),a}function D(t){return t.children}function re(t,e){this.props=t,this.context=e}function Y(t,e){if(e==null)return t.__?Y(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"?Y(t):null}function Ze(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 Ze(t)}}function Be(t){(!t.__d&&(t.__d=!0)&&J.push(t)&&!ae.__r++||je!=w.debounceRendering)&&((je=w.debounceRendering)||Ye)(ae)}function ae(){for(var t,e,n,s,i,a,r,c=1;J.length;)J.length>c&&J.sort(Ge),t=J.shift(),c=J.length,t.__d&&(n=void 0,s=void 0,i=(s=(e=t).__v).__e,a=[],r=[],e.__P&&((n=V({},s)).__v=s.__v+1,w.vnode&&w.vnode(n),Pe(e.__P,n,s,e.__n,e.__P.namespaceURI,32&s.__u?[i]:null,a,i??Y(s),!!(32&s.__u),r),n.__v=s.__v,n.__.__k[n.__i]=n,nt(a,n,r),s.__e=s.__=null,n.__e!=i&&Ze(n)));ae.__r=0}function et(t,e,n,s,i,a,r,c,u,l,g){var p,h,f,E,A,k,x,b=s&&s.__k||Qe,H=e.length;for(u=un(n,e,b,u,H),p=0;p<H;p++)(f=n.__k[p])!=null&&(h=f.__i==-1?Z:b[f.__i]||Z,f.__i=p,k=Pe(t,f,h,i,a,r,c,u,l,g),E=f.__e,f.ref&&h.ref!=f.ref&&(h.ref&&Te(h.ref,null,f),g.push(f.ref,f.__c||E,f)),A==null&&E!=null&&(A=E),(x=!!(4&f.__u))||h.__k===f.__k?u=tt(f,u,t,x):typeof f.type=="function"&&k!==void 0?u=k:E&&(u=E.nextSibling),f.__u&=-7);return n.__e=A,u}function un(t,e,n,s,i){var a,r,c,u,l,g=n.length,p=g,h=0;for(t.__k=new Array(i),a=0;a<i;a++)(r=e[a])!=null&&typeof r!="boolean"&&typeof r!="function"?(typeof r=="string"||typeof r=="number"||typeof r=="bigint"||r.constructor==String?r=t.__k[a]=oe(null,r,null,null,null):le(r)?r=t.__k[a]=oe(D,{children:r},null,null,null):r.constructor===void 0&&r.__b>0?r=t.__k[a]=oe(r.type,r.props,r.key,r.ref?r.ref:null,r.__v):t.__k[a]=r,u=a+h,r.__=t,r.__b=t.__b+1,c=null,(l=r.__i=gn(r,n,u,p))!=-1&&(p--,(c=n[l])&&(c.__u|=2)),c==null||c.__v==null?(l==-1&&(i>g?h--:i<g&&h++),typeof r.type!="function"&&(r.__u|=4)):l!=u&&(l==u-1?h--:l==u+1?h++:(l>u?h--:h++,r.__u|=4))):t.__k[a]=null;if(p)for(a=0;a<g;a++)(c=n[a])!=null&&(2&c.__u)==0&&(c.__e==s&&(s=Y(c)),it(c,c));return s}function tt(t,e,n,s){var i,a;if(typeof t.type=="function"){for(i=t.__k,a=0;i&&a<i.length;a++)i[a]&&(i[a].__=t,e=tt(i[a],e,n,s));return e}t.__e!=e&&(s&&(e&&t.type&&!e.parentNode&&(e=Y(t)),n.insertBefore(t.__e,e||null)),e=t.__e);do e=e&&e.nextSibling;while(e!=null&&e.nodeType==8);return e}function gn(t,e,n,s){var i,a,r,c=t.key,u=t.type,l=e[n],g=l!=null&&(2&l.__u)==0;if(l===null&&c==null||g&&c==l.key&&u==l.type)return n;if(s>(g?1:0)){for(i=n-1,a=n+1;i>=0||a<e.length;)if((l=e[r=i>=0?i--:a++])!=null&&(2&l.__u)==0&&c==l.key&&u==l.type)return r}return-1}function qe(t,e,n){e[0]=="-"?t.setProperty(e,n??""):t[e]=n==null?"":typeof n!="number"||dn.test(e)?n:n+"px"}function ie(t,e,n,s,i){var a,r;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||qe(t.style,e,"");if(n)for(e in n)s&&n[e]==s[e]||qe(t.style,e,n[e])}else if(e[0]=="o"&&e[1]=="n")a=e!=(e=e.replace(Ke,"$1")),r=e.toLowerCase(),e=r in t||e=="onFocusOut"||e=="onFocusIn"?r.slice(2):e.slice(2),t.l||(t.l={}),t.l[e+a]=n,n?s?n.u=s.u:(n.u=ke,t.addEventListener(e,a?be:ye,a)):t.removeEventListener(e,a?be:ye,a);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 Je(t){return function(e){if(this.l){var n=this.l[e.type+t];if(e.t==null)e.t=ke++;else if(e.t<n.u)return;return n(w.event?w.event(e):e)}}}function Pe(t,e,n,s,i,a,r,c,u,l){var g,p,h,f,E,A,k,x,b,H,R,B,N,X,U,F,L,O=e.type;if(e.constructor!==void 0)return null;128&n.__u&&(u=!!(32&n.__u),a=[c=e.__e=n.__e]),(g=w.__b)&&g(e);e:if(typeof O=="function")try{if(x=e.props,b="prototype"in O&&O.prototype.render,H=(g=O.contextType)&&s[g.__c],R=g?H?H.props.value:g.__:s,n.__c?k=(p=e.__c=n.__c).__=p.__E:(b?e.__c=p=new O(x,R):(e.__c=p=new re(x,R),p.constructor=O,p.render=fn),H&&H.sub(p),p.state||(p.state={}),p.__n=s,h=p.__d=!0,p.__h=[],p._sb=[]),b&&p.__s==null&&(p.__s=p.state),b&&O.getDerivedStateFromProps!=null&&(p.__s==p.state&&(p.__s=V({},p.__s)),V(p.__s,O.getDerivedStateFromProps(x,p.__s))),f=p.props,E=p.state,p.__v=e,h)b&&O.getDerivedStateFromProps==null&&p.componentWillMount!=null&&p.componentWillMount(),b&&p.componentDidMount!=null&&p.__h.push(p.componentDidMount);else{if(b&&O.getDerivedStateFromProps==null&&x!==f&&p.componentWillReceiveProps!=null&&p.componentWillReceiveProps(x,R),e.__v==n.__v||!p.__e&&p.shouldComponentUpdate!=null&&p.shouldComponentUpdate(x,p.__s,R)===!1){for(e.__v!=n.__v&&(p.props=x,p.state=p.__s,p.__d=!1),e.__e=n.__e,e.__k=n.__k,e.__k.some(function(z){z&&(z.__=e)}),B=0;B<p._sb.length;B++)p.__h.push(p._sb[B]);p._sb=[],p.__h.length&&r.push(p);break e}p.componentWillUpdate!=null&&p.componentWillUpdate(x,p.__s,R),b&&p.componentDidUpdate!=null&&p.__h.push(function(){p.componentDidUpdate(f,E,A)})}if(p.context=R,p.props=x,p.__P=t,p.__e=!1,N=w.__r,X=0,b){for(p.state=p.__s,p.__d=!1,N&&N(e),g=p.render(p.props,p.state,p.context),U=0;U<p._sb.length;U++)p.__h.push(p._sb[U]);p._sb=[]}else do p.__d=!1,N&&N(e),g=p.render(p.props,p.state,p.context),p.state=p.__s;while(p.__d&&++X<25);p.state=p.__s,p.getChildContext!=null&&(s=V(V({},s),p.getChildContext())),b&&!h&&p.getSnapshotBeforeUpdate!=null&&(A=p.getSnapshotBeforeUpdate(f,E)),F=g,g!=null&&g.type===D&&g.key==null&&(F=st(g.props.children)),c=et(t,le(F)?F:[F],e,n,s,i,a,r,c,u,l),p.base=e.__e,e.__u&=-161,p.__h.length&&r.push(p),k&&(p.__E=p.__=null)}catch(z){if(e.__v=null,u||a!=null)if(z.then){for(e.__u|=u?160:128;c&&c.nodeType==8&&c.nextSibling;)c=c.nextSibling;a[a.indexOf(c)]=null,e.__e=c}else{for(L=a.length;L--;)Ee(a[L]);we(e)}else e.__e=n.__e,e.__k=n.__k,z.then||we(e);w.__e(z,e,n)}else a==null&&e.__v==n.__v?(e.__k=n.__k,e.__e=n.__e):c=e.__e=hn(n.__e,e,n,s,i,a,r,u,l);return(g=w.diffed)&&g(e),128&e.__u?void 0:c}function we(t){t&&t.__c&&(t.__c.__e=!0),t&&t.__k&&t.__k.forEach(we)}function nt(t,e,n){for(var s=0;s<n.length;s++)Te(n[s],n[++s],n[++s]);w.__c&&w.__c(e,t),t.some(function(i){try{t=i.__h,i.__h=[],t.some(function(a){a.call(i)})}catch(a){w.__e(a,i.__v)}})}function st(t){return typeof t!="object"||t==null||t.__b&&t.__b>0?t:le(t)?t.map(st):V({},t)}function hn(t,e,n,s,i,a,r,c,u){var l,g,p,h,f,E,A,k=n.props||Z,x=e.props,b=e.type;if(b=="svg"?i="http://www.w3.org/2000/svg":b=="math"?i="http://www.w3.org/1998/Math/MathML":i||(i="http://www.w3.org/1999/xhtml"),a!=null){for(l=0;l<a.length;l++)if((f=a[l])&&"setAttribute"in f==!!b&&(b?f.localName==b:f.nodeType==3)){t=f,a[l]=null;break}}if(t==null){if(b==null)return document.createTextNode(x);t=document.createElementNS(i,b,x.is&&x),c&&(w.__m&&w.__m(e,a),c=!1),a=null}if(b==null)k===x||c&&t.data==x||(t.data=x);else{if(a=a&&pe.call(t.childNodes),!c&&a!=null)for(k={},l=0;l<t.attributes.length;l++)k[(f=t.attributes[l]).name]=f.value;for(l in k)if(f=k[l],l!="children"){if(l=="dangerouslySetInnerHTML")p=f;else if(!(l in x)){if(l=="value"&&"defaultValue"in x||l=="checked"&&"defaultChecked"in x)continue;ie(t,l,null,f,i)}}for(l in x)f=x[l],l=="children"?h=f:l=="dangerouslySetInnerHTML"?g=f:l=="value"?E=f:l=="checked"?A=f:c&&typeof f!="function"||k[l]===f||ie(t,l,f,k[l],i);if(g)c||p&&(g.__html==p.__html||g.__html==t.innerHTML)||(t.innerHTML=g.__html),e.__k=[];else if(p&&(t.innerHTML=""),et(e.type=="template"?t.content:t,le(h)?h:[h],e,n,s,b=="foreignObject"?"http://www.w3.org/1999/xhtml":i,a,r,a?a[0]:n.__k&&Y(n,0),c,u),a!=null)for(l=a.length;l--;)Ee(a[l]);c||(l="value",b=="progress"&&E==null?t.removeAttribute("value"):E!=null&&(E!==t[l]||b=="progress"&&!E||b=="option"&&E!=k[l])&&ie(t,l,E,k[l],i),l="checked",A!=null&&A!=t[l]&&ie(t,l,A,k[l],i))}return t}function Te(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){w.__e(i,n)}}function it(t,e,n){var s,i;if(w.unmount&&w.unmount(t),(s=t.ref)&&(s.current&&s.current!=t.__e||Te(s,null,e)),(s=t.__c)!=null){if(s.componentWillUnmount)try{s.componentWillUnmount()}catch(a){w.__e(a,e)}s.base=s.__P=null}if(s=t.__k)for(i=0;i<s.length;i++)s[i]&&it(s[i],e,n||typeof t.type!="function");n||Ee(t.__e),t.__c=t.__=t.__e=void 0}function fn(t,e,n){return this.constructor(t,n)}function Ie(t,e,n){var s,i,a,r;e==document&&(e=document.documentElement),w.__&&w.__(t,e),i=(s=typeof n=="function")?null:n&&n.__k||e.__k,a=[],r=[],Pe(e,t=(!s&&n||e).__k=Se(D,null,[t]),i||Z,Z,e.namespaceURI,!s&&n?[n]:i?null:e.firstChild?pe.call(e.childNodes):null,a,!s&&n?n:i?i.__e:e.firstChild,s,r),nt(a,t,r)}pe=Qe.slice,w={__e:function(t,e,n,s){for(var i,a,r;e=e.__;)if((i=e.__c)&&!i.__)try{if((a=i.constructor)&&a.getDerivedStateFromError!=null&&(i.setState(a.getDerivedStateFromError(t)),r=i.__d),i.componentDidCatch!=null&&(i.componentDidCatch(t,s||{}),r=i.__d),r)return i.__E=i}catch(c){t=c}throw t}},Xe=0,ln=function(t){return t!=null&&t.constructor===void 0},re.prototype.setState=function(t,e){var n;n=this.__s!=null&&this.__s!=this.state?this.__s:this.__s=V({},this.state),typeof t=="function"&&(t=t(V({},n),this.props)),t&&V(n,t),t!=null&&this.__v&&(e&&this._sb.push(e),Be(this))},re.prototype.forceUpdate=function(t){this.__v&&(this.__e=!0,t&&this.__h.push(t),Be(this))},re.prototype.render=D,J=[],Ye=typeof Promise=="function"?Promise.prototype.then.bind(Promise.resolve()):setTimeout,Ge=function(t,e){return t.__v.__b-e.__v.__b},ae.__r=0,Ke=/(PointerCapture)$|Capture$/i,ke=0,ye=Je(!1),be=Je(!0),cn=0;var ee,M,Me,ot,te=0,gt=[],C=w,rt=C.__b,at=C.__r,pt=C.diffed,lt=C.__c,ct=C.unmount,dt=C.__;function $e(t,e){C.__h&&C.__h(M,t,te||e),te=0;var n=M.__H||(M.__H={__:[],__h:[]});return t>=n.__.length&&n.__.push({}),n.__[t]}function $(t){return te=1,mn(_t,t)}function mn(t,e,n){var s=$e(ee++,2);if(s.t=t,!s.__c&&(s.__=[n?n(e):_t(void 0,e),function(c){var u=s.__N?s.__N[0]:s.__[0],l=s.t(u,c);u!==l&&(s.__N=[l,s.__[1]],s.__c.setState({}))}],s.__c=M,!M.__f)){var i=function(c,u,l){if(!s.__c.__H)return!0;var g=s.__c.__H.__.filter(function(h){return!!h.__c});if(g.every(function(h){return!h.__N}))return!a||a.call(this,c,u,l);var p=s.__c.props!==c;return g.forEach(function(h){if(h.__N){var f=h.__[0];h.__=h.__N,h.__N=void 0,f!==h.__[0]&&(p=!0)}}),a&&a.call(this,c,u,l)||p};M.__f=!0;var a=M.shouldComponentUpdate,r=M.componentWillUpdate;M.componentWillUpdate=function(c,u,l){if(this.__e){var g=a;a=void 0,i(c,u,l),a=g}r&&r.call(this,c,u,l)},M.shouldComponentUpdate=i}return s.__N||s.__}function j(t,e){var n=$e(ee++,3);!C.__s&&mt(n.__H,e)&&(n.__=t,n.u=e,M.__H.__h.push(n))}function G(t){return te=5,ht(function(){return{current:t}},[])}function ht(t,e){var n=$e(ee++,7);return mt(n.__H,e)&&(n.__=t(),n.__H=e,n.__h=t),n.__}function ft(t,e){return te=8,ht(function(){return t},e)}function _n(){for(var t;t=gt.shift();)if(t.__P&&t.__H)try{t.__H.__h.forEach(ce),t.__H.__h.forEach(Ce),t.__H.__h=[]}catch(e){t.__H.__h=[],C.__e(e,t.__v)}}C.__b=function(t){M=null,rt&&rt(t)},C.__=function(t,e){t&&e.__k&&e.__k.__m&&(t.__m=e.__k.__m),dt&&dt(t,e)},C.__r=function(t){at&&at(t),ee=0;var e=(M=t.__c).__H;e&&(Me===M?(e.__h=[],M.__h=[],e.__.forEach(function(n){n.__N&&(n.__=n.__N),n.u=n.__N=void 0})):(e.__h.forEach(ce),e.__h.forEach(Ce),e.__h=[],ee=0)),Me=M},C.diffed=function(t){pt&&pt(t);var e=t.__c;e&&e.__H&&(e.__H.__h.length&&(gt.push(e)!==1&&ot===C.requestAnimationFrame||((ot=C.requestAnimationFrame)||vn)(_n)),e.__H.__.forEach(function(n){n.u&&(n.__H=n.u),n.u=void 0})),Me=M=null},C.__c=function(t,e){e.some(function(n){try{n.__h.forEach(ce),n.__h=n.__h.filter(function(s){return!s.__||Ce(s)})}catch(s){e.some(function(i){i.__h&&(i.__h=[])}),e=[],C.__e(s,n.__v)}}),lt&<(t,e)},C.unmount=function(t){ct&&ct(t);var e,n=t.__c;n&&n.__H&&(n.__H.__.forEach(function(s){try{ce(s)}catch(i){e=i}}),n.__H=void 0,e&&C.__e(e,n.__v))};var ut=typeof requestAnimationFrame=="function";function vn(t){var e,n=function(){clearTimeout(s),ut&&cancelAnimationFrame(e),setTimeout(t)},s=setTimeout(n,35);ut&&(e=requestAnimationFrame(n))}function ce(t){var e=M,n=t.__c;typeof n=="function"&&(t.__c=void 0,n()),M=e}function Ce(t){var e=M;t.__c=t.__(),M=e}function mt(t,e){return!t||t.length!==e.length||e.some(function(n,s){return n!==t[s]})}function _t(t,e){return typeof e=="function"?e(t):e}function vt(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 be=Object.defineProperty;var an=Object.getOwnPropertyDescriptor;var pn=Object.getOwnPropertyNames;var ln=Object.prototype.hasOwnProperty;var cn=(t,e)=>{for(var n in e)be(t,n,{get:e[n],enumerable:!0})},dn=(t,e,n,s)=>{if(e&&typeof e=="object"||typeof e=="function")for(let i of pn(e))!ln.call(t,i)&&i!==n&&be(t,i,{get:()=>e[i],enumerable:!(s=an(e,i))||s.enumerable});return t};var un=t=>dn(be({},"__esModule",{value:!0}),t);var Rn={};cn(Rn,{close:()=>Ct,default:()=>Dn,destroy:()=>It,getIdentity:()=>zt,getTrackedElements:()=>Ht,identify:()=>Nt,init:()=>Re,offEvent:()=>Wt,on:()=>Vt,onEvent:()=>Ft,open:()=>Mt,reset:()=>Ut,sendMessage:()=>At,setupTrackedElements:()=>Lt,toggle:()=>$t,trigger:()=>Ot,uploadFile:()=>Dt,uploadFiles:()=>Rt});var de,w,Ge,gn,Y,qe,Ke,Qe,Ze,Ee,we,ke,hn,ee={},et=[],fn=/acit|ex(?:s|g|n|p|$)|rph|grid|ows|mnc|ntw|ine[ch]|zoo|^ord|itera/i,ue=Array.isArray;function j(t,e){for(var n in e)t[n]=e[n];return t}function Pe(t){t&&t.parentNode&&t.parentNode.removeChild(t)}function Te(t,e,n){var s,i,a,r={};for(a in e)a=="key"?s=e[a]:a=="ref"?i=e[a]:r[a]=e[a];if(arguments.length>2&&(r.children=arguments.length>3?de.call(arguments,2):n),typeof t=="function"&&t.defaultProps!=null)for(a in t.defaultProps)r[a]===void 0&&(r[a]=t.defaultProps[a]);return pe(t,r,s,i,null)}function pe(t,e,n,s,i){var a={type:t,props:e,key:n,ref:s,__k:null,__:null,__b:0,__e:null,__c:null,constructor:void 0,__v:i??++Ge,__i:-1,__u:0};return i==null&&w.vnode!=null&&w.vnode(a),a}function $(t){return t.children}function le(t,e){this.props=t,this.context=e}function G(t,e){if(e==null)return t.__?G(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"?G(t):null}function tt(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 tt(t)}}function Je(t){(!t.__d&&(t.__d=!0)&&Y.push(t)&&!ce.__r++||qe!=w.debounceRendering)&&((qe=w.debounceRendering)||Ke)(ce)}function ce(){for(var t,e,n,s,i,a,r,d=1;Y.length;)Y.length>d&&Y.sort(Qe),t=Y.shift(),d=Y.length,t.__d&&(n=void 0,s=void 0,i=(s=(e=t).__v).__e,a=[],r=[],e.__P&&((n=j({},s)).__v=s.__v+1,w.vnode&&w.vnode(n),Ie(e.__P,n,s,e.__n,e.__P.namespaceURI,32&s.__u?[i]:null,a,i??G(s),!!(32&s.__u),r),n.__v=s.__v,n.__.__k[n.__i]=n,it(a,n,r),s.__e=s.__=null,n.__e!=i&&tt(n)));ce.__r=0}function nt(t,e,n,s,i,a,r,d,u,l,g){var p,h,f,T,D,E,_,b=s&&s.__k||et,F=e.length;for(u=mn(n,e,b,u,F),p=0;p<F;p++)(f=n.__k[p])!=null&&(h=f.__i==-1?ee:b[f.__i]||ee,f.__i=p,E=Ie(t,f,h,i,a,r,d,u,l,g),T=f.__e,f.ref&&h.ref!=f.ref&&(h.ref&&Me(h.ref,null,f),g.push(f.ref,f.__c||T,f)),D==null&&T!=null&&(D=T),(_=!!(4&f.__u))||h.__k===f.__k?u=st(f,u,t,_):typeof f.type=="function"&&E!==void 0?u=E:T&&(u=T.nextSibling),f.__u&=-7);return n.__e=D,u}function mn(t,e,n,s,i){var a,r,d,u,l,g=n.length,p=g,h=0;for(t.__k=new Array(i),a=0;a<i;a++)(r=e[a])!=null&&typeof r!="boolean"&&typeof r!="function"?(typeof r=="string"||typeof r=="number"||typeof r=="bigint"||r.constructor==String?r=t.__k[a]=pe(null,r,null,null,null):ue(r)?r=t.__k[a]=pe($,{children:r},null,null,null):r.constructor===void 0&&r.__b>0?r=t.__k[a]=pe(r.type,r.props,r.key,r.ref?r.ref:null,r.__v):t.__k[a]=r,u=a+h,r.__=t,r.__b=t.__b+1,d=null,(l=r.__i=_n(r,n,u,p))!=-1&&(p--,(d=n[l])&&(d.__u|=2)),d==null||d.__v==null?(l==-1&&(i>g?h--:i<g&&h++),typeof r.type!="function"&&(r.__u|=4)):l!=u&&(l==u-1?h--:l==u+1?h++:(l>u?h--:h++,r.__u|=4))):t.__k[a]=null;if(p)for(a=0;a<g;a++)(d=n[a])!=null&&(2&d.__u)==0&&(d.__e==s&&(s=G(d)),rt(d,d));return s}function st(t,e,n,s){var i,a;if(typeof t.type=="function"){for(i=t.__k,a=0;i&&a<i.length;a++)i[a]&&(i[a].__=t,e=st(i[a],e,n,s));return e}t.__e!=e&&(s&&(e&&t.type&&!e.parentNode&&(e=G(t)),n.insertBefore(t.__e,e||null)),e=t.__e);do e=e&&e.nextSibling;while(e!=null&&e.nodeType==8);return e}function _n(t,e,n,s){var i,a,r,d=t.key,u=t.type,l=e[n],g=l!=null&&(2&l.__u)==0;if(l===null&&d==null||g&&d==l.key&&u==l.type)return n;if(s>(g?1:0)){for(i=n-1,a=n+1;i>=0||a<e.length;)if((l=e[r=i>=0?i--:a++])!=null&&(2&l.__u)==0&&d==l.key&&u==l.type)return r}return-1}function Ye(t,e,n){e[0]=="-"?t.setProperty(e,n??""):t[e]=n==null?"":typeof n!="number"||fn.test(e)?n:n+"px"}function ae(t,e,n,s,i){var a,r;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||Ye(t.style,e,"");if(n)for(e in n)s&&n[e]==s[e]||Ye(t.style,e,n[e])}else if(e[0]=="o"&&e[1]=="n")a=e!=(e=e.replace(Ze,"$1")),r=e.toLowerCase(),e=r in t||e=="onFocusOut"||e=="onFocusIn"?r.slice(2):e.slice(2),t.l||(t.l={}),t.l[e+a]=n,n?s?n.u=s.u:(n.u=Ee,t.addEventListener(e,a?ke:we,a)):t.removeEventListener(e,a?ke:we,a);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 Xe(t){return function(e){if(this.l){var n=this.l[e.type+t];if(e.t==null)e.t=Ee++;else if(e.t<n.u)return;return n(w.event?w.event(e):e)}}}function Ie(t,e,n,s,i,a,r,d,u,l){var g,p,h,f,T,D,E,_,b,F,R,q,U,X,z,W,H,O=e.type;if(e.constructor!==void 0)return null;128&n.__u&&(u=!!(32&n.__u),a=[d=e.__e=n.__e]),(g=w.__b)&&g(e);e:if(typeof O=="function")try{if(_=e.props,b="prototype"in O&&O.prototype.render,F=(g=O.contextType)&&s[g.__c],R=g?F?F.props.value:g.__:s,n.__c?E=(p=e.__c=n.__c).__=p.__E:(b?e.__c=p=new O(_,R):(e.__c=p=new le(_,R),p.constructor=O,p.render=xn),F&&F.sub(p),p.state||(p.state={}),p.__n=s,h=p.__d=!0,p.__h=[],p._sb=[]),b&&p.__s==null&&(p.__s=p.state),b&&O.getDerivedStateFromProps!=null&&(p.__s==p.state&&(p.__s=j({},p.__s)),j(p.__s,O.getDerivedStateFromProps(_,p.__s))),f=p.props,T=p.state,p.__v=e,h)b&&O.getDerivedStateFromProps==null&&p.componentWillMount!=null&&p.componentWillMount(),b&&p.componentDidMount!=null&&p.__h.push(p.componentDidMount);else{if(b&&O.getDerivedStateFromProps==null&&_!==f&&p.componentWillReceiveProps!=null&&p.componentWillReceiveProps(_,R),e.__v==n.__v||!p.__e&&p.shouldComponentUpdate!=null&&p.shouldComponentUpdate(_,p.__s,R)===!1){for(e.__v!=n.__v&&(p.props=_,p.state=p.__s,p.__d=!1),e.__e=n.__e,e.__k=n.__k,e.__k.some(function(V){V&&(V.__=e)}),q=0;q<p._sb.length;q++)p.__h.push(p._sb[q]);p._sb=[],p.__h.length&&r.push(p);break e}p.componentWillUpdate!=null&&p.componentWillUpdate(_,p.__s,R),b&&p.componentDidUpdate!=null&&p.__h.push(function(){p.componentDidUpdate(f,T,D)})}if(p.context=R,p.props=_,p.__P=t,p.__e=!1,U=w.__r,X=0,b){for(p.state=p.__s,p.__d=!1,U&&U(e),g=p.render(p.props,p.state,p.context),z=0;z<p._sb.length;z++)p.__h.push(p._sb[z]);p._sb=[]}else do p.__d=!1,U&&U(e),g=p.render(p.props,p.state,p.context),p.state=p.__s;while(p.__d&&++X<25);p.state=p.__s,p.getChildContext!=null&&(s=j(j({},s),p.getChildContext())),b&&!h&&p.getSnapshotBeforeUpdate!=null&&(D=p.getSnapshotBeforeUpdate(f,T)),W=g,g!=null&&g.type===$&&g.key==null&&(W=ot(g.props.children)),d=nt(t,ue(W)?W:[W],e,n,s,i,a,r,d,u,l),p.base=e.__e,e.__u&=-161,p.__h.length&&r.push(p),E&&(p.__E=p.__=null)}catch(V){if(e.__v=null,u||a!=null)if(V.then){for(e.__u|=u?160:128;d&&d.nodeType==8&&d.nextSibling;)d=d.nextSibling;a[a.indexOf(d)]=null,e.__e=d}else{for(H=a.length;H--;)Pe(a[H]);Se(e)}else e.__e=n.__e,e.__k=n.__k,V.then||Se(e);w.__e(V,e,n)}else a==null&&e.__v==n.__v?(e.__k=n.__k,e.__e=n.__e):d=e.__e=vn(n.__e,e,n,s,i,a,r,u,l);return(g=w.diffed)&&g(e),128&e.__u?void 0:d}function Se(t){t&&t.__c&&(t.__c.__e=!0),t&&t.__k&&t.__k.forEach(Se)}function it(t,e,n){for(var s=0;s<n.length;s++)Me(n[s],n[++s],n[++s]);w.__c&&w.__c(e,t),t.some(function(i){try{t=i.__h,i.__h=[],t.some(function(a){a.call(i)})}catch(a){w.__e(a,i.__v)}})}function ot(t){return typeof t!="object"||t==null||t.__b&&t.__b>0?t:ue(t)?t.map(ot):j({},t)}function vn(t,e,n,s,i,a,r,d,u){var l,g,p,h,f,T,D,E=n.props||ee,_=e.props,b=e.type;if(b=="svg"?i="http://www.w3.org/2000/svg":b=="math"?i="http://www.w3.org/1998/Math/MathML":i||(i="http://www.w3.org/1999/xhtml"),a!=null){for(l=0;l<a.length;l++)if((f=a[l])&&"setAttribute"in f==!!b&&(b?f.localName==b:f.nodeType==3)){t=f,a[l]=null;break}}if(t==null){if(b==null)return document.createTextNode(_);t=document.createElementNS(i,b,_.is&&_),d&&(w.__m&&w.__m(e,a),d=!1),a=null}if(b==null)E===_||d&&t.data==_||(t.data=_);else{if(a=a&&de.call(t.childNodes),!d&&a!=null)for(E={},l=0;l<t.attributes.length;l++)E[(f=t.attributes[l]).name]=f.value;for(l in E)if(f=E[l],l!="children"){if(l=="dangerouslySetInnerHTML")p=f;else if(!(l in _)){if(l=="value"&&"defaultValue"in _||l=="checked"&&"defaultChecked"in _)continue;ae(t,l,null,f,i)}}for(l in _)f=_[l],l=="children"?h=f:l=="dangerouslySetInnerHTML"?g=f:l=="value"?T=f:l=="checked"?D=f:d&&typeof f!="function"||E[l]===f||ae(t,l,f,E[l],i);if(g)d||p&&(g.__html==p.__html||g.__html==t.innerHTML)||(t.innerHTML=g.__html),e.__k=[];else if(p&&(t.innerHTML=""),nt(e.type=="template"?t.content:t,ue(h)?h:[h],e,n,s,b=="foreignObject"?"http://www.w3.org/1999/xhtml":i,a,r,a?a[0]:n.__k&&G(n,0),d,u),a!=null)for(l=a.length;l--;)Pe(a[l]);d||(l="value",b=="progress"&&T==null?t.removeAttribute("value"):T!=null&&(T!==t[l]||b=="progress"&&!T||b=="option"&&T!=E[l])&&ae(t,l,T,E[l],i),l="checked",D!=null&&D!=t[l]&&ae(t,l,D,E[l],i))}return t}function Me(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){w.__e(i,n)}}function rt(t,e,n){var s,i;if(w.unmount&&w.unmount(t),(s=t.ref)&&(s.current&&s.current!=t.__e||Me(s,null,e)),(s=t.__c)!=null){if(s.componentWillUnmount)try{s.componentWillUnmount()}catch(a){w.__e(a,e)}s.base=s.__P=null}if(s=t.__k)for(i=0;i<s.length;i++)s[i]&&rt(s[i],e,n||typeof t.type!="function");n||Pe(t.__e),t.__c=t.__=t.__e=void 0}function xn(t,e,n){return this.constructor(t,n)}function Ce(t,e,n){var s,i,a,r;e==document&&(e=document.documentElement),w.__&&w.__(t,e),i=(s=typeof n=="function")?null:n&&n.__k||e.__k,a=[],r=[],Ie(e,t=(!s&&n||e).__k=Te($,null,[t]),i||ee,ee,e.namespaceURI,!s&&n?[n]:i?null:e.firstChild?de.call(e.childNodes):null,a,!s&&n?n:i?i.__e:e.firstChild,s,r),it(a,t,r)}de=et.slice,w={__e:function(t,e,n,s){for(var i,a,r;e=e.__;)if((i=e.__c)&&!i.__)try{if((a=i.constructor)&&a.getDerivedStateFromError!=null&&(i.setState(a.getDerivedStateFromError(t)),r=i.__d),i.componentDidCatch!=null&&(i.componentDidCatch(t,s||{}),r=i.__d),r)return i.__E=i}catch(d){t=d}throw t}},Ge=0,gn=function(t){return t!=null&&t.constructor===void 0},le.prototype.setState=function(t,e){var n;n=this.__s!=null&&this.__s!=this.state?this.__s:this.__s=j({},this.state),typeof t=="function"&&(t=t(j({},n),this.props)),t&&j(n,t),t!=null&&this.__v&&(e&&this._sb.push(e),Je(this))},le.prototype.forceUpdate=function(t){this.__v&&(this.__e=!0,t&&this.__h.push(t),Je(this))},le.prototype.render=$,Y=[],Ke=typeof Promise=="function"?Promise.prototype.then.bind(Promise.resolve()):setTimeout,Qe=function(t,e){return t.__v.__b-e.__v.__b},ce.__r=0,Ze=/(PointerCapture)$|Capture$/i,Ee=0,we=Xe(!1),ke=Xe(!0),hn=0;var te,M,$e,at,ne=0,ft=[],C=w,pt=C.__b,lt=C.__r,ct=C.diffed,dt=C.__c,ut=C.unmount,gt=C.__;function De(t,e){C.__h&&C.__h(M,t,ne||e),ne=0;var n=M.__H||(M.__H={__:[],__h:[]});return t>=n.__.length&&n.__.push({}),n.__[t]}function A(t){return ne=1,yn(xt,t)}function yn(t,e,n){var s=De(te++,2);if(s.t=t,!s.__c&&(s.__=[n?n(e):xt(void 0,e),function(d){var u=s.__N?s.__N[0]:s.__[0],l=s.t(u,d);u!==l&&(s.__N=[l,s.__[1]],s.__c.setState({}))}],s.__c=M,!M.__f)){var i=function(d,u,l){if(!s.__c.__H)return!0;var g=s.__c.__H.__.filter(function(h){return!!h.__c});if(g.every(function(h){return!h.__N}))return!a||a.call(this,d,u,l);var p=s.__c.props!==d;return g.forEach(function(h){if(h.__N){var f=h.__[0];h.__=h.__N,h.__N=void 0,f!==h.__[0]&&(p=!0)}}),a&&a.call(this,d,u,l)||p};M.__f=!0;var a=M.shouldComponentUpdate,r=M.componentWillUpdate;M.componentWillUpdate=function(d,u,l){if(this.__e){var g=a;a=void 0,i(d,u,l),a=g}r&&r.call(this,d,u,l)},M.shouldComponentUpdate=i}return s.__N||s.__}function B(t,e){var n=De(te++,3);!C.__s&&vt(n.__H,e)&&(n.__=t,n.u=e,M.__H.__h.push(n))}function K(t){return ne=5,mt(function(){return{current:t}},[])}function mt(t,e){var n=De(te++,7);return vt(n.__H,e)&&(n.__=t(),n.__H=e,n.__h=t),n.__}function _t(t,e){return ne=8,mt(function(){return t},e)}function bn(){for(var t;t=ft.shift();)if(t.__P&&t.__H)try{t.__H.__h.forEach(ge),t.__H.__h.forEach(Ae),t.__H.__h=[]}catch(e){t.__H.__h=[],C.__e(e,t.__v)}}C.__b=function(t){M=null,pt&&pt(t)},C.__=function(t,e){t&&e.__k&&e.__k.__m&&(t.__m=e.__k.__m),gt&>(t,e)},C.__r=function(t){lt&<(t),te=0;var e=(M=t.__c).__H;e&&($e===M?(e.__h=[],M.__h=[],e.__.forEach(function(n){n.__N&&(n.__=n.__N),n.u=n.__N=void 0})):(e.__h.forEach(ge),e.__h.forEach(Ae),e.__h=[],te=0)),$e=M},C.diffed=function(t){ct&&ct(t);var e=t.__c;e&&e.__H&&(e.__H.__h.length&&(ft.push(e)!==1&&at===C.requestAnimationFrame||((at=C.requestAnimationFrame)||wn)(bn)),e.__H.__.forEach(function(n){n.u&&(n.__H=n.u),n.u=void 0})),$e=M=null},C.__c=function(t,e){e.some(function(n){try{n.__h.forEach(ge),n.__h=n.__h.filter(function(s){return!s.__||Ae(s)})}catch(s){e.some(function(i){i.__h&&(i.__h=[])}),e=[],C.__e(s,n.__v)}}),dt&&dt(t,e)},C.unmount=function(t){ut&&ut(t);var e,n=t.__c;n&&n.__H&&(n.__H.__.forEach(function(s){try{ge(s)}catch(i){e=i}}),n.__H=void 0,e&&C.__e(e,n.__v))};var ht=typeof requestAnimationFrame=="function";function wn(t){var e,n=function(){clearTimeout(s),ht&&cancelAnimationFrame(e),setTimeout(t)},s=setTimeout(n,35);ht&&(e=requestAnimationFrame(n))}function ge(t){var e=M,n=t.__c;typeof n=="function"&&(t.__c=void 0,n()),M=e}function Ae(t){var e=M;t.__c=t.__(),M=e}function vt(t,e){return!t||t.length!==e.length||e.some(function(n,s){return n!==t[s]})}function xt(t,e){return typeof e=="function"?e(t):e}function yt(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;
|
|
@@ -130,7 +130,7 @@
|
|
|
130
130
|
display: flex;
|
|
131
131
|
align-items: center;
|
|
132
132
|
justify-content: space-between;
|
|
133
|
-
padding:
|
|
133
|
+
padding: 12px 14px;
|
|
134
134
|
background: ${t};
|
|
135
135
|
color: white;
|
|
136
136
|
}
|
|
@@ -138,24 +138,24 @@
|
|
|
138
138
|
.pp-header-info {
|
|
139
139
|
display: flex;
|
|
140
140
|
align-items: center;
|
|
141
|
-
gap:
|
|
141
|
+
gap: 10px;
|
|
142
142
|
}
|
|
143
143
|
|
|
144
144
|
.pp-avatar {
|
|
145
|
-
width:
|
|
146
|
-
height:
|
|
145
|
+
width: 36px;
|
|
146
|
+
height: 36px;
|
|
147
147
|
border-radius: 50%;
|
|
148
148
|
object-fit: cover;
|
|
149
149
|
}
|
|
150
150
|
|
|
151
151
|
.pp-header-title {
|
|
152
152
|
font-weight: 600;
|
|
153
|
-
font-size:
|
|
153
|
+
font-size: 15px;
|
|
154
154
|
}
|
|
155
155
|
|
|
156
156
|
.pp-header-status {
|
|
157
|
-
font-size:
|
|
158
|
-
opacity: 0.
|
|
157
|
+
font-size: 11px;
|
|
158
|
+
opacity: 0.85;
|
|
159
159
|
display: flex;
|
|
160
160
|
align-items: center;
|
|
161
161
|
gap: 4px;
|
|
@@ -201,10 +201,10 @@
|
|
|
201
201
|
.pp-messages {
|
|
202
202
|
flex: 1;
|
|
203
203
|
overflow-y: auto;
|
|
204
|
-
padding:
|
|
204
|
+
padding: 12px;
|
|
205
205
|
display: flex;
|
|
206
206
|
flex-direction: column;
|
|
207
|
-
gap:
|
|
207
|
+
gap: 3px;
|
|
208
208
|
}
|
|
209
209
|
|
|
210
210
|
.pp-welcome {
|
|
@@ -214,14 +214,32 @@
|
|
|
214
214
|
font-size: 13px;
|
|
215
215
|
}
|
|
216
216
|
|
|
217
|
+
.pp-date-separator {
|
|
218
|
+
display: flex;
|
|
219
|
+
align-items: center;
|
|
220
|
+
justify-content: center;
|
|
221
|
+
margin: 16px 0 12px;
|
|
222
|
+
}
|
|
223
|
+
|
|
224
|
+
.pp-date-separator span {
|
|
225
|
+
background: ${s.bgSecondary};
|
|
226
|
+
color: ${s.textSecondary};
|
|
227
|
+
font-size: 11px;
|
|
228
|
+
padding: 4px 12px;
|
|
229
|
+
border-radius: 12px;
|
|
230
|
+
font-weight: 500;
|
|
231
|
+
}
|
|
232
|
+
|
|
217
233
|
.pp-message {
|
|
218
|
-
max-width:
|
|
219
|
-
padding: 10px
|
|
220
|
-
border-radius:
|
|
234
|
+
max-width: 85%;
|
|
235
|
+
padding: 6px 10px;
|
|
236
|
+
border-radius: 12px;
|
|
221
237
|
word-wrap: break-word;
|
|
222
238
|
position: relative;
|
|
223
239
|
user-select: text;
|
|
224
240
|
-webkit-user-select: text;
|
|
241
|
+
font-size: 14px;
|
|
242
|
+
line-height: 1.35;
|
|
225
243
|
}
|
|
226
244
|
|
|
227
245
|
/* Hover actions container - positioned above message (Slack style) */
|
|
@@ -313,7 +331,8 @@
|
|
|
313
331
|
align-self: flex-end;
|
|
314
332
|
background: ${t};
|
|
315
333
|
color: white;
|
|
316
|
-
border-bottom-right-radius:
|
|
334
|
+
border-bottom-right-radius: 3px;
|
|
335
|
+
margin-left: 32px;
|
|
317
336
|
}
|
|
318
337
|
|
|
319
338
|
.pp-message-operator,
|
|
@@ -321,19 +340,31 @@
|
|
|
321
340
|
align-self: flex-start;
|
|
322
341
|
background: ${s.messageBg};
|
|
323
342
|
color: ${s.text};
|
|
324
|
-
border-bottom-left-radius:
|
|
343
|
+
border-bottom-left-radius: 3px;
|
|
344
|
+
margin-right: 32px;
|
|
345
|
+
}
|
|
346
|
+
|
|
347
|
+
/* Add spacing between different senders */
|
|
348
|
+
.pp-message-visitor + .pp-message-operator,
|
|
349
|
+
.pp-message-visitor + .pp-message-ai,
|
|
350
|
+
.pp-message-operator + .pp-message-visitor,
|
|
351
|
+
.pp-message-ai + .pp-message-visitor {
|
|
352
|
+
margin-top: 8px;
|
|
325
353
|
}
|
|
326
354
|
|
|
327
355
|
.pp-message-content {
|
|
328
|
-
|
|
356
|
+
display: inline;
|
|
329
357
|
}
|
|
330
358
|
|
|
331
359
|
.pp-message-time {
|
|
332
|
-
font-size:
|
|
333
|
-
opacity: 0.
|
|
334
|
-
display: flex;
|
|
360
|
+
font-size: 10px;
|
|
361
|
+
opacity: 0.6;
|
|
362
|
+
display: inline-flex;
|
|
335
363
|
align-items: center;
|
|
336
|
-
gap:
|
|
364
|
+
gap: 3px;
|
|
365
|
+
float: right;
|
|
366
|
+
margin-left: 8px;
|
|
367
|
+
margin-top: 4px;
|
|
337
368
|
}
|
|
338
369
|
|
|
339
370
|
.pp-ai-badge {
|
|
@@ -370,13 +401,13 @@
|
|
|
370
401
|
|
|
371
402
|
.pp-typing {
|
|
372
403
|
display: flex;
|
|
373
|
-
gap:
|
|
374
|
-
padding:
|
|
404
|
+
gap: 3px;
|
|
405
|
+
padding: 8px 12px;
|
|
375
406
|
}
|
|
376
407
|
|
|
377
408
|
.pp-typing span {
|
|
378
|
-
width:
|
|
379
|
-
height:
|
|
409
|
+
width: 6px;
|
|
410
|
+
height: 6px;
|
|
380
411
|
background: ${s.textSecondary};
|
|
381
412
|
border-radius: 50%;
|
|
382
413
|
animation: pp-bounce 1.4s infinite ease-in-out both;
|
|
@@ -392,14 +423,18 @@
|
|
|
392
423
|
|
|
393
424
|
.pp-input-form {
|
|
394
425
|
display: flex;
|
|
395
|
-
padding: 12px;
|
|
426
|
+
padding: 10px 12px;
|
|
396
427
|
gap: 8px;
|
|
397
428
|
border-top: 1px solid ${s.border};
|
|
429
|
+
align-items: center;
|
|
398
430
|
}
|
|
399
431
|
|
|
400
432
|
.pp-input {
|
|
401
433
|
flex: 1;
|
|
402
|
-
|
|
434
|
+
min-width: 0;
|
|
435
|
+
height: 40px;
|
|
436
|
+
line-height: 40px;
|
|
437
|
+
padding: 0 16px;
|
|
403
438
|
border: 1px solid ${s.border};
|
|
404
439
|
border-radius: 20px;
|
|
405
440
|
background: ${s.bg};
|
|
@@ -407,6 +442,8 @@
|
|
|
407
442
|
font-size: 14px;
|
|
408
443
|
outline: none;
|
|
409
444
|
transition: border-color 0.2s;
|
|
445
|
+
box-sizing: border-box;
|
|
446
|
+
margin: 0;
|
|
410
447
|
}
|
|
411
448
|
|
|
412
449
|
.pp-input:focus {
|
|
@@ -420,6 +457,7 @@
|
|
|
420
457
|
.pp-send-btn {
|
|
421
458
|
width: 40px;
|
|
422
459
|
height: 40px;
|
|
460
|
+
min-width: 40px;
|
|
423
461
|
border-radius: 50%;
|
|
424
462
|
background: ${t};
|
|
425
463
|
color: white;
|
|
@@ -428,7 +466,18 @@
|
|
|
428
466
|
display: flex;
|
|
429
467
|
align-items: center;
|
|
430
468
|
justify-content: center;
|
|
431
|
-
transition: opacity 0.2s;
|
|
469
|
+
transition: opacity 0.2s, transform 0.1s;
|
|
470
|
+
flex-shrink: 0;
|
|
471
|
+
margin: 0;
|
|
472
|
+
padding: 0;
|
|
473
|
+
}
|
|
474
|
+
|
|
475
|
+
.pp-send-btn:not(:disabled):hover {
|
|
476
|
+
transform: scale(1.05);
|
|
477
|
+
}
|
|
478
|
+
|
|
479
|
+
.pp-send-btn:not(:disabled):active {
|
|
480
|
+
transform: scale(0.95);
|
|
432
481
|
}
|
|
433
482
|
|
|
434
483
|
.pp-send-btn:disabled {
|
|
@@ -447,6 +496,7 @@
|
|
|
447
496
|
font-size: 11px;
|
|
448
497
|
color: ${s.textSecondary};
|
|
449
498
|
border-top: 1px solid ${s.border};
|
|
499
|
+
opacity: 0.7;
|
|
450
500
|
}
|
|
451
501
|
|
|
452
502
|
.pp-footer a {
|
|
@@ -475,6 +525,7 @@
|
|
|
475
525
|
.pp-attach-btn {
|
|
476
526
|
width: 40px;
|
|
477
527
|
height: 40px;
|
|
528
|
+
min-width: 40px;
|
|
478
529
|
border-radius: 50%;
|
|
479
530
|
background: transparent;
|
|
480
531
|
color: ${s.textSecondary};
|
|
@@ -483,6 +534,8 @@
|
|
|
483
534
|
display: flex;
|
|
484
535
|
align-items: center;
|
|
485
536
|
justify-content: center;
|
|
537
|
+
margin: 0;
|
|
538
|
+
padding: 0;
|
|
486
539
|
transition: color 0.2s, border-color 0.2s;
|
|
487
540
|
flex-shrink: 0;
|
|
488
541
|
}
|
|
@@ -996,7 +1049,7 @@
|
|
|
996
1049
|
margin-left: 4px;
|
|
997
1050
|
font-style: italic;
|
|
998
1051
|
}
|
|
999
|
-
`}var xn=0;function o(t,e,n,s,i,a){e||(e={});var r,c,u=e;if("ref"in u)for(c in u={},e)c=="ref"?r=e[c]:u[c]=e[c];var l={type:t,props:u,key:n,ref:r,__k:null,__:null,__b:0,__e:null,__c:null,constructor:void 0,__v:--xn,__i:-1,__u:0,__source:i,__self:a};if(typeof t=="function"&&(r=t.defaultProps))for(c in r)u[c]===void 0&&(u[c]=r[c]);return w.vnode&&w.vnode(l),l}function kt({client:t,config:e}){let[n,s]=$(!1),[i,a]=$([]),[r,c]=$(""),[u,l]=$(!1),[g,p]=$(!1),[h,f]=$(!1),[E,A]=$(0),[k,x]=$([]),[b,H]=$(!1),[R,B]=$(null),[N,X]=$(null),[U,F]=$(""),[L,O]=$(null),[z,ge]=$(!1),[Ut,Re]=$(null),[Oe,De]=$(null),[W,he]=$(e),fe=G(null),me=G(null),Le=G(null),zt=G(null);j(()=>{let d=t.on("openChange",s),_=t.on("message",()=>{a([...t.getMessages()])}),T=t.on("typing",m=>{l(m.isTyping)}),v=t.on("presence",m=>{p(m.online)}),S=t.on("connect",()=>{f(!0),a(t.getMessages()),p(t.getSession()?.operatorOnline??!1),he(t.getConfig())}),I=t.on("configUpdate",()=>{he(t.getConfig())});return t.isConnected()&&(f(!0),a(t.getMessages()),p(t.getSession()?.operatorOnline??!1),he(t.getConfig())),()=>{d(),_(),T(),v(),S(),I()}},[t]),j(()=>{n&&fe.current?.scrollIntoView({behavior:"smooth"})},[i,n]),j(()=>{n&&(setTimeout(()=>{fe.current?.scrollIntoView({behavior:"auto"})},50),me.current?.focus(),A(0))},[n]),j(()=>{if(!n&&i.length>0){let d=i.filter(_=>_.sender!=="visitor"&&_.status!=="read").length;A(d)}},[i,n]);let se=ft(()=>{if(!n||!h)return;let d=i.filter(_=>_.sender!=="visitor"&&_.status!=="read");if(d.length>0){let _=d.map(T=>T.id);t.sendReadStatus(_,"read")}},[n,h,i,t]);if(j(()=>{if(!n||!h)return;let d=setTimeout(()=>{se()},1e3);return()=>clearTimeout(d)},[n,h,i,se]),j(()=>{let d=()=>{document.visibilityState==="visible"&&n&&se()};return document.addEventListener("visibilitychange",d),()=>document.removeEventListener("visibilitychange",d)},[n,se]),j(()=>{let d=t.on("read",()=>{a([...t.getMessages()])});return()=>d()},[t]),!yn(W))return null;let Vt=async d=>{d.preventDefault();let _=r.trim().length>0,T=k.filter(m=>m.status==="ready"&&m.attachment);if(!_&&T.length===0)return;let v=r,S=T.map(m=>m.attachment.id),I=R?.id;c(""),x([]),B(null);try{await t.sendMessage(v,S,I)}catch(m){console.error("[PocketPing] Failed to send message:",m)}},jt=d=>{let _=d.target;c(_.value),t.sendTyping(!0)},Bt=async d=>{let _=d.target,T=_.files;if(!T||T.length===0)return;let v=[];for(let S=0;S<T.length;S++){let I=T[S],m=`pending-${Date.now()}-${S}`,P;I.type.startsWith("image/")&&(P=URL.createObjectURL(I)),v.push({id:m,file:I,preview:P,progress:0,status:"pending"})}x(S=>[...S,...v]),_.value="",H(!0);for(let S of v)try{x(m=>m.map(P=>P.id===S.id?{...P,status:"uploading"}:P));let I=await t.uploadFile(S.file,m=>{x(P=>P.map(ve=>ve.id===S.id?{...ve,progress:m}:ve))});x(m=>m.map(P=>P.id===S.id?{...P,status:"ready",progress:100,attachment:I}:P))}catch(I){console.error("[PocketPing] Failed to upload file:",I),x(m=>m.map(P=>P.id===S.id?{...P,status:"error",error:"Upload failed"}:P))}H(!1)},qt=d=>{x(_=>{let T=_.find(v=>v.id===d);return T?.preview&&URL.revokeObjectURL(T.preview),_.filter(v=>v.id!==d)})},He=d=>{B(d),O(null),me.current?.focus()},Jt=()=>{B(null)},Fe=d=>{d.sender==="visitor"&&(X(d),F(d.content),O(null))},We=()=>{X(null),F("")},Xt=async()=>{if(!(!N||!U.trim()))try{await t.editMessage(N.id,U.trim()),X(null),F("")}catch(d){console.error("[PocketPing] Failed to edit message:",d)}},Ne=async d=>{if(d.sender==="visitor"&&(O(null),confirm("Delete this message?")))try{await t.deleteMessage(d.id)}catch(_){console.error("[PocketPing] Failed to delete message:",_)}},Yt=(d,_)=>{d.preventDefault();let T=d;O({message:_,x:T.clientX,y:T.clientY})},Gt=d=>{let _=setTimeout(()=>{navigator.vibrate&&navigator.vibrate(50),O({message:d,x:window.innerWidth/2-60,y:window.innerHeight/2-50})},500);De(_)},Ue=()=>{Oe&&(clearTimeout(Oe),De(null))};j(()=>{if(!L)return;let d=()=>O(null);return document.addEventListener("click",d),()=>document.removeEventListener("click",d)},[L]);let ze=d=>{let _=document.getElementById(`pp-msg-${d}`);_&&(_.scrollIntoView({behavior:"smooth",block:"center"}),_.classList.add("pp-message-highlight"),setTimeout(()=>{_.classList.remove("pp-message-highlight")},1500))},K=G(0),Kt=d=>{d.preventDefault(),d.stopPropagation(),K.current++,K.current===1&&ge(!0)},Qt=d=>{d.preventDefault(),d.stopPropagation()},Zt=d=>{d.preventDefault(),d.stopPropagation(),K.current--,K.current===0&&ge(!1)},en=async d=>{d.preventDefault(),d.stopPropagation(),K.current=0,ge(!1);let _=d.dataTransfer?.files;if(!_||_.length===0)return;let T=[];for(let v=0;v<_.length;v++){let S=_[v],I=`pending-${Date.now()}-${v}`,m;S.type.startsWith("image/")&&(m=URL.createObjectURL(S)),T.push({id:I,file:S,preview:m,progress:0,status:"pending"})}x(v=>[...v,...T]),H(!0);for(let v of T)try{x(I=>I.map(m=>m.id===v.id?{...m,status:"uploading"}:m));let S=await t.uploadFile(v.file,I=>{x(m=>m.map(P=>P.id===v.id?{...P,progress:I}:P))});x(I=>I.map(m=>m.id===v.id?{...m,status:"ready",progress:100,attachment:S}:m))}catch(S){console.error("[PocketPing] Failed to upload dropped file:",S),x(I=>I.map(m=>m.id===v.id?{...m,status:"error",error:"Upload failed"}:m))}H(!1)},Ve=W.position??"bottom-right",_e=bn(W.theme??"auto"),tn=W.primaryColor??"#6366f1",Q=_e==="dark"?"#9ca3af":"#6b7280";return o(D,{children:[o("style",{children:vt(tn,_e)}),o("button",{class:`pp-toggle pp-${Ve}`,onClick:()=>t.toggleOpen(),"aria-label":n?"Close chat":"Open chat",children:[n?o(ne,{}):o(kn,{}),!n&&E>0&&o("span",{class:"pp-unread-badge",children:E>9?"9+":E}),!n&&E===0&&g&&o("span",{class:"pp-online-dot"})]}),n&&o("div",{class:`pp-window pp-${Ve} pp-theme-${_e} ${z?"pp-dragging":""}`,onDragEnter:Kt,onDragOver:Qt,onDragLeave:Zt,onDrop:en,children:[z&&o("div",{class:"pp-drop-overlay",children:[o("div",{class:"pp-drop-icon",children:o(xt,{})}),o("div",{class:"pp-drop-text",children:"Drop files to upload"})]}),o("div",{class:"pp-header",children:[o("div",{class:"pp-header-info",children:[W.operatorAvatar&&o("img",{src:W.operatorAvatar,alt:"",class:"pp-avatar"}),o("div",{children:[o("div",{class:"pp-header-title",children:W.operatorName??"Support"}),o("div",{class:"pp-header-status",children:g?o(D,{children:[o("span",{class:"pp-status-dot pp-online"})," Online"]}):o(D,{children:[o("span",{class:"pp-status-dot"})," Away"]})})]})]}),o("button",{class:"pp-close-btn",onClick:()=>t.setOpen(!1),"aria-label":"Close chat",children:o(ne,{})})]}),o("div",{class:"pp-messages",ref:zt,children:[W.welcomeMessage&&i.length===0&&o("div",{class:"pp-welcome",children:W.welcomeMessage}),i.map(d=>{let _=!!d.deletedAt,T=!!d.editedAt,v=null;if(d.replyTo)if(typeof d.replyTo=="object")v=d.replyTo;else{let m=i.find(P=>P.id===d.replyTo);if(m){let P=!!(m.attachments&&m.attachments.length>0);v={id:m.id,sender:m.sender,content:m.content,deleted:!!m.deletedAt,hasAttachment:P,attachmentType:P?m.attachments[0].mimeType:void 0}}}let I=Ut===d.id&&!_;return o("div",{id:`pp-msg-${d.id}`,class:`pp-message pp-message-${d.sender} ${_?"pp-message-deleted":""}`,onContextMenu:m=>Yt(m,d),onMouseEnter:()=>Re(d.id),onMouseLeave:()=>Re(null),onTouchStart:()=>Gt(d),onTouchEnd:Ue,onTouchCancel:Ue,children:[I&&o("div",{class:`pp-message-actions ${d.sender==="visitor"?"pp-actions-left":"pp-actions-right"}`,children:[o("button",{class:"pp-action-btn",onClick:()=>He(d),title:"Reply",children:o(yt,{color:Q})}),d.sender==="visitor"&&o(D,{children:[o("button",{class:"pp-action-btn",onClick:()=>Fe(d),title:"Edit",children:o(bt,{color:Q})}),o("button",{class:"pp-action-btn pp-action-delete",onClick:()=>Ne(d),title:"Delete",children:o(wt,{color:Q})})]})]}),v&&(v.content||v.hasAttachment)&&o("div",{class:"pp-reply-quote pp-reply-quote-clickable",onClick:()=>ze(v.id),role:"button",tabIndex:0,onKeyDown:m=>m.key==="Enter"&&ze(v.id),children:[o("span",{class:"pp-reply-sender",children:v.sender==="visitor"?"You":"Support"}),o("span",{class:"pp-reply-content",children:v.deleted?"Message deleted":o(D,{children:[v.hasAttachment&&o("span",{class:"pp-reply-attachment-icon",children:v.attachmentType?.startsWith("image/")?"\u{1F4F7} ":"\u{1F4CE} "}),v.content?o(D,{children:[(v.content||"").slice(0,50),(v.content||"").length>50?"...":""]}):v.attachmentType?.startsWith("image/")?"Photo":"File"]})})]}),_?o("div",{class:"pp-message-content pp-deleted-content",children:[o("span",{class:"pp-deleted-icon",children:"\u{1F5D1}\uFE0F"})," Message deleted"]}):o(D,{children:[d.content&&o("div",{class:"pp-message-content",children:d.content}),d.attachments&&d.attachments.length>0&&o("div",{class:"pp-message-attachments",children:d.attachments.map(m=>o(Pn,{attachment:m},m.id))})]}),o("div",{class:"pp-message-time",children:[wn(d.timestamp),T&&!_&&o("span",{class:"pp-edited-badge",children:"edited"}),d.sender==="ai"&&o("span",{class:"pp-ai-badge",children:"AI"}),d.sender==="visitor"&&!_&&o("span",{class:`pp-status pp-status-${d.status??"sent"}`,children:o(Sn,{status:d.status})})]})]},d.id)}),u&&o("div",{class:"pp-message pp-message-operator pp-typing",children:[o("span",{}),o("span",{}),o("span",{})]}),o("div",{ref:fe})]}),L&&o("div",{class:"pp-message-menu",style:{top:`${L.y}px`,left:`${L.x}px`},children:[o("button",{onClick:()=>He(L.message),children:[o(yt,{color:Q})," Reply"]}),L.message.sender==="visitor"&&!L.message.deletedAt&&o(D,{children:[o("button",{onClick:()=>Fe(L.message),children:[o(bt,{color:Q})," Edit"]}),o("button",{class:"pp-menu-delete",onClick:()=>Ne(L.message),children:[o(wt,{color:"#ef4444"})," Delete"]})]})]}),N&&o("div",{class:"pp-edit-modal",children:[o("div",{class:"pp-edit-header",children:[o("span",{children:"Edit message"}),o("button",{onClick:We,children:o(ne,{})})]}),o("textarea",{class:"pp-edit-input",value:U,onInput:d=>F(d.target.value),autoFocus:!0}),o("div",{class:"pp-edit-actions",children:[o("button",{class:"pp-edit-cancel",onClick:We,children:"Cancel"}),o("button",{class:"pp-edit-save",onClick:Xt,disabled:!U.trim(),children:"Save"})]})]}),R&&o("div",{class:"pp-reply-preview",children:[o("div",{class:"pp-reply-preview-content",children:[o("span",{class:"pp-reply-label",children:"Replying to"}),o("span",{class:"pp-reply-text",children:[R.attachments&&R.attachments.length>0&&o("span",{class:"pp-reply-attachment-icon",children:R.attachments[0].mimeType.startsWith("image/")?"\u{1F4F7} ":"\u{1F4CE} "}),R.content?o(D,{children:[R.content.slice(0,50),R.content.length>50?"...":""]}):R.attachments?.[0]?.mimeType.startsWith("image/")?"Photo":"File"]})]}),o("button",{class:"pp-reply-cancel",onClick:Jt,children:o(ne,{})})]}),k.length>0&&o("div",{class:"pp-attachments-preview",children:k.map(d=>o("div",{class:`pp-attachment-preview pp-attachment-${d.status}`,children:[d.preview?o("img",{src:d.preview,alt:d.file.name,class:"pp-preview-img"}):o("div",{class:"pp-preview-file",children:o(Et,{mimeType:d.file.type})}),o("button",{class:"pp-remove-attachment",onClick:()=>qt(d.id),"aria-label":"Remove attachment",type:"button",children:o(ne,{})}),d.status==="uploading"&&o("div",{class:"pp-upload-progress",style:{width:`${d.progress}%`}}),d.status==="error"&&o("div",{class:"pp-upload-error",title:d.error,children:"!"})]},d.id))}),o("form",{class:"pp-input-form",onSubmit:Vt,children:[o("input",{ref:d=>{Le.current=d,d&&(d.onchange=Bt)},type:"file",class:"pp-file-input",accept:"image/*,audio/*,video/*,.pdf,.doc,.docx,.xls,.xlsx,.txt",multiple:!0}),o("button",{type:"button",class:"pp-attach-btn",onClick:()=>Le.current?.click(),disabled:!h||b,"aria-label":"Attach file",children:o(xt,{})}),o("input",{ref:me,type:"text",class:"pp-input",placeholder:W.placeholder??"Type a message...",value:r,onInput:jt,disabled:!h}),o("button",{type:"submit",class:"pp-send-btn",disabled:!r.trim()&&k.filter(d=>d.status==="ready").length===0||!h||b,"aria-label":"Send message",children:o(En,{})})]}),o("div",{class:"pp-footer",children:["Powered by ",o("a",{href:"https://pocketping.io",target:"_blank",rel:"noopener",children:"PocketPing"})]})]})]})}function yn(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 bn(t){return t==="auto"?window.matchMedia("(prefers-color-scheme: dark)").matches?"dark":"light":t}function wn(t){return new Date(t).toLocaleTimeString([],{hour:"2-digit",minute:"2-digit"})}function kn(){return o("svg",{viewBox:"0 0 24 24",fill:"none",stroke:"currentColor","stroke-width":"2",children:o("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 ne(){return o("svg",{viewBox:"0 0 24 24",fill:"none",stroke:"currentColor","stroke-width":"2",children:[o("line",{x1:"18",y1:"6",x2:"6",y2:"18"}),o("line",{x1:"6",y1:"6",x2:"18",y2:"18"})]})}function En(){return o("svg",{viewBox:"0 0 24 24",fill:"none",stroke:"currentColor","stroke-width":"2",children:[o("line",{x1:"22",y1:"2",x2:"11",y2:"13"}),o("polygon",{points:"22 2 15 22 11 13 2 9 22 2"})]})}function Sn({status:t}){return!t||t==="sending"||t==="sent"?o("svg",{viewBox:"0 0 16 16",fill:"none",stroke:"currentColor","stroke-width":"2",class:"pp-check",children:o("polyline",{points:"3 8 7 12 13 4"})}):t==="delivered"?o("svg",{viewBox:"0 0 20 16",fill:"none",stroke:"currentColor","stroke-width":"2",class:"pp-check-double",children:[o("polyline",{points:"1 8 5 12 11 4"}),o("polyline",{points:"7 8 11 12 17 4"})]}):t==="read"?o("svg",{viewBox:"0 0 20 16",fill:"none",stroke:"currentColor","stroke-width":"2",class:"pp-check-double pp-check-read",children:[o("polyline",{points:"1 8 5 12 11 4"}),o("polyline",{points:"7 8 11 12 17 4"})]}):null}function xt(){return o("svg",{viewBox:"0 0 24 24",fill:"none",stroke:"currentColor","stroke-width":"2",children:o("path",{d:"M21.44 11.05l-9.19 9.19a6 6 0 0 1-8.49-8.49l9.19-9.19a4 4 0 0 1 5.66 5.66l-9.2 9.19a2 2 0 0 1-2.83-2.83l8.49-8.48"})})}function yt({color:t,size:e=16}){return o("svg",{viewBox:"0 0 24 24",fill:"none","stroke-width":"2",style:{stroke:t||"currentColor",width:`${e}px`,minWidth:`${e}px`,height:`${e}px`,display:"block",flexShrink:0},children:[o("polyline",{points:"9 17 4 12 9 7"}),o("path",{d:"M20 18v-2a4 4 0 0 0-4-4H4"})]})}function bt({color:t,size:e=16}){return o("svg",{viewBox:"0 0 24 24",fill:"none","stroke-width":"2",style:{stroke:t||"currentColor",width:`${e}px`,minWidth:`${e}px`,height:`${e}px`,display:"block",flexShrink:0},children:o("path",{d:"M17 3a2.828 2.828 0 1 1 4 4L7.5 20.5 2 22l1.5-5.5L17 3z"})})}function wt({color:t,size:e=16}){return o("svg",{viewBox:"0 0 24 24",fill:"none","stroke-width":"2",style:{stroke:t||"currentColor",width:`${e}px`,minWidth:`${e}px`,height:`${e}px`,display:"block",flexShrink:0},children:[o("polyline",{points:"3 6 5 6 21 6"}),o("path",{d:"M19 6v14a2 2 0 0 1-2 2H7a2 2 0 0 1-2-2V6m3 0V4a2 2 0 0 1 2-2h4a2 2 0 0 1 2 2v2"})]})}function Et({mimeType:t}){return t==="application/pdf"?o("svg",{viewBox:"0 0 24 24",fill:"none",stroke:"currentColor","stroke-width":"2",children:[o("path",{d:"M14 2H6a2 2 0 0 0-2 2v16a2 2 0 0 0 2 2h12a2 2 0 0 0 2-2V8z"}),o("polyline",{points:"14 2 14 8 20 8"}),o("path",{d:"M9 15h6"}),o("path",{d:"M9 11h6"})]}):t.startsWith("audio/")?o("svg",{viewBox:"0 0 24 24",fill:"none",stroke:"currentColor","stroke-width":"2",children:[o("path",{d:"M9 18V5l12-2v13"}),o("circle",{cx:"6",cy:"18",r:"3"}),o("circle",{cx:"18",cy:"16",r:"3"})]}):t.startsWith("video/")?o("svg",{viewBox:"0 0 24 24",fill:"none",stroke:"currentColor","stroke-width":"2",children:[o("rect",{x:"2",y:"2",width:"20",height:"20",rx:"2.18",ry:"2.18"}),o("line",{x1:"7",y1:"2",x2:"7",y2:"22"}),o("line",{x1:"17",y1:"2",x2:"17",y2:"22"}),o("line",{x1:"2",y1:"12",x2:"22",y2:"12"}),o("line",{x1:"2",y1:"7",x2:"7",y2:"7"}),o("line",{x1:"2",y1:"17",x2:"7",y2:"17"}),o("line",{x1:"17",y1:"17",x2:"22",y2:"17"}),o("line",{x1:"17",y1:"7",x2:"22",y2:"7"})]}):o("svg",{viewBox:"0 0 24 24",fill:"none",stroke:"currentColor","stroke-width":"2",children:[o("path",{d:"M14 2H6a2 2 0 0 0-2 2v16a2 2 0 0 0 2 2h12a2 2 0 0 0 2-2V8z"}),o("polyline",{points:"14 2 14 8 20 8"})]})}function Pn({attachment:t}){let e=t.mimeType.startsWith("image/"),n=t.mimeType.startsWith("audio/"),s=t.mimeType.startsWith("video/"),i=a=>a<1024?`${a} B`:a<1024*1024?`${(a/1024).toFixed(1)} KB`:`${(a/(1024*1024)).toFixed(1)} MB`;return e?o("a",{href:t.url,target:"_blank",rel:"noopener",class:"pp-attachment pp-attachment-image",children:o("img",{src:t.thumbnailUrl||t.url,alt:t.filename})}):n?o("div",{class:"pp-attachment pp-attachment-audio",children:[o("audio",{controls:!0,preload:"metadata",children:o("source",{src:t.url,type:t.mimeType})}),o("span",{class:"pp-attachment-name",children:t.filename})]}):s?o("div",{class:"pp-attachment pp-attachment-video",children:o("video",{controls:!0,preload:"metadata",children:o("source",{src:t.url,type:t.mimeType})})}):o("a",{href:t.url,target:"_blank",rel:"noopener",class:"pp-attachment pp-attachment-file",children:[o(Et,{mimeType:t.mimeType}),o("div",{class:"pp-attachment-info",children:[o("span",{class:"pp-attachment-name",children:t.filename}),o("span",{class:"pp-attachment-size",children:i(t.size)})]})]})}var de="0.3.6";var ue=class{constructor(e){this.session=null;this.ws=null;this.sse=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.wsConnectedAt=0;this.quickFailureThreshold=2e3;this.connectionMode="none";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(),a=new URLSearchParams(window.location.search).get("pp_inspector"),r=await this.fetch("/connect",{method:"POST",body:JSON.stringify({visitorId:e,sessionId:n,inspectorToken:a||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:r.sessionId,visitorId:r.visitorId,operatorOnline:r.operatorOnline??!1,messages:r.messages??[],identity:r.identity||s||void 0},r.operatorName&&(this.config.operatorName=r.operatorName),r.operatorAvatar&&(this.config.operatorAvatar=r.operatorAvatar),r.primaryColor&&(this.config.primaryColor=r.primaryColor),r.welcomeMessage&&(this.config.welcomeMessage=r.welcomeMessage),this.emit("configUpdate",{operatorName:this.config.operatorName,operatorAvatar:this.config.operatorAvatar,primaryColor:this.config.primaryColor,welcomeMessage:this.config.welcomeMessage}),this.storeSessionId(r.sessionId),this.connectRealtime(),r.inspectorMode?this.enableInspectorMode():r.trackedElements?.length&&this.setupTrackedElements(r.trackedElements),this.emit("connect",this.session),this.config.onConnect?.(r.sessionId),this.session}disconnect(){this.ws&&(this.ws.onclose=null,this.ws.onmessage=null,this.ws.onerror=null,this.ws.onopen=null,this.ws.close(),this.ws=null),this.sse&&(this.sse.close(),this.sse=null),this.session=null,this.connectionMode="none",this.reconnectTimeout&&clearTimeout(this.reconnectTimeout),this.stopPolling(),this.cleanupTrackedElements(),this.disableInspectorMode()}async sendMessage(e,n,s){if(!this.session)throw new Error("Not connected");let i=`temp-${this.generateId()}`,a={id:i,sessionId:this.session.sessionId,content:e,sender:"visitor",timestamp:new Date().toISOString(),status:"sending",replyTo:s};this.session.messages.push(a),this.emit("message",a);try{let r=await this.fetch("/message",{method:"POST",body:JSON.stringify({sessionId:this.session.sessionId,content:e,sender:"visitor",attachmentIds:n||[],replyTo:s})}),c=this.session.messages.findIndex(l=>l.id===i);c>=0&&(this.session.messages[c].id=r.messageId,this.session.messages[c].timestamp=r.timestamp,this.session.messages[c].status="sent",r.attachments&&r.attachments.length>0&&(this.session.messages[c].attachments=r.attachments),this.emit("message",this.session.messages[c]));let u=this.session.messages[c]||{id:r.messageId,sessionId:this.session.sessionId,content:e,sender:"visitor",timestamp:r.timestamp,status:"sent",attachments:r.attachments};return this.config.onMessage?.(u),u}catch(r){let c=this.session.messages.findIndex(u=>u.id===i);throw c>=0&&(this.session.messages.splice(c,1),this.emit("message",a)),r}}async uploadFile(e,n){if(!this.session)throw new Error("Not connected");this.emit("uploadStart",{filename:e.name,size:e.size});try{let s=await this.fetch("/upload",{method:"POST",body:JSON.stringify({sessionId:this.session.sessionId,filename:e.name,mimeType:e.type||"application/octet-stream",size:e.size})});n?.(10),this.emit("uploadProgress",{filename:e.name,progress:10}),await this.uploadToPresignedUrl(s.uploadUrl,e,a=>{let r=10+a*.8;n?.(r),this.emit("uploadProgress",{filename:e.name,progress:r})});let i=await this.fetch("/upload/complete",{method:"POST",body:JSON.stringify({sessionId:this.session.sessionId,attachmentId:s.attachmentId})});return n?.(100),this.emit("uploadComplete",i),{id:i.id,filename:i.filename,mimeType:i.mimeType,size:i.size,url:i.url,thumbnailUrl:i.thumbnailUrl,status:i.status}}catch(s){throw this.emit("uploadError",{filename:e.name,error:s}),s}}async uploadFiles(e,n){let s=[],i=e.length;for(let a=0;a<i;a++){let r=e[a],c=a/i*100,u=100/i,l=await this.uploadFile(r,g=>{let p=c+g/100*u;n?.(p)});s.push(l)}return s}uploadToPresignedUrl(e,n,s){return new Promise((i,a)=>{let r=new XMLHttpRequest;r.upload.addEventListener("progress",c=>{if(c.lengthComputable){let u=c.loaded/c.total*100;s?.(u)}}),r.addEventListener("load",()=>{r.status>=200&&r.status<300?i():a(new Error(`Upload failed with status ${r.status}`))}),r.addEventListener("error",()=>{a(new Error("Upload failed"))}),r.open("PUT",e),r.setRequestHeader("Content-Type",n.type||"application/octet-stream"),r.send(n)})}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 editMessage(e,n){if(!this.session)throw new Error("Not connected");let s=await this.fetch(`/message/${e}`,{method:"PATCH",body:JSON.stringify({sessionId:this.session.sessionId,content:n})}),i=this.session.messages.findIndex(a=>a.id===e);return i>=0&&(this.session.messages[i].content=s.message.content,this.session.messages[i].editedAt=s.message.editedAt,this.emit("messageEdited",this.session.messages[i])),this.session.messages[i]}async deleteMessage(e){if(!this.session)throw new Error("Not connected");let n=await this.fetch(`/message/${e}?sessionId=${encodeURIComponent(this.session.sessionId)}`,{method:"DELETE"});if(n.deleted){let s=this.session.messages.findIndex(i=>i.id===e);s>=0&&(this.session.messages[s].deletedAt=new Date().toISOString(),this.session.messages[s].content="",this.emit("messageDeleted",this.session.messages[s]))}return n.deleted}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}getConfig(){return this.config}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=r=>{let c={...n.data,selector:n.selector,elementText:r.target?.textContent?.trim().slice(0,100),url:window.location.href};this.trigger(n.name,c,{widgetMessage:n.widgetMessage})},a=r=>{r.target?.closest(n.selector)&&i(r)};document.addEventListener(s,a,!0),this.trackedElementCleanups.push(()=>{document.removeEventListener(s,a,!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=`
|
|
1052
|
+
`}var kn=0;function o(t,e,n,s,i,a){e||(e={});var r,d,u=e;if("ref"in u)for(d in u={},e)d=="ref"?r=e[d]:u[d]=e[d];var l={type:t,props:u,key:n,ref:r,__k:null,__:null,__b:0,__e:null,__c:null,constructor:void 0,__v:--kn,__i:-1,__u:0,__source:i,__self:a};if(typeof t=="function"&&(r=t.defaultProps))for(d in r)u[d]===void 0&&(u[d]=r[d]);return w.vnode&&w.vnode(l),l}function Sn(t){let e=new Date,n=new Date(t),s=new Date(e.getFullYear(),e.getMonth(),e.getDate()),i=new Date(n.getFullYear(),n.getMonth(),n.getDate()),a=Math.floor((s.getTime()-i.getTime())/(1e3*60*60*24));return a===0?"Today":a===1?"Yesterday":n.toLocaleDateString("en-US",{month:"short",day:"numeric",year:n.getFullYear()!==e.getFullYear()?"numeric":void 0})}function bt(t){let e=new Date(t);return`${e.getFullYear()}-${e.getMonth()}-${e.getDate()}`}function Pt({client:t,config:e}){let[n,s]=A(!1),[i,a]=A([]),[r,d]=A(""),[u,l]=A(!1),[g,p]=A(!1),[h,f]=A(!1),[T,D]=A(0),[E,_]=A([]),[b,F]=A(!1),[R,q]=A(null),[U,X]=A(null),[z,W]=A(""),[H,O]=A(null),[V,me]=A(!1),[jt,Oe]=A(null),[Le,He]=A(null),[N,_e]=A(e),ve=K(null),xe=K(null),Fe=K(null),Bt=K(null);B(()=>{let c=t.on("openChange",s),v=t.on("message",()=>{a([...t.getMessages()])}),k=t.on("typing",m=>{l(m.isTyping)}),P=t.on("presence",m=>{p(m.online)}),S=t.on("connect",()=>{f(!0),a(t.getMessages()),p(t.getSession()?.operatorOnline??!1),_e(t.getConfig())}),I=t.on("configUpdate",()=>{_e(t.getConfig())});return t.isConnected()&&(f(!0),a(t.getMessages()),p(t.getSession()?.operatorOnline??!1),_e(t.getConfig())),()=>{c(),v(),k(),P(),S(),I()}},[t]),B(()=>{n&&ve.current?.scrollIntoView({behavior:"smooth"})},[i,n]),B(()=>{n&&(setTimeout(()=>{ve.current?.scrollIntoView({behavior:"auto"})},50),xe.current?.focus(),D(0))},[n]),B(()=>{if(!n&&i.length>0){let c=i.filter(v=>v.sender!=="visitor"&&v.status!=="read").length;D(c)}},[i,n]);let ie=_t(()=>{if(!n||!h)return;let c=i.filter(v=>v.sender!=="visitor"&&v.status!=="read");if(c.length>0){let v=c.map(k=>k.id);t.sendReadStatus(v,"read")}},[n,h,i,t]);if(B(()=>{if(!n||!h)return;let c=setTimeout(()=>{ie()},1e3);return()=>clearTimeout(c)},[n,h,i,ie]),B(()=>{let c=()=>{document.visibilityState==="visible"&&n&&ie()};return document.addEventListener("visibilitychange",c),()=>document.removeEventListener("visibilitychange",c)},[n,ie]),B(()=>{let c=t.on("read",()=>{a([...t.getMessages()])});return()=>c()},[t]),!En(N))return null;let qt=async c=>{c.preventDefault();let v=r.trim().length>0,k=E.filter(m=>m.status==="ready"&&m.attachment);if(!v&&k.length===0)return;let P=r,S=k.map(m=>m.attachment.id),I=R?.id;d(""),_([]),q(null);try{await t.sendMessage(P,S,I)}catch(m){console.error("[PocketPing] Failed to send message:",m)}},Jt=c=>{let v=c.target;d(v.value),t.sendTyping(!0)},Yt=async c=>{let v=c.target,k=v.files;if(!k||k.length===0)return;let P=[];for(let S=0;S<k.length;S++){let I=k[S],m=`pending-${Date.now()}-${S}`,x;I.type.startsWith("image/")&&(x=URL.createObjectURL(I)),P.push({id:m,file:I,preview:x,progress:0,status:"pending"})}_(S=>[...S,...P]),v.value="",F(!0);for(let S of P)try{_(m=>m.map(x=>x.id===S.id?{...x,status:"uploading"}:x));let I=await t.uploadFile(S.file,m=>{_(x=>x.map(oe=>oe.id===S.id?{...oe,progress:m}:oe))});_(m=>m.map(x=>x.id===S.id?{...x,status:"ready",progress:100,attachment:I}:x))}catch(I){console.error("[PocketPing] Failed to upload file:",I),_(m=>m.map(x=>x.id===S.id?{...x,status:"error",error:"Upload failed"}:x))}F(!1)},Xt=c=>{_(v=>{let k=v.find(P=>P.id===c);return k?.preview&&URL.revokeObjectURL(k.preview),v.filter(P=>P.id!==c)})},We=c=>{q(c),O(null),xe.current?.focus()},Gt=()=>{q(null)},Ne=c=>{c.sender==="visitor"&&(X(c),W(c.content),O(null))},Ue=()=>{X(null),W("")},Kt=async()=>{if(!(!U||!z.trim()))try{await t.editMessage(U.id,z.trim()),X(null),W("")}catch(c){console.error("[PocketPing] Failed to edit message:",c)}},ze=async c=>{if(c.sender==="visitor"&&(O(null),confirm("Delete this message?")))try{await t.deleteMessage(c.id)}catch(v){console.error("[PocketPing] Failed to delete message:",v)}},Qt=(c,v)=>{c.preventDefault();let k=c;O({message:v,x:k.clientX,y:k.clientY})},Zt=c=>{let v=setTimeout(()=>{navigator.vibrate&&navigator.vibrate(50),O({message:c,x:window.innerWidth/2-60,y:window.innerHeight/2-50})},500);He(v)},Ve=()=>{Le&&(clearTimeout(Le),He(null))};B(()=>{if(!H)return;let c=()=>O(null);return document.addEventListener("click",c),()=>document.removeEventListener("click",c)},[H]);let je=c=>{let v=document.getElementById(`pp-msg-${c}`);v&&(v.scrollIntoView({behavior:"smooth",block:"center"}),v.classList.add("pp-message-highlight"),setTimeout(()=>{v.classList.remove("pp-message-highlight")},1500))},Q=K(0),en=c=>{c.preventDefault(),c.stopPropagation(),Q.current++,Q.current===1&&me(!0)},tn=c=>{c.preventDefault(),c.stopPropagation()},nn=c=>{c.preventDefault(),c.stopPropagation(),Q.current--,Q.current===0&&me(!1)},sn=async c=>{c.preventDefault(),c.stopPropagation(),Q.current=0,me(!1);let v=c.dataTransfer?.files;if(!v||v.length===0)return;let k=[];for(let P=0;P<v.length;P++){let S=v[P],I=`pending-${Date.now()}-${P}`,m;S.type.startsWith("image/")&&(m=URL.createObjectURL(S)),k.push({id:I,file:S,preview:m,progress:0,status:"pending"})}_(P=>[...P,...k]),F(!0);for(let P of k)try{_(I=>I.map(m=>m.id===P.id?{...m,status:"uploading"}:m));let S=await t.uploadFile(P.file,I=>{_(m=>m.map(x=>x.id===P.id?{...x,progress:I}:x))});_(I=>I.map(m=>m.id===P.id?{...m,status:"ready",progress:100,attachment:S}:m))}catch(S){console.error("[PocketPing] Failed to upload dropped file:",S),_(I=>I.map(m=>m.id===P.id?{...m,status:"error",error:"Upload failed"}:m))}F(!1)},Be=N.position??"bottom-right",ye=Pn(N.theme??"auto"),on=N.primaryColor??"#6366f1",Z=ye==="dark"?"#9ca3af":"#6b7280";return o($,{children:[o("style",{children:yt(on,ye)}),o("button",{class:`pp-toggle pp-${Be}`,onClick:()=>t.toggleOpen(),"aria-label":n?"Close chat":"Open chat",children:[n?o(se,{}):o(In,{}),!n&&T>0&&o("span",{class:"pp-unread-badge",children:T>9?"9+":T}),!n&&T===0&&g&&o("span",{class:"pp-online-dot"})]}),n&&o("div",{class:`pp-window pp-${Be} pp-theme-${ye} ${V?"pp-dragging":""}`,onDragEnter:en,onDragOver:tn,onDragLeave:nn,onDrop:sn,children:[V&&o("div",{class:"pp-drop-overlay",children:[o("div",{class:"pp-drop-icon",children:o(wt,{})}),o("div",{class:"pp-drop-text",children:"Drop files to upload"})]}),o("div",{class:"pp-header",children:[o("div",{class:"pp-header-info",children:[N.operatorAvatar&&o("img",{src:N.operatorAvatar,alt:"",class:"pp-avatar"}),o("div",{children:[o("div",{class:"pp-header-title",children:N.operatorName??"Support"}),o("div",{class:"pp-header-status",children:g?o($,{children:[o("span",{class:"pp-status-dot pp-online"})," Online"]}):o($,{children:[o("span",{class:"pp-status-dot"})," Away"]})})]})]}),o("button",{class:"pp-close-btn",onClick:()=>t.setOpen(!1),"aria-label":"Close chat",children:o(se,{})})]}),o("div",{class:"pp-messages",ref:Bt,children:[N.welcomeMessage&&i.length===0&&o("div",{class:"pp-welcome",children:N.welcomeMessage}),i.map((c,v)=>{let k=!!c.deletedAt,P=!!c.editedAt,S=new Date(c.timestamp),I=v>0?i[v-1]:null,m=!I||bt(new Date(I.timestamp))!==bt(S),x=null;if(c.replyTo)if(typeof c.replyTo=="object")x=c.replyTo;else{let L=i.find(re=>re.id===c.replyTo);if(L){let re=!!(L.attachments&&L.attachments.length>0);x={id:L.id,sender:L.sender,content:L.content,deleted:!!L.deletedAt,hasAttachment:re,attachmentType:re?L.attachments[0].mimeType:void 0}}}let rn=jt===c.id&&!k;return o($,{children:[m&&o("div",{class:"pp-date-separator",children:o("span",{children:Sn(S)})}),o("div",{id:`pp-msg-${c.id}`,class:`pp-message pp-message-${c.sender} ${k?"pp-message-deleted":""}`,onContextMenu:L=>Qt(L,c),onMouseEnter:()=>Oe(c.id),onMouseLeave:()=>Oe(null),onTouchStart:()=>Zt(c),onTouchEnd:Ve,onTouchCancel:Ve,children:[rn&&o("div",{class:`pp-message-actions ${c.sender==="visitor"?"pp-actions-left":"pp-actions-right"}`,children:[o("button",{class:"pp-action-btn",onClick:()=>We(c),title:"Reply",children:o(kt,{color:Z})}),c.sender==="visitor"&&o($,{children:[o("button",{class:"pp-action-btn",onClick:()=>Ne(c),title:"Edit",children:o(St,{color:Z})}),o("button",{class:"pp-action-btn pp-action-delete",onClick:()=>ze(c),title:"Delete",children:o(Et,{color:Z})})]})]}),x&&(x.content||x.hasAttachment)&&o("div",{class:"pp-reply-quote pp-reply-quote-clickable",onClick:()=>je(x.id),role:"button",tabIndex:0,onKeyDown:L=>L.key==="Enter"&&je(x.id),children:[o("span",{class:"pp-reply-sender",children:x.sender==="visitor"?"You":"Support"}),o("span",{class:"pp-reply-content",children:x.deleted?"Message deleted":o($,{children:[x.hasAttachment&&o("span",{class:"pp-reply-attachment-icon",children:x.attachmentType?.startsWith("image/")?"\u{1F4F7} ":"\u{1F4CE} "}),x.content?o($,{children:[(x.content||"").slice(0,50),(x.content||"").length>50?"...":""]}):x.attachmentType?.startsWith("image/")?"Photo":"File"]})})]}),k?o("div",{class:"pp-message-content pp-deleted-content",children:[o("span",{class:"pp-deleted-icon",children:"\u{1F5D1}\uFE0F"})," Message deleted"]}):o($,{children:[c.content&&o("div",{class:"pp-message-content",children:c.content}),c.attachments&&c.attachments.length>0&&o("div",{class:"pp-message-attachments",children:c.attachments.map(L=>o($n,{attachment:L},L.id))})]}),o("div",{class:"pp-message-time",children:[Tn(c.timestamp),P&&!k&&o("span",{class:"pp-edited-badge",children:"edited"}),c.sender==="ai"&&o("span",{class:"pp-ai-badge",children:"AI"}),c.sender==="visitor"&&!k&&o("span",{class:`pp-status pp-status-${c.status??"sent"}`,children:o(Cn,{status:c.status})})]})]})]},c.id)}),u&&o("div",{class:"pp-message pp-message-operator pp-typing",children:[o("span",{}),o("span",{}),o("span",{})]}),o("div",{ref:ve})]}),H&&o("div",{class:"pp-message-menu",style:{top:`${H.y}px`,left:`${H.x}px`},children:[o("button",{onClick:()=>We(H.message),children:[o(kt,{color:Z})," Reply"]}),H.message.sender==="visitor"&&!H.message.deletedAt&&o($,{children:[o("button",{onClick:()=>Ne(H.message),children:[o(St,{color:Z})," Edit"]}),o("button",{class:"pp-menu-delete",onClick:()=>ze(H.message),children:[o(Et,{color:"#ef4444"})," Delete"]})]})]}),U&&o("div",{class:"pp-edit-modal",children:[o("div",{class:"pp-edit-header",children:[o("span",{children:"Edit message"}),o("button",{onClick:Ue,children:o(se,{})})]}),o("textarea",{class:"pp-edit-input",value:z,onInput:c=>W(c.target.value),autoFocus:!0}),o("div",{class:"pp-edit-actions",children:[o("button",{class:"pp-edit-cancel",onClick:Ue,children:"Cancel"}),o("button",{class:"pp-edit-save",onClick:Kt,disabled:!z.trim(),children:"Save"})]})]}),R&&o("div",{class:"pp-reply-preview",children:[o("div",{class:"pp-reply-preview-content",children:[o("span",{class:"pp-reply-label",children:"Replying to"}),o("span",{class:"pp-reply-text",children:[R.attachments&&R.attachments.length>0&&o("span",{class:"pp-reply-attachment-icon",children:R.attachments[0].mimeType.startsWith("image/")?"\u{1F4F7} ":"\u{1F4CE} "}),R.content?o($,{children:[R.content.slice(0,50),R.content.length>50?"...":""]}):R.attachments?.[0]?.mimeType.startsWith("image/")?"Photo":"File"]})]}),o("button",{class:"pp-reply-cancel",onClick:Gt,children:o(se,{})})]}),E.length>0&&o("div",{class:"pp-attachments-preview",children:E.map(c=>o("div",{class:`pp-attachment-preview pp-attachment-${c.status}`,children:[c.preview?o("img",{src:c.preview,alt:c.file.name,class:"pp-preview-img"}):o("div",{class:"pp-preview-file",children:o(Tt,{mimeType:c.file.type})}),o("button",{class:"pp-remove-attachment",onClick:()=>Xt(c.id),"aria-label":"Remove attachment",type:"button",children:o(se,{})}),c.status==="uploading"&&o("div",{class:"pp-upload-progress",style:{width:`${c.progress}%`}}),c.status==="error"&&o("div",{class:"pp-upload-error",title:c.error,children:"!"})]},c.id))}),o("form",{class:"pp-input-form",onSubmit:qt,children:[o("input",{ref:c=>{Fe.current=c,c&&(c.onchange=Yt)},type:"file",class:"pp-file-input",accept:"image/*,audio/*,video/*,.pdf,.doc,.docx,.xls,.xlsx,.txt",multiple:!0}),o("button",{type:"button",class:"pp-attach-btn",onClick:()=>Fe.current?.click(),disabled:!h||b,"aria-label":"Attach file",children:o(wt,{})}),o("input",{ref:xe,type:"text",class:"pp-input",placeholder:N.placeholder??"Type a message...",value:r,onInput:Jt,disabled:!h}),o("button",{type:"submit",class:"pp-send-btn",disabled:!r.trim()&&E.filter(c=>c.status==="ready").length===0||!h||b,"aria-label":"Send message",children:o(Mn,{})})]}),o("div",{class:"pp-footer",children:["Powered by ",o("a",{href:"https://pocketping.io",target:"_blank",rel:"noopener",children:"PocketPing"})]})]})]})}function En(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 Pn(t){return t==="auto"?window.matchMedia("(prefers-color-scheme: dark)").matches?"dark":"light":t}function Tn(t){return new Date(t).toLocaleTimeString([],{hour:"2-digit",minute:"2-digit"})}function In(){return o("svg",{viewBox:"0 0 24 24",fill:"none",stroke:"currentColor","stroke-width":"2",children:o("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 se(){return o("svg",{viewBox:"0 0 24 24",fill:"none",stroke:"currentColor","stroke-width":"2",children:[o("line",{x1:"18",y1:"6",x2:"6",y2:"18"}),o("line",{x1:"6",y1:"6",x2:"18",y2:"18"})]})}function Mn(){return o("svg",{viewBox:"0 0 24 24",fill:"none",stroke:"currentColor","stroke-width":"2",children:[o("line",{x1:"22",y1:"2",x2:"11",y2:"13"}),o("polygon",{points:"22 2 15 22 11 13 2 9 22 2"})]})}function Cn({status:t}){return!t||t==="sending"||t==="sent"?o("svg",{viewBox:"0 0 16 16",fill:"none",stroke:"currentColor","stroke-width":"2",class:"pp-check",children:o("polyline",{points:"3 8 7 12 13 4"})}):t==="delivered"?o("svg",{viewBox:"0 0 20 16",fill:"none",stroke:"currentColor","stroke-width":"2",class:"pp-check-double",children:[o("polyline",{points:"1 8 5 12 11 4"}),o("polyline",{points:"7 8 11 12 17 4"})]}):t==="read"?o("svg",{viewBox:"0 0 20 16",fill:"none",stroke:"currentColor","stroke-width":"2",class:"pp-check-double pp-check-read",children:[o("polyline",{points:"1 8 5 12 11 4"}),o("polyline",{points:"7 8 11 12 17 4"})]}):null}function wt(){return o("svg",{viewBox:"0 0 24 24",fill:"none",stroke:"currentColor","stroke-width":"2",children:o("path",{d:"M21.44 11.05l-9.19 9.19a6 6 0 0 1-8.49-8.49l9.19-9.19a4 4 0 0 1 5.66 5.66l-9.2 9.19a2 2 0 0 1-2.83-2.83l8.49-8.48"})})}function kt({color:t,size:e=16}){return o("svg",{viewBox:"0 0 24 24",fill:"none","stroke-width":"2",style:{stroke:t||"currentColor",width:`${e}px`,minWidth:`${e}px`,height:`${e}px`,display:"block",flexShrink:0},children:[o("polyline",{points:"9 17 4 12 9 7"}),o("path",{d:"M20 18v-2a4 4 0 0 0-4-4H4"})]})}function St({color:t,size:e=16}){return o("svg",{viewBox:"0 0 24 24",fill:"none","stroke-width":"2",style:{stroke:t||"currentColor",width:`${e}px`,minWidth:`${e}px`,height:`${e}px`,display:"block",flexShrink:0},children:o("path",{d:"M17 3a2.828 2.828 0 1 1 4 4L7.5 20.5 2 22l1.5-5.5L17 3z"})})}function Et({color:t,size:e=16}){return o("svg",{viewBox:"0 0 24 24",fill:"none","stroke-width":"2",style:{stroke:t||"currentColor",width:`${e}px`,minWidth:`${e}px`,height:`${e}px`,display:"block",flexShrink:0},children:[o("polyline",{points:"3 6 5 6 21 6"}),o("path",{d:"M19 6v14a2 2 0 0 1-2 2H7a2 2 0 0 1-2-2V6m3 0V4a2 2 0 0 1 2-2h4a2 2 0 0 1 2 2v2"})]})}function Tt({mimeType:t}){return t==="application/pdf"?o("svg",{viewBox:"0 0 24 24",fill:"none",stroke:"currentColor","stroke-width":"2",children:[o("path",{d:"M14 2H6a2 2 0 0 0-2 2v16a2 2 0 0 0 2 2h12a2 2 0 0 0 2-2V8z"}),o("polyline",{points:"14 2 14 8 20 8"}),o("path",{d:"M9 15h6"}),o("path",{d:"M9 11h6"})]}):t.startsWith("audio/")?o("svg",{viewBox:"0 0 24 24",fill:"none",stroke:"currentColor","stroke-width":"2",children:[o("path",{d:"M9 18V5l12-2v13"}),o("circle",{cx:"6",cy:"18",r:"3"}),o("circle",{cx:"18",cy:"16",r:"3"})]}):t.startsWith("video/")?o("svg",{viewBox:"0 0 24 24",fill:"none",stroke:"currentColor","stroke-width":"2",children:[o("rect",{x:"2",y:"2",width:"20",height:"20",rx:"2.18",ry:"2.18"}),o("line",{x1:"7",y1:"2",x2:"7",y2:"22"}),o("line",{x1:"17",y1:"2",x2:"17",y2:"22"}),o("line",{x1:"2",y1:"12",x2:"22",y2:"12"}),o("line",{x1:"2",y1:"7",x2:"7",y2:"7"}),o("line",{x1:"2",y1:"17",x2:"7",y2:"17"}),o("line",{x1:"17",y1:"17",x2:"22",y2:"17"}),o("line",{x1:"17",y1:"7",x2:"22",y2:"7"})]}):o("svg",{viewBox:"0 0 24 24",fill:"none",stroke:"currentColor","stroke-width":"2",children:[o("path",{d:"M14 2H6a2 2 0 0 0-2 2v16a2 2 0 0 0 2 2h12a2 2 0 0 0 2-2V8z"}),o("polyline",{points:"14 2 14 8 20 8"})]})}function $n({attachment:t}){let e=t.mimeType.startsWith("image/"),n=t.mimeType.startsWith("audio/"),s=t.mimeType.startsWith("video/"),i=a=>a<1024?`${a} B`:a<1024*1024?`${(a/1024).toFixed(1)} KB`:`${(a/(1024*1024)).toFixed(1)} MB`;return e?o("a",{href:t.url,target:"_blank",rel:"noopener",class:"pp-attachment pp-attachment-image",children:o("img",{src:t.thumbnailUrl||t.url,alt:t.filename})}):n?o("div",{class:"pp-attachment pp-attachment-audio",children:[o("audio",{controls:!0,preload:"metadata",children:o("source",{src:t.url,type:t.mimeType})}),o("span",{class:"pp-attachment-name",children:t.filename})]}):s?o("div",{class:"pp-attachment pp-attachment-video",children:o("video",{controls:!0,preload:"metadata",children:o("source",{src:t.url,type:t.mimeType})})}):o("a",{href:t.url,target:"_blank",rel:"noopener",class:"pp-attachment pp-attachment-file",children:[o(Tt,{mimeType:t.mimeType}),o("div",{class:"pp-attachment-info",children:[o("span",{class:"pp-attachment-name",children:t.filename}),o("span",{class:"pp-attachment-size",children:i(t.size)})]})]})}var he="0.3.7";var fe=class{constructor(e){this.session=null;this.ws=null;this.sse=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.wsConnectedAt=0;this.quickFailureThreshold=2e3;this.connectionMode="none";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(),a=new URLSearchParams(window.location.search).get("pp_inspector"),r=await this.fetch("/connect",{method:"POST",body:JSON.stringify({visitorId:e,sessionId:n,inspectorToken:a||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:r.sessionId,visitorId:r.visitorId,operatorOnline:r.operatorOnline??!1,messages:r.messages??[],identity:r.identity||s||void 0},r.operatorName&&(this.config.operatorName=r.operatorName),r.operatorAvatar&&(this.config.operatorAvatar=r.operatorAvatar),r.primaryColor&&(this.config.primaryColor=r.primaryColor),r.welcomeMessage&&(this.config.welcomeMessage=r.welcomeMessage),this.emit("configUpdate",{operatorName:this.config.operatorName,operatorAvatar:this.config.operatorAvatar,primaryColor:this.config.primaryColor,welcomeMessage:this.config.welcomeMessage}),this.storeSessionId(r.sessionId),this.connectRealtime(),r.inspectorMode?this.enableInspectorMode():r.trackedElements?.length&&this.setupTrackedElements(r.trackedElements),this.emit("connect",this.session),this.config.onConnect?.(r.sessionId),this.session}disconnect(){this.ws&&(this.ws.onclose=null,this.ws.onmessage=null,this.ws.onerror=null,this.ws.onopen=null,this.ws.close(),this.ws=null),this.sse&&(this.sse.close(),this.sse=null),this.session=null,this.connectionMode="none",this.reconnectTimeout&&clearTimeout(this.reconnectTimeout),this.stopPolling(),this.cleanupTrackedElements(),this.disableInspectorMode()}async sendMessage(e,n,s){if(!this.session)throw new Error("Not connected");let i=`temp-${this.generateId()}`,a={id:i,sessionId:this.session.sessionId,content:e,sender:"visitor",timestamp:new Date().toISOString(),status:"sending",replyTo:s};this.session.messages.push(a),this.emit("message",a);try{let r=await this.fetch("/message",{method:"POST",body:JSON.stringify({sessionId:this.session.sessionId,content:e,sender:"visitor",attachmentIds:n||[],replyTo:s})}),d=this.session.messages.findIndex(l=>l.id===i);d>=0&&(this.session.messages[d].id=r.messageId,this.session.messages[d].timestamp=r.timestamp,this.session.messages[d].status="sent",r.attachments&&r.attachments.length>0&&(this.session.messages[d].attachments=r.attachments),this.emit("message",this.session.messages[d]));let u=this.session.messages[d]||{id:r.messageId,sessionId:this.session.sessionId,content:e,sender:"visitor",timestamp:r.timestamp,status:"sent",attachments:r.attachments};return this.config.onMessage?.(u),u}catch(r){let d=this.session.messages.findIndex(u=>u.id===i);throw d>=0&&(this.session.messages.splice(d,1),this.emit("message",a)),r}}async uploadFile(e,n){if(!this.session)throw new Error("Not connected");this.emit("uploadStart",{filename:e.name,size:e.size});try{let s=await this.fetch("/upload",{method:"POST",body:JSON.stringify({sessionId:this.session.sessionId,filename:e.name,mimeType:e.type||"application/octet-stream",size:e.size})});n?.(10),this.emit("uploadProgress",{filename:e.name,progress:10}),await this.uploadToPresignedUrl(s.uploadUrl,e,a=>{let r=10+a*.8;n?.(r),this.emit("uploadProgress",{filename:e.name,progress:r})});let i=await this.fetch("/upload/complete",{method:"POST",body:JSON.stringify({sessionId:this.session.sessionId,attachmentId:s.attachmentId})});return n?.(100),this.emit("uploadComplete",i),{id:i.id,filename:i.filename,mimeType:i.mimeType,size:i.size,url:i.url,thumbnailUrl:i.thumbnailUrl,status:i.status}}catch(s){throw this.emit("uploadError",{filename:e.name,error:s}),s}}async uploadFiles(e,n){let s=[],i=e.length;for(let a=0;a<i;a++){let r=e[a],d=a/i*100,u=100/i,l=await this.uploadFile(r,g=>{let p=d+g/100*u;n?.(p)});s.push(l)}return s}uploadToPresignedUrl(e,n,s){return new Promise((i,a)=>{let r=new XMLHttpRequest;r.upload.addEventListener("progress",d=>{if(d.lengthComputable){let u=d.loaded/d.total*100;s?.(u)}}),r.addEventListener("load",()=>{r.status>=200&&r.status<300?i():a(new Error(`Upload failed with status ${r.status}`))}),r.addEventListener("error",()=>{a(new Error("Upload failed"))}),r.open("PUT",e),r.setRequestHeader("Content-Type",n.type||"application/octet-stream"),r.send(n)})}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 editMessage(e,n){if(!this.session)throw new Error("Not connected");let s=await this.fetch(`/message/${e}`,{method:"PATCH",body:JSON.stringify({sessionId:this.session.sessionId,content:n})}),i=this.session.messages.findIndex(a=>a.id===e);return i>=0&&(this.session.messages[i].content=s.message.content,this.session.messages[i].editedAt=s.message.editedAt,this.emit("messageEdited",this.session.messages[i])),this.session.messages[i]}async deleteMessage(e){if(!this.session)throw new Error("Not connected");let n=await this.fetch(`/message/${e}?sessionId=${encodeURIComponent(this.session.sessionId)}`,{method:"DELETE"});if(n.deleted){let s=this.session.messages.findIndex(i=>i.id===e);s>=0&&(this.session.messages[s].deletedAt=new Date().toISOString(),this.session.messages[s].content="",this.emit("messageDeleted",this.session.messages[s]))}return n.deleted}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}getConfig(){return this.config}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=r=>{let d={...n.data,selector:n.selector,elementText:r.target?.textContent?.trim().slice(0,100),url:window.location.href};this.trigger(n.name,d,{widgetMessage:n.widgetMessage})},a=r=>{r.target?.closest(n.selector)&&i(r)};document.addEventListener(s,a,!0),this.trackedElementCleanups.push(()=>{document.removeEventListener(s,a,!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=`
|
|
1000
1053
|
<style>
|
|
1001
1054
|
#pp-inspector-overlay {
|
|
1002
1055
|
position: fixed;
|
|
@@ -1079,9 +1132,9 @@
|
|
|
1079
1132
|
<button id="pp-inspector-exit">Exit</button>
|
|
1080
1133
|
</div>
|
|
1081
1134
|
<div id="pp-inspector-tooltip"></div>
|
|
1082
|
-
`,document.body.appendChild(e);let n=document.getElementById("pp-inspector-tooltip"),s=null,i=u=>{if(u.id&&!u.id.startsWith("pp-"))return`#${CSS.escape(u.id)}`;let l=Array.from(u.classList).filter(h=>!h.startsWith("pp-"));if(l.length>0){let h="."+l.map(f=>CSS.escape(f)).join(".");if(document.querySelectorAll(h).length===1)return h}for(let h of Array.from(u.attributes))if(h.name.startsWith("data-")&&h.value){let f=`[${h.name}="${CSS.escape(h.value)}"]`;if(document.querySelectorAll(f).length===1)return f}let g=[],p=u;for(;p&&p!==document.body;){let h=p.tagName.toLowerCase();if(p.id&&!p.id.startsWith("pp-")){h=`#${CSS.escape(p.id)}`,g.unshift(h);break}let f=p.parentElement;if(f){let
|
|
1135
|
+
`,document.body.appendChild(e);let n=document.getElementById("pp-inspector-tooltip"),s=null,i=u=>{if(u.id&&!u.id.startsWith("pp-"))return`#${CSS.escape(u.id)}`;let l=Array.from(u.classList).filter(h=>!h.startsWith("pp-"));if(l.length>0){let h="."+l.map(f=>CSS.escape(f)).join(".");if(document.querySelectorAll(h).length===1)return h}for(let h of Array.from(u.attributes))if(h.name.startsWith("data-")&&h.value){let f=`[${h.name}="${CSS.escape(h.value)}"]`;if(document.querySelectorAll(f).length===1)return f}let g=[],p=u;for(;p&&p!==document.body;){let h=p.tagName.toLowerCase();if(p.id&&!p.id.startsWith("pp-")){h=`#${CSS.escape(p.id)}`,g.unshift(h);break}let f=p.parentElement;if(f){let T=p.tagName,D=Array.from(f.children).filter(E=>E.tagName===T);if(D.length>1){let E=D.indexOf(p)+1;h+=`:nth-of-type(${E})`}}g.unshift(h),p=f}return g.join(" > ")},a=u=>{let l=u.target;if(l.closest("#pp-inspector-overlay")||l.closest("#pocketping-widget"))return;s&&s.classList.remove("pp-inspector-highlight"),l.classList.add("pp-inspector-highlight"),s=l;let g=i(l);n.textContent=g,n.style.display="block",n.style.left=`${u.clientX+15}px`,n.style.top=`${u.clientY+15}px`;let p=n.getBoundingClientRect();p.right>window.innerWidth&&(n.style.left=`${u.clientX-p.width-15}px`),p.bottom>window.innerHeight&&(n.style.top=`${u.clientY-p.height-15}px`)},r=u=>{let l=u.target;l.closest("#pp-inspector-overlay")||(l.classList.remove("pp-inspector-highlight"),n.style.display="none")},d=u=>{let l=u.target;if(l.id==="pp-inspector-exit"){this.disableInspectorMode();return}if(l.closest("#pp-inspector-overlay")||l.closest("#pocketping-widget"))return;u.preventDefault(),u.stopPropagation();let g=i(l);this.ws&&this.ws.readyState===WebSocket.OPEN&&this.ws.send(JSON.stringify({type:"inspector_select",data:{selector:g,tagName:l.tagName.toLowerCase(),text:l.textContent?.trim().slice(0,50)||"",url:window.location.href}})),this.emit("inspectorSelect",{selector:g,element:l}),l.classList.remove("pp-inspector-highlight"),l.classList.add("pp-inspector-highlight"),setTimeout(()=>{l.classList.remove("pp-inspector-highlight")},500);let p=document.getElementById("pp-inspector-banner");if(p){let h=p.innerHTML;p.innerHTML=`
|
|
1083
1136
|
<svg width="20" height="20" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2">
|
|
1084
1137
|
<polyline points="20 6 9 17 4 12"/>
|
|
1085
1138
|
</svg>
|
|
1086
1139
|
<span>Selector captured: <code style="background:rgba(255,255,255,0.2);padding:2px 6px;border-radius:4px;font-family:monospace;">${g}</code></span>
|
|
1087
|
-
`,setTimeout(()=>{p&&this.inspectorMode&&(p.innerHTML=h,document.getElementById("pp-inspector-exit")?.addEventListener("click",()=>{this.disableInspectorMode()}))},2e3)}console.info(`[PocketPing] \u{1F4CC} Selector captured: ${g}`)};document.addEventListener("mouseover",a,!0),document.addEventListener("mouseout",r,!0),document.addEventListener("click",c,!0),this.inspectorCleanup=()=>{document.removeEventListener("mouseover",a,!0),document.removeEventListener("mouseout",r,!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}connectRealtime(){if(this.session){if(this.connectionMode==="polling"){this.startPolling();return}if(this.connectionMode==="sse"){this.connectSSE();return}this.connectWebSocket()}}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.wsConnectedAt=Date.now();let n=setTimeout(()=>{console.warn("[PocketPing] \u23F1\uFE0F WebSocket timeout - trying SSE"),this.ws&&this.ws.readyState!==WebSocket.OPEN&&(this.ws.onclose=null,this.ws.onerror=null,this.ws.onopen=null,this.ws.close(),this.ws=null,this.connectSSE())},5e3);this.ws.onopen=()=>{clearTimeout(n),this.connectionMode="ws",this.reconnectAttempts=0,this.wsConnectedAt=Date.now(),this.emit("wsConnected",null)},this.ws.onmessage=s=>{try{let i=JSON.parse(s.data);this.handleRealtimeEvent(i)}catch(i){console.error("[PocketPing] Failed to parse WS message:",i)}},this.ws.onclose=()=>{clearTimeout(n),this.emit("wsDisconnected",null),this.handleWsFailure()},this.ws.onerror=()=>{clearTimeout(n)}}catch{console.warn("[PocketPing] WebSocket unavailable - trying SSE"),this.connectSSE()}}connectSSE(){if(!this.session)return;let e=new URLSearchParams({sessionId:this.session.sessionId}),n=this.getLastEventTimestamp();n&&e.set("after",n);let s=this.config.endpoint.replace(/\/$/,"")+`/stream?${e.toString()}`;try{this.sse=new EventSource(s);let i=setTimeout(()=>{console.warn("[PocketPing] \u23F1\uFE0F SSE timeout - falling back to polling"),this.sse&&this.sse.readyState!==EventSource.OPEN&&(this.sse.close(),this.sse=null,this.connectionMode="polling",this.startPolling())},5e3);this.sse.onopen=()=>{clearTimeout(i),this.connectionMode="sse",this.emit("sseConnected",null)},this.sse.addEventListener("message",a=>{try{let r=JSON.parse(a.data);this.handleRealtimeEvent(r)}catch(r){console.error("[PocketPing] Failed to parse SSE message:",r)}}),this.sse.addEventListener("connected",()=>{}),this.sse.onerror=()=>{clearTimeout(i),console.warn("[PocketPing] \u274C SSE error - falling back to polling"),this.sse&&(this.sse.close(),this.sse=null),this.connectionMode="polling",this.startPolling()}}catch{console.warn("[PocketPing] SSE unavailable - falling back to polling"),this.connectionMode="polling",this.startPolling()}}handleWsFailure(){if(Date.now()-this.wsConnectedAt<this.quickFailureThreshold){console.info("[PocketPing] WebSocket failed quickly - trying SSE"),this.connectSSE();return}this.scheduleReconnect()}handleRealtimeEvent(e){this.handleWebSocketEvent(e)}getLastEventTimestamp(){if(!this.session)return null;let e=null;for(let n of this.session.messages){let s=[n.timestamp,n.editedAt,n.deletedAt,n.deliveredAt,n.readAt].filter(Boolean).map(i=>new Date(i)).filter(i=>!isNaN(i.getTime()));for(let i of s)(!e||i>e)&&(e=i)}return e?e.toISOString():null}handleWebSocketEvent(e){switch(e.type){case"message":let n=e.data;if(this.session){let u=this.session.messages.findIndex(l=>l.id===n.id);if(u<0&&n.sender==="visitor"&&(u=this.session.messages.findIndex(l=>l.id.startsWith("temp-")&&l.content===n.content&&l.sender==="visitor"),u>=0&&(this.session.messages[u].id=n.id)),u<0&&n.sender!=="visitor"){let l=new Date(n.timestamp).getTime();u=this.session.messages.findIndex(g=>g.sender===n.sender&&g.content===n.content&&Math.abs(new Date(g.timestamp).getTime()-l)<2e3)}if(u>=0){let l=this.session.messages[u],g=!1;n.status&&n.status!==l.status&&(l.status=n.status,g=!0,n.deliveredAt&&(l.deliveredAt=n.deliveredAt),n.readAt&&(l.readAt=n.readAt),this.emit("read",{messageIds:[n.id],status:n.status})),n.content!==void 0&&n.content!==l.content&&(l.content=n.content,g=!0),n.editedAt!==void 0&&n.editedAt!==l.editedAt&&(l.editedAt=n.editedAt,g=!0),n.deletedAt!==void 0&&n.deletedAt!==l.deletedAt&&(l.deletedAt=n.deletedAt,g=!0),n.replyTo!==void 0&&(l.replyTo=n.replyTo,g=!0),n.attachments!==void 0&&(l.attachments=n.attachments,g=!0),g&&this.emit("message",l)}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 u of this.session.messages)i.messageIds.includes(u.id)&&(u.status=i.status,i.deliveredAt&&(u.deliveredAt=i.deliveredAt),i.readAt&&(u.readAt=i.readAt));this.emit("read",i);break;case"message_edited":if(this.session){let u=e.data,l=this.session.messages.findIndex(g=>g.id===u.messageId);if(l>=0){let g=this.session.messages[l];g.content=u.content,g.editedAt=u.editedAt??new Date().toISOString(),this.emit("message",g)}}break;case"message_deleted":if(this.session){let u=e.data,l=this.session.messages.findIndex(g=>g.id===u.messageId);if(l>=0){let g=this.session.messages[l];g.deletedAt=u.deletedAt??new Date().toISOString(),this.emit("message",g)}}break;case"event":let a=e.data;this.emitCustomEvent(a);break;case"version_warning":let r=e.data;this.handleVersionWarning(r);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, trying SSE"),this.connectSSE();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.getLastEventTimestamp(),s=await this.fetchMessages(n??void 0);this.pollingFailures=0;for(let i of s){let a=this.session.messages.findIndex(r=>r.id===i.id);if(a>=0){let r=this.session.messages[a],c=!1;i.status&&i.status!==r.status&&(r.status=i.status,c=!0,i.deliveredAt&&(r.deliveredAt=i.deliveredAt),i.readAt&&(r.readAt=i.readAt),this.emit("read",{messageIds:[i.id],status:i.status})),i.content!==void 0&&i.content!==r.content&&(r.content=i.content,c=!0),i.editedAt!==void 0&&i.editedAt!==r.editedAt&&(r.editedAt=i.editedAt,c=!0),i.deletedAt!==void 0&&i.deletedAt!==r.deletedAt&&(r.deletedAt=i.deletedAt,c=!0),i.replyTo!==void 0&&(r.replyTo=i.replyTo,c=!0),i.attachments!==void 0&&(r.attachments=i.attachments,c=!0),c&&this.emit("message",r)}else this.session.messages.push(i),this.emit("message",i),this.config.onMessage?.(i)}}catch(n){if(this.pollingFailures++,console.error("[PocketPing] \u274C Polling error:",n),(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(2e3*Math.pow(2,this.pollingFailures-1),3e4):2e3;this.pollingTimeout=setTimeout(e,n)}}};this.pollingTimeout=setTimeout(e,500)}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":de,...n.headers}});if(this.checkVersionHeaders(i),!i.ok){let a=await i.text();throw new Error(`PocketPing API error: ${i.status} ${a}`)}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"),a=e.headers.get("X-PocketPing-Version-Message");if(!n||n==="ok")return;let r="info",c=!0;n==="deprecated"?r="warning":n==="unsupported"?(r="error",c=!1):n==="outdated"&&(r="info");let u={severity:r,message:a||`Widget version ${de} is ${n}`,currentVersion:de,minVersion:s||void 0,latestVersion:i||void 0,canContinue:c,upgradeUrl:"https://docs.pocketping.io/widget/installation"};this.handleVersionWarning(u)}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,q=null,Tn="https://app.pocketping.io/api/widget";function Ae(t){if(y)return console.warn("[PocketPing] Already initialized"),y;let e=t.endpoint;if(!e&&t.projectId&&(e=`${Tn}/${t.projectId}`),!e)throw new Error("[PocketPing] endpoint or projectId is required");let n={...t,endpoint:e};return y=new ue(n),q=document.createElement("div"),q.id="pocketping-container",document.body.appendChild(q),Ie(Se(kt,{client:y,config:t}),q),y.connect().catch(s=>{console.error("[PocketPing] Failed to connect:",s)}),y}function St(){q&&(Ie(null,q),q.remove(),q=null),y&&(y.disconnect(),y=null)}function Pt(){y?.setOpen(!0)}function Tt(){y?.setOpen(!1)}function It(){y?.toggleOpen()}function Mt(t,e){if(!y)throw new Error("[PocketPing] Not initialized");return y.sendMessage(t,e)}async function Ct(t,e){if(!y)throw new Error("[PocketPing] Not initialized");return y.uploadFile(t,e)}async function $t(t,e){if(!y)throw new Error("[PocketPing] Not initialized");return y.uploadFiles(t,e)}function At(t,e,n){if(!y){console.warn("[PocketPing] Not initialized, cannot trigger event");return}y.trigger(t,e,n)}function Rt(t){if(!y){console.warn("[PocketPing] Not initialized, cannot setup tracked elements");return}y.setupTrackedElements(t)}function Ot(){return y?.getTrackedElements()||[]}function Dt(t,e){return y?y.onEvent(t,e):(console.warn("[PocketPing] Not initialized, cannot subscribe to event"),()=>{})}function Lt(t,e){y?.offEvent(t,e)}async function Ht(t){if(!y)throw new Error("[PocketPing] Not initialized");return y.identify(t)}async function Ft(t){if(!y){console.warn("[PocketPing] Not initialized");return}return y.reset(t)}function Wt(){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)&&Ae({projectId:e,endpoint:n,theme:t.dataset.theme||"auto",position:t.dataset.position||"bottom-right"})}}var In={init:Ae,destroy:St,open:Pt,close:Tt,toggle:It,sendMessage:Mt,uploadFile:Ct,uploadFiles:$t,trigger:At,onEvent:Dt,offEvent:Lt,on:Nt,identify:Ht,reset:Ft,getIdentity:Wt,setupTrackedElements:Rt,getTrackedElements:Ot};return pn(Mn);})();
|
|
1140
|
+
`,setTimeout(()=>{p&&this.inspectorMode&&(p.innerHTML=h,document.getElementById("pp-inspector-exit")?.addEventListener("click",()=>{this.disableInspectorMode()}))},2e3)}console.info(`[PocketPing] \u{1F4CC} Selector captured: ${g}`)};document.addEventListener("mouseover",a,!0),document.addEventListener("mouseout",r,!0),document.addEventListener("click",d,!0),this.inspectorCleanup=()=>{document.removeEventListener("mouseover",a,!0),document.removeEventListener("mouseout",r,!0),document.removeEventListener("click",d,!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}connectRealtime(){if(this.session){if(this.connectionMode==="polling"){this.startPolling();return}if(this.connectionMode==="sse"){this.connectSSE();return}this.connectWebSocket()}}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.wsConnectedAt=Date.now();let n=setTimeout(()=>{console.warn("[PocketPing] \u23F1\uFE0F WebSocket timeout - trying SSE"),this.ws&&this.ws.readyState!==WebSocket.OPEN&&(this.ws.onclose=null,this.ws.onerror=null,this.ws.onopen=null,this.ws.close(),this.ws=null,this.connectSSE())},5e3);this.ws.onopen=()=>{clearTimeout(n),this.connectionMode="ws",this.reconnectAttempts=0,this.wsConnectedAt=Date.now(),this.emit("wsConnected",null)},this.ws.onmessage=s=>{try{let i=JSON.parse(s.data);this.handleRealtimeEvent(i)}catch(i){console.error("[PocketPing] Failed to parse WS message:",i)}},this.ws.onclose=()=>{clearTimeout(n),this.emit("wsDisconnected",null),this.handleWsFailure()},this.ws.onerror=()=>{clearTimeout(n)}}catch{console.warn("[PocketPing] WebSocket unavailable - trying SSE"),this.connectSSE()}}connectSSE(){if(!this.session)return;let e=new URLSearchParams({sessionId:this.session.sessionId}),n=this.getLastEventTimestamp();n&&e.set("after",n);let s=this.config.endpoint.replace(/\/$/,"")+`/stream?${e.toString()}`;try{this.sse=new EventSource(s);let i=setTimeout(()=>{console.warn("[PocketPing] \u23F1\uFE0F SSE timeout - falling back to polling"),this.sse&&this.sse.readyState!==EventSource.OPEN&&(this.sse.close(),this.sse=null,this.connectionMode="polling",this.startPolling())},5e3);this.sse.onopen=()=>{clearTimeout(i),this.connectionMode="sse",this.emit("sseConnected",null)},this.sse.addEventListener("message",a=>{try{let r=JSON.parse(a.data);this.handleRealtimeEvent(r)}catch(r){console.error("[PocketPing] Failed to parse SSE message:",r)}}),this.sse.addEventListener("connected",()=>{}),this.sse.onerror=()=>{clearTimeout(i),console.warn("[PocketPing] \u274C SSE error - falling back to polling"),this.sse&&(this.sse.close(),this.sse=null),this.connectionMode="polling",this.startPolling()}}catch{console.warn("[PocketPing] SSE unavailable - falling back to polling"),this.connectionMode="polling",this.startPolling()}}handleWsFailure(){if(Date.now()-this.wsConnectedAt<this.quickFailureThreshold){console.info("[PocketPing] WebSocket failed quickly - trying SSE"),this.connectSSE();return}this.scheduleReconnect()}handleRealtimeEvent(e){this.handleWebSocketEvent(e)}getLastEventTimestamp(){if(!this.session)return null;let e=null;for(let n of this.session.messages){let s=[n.timestamp,n.editedAt,n.deletedAt,n.deliveredAt,n.readAt].filter(Boolean).map(i=>new Date(i)).filter(i=>!isNaN(i.getTime()));for(let i of s)(!e||i>e)&&(e=i)}return e?e.toISOString():null}handleWebSocketEvent(e){switch(e.type){case"message":let n=e.data;if(this.session){let u=this.session.messages.findIndex(l=>l.id===n.id);if(u<0&&n.sender==="visitor"&&(u=this.session.messages.findIndex(l=>l.id.startsWith("temp-")&&l.content===n.content&&l.sender==="visitor"),u>=0&&(this.session.messages[u].id=n.id)),u<0&&n.sender!=="visitor"){let l=new Date(n.timestamp).getTime();u=this.session.messages.findIndex(g=>g.sender===n.sender&&g.content===n.content&&Math.abs(new Date(g.timestamp).getTime()-l)<2e3)}if(u>=0){let l=this.session.messages[u],g=!1;n.status&&n.status!==l.status&&(l.status=n.status,g=!0,n.deliveredAt&&(l.deliveredAt=n.deliveredAt),n.readAt&&(l.readAt=n.readAt),this.emit("read",{messageIds:[n.id],status:n.status})),n.content!==void 0&&n.content!==l.content&&(l.content=n.content,g=!0),n.editedAt!==void 0&&n.editedAt!==l.editedAt&&(l.editedAt=n.editedAt,g=!0),n.deletedAt!==void 0&&n.deletedAt!==l.deletedAt&&(l.deletedAt=n.deletedAt,g=!0),n.replyTo!==void 0&&(l.replyTo=n.replyTo,g=!0),n.attachments!==void 0&&(l.attachments=n.attachments,g=!0),g&&this.emit("message",l)}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 u of this.session.messages)i.messageIds.includes(u.id)&&(u.status=i.status,i.deliveredAt&&(u.deliveredAt=i.deliveredAt),i.readAt&&(u.readAt=i.readAt));this.emit("read",i);break;case"message_edited":if(this.session){let u=e.data,l=this.session.messages.findIndex(g=>g.id===u.messageId);if(l>=0){let g=this.session.messages[l];g.content=u.content,g.editedAt=u.editedAt??new Date().toISOString(),this.emit("message",g)}}break;case"message_deleted":if(this.session){let u=e.data,l=this.session.messages.findIndex(g=>g.id===u.messageId);if(l>=0){let g=this.session.messages[l];g.deletedAt=u.deletedAt??new Date().toISOString(),this.emit("message",g)}}break;case"event":let a=e.data;this.emitCustomEvent(a);break;case"version_warning":let r=e.data;this.handleVersionWarning(r);break;case"config_update":let d=e.data;d.trackedElements&&(this.setupTrackedElements(d.trackedElements),this.emit("configUpdate",d));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, trying SSE"),this.connectSSE();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.getLastEventTimestamp(),s=await this.fetchMessages(n??void 0);this.pollingFailures=0;for(let i of s){let a=this.session.messages.findIndex(r=>r.id===i.id);if(a>=0){let r=this.session.messages[a],d=!1;i.status&&i.status!==r.status&&(r.status=i.status,d=!0,i.deliveredAt&&(r.deliveredAt=i.deliveredAt),i.readAt&&(r.readAt=i.readAt),this.emit("read",{messageIds:[i.id],status:i.status})),i.content!==void 0&&i.content!==r.content&&(r.content=i.content,d=!0),i.editedAt!==void 0&&i.editedAt!==r.editedAt&&(r.editedAt=i.editedAt,d=!0),i.deletedAt!==void 0&&i.deletedAt!==r.deletedAt&&(r.deletedAt=i.deletedAt,d=!0),i.replyTo!==void 0&&(r.replyTo=i.replyTo,d=!0),i.attachments!==void 0&&(r.attachments=i.attachments,d=!0),d&&this.emit("message",r)}else this.session.messages.push(i),this.emit("message",i),this.config.onMessage?.(i)}}catch(n){if(this.pollingFailures++,console.error("[PocketPing] \u274C Polling error:",n),(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(2e3*Math.pow(2,this.pollingFailures-1),3e4):2e3;this.pollingTimeout=setTimeout(e,n)}}};this.pollingTimeout=setTimeout(e,500)}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":he,...n.headers}});if(this.checkVersionHeaders(i),!i.ok){let a=await i.text();throw new Error(`PocketPing API error: ${i.status} ${a}`)}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"),a=e.headers.get("X-PocketPing-Version-Message");if(!n||n==="ok")return;let r="info",d=!0;n==="deprecated"?r="warning":n==="unsupported"?(r="error",d=!1):n==="outdated"&&(r="info");let u={severity:r,message:a||`Widget version ${he} is ${n}`,currentVersion:he,minVersion:s||void 0,latestVersion:i||void 0,canContinue:d,upgradeUrl:"https://docs.pocketping.io/widget/installation"};this.handleVersionWarning(u)}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,J=null,An="https://app.pocketping.io/api/widget";function Re(t){if(y)return console.warn("[PocketPing] Already initialized"),y;let e=t.endpoint;if(!e&&t.projectId&&(e=`${An}/${t.projectId}`),!e)throw new Error("[PocketPing] endpoint or projectId is required");let n={...t,endpoint:e};return y=new fe(n),J=document.createElement("div"),J.id="pocketping-container",document.body.appendChild(J),Ce(Te(Pt,{client:y,config:t}),J),y.connect().catch(s=>{console.error("[PocketPing] Failed to connect:",s)}),y}function It(){J&&(Ce(null,J),J.remove(),J=null),y&&(y.disconnect(),y=null)}function Mt(){y?.setOpen(!0)}function Ct(){y?.setOpen(!1)}function $t(){y?.toggleOpen()}function At(t,e){if(!y)throw new Error("[PocketPing] Not initialized");return y.sendMessage(t,e)}async function Dt(t,e){if(!y)throw new Error("[PocketPing] Not initialized");return y.uploadFile(t,e)}async function Rt(t,e){if(!y)throw new Error("[PocketPing] Not initialized");return y.uploadFiles(t,e)}function Ot(t,e,n){if(!y){console.warn("[PocketPing] Not initialized, cannot trigger event");return}y.trigger(t,e,n)}function Lt(t){if(!y){console.warn("[PocketPing] Not initialized, cannot setup tracked elements");return}y.setupTrackedElements(t)}function Ht(){return y?.getTrackedElements()||[]}function Ft(t,e){return y?y.onEvent(t,e):(console.warn("[PocketPing] Not initialized, cannot subscribe to event"),()=>{})}function Wt(t,e){y?.offEvent(t,e)}async function Nt(t){if(!y)throw new Error("[PocketPing] Not initialized");return y.identify(t)}async function Ut(t){if(!y){console.warn("[PocketPing] Not initialized");return}return y.reset(t)}function zt(){return y?.getIdentity()||null}function Vt(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)&&Re({projectId:e,endpoint:n,theme:t.dataset.theme||"auto",position:t.dataset.position||"bottom-right"})}}var Dn={init:Re,destroy:It,open:Mt,close:Ct,toggle:$t,sendMessage:At,uploadFile:Dt,uploadFiles:Rt,trigger:Ot,onEvent:Ft,offEvent:Wt,on:Vt,identify:Nt,reset:Ut,getIdentity:zt,setupTrackedElements:Lt,getTrackedElements:Ht};return un(Rn);})();
|