Move clamp to function

more-colors
missionfloyd 2023-06-10 17:20:26 -06:00
parent 04ebf76e16
commit 4de923420a
1 changed files with 12 additions and 14 deletions

View File

@ -1,29 +1,27 @@
onUiLoaded(function() {
gradioApp().querySelector("#qrcode_geo_latitude input").addEventListener("input", (event) => {
let target = event.originalTarget || event.composedPath()[0];
if (target.value < -90) {
target.value = -90;
} else if (target.value > 90) {
target.value = 90;
} else {
return;
let value = target.value;
if (value < -90 || value > 90) {
target.value = clamp(value, -90, 90)
updateInput(target);
}
updateInput(target);
});
gradioApp().querySelector("#qrcode_geo_longitude input").addEventListener("input", (event) => {
let target = event.originalTarget || event.composedPath()[0];
if (target.value < -180) {
target.value = -180;
} else if (target.value > 180) {
target.value = 180;
} else {
return;
let value = target.value;
if (value < -180 || value > 180) {
target.value = clamp(value, -180, 180)
updateInput(target);
}
updateInput(target);
});
});
function clamp(num, min, max) {
return Math.min(Math.max(num, min), max);
};
async function sendToControlnet(img, tab, index) {
const response = await fetch(img);
const blob = await response.blob();