Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Sign in / Register
Toggle navigation
S
Stable Diffusion Webui
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Locked Files
Issues
0
Issues
0
List
Boards
Labels
Service Desk
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Security & Compliance
Security & Compliance
Dependency List
License Compliance
Packages
Packages
List
Container Registry
Analytics
Analytics
CI / CD
Code Review
Insights
Issues
Repository
Value Stream
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
novelai-storage
Stable Diffusion Webui
Commits
e89a248e
Commit
e89a248e
authored
Jun 05, 2023
by
AUTOMATIC1111
Committed by
GitHub
Jun 05, 2023
Browse files
Options
Browse Files
Download
Plain Diff
Merge pull request #11031 from akx/zoom-and-pan-namespace
Zoom and pan: namespace & simplify
parents
1dd8d571
2d4c66f7
Changes
1
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
111 additions
and
124 deletions
+111
-124
extensions-builtin/canvas-zoom-and-pan/javascript/zoom.js
extensions-builtin/canvas-zoom-and-pan/javascript/zoom.js
+111
-124
No files found.
extensions-builtin/canvas-zoom-and-pan/javascript/zoom.js
View file @
e89a248e
// Helper functions
onUiLoaded
(
async
()
=>
{
// Get active tab
const
elementIDs
=
{
function
getActiveTab
(
elements
,
all
=
false
)
{
img2imgTabs
:
"
#mode_img2img .tab-nav
"
,
inpaint
:
"
#img2maskimg
"
,
inpaintSketch
:
"
#inpaint_sketch
"
,
rangeGroup
:
"
#img2img_column_size
"
,
sketch
:
"
#img2img_sketch
"
,
};
const
tabNameToElementId
=
{
"
Inpaint sketch
"
:
elementIDs
.
inpaintSketch
,
"
Inpaint
"
:
elementIDs
.
inpaint
,
"
Sketch
"
:
elementIDs
.
sketch
,
};
// Helper functions
// Get active tab
function
getActiveTab
(
elements
,
all
=
false
)
{
const
tabs
=
elements
.
img2imgTabs
.
querySelectorAll
(
"
button
"
);
const
tabs
=
elements
.
img2imgTabs
.
querySelectorAll
(
"
button
"
);
if
(
all
)
return
tabs
;
if
(
all
)
return
tabs
;
...
@@ -10,40 +24,33 @@ function getActiveTab(elements, all = false) {
...
@@ -10,40 +24,33 @@ function getActiveTab(elements, all = false) {
return
tab
;
return
tab
;
}
}
}
}
}
}
// Get tab ID
// Get tab ID
function
getTabId
(
elements
,
elementID
s
)
{
function
getTabId
(
element
s
)
{
const
activeTab
=
getActiveTab
(
elements
);
const
activeTab
=
getActiveTab
(
elements
);
const
tabIdLookup
=
{
return
tabNameToElementId
[
activeTab
.
innerText
];
"
Sketch
"
:
elementIDs
.
sketch
,
}
"
Inpaint sketch
"
:
elementIDs
.
inpaintSketch
,
"
Inpaint
"
:
elementIDs
.
inpaint
// Wait until opts loaded
};
async
function
waitForOpts
()
{
return
tabIdLookup
[
activeTab
.
innerText
];
for
(;;)
{
}
if
(
window
.
opts
&&
Object
.
keys
(
window
.
opts
).
length
)
{
return
window
.
opts
;
// Wait until opts loaded
}
async
function
waitForOpts
()
{
await
new
Promise
(
resolve
=>
setTimeout
(
resolve
,
100
));
return
new
Promise
(
resolve
=>
{
}
const
checkInterval
=
setInterval
(()
=>
{
}
if
(
window
.
opts
&&
Object
.
keys
(
window
.
opts
).
length
!==
0
)
{
clearInterval
(
checkInterval
);
resolve
(
window
.
opts
);
}
},
100
);
});
}
// Check is hotkey valid
// Check is hotkey valid
function
isSingleLetter
(
value
)
{
function
isSingleLetter
(
value
)
{
return
(
return
(
typeof
value
===
"
string
"
&&
value
.
length
===
1
&&
/
[
a-z
]
/i
.
test
(
value
)
typeof
value
===
"
string
"
&&
value
.
length
===
1
&&
/
[
a-z
]
/i
.
test
(
value
)
);
);
}
}
// Create hotkeyConfig from opts
// Create hotkeyConfig from opts
function
createHotkeyConfig
(
defaultHotkeysConfig
,
hotkeysConfigOpts
)
{
function
createHotkeyConfig
(
defaultHotkeysConfig
,
hotkeysConfigOpts
)
{
const
result
=
{};
const
result
=
{};
const
usedKeys
=
new
Set
();
const
usedKeys
=
new
Set
();
...
@@ -70,18 +77,17 @@ function createHotkeyConfig(defaultHotkeysConfig, hotkeysConfigOpts) {
...
@@ -70,18 +77,17 @@ function createHotkeyConfig(defaultHotkeysConfig, hotkeysConfigOpts) {
}
}
return
result
;
return
result
;
}
}
/**
/**
* The restoreImgRedMask function displays a red mask around an image to indicate the aspect ratio.
* The restoreImgRedMask function displays a red mask around an image to indicate the aspect ratio.
* If the image display property is set to 'none', the mask breaks. To fix this, the function
* If the image display property is set to 'none', the mask breaks. To fix this, the function
* temporarily sets the display property to 'block' and then hides the mask again after 300 milliseconds
* temporarily sets the display property to 'block' and then hides the mask again after 300 milliseconds
* to avoid breaking the canvas. Additionally, the function adjusts the mask to work correctly on
* to avoid breaking the canvas. Additionally, the function adjusts the mask to work correctly on
* very long images.
* very long images.
*/
*/
function
restoreImgRedMask
(
elements
)
{
function
restoreImgRedMask
(
elements
,
elementIDs
)
{
const
mainTabId
=
getTabId
(
elements
);
const
mainTabId
=
getTabId
(
elements
,
elementIDs
);
if
(
!
mainTabId
)
return
;
if
(
!
mainTabId
)
return
;
...
@@ -112,10 +118,8 @@ function restoreImgRedMask(elements, elementIDs) {
...
@@ -112,10 +118,8 @@ function restoreImgRedMask(elements, elementIDs) {
setTimeout
(()
=>
{
setTimeout
(()
=>
{
img
.
style
.
display
=
"
none
"
;
img
.
style
.
display
=
"
none
"
;
},
400
);
},
400
);
}
}
// Main
onUiLoaded
(
async
()
=>
{
const
hotkeysConfigOpts
=
await
waitForOpts
();
const
hotkeysConfigOpts
=
await
waitForOpts
();
// Default config
// Default config
...
@@ -137,38 +141,22 @@ onUiLoaded(async() => {
...
@@ -137,38 +141,22 @@ onUiLoaded(async() => {
let
mouseX
,
mouseY
;
let
mouseX
,
mouseY
;
let
activeElement
;
let
activeElement
;
const
elementIDs
=
{
const
elements
=
Object
.
fromEntries
(
Object
.
keys
(
elementIDs
).
map
((
id
)
=>
[
sketch
:
"
#img2img_sketch
"
,
id
,
inpaint
:
"
#img2maskimg
"
,
gradioApp
().
querySelector
(
elementIDs
[
id
]),
inpaintSketch
:
"
#inpaint_sketch
"
,
]));
img2imgTabs
:
"
#mode_img2img .tab-nav
"
,
rangeGroup
:
"
#img2img_column_size
"
};
async
function
getElements
()
{
const
elements
=
await
Promise
.
all
(
Object
.
values
(
elementIDs
).
map
(
id
=>
gradioApp
().
querySelector
(
id
))
);
return
Object
.
fromEntries
(
Object
.
keys
(
elementIDs
).
map
((
key
,
index
)
=>
[
key
,
elements
[
index
]])
);
}
const
elements
=
await
getElements
();
const
elemData
=
{};
const
elemData
=
{};
// Apply functionality to the range inputs. Restore redmask and correct for long images.
// Apply functionality to the range inputs. Restore redmask and correct for long images.
const
rangeInputs
=
elements
.
rangeGroup
?
elements
.
rangeGroup
.
querySelectorAll
(
"
input
"
)
:
const
rangeInputs
=
elements
.
rangeGroup
?
Array
.
from
(
elements
.
rangeGroup
.
querySelectorAll
(
"
input
"
)
)
:
[
[
gradioApp
().
querySelector
(
"
#img2img_width input[type='range']
"
),
gradioApp
().
querySelector
(
"
#img2img_width input[type='range']
"
),
gradioApp
().
querySelector
(
"
#img2img_height input[type='range']
"
)
gradioApp
().
querySelector
(
"
#img2img_height input[type='range']
"
)
];
];
rangeInputs
.
forEach
(
input
=>
{
for
(
const
input
of
rangeInputs
)
{
if
(
input
)
{
input
?.
addEventListener
(
"
input
"
,
()
=>
restoreImgRedMask
(
elements
));
input
.
addEventListener
(
"
input
"
,
()
=>
restoreImgRedMask
(
elements
,
elementIDs
));
}
}
});
function
applyZoomAndPan
(
elemId
)
{
function
applyZoomAndPan
(
elemId
)
{
const
targetElement
=
gradioApp
().
querySelector
(
elemId
);
const
targetElement
=
gradioApp
().
querySelector
(
elemId
);
...
@@ -223,12 +211,11 @@ onUiLoaded(async() => {
...
@@ -223,12 +211,11 @@ onUiLoaded(async() => {
action
:
"
Move canvas
"
action
:
"
Move canvas
"
}
}
];
];
hotkeys
.
forEach
(
function
(
hotkey
)
{
for
(
const
hotkey
of
hotkeys
)
{
const
p
=
document
.
createElement
(
"
p
"
);
const
p
=
document
.
createElement
(
"
p
"
);
p
.
innerHTML
=
p
.
innerHTML
=
`<b>
${
hotkey
.
key
}
</b> -
${
hotkey
.
action
}
`
;
"
<b>
"
+
hotkey
.
key
+
"
</b>
"
+
"
-
"
+
hotkey
.
action
;
tooltipContent
.
appendChild
(
p
);
tooltipContent
.
appendChild
(
p
);
}
);
}
// Add information and content elements to the tooltip element
// Add information and content elements to the tooltip element
tooltip
.
appendChild
(
info
);
tooltip
.
appendChild
(
info
);
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment