From 1556f8d7924e6de04a8d8da465e9ba1a4fac9589 Mon Sep 17 00:00:00 2001 From: tim h Date: Sat, 14 Jan 2023 16:33:39 -0600 Subject: [PATCH 01/14] fixes issue 167? --- index.html | 1 + js/index.js | 24 +++++++++++++++++++++++- 2 files changed, 24 insertions(+), 1 deletion(-) diff --git a/index.html b/index.html index f87960c..56ed091 100644 --- a/index.html +++ b/index.html @@ -83,6 +83,7 @@ Stable Diffusion settings
+
diff --git a/js/index.js b/js/index.js index 87a8929..41c98bc 100644 --- a/js/index.js +++ b/js/index.js @@ -589,7 +589,7 @@ const makeSlider = ( }); }; -const modelAutoComplete = createAutoComplete( +let modelAutoComplete = createAutoComplete( "Model", document.getElementById("models-ac-select") ); @@ -956,6 +956,28 @@ async function getUpscalers() { */ } +async function refreshModels() { + var original = document.getElementById("models-ac-select"); + var newdiv = document.createElement("div"); + newdiv.id = "models-ac-select"; + original.replaceWith(newdiv); + modelAutoComplete = createAutoComplete( + "Model", + document.getElementById("models-ac-select") + ); + modelAutoComplete.onchange.on(({value}) => { + if (value.toLowerCase().includes("inpainting")) + document.querySelector( + "#models-ac-select input.autocomplete-text" + ).style.backgroundColor = "#cfc"; + else + document.querySelector( + "#models-ac-select input.autocomplete-text" + ).style.backgroundColor = "#fcc"; + }); + getModels(); +} + async function getModels() { const url = document.getElementById("host").value + "/sdapi/v1/sd-models"; let opt = null; From 52c6f0608a351cca21ee72c8985b77b8a879115e Mon Sep 17 00:00:00 2001 From: zero01101 Date: Sat, 14 Jan 2023 22:38:25 +0000 Subject: [PATCH 02/14] Fixed resource hashes --- index.html | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/index.html b/index.html index 56ed091..8f3b70a 100644 --- a/index.html +++ b/index.html @@ -360,7 +360,7 @@ - + - + - + - + - + - + From 874e39de4bf87b584da6715f7e2bdfa23cfaa491 Mon Sep 17 00:00:00 2001 From: Victor Seiji Hariki Date: Mon, 16 Jan 2023 23:20:13 -0300 Subject: [PATCH 11/14] add Ctrl+A and Ctrl+Shift+A shortcuts to select selects all layer content and all visible (still only on current layer) Signed-off-by: Victor Seiji Hariki --- index.html | 4 +- js/lib/input.js | 1 + js/ui/tool/select.js | 93 +++++++++++++++++++++++++++++++------------- 3 files changed, 68 insertions(+), 30 deletions(-) diff --git a/index.html b/index.html index 6878c2d..d033f86 100644 --- a/index.html +++ b/index.html @@ -350,7 +350,7 @@ - + @@ -388,7 +388,7 @@ src="js/ui/tool/colorbrush.js?v=3f8c01a" type="text/javascript"> + @@ -388,7 +388,7 @@ src="js/ui/tool/colorbrush.js?v=3f8c01a" type="text/javascript"> - + diff --git a/js/global.js b/js/global.js index 91d0f81..446758f 100644 --- a/js/global.js +++ b/js/global.js @@ -53,6 +53,9 @@ const global = { // HRFix compatibility shenanigans isOldHRFix: false, + + // WebUI object to communitate with parent window + webui: null, }; global._firstRun = !localStorage.getItem("openoutpaint/host"); diff --git a/js/ui/tool/select.js b/js/ui/tool/select.js index 6a1095b..2432c8e 100644 --- a/js/ui/tool/select.js +++ b/js/ui/tool/select.js @@ -714,7 +714,7 @@ const selectTransformTool = () => createVisibleResourceButton.disabled = true; }; - // Disable buttons (if something is selected) + // Enable buttons (if something is selected) state.ctxmenu.enableButtons = () => { saveSelectionButton.disabled = ""; createResourceButton.disabled = ""; @@ -723,6 +723,21 @@ const selectTransformTool = () => }; state.ctxmenu.actionArray = actionArray; state.ctxmenu.visibleActionArray = visibleActionArray; + + // Send Selection to Destination + state.ctxmenu.sendSelected = document.createElement("select"); + state.ctxmenu.sendSelected.style.width = "100%"; + state.ctxmenu.sendSelected.addEventListener("change", (evn) => { + const v = evn.target.value; + if (state.selected && v !== "None") + global.webui && global.webui.sendTo(state.selected.canvas, v); + evn.target.value = "None"; + }); + + let opt = document.createElement("option"); + opt.textContent = "Send To..."; + opt.value = "None"; + state.ctxmenu.sendSelected.appendChild(opt); } const array = document.createElement("div"); array.classList.add("checkbox-array"); @@ -733,6 +748,23 @@ const selectTransformTool = () => menu.appendChild(state.ctxmenu.selectionPeekOpacitySlider); menu.appendChild(state.ctxmenu.actionArray); menu.appendChild(state.ctxmenu.visibleActionArray); + if (global.webui && global.webui.destinations) { + while (state.ctxmenu.sendSelected.lastChild.value !== "None") { + state.ctxmenu.sendSelected.removeChild( + state.ctxmenu.sendSelected.lastChild + ); + } + + global.webui.destinations.forEach((dst) => { + const opt = document.createElement("option"); + opt.textContent = dst.name; + opt.value = dst.id; + + state.ctxmenu.sendSelected.appendChild(opt); + }); + + menu.appendChild(state.ctxmenu.sendSelected); + } }, shortcut: "S", } diff --git a/js/webui.js b/js/webui.js index 9995582..de934f6 100644 --- a/js/webui.js +++ b/js/webui.js @@ -2,6 +2,32 @@ * This file should only be actually loaded if we are in a trusted environment. */ (async () => { + let parentWindow = null; + const webui = { + /** @type {{name: string, id: string}[]} */ + destinations: null, + + /** + * Sends a + * + * @param {HTMLCanvas} canvas Canvas to send the data of + * @param {string} destination The ID of the destination + */ + sendTo(canvas, destination) { + if (!this.destinations.find((d) => d.id === destination)) + throw new Error("[webui] Given destination is not available"); + + parentWindow && + parentWindow.postMessage({ + type: "openoutpaint/sendto", + message: { + image: canvas.toDataURL(), + destination, + }, + }); + }, + }; + // Check if key file exists const response = await fetch("key.json"); @@ -48,8 +74,6 @@ } if (data) { - let parentWindow = null; - if (!data.trusted) console.debug(`[webui] Loaded key`); window.addEventListener("message", ({data, origin, source}) => { @@ -65,6 +89,11 @@ console.warn(`[webui] Communication has not been initialized`); } + if (global.debug) { + console.debug("[webui] Received message:"); + console.debug(data); + } + try { switch (data.type) { case "openoutpaint/init": @@ -77,6 +106,7 @@ data.host, `Are you sure you want to modify the host?\nThis configuration was provided by the hosting page\n - ${parentWindow.document.title} (${origin})` ); + if (data.destinations) webui.destinations = data.destinations; break; case "openoutpaint/add-resource": @@ -142,4 +172,7 @@ } }); } -})(); + return webui; +})().then((value) => { + global.webui = value; +}); diff --git a/pages/embed.test.html b/pages/embed.test.html index b4ac0ab..ba38bc4 100644 --- a/pages/embed.test.html +++ b/pages/embed.test.html @@ -8,8 +8,8 @@ - + @@ -358,15 +358,16 @@ + - +