mirror of
https://github.com/Comfy-Org/ComfyUI_frontend.git
synced 2026-04-29 10:42:44 +00:00
[TS] Use strict mode in Canvas: initializers (#645)
- Code search verified no consumers expecting explicit null on callbacks (best effort) - Removes redundant code
This commit is contained in:
@@ -491,26 +491,26 @@ export class LGraphCanvas implements ConnectionColorContext {
|
|||||||
/** @deprecated See {@link LGraphCanvas.resizingGroup} */
|
/** @deprecated See {@link LGraphCanvas.resizingGroup} */
|
||||||
selected_group_resizing?: boolean
|
selected_group_resizing?: boolean
|
||||||
/** @deprecated See {@link pointer}.{@link CanvasPointer.dragStarted dragStarted} */
|
/** @deprecated See {@link pointer}.{@link CanvasPointer.dragStarted dragStarted} */
|
||||||
last_mouse_dragging: boolean
|
last_mouse_dragging?: boolean
|
||||||
onMouseDown: (arg0: CanvasMouseEvent) => void
|
onMouseDown?: (arg0: CanvasMouseEvent) => void
|
||||||
_highlight_pos?: Point
|
_highlight_pos?: Point
|
||||||
_highlight_input?: INodeInputSlot
|
_highlight_input?: INodeInputSlot
|
||||||
// TODO: Check if panels are used
|
// TODO: Check if panels are used
|
||||||
/** @deprecated Panels */
|
/** @deprecated Panels */
|
||||||
node_panel
|
node_panel?: any
|
||||||
/** @deprecated Panels */
|
/** @deprecated Panels */
|
||||||
options_panel
|
options_panel?: any
|
||||||
onDropItem: (e: Event) => any
|
onDropItem?: (e: Event) => any
|
||||||
_bg_img: HTMLImageElement
|
_bg_img?: HTMLImageElement
|
||||||
_pattern?: CanvasPattern
|
_pattern?: CanvasPattern
|
||||||
_pattern_img: HTMLImageElement
|
_pattern_img?: HTMLImageElement
|
||||||
// TODO: This looks like another panel thing
|
// TODO: This looks like another panel thing
|
||||||
prompt_box: IDialog
|
prompt_box?: IDialog | null
|
||||||
search_box: HTMLDivElement
|
search_box?: HTMLDivElement
|
||||||
/** @deprecated Panels */
|
/** @deprecated Panels */
|
||||||
SELECTED_NODE: LGraphNode
|
SELECTED_NODE?: LGraphNode
|
||||||
/** @deprecated Panels */
|
/** @deprecated Panels */
|
||||||
NODEPANEL_IS_OPEN: boolean
|
NODEPANEL_IS_OPEN?: boolean
|
||||||
|
|
||||||
/** Once per frame check of snap to grid value. @todo Update on change. */
|
/** Once per frame check of snap to grid value. @todo Update on change. */
|
||||||
#snapToGrid?: number
|
#snapToGrid?: number
|
||||||
@@ -581,7 +581,7 @@ export class LGraphCanvas implements ConnectionColorContext {
|
|||||||
this.background_image = LGraphCanvas.DEFAULT_BACKGROUND_IMAGE
|
this.background_image = LGraphCanvas.DEFAULT_BACKGROUND_IMAGE
|
||||||
|
|
||||||
this.ds = new DragAndScale()
|
this.ds = new DragAndScale()
|
||||||
this.pointer = new CanvasPointer(this.canvas)
|
this.pointer = new CanvasPointer(canvas)
|
||||||
// otherwise it generates ugly patterns when scaling down too much
|
// otherwise it generates ugly patterns when scaling down too much
|
||||||
this.zoom_modify_alpha = true
|
this.zoom_modify_alpha = true
|
||||||
// in range (1.01, 2.5). Less than 1 will invert the zoom direction
|
// in range (1.01, 2.5). Less than 1 will invert the zoom direction
|
||||||
@@ -655,21 +655,6 @@ export class LGraphCanvas implements ConnectionColorContext {
|
|||||||
this.graph_mouse = [0, 0]
|
this.graph_mouse = [0, 0]
|
||||||
this.canvas_mouse = this.graph_mouse
|
this.canvas_mouse = this.graph_mouse
|
||||||
|
|
||||||
// to personalize the search box
|
|
||||||
this.onSearchBox = null
|
|
||||||
this.onSearchBoxSelection = null
|
|
||||||
|
|
||||||
// callbacks
|
|
||||||
this.onMouse = null
|
|
||||||
this.onDrawBackground = null
|
|
||||||
this.onDrawForeground = null
|
|
||||||
this.onDrawOverlay = null
|
|
||||||
this.onDrawLinkTooltip = null
|
|
||||||
this.onNodeMoved = null
|
|
||||||
this.onSelectionChange = null
|
|
||||||
this.onBeforeChange = null
|
|
||||||
this.onAfterChange = null
|
|
||||||
|
|
||||||
this.connections_width = 3
|
this.connections_width = 3
|
||||||
|
|
||||||
this.current_node = null
|
this.current_node = null
|
||||||
@@ -685,8 +670,13 @@ export class LGraphCanvas implements ConnectionColorContext {
|
|||||||
this.viewport = options.viewport || null
|
this.viewport = options.viewport || null
|
||||||
|
|
||||||
// link canvas and graph
|
// link canvas and graph
|
||||||
|
this.graph = graph
|
||||||
graph?.attachCanvas(this)
|
graph?.attachCanvas(this)
|
||||||
|
|
||||||
|
// TypeScript strict workaround: cannot use method to initialize properties.
|
||||||
|
this.canvas = undefined!
|
||||||
|
this.bgcanvas = undefined!
|
||||||
|
|
||||||
this.setCanvas(canvas, options.skip_events)
|
this.setCanvas(canvas, options.skip_events)
|
||||||
this.clear()
|
this.clear()
|
||||||
|
|
||||||
@@ -1660,12 +1650,10 @@ export class LGraphCanvas implements ConnectionColorContext {
|
|||||||
element.tabindex = "1"
|
element.tabindex = "1"
|
||||||
|
|
||||||
// Background canvas: To render objects behind nodes (background, links, groups)
|
// Background canvas: To render objects behind nodes (background, links, groups)
|
||||||
this.bgcanvas = null
|
this.bgcanvas = document.createElement("canvas")
|
||||||
if (!this.bgcanvas) {
|
this.bgcanvas.width = this.canvas.width
|
||||||
this.bgcanvas = document.createElement("canvas")
|
this.bgcanvas.height = this.canvas.height
|
||||||
this.bgcanvas.width = this.canvas.width
|
|
||||||
this.bgcanvas.height = this.canvas.height
|
|
||||||
}
|
|
||||||
if (element.getContext == null) {
|
if (element.getContext == null) {
|
||||||
if (element.localName != "canvas") {
|
if (element.localName != "canvas") {
|
||||||
throw "Element supplied for LGraphCanvas must be a <canvas> element, you passed a " +
|
throw "Element supplied for LGraphCanvas must be a <canvas> element, you passed a " +
|
||||||
@@ -2575,6 +2563,7 @@ export class LGraphCanvas implements ConnectionColorContext {
|
|||||||
// Legacy custom widget callback
|
// Legacy custom widget callback
|
||||||
if (widget.mouse) {
|
if (widget.mouse) {
|
||||||
const { eUp } = pointer
|
const { eUp } = pointer
|
||||||
|
if (!eUp) return
|
||||||
const { canvasX, canvasY } = eUp
|
const { canvasX, canvasY } = eUp
|
||||||
widget.mouse(eUp, [canvasX - node.pos[0], canvasY - node.pos[1]], node)
|
widget.mouse(eUp, [canvasX - node.pos[0], canvasY - node.pos[1]], node)
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user