1(function($,b){typeof exports=="object"&&typeof module<"u"?b(exports):typeof define=="function"&&define.amd?define(["exports"],b):($=typeof globalThis<"u"?globalThis:$||self,b($.TarosChatLoader={}))})(this,(function($){"use strict";var b=typeof document<"u"?document.currentScript:null,y="1.0.0",R="TarosChat";function be(e,t=32){const o=`width="${t}" height="${t}"`;switch(e){case"chat":return`<svg viewBox="0 0 24 24" ${o} role="img" aria-hidden="true" focusable="false" fill="none"> 2 <path fill="currentColor" d="M7.2 5.2h9.6a3.2 3.2 0 0 1 3.2 3.2v4.6a3.2 3.2 0 0 1-3.2 3.2h-2.18l-2.88 2.13c-.74.55-1.78 0-1.78-.9V16.2H7.2a3.2 3.2 0 0 1-3.2-3.2V8.4a3.2 3.2 0 0 1 3.2-3.2Z"></path> 3 </svg>`;case"sparkles":return`<svg viewBox="0 0 24 24" ${o} role="img" aria-hidden="true" focusable="false" fill="none"> 4 <path fill="currentColor" d="M9.5 2l2.25 4.5L16.5 9l-4.75 2.5L9.5 16l-2.25-4.5L2.5 9l4.75-2.5L9.5 2zM19 10l1.5 3 3 1.5-3 1.5-1.5 3-1.5-3-3-1.5 3-1.5 1.5-3zM12 18l1 2 2 1-2 1-1 2-1-2-2-1 2-1 1-2z"/> 5 </svg>`;case"bot":return`<svg viewBox="0 0 24 24" ${o} role="img" aria-hidden="true" focusable="false" fill="none"> 6 <path fill="currentColor" d="M17.753 14a2.25 2.25 0 0 1 2.25 2.25v.904A3.75 3.75 0 0 1 18.696 20c-1.565 1.344-3.806 2-6.696 2s-5.128-.656-6.69-2a3.75 3.75 0 0 1-1.306-2.843v-.907A2.25 2.25 0 0 1 6.254 14h11.5zM11.9 2.006L12 2a.75.75 0 0 1 .743.648l.007.102v.5h3.5a2.25 2.25 0 0 1 2.25 2.25v4.505a2.25 2.25 0 0 1-2.25 2.25h-8.5a2.25 2.25 0 0 1-2.25-2.25V5.5A2.25 2.25 0 0 1 7.75 3.25h3.5v-.5a.75.75 0 0 1 .65-.744L12 2zM9.749 6.5a1.499 1.499 0 1 0 0 2.998 1.499 1.499 0 0 0 0-2.998zm4.493 0a1.499 1.499 0 1 0 0 2.998 1.499 1.499 0 0 0 0-2.998z"/> 7 </svg>`;case"wand":return`<svg viewBox="0 0 24 24" ${o} role="img" aria-hidden="true" focusable="false" fill="none"> 8 <path fill="currentColor" d="M7.5 5.6L10 7 8.6 4.5 10 2 7.5 3.4 5 2l1.4 2.5L5 7l2.5-1.4zm12 9.8L17 14l1.4 2.5L17 19l2.5-1.4L22 19l-1.4-2.5L22 14l-2.5 1.4zM22 2l-2.5 1.4L17 2l1.4 2.5L17 7l2.5-1.4L22 7l-1.4-2.5L22 2zm-7.63 5.29a.996.996 0 0 0-1.41 0L1.29 18.96a.996.996 0 0 0 0 1.41l2.34 2.34c.39.39 1.02.39 1.41 0L16.71 11.04a.996.996 0 0 0 0-1.41l-2.34-2.34zm-1.03 5.49l-2.12-2.12 2.44-2.44 2.12 2.12-2.44 2.44z"/> 9 </svg>`;case"message":return`<svg viewBox="0 0 24 24" ${o} role="img" aria-hidden="true" focusable="false" fill="none"> 10 <path fill="currentColor" d="M20 2H4c-1.1 0-2 .9-2 2v18l4-4h14c1.1 0 2-.9 2-2V4c0-1.1-.9-2-2-2zm0 14H6l-2 2V4h16v12z"/> 11 </svg>`;case"lightning":return`<svg viewBox="0 0 24 24" ${o} role="img" aria-hidden="true" focusable="false" fill="none"> 12 <path fill="currentColor" d="M11 21h-1l1-7H7.5c-.58 0-.57-.32-.38-.66.19-.34.05-.08.07-.12C8.48 10.94 10.42 7.54 13 3h1l-1 7h3.5c.49 0 .56.33.47.51l-.07.15C12.96 17.55 11 21 11 21z"/> 13 </svg>`;case"help":return`<svg viewBox="0 0 24 24" ${o} role="img" aria-hidden="true" focusable="false" fill="none"> 14 <path fill="currentColor" d="M12 2C6.48 2 2 6.48 2 12s4.48 10 10 10 10-4.48 10-10S17.52 2 12 2zm1 17h-2v-2h2v2zm2.07-7.75l-.9.92C13.45 12.9 13 13.5 13 15h-2v-.5c0-1.1.45-2.1 1.17-2.83l1.24-1.26c.37-.36.59-.86.59-1.41 0-1.1-.9-2-2-2s-2 .9-2 2H8c0-2.21 1.79-4 4-4s4 1.79 4 4c0 .88-.36 1.68-.93 2.25z"/> 15 </svg>`;default:return`<svg viewBox="0 0 24 24" ${o} role="img" aria-hidden="true" focusable="false" fill="none"> 16 <path fill="currentColor" d="M7.2 5.2h9.6a3.2 3.2 0 0 1 3.2 3.2v4.6a3.2 3.2 0 0 1-3.2 3.2h-2.18l-2.88 2.13c-.74.55-1.78 0-1.78-.9V16.2H7.2a3.2 3.2 0 0 1-3.2-3.2V8.4a3.2 3.2 0 0 1 3.2-3.2Z"></path> 17 </svg>`}}function ye(e){switch(e){case"circle":return 9999;case"rounded":return 16;case"square":return 4;default:return 9999}}const we="0.0.2",K="https://widgets.taros.ai/iframe",ve=2147483e3,xe="taros-widget-position",Z=8,Q=new Set,ee={en:{openChat:"Open chat",closeChat:"Close chat",chatTitle:"Chat",typeMessage:"Type a message...",send:"Send",poweredBy:"Powered by",hideWidget:"Hide widget"},da:{openChat:"Ã bn chat",closeChat:"Luk chat",chatTitle:"Chat",typeMessage:"Skriv en besked...",send:"Send",poweredBy:"Drevet af",hideWidget:"Skjul widget"}};let A="en";function S(e){return ee[A][e]||ee.en[e]||e}const te={source:"api",focus:!0};let ne=!1;class $e{listeners=new Map;on(t,o){const i=this.listeners.get(t)??new Set;return i.add(o),this.listeners.set(t,i),()=>this.off(t,o)}once(t,o){const i=this.on(t,r=>{i(),o(r)});return i}off(t,o){const i=this.listeners.get(t);i&&(i.delete(o),i.size===0&&this.listeners.delete(t))}emit(t,o){const i=this.listeners.get(t);if(i)for(const r of i)r(o)}}const p=new $e,n={config:Ee(),features:{notifications:!1,audio:!1},initialized:!1,open:!1,minimized:!1,closing:!1,destroyed:!1,fallbackActive:!1,nonce:Le(),expectedOrigin:void 0,handshakeInitiated:!1,handshakeComplete:!1,queuedMessages:[],lastOpenPayload:void 0,initRetryTimer:void 0,iframe:null,container:null,bubble:null,bubbleWrapper:null,sideTab:null,contextMenu:null,backdrop:null,iframeWrapper:null,positionSetByDataAttr:!1};function Ee(){return{botId:void 0,locale:void 0,theme:void 0,mode:"bubble",position:"bottom-right",zIndex:ve,iframeUrl:K,parentOrigin:window.location.origin,apiEndpoints:void 0}}
17function Ce(){if(typeof performance>"u")return!1;try{const e=performance.getEntriesByType("navigation");if(e.length>0){const t=e[0];if(t.type==="reload")return!0;if(t.type==="navigate")try{const o=sessionStorage.getItem("taros_last_url"),i=window.location.href;if(sessionStorage.setItem("taros_last_url",i),o===i)return!0}catch{}}}catch{}return!1}const ke=Ce();function Le(){return typeof crypto<"u"&&"randomUUID"in crypto?crypto.randomUUID():`${Date.now().toString(36)}-${Math.random().toString(16).slice(2)}`}function oe(e){if(!e)return[];let t=[];if(Array.isArray(e))t=e.map(r=>typeof r=="string"?r:String(r));else{const r=e.trim();if(!r)return[];if(r.startsWith("[")&&r.endsWith("]")||r.startsWith("{"))try{const a=JSON.parse(r);Array.isArray(a)&&(t=a.map(s=>typeof s=="string"?s:String(s)))}catch{}t.length===0&&(t=r.split(/[\s,]+/).map(a=>a.trim()))}const o=new Set,i=[];for(const r of t){if(!r)continue;let a=r;try{const s=new URL(r,window.location.href);a=s.origin+s.pathname}catch{try{const s=new URL(r);a=s.origin+s.pathname}catch{continue}}a=a.replace(/\/+$/,""),o.has(a)||(o.add(a),i.push(a))}return i}function Te(e){if(e)try{const t=new URL(e.src,window.location.href),o=`${t.hostname}${t.port?`:${t.port}`:""}`;if(o==="localhost:5173"||o==="127.0.0.1:5173")return[t.hostname==="127.0.0.1"?"http://127.0.0.1:3000":"http://localhost:3000"];if((t.hostname==="localhost"||t.hostname==="127.0.0.1")&&!t.port)return["http://localhost:3000"]}catch{}}function Se(){if(!(typeof document>"u"))try{const t=new URL(n.config.iframeUrl).origin;if(Q.has(t))return;const o=document.head;if(!o)return;const i=(r,a,s)=>{if(o.querySelector(`link[rel="${r}"][href="${a}"][data-taros-loader="hint"]`))return;const c=document.createElement("link");c.rel=r,c.href=a,c.dataset.tarosLoader="hint",s&&s(c),o.appendChild(c)};i("preconnect",t,r=>{r.crossOrigin="anonymous"}),i("dns-prefetch",t),Q.add(t)}catch(e){u("Unable to warm widget origin",e)}}function _(e){try{const t=new URL(e),o=`${t.protocol}//${t.hostname.toLowerCase()}${t.port?`:${t.port}`:""}`;return{raw:e,canonical:o}}catch{return}}function ie(){try{const e=new URL(n.config.iframeUrl);return _(e.origin)}catch{return}}function re(){const e=ie();e&&(n.expectedOrigin=e)}function Ie(e){if(e==="null")return typeof{url:typeof document>"u"&&typeof location>"u"?require("url").pathToFileURL(__filename).href:typeof document>"u"?location.href:b&&b.tagName.toUpperCase()==="SCRIPT"&&b.src||new URL("widget.js",document.baseURI).href}<"u"&&!1?(u(" Allowing null origin for development"),!0):!1;const t=_(e);if(!t)return!1;const o=ie();if(o){const i=new URL(o.raw),r=new URL(e),a=i.hostname,s=r.hostname;if(a===s&&i.protocol===r.protocol)return n.expectedOrigin=t,!0;const l=[a,`www.${a}`,`widgets.${a}`];if(a.startsWith("www.")){const c=a.slice(4);l.push(c,`widgets.${c}`)}if(a.startsWith("widgets.")){const c=a.slice(8);l.push(c,`www.${c}`)}if(l.includes(s)&&i.protocol===r.protocol)return n.expectedOrigin=t,!0}return n.expectedOrigin?n.expectedOrigin.canonical===t.canonical?(n.expectedOrigin.raw!==t.raw&&(n.expectedOrigin=t),!0):o&&o.canonical===t.canonical?(n.expectedOrigin=t,!0):!1:!o||o.canonical===t.canonical?(n.expectedOrigin=t,!0):!1}async function Oe(){const e=Re();if(Ae(e),(n.config.loaderScriptSrc?.includes("experimental")||typeof window<"u"&&window.location.hostname.includes("experimental"))&&n.config.iframeUrl===K&&(n.config.iframeUrl="https://experimentalwidgets.taros.ai/iframe"),window.addEventListener("message",ue,!1),Se(),!n.config.botId){u(" Missing botId, activating fallback"),k("missing_bot_id");return}if(!await Me()){u(" Widget disabled, not rendering");return}We(),n.config.mode==="bubble"?(_e(),X()):(u(" Creating inline iframe"),Y())}async function Me(){if(!n.config.botId)return!0;const t=n.config.loaderScriptSrc?.includes("experimental")||n.config.iframeUrl.includes("experimental")||typeof window<"u"&&window.location.hostname.includes("experimental")?"https://experimental.taros.ai":"https://taros.ai";try{const o=new AbortController,i=setTimeout(()=>o.abort(),5e3),r=await fetch(`${t}/api/widgets/bots/${n.config.botId}/config`,{signal:o.signal,headers:{"X-Taros-Embedding-Origin":n.config.parentOrigin,"X-Taros-Embedding-Page-Url":window.location.href}});if(clearTimeout(i),!r.ok){if(r.status===404)return u("Bot not found, not showing widget"),!1;if(r.status===403)try{if((await r.json()).disabled)return u("Bot is disabled, not showing widget"),!1}catch{}return u("Failed to fetch widget config",r.status),!0}const a=await r.json();if(!a.success||!a.data)return u("Invalid widget config response",a),!0;const s=a.data;s.mode&&!n.config.mode&&(n.config.mode=s.mode),s.position&&j(s.position)&&!n.positionSetByDataAttr&&(n.config.position=s.position),s.theme&&(n.config.theme=s.theme),s.language&&(n.config.language=s.language);const l=n.config.language;return l&&l!=="auto"?A=l:A="en",u("Applied config from API",{mode:n.config.mode,hasTheme:!!n.config.theme,language:A}),!0}catch(o){return u("Error fetching widget config",o),!0}}function Re(){const e=document.currentScript;return e instanceof HTMLScriptElement?e:Array.from(document.getElementsByTagName("script")).reverse().find(o=>o.dataset.bot)??null}function D(e){if(n.minimized=e,n.bubbleWrapper&&(n.bubbleWrapper.style.transform=e?"scale(0.8)":"scale(1)",n.bubbleWrapper.style.opacity=e?"0":"1",n.bubbleWrapper.style.pointerEvents=e?"none":"auto"),n.sideTab){const o=(n.config.position??"bottom-right").includes("left");n.sideTab.style.transform=e?"translateX(0)":`translateX(${o?"-100%":"100%"})`,n.sideTab.style.opacity=e?"1":"0",n.sideTab.style.pointerEvents=e?"auto":"none"}}function Ae(e){if(!e)return;const{dataset:t}=e;
17if(e.src){n.config.loaderScriptSrc=e.src;try{const r=new URL(e.src).searchParams.get("botId");r&&(n.config.botId=r.trim())}catch{}}if(t.bot&&(n.config.botId=t.bot.trim()),t.locale&&(n.config.locale=t.locale.trim()),t.theme)try{n.config.theme=JSON.parse(t.theme)}catch(i){u("Failed to parse data-theme JSON",i)}(t.mode==="inline"||t.mode==="bubble")&&(n.config.mode=t.mode);const o=t.position;if(o&&j(o)&&(n.config.position=o,n.positionSetByDataAttr=!0),t.z){const i=Number(t.z);Number.isNaN(i)||(n.config.zIndex=i)}if(t.src)try{const i=new URL(t.src,window.location.href);n.config.iframeUrl=i.toString(),re()}catch(i){u("Invalid data-src value",i)}if(t.configEndpoint){const i=oe(t.configEndpoint);i.length>0&&(n.config.apiEndpoints=i)}if(!n.config.apiEndpoints||n.config.apiEndpoints.length===0){const i=Te(e);i&&i.length>0&&(n.config.apiEndpoints=i)}}function j(e){return e==="top-left"||e==="top-right"||e==="bottom-left"||e==="bottom-right"}function se(){return n.config.botId?`${xe}:${n.config.botId}`:null}function Be(){if(n.positionSetByDataAttr)return null;const e=se();if(!e)return null;try{const t=window.localStorage.getItem(e);if(t&&j(t))return t}catch{}return null}function ze(e){const t=se();if(t)try{window.localStorage.setItem(t,e)}catch{}}function We(){const e=Be();e&&(n.config.position=e)}function Ue(e){if(n.config.position=e,n.bubbleWrapper){const t=N(e,n.config.theme?.positionOffsetX,n.config.theme?.positionOffsetY);n.bubbleWrapper.style.top="auto",n.bubbleWrapper.style.right="auto",n.bubbleWrapper.style.bottom="auto",n.bubbleWrapper.style.left="auto";for(const[o,i]of Object.entries(t))n.bubbleWrapper.style.setProperty(o,i)}n.container&&W(n.container,O()),n.sideTab&&(n.sideTab.remove(),n.sideTab=null),n.config.theme?.button?.allowHiding&&(ae(),D(n.minimized))}function Pe(e,t,o){let i=null,r=0,a=0,s=!1,l="",c="";const f=()=>{if(window.removeEventListener("pointermove",h),window.removeEventListener("pointerup",L),window.removeEventListener("pointercancel",g),i!==null)try{t.releasePointerCapture(i)}catch{}i=null,s=!1,e.style.transition=l,t.style.cursor=c},h=d=>{if(i===null||d.pointerId!==i)return;const T=d.clientX-r,m=d.clientY-a,st=Math.abs(T)>Z||Math.abs(m)>Z;if(!s&&!st)return;s||(s=!0,e.style.transition="none");const P=n.config.theme,me=P?.button?.size??P?.buttonSize??60,J=P?.positionOffsetX??20,at=P?.positionOffsetY??20,lt=Math.max(J,window.innerWidth-me-J),ct=Math.min(lt,Math.max(J,d.clientX-me/2));e.style.left=`${Math.round(ct)}px`,e.style.right="auto",e.style.top="auto",e.style.bottom=`${at}px`,d.preventDefault()},C=d=>{const m=d<window.innerWidth/2?"bottom-left":"bottom-right";Ue(m),ze(m),o()},L=d=>{if(i===null||d.pointerId!==i)return;const T=s,m=d.clientX;f(),T&&(C(m),d.preventDefault())},g=d=>{i===null||d.pointerId!==i||f()};t.addEventListener("pointerdown",d=>{if(!(n.open||n.minimized)&&d.button===0){i=d.pointerId,r=d.clientX,a=d.clientY,s=!1,l=e.style.transition,c=t.style.cursor,t.style.cursor="grabbing";try{t.setPointerCapture(d.pointerId)}catch{}window.addEventListener("pointermove",h),window.addEventListener("pointerup",L),window.addEventListener("pointercancel",g)}})}function _e(){const e=n.config.theme?.button;let t=!1;const o=document.createElement("div");o.setAttribute("data-taros","bubble-wrapper"),o.style.cssText=je(),o.style.transition="transform 0.3s cubic-bezier(0.34, 1.56, 0.64, 1), opacity 0.2s ease";const i=document.createElement("button");i.type="button",i.setAttribute("data-taros","bubble"),i.setAttribute("aria-label",S("openChat")),i.style.cssText=Ne(),i.innerHTML=Ye(),n.bubble=i,Ge(i),Pe(o,i,()=>{t=!0}),o.appendChild(i);let r=null;e?.showLabel&&e?.label&&(r=He(e),o.appendChild(r)),e?.allowHiding&&i.addEventListener("contextmenu",l=>{l.preventDefault(),De(l.clientX,l.clientY)}),n.bubbleWrapper=o,z(),i.addEventListener("click",l=>{if(t){t=!1,l.preventDefault();return}n.open?x("user"):M("user")}),i.addEventListener("mouseenter",X),i.addEventListener("focus",X);const a=()=>{!n.minimized&&!n.open&&(i.style.transform="scale(1.05)"),i.dispatchEvent(new MouseEvent("mouseenter",{bubbles:!1}))},s=()=>{n.minimized||(i.style.transform="scale(1)"),i.dispatchEvent(new MouseEvent("mouseleave",{bubbles:!1}))};i.addEventListener("mouseenter",a),i.addEventListener("mouseleave",s),r&&(r.addEventListener("mouseenter",a),r.addEventListener("mouseleave",s),r.addEventListener("click",()=>{n.open?x("user"):M("user")})),Xe(o),document.body.appendChild(o),e?.allowHiding&&ae(),document.addEventListener("click",()=>H())}function De(e,t){H();const o=document.createElement("div"),i=140,r=40,a=window.innerWidth,s=window.innerHeight;let l=e,c=t;e+i>a-10&&(l=e-i),t+r>s-10&&(c=t-r-10),l=Math.max(10,l),c=Math.max(10,c),o.style.cssText=["position:fixed",`left:${l}px`,`top:${c}
17px`,"background:#fff","border:1px solid #e2e8f0","border-radius:8px","box-shadow:0 10px 15px -3px rgba(0, 0, 0, 0.1), 0 4px 6px -2px rgba(0, 0, 0, 0.05)","z-index:2147483647","min-width:120px","padding:4px","display:flex","flex-direction:column","animation:tarosFadeIn 0.1s ease-out"].join(";");const f=document.createElement("button");f.textContent=S("hideWidget"),f.style.cssText=["text-align:left","background:transparent","border:none","padding:8px 12px","font-size:14px","color:#1e293b","cursor:pointer","border-radius:4px","display:flex","align-items:center","gap:8px","width:100%"].join(";"),f.addEventListener("mouseenter",()=>{f.style.background="#f1f5f9"}),f.addEventListener("mouseleave",()=>{f.style.background="transparent"}),f.addEventListener("click",h=>{h.stopPropagation(),D(!0),H()}),o.appendChild(f),document.body.appendChild(o),n.contextMenu=o}function H(){n.contextMenu&&(n.contextMenu.remove(),n.contextMenu=null)}function ae(){const e=v(),t=le(e),o=document.createElement("div"),i=n.config.position??"bottom-right",r=i.includes("right"),a=i.includes("bottom"),s=60,l=6,c=36,f=n.config.theme?.positionOffsetX??20,h=n.config.theme?.positionOffsetY??20,C=a?`bottom:${h+10}px`:`top:${h+10}px`,L=r?`right:${f}px`:`left:${f}px`,g="12px",d=r?`${g} 0 0 ${g}`:`0 ${g} ${g} 0`;o.style.cssText=["position:fixed",C,L,`width:${l}px`,`height:${s}px`,`background:${e}`,`color:${t}`,`z-index:${n.config.zIndex}`,`border-radius:${d}`,"box-shadow: 0 4px 12px rgba(0,0,0,0.15)","cursor:pointer","display:flex","align-items:center","justify-content:center","transition:transform 0.3s cubic-bezier(0.34, 1.56, 0.64, 1), opacity 0.2s ease, width 0.2s ease, background-color 0.2s",`transform:translateX(${r?"100%":"-100%"})`,"opacity:0","pointer-events:none","overflow:hidden"].join(";");const T=r?'<svg viewBox="0 0 24 24" width="20" height="20" fill="none" stroke="currentColor" stroke-width="2.5" stroke-linecap="round" stroke-linejoin="round" style="opacity:0;transition:opacity 0.2s"><path d="M15 18l-6-6 6-6"/></svg>':'<svg viewBox="0 0 24 24" width="20" height="20" fill="none" stroke="currentColor" stroke-width="2.5" stroke-linecap="round" stroke-linejoin="round" style="opacity:0;transition:opacity 0.2s"><path d="M9 18l6-6-6-6"/></svg>';o.innerHTML=T,o.addEventListener("mouseenter",()=>{if(!n.minimized)return;o.style.width=`${c}px`,o.style.opacity="1";const m=o.querySelector("svg");m&&(m.style.opacity="1")}),o.addEventListener("mouseleave",()=>{if(!n.minimized)return;o.style.width=`${l}px`,o.style.opacity="0.6";const m=o.querySelector("svg");m&&(m.style.opacity="0")}),o.addEventListener("click",()=>{D(!1)}),n.sideTab=o,document.body.appendChild(o)}function je(){const e=n.config.theme,o=e?.button?.size??e?.buttonSize??60,i=Object.entries(N(n.config.position,e?.positionOffsetX,e?.positionOffsetY)).map(([r,a])=>`${r}:${a}`).join(";");return["position:fixed",`z-index:${n.config.zIndex}`,`width:${o}px`,`height:${o}px`,"pointer-events:none",i].join(";")}function He(e){const t=document.createElement("div");t.setAttribute("data-taros","bubble-label");const o=e.labelOffsetX??0,i=e.labelOffsetY??0,r=e.labelPosition??"bottom",a=e.labelShape??"pill",s=e.labelBackgroundColor??v(),l=e.labelTextColor??"#ffffff",c=()=>{switch(a){case"rounded":return"8px";case"square":return"4px";case"speech":return"8px";default:return"9999px"}};let f=["position:absolute","white-space:nowrap"];switch(r){case"top":f.push("bottom:100%","left:50%","margin-bottom:8px");break;case"bottom":f.push("top:100%","left:50%","margin-top:8px");break;case"left":f.push("right:100%","top:50%","margin-right:8px");break;case"right":f.push("left:100%","top:50%","margin-left:8px");break}let h="";r==="left"||r==="right"?h=`translateY(calc(-50% + ${i}px)) translateX(${o}px)`:h=`translateX(calc(-50% + ${o}px)) translateY(${i}px)`,t.style.cssText=[...f,"pointer-events:auto","cursor:pointer",`transform:${h}`].join(";");const C=document.createElement("div");C.style.cssText=[`background:${s}`,`color:${l}`,"padding:4px 10px",`border-radius:${c()}`,"font-size:11px","font-weight:500","font-family:system-ui, -apple-system, sans-serif","box-shadow:0 2px 8px rgba(0,0,0,0.15)","white-space:nowrap"].join(";"),C.textContent=e.label??"";const L=a==="speech",g=a==="speech"?10:6,d=document.createElement("div");switch(L?d.style.cssText=["position:absolute",`width:${g}px`,`height:${g}px`,`background:${s}`,"transform:rotate(45deg)"].join(";"):d.style.display="none",r){case"left":d.style.right="-3px",d.style.top="50%",d.style.marginTop=`-${g/2}px`;break;case"right":d.style.left="-3px",d.style.top="50%",d.style.marginTop=`-${g/2}px`;break;case"top":d.style.bottom="-3px",d.style.left="50%",d.style.marginLeft=`-${g/2}px`;break;default:d.style.top="-3px",d.style.left="50%",d.style.marginLeft=`-${g/2}px`;break}return t.appendChild(C),t.appendChild(d),t.addEventListener("click",()=>{n.open?x("user"):M("user")}),t}function Xe(e){const t=n.config.theme?.entranceAnimation;if(t?.enabled===!1)return;const o=t?.type??"slideUp",i=t?.duration??.3,r=t?.delay??0,s={fadeIn:"translate3d(0,
170,0)",slideUp:"translate3d(0,20px,0)",slideDown:"translate3d(0,-20px,0)",slideLeft:"translate3d(20px,0,0)",slideRight:"translate3d(-20px,0,0)",bounceIn:"scale(0.3)"}[o]||"translate3d(0,20px,0)";e.style.opacity="0",e.style.transform=s,e.style.transition=`opacity ${i}s ease, transform ${i}s ease`,setTimeout(()=>{e.style.opacity="1",e.style.transform="translate3d(0,0,0) scale(1)"},r*1e3)}function X(){if(!n.iframe){if(n.destroyed||n.fallbackActive){console.debug("TarosChat: Widget destroyed or fallback active, skipping warmup");return}Y()}}function Ne(){const e=n.config.theme,t=e?.button,o=F(),i=ce(),{base:r}=V(),a=e?.animation?.duration??.2,s=t?.size??e?.buttonSize??60;let l;return t?.shape?l=ye(t.shape):l=e?.buttonBorderRadius??9999,["position:relative",`width:${s}px`,`height:${s}px`,"padding:0",`border:${t?.borderColor?`1px solid ${t.borderColor}`:"none"}`,`border-radius:${l}px`,"display:flex","align-items:center","justify-content:center","cursor:pointer","pointer-events:auto",`background:${o}`,`color:${i}`,`box-shadow:${r}`,`transition:transform ${a}s ease, box-shadow 0.2s ease, background-color 0.2s ease, color 0.2s ease, border-color 0.2s ease`,"line-height:1","font-size:0","outline:none","will-change:transform","transform:translate3d(0,0,0) scale(1)"].join(";")}function N(e,t,o){const i=`${t??20}px`,r=`${o??20}px`;switch(e){case"top-left":return{top:r,left:i};case"top-right":return{top:r,right:i};case"bottom-left":return{bottom:r,left:i};default:return{bottom:r,right:i}}}function w(e){if(typeof e!="string")return null;let t=e.trim();return t?(t.startsWith("#")||(t=`#${t}`),/^#([0-9a-fA-F]{6})$/.test(t)?t.toLowerCase():null):null}function B(e){if(!/^#([0-9a-fA-F]{6})$/.test(e))return null;const t=parseInt(e.slice(1),16),o=t>>16&255,i=t>>8&255,r=t&255;return{r:o,g:i,b:r}}function le(e){const t=B(e);return t&&(t.r*299+t.g*587+t.b*114)/1e3>=128?"#000000":"#ffffff"}function I(e,t,o){const i=B(e),r=B(t);if(!i||!r)return e;const a=Math.max(0,Math.min(1,o)),s=(l,c)=>Math.round(l+(c-l)*a).toString(16).padStart(2,"0");return`#${s(i.r,r.r)}${s(i.g,r.g)}${s(i.b,r.b)}`}function q(e,t){const o=B(e);if(!o)return`rgba(15,23,42,${Math.max(0,Math.min(1,t))})`;const i=Math.max(0,Math.min(1,t));return`rgba(${o.r},${o.g},${o.b},${i})`}function v(){const e=w(n.config.theme?.brandColor);if(e)return e;const t=typeof window<"u"?getComputedStyle(document.documentElement).getPropertyValue("--taros-color-brand").trim():"",o=w(t);return o||"#198754"}function F(){const e=n.config.theme,t=e?.button;if(t?.backgroundColor){const r=w(t.backgroundColor);if(r){if(t.useGradient!==!1){const a=w(t.gradientStart),s=w(t.gradientEnd);return a&&s?`linear-gradient(135deg, ${a}, ${s})`:`linear-gradient(135deg, ${I(r,"#ffffff",.24)}, ${r})`}return r}}const o=v(),i=e?.gradientStrength??100;if(i===0)return o;{const r=w(e?.brandGradientStart),a=w(e?.brandGradientEnd);return r&&a?`linear-gradient(135deg, ${r}, ${a})`:`linear-gradient(135deg, ${I(o,"#ffffff",.24*(i/100))}, ${o})`}}function qe(){const e=v(),t=I(e,"#ffffff",.8),o=I(e,"#ffffff",.6);return`radial-gradient(circle at 30% 30%, ${t}, ${o})`}function ce(){const e=n.config.theme?.button;if(e?.dynamicColors){const t=F(),o=/#([0-9a-fA-F]{6})/.exec(t);if(o)return le(o[0])}return e?.iconColor??"#ffffff"}function Fe(){return v()}function Ve(){return I(v(),"#ffffff",.7)}function V(){const e=n.config.theme?.shadow;if(!e?.enabled)return{base:"none",hover:"none",active:"none"};const t=w(e.color)||v(),o=e.blur??26,i=e.opacity??.34,r=e.offsetX??0,a=e.offsetY??12,s=n.config.theme?.button,l=s?.glow?`0 0 15px ${s.borderColor||v()}, `:"",c=`${l}${r}px ${a}px ${o}px ${q(t,i)}`,f=`${l}${r}px ${a+4}px ${o+10}px ${q(t,i+.04)}`,h=`${l}${r}px ${a-4}px ${Math.max(o-8,0)}px ${q(t,i-.02)}`;return{base:c,hover:f,active:h}}function Ye(){const e=n.config.theme?.button;if(e?.useCustomImage&&e?.customImageUrl)return` 18 <img 19 src="${e.customImageUrl}" 20 alt="Chat" 21 style="width:100%;height:100%;object-fit:cover;border-radius:inherit;" 22 data-icon="custom-image" 23 /> 24 `;const t=e?.icon??"chat";let o;return t==="custom"&&e?.customIconUrl?o=`<img src="${e.customIconUrl}" alt="" style="width:32px;height:32px;object-fit:contain;" />`:o=be(t,32),` 25 <span style="position:absolute;inset:0;display:flex;align-items:center;justify-content:center;">
26 <span data-icon="closed" aria-hidden="true" style="position:absolute;display:flex;align-items:center;justify-content:center;width:32px;height:32px;pointer-events:none;transition:opacity 0.18s ease, transform 0.18s ease;transform:scale(1);opacity:1;"> 27 ${o} 28 </span> 29 <span data-icon="opened" aria-hidden="true" style="position:absolute;display:flex;align-items:center;justify-content:center;width:32px;height:32px;pointer-events:none;transition:opacity 0.18s ease, transform 0.18s ease;transform:scale(0.75);opacity:0;"> 30 <svg viewBox="0 0 24 24" width="28" height="28" role="img" aria-hidden="true" focusable="false" fill="none"> 31 <circle cx="12" cy="12" r="9" stroke="currentColor" stroke-opacity="0.35" stroke-width="1.6"></circle> 32 <path d="M7.2 12h9.6" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round"></path> 33 </svg> 34 </span> 35 </span> 36 `}function Ge(e){const t=n.config.theme?.animation,o=t?.enabled??!0,i=t?.type??"scale",r=t?.duration??.2,s=(()=>{if(!o||i==="none")return{base:"translate3d(0,0,0)",hover:"translate3d(0,0,0)",active:"translate3d(0,0,0)"};switch(i){case"scale":return{base:"translate3d(0,0,0) scale(1)",hover:"translate3d(0,-1px,0) scale(1.05)",active:"translate3d(0,1px,0) scale(0.96)"};case"bounce":return{base:"translate3d(0,0,0) scale(1)",hover:"translate3d(0,-4px,0) scale(1.02)",active:"translate3d(0,2px,0) scale(0.98)"};case"pulse":return{base:"translate3d(0,0,0) scale(1)",hover:"translate3d(0,0,0) scale(1.08)",active:"translate3d(0,0,0) scale(0.94)"};case"shake":return{base:"translate3d(0,0,0)",hover:"translate3d(2px,0,0)",active:"translate3d(-1px,0,0)"};case"rotate":return{base:"translate3d(0,0,0) rotate(0deg)",hover:"translate3d(0,0,0) rotate(5deg)",active:"translate3d(0,0,0) rotate(-2deg)"};default:return{base:"translate3d(0,0,0) scale(1)",hover:"translate3d(0,-1px,0) scale(1.05)",active:"translate3d(0,1px,0) scale(0.96)"}}})(),l=()=>V();e.style.transition=`transform ${r}s ease, box-shadow 0.2s ease, background-color 0.2s ease, color 0.2s ease, border-color 0.2s ease`;const c=()=>{e.style.boxShadow=l().base,e.style.transform=s.base},f=()=>{e.style.boxShadow=l().hover,e.style.transform=s.hover};e.addEventListener("mouseenter",f),e.addEventListener("mouseleave",c),e.addEventListener("focus",f),e.addEventListener("blur",c),e.addEventListener("mousedown",()=>{e.style.boxShadow=l().active,e.style.transform=s.active}),e.addEventListener("mouseup",()=>{f()}),c()}function z(){const e=n.bubble;if(!e)return;const t=n.open;e.setAttribute("aria-label",S(t?"closeChat":"openChat")),e.setAttribute("data-open",t?"true":"false");const o=F(),i=qe(),r=ce(),a=Fe(),s=Ve();e.style.background=t?i:o,e.style.color=t?a:r,e.style.borderColor=t?s:"transparent",e.style.boxShadow=V().base;const l=e.querySelector('[data-icon="closed"]'),c=e.querySelector('[data-icon="opened"]');l&&c&&(l.style.opacity=t?"0":"1",l.style.transform=t?"scale(0.75) rotate(-4deg)":"scale(1) rotate(0deg)",c.style.opacity=t?"1":"0",c.style.transform=t?"scale(1) rotate(0deg)":"scale(0.75) rotate(4deg)")}function Je(){if(n.backdrop)return n.backdrop;const e=document.createElement("div");return e.style.cssText=["position:fixed","top:0","left:0","width:100vw","height:100vh",`z-index:${n.config.zIndex-1}`,"background:transparent","opacity:0","pointer-events:none","transition:opacity 0.24s ease"].join(";"),e.addEventListener("click",()=>x("user")),e.addEventListener("keydown",t=>{t.key==="Escape"&&x("escape")}),document.body.appendChild(e),n.backdrop=e,e}function O(){const e=window.innerWidth,t=window.innerHeight;if(e<=768)return{width:e,height:t,fullscreen:!0};let o,i;return e<=1024?(o=Math.min(480,e-32),i=Math.min(620,t-64)):(o=Math.min(520,e-64),i=Math.min(720,t-80)),{width:o,height:i,fullscreen:!1}}function W(e,t){const o=n.config.theme?.windowBorderRadius??24;if(t.fullscreen)e.style.cssText=["position:fixed","inset:0",`z-index:${n.config.zIndex}`,"display:none","pointer-events:none","width:100vw","height:100vh","height:100dvh","background:transparent","margin:0","padding:0","box-sizing:border-box","overflow:hidden","border-radius:0","transform:scale(1)","transition:none"].join(";");else{const i=n.config.position??"bottom-right",r=i.includes("left"),s=`${i.includes("top")?"top":"bottom"}
36 ${r?"left":"right"}`;e.style.cssText=["position:fixed",`z-index:${n.config.zIndex}`,"display:none","pointer-events:none",...Object.entries(N(n.config.position)).map(([l,c])=>`${l}:${c}`),`width:${t.width}px`,`height:${t.height}px`,"background:transparent","margin:0","padding:0","box-sizing:border-box","overflow:hidden","box-shadow:0 28px 60px rgba(15,23,42,0.35)",`border-radius:${o}px`,`transform-origin:${s}`,"transform:scale(0.98)","transition:transform 0.24s ease"].join(";")}e.dataset.tarosFullscreen=t.fullscreen?"true":"false"}function Ke(e,t){const o=n.config.theme?.windowBorderRadius??24;e.style.borderRadius=t.fullscreen?"0":`${o}px`}function de(){const e=O();if(n.container)return W(n.container,e),n.container;const t=document.createElement("div");W(t,e),document.body.appendChild(t),n.container=t;let o;const i=()=>{n.open&&(o&&window.clearTimeout(o),o=window.setTimeout(()=>{if(!n.open)return;const r=n.lastOpenPayload??te;x("api","window_resized"),requestAnimationFrame(()=>{n.destroyed||n.fallbackActive||n.open||M(r.source,{focus:r.focus})})},150))};return window.addEventListener("resize",i),t}function Y(){if(n.iframe||n.destroyed||n.fallbackActive)return n.iframe;tt(),p.emit("state",{status:"connecting",details:"Creating iframe"});const e=de();e.innerHTML="";const t=document.createElement("iframe");t.title=S("chatTitle"),t.setAttribute("role","region"),t.setAttribute("aria-live","polite");const o=["allow-scripts","allow-forms","allow-popups","allow-downloads","allow-same-origin"];try{const s=new URL(n.config.iframeUrl);if(s.pathname==="/"&&!s.hostname.includes("widgets")&&(u("Widget iframe URL appears to be main website, this may cause issues"),!s.hostname.includes("localhost")))return k("invalid_widget_url"),null;const l=_(s.origin);l&&(n.expectedOrigin=l),e.appendChild(t),n.iframe=t,n.handshakeInitiated=!1,n.handshakeComplete=!1,t.src=s.toString()}catch{return k("invalid_iframe_url"),null}const i=o.join(" ");t.setAttribute("sandbox",i),t.setAttribute("allow","fullscreen; autoplay; clipboard-write; microphone; camera"),t.setAttribute("loading","eager"),t.setAttribute("referrerpolicy","strict-origin-when-cross-origin");const r=n.config.theme?.windowBorderRadius??24,a=O();return t.style.cssText=["position:relative","width:100%","height:100%","border:none","background:transparent",`border-radius:${a.fullscreen?"0":r+"px"}`,"margin:0","padding:0","display:block","overflow:hidden"].join(";"),t.addEventListener("load",()=>{p.emit("state",{status:"connecting",details:"Iframe loaded, waiting for widget"})}),t}function M(e="api",t={}){if(n.destroyed)return;if(n.fallbackActive){pe();return}const o=O(),i=t.focus??!0,r=de();W(r,o);const a=Y();if(a&&Ke(a,o),r.style.display="block",r.style.pointerEvents="auto",!o.fullscreen){const s=Je();requestAnimationFrame(()=>{r.style.transform="scale(1)",s.style.opacity="1",s.style.pointerEvents="auto"})}n.open=!0,n.lastOpenPayload={source:e,focus:i},n.bubbleWrapper&&(n.bubbleWrapper.style.display="none"),z(),p.emit("opened",void 0),U({type:"OPEN",version:y,nonce:n.nonce,payload:{source:e,focus:i}})}function x(e="api",t){if(n.destroyed)return;const o=n.container,i=O();o&&(o.style.pointerEvents="none",o.style.display="none",i.fullscreen||(o.style.transform="scale(0.98)")),!i.fullscreen&&n.backdrop&&(n.backdrop.style.opacity="0",n.backdrop.style.pointerEvents="none"),n.open=!1,n.lastOpenPayload=void 0,n.bubbleWrapper&&(n.bubbleWrapper.style.display="flex"),z(),p.emit("closed",t?{reason:t}:void 0),U({type:"CLOSE",version:y,nonce:n.nonce,payload:{source:e,reason:t}})}function Ze(){if(n.destroyed)return;n.destroyed=!0,n.initRetryTimer!=null&&(window.clearTimeout(n.initRetryTimer),n.initRetryTimer=void 0),window.removeEventListener("message",ue),n.iframe?.remove(),n.container?.remove(),n.backdrop?.remove(),n.bubbleWrapper?.remove(),n.iframe=null,n.container=null,n.backdrop=null,n.bubble=null,n.bubbleWrapper=null;const e=window;delete e[R],p.emit("closed",{reason:"destroy"})}function Qe(e){n.destroyed||n.fallbackActive||U({type:"USER_MESSAGE",version:y,nonce:n.nonce,payload:e})}function U(e){const t=n.iframe?.contentWindow,o=n.expectedOrigin?.raw;if(!t||!n.handshakeComplete){n.queuedMessages.push(e);return}const i=o==="null"?"*":o||"*";
36try{t.postMessage(e,i)}catch(r){u("postMessage failed",r)}}function et(){if(!n.handshakeComplete||!n.iframe?.contentWindow)return;const{contentWindow:e}=n.iframe,t=n.expectedOrigin?.raw,o=t==="null"?"*":t||"*";for(;n.queuedMessages.length>0;){const i=n.queuedMessages.shift();if(!i)break;e.postMessage(i,o)}}function fe(){if(n.handshakeComplete)return;const e=n.iframe?.contentWindow,t=n.expectedOrigin?.raw;if(!e||!t){G();return}if(!n.config.botId){u(" Missing botId, activating fallback"),k("missing_bot_id");return}const o={botId:n.config.botId,parentOrigin:n.config.parentOrigin,parentHref:window.location.href,locale:n.config.locale,theme:n.config.theme,mode:n.config.mode,configEndpoints:n.config.apiEndpoints&&n.config.apiEndpoints.length>0?[...n.config.apiEndpoints]:void 0,nonce:n.nonce,loaderVersion:we,protocolVersion:y,isPageReload:ke};try{const i=t==="null"?"*":t;e.postMessage({type:"INIT",version:y,nonce:n.nonce,payload:o},i),n.handshakeInitiated=!0}catch(i){u(" Failed to send INIT",i)}}let E=0;function tt(){E=0}function G(){if(n.handshakeComplete||n.initRetryTimer!=null)return;if(E>=10){u(" Max retries reached (10 attempts), stopping");return}let e;E===0?e=3e4:e=Math.min(1e3*Math.pow(2,E-1),6e4),console.debug(`TarosChat: Scheduling retry attempt ${E+2} with delay ${e}ms`),n.initRetryTimer=window.setTimeout(()=>{n.initRetryTimer=void 0,!n.handshakeComplete&&(E++,console.debug(`TarosChat: Init attempt ${E+1} (after ${e}ms delay)`),fe(),n.handshakeComplete||G())},e)}function ue(e){const t=n.iframe?.contentWindow;if(!t||e.source!==t||!Ie(e.origin))return;const o=e.data;if(!o||typeof o!="object")return;if(o.type==="READY"){nt(o);return}if(o.nonce===n.nonce)switch(o.type){case"ACK":ot(o.payload);break;case"BOT_MESSAGE":p.emit("message",o.payload);break;case"STATE":{const r=o.payload;r?.details==="closed_by_user"&&x("user","closed_by_user"),p.emit("state",r);break}case"ERROR":it(o.payload);break}}function nt(e){if(!Array.isArray(e.supportedVersions)||!e.supportedVersions.includes(y)){k("incompatible_version"),p.emit("error",{code:"incompatible_version",message:"Widget does not support this loader protocol version.",recoverable:!1,context:"loader"});return}if(p.emit("state",{status:"connecting",details:"Widget ready, starting handshake"}),(n.handshakeComplete||n.handshakeInitiated)&&(n.handshakeComplete=!1,n.handshakeInitiated=!1,n.initRetryTimer!=null&&(window.clearTimeout(n.initRetryTimer),n.initRetryTimer=void 0),n.open)){n.queuedMessages=n.queuedMessages.filter(i=>i.type!=="OPEN");const o=n.lastOpenPayload??te;U({type:"OPEN",version:y,nonce:n.nonce,payload:{...o}})}n.handshakeInitiated=!0,fe(),setTimeout(()=>{n.handshakeComplete||G()},500)}function ot(e){n.handshakeComplete=!0,n.initRetryTimer!=null&&(window.clearTimeout(n.initRetryTimer),n.initRetryTimer=void 0),n.queuedMessages=n.queuedMessages.filter(t=>t.type!=="INIT"),et(),p.emit("state",{status:"ready",details:`Protocol ${e.acceptedVersion}`})}function it(e){p.emit("error",{...e,context:"widget"}),e.recoverable||k(e.code)}function k(e){n.fallbackActive=!0,pe(e),u("Fallback activated",e)}function pe(e="unavailable"){u(`Fallback activated - ${e}`)}const ge={open(){M("api")},close(e){x("api",e)},send(e){Qe(e)},destroy(){Ze()},init(e){if(e.botId&&(n.config.botId=e.botId),e.locale&&(n.config.locale=e.locale),e.theme&&(n.config.theme=e.theme),e.configEndpoints){const t=oe(e.configEndpoints);n.config.apiEndpoints=t.length>0?t:n.config.apiEndpoints}if((e.mode==="inline"||e.mode==="bubble")&&(n.config.mode=e.mode),e.iframeUrl)try{const t=new URL(e.iframeUrl,window.location.href);n.config.iframeUrl=t.toString(),re()}catch(t){u("Invalid iframeUrl passed to init",t)}z(),u("TarosChat.init",n.config)},on(e,t){return p.on(e,t)},once(e,t){return p.once(e,t)},off(e,t){p.off(e,t)}};function rt(){const e=window;e[R]||(e[R]=ge)}function he(){if(ne){u(" Bootstrap already started");return}if(window[R]){u(" Another widget instance already running, cleaning up stale DOM"),document.querySelectorAll("[data-taros]").forEach(t=>t.parentNode?.removeChild(t));return}ne=!0,rt(),Oe().catch(t=>{u("Bootstrap error",t)})}function u(e,t){typeof{url:typeof document>"u"&&typeof location>"u"?require("url").pathToFileURL(__filename).href:typeof document>"u"?location.href:b&&b.tagName.toUpperCase()==="SCRIPT"&&b.src||new URL("widget.js",document.baseURI).href}<"u"&&!1&&console.debug(`TarosChat: ${e}`,t??"")}if(typeof window<"u")if(document.body)he();else{u(" Document body not ready, setting up listeners");const e=()=>document.body?(he(),!0):!1;let t;if(typeof MutationObserver<"u"&&(t=new MutationObserver(()=>{e()&&t&&(t.disconnect(),t=void 0)}),t.observe(document.documentElement,{childList:!0})),document.addEventListener("DOMContentLoaded",()=>{t&&(t.disconnect(),t=void 0),e()},{once:!0}),!t){const o=window.setInterval(()=>{e()&&window.clearInterval(o)},10)}}$.PROTOCOL_VERSION=y,$.default=ge,Object.defineProperties($,{__esModule:{value:!0},[Symbol.toStringTag]:{value:"Module"}})}));
Line numbers count LF bytes from the start of the resource, as the search results do. Vendor segments are library code the classifier recognised; they are stored but not indexed. Bytes are shown as Latin1 characters, one per byte.