@@ -2,72 +2,70 @@ import { api } from "./api.js";
2
2
import { ComfyDialog as _ComfyDialog } from "./ui/dialog.js" ;
3
3
import { toggleSwitch } from "./ui/toggleSwitch.js" ;
4
4
import { ComfySettingsDialog } from "./ui/settings.js" ;
5
+ import { ComfyApp , app } from "./app.js" ;
5
6
6
7
export const ComfyDialog = _ComfyDialog ;
7
8
8
- /**
9
- *
10
- * @param { string } tag HTML Element Tag and optional classes e.g. div.class1.class2
11
- * @param { string | Element | Element[] | {
12
- * parent?: Element,
13
- * $?: (el: Element) => void,
14
- * dataset?: DOMStringMap,
15
- * style?: CSSStyleDeclaration,
16
- * for?: string
17
- * ...any
18
- * } | undefined } [propsOrChildren]
19
- * @param { Element[] | Element | undefined } [children]
20
- * @returns
21
- */
22
- export function $el ( tag , propsOrChildren , children ) {
23
- const split = tag . split ( "." ) ;
24
- const element = document . createElement ( split . shift ( ) ) ;
25
- if ( split . length > 0 ) {
26
- element . classList . add ( ...split ) ;
27
- }
28
-
29
- if ( propsOrChildren ) {
30
- if ( typeof propsOrChildren === "string" ) {
31
- propsOrChildren = { textContent : propsOrChildren } ;
32
- } else if ( propsOrChildren instanceof Element ) {
33
- propsOrChildren = [ propsOrChildren ] ;
34
- }
35
- if ( Array . isArray ( propsOrChildren ) ) {
36
- element . append ( ...propsOrChildren ) ;
37
- } else {
38
- const { parent, $ : cb , dataset, style } = propsOrChildren ;
39
- delete propsOrChildren . parent ;
40
- delete propsOrChildren . $ ;
41
- delete propsOrChildren . dataset ;
42
- delete propsOrChildren . style ;
43
-
44
- if ( Object . hasOwn ( propsOrChildren , "for" ) ) {
45
- element . setAttribute ( "for" , propsOrChildren . for )
46
- }
47
-
48
- if ( style ) {
49
- Object . assign ( element . style , style ) ;
50
- }
51
-
52
- if ( dataset ) {
53
- Object . assign ( element . dataset , dataset ) ;
54
- }
55
-
56
- Object . assign ( element , propsOrChildren ) ;
57
- if ( children ) {
58
- element . append ( ...( children instanceof Array ? children : [ children ] ) ) ;
59
- }
60
-
61
- if ( parent ) {
62
- parent . append ( element ) ;
63
- }
64
-
65
- if ( cb ) {
66
- cb ( element ) ;
67
- }
68
- }
69
- }
70
- return element ;
9
+ type Position2D = {
10
+ x : number ,
11
+ y : number
12
+ } ;
13
+
14
+ type Props = {
15
+ parent ?: HTMLElement ,
16
+ $ ?: ( el : HTMLElement ) => void ,
17
+ dataset ?: DOMStringMap ,
18
+ style ?: Partial < CSSStyleDeclaration > ,
19
+ for ?: string ,
20
+ textContent ?: string ,
21
+ [ key : string ] : any
22
+ } ;
23
+
24
+ export function $el ( tag : string , propsOrChildren ?: string | Element | Element [ ] | Props , children ?: Element [ ] | Element ) : HTMLElement {
25
+ const split = tag . split ( "." ) ;
26
+ const element = document . createElement ( split . shift ( ) as string ) ;
27
+ if ( split . length > 0 ) {
28
+ element . classList . add ( ...split ) ;
29
+ }
30
+
31
+ if ( propsOrChildren ) {
32
+ if ( typeof propsOrChildren === "string" ) {
33
+ propsOrChildren = { textContent : propsOrChildren } ;
34
+ } else if ( propsOrChildren instanceof Element ) {
35
+ propsOrChildren = [ propsOrChildren ] ;
36
+ }
37
+ if ( Array . isArray ( propsOrChildren ) ) {
38
+ element . append ( ...propsOrChildren ) ;
39
+ } else {
40
+ const { parent, $ : cb , dataset, style, ...rest } = propsOrChildren as Props ;
41
+
42
+ if ( rest . for ) {
43
+ element . setAttribute ( "for" , rest . for )
44
+ }
45
+
46
+ if ( style ) {
47
+ Object . assign ( element . style , style ) ;
48
+ }
49
+
50
+ if ( dataset ) {
51
+ Object . assign ( element . dataset , dataset ) ;
52
+ }
53
+
54
+ Object . assign ( element , rest ) ;
55
+ if ( children ) {
56
+ element . append ( ...( Array . isArray ( children ) ? children : [ children ] ) ) ;
57
+ }
58
+
59
+ if ( parent ) {
60
+ parent . append ( element ) ;
61
+ }
62
+
63
+ if ( cb ) {
64
+ cb ( element ) ;
65
+ }
66
+ }
67
+ }
68
+ return element ;
71
69
}
72
70
73
71
function dragElement ( dragEl , settings ) {
@@ -130,9 +128,9 @@ function dragElement(dragEl, settings) {
130
128
}
131
129
132
130
function restorePos ( ) {
133
- let pos = localStorage . getItem ( "Comfy.MenuPosition" ) ;
134
- if ( pos ) {
135
- pos = JSON . parse ( pos ) ;
131
+ let posString = localStorage . getItem ( "Comfy.MenuPosition" ) ;
132
+ if ( posString ) {
133
+ const pos = JSON . parse ( posString ) as Position2D ;
136
134
newPosX = pos . x ;
137
135
newPosY = pos . y ;
138
136
positionElement ( ) ;
@@ -198,12 +196,14 @@ class ComfyList {
198
196
#type;
199
197
#text;
200
198
#reverse;
199
+ element : HTMLDivElement ;
200
+ button ?: HTMLButtonElement ;
201
201
202
- constructor ( text , type , reverse ) {
202
+ constructor ( text , type ? , reverse ? ) {
203
203
this . #text = text ;
204
204
this . #type = type || text . toLowerCase ( ) ;
205
205
this . #reverse = reverse || false ;
206
- this . element = $el ( "div.comfy-list" ) ;
206
+ this . element = $el ( "div.comfy-list" ) as HTMLDivElement ;
207
207
this . element . style . display = "none" ;
208
208
}
209
209
@@ -289,6 +289,20 @@ class ComfyList {
289
289
}
290
290
291
291
export class ComfyUI {
292
+ app : ComfyApp ;
293
+ dialog : _ComfyDialog ;
294
+ settings : ComfySettingsDialog ;
295
+ batchCount : number ;
296
+ lastQueueSize : number ;
297
+ queue : ComfyList ;
298
+ history : ComfyList ;
299
+ autoQueueMode : string ;
300
+ graphHasChanged : boolean ;
301
+ autoQueueEnabled : boolean ;
302
+ menuHamburger : HTMLDivElement ;
303
+ menuContainer : HTMLDivElement ;
304
+ queueSize : Element ;
305
+
292
306
constructor ( app ) {
293
307
this . app = app ;
294
308
this . dialog = new ComfyDialog ( ) ;
@@ -371,7 +385,7 @@ export class ComfyUI {
371
385
onchange : ( ) => {
372
386
app . handleFile ( fileInput . files [ 0 ] ) ;
373
387
} ,
374
- } ) ;
388
+ } ) as HTMLInputElement ;
375
389
376
390
const autoQueueModeEl = toggleSwitch (
377
391
"autoQueueMode" ,
@@ -408,7 +422,7 @@ export class ComfyUI {
408
422
} ,
409
423
} ,
410
424
[ $el ( "div" ) , $el ( "div" ) , $el ( "div" ) ]
411
- ) ;
425
+ ) as HTMLDivElement ;
412
426
413
427
this . menuContainer = $el ( "div.comfy-menu" , { parent : document . body } , [
414
428
$el ( "div.drag-handle.comfy-menu-header" , {
@@ -446,8 +460,9 @@ export class ComfyUI {
446
460
type : "checkbox" ,
447
461
onchange : ( i ) => {
448
462
document . getElementById ( "extraOptions" ) . style . display = i . srcElement . checked ? "block" : "none" ;
449
- this . batchCount = i . srcElement . checked ? document . getElementById ( "batchCountInputRange" ) . value : 1 ;
450
- document . getElementById ( "autoQueueCheckbox" ) . checked = false ;
463
+ this . batchCount = i . srcElement . checked ?
464
+ Number . parseInt ( ( document . getElementById ( "batchCountInputRange" ) as HTMLInputElement ) . value ) : 1 ;
465
+ ( document . getElementById ( "autoQueueCheckbox" ) as HTMLInputElement ) . checked = false ;
451
466
this . autoQueueEnabled = false ;
452
467
} ,
453
468
} ) ,
@@ -462,10 +477,14 @@ export class ComfyUI {
462
477
type : "number" ,
463
478
value : this . batchCount ,
464
479
min : "1" ,
465
- style : { width : "35%" , "margin-left " : "0.4em" } ,
480
+ style : { width : "35%" , "marginLeft " : "0.4em" } ,
466
481
oninput : ( i ) => {
467
482
this . batchCount = i . target . value ;
468
- document . getElementById ( "batchCountInputRange" ) . value = this . batchCount ;
483
+ /* Even though an <input> element with a type of range logically represents a number (since
484
+ it's used for numeric input), the value it holds is still treated as a string in HTML and
485
+ JavaScript. This behavior is consistent across all <input> elements regardless of their type
486
+ (like text, number, or range), where the .value property is always a string. */
487
+ ( document . getElementById ( "batchCountInputRange" ) as HTMLInputElement ) . value = this . batchCount . toString ( ) ;
469
488
} ,
470
489
} ) ,
471
490
$el ( "input" , {
@@ -476,7 +495,8 @@ export class ComfyUI {
476
495
value : this . batchCount ,
477
496
oninput : ( i ) => {
478
497
this . batchCount = i . srcElement . value ;
479
- document . getElementById ( "batchCountInputNumber" ) . value = i . srcElement . value ;
498
+ // Note
499
+ ( document . getElementById ( "batchCountInputNumber" ) as HTMLInputElement ) . value = i . srcElement . value ;
480
500
} ,
481
501
} ) ,
482
502
] ) ,
@@ -505,7 +525,7 @@ export class ComfyUI {
505
525
onclick : ( ) => app . queuePrompt ( - 1 , this . batchCount )
506
526
} ) ,
507
527
$el ( "button" , {
508
- $ : ( b ) => ( this . queue . button = b ) ,
528
+ $ : ( b ) => ( this . queue . button = b as HTMLButtonElement ) ,
509
529
id : "comfy-view-queue-button" ,
510
530
textContent : "View Queue" ,
511
531
onclick : ( ) => {
@@ -514,7 +534,7 @@ export class ComfyUI {
514
534
} ,
515
535
} ) ,
516
536
$el ( "button" , {
517
- $ : ( b ) => ( this . history . button = b ) ,
537
+ $ : ( b ) => ( this . history . button = b as HTMLButtonElement ) ,
518
538
id : "comfy-view-history-button" ,
519
539
textContent : "View History" ,
520
540
onclick : ( ) => {
@@ -615,7 +635,7 @@ export class ComfyUI {
615
635
app . resetView ( ) ;
616
636
}
617
637
} ) ,
618
- ] ) ;
638
+ ] ) as HTMLDivElement ;
619
639
620
640
const devMode = this . settings . addSetting ( {
621
641
id : "Comfy.DevMode" ,
0 commit comments