aboutsummaryrefslogtreecommitdiff
path: root/javascript
diff options
context:
space:
mode:
Diffstat (limited to 'javascript')
-rw-r--r--javascript/badScaleChecker.js108
-rw-r--r--javascript/edit-attention.js5
-rw-r--r--javascript/edit-order.js41
-rw-r--r--javascript/extensions.js18
-rw-r--r--javascript/extraNetworks.js66
-rw-r--r--javascript/hints.js3
6 files changed, 227 insertions, 14 deletions
diff --git a/javascript/badScaleChecker.js b/javascript/badScaleChecker.js
new file mode 100644
index 00000000..625ad309
--- /dev/null
+++ b/javascript/badScaleChecker.js
@@ -0,0 +1,108 @@
+(function() {
+ var ignore = localStorage.getItem("bad-scale-ignore-it") == "ignore-it";
+
+ function getScale() {
+ var ratio = 0,
+ screen = window.screen,
+ ua = navigator.userAgent.toLowerCase();
+
+ if (window.devicePixelRatio !== undefined) {
+ ratio = window.devicePixelRatio;
+ } else if (~ua.indexOf('msie')) {
+ if (screen.deviceXDPI && screen.logicalXDPI) {
+ ratio = screen.deviceXDPI / screen.logicalXDPI;
+ }
+ } else if (window.outerWidth !== undefined && window.innerWidth !== undefined) {
+ ratio = window.outerWidth / window.innerWidth;
+ }
+
+ return ratio == 0 ? 0 : Math.round(ratio * 100);
+ }
+
+ var showing = false;
+
+ var div = document.createElement("div");
+ div.style.position = "fixed";
+ div.style.top = "0px";
+ div.style.left = "0px";
+ div.style.width = "100vw";
+ div.style.backgroundColor = "firebrick";
+ div.style.textAlign = "center";
+ div.style.zIndex = 99;
+
+ var b = document.createElement("b");
+ b.innerHTML = 'Bad Scale: ??% ';
+
+ div.appendChild(b);
+
+ var note1 = document.createElement("p");
+ note1.innerHTML = "Change your browser or your computer settings!";
+ note1.title = 'Just make sure "computer-scale" * "browser-scale" = 100% ,\n' +
+ "you can keep your computer-scale and only change this page's scale,\n" +
+ "for example: your computer-scale is 125%, just use [\"CTRL\"+\"-\"] to make your browser-scale of this page to 80%.";
+ div.appendChild(note1);
+
+ var note2 = document.createElement("p");
+ note2.innerHTML = " Otherwise, it will cause this page to not function properly!";
+ note2.title = "When you click \"Copy image to: [inpaint sketch]\" in some img2img's tab,\n" +
+ "if scale<100% the canvas will be invisible,\n" +
+ "else if scale>100% this page will take large amount of memory and CPU performance.";
+ div.appendChild(note2);
+
+ var btn = document.createElement("button");
+ btn.innerHTML = "Click here to ignore";
+
+ div.appendChild(btn);
+
+ function tryShowTopBar(scale) {
+ if (showing) return;
+
+ b.innerHTML = 'Bad Scale: ' + scale + '% ';
+
+ var updateScaleTimer = setInterval(function() {
+ var newScale = getScale();
+ b.innerHTML = 'Bad Scale: ' + newScale + '% ';
+ if (newScale == 100) {
+ var p = div.parentNode;
+ if (p != null) p.removeChild(div);
+ showing = false;
+ clearInterval(updateScaleTimer);
+ check();
+ }
+ }, 999);
+
+ btn.onclick = function() {
+ clearInterval(updateScaleTimer);
+ var p = div.parentNode;
+ if (p != null) p.removeChild(div);
+ ignore = true;
+ showing = false;
+ localStorage.setItem("bad-scale-ignore-it", "ignore-it");
+ };
+
+ document.body.appendChild(div);
+ }
+
+ function check() {
+ if (!ignore) {
+ var timer = setInterval(function() {
+ var scale = getScale();
+ if (scale != 100 && !ignore) {
+ tryShowTopBar(scale);
+ clearInterval(timer);
+ }
+ if (ignore) {
+ clearInterval(timer);
+ }
+ }, 999);
+ }
+ }
+
+ if (document.readyState != "complete") {
+ document.onreadystatechange = function() {
+ if (document.readyState != "complete") check();
+ };
+ } else {
+ check();
+ }
+})();
diff --git a/javascript/edit-attention.js b/javascript/edit-attention.js
index ffa73147..8906c892 100644
--- a/javascript/edit-attention.js
+++ b/javascript/edit-attention.js
@@ -100,11 +100,12 @@ function keyupEditAttention(event) {
if (String(weight).length == 1) weight += ".0";
if (closeCharacter == ')' && weight == 1) {
- text = text.slice(0, selectionStart - 1) + text.slice(selectionStart, selectionEnd) + text.slice(selectionEnd + 5);
+ var endParenPos = text.substring(selectionEnd).indexOf(')');
+ text = text.slice(0, selectionStart - 1) + text.slice(selectionStart, selectionEnd) + text.slice(selectionEnd + endParenPos + 1);
selectionStart--;
selectionEnd--;
} else {
- text = text.slice(0, selectionEnd + 1) + weight + text.slice(selectionEnd + 1 + end - 1);
+ text = text.slice(0, selectionEnd + 1) + weight + text.slice(selectionEnd + end);
}
target.focus();
diff --git a/javascript/edit-order.js b/javascript/edit-order.js
new file mode 100644
index 00000000..ed4ef9ac
--- /dev/null
+++ b/javascript/edit-order.js
@@ -0,0 +1,41 @@
+/* alt+left/right moves text in prompt */
+
+function keyupEditOrder(event) {
+ if (!opts.keyedit_move) return;
+
+ let target = event.originalTarget || event.composedPath()[0];
+ if (!target.matches("*:is([id*='_toprow'] [id*='_prompt'], .prompt) textarea")) return;
+ if (!event.altKey) return;
+
+ let isLeft = event.key == "ArrowLeft";
+ let isRight = event.key == "ArrowRight";
+ if (!isLeft && !isRight) return;
+ event.preventDefault();
+
+ let selectionStart = target.selectionStart;
+ let selectionEnd = target.selectionEnd;
+ let text = target.value;
+ let items = text.split(",");
+ let indexStart = (text.slice(0, selectionStart).match(/,/g) || []).length;
+ let indexEnd = (text.slice(0, selectionEnd).match(/,/g) || []).length;
+ let range = indexEnd - indexStart + 1;
+
+ if (isLeft && indexStart > 0) {
+ items.splice(indexStart - 1, 0, ...items.splice(indexStart, range));
+ target.value = items.join();
+ target.selectionStart = items.slice(0, indexStart - 1).join().length + (indexStart == 1 ? 0 : 1);
+ target.selectionEnd = items.slice(0, indexEnd).join().length;
+ } else if (isRight && indexEnd < items.length - 1) {
+ items.splice(indexStart + 1, 0, ...items.splice(indexStart, range));
+ target.value = items.join();
+ target.selectionStart = items.slice(0, indexStart + 1).join().length + 1;
+ target.selectionEnd = items.slice(0, indexEnd + 2).join().length;
+ }
+
+ event.preventDefault();
+ updateInput(target);
+}
+
+addEventListener('keydown', (event) => {
+ keyupEditOrder(event);
+});
diff --git a/javascript/extensions.js b/javascript/extensions.js
index efeaf3a5..1f7254c5 100644
--- a/javascript/extensions.js
+++ b/javascript/extensions.js
@@ -72,3 +72,21 @@ function config_state_confirm_restore(_, config_state_name, config_restore_type)
}
return [confirmed, config_state_name, config_restore_type];
}
+
+function toggle_all_extensions(event) {
+ gradioApp().querySelectorAll('#extensions .extension_toggle').forEach(function(checkbox_el) {
+ checkbox_el.checked = event.target.checked;
+ });
+}
+
+function toggle_extension() {
+ let all_extensions_toggled = true;
+ for (const checkbox_el of gradioApp().querySelectorAll('#extensions .extension_toggle')) {
+ if (!checkbox_el.checked) {
+ all_extensions_toggled = false;
+ break;
+ }
+ }
+
+ gradioApp().querySelector('#extensions .all_extensions_toggle').checked = all_extensions_toggled;
+}
diff --git a/javascript/extraNetworks.js b/javascript/extraNetworks.js
index b87bca3e..5582a6e5 100644
--- a/javascript/extraNetworks.js
+++ b/javascript/extraNetworks.js
@@ -113,7 +113,7 @@ function setupExtraNetworks() {
onUiLoaded(setupExtraNetworks);
-var re_extranet = /<([^:]+:[^:]+):[\d.]+>/;
+var re_extranet = /<([^:]+:[^:]+):[\d.]+>(.*)/;
var re_extranet_g = /\s+<([^:]+:[^:]+):[\d.]+>/g;
function tryToRemoveExtraNetworkFromPrompt(textarea, text) {
@@ -121,15 +121,22 @@ function tryToRemoveExtraNetworkFromPrompt(textarea, text) {
var replaced = false;
var newTextareaText;
if (m) {
+ var extraTextAfterNet = m[2];
var partToSearch = m[1];
- newTextareaText = textarea.value.replaceAll(re_extranet_g, function(found) {
+ var foundAtPosition = -1;
+ newTextareaText = textarea.value.replaceAll(re_extranet_g, function(found, net, pos) {
m = found.match(re_extranet);
if (m[1] == partToSearch) {
replaced = true;
+ foundAtPosition = pos;
return "";
}
return found;
});
+
+ if (foundAtPosition >= 0 && newTextareaText.substr(foundAtPosition, extraTextAfterNet.length) == extraTextAfterNet) {
+ newTextareaText = newTextareaText.substr(0, foundAtPosition) + newTextareaText.substr(foundAtPosition + extraTextAfterNet.length);
+ }
} else {
newTextareaText = textarea.value.replaceAll(new RegExp(text, "g"), function(found) {
if (found == text) {
@@ -182,19 +189,20 @@ function extraNetworksSearchButton(tabs_id, event) {
var globalPopup = null;
var globalPopupInner = null;
+function closePopup() {
+ if (!globalPopup) return;
+
+ globalPopup.style.display = "none";
+}
function popup(contents) {
if (!globalPopup) {
globalPopup = document.createElement('div');
- globalPopup.onclick = function() {
- globalPopup.style.display = "none";
- };
+ globalPopup.onclick = closePopup;
globalPopup.classList.add('global-popup');
var close = document.createElement('div');
close.classList.add('global-popup-close');
- close.onclick = function() {
- globalPopup.style.display = "none";
- };
+ close.onclick = closePopup;
close.title = "Close";
globalPopup.appendChild(close);
@@ -205,7 +213,7 @@ function popup(contents) {
globalPopupInner.classList.add('global-popup-inner');
globalPopup.appendChild(globalPopupInner);
- gradioApp().appendChild(globalPopup);
+ gradioApp().querySelector('.main').appendChild(globalPopup);
}
globalPopupInner.innerHTML = '';
@@ -263,3 +271,43 @@ function extraNetworksRequestMetadata(event, extraPage, cardName) {
event.stopPropagation();
}
+
+var extraPageUserMetadataEditors = {};
+
+function extraNetworksEditUserMetadata(event, tabname, extraPage, cardName) {
+ var id = tabname + '_' + extraPage + '_edit_user_metadata';
+
+ var editor = extraPageUserMetadataEditors[id];
+ if (!editor) {
+ editor = {};
+ editor.page = gradioApp().getElementById(id);
+ editor.nameTextarea = gradioApp().querySelector("#" + id + "_name" + ' textarea');
+ editor.button = gradioApp().querySelector("#" + id + "_button");
+ extraPageUserMetadataEditors[id] = editor;
+ }
+
+ editor.nameTextarea.value = cardName;
+ updateInput(editor.nameTextarea);
+
+ editor.button.click();
+
+ popup(editor.page);
+
+ event.stopPropagation();
+}
+
+function extraNetworksRefreshSingleCard(page, tabname, name) {
+ requestGet("./sd_extra_networks/get-single-card", {page: page, tabname: tabname, name: name}, function(data) {
+ if (data && data.html) {
+ var card = gradioApp().querySelector('.card[data-name=' + JSON.stringify(name) + ']'); // likely using the wrong stringify function
+
+ var newDiv = document.createElement('DIV');
+ newDiv.innerHTML = data.html;
+ var newCard = newDiv.firstElementChild;
+
+ newCard.style = '';
+ card.parentElement.insertBefore(newCard, card);
+ card.parentElement.removeChild(card);
+ }
+ });
+}
diff --git a/javascript/hints.js b/javascript/hints.js
index dc75ce31..4167cb28 100644
--- a/javascript/hints.js
+++ b/javascript/hints.js
@@ -84,8 +84,6 @@ var titles = {
"Checkpoint name": "Loads weights from checkpoint before making images. You can either use hash or a part of filename (as seen in settings) for checkpoint name. Recommended to use with Y axis for less switching.",
"Inpainting conditioning mask strength": "Only applies to inpainting models. Determines how strongly to mask off the original image for inpainting and img2img. 1.0 means fully masked, which is the default behaviour. 0.0 means a fully unmasked conditioning. Lower values will help preserve the overall composition of the image, but will struggle with large changes.",
- "vram": "Torch active: Peak amount of VRAM used by Torch during generation, excluding cached data.\nTorch reserved: Peak amount of VRAM allocated by Torch, including all active and cached data.\nSys VRAM: Peak amount of VRAM allocation across all applications / total GPU VRAM (peak utilization%).",
-
"Eta noise seed delta": "If this values is non-zero, it will be added to seed and used to initialize RNG for noises when using samplers with Eta. You can use this to produce even more variation of images, or you can use this to match images of other software if you know what you are doing.",
"Filename word regex": "This regular expression will be used extract words from filename, and they will be joined using the option below into label text used for training. Leave empty to keep filename text as it is.",
@@ -110,7 +108,6 @@ var titles = {
"Upscale by": "Adjusts the size of the image by multiplying the original width and height by the selected value. Ignored if either Resize width to or Resize height to are non-zero.",
"Resize width to": "Resizes image to this width. If 0, width is inferred from either of two nearby sliders.",
"Resize height to": "Resizes image to this height. If 0, height is inferred from either of two nearby sliders.",
- "Multiplier for extra networks": "When adding extra network such as Hypernetwork or Lora to prompt, use this multiplier for it.",
"Discard weights with matching name": "Regular expression; if weights's name matches it, the weights is not written to the resulting checkpoint. Use ^model_ema to discard EMA weights.",
"Extra networks tab order": "Comma-separated list of tab names; tabs listed here will appear in the extra networks UI first and in order listed.",
"Negative Guidance minimum sigma": "Skip negative prompt for steps where image is already mostly denoised; the higher this value, the more skips there will be; provides increased performance in exchange for minor quality reduction."