Corrected the code according to Code style

This commit is contained in:
Danil Boldyrev 2023-05-28 20:22:35 +03:00
parent 9e69009d1b
commit f48bce5f68

View File

@ -19,7 +19,7 @@ onUiLoaded(async () => {
resetZoom: "KeyR", resetZoom: "KeyR",
fitToScreen: "KeyS", fitToScreen: "KeyS",
moveKey: "KeyF", moveKey: "KeyF",
overlap: "KeyO", overlap: "KeyO"
}; };
let isMoving = false; let isMoving = false;
@ -29,12 +29,12 @@ onUiLoaded(async () => {
sketch: "#img2img_sketch", sketch: "#img2img_sketch",
inpaint: "#img2maskimg", inpaint: "#img2maskimg",
inpaintSketch: "#inpaint_sketch", inpaintSketch: "#inpaint_sketch",
img2imgTabs: "#mode_img2img .tab-nav", img2imgTabs: "#mode_img2img .tab-nav"
}; };
async function getElements() { async function getElements() {
const elements = await Promise.all( const elements = await Promise.all(
Object.values(elementIDs).map((id) => document.querySelector(id)) Object.values(elementIDs).map(id => document.querySelector(id))
); );
return Object.fromEntries( return Object.fromEntries(
Object.keys(elementIDs).map((key, index) => [key, elements[index]]) Object.keys(elementIDs).map((key, index) => [key, elements[index]])
@ -116,13 +116,18 @@ onUiLoaded(async () => {
percentage = 5 percentage = 5
) { ) {
const input = const input =
document.querySelector(`${elemId} input[aria-label='Brush radius']`) || document.querySelector(
document.querySelector(`${elemId} button[aria-label="Use brush"]`); `${elemId} input[aria-label='Brush radius']`
) ||
document.querySelector(
`${elemId} button[aria-label="Use brush"]`
);
if (input) { if (input) {
input.click(); input.click();
if (!withoutValue) { if (!withoutValue) {
const maxValue = parseFloat(input.getAttribute("max")) || 100; const maxValue =
parseFloat(input.getAttribute("max")) || 100;
const changeAmount = maxValue * (percentage / 100); const changeAmount = maxValue * (percentage / 100);
const newValue = const newValue =
parseFloat(input.value) + parseFloat(input.value) +
@ -134,7 +139,7 @@ onUiLoaded(async () => {
} }
// Reset zoom when uploading a new image // Reset zoom when uploading a new image
fileInput = document.querySelector( const fileInput = document.querySelector(
`${elemId} input[type="file"][accept="image/*"].svelte-116rqfv` `${elemId} input[type="file"][accept="image/*"].svelte-116rqfv`
); );
fileInput.addEventListener("click", resetZoom); fileInput.addEventListener("click", resetZoom);
@ -211,7 +216,8 @@ onUiLoaded(async () => {
const originYValue = parseFloat(originY); const originYValue = parseFloat(originY);
const offsetX = const offsetX =
(screenWidth - elementWidth * scale) / 2 - originXValue * (1 - scale); (screenWidth - elementWidth * scale) / 2 -
originXValue * (1 - scale);
const offsetY = const offsetY =
(screenHeight - elementHeight * scale) / 2.5 - (screenHeight - elementHeight * scale) / 2.5 -
originYValue * (1 - scale); originYValue * (1 - scale);
@ -305,7 +311,7 @@ onUiLoaded(async () => {
const hotkeyActions = { const hotkeyActions = {
[hotkeysConfig.resetZoom]: resetZoom, [hotkeysConfig.resetZoom]: resetZoom,
[hotkeysConfig.overlap]: toggleOverlap, [hotkeysConfig.overlap]: toggleOverlap,
[hotkeysConfig.fitToScreen]: fitToScreen, [hotkeysConfig.fitToScreen]: fitToScreen
// [hotkeysConfig.moveKey] : moveCanvas, // [hotkeysConfig.moveKey] : moveCanvas,
}; };
@ -354,7 +360,7 @@ onUiLoaded(async () => {
} }
}); });
targetElement.addEventListener("wheel", (e) => { targetElement.addEventListener("wheel", e => {
// change zoom level // change zoom level
const operation = e.deltaY > 0 ? "-" : "+"; const operation = e.deltaY > 0 ? "-" : "+";
changeZoomLevel(operation, e); changeZoomLevel(operation, e);