diff --git a/litegraph b/litegraph index 950a78d..23242ca 160000 --- a/litegraph +++ b/litegraph @@ -1 +1 @@ -Subproject commit 950a78df0327d55ddee76acbe1311b2a1515d359 +Subproject commit 23242ca3d77e4463158cc7e340cac29409260440 diff --git a/src/lib/components/ComfyApp.ts b/src/lib/components/ComfyApp.ts index 30452f3..97bff8d 100644 --- a/src/lib/components/ComfyApp.ts +++ b/src/lib/components/ComfyApp.ts @@ -127,6 +127,11 @@ export default class ComfyApp { this.addPasteHandler(); this.addKeyboardHandler(); + // Distinguish frontend/backend connections + const BACKEND_TYPES = ["CLIP", "CLIP_VISION", "CLIP_VISION_OUTPUT", "CONDITIONING", "CONTROL_NET", "IMAGE", "LATENT", "MASK", "MODEL", "STYLE_MODEL", "VAE"] + for (const type of BACKEND_TYPES) + LGraphCanvas.link_type_colors[type] = "orange" // yellow + // await this.#invokeExtensionsAsync("setup"); // Ensure the canvas fills the window @@ -236,6 +241,9 @@ export default class ComfyApp { this.type = nodeId; // XXX: workaround dependency in LGraphNode.addInput() (this as any).comfyClass = nodeId; (this as any).isBackendNode = true; + const color = LGraphCanvas.node_colors["yellow"]; + this.color = color.color + this.bgColor = color.bgColor var inputs = nodeData["input"]["required"]; if (nodeData["input"]["optional"] != undefined) { inputs = Object.assign({}, nodeData["input"]["required"], nodeData["input"]["optional"]) @@ -267,7 +275,7 @@ export default class ComfyApp { for (const o in nodeData["output"]) { const output = nodeData["output"][o]; const outputName = nodeData["output_name"][o] || output; - this.addOutput(outputName, output); + this.addOutput(outputName, output, { color_off: "orange", color_on: "orange" }); } const s = this.computeSize(); @@ -477,8 +485,14 @@ export default class ComfyApp { const inp = node.inputs[i]; const inputLink = node.getInputLink(i) const inputNode = node.getInputNode(i) - if (!inputLink || !inputNode) + if (!inputLink || !inputNode) { + if ("config" in inp) { + const defaultValue = (inp as IComfyInputSlot).config?.defaultValue + if (defaultValue !== null && defaultValue !== undefined) + inputs[inp.name] = defaultValue + } continue; + } let serialize = true; if ("config" in inp) diff --git a/src/lib/nodes/ComfyWidgetNodes.ts b/src/lib/nodes/ComfyWidgetNodes.ts index 154f8ed..008f394 100644 --- a/src/lib/nodes/ComfyWidgetNodes.ts +++ b/src/lib/nodes/ComfyWidgetNodes.ts @@ -1,10 +1,11 @@ -import { LiteGraph, type ContextMenuItem, type LGraphNode, type Vector2, LConnectionKind, LLink, LGraphCanvas, type SlotType, TitleMode, type SlotLayout, LGraph, type INodeInputSlot } from "@litegraph-ts/core"; +import { LiteGraph, type ContextMenuItem, type LGraphNode, type Vector2, LConnectionKind, LLink, LGraphCanvas, type SlotType, TitleMode, type SlotLayout, LGraph, type INodeInputSlot, type ITextWidget } from "@litegraph-ts/core"; import ComfyGraphNode from "./ComfyGraphNode"; import ComboWidget from "$lib/widgets/ComboWidget.svelte"; import RangeWidget from "$lib/widgets/RangeWidget.svelte"; import TextWidget from "$lib/widgets/TextWidget.svelte"; import type { SvelteComponentDev } from "svelte/internal"; import { ComfyWidgets } from "$lib/widgets"; +import { Watch } from "@litegraph-ts/nodes-basic"; export interface ComfyWidgetProperties extends Record { value: any, @@ -26,6 +27,32 @@ export abstract class ComfyWidgetNode extends ComfyGraphNode { override isBackendNode = false; override serialize_widgets = true; + displayWidget: ITextWidget; + + override size: Vector2 = [60, 40]; + + constructor(name?: string) { + super(name) + const color = LGraphCanvas.node_colors["blue"] + this.color ||= color.color + this.bgColor ||= color.bgColor + this.displayWidget = this.addWidget( + "text", + "Value", + "" + ); + } + + override onPropertyChanged(name: string, value: any) { + if (name == "value") { + this.displayWidget.value = Watch.toString(value) + } + } + + setValue(value: any) { + this.setProperty("value", value) + } + override onExecute() { // Assumption: we will have one output in the inherited class with the // correct type @@ -47,17 +74,18 @@ export class ComfySliderNode extends ComfyWidgetNode { override svelteComponentType = RangeWidget override inputWidgetTypes = ["number", "slider"] - constructor(name?: string) { - super(name) - this.addOutput("value", "number"); + static slotLayout: SlotLayout = { + outputs: [ + { name: "value", type: "number" } + ] } } LiteGraph.registerNodeType({ class: ComfySliderNode, - title: "ComfyBox.UI.Slider", + title: "UI.Slider", desc: "Slider outputting a number value", - type: "comfybox/ui/slider" + type: "ui/slider" }) export interface ComfyComboProperties extends ComfyWidgetProperties { @@ -71,15 +99,21 @@ export class ComfyComboNode extends ComfyWidgetNode { value: "*" } + static slotLayout: SlotLayout = { + outputs: [ + { name: "value", type: "string" } + ] + } + override svelteComponentType = ComboWidget override inputWidgetTypes = ["combo", "enum"] } LiteGraph.registerNodeType({ class: ComfyComboNode, - title: "ComfyBox.UI.Combo", + title: "UI.Combo", desc: "Combo box outputting a string value", - type: "comfybox/ui/combo" + type: "ui/combo" }) export interface ComfyTextProperties extends ComfyWidgetProperties { @@ -91,13 +125,19 @@ export class ComfyTextNode extends ComfyWidgetNode { value: "" } + static slotLayout: SlotLayout = { + outputs: [ + { name: "value", type: "string" } + ] + } + override svelteComponentType = TextWidget override inputWidgetTypes = ["text"] } LiteGraph.registerNodeType({ class: ComfyTextNode, - title: "ComfyBox.UI.Text", + title: "UI.Text", desc: "Textbox outputting a string value", - type: "comfybox/ui/text" + type: "ui/text" }) diff --git a/src/lib/nodes/index.ts b/src/lib/nodes/index.ts index e355079..c35b6e8 100644 --- a/src/lib/nodes/index.ts +++ b/src/lib/nodes/index.ts @@ -1,2 +1,3 @@ export { default as ComfyReroute } from "./ComfyReroute" export { ComfySaveImageNode, ComfyPreviewImageNode } from "./ComfyImageNodes" +export { ComfyWidgetNode, ComfySliderNode, ComfyComboNode, ComfyTextNode } from "./ComfyWidgetNodes" diff --git a/src/lib/widgets.ts b/src/lib/widgets.ts index e3e08e8..0bc4464 100644 --- a/src/lib/widgets.ts +++ b/src/lib/widgets.ts @@ -24,9 +24,6 @@ function addComfyInput(node: LGraphNode, inputName: string, extraInfo: Partial