@lemonsliceai/lemon-slice-widget 1.0.29 → 1.0.30
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.js +1 -1
- package/package.json +1 -1
package/dist/index.js
CHANGED
|
@@ -65,4 +65,4 @@ In order to be iterable, non-array objects must have a [Symbol.iterator]() metho
|
|
|
65
65
|
bg-[var(--color-primary-action)] backdrop-blur-xl
|
|
66
66
|
rounded-full transition-opacity hover:bg-[var(--color-primary-action-hover)] shadow-inset-white-20`,children:[A(Um,{className:"size-5 text-white"}),A("p",{className:"text-sm text-white whitespace-nowrap font-medium",children:f||"Video chat"})]})}),A("div",{className:"flex sm:hidden absolute inset-2 items-end justify-center",children:A("div",{className:`flex items-center gap-2 px-3 h-11
|
|
67
67
|
bg-[var(--color-primary-action)] backdrop-blur-xl
|
|
68
|
-
rounded-full transition-opacity hover:bg-[var(--color-primary-action-hover)] shadow-inset-white-20`,children:[A(Um,{className:"size-5 text-white"}),A("p",{className:"text-base text-white whitespace-nowrap font-medium",children:f||"Join"})]})})]}),Dt&&A(ax,{onClose:F,onSetMessageRef:Te=>{u.current=Te},onFocusRef:Te=>{p.current=Te},showKeyboardOnMobile:t}),A("div",{className:e?"hidden":"pointer-events-none absolute inset-0 rounded-3xl shadow-inset-white-20"})]})}function ux(){const{setWidgetState:e,widgetState:t}=At();return A("button",{onClick:()=>{e(Qe)},className:`fixed right-0 bottom-25 z-50 bg-black/40 rounded-l-3xl w-[36px] h-[64px] flex items-center justify-center hover:bg-black/30 transition-all duration-300 cursor-pointer backdrop-blur-xl shadow-inset-white-20 ${t===Qe?"opacity-0 pointer-events-none":"opacity-100"}`,"aria-label":"Open widget",children:A(X1,{size:24,color:"white"})})}const dx="https://toinfinityai--s2v-pipecat-server-create-room.modal.run",fx="https://lemonslice.com/api";class qm extends Error{constructor(){super("Pipecat rate limited"),this.name="PipecatRateLimitedError"}}async function hx(e){const t=await fetch(`${dx}`,{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({agent_id:e,ack_bot_ready:!0})});if(!t.ok)throw t.status===429?new qm:new Error(`Failed to create agent room: ${t.statusText}`);const n=await t.json();return"session_id"in n&&n.session_id!=null&&console.info("session_info",{session_id:n.session_id}),n}async function px(e){const t=await fetch(`${fx}/agents/${e}`,{method:"GET",headers:{"Content-Type":"application/json"}});if(!t.ok)throw new Error(`Failed to get agent: ${t.statusText}`);return await t.json()}function mx(){return 0}function gx({agentId:e,isInline:t,hidePoweredBy:n,hideUI:r=!1,showKeyboardOnMobile:i=!1}){const{agentData:o,setAgentData:a}=Qt(),{widgetState:s,setWidgetState:c,roomUrl:l,setRoomUrl:d,isTransitioning:f,isAboutToTransition:m,hasJoinedRoom:g,setHasJoinedRoom:y,resetDailyState:v,setIsAgentVideoReady:b,setIsImageChanging:_,setIsImageChangeRequested:S,setAudioPermissionBlocked:T,retryDailyAudioRef:M}=At(),{startMaxVideoTimer:x,errorMsg:C,setErrorMsg:E,setNonFatalErrorMsg:O}=io(),{resetInitMsg:V}=Rc(),{isAudioMuted:B,isMicMuted:N}=Nr(),{hasUserInteracted:z}=er(),R=kt(),ee=Rr(),X=Xt({filter:"remote"}),Z=ae(!1),W=ae(!1),K=ae(null),$=ae(null),[U,ie]=te(!1),[le,u]=te(!1);J(()=>{e&&px(e).then(h=>{if(!h.sufficient_balance)throw new Error("Insufficient balance");a(h)}).catch(h=>{console.error("Error fetching agent data:",h)})},[e,a]),J(()=>{s===ke&&z&&!Z.current&&!l&&e&&!C&&(Z.current=!0,hx(e).then(h=>{h.room_url?d(h.room_url):E("An error occurred. Please try again.")}).catch(h=>{console.error("Error creating agent room:",h),h instanceof qm?E("This agent is currently busy. Please try again in a few minutes."):E("An error occurred. Please try again.")}).finally(()=>{Z.current=!1}))},[s,z,e,l,C]),J(()=>{if(s!==ke||!R||!l||g||W.current)return;W.current=!0;const h=mx(),w=()=>{R.join({url:l,audioSource:!0,videoSource:!1,startAudioOff:N,dailyConfig:{alwaysIncludeMicInPermissionPrompt:!1}}).then(()=>{y(!0),V()}).catch(k=>{console.error("Error joining call:",k),E("An error occurred. Please try again."),y(!1)}).finally(()=>{W.current=!1})};if(h>0){console.log(`[cold start] Delaying join by ${h}ms (from ?coldStartDelay=${h})`);const k=window.setTimeout(w,h);return()=>{window.clearTimeout(k),W.current=!1}}w()},[s,R,l,g,N]),J(()=>{R&&!g&&R.leave()},[g,R]),J(()=>(!g&&$.current&&($.current.getTracks().forEach(h=>{h.stop()}),$.current=null),()=>{$.current&&($.current.getTracks().forEach(h=>{h.stop()}),$.current=null)}),[g]),q("app-message",j(h=>{h?.data?.type==="pipecat_shutdown"&&(E("An error occurred. Please try again."),v()),h?.data?.type==="bot_ready"&&(b(!0),ee({event:"bot_ready_ack"},"*")),h?.data?.type==="gpu_error"&&(E("An error occurred. Please try again."),v()),h?.data?.type==="image_created"&&(_(!0),S(!1)),h?.data?.type==="image_change_complete"&&(_(!1),S(!1)),h?.data?.type==="image_change_error"&&(S(!1),_(!1),O("Unable to imagine"))},[ee])),q("participant-joined",j(()=>{x()},[])),q("error",j(()=>{console.error("Encountered Daily error"),E("An error occurred. Please try again.")},[])),q("participant-left",j(()=>{!C&&g&&(console.error("Agent left the call"),c(Qe),v())},[g])),q("network-connection",j(h=>{if(!h)return;const w=h.type,k=h.event;k==="connected"?w==="peer-to-peer"||w==="sfu"?ie(!1):w==="signaling"&&u(!1):k==="interrupted"&&(w==="peer-to-peer"||w==="sfu"?ie(!0):w==="signaling"&&u(!0))},[])),J(()=>{O(le?"Network issues.":U?"Poor connection.":"")},[U,le]);const p=j(h=>{const w=new Date().toISOString();if(console.error("DailyAudio play failed:",{name:h?.name,message:h?.message,sessionId:h?.sessionId,type:h?.type,timestamp:w,full:h}),h?.name==="NotAllowedError"){T(!0);return}E("An error occurred. Please try again.")},[E,T]);return J(()=>(M.current=()=>{T(!1),R&&navigator.mediaDevices?.getUserMedia({audio:!0})?.then(w=>{const k=w.getAudioTracks()[0];k&&typeof R.updateInputSettings=="function"?($.current&&$.current.getTracks().forEach(P=>{P.stop()}),$.current=w,R.updateInputSettings({audio:{settings:{customTrack:k}}}).catch(P=>console.warn("updateInputSettings(audio) failed:",P))):w.getTracks().forEach(P=>{P.stop()})}).catch(w=>console.warn("getUserMedia(audio) in retry failed:",w));const h=K.current?.getAllAudio?.();if(h?.length){const w=h.filter(k=>k).map(k=>(k.muted=!1,k.play()));Promise.allSettled(w).then(k=>{const P=k.every(D=>D.status==="rejected");T(P)})}},()=>{M.current=null}),[M,T,R]),J(()=>{if(K.current){const h=K.current.getAllAudio();h&&h.length>0&&h.forEach(w=>{w&&(w.muted=B)})}},[B,X.length]),J(()=>{const h=()=>{v()};return window.addEventListener("beforeunload",h),()=>{window.removeEventListener("beforeunload",h),v(),$.current&&($.current.getTracks().forEach(w=>{w.stop()}),$.current=null)}},[]),o?A("div",{className:t?"":"fixed bottom-5 right-5 z-1000 flex flex-col items-end",children:[!r&&(s===Et||f||m)&&A(ux,{}),(s===ke||s===Qe||f||m)&&A(lx,{hideUI:r,showKeyboardOnMobile:i}),A("div",{className:"fixed bottom-[6px] right-5 text-right text-[8px] text-white mix-blend-difference transition-opacity duration-150 shadow-2xs pr-[4px]",style:{visibility:!t&&!n&&!r&&s!==Et?"visible":"hidden"},children:["Powered by"," ",A("a",{href:"https://lemonslice.com",target:"_blank",rel:"noopener noreferrer",className:"underline",children:"Lemon Slice"})]}),A(Ff,{ref:K,onPlayFailed:p})]}):null}const vx=Le(void 0);function yx({children:e,agentId:t,onAPIReady:n}){const r=Rr(),{isAudioMuted:i,setIsAudioMuted:o,isMicMuted:a,setIsMicMuted:s}=Nr(),{widgetState:c,setWidgetState:l,hasJoinedRoom:d,setIsImageChangeRequested:f}=At(),{setHasUserInteracted:m}=er(),{sendMessage:g}=Rc(),{agentData:y}=Qt(),v=Xt({filter:"remote"}),b=j(()=>{m(!0),c!==ke&&l(ke)},[c,m,l]),_=j(async()=>{o(!0)},[o]),S=j(async()=>{o(!1)},[o]),T=j(()=>i,[i]),M=j(()=>!0,[]),x=j(async()=>{b(),s(!1)},[b,s]),C=j(async()=>{s(!0)},[s]),E=j(()=>!a,[a]),O=j(()=>!0,[]),V=j(async z=>{if(!z.trim())throw new Error("Message cannot be empty");const R=z.trim();b(),g(R,r,d,v,{allowImageEdits:y?.allow_image_edits||!1,setIsImageChangeRequested:f})},[b,r,g,d,v,y,f]),B=Ne(()=>({mute:_,unmute:S,isMuted:T,canUnmute:M,micOn:x,micOff:C,isMicOn:E,canTurnOnMic:O,sendMessage:V}),[_,S,T,M,x,C,E,O,V]),N=ae(n);return J(()=>{N.current=n},[n]),J(()=>{N.current&&N.current(B)},[B]),A(vx.Provider,{value:{api:B},children:e})}function ko(e){if(e==null||e==="")return null;if(typeof e=="number")return Number.isFinite(e)?e:null;const t=Number(e);return Number.isFinite(t)?t:null}const Gm="#919191",bx=.3,_x=.1;function wx(e,t){if(e==null||e==="")return t;const n=typeof e=="number"?e:Number(e);return Number.isFinite(n)?Math.min(1,Math.max(0,n)):t}function Km(e){if(typeof e!="string")return null;const n=e.trim().match(/^#?([0-9a-fA-F]{3}|[0-9a-fA-F]{6})$/);if(!n)return null;let r=n[1];r.length===3&&(r=r.split("").map(s=>s+s).join(""));const i=parseInt(r.slice(0,2),16),o=parseInt(r.slice(2,4),16),a=parseInt(r.slice(4,6),16);return[i,o,a].some(s=>Number.isNaN(s))?null:{r:i,g:o,b:a}}function kx(e={}){const t=e["agent-id"]||void 0,[n,r]=te(null),i=e.inline,o=i==="true"||i===""||i===!0,a=e["show-minimize-button"],s=a===void 0||a==="true"||a===""||a===!0,c=e["initial-state"],l=c==="active"||c==="minimized"||c==="hidden"?c:"minimized",d=e["controlled-widget-state"],f=d==="active"||d==="minimized"||d==="hidden"?d:null,m=e["controlled-show-minimize-button"],g=m===void 0?null:m==="true"||m===""||m===!0,y=ko(e["custom-active-width"]),v=ko(e["custom-active-height"]),b=ko(e["custom-minimized-width"]),_=ko(e["custom-minimized-height"]),S=typeof e["video-button-color-hex"]=="string"?e["video-button-color-hex"].trim():"",T=Km(Gm),M=Km(S||Gm)??T,x=wx(e["video-button-color-opacity"],bx),C=Math.max(0,Math.min(1,x-_x)),E=e["hide-powered-by"],O=E==="true"||E===""||E===!0,V=e["hide-ui"],B=V==="true"||V===""||V===!0,N=e["skip-welcome-video"],z=N==="true"||N===""||N===!0,R=e["show-keyboard-on-mobile"],ee=R==="true"||R===""||R===!0,X=typeof e["video-button-text"]=="string"?e["video-button-text"].trim():null,Z=`rgba(${M.r}, ${M.g}, ${M.b}, ${x})`,W=`rgba(${M.r}, ${M.g}, ${M.b}, ${C})`,K={"--color-primary-action":Z,"--color-primary-action-hover":W},$=Ne(()=>Or.createCallObject({videoSource:!1,audioSource:!0}),[]),U=ae(null);return J(()=>{U.current=n},[n]),J(()=>{if(!n)return;const ie=()=>{const u=document.querySelectorAll("lemon-slice-widget");let p=null;for(const h of u){const w=h.getAttribute("agent-id");if((w===t||!w&&!t&&!p)&&(p=h,w===t))break}!p&&u.length>0&&(p=u[0]),p&&(p.mute=()=>U.current?.mute(),p.unmute=()=>U.current?.unmute(),p.isMuted=()=>U.current?.isMuted()??!1,p.canUnmute=()=>U.current?.canUnmute()??!1,p.micOn=()=>U.current?.micOn(),p.micOff=()=>U.current?.micOff(),p.isMicOn=()=>U.current?.isMicOn()??!1,p.canTurnOnMic=()=>U.current?.canTurnOnMic()??!1,p.sendMessage=h=>U.current?.sendMessage(h))};ie();const le=setTimeout(ie,100);return()=>clearTimeout(le)},[!!n,t]),J(()=>()=>{if($){try{const ie=$.meetingState();(ie==="joined-meeting"||ie==="joining-meeting")&&$.leave()}catch{}try{$.destroy()}catch(ie){console.error("Error destroying call object:",ie)}}},[$]),A("div",{translate:!1,style:K,children:A(X0,{children:A(Q0,{children:A(q0,{children:A(F0,{callObject:$,children:A(K0,{showMinimizeButton:s,initialState:l,controlledWidgetState:f,controlledShowMinimizeButton:g,customActiveWidth:y,customActiveHeight:v,customMinimizedWidth:b,customMinimizedHeight:_,videoButtonText:X,skipWelcomeVideo:z,children:A(e_,{children:A(Y0,{children:A(rx,{children:A(yx,{agentId:t,onAPIReady:ie=>{r(ie)},children:[A(J0,{}),A(gx,{agentId:t,isInline:o,hidePoweredBy:O,hideUI:B,showKeyboardOnMobile:ee})]})})})})})})})})})})}const Sx=["agent-id","inline","show-minimize-button","initial-state","controlled-widget-state","controlled-show-minimize-button","custom-active-width","custom-active-height","custom-minimized-width","custom-minimized-height","video-button-color-hex","video-button-color-opacity","video-button-text","hide-powered-by","hide-ui","show-keyboard-on-mobile"];function Ym(e="lemon-slice-widget"){sg(kx,e,Sx,{shadow:!0,mode:"open"})}return Ym(),xo.registerWidget=Ym,Object.defineProperty(xo,Symbol.toStringTag,{value:"Module"}),xo})({});
|
|
68
|
+
rounded-full transition-opacity hover:bg-[var(--color-primary-action-hover)] shadow-inset-white-20`,children:[A(Um,{className:"size-5 text-white"}),A("p",{className:"text-base text-white whitespace-nowrap font-medium",children:f||"Join"})]})})]}),Dt&&A(ax,{onClose:F,onSetMessageRef:Te=>{u.current=Te},onFocusRef:Te=>{p.current=Te},showKeyboardOnMobile:t}),A("div",{className:e?"hidden":"pointer-events-none absolute inset-0 rounded-3xl shadow-inset-white-20"})]})}function ux(){const{setWidgetState:e,widgetState:t}=At();return A("button",{onClick:()=>{e(Qe)},className:`fixed right-0 bottom-25 z-50 bg-black/40 rounded-l-3xl w-[36px] h-[64px] flex items-center justify-center hover:bg-black/30 transition-all duration-300 cursor-pointer backdrop-blur-xl shadow-inset-white-20 ${t===Qe?"opacity-0 pointer-events-none":"opacity-100"}`,"aria-label":"Open widget",children:A(X1,{size:24,color:"white"})})}const dx="https://toinfinityai--s2v-pipecat-server-create-room.modal.run",fx="https://lemonslice.com/api";class qm extends Error{constructor(){super("Pipecat rate limited"),this.name="PipecatRateLimitedError"}}async function hx(e){const t=Date.now(),n=await fetch(`${dx}`,{method:"POST",headers:{"Content-Type":"application/json","X-Post-Started-At-Ms":String(t)},body:JSON.stringify({agent_id:e,ack_bot_ready:!0})});if(!n.ok)throw n.status===429?new qm:new Error(`Failed to create agent room: ${n.statusText}`);const r=await n.json();return"session_id"in r&&r.session_id!=null&&console.info("session_info",{session_id:r.session_id}),r}async function px(e){const t=await fetch(`${fx}/agents/${e}`,{method:"GET",headers:{"Content-Type":"application/json"}});if(!t.ok)throw new Error(`Failed to get agent: ${t.statusText}`);return await t.json()}function mx(){return 0}function gx({agentId:e,isInline:t,hidePoweredBy:n,hideUI:r=!1,showKeyboardOnMobile:i=!1}){const{agentData:o,setAgentData:a}=Qt(),{widgetState:s,setWidgetState:c,roomUrl:l,setRoomUrl:d,isTransitioning:f,isAboutToTransition:m,hasJoinedRoom:g,setHasJoinedRoom:y,resetDailyState:v,setIsAgentVideoReady:b,setIsImageChanging:_,setIsImageChangeRequested:S,setAudioPermissionBlocked:T,retryDailyAudioRef:M}=At(),{startMaxVideoTimer:x,errorMsg:C,setErrorMsg:E,setNonFatalErrorMsg:O}=io(),{resetInitMsg:V}=Rc(),{isAudioMuted:B,isMicMuted:N}=Nr(),{hasUserInteracted:z}=er(),R=kt(),ee=Rr(),X=Xt({filter:"remote"}),Z=ae(!1),W=ae(!1),K=ae(null),$=ae(null),[U,ie]=te(!1),[le,u]=te(!1);J(()=>{e&&px(e).then(h=>{if(!h.sufficient_balance)throw new Error("Insufficient balance");a(h)}).catch(h=>{console.error("Error fetching agent data:",h)})},[e,a]),J(()=>{s===ke&&z&&!Z.current&&!l&&e&&!C&&(Z.current=!0,hx(e).then(h=>{h.room_url?d(h.room_url):E("An error occurred. Please try again.")}).catch(h=>{console.error("Error creating agent room:",h),h instanceof qm?E("This agent is currently busy. Please try again in a few minutes."):E("An error occurred. Please try again.")}).finally(()=>{Z.current=!1}))},[s,z,e,l,C]),J(()=>{if(s!==ke||!R||!l||g||W.current)return;W.current=!0;const h=mx(),w=()=>{R.join({url:l,audioSource:!0,videoSource:!1,startAudioOff:N,dailyConfig:{alwaysIncludeMicInPermissionPrompt:!1}}).then(()=>{y(!0),V()}).catch(k=>{console.error("Error joining call:",k),E("An error occurred. Please try again."),y(!1)}).finally(()=>{W.current=!1})};if(h>0){console.log(`[cold start] Delaying join by ${h}ms (from ?coldStartDelay=${h})`);const k=window.setTimeout(w,h);return()=>{window.clearTimeout(k),W.current=!1}}w()},[s,R,l,g,N]),J(()=>{R&&!g&&R.leave()},[g,R]),J(()=>(!g&&$.current&&($.current.getTracks().forEach(h=>{h.stop()}),$.current=null),()=>{$.current&&($.current.getTracks().forEach(h=>{h.stop()}),$.current=null)}),[g]),q("app-message",j(h=>{h?.data?.type==="pipecat_shutdown"&&(E("An error occurred. Please try again."),v()),h?.data?.type==="bot_ready"&&(b(!0),ee({event:"bot_ready_ack"},"*")),h?.data?.type==="gpu_error"&&(E("An error occurred. Please try again."),v()),h?.data?.type==="image_created"&&(_(!0),S(!1)),h?.data?.type==="image_change_complete"&&(_(!1),S(!1)),h?.data?.type==="image_change_error"&&(S(!1),_(!1),O("Unable to imagine"))},[ee])),q("participant-joined",j(()=>{x()},[])),q("error",j(()=>{console.error("Encountered Daily error"),E("An error occurred. Please try again.")},[])),q("participant-left",j(()=>{!C&&g&&(console.error("Agent left the call"),c(Qe),v())},[g])),q("network-connection",j(h=>{if(!h)return;const w=h.type,k=h.event;k==="connected"?w==="peer-to-peer"||w==="sfu"?ie(!1):w==="signaling"&&u(!1):k==="interrupted"&&(w==="peer-to-peer"||w==="sfu"?ie(!0):w==="signaling"&&u(!0))},[])),J(()=>{O(le?"Network issues.":U?"Poor connection.":"")},[U,le]);const p=j(h=>{const w=new Date().toISOString();if(console.error("DailyAudio play failed:",{name:h?.name,message:h?.message,sessionId:h?.sessionId,type:h?.type,timestamp:w,full:h}),h?.name==="NotAllowedError"){T(!0);return}E("An error occurred. Please try again.")},[E,T]);return J(()=>(M.current=()=>{T(!1),R&&navigator.mediaDevices?.getUserMedia({audio:!0})?.then(w=>{const k=w.getAudioTracks()[0];k&&typeof R.updateInputSettings=="function"?($.current&&$.current.getTracks().forEach(P=>{P.stop()}),$.current=w,R.updateInputSettings({audio:{settings:{customTrack:k}}}).catch(P=>console.warn("updateInputSettings(audio) failed:",P))):w.getTracks().forEach(P=>{P.stop()})}).catch(w=>console.warn("getUserMedia(audio) in retry failed:",w));const h=K.current?.getAllAudio?.();if(h?.length){const w=h.filter(k=>k).map(k=>(k.muted=!1,k.play()));Promise.allSettled(w).then(k=>{const P=k.every(D=>D.status==="rejected");T(P)})}},()=>{M.current=null}),[M,T,R]),J(()=>{if(K.current){const h=K.current.getAllAudio();h&&h.length>0&&h.forEach(w=>{w&&(w.muted=B)})}},[B,X.length]),J(()=>{const h=()=>{v()};return window.addEventListener("beforeunload",h),()=>{window.removeEventListener("beforeunload",h),v(),$.current&&($.current.getTracks().forEach(w=>{w.stop()}),$.current=null)}},[]),o?A("div",{className:t?"":"fixed bottom-5 right-5 z-1000 flex flex-col items-end",children:[!r&&(s===Et||f||m)&&A(ux,{}),(s===ke||s===Qe||f||m)&&A(lx,{hideUI:r,showKeyboardOnMobile:i}),A("div",{className:"fixed bottom-[6px] right-5 text-right text-[8px] text-white mix-blend-difference transition-opacity duration-150 shadow-2xs pr-[4px]",style:{visibility:!t&&!n&&!r&&s!==Et?"visible":"hidden"},children:["Powered by"," ",A("a",{href:"https://lemonslice.com",target:"_blank",rel:"noopener noreferrer",className:"underline",children:"Lemon Slice"})]}),A(Ff,{ref:K,onPlayFailed:p})]}):null}const vx=Le(void 0);function yx({children:e,agentId:t,onAPIReady:n}){const r=Rr(),{isAudioMuted:i,setIsAudioMuted:o,isMicMuted:a,setIsMicMuted:s}=Nr(),{widgetState:c,setWidgetState:l,hasJoinedRoom:d,setIsImageChangeRequested:f}=At(),{setHasUserInteracted:m}=er(),{sendMessage:g}=Rc(),{agentData:y}=Qt(),v=Xt({filter:"remote"}),b=j(()=>{m(!0),c!==ke&&l(ke)},[c,m,l]),_=j(async()=>{o(!0)},[o]),S=j(async()=>{o(!1)},[o]),T=j(()=>i,[i]),M=j(()=>!0,[]),x=j(async()=>{b(),s(!1)},[b,s]),C=j(async()=>{s(!0)},[s]),E=j(()=>!a,[a]),O=j(()=>!0,[]),V=j(async z=>{if(!z.trim())throw new Error("Message cannot be empty");const R=z.trim();b(),g(R,r,d,v,{allowImageEdits:y?.allow_image_edits||!1,setIsImageChangeRequested:f})},[b,r,g,d,v,y,f]),B=Ne(()=>({mute:_,unmute:S,isMuted:T,canUnmute:M,micOn:x,micOff:C,isMicOn:E,canTurnOnMic:O,sendMessage:V}),[_,S,T,M,x,C,E,O,V]),N=ae(n);return J(()=>{N.current=n},[n]),J(()=>{N.current&&N.current(B)},[B]),A(vx.Provider,{value:{api:B},children:e})}function ko(e){if(e==null||e==="")return null;if(typeof e=="number")return Number.isFinite(e)?e:null;const t=Number(e);return Number.isFinite(t)?t:null}const Gm="#919191",bx=.3,_x=.1;function wx(e,t){if(e==null||e==="")return t;const n=typeof e=="number"?e:Number(e);return Number.isFinite(n)?Math.min(1,Math.max(0,n)):t}function Km(e){if(typeof e!="string")return null;const n=e.trim().match(/^#?([0-9a-fA-F]{3}|[0-9a-fA-F]{6})$/);if(!n)return null;let r=n[1];r.length===3&&(r=r.split("").map(s=>s+s).join(""));const i=parseInt(r.slice(0,2),16),o=parseInt(r.slice(2,4),16),a=parseInt(r.slice(4,6),16);return[i,o,a].some(s=>Number.isNaN(s))?null:{r:i,g:o,b:a}}function kx(e={}){const t=e["agent-id"]||void 0,[n,r]=te(null),i=e.inline,o=i==="true"||i===""||i===!0,a=e["show-minimize-button"],s=a===void 0||a==="true"||a===""||a===!0,c=e["initial-state"],l=c==="active"||c==="minimized"||c==="hidden"?c:"minimized",d=e["controlled-widget-state"],f=d==="active"||d==="minimized"||d==="hidden"?d:null,m=e["controlled-show-minimize-button"],g=m===void 0?null:m==="true"||m===""||m===!0,y=ko(e["custom-active-width"]),v=ko(e["custom-active-height"]),b=ko(e["custom-minimized-width"]),_=ko(e["custom-minimized-height"]),S=typeof e["video-button-color-hex"]=="string"?e["video-button-color-hex"].trim():"",T=Km(Gm),M=Km(S||Gm)??T,x=wx(e["video-button-color-opacity"],bx),C=Math.max(0,Math.min(1,x-_x)),E=e["hide-powered-by"],O=E==="true"||E===""||E===!0,V=e["hide-ui"],B=V==="true"||V===""||V===!0,N=e["skip-welcome-video"],z=N==="true"||N===""||N===!0,R=e["show-keyboard-on-mobile"],ee=R==="true"||R===""||R===!0,X=typeof e["video-button-text"]=="string"?e["video-button-text"].trim():null,Z=`rgba(${M.r}, ${M.g}, ${M.b}, ${x})`,W=`rgba(${M.r}, ${M.g}, ${M.b}, ${C})`,K={"--color-primary-action":Z,"--color-primary-action-hover":W},$=Ne(()=>Or.createCallObject({videoSource:!1,audioSource:!0}),[]),U=ae(null);return J(()=>{U.current=n},[n]),J(()=>{if(!n)return;const ie=()=>{const u=document.querySelectorAll("lemon-slice-widget");let p=null;for(const h of u){const w=h.getAttribute("agent-id");if((w===t||!w&&!t&&!p)&&(p=h,w===t))break}!p&&u.length>0&&(p=u[0]),p&&(p.mute=()=>U.current?.mute(),p.unmute=()=>U.current?.unmute(),p.isMuted=()=>U.current?.isMuted()??!1,p.canUnmute=()=>U.current?.canUnmute()??!1,p.micOn=()=>U.current?.micOn(),p.micOff=()=>U.current?.micOff(),p.isMicOn=()=>U.current?.isMicOn()??!1,p.canTurnOnMic=()=>U.current?.canTurnOnMic()??!1,p.sendMessage=h=>U.current?.sendMessage(h))};ie();const le=setTimeout(ie,100);return()=>clearTimeout(le)},[!!n,t]),J(()=>()=>{if($){try{const ie=$.meetingState();(ie==="joined-meeting"||ie==="joining-meeting")&&$.leave()}catch{}try{$.destroy()}catch(ie){console.error("Error destroying call object:",ie)}}},[$]),A("div",{translate:!1,style:K,children:A(X0,{children:A(Q0,{children:A(q0,{children:A(F0,{callObject:$,children:A(K0,{showMinimizeButton:s,initialState:l,controlledWidgetState:f,controlledShowMinimizeButton:g,customActiveWidth:y,customActiveHeight:v,customMinimizedWidth:b,customMinimizedHeight:_,videoButtonText:X,skipWelcomeVideo:z,children:A(e_,{children:A(Y0,{children:A(rx,{children:A(yx,{agentId:t,onAPIReady:ie=>{r(ie)},children:[A(J0,{}),A(gx,{agentId:t,isInline:o,hidePoweredBy:O,hideUI:B,showKeyboardOnMobile:ee})]})})})})})})})})})})}const Sx=["agent-id","inline","show-minimize-button","initial-state","controlled-widget-state","controlled-show-minimize-button","custom-active-width","custom-active-height","custom-minimized-width","custom-minimized-height","video-button-color-hex","video-button-color-opacity","video-button-text","hide-powered-by","hide-ui","show-keyboard-on-mobile"];function Ym(e="lemon-slice-widget"){sg(kx,e,Sx,{shadow:!0,mode:"open"})}return Ym(),xo.registerWidget=Ym,Object.defineProperty(xo,Symbol.toStringTag,{value:"Module"}),xo})({});
|