@pocketping/widget 1.0.2 → 1.2.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 +1259 -113
- package/dist/index.d.cts +80 -4
- package/dist/index.d.ts +80 -4
- package/dist/index.js +1256 -112
- package/dist/pocketping.min.global.js +493 -7
- package/package.json +10 -3
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
"use strict";var PocketPing=(()=>{var te=Object.defineProperty;var pt=Object.getOwnPropertyDescriptor;var dt=Object.getOwnPropertyNames;var ut=Object.prototype.hasOwnProperty;var gt=(t,e)=>{for(var n in e)te(t,n,{get:e[n],enumerable:!0})},_t=(t,e,n,s)=>{if(e&&typeof e=="object"||typeof e=="function")for(let i of dt(e))!ut.call(t,i)&&i!==n&&te(t,i,{get:()=>e[i],enumerable:!(s=pt(e,i))||s.enumerable});return t};var ft=t=>_t(te({},"__esModule",{value:!0}),t);var Rt={};gt(Rt,{close:()=>Ge,default:()=>Ht,destroy:()=>Je,getIdentity:()=>ot,getTrackedElements:()=>et,identify:()=>st,init:()=>fe,offEvent:()=>nt,on:()=>rt,onEvent:()=>tt,open:()=>Xe,reset:()=>it,sendMessage:()=>Ze,setupTrackedElements:()=>Qe,toggle:()=>Ye,trigger:()=>Ke});var G,y,be,ht,N,he,xe,ke,we,oe,ne,se,mt,U={},Pe=[],vt=/acit|ex(?:s|g|n|p|$)|rph|grid|ows|mnc|ntw|ine[ch]|zoo|^ord|itera/i,Y=Array.isArray;function T(t,e){for(var n in e)t[n]=e[n];return t}function re(t){t&&t.parentNode&&t.parentNode.removeChild(t)}function ae(t,e,n){var s,i,o,a={};for(o in e)o=="key"?s=e[o]:o=="ref"?i=e[o]:a[o]=e[o];if(arguments.length>2&&(a.children=arguments.length>3?G.call(arguments,2):n),typeof t=="function"&&t.defaultProps!=null)for(o in t.defaultProps)a[o]===void 0&&(a[o]=t.defaultProps[o]);return q(t,a,s,i,null)}function q(t,e,n,s,i){var o={type:t,props:e,key:n,ref:s,__k:null,__:null,__b:0,__e:null,__c:null,constructor:void 0,__v:i??++be,__i:-1,__u:0};return i==null&&y.vnode!=null&&y.vnode(o),o}function I(t){return t.children}function J(t,e){this.props=t,this.context=e}function L(t,e){if(e==null)return t.__?L(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"?L(t):null}function Se(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 Se(t)}}function me(t){(!t.__d&&(t.__d=!0)&&N.push(t)&&!X.__r++||he!=y.debounceRendering)&&((he=y.debounceRendering)||xe)(X)}function X(){for(var t,e,n,s,i,o,a,c=1;N.length;)N.length>c&&N.sort(ke),t=N.shift(),c=N.length,t.__d&&(n=void 0,s=void 0,i=(s=(e=t).__v).__e,o=[],a=[],e.__P&&((n=T({},s)).__v=s.__v+1,y.vnode&&y.vnode(n),le(e.__P,n,s,e.__n,e.__P.namespaceURI,32&s.__u?[i]:null,o,i??L(s),!!(32&s.__u),a),n.__v=s.__v,n.__.__k[n.__i]=n,Ie(o,n,a),s.__e=s.__=null,n.__e!=i&&Se(n)));X.__r=0}function Ee(t,e,n,s,i,o,a,c,p,l,g){var r,d,_,x,S,h,v,m=s&&s.__k||Pe,C=e.length;for(p=yt(n,e,m,p,C),r=0;r<C;r++)(_=n.__k[r])!=null&&(d=_.__i==-1?U:m[_.__i]||U,_.__i=r,h=le(t,_,d,i,o,a,c,p,l,g),x=_.__e,_.ref&&d.ref!=_.ref&&(d.ref&&ce(d.ref,null,_),g.push(_.ref,_.__c||x,_)),S==null&&x!=null&&(S=x),(v=!!(4&_.__u))||d.__k===_.__k?p=Ce(_,p,t,v):typeof _.type=="function"&&h!==void 0?p=h:x&&(p=x.nextSibling),_.__u&=-7);return n.__e=S,p}function yt(t,e,n,s,i){var o,a,c,p,l,g=n.length,r=g,d=0;for(t.__k=new Array(i),o=0;o<i;o++)(a=e[o])!=null&&typeof a!="boolean"&&typeof a!="function"?(typeof a=="string"||typeof a=="number"||typeof a=="bigint"||a.constructor==String?a=t.__k[o]=q(null,a,null,null,null):Y(a)?a=t.__k[o]=q(I,{children:a},null,null,null):a.constructor===void 0&&a.__b>0?a=t.__k[o]=q(a.type,a.props,a.key,a.ref?a.ref:null,a.__v):t.__k[o]=a,p=o+d,a.__=t,a.__b=t.__b+1,c=null,(l=a.__i=bt(a,n,p,r))!=-1&&(r--,(c=n[l])&&(c.__u|=2)),c==null||c.__v==null?(l==-1&&(i>g?d--:i<g&&d++),typeof a.type!="function"&&(a.__u|=4)):l!=p&&(l==p-1?d--:l==p+1?d++:(l>p?d--:d++,a.__u|=4))):t.__k[o]=null;if(r)for(o=0;o<g;o++)(c=n[o])!=null&&(2&c.__u)==0&&(c.__e==s&&(s=L(c)),Me(c,c));return s}function Ce(t,e,n,s){var i,o;if(typeof t.type=="function"){for(i=t.__k,o=0;i&&o<i.length;o++)i[o]&&(i[o].__=t,e=Ce(i[o],e,n,s));return e}t.__e!=e&&(s&&(e&&t.type&&!e.parentNode&&(e=L(t)),n.insertBefore(t.__e,e||null)),e=t.__e);do e=e&&e.nextSibling;while(e!=null&&e.nodeType==8);return e}function bt(t,e,n,s){var i,o,a,c=t.key,p=t.type,l=e[n],g=l!=null&&(2&l.__u)==0;if(l===null&&c==null||g&&c==l.key&&p==l.type)return n;if(s>(g?1:0)){for(i=n-1,o=n+1;i>=0||o<e.length;)if((l=e[a=i>=0?i--:o++])!=null&&(2&l.__u)==0&&c==l.key&&p==l.type)return a}return-1}function ve(t,e,n){e[0]=="-"?t.setProperty(e,n??""):t[e]=n==null?"":typeof n!="number"||vt.test(e)?n:n+"px"}function B(t,e,n,s,i){var o,a;e:if(e=="style")if(typeof n=="string")t.style.cssText=n;else{if(typeof s=="string"&&(t.style.cssText=s=""),s)for(e in s)n&&e in n||ve(t.style,e,"");if(n)for(e in n)s&&n[e]==s[e]||ve(t.style,e,n[e])}else if(e[0]=="o"&&e[1]=="n")o=e!=(e=e.replace(we,"$1")),a=e.toLowerCase(),e=a in t||e=="onFocusOut"||e=="onFocusIn"?a.slice(2):e.slice(2),t.l||(t.l={}),t.l[e+o]=n,n?s?n.u=s.u:(n.u=oe,t.addEventListener(e,o?se:ne,o)):t.removeEventListener(e,o?se:ne,o);else{if(i=="http://www.w3.org/2000/svg")e=e.replace(/xlink(H|:h)/,"h").replace(/sName$/,"s");else if(e!="width"&&e!="height"&&e!="href"&&e!="list"&&e!="form"&&e!="tabIndex"&&e!="download"&&e!="rowSpan"&&e!="colSpan"&&e!="role"&&e!="popover"&&e in t)try{t[e]=n??"";break e}catch{}typeof n=="function"||(n==null||n===!1&&e[4]!="-"?t.removeAttribute(e):t.setAttribute(e,e=="popover"&&n==1?"":n))}}function ye(t){return function(e){if(this.l){var n=this.l[e.type+t];if(e.t==null)e.t=oe++;else if(e.t<n.u)return;return n(y.event?y.event(e):e)}}}function le(t,e,n,s,i,o,a,c,p,l){var g,r,d,_,x,S,h,v,m,C,E,W,H,j,R,$,F,f=e.type;if(e.constructor!==void 0)return null;128&n.__u&&(p=!!(32&n.__u),o=[c=e.__e=n.__e]),(g=y.__b)&&g(e);e:if(typeof f=="function")try{if(v=e.props,m="prototype"in f&&f.prototype.render,C=(g=f.contextType)&&s[g.__c],E=g?C?C.props.value:g.__:s,n.__c?h=(r=e.__c=n.__c).__=r.__E:(m?e.__c=r=new f(v,E):(e.__c=r=new J(v,E),r.constructor=f,r.render=kt),C&&C.sub(r),r.state||(r.state={}),r.__n=s,d=r.__d=!0,r.__h=[],r._sb=[]),m&&r.__s==null&&(r.__s=r.state),m&&f.getDerivedStateFromProps!=null&&(r.__s==r.state&&(r.__s=T({},r.__s)),T(r.__s,f.getDerivedStateFromProps(v,r.__s))),_=r.props,x=r.state,r.__v=e,d)m&&f.getDerivedStateFromProps==null&&r.componentWillMount!=null&&r.componentWillMount(),m&&r.componentDidMount!=null&&r.__h.push(r.componentDidMount);else{if(m&&f.getDerivedStateFromProps==null&&v!==_&&r.componentWillReceiveProps!=null&&r.componentWillReceiveProps(v,E),e.__v==n.__v||!r.__e&&r.shouldComponentUpdate!=null&&r.shouldComponentUpdate(v,r.__s,E)===!1){for(e.__v!=n.__v&&(r.props=v,r.state=r.__s,r.__d=!1),e.__e=n.__e,e.__k=n.__k,e.__k.some(function(w){w&&(w.__=e)}),W=0;W<r._sb.length;W++)r.__h.push(r._sb[W]);r._sb=[],r.__h.length&&a.push(r);break e}r.componentWillUpdate!=null&&r.componentWillUpdate(v,r.__s,E),m&&r.componentDidUpdate!=null&&r.__h.push(function(){r.componentDidUpdate(_,x,S)})}if(r.context=E,r.props=v,r.__P=t,r.__e=!1,H=y.__r,j=0,m){for(r.state=r.__s,r.__d=!1,H&&H(e),g=r.render(r.props,r.state,r.context),R=0;R<r._sb.length;R++)r.__h.push(r._sb[R]);r._sb=[]}else do r.__d=!1,H&&H(e),g=r.render(r.props,r.state,r.context),r.state=r.__s;while(r.__d&&++j<25);r.state=r.__s,r.getChildContext!=null&&(s=T(T({},s),r.getChildContext())),m&&!d&&r.getSnapshotBeforeUpdate!=null&&(S=r.getSnapshotBeforeUpdate(_,x)),$=g,g!=null&&g.type===I&&g.key==null&&($=Te(g.props.children)),c=Ee(t,Y($)?$:[$],e,n,s,i,o,a,c,p,l),r.base=e.__e,e.__u&=-161,r.__h.length&&a.push(r),h&&(r.__E=r.__=null)}catch(w){if(e.__v=null,p||o!=null)if(w.then){for(e.__u|=p?160:128;c&&c.nodeType==8&&c.nextSibling;)c=c.nextSibling;o[o.indexOf(c)]=null,e.__e=c}else{for(F=o.length;F--;)re(o[F]);ie(e)}else e.__e=n.__e,e.__k=n.__k,w.then||ie(e);y.__e(w,e,n)}else o==null&&e.__v==n.__v?(e.__k=n.__k,e.__e=n.__e):c=e.__e=xt(n.__e,e,n,s,i,o,a,p,l);return(g=y.diffed)&&g(e),128&e.__u?void 0:c}function ie(t){t&&t.__c&&(t.__c.__e=!0),t&&t.__k&&t.__k.forEach(ie)}function Ie(t,e,n){for(var s=0;s<n.length;s++)ce(n[s],n[++s],n[++s]);y.__c&&y.__c(e,t),t.some(function(i){try{t=i.__h,i.__h=[],t.some(function(o){o.call(i)})}catch(o){y.__e(o,i.__v)}})}function Te(t){return typeof t!="object"||t==null||t.__b&&t.__b>0?t:Y(t)?t.map(Te):T({},t)}function xt(t,e,n,s,i,o,a,c,p){var l,g,r,d,_,x,S,h=n.props||U,v=e.props,m=e.type;if(m=="svg"?i="http://www.w3.org/2000/svg":m=="math"?i="http://www.w3.org/1998/Math/MathML":i||(i="http://www.w3.org/1999/xhtml"),o!=null){for(l=0;l<o.length;l++)if((_=o[l])&&"setAttribute"in _==!!m&&(m?_.localName==m:_.nodeType==3)){t=_,o[l]=null;break}}if(t==null){if(m==null)return document.createTextNode(v);t=document.createElementNS(i,m,v.is&&v),c&&(y.__m&&y.__m(e,o),c=!1),o=null}if(m==null)h===v||c&&t.data==v||(t.data=v);else{if(o=o&&G.call(t.childNodes),!c&&o!=null)for(h={},l=0;l<t.attributes.length;l++)h[(_=t.attributes[l]).name]=_.value;for(l in h)if(_=h[l],l!="children"){if(l=="dangerouslySetInnerHTML")r=_;else if(!(l in v)){if(l=="value"&&"defaultValue"in v||l=="checked"&&"defaultChecked"in v)continue;B(t,l,null,_,i)}}for(l in v)_=v[l],l=="children"?d=_:l=="dangerouslySetInnerHTML"?g=_:l=="value"?x=_:l=="checked"?S=_:c&&typeof _!="function"||h[l]===_||B(t,l,_,h[l],i);if(g)c||r&&(g.__html==r.__html||g.__html==t.innerHTML)||(t.innerHTML=g.__html),e.__k=[];else if(r&&(t.innerHTML=""),Ee(e.type=="template"?t.content:t,Y(d)?d:[d],e,n,s,m=="foreignObject"?"http://www.w3.org/1999/xhtml":i,o,a,o?o[0]:n.__k&&L(n,0),c,p),o!=null)for(l=o.length;l--;)re(o[l]);c||(l="value",m=="progress"&&x==null?t.removeAttribute("value"):x!=null&&(x!==t[l]||m=="progress"&&!x||m=="option"&&x!=h[l])&&B(t,l,x,h[l],i),l="checked",S!=null&&S!=t[l]&&B(t,l,S,h[l],i))}return t}function ce(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){y.__e(i,n)}}function Me(t,e,n){var s,i;if(y.unmount&&y.unmount(t),(s=t.ref)&&(s.current&&s.current!=t.__e||ce(s,null,e)),(s=t.__c)!=null){if(s.componentWillUnmount)try{s.componentWillUnmount()}catch(o){y.__e(o,e)}s.base=s.__P=null}if(s=t.__k)for(i=0;i<s.length;i++)s[i]&&Me(s[i],e,n||typeof t.type!="function");n||re(t.__e),t.__c=t.__=t.__e=void 0}function kt(t,e,n){return this.constructor(t,n)}function pe(t,e,n){var s,i,o,a;e==document&&(e=document.documentElement),y.__&&y.__(t,e),i=(s=typeof n=="function")?null:n&&n.__k||e.__k,o=[],a=[],le(e,t=(!s&&n||e).__k=ae(I,null,[t]),i||U,U,e.namespaceURI,!s&&n?[n]:i?null:e.firstChild?G.call(e.childNodes):null,o,!s&&n?n:i?i.__e:e.firstChild,s,a),Ie(o,t,a)}G=Pe.slice,y={__e:function(t,e,n,s){for(var i,o,a;e=e.__;)if((i=e.__c)&&!i.__)try{if((o=i.constructor)&&o.getDerivedStateFromError!=null&&(i.setState(o.getDerivedStateFromError(t)),a=i.__d),i.componentDidCatch!=null&&(i.componentDidCatch(t,s||{}),a=i.__d),a)return i.__E=i}catch(c){t=c}throw t}},be=0,ht=function(t){return t!=null&&t.constructor===void 0},J.prototype.setState=function(t,e){var n;n=this.__s!=null&&this.__s!=this.state?this.__s:this.__s=T({},this.state),typeof t=="function"&&(t=t(T({},n),this.props)),t&&T(n,t),t!=null&&this.__v&&(e&&this._sb.push(e),me(this))},J.prototype.forceUpdate=function(t){this.__v&&(this.__e=!0,t&&this.__h.push(t),me(this))},J.prototype.render=I,N=[],xe=typeof Promise=="function"?Promise.prototype.then.bind(Promise.resolve()):setTimeout,ke=function(t,e){return t.__v.__b-e.__v.__b},X.__r=0,we=/(PointerCapture)$|Capture$/i,oe=0,ne=ye(!1),se=ye(!0),mt=0;var D,k,de,$e,z=0,Fe=[],P=y,Ae=P.__b,Oe=P.__r,He=P.diffed,Re=P.__c,Ne=P.unmount,Le=P.__;function ge(t,e){P.__h&&P.__h(k,t,z||e),z=0;var n=k.__H||(k.__H={__:[],__h:[]});return t>=n.__.length&&n.__.push({}),n.__[t]}function M(t){return z=1,wt(ze,t)}function wt(t,e,n){var s=ge(D++,2);if(s.t=t,!s.__c&&(s.__=[n?n(e):ze(void 0,e),function(c){var p=s.__N?s.__N[0]:s.__[0],l=s.t(p,c);p!==l&&(s.__N=[l,s.__[1]],s.__c.setState({}))}],s.__c=k,!k.__f)){var i=function(c,p,l){if(!s.__c.__H)return!0;var g=s.__c.__H.__.filter(function(d){return!!d.__c});if(g.every(function(d){return!d.__N}))return!o||o.call(this,c,p,l);var r=s.__c.props!==c;return g.forEach(function(d){if(d.__N){var _=d.__[0];d.__=d.__N,d.__N=void 0,_!==d.__[0]&&(r=!0)}}),o&&o.call(this,c,p,l)||r};k.__f=!0;var o=k.shouldComponentUpdate,a=k.componentWillUpdate;k.componentWillUpdate=function(c,p,l){if(this.__e){var g=o;o=void 0,i(c,p,l),o=g}a&&a.call(this,c,p,l)},k.shouldComponentUpdate=i}return s.__N||s.__}function A(t,e){var n=ge(D++,3);!P.__s&&De(n.__H,e)&&(n.__=t,n.u=e,k.__H.__h.push(n))}function _e(t){return z=5,Ve(function(){return{current:t}},[])}function Ve(t,e){var n=ge(D++,7);return De(n.__H,e)&&(n.__=t(),n.__H=e,n.__h=t),n.__}function Ue(t,e){return z=8,Ve(function(){return t},e)}function Pt(){for(var t;t=Fe.shift();)if(t.__P&&t.__H)try{t.__H.__h.forEach(Z),t.__H.__h.forEach(ue),t.__H.__h=[]}catch(e){t.__H.__h=[],P.__e(e,t.__v)}}P.__b=function(t){k=null,Ae&&Ae(t)},P.__=function(t,e){t&&e.__k&&e.__k.__m&&(t.__m=e.__k.__m),Le&&Le(t,e)},P.__r=function(t){Oe&&Oe(t),D=0;var e=(k=t.__c).__H;e&&(de===k?(e.__h=[],k.__h=[],e.__.forEach(function(n){n.__N&&(n.__=n.__N),n.u=n.__N=void 0})):(e.__h.forEach(Z),e.__h.forEach(ue),e.__h=[],D=0)),de=k},P.diffed=function(t){He&&He(t);var e=t.__c;e&&e.__H&&(e.__H.__h.length&&(Fe.push(e)!==1&&$e===P.requestAnimationFrame||(($e=P.requestAnimationFrame)||St)(Pt)),e.__H.__.forEach(function(n){n.u&&(n.__H=n.u),n.u=void 0})),de=k=null},P.__c=function(t,e){e.some(function(n){try{n.__h.forEach(Z),n.__h=n.__h.filter(function(s){return!s.__||ue(s)})}catch(s){e.some(function(i){i.__h&&(i.__h=[])}),e=[],P.__e(s,n.__v)}}),Re&&Re(t,e)},P.unmount=function(t){Ne&&Ne(t);var e,n=t.__c;n&&n.__H&&(n.__H.__.forEach(function(s){try{Z(s)}catch(i){e=i}}),n.__H=void 0,e&&P.__e(e,n.__v))};var We=typeof requestAnimationFrame=="function";function St(t){var e,n=function(){clearTimeout(s),We&&cancelAnimationFrame(e),setTimeout(t)},s=setTimeout(n,35);We&&(e=requestAnimationFrame(n))}function Z(t){var e=k,n=t.__c;typeof n=="function"&&(t.__c=void 0,n()),k=e}function ue(t){var e=k;t.__c=t.__(),k=e}function De(t,e){return!t||t.length!==e.length||e.some(function(n,s){return n!==t[s]})}function ze(t,e){return typeof e=="function"?e(t):e}function je(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 _e=Object.defineProperty;var Bt=Object.getOwnPropertyDescriptor;var qt=Object.getOwnPropertyNames;var Jt=Object.prototype.hasOwnProperty;var Xt=(t,e)=>{for(var n in e)_e(t,n,{get:e[n],enumerable:!0})},Gt=(t,e,n,s)=>{if(e&&typeof e=="object"||typeof e=="function")for(let i of qt(e))!Jt.call(t,i)&&i!==n&&_e(t,i,{get:()=>e[i],enumerable:!(s=Bt(e,i))||s.enumerable});return t};var Yt=t=>Gt(_e({},"__esModule",{value:!0}),t);var bn={};Xt(bn,{close:()=>ft,default:()=>yn,destroy:()=>gt,getIdentity:()=>Mt,getTrackedElements:()=>wt,identify:()=>Pt,init:()=>Te,offEvent:()=>Et,on:()=>Ct,onEvent:()=>kt,open:()=>ht,reset:()=>St,sendMessage:()=>_t,setupTrackedElements:()=>bt,toggle:()=>mt,trigger:()=>yt,uploadFile:()=>vt,uploadFiles:()=>xt});var ae,k,Ne,Kt,J,De,Ue,We,ze,be,ve,xe,Qt,Q={},Ve=[],Zt=/acit|ex(?:s|g|n|p|$)|rph|grid|ows|mnc|ntw|ine[ch]|zoo|^ord|itera/i,pe=Array.isArray;function V(t,e){for(var n in e)t[n]=e[n];return t}function we(t){t&&t.parentNode&&t.parentNode.removeChild(t)}function ke(t,e,n){var s,i,r,a={};for(r in e)r=="key"?s=e[r]:r=="ref"?i=e[r]:a[r]=e[r];if(arguments.length>2&&(a.children=arguments.length>3?ae.call(arguments,2):n),typeof t=="function"&&t.defaultProps!=null)for(r in t.defaultProps)a[r]===void 0&&(a[r]=t.defaultProps[r]);return ie(t,a,s,i,null)}function ie(t,e,n,s,i){var r={type:t,props:e,key:n,ref:s,__k:null,__:null,__b:0,__e:null,__c:null,constructor:void 0,__v:i??++Ne,__i:-1,__u:0};return i==null&&k.vnode!=null&&k.vnode(r),r}function L(t){return t.children}function oe(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 je(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 je(t)}}function Le(t){(!t.__d&&(t.__d=!0)&&J.push(t)&&!re.__r++||De!=k.debounceRendering)&&((De=k.debounceRendering)||Ue)(re)}function re(){for(var t,e,n,s,i,r,a,c=1;J.length;)J.length>c&&J.sort(We),t=J.shift(),c=J.length,t.__d&&(n=void 0,s=void 0,i=(s=(e=t).__v).__e,r=[],a=[],e.__P&&((n=V({},s)).__v=s.__v+1,k.vnode&&k.vnode(n),Ee(e.__P,n,s,e.__n,e.__P.namespaceURI,32&s.__u?[i]:null,r,i??G(s),!!(32&s.__u),a),n.__v=s.__v,n.__.__k[n.__i]=n,Je(r,n,a),s.__e=s.__=null,n.__e!=i&&je(n)));re.__r=0}function Be(t,e,n,s,i,r,a,c,u,l,h){var p,g,f,P,$,E,m,w=s&&s.__k||Ve,D=e.length;for(u=en(n,e,w,u,D),p=0;p<D;p++)(f=n.__k[p])!=null&&(g=f.__i==-1?Q:w[f.__i]||Q,f.__i=p,E=Ee(t,f,g,i,r,a,c,u,l,h),P=f.__e,f.ref&&g.ref!=f.ref&&(g.ref&&Pe(g.ref,null,f),h.push(f.ref,f.__c||P,f)),$==null&&P!=null&&($=P),(m=!!(4&f.__u))||g.__k===f.__k?u=qe(f,u,t,m):typeof f.type=="function"&&E!==void 0?u=E:P&&(u=P.nextSibling),f.__u&=-7);return n.__e=$,u}function en(t,e,n,s,i){var r,a,c,u,l,h=n.length,p=h,g=0;for(t.__k=new Array(i),r=0;r<i;r++)(a=e[r])!=null&&typeof a!="boolean"&&typeof a!="function"?(typeof a=="string"||typeof a=="number"||typeof a=="bigint"||a.constructor==String?a=t.__k[r]=ie(null,a,null,null,null):pe(a)?a=t.__k[r]=ie(L,{children:a},null,null,null):a.constructor===void 0&&a.__b>0?a=t.__k[r]=ie(a.type,a.props,a.key,a.ref?a.ref:null,a.__v):t.__k[r]=a,u=r+g,a.__=t,a.__b=t.__b+1,c=null,(l=a.__i=tn(a,n,u,p))!=-1&&(p--,(c=n[l])&&(c.__u|=2)),c==null||c.__v==null?(l==-1&&(i>h?g--:i<h&&g++),typeof a.type!="function"&&(a.__u|=4)):l!=u&&(l==u-1?g--:l==u+1?g++:(l>u?g--:g++,a.__u|=4))):t.__k[r]=null;if(p)for(r=0;r<h;r++)(c=n[r])!=null&&(2&c.__u)==0&&(c.__e==s&&(s=G(c)),Ge(c,c));return s}function qe(t,e,n,s){var i,r;if(typeof t.type=="function"){for(i=t.__k,r=0;i&&r<i.length;r++)i[r]&&(i[r].__=t,e=qe(i[r],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 tn(t,e,n,s){var i,r,a,c=t.key,u=t.type,l=e[n],h=l!=null&&(2&l.__u)==0;if(l===null&&c==null||h&&c==l.key&&u==l.type)return n;if(s>(h?1:0)){for(i=n-1,r=n+1;i>=0||r<e.length;)if((l=e[a=i>=0?i--:r++])!=null&&(2&l.__u)==0&&c==l.key&&u==l.type)return a}return-1}function He(t,e,n){e[0]=="-"?t.setProperty(e,n??""):t[e]=n==null?"":typeof n!="number"||Zt.test(e)?n:n+"px"}function se(t,e,n,s,i){var r,a;e:if(e=="style")if(typeof n=="string")t.style.cssText=n;else{if(typeof s=="string"&&(t.style.cssText=s=""),s)for(e in s)n&&e in n||He(t.style,e,"");if(n)for(e in n)s&&n[e]==s[e]||He(t.style,e,n[e])}else if(e[0]=="o"&&e[1]=="n")r=e!=(e=e.replace(ze,"$1")),a=e.toLowerCase(),e=a in t||e=="onFocusOut"||e=="onFocusIn"?a.slice(2):e.slice(2),t.l||(t.l={}),t.l[e+r]=n,n?s?n.u=s.u:(n.u=be,t.addEventListener(e,r?xe:ve,r)):t.removeEventListener(e,r?xe:ve,r);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 Fe(t){return function(e){if(this.l){var n=this.l[e.type+t];if(e.t==null)e.t=be++;else if(e.t<n.u)return;return n(k.event?k.event(e):e)}}}function Ee(t,e,n,s,i,r,a,c,u,l){var h,p,g,f,P,$,E,m,w,D,H,B,U,X,W,F,O,A=e.type;if(e.constructor!==void 0)return null;128&n.__u&&(u=!!(32&n.__u),r=[c=e.__e=n.__e]),(h=k.__b)&&h(e);e:if(typeof A=="function")try{if(m=e.props,w="prototype"in A&&A.prototype.render,D=(h=A.contextType)&&s[h.__c],H=h?D?D.props.value:h.__:s,n.__c?E=(p=e.__c=n.__c).__=p.__E:(w?e.__c=p=new A(m,H):(e.__c=p=new oe(m,H),p.constructor=A,p.render=sn),D&&D.sub(p),p.state||(p.state={}),p.__n=s,g=p.__d=!0,p.__h=[],p._sb=[]),w&&p.__s==null&&(p.__s=p.state),w&&A.getDerivedStateFromProps!=null&&(p.__s==p.state&&(p.__s=V({},p.__s)),V(p.__s,A.getDerivedStateFromProps(m,p.__s))),f=p.props,P=p.state,p.__v=e,g)w&&A.getDerivedStateFromProps==null&&p.componentWillMount!=null&&p.componentWillMount(),w&&p.componentDidMount!=null&&p.__h.push(p.componentDidMount);else{if(w&&A.getDerivedStateFromProps==null&&m!==f&&p.componentWillReceiveProps!=null&&p.componentWillReceiveProps(m,H),e.__v==n.__v||!p.__e&&p.shouldComponentUpdate!=null&&p.shouldComponentUpdate(m,p.__s,H)===!1){for(e.__v!=n.__v&&(p.props=m,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&&a.push(p);break e}p.componentWillUpdate!=null&&p.componentWillUpdate(m,p.__s,H),w&&p.componentDidUpdate!=null&&p.__h.push(function(){p.componentDidUpdate(f,P,$)})}if(p.context=H,p.props=m,p.__P=t,p.__e=!1,U=k.__r,X=0,w){for(p.state=p.__s,p.__d=!1,U&&U(e),h=p.render(p.props,p.state,p.context),W=0;W<p._sb.length;W++)p.__h.push(p._sb[W]);p._sb=[]}else do p.__d=!1,U&&U(e),h=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())),w&&!g&&p.getSnapshotBeforeUpdate!=null&&($=p.getSnapshotBeforeUpdate(f,P)),F=h,h!=null&&h.type===L&&h.key==null&&(F=Xe(h.props.children)),c=Be(t,pe(F)?F:[F],e,n,s,i,r,a,c,u,l),p.base=e.__e,e.__u&=-161,p.__h.length&&a.push(p),E&&(p.__E=p.__=null)}catch(z){if(e.__v=null,u||r!=null)if(z.then){for(e.__u|=u?160:128;c&&c.nodeType==8&&c.nextSibling;)c=c.nextSibling;r[r.indexOf(c)]=null,e.__e=c}else{for(O=r.length;O--;)we(r[O]);ye(e)}else e.__e=n.__e,e.__k=n.__k,z.then||ye(e);k.__e(z,e,n)}else r==null&&e.__v==n.__v?(e.__k=n.__k,e.__e=n.__e):c=e.__e=nn(n.__e,e,n,s,i,r,a,u,l);return(h=k.diffed)&&h(e),128&e.__u?void 0:c}function ye(t){t&&t.__c&&(t.__c.__e=!0),t&&t.__k&&t.__k.forEach(ye)}function Je(t,e,n){for(var s=0;s<n.length;s++)Pe(n[s],n[++s],n[++s]);k.__c&&k.__c(e,t),t.some(function(i){try{t=i.__h,i.__h=[],t.some(function(r){r.call(i)})}catch(r){k.__e(r,i.__v)}})}function Xe(t){return typeof t!="object"||t==null||t.__b&&t.__b>0?t:pe(t)?t.map(Xe):V({},t)}function nn(t,e,n,s,i,r,a,c,u){var l,h,p,g,f,P,$,E=n.props||Q,m=e.props,w=e.type;if(w=="svg"?i="http://www.w3.org/2000/svg":w=="math"?i="http://www.w3.org/1998/Math/MathML":i||(i="http://www.w3.org/1999/xhtml"),r!=null){for(l=0;l<r.length;l++)if((f=r[l])&&"setAttribute"in f==!!w&&(w?f.localName==w:f.nodeType==3)){t=f,r[l]=null;break}}if(t==null){if(w==null)return document.createTextNode(m);t=document.createElementNS(i,w,m.is&&m),c&&(k.__m&&k.__m(e,r),c=!1),r=null}if(w==null)E===m||c&&t.data==m||(t.data=m);else{if(r=r&&ae.call(t.childNodes),!c&&r!=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 m)){if(l=="value"&&"defaultValue"in m||l=="checked"&&"defaultChecked"in m)continue;se(t,l,null,f,i)}}for(l in m)f=m[l],l=="children"?g=f:l=="dangerouslySetInnerHTML"?h=f:l=="value"?P=f:l=="checked"?$=f:c&&typeof f!="function"||E[l]===f||se(t,l,f,E[l],i);if(h)c||p&&(h.__html==p.__html||h.__html==t.innerHTML)||(t.innerHTML=h.__html),e.__k=[];else if(p&&(t.innerHTML=""),Be(e.type=="template"?t.content:t,pe(g)?g:[g],e,n,s,w=="foreignObject"?"http://www.w3.org/1999/xhtml":i,r,a,r?r[0]:n.__k&&G(n,0),c,u),r!=null)for(l=r.length;l--;)we(r[l]);c||(l="value",w=="progress"&&P==null?t.removeAttribute("value"):P!=null&&(P!==t[l]||w=="progress"&&!P||w=="option"&&P!=E[l])&&se(t,l,P,E[l],i),l="checked",$!=null&&$!=t[l]&&se(t,l,$,E[l],i))}return t}function Pe(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){k.__e(i,n)}}function Ge(t,e,n){var s,i;if(k.unmount&&k.unmount(t),(s=t.ref)&&(s.current&&s.current!=t.__e||Pe(s,null,e)),(s=t.__c)!=null){if(s.componentWillUnmount)try{s.componentWillUnmount()}catch(r){k.__e(r,e)}s.base=s.__P=null}if(s=t.__k)for(i=0;i<s.length;i++)s[i]&&Ge(s[i],e,n||typeof t.type!="function");n||we(t.__e),t.__c=t.__=t.__e=void 0}function sn(t,e,n){return this.constructor(t,n)}function Se(t,e,n){var s,i,r,a;e==document&&(e=document.documentElement),k.__&&k.__(t,e),i=(s=typeof n=="function")?null:n&&n.__k||e.__k,r=[],a=[],Ee(e,t=(!s&&n||e).__k=ke(L,null,[t]),i||Q,Q,e.namespaceURI,!s&&n?[n]:i?null:e.firstChild?ae.call(e.childNodes):null,r,!s&&n?n:i?i.__e:e.firstChild,s,a),Je(r,t,a)}ae=Ve.slice,k={__e:function(t,e,n,s){for(var i,r,a;e=e.__;)if((i=e.__c)&&!i.__)try{if((r=i.constructor)&&r.getDerivedStateFromError!=null&&(i.setState(r.getDerivedStateFromError(t)),a=i.__d),i.componentDidCatch!=null&&(i.componentDidCatch(t,s||{}),a=i.__d),a)return i.__E=i}catch(c){t=c}throw t}},Ne=0,Kt=function(t){return t!=null&&t.constructor===void 0},oe.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),Le(this))},oe.prototype.forceUpdate=function(t){this.__v&&(this.__e=!0,t&&this.__h.push(t),Le(this))},oe.prototype.render=L,J=[],Ue=typeof Promise=="function"?Promise.prototype.then.bind(Promise.resolve()):setTimeout,We=function(t,e){return t.__v.__b-e.__v.__b},re.__r=0,ze=/(PointerCapture)$|Capture$/i,be=0,ve=Fe(!1),xe=Fe(!0),Qt=0;var Z,C,Me,Ye,ee=0,it=[],T=k,Ke=T.__b,Qe=T.__r,Ze=T.diffed,et=T.__c,tt=T.unmount,nt=T.__;function Ie(t,e){T.__h&&T.__h(C,t,ee||e),ee=0;var n=C.__H||(C.__H={__:[],__h:[]});return t>=n.__.length&&n.__.push({}),n.__[t]}function R(t){return ee=1,on(pt,t)}function on(t,e,n){var s=Ie(Z++,2);if(s.t=t,!s.__c&&(s.__=[n?n(e):pt(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=C,!C.__f)){var i=function(c,u,l){if(!s.__c.__H)return!0;var h=s.__c.__H.__.filter(function(g){return!!g.__c});if(h.every(function(g){return!g.__N}))return!r||r.call(this,c,u,l);var p=s.__c.props!==c;return h.forEach(function(g){if(g.__N){var f=g.__[0];g.__=g.__N,g.__N=void 0,f!==g.__[0]&&(p=!0)}}),r&&r.call(this,c,u,l)||p};C.__f=!0;var r=C.shouldComponentUpdate,a=C.componentWillUpdate;C.componentWillUpdate=function(c,u,l){if(this.__e){var h=r;r=void 0,i(c,u,l),r=h}a&&a.call(this,c,u,l)},C.shouldComponentUpdate=i}return s.__N||s.__}function j(t,e){var n=Ie(Z++,3);!T.__s&&at(n.__H,e)&&(n.__=t,n.u=e,C.__H.__h.push(n))}function Y(t){return ee=5,ot(function(){return{current:t}},[])}function ot(t,e){var n=Ie(Z++,7);return at(n.__H,e)&&(n.__=t(),n.__H=e,n.__h=t),n.__}function rt(t,e){return ee=8,ot(function(){return t},e)}function rn(){for(var t;t=it.shift();)if(t.__P&&t.__H)try{t.__H.__h.forEach(le),t.__H.__h.forEach(Ce),t.__H.__h=[]}catch(e){t.__H.__h=[],T.__e(e,t.__v)}}T.__b=function(t){C=null,Ke&&Ke(t)},T.__=function(t,e){t&&e.__k&&e.__k.__m&&(t.__m=e.__k.__m),nt&&nt(t,e)},T.__r=function(t){Qe&&Qe(t),Z=0;var e=(C=t.__c).__H;e&&(Me===C?(e.__h=[],C.__h=[],e.__.forEach(function(n){n.__N&&(n.__=n.__N),n.u=n.__N=void 0})):(e.__h.forEach(le),e.__h.forEach(Ce),e.__h=[],Z=0)),Me=C},T.diffed=function(t){Ze&&Ze(t);var e=t.__c;e&&e.__H&&(e.__H.__h.length&&(it.push(e)!==1&&Ye===T.requestAnimationFrame||((Ye=T.requestAnimationFrame)||an)(rn)),e.__H.__.forEach(function(n){n.u&&(n.__H=n.u),n.u=void 0})),Me=C=null},T.__c=function(t,e){e.some(function(n){try{n.__h.forEach(le),n.__h=n.__h.filter(function(s){return!s.__||Ce(s)})}catch(s){e.some(function(i){i.__h&&(i.__h=[])}),e=[],T.__e(s,n.__v)}}),et&&et(t,e)},T.unmount=function(t){tt&&tt(t);var e,n=t.__c;n&&n.__H&&(n.__H.__.forEach(function(s){try{le(s)}catch(i){e=i}}),n.__H=void 0,e&&T.__e(e,n.__v))};var st=typeof requestAnimationFrame=="function";function an(t){var e,n=function(){clearTimeout(s),st&&cancelAnimationFrame(e),setTimeout(t)},s=setTimeout(n,35);st&&(e=requestAnimationFrame(n))}function le(t){var e=C,n=t.__c;typeof n=="function"&&(t.__c=void 0,n()),C=e}function Ce(t){var e=C;t.__c=t.__(),C=e}function at(t,e){return!t||t.length!==e.length||e.some(function(n,s){return n!==t[s]})}function pt(t,e){return typeof e=="function"?e(t):e}function lt(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;
|
|
@@ -172,6 +172,12 @@
|
|
|
172
172
|
border-radius: 4px;
|
|
173
173
|
opacity: 0.8;
|
|
174
174
|
transition: opacity 0.2s;
|
|
175
|
+
flex-shrink: 0;
|
|
176
|
+
width: 28px;
|
|
177
|
+
height: 28px;
|
|
178
|
+
display: flex;
|
|
179
|
+
align-items: center;
|
|
180
|
+
justify-content: center;
|
|
175
181
|
}
|
|
176
182
|
|
|
177
183
|
.pp-close-btn:hover {
|
|
@@ -179,8 +185,8 @@
|
|
|
179
185
|
}
|
|
180
186
|
|
|
181
187
|
.pp-close-btn svg {
|
|
182
|
-
width:
|
|
183
|
-
height:
|
|
188
|
+
width: 16px;
|
|
189
|
+
height: 16px;
|
|
184
190
|
}
|
|
185
191
|
|
|
186
192
|
.pp-messages {
|
|
@@ -354,7 +360,487 @@
|
|
|
354
360
|
.pp-footer a:hover {
|
|
355
361
|
text-decoration: underline;
|
|
356
362
|
}
|
|
357
|
-
`}var Et=0;function u(t,e,n,s,i,o){e||(e={});var a,c,p=e;if("ref"in p)for(c in p={},e)c=="ref"?a=e[c]:p[c]=e[c];var l={type:t,props:p,key:n,ref:a,__k:null,__:null,__b:0,__e:null,__c:null,constructor:void 0,__v:--Et,__i:-1,__u:0,__source:i,__self:o};if(typeof t=="function"&&(a=t.defaultProps))for(c in a)p[c]===void 0&&(p[c]=a[c]);return y.vnode&&y.vnode(l),l}function qe({client:t,config:e}){let[n,s]=M(!1),[i,o]=M([]),[a,c]=M(""),[p,l]=M(!1),[g,r]=M(!1),[d,_]=M(!1),[x,S]=M(0),[h,v]=M(e),m=_e(null),C=_e(null);A(()=>{let f=t.on("openChange",s),w=t.on("message",()=>{o([...t.getMessages()])}),V=t.on("typing",ee=>{l(ee.isTyping)}),at=t.on("presence",ee=>{r(ee.online)}),lt=t.on("connect",()=>{_(!0),o(t.getMessages()),r(t.getSession()?.operatorOnline??!1),v(t.getConfig())}),ct=t.on("configUpdate",()=>{v(t.getConfig())});return t.isConnected()&&(_(!0),o(t.getMessages()),r(t.getSession()?.operatorOnline??!1),v(t.getConfig())),()=>{f(),w(),V(),at(),lt(),ct()}},[t]),A(()=>{n&&m.current?.scrollIntoView({behavior:"smooth"})},[i,n]),A(()=>{n&&(setTimeout(()=>{m.current?.scrollIntoView({behavior:"auto"})},50),C.current?.focus(),S(0))},[n]),A(()=>{if(!n&&i.length>0){let f=i.filter(w=>w.sender!=="visitor"&&w.status!=="read").length;S(f)}},[i,n]);let E=Ue(()=>{if(!n||!d)return;let f=i.filter(w=>w.sender!=="visitor"&&w.status!=="read");if(f.length>0){let w=f.map(V=>V.id);t.sendReadStatus(w,"read")}},[n,d,i,t]);if(A(()=>{if(!n||!d)return;let f=setTimeout(()=>{E()},1e3);return()=>clearTimeout(f)},[n,d,i,E]),A(()=>{let f=()=>{document.visibilityState==="visible"&&n&&E()};return document.addEventListener("visibilitychange",f),()=>document.removeEventListener("visibilitychange",f)},[n,E]),A(()=>{let f=t.on("read",()=>{o([...t.getMessages()])});return()=>f()},[t]),!Ct(h))return null;let H=async f=>{if(f.preventDefault(),!a.trim())return;let w=a;c("");try{await t.sendMessage(w)}catch(V){console.error("[PocketPing] Failed to send message:",V)}},j=f=>{let w=f.target;c(w.value),t.sendTyping(!0)},R=h.position??"bottom-right",$=It(h.theme??"auto"),F=h.primaryColor??"#6366f1";return u(I,{children:[u("style",{children:je(F,$)}),u("button",{class:`pp-toggle pp-${R}`,onClick:()=>t.toggleOpen(),"aria-label":n?"Close chat":"Open chat",children:[n?u(Be,{}):u(Mt,{}),!n&&x>0&&u("span",{class:"pp-unread-badge",children:x>9?"9+":x}),!n&&x===0&&g&&u("span",{class:"pp-online-dot"})]}),n&&u("div",{class:`pp-window pp-${R} pp-theme-${$}`,children:[u("div",{class:"pp-header",children:[u("div",{class:"pp-header-info",children:[h.operatorAvatar&&u("img",{src:h.operatorAvatar,alt:"",class:"pp-avatar"}),u("div",{children:[u("div",{class:"pp-header-title",children:h.operatorName??"Support"}),u("div",{class:"pp-header-status",children:g?u(I,{children:[u("span",{class:"pp-status-dot pp-online"})," Online"]}):u(I,{children:[u("span",{class:"pp-status-dot"})," Away"]})})]})]}),u("button",{class:"pp-close-btn",onClick:()=>t.setOpen(!1),"aria-label":"Close chat",children:u(Be,{})})]}),u("div",{class:"pp-messages",children:[h.welcomeMessage&&i.length===0&&u("div",{class:"pp-welcome",children:h.welcomeMessage}),i.map(f=>u("div",{class:`pp-message pp-message-${f.sender}`,children:[u("div",{class:"pp-message-content",children:f.content}),u("div",{class:"pp-message-time",children:[Tt(f.timestamp),f.sender==="ai"&&u("span",{class:"pp-ai-badge",children:"AI"}),f.sender==="visitor"&&u("span",{class:`pp-status pp-status-${f.status??"sent"}`,children:u(At,{status:f.status})})]})]},f.id)),p&&u("div",{class:"pp-message pp-message-operator pp-typing",children:[u("span",{}),u("span",{}),u("span",{})]}),u("div",{ref:m})]}),u("form",{class:"pp-input-form",onSubmit:H,children:[u("input",{ref:C,type:"text",class:"pp-input",placeholder:h.placeholder??"Type a message...",value:a,onInput:j,disabled:!d}),u("button",{type:"submit",class:"pp-send-btn",disabled:!a.trim()||!d,"aria-label":"Send message",children:u($t,{})})]}),u("div",{class:"pp-footer",children:["Powered by ",u("a",{href:"https://pocketping.io",target:"_blank",rel:"noopener",children:"PocketPing"})]})]})]})}function Ct(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 It(t){return t==="auto"?window.matchMedia("(prefers-color-scheme: dark)").matches?"dark":"light":t}function Tt(t){return new Date(t).toLocaleTimeString([],{hour:"2-digit",minute:"2-digit"})}function Mt(){return u("svg",{viewBox:"0 0 24 24",fill:"none",stroke:"currentColor","stroke-width":"2",children:u("path",{d:"M21 15a2 2 0 0 1-2 2H7l-4 4V5a2 2 0 0 1 2-2h14a2 2 0 0 1 2 2z"})})}function Be(){return u("svg",{viewBox:"0 0 24 24",fill:"none",stroke:"currentColor","stroke-width":"2",children:[u("line",{x1:"18",y1:"6",x2:"6",y2:"18"}),u("line",{x1:"6",y1:"6",x2:"18",y2:"18"})]})}function $t(){return u("svg",{viewBox:"0 0 24 24",fill:"none",stroke:"currentColor","stroke-width":"2",children:[u("line",{x1:"22",y1:"2",x2:"11",y2:"13"}),u("polygon",{points:"22 2 15 22 11 13 2 9 22 2"})]})}function At({status:t}){return!t||t==="sending"||t==="sent"?u("svg",{viewBox:"0 0 16 16",fill:"none",stroke:"currentColor","stroke-width":"2",class:"pp-check",children:u("polyline",{points:"3 8 7 12 13 4"})}):t==="delivered"?u("svg",{viewBox:"0 0 20 16",fill:"none",stroke:"currentColor","stroke-width":"2",class:"pp-check-double",children:[u("polyline",{points:"1 8 5 12 11 4"}),u("polyline",{points:"7 8 11 12 17 4"})]}):t==="read"?u("svg",{viewBox:"0 0 20 16",fill:"none",stroke:"currentColor","stroke-width":"2",class:"pp-check-double pp-check-read",children:[u("polyline",{points:"1 8 5 12 11 4"}),u("polyline",{points:"7 8 11 12 17 4"})]}):null}var K="1.0.2";var Q=class{constructor(e){this.session=null;this.ws=null;this.isOpen=!1;this.listeners=new Map;this.customEventHandlers=new Map;this.reconnectAttempts=0;this.maxReconnectAttempts=5;this.reconnectTimeout=null;this.pollingTimeout=null;this.pollingFailures=0;this.maxPollingFailures=10;this.wsConnectedAt=0;this.quickFailureThreshold=2e3;this.usePollingFallback=!1;this.trackedElementCleanups=[];this.currentTrackedElements=[];this.inspectorMode=!1;this.inspectorCleanup=null;this.config=e}async connect(){let e=this.getOrCreateVisitorId(),n=this.getStoredSessionId(),s=this.getStoredIdentity(),o=new URLSearchParams(window.location.search).get("pp_inspector"),a=await this.fetch("/connect",{method:"POST",body:JSON.stringify({visitorId:e,sessionId:n,inspectorToken:o||void 0,metadata:{url:window.location.href,referrer:document.referrer||void 0,pageTitle:document.title||void 0,userAgent:navigator.userAgent,timezone:Intl.DateTimeFormat().resolvedOptions().timeZone,language:navigator.language,screenResolution:`${window.screen.width}x${window.screen.height}`},identity:s||void 0})});return this.session={sessionId:a.sessionId,visitorId:a.visitorId,operatorOnline:a.operatorOnline??!1,messages:a.messages??[],identity:a.identity||s||void 0},a.operatorName&&(this.config.operatorName=a.operatorName),a.operatorAvatar&&(this.config.operatorAvatar=a.operatorAvatar),a.primaryColor&&(this.config.primaryColor=a.primaryColor),a.welcomeMessage&&(this.config.welcomeMessage=a.welcomeMessage),this.emit("configUpdate",{operatorName:this.config.operatorName,operatorAvatar:this.config.operatorAvatar,primaryColor:this.config.primaryColor,welcomeMessage:this.config.welcomeMessage}),this.storeSessionId(a.sessionId),this.connectWebSocket(),a.inspectorMode?this.enableInspectorMode():a.trackedElements?.length&&this.setupTrackedElements(a.trackedElements),this.emit("connect",this.session),this.config.onConnect?.(a.sessionId),this.session}disconnect(){this.ws?.close(),this.ws=null,this.session=null,this.reconnectTimeout&&clearTimeout(this.reconnectTimeout),this.stopPolling(),this.cleanupTrackedElements(),this.disableInspectorMode()}async sendMessage(e){if(!this.session)throw new Error("Not connected");let n=`temp-${this.generateId()}`,s={id:n,sessionId:this.session.sessionId,content:e,sender:"visitor",timestamp:new Date().toISOString(),status:"sending"};this.session.messages.push(s),this.emit("message",s);try{let i=await this.fetch("/message",{method:"POST",body:JSON.stringify({sessionId:this.session.sessionId,content:e,sender:"visitor"})}),o=this.session.messages.findIndex(c=>c.id===n);o>=0&&(this.session.messages[o].id=i.messageId,this.session.messages[o].timestamp=i.timestamp,this.session.messages[o].status="sent",this.emit("message",this.session.messages[o]));let a=this.session.messages[o]||{id:i.messageId,sessionId:this.session.sessionId,content:e,sender:"visitor",timestamp:i.timestamp,status:"sent"};return this.config.onMessage?.(a),a}catch(i){let o=this.session.messages.findIndex(a=>a.id===n);throw o>=0&&(this.session.messages.splice(o,1),this.emit("message",s)),i}}async fetchMessages(e){if(!this.session)throw new Error("Not connected");let n=new URLSearchParams({sessionId:this.session.sessionId});return e&&n.set("after",e),(await this.fetch(`/messages?${n}`,{method:"GET"})).messages}async sendTyping(e=!0){this.session&&await this.fetch("/typing",{method:"POST",body:JSON.stringify({sessionId:this.session.sessionId,sender:"visitor",isTyping:e})})}async sendReadStatus(e,n){if(!(!this.session||e.length===0))try{await this.fetch("/read",{method:"POST",body:JSON.stringify({sessionId:this.session.sessionId,messageIds:e,status:n})});for(let s of this.session.messages)e.includes(s.id)&&(s.status=n,n==="delivered"?s.deliveredAt=new Date().toISOString():n==="read"&&(s.readAt=new Date().toISOString()));this.emit("readStatusSent",{messageIds:e,status:n})}catch(s){console.error("[PocketPing] Failed to send read status:",s)}}async getPresence(){return this.fetch("/presence",{method:"GET"})}async identify(e){if(!e?.id)throw new Error("[PocketPing] identity.id is required");if(this.storeIdentity(e),this.session)try{await this.fetch("/identify",{method:"POST",body:JSON.stringify({sessionId:this.session.sessionId,identity:e})}),this.session.identity=e,this.emit("identify",e)}catch(n){throw console.error("[PocketPing] Failed to identify:",n),n}}async reset(e){this.clearIdentity(),this.session&&(this.session.identity=void 0),e?.newSession&&(localStorage.removeItem("pocketping_session_id"),localStorage.removeItem("pocketping_visitor_id"),this.disconnect(),await this.connect()),this.emit("reset",null)}getIdentity(){return this.session?.identity||this.getStoredIdentity()}getSession(){return this.session}getMessages(){return this.session?.messages??[]}isConnected(){return this.session!==null}isWidgetOpen(){return this.isOpen}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=a=>{let c={...n.data,selector:n.selector,elementText:a.target?.textContent?.trim().slice(0,100),url:window.location.href};this.trigger(n.name,c,{widgetMessage:n.widgetMessage})},o=a=>{a.target?.closest(n.selector)&&i(a)};document.addEventListener(s,o,!0),this.trackedElementCleanups.push(()=>{document.removeEventListener(s,o,!0)})}e.length>0&&console.info(`[PocketPing] Tracking ${e.length} element(s)`)}cleanupTrackedElements(){for(let e of this.trackedElementCleanups)e();this.trackedElementCleanups=[],this.currentTrackedElements=[]}getTrackedElements(){return[...this.currentTrackedElements]}enableInspectorMode(){if(this.inspectorMode)return;this.inspectorMode=!0,console.info("[PocketPing] \u{1F50D} Inspector mode active - click on any element to select it");let e=document.createElement("div");e.id="pp-inspector-overlay",e.innerHTML=`
|
|
363
|
+
|
|
364
|
+
/* Attachment Styles */
|
|
365
|
+
.pp-file-input {
|
|
366
|
+
/* Use offscreen positioning instead of display:none for better browser compatibility */
|
|
367
|
+
position: absolute;
|
|
368
|
+
width: 1px;
|
|
369
|
+
height: 1px;
|
|
370
|
+
padding: 0;
|
|
371
|
+
margin: -1px;
|
|
372
|
+
overflow: hidden;
|
|
373
|
+
clip: rect(0, 0, 0, 0);
|
|
374
|
+
white-space: nowrap;
|
|
375
|
+
border: 0;
|
|
376
|
+
}
|
|
377
|
+
|
|
378
|
+
.pp-attach-btn {
|
|
379
|
+
width: 40px;
|
|
380
|
+
height: 40px;
|
|
381
|
+
border-radius: 50%;
|
|
382
|
+
background: transparent;
|
|
383
|
+
color: ${s.textSecondary};
|
|
384
|
+
border: 1px solid ${s.border};
|
|
385
|
+
cursor: pointer;
|
|
386
|
+
display: flex;
|
|
387
|
+
align-items: center;
|
|
388
|
+
justify-content: center;
|
|
389
|
+
transition: color 0.2s, border-color 0.2s;
|
|
390
|
+
flex-shrink: 0;
|
|
391
|
+
}
|
|
392
|
+
|
|
393
|
+
.pp-attach-btn:hover:not(:disabled) {
|
|
394
|
+
color: ${t};
|
|
395
|
+
border-color: ${t};
|
|
396
|
+
}
|
|
397
|
+
|
|
398
|
+
.pp-attach-btn:disabled {
|
|
399
|
+
opacity: 0.5;
|
|
400
|
+
cursor: not-allowed;
|
|
401
|
+
}
|
|
402
|
+
|
|
403
|
+
.pp-attach-btn svg {
|
|
404
|
+
width: 18px;
|
|
405
|
+
height: 18px;
|
|
406
|
+
}
|
|
407
|
+
|
|
408
|
+
.pp-attachments-preview {
|
|
409
|
+
display: flex;
|
|
410
|
+
gap: 8px;
|
|
411
|
+
padding: 8px 12px;
|
|
412
|
+
border-top: 1px solid ${s.border};
|
|
413
|
+
overflow-x: auto;
|
|
414
|
+
background: ${s.bgSecondary};
|
|
415
|
+
}
|
|
416
|
+
|
|
417
|
+
.pp-attachment-preview {
|
|
418
|
+
position: relative;
|
|
419
|
+
width: 60px;
|
|
420
|
+
height: 60px;
|
|
421
|
+
border-radius: 8px;
|
|
422
|
+
overflow: hidden;
|
|
423
|
+
flex-shrink: 0;
|
|
424
|
+
background: ${s.bg};
|
|
425
|
+
border: 1px solid ${s.border};
|
|
426
|
+
}
|
|
427
|
+
|
|
428
|
+
.pp-preview-img {
|
|
429
|
+
width: 100%;
|
|
430
|
+
height: 100%;
|
|
431
|
+
object-fit: cover;
|
|
432
|
+
}
|
|
433
|
+
|
|
434
|
+
.pp-preview-file {
|
|
435
|
+
width: 100%;
|
|
436
|
+
height: 100%;
|
|
437
|
+
display: flex;
|
|
438
|
+
align-items: center;
|
|
439
|
+
justify-content: center;
|
|
440
|
+
color: ${s.textSecondary};
|
|
441
|
+
}
|
|
442
|
+
|
|
443
|
+
.pp-preview-file svg {
|
|
444
|
+
width: 24px;
|
|
445
|
+
height: 24px;
|
|
446
|
+
}
|
|
447
|
+
|
|
448
|
+
.pp-remove-attachment {
|
|
449
|
+
position: absolute;
|
|
450
|
+
top: 2px;
|
|
451
|
+
right: 2px;
|
|
452
|
+
width: 18px;
|
|
453
|
+
height: 18px;
|
|
454
|
+
border-radius: 50%;
|
|
455
|
+
background: rgba(0, 0, 0, 0.6);
|
|
456
|
+
color: white;
|
|
457
|
+
border: none;
|
|
458
|
+
cursor: pointer;
|
|
459
|
+
display: flex;
|
|
460
|
+
align-items: center;
|
|
461
|
+
justify-content: center;
|
|
462
|
+
padding: 0;
|
|
463
|
+
}
|
|
464
|
+
|
|
465
|
+
.pp-remove-attachment svg {
|
|
466
|
+
width: 10px;
|
|
467
|
+
height: 10px;
|
|
468
|
+
}
|
|
469
|
+
|
|
470
|
+
.pp-upload-progress {
|
|
471
|
+
position: absolute;
|
|
472
|
+
bottom: 0;
|
|
473
|
+
left: 0;
|
|
474
|
+
height: 3px;
|
|
475
|
+
background: ${t};
|
|
476
|
+
transition: width 0.1s;
|
|
477
|
+
}
|
|
478
|
+
|
|
479
|
+
.pp-upload-error {
|
|
480
|
+
position: absolute;
|
|
481
|
+
top: 50%;
|
|
482
|
+
left: 50%;
|
|
483
|
+
transform: translate(-50%, -50%);
|
|
484
|
+
width: 24px;
|
|
485
|
+
height: 24px;
|
|
486
|
+
border-radius: 50%;
|
|
487
|
+
background: #ef4444;
|
|
488
|
+
color: white;
|
|
489
|
+
font-weight: bold;
|
|
490
|
+
display: flex;
|
|
491
|
+
align-items: center;
|
|
492
|
+
justify-content: center;
|
|
493
|
+
font-size: 14px;
|
|
494
|
+
}
|
|
495
|
+
|
|
496
|
+
.pp-attachment-uploading {
|
|
497
|
+
opacity: 0.7;
|
|
498
|
+
}
|
|
499
|
+
|
|
500
|
+
.pp-attachment-error {
|
|
501
|
+
border-color: #ef4444;
|
|
502
|
+
}
|
|
503
|
+
|
|
504
|
+
/* Message Attachments */
|
|
505
|
+
.pp-message-attachments {
|
|
506
|
+
display: flex;
|
|
507
|
+
flex-direction: column;
|
|
508
|
+
gap: 8px;
|
|
509
|
+
margin-top: 4px;
|
|
510
|
+
}
|
|
511
|
+
|
|
512
|
+
.pp-attachment {
|
|
513
|
+
display: block;
|
|
514
|
+
text-decoration: none;
|
|
515
|
+
color: inherit;
|
|
516
|
+
border-radius: 8px;
|
|
517
|
+
overflow: hidden;
|
|
518
|
+
}
|
|
519
|
+
|
|
520
|
+
.pp-attachment-image img {
|
|
521
|
+
max-width: 200px;
|
|
522
|
+
max-height: 200px;
|
|
523
|
+
border-radius: 8px;
|
|
524
|
+
display: block;
|
|
525
|
+
}
|
|
526
|
+
|
|
527
|
+
.pp-attachment-audio {
|
|
528
|
+
display: flex;
|
|
529
|
+
flex-direction: column;
|
|
530
|
+
gap: 4px;
|
|
531
|
+
}
|
|
532
|
+
|
|
533
|
+
.pp-attachment-audio audio {
|
|
534
|
+
width: 200px;
|
|
535
|
+
height: 36px;
|
|
536
|
+
}
|
|
537
|
+
|
|
538
|
+
.pp-attachment-audio .pp-attachment-name {
|
|
539
|
+
font-size: 11px;
|
|
540
|
+
opacity: 0.7;
|
|
541
|
+
white-space: nowrap;
|
|
542
|
+
overflow: hidden;
|
|
543
|
+
text-overflow: ellipsis;
|
|
544
|
+
max-width: 200px;
|
|
545
|
+
}
|
|
546
|
+
|
|
547
|
+
.pp-attachment-video video {
|
|
548
|
+
max-width: 200px;
|
|
549
|
+
max-height: 200px;
|
|
550
|
+
border-radius: 8px;
|
|
551
|
+
display: block;
|
|
552
|
+
}
|
|
553
|
+
|
|
554
|
+
.pp-attachment-file {
|
|
555
|
+
display: flex;
|
|
556
|
+
align-items: center;
|
|
557
|
+
gap: 8px;
|
|
558
|
+
padding: 8px 12px;
|
|
559
|
+
background: ${n?"rgba(255,255,255,0.1)":"rgba(0,0,0,0.05)"};
|
|
560
|
+
border-radius: 8px;
|
|
561
|
+
transition: background 0.2s;
|
|
562
|
+
}
|
|
563
|
+
|
|
564
|
+
.pp-attachment-file:hover {
|
|
565
|
+
background: ${n?"rgba(255,255,255,0.15)":"rgba(0,0,0,0.08)"};
|
|
566
|
+
}
|
|
567
|
+
|
|
568
|
+
.pp-attachment-file svg {
|
|
569
|
+
width: 24px;
|
|
570
|
+
height: 24px;
|
|
571
|
+
flex-shrink: 0;
|
|
572
|
+
}
|
|
573
|
+
|
|
574
|
+
.pp-attachment-info {
|
|
575
|
+
display: flex;
|
|
576
|
+
flex-direction: column;
|
|
577
|
+
min-width: 0;
|
|
578
|
+
}
|
|
579
|
+
|
|
580
|
+
.pp-attachment-name {
|
|
581
|
+
font-size: 13px;
|
|
582
|
+
font-weight: 500;
|
|
583
|
+
white-space: nowrap;
|
|
584
|
+
overflow: hidden;
|
|
585
|
+
text-overflow: ellipsis;
|
|
586
|
+
}
|
|
587
|
+
|
|
588
|
+
.pp-attachment-size {
|
|
589
|
+
font-size: 11px;
|
|
590
|
+
opacity: 0.7;
|
|
591
|
+
}
|
|
592
|
+
|
|
593
|
+
/* Drag & Drop */
|
|
594
|
+
.pp-dragging {
|
|
595
|
+
position: relative;
|
|
596
|
+
}
|
|
597
|
+
|
|
598
|
+
.pp-drop-overlay {
|
|
599
|
+
position: absolute;
|
|
600
|
+
inset: 0;
|
|
601
|
+
background: ${n?"rgba(0,0,0,0.9)":"rgba(255,255,255,0.95)"};
|
|
602
|
+
display: flex;
|
|
603
|
+
flex-direction: column;
|
|
604
|
+
align-items: center;
|
|
605
|
+
justify-content: center;
|
|
606
|
+
gap: 12px;
|
|
607
|
+
z-index: 100;
|
|
608
|
+
border: 3px dashed ${t};
|
|
609
|
+
border-radius: 16px;
|
|
610
|
+
margin: 4px;
|
|
611
|
+
pointer-events: none;
|
|
612
|
+
}
|
|
613
|
+
|
|
614
|
+
.pp-drop-icon svg {
|
|
615
|
+
width: 48px;
|
|
616
|
+
height: 48px;
|
|
617
|
+
color: ${t};
|
|
618
|
+
}
|
|
619
|
+
|
|
620
|
+
.pp-drop-text {
|
|
621
|
+
font-size: 16px;
|
|
622
|
+
font-weight: 500;
|
|
623
|
+
color: ${s.text};
|
|
624
|
+
}
|
|
625
|
+
|
|
626
|
+
/* Message Context Menu */
|
|
627
|
+
.pp-message-menu {
|
|
628
|
+
position: fixed;
|
|
629
|
+
background: ${s.bg};
|
|
630
|
+
border: 1px solid ${s.border};
|
|
631
|
+
border-radius: 8px;
|
|
632
|
+
box-shadow: 0 4px 12px rgba(0,0,0,0.15);
|
|
633
|
+
padding: 4px;
|
|
634
|
+
z-index: 200;
|
|
635
|
+
min-width: 120px;
|
|
636
|
+
}
|
|
637
|
+
|
|
638
|
+
.pp-message-menu button {
|
|
639
|
+
display: flex;
|
|
640
|
+
align-items: center;
|
|
641
|
+
gap: 8px;
|
|
642
|
+
width: 100%;
|
|
643
|
+
padding: 8px 12px;
|
|
644
|
+
border: none;
|
|
645
|
+
background: transparent;
|
|
646
|
+
color: ${s.text};
|
|
647
|
+
font-size: 13px;
|
|
648
|
+
cursor: pointer;
|
|
649
|
+
border-radius: 4px;
|
|
650
|
+
text-align: left;
|
|
651
|
+
}
|
|
652
|
+
|
|
653
|
+
.pp-message-menu button:hover {
|
|
654
|
+
background: ${n?"rgba(255,255,255,0.1)":"rgba(0,0,0,0.05)"};
|
|
655
|
+
}
|
|
656
|
+
|
|
657
|
+
.pp-message-menu button svg {
|
|
658
|
+
width: 16px;
|
|
659
|
+
height: 16px;
|
|
660
|
+
}
|
|
661
|
+
|
|
662
|
+
.pp-menu-delete {
|
|
663
|
+
color: #ef4444 !important;
|
|
664
|
+
}
|
|
665
|
+
|
|
666
|
+
/* Edit Modal */
|
|
667
|
+
.pp-edit-modal {
|
|
668
|
+
position: absolute;
|
|
669
|
+
bottom: 80px;
|
|
670
|
+
left: 12px;
|
|
671
|
+
right: 12px;
|
|
672
|
+
background: ${s.bg};
|
|
673
|
+
border: 1px solid ${s.border};
|
|
674
|
+
border-radius: 12px;
|
|
675
|
+
box-shadow: 0 4px 20px rgba(0,0,0,0.15);
|
|
676
|
+
z-index: 150;
|
|
677
|
+
overflow: hidden;
|
|
678
|
+
}
|
|
679
|
+
|
|
680
|
+
.pp-edit-header {
|
|
681
|
+
display: flex;
|
|
682
|
+
justify-content: space-between;
|
|
683
|
+
align-items: center;
|
|
684
|
+
padding: 12px 16px;
|
|
685
|
+
border-bottom: 1px solid ${s.border};
|
|
686
|
+
font-weight: 500;
|
|
687
|
+
}
|
|
688
|
+
|
|
689
|
+
.pp-edit-header button {
|
|
690
|
+
background: transparent;
|
|
691
|
+
border: none;
|
|
692
|
+
color: ${s.textSecondary};
|
|
693
|
+
cursor: pointer;
|
|
694
|
+
padding: 4px;
|
|
695
|
+
}
|
|
696
|
+
|
|
697
|
+
.pp-edit-header button svg {
|
|
698
|
+
width: 18px;
|
|
699
|
+
height: 18px;
|
|
700
|
+
}
|
|
701
|
+
|
|
702
|
+
.pp-edit-input {
|
|
703
|
+
width: 100%;
|
|
704
|
+
padding: 12px 16px;
|
|
705
|
+
border: none;
|
|
706
|
+
background: transparent;
|
|
707
|
+
color: ${s.text};
|
|
708
|
+
font-size: 14px;
|
|
709
|
+
resize: none;
|
|
710
|
+
min-height: 80px;
|
|
711
|
+
outline: none;
|
|
712
|
+
}
|
|
713
|
+
|
|
714
|
+
.pp-edit-actions {
|
|
715
|
+
display: flex;
|
|
716
|
+
justify-content: flex-end;
|
|
717
|
+
gap: 8px;
|
|
718
|
+
padding: 12px 16px;
|
|
719
|
+
border-top: 1px solid ${s.border};
|
|
720
|
+
}
|
|
721
|
+
|
|
722
|
+
.pp-edit-cancel {
|
|
723
|
+
padding: 8px 16px;
|
|
724
|
+
border: 1px solid ${s.border};
|
|
725
|
+
border-radius: 6px;
|
|
726
|
+
background: transparent;
|
|
727
|
+
color: ${s.text};
|
|
728
|
+
font-size: 13px;
|
|
729
|
+
cursor: pointer;
|
|
730
|
+
}
|
|
731
|
+
|
|
732
|
+
.pp-edit-save {
|
|
733
|
+
padding: 8px 16px;
|
|
734
|
+
border: none;
|
|
735
|
+
border-radius: 6px;
|
|
736
|
+
background: ${t};
|
|
737
|
+
color: white;
|
|
738
|
+
font-size: 13px;
|
|
739
|
+
cursor: pointer;
|
|
740
|
+
}
|
|
741
|
+
|
|
742
|
+
.pp-edit-save:disabled {
|
|
743
|
+
opacity: 0.5;
|
|
744
|
+
cursor: not-allowed;
|
|
745
|
+
}
|
|
746
|
+
|
|
747
|
+
/* Reply Preview */
|
|
748
|
+
.pp-reply-preview {
|
|
749
|
+
display: flex;
|
|
750
|
+
align-items: center;
|
|
751
|
+
gap: 8px;
|
|
752
|
+
padding: 8px 12px;
|
|
753
|
+
background: ${n?"rgba(255,255,255,0.05)":"rgba(0,0,0,0.03)"};
|
|
754
|
+
border-top: 1px solid ${s.border};
|
|
755
|
+
border-left: 3px solid ${t};
|
|
756
|
+
}
|
|
757
|
+
|
|
758
|
+
.pp-reply-preview-content {
|
|
759
|
+
flex: 1;
|
|
760
|
+
min-width: 0;
|
|
761
|
+
}
|
|
762
|
+
|
|
763
|
+
.pp-reply-label {
|
|
764
|
+
display: block;
|
|
765
|
+
font-size: 11px;
|
|
766
|
+
color: ${t};
|
|
767
|
+
font-weight: 500;
|
|
768
|
+
margin-bottom: 2px;
|
|
769
|
+
}
|
|
770
|
+
|
|
771
|
+
.pp-reply-text {
|
|
772
|
+
display: block;
|
|
773
|
+
font-size: 12px;
|
|
774
|
+
color: ${s.textSecondary};
|
|
775
|
+
white-space: nowrap;
|
|
776
|
+
overflow: hidden;
|
|
777
|
+
text-overflow: ellipsis;
|
|
778
|
+
}
|
|
779
|
+
|
|
780
|
+
.pp-reply-cancel {
|
|
781
|
+
background: transparent;
|
|
782
|
+
border: none;
|
|
783
|
+
color: ${s.textSecondary};
|
|
784
|
+
cursor: pointer;
|
|
785
|
+
padding: 4px;
|
|
786
|
+
flex-shrink: 0;
|
|
787
|
+
}
|
|
788
|
+
|
|
789
|
+
.pp-reply-cancel svg {
|
|
790
|
+
width: 16px;
|
|
791
|
+
height: 16px;
|
|
792
|
+
}
|
|
793
|
+
|
|
794
|
+
/* Reply Quote in Message */
|
|
795
|
+
.pp-reply-quote {
|
|
796
|
+
background: ${n?"rgba(255,255,255,0.1)":"rgba(0,0,0,0.05)"};
|
|
797
|
+
border-left: 2px solid ${t};
|
|
798
|
+
padding: 4px 8px;
|
|
799
|
+
margin-bottom: 6px;
|
|
800
|
+
border-radius: 0 4px 4px 0;
|
|
801
|
+
font-size: 12px;
|
|
802
|
+
}
|
|
803
|
+
|
|
804
|
+
.pp-reply-sender {
|
|
805
|
+
display: block;
|
|
806
|
+
font-weight: 500;
|
|
807
|
+
color: ${t};
|
|
808
|
+
margin-bottom: 2px;
|
|
809
|
+
}
|
|
810
|
+
|
|
811
|
+
.pp-reply-content {
|
|
812
|
+
display: block;
|
|
813
|
+
color: ${s.textSecondary};
|
|
814
|
+
white-space: nowrap;
|
|
815
|
+
overflow: hidden;
|
|
816
|
+
text-overflow: ellipsis;
|
|
817
|
+
}
|
|
818
|
+
|
|
819
|
+
/* Deleted Message */
|
|
820
|
+
.pp-message-deleted {
|
|
821
|
+
opacity: 0.6;
|
|
822
|
+
}
|
|
823
|
+
|
|
824
|
+
.pp-deleted-content {
|
|
825
|
+
font-style: italic;
|
|
826
|
+
color: ${s.textSecondary};
|
|
827
|
+
display: flex;
|
|
828
|
+
align-items: center;
|
|
829
|
+
gap: 4px;
|
|
830
|
+
}
|
|
831
|
+
|
|
832
|
+
.pp-deleted-icon {
|
|
833
|
+
font-size: 12px;
|
|
834
|
+
}
|
|
835
|
+
|
|
836
|
+
/* Edited Badge */
|
|
837
|
+
.pp-edited-badge {
|
|
838
|
+
font-size: 10px;
|
|
839
|
+
color: ${s.textSecondary};
|
|
840
|
+
margin-left: 4px;
|
|
841
|
+
font-style: italic;
|
|
842
|
+
}
|
|
843
|
+
`}var pn=0;function o(t,e,n,s,i,r){e||(e={});var a,c,u=e;if("ref"in u)for(c in u={},e)c=="ref"?a=e[c]:u[c]=e[c];var l={type:t,props:u,key:n,ref:a,__k:null,__:null,__b:0,__e:null,__c:null,constructor:void 0,__v:--pn,__i:-1,__u:0,__source:i,__self:r};if(typeof t=="function"&&(a=t.defaultProps))for(c in a)u[c]===void 0&&(u[c]=a[c]);return k.vnode&&k.vnode(l),l}function dt({client:t,config:e}){let[n,s]=R(!1),[i,r]=R([]),[a,c]=R(""),[u,l]=R(!1),[h,p]=R(!1),[g,f]=R(!1),[P,$]=R(0),[E,m]=R([]),[w,D]=R(!1),[H,B]=R(null),[U,X]=R(null),[W,F]=R(""),[O,A]=R(null),[z,ue]=R(!1),[N,ge]=R(e),he=Y(null),fe=Y(null),$e=Y(null),It=Y(null);j(()=>{let d=t.on("openChange",s),v=t.on("message",()=>{r([...t.getMessages()])}),S=t.on("typing",_=>{l(_.isTyping)}),b=t.on("presence",_=>{p(_.online)}),y=t.on("connect",()=>{f(!0),r(t.getMessages()),p(t.getSession()?.operatorOnline??!1),ge(t.getConfig())}),M=t.on("configUpdate",()=>{ge(t.getConfig())});return t.isConnected()&&(f(!0),r(t.getMessages()),p(t.getSession()?.operatorOnline??!1),ge(t.getConfig())),()=>{d(),v(),S(),b(),y(),M()}},[t]),j(()=>{n&&he.current?.scrollIntoView({behavior:"smooth"})},[i,n]),j(()=>{n&&(setTimeout(()=>{he.current?.scrollIntoView({behavior:"auto"})},50),fe.current?.focus(),$(0))},[n]),j(()=>{if(!n&&i.length>0){let d=i.filter(v=>v.sender!=="visitor"&&v.status!=="read").length;$(d)}},[i,n]);let ne=rt(()=>{if(!n||!g)return;let d=i.filter(v=>v.sender!=="visitor"&&v.status!=="read");if(d.length>0){let v=d.map(S=>S.id);t.sendReadStatus(v,"read")}},[n,g,i,t]);if(j(()=>{if(!n||!g)return;let d=setTimeout(()=>{ne()},1e3);return()=>clearTimeout(d)},[n,g,i,ne]),j(()=>{let d=()=>{document.visibilityState==="visible"&&n&&ne()};return document.addEventListener("visibilitychange",d),()=>document.removeEventListener("visibilitychange",d)},[n,ne]),j(()=>{let d=t.on("read",()=>{r([...t.getMessages()])});return()=>d()},[t]),!ln(N))return null;let Tt=async d=>{d.preventDefault();let v=a.trim().length>0,S=E.filter(_=>_.status==="ready"&&_.attachment);if(!v&&S.length===0)return;let b=a,y=S.map(_=>_.attachment.id),M=H?.id;c(""),m([]),B(null);try{await t.sendMessage(b,y,M)}catch(_){console.error("[PocketPing] Failed to send message:",_)}},$t=d=>{let v=d.target;c(v.value),t.sendTyping(!0)},At=async d=>{let v=d.target,S=v.files;if(!S||S.length===0)return;let b=[];for(let y=0;y<S.length;y++){let M=S[y],_=`pending-${Date.now()}-${y}`,I;M.type.startsWith("image/")&&(I=URL.createObjectURL(M)),b.push({id:_,file:M,preview:I,progress:0,status:"pending"})}m(y=>[...y,...b]),v.value="",D(!0);for(let y of b)try{m(_=>_.map(I=>I.id===y.id?{...I,status:"uploading"}:I));let M=await t.uploadFile(y.file,_=>{m(I=>I.map(me=>me.id===y.id?{...me,progress:_}:me))});m(_=>_.map(I=>I.id===y.id?{...I,status:"ready",progress:100,attachment:M}:I))}catch(M){console.error("[PocketPing] Failed to upload file:",M),m(_=>_.map(I=>I.id===y.id?{...I,status:"error",error:"Upload failed"}:I))}D(!1)},Rt=d=>{m(v=>{let S=v.find(b=>b.id===d);return S?.preview&&URL.revokeObjectURL(S.preview),v.filter(b=>b.id!==d)})},Ot=d=>{B(d),A(null),fe.current?.focus()},Dt=()=>{B(null)},Lt=d=>{d.sender==="visitor"&&(X(d),F(d.content),A(null))},Ae=()=>{X(null),F("")},Ht=async()=>{if(!(!U||!W.trim()))try{await t.editMessage(U.id,W.trim()),X(null),F("")}catch(d){console.error("[PocketPing] Failed to edit message:",d)}},Ft=async d=>{if(d.sender==="visitor"&&(A(null),confirm("Delete this message?")))try{await t.deleteMessage(d.id)}catch(v){console.error("[PocketPing] Failed to delete message:",v)}},Nt=(d,v)=>{d.preventDefault();let S=d;A({message:v,x:S.clientX,y:S.clientY})};j(()=>{if(!O)return;let d=()=>A(null);return document.addEventListener("click",d),()=>document.removeEventListener("click",d)},[O]);let K=Y(0),Ut=d=>{d.preventDefault(),d.stopPropagation(),K.current++,K.current===1&&ue(!0)},Wt=d=>{d.preventDefault(),d.stopPropagation()},zt=d=>{d.preventDefault(),d.stopPropagation(),K.current--,K.current===0&&ue(!1)},Vt=async d=>{d.preventDefault(),d.stopPropagation(),K.current=0,ue(!1);let v=d.dataTransfer?.files;if(!v||v.length===0)return;let S=[];for(let b=0;b<v.length;b++){let y=v[b],M=`pending-${Date.now()}-${b}`,_;y.type.startsWith("image/")&&(_=URL.createObjectURL(y)),S.push({id:M,file:y,preview:_,progress:0,status:"pending"})}m(b=>[...b,...S]),D(!0);for(let b of S)try{m(M=>M.map(_=>_.id===b.id?{..._,status:"uploading"}:_));let y=await t.uploadFile(b.file,M=>{m(_=>_.map(I=>I.id===b.id?{...I,progress:M}:I))});m(M=>M.map(_=>_.id===b.id?{..._,status:"ready",progress:100,attachment:y}:_))}catch(y){console.error("[PocketPing] Failed to upload dropped file:",y),m(M=>M.map(_=>_.id===b.id?{..._,status:"error",error:"Upload failed"}:_))}D(!1)},Re=N.position??"bottom-right",Oe=cn(N.theme??"auto"),jt=N.primaryColor??"#6366f1";return o(L,{children:[o("style",{children:lt(jt,Oe)}),o("button",{class:`pp-toggle pp-${Re}`,onClick:()=>t.toggleOpen(),"aria-label":n?"Close chat":"Open chat",children:[n?o(te,{}):o(un,{}),!n&&P>0&&o("span",{class:"pp-unread-badge",children:P>9?"9+":P}),!n&&P===0&&h&&o("span",{class:"pp-online-dot"})]}),n&&o("div",{class:`pp-window pp-${Re} pp-theme-${Oe} ${z?"pp-dragging":""}`,onDragEnter:Ut,onDragOver:Wt,onDragLeave:zt,onDrop:Vt,children:[z&&o("div",{class:"pp-drop-overlay",children:[o("div",{class:"pp-drop-icon",children:o(ct,{})}),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:h?o(L,{children:[o("span",{class:"pp-status-dot pp-online"})," Online"]}):o(L,{children:[o("span",{class:"pp-status-dot"})," Away"]})})]})]}),o("button",{class:"pp-close-btn",onClick:()=>t.setOpen(!1),"aria-label":"Close chat",children:o(te,{})})]}),o("div",{class:"pp-messages",ref:It,children:[N.welcomeMessage&&i.length===0&&o("div",{class:"pp-welcome",children:N.welcomeMessage}),i.map(d=>{let v=!!d.deletedAt,S=!!d.editedAt,b=d.replyTo?i.find(y=>y.id===d.replyTo):null;return o("div",{class:`pp-message pp-message-${d.sender} ${v?"pp-message-deleted":""}`,onContextMenu:y=>Nt(y,d),children:[b&&o("div",{class:"pp-reply-quote",children:[o("span",{class:"pp-reply-sender",children:b.sender==="visitor"?"You":"Support"}),o("span",{class:"pp-reply-content",children:[b.deletedAt?"Message deleted":b.content.slice(0,50),b.content.length>50?"...":""]})]}),v?o("div",{class:"pp-message-content pp-deleted-content",children:[o("span",{class:"pp-deleted-icon",children:"\u{1F5D1}\uFE0F"})," Message deleted"]}):o(L,{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(y=>o(vn,{attachment:y},y.id))})]}),o("div",{class:"pp-message-time",children:[dn(d.timestamp),S&&!v&&o("span",{class:"pp-edited-badge",children:"edited"}),d.sender==="ai"&&o("span",{class:"pp-ai-badge",children:"AI"}),d.sender==="visitor"&&!v&&o("span",{class:`pp-status pp-status-${d.status??"sent"}`,children:o(hn,{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:he})]}),O&&o("div",{class:"pp-message-menu",style:{top:`${O.y}px`,left:`${O.x}px`},children:[o("button",{onClick:()=>Ot(O.message),children:[o(fn,{})," Reply"]}),O.message.sender==="visitor"&&!O.message.deletedAt&&o(L,{children:[o("button",{onClick:()=>Lt(O.message),children:[o(mn,{})," Edit"]}),o("button",{class:"pp-menu-delete",onClick:()=>Ft(O.message),children:[o(_n,{})," Delete"]})]})]}),U&&o("div",{class:"pp-edit-modal",children:[o("div",{class:"pp-edit-header",children:[o("span",{children:"Edit message"}),o("button",{onClick:Ae,children:o(te,{})})]}),o("textarea",{class:"pp-edit-input",value:W,onInput:d=>F(d.target.value),autoFocus:!0}),o("div",{class:"pp-edit-actions",children:[o("button",{class:"pp-edit-cancel",onClick:Ae,children:"Cancel"}),o("button",{class:"pp-edit-save",onClick:Ht,disabled:!W.trim(),children:"Save"})]})]}),H&&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:[H.content.slice(0,50),H.content.length>50?"...":""]})]}),o("button",{class:"pp-reply-cancel",onClick:Dt,children:o(te,{})})]}),E.length>0&&o("div",{class:"pp-attachments-preview",children:E.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(ut,{mimeType:d.file.type})}),o("button",{class:"pp-remove-attachment",onClick:()=>Rt(d.id),"aria-label":"Remove attachment",type:"button",children:o(te,{})}),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:Tt,children:[o("input",{ref:d=>{$e.current=d,d&&(d.onchange=At)},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:()=>$e.current?.click(),disabled:!g||w,"aria-label":"Attach file",children:o(ct,{})}),o("input",{ref:fe,type:"text",class:"pp-input",placeholder:N.placeholder??"Type a message...",value:a,onInput:$t,disabled:!g}),o("button",{type:"submit",class:"pp-send-btn",disabled:!a.trim()&&E.filter(d=>d.status==="ready").length===0||!g||w,"aria-label":"Send message",children:o(gn,{})})]}),o("div",{class:"pp-footer",children:["Powered by ",o("a",{href:"https://pocketping.io",target:"_blank",rel:"noopener",children:"PocketPing"})]})]})]})}function ln(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 cn(t){return t==="auto"?window.matchMedia("(prefers-color-scheme: dark)").matches?"dark":"light":t}function dn(t){return new Date(t).toLocaleTimeString([],{hour:"2-digit",minute:"2-digit"})}function un(){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 te(){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 gn(){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 hn({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 ct(){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 fn(){return o("svg",{viewBox:"0 0 24 24",fill:"none",stroke:"currentColor","stroke-width":"2",children:[o("polyline",{points:"9 17 4 12 9 7"}),o("path",{d:"M20 18v-2a4 4 0 0 0-4-4H4"})]})}function mn(){return o("svg",{viewBox:"0 0 24 24",fill:"none",stroke:"currentColor","stroke-width":"2",children:o("path",{d:"M17 3a2.828 2.828 0 1 1 4 4L7.5 20.5 2 22l1.5-5.5L17 3z"})})}function _n(){return o("svg",{viewBox:"0 0 24 24",fill:"none",stroke:"currentColor","stroke-width":"2",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 ut({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 vn({attachment:t}){let e=t.mimeType.startsWith("image/"),n=t.mimeType.startsWith("audio/"),s=t.mimeType.startsWith("video/"),i=r=>r<1024?`${r} B`:r<1024*1024?`${(r/1024).toFixed(1)} KB`:`${(r/(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(ut,{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 ce="0.3.6";var de=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(),r=new URLSearchParams(window.location.search).get("pp_inspector"),a=await this.fetch("/connect",{method:"POST",body:JSON.stringify({visitorId:e,sessionId:n,inspectorToken:r||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:a.sessionId,visitorId:a.visitorId,operatorOnline:a.operatorOnline??!1,messages:a.messages??[],identity:a.identity||s||void 0},a.operatorName&&(this.config.operatorName=a.operatorName),a.operatorAvatar&&(this.config.operatorAvatar=a.operatorAvatar),a.primaryColor&&(this.config.primaryColor=a.primaryColor),a.welcomeMessage&&(this.config.welcomeMessage=a.welcomeMessage),this.emit("configUpdate",{operatorName:this.config.operatorName,operatorAvatar:this.config.operatorAvatar,primaryColor:this.config.primaryColor,welcomeMessage:this.config.welcomeMessage}),this.storeSessionId(a.sessionId),this.connectRealtime(),a.inspectorMode?this.enableInspectorMode():a.trackedElements?.length&&this.setupTrackedElements(a.trackedElements),this.emit("connect",this.session),this.config.onConnect?.(a.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()}`,r={id:i,sessionId:this.session.sessionId,content:e,sender:"visitor",timestamp:new Date().toISOString(),status:"sending",replyTo:s};this.session.messages.push(r),this.emit("message",r);try{let a=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=a.messageId,this.session.messages[c].timestamp=a.timestamp,this.session.messages[c].status="sent",a.attachments&&a.attachments.length>0&&(this.session.messages[c].attachments=a.attachments),this.emit("message",this.session.messages[c]));let u=this.session.messages[c]||{id:a.messageId,sessionId:this.session.sessionId,content:e,sender:"visitor",timestamp:a.timestamp,status:"sent",attachments:a.attachments};return this.config.onMessage?.(u),u}catch(a){let c=this.session.messages.findIndex(u=>u.id===i);throw c>=0&&(this.session.messages.splice(c,1),this.emit("message",r)),a}}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,r=>{let a=10+r*.8;n?.(a),this.emit("uploadProgress",{filename:e.name,progress:a})});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 r=0;r<i;r++){let a=e[r],c=r/i*100,u=100/i,l=await this.uploadFile(a,h=>{let p=c+h/100*u;n?.(p)});s.push(l)}return s}uploadToPresignedUrl(e,n,s){return new Promise((i,r)=>{let a=new XMLHttpRequest;a.upload.addEventListener("progress",c=>{if(c.lengthComputable){let u=c.loaded/c.total*100;s?.(u)}}),a.addEventListener("load",()=>{a.status>=200&&a.status<300?i():r(new Error(`Upload failed with status ${a.status}`))}),a.addEventListener("error",()=>{r(new Error("Upload failed"))}),a.open("PUT",e),a.setRequestHeader("Content-Type",n.type||"application/octet-stream"),a.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(r=>r.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}`,{method:"DELETE",body:JSON.stringify({sessionId:this.session.sessionId})});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=a=>{let c={...n.data,selector:n.selector,elementText:a.target?.textContent?.trim().slice(0,100),url:window.location.href};this.trigger(n.name,c,{widgetMessage:n.widgetMessage})},r=a=>{a.target?.closest(n.selector)&&i(a)};document.addEventListener(s,r,!0),this.trackedElementCleanups.push(()=>{document.removeEventListener(s,r,!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=`
|
|
358
844
|
<style>
|
|
359
845
|
#pp-inspector-overlay {
|
|
360
846
|
position: fixed;
|
|
@@ -437,9 +923,9 @@
|
|
|
437
923
|
<button id="pp-inspector-exit">Exit</button>
|
|
438
924
|
</div>
|
|
439
925
|
<div id="pp-inspector-tooltip"></div>
|
|
440
|
-
`,document.body.appendChild(e);let n=document.getElementById("pp-inspector-tooltip"),s=null,i=
|
|
926
|
+
`,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(g=>!g.startsWith("pp-"));if(l.length>0){let g="."+l.map(f=>CSS.escape(f)).join(".");if(document.querySelectorAll(g).length===1)return g}for(let g of Array.from(u.attributes))if(g.name.startsWith("data-")&&g.value){let f=`[${g.name}="${CSS.escape(g.value)}"]`;if(document.querySelectorAll(f).length===1)return f}let h=[],p=u;for(;p&&p!==document.body;){let g=p.tagName.toLowerCase();if(p.id&&!p.id.startsWith("pp-")){g=`#${CSS.escape(p.id)}`,h.unshift(g);break}let f=p.parentElement;if(f){let P=p.tagName,$=Array.from(f.children).filter(E=>E.tagName===P);if($.length>1){let E=$.indexOf(p)+1;g+=`:nth-of-type(${E})`}}h.unshift(g),p=f}return h.join(" > ")},r=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 h=i(l);n.textContent=h,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`)},a=u=>{let l=u.target;l.closest("#pp-inspector-overlay")||(l.classList.remove("pp-inspector-highlight"),n.style.display="none")},c=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 h=i(l);this.ws&&this.ws.readyState===WebSocket.OPEN&&this.ws.send(JSON.stringify({type:"inspector_select",data:{selector:h,tagName:l.tagName.toLowerCase(),text:l.textContent?.trim().slice(0,50)||"",url:window.location.href}})),this.emit("inspectorSelect",{selector:h,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 g=p.innerHTML;p.innerHTML=`
|
|
441
927
|
<svg width="20" height="20" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2">
|
|
442
928
|
<polyline points="20 6 9 17 4 12"/>
|
|
443
929
|
</svg>
|
|
444
|
-
<span>Selector captured: <code style="background:rgba(255,255,255,0.2);padding:2px 6px;border-radius:4px;font-family:monospace;">${
|
|
445
|
-
`,setTimeout(()=>{r&&this.inspectorMode&&(r.innerHTML=d,document.getElementById("pp-inspector-exit")?.addEventListener("click",()=>{this.disableInspectorMode()}))},2e3)}console.info(`[PocketPing] \u{1F4CC} Selector captured: ${g}`)};document.addEventListener("mouseover",o,!0),document.addEventListener("mouseout",a,!0),document.addEventListener("click",c,!0),this.inspectorCleanup=()=>{document.removeEventListener("mouseover",o,!0),document.removeEventListener("mouseout",a,!0),document.removeEventListener("click",c,!0),e.remove(),s&&s.classList.remove("pp-inspector-highlight")},document.getElementById("pp-inspector-exit")?.addEventListener("click",()=>{this.disableInspectorMode()})}disableInspectorMode(){this.inspectorMode&&(this.inspectorMode=!1,this.inspectorCleanup&&(this.inspectorCleanup(),this.inspectorCleanup=null),console.info("[PocketPing] Inspector mode disabled"),this.emit("inspectorDisabled",null))}isInspectorModeActive(){return this.inspectorMode}connectWebSocket(){if(!this.session)return;if(this.usePollingFallback){this.startPolling();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(),this.ws.onopen=()=>{this.reconnectAttempts=0,this.wsConnectedAt=Date.now(),this.emit("wsConnected",null)},this.ws.onmessage=n=>{try{let s=JSON.parse(n.data);this.handleWebSocketEvent(s)}catch(s){console.error("[PocketPing] Failed to parse WS message:",s)}},this.ws.onclose=()=>{this.emit("wsDisconnected",null),this.handleWsFailure()},this.ws.onerror=()=>{}}catch{console.warn("[PocketPing] WebSocket unavailable, using polling"),this.usePollingFallback=!0,this.startPolling()}}handleWsFailure(){if(Date.now()-this.wsConnectedAt<this.quickFailureThreshold&&(this.reconnectAttempts++,this.reconnectAttempts>=2)){console.info("[PocketPing] WebSocket not available (serverless?), using polling"),this.usePollingFallback=!0,this.startPolling();return}this.scheduleReconnect()}handleWebSocketEvent(e){switch(e.type){case"message":let n=e.data;if(this.session){let p=this.session.messages.findIndex(l=>l.id===n.id);if(p<0&&n.sender==="visitor"&&(p=this.session.messages.findIndex(l=>l.id.startsWith("temp-")&&l.content===n.content&&l.sender==="visitor"),p>=0&&(this.session.messages[p].id=n.id)),p<0&&n.sender!=="visitor"){let l=new Date(n.timestamp).getTime();p=this.session.messages.findIndex(g=>g.sender===n.sender&&g.content===n.content&&Math.abs(new Date(g.timestamp).getTime()-l)<2e3)}if(p>=0){let l=this.session.messages[p];n.status&&n.status!==l.status&&(l.status=n.status,n.deliveredAt&&(l.deliveredAt=n.deliveredAt),n.readAt&&(l.readAt=n.readAt),this.emit("read",{messageIds:[n.id],status:n.status}))}else this.session.messages.push(n),this.emit("message",n),this.config.onMessage?.(n)}n.sender!=="visitor"&&this.emit("typing",{isTyping:!1});break;case"typing":let s=e.data;s.sender!=="visitor"&&this.emit("typing",{isTyping:s.isTyping});break;case"presence":this.session&&(this.session.operatorOnline=e.data.online),this.emit("presence",e.data);break;case"ai_takeover":this.emit("aiTakeover",e.data);break;case"read":let i=e.data;if(this.session)for(let p of this.session.messages)i.messageIds.includes(p.id)&&(p.status=i.status,i.deliveredAt&&(p.deliveredAt=i.deliveredAt),i.readAt&&(p.readAt=i.readAt));this.emit("read",i);break;case"event":let o=e.data;this.emitCustomEvent(o);break;case"version_warning":let a=e.data;this.handleVersionWarning(a);break;case"config_update":let c=e.data;c.trackedElements&&(this.setupTrackedElements(c.trackedElements),this.emit("configUpdate",c));break}}handleVersionWarning(e){let n="[PocketPing]",s=e.upgradeUrl?` Upgrade: ${e.upgradeUrl}`:" Update your widget to the latest version.";switch(e.severity){case"error":console.error(`${n} \u{1F6A8} VERSION ERROR: ${e.message}${s}`),console.error(`${n} Current: ${e.currentVersion}, Required: ${e.minVersion||"unknown"}`);break;case"warning":console.warn(`${n} \u26A0\uFE0F VERSION WARNING: ${e.message}${s}`),console.warn(`${n} Current: ${e.currentVersion}, Latest: ${e.latestVersion||"unknown"}`);break;case"info":console.info(`${n} \u2139\uFE0F ${e.message}`);break}this.emit("versionWarning",e),this.config.onVersionWarning?.(e),e.canContinue||(console.error(`${n} Widget is incompatible with backend. Please update immediately.`),this.disconnect())}scheduleReconnect(){if(this.reconnectAttempts>=this.maxReconnectAttempts){console.warn("[PocketPing] Max reconnect attempts reached, switching to polling"),this.startPolling();return}let e=Math.min(1e3*Math.pow(2,this.reconnectAttempts),3e4);this.reconnectAttempts++,this.reconnectTimeout=setTimeout(()=>{this.connectWebSocket()},e)}startPolling(){let e=async()=>{if(this.session){try{let n=this.session.messages[this.session.messages.length-1]?.id,s=await this.fetchMessages(n);this.pollingFailures=0;for(let i of s)this.session.messages.find(o=>o.id===i.id)||(this.session.messages.push(i),this.emit("message",i),this.config.onMessage?.(i))}catch{if(this.pollingFailures++,(this.pollingFailures<=3||this.pollingFailures%3===0)&&console.warn(`[PocketPing] Polling failed (${this.pollingFailures}/${this.maxPollingFailures})`),this.pollingFailures>=this.maxPollingFailures){console.error("[PocketPing] Polling disabled after too many failures. Real-time updates unavailable."),this.emit("pollingDisabled",{failures:this.pollingFailures});return}}if(this.session){let n=this.pollingFailures>0?Math.min(3e3*Math.pow(2,this.pollingFailures-1),3e4):3e3;this.pollingTimeout=setTimeout(e,n)}}};e()}stopPolling(){this.pollingTimeout&&(clearTimeout(this.pollingTimeout),this.pollingTimeout=null),this.pollingFailures=0}async fetch(e,n){let s=this.config.endpoint.replace(/\/$/,"")+e,i=await fetch(s,{...n,headers:{"Content-Type":"application/json","X-PocketPing-Version":K,...n.headers}});if(this.checkVersionHeaders(i),!i.ok){let o=await i.text();throw new Error(`PocketPing API error: ${i.status} ${o}`)}return i.json()}checkVersionHeaders(e){let n=e.headers.get("X-PocketPing-Version-Status"),s=e.headers.get("X-PocketPing-Min-Version"),i=e.headers.get("X-PocketPing-Latest-Version"),o=e.headers.get("X-PocketPing-Version-Message");if(!n||n==="ok")return;let a="info",c=!0;n==="deprecated"?a="warning":n==="unsupported"?(a="error",c=!1):n==="outdated"&&(a="info");let p={severity:a,message:o||`Widget version ${K} is ${n}`,currentVersion:K,minVersion:s||void 0,latestVersion:i||void 0,canContinue:c,upgradeUrl:"https://docs.pocketping.io/widget/installation"};this.handleVersionWarning(p)}getOrCreateVisitorId(){let e="pocketping_visitor_id",n=localStorage.getItem(e);return n||(n=this.generateId(),localStorage.setItem(e,n)),n}getStoredSessionId(){return localStorage.getItem("pocketping_session_id")}storeSessionId(e){localStorage.setItem("pocketping_session_id",e)}getStoredIdentity(){try{let e=localStorage.getItem("pocketping_user_identity");return e?JSON.parse(e):null}catch{return null}}storeIdentity(e){localStorage.setItem("pocketping_user_identity",JSON.stringify(e))}clearIdentity(){localStorage.removeItem("pocketping_user_identity")}generateId(){return`${Date.now().toString(36)}-${Math.random().toString(36).slice(2,11)}`}};var b=null,O=null,Ot="https://app.pocketping.io/api/widget";function fe(t){if(b)return console.warn("[PocketPing] Already initialized"),b;let e=t.endpoint;if(!e&&t.projectId&&(e=`${Ot}/${t.projectId}`),!e)throw new Error("[PocketPing] endpoint or projectId is required");let n={...t,endpoint:e};return b=new Q(n),O=document.createElement("div"),O.id="pocketping-container",document.body.appendChild(O),pe(ae(qe,{client:b,config:t}),O),b.connect().catch(s=>{console.error("[PocketPing] Failed to connect:",s)}),b}function Je(){O&&(pe(null,O),O.remove(),O=null),b&&(b.disconnect(),b=null)}function Xe(){b?.setOpen(!0)}function Ge(){b?.setOpen(!1)}function Ye(){b?.toggleOpen()}function Ze(t){if(!b)throw new Error("[PocketPing] Not initialized");return b.sendMessage(t)}function Ke(t,e,n){if(!b){console.warn("[PocketPing] Not initialized, cannot trigger event");return}b.trigger(t,e,n)}function Qe(t){if(!b){console.warn("[PocketPing] Not initialized, cannot setup tracked elements");return}b.setupTrackedElements(t)}function et(){return b?.getTrackedElements()||[]}function tt(t,e){return b?b.onEvent(t,e):(console.warn("[PocketPing] Not initialized, cannot subscribe to event"),()=>{})}function nt(t,e){b?.offEvent(t,e)}async function st(t){if(!b)throw new Error("[PocketPing] Not initialized");return b.identify(t)}async function it(t){if(!b){console.warn("[PocketPing] Not initialized");return}return b.reset(t)}function ot(){return b?.getIdentity()||null}function rt(t,e){return b?b.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)&&fe({projectId:e,endpoint:n,theme:t.dataset.theme||"auto",position:t.dataset.position||"bottom-right"})}}var Ht={init:fe,destroy:Je,open:Xe,close:Ge,toggle:Ye,sendMessage:Ze,trigger:Ke,onEvent:tt,offEvent:nt,on:rt,identify:st,reset:it,getIdentity:ot,setupTrackedElements:Qe,getTrackedElements:et};return ft(Rt);})();
|
|
930
|
+
<span>Selector captured: <code style="background:rgba(255,255,255,0.2);padding:2px 6px;border-radius:4px;font-family:monospace;">${h}</code></span>
|
|
931
|
+
`,setTimeout(()=>{p&&this.inspectorMode&&(p.innerHTML=g,document.getElementById("pp-inspector-exit")?.addEventListener("click",()=>{this.disableInspectorMode()}))},2e3)}console.info(`[PocketPing] \u{1F4CC} Selector captured: ${h}`)};document.addEventListener("mouseover",r,!0),document.addEventListener("mouseout",a,!0),document.addEventListener("click",c,!0),this.inspectorCleanup=()=>{document.removeEventListener("mouseover",r,!0),document.removeEventListener("mouseout",a,!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=this.config.endpoint.replace(/\/$/,"")+`/stream?sessionId=${this.session.sessionId}`;try{this.sse=new EventSource(e);let n=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(n),this.connectionMode="sse",this.emit("sseConnected",null)},this.sse.addEventListener("message",s=>{try{let i=JSON.parse(s.data);this.handleRealtimeEvent(i)}catch(i){console.error("[PocketPing] Failed to parse SSE message:",i)}}),this.sse.addEventListener("connected",()=>{}),this.sse.onerror=()=>{clearTimeout(n),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)}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(h=>h.sender===n.sender&&h.content===n.content&&Math.abs(new Date(h.timestamp).getTime()-l)<2e3)}if(u>=0){let l=this.session.messages[u];n.status&&n.status!==l.status&&(l.status=n.status,n.deliveredAt&&(l.deliveredAt=n.deliveredAt),n.readAt&&(l.readAt=n.readAt),this.emit("read",{messageIds:[n.id],status:n.status}))}else this.session.messages.push(n),this.emit("message",n),this.config.onMessage?.(n)}n.sender!=="visitor"&&this.emit("typing",{isTyping:!1});break;case"typing":let s=e.data;s.sender!=="visitor"&&this.emit("typing",{isTyping:s.isTyping});break;case"presence":this.session&&(this.session.operatorOnline=e.data.online),this.emit("presence",e.data);break;case"ai_takeover":this.emit("aiTakeover",e.data);break;case"read":let i=e.data;if(this.session)for(let 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"event":let r=e.data;this.emitCustomEvent(r);break;case"version_warning":let a=e.data;this.handleVersionWarning(a);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.session.messages[this.session.messages.length-1]?.id,s=await this.fetchMessages(n);this.pollingFailures=0;for(let i of s)this.session.messages.find(r=>r.id===i.id)||(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":ce,...n.headers}});if(this.checkVersionHeaders(i),!i.ok){let r=await i.text();throw new Error(`PocketPing API error: ${i.status} ${r}`)}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"),r=e.headers.get("X-PocketPing-Version-Message");if(!n||n==="ok")return;let a="info",c=!0;n==="deprecated"?a="warning":n==="unsupported"?(a="error",c=!1):n==="outdated"&&(a="info");let u={severity:a,message:r||`Widget version ${ce} is ${n}`,currentVersion:ce,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 x=null,q=null,xn="https://app.pocketping.io/api/widget";function Te(t){if(x)return console.warn("[PocketPing] Already initialized"),x;let e=t.endpoint;if(!e&&t.projectId&&(e=`${xn}/${t.projectId}`),!e)throw new Error("[PocketPing] endpoint or projectId is required");let n={...t,endpoint:e};return x=new de(n),q=document.createElement("div"),q.id="pocketping-container",document.body.appendChild(q),Se(ke(dt,{client:x,config:t}),q),x.connect().catch(s=>{console.error("[PocketPing] Failed to connect:",s)}),x}function gt(){q&&(Se(null,q),q.remove(),q=null),x&&(x.disconnect(),x=null)}function ht(){x?.setOpen(!0)}function ft(){x?.setOpen(!1)}function mt(){x?.toggleOpen()}function _t(t,e){if(!x)throw new Error("[PocketPing] Not initialized");return x.sendMessage(t,e)}async function vt(t,e){if(!x)throw new Error("[PocketPing] Not initialized");return x.uploadFile(t,e)}async function xt(t,e){if(!x)throw new Error("[PocketPing] Not initialized");return x.uploadFiles(t,e)}function yt(t,e,n){if(!x){console.warn("[PocketPing] Not initialized, cannot trigger event");return}x.trigger(t,e,n)}function bt(t){if(!x){console.warn("[PocketPing] Not initialized, cannot setup tracked elements");return}x.setupTrackedElements(t)}function wt(){return x?.getTrackedElements()||[]}function kt(t,e){return x?x.onEvent(t,e):(console.warn("[PocketPing] Not initialized, cannot subscribe to event"),()=>{})}function Et(t,e){x?.offEvent(t,e)}async function Pt(t){if(!x)throw new Error("[PocketPing] Not initialized");return x.identify(t)}async function St(t){if(!x){console.warn("[PocketPing] Not initialized");return}return x.reset(t)}function Mt(){return x?.getIdentity()||null}function Ct(t,e){return x?x.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)&&Te({projectId:e,endpoint:n,theme:t.dataset.theme||"auto",position:t.dataset.position||"bottom-right"})}}var yn={init:Te,destroy:gt,open:ht,close:ft,toggle:mt,sendMessage:_t,uploadFile:vt,uploadFiles:xt,trigger:yt,onEvent:kt,offEvent:Et,on:Ct,identify:Pt,reset:St,getIdentity:Mt,setupTrackedElements:bt,getTrackedElements:wt};return Yt(bn);})();
|