@bravophone/webphone 0.3.0 → 0.4.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.
@@ -1,26 +1,26 @@
1
- (function(W,U){typeof exports=="object"&&typeof module!="undefined"?module.exports=U():typeof define=="function"&&define.amd?define(U):(W=typeof globalThis!="undefined"?globalThis:W||self,W.Bravophone=U())})(this,function(){"use strict";const W='stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round"',U=`<svg viewBox="0 0 24 24" fill="none" ${W} aria-hidden="true">
1
+ (function(C,N){typeof exports=="object"&&typeof module!="undefined"?module.exports=N():typeof define=="function"&&define.amd?define(N):(C=typeof globalThis!="undefined"?globalThis:C||self,C.Bravophone=N())})(this,function(){"use strict";const C='stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round"',N=`<svg viewBox="0 0 24 24" fill="none" ${C} aria-hidden="true">
2
2
  <path class="bp-i-body" d="M15.6 12.8a11 11 0 0 1-4.4-4.4l1-1a1.6 1.6 0 0 0 .3-1.7c-.2-.7-.4-1.4-.5-2.2A1.6 1.6 0 0 0 10.4 2H7.9a1.6 1.6 0 0 0-1.6 1.8 15.8 15.8 0 0 0 2.4 6.9 15.6 15.6 0 0 0 4.8 4.8 15.8 15.8 0 0 0 6.9 2.4 1.6 1.6 0 0 0 1.7-1.6v-2.5a1.6 1.6 0 0 0-1.4-1.6c-.8-.1-1.5-.3-2.2-.5a1.6 1.6 0 0 0-1.7.4z"/>
3
3
  <path class="bp-i-wave bp-i-wave-1" d="M14.5 6.2a4 4 0 0 1 3.3 3.3"/>
4
4
  <path class="bp-i-wave bp-i-wave-2" d="M14.1 2.6a7.6 7.6 0 0 1 7.3 7.3"/>
5
- </svg>`,xe=`<svg viewBox="0 0 24 24" fill="none" ${W} aria-hidden="true">
5
+ </svg>`,xe=`<svg viewBox="0 0 24 24" fill="none" ${C} aria-hidden="true">
6
6
  <path class="bp-i-bar bp-i-bar-1" d="M4 10v4"/>
7
7
  <path class="bp-i-bar bp-i-bar-2" d="M8.7 6.5v11"/>
8
8
  <path class="bp-i-bar bp-i-bar-3" d="M12 3.5v17"/>
9
9
  <path class="bp-i-bar bp-i-bar-4" d="M15.3 6.5v11"/>
10
10
  <path class="bp-i-bar bp-i-bar-5" d="M20 10v4"/>
11
- </svg>`,we=`<svg viewBox="0 0 24 24" fill="none" ${W} aria-hidden="true">
11
+ </svg>`,we=`<svg viewBox="0 0 24 24" fill="none" ${C} aria-hidden="true">
12
12
  <path class="bp-i-body" d="M4 13v-1a8 8 0 0 1 16 0v1"/>
13
13
  <path class="bp-i-body" d="M20 14.5v2a3.5 3.5 0 0 1-3.5 3.5H13"/>
14
14
  <rect class="bp-i-cup" x="1.6" y="12.6" width="4.4" height="6.4" rx="1.8"/>
15
15
  <rect class="bp-i-cup" x="18" y="12.6" width="4.4" height="6.4" rx="1.8"/>
16
- </svg>`,ye=`<svg viewBox="0 0 24 24" fill="none" ${W} aria-hidden="true">
16
+ </svg>`,ye=`<svg viewBox="0 0 24 24" fill="none" ${C} aria-hidden="true">
17
17
  <path class="bp-i-body" d="M21 11.5a8.4 8.4 0 0 1-9 8.4 9 9 0 0 1-2.9-.5L3 21.5l1.5-4.6A8.4 8.4 0 0 1 12 3.1a8.4 8.4 0 0 1 9 8.4z"/>
18
18
  <path class="bp-i-hand" d="M14.6 14.4a6.5 6.5 0 0 1-3.2-3.2l.7-.7a1 1 0 0 0 .2-1.1 6 6 0 0 1-.3-1.2 1 1 0 0 0-1-.8H9.6a1 1 0 0 0-1 1.1 9.6 9.6 0 0 0 4.8 7.2 1 1 0 0 0 1.4-.9v-1.2a1 1 0 0 0-.8-1z"/>
19
19
  </svg>`,ve=`<svg viewBox="0 0 10 16" width="10" height="16" fill="currentColor" aria-hidden="true">
20
20
  <circle cx="2.6" cy="2.6" r="1.35"/><circle cx="7.4" cy="2.6" r="1.35"/>
21
21
  <circle cx="2.6" cy="8" r="1.35"/><circle cx="7.4" cy="8" r="1.35"/>
22
22
  <circle cx="2.6" cy="13.4" r="1.35"/><circle cx="7.4" cy="13.4" r="1.35"/>
23
- </svg>`,G={"phone-waves":U,waveform:xe,headset:we,"chat-phone":ye},te="phone-waves",ke=`
23
+ </svg>`,G={"phone-waves":N,waveform:xe,headset:we,"chat-phone":ye},te="phone-waves",ke=`
24
24
  :host { all: initial; }
25
25
  * { box-sizing: border-box; }
26
26
 
@@ -354,7 +354,7 @@
354
354
  .bp-launcher-icon { transition: none; }
355
355
  }
356
356
 
357
- `,se="bravophone:widget:geometry",Y=28,J=32;function Me(e){try{const a=localStorage.getItem(se);if(!a)return{...e};const i=JSON.parse(a);return i.dock?{...e,...i,...N(i.dock,i)}:{...e,...i}}catch(a){return{...e}}}function V(e){try{localStorage.setItem(se,JSON.stringify(e))}catch(a){}}function de(e){return{minWidth:e.minWidth,minHeight:e.minHeight,maxWidth:Math.max(e.minWidth,Math.min(e.maxWidth,window.innerWidth)),maxHeight:Math.max(e.minHeight,Math.min(e.maxHeight,window.innerHeight))}}function R(e){const a=Math.max(0,window.innerWidth-e.width),i=Math.max(0,window.innerHeight-40);return{...e,x:Math.min(Math.max(0,e.x),a),y:Math.min(Math.max(0,e.y),i)}}function N(e,a){const i=window.innerWidth,o=window.innerHeight,n=Math.round(i/2),d=Math.round(o/2),u=Math.min(a.width,i);switch(e){case"left":return{x:0,y:0,width:u,height:o};case"right":return{x:i-u,y:0,width:u,height:o};case"left-half":return{x:0,y:0,width:n,height:o};case"right-half":return{x:i-n,y:0,width:n,height:o};case"top":return{x:a.x,y:0,width:u,height:d};case"bottom":return{x:a.x,y:o-d,width:u,height:d};case"top-half":return{x:0,y:0,width:i,height:d};case"bottom-half":return{x:0,y:o-d,width:i,height:d};case"max":return{x:0,y:0,width:i,height:o};default:return{x:a.x,y:a.y,width:a.width,height:a.height}}}function Le(e,a,i){const o=window.innerWidth,n=window.innerHeight,d=e<=Y,u=e>=o-Y,f=a<=Y,t=a>=n-Y;return(f||t)&&d?"left-half":(f||t)&&u?"right-half":f?i||"max":t?"bottom-half":d?"left":u?"right":null}function ze({root:e,handle:a,handles:i,preview:o,geometry:n,limits:d,topDock:u,onChange:f}){let t={...n},g=null,p="",c=null,l=null,w=null,y=null;const z=()=>{e.style.left=`${t.x}px`,e.style.top=`${t.y}px`,e.style.width=`${t.width}px`,e.style.height=`${t.height}px`,e.classList.toggle("bp-docked",!!t.dock),f==null||f(t)},B=r=>{if(o){if(!r){o.hidden=!0;return}o.hidden=!1,o.style.left=`${r.x}px`,o.style.top=`${r.y}px`,o.style.width=`${r.width}px`,o.style.height=`${r.height}px`}},I=(r,b)=>{const h=de(d);let{x:v,y:S,width:E,height:H}=c;p.includes("e")&&(E=c.width+r),p.includes("w")&&(E=c.width-r),p.includes("s")&&(H=c.height+b),p.includes("n")&&(H=c.height-b),E=Math.min(h.maxWidth,Math.max(h.minWidth,E)),H=Math.min(h.maxHeight,Math.max(h.minHeight,H)),p.includes("w")&&(v=c.x+(c.width-E)),p.includes("n")&&(S=c.y+(c.height-H)),p.includes("e")&&Math.abs(v+E-window.innerWidth)<=J&&(E=window.innerWidth-v),p.includes("w")&&Math.abs(v)<=J&&(E+=v,v=0),p.includes("s")&&Math.abs(S+H-window.innerHeight)<=J&&(H=window.innerHeight-S),p.includes("n")&&Math.abs(S)<=J&&(H+=S,S=0),t={...t,x:v,y:S,width:E,height:H,dock:null},z()},_=(r,b,h,v)=>{if(t.dock){const S=y||{width:d.width,height:d.height},E=l.x/Math.max(1,t.width);t={...t,...S,dock:null},l={x:Math.round(S.width*E),y:Math.min(l.y,32)},c={...c,x:h-l.x,y:v-l.y,px:c.px+r,py:c.py+b},r=0,b=0}t=R({...t,x:c.x+r,y:c.y+b}),z(),w=Le(h,v,u),B(w?N(w,t):null)},K=()=>{w&&(y=y||{width:t.width,height:t.height},t={...t,...N(w,t),dock:w},z())},Z=(r,b)=>h=>{h.button===0&&(r==="drag"&&h.target.closest(".bp-btn")||(g=r,p=b||"",c={px:h.clientX,py:h.clientY,...t},l={x:h.clientX-t.x,y:h.clientY-t.y},t.dock||(y={width:t.width,height:t.height}),e.classList.add(r==="drag"?"bp-dragging":"bp-resizing"),h.currentTarget.setPointerCapture(h.pointerId),h.preventDefault()))},j=r=>{if(!g||!c)return;const b=r.clientX-c.px,h=r.clientY-c.py;g==="drag"?_(b,h,r.clientX,r.clientY):I(b,h)},A=r=>{if(g){e.classList.remove("bp-dragging","bp-resizing"),B(null),g==="drag"&&K(),g=null,p="",c=null,w=null;try{r.currentTarget.releasePointerCapture(r.pointerId)}catch(b){}V(t)}};a.addEventListener("pointerdown",Z("drag")),a.addEventListener("pointermove",j),a.addEventListener("pointerup",A),a.addEventListener("pointercancel",A),(i||[]).forEach(({el:r,dir:b})=>{r.addEventListener("pointerdown",Z("resize",b)),r.addEventListener("pointermove",j),r.addEventListener("pointerup",A),r.addEventListener("pointercancel",A)});const q=()=>{t=t.dock?{...t,...N(t.dock,t)}:R(t),z()};window.addEventListener("resize",q);const Q={start(r){var b,h;g="drag",c={px:r.x,py:r.y,...t},l={x:(b=r.cx)!=null?b:t.width/2,y:(h=r.cy)!=null?h:20},t.dock||(y={width:t.width,height:t.height}),e.classList.add("bp-dragging")},move(r){if(g!=="drag"||!c)return;const b=r.x-c.px,h=r.y-c.py;_(b,h,c.x+b+l.x,c.y+h+l.y)},end(){g==="drag"&&(e.classList.remove("bp-dragging"),B(null),K(),g=null,c=null,w=null,V(t))}};return z(),{external:Q,get geometry(){return{...t}},set(r){const b=de(d),h={...t,...r,dock:null};h.width=Math.min(b.maxWidth,Math.max(b.minWidth,h.width)),h.height=Math.min(b.maxHeight,Math.max(b.minHeight,h.height)),t=R(h),z(),V(t)},dock(r){if(!r||r==="float"){const b=y||{width:d.width,height:d.height};t=R({...t,...b,dock:null})}else t.dock||(y={width:t.width,height:t.height}),t={...t,...N(r,t),dock:r};z(),V(t)},destroy(){window.removeEventListener("resize",q)}}}const ce="bravophone/v1";function Se({frame:e,origin:a,onEvent:i}){const o=new Map;let n=0,d=!1;const u=[],f=g=>{var c;if(g.origin!==a||g.source!==e.contentWindow)return;const p=g.data;if(!(!p||p.protocol!==ce)){if(p.type==="ready"){for(d=!0;u.length;)u.shift()();i==null||i("ready",(c=p.payload)!=null?c:{});return}if(p.type==="reply"){const l=o.get(p.id);if(!l)return;o.delete(p.id),clearTimeout(l.timer),p.error?l.reject(new Error(p.error)):l.resolve(p.payload);return}p.type==="event"&&(i==null||i(p.name,p.payload))}};window.addEventListener("message",f);function t(g,p,{timeout:c=15e3}={}){return new Promise((l,w)=>{const y=`${Date.now()}-${++n}`,z=()=>{var I;const B=setTimeout(()=>{o.delete(y),w(new Error(`Bravophone: timeout no comando "${g}"`))},c);o.set(y,{resolve:l,reject:w,timer:B}),(I=e.contentWindow)==null||I.postMessage({protocol:ce,type:"command",id:y,command:g,payload:p},a)};d?z():u.push(z)})}return{call:t,get ready(){return d},destroy(){window.removeEventListener("message",f),o.forEach(({reject:g,timer:p})=>{clearTimeout(p),g(new Error("Bravophone: widget destruído"))}),o.clear()}}}const pe="bravophone:launcher",Ee=4,ae=8;function He(e){try{const a=localStorage.getItem(pe);return a?{...e,...JSON.parse(a)}:{...e}}catch(a){return{...e}}}function ne(e){try{localStorage.setItem(pe,JSON.stringify(e))}catch(a){}}function P(e,a){const i=Math.max(ae,window.innerHeight-a-ae);return Math.min(Math.max(ae,e),i)}function Te({el:e,side:a,y:i,onOpen:o}){let n={side:a,y:P(i,e.offsetHeight||48)},d=null,u=!1;const f=()=>{e.dataset.side=n.side,e.style.top=`${n.y}px`,e.style.right=n.side==="right"?"0px":"auto",e.style.left=n.side==="left"?"0px":"auto"},t=l=>{l.button===0&&(d={py:l.clientY,y:n.y},u=!1,e.setPointerCapture(l.pointerId))},g=l=>{if(!d)return;const w=l.clientY-d.py;!u&&Math.abs(w)<Ee||(u||(u=!0,e.classList.add("bp-launcher-dragging")),n.y=P(d.y+w,e.offsetHeight),f())},p=l=>{if(!d)return;const w=u;d=null,u=!1,e.classList.remove("bp-launcher-dragging");try{e.releasePointerCapture(l.pointerId)}catch(y){}w?ne(n):o==null||o()};e.addEventListener("pointerdown",t),e.addEventListener("pointermove",g),e.addEventListener("pointerup",p),e.addEventListener("pointercancel",p),e.addEventListener("keydown",l=>{(l.key==="Enter"||l.key===" ")&&(l.preventDefault(),o==null||o())});const c=()=>{n.y=P(n.y,e.offsetHeight),f()};return window.addEventListener("resize",c),f(),{get state(){return{...n}},setSide(l){n.side=l,f(),ne(n)},moveTo(l){n.y=P(l,e.offsetHeight),f(),ne(n)},destroy(){window.removeEventListener("resize",c)}}}const Ie="https://cdn.jsdelivr.net/npm";function $e(e,a="@bravophone/webphone"){return`${Ie}/${a}@${e}/host/`}function Oe({version:e,parentOrigin:a,token:i,base:o}){const n=o||$e(e),d=JSON.stringify({parentOrigin:a,token:i||null}).replace(/</g,"\\u003c");return`<!doctype html>
357
+ `,se="bravophone:widget:geometry",Y=28,V=32;function Me(e){try{const t=localStorage.getItem(se);if(!t)return{...e};const n=JSON.parse(t);return n.dock?{...e,...n,...P(n.dock,n)}:{...e,...n}}catch(t){return{...e}}}function J(e){try{localStorage.setItem(se,JSON.stringify(e))}catch(t){}}function de(e){return{minWidth:e.minWidth,minHeight:e.minHeight,maxWidth:Math.max(e.minWidth,Math.min(e.maxWidth,window.innerWidth)),maxHeight:Math.max(e.minHeight,Math.min(e.maxHeight,window.innerHeight))}}function U(e){const t=Math.max(0,window.innerWidth-e.width),n=Math.max(0,window.innerHeight-40);return{...e,x:Math.min(Math.max(0,e.x),t),y:Math.min(Math.max(0,e.y),n)}}function P(e,t){const n=window.innerWidth,i=window.innerHeight,r=Math.round(n/2),d=Math.round(i/2),u=Math.min(t.width,n);switch(e){case"left":return{x:0,y:0,width:u,height:i};case"right":return{x:n-u,y:0,width:u,height:i};case"left-half":return{x:0,y:0,width:r,height:i};case"right-half":return{x:n-r,y:0,width:r,height:i};case"top":return{x:t.x,y:0,width:u,height:d};case"bottom":return{x:t.x,y:i-d,width:u,height:d};case"top-half":return{x:0,y:0,width:n,height:d};case"bottom-half":return{x:0,y:i-d,width:n,height:d};case"max":return{x:0,y:0,width:n,height:i};default:return{x:t.x,y:t.y,width:t.width,height:t.height}}}function Le(e,t,n){const i=window.innerWidth,r=window.innerHeight,d=e<=Y,u=e>=i-Y,x=t<=Y,a=t>=r-Y;return(x||a)&&d?"left-half":(x||a)&&u?"right-half":x?n||"max":a?"bottom-half":d?"left":u?"right":null}function Se({root:e,handle:t,handles:n,preview:i,geometry:r,limits:d,topDock:u,onChange:x}){let a={...r},g=null,p="",c=null,l=null,w=null,M=null;const y=()=>{e.style.left=`${a.x}px`,e.style.top=`${a.y}px`,e.style.width=`${a.width}px`,e.style.height=`${a.height}px`,e.classList.toggle("bp-docked",!!a.dock),x==null||x(a)},A=o=>{if(i){if(!o){i.hidden=!0;return}i.hidden=!1,i.style.left=`${o.x}px`,i.style.top=`${o.y}px`,i.style.width=`${o.width}px`,i.style.height=`${o.height}px`}},R=(o,b)=>{const h=de(d);let{x:E,y:v,width:L,height:T}=c;p.includes("e")&&(L=c.width+o),p.includes("w")&&(L=c.width-o),p.includes("s")&&(T=c.height+b),p.includes("n")&&(T=c.height-b),L=Math.min(h.maxWidth,Math.max(h.minWidth,L)),T=Math.min(h.maxHeight,Math.max(h.minHeight,T)),p.includes("w")&&(E=c.x+(c.width-L)),p.includes("n")&&(v=c.y+(c.height-T)),p.includes("e")&&Math.abs(E+L-window.innerWidth)<=V&&(L=window.innerWidth-E),p.includes("w")&&Math.abs(E)<=V&&(L+=E,E=0),p.includes("s")&&Math.abs(v+T-window.innerHeight)<=V&&(T=window.innerHeight-v),p.includes("n")&&Math.abs(v)<=V&&(T+=v,v=0),a={...a,x:E,y:v,width:L,height:T,dock:null},y()},W=(o,b,h,E)=>{if(a.dock){const v=M||{width:d.width,height:d.height},L=l.x/Math.max(1,a.width);a={...a,...v,dock:null},l={x:Math.round(v.width*L),y:Math.min(l.y,32)},c={...c,x:h-l.x,y:E-l.y,px:c.px+o,py:c.py+b},o=0,b=0}a=U({...a,x:c.x+o,y:c.y+b}),y(),w=Le(h,E,u),A(w?P(w,a):null)},q=()=>{w&&(M=M||{width:a.width,height:a.height},a={...a,...P(w,a),dock:w},y())},K=(o,b)=>h=>{h.button===0&&(o==="drag"&&h.target.closest(".bp-btn")||(g=o,p=b||"",c={px:h.clientX,py:h.clientY,...a},l={x:h.clientX-a.x,y:h.clientY-a.y},a.dock||(M={width:a.width,height:a.height}),e.classList.add(o==="drag"?"bp-dragging":"bp-resizing"),h.currentTarget.setPointerCapture(h.pointerId),h.preventDefault()))},Z=o=>{if(!g||!c)return;const b=o.clientX-c.px,h=o.clientY-c.py;g==="drag"?W(b,h,o.clientX,o.clientY):R(b,h)},B=o=>{if(g){e.classList.remove("bp-dragging","bp-resizing"),A(null),g==="drag"&&q(),g=null,p="",c=null,w=null;try{o.currentTarget.releasePointerCapture(o.pointerId)}catch(b){}J(a)}};t.addEventListener("pointerdown",K("drag")),t.addEventListener("pointermove",Z),t.addEventListener("pointerup",B),t.addEventListener("pointercancel",B),(n||[]).forEach(({el:o,dir:b})=>{o.addEventListener("pointerdown",K("resize",b)),o.addEventListener("pointermove",Z),o.addEventListener("pointerup",B),o.addEventListener("pointercancel",B)});const j=()=>{a=a.dock?{...a,...P(a.dock,a)}:U(a),y()};window.addEventListener("resize",j);const Q={start(o){var b,h;g="drag",c={px:o.x,py:o.y,...a},l={x:(b=o.cx)!=null?b:a.width/2,y:(h=o.cy)!=null?h:20},a.dock||(M={width:a.width,height:a.height}),e.classList.add("bp-dragging")},move(o){if(g!=="drag"||!c)return;const b=o.x-c.px,h=o.y-c.py;W(b,h,c.x+b+l.x,c.y+h+l.y)},end(){g==="drag"&&(e.classList.remove("bp-dragging"),A(null),q(),g=null,c=null,w=null,J(a))}};return y(),{external:Q,get geometry(){return{...a}},set(o){const b=de(d),h={...a,...o,dock:null};h.width=Math.min(b.maxWidth,Math.max(b.minWidth,h.width)),h.height=Math.min(b.maxHeight,Math.max(b.minHeight,h.height)),a=U(h),y(),J(a)},dock(o){if(!o||o==="float"){const b=M||{width:d.width,height:d.height};a=U({...a,...b,dock:null})}else a.dock||(M={width:a.width,height:a.height}),a={...a,...P(o,a),dock:o};y(),J(a)},destroy(){window.removeEventListener("resize",j)}}}const ce="bravophone/v1";function ze({frame:e,origin:t,onEvent:n}){const i=new Map;let r=0,d=!1;const u=[],x=g=>{var c;if(g.origin!==t||g.source!==e.contentWindow)return;const p=g.data;if(!(!p||p.protocol!==ce)){if(p.type==="ready"){for(d=!0;u.length;)u.shift()();n==null||n("ready",(c=p.payload)!=null?c:{});return}if(p.type==="reply"){const l=i.get(p.id);if(!l)return;i.delete(p.id),clearTimeout(l.timer),p.error?l.reject(new Error(p.error)):l.resolve(p.payload);return}p.type==="event"&&(n==null||n(p.name,p.payload))}};window.addEventListener("message",x);function a(g,p,{timeout:c=15e3}={}){return new Promise((l,w)=>{const M=`${Date.now()}-${++r}`,y=()=>{var R;const A=setTimeout(()=>{i.delete(M),w(new Error(`Bravophone: timeout no comando "${g}"`))},c);i.set(M,{resolve:l,reject:w,timer:A}),(R=e.contentWindow)==null||R.postMessage({protocol:ce,type:"command",id:M,command:g,payload:p},t)};d?y():u.push(y)})}return{call:a,get ready(){return d},destroy(){window.removeEventListener("message",x),i.forEach(({reject:g,timer:p})=>{clearTimeout(p),g(new Error("Bravophone: widget destruído"))}),i.clear()}}}const pe="bravophone:launcher",Ee=4,ae=8;function Te(e){try{const t=localStorage.getItem(pe);return t?{...e,...JSON.parse(t)}:{...e}}catch(t){return{...e}}}function ne(e){try{localStorage.setItem(pe,JSON.stringify(e))}catch(t){}}function _(e,t){const n=Math.max(ae,window.innerHeight-t-ae);return Math.min(Math.max(ae,e),n)}function He({el:e,side:t,y:n,onOpen:i}){let r={side:t,y:_(n,e.offsetHeight||48)},d=null,u=!1;const x=()=>{e.dataset.side=r.side,e.style.top=`${r.y}px`,e.style.right=r.side==="right"?"0px":"auto",e.style.left=r.side==="left"?"0px":"auto"},a=l=>{l.button===0&&(d={py:l.clientY,y:r.y},u=!1,e.setPointerCapture(l.pointerId))},g=l=>{if(!d)return;const w=l.clientY-d.py;!u&&Math.abs(w)<Ee||(u||(u=!0,e.classList.add("bp-launcher-dragging")),r.y=_(d.y+w,e.offsetHeight),x())},p=l=>{if(!d)return;const w=u;d=null,u=!1,e.classList.remove("bp-launcher-dragging");try{e.releasePointerCapture(l.pointerId)}catch(M){}w?ne(r):i==null||i()};e.addEventListener("pointerdown",a),e.addEventListener("pointermove",g),e.addEventListener("pointerup",p),e.addEventListener("pointercancel",p),e.addEventListener("keydown",l=>{(l.key==="Enter"||l.key===" ")&&(l.preventDefault(),i==null||i())});const c=()=>{r.y=_(r.y,e.offsetHeight),x()};return window.addEventListener("resize",c),x(),{get state(){return{...r}},setSide(l){r.side=l,x(),ne(r)},moveTo(l){r.y=_(l,e.offsetHeight),x(),ne(r)},destroy(){window.removeEventListener("resize",c)}}}const Ie="https://cdn.jsdelivr.net/npm";function Oe(e,t="@bravophone/webphone"){return`${Ie}/${t}@${e}/host/`}function $e({version:e,parentOrigin:t,session:n,base:i}){const r=i||Oe(e),d=JSON.stringify({parentOrigin:t,session:n||null}).replace(/</g,"\\u003c");return`<!doctype html>
358
358
  <html lang="pt-BR">
359
359
  <head>
360
360
  <meta charset="UTF-8">
@@ -365,9 +365,9 @@
365
365
  elas resolvem contra a página do integrador — o documento herda o
366
366
  baseURI do pai — e somem todas: logo, atender, desligar, mudo, hold,
367
367
  transferir. Com <base>, resolvem contra o CDN. -->
368
- <base href="${n}">
369
- <link rel="stylesheet" href="${n}css/dark-theme.css">
370
- <link rel="stylesheet" href="${n}styles/theme-fixes.css">
368
+ <base href="${r}">
369
+ <link rel="stylesheet" href="${r}css/dark-theme.css">
370
+ <link rel="stylesheet" href="${r}styles/theme-fixes.css">
371
371
  <style>
372
372
  html, body { margin: 0; height: 100%; background: #10131c; overflow: hidden; }
373
373
  #app { height: 100%; }
@@ -378,22 +378,41 @@
378
378
  // O guest-bridge lê daqui: em srcdoc não há query string para carregar a
379
379
  // origem do pai.
380
380
  window.__bpParentOrigin = cfg.parentOrigin;
381
- if (cfg.token) {
382
- // Grava onde o bundle procura, antes dele avaliar, para a sessão subir
383
- // autenticada em vez de piscar a tela de login.
384
- try { localStorage.setItem('bp.local.vxToken', JSON.stringify(cfg.token)); } catch (e) {}
381
+ // Grava a sessão onde o bundle procura, ANTES dele avaliar, para já subir
382
+ // autenticado em vez de piscar a tela de login.
383
+ //
384
+ // As chaves e o prefixo não são escolha nossa: 'bp.local.' é como o
385
+ // chrome-shim mapeia chrome.storage.local, e os nomes vêm do bpSaveSession
386
+ // do bundle. Um token sozinho NÃO basta — sem sip e ramal o webphone não
387
+ // tem o que registrar, e o RouteSelector avisa "faça login pelo webphone".
388
+ if (cfg.session) {
389
+ var s = cfg.session;
390
+ var mapa = {
391
+ bravophoneVxToken: s.vxToken || null,
392
+ bravophoneVxTokenExpiresAt: s.expiresIn ? Date.now() + 1000 * Number(s.expiresIn) : null,
393
+ bravophoneSip: s.sip || null,
394
+ bravophoneTenant: s.tenant || null,
395
+ bravophoneRamal: s.ramal || null,
396
+ bravophoneClienteId: s.clienteId || null,
397
+ bravophoneRamaisUrl: s.ramaisUrl || null
398
+ };
399
+ try {
400
+ for (var k in mapa) {
401
+ if (mapa[k] !== null) localStorage.setItem('bp.local.' + k, JSON.stringify(mapa[k]));
402
+ }
403
+ } catch (e) {}
385
404
  }
386
405
  })();
387
406
  <\/script>
388
- <script src="${n}shim/messages.js"><\/script>
389
- <script src="${n}shim/chrome-shim.js"><\/script>
390
- <script src="${n}js/libwebphone.js"><\/script>
391
- <script src="${n}js/bravophone-route-selector.js"><\/script>
392
- <script defer src="${n}popup.js"><\/script>
393
- <script defer src="${n}shim/guest-bridge.js"><\/script>
407
+ <script src="${r}shim/messages.js"><\/script>
408
+ <script src="${r}shim/chrome-shim.js"><\/script>
409
+ <script src="${r}js/libwebphone.js"><\/script>
410
+ <script src="${r}js/bravophone-route-selector.js"><\/script>
411
+ <script defer src="${r}popup.js"><\/script>
412
+ <script defer src="${r}shim/guest-bridge.js"><\/script>
394
413
  </head>
395
414
  <body>
396
415
  <noscript><strong>O webphone precisa de JavaScript habilitado.</strong></noscript>
397
416
  <div id="app"></div>
398
417
  </body>
399
- </html>`}const he={width:380,height:640,minWidth:320,minHeight:420,maxWidth:1600,maxHeight:1400,margin:24};function x(e,a={},i=[]){const o=document.createElement(e);for(const[n,d]of Object.entries(a))n==="class"?o.className=d:n==="text"?o.textContent=d:d!=null&&o.setAttribute(n,d);return i.forEach(n=>o.appendChild(n)),o}function Ce(e){const{hostUrl:a,token:i,position:o="bottom-right",open:n=!1,launcher:d=!0,title:u="BRAVOPHONE",frame:f="bar",dockTop:t="max",launcherSide:g="right",launcherIcon:p=te,mode:c="srcdoc",hostBase:l,version:w,emit:y}=e,z=c==="srcdoc",B=z?window.location.origin:new URL(a).origin,I=x("div",{"data-bravophone":"root"});I.style.cssText="all:initial;position:static";const _=I.attachShadow({mode:"open"});_.appendChild(x("style",{text:ke}));const K=(()=>{var fe;const{width:s,height:L,margin:C}=he,F=window.innerWidth-s-C,ge=window.innerHeight-L-C,me={"bottom-right":{x:F,y:ge},"bottom-left":{x:C,y:ge},"top-right":{x:F,y:C},"top-left":{x:C,y:C}};return R({...(fe=me[o])!=null?fe:me["bottom-right"],width:s,height:L})})(),Z=R(Me(K)),j=x("span",{class:"bp-status","data-state":"connecting"}),A=x("button",{class:"bp-btn bp-btn-min",title:"Minimizar",text:"—"}),q=x("button",{class:"bp-btn bp-btn-close",title:"Fechar",text:"×"}),Q=x("div",{class:"bp-header"},[j,x("span",{class:"bp-title",text:u}),A,q]),r=x("iframe",{class:"bp-frame",allow:"microphone; autoplay; clipboard-write; speaker-selection",title:"Webphone BRAVOPHONE"});z?r.setAttribute("srcdoc",Oe({version:w,parentOrigin:B,token:i,base:l})):r.setAttribute("src",We(new URL(a),{token:i,embed:"1",parent:location.origin}));const h=["n","s","w","e","nw","ne","sw","se"].map(s=>({el:x("div",{class:`bp-h bp-h-${s}`}),dir:s})),v=x("div",{class:"bp-preview"});v.hidden=!0;const S=x("button",{class:"bp-btn bp-btn-close",title:"Fechar",text:"×"}),E=x("div",{class:"bp-overlay"},[S]),H=x("div",{class:"bp-body"},[r,E]),M=x("div",{class:"bp-root"},[Q,H,...h.map(s=>s.el)]);f!=="bar"&&M.classList.add("bp-chromeless"),M.hidden=!n;const ie=x("span",{class:"bp-launcher-icon"});ie.innerHTML=G[p]||G[te];const le=x("span",{class:"bp-launcher-grip","aria-hidden":"true"});le.innerHTML=ve;const T=x("div",{class:"bp-launcher",role:"button",tabindex:"0",title:"Abrir webphone","aria-label":"Abrir webphone"},[le,ie,x("span",{class:"bp-badge"})]);T.dataset.state="connecting",T.hidden=!d,_.append(v,M,T),document.body.appendChild(I);const be=He({side:g,y:Math.round(window.innerHeight/2-24)}),ue=Te({el:T,side:be.side,y:P(be.y,48),onOpen:()=>O.reveal()}),$=ze({root:M,handle:Q,handles:h,preview:v,geometry:Z,limits:he,topDock:t,onChange:s=>y("resize",{width:s.width,height:s.height,dock:s.dock||null})}),re=Se({frame:r,origin:B,onEvent:(s,L)=>{var C;if(s==="ready"&&(j.dataset.state="ready",T.dataset.state="ready",i&&re.call("auth",{token:i}).catch(()=>{})),s==="state"){const F=(C=L==null?void 0:L.state)!=null?C:"ready";j.dataset.state=F,T.dataset.state=F}if(s==="call:incoming"&&(O.show(),T.dataset.badge="1",T.dataset.state="ringing"),s==="call:answered"&&(T.dataset.state="incall"),s==="call:ended"&&(delete T.dataset.badge,T.dataset.state="ready"),s==="drag:start"){$.external.start(L);return}if(s==="drag:move"){$.external.move(L);return}if(s==="drag:end"){$.external.end();return}y(s,L)}});let ee=!1,oe=null;const O={el:I,bridge:re,show(){M.hidden=!1,y("open")},hide(){M.hidden=!0,y("close")},toggle(){M.hidden?O.show():O.hide()},reveal(){if(M.hidden){O.show();return}const s=$.geometry;(s.x+s.width<40||s.x>window.innerWidth-40||s.y>window.innerHeight-40)&&$.set({x:Math.round((window.innerWidth-s.width)/2),y:Math.round((window.innerHeight-s.height)/2)}),M.classList.remove("bp-attention"),M.offsetWidth,M.classList.add("bp-attention"),clearTimeout(oe),oe=setTimeout(()=>M.classList.remove("bp-attention"),1800),y("reveal")},get isOpen(){return!M.hidden},minimize(s){if(f!=="bar"){O.hide();return}ee=s!=null?s:!ee,M.classList.toggle("bp-minimized",ee),A.textContent=ee?"▢":"—"},move(s,L){$.set({x:s,y:L})},resize(s,L){$.set({width:s,height:L})},dock(s){$.dock(s)},setLauncherSide(s){ue.setSide(s)},setLauncherIcon(s){ie.innerHTML=G[s]||G[te]},get geometry(){return $.geometry},destroy(){clearTimeout(oe),re.destroy(),$.destroy(),ue.destroy(),v.remove(),I.remove()}};return q.addEventListener("click",()=>O.hide()),A.addEventListener("click",()=>O.minimize()),S.addEventListener("click",()=>O.hide()),O}function We(e,a){const i=new URL(e.href);for(const[o,n]of Object.entries(a))n!=null&&n!==""&&i.searchParams.set(o,n);return a.token&&(i.searchParams.delete("token"),i.hash=`token=${encodeURIComponent(a.token)}`),i.href}const Be="";let k=null;const D=new Map;function Ae(e,a){var i,o;(i=D.get(e))==null||i.forEach(n=>{try{n(a)}catch(d){console.error("[Bravophone] listener falhou:",d)}}),(o=D.get("*"))==null||o.forEach(n=>{try{n({event:e,payload:a})}catch(d){console.error("[Bravophone] listener falhou:",d)}})}function m(){if(!k)throw new Error("Bravophone: chame Bravophone.init() antes.");return k}const X={init(e={}){if(k)return k;if(typeof window=="undefined"||!document.body)throw new Error("Bravophone: init() precisa rodar no browser, após o <body> existir.");if(location.protocol!=="https:"&&location.hostname!=="localhost"&&console.warn("[Bravophone] Contexto inseguro: o microfone exige HTTPS ou localhost."),e.mode==="hosted"&&!e.hostUrl)throw new Error("Bravophone: mode 'hosted' exige hostUrl. Use mode 'srcdoc' (padrão) para carregar o webphone do CDN sem depender de um host próprio.");return k=Ce({hostUrl:Be,version:X.version,...e,emit:Ae}),k},show(){m().show()},hide(){m().hide()},toggle(){m().toggle()},reveal(){m().reveal()},minimize(e){m().minimize(e)},move(e,a){m().move(e,a)},resize(e,a){m().resize(e,a)},dock(e){m().dock(e)},setLauncherSide(e){m().setLauncherSide(e)},setLauncherIcon(e){m().setLauncherIcon(e)},get isOpen(){return k?k.isOpen:!1},get geometry(){return k?k.geometry:null},call(e,a){return m().bridge.call("call",{number:e,meta:a})},hangup(){return m().bridge.call("hangup")},answer(){return m().bridge.call("answer")},mute(){return m().bridge.call("mute")},hold(){return m().bridge.call("hold")},sendDTMF(e){return m().bridge.call("dtmf",{tone:e})},transfer(e){return m().bridge.call("transfer",{to:e})},getStatus(){return m().bridge.call("status")},setAuth(e){return m().bridge.call("auth",{token:e})},logout(){return m().bridge.call("logout")},on(e,a){return D.has(e)||D.set(e,new Set),D.get(e).add(a),()=>X.off(e,a)},off(e,a){var i;(i=D.get(e))==null||i.delete(a)},destroy(){k==null||k.destroy(),k=null,D.clear()},version:"0.3.0"};return typeof window!="undefined"&&(window.Bravophone=X),X});
418
+ </html>`}const le={width:380,height:640,minWidth:320,minHeight:420,maxWidth:1600,maxHeight:1400,margin:24};function f(e,t={},n=[]){const i=document.createElement(e);for(const[r,d]of Object.entries(t))r==="class"?i.className=d:r==="text"?i.textContent=d:d!=null&&i.setAttribute(r,d);return n.forEach(r=>i.appendChild(r)),i}function Ce(e){const{hostUrl:t,token:n,session:i,position:r="bottom-right",open:d=!1,launcher:u=!0,title:x="BRAVOPHONE",frame:a="bar",dockTop:g="max",launcherSide:p="right",launcherIcon:c=te,mode:l="srcdoc",hostBase:w,version:M,emit:y}=e,A=l==="srcdoc",R=A?window.location.origin:new URL(t).origin,W=f("div",{"data-bravophone":"root"});W.style.cssText="all:initial;position:static";const q=W.attachShadow({mode:"open"});q.appendChild(f("style",{text:ke}));const K=(()=>{var fe;const{width:s,height:z,margin:$}=le,F=window.innerWidth-s-$,ge=window.innerHeight-z-$,me={"bottom-right":{x:F,y:ge},"bottom-left":{x:$,y:ge},"top-right":{x:F,y:$},"top-left":{x:$,y:$}};return U({...(fe=me[r])!=null?fe:me["bottom-right"],width:s,height:z})})(),Z=U(Me(K)),B=f("span",{class:"bp-status","data-state":"connecting"}),j=f("button",{class:"bp-btn bp-btn-min",title:"Minimizar",text:"—"}),Q=f("button",{class:"bp-btn bp-btn-close",title:"Fechar",text:"×"}),o=f("div",{class:"bp-header"},[B,f("span",{class:"bp-title",text:x}),j,Q]),b=f("iframe",{class:"bp-frame",allow:"microphone; autoplay; clipboard-write; speaker-selection",title:"Webphone BRAVOPHONE"});A?b.setAttribute("srcdoc",$e({version:M,parentOrigin:R,base:w,session:i||(n?{vxToken:n}:null)})):b.setAttribute("src",Ae(new URL(t),{token:n,embed:"1",parent:location.origin}));const E=["n","s","w","e","nw","ne","sw","se"].map(s=>({el:f("div",{class:`bp-h bp-h-${s}`}),dir:s})),v=f("div",{class:"bp-preview"});v.hidden=!0;const L=f("button",{class:"bp-btn bp-btn-close",title:"Fechar",text:"×"}),T=f("div",{class:"bp-overlay"},[L]),De=f("div",{class:"bp-body"},[b,T]),S=f("div",{class:"bp-root"},[o,De,...E.map(s=>s.el)]);a!=="bar"&&S.classList.add("bp-chromeless"),S.hidden=!d;const re=f("span",{class:"bp-launcher-icon"});re.innerHTML=G[c]||G[te];const he=f("span",{class:"bp-launcher-grip","aria-hidden":"true"});he.innerHTML=ve;const H=f("div",{class:"bp-launcher",role:"button",tabindex:"0",title:"Abrir webphone","aria-label":"Abrir webphone"},[he,re,f("span",{class:"bp-badge"})]);H.dataset.state="connecting",H.hidden=!u,q.append(v,S,H),document.body.appendChild(W);const be=Te({side:p,y:Math.round(window.innerHeight/2-24)}),ue=He({el:H,side:be.side,y:_(be.y,48),onOpen:()=>O.reveal()}),I=Se({root:S,handle:o,handles:E,preview:v,geometry:Z,limits:le,topDock:g,onChange:s=>y("resize",{width:s.width,height:s.height,dock:s.dock||null})}),ie=ze({frame:b,origin:R,onEvent:(s,z)=>{var $;if(s==="ready"&&(B.dataset.state="ready",H.dataset.state="ready",(i||n)&&ie.call("auth",{session:i||{vxToken:n}}).catch(()=>{})),s==="state"){const F=($=z==null?void 0:z.state)!=null?$:"ready";B.dataset.state=F,H.dataset.state=F}if(s==="call:incoming"&&(O.show(),H.dataset.badge="1",H.dataset.state="ringing"),s==="call:answered"&&(H.dataset.state="incall"),s==="call:ended"&&(delete H.dataset.badge,H.dataset.state="ready"),s==="drag:start"){I.external.start(z);return}if(s==="drag:move"){I.external.move(z);return}if(s==="drag:end"){I.external.end();return}y(s,z)}});let ee=!1,oe=null;const O={el:W,bridge:ie,show(){S.hidden=!1,y("open")},hide(){S.hidden=!0,y("close")},toggle(){S.hidden?O.show():O.hide()},reveal(){if(S.hidden){O.show();return}const s=I.geometry;(s.x+s.width<40||s.x>window.innerWidth-40||s.y>window.innerHeight-40)&&I.set({x:Math.round((window.innerWidth-s.width)/2),y:Math.round((window.innerHeight-s.height)/2)}),S.classList.remove("bp-attention"),S.offsetWidth,S.classList.add("bp-attention"),clearTimeout(oe),oe=setTimeout(()=>S.classList.remove("bp-attention"),1800),y("reveal")},get isOpen(){return!S.hidden},minimize(s){if(a!=="bar"){O.hide();return}ee=s!=null?s:!ee,S.classList.toggle("bp-minimized",ee),j.textContent=ee?"▢":"—"},move(s,z){I.set({x:s,y:z})},resize(s,z){I.set({width:s,height:z})},dock(s){I.dock(s)},setLauncherSide(s){ue.setSide(s)},setLauncherIcon(s){re.innerHTML=G[s]||G[te]},get geometry(){return I.geometry},destroy(){clearTimeout(oe),ie.destroy(),I.destroy(),ue.destroy(),v.remove(),W.remove()}};return Q.addEventListener("click",()=>O.hide()),j.addEventListener("click",()=>O.minimize()),L.addEventListener("click",()=>O.hide()),O}function Ae(e,t){const n=new URL(e.href);for(const[i,r]of Object.entries(t))r!=null&&r!==""&&n.searchParams.set(i,r);return t.token&&(n.searchParams.delete("token"),n.hash=`token=${encodeURIComponent(t.token)}`),n.href}const We="";let k=null;const D=new Map;function Be(e,t){var n,i;(n=D.get(e))==null||n.forEach(r=>{try{r(t)}catch(d){console.error("[Bravophone] listener falhou:",d)}}),(i=D.get("*"))==null||i.forEach(r=>{try{r({event:e,payload:t})}catch(d){console.error("[Bravophone] listener falhou:",d)}})}function m(){if(!k)throw new Error("Bravophone: chame Bravophone.init() antes.");return k}const X={init(e={}){if(k)return k;if(typeof window=="undefined"||!document.body)throw new Error("Bravophone: init() precisa rodar no browser, após o <body> existir.");if(location.protocol!=="https:"&&location.hostname!=="localhost"&&console.warn("[Bravophone] Contexto inseguro: o microfone exige HTTPS ou localhost."),e.mode==="hosted"&&!e.hostUrl)throw new Error("Bravophone: mode 'hosted' exige hostUrl. Use mode 'srcdoc' (padrão) para carregar o webphone do CDN sem depender de um host próprio.");return k=Ce({hostUrl:We,version:X.version,...e,emit:Be}),k},show(){m().show()},hide(){m().hide()},toggle(){m().toggle()},reveal(){m().reveal()},minimize(e){m().minimize(e)},move(e,t){m().move(e,t)},resize(e,t){m().resize(e,t)},dock(e){m().dock(e)},setLauncherSide(e){m().setLauncherSide(e)},setLauncherIcon(e){m().setLauncherIcon(e)},get isOpen(){return k?k.isOpen:!1},get geometry(){return k?k.geometry:null},call(e,t){return m().bridge.call("call",{number:e,meta:t})},hangup(){return m().bridge.call("hangup")},answer(){return m().bridge.call("answer")},mute(){return m().bridge.call("mute")},hold(){return m().bridge.call("hold")},sendDTMF(e){return m().bridge.call("dtmf",{tone:e})},transfer(e){return m().bridge.call("transfer",{to:e})},getStatus(){return m().bridge.call("status")},setAuth(e){const t=typeof e=="string"?{vxToken:e}:e;return m().bridge.call("auth",{session:t})},logout(){return m().bridge.call("logout")},on(e,t){return D.has(e)||D.set(e,new Set),D.get(e).add(t),()=>X.off(e,t)},off(e,t){var n;(n=D.get(e))==null||n.delete(t)},destroy(){k==null||k.destroy(),k=null,D.clear()},version:"0.4.0"};return typeof window!="undefined"&&(window.Bravophone=X),X});
@@ -29,7 +29,7 @@
29
29
 
30
30
  /* AMBIENTE: HOMOLOGACAO. Mesma constante usada pelo popup.js (BP_API_BASE);
31
31
  para virar producao troque aqui, no popup.js e no host_permissions. */
32
- var API_BASE = "https://reports-hmg.teambravotech.com";
32
+ var API_BASE = "https://pabx.teambravotech.com";
33
33
  var TOKEN_STORAGE_KEY = "bravophoneVxToken";
34
34
 
35
35
  /**