From 903acff924af4531bff907710c69a91265a0347d Mon Sep 17 00:00:00 2001 From: patriceac <48073125+patriceac@users.noreply.github.com> Date: Thu, 10 Nov 2022 18:36:39 -0800 Subject: [PATCH 01/20] Adding Use Settings --- ui/media/css/main.css | 10 ++++++ ui/media/js/image-modifiers.js | 54 +++++++++++++++++++++++++++++++- ui/media/js/main.js | 57 +++++++++++++++++++++++++++++----- 3 files changed, 113 insertions(+), 8 deletions(-) diff --git a/ui/media/css/main.css b/ui/media/css/main.css index da87216d..33d18177 100644 --- a/ui/media/css/main.css +++ b/ui/media/css/main.css @@ -428,6 +428,16 @@ img { .secondaryButton:hover { background: rgb(177, 27, 0); } +.useSettings { + background: var(--accent-color); + border: var(--make-image-border); + color: rgb(255, 221, 255); + margin-right: 6pt; + float: right; +} +.useSettings:hover { + background: hsl(var(--accent-hue), 100%, calc(var(--accent-lightness) + 6%)); +} .stopTask { float: right; } diff --git a/ui/media/js/image-modifiers.js b/ui/media/js/image-modifiers.js index 12bdd65f..8cf26a49 100644 --- a/ui/media/js/image-modifiers.js +++ b/ui/media/js/image-modifiers.js @@ -148,6 +148,58 @@ async function loadModifiers() { loadCustomModifiers() } +function refreshModifiersState(newTags) { + // clear existing modifiers + document.querySelector('#editor-modifiers').querySelectorAll('.modifier-card').forEach(modifierCard => { + const modifierName = modifierCard.querySelector('.modifier-card-label').innerText + if (activeTags.map(x => x.name).includes(modifierName)) { + modifierCard.classList.remove(activeCardClass) + modifierCard.querySelector('.modifier-card-image-overlay').innerText = '+' + } + }) + activeTags = [] + + // set new modifiers + newTags.forEach(tag => { + let found = false + document.querySelector('#editor-modifiers').querySelectorAll('.modifier-card').forEach(modifierCard => { + const modifierName = modifierCard.querySelector('.modifier-card-label').innerText + if (tag == modifierName) { + // add modifier to active array + activeTags.push({ + 'name': modifierName, + 'element': modifierCard.cloneNode(true), + 'originElement': modifierCard + }) + modifierCard.classList.add(activeCardClass) + modifierCard.querySelector('.modifier-card-image-overlay').innerText = '-' + found = true + } + }) + if (found == false) { // custom tag went missing, create one here + let modifierCard = createModifierCard(tag, undefined) // create a modifier card for the missing tag, no image + + modifierCard.addEventListener('click', () => { + if (activeTags.map(x => x.name).includes(tag)) { + // remove modifier from active array + activeTags = activeTags.filter(x => x.name != tag) + modifierCard.classList.remove(activeCardClass) + + modifierCard.querySelector('.modifier-card-image-overlay').innerText = '+' + } + refreshTagsList() + }) + + activeTags.push({ + 'name': tag, + 'element': modifierCard, + 'originElement': undefined // no origin element for missing tags + }) + } + }) + refreshTagsList() +} + function refreshTagsList() { editorModifierTagsList.innerHTML = '' @@ -167,7 +219,7 @@ function refreshTagsList() { tag.element.addEventListener('click', () => { let idx = activeTags.indexOf(tag) - if (idx !== -1) { + if (idx !== -1 && activeTags[idx].originElement !== undefined) { activeTags[idx].originElement.classList.remove(activeCardClass) activeTags[idx].originElement.querySelector('.modifier-card-image-overlay').innerText = '+' diff --git a/ui/media/js/main.js b/ui/media/js/main.js index b326dee3..f6103eba 100644 --- a/ui/media/js/main.js +++ b/ui/media/js/main.js @@ -780,7 +780,9 @@ function getCurrentUserRequest() { stream_progress_updates: true, stream_image_progress: (numOutputsTotal > 50 ? false : streamImageProgressField.checked), show_only_filtered_image: showOnlyFilteredImageField.checked, - output_format: outputFormatField.value + output_format: outputFormatField.value, + original_prompt: promptField.value, + active_tags: (activeTags.map(x => x.name)) } } if (IMAGE_REGEX.test(initImagePreview.src)) { @@ -855,6 +857,7 @@ function createTask(task) { taskEntry.innerHTML = `
Enqueued
+
${taskConfig}
@@ -893,6 +896,47 @@ function createTask(task) { } }) + task['useSettings'] = taskEntry.querySelector('.useSettings') + task['useSettings'].addEventListener('click', async function(e) { + TASK_REQ_NO_EXPORT.forEach((key) => delete task.reqBody[key]) // don't restore system settings when restoring tasks + restoreTaskToUI(task) + e.stopPropagation(); + + // restore the original tag + promptField.value = task.reqBody.original_prompt + + // Restore modifiers + refreshModifiersState(task.reqBody.active_tags) + + // properly reset checkboxes + if (!('use_face_correction' in task.reqBody)) { + useFaceCorrectionField.checked = false + } + if (!('use_upscale' in task.reqBody)) { + useUpscalingField.checked = false + } + if (!('mask' in task.reqBody)) { + maskSetting.checked = false + } + + // Show the source picture if present + initImagePreview.src = (task.reqBody.init_image == undefined ? '' : task.reqBody.init_image) + if (IMAGE_REGEX.test(initImagePreview.src)) { + Boolean(task.reqBody.mask) ? inpaintingEditor.setImg(task.reqBody.mask) : inpaintingEditor.resetBackground() + initImagePreviewContainer.style.display = 'block' + inpaintingEditorContainer.style.display = 'none' + promptStrengthContainer.style.display = 'table-row' + //samplerSelectionContainer.style.display = 'none' + // maskSetting.checked = false + inpaintingEditorContainer.style.display = maskSetting.checked ? 'block' : 'none' + } else { + initImagePreviewContainer.style.display = 'none' + // inpaintingEditorContainer.style.display = 'none' + promptStrengthContainer.style.display = 'none' + // maskSetting.style.display = 'none' + } + }) + imagePreview.insertBefore(taskEntry, previewTools.nextSibling) task.previewPrompt.innerText = task.reqBody.prompt @@ -913,15 +957,14 @@ function getPrompts() { prompts = prompts.map(prompt => prompt.trim()) prompts = prompts.filter(prompt => prompt !== '') + if (activeTags.length > 0) { + const promptTags = activeTags.map(x => x.name).join(", ") + prompts = prompts.map((prompt) => `${prompt}, ${promptTags}`) + } let promptsToMake = applySetOperator(prompts) promptsToMake = applyPermuteOperator(promptsToMake) - if (activeTags.length <= 0) { - return promptsToMake - } - - const promptTags = activeTags.map(x => x.name).join(", ") - return promptsToMake.map((prompt) => `${prompt}, ${promptTags}`) + return promptsToMake } function applySetOperator(prompts) { From 332f2b0678e05ed4c496d6c74cfad66d555abb44 Mon Sep 17 00:00:00 2001 From: patriceac <48073125+patriceac@users.noreply.github.com> Date: Sat, 12 Nov 2022 19:04:23 -0800 Subject: [PATCH 02/20] Hotfix for CSS layout regression --- ui/media/css/main.css | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/ui/media/css/main.css b/ui/media/css/main.css index d878fa19..33d18177 100644 --- a/ui/media/css/main.css +++ b/ui/media/css/main.css @@ -28,7 +28,6 @@ label { font-size: 13px; margin-bottom: 6px; margin-top: 5px; - display: block; } .image_preview_container { margin-top: 10pt; @@ -657,9 +656,9 @@ input::file-selector-button { } @media (min-width: 700px) { - /* #editor { + #editor { max-width: 480px; - } */ + } .float-container { padding: 20px; } From a6f3e87921ec157cea3beec350e3d3c6a21f4df8 Mon Sep 17 00:00:00 2001 From: patriceac <48073125+patriceac@users.noreply.github.com> Date: Wed, 16 Nov 2022 00:35:02 -0800 Subject: [PATCH 03/20] Image modifiers drag-and-drop plugin --- ui/plugins/ui/modifiers-dnd.plugin.js | 100 ++++++++++++++++++++++++++ 1 file changed, 100 insertions(+) create mode 100644 ui/plugins/ui/modifiers-dnd.plugin.js diff --git a/ui/plugins/ui/modifiers-dnd.plugin.js b/ui/plugins/ui/modifiers-dnd.plugin.js new file mode 100644 index 00000000..9406cf82 --- /dev/null +++ b/ui/plugins/ui/modifiers-dnd.plugin.js @@ -0,0 +1,100 @@ +(function () { + "use strict" + + var styleSheet = document.createElement("style"); + styleSheet.textContent = ` + .modifier-card-tiny.drag-sort-active { + background: transparent; + border: 2px dashed white; + opacity:0.2; + } + `; + document.head.appendChild(styleSheet); + + // observe for changes in tag list + var observer = new MutationObserver(function (mutations) { + // mutations.forEach(function (mutation) { + if (editorModifierTagsList.childNodes.length > 0) { + ModifierDragAndDrop(editorModifierTagsList) + } + // }) + }) + + observer.observe(editorModifierTagsList, { + childList: true + }) + + let current + function ModifierDragAndDrop(target) { + editorModifierTagsList.ondragenter = (e) => { + e.preventDefault() + e.stopPropagation() + } + editorModifierTagsList.ondragover = (e) => { + e.preventDefault() + e.stopPropagation() + } + + let overlays = document.querySelector('#editor-inputs-tags-list').querySelectorAll('.modifier-card-overlay') + overlays.forEach (i => { + i.parentElement.draggable = true; + + i.parentElement.ondragstart = (e) => { + current = i + i.parentElement.getElementsByClassName('modifier-card-image-overlay')[0].innerText = '' + i.parentElement.draggable = true + i.parentElement.classList.add('drag-sort-active') + for(let item of document.querySelector('#editor-inputs-tags-list').getElementsByClassName('modifier-card-image-overlay')) { + if (item.parentElement.parentElement.getElementsByClassName('modifier-card-overlay')[0] != current) { + item.parentElement.parentElement.getElementsByClassName('modifier-card-image-overlay')[0].style.opacity = 0 + if(item.parentElement.getElementsByClassName('modifier-card-image').length > 0) { + item.parentElement.getElementsByClassName('modifier-card-image')[0].style.filter = 'none' + } + item.parentElement.parentElement.style.transform = 'none' + item.parentElement.parentElement.style.boxShadow = 'none' + } + item.innerText = '' + } + } + + i.ondragenter = (e) => { + e.preventDefault() + if (i != current) { + let currentPos = 0, droppedPos = 0; + for (let it = 0; it < overlays.length; it++) { + if (current == overlays[it]) { currentPos = it; } + if (i == overlays[it]) { droppedPos = it; } + } + + if (i.parentElement != current.parentElement) { + let currentPos = 0, droppedPos = 0 + for (let it = 0; it < overlays.length; it++) { + if (current == overlays[it]) { currentPos = it } + if (i == overlays[it]) { droppedPos = it } + } + if (currentPos < droppedPos) { + current = i.parentElement.parentNode.insertBefore(current.parentElement, i.parentElement.nextSibling).getElementsByClassName('modifier-card-overlay')[0] + } else { + current = i.parentElement.parentNode.insertBefore(current.parentElement, i.parentElement).getElementsByClassName('modifier-card-overlay')[0] + } + // update active tags + const tag = activeTags.splice(currentPos, 1) + activeTags.splice(droppedPos, 0, tag[0]) + } + } + }; + + i.ondragover = (e) => { + e.preventDefault() + } + + i.parentElement.ondragend = (e) => { + i.parentElement.classList.remove('drag-sort-active') + for(let item of document.querySelector('#editor-inputs-tags-list').getElementsByClassName('modifier-card-image-overlay')) { + item.style.opacity = '' + item.innerText = '-' + } + } + }) + } +})() From af4a925b54f8fe11a81e9df1fe36ba6fcd900e0a Mon Sep 17 00:00:00 2001 From: patriceac <48073125+patriceac@users.noreply.github.com> Date: Wed, 16 Nov 2022 00:38:17 -0800 Subject: [PATCH 04/20] Delete modifiers-dnd.plugin.js --- ui/plugins/ui/modifiers-dnd.plugin.js | 100 -------------------------- 1 file changed, 100 deletions(-) delete mode 100644 ui/plugins/ui/modifiers-dnd.plugin.js diff --git a/ui/plugins/ui/modifiers-dnd.plugin.js b/ui/plugins/ui/modifiers-dnd.plugin.js deleted file mode 100644 index 9406cf82..00000000 --- a/ui/plugins/ui/modifiers-dnd.plugin.js +++ /dev/null @@ -1,100 +0,0 @@ -(function () { - "use strict" - - var styleSheet = document.createElement("style"); - styleSheet.textContent = ` - .modifier-card-tiny.drag-sort-active { - background: transparent; - border: 2px dashed white; - opacity:0.2; - } - `; - document.head.appendChild(styleSheet); - - // observe for changes in tag list - var observer = new MutationObserver(function (mutations) { - // mutations.forEach(function (mutation) { - if (editorModifierTagsList.childNodes.length > 0) { - ModifierDragAndDrop(editorModifierTagsList) - } - // }) - }) - - observer.observe(editorModifierTagsList, { - childList: true - }) - - let current - function ModifierDragAndDrop(target) { - editorModifierTagsList.ondragenter = (e) => { - e.preventDefault() - e.stopPropagation() - } - editorModifierTagsList.ondragover = (e) => { - e.preventDefault() - e.stopPropagation() - } - - let overlays = document.querySelector('#editor-inputs-tags-list').querySelectorAll('.modifier-card-overlay') - overlays.forEach (i => { - i.parentElement.draggable = true; - - i.parentElement.ondragstart = (e) => { - current = i - i.parentElement.getElementsByClassName('modifier-card-image-overlay')[0].innerText = '' - i.parentElement.draggable = true - i.parentElement.classList.add('drag-sort-active') - for(let item of document.querySelector('#editor-inputs-tags-list').getElementsByClassName('modifier-card-image-overlay')) { - if (item.parentElement.parentElement.getElementsByClassName('modifier-card-overlay')[0] != current) { - item.parentElement.parentElement.getElementsByClassName('modifier-card-image-overlay')[0].style.opacity = 0 - if(item.parentElement.getElementsByClassName('modifier-card-image').length > 0) { - item.parentElement.getElementsByClassName('modifier-card-image')[0].style.filter = 'none' - } - item.parentElement.parentElement.style.transform = 'none' - item.parentElement.parentElement.style.boxShadow = 'none' - } - item.innerText = '' - } - } - - i.ondragenter = (e) => { - e.preventDefault() - if (i != current) { - let currentPos = 0, droppedPos = 0; - for (let it = 0; it < overlays.length; it++) { - if (current == overlays[it]) { currentPos = it; } - if (i == overlays[it]) { droppedPos = it; } - } - - if (i.parentElement != current.parentElement) { - let currentPos = 0, droppedPos = 0 - for (let it = 0; it < overlays.length; it++) { - if (current == overlays[it]) { currentPos = it } - if (i == overlays[it]) { droppedPos = it } - } - if (currentPos < droppedPos) { - current = i.parentElement.parentNode.insertBefore(current.parentElement, i.parentElement.nextSibling).getElementsByClassName('modifier-card-overlay')[0] - } else { - current = i.parentElement.parentNode.insertBefore(current.parentElement, i.parentElement).getElementsByClassName('modifier-card-overlay')[0] - } - // update active tags - const tag = activeTags.splice(currentPos, 1) - activeTags.splice(droppedPos, 0, tag[0]) - } - } - }; - - i.ondragover = (e) => { - e.preventDefault() - } - - i.parentElement.ondragend = (e) => { - i.parentElement.classList.remove('drag-sort-active') - for(let item of document.querySelector('#editor-inputs-tags-list').getElementsByClassName('modifier-card-image-overlay')) { - item.style.opacity = '' - item.innerText = '-' - } - } - }) - } -})() From 061cee207f2cb32ee3380e43e825300e305ea4a5 Mon Sep 17 00:00:00 2001 From: patriceac <48073125+patriceac@users.noreply.github.com> Date: Wed, 16 Nov 2022 00:39:41 -0800 Subject: [PATCH 05/20] Delete modifiers-dnd.plugin.js --- ui/plugins/ui/modifiers-dnd.plugin.js | 100 -------------------------- 1 file changed, 100 deletions(-) delete mode 100644 ui/plugins/ui/modifiers-dnd.plugin.js diff --git a/ui/plugins/ui/modifiers-dnd.plugin.js b/ui/plugins/ui/modifiers-dnd.plugin.js deleted file mode 100644 index 9406cf82..00000000 --- a/ui/plugins/ui/modifiers-dnd.plugin.js +++ /dev/null @@ -1,100 +0,0 @@ -(function () { - "use strict" - - var styleSheet = document.createElement("style"); - styleSheet.textContent = ` - .modifier-card-tiny.drag-sort-active { - background: transparent; - border: 2px dashed white; - opacity:0.2; - } - `; - document.head.appendChild(styleSheet); - - // observe for changes in tag list - var observer = new MutationObserver(function (mutations) { - // mutations.forEach(function (mutation) { - if (editorModifierTagsList.childNodes.length > 0) { - ModifierDragAndDrop(editorModifierTagsList) - } - // }) - }) - - observer.observe(editorModifierTagsList, { - childList: true - }) - - let current - function ModifierDragAndDrop(target) { - editorModifierTagsList.ondragenter = (e) => { - e.preventDefault() - e.stopPropagation() - } - editorModifierTagsList.ondragover = (e) => { - e.preventDefault() - e.stopPropagation() - } - - let overlays = document.querySelector('#editor-inputs-tags-list').querySelectorAll('.modifier-card-overlay') - overlays.forEach (i => { - i.parentElement.draggable = true; - - i.parentElement.ondragstart = (e) => { - current = i - i.parentElement.getElementsByClassName('modifier-card-image-overlay')[0].innerText = '' - i.parentElement.draggable = true - i.parentElement.classList.add('drag-sort-active') - for(let item of document.querySelector('#editor-inputs-tags-list').getElementsByClassName('modifier-card-image-overlay')) { - if (item.parentElement.parentElement.getElementsByClassName('modifier-card-overlay')[0] != current) { - item.parentElement.parentElement.getElementsByClassName('modifier-card-image-overlay')[0].style.opacity = 0 - if(item.parentElement.getElementsByClassName('modifier-card-image').length > 0) { - item.parentElement.getElementsByClassName('modifier-card-image')[0].style.filter = 'none' - } - item.parentElement.parentElement.style.transform = 'none' - item.parentElement.parentElement.style.boxShadow = 'none' - } - item.innerText = '' - } - } - - i.ondragenter = (e) => { - e.preventDefault() - if (i != current) { - let currentPos = 0, droppedPos = 0; - for (let it = 0; it < overlays.length; it++) { - if (current == overlays[it]) { currentPos = it; } - if (i == overlays[it]) { droppedPos = it; } - } - - if (i.parentElement != current.parentElement) { - let currentPos = 0, droppedPos = 0 - for (let it = 0; it < overlays.length; it++) { - if (current == overlays[it]) { currentPos = it } - if (i == overlays[it]) { droppedPos = it } - } - if (currentPos < droppedPos) { - current = i.parentElement.parentNode.insertBefore(current.parentElement, i.parentElement.nextSibling).getElementsByClassName('modifier-card-overlay')[0] - } else { - current = i.parentElement.parentNode.insertBefore(current.parentElement, i.parentElement).getElementsByClassName('modifier-card-overlay')[0] - } - // update active tags - const tag = activeTags.splice(currentPos, 1) - activeTags.splice(droppedPos, 0, tag[0]) - } - } - }; - - i.ondragover = (e) => { - e.preventDefault() - } - - i.parentElement.ondragend = (e) => { - i.parentElement.classList.remove('drag-sort-active') - for(let item of document.querySelector('#editor-inputs-tags-list').getElementsByClassName('modifier-card-image-overlay')) { - item.style.opacity = '' - item.innerText = '-' - } - } - }) - } -})() From 0c93c4754d5220ed9a547484bdb904db3531210e Mon Sep 17 00:00:00 2001 From: cmdr2 Date: Thu, 17 Nov 2022 10:49:22 +0530 Subject: [PATCH 06/20] Tabs to spaces --- ui/media/js/dnd.js | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) diff --git a/ui/media/js/dnd.js b/ui/media/js/dnd.js index 1a1c115d..f9914264 100644 --- a/ui/media/js/dnd.js +++ b/ui/media/js/dnd.js @@ -430,10 +430,10 @@ function checkWriteToClipboardPermission (result) { copyIcon.innerHTML = `Copy Image Settings` copyIcon.addEventListener('click', (event) => { event.stopPropagation() - // Add css class 'active' - copyIcon.classList.add('active') - // In 1000 ms remove the 'active' class - asyncDelay(1000).then(() => copyIcon.classList.remove('active')) + // Add css class 'active' + copyIcon.classList.add('active') + // In 1000 ms remove the 'active' class + asyncDelay(1000).then(() => copyIcon.classList.remove('active')) const uiState = readUI() TASK_REQ_NO_EXPORT.forEach((key) => delete uiState.reqBody[key]) if (uiState.reqBody.init_image && !IMAGE_REGEX.test(uiState.reqBody.init_image)) { @@ -450,10 +450,10 @@ function checkWriteToClipboardPermission (result) { pasteIcon.innerHTML = `Paste Image Settings` pasteIcon.addEventListener('click', (event) => { event.stopPropagation() - // Add css class 'active' - pasteIcon.classList.add('active') - // In 1000 ms remove the 'active' class - asyncDelay(1000).then(() => pasteIcon.classList.remove('active')) + // Add css class 'active' + pasteIcon.classList.add('active') + // In 1000 ms remove the 'active' class + asyncDelay(1000).then(() => pasteIcon.classList.remove('active')) pasteFromClipboard() }) resetSettings.parentNode.insertBefore(pasteIcon, resetSettings) From cc3186a683c1c347891d8f116d5f98af9aa29dcf Mon Sep 17 00:00:00 2001 From: cmdr2 Date: Thu, 17 Nov 2022 11:01:10 +0530 Subject: [PATCH 07/20] Highlight the Save settings button when pressed --- ui/index.html | 8 ++++---- ui/media/css/main.css | 3 +++ ui/media/js/dnd.js | 8 ++++---- ui/media/js/parameters.js | 3 +++ 4 files changed, 14 insertions(+), 8 deletions(-) diff --git a/ui/index.html b/ui/index.html index 81ab64be..9b04c9d0 100644 --- a/ui/index.html +++ b/ui/index.html @@ -7,7 +7,7 @@ - + @@ -328,15 +328,15 @@
- - + + - + - + - + - + - + - +