Files
ComfyUI_frontend/src/node/NodeOutputSlot.ts
filtered 63407abf3c Reduce input socket hitbox for widgets (#966)
Restores the full left-arrow button click area for widgets. Previously
lost ~5 canvas pixels to clicks intercepted by input sockets.

Supporting refactors:
- Maps concrete node slot impls. to private array, once per frame
- Converts slot boundingRect to use absolute canvas pos (same as other
elements)
- Stores parent node ref in concrete slot classes
2025-04-25 14:12:09 +00:00

49 lines
1.4 KiB
TypeScript

import type { INodeInputSlot, INodeOutputSlot, OptionalProps } from "@/interfaces"
import type { LGraphNode } from "@/LGraphNode"
import type { LinkId } from "@/LLink"
import { LabelPosition } from "@/draw"
import { LiteGraph } from "@/litegraph"
import { type IDrawOptions, NodeSlot } from "@/node/NodeSlot"
export class NodeOutputSlot extends NodeSlot implements INodeOutputSlot {
links: LinkId[] | null
_data?: unknown
slot_index?: number
get isWidgetInputSlot(): false {
return false
}
constructor(slot: OptionalProps<INodeOutputSlot, "boundingRect">, node: LGraphNode) {
super(slot, node)
this.links = slot.links
this._data = slot._data
this.slot_index = slot.slot_index
}
override isValidTarget(fromSlot: INodeInputSlot | INodeOutputSlot): boolean {
return "link" in fromSlot && LiteGraph.isValidConnection(this.type, fromSlot.type)
}
override isConnected(): boolean {
return this.links != null && this.links.length > 0
}
override draw(ctx: CanvasRenderingContext2D, options: Omit<IDrawOptions, "doStroke" | "labelPosition">) {
const originalTextAlign = ctx.textAlign
const originalStrokeStyle = ctx.strokeStyle
ctx.textAlign = "right"
ctx.strokeStyle = "black"
super.draw(ctx, {
...options,
labelPosition: LabelPosition.Left,
doStroke: true,
})
ctx.textAlign = originalTextAlign
ctx.strokeStyle = originalStrokeStyle
}
}