(()=>{let t="difyChatbotConfig",u="dify-chatbot-bubble-button",y="dify-chatbot-bubble-window",p=window[t],l=!1,c=` position: absolute; display: flex; flex-direction: column; justify-content: space-between; top: unset; right: var(--${u}-right, 1rem); /* Align with dify-chatbot-bubble-button. */ bottom: var(--${u}-bottom, 1rem); /* Align with dify-chatbot-bubble-button. */ left: unset; width: 30rem; max-width: calc(100vw - 2rem); height: 44rem; max-height: calc(100vh - 6rem); border: none; z-index: 2147483640; overflow: hidden; user-select: none; transition-property: width, height; transition-timing-function: cubic-bezier(0.4, 0, 0.2, 1); transition-duration: 150ms; `;async function e(){let m=!1;if(p&&p.token){var e=new URLSearchParams({...await(async()=>{var e=p?.inputs||{};let n={};return await Promise.all(Object.entries(e).map(async([e,t])=>{n[e]=await i(t)})),n})(),...await(async()=>{var e=p?.systemVariables||{};let n={};return await Promise.all(Object.entries(e).map(async([e,t])=>{n["sys."+e]=await i(t)})),n})()}),o=p.baseUrl||`https://${p.isDev?"dev.":""}udify.app`;let n=new URL(o).origin,t=`${o}/chatbot/${p.token}?`+e;o=s();async function i(e){e=(new TextEncoder).encode(e),e=new Response(new Blob([e]).stream().pipeThrough(new CompressionStream("gzip"))).arrayBuffer(),e=new Uint8Array(await e);return btoa(String.fromCharCode(...e))}function s(){var e=document.createElement("iframe");return e.allow="fullscreen;microphone",e.title="dify chatbot bubble window",e.id=y,e.src=t,e.style.cssText=c,e}function a(){var e,t,n;window.innerWidth<=640||(e=document.getElementById(y),t=document.getElementById(u),e&&t&&(t=t.getBoundingClientRect(),n=window.innerHeight/2,t.top+t.height/2{"className"===e?n.classList.add(...t.split(" ")):"style"===e?"object"==typeof t?Object.assign(n.style,t):n.style.cssText=t:"function"==typeof t?n.addEventListener(e.replace(/^on/,"").toLowerCase(),t):n[e]=t}),n.id=u;var e=document.createElement("style"),e=(document.head.appendChild(e),e.textContent=` #${n.id} { position: fixed; bottom: var(--${n.id}-bottom, 1rem); right: var(--${n.id}-right, 1rem); left: var(--${n.id}-left, unset); top: var(--${n.id}-top, unset); width: var(--${n.id}-width, 40px); height: var(--${n.id}-height, 40px); border-radius: var(--${n.id}-border-radius, 25px); box-shadow: var(--${n.id}-box-shadow, rgba(0, 0, 0, 0.2) 0px 4px 8px 0px); cursor: pointer; z-index: 2147483647; background: linear-gradient(90deg, #eb8698, #1366ec, #eb8698); background-size: 200% 100%; animation: chat-bg-flow 8s ease infinite; } @keyframes chat-bubble-float { 0%, 100% { transform: translateY(0) rotateY(0); opacity: 1; } 5% { transform: translateY(0) rotateY(0); } 20% { transform: translateY(0) rotateY(90deg); } 25% { transform: translateY(0) rotateY(0); } 40% { transform: translateY(-5px) scale(1.2) rotateY(0); opacity: 0.9; } 50% { transform: translateY(0) rotateY(0); } 100% { transform: translateY(0) rotateY(0); } } #openIcon { display: inline-block; animation: chat-bubble-float 4s cubic-bezier(0.2, 0.8, 0.2, 1) infinite; transform-style: preserve-3d; perspective: 1000px; } @keyframes chat-bg-flow { 0% { background-position: 0% 50%; } 50% { background-position: 100% 50%; } 100% { background-position: 0% 50%; } } `,document.createElement("div"));function t(){var e;m||((e=document.getElementById(y))?(e.style.display="none"===e.style.display?"block":"none","none"===e.style.display?h("open"):h("close"),"none"===e.style.display?document.removeEventListener("keydown",b):document.addEventListener("keydown",b),a()):(n.appendChild(s()),a(),this.title="Exit (ESC)",h("close"),document.addEventListener("keydown",b)))}if(e.style.cssText="position: relative; display: flex; align-items: center; justify-content: center; width: 100%; height: 100%; z-index: 2147483647;",e.innerHTML=` `,n.appendChild(e),document.body.appendChild(n),n.addEventListener("click",t),n.addEventListener("touchend",e=>{e.preventDefault(),t()},{passive:!1}),p.draggable){var d=n;var l=p.dragAxis||"both";let s,a,t,r;function o(e){m=!1,r=("touchstart"===e.type?(s=e.touches[0].clientX-d.offsetLeft,a=e.touches[0].clientY-d.offsetTop,t=e.touches[0].clientX,e.touches[0]):(s=e.clientX-d.offsetLeft,a=e.clientY-d.offsetTop,t=e.clientX,e)).clientY,document.addEventListener("mousemove",i),document.addEventListener("touchmove",i,{passive:!1}),document.addEventListener("mouseup",c),document.addEventListener("touchend",c),e.preventDefault()}function i(n){var o="touchmove"===n.type?n.touches[0]:n,i=o.clientX-t,o=o.clientY-r;if(m=8{m=!1},0),d.style.transition="",d.style.cursor="pointer",document.removeEventListener("mousemove",i),document.removeEventListener("touchmove",i),document.removeEventListener("mouseup",c),document.removeEventListener("touchend",c)}d.addEventListener("mousedown",o),d.addEventListener("touchstart",o)}}o.style.display="none",document.body.appendChild(o),2048{if(t.origin===n){let e=document.getElementById(y);if(e&&t.source===e.contentWindow)if("dify-chatbot-iframe-ready"===t.data.type)e.contentWindow?.postMessage({type:"dify-chatbot-config",payload:{isToggledByButton:!0,isDraggable:!!p.draggable}},n);else if("dify-chatbot-expand-change"===t.data.type)r();else if("dify-chatbot-iframe-close"===t.data.type&&e){h("open"),l&&r();let e=document.getElementById(y);e.style.display="none"}}}),document.getElementById(u)||d()}else console.error(t+" is empty or token is not provided")}function h(e="open"){"open"===e?(document.getElementById("openIcon").style.display="block",document.getElementById("closeIcon").style.display="none"):"hidden"===e?(document.getElementById("openIcon").style.display="none",document.getElementById("closeIcon").style.display="none"):(document.getElementById("openIcon").style.display="none",document.getElementById("closeIcon").style.display="block")}function b(e){"Escape"===e.key&&(e=document.getElementById(y))&&"none"!==e.style.display&&(e.style.display="none",h("open"))}document.addEventListener("keydown",b),p?.dynamicScript?e():document.body.onload=e})();