mirror of
https://github.com/AUTOMATIC1111/stable-diffusion-webui.git
synced 2026-02-01 05:50:01 +00:00
Merge branch 'dev' into gradio4
This commit is contained in:
@@ -8,9 +8,6 @@ var contextMenuInit = function() {
|
||||
};
|
||||
|
||||
function showContextMenu(event, element, menuEntries) {
|
||||
let posx = event.clientX + document.body.scrollLeft + document.documentElement.scrollLeft;
|
||||
let posy = event.clientY + document.body.scrollTop + document.documentElement.scrollTop;
|
||||
|
||||
let oldMenu = gradioApp().querySelector('#context-menu');
|
||||
if (oldMenu) {
|
||||
oldMenu.remove();
|
||||
@@ -23,10 +20,8 @@ var contextMenuInit = function() {
|
||||
contextMenu.style.background = baseStyle.background;
|
||||
contextMenu.style.color = baseStyle.color;
|
||||
contextMenu.style.fontFamily = baseStyle.fontFamily;
|
||||
contextMenu.style.top = posy + 'px';
|
||||
contextMenu.style.left = posx + 'px';
|
||||
|
||||
|
||||
contextMenu.style.top = event.pageY + 'px';
|
||||
contextMenu.style.left = event.pageX + 'px';
|
||||
|
||||
const contextMenuList = document.createElement('ul');
|
||||
contextMenuList.className = 'context-menu-items';
|
||||
@@ -43,21 +38,6 @@ var contextMenuInit = function() {
|
||||
});
|
||||
|
||||
gradioApp().appendChild(contextMenu);
|
||||
|
||||
let menuWidth = contextMenu.offsetWidth + 4;
|
||||
let menuHeight = contextMenu.offsetHeight + 4;
|
||||
|
||||
let windowWidth = window.innerWidth;
|
||||
let windowHeight = window.innerHeight;
|
||||
|
||||
if ((windowWidth - posx) < menuWidth) {
|
||||
contextMenu.style.left = windowWidth - menuWidth + "px";
|
||||
}
|
||||
|
||||
if ((windowHeight - posy) < menuHeight) {
|
||||
contextMenu.style.top = windowHeight - menuHeight + "px";
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
function appendContextMenuOption(targetElementSelector, entryName, entryFunction) {
|
||||
@@ -107,16 +87,23 @@ var contextMenuInit = function() {
|
||||
oldMenu.remove();
|
||||
}
|
||||
});
|
||||
gradioApp().addEventListener("contextmenu", function(e) {
|
||||
let oldMenu = gradioApp().querySelector('#context-menu');
|
||||
if (oldMenu) {
|
||||
oldMenu.remove();
|
||||
}
|
||||
menuSpecs.forEach(function(v, k) {
|
||||
if (e.composedPath()[0].matches(k)) {
|
||||
showContextMenu(e, e.composedPath()[0], v);
|
||||
e.preventDefault();
|
||||
['contextmenu', 'touchstart'].forEach((eventType) => {
|
||||
gradioApp().addEventListener(eventType, function(e) {
|
||||
let ev = e;
|
||||
if (eventType.startsWith('touch')) {
|
||||
if (e.touches.length !== 2) return;
|
||||
ev = e.touches[0];
|
||||
}
|
||||
let oldMenu = gradioApp().querySelector('#context-menu');
|
||||
if (oldMenu) {
|
||||
oldMenu.remove();
|
||||
}
|
||||
menuSpecs.forEach(function(v, k) {
|
||||
if (e.composedPath()[0].matches(k)) {
|
||||
showContextMenu(ev, e.composedPath()[0], v);
|
||||
e.preventDefault();
|
||||
}
|
||||
});
|
||||
});
|
||||
});
|
||||
eventListenerApplied = true;
|
||||
|
||||
11
javascript/dragdrop.js
vendored
11
javascript/dragdrop.js
vendored
@@ -56,6 +56,15 @@ function eventHasFiles(e) {
|
||||
return false;
|
||||
}
|
||||
|
||||
function isURL(url) {
|
||||
try {
|
||||
const _ = new URL(url);
|
||||
return true;
|
||||
} catch {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
function dragDropTargetIsPrompt(target) {
|
||||
if (target?.placeholder && target?.placeholder.indexOf("Prompt") >= 0) return true;
|
||||
if (target?.parentNode?.parentNode?.className?.indexOf("prompt") > 0) return true;
|
||||
@@ -77,7 +86,7 @@ window.document.addEventListener('dragover', e => {
|
||||
window.document.addEventListener('drop', async e => {
|
||||
const target = e.composedPath()[0];
|
||||
const url = e.dataTransfer.getData('text/uri-list') || e.dataTransfer.getData('text/plain');
|
||||
if (!eventHasFiles(e) && !url) return;
|
||||
if (!eventHasFiles(e) && !isURL(url)) return;
|
||||
|
||||
if (dragDropTargetIsPrompt(target)) {
|
||||
e.stopPropagation();
|
||||
|
||||
@@ -6,6 +6,8 @@ function closeModal() {
|
||||
function showModal(event) {
|
||||
const source = event.target || event.srcElement;
|
||||
const modalImage = gradioApp().getElementById("modalImage");
|
||||
const modalToggleLivePreviewBtn = gradioApp().getElementById("modal_toggle_live_preview");
|
||||
modalToggleLivePreviewBtn.innerHTML = opts.js_live_preview_in_modal_lightbox ? "🗇" : "🗆";
|
||||
const lb = gradioApp().getElementById("lightboxModal");
|
||||
modalImage.src = source.src;
|
||||
if (modalImage.style.display === 'none') {
|
||||
@@ -51,14 +53,7 @@ function modalImageSwitch(offset) {
|
||||
var galleryButtons = all_gallery_buttons();
|
||||
|
||||
if (galleryButtons.length > 1) {
|
||||
var currentButton = selected_gallery_button();
|
||||
|
||||
var result = -1;
|
||||
galleryButtons.forEach(function(v, i) {
|
||||
if (v == currentButton) {
|
||||
result = i;
|
||||
}
|
||||
});
|
||||
var result = selected_gallery_index();
|
||||
|
||||
if (result != -1) {
|
||||
var nextButton = galleryButtons[negmod((result + offset), galleryButtons.length)];
|
||||
@@ -159,6 +154,13 @@ function modalZoomToggle(event) {
|
||||
event.stopPropagation();
|
||||
}
|
||||
|
||||
function modalLivePreviewToggle(event) {
|
||||
const modalToggleLivePreview = gradioApp().getElementById("modal_toggle_live_preview");
|
||||
opts.js_live_preview_in_modal_lightbox = !opts.js_live_preview_in_modal_lightbox;
|
||||
modalToggleLivePreview.innerHTML = opts.js_live_preview_in_modal_lightbox ? "🗇" : "🗆";
|
||||
event.stopPropagation();
|
||||
}
|
||||
|
||||
function modalTileImageToggle(event) {
|
||||
const modalImage = gradioApp().getElementById("modalImage");
|
||||
const modal = gradioApp().getElementById("lightboxModal");
|
||||
@@ -216,6 +218,14 @@ document.addEventListener("DOMContentLoaded", function() {
|
||||
modalSave.title = "Save Image(s)";
|
||||
modalControls.appendChild(modalSave);
|
||||
|
||||
const modalToggleLivePreview = document.createElement('span');
|
||||
modalToggleLivePreview.className = 'modalToggleLivePreview cursor';
|
||||
modalToggleLivePreview.id = "modal_toggle_live_preview";
|
||||
modalToggleLivePreview.innerHTML = "🗆";
|
||||
modalToggleLivePreview.onclick = modalLivePreviewToggle;
|
||||
modalToggleLivePreview.title = "Toggle live preview";
|
||||
modalControls.appendChild(modalToggleLivePreview);
|
||||
|
||||
const modalClose = document.createElement('span');
|
||||
modalClose.className = 'modalClose cursor';
|
||||
modalClose.innerHTML = '×';
|
||||
|
||||
@@ -76,6 +76,26 @@ function requestProgress(id_task, progressbarContainer, gallery, atEnd, onProgre
|
||||
var dateStart = new Date();
|
||||
var wasEverActive = false;
|
||||
var parentProgressbar = progressbarContainer.parentNode;
|
||||
var wakeLock = null;
|
||||
|
||||
var requestWakeLock = async function() {
|
||||
if (!opts.prevent_screen_sleep_during_generation || wakeLock) return;
|
||||
try {
|
||||
wakeLock = await navigator.wakeLock.request('screen');
|
||||
} catch (err) {
|
||||
console.error('Wake Lock is not supported.');
|
||||
}
|
||||
};
|
||||
|
||||
var releaseWakeLock = async function() {
|
||||
if (!opts.prevent_screen_sleep_during_generation || !wakeLock) return;
|
||||
try {
|
||||
await wakeLock.release();
|
||||
wakeLock = null;
|
||||
} catch (err) {
|
||||
console.error('Wake Lock release failed', err);
|
||||
}
|
||||
};
|
||||
|
||||
var divProgress = document.createElement('div');
|
||||
divProgress.className = 'progressDiv';
|
||||
@@ -89,6 +109,7 @@ function requestProgress(id_task, progressbarContainer, gallery, atEnd, onProgre
|
||||
var livePreview = null;
|
||||
|
||||
var removeProgressBar = function() {
|
||||
releaseWakeLock();
|
||||
if (!divProgress) return;
|
||||
|
||||
setTitle("");
|
||||
@@ -100,6 +121,7 @@ function requestProgress(id_task, progressbarContainer, gallery, atEnd, onProgre
|
||||
};
|
||||
|
||||
var funProgress = function(id_task) {
|
||||
requestWakeLock();
|
||||
request("./internal/progress", {id_task: id_task, live_preview: false}, function(res) {
|
||||
if (res.completed) {
|
||||
removeProgressBar();
|
||||
|
||||
@@ -26,6 +26,14 @@ function selected_gallery_index() {
|
||||
return all_gallery_buttons().findIndex(elem => elem.classList.contains('selected'));
|
||||
}
|
||||
|
||||
function gallery_container_buttons(gallery_container) {
|
||||
return gradioApp().querySelectorAll(`#${gallery_container} .thumbnail-item.thumbnail-small`);
|
||||
}
|
||||
|
||||
function selected_gallery_index_id(gallery_container) {
|
||||
return Array.from(gallery_container_buttons(gallery_container)).findIndex(elem => elem.classList.contains('selected'));
|
||||
}
|
||||
|
||||
function extract_image_from_gallery(gallery) {
|
||||
if (gallery.length == 0) {
|
||||
return [null];
|
||||
@@ -286,6 +294,7 @@ onAfterUiUpdate(function() {
|
||||
var jsdata = textarea.value;
|
||||
opts = JSON.parse(jsdata);
|
||||
|
||||
executeCallbacks(optionsAvailableCallbacks); /*global optionsAvailableCallbacks*/
|
||||
executeCallbacks(optionsChangedCallbacks); /*global optionsChangedCallbacks*/
|
||||
|
||||
Object.defineProperty(textarea, 'value', {
|
||||
@@ -324,8 +333,8 @@ onOptionsChanged(function() {
|
||||
let txt2img_textarea, img2img_textarea = undefined;
|
||||
|
||||
function restart_reload() {
|
||||
document.body.style.backgroundColor = "var(--background-fill-primary)";
|
||||
document.body.innerHTML = '<h1 style="font-family:monospace;margin-top:20%;color:lightgray;text-align:center;">Reloading...</h1>';
|
||||
|
||||
var requestPing = function() {
|
||||
requestGet("./internal/ping", {}, function(data) {
|
||||
location.reload();
|
||||
|
||||
Reference in New Issue
Block a user