@@ -17,46 +17,53 @@ function getType(node) {
17
17
18
18
const getImage = ( imageId ) => document . querySelector ( `#${ CSS . escape ( imageId ) } ` ) ;
19
19
20
- const calculateImagePosition = ( el , rootRect , bodyRect ) => {
21
- const { x } = el . getBoundingClientRect ( ) ;
22
- let { top, left } = rootRect ;
23
- const { width : bodyWidth , height : bodyHeight } = bodyRect ;
24
-
25
- const isSpaceRight = x + IMAGE_WIDTH <= bodyWidth ;
26
- if ( isSpaceRight ) {
27
- left += rootRect . width + IMAGE_WIDTH ;
28
- }
29
-
30
- const isSpaceBelow = rootRect . top + IMAGE_HEIGHT <= bodyHeight ;
31
- if ( ! isSpaceBelow ) {
32
- top = bodyHeight - IMAGE_HEIGHT ;
33
- }
34
-
35
- return { left : Math . round ( left ) , top : Math . round ( top ) } ;
20
+ const calculateImagePosition = ( el , bodyRect ) => {
21
+ let { top, left, right } = el . getBoundingClientRect ( ) ;
22
+ const { width : bodyWidth , height : bodyHeight } = bodyRect ;
23
+
24
+ const isSpaceRight = right + IMAGE_WIDTH <= bodyWidth ;
25
+ if ( isSpaceRight ) {
26
+ left = right ;
27
+ } else {
28
+ left -= IMAGE_WIDTH ;
29
+ }
30
+
31
+ top = top - IMAGE_HEIGHT / 2 ;
32
+ if ( top + IMAGE_HEIGHT > bodyHeight ) {
33
+ top = bodyHeight - IMAGE_HEIGHT ;
34
+ }
35
+ if ( top < 0 ) {
36
+ top = 0 ;
37
+ }
38
+
39
+ return { left : Math . round ( left ) , top : Math . round ( top ) , isLeft : ! isSpaceRight } ;
36
40
} ;
37
41
38
- function showImage ( el , imageId , getRootRect ) {
39
- const img = getImage ( imageId ) ;
40
- if ( img ) {
41
- const rootRect = getRootRect ( ) ;
42
- if ( ! rootRect ) return ;
42
+ function showImage ( el , imageId ) {
43
+ const img = getImage ( imageId ) ;
44
+ if ( img ) {
45
+ const bodyRect = document . body . getBoundingClientRect ( ) ;
46
+ if ( ! bodyRect ) return ;
43
47
44
- const bodyRect = document . body . getBoundingClientRect ( ) ;
45
- if ( ! bodyRect ) return ;
48
+ const { left, top, isLeft } = calculateImagePosition ( el , bodyRect ) ;
46
49
47
- const { left, top } = calculateImagePosition ( el , rootRect , bodyRect ) ;
50
+ img . style . display = "block" ;
51
+ img . style . left = `${ left } px` ;
52
+ img . style . top = `${ top } px` ;
48
53
49
- img . style . display = "block" ;
50
- img . style . left = `${ left } px` ;
51
- img . style . top = `${ top } px` ;
52
- }
54
+ if ( isLeft ) {
55
+ img . classList . add ( "left" ) ;
56
+ } else {
57
+ img . classList . remove ( "left" ) ;
58
+ }
59
+ }
53
60
}
54
61
55
62
function closeImage ( imageId ) {
56
- const img = getImage ( imageId ) ;
57
- if ( img ) {
58
- img . style . display = "none" ;
59
- }
63
+ const img = getImage ( imageId ) ;
64
+ if ( img ) {
65
+ img . style . display = "none" ;
66
+ }
60
67
}
61
68
62
69
app . registerExtension ( {
@@ -72,13 +79,14 @@ app.registerExtension({
72
79
position: absolute;
73
80
left: 0;
74
81
top: 0;
75
- transform: translate(-100%, 0);
76
82
width: ${ IMAGE_WIDTH } px;
77
83
height: ${ IMAGE_HEIGHT } px;
78
84
background-size: contain;
79
- background-position: top right;
80
85
background-repeat: no-repeat;
81
- filter: brightness(65%);
86
+ z-index: 9999;
87
+ }
88
+ .pysssss-combo-image.left {
89
+ background-position: top right;
82
90
}
83
91
` ,
84
92
parent : document . body ,
@@ -118,27 +126,22 @@ app.registerExtension({
118
126
} ) ;
119
127
120
128
function encodeRFC3986URIComponent ( str ) {
121
- return encodeURIComponent ( str ) . replace (
122
- / [ ! ' ( ) * ] / g,
123
- ( c ) => `%${ c . charCodeAt ( 0 ) . toString ( 16 ) . toUpperCase ( ) } ` ,
124
- ) ;
129
+ return encodeURIComponent ( str ) . replace ( / [ ! ' ( ) * ] / g, ( c ) => `%${ c . charCodeAt ( 0 ) . toString ( 16 ) . toUpperCase ( ) } ` ) ;
125
130
}
126
131
127
132
// After an element is created for an item, add an image if it has one
128
133
contextMenuHook [ "addItem" ] . push ( function ( el , menu , [ name , value , options ] ) {
129
134
if ( el && isCustomItem ( value ) && value ?. image && ! value . submenu ) {
130
135
const key = `pysssss-image-combo-${ name } ` ;
131
136
el . textContent += " *" ;
132
- $el ( ` div.pysssss-combo-image` , {
137
+ $el ( " div.pysssss-combo-image" , {
133
138
id : key ,
134
139
parent : document . body ,
135
140
style : {
136
141
backgroundImage : `url(/pysssss/view/${ encodeRFC3986URIComponent ( value . image ) } )` ,
137
142
} ,
138
143
} ) ;
139
-
140
- const getRootRect = ( ) => menu . root ?. getBoundingClientRect ( ) ;
141
- const showHandler = ( ) => showImage ( el , key , getRootRect ) ;
144
+ const showHandler = ( ) => showImage ( el , key ) ;
142
145
const closeHandler = ( ) => closeImage ( key ) ;
143
146
144
147
el . addEventListener ( "mouseenter" , showHandler , { passive : true } ) ;
@@ -225,18 +228,18 @@ app.registerExtension({
225
228
}
226
229
}
227
230
return false ;
228
- }
231
+ } ;
229
232
const includesFromMenuItem = function ( item ) {
230
233
if ( item . submenu ) {
231
- return includesFromMenuItems ( item . submenu . options )
234
+ return includesFromMenuItems ( item . submenu . options ) ;
232
235
} else {
233
236
return item . content === searchElement . content ;
234
237
}
235
- }
238
+ } ;
236
239
237
240
const includes = valuesIncludes . apply ( this , arguments ) || includesFromMenuItems ( this ) ;
238
241
return includes ;
239
- }
242
+ } ;
240
243
241
244
return v ;
242
245
} ,
@@ -324,7 +327,6 @@ app.registerExtension({
324
327
return exampleCb ?. apply ( this , arguments ) ?? exampleList . value ;
325
328
} ;
326
329
327
-
328
330
const listExamples = async ( ) => {
329
331
exampleList . disabled = true ;
330
332
exampleList . options . values = [ "[none]" ] ;
@@ -386,9 +388,7 @@ app.registerExtension({
386
388
img = this . imgs [ this . overIndex ] ;
387
389
}
388
390
if ( img ) {
389
- const nodes = app . graph . _nodes . filter (
390
- ( n ) => n . comfyClass === LORA_LOADER || n . comfyClass === CHECKPOINT_LOADER
391
- ) ;
391
+ const nodes = app . graph . _nodes . filter ( ( n ) => n . comfyClass === LORA_LOADER || n . comfyClass === CHECKPOINT_LOADER ) ;
392
392
if ( nodes . length ) {
393
393
options . unshift ( {
394
394
content : "Save as Preview" ,
0 commit comments