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
696c338e
Commit
696c338e
authored
May 01, 2023
by
AUTOMATIC1111
Committed by
GitHub
May 01, 2023
Browse files
Options
Browse Files
Download
Plain Diff
Merge pull request #9953 from akx/js-misc-fixes
Miscellaneous JS fixes
parents
b463b8a1
50f63e22
Changes
15
Show whitespace changes
Inline
Side-by-side
Showing
15 changed files
with
88 additions
and
102 deletions
+88
-102
javascript/aspectRatioOverlay.js
javascript/aspectRatioOverlay.js
+14
-19
javascript/contextMenus.js
javascript/contextMenus.js
+5
-7
javascript/edit-attention.js
javascript/edit-attention.js
+4
-4
javascript/extensions.js
javascript/extensions.js
+6
-6
javascript/extraNetworks.js
javascript/extraNetworks.js
+9
-9
javascript/generationParams.js
javascript/generationParams.js
+1
-1
javascript/hints.js
javascript/hints.js
+3
-1
javascript/hires_fix.js
javascript/hires_fix.js
+6
-10
javascript/imageMaskFix.js
javascript/imageMaskFix.js
+6
-7
javascript/imageParams.js
javascript/imageParams.js
+0
-1
javascript/imageviewer.js
javascript/imageviewer.js
+4
-8
javascript/localization.js
javascript/localization.js
+5
-5
javascript/notification.js
javascript/notification.js
+3
-3
javascript/progressbar.js
javascript/progressbar.js
+3
-4
javascript/ui.js
javascript/ui.js
+19
-17
No files found.
javascript/aspectRatioOverlay.js
View file @
696c338e
...
@@ -45,29 +45,24 @@ function dimensionChange(e, is_width, is_height){
...
@@ -45,29 +45,24 @@ function dimensionChange(e, is_width, is_height){
var
viewportOffset
=
targetElement
.
getBoundingClientRect
();
var
viewportOffset
=
targetElement
.
getBoundingClientRect
();
viewportscale
=
Math
.
min
(
targetElement
.
clientWidth
/
targetElement
.
naturalWidth
,
targetElement
.
clientHeight
/
targetElement
.
naturalHeight
)
v
ar
v
iewportscale
=
Math
.
min
(
targetElement
.
clientWidth
/
targetElement
.
naturalWidth
,
targetElement
.
clientHeight
/
targetElement
.
naturalHeight
)
scaledx
=
targetElement
.
naturalWidth
*
viewportscale
var
scaledx
=
targetElement
.
naturalWidth
*
viewportscale
scaledy
=
targetElement
.
naturalHeight
*
viewportscale
var
scaledy
=
targetElement
.
naturalHeight
*
viewportscale
cleintRectTop
=
(
viewportOffset
.
top
+
window
.
scrollY
)
var
cleintRectTop
=
(
viewportOffset
.
top
+
window
.
scrollY
)
cleintRectLeft
=
(
viewportOffset
.
left
+
window
.
scrollX
)
var
cleintRectLeft
=
(
viewportOffset
.
left
+
window
.
scrollX
)
cleintRectCentreY
=
cleintRectTop
+
(
targetElement
.
clientHeight
/
2
)
var
cleintRectCentreY
=
cleintRectTop
+
(
targetElement
.
clientHeight
/
2
)
cleintRectCentreX
=
cleintRectLeft
+
(
targetElement
.
clientWidth
/
2
)
var
cleintRectCentreX
=
cleintRectLeft
+
(
targetElement
.
clientWidth
/
2
)
viewRectTop
=
cleintRectCentreY
-
(
scaledy
/
2
)
var
arscale
=
Math
.
min
(
scaledx
/
currentWidth
,
scaledy
/
currentHeight
)
viewRectLeft
=
cleintRectCentreX
-
(
scaledx
/
2
)
var
arscaledx
=
currentWidth
*
arscale
arRectWidth
=
scaledx
var
arscaledy
=
currentHeight
*
arscale
arRectHeight
=
scaledy
arscale
=
Math
.
min
(
arRectWidth
/
currentWidth
,
arRectHeight
/
currentHeight
)
var
arRectTop
=
cleintRectCentreY
-
(
arscaledy
/
2
)
arscaledx
=
currentWidth
*
arscale
var
arRectLeft
=
cleintRectCentreX
-
(
arscaledx
/
2
)
arscaledy
=
currentHeight
*
arscale
var
arRectWidth
=
arscaledx
var
arRectHeight
=
arscaledy
arRectTop
=
cleintRectCentreY
-
(
arscaledy
/
2
)
arRectLeft
=
cleintRectCentreX
-
(
arscaledx
/
2
)
arRectWidth
=
arscaledx
arRectHeight
=
arscaledy
arPreviewRect
.
style
.
top
=
arRectTop
+
'
px
'
;
arPreviewRect
.
style
.
top
=
arRectTop
+
'
px
'
;
arPreviewRect
.
style
.
left
=
arRectLeft
+
'
px
'
;
arPreviewRect
.
style
.
left
=
arRectLeft
+
'
px
'
;
...
...
javascript/contextMenus.js
View file @
696c338e
...
@@ -4,7 +4,7 @@ contextMenuInit = function(){
...
@@ -4,7 +4,7 @@ contextMenuInit = function(){
let
menuSpecs
=
new
Map
();
let
menuSpecs
=
new
Map
();
const
uid
=
function
(){
const
uid
=
function
(){
return
Date
.
now
().
toString
(
36
)
+
Math
.
random
().
toString
(
36
).
substr
(
2
);
return
Date
.
now
().
toString
(
36
)
+
Math
.
random
().
toString
(
36
).
substr
ing
(
2
);
}
}
function
showContextMenu
(
event
,
element
,
menuEntries
){
function
showContextMenu
(
event
,
element
,
menuEntries
){
...
@@ -16,8 +16,7 @@ contextMenuInit = function(){
...
@@ -16,8 +16,7 @@ contextMenuInit = function(){
oldMenu
.
remove
()
oldMenu
.
remove
()
}
}
let
tabButton
=
uiCurrentTab
let
baseStyle
=
window
.
getComputedStyle
(
uiCurrentTab
)
let
baseStyle
=
window
.
getComputedStyle
(
tabButton
)
const
contextMenu
=
document
.
createElement
(
'
nav
'
)
const
contextMenu
=
document
.
createElement
(
'
nav
'
)
contextMenu
.
id
=
"
context-menu
"
contextMenu
.
id
=
"
context-menu
"
...
@@ -36,7 +35,7 @@ contextMenuInit = function(){
...
@@ -36,7 +35,7 @@ contextMenuInit = function(){
menuEntries
.
forEach
(
function
(
entry
){
menuEntries
.
forEach
(
function
(
entry
){
let
contextMenuEntry
=
document
.
createElement
(
'
a
'
)
let
contextMenuEntry
=
document
.
createElement
(
'
a
'
)
contextMenuEntry
.
innerHTML
=
entry
[
'
name
'
]
contextMenuEntry
.
innerHTML
=
entry
[
'
name
'
]
contextMenuEntry
.
addEventListener
(
"
click
"
,
function
(
e
)
{
contextMenuEntry
.
addEventListener
(
"
click
"
,
function
()
{
entry
[
'
func
'
]();
entry
[
'
func
'
]();
})
})
contextMenuList
.
append
(
contextMenuEntry
);
contextMenuList
.
append
(
contextMenuEntry
);
...
@@ -63,7 +62,7 @@ contextMenuInit = function(){
...
@@ -63,7 +62,7 @@ contextMenuInit = function(){
function
appendContextMenuOption
(
targetElementSelector
,
entryName
,
entryFunction
){
function
appendContextMenuOption
(
targetElementSelector
,
entryName
,
entryFunction
){
currentItems
=
menuSpecs
.
get
(
targetElementSelector
)
var
currentItems
=
menuSpecs
.
get
(
targetElementSelector
)
if
(
!
currentItems
){
if
(
!
currentItems
){
currentItems
=
[]
currentItems
=
[]
...
@@ -79,7 +78,7 @@ contextMenuInit = function(){
...
@@ -79,7 +78,7 @@ contextMenuInit = function(){
}
}
function
removeContextMenuOption
(
uid
){
function
removeContextMenuOption
(
uid
){
menuSpecs
.
forEach
(
function
(
v
,
k
)
{
menuSpecs
.
forEach
(
function
(
v
)
{
let
index
=
-
1
let
index
=
-
1
v
.
forEach
(
function
(
e
,
ei
){
if
(
e
[
'
id
'
]
==
uid
){
index
=
ei
}})
v
.
forEach
(
function
(
e
,
ei
){
if
(
e
[
'
id
'
]
==
uid
){
index
=
ei
}})
if
(
index
>=
0
){
if
(
index
>=
0
){
...
@@ -112,7 +111,6 @@ contextMenuInit = function(){
...
@@ -112,7 +111,6 @@ contextMenuInit = function(){
if
(
e
.
composedPath
()[
0
].
matches
(
k
)){
if
(
e
.
composedPath
()[
0
].
matches
(
k
)){
showContextMenu
(
e
,
e
.
composedPath
()[
0
],
v
)
showContextMenu
(
e
,
e
.
composedPath
()[
0
],
v
)
e
.
preventDefault
()
e
.
preventDefault
()
return
}
}
})
})
});
});
...
...
javascript/edit-attention.js
View file @
696c338e
...
@@ -69,8 +69,8 @@ function keyupEditAttention(event){
...
@@ -69,8 +69,8 @@ function keyupEditAttention(event){
event
.
preventDefault
();
event
.
preventDefault
();
closeCharacter
=
'
)
'
var
closeCharacter
=
'
)
'
delta
=
opts
.
keyedit_precision_attention
var
delta
=
opts
.
keyedit_precision_attention
if
(
selectionStart
>
0
&&
text
[
selectionStart
-
1
]
==
'
<
'
){
if
(
selectionStart
>
0
&&
text
[
selectionStart
-
1
]
==
'
<
'
){
closeCharacter
=
'
>
'
closeCharacter
=
'
>
'
...
@@ -91,8 +91,8 @@ function keyupEditAttention(event){
...
@@ -91,8 +91,8 @@ function keyupEditAttention(event){
selectionEnd
+=
1
;
selectionEnd
+=
1
;
}
}
end
=
text
.
slice
(
selectionEnd
+
1
).
indexOf
(
closeCharacter
)
+
1
;
var
end
=
text
.
slice
(
selectionEnd
+
1
).
indexOf
(
closeCharacter
)
+
1
;
weight
=
parseFloat
(
text
.
slice
(
selectionEnd
+
1
,
selectionEnd
+
1
+
end
));
var
weight
=
parseFloat
(
text
.
slice
(
selectionEnd
+
1
,
selectionEnd
+
1
+
end
));
if
(
isNaN
(
weight
))
return
;
if
(
isNaN
(
weight
))
return
;
weight
+=
isPlus
?
delta
:
-
delta
;
weight
+=
isPlus
?
delta
:
-
delta
;
...
...
javascript/extensions.js
View file @
696c338e
function
extensions_apply
(
_
,
_
,
disable_all
){
function
extensions_apply
(
_
disabled_list
,
_update_list
,
disable_all
){
var
disable
=
[]
var
disable
=
[]
var
update
=
[]
var
update
=
[]
gradioApp
().
querySelectorAll
(
'
#extensions input[type="checkbox"]
'
).
forEach
(
function
(
x
){
gradioApp
().
querySelectorAll
(
'
#extensions input[type="checkbox"]
'
).
forEach
(
function
(
x
){
if
(
x
.
name
.
startsWith
(
"
enable_
"
)
&&
!
x
.
checked
)
if
(
x
.
name
.
startsWith
(
"
enable_
"
)
&&
!
x
.
checked
)
disable
.
push
(
x
.
name
.
substr
(
7
))
disable
.
push
(
x
.
name
.
substr
ing
(
7
))
if
(
x
.
name
.
startsWith
(
"
update_
"
)
&&
x
.
checked
)
if
(
x
.
name
.
startsWith
(
"
update_
"
)
&&
x
.
checked
)
update
.
push
(
x
.
name
.
substr
(
7
))
update
.
push
(
x
.
name
.
substr
ing
(
7
))
})
})
restart_reload
()
restart_reload
()
...
@@ -16,12 +16,12 @@ function extensions_apply(_, _, disable_all){
...
@@ -16,12 +16,12 @@ function extensions_apply(_, _, disable_all){
return
[
JSON
.
stringify
(
disable
),
JSON
.
stringify
(
update
),
disable_all
]
return
[
JSON
.
stringify
(
disable
),
JSON
.
stringify
(
update
),
disable_all
]
}
}
function
extensions_check
(
_
,
_
){
function
extensions_check
(){
var
disable
=
[]
var
disable
=
[]
gradioApp
().
querySelectorAll
(
'
#extensions input[type="checkbox"]
'
).
forEach
(
function
(
x
){
gradioApp
().
querySelectorAll
(
'
#extensions input[type="checkbox"]
'
).
forEach
(
function
(
x
){
if
(
x
.
name
.
startsWith
(
"
enable_
"
)
&&
!
x
.
checked
)
if
(
x
.
name
.
startsWith
(
"
enable_
"
)
&&
!
x
.
checked
)
disable
.
push
(
x
.
name
.
substr
(
7
))
disable
.
push
(
x
.
name
.
substr
ing
(
7
))
})
})
gradioApp
().
querySelectorAll
(
'
#extensions .extension_status
'
).
forEach
(
function
(
x
){
gradioApp
().
querySelectorAll
(
'
#extensions .extension_status
'
).
forEach
(
function
(
x
){
...
@@ -41,7 +41,7 @@ function install_extension_from_index(button, url){
...
@@ -41,7 +41,7 @@ function install_extension_from_index(button, url){
button
.
disabled
=
"
disabled
"
button
.
disabled
=
"
disabled
"
button
.
value
=
"
Installing...
"
button
.
value
=
"
Installing...
"
textarea
=
gradioApp
().
querySelector
(
'
#extension_to_install textarea
'
)
var
textarea
=
gradioApp
().
querySelector
(
'
#extension_to_install textarea
'
)
textarea
.
value
=
url
textarea
.
value
=
url
updateInput
(
textarea
)
updateInput
(
textarea
)
...
...
javascript/extraNetworks.js
View file @
696c338e
...
@@ -10,11 +10,11 @@ function setupExtraNetworksForTab(tabname){
...
@@ -10,11 +10,11 @@ function setupExtraNetworksForTab(tabname){
tabs
.
appendChild
(
search
)
tabs
.
appendChild
(
search
)
tabs
.
appendChild
(
refresh
)
tabs
.
appendChild
(
refresh
)
search
.
addEventListener
(
"
input
"
,
function
(
evt
){
search
.
addEventListener
(
"
input
"
,
function
(){
searchTerm
=
search
.
value
.
toLowerCase
()
var
searchTerm
=
search
.
value
.
toLowerCase
()
gradioApp
().
querySelectorAll
(
'
#
'
+
tabname
+
'
_extra_tabs div.card
'
).
forEach
(
function
(
elem
){
gradioApp
().
querySelectorAll
(
'
#
'
+
tabname
+
'
_extra_tabs div.card
'
).
forEach
(
function
(
elem
){
text
=
elem
.
querySelector
(
'
.name
'
).
textContent
.
toLowerCase
()
+
"
"
+
elem
.
querySelector
(
'
.search_term
'
).
textContent
.
toLowerCase
()
var
text
=
elem
.
querySelector
(
'
.name
'
).
textContent
.
toLowerCase
()
+
"
"
+
elem
.
querySelector
(
'
.search_term
'
).
textContent
.
toLowerCase
()
elem
.
style
.
display
=
text
.
indexOf
(
searchTerm
)
==
-
1
?
"
none
"
:
""
elem
.
style
.
display
=
text
.
indexOf
(
searchTerm
)
==
-
1
?
"
none
"
:
""
})
})
});
});
...
@@ -55,7 +55,7 @@ function tryToRemoveExtraNetworkFromPrompt(textarea, text){
...
@@ -55,7 +55,7 @@ function tryToRemoveExtraNetworkFromPrompt(textarea, text){
var
partToSearch
=
m
[
1
]
var
partToSearch
=
m
[
1
]
var
replaced
=
false
var
replaced
=
false
var
newTextareaText
=
textarea
.
value
.
replaceAll
(
re_extranet_g
,
function
(
found
,
index
){
var
newTextareaText
=
textarea
.
value
.
replaceAll
(
re_extranet_g
,
function
(
found
){
m
=
found
.
match
(
re_extranet
);
m
=
found
.
match
(
re_extranet
);
if
(
m
[
1
]
==
partToSearch
){
if
(
m
[
1
]
==
partToSearch
){
replaced
=
true
;
replaced
=
true
;
...
@@ -96,9 +96,9 @@ function saveCardPreview(event, tabname, filename){
...
@@ -96,9 +96,9 @@ function saveCardPreview(event, tabname, filename){
}
}
function
extraNetworksSearchButton
(
tabs_id
,
event
){
function
extraNetworksSearchButton
(
tabs_id
,
event
){
searchTextarea
=
gradioApp
().
querySelector
(
"
#
"
+
tabs_id
+
'
> div > textarea
'
)
var
searchTextarea
=
gradioApp
().
querySelector
(
"
#
"
+
tabs_id
+
'
> div > textarea
'
)
button
=
event
.
target
var
button
=
event
.
target
text
=
button
.
classList
.
contains
(
"
search-all
"
)
?
""
:
button
.
textContent
.
trim
()
var
text
=
button
.
classList
.
contains
(
"
search-all
"
)
?
""
:
button
.
textContent
.
trim
()
searchTextarea
.
value
=
text
searchTextarea
.
value
=
text
updateInput
(
searchTextarea
)
updateInput
(
searchTextarea
)
...
@@ -133,7 +133,7 @@ function popup(contents){
...
@@ -133,7 +133,7 @@ function popup(contents){
}
}
function
extraNetworksShowMetadata
(
text
){
function
extraNetworksShowMetadata
(
text
){
elem
=
document
.
createElement
(
'
pre
'
)
var
elem
=
document
.
createElement
(
'
pre
'
)
elem
.
classList
.
add
(
'
popup-metadata
'
);
elem
.
classList
.
add
(
'
popup-metadata
'
);
elem
.
textContent
=
text
;
elem
.
textContent
=
text
;
...
@@ -165,7 +165,7 @@ function requestGet(url, data, handler, errorHandler){
...
@@ -165,7 +165,7 @@ function requestGet(url, data, handler, errorHandler){
}
}
function
extraNetworksRequestMetadata
(
event
,
extraPage
,
cardName
){
function
extraNetworksRequestMetadata
(
event
,
extraPage
,
cardName
){
showError
=
function
(){
extraNetworksShowMetadata
(
"
there was an error getting metadata
"
);
}
var
showError
=
function
(){
extraNetworksShowMetadata
(
"
there was an error getting metadata
"
);
}
requestGet
(
"
./sd_extra_networks/metadata
"
,
{
"
page
"
:
extraPage
,
"
item
"
:
cardName
},
function
(
data
){
requestGet
(
"
./sd_extra_networks/metadata
"
,
{
"
page
"
:
extraPage
,
"
item
"
:
cardName
},
function
(
data
){
if
(
data
&&
data
.
metadata
){
if
(
data
&&
data
.
metadata
){
...
...
javascript/generationParams.js
View file @
696c338e
...
@@ -23,7 +23,7 @@ let modalObserver = new MutationObserver(function(mutations) {
...
@@ -23,7 +23,7 @@ let modalObserver = new MutationObserver(function(mutations) {
});
});
function
attachGalleryListeners
(
tab_name
)
{
function
attachGalleryListeners
(
tab_name
)
{
gallery
=
gradioApp
().
querySelector
(
'
#
'
+
tab_name
+
'
_gallery
'
)
var
gallery
=
gradioApp
().
querySelector
(
'
#
'
+
tab_name
+
'
_gallery
'
)
gallery
?.
addEventListener
(
'
click
'
,
()
=>
gradioApp
().
getElementById
(
tab_name
+
"
_generation_info_button
"
).
click
());
gallery
?.
addEventListener
(
'
click
'
,
()
=>
gradioApp
().
getElementById
(
tab_name
+
"
_generation_info_button
"
).
click
());
gallery
?.
addEventListener
(
'
keydown
'
,
(
e
)
=>
{
gallery
?.
addEventListener
(
'
keydown
'
,
(
e
)
=>
{
if
(
e
.
keyCode
==
37
||
e
.
keyCode
==
39
)
// left or right arrow
if
(
e
.
keyCode
==
37
||
e
.
keyCode
==
39
)
// left or right arrow
...
...
javascript/hints.js
View file @
696c338e
...
@@ -118,7 +118,9 @@ titles = {
...
@@ -118,7 +118,9 @@ titles = {
onUiUpdate
(
function
(){
onUiUpdate
(
function
(){
gradioApp
().
querySelectorAll
(
'
span, button, select, p
'
).
forEach
(
function
(
span
){
gradioApp
().
querySelectorAll
(
'
span, button, select, p
'
).
forEach
(
function
(
span
){
tooltip
=
titles
[
span
.
textContent
];
if
(
span
.
title
)
return
;
// already has a title
let
tooltip
=
titles
[
span
.
textContent
];
if
(
!
tooltip
){
if
(
!
tooltip
){
tooltip
=
titles
[
span
.
value
];
tooltip
=
titles
[
span
.
value
];
...
...
javascript/hires_fix.js
View file @
696c338e
function
setInactive
(
elem
,
inactive
){
function
onCalcResolutionHires
(
enable
,
width
,
height
,
hr_scale
,
hr_resize_x
,
hr_resize_y
){
if
(
inactive
){
function
setInactive
(
elem
,
inactive
){
elem
.
classList
.
add
(
'
inactive
'
)
elem
.
classList
.
toggle
(
'
inactive
'
,
!!
inactive
)
}
else
{
elem
.
classList
.
remove
(
'
inactive
'
)
}
}
}
function
onCalcResolutionHires
(
enable
,
width
,
height
,
hr_scale
,
hr_resize_x
,
hr_resize_y
){
var
hrUpscaleBy
=
gradioApp
().
getElementById
(
'
txt2img_hr_scale
'
)
hrUpscaleBy
=
gradioApp
().
getElementById
(
'
txt2img_hr_scale
'
)
var
hrResizeX
=
gradioApp
().
getElementById
(
'
txt2img_hr_resize_x
'
)
hrResizeX
=
gradioApp
().
getElementById
(
'
txt2img_hr_resize_x
'
)
var
hrResizeY
=
gradioApp
().
getElementById
(
'
txt2img_hr_resize_y
'
)
hrResizeY
=
gradioApp
().
getElementById
(
'
txt2img_hr_resize_y
'
)
gradioApp
().
getElementById
(
'
txt2img_hires_fix_row2
'
).
style
.
display
=
opts
.
use_old_hires_fix_width_height
?
"
none
"
:
""
gradioApp
().
getElementById
(
'
txt2img_hires_fix_row2
'
).
style
.
display
=
opts
.
use_old_hires_fix_width_height
?
"
none
"
:
""
...
...
javascript/imageMaskFix.js
View file @
696c338e
...
@@ -2,11 +2,10 @@
...
@@ -2,11 +2,10 @@
* temporary fix for https://github.com/AUTOMATIC1111/stable-diffusion-webui/issues/668
* temporary fix for https://github.com/AUTOMATIC1111/stable-diffusion-webui/issues/668
* @see https://github.com/gradio-app/gradio/issues/1721
* @see https://github.com/gradio-app/gradio/issues/1721
*/
*/
window
.
addEventListener
(
'
resize
'
,
()
=>
imageMaskResize
());
function
imageMaskResize
()
{
function
imageMaskResize
()
{
const
canvases
=
gradioApp
().
querySelectorAll
(
'
#img2maskimg .touch-none canvas
'
);
const
canvases
=
gradioApp
().
querySelectorAll
(
'
#img2maskimg .touch-none canvas
'
);
if
(
!
canvases
.
length
)
{
if
(
!
canvases
.
length
)
{
canvases_fixed
=
false
;
canvases_fixed
=
false
;
// TODO: this is unused..?
window
.
removeEventListener
(
'
resize
'
,
imageMaskResize
);
window
.
removeEventListener
(
'
resize
'
,
imageMaskResize
);
return
;
return
;
}
}
...
@@ -15,7 +14,7 @@ function imageMaskResize() {
...
@@ -15,7 +14,7 @@ function imageMaskResize() {
const
previewImage
=
wrapper
.
previousElementSibling
;
const
previewImage
=
wrapper
.
previousElementSibling
;
if
(
!
previewImage
.
complete
)
{
if
(
!
previewImage
.
complete
)
{
previewImage
.
addEventListener
(
'
load
'
,
()
=>
imageMaskResize
()
);
previewImage
.
addEventListener
(
'
load
'
,
imageMaskResize
);
return
;
return
;
}
}
...
@@ -24,7 +23,6 @@ function imageMaskResize() {
...
@@ -24,7 +23,6 @@ function imageMaskResize() {
const
nw
=
previewImage
.
naturalWidth
;
const
nw
=
previewImage
.
naturalWidth
;
const
nh
=
previewImage
.
naturalHeight
;
const
nh
=
previewImage
.
naturalHeight
;
const
portrait
=
nh
>
nw
;
const
portrait
=
nh
>
nw
;
const
factor
=
portrait
;
const
wW
=
Math
.
min
(
w
,
portrait
?
h
/
nh
*
nw
:
w
/
nw
*
nw
);
const
wW
=
Math
.
min
(
w
,
portrait
?
h
/
nh
*
nw
:
w
/
nw
*
nw
);
const
wH
=
Math
.
min
(
h
,
portrait
?
h
/
nh
*
nh
:
w
/
nw
*
nh
);
const
wH
=
Math
.
min
(
h
,
portrait
?
h
/
nh
*
nh
:
w
/
nw
*
nh
);
...
@@ -40,6 +38,7 @@ function imageMaskResize() {
...
@@ -40,6 +38,7 @@ function imageMaskResize() {
c
.
style
.
maxHeight
=
'
100%
'
;
c
.
style
.
maxHeight
=
'
100%
'
;
c
.
style
.
objectFit
=
'
contain
'
;
c
.
style
.
objectFit
=
'
contain
'
;
});
});
}
}
onUiUpdate
(()
=>
imageMaskResize
());
onUiUpdate
(
imageMaskResize
);
window
.
addEventListener
(
'
resize
'
,
imageMaskResize
);
javascript/imageParams.js
View file @
696c338e
window
.
onload
=
(
function
(){
window
.
onload
=
(
function
(){
window
.
addEventListener
(
'
drop
'
,
e
=>
{
window
.
addEventListener
(
'
drop
'
,
e
=>
{
const
target
=
e
.
composedPath
()[
0
];
const
target
=
e
.
composedPath
()[
0
];
const
idx
=
selected_gallery_index
();
if
(
target
.
placeholder
.
indexOf
(
"
Prompt
"
)
==
-
1
)
return
;
if
(
target
.
placeholder
.
indexOf
(
"
Prompt
"
)
==
-
1
)
return
;
let
prompt_target
=
get_tab_index
(
'
tabs
'
)
==
1
?
"
img2img_prompt_image
"
:
"
txt2img_prompt_image
"
;
let
prompt_target
=
get_tab_index
(
'
tabs
'
)
==
1
?
"
img2img_prompt_image
"
:
"
txt2img_prompt_image
"
;
...
...
javascript/imageviewer.js
View file @
696c338e
...
@@ -57,7 +57,7 @@ function modalImageSwitch(offset) {
...
@@ -57,7 +57,7 @@ function modalImageSwitch(offset) {
})
})
if
(
result
!=
-
1
)
{
if
(
result
!=
-
1
)
{
nextButton
=
galleryButtons
[
negmod
((
result
+
offset
),
galleryButtons
.
length
)]
var
nextButton
=
galleryButtons
[
negmod
((
result
+
offset
),
galleryButtons
.
length
)]
nextButton
.
click
()
nextButton
.
click
()
const
modalImage
=
gradioApp
().
getElementById
(
"
modalImage
"
);
const
modalImage
=
gradioApp
().
getElementById
(
"
modalImage
"
);
const
modal
=
gradioApp
().
getElementById
(
"
lightboxModal
"
);
const
modal
=
gradioApp
().
getElementById
(
"
lightboxModal
"
);
...
@@ -144,15 +144,11 @@ function setupImageForLightbox(e) {
...
@@ -144,15 +144,11 @@ function setupImageForLightbox(e) {
}
}
function
modalZoomSet
(
modalImage
,
enable
)
{
function
modalZoomSet
(
modalImage
,
enable
)
{
if
(
enable
)
{
if
(
modalImage
)
modalImage
.
classList
.
toggle
(
'
modalImageFullscreen
'
,
!!
enable
);
modalImage
.
classList
.
add
(
'
modalImageFullscreen
'
);
}
else
{
modalImage
.
classList
.
remove
(
'
modalImageFullscreen
'
);
}
}
}
function
modalZoomToggle
(
event
)
{
function
modalZoomToggle
(
event
)
{
modalImage
=
gradioApp
().
getElementById
(
"
modalImage
"
);
var
modalImage
=
gradioApp
().
getElementById
(
"
modalImage
"
);
modalZoomSet
(
modalImage
,
!
modalImage
.
classList
.
contains
(
'
modalImageFullscreen
'
))
modalZoomSet
(
modalImage
,
!
modalImage
.
classList
.
contains
(
'
modalImageFullscreen
'
))
event
.
stopPropagation
()
event
.
stopPropagation
()
}
}
...
@@ -179,7 +175,7 @@ function galleryImageHandler(e) {
...
@@ -179,7 +175,7 @@ function galleryImageHandler(e) {
}
}
onUiUpdate
(
function
()
{
onUiUpdate
(
function
()
{
fullImg_preview
=
gradioApp
().
querySelectorAll
(
'
.gradio-gallery > div > img
'
)
var
fullImg_preview
=
gradioApp
().
querySelectorAll
(
'
.gradio-gallery > div > img
'
)
if
(
fullImg_preview
!=
null
)
{
if
(
fullImg_preview
!=
null
)
{
fullImg_preview
.
forEach
(
setupImageForLightbox
);
fullImg_preview
.
forEach
(
setupImageForLightbox
);
}
}
...
...
javascript/localization.js
View file @
696c338e
...
@@ -35,11 +35,11 @@ function canBeTranslated(node, text){
...
@@ -35,11 +35,11 @@ function canBeTranslated(node, text){
if
(
!
text
)
return
false
;
if
(
!
text
)
return
false
;
if
(
!
node
.
parentElement
)
return
false
;
if
(
!
node
.
parentElement
)
return
false
;
parentType
=
node
.
parentElement
.
nodeName
var
parentType
=
node
.
parentElement
.
nodeName
if
(
parentType
==
'
SCRIPT
'
||
parentType
==
'
STYLE
'
||
parentType
==
'
TEXTAREA
'
)
return
false
;
if
(
parentType
==
'
SCRIPT
'
||
parentType
==
'
STYLE
'
||
parentType
==
'
TEXTAREA
'
)
return
false
;
if
(
parentType
==
'
OPTION
'
||
parentType
==
'
SPAN
'
){
if
(
parentType
==
'
OPTION
'
||
parentType
==
'
SPAN
'
){
pnode
=
node
var
pnode
=
node
for
(
var
level
=
0
;
level
<
4
;
level
++
){
for
(
var
level
=
0
;
level
<
4
;
level
++
){
pnode
=
pnode
.
parentElement
pnode
=
pnode
.
parentElement
if
(
!
pnode
)
break
;
if
(
!
pnode
)
break
;
...
@@ -69,7 +69,7 @@ function getTranslation(text){
...
@@ -69,7 +69,7 @@ function getTranslation(text){
}
}
function
processTextNode
(
node
){
function
processTextNode
(
node
){
text
=
node
.
textContent
.
trim
()
var
text
=
node
.
textContent
.
trim
()
if
(
!
canBeTranslated
(
node
,
text
))
return
if
(
!
canBeTranslated
(
node
,
text
))
return
...
@@ -105,7 +105,7 @@ function processNode(node){
...
@@ -105,7 +105,7 @@ function processNode(node){
}
}
function
dumpTranslations
(){
function
dumpTranslations
(){
dumped
=
{}
var
dumped
=
{}
if
(
localization
.
rtl
)
{
if
(
localization
.
rtl
)
{
dumped
.
rtl
=
true
dumped
.
rtl
=
true
}
}
...
@@ -151,7 +151,7 @@ document.addEventListener("DOMContentLoaded", function() {
...
@@ -151,7 +151,7 @@ document.addEventListener("DOMContentLoaded", function() {
})
})
function
download_localization
()
{
function
download_localization
()
{
text
=
JSON
.
stringify
(
dumpTranslations
(),
null
,
4
)
var
text
=
JSON
.
stringify
(
dumpTranslations
(),
null
,
4
)
var
element
=
document
.
createElement
(
'
a
'
);
var
element
=
document
.
createElement
(
'
a
'
);
element
.
setAttribute
(
'
href
'
,
'
data:text/plain;charset=utf-8,
'
+
encodeURIComponent
(
text
));
element
.
setAttribute
(
'
href
'
,
'
data:text/plain;charset=utf-8,
'
+
encodeURIComponent
(
text
));
...
...
javascript/notification.js
View file @
696c338e
...
@@ -2,15 +2,15 @@
...
@@ -2,15 +2,15 @@
let
lastHeadImg
=
null
;
let
lastHeadImg
=
null
;
notificationButton
=
null
let
notificationButton
=
null
;
onUiUpdate
(
function
(){
onUiUpdate
(
function
(){
if
(
notificationButton
==
null
){
if
(
notificationButton
==
null
){
notificationButton
=
gradioApp
().
getElementById
(
'
request_notifications
'
)
notificationButton
=
gradioApp
().
getElementById
(
'
request_notifications
'
)
if
(
notificationButton
!=
null
){
if
(
notificationButton
!=
null
){
notificationButton
.
addEventListener
(
'
click
'
,
function
(
evt
)
{
notificationButton
.
addEventListener
(
'
click
'
,
()
=>
{
Notification
.
requestPermission
();
void
Notification
.
requestPermission
();
},
true
);
},
true
);
}
}
}
}
...
...
javascript/progressbar.js
View file @
696c338e
// code related to showing and updating progressbar shown as the image is being made
// code related to showing and updating progressbar shown as the image is being made
function
rememberGallerySelection
(
id_gallery
){
function
rememberGallerySelection
(){
}
}
function
getGallerySelectedIndex
(
id_gallery
){
function
getGallerySelectedIndex
(){
}
}
function
request
(
url
,
data
,
handler
,
errorHandler
){
function
request
(
url
,
data
,
handler
,
errorHandler
){
var
xhr
=
new
XMLHttpRequest
();
var
xhr
=
new
XMLHttpRequest
();
var
url
=
url
;
xhr
.
open
(
"
POST
"
,
url
,
true
);
xhr
.
open
(
"
POST
"
,
url
,
true
);
xhr
.
setRequestHeader
(
"
Content-Type
"
,
"
application/json
"
);
xhr
.
setRequestHeader
(
"
Content-Type
"
,
"
application/json
"
);
xhr
.
onreadystatechange
=
function
()
{
xhr
.
onreadystatechange
=
function
()
{
...
@@ -107,7 +106,7 @@ function requestProgress(id_task, progressbarContainer, gallery, atEnd, onProgre
...
@@ -107,7 +106,7 @@ function requestProgress(id_task, progressbarContainer, gallery, atEnd, onProgre
divProgress
.
style
.
width
=
rect
.
width
+
"
px
"
;
divProgress
.
style
.
width
=
rect
.
width
+
"
px
"
;
}
}
progressText
=
""
let
progressText
=
""
divInner
.
style
.
width
=
((
res
.
progress
||
0
)
*
100.0
)
+
'
%
'
divInner
.
style
.
width
=
((
res
.
progress
||
0
)
*
100.0
)
+
'
%
'
divInner
.
style
.
background
=
res
.
progress
?
""
:
"
transparent
"
divInner
.
style
.
background
=
res
.
progress
?
""
:
"
transparent
"
...
...
javascript/ui.js
View file @
696c338e
// various functions for interaction with ui.py not large enough to warrant putting them in separate files
// various functions for interaction with ui.py not large enough to warrant putting them in separate files
function
set_theme
(
theme
){
function
set_theme
(
theme
){
gradioURL
=
window
.
location
.
href
var
gradioURL
=
window
.
location
.
href
if
(
!
gradioURL
.
includes
(
'
?__theme=
'
))
{
if
(
!
gradioURL
.
includes
(
'
?__theme=
'
))
{
window
.
location
.
replace
(
gradioURL
+
'
?__theme=
'
+
theme
);
window
.
location
.
replace
(
gradioURL
+
'
?__theme=
'
+
theme
);
}
}
...
@@ -47,7 +47,7 @@ function extract_image_from_gallery(gallery){
...
@@ -47,7 +47,7 @@ function extract_image_from_gallery(gallery){
return
[
gallery
[
0
]];
return
[
gallery
[
0
]];
}
}
index
=
selected_gallery_index
()
var
index
=
selected_gallery_index
()
if
(
index
<
0
||
index
>=
gallery
.
length
){
if
(
index
<
0
||
index
>=
gallery
.
length
){
// Use the first image in the gallery as the default
// Use the first image in the gallery as the default
...
@@ -58,7 +58,7 @@ function extract_image_from_gallery(gallery){
...
@@ -58,7 +58,7 @@ function extract_image_from_gallery(gallery){
}
}
function
args_to_array
(
args
){
function
args_to_array
(
args
){
res
=
[]
var
res
=
[]
for
(
var
i
=
0
;
i
<
args
.
length
;
i
++
){
for
(
var
i
=
0
;
i
<
args
.
length
;
i
++
){
res
.
push
(
args
[
i
])
res
.
push
(
args
[
i
])
}
}
...
@@ -138,7 +138,7 @@ function get_img2img_tab_index() {
...
@@ -138,7 +138,7 @@ function get_img2img_tab_index() {
}
}
function
create_submit_args
(
args
){
function
create_submit_args
(
args
){
res
=
[]
var
res
=
[]
for
(
var
i
=
0
;
i
<
args
.
length
;
i
++
){
for
(
var
i
=
0
;
i
<
args
.
length
;
i
++
){
res
.
push
(
args
[
i
])
res
.
push
(
args
[
i
])
}
}
...
@@ -160,7 +160,7 @@ function showSubmitButtons(tabname, show){
...
@@ -160,7 +160,7 @@ function showSubmitButtons(tabname, show){
}
}
function
showRestoreProgressButton
(
tabname
,
show
){
function
showRestoreProgressButton
(
tabname
,
show
){
button
=
gradioApp
().
getElementById
(
tabname
+
"
_restore_progress
"
)
var
button
=
gradioApp
().
getElementById
(
tabname
+
"
_restore_progress
"
)
if
(
!
button
)
return
if
(
!
button
)
return
button
.
style
.
display
=
show
?
"
flex
"
:
"
none
"
button
.
style
.
display
=
show
?
"
flex
"
:
"
none
"
...
@@ -207,8 +207,9 @@ function submit_img2img(){
...
@@ -207,8 +207,9 @@ function submit_img2img(){
return
res
return
res
}
}
function
restoreProgressTxt2img
(
x
){
function
restoreProgressTxt2img
(){
showRestoreProgressButton
(
"
txt2img
"
,
false
)
showRestoreProgressButton
(
"
txt2img
"
,
false
)
var
id
=
localStorage
.
getItem
(
"
txt2img_task_id
"
)
id
=
localStorage
.
getItem
(
"
txt2img_task_id
"
)
id
=
localStorage
.
getItem
(
"
txt2img_task_id
"
)
...
@@ -220,10 +221,11 @@ function restoreProgressTxt2img(x){
...
@@ -220,10 +221,11 @@ function restoreProgressTxt2img(x){
return
id
return
id
}
}
function
restoreProgressImg2img
(
x
){
function
restoreProgressImg2img
(){
showRestoreProgressButton
(
"
img2img
"
,
false
)
showRestoreProgressButton
(
"
img2img
"
,
false
)
id
=
localStorage
.
getItem
(
"
img2img_task_id
"
)
var
id
=
localStorage
.
getItem
(
"
img2img_task_id
"
)
if
(
id
)
{
if
(
id
)
{
requestProgress
(
id
,
gradioApp
().
getElementById
(
'
img2img_gallery_container
'
),
gradioApp
().
getElementById
(
'
img2img_gallery
'
),
function
(){
requestProgress
(
id
,
gradioApp
().
getElementById
(
'
img2img_gallery_container
'
),
gradioApp
().
getElementById
(
'
img2img_gallery
'
),
function
(){
...
@@ -252,7 +254,7 @@ function modelmerger(){
...
@@ -252,7 +254,7 @@ function modelmerger(){
function
ask_for_style_name
(
_
,
prompt_text
,
negative_prompt_text
)
{
function
ask_for_style_name
(
_
,
prompt_text
,
negative_prompt_text
)
{
name_
=
prompt
(
'
Style name:
'
)
var
name_
=
prompt
(
'
Style name:
'
)
return
[
name_
,
prompt_text
,
negative_prompt_text
]
return
[
name_
,
prompt_text
,
negative_prompt_text
]
}
}
...
@@ -287,11 +289,11 @@ function recalculate_prompts_img2img(){
...
@@ -287,11 +289,11 @@ function recalculate_prompts_img2img(){
}
}
opts
=
{}
var
opts
=
{}
onUiUpdate
(
function
(){
onUiUpdate
(
function
(){
if
(
Object
.
keys
(
opts
).
length
!=
0
)
return
;
if
(
Object
.
keys
(
opts
).
length
!=
0
)
return
;
json_elem
=
gradioApp
().
getElementById
(
'
settings_json
'
)
var
json_elem
=
gradioApp
().
getElementById
(
'
settings_json
'
)
if
(
json_elem
==
null
)
return
;
if
(
json_elem
==
null
)
return
;
var
textarea
=
json_elem
.
querySelector
(
'
textarea
'
)
var
textarea
=
json_elem
.
querySelector
(
'
textarea
'
)
...
@@ -340,8 +342,8 @@ onUiUpdate(function(){
...
@@ -340,8 +342,8 @@ onUiUpdate(function(){
registerTextarea
(
'
img2img_prompt
'
,
'
img2img_token_counter
'
,
'
img2img_token_button
'
)
registerTextarea
(
'
img2img_prompt
'
,
'
img2img_token_counter
'
,
'
img2img_token_button
'
)
registerTextarea
(
'
img2img_neg_prompt
'
,
'
img2img_negative_token_counter
'
,
'
img2img_negative_token_button
'
)
registerTextarea
(
'
img2img_neg_prompt
'
,
'
img2img_negative_token_counter
'
,
'
img2img_negative_token_button
'
)
show_all_pages
=
gradioApp
().
getElementById
(
'
settings_show_all_pages
'
)
var
show_all_pages
=
gradioApp
().
getElementById
(
'
settings_show_all_pages
'
)
settings_tabs
=
gradioApp
().
querySelector
(
'
#settings div
'
)
var
settings_tabs
=
gradioApp
().
querySelector
(
'
#settings div
'
)
if
(
show_all_pages
&&
settings_tabs
){
if
(
show_all_pages
&&
settings_tabs
){
settings_tabs
.
appendChild
(
show_all_pages
)
settings_tabs
.
appendChild
(
show_all_pages
)
show_all_pages
.
onclick
=
function
(){
show_all_pages
.
onclick
=
function
(){
...
@@ -353,9 +355,9 @@ onUiUpdate(function(){
...
@@ -353,9 +355,9 @@ onUiUpdate(function(){
})
})
onOptionsChanged
(
function
(){
onOptionsChanged
(
function
(){
elem
=
gradioApp
().
getElementById
(
'
sd_checkpoint_hash
'
)
var
elem
=
gradioApp
().
getElementById
(
'
sd_checkpoint_hash
'
)
sd_checkpoint_hash
=
opts
.
sd_checkpoint_hash
||
""
var
sd_checkpoint_hash
=
opts
.
sd_checkpoint_hash
||
""
shorthash
=
sd_checkpoint_hash
.
substr
(
0
,
10
)
var
shorthash
=
sd_checkpoint_hash
.
substring
(
0
,
10
)
if
(
elem
&&
elem
.
textContent
!=
shorthash
){
if
(
elem
&&
elem
.
textContent
!=
shorthash
){
elem
.
textContent
=
shorthash
elem
.
textContent
=
shorthash
...
...
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