Skip to content

Commit

Permalink
new extension manager
Browse files Browse the repository at this point in the history
  • Loading branch information
vladmandic committed May 10, 2023
1 parent aad2a53 commit c5df801
Show file tree
Hide file tree
Showing 27 changed files with 2,964 additions and 3,001 deletions.
5 changes: 3 additions & 2 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,14 +1,15 @@
# defaults
__pycache__
/params.txt
/cache.json
/config.json
/ui-config.json
/params.txt
/setup.log
/styles.csv
/ui-config.json
/user.css
/webui-user.bat
/webui-user.sh
/html/extensions.json
/javascript/themes.json
node_modules
pnpm-lock.yaml
Expand Down
2 changes: 1 addition & 1 deletion extensions-builtin/stable-diffusion-webui-images-browser
7 changes: 4 additions & 3 deletions installer.py
Original file line number Diff line number Diff line change
Expand Up @@ -318,8 +318,9 @@ def run_extension_installer(folder):

# get list of all enabled extensions
def list_extensions(folder):
if opts.get('disable_all_extensions', 'none') != 'none':
log.debug('Disabled extensions: all')
disabled_extensions = opts.get('disable_all_extensions', 'none')
if disabled_extensions != 'none':
log.debug(f'Disabled extensions: {disabled_extensions}')
return []
disabled_extensions = set(opts.get('disabled_extensions', []))
if len(disabled_extensions) > 0:
Expand Down Expand Up @@ -350,7 +351,7 @@ def install_extensions():
if not args.skip_extensions:
run_extension_installer(os.path.join(folder, ext))
log.info(f'Extensions enabled: {extensions_enabled}')
if (len(extensions_duplicates) > 0):
if len(extensions_duplicates) > 0:
log.warning(f'Extensions duplicates: {extensions_duplicates}')


Expand Down
213 changes: 106 additions & 107 deletions javascript/aspectRatioOverlay.js
Original file line number Diff line number Diff line change
@@ -1,107 +1,106 @@
let currentWidth = null;
let currentHeight = null;
let arFrameTimeout = setTimeout(() => {}, 0);

function dimensionChange(e, is_width, is_height) {
if (is_width) {
currentWidth = e.target.value * 1.0;
}
if (is_height) {
currentHeight = e.target.value * 1.0;
}

const inImg2img = gradioApp().querySelector('#tab_img2img').style.display == 'block';

if (!inImg2img) {
return;
}

let targetElement = null;

const tabIndex = get_tab_index('mode_img2img');
if (tabIndex == 0) { // img2img
targetElement = gradioApp().querySelector('#img2img_image div[data-testid=image] img');
} else if (tabIndex == 1) { // Sketch
targetElement = gradioApp().querySelector('#img2img_sketch div[data-testid=image] img');
} else if (tabIndex == 2) { // Inpaint
targetElement = gradioApp().querySelector('#img2maskimg div[data-testid=image] img');
} else if (tabIndex == 3) { // Inpaint sketch
targetElement = gradioApp().querySelector('#inpaint_sketch div[data-testid=image] img');
}

if (targetElement) {
let arPreviewRect = gradioApp().querySelector('#imageARPreview');
if (!arPreviewRect) {
arPreviewRect = document.createElement('div');
arPreviewRect.id = 'imageARPreview';
gradioApp().appendChild(arPreviewRect);
}

const viewportOffset = targetElement.getBoundingClientRect();

viewportscale = Math.min(targetElement.clientWidth / targetElement.naturalWidth, targetElement.clientHeight / targetElement.naturalHeight);

scaledx = targetElement.naturalWidth * viewportscale;
scaledy = targetElement.naturalHeight * viewportscale;

cleintRectTop = (viewportOffset.top + window.scrollY);
cleintRectLeft = (viewportOffset.left + window.scrollX);
cleintRectCentreY = cleintRectTop + (targetElement.clientHeight / 2);
cleintRectCentreX = cleintRectLeft + (targetElement.clientWidth / 2);

viewRectTop = cleintRectCentreY - (scaledy / 2);
viewRectLeft = cleintRectCentreX - (scaledx / 2);
arRectWidth = scaledx;
arRectHeight = scaledy;

arscale = Math.min(arRectWidth / currentWidth, arRectHeight / currentHeight);
arscaledx = currentWidth * arscale;
arscaledy = currentHeight * arscale;

arRectTop = cleintRectCentreY - (arscaledy / 2);
arRectLeft = cleintRectCentreX - (arscaledx / 2);
arRectWidth = arscaledx;
arRectHeight = arscaledy;

arPreviewRect.style.top = `${arRectTop}px`;
arPreviewRect.style.left = `${arRectLeft}px`;
arPreviewRect.style.width = `${arRectWidth}px`;
arPreviewRect.style.height = `${arRectHeight}px`;

clearTimeout(arFrameTimeout);
arFrameTimeout = setTimeout(() => {
arPreviewRect.style.display = 'none';
}, 2000);

arPreviewRect.style.display = 'block';
}
}

onUiUpdate(() => {
const arPreviewRect = gradioApp().querySelector('#imageARPreview');
if (arPreviewRect) {
arPreviewRect.style.display = 'none';
}
const tabImg2img = gradioApp().querySelector('#tab_img2img');
if (tabImg2img) {
const inImg2img = tabImg2img.style.display == 'block';
if (inImg2img) {
const inputs = gradioApp().querySelectorAll('input');
inputs.forEach((e) => {
const is_width = e.parentElement.id == 'img2img_width';
const is_height = e.parentElement.id == 'img2img_height';

if ((is_width || is_height) && !e.classList.contains('scrollwatch')) {
e.addEventListener('input', (e) => { dimensionChange(e, is_width, is_height); });
e.classList.add('scrollwatch');
}
if (is_width) {
currentWidth = e.value * 1.0;
}
if (is_height) {
currentHeight = e.value * 1.0;
}
});
}
}
});
let currentWidth = null;
let currentHeight = null;
let arFrameTimeout = setTimeout(() => {}, 0);

function dimensionChange(e, is_width, is_height) {
if (is_width) {
currentWidth = e.target.value * 1.0;
}
if (is_height) {
currentHeight = e.target.value * 1.0;
}

const inImg2img = gradioApp().querySelector('#tab_img2img').style.display === 'block';

if (!inImg2img) {
return;
}

let targetElement = null;

const tabIndex = get_tab_index('mode_img2img');
if (tabIndex === 0) { // img2img
targetElement = gradioApp().querySelector('#img2img_image div[data-testid=image] img');
} else if (tabIndex === 1) { // Sketch
targetElement = gradioApp().querySelector('#img2img_sketch div[data-testid=image] img');
} else if (tabIndex === 2) { // Inpaint
targetElement = gradioApp().querySelector('#img2maskimg div[data-testid=image] img');
} else if (tabIndex === 3) { // Inpaint sketch
targetElement = gradioApp().querySelector('#inpaint_sketch div[data-testid=image] img');
}

if (targetElement) {
let arPreviewRect = gradioApp().querySelector('#imageARPreview');
if (!arPreviewRect) {
arPreviewRect = document.createElement('div');
arPreviewRect.id = 'imageARPreview';
gradioApp().appendChild(arPreviewRect);
}

const viewportOffset = targetElement.getBoundingClientRect();

viewportscale = Math.min(targetElement.clientWidth / targetElement.naturalWidth, targetElement.clientHeight / targetElement.naturalHeight);

scaledx = targetElement.naturalWidth * viewportscale;
scaledy = targetElement.naturalHeight * viewportscale;

cleintRectTop = (viewportOffset.top + window.scrollY);
cleintRectLeft = (viewportOffset.left + window.scrollX);
cleintRectCentreY = cleintRectTop + (targetElement.clientHeight / 2);
cleintRectCentreX = cleintRectLeft + (targetElement.clientWidth / 2);

viewRectTop = cleintRectCentreY - (scaledy / 2);
viewRectLeft = cleintRectCentreX - (scaledx / 2);
arRectWidth = scaledx;
arRectHeight = scaledy;

arscale = Math.min(arRectWidth / currentWidth, arRectHeight / currentHeight);
arscaledx = currentWidth * arscale;
arscaledy = currentHeight * arscale;

arRectTop = cleintRectCentreY - (arscaledy / 2);
arRectLeft = cleintRectCentreX - (arscaledx / 2);
arRectWidth = arscaledx;
arRectHeight = arscaledy;

arPreviewRect.style.top = `${arRectTop}px`;
arPreviewRect.style.left = `${arRectLeft}px`;
arPreviewRect.style.width = `${arRectWidth}px`;
arPreviewRect.style.height = `${arRectHeight}px`;

clearTimeout(arFrameTimeout);
arFrameTimeout = setTimeout(() => {
arPreviewRect.style.display = 'none';
}, 2000);
arPreviewRect.style.display = 'block';
}
}

onUiUpdate(() => {
const arPreviewRect = gradioApp().querySelector('#imageARPreview');
if (arPreviewRect) {
arPreviewRect.style.display = 'none';
}
const tabImg2img = gradioApp().querySelector('#tab_img2img');
if (tabImg2img) {
const inImg2img = tabImg2img.style.display === 'block';
if (inImg2img) {
const inputs = gradioApp().querySelectorAll('input');
inputs.forEach((e) => {
const is_width = e.parentElement.id === 'img2img_width';
const is_height = e.parentElement.id === 'img2img_height';

if ((is_width || is_height) && !e.classList.contains('scrollwatch')) {
e.addEventListener('input', (e) => { dimensionChange(e, is_width, is_height); });
e.classList.add('scrollwatch');
}
if (is_width) {
currentWidth = e.value * 1.0;
}
if (is_height) {
currentHeight = e.value * 1.0;
}
});
}
}
});
Loading

0 comments on commit c5df801

Please sign in to comment.