1
1
import { toString } from 'es-toolkit/compat'
2
2
3
3
import { PREFIX , SEPARATOR } from '@/constants/groupNodeConstants'
4
- import { LinkConnector } from '@/lib/litegraph/src/canvas/LinkConnector'
5
4
import {
6
5
type LinkRenderContext ,
7
6
LitegraphLinkAdapter
@@ -17,6 +16,7 @@ import { LGraphGroup } from './LGraphGroup'
17
16
import { LGraphNode , type NodeId , type NodeProperty } from './LGraphNode'
18
17
import { LLink , type LinkId } from './LLink'
19
18
import { Reroute , type RerouteId } from './Reroute'
19
+ import { LinkConnector } from './canvas/LinkConnector'
20
20
import { isOverNodeInput , isOverNodeOutput } from './canvas/measureSlots'
21
21
import { strokeShape } from './draw'
22
22
import type {
@@ -25,6 +25,7 @@ import type {
25
25
} from './infrastructure/CustomEventTarget'
26
26
import type { LGraphCanvasEventMap } from './infrastructure/LGraphCanvasEventMap'
27
27
import { NullGraphError } from './infrastructure/NullGraphError'
28
+ import { Rectangle } from './infrastructure/Rectangle'
28
29
import type {
29
30
CanvasColour ,
30
31
ColorOption ,
@@ -47,12 +48,11 @@ import type {
47
48
NullableProperties ,
48
49
Point ,
49
50
Positionable ,
50
- ReadOnlyPoint ,
51
51
ReadOnlyRect ,
52
52
Rect ,
53
53
Size
54
54
} from './interfaces'
55
- import { LiteGraph , Rectangle , SubgraphNode , createUuidv4 } from './litegraph'
55
+ import { LiteGraph } from './litegraph'
56
56
import {
57
57
containsRect ,
58
58
createBounds ,
@@ -67,6 +67,7 @@ import { NodeInputSlot } from './node/NodeInputSlot'
67
67
import type { Subgraph } from './subgraph/Subgraph'
68
68
import { SubgraphIONodeBase } from './subgraph/SubgraphIONodeBase'
69
69
import type { SubgraphInputNode } from './subgraph/SubgraphInputNode'
70
+ import { SubgraphNode } from './subgraph/SubgraphNode'
70
71
import type { SubgraphOutputNode } from './subgraph/SubgraphOutputNode'
71
72
import type {
72
73
CanvasPointerEvent ,
@@ -88,6 +89,7 @@ import type { IBaseWidget } from './types/widgets'
88
89
import { alignNodes , distributeNodes , getBoundaryNodes } from './utils/arrange'
89
90
import { findFirstNode , getAllNestedItems } from './utils/collections'
90
91
import { resolveConnectingLinkColor } from './utils/linkColors'
92
+ import { createUuidv4 } from './utils/uuid'
91
93
import type { UUID } from './utils/uuid'
92
94
import { BaseWidget } from './widgets/BaseWidget'
93
95
import { toConcreteWidget } from './widgets/widgetMap'
@@ -228,20 +230,19 @@ const cursors = {
228
230
NW : 'nwse-resize'
229
231
} as const
230
232
233
+ // Optimised buffers used during rendering
234
+ const temp = new Rectangle ( )
235
+ const temp_vec2 : Point = [ 0 , 0 ]
236
+ const tmp_area = new Rectangle ( )
237
+ const margin_area = new Rectangle ( )
238
+ const link_bounding = new Rectangle ( )
231
239
/**
232
240
* This class is in charge of rendering one graph inside a canvas. And provides all the interaction required.
233
241
* Valid callbacks are: onNodeSelected, onNodeDeselected, onShowNodePanel, onNodeDblClicked
234
242
*/
235
243
export class LGraphCanvas
236
244
implements CustomEventDispatcher < LGraphCanvasEventMap >
237
245
{
238
- // Optimised buffers used during rendering
239
- static #temp = new Float32Array ( 4 )
240
- static #temp_vec2 = new Float32Array ( 2 )
241
- static #tmp_area = new Float32Array ( 4 )
242
- static #margin_area = new Float32Array ( 4 )
243
- static #link_bounding = new Float32Array ( 4 )
244
-
245
246
static DEFAULT_BACKGROUND_IMAGE =
246
247
'data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAGQAAABkCAIAAAD/gAIDAAAAGXRFWHRTb2Z0d2FyZQBBZG9iZSBJbWFnZVJlYWR5ccllPAAAAQBJREFUeNrs1rEKwjAUhlETUkj3vP9rdmr1Ysammk2w5wdxuLgcMHyptfawuZX4pJSWZTnfnu/lnIe/jNNxHHGNn//HNbbv+4dr6V+11uF527arU7+u63qfa/bnmh8sWLBgwYJlqRf8MEptXPBXJXa37BSl3ixYsGDBMliwFLyCV/DeLIMFCxYsWLBMwSt4Be/NggXLYMGCBUvBK3iNruC9WbBgwYJlsGApeAWv4L1ZBgsWLFiwYJmCV/AK3psFC5bBggULloJX8BpdwXuzYMGCBctgwVLwCl7Be7MMFixYsGDBsu8FH1FaSmExVfAxBa/gvVmwYMGCZbBg/W4vAQYA5tRF9QYlv/QAAAAASUVORK5CYII='
247
248
@@ -628,7 +629,7 @@ export class LGraphCanvas
628
629
dirty_area ?: Rect | null
629
630
/** @deprecated Unused */
630
631
node_in_panel ?: LGraphNode | null
631
- last_mouse : ReadOnlyPoint = [ 0 , 0 ]
632
+ last_mouse : Readonly < Point > = [ 0 , 0 ]
632
633
last_mouseclick : number = 0
633
634
graph : LGraph | Subgraph | null
634
635
get _graph ( ) : LGraph | Subgraph {
@@ -2634,7 +2635,7 @@ export class LGraphCanvas
2634
2635
pointer : CanvasPointer ,
2635
2636
node ?: LGraphNode | undefined
2636
2637
) : void {
2637
- const dragRect = new Float32Array ( 4 )
2638
+ const dragRect : Rect = [ 0 , 0 , 0 , 0 ]
2638
2639
2639
2640
dragRect [ 0 ] = e . canvasX
2640
2641
dragRect [ 1 ] = e . canvasY
@@ -3174,7 +3175,7 @@ export class LGraphCanvas
3174
3175
3175
3176
LGraphCanvas . active_canvas = this
3176
3177
this . adjustMouseEvent ( e )
3177
- const mouse : ReadOnlyPoint = [ e . clientX , e . clientY ]
3178
+ const mouse : Readonly < Point > = [ e . clientX , e . clientY ]
3178
3179
this . mouse [ 0 ] = mouse [ 0 ]
3179
3180
this . mouse [ 1 ] = mouse [ 1 ]
3180
3181
const delta = [ mouse [ 0 ] - this . last_mouse [ 0 ] , mouse [ 1 ] - this . last_mouse [ 1 ] ]
@@ -4077,7 +4078,7 @@ export class LGraphCanvas
4077
4078
this . setDirty ( true )
4078
4079
}
4079
4080
4080
- #handleMultiSelect( e : CanvasPointerEvent , dragRect : Float32Array ) {
4081
+ #handleMultiSelect( e : CanvasPointerEvent , dragRect : Rect ) {
4081
4082
// Process drag
4082
4083
// Convert Point pair (pos, offset) to Rect
4083
4084
const { graph, selectedItems, subgraph } = this
@@ -4848,7 +4849,7 @@ export class LGraphCanvas
4848
4849
}
4849
4850
4850
4851
/** Get the target snap / highlight point in graph space */
4851
- #getHighlightPosition( ) : ReadOnlyPoint {
4852
+ #getHighlightPosition( ) : Readonly < Point > {
4852
4853
return LiteGraph . snaps_for_comfy
4853
4854
? this . linkConnector . state . snapLinksPos ??
4854
4855
this . _highlight_pos ??
@@ -4863,7 +4864,7 @@ export class LGraphCanvas
4863
4864
*/
4864
4865
#renderSnapHighlight(
4865
4866
ctx : CanvasRenderingContext2D ,
4866
- highlightPos : ReadOnlyPoint
4867
+ highlightPos : Readonly < Point >
4867
4868
) : void {
4868
4869
const linkConnectorSnap = ! ! this . linkConnector . state . snapLinksPos
4869
4870
if ( ! this . _highlight_pos && ! linkConnectorSnap ) return
@@ -5204,8 +5205,9 @@ export class LGraphCanvas
5204
5205
5205
5206
// clip if required (mask)
5206
5207
const shape = node . _shape || RenderShape . BOX
5207
- const size = LGraphCanvas . #temp_vec2
5208
- size . set ( node . renderingSize )
5208
+ const size = temp_vec2
5209
+ size [ 0 ] = node . renderingSize [ 0 ]
5210
+ size [ 1 ] = node . renderingSize [ 1 ]
5209
5211
5210
5212
if ( node . collapsed ) {
5211
5213
ctx . font = this . inner_text_font
@@ -5399,7 +5401,7 @@ export class LGraphCanvas
5399
5401
: true
5400
5402
5401
5403
// Normalised node dimensions
5402
- const area = LGraphCanvas . # tmp_area
5404
+ const area = tmp_area
5403
5405
area . set ( node . boundingRect )
5404
5406
area [ 0 ] -= node . pos [ 0 ]
5405
5407
area [ 1 ] -= node . pos [ 1 ]
@@ -5501,7 +5503,7 @@ export class LGraphCanvas
5501
5503
item : Positionable ,
5502
5504
shape = RenderShape . ROUND
5503
5505
) {
5504
- const snapGuide = LGraphCanvas . # temp
5506
+ const snapGuide = temp
5505
5507
snapGuide . set ( item . boundingRect )
5506
5508
5507
5509
// Not all items have pos equal to top-left of bounds
@@ -5548,10 +5550,10 @@ export class LGraphCanvas
5548
5550
5549
5551
const now = LiteGraph . getTime ( )
5550
5552
const { visible_area } = this
5551
- LGraphCanvas . # margin_area[ 0 ] = visible_area [ 0 ] - 20
5552
- LGraphCanvas . # margin_area[ 1 ] = visible_area [ 1 ] - 20
5553
- LGraphCanvas . # margin_area[ 2 ] = visible_area [ 2 ] + 40
5554
- LGraphCanvas . # margin_area[ 3 ] = visible_area [ 3 ] + 40
5553
+ margin_area [ 0 ] = visible_area [ 0 ] - 20
5554
+ margin_area [ 1 ] = visible_area [ 1 ] - 20
5555
+ margin_area [ 2 ] = visible_area [ 2 ] + 40
5556
+ margin_area [ 3 ] = visible_area [ 3 ] + 40
5555
5557
5556
5558
// draw connections
5557
5559
ctx . lineWidth = this . connections_width
@@ -5772,18 +5774,13 @@ export class LGraphCanvas
5772
5774
// Bounding box of all points (bezier overshoot on long links will be cut)
5773
5775
const pointsX = points . map ( ( x ) => x [ 0 ] )
5774
5776
const pointsY = points . map ( ( x ) => x [ 1 ] )
5775
- LGraphCanvas . #link_bounding[ 0 ] = Math . min ( ...pointsX )
5776
- LGraphCanvas . #link_bounding[ 1 ] = Math . min ( ...pointsY )
5777
- LGraphCanvas . #link_bounding[ 2 ] =
5778
- Math . max ( ...pointsX ) - LGraphCanvas . #link_bounding[ 0 ]
5779
- LGraphCanvas . #link_bounding[ 3 ] =
5780
- Math . max ( ...pointsY ) - LGraphCanvas . #link_bounding[ 1 ]
5777
+ link_bounding [ 0 ] = Math . min ( ...pointsX )
5778
+ link_bounding [ 1 ] = Math . min ( ...pointsY )
5779
+ link_bounding [ 2 ] = Math . max ( ...pointsX ) - link_bounding [ 0 ]
5780
+ link_bounding [ 3 ] = Math . max ( ...pointsY ) - link_bounding [ 1 ]
5781
5781
5782
5782
// skip links outside of the visible area of the canvas
5783
- if (
5784
- ! overlapBounding ( LGraphCanvas . #link_bounding, LGraphCanvas . #margin_area)
5785
- )
5786
- return
5783
+ if ( ! overlapBounding ( link_bounding , margin_area ) ) return
5787
5784
5788
5785
const start_dir = startDirection || LinkDirection . RIGHT
5789
5786
const end_dir = endDirection || LinkDirection . LEFT
@@ -5942,8 +5939,8 @@ export class LGraphCanvas
5942
5939
*/
5943
5940
renderLink (
5944
5941
ctx : CanvasRenderingContext2D ,
5945
- a : ReadOnlyPoint ,
5946
- b : ReadOnlyPoint ,
5942
+ a : Readonly < Point > ,
5943
+ b : Readonly < Point > ,
5947
5944
link : LLink | null ,
5948
5945
skip_border : boolean ,
5949
5946
flow : number | null ,
@@ -5960,9 +5957,9 @@ export class LGraphCanvas
5960
5957
/** When defined, render data will be saved to this reroute instead of the {@link link}. */
5961
5958
reroute ?: Reroute
5962
5959
/** Offset of the bezier curve control point from {@link a point a} (output side) */
5963
- startControl ?: ReadOnlyPoint
5960
+ startControl ?: Readonly < Point >
5964
5961
/** Offset of the bezier curve control point from {@link b point b} (input side) */
5965
- endControl ?: ReadOnlyPoint
5962
+ endControl ?: Readonly < Point >
5966
5963
/** Number of sublines (useful to represent vec3 or rgb) @todo If implemented, refactor calculations out of the loop */
5967
5964
num_sublines ?: number
5968
5965
/** Whether this is a floating link segment */
0 commit comments