signalbird 2.0.1 → 2.0.2
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/README.md +1 -1
- package/dist/signalbird.js +1 -1
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -94,7 +94,7 @@ değil, kasıtlı bir duvardır — anahtar bir kez istemciye indiğinde herkesi
|
|
|
94
94
|
| Go | `go get github.com/Pariette-Inc/signalbird.sdk` |
|
|
95
95
|
| .NET, ASP.NET Core | `dotnet add package Signalbird.Sdk` |
|
|
96
96
|
| Swift (iOS, macOS) | SPM: `https://github.com/Pariette-Inc/signalbird.sdk` |
|
|
97
|
-
| Kotlin (Android) | `implementation("io.signalbird:signalbird-sdk:2.0.
|
|
97
|
+
| Kotlin (Android) | `implementation("io.signalbird:signalbird-sdk:2.0.2")` |
|
|
98
98
|
| Canlı sohbet widget'ı (herhangi bir site) | `<script async src="https://signalbird.io/sdk/v1/signalbird.js" data-key="sb_public_live_…" data-channel="destek"></script>` |
|
|
99
99
|
|
|
100
100
|
> Hepsi **bu repodan** çıkar ve **aynı sürümü** taşır — ayrı SDK reposu ya da
|
package/dist/signalbird.js
CHANGED
|
@@ -274,5 +274,5 @@ transition:filter .15s,transform .1s}
|
|
|
274
274
|
.notice{margin:10px 16px;padding:10px 13px;font-size:12.5px;color:var(--sb-m);background:var(--sb-s);border:1px solid var(--sb-b);
|
|
275
275
|
border-radius:11px;text-align:center}
|
|
276
276
|
.notice button{color:var(--sb-c);font-weight:600;margin-left:6px}
|
|
277
|
-
`;function a(s,e,...t){let i=document.createElement(s);if(e)for(let n in e){let r=e[n];r==null||r===false||(n==="class"?i.className=String(r):n==="style"?i.setAttribute("style",String(r)):n.startsWith("on")&&typeof r=="function"?i.addEventListener(n.slice(2).toLowerCase(),r):n==="html"?i.innerHTML=String(r):n in i&&n!=="list"&&n!=="form"?i[n]=r:i.setAttribute(n,String(r)));}return be(i,t),i}function be(s,e){for(let t of e)t==null||t===false||s.appendChild(typeof t=="object"?t:document.createTextNode(String(t)));}function C(s){for(;s.firstChild;)s.removeChild(s.firstChild);}function v(s,e=18){let t=document.createElementNS("http://www.w3.org/2000/svg","svg");return t.setAttribute("viewBox","0 0 24 24"),t.setAttribute("width",String(e)),t.setAttribute("height",String(e)),t.setAttribute("fill","none"),t.setAttribute("stroke","currentColor"),t.setAttribute("stroke-width","2"),t.setAttribute("stroke-linecap","round"),t.setAttribute("stroke-linejoin","round"),t.innerHTML=ve[s],t}function K(s=26){let e=document.createElementNS("http://www.w3.org/2000/svg","svg");return e.setAttribute("viewBox","10 2 28 38"),e.setAttribute("width",String(s)),e.setAttribute("height",String(s)),e.setAttribute("fill","none"),e.setAttribute("stroke","currentColor"),e.setAttribute("stroke-width","2"),e.setAttribute("stroke-linejoin","round"),e.setAttribute("aria-hidden","true"),e.innerHTML='<path d="M16 16 L30 16 L33 18 L24 33 L15 18 Z" fill="currentColor" fill-opacity=".18" stroke="none"/><path d="M23 4 L31 9 L23 14 L16 9 Z" fill="currentColor" fill-opacity=".28" stroke="none"/><path d="M30 16 L33 18 L36 27 L34 34 L41 32 L44 38 L31 37 L24 37 L17 35 L13 27 L15 18 L16 16"/><path d="M16 16 L16 9 L23 4 L31 9 L30 16"/><path d="M21.4 12.4 L23.2 18.6 L25 12.4 Z" fill="currentColor" fill-opacity=".35"/><circle cx="28.4" cy="11.4" r="1.6" fill="currentColor" stroke="none"/>',e}var ve={chat:'<path d="M21 11.5a8.4 8.4 0 0 1-.9 3.8 8.5 8.5 0 0 1-7.6 4.7 8.4 8.4 0 0 1-3.8-.9L3 21l1.9-5.7a8.4 8.4 0 0 1-.9-3.8 8.5 8.5 0 0 1 4.7-7.6 8.4 8.4 0 0 1 3.8-.9h.5a8.5 8.5 0 0 1 8 8v.5z"/>',close:'<path d="M18 6 6 18M6 6l12 12"/>',send:'<path d="m22 2-7 20-4-9-9-4 20-7z"/><path d="M22 2 11 13"/>',clip:'<path d="m21.4 11.05-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"/>',file:'<path d="M14.5 2H6a2 2 0 0 0-2 2v16a2 2 0 0 0 2 2h12a2 2 0 0 0 2-2V7.5L14.5 2z"/><path d="M14 2v6h6"/>',check:'<path d="M20 6 9 17l-5-5"/>',checks:'<path d="M18 6 7 17l-4-4"/><path d="m22 10-7.5 7.5L13 16"/>',reply:'<path d="M9 17H5a2 2 0 0 1-2-2V9"/><path d="m3 9 4-4"/><path d="m3 9 4 4"/><path d="M9 17h6a6 6 0 0 0 0-12h-2"/>',more:'<circle cx="12" cy="12" r="1"/><circle cx="19" cy="12" r="1"/><circle cx="5" cy="12" r="1"/>',star:'<path d="m12 2 3.09 6.26L22 9.27l-5 4.87 1.18 6.88L12 17.77l-6.18 3.25L7 14.14 2 9.27l6.91-1.01L12 2z"/>',chevron:'<path d="m6 9 6 6 6-6"/>',smile:'<circle cx="12" cy="12" r="10"/><path d="M8 14s1.5 2 4 2 4-2 4-2"/><path d="M9 9h.01M15 9h.01"/>',done:'<path d="M22 11.08V12a10 10 0 1 1-5.93-9.14"/><path d="m22 4-10 10-3-3"/>'};function ee(s){return s<1024?`${s} B`:s<1024*1024?`${(s/1024).toFixed(0)} KB`:`${(s/1024/1024).toFixed(1)} MB`}function te(){return typeof crypto!="undefined"&&"randomUUID"in crypto?crypto.randomUUID():"xxxxxxxx-xxxx-4xxx-yxxx-xxxxxxxxxxxx".replace(/[xy]/g,s=>{let e=Math.random()*16|0;return (s==="x"?e:e&3|8).toString(16)})}var ie=["\u{1F44D}","\u2764\uFE0F","\u{1F602}","\u{1F62E}","\u{1F622}","\u{1F64F}"],ye=900*1e3;function ae(s,e){let t=s.scrollHeight-s.scrollTop-s.clientHeight<40,i=s.scrollHeight;C(s),e.greeting&&e.messages.length===0&&s.appendChild(a("div",{class:"gr"},e.greeting));let n="",r=null;for(let o of e.messages){let l=Ce(o.created_at);l!==n&&(s.appendChild(a("div",{class:"day"},Te(o.created_at,e))),n=l,r=null),s.appendChild(xe(o,e,r)),r=o;}(t||i===0)&&(s.scrollTop=s.scrollHeight);}function U(s){s.scrollTop=s.scrollHeight;}function xe(s,e,t){var f;let i=s.sender_type==="visitor"?"v":s.sender_type==="system"?"s":"a",n=t&&t.sender_type!==s.sender_type,r=a("div",{class:`row ${i}${n?" gap":""}${s._pending?" pend":""}${s._failed?" fail":""}`,"data-id":s.id}),o=a("div",{class:`bb${s.deleted_at?" del":""}`});if(s.deleted_at)return o.textContent=e.t.deleted,r.appendChild(o),r;if(s.reply_to_id){let c=e.find(s.reply_to_id),u=c?c.sender_type==="visitor"?e.t.you:c.sender_name||e.agentName:"";o.appendChild(a("span",{class:"q"},u?`${u}: `:"",c?I(c,e.t):"\u2026"));}let l=s.attachments||[],d=l.filter(c=>ne(c.mime)),h=l.filter(c=>!ne(c.mime));if(s._files&&s._files.length){let c=a("div",{class:"imgs"});for(let u of s._files)u.type.startsWith("image/")?c.appendChild(a("img",{src:URL.createObjectURL(u),alt:u.name})):o.appendChild(se({name:u.name,url:"",mime:u.type,size:u.size},e));c.childNodes.length&&o.appendChild(c);}if(d.length){let c=a("div",{class:"imgs"});for(let u of d)c.appendChild(a("img",{src:u.url,alt:u.name,loading:"lazy",onclick:()=>e.actions.openImage(u.url)}));o.appendChild(c);}for(let c of h)o.appendChild(se(c,e));let g=(i==="v"?null:(f=s.translation)==null?void 0:f.body)||s.body;g&&o.appendChild(document.createTextNode(g)),s._failed&&(o.appendChild(a("div",{style:"font-size:11px;margin-top:4px"},e.t.failed)),o.addEventListener("click",()=>e.actions.retry(s))),r.appendChild(o);let p=s.reactions&&Object.keys(s.reactions).length?s.reactions:null;if(p){let c=a("div",{class:"rx"});for(let u in p){let b=p[u]||[];if(!b.length)continue;let x=b.includes("visitor");c.appendChild(a("button",{class:x?"me":"",type:"button",onclick:()=>e.actions.react(s,u)},`${u} ${b.length}`));}c.childNodes.length&&r.appendChild(c);}if(i!=="s"){let c=a("div",{class:"mt"},Le(s.created_at,e.locale));if(s.edited_at&&c.appendChild(a("span",{class:"ed"},`\xB7 ${e.t.edited}`)),i==="v"&&!s._failed){let u=a("span",{class:`tk${s.read_at?" rd":""}`});u.appendChild(s._pending?v("check",12):s.read_at||s.delivered_at?v("checks",13):v("check",12)),s._pending&&(u.style.opacity=".4"),c.appendChild(u);}r.appendChild(c);}return i!=="s"&&!s._pending&&!s._failed&&(r.appendChild(we(s,e,r)),ke(r)),r}function we(s,e,t){let i=a("div",{class:"ac"});for(let l of ie.slice(0,3))i.appendChild(a("button",{type:"button",title:e.t.react,onclick:()=>e.actions.react(s,l)},l));i.appendChild(a("button",{type:"button",title:e.t.reply,onclick:()=>e.actions.reply(s)},v("reply",15)));let n=a("div",{class:"menu"});for(let l of ie.slice(3))n.appendChild(a("button",{type:"button",onclick:()=>{n.classList.remove("show"),e.actions.react(s,l);}},`${l} ${e.t.react}`));return s.sender_type==="visitor"&&Date.now()-Date.parse(s.created_at)<ye&&(n.appendChild(a("button",{type:"button",onclick:()=>{n.classList.remove("show"),e.actions.edit(s);}},e.t.edit)),n.appendChild(a("button",{type:"button",class:"dg",onclick:()=>{n.classList.remove("show"),e.actions.remove(s);}},e.t.delete))),i.appendChild(a("button",{type:"button",title:e.t.react,onclick:l=>{l.stopPropagation(),n.classList.toggle("show"),n.style.top=`${t.offsetHeight+4}px`;}},v("more",15))),t.appendChild(n),document.addEventListener("click",()=>n.classList.remove("show"),{once:true,capture:true}),i}function ke(s){let e=null,t=()=>{e=setTimeout(()=>{s.classList.add("acts");let n=r=>{s.contains(r.target)||(s.classList.remove("acts"),document.removeEventListener("touchstart",n,true));};document.addEventListener("touchstart",n,true);},450);},i=()=>e&&clearTimeout(e);s.addEventListener("touchstart",t,{passive:true}),s.addEventListener("touchend",i),s.addEventListener("touchmove",i,{passive:true});}function se(s,e){return a("a",{class:"fr",href:s.url||void 0,target:"_blank",rel:"noopener"},v("file",18),a("span",{class:"fn"},s.name||e.t.attachment),a("span",{class:"fs"},ee(s.size||0)))}function I(s,e){var n,r;if(s.deleted_at)return e.deleted;let t=(s.sender_type==="visitor"?null:(n=s.translation)==null?void 0:n.body)||s.body;if(t)return t.length>90?t.slice(0,90)+"\u2026":t;let i=(r=s.attachments)==null?void 0:r[0];return i?`\u{1F4CE} ${i.name}`:"\u2026"}function ne(s){return !!s&&s.startsWith("image/")}function Ce(s){let e=new Date(s);return `${e.getFullYear()}-${e.getMonth()}-${e.getDate()}`}function Te(s,e){let t=new Date(s),i=new Date,n=Math.round((re(i)-re(t))/864e5);if(n===0)return e.t.today;if(n===1)return e.t.yesterday;try{return new Intl.DateTimeFormat(e.locale,{day:"numeric",month:"long",year:t.getFullYear()!==i.getFullYear()?"numeric":void 0}).format(t)}catch(r){return t.toLocaleDateString()}}function re(s){return new Date(s.getFullYear(),s.getMonth(),s.getDate()).getTime()}function Le(s,e){let t=new Date(s);try{return new Intl.DateTimeFormat(e,{hour:"2-digit",minute:"2-digit"}).format(t)}catch(i){return t.toLocaleTimeString()}}var Ee={launcher:"Sohbet",title:"Sohbet",online:"\xC7evrimi\xE7i",offline:"Genelde birka\xE7 dakika i\xE7inde yan\u0131tl\u0131yoruz",greeting:"Merhaba! Size nas\u0131l yard\u0131mc\u0131 olabiliriz?",offlineMessage:"\u015Eu an \xE7evrimd\u0131\u015F\u0131y\u0131z. Mesaj\u0131n\u0131z\u0131 b\u0131rak\u0131n, en k\u0131sa s\xFCrede d\xF6nelim.",prechatTitle:"Ba\u015Flamadan \xF6nce",prechatHint:"Size geri d\xF6nebilmemiz i\xE7in bilgilerinizi b\u0131rak\u0131n.",topicLabel:"Konu",topicPlaceholder:"Konu se\xE7in (iste\u011Fe ba\u011Fl\u0131)",name:"Ad\u0131n\u0131z",email:"E-posta",start:"Sohbete ba\u015Fla",skip:"Atla",placeholder:"Mesaj\u0131n\u0131z\u0131 yaz\u0131n\u2026",send:"G\xF6nder",attach:"Dosya ekle",typing:"yaz\u0131yor\u2026",today:"Bug\xFCn",yesterday:"D\xFCn",reply:"Yan\u0131tla",react:"Tepki ver",edit:"D\xFCzenle",delete:"Sil",deleted:"Bu mesaj silindi",edited:"d\xFCzenlendi",save:"Kaydet",cancel:"Vazge\xE7",you:"Siz",agent:"Destek",system:"Sistem",endChat:"Sohbeti bitir",newChat:"Yeni sohbet",resolved:"Bu sohbet \xE7\xF6z\xFCld\xFC olarak i\u015Faretlendi.",closed:"Bu sohbet kapat\u0131ld\u0131.",rateTitle:"Bu sohbeti nas\u0131l buldunuz?",rateComment:"Eklemek istedi\u011Finiz bir \u015Fey var m\u0131? (iste\u011Fe ba\u011Fl\u0131)",rateSend:"G\xF6nder",rateThanks:"Te\u015Fekk\xFCrler! Geri bildiriminiz al\u0131nd\u0131.",reviewIntro:"Yard\u0131mc\u0131 olabildiysek bizi yorumlar m\u0131s\u0131n\u0131z?",reviewCta:"De\u011Ferlendir",failed:"G\xF6nderilemedi \u2014 tekrar dene",fileTooLarge:"Dosya \xE7ok b\xFCy\xFCk (en fazla {mb} MB)",fileNotAllowed:"Yaln\u0131zca foto\u011Fraf y\xFCkleyebilirsiniz",unavailable:"Sohbet \u015Fu an kullan\u0131lam\u0131yor. L\xFCtfen daha sonra tekrar deneyin.",close:"Kapat",dismiss:"Sohbet balonunu gizle",minimize:"K\xFC\xE7\xFClt",unreadTitle:"({n}) Yeni mesaj",dropHere:"Dosyay\u0131 buraya b\u0131rak\u0131n",replyingTo:"Yan\u0131tlan\u0131yor",attachment:"Ek",poweredBy:"Signalbird ile",resize:"Boyutland\u0131r"},Me={launcher:"Chat",title:"Chat",online:"Online",offline:"We usually reply within a few minutes",greeting:"Hi there! How can we help you?",offlineMessage:"We're offline right now. Leave a message and we'll get back to you.",prechatTitle:"Before we start",prechatHint:"Leave your details so we can get back to you.",topicLabel:"Topic",topicPlaceholder:"Pick a topic (optional)",name:"Your name",email:"Email",start:"Start chat",skip:"Skip",placeholder:"Type your message\u2026",send:"Send",attach:"Attach file",typing:"is typing\u2026",today:"Today",yesterday:"Yesterday",reply:"Reply",react:"React",edit:"Edit",delete:"Delete",deleted:"This message was deleted",edited:"edited",save:"Save",cancel:"Cancel",you:"You",agent:"Support",system:"System",endChat:"End chat",newChat:"New chat",resolved:"This conversation was marked as resolved.",closed:"This conversation was closed.",rateTitle:"How was this conversation?",rateComment:"Anything to add? (optional)",rateSend:"Send",rateThanks:"Thanks! Your feedback was received.",reviewIntro:"If we were helpful, would you leave us a review?",reviewCta:"Leave a review",failed:"Not sent \u2014 tap to retry",fileTooLarge:"File is too large (max {mb} MB)",fileNotAllowed:"Only photos can be uploaded",unavailable:"Chat is unavailable right now. Please try again later.",close:"Close",dismiss:"Hide the chat bubble",minimize:"Minimize",unreadTitle:"({n}) New message",dropHere:"Drop the file here",replyingTo:"Replying to",attachment:"Attachment",poweredBy:"Powered by Signalbird",resize:"Resize"};function F(s,e){let t=n=>n&&n!=="auto"?n.toLowerCase().slice(0,2):null;return (t(e)||t(s)||t(typeof navigator!="undefined"?navigator.language:null)||"en")==="tr"?"tr":"en"}function j(s){return s==="tr"?Ee:Me}function P(s,e){return s.replace(/\{(\w+)\}/g,(t,i)=>{var n;return String((n=e[i])!=null?n:"")})}var Se=/^image\/(jpeg|png|gif|webp)$/,O=class{constructor(e){this.o=e;this.list=null;this.typingEl=null;this.textarea=null;this.chips=null;this.replyBar=null;this.notice=null;this.files=[];this.replyTo=null;this.editing=null;this.view="none";this.typingTimer=null;this.wasTyping=false;var d;let t=e.t;this.host=a("div",{id:"signalbird-widget"}),this.root=this.host.attachShadow({mode:"open"}),this.root.appendChild(a("style",null,Q));let i=e.settings.position==="left"?"left":"right",n=e.settings.layout==="sidebar"?" sidebar":"";if(this.wrap=a("div",{class:`sb ${i}${n}${Ae(e.settings.theme)?" dark":""}`,style:`--sb-c:${Re(e.settings.color)}`}),e.settings.theme==="auto"&&typeof matchMedia=="function"){let h=matchMedia("(prefers-color-scheme: dark)");(d=h.addEventListener)==null||d.call(h,"change",g=>this.wrap.classList.toggle("dark",g.matches));}this.badge=a("span",{class:"badge",style:"display:none"});let r=e.settings.launcher_text;this.launcher=a("button",{class:`ln${r?"":" icon-only"}`,type:"button","aria-label":r||t.launcher,onclick:()=>e.actions.open()},this.launcherMark(),r?a("span",{class:"lt"},r):null,this.badge),this.dismissBtn=a("button",{class:"dm",type:"button",title:t.dismiss,"aria-label":t.dismiss,onclick:h=>{h.stopPropagation(),e.actions.dismiss();}},v("close",12)),this.headerAvatar=a("div",{class:"av"},this.brandAvatar()),this.headerName=a("div",{class:"hn"},e.appName||t.title),this.headerDot=a("span",{class:"dot"}),this.headerStatus=a("div",{class:"hs"},this.headerDot,a("span",null,t.offline)),this.endBtn=a("button",{class:"hb",type:"button",title:t.endChat,style:"display:none",onclick:()=>e.actions.endChat()},v("done",18));let o=a("div",{class:"hd"},this.headerAvatar,a("div",{class:"hi"},this.headerName,this.headerStatus),this.endBtn,a("button",{class:"hb",type:"button",title:t.close,"aria-label":t.close,onclick:()=>e.actions.close()},v("close",20)));this.banner=a("div",{class:"bn",style:"display:none"}),this.body=a("div",{class:"bd"}),this.grip=a("div",{class:"gp",title:t.resize,"aria-hidden":"true"}),this.panel=a("div",{class:"pn",role:"dialog","aria-label":t.title},a("div",{class:"br"}),o,this.banner,this.body,this.grip),e.settings.layout!=="sidebar"&&(this.restoreGeometry(),this.enableMove(o),this.enableResize()),this.wrap.appendChild(this.launcher),this.wrap.appendChild(this.dismissBtn),this.wrap.appendChild(this.panel),this.root.appendChild(this.wrap);let l=0;this.body.addEventListener("dragenter",h=>{h.preventDefault(),l++,this.body.classList.add("dragging");}),this.body.addEventListener("dragover",h=>h.preventDefault()),this.body.addEventListener("dragleave",()=>{--l<=0&&(l=0,this.body.classList.remove("dragging"));}),this.body.addEventListener("drop",h=>{var g;h.preventDefault(),l=0,this.body.classList.remove("dragging"),this.view==="chat"&&((g=h.dataTransfer)!=null&&g.files)&&this.addFiles(Array.from(h.dataTransfer.files));});}mount(){this.host.isConnected||document.body.appendChild(this.host);}unmount(){this.host.remove();}setDismissed(e){this.wrap.classList.toggle("hidden",e);}setLauncherHidden(e){this.wrap.classList.toggle("no-ln",e);}setOpen(e){this.wrap.classList.toggle("open",e),e&&this.list&&requestAnimationFrame(()=>{var t;this.list&&U(this.list),(t=this.textarea)==null||t.focus();});}setUnread(e){this.badge.textContent=e>99?"99+":String(e),this.badge.style.display=e>0?"flex":"none";}attention(){let e=this.launcher;e.classList.remove("sb-attn"),e.offsetWidth,e.classList.add("sb-attn"),window.setTimeout(()=>e.classList.remove("sb-attn"),2400);}setHeader(e,t){var o;let i=this.o.t,n=(e==null?void 0:e.name)||this.o.appName||i.title;this.headerName.textContent=n,C(this.headerAvatar),e!=null&&e.avatar?this.headerAvatar.appendChild(a("img",{src:e.avatar,alt:""})):this.headerAvatar.appendChild(e?document.createTextNode(oe(n)):this.brandAvatar());let r=(o=e==null?void 0:e.online)!=null?o:t;this.headerDot.classList.toggle("on",r),this.headerStatus.lastChild.textContent=r?i.online:i.offline;}setBanner(e,t=false){this.banner.textContent=e||"",this.banner.className=`bn${t?" err":""}`,this.banner.style.display=e?"block":"none";}setEndVisible(e){this.endBtn.style.display=e?"flex":"none";}showPrechat(e){let t=this.o.t,i=this.o.settings.prechat||{name:true,email:true,required:false};this.view="prechat",this.list=null,this.textarea=null,C(this.body);let n=a("input",{type:"text",placeholder:t.name,value:e.name||"",autocomplete:"name"}),r=a("input",{type:"email",placeholder:t.email,value:e.email||"",autocomplete:"email"}),o=this.o.topics||[],l=o.length?a("select",{"aria-label":t.topicLabel},a("option",{value:""},t.topicPlaceholder),...o.map(g=>a("option",{value:g.slug},g.name))):null,d=()=>{let g=n.value.trim(),p=r.value.trim();if(i.required&&(i.name&&!g||i.email&&!p)){(i.name&&!g?n:r).focus();return}if(p&&!/^[^\s@]+@[^\s@]+\.[^\s@]+$/.test(p)){r.focus();return}this.o.actions.submitPrechat(g,p,(l==null?void 0:l.value)||null);},h=a("form",{class:"fm",onsubmit:g=>{g.preventDefault(),d();}},a("h3",null,t.prechatTitle),a("p",null,this.o.settings.greeting||t.prechatHint),i.name?n:null,i.email?r:null,l,a("button",{class:"btn",type:"submit"},t.start),i.required?null:a("button",{class:"btn gh",type:"button",onclick:()=>this.o.actions.skipPrechat((l==null?void 0:l.value)||null)},t.skip));this.body.appendChild(h),setTimeout(()=>(i.name?n:r).focus(),50);}showChat(){if(this.view==="chat"&&this.list)return;let e=this.o.t;this.view="chat",C(this.body),this.list=a("div",{class:"ml"}),this.notice=a("div",{class:"notice",style:"display:none"}),this.typingEl=a("div",{class:"tp"},a("i"),a("i"),a("i"),a("span",{style:"margin-left:4px"},"")),this.replyBar=a("div",{class:"rq",style:"display:none"}),this.chips=a("div",{class:"chips",style:"display:none"}),this.textarea=a("textarea",{rows:1,placeholder:e.placeholder,"aria-label":e.placeholder,onkeydown:n=>{n.key==="Enter"&&!n.shiftKey&&!n.isComposing?(n.preventDefault(),this.submit()):n.key==="Escape"&&(this.editing?this.cancelEdit():this.replyTo&&this.setReply(null));},oninput:()=>{this.autosize(),this.notifyTyping();},onpaste:n=>{var o;let r=Array.from(((o=n.clipboardData)==null?void 0:o.files)||[]);r.length&&(n.preventDefault(),this.addFiles(r));}});let t=a("input",{type:"file",multiple:true,style:"display:none",accept:"image/jpeg,image/png,image/gif,image/webp",onchange:()=>{this.addFiles(Array.from(t.files||[])),t.value="";}}),i=a("div",{class:"cp"},this.replyBar,this.chips,a("div",{class:"cr"},a("button",{class:"cb",type:"button",title:e.attach,"aria-label":e.attach,onclick:()=>t.click()},v("clip",19)),this.textarea,a("button",{class:"cb sd",type:"button",title:e.send,"aria-label":e.send,onclick:()=>this.submit()},v("send",17))),t,a("div",{class:"pw"},a("a",{href:"https://signalbird.io",target:"_blank",rel:"noopener",title:e.poweredBy},a("span",{class:"pk"},K(13)),a("span",{class:"pn2"},"Signalbird"))));this.body.appendChild(this.list),this.body.appendChild(this.notice),this.body.appendChild(this.typingEl),this.body.appendChild(i),this.body.appendChild(a("div",{class:"drop"},e.dropHere));}showRating(){let e=this.o.t;this.view="rating",this.list=null,this.textarea=null,C(this.body);let t=0,i=[],n=()=>i.forEach((d,h)=>d.classList.toggle("on",h<t)),r=a("div",{class:"stars"});for(let d=1;d<=5;d++){let h=a("button",{type:"button","aria-label":String(d),onclick:()=>{t=d,n();}},v("star",30));i.push(h),r.appendChild(h);}let o=a("textarea",{placeholder:e.rateComment}),l=a("form",{class:"fm",onsubmit:d=>{d.preventDefault(),this.o.actions.rate(t,o.value.trim());}},a("h3",{style:"text-align:center"},e.rateTitle),r,o,a("button",{class:"btn",type:"submit"},e.rateSend),a("button",{class:"btn gh",type:"button",onclick:()=>this.o.actions.rate(0,"")},e.skip));this.body.appendChild(l);}showThanks(e){this.view="none",this.list=null,C(this.body);let t=a("div",{class:"ok"},a("p",null,this.o.t.rateThanks));e!=null&&e.url&&(t.appendChild(a("p",{class:"rv"},this.o.t.reviewIntro)),t.appendChild(a("a",{class:"btn",href:e.url,target:"_blank",rel:"noopener noreferrer",style:"margin-top:10px;display:inline-flex;text-decoration:none"},e.label||this.o.t.reviewCta))),t.appendChild(a("button",{class:"btn gh",type:"button",style:"margin-top:10px",onclick:()=>this.o.actions.newChat()},this.o.t.newChat)),this.body.appendChild(t);}get currentView(){return this.view}render(e){this.list&&ae(this.list,{...e,t:this.o.t,locale:this.o.locale,actions:this.o.actions});}setTyping(e,t){this.typingEl&&(this.typingEl.classList.toggle("on",e),this.typingEl.lastChild.textContent=`${t} ${this.o.t.typing}`,e&&this.list&&U(this.list));}setNotice(e,t){if(this.notice){if(C(this.notice),!e){this.notice.style.display="none";return}this.notice.appendChild(document.createTextNode(e)),t&&this.notice.appendChild(a("button",{type:"button",onclick:t.fn},t.label)),this.notice.style.display="block";}}setReply(e){var i;if(this.replyTo=e,!this.replyBar)return;if(C(this.replyBar),!e){this.replyBar.style.display="none";return}let t=e.sender_type==="visitor"?this.o.t.you:e.sender_name||this.o.t.agent;this.replyBar.appendChild(a("span",{class:"rt"},`${this.o.t.replyingTo} ${t}: ${I(e,this.o.t)}`)),this.replyBar.appendChild(a("button",{type:"button",onclick:()=>this.setReply(null)},v("close",14))),this.replyBar.style.display="flex",(i=this.textarea)==null||i.focus();}startEdit(e){this.textarea&&(this.editing=e,this.setReply(null),this.textarea.value=e.body||"",this.autosize(),this.textarea.focus(),this.replyBar&&(C(this.replyBar),this.replyBar.appendChild(a("span",{class:"rt"},`${this.o.t.edit}: ${I(e,this.o.t)}`)),this.replyBar.appendChild(a("button",{type:"button",onclick:()=>this.cancelEdit()},v("close",14))),this.replyBar.style.display="flex"));}cancelEdit(){this.editing=null,this.textarea&&(this.textarea.value="",this.autosize()),this.replyBar&&(C(this.replyBar),this.replyBar.style.display="none");}submit(){if(!this.textarea)return;let e=this.textarea.value.trim();if(this.editing){let n=this.editing;this.cancelEdit(),e&&e!==n.body&&this.o.actions.saveEdit(n,e);return}if(!e&&this.files.length===0)return;let t=this.files,i=this.replyTo;this.files=[],this.renderChips(),this.setReply(null),this.textarea.value="",this.autosize(),this.stopTyping(),this.o.actions.send(e,t,i),this.textarea.focus();}addFiles(e){let t=this.o.maxMb*1024*1024;for(let i of e){if(i.size>t){this.flash(P(this.o.t.fileTooLarge,{mb:this.o.maxMb}));continue}if(i.type&&!Se.test(i.type)){this.flash(this.o.t.fileNotAllowed);continue}if(this.files.length>=5)break;this.files.push(i);}this.renderChips();}renderChips(){this.chips&&(C(this.chips),this.chips.style.display=this.files.length?"flex":"none",this.files.forEach((e,t)=>{let i=a("div",{class:"chip"},e.type.startsWith("image/")?a("img",{src:URL.createObjectURL(e),alt:""}):v("file",16),a("span",null,e.name),a("button",{type:"button",onclick:()=>{this.files.splice(t,1),this.renderChips();}},v("close",12)));this.chips.appendChild(i);}));}launcherMark(){let e=this.o.settings,t=de(e.logo_url);return e.launcher_icon==="logo"&&t?a("img",{class:"lg",src:t,alt:""}):e.launcher_icon==="chat"?v("chat",24):K(26)}brandAvatar(){let e=de(this.o.settings.logo_url);return e?a("img",{src:e,alt:""}):document.createTextNode(oe(this.o.appName))}restoreGeometry(){let e=_e();e&&(e.w&&(this.panel.style.width=`${e.w}px`),e.h&&(this.panel.style.height=`${e.h}px`),this.wrap.style.setProperty("--sb-dx",`${e.dx||0}px`),this.wrap.style.setProperty("--sb-dy",`${e.dy||0}px`));}saveGeometry(){ze({w:this.panel.offsetWidth,h:this.panel.offsetHeight,dx:parseFloat(this.wrap.style.getPropertyValue("--sb-dx"))||0,dy:parseFloat(this.wrap.style.getPropertyValue("--sb-dy"))||0});}enableMove(e){e.addEventListener("pointerdown",t=>{if(t.button!==0||le()||t.target.closest("button"))return;let i=t.clientX,n=t.clientY,r=parseFloat(this.wrap.style.getPropertyValue("--sb-dx"))||0,o=parseFloat(this.wrap.style.getPropertyValue("--sb-dy"))||0,l=this.wrap.classList.contains("left")?-1:1,d=false,h=p=>{let f=p.clientX-i,c=p.clientY-n;if(!d&&Math.abs(f)+Math.abs(c)<4)return;d=true,this.wrap.classList.add("moving");let u=Math.max(0,innerWidth-this.panel.offsetWidth-24),b=Math.max(0,innerHeight-this.panel.offsetHeight-24);this.wrap.style.setProperty("--sb-dx",`${H(r-f*l,0,u)}px`),this.wrap.style.setProperty("--sb-dy",`${H(o-c,0,b)}px`);},g=()=>{removeEventListener("pointermove",h),removeEventListener("pointerup",g),this.wrap.classList.remove("moving"),d&&this.saveGeometry();};addEventListener("pointermove",h),addEventListener("pointerup",g);});}enableResize(){this.grip.addEventListener("pointerdown",e=>{if(e.button!==0||le())return;e.preventDefault();let t=e.clientX,i=e.clientY,n=this.panel.offsetWidth,r=this.panel.offsetHeight,o=this.wrap.classList.contains("left")?-1:1;this.wrap.classList.add("sizing");let l=h=>{this.panel.style.width=`${H(n+(t-h.clientX)*o,320,innerWidth-40)}px`,this.panel.style.height=`${H(r+(i-h.clientY),380,innerHeight-40)}px`;},d=()=>{removeEventListener("pointermove",l),removeEventListener("pointerup",d),this.wrap.classList.remove("sizing"),this.saveGeometry();};addEventListener("pointermove",l),addEventListener("pointerup",d);});}flash(e){this.setBanner(e,true),setTimeout(()=>this.setBanner(null),3e3);}autosize(){let e=this.textarea;e&&(e.style.height="auto",e.style.height=`${Math.min(e.scrollHeight,120)}px`);}notifyTyping(){this.wasTyping||(this.wasTyping=true,this.o.actions.typing(true)),this.typingTimer&&clearTimeout(this.typingTimer),this.typingTimer=setTimeout(()=>this.stopTyping(),2500);}stopTyping(){this.typingTimer&&clearTimeout(this.typingTimer),this.typingTimer=null,this.wasTyping&&(this.wasTyping=false,this.o.actions.typing(false));}};function oe(s){return (s||"?").split(/\s+/).slice(0,2).map(e=>e[0]||"").join("").toUpperCase()}var pe="sb_geometry";function _e(){try{let s=localStorage.getItem(pe);if(!s)return null;let e=JSON.parse(s);return !e||e.w>innerWidth||e.h>innerHeight?null:e}catch(s){return null}}function ze(s){try{localStorage.setItem(pe,JSON.stringify(s));}catch(e){}}function H(s,e,t){return Math.min(Math.max(s,e),t)}function le(){return innerWidth<=640}function Ae(s){return s==="dark"?true:s!=="auto"||typeof matchMedia!="function"?false:matchMedia("(prefers-color-scheme: dark)").matches}function de(s){return typeof s=="string"&&/^(https:\/\/|data:image\/)/i.test(s)?s:null}function Re(s){return s&&/^(#[0-9a-f]{3,8}|rgba?\([\d\s.,%]+\)|hsla?\([\d\s.,%]+\))$/i.test(s)?s:"#111827"}var $=class{constructor(){this.original=null;this.timer=null;this.label="";}update(e,t){e>0&&document.hidden?(this.label=t(e),this.begin()):this.end();}begin(){if(this.timer)return;this.original=document.title;let e=false;this.timer=setInterval(()=>{if(!document.hidden)return this.end();e=!e,document.title=e?this.label:this.original||"";},1200);}end(){this.timer&&clearInterval(this.timer),this.timer=null,this.original!==null&&(document.title=this.original,this.original=null);}};var M=null;function Y(){try{let s=window.AudioContext||window.webkitAudioContext;if(!s)return;M||(M=new s),M.state==="suspended"&&M.resume();let e=M.currentTime,t=M.createGain();t.gain.setValueAtTime(1e-4,e),t.gain.exponentialRampToValueAtTime(.12,e+.02),t.gain.exponentialRampToValueAtTime(1e-4,e+.35),t.connect(M.destination);let i=M.createOscillator();i.type="sine",i.frequency.setValueAtTime(880,e),i.frequency.setValueAtTime(1175,e+.12),i.connect(t),i.start(e),i.stop(e+.36);}catch(s){}}var Ie="https://live.signalbird.io/api",k="/v1/sdk/chat/conversations",N=class{constructor(e){this.opts=e;this.title=new $;this.topic=null;this.ui=null;this.settings=null;this.appName="";this.started=false;this.destroyed=false;this.pendingSends=new Map;this.ratingMode=null;this.autoOpened=false;this.identity=null;this.lastTypingSent=0;this.pollCount=0;this.forceFull=false;this.socket=null;this.onVisibility=()=>{this.syncUnread(),!document.hidden&&this.store.isOpen&&this.store.conversation&&this.markRead();};this.baseUrl=(e.baseUrl||Ie).replace(/\/$/,""),this.store=new z(e.publicKey),this.api=new _(this.baseUrl,e.publicKey,e.chatKey,()=>this.store.secret,(...t)=>this.log(...t)),this.poller=new A(()=>this.tick()),this.identity=e.user&&(e.user.name||e.user.email||e.user.external_id)?e.user:null,this.locale=F(null,e.locale),this.t=j(this.locale),this.ready=this.start().catch(t=>this.log("start failed",t));}log(...e){this.opts.debug&&console.debug("[signalbird]",...e);}async start(){var g;let e=await this.api.post("/v1/sdk/bootstrap",{page_url:location.href,locale:this.opts.locale});if(!e.ok||!((g=e.data)!=null&&g.app)){this.log("bootstrap failed",e);return}if(this.destroyed)return;let{app:t,online:i,within_hours:n,visitor:r,conversation:o,topics:l,realtime:d}=e.data;if(!t.chat_enabled){this.log("chat disabled for app");return}this.settings=t.chat||{},this.appName=t.name||"",this.locale=F(this.settings.locale,this.opts.locale),this.t=j(this.locale),this.store.visitor&&!r&&this.store.clearVisitor(),r&&this.store.setVisitor({id:r.id,name:r.name,email:r.email}),this.store.online=!!i,this.store.withinHours=n!==false,o&&this.store.setConversation(o);let h=Number(this.settings.max_attachment_mb||t.max_attachment_mb||10);this.ui=new O({t:this.t,locale:this.locale,settings:this.settings,appName:this.appName,maxMb:h,topics:l||[],actions:{open:()=>this.open(),close:()=>this.close(),send:(p,f,c)=>{this.send(p,f,c);},typing:p=>{this.typing(p);},submitPrechat:(p,f,c)=>{this.submitPrechat(p,f,c);},skipPrechat:p=>{this.topic=p,this.enterChat();},rate:(p,f)=>{this.rate(p,f);},dismiss:()=>this.dismiss(),endChat:()=>this.endChat(),newChat:()=>this.newChat(),saveEdit:(p,f)=>{this.saveEdit(p,f);},reply:p=>{var f;return (f=this.ui)==null?void 0:f.setReply(p)},react:(p,f)=>{this.react(p,f);},edit:p=>{var f;return (f=this.ui)==null?void 0:f.startEdit(p)},remove:p=>{this.remove(p);},retry:p=>{this.retry(p);},openImage:p=>window.open(p,"_blank","noopener")}}),this.store.on("unread",()=>this.syncUnread()),this.store.on("messages",()=>this.render()),this.store.on("change",()=>this.render()),document.addEventListener("visibilitychange",this.onVisibility),this.ui.mount(),this.ui.setDismissed(this.store.dismissed),this.syncLauncher(),this.ui.setHeader(this.store.agent,this.store.online),this.applyBanner(),this.store.setUnread((r==null?void 0:r.unread)||(o==null?void 0:o.visitor_unread)||0),this.syncUnread(),this.started=true,this.poller.start(),d!=null&&d.enabled&&(this.socket=new R(d,(p,f)=>this.authorizeChannel(p,f),p=>this.onSocketEvent(p),p=>{this.log("socket",p?"connected":"disconnected"),this.poller.setLive(p),p&&this.poller.poke(0);},(...p)=>this.log(...p)),this.socket.connect(),this.subscribeVisitor()),this.opts.user&&this.identify(this.opts.user);}applyBanner(){!this.ui||!this.settings||this.ui.setBanner(this.store.withinHours?null:this.settings.offline_message||this.t.offlineMessage);}syncUnread(){var t;let e=this.store.isOpen&&!document.hidden?0:this.store.unread;(t=this.ui)==null||t.setUnread(this.store.unread),this.title.update(e,i=>P(this.t.unreadTitle,{n:i})),this.store.emit("public:unread",this.store.unread),this.syncLauncher();}syncLauncher(){var i;if(!this.ui)return;if(((i=this.settings)==null?void 0:i.launcher_mode)!=="manual"){this.ui.setLauncherHidden(false);return}let e=this.store.conversation,t=!!e&&e.status!=="closed";this.ui.setLauncherHidden(!(this.store.isOpen||t||this.store.unread>0));}dismiss(){var e;this.store.setDismissed(true),this.close(),(e=this.ui)==null||e.setDismissed(true);}open(){var e,t;this.store.dismissed&&(this.store.setDismissed(false),(e=this.ui)==null||e.setDismissed(false)),!(!this.ui||this.store.isOpen)&&(((t=this.store.conversation)==null?void 0:t.status)==="closed"&&(this.store.setConversation(null),this.ratingMode=null),this.store.isOpen=true,this.ui.setOpen(true),this.syncLauncher(),this.poller.setOpen(true),this.decideView(),this.store.emit("public:open"),this.store.conversation?this.loadConversation():this.store.setUnread(0),this.syncUnread());}close(){if(!this.ui||!this.store.isOpen)return;let e=this.store.conversation;if(e&&e.status==="resolved"&&!this.store.wasRated(e.id)&&this.ui.currentView==="chat"&&this.store.messages.some(t=>t.sender_type==="agent")){this.ratingMode="resolved",this.ui.setEndVisible(false),this.ui.showRating();return}this.store.isOpen=false,this.ui.setOpen(false),this.poller.setOpen(false),this.typing(false),this.store.emit("public:close"),this.syncUnread(),this.syncLauncher();}toggle(){this.store.isOpen?this.close():this.open();}isOpen(){return this.store.isOpen}on(e,t){this.store.on(`public:${e}`,t);}off(e,t){this.store.off(`public:${e}`,t);}async identify(e){var r;if(await this.ready,this.destroyed)return;this.identity={...this.identity||{},...e},((r=this.ui)==null?void 0:r.currentView)==="prechat"&&this.enterChat();let[t,...i]=(e.name||"").trim().split(/\s+/),n={external_id:e.external_id,email:e.email,phone:e.phone,first_name:t||void 0,last_name:i.join(" ")||void 0,attributes:e.attributes};e.external_id&&this.check(await this.api.post("/v1/sdk/identify",n)),await this.session({name:e.name,email:e.email,external_id:e.external_id});}async pushRegister(e){return await this.ready,this.api.post("/v1/sdk/devices",{provider:e.platform==="ios"?"apns":"fcm",locale:this.locale,...e})}destroy(){var e,t;this.destroyed=true,(e=this.socket)==null||e.close(),this.socket=null,this.poller.stop(),this.title.end(),document.removeEventListener("visibilitychange",this.onVisibility),(t=this.ui)==null||t.unmount(),this.ui=null;}decideView(){var r,o;if(!this.ui||!this.settings)return;let e=this.settings.prechat,t=this.store.visitor;!!!((r=this.identity)!=null&&r.name||(o=this.identity)!=null&&o.email||t!=null&&t.name||t!=null&&t.email)&&!this.store.conversation&&e&&(e.name||e.email)?this.ui.showPrechat({}):this.enterChat();}enterChat(){var e;this.ui&&(this.ratingMode=null,this.ui.showChat(),this.ui.setEndVisible(((e=this.store.conversation)==null?void 0:e.status)==="open"),this.render());}render(){var t,i;if(!this.ui||this.ui.currentView!=="chat")return;let e=this.store.conversation;this.ui.render({messages:this.store.messages,greeting:((t=this.settings)==null?void 0:t.greeting)||this.t.greeting,agentName:((i=this.store.agent)==null?void 0:i.name)||this.t.agent,find:n=>this.store.find(n)}),this.ui.setEndVisible((e==null?void 0:e.status)==="open"),e&&e.status!=="open"?this.ui.setNotice(e.status==="resolved"?this.t.resolved:this.t.closed,{label:this.t.newChat,fn:()=>this.newChat()}):this.ui.setNotice(null);}async submitPrechat(e,t,i){var r;this.topic=i,await this.session({name:e||void 0,email:t||void 0})?this.enterChat():(r=this.ui)==null||r.setBanner(this.t.unavailable,true);}newChat(){this.ratingMode=null,this.store.setConversation(null),this.enterChat(),this.store.isOpen||this.open();}endChat(){!this.ui||!this.store.conversation||(this.ratingMode="end",this.ui.setEndVisible(false),this.ui.showRating());}async rate(e,t){var r;let i=this.store.conversation,n=this.ratingMode;if(this.ratingMode=null,!(!i||!this.ui)){if(e>0){let o=await this.api.post(`${k}/${i.id}/rate`,{rating:e,comment:t||void 0});this.check(o),this.store.markRated(i.id);}if(n==="end"){let o=await this.api.post(`${k}/${i.id}/close`);this.check(o),((r=this.store.conversation)==null?void 0:r.id)===i.id&&this.store.setConversation({...i,status:"closed"}),this.ui.showThanks(this.reviewFor(e));return}e===0&&this.store.markRated(i.id),this.enterChat(),this.close();}}reviewFor(e){var n,r,o,l;let t=(((n=this.settings)==null?void 0:n.review_url)||"").trim(),i=Number((o=(r=this.settings)==null?void 0:r.review_min_rating)!=null?o:3);return !t||!/^https?:\/\//i.test(t)?null:e>0&&e>=i?{url:t,label:((l=this.settings)==null?void 0:l.review_label)||null}:null}async session(e={}){var n;let t=this.identity?{name:this.identity.name,email:this.identity.email,external_id:this.identity.external_id}:{},i=await this.api.post("/v1/sdk/chat/session",{...t,...e,locale:this.locale,page_url:location.href,user_agent:navigator.userAgent});if(i.ok&&((n=i.data)!=null&&n.visitor)){let r=i.data.visitor;return !r.secret&&!this.store.visitor?(this.log("session returned no secret"),false):(this.store.setVisitor(r),this.subscribeVisitor(),true)}return !i.ok&&i.code==="VISITOR_INVALID"&&this.store.visitor?(this.store.clearVisitor(),this.session(e)):(this.check(i),false)}subscribeVisitor(){var t;let e=(t=this.store.visitor)==null?void 0:t.id;this.socket&&e&&this.socket.subscribe(`visitor.${e}`);}async authorizeChannel(e,t){var n;let i=await this.api.post("/v1/sdk/chat/socket/auth",{socket_id:e,channel:t});return i.ok&&((n=i.data)!=null&&n.auth)?{auth:i.data.auth,at:i.data.at}:null}onSocketEvent(e){var t,i;if(e.name==="chat.typing"){e.data.who==="agent"&&(this.store.agentTyping=e.data.active===true,(i=this.ui)==null||i.setTyping(this.store.agentTyping,((t=this.store.agent)==null?void 0:t.name)||this.t.agent));return}e.data.updated===true&&(this.forceFull=true),this.poller.poke(0);}async loadConversation(){let e=this.store.conversation;if(!e)return;let t=await this.api.get(`${k}/${e.id}`,{limit:50});this.applyPayload(t,true)&&this.store.isOpen&&!document.hidden&&this.store.setUnread(0);}applyPayload(e,t){var n,r,o,l;if(!e.ok)return this.check(e),e.status===404&&this.store.setConversation(null),-1;let i=e.data;if(i.conversation){let d=(n=this.store.conversation)==null?void 0:n.status;this.store.conversation=i.conversation,d!==i.conversation.status&&this.store.emit("change");}return i.agent!==void 0&&(this.store.agent=i.agent||null),this.store.agentTyping=!!i.agent_typing,(r=this.ui)==null||r.setHeader(this.store.agent,this.store.online),(l=this.ui)==null||l.setTyping(this.store.agentTyping,((o=this.store.agent)==null?void 0:o.name)||this.t.agent),this.store.mergeMessages(i.messages||[],t)}async tick(){var d,h,g,p;if(!this.started||!this.store.visitor)return false;this.pollCount++;let e=this.store.conversation;if(this.store.isOpen&&e){let f=this.pollCount%5===0||this.forceFull;this.forceFull=false;let c=f?void 0:this.store.lastServerMessageId||void 0,u=await this.api.get(`${k}/${e.id}`,c?{after:c}:{limit:50}),b=this.applyPayload(u,!c);return b>0&&(document.hidden?(this.store.setUnread(this.store.unread+b),(d=this.settings)!=null&&d.sound&&Y()):this.markRead()),b>0}if(this.store.isOpen&&!e&&this.pollCount%10!==0)return false;let t=await this.api.get(k);if(!t.ok)return this.check(t),false;let i=t.data,n=Array.isArray(i)?i:(i==null?void 0:i.conversations)||(i==null?void 0:i.data)||[],r=n.find(f=>f.status==="open")||null,o=n.reduce((f,c)=>f+(c.visitor_unread||0),0),l=o>this.store.unread;return r&&r.id!==((h=this.store.conversation)==null?void 0:h.id)&&(this.store.setConversation(r),this.store.isOpen&&this.loadConversation()),(!this.store.isOpen||document.hidden)&&(this.store.setUnread(o),l&&((g=this.settings)!=null&&g.sound&&Y(),(p=this.ui)==null||p.attention(),!this.autoOpened&&!document.hidden&&(this.autoOpened=true,this.open()))),l}async markRead(){let e=this.store.conversation,t=this.store.lastServerMessageId;!e||!t||(this.store.setUnread(0),await this.api.post(`${k}/${e.id}/read`,{last_message_id:t},true));}async send(e,t,i,n=te()){var l;let r={id:`local_${n}`,client_id:n,sender_type:"visitor",type:t.length?t[0].type.startsWith("image/")?"image":"file":"text",body:e||null,attachments:null,reply_to_id:(i==null?void 0:i.id)||null,created_at:new Date().toISOString(),_pending:true,_files:t};this.pendingSends.set(n,{text:e,files:t,replyTo:(i==null?void 0:i.id)||null}),this.store.upsertMessage(r);let o=()=>{let d=this.store.find(r.id);d&&this.store.upsertMessage({...d,_pending:false,_failed:true});};try{if(!this.store.visitor&&!await this.session())return o();let d=this.store.conversation,h=!d||d.status!=="open";if(h&&t.length===0){let c=await this.api.post(k,{body:e,page_url:location.href,client_id:n,...this.topic?{topic:this.topic}:{}});if(!c.ok)return this.sendFailed(c,o);this.store.setConversation(c.data.conversation),this.store.mergeMessages(c.data.messages||[]),this.reconcile(r,c.data.messages),this.pendingSends.delete(n),this.poller.poke(3e3);return}if(h){let c=await this.api.post(k,{page_url:location.href,...this.topic?{topic:this.topic}:{}});if(!c.ok)return this.sendFailed(c,o);this.store.setConversation(c.data.conversation),this.store.mergeMessages(c.data.messages||[]),d=c.data.conversation;}if(!d)return o();let g=[];for(let c of t){let u=await this.api.upload(`${k}/${d.id}/attachments`,c);if(!u.ok)return this.sendFailed(u,o);g.push(u.data);}let p=await this.api.post(`${k}/${d.id}/messages`,{body:e||void 0,attachments:g.length?g:void 0,reply_to_id:(i==null?void 0:i.id)||void 0,client_id:n});if(!p.ok)return this.sendFailed(p,o);let f=((l=p.data)==null?void 0:l.message)||p.data;this.reconcile(r,[f]),this.pendingSends.delete(n),this.poller.poke(3e3);}catch(d){this.log("send error",d),o();}}reconcile(e,t){let i=(t||[]).find(n=>n.client_id===e.client_id);i?this.store.mergeMessages([{...i,client_id:e.client_id}]):t&&t.length&&(this.store.removeMessage(e.id),this.store.mergeMessages(t));}sendFailed(e,t){var i;this.check(e),(e.code==="CHAT_UNAVAILABLE"||e.status===503)&&((i=this.ui)==null||i.setBanner(this.t.unavailable,true)),t();}async retry(e){let t=e.client_id?this.pendingSends.get(e.client_id):null;this.store.removeMessage(e.id),!(!t||!e.client_id)&&await this.send(t.text,t.files,this.store.find(t.replyTo)||null,e.client_id);}async typing(e){let t=this.store.conversation;if(!t||t.status!=="open"||!this.store.visitor)return;let i=Date.now();e&&i-this.lastTypingSent<4e3||(this.lastTypingSent=e?i:0,await this.api.post(`${k}/${t.id}/typing`,{is_typing:e},true));}async react(e,t){var h,g,p,f;let i=this.store.conversation;if(!i)return;let n={...e.reactions||{}},r=[...n[t]||[]],o=r.indexOf("visitor");o>=0?r.splice(o,1):r.push("visitor"),n[t]=r,this.store.upsertMessage({...e,reactions:n});let l=await this.api.post(`${k}/${i.id}/messages/${e.id}/reactions`,{emoji:t});if(!l.ok){this.check(l),this.store.upsertMessage({...e});return}let d=(f=(g=(h=l.data)==null?void 0:h.message)==null?void 0:g.reactions)!=null?f:(p=l.data)==null?void 0:p.reactions;d&&this.store.upsertMessage({...e,reactions:d});}async saveEdit(e,t){var o;let i=this.store.conversation;if(!i)return;this.store.upsertMessage({...e,body:t,edited_at:new Date().toISOString()});let n=await this.api.patch(`${k}/${i.id}/messages/${e.id}`,{body:t});if(!n.ok){this.check(n),this.store.upsertMessage({...e});return}let r=((o=n.data)==null?void 0:o.message)||n.data;r&&r.id&&this.store.upsertMessage(r);}async remove(e){let t=this.store.conversation;if(!t)return;this.store.upsertMessage({...e,deleted_at:new Date().toISOString()});let i=await this.api.delete(`${k}/${t.id}/messages/${e.id}`);i.ok||(this.check(i),this.store.upsertMessage({...e}));}check(e){e.ok||(e.code==="VISITOR_INVALID"||e.status===401&&this.store.visitor)&&(this.store.clearVisitor(),this.store.isOpen&&this.decideView());}};var Pe={tr:{loading:"Y\xFCkleniyor\u2026",failed:"Ekran y\xFCklenemedi.",expired:"Bu ba\u011Flant\u0131n\u0131n s\xFCresi doldu.",retry:"Yeniden dene"},en:{loading:"Loading\u2026",failed:"The screen could not be loaded.",expired:"This link has expired.",retry:"Try again"}};function He(s){if(s==="light"||s==="dark")return s;if(typeof document!="undefined"){let e=document.documentElement;if(e.classList.contains("dark")||e.dataset.theme==="dark")return "dark";if(e.classList.contains("light")||e.dataset.theme==="light")return "light"}return typeof window!="undefined"&&typeof window.matchMedia=="function"&&window.matchMedia("(prefers-color-scheme: dark)").matches?"dark":"light"}function Oe(s){if(typeof s=="string")return s||null;if(s&&typeof s=="object"){let e=s;if(typeof e.url=="string")return e.url;if(e.data&&typeof e.data.url=="string")return e.data.url}return null}function ce(s){var f,c;let e=Pe[(f=s.language)!=null?f:"tr"],t=new Map,i=null,n=null,r=null,o=(c=s.theme)!=null?c:"auto",l=false,d=(u,b)=>{var x;(x=t.get(u))==null||x.forEach(w=>{try{w(b);}catch(E){console.warn("[signalbird]",E);}});},h=()=>{r&&(window.removeEventListener("message",r),r=null),n=null,i&&(i.textContent="");},g=(u,b)=>{var E;if(!i)return;i.textContent="";let x=document.createElement("div");x.setAttribute("data-signalbird-status",""),x.style.cssText=`display:flex;align-items:center;justify-content:center;gap:12px;min-height:${(E=s.minHeight)!=null?E:220}px;font:13px/1.5 system-ui,-apple-system,sans-serif;color:#6b7280;text-align:center;padding:24px;`;let w=document.createElement("span");if(w.textContent=u,x.appendChild(w),b){let y=document.createElement("button");y.type="button",y.textContent=e.retry,y.style.cssText="border:1px solid currentColor;border-radius:8px;background:transparent;color:inherit;padding:4px 10px;font:inherit;cursor:pointer;",y.addEventListener("click",()=>{p();}),x.appendChild(y);}i.appendChild(x);},p=async()=>{var E;if(!i||l)return;h(),g(e.loading,false);let u=He(o),b=null;try{s.url?(b=s.url,s={...s,url:void 0}):s.mint&&(b=Oe(await s.mint({module:s.module,theme:u,locale:s.locale})));}catch(y){d("error",y),g(y instanceof Error?y.message:e.failed,true);return}if(!b){d("error",new Error("EMBED_URL_MISSING")),g(e.expired,!!s.mint);return}let x=b;try{let y=new URL(b);y.searchParams.set("theme",u),s.locale&&y.searchParams.set("locale",s.locale),s.accent&&y.searchParams.set("accent",s.accent.replace(/^#/,"")),x=y.toString();}catch(y){}let w=document.createElement("iframe");w.src=x,w.title="Signalbird",w.style.cssText="width:100%;border:0;display:block;",w.style.height=`${typeof s.height=="number"?s.height:(E=s.minHeight)!=null?E:640}px`,w.setAttribute("allow","clipboard-write; fullscreen; autoplay"),w.setAttribute("sandbox","allow-same-origin allow-scripts allow-forms allow-popups allow-downloads"),w.setAttribute("referrerpolicy","strict-origin-when-cross-origin"),w.setAttribute("loading","lazy"),s.className&&(w.className=s.className),i.textContent="",i.appendChild(w),n=w,r=y=>{var W,G;if(!n||y.source!==n.contentWindow)return;let L=y.data;if(!(!L||typeof L.type!="string")){if(L.type==="signalbird:ready"){d("ready",L.module);return}if(L.type==="signalbird:height"&&typeof L.px=="number"&&(d("height",L.px),((W=s.height)!=null?W:"auto")==="auto")){let ue=Math.max(L.px,(G=s.minHeight)!=null?G:220);n.style.height=`${ue}px`;}}},window.addEventListener("message",r);};return {async mount(u){let b=typeof u=="string"?document.querySelector(u):u;if(!(b instanceof HTMLElement))throw new Error("Signalbird: g\xF6mme kab\u0131 bulunamad\u0131 \u2014 "+String(u));i=b,l=false,await p();},refresh:()=>p(),async setTheme(u){o=u,await p();},destroy(){l=true,h(),t.clear(),i=null;},on(u,b){t.has(u)||t.set(u,new Set),t.get(u).add(b);},off(u,b){var x;(x=t.get(u))==null||x.delete(b);}}}var ut="2.0.1",m=null,B=[],S=null;function T(s,e){try{return s()}catch(t){try{console.warn("[signalbird]",t);}catch(i){}return e}}function he(s){s.catch(()=>{});}function $e(s){T(()=>{if(!s||!s.publicKey){console.warn("[signalbird] init: publicKey zorunlu");return}if(!(typeof document=="undefined"||typeof window=="undefined")){m&&m.destroy(),m=new N(s);for(let{event:e,fn:t}of B)m.on(e,t);if(S){let e=S;S=null,he(m.identify(e));}}},void 0);}function gt(s){T(()=>{if(s){if(!m){S={...S||{},...s};return}he(m.identify(s));}},void 0);}var ft={open(){T(()=>m==null?void 0:m.open(),void 0);},close(){T(()=>m==null?void 0:m.close(),void 0);},toggle(){T(()=>m==null?void 0:m.toggle(),void 0);},isOpen(){return T(()=>!!(m!=null&&m.isOpen()),false)},on(s,e){T(()=>{typeof e=="function"&&(B.push({event:s,fn:e}),m==null||m.on(s,e));},void 0);},off(s,e){T(()=>{let t=B.findIndex(i=>i.event===s&&i.fn===e);t>=0&&B.splice(t,1),m==null||m.off(s,e);},void 0);}},mt={register(s){return T(()=>m?m.pushRegister(s).catch(e=>({ok:!1,status:0,code:"NETWORK_ERROR",message:String(e)})):Promise.resolve({ok:!1,status:0,code:"NOT_INITIALIZED",message:"Signalbird.init \xE7a\u011Fr\u0131lmad\u0131"}),Promise.resolve({ok:false,status:0,code:"WIDGET_ERROR",message:"widget error"}))}},bt=ce;function vt(){T(()=>{m==null||m.destroy(),m=null;},void 0);}T(()=>{if(typeof document=="undefined")return;let s=document.currentScript||document.querySelector('script[data-key][src*="signalbird"]'),e=s==null?void 0:s.dataset;if(!e||!e.key)return;let t=()=>$e({publicKey:e.key,chatKey:e.channel||void 0,baseUrl:e.baseUrl||void 0,locale:e.locale||void 0,debug:e.debug==="true"||e.debug==="1"});document.body?t():document.addEventListener("DOMContentLoaded",t,{once:!0});},void 0);
|
|
277
|
+
`;function a(s,e,...t){let i=document.createElement(s);if(e)for(let n in e){let r=e[n];r==null||r===false||(n==="class"?i.className=String(r):n==="style"?i.setAttribute("style",String(r)):n.startsWith("on")&&typeof r=="function"?i.addEventListener(n.slice(2).toLowerCase(),r):n==="html"?i.innerHTML=String(r):n in i&&n!=="list"&&n!=="form"?i[n]=r:i.setAttribute(n,String(r)));}return be(i,t),i}function be(s,e){for(let t of e)t==null||t===false||s.appendChild(typeof t=="object"?t:document.createTextNode(String(t)));}function C(s){for(;s.firstChild;)s.removeChild(s.firstChild);}function v(s,e=18){let t=document.createElementNS("http://www.w3.org/2000/svg","svg");return t.setAttribute("viewBox","0 0 24 24"),t.setAttribute("width",String(e)),t.setAttribute("height",String(e)),t.setAttribute("fill","none"),t.setAttribute("stroke","currentColor"),t.setAttribute("stroke-width","2"),t.setAttribute("stroke-linecap","round"),t.setAttribute("stroke-linejoin","round"),t.innerHTML=ve[s],t}function K(s=26){let e=document.createElementNS("http://www.w3.org/2000/svg","svg");return e.setAttribute("viewBox","10 2 28 38"),e.setAttribute("width",String(s)),e.setAttribute("height",String(s)),e.setAttribute("fill","none"),e.setAttribute("stroke","currentColor"),e.setAttribute("stroke-width","2"),e.setAttribute("stroke-linejoin","round"),e.setAttribute("aria-hidden","true"),e.innerHTML='<path d="M16 16 L30 16 L33 18 L24 33 L15 18 Z" fill="currentColor" fill-opacity=".18" stroke="none"/><path d="M23 4 L31 9 L23 14 L16 9 Z" fill="currentColor" fill-opacity=".28" stroke="none"/><path d="M30 16 L33 18 L36 27 L34 34 L41 32 L44 38 L31 37 L24 37 L17 35 L13 27 L15 18 L16 16"/><path d="M16 16 L16 9 L23 4 L31 9 L30 16"/><path d="M21.4 12.4 L23.2 18.6 L25 12.4 Z" fill="currentColor" fill-opacity=".35"/><circle cx="28.4" cy="11.4" r="1.6" fill="currentColor" stroke="none"/>',e}var ve={chat:'<path d="M21 11.5a8.4 8.4 0 0 1-.9 3.8 8.5 8.5 0 0 1-7.6 4.7 8.4 8.4 0 0 1-3.8-.9L3 21l1.9-5.7a8.4 8.4 0 0 1-.9-3.8 8.5 8.5 0 0 1 4.7-7.6 8.4 8.4 0 0 1 3.8-.9h.5a8.5 8.5 0 0 1 8 8v.5z"/>',close:'<path d="M18 6 6 18M6 6l12 12"/>',send:'<path d="m22 2-7 20-4-9-9-4 20-7z"/><path d="M22 2 11 13"/>',clip:'<path d="m21.4 11.05-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"/>',file:'<path d="M14.5 2H6a2 2 0 0 0-2 2v16a2 2 0 0 0 2 2h12a2 2 0 0 0 2-2V7.5L14.5 2z"/><path d="M14 2v6h6"/>',check:'<path d="M20 6 9 17l-5-5"/>',checks:'<path d="M18 6 7 17l-4-4"/><path d="m22 10-7.5 7.5L13 16"/>',reply:'<path d="M9 17H5a2 2 0 0 1-2-2V9"/><path d="m3 9 4-4"/><path d="m3 9 4 4"/><path d="M9 17h6a6 6 0 0 0 0-12h-2"/>',more:'<circle cx="12" cy="12" r="1"/><circle cx="19" cy="12" r="1"/><circle cx="5" cy="12" r="1"/>',star:'<path d="m12 2 3.09 6.26L22 9.27l-5 4.87 1.18 6.88L12 17.77l-6.18 3.25L7 14.14 2 9.27l6.91-1.01L12 2z"/>',chevron:'<path d="m6 9 6 6 6-6"/>',smile:'<circle cx="12" cy="12" r="10"/><path d="M8 14s1.5 2 4 2 4-2 4-2"/><path d="M9 9h.01M15 9h.01"/>',done:'<path d="M22 11.08V12a10 10 0 1 1-5.93-9.14"/><path d="m22 4-10 10-3-3"/>'};function ee(s){return s<1024?`${s} B`:s<1024*1024?`${(s/1024).toFixed(0)} KB`:`${(s/1024/1024).toFixed(1)} MB`}function te(){return typeof crypto!="undefined"&&"randomUUID"in crypto?crypto.randomUUID():"xxxxxxxx-xxxx-4xxx-yxxx-xxxxxxxxxxxx".replace(/[xy]/g,s=>{let e=Math.random()*16|0;return (s==="x"?e:e&3|8).toString(16)})}var ie=["\u{1F44D}","\u2764\uFE0F","\u{1F602}","\u{1F62E}","\u{1F622}","\u{1F64F}"],ye=900*1e3;function ae(s,e){let t=s.scrollHeight-s.scrollTop-s.clientHeight<40,i=s.scrollHeight;C(s),e.greeting&&e.messages.length===0&&s.appendChild(a("div",{class:"gr"},e.greeting));let n="",r=null;for(let o of e.messages){let l=Ce(o.created_at);l!==n&&(s.appendChild(a("div",{class:"day"},Te(o.created_at,e))),n=l,r=null),s.appendChild(xe(o,e,r)),r=o;}(t||i===0)&&(s.scrollTop=s.scrollHeight);}function U(s){s.scrollTop=s.scrollHeight;}function xe(s,e,t){var f;let i=s.sender_type==="visitor"?"v":s.sender_type==="system"?"s":"a",n=t&&t.sender_type!==s.sender_type,r=a("div",{class:`row ${i}${n?" gap":""}${s._pending?" pend":""}${s._failed?" fail":""}`,"data-id":s.id}),o=a("div",{class:`bb${s.deleted_at?" del":""}`});if(s.deleted_at)return o.textContent=e.t.deleted,r.appendChild(o),r;if(s.reply_to_id){let c=e.find(s.reply_to_id),u=c?c.sender_type==="visitor"?e.t.you:c.sender_name||e.agentName:"";o.appendChild(a("span",{class:"q"},u?`${u}: `:"",c?I(c,e.t):"\u2026"));}let l=s.attachments||[],d=l.filter(c=>ne(c.mime)),h=l.filter(c=>!ne(c.mime));if(s._files&&s._files.length){let c=a("div",{class:"imgs"});for(let u of s._files)u.type.startsWith("image/")?c.appendChild(a("img",{src:URL.createObjectURL(u),alt:u.name})):o.appendChild(se({name:u.name,url:"",mime:u.type,size:u.size},e));c.childNodes.length&&o.appendChild(c);}if(d.length){let c=a("div",{class:"imgs"});for(let u of d)c.appendChild(a("img",{src:u.url,alt:u.name,loading:"lazy",onclick:()=>e.actions.openImage(u.url)}));o.appendChild(c);}for(let c of h)o.appendChild(se(c,e));let g=(i==="v"?null:(f=s.translation)==null?void 0:f.body)||s.body;g&&o.appendChild(document.createTextNode(g)),s._failed&&(o.appendChild(a("div",{style:"font-size:11px;margin-top:4px"},e.t.failed)),o.addEventListener("click",()=>e.actions.retry(s))),r.appendChild(o);let p=s.reactions&&Object.keys(s.reactions).length?s.reactions:null;if(p){let c=a("div",{class:"rx"});for(let u in p){let b=p[u]||[];if(!b.length)continue;let x=b.includes("visitor");c.appendChild(a("button",{class:x?"me":"",type:"button",onclick:()=>e.actions.react(s,u)},`${u} ${b.length}`));}c.childNodes.length&&r.appendChild(c);}if(i!=="s"){let c=a("div",{class:"mt"},Le(s.created_at,e.locale));if(s.edited_at&&c.appendChild(a("span",{class:"ed"},`\xB7 ${e.t.edited}`)),i==="v"&&!s._failed){let u=a("span",{class:`tk${s.read_at?" rd":""}`});u.appendChild(s._pending?v("check",12):s.read_at||s.delivered_at?v("checks",13):v("check",12)),s._pending&&(u.style.opacity=".4"),c.appendChild(u);}r.appendChild(c);}return i!=="s"&&!s._pending&&!s._failed&&(r.appendChild(we(s,e,r)),ke(r)),r}function we(s,e,t){let i=a("div",{class:"ac"});for(let l of ie.slice(0,3))i.appendChild(a("button",{type:"button",title:e.t.react,onclick:()=>e.actions.react(s,l)},l));i.appendChild(a("button",{type:"button",title:e.t.reply,onclick:()=>e.actions.reply(s)},v("reply",15)));let n=a("div",{class:"menu"});for(let l of ie.slice(3))n.appendChild(a("button",{type:"button",onclick:()=>{n.classList.remove("show"),e.actions.react(s,l);}},`${l} ${e.t.react}`));return s.sender_type==="visitor"&&Date.now()-Date.parse(s.created_at)<ye&&(n.appendChild(a("button",{type:"button",onclick:()=>{n.classList.remove("show"),e.actions.edit(s);}},e.t.edit)),n.appendChild(a("button",{type:"button",class:"dg",onclick:()=>{n.classList.remove("show"),e.actions.remove(s);}},e.t.delete))),i.appendChild(a("button",{type:"button",title:e.t.react,onclick:l=>{l.stopPropagation(),n.classList.toggle("show"),n.style.top=`${t.offsetHeight+4}px`;}},v("more",15))),t.appendChild(n),document.addEventListener("click",()=>n.classList.remove("show"),{once:true,capture:true}),i}function ke(s){let e=null,t=()=>{e=setTimeout(()=>{s.classList.add("acts");let n=r=>{s.contains(r.target)||(s.classList.remove("acts"),document.removeEventListener("touchstart",n,true));};document.addEventListener("touchstart",n,true);},450);},i=()=>e&&clearTimeout(e);s.addEventListener("touchstart",t,{passive:true}),s.addEventListener("touchend",i),s.addEventListener("touchmove",i,{passive:true});}function se(s,e){return a("a",{class:"fr",href:s.url||void 0,target:"_blank",rel:"noopener"},v("file",18),a("span",{class:"fn"},s.name||e.t.attachment),a("span",{class:"fs"},ee(s.size||0)))}function I(s,e){var n,r;if(s.deleted_at)return e.deleted;let t=(s.sender_type==="visitor"?null:(n=s.translation)==null?void 0:n.body)||s.body;if(t)return t.length>90?t.slice(0,90)+"\u2026":t;let i=(r=s.attachments)==null?void 0:r[0];return i?`\u{1F4CE} ${i.name}`:"\u2026"}function ne(s){return !!s&&s.startsWith("image/")}function Ce(s){let e=new Date(s);return `${e.getFullYear()}-${e.getMonth()}-${e.getDate()}`}function Te(s,e){let t=new Date(s),i=new Date,n=Math.round((re(i)-re(t))/864e5);if(n===0)return e.t.today;if(n===1)return e.t.yesterday;try{return new Intl.DateTimeFormat(e.locale,{day:"numeric",month:"long",year:t.getFullYear()!==i.getFullYear()?"numeric":void 0}).format(t)}catch(r){return t.toLocaleDateString()}}function re(s){return new Date(s.getFullYear(),s.getMonth(),s.getDate()).getTime()}function Le(s,e){let t=new Date(s);try{return new Intl.DateTimeFormat(e,{hour:"2-digit",minute:"2-digit"}).format(t)}catch(i){return t.toLocaleTimeString()}}var Ee={launcher:"Sohbet",title:"Sohbet",online:"\xC7evrimi\xE7i",offline:"Genelde birka\xE7 dakika i\xE7inde yan\u0131tl\u0131yoruz",greeting:"Merhaba! Size nas\u0131l yard\u0131mc\u0131 olabiliriz?",offlineMessage:"\u015Eu an \xE7evrimd\u0131\u015F\u0131y\u0131z. Mesaj\u0131n\u0131z\u0131 b\u0131rak\u0131n, en k\u0131sa s\xFCrede d\xF6nelim.",prechatTitle:"Ba\u015Flamadan \xF6nce",prechatHint:"Size geri d\xF6nebilmemiz i\xE7in bilgilerinizi b\u0131rak\u0131n.",topicLabel:"Konu",topicPlaceholder:"Konu se\xE7in (iste\u011Fe ba\u011Fl\u0131)",name:"Ad\u0131n\u0131z",email:"E-posta",start:"Sohbete ba\u015Fla",skip:"Atla",placeholder:"Mesaj\u0131n\u0131z\u0131 yaz\u0131n\u2026",send:"G\xF6nder",attach:"Dosya ekle",typing:"yaz\u0131yor\u2026",today:"Bug\xFCn",yesterday:"D\xFCn",reply:"Yan\u0131tla",react:"Tepki ver",edit:"D\xFCzenle",delete:"Sil",deleted:"Bu mesaj silindi",edited:"d\xFCzenlendi",save:"Kaydet",cancel:"Vazge\xE7",you:"Siz",agent:"Destek",system:"Sistem",endChat:"Sohbeti bitir",newChat:"Yeni sohbet",resolved:"Bu sohbet \xE7\xF6z\xFCld\xFC olarak i\u015Faretlendi.",closed:"Bu sohbet kapat\u0131ld\u0131.",rateTitle:"Bu sohbeti nas\u0131l buldunuz?",rateComment:"Eklemek istedi\u011Finiz bir \u015Fey var m\u0131? (iste\u011Fe ba\u011Fl\u0131)",rateSend:"G\xF6nder",rateThanks:"Te\u015Fekk\xFCrler! Geri bildiriminiz al\u0131nd\u0131.",reviewIntro:"Yard\u0131mc\u0131 olabildiysek bizi yorumlar m\u0131s\u0131n\u0131z?",reviewCta:"De\u011Ferlendir",failed:"G\xF6nderilemedi \u2014 tekrar dene",fileTooLarge:"Dosya \xE7ok b\xFCy\xFCk (en fazla {mb} MB)",fileNotAllowed:"Yaln\u0131zca foto\u011Fraf y\xFCkleyebilirsiniz",unavailable:"Sohbet \u015Fu an kullan\u0131lam\u0131yor. L\xFCtfen daha sonra tekrar deneyin.",close:"Kapat",dismiss:"Sohbet balonunu gizle",minimize:"K\xFC\xE7\xFClt",unreadTitle:"({n}) Yeni mesaj",dropHere:"Dosyay\u0131 buraya b\u0131rak\u0131n",replyingTo:"Yan\u0131tlan\u0131yor",attachment:"Ek",poweredBy:"Signalbird ile",resize:"Boyutland\u0131r"},Me={launcher:"Chat",title:"Chat",online:"Online",offline:"We usually reply within a few minutes",greeting:"Hi there! How can we help you?",offlineMessage:"We're offline right now. Leave a message and we'll get back to you.",prechatTitle:"Before we start",prechatHint:"Leave your details so we can get back to you.",topicLabel:"Topic",topicPlaceholder:"Pick a topic (optional)",name:"Your name",email:"Email",start:"Start chat",skip:"Skip",placeholder:"Type your message\u2026",send:"Send",attach:"Attach file",typing:"is typing\u2026",today:"Today",yesterday:"Yesterday",reply:"Reply",react:"React",edit:"Edit",delete:"Delete",deleted:"This message was deleted",edited:"edited",save:"Save",cancel:"Cancel",you:"You",agent:"Support",system:"System",endChat:"End chat",newChat:"New chat",resolved:"This conversation was marked as resolved.",closed:"This conversation was closed.",rateTitle:"How was this conversation?",rateComment:"Anything to add? (optional)",rateSend:"Send",rateThanks:"Thanks! Your feedback was received.",reviewIntro:"If we were helpful, would you leave us a review?",reviewCta:"Leave a review",failed:"Not sent \u2014 tap to retry",fileTooLarge:"File is too large (max {mb} MB)",fileNotAllowed:"Only photos can be uploaded",unavailable:"Chat is unavailable right now. Please try again later.",close:"Close",dismiss:"Hide the chat bubble",minimize:"Minimize",unreadTitle:"({n}) New message",dropHere:"Drop the file here",replyingTo:"Replying to",attachment:"Attachment",poweredBy:"Powered by Signalbird",resize:"Resize"};function F(s,e){let t=n=>n&&n!=="auto"?n.toLowerCase().slice(0,2):null;return (t(e)||t(s)||t(typeof navigator!="undefined"?navigator.language:null)||"en")==="tr"?"tr":"en"}function j(s){return s==="tr"?Ee:Me}function P(s,e){return s.replace(/\{(\w+)\}/g,(t,i)=>{var n;return String((n=e[i])!=null?n:"")})}var Se=/^image\/(jpeg|png|gif|webp)$/,O=class{constructor(e){this.o=e;this.list=null;this.typingEl=null;this.textarea=null;this.chips=null;this.replyBar=null;this.notice=null;this.files=[];this.replyTo=null;this.editing=null;this.view="none";this.typingTimer=null;this.wasTyping=false;var d;let t=e.t;this.host=a("div",{id:"signalbird-widget"}),this.root=this.host.attachShadow({mode:"open"}),this.root.appendChild(a("style",null,Q));let i=e.settings.position==="left"?"left":"right",n=e.settings.layout==="sidebar"?" sidebar":"";if(this.wrap=a("div",{class:`sb ${i}${n}${Ae(e.settings.theme)?" dark":""}`,style:`--sb-c:${Re(e.settings.color)}`}),e.settings.theme==="auto"&&typeof matchMedia=="function"){let h=matchMedia("(prefers-color-scheme: dark)");(d=h.addEventListener)==null||d.call(h,"change",g=>this.wrap.classList.toggle("dark",g.matches));}this.badge=a("span",{class:"badge",style:"display:none"});let r=e.settings.launcher_text;this.launcher=a("button",{class:`ln${r?"":" icon-only"}`,type:"button","aria-label":r||t.launcher,onclick:()=>e.actions.open()},this.launcherMark(),r?a("span",{class:"lt"},r):null,this.badge),this.dismissBtn=a("button",{class:"dm",type:"button",title:t.dismiss,"aria-label":t.dismiss,onclick:h=>{h.stopPropagation(),e.actions.dismiss();}},v("close",12)),this.headerAvatar=a("div",{class:"av"},this.brandAvatar()),this.headerName=a("div",{class:"hn"},e.appName||t.title),this.headerDot=a("span",{class:"dot"}),this.headerStatus=a("div",{class:"hs"},this.headerDot,a("span",null,t.offline)),this.endBtn=a("button",{class:"hb",type:"button",title:t.endChat,style:"display:none",onclick:()=>e.actions.endChat()},v("done",18));let o=a("div",{class:"hd"},this.headerAvatar,a("div",{class:"hi"},this.headerName,this.headerStatus),this.endBtn,a("button",{class:"hb",type:"button",title:t.close,"aria-label":t.close,onclick:()=>e.actions.close()},v("close",20)));this.banner=a("div",{class:"bn",style:"display:none"}),this.body=a("div",{class:"bd"}),this.grip=a("div",{class:"gp",title:t.resize,"aria-hidden":"true"}),this.panel=a("div",{class:"pn",role:"dialog","aria-label":t.title},a("div",{class:"br"}),o,this.banner,this.body,this.grip),e.settings.layout!=="sidebar"&&(this.restoreGeometry(),this.enableMove(o),this.enableResize()),this.wrap.appendChild(this.launcher),this.wrap.appendChild(this.dismissBtn),this.wrap.appendChild(this.panel),this.root.appendChild(this.wrap);let l=0;this.body.addEventListener("dragenter",h=>{h.preventDefault(),l++,this.body.classList.add("dragging");}),this.body.addEventListener("dragover",h=>h.preventDefault()),this.body.addEventListener("dragleave",()=>{--l<=0&&(l=0,this.body.classList.remove("dragging"));}),this.body.addEventListener("drop",h=>{var g;h.preventDefault(),l=0,this.body.classList.remove("dragging"),this.view==="chat"&&((g=h.dataTransfer)!=null&&g.files)&&this.addFiles(Array.from(h.dataTransfer.files));});}mount(){this.host.isConnected||document.body.appendChild(this.host);}unmount(){this.host.remove();}setDismissed(e){this.wrap.classList.toggle("hidden",e);}setLauncherHidden(e){this.wrap.classList.toggle("no-ln",e);}setOpen(e){this.wrap.classList.toggle("open",e),e&&this.list&&requestAnimationFrame(()=>{var t;this.list&&U(this.list),(t=this.textarea)==null||t.focus();});}setUnread(e){this.badge.textContent=e>99?"99+":String(e),this.badge.style.display=e>0?"flex":"none";}attention(){let e=this.launcher;e.classList.remove("sb-attn"),e.offsetWidth,e.classList.add("sb-attn"),window.setTimeout(()=>e.classList.remove("sb-attn"),2400);}setHeader(e,t){var o;let i=this.o.t,n=(e==null?void 0:e.name)||this.o.appName||i.title;this.headerName.textContent=n,C(this.headerAvatar),e!=null&&e.avatar?this.headerAvatar.appendChild(a("img",{src:e.avatar,alt:""})):this.headerAvatar.appendChild(e?document.createTextNode(oe(n)):this.brandAvatar());let r=(o=e==null?void 0:e.online)!=null?o:t;this.headerDot.classList.toggle("on",r),this.headerStatus.lastChild.textContent=r?i.online:i.offline;}setBanner(e,t=false){this.banner.textContent=e||"",this.banner.className=`bn${t?" err":""}`,this.banner.style.display=e?"block":"none";}setEndVisible(e){this.endBtn.style.display=e?"flex":"none";}showPrechat(e){let t=this.o.t,i=this.o.settings.prechat||{name:true,email:true,required:false};this.view="prechat",this.list=null,this.textarea=null,C(this.body);let n=a("input",{type:"text",placeholder:t.name,value:e.name||"",autocomplete:"name"}),r=a("input",{type:"email",placeholder:t.email,value:e.email||"",autocomplete:"email"}),o=this.o.topics||[],l=o.length?a("select",{"aria-label":t.topicLabel},a("option",{value:""},t.topicPlaceholder),...o.map(g=>a("option",{value:g.slug},g.name))):null,d=()=>{let g=n.value.trim(),p=r.value.trim();if(i.required&&(i.name&&!g||i.email&&!p)){(i.name&&!g?n:r).focus();return}if(p&&!/^[^\s@]+@[^\s@]+\.[^\s@]+$/.test(p)){r.focus();return}this.o.actions.submitPrechat(g,p,(l==null?void 0:l.value)||null);},h=a("form",{class:"fm",onsubmit:g=>{g.preventDefault(),d();}},a("h3",null,t.prechatTitle),a("p",null,this.o.settings.greeting||t.prechatHint),i.name?n:null,i.email?r:null,l,a("button",{class:"btn",type:"submit"},t.start),i.required?null:a("button",{class:"btn gh",type:"button",onclick:()=>this.o.actions.skipPrechat((l==null?void 0:l.value)||null)},t.skip));this.body.appendChild(h),setTimeout(()=>(i.name?n:r).focus(),50);}showChat(){if(this.view==="chat"&&this.list)return;let e=this.o.t;this.view="chat",C(this.body),this.list=a("div",{class:"ml"}),this.notice=a("div",{class:"notice",style:"display:none"}),this.typingEl=a("div",{class:"tp"},a("i"),a("i"),a("i"),a("span",{style:"margin-left:4px"},"")),this.replyBar=a("div",{class:"rq",style:"display:none"}),this.chips=a("div",{class:"chips",style:"display:none"}),this.textarea=a("textarea",{rows:1,placeholder:e.placeholder,"aria-label":e.placeholder,onkeydown:n=>{n.key==="Enter"&&!n.shiftKey&&!n.isComposing?(n.preventDefault(),this.submit()):n.key==="Escape"&&(this.editing?this.cancelEdit():this.replyTo&&this.setReply(null));},oninput:()=>{this.autosize(),this.notifyTyping();},onpaste:n=>{var o;let r=Array.from(((o=n.clipboardData)==null?void 0:o.files)||[]);r.length&&(n.preventDefault(),this.addFiles(r));}});let t=a("input",{type:"file",multiple:true,style:"display:none",accept:"image/jpeg,image/png,image/gif,image/webp",onchange:()=>{this.addFiles(Array.from(t.files||[])),t.value="";}}),i=a("div",{class:"cp"},this.replyBar,this.chips,a("div",{class:"cr"},a("button",{class:"cb",type:"button",title:e.attach,"aria-label":e.attach,onclick:()=>t.click()},v("clip",19)),this.textarea,a("button",{class:"cb sd",type:"button",title:e.send,"aria-label":e.send,onclick:()=>this.submit()},v("send",17))),t,a("div",{class:"pw"},a("a",{href:"https://signalbird.io",target:"_blank",rel:"noopener",title:e.poweredBy},a("span",{class:"pk"},K(13)),a("span",{class:"pn2"},"Signalbird"))));this.body.appendChild(this.list),this.body.appendChild(this.notice),this.body.appendChild(this.typingEl),this.body.appendChild(i),this.body.appendChild(a("div",{class:"drop"},e.dropHere));}showRating(){let e=this.o.t;this.view="rating",this.list=null,this.textarea=null,C(this.body);let t=0,i=[],n=()=>i.forEach((d,h)=>d.classList.toggle("on",h<t)),r=a("div",{class:"stars"});for(let d=1;d<=5;d++){let h=a("button",{type:"button","aria-label":String(d),onclick:()=>{t=d,n();}},v("star",30));i.push(h),r.appendChild(h);}let o=a("textarea",{placeholder:e.rateComment}),l=a("form",{class:"fm",onsubmit:d=>{d.preventDefault(),this.o.actions.rate(t,o.value.trim());}},a("h3",{style:"text-align:center"},e.rateTitle),r,o,a("button",{class:"btn",type:"submit"},e.rateSend),a("button",{class:"btn gh",type:"button",onclick:()=>this.o.actions.rate(0,"")},e.skip));this.body.appendChild(l);}showThanks(e){this.view="none",this.list=null,C(this.body);let t=a("div",{class:"ok"},a("p",null,this.o.t.rateThanks));e!=null&&e.url&&(t.appendChild(a("p",{class:"rv"},this.o.t.reviewIntro)),t.appendChild(a("a",{class:"btn",href:e.url,target:"_blank",rel:"noopener noreferrer",style:"margin-top:10px;display:inline-flex;text-decoration:none"},e.label||this.o.t.reviewCta))),t.appendChild(a("button",{class:"btn gh",type:"button",style:"margin-top:10px",onclick:()=>this.o.actions.newChat()},this.o.t.newChat)),this.body.appendChild(t);}get currentView(){return this.view}render(e){this.list&&ae(this.list,{...e,t:this.o.t,locale:this.o.locale,actions:this.o.actions});}setTyping(e,t){this.typingEl&&(this.typingEl.classList.toggle("on",e),this.typingEl.lastChild.textContent=`${t} ${this.o.t.typing}`,e&&this.list&&U(this.list));}setNotice(e,t){if(this.notice){if(C(this.notice),!e){this.notice.style.display="none";return}this.notice.appendChild(document.createTextNode(e)),t&&this.notice.appendChild(a("button",{type:"button",onclick:t.fn},t.label)),this.notice.style.display="block";}}setReply(e){var i;if(this.replyTo=e,!this.replyBar)return;if(C(this.replyBar),!e){this.replyBar.style.display="none";return}let t=e.sender_type==="visitor"?this.o.t.you:e.sender_name||this.o.t.agent;this.replyBar.appendChild(a("span",{class:"rt"},`${this.o.t.replyingTo} ${t}: ${I(e,this.o.t)}`)),this.replyBar.appendChild(a("button",{type:"button",onclick:()=>this.setReply(null)},v("close",14))),this.replyBar.style.display="flex",(i=this.textarea)==null||i.focus();}startEdit(e){this.textarea&&(this.editing=e,this.setReply(null),this.textarea.value=e.body||"",this.autosize(),this.textarea.focus(),this.replyBar&&(C(this.replyBar),this.replyBar.appendChild(a("span",{class:"rt"},`${this.o.t.edit}: ${I(e,this.o.t)}`)),this.replyBar.appendChild(a("button",{type:"button",onclick:()=>this.cancelEdit()},v("close",14))),this.replyBar.style.display="flex"));}cancelEdit(){this.editing=null,this.textarea&&(this.textarea.value="",this.autosize()),this.replyBar&&(C(this.replyBar),this.replyBar.style.display="none");}submit(){if(!this.textarea)return;let e=this.textarea.value.trim();if(this.editing){let n=this.editing;this.cancelEdit(),e&&e!==n.body&&this.o.actions.saveEdit(n,e);return}if(!e&&this.files.length===0)return;let t=this.files,i=this.replyTo;this.files=[],this.renderChips(),this.setReply(null),this.textarea.value="",this.autosize(),this.stopTyping(),this.o.actions.send(e,t,i),this.textarea.focus();}addFiles(e){let t=this.o.maxMb*1024*1024;for(let i of e){if(i.size>t){this.flash(P(this.o.t.fileTooLarge,{mb:this.o.maxMb}));continue}if(i.type&&!Se.test(i.type)){this.flash(this.o.t.fileNotAllowed);continue}if(this.files.length>=5)break;this.files.push(i);}this.renderChips();}renderChips(){this.chips&&(C(this.chips),this.chips.style.display=this.files.length?"flex":"none",this.files.forEach((e,t)=>{let i=a("div",{class:"chip"},e.type.startsWith("image/")?a("img",{src:URL.createObjectURL(e),alt:""}):v("file",16),a("span",null,e.name),a("button",{type:"button",onclick:()=>{this.files.splice(t,1),this.renderChips();}},v("close",12)));this.chips.appendChild(i);}));}launcherMark(){let e=this.o.settings,t=de(e.logo_url);return e.launcher_icon==="logo"&&t?a("img",{class:"lg",src:t,alt:""}):e.launcher_icon==="chat"?v("chat",24):K(26)}brandAvatar(){let e=de(this.o.settings.logo_url);return e?a("img",{src:e,alt:""}):document.createTextNode(oe(this.o.appName))}restoreGeometry(){let e=_e();e&&(e.w&&(this.panel.style.width=`${e.w}px`),e.h&&(this.panel.style.height=`${e.h}px`),this.wrap.style.setProperty("--sb-dx",`${e.dx||0}px`),this.wrap.style.setProperty("--sb-dy",`${e.dy||0}px`));}saveGeometry(){ze({w:this.panel.offsetWidth,h:this.panel.offsetHeight,dx:parseFloat(this.wrap.style.getPropertyValue("--sb-dx"))||0,dy:parseFloat(this.wrap.style.getPropertyValue("--sb-dy"))||0});}enableMove(e){e.addEventListener("pointerdown",t=>{if(t.button!==0||le()||t.target.closest("button"))return;let i=t.clientX,n=t.clientY,r=parseFloat(this.wrap.style.getPropertyValue("--sb-dx"))||0,o=parseFloat(this.wrap.style.getPropertyValue("--sb-dy"))||0,l=this.wrap.classList.contains("left")?-1:1,d=false,h=p=>{let f=p.clientX-i,c=p.clientY-n;if(!d&&Math.abs(f)+Math.abs(c)<4)return;d=true,this.wrap.classList.add("moving");let u=Math.max(0,innerWidth-this.panel.offsetWidth-24),b=Math.max(0,innerHeight-this.panel.offsetHeight-24);this.wrap.style.setProperty("--sb-dx",`${H(r-f*l,0,u)}px`),this.wrap.style.setProperty("--sb-dy",`${H(o-c,0,b)}px`);},g=()=>{removeEventListener("pointermove",h),removeEventListener("pointerup",g),this.wrap.classList.remove("moving"),d&&this.saveGeometry();};addEventListener("pointermove",h),addEventListener("pointerup",g);});}enableResize(){this.grip.addEventListener("pointerdown",e=>{if(e.button!==0||le())return;e.preventDefault();let t=e.clientX,i=e.clientY,n=this.panel.offsetWidth,r=this.panel.offsetHeight,o=this.wrap.classList.contains("left")?-1:1;this.wrap.classList.add("sizing");let l=h=>{this.panel.style.width=`${H(n+(t-h.clientX)*o,320,innerWidth-40)}px`,this.panel.style.height=`${H(r+(i-h.clientY),380,innerHeight-40)}px`;},d=()=>{removeEventListener("pointermove",l),removeEventListener("pointerup",d),this.wrap.classList.remove("sizing"),this.saveGeometry();};addEventListener("pointermove",l),addEventListener("pointerup",d);});}flash(e){this.setBanner(e,true),setTimeout(()=>this.setBanner(null),3e3);}autosize(){let e=this.textarea;e&&(e.style.height="auto",e.style.height=`${Math.min(e.scrollHeight,120)}px`);}notifyTyping(){this.wasTyping||(this.wasTyping=true,this.o.actions.typing(true)),this.typingTimer&&clearTimeout(this.typingTimer),this.typingTimer=setTimeout(()=>this.stopTyping(),2500);}stopTyping(){this.typingTimer&&clearTimeout(this.typingTimer),this.typingTimer=null,this.wasTyping&&(this.wasTyping=false,this.o.actions.typing(false));}};function oe(s){return (s||"?").split(/\s+/).slice(0,2).map(e=>e[0]||"").join("").toUpperCase()}var pe="sb_geometry";function _e(){try{let s=localStorage.getItem(pe);if(!s)return null;let e=JSON.parse(s);return !e||e.w>innerWidth||e.h>innerHeight?null:e}catch(s){return null}}function ze(s){try{localStorage.setItem(pe,JSON.stringify(s));}catch(e){}}function H(s,e,t){return Math.min(Math.max(s,e),t)}function le(){return innerWidth<=640}function Ae(s){return s==="dark"?true:s!=="auto"||typeof matchMedia!="function"?false:matchMedia("(prefers-color-scheme: dark)").matches}function de(s){return typeof s=="string"&&/^(https:\/\/|data:image\/)/i.test(s)?s:null}function Re(s){return s&&/^(#[0-9a-f]{3,8}|rgba?\([\d\s.,%]+\)|hsla?\([\d\s.,%]+\))$/i.test(s)?s:"#111827"}var $=class{constructor(){this.original=null;this.timer=null;this.label="";}update(e,t){e>0&&document.hidden?(this.label=t(e),this.begin()):this.end();}begin(){if(this.timer)return;this.original=document.title;let e=false;this.timer=setInterval(()=>{if(!document.hidden)return this.end();e=!e,document.title=e?this.label:this.original||"";},1200);}end(){this.timer&&clearInterval(this.timer),this.timer=null,this.original!==null&&(document.title=this.original,this.original=null);}};var M=null;function Y(){try{let s=window.AudioContext||window.webkitAudioContext;if(!s)return;M||(M=new s),M.state==="suspended"&&M.resume();let e=M.currentTime,t=M.createGain();t.gain.setValueAtTime(1e-4,e),t.gain.exponentialRampToValueAtTime(.12,e+.02),t.gain.exponentialRampToValueAtTime(1e-4,e+.35),t.connect(M.destination);let i=M.createOscillator();i.type="sine",i.frequency.setValueAtTime(880,e),i.frequency.setValueAtTime(1175,e+.12),i.connect(t),i.start(e),i.stop(e+.36);}catch(s){}}var Ie="https://live.signalbird.io/api",k="/v1/sdk/chat/conversations",N=class{constructor(e){this.opts=e;this.title=new $;this.topic=null;this.ui=null;this.settings=null;this.appName="";this.started=false;this.destroyed=false;this.pendingSends=new Map;this.ratingMode=null;this.autoOpened=false;this.identity=null;this.lastTypingSent=0;this.pollCount=0;this.forceFull=false;this.socket=null;this.onVisibility=()=>{this.syncUnread(),!document.hidden&&this.store.isOpen&&this.store.conversation&&this.markRead();};this.baseUrl=(e.baseUrl||Ie).replace(/\/$/,""),this.store=new z(e.publicKey),this.api=new _(this.baseUrl,e.publicKey,e.chatKey,()=>this.store.secret,(...t)=>this.log(...t)),this.poller=new A(()=>this.tick()),this.identity=e.user&&(e.user.name||e.user.email||e.user.external_id)?e.user:null,this.locale=F(null,e.locale),this.t=j(this.locale),this.ready=this.start().catch(t=>this.log("start failed",t));}log(...e){this.opts.debug&&console.debug("[signalbird]",...e);}async start(){var g;let e=await this.api.post("/v1/sdk/bootstrap",{page_url:location.href,locale:this.opts.locale});if(!e.ok||!((g=e.data)!=null&&g.app)){this.log("bootstrap failed",e);return}if(this.destroyed)return;let{app:t,online:i,within_hours:n,visitor:r,conversation:o,topics:l,realtime:d}=e.data;if(!t.chat_enabled){this.log("chat disabled for app");return}this.settings=t.chat||{},this.appName=t.name||"",this.locale=F(this.settings.locale,this.opts.locale),this.t=j(this.locale),this.store.visitor&&!r&&this.store.clearVisitor(),r&&this.store.setVisitor({id:r.id,name:r.name,email:r.email}),this.store.online=!!i,this.store.withinHours=n!==false,o&&this.store.setConversation(o);let h=Number(this.settings.max_attachment_mb||t.max_attachment_mb||10);this.ui=new O({t:this.t,locale:this.locale,settings:this.settings,appName:this.appName,maxMb:h,topics:l||[],actions:{open:()=>this.open(),close:()=>this.close(),send:(p,f,c)=>{this.send(p,f,c);},typing:p=>{this.typing(p);},submitPrechat:(p,f,c)=>{this.submitPrechat(p,f,c);},skipPrechat:p=>{this.topic=p,this.enterChat();},rate:(p,f)=>{this.rate(p,f);},dismiss:()=>this.dismiss(),endChat:()=>this.endChat(),newChat:()=>this.newChat(),saveEdit:(p,f)=>{this.saveEdit(p,f);},reply:p=>{var f;return (f=this.ui)==null?void 0:f.setReply(p)},react:(p,f)=>{this.react(p,f);},edit:p=>{var f;return (f=this.ui)==null?void 0:f.startEdit(p)},remove:p=>{this.remove(p);},retry:p=>{this.retry(p);},openImage:p=>window.open(p,"_blank","noopener")}}),this.store.on("unread",()=>this.syncUnread()),this.store.on("messages",()=>this.render()),this.store.on("change",()=>this.render()),document.addEventListener("visibilitychange",this.onVisibility),this.ui.mount(),this.ui.setDismissed(this.store.dismissed),this.syncLauncher(),this.ui.setHeader(this.store.agent,this.store.online),this.applyBanner(),this.store.setUnread((r==null?void 0:r.unread)||(o==null?void 0:o.visitor_unread)||0),this.syncUnread(),this.started=true,this.poller.start(),d!=null&&d.enabled&&(this.socket=new R(d,(p,f)=>this.authorizeChannel(p,f),p=>this.onSocketEvent(p),p=>{this.log("socket",p?"connected":"disconnected"),this.poller.setLive(p),p&&this.poller.poke(0);},(...p)=>this.log(...p)),this.socket.connect(),this.subscribeVisitor()),this.opts.user&&this.identify(this.opts.user);}applyBanner(){!this.ui||!this.settings||this.ui.setBanner(this.store.withinHours?null:this.settings.offline_message||this.t.offlineMessage);}syncUnread(){var t;let e=this.store.isOpen&&!document.hidden?0:this.store.unread;(t=this.ui)==null||t.setUnread(this.store.unread),this.title.update(e,i=>P(this.t.unreadTitle,{n:i})),this.store.emit("public:unread",this.store.unread),this.syncLauncher();}syncLauncher(){var i;if(!this.ui)return;if(((i=this.settings)==null?void 0:i.launcher_mode)!=="manual"){this.ui.setLauncherHidden(false);return}let e=this.store.conversation,t=!!e&&e.status!=="closed";this.ui.setLauncherHidden(!(this.store.isOpen||t||this.store.unread>0));}dismiss(){var e;this.store.setDismissed(true),this.close(),(e=this.ui)==null||e.setDismissed(true);}open(){var e,t;this.store.dismissed&&(this.store.setDismissed(false),(e=this.ui)==null||e.setDismissed(false)),!(!this.ui||this.store.isOpen)&&(((t=this.store.conversation)==null?void 0:t.status)==="closed"&&(this.store.setConversation(null),this.ratingMode=null),this.store.isOpen=true,this.ui.setOpen(true),this.syncLauncher(),this.poller.setOpen(true),this.decideView(),this.store.emit("public:open"),this.store.conversation?this.loadConversation():this.store.setUnread(0),this.syncUnread());}close(){if(!this.ui||!this.store.isOpen)return;let e=this.store.conversation;if(e&&e.status==="resolved"&&!this.store.wasRated(e.id)&&this.ui.currentView==="chat"&&this.store.messages.some(t=>t.sender_type==="agent")){this.ratingMode="resolved",this.ui.setEndVisible(false),this.ui.showRating();return}this.store.isOpen=false,this.ui.setOpen(false),this.poller.setOpen(false),this.typing(false),this.store.emit("public:close"),this.syncUnread(),this.syncLauncher();}toggle(){this.store.isOpen?this.close():this.open();}isOpen(){return this.store.isOpen}on(e,t){this.store.on(`public:${e}`,t);}off(e,t){this.store.off(`public:${e}`,t);}async identify(e){var r;if(await this.ready,this.destroyed)return;this.identity={...this.identity||{},...e},((r=this.ui)==null?void 0:r.currentView)==="prechat"&&this.enterChat();let[t,...i]=(e.name||"").trim().split(/\s+/),n={external_id:e.external_id,email:e.email,phone:e.phone,first_name:t||void 0,last_name:i.join(" ")||void 0,attributes:e.attributes};e.external_id&&this.check(await this.api.post("/v1/sdk/identify",n)),await this.session({name:e.name,email:e.email,external_id:e.external_id});}async pushRegister(e){return await this.ready,this.api.post("/v1/sdk/devices",{provider:e.platform==="ios"?"apns":"fcm",locale:this.locale,...e})}destroy(){var e,t;this.destroyed=true,(e=this.socket)==null||e.close(),this.socket=null,this.poller.stop(),this.title.end(),document.removeEventListener("visibilitychange",this.onVisibility),(t=this.ui)==null||t.unmount(),this.ui=null;}decideView(){var r,o;if(!this.ui||!this.settings)return;let e=this.settings.prechat,t=this.store.visitor;!!!((r=this.identity)!=null&&r.name||(o=this.identity)!=null&&o.email||t!=null&&t.name||t!=null&&t.email)&&!this.store.conversation&&e&&(e.name||e.email)?this.ui.showPrechat({}):this.enterChat();}enterChat(){var e;this.ui&&(this.ratingMode=null,this.ui.showChat(),this.ui.setEndVisible(((e=this.store.conversation)==null?void 0:e.status)==="open"),this.render());}render(){var t,i;if(!this.ui||this.ui.currentView!=="chat")return;let e=this.store.conversation;this.ui.render({messages:this.store.messages,greeting:((t=this.settings)==null?void 0:t.greeting)||this.t.greeting,agentName:((i=this.store.agent)==null?void 0:i.name)||this.t.agent,find:n=>this.store.find(n)}),this.ui.setEndVisible((e==null?void 0:e.status)==="open"),e&&e.status!=="open"?this.ui.setNotice(e.status==="resolved"?this.t.resolved:this.t.closed,{label:this.t.newChat,fn:()=>this.newChat()}):this.ui.setNotice(null);}async submitPrechat(e,t,i){var r;this.topic=i,await this.session({name:e||void 0,email:t||void 0})?this.enterChat():(r=this.ui)==null||r.setBanner(this.t.unavailable,true);}newChat(){this.ratingMode=null,this.store.setConversation(null),this.enterChat(),this.store.isOpen||this.open();}endChat(){!this.ui||!this.store.conversation||(this.ratingMode="end",this.ui.setEndVisible(false),this.ui.showRating());}async rate(e,t){var r;let i=this.store.conversation,n=this.ratingMode;if(this.ratingMode=null,!(!i||!this.ui)){if(e>0){let o=await this.api.post(`${k}/${i.id}/rate`,{rating:e,comment:t||void 0});this.check(o),this.store.markRated(i.id);}if(n==="end"){let o=await this.api.post(`${k}/${i.id}/close`);this.check(o),((r=this.store.conversation)==null?void 0:r.id)===i.id&&this.store.setConversation({...i,status:"closed"}),this.ui.showThanks(this.reviewFor(e));return}e===0&&this.store.markRated(i.id),this.enterChat(),this.close();}}reviewFor(e){var n,r,o,l;let t=(((n=this.settings)==null?void 0:n.review_url)||"").trim(),i=Number((o=(r=this.settings)==null?void 0:r.review_min_rating)!=null?o:3);return !t||!/^https?:\/\//i.test(t)?null:e>0&&e>=i?{url:t,label:((l=this.settings)==null?void 0:l.review_label)||null}:null}async session(e={}){var n;let t=this.identity?{name:this.identity.name,email:this.identity.email,external_id:this.identity.external_id}:{},i=await this.api.post("/v1/sdk/chat/session",{...t,...e,locale:this.locale,page_url:location.href,user_agent:navigator.userAgent});if(i.ok&&((n=i.data)!=null&&n.visitor)){let r=i.data.visitor;return !r.secret&&!this.store.visitor?(this.log("session returned no secret"),false):(this.store.setVisitor(r),this.subscribeVisitor(),true)}return !i.ok&&i.code==="VISITOR_INVALID"&&this.store.visitor?(this.store.clearVisitor(),this.session(e)):(this.check(i),false)}subscribeVisitor(){var t;let e=(t=this.store.visitor)==null?void 0:t.id;this.socket&&e&&this.socket.subscribe(`visitor.${e}`);}async authorizeChannel(e,t){var n;let i=await this.api.post("/v1/sdk/chat/socket/auth",{socket_id:e,channel:t});return i.ok&&((n=i.data)!=null&&n.auth)?{auth:i.data.auth,at:i.data.at}:null}onSocketEvent(e){var t,i;if(e.name==="chat.typing"){e.data.who==="agent"&&(this.store.agentTyping=e.data.active===true,(i=this.ui)==null||i.setTyping(this.store.agentTyping,((t=this.store.agent)==null?void 0:t.name)||this.t.agent));return}e.data.updated===true&&(this.forceFull=true),this.poller.poke(0);}async loadConversation(){let e=this.store.conversation;if(!e)return;let t=await this.api.get(`${k}/${e.id}`,{limit:50});this.applyPayload(t,true)&&this.store.isOpen&&!document.hidden&&this.store.setUnread(0);}applyPayload(e,t){var n,r,o,l;if(!e.ok)return this.check(e),e.status===404&&this.store.setConversation(null),-1;let i=e.data;if(i.conversation){let d=(n=this.store.conversation)==null?void 0:n.status;this.store.conversation=i.conversation,d!==i.conversation.status&&this.store.emit("change");}return i.agent!==void 0&&(this.store.agent=i.agent||null),this.store.agentTyping=!!i.agent_typing,(r=this.ui)==null||r.setHeader(this.store.agent,this.store.online),(l=this.ui)==null||l.setTyping(this.store.agentTyping,((o=this.store.agent)==null?void 0:o.name)||this.t.agent),this.store.mergeMessages(i.messages||[],t)}async tick(){var d,h,g,p;if(!this.started||!this.store.visitor)return false;this.pollCount++;let e=this.store.conversation;if(this.store.isOpen&&e){let f=this.pollCount%5===0||this.forceFull;this.forceFull=false;let c=f?void 0:this.store.lastServerMessageId||void 0,u=await this.api.get(`${k}/${e.id}`,c?{after:c}:{limit:50}),b=this.applyPayload(u,!c);return b>0&&(document.hidden?(this.store.setUnread(this.store.unread+b),(d=this.settings)!=null&&d.sound&&Y()):this.markRead()),b>0}if(this.store.isOpen&&!e&&this.pollCount%10!==0)return false;let t=await this.api.get(k);if(!t.ok)return this.check(t),false;let i=t.data,n=Array.isArray(i)?i:(i==null?void 0:i.conversations)||(i==null?void 0:i.data)||[],r=n.find(f=>f.status==="open")||null,o=n.reduce((f,c)=>f+(c.visitor_unread||0),0),l=o>this.store.unread;return r&&r.id!==((h=this.store.conversation)==null?void 0:h.id)&&(this.store.setConversation(r),this.store.isOpen&&this.loadConversation()),(!this.store.isOpen||document.hidden)&&(this.store.setUnread(o),l&&((g=this.settings)!=null&&g.sound&&Y(),(p=this.ui)==null||p.attention(),!this.autoOpened&&!document.hidden&&(this.autoOpened=true,this.open()))),l}async markRead(){let e=this.store.conversation,t=this.store.lastServerMessageId;!e||!t||(this.store.setUnread(0),await this.api.post(`${k}/${e.id}/read`,{last_message_id:t},true));}async send(e,t,i,n=te()){var l;let r={id:`local_${n}`,client_id:n,sender_type:"visitor",type:t.length?t[0].type.startsWith("image/")?"image":"file":"text",body:e||null,attachments:null,reply_to_id:(i==null?void 0:i.id)||null,created_at:new Date().toISOString(),_pending:true,_files:t};this.pendingSends.set(n,{text:e,files:t,replyTo:(i==null?void 0:i.id)||null}),this.store.upsertMessage(r);let o=()=>{let d=this.store.find(r.id);d&&this.store.upsertMessage({...d,_pending:false,_failed:true});};try{if(!this.store.visitor&&!await this.session())return o();let d=this.store.conversation,h=!d||d.status!=="open";if(h&&t.length===0){let c=await this.api.post(k,{body:e,page_url:location.href,client_id:n,...this.topic?{topic:this.topic}:{}});if(!c.ok)return this.sendFailed(c,o);this.store.setConversation(c.data.conversation),this.store.mergeMessages(c.data.messages||[]),this.reconcile(r,c.data.messages),this.pendingSends.delete(n),this.poller.poke(3e3);return}if(h){let c=await this.api.post(k,{page_url:location.href,...this.topic?{topic:this.topic}:{}});if(!c.ok)return this.sendFailed(c,o);this.store.setConversation(c.data.conversation),this.store.mergeMessages(c.data.messages||[]),d=c.data.conversation;}if(!d)return o();let g=[];for(let c of t){let u=await this.api.upload(`${k}/${d.id}/attachments`,c);if(!u.ok)return this.sendFailed(u,o);g.push(u.data);}let p=await this.api.post(`${k}/${d.id}/messages`,{body:e||void 0,attachments:g.length?g:void 0,reply_to_id:(i==null?void 0:i.id)||void 0,client_id:n});if(!p.ok)return this.sendFailed(p,o);let f=((l=p.data)==null?void 0:l.message)||p.data;this.reconcile(r,[f]),this.pendingSends.delete(n),this.poller.poke(3e3);}catch(d){this.log("send error",d),o();}}reconcile(e,t){let i=(t||[]).find(n=>n.client_id===e.client_id);i?this.store.mergeMessages([{...i,client_id:e.client_id}]):t&&t.length&&(this.store.removeMessage(e.id),this.store.mergeMessages(t));}sendFailed(e,t){var i;this.check(e),(e.code==="CHAT_UNAVAILABLE"||e.status===503)&&((i=this.ui)==null||i.setBanner(this.t.unavailable,true)),t();}async retry(e){let t=e.client_id?this.pendingSends.get(e.client_id):null;this.store.removeMessage(e.id),!(!t||!e.client_id)&&await this.send(t.text,t.files,this.store.find(t.replyTo)||null,e.client_id);}async typing(e){let t=this.store.conversation;if(!t||t.status!=="open"||!this.store.visitor)return;let i=Date.now();e&&i-this.lastTypingSent<4e3||(this.lastTypingSent=e?i:0,await this.api.post(`${k}/${t.id}/typing`,{is_typing:e},true));}async react(e,t){var h,g,p,f;let i=this.store.conversation;if(!i)return;let n={...e.reactions||{}},r=[...n[t]||[]],o=r.indexOf("visitor");o>=0?r.splice(o,1):r.push("visitor"),n[t]=r,this.store.upsertMessage({...e,reactions:n});let l=await this.api.post(`${k}/${i.id}/messages/${e.id}/reactions`,{emoji:t});if(!l.ok){this.check(l),this.store.upsertMessage({...e});return}let d=(f=(g=(h=l.data)==null?void 0:h.message)==null?void 0:g.reactions)!=null?f:(p=l.data)==null?void 0:p.reactions;d&&this.store.upsertMessage({...e,reactions:d});}async saveEdit(e,t){var o;let i=this.store.conversation;if(!i)return;this.store.upsertMessage({...e,body:t,edited_at:new Date().toISOString()});let n=await this.api.patch(`${k}/${i.id}/messages/${e.id}`,{body:t});if(!n.ok){this.check(n),this.store.upsertMessage({...e});return}let r=((o=n.data)==null?void 0:o.message)||n.data;r&&r.id&&this.store.upsertMessage(r);}async remove(e){let t=this.store.conversation;if(!t)return;this.store.upsertMessage({...e,deleted_at:new Date().toISOString()});let i=await this.api.delete(`${k}/${t.id}/messages/${e.id}`);i.ok||(this.check(i),this.store.upsertMessage({...e}));}check(e){e.ok||(e.code==="VISITOR_INVALID"||e.status===401&&this.store.visitor)&&(this.store.clearVisitor(),this.store.isOpen&&this.decideView());}};var Pe={tr:{loading:"Y\xFCkleniyor\u2026",failed:"Ekran y\xFCklenemedi.",expired:"Bu ba\u011Flant\u0131n\u0131n s\xFCresi doldu.",retry:"Yeniden dene"},en:{loading:"Loading\u2026",failed:"The screen could not be loaded.",expired:"This link has expired.",retry:"Try again"}};function He(s){if(s==="light"||s==="dark")return s;if(typeof document!="undefined"){let e=document.documentElement;if(e.classList.contains("dark")||e.dataset.theme==="dark")return "dark";if(e.classList.contains("light")||e.dataset.theme==="light")return "light"}return typeof window!="undefined"&&typeof window.matchMedia=="function"&&window.matchMedia("(prefers-color-scheme: dark)").matches?"dark":"light"}function Oe(s){if(typeof s=="string")return s||null;if(s&&typeof s=="object"){let e=s;if(typeof e.url=="string")return e.url;if(e.data&&typeof e.data.url=="string")return e.data.url}return null}function ce(s){var f,c;let e=Pe[(f=s.language)!=null?f:"tr"],t=new Map,i=null,n=null,r=null,o=(c=s.theme)!=null?c:"auto",l=false,d=(u,b)=>{var x;(x=t.get(u))==null||x.forEach(w=>{try{w(b);}catch(E){console.warn("[signalbird]",E);}});},h=()=>{r&&(window.removeEventListener("message",r),r=null),n=null,i&&(i.textContent="");},g=(u,b)=>{var E;if(!i)return;i.textContent="";let x=document.createElement("div");x.setAttribute("data-signalbird-status",""),x.style.cssText=`display:flex;align-items:center;justify-content:center;gap:12px;min-height:${(E=s.minHeight)!=null?E:220}px;font:13px/1.5 system-ui,-apple-system,sans-serif;color:#6b7280;text-align:center;padding:24px;`;let w=document.createElement("span");if(w.textContent=u,x.appendChild(w),b){let y=document.createElement("button");y.type="button",y.textContent=e.retry,y.style.cssText="border:1px solid currentColor;border-radius:8px;background:transparent;color:inherit;padding:4px 10px;font:inherit;cursor:pointer;",y.addEventListener("click",()=>{p();}),x.appendChild(y);}i.appendChild(x);},p=async()=>{var E;if(!i||l)return;h(),g(e.loading,false);let u=He(o),b=null;try{s.url?(b=s.url,s={...s,url:void 0}):s.mint&&(b=Oe(await s.mint({module:s.module,theme:u,locale:s.locale})));}catch(y){d("error",y),g(y instanceof Error?y.message:e.failed,true);return}if(!b){d("error",new Error("EMBED_URL_MISSING")),g(e.expired,!!s.mint);return}let x=b;try{let y=new URL(b);y.searchParams.set("theme",u),s.locale&&y.searchParams.set("locale",s.locale),s.accent&&y.searchParams.set("accent",s.accent.replace(/^#/,"")),x=y.toString();}catch(y){}let w=document.createElement("iframe");w.src=x,w.title="Signalbird",w.style.cssText="width:100%;border:0;display:block;",w.style.height=`${typeof s.height=="number"?s.height:(E=s.minHeight)!=null?E:640}px`,w.setAttribute("allow","clipboard-write; fullscreen; autoplay"),w.setAttribute("sandbox","allow-same-origin allow-scripts allow-forms allow-popups allow-downloads"),w.setAttribute("referrerpolicy","strict-origin-when-cross-origin"),w.setAttribute("loading","lazy"),s.className&&(w.className=s.className),i.textContent="",i.appendChild(w),n=w,r=y=>{var W,G;if(!n||y.source!==n.contentWindow)return;let L=y.data;if(!(!L||typeof L.type!="string")){if(L.type==="signalbird:ready"){d("ready",L.module);return}if(L.type==="signalbird:height"&&typeof L.px=="number"&&(d("height",L.px),((W=s.height)!=null?W:"auto")==="auto")){let ue=Math.max(L.px,(G=s.minHeight)!=null?G:220);n.style.height=`${ue}px`;}}},window.addEventListener("message",r);};return {async mount(u){let b=typeof u=="string"?document.querySelector(u):u;if(!(b instanceof HTMLElement))throw new Error("Signalbird: g\xF6mme kab\u0131 bulunamad\u0131 \u2014 "+String(u));i=b,l=false,await p();},refresh:()=>p(),async setTheme(u){o=u,await p();},destroy(){l=true,h(),t.clear(),i=null;},on(u,b){t.has(u)||t.set(u,new Set),t.get(u).add(b);},off(u,b){var x;(x=t.get(u))==null||x.delete(b);}}}var ut="2.0.2",m=null,B=[],S=null;function T(s,e){try{return s()}catch(t){try{console.warn("[signalbird]",t);}catch(i){}return e}}function he(s){s.catch(()=>{});}function $e(s){T(()=>{if(!s||!s.publicKey){console.warn("[signalbird] init: publicKey zorunlu");return}if(!(typeof document=="undefined"||typeof window=="undefined")){m&&m.destroy(),m=new N(s);for(let{event:e,fn:t}of B)m.on(e,t);if(S){let e=S;S=null,he(m.identify(e));}}},void 0);}function gt(s){T(()=>{if(s){if(!m){S={...S||{},...s};return}he(m.identify(s));}},void 0);}var ft={open(){T(()=>m==null?void 0:m.open(),void 0);},close(){T(()=>m==null?void 0:m.close(),void 0);},toggle(){T(()=>m==null?void 0:m.toggle(),void 0);},isOpen(){return T(()=>!!(m!=null&&m.isOpen()),false)},on(s,e){T(()=>{typeof e=="function"&&(B.push({event:s,fn:e}),m==null||m.on(s,e));},void 0);},off(s,e){T(()=>{let t=B.findIndex(i=>i.event===s&&i.fn===e);t>=0&&B.splice(t,1),m==null||m.off(s,e);},void 0);}},mt={register(s){return T(()=>m?m.pushRegister(s).catch(e=>({ok:!1,status:0,code:"NETWORK_ERROR",message:String(e)})):Promise.resolve({ok:!1,status:0,code:"NOT_INITIALIZED",message:"Signalbird.init \xE7a\u011Fr\u0131lmad\u0131"}),Promise.resolve({ok:false,status:0,code:"WIDGET_ERROR",message:"widget error"}))}},bt=ce;function vt(){T(()=>{m==null||m.destroy(),m=null;},void 0);}T(()=>{if(typeof document=="undefined")return;let s=document.currentScript||document.querySelector('script[data-key][src*="signalbird"]'),e=s==null?void 0:s.dataset;if(!e||!e.key)return;let t=()=>$e({publicKey:e.key,chatKey:e.channel||void 0,baseUrl:e.baseUrl||void 0,locale:e.locale||void 0,debug:e.debug==="true"||e.debug==="1"});document.body?t():document.addEventListener("DOMContentLoaded",t,{once:!0});},void 0);
|
|
278
278
|
exports.chat=ft;exports.destroy=vt;exports.embed=bt;exports.identify=gt;exports.init=$e;exports.push=mt;exports.version=ut;return exports;})({});
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "signalbird",
|
|
3
|
-
"version": "2.0.
|
|
3
|
+
"version": "2.0.2",
|
|
4
4
|
"description": "Signalbird SDK — Telsiz (Radio), Gönderim (Messaging), Yönetim (Management) ve son kullanıcı sohbet/push istemcisi: sunucu, tarayıcı, mobil",
|
|
5
5
|
"main": "./dist/index.js",
|
|
6
6
|
"module": "./dist/index.mjs",
|