This commit is contained in:
kk8bit
2025-03-02 06:21:07 +08:00
parent 71a28bfe01
commit 0494f42e34
3 changed files with 19 additions and 21 deletions
+1 -1
View File
@@ -1,7 +1,7 @@
[project]
name = "kaytool"
description ="The KayTool custom node toolkit is designed to enhance the efficiency of building ComfyUI workflows. It includes a variety of practical nodes: wireless data transfer (Set & Get), AI translation (Tencent and Baidu), dynamic mathematical operations, image processing (size extraction, color adjustment, background removal, mask blurring and expansion), flexible text handling, precision sliders, advanced image saving with metadata support, and more."
version = "0.21.1"
version = "0.21.2"
license = {file = "LICENSE"}
dependencies = ["rembg"]
+18 -7
View File
@@ -1,14 +1,14 @@
import { app } from "../../scripts/app.js";
import { ComfyWidgets } from "../../scripts/widgets.js";
export function setupGenericDisplay(nodeType, nodeName) {
// 定义通用显示逻辑
function setupGenericDisplay(nodeType, nodeName) {
const onExecuted = nodeType.prototype.onExecuted;
nodeType.prototype.onExecuted = function (message) {
// 调用原始的 onExecuted 方法(如果存在)
onExecuted?.apply(this, arguments);
// 清理多余的 widgets
if (this.widgets && this.widgets.length > 0) {
for (let i = 1; i < this.widgets.length; i++) {
this.widgets[i]?.onRemove?.();
@@ -16,13 +16,13 @@ export function setupGenericDisplay(nodeType, nodeName) {
this.widgets.length = 1;
}
// 查找或创建 "displaytext" widget
let textWidget = Array.isArray(this.widgets)
? this.widgets.find(w => w && w.name === "displaytext")
: null;
if (!textWidget) {
try {
textWidget = ComfyWidgets["STRING"](this, "displaytext", ["STRING", { multiline: true }], app).widget;
if (textWidget && textWidget.inputEl) {
textWidget.inputEl.readOnly = true;
@@ -34,7 +34,7 @@ export function setupGenericDisplay(nodeType, nodeName) {
}
}
// 更新 "displaytext" widget 的值
if (message && message.hasOwnProperty("text")) {
const text = message["text"];
if (textWidget) {
@@ -46,4 +46,15 @@ export function setupGenericDisplay(nodeType, nodeName) {
console.warn(`[${nodeName}] Message does not contain a "text" property.`);
}
};
}
}
// 注册扩展
app.registerExtension({
name: "KayTool.GenericDisplay",
async beforeRegisterNodeDef(nodeType, nodeData, app) {
const nodesWithDisplay = ["Display_Any", "To_Int", "Abc_Math"];
if (nodesWithDisplay.includes(nodeData.name)) {
setupGenericDisplay(nodeType, nodeData.name);
}
},
});
-13
View File
@@ -1,13 +0,0 @@
import { app } from "../../scripts/app.js";
import { setupGenericDisplay } from "./common_display.js";
app.registerExtension({
name: "KayTool.GenericDisplay",
async beforeRegisterNodeDef(nodeType, nodeData, app) {
const nodesWithDisplay = ["Display_Any", "To_Int", "Abc_Math"];
if (nodesWithDisplay.includes(nodeData.name)) {
setupGenericDisplay(nodeType, nodeData.name);
}
},
});