mirror of https://github.com/langgenius/dify.git
fix: refactor SVG icon handling logic and optimize event listener management in embed.js to support mobile browsers #16719 (#16717)
This commit is contained in:
parent
316cb00ada
commit
c285441233
|
@ -14,17 +14,18 @@
|
||||||
const config = window[configKey];
|
const config = window[configKey];
|
||||||
|
|
||||||
// SVG icons for open and close states
|
// SVG icons for open and close states
|
||||||
const svgIcons = {
|
const svgIcons = `<svg id="openIcon" width="24" height="24" viewBox="0 0 24 24" fill="none" xmlns="http://www.w3.org/2000/svg">
|
||||||
open: `<svg id="openIcon" width="24" height="24" viewBox="0 0 24 24" fill="none" xmlns="http://www.w3.org/2000/svg">
|
|
||||||
<path fill-rule="evenodd" clip-rule="evenodd" d="M7.7586 2L16.2412 2C17.0462 1.99999 17.7105 1.99998 18.2517 2.04419C18.8138 2.09012 19.3305 2.18868 19.8159 2.43598C20.5685 2.81947 21.1804 3.43139 21.5639 4.18404C21.8112 4.66937 21.9098 5.18608 21.9557 5.74818C21.9999 6.28937 21.9999 6.95373 21.9999 7.7587L22 14.1376C22.0004 14.933 22.0007 15.5236 21.8636 16.0353C21.4937 17.4156 20.4155 18.4938 19.0352 18.8637C18.7277 18.9461 18.3917 18.9789 17.9999 18.9918L17.9999 20.371C18 20.6062 18 20.846 17.9822 21.0425C17.9651 21.2305 17.9199 21.5852 17.6722 21.8955C17.3872 22.2525 16.9551 22.4602 16.4983 22.4597C16.1013 22.4593 15.7961 22.273 15.6386 22.1689C15.474 22.06 15.2868 21.9102 15.1031 21.7632L12.69 19.8327C12.1714 19.4178 12.0174 19.3007 11.8575 19.219C11.697 19.137 11.5262 19.0771 11.3496 19.0408C11.1737 19.0047 10.9803 19 10.3162 19H7.75858C6.95362 19 6.28927 19 5.74808 18.9558C5.18598 18.9099 4.66928 18.8113 4.18394 18.564C3.43129 18.1805 2.81937 17.5686 2.43588 16.816C2.18859 16.3306 2.09002 15.8139 2.0441 15.2518C1.99988 14.7106 1.99989 14.0463 1.9999 13.2413V7.75868C1.99989 6.95372 1.99988 6.28936 2.0441 5.74818C2.09002 5.18608 2.18859 4.66937 2.43588 4.18404C2.81937 3.43139 3.43129 2.81947 4.18394 2.43598C4.66928 2.18868 5.18598 2.09012 5.74808 2.04419C6.28927 1.99998 6.95364 1.99999 7.7586 2ZM10.5073 7.5C10.5073 6.67157 9.83575 6 9.00732 6C8.1789 6 7.50732 6.67157 7.50732 7.5C7.50732 8.32843 8.1789 9 9.00732 9C9.83575 9 10.5073 8.32843 10.5073 7.5ZM16.6073 11.7001C16.1669 11.3697 15.5426 11.4577 15.2105 11.8959C15.1488 11.9746 15.081 12.0486 15.0119 12.1207C14.8646 12.2744 14.6432 12.4829 14.3566 12.6913C13.7796 13.111 12.9818 13.5001 12.0073 13.5001C11.0328 13.5001 10.235 13.111 9.65799 12.6913C9.37138 12.4829 9.15004 12.2744 9.00274 12.1207C8.93366 12.0486 8.86581 11.9745 8.80418 11.8959C8.472 11.4577 7.84775 11.3697 7.40732 11.7001C6.96549 12.0314 6.87595 12.6582 7.20732 13.1001C7.20479 13.0968 7.21072 13.1043 7.22094 13.1171C7.24532 13.1478 7.29407 13.2091 7.31068 13.2289C7.36932 13.2987 7.45232 13.3934 7.55877 13.5045C7.77084 13.7258 8.08075 14.0172 8.48165 14.3088C9.27958 14.8891 10.4818 15.5001 12.0073 15.5001C13.5328 15.5001 14.735 14.8891 15.533 14.3088C15.9339 14.0172 16.2438 13.7258 16.4559 13.5045C16.5623 13.3934 16.6453 13.2987 16.704 13.2289C16.7333 13.1939 16.7567 13.165 16.7739 13.1432C17.1193 12.6969 17.0729 12.0493 16.6073 11.7001ZM15.0073 6C15.8358 6 16.5073 6.67157 16.5073 7.5C16.5073 8.32843 15.8358 9 15.0073 9C14.1789 9 13.5073 8.32843 13.5073 7.5C13.5073 6.67157 14.1789 6 15.0073 6Z" fill="white"/>
|
<path fill-rule="evenodd" clip-rule="evenodd" d="M7.7586 2L16.2412 2C17.0462 1.99999 17.7105 1.99998 18.2517 2.04419C18.8138 2.09012 19.3305 2.18868 19.8159 2.43598C20.5685 2.81947 21.1804 3.43139 21.5639 4.18404C21.8112 4.66937 21.9098 5.18608 21.9557 5.74818C21.9999 6.28937 21.9999 6.95373 21.9999 7.7587L22 14.1376C22.0004 14.933 22.0007 15.5236 21.8636 16.0353C21.4937 17.4156 20.4155 18.4938 19.0352 18.8637C18.7277 18.9461 18.3917 18.9789 17.9999 18.9918L17.9999 20.371C18 20.6062 18 20.846 17.9822 21.0425C17.9651 21.2305 17.9199 21.5852 17.6722 21.8955C17.3872 22.2525 16.9551 22.4602 16.4983 22.4597C16.1013 22.4593 15.7961 22.273 15.6386 22.1689C15.474 22.06 15.2868 21.9102 15.1031 21.7632L12.69 19.8327C12.1714 19.4178 12.0174 19.3007 11.8575 19.219C11.697 19.137 11.5262 19.0771 11.3496 19.0408C11.1737 19.0047 10.9803 19 10.3162 19H7.75858C6.95362 19 6.28927 19 5.74808 18.9558C5.18598 18.9099 4.66928 18.8113 4.18394 18.564C3.43129 18.1805 2.81937 17.5686 2.43588 16.816C2.18859 16.3306 2.09002 15.8139 2.0441 15.2518C1.99988 14.7106 1.99989 14.0463 1.9999 13.2413V7.75868C1.99989 6.95372 1.99988 6.28936 2.0441 5.74818C2.09002 5.18608 2.18859 4.66937 2.43588 4.18404C2.81937 3.43139 3.43129 2.81947 4.18394 2.43598C4.66928 2.18868 5.18598 2.09012 5.74808 2.04419C6.28927 1.99998 6.95364 1.99999 7.7586 2ZM10.5073 7.5C10.5073 6.67157 9.83575 6 9.00732 6C8.1789 6 7.50732 6.67157 7.50732 7.5C7.50732 8.32843 8.1789 9 9.00732 9C9.83575 9 10.5073 8.32843 10.5073 7.5ZM16.6073 11.7001C16.1669 11.3697 15.5426 11.4577 15.2105 11.8959C15.1488 11.9746 15.081 12.0486 15.0119 12.1207C14.8646 12.2744 14.6432 12.4829 14.3566 12.6913C13.7796 13.111 12.9818 13.5001 12.0073 13.5001C11.0328 13.5001 10.235 13.111 9.65799 12.6913C9.37138 12.4829 9.15004 12.2744 9.00274 12.1207C8.93366 12.0486 8.86581 11.9745 8.80418 11.8959C8.472 11.4577 7.84775 11.3697 7.40732 11.7001C6.96549 12.0314 6.87595 12.6582 7.20732 13.1001C7.20479 13.0968 7.21072 13.1043 7.22094 13.1171C7.24532 13.1478 7.29407 13.2091 7.31068 13.2289C7.36932 13.2987 7.45232 13.3934 7.55877 13.5045C7.77084 13.7258 8.08075 14.0172 8.48165 14.3088C9.27958 14.8891 10.4818 15.5001 12.0073 15.5001C13.5328 15.5001 14.735 14.8891 15.533 14.3088C15.9339 14.0172 16.2438 13.7258 16.4559 13.5045C16.5623 13.3934 16.6453 13.2987 16.704 13.2289C16.7333 13.1939 16.7567 13.165 16.7739 13.1432C17.1193 12.6969 17.0729 12.0493 16.6073 11.7001ZM15.0073 6C15.8358 6 16.5073 6.67157 16.5073 7.5C16.5073 8.32843 15.8358 9 15.0073 9C14.1789 9 13.5073 8.32843 13.5073 7.5C13.5073 6.67157 14.1789 6 15.0073 6Z" fill="white"/>
|
||||||
</svg>`,
|
</svg>
|
||||||
close: `<svg id="closeIcon" width="24" height="24" viewBox="0 0 24 24" fill="none" xmlns="http://www.w3.org/2000/svg">
|
<svg id="closeIcon" style="display:none" width="24" height="24" viewBox="0 0 24 24" fill="none" xmlns="http://www.w3.org/2000/svg">
|
||||||
<path d="M18 18L6 6M6 18L18 6" stroke="white" stroke-width="2" stroke-linecap="round" stroke-linejoin="round"/>
|
<path d="M18 18L6 6M6 18L18 6" stroke="white" stroke-width="2" stroke-linecap="round" stroke-linejoin="round"/>
|
||||||
</svg>`
|
</svg>
|
||||||
};
|
`;
|
||||||
|
|
||||||
// Main function to embed the chatbot
|
// Main function to embed the chatbot
|
||||||
async function embedChatbot() {
|
async function embedChatbot() {
|
||||||
|
let isDragging = false
|
||||||
|
|
||||||
if (!config || !config.token) {
|
if (!config || !config.token) {
|
||||||
console.error(`${configKey} is empty or token is not provided`);
|
console.error(`${configKey} is empty or token is not provided`);
|
||||||
return;
|
return;
|
||||||
|
@ -33,7 +34,9 @@
|
||||||
async function compressAndEncodeBase64(input) {
|
async function compressAndEncodeBase64(input) {
|
||||||
const uint8Array = new TextEncoder().encode(input);
|
const uint8Array = new TextEncoder().encode(input);
|
||||||
const compressedStream = new Response(
|
const compressedStream = new Response(
|
||||||
new Blob([uint8Array]).stream().pipeThrough(new CompressionStream('gzip'))
|
new Blob([uint8Array])
|
||||||
|
.stream()
|
||||||
|
.pipeThrough(new CompressionStream("gzip"))
|
||||||
).arrayBuffer();
|
).arrayBuffer();
|
||||||
const compressedUint8Array = new Uint8Array(await compressedStream);
|
const compressedUint8Array = new Uint8Array(await compressedStream);
|
||||||
return btoa(String.fromCharCode(...compressedUint8Array));
|
return btoa(String.fromCharCode(...compressedUint8Array));
|
||||||
|
@ -112,33 +115,30 @@
|
||||||
|
|
||||||
// Function to reset the iframe position
|
// Function to reset the iframe position
|
||||||
function resetIframePosition() {
|
function resetIframePosition() {
|
||||||
if (window.innerWidth <= 640)
|
if (window.innerWidth <= 640) return;
|
||||||
return
|
|
||||||
|
|
||||||
const targetIframe = document.getElementById(iframeId);
|
const targetIframe = document.getElementById(iframeId);
|
||||||
const targetButton = document.getElementById(buttonId);
|
const targetButton = document.getElementById(buttonId);
|
||||||
if (targetIframe && targetButton) {
|
if (targetIframe && targetButton) {
|
||||||
const buttonRect = targetButton.getBoundingClientRect();
|
const buttonRect = targetButton.getBoundingClientRect();
|
||||||
|
|
||||||
const buttonInBottom = buttonRect.top - 5 > targetIframe.clientHeight
|
const buttonInBottom = buttonRect.top - 5 > targetIframe.clientHeight;
|
||||||
|
|
||||||
if (buttonInBottom) {
|
if (buttonInBottom) {
|
||||||
targetIframe.style.bottom = '0px';
|
targetIframe.style.bottom = "0px";
|
||||||
targetIframe.style.top = 'unset';
|
targetIframe.style.top = "unset";
|
||||||
}
|
} else {
|
||||||
else {
|
targetIframe.style.bottom = "unset";
|
||||||
targetIframe.style.bottom = 'unset';
|
targetIframe.style.top = "0px";
|
||||||
targetIframe.style.top = '0px';
|
|
||||||
}
|
}
|
||||||
|
|
||||||
const buttonInRight = buttonRect.right > targetIframe.clientWidth;
|
const buttonInRight = buttonRect.right > targetIframe.clientWidth;
|
||||||
|
|
||||||
if (buttonInRight) {
|
if (buttonInRight) {
|
||||||
targetIframe.style.right = '0';
|
targetIframe.style.right = "0";
|
||||||
targetIframe.style.left = 'unset';
|
targetIframe.style.left = "unset";
|
||||||
}
|
} else {
|
||||||
else {
|
targetIframe.style.right = "unset";
|
||||||
targetIframe.style.right = 'unset';
|
|
||||||
targetIframe.style.left = 0;
|
targetIframe.style.left = 0;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -193,33 +193,41 @@
|
||||||
const displayDiv = document.createElement("div");
|
const displayDiv = document.createElement("div");
|
||||||
displayDiv.style.cssText =
|
displayDiv.style.cssText =
|
||||||
"position: relative; display: flex; align-items: center; justify-content: center; width: 100%; height: 100%; z-index: 2147483647;";
|
"position: relative; display: flex; align-items: center; justify-content: center; width: 100%; height: 100%; z-index: 2147483647;";
|
||||||
displayDiv.innerHTML = svgIcons.open;
|
displayDiv.innerHTML = svgIcons;
|
||||||
containerDiv.appendChild(displayDiv);
|
containerDiv.appendChild(displayDiv);
|
||||||
document.body.appendChild(containerDiv);
|
document.body.appendChild(containerDiv);
|
||||||
|
|
||||||
// Add click event listener to toggle chatbot
|
// Add click event listener to toggle chatbot
|
||||||
containerDiv.addEventListener("click", function () {
|
containerDiv.addEventListener("click", handleClick);
|
||||||
|
// Add touch event listener
|
||||||
|
containerDiv.addEventListener("touchend", handleClick);
|
||||||
|
|
||||||
|
function handleClick() {
|
||||||
|
if (isDragging) return;
|
||||||
|
|
||||||
const targetIframe = document.getElementById(iframeId);
|
const targetIframe = document.getElementById(iframeId);
|
||||||
if (!targetIframe) {
|
if (!targetIframe) {
|
||||||
containerDiv.prepend(createIframe());
|
containerDiv.appendChild(createIframe());
|
||||||
resetIframePosition();
|
resetIframePosition();
|
||||||
this.title = "Exit (ESC)";
|
this.title = "Exit (ESC)";
|
||||||
displayDiv.innerHTML = svgIcons.close;
|
setSvgIcon("close");
|
||||||
document.addEventListener('keydown', handleEscKey);
|
document.addEventListener("keydown", handleEscKey);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
targetIframe.style.display = targetIframe.style.display === "none" ? "block" : "none";
|
targetIframe.style.display =
|
||||||
displayDiv.innerHTML = targetIframe.style.display === "none" ? svgIcons.open : svgIcons.close;
|
targetIframe.style.display === "none" ? "block" : "none";
|
||||||
|
targetIframe.style.display === "none"
|
||||||
|
? setSvgIcon("open")
|
||||||
|
: setSvgIcon("close");
|
||||||
|
|
||||||
if (targetIframe.style.display === "none") {
|
if (targetIframe.style.display === "none") {
|
||||||
document.removeEventListener('keydown', handleEscKey);
|
document.removeEventListener("keydown", handleEscKey);
|
||||||
} else {
|
} else {
|
||||||
document.addEventListener('keydown', handleEscKey);
|
document.addEventListener("keydown", handleEscKey);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
resetIframePosition();
|
resetIframePosition();
|
||||||
});
|
}
|
||||||
|
|
||||||
// Enable dragging if specified in config
|
// Enable dragging if specified in config
|
||||||
if (config.draggable) {
|
if (config.draggable) {
|
||||||
|
@ -229,20 +237,39 @@
|
||||||
|
|
||||||
// Function to enable dragging of the chat button
|
// Function to enable dragging of the chat button
|
||||||
function enableDragging(element, axis) {
|
function enableDragging(element, axis) {
|
||||||
let isDragging = false;
|
let startX, startY, startClientX, startClientY;
|
||||||
let startX, startY;
|
|
||||||
|
|
||||||
element.addEventListener("mousedown", startDragging);
|
element.addEventListener("mousedown", startDragging);
|
||||||
document.addEventListener("mousemove", drag);
|
element.addEventListener("touchstart", startDragging);
|
||||||
document.addEventListener("mouseup", stopDragging);
|
|
||||||
|
|
||||||
function startDragging(e) {
|
function startDragging(e) {
|
||||||
isDragging = true;
|
isDragging = false;
|
||||||
startX = e.clientX - element.offsetLeft;
|
if (e.type === "touchstart") {
|
||||||
startY = e.clientY - element.offsetTop;
|
startX = e.touches[0].clientX - element.offsetLeft;
|
||||||
|
startY = e.touches[0].clientY - element.offsetTop;
|
||||||
|
startClientX = e.touches[0].clientX;
|
||||||
|
startClientY = e.touches[0].clientY;
|
||||||
|
} else {
|
||||||
|
startX = e.clientX - element.offsetLeft;
|
||||||
|
startY = e.clientY - element.offsetTop;
|
||||||
|
}
|
||||||
|
document.addEventListener("mousemove", drag);
|
||||||
|
document.addEventListener("touchmove", drag, { passive: false });
|
||||||
|
document.addEventListener("mouseup", stopDragging);
|
||||||
|
document.addEventListener("touchend", stopDragging);
|
||||||
|
e.preventDefault();
|
||||||
}
|
}
|
||||||
|
|
||||||
function drag(e) {
|
function drag(e) {
|
||||||
|
const touch = e.type === "touchmove" ? e.touches[0] : e;
|
||||||
|
const deltaX = touch.clientX - startClientX;
|
||||||
|
const deltaY = touch.clientY - startClientY;
|
||||||
|
|
||||||
|
// Determine whether it is a drag operation
|
||||||
|
if (Math.abs(deltaX) > 8 || Math.abs(deltaY) > 8) {
|
||||||
|
isDragging = true;
|
||||||
|
}
|
||||||
|
|
||||||
if (!isDragging) return;
|
if (!isDragging) return;
|
||||||
|
|
||||||
element.style.transition = "none";
|
element.style.transition = "none";
|
||||||
|
@ -252,11 +279,17 @@
|
||||||
const targetIframe = document.getElementById(iframeId);
|
const targetIframe = document.getElementById(iframeId);
|
||||||
if (targetIframe) {
|
if (targetIframe) {
|
||||||
targetIframe.style.display = "none";
|
targetIframe.style.display = "none";
|
||||||
element.querySelector("div").innerHTML = svgIcons.open;
|
setSvgIcon("open");
|
||||||
}
|
}
|
||||||
|
|
||||||
const newLeft = e.clientX - startX;
|
let newLeft, newBottom;
|
||||||
const newBottom = window.innerHeight - e.clientY - startY;
|
if (e.type === "touchmove") {
|
||||||
|
newLeft = e.touches[0].clientX - startX;
|
||||||
|
newBottom = window.innerHeight - e.touches[0].clientY - startY;
|
||||||
|
} else {
|
||||||
|
newLeft = e.clientX - startX;
|
||||||
|
newBottom = window.innerHeight - e.clientY - startY;
|
||||||
|
}
|
||||||
|
|
||||||
const elementRect = element.getBoundingClientRect();
|
const elementRect = element.getBoundingClientRect();
|
||||||
const maxX = window.innerWidth - elementRect.width;
|
const maxX = window.innerWidth - elementRect.width;
|
||||||
|
@ -279,9 +312,16 @@
|
||||||
}
|
}
|
||||||
|
|
||||||
function stopDragging() {
|
function stopDragging() {
|
||||||
isDragging = false;
|
setTimeout(() => {
|
||||||
|
isDragging = false;
|
||||||
|
}, 0);
|
||||||
element.style.transition = "";
|
element.style.transition = "";
|
||||||
element.style.cursor = "pointer";
|
element.style.cursor = "pointer";
|
||||||
|
|
||||||
|
document.removeEventListener("mousemove", drag);
|
||||||
|
document.removeEventListener("touchmove", drag);
|
||||||
|
document.removeEventListener("mouseup", stopDragging);
|
||||||
|
document.removeEventListener("touchend", stopDragging);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -291,18 +331,27 @@
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
function setSvgIcon(type = "open") {
|
||||||
|
if (type === "open") {
|
||||||
|
document.getElementById("openIcon").style.display = "block";
|
||||||
|
document.getElementById("closeIcon").style.display = "none";
|
||||||
|
} else {
|
||||||
|
document.getElementById("openIcon").style.display = "none";
|
||||||
|
document.getElementById("closeIcon").style.display = "block";
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
// Add esc Exit keyboard event triggered
|
// Add esc Exit keyboard event triggered
|
||||||
function handleEscKey(event) {
|
function handleEscKey(event) {
|
||||||
if (event.key === 'Escape') {
|
if (event.key === "Escape") {
|
||||||
const targetIframe = document.getElementById(iframeId);
|
const targetIframe = document.getElementById(iframeId);
|
||||||
const button = document.getElementById(buttonId);
|
if (targetIframe && targetIframe.style.display !== "none") {
|
||||||
if (targetIframe && targetIframe.style.display !== 'none') {
|
targetIframe.style.display = "none";
|
||||||
targetIframe.style.display = 'none';
|
setSvgIcon("open");
|
||||||
button.querySelector('div').innerHTML = svgIcons.open;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
document.addEventListener('keydown', handleEscKey);
|
document.addEventListener("keydown", handleEscKey);
|
||||||
|
|
||||||
// Set the embedChatbot function to run when the body is loaded,Avoid infinite nesting
|
// Set the embedChatbot function to run when the body is loaded,Avoid infinite nesting
|
||||||
if (config?.dynamicScript) {
|
if (config?.dynamicScript) {
|
||||||
|
@ -310,4 +359,4 @@
|
||||||
} else {
|
} else {
|
||||||
document.body.onload = embedChatbot;
|
document.body.onload = embedChatbot;
|
||||||
}
|
}
|
||||||
})();
|
})();
|
||||||
|
|
|
@ -1,8 +1,4 @@
|
||||||
(()=>{let t="difyChatbotConfig",a="dify-chatbot-bubble-button",c="dify-chatbot-bubble-window",p=window[t],u={open:`<svg id="openIcon" width="24" height="24" viewBox="0 0 24 24" fill="none" xmlns="http://www.w3.org/2000/svg">
|
(()=>{let t="difyChatbotConfig",m="dify-chatbot-bubble-button",h="dify-chatbot-bubble-window",p=window[t];async function e(){let u=!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 o(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 o(t)})),n})()});let t=`${p.baseUrl||`https://${p.isDev?"dev.":""}udify.app`}/chatbot/${p.token}?`+e;e=s();async function o(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=h,e.src=t,e.style.cssText=`
|
||||||
<path fill-rule="evenodd" clip-rule="evenodd" d="M7.7586 2L16.2412 2C17.0462 1.99999 17.7105 1.99998 18.2517 2.04419C18.8138 2.09012 19.3305 2.18868 19.8159 2.43598C20.5685 2.81947 21.1804 3.43139 21.5639 4.18404C21.8112 4.66937 21.9098 5.18608 21.9557 5.74818C21.9999 6.28937 21.9999 6.95373 21.9999 7.7587L22 14.1376C22.0004 14.933 22.0007 15.5236 21.8636 16.0353C21.4937 17.4156 20.4155 18.4938 19.0352 18.8637C18.7277 18.9461 18.3917 18.9789 17.9999 18.9918L17.9999 20.371C18 20.6062 18 20.846 17.9822 21.0425C17.9651 21.2305 17.9199 21.5852 17.6722 21.8955C17.3872 22.2525 16.9551 22.4602 16.4983 22.4597C16.1013 22.4593 15.7961 22.273 15.6386 22.1689C15.474 22.06 15.2868 21.9102 15.1031 21.7632L12.69 19.8327C12.1714 19.4178 12.0174 19.3007 11.8575 19.219C11.697 19.137 11.5262 19.0771 11.3496 19.0408C11.1737 19.0047 10.9803 19 10.3162 19H7.75858C6.95362 19 6.28927 19 5.74808 18.9558C5.18598 18.9099 4.66928 18.8113 4.18394 18.564C3.43129 18.1805 2.81937 17.5686 2.43588 16.816C2.18859 16.3306 2.09002 15.8139 2.0441 15.2518C1.99988 14.7106 1.99989 14.0463 1.9999 13.2413V7.75868C1.99989 6.95372 1.99988 6.28936 2.0441 5.74818C2.09002 5.18608 2.18859 4.66937 2.43588 4.18404C2.81937 3.43139 3.43129 2.81947 4.18394 2.43598C4.66928 2.18868 5.18598 2.09012 5.74808 2.04419C6.28927 1.99998 6.95364 1.99999 7.7586 2ZM10.5073 7.5C10.5073 6.67157 9.83575 6 9.00732 6C8.1789 6 7.50732 6.67157 7.50732 7.5C7.50732 8.32843 8.1789 9 9.00732 9C9.83575 9 10.5073 8.32843 10.5073 7.5ZM16.6073 11.7001C16.1669 11.3697 15.5426 11.4577 15.2105 11.8959C15.1488 11.9746 15.081 12.0486 15.0119 12.1207C14.8646 12.2744 14.6432 12.4829 14.3566 12.6913C13.7796 13.111 12.9818 13.5001 12.0073 13.5001C11.0328 13.5001 10.235 13.111 9.65799 12.6913C9.37138 12.4829 9.15004 12.2744 9.00274 12.1207C8.93366 12.0486 8.86581 11.9745 8.80418 11.8959C8.472 11.4577 7.84775 11.3697 7.40732 11.7001C6.96549 12.0314 6.87595 12.6582 7.20732 13.1001C7.20479 13.0968 7.21072 13.1043 7.22094 13.1171C7.24532 13.1478 7.29407 13.2091 7.31068 13.2289C7.36932 13.2987 7.45232 13.3934 7.55877 13.5045C7.77084 13.7258 8.08075 14.0172 8.48165 14.3088C9.27958 14.8891 10.4818 15.5001 12.0073 15.5001C13.5328 15.5001 14.735 14.8891 15.533 14.3088C15.9339 14.0172 16.2438 13.7258 16.4559 13.5045C16.5623 13.3934 16.6453 13.2987 16.704 13.2289C16.7333 13.1939 16.7567 13.165 16.7739 13.1432C17.1193 12.6969 17.0729 12.0493 16.6073 11.7001ZM15.0073 6C15.8358 6 16.5073 6.67157 16.5073 7.5C16.5073 8.32843 15.8358 9 15.0073 9C14.1789 9 13.5073 8.32843 13.5073 7.5C13.5073 6.67157 14.1789 6 15.0073 6Z" fill="white"/>
|
|
||||||
</svg>`,close:`<svg id="closeIcon" width="24" height="24" viewBox="0 0 24 24" fill="none" xmlns="http://www.w3.org/2000/svg">
|
|
||||||
<path d="M18 18L6 6M6 18L18 6" stroke="white" stroke-width="2" stroke-linecap="round" stroke-linejoin="round"/>
|
|
||||||
</svg>`};async function e(){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 o(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 o(t)})),n})()});let t=`${p.baseUrl||`https://${p.isDev?"dev.":""}udify.app`}/chatbot/${p.token}?`+e;e=i();async function o(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 i(){var e=document.createElement("iframe");return e.allow="fullscreen;microphone",e.title="dify chatbot bubble window",e.id=c,e.src=t,e.style.cssText=`
|
|
||||||
position: absolute;
|
position: absolute;
|
||||||
display: flex;
|
display: flex;
|
||||||
flex-direction: column;
|
flex-direction: column;
|
||||||
|
@ -18,7 +14,7 @@
|
||||||
z-index: 2147483640;
|
z-index: 2147483640;
|
||||||
overflow: hidden;
|
overflow: hidden;
|
||||||
user-select: none;
|
user-select: none;
|
||||||
`,e}function r(){var e,t;window.innerWidth<=640||(e=document.getElementById(c),t=document.getElementById(a),e&&t&&((t=t.getBoundingClientRect()).top-5>e.clientHeight?(e.style.bottom="0px",e.style.top="unset"):(e.style.bottom="unset",e.style.top="0px"),t.right>e.clientWidth?(e.style.right="0",e.style.left="unset"):(e.style.right="unset",e.style.left=0)))}function n(){let n=document.createElement("div");Object.entries(p.containerProps||{}).forEach(([e,t])=>{"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=a;var e=document.createElement("style");document.head.appendChild(e),e.sheet.insertRule(`
|
`,e}function d(){var e,t;window.innerWidth<=640||(e=document.getElementById(h),t=document.getElementById(m),e&&t&&((t=t.getBoundingClientRect()).top-5>e.clientHeight?(e.style.bottom="0px",e.style.top="unset"):(e.style.bottom="unset",e.style.top="0px"),t.right>e.clientWidth?(e.style.right="0",e.style.left="unset"):(e.style.right="unset",e.style.left=0)))}function n(){let n=document.createElement("div");Object.entries(p.containerProps||{}).forEach(([e,t])=>{"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=m;var e=document.createElement("style"),e=(document.head.appendChild(e),e.sheet.insertRule(`
|
||||||
#${n.id} {
|
#${n.id} {
|
||||||
position: fixed;
|
position: fixed;
|
||||||
bottom: var(--${n.id}-bottom, 1rem);
|
bottom: var(--${n.id}-bottom, 1rem);
|
||||||
|
@ -33,4 +29,10 @@
|
||||||
cursor: pointer;
|
cursor: pointer;
|
||||||
z-index: 2147483647;
|
z-index: 2147483647;
|
||||||
}
|
}
|
||||||
`);let t=document.createElement("div");if(t.style.cssText="position: relative; display: flex; align-items: center; justify-content: center; width: 100%; height: 100%; z-index: 2147483647;",t.innerHTML=u.open,n.appendChild(t),document.body.appendChild(n),n.addEventListener("click",function(){var e=document.getElementById(c);e?(e.style.display="none"===e.style.display?"block":"none",t.innerHTML="none"===e.style.display?u.open:u.close,"none"===e.style.display?document.removeEventListener("keydown",d):document.addEventListener("keydown",d),r()):(n.prepend(i()),r(),this.title="Exit (ESC)",t.innerHTML=u.close,document.addEventListener("keydown",d))}),p.draggable){var s=n;var l=p.dragAxis||"both";let i=!1,r,d;s.addEventListener("mousedown",function(e){i=!0,r=e.clientX-s.offsetLeft,d=e.clientY-s.offsetTop}),document.addEventListener("mousemove",function(e){var t,n,o;i&&(s.style.transition="none",s.style.cursor="grabbing",(t=document.getElementById(c))&&(t.style.display="none",s.querySelector("div").innerHTML=u.open),t=e.clientX-r,e=window.innerHeight-e.clientY-d,o=s.getBoundingClientRect(),n=window.innerWidth-o.width,o=window.innerHeight-o.height,"x"!==l&&"both"!==l||s.style.setProperty(`--${a}-left`,Math.max(0,Math.min(t,n))+"px"),"y"!==l&&"both"!==l||s.style.setProperty(`--${a}-bottom`,Math.max(0,Math.min(e,o))+"px"))}),document.addEventListener("mouseup",function(){i=!1,s.style.transition="",s.style.cursor="pointer"})}}e.style.display="none",document.body.appendChild(e),2048<t.length&&console.error("The URL is too long, please reduce the number of inputs to prevent the bot from failing to load"),document.getElementById(a)||n()}else console.error(t+" is empty or token is not provided")}function d(e){var t;"Escape"===e.key&&(e=document.getElementById(c),t=document.getElementById(a),e)&&"none"!==e.style.display&&(e.style.display="none",t.querySelector("div").innerHTML=u.open)}document.addEventListener("keydown",d),p?.dynamicScript?e():document.body.onload=e})();
|
`),document.createElement("div"));function t(){var e;u||((e=document.getElementById(h))?(e.style.display="none"===e.style.display?"block":"none","none"===e.style.display?y("open"):y("close"),"none"===e.style.display?document.removeEventListener("keydown",l):document.addEventListener("keydown",l),d()):(n.appendChild(s()),d(),this.title="Exit (ESC)",y("close"),document.addEventListener("keydown",l)))}if(e.style.cssText="position: relative; display: flex; align-items: center; justify-content: center; width: 100%; height: 100%; z-index: 2147483647;",e.innerHTML=`<svg id="openIcon" width="24" height="24" viewBox="0 0 24 24" fill="none" xmlns="http://www.w3.org/2000/svg">
|
||||||
|
<path fill-rule="evenodd" clip-rule="evenodd" d="M7.7586 2L16.2412 2C17.0462 1.99999 17.7105 1.99998 18.2517 2.04419C18.8138 2.09012 19.3305 2.18868 19.8159 2.43598C20.5685 2.81947 21.1804 3.43139 21.5639 4.18404C21.8112 4.66937 21.9098 5.18608 21.9557 5.74818C21.9999 6.28937 21.9999 6.95373 21.9999 7.7587L22 14.1376C22.0004 14.933 22.0007 15.5236 21.8636 16.0353C21.4937 17.4156 20.4155 18.4938 19.0352 18.8637C18.7277 18.9461 18.3917 18.9789 17.9999 18.9918L17.9999 20.371C18 20.6062 18 20.846 17.9822 21.0425C17.9651 21.2305 17.9199 21.5852 17.6722 21.8955C17.3872 22.2525 16.9551 22.4602 16.4983 22.4597C16.1013 22.4593 15.7961 22.273 15.6386 22.1689C15.474 22.06 15.2868 21.9102 15.1031 21.7632L12.69 19.8327C12.1714 19.4178 12.0174 19.3007 11.8575 19.219C11.697 19.137 11.5262 19.0771 11.3496 19.0408C11.1737 19.0047 10.9803 19 10.3162 19H7.75858C6.95362 19 6.28927 19 5.74808 18.9558C5.18598 18.9099 4.66928 18.8113 4.18394 18.564C3.43129 18.1805 2.81937 17.5686 2.43588 16.816C2.18859 16.3306 2.09002 15.8139 2.0441 15.2518C1.99988 14.7106 1.99989 14.0463 1.9999 13.2413V7.75868C1.99989 6.95372 1.99988 6.28936 2.0441 5.74818C2.09002 5.18608 2.18859 4.66937 2.43588 4.18404C2.81937 3.43139 3.43129 2.81947 4.18394 2.43598C4.66928 2.18868 5.18598 2.09012 5.74808 2.04419C6.28927 1.99998 6.95364 1.99999 7.7586 2ZM10.5073 7.5C10.5073 6.67157 9.83575 6 9.00732 6C8.1789 6 7.50732 6.67157 7.50732 7.5C7.50732 8.32843 8.1789 9 9.00732 9C9.83575 9 10.5073 8.32843 10.5073 7.5ZM16.6073 11.7001C16.1669 11.3697 15.5426 11.4577 15.2105 11.8959C15.1488 11.9746 15.081 12.0486 15.0119 12.1207C14.8646 12.2744 14.6432 12.4829 14.3566 12.6913C13.7796 13.111 12.9818 13.5001 12.0073 13.5001C11.0328 13.5001 10.235 13.111 9.65799 12.6913C9.37138 12.4829 9.15004 12.2744 9.00274 12.1207C8.93366 12.0486 8.86581 11.9745 8.80418 11.8959C8.472 11.4577 7.84775 11.3697 7.40732 11.7001C6.96549 12.0314 6.87595 12.6582 7.20732 13.1001C7.20479 13.0968 7.21072 13.1043 7.22094 13.1171C7.24532 13.1478 7.29407 13.2091 7.31068 13.2289C7.36932 13.2987 7.45232 13.3934 7.55877 13.5045C7.77084 13.7258 8.08075 14.0172 8.48165 14.3088C9.27958 14.8891 10.4818 15.5001 12.0073 15.5001C13.5328 15.5001 14.735 14.8891 15.533 14.3088C15.9339 14.0172 16.2438 13.7258 16.4559 13.5045C16.5623 13.3934 16.6453 13.2987 16.704 13.2289C16.7333 13.1939 16.7567 13.165 16.7739 13.1432C17.1193 12.6969 17.0729 12.0493 16.6073 11.7001ZM15.0073 6C15.8358 6 16.5073 6.67157 16.5073 7.5C16.5073 8.32843 15.8358 9 15.0073 9C14.1789 9 13.5073 8.32843 13.5073 7.5C13.5073 6.67157 14.1789 6 15.0073 6Z" fill="white"/>
|
||||||
|
</svg>
|
||||||
|
<svg id="closeIcon" style="display:none" width="24" height="24" viewBox="0 0 24 24" fill="none" xmlns="http://www.w3.org/2000/svg">
|
||||||
|
<path d="M18 18L6 6M6 18L18 6" stroke="white" stroke-width="2" stroke-linecap="round" stroke-linejoin="round"/>
|
||||||
|
</svg>
|
||||||
|
`,n.appendChild(e),document.body.appendChild(n),n.addEventListener("click",t),n.addEventListener("touchend",t),p.draggable){var r=n;var a=p.dragAxis||"both";let s,d,t,l;function o(e){u=!1,"touchstart"===e.type?(s=e.touches[0].clientX-r.offsetLeft,d=e.touches[0].clientY-r.offsetTop,t=e.touches[0].clientX,l=e.touches[0].clientY):(s=e.clientX-r.offsetLeft,d=e.clientY-r.offsetTop),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-l;if(u=8<Math.abs(i)||8<Math.abs(o)?!0:u){r.style.transition="none",r.style.cursor="grabbing";i=document.getElementById(h);i&&(i.style.display="none",y("open"));let e,t;t="touchmove"===n.type?(e=n.touches[0].clientX-s,window.innerHeight-n.touches[0].clientY-d):(e=n.clientX-s,window.innerHeight-n.clientY-d);o=r.getBoundingClientRect(),i=window.innerWidth-o.width,n=window.innerHeight-o.height;"x"!==a&&"both"!==a||r.style.setProperty(`--${m}-left`,Math.max(0,Math.min(e,i))+"px"),"y"!==a&&"both"!==a||r.style.setProperty(`--${m}-bottom`,Math.max(0,Math.min(t,n))+"px")}}function c(){setTimeout(()=>{u=!1},0),r.style.transition="",r.style.cursor="pointer",document.removeEventListener("mousemove",i),document.removeEventListener("touchmove",i),document.removeEventListener("mouseup",c),document.removeEventListener("touchend",c)}r.addEventListener("mousedown",o),r.addEventListener("touchstart",o)}}e.style.display="none",document.body.appendChild(e),2048<t.length&&console.error("The URL is too long, please reduce the number of inputs to prevent the bot from failing to load"),document.getElementById(m)||n()}else console.error(t+" is empty or token is not provided")}function y(e="open"){"open"===e?(document.getElementById("openIcon").style.display="block",document.getElementById("closeIcon").style.display="none"):(document.getElementById("openIcon").style.display="none",document.getElementById("closeIcon").style.display="block")}function l(e){"Escape"===e.key&&(e=document.getElementById(h))&&"none"!==e.style.display&&(e.style.display="none",y("open"))}document.addEventListener("keydown",l),p?.dynamicScript?e():document.body.onload=e})();
|
Loading…
Reference in New Issue