@verba-ai/chat-sdk 1.0.6 → 1.0.7
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/chat-sdk.umd.cjs
CHANGED
|
@@ -115,5 +115,5 @@
|
|
|
115
115
|
`;const i=document.createElementNS("http://www.w3.org/2000/svg","svg");return i.setAttribute("class","verba-bubble-icon verba-bubble-icon--close"),i.setAttribute("width","22"),i.setAttribute("height","22"),i.setAttribute("viewBox","0 0 24 24"),i.setAttribute("fill","none"),i.setAttribute("stroke",e?.closeIconColor??"#ffffff"),i.setAttribute("stroke-width","2.5"),i.setAttribute("stroke-linecap","round"),i.innerHTML=`
|
|
116
116
|
<line x1="18" y1="6" x2="6" y2="18"/>
|
|
117
117
|
<line x1="6" y1="6" x2="18" y2="18"/>
|
|
118
|
-
`,t.appendChild(s),t.appendChild(i),J(t,{boxShadow:["0 4px 20px rgba(99,102,241,0.45), 0 0 0 0 rgba(99,102,241,0.4)","0 4px 20px rgba(99,102,241,0.45), 0 0 0 14px rgba(99,102,241,0)","0 4px 20px rgba(99,102,241,0.45), 0 0 0 0 rgba(99,102,241,0)"]},{duration:1.8,ease:"easeOut",delay:.4,repeat:1}),t}function va(e){e.style.pointerEvents="all",J(e,{opacity:1,display:"block",y:0,scale:1},{duration:.25,ease:[.4,0,.2,1]})}function Ta(e){e.style.pointerEvents="none",J(e,{opacity:0,display:"none",y:12,scale:.97},{duration:.25,ease:[.4,0,.2,1]})}function es(e,t){e.classList.toggle(da,t),e.setAttribute("aria-label",t?"Close chat":"Open chat"),e.setAttribute("aria-expanded",String(t));const n=e.querySelector(".verba-bubble-icon--chat"),s=e.querySelector(".verba-bubble-icon--close");t?(J(n,{opacity:0,scale:.5,rotate:90},{duration:.22,ease:[.34,1.56,.64,1]}),J(s,{opacity:1,scale:1,rotate:0},{duration:.22,ease:[.34,1.56,.64,1]})):(J(n,{opacity:1,scale:1,rotate:0},{duration:.22,ease:[.34,1.56,.64,1]}),J(s,{opacity:0,scale:.5,rotate:-90},{duration:.22,ease:[.34,1.56,.64,1]}))}const xa="
|
|
118
|
+
`,t.appendChild(s),t.appendChild(i),J(t,{boxShadow:["0 4px 20px rgba(99,102,241,0.45), 0 0 0 0 rgba(99,102,241,0.4)","0 4px 20px rgba(99,102,241,0.45), 0 0 0 14px rgba(99,102,241,0)","0 4px 20px rgba(99,102,241,0.45), 0 0 0 0 rgba(99,102,241,0)"]},{duration:1.8,ease:"easeOut",delay:.4,repeat:1}),t}function va(e){e.style.pointerEvents="all",J(e,{opacity:1,display:"block",y:0,scale:1},{duration:.25,ease:[.4,0,.2,1]})}function Ta(e){e.style.pointerEvents="none",J(e,{opacity:0,display:"none",y:12,scale:.97},{duration:.25,ease:[.4,0,.2,1]})}function es(e,t){e.classList.toggle(da,t),e.setAttribute("aria-label",t?"Close chat":"Open chat"),e.setAttribute("aria-expanded",String(t));const n=e.querySelector(".verba-bubble-icon--chat"),s=e.querySelector(".verba-bubble-icon--close");t?(J(n,{opacity:0,scale:.5,rotate:90},{duration:.22,ease:[.34,1.56,.64,1]}),J(s,{opacity:1,scale:1,rotate:0},{duration:.22,ease:[.34,1.56,.64,1]})):(J(n,{opacity:1,scale:1,rotate:0},{duration:.22,ease:[.34,1.56,.64,1]}),J(s,{opacity:0,scale:.5,rotate:-90},{duration:.22,ease:[.34,1.56,.64,1]}))}const xa="https://embed.verba.chat/embeddable.html";class Et extends Error{constructor(t){super(`[VerbaChatSDK] ${t}`),this.name="ChatSDKError"}}class Sa{config;state="uninitialized";isVisible=!1;isInline=!1;container=null;iframe=null;bubble=null;cleanupCallbacks=[];constructor(t){const n=t.tagId;if(!n?.trim())throw new Et("`tagId` is required and must not be empty.");this.config={tagId:n.trim(),theme:t.theme??"light",bubble:t.bubble,container:t.container}}init(){return this.assertState("uninitialized","init"),pa(),this.state="ready",this.isInline=!!this.config.container,this.isInline?this.mountInline():this.mountFloating(),this}show(){return this.assertNotState("uninitialized","show"),this.assertNotState("destroyed","show"),this.isVisible||!this.iframe?this:(this.isVisible=!0,this.isInline||(va(this.iframe),this.bubble&&es(this.bubble,!0)),this)}hide(){return this.assertNotState("uninitialized","hide"),this.assertNotState("destroyed","hide"),!this.isVisible||!this.iframe?this:(this.isVisible=!1,this.isInline||(Ta(this.iframe),this.bubble&&es(this.bubble,!1)),this)}destroy(){if(this.state!=="destroyed"){this.container?.remove(),this.container=null,this.iframe=null,this.bubble=null;for(const t of this.cleanupCallbacks)t();this.cleanupCallbacks.length=0,ma(),this.state="destroyed",this.isVisible=!1}}get currentState(){return this.state}mountInline(){const t=this.resolveContainer();if(!t){console.error("[VerbaChatSDK] Container element not found. Falling back to floating mode."),this.isInline=!1,this.mountFloating();return}const n=ya(),s=ts(this.buildWidgetUrl());n.appendChild(s),t.appendChild(n),this.container=n,this.iframe=s,this.isVisible=!0}mountFloating(){const t=this.config.bubble?.position??"bottom-right",n=ga(t),s=ts(this.buildWidgetUrl()),i=ba(this.config.bubble),r=()=>{this.isVisible?this.hide():this.show()};i.addEventListener("click",r),this.cleanupCallbacks.push(()=>i.removeEventListener("click",r));const a=o=>{this.isVisible&&this.container&&o.target instanceof Node&&!this.container.contains(o.target)&&this.hide()};document.addEventListener("click",a,!0),this.cleanupCallbacks.push(()=>document.removeEventListener("click",a,!0)),n.appendChild(s),n.appendChild(i),document.body.appendChild(n),this.container=n,this.iframe=s,this.bubble=i,this.isVisible=!1}assertState(t,n){if(this.state!==t)throw new Et(`Cannot call \`${n}()\` in state "${this.state}". Expected "${t}".`)}assertNotState(t,n){if(this.state===t)throw new Et(`Cannot call \`${n}()\` in state "${t}".`)}resolveContainer(){const{container:t}=this.config;return t?typeof t=="string"?document.querySelector(t):t:null}buildWidgetUrl(){const t=new URL(xa);if(t.searchParams.set("tag-id",this.config.tagId),t.searchParams.set("sdk-version","1.0.7"),typeof this.config.theme=="object"){const n=this.config.theme;n.primaryColor&&t.searchParams.set("color",n.primaryColor),n.textColor&&t.searchParams.set("textColor",n.textColor),n.backgroundColor&&t.searchParams.set("backgroundColor",n.backgroundColor),n.fontFamily&&t.searchParams.set("fontFamily",n.fontFamily)}else t.searchParams.set("theme",this.config.theme);return t.toString()}}q.ChatSDK=Sa,q.ChatSDKError=Et,Object.defineProperty(q,Symbol.toStringTag,{value:"Module"})}));
|
|
119
119
|
//# sourceMappingURL=chat-sdk.umd.cjs.map
|